@getcortexlabs/mavis-core 0.1.0-alpha.9 → 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.
Files changed (245) hide show
  1. package/README.md +2 -2
  2. package/dist/capabilities.d.ts +7 -7
  3. package/dist/capabilities.d.ts.map +1 -1
  4. package/dist/capabilities.js +29 -4
  5. package/dist/capabilities.js.map +1 -1
  6. package/dist/chart.d.ts +43 -0
  7. package/dist/chart.d.ts.map +1 -0
  8. package/dist/chart.js +105 -0
  9. package/dist/chart.js.map +1 -0
  10. package/dist/collections.d.ts +46 -0
  11. package/dist/collections.d.ts.map +1 -0
  12. package/dist/collections.js +48 -0
  13. package/dist/collections.js.map +1 -0
  14. package/dist/contracts.d.ts +20 -0
  15. package/dist/contracts.d.ts.map +1 -1
  16. package/dist/contracts.js +2 -0
  17. package/dist/contracts.js.map +1 -1
  18. package/dist/discovery.d.ts +49 -0
  19. package/dist/discovery.d.ts.map +1 -0
  20. package/dist/discovery.js +80 -0
  21. package/dist/discovery.js.map +1 -0
  22. package/dist/experimental-regions.d.ts +10 -0
  23. package/dist/experimental-regions.d.ts.map +1 -1
  24. package/dist/experimental-regions.js +23 -0
  25. package/dist/experimental-regions.js.map +1 -1
  26. package/dist/experimental.d.ts +5 -0
  27. package/dist/experimental.d.ts.map +1 -1
  28. package/dist/experimental.js +29 -0
  29. package/dist/experimental.js.map +1 -1
  30. package/dist/index.d.ts +12 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +10 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/interactive.d.ts +36 -0
  35. package/dist/interactive.d.ts.map +1 -0
  36. package/dist/interactive.js +61 -0
  37. package/dist/interactive.js.map +1 -0
  38. package/dist/link.d.ts +2 -0
  39. package/dist/link.d.ts.map +1 -1
  40. package/dist/link.js.map +1 -1
  41. package/dist/motion.d.ts +8 -0
  42. package/dist/motion.d.ts.map +1 -1
  43. package/dist/motion.js +11 -0
  44. package/dist/motion.js.map +1 -1
  45. package/dist/navigation-transition.d.ts +10 -0
  46. package/dist/navigation-transition.d.ts.map +1 -0
  47. package/dist/navigation-transition.js +10 -0
  48. package/dist/navigation-transition.js.map +1 -0
  49. package/dist/number-flow-format.d.ts +16 -0
  50. package/dist/number-flow-format.d.ts.map +1 -0
  51. package/dist/number-flow-format.js +49 -0
  52. package/dist/number-flow-format.js.map +1 -0
  53. package/dist/popover.d.ts +17 -0
  54. package/dist/popover.d.ts.map +1 -0
  55. package/dist/popover.js +19 -0
  56. package/dist/popover.js.map +1 -0
  57. package/dist/section-scroll.d.ts +14 -0
  58. package/dist/section-scroll.d.ts.map +1 -0
  59. package/dist/section-scroll.js +28 -0
  60. package/dist/section-scroll.js.map +1 -0
  61. package/dist/time.d.ts +34 -0
  62. package/dist/time.d.ts.map +1 -0
  63. package/dist/time.js +78 -0
  64. package/dist/time.js.map +1 -0
  65. package/dist/vue/carousel.d.ts +13 -0
  66. package/dist/vue/carousel.d.ts.map +1 -0
  67. package/dist/vue/carousel.js +136 -0
  68. package/dist/vue/carousel.js.map +1 -0
  69. package/dist/vue/chart.d.ts +194 -0
  70. package/dist/vue/chart.d.ts.map +1 -0
  71. package/dist/vue/chart.js +245 -0
  72. package/dist/vue/chart.js.map +1 -0
  73. package/dist/vue/command-palette.d.ts +129 -0
  74. package/dist/vue/command-palette.d.ts.map +1 -0
  75. package/dist/vue/command-palette.js +190 -0
  76. package/dist/vue/command-palette.js.map +1 -0
  77. package/dist/vue/component-motion.d.ts +17 -0
  78. package/dist/vue/component-motion.d.ts.map +1 -0
  79. package/dist/vue/component-motion.js +83 -0
  80. package/dist/vue/component-motion.js.map +1 -0
  81. package/dist/vue/component-props.d.ts +1016 -18
  82. package/dist/vue/component-props.d.ts.map +1 -1
  83. package/dist/vue/component-props.js +28 -0
  84. package/dist/vue/component-props.js.map +1 -1
  85. package/dist/vue/configurator.d.ts +2 -2
  86. package/dist/vue/configurator.d.ts.map +1 -1
  87. package/dist/vue/configurator.js +3 -1
  88. package/dist/vue/configurator.js.map +1 -1
  89. package/dist/vue/data-table.d.ts +17 -0
  90. package/dist/vue/data-table.d.ts.map +1 -0
  91. package/dist/vue/data-table.js +133 -0
  92. package/dist/vue/data-table.js.map +1 -0
  93. package/dist/vue/date-calendar.d.ts +2 -0
  94. package/dist/vue/date-calendar.d.ts.map +1 -1
  95. package/dist/vue/date-calendar.js +20 -1
  96. package/dist/vue/date-calendar.js.map +1 -1
  97. package/dist/vue/date-picker.d.ts +8 -8
  98. package/dist/vue/date-props.d.ts +6 -0
  99. package/dist/vue/date-props.d.ts.map +1 -1
  100. package/dist/vue/date-props.js +3 -0
  101. package/dist/vue/date-props.js.map +1 -1
  102. package/dist/vue/discovery-components.d.ts +50 -0
  103. package/dist/vue/discovery-components.d.ts.map +1 -0
  104. package/dist/vue/discovery-components.js +2 -0
  105. package/dist/vue/discovery-components.js.map +1 -0
  106. package/dist/vue/discovery-controls.d.ts +197 -0
  107. package/dist/vue/discovery-controls.d.ts.map +1 -0
  108. package/dist/vue/discovery-controls.js +185 -0
  109. package/dist/vue/discovery-controls.js.map +1 -0
  110. package/dist/vue/discovery-props.d.ts +249 -0
  111. package/dist/vue/discovery-props.d.ts.map +1 -0
  112. package/dist/vue/discovery-props.js +87 -0
  113. package/dist/vue/discovery-props.js.map +1 -0
  114. package/dist/vue/global-components.d.ts +131 -0
  115. package/dist/vue/global-components.d.ts.map +1 -1
  116. package/dist/vue/index.d.ts +25 -0
  117. package/dist/vue/index.d.ts.map +1 -1
  118. package/dist/vue/index.js +21 -0
  119. package/dist/vue/index.js.map +1 -1
  120. package/dist/vue/interactive-components.d.ts +31 -0
  121. package/dist/vue/interactive-components.d.ts.map +1 -0
  122. package/dist/vue/interactive-components.js +2 -0
  123. package/dist/vue/interactive-components.js.map +1 -0
  124. package/dist/vue/interactive-props.d.ts +254 -0
  125. package/dist/vue/interactive-props.d.ts.map +1 -0
  126. package/dist/vue/interactive-props.js +85 -0
  127. package/dist/vue/interactive-props.js.map +1 -0
  128. package/dist/vue/list-motion.d.ts +7 -0
  129. package/dist/vue/list-motion.d.ts.map +1 -0
  130. package/dist/vue/list-motion.js +28 -0
  131. package/dist/vue/list-motion.js.map +1 -0
  132. package/dist/vue/menu.d.ts +122 -0
  133. package/dist/vue/menu.d.ts.map +1 -0
  134. package/dist/vue/menu.js +79 -0
  135. package/dist/vue/menu.js.map +1 -0
  136. package/dist/vue/navigation-controls.d.ts +125 -0
  137. package/dist/vue/navigation-controls.d.ts.map +1 -0
  138. package/dist/vue/navigation-controls.js +130 -0
  139. package/dist/vue/navigation-controls.js.map +1 -0
  140. package/dist/vue/navigation-props.d.ts +283 -0
  141. package/dist/vue/navigation-props.d.ts.map +1 -0
  142. package/dist/vue/navigation-props.js +82 -0
  143. package/dist/vue/navigation-props.js.map +1 -0
  144. package/dist/vue/number-flow.d.ts +75 -0
  145. package/dist/vue/number-flow.d.ts.map +1 -0
  146. package/dist/vue/number-flow.js +57 -0
  147. package/dist/vue/number-flow.js.map +1 -0
  148. package/dist/vue/partition.d.ts +15 -0
  149. package/dist/vue/partition.d.ts.map +1 -0
  150. package/dist/vue/partition.js +42 -0
  151. package/dist/vue/partition.js.map +1 -0
  152. package/dist/vue/platform.d.ts +37 -0
  153. package/dist/vue/platform.d.ts.map +1 -0
  154. package/dist/vue/platform.js +46 -0
  155. package/dist/vue/platform.js.map +1 -0
  156. package/dist/vue/props.d.ts +76 -36
  157. package/dist/vue/props.d.ts.map +1 -1
  158. package/dist/vue/props.js +3 -1
  159. package/dist/vue/props.js.map +1 -1
  160. package/dist/vue/sortable-list.d.ts +24 -0
  161. package/dist/vue/sortable-list.d.ts.map +1 -0
  162. package/dist/vue/sortable-list.js +251 -0
  163. package/dist/vue/sortable-list.js.map +1 -0
  164. package/dist/vue/swipe-actions.d.ts +96 -0
  165. package/dist/vue/swipe-actions.d.ts.map +1 -0
  166. package/dist/vue/swipe-actions.js +174 -0
  167. package/dist/vue/swipe-actions.js.map +1 -0
  168. package/dist/vue/time-picker.d.ts +488 -0
  169. package/dist/vue/time-picker.d.ts.map +1 -0
  170. package/dist/vue/time-picker.js +190 -0
  171. package/dist/vue/time-picker.js.map +1 -0
  172. package/dist/vue/tree-view.d.ts +111 -0
  173. package/dist/vue/tree-view.d.ts.map +1 -0
  174. package/dist/vue/tree-view.js +204 -0
  175. package/dist/vue/tree-view.js.map +1 -0
  176. package/dist/vue/virtual-list.d.ts +26 -0
  177. package/dist/vue/virtual-list.d.ts.map +1 -0
  178. package/dist/vue/virtual-list.js +2 -0
  179. package/dist/vue/virtual-list.js.map +1 -0
  180. package/dist/vue/wayfinding-controls.d.ts +199 -0
  181. package/dist/vue/wayfinding-controls.d.ts.map +1 -0
  182. package/dist/vue/wayfinding-controls.js +330 -0
  183. package/dist/vue/wayfinding-controls.js.map +1 -0
  184. package/dist/vue/wayfinding-props.d.ts +221 -0
  185. package/dist/vue/wayfinding-props.d.ts.map +1 -0
  186. package/dist/vue/wayfinding-props.js +86 -0
  187. package/dist/vue/wayfinding-props.js.map +1 -0
  188. package/dist/vue/workflows.d.ts +2 -2
  189. package/dist/vue/workflows.d.ts.map +1 -1
  190. package/dist/vue/workflows.js +17 -4
  191. package/dist/vue/workflows.js.map +1 -1
  192. package/dist/wayfinding.d.ts +50 -0
  193. package/dist/wayfinding.d.ts.map +1 -0
  194. package/dist/wayfinding.js +54 -0
  195. package/dist/wayfinding.js.map +1 -0
  196. package/package.json +2 -2
  197. package/src/capabilities.ts +30 -4
  198. package/src/chart.ts +151 -0
  199. package/src/collections.ts +87 -0
  200. package/src/contracts.ts +2 -0
  201. package/src/discovery.ts +139 -0
  202. package/src/experimental-regions.ts +29 -0
  203. package/src/experimental.ts +40 -0
  204. package/src/index.ts +18 -1
  205. package/src/interactive.ts +91 -0
  206. package/src/link.ts +2 -0
  207. package/src/motion.ts +14 -0
  208. package/src/navigation-transition.ts +14 -0
  209. package/src/number-flow-format.ts +68 -0
  210. package/src/popover.ts +38 -0
  211. package/src/section-scroll.ts +46 -0
  212. package/src/time.ts +83 -0
  213. package/src/vue/carousel.ts +198 -0
  214. package/src/vue/chart.ts +337 -0
  215. package/src/vue/command-palette.ts +235 -0
  216. package/src/vue/component-motion.ts +109 -0
  217. package/src/vue/component-props.ts +57 -0
  218. package/src/vue/configurator.ts +3 -1
  219. package/src/vue/data-table.ts +190 -0
  220. package/src/vue/date-calendar.ts +30 -1
  221. package/src/vue/date-props.ts +3 -0
  222. package/src/vue/discovery-components.ts +60 -0
  223. package/src/vue/discovery-controls.ts +241 -0
  224. package/src/vue/discovery-props.ts +92 -0
  225. package/src/vue/global-components.ts +121 -0
  226. package/src/vue/index.ts +44 -0
  227. package/src/vue/interactive-components.ts +29 -0
  228. package/src/vue/interactive-props.ts +90 -0
  229. package/src/vue/list-motion.ts +31 -0
  230. package/src/vue/menu.ts +100 -0
  231. package/src/vue/navigation-controls.ts +159 -0
  232. package/src/vue/navigation-props.ts +87 -0
  233. package/src/vue/number-flow.ts +83 -0
  234. package/src/vue/partition.ts +49 -0
  235. package/src/vue/platform.ts +73 -0
  236. package/src/vue/props.ts +3 -1
  237. package/src/vue/sortable-list.ts +308 -0
  238. package/src/vue/swipe-actions.ts +226 -0
  239. package/src/vue/time-picker.ts +227 -0
  240. package/src/vue/tree-view.ts +259 -0
  241. package/src/vue/virtual-list.ts +28 -0
  242. package/src/vue/wayfinding-controls.ts +430 -0
  243. package/src/vue/wayfinding-props.ts +97 -0
  244. package/src/vue/workflows.ts +17 -4
  245. package/src/wayfinding.ts +85 -0
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,19 @@ 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'
@@ -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
+ }
package/src/popover.ts ADDED
@@ -0,0 +1,38 @@
1
+ export type PopoverPlacement = 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end'
2
+ export type PopoverCloseReason = 'trigger' | 'outside' | 'escape' | 'back' | 'select' | 'program'
3
+ export interface PopoverRect {
4
+ x: number
5
+ y: number
6
+ width: number
7
+ height: number
8
+ }
9
+
10
+ /** Coordinates share one CSS-pixel/DIP space. Flip vertically, then clamp to the viewport. */
11
+ export function placePopover(
12
+ anchor: PopoverRect,
13
+ panel: { width: number; height: number },
14
+ viewport: PopoverRect,
15
+ placement: PopoverPlacement,
16
+ rtl = false,
17
+ gap = 8,
18
+ margin = 8,
19
+ ) {
20
+ const bottom = anchor.y + anchor.height + gap
21
+ const top = anchor.y - gap - panel.height
22
+ const lower = viewport.y + viewport.height - margin
23
+ const upper = viewport.y + margin
24
+ let above = placement.startsWith('top')
25
+ if (above && top < upper && bottom + panel.height <= lower) above = false
26
+ else if (!above && bottom + panel.height > lower && top >= upper) above = true
27
+ const end = placement.endsWith('end') !== rtl
28
+ const clamp = (value: number, min: number, max: number) =>
29
+ Math.max(min, Math.min(value, Math.max(min, max)))
30
+ return {
31
+ x: clamp(
32
+ end ? anchor.x + anchor.width - panel.width : anchor.x,
33
+ viewport.x + margin,
34
+ viewport.x + viewport.width - panel.width - margin,
35
+ ),
36
+ y: clamp(above ? top : bottom, upper, lower - panel.height),
37
+ }
38
+ }
@@ -0,0 +1,46 @@
1
+ export type ScrollEdge = 'start' | 'center' | 'end'
2
+ export interface SectionScrollOptions {
3
+ /** [section edge, viewport edge]. Default: ['start', 'end']. */
4
+ start?: readonly [ScrollEdge, ScrollEdge]
5
+ /** [section edge, viewport edge]. Default: ['end', 'start']. */
6
+ end?: readonly [ScrollEdge, ScrollEdge]
7
+ }
8
+ const edge = { start: 0, center: 0.5, end: 1 } as const
9
+ export function validateSectionScroll(options: SectionScrollOptions) {
10
+ for (const value of [options.start, options.end])
11
+ if (
12
+ value !== undefined &&
13
+ (!Array.isArray(value) ||
14
+ value.length !== 2 ||
15
+ value.some((part) => !Object.hasOwn(edge, part)))
16
+ )
17
+ throw new TypeError(
18
+ 'Section points must pair start, center or end for the section and viewport.',
19
+ )
20
+ }
21
+ /** Renderer geometry only; Jolt owns interpolation, scheduling and reduced motion. */
22
+ export function sectionScrollRange(
23
+ top: number,
24
+ height: number,
25
+ viewport: number,
26
+ maximum: number,
27
+ options: SectionScrollOptions,
28
+ ) {
29
+ validateSectionScroll(options)
30
+ if (
31
+ ![top, height, viewport, maximum].every(Number.isFinite) ||
32
+ height < 0 ||
33
+ viewport < 0 ||
34
+ maximum < 0
35
+ )
36
+ throw new RangeError('Section geometry must be finite.')
37
+ const position = ([section, screen]: readonly [ScrollEdge, ScrollEdge]) =>
38
+ top + height * edge[section] - viewport * edge[screen]
39
+ const start = position(options.start ?? ['start', 'end'])
40
+ const end = position(options.end ?? ['end', 'start'])
41
+ if (end < start) throw new RangeError('Section end must follow its start.')
42
+ const clamp = (value: number) => Math.max(0, Math.min(maximum, value))
43
+ const range = [clamp(start), clamp(end)] as const
44
+ // A section with no traversable range settles; never divide by zero or add a clock.
45
+ return { range: range[1] > range[0] ? range : ([0, 1] as const), settled: range[1] <= range[0] }
46
+ }
package/src/time.ts ADDED
@@ -0,0 +1,83 @@
1
+ /** A wall-clock time, independent of date, timezone and daylight-saving transitions. */
2
+ export type LocalTime = string
3
+ export type TimeLocale = 'en-US' | 'pt-BR'
4
+ export type HourCycle = 'h12' | 'h23'
5
+ export interface TimeOptions {
6
+ locale?: TimeLocale
7
+ hourCycle?: HourCycle
8
+ min?: LocalTime
9
+ max?: LocalTime
10
+ minuteStep?: number
11
+ }
12
+ export type TimeValidation =
13
+ | { status: 'empty'; value: null }
14
+ | { status: 'valid'; value: LocalTime }
15
+ | { status: 'incomplete' | 'invalid' | 'range' | 'step'; value: null }
16
+
17
+ export function timeMinutes(value: LocalTime): number {
18
+ if (!/^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value))
19
+ throw new RangeError('Time must use HH:mm between 00:00 and 23:59.')
20
+ return Number(value.slice(0, 2)) * 60 + Number(value.slice(3))
21
+ }
22
+ export function localTime(minutes: number): LocalTime {
23
+ if (!Number.isInteger(minutes) || minutes < 0 || minutes >= 1440)
24
+ throw new RangeError('Time requires an integer minute within one day.')
25
+ return `${String(Math.floor(minutes / 60)).padStart(2, '0')}:${String(minutes % 60).padStart(2, '0')}`
26
+ }
27
+ export function timeOptions(options: TimeOptions = {}) {
28
+ const min = options.min === undefined ? 0 : timeMinutes(options.min)
29
+ const max = options.max === undefined ? 1439 : timeMinutes(options.max)
30
+ const step = options.minuteStep ?? 1
31
+ if (min > max)
32
+ throw new RangeError('Time min must not exceed max; overnight ranges are not supported.')
33
+ if (!Number.isInteger(step) || step < 1 || step > 30 || 60 % step)
34
+ throw new RangeError('minuteStep must be a divisor of 60 between 1 and 30.')
35
+ if (Math.ceil(min / step) * step > max)
36
+ throw new RangeError('Time bounds contain no selectable time.')
37
+ const locale = options.locale ?? 'en-US'
38
+ const cycle = options.hourCycle ?? (locale === 'pt-BR' ? 'h23' : 'h12')
39
+ if (!['en-US', 'pt-BR'].includes(locale) || !['h12', 'h23'].includes(cycle))
40
+ throw new RangeError('Unsupported time locale or hour cycle.')
41
+ return { min, max, step, cycle }
42
+ }
43
+ export function validateTime(value: LocalTime | null, options: TimeOptions = {}): TimeValidation {
44
+ const { min, max, step } = timeOptions(options)
45
+ if (value === null) return { status: 'empty', value: null }
46
+ let minutes: number
47
+ try {
48
+ minutes = timeMinutes(value)
49
+ } catch {
50
+ return { status: 'invalid', value: null }
51
+ }
52
+ if (minutes < min || minutes > max) return { status: 'range', value: null }
53
+ if (minutes % step) return { status: 'step', value: null }
54
+ return { status: 'valid', value }
55
+ }
56
+ /** Deterministic during SSR and on native runtimes without Intl. Never constructs a Date. */
57
+ export function formatTime(value: LocalTime | null, options: TimeOptions = {}): string {
58
+ const { cycle } = timeOptions(options)
59
+ if (value === null) return ''
60
+ const minutes = timeMinutes(value)
61
+ if (cycle === 'h23') return value
62
+ const hour = Math.floor(minutes / 60)
63
+ return `${hour % 12 || 12}:${value.slice(3)} ${hour < 12 ? 'AM' : 'PM'}`
64
+ }
65
+ export function parseTime(draft: string, options: TimeOptions = {}): TimeValidation {
66
+ const { cycle } = timeOptions(options)
67
+ const text = draft.trim()
68
+ if (!text) return { status: 'empty', value: null }
69
+ const match =
70
+ cycle === 'h23' ? /^(\d{1,2}):(\d{2})$/.exec(text) : /^(\d{1,2}):(\d{2})\s*(AM|PM)$/i.exec(text)
71
+ if (!match)
72
+ return {
73
+ status: /^\d{0,2}(?::\d{0,2})?\s*[apm]{0,2}$/i.test(text) ? 'incomplete' : 'invalid',
74
+ value: null,
75
+ }
76
+ let hour = Number(match[1])
77
+ if (Number(match[2]) > 59) return { status: 'invalid', value: null }
78
+ if (cycle === 'h12') {
79
+ if (hour < 1 || hour > 12) return { status: 'invalid', value: null }
80
+ hour = (hour % 12) + (match[3]!.toUpperCase() === 'PM' ? 12 : 0)
81
+ } else if (hour > 23) return { status: 'invalid', value: null }
82
+ return validateTime(localTime(hour * 60 + Number(match[2])), options)
83
+ }
@@ -0,0 +1,198 @@
1
+ import type { CarouselComponent } from './discovery-components.js'
2
+ import {
3
+ computed,
4
+ defineComponent,
5
+ h,
6
+ markRaw,
7
+ mergeProps,
8
+ onScopeDispose,
9
+ ref,
10
+ watch,
11
+ type Component,
12
+ } from '@vue/runtime-core'
13
+ import { choiceKey, type ChoiceValue } from '../choice.js'
14
+ import { collectionKeys } from '../discovery.js'
15
+ import { componentMotion } from '../motion.js'
16
+ import { createMotionSurface } from '../experimental.js'
17
+ import { carouselProps } from './discovery-props.js'
18
+ import { useMavisTheme } from './theme.js'
19
+
20
+ export function createCarousel(
21
+ ui: {
22
+ Column: Component
23
+ Row: Component
24
+ Box: Component
25
+ Text: Component
26
+ Button: Component
27
+ gestures: (
28
+ move: (direction: number) => void,
29
+ direction: { value: number },
30
+ ) => Record<string, unknown>
31
+ },
32
+ platform: 'web' | 'native',
33
+ ) {
34
+ return defineComponent({
35
+ name: 'MCarousel',
36
+ inheritAttrs: false,
37
+ props: carouselProps,
38
+ emits: { 'update:modelValue': (_value: ChoiceValue) => true },
39
+ setup(props, { attrs, slots, emit }) {
40
+ const { theme } = useMavisTheme()
41
+ const keys = computed(() => collectionKeys(props.items, props.itemKey))
42
+ const index = computed(() =>
43
+ Math.max(
44
+ 0,
45
+ keys.value.findIndex((key) => key === props.modelValue),
46
+ ),
47
+ )
48
+ const direction = ref(1)
49
+ const surface = markRaw(createMotionSurface())
50
+ const readingDirection = ref(1)
51
+ let first = true
52
+ onScopeDispose(
53
+ surface.use((motion) => {
54
+ if (!first)
55
+ motion.animate(
56
+ { x: [direction.value * readingDirection.value * 48, 0], opacity: [0.7, 1] },
57
+ componentMotion(theme.value, 'layout'),
58
+ )
59
+ first = false
60
+ const drag = motion.drag({
61
+ axis: 'x',
62
+ snap: { x: [0] },
63
+ onRelease: ({ x, velocityX }) => {
64
+ if (props.disabled) return
65
+ const projected = x + velocityX * 0.12
66
+ if (Math.abs(x) >= 40 || (Math.abs(x) >= 8 && Math.abs(projected) >= 60))
67
+ move((projected < 0 ? 1 : -1) * readingDirection.value)
68
+ },
69
+ })
70
+ const stop = watch(
71
+ () => props.disabled || keys.value.length < 2,
72
+ (disabled) => {
73
+ if (disabled) {
74
+ drag.cancel()
75
+ drag.pause()
76
+ motion.set({ x: 0 })
77
+ } else drag.resume()
78
+ },
79
+ { immediate: true },
80
+ )
81
+ return stop
82
+ }),
83
+ )
84
+ function choose(next: number) {
85
+ if (props.disabled || next === index.value || !keys.value.length) return
86
+ direction.value = next > index.value ? 1 : -1
87
+ emit('update:modelValue', keys.value[next]!)
88
+ }
89
+ function move(amount: number) {
90
+ const count = keys.value.length
91
+ if (!count) return
92
+ const next = props.loop
93
+ ? (index.value + amount + count) % count
94
+ : Math.max(0, Math.min(count - 1, index.value + amount))
95
+ choose(next)
96
+ }
97
+ watch(index, (next, previous) => {
98
+ direction.value = next > previous ? 1 : -1
99
+ })
100
+ const gestures = ui.gestures(move, readingDirection)
101
+ return () =>
102
+ h(
103
+ ui.Column,
104
+ mergeProps(
105
+ { id: props.id, gap: 'md' },
106
+ attrs,
107
+ platform === 'web'
108
+ ? {
109
+ class: 'm-carousel',
110
+ role: 'region',
111
+ 'aria-roledescription': 'carousel',
112
+ 'aria-label': props.label,
113
+ }
114
+ : {},
115
+ ),
116
+ () => [
117
+ h(ui.Row, { justify: 'between', gap: 'md', wrap: true }, () => [
118
+ h(ui.Text, { as: 'h2', text: props.label, variant: 'heading' }),
119
+ h(ui.Text, {
120
+ text: keys.value.length ? `${index.value + 1} / ${keys.value.length}` : '0 / 0',
121
+ tone: 'muted',
122
+ variant: 'caption',
123
+ ...(platform === 'web'
124
+ ? { role: 'status', 'aria-live': 'polite', 'aria-atomic': 'true' }
125
+ : { accessibilityLiveRegion: 'polite' }),
126
+ }),
127
+ ]),
128
+ keys.value.length
129
+ ? h(
130
+ ui.Box,
131
+ mergeProps(
132
+ { radius: 'lg' },
133
+ gestures,
134
+ platform === 'web' ? { style: { overflow: 'clip', touchAction: 'pan-y' } } : {},
135
+ ),
136
+ () =>
137
+ h(
138
+ ui.Box,
139
+ {
140
+ key: choiceKey(keys.value[index.value]!),
141
+ motionSurface: surface,
142
+ ...(platform === 'web'
143
+ ? {
144
+ role: 'group',
145
+ 'aria-roledescription': 'slide',
146
+ 'aria-label': `${props.slideLabel} ${index.value + 1} / ${keys.value.length}`,
147
+ }
148
+ : {}),
149
+ },
150
+ () =>
151
+ slots.default?.({
152
+ item: props.items[index.value],
153
+ index: index.value,
154
+ itemKey: keys.value[index.value],
155
+ }),
156
+ ),
157
+ )
158
+ : (slots.empty?.() ?? h(ui.Text, { text: props.emptyLabel, tone: 'muted' })),
159
+ h(ui.Row, { justify: 'between', gap: 'sm' }, () => [
160
+ h(ui.Button, {
161
+ icon: 'arrow-left',
162
+ variant: 'secondary',
163
+ accessibilityLabel: props.previousLabel,
164
+ disabled:
165
+ props.disabled || keys.value.length < 2 || (!props.loop && index.value === 0),
166
+ onClick: () => move(-1),
167
+ }),
168
+ h(ui.Row, { gap: 'xs', wrap: true, justify: 'center', shrink: 1 }, () =>
169
+ keys.value.map((key, n) =>
170
+ h(ui.Button, {
171
+ key: choiceKey(key),
172
+ text: String(n + 1),
173
+ variant: n === index.value ? 'primary' : 'ghost',
174
+ accessibilityLabel: `${props.slideLabel} ${n + 1}`,
175
+ disabled: props.disabled,
176
+ ...(platform === 'web'
177
+ ? { 'aria-current': n === index.value ? 'true' : undefined }
178
+ : {}),
179
+ onClick: () => choose(n),
180
+ }),
181
+ ),
182
+ ),
183
+ h(ui.Button, {
184
+ icon: 'arrow-right',
185
+ variant: 'secondary',
186
+ accessibilityLabel: props.nextLabel,
187
+ disabled:
188
+ props.disabled ||
189
+ keys.value.length < 2 ||
190
+ (!props.loop && index.value === keys.value.length - 1),
191
+ onClick: () => move(1),
192
+ }),
193
+ ]),
194
+ ],
195
+ )
196
+ },
197
+ }) as unknown as CarouselComponent
198
+ }