@viewstem/ui 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.ko.md +47 -0
  3. package/README.md +60 -2
  4. package/dist/BASECOAT-LICENSE.md +21 -0
  5. package/dist/basecoat-contracts.d.ts +2 -0
  6. package/dist/basecoat-contracts.js +358 -0
  7. package/dist/basecoat-controllers.js +1612 -0
  8. package/dist/behaviors.d.ts +29 -0
  9. package/dist/behaviors.js +1475 -0
  10. package/dist/browser.d.ts +2 -0
  11. package/dist/browser.js +2 -0
  12. package/dist/catalog-meta.d.ts +26 -0
  13. package/dist/catalog-meta.js +130 -0
  14. package/dist/component-context.d.ts +7 -0
  15. package/dist/component-context.js +10 -0
  16. package/dist/components.d.ts +2 -0
  17. package/dist/components.js +532 -0
  18. package/dist/data-table.d.ts +2 -0
  19. package/dist/data-table.js +231 -0
  20. package/dist/date-calendar.d.ts +4 -0
  21. package/dist/date-calendar.js +512 -0
  22. package/dist/dynamic-catalog.d.ts +2 -0
  23. package/dist/dynamic-catalog.js +118 -0
  24. package/dist/form-scroll-families.d.ts +7 -0
  25. package/dist/form-scroll-families.js +895 -0
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +12 -0
  28. package/dist/markup-families.d.ts +10 -0
  29. package/dist/markup-families.js +492 -0
  30. package/dist/menus.d.ts +8 -0
  31. package/dist/menus.js +427 -0
  32. package/dist/shadcn.d.ts +13 -0
  33. package/dist/shadcn.js +8 -0
  34. package/dist/slider-values.d.ts +9 -0
  35. package/dist/slider-values.js +43 -0
  36. package/dist/slider.d.ts +2 -0
  37. package/dist/slider.js +148 -0
  38. package/dist/static-catalog.d.ts +2 -0
  39. package/dist/static-catalog.js +87 -0
  40. package/dist/style-scope.d.ts +2 -0
  41. package/dist/style-scope.js +3 -0
  42. package/dist/styles.css +9573 -0
  43. package/dist/styles.css.d.ts +1 -0
  44. package/dist/support.json +1 -0
  45. package/dist/widget-families.d.ts +6 -0
  46. package/dist/widget-families.js +739 -0
  47. package/package.json +59 -4
