@luxalgo/vela-ui 0.2.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 (217) hide show
  1. package/CHANGELOG.md +153 -91
  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/badge.js +1 -1
  8. package/dist/bar-chart.d.ts +1 -1
  9. package/dist/bar-chart.js +1 -1
  10. package/dist/button.d.ts +1 -1
  11. package/dist/button.js +4 -4
  12. package/dist/callout-bubble.d.ts +1 -1
  13. package/dist/callout-bubble.js +4 -4
  14. package/dist/card.d.ts +52 -0
  15. package/dist/card.js +179 -0
  16. package/dist/checkbox.js +5 -5
  17. package/dist/{chunk-B5ZSRUDQ.js → chunk-BWSOMG3G.js} +2 -2
  18. package/dist/{chunk-G7IQLY3A.js → chunk-C3PXY2SW.js} +5 -0
  19. package/dist/{chunk-CC3DDNFC.js → chunk-DXDCKZ2M.js} +4 -4
  20. package/dist/chunk-GUIYFQ27.js +30 -0
  21. package/dist/{chunk-WGULXRWD.js → chunk-KUWTI2PE.js} +4 -4
  22. package/dist/{chunk-Z5PINFQO.js → chunk-QGWAN3EP.js} +5 -5
  23. package/dist/{chunk-V2Q4MRMS.js → chunk-RH53NQGE.js} +30 -4
  24. package/dist/{chunk-WBGSYCV2.js → chunk-SKFAYTDK.js} +4 -4
  25. package/dist/{chunk-MJ4RUGX7.js → chunk-TGJNHUYV.js} +3 -3
  26. package/dist/{chunk-WXH3EFV5.js → chunk-VC7SVSDK.js} +4 -4
  27. package/dist/{chunk-7VMN7NKJ.js → chunk-YT2BSP7O.js} +3 -3
  28. package/dist/collapsible.d.ts +1 -1
  29. package/dist/collapsible.js +3 -3
  30. package/dist/color-picker.js +5 -5
  31. package/dist/context-menu.js +5 -5
  32. package/dist/data-table.d.ts +1 -1
  33. package/dist/data-table.js +1 -1
  34. package/dist/date-picker.d.ts +1 -1
  35. package/dist/date-picker.js +2 -2
  36. package/dist/dialog.d.ts +9 -1
  37. package/dist/dialog.js +15 -5
  38. package/dist/donut.d.ts +1 -1
  39. package/dist/donut.js +1 -1
  40. package/dist/drawer.d.ts +1 -1
  41. package/dist/drawer.js +2 -2
  42. package/dist/dropdown-menu.d.ts +1 -1
  43. package/dist/dropdown-menu.js +5 -5
  44. package/dist/empty.d.ts +1 -1
  45. package/dist/empty.js +2 -2
  46. package/dist/field.js +13 -13
  47. package/dist/{stat.d.ts → figure.d.ts} +9 -9
  48. package/dist/figure.js +41 -0
  49. package/dist/glyph-select.js +5 -5
  50. package/dist/hover-card.d.ts +1 -1
  51. package/dist/hover-card.js +3 -3
  52. package/dist/icons.js +1 -1
  53. package/dist/index.d.ts +4 -2
  54. package/dist/index.js +3 -3
  55. package/dist/input-group.d.ts +1 -1
  56. package/dist/input-group.js +4 -4
  57. package/dist/input.js +2 -2
  58. package/dist/item.d.ts +1 -1
  59. package/dist/item.js +2 -2
  60. package/dist/kbd.d.ts +1 -1
  61. package/dist/kbd.js +2 -2
  62. package/dist/line-chart.d.ts +1 -1
  63. package/dist/line-chart.js +1 -1
  64. package/dist/manifest.json +691 -74
  65. package/dist/month-grid.js +1 -1
  66. package/dist/number-input.d.ts +1 -1
  67. package/dist/number-input.js +5 -5
  68. package/dist/popover.js +3 -3
  69. package/dist/scatter-chart.d.ts +1 -1
  70. package/dist/scatter-chart.js +1 -1
  71. package/dist/select.d.ts +1 -1
  72. package/dist/select.js +7 -7
  73. package/dist/slider.d.ts +1 -1
  74. package/dist/slider.js +2 -2
  75. package/dist/sort-button.js +4 -4
  76. package/dist/sparkline.d.ts +1 -1
  77. package/dist/sparkline.js +1 -1
  78. package/dist/switch.d.ts +1 -1
  79. package/dist/switch.js +3 -3
  80. package/dist/tabs.d.ts +1 -1
  81. package/dist/tabs.js +4 -4
  82. package/dist/text-area.d.ts +1 -1
  83. package/dist/text-area.js +2 -2
  84. package/dist/theme-TefB8vtl.d.ts +341 -0
  85. package/dist/theme.d.ts +42 -192
  86. package/dist/theme.js +1 -1
  87. package/dist/theme.schema.json +321 -30
  88. package/dist/toast.d.ts +49 -0
  89. package/dist/toast.js +463 -0
  90. package/dist/toggle-group.d.ts +1 -1
  91. package/dist/toggle-group.js +4 -4
  92. package/dist/tooltip.js +2 -2
  93. package/dist/treemap.d.ts +80 -0
  94. package/dist/treemap.js +470 -0
  95. package/dist/zag.d.ts +11 -2
  96. package/dist/zag.js +1 -1
  97. package/docs/theming.md +217 -217
  98. package/docs/what-to-change.md +20 -20
  99. package/docs/writing-a-component.md +250 -250
  100. package/llms.txt +6 -3
  101. package/package.json +90 -90
  102. package/registry/badge.ts +119 -119
  103. package/registry/bar-chart.ts +215 -215
  104. package/registry/button.ts +387 -379
  105. package/registry/callout-bubble.ts +347 -347
  106. package/registry/card.ts +379 -0
  107. package/registry/checkbox.ts +234 -234
  108. package/registry/collapsible.ts +271 -271
  109. package/registry/color-picker.ts +582 -582
  110. package/registry/context-menu.ts +208 -208
  111. package/registry/data-table.ts +215 -215
  112. package/registry/date-picker.ts +483 -483
  113. package/registry/dialog.ts +551 -535
  114. package/registry/donut.ts +145 -145
  115. package/registry/drawer.ts +636 -636
  116. package/registry/dropdown-menu.ts +762 -762
  117. package/registry/empty.ts +91 -91
  118. package/registry/field.ts +584 -584
  119. package/registry/{stat.ts → figure.ts} +96 -96
  120. package/registry/glyph-select.ts +268 -268
  121. package/registry/hover-card.ts +222 -222
  122. package/registry/input-group.ts +229 -229
  123. package/registry/input.ts +181 -181
  124. package/registry/item.ts +376 -376
  125. package/registry/kbd.ts +64 -64
  126. package/registry/line-chart.ts +218 -218
  127. package/registry/month-grid.ts +328 -328
  128. package/registry/number-input.ts +443 -443
  129. package/registry/popover.ts +368 -368
  130. package/registry/scatter-chart.ts +221 -221
  131. package/registry/select.ts +620 -620
  132. package/registry/slider.ts +259 -259
  133. package/registry/sort-button.ts +189 -189
  134. package/registry/sparkline.ts +114 -114
  135. package/registry/switch.ts +205 -205
  136. package/registry/tabs.ts +426 -426
  137. package/registry/text-area.ts +186 -186
  138. package/registry/toast.ts +965 -0
  139. package/registry/toggle-group.ts +295 -295
  140. package/registry/tooltip.ts +156 -156
  141. package/registry/treemap.ts +847 -0
  142. package/skills/theming-vela-ui/SKILL.md +137 -137
  143. package/skills/using-vela-ui-components/SKILL.md +139 -137
  144. package/skills/writing-vela-ui-components/SKILL.md +163 -163
  145. package/src/components/badge.ts +119 -119
  146. package/src/components/bar-chart.ts +215 -215
  147. package/src/components/button.ts +387 -379
  148. package/src/components/callout-bubble.ts +347 -347
  149. package/src/components/card.ts +379 -0
  150. package/src/components/checkbox.ts +234 -234
  151. package/src/components/collapsible.ts +271 -271
  152. package/src/components/color-picker.ts +582 -582
  153. package/src/components/context-menu.ts +208 -208
  154. package/src/components/data-table.ts +215 -215
  155. package/src/components/date-picker.ts +483 -483
  156. package/src/components/dialog.ts +551 -535
  157. package/src/components/donut.ts +145 -145
  158. package/src/components/drawer.ts +636 -636
  159. package/src/components/dropdown-menu.ts +762 -762
  160. package/src/components/empty.ts +91 -91
  161. package/src/components/field.ts +584 -584
  162. package/src/components/{stat.ts → figure.ts} +96 -96
  163. package/src/components/glyph-select.ts +268 -268
  164. package/src/components/hover-card.ts +222 -222
  165. package/src/components/input-group.ts +229 -229
  166. package/src/components/input.ts +181 -181
  167. package/src/components/item.ts +376 -376
  168. package/src/components/kbd.ts +64 -64
  169. package/src/components/line-chart.ts +218 -218
  170. package/src/components/month-grid.ts +328 -328
  171. package/src/components/number-input.ts +443 -443
  172. package/src/components/popover.ts +368 -368
  173. package/src/components/scatter-chart.ts +221 -221
  174. package/src/components/select.ts +620 -620
  175. package/src/components/slider.ts +259 -259
  176. package/src/components/sort-button.ts +189 -189
  177. package/src/components/sparkline.ts +114 -114
  178. package/src/components/switch.ts +205 -205
  179. package/src/components/tabs.ts +426 -426
  180. package/src/components/text-area.ts +186 -186
  181. package/src/components/toast.ts +965 -0
  182. package/src/components/toggle-group.ts +295 -295
  183. package/src/components/tooltip.ts +156 -156
  184. package/src/components/treemap.ts +847 -0
  185. package/src/index.ts +24 -24
  186. package/src/lib/calendar.ts +117 -117
  187. package/src/lib/chart.ts +72 -72
  188. package/src/lib/color.ts +89 -89
  189. package/src/lib/component-index.ts +163 -151
  190. package/src/lib/css.ts +48 -48
  191. package/src/lib/define.ts +45 -45
  192. package/src/lib/dispose.ts +36 -36
  193. package/src/lib/h.ts +55 -55
  194. package/src/lib/headless.ts +16 -16
  195. package/src/lib/i18n.ts +30 -30
  196. package/src/lib/icons.ts +244 -237
  197. package/src/lib/kit-text.ts +26 -26
  198. package/src/lib/page.ts +24 -24
  199. package/src/lib/palette.ts +81 -81
  200. package/src/lib/placement.ts +188 -188
  201. package/src/lib/scope.ts +135 -135
  202. package/src/lib/styles.ts +53 -53
  203. package/src/lib/surface-events.ts +31 -31
  204. package/src/lib/surface-exit.ts +87 -87
  205. package/src/lib/t.ts +68 -68
  206. package/src/lib/theme.ts +684 -664
  207. package/src/lib/tokens.ts +110 -110
  208. package/src/lib/variants.ts +32 -32
  209. package/src/lib/zag.ts +61 -46
  210. package/stylelint/index.mjs +60 -60
  211. package/stylelint/lint.mjs +81 -81
  212. package/stylelint/plugin.mjs +115 -115
  213. package/dist/chunk-P4MTEMT7.js +0 -23
  214. package/dist/stat.js +0 -41
  215. package/dist/{chunk-U3EH42YY.js → chunk-5BJV5FY5.js} +1 -1
  216. package/dist/{chunk-E2FE6V2N.js → chunk-ALAHGSLC.js} +1 -1
  217. package/dist/{chunk-C3ICYMI3.js → chunk-FYVQO5TN.js} +1 -1
