@weasel-js/labkit 1.5.0 → 1.5.1

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 (192) hide show
  1. package/README.md +41 -4
  2. package/dist/_dts/{CanvasStackContext-CqkxkFJW.d.ts → CanvasStackContext-CJNMS6mz.d.ts} +1 -1
  3. package/dist/_dts/{PrefsForm.d-DDHFANkc.d.ts → PrefsForm.d-DPy9I8It.d.ts} +4 -0
  4. package/dist/_dts/Select.d-Gwr8fLpK.d.ts +453 -0
  5. package/dist/_dts/{frac-8R6UmlvN.d.ts → frac-B4okC2lX.d.ts} +42 -4
  6. package/dist/_dts/{index-retnAut7.d.ts → index-BNdz-tNd.d.ts} +90 -10
  7. package/dist/_dts/{index-B8uu2ba7.d.ts → index-CSJoj4LC.d.ts} +17 -6
  8. package/dist/_dts/{types-Ca2LCnPq.d.ts → types-DzoNY1pO.d.ts} +28 -4
  9. package/dist/_dts/{usePanZoom-nS798rOF.d.ts → usePanZoom-Pzf9f2jh.d.ts} +2 -2
  10. package/dist/_dts/{useTrialState-jcx_TdU6.d.ts → useTrialState-uLlmaccn.d.ts} +1 -1
  11. package/dist/canvas/index.d.ts +5 -5
  12. package/dist/canvas/index.js +1 -1
  13. package/dist/chrome/index.d.ts +4 -4
  14. package/dist/chrome/index.js +7 -7
  15. package/dist/chunk-7PFH3CNM.js +150 -0
  16. package/dist/chunk-7PFH3CNM.js.map +1 -0
  17. package/dist/{chunk-PGETSEDK.js → chunk-CEIUBPPW.js} +10 -6
  18. package/dist/chunk-CEIUBPPW.js.map +1 -0
  19. package/dist/chunk-EH7UEQV7.js +590 -0
  20. package/dist/chunk-EH7UEQV7.js.map +1 -0
  21. package/dist/{chunk-EKIICY6X.js → chunk-EHGVROVV.js} +37 -25
  22. package/dist/chunk-EHGVROVV.js.map +1 -0
  23. package/dist/{chunk-ZPH5WTWF.js → chunk-ERFMC6WU.js} +142 -66
  24. package/dist/chunk-ERFMC6WU.js.map +1 -0
  25. package/dist/{chunk-NS64DXMN.js → chunk-IHUVQ3TX.js} +39 -16
  26. package/dist/chunk-IHUVQ3TX.js.map +1 -0
  27. package/dist/{chunk-QLSV2N3G.js → chunk-IJJUK4FU.js} +25 -13
  28. package/dist/chunk-IJJUK4FU.js.map +1 -0
  29. package/dist/{chunk-67SJLMC7.js → chunk-IXTQI7JX.js} +45 -12
  30. package/dist/chunk-IXTQI7JX.js.map +1 -0
  31. package/dist/{chunk-MUKOW3TC.js → chunk-MDVTK5U3.js} +4 -4
  32. package/dist/{chunk-MUKOW3TC.js.map → chunk-MDVTK5U3.js.map} +1 -1
  33. package/dist/{chunk-UU3NJO6N.js → chunk-PHK4W562.js} +3 -3
  34. package/dist/{chunk-UU3NJO6N.js.map → chunk-PHK4W562.js.map} +1 -1
  35. package/dist/chunk-PJ7WEQBJ.js +18 -0
  36. package/dist/chunk-PJ7WEQBJ.js.map +1 -0
  37. package/dist/chunk-T3EC2DXD.js +12628 -0
  38. package/dist/chunk-T3EC2DXD.js.map +1 -0
  39. package/dist/{chunk-KJALCDWE.js → chunk-UN4U4P63.js} +4 -4
  40. package/dist/{chunk-KJALCDWE.js.map → chunk-UN4U4P63.js.map} +1 -1
  41. package/dist/{chunk-NDRYLVOW.js → chunk-Z76KEZAX.js} +2 -2
  42. package/dist/chunk-Z76KEZAX.js.map +1 -0
  43. package/dist/{chunk-6ZDGOZQV.js → chunk-ZDHY47EV.js} +70 -17
  44. package/dist/chunk-ZDHY47EV.js.map +1 -0
  45. package/dist/config/index.d.ts +60 -16
  46. package/dist/config/index.js +6 -4
  47. package/dist/controls/index.d.ts +3 -3
  48. package/dist/controls/index.js +4 -4
  49. package/dist/dragdrop/index.d.ts +3 -3
  50. package/dist/index.d.ts +177 -53
  51. package/dist/index.js +1333 -1683
  52. package/dist/index.js.map +1 -1
  53. package/dist/layers/index.d.ts +4 -4
  54. package/dist/layers/index.js +2 -2
  55. package/dist/loupe/index.d.ts +67 -16
  56. package/dist/loupe/index.js +1 -1
  57. package/dist/passthrough/weasel-ui.d.ts +26 -202
  58. package/dist/passthrough/weasel-ui.js +1 -1
  59. package/dist/primitives/index.d.ts +3 -1
  60. package/dist/primitives/index.js +3 -3
  61. package/dist/state/index.d.ts +5 -5
  62. package/dist/state/index.js +5 -3
  63. package/dist/state/index.js.map +1 -1
  64. package/dist/styles.css +153 -40
  65. package/dist/surface/index.js +1 -1
  66. package/dist/ui/layers/index.js +1 -1
  67. package/dist/undo/index.d.ts +3 -3
  68. package/package.json +9 -9
  69. package/src/annotations/AnnotationOverlay.tsx +3 -0
  70. package/src/annotations/Annotations.less +4 -0
  71. package/src/annotations/Annotations.overlay.test.tsx +20 -0
  72. package/src/annotations/svgNodes.ts +1 -0
  73. package/src/annotations/toolMap.test.ts +9 -5
  74. package/src/annotations/toolMap.ts +3 -0
  75. package/src/canvas/CanvasStack.stories.tsx +1 -1
  76. package/src/canvas/usePanZoom.test.ts +28 -0
  77. package/src/canvas/usePanZoom.ts +11 -4
  78. package/src/chrome/ChromeRegions.stories.tsx +1 -1
  79. package/src/chrome/LabChrome.tsx +21 -5
  80. package/src/chrome/builtins.test.ts +1 -0
  81. package/src/chrome/builtins.tsx +1 -0
  82. package/src/chrome/index.ts +1 -0
  83. package/src/chrome/labTypes.ts +2 -2
  84. package/src/chrome/regions/PaletteRegion.tsx +1 -6
  85. package/src/chrome/regions/SidebarRegion.stories.tsx +44 -0
  86. package/src/chrome/regions/ToolbarRegion.tsx +11 -7
  87. package/src/chrome/types.ts +3 -0
  88. package/src/config/auto.test.ts +12 -0
  89. package/src/config/auto.ts +15 -0
  90. package/src/config/autoConfig.test.ts +107 -0
  91. package/src/config/autoConfig.ts +153 -0
  92. package/src/config/builder.test.ts +38 -0
  93. package/src/config/builder.ts +53 -8
  94. package/src/config/index.ts +3 -0
  95. package/src/config/path.ts +7 -2
  96. package/src/config/resolve.test.ts +25 -0
  97. package/src/config/resolve.ts +17 -1
  98. package/src/config/types.ts +32 -2
  99. package/src/config/useResolvedConfig.ts +26 -0
  100. package/src/controls/AutoControls.stories.tsx +88 -0
  101. package/src/controls/ControlPanel.stories.tsx +42 -1
  102. package/src/controls/ControlPanel.test.tsx +514 -4
  103. package/src/controls/ControlPanel.tsx +557 -80
  104. package/src/index.ts +29 -1
  105. package/src/instrument/serializers.ts +29 -1
  106. package/src/lab/Lab.chrome.test.tsx +16 -0
  107. package/src/lab/Lab.stories.tsx +1 -1
  108. package/src/lab/Lab.surface.test.tsx +7 -2
  109. package/src/lab/Lab.test.tsx +79 -1
  110. package/src/lab/Lab.tsx +105 -13
  111. package/src/lab/LabContext.ts +8 -0
  112. package/src/lab/LabFit.stories.tsx +4 -4
  113. package/src/lab/LabFullChrome.stories.tsx +1 -1
  114. package/src/lab/LabHeader.tsx +0 -1
  115. package/src/lab/LabRoot.test.tsx +56 -0
  116. package/src/lab/LabRoot.tsx +47 -0
  117. package/src/lab/LabShell.less +24 -3
  118. package/src/lab/LabShell.stories.tsx +50 -1
  119. package/src/lab/LabShell.tsx +18 -27
  120. package/src/lab/LabSwitcher.less +10 -10
  121. package/src/lab/LabSwitcher.test.tsx +14 -9
  122. package/src/lab/LabSwitcher.tsx +8 -4
  123. package/src/lab/Workspace.less +1 -1
  124. package/src/lab/Workspace.stories.tsx +1 -1
  125. package/src/lab/Workspace.surface.test.tsx +1 -1
  126. package/src/lab/index.ts +2 -0
  127. package/src/layers/LayerList.stories.tsx +1 -1
  128. package/src/loupe/AGENTS.md +16 -4
  129. package/src/loupe/LoupeGestures.tsx +67 -0
  130. package/src/loupe/TrialLoupe.tsx +43 -28
  131. package/src/loupe/index.ts +4 -0
  132. package/src/loupe/loupeActions.ts +98 -0
  133. package/src/loupe/useLoupe.test.tsx +59 -2
  134. package/src/loupe/useLoupe.ts +28 -48
  135. package/src/passthrough/weasel-ui.ts +3 -3
  136. package/src/primitives/FloatingPanel.stories.tsx +1 -1
  137. package/src/primitives/FpsMeter.stories.tsx +1 -1
  138. package/src/primitives/JobProgress.stories.tsx +1 -1
  139. package/src/primitives/Legend.stories.tsx +1 -1
  140. package/src/primitives/ScaleIndicator.stories.tsx +1 -1
  141. package/src/primitives/Sidebar.less +7 -0
  142. package/src/primitives/Sidebar.stories.tsx +1 -1
  143. package/src/primitives/Split.test.tsx +25 -0
  144. package/src/primitives/Split.tsx +36 -20
  145. package/src/primitives/StatusBar.stories.tsx +1 -1
  146. package/src/primitives/Toolbar.stories.tsx +1 -1
  147. package/src/specimen/Specimen.less +95 -0
  148. package/src/specimen/Specimen.stories.tsx +13 -0
  149. package/src/specimen/Specimen.test.tsx +13 -0
  150. package/src/specimen/Specimen.tsx +888 -0
  151. package/src/state/Persistence.stories.tsx +4 -4
  152. package/src/state/store.test.ts +65 -0
  153. package/src/state/store.ts +32 -8
  154. package/src/state/types.ts +26 -2
  155. package/src/state/useTrialState.test.tsx +85 -0
  156. package/src/state/useTrialState.ts +9 -1
  157. package/src/styles.less +1 -0
  158. package/src/surface/index.ts +1 -1
  159. package/src/surface/useSurfaceTile.test.tsx +1 -1
  160. package/src/surface/useTiledSurface.test.tsx +65 -10
  161. package/src/surface/useTiledSurface.ts +23 -11
  162. package/src/theme/Interstellar.stories.tsx +2 -2
  163. package/src/theme/interstellar.test.ts +16 -5
  164. package/src/theme/interstellar.theme.json +180 -0
  165. package/src/theme/interstellar.ts +8 -5
  166. package/src/tools/labTool.ts +3 -3
  167. package/src/trial/Trial.annotations.test.tsx +13 -4
  168. package/src/trial/Trial.canvas.test.tsx +32 -0
  169. package/src/trial/Trial.config.test.tsx +75 -2
  170. package/src/trial/Trial.less +4 -0
  171. package/src/trial/Trial.stories.tsx +4 -1
  172. package/src/trial/Trial.test.tsx +3 -0
  173. package/src/trial/Trial.tsx +21 -14
  174. package/src/trial/TrialChrome.tsx +17 -3
  175. package/src/trial/trialOps.test.ts +101 -1
  176. package/src/trial/trialOps.ts +62 -4
  177. package/dist/_dts/ToggleBar.d-DbHoWKIA.d.ts +0 -116
  178. package/dist/chunk-67SJLMC7.js.map +0 -1
  179. package/dist/chunk-6ZDGOZQV.js.map +0 -1
  180. package/dist/chunk-E44SU6XS.js +0 -50
  181. package/dist/chunk-E44SU6XS.js.map +0 -1
  182. package/dist/chunk-EKIICY6X.js.map +0 -1
  183. package/dist/chunk-NDRYLVOW.js.map +0 -1
  184. package/dist/chunk-NS64DXMN.js.map +0 -1
  185. package/dist/chunk-PGETSEDK.js.map +0 -1
  186. package/dist/chunk-QLSV2N3G.js.map +0 -1
  187. package/dist/chunk-S2SHZRD7.js +0 -7681
  188. package/dist/chunk-S2SHZRD7.js.map +0 -1
  189. package/dist/chunk-TQBBYTAF.js +0 -280
  190. package/dist/chunk-TQBBYTAF.js.map +0 -1
  191. package/dist/chunk-ZPH5WTWF.js.map +0 -1
  192. package/src/theme/interstellar.tokens.json +0 -61