@@ -0,0 +1,532 @@
1
+ import { attributes, components, domEvents, support } from './shadcn.js';
2
+ import { chart, combobox, command, commandDialog, disclosure, group, modal, notifications, popover, range, scopeChartColor, select, tabs, tooltip, uniqueId } from './behaviors.js';
3
+ import { dateCalendar } from './date-calendar.js';
4
+ import { multiSlider } from './slider.js';
5
+ import { dataTable } from './data-table.js';
6
+ import { bindComponent, emitFrom, readInputs } from './component-context.js';
7
+ import { menus } from './menus.js';
8
+ import { markupBehavior, markupTag } from './markup-families.js';
9
+ import { widgetBehavior } from './widget-families.js';
10
+ import { formScrollBehavior, formScrollHost } from './form-scroll-families.js';
11
+ import { styleScope } from './style-scope.js';
12
+ const contracts = new Map(support.map(spec => [spec.id, spec]));
13
+ const detailsGroup = new Set(['RadioGroup.Root', 'Pagination.Root', 'Sidebar.Provider']);
14
+ const modalRoots = /^(?:Dialog|AlertDialog|Drawer|Sheet)\.(?:Root|NestedRoot)$/;
15
+ const modalParts = /^(?:Dialog|AlertDialog|Drawer|Sheet)\.(Trigger|Close|Content|Title|Description|Action|Cancel|Overlay)$/;
16
+ const labelledMenuParts = /^(?:Command\.(?:Item|LinkItem)|(?:ContextMenu|DropdownMenu|Menubar)\.Item)$/;
17
+ function domEvent(event, target) {
18
+ const payload = { type: event.type };
19
+ for (const key of ['value', 'checked']) {
20
+ const value = target[key];
21
+ if (typeof value === 'boolean' || typeof value === 'string')
22
+ payload[key] = value;
23
+ }
24
+ const source = event;
25
+ for (const key of ['key', 'code', 'button', 'buttons', 'altKey', 'ctrlKey', 'metaKey', 'shiftKey']) {
26
+ const value = source[key];
27
+ if (typeof value === 'string' || typeof value === 'boolean' || typeof value === 'number')
28
+ payload[key] = value;
29
+ }
30
+ return payload;
31
+ }
32
+ function setAttribute(element, key, value, fallback) {
33
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
34
+ const boolean = ['disabled', 'required', 'readonly', 'multiple', 'hidden', 'inert', 'selected'];
35
+ if (boolean.includes(key) && typeof value === 'boolean')
36
+ element.toggleAttribute(key, value);
37
+ else if (element.getAttribute(key) !== String(value))
38
+ element.setAttribute(key, String(value));
39
+ }
40
+ else if (fallback !== undefined)
41
+ element.setAttribute(key, fallback);
42
+ else if (element.hasAttribute(key))
43
+ element.removeAttribute(key);
44
+ }
45
+ function safeUrl(element, value, allowCsvDownload = false) {
46
+ if (typeof value !== 'string')
47
+ return undefined;
48
+ try {
49
+ if (allowCsvDownload && /^data:text\/csv(?:;charset=utf-8)?(?:;base64)?,/i.test(value))
50
+ return value;
51
+ const protocol = new URL(value, element.ownerDocument.baseURI).protocol;
52
+ return ['http:', 'https:', 'mailto:', 'tel:', 'blob:'].includes(protocol) ? value : undefined;
53
+ }
54
+ catch {
55
+ return undefined;
56
+ }
57
+ }
58
+ function disposeEntry(entry) {
59
+ entry.events.abort();
60
+ entry.behavior?.dispose?.();
61
+ entry.element.remove();
62
+ }
63
+ function behavior(name, element, send, signal) {
64
+ if (name === 'Calendar.Root' || name === 'RangeCalendar.Root' || name === 'DatePicker')
65
+ return dateCalendar(element, name, send, signal);
66
+ if (name === 'DataTable')
67
+ return dataTable(element, send, signal);
68
+ if (modalRoots.test(name))
69
+ return modal(element, send, signal);
70
+ if (name === 'Accordion.Root' || name === 'Collapsible.Root')
71
+ return disclosure(element, name, send, signal);
72
+ if (name === 'Tabs.Root')
73
+ return tabs(element, send, signal);
74
+ if (name === 'Select.Root')
75
+ return select(element, send, signal);
76
+ if (name === 'Popover.Root')
77
+ return popover(element, send, signal);
78
+ if (name === 'DropdownMenu.Root' || name === 'ContextMenu.Root' || name === 'Menubar.Root') {
79
+ const family = name.slice(0, -5);
80
+ return menus(element, family, send, signal);
81
+ }
82
+ if (name === 'Tooltip.Root')
83
+ return tooltip(element, send, signal);
84
+ if (name === 'Combobox')
85
+ return combobox(element, send, signal);
86
+ if (name === 'Command.Root')
87
+ return command(element, send, signal);
88
+ if (name === 'Slider')
89
+ return element.localName === 'input'
90
+ ? range(element, send, signal) : multiSlider(element, send, signal);
91
+ if (detailsGroup.has(name))
92
+ return group(element, name, send, signal);
93
+ if (name === 'Notifications')
94
+ return notifications(element, send);
95
+ if (name === 'Chart')
96
+ return chart(element);
97
+ return markupBehavior(name, element, send, signal) ??
98
+ widgetBehavior(name, element, send, signal) ??
99
+ formScrollBehavior(name, element, send, signal);
100
+ }
101
+ export function catalogComponent(name) {
102
+ return { mount(context) {
103
+ const doc = context.parent.ownerDocument;
104
+ function createEntry(node) {
105
+ const definition = components.get(name);
106
+ const markup = name === 'Slider' && node.inputs.type === 'multiple'
107
+ ? ['div', 'vs-slider-group', { role: 'group' }]
108
+ : definition ?? ['div', ''];
109
+ const tag = markupTag(name, node.inputs) ?? markup[0];
110
+ const defaults = markup[2];
111
+ const part = modalParts.exec(name)?.[1]?.toLowerCase();
112
+ const childAction = !!node.slots.child?.length && !!part;
113
+ const childTrigger = !!node.slots.child?.length && (/^(?:DropdownMenu|HoverCard|Tooltip|Popover)\.Trigger$/.test(name) || name === 'Popover.Close');
114
+ const control = styleScope.createElement(doc, childAction || childTrigger ? 'span' : tag);
115
+ if (defaults)
116
+ for (const [key, value] of Object.entries(defaults)) {
117
+ if (name !== 'Button' || tag !== 'a' || key !== 'type')
118
+ control.setAttribute(key, value);
119
+ }
120
+ let element = control;
121
+ let host = formScrollHost(name, control) ?? control;
122
+ if (name === 'Carousel.Content' || name === 'HoverCard.Content' || name === 'AspectRatio') {
123
+ element = styleScope.createElement(doc, 'div');
124
+ element.className = name === 'Carousel.Content' ? 'vs-carousel-viewport' : name === 'HoverCard.Content' ? 'vs-hover-positioner' : 'vs-ui-aspect-frame';
125
+ element.append(control);
126
+ }
127
+ else if (name === 'CodeBlock.Content') {
128
+ host = styleScope.createElement(doc, 'code');
129
+ control.append(host);
130
+ }
131
+ else if (name === 'Command.Input') {
132
+ element = styleScope.createElement(doc, 'header');
133
+ element.append(control);
134
+ }
135
+ else if (name === 'Table.Root') {
136
+ element = styleScope.createElement(doc, 'div');
137
+ element.className = 'table-container';
138
+ element.append(control);
139
+ }
140
+ else if (tag === 'dialog') {
141
+ host = styleScope.createElement(doc, 'div');
142
+ control.append(host);
143
+ }
144
+ else if (name === 'Sidebar.Root') {
145
+ host = styleScope.createElement(doc, 'nav');
146
+ control.append(host);
147
+ }
148
+ else if (name === 'Field.Separator' || name === 'Command.Group') {
149
+ host = styleScope.createElement(doc, name === 'Field.Separator' ? 'span' : 'div');
150
+ control.append(host);
151
+ }
152
+ else if (/^(?:DropdownMenu|ContextMenu|Menubar)\.(?:Sub)?Content$/.test(name)) {
153
+ element = styleScope.createElement(doc, 'div');
154
+ element.dataset.vsMenuPositioner = '';
155
+ control.setAttribute('aria-hidden', 'true');
156
+ element.append(control);
157
+ }
158
+ else if (name === 'Select.Content') {
159
+ host = styleScope.createElement(doc, 'div');
160
+ host.setAttribute('role', 'listbox');
161
+ control.append(host);
162
+ }
163
+ if (childAction || childTrigger)
164
+ control.className = 'vs-ui-transparent';
165
+ control.dataset.vsComponent = name;
166
+ control.dataset.vsPart = !definition ? 'group' : name === 'Card.Root' ? 'card' : name.startsWith('Card.') ? name.replace('Card.', 'card-').toLowerCase() : modalRoots.test(name) ? 'dialog-root' : part ? 'dialog-' + part : name.split('.').at(-1).toLowerCase();
167
+ if (part === 'trigger')
168
+ control.dataset.vsModalAction = 'open';
169
+ if (part === 'close' || part === 'cancel')
170
+ control.dataset.vsModalAction = 'close';
171
+ const label = doc.createTextNode('');
172
+ if (!['input', 'img', 'hr'].includes(tag))
173
+ host.prepend(label);
174
+ const entry = { node, name, element, control, host, label, markup, composing: false, events: new AbortController() };
175
+ const { signal } = entry.events;
176
+ if (name === 'Avatar.Image') {
177
+ let pendingStatus;
178
+ const reportImageStatus = (status) => {
179
+ pendingStatus?.disconnect();
180
+ control.toggleAttribute('data-vs-loaded', status === 'loaded');
181
+ const avatar = control.closest('[data-vs-component="Avatar.Root"]');
182
+ if (!avatar)
183
+ return;
184
+ const hover = avatar.closest('[data-vs-component="HoverCard.Content"]');
185
+ const src = control.getAttribute('src');
186
+ const publish = () => {
187
+ if (control.getAttribute('src') === src)
188
+ emitFrom(avatar, 'loadingStatusChange', { value: status });
189
+ };
190
+ if (!hover || hover.dataset.state === 'open' || readInputs(hover).forceMount === true) {
191
+ publish();
192
+ return;
193
+ }
194
+ pendingStatus = new doc.defaultView.MutationObserver(() => {
195
+ if (hover.dataset.state !== 'open')
196
+ return;
197
+ pendingStatus?.disconnect();
198
+ publish();
199
+ });
200
+ pendingStatus.observe(hover, { attributes: true, attributeFilter: ['data-state'] });
201
+ };
202
+ signal.addEventListener('abort', () => pendingStatus?.disconnect(), { once: true });
203
+ control.addEventListener('load', () => reportImageStatus('loaded'), { signal });
204
+ control.addEventListener('error', () => reportImageStatus('error'), { signal });
205
+ }
206
+ const events = contracts.get(node.componentRef ?? '')?.events ?? {};
207
+ const send = (event, payload) => {
208
+ if (!Object.hasOwn(events, event))
209
+ return;
210
+ const source = entry.node;
211
+ // Controllers finish their native event stack before an Action can replace the DOM.
212
+ queueMicrotask(() => {
213
+ if (!signal.aborted && !context.signal.aborted && source.generation === entry.node.generation) {
214
+ void context.emit(event, payload).catch(() => { });
215
+ }
216
+ });
217
+ };
218
+ bindComponent(control, () => entry.node.inputs, send);
219
+ if (childAction || (childTrigger && name === 'Popover.Trigger'))
220
+ control.addEventListener('click', event => {
221
+ if (entry.node.inputs.disabled !== true)
222
+ return;
223
+ event.preventDefault();
224
+ event.stopImmediatePropagation();
225
+ }, { capture: true, signal });
226
+ for (const [eventName, nativeName] of Object.entries(domEvents)) {
227
+ if (!Object.hasOwn(events, eventName))
228
+ continue;
229
+ control.addEventListener(nativeName, event => {
230
+ if (nativeName === 'submit')
231
+ event.preventDefault();
232
+ if (nativeName === 'input' && (entry.composing || event.isComposing))
233
+ return;
234
+ send(eventName, domEvent(event, control));
235
+ }, { signal });
236
+ }
237
+ if (Object.hasOwn(events, 'input') && ['input', 'textarea'].includes(tag)) {
238
+ control.addEventListener('compositionstart', () => { entry.composing = true; }, { signal });
239
+ control.addEventListener('compositionend', event => {
240
+ entry.composing = false;
241
+ send('input', { ...domEvent(event, control), type: 'input' });
242
+ }, { signal });
243
+ }
244
+ if (name === 'Checkbox' || name === 'Switch') {
245
+ const input = control;
246
+ input.addEventListener('change', () => {
247
+ send('checkedChange', { value: input.checked });
248
+ if (entry.node.inputs.indeterminate === true && !input.indeterminate)
249
+ send('indeterminateChange', { value: false });
250
+ }, { signal });
251
+ }
252
+ if (name === 'Collapsible.Trigger' && node.slots.child?.length) {
253
+ control.addEventListener('click', event => {
254
+ if (event.target.closest('button, a, input, select, textarea')) {
255
+ event.preventDefault();
256
+ const details = control.closest('details');
257
+ if (details)
258
+ details.open = !details.open;
259
+ }
260
+ }, { signal });
261
+ }
262
+ if (name === 'InputGroup.Addon') {
263
+ control.addEventListener('click', event => {
264
+ if (!event.defaultPrevented && !event.target.closest('button, a[href]')) {
265
+ control.parentElement?.querySelector(':scope > input')?.focus();
266
+ }
267
+ }, { signal });
268
+ }
269
+ if (name === 'Command.Item' || name === 'Command.LinkItem') {
270
+ control.addEventListener('click', event => {
271
+ if (entry.node.inputs.disabled !== true) {
272
+ send('select', { value: null });
273
+ }
274
+ }, { signal });
275
+ }
276
+ if (name === 'Progress' || name === 'Field.Separator' || name === 'Command.Group') {
277
+ const auxiliary = styleScope.createElement(doc, name === 'Field.Separator' ? 'hr' : 'span');
278
+ if (name === 'Field.Separator')
279
+ auxiliary.setAttribute('role', 'separator');
280
+ if (name === 'Command.Group')
281
+ auxiliary.setAttribute('role', 'heading');
282
+ control.prepend(auxiliary);
283
+ entry.auxiliary = auxiliary;
284
+ }
285
+ if (name === 'Dialog.Content' || name === 'Sheet.Content') {
286
+ const close = styleScope.createElement(doc, 'button');
287
+ close.type = 'button';
288
+ close.className = 'btn vs-dialog-dismiss';
289
+ close.dataset.variant = 'ghost';
290
+ close.dataset.size = 'icon-sm';
291
+ close.dataset.vsModalAction = 'close';
292
+ close.setAttribute('aria-label', 'Close');
293
+ host.append(close);
294
+ entry.auxiliary = close;
295
+ }
296
+ if (name === 'Drawer.Content') {
297
+ const handle = styleScope.createElement(doc, 'div');
298
+ handle.className = 'vs-drawer-handle';
299
+ handle.setAttribute('aria-hidden', 'true');
300
+ host.append(handle);
301
+ }
302
+ const enhancement = name === 'Command.Dialog'
303
+ ? commandDialog(control, host, send, signal)
304
+ : behavior(name, control, send, signal);
305
+ if (enhancement)
306
+ entry.behavior = enhancement;
307
+ return entry;
308
+ }
309
+ function update(entry, node) {
310
+ entry.node = node;
311
+ const { control, host, label, name, markup, auxiliary } = entry;
312
+ const { inputs } = node;
313
+ const descendants = components.has(name) ? node.slots.child?.length ? node.slots.child : node.slots.default ?? [] : node.children;
314
+ const defaultText = name === 'Breadcrumb.Ellipsis' || name === 'Pagination.Ellipsis' ? '…'
315
+ : name === 'Breadcrumb.Separator' ? '›'
316
+ : name === 'Pagination.NextButton' || name === 'Pagination.Next' ? 'Next'
317
+ : name === 'Pagination.PrevButton' || name === 'Pagination.Previous' ? 'Previous'
318
+ : name === 'Pagination.Link' && inputs.page && typeof inputs.page === 'object' && 'value' in inputs.page ? String(inputs.page.value)
319
+ : name === 'Select.Value' && typeof inputs.placeholder === 'string' ? inputs.placeholder : '';
320
+ const shortcutRef = labelledMenuParts.test(name) ? 'shadcn.' + name.split('.')[0] + '.Shortcut' : undefined;
321
+ const replacesLabel = descendants.length && (!shortcutRef || descendants.some(child => child.componentRef !== shortcutRef));
322
+ const content = replacesLabel ? ''
323
+ : typeof inputs.text === 'string' ? inputs.text : defaultText;
324
+ if (label.data !== content)
325
+ label.data = content;
326
+ const [, className, defaults] = markup;
327
+ const activeCommand = (name === 'Command.Item' || name === 'Command.LinkItem') && control.classList.contains('active');
328
+ const combined = [node.slots.child?.length && (modalParts.test(name) || (/^(?:DropdownMenu|HoverCard|Tooltip|Popover)\.Trigger$/.test(name) || name === 'Popover.Close')) ? 'vs-ui-transparent' : className,
329
+ inputs.class, activeCommand && 'active'].filter(Boolean).join(' ');
330
+ if (control.className !== combined)
331
+ control.className = combined;
332
+ for (const key of attributes) {
333
+ if (key === 'class' || !Object.hasOwn(inputs, key))
334
+ continue;
335
+ const value = key === 'href' || key === 'src' ? safeUrl(control, inputs[key], name === 'Attachment.Action' && key === 'href' && (inputs.download === true || typeof inputs.download === 'string')) : inputs[key];
336
+ if (name === 'Avatar.Image' && key === 'src' && control.getAttribute('src') !== value)
337
+ delete control.dataset.vsLoaded;
338
+ setAttribute(control, key, value, defaults?.[key]);
339
+ }
340
+ for (const key of attributes) {
341
+ if (key === 'class' || Object.hasOwn(inputs, key))
342
+ continue;
343
+ if (entry.control.dataset.vsManaged?.split(' ').includes(key))
344
+ setAttribute(control, key, undefined, defaults?.[key]);
345
+ }
346
+ control.dataset.vsManaged = [...attributes].filter(key => key !== 'class' && Object.hasOwn(inputs, key)).join(' ');
347
+ if (control.localName === 'button') {
348
+ const button = control;
349
+ button.type = inputs.type === 'submit' || inputs.type === 'reset' ? inputs.type : 'button';
350
+ if (control.dataset.vsModalAction === 'open')
351
+ button.setAttribute('aria-haspopup', 'dialog');
352
+ }
353
+ for (const key of ['variant', 'size', 'orientation', 'align']) {
354
+ const value = key === 'variant' && inputs.variant === 'default' && (name === 'Button' || name === 'InputGroup.Button') ? 'primary'
355
+ : key === 'size' && inputs.size === 'default' ? undefined : inputs[key];
356
+ setAttribute(control, 'data-' + key, value, defaults?.['data-' + key]);
357
+ }
358
+ if (typeof inputs.value === 'string' && !['input', 'select', 'textarea', 'option'].includes(control.localName)) {
359
+ control.dataset.value = inputs.value;
360
+ }
361
+ else
362
+ delete control.dataset.value;
363
+ if (name === 'Select.Item')
364
+ setAttribute(control, 'data-label', inputs.label);
365
+ if (name === 'Command.Item' || name === 'Command.LinkItem') {
366
+ setAttribute(control, 'data-keywords', Array.isArray(inputs.keywords) ? inputs.keywords.join(',') : undefined);
367
+ }
368
+ if (name === 'Command.Group' && auxiliary) {
369
+ auxiliary.textContent = typeof inputs.heading === 'string' ? inputs.heading : '';
370
+ auxiliary.hidden = !auxiliary.textContent;
371
+ }
372
+ if (name === 'Sidebar.MenuButton' || name === 'Sidebar.MenuSubButton') {
373
+ setAttribute(control, 'data-active', inputs.isActive);
374
+ }
375
+ if (typeof inputs.disabled === 'boolean' && ['summary', 'details', 'div'].includes(control.localName)) {
376
+ control.setAttribute('aria-disabled', String(inputs.disabled));
377
+ }
378
+ if (control.localName === 'span' && (control.dataset.vsModalAction || name === 'Popover.Trigger')) {
379
+ control.inert = inputs.disabled === true || inputs.inert === true;
380
+ if (inputs.disabled === true)
381
+ control.setAttribute('aria-disabled', 'true');
382
+ else if (inputs['aria-disabled'] === undefined)
383
+ control.removeAttribute('aria-disabled');
384
+ }
385
+ const fieldValue = inputs.value === null ? '' : typeof inputs.value === 'number' ? String(inputs.value) : inputs.value;
386
+ if (control.localName === 'input') {
387
+ const input = control;
388
+ if (name === 'Checkbox' || name === 'Switch' || name === 'RadioGroup.Item') {
389
+ if (typeof inputs.checked === 'boolean')
390
+ input.checked = inputs.checked;
391
+ if (name === 'Checkbox')
392
+ input.indeterminate = inputs.indeterminate === true;
393
+ setAttribute(input, 'value', inputs.value);
394
+ }
395
+ else if (name !== 'Slider') {
396
+ const type = typeof inputs.type === 'string' ? inputs.type : 'text';
397
+ if (input.type !== type)
398
+ input.type = type;
399
+ if (!entry.composing && typeof fieldValue === 'string' && input.value !== fieldValue && type !== 'file')
400
+ input.value = fieldValue;
401
+ }
402
+ }
403
+ if (control.localName === 'textarea' && !entry.composing && typeof fieldValue === 'string') {
404
+ const textarea = control;
405
+ if (textarea.value !== fieldValue)
406
+ textarea.value = fieldValue;
407
+ }
408
+ if (control.localName === 'option') {
409
+ setAttribute(control, 'value', inputs.value);
410
+ setAttribute(control, 'selected', inputs.selected);
411
+ }
412
+ if (name === 'Card.Title' || name.endsWith('Dialog.Title') || name === 'Drawer.Title')
413
+ control.dataset.title = '';
414
+ if (name === 'Card.Description' || name.endsWith('Dialog.Description') || name === 'Drawer.Description')
415
+ control.dataset.description = '';
416
+ if (name === 'Pagination.Link' && inputs.page && typeof inputs.page === 'object') {
417
+ control.dataset.vsPage = String(inputs.page.value);
418
+ }
419
+ if (/^Pagination\.(Next|Prev)/.test(name))
420
+ control.dataset.vsPage ||= '1';
421
+ if (name === 'Separator') {
422
+ setAttribute(control, 'role', inputs.decorative === false ? 'separator' : 'none');
423
+ }
424
+ if (name === 'Sonner' || name === 'Notifications')
425
+ setAttribute(control, 'aria-label', inputs.containerAriaLabel);
426
+ if (name === 'Sidebar.Root')
427
+ setAttribute(control, 'data-collapsible', inputs.collapsible);
428
+ if (name === 'Field.Separator')
429
+ host.hidden = !content && !descendants.length;
430
+ if ((name === 'Dialog.Content' || name === 'Sheet.Content') && auxiliary)
431
+ auxiliary.hidden = inputs.showCloseButton === false;
432
+ if (name === 'Sheet.Content')
433
+ control.dataset.side = typeof inputs.side === 'string' ? inputs.side : 'right';
434
+ if (name === 'Progress' && auxiliary) {
435
+ const value = Number(inputs.value ?? 0);
436
+ const max = Number(inputs.max ?? 100);
437
+ setAttribute(control, 'aria-valuemax', max);
438
+ setAttribute(control, 'aria-valuenow', value);
439
+ auxiliary.style.width = `${Math.max(0, Math.min(100, value / (max || 1) * 100))}%`;
440
+ }
441
+ if (name === 'Chart.Container' && inputs.config && typeof inputs.config === 'object') {
442
+ const config = inputs.config;
443
+ for (const key of Array.from(control.style))
444
+ if (key.startsWith('--color-'))
445
+ control.style.removeProperty(key);
446
+ for (const [key, { color }] of Object.entries(config)) {
447
+ if (/^[\w-]+$/.test(key) && color && doc.defaultView?.CSS.supports('color', color)) {
448
+ control.style.setProperty('--color-' + key, scopeChartColor(color));
449
+ }
450
+ }
451
+ }
452
+ }
453
+ function afterChildren(entry) {
454
+ const { control, name, node: { inputs } } = entry;
455
+ if (name === 'Tooltip.Root') {
456
+ const trigger = control.querySelector('[data-vs-component="Tooltip.Trigger"]');
457
+ const tooltip = control.querySelector('[data-vs-component="Tooltip.Content"]');
458
+ if (trigger && tooltip) {
459
+ tooltip.id ||= uniqueId();
460
+ (trigger.classList.contains('vs-ui-transparent') ? trigger.querySelector(':scope > *') ?? trigger : trigger).setAttribute('aria-describedby', tooltip.id);
461
+ }
462
+ }
463
+ if (name === 'NativeSelect.Root' && inputs.value !== undefined) {
464
+ const select = control;
465
+ const values = (Array.isArray(inputs.value) ? inputs.value : [inputs.value])
466
+ .filter(value => typeof value === 'string' || typeof value === 'number').map(String);
467
+ if (select.multiple) {
468
+ for (const option of select.options)
469
+ option.selected = values.includes(option.value);
470
+ }
471
+ else
472
+ select.selectedIndex = Array.from(select.options).findIndex(option => values.includes(option.value));
473
+ }
474
+ entry.behavior?.sync(inputs);
475
+ }
476
+ let entry;
477
+ let withdraw;
478
+ let slotName;
479
+ const release = () => {
480
+ withdraw?.();
481
+ withdraw = undefined;
482
+ slotName = undefined;
483
+ if (entry)
484
+ disposeEntry(entry);
485
+ entry = undefined;
486
+ };
487
+ function render(node) {
488
+ if (/\.Portal$/.test(name)) {
489
+ if (!withdraw && Object.hasOwn(node.slots, 'default'))
490
+ withdraw = context.provideSlot('default', context.parent);
491
+ return;
492
+ }
493
+ const nextTag = markupTag(name, node.inputs);
494
+ if (entry && (!!entry.node.slots.child?.length !== !!node.slots.child?.length
495
+ || (nextTag !== undefined && !entry.node.slots.child?.length && entry.control.localName !== nextTag)))
496
+ release();
497
+ if (!entry) {
498
+ entry = createEntry(node);
499
+ context.parent.insertBefore(entry.element, context.anchor);
500
+ }
501
+ const nextSlot = node.slots.child?.length ? 'child'
502
+ : Object.hasOwn(node.slots, 'default') ? 'default' : undefined;
503
+ if (slotName !== nextSlot) {
504
+ withdraw?.();
505
+ slotName = nextSlot;
506
+ withdraw = nextSlot === undefined ? undefined : context.provideSlot(nextSlot, entry.host, entry.host.firstElementChild);
507
+ }
508
+ update(entry, node);
509
+ }
510
+ try {
511
+ render(context.node);
512
+ }
513
+ catch (cause) {
514
+ release();
515
+ throw cause;
516
+ }
517
+ return {
518
+ update: render,
519
+ setPending(pending) {
520
+ if (!entry)
521
+ return;
522
+ if (pending)
523
+ entry.element.setAttribute('aria-busy', 'true');
524
+ else
525
+ entry.element.removeAttribute('aria-busy');
526
+ },
527
+ afterChildren() { if (entry)
528
+ afterChildren(entry); },
529
+ dispose: release,
530
+ };
531
+ } };
532
+ }
@@ -0,0 +1,2 @@
1
+ import { type Behavior, type Send } from './behaviors.js';
2
+ export declare function dataTable(element: HTMLElement, send: Send, signal: AbortSignal): Behavior;