@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,241 @@
|
|
|
1
|
+
import { css, html, nothing } from "lit";
|
|
2
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
3
|
+
import { UiElement } from "../element.js";
|
|
4
|
+
import { tok } from "../theme.js";
|
|
5
|
+
import { baseStyles, CANCEL, clamp, COMMIT, Drag, emit, PREVIEW, roundTo } from "./shared.js";
|
|
6
|
+
const CHECKER = "repeating-conic-gradient(#cbd5e1 0 25%, #ffffff 0 50%) 0 0 / 8px 8px";
|
|
7
|
+
export const checkerUnder = (background) => `${background}, ${CHECKER}`;
|
|
8
|
+
const thumbStyles = css `
|
|
9
|
+
.thumb{position: absolute;width: 14px;height: 14px;border-radius: 50%;border: 2px solid #ffffff;box-shadow:
|
|
10
|
+
0 0 0 1px rgba(0, 0, 0, 0.25),
|
|
11
|
+
0 1px 3px rgba(0, 0, 0, 0.3);transform: translate(-50%, -50%);background: transparent;}.thumb:focus-visible{outline: 2px solid ${tok("accent")};outline-offset: 2px;}`;
|
|
12
|
+
function keyStep(e) {
|
|
13
|
+
const big = e.shiftKey ? 10 : 1;
|
|
14
|
+
switch (e.key) {
|
|
15
|
+
case "ArrowRight":
|
|
16
|
+
case "ArrowUp":
|
|
17
|
+
return { steps: big };
|
|
18
|
+
case "ArrowLeft":
|
|
19
|
+
case "ArrowDown":
|
|
20
|
+
return { steps: -big };
|
|
21
|
+
case "PageUp":
|
|
22
|
+
return { steps: 10 };
|
|
23
|
+
case "PageDown":
|
|
24
|
+
return { steps: -10 };
|
|
25
|
+
case "Home":
|
|
26
|
+
return { to: "min" };
|
|
27
|
+
case "End":
|
|
28
|
+
return { to: "max" };
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
export class Slider extends UiElement {
|
|
33
|
+
static styles = [
|
|
34
|
+
baseStyles,
|
|
35
|
+
thumbStyles,
|
|
36
|
+
css `
|
|
37
|
+
:host{display: block;padding: 6px 7px;}.track{position: relative;height: 10px;border-radius: 5px;background: ${tok("bg2")};box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);touch-action: none;cursor: pointer;}.thumb{top: 50%;}:host([disabled]){opacity: 0.45;pointer-events: none;}`,
|
|
38
|
+
];
|
|
39
|
+
static properties = {
|
|
40
|
+
value: { type: Number },
|
|
41
|
+
min: { type: Number },
|
|
42
|
+
max: { type: Number },
|
|
43
|
+
step: { type: Number },
|
|
44
|
+
label: {},
|
|
45
|
+
valueText: { attribute: false },
|
|
46
|
+
track: {},
|
|
47
|
+
mixed: { type: Boolean },
|
|
48
|
+
disabled: { type: Boolean, reflect: true },
|
|
49
|
+
};
|
|
50
|
+
#dragValue = null;
|
|
51
|
+
#dragFrom = null;
|
|
52
|
+
#drag = new Drag({
|
|
53
|
+
move: (e) => this.#to(this.#fromPointer(e)),
|
|
54
|
+
commit: () => {
|
|
55
|
+
const v = this.#dragValue;
|
|
56
|
+
this.#dragValue = null;
|
|
57
|
+
if (v !== null) {
|
|
58
|
+
if (v === this.#dragFrom)
|
|
59
|
+
emit(this, CANCEL);
|
|
60
|
+
else
|
|
61
|
+
emit(this, COMMIT, v);
|
|
62
|
+
}
|
|
63
|
+
this.requestUpdate();
|
|
64
|
+
},
|
|
65
|
+
cancel: () => {
|
|
66
|
+
const had = this.#dragValue !== null;
|
|
67
|
+
this.#dragValue = null;
|
|
68
|
+
if (had)
|
|
69
|
+
emit(this, CANCEL);
|
|
70
|
+
this.requestUpdate();
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
constructor() {
|
|
74
|
+
super();
|
|
75
|
+
this.value = 0;
|
|
76
|
+
this.min = 0;
|
|
77
|
+
this.max = 1;
|
|
78
|
+
this.step = 0.01;
|
|
79
|
+
this.label = "";
|
|
80
|
+
this.mixed = false;
|
|
81
|
+
this.disabled = false;
|
|
82
|
+
}
|
|
83
|
+
disconnectedCallback() {
|
|
84
|
+
super.disconnectedCallback();
|
|
85
|
+
this.#drag.cancel();
|
|
86
|
+
}
|
|
87
|
+
requestUpdate(...args) {
|
|
88
|
+
super.requestUpdate(...args);
|
|
89
|
+
if (args[0] === "disabled" && this.disabled)
|
|
90
|
+
this.#drag.cancel();
|
|
91
|
+
}
|
|
92
|
+
#snap(v) {
|
|
93
|
+
const s = this.step > 0 ? Math.round((v - this.min) / this.step) * this.step + this.min : v;
|
|
94
|
+
return clamp(roundTo(s, this.step), this.min, this.max);
|
|
95
|
+
}
|
|
96
|
+
#fromPointer(e) {
|
|
97
|
+
const track = this.renderRoot.querySelector(".track").getBoundingClientRect();
|
|
98
|
+
const f = track.width > 0 ? clamp((e.clientX - track.left) / track.width, 0, 1) : 0;
|
|
99
|
+
return this.#snap(this.min + f * (this.max - this.min));
|
|
100
|
+
}
|
|
101
|
+
#to(v) {
|
|
102
|
+
if (v === this.#dragValue || (this.#dragValue === null && v === this.#dragFrom))
|
|
103
|
+
return;
|
|
104
|
+
this.#dragValue = v;
|
|
105
|
+
emit(this, PREVIEW, v);
|
|
106
|
+
this.requestUpdate();
|
|
107
|
+
}
|
|
108
|
+
#press(e) {
|
|
109
|
+
if (this.disabled || !this.#drag.start(e, e.currentTarget, this.ui))
|
|
110
|
+
return;
|
|
111
|
+
this.#dragValue = null;
|
|
112
|
+
this.#dragFrom = this.mixed ? null : this.value;
|
|
113
|
+
this.#to(this.#fromPointer(e));
|
|
114
|
+
}
|
|
115
|
+
#key(e) {
|
|
116
|
+
if (this.disabled)
|
|
117
|
+
return;
|
|
118
|
+
if (e.key === "Escape" && this.#drag.active) {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
return this.#drag.cancel();
|
|
121
|
+
}
|
|
122
|
+
const k = keyStep(e);
|
|
123
|
+
if (!k || this.#drag.active)
|
|
124
|
+
return;
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
const next = "to" in k ? (k.to === "min" ? this.min : this.max) : this.#snap(this.value + k.steps * this.step);
|
|
127
|
+
if (next !== this.value || this.mixed)
|
|
128
|
+
emit(this, COMMIT, next);
|
|
129
|
+
}
|
|
130
|
+
render() {
|
|
131
|
+
const v = this.#dragValue ?? this.value;
|
|
132
|
+
const f = this.max > this.min ? clamp((v - this.min) / (this.max - this.min), 0, 1) : 0;
|
|
133
|
+
return html `<div class="track" part="track" style=${styleMap({ background: this.track })} @pointerdown=${(e) => this.#press(e)} @mousedown=${(e) => e.preventDefault()}>
|
|
134
|
+
<div class="thumb" part="thumb" role="slider" tabindex=${this.disabled ? -1 : 0} aria-label=${this.label || nothing} aria-valuemin=${this.min} aria-valuemax=${this.max} aria-valuenow=${v} aria-valuetext=${this.valueText ? this.valueText(v) : nothing} aria-disabled=${this.disabled ? "true" : nothing} style=${styleMap({ left: `${f * 100}%` })} @keydown=${(e) => this.#key(e)} ></div>
|
|
135
|
+
</div>`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const same = (a, b) => !!a && !!b && a.x === b.x && a.y === b.y;
|
|
139
|
+
export class ColorArea extends UiElement {
|
|
140
|
+
static styles = [
|
|
141
|
+
baseStyles,
|
|
142
|
+
thumbStyles,
|
|
143
|
+
css `
|
|
144
|
+
:host{display: block;}.area{position: relative;height: 160px;border-radius: calc(${tok("radius")} - 4px);touch-action: none;cursor: crosshair;}`,
|
|
145
|
+
];
|
|
146
|
+
static properties = {
|
|
147
|
+
hue: { type: Number },
|
|
148
|
+
x: { type: Number },
|
|
149
|
+
y: { type: Number },
|
|
150
|
+
label: {},
|
|
151
|
+
mixed: { type: Boolean },
|
|
152
|
+
disabled: { type: Boolean, reflect: true },
|
|
153
|
+
};
|
|
154
|
+
#dragValue = null;
|
|
155
|
+
#dragFrom = null;
|
|
156
|
+
#drag = new Drag({
|
|
157
|
+
move: (e) => this.#to(this.#fromPointer(e)),
|
|
158
|
+
commit: () => {
|
|
159
|
+
const v = this.#dragValue;
|
|
160
|
+
this.#dragValue = null;
|
|
161
|
+
if (v) {
|
|
162
|
+
if (same(v, this.#dragFrom))
|
|
163
|
+
emit(this, CANCEL);
|
|
164
|
+
else
|
|
165
|
+
emit(this, COMMIT, v);
|
|
166
|
+
}
|
|
167
|
+
this.requestUpdate();
|
|
168
|
+
},
|
|
169
|
+
cancel: () => {
|
|
170
|
+
const had = this.#dragValue !== null;
|
|
171
|
+
this.#dragValue = null;
|
|
172
|
+
if (had)
|
|
173
|
+
emit(this, CANCEL);
|
|
174
|
+
this.requestUpdate();
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
constructor() {
|
|
178
|
+
super();
|
|
179
|
+
this.hue = 0;
|
|
180
|
+
this.x = 0;
|
|
181
|
+
this.y = 0;
|
|
182
|
+
this.label = "";
|
|
183
|
+
this.mixed = false;
|
|
184
|
+
this.disabled = false;
|
|
185
|
+
}
|
|
186
|
+
disconnectedCallback() {
|
|
187
|
+
super.disconnectedCallback();
|
|
188
|
+
this.#drag.cancel();
|
|
189
|
+
}
|
|
190
|
+
requestUpdate(...args) {
|
|
191
|
+
super.requestUpdate(...args);
|
|
192
|
+
if (args[0] === "disabled" && this.disabled)
|
|
193
|
+
this.#drag.cancel();
|
|
194
|
+
}
|
|
195
|
+
#fromPointer(e) {
|
|
196
|
+
const r = this.renderRoot.querySelector(".area").getBoundingClientRect();
|
|
197
|
+
const x = r.width > 0 ? clamp((e.clientX - r.left) / r.width, 0, 1) : 0;
|
|
198
|
+
const y = r.height > 0 ? 1 - clamp((e.clientY - r.top) / r.height, 0, 1) : 0;
|
|
199
|
+
return { x, y };
|
|
200
|
+
}
|
|
201
|
+
#to(v) {
|
|
202
|
+
const last = this.#dragValue;
|
|
203
|
+
if (same(v, last) || (!last && same(v, this.#dragFrom)))
|
|
204
|
+
return;
|
|
205
|
+
this.#dragValue = v;
|
|
206
|
+
emit(this, PREVIEW, v);
|
|
207
|
+
this.requestUpdate();
|
|
208
|
+
}
|
|
209
|
+
#press(e) {
|
|
210
|
+
if (this.disabled || !this.#drag.start(e, e.currentTarget, this.ui))
|
|
211
|
+
return;
|
|
212
|
+
this.#dragValue = null;
|
|
213
|
+
this.#dragFrom = this.mixed ? null : { x: this.x, y: this.y };
|
|
214
|
+
this.#to(this.#fromPointer(e));
|
|
215
|
+
}
|
|
216
|
+
#key(e) {
|
|
217
|
+
if (this.disabled)
|
|
218
|
+
return;
|
|
219
|
+
if (e.key === "Escape" && this.#drag.active) {
|
|
220
|
+
e.preventDefault();
|
|
221
|
+
return this.#drag.cancel();
|
|
222
|
+
}
|
|
223
|
+
if (this.#drag.active)
|
|
224
|
+
return;
|
|
225
|
+
const big = e.shiftKey ? 0.1 : 0.01;
|
|
226
|
+
const d = e.key === "ArrowRight" ? { x: big, y: 0 } : e.key === "ArrowLeft" ? { x: -big, y: 0 } : e.key === "ArrowUp" ? { x: 0, y: big } : e.key === "ArrowDown" ? { x: 0, y: -big } : null;
|
|
227
|
+
if (!d)
|
|
228
|
+
return;
|
|
229
|
+
e.preventDefault();
|
|
230
|
+
const next = { x: clamp(roundTo(this.x + d.x, 0.01), 0, 1), y: clamp(roundTo(this.y + d.y, 0.01), 0, 1) };
|
|
231
|
+
if (next.x !== this.x || next.y !== this.y || this.mixed)
|
|
232
|
+
emit(this, COMMIT, next);
|
|
233
|
+
}
|
|
234
|
+
render() {
|
|
235
|
+
const v = this.#dragValue ?? { x: this.x, y: this.y };
|
|
236
|
+
const pct = (n) => Math.round(n * 100);
|
|
237
|
+
return html `<div class="area" part="area" style=${styleMap({ background: `linear-gradient(to top, #000000, transparent), linear-gradient(to right, #ffffff, hsl(${this.hue} 100% 50%))` })} @pointerdown=${(e) => this.#press(e)} @mousedown=${(e) => e.preventDefault()} >
|
|
238
|
+
<div class="thumb" part="thumb" role="slider" tabindex=${this.disabled ? -1 : 0} aria-label=${this.label || this.t("color.area")} aria-valuemin="0" aria-valuemax="100" aria-valuenow=${pct(v.x)} aria-valuetext=${`${this.t("color.saturation")} ${pct(v.x)}%, ${this.t("color.brightness")} ${pct(v.y)}%`} aria-disabled=${this.disabled ? "true" : nothing} style=${styleMap({ left: `${v.x * 100}%`, top: `${(1 - v.y) * 100}%` })} @keydown=${(e) => this.#key(e)} ></div>
|
|
239
|
+
</div>`;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FillPaint } from "@daasboard/editor";
|
|
2
|
+
import { type Box } from "../color/gradient.js";
|
|
3
|
+
import { UiElement } from "../element.js";
|
|
4
|
+
export declare function swatchBackground(paint: FillPaint | null, mixed: boolean, box?: Box): string;
|
|
5
|
+
export declare class Swatch extends UiElement {
|
|
6
|
+
static styles: import("lit").CSSResult[];
|
|
7
|
+
static properties: {
|
|
8
|
+
paint: {
|
|
9
|
+
attribute: boolean;
|
|
10
|
+
};
|
|
11
|
+
mixed: {
|
|
12
|
+
type: BooleanConstructor;
|
|
13
|
+
};
|
|
14
|
+
box: {
|
|
15
|
+
attribute: boolean;
|
|
16
|
+
};
|
|
17
|
+
label: {};
|
|
18
|
+
};
|
|
19
|
+
paint: FillPaint | null;
|
|
20
|
+
mixed: boolean;
|
|
21
|
+
box: Box;
|
|
22
|
+
label: string;
|
|
23
|
+
constructor();
|
|
24
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { css, html, nothing } from "lit";
|
|
2
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
3
|
+
import { formatHex, parseStored } from "../color/color.js";
|
|
4
|
+
import { paintCss } from "../color/gradient.js";
|
|
5
|
+
import { UiElement } from "../element.js";
|
|
6
|
+
import { baseStyles } from "./shared.js";
|
|
7
|
+
const CHECKER = "repeating-conic-gradient(#cbd5e1 0 25%, #ffffff 0 50%) 0 0 / 8px 8px";
|
|
8
|
+
const MIXED = "linear-gradient(135deg, #ffffff 0 50%, #475569 50% 100%)";
|
|
9
|
+
const NONE = "linear-gradient(to top right, transparent calc(50% - 1px), #e03131 calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)), #ffffff";
|
|
10
|
+
export function swatchBackground(paint, mixed, box = { w: 1, h: 1 }) {
|
|
11
|
+
if (mixed)
|
|
12
|
+
return MIXED;
|
|
13
|
+
if (paint === null)
|
|
14
|
+
return NONE;
|
|
15
|
+
if (typeof paint === "string") {
|
|
16
|
+
const c = formatHex(parseStored(paint));
|
|
17
|
+
return `linear-gradient(${c}, ${c}), ${CHECKER}`;
|
|
18
|
+
}
|
|
19
|
+
return `${paintCss(paint, box)}, ${CHECKER}`;
|
|
20
|
+
}
|
|
21
|
+
export class Swatch extends UiElement {
|
|
22
|
+
static styles = [
|
|
23
|
+
baseStyles,
|
|
24
|
+
css `
|
|
25
|
+
:host{display: inline-block;width: 20px;height: 20px;flex: none;}.swatch{display: block;width: 100%;height: 100%;border-radius: 4px;box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);}`,
|
|
26
|
+
];
|
|
27
|
+
static properties = { paint: { attribute: false }, mixed: { type: Boolean }, box: { attribute: false }, label: {} };
|
|
28
|
+
constructor() {
|
|
29
|
+
super();
|
|
30
|
+
this.paint = null;
|
|
31
|
+
this.mixed = false;
|
|
32
|
+
this.box = { w: 1, h: 1 };
|
|
33
|
+
this.label = "";
|
|
34
|
+
}
|
|
35
|
+
render() {
|
|
36
|
+
return html `<span class="swatch" part="swatch" role=${this.label ? "img" : nothing} aria-label=${this.label || nothing} aria-hidden=${this.label ? nothing : "true"} style=${styleMap({ background: swatchBackground(this.paint, this.mixed, this.box) })} ></span>`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ReactiveController, type ReactiveControllerHost, type TemplateResult } from "lit";
|
|
2
|
+
export declare const TOOLTIP_DELAY_MS = 500;
|
|
3
|
+
export declare class Tooltip implements ReactiveController {
|
|
4
|
+
#private;
|
|
5
|
+
private readonly host;
|
|
6
|
+
constructor(host: ReactiveControllerHost & HTMLElement & {
|
|
7
|
+
readonly renderRoot: HTMLElement | DocumentFragment;
|
|
8
|
+
});
|
|
9
|
+
hostDisconnected(): void;
|
|
10
|
+
template(): TemplateResult;
|
|
11
|
+
get text(): string;
|
|
12
|
+
readonly enter: (e: Event) => void;
|
|
13
|
+
readonly leave: () => void;
|
|
14
|
+
readonly focus: (e: FocusEvent) => void;
|
|
15
|
+
readonly key: (e: KeyboardEvent) => void;
|
|
16
|
+
show(anchor: HTMLElement): void;
|
|
17
|
+
hide(): void;
|
|
18
|
+
}
|
|
19
|
+
export declare const tooltipStyles: import("lit").CSSResult;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { css, html } from "lit";
|
|
2
|
+
import { tok } from "../theme.js";
|
|
3
|
+
import { hasPopoverApi, place } from "./place.js";
|
|
4
|
+
export const TOOLTIP_DELAY_MS = 500;
|
|
5
|
+
export class Tooltip {
|
|
6
|
+
host;
|
|
7
|
+
#timer;
|
|
8
|
+
#stop = null;
|
|
9
|
+
#anchor = null;
|
|
10
|
+
constructor(host) {
|
|
11
|
+
this.host = host;
|
|
12
|
+
host.addController(this);
|
|
13
|
+
}
|
|
14
|
+
hostDisconnected() {
|
|
15
|
+
this.hide();
|
|
16
|
+
}
|
|
17
|
+
template() {
|
|
18
|
+
return html `<span class="tip" id="tip" role="tooltip" popover="manual" part="tooltip"></span>`;
|
|
19
|
+
}
|
|
20
|
+
get text() {
|
|
21
|
+
return this.#anchor ? (this.#tip()?.textContent ?? "") : "";
|
|
22
|
+
}
|
|
23
|
+
enter = (e) => {
|
|
24
|
+
const anchor = e.currentTarget;
|
|
25
|
+
clearTimeout(this.#timer);
|
|
26
|
+
this.#timer = setTimeout(() => this.show(anchor), TOOLTIP_DELAY_MS);
|
|
27
|
+
};
|
|
28
|
+
leave = () => this.hide();
|
|
29
|
+
focus = (e) => {
|
|
30
|
+
const anchor = e.currentTarget;
|
|
31
|
+
if (anchor.matches(":focus-visible"))
|
|
32
|
+
this.show(anchor);
|
|
33
|
+
};
|
|
34
|
+
key = (e) => {
|
|
35
|
+
if (e.key === "Escape" && this.#anchor)
|
|
36
|
+
this.hide();
|
|
37
|
+
};
|
|
38
|
+
show(anchor) {
|
|
39
|
+
clearTimeout(this.#timer);
|
|
40
|
+
const tip = this.#tip();
|
|
41
|
+
const label = anchor.dataset.tip;
|
|
42
|
+
if (!tip || !label)
|
|
43
|
+
return;
|
|
44
|
+
this.hide();
|
|
45
|
+
const shortcut = anchor.dataset.shortcut;
|
|
46
|
+
tip.replaceChildren(label);
|
|
47
|
+
if (shortcut) {
|
|
48
|
+
const kbd = tip.ownerDocument.createElement("kbd");
|
|
49
|
+
kbd.textContent = shortcut;
|
|
50
|
+
tip.append(kbd);
|
|
51
|
+
}
|
|
52
|
+
this.#anchor = anchor;
|
|
53
|
+
if (hasPopoverApi(tip)) {
|
|
54
|
+
try {
|
|
55
|
+
tip.showPopover();
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else
|
|
62
|
+
tip.toggleAttribute("data-open", true);
|
|
63
|
+
this.#stop = place(anchor, tip, { placement: "bottom", gap: 6 });
|
|
64
|
+
}
|
|
65
|
+
hide() {
|
|
66
|
+
clearTimeout(this.#timer);
|
|
67
|
+
this.#stop?.();
|
|
68
|
+
this.#stop = null;
|
|
69
|
+
if (!this.#anchor)
|
|
70
|
+
return;
|
|
71
|
+
this.#anchor = null;
|
|
72
|
+
const tip = this.#tip();
|
|
73
|
+
if (!tip)
|
|
74
|
+
return;
|
|
75
|
+
if (hasPopoverApi(tip) && tip.matches(":popover-open"))
|
|
76
|
+
tip.hidePopover();
|
|
77
|
+
tip.removeAttribute("data-open");
|
|
78
|
+
}
|
|
79
|
+
#tip() {
|
|
80
|
+
return this.host.renderRoot.querySelector("#tip");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export const tooltipStyles = css `
|
|
84
|
+
.tip{display: none;position: fixed;inset: auto;margin: 0;padding: 4px 7px;border: 0;border-radius: 6px;background: ${tok("fg")};color: ${tok("bg")};font-size: 11px;line-height: 14px;white-space: nowrap;pointer-events: none;gap: 6px;align-items: baseline;}.tip:popover-open{display: flex;}.tip[data-open]{display: flex;z-index: 2147483647;}.tip kbd{font: inherit;opacity: 0.7;}`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SceneObject } from "@daasboard/editor";
|
|
2
|
+
import type { UiState } from "../surface.js";
|
|
3
|
+
import type { NumberField } from "./number-field.js";
|
|
4
|
+
export type Scope = readonly [on: readonly SceneObject[], session: unknown];
|
|
5
|
+
export declare const sameScope: (a: Scope, b: Scope) => boolean;
|
|
6
|
+
export type Typed = {
|
|
7
|
+
at: Element;
|
|
8
|
+
el: Element;
|
|
9
|
+
key: string;
|
|
10
|
+
scope: Scope | null;
|
|
11
|
+
};
|
|
12
|
+
export declare const fieldOf: (el: Element) => NumberField | null;
|
|
13
|
+
export declare function scopeOf(s: UiState, key: string): Scope | null;
|
|
14
|
+
export declare class TypedValues {
|
|
15
|
+
#private;
|
|
16
|
+
private readonly root;
|
|
17
|
+
private readonly keyOf;
|
|
18
|
+
constructor(root: () => Node, keyOf: (at: Element) => string | null | undefined);
|
|
19
|
+
get typed(): Typed | null;
|
|
20
|
+
listen(host: HTMLElement): void;
|
|
21
|
+
unlisten(host: HTMLElement): void;
|
|
22
|
+
end(): void;
|
|
23
|
+
discard(at: Element): boolean;
|
|
24
|
+
rescope(s: UiState, typed: readonly string[] | null, read: readonly string[] | null): void;
|
|
25
|
+
take(from: EventTarget | null | undefined): Typed | null;
|
|
26
|
+
stale({ key, scope }: Typed): boolean;
|
|
27
|
+
commitDraftOf(field: NumberField | null): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export const sameScope = (a, b) => {
|
|
2
|
+
if (a[1] !== b[1] || a[0].length !== b[0].length)
|
|
3
|
+
return false;
|
|
4
|
+
const ids = new Set();
|
|
5
|
+
for (const o of b[0])
|
|
6
|
+
ids.add(o.id);
|
|
7
|
+
return a[0].every((o) => ids.has(o.id));
|
|
8
|
+
};
|
|
9
|
+
export const fieldOf = (el) => {
|
|
10
|
+
const host = el.getRootNode().host;
|
|
11
|
+
return host?.localName === "daas-number-field" ? host : null;
|
|
12
|
+
};
|
|
13
|
+
export function scopeOf(s, key) {
|
|
14
|
+
const pv = s.values[key];
|
|
15
|
+
const d = pv?.descriptor;
|
|
16
|
+
if (!d)
|
|
17
|
+
return null;
|
|
18
|
+
const on = pv.applicable === s.targets.length ? s.targets : s.targets.filter((o) => d.appliesTo(o));
|
|
19
|
+
return [on, d.textMark ? s.host.controller.textTarget() : null];
|
|
20
|
+
}
|
|
21
|
+
export class TypedValues {
|
|
22
|
+
root;
|
|
23
|
+
keyOf;
|
|
24
|
+
#typed = null;
|
|
25
|
+
#scopes = new Map();
|
|
26
|
+
#scoped = null;
|
|
27
|
+
#state = null;
|
|
28
|
+
#every = false;
|
|
29
|
+
#ending = null;
|
|
30
|
+
constructor(root, keyOf) {
|
|
31
|
+
this.root = root;
|
|
32
|
+
this.keyOf = keyOf;
|
|
33
|
+
}
|
|
34
|
+
get typed() {
|
|
35
|
+
return this.#typed;
|
|
36
|
+
}
|
|
37
|
+
listen(host) {
|
|
38
|
+
host.addEventListener("input", this.#onTyped);
|
|
39
|
+
host.addEventListener("pointerdown", this.#onPress);
|
|
40
|
+
}
|
|
41
|
+
unlisten(host) {
|
|
42
|
+
host.removeEventListener("input", this.#onTyped);
|
|
43
|
+
host.removeEventListener("pointerdown", this.#onPress);
|
|
44
|
+
}
|
|
45
|
+
end() {
|
|
46
|
+
this.#typed = null;
|
|
47
|
+
}
|
|
48
|
+
discard(at) {
|
|
49
|
+
if (!this.#typed || this.#typed.at !== at)
|
|
50
|
+
return false;
|
|
51
|
+
this.#typed = null;
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
rescope(s, typed, read) {
|
|
55
|
+
if (s.values === this.#scoped)
|
|
56
|
+
return;
|
|
57
|
+
this.#scoped = s.values;
|
|
58
|
+
this.#state = s;
|
|
59
|
+
this.#every = typed === null;
|
|
60
|
+
this.#scopes.clear();
|
|
61
|
+
for (const key of typed ?? []) {
|
|
62
|
+
const scope = scopeOf(s, key);
|
|
63
|
+
if (scope)
|
|
64
|
+
this.#scopes.set(key, scope);
|
|
65
|
+
}
|
|
66
|
+
const t = this.#typed;
|
|
67
|
+
if (t?.scope && (read === null || read.includes(t.key))) {
|
|
68
|
+
const now = this.#scopes.get(t.key) ?? (this.#every ? scopeOf(s, t.key) : null);
|
|
69
|
+
if (!now || !sameScope(now, t.scope))
|
|
70
|
+
t.scope = null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
#onTyped = (e) => {
|
|
74
|
+
const path = e.composedPath();
|
|
75
|
+
const el = path[0];
|
|
76
|
+
const root = this.root();
|
|
77
|
+
const at = path.find((n) => n instanceof Element && n.getRootNode() === root);
|
|
78
|
+
const key = at && this.keyOf(at);
|
|
79
|
+
if (!at || !key || this.#typed?.el === el)
|
|
80
|
+
return;
|
|
81
|
+
for (const type of ["keydown", "blur"]) {
|
|
82
|
+
el.addEventListener(type, this.#drafting, true);
|
|
83
|
+
el.addEventListener(type, this.#drafted);
|
|
84
|
+
}
|
|
85
|
+
this.#typed = { at, el, key, scope: this.#scopes.get(key) ?? (this.#every && this.#state ? scopeOf(this.#state, key) : null) };
|
|
86
|
+
};
|
|
87
|
+
#drafting = (e) => {
|
|
88
|
+
const el = e.currentTarget;
|
|
89
|
+
const k = e.key;
|
|
90
|
+
this.#ending = (k === "ArrowUp" || k === "ArrowDown") && fieldOf(el)?.draftValue === null ? null : el;
|
|
91
|
+
};
|
|
92
|
+
#drafted = (e) => {
|
|
93
|
+
const el = e.currentTarget;
|
|
94
|
+
const k = e.key;
|
|
95
|
+
this.#ending = null;
|
|
96
|
+
if (this.#typed?.el === el && (e.type === "blur" || k === "Enter" || k === "Escape" || ((k === "ArrowUp" || k === "ArrowDown") && fieldOf(el))))
|
|
97
|
+
this.#typed = null;
|
|
98
|
+
};
|
|
99
|
+
#onPress = () => {
|
|
100
|
+
if (this.#typed && fieldOf(this.#typed.el)?.scrubbing)
|
|
101
|
+
this.#typed = null;
|
|
102
|
+
};
|
|
103
|
+
take(from) {
|
|
104
|
+
const t = this.#typed;
|
|
105
|
+
const typed = t && t.at === from && (this.#ending === t.el || fieldOf(t.el)?.scrubbing) ? t : null;
|
|
106
|
+
if (typed)
|
|
107
|
+
this.#typed = null;
|
|
108
|
+
return typed;
|
|
109
|
+
}
|
|
110
|
+
stale({ key, scope }) {
|
|
111
|
+
const c = this.#state?.host.controller;
|
|
112
|
+
if (!c || !scope)
|
|
113
|
+
return true;
|
|
114
|
+
const d = c.read([key])[key]?.descriptor;
|
|
115
|
+
return !sameScope(scope, [c.targets().filter((o) => d?.appliesTo(o)), d?.textMark ? c.textTarget() : null]);
|
|
116
|
+
}
|
|
117
|
+
commitDraftOf(field) {
|
|
118
|
+
const own = !!field && this.#typed?.at === field;
|
|
119
|
+
if (own)
|
|
120
|
+
this.#ending = this.#typed.el;
|
|
121
|
+
field?.commitDraft();
|
|
122
|
+
this.#ending = null;
|
|
123
|
+
if (own)
|
|
124
|
+
this.#typed = null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LitElement, type TemplateResult } from "lit";
|
|
2
|
+
import { type IconName } from "./icons/index.js";
|
|
3
|
+
import type { RecentsStore, ResolvedOptions } from "./options.js";
|
|
4
|
+
import type { UiScheduler } from "./scheduler.js";
|
|
5
|
+
import { type StringKey } from "./strings.js";
|
|
6
|
+
export interface UiContext {
|
|
7
|
+
readonly scheduler: UiScheduler;
|
|
8
|
+
readonly options: ResolvedOptions;
|
|
9
|
+
readonly mac: boolean;
|
|
10
|
+
readonly container: HTMLElement | null;
|
|
11
|
+
readonly recents: RecentsStore;
|
|
12
|
+
attach(el: UiElement): void;
|
|
13
|
+
detach(el: UiElement): void;
|
|
14
|
+
beginDrag(cancel: () => void): () => void;
|
|
15
|
+
readonly scope: number;
|
|
16
|
+
returnFocus(): void;
|
|
17
|
+
}
|
|
18
|
+
export declare const CONTEXT: unique symbol;
|
|
19
|
+
export interface ContextOwner {
|
|
20
|
+
[CONTEXT]?: UiContext;
|
|
21
|
+
}
|
|
22
|
+
export declare function contextOf(node: Node): UiContext | null;
|
|
23
|
+
export interface ScopeChange {
|
|
24
|
+
readonly targets: boolean;
|
|
25
|
+
readonly session: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare class UiElement extends LitElement {
|
|
28
|
+
#private;
|
|
29
|
+
protected get ui(): UiContext | null;
|
|
30
|
+
connectedCallback(): void;
|
|
31
|
+
disconnectedCallback(): void;
|
|
32
|
+
requestUpdate(...args: Parameters<LitElement["requestUpdate"]>): void;
|
|
33
|
+
protected scheduleUpdate(): void | Promise<unknown>;
|
|
34
|
+
flushUpdate(): void;
|
|
35
|
+
scopeChanged(_change: ScopeChange): void;
|
|
36
|
+
protected t(key: StringKey): string;
|
|
37
|
+
protected drawIcon(name: IconName, size?: number): TemplateResult;
|
|
38
|
+
protected shortcutText(text: string | undefined): string;
|
|
39
|
+
protected shortcutAria(text: string | undefined): string;
|
|
40
|
+
}
|
package/dist/element.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
import { icon } from "./icons/index.js";
|
|
3
|
+
import { ariaChord, formatChord, isMac, parseChord } from "./keys.js";
|
|
4
|
+
import { DEFAULT_STRINGS } from "./strings.js";
|
|
5
|
+
export const CONTEXT = Symbol("daas-ui context");
|
|
6
|
+
export function contextOf(node) {
|
|
7
|
+
for (let n = node; n; n = n.parentNode ?? n.host ?? null) {
|
|
8
|
+
const c = n[CONTEXT];
|
|
9
|
+
if (c)
|
|
10
|
+
return c;
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
export class UiElement extends LitElement {
|
|
15
|
+
#ctx = null;
|
|
16
|
+
#left = null;
|
|
17
|
+
get ui() {
|
|
18
|
+
return this.#ctx;
|
|
19
|
+
}
|
|
20
|
+
connectedCallback() {
|
|
21
|
+
super.connectedCallback();
|
|
22
|
+
this.#ctx = contextOf(this);
|
|
23
|
+
this.#left = null;
|
|
24
|
+
this.#ctx?.attach(this);
|
|
25
|
+
if (!this.isUpdatePending)
|
|
26
|
+
return;
|
|
27
|
+
if (this.#ctx)
|
|
28
|
+
this.#ctx.scheduler.enqueue(this);
|
|
29
|
+
else {
|
|
30
|
+
this.isUpdatePending = false;
|
|
31
|
+
this.requestUpdate();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
disconnectedCallback() {
|
|
35
|
+
super.disconnectedCallback();
|
|
36
|
+
this.#ctx?.detach(this);
|
|
37
|
+
this.#left = this.#ctx?.scheduler ?? null;
|
|
38
|
+
this.#ctx = null;
|
|
39
|
+
}
|
|
40
|
+
requestUpdate(...args) {
|
|
41
|
+
super.requestUpdate(...args);
|
|
42
|
+
if (this.hasUpdated && this.isUpdatePending)
|
|
43
|
+
this.#ctx?.scheduler.enqueue(this);
|
|
44
|
+
}
|
|
45
|
+
scheduleUpdate() {
|
|
46
|
+
const s = this.#ctx?.scheduler;
|
|
47
|
+
if (!s)
|
|
48
|
+
return this.#left ? undefined : super.scheduleUpdate();
|
|
49
|
+
if (!this.isUpdatePending)
|
|
50
|
+
return;
|
|
51
|
+
return s.enqueue(this);
|
|
52
|
+
}
|
|
53
|
+
flushUpdate() {
|
|
54
|
+
if (this.isUpdatePending)
|
|
55
|
+
this.performUpdate();
|
|
56
|
+
}
|
|
57
|
+
scopeChanged(_change) { }
|
|
58
|
+
t(key) {
|
|
59
|
+
return this.#ctx?.options.strings.t(key) ?? DEFAULT_STRINGS[key];
|
|
60
|
+
}
|
|
61
|
+
drawIcon(name, size = 16) {
|
|
62
|
+
return icon(name, size, this.#ctx?.options.icons);
|
|
63
|
+
}
|
|
64
|
+
shortcutText(text) {
|
|
65
|
+
const chord = this.#chord(text);
|
|
66
|
+
return chord ? formatChord(chord, this.#mac()) : "";
|
|
67
|
+
}
|
|
68
|
+
shortcutAria(text) {
|
|
69
|
+
const chord = this.#chord(text);
|
|
70
|
+
return chord ? ariaChord(chord) : "";
|
|
71
|
+
}
|
|
72
|
+
#mac() {
|
|
73
|
+
return this.#ctx?.mac ?? isMac();
|
|
74
|
+
}
|
|
75
|
+
#chord(text) {
|
|
76
|
+
return text ? parseChord(text, this.#mac()) : null;
|
|
77
|
+
}
|
|
78
|
+
}
|