import { settings } from "../settings.js"; import { getIconElement, isDefinedIcon } from "./icons.js"; const styles = ["purple", "gray", "red", "green", "yellow", "blue"]; class DevToolbarHighlight extends HTMLElement { icon; _highlightStyle = "purple"; get highlightStyle() { return this._highlightStyle; } set highlightStyle(value) { if (!styles.includes(value)) { settings.logger.error( `Invalid style: ${value}, expected one of ${styles.join(", ")}, got ${value}.` ); return; } this._highlightStyle = value; this.updateStyle(); } static observedAttributes = ["highlight-style"]; shadowRoot; constructor() { super(); this.shadowRoot = this.attachShadow({ mode: "open" }); this.icon = this.hasAttribute("icon") ? this.getAttribute("icon") : void 0; this.shadowRoot.innerHTML = ` `; } updateStyle() { const style = this.shadowRoot.querySelector("#selected-style"); if (style) { style.innerHTML = ` :host { --background: var(--${this.highlightStyle}-background); --border: var(--${this.highlightStyle}-border); }`; } } attributeChangedCallback() { if (this.hasAttribute("highlight-style")) this.highlightStyle = this.getAttribute("highlight-style"); } connectedCallback() { this.updateStyle(); if (this.icon) { let iconContainer = document.createElement("div"); iconContainer.classList.add("icon"); let iconElement; if (isDefinedIcon(this.icon)) { iconElement = getIconElement(this.icon); } else { iconElement = document.createElementNS("http://www.w3.org/2000/svg", "svg"); iconElement.setAttribute("viewBox", "0 0 16 16"); iconElement.innerHTML = this.icon; } if (iconElement) { iconElement?.style.setProperty("width", "16px"); iconElement?.style.setProperty("height", "16px"); iconContainer.append(iconElement); this.shadowRoot.append(iconContainer); } } } } export { DevToolbarHighlight };