@@ -0,0 +1,590 @@
1
+ import { fromConfigFields, isLeafVisible } from './chunk-PHK4W562.js';
2
+ import { resolveAutoConfig, schemaNodeAtPath, valueAtPath, auto } from './chunk-7PFH3CNM.js';
3
+ import { k, J, n3, j2, L3, U, H, z2, R2, F2, V, g, a4, e2, B } from './chunk-T3EC2DXD.js';
4
+ import { isBuiltinToolPref } from '@weasel-js/core';
5
+ import { useMemo, useState, useRef, useEffect, Fragment as Fragment$1 } from 'react';
6
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
+
8
+ var gridOf = (pack) => pack === "one-up" ? "auto-color" : "pairs";
9
+ function sectionRows(section, rows) {
10
+ return {
11
+ pack: section.pack ?? rows.pack,
12
+ layout: section.layout ?? rows.layout,
13
+ grid: section.pack ? gridOf(section.pack) : rows.grid
14
+ };
15
+ }
16
+ var NO_AUTO = /* @__PURE__ */ new Set();
17
+ function ControlPanel({
18
+ schema,
19
+ fields,
20
+ config,
21
+ setConfig,
22
+ renderers,
23
+ pack = "pairs",
24
+ layout,
25
+ density,
26
+ align,
27
+ collapse,
28
+ collapsed,
29
+ onCollapse,
30
+ auto: given,
31
+ showHidden = false,
32
+ className
33
+ }) {
34
+ const resolved = useMemo(() => schema ?? fromConfigFields(fields ?? []), [schema, fields]);
35
+ const [ownAuto, setOwnAuto] = useState(NO_AUTO);
36
+ const auto2 = given ?? ownAuto;
37
+ const setRowAuto = (path, next, value) => {
38
+ if (given) {
39
+ setConfig(path, next ? auto : value);
40
+ return;
41
+ }
42
+ setOwnAuto((prev) => {
43
+ const now = new Set(prev);
44
+ if (next) now.add(path);
45
+ else now.delete(path);
46
+ return now;
47
+ });
48
+ if (!next) setConfig(path, value);
49
+ };
50
+ const shown = useMemo(
51
+ () => auto2 && auto2.size > 0 ? resolveAutoConfig(resolved, config, auto2) : config,
52
+ [resolved, config, auto2]
53
+ );
54
+ const listRef = useRef(null);
55
+ const toggles = useRef(/* @__PURE__ */ new Map());
56
+ useEffect(() => {
57
+ const host = listRef.current;
58
+ if (!host) return;
59
+ const onDown = (e2) => {
60
+ if (!e2.shiftKey) return;
61
+ const row = e2.target?.closest("[data-auto-path]");
62
+ const path = row?.getAttribute("data-auto-path");
63
+ const toggle = path ? toggles.current.get(path) : void 0;
64
+ if (!toggle) return;
65
+ e2.preventDefault();
66
+ e2.stopPropagation();
67
+ toggle();
68
+ };
69
+ host.addEventListener("pointerdown", onDown, true);
70
+ return () => host.removeEventListener("pointerdown", onDown, true);
71
+ }, []);
72
+ const gridPack = gridOf(pack);
73
+ const folds = collapse !== void 0 || collapsed !== void 0 || onCollapse !== void 0 || resolved.sections.some((s) => s.collapsed !== void 0);
74
+ const startsFolded = collapse === "closed";
75
+ const fold = (key, declared, grid = gridPack) => ({
76
+ pack: grid,
77
+ collapsible: folds,
78
+ defaultCollapsed: declared ?? startsFolded,
79
+ collapsed: collapsed ? collapsed[key] ?? declared ?? startsFolded : void 0,
80
+ onCollapsedChange: onCollapse ? (next) => onCollapse(key, next) : void 0
81
+ });
82
+ const node = (path, rows) => {
83
+ const found = schemaNodeAtPath(resolved.group, path);
84
+ if (!found) return null;
85
+ if (!isLeafVisible(resolved, path, config, showHidden)) return null;
86
+ if (n3(found)) {
87
+ return /* @__PURE__ */ jsx(
88
+ ControlRow,
89
+ {
90
+ path,
91
+ leaf: found,
92
+ resolved,
93
+ config,
94
+ shown,
95
+ setConfig,
96
+ renderers,
97
+ pack: rows.pack,
98
+ layout: rows.layout,
99
+ auto: auto2,
100
+ setRowAuto,
101
+ toggles: toggles.current
102
+ },
103
+ path
104
+ );
105
+ }
106
+ if (found.name === "") return /* @__PURE__ */ jsx(Fragment$1, { children: body(found, path, rows) }, path);
107
+ return /* @__PURE__ */ jsx(J, { title: found.name, ...fold(path, void 0, rows.grid), children: body(found, path, rows) }, path);
108
+ };
109
+ const pairable = (path) => {
110
+ const found = schemaNodeAtPath(resolved.group, path);
111
+ if (!found || !n3(found)) return void 0;
112
+ const pair = extra(found, "pair");
113
+ if (pair === void 0) return void 0;
114
+ if (!isLeafVisible(resolved, path, config, showHidden))
115
+ return void 0;
116
+ if (renderers?.[path] ?? resolved.renderers[path] ?? renderers?.[found.kind]) return void 0;
117
+ if (!isBuiltinToolPref(found)) return void 0;
118
+ if (found.kind === "paint" || found.kind === "object" || isSliderLeaf(found)) return void 0;
119
+ return { leaf: found, pair };
120
+ };
121
+ const rowsFor = (paths, rows) => {
122
+ const out = [];
123
+ for (let i = 0; i < paths.length; ) {
124
+ const head = pairable(paths[i]);
125
+ if (!head) {
126
+ out.push(node(paths[i], rows));
127
+ i += 1;
128
+ continue;
129
+ }
130
+ const { pair } = head;
131
+ const cells = [{ path: paths[i], leaf: head.leaf }];
132
+ let j2 = i + 1;
133
+ for (; j2 < paths.length; j2 += 1) {
134
+ const next = pairable(paths[j2]);
135
+ if (!next || next.pair !== pair) break;
136
+ cells.push({ path: paths[j2], leaf: next.leaf });
137
+ }
138
+ out.push(
139
+ /* @__PURE__ */ jsx(
140
+ PairedRow,
141
+ {
142
+ label: pair,
143
+ cells,
144
+ shown,
145
+ setConfig,
146
+ layout: rows.layout
147
+ },
148
+ paths[i]
149
+ )
150
+ );
151
+ i = j2;
152
+ }
153
+ return out;
154
+ };
155
+ const body = (group, at, rows) => {
156
+ const sections = resolved.sections.filter((s) => s.at === at);
157
+ const sectioned = new Set(sections.flatMap((s) => s.paths));
158
+ const paths = Object.keys(group.children).map((key) => at === "" ? key : `${at}.${key}`);
159
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
160
+ rowsFor(
161
+ paths.filter((p) => !sectioned.has(p)),
162
+ rows
163
+ ),
164
+ sections.map((section) => {
165
+ const inner = sectionRows(section, rows);
166
+ return /* @__PURE__ */ jsx(
167
+ J,
168
+ {
169
+ title: section.label,
170
+ ...fold(sectionKey(section), section.collapsed, inner.grid),
171
+ children: rowsFor(section.paths, inner)
172
+ },
173
+ sectionKey(section)
174
+ );
175
+ })
176
+ ] });
177
+ };
178
+ return /* @__PURE__ */ jsx("div", { ref: listRef, children: /* @__PURE__ */ jsx(
179
+ k,
180
+ {
181
+ pack: gridPack,
182
+ density,
183
+ align,
184
+ className: className ? `lk-control-panel ${className}` : "lk-control-panel",
185
+ children: body(resolved.group, "", { pack, layout, grid: gridPack })
186
+ }
187
+ ) });
188
+ }
189
+ function sectionKey(section) {
190
+ return section.at === "" ? section.label : `${section.at}.${section.label}`;
191
+ }
192
+ function isSliderLeaf(leaf) {
193
+ return leaf.kind === "number" && extra(leaf, "control") === "slider" && extra(leaf, "min") !== void 0 && extra(leaf, "max") !== void 0;
194
+ }
195
+ function extra(leaf, key) {
196
+ return leaf[key];
197
+ }
198
+ function ControlRow({
199
+ path,
200
+ leaf,
201
+ resolved,
202
+ config,
203
+ shown,
204
+ setConfig,
205
+ renderers,
206
+ pack,
207
+ layout,
208
+ auto: auto2,
209
+ setRowAuto,
210
+ toggles
211
+ }) {
212
+ const write = (value2) => setConfig(path, value2);
213
+ const fallback = extra(leaf, "default");
214
+ const pinned = valueAtPath(config, path) ?? fallback;
215
+ const isAutoRow = auto2?.has(path) ?? false;
216
+ const canAuto = !extra(leaf, "manual");
217
+ const resolvedValue = isAutoRow ? valueAtPath(shown, path) : void 0;
218
+ const value = resolvedValue ?? pinned;
219
+ const setAuto = (next) => setRowAuto(path, next, value);
220
+ const onAutoChange = canAuto ? setAuto : void 0;
221
+ const readsItsOwnValue = !isSliderLeaf(leaf);
222
+ const readoutValue = leaf.kind === "number" && typeof resolvedValue === "number" ? numberField(leaf, resolvedValue).shown : resolvedValue;
223
+ const autoReadout = !isAutoRow ? void 0 : resolvedValue === void 0 || readsItsOwnValue ? "auto" : `auto \xB7 ${String(readoutValue)}`;
224
+ const autoProps = { auto: isAutoRow, onAutoChange, "data-auto-path": canAuto ? path : void 0 };
225
+ useEffect(() => {
226
+ if (!canAuto) return;
227
+ toggles.set(path, () => setAuto(!isAutoRow));
228
+ return () => {
229
+ toggles.delete(path);
230
+ };
231
+ });
232
+ const custom = renderers?.[path] ?? resolved.renderers[path] ?? renderers?.[leaf.kind];
233
+ if (custom) return custom({ path, pref: leaf, value, setValue: write, auto: isAutoRow, setAuto });
234
+ const label = leaf.name;
235
+ const description = leaf.description;
236
+ const read = () => value;
237
+ const wide = pack === "auto";
238
+ if (!isBuiltinToolPref(leaf))
239
+ return /* @__PURE__ */ jsx(UnwiredRow, { label, kind: leaf.kind, description });
240
+ switch (leaf.kind) {
241
+ case "number": {
242
+ const field = numberField(leaf, read());
243
+ const suffix = extra(leaf, "suffix") ?? field.unit?.suffix;
244
+ const notation = extra(leaf, "format");
245
+ if (isSliderLeaf(leaf)) {
246
+ return /* @__PURE__ */ jsx(
247
+ F2,
248
+ {
249
+ label,
250
+ value: field.shown,
251
+ min: field.min,
252
+ max: field.max,
253
+ step: field.step,
254
+ notation,
255
+ unit: suffix,
256
+ onChange: (n2) => write(field.store(n2)),
257
+ readout: autoReadout,
258
+ layout,
259
+ span: wide,
260
+ description,
261
+ ...autoProps
262
+ }
263
+ );
264
+ }
265
+ return /* @__PURE__ */ jsx(
266
+ V,
267
+ {
268
+ label,
269
+ value: field.shown,
270
+ min: field.min,
271
+ max: field.max,
272
+ step: field.step,
273
+ unit: suffix,
274
+ onChange: (n2) => write(field.store(n2)),
275
+ readout: autoReadout,
276
+ layout,
277
+ description,
278
+ ...autoProps
279
+ }
280
+ );
281
+ }
282
+ case "boolean": {
283
+ const Row = extra(leaf, "control") === "switch" ? z2 : R2;
284
+ return /* @__PURE__ */ jsx(
285
+ Row,
286
+ {
287
+ label,
288
+ value: read(),
289
+ onChange: write,
290
+ readout: autoReadout,
291
+ layout,
292
+ description,
293
+ ...autoProps
294
+ }
295
+ );
296
+ }
297
+ case "enum": {
298
+ const options = extra(leaf, "options") ?? [];
299
+ const segmented = extra(leaf, "control") === "radio";
300
+ const Row = segmented ? U : H;
301
+ return /* @__PURE__ */ jsx(
302
+ Row,
303
+ {
304
+ label,
305
+ value: read(),
306
+ options,
307
+ onChange: write,
308
+ readout: autoReadout,
309
+ layout,
310
+ span: segmented && wide,
311
+ description,
312
+ ...autoProps
313
+ }
314
+ );
315
+ }
316
+ case "string":
317
+ return /* @__PURE__ */ jsx(
318
+ DebouncedTextRow,
319
+ {
320
+ leaf,
321
+ label,
322
+ value: read(),
323
+ write,
324
+ readout: autoReadout,
325
+ layout,
326
+ span: wide,
327
+ description,
328
+ ...autoProps
329
+ }
330
+ );
331
+ case "color": {
332
+ const common = {
333
+ label,
334
+ readout: autoReadout,
335
+ layout,
336
+ description,
337
+ ...autoProps
338
+ };
339
+ if (extra(leaf, "alpha") !== true)
340
+ return /* @__PURE__ */ jsx(L3, { ...common, value: read(), onChange: write });
341
+ const { rgb, alpha } = splitHexAlpha(read());
342
+ return /* @__PURE__ */ jsx(
343
+ L3,
344
+ {
345
+ ...common,
346
+ value: rgb,
347
+ onChange: (next) => write(joinHexAlpha(next, alpha)),
348
+ alpha,
349
+ onAlphaChange: (next) => write(joinHexAlpha(rgb, next))
350
+ }
351
+ );
352
+ }
353
+ case "paint":
354
+ case "object":
355
+ return /* @__PURE__ */ jsx(UnwiredRow, { label, kind: leaf.kind, description });
356
+ default: {
357
+ const _exhaustive = leaf;
358
+ throw new Error(
359
+ `ControlPanel: no control for built-in pref kind "${_exhaustive.kind}"`
360
+ );
361
+ }
362
+ }
363
+ }
364
+ function UnwiredRow({
365
+ label,
366
+ kind,
367
+ description
368
+ }) {
369
+ return /* @__PURE__ */ jsx(j2, { label, description, children: /* @__PURE__ */ jsxs("span", { className: "lk-control-panel__unknown", children: [
370
+ "no control for \u201C",
371
+ kind,
372
+ "\u201D"
373
+ ] }) });
374
+ }
375
+ function DebouncedTextRow({
376
+ leaf,
377
+ label,
378
+ value,
379
+ write,
380
+ layout,
381
+ span,
382
+ description,
383
+ readout,
384
+ auto: auto2,
385
+ onAutoChange,
386
+ "data-auto-path": autoPath
387
+ }) {
388
+ const text = useDebouncedText(
389
+ value,
390
+ write,
391
+ extra(leaf, "debounceMs") ?? 150
392
+ );
393
+ return /* @__PURE__ */ jsx(
394
+ B,
395
+ {
396
+ label,
397
+ readout,
398
+ layout,
399
+ span,
400
+ description,
401
+ auto: auto2,
402
+ onAutoChange,
403
+ "data-auto-path": autoPath,
404
+ value: text.local,
405
+ placeholder: extra(leaf, "placeholder"),
406
+ maxLength: extra(leaf, "maxLength"),
407
+ onChange: text.type
408
+ }
409
+ );
410
+ }
411
+ function numberField(leaf, value) {
412
+ const unit = extra(leaf, "unit");
413
+ const bounds = unit ? e2(leaf) : {
414
+ min: extra(leaf, "min"),
415
+ max: extra(leaf, "max"),
416
+ step: extra(leaf, "step")
417
+ };
418
+ const lo = bounds.min ?? Number.NEGATIVE_INFINITY;
419
+ const hi = bounds.max ?? Number.POSITIVE_INFINITY;
420
+ return {
421
+ unit,
422
+ min: bounds.min,
423
+ max: bounds.max,
424
+ step: bounds.step,
425
+ shown: unit ? unit.toDisplay(value) : value,
426
+ store: (shown) => {
427
+ const clamped = Math.min(hi, Math.max(lo, shown));
428
+ return unit ? unit.fromDisplay(clamped) : clamped;
429
+ }
430
+ };
431
+ }
432
+ function splitHexAlpha(value) {
433
+ const digits = /^#([0-9a-f]{3,8})$/i.exec(value?.trim() ?? "")?.[1];
434
+ const twice = (s) => s.split("").map((c) => c + c).join("");
435
+ const byte = (s) => Number.parseInt(s, 16) / 255;
436
+ switch (digits?.length) {
437
+ case 3:
438
+ return { rgb: `#${twice(digits)}`, alpha: 1 };
439
+ case 4:
440
+ return { rgb: `#${twice(digits.slice(0, 3))}`, alpha: byte(twice(digits.slice(3))) };
441
+ case 6:
442
+ return { rgb: `#${digits}`, alpha: 1 };
443
+ case 8:
444
+ return { rgb: `#${digits.slice(0, 6)}`, alpha: byte(digits.slice(6)) };
445
+ default:
446
+ return { rgb: "#000000", alpha: 1 };
447
+ }
448
+ }
449
+ function joinHexAlpha(rgb, alpha) {
450
+ const byte = Math.max(0, Math.min(255, Math.round(alpha * 255)));
451
+ return `${rgb}${byte.toString(16).padStart(2, "0")}`;
452
+ }
453
+ function PairedRow({
454
+ label,
455
+ cells,
456
+ shown,
457
+ setConfig,
458
+ layout
459
+ }) {
460
+ return /* @__PURE__ */ jsx(j2, { group: true, label, layout, children: cells.map(({ path, leaf }) => /* @__PURE__ */ jsx(
461
+ PairCell,
462
+ {
463
+ leaf,
464
+ value: valueAtPath(shown, path) ?? extra(leaf, "default"),
465
+ write: (value) => setConfig(path, value)
466
+ },
467
+ path
468
+ )) });
469
+ }
470
+ function PairCell({
471
+ leaf,
472
+ value,
473
+ write
474
+ }) {
475
+ const name = leaf.name;
476
+ const title = leaf.description;
477
+ const text = useDebouncedText(
478
+ typeof value === "string" ? value : "",
479
+ write,
480
+ extra(leaf, "debounceMs") ?? 150
481
+ );
482
+ switch (leaf.kind) {
483
+ case "number": {
484
+ const field = numberField(leaf, typeof value === "number" ? value : 0);
485
+ return /* @__PURE__ */ jsx(
486
+ "input",
487
+ {
488
+ type: "number",
489
+ "aria-label": name,
490
+ title,
491
+ value: field.shown,
492
+ min: field.min,
493
+ max: field.max,
494
+ step: field.step,
495
+ onChange: (e2) => {
496
+ const n2 = Number(e2.target.value);
497
+ if (e2.target.value !== "" && Number.isFinite(n2)) write(field.store(n2));
498
+ }
499
+ }
500
+ );
501
+ }
502
+ case "boolean":
503
+ return extra(leaf, "control") === "switch" ? /* @__PURE__ */ jsx(a4, { "aria-label": name, isSelected: value === true, onChange: write }) : /* @__PURE__ */ jsx(
504
+ "input",
505
+ {
506
+ type: "checkbox",
507
+ "aria-label": name,
508
+ title,
509
+ checked: value === true,
510
+ onChange: (e2) => write(e2.target.checked)
511
+ }
512
+ );
513
+ case "string":
514
+ return /* @__PURE__ */ jsx(
515
+ "input",
516
+ {
517
+ type: "text",
518
+ "aria-label": name,
519
+ title,
520
+ value: text.local,
521
+ placeholder: extra(leaf, "placeholder"),
522
+ maxLength: extra(leaf, "maxLength"),
523
+ onChange: (e2) => text.type(e2.target.value)
524
+ }
525
+ );
526
+ case "color": {
527
+ const { rgb, alpha } = splitHexAlpha(typeof value === "string" ? value : "");
528
+ const carriesAlpha = extra(leaf, "alpha") === true;
529
+ return /* @__PURE__ */ jsx(
530
+ "input",
531
+ {
532
+ type: "color",
533
+ "aria-label": name,
534
+ title,
535
+ value: rgb,
536
+ onChange: (e2) => write(carriesAlpha ? joinHexAlpha(e2.target.value, alpha) : e2.target.value)
537
+ }
538
+ );
539
+ }
540
+ case "enum": {
541
+ const options = extra(leaf, "options") ?? [];
542
+ return /* @__PURE__ */ jsx("span", { title, children: /* @__PURE__ */ jsx(
543
+ g,
544
+ {
545
+ variant: "bare",
546
+ "aria-label": name,
547
+ options,
548
+ selectedKey: typeof value === "string" ? value : null,
549
+ onSelectionChange: write
550
+ }
551
+ ) });
552
+ }
553
+ default:
554
+ return null;
555
+ }
556
+ }
557
+ function useDebouncedText(value, write, debounceMs) {
558
+ const [local, setLocal] = useState(value);
559
+ const timer = useRef(null);
560
+ const lastExternal = useRef(value);
561
+ useEffect(() => {
562
+ if (value !== lastExternal.current) {
563
+ lastExternal.current = value;
564
+ setLocal(value);
565
+ }
566
+ }, [value]);
567
+ useEffect(
568
+ () => () => {
569
+ if (timer.current) clearTimeout(timer.current);
570
+ },
571
+ []
572
+ );
573
+ return {
574
+ local,
575
+ type: (next) => {
576
+ setLocal(next);
577
+ if (timer.current) clearTimeout(timer.current);
578
+ const commit = () => {
579
+ lastExternal.current = next;
580
+ write(next);
581
+ };
582
+ if (debounceMs === 0) commit();
583
+ else timer.current = setTimeout(commit, debounceMs);
584
+ }
585
+ };
586
+ }
587
+
588
+ export { ControlPanel };
589
+ //# sourceMappingURL=chunk-EH7UEQV7.js.map
590
+ //# sourceMappingURL=chunk-EH7UEQV7.js.map