@daasboard/ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +5 -0
- package/README.md +6 -2
- package/dist/LICENSE-lucide.txt +43 -0
- package/dist/color/color.d.ts +34 -0
- package/dist/color/color.js +106 -0
- package/dist/color/edit.d.ts +34 -0
- package/dist/color/edit.js +40 -0
- package/dist/color/gradient.d.ts +39 -0
- package/dist/color/gradient.js +129 -0
- package/dist/color/index.d.ts +3 -0
- package/dist/color/index.js +3 -0
- package/dist/controls/buttons.d.ts +54 -0
- package/dist/controls/buttons.js +95 -0
- package/dist/controls/font-picker.d.ts +35 -0
- package/dist/controls/font-picker.js +178 -0
- package/dist/controls/index.d.ts +43 -0
- package/dist/controls/index.js +32 -0
- package/dist/controls/number-field.d.ts +60 -0
- package/dist/controls/number-field.js +190 -0
- package/dist/controls/place.d.ts +10 -0
- package/dist/controls/place.js +77 -0
- package/dist/controls/popover.d.ts +84 -0
- package/dist/controls/popover.js +366 -0
- package/dist/controls/shared.d.ts +30 -0
- package/dist/controls/shared.js +134 -0
- package/dist/controls/slider.d.ts +82 -0
- package/dist/controls/slider.js +241 -0
- package/dist/controls/swatch.d.ts +25 -0
- package/dist/controls/swatch.js +38 -0
- package/dist/controls/tooltip.d.ts +19 -0
- package/dist/controls/tooltip.js +84 -0
- package/dist/controls/typed.d.ts +28 -0
- package/dist/controls/typed.js +126 -0
- package/dist/element.d.ts +40 -0
- package/dist/element.js +78 -0
- package/dist/host.d.ts +99 -0
- package/dist/host.js +1 -0
- package/dist/icons/index.d.ts +7 -0
- package/dist/icons/index.js +31 -0
- package/dist/icons/lucide.d.ts +851 -0
- package/dist/icons/lucide.js +90 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +16 -0
- package/dist/keys.d.ts +30 -0
- package/dist/keys.js +122 -0
- package/dist/mount.d.ts +11 -0
- package/dist/mount.js +96 -0
- package/dist/options.d.ts +152 -0
- package/dist/options.js +78 -0
- package/dist/palette.d.ts +6 -0
- package/dist/palette.js +9 -0
- package/dist/picker/handles.d.ts +7 -0
- package/dist/picker/handles.js +8 -0
- package/dist/picker/index.d.ts +21 -0
- package/dist/picker/index.js +20 -0
- package/dist/picker/palette.d.ts +8 -0
- package/dist/picker/palette.js +14 -0
- package/dist/picker/picker.d.ts +63 -0
- package/dist/picker/picker.js +561 -0
- package/dist/picker/solid-editor.d.ts +60 -0
- package/dist/picker/solid-editor.js +330 -0
- package/dist/picker/stop-bar.d.ts +27 -0
- package/dist/picker/stop-bar.js +140 -0
- package/dist/prefs.d.ts +6 -0
- package/dist/prefs.js +34 -0
- package/dist/recents.d.ts +9 -0
- package/dist/recents.js +140 -0
- package/dist/root.d.ts +31 -0
- package/dist/root.js +526 -0
- package/dist/scheduler.d.ts +21 -0
- package/dist/scheduler.js +132 -0
- package/dist/strings.d.ts +284 -0
- package/dist/strings.js +287 -0
- package/dist/surface.d.ts +27 -0
- package/dist/surface.js +8 -0
- package/dist/surfaces/context-menu/index.d.ts +2 -0
- package/dist/surfaces/context-menu/index.js +2 -0
- package/dist/surfaces/context-menu/items.d.ts +14 -0
- package/dist/surfaces/context-menu/items.js +38 -0
- package/dist/surfaces/context-menu/menu.d.ts +16 -0
- package/dist/surfaces/context-menu/menu.js +135 -0
- package/dist/surfaces/pane/index.d.ts +16 -0
- package/dist/surfaces/pane/index.js +19 -0
- package/dist/surfaces/pane/model.d.ts +41 -0
- package/dist/surfaces/pane/model.js +139 -0
- package/dist/surfaces/pane/outlet.d.ts +16 -0
- package/dist/surfaces/pane/outlet.js +20 -0
- package/dist/surfaces/pane/pane.d.ts +40 -0
- package/dist/surfaces/pane/pane.js +1429 -0
- package/dist/surfaces/pane/placement.d.ts +11 -0
- package/dist/surfaces/pane/placement.js +62 -0
- package/dist/surfaces/pane/text-field.d.ts +16 -0
- package/dist/surfaces/pane/text-field.js +20 -0
- package/dist/surfaces/selection-toolbar/index.d.ts +2 -0
- package/dist/surfaces/selection-toolbar/index.js +2 -0
- package/dist/surfaces/selection-toolbar/items.d.ts +37 -0
- package/dist/surfaces/selection-toolbar/items.js +183 -0
- package/dist/surfaces/selection-toolbar/toolbar.d.ts +27 -0
- package/dist/surfaces/selection-toolbar/toolbar.js +956 -0
- package/dist/surfaces/tools/index.d.ts +2 -0
- package/dist/surfaces/tools/index.js +2 -0
- package/dist/surfaces/tools/keys.d.ts +11 -0
- package/dist/surfaces/tools/keys.js +21 -0
- package/dist/surfaces/tools/model.d.ts +48 -0
- package/dist/surfaces/tools/model.js +155 -0
- package/dist/surfaces/tools/toolbar.d.ts +27 -0
- package/dist/surfaces/tools/toolbar.js +502 -0
- package/dist/theme.d.ts +26 -0
- package/dist/theme.js +47 -0
- package/package.json +31 -3
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { css, html, nothing } from "lit";
|
|
2
|
+
import { live } from "lit/directives/live.js";
|
|
3
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
4
|
+
import { channelsOf, formatHex, fromChannels, hsvFrom, hsvToRgb, parseHex, parseStored } from "../color/color.js";
|
|
5
|
+
import { NO_PAINT_GRAY } from "../color/gradient.js";
|
|
6
|
+
import { checkerUnder } from "../controls/slider.js";
|
|
7
|
+
import { baseStyles, CANCEL, COMMIT, emit, focusWithin, keepFocus, PREVIEW } from "../controls/shared.js";
|
|
8
|
+
import { swatchBackground } from "../controls/swatch.js";
|
|
9
|
+
import { UiElement } from "../element.js";
|
|
10
|
+
import { COLOR_FORMATS, PICKER_MODES } from "../options.js";
|
|
11
|
+
import { memoryPrefs } from "../prefs.js";
|
|
12
|
+
import { tok } from "../theme.js";
|
|
13
|
+
import { PALETTE_COLUMNS, paletteGroups } from "./palette.js";
|
|
14
|
+
export const MODE_PREF = "picker.mode";
|
|
15
|
+
const standalonePrefs = memoryPrefs();
|
|
16
|
+
const noColor = () => hsvFrom(parseStored(NO_PAINT_GRAY));
|
|
17
|
+
export const eyeDropper = () => globalThis.EyeDropper ?? null;
|
|
18
|
+
export const pickerStyles = css `
|
|
19
|
+
.row{display: flex;align-items: center;gap: 6px;}.grow{flex: 1;min-width: 0;}.label{color: ${tok("muted")};font-size: 11px;}.chip{width: 20px;height: 20px;border-radius: 4px;box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);}button.chip[aria-pressed="true"]{outline: 2px solid ${tok("accent")};outline-offset: 1px;}`;
|
|
20
|
+
export class SolidEditor extends UiElement {
|
|
21
|
+
static styles = [
|
|
22
|
+
baseStyles,
|
|
23
|
+
pickerStyles,
|
|
24
|
+
css `
|
|
25
|
+
:host{display: flex;flex-direction: column;gap: 8px;}/* the palette or the color space, which the mode switch replaces: laid out as the host's own children */
|
|
26
|
+
.view{display: contents;}.palette{display: grid;grid-template-columns: repeat(${PALETTE_COLUMNS}, 20px);gap: 4px;}.group{display: flex;flex-direction: column;gap: 4px;}.hex{width: 100%;height: ${tok("control")};padding: 0 6px;border: 1px solid transparent;border-radius: calc(${tok("radius")} - 4px);background: ${tok("bg2")};font: inherit;color: inherit;outline: none;}.hex:focus{border-color: ${tok("accent")};}.fields{display: grid;grid-template-columns: 64px 1fr 52px auto;gap: 4px;align-items: center;}.channels{display: flex;gap: 2px;}.channels daas-number-field{flex: 1;}`,
|
|
27
|
+
];
|
|
28
|
+
static properties = {
|
|
29
|
+
color: {},
|
|
30
|
+
mixed: { type: Boolean },
|
|
31
|
+
allowNone: { type: Boolean, attribute: "allow-none" },
|
|
32
|
+
alpha: { type: Boolean },
|
|
33
|
+
formats: { attribute: false },
|
|
34
|
+
modes: { attribute: false },
|
|
35
|
+
palette: { attribute: false },
|
|
36
|
+
eyedropper: { type: Boolean },
|
|
37
|
+
};
|
|
38
|
+
#hsv = noColor();
|
|
39
|
+
#accepted = noColor();
|
|
40
|
+
#reverted = false;
|
|
41
|
+
#before = null;
|
|
42
|
+
#beforeColor = null;
|
|
43
|
+
#beforeMixed = false;
|
|
44
|
+
#mode = null;
|
|
45
|
+
#format = null;
|
|
46
|
+
#hexDraft = null;
|
|
47
|
+
#hexEscaped = false;
|
|
48
|
+
#picking = null;
|
|
49
|
+
constructor() {
|
|
50
|
+
super();
|
|
51
|
+
this.color = null;
|
|
52
|
+
this.mixed = false;
|
|
53
|
+
this.allowNone = true;
|
|
54
|
+
this.alpha = true;
|
|
55
|
+
this.formats = COLOR_FORMATS;
|
|
56
|
+
this.modes = PICKER_MODES;
|
|
57
|
+
this.palette = undefined;
|
|
58
|
+
this.eyedropper = true;
|
|
59
|
+
}
|
|
60
|
+
disconnectedCallback() {
|
|
61
|
+
super.disconnectedCallback();
|
|
62
|
+
this.abortPick();
|
|
63
|
+
}
|
|
64
|
+
willUpdate(changed) {
|
|
65
|
+
if (!changed.has("color") || this.#before)
|
|
66
|
+
return;
|
|
67
|
+
if (this.color === null) {
|
|
68
|
+
this.#hsv = this.#accepted = noColor();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const rgba = parseStored(this.color);
|
|
72
|
+
if (formatHex(hsvToRgb(this.#hsv)) !== formatHex(rgba))
|
|
73
|
+
this.#hsv = hsvFrom(rgba, this.#hsv);
|
|
74
|
+
this.#accepted = this.#hsv;
|
|
75
|
+
}
|
|
76
|
+
#current() {
|
|
77
|
+
return this.color === null ? null : formatHex(parseStored(this.color));
|
|
78
|
+
}
|
|
79
|
+
get hex() {
|
|
80
|
+
return formatHex(hsvToRgb(this.#hsv));
|
|
81
|
+
}
|
|
82
|
+
get mode() {
|
|
83
|
+
const modes = this.modes.length > 0 ? this.modes : PICKER_MODES;
|
|
84
|
+
const stored = this.#prefs().get(MODE_PREF);
|
|
85
|
+
const m = this.#mode ?? (stored && modes.includes(stored) ? stored : modes[0]);
|
|
86
|
+
return modes.includes(m) ? m : modes[0];
|
|
87
|
+
}
|
|
88
|
+
#prefs() {
|
|
89
|
+
return this.ui?.options.prefs ?? standalonePrefs;
|
|
90
|
+
}
|
|
91
|
+
#setMode(m) {
|
|
92
|
+
this.#mode = m;
|
|
93
|
+
this.#prefs().set(MODE_PREF, m);
|
|
94
|
+
this.requestUpdate();
|
|
95
|
+
}
|
|
96
|
+
get format() {
|
|
97
|
+
const formats = this.formats.length > 0 ? this.formats : COLOR_FORMATS;
|
|
98
|
+
return this.#format && formats.includes(this.#format) ? this.#format : formats[0];
|
|
99
|
+
}
|
|
100
|
+
#preview(next) {
|
|
101
|
+
if (!this.#before) {
|
|
102
|
+
this.#before = this.#hsv;
|
|
103
|
+
this.#beforeColor = this.#current();
|
|
104
|
+
this.#beforeMixed = this.mixed;
|
|
105
|
+
}
|
|
106
|
+
this.#hsv = next;
|
|
107
|
+
emit(this, PREVIEW, this.hex);
|
|
108
|
+
this.requestUpdate();
|
|
109
|
+
}
|
|
110
|
+
#commit(next) {
|
|
111
|
+
const before = this.#before;
|
|
112
|
+
this.#before = null;
|
|
113
|
+
this.#hsv = next;
|
|
114
|
+
const [from, mixed] = before ? [this.#beforeColor, this.#beforeMixed] : [this.#current(), this.mixed];
|
|
115
|
+
this.#reverted = false;
|
|
116
|
+
if (!mixed && this.hex === from) {
|
|
117
|
+
if (before)
|
|
118
|
+
emit(this, CANCEL);
|
|
119
|
+
}
|
|
120
|
+
else
|
|
121
|
+
emit(this, COMMIT, this.hex);
|
|
122
|
+
if (!this.#reverted)
|
|
123
|
+
this.#accepted = this.#hsv;
|
|
124
|
+
this.requestUpdate();
|
|
125
|
+
}
|
|
126
|
+
#cancel() {
|
|
127
|
+
if (this.#before)
|
|
128
|
+
this.#hsv = this.#before;
|
|
129
|
+
this.#before = null;
|
|
130
|
+
emit(this, CANCEL);
|
|
131
|
+
this.requestUpdate();
|
|
132
|
+
}
|
|
133
|
+
#relay(make) {
|
|
134
|
+
return {
|
|
135
|
+
preview: (e) => {
|
|
136
|
+
e.stopPropagation();
|
|
137
|
+
this.#preview(make(e.detail));
|
|
138
|
+
},
|
|
139
|
+
commit: (e) => {
|
|
140
|
+
e.stopPropagation();
|
|
141
|
+
this.#commit(make(e.detail));
|
|
142
|
+
},
|
|
143
|
+
cancel: (e) => {
|
|
144
|
+
e.stopPropagation();
|
|
145
|
+
this.#cancel();
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
#none() {
|
|
150
|
+
this.#before = null;
|
|
151
|
+
if (!this.allowNone)
|
|
152
|
+
this.#commit({ ...this.#hsv, a: 0 });
|
|
153
|
+
else if (this.color !== null || this.mixed)
|
|
154
|
+
emit(this, COMMIT, null);
|
|
155
|
+
}
|
|
156
|
+
#pick(hex) {
|
|
157
|
+
const c = parseHex(hex);
|
|
158
|
+
if (c)
|
|
159
|
+
this.#commit(hsvFrom(c, this.#hsv));
|
|
160
|
+
}
|
|
161
|
+
async #eyedrop() {
|
|
162
|
+
const Ctor = eyeDropper();
|
|
163
|
+
if (!Ctor)
|
|
164
|
+
return;
|
|
165
|
+
this.abortPick();
|
|
166
|
+
const pick = new AbortController();
|
|
167
|
+
this.#picking = pick;
|
|
168
|
+
try {
|
|
169
|
+
const { sRGBHex } = await new Ctor().open({ signal: pick.signal });
|
|
170
|
+
if (this.#picking !== pick)
|
|
171
|
+
return;
|
|
172
|
+
const c = parseHex(sRGBHex);
|
|
173
|
+
if (c)
|
|
174
|
+
this.#commit({ ...hsvFrom(c, this.#hsv), a: this.#hsv.a });
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
if (this.#picking === pick)
|
|
180
|
+
this.#picking = null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
abortPick() {
|
|
184
|
+
const pick = this.#picking;
|
|
185
|
+
this.#picking = null;
|
|
186
|
+
pick?.abort();
|
|
187
|
+
}
|
|
188
|
+
revert() {
|
|
189
|
+
this.#reverted = true;
|
|
190
|
+
this.#before = null;
|
|
191
|
+
this.#hsv = this.#accepted;
|
|
192
|
+
this.requestUpdate();
|
|
193
|
+
}
|
|
194
|
+
#hexKey(e) {
|
|
195
|
+
if (e.key === "Enter") {
|
|
196
|
+
e.preventDefault();
|
|
197
|
+
this.#hexCommit();
|
|
198
|
+
}
|
|
199
|
+
else if (e.key === "Escape" && this.#hexDraft !== null) {
|
|
200
|
+
e.preventDefault();
|
|
201
|
+
e.stopPropagation();
|
|
202
|
+
this.#hexDraft = null;
|
|
203
|
+
this.#hexEscaped = true;
|
|
204
|
+
this.requestUpdate();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
#hexCommit() {
|
|
208
|
+
const draft = this.#hexDraft;
|
|
209
|
+
this.#hexDraft = null;
|
|
210
|
+
if (draft === null)
|
|
211
|
+
return;
|
|
212
|
+
const text = draft.trim().replace(/^#/, "");
|
|
213
|
+
const c = parseHex(text);
|
|
214
|
+
if (c) {
|
|
215
|
+
const next = { ...hsvFrom(c, this.#hsv), a: text.length === 4 || text.length === 8 ? c.a : this.#hsv.a };
|
|
216
|
+
this.#commit(next);
|
|
217
|
+
}
|
|
218
|
+
this.requestUpdate();
|
|
219
|
+
}
|
|
220
|
+
#hexBlur() {
|
|
221
|
+
if (this.#hexEscaped) {
|
|
222
|
+
this.#hexEscaped = false;
|
|
223
|
+
this.#hexDraft = null;
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
this.#hexCommit();
|
|
227
|
+
}
|
|
228
|
+
#renderModes() {
|
|
229
|
+
const modes = this.modes.length > 0 ? this.modes : PICKER_MODES;
|
|
230
|
+
if (modes.length < 2)
|
|
231
|
+
return nothing;
|
|
232
|
+
return html `<daas-segmented label=${this.t("color.palette")} .options=${modes.map((m) => ({ value: m, label: this.t(m === "palette" ? "color.palette" : "color.space"), icon: m === "palette" ? "palette" : "color-space" }))} .value=${this.mode} @daas-commit=${(e) => {
|
|
233
|
+
e.stopPropagation();
|
|
234
|
+
const view = this.renderRoot.querySelector(".view");
|
|
235
|
+
if (view && focusWithin(view))
|
|
236
|
+
e.currentTarget.focusSegment(e.detail);
|
|
237
|
+
this.#setMode(e.detail);
|
|
238
|
+
}} ></daas-segmented>`;
|
|
239
|
+
}
|
|
240
|
+
#renderPalette() {
|
|
241
|
+
const current = this.color === null || this.mixed ? null : formatHex({ ...hsvToRgb(this.#hsv) });
|
|
242
|
+
const groups = paletteGroups(this.palette);
|
|
243
|
+
return html `${groups.map((g) => html `<div class="group">
|
|
244
|
+
${g.name ? html `<span class="label">${g.name}</span>` : nothing}
|
|
245
|
+
<div class="palette" role="group" aria-label=${g.name || this.t("color.palette")} @keydown=${(e) => this.#paletteKey(e)}>
|
|
246
|
+
${g.colors.map((c, i) => {
|
|
247
|
+
const hex = formatHex(parseStored(c));
|
|
248
|
+
return html `<button class="chip" part="swatch" aria-label=${hex} aria-pressed=${hex === current ? "true" : "false"} tabindex=${i === 0 ? 0 : -1} style=${styleMap({ background: swatchBackground(hex, false) })} @pointerdown=${keepFocus} @mousedown=${keepFocus} @click=${() => this.#pick(hex)} ></button>`;
|
|
249
|
+
})}
|
|
250
|
+
</div>
|
|
251
|
+
</div>`)}`;
|
|
252
|
+
}
|
|
253
|
+
#paletteKey(e) {
|
|
254
|
+
const grid = e.currentTarget;
|
|
255
|
+
const chips = [...grid.querySelectorAll("button")];
|
|
256
|
+
const at = chips.indexOf(e.target);
|
|
257
|
+
const step = { ArrowRight: 1, ArrowLeft: -1, ArrowDown: PALETTE_COLUMNS, ArrowUp: -PALETTE_COLUMNS }[e.key];
|
|
258
|
+
if (at < 0 || step === undefined)
|
|
259
|
+
return;
|
|
260
|
+
e.preventDefault();
|
|
261
|
+
const to = chips[Math.min(chips.length - 1, Math.max(0, at + step))];
|
|
262
|
+
chips.forEach((c) => (c.tabIndex = c === to ? 0 : -1));
|
|
263
|
+
to.focus();
|
|
264
|
+
}
|
|
265
|
+
#open() {
|
|
266
|
+
return this.mixed || this.color === null;
|
|
267
|
+
}
|
|
268
|
+
#renderSpace() {
|
|
269
|
+
const area = this.#relay((v) => ({ ...this.#hsv, s: v.x, v: v.y }));
|
|
270
|
+
const hue = this.#relay((h) => ({ ...this.#hsv, h }));
|
|
271
|
+
return html `<daas-color-area .hue=${this.#hsv.h} .x=${this.#hsv.s} .y=${this.#hsv.v} .mixed=${this.#open()} @daas-preview=${area.preview} @daas-commit=${area.commit} @daas-cancel=${area.cancel} ></daas-color-area>
|
|
272
|
+
<daas-slider label=${this.t("color.hue")} .min=${0} .max=${360} .step=${1} .value=${this.#hsv.h} .mixed=${this.#open()} track="linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000)" @daas-preview=${hue.preview} @daas-commit=${hue.commit} @daas-cancel=${hue.cancel} ></daas-slider>`;
|
|
273
|
+
}
|
|
274
|
+
#renderAlpha() {
|
|
275
|
+
const opaque = formatHex({ ...hsvToRgb(this.#hsv), a: 1 });
|
|
276
|
+
const alpha = this.#relay((a) => ({ ...this.#hsv, a }));
|
|
277
|
+
return html `<div class="row">
|
|
278
|
+
${this.alpha
|
|
279
|
+
? html `<daas-slider class="grow" label=${this.t("color.alpha")} .min=${0} .max=${1} .step=${0.01} .value=${this.#hsv.a} .mixed=${this.#open()} .valueText=${(v) => `${Math.round(v * 100)}%`} track=${checkerUnder(`linear-gradient(to right, ${opaque}00, ${opaque})`)} @daas-preview=${alpha.preview} @daas-commit=${alpha.commit} @daas-cancel=${alpha.cancel} ></daas-slider>`
|
|
280
|
+
: html `<span class="grow"></span>`}
|
|
281
|
+
<daas-toggle-button icon="no-color" label=${this.t(this.allowNone ? "color.none" : "color.transparent")} .pressed=${this.allowNone ? this.color === null && !this.mixed : this.#hsv.a === 0} @daas-commit=${(e) => {
|
|
282
|
+
e.stopPropagation();
|
|
283
|
+
this.#none();
|
|
284
|
+
}} ></daas-toggle-button>
|
|
285
|
+
</div>`;
|
|
286
|
+
}
|
|
287
|
+
#renderFields() {
|
|
288
|
+
const formats = this.formats.length > 0 ? this.formats : COLOR_FORMATS;
|
|
289
|
+
const format = this.format;
|
|
290
|
+
const rgba = hsvToRgb(this.#hsv);
|
|
291
|
+
const shown = this.mixed && this.#hexDraft === null ? "" : (this.#hexDraft ?? formatHex({ ...rgba, a: 1 }).slice(1));
|
|
292
|
+
const channelNames = {
|
|
293
|
+
rgb: [this.t("color.red"), this.t("color.green"), this.t("color.blue")],
|
|
294
|
+
hsl: [this.t("color.hue"), this.t("color.saturation"), this.t("color.lightness")],
|
|
295
|
+
};
|
|
296
|
+
const channels = format === "hex" ? [] : channelsOf(rgba, format);
|
|
297
|
+
const limits = format === "hsl" ? [360, 100, 100] : [255, 255, 255];
|
|
298
|
+
const alpha = this.#relay((a) => ({ ...this.#hsv, a: a / 100 }));
|
|
299
|
+
return html `<div class="fields">
|
|
300
|
+
${formats.length > 1
|
|
301
|
+
? html `<daas-select label=${this.t("color.format")} .options=${formats.map((f) => ({ value: f, label: this.t(`color.${f}`) }))} .value=${format} @daas-commit=${(e) => {
|
|
302
|
+
e.stopPropagation();
|
|
303
|
+
this.#format = e.detail;
|
|
304
|
+
this.requestUpdate();
|
|
305
|
+
}} ></daas-select>`
|
|
306
|
+
: html `<span class="label">${this.t(`color.${format}`)}</span>`}
|
|
307
|
+
${format === "hex"
|
|
308
|
+
? html `<input class="hex" part="hex" aria-label=${this.t("color.hex")} placeholder=${this.mixed ? this.t("value.mixed") : ""} maxlength="9" spellcheck="false" autocomplete="off" .value=${live(shown)} @input=${(e) => (this.#hexDraft = e.target.value)} @keydown=${(e) => this.#hexKey(e)} @focus=${(e) => e.target.select()} @blur=${() => this.#hexBlur()} />`
|
|
309
|
+
: html `<div class="channels">
|
|
310
|
+
${channels.map((v, i) => {
|
|
311
|
+
const ch = this.#relay((x) => {
|
|
312
|
+
const next = [...channels];
|
|
313
|
+
next[i] = x;
|
|
314
|
+
return hsvFrom(fromChannels(format, next, this.#hsv.a), this.#hsv);
|
|
315
|
+
});
|
|
316
|
+
return html `<daas-number-field name=${channelNames[format][i]} .value=${Math.round(v)} .mixed=${this.mixed} .min=${0} .max=${limits[i]} .precision=${0} @daas-preview=${ch.preview} @daas-commit=${ch.commit} @daas-cancel=${ch.cancel} ></daas-number-field>`;
|
|
317
|
+
})}
|
|
318
|
+
</div>`}
|
|
319
|
+
${this.alpha
|
|
320
|
+
? html `<daas-number-field name=${this.t("color.alpha")} unit="%" .value=${Math.round(this.#hsv.a * 100)} .mixed=${this.mixed} .min=${0} .max=${100} .precision=${0} @daas-preview=${alpha.preview} @daas-commit=${alpha.commit} @daas-cancel=${alpha.cancel} ></daas-number-field>`
|
|
321
|
+
: html `<span></span>`}
|
|
322
|
+
${this.eyedropper && eyeDropper()
|
|
323
|
+
? html `<daas-icon-button icon="eyedropper" label=${this.t("color.eyedropper")} @click=${() => void this.#eyedrop()}></daas-icon-button>`
|
|
324
|
+
: nothing}
|
|
325
|
+
</div>`;
|
|
326
|
+
}
|
|
327
|
+
render() {
|
|
328
|
+
return html `${this.#renderModes()} <div class="view">${this.mode === "palette" ? this.#renderPalette() : this.#renderSpace()}</div> ${this.#renderAlpha()} ${this.#renderFields()}`;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { GradientStop } from "@daasboard/editor";
|
|
2
|
+
import { type PropertyValues } from "lit";
|
|
3
|
+
import { UiElement } from "../element.js";
|
|
4
|
+
export declare const STOP_SELECT = "daas-stop";
|
|
5
|
+
export declare class StopBar extends UiElement {
|
|
6
|
+
#private;
|
|
7
|
+
static styles: import("lit").CSSResult[];
|
|
8
|
+
static properties: {
|
|
9
|
+
stops: {
|
|
10
|
+
attribute: boolean;
|
|
11
|
+
};
|
|
12
|
+
selected: {
|
|
13
|
+
type: NumberConstructor;
|
|
14
|
+
};
|
|
15
|
+
mixed: {
|
|
16
|
+
type: BooleanConstructor;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
stops: readonly GradientStop[];
|
|
20
|
+
selected: number;
|
|
21
|
+
mixed: boolean;
|
|
22
|
+
constructor();
|
|
23
|
+
disconnectedCallback(): void;
|
|
24
|
+
protected updated(changed: PropertyValues<this>): void;
|
|
25
|
+
focusHandle(i: number): void;
|
|
26
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { css, html } from "lit";
|
|
2
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
3
|
+
import { formatHex, parseStored } from "../color/color.js";
|
|
4
|
+
import { paintCss, sortedStops, stopColorAt } from "../color/gradient.js";
|
|
5
|
+
import { baseStyles, CANCEL, clamp, COMMIT, Drag, emit, PREVIEW } from "../controls/shared.js";
|
|
6
|
+
import { checkerUnder } from "../controls/slider.js";
|
|
7
|
+
import { UiElement } from "../element.js";
|
|
8
|
+
import { tok } from "../theme.js";
|
|
9
|
+
export const STOP_SELECT = "daas-stop";
|
|
10
|
+
const tidy = (at) => Math.round(clamp(at, 0, 1) * 1000) / 1000;
|
|
11
|
+
export class StopBar extends UiElement {
|
|
12
|
+
static styles = [
|
|
13
|
+
baseStyles,
|
|
14
|
+
css `
|
|
15
|
+
:host{display: block;padding: 0 8px;}.bar{position: relative;height: 18px;border-radius: 4px;box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);cursor: copy;touch-action: none;}.handle{position: absolute;top: 50%;width: 14px;height: 22px;border-radius: 4px;border: 2px solid #ffffff;box-shadow:
|
|
16
|
+
0 0 0 1px rgba(0, 0, 0, 0.3),
|
|
17
|
+
0 1px 3px rgba(0, 0, 0, 0.25);transform: translate(-50%, -50%);cursor: ew-resize;}.handle.selected{box-shadow:
|
|
18
|
+
0 0 0 2px ${tok("accent")},
|
|
19
|
+
0 1px 3px rgba(0, 0, 0, 0.25);}`,
|
|
20
|
+
];
|
|
21
|
+
static properties = { stops: { attribute: false }, selected: { type: Number }, mixed: { type: Boolean } };
|
|
22
|
+
#dragStops = null;
|
|
23
|
+
#dragIndex = -1;
|
|
24
|
+
#dragFrom = 0;
|
|
25
|
+
#refocus = null;
|
|
26
|
+
#drag = new Drag({
|
|
27
|
+
move: (e) => this.#dragTo(this.#atOf(e)),
|
|
28
|
+
commit: () => {
|
|
29
|
+
const stops = this.#dragStops;
|
|
30
|
+
const moved = stops?.[this.#dragIndex];
|
|
31
|
+
this.#dragStops = null;
|
|
32
|
+
if (stops && moved) {
|
|
33
|
+
if (moved.at === this.#dragFrom)
|
|
34
|
+
emit(this, CANCEL);
|
|
35
|
+
else
|
|
36
|
+
this.#commit(stops, moved);
|
|
37
|
+
}
|
|
38
|
+
this.requestUpdate();
|
|
39
|
+
},
|
|
40
|
+
cancel: () => {
|
|
41
|
+
const had = this.#dragStops !== null;
|
|
42
|
+
this.#dragStops = null;
|
|
43
|
+
if (had)
|
|
44
|
+
emit(this, CANCEL);
|
|
45
|
+
this.requestUpdate();
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
constructor() {
|
|
49
|
+
super();
|
|
50
|
+
this.stops = [];
|
|
51
|
+
this.selected = 0;
|
|
52
|
+
this.mixed = false;
|
|
53
|
+
}
|
|
54
|
+
disconnectedCallback() {
|
|
55
|
+
super.disconnectedCallback();
|
|
56
|
+
this.#drag.cancel();
|
|
57
|
+
}
|
|
58
|
+
updated(changed) {
|
|
59
|
+
if (this.#refocus === null || !changed.has("stops"))
|
|
60
|
+
return;
|
|
61
|
+
const handle = this.renderRoot.querySelectorAll(".handle")[this.#refocus];
|
|
62
|
+
this.#refocus = null;
|
|
63
|
+
handle?.focus();
|
|
64
|
+
}
|
|
65
|
+
focusHandle(i) {
|
|
66
|
+
void this.updateComplete.then(() => this.renderRoot.querySelectorAll(".handle")[i]?.focus());
|
|
67
|
+
}
|
|
68
|
+
#select(i) {
|
|
69
|
+
if (i === this.selected)
|
|
70
|
+
return;
|
|
71
|
+
this.selected = i;
|
|
72
|
+
this.dispatchEvent(new CustomEvent(STOP_SELECT, { detail: i, bubbles: true }));
|
|
73
|
+
}
|
|
74
|
+
#commit(stops, moved) {
|
|
75
|
+
const sorted = sortedStops(stops);
|
|
76
|
+
emit(this, COMMIT, sorted);
|
|
77
|
+
const at = sorted.indexOf(moved);
|
|
78
|
+
this.#select(at);
|
|
79
|
+
return at;
|
|
80
|
+
}
|
|
81
|
+
#atOf(e) {
|
|
82
|
+
const r = this.renderRoot.querySelector(".bar").getBoundingClientRect();
|
|
83
|
+
return tidy(r.width > 0 ? (e.clientX - r.left) / r.width : 0);
|
|
84
|
+
}
|
|
85
|
+
#dragTo(at) {
|
|
86
|
+
const base = this.#dragStops ?? this.stops;
|
|
87
|
+
if (base[this.#dragIndex]?.at === at)
|
|
88
|
+
return;
|
|
89
|
+
this.#dragStops = base.map((s, j) => (j === this.#dragIndex ? { ...s, at } : s));
|
|
90
|
+
emit(this, PREVIEW, this.#dragStops);
|
|
91
|
+
this.requestUpdate();
|
|
92
|
+
}
|
|
93
|
+
#pressHandle(e, i) {
|
|
94
|
+
e.stopPropagation();
|
|
95
|
+
this.#refocus = null;
|
|
96
|
+
this.#select(i);
|
|
97
|
+
const bar = this.renderRoot.querySelector(".bar");
|
|
98
|
+
if (!this.#drag.start(e, bar, this.ui))
|
|
99
|
+
return;
|
|
100
|
+
this.#dragIndex = i;
|
|
101
|
+
this.#dragFrom = this.mixed ? null : (this.stops[i]?.at ?? 0);
|
|
102
|
+
this.#dragStops = null;
|
|
103
|
+
}
|
|
104
|
+
#pressBar(e) {
|
|
105
|
+
if (e.button !== 0)
|
|
106
|
+
return;
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
const at = this.#atOf(e);
|
|
109
|
+
const added = { at, color: stopColorAt(this.stops, at) };
|
|
110
|
+
this.#commit([...this.stops, added], added);
|
|
111
|
+
}
|
|
112
|
+
#key(e, i) {
|
|
113
|
+
const s = this.stops[i];
|
|
114
|
+
if (!s)
|
|
115
|
+
return;
|
|
116
|
+
if (this.#drag.active) {
|
|
117
|
+
if (e.key === "Escape") {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
e.stopPropagation();
|
|
120
|
+
this.#drag.cancel();
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const big = e.shiftKey ? 0.1 : 0.01;
|
|
125
|
+
const at = e.key === "ArrowRight" || e.key === "ArrowUp" ? s.at + big : e.key === "ArrowLeft" || e.key === "ArrowDown" ? s.at - big : e.key === "Home" ? 0 : e.key === "End" ? 1 : null;
|
|
126
|
+
if (at === null)
|
|
127
|
+
return;
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
const moved = { ...s, at: tidy(at) };
|
|
130
|
+
if (moved.at !== s.at)
|
|
131
|
+
this.#refocus = this.#commit(this.stops.map((x, j) => (j === i ? moved : x)), moved);
|
|
132
|
+
}
|
|
133
|
+
render() {
|
|
134
|
+
const stops = this.#dragStops ?? this.stops;
|
|
135
|
+
const bar = paintCss({ type: "linear", start: [0, 0.5], end: [1, 0.5], stops: [...stops] }, { w: 1, h: 1 });
|
|
136
|
+
return html `<div class="bar" part="bar" style=${styleMap({ background: checkerUnder(bar) })} @pointerdown=${(e) => this.#pressBar(e)} @mousedown=${(e) => e.preventDefault()}>
|
|
137
|
+
${stops.map((s, i) => html `<div class="handle ${i === this.selected ? "selected" : ""}" part="handle" role="slider" tabindex="0" aria-label=${`${this.t("paint.stop")} ${i + 1}`} aria-valuemin="0" aria-valuemax="100" aria-valuenow=${Math.round(s.at * 1000) / 10} style=${styleMap({ left: `${clamp(s.at, 0, 1) * 100}%`, background: formatHex(parseStored(s.color)) })} @pointerdown=${(e) => this.#pressHandle(e, i)} @mousedown=${(e) => e.preventDefault()} @focus=${() => this.#select(i)} @keydown=${(e) => this.#key(e, i)} ></div>`)}
|
|
138
|
+
</div>`;
|
|
139
|
+
}
|
|
140
|
+
}
|
package/dist/prefs.d.ts
ADDED
package/dist/prefs.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function memoryPrefs() {
|
|
2
|
+
const values = new Map();
|
|
3
|
+
return {
|
|
4
|
+
get: (key) => values.get(key) ?? null,
|
|
5
|
+
set: (key, value) => void values.set(key, value),
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function localStoragePrefs(prefix = "daas-ui:") {
|
|
9
|
+
const storage = () => {
|
|
10
|
+
try {
|
|
11
|
+
return globalThis.localStorage ?? null;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
get(key) {
|
|
19
|
+
try {
|
|
20
|
+
return storage()?.getItem(prefix + key) ?? null;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
set(key, value) {
|
|
27
|
+
try {
|
|
28
|
+
storage()?.setItem(prefix + key, value);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FillPaint } from "@daasboard/editor";
|
|
2
|
+
import type { RecentsStore } from "./options.js";
|
|
3
|
+
import type { PrefsStore } from "./prefs.js";
|
|
4
|
+
export declare const DEFAULT_RECENTS = 16;
|
|
5
|
+
export declare const RECENTS_PREF = "picker.recents";
|
|
6
|
+
export declare function paintKey(p: FillPaint): string;
|
|
7
|
+
export declare function storedPaint(v: unknown): FillPaint | null;
|
|
8
|
+
export declare function memoryRecents(max?: number): RecentsStore;
|
|
9
|
+
export declare function prefsRecents(prefs: () => PrefsStore, max?: number): RecentsStore;
|