@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.
Files changed (110) hide show
  1. package/LICENSE +5 -0
  2. package/README.md +6 -2
  3. package/dist/LICENSE-lucide.txt +43 -0
  4. package/dist/color/color.d.ts +34 -0
  5. package/dist/color/color.js +106 -0
  6. package/dist/color/edit.d.ts +34 -0
  7. package/dist/color/edit.js +40 -0
  8. package/dist/color/gradient.d.ts +39 -0
  9. package/dist/color/gradient.js +129 -0
  10. package/dist/color/index.d.ts +3 -0
  11. package/dist/color/index.js +3 -0
  12. package/dist/controls/buttons.d.ts +54 -0
  13. package/dist/controls/buttons.js +95 -0
  14. package/dist/controls/font-picker.d.ts +35 -0
  15. package/dist/controls/font-picker.js +178 -0
  16. package/dist/controls/index.d.ts +43 -0
  17. package/dist/controls/index.js +32 -0
  18. package/dist/controls/number-field.d.ts +60 -0
  19. package/dist/controls/number-field.js +190 -0
  20. package/dist/controls/place.d.ts +10 -0
  21. package/dist/controls/place.js +77 -0
  22. package/dist/controls/popover.d.ts +84 -0
  23. package/dist/controls/popover.js +366 -0
  24. package/dist/controls/shared.d.ts +30 -0
  25. package/dist/controls/shared.js +134 -0
  26. package/dist/controls/slider.d.ts +82 -0
  27. package/dist/controls/slider.js +241 -0
  28. package/dist/controls/swatch.d.ts +25 -0
  29. package/dist/controls/swatch.js +38 -0
  30. package/dist/controls/tooltip.d.ts +19 -0
  31. package/dist/controls/tooltip.js +84 -0
  32. package/dist/controls/typed.d.ts +28 -0
  33. package/dist/controls/typed.js +126 -0
  34. package/dist/element.d.ts +40 -0
  35. package/dist/element.js +78 -0
  36. package/dist/host.d.ts +99 -0
  37. package/dist/host.js +1 -0
  38. package/dist/icons/index.d.ts +7 -0
  39. package/dist/icons/index.js +31 -0
  40. package/dist/icons/lucide.d.ts +851 -0
  41. package/dist/icons/lucide.js +90 -0
  42. package/dist/index.d.ts +18 -0
  43. package/dist/index.js +16 -0
  44. package/dist/keys.d.ts +30 -0
  45. package/dist/keys.js +122 -0
  46. package/dist/mount.d.ts +11 -0
  47. package/dist/mount.js +96 -0
  48. package/dist/options.d.ts +152 -0
  49. package/dist/options.js +78 -0
  50. package/dist/palette.d.ts +6 -0
  51. package/dist/palette.js +9 -0
  52. package/dist/picker/handles.d.ts +7 -0
  53. package/dist/picker/handles.js +8 -0
  54. package/dist/picker/index.d.ts +21 -0
  55. package/dist/picker/index.js +20 -0
  56. package/dist/picker/palette.d.ts +8 -0
  57. package/dist/picker/palette.js +14 -0
  58. package/dist/picker/picker.d.ts +63 -0
  59. package/dist/picker/picker.js +561 -0
  60. package/dist/picker/solid-editor.d.ts +60 -0
  61. package/dist/picker/solid-editor.js +330 -0
  62. package/dist/picker/stop-bar.d.ts +27 -0
  63. package/dist/picker/stop-bar.js +140 -0
  64. package/dist/prefs.d.ts +6 -0
  65. package/dist/prefs.js +34 -0
  66. package/dist/recents.d.ts +9 -0
  67. package/dist/recents.js +140 -0
  68. package/dist/root.d.ts +31 -0
  69. package/dist/root.js +526 -0
  70. package/dist/scheduler.d.ts +21 -0
  71. package/dist/scheduler.js +132 -0
  72. package/dist/strings.d.ts +284 -0
  73. package/dist/strings.js +287 -0
  74. package/dist/surface.d.ts +27 -0
  75. package/dist/surface.js +8 -0
  76. package/dist/surfaces/context-menu/index.d.ts +2 -0
  77. package/dist/surfaces/context-menu/index.js +2 -0
  78. package/dist/surfaces/context-menu/items.d.ts +14 -0
  79. package/dist/surfaces/context-menu/items.js +38 -0
  80. package/dist/surfaces/context-menu/menu.d.ts +16 -0
  81. package/dist/surfaces/context-menu/menu.js +135 -0
  82. package/dist/surfaces/pane/index.d.ts +16 -0
  83. package/dist/surfaces/pane/index.js +19 -0
  84. package/dist/surfaces/pane/model.d.ts +41 -0
  85. package/dist/surfaces/pane/model.js +139 -0
  86. package/dist/surfaces/pane/outlet.d.ts +16 -0
  87. package/dist/surfaces/pane/outlet.js +20 -0
  88. package/dist/surfaces/pane/pane.d.ts +40 -0
  89. package/dist/surfaces/pane/pane.js +1429 -0
  90. package/dist/surfaces/pane/placement.d.ts +11 -0
  91. package/dist/surfaces/pane/placement.js +62 -0
  92. package/dist/surfaces/pane/text-field.d.ts +16 -0
  93. package/dist/surfaces/pane/text-field.js +20 -0
  94. package/dist/surfaces/selection-toolbar/index.d.ts +2 -0
  95. package/dist/surfaces/selection-toolbar/index.js +2 -0
  96. package/dist/surfaces/selection-toolbar/items.d.ts +37 -0
  97. package/dist/surfaces/selection-toolbar/items.js +183 -0
  98. package/dist/surfaces/selection-toolbar/toolbar.d.ts +27 -0
  99. package/dist/surfaces/selection-toolbar/toolbar.js +956 -0
  100. package/dist/surfaces/tools/index.d.ts +2 -0
  101. package/dist/surfaces/tools/index.js +2 -0
  102. package/dist/surfaces/tools/keys.d.ts +11 -0
  103. package/dist/surfaces/tools/keys.js +21 -0
  104. package/dist/surfaces/tools/model.d.ts +48 -0
  105. package/dist/surfaces/tools/model.js +155 -0
  106. package/dist/surfaces/tools/toolbar.d.ts +27 -0
  107. package/dist/surfaces/tools/toolbar.js +502 -0
  108. package/dist/theme.d.ts +26 -0
  109. package/dist/theme.js +47 -0
  110. package/package.json +31 -3
