@getcortexlabs/mavis-core 0.1.0-alpha.8 → 0.1.0-rc.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/capabilities.d.ts +7 -7
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +30 -4
- package/dist/capabilities.js.map +1 -1
- package/dist/chart.d.ts +43 -0
- package/dist/chart.d.ts.map +1 -0
- package/dist/chart.js +105 -0
- package/dist/chart.js.map +1 -0
- package/dist/collections.d.ts +46 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +48 -0
- package/dist/collections.js.map +1 -0
- package/dist/contracts.d.ts +20 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +2 -0
- package/dist/contracts.js.map +1 -1
- package/dist/date-input.d.ts +10 -0
- package/dist/date-input.d.ts.map +1 -0
- package/dist/date-input.js +58 -0
- package/dist/date-input.js.map +1 -0
- package/dist/date-time.d.ts +19 -0
- package/dist/date-time.d.ts.map +1 -0
- package/dist/date-time.js +27 -0
- package/dist/date-time.js.map +1 -0
- package/dist/discovery.d.ts +49 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +80 -0
- package/dist/discovery.js.map +1 -0
- package/dist/experimental-regions.d.ts +10 -0
- package/dist/experimental-regions.d.ts.map +1 -1
- package/dist/experimental-regions.js +23 -0
- package/dist/experimental-regions.js.map +1 -1
- package/dist/experimental.d.ts +5 -0
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +29 -0
- package/dist/experimental.js.map +1 -1
- package/dist/grid.d.ts +3 -0
- package/dist/grid.d.ts.map +1 -0
- package/dist/grid.js +16 -0
- package/dist/grid.js.map +1 -0
- package/dist/index.d.ts +17 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/input.d.ts +4 -0
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js.map +1 -1
- package/dist/interactive.d.ts +36 -0
- package/dist/interactive.d.ts.map +1 -0
- package/dist/interactive.js +61 -0
- package/dist/interactive.js.map +1 -0
- package/dist/link.d.ts +24 -0
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +41 -0
- package/dist/link.js.map +1 -1
- package/dist/motion.d.ts +8 -0
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +11 -0
- package/dist/motion.js.map +1 -1
- package/dist/navigation-transition.d.ts +10 -0
- package/dist/navigation-transition.d.ts.map +1 -0
- package/dist/navigation-transition.js +10 -0
- package/dist/navigation-transition.js.map +1 -0
- package/dist/number-flow-format.d.ts +16 -0
- package/dist/number-flow-format.d.ts.map +1 -0
- package/dist/number-flow-format.js +49 -0
- package/dist/number-flow-format.js.map +1 -0
- package/dist/popover.d.ts +17 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/popover.js +19 -0
- package/dist/popover.js.map +1 -0
- package/dist/section-scroll.d.ts +14 -0
- package/dist/section-scroll.d.ts.map +1 -0
- package/dist/section-scroll.js +28 -0
- package/dist/section-scroll.js.map +1 -0
- package/dist/sheet.d.ts +7 -0
- package/dist/sheet.d.ts.map +1 -1
- package/dist/time.d.ts +34 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +78 -0
- package/dist/time.js.map +1 -0
- package/dist/vue/carousel.d.ts +13 -0
- package/dist/vue/carousel.d.ts.map +1 -0
- package/dist/vue/carousel.js +136 -0
- package/dist/vue/carousel.js.map +1 -0
- package/dist/vue/chart.d.ts +194 -0
- package/dist/vue/chart.d.ts.map +1 -0
- package/dist/vue/chart.js +245 -0
- package/dist/vue/chart.js.map +1 -0
- package/dist/vue/command-palette.d.ts +129 -0
- package/dist/vue/command-palette.d.ts.map +1 -0
- package/dist/vue/command-palette.js +190 -0
- package/dist/vue/command-palette.js.map +1 -0
- package/dist/vue/component-motion.d.ts +17 -0
- package/dist/vue/component-motion.d.ts.map +1 -0
- package/dist/vue/component-motion.js +83 -0
- package/dist/vue/component-motion.js.map +1 -0
- package/dist/vue/component-props.d.ts +1505 -402
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +28 -0
- package/dist/vue/component-props.js.map +1 -1
- package/dist/vue/configurator-props.d.ts +21 -0
- package/dist/vue/configurator-props.d.ts.map +1 -1
- package/dist/vue/configurator-props.js +6 -0
- package/dist/vue/configurator-props.js.map +1 -1
- package/dist/vue/configurator.d.ts +3 -3
- package/dist/vue/configurator.d.ts.map +1 -1
- package/dist/vue/configurator.js +3 -1
- package/dist/vue/configurator.js.map +1 -1
- package/dist/vue/data-table.d.ts +17 -0
- package/dist/vue/data-table.d.ts.map +1 -0
- package/dist/vue/data-table.js +133 -0
- package/dist/vue/data-table.js.map +1 -0
- package/dist/vue/date-calendar.d.ts +2 -0
- package/dist/vue/date-calendar.d.ts.map +1 -1
- package/dist/vue/date-calendar.js +20 -1
- package/dist/vue/date-calendar.js.map +1 -1
- package/dist/vue/date-picker.d.ts +48 -13
- package/dist/vue/date-picker.d.ts.map +1 -1
- package/dist/vue/date-picker.js +67 -74
- package/dist/vue/date-picker.js.map +1 -1
- package/dist/vue/date-props.d.ts +15 -0
- package/dist/vue/date-props.d.ts.map +1 -1
- package/dist/vue/date-props.js +4 -0
- package/dist/vue/date-props.js.map +1 -1
- package/dist/vue/discovery-components.d.ts +50 -0
- package/dist/vue/discovery-components.d.ts.map +1 -0
- package/dist/vue/discovery-components.js +2 -0
- package/dist/vue/discovery-components.js.map +1 -0
- package/dist/vue/discovery-controls.d.ts +197 -0
- package/dist/vue/discovery-controls.d.ts.map +1 -0
- package/dist/vue/discovery-controls.js +185 -0
- package/dist/vue/discovery-controls.js.map +1 -0
- package/dist/vue/discovery-props.d.ts +249 -0
- package/dist/vue/discovery-props.d.ts.map +1 -0
- package/dist/vue/discovery-props.js +87 -0
- package/dist/vue/discovery-props.js.map +1 -0
- package/dist/vue/global-components.d.ts +134 -2
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +27 -1
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +23 -1
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/interactive-components.d.ts +31 -0
- package/dist/vue/interactive-components.d.ts.map +1 -0
- package/dist/vue/interactive-components.js +2 -0
- package/dist/vue/interactive-components.js.map +1 -0
- package/dist/vue/interactive-props.d.ts +254 -0
- package/dist/vue/interactive-props.d.ts.map +1 -0
- package/dist/vue/interactive-props.js +85 -0
- package/dist/vue/interactive-props.js.map +1 -0
- package/dist/vue/list-motion.d.ts +7 -0
- package/dist/vue/list-motion.d.ts.map +1 -0
- package/dist/vue/list-motion.js +28 -0
- package/dist/vue/list-motion.js.map +1 -0
- package/dist/vue/menu.d.ts +122 -0
- package/dist/vue/menu.d.ts.map +1 -0
- package/dist/vue/menu.js +79 -0
- package/dist/vue/menu.js.map +1 -0
- package/dist/vue/navigation-controls.d.ts +125 -0
- package/dist/vue/navigation-controls.d.ts.map +1 -0
- package/dist/vue/navigation-controls.js +130 -0
- package/dist/vue/navigation-controls.js.map +1 -0
- package/dist/vue/navigation-props.d.ts +283 -0
- package/dist/vue/navigation-props.d.ts.map +1 -0
- package/dist/vue/navigation-props.js +82 -0
- package/dist/vue/navigation-props.js.map +1 -0
- package/dist/vue/navigation.d.ts +7 -0
- package/dist/vue/navigation.d.ts.map +1 -0
- package/dist/vue/navigation.js +15 -0
- package/dist/vue/navigation.js.map +1 -0
- package/dist/vue/number-flow.d.ts +75 -0
- package/dist/vue/number-flow.d.ts.map +1 -0
- package/dist/vue/number-flow.js +57 -0
- package/dist/vue/number-flow.js.map +1 -0
- package/dist/vue/partition.d.ts +15 -0
- package/dist/vue/partition.d.ts.map +1 -0
- package/dist/vue/partition.js +42 -0
- package/dist/vue/partition.js.map +1 -0
- package/dist/vue/platform.d.ts +37 -0
- package/dist/vue/platform.d.ts.map +1 -0
- package/dist/vue/platform.js +46 -0
- package/dist/vue/platform.js.map +1 -0
- package/dist/vue/props.d.ts +233 -36
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +15 -1
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/sortable-list.d.ts +24 -0
- package/dist/vue/sortable-list.d.ts.map +1 -0
- package/dist/vue/sortable-list.js +251 -0
- package/dist/vue/sortable-list.js.map +1 -0
- package/dist/vue/swipe-actions.d.ts +96 -0
- package/dist/vue/swipe-actions.d.ts.map +1 -0
- package/dist/vue/swipe-actions.js +174 -0
- package/dist/vue/swipe-actions.js.map +1 -0
- package/dist/vue/time-picker.d.ts +488 -0
- package/dist/vue/time-picker.d.ts.map +1 -0
- package/dist/vue/time-picker.js +190 -0
- package/dist/vue/time-picker.js.map +1 -0
- package/dist/vue/tree-view.d.ts +111 -0
- package/dist/vue/tree-view.d.ts.map +1 -0
- package/dist/vue/tree-view.js +204 -0
- package/dist/vue/tree-view.js.map +1 -0
- package/dist/vue/virtual-list.d.ts +26 -0
- package/dist/vue/virtual-list.d.ts.map +1 -0
- package/dist/vue/virtual-list.js +2 -0
- package/dist/vue/virtual-list.js.map +1 -0
- package/dist/vue/wayfinding-controls.d.ts +199 -0
- package/dist/vue/wayfinding-controls.d.ts.map +1 -0
- package/dist/vue/wayfinding-controls.js +330 -0
- package/dist/vue/wayfinding-controls.js.map +1 -0
- package/dist/vue/wayfinding-props.d.ts +221 -0
- package/dist/vue/wayfinding-props.d.ts.map +1 -0
- package/dist/vue/wayfinding-props.js +86 -0
- package/dist/vue/wayfinding-props.js.map +1 -0
- package/dist/vue/workflows.d.ts +2 -2
- package/dist/vue/workflows.d.ts.map +1 -1
- package/dist/vue/workflows.js +17 -4
- package/dist/vue/workflows.js.map +1 -1
- package/dist/wayfinding.d.ts +50 -0
- package/dist/wayfinding.d.ts.map +1 -0
- package/dist/wayfinding.js +54 -0
- package/dist/wayfinding.js.map +1 -0
- package/package.json +2 -2
- package/src/capabilities.ts +31 -4
- package/src/chart.ts +151 -0
- package/src/collections.ts +87 -0
- package/src/contracts.ts +2 -0
- package/src/date-input.ts +87 -0
- package/src/date-time.ts +37 -0
- package/src/discovery.ts +139 -0
- package/src/experimental-regions.ts +29 -0
- package/src/experimental.ts +40 -0
- package/src/grid.ts +19 -0
- package/src/index.ts +24 -3
- package/src/input.ts +5 -0
- package/src/interactive.ts +91 -0
- package/src/link.ts +63 -0
- package/src/motion.ts +14 -0
- package/src/navigation-transition.ts +14 -0
- package/src/number-flow-format.ts +68 -0
- package/src/popover.ts +38 -0
- package/src/section-scroll.ts +46 -0
- package/src/sheet.ts +11 -0
- package/src/time.ts +83 -0
- package/src/vue/carousel.ts +198 -0
- package/src/vue/chart.ts +337 -0
- package/src/vue/command-palette.ts +235 -0
- package/src/vue/component-motion.ts +109 -0
- package/src/vue/component-props.ts +57 -0
- package/src/vue/configurator-props.ts +6 -0
- package/src/vue/configurator.ts +3 -1
- package/src/vue/data-table.ts +190 -0
- package/src/vue/date-calendar.ts +30 -1
- package/src/vue/date-picker.ts +81 -85
- package/src/vue/date-props.ts +5 -0
- package/src/vue/discovery-components.ts +60 -0
- package/src/vue/discovery-controls.ts +241 -0
- package/src/vue/discovery-props.ts +92 -0
- package/src/vue/global-components.ts +124 -2
- package/src/vue/index.ts +46 -0
- package/src/vue/interactive-components.ts +29 -0
- package/src/vue/interactive-props.ts +90 -0
- package/src/vue/list-motion.ts +31 -0
- package/src/vue/menu.ts +100 -0
- package/src/vue/navigation-controls.ts +159 -0
- package/src/vue/navigation-props.ts +87 -0
- package/src/vue/navigation.ts +16 -0
- package/src/vue/number-flow.ts +83 -0
- package/src/vue/partition.ts +49 -0
- package/src/vue/platform.ts +73 -0
- package/src/vue/props.ts +16 -1
- package/src/vue/sortable-list.ts +308 -0
- package/src/vue/swipe-actions.ts +226 -0
- package/src/vue/time-picker.ts +227 -0
- package/src/vue/tree-view.ts +259 -0
- package/src/vue/virtual-list.ts +28 -0
- package/src/vue/wayfinding-controls.ts +430 -0
- package/src/vue/wayfinding-props.ts +97 -0
- package/src/vue/workflows.ts +17 -4
- package/src/wayfinding.ts +85 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { collectionKeys } from './discovery.js';
|
|
2
|
+
import { linkDestination } from './link.js';
|
|
3
|
+
import { validateNavigation } from './collections.js';
|
|
4
|
+
const searchable = (value) => value
|
|
5
|
+
.normalize('NFD')
|
|
6
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
7
|
+
.toLowerCase();
|
|
8
|
+
export function filterCommands(items, query) {
|
|
9
|
+
collectionKeys(items, 'value');
|
|
10
|
+
for (const item of items)
|
|
11
|
+
if (!item.label.trim())
|
|
12
|
+
throw new TypeError('Commands require labels.');
|
|
13
|
+
const terms = searchable(query.trim()).split(/\s+/).filter(Boolean);
|
|
14
|
+
return items.filter((item) => {
|
|
15
|
+
const haystack = searchable([item.label, item.description, item.group, ...(item.keywords ?? [])]
|
|
16
|
+
.filter(Boolean)
|
|
17
|
+
.join(' '));
|
|
18
|
+
return terms.every((term) => haystack.includes(term));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export function validateRail(groups) {
|
|
22
|
+
collectionKeys(groups, 'key');
|
|
23
|
+
for (const group of groups)
|
|
24
|
+
if (!group.label.trim())
|
|
25
|
+
throw new TypeError('Navigation groups require labels.');
|
|
26
|
+
validateNavigation(groups.flatMap((group) => group.items));
|
|
27
|
+
}
|
|
28
|
+
export function breadcrumbParts(items, maxItems) {
|
|
29
|
+
collectionKeys(items, 'key');
|
|
30
|
+
if (!Number.isInteger(maxItems) || maxItems < 2)
|
|
31
|
+
throw new RangeError('Breadcrumb maxItems must be an integer of at least 2.');
|
|
32
|
+
items.forEach((item, index) => {
|
|
33
|
+
if (!item.label.trim())
|
|
34
|
+
throw new TypeError('Breadcrumb entries require labels.');
|
|
35
|
+
if (index < items.length - 1 && !item.href)
|
|
36
|
+
throw new TypeError('Breadcrumb ancestors require destinations.');
|
|
37
|
+
if (item.href !== undefined)
|
|
38
|
+
linkDestination(item.href);
|
|
39
|
+
});
|
|
40
|
+
if (items.length <= maxItems)
|
|
41
|
+
return { before: items, hidden: [], after: [] };
|
|
42
|
+
const split = items.length - maxItems + 1;
|
|
43
|
+
return { before: items.slice(0, 1), hidden: items.slice(1, split), after: items.slice(split) };
|
|
44
|
+
}
|
|
45
|
+
export function validateTimeline(items) {
|
|
46
|
+
collectionKeys(items, 'key');
|
|
47
|
+
for (const item of items) {
|
|
48
|
+
if (!item.title.trim())
|
|
49
|
+
throw new TypeError('Timeline entries require titles.');
|
|
50
|
+
if (item.status && !['complete', 'current', 'upcoming', 'error'].includes(item.status))
|
|
51
|
+
throw new TypeError('Unknown timeline status.');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=wayfinding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wayfinding.js","sourceRoot":"","sources":["../src/wayfinding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,EAAE,eAAe,EAAqB,MAAM,WAAW,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAuB,MAAM,kBAAkB,CAAA;AAa1E,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE,CACnC,KAAK;KACF,SAAS,CAAC,KAAK,CAAC;KAChB,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;KAC/B,WAAW,EAAE,CAAA;AAClB,MAAM,UAAU,cAAc,CAAC,KAA6B,EAAE,KAAa;IACzE,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC9B,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAA;IACjG,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACnE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAG,UAAU,CACzB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;aACjE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,CACb,CAAA;QACD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;AACJ,CAAC;AAMD,MAAM,UAAU,YAAY,CAAC,MAAkC;IAC7D,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IAC7B,KAAK,MAAM,KAAK,IAAI,MAAM;QACxB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAA;IACnF,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;AAC5D,CAAC;AAQD,MAAM,UAAU,eAAe,CAAC,KAAgC,EAAE,QAAgB;IAChF,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC5B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC;QAC7C,MAAM,IAAI,UAAU,CAAC,uDAAuD,CAAC,CAAA;IAC/E,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAA;QACjF,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YACxC,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAA;QACnE,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YAAE,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzD,CAAC,CAAC,CAAA;IACF,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;IAC7E,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,QAAQ,GAAG,CAAC,CAAA;IACzC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAA;AAChG,CAAC;AAWD,MAAM,UAAU,gBAAgB,CAAC,KAA8B;IAC7D,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,SAAS,CAAC,kCAAkC,CAAC,CAAA;QAC/E,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;YACpF,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAA;IACnD,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getcortexlabs/mavis-core",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-rc.11.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Shared Mavis themes and component contracts.",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public",
|
|
51
|
-
"tag": "
|
|
51
|
+
"tag": "rc",
|
|
52
52
|
"registry": "https://registry.npmjs.org/"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
package/src/capabilities.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
/** Source capabilities, not a promise that every feature is in the last npm release. */
|
|
2
2
|
export const componentNames = [
|
|
3
|
+
'MSortableList',
|
|
4
|
+
'MSwipeActions',
|
|
5
|
+
'MNumberFlow',
|
|
6
|
+
'MResizablePanels',
|
|
7
|
+
'MImageCompare',
|
|
8
|
+
'MImageViewer',
|
|
9
|
+
|
|
3
10
|
'MScreen',
|
|
4
11
|
'MRow',
|
|
5
12
|
'MColumn',
|
|
6
13
|
'MStack',
|
|
14
|
+
'MGrid',
|
|
7
15
|
'MLink',
|
|
8
16
|
'MBox',
|
|
9
17
|
'MCard',
|
|
10
18
|
'MText',
|
|
11
19
|
'MSpan',
|
|
12
20
|
'MThemeProvider',
|
|
21
|
+
'MPlatform',
|
|
13
22
|
'MIcon',
|
|
14
23
|
'MButton',
|
|
15
24
|
'MInput',
|
|
@@ -45,6 +54,24 @@ export const componentNames = [
|
|
|
45
54
|
'MFormErrors',
|
|
46
55
|
'MSteps',
|
|
47
56
|
'MPagination',
|
|
57
|
+
'MPopover',
|
|
58
|
+
'MMenu',
|
|
59
|
+
'MAppBar',
|
|
60
|
+
'MTabBar',
|
|
61
|
+
'MTimePicker',
|
|
62
|
+
'MVirtualList',
|
|
63
|
+
'MDataTable',
|
|
64
|
+
'MCarousel',
|
|
65
|
+
'MRangeSlider',
|
|
66
|
+
'MCalendar',
|
|
67
|
+
'MRating',
|
|
68
|
+
'MTreeView',
|
|
69
|
+
'MCommandPalette',
|
|
70
|
+
'MNavigationRail',
|
|
71
|
+
'MBreadcrumb',
|
|
72
|
+
'MTooltip',
|
|
73
|
+
'MTimeline',
|
|
74
|
+
'MChart',
|
|
48
75
|
] as const
|
|
49
76
|
export type ComponentName = (typeof componentNames)[number]
|
|
50
77
|
export type CapabilityStatus = 'experimental' | 'planned' | 'unsupported' | 'unverified'
|
|
@@ -52,11 +79,11 @@ export type CapabilityStatus = 'experimental' | 'planned' | 'unsupported' | 'unv
|
|
|
52
79
|
export const targetCapabilities = {
|
|
53
80
|
version: 1,
|
|
54
81
|
source: 'repository',
|
|
55
|
-
publishedBaseline: '0.1.0-
|
|
82
|
+
publishedBaseline: '0.1.0-rc.11.1',
|
|
56
83
|
developmentMotion: {
|
|
57
84
|
availability: 'published',
|
|
58
85
|
joltCommit: null,
|
|
59
|
-
publishedJoltRelease: '0.1.0-rc.
|
|
86
|
+
publishedJoltRelease: '0.1.0-rc.11',
|
|
60
87
|
features: {
|
|
61
88
|
gradient: ['web', 'ios', 'android'],
|
|
62
89
|
loadingEffects: ['web', 'ios'],
|
|
@@ -82,7 +109,7 @@ export const targetCapabilities = {
|
|
|
82
109
|
streaming: 'unverified',
|
|
83
110
|
rsc: 'unsupported',
|
|
84
111
|
},
|
|
85
|
-
motion: { engine: 'jolt', minimum: '0.1.0-rc.
|
|
112
|
+
motion: { engine: 'jolt', minimum: '0.1.0-rc.11', start: 'client-mount' },
|
|
86
113
|
ssr: {
|
|
87
114
|
availability: '0.1.0-alpha.5',
|
|
88
115
|
host: 'nuxt',
|
|
@@ -125,7 +152,7 @@ export const targetCapabilities = {
|
|
|
125
152
|
streaming: 'unsupported',
|
|
126
153
|
rsc: 'unsupported',
|
|
127
154
|
},
|
|
128
|
-
motion: { engine: 'jolt', minimum: '0.1.0-rc.
|
|
155
|
+
motion: { engine: 'jolt', minimum: '0.1.0-rc.11', start: 'native-loaded' },
|
|
129
156
|
},
|
|
130
157
|
],
|
|
131
158
|
planned: [
|
package/src/chart.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { collectionKeys } from './discovery.js'
|
|
2
|
+
import type { ChoiceValue } from './choice.js'
|
|
3
|
+
|
|
4
|
+
export interface ChartCategory {
|
|
5
|
+
key: ChoiceValue
|
|
6
|
+
label: string
|
|
7
|
+
}
|
|
8
|
+
export interface ChartSeries {
|
|
9
|
+
key: ChoiceValue
|
|
10
|
+
label: string
|
|
11
|
+
values: readonly (number | null)[]
|
|
12
|
+
/** A shared CSS/native hex color; the theme supplies defaults. */
|
|
13
|
+
color?: string
|
|
14
|
+
}
|
|
15
|
+
export interface ChartSelection {
|
|
16
|
+
category: ChoiceValue
|
|
17
|
+
series: ChoiceValue
|
|
18
|
+
}
|
|
19
|
+
export interface ChartPoint {
|
|
20
|
+
key?: ChoiceValue
|
|
21
|
+
x: number
|
|
22
|
+
y: number
|
|
23
|
+
value: number
|
|
24
|
+
index: number
|
|
25
|
+
}
|
|
26
|
+
export interface ChartGeometry {
|
|
27
|
+
min: number
|
|
28
|
+
max: number
|
|
29
|
+
zero: number
|
|
30
|
+
ticks: readonly number[]
|
|
31
|
+
series: readonly { key: ChoiceValue; points: readonly (ChartPoint | null)[] }[]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Hit testing uses normalized plot coordinates, independent of DOM/native geometry. */
|
|
35
|
+
export function chartHitTest(geometry: ChartGeometry, type: 'line' | 'bar', x: number, y: number) {
|
|
36
|
+
const count = geometry.series[0]?.points.length ?? 0
|
|
37
|
+
if (!count || !Number.isFinite(x) || !Number.isFinite(y)) return null
|
|
38
|
+
const category = Math.max(0, Math.min(count - 1, Math.floor(x * count)))
|
|
39
|
+
if (type === 'bar') {
|
|
40
|
+
const within = x * count - category
|
|
41
|
+
const series = Math.max(
|
|
42
|
+
0,
|
|
43
|
+
Math.min(
|
|
44
|
+
geometry.series.length - 1,
|
|
45
|
+
Math.floor(((within - 0.15) / 0.7) * geometry.series.length),
|
|
46
|
+
),
|
|
47
|
+
)
|
|
48
|
+
return geometry.series[series]?.points[category] ? { category, series } : null
|
|
49
|
+
}
|
|
50
|
+
let nearest = -1,
|
|
51
|
+
distance = Infinity
|
|
52
|
+
geometry.series.forEach((series, index) => {
|
|
53
|
+
const point = series.points[category]
|
|
54
|
+
if (point && Math.abs(point.y - y) < distance) {
|
|
55
|
+
nearest = index
|
|
56
|
+
distance = Math.abs(point.y - y)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
return nearest < 0 ? null : { category, series: nearest }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Category positions and values normalized to [0,1], identical in both renderers. */
|
|
63
|
+
export function chartGeometry(
|
|
64
|
+
categories: readonly ChartCategory[],
|
|
65
|
+
series: readonly ChartSeries[],
|
|
66
|
+
domain?: readonly [number, number],
|
|
67
|
+
): ChartGeometry {
|
|
68
|
+
collectionKeys(categories, 'key')
|
|
69
|
+
collectionKeys(series, 'key')
|
|
70
|
+
// This first renderer targets small product charts, not unbounded telemetry streams.
|
|
71
|
+
if (categories.length > 100 || series.length > 8)
|
|
72
|
+
throw new RangeError('Chart supports up to 100 categories and 8 series.')
|
|
73
|
+
for (const category of categories)
|
|
74
|
+
if (!category.label.trim()) throw new TypeError('Chart categories require labels.')
|
|
75
|
+
const values: number[] = []
|
|
76
|
+
for (const item of series) {
|
|
77
|
+
if (!item.label.trim() || item.values.length !== categories.length)
|
|
78
|
+
throw new TypeError('Chart series require labels and one value per category.')
|
|
79
|
+
if (item.color && !/^#[\da-f]{6}$/i.test(item.color))
|
|
80
|
+
throw new TypeError('Chart colors must be six digit hex values.')
|
|
81
|
+
for (const value of item.values) {
|
|
82
|
+
if (value !== null && !Number.isFinite(value))
|
|
83
|
+
throw new RangeError('Chart values must be finite numbers or null.')
|
|
84
|
+
if (value !== null) values.push(value)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
let min = Math.min(0, ...values),
|
|
88
|
+
max = Math.max(0, ...values)
|
|
89
|
+
if (domain) {
|
|
90
|
+
if (domain.length !== 2 || !domain.every(Number.isFinite) || domain[0] >= domain[1])
|
|
91
|
+
throw new RangeError('Chart domain requires two increasing finite values.')
|
|
92
|
+
;[min, max] = domain
|
|
93
|
+
if (values.some((value) => value < min || value > max))
|
|
94
|
+
throw new RangeError('Chart domain must contain every value.')
|
|
95
|
+
} else if (min === max) max = min + 1
|
|
96
|
+
const span = max - min
|
|
97
|
+
if (!Number.isFinite(span)) throw new RangeError('Chart domain span must be finite.')
|
|
98
|
+
const y = (value: number) => 1 - (value - min) / span
|
|
99
|
+
return {
|
|
100
|
+
min,
|
|
101
|
+
max,
|
|
102
|
+
zero: y(Math.max(min, Math.min(max, 0))),
|
|
103
|
+
ticks: Array.from({ length: 5 }, (_, i) => min + span * (i / 4)),
|
|
104
|
+
series: series.map((item) => ({
|
|
105
|
+
key: item.key,
|
|
106
|
+
points: item.values.map((value, index) =>
|
|
107
|
+
value === null
|
|
108
|
+
? null
|
|
109
|
+
: {
|
|
110
|
+
key: categories[index]!.key,
|
|
111
|
+
value,
|
|
112
|
+
index,
|
|
113
|
+
x: (index + 0.5) / Math.max(1, categories.length),
|
|
114
|
+
y: y(value),
|
|
115
|
+
},
|
|
116
|
+
),
|
|
117
|
+
})),
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Presentation-only interpolation. Canonical values and hit testing always use the model. */
|
|
122
|
+
export function interpolateChart(
|
|
123
|
+
from: ChartGeometry | undefined,
|
|
124
|
+
to: ChartGeometry,
|
|
125
|
+
progress: number,
|
|
126
|
+
): ChartGeometry {
|
|
127
|
+
const mix = (a: number, b: number) => a + (b - a) * Math.max(0, Math.min(1, progress))
|
|
128
|
+
const previousSeries = new Map(from?.series.map((series) => [series.key, series]))
|
|
129
|
+
return {
|
|
130
|
+
...to,
|
|
131
|
+
zero: mix(from?.zero ?? to.zero, to.zero),
|
|
132
|
+
series: to.series.map((series) => {
|
|
133
|
+
const old = previousSeries.get(series.key)
|
|
134
|
+
const previousPoints = new Map(
|
|
135
|
+
old?.points.flatMap((point) => (point ? [[point.key ?? point.index, point] as const] : [])),
|
|
136
|
+
)
|
|
137
|
+
return {
|
|
138
|
+
...series,
|
|
139
|
+
points: series.points.map((point) => {
|
|
140
|
+
if (!point) return null
|
|
141
|
+
const previous = previousPoints.get(point.key ?? point.index)
|
|
142
|
+
return {
|
|
143
|
+
...point,
|
|
144
|
+
x: mix(previous?.x ?? point.x, point.x),
|
|
145
|
+
y: mix(previous?.y ?? from?.zero ?? to.zero, point.y),
|
|
146
|
+
}
|
|
147
|
+
}),
|
|
148
|
+
}
|
|
149
|
+
}),
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { choiceKey, type ChoiceValue } from './choice.js'
|
|
2
|
+
import type { IconName } from './icon.js'
|
|
3
|
+
import { linkDestination, type LinkNavigate } from './link.js'
|
|
4
|
+
|
|
5
|
+
export interface MenuAction {
|
|
6
|
+
value: ChoiceValue
|
|
7
|
+
label: string
|
|
8
|
+
icon?: IconName
|
|
9
|
+
disabled?: boolean
|
|
10
|
+
destructive?: boolean
|
|
11
|
+
}
|
|
12
|
+
export type MenuItem =
|
|
13
|
+
MenuAction | { type: 'separator'; key: string } | { type: 'group'; key: string; label: string }
|
|
14
|
+
export interface NavigationItem {
|
|
15
|
+
value: ChoiceValue
|
|
16
|
+
label: string
|
|
17
|
+
href: string
|
|
18
|
+
icon?: IconName
|
|
19
|
+
badge?: string | number
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
navigate?: LinkNavigate
|
|
22
|
+
}
|
|
23
|
+
export function validateMenu(items: readonly MenuItem[]) {
|
|
24
|
+
const keys = new Set<string>()
|
|
25
|
+
for (const item of items) {
|
|
26
|
+
const key = 'type' in item ? `decoration:${item.key}` : choiceKey(item.value)
|
|
27
|
+
if (keys.has(key)) throw new RangeError('Menu items require unique keys.')
|
|
28
|
+
keys.add(key)
|
|
29
|
+
if ((!('type' in item) || item.type === 'group') && !item.label.trim())
|
|
30
|
+
throw new TypeError('Menu actions and groups require labels.')
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function validateNavigation(items: readonly NavigationItem[]) {
|
|
34
|
+
validateMenu(items)
|
|
35
|
+
items.forEach((item) => linkDestination(item.href))
|
|
36
|
+
}
|
|
37
|
+
export type VirtualItemKey<T = unknown> = string | ((item: T) => ChoiceValue)
|
|
38
|
+
export interface VirtualItemSlot<T = unknown> {
|
|
39
|
+
item: T
|
|
40
|
+
index: number
|
|
41
|
+
itemKey: ChoiceValue
|
|
42
|
+
}
|
|
43
|
+
export interface VirtualListHandle {
|
|
44
|
+
scrollToIndex(index: number): void
|
|
45
|
+
}
|
|
46
|
+
export function virtualKeys<T>(items: readonly T[], itemKey: VirtualItemKey<T>): ChoiceValue[] {
|
|
47
|
+
const seen = new Set<string>()
|
|
48
|
+
return items.map((item) => {
|
|
49
|
+
const key =
|
|
50
|
+
typeof itemKey === 'function' ? itemKey(item) : (item as Record<string, unknown>)?.[itemKey]
|
|
51
|
+
if (
|
|
52
|
+
(typeof key !== 'string' && typeof key !== 'number') ||
|
|
53
|
+
(typeof key === 'number' && !Number.isFinite(key))
|
|
54
|
+
)
|
|
55
|
+
throw new TypeError('Virtual list items require finite number or string keys.')
|
|
56
|
+
const id = choiceKey(key)
|
|
57
|
+
if (seen.has(id)) throw new RangeError('Virtual list keys must be unique.')
|
|
58
|
+
seen.add(id)
|
|
59
|
+
return key
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
export function virtualWindow(
|
|
63
|
+
count: number,
|
|
64
|
+
rowHeight: number,
|
|
65
|
+
height: number,
|
|
66
|
+
offset: number,
|
|
67
|
+
overscan = 3,
|
|
68
|
+
) {
|
|
69
|
+
if (
|
|
70
|
+
!Number.isInteger(count) ||
|
|
71
|
+
count < 0 ||
|
|
72
|
+
!Number.isFinite(rowHeight) ||
|
|
73
|
+
rowHeight <= 0 ||
|
|
74
|
+
!Number.isFinite(height) ||
|
|
75
|
+
height <= 0 ||
|
|
76
|
+
!Number.isInteger(overscan) ||
|
|
77
|
+
overscan < 0 ||
|
|
78
|
+
!Number.isFinite(offset)
|
|
79
|
+
)
|
|
80
|
+
throw new RangeError(
|
|
81
|
+
'Virtual list requires positive finite dimensions and nonnegative integer overscan.',
|
|
82
|
+
)
|
|
83
|
+
const scrollTop = Math.max(0, Math.min(offset, Math.max(0, count * rowHeight - height)))
|
|
84
|
+
const start = Math.max(0, Math.floor(scrollTop / rowHeight) - overscan)
|
|
85
|
+
const end = Math.min(count, Math.ceil((scrollTop + height) / rowHeight) + overscan)
|
|
86
|
+
return { start, end, scrollTop, totalHeight: count * rowHeight }
|
|
87
|
+
}
|
package/src/contracts.ts
CHANGED
|
@@ -104,6 +104,7 @@ const layout = {
|
|
|
104
104
|
}
|
|
105
105
|
export const rowContract = {
|
|
106
106
|
...layout,
|
|
107
|
+
motionRegion: motionBoxContract.motionRegion,
|
|
107
108
|
align: property<Align>()({
|
|
108
109
|
kind: 'string',
|
|
109
110
|
values: ['start', 'center', 'end', 'stretch'],
|
|
@@ -112,6 +113,7 @@ export const rowContract = {
|
|
|
112
113
|
}
|
|
113
114
|
export const columnContract = {
|
|
114
115
|
...layout,
|
|
116
|
+
motionRegion: motionBoxContract.motionRegion,
|
|
115
117
|
align: property<Align>()({
|
|
116
118
|
kind: 'string',
|
|
117
119
|
values: ['start', 'center', 'end', 'stretch'],
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import {
|
|
2
|
+
civilDate,
|
|
3
|
+
isCivilDate,
|
|
4
|
+
validateDateDraft,
|
|
5
|
+
validateDateConstraints,
|
|
6
|
+
validateDateRangeDraft,
|
|
7
|
+
type CivilDate,
|
|
8
|
+
type DateConstraints,
|
|
9
|
+
type DateLocale,
|
|
10
|
+
type DateRangeDraft,
|
|
11
|
+
type DateValidation,
|
|
12
|
+
} from './date.js'
|
|
13
|
+
|
|
14
|
+
/** Deliberately bounded numeric editing grammars; no locale guessing or timestamp conversion. */
|
|
15
|
+
export type DateInputFormat = 'iso' | 'locale' | 'yyyy-MM-dd' | 'dd/MM/yyyy' | 'MM/dd/yyyy'
|
|
16
|
+
export function resolveDateInputFormat(format: DateInputFormat, locale: DateLocale) {
|
|
17
|
+
if (format === 'iso' || format === 'yyyy-MM-dd') return 'yyyy-MM-dd'
|
|
18
|
+
if (format === 'locale') return locale === 'pt-BR' ? 'dd/MM/yyyy' : 'MM/dd/yyyy'
|
|
19
|
+
if (format === 'dd/MM/yyyy' || format === 'MM/dd/yyyy') return format
|
|
20
|
+
throw new RangeError(
|
|
21
|
+
'Unsupported dateFormat. Use iso, locale, yyyy-MM-dd, dd/MM/yyyy or MM/dd/yyyy.',
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
export function dateInputPlaceholder(format: DateInputFormat, locale: DateLocale): string {
|
|
25
|
+
const pattern = resolveDateInputFormat(format, locale)
|
|
26
|
+
return pattern.replace('yyyy', locale === 'pt-BR' ? 'AAAA' : 'YYYY').replace('dd', 'DD')
|
|
27
|
+
}
|
|
28
|
+
export function formatDateInput(
|
|
29
|
+
value: CivilDate,
|
|
30
|
+
format: DateInputFormat = 'iso',
|
|
31
|
+
locale: DateLocale = 'en-US',
|
|
32
|
+
): string {
|
|
33
|
+
civilDate(value)
|
|
34
|
+
const [year, month, day] = value.split('-')
|
|
35
|
+
return resolveDateInputFormat(format, locale)
|
|
36
|
+
.replace('yyyy', year!)
|
|
37
|
+
.replace('MM', month!)
|
|
38
|
+
.replace('dd', day!)
|
|
39
|
+
}
|
|
40
|
+
export function parseDateInput(
|
|
41
|
+
value: string,
|
|
42
|
+
format: DateInputFormat = 'iso',
|
|
43
|
+
locale: DateLocale = 'en-US',
|
|
44
|
+
): CivilDate | null {
|
|
45
|
+
const pattern = resolveDateInputFormat(format, locale)
|
|
46
|
+
if (pattern === 'yyyy-MM-dd') return isCivilDate(value) ? value : null
|
|
47
|
+
const match = /^(\d{2})\/(\d{2})\/(\d{4})$/.exec(value)
|
|
48
|
+
if (!match) return null
|
|
49
|
+
const iso = `${match[3]}-${pattern === 'dd/MM/yyyy' ? match[2] : match[1]}-${pattern === 'dd/MM/yyyy' ? match[1] : match[2]}`
|
|
50
|
+
return isCivilDate(iso) ? iso : null
|
|
51
|
+
}
|
|
52
|
+
export function validateDateInput(
|
|
53
|
+
value: string,
|
|
54
|
+
options: DateConstraints,
|
|
55
|
+
format: DateInputFormat,
|
|
56
|
+
locale: DateLocale,
|
|
57
|
+
): DateValidation {
|
|
58
|
+
validateDateConstraints(options)
|
|
59
|
+
const pattern = resolveDateInputFormat(format, locale)
|
|
60
|
+
const parsed = parseDateInput(value, format, locale)
|
|
61
|
+
if (!value || parsed) return validateDateDraft(parsed ?? '', options)
|
|
62
|
+
const incomplete =
|
|
63
|
+
value.length < 10 &&
|
|
64
|
+
(pattern === 'yyyy-MM-dd'
|
|
65
|
+
? /^\d{0,4}(-\d{0,2}(-\d{0,2})?)?$/.test(value)
|
|
66
|
+
: /^\d{0,2}(\/\d{0,2}(\/\d{0,4})?)?$/.test(value))
|
|
67
|
+
return { valid: false, complete: false, reason: incomplete ? 'incomplete' : 'invalid' }
|
|
68
|
+
}
|
|
69
|
+
export function validateDateRangeInput(
|
|
70
|
+
draft: DateRangeDraft,
|
|
71
|
+
options: DateConstraints,
|
|
72
|
+
format: DateInputFormat,
|
|
73
|
+
locale: DateLocale,
|
|
74
|
+
): DateValidation {
|
|
75
|
+
const start = validateDateInput(draft.start, options, format, locale)
|
|
76
|
+
const end = validateDateInput(draft.end, options, format, locale)
|
|
77
|
+
const complete = start.complete && end.complete
|
|
78
|
+
if (!start.valid) return { ...start, complete }
|
|
79
|
+
if (!end.valid) return { ...end, complete }
|
|
80
|
+
return validateDateRangeDraft(
|
|
81
|
+
{
|
|
82
|
+
start: parseDateInput(draft.start, format, locale) ?? '',
|
|
83
|
+
end: parseDateInput(draft.end, format, locale) ?? '',
|
|
84
|
+
},
|
|
85
|
+
options,
|
|
86
|
+
)
|
|
87
|
+
}
|
package/src/date-time.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** An instant is a Date or milliseconds since the Unix epoch; strings are never guessed. */
|
|
2
|
+
export type DateTimeValue = Date | number
|
|
3
|
+
export type DateTimeStyle = 'short' | 'medium' | 'long' | 'full'
|
|
4
|
+
export interface DateTimeFormatOptions {
|
|
5
|
+
/** Explicit IANA zone (or UTC), required for deterministic server/client presentation. */
|
|
6
|
+
timeZone: string
|
|
7
|
+
locale?: string
|
|
8
|
+
dateStyle?: DateTimeStyle
|
|
9
|
+
timeStyle?: DateTimeStyle
|
|
10
|
+
}
|
|
11
|
+
export function dateTimeMilliseconds(value: DateTimeValue): number {
|
|
12
|
+
const milliseconds = value instanceof Date ? value.getTime() : value
|
|
13
|
+
if (
|
|
14
|
+
typeof milliseconds !== 'number' ||
|
|
15
|
+
!Number.isFinite(milliseconds) ||
|
|
16
|
+
Math.abs(milliseconds) > 8640000000000000
|
|
17
|
+
)
|
|
18
|
+
throw new RangeError('An instant must be a valid Date or finite epoch milliseconds.')
|
|
19
|
+
return Math.trunc(milliseconds)
|
|
20
|
+
}
|
|
21
|
+
/** @internal Shared option validation, without acquiring a platform formatter. */
|
|
22
|
+
export function resolveDateTimeOptions(options: DateTimeFormatOptions) {
|
|
23
|
+
if (!options || typeof options.timeZone !== 'string' || !options.timeZone.trim())
|
|
24
|
+
throw new RangeError('An explicit timeZone is required.')
|
|
25
|
+
const locale = options.locale ?? 'en-US'
|
|
26
|
+
if (!/^[a-z]{2,8}(?:-[a-z0-9]{1,8})*$/i.test(locale)) throw new RangeError('Use a BCP 47 locale.')
|
|
27
|
+
for (const style of [options.dateStyle, options.timeStyle])
|
|
28
|
+
if (style !== undefined && !['short', 'medium', 'long', 'full'].includes(style))
|
|
29
|
+
throw new RangeError('Invalid date/time style.')
|
|
30
|
+
const defaults = options.dateStyle === undefined && options.timeStyle === undefined
|
|
31
|
+
return {
|
|
32
|
+
locale,
|
|
33
|
+
timeZone: options.timeZone,
|
|
34
|
+
dateStyle: defaults ? ('medium' as const) : options.dateStyle,
|
|
35
|
+
timeStyle: defaults ? ('short' as const) : options.timeStyle,
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/discovery.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { choiceKey, type ChoiceValue } from './choice.js'
|
|
2
|
+
import { virtualKeys, type VirtualItemKey } from './collections.js'
|
|
3
|
+
import { sliderScale } from './slider.js'
|
|
4
|
+
|
|
5
|
+
export type RangeValue = readonly [number, number]
|
|
6
|
+
export function rangeValue(
|
|
7
|
+
value: RangeValue,
|
|
8
|
+
min: number,
|
|
9
|
+
max: number,
|
|
10
|
+
step: number,
|
|
11
|
+
): [number, number] {
|
|
12
|
+
const scale = sliderScale(min, max, step)
|
|
13
|
+
if (!Array.isArray(value) || value.length !== 2 || value[0]! > value[1]!)
|
|
14
|
+
throw new RangeError('RangeSlider requires an ordered pair.')
|
|
15
|
+
return [scale.fromNative(scale.toNative(value[0]!)), scale.fromNative(scale.toNative(value[1]!))]
|
|
16
|
+
}
|
|
17
|
+
export function moveRange(
|
|
18
|
+
value: RangeValue,
|
|
19
|
+
thumb: 0 | 1,
|
|
20
|
+
next: number,
|
|
21
|
+
min: number,
|
|
22
|
+
max: number,
|
|
23
|
+
step: number,
|
|
24
|
+
): [number, number] {
|
|
25
|
+
const pair = rangeValue(value, min, max, step)
|
|
26
|
+
const scale = sliderScale(min, max, step)
|
|
27
|
+
const snapped = scale.fromNative(scale.toNative(next))
|
|
28
|
+
pair[thumb] = thumb === 0 ? Math.min(snapped, pair[1]) : Math.max(snapped, pair[0])
|
|
29
|
+
return pair
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface DataColumn<T = Record<string, unknown>> {
|
|
33
|
+
key: string
|
|
34
|
+
label: string
|
|
35
|
+
/** Display text; sorting remains an application-owned operation. */
|
|
36
|
+
value?: (item: T) => string | number | null | undefined
|
|
37
|
+
sortable?: boolean
|
|
38
|
+
width?: number
|
|
39
|
+
align?: 'start' | 'end'
|
|
40
|
+
}
|
|
41
|
+
export interface DataSort {
|
|
42
|
+
key: string
|
|
43
|
+
direction: 'ascending' | 'descending'
|
|
44
|
+
}
|
|
45
|
+
export interface DataCellSlot<T = Record<string, unknown>> {
|
|
46
|
+
item: T
|
|
47
|
+
itemKey: ChoiceValue
|
|
48
|
+
column: DataColumn<T>
|
|
49
|
+
value: string | number | null | undefined
|
|
50
|
+
index: number
|
|
51
|
+
}
|
|
52
|
+
export function validateColumns(columns: readonly DataColumn[]) {
|
|
53
|
+
const seen = new Set<string>()
|
|
54
|
+
if (!columns.length) throw new RangeError('DataTable requires at least one column.')
|
|
55
|
+
for (const column of columns) {
|
|
56
|
+
if (!column.key || !column.label.trim() || seen.has(column.key))
|
|
57
|
+
throw new TypeError('DataTable columns require unique keys and nonempty labels.')
|
|
58
|
+
if (column.width !== undefined && (!Number.isFinite(column.width) || column.width < 44))
|
|
59
|
+
throw new RangeError('Column width must be at least 44.')
|
|
60
|
+
seen.add(column.key)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function nextDataSort(current: DataSort | null, key: string): DataSort | null {
|
|
64
|
+
return current?.key !== key
|
|
65
|
+
? { key, direction: 'ascending' }
|
|
66
|
+
: current.direction === 'ascending'
|
|
67
|
+
? { key, direction: 'descending' }
|
|
68
|
+
: null
|
|
69
|
+
}
|
|
70
|
+
/** Page selection preserves keys from other pages and does not mutate the input. */
|
|
71
|
+
export function selectPage(
|
|
72
|
+
selected: readonly ChoiceValue[],
|
|
73
|
+
page: readonly ChoiceValue[],
|
|
74
|
+
checked: boolean,
|
|
75
|
+
) {
|
|
76
|
+
const pageIds = new Set(page.map(choiceKey))
|
|
77
|
+
const result = selected.filter((key) => !pageIds.has(choiceKey(key)))
|
|
78
|
+
return checked ? [...result, ...page] : result
|
|
79
|
+
}
|
|
80
|
+
export function collectionKeys<T>(items: readonly T[], itemKey: VirtualItemKey<T>) {
|
|
81
|
+
return virtualKeys(items, itemKey)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface TreeNode {
|
|
85
|
+
key: ChoiceValue
|
|
86
|
+
label: string
|
|
87
|
+
disabled?: boolean
|
|
88
|
+
children?: readonly TreeNode[]
|
|
89
|
+
/** True with undefined children requests loading on expansion. An empty array is loaded. */
|
|
90
|
+
hasChildren?: boolean
|
|
91
|
+
}
|
|
92
|
+
export interface TreeEntry {
|
|
93
|
+
node: TreeNode
|
|
94
|
+
parent: ChoiceValue | null
|
|
95
|
+
level: number
|
|
96
|
+
position: number
|
|
97
|
+
siblings: number
|
|
98
|
+
}
|
|
99
|
+
export function treeEntries(
|
|
100
|
+
nodes: readonly TreeNode[],
|
|
101
|
+
expanded: readonly ChoiceValue[],
|
|
102
|
+
): TreeEntry[] {
|
|
103
|
+
const seen = new Set<string>()
|
|
104
|
+
const open = new Set(expanded.map(choiceKey))
|
|
105
|
+
const visible: TreeEntry[] = []
|
|
106
|
+
function visit(
|
|
107
|
+
children: readonly TreeNode[],
|
|
108
|
+
parent: ChoiceValue | null,
|
|
109
|
+
level: number,
|
|
110
|
+
show: boolean,
|
|
111
|
+
) {
|
|
112
|
+
if (level > 100) throw new RangeError('TreeView depth exceeds 100 levels.')
|
|
113
|
+
for (const [index, node] of children.entries()) {
|
|
114
|
+
if (
|
|
115
|
+
(typeof node.key !== 'string' && typeof node.key !== 'number') ||
|
|
116
|
+
(typeof node.key === 'number' && !Number.isFinite(node.key)) ||
|
|
117
|
+
!node.label.trim()
|
|
118
|
+
)
|
|
119
|
+
throw new TypeError('Tree nodes require a finite key and label.')
|
|
120
|
+
const id = choiceKey(node.key)
|
|
121
|
+
if (seen.has(id)) throw new RangeError('Tree keys must be unique; cycles are not allowed.')
|
|
122
|
+
seen.add(id)
|
|
123
|
+
if (show)
|
|
124
|
+
visible.push({ node, parent, level, position: index + 1, siblings: children.length })
|
|
125
|
+
if (node.children) visit(node.children, node.key, level + 1, show && open.has(id))
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
visit(nodes, null, 1, true)
|
|
129
|
+
return visible
|
|
130
|
+
}
|
|
131
|
+
export function treeBranch(node: TreeNode) {
|
|
132
|
+
return node.children === undefined ? !!node.hasChildren : node.children.length > 0
|
|
133
|
+
}
|
|
134
|
+
export function ratingValue(value: number, max: number, step: number) {
|
|
135
|
+
if (!Number.isInteger(max) || max < 1 || max > 10 || (step !== 1 && step !== 0.5))
|
|
136
|
+
throw new RangeError('Rating requires max 1–10 and step 1 or 0.5.')
|
|
137
|
+
if (!Number.isFinite(value)) throw new RangeError('Rating must be finite.')
|
|
138
|
+
return Math.max(0, Math.min(max, Math.round(value / step) * step))
|
|
139
|
+
}
|