import { html } from "lit" import { styleMap } from "lit/directives/style-map.js" import ColorHandlerElement from "../element/ColorHandlerElement" import ColorSliderElement from "../element/ColorSliderElement" import LinearColorEntity from "../entity/LinearColorEntity" import WindowTemplate from "./WindowTemplate" /** @typedef {import("../element/WindowElement").default} WindowElement */ export default class ColorPickerWindowTemplate extends WindowTemplate { /** @type {LinearColorEntity} */ #color get color() { return this.#color } /** @param {LinearColorEntity} value */ set color(value) { if (value.toNumber() == this.color?.toNumber()) { return } this.element.requestUpdate("color", this.#color) this.#color = value } connectedCallback() { super.connectedCallback() this.color = this.element.windowOptions.getPinColor() } /** @param {Map} changedProperties */ firstUpdated(changedProperties) { const wheelHandler = new ColorHandlerElement() const spectrumHandler = new ColorHandlerElement() const saturationSlider = new ColorSliderElement() wheelHandler.template.locationChangeCallback = ([x, y], radius, v, a) => { this.color = LinearColorEntity.fromWheelLocation([x, y], radius, v, a) } this.element.querySelector(".ueb-color-picker-wheel").appendChild(wheelHandler) } renderContent() { const [h, s, v] = this.color.toHSVA() const style = { "--ueb-color-r": this.color.R.toString(), "--ueb-color-g": this.color.G.toString(), "--ueb-color-b": this.color.B.toString(), "--ueb-color-a": this.color.A.toString(), "--ueb-color-h": h.toString(), "--ueb-color-s": s.toString(), "--ueb-color-v": v.toString(), } return html`
` } renderWindowName() { return html`Color Picker` } }