import { DiffuseElement } from "@common/element.js"; /** * @import {RenderArg} from "@common/element.d.ts" */ //////////////////////////////////////////// // ELEMENT //////////////////////////////////////////// class WindowElement extends DiffuseElement { static observedAttributes = ["open"]; constructor() { super(); this.id = this.id?.length ? this.id : crypto.randomUUID(); this.attachShadow({ mode: "open" }); } // ACTIONS activate() { this.shadowRoot?.querySelector(".title-bar")?.classList.remove("inactive"); } deactivate() { this.shadowRoot?.querySelector(".title-bar")?.classList.add("inactive"); } // RENDER /** * @param {RenderArg} _ */ render({ html }) { return html` this.removeAttribute("open")}"> `; } // EVENTS /** * @param {MouseEvent} mouse */ titleBarMouseDown(mouse) { const event = new CustomEvent("dtw-window-start-move", { bubbles: true, composed: true, detail: { element: this, x: mouse.x, xElement: mouse.layerX, y: mouse.y, yElement: mouse.layerY, }, }); this.dispatchEvent(event); } } export default WindowElement; //////////////////////////////////////////// // REGISTER //////////////////////////////////////////// export const CLASS = WindowElement; export const NAME = "dtw-window"; customElements.define(NAME, WindowElement);