@@ -0,0 +1,956 @@
1
+ import { css, html, noChange, nothing } from "lit";
2
+ import { applyPaintEdit } from "../../color/edit.js";
3
+ import { paintCss } from "../../color/gradient.js";
4
+ import { formatHex, parseStored } from "../../color/color.js";
5
+ import { buttonStyles } from "../../controls/buttons.js";
6
+ import { baseStyles, focused, focusWithin, keepFocus, within } from "../../controls/shared.js";
7
+ import { TypedValues } from "../../controls/typed.js";
8
+ import { swatchBackground } from "../../controls/swatch.js";
9
+ import { Tooltip, tooltipStyles } from "../../controls/tooltip.js";
10
+ import { colorOptionsFor } from "../../options.js";
11
+ import { STICKY_COLORS } from "../../palette.js";
12
+ import { canvasHandles } from "../../picker/handles.js";
13
+ import { PaintPicker, pickerTypes } from "../../picker/picker.js";
14
+ import { DEFAULT_STRINGS } from "../../strings.js";
15
+ import { CONTEXT } from "../../element.js";
16
+ import { UiSurface } from "../../surface.js";
17
+ import { rootReset, themeStyles, tok } from "../../theme.js";
18
+ import { BAR_KEYS, CONNECTOR_TYPES, connectorType, CORNERS, entryId, GEOMETRY, itemKeys, typedKeys, itemList, ITEMS, PADDINGS, sameValues, SHADOW, shortcutOf, shownMask, SIDES, stepSize, } from "./items.js";
19
+ export const SELECTION_TOOLBAR_TAG = "daas-selection-toolbar";
20
+ const OPACITY_PRESETS = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0];
21
+ const SIDE_NAMES = ["top", "right", "bottom", "left"];
22
+ const SHADOW_NAMES = ["x", "y", "blur", "spread"];
23
+ const FLOAT_GAP = 10;
24
+ const FLOAT_MARGIN = 8;
25
+ const PANEL_ICONS = { borderStyle: "border-style", lineEnds: "line-ends", moreStyles: "underline", textOptions: "line-height", shadow: "shadow", opacity: "opacity" };
26
+ const EMPTY = [];
27
+ const styles = css `:host{display: block;max-width: 100%;pointer-events: auto;}:host([hidden]){display: none;}:host([data-placement="floating"]){position: absolute;left: 0;top: 0;max-width: calc(100% - ${FLOAT_MARGIN * 2}px);}
28
+ .bar{display: flex;align-items: center;gap: 2px;max-width: 100%;padding: 4px;overflow-x: auto;scrollbar-width: thin;border: 1px solid ${tok("border")};border-radius: ${tok("radius")};background: ${tok("bg")};box-shadow: ${tok("shadow")};}
29
+ .item,.size{display: flex;align-items: center;flex: none;}
30
+ .sep{flex: none;width: 1px;height: 20px;margin: 0 4px;background: ${tok("border")};}
31
+ button{flex: none;}
32
+ button[aria-expanded="true"]{background: ${tok("accentSoft")};color: ${tok("accent")};}
33
+ .peek{flex-direction: column;gap: 1px;}
34
+ .peek .color{width: 16px;height: 4px;border: 1px solid rgba(0,0,0,0.16);}
35
+ .dot{width: 16px;height: 16px;border-radius: 50%;box-shadow: inset 0 0 0 1px rgba(0,0,0,0.16);}
36
+ .font{justify-content: space-between;width: 104px;}
37
+ .font span{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
38
+ .font span.mixed,h3{color: ${tok("muted")};}
39
+ .size daas-number-field{width: 74px;}
40
+ .size button{min-width: 26px;padding: 0 3px;}
41
+ .panel{display: flex;flex-direction: column;gap: 8px;width: 236px;padding: 6px;}
42
+ .panel.fit{width: auto;padding: 0;}
43
+ .panel:focus{outline: none;}
44
+ .row{display: flex;align-items: center;gap: 6px;}
45
+ .row > daas-number-field,.row > daas-select,.grid > *{flex: 1;min-width: 0;}
46
+ .grid{display: grid;grid-template-columns: repeat(2,minmax(0,1fr));gap: 6px;}
47
+ .color-row{justify-content: flex-start;gap: 8px;width: 100%;padding: 0 6px;background: ${tok("bg2")};}
48
+ h3{margin: 0;font-size: 11px;font-weight: 600;}
49
+ .swatches{display: flex;gap: 4px;}
50
+ .presets{display: grid;grid-template-columns: repeat(4,1fr);gap: 2px;}
51
+ .presets button{min-width: 0;height: 28px;}
52
+ .swatches button{min-width: 0;width: 28px;height: 28px;padding: 0;border-radius: 50%;}
53
+ .swatches button[aria-pressed="true"]{box-shadow: 0 0 0 2px ${tok("accent")};background: none;}
54
+ .swatches .dot{width: 22px;height: 22px;}`;
55
+ const focus = (el) => el?.focus({ preventScroll: true });
56
+ const isOff = (pv) => !!pv && pv.value !== true && !pv.mixed;
57
+ function firstFocusable(el) {
58
+ const walk = (root) => {
59
+ for (const n of root.children) {
60
+ if (n instanceof HTMLElement && !n.shadowRoot && n.tabIndex >= 0 && !n.hasAttribute("disabled") && !n.hidden)
61
+ return n;
62
+ const inner = (n.shadowRoot && walk(n.shadowRoot)) || walk(n);
63
+ if (inner)
64
+ return inner;
65
+ }
66
+ return null;
67
+ };
68
+ return walk({ children: [el] });
69
+ }
70
+ function focusFirst(el) {
71
+ const target = firstFocusable(el);
72
+ focus(target);
73
+ return !!target;
74
+ }
75
+ const GEOMETRY_KEYS = new Set(GEOMETRY);
76
+ const NO_KEYS = new Set();
77
+ const CONTROLS = "[data-roving], daas-number-field";
78
+ const fontsSig = (fonts) => fonts.map((f) => `${f.family}\t${f.label ?? ""}\t${f.weights.join(",")}\t${f.italic ? 1 : 0}`).join("\n");
79
+ const keyOf = (el) => el?.closest("[data-key]")?.dataset.key;
80
+ function layers(paints, box) {
81
+ return [...paints]
82
+ .reverse()
83
+ .map((p) => (typeof p === "string" ? `linear-gradient(${(p = formatHex(parseStored(p)))}, ${p})` : paintCss(p, box)))
84
+ .join(", ");
85
+ }
86
+ const dot = (background) => html `<span class="dot" style="background: ${background}"></span>`;
87
+ const swatchDot = (pv) => dot(swatchBackground((pv.value ?? null), !!pv.mixed));
88
+ export class SelectionToolbar extends UiSurface {
89
+ static styles = [rootReset, baseStyles, themeStyles, tooltipStyles, buttonStyles, styles];
90
+ #tooltip = new Tooltip(this);
91
+ #source = null;
92
+ #list = [];
93
+ #keys = [];
94
+ #panelKeys = NO_KEYS;
95
+ #shown = [];
96
+ #mask = [];
97
+ #barKey = "";
98
+ #barList = null;
99
+ #panel = null;
100
+ #anchor = null;
101
+ #menu = null;
102
+ #menuEntries = EMPTY;
103
+ #menuSources = {};
104
+ #shadowColor = false;
105
+ #corners = false;
106
+ #sizeOff = [false, false];
107
+ #dragging = false;
108
+ #rove = null;
109
+ #pointer = false;
110
+ #escape = false;
111
+ #panelKeyboard = false;
112
+ #menuKeyboard = false;
113
+ #resize = null;
114
+ #size = { w: 0, h: 0 };
115
+ #board = { w: 0, h: 0 };
116
+ #rendered = null;
117
+ #own = false;
118
+ #barVersion = 0;
119
+ #panelOnly = false;
120
+ #hold = null;
121
+ #relisted = false;
122
+ #typed = new TypedValues(() => this.renderRoot, keyOf);
123
+ #scoped = null;
124
+ #fonts = [];
125
+ #fontsSig = "";
126
+ #fontsRef = null;
127
+ #fontsRevision = -1;
128
+ #typedKeys = [];
129
+ #settled = null;
130
+ moving = false;
131
+ connectedCallback() {
132
+ super.connectedCallback();
133
+ this.addEventListener("pointerdown", this.#onInput, true);
134
+ this.addEventListener("keydown", this.#onInput, true);
135
+ this.addEventListener("blur", this.#onBlur);
136
+ this.#typed.listen(this);
137
+ }
138
+ disconnectedCallback() {
139
+ this.removeEventListener("pointerdown", this.#onInput, true);
140
+ this.removeEventListener("keydown", this.#onInput, true);
141
+ this.removeEventListener("blur", this.#onBlur);
142
+ this.#typed.unlisten(this);
143
+ this.#observe(false);
144
+ this.#cancel();
145
+ if (!this.moving) {
146
+ this.#hold = null;
147
+ this.#typed.end();
148
+ }
149
+ super.disconnectedCallback();
150
+ }
151
+ #onInput = (e) => {
152
+ this.#pointer = e.type === "pointerdown";
153
+ if (this.#pointer) {
154
+ this.#escape = false;
155
+ this.#tooltip.hide();
156
+ }
157
+ };
158
+ #rescope(s) {
159
+ this.#typed.rescope(s, this.#typedKeys, this.#keys);
160
+ if (s.values === this.#scoped)
161
+ return;
162
+ this.#scoped = s.values;
163
+ if (!this.#ctrl.hasPreview()) {
164
+ this.#settled = s.values;
165
+ for (const p of this.renderRoot.querySelectorAll("#panel daas-paint-picker[data-key]")) {
166
+ p.value = this.#paint(p.dataset.key);
167
+ p.settle();
168
+ }
169
+ }
170
+ }
171
+ #onBlur = () => {
172
+ if (!this.#hold)
173
+ this.removeAttribute("tabindex");
174
+ };
175
+ updated() {
176
+ if (this.#relisted) {
177
+ this.#relisted = false;
178
+ const trigger = this.#panel && this.#trigger(this.#panel === "location" ? "more" : this.#panel);
179
+ if (trigger && trigger !== this.#anchor)
180
+ this.#popover()?.reanchor((this.#anchor = trigger));
181
+ }
182
+ if (this.#hold)
183
+ queueMicrotask(this.#settle);
184
+ }
185
+ #settle = () => {
186
+ const hold = this.#hold;
187
+ if (!hold || this.moving)
188
+ return;
189
+ if (hold.on === this ? this.#inner() !== null : focused(this.ownerDocument) !== hold.on) {
190
+ this.#hold = null;
191
+ if (this.#inner() === undefined)
192
+ this.removeAttribute("tabindex");
193
+ return;
194
+ }
195
+ const c = this.#control(hold.item);
196
+ this.#hold = null;
197
+ focus(c);
198
+ if (c && focusWithin(c))
199
+ return;
200
+ if (!c || !this.style.visibility)
201
+ this.state?.host.returnFocus();
202
+ else
203
+ this.#hold = hold;
204
+ };
205
+ #where() {
206
+ const inner = this.#inner();
207
+ if (inner === undefined)
208
+ return null;
209
+ const entry = inner?.closest(".bar [data-entry]");
210
+ const el = focused(this.ownerDocument) ?? inner ?? this;
211
+ return entry ? [entry.dataset.entry, [...entry.querySelectorAll(CONTROLS)].indexOf(inner), el] : [null, -1, el, keyOf(inner)];
212
+ }
213
+ #control([id, at, el, key]) {
214
+ if (id === null)
215
+ return this.#panelFallback(key, this.state.values) ?? (el.isConnected && within(this, el) && !el.matches(":disabled") ? el : this.#popover()?.open ? this.renderRoot.querySelector("#panel .panel") : null);
216
+ const entry = this.renderRoot.querySelector(`.bar [data-entry="${id}"]`);
217
+ if (!entry)
218
+ return null;
219
+ if (el.isConnected && within(entry, el) && !el.matches(":disabled"))
220
+ return el;
221
+ const c = entry.querySelectorAll(CONTROLS)[at];
222
+ const on = c && !c.matches(":disabled") && (c.matches("[data-roving]") ? c : firstFocusable(c));
223
+ return on || entry.querySelector("[data-roving]:not(:disabled)") || firstFocusable(entry);
224
+ }
225
+ #panelFallback(key, values) {
226
+ if (!key || !this.#panel)
227
+ return null;
228
+ if (!(key in values) || (!("radius" in values) && CORNERS.includes(key)))
229
+ return this.renderRoot.querySelector("#panel .panel");
230
+ return key !== "shadowOn" && this.#panel === "shadow" && isOff(values.shadowOn) ? firstFocusable(this.renderRoot.querySelector('#panel [data-key="shadowOn"]')) : null;
231
+ }
232
+ startMove(park) {
233
+ this.moving = true;
234
+ const item = this.#hold?.item ?? this.#where();
235
+ this.#hold = item && { item, on: park };
236
+ }
237
+ moved() {
238
+ this.moving = false;
239
+ const pop = this.#popover();
240
+ if (this.#panel && pop && !pop.open && this.#anchor?.isConnected)
241
+ pop.show(this.#anchor);
242
+ this.#settle();
243
+ }
244
+ release(park) {
245
+ if (this.#hold?.on !== park)
246
+ return false;
247
+ this.#hold = null;
248
+ return true;
249
+ }
250
+ keys() {
251
+ const o = (this.ui ?? this[CONTEXT])?.options.selectionToolbar ?? this.state?.options.selectionToolbar;
252
+ const items = o ? o.items : undefined;
253
+ if (items !== this.#source || this.#list.length === 0) {
254
+ this.#source = items;
255
+ this.#list = itemList(items);
256
+ this.#keys = itemKeys(this.#list);
257
+ this.#typedKeys = typedKeys(this.#list);
258
+ const bar = new Set([...BAR_KEYS, ...this.#list.flatMap((e) => (typeof e === "object" ? (e.requires ?? []) : []))]);
259
+ this.#panelKeys = new Set(this.#keys.filter((k) => !bar.has(k)));
260
+ }
261
+ return this.#keys;
262
+ }
263
+ requestUpdate(...args) {
264
+ if (args[0] === undefined && #own in this)
265
+ this.#own = true;
266
+ super.requestUpdate(...args);
267
+ }
268
+ shouldUpdate(changed) {
269
+ const own = this.#own;
270
+ this.#own = false;
271
+ const last = this.#rendered;
272
+ const s = this.state;
273
+ if (s)
274
+ this.#rescope(s);
275
+ const change = own || !last || !s || changed.size !== 1 || !changed.has("state") ? "all" : this.#change(last, s);
276
+ if (change === "all")
277
+ this.#barVersion++;
278
+ this.#panelOnly = change === "panel";
279
+ return change !== "same";
280
+ }
281
+ #takeFonts(s) {
282
+ const fonts = s.host.fonts();
283
+ if (fonts === this.#fontsRef && s.revision === this.#fontsRevision)
284
+ return;
285
+ this.#fontsRef = fonts;
286
+ this.#fontsRevision = s.revision;
287
+ const sig = fontsSig(fonts);
288
+ if (sig === this.#fontsSig)
289
+ return;
290
+ this.#fontsSig = sig;
291
+ this.#fonts = [...fonts];
292
+ }
293
+ #change(last, s) {
294
+ const a = last.state;
295
+ if (s.options !== a.options || s.readOnly !== a.readOnly || s.textSession !== a.textSession || s.gesture !== a.gesture)
296
+ return "all";
297
+ if (s.targets.length !== a.targets.length || s.targets.some((o, i) => o !== a.targets[i] || o.version !== last.versions[i]))
298
+ return "all";
299
+ const fonts = s.host.fonts();
300
+ if (fonts !== last.fonts)
301
+ return "all";
302
+ if (s.revision !== this.#fontsRevision && fonts === this.#fontsRef) {
303
+ if (fontsSig(fonts) !== this.#fontsSig)
304
+ return "all";
305
+ this.#fontsRevision = s.revision;
306
+ }
307
+ if (this.dataset.placement === "floating" && !s.gesture && JSON.stringify(last.rect) !== JSON.stringify(s.host.selectionRect()))
308
+ return "all";
309
+ if (!sameValues(a.values, s.values, this.#keys, this.#panelKeys))
310
+ return "all";
311
+ return sameValues(a.values, s.values, this.#panelKeys, this.#panel === "location" ? NO_KEYS : GEOMETRY_KEYS) ? "same" : "panel";
312
+ }
313
+ willUpdate() {
314
+ const s = this.state;
315
+ if (!s)
316
+ return;
317
+ if (this.#panelOnly) {
318
+ this.#rendered = { ...this.#rendered, state: s };
319
+ return;
320
+ }
321
+ this.keys();
322
+ const o = s.options.selectionToolbar;
323
+ const p = o && o.placement;
324
+ const placement = typeof p === "object" && p ? "container" : p === "floating" ? "floating" : "top";
325
+ if ((placement === "floating") !== !!this.#resize)
326
+ this.#observe(placement === "floating");
327
+ this.dataset.placement = placement;
328
+ const rect = placement === "floating" && !s.gesture ? s.host.selectionRect() : null;
329
+ this.#rendered = { state: s, versions: s.targets.map((o) => o.version), rect, fonts: s.host.fonts() };
330
+ this.#takeFonts(s);
331
+ const visible = !s.readOnly && (placement !== "floating" || !!rect);
332
+ if (!visible)
333
+ this.#cancel();
334
+ const mask = visible ? shownMask(this.#list, s.values, s.targets, s.textSession) : [];
335
+ const shown = this.#list.filter((_, i) => mask[i]);
336
+ const size = s.values.fontSize;
337
+ const n = size && !size.mixed ? Number(size.value) : NaN;
338
+ const typed = this.renderRoot.querySelector(".size daas-number-field")?.draftValue ?? n;
339
+ this.#sizeOff = [Math.max(n, typed) <= (size?.descriptor.min ?? 1), Math.min(n, typed) >= (size?.descriptor.max ?? 999)];
340
+ this.#keepFocus(shown, s.textSession, s.values);
341
+ if (this.#list !== this.#barList) {
342
+ const item = this.#where();
343
+ if (item?.[0]) {
344
+ this.#hold = { item, on: this };
345
+ this.tabIndex = -1;
346
+ focus(this);
347
+ }
348
+ this.#barList = this.#list;
349
+ this.#relisted = true;
350
+ }
351
+ this.#shown = shown;
352
+ this.#mask = mask;
353
+ this.hidden = shown.length === 0;
354
+ if (rect && !this.hidden)
355
+ this.#float(rect);
356
+ else
357
+ this.style.transform = this.style.visibility = "";
358
+ }
359
+ #inner() {
360
+ let a = this.ownerDocument.activeElement;
361
+ while (a && a !== this)
362
+ a = a.shadowRoot?.activeElement ?? null;
363
+ if (!a)
364
+ return undefined;
365
+ try {
366
+ return this.shadowRoot.activeElement;
367
+ }
368
+ catch {
369
+ return null;
370
+ }
371
+ }
372
+ #focusedEntry() {
373
+ const inner = this.#inner();
374
+ if (inner === undefined)
375
+ return null;
376
+ const entry = inner?.closest("[data-entry]");
377
+ return entry ? entry.dataset.entry : inner?.closest("#panel") ? (this.#panel === "location" ? "more" : (this.#panel ?? "")) : "";
378
+ }
379
+ #trigger(entry) {
380
+ return this.renderRoot.querySelector(`[data-entry="${entry}"] [data-roving]`);
381
+ }
382
+ #focusEntry(id) {
383
+ const entry = this.renderRoot.querySelector(`.bar [data-entry="${id}"]`);
384
+ const on = entry?.querySelector("[data-roving]:not(:disabled)");
385
+ if (on)
386
+ focus(on);
387
+ else if (entry)
388
+ focusFirst(entry);
389
+ return !!entry && focusWithin(entry);
390
+ }
391
+ #keepFocus(shown, textSession, values) {
392
+ const ids = new Set(shown.filter((e) => e !== "|").map(entryId));
393
+ const panelItem = this.#panel === "location" ? "more" : this.#panel;
394
+ const focused = this.#focusedEntry();
395
+ if (focused !== null && !(focused !== "" ? ids.has(focused) : ids.size > 0)) {
396
+ const order = this.#shown.filter((e) => typeof e === "string" && e !== "|");
397
+ const at = order.indexOf(focused);
398
+ const next = textSession || at < 0 ? [] : [...order.slice(at + 1), ...order.slice(0, at).reverse()].filter((id) => ids.has(id));
399
+ if (!next.some((id) => this.#focusEntry(id)))
400
+ this.state?.host.returnFocus();
401
+ }
402
+ else if (focused !== null && panelItem && ids.has(panelItem)) {
403
+ focus(this.#panelFallback(keyOf(this.#inner()), values));
404
+ }
405
+ const steps = [...this.renderRoot.querySelectorAll(".size [data-roving]")];
406
+ const at = steps.indexOf(this.#inner());
407
+ if (at >= 0 && this.#sizeOff[at]) {
408
+ if (this.#sizeOff[1 - at])
409
+ focusFirst(this.renderRoot.querySelector(".size daas-number-field"));
410
+ else
411
+ focus(steps[1 - at]);
412
+ }
413
+ if (panelItem && !ids.has(panelItem))
414
+ this.#closePanel(false);
415
+ else if (this.#panel === "location" && !("x" in values)) {
416
+ if (focusWithin(this.#popover()))
417
+ focus(this.#trigger("more"));
418
+ this.#closePanel(false);
419
+ }
420
+ }
421
+ #observe(on) {
422
+ this.#resize?.disconnect();
423
+ this.#resize = null;
424
+ const RO = this.ownerDocument.defaultView?.ResizeObserver;
425
+ if (!on || !RO)
426
+ return;
427
+ this.#resize = new RO((entries) => {
428
+ for (const e of entries)
429
+ Object.assign(e.target === this ? this.#size : this.#board, { w: e.contentRect.width, h: e.contentRect.height });
430
+ this.requestUpdate();
431
+ });
432
+ this.#resize.observe(this);
433
+ if (this.parentElement)
434
+ this.#resize.observe(this.parentElement);
435
+ }
436
+ #float(r) {
437
+ const { w, h } = this.#size;
438
+ const board = this.#board;
439
+ const x = Math.max(FLOAT_MARGIN, Math.min(r.x + r.w / 2 - w / 2, board.w - w - FLOAT_MARGIN));
440
+ let y = r.y - FLOAT_GAP - h;
441
+ const below = y < FLOAT_MARGIN;
442
+ if (below) {
443
+ y = r.y + r.h + FLOAT_GAP;
444
+ if (y + h > board.h - FLOAT_MARGIN)
445
+ y = Math.max(FLOAT_MARGIN, board.h - h - FLOAT_MARGIN);
446
+ }
447
+ this.dataset.side = below ? "below" : "above";
448
+ this.style.transform = `translate(${Math.round(x)}px, ${Math.round(y)}px)`;
449
+ this.style.visibility = w > 0 ? "" : "hidden";
450
+ }
451
+ get #ctrl() {
452
+ return this.state.host.controller;
453
+ }
454
+ #value(key) {
455
+ return this.state?.values[key];
456
+ }
457
+ #writable() {
458
+ const s = this.state;
459
+ return !!s && !s.readOnly && !s.host.readOnly();
460
+ }
461
+ #set(patch) {
462
+ this.#cancel();
463
+ if (this.#writable())
464
+ this.#ctrl.set(patch);
465
+ }
466
+ #pick(patch) {
467
+ this.#set(patch);
468
+ if (this.#pointer)
469
+ this.#panelKeyboard = false;
470
+ }
471
+ #preview(patch) {
472
+ if (!this.#writable())
473
+ return this.#cancel();
474
+ this.#dragging = true;
475
+ this.#ctrl.preview(patch);
476
+ }
477
+ #commit(patch, from) {
478
+ const ctrl = this.#ctrl;
479
+ const typed = this.#typed.take(from);
480
+ if (!this.#writable() || (!this.#dragging && typed && this.#typed.stale(typed))) {
481
+ if (from instanceof PaintPicker)
482
+ from.revert();
483
+ return this.#cancel();
484
+ }
485
+ if (!this.#dragging)
486
+ return ctrl.set(patch);
487
+ this.#dragging = false;
488
+ ctrl.preview(patch);
489
+ ctrl.commitPreview();
490
+ }
491
+ #cancel = () => {
492
+ if (!this.#dragging)
493
+ return;
494
+ this.#dragging = false;
495
+ this.state?.host.controller.cancelPreview();
496
+ };
497
+ #paint(key) {
498
+ const values = this.#settled ?? this.state.values;
499
+ const fills = key === "fill" && values.fills;
500
+ const pv = values[key];
501
+ return ((fills ? (fills.mixed ? fills.values?.[0] : fills.value)?.at(-1) : pv?.mixed ? pv.values?.[0] : pv?.value) ?? null);
502
+ }
503
+ #storedPaint(key) {
504
+ const d = this.#value(key)?.descriptor;
505
+ const o = d && this.#ctrl.targets().find((t) => d.appliesTo(t));
506
+ if (!o)
507
+ return null;
508
+ const fills = key === "fill" ? this.#value("fills")?.descriptor : undefined;
509
+ return ((fills ? fills.read(o)?.at(-1) : d.read(o)) ?? null);
510
+ }
511
+ #paintPatch(key, edit) {
512
+ const paint = this.#storedPaint(key);
513
+ return (o) => ({ [key]: applyPaintEdit(edit, paint, { w: o.w, h: o.h }) ?? undefined });
514
+ }
515
+ #on(key) {
516
+ const pv = this.#value(key);
517
+ return pv?.value === true && !pv.mixed;
518
+ }
519
+ #first(key) {
520
+ const pv = this.#value(key);
521
+ return pv?.mixed ? pv.values?.[0] : pv?.value;
522
+ }
523
+ runCommand(command) {
524
+ const s = this.state;
525
+ if (!s || !this.#writable() || s.targets.length === 0 || s.textSession)
526
+ return false;
527
+ if (command === "locationAndSize")
528
+ return this.#openLocation(true);
529
+ if (command === "lock") {
530
+ if (!s.values.locked)
531
+ return false;
532
+ this.#set({ locked: !this.#on("locked") });
533
+ return true;
534
+ }
535
+ const spec = s.host.controller.commands[command];
536
+ if (!spec?.canRun())
537
+ return false;
538
+ this.#cancel();
539
+ spec.run();
540
+ return true;
541
+ }
542
+ #redraw = () => this.requestUpdate();
543
+ #fieldKey = (e) => {
544
+ if (e.key === "Enter" && !e.isComposing && this.state?.textSession)
545
+ this.state.host.returnFocus();
546
+ };
547
+ #popover() {
548
+ return this.renderRoot.querySelector("#panel");
549
+ }
550
+ async #openPanel(panel, anchor, keyboard) {
551
+ const pop = this.#popover();
552
+ if (pop.open && this.#panel === panel)
553
+ return this.#closePanel(keyboard);
554
+ if (pop.open)
555
+ pop.hide();
556
+ this.#tooltip.hide();
557
+ this.#panel = panel;
558
+ this.#anchor = anchor;
559
+ const from = focused(this.ownerDocument);
560
+ this.requestUpdate();
561
+ await this.updateComplete;
562
+ const at = this.#anchor;
563
+ if (this.#panel !== panel || !at?.isConnected)
564
+ return;
565
+ if (!pop.open) {
566
+ pop.toggle(at);
567
+ if (!pop.open) {
568
+ this.#panel = null;
569
+ return void this.requestUpdate();
570
+ }
571
+ this.requestUpdate();
572
+ }
573
+ else if (!this.#hold && ![from, at].includes(focused(this.ownerDocument)))
574
+ return;
575
+ this.#panelKeyboard = keyboard;
576
+ const first = keyboard ? this.renderRoot.querySelector("#panel [data-first]") : null;
577
+ const to = (first && firstFocusable(first)) || this.renderRoot.querySelector("#panel .panel");
578
+ if (this.#hold)
579
+ this.#hold.item = [null, -1, to];
580
+ else
581
+ focus(to);
582
+ }
583
+ #openLocation(keyboard) {
584
+ const anchor = this.#trigger("more");
585
+ if (!anchor || !("x" in this.state.values))
586
+ return false;
587
+ void this.#openPanel("location", anchor, keyboard);
588
+ return true;
589
+ }
590
+ #closePanel(keyboard) {
591
+ this.#toAnchor(keyboard);
592
+ this.#popover()?.hide();
593
+ this.#panel = null;
594
+ this.requestUpdate();
595
+ }
596
+ #toAnchor(keyboard) {
597
+ if (keyboard && !this.state?.textSession && focusWithin(this.#popover()))
598
+ focus(this.#anchor);
599
+ }
600
+ #onPanelClose = () => {
601
+ if (this.moving)
602
+ return;
603
+ this.#toAnchor(this.#escape && this.#panelKeyboard);
604
+ this.#escape = false;
605
+ this.#panel = null;
606
+ this.#shadowColor = false;
607
+ this.requestUpdate();
608
+ };
609
+ #label(key) {
610
+ const label = this.#value(key)?.descriptor.label ?? key;
611
+ return this.ui?.options.strings.label(key, label) ?? label;
612
+ }
613
+ #colorText(pv) {
614
+ const p = pv.value;
615
+ return pv.mixed ? this.t("value.mixed") : p == null ? this.t("value.none") : typeof p === "string" ? formatHex(parseStored(p)) : this.t(p.type === "linear" ? "paint.linear" : "paint.radial");
616
+ }
617
+ #barKeys = (e) => {
618
+ if (this.state?.host.allowsKey?.(e) === false)
619
+ return;
620
+ const origin = e.composedPath()[0];
621
+ const els = [...this.renderRoot.querySelectorAll(".bar [data-roving]:not(:disabled)")];
622
+ const at = els.indexOf(origin);
623
+ if (at < 0)
624
+ return;
625
+ const to = e.key === "ArrowRight" ? at + 1 : e.key === "ArrowLeft" ? at - 1 : e.key === "Home" ? 0 : e.key === "End" ? els.length - 1 : null;
626
+ if (to !== null) {
627
+ e.preventDefault();
628
+ els[(to + els.length) % els.length].focus();
629
+ }
630
+ else if (e.key === "ArrowDown" && origin.hasAttribute("aria-haspopup")) {
631
+ e.preventDefault();
632
+ origin.click();
633
+ }
634
+ else
635
+ this.#tooltip.key(e);
636
+ };
637
+ #button(entry, o, click) {
638
+ return html `<button part="item" class=${o.cls ?? ""} data-roving tabindex=${this.#rove === entry ? 0 : -1} aria-label=${o.label} aria-pressed=${o.pressed ?? nothing} aria-haspopup=${o.popup ?? nothing} aria-expanded=${o.popup ? !!o.open : nothing} aria-keyshortcuts=${this.shortcutAria(o.shortcut) || nothing} data-tip=${o.label} data-shortcut=${this.shortcutText(o.shortcut) || nothing} ?disabled=${o.disabled} @pointerdown=${keepFocus} @mousedown=${keepFocus} @pointerenter=${this.#tooltip.enter} @pointerleave=${this.#tooltip.leave} @focus=${(e) => {
639
+ this.#rove = entry;
640
+ for (const b of this.renderRoot.querySelectorAll(".bar [data-roving]"))
641
+ b.tabIndex = b === e.currentTarget ? 0 : -1;
642
+ this.#tooltip.focus(e);
643
+ }} @blur=${this.#tooltip.leave} @click=${(e) => {
644
+ click(e);
645
+ if (!o.popup && e.detail && focusWithin(this))
646
+ this.state?.host.returnFocus();
647
+ }}>${o.icon ? this.drawIcon(o.icon) : nothing}${o.content ?? nothing}</button>`;
648
+ }
649
+ #panelButton(panel, o) {
650
+ return this.#button(panel === "location" ? "more" : panel, { ...o, popup: "dialog", open: this.#panel === panel }, (e) => void this.#openPanel(panel, e.currentTarget, e.detail === 0));
651
+ }
652
+ #peek(item) {
653
+ const pv = this.#value(item);
654
+ const box = this.#box(item);
655
+ const fills = item === "fill" ? this.#value("fills") : undefined;
656
+ const stack = !!fills && (fills.mixed ? (fills.values ?? []).some((v) => Array.isArray(v) && v.length > 1) : Array.isArray(fills.value) && fills.value.length > 1);
657
+ const solid = !stack && !pv.mixed && typeof pv.value === "string" ? formatHex(parseStored(pv.value)) : null;
658
+ const background = solid && solid.length === 7 ? solid : stack && !fills.mixed ? layers(fills.value, box) : swatchBackground((pv.value ?? null), !!pv.mixed || stack, box);
659
+ const label = `${this.#label(item)}: ${stack ? this.t("selection.multipleFills") : this.#colorText(pv)}`;
660
+ return this.#panelButton(item, { label, cls: "peek", content: html `${this.drawIcon(item === "textColor" ? "text-color" : item)}<span class="color" style="background: ${background}"></span>` });
661
+ }
662
+ #box(key) {
663
+ const d = this.#value(key)?.descriptor;
664
+ const o = this.state?.targets.find((t) => !d || d.appliesTo(t));
665
+ return o ? { w: o.w, h: o.h } : { w: 1, h: 1 };
666
+ }
667
+ #item(e) {
668
+ if (typeof e !== "string")
669
+ return this.#custom(e);
670
+ const v = (k) => this.#value(k);
671
+ switch (e) {
672
+ case "stickyColor":
673
+ return this.#panelButton(e, { label: this.#panelLabel(e), content: swatchDot(v("fill")) });
674
+ case "fill":
675
+ case "stroke":
676
+ case "textColor":
677
+ return this.#peek(e);
678
+ case "connectorType":
679
+ case "list": {
680
+ const conn = e === "connectorType";
681
+ const pv = conn ? null : v("list");
682
+ const current = conn ? connectorType(v("route"), v("bendRadius")) : pv.mixed ? null : String(pv.value ?? "none");
683
+ const kind = conn ? "connector" : "list";
684
+ const icon = conn ? (current ?? "rounded") : !current || current === "none" ? "bullet" : current;
685
+ return this.#menuItem(e, `${kind}-${icon}`, this.#panelLabel(e), () => (conn ? Object.keys(CONNECTOR_TYPES) : (pv.descriptor.options ?? [])).map((o) => ({ value: o, label: this.t(`${kind}.${o}`), icon: `${kind}-${o}`, checked: o === current })), (value) => void ((conn ? value !== current : pv.mixed || pv.value !== value) && this.#set(conn ? { ...CONNECTOR_TYPES[value] } : { list: value })));
686
+ }
687
+ case "font": {
688
+ const pv = v("fontFamily");
689
+ const family = this.#fonts.find((f) => f.family === pv.value);
690
+ const name = pv.mixed ? this.t("value.mixed") : (family?.label ?? String(pv.value ?? ""));
691
+ return this.#panelButton(e, { label: `${this.#label("fontFamily")}: ${name}`, cls: "font", content: html `<span class=${pv.mixed ? "mixed" : ""}>${name}</span>${this.drawIcon("chevron-down", 14)}` });
692
+ }
693
+ case "fontSize":
694
+ return this.#sizeField();
695
+ case "bold":
696
+ case "italic": {
697
+ const pressed = this.#on(e);
698
+ return this.#button(e, { label: this.#label(e), icon: e, pressed, shortcut: this.state.textSession ? (e === "bold" ? "Mod+B" : "Mod+I") : undefined }, () => this.#set({ [e]: !pressed }));
699
+ }
700
+ case "more":
701
+ return this.#menuItem(e, "more", this.#panelLabel(e), () => this.#moreItems(), (value) => {
702
+ if (value !== "locationAndSize")
703
+ return void this.runCommand(value);
704
+ const keyboard = this.#menuKeyboard;
705
+ queueMicrotask(() => this.#openLocation(keyboard));
706
+ });
707
+ default: {
708
+ const align = e === "align" && v("textAlign");
709
+ const icon = align ? `align-${align.mixed ? "left" : String(align.value ?? "left")}` : PANEL_ICONS[e];
710
+ return this.#panelButton(e, { label: this.#panelLabel(e), icon, pressed: e === "shadow" ? this.#on("shadowOn") : undefined });
711
+ }
712
+ }
713
+ }
714
+ #custom(e) {
715
+ const s = this.state;
716
+ try {
717
+ return e.render({ host: s.host, values: Object.fromEntries((e.requires ?? []).map((k) => [k, s.values[k]])), targets: s.targets }) ?? nothing;
718
+ }
719
+ catch (err) {
720
+ queueMicrotask(() => {
721
+ throw err;
722
+ });
723
+ return nothing;
724
+ }
725
+ }
726
+ #menuEl(id) {
727
+ return this.renderRoot.querySelector(`daas-menu[data-menu="${id}"]`);
728
+ }
729
+ async #openMenu(id, anchor, keyboard) {
730
+ const m = this.#menuEl(id);
731
+ this.#tooltip.hide();
732
+ if (m.open)
733
+ return m.hide(keyboard);
734
+ this.#menu = id;
735
+ this.#menuKeyboard = keyboard;
736
+ this.#menuEntries = this.#menuSources[id]?.() ?? EMPTY;
737
+ this.requestUpdate();
738
+ await this.updateComplete;
739
+ if (this.#menu !== id || !anchor.isConnected)
740
+ return;
741
+ if (keyboard)
742
+ await m.show(anchor, "checked");
743
+ else
744
+ m.toggle(anchor);
745
+ if (!m.open)
746
+ this.#menu = null;
747
+ this.requestUpdate();
748
+ }
749
+ #menuItem(id, icon, label, items, pick) {
750
+ this.#menuSources[id] = items;
751
+ return html `${this.#button(id, { label, icon, popup: "menu", open: this.#menuEl(id)?.open ?? false }, (e) => void this.#openMenu(id, e.currentTarget, e.detail === 0))}<daas-menu data-menu=${id} label=${label} placement="bottom-start" .items=${this.#menu === id ? this.#menuEntries : EMPTY} @daas-close=${() => {
752
+ if (this.#menu === id)
753
+ this.#menu = null;
754
+ this.requestUpdate();
755
+ if (!this.#menuKeyboard || this.state?.textSession)
756
+ queueMicrotask(() => this.#focusedEntry() !== null && this.state?.host.returnFocus());
757
+ }} @daas-commit=${(e) => pick(e.detail)}></daas-menu>`;
758
+ }
759
+ #moreItems() {
760
+ const s = this.state;
761
+ const entry = (name, label, more) => {
762
+ const shortcut = shortcutOf(name, s.options.shortcuts);
763
+ return { value: name, label, ...more, ...(shortcut ? { shortcut } : {}) };
764
+ };
765
+ const out = [];
766
+ if ("x" in s.values)
767
+ out.push(entry("locationAndSize", this.t("selection.locationAndSize")), "separator");
768
+ if (s.values.locked) {
769
+ const lock = this.#on("locked") ? "unlock" : "lock";
770
+ out.push(entry("lock", this.t(`command.${lock}`), { icon: lock }), "separator");
771
+ }
772
+ for (const name of ["bringToFront", "bringForward", "sendBackward", "sendToBack", "|", "duplicate", "delete"]) {
773
+ out.push(name === "|" ? "separator" : entry(name, this.t(`command.${name}`), { disabled: !s.host.controller.commands[name]?.canRun() }));
774
+ }
775
+ return out;
776
+ }
777
+ #sizeField() {
778
+ const d = this.#value("fontSize").descriptor;
779
+ const min = d.min ?? 1;
780
+ const max = d.max ?? 999;
781
+ const step = (dir) => () => {
782
+ this.#typed.commitDraftOf(this.renderRoot.querySelector(".size daas-number-field"));
783
+ if (!this.state.textSession) {
784
+ return this.#set((o) => {
785
+ if (!d.appliesTo(o))
786
+ return {};
787
+ const n = Number(d.read(o));
788
+ const next = stepSize(n, dir, min, max);
789
+ return next !== n ? { fontSize: next } : {};
790
+ });
791
+ }
792
+ const pv = this.#ctrl.read(["fontSize"]).fontSize;
793
+ const value = Number(pv?.mixed ? pv.values?.[0] : pv?.value);
794
+ const next = stepSize(value, dir, min, max);
795
+ if (next !== value || pv?.mixed)
796
+ this.#set({ fontSize: next });
797
+ };
798
+ return html `<div class="size" data-entry="fontSize" role="group" aria-label=${this.#label("fontSize")} @input=${this.#redraw} @keyup=${this.#redraw} @focusout=${this.#redraw}>${this.#button("fontSize", { label: this.t("selection.sizeDown"), icon: "minus", disabled: this.#sizeOff[0] }, step(-1))}${this.#number("fontSize", { icon: "tool-text", precision: 1 })}${this.#button("fontSize+", { label: this.t("selection.sizeUp"), icon: "plus", disabled: this.#sizeOff[1] }, step(1))}</div>`;
799
+ }
800
+ render() {
801
+ const s = this.state;
802
+ if (!s || this.#shown.length === 0)
803
+ return this.#tooltip.template();
804
+ const roving = this.#shown.flatMap((e) => (e === "|" || typeof e !== "string" ? [] : e === "fontSize" ? ["fontSize", "fontSize+"].filter((_, i) => !this.#sizeOff[i]) : [e]));
805
+ if (!roving.includes(this.#rove))
806
+ this.#rove = roving[0] ?? null;
807
+ const key = `${this.#barVersion} ${this.#rove}`;
808
+ const bar = this.#barKey === key
809
+ ? noChange
810
+ : this.#list.map((e, i) => !this.#mask[i] ? nothing : e === "|" ? html `<span class="sep" role="separator"></span>` : e === "fontSize" ? this.#item(e) : html `<span class="item" data-entry=${entryId(e)}>${this.#item(e)}</span>`);
811
+ this.#barKey = key;
812
+ return html `<div class="bar" part="bar" role="toolbar" aria-label=${this.t(s.textSession ? "surface.textFormatting" : "surface.selection")} @keydown=${this.#barKeys}>${bar}</div><daas-popover id="panel" part="panel" placement="bottom" @daas-close=${(e) => {
813
+ if (e.target === e.currentTarget)
814
+ this.#onPanelClose();
815
+ }} @keydown=${(e) => {
816
+ this.#escape = e.key === "Escape" && !e.defaultPrevented;
817
+ }}>${this.#panel ? this.#renderPanel(this.#panel) : nothing}</daas-popover>${this.#tooltip.template()}`;
818
+ }
819
+ #renderPanel(panel) {
820
+ const values = this.state.values;
821
+ const v = (k) => values[k];
822
+ const picker = panel === "fill" || panel === "stroke" || panel === "textColor";
823
+ const bodies = {
824
+ stickyColor: () => {
825
+ const pv = v("fill");
826
+ const current = pv.mixed ? null : typeof pv.value === "string" ? formatHex(parseStored(pv.value)) : null;
827
+ return this.#presets("swatches", this.t("selection.stickyColor"), STICKY_COLORS, (c) => c.color === current, (c) => ({ fill: c.color }), (c) => dot(c.color), (c) => this.t(c.label));
828
+ },
829
+ borderStyle: () => html `<div class="row">${this.#number("strokeWidth", { icon: "border-style", unit: "px", precision: 1, first: true })}</div>${this.#select("dash", "dash")}${SIDES.some((k) => k in values) ? html `<div class="row" role="group" aria-label=${this.t("selection.sides")}>${SIDES.map((k, i) => this.#toggle(k, undefined, undefined, undefined, this.t(`side.${SIDE_NAMES[i]}`)))}</div>` : nothing}${"radius" in values
830
+ ? html `<div class="row">${this.#number("radius", { icon: "corner-radius", unit: "px" })}<daas-toggle-button data-key="radius" icon="corners" label=${this.t("selection.corners")} .pressed=${this.#corners} @daas-commit=${(e) => {
831
+ if (this.#corners && this.#inner()?.closest(".grid"))
832
+ focusFirst(e.currentTarget);
833
+ this.#corners = !this.#corners;
834
+ this.requestUpdate();
835
+ }}></daas-toggle-button></div>${this.#corners ? html `<div class="grid">${CORNERS.map((k) => this.#number(k, { icon: "corner-radius", unit: "px" }))}</div>` : nothing}`
836
+ : nothing}`,
837
+ lineEnds: () => {
838
+ const start = v("lineStart");
839
+ const end = v("lineEnd");
840
+ const swap = () => this.#set((o) => (start.descriptor.appliesTo(o) ? { lineStart: end.descriptor.read(o), lineEnd: start.descriptor.read(o) } : {}));
841
+ return html `<div class="row">${this.#select("lineStart", "arrow", true)}<daas-icon-button icon="swap" label=${this.t("selection.swap")} ?disabled=${!start.mixed && !end.mixed && start.value === end.value} @click=${swap}></daas-icon-button>${this.#select("lineEnd", "arrow")}</div>`;
842
+ },
843
+ font: () => {
844
+ const family = v("fontFamily");
845
+ const weight = values.fontWeight;
846
+ return html `<daas-font-picker data-first .fonts=${this.#fonts} .value=${family.mixed ? null : String(family.value ?? "")} .weight=${weight && !weight.mixed ? Number(weight.value) : null} .mixed=${!!family.mixed} @daas-commit=${(e) => {
847
+ const { family: f, weight: w } = e.detail;
848
+ const picked = family.mixed || f !== family.value;
849
+ const patch = picked ? { fontFamily: f } : {};
850
+ if (weight && (weight.mixed || w !== weight.value))
851
+ patch.fontWeight = w;
852
+ if (Object.keys(patch).length)
853
+ this.#set(patch);
854
+ if (picked)
855
+ this.#closePanel(!this.#pointer);
856
+ }}></daas-font-picker>`;
857
+ },
858
+ moreStyles: () => {
859
+ const session = this.state.textSession;
860
+ return html `<div class="row">${this.#toggle("underline", "underline", session ? "Mod+U" : undefined, true)}${this.#toggle("strike", "strike", session ? "Mod+Shift+X" : undefined)}</div>${this.#segments("textCase", "case")}`;
861
+ },
862
+ textOptions: () => html `<div class="grid">${this.#number("lineHeight", { icon: "line-height", first: true })}${this.#number("letterSpacing", { icon: "letter-spacing", unit: "px", precision: 1 })}</div>${PADDINGS.some((k) => k in values) ? html `<h3>${this.t("selection.padding")}</h3><div class="grid">${PADDINGS.map((k, i) => this.#number(k, { label: this.t(`side.${SIDE_NAMES[i]}.short`), unit: "px" }))}</div>` : nothing}`,
863
+ align: () => html `${this.#segments("textAlign", "align", true)}${this.#segments("valign", "valign")}`,
864
+ shadow: () => {
865
+ const off = isOff(v("shadowOn"));
866
+ const color = values.shadowColor;
867
+ const open = this.#shadowColor;
868
+ const text = color && this.#colorText(color);
869
+ return html `<div class="row">${this.#toggle("shadowOn", "shadow", undefined, true, this.#label("shadowOn"))}</div><div class="grid">${SHADOW.map((k, i) => this.#number(k, { label: this.t(`shadow.${SHADOW_NAMES[i]}.short`), unit: "px", precision: 1, disabled: off }))}</div>${color
870
+ ? html `<button class="color-row" data-key="shadowColor" aria-label=${`${this.#label("shadowColor")}: ${text}`} aria-haspopup="dialog" aria-expanded=${open} ?disabled=${off} @pointerdown=${keepFocus} @mousedown=${keepFocus} @click=${(e) => {
871
+ const pop = this.renderRoot.querySelector("#shadow-color");
872
+ const anchor = e.currentTarget;
873
+ const keyboard = e.detail === 0;
874
+ if (!pop)
875
+ return;
876
+ if (pop.open)
877
+ return pop.hide();
878
+ this.#shadowColor = true;
879
+ this.requestUpdate();
880
+ void this.updateComplete.then(() => {
881
+ if (!anchor.isConnected)
882
+ return;
883
+ pop.toggle(anchor);
884
+ const picker = pop.open && keyboard ? pop.querySelector("daas-paint-picker") : null;
885
+ if (picker)
886
+ focusFirst(picker);
887
+ });
888
+ }}>${swatchDot(color)}${text}</button><daas-popover id="shadow-color" data-key="shadowColor" placement="right-start" @daas-close=${() => {
889
+ this.#shadowColor = false;
890
+ this.requestUpdate();
891
+ }}>${open ? this.#picker("shadowColor") : nothing}</daas-popover>`
892
+ : nothing}`;
893
+ },
894
+ opacity: () => {
895
+ const pv = v("opacity");
896
+ return html `<div class="row">${this.#number("opacity", { icon: "opacity", unit: "%", scale: 100, step: 1, precision: 0, first: true })}</div>${this.#presets("presets", this.t("selection.presets"), OPACITY_PRESETS, (p) => !pv.mixed && pv.value === p / 100, (p) => ({ opacity: p / 100 }), (p) => `${p}%`)}`;
897
+ },
898
+ location: () => html `<div class="grid">${GEOMETRY.map((k, i) => (k === "rotation" ? this.#number(k, { icon: "rotation", unit: "°", precision: 1 }) : this.#number(k, { label: k.toUpperCase(), unit: "px", first: i === 0 })))}</div>`,
899
+ };
900
+ const label = panel === "location" ? this.t("selection.locationAndSize") : this.#panelLabel(panel);
901
+ return html `<div class="panel ${picker || panel === "font" ? "fit" : ""}" role="dialog" aria-label=${label} tabindex="-1">${picker ? this.#picker(panel) : bodies[panel]?.()}</div>`;
902
+ }
903
+ #panelLabel(panel) {
904
+ const own = `selection.${panel}`;
905
+ return own in DEFAULT_STRINGS ? this.t(own) : this.#label(ITEMS[panel].requires[0]);
906
+ }
907
+ #number(key, o = {}) {
908
+ const pv = this.#value(key);
909
+ if (!pv)
910
+ return nothing;
911
+ const d = pv.descriptor;
912
+ const scale = o.scale ?? 1;
913
+ const v = Number(this.#first(key));
914
+ return html `<daas-number-field ?data-first=${o.first} data-key=${key} label=${o.label ?? ""} label-icon=${o.icon ?? nothing} name=${this.#label(key)} unit=${o.unit ?? ""} .value=${Number.isFinite(v) ? Math.round(v * scale * 1000) / 1000 : null} .mixed=${!!pv.mixed} .min=${(d.min ?? -Infinity) * scale} .max=${(d.max ?? Infinity) * scale} .step=${o.step ?? (d.step ?? 1) * scale} .precision=${o.precision ?? 2} ?disabled=${o.disabled} @daas-preview=${(e) => this.#preview({ [key]: e.detail / scale })} @daas-commit=${(e) => this.#commit({ [key]: e.detail / scale }, e.currentTarget)} @daas-cancel=${this.#cancel} @keydown=${this.#fieldKey}></daas-number-field>`;
915
+ }
916
+ #segments(key, prefix, first) {
917
+ const pv = this.#value(key);
918
+ if (!pv)
919
+ return nothing;
920
+ const options = (pv.descriptor.options ?? []).map((v) => ({ value: v, label: this.t(`${prefix}.${v}`), icon: `${prefix}-${v}` }));
921
+ return html `<daas-segmented ?data-first=${first} data-key=${key} label=${this.#label(key)} .options=${options} .value=${pv.mixed ? null : String(pv.value ?? "")} @daas-commit=${(e) => this.#pick({ [key]: e.detail })}></daas-segmented>`;
922
+ }
923
+ #toggle(key, icon, shortcut, first, text) {
924
+ const pv = this.#value(key);
925
+ if (!pv)
926
+ return nothing;
927
+ return html `<daas-toggle-button ?data-first=${first} data-key=${key} icon=${icon ?? nothing} text=${text ?? nothing} label=${this.#label(key)} shortcut=${shortcut ?? nothing} .pressed=${this.#on(key)} @daas-commit=${(e) => this.#pick({ [key]: e.detail })}></daas-toggle-button>`;
928
+ }
929
+ #select(key, prefix, first) {
930
+ const pv = this.#value(key);
931
+ if (!pv)
932
+ return nothing;
933
+ const options = (pv.descriptor.options ?? []).map((v) => ({ value: v, label: this.t(`${prefix}.${v}`) }));
934
+ return html `<daas-select ?data-first=${first} data-key=${key} label=${this.#label(key)} .options=${options} .value=${pv.mixed ? null : String(pv.value)} .mixed=${!!pv.mixed || pv.value === "custom"} @daas-commit=${(e) => this.#set({ [key]: e.detail })}></daas-select>`;
935
+ }
936
+ #picker(key) {
937
+ const s = this.state;
938
+ const pv = this.#value(key);
939
+ const color = colorOptionsFor(s.options, "selectionToolbar");
940
+ const fills = key === "fill" ? this.#value("fills") : undefined;
941
+ const stack = !!fills && (fills.mixed || (Array.isArray(fills.value) && fills.value.length > 1));
942
+ const one = key === "fill" && s.targets.length === 1 ? s.targets[0] : undefined;
943
+ return html `<daas-paint-picker data-first data-key=${key} .value=${this.#paint(key)} .mixed=${!!pv.mixed || stack} .box=${this.#box(key)} .types=${pickerTypes(color, pv.descriptor.type)} .color=${color} .allowNone=${key === "fill" || key === "stroke"} .handles=${one ? canvasHandles(s.host, { id: one.id }) : null} @daas-preview=${(e) => this.#preview(this.#paintPatch(key, e.detail))} @daas-commit=${(e) => this.#commit(this.#paintPatch(key, e.detail), e.currentTarget)} @daas-cancel=${this.#cancel}></daas-paint-picker>`;
944
+ }
945
+ #presets(cls, label, values, current, patch, content, name) {
946
+ return html `<div class=${cls} role="group" aria-label=${label}>${values.map((v, i) => html `<button ?data-first=${!!name && i === 0} aria-label=${name ? name(v) : nothing} aria-pressed=${current(v)} @pointerdown=${keepFocus} @mousedown=${keepFocus} @click=${(e) => {
947
+ if (!current(v))
948
+ this.#set(patch(v));
949
+ this.#closePanel(e.detail === 0);
950
+ }}>${content(v)}</button>`)}</div>`;
951
+ }
952
+ }
953
+ export function defineSelectionToolbar() {
954
+ if (!customElements.get(SELECTION_TOOLBAR_TAG))
955
+ customElements.define(SELECTION_TOOLBAR_TAG, SelectionToolbar);
956
+ }