@@ -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 '../lib/tokens';
7
- import { injectStyles as injectSheet } from '../lib/styles';
8
- import { css, defineStyles } from '../lib/css';
9
- import { defineComponent } from '../lib/define';
10
- import { disposeWithin } from '../lib/dispose';
11
- import { t } from '../lib/t';
12
- import { ColorField, type ColorFieldOpts } from './color-picker';
13
- import { widthField } from './glyph-select';
14
- import { NumberInput } from './number-input';
15
- import { Select, type SelectListPopoverOpts, type SelectOption } from './select';
16
- import { Checkbox } from './checkbox';
17
- import { TextArea } from './text-area';
18
- import { Input } from './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 '../lib/tokens';
7
+ import { injectStyles as injectSheet } from '../lib/styles';
8
+ import { css, defineStyles } from '../lib/css';
9
+ import { defineComponent } from '../lib/define';
10
+ import { disposeWithin } from '../lib/dispose';
11
+ import { t } from '../lib/t';
12
+ import { ColorField, type ColorFieldOpts } from './color-picker';
13
+ import { widthField } from './glyph-select';
14
+ import { NumberInput } from './number-input';
15
+ import { Select, type SelectListPopoverOpts, type SelectOption } from './select';
16
+ import { Checkbox } from './checkbox';
17
+ import { TextArea } from './text-area';
18
+ import { Input } from './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
  }