@luxalgo/vela-ui 0.3.0 → 0.4.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 (167) hide show
  1. package/CHANGELOG.md +153 -132
  2. package/LICENSE +201 -201
  3. package/NOTICE +28 -28
  4. package/README.md +86 -86
  5. package/cli/engine.mjs +282 -282
  6. package/cli/index.mjs +154 -154
  7. package/dist/callout-bubble.js +2 -2
  8. package/dist/checkbox.js +2 -2
  9. package/dist/{chunk-KKS6NEGI.js → chunk-BWSOMG3G.js} +1 -1
  10. package/dist/chunk-GUIYFQ27.js +30 -0
  11. package/dist/{chunk-B2EZB5ZG.js → chunk-KUWTI2PE.js} +2 -2
  12. package/dist/{chunk-WWHNUKSZ.js → chunk-QGWAN3EP.js} +2 -2
  13. package/dist/{chunk-TBXUF5YX.js → chunk-RH53NQGE.js} +18 -4
  14. package/dist/{chunk-IOOYDSSK.js → chunk-SKFAYTDK.js} +1 -1
  15. package/dist/{chunk-OQXFQMZM.js → chunk-TGJNHUYV.js} +2 -2
  16. package/dist/{chunk-UEO6W37Z.js → chunk-VC7SVSDK.js} +1 -1
  17. package/dist/{chunk-OJ2SEMN6.js → chunk-YT2BSP7O.js} +1 -1
  18. package/dist/collapsible.js +1 -1
  19. package/dist/color-picker.js +4 -4
  20. package/dist/context-menu.js +3 -3
  21. package/dist/dialog.js +3 -3
  22. package/dist/donut.d.ts +1 -1
  23. package/dist/drawer.js +1 -1
  24. package/dist/dropdown-menu.js +3 -3
  25. package/dist/field.js +8 -8
  26. package/dist/{stat.d.ts → figure.d.ts} +9 -9
  27. package/dist/figure.js +41 -0
  28. package/dist/glyph-select.js +3 -3
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.js +1 -1
  31. package/dist/manifest.json +74 -74
  32. package/dist/number-input.js +2 -2
  33. package/dist/popover.js +2 -2
  34. package/dist/select.d.ts +1 -1
  35. package/dist/select.js +4 -4
  36. package/dist/slider.js +1 -1
  37. package/dist/sort-button.js +1 -1
  38. package/dist/switch.js +1 -1
  39. package/dist/tabs.js +1 -1
  40. package/dist/{theme-Ct-q58xz.d.ts → theme-TefB8vtl.d.ts} +2 -2
  41. package/dist/theme.d.ts +2 -2
  42. package/dist/theme.js +1 -1
  43. package/dist/theme.schema.json +30 -30
  44. package/dist/toast.d.ts +2 -2
  45. package/dist/toast.js +1 -1
  46. package/dist/toggle-group.js +1 -1
  47. package/dist/tooltip.js +1 -1
  48. package/dist/zag.d.ts +11 -2
  49. package/dist/zag.js +1 -1
  50. package/docs/theming.md +217 -217
  51. package/docs/what-to-change.md +20 -20
  52. package/docs/writing-a-component.md +250 -250
  53. package/llms.txt +3 -3
  54. package/package.json +90 -90
  55. package/registry/badge.ts +119 -119
  56. package/registry/bar-chart.ts +215 -215
  57. package/registry/button.ts +387 -387
  58. package/registry/callout-bubble.ts +347 -347
  59. package/registry/card.ts +379 -379
  60. package/registry/checkbox.ts +234 -234
  61. package/registry/collapsible.ts +271 -271
  62. package/registry/color-picker.ts +582 -582
  63. package/registry/context-menu.ts +208 -208
  64. package/registry/data-table.ts +215 -215
  65. package/registry/date-picker.ts +483 -483
  66. package/registry/dialog.ts +551 -551
  67. package/registry/donut.ts +145 -145
  68. package/registry/drawer.ts +636 -636
  69. package/registry/dropdown-menu.ts +762 -762
  70. package/registry/empty.ts +91 -91
  71. package/registry/field.ts +584 -584
  72. package/registry/{stat.ts → figure.ts} +96 -96
  73. package/registry/glyph-select.ts +268 -268
  74. package/registry/hover-card.ts +222 -222
  75. package/registry/input-group.ts +229 -229
  76. package/registry/input.ts +181 -181
  77. package/registry/item.ts +376 -376
  78. package/registry/kbd.ts +64 -64
  79. package/registry/line-chart.ts +218 -218
  80. package/registry/month-grid.ts +328 -328
  81. package/registry/number-input.ts +443 -443
  82. package/registry/popover.ts +368 -368
  83. package/registry/scatter-chart.ts +221 -221
  84. package/registry/select.ts +620 -620
  85. package/registry/slider.ts +259 -259
  86. package/registry/sort-button.ts +189 -189
  87. package/registry/sparkline.ts +114 -114
  88. package/registry/switch.ts +205 -205
  89. package/registry/tabs.ts +426 -426
  90. package/registry/text-area.ts +186 -186
  91. package/registry/toast.ts +965 -965
  92. package/registry/toggle-group.ts +295 -295
  93. package/registry/tooltip.ts +156 -156
  94. package/registry/treemap.ts +847 -847
  95. package/skills/theming-vela-ui/SKILL.md +137 -137
  96. package/skills/using-vela-ui-components/SKILL.md +139 -139
  97. package/skills/writing-vela-ui-components/SKILL.md +163 -163
  98. package/src/components/badge.ts +119 -119
  99. package/src/components/bar-chart.ts +215 -215
  100. package/src/components/button.ts +387 -387
  101. package/src/components/callout-bubble.ts +347 -347
  102. package/src/components/card.ts +379 -379
  103. package/src/components/checkbox.ts +234 -234
  104. package/src/components/collapsible.ts +271 -271
  105. package/src/components/color-picker.ts +582 -582
  106. package/src/components/context-menu.ts +208 -208
  107. package/src/components/data-table.ts +215 -215
  108. package/src/components/date-picker.ts +483 -483
  109. package/src/components/dialog.ts +551 -551
  110. package/src/components/donut.ts +145 -145
  111. package/src/components/drawer.ts +636 -636
  112. package/src/components/dropdown-menu.ts +762 -762
  113. package/src/components/empty.ts +91 -91
  114. package/src/components/field.ts +584 -584
  115. package/src/components/{stat.ts → figure.ts} +96 -96
  116. package/src/components/glyph-select.ts +268 -268
  117. package/src/components/hover-card.ts +222 -222
  118. package/src/components/input-group.ts +229 -229
  119. package/src/components/input.ts +181 -181
  120. package/src/components/item.ts +376 -376
  121. package/src/components/kbd.ts +64 -64
  122. package/src/components/line-chart.ts +218 -218
  123. package/src/components/month-grid.ts +328 -328
  124. package/src/components/number-input.ts +443 -443
  125. package/src/components/popover.ts +368 -368
  126. package/src/components/scatter-chart.ts +221 -221
  127. package/src/components/select.ts +620 -620
  128. package/src/components/slider.ts +259 -259
  129. package/src/components/sort-button.ts +189 -189
  130. package/src/components/sparkline.ts +114 -114
  131. package/src/components/switch.ts +205 -205
  132. package/src/components/tabs.ts +426 -426
  133. package/src/components/text-area.ts +186 -186
  134. package/src/components/toast.ts +965 -965
  135. package/src/components/toggle-group.ts +295 -295
  136. package/src/components/tooltip.ts +156 -156
  137. package/src/components/treemap.ts +847 -847
  138. package/src/index.ts +24 -24
  139. package/src/lib/calendar.ts +117 -117
  140. package/src/lib/chart.ts +72 -72
  141. package/src/lib/color.ts +89 -89
  142. package/src/lib/component-index.ts +163 -163
  143. package/src/lib/css.ts +48 -48
  144. package/src/lib/define.ts +45 -45
  145. package/src/lib/dispose.ts +36 -36
  146. package/src/lib/h.ts +55 -55
  147. package/src/lib/headless.ts +16 -16
  148. package/src/lib/i18n.ts +30 -30
  149. package/src/lib/icons.ts +244 -244
  150. package/src/lib/kit-text.ts +26 -26
  151. package/src/lib/page.ts +24 -24
  152. package/src/lib/palette.ts +81 -81
  153. package/src/lib/placement.ts +188 -188
  154. package/src/lib/scope.ts +135 -135
  155. package/src/lib/styles.ts +53 -53
  156. package/src/lib/surface-events.ts +31 -31
  157. package/src/lib/surface-exit.ts +87 -87
  158. package/src/lib/t.ts +68 -68
  159. package/src/lib/theme.ts +684 -670
  160. package/src/lib/tokens.ts +110 -110
  161. package/src/lib/variants.ts +32 -32
  162. package/src/lib/zag.ts +61 -46
  163. package/stylelint/index.mjs +60 -60
  164. package/stylelint/lint.mjs +81 -81
  165. package/stylelint/plugin.mjs +115 -115
  166. package/dist/chunk-P4MTEMT7.js +0 -23
  167. package/dist/stat.js +0 -41
