@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,502 @@
1
+ import { css, html, nothing, svg } from "lit";
2
+ import { isPresetName, PRESET_PATHS } from "@daasboard/editor";
3
+ import { defineControls } from "../../controls/index.js";
4
+ import { baseStyles, focused, keepFocus, within } from "../../controls/shared.js";
5
+ import { Tooltip, tooltipStyles } from "../../controls/tooltip.js";
6
+ import { icon, ICON_NAMES } from "../../icons/index.js";
7
+ import { DEFAULT_TOOL_SHORTCUTS } from "../../keys.js";
8
+ import { STICKY_COLORS } from "../../palette.js";
9
+ import { UiSurface } from "../../surface.js";
10
+ import { rootReset, themeStyles, tok } from "../../theme.js";
11
+ import { handleZoomKey, ZOOM_SHORTCUTS, ZOOM_LEVELS } from "./keys.js";
12
+ export { ZOOM_SHORTCUTS } from "./keys.js";
13
+ import { CreationColorMemory, overflowCount, resolveToolbarOptions, toolbarGroups } from "./model.js";
14
+ export const TOOLS_TAG = "daas-tools-toolbar";
15
+ const QUICK_COMMANDS = ["undo", "redo", "delete", "duplicate"];
16
+ const toolId = (tool) => typeof tool === "string" ? tool : tool.id;
17
+ const zoomLevel = (value) => value === "50" ? .5 : value === "200" ? 2 : ZOOM_LEVELS[value];
18
+ const styles = css `
19
+ :host{display: flex;flex-direction: column;align-items: center;gap: 6px;pointer-events: auto;max-width: 100%;}:host([data-placement="left"]), :host([data-placement="right"]){flex-direction: row;align-items: flex-start;}:host([data-placement="right"]){flex-direction: row-reverse;}:host([hidden]){display: none;}.bar, .tray{display: flex;align-items: center;gap: 4px;padding: 4px;border: 1px solid ${tok("border")};border-radius: ${tok("radius")};background: ${tok("bg")};box-shadow: ${tok("shadow")};}.bar{position: relative;flex: none;max-width: 100%;overflow-x: auto;}.group, .slot, .zoom-group{display: flex;align-items: center;flex: none;}.group{gap: 2px;}.group.divided, .zoom-group{border-left: 1px solid ${tok("border")};padding-left: 4px;}.bar.vertical{flex-direction: column;}.vertical .group{flex-direction: column;}.vertical .group.divided, .vertical .zoom-group{border-left: 0;padding-left: 0;border-top: 1px solid ${tok("border")};padding-top: 4px;}.measure{display: contents;}.measure.clipped{display: block;position: absolute;width: 0;height: 0;overflow: clip;visibility: hidden;pointer-events: none;}.group[hidden], button[data-action="more"][hidden]{display: flex !important;width: max-content;visibility: hidden;}button{display: inline-flex;align-items: center;justify-content: center;gap: 4px;height: ${tok("control")};min-width: ${tok("control")};padding: 0 6px;border-radius: calc(${tok("radius")} - 4px);flex: none;}button:hover:not(:disabled){background: ${tok("hover")};}button[aria-pressed="true"]{background: ${tok("accentSoft")};box-shadow: inset 0 0 0 1px ${tok("accent")};}button[data-split]{min-width: 16px;width: 16px;padding: 0;}button[data-action="zoom"]{min-width: 64px;font-variant-numeric: tabular-nums;white-space: nowrap;}button[data-color]{min-width: 24px;width: 24px;height: 24px;padding: 3px;}.swatch{display: block;width: 18px;height: 18px;border: 1px solid ${tok("borderStrong")};border-radius: 50%;}.tray{max-width: 100%;flex-wrap: wrap;justify-content: center;}.trays{display: flex;gap: 6px;max-width: 100%;flex-wrap: wrap;justify-content: center;}:host([data-placement="left"]) .trays, :host([data-placement="right"]) .trays{flex-direction: column;flex-wrap: nowrap;align-items: flex-start;flex: none;}:host([data-placement="bottom"]) .trays{order: -1;}`;
20
+ export class ToolsToolbar extends UiSurface {
21
+ static styles = [rootReset, baseStyles, themeStyles, tooltipStyles, styles];
22
+ keyHandler = null;
23
+ #tooltip = new Tooltip(this);
24
+ #groups = [];
25
+ #visible = Infinity;
26
+ #last = new Map();
27
+ #memory = null;
28
+ #restored = false;
29
+ #touch = false;
30
+ #touchPointers = new Set();
31
+ #board = null;
32
+ #resize = null;
33
+ #observed = new Set();
34
+ #menuTools = [];
35
+ #menuSlot = null;
36
+ #menuPointer = false;
37
+ #tab = null;
38
+ #readOnly = false;
39
+ #activeTool = null;
40
+ #localVersion = 0;
41
+ #drawn = [];
42
+ #focusAfter = null;
43
+ connectedCallback() {
44
+ super.connectedCallback();
45
+ this.#board = this.ui?.container ?? null;
46
+ this.#watchPointers("addEventListener");
47
+ }
48
+ disconnectedCallback() {
49
+ this.#resize?.disconnect();
50
+ this.#resize = null;
51
+ this.#observed.clear();
52
+ this.#watchPointers("removeEventListener");
53
+ this.#touchPointers.clear();
54
+ this.#board = null;
55
+ super.disconnectedCallback();
56
+ }
57
+ #watchPointers(method) {
58
+ for (const target of [this, this.#board])
59
+ for (const type of ["pointerdown", "pointerup", "pointercancel"]) {
60
+ target?.[method](type, (type === "pointerdown" ? this.#pointer : this.#pointerEnd), { capture: true, passive: true });
61
+ }
62
+ }
63
+ setCreationColor(tool, color) {
64
+ const s = this.state;
65
+ if (!s || s.host.readOnly() || !this.#memory)
66
+ return false;
67
+ const changed = this.#memory.set(tool, color, s.host.tools);
68
+ if (changed)
69
+ this.requestUpdate();
70
+ return changed;
71
+ }
72
+ handleKey(e) {
73
+ if (this.keyHandler)
74
+ return this.keyHandler(e);
75
+ const s = this.state;
76
+ return s ? handleZoomKey(e, this.ui?.options ?? s.options, s.host, this.ui?.mac ?? false) : false;
77
+ }
78
+ #pointer = (e) => {
79
+ if ((e.pointerType === "touch" || e.pointerType === "pen") && !this.#touch)
80
+ this.#touchPointers.add(e.pointerId);
81
+ };
82
+ #pointerEnd = (e) => {
83
+ if (this.#touchPointers.delete(e.pointerId) && !this.#touchPointers.size) {
84
+ this.#touch = true;
85
+ this.requestUpdate();
86
+ }
87
+ };
88
+ #options() {
89
+ return resolveToolbarOptions(this.state?.options.toolbar || {});
90
+ }
91
+ requestUpdate(...args) {
92
+ if (this.hasUpdated && args.length === 0)
93
+ this.#localVersion++;
94
+ super.requestUpdate(...args);
95
+ }
96
+ shouldUpdate(_changed) {
97
+ const s = this.state;
98
+ if (!s)
99
+ return !this.hasUpdated;
100
+ const commands = this.#touch && !s.readOnly && this.#options().quickActions.touch
101
+ ? QUICK_COMMANDS.map((name) => !!s.host.controller.commands[name]?.canRun()).join()
102
+ : "";
103
+ const inputs = [s.tool, s.readOnly, s.zoom, s.options, commands, this.#localVersion];
104
+ if (this.hasUpdated && inputs.every((value, i) => value === this.#drawn[i]))
105
+ return false;
106
+ this.#drawn = inputs;
107
+ return true;
108
+ }
109
+ willUpdate() {
110
+ const s = this.state;
111
+ if (!s)
112
+ return;
113
+ const options = this.#options();
114
+ this.dataset.placement = typeof options.placement === "string" ? options.placement : "container";
115
+ const groups = toolbarGroups(s.options.toolbar === false ? [] : s.options.toolbar.tools, s.readOnly)
116
+ .map(group => ({ ...group, slots: group.slots.map(slot => ({ ...slot,
117
+ tools: slot.tools.filter(tool => tool !== "image" || !!s.host.insertImages) })).filter(slot => slot.tools.length) }))
118
+ .filter(group => group.slots.length);
119
+ this.#keepFocus(groups, this.#visible, s.readOnly);
120
+ this.#groups = groups;
121
+ if (this.#memory?.prefs !== s.options.prefs || this.#memory.remember !== options.rememberToolStyles) {
122
+ if (!this.#memory)
123
+ this.#memory = new CreationColorMemory(s.options.prefs, options.rememberToolStyles);
124
+ else
125
+ this.#memory.configure(s.options.prefs, options.rememberToolStyles);
126
+ this.#restored = false;
127
+ }
128
+ if (!this.#restored && !s.readOnly && !s.host.readOnly()) {
129
+ this.#memory.restore(s.host.tools);
130
+ this.#restored = true;
131
+ }
132
+ if (this.#activeTool !== s.tool) {
133
+ for (const group of this.#groups)
134
+ for (const slot of group.slots) {
135
+ if (slot.tools.some((tool) => tool === s.tool))
136
+ this.#last.set(slot.id, s.tool);
137
+ }
138
+ this.#activeTool = s.tool;
139
+ }
140
+ if (s.readOnly !== this.#readOnly) {
141
+ this.#menu("tools")?.hide();
142
+ this.#readOnly = s.readOnly;
143
+ }
144
+ }
145
+ #selected(slot) {
146
+ return slot.tools.find((tool) => toolId(tool) === this.#last.get(slot.id)) ?? slot.tools[0];
147
+ }
148
+ #label(tool) {
149
+ return typeof tool === "string" ? this.t(`tool.${tool}`) : tool.label;
150
+ }
151
+ #shortcut(tool) {
152
+ if (typeof tool !== "string")
153
+ return tool.shortcut;
154
+ const overrides = this.state?.options.shortcuts;
155
+ if (overrides && tool in overrides)
156
+ return overrides[tool] ?? undefined;
157
+ return tool in ZOOM_SHORTCUTS ? ZOOM_SHORTCUTS[tool] : DEFAULT_TOOL_SHORTCUTS[tool];
158
+ }
159
+ #drawTool(tool) {
160
+ if (typeof tool !== "string") {
161
+ const known = typeof tool.icon === "string" && ICON_NAMES.includes(tool.icon) ? tool.icon : null;
162
+ return known ? this.drawIcon(known) : icon("tool-rect", 18, { "tool-rect": tool.icon });
163
+ }
164
+ if (!isPresetName(tool))
165
+ return this.drawIcon(`tool-${tool}`, 18);
166
+ const path = PRESET_PATHS[tool].map((c) => {
167
+ switch (c.t) {
168
+ case "M":
169
+ case "L": return `${c.t}${c.x} ${c.y}`;
170
+ case "Q": return `Q${c.cx} ${c.cy} ${c.x} ${c.y}`;
171
+ case "C": return `C${c.c1x} ${c.c1y} ${c.c2x} ${c.c2y} ${c.x} ${c.y}`;
172
+ case "Z": return "Z";
173
+ }
174
+ }).join(" ");
175
+ return svg `<svg class="icon" part="icon" aria-hidden="true" width="18" height="18" viewBox="-.1 -.1 1.2 1.2" fill="none" stroke="currentColor" stroke-width=".09" stroke-linejoin="round"><path d=${path}></path></svg>`;
176
+ }
177
+ recordToolUse(tool, slot = null) {
178
+ const options = this.ui?.options ?? this.state?.options;
179
+ if (!options || options.toolbar === false)
180
+ return;
181
+ const groups = toolbarGroups(options.toolbar.tools, this.state?.host.readOnly() ?? false);
182
+ for (const groupSlot of groups.flatMap((group) => group.slots)) {
183
+ if ((!slot || groupSlot.id === slot) && groupSlot.tools.some((entry) => toolId(entry) === toolId(tool)))
184
+ this.#last.set(groupSlot.id, toolId(tool));
185
+ }
186
+ this.#activeTool = this.state?.host.tools.active ?? this.#activeTool;
187
+ this.requestUpdate();
188
+ }
189
+ #activate(tool, slot, pointer) {
190
+ const host = this.state?.host;
191
+ if (!host || (host.readOnly() && tool !== "select" && tool !== "hand"))
192
+ return;
193
+ if (tool === "image")
194
+ host.insertImages?.();
195
+ else if (typeof tool === "string")
196
+ host.tools.setTool(tool);
197
+ else
198
+ tool.activate(host);
199
+ this.recordToolUse(tool, slot);
200
+ if (pointer)
201
+ host.returnFocus();
202
+ this.requestUpdate();
203
+ }
204
+ #menu(which) {
205
+ return this.renderRoot.querySelector(`daas-menu[data-menu="${which}"]`);
206
+ }
207
+ async #openTools(anchor, tools, slot, keyboard = false, last = false) {
208
+ this.#tooltip.hide();
209
+ const menu = this.#menu("tools");
210
+ if (menu?.open && this.#menuSlot === slot && menu.shadowRoot?.querySelector("daas-popover")?.opener === anchor) {
211
+ menu.hide();
212
+ return;
213
+ }
214
+ menu?.hide();
215
+ this.#menuTools = tools;
216
+ this.#menuSlot = slot;
217
+ this.#menuPointer = !keyboard;
218
+ menu.items = this.#toolMenuItems();
219
+ await menu.updateComplete;
220
+ if (!anchor.isConnected)
221
+ return;
222
+ await menu.show(anchor, last ? "last" : "checked");
223
+ this.requestUpdate();
224
+ }
225
+ #zoomItems() {
226
+ return ["zoomIn", "zoomOut", "50", "zoomReset", "200", "zoomFit", "zoomSelection"].map((value) => {
227
+ const level = zoomLevel(value);
228
+ const shortcut = this.#shortcut(value);
229
+ return { value, label: typeof level === "number" ? this.#percent(level * 100) : this.t(`zoom.${level}`),
230
+ ...(level === "in" || level === "out" ? { icon: `zoom-${level}` } : {}),
231
+ ...(shortcut ? { shortcut } : {}), ...(typeof level === "number" ? { checked: this.state?.zoom === level } : {}), };
232
+ });
233
+ }
234
+ async #openZoom(button, focus) {
235
+ const menu = this.#menu("zoom");
236
+ menu.items = this.#zoomItems();
237
+ await menu.updateComplete;
238
+ if (!button.isConnected)
239
+ return;
240
+ if (focus)
241
+ await menu.show(button, focus);
242
+ else
243
+ menu.toggle(button);
244
+ this.requestUpdate();
245
+ }
246
+ #zoom(value) {
247
+ const level = zoomLevel(value);
248
+ if (level !== undefined)
249
+ this.state?.host.camera.zoomTo(level);
250
+ if (this.#menuPointer)
251
+ queueMicrotask(() => this.state?.host.returnFocus());
252
+ }
253
+ #toolMenuItems() {
254
+ return this.#menuTools.map((tool) => ({ value: toolId(tool), label: this.#label(tool), checked: typeof tool === "string" && this.state?.tool === tool,
255
+ ...(this.#shortcut(tool) ? { shortcut: this.#shortcut(tool) } : {}),
256
+ disabled: !!this.state?.host.readOnly() && tool !== "select" && tool !== "hand", }));
257
+ }
258
+ #percent(value) {
259
+ return this.t("zoom.percent").replace("{value}", String(value));
260
+ }
261
+ #slot(slot) {
262
+ const tool = this.#selected(slot);
263
+ const shortcut = this.#shortcut(tool);
264
+ const split = slot.tools.length > 1;
265
+ const tint = typeof tool === "string" && tool !== "image" ? this.#memory?.color(tool) : null;
266
+ return html `<div class="slot">
267
+ <button part="tool" data-tool=${toolId(tool)} data-slot=${slot.id} data-roving=${slot.id} tabindex="-1" aria-label=${this.#label(tool)} aria-pressed=${String(typeof tool === "string" && this.state?.tool === tool)} aria-keyshortcuts=${this.shortcutAria(shortcut) || nothing} data-tip=${this.#label(tool)} data-shortcut=${this.shortcutText(shortcut) || nothing} style=${tint ? `color:${tint}` : nothing} @pointerenter=${this.#tooltip.enter} @pointerleave=${this.#tooltip.leave} @focus=${this.#tooltip.focus} @blur=${this.#tooltip.leave} @click=${(e) => this.#activate(tool, slot.id, e.detail > 0)}>
268
+ <span class="tool-icon" style=${tint ? `filter:drop-shadow(0 0 .5px var(--daas-ui-fg))` : nothing}>${this.#drawTool(tool)}</span>
269
+ </button>
270
+ ${split ? html `<button part="split" data-split=${slot.id} data-roving=${`${slot.id}-menu`} tabindex="-1" aria-label=${`${this.#label(tool)} — ${this.t("tools.options")}`} aria-haspopup="menu" aria-expanded=${String(!!this.#menu("tools")?.open && this.#menuSlot === slot.id)} @click=${(e) => void this.#openTools(e.currentTarget, slot.tools, slot.id, e.detail === 0)}>${this.drawIcon("chevron-down", 12)}</button>` : nothing}
271
+ </div>`;
272
+ }
273
+ #buttons(scope = this.renderRoot) {
274
+ return [...scope.querySelectorAll("button[data-roving]:not(:disabled)")].filter((button) => !button.hidden && !button.closest("[hidden]"));
275
+ }
276
+ #roving() {
277
+ for (const button of this.renderRoot.querySelectorAll("button[data-roving]"))
278
+ if (button.tabIndex !== -1)
279
+ button.tabIndex = -1;
280
+ for (const toolbar of this.renderRoot.querySelectorAll('[role="toolbar"]')) {
281
+ const buttons = this.#buttons(toolbar);
282
+ const tab = buttons.find((button) => button.dataset.roving === this.#tab) ?? buttons[0];
283
+ if (tab && tab.tabIndex !== 0)
284
+ tab.tabIndex = 0;
285
+ }
286
+ }
287
+ #keepFocus(groups, visible, readOnly) {
288
+ if (this.#focusAfter)
289
+ return;
290
+ const active = focused(this.ownerDocument);
291
+ if (!active || active === this || !within(this, active) || active.classList.contains("bar"))
292
+ return;
293
+ const group = active.closest("[data-group]");
294
+ const groupIndex = group ? groups.findIndex((g) => g.id === group.dataset.group) : -1;
295
+ let next = null;
296
+ if (readOnly && !this.#readOnly && active.dataset.tool !== "select" && active.dataset.tool !== "hand" && active.dataset.action !== "zoom") {
297
+ const selectSlot = groups.flatMap((g) => g.slots).find((slot) => slot.tools.includes("select"));
298
+ if (selectSlot)
299
+ this.#last.set(selectSlot.id, "select");
300
+ next = '[data-tool="select"]';
301
+ }
302
+ else if (group && (groupIndex < 0 || groupIndex >= visible)) {
303
+ next = visible < groups.length ? '[data-action="more"]' : "button[data-roving]";
304
+ }
305
+ else if (active.dataset.action === "more" && visible >= groups.length) {
306
+ const slot = groups[this.#visible]?.slots[0];
307
+ next = slot ? `[data-slot="${slot.id}"]` : '[data-action="zoom"]';
308
+ }
309
+ else if (active.dataset.action === "zoom" && !this.#options().zoom) {
310
+ next = "button[data-roving]";
311
+ }
312
+ else if ((active.dataset.color && (this.state?.tool !== "sticky" || !this.#options().quickActions.toolOptions))
313
+ || (active.dataset.command && !this.#options().quickActions.touch)) {
314
+ next = `[data-tool="${this.state?.tool}"]`;
315
+ }
316
+ if (!next)
317
+ return;
318
+ this.#focusAfter = next;
319
+ this.renderRoot.querySelector(".bar")?.focus({ preventScroll: true });
320
+ }
321
+ #keys(e) {
322
+ if (this.state?.host.allowsKey?.(e) === false)
323
+ return;
324
+ if (e.defaultPrevented || e.isComposing || e.keyCode === 229)
325
+ return;
326
+ const button = e.target;
327
+ if (!button.matches?.("button[data-roving]"))
328
+ return;
329
+ const vertical = button.closest('[role="toolbar"]')?.getAttribute("aria-orientation") === "vertical";
330
+ const opener = e.key === (vertical ? "ArrowRight" : "ArrowDown") || (!vertical && e.key === "ArrowUp") || (e.altKey && e.key === "ArrowDown");
331
+ if (opener) {
332
+ const slot = this.#groups.flatMap((group) => group.slots).find((slot) => slot.id === (button.dataset.slot ?? button.dataset.split));
333
+ if (slot && slot.tools.length > 1) {
334
+ e.preventDefault();
335
+ void this.#openTools(button, slot.tools, slot.id, true, e.key === "ArrowUp");
336
+ return;
337
+ }
338
+ if (button.dataset.action === "more" || button.dataset.action === "zoom") {
339
+ e.preventDefault();
340
+ if (button.dataset.action === "more")
341
+ void this.#openTools(button, this.#overflowTools(), null, true, e.key === "ArrowUp");
342
+ else {
343
+ this.#menuPointer = false;
344
+ void this.#openZoom(button, e.key === "ArrowUp" ? "last" : "first");
345
+ }
346
+ return;
347
+ }
348
+ }
349
+ const buttons = this.#buttons(button.closest('[role="toolbar"]') ?? this.renderRoot);
350
+ let index = buttons.indexOf(button);
351
+ if (e.key === (vertical ? "ArrowDown" : "ArrowRight"))
352
+ index++;
353
+ else if (e.key === (vertical ? "ArrowUp" : "ArrowLeft"))
354
+ index--;
355
+ else if (e.key === "Home")
356
+ index = 0;
357
+ else if (e.key === "End")
358
+ index = buttons.length - 1;
359
+ else {
360
+ if (!this.handleKey(e) && e.key === "Escape") {
361
+ e.preventDefault();
362
+ this.state?.host.returnFocus();
363
+ }
364
+ return;
365
+ }
366
+ e.preventDefault();
367
+ const next = buttons[(index + buttons.length) % buttons.length];
368
+ if (next) {
369
+ this.#tab = next.dataset.roving;
370
+ this.#roving();
371
+ next.focus();
372
+ }
373
+ }
374
+ #overflowTools() {
375
+ return this.#groups.slice(this.#visible).flatMap((group) => group.slots.flatMap((slot) => slot.tools));
376
+ }
377
+ render() {
378
+ const s = this.state;
379
+ if (!s || s.options.toolbar === false)
380
+ return nothing;
381
+ const options = this.#options();
382
+ const more = this.#visible < this.#groups.length;
383
+ return html `<div class="bar ${options.vertical ? "vertical" : ""}" role="toolbar" tabindex="-1" aria-label=${this.t("surface.tools")} aria-orientation=${options.vertical ? "vertical" : "horizontal"} @pointerdown=${this.#press} @mousedown=${keepFocus} @keydown=${(e) => this.#keys(e)} @focusin=${(e) => { const button = e.target; if (button.dataset.roving) {
384
+ this.#tab = button.dataset.roving;
385
+ this.#roving();
386
+ } }}>
387
+ ${this.#groups.map((group, index) => html `<div class="measure ${index >= this.#visible ? "clipped" : ""}"><div class="group ${index ? "divided" : ""}" data-group=${group.id} ?hidden=${index >= this.#visible} ?inert=${index >= this.#visible}>${group.slots.map((slot) => this.#slot(slot))}</div></div>`)}
388
+ <div class="measure ${more ? "" : "clipped"}"><button part="more" data-action="more" data-roving="more" tabindex="-1" ?hidden=${!more} ?inert=${!more} aria-label=${this.t("tools.more")} aria-haspopup="menu" aria-expanded=${String(!!this.#menu("tools")?.open && this.#menuSlot === null)} @click=${(e) => void this.#openTools(e.currentTarget, this.#overflowTools(), null, e.detail === 0)}>${this.drawIcon("more")}</button></div>
389
+ ${options.zoom ? html `<div class="zoom-group"><button part="zoom" data-action="zoom" data-roving="zoom" tabindex="-1" aria-label=${this.t("zoom.menu")} aria-haspopup="menu" aria-expanded=${String(this.#menu("zoom")?.open ?? false)} @click=${(e) => { this.#menuPointer = e.detail > 0; void this.#openZoom(e.currentTarget); }}>
390
+ ${this.#percent(Math.round(s.zoom * 100))}${this.drawIcon("chevron-down", 12)}</button></div>` : nothing}
391
+ </div>
392
+ <div class="trays" @pointerdown=${this.#press} @mousedown=${keepFocus}>
393
+ ${!s.readOnly && s.tool === "sticky" && options.quickActions.toolOptions ? this.#tray(true) : nothing}
394
+ ${!s.readOnly && this.#touch && options.quickActions.touch ? this.#tray(false) : nothing}
395
+ </div>
396
+ ${this.#renderMenu("tools")}${this.#renderMenu("zoom")}${this.#tooltip.template()}`;
397
+ }
398
+ #press = (e) => {
399
+ keepFocus(e);
400
+ this.#tooltip.hide();
401
+ };
402
+ #tray(colors) {
403
+ const host = this.state.host;
404
+ const items = colors
405
+ ? STICKY_COLORS.map(({ color, label }) => ({ value: color, label: `${this.t("tool.sticky")} ${this.t(label)}` }))
406
+ : QUICK_COMMANDS.map((value) => ({ value, label: this.t(`command.${value}`) }));
407
+ return html `<div class="tray" role="toolbar" aria-label=${this.t(colors ? "tools.colors" : "tools.quickActions")} @keydown=${this.#keys}>
408
+ ${items.map(({ value, label }, index) => html `<button data-color=${colors ? value : nothing} data-command=${colors ? nothing : value} data-roving=${colors ? `color-${index}` : value} tabindex="-1" aria-label=${label} aria-pressed=${colors ? String((this.#memory?.color("sticky") ?? STICKY_COLORS[0].color) === value) : nothing} ?disabled=${!colors && !host.controller.commands[value]?.canRun()} @click=${this.#quick}>
409
+ ${colors ? html `<span class="swatch" style=${`background:${value}`}></span>` : this.drawIcon(value)}
410
+ </button>`)}
411
+ </div>`;
412
+ }
413
+ #quick = (e) => {
414
+ const { color, command } = e.currentTarget.dataset;
415
+ const host = this.state.host;
416
+ if (color)
417
+ this.setCreationColor("sticky", color);
418
+ else {
419
+ const c = command ? host.controller.commands[command] : undefined;
420
+ if (!host.readOnly() && c?.canRun())
421
+ c.run();
422
+ this.requestUpdate();
423
+ }
424
+ if (e.detail > 0)
425
+ host.returnFocus();
426
+ };
427
+ #renderMenu(which) {
428
+ const options = this.#options();
429
+ const menu = this.#menu(which);
430
+ if (menu?.open)
431
+ menu.items = which === "tools" ? this.#toolMenuItems() : this.#zoomItems();
432
+ return html `<daas-menu data-menu=${which} label=${this.t(which === "tools" ? "tools.more" : "zoom.menu")} placement=${options.vertical ? "right-start" : `${options.placement === "bottom" ? "top" : "bottom"}-${which === "tools" ? "start" : "end"}`} @pointerdown=${(e) => { keepFocus(e); this.#menuPointer = true; }} @mousedown=${keepFocus} @keydown=${() => { this.#menuPointer = false; }} @daas-commit=${(e) => {
433
+ e.stopPropagation();
434
+ if (which === "zoom")
435
+ this.#zoom(e.detail);
436
+ else {
437
+ const tool = this.#menuTools.find((tool) => toolId(tool) === e.detail);
438
+ if (tool) {
439
+ this.#activate(tool, this.#menuSlot, false);
440
+ if (this.#menuPointer)
441
+ queueMicrotask(() => this.state?.host.returnFocus());
442
+ }
443
+ }
444
+ }} @daas-open=${() => this.requestUpdate()} @daas-close=${() => this.requestUpdate()}></daas-menu>`;
445
+ }
446
+ updated() {
447
+ this.#roving();
448
+ if (this.#focusAfter) {
449
+ const next = this.renderRoot.querySelector(this.#focusAfter);
450
+ this.#focusAfter = null;
451
+ (next && !next.closest("[hidden]") ? next : this.#buttons()[0])?.focus({ preventScroll: true });
452
+ }
453
+ const RO = this.ownerDocument.defaultView?.ResizeObserver;
454
+ if (!RO || !this.isConnected)
455
+ return;
456
+ this.#resize ??= new RO(() => this.#measure());
457
+ const elements = [this.ui?.container, this.parentElement, ...this.renderRoot.querySelectorAll(".bar, .group, .zoom-group, button[data-action=more]")].filter((el) => !!el);
458
+ for (const el of this.#observed)
459
+ if (!elements.includes(el)) {
460
+ this.#resize.unobserve(el);
461
+ this.#observed.delete(el);
462
+ }
463
+ for (const el of elements)
464
+ if (!this.#observed.has(el)) {
465
+ this.#resize.observe(el);
466
+ this.#observed.add(el);
467
+ }
468
+ }
469
+ #measure() {
470
+ if (!this.isConnected || !this.state)
471
+ return;
472
+ const options = this.#options();
473
+ const board = this.ui?.container ?? this.parentElement;
474
+ if (!board)
475
+ return;
476
+ const axis = options.vertical ? "offsetHeight" : "offsetWidth";
477
+ let available = (options.vertical ? board.clientHeight : board.clientWidth) - 24;
478
+ if (typeof options.placement === "object") {
479
+ const container = options.placement.container;
480
+ const style = this.ownerDocument.defaultView.getComputedStyle(container);
481
+ available = container.clientWidth - (parseFloat(style.paddingLeft) || 0) - (parseFloat(style.paddingRight) || 0);
482
+ }
483
+ this.style.maxWidth = `${Math.max(0, options.vertical ? board.clientWidth : available)}px`;
484
+ const groups = [...this.renderRoot.querySelectorAll(".group")];
485
+ const zoom = this.renderRoot.querySelector(".zoom-group");
486
+ const more = this.renderRoot.querySelector("button[data-action=more]");
487
+ const count = overflowCount(groups.map((el) => el[axis]), available, {
488
+ fixed: 10 + (zoom ? zoom[axis] + (groups.length ? 4 : 0) : 0), more: more?.[axis] ?? 0, gap: 4, enabled: options.overflow,
489
+ });
490
+ if (count !== this.#visible) {
491
+ this.#keepFocus(this.#groups, count, this.state.readOnly);
492
+ this.#visible = count;
493
+ this.#menu("tools")?.hide();
494
+ this.requestUpdate();
495
+ }
496
+ }
497
+ }
498
+ export function defineToolsToolbar() {
499
+ defineControls();
500
+ if (!customElements.get(TOOLS_TAG))
501
+ customElements.define(TOOLS_TAG, ToolsToolbar);
502
+ }
@@ -0,0 +1,26 @@
1
+ export interface ThemeTokens {
2
+ bg: string;
3
+ bg2: string;
4
+ fg: string;
5
+ text: string;
6
+ muted: string;
7
+ border: string;
8
+ borderStrong: string;
9
+ hover: string;
10
+ accent: string;
11
+ accentFg: string;
12
+ accentSoft: string;
13
+ danger: string;
14
+ radius: string;
15
+ font: string;
16
+ shadow: string;
17
+ control: string;
18
+ }
19
+ export type ThemeName = "light" | "dark" | "auto";
20
+ export declare const LIGHT_TOKENS: ThemeTokens;
21
+ export declare const DARK_TOKENS: ThemeTokens;
22
+ export declare const TOKEN_NAMES: (keyof ThemeTokens)[];
23
+ export declare const tokenVar: (name: keyof ThemeTokens) => string;
24
+ export declare const tok: (name: keyof ThemeTokens) => import("lit").CSSResult;
25
+ export declare const rootReset: import("lit").CSSResult;
26
+ export declare const themeStyles: import("lit").CSSResult;
package/dist/theme.js ADDED
@@ -0,0 +1,47 @@
1
+ import { css, unsafeCSS } from "lit";
2
+ export const LIGHT_TOKENS = {
3
+ bg: "#ffffff",
4
+ bg2: "#f8fafc",
5
+ fg: "#0f172a",
6
+ text: "#475569",
7
+ muted: "#64748b",
8
+ border: "#e2e8f0",
9
+ borderStrong: "#cbd5e1",
10
+ hover: "#f1f5f9",
11
+ accent: "#2563eb",
12
+ accentFg: "#ffffff",
13
+ accentSoft: "rgba(191, 219, 254, 0.45)",
14
+ danger: "#c92a2a",
15
+ radius: "10px",
16
+ font: 'ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',
17
+ shadow: "0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.1)",
18
+ control: "32px",
19
+ };
20
+ export const DARK_TOKENS = {
21
+ ...LIGHT_TOKENS,
22
+ bg: "#1e222b",
23
+ bg2: "#262b35",
24
+ fg: "#e7eaf0",
25
+ text: "#b7bfcd",
26
+ muted: "#8e97a9",
27
+ border: "#343a46",
28
+ borderStrong: "#4a5366",
29
+ hover: "#2c323e",
30
+ accent: "#7ea2ff",
31
+ accentFg: "#10152a",
32
+ accentSoft: "rgba(126, 162, 255, 0.16)",
33
+ danger: "#ff8787",
34
+ shadow: "0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px rgba(0, 0, 0, 0.45)",
35
+ };
36
+ export const TOKEN_NAMES = Object.keys(LIGHT_TOKENS);
37
+ export const tokenVar = (name) => `--daas-ui-${name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`;
38
+ export const tok = (name) => unsafeCSS(`var(${tokenVar(name)}, ${LIGHT_TOKENS[name]})`);
39
+ const declarations = (t, names = TOKEN_NAMES) => unsafeCSS(names.map((k) => `${tokenVar(k)}: ${t[k]};`).join(" "));
40
+ const DARK_CHANGES = TOKEN_NAMES.filter((k) => DARK_TOKENS[k] !== LIGHT_TOKENS[k]);
41
+ export const rootReset = css `
42
+ :host{all: initial;-webkit-font-smoothing: antialiased;}`;
43
+ export const themeStyles = css `
44
+ :host{${declarations(LIGHT_TOKENS)}
45
+ color-scheme: light;}:host([data-theme="dark"]){${declarations(DARK_TOKENS, DARK_CHANGES)}
46
+ color-scheme: dark;}@media (prefers-color-scheme: dark){:host([data-theme="auto"]){${declarations(DARK_TOKENS, DARK_CHANGES)}
47
+ color-scheme: dark;}}:host([data-density="compact"]){--daas-ui-control: 28px;}`;
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "@daasboard/ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "dependencies": {
8
+ "@daasboard/editor": "0.1.0",
9
+ "@floating-ui/dom": "1.8.0",
10
+ "lit": "3.3.3"
11
+ },
12
+ "license": "UNLICENSED",
13
+ "description": "Built-in controls and toolbars for daasboard.",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "LICENSE"
25
+ ],
26
+ "sideEffects": false,
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "engines": {
31
+ "node": ">=22.3.0"
32
+ },
33
+ "daasboardCommit": "ec08eb540f53c278ff9aa3d7c23a51407c429133"
6
34
  }