@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
package/src/dashboard.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { chartGeometry } from './chart.js'
|
|
2
|
+
|
|
3
|
+
export interface KanbanColumn {
|
|
4
|
+
id: string
|
|
5
|
+
title: string
|
|
6
|
+
limit?: number
|
|
7
|
+
}
|
|
8
|
+
export interface KanbanCard {
|
|
9
|
+
id: string
|
|
10
|
+
column: string
|
|
11
|
+
title: string
|
|
12
|
+
description?: string
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
}
|
|
15
|
+
export interface KanbanMove {
|
|
16
|
+
id: string
|
|
17
|
+
from: string
|
|
18
|
+
to: string
|
|
19
|
+
before: string | null
|
|
20
|
+
}
|
|
21
|
+
export interface DonutSegment {
|
|
22
|
+
id: string
|
|
23
|
+
label: string
|
|
24
|
+
value: number
|
|
25
|
+
color?: string
|
|
26
|
+
}
|
|
27
|
+
export interface SparklinePoint {
|
|
28
|
+
id: string
|
|
29
|
+
label: string
|
|
30
|
+
value: number | null
|
|
31
|
+
}
|
|
32
|
+
export interface DashboardRect {
|
|
33
|
+
x: number
|
|
34
|
+
y: number
|
|
35
|
+
width: number
|
|
36
|
+
height: number
|
|
37
|
+
}
|
|
38
|
+
export function dashboardNumber(value: number, min: number, max: number, name: string) {
|
|
39
|
+
if (!Number.isFinite(value) || value < min || value > max)
|
|
40
|
+
throw new RangeError(`${name} must be between ${min} and ${max}.`)
|
|
41
|
+
return value
|
|
42
|
+
}
|
|
43
|
+
function unique(items: readonly { id: string }[], name: string) {
|
|
44
|
+
const keys = new Set<string>()
|
|
45
|
+
for (const item of items) {
|
|
46
|
+
if (!item.id || keys.has(item.id)) throw new TypeError(`${name} requires unique, nonempty IDs.`)
|
|
47
|
+
keys.add(item.id)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function validateKanban(columns: readonly KanbanColumn[], cards: readonly KanbanCard[]) {
|
|
51
|
+
unique(columns, 'Kanban columns')
|
|
52
|
+
unique(cards, 'Kanban cards')
|
|
53
|
+
if (!columns.length || columns.length > 12 || cards.length > 500)
|
|
54
|
+
throw new RangeError('Kanban supports 1–12 columns and at most 500 cards.')
|
|
55
|
+
for (const column of columns) {
|
|
56
|
+
if (!column.title.trim()) throw new TypeError('Kanban columns need a title.')
|
|
57
|
+
if (column.limit !== undefined && (!Number.isInteger(column.limit) || column.limit < 1))
|
|
58
|
+
throw new RangeError('Column limits must be positive integers.')
|
|
59
|
+
}
|
|
60
|
+
for (const card of cards)
|
|
61
|
+
if (!card.title.trim() || !columns.some((c) => c.id === card.column))
|
|
62
|
+
throw new TypeError('Cards require a title and an existing column.')
|
|
63
|
+
}
|
|
64
|
+
/** Keeps hidden cards and consumer metadata intact; limits apply to all cards, not the filtered view. */
|
|
65
|
+
export function moveKanban<T extends KanbanCard>(
|
|
66
|
+
columns: readonly KanbanColumn[],
|
|
67
|
+
cards: readonly T[],
|
|
68
|
+
id: string,
|
|
69
|
+
to: string,
|
|
70
|
+
before: string | null = null,
|
|
71
|
+
): { cards: T[]; move: KanbanMove } | null {
|
|
72
|
+
validateKanban(columns, cards)
|
|
73
|
+
const card = cards.find((c) => c.id === id),
|
|
74
|
+
column = columns.find((c) => c.id === to)
|
|
75
|
+
if (!card || card.disabled || !column || before === id) return null
|
|
76
|
+
if (before !== null && !cards.some((c) => c.id === before && c.column === to)) return null
|
|
77
|
+
if (
|
|
78
|
+
card.column !== to &&
|
|
79
|
+
column.limit !== undefined &&
|
|
80
|
+
cards.filter((c) => c.column === to).length >= column.limit
|
|
81
|
+
)
|
|
82
|
+
return null
|
|
83
|
+
const next = cards.filter((c) => c.id !== id)
|
|
84
|
+
const index = before === null ? next.length : next.findIndex((c) => c.id === before)
|
|
85
|
+
next.splice(index, 0, { ...card, column: to })
|
|
86
|
+
const oldOrder = cards
|
|
87
|
+
.filter((c) => c.column === to)
|
|
88
|
+
.map((c) => c.id)
|
|
89
|
+
.join('\0')
|
|
90
|
+
const newOrder = next
|
|
91
|
+
.filter((c) => c.column === to)
|
|
92
|
+
.map((c) => c.id)
|
|
93
|
+
.join('\0')
|
|
94
|
+
if (card.column === to && oldOrder === newOrder) return null
|
|
95
|
+
return { cards: next, move: { id, from: card.column, to, before } }
|
|
96
|
+
}
|
|
97
|
+
export function donutGeometry(segments: readonly DonutSegment[]) {
|
|
98
|
+
unique(segments, 'Donut segments')
|
|
99
|
+
if (segments.length > 24) throw new RangeError('Donut supports at most 24 segments.')
|
|
100
|
+
let total = 0
|
|
101
|
+
for (const segment of segments) {
|
|
102
|
+
if (!segment.label.trim() || !Number.isFinite(segment.value) || segment.value < 0)
|
|
103
|
+
throw new TypeError('Donut segments require a label and finite nonnegative value.')
|
|
104
|
+
if (segment.color && !/^#[\da-f]{6}$/i.test(segment.color))
|
|
105
|
+
throw new TypeError('Segment colors must be six-digit HEX.')
|
|
106
|
+
total += segment.value
|
|
107
|
+
}
|
|
108
|
+
if (!Number.isFinite(total)) throw new RangeError('Donut total must be finite.')
|
|
109
|
+
let offset = 0
|
|
110
|
+
return {
|
|
111
|
+
total,
|
|
112
|
+
segments: segments.map((segment) => {
|
|
113
|
+
const ratio = total ? segment.value / total : 0,
|
|
114
|
+
start = offset
|
|
115
|
+
offset = Math.min(1, offset + ratio)
|
|
116
|
+
return { ...segment, ratio, start, end: offset }
|
|
117
|
+
}),
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export const donutPath = 'M 50 10 A 40 40 0 1 1 50 90 A 40 40 0 1 1 50 10'
|
|
121
|
+
/** Uses the chart domain/null conventions. A zero-length line is extended for a single point. */
|
|
122
|
+
export function sparklineGeometry(
|
|
123
|
+
points: readonly SparklinePoint[],
|
|
124
|
+
domain?: readonly [number, number],
|
|
125
|
+
width = 100,
|
|
126
|
+
height = 40,
|
|
127
|
+
) {
|
|
128
|
+
unique(points, 'Sparkline points')
|
|
129
|
+
const geometry = chartGeometry(
|
|
130
|
+
points.map((p) => ({ key: p.id, label: p.label })),
|
|
131
|
+
[{ key: 'sparkline', label: 'Values', values: points.map((p) => p.value) }],
|
|
132
|
+
domain,
|
|
133
|
+
)
|
|
134
|
+
const paths: { id: string; d: string }[] = []
|
|
135
|
+
let d = '',
|
|
136
|
+
id = '',
|
|
137
|
+
count = 0,
|
|
138
|
+
last = ''
|
|
139
|
+
const flush = () => {
|
|
140
|
+
if (d) paths.push({ id, d: count === 1 ? `${d} L${last}` : d })
|
|
141
|
+
d = ''
|
|
142
|
+
count = 0
|
|
143
|
+
}
|
|
144
|
+
for (const point of geometry.series[0]?.points ?? []) {
|
|
145
|
+
if (!point) {
|
|
146
|
+
flush()
|
|
147
|
+
continue
|
|
148
|
+
}
|
|
149
|
+
if (!d) id = points[point.index]!.id
|
|
150
|
+
const x =
|
|
151
|
+
(points.length === 1 ? 0.5 : 0.02 + (point.index / (points.length - 1)) * 0.96) * width
|
|
152
|
+
const y = (0.1 + point.y * 0.8) * height
|
|
153
|
+
last = `${Math.min(width * 0.98, x + 0.01)} ${y}`
|
|
154
|
+
d += `${d ? ' L' : 'M'}${x} ${y}`
|
|
155
|
+
count++
|
|
156
|
+
}
|
|
157
|
+
flush()
|
|
158
|
+
return { ...geometry, paths }
|
|
159
|
+
}
|
|
160
|
+
export function effectColors(colors: readonly string[]) {
|
|
161
|
+
if (colors.length < 2 || colors.length > 8 || colors.some((c) => !/^#[\da-f]{6}$/i.test(c)))
|
|
162
|
+
throw new TypeError('Effects require 2–8 six-digit HEX colors.')
|
|
163
|
+
return colors
|
|
164
|
+
}
|
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
|
+
}
|
|
@@ -99,6 +99,11 @@ export interface MotionSharedOptions {
|
|
|
99
99
|
transition?: Exclude<MotionOptions, { type: 'gravity' }>
|
|
100
100
|
layoutTimeout?: number
|
|
101
101
|
}
|
|
102
|
+
export interface MotionLayoutOptions {
|
|
103
|
+
transition?: Exclude<MotionOptions, { type: 'gravity' }>
|
|
104
|
+
size?: 'scale' | false
|
|
105
|
+
enter?: boolean
|
|
106
|
+
}
|
|
102
107
|
export interface MotionSharedLayout extends MotionBinding {
|
|
103
108
|
readonly active: boolean
|
|
104
109
|
/** Explicit identity; follows replacement of this declared surface. */
|
|
@@ -151,6 +156,8 @@ type Available = {
|
|
|
151
156
|
onAvailable(setup: () => void | (() => void)): () => void
|
|
152
157
|
}
|
|
153
158
|
export interface MotionRegion extends Available {
|
|
159
|
+
/** Animate keyed direct children after a synchronous data mutation. Not a virtual-list API. */
|
|
160
|
+
animateLayout(change: () => void, options?: MotionLayoutOptions): MotionPlayback
|
|
154
161
|
onKeyboard(callback: (state: MotionKeyboardState) => void): MotionKeyboard
|
|
155
162
|
/** Waits for initial native layout; the engine owns simulation and later geometry. */
|
|
156
163
|
physicsWorld(
|
|
@@ -171,6 +178,7 @@ export interface MotionRegion extends Available {
|
|
|
171
178
|
diagnostics(options: MotionDiagnosticsOptions): MotionDiagnostics
|
|
172
179
|
}
|
|
173
180
|
export interface MotionRegionAdapter {
|
|
181
|
+
animateLayout?(change: () => void, options: MotionLayoutOptions): MotionPlayback
|
|
174
182
|
onKeyboard?(callback: (state: MotionKeyboardState) => void): Omit<MotionKeyboard, 'disposed'>
|
|
175
183
|
physicsWorld?(
|
|
176
184
|
bodies: readonly MotionCircleBody<MotionSurfaceAdapter>[],
|
|
@@ -396,6 +404,27 @@ function group(
|
|
|
396
404
|
export function createMotionRegion(): MotionRegion {
|
|
397
405
|
const entry: { state?: RegionState; setups: Set<() => () => void> } = { setups: new Set() }
|
|
398
406
|
const region: MotionRegion = {
|
|
407
|
+
animateLayout(change, options = {}) {
|
|
408
|
+
const state = regionState(region)
|
|
409
|
+
if (typeof change !== 'function')
|
|
410
|
+
throw new TypeError('Layout motion needs a synchronous change callback.')
|
|
411
|
+
if (options.size !== undefined && options.size !== false && options.size !== 'scale')
|
|
412
|
+
throw new TypeError('Layout size must be scale or false.')
|
|
413
|
+
if (options.enter !== undefined && typeof options.enter !== 'boolean')
|
|
414
|
+
throw new TypeError('Layout enter must be a boolean.')
|
|
415
|
+
if (!state.adapter.animateLayout) throw new Error('Layout motion is unavailable.')
|
|
416
|
+
const raw = state.adapter.animateLayout(change, options)
|
|
417
|
+
const resource = { dispose: () => raw.stop() }
|
|
418
|
+
state.resources.add(resource)
|
|
419
|
+
const forget = () => state.resources.delete(resource)
|
|
420
|
+
void raw.finished.then(forget, forget)
|
|
421
|
+
return {
|
|
422
|
+
finished: raw.finished,
|
|
423
|
+
stop() {
|
|
424
|
+
if (state.valid && state.resources.has(resource)) raw.stop()
|
|
425
|
+
},
|
|
426
|
+
}
|
|
427
|
+
},
|
|
399
428
|
get available() {
|
|
400
429
|
return Boolean(entry.state?.valid)
|
|
401
430
|
},
|
package/src/experimental.ts
CHANGED
|
@@ -5,6 +5,9 @@ import {
|
|
|
5
5
|
type MotionValueOptions,
|
|
6
6
|
type MotionDecayOptions,
|
|
7
7
|
} from './experimental-playback.js'
|
|
8
|
+
import { validateSectionScroll, type SectionScrollOptions } from './section-scroll.js'
|
|
9
|
+
export { sectionScrollRange } from './section-scroll.js'
|
|
10
|
+
export type { SectionScrollOptions, ScrollEdge } from './section-scroll.js'
|
|
8
11
|
export * from './experimental-playback.js'
|
|
9
12
|
export * from './experimental-effects.js'
|
|
10
13
|
export * from './experimental-collections.js'
|
|
@@ -103,6 +106,12 @@ export interface MotionSurface extends MotionVisualSurface {
|
|
|
103
106
|
frames: MotionScrollFrames,
|
|
104
107
|
options: MotionScrollOptions,
|
|
105
108
|
): MotionScrollLink
|
|
109
|
+
scrollSection(
|
|
110
|
+
source: MotionScrollSource,
|
|
111
|
+
section: MotionRegion,
|
|
112
|
+
frames: MotionScrollFrames,
|
|
113
|
+
options?: SectionScrollOptions,
|
|
114
|
+
): MotionScrollLink
|
|
106
115
|
}
|
|
107
116
|
export interface MotionBinding {
|
|
108
117
|
readonly disposed: boolean
|
|
@@ -189,6 +198,12 @@ export interface MotionSurfaceAdapter extends Partial<MotionVisualAdapter> {
|
|
|
189
198
|
frames: MotionScrollFrames,
|
|
190
199
|
options: MotionScrollOptions,
|
|
191
200
|
): Omit<MotionScrollLink, 'disposed'>
|
|
201
|
+
scrollSection?(
|
|
202
|
+
source: MotionScrollAdapter,
|
|
203
|
+
section: MotionRegionAdapter,
|
|
204
|
+
frames: MotionScrollFrames,
|
|
205
|
+
options: SectionScrollOptions,
|
|
206
|
+
): Omit<MotionScrollLink, 'disposed'>
|
|
192
207
|
mapColor?(
|
|
193
208
|
source: Pick<MotionReadable, 'get' | 'dispose'>,
|
|
194
209
|
input: readonly number[],
|
|
@@ -963,6 +978,31 @@ export function createMotionSurface(): MotionSurface {
|
|
|
963
978
|
for (const [, state] of entries) depend(state, handle)
|
|
964
979
|
return handle
|
|
965
980
|
},
|
|
981
|
+
scrollSection(source, section, frames, options = {}) {
|
|
982
|
+
const binding = current()
|
|
983
|
+
const scroll = scrollSources.get(source)
|
|
984
|
+
if (!scroll) throw new Error('Scroll source is unavailable.')
|
|
985
|
+
const region = regionState(section)
|
|
986
|
+
validateScroll(frames, { range: [0, 1] })
|
|
987
|
+
validateSectionScroll(options)
|
|
988
|
+
if (!binding.adapter.scrollSection) throw new Error('Section scroll motion is unavailable.')
|
|
989
|
+
const raw = binding.adapter.scrollSection(scroll.adapter, region.adapter, frames, options)
|
|
990
|
+
const resource = { dispose: () => link.dispose() }
|
|
991
|
+
const link = own(binding, {
|
|
992
|
+
get execution() {
|
|
993
|
+
return raw.execution
|
|
994
|
+
},
|
|
995
|
+
refresh: () => raw.refresh(),
|
|
996
|
+
dispose() {
|
|
997
|
+
scroll.links.delete(link)
|
|
998
|
+
region.resources.delete(resource)
|
|
999
|
+
raw.dispose()
|
|
1000
|
+
},
|
|
1001
|
+
})
|
|
1002
|
+
scroll.links.add(link)
|
|
1003
|
+
region.resources.add(resource)
|
|
1004
|
+
return link
|
|
1005
|
+
},
|
|
966
1006
|
scrollLinked(source, frames, options) {
|
|
967
1007
|
const binding = current()
|
|
968
1008
|
const state = scrollSources.get(source)
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { defineTheme, mavis, midnight } from './theme/themes.js'
|
|
2
2
|
export { resolveSpace } from './theme/resolve.js'
|
|
3
|
-
export { pressMotion, revealMotion, motionRecipe } from './motion.js'
|
|
3
|
+
export { pressMotion, revealMotion, motionRecipe, componentMotion } from './motion.js'
|
|
4
|
+
export type { ComponentMotion } from './motion.js'
|
|
4
5
|
export type {
|
|
5
6
|
FontFamily,
|
|
6
7
|
MotionTheme,
|
|
@@ -96,3 +97,24 @@ export * from './multi-select.js'
|
|
|
96
97
|
export * from './choice-motion.js'
|
|
97
98
|
|
|
98
99
|
export { gridColumns } from './grid.js'
|
|
100
|
+
|
|
101
|
+
export * from './time.js'
|
|
102
|
+
export * from './popover.js'
|
|
103
|
+
export * from './collections.js'
|
|
104
|
+
|
|
105
|
+
export { defineNavigationTransition } from './navigation-transition.js'
|
|
106
|
+
export type { NavigationTransition } from './navigation-transition.js'
|
|
107
|
+
|
|
108
|
+
export * from './discovery.js'
|
|
109
|
+
|
|
110
|
+
export * from './wayfinding.js'
|
|
111
|
+
export * from './chart.js'
|
|
112
|
+
|
|
113
|
+
export * from './interactive.js'
|
|
114
|
+
|
|
115
|
+
export * from './number-flow-format.js'
|
|
116
|
+
|
|
117
|
+
export * from './screen-components.js'
|
|
118
|
+
export * from './creative-controls.js'
|
|
119
|
+
|
|
120
|
+
export * from './dashboard.js'
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { choiceKey, type ChoiceValue } from './choice.js'
|
|
2
|
+
import { virtualKeys, type VirtualItemKey } from './collections.js'
|
|
3
|
+
import type { IconName } from './icon.js'
|
|
4
|
+
|
|
5
|
+
export interface SwipeAction {
|
|
6
|
+
value: ChoiceValue
|
|
7
|
+
label: string
|
|
8
|
+
icon?: IconName
|
|
9
|
+
destructive?: boolean
|
|
10
|
+
disabled?: boolean
|
|
11
|
+
}
|
|
12
|
+
export type SwipeSide = 'start' | 'end' | null
|
|
13
|
+
export interface ViewerImage {
|
|
14
|
+
key: ChoiceValue
|
|
15
|
+
src: string
|
|
16
|
+
thumbnail?: string
|
|
17
|
+
alt: string
|
|
18
|
+
caption?: string
|
|
19
|
+
aspectRatio?: number
|
|
20
|
+
}
|
|
21
|
+
export interface SortableMove {
|
|
22
|
+
key: ChoiceValue
|
|
23
|
+
beforeKey: ChoiceValue | null
|
|
24
|
+
fromIndex: number
|
|
25
|
+
toIndex: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function finiteRange(value: number, min: number, max: number) {
|
|
29
|
+
if (![value, min, max].every(Number.isFinite) || min > max)
|
|
30
|
+
throw new RangeError('Expected a finite value and ordered bounds.')
|
|
31
|
+
return Math.max(min, Math.min(max, value))
|
|
32
|
+
}
|
|
33
|
+
export function positiveSize(value: number, name: string) {
|
|
34
|
+
if (!Number.isFinite(value) || value <= 0) throw new RangeError(`${name} must be positive.`)
|
|
35
|
+
return value
|
|
36
|
+
}
|
|
37
|
+
export function moveItem<T>(
|
|
38
|
+
items: readonly T[],
|
|
39
|
+
itemKey: VirtualItemKey<T>,
|
|
40
|
+
key: ChoiceValue,
|
|
41
|
+
beforeKey: ChoiceValue | null,
|
|
42
|
+
): { items: T[]; move: SortableMove } | null {
|
|
43
|
+
const keys = virtualKeys(items, itemKey)
|
|
44
|
+
const fromIndex = keys.indexOf(key)
|
|
45
|
+
if (fromIndex < 0 || beforeKey === key || (beforeKey !== null && !keys.includes(beforeKey)))
|
|
46
|
+
return null
|
|
47
|
+
const remaining = items.filter((_, index) => index !== fromIndex)
|
|
48
|
+
const remainingKeys = keys.filter((_, index) => index !== fromIndex)
|
|
49
|
+
const toIndex = beforeKey === null ? remaining.length : remainingKeys.indexOf(beforeKey)
|
|
50
|
+
if (toIndex === fromIndex) return null
|
|
51
|
+
remaining.splice(toIndex, 0, items[fromIndex]!)
|
|
52
|
+
return { items: remaining, move: { key, beforeKey, fromIndex, toIndex } }
|
|
53
|
+
}
|
|
54
|
+
export function validateActions(start: readonly SwipeAction[], end: readonly SwipeAction[]) {
|
|
55
|
+
const keys = new Set<string>()
|
|
56
|
+
for (const action of [...start, ...end]) {
|
|
57
|
+
const key = choiceKey(action.value)
|
|
58
|
+
if (keys.has(key)) throw new RangeError('Swipe actions require unique keys across both sides.')
|
|
59
|
+
if (!action.label.trim()) throw new TypeError('Swipe actions require visible labels.')
|
|
60
|
+
keys.add(key)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function swipeDestination(
|
|
64
|
+
x: number,
|
|
65
|
+
velocity: number,
|
|
66
|
+
startWidth: number,
|
|
67
|
+
endWidth: number,
|
|
68
|
+
direction = 1,
|
|
69
|
+
): SwipeSide {
|
|
70
|
+
const projected = (x + velocity * 0.12) * direction
|
|
71
|
+
return projected > startWidth * 0.45 && startWidth > 0
|
|
72
|
+
? 'start'
|
|
73
|
+
: projected < -endWidth * 0.45 && endWidth > 0
|
|
74
|
+
? 'end'
|
|
75
|
+
: null
|
|
76
|
+
}
|
|
77
|
+
export function panelValue(value: number, min: number, max: number, collapsible: boolean) {
|
|
78
|
+
finiteRange(min, 0, 100)
|
|
79
|
+
finiteRange(max, 0, 100)
|
|
80
|
+
if (min < 0 || max > 100 || min >= max)
|
|
81
|
+
throw new RangeError('Panel bounds must satisfy 0 <= min < max <= 100.')
|
|
82
|
+
return collapsible && value === 0 ? 0 : finiteRange(value, min, max)
|
|
83
|
+
}
|
|
84
|
+
export function validateViewer(images: readonly ViewerImage[]) {
|
|
85
|
+
virtualKeys(images, 'key')
|
|
86
|
+
for (const image of images) {
|
|
87
|
+
if (!image.src.trim() || !image.alt.trim())
|
|
88
|
+
throw new TypeError('Viewer images require src and descriptive alt text.')
|
|
89
|
+
if (image.aspectRatio !== undefined) positiveSize(image.aspectRatio, 'aspectRatio')
|
|
90
|
+
}
|
|
91
|
+
}
|
package/src/link.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface NavigationOptions {
|
|
|
9
9
|
|
|
10
10
|
/** App-owned navigation. Instances belong to one app (and one SSR request). */
|
|
11
11
|
export interface MavisNavigation {
|
|
12
|
+
/** Releases host hooks when the application unmounts. */
|
|
13
|
+
dispose?(): void
|
|
12
14
|
resolve(href: string): string
|
|
13
15
|
push: LinkNavigate
|
|
14
16
|
replace: LinkNavigate
|
package/src/motion.ts
CHANGED
|
@@ -45,6 +45,20 @@ export const revealMotion = {
|
|
|
45
45
|
enter: [{ opacity: [0, 1], y: [8, 0] }, { duration: 180 }],
|
|
46
46
|
leave: [{ opacity: 0 }, { duration: 120 }],
|
|
47
47
|
} as const
|
|
48
|
+
|
|
49
|
+
/** Shared interaction timing; components keep semantics and Jolt owns every frame. */
|
|
50
|
+
export type ComponentMotion = 'selection' | 'layout' | 'overlay' | 'data' | 'feedback'
|
|
51
|
+
export function componentMotion(theme: MavisTheme, kind: ComponentMotion) {
|
|
52
|
+
const motion = theme.motion
|
|
53
|
+
validateMotion(motion)
|
|
54
|
+
const factor = { selection: 1.5, layout: 1.8, overlay: 1, data: 2.4, feedback: 1.2 }[kind]
|
|
55
|
+
return {
|
|
56
|
+
type: kind === 'overlay' || kind === 'data' ? ('tween' as const) : ('spring' as const),
|
|
57
|
+
duration: motion.enterDuration * factor,
|
|
58
|
+
ease: motion.ease,
|
|
59
|
+
bounce: kind === 'feedback' ? Math.min(0.2, motion.releaseBounce) : 0,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
48
62
|
import type { MotionTheme, MavisTheme } from './theme/types.js'
|
|
49
63
|
|
|
50
64
|
export const defaultMotion: Readonly<MotionTheme> = Object.freeze({
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface NavigationTransition {
|
|
2
|
+
name?: 'fade' | 'slide' | 'none'
|
|
3
|
+
duration?: number
|
|
4
|
+
}
|
|
5
|
+
/** Shared policy; routers retain guard, history, cancellation and native-back ownership. */
|
|
6
|
+
export function defineNavigationTransition(options: NavigationTransition = {}) {
|
|
7
|
+
const name = options.name ?? 'fade',
|
|
8
|
+
duration = options.duration ?? 220
|
|
9
|
+
if (!['fade', 'slide', 'none'].includes(name))
|
|
10
|
+
throw new TypeError('Navigation transition must be fade, slide or none.')
|
|
11
|
+
if (!Number.isFinite(duration) || duration < 0 || duration > 10000)
|
|
12
|
+
throw new RangeError('Navigation duration must be between 0 and 10000ms.')
|
|
13
|
+
return Object.freeze({ name, duration })
|
|
14
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Formatting options supported by both platform formatters and Intl. */
|
|
2
|
+
export interface NumberFlowFormat {
|
|
3
|
+
style?: 'decimal' | 'currency' | 'percent'
|
|
4
|
+
currency?: string
|
|
5
|
+
currencyDisplay?: 'symbol' | 'code'
|
|
6
|
+
useGrouping?: boolean
|
|
7
|
+
minimumIntegerDigits?: number
|
|
8
|
+
minimumFractionDigits?: number
|
|
9
|
+
maximumFractionDigits?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function resolveNumberFlowFormat(options: NumberFlowFormat = {}): NumberFlowFormat {
|
|
13
|
+
const allowed = new Set([
|
|
14
|
+
'style',
|
|
15
|
+
'currency',
|
|
16
|
+
'currencyDisplay',
|
|
17
|
+
'useGrouping',
|
|
18
|
+
'minimumIntegerDigits',
|
|
19
|
+
'minimumFractionDigits',
|
|
20
|
+
'maximumFractionDigits',
|
|
21
|
+
])
|
|
22
|
+
for (const key of Object.keys(options))
|
|
23
|
+
if (!allowed.has(key))
|
|
24
|
+
throw new RangeError(
|
|
25
|
+
`Unsupported number format option: ${key}. Use formatValue for custom formatting.`,
|
|
26
|
+
)
|
|
27
|
+
const style = options.style ?? 'decimal'
|
|
28
|
+
if (!['decimal', 'currency', 'percent'].includes(style))
|
|
29
|
+
throw new RangeError('Unknown number format style.')
|
|
30
|
+
if (style === 'currency' && !/^[a-z]{3}$/i.test(options.currency ?? ''))
|
|
31
|
+
throw new RangeError('Currency formatting requires a three-letter currency code.')
|
|
32
|
+
if (
|
|
33
|
+
options.currencyDisplay !== undefined &&
|
|
34
|
+
!['symbol', 'code'].includes(options.currencyDisplay)
|
|
35
|
+
)
|
|
36
|
+
throw new RangeError('currencyDisplay must be symbol or code.')
|
|
37
|
+
if (options.useGrouping !== undefined && typeof options.useGrouping !== 'boolean')
|
|
38
|
+
throw new RangeError('useGrouping must be a boolean.')
|
|
39
|
+
for (const [key, min, max] of [
|
|
40
|
+
['minimumIntegerDigits', 1, 21],
|
|
41
|
+
['minimumFractionDigits', 0, 20],
|
|
42
|
+
['maximumFractionDigits', 0, 20],
|
|
43
|
+
] as const) {
|
|
44
|
+
const value = options[key]
|
|
45
|
+
if (value !== undefined && (!Number.isInteger(value) || value < min || value > max))
|
|
46
|
+
throw new RangeError(`${key} must be an integer from ${min} to ${max}.`)
|
|
47
|
+
}
|
|
48
|
+
if (
|
|
49
|
+
options.minimumFractionDigits !== undefined &&
|
|
50
|
+
options.maximumFractionDigits !== undefined &&
|
|
51
|
+
options.minimumFractionDigits > options.maximumFractionDigits
|
|
52
|
+
)
|
|
53
|
+
throw new RangeError('minimumFractionDigits cannot exceed maximumFractionDigits.')
|
|
54
|
+
return {
|
|
55
|
+
...options,
|
|
56
|
+
style,
|
|
57
|
+
...(options.currency ? { currency: options.currency.toUpperCase() } : {}),
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function numberFlowFractionDigits(options: NumberFlowFormat, currencyDigits = 2) {
|
|
62
|
+
const defaults =
|
|
63
|
+
options.style === 'currency' ? Math.max(0, currencyDigits) : options.style === 'percent' ? 0 : 3
|
|
64
|
+
const minimum =
|
|
65
|
+
options.minimumFractionDigits ??
|
|
66
|
+
Math.min(options.style === 'currency' ? defaults : 0, options.maximumFractionDigits ?? defaults)
|
|
67
|
+
return { minimum, maximum: options.maximumFractionDigits ?? Math.max(minimum, defaults) }
|
|
68
|
+
}
|