@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,1429 @@
1
+ import { aggregateMembers } from "@daasboard/editor";
2
+ import { sameScope, scopeOf, TypedValues } from "../../controls/typed.js";
3
+ import { css, html, noChange, nothing } from "lit";
4
+ import { AsyncDirective, directive, Directive } from "lit/async-directive.js";
5
+ import { insertPart, removePart, setChildPartValue } from "lit/directive-helpers.js";
6
+ import { guard } from "lit/directives/guard.js";
7
+ import { formatHex, parseHex, parseStored } from "../../color/color.js";
8
+ import { applyPaintEdit } from "../../color/edit.js";
9
+ import { NO_PAINT_GRAY } from "../../color/gradient.js";
10
+ import { baseStyles, cancelDragsWithin, draggingWithin, focused, focusWithin, keepFocus, within } from "../../controls/shared.js";
11
+ import { Tooltip, tooltipStyles } from "../../controls/tooltip.js";
12
+ import { colorOptionsFor } from "../../options.js";
13
+ import { canvasHandles } from "../../picker/handles.js";
14
+ import { pickerTypes } from "../../picker/picker.js";
15
+ import { DEFAULT_STRINGS } from "../../strings.js";
16
+ import { ALL_KEYS, UiSurface } from "../../surface.js";
17
+ import { tok } from "../../theme.js";
18
+ import { CORNER_KEYS, hiddenKeys, paneModel, ROWS, SECTION_IDS, SECTION_KEYS, SHADOW_KEYS, shownValues, SIDE_KEYS, STROKE_MORE_KEYS, TEXT_MORE_KEYS } from "./model.js";
19
+ export const NARROW_PX = 760;
20
+ export const NEW_LAYER = NO_PAINT_GRAY;
21
+ export const NEW_STROKE = "#000000";
22
+ const sameDeps = (a, b) => a.length === b.length && a.every((d, i) => d === b[i]);
23
+ const first = (pv) => (pv ? (pv.mixed ? pv.values?.[0] : pv.value) : undefined);
24
+ const boxOf = (o) => ({ w: o.w, h: o.h });
25
+ const hexOf = (c) => (typeof c === "string" && c ? formatHex({ ...parseStored(c), a: 1 }).slice(1).toUpperCase() : "");
26
+ const alphaOf = (c) => (typeof c === "string" && c ? parseStored(c).a : 1);
27
+ const withAlpha = (c, a) => formatHex({ ...parseStored(typeof c === "string" && c ? c : "#000000"), a });
28
+ const stack = (v) => (Array.isArray(v) ? v : []);
29
+ const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : null);
30
+ const PICKER_LESS = ["solid"];
31
+ const STACK = ["fills"];
32
+ const LAYOUT_COMMANDS = ["alignLeft", "alignCenter", "alignRight", "alignTop", "alignMiddle", "alignBottom", "distributeHorizontal", "distributeVertical"];
33
+ const CELLS = {
34
+ "text:font": ["fontFamily"],
35
+ "text:paddingSides": ["paddingTop", "paddingBottom"],
36
+ "stroke:geometry": ["strokeAlign", "strokeWidth"],
37
+ };
38
+ const MORE_KEYS = {
39
+ "appearance:opacity": CORNER_KEYS,
40
+ "text:font": ["fontWeight"],
41
+ "text:weightSize": ["fontFamily"],
42
+ "effects:shadow": SHADOW_KEYS,
43
+ };
44
+ const NUMS = {
45
+ x: ["short.x"],
46
+ y: ["short.y"],
47
+ w: ["short.w"],
48
+ h: ["short.h"],
49
+ rotation: ["rotation", 1],
50
+ opacity: ["opacity", 0, 100, 1],
51
+ radius: ["corner-radius"],
52
+ radiusTopLeft: ["short.topLeft"],
53
+ radiusTopRight: ["short.topRight"],
54
+ radiusBottomLeft: ["short.bottomLeft"],
55
+ radiusBottomRight: ["short.bottomRight"],
56
+ fontSize: ["tool-text", 1],
57
+ lineHeight: ["line-height"],
58
+ letterSpacing: ["letter-spacing"],
59
+ paddingLeft: ["short.left"],
60
+ paddingRight: ["short.right"],
61
+ paddingTop: ["short.top"],
62
+ paddingBottom: ["short.bottom"],
63
+ strokeWidth: ["border-style"],
64
+ bendRadius: ["corner-radius"],
65
+ shadowX: ["short.x"],
66
+ shadowBlur: ["short.blur"],
67
+ shadowY: ["short.y"],
68
+ shadowSpread: ["short.spread"],
69
+ };
70
+ const SEGMENT_ICONS = {
71
+ textAlign: { left: "align-left", center: "align-center", right: "align-right", justify: "align-justify" },
72
+ valign: { top: "valign-top", middle: "valign-middle", bottom: "valign-bottom" },
73
+ textCase: { none: "case-none", upper: "case-upper", lower: "case-lower" },
74
+ list: { none: "list-none", bullet: "list-bullet", number: "list-number", task: "list-task" },
75
+ };
76
+ const ADDS = { fill: ["fills", "pane.addFill"], stroke: ["stroke", "pane.addStroke"], effects: ["shadowOn", "pane.addEffect"] };
77
+ function same(a, b) {
78
+ if (a === b)
79
+ return true;
80
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null || Array.isArray(a) !== Array.isArray(b))
81
+ return false;
82
+ if (Array.isArray(a)) {
83
+ const c = b;
84
+ if (a.length !== c.length)
85
+ return false;
86
+ for (let i = 0; i < a.length; i++)
87
+ if (a[i] !== c[i] && !same(a[i], c[i]))
88
+ return false;
89
+ return true;
90
+ }
91
+ const ka = Object.keys(a);
92
+ if (ka.length !== Object.keys(b).length)
93
+ return false;
94
+ for (const k of ka)
95
+ if (!same(a[k], b[k]))
96
+ return false;
97
+ return true;
98
+ }
99
+ const samePv = (a, b) => !!a && !!b && a.descriptor === b.descriptor && a.applicable === b.applicable && !!a.mixed === !!b.mixed && (a.mixed ? same(a.values, b.values) : same(a.value, b.value));
100
+ const madeFor = (h, pvs, deps) => h.pvs.length === pvs.length && h.pvs.every((p, i) => p === pvs[i] || samePv(p, pvs[i])) && sameDeps(h.deps, deps);
101
+ const roleOf = (el) => el.getAttribute("aria-label") ?? el.getAttribute("label") ?? el.getAttribute("name");
102
+ function pathWithin(root, el) {
103
+ const path = [];
104
+ for (let n = el; n !== root;) {
105
+ const parent = n.parentNode;
106
+ if (!parent)
107
+ break;
108
+ const shadow = parent instanceof ShadowRoot;
109
+ path.unshift([n.localName, [...parent.children].filter((c) => c.localName === n.localName).indexOf(n), shadow, roleOf(n)]);
110
+ n = shadow ? parent.host : parent;
111
+ }
112
+ return path;
113
+ }
114
+ const RESCUE = Symbol("rescue");
115
+ const DRAGGING = Symbol("dragging");
116
+ class Kept extends AsyncDirective {
117
+ #part = null;
118
+ render() {
119
+ return noChange;
120
+ }
121
+ update(part) {
122
+ this.#part = part;
123
+ if (part.element.hasAttribute("disabled"))
124
+ this.#rescue();
125
+ return noChange;
126
+ }
127
+ disconnected() {
128
+ this.#rescue();
129
+ }
130
+ #rescue() {
131
+ const part = this.#part;
132
+ if (part)
133
+ part.options?.host?.[RESCUE](part.element);
134
+ }
135
+ }
136
+ const kept = directive(Kept);
137
+ class Keyed extends Directive {
138
+ #parts = new Map();
139
+ render(_items, _key, _make) {
140
+ return noChange;
141
+ }
142
+ update(container, [items, key, make]) {
143
+ const old = this.#parts;
144
+ const parts = new Map();
145
+ const list = [...new Map(items.map((item) => [key(item), item]))];
146
+ const keys = new Set(list.map(([k]) => k));
147
+ for (const [k, part] of old)
148
+ if (!keys.has(k)) {
149
+ removePart(part);
150
+ part.endNode?.remove();
151
+ old.delete(k);
152
+ }
153
+ const parent = container.parentNode;
154
+ const marker = (el) => {
155
+ let top = el;
156
+ while (top && top.parentNode !== parent)
157
+ top = top.parentNode ?? top.host ?? null;
158
+ return top?.previousSibling ?? null;
159
+ };
160
+ const dragStart = marker(container.options?.host?.[DRAGGING]?.() ?? null);
161
+ let focusStart = marker(focused(parent.ownerDocument));
162
+ if (dragStart && focusStart && focusStart !== dragStart) {
163
+ const at = (start) => list.findIndex(([k]) => old.get(k)?.startNode === start);
164
+ const d = at(dragStart);
165
+ const f = at(focusStart);
166
+ if (d >= 0 && f >= 0 && d < f !== !!(dragStart.compareDocumentPosition(focusStart) & Node.DOCUMENT_POSITION_FOLLOWING))
167
+ focusStart = null;
168
+ }
169
+ let next;
170
+ for (let i = list.length - 1; i >= 0; i--) {
171
+ const [k, item] = list[i];
172
+ const had = old.get(k);
173
+ const part = had && (had.startNode === focusStart || had.startNode === dragStart) ? had : insertPart(container, next, had);
174
+ setChildPartValue(part, make(item));
175
+ parts.set(k, (next = part));
176
+ }
177
+ this.#parts = parts;
178
+ return noChange;
179
+ }
180
+ }
181
+ const keyedParts = directive(Keyed);
182
+ const keyed = (items, key, make) => keyedParts(items, key, make);
183
+ const line = (main, gutter = nothing) => html `<div class="main">${main}</div><div class="gutter">${gutter}</div>`;
184
+ const GAP = html `<span></span>`;
185
+ const paneStyles = css `
186
+ :host{--daas-ui-control: 24px;display: block;box-sizing: border-box;pointer-events: auto;}:host([data-mode="docked"][data-open]){position: relative;align-self: stretch;}:host(:not([data-open])), :host([data-mode="narrow"]){position: absolute;top: 8px;right: 8px;}:host([data-side="left"]:not([data-open])), :host([data-side="left"][data-mode="narrow"]){right: auto;left: 8px;}:host([data-mode="narrow"][data-open]){bottom: 8px;}.pane{display: flex;flex-direction: column;box-sizing: border-box;width: 232px;height: 100%;background: ${tok("bg")};color: ${tok("fg")};}:host([data-mode="docked"]) .pane{border-left: 1px solid ${tok("border")};}:host([data-mode="docked"][data-side="left"]) .pane{border-left: 0;border-right: 1px solid ${tok("border")};}:host(:not([data-open])) .pane, :host([data-mode="narrow"]) .pane{border: 1px solid ${tok("border")};border-radius: ${tok("radius")};box-shadow: ${tok("shadow")};}:host(:not([data-open])) .pane{width: auto;height: auto;}:host([data-mode="container"]) .pane{width: 100%;height: auto;}.bar{display: flex;align-items: center;flex: none;height: 40px;padding: 0 6px;}:host(:not([data-open])) .bar{height: auto;padding: 2px;}.toggle, .title{display: inline-flex;align-items: center;gap: 6px;height: 28px;padding: 0 8px;border-radius: calc(${tok("radius")} - 4px);font-weight: 600;}.toggle:hover, .title:hover:not(:disabled){background: ${tok("hover")};}.body{flex: 1;min-height: 0;overflow: hidden auto;padding-bottom: 8px;}.section{padding: 0 12px 8px;border-top: 1px solid ${tok("border")};}.section:first-child{border-top: 0;}.head, .row{display: grid;grid-template-columns: 184px 24px;align-items: center;}.head{height: 40px;}.row{min-height: 24px;}.row + .row, .lines{margin-top: 4px;}.title{justify-self: start;height: 24px;margin-left: -4px;padding: 0 4px;}.muted .title{color: ${tok("muted")};font-weight: 500;}.main{display: grid;grid-template-columns: 88px 88px;gap: 4px 8px;align-items: center;min-width: 0;}.wide, .lines{grid-column: 1 / -1;}.hosted{display: contents;}.gutter{display: flex;justify-content: center;}.icon-btn, .swatch-btn{display: inline-flex;align-items: center;justify-content: center;width: 24px;height: 24px;border-radius: calc(${tok("radius")} - 4px);color: ${tok("text")};}.icon-btn:hover:not(:disabled), .paint:hover:not(:disabled), .swatch-btn:hover:not(:disabled){background: ${tok("hover")};color: ${tok("fg")};}.icon-btn[aria-pressed="true"]{background: ${tok("accentSoft")};color: ${tok("accent")};}.icon-btn[aria-pressed="mixed"]{background: ${tok("hover")};}.aligns{display: flex;justify-content: space-between;}.color, .layer{display: grid;grid-template-columns: 24px 1fr 72px;gap: 4px;align-items: center;min-width: 0;}.color.bare{grid-template-columns: 24px 1fr;}.layer{grid-template-columns: 1fr 72px;}.layer.gradient{grid-template-columns: 1fr;}.paint, .select-btn{display: flex;align-items: center;gap: 6px;min-width: 0;height: 24px;padding: 0 6px 0 2px;border-radius: calc(${tok("radius")} - 4px);background: ${tok("bg2")};text-align: left;}.select-btn{padding: 0 6px 0 8px;border: 1px solid ${tok("border")};background: ${tok("bg")};}.paint span, .select-btn span, .name{flex: 1;min-width: 0;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}.name, .select-btn .mixed{color: ${tok("muted")};}daas-number-field, daas-select, daas-text-field, daas-segmented{min-width: 0;}daas-number-field::part(input){text-overflow: ellipsis;}daas-segmented::part(segment){min-width: 20px;padding: 0 2px;}.pop{display: grid;gap: 6px;width: 196px;padding: 4px;}.hold{position: absolute;width: 0;height: 0;outline: none;}.pop .main{grid-template-columns: 94px 94px;}.toggles{display: flex;gap: 4px;}.square{position: relative;width: 72px;height: 72px;margin: 4px auto;}.square::before{content: "";position: absolute;inset: 12px;border: 1px dashed ${tok("borderStrong")};}.side{position: absolute;inset: 12px;border-radius: 3px;background: ${tok("border")};}.side[aria-pressed="true"]{background: ${tok("accent")};}.side[aria-pressed="mixed"]{background: ${tok("muted")};}.top{top: 0;bottom: auto;height: 8px;}.bottom{top: auto;bottom: 0;height: 8px;}.left{left: 0;right: auto;width: 8px;}.right{left: auto;right: 0;width: 8px;}`;
187
+ export class PaneSurface extends UiSurface {
188
+ static styles = [baseStyles, tooltipStyles, paneStyles];
189
+ static properties = { ...UiSurface.properties, placement: {} };
190
+ #tip = new Tooltip(this);
191
+ #model = [];
192
+ #narrow = false;
193
+ #resize = null;
194
+ #expanded = true;
195
+ #overlay = false;
196
+ #toggled = new Map();
197
+ #view = { lock: false, corners: false, paddingSides: false };
198
+ #selection = null;
199
+ #hasText = false;
200
+ #can = null;
201
+ #canFor = null;
202
+ #previewing = false;
203
+ #previewKey = "";
204
+ #previewPatch = {};
205
+ #owner = null;
206
+ #pickFocus = null;
207
+ #settled = null;
208
+ #heldFor = null;
209
+ #ratio = null;
210
+ #pick = null;
211
+ #hosted = new Map();
212
+ #memos = new Map();
213
+ #lookups = 0;
214
+ #lookingUp = false;
215
+ #lookupScope = null;
216
+ #lookupKey = "";
217
+ #versions = new Map();
218
+ #prev = {};
219
+ #shown = {};
220
+ #epoch = 0;
221
+ #deps = [];
222
+ #hidden = new Set();
223
+ #scoped = 0;
224
+ #typed = new TypedValues(() => this.renderRoot, (at) => at.closest("[data-key]")?.dataset.key);
225
+ #root = null;
226
+ retired = false;
227
+ constructor() {
228
+ super();
229
+ this.placement = "right";
230
+ }
231
+ keys() {
232
+ return ALL_KEYS;
233
+ }
234
+ connectedCallback() {
235
+ super.connectedCallback();
236
+ this.#root = this.ui;
237
+ this.#typed.listen(this);
238
+ this.#observe();
239
+ }
240
+ get #scope() {
241
+ return this.#root?.scope ?? 0;
242
+ }
243
+ disconnectedCallback() {
244
+ super.disconnectedCallback();
245
+ this.#typed.unlisten(this);
246
+ this.#resize?.disconnect();
247
+ this.#resize = null;
248
+ this.#endPreview();
249
+ }
250
+ retire(off) {
251
+ this.#dropWithin(this.renderRoot);
252
+ cancelDragsWithin(this.renderRoot);
253
+ off();
254
+ this.retired = true;
255
+ this.#typed.end();
256
+ this.#cancelLookup();
257
+ for (const h of this.#hosted.values())
258
+ this.#cancel(h, true);
259
+ this.#hosted.clear();
260
+ this.#endPreview();
261
+ this.#hidden.clear();
262
+ }
263
+ configured(o) {
264
+ for (const key of hiddenKeys(o.hide)) {
265
+ this.#hidden.add(key);
266
+ const h = this.#hosted.get(`key:${key}`);
267
+ if (h?.drag)
268
+ this.#cancel(h);
269
+ }
270
+ this.#regate();
271
+ if (this.#lookingUp && this.#hidden.has(this.#lookupKey))
272
+ this.#cancelLookup();
273
+ }
274
+ #gate(key, patch = {}, scoped = true) {
275
+ const s = this.state;
276
+ const hidden = this.#hidden;
277
+ if (!s || this.retired || s.host.readOnly() || (key !== null && this.#hiddenKey(key)) || (scoped && this.#scoped !== this.#scope))
278
+ return null;
279
+ if (!hidden.size)
280
+ return patch;
281
+ const keep = (p) => {
282
+ const out = {};
283
+ for (const [k, v] of Object.entries(p)) {
284
+ const members = aggregateMembers(this.#shown[k]?.descriptor);
285
+ if (hidden.has(k))
286
+ continue;
287
+ if (members?.some((m) => hidden.has(m)))
288
+ for (const m of members)
289
+ hidden.has(m) || (out[m] = v);
290
+ else
291
+ out[k] = v;
292
+ }
293
+ return out;
294
+ };
295
+ return typeof patch === "function" ? (o) => keep(patch(o)) : keep(patch);
296
+ }
297
+ #hiddenKey(key) {
298
+ return this.#hidden.has(key) || !!aggregateMembers(this.#shown[key]?.descriptor)?.every((m) => this.#hidden.has(m));
299
+ }
300
+ #refuse(from = this.renderRoot) {
301
+ cancelDragsWithin(from);
302
+ this.#regate();
303
+ }
304
+ #regate() {
305
+ if (!this.#previewing)
306
+ return;
307
+ const p = this.#gate(this.#previewKey, this.#previewPatch);
308
+ if (p)
309
+ this.#ctrl.preview(p, `Set ${this.#previewKey}`);
310
+ else
311
+ this.#revoke();
312
+ }
313
+ #revoke() {
314
+ const o = this.#owner;
315
+ this.#endPreview();
316
+ if (!o)
317
+ return;
318
+ if (o.h) {
319
+ if (o.h.drag)
320
+ this.#cancel(o.h);
321
+ }
322
+ else if (o.el)
323
+ cancelDragsWithin(o.el);
324
+ }
325
+ #cancelLookup() {
326
+ this.#lookups++;
327
+ this.#lookingUp = false;
328
+ this.#epoch++;
329
+ }
330
+ #observe() {
331
+ this.#resize?.disconnect();
332
+ this.#resize = null;
333
+ const RO = this.ownerDocument.defaultView?.ResizeObserver;
334
+ const board = this.getRootNode().host;
335
+ if (!RO || !board || this.placement === "container")
336
+ return;
337
+ this.#resize = new RO((entries) => {
338
+ const w = entries.at(-1)?.contentRect.width ?? board.clientWidth;
339
+ const narrow = w > 0 && w < NARROW_PX;
340
+ if (narrow === this.#narrow)
341
+ return;
342
+ const active = focused(this.ownerDocument);
343
+ const keep = within(this, active) && !active?.classList.contains("toggle");
344
+ this.#narrow = narrow;
345
+ this.#overlay = narrow && keep;
346
+ if (keep && !narrow)
347
+ this.#expanded = true;
348
+ if (!this.open)
349
+ for (const pop of this.renderRoot.querySelectorAll("daas-popover"))
350
+ pop.hide();
351
+ this.requestUpdate();
352
+ });
353
+ this.#resize.observe(board);
354
+ }
355
+ get mode() {
356
+ return this.placement === "container" ? "container" : this.#narrow ? "narrow" : "docked";
357
+ }
358
+ get open() {
359
+ const m = this.mode;
360
+ return m === "container" || (m === "narrow" ? this.#overlay : this.#expanded);
361
+ }
362
+ get sections() {
363
+ return this.#model;
364
+ }
365
+ get #opts() {
366
+ const p = this.state?.options.pane;
367
+ return p ? p : {};
368
+ }
369
+ get #colorOpts() {
370
+ const options = this.state.options;
371
+ return this.#memo("color", [options], () => colorOptionsFor(options, "pane"));
372
+ }
373
+ #memo(id, deps, make) {
374
+ const m = this.#memos.get(id);
375
+ if (m && sameDeps(m.deps, deps))
376
+ return m.value;
377
+ const value = make();
378
+ this.#memos.set(id, { deps, value });
379
+ return value;
380
+ }
381
+ #isCollapsed(id) {
382
+ const t = this.#toggled.get(id);
383
+ if (t !== undefined)
384
+ return t;
385
+ return (this.#opts.collapsed?.includes(id) ?? false) || (id === "text" && !this.#hasText);
386
+ }
387
+ #touch(key) {
388
+ this.#versions.set(key, (this.#versions.get(key) ?? 0) + 1);
389
+ this.requestUpdate();
390
+ }
391
+ #bump() {
392
+ this.#epoch++;
393
+ this.requestUpdate();
394
+ }
395
+ #sum(keys) {
396
+ let sum = 0;
397
+ for (const k of keys)
398
+ sum += this.#versions.get(k) ?? 0;
399
+ return sum;
400
+ }
401
+ #data() {
402
+ const targets = this.state.targets;
403
+ return this.#memo("data", [targets], () => targets.map((o) => `${o.id}@${o.version}`).join(" "));
404
+ }
405
+ #guarded(m) {
406
+ const keys = m.custom ? [...(m.custom.keys ?? [])] : [...(SECTION_KEYS[m.id] ?? [])];
407
+ for (const r of m.rows)
408
+ if (r.startsWith("key:"))
409
+ keys.push(r.slice(4));
410
+ return guard([`${m.rows.join()}|${m.collapsed}|${m.empty}|${m.disabled}|${m.own}`, this.#sum(keys), this.#epoch, m.custom?.render ? this.#data() : ""], () => this.#section(m));
411
+ }
412
+ #rowKeys(m, r) {
413
+ if (r.startsWith("key:"))
414
+ return [r.slice(4)];
415
+ if (r.startsWith("layer:") || r === "mixed")
416
+ return ["fills"];
417
+ if (r === "custom")
418
+ return m.custom?.keys ?? [];
419
+ return [...(ROWS[m.id]?.[r] ?? []), ...(MORE_KEYS[`${m.id}:${r}`] ?? [])];
420
+ }
421
+ shouldUpdate(changed) {
422
+ if (changed.size !== 1 || !changed.has("state"))
423
+ return true;
424
+ const was = changed.get("state");
425
+ const s = this.state;
426
+ return !was || !s || was.values !== s.values || was.targets !== s.targets || was.options !== s.options || was.readOnly !== s.readOnly || was.textSession !== s.textSession || was.host !== s.host || was.revision !== s.revision || this.#scoped !== this.#scope;
427
+ }
428
+ willUpdate() {
429
+ const mode = this.mode;
430
+ const side = this.placement === "left" ? "left" : "right";
431
+ if (this.dataset.mode !== mode)
432
+ this.dataset.mode = mode;
433
+ if (this.dataset.side !== side)
434
+ this.dataset.side = side;
435
+ if (this.hasAttribute("data-open") !== this.open)
436
+ this.toggleAttribute("data-open", this.open);
437
+ const s = this.state;
438
+ if (!s)
439
+ return;
440
+ this.#typed.rescope(s, null, null);
441
+ const ids = s.targets.map((o) => o.id).join("\n");
442
+ if (ids !== this.#selection) {
443
+ this.#selection = ids;
444
+ this.#hasText = s.targets.some((o) => o.text?.paragraphs.some((p) => p.runs.some((r) => r.text.length > 0)) ?? false);
445
+ this.#toggled.delete("text");
446
+ this.#can = null;
447
+ }
448
+ const hide = this.#opts.hide;
449
+ this.#hidden = hiddenKeys(hide);
450
+ this.#shown = this.#memo("shown", [s.values, hide], () => shownValues(s.values, hide));
451
+ const listed = (this.#opts.sections ?? SECTION_IDS).map((x) => (typeof x === "string" ? x : x.id));
452
+ const model = paneModel({
453
+ values: s.values,
454
+ targets: s.targets.length,
455
+ readOnly: s.readOnly,
456
+ options: this.#opts,
457
+ view: { collapsed: new Set(listed.filter((id) => this.#isCollapsed(id))), ...this.#view, fillsHeld: this.#held("fills") },
458
+ replaced: this.#replaced("fills") ? STACK : [],
459
+ });
460
+ this.#model = model;
461
+ const prev = this.#prev;
462
+ if (prev !== s.values) {
463
+ for (const k in s.values)
464
+ if (!samePv(prev[k], s.values[k]))
465
+ this.#touch(k);
466
+ for (const k in prev)
467
+ if (!(k in s.values))
468
+ this.#touch(k);
469
+ this.#prev = s.values;
470
+ }
471
+ this.#scoped = this.#scope;
472
+ const deps = [s.options, s.readOnly, s.revision, this.#scoped, this.placement, this.#box(), ids];
473
+ if (deps.some((d, i) => d !== this.#deps[i])) {
474
+ this.#deps = deps;
475
+ this.#epoch++;
476
+ }
477
+ if (s.targets !== this.#canFor && !s.host.controller.hasPreview()) {
478
+ this.#canFor = s.targets;
479
+ const was = this.#can;
480
+ this.#can = null;
481
+ if (was && model.some((m) => m.id === "layout" && m.rows.includes("align")) && LAYOUT_COMMANDS.some((n) => this.#canRun(n) !== was[n]))
482
+ this.#epoch++;
483
+ }
484
+ const pick = this.#pick;
485
+ if (pick && (!model.some((m) => m.id === pick.sec && m.rows.some((r) => `${m.id}:${r}` === pick.row)) || !this.#layerShown(pick)))
486
+ this.#closePicker();
487
+ if (this.#lookingUp && this.#lookupScope) {
488
+ const now = scopeOf(s, this.#lookupKey);
489
+ if (!now || !sameScope(now, this.#lookupScope))
490
+ this.#cancelLookup();
491
+ }
492
+ if (!s.host.controller.hasPreview()) {
493
+ this.#settled = s.values;
494
+ const open = this.#pick;
495
+ const picker = open && this.renderRoot.querySelector(`#${this.#pickerId(open.key)} > daas-paint-picker`);
496
+ if (picker) {
497
+ picker.value = this.#pickerProps(open).value;
498
+ picker.settle();
499
+ }
500
+ }
501
+ }
502
+ updated(changed) {
503
+ if (changed.has("placement"))
504
+ this.#observe();
505
+ const path = this.#pickFocus;
506
+ if (path) {
507
+ this.#pickFocus = null;
508
+ void this.#refocusPicker(path);
509
+ }
510
+ for (const [k, h] of this.#hosted)
511
+ if (h.el && !this.renderRoot.contains(h.el)) {
512
+ this.#cancel(h, true);
513
+ this.#hosted.delete(k);
514
+ }
515
+ }
516
+ get #ctrl() {
517
+ return this.state.host.controller;
518
+ }
519
+ #ranged(key) {
520
+ return !!this.state?.textSession && !!this.#shown[key]?.descriptor.textMark;
521
+ }
522
+ #preview(key, patch, from, h = null) {
523
+ const p = this.#gate(key, patch);
524
+ if (!p) {
525
+ this.#refuse(from);
526
+ return false;
527
+ }
528
+ const el = (h ? h.el : from) ?? null;
529
+ const o = this.#owner;
530
+ if (o && (h ? o.h !== h : o.el !== el))
531
+ this.#revoke();
532
+ this.#previewing = true;
533
+ this.#previewKey = key;
534
+ this.#previewPatch = patch;
535
+ this.#owner = { el, h };
536
+ this.#ctrl.preview(p, `Set ${key}`);
537
+ return true;
538
+ }
539
+ #commit(key, patch, from) {
540
+ const typed = this.#typed.take(from);
541
+ if (typed && this.#typed.stale(typed))
542
+ return false;
543
+ const p = this.#gate(key, patch, !typed);
544
+ if (!p) {
545
+ this.#regate();
546
+ return false;
547
+ }
548
+ this.#ratio = null;
549
+ if (this.#previewing && key === this.#previewKey) {
550
+ this.#previewing = false;
551
+ this.#owner = null;
552
+ this.#ctrl.preview(p, `Set ${key}`);
553
+ this.#ctrl.commitPreview();
554
+ }
555
+ else
556
+ this.#ctrl.set(p);
557
+ return true;
558
+ }
559
+ #endOwned(who) {
560
+ const o = this.#owner;
561
+ if (o && (o.h === who || o.el === who))
562
+ this.#endPreview();
563
+ }
564
+ #endPreview() {
565
+ this.#ratio = null;
566
+ this.#owner = null;
567
+ if (!this.#previewing)
568
+ return;
569
+ this.#previewing = false;
570
+ this.state?.host.controller.cancelPreview();
571
+ }
572
+ #own(key) {
573
+ const pv = this.#shown[key];
574
+ if (this.#ranged(key)) {
575
+ const v = first(pv);
576
+ return () => v;
577
+ }
578
+ return (o) => pv.descriptor.read(o);
579
+ }
580
+ #each(key, next) {
581
+ const own = this.#own(key);
582
+ return this.#applicable([key], (o) => ({ [key]: next(own(o), o) }));
583
+ }
584
+ #applicable(keys, write) {
585
+ const ds = keys.map((k) => this.#shown[k]?.descriptor);
586
+ return (o) => (ds.every((d) => !d || d.appliesTo(o)) ? write(o) : {});
587
+ }
588
+ #focusBefore(removed, to) {
589
+ if (!removed || !focusWithin(removed))
590
+ return;
591
+ this.#dropWithin(removed);
592
+ to()?.focus({ preventScroll: true });
593
+ }
594
+ #dropWithin(el) {
595
+ for (const h of this.#hosted.values())
596
+ if (h.drag && el.contains(h.el))
597
+ this.#cancel(h, true);
598
+ }
599
+ #title(sectionId) {
600
+ for (const el of this.renderRoot.querySelectorAll("[data-section]"))
601
+ if (el.dataset.section === sectionId)
602
+ return el.querySelector(".title");
603
+ return null;
604
+ }
605
+ [RESCUE](el) {
606
+ if (!focusWithin(el))
607
+ return;
608
+ this.#dropWithin(el);
609
+ const sec = el.closest("[data-sec]")?.dataset.sec ?? el.closest("[data-section]")?.dataset.section;
610
+ const next = this.open ? this.#model : [];
611
+ const to = (next.some((m) => m.id === sec) ? this.#title(sec) : null) ?? this.renderRoot.querySelector(".toggle") ?? (next[0] ? this.#title(next[0].id) : null);
612
+ if (to)
613
+ to.focus({ preventScroll: true });
614
+ else
615
+ this.state?.host.returnFocus();
616
+ }
617
+ [DRAGGING]() {
618
+ return this.#owner?.el ?? draggingWithin(this.renderRoot);
619
+ }
620
+ #label(key) {
621
+ const s = this.state;
622
+ return s ? s.options.strings.label(key, s.values[key]?.descriptor.label ?? key) : key;
623
+ }
624
+ #options(key, from) {
625
+ const strings = this.state.options.strings;
626
+ const icons = Array.isArray(from) ? null : from;
627
+ return this.#memo(`options:${key}`, [from, strings], () => (icons ? Object.keys(icons) : from).map((v) => ({ value: v, label: strings.option(key, v), ...(icons ? { icon: icons[v] } : {}) })));
628
+ }
629
+ #toggle(e) {
630
+ const open = !this.open;
631
+ if (!open)
632
+ this.#focusBefore(this.renderRoot.querySelector(".body"), () => e.currentTarget);
633
+ if (this.mode === "narrow")
634
+ this.#overlay = open;
635
+ else
636
+ this.#expanded = open;
637
+ this.requestUpdate();
638
+ }
639
+ #onKey(e) {
640
+ if (e.key === "Enter" && !e.isComposing && e.keyCode !== 229 && this.state?.textSession) {
641
+ const path = e.composedPath();
642
+ if (path[0]?.localName === "input" && !path.some((n) => n.localName === "daas-popover")) {
643
+ e.preventDefault();
644
+ return this.state.host.returnFocus();
645
+ }
646
+ }
647
+ if (e.key !== "Escape" || e.defaultPrevented || this.mode !== "narrow" || !this.#overlay)
648
+ return;
649
+ if (e.composedPath().some((n) => n instanceof Element && n.localName === "daas-popover" && n.open))
650
+ return;
651
+ e.preventDefault();
652
+ this.#focusBefore(this.renderRoot.querySelector(".body"), () => this.renderRoot.querySelector(".toggle"));
653
+ this.#overlay = false;
654
+ this.requestUpdate();
655
+ }
656
+ #titleClick(m) {
657
+ if (m.empty && m.own && !this.state?.readOnly && this.#adds(m.id))
658
+ return this.#add(m.id);
659
+ this.#toggled.set(m.id, !m.collapsed);
660
+ this.#bump();
661
+ }
662
+ #btn(icon, label, click, o = {}) {
663
+ const tip = this.#tip;
664
+ const toggle = o.text !== undefined;
665
+ return html `<button class=${toggle ? "toggle" : "icon-btn"} part=${toggle ? "toggle" : "button"} aria-label=${toggle ? nothing : label} aria-controls=${toggle ? "body" : nothing}
666
+ aria-pressed=${o.pressed === undefined ? nothing : String(o.pressed)} aria-expanded=${o.expanded === undefined ? nothing : String(o.expanded)} data-tip=${label} ?disabled=${o.disabled}
667
+ @pointerdown=${(e) => {
668
+ keepFocus(e);
669
+ tip.hide();
670
+ }} @mousedown=${keepFocus} @pointerenter=${tip.enter} @pointerleave=${tip.leave} @focus=${tip.focus} @blur=${tip.leave} @keydown=${tip.key} @click=${click} ${kept()}
671
+ >${this.drawIcon(icon)}${toggle ? html `<span>${o.text}</span>` : nothing}</button>`;
672
+ }
673
+ #toggleKey(key, icon) {
674
+ const pv = this.#shown[key];
675
+ const on = pv.mixed ? "mixed" : !!pv.value;
676
+ return this.#btn(icon, this.#label(key), () => this.#commit(key, { [key]: on !== true }), { pressed: on, disabled: this.state.readOnly });
677
+ }
678
+ #pop(e, id) {
679
+ const pop = this.renderRoot.querySelector(`#${id}`);
680
+ const anchor = e.currentTarget;
681
+ if (!pop)
682
+ return;
683
+ if (pop.open)
684
+ return this.#close(pop, anchor);
685
+ pop.toggle(anchor);
686
+ if (e.detail === 0 && pop.open)
687
+ this.#focusFirst(pop);
688
+ }
689
+ #focusFirst(el) {
690
+ const walk = (n) => {
691
+ for (const c of n.children) {
692
+ if (c instanceof HTMLElement && c.matches("button:not(:disabled), input:not(:disabled), [tabindex='0']"))
693
+ return c;
694
+ const inner = (c.shadowRoot && walk(c.shadowRoot)) || walk(c);
695
+ if (inner)
696
+ return inner;
697
+ }
698
+ return null;
699
+ };
700
+ void el.updateComplete?.then(() => walk(el)?.focus());
701
+ }
702
+ #close(pop, opener) {
703
+ if (!pop?.open)
704
+ return;
705
+ if (opener && !this.state?.textSession && focusWithin(pop))
706
+ opener.focus({ preventScroll: true });
707
+ pop.hide();
708
+ }
709
+ #onClose = (e) => {
710
+ const pop = e.target;
711
+ if (this.state?.textSession || !focusWithin(pop))
712
+ return;
713
+ const opener = pop.opener;
714
+ if (opener instanceof HTMLElement && opener.isConnected && within(this, opener))
715
+ opener.focus({ preventScroll: true });
716
+ };
717
+ #field(key, sec = "", row = "", generic = false) {
718
+ const pv = this.#shown[key];
719
+ if (!pv)
720
+ return this.state.targets.length || this.#opts.hide?.includes(key) ? GAP : this.#num(key, { value: null, disabled: true });
721
+ const host = this.#hostedFor(key, generic);
722
+ if (host)
723
+ return host;
724
+ const label = this.#label(key);
725
+ switch (key === "fontWeight" ? key : pv.descriptor.type) {
726
+ case "fontWeight":
727
+ return this.#select(key, this.#weights(), (v) => ({ fontWeight: Number(v) }));
728
+ case "number": {
729
+ const route = key === "bendRadius" && this.#shown.route;
730
+ if (route && !(route.mixed ? route.values?.includes("ortho") : route.value === "ortho"))
731
+ return GAP;
732
+ return this.#num(key, generic ? { label: label.slice(0, 1) } : key === "radius" && pv.value === undefined ? { mixed: true } : {});
733
+ }
734
+ case "enum":
735
+ return SEGMENT_ICONS[key] ? this.#segments(key) : this.#select(key);
736
+ case "color":
737
+ return this.#color(key, sec, row, generic);
738
+ case "paint": {
739
+ const p = first(pv);
740
+ return this.#swatchButton(key, sec, row, label, p, !!pv.mixed, undefined, this.#paintName(p, !!pv.mixed, this.t("value.none")));
741
+ }
742
+ case "boolean":
743
+ return this.#toggleKey(key, generic ? "check" : key);
744
+ case "font":
745
+ return this.#font(key, row, !generic);
746
+ case "embed":
747
+ return this.#url(key, !generic);
748
+ }
749
+ return this.#text(label, pv.mixed ? null : String(pv.value ?? ""), !!pv.mixed, (text, from) => this.#commit(key, { [key]: text }, from), key);
750
+ }
751
+ #text(name, value, mixed, commit, key, cls = "", placeholder = "", busy = false) {
752
+ return html `<daas-text-field class=${cls} data-key=${key ?? nothing} name=${name} placeholder=${placeholder} .value=${value} .mixed=${mixed} .busy=${busy} ?disabled=${this.state.readOnly}
753
+ @daas-commit=${(e) => commit(e.detail, e.currentTarget)} ${kept()}></daas-text-field>`;
754
+ }
755
+ #num(key, o = {}) {
756
+ const pv = this.#shown[key];
757
+ const d = pv?.descriptor;
758
+ const [handle = "", precision = 2, scale = 1, step] = NUMS[key] ?? [];
759
+ const letter = handle.includes(".");
760
+ const label = o.label ?? (letter ? this.t(handle) : undefined);
761
+ const v = o.value !== undefined ? o.value : num(first(pv));
762
+ const write = (e) => (o.patch ?? ((n) => this.#size(key, n)))(e.detail / scale);
763
+ return html `<daas-number-field data-key=${key} label=${label ?? nothing} label-icon=${letter || !handle ? nothing : handle} name=${o.name ?? (pv ? this.#label(key) : (label ?? key))}
764
+ .value=${v === null ? null : Number((v * scale).toFixed(6))} .mixed=${o.mixed ?? !!pv?.mixed} .min=${d?.min !== undefined ? d.min * scale : -Infinity} .max=${d?.max !== undefined ? d.max * scale : Infinity}
765
+ .step=${step ?? (d?.step !== undefined ? d.step * scale : 1)} .precision=${precision} ?disabled=${this.state.readOnly || !!o.disabled}
766
+ @daas-preview=${(e) => this.#preview(key, write(e), e.currentTarget)} @daas-commit=${(e) => this.#commit(key, write(e), e.currentTarget)} @daas-cancel=${(e) => this.#endOwned(e.currentTarget)} ${kept()}></daas-number-field>`;
767
+ }
768
+ #select(key, options = this.#options(key, this.#shown[key].descriptor.options ?? []), write = (v) => ({ [key]: v })) {
769
+ const pv = this.#shown[key];
770
+ return html `<daas-select data-key=${key} label=${this.#label(key)} .options=${options} .value=${pv.mixed ? null : String(pv.value ?? "")} .mixed=${!!pv.mixed} ?disabled=${this.state.readOnly}
771
+ @daas-commit=${(e) => this.#commit(key, write(e.detail))} ${kept()}></daas-select>`;
772
+ }
773
+ #segments(key) {
774
+ const pv = this.#shown[key];
775
+ return html `<daas-segmented data-key=${key} label=${this.#label(key)} .options=${this.#options(key, SEGMENT_ICONS[key])} .value=${pv.mixed ? null : String(pv.value ?? "")} ?disabled=${this.state.readOnly}
776
+ @daas-commit=${(e) => this.#commit(key, { [key]: e.detail })} ${kept()}></daas-segmented>`;
777
+ }
778
+ #weights() {
779
+ const s = this.state;
780
+ const family = first(this.#shown.fontFamily);
781
+ const declared = s.host.fonts().find((f) => f.family === family)?.weights;
782
+ const w = num(first(this.#shown.fontWeight));
783
+ const strings = s.options.strings;
784
+ return this.#memo("weights", [declared, w, strings, s.revision], () => [...new Set([...(declared ?? []), ...(w !== null ? [w] : [])])]
785
+ .sort((a, b) => a - b)
786
+ .map((x) => ({ value: String(x), label: `weight.${x}` in DEFAULT_STRINGS ? strings.t(`weight.${x}`) : String(x) })));
787
+ }
788
+ #color(key, sec, row, bare) {
789
+ const pv = this.#shown[key];
790
+ const c = first(pv);
791
+ const label = this.#label(key);
792
+ const typed = (text, from) => {
793
+ const rgba = parseHex(text);
794
+ if (!rgba)
795
+ return this.requestUpdate();
796
+ const digits = text.trim().replace(/^#/, "").length;
797
+ const alpha = digits === 4 || digits === 8;
798
+ this.#commit(key, this.#each(key, (own) => formatHex(alpha ? rgba : { ...rgba, a: alphaOf(own) })), from);
799
+ };
800
+ return this.#paint(`color ${bare ? "bare" : "wide"}`, key, sec, row, label, c, !!pv.mixed, this.#text(label, hexOf(c), !!pv.mixed, typed), bare ? null : (a) => this.#each(key, (own) => withAlpha(own, a)));
801
+ }
802
+ #paint(cls, key, sec, row, label, paint, mixed, more, alpha, layer, text) {
803
+ const write = (e) => alpha(e.detail / 100);
804
+ return html `<div class=${cls} data-key=${key} ${kept()}>${this.#swatchButton(key, sec, row, label, paint, mixed, layer, text)}${more}${alpha
805
+ ? html `<daas-number-field label-icon="opacity" name=${`${label}, ${this.t("color.alpha")}`} .value=${Math.round(alphaOf(paint) * 100)} .mixed=${mixed} .min=${0} .max=${100} .precision=${0}
806
+ ?disabled=${this.state.readOnly || paint === undefined} @daas-preview=${(e) => this.#preview(key, write(e), e.currentTarget)} @daas-commit=${(e) => this.#commit(key, write(e), e.currentTarget)}
807
+ @daas-cancel=${(e) => this.#endOwned(e.currentTarget)} ${kept()}></daas-number-field>`
808
+ : nothing}</div>`;
809
+ }
810
+ #paintName(p, mixed, none = "") {
811
+ return mixed ? this.t("value.mixed") : typeof p === "string" ? hexOf(p) : p ? this.t(p.type === "linear" ? "paint.linear" : "paint.radial") : none;
812
+ }
813
+ #swatchButton(key, sec, row, label, paint, mixed, layer, text) {
814
+ const swatch = html `<daas-swatch .paint=${(paint ?? null)} .mixed=${mixed} .box=${this.#box()}></daas-swatch>`;
815
+ const name = text === undefined ? nothing : html `<span>${text}</span>`;
816
+ if (this.state.readOnly)
817
+ return text === undefined ? swatch : html `<span class="paint">${swatch}${name}</span>`;
818
+ const tip = this.#tip;
819
+ return html `<button class=${text === undefined ? "swatch-btn" : "paint"} part="swatch" aria-label=${text === undefined ? label : `${label}: ${text}`} aria-haspopup="dialog" data-tip=${label}
820
+ @pointerdown=${(e) => {
821
+ keepFocus(e);
822
+ tip.hide();
823
+ }} @mousedown=${keepFocus} @pointerenter=${tip.enter} @pointerleave=${tip.leave} @blur=${tip.leave}
824
+ @click=${(e) => this.#openPicker(e, { key, sec, row, ...(layer !== undefined ? { layer } : {}) })} ${kept()}>${swatch}${name}</button>`;
825
+ }
826
+ #box() {
827
+ const t = this.state?.targets[0];
828
+ const w = t ? t.w : 1;
829
+ const h = t ? t.h : 1;
830
+ return this.#memo("box", [w, h], () => ({ w, h }));
831
+ }
832
+ #pickerId(key) {
833
+ return key === "shadowColor" ? "shadow-picker" : "picker";
834
+ }
835
+ get #toward() {
836
+ return this.placement === "left" ? "right-start" : "left-start";
837
+ }
838
+ #openPicker(e, pick) {
839
+ const id = this.#pickerId(pick.key);
840
+ const pop = this.renderRoot.querySelector(`#${id}`);
841
+ if (!pop)
842
+ return;
843
+ const anchor = e.currentTarget;
844
+ const p = this.#pick;
845
+ const same = p && p.key === pick.key && p.layer === pick.layer && p.row === pick.row;
846
+ if (pop.open) {
847
+ this.#close(pop, anchor);
848
+ if (same)
849
+ return;
850
+ }
851
+ this.#pick = pick;
852
+ this.#bump();
853
+ void this.updateComplete.then(() => {
854
+ if (this.#pick !== pick || !anchor.isConnected)
855
+ return;
856
+ pop.show(anchor);
857
+ if (e.detail === 0)
858
+ this.#focusFirst(pop);
859
+ });
860
+ }
861
+ #closePicker() {
862
+ const id = this.#pick ? this.#pickerId(this.#pick.key) : "picker";
863
+ const pop = this.renderRoot.querySelector(`#${id}`);
864
+ this.#pick = null;
865
+ this.#pickFocus = null;
866
+ this.#epoch++;
867
+ if (pop)
868
+ this[RESCUE](pop);
869
+ this.#close(pop);
870
+ }
871
+ #pickerProps(pick) {
872
+ const pv = pick && this.#shown[pick.key];
873
+ if (!pick || !pv)
874
+ return { value: null, mixed: false, types: PICKER_LESS, allowNone: false };
875
+ const sv = this.#settled?.[pick.key] ?? pv;
876
+ const color = this.#colorOpts;
877
+ const type = pv.descriptor.type;
878
+ const types = this.#memo(`types:${type}`, [color], () => pickerTypes(color, type));
879
+ if (pick.layer === "mixed")
880
+ return { value: stack(sv.values?.[0]).at(-1) ?? null, mixed: true, types, allowNone: true };
881
+ if (pick.layer !== undefined)
882
+ return { value: stack(sv.value)[pick.layer] ?? null, mixed: false, types, allowNone: true };
883
+ const v = first(sv);
884
+ return { value: v === undefined || v === null ? null : v, mixed: !!pv.mixed, types, allowNone: type === "paint" || pick.key === "stroke" };
885
+ }
886
+ #held(key) {
887
+ if (!this.#previewing || this.#previewKey !== key)
888
+ return undefined;
889
+ const s = this.state;
890
+ const memo = this.#heldFor;
891
+ if (memo && memo[0] === s && memo[1] === key)
892
+ return memo[2];
893
+ const d = this.#shown[key]?.descriptor;
894
+ const values = d ? (s?.targets ?? []).filter((o) => d.appliesTo(o)).map((o) => d.read(o)) : [];
895
+ const first = values[0];
896
+ const held = !d || !values.length ? undefined : values.some((v) => !same(v, first)) ? { mixed: true, values, applicable: values.length, descriptor: d } : { value: first, applicable: values.length, descriptor: d };
897
+ this.#heldFor = [s, key, held];
898
+ return held;
899
+ }
900
+ #structural(key) {
901
+ return this.#held(key) ?? this.#shown[key];
902
+ }
903
+ #layerShown(pick) {
904
+ if (pick.layer === undefined)
905
+ return true;
906
+ const v = this.#structural(pick.key);
907
+ return !!v && (pick.layer === "mixed" ? !!v.mixed : !v.mixed && stack(v.value).length > pick.layer);
908
+ }
909
+ #pickPatch(pick, edit) {
910
+ const pv = this.#shown[pick.key];
911
+ if (!pv)
912
+ return null;
913
+ const key = pick.key;
914
+ if (pick.layer === "mixed") {
915
+ const top = stack(this.#stored(key)).at(-1) ?? null;
916
+ return this.#applicable([key], (o) => {
917
+ const next = applyPaintEdit(edit, top, boxOf(o));
918
+ return { [key]: next === null ? [] : [next] };
919
+ });
920
+ }
921
+ if (pick.layer !== undefined)
922
+ return this.#layerPatch(key, pick.layer, (paint, o) => applyPaintEdit(edit, paint, boxOf(o)));
923
+ const mixed = !!(this.#settled?.[key] ?? pv).mixed;
924
+ const firstPaint = mixed ? (this.#stored(key) ?? null) : null;
925
+ return this.#each(key, (own, o) => applyPaintEdit(edit, mixed ? firstPaint : (own ?? null), boxOf(o)) ?? undefined);
926
+ }
927
+ #stored(key) {
928
+ const d = this.#shown[key]?.descriptor;
929
+ const o = d && this.state?.targets.find((t) => d.appliesTo(t));
930
+ return o ? d.read(o) : undefined;
931
+ }
932
+ #pickerPopover(id) {
933
+ const pick = this.#pick && this.#pickerId(this.#pick.key) === id ? this.#pick : null;
934
+ const p = this.#pickerProps(pick);
935
+ const s = this.state;
936
+ const layer = pick?.key === "fills" && s?.targets.length === 1 && !s.readOnly ? pick.layer : undefined;
937
+ const t = typeof layer === "number" ? s.targets[0].id : null;
938
+ const handles = this.#memo("handles", [s?.host, t, layer], () => (t ? canvasHandles(s.host, { id: t, layer: layer }) : null));
939
+ const relay = (type) => (e) => {
940
+ e.stopPropagation();
941
+ const picker = e.currentTarget;
942
+ if (!pick || !picker.isConnected)
943
+ return;
944
+ const patch = this.#pickPatch(pick, e.detail);
945
+ if (type === "preview") {
946
+ if (patch)
947
+ this.#preview(pick.key, patch, picker);
948
+ }
949
+ else if (!patch || !this.#commit(pick.key, patch, picker))
950
+ picker.revert();
951
+ };
952
+ return html `<daas-popover id=${id} placement=${this.#toward} data-sec=${pick?.sec ?? nothing} data-row=${pick?.row ?? nothing}
953
+ @daas-close=${(e) => {
954
+ if (e.target === e.currentTarget && this.#pick === pick) {
955
+ this.#pick = null;
956
+ this.#bump();
957
+ }
958
+ }} ${kept()}><span class="hold" tabindex="-1"></span><daas-paint-picker data-key=${pick?.key ?? nothing} .value=${p.value} .mixed=${p.mixed} .box=${this.#box()} .types=${p.types} .color=${this.#colorOpts} .allowNone=${p.allowNone} .handles=${handles}
959
+ @daas-preview=${relay("preview")} @daas-commit=${relay("commit")}
960
+ @daas-cancel=${(e) => {
961
+ e.stopPropagation();
962
+ if (e.currentTarget.isConnected)
963
+ this.#endOwned(e.currentTarget);
964
+ }}></daas-paint-picker></daas-popover>`;
965
+ }
966
+ #parkPickerFocus() {
967
+ const pick = this.#pick;
968
+ const pop = pick && this.renderRoot?.querySelector(`#${this.#pickerId(pick.key)}`);
969
+ const picker = pop?.querySelector("daas-paint-picker");
970
+ const active = picker && focused(this.ownerDocument);
971
+ if (!pop || !picker || !active || !within(picker, active))
972
+ return;
973
+ this.#pickFocus = pathWithin(picker, active);
974
+ pop.querySelector(".hold")?.focus({ preventScroll: true });
975
+ }
976
+ async #refocusPicker(path) {
977
+ const pick = this.#pick;
978
+ const pop = pick ? this.renderRoot.querySelector(`#${this.#pickerId(pick.key)}`) : null;
979
+ let node = pop?.querySelector("daas-paint-picker") ?? null;
980
+ for (const [name, nth, inShadow, label] of path) {
981
+ if (!node)
982
+ break;
983
+ await node.updateComplete;
984
+ const scope = inShadow ? node.shadowRoot : node;
985
+ const same = scope ? [...scope.children].filter((c) => c.localName === name) : [];
986
+ const at = same[nth] ?? null;
987
+ node = at && roleOf(at) === label ? at : (same.find((c) => roleOf(c) === label) ?? null);
988
+ }
989
+ if (!pop?.open || focused(this.ownerDocument) !== pop.querySelector(".hold") || !node?.isConnected)
990
+ return;
991
+ node.focus({ preventScroll: true });
992
+ }
993
+ #layerPatch(key, i, next) {
994
+ const pv = this.#shown[key];
995
+ return this.#applicable([key], (o) => {
996
+ const layers = stack(pv.descriptor.read(o));
997
+ const paint = next(layers[i] ?? null, o);
998
+ return { [key]: paint === null ? layers.filter((_, j) => j !== i) : layers.map((l, j) => (j === i ? paint : l)) };
999
+ });
1000
+ }
1001
+ #addLayer(key) {
1002
+ const pv = this.#shown[key];
1003
+ if (pv)
1004
+ this.#commit(key, this.#applicable([key], (o) => ({ [key]: [...stack(pv.descriptor.read(o)), NEW_LAYER] })));
1005
+ }
1006
+ #removeLayer(e, key, sec, i) {
1007
+ const pv = this.#shown[key];
1008
+ if (!pv)
1009
+ return;
1010
+ if (i === "mixed" || i === stack(pv.value).length - 1)
1011
+ this.#focusBefore(e.currentTarget.closest(".layer-row"), () => this.#title(sec));
1012
+ this.#commit(key, i === "mixed" ? { [key]: [] } : this.#applicable([key], (o) => ({ [key]: stack(pv.descriptor.read(o)).filter((_, j) => j !== i) })));
1013
+ }
1014
+ #layer(key, sec, row, i) {
1015
+ const pv = this.#shown[key];
1016
+ const own = stack(pv.mixed ? pv.values?.[0] : pv.value);
1017
+ const paint = i === "mixed" ? (own.at(-1) ?? null) : (own[i] ?? null);
1018
+ const solid = i !== "mixed" && typeof paint === "string";
1019
+ const label = i === "mixed" ? this.#label(key) : `${this.t("pane.layer")} ${i + 1}`;
1020
+ const alpha = solid ? (a) => this.#layerPatch(key, i, (p) => (typeof p === "string" ? withAlpha(p, a) : p)) : null;
1021
+ return line(this.#paint(`layer wide ${solid ? "" : "gradient"}`, key, sec, row, label, paint, i === "mixed", nothing, alpha, i, this.#paintName(paint, i === "mixed")), this.state.readOnly ? nothing : this.#btn("minus", `${this.t("pane.removeFill")}: ${label}`, (e) => this.#removeLayer(e, key, sec, i)));
1022
+ }
1023
+ #adds(sec) {
1024
+ const key = ADDS[sec]?.[0];
1025
+ return !!key && key in this.#shown && !(key === "fills" && this.#replaced(key));
1026
+ }
1027
+ #add(sec) {
1028
+ const v = this.#shown;
1029
+ if (sec === "fill")
1030
+ return this.#addLayer("fills");
1031
+ if (sec === "stroke") {
1032
+ const width = v.strokeWidth?.descriptor;
1033
+ return void this.#commit("stroke", this.#applicable(["stroke"], (o) => ({ stroke: NEW_STROKE, ...(width?.appliesTo(o) && width.read(o) === 0 ? { strokeWidth: 1 } : {}) })));
1034
+ }
1035
+ if (sec === "effects") {
1036
+ const patch = { shadowOn: true };
1037
+ for (const k of SHADOW_KEYS)
1038
+ if (k in v)
1039
+ patch[k] = undefined;
1040
+ this.#commit("shadowOn", patch);
1041
+ }
1042
+ }
1043
+ #hostedFor(key, generic) {
1044
+ const s = this.state;
1045
+ const pv = this.#shown[key];
1046
+ if (!pv || s.readOnly)
1047
+ return null;
1048
+ const controls = s.options.controls;
1049
+ const factory = controls[`key:${key}`] ?? (generic ? controls[pv.descriptor.type] : undefined);
1050
+ if (!factory)
1051
+ return null;
1052
+ const el = this.#hosted_(`key:${key}`, factory, [pv], [s.revision], (at) => {
1053
+ const ctx = {
1054
+ descriptor: pv.descriptor,
1055
+ value: pv,
1056
+ preview: (v) => {
1057
+ const h = at();
1058
+ if (h.gone || h.cancelling || h.dropped || h.scope !== this.#scope)
1059
+ return;
1060
+ const had = !!h.drag;
1061
+ if (!this.#preview(key, { [key]: v }, h.el, h))
1062
+ return void (had && !at().drag ? undefined : this.#cancel(h, false, true));
1063
+ h.drag ??= this.#root?.beginDrag(() => this.#cancel(h)) ?? (() => { });
1064
+ },
1065
+ commit: (v) => {
1066
+ if (this.#live(at()) && this.#shown[key])
1067
+ this.#commit(key, { [key]: v });
1068
+ this.#touch(key);
1069
+ },
1070
+ cancel: () => {
1071
+ if (this.#live(at()))
1072
+ this.#endOwned(at());
1073
+ this.#touch(key);
1074
+ },
1075
+ onCancel: (listener) => void at().cancels.push(listener),
1076
+ };
1077
+ return factory(ctx);
1078
+ });
1079
+ return this.#hostedPart(el);
1080
+ }
1081
+ #cancel(h, gone = false, ran = !!h.drag) {
1082
+ if (h.gone)
1083
+ return;
1084
+ h.gone = gone;
1085
+ if (h.drag) {
1086
+ h.drag();
1087
+ h.drag = null;
1088
+ }
1089
+ this.#endOwned(h);
1090
+ if (!h.cancels.length)
1091
+ return void (h.dropped ||= ran);
1092
+ h.dropped = false;
1093
+ h.cancelling = true;
1094
+ for (const listener of [...h.cancels])
1095
+ try {
1096
+ listener();
1097
+ }
1098
+ catch (e) {
1099
+ queueMicrotask(() => {
1100
+ throw e;
1101
+ });
1102
+ }
1103
+ h.cancelling = false;
1104
+ }
1105
+ #live(h) {
1106
+ if (h.cancelling)
1107
+ return false;
1108
+ const now = h.scope === this.#scope;
1109
+ if (!now && h.drag)
1110
+ this.#cancel(h);
1111
+ h.drag?.();
1112
+ h.drag = null;
1113
+ if (!h.dropped)
1114
+ return now && !h.gone;
1115
+ h.dropped = false;
1116
+ h.pvs = [];
1117
+ return false;
1118
+ }
1119
+ scopeChanged(change) {
1120
+ for (const h of this.#hosted.values())
1121
+ this.#cancel(h);
1122
+ const moved = (key) => change.targets || (change.session && !!key && !!this.#shown[key]?.descriptor.textMark);
1123
+ for (const f of this.renderRoot?.querySelectorAll("daas-number-field, daas-text-field") ?? [])
1124
+ if (moved(f.closest("[data-key]")?.dataset.key) && f.discardDraft())
1125
+ this.#typed.discard(f);
1126
+ if (moved(this.#pick?.key))
1127
+ this.#parkPickerFocus();
1128
+ }
1129
+ #replaced(key) {
1130
+ const s = this.state;
1131
+ return !!s && !s.readOnly && !!s.options.controls[`key:${key}`];
1132
+ }
1133
+ #hosted_(id, make, pvs, deps, create) {
1134
+ if (this.retired)
1135
+ return null;
1136
+ const had = this.#hosted.get(id);
1137
+ const scope = this.#scope;
1138
+ if (had && had.make === make && (had.drag || madeFor(had, pvs, deps))) {
1139
+ if (!had.drag)
1140
+ had.scope = scope;
1141
+ return had.el;
1142
+ }
1143
+ let h = { el: null, make, pvs, deps, drag: null, cancels: [], cancelling: false, dropped: false, gone: false, scope };
1144
+ h.el = create(() => h);
1145
+ if (had && had.make === make && h.el === had.el) {
1146
+ had.pvs = pvs;
1147
+ had.deps = deps;
1148
+ had.scope = scope;
1149
+ had.cancels.push(...h.cancels);
1150
+ h = had;
1151
+ return h.el;
1152
+ }
1153
+ this.#hosted.set(id, h);
1154
+ if (!had)
1155
+ return h.el;
1156
+ if (had.drag)
1157
+ this.#cancel(had, true);
1158
+ if (had.el && h.el !== had.el)
1159
+ this[RESCUE](had.el);
1160
+ this.#cancel(had, true);
1161
+ return h.el;
1162
+ }
1163
+ #hostedPart(el) {
1164
+ return el ? html `<div class="hosted" ${kept()}>${el}</div>` : null;
1165
+ }
1166
+ #custom(m) {
1167
+ const s = this.state;
1168
+ const render = m.custom?.render;
1169
+ const keys = m.custom?.keys ?? [];
1170
+ const values = {};
1171
+ for (const k of keys)
1172
+ if (this.#shown[k])
1173
+ values[k] = this.#shown[k];
1174
+ const el = render
1175
+ ? this.#hosted_(`section:${m.id}`, render, keys.map((k) => this.#shown[k]), [this.#data(), s.readOnly, s.revision], () => render({ host: s.host, values, targets: s.targets }))
1176
+ : null;
1177
+ return html `<div class="lines" ${kept()}>${el ?? nothing}</div>`;
1178
+ }
1179
+ async #link(key, text, from) {
1180
+ const url = text.trim();
1181
+ const s = this.state;
1182
+ const typed = this.#typed.take(from);
1183
+ if (!url || !s || s.readOnly || (typed && this.#typed.stale(typed)))
1184
+ return this.requestUpdate();
1185
+ const pv = this.#shown[key];
1186
+ if (pv && !pv.mixed && url === (first(pv)?.url ?? "")) {
1187
+ if (this.#lookingUp)
1188
+ this.#cancelLookup();
1189
+ return this.requestUpdate();
1190
+ }
1191
+ const scope = typed?.scope ?? scopeOf(s, key);
1192
+ if (!scope)
1193
+ return this.requestUpdate();
1194
+ const lookup = ++this.#lookups;
1195
+ this.#lookingUp = true;
1196
+ this.#lookupKey = key;
1197
+ this.#lookupScope = scope;
1198
+ this.#bump();
1199
+ let ref;
1200
+ try {
1201
+ ref = s.host.lookupLink ? await s.host.lookupLink(url) : { url };
1202
+ }
1203
+ catch {
1204
+ ref = null;
1205
+ }
1206
+ if (lookup !== this.#lookups)
1207
+ return;
1208
+ this.#lookingUp = false;
1209
+ this.#bump();
1210
+ const c = this.state.host.controller;
1211
+ const d = this.#shown[key]?.descriptor;
1212
+ const same = !!d && sameScope(scope, [c.targets().filter((o) => d.appliesTo(o)), d.textMark ? c.textTarget() : null]);
1213
+ const p = ref && this.isConnected && same ? this.#gate(key, { [key]: ref }, false) : null;
1214
+ if (p)
1215
+ c.set(p);
1216
+ }
1217
+ #url(key, wide) {
1218
+ const pv = this.#shown[key];
1219
+ return this.#text(this.#label(key), first(pv)?.url ?? "", !!pv.mixed, (text, from) => void this.#link(key, text, from), key, wide ? "wide" : "", this.t("pane.url"), this.#lookingUp);
1220
+ }
1221
+ #font(key, row, wide) {
1222
+ const s = this.state;
1223
+ const pv = this.#shown[key];
1224
+ const fonts = this.#memo("fonts", [s.host.fonts(), s.revision], () => [...s.host.fonts()]);
1225
+ const family = first(pv);
1226
+ const shown = pv.mixed ? this.t("value.mixed") : (fonts.find((f) => f.family === family)?.label ?? family ?? "");
1227
+ const weight = key === "fontFamily" ? this.#shown.fontWeight : undefined;
1228
+ const id = `font-${row.replace(/[^a-z0-9]/gi, "-")}`;
1229
+ const pick = (e) => {
1230
+ e.stopPropagation();
1231
+ const patch = {};
1232
+ if (pv.mixed || e.detail.family !== pv.value)
1233
+ patch[key] = e.detail.family;
1234
+ if (weight && (weight.mixed || weight.value !== e.detail.weight))
1235
+ patch.fontWeight = e.detail.weight;
1236
+ if (Object.keys(patch).length > 0)
1237
+ this.#commit(key, patch);
1238
+ this.#close(this.renderRoot.querySelector(`#${id}`));
1239
+ };
1240
+ return html `<button class="select-btn ${wide ? "wide" : ""}" part="font" data-key=${key} aria-label=${`${this.#label(key)}: ${shown}`} aria-haspopup="dialog" ?disabled=${s.readOnly}
1241
+ @pointerdown=${keepFocus} @mousedown=${keepFocus} @click=${(e) => this.#pop(e, id)} ${kept()}><span class=${pv.mixed ? "mixed" : ""}>${shown}</span>${this.drawIcon("chevron-down", 14)}</button
1242
+ ><daas-popover id=${id} placement="left-start" ${kept()}><daas-font-picker .fonts=${fonts} .value=${pv.mixed ? null : (family ?? null)} .weight=${num(first(weight))} .mixed=${!!pv.mixed}
1243
+ @daas-commit=${pick}></daas-font-picker></daas-popover>`;
1244
+ }
1245
+ #generic(key, sec, row) {
1246
+ const label = this.#label(key);
1247
+ if (this.#shown[key].descriptor.type === "paints" && !this.#hostedFor(key, true))
1248
+ return this.#genericStack(key, sec, row, label);
1249
+ return line([html `<span class="name" title=${label}>${label}</span>`, this.#field(key, sec, row, true)]);
1250
+ }
1251
+ #genericStack(key, sec, row, label) {
1252
+ const pv = this.#structural(key);
1253
+ const layers = pv.mixed ? ["mixed"] : stack(pv.value).map((_, i) => i).reverse();
1254
+ return [
1255
+ line(html `<span class="name wide" title=${label}>${label}</span>`, this.state.readOnly ? nothing : this.#btn("plus", `${this.t("pane.addFill")}: ${label}`, () => this.#addLayer(key))),
1256
+ html `<div class="lines">${keyed(layers, (i) => (i === "mixed" ? i : `layer:${i}`), (i) => html `<div class="row layer-row">${this.#layer(key, sec, row, i)}</div>`)}</div>`,
1257
+ ];
1258
+ }
1259
+ #section(m) {
1260
+ const id = `title-${m.id}`;
1261
+ const adds = m.empty && m.own && !this.state.readOnly && this.#adds(m.id);
1262
+ return html `<section class="section ${m.empty || m.disabled ? "muted" : ""}" part="section" data-section=${m.id} aria-labelledby=${id}><div class="head"><button class="title" id=${id} part="section-title"
1263
+ aria-expanded=${adds ? nothing : String(!m.collapsed)} @pointerdown=${keepFocus} @mousedown=${keepFocus} @click=${() => this.#titleClick(m)} ${kept()}>${m.custom ? m.custom.title : this.t(`pane.${m.id}`)}</button
1264
+ ><div class="gutter">${this.#headGutter(m)}</div></div
1265
+ >${keyed(m.rows, (r) => r, (r) => html `<div class="row ${r.startsWith("layer:") || r === "mixed" ? "layer-row" : ""}" part="row" data-sec=${m.id} data-row=${`${m.id}:${r}`}>${guard([this.#sum(this.#rowKeys(m, r)), this.#epoch, m.disabled, r === "custom" ? this.#data() : ""], () => this.#row(m, r))}</div>`)}</section>`;
1266
+ }
1267
+ #headGutter(m) {
1268
+ if (m.id === "text")
1269
+ return this.#btn(m.collapsed ? "chevron-right" : "chevron-down", this.t("pane.text"), () => this.#titleClick({ ...m, empty: false }), { expanded: !m.collapsed });
1270
+ if (this.state.readOnly)
1271
+ return nothing;
1272
+ if (m.id === "layout")
1273
+ return m.disabled ? nothing : this.#layoutMenu();
1274
+ if (!m.own)
1275
+ return nothing;
1276
+ if ((m.empty || m.id === "fill") && this.#adds(m.id))
1277
+ return this.#btn("plus", this.t(ADDS[m.id][1]), () => this.#add(m.id));
1278
+ return m.id === "stroke" && !m.empty && STROKE_MORE_KEYS.some((k) => k in this.#shown) ? this.#strokeMore() : nothing;
1279
+ }
1280
+ #row(m, r) {
1281
+ const row = `${m.id}:${r}`;
1282
+ if (r === "key:fills" && m.id === "fill")
1283
+ return line(html `<div class="wide">${this.#hostedFor("fills", false) ?? nothing}</div>`);
1284
+ if (r.startsWith("key:"))
1285
+ return this.#generic(r.slice(4), m.id, row);
1286
+ if (r.startsWith("layer:") || r === "mixed")
1287
+ return this.#layer("fills", m.id, row, r === "mixed" ? r : Number(r.slice(6)));
1288
+ if (r === "custom")
1289
+ return this.#custom(m);
1290
+ const v = this.#shown;
1291
+ switch (row) {
1292
+ case "layout:align":
1293
+ return line(html `<div class="aligns wide">${LAYOUT_COMMANDS.slice(0, 6).map((n) => this.#btn(`align-objects-${n.slice(5).toLowerCase()}`, this.t(`command.${n}`), () => this.#run(n), { disabled: !this.#canRun(n) }))}</div>`);
1294
+ case "text:padding": {
1295
+ const pair = (a, b, axis) => {
1296
+ const keys = [a, b].filter((k) => k in v);
1297
+ if (keys.length === 0)
1298
+ return GAP;
1299
+ const values = keys.map((k) => num(first(v[k])));
1300
+ const mixed = keys.some((k) => v[k].mixed) || values.some((x) => x !== values[0]);
1301
+ return this.#num(keys[0], { label: this.t(`short.padding${axis}`), name: this.t(`pane.padding${axis}`), value: values[0] ?? null, mixed, patch: (n) => Object.fromEntries(keys.map((k) => [k, n])) });
1302
+ };
1303
+ return line(keyed([this.#view.paddingSides ? "sides" : "pairs"], (m) => m, (m) => (m === "sides" ? [this.#field("paddingLeft"), this.#field("paddingRight")] : [pair("paddingLeft", "paddingRight", "X"), pair("paddingTop", "paddingBottom", "Y")])), this.#flip("paddingSides", "padding", "pane.paddingSides"));
1304
+ }
1305
+ case "effects:shadow":
1306
+ return this.#shadow(row);
1307
+ }
1308
+ return line((CELLS[row] ?? ROWS[m.id]?.[r] ?? []).map((k) => this.#field(k, m.id, row)), this.#gutter(row));
1309
+ }
1310
+ #gutter(row) {
1311
+ const v = this.#shown;
1312
+ const ro = this.state.readOnly;
1313
+ switch (row) {
1314
+ case "layout:size":
1315
+ return "w" in v && "h" in v && !ro ? this.#flip("lock", this.#view.lock ? "lock" : "unlock", "pane.lockRatio") : nothing;
1316
+ case "appearance:opacity":
1317
+ return CORNER_KEYS.some((k) => k in v) ? this.#flip("corners", "corners", "pane.corners") : nothing;
1318
+ case "text:font":
1319
+ return this.#textMore();
1320
+ case "stroke:color":
1321
+ return ro ? nothing : this.#btn("minus", this.t("pane.removeStroke"), (e) => this.#removeStroke(e));
1322
+ case "stroke:geometry":
1323
+ return SIDE_KEYS.some((k) => k in v) && !ro ? this.#sides() : nothing;
1324
+ case "stroke:ends":
1325
+ return "lineStart" in v && "lineEnd" in v && !ro
1326
+ ? this.#btn("swap", this.t("pane.swapEnds"), () => this.#commit("lineStart", this.#applicable(["lineStart", "lineEnd"], (o) => ({ lineStart: v.lineEnd.descriptor.read(o), lineEnd: v.lineStart.descriptor.read(o) }))))
1327
+ : nothing;
1328
+ }
1329
+ return nothing;
1330
+ }
1331
+ #flip(name, icon, label) {
1332
+ return this.#btn(icon, this.t(label), () => {
1333
+ this.#view[name] = !this.#view[name];
1334
+ this.#bump();
1335
+ }, { pressed: this.#view[name] });
1336
+ }
1337
+ #more(id, icon, label, content) {
1338
+ return html `${this.#btn(icon, this.t(label), (e) => this.#pop(e, id))}<daas-popover id=${id} placement="bottom-end" ${kept()}>${content}</daas-popover>`;
1339
+ }
1340
+ #canRun(name) {
1341
+ if (!this.#can) {
1342
+ const cmds = this.#ctrl.commands;
1343
+ const can = {};
1344
+ for (const n of LAYOUT_COMMANDS)
1345
+ can[n] = cmds[n]?.canRun() ?? false;
1346
+ this.#can = can;
1347
+ }
1348
+ return this.#can[name] ?? false;
1349
+ }
1350
+ #run(name) {
1351
+ const cmd = this.#gate(null, {}, false) ? this.#ctrl.commands[name] : undefined;
1352
+ if (!cmd?.canRun())
1353
+ return;
1354
+ cmd.run();
1355
+ this.#can = null;
1356
+ this.#bump();
1357
+ }
1358
+ #layoutMenu() {
1359
+ const h = this.#canRun("distributeHorizontal");
1360
+ const v = this.#canRun("distributeVertical");
1361
+ const strings = this.state.options.strings;
1362
+ const items = this.#memo("layout-menu", [h, v, strings], () => LAYOUT_COMMANDS.slice(6).map((n) => ({ value: n, label: strings.t(`command.${n}`), icon: `distribute-${n.slice(10).toLowerCase()}`, disabled: !this.#canRun(n) })));
1363
+ return html `${this.#btn("more-vertical", this.t("pane.layoutMore"), (e) => this.renderRoot.querySelector("#layout-menu")?.toggle(e.currentTarget))}<daas-menu
1364
+ id="layout-menu" label=${this.t("pane.layoutMore")} placement="bottom-end" .items=${items} @daas-commit=${(e) => this.#run(e.detail)} ${kept()}></daas-menu>`;
1365
+ }
1366
+ #size(key, n) {
1367
+ const v = this.#shown;
1368
+ if (!this.#view.lock || (key !== "w" && key !== "h") || !v.w || !v.h || v.w.mixed || v.h.mixed)
1369
+ return { [key]: n };
1370
+ const w = num(v.w.value);
1371
+ const h = num(v.h.value);
1372
+ const ratio = (this.#ratio ??= w && h ? h / w : null);
1373
+ if (!ratio)
1374
+ return { [key]: n };
1375
+ return key === "w" ? { w: n, h: Number((n * ratio).toFixed(2)) } : { h: n, w: Number((n / ratio).toFixed(2)) };
1376
+ }
1377
+ #textMore() {
1378
+ const v = this.#shown;
1379
+ if (this.state.readOnly || !TEXT_MORE_KEYS.some((k) => k in v))
1380
+ return nothing;
1381
+ const fields = (keys) => keys.filter((k) => k in v).map((k) => this.#field(k));
1382
+ return this.#more("text-more", "more", "pane.textMore", html `<div class="pop"><div class="toggles">${fields(TEXT_MORE_KEYS.slice(0, 4))}</div>${fields(TEXT_MORE_KEYS.slice(4))}</div>`);
1383
+ }
1384
+ #strokeMore() {
1385
+ const keys = STROKE_MORE_KEYS.filter((k) => k in this.#shown);
1386
+ return this.#more("stroke-more", "more", "pane.strokeMore", html `<div class="pop"><div class="main">${keys.map((k) => html `<span class="name">${this.#label(k)}</span>${this.#field(k)}`)}</div></div>`);
1387
+ }
1388
+ #sides() {
1389
+ const side = (key) => {
1390
+ const pv = this.#shown[key];
1391
+ if (!pv)
1392
+ return nothing;
1393
+ const host = this.#hostedFor(key, false);
1394
+ if (host)
1395
+ return host;
1396
+ const on = pv.mixed ? "mixed" : pv.value ? "true" : "false";
1397
+ return html `<button class="side ${key.slice(6).toLowerCase()}" aria-label=${this.#label(key)} aria-pressed=${on} @pointerdown=${keepFocus} @mousedown=${keepFocus}
1398
+ @click=${() => this.#commit(key, { [key]: on !== "true" })} ${kept()}></button>`;
1399
+ };
1400
+ return this.#more("sides", "sides", "pane.strokeSides", html `<div class="square" role="group" aria-label=${this.t("pane.strokeSides")}>${SIDE_KEYS.map(side)}</div>`);
1401
+ }
1402
+ #removeStroke(e) {
1403
+ this.#focusBefore(e.currentTarget.closest("[data-row]"), () => this.#title("stroke"));
1404
+ this.#commit("stroke", { stroke: undefined });
1405
+ }
1406
+ #shadow(row) {
1407
+ const v = this.#shown;
1408
+ const remove = (e) => {
1409
+ this.#focusBefore(e.currentTarget.closest("[data-row]"), () => this.#title("effects"));
1410
+ this.#commit("shadowOn", { shadowOn: false });
1411
+ };
1412
+ return line(html `<button class="paint wide" part="effect" aria-haspopup="dialog" @pointerdown=${keepFocus} @mousedown=${keepFocus} @click=${(e) => this.#pop(e, "shadow")} ${kept()}><daas-swatch
1413
+ .paint=${(first(v.shadowColor) ?? null)} .mixed=${!!v.shadowColor?.mixed}></daas-swatch
1414
+ ><span>${this.t("pane.dropShadow")}${v.shadowOn?.mixed ? ` (${this.t("value.mixed")})` : ""}</span></button
1415
+ ><daas-popover id="shadow" placement=${this.#toward} ${kept()}><div class="pop">
1416
+ <div class="main">${SHADOW_KEYS.slice(0, 4).map((k) => this.#field(k))}</div>${"shadowColor" in v ? this.#field("shadowColor", "effects", row) : nothing}${this.#pickerPopover("shadow-picker")}
1417
+ </div></daas-popover>`, this.state.readOnly ? nothing : this.#btn("minus", this.t("pane.removeEffect"), remove));
1418
+ }
1419
+ render() {
1420
+ const s = this.state;
1421
+ const open = this.open;
1422
+ const label = this.t("surface.properties");
1423
+ return html `<div class="pane" part="pane" @keydown=${(e) => this.#onKey(e)} @daas-close=${this.#onClose}>${this.mode === "container"
1424
+ ? nothing
1425
+ : html `<div class="bar">${this.#btn("panel", this.t(open ? "pane.hide" : "pane.show"), (e) => this.#toggle(e), { expanded: open, text: label })}</div>`}${open && s
1426
+ ? html `<div class="body" id="body" part="body" role="region" aria-label=${label}>${keyed(this.#model, (m) => m.id, (m) => this.#guarded(m))}${guard([this.#pick, this.#epoch, this.#pick ? this.#versions.get(this.#pick.key) : 0], () => this.#pickerPopover("picker"))}</div>`
1427
+ : nothing}${this.#tip.template()}</div>`;
1428
+ }
1429
+ }