package/registry/field.ts CHANGED
@@ -1,585 +1,585 @@
1
- // Field: the label-and-control grid the settings dialogs lay their inputs out on: rows (a
2
- // label and its control, an optional master toggle that dims the control, an optional info
3
- // mark), full-width toggles, stacked and inline rows, section headings and separators, and
4
- // a factory that builds a row's control from a descriptor. Rows use `display: contents`, so
5
- // their label and control sit on the grid's own tracks.
6
- import type { ChartTheme } from '@luxalgo/vela-ui/tokens';
7
- import { injectStyles as injectSheet } from '@luxalgo/vela-ui/styles';
8
- import { css, defineStyles } from '@luxalgo/vela-ui';
9
- import { defineComponent } from '@luxalgo/vela-ui';
10
- import { disposeWithin } from '@luxalgo/vela-ui/dispose';
11
- import { t } from '@luxalgo/vela-ui';
12
- import { ColorField, type ColorFieldOpts } from '@luxalgo/vela-ui/color-picker';
13
- import { widthField } from '@luxalgo/vela-ui/glyph-select';
14
- import { NumberInput } from '@luxalgo/vela-ui/number-input';
15
- import { Select, type SelectListPopoverOpts, type SelectOption } from '@luxalgo/vela-ui/select';
16
- import { Checkbox } from '@luxalgo/vela-ui/checkbox';
17
- import { TextArea } from '@luxalgo/vela-ui/text-area';
18
- import { Input } from '@luxalgo/vela-ui/input';
19
-
20
- export type FieldGridVariant = 'settings' | 'inputs';
21
- export type FieldLabelSize = 'sm' | 'md';
22
-
23
- /** Label↔control and between-row rhythm shared by the settings surfaces. */
24
- export const FIELD_GAP_PX = 16;
25
-
26
- /** Grid tracks for a field grid. Settings hugs both columns; inputs give leftover
27
- * space to the control column. Mobile flips the label to a flexible track. */
28
- export function fieldGridColumns(variant: FieldGridVariant, mobile: boolean): string {
29
- if (variant === 'inputs') return mobile ? 'minmax(0,1fr) auto' : 'max-content 1fr';
30
- return mobile ? 'minmax(0,1fr) max-content' : 'max-content max-content';
31
- }
32
-
33
- export const fieldDef = defineComponent({
34
- name: 'field',
35
- parts: ['grid', 'row', 'span', 'label', 'cell', 'bool', 'stacked', 'stacked-head', 'inline', 'inline-item', 'toggle-label', 'section', 'sep'],
36
- });
37
-
38
- type FieldPart = (typeof fieldDef.parts)[number];
39
-
40
- const GAP = `${FIELD_GAP_PX}px`;
41
-
42
- const injectFieldStyles = defineStyles(
43
- 'vela-ui-field',
44
- css`
45
- @layer vela.ui {
46
- [data-slot~='field-grid'] {
47
- align-items: center;
48
- align-content: start;
49
- column-gap: ${GAP};
50
- row-gap: ${GAP};
51
-
52
- &:where(:not([hidden])) {
53
- display: grid;
54
- }
55
- &[data-variant='inputs'] {
56
- grid-template-columns: max-content 1fr;
57
- }
58
- &[data-variant='inputs'][data-mobile] {
59
- grid-template-columns: minmax(0, 1fr) auto;
60
- }
61
- &[data-variant='settings'] {
62
- grid-template-columns: max-content max-content;
63
- column-gap: 12px;
64
- }
65
- &[data-variant='settings'][data-mobile] {
66
- grid-template-columns: minmax(0, 1fr) max-content;
67
- }
68
- }
69
- [data-slot~='field-row']:where(:not([hidden])) {
70
- display: contents;
71
- }
72
- [data-slot~='field-span'] {
73
- grid-column: 1 / -1;
74
- }
75
- [data-slot~='field-label'] {
76
- opacity: 0.9;
77
- white-space: nowrap;
78
- overflow: hidden;
79
- text-overflow: ellipsis;
80
- font-size: 14px;
81
-
82
- &[data-size='sm'] {
83
- font-size: inherit;
84
- opacity: 0.85;
85
- }
86
- }
87
- /* Titles are fully inert: spans, not label[for] — native labels propagate :hover
88
- and clicks onto their control, and both belong to the input alone. */
89
- [data-slot~='field-cell'] {
90
- display: flex;
91
- align-items: center;
92
- gap: 8px;
93
- justify-self: start;
94
- }
95
- [data-slot~='field-bool']:where(:not([hidden])) {
96
- display: flex;
97
- align-items: center;
98
- gap: 8px;
99
- min-height: 22px;
100
- }
101
- [data-slot~='field-stacked']:where(:not([hidden])) {
102
- display: flex;
103
- flex-direction: column;
104
- gap: 8px;
105
- }
106
- [data-slot~='field-stacked-head'] {
107
- display: flex;
108
- align-items: center;
109
- justify-content: center;
110
- gap: 8px;
111
- }
112
- [data-slot~='field-inline']:where(:not([hidden])) {
113
- display: flex;
114
- flex-wrap: wrap;
115
- align-items: center;
116
- gap: 12px;
117
- }
118
- [data-slot~='field-inline-item'] {
119
- display: flex;
120
- align-items: center;
121
- gap: 8px;
122
- }
123
- [data-slot~='field-toggle-label'] {
124
- display: flex;
125
- align-items: center;
126
- gap: 8px;
127
- }
128
- [data-slot~='field-section'] {
129
- grid-column: 1 / -1;
130
- margin: 24px 0 0;
131
- padding-bottom: 8px;
132
- font-size: ${t.fontSize.sm};
133
- font-weight: 700;
134
- letter-spacing: 0.05em;
135
- text-transform: uppercase;
136
- color: ${t.fg.muted};
137
-
138
- &[data-variant='inputs'] {
139
- margin: 0;
140
- padding: 20px 0 8px;
141
- font-size: 11px;
142
- font-weight: 600;
143
- }
144
- &[data-variant='inputs'][data-first] {
145
- padding-top: 4px;
146
- }
147
- }
148
- [data-slot~='field-sep'] {
149
- grid-column: 1 / -1;
150
- height: 14px;
151
- }
152
- }
153
- `,
154
- );
155
-
156
- /* A row's master toggle dims its controls. The dimmed state must beat every other style on
157
- the control, the host's included, so it stays outside the layers and important. */
158
- const DIM_CSS = '.vela-field-dim { opacity: 0.4 !important; pointer-events: none !important; }';
159
-
160
- function injectStyles(doc: Document): void {
161
- injectFieldStyles(doc);
162
- injectSheet('vela-ui-field-dim', DIM_CSS, doc);
163
- }
164
-
165
- /** Give an element its field parts: the `vela-field-*` classes and the `data-slot` tokens. */
166
- function cls(el: HTMLElement, ...parts: FieldPart[]): void {
167
- el.className = parts.map((p) => `vela-field-${p}`).join(' ');
168
- el.setAttribute('data-slot', parts.map((p) => fieldDef.slot(p)).join(' '));
169
- }
170
- export interface FieldGridOptions {
171
- variant?: FieldGridVariant;
172
- mobile?: boolean;
173
- }
174
-
175
- /** Shared label/control grid. Rows with `display:contents` participate in these tracks. */
176
- export function fieldGrid(opts: FieldGridOptions = {}): HTMLElement {
177
- injectStyles(document);
178
- const el = document.createElement('div');
179
- cls(el, 'grid');
180
- const variant = opts.variant ?? 'inputs';
181
- el.dataset.variant = variant;
182
- if (opts.mobile) el.dataset.mobile = '';
183
- el.style.gridTemplateColumns = fieldGridColumns(variant, opts.mobile === true);
184
- return el;
185
- }
186
-
187
- export interface FieldSectionOptions {
188
- variant?: FieldGridVariant;
189
- first?: boolean;
190
- }
191
-
192
- /** Uppercase group heading that spans the field grid. */
193
- export function fieldSection(title: string, opts: FieldSectionOptions = {}): HTMLElement {
194
- injectStyles(document);
195
- const el = document.createElement('div');
196
- cls(el, 'section');
197
- if (opts.variant) el.dataset.variant = opts.variant;
198
- if (opts.first) el.dataset.first = '';
199
- el.textContent = title;
200
- return el;
201
- }
202
-
203
- /** Vertical breathing space between row clusters. */
204
- export function fieldSeparator(): HTMLElement {
205
- injectStyles(document);
206
- const el = document.createElement('div');
207
- cls(el, 'sep');
208
- return el;
209
- }
210
-
211
- export interface FieldToggleOpts {
212
- checked: boolean;
213
- onChange: (v: boolean) => void;
214
- get?: () => boolean;
215
- id?: string;
216
- }
217
-
218
- export interface FieldInlineItem {
219
- label?: string;
220
- id?: string;
221
- control: HTMLElement;
222
- /** Toggle sits left of its label (bool companion on an inline row). */
223
- toggleFirst?: boolean;
224
- fit?: boolean;
225
- }
226
-
227
- export interface FieldRowOptions {
228
- label: string;
229
- id?: string;
230
- control?: HTMLElement | HTMLElement[];
231
- info?: HTMLElement;
232
- toggle?: FieldToggleOpts;
233
- /** Full-width toggle + label (no control column). */
234
- bool?: boolean;
235
- /** Full-width stacked: centered label above a full-width control (textarea). */
236
- stacked?: boolean;
237
- /** Full-width wrap of several labeled controls. */
238
- inline?: FieldInlineItem[];
239
- /** Skip the 100px control wrap (color / session / time). */
240
- fit?: boolean;
241
- /** Wrap a single control at this width (indicator dialog number/select column). */
242
- controlWidth?: number;
243
- labelSize?: FieldLabelSize;
244
- className?: string;
245
- }
246
-
247
- function labelEl(text: string, opts: { id?: string; size?: FieldLabelSize }): HTMLElement {
248
- // A SPAN on purpose, never a `<label for>`: the title is fully INERT — it neither
249
- // reacts to hover (native labels propagate `:hover` onto their control) nor to
250
- // clicks. Only the input itself is interactive. The a11y association a label would
251
- // have given lives on the control as `aria-labelledby` instead.
252
- const el = document.createElement('span');
253
- cls(el, 'label');
254
- if (opts.size) el.dataset.size = opts.size;
255
- el.textContent = text;
256
- const id = opts.id;
257
- if (id) {
258
- el.id = `${id}--title`;
259
- // The control exists but may not be attached yet (rows are assembled before the
260
- // dialog mounts); after the current task it is, so the name lands reliably.
261
- queueMicrotask(() => {
262
- el.ownerDocument.getElementById(id)?.setAttribute('aria-labelledby', el.id);
263
- });
264
- }
265
- return el;
266
- }
267
-
268
- function asList(control: HTMLElement | HTMLElement[] | undefined): HTMLElement[] {
269
- if (!control) return [];
270
- return Array.isArray(control) ? control : [control];
271
- }
272
-
273
- function applyClass(el: HTMLElement, extra?: string): void {
274
- if (extra) for (const c of extra.split(/\s+/)) if (c) el.classList.add(c);
275
- }
276
-
277
- function dimControls(controls: HTMLElement[], on: boolean): void {
278
- for (const c of controls) {
279
- if (c.dataset.sdSelfGated === '1') continue;
280
- c.classList.toggle('vela-field-dim', !on);
281
- }
282
- }
283
-
284
- /** Label + control slot, optional master toggle, optional ⓘ. Grid-aware. */
285
- export function fieldRow(opts: FieldRowOptions): HTMLElement {
286
- injectStyles(document);
287
- const size = opts.labelSize;
288
-
289
- if (opts.inline) {
290
- const wrap = document.createElement('div');
291
- cls(wrap, 'span', 'inline');
292
- for (const item of opts.inline) {
293
- const it = document.createElement('div');
294
- cls(it, 'inline-item');
295
- if (item.toggleFirst) it.style.flexDirection = 'row-reverse';
296
- if (item.label) {
297
- it.appendChild(labelEl(item.label, { id: item.id, size }));
298
- }
299
- if (item.fit) it.appendChild(item.control);
300
- else {
301
- const cw = document.createElement('div');
302
- cw.style.width = '100px';
303
- cw.appendChild(item.control);
304
- it.appendChild(cw);
305
- }
306
- wrap.appendChild(it);
307
- }
308
- if (opts.info) wrap.appendChild(opts.info);
309
- applyClass(wrap, opts.className);
310
- return wrap;
311
- }
312
-
313
- if (opts.bool) {
314
- const wrap = document.createElement('div');
315
- cls(wrap, 'span', 'bool');
316
- const sw = new Checkbox({
317
- id: opts.toggle?.id ?? opts.id,
318
- checked: opts.toggle?.checked ?? false,
319
- size: 'md',
320
- tone: 'bright',
321
- onCheckedChange: (v) => opts.toggle?.onChange(v),
322
- });
323
- wrap.append(sw.el, labelEl(opts.label, { id: opts.toggle?.id ?? opts.id, size }));
324
- if (opts.info) wrap.appendChild(opts.info);
325
- if (opts.toggle?.get) {
326
- const get = opts.toggle.get;
327
- wrap.addEventListener('vela-sync', () => { sw.setChecked(get()); });
328
- }
329
- applyClass(wrap, opts.className);
330
- return wrap;
331
- }
332
-
333
- if (opts.stacked) {
334
- const wrap = document.createElement('div');
335
- cls(wrap, 'span', 'stacked');
336
- const head = document.createElement('div');
337
- cls(head, 'stacked-head');
338
- head.appendChild(labelEl(opts.label, { id: opts.id, size }));
339
- if (opts.info) head.appendChild(opts.info);
340
- wrap.appendChild(head);
341
- for (const c of asList(opts.control)) wrap.appendChild(c);
342
- applyClass(wrap, opts.className);
343
- return wrap;
344
- }
345
-
346
- const wrap = document.createElement('div');
347
- cls(wrap, 'row');
348
- const controls = asList(opts.control);
349
-
350
- if (opts.toggle) {
351
- const left = document.createElement('div');
352
- cls(left, 'toggle-label');
353
- const sw = new Checkbox({
354
- id: opts.toggle.id ?? opts.id,
355
- checked: opts.toggle.checked,
356
- size: 'md',
357
- tone: 'bright',
358
- onCheckedChange: (v) => {
359
- opts.toggle!.onChange(v);
360
- if (controls.length > 0) dimControls(controls, v);
361
- },
362
- });
363
- left.append(sw.el, labelEl(opts.label, { id: opts.toggle.id ?? opts.id, size }));
364
- wrap.appendChild(left);
365
- if (controls.length > 0) dimControls(controls, opts.toggle.checked);
366
- if (opts.toggle.get) {
367
- const get = opts.toggle.get;
368
- wrap.addEventListener('vela-sync', () => {
369
- const v = get();
370
- sw.setChecked(v);
371
- if (controls.length > 0) dimControls(controls, v);
372
- });
373
- }
374
- } else {
375
- wrap.appendChild(labelEl(opts.label, { id: opts.id, size }));
376
- }
377
-
378
- const cell = document.createElement('div');
379
- cls(cell, 'cell');
380
- if (opts.controlWidth != null && controls.length === 1 && !opts.fit) {
381
- const cw = document.createElement('div');
382
- cw.style.width = `${opts.controlWidth}px`;
383
- cw.appendChild(controls[0]!);
384
- cell.appendChild(cw);
385
- } else {
386
- for (const c of controls) cell.appendChild(c);
387
- }
388
- if (opts.info) cell.appendChild(opts.info);
389
- wrap.appendChild(cell);
390
- applyClass(wrap, opts.className);
391
- return wrap;
392
- }
393
-
394
- export interface FieldControlHandle {
395
- el: HTMLElement;
396
- setValue?: (v: unknown) => void;
397
- /** Release the control. Discarding a subtree with {@link disposeWithin} does it too. */
398
- destroy(): void;
399
- }
400
-
401
- export type FieldControlDesc =
402
- | {
403
- kind: 'number';
404
- id?: string;
405
- value: number;
406
- min?: number;
407
- max?: number;
408
- step?: number;
409
- integer?: boolean;
410
- commit?: 'blur' | 'live';
411
- steppers?: boolean;
412
- fill?: boolean;
413
- compact?: boolean;
414
- clamp?: boolean;
415
- placeholder?: string;
416
- emptyValue?: number;
417
- title?: string;
418
- onChange: (v: number) => void;
419
- sync?: () => number;
420
- }
421
- | {
422
- kind: 'select';
423
- id?: string;
424
- options: readonly SelectOption[];
425
- value: string;
426
- fill?: boolean;
427
- theme?: ChartTheme;
428
- list?: SelectListPopoverOpts;
429
- title?: string;
430
- onChange: (v: string) => void;
431
- sync?: () => string;
432
- }
433
- | {
434
- kind: 'switch';
435
- id?: string;
436
- checked: boolean;
437
- onChange: (v: boolean) => void;
438
- sync?: () => boolean;
439
- }
440
- | {
441
- kind: 'color';
442
- id?: string;
443
- theme: ChartTheme;
444
- get: () => string;
445
- onChange: (v: string) => void;
446
- popover?: ColorFieldOpts['popover'];
447
- /** Opacity-drag commit policy (default `'live'`): `'release'` when `onChange` recomputes rather than repaints. */
448
- commit?: ColorFieldOpts['commit'];
449
- title?: string;
450
- }
451
- | {
452
- kind: 'text';
453
- id?: string;
454
- value: string;
455
- fill?: boolean;
456
- placeholder?: string;
457
- onChange: (v: string) => void;
458
- sync?: () => string;
459
- }
460
- | {
461
- kind: 'textarea';
462
- id?: string;
463
- value: string;
464
- rows?: number;
465
- autoGrow?: boolean;
466
- maxLines?: number;
467
- placeholder?: string;
468
- onChange: (v: string) => void;
469
- sync?: () => string;
470
- }
471
- | {
472
- kind: 'width';
473
- theme: ChartTheme;
474
- get: () => number;
475
- onChange: (v: number) => void;
476
- title?: string;
477
- };
478
-
479
- /** One kit control from a neutral descriptor. `sync` re-reads on `vela-sync`. */
480
- export function buildFieldControl(desc: FieldControlDesc): FieldControlHandle {
481
- if (desc.kind === 'number') {
482
- const ni = new NumberInput({
483
- id: desc.id,
484
- value: desc.value,
485
- min: desc.min,
486
- max: desc.max,
487
- step: desc.step,
488
- integer: desc.integer,
489
- size: 'md',
490
- fill: desc.fill,
491
- compact: desc.compact,
492
- commit: desc.commit,
493
- steppers: desc.steppers,
494
- clamp: desc.clamp,
495
- placeholder: desc.placeholder,
496
- emptyValue: desc.emptyValue,
497
- title: desc.title,
498
- onChange: desc.onChange,
499
- });
500
- if (desc.sync) {
501
- const sync = desc.sync;
502
- ni.el.addEventListener('vela-sync', () => { ni.setValue(sync()); });
503
- }
504
- return { el: ni.el, setValue: (v) => ni.setValue(Number(v)), destroy: () => ni.destroy() };
505
- }
506
- if (desc.kind === 'select') {
507
- const sel = new Select({
508
- id: desc.id,
509
- options: desc.options,
510
- value: desc.value,
511
- size: 'md',
512
- fill: desc.fill,
513
- theme: desc.theme,
514
- list: desc.list,
515
- onValueChange: desc.onChange,
516
- });
517
- if (desc.title) sel.el.title = desc.title;
518
- if (desc.sync) {
519
- const sync = desc.sync;
520
- sel.el.addEventListener('vela-sync', () => { sel.setValue(sync()); });
521
- }
522
- return { el: sel.el, setValue: (v) => sel.setValue(String(v)), destroy: () => sel.destroy() };
523
- }
524
- if (desc.kind === 'switch') {
525
- const sw = new Checkbox({
526
- id: desc.id,
527
- checked: desc.checked,
528
- size: 'md',
529
- tone: 'bright',
530
- onCheckedChange: desc.onChange,
531
- });
532
- if (desc.sync) {
533
- const sync = desc.sync;
534
- sw.el.addEventListener('vela-sync', () => { sw.setChecked(sync()); });
535
- }
536
- return { el: sw.el, setValue: (v) => sw.setChecked(Boolean(v)), destroy: () => sw.destroy() };
537
- }
538
- if (desc.kind === 'color') {
539
- const field = new ColorField({
540
- theme: desc.theme,
541
- getVal: desc.get,
542
- onVal: desc.onChange,
543
- shape: 'circle',
544
- id: desc.id,
545
- popover: desc.popover,
546
- commit: desc.commit,
547
- });
548
- if (desc.title) field.el.title = desc.title;
549
- return { el: field.el, destroy: () => field.destroy() };
550
- }
551
- if (desc.kind === 'text') {
552
- const tf = new Input({
553
- id: desc.id,
554
- value: desc.value,
555
- size: 'md',
556
- fill: desc.fill,
557
- onChange: desc.onChange,
558
- });
559
- if (desc.placeholder) tf.input.placeholder = desc.placeholder;
560
- if (desc.sync) {
561
- const sync = desc.sync;
562
- tf.el.addEventListener('vela-sync', () => { tf.setValue(sync()); });
563
- }
564
- return { el: tf.el, setValue: (v) => tf.setValue(String(v)), destroy: () => tf.destroy() };
565
- }
566
- if (desc.kind === 'textarea') {
567
- const ta = new TextArea({
568
- id: desc.id,
569
- value: desc.value,
570
- rows: desc.rows,
571
- autoGrow: desc.autoGrow,
572
- maxLines: desc.maxLines,
573
- placeholder: desc.placeholder,
574
- onChange: desc.onChange,
575
- });
576
- if (desc.sync) {
577
- const sync = desc.sync;
578
- ta.el.addEventListener('vela-sync', () => { ta.setValue(sync()); });
579
- }
580
- return { el: ta.el, setValue: (v) => ta.setValue(String(v)), destroy: () => ta.destroy() };
581
- }
582
- const el = widthField(desc.theme, desc.get, desc.onChange);
583
- if (desc.title) el.title = desc.title;
584
- return { el, destroy: () => disposeWithin(el) };
1
+ // Field: the label-and-control grid the settings dialogs lay their inputs out on: rows (a
2
+ // label and its control, an optional master toggle that dims the control, an optional info
3
+ // mark), full-width toggles, stacked and inline rows, section headings and separators, and
4
+ // a factory that builds a row's control from a descriptor. Rows use `display: contents`, so
5
+ // their label and control sit on the grid's own tracks.
6
+ import type { ChartTheme } from '@luxalgo/vela-ui/tokens';
7
+ import { injectStyles as injectSheet } from '@luxalgo/vela-ui/styles';
8
+ import { css, defineStyles } from '@luxalgo/vela-ui';
9
+ import { defineComponent } from '@luxalgo/vela-ui';
10
+ import { disposeWithin } from '@luxalgo/vela-ui/dispose';
11
+ import { t } from '@luxalgo/vela-ui';
12
+ import { ColorField, type ColorFieldOpts } from '@luxalgo/vela-ui/color-picker';
13
+ import { widthField } from '@luxalgo/vela-ui/glyph-select';
14
+ import { NumberInput } from '@luxalgo/vela-ui/number-input';
15
+ import { Select, type SelectListPopoverOpts, type SelectOption } from '@luxalgo/vela-ui/select';
16
+ import { Checkbox } from '@luxalgo/vela-ui/checkbox';
17
+ import { TextArea } from '@luxalgo/vela-ui/text-area';
18
+ import { Input } from '@luxalgo/vela-ui/input';
19
+
20
+ export type FieldGridVariant = 'settings' | 'inputs';
21
+ export type FieldLabelSize = 'sm' | 'md';
22
+
23
+ /** Label↔control and between-row rhythm shared by the settings surfaces. */
24
+ export const FIELD_GAP_PX = 16;
25
+
26
+ /** Grid tracks for a field grid. Settings hugs both columns; inputs give leftover
27
+ * space to the control column. Mobile flips the label to a flexible track. */
28
+ export function fieldGridColumns(variant: FieldGridVariant, mobile: boolean): string {
29
+ if (variant === 'inputs') return mobile ? 'minmax(0,1fr) auto' : 'max-content 1fr';
30
+ return mobile ? 'minmax(0,1fr) max-content' : 'max-content max-content';
31
+ }
32
+
33
+ export const fieldDef = defineComponent({
34
+ name: 'field',
35
+ parts: ['grid', 'row', 'span', 'label', 'cell', 'bool', 'stacked', 'stacked-head', 'inline', 'inline-item', 'toggle-label', 'section', 'sep'],
36
+ });
37
+
38
+ type FieldPart = (typeof fieldDef.parts)[number];
39
+
40
+ const GAP = `${FIELD_GAP_PX}px`;
41
+
42
+ const injectFieldStyles = defineStyles(
43
+ 'vela-ui-field',
44
+ css`
45
+ @layer vela.ui {
46
+ [data-slot~='field-grid'] {
47
+ align-items: center;
48
+ align-content: start;
49
+ column-gap: ${GAP};
50
+ row-gap: ${GAP};
51
+
52
+ &:where(:not([hidden])) {
53
+ display: grid;
54
+ }
55
+ &[data-variant='inputs'] {
56
+ grid-template-columns: max-content 1fr;
57
+ }
58
+ &[data-variant='inputs'][data-mobile] {
59
+ grid-template-columns: minmax(0, 1fr) auto;
60
+ }
61
+ &[data-variant='settings'] {
62
+ grid-template-columns: max-content max-content;
63
+ column-gap: 12px;
64
+ }
65
+ &[data-variant='settings'][data-mobile] {
66
+ grid-template-columns: minmax(0, 1fr) max-content;
67
+ }
68
+ }
69
+ [data-slot~='field-row']:where(:not([hidden])) {
70
+ display: contents;
71
+ }
72
+ [data-slot~='field-span'] {
73
+ grid-column: 1 / -1;
74
+ }
75
+ [data-slot~='field-label'] {
76
+ opacity: 0.9;
77
+ white-space: nowrap;
78
+ overflow: hidden;
79
+ text-overflow: ellipsis;
80
+ font-size: 14px;
81
+
82
+ &[data-size='sm'] {
83
+ font-size: inherit;
84
+ opacity: 0.85;
85
+ }
86
+ }
87
+ /* Titles are fully inert: spans, not label[for] — native labels propagate :hover
88
+ and clicks onto their control, and both belong to the input alone. */
89
+ [data-slot~='field-cell'] {
90
+ display: flex;
91
+ align-items: center;
92
+ gap: 8px;
93
+ justify-self: start;
94
+ }
95
+ [data-slot~='field-bool']:where(:not([hidden])) {
96
+ display: flex;
97
+ align-items: center;
98
+ gap: 8px;
99
+ min-height: 22px;
100
+ }
101
+ [data-slot~='field-stacked']:where(:not([hidden])) {
102
+ display: flex;
103
+ flex-direction: column;
104
+ gap: 8px;
105
+ }
106
+ [data-slot~='field-stacked-head'] {
107
+ display: flex;
108
+ align-items: center;
109
+ justify-content: center;
110
+ gap: 8px;
111
+ }
112
+ [data-slot~='field-inline']:where(:not([hidden])) {
113
+ display: flex;
114
+ flex-wrap: wrap;
115
+ align-items: center;
116
+ gap: 12px;
117
+ }
118
+ [data-slot~='field-inline-item'] {
119
+ display: flex;
120
+ align-items: center;
121
+ gap: 8px;
122
+ }
123
+ [data-slot~='field-toggle-label'] {
124
+ display: flex;
125
+ align-items: center;
126
+ gap: 8px;
127
+ }
128
+ [data-slot~='field-section'] {
129
+ grid-column: 1 / -1;
130
+ margin: 24px 0 0;
131
+ padding-bottom: 8px;
132
+ font-size: ${t.fontSize.sm};
133
+ font-weight: 700;
134
+ letter-spacing: 0.05em;
135
+ text-transform: uppercase;
136
+ color: ${t.fg.muted};
137
+
138
+ &[data-variant='inputs'] {
139
+ margin: 0;
140
+ padding: 20px 0 8px;
141
+ font-size: 11px;
142
+ font-weight: 600;
143
+ }
144
+ &[data-variant='inputs'][data-first] {
145
+ padding-top: 4px;
146
+ }
147
+ }
148
+ [data-slot~='field-sep'] {
149
+ grid-column: 1 / -1;
150
+ height: 14px;
151
+ }
152
+ }
153
+ `,
154
+ );
155
+
156
+ /* A row's master toggle dims its controls. The dimmed state must beat every other style on
157
+ the control, the host's included, so it stays outside the layers and important. */
158
+ const DIM_CSS = '.vela-field-dim { opacity: 0.4 !important; pointer-events: none !important; }';
159
+
160
+ function injectStyles(doc: Document): void {
161
+ injectFieldStyles(doc);
162
+ injectSheet('vela-ui-field-dim', DIM_CSS, doc);
163
+ }
164
+
165
+ /** Give an element its field parts: the `vela-field-*` classes and the `data-slot` tokens. */
166
+ function cls(el: HTMLElement, ...parts: FieldPart[]): void {
167
+ el.className = parts.map((p) => `vela-field-${p}`).join(' ');
168
+ el.setAttribute('data-slot', parts.map((p) => fieldDef.slot(p)).join(' '));
169
+ }
170
+ export interface FieldGridOptions {
171
+ variant?: FieldGridVariant;
172
+ mobile?: boolean;
173
+ }
174
+
175
+ /** Shared label/control grid. Rows with `display:contents` participate in these tracks. */
176
+ export function fieldGrid(opts: FieldGridOptions = {}): HTMLElement {
177
+ injectStyles(document);
178
+ const el = document.createElement('div');
179
+ cls(el, 'grid');
180
+ const variant = opts.variant ?? 'inputs';
181
+ el.dataset.variant = variant;
182
+ if (opts.mobile) el.dataset.mobile = '';
183
+ el.style.gridTemplateColumns = fieldGridColumns(variant, opts.mobile === true);
184
+ return el;
185
+ }
186
+
187
+ export interface FieldSectionOptions {
188
+ variant?: FieldGridVariant;
189
+ first?: boolean;
190
+ }
191
+
192
+ /** Uppercase group heading that spans the field grid. */
193
+ export function fieldSection(title: string, opts: FieldSectionOptions = {}): HTMLElement {
194
+ injectStyles(document);
195
+ const el = document.createElement('div');
196
+ cls(el, 'section');
197
+ if (opts.variant) el.dataset.variant = opts.variant;
198
+ if (opts.first) el.dataset.first = '';
199
+ el.textContent = title;
200
+ return el;
201
+ }
202
+
203
+ /** Vertical breathing space between row clusters. */
204
+ export function fieldSeparator(): HTMLElement {
205
+ injectStyles(document);
206
+ const el = document.createElement('div');
207
+ cls(el, 'sep');
208
+ return el;
209
+ }
210
+
211
+ export interface FieldToggleOpts {
212
+ checked: boolean;
213
+ onChange: (v: boolean) => void;
214
+ get?: () => boolean;
215
+ id?: string;
216
+ }
217
+
218
+ export interface FieldInlineItem {
219
+ label?: string;
220
+ id?: string;
221
+ control: HTMLElement;
222
+ /** Toggle sits left of its label (bool companion on an inline row). */
223
+ toggleFirst?: boolean;
224
+ fit?: boolean;
225
+ }
226
+
227
+ export interface FieldRowOptions {
228
+ label: string;
229
+ id?: string;
230
+ control?: HTMLElement | HTMLElement[];
231
+ info?: HTMLElement;
232
+ toggle?: FieldToggleOpts;
233
+ /** Full-width toggle + label (no control column). */
234
+ bool?: boolean;
235
+ /** Full-width stacked: centered label above a full-width control (textarea). */
236
+ stacked?: boolean;
237
+ /** Full-width wrap of several labeled controls. */
238
+ inline?: FieldInlineItem[];
239
+ /** Skip the 100px control wrap (color / session / time). */
240
+ fit?: boolean;
241
+ /** Wrap a single control at this width (indicator dialog number/select column). */
242
+ controlWidth?: number;
243
+ labelSize?: FieldLabelSize;
244
+ className?: string;
245
+ }
246
+
247
+ function labelEl(text: string, opts: { id?: string; size?: FieldLabelSize }): HTMLElement {
248
+ // A SPAN on purpose, never a `<label for>`: the title is fully INERT — it neither
249
+ // reacts to hover (native labels propagate `:hover` onto their control) nor to
250
+ // clicks. Only the input itself is interactive. The a11y association a label would
251
+ // have given lives on the control as `aria-labelledby` instead.
252
+ const el = document.createElement('span');
253
+ cls(el, 'label');
254
+ if (opts.size) el.dataset.size = opts.size;
255
+ el.textContent = text;
256
+ const id = opts.id;
257
+ if (id) {
258
+ el.id = `${id}--title`;
259
+ // The control exists but may not be attached yet (rows are assembled before the
260
+ // dialog mounts); after the current task it is, so the name lands reliably.
261
+ queueMicrotask(() => {
262
+ el.ownerDocument.getElementById(id)?.setAttribute('aria-labelledby', el.id);
263
+ });
264
+ }
265
+ return el;
266
+ }
267
+
268
+ function asList(control: HTMLElement | HTMLElement[] | undefined): HTMLElement[] {
269
+ if (!control) return [];
270
+ return Array.isArray(control) ? control : [control];
271
+ }
272
+
273
+ function applyClass(el: HTMLElement, extra?: string): void {
274
+ if (extra) for (const c of extra.split(/\s+/)) if (c) el.classList.add(c);
275
+ }
276
+
277
+ function dimControls(controls: HTMLElement[], on: boolean): void {
278
+ for (const c of controls) {
279
+ if (c.dataset.sdSelfGated === '1') continue;
280
+ c.classList.toggle('vela-field-dim', !on);
281
+ }
282
+ }
283
+
284
+ /** Label + control slot, optional master toggle, optional ⓘ. Grid-aware. */
285
+ export function fieldRow(opts: FieldRowOptions): HTMLElement {
286
+ injectStyles(document);
287
+ const size = opts.labelSize;
288
+
289
+ if (opts.inline) {
290
+ const wrap = document.createElement('div');
291
+ cls(wrap, 'span', 'inline');
292
+ for (const item of opts.inline) {
293
+ const it = document.createElement('div');
294
+ cls(it, 'inline-item');
295
+ if (item.toggleFirst) it.style.flexDirection = 'row-reverse';
296
+ if (item.label) {
297
+ it.appendChild(labelEl(item.label, { id: item.id, size }));
298
+ }
299
+ if (item.fit) it.appendChild(item.control);
300
+ else {
301
+ const cw = document.createElement('div');
302
+ cw.style.width = '100px';
303
+ cw.appendChild(item.control);
304
+ it.appendChild(cw);
305
+ }
306
+ wrap.appendChild(it);
307
+ }
308
+ if (opts.info) wrap.appendChild(opts.info);
309
+ applyClass(wrap, opts.className);
310
+ return wrap;
311
+ }
312
+
313
+ if (opts.bool) {
314
+ const wrap = document.createElement('div');
315
+ cls(wrap, 'span', 'bool');
316
+ const sw = new Checkbox({
317
+ id: opts.toggle?.id ?? opts.id,
318
+ checked: opts.toggle?.checked ?? false,
319
+ size: 'md',
320
+ tone: 'bright',
321
+ onCheckedChange: (v) => opts.toggle?.onChange(v),
322
+ });
323
+ wrap.append(sw.el, labelEl(opts.label, { id: opts.toggle?.id ?? opts.id, size }));
324
+ if (opts.info) wrap.appendChild(opts.info);
325
+ if (opts.toggle?.get) {
326
+ const get = opts.toggle.get;
327
+ wrap.addEventListener('vela-sync', () => { sw.setChecked(get()); });
328
+ }
329
+ applyClass(wrap, opts.className);
330
+ return wrap;
331
+ }
332
+
333
+ if (opts.stacked) {
334
+ const wrap = document.createElement('div');
335
+ cls(wrap, 'span', 'stacked');
336
+ const head = document.createElement('div');
337
+ cls(head, 'stacked-head');
338
+ head.appendChild(labelEl(opts.label, { id: opts.id, size }));
339
+ if (opts.info) head.appendChild(opts.info);
340
+ wrap.appendChild(head);
341
+ for (const c of asList(opts.control)) wrap.appendChild(c);
342
+ applyClass(wrap, opts.className);
343
+ return wrap;
344
+ }
345
+
346
+ const wrap = document.createElement('div');
347
+ cls(wrap, 'row');
348
+ const controls = asList(opts.control);
349
+
350
+ if (opts.toggle) {
351
+ const left = document.createElement('div');
352
+ cls(left, 'toggle-label');
353
+ const sw = new Checkbox({
354
+ id: opts.toggle.id ?? opts.id,
355
+ checked: opts.toggle.checked,
356
+ size: 'md',
357
+ tone: 'bright',
358
+ onCheckedChange: (v) => {
359
+ opts.toggle!.onChange(v);
360
+ if (controls.length > 0) dimControls(controls, v);
361
+ },
362
+ });
363
+ left.append(sw.el, labelEl(opts.label, { id: opts.toggle.id ?? opts.id, size }));
364
+ wrap.appendChild(left);
365
+ if (controls.length > 0) dimControls(controls, opts.toggle.checked);
366
+ if (opts.toggle.get) {
367
+ const get = opts.toggle.get;
368
+ wrap.addEventListener('vela-sync', () => {
369
+ const v = get();
370
+ sw.setChecked(v);
371
+ if (controls.length > 0) dimControls(controls, v);
372
+ });
373
+ }
374
+ } else {
375
+ wrap.appendChild(labelEl(opts.label, { id: opts.id, size }));
376
+ }
377
+
378
+ const cell = document.createElement('div');
379
+ cls(cell, 'cell');
380
+ if (opts.controlWidth != null && controls.length === 1 && !opts.fit) {
381
+ const cw = document.createElement('div');
382
+ cw.style.width = `${opts.controlWidth}px`;
383
+ cw.appendChild(controls[0]!);
384
+ cell.appendChild(cw);
385
+ } else {
386
+ for (const c of controls) cell.appendChild(c);
387
+ }
388
+ if (opts.info) cell.appendChild(opts.info);
389
+ wrap.appendChild(cell);
390
+ applyClass(wrap, opts.className);
391
+ return wrap;
392
+ }
393
+
394
+ export interface FieldControlHandle {
395
+ el: HTMLElement;
396
+ setValue?: (v: unknown) => void;
397
+ /** Release the control. Discarding a subtree with {@link disposeWithin} does it too. */
398
+ destroy(): void;
399
+ }
400
+
401
+ export type FieldControlDesc =
402
+ | {
403
+ kind: 'number';
404
+ id?: string;
405
+ value: number;
406
+ min?: number;
407
+ max?: number;
408
+ step?: number;
409
+ integer?: boolean;
410
+ commit?: 'blur' | 'live';
411
+ steppers?: boolean;
412
+ fill?: boolean;
413
+ compact?: boolean;
414
+ clamp?: boolean;
415
+ placeholder?: string;
416
+ emptyValue?: number;
417
+ title?: string;
418
+ onChange: (v: number) => void;
419
+ sync?: () => number;
420
+ }
421
+ | {
422
+ kind: 'select';
423
+ id?: string;
424
+ options: readonly SelectOption[];
425
+ value: string;
426
+ fill?: boolean;
427
+ theme?: ChartTheme;
428
+ list?: SelectListPopoverOpts;
429
+ title?: string;
430
+ onChange: (v: string) => void;
431
+ sync?: () => string;
432
+ }
433
+ | {
434
+ kind: 'switch';
435
+ id?: string;
436
+ checked: boolean;
437
+ onChange: (v: boolean) => void;
438
+ sync?: () => boolean;
439
+ }
440
+ | {
441
+ kind: 'color';
442
+ id?: string;
443
+ theme: ChartTheme;
444
+ get: () => string;
445
+ onChange: (v: string) => void;
446
+ popover?: ColorFieldOpts['popover'];
447
+ /** Opacity-drag commit policy (default `'live'`): `'release'` when `onChange` recomputes rather than repaints. */
448
+ commit?: ColorFieldOpts['commit'];
449
+ title?: string;
450
+ }
451
+ | {
452
+ kind: 'text';
453
+ id?: string;
454
+ value: string;
455
+ fill?: boolean;
456
+ placeholder?: string;
457
+ onChange: (v: string) => void;
458
+ sync?: () => string;
459
+ }
460
+ | {
461
+ kind: 'textarea';
462
+ id?: string;
463
+ value: string;
464
+ rows?: number;
465
+ autoGrow?: boolean;
466
+ maxLines?: number;
467
+ placeholder?: string;
468
+ onChange: (v: string) => void;
469
+ sync?: () => string;
470
+ }
471
+ | {
472
+ kind: 'width';
473
+ theme: ChartTheme;
474
+ get: () => number;
475
+ onChange: (v: number) => void;
476
+ title?: string;
477
+ };
478
+
479
+ /** One kit control from a neutral descriptor. `sync` re-reads on `vela-sync`. */
480
+ export function buildFieldControl(desc: FieldControlDesc): FieldControlHandle {
481
+ if (desc.kind === 'number') {
482
+ const ni = new NumberInput({
483
+ id: desc.id,
484
+ value: desc.value,
485
+ min: desc.min,
486
+ max: desc.max,
487
+ step: desc.step,
488
+ integer: desc.integer,
489
+ size: 'md',
490
+ fill: desc.fill,
491
+ compact: desc.compact,
492
+ commit: desc.commit,
493
+ steppers: desc.steppers,
494
+ clamp: desc.clamp,
495
+ placeholder: desc.placeholder,
496
+ emptyValue: desc.emptyValue,
497
+ title: desc.title,
498
+ onChange: desc.onChange,
499
+ });
500
+ if (desc.sync) {
501
+ const sync = desc.sync;
502
+ ni.el.addEventListener('vela-sync', () => { ni.setValue(sync()); });
503
+ }
504
+ return { el: ni.el, setValue: (v) => ni.setValue(Number(v)), destroy: () => ni.destroy() };
505
+ }
506
+ if (desc.kind === 'select') {
507
+ const sel = new Select({
508
+ id: desc.id,
509
+ options: desc.options,
510
+ value: desc.value,
511
+ size: 'md',
512
+ fill: desc.fill,
513
+ theme: desc.theme,
514
+ list: desc.list,
515
+ onValueChange: desc.onChange,
516
+ });
517
+ if (desc.title) sel.el.title = desc.title;
518
+ if (desc.sync) {
519
+ const sync = desc.sync;
520
+ sel.el.addEventListener('vela-sync', () => { sel.setValue(sync()); });
521
+ }
522
+ return { el: sel.el, setValue: (v) => sel.setValue(String(v)), destroy: () => sel.destroy() };
523
+ }
524
+ if (desc.kind === 'switch') {
525
+ const sw = new Checkbox({
526
+ id: desc.id,
527
+ checked: desc.checked,
528
+ size: 'md',
529
+ tone: 'bright',
530
+ onCheckedChange: desc.onChange,
531
+ });
532
+ if (desc.sync) {
533
+ const sync = desc.sync;
534
+ sw.el.addEventListener('vela-sync', () => { sw.setChecked(sync()); });
535
+ }
536
+ return { el: sw.el, setValue: (v) => sw.setChecked(Boolean(v)), destroy: () => sw.destroy() };
537
+ }
538
+ if (desc.kind === 'color') {
539
+ const field = new ColorField({
540
+ theme: desc.theme,
541
+ getVal: desc.get,
542
+ onVal: desc.onChange,
543
+ shape: 'circle',
544
+ id: desc.id,
545
+ popover: desc.popover,
546
+ commit: desc.commit,
547
+ });
548
+ if (desc.title) field.el.title = desc.title;
549
+ return { el: field.el, destroy: () => field.destroy() };
550
+ }
551
+ if (desc.kind === 'text') {
552
+ const tf = new Input({
553
+ id: desc.id,
554
+ value: desc.value,
555
+ size: 'md',
556
+ fill: desc.fill,
557
+ onChange: desc.onChange,
558
+ });
559
+ if (desc.placeholder) tf.input.placeholder = desc.placeholder;
560
+ if (desc.sync) {
561
+ const sync = desc.sync;
562
+ tf.el.addEventListener('vela-sync', () => { tf.setValue(sync()); });
563
+ }
564
+ return { el: tf.el, setValue: (v) => tf.setValue(String(v)), destroy: () => tf.destroy() };
565
+ }
566
+ if (desc.kind === 'textarea') {
567
+ const ta = new TextArea({
568
+ id: desc.id,
569
+ value: desc.value,
570
+ rows: desc.rows,
571
+ autoGrow: desc.autoGrow,
572
+ maxLines: desc.maxLines,
573
+ placeholder: desc.placeholder,
574
+ onChange: desc.onChange,
575
+ });
576
+ if (desc.sync) {
577
+ const sync = desc.sync;
578
+ ta.el.addEventListener('vela-sync', () => { ta.setValue(sync()); });
579
+ }
580
+ return { el: ta.el, setValue: (v) => ta.setValue(String(v)), destroy: () => ta.destroy() };
581
+ }
582
+ const el = widthField(desc.theme, desc.get, desc.onChange);
583
+ if (desc.title) el.title = desc.title;
584
+ return { el, destroy: () => disposeWithin(el) };
585
585
  }