@getcortexlabs/mavis-core 0.1.0-alpha.9 → 0.1.0-rc.12
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 +48 -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/creative-controls.d.ts +47 -0
- package/dist/creative-controls.d.ts.map +1 -0
- package/dist/creative-controls.js +112 -0
- package/dist/creative-controls.js.map +1 -0
- package/dist/dashboard.d.ts +72 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +115 -0
- package/dist/dashboard.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/index.d.ts +15 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.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 +2 -0
- package/dist/link.d.ts.map +1 -1
- 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/screen-components.d.ts +45 -0
- package/dist/screen-components.d.ts.map +1 -0
- package/dist/screen-components.js +23 -0
- package/dist/screen-components.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/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/animated-text.d.ts +101 -0
- package/dist/vue/animated-text.d.ts.map +1 -0
- package/dist/vue/animated-text.js +56 -0
- package/dist/vue/animated-text.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 +1708 -21
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +50 -0
- package/dist/vue/component-props.js.map +1 -1
- package/dist/vue/composer.d.ts +159 -0
- package/dist/vue/composer.d.ts.map +1 -0
- package/dist/vue/composer.js +142 -0
- package/dist/vue/composer.js.map +1 -0
- package/dist/vue/configurator.d.ts +2 -2
- 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/creative-controls.d.ts +328 -0
- package/dist/vue/creative-controls.d.ts.map +1 -0
- package/dist/vue/creative-controls.js +396 -0
- package/dist/vue/creative-controls.js.map +1 -0
- package/dist/vue/creative-props.d.ts +260 -0
- package/dist/vue/creative-props.d.ts.map +1 -0
- package/dist/vue/creative-props.js +92 -0
- package/dist/vue/creative-props.js.map +1 -0
- package/dist/vue/dashboard-charts.d.ts +240 -0
- package/dist/vue/dashboard-charts.d.ts.map +1 -0
- package/dist/vue/dashboard-charts.js +263 -0
- package/dist/vue/dashboard-charts.js.map +1 -0
- package/dist/vue/dashboard-effects.d.ts +211 -0
- package/dist/vue/dashboard-effects.d.ts.map +1 -0
- package/dist/vue/dashboard-effects.js +235 -0
- package/dist/vue/dashboard-effects.js.map +1 -0
- package/dist/vue/dashboard-props.d.ts +244 -0
- package/dist/vue/dashboard-props.d.ts.map +1 -0
- package/dist/vue/dashboard-props.js +94 -0
- package/dist/vue/dashboard-props.js.map +1 -0
- 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 +8 -8
- package/dist/vue/date-props.d.ts +6 -0
- package/dist/vue/date-props.d.ts.map +1 -1
- package/dist/vue/date-props.js +3 -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 +237 -0
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +41 -0
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +37 -0
- 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/kanban.d.ts +150 -0
- package/dist/vue/kanban.d.ts.map +1 -0
- package/dist/vue/kanban.js +267 -0
- package/dist/vue/kanban.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/marquee.d.ts +96 -0
- package/dist/vue/marquee.d.ts.map +1 -0
- package/dist/vue/marquee.js +186 -0
- package/dist/vue/marquee.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/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/pin-cell.d.ts +14 -0
- package/dist/vue/pin-cell.d.ts.map +1 -0
- package/dist/vue/pin-cell.js +19 -0
- package/dist/vue/pin-cell.js.map +1 -0
- package/dist/vue/pin-input.d.ts +14 -0
- package/dist/vue/pin-input.d.ts.map +1 -0
- package/dist/vue/pin-input.js +23 -0
- package/dist/vue/pin-input.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 +82 -42
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +3 -1
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/screen-component-props.d.ts +236 -0
- package/dist/vue/screen-component-props.d.ts.map +1 -0
- package/dist/vue/screen-component-props.js +90 -0
- package/dist/vue/screen-component-props.js.map +1 -0
- package/dist/vue/scroll-frame.d.ts +223 -0
- package/dist/vue/scroll-frame.d.ts.map +1 -0
- package/dist/vue/scroll-frame.js +346 -0
- package/dist/vue/scroll-frame.js.map +1 -0
- 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/speed-dial.d.ts +73 -0
- package/dist/vue/speed-dial.d.ts.map +1 -0
- package/dist/vue/speed-dial.js +78 -0
- package/dist/vue/speed-dial.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/swipe-deck.d.ts +120 -0
- package/dist/vue/swipe-deck.d.ts.map +1 -0
- package/dist/vue/swipe-deck.js +229 -0
- package/dist/vue/swipe-deck.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/tour.d.ts +120 -0
- package/dist/vue/tour.d.ts.map +1 -0
- package/dist/vue/tour.js +165 -0
- package/dist/vue/tour.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 +50 -4
- package/src/chart.ts +151 -0
- package/src/collections.ts +87 -0
- package/src/contracts.ts +2 -0
- package/src/creative-controls.ts +169 -0
- package/src/dashboard.ts +164 -0
- package/src/discovery.ts +139 -0
- package/src/experimental-regions.ts +29 -0
- package/src/experimental.ts +40 -0
- package/src/index.ts +23 -1
- package/src/interactive.ts +91 -0
- package/src/link.ts +2 -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/screen-components.ts +59 -0
- package/src/section-scroll.ts +46 -0
- package/src/time.ts +83 -0
- package/src/vue/animated-text.ts +72 -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 +104 -0
- package/src/vue/composer.ts +192 -0
- package/src/vue/configurator.ts +3 -1
- package/src/vue/creative-controls.ts +524 -0
- package/src/vue/creative-props.ts +94 -0
- package/src/vue/dashboard-charts.ts +346 -0
- package/src/vue/dashboard-effects.ts +304 -0
- package/src/vue/dashboard-props.ts +95 -0
- package/src/vue/data-table.ts +190 -0
- package/src/vue/date-calendar.ts +30 -1
- package/src/vue/date-props.ts +3 -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 +237 -0
- package/src/vue/index.ts +64 -0
- package/src/vue/interactive-components.ts +29 -0
- package/src/vue/interactive-props.ts +90 -0
- package/src/vue/kanban.ts +360 -0
- package/src/vue/list-motion.ts +31 -0
- package/src/vue/marquee.ts +248 -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/number-flow.ts +83 -0
- package/src/vue/partition.ts +49 -0
- package/src/vue/pin-cell.ts +26 -0
- package/src/vue/pin-input.ts +31 -0
- package/src/vue/platform.ts +73 -0
- package/src/vue/props.ts +3 -1
- package/src/vue/screen-component-props.ts +92 -0
- package/src/vue/scroll-frame.ts +429 -0
- package/src/vue/sortable-list.ts +308 -0
- package/src/vue/speed-dial.ts +108 -0
- package/src/vue/swipe-actions.ts +226 -0
- package/src/vue/swipe-deck.ts +277 -0
- package/src/vue/time-picker.ts +227 -0
- package/src/vue/tour.ts +239 -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":"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"}
|
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.12",
|
|
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,5 +1,32 @@
|
|
|
1
1
|
/** Source capabilities, not a promise that every feature is in the last npm release. */
|
|
2
2
|
export const componentNames = [
|
|
3
|
+
'MKanban',
|
|
4
|
+
'MDonutChart',
|
|
5
|
+
'MSparkline',
|
|
6
|
+
'MGradientBackground',
|
|
7
|
+
'MParticleField',
|
|
8
|
+
'MConfetti',
|
|
9
|
+
'MColorPicker',
|
|
10
|
+
'MSwipeDeck',
|
|
11
|
+
'MGauge',
|
|
12
|
+
'MTour',
|
|
13
|
+
'MTourTarget',
|
|
14
|
+
'MTransferList',
|
|
15
|
+
'MMarquee',
|
|
16
|
+
'MCollapsibleHeader',
|
|
17
|
+
'MRefreshControl',
|
|
18
|
+
'MComposer',
|
|
19
|
+
'MSpeedDial',
|
|
20
|
+
'MPinInput',
|
|
21
|
+
'MAnimatedText',
|
|
22
|
+
|
|
23
|
+
'MSortableList',
|
|
24
|
+
'MSwipeActions',
|
|
25
|
+
'MNumberFlow',
|
|
26
|
+
'MResizablePanels',
|
|
27
|
+
'MImageCompare',
|
|
28
|
+
'MImageViewer',
|
|
29
|
+
|
|
3
30
|
'MScreen',
|
|
4
31
|
'MRow',
|
|
5
32
|
'MColumn',
|
|
@@ -11,6 +38,7 @@ export const componentNames = [
|
|
|
11
38
|
'MText',
|
|
12
39
|
'MSpan',
|
|
13
40
|
'MThemeProvider',
|
|
41
|
+
'MPlatform',
|
|
14
42
|
'MIcon',
|
|
15
43
|
'MButton',
|
|
16
44
|
'MInput',
|
|
@@ -46,6 +74,24 @@ export const componentNames = [
|
|
|
46
74
|
'MFormErrors',
|
|
47
75
|
'MSteps',
|
|
48
76
|
'MPagination',
|
|
77
|
+
'MPopover',
|
|
78
|
+
'MMenu',
|
|
79
|
+
'MAppBar',
|
|
80
|
+
'MTabBar',
|
|
81
|
+
'MTimePicker',
|
|
82
|
+
'MVirtualList',
|
|
83
|
+
'MDataTable',
|
|
84
|
+
'MCarousel',
|
|
85
|
+
'MRangeSlider',
|
|
86
|
+
'MCalendar',
|
|
87
|
+
'MRating',
|
|
88
|
+
'MTreeView',
|
|
89
|
+
'MCommandPalette',
|
|
90
|
+
'MNavigationRail',
|
|
91
|
+
'MBreadcrumb',
|
|
92
|
+
'MTooltip',
|
|
93
|
+
'MTimeline',
|
|
94
|
+
'MChart',
|
|
49
95
|
] as const
|
|
50
96
|
export type ComponentName = (typeof componentNames)[number]
|
|
51
97
|
export type CapabilityStatus = 'experimental' | 'planned' | 'unsupported' | 'unverified'
|
|
@@ -53,11 +99,11 @@ export type CapabilityStatus = 'experimental' | 'planned' | 'unsupported' | 'unv
|
|
|
53
99
|
export const targetCapabilities = {
|
|
54
100
|
version: 1,
|
|
55
101
|
source: 'repository',
|
|
56
|
-
publishedBaseline: '0.1.0-
|
|
102
|
+
publishedBaseline: '0.1.0-rc.12',
|
|
57
103
|
developmentMotion: {
|
|
58
104
|
availability: 'published',
|
|
59
105
|
joltCommit: null,
|
|
60
|
-
publishedJoltRelease: '0.1.0-rc.
|
|
106
|
+
publishedJoltRelease: '0.1.0-rc.11.1',
|
|
61
107
|
features: {
|
|
62
108
|
gradient: ['web', 'ios', 'android'],
|
|
63
109
|
loadingEffects: ['web', 'ios'],
|
|
@@ -83,7 +129,7 @@ export const targetCapabilities = {
|
|
|
83
129
|
streaming: 'unverified',
|
|
84
130
|
rsc: 'unsupported',
|
|
85
131
|
},
|
|
86
|
-
motion: { engine: 'jolt', minimum: '0.1.0-rc.
|
|
132
|
+
motion: { engine: 'jolt', minimum: '0.1.0-rc.11.1', start: 'client-mount' },
|
|
87
133
|
ssr: {
|
|
88
134
|
availability: '0.1.0-alpha.5',
|
|
89
135
|
host: 'nuxt',
|
|
@@ -126,7 +172,7 @@ export const targetCapabilities = {
|
|
|
126
172
|
streaming: 'unsupported',
|
|
127
173
|
rsc: 'unsupported',
|
|
128
174
|
},
|
|
129
|
-
motion: { engine: 'jolt', minimum: '0.1.0-rc.
|
|
175
|
+
motion: { engine: 'jolt', minimum: '0.1.0-rc.11.1', start: 'native-loaded' },
|
|
130
176
|
},
|
|
131
177
|
],
|
|
132
178
|
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,169 @@
|
|
|
1
|
+
import { validateChoices, type ChoiceOption, type ChoiceValue } from './choice.js'
|
|
2
|
+
|
|
3
|
+
export interface RgbaColor {
|
|
4
|
+
r: number
|
|
5
|
+
g: number
|
|
6
|
+
b: number
|
|
7
|
+
a: number
|
|
8
|
+
}
|
|
9
|
+
export interface HsvColor {
|
|
10
|
+
h: number
|
|
11
|
+
s: number
|
|
12
|
+
v: number
|
|
13
|
+
a: number
|
|
14
|
+
}
|
|
15
|
+
export function bounded(value: number, min: number, max: number) {
|
|
16
|
+
if (![value, min, max].every(Number.isFinite) || max <= min)
|
|
17
|
+
throw new RangeError('Values must be finite and max must exceed min.')
|
|
18
|
+
return Math.min(max, Math.max(min, value))
|
|
19
|
+
}
|
|
20
|
+
/** Deliberately accepts only HEX and numeric RGB(A), never arbitrary CSS. */
|
|
21
|
+
export function parseColor(input: string): RgbaColor | null {
|
|
22
|
+
const hex = /^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i.exec(input.trim())
|
|
23
|
+
if (hex) {
|
|
24
|
+
let value = hex[1]!
|
|
25
|
+
if (value.length <= 4) value = [...value].map((c) => c + c).join('')
|
|
26
|
+
return {
|
|
27
|
+
r: parseInt(value.slice(0, 2), 16),
|
|
28
|
+
g: parseInt(value.slice(2, 4), 16),
|
|
29
|
+
b: parseInt(value.slice(4, 6), 16),
|
|
30
|
+
a: value.length === 8 ? parseInt(value.slice(6), 16) / 255 : 1,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const rgb =
|
|
34
|
+
/^rgba?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)(?:\s*,\s*(\d*\.?\d+))?\s*\)$/i.exec(
|
|
35
|
+
input.trim(),
|
|
36
|
+
)
|
|
37
|
+
if (!rgb) return null
|
|
38
|
+
const [r, g, b, a] = [
|
|
39
|
+
Number(rgb[1]),
|
|
40
|
+
Number(rgb[2]),
|
|
41
|
+
Number(rgb[3]),
|
|
42
|
+
rgb[4] === undefined ? 1 : Number(rgb[4]),
|
|
43
|
+
]
|
|
44
|
+
if ([r!, g!, b!].some((v) => v > 255) || a! > 1) return null
|
|
45
|
+
return { r: Math.round(r!), g: Math.round(g!), b: Math.round(b!), a: a! }
|
|
46
|
+
}
|
|
47
|
+
export function colorHex(color: RgbaColor, alpha = false) {
|
|
48
|
+
return (
|
|
49
|
+
'#' +
|
|
50
|
+
[color.r, color.g, color.b, ...(alpha ? [color.a * 255] : [])]
|
|
51
|
+
.map((v) =>
|
|
52
|
+
Math.round(bounded(v, 0, 255))
|
|
53
|
+
.toString(16)
|
|
54
|
+
.padStart(2, '0'),
|
|
55
|
+
)
|
|
56
|
+
.join('')
|
|
57
|
+
.toUpperCase()
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
export function colorHsv(color: RgbaColor): HsvColor {
|
|
61
|
+
const [r, g, b] = [color.r / 255, color.g / 255, color.b / 255]
|
|
62
|
+
const max = Math.max(r!, g!, b!),
|
|
63
|
+
min = Math.min(r!, g!, b!),
|
|
64
|
+
delta = max - min
|
|
65
|
+
const h = !delta
|
|
66
|
+
? 0
|
|
67
|
+
: max === r
|
|
68
|
+
? ((g! - b!) / delta) % 6
|
|
69
|
+
: max === g
|
|
70
|
+
? (b! - r!) / delta + 2
|
|
71
|
+
: (r! - g!) / delta + 4
|
|
72
|
+
return { h: (h * 60 + 360) % 360, s: max ? (delta / max) * 100 : 0, v: max * 100, a: color.a }
|
|
73
|
+
}
|
|
74
|
+
export function hsvColor(color: HsvColor): RgbaColor {
|
|
75
|
+
const h = bounded(color.h, 0, 360) / 60,
|
|
76
|
+
s = bounded(color.s, 0, 100) / 100,
|
|
77
|
+
v = bounded(color.v, 0, 100) / 100
|
|
78
|
+
const c = v * s,
|
|
79
|
+
x = c * (1 - Math.abs((h % 2) - 1)),
|
|
80
|
+
m = v - c
|
|
81
|
+
const [r, g, b] =
|
|
82
|
+
h < 1
|
|
83
|
+
? [c, x, 0]
|
|
84
|
+
: h < 2
|
|
85
|
+
? [x, c, 0]
|
|
86
|
+
: h < 3
|
|
87
|
+
? [0, c, x]
|
|
88
|
+
: h < 4
|
|
89
|
+
? [0, x, c]
|
|
90
|
+
: h < 5
|
|
91
|
+
? [x, 0, c]
|
|
92
|
+
: [c, 0, x]
|
|
93
|
+
return {
|
|
94
|
+
r: Math.round((r! + m) * 255),
|
|
95
|
+
g: Math.round((g! + m) * 255),
|
|
96
|
+
b: Math.round((b! + m) * 255),
|
|
97
|
+
a: bounded(color.a, 0, 1),
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export interface SwipeCard {
|
|
101
|
+
id: ChoiceValue
|
|
102
|
+
title: string
|
|
103
|
+
description?: string
|
|
104
|
+
image?: string
|
|
105
|
+
}
|
|
106
|
+
export type SwipeDecision = 'accept' | 'reject'
|
|
107
|
+
export function deckDecision(
|
|
108
|
+
distance: number,
|
|
109
|
+
velocity: number,
|
|
110
|
+
threshold: number,
|
|
111
|
+
): SwipeDecision | null {
|
|
112
|
+
if (![distance, velocity, threshold].every(Number.isFinite) || threshold <= 0)
|
|
113
|
+
throw new RangeError('Invalid swipe geometry.')
|
|
114
|
+
return Math.abs(distance) >= threshold || (Math.abs(distance) > 12 && Math.abs(velocity) > 600)
|
|
115
|
+
? distance + velocity * 0.08 >= 0
|
|
116
|
+
? 'accept'
|
|
117
|
+
: 'reject'
|
|
118
|
+
: null
|
|
119
|
+
}
|
|
120
|
+
export function validateCards(items: readonly SwipeCard[]) {
|
|
121
|
+
validateChoices(
|
|
122
|
+
items.map((item) => ({ value: item.id, label: item.title })),
|
|
123
|
+
null,
|
|
124
|
+
)
|
|
125
|
+
return items
|
|
126
|
+
}
|
|
127
|
+
export interface TourStep {
|
|
128
|
+
id: string
|
|
129
|
+
title: string
|
|
130
|
+
description: string
|
|
131
|
+
}
|
|
132
|
+
export function validateTour(steps: readonly TourStep[]) {
|
|
133
|
+
validateChoices(
|
|
134
|
+
steps.map((step) => ({ value: step.id, label: step.title })),
|
|
135
|
+
null,
|
|
136
|
+
)
|
|
137
|
+
if (steps.some((step) => !step.id.trim()))
|
|
138
|
+
throw new TypeError('Tour targets require nonempty ids.')
|
|
139
|
+
return steps
|
|
140
|
+
}
|
|
141
|
+
export interface MarqueeItem {
|
|
142
|
+
id: ChoiceValue
|
|
143
|
+
label: string
|
|
144
|
+
image?: string
|
|
145
|
+
}
|
|
146
|
+
export function transferValues(
|
|
147
|
+
options: readonly ChoiceOption[],
|
|
148
|
+
selected: readonly ChoiceValue[],
|
|
149
|
+
checked: readonly ChoiceValue[],
|
|
150
|
+
direction: 'add' | 'remove',
|
|
151
|
+
) {
|
|
152
|
+
validateChoices(options, null)
|
|
153
|
+
const enabled = new Set(
|
|
154
|
+
options.filter((option) => !option.disabled).map((option) => option.value),
|
|
155
|
+
)
|
|
156
|
+
const changes = new Set(checked.filter((value) => enabled.has(value)))
|
|
157
|
+
return direction === 'add'
|
|
158
|
+
? [...new Set([...selected, ...changes])]
|
|
159
|
+
: selected.filter((value) => !changes.has(value))
|
|
160
|
+
}
|
|
161
|
+
export function gaugeGeometry(value: number, min: number, max: number, semi: boolean) {
|
|
162
|
+
const clamped = bounded(value, min, max)
|
|
163
|
+
return {
|
|
164
|
+
value: clamped,
|
|
165
|
+
ratio: (clamped - min) / (max - min),
|
|
166
|
+
path: semi ? 'M 10 50 A 40 40 0 0 1 90 50' : 'M 50 10 A 40 40 0 1 1 49.999 10',
|
|
167
|
+
viewBox: [0, 0, 100, semi ? 58 : 100] as const,
|
|
168
|
+
}
|
|
169
|
+
}
|