import { defaultSettings, settings } from "../settings.js";
const placements = ["bottom-left", "bottom-center", "bottom-right"];
function isValidPlacement(value) {
return placements.map(String).includes(value);
}
class DevToolbarWindow extends HTMLElement {
shadowRoot;
_placement = defaultSettings.placement;
get placement() {
return this._placement;
}
set placement(value) {
if (!isValidPlacement(value)) {
settings.logger.error(
`Invalid placement: ${value}, expected one of ${placements.join(", ")}, got ${value}.`
);
return;
}
this._placement = value;
this.updateStyle();
}
static observedAttributes = ["placement"];
constructor() {
super();
this.shadowRoot = this.attachShadow({ mode: "open" });
}
async connectedCallback() {
this.shadowRoot.innerHTML = `
`;
this.updateStyle();
}
attributeChangedCallback() {
if (this.hasAttribute("placement"))
this.placement = this.getAttribute("placement");
}
updateStyle() {
const style = this.shadowRoot.querySelector("#selected-style");
if (style) {
const styleMap = {
"bottom-left": `
:host {
left: 16px;
}
`,
"bottom-center": `
:host {
left: 50%;
transform: translateX(-50%);
}
`,
"bottom-right": `
:host {
right: 16px;
}
`
};
style.innerHTML = styleMap[this.placement];
}
}
}
export {
DevToolbarWindow,
isValidPlacement,
placements
};