Files
@ 87de3fada483
Branch filter:
Location: light9/web/light9-color-picker.ts - annotation
87de3fada483
2.9 KiB
video/MP2T
dead code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 | import debug from "debug";
import { css, html, LitElement, PropertyValueMap } from "lit";
import { customElement, property, queryAsync, state } from "lit/decorators.js";
import color from "onecolor";
import { ClientCoord, pickerFloat } from "./floating_color_picker";
export { Slider } from "@material/mwc-slider";
const log = debug("control.color");
type int8 = number;
@customElement("light9-color-picker")
export class Light9ColorPicker extends LitElement {
static styles = [
css`
:host {
position: relative;
display: flex;
align-items: center;
flex-wrap: wrap;
user-select: none;
}
#swatch {
display: inline-block;
width: 50px;
height: 30px;
margin-right: 3px;
border: 1px solid #333;
}
mwc-slider {
width: 160px;
}
#vee {
display: flex;
align-items: center;
}
`,
];
render() {
return html`
<div id="swatch" style="background-color: ${this.color}; border-color: ${this.hueSatColor}" @mousedown=${this.startFloatingPick}></div>
<span id="vee"> V: <mwc-slider id="value" .value=${this.value} step="1" min="0" max="255" @input=${this.onVSliderChange}></mwc-slider> </span>
`;
}
// Selected color. Read/write. Equal to value*hueSatColor. Never null.
@property() color: string = "#000";
@state() hueSatColor: string = "#fff"; // always full value
@state() value: int8 = 0;
@queryAsync("#swatch") swatchEl!: Promise<HTMLElement>;
connectedCallback(): void {
super.connectedCallback();
pickerFloat.pageInit();
}
update(changedProperties: PropertyValueMap<this>) {
super.update(changedProperties);
if (changedProperties.has("color")) {
this.setColor(this.color);
}
if (changedProperties.has("value") || changedProperties.has("hueSatColor")) {
this.updateColorFromHSV();
this.dispatchEvent(new CustomEvent("input", { detail: { value: this.color } }));
this.swatchEl.then((sw) => {
sw.style.borderColor = this.hueSatColor;
});
}
}
private updateColorFromHSV() {
this.color = color(this.hueSatColor)
.value(this.value / 255)
.hex();
}
private onVSliderChange(ev: CustomEvent) {
this.value = ev.detail.value;
}
// for outside users of the component
setColor(col: string) {
if (col === null) throw new Error("col===null");
if (typeof col !== "string") throw new Error("typeof col=" + typeof col);
this.value = color(col).value() * 255;
// don't update this if only the value changed, or we desaturate
this.hueSatColor = color(col).value(1).hex();
}
private startFloatingPick(ev: MouseEvent) {
if (this.value < (20 as int8)) {
log("boost");
this.value = 255 as int8;
this.updateColorFromHSV();
}
pickerFloat.startPick(new ClientCoord(ev.clientX, ev.clientY), this.color, (hsc: string) => {
this.hueSatColor = hsc;
});
}
}
|