@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
@@ -0,0 +1,159 @@
1
+ import { useComponentSelection, useComponentLayout } from './component-motion.js'
2
+ import { defineComponent, h, inject, mergeProps, type Component } from '@vue/runtime-core'
3
+ import { choiceKey } from '../choice.js'
4
+ import { validateNavigation } from '../collections.js'
5
+ import { appBarProps, tabBarProps } from './navigation-props.js'
6
+ import { navigationKey } from './navigation.js'
7
+ import { useMavisTheme } from './theme.js'
8
+
9
+ export function createNavigationControls(
10
+ ui: {
11
+ Box: Component
12
+ Row: Component
13
+ Column: Component
14
+ Text: Component
15
+ Button: Component
16
+ Badge: Component
17
+ },
18
+ platform: 'web' | 'native',
19
+ ) {
20
+ const MAppBar = defineComponent({
21
+ name: 'MAppBar',
22
+ inheritAttrs: false,
23
+ props: appBarProps,
24
+ emits: { back: () => true, error: (_error: unknown) => true },
25
+ setup(props, { attrs, slots, emit }) {
26
+ const navigation = inject(navigationKey, undefined)
27
+ const { theme } = useMavisTheme()
28
+ async function back() {
29
+ try {
30
+ const navigate = props.navigateBack ?? navigation?.back
31
+ if (!navigate) throw new Error('MAppBar back requires navigation or navigateBack.')
32
+ await navigate()
33
+ emit('back')
34
+ } catch (error) {
35
+ emit('error', error)
36
+ }
37
+ }
38
+ return () => {
39
+ if (!props.title.trim()) throw new TypeError('App bars require a title.')
40
+ return h(
41
+ ui.Row,
42
+ mergeProps(
43
+ {
44
+ id: props.id,
45
+ padding: 'md',
46
+ gap: 'md',
47
+ shrink: 0,
48
+ backgroundColor: theme.value.colors.surface,
49
+ },
50
+ attrs,
51
+ platform === 'web'
52
+ ? { role: 'group', 'aria-label': props.title, class: 'm-app-bar' }
53
+ : {},
54
+ ),
55
+ () => [
56
+ props.back
57
+ ? h(ui.Button, {
58
+ icon: 'arrow-left',
59
+ accessibilityLabel: props.backLabel,
60
+ variant: 'ghost',
61
+ onClick: back,
62
+ })
63
+ : null,
64
+ slots.leading?.(),
65
+ h(ui.Column, { grow: 1, shrink: 1, gap: 'xs' }, () => [
66
+ h(ui.Text, { text: props.title, variant: 'heading', as: 'h1' }),
67
+ props.subtitle
68
+ ? h(ui.Text, { text: props.subtitle, variant: 'caption', tone: 'muted' })
69
+ : null,
70
+ ]),
71
+ slots.actions?.(),
72
+ ],
73
+ )
74
+ }
75
+ },
76
+ })
77
+ const MTabBar = defineComponent({
78
+ name: 'MTabBar',
79
+ inheritAttrs: false,
80
+ props: tabBarProps,
81
+ emits: { error: (_error: unknown) => true },
82
+ setup(props, { attrs, emit }) {
83
+ const { theme } = useMavisTheme()
84
+ const selection = useComponentSelection(() => props.modelValue)
85
+ return () => {
86
+ validateNavigation(props.items)
87
+ if (!props.label.trim()) throw new TypeError('Tab bars require a navigation label.')
88
+ return h(
89
+ ui.Row,
90
+ mergeProps(
91
+ {
92
+ id: props.id,
93
+ motionRegion: selection.region,
94
+ gap: 'xs',
95
+ padding: 'sm',
96
+ shrink: 0,
97
+ backgroundColor: theme.value.colors.surface,
98
+ },
99
+ attrs,
100
+ platform === 'web'
101
+ ? {
102
+ role: 'navigation',
103
+ 'aria-label': props.label,
104
+ class: 'm-tab-bar',
105
+ style: props.safeArea
106
+ ? {
107
+ paddingBottom:
108
+ 'max(var(--m-tab-padding, 8px), env(safe-area-inset-bottom))',
109
+ }
110
+ : undefined,
111
+ }
112
+ : { accessibilityLabel: props.label },
113
+ ),
114
+ () =>
115
+ props.items.map((item) => {
116
+ const current = item.value === props.modelValue
117
+ return h(
118
+ ui.Button,
119
+ {
120
+ key: choiceKey(item.value),
121
+ grow: 1,
122
+ shrink: 1,
123
+ text: item.label,
124
+ icon: item.icon,
125
+ href: item.href,
126
+ navigate: item.navigate,
127
+ disabled: props.disabled || item.disabled,
128
+ variant: current ? 'primary' : 'ghost',
129
+ accessibilityLabel: `${item.label}${item.badge !== undefined ? ` ${item.badge}` : ''}${current && platform === 'native' ? `. ${props.currentLabel}` : ''}`,
130
+ ...(platform === 'web' ? { 'aria-current': current ? 'page' : undefined } : {}),
131
+ onError: (error: unknown) => emit('error', error),
132
+ },
133
+ {
134
+ trailing: () =>
135
+ h(ui.Row, { gap: 'xs' }, () => [
136
+ platform === 'web' && item.badge !== undefined ? ' ' : null,
137
+ current
138
+ ? h(ui.Box, {
139
+ width: 5,
140
+ height: 5,
141
+ radius: 'full',
142
+ backgroundColor: theme.value.colors.onPrimary,
143
+ motionSurface: selection.marker,
144
+ accessibilityHidden: true,
145
+ })
146
+ : null,
147
+ item.badge !== undefined
148
+ ? h(ui.Badge, { text: String(item.badge), accessibilityHidden: true })
149
+ : null,
150
+ ]),
151
+ },
152
+ )
153
+ }),
154
+ )
155
+ }
156
+ },
157
+ })
158
+ return { MAppBar, MTabBar }
159
+ }
@@ -0,0 +1,87 @@
1
+ import type { PropType } from '@vue/runtime-core'
2
+ import type { ChoiceValue } from '../choice.js'
3
+ import type { MenuItem, NavigationItem, VirtualItemKey } from '../collections.js'
4
+ import type { PopoverPlacement } from '../popover.js'
5
+ import type { HourCycle, LocalTime, TimeLocale } from '../time.js'
6
+ import { buttonProps, inputProps, spacingProp } from './props.js'
7
+
8
+ export const popoverProps = {
9
+ id: inputProps.id,
10
+ open: Boolean,
11
+ label: { type: String, required: true as const },
12
+ triggerLabel: { type: String, required: true as const },
13
+ icon: buttonProps.icon,
14
+ variant: { ...buttonProps.variant, default: 'secondary' },
15
+ disabled: Boolean,
16
+ placement: { type: String as PropType<PopoverPlacement>, default: 'bottom-start' },
17
+ width: { type: Number, default: 280 },
18
+ padding: { ...spacingProp, default: 'md' },
19
+ /** Menu owns its keyboard behavior; ordinary popovers contain arbitrary controls. */
20
+ role: { type: String as PropType<'dialog' | 'menu'>, default: 'dialog' },
21
+ }
22
+ export const menuProps = {
23
+ ...popoverProps,
24
+ items: { type: Array as PropType<readonly MenuItem[]>, required: true as const },
25
+ }
26
+ export const appBarProps = {
27
+ id: inputProps.id,
28
+ title: { type: String, required: true as const },
29
+ subtitle: String,
30
+ back: Boolean,
31
+ backLabel: { type: String, default: 'Back' },
32
+ /** Optional app-owned callback; otherwise uses the installed navigation service. */
33
+ navigateBack: Function as PropType<() => void | Promise<unknown>>,
34
+ }
35
+ export const tabBarProps = {
36
+ id: inputProps.id,
37
+ label: { type: String, required: true as const },
38
+ modelValue: { type: [String, Number] as PropType<ChoiceValue | null>, default: null },
39
+ items: { type: Array as PropType<readonly NavigationItem[]>, required: true as const },
40
+ disabled: Boolean,
41
+ currentLabel: { type: String, default: 'Current page' },
42
+ /** Web viewport inset; native MScreen already owns the safe area. */
43
+ safeArea: { type: Boolean, default: false },
44
+ }
45
+ export const timePickerProps = {
46
+ id: inputProps.id,
47
+ label: inputProps.label,
48
+ width: inputProps.width,
49
+ grow: inputProps.grow,
50
+ shrink: inputProps.shrink,
51
+ modelValue: { type: String as PropType<LocalTime | null>, default: null },
52
+ draft: { type: String, default: undefined },
53
+ min: String,
54
+ max: String,
55
+ minuteStep: { type: Number, default: 1 },
56
+ locale: { type: String as PropType<TimeLocale>, default: 'en-US' },
57
+ hourCycle: String as PropType<HourCycle>,
58
+ name: inputProps.name,
59
+ disabled: Boolean,
60
+ readonly: Boolean,
61
+ required: Boolean,
62
+ helperText: inputProps.helperText,
63
+ error: inputProps.error,
64
+ placeholder: { type: String, default: undefined },
65
+ chooseLabel: { type: String, default: 'Choose time' },
66
+ confirmLabel: { type: String, default: 'Apply' },
67
+ cancelLabel: { type: String, default: 'Cancel' },
68
+ clearLabel: { type: String, default: 'Clear time' },
69
+ hourLabel: { type: String, default: 'Hour' },
70
+ minuteLabel: { type: String, default: 'Minute' },
71
+ periodLabel: { type: String, default: 'Period' },
72
+ invalidLabel: {
73
+ type: String,
74
+ default: 'Enter a valid time within the allowed range and interval.',
75
+ },
76
+ }
77
+ export const virtualListProps = {
78
+ id: inputProps.id,
79
+ label: { type: String, required: true as const },
80
+ items: { type: Array as PropType<readonly unknown[]>, required: true as const },
81
+ itemKey: { type: [String, Function] as PropType<VirtualItemKey>, default: 'id' },
82
+ rowHeight: { type: Number, required: true as const },
83
+ height: { type: Number, required: true as const },
84
+ overscan: { type: Number, default: 3 },
85
+ initialIndex: { type: Number, default: 0 },
86
+ emptyLabel: { type: String, default: 'No items' },
87
+ }
@@ -0,0 +1,83 @@
1
+ import {
2
+ computed,
3
+ defineComponent,
4
+ h,
5
+ markRaw,
6
+ mergeProps,
7
+ onScopeDispose,
8
+ watch,
9
+ type Component,
10
+ } from '@vue/runtime-core'
11
+ import { createMotionSurface, type MotionPlayback } from '../experimental.js'
12
+ import { resolveNumberFlowFormat, type NumberFlowFormat } from '../number-flow-format.js'
13
+ import { numberFlowProps } from './interactive-props.js'
14
+
15
+ export function createNumberFlow(
16
+ Text: Component,
17
+ platform: 'web' | 'native',
18
+ formatter: (locale: string, options: NumberFlowFormat) => (value: number) => string = (
19
+ locale,
20
+ options,
21
+ ) => new Intl.NumberFormat(locale, options).format,
22
+ ) {
23
+ return defineComponent({
24
+ name: 'MNumberFlow',
25
+ inheritAttrs: false,
26
+ props: numberFlowProps,
27
+ setup(props, { attrs }) {
28
+ const surface = markRaw(createMotionSurface())
29
+ const format = computed(
30
+ () => props.formatValue ?? formatter(props.locale, resolveNumberFlowFormat(props.format)),
31
+ )
32
+ const text = computed(() => {
33
+ if (!Number.isFinite(props.duration) || props.duration <= 0)
34
+ throw new RangeError('MNumberFlow duration must be positive.')
35
+ if (!Number.isFinite(props.value)) throw new RangeError('MNumberFlow value must be finite.')
36
+ return format.value(props.value)
37
+ })
38
+ let playback: MotionPlayback | undefined
39
+ watch(
40
+ () => [props.value, format.value] as const,
41
+ () => {
42
+ if (!props.animated) playback?.stop()
43
+ if (surface.available && props.animated)
44
+ playback = surface.rollTo(props.value, {
45
+ format: format.value,
46
+ duration: props.duration,
47
+ stagger: 24,
48
+ tabular: true,
49
+ })
50
+ },
51
+ { flush: 'pre' },
52
+ )
53
+ watch(
54
+ () => props.animated,
55
+ () => {
56
+ if (!props.animated) playback?.stop()
57
+ },
58
+ )
59
+ onScopeDispose(() => playback?.stop())
60
+ return () =>
61
+ h(
62
+ Text,
63
+ mergeProps(attrs, {
64
+ id: props.id,
65
+ text: text.value,
66
+ variant: props.variant,
67
+ tone: props.tone,
68
+ motionSurface: surface,
69
+ accessibilityLabel: props.label ? `${props.label}: ${text.value}` : text.value,
70
+ ...(platform === 'web'
71
+ ? {
72
+ class: 'm-number-flow',
73
+ role: props.announce ? 'status' : undefined,
74
+ 'aria-live': props.announce ? 'polite' : 'off',
75
+ 'aria-atomic': 'true',
76
+ style: { fontVariantNumeric: 'tabular-nums', whiteSpace: 'nowrap' },
77
+ }
78
+ : { accessibilityLiveRegion: props.announce ? 'polite' : 'none' }),
79
+ }),
80
+ )
81
+ },
82
+ })
83
+ }
@@ -0,0 +1,49 @@
1
+ import { computed, onScopeDispose, ref, watch } from '@vue/runtime-core'
2
+ import { finiteRange, positiveSize } from '../interactive.js'
3
+
4
+ /** Shared transaction: dragging follows input; cancellation restores the owner's starting value. */
5
+ export function usePartition(
6
+ read: () => number,
7
+ options: () => { min: number; max: number; step: number; disabled: boolean },
8
+ emit: (value: number) => void,
9
+ ) {
10
+ const dragging = ref(false)
11
+ const canonical = computed(() => finiteRange(read(), options().min, options().max))
12
+ let origin = 0
13
+ function update(value: number) {
14
+ const config = options()
15
+ if (config.disabled) return
16
+ const step = positiveSize(config.step, 'step')
17
+ const next = finiteRange(
18
+ config.min + Math.round((value - config.min) / step) * step,
19
+ config.min,
20
+ config.max,
21
+ )
22
+ if (next !== canonical.value) emit(Number(next.toFixed(8)))
23
+ }
24
+ function begin() {
25
+ if (options().disabled) return false
26
+ origin = canonical.value
27
+ dragging.value = true
28
+ return true
29
+ }
30
+ function end() {
31
+ dragging.value = false
32
+ }
33
+ function cancel() {
34
+ if (dragging.value) {
35
+ dragging.value = false
36
+ emit(origin)
37
+ }
38
+ }
39
+ watch(
40
+ () => options().disabled,
41
+ (disabled) => {
42
+ if (disabled) cancel()
43
+ },
44
+ )
45
+ onScopeDispose(() => {
46
+ dragging.value = false
47
+ })
48
+ return { canonical, dragging, update, begin, end, cancel }
49
+ }
@@ -0,0 +1,73 @@
1
+ import {
2
+ defineComponent,
3
+ inject,
4
+ type InjectionKey,
5
+ type PropType,
6
+ type SlotsType,
7
+ } from '@vue/runtime-core'
8
+
9
+ export type MavisPlatform = 'web' | 'ios' | 'android'
10
+ export type MavisPlatformTarget = MavisPlatform | 'native'
11
+ export type MavisPlatformContext = Readonly<{
12
+ platform: MavisPlatform
13
+ isWeb: boolean
14
+ isNative: boolean
15
+ isIOS: boolean
16
+ isAndroid: boolean
17
+ }>
18
+
19
+ /** @internal Supplied by the renderer, including services-only installation. */
20
+ export const platformKey: InjectionKey<MavisPlatformContext> = Symbol('mavis-platform')
21
+
22
+ /** @internal No browser globals, viewport detection or mutable process-wide state. */
23
+ export function createPlatformContext(platform: MavisPlatform): MavisPlatformContext {
24
+ if (!['web', 'ios', 'android'].includes(platform)) throw new RangeError('Unknown Mavis platform.')
25
+ return Object.freeze({
26
+ platform,
27
+ isWeb: platform === 'web',
28
+ isNative: platform !== 'web',
29
+ isIOS: platform === 'ios',
30
+ isAndroid: platform === 'android',
31
+ })
32
+ }
33
+
34
+ export function useMavisPlatform(): MavisPlatformContext {
35
+ const platform = inject(platformKey, undefined)
36
+ if (!platform)
37
+ throw new Error(
38
+ 'Install createMavis() or createMavisServices() in this app before using Mavis platform APIs.',
39
+ )
40
+ return platform
41
+ }
42
+
43
+ export const platformProps = {
44
+ only: {
45
+ type: [String, Array] as PropType<MavisPlatformTarget | readonly MavisPlatformTarget[]>,
46
+ required: true as const,
47
+ },
48
+ }
49
+
50
+ /** Only the selected slot is evaluated; excluded children never run setup or mount. */
51
+ export const MPlatform = defineComponent({
52
+ name: 'MPlatform',
53
+ inheritAttrs: false,
54
+ props: platformProps,
55
+ slots: Object as SlotsType<{ default: () => unknown; fallback: () => unknown }>,
56
+ setup(props, { slots }) {
57
+ const platform = useMavisPlatform()
58
+ return () => {
59
+ const targets = Array.isArray(props.only) ? props.only : [props.only]
60
+ if (
61
+ !targets.length ||
62
+ targets.some((target) => !['web', 'native', 'ios', 'android'].includes(target))
63
+ )
64
+ throw new RangeError(
65
+ 'MPlatform.only requires web, native, ios, android, or a non-empty array of these targets.',
66
+ )
67
+ const matches = targets.some(
68
+ (target) => target === platform.platform || (target === 'native' && platform.isNative),
69
+ )
70
+ return matches ? slots.default?.() : slots.fallback?.()
71
+ }
72
+ },
73
+ })
package/src/vue/props.ts CHANGED
@@ -171,8 +171,10 @@ export const skeletonProps = {
171
171
  }
172
172
  export const rowProps = vueProps(rowContract)
173
173
  export const columnProps = vueProps(columnContract)
174
+ const { motionRegion: _columnMotionRegion, ...columnLayoutProps } = columnProps
174
175
  export const gridProps = {
175
176
  ...boxProps,
177
+ motionRegion: columnProps.motionRegion,
176
178
  columns: { type: Number, default: undefined },
177
179
  minColumnWidth: { type: Number, default: undefined },
178
180
  gap: spacingProp,
@@ -350,7 +352,7 @@ export const screenProps = {
350
352
  /** Puts the software keyboard away on a tap outside the editor and, with `scroll`, on a drag towards it. */
351
353
  dismissKeyboard: { type: Boolean, default: true },
352
354
  }
353
- export const revealProps = { ...columnProps, show: Boolean }
355
+ export const revealProps = { ...columnLayoutProps, show: Boolean }
354
356
  export const sheetProps = {
355
357
  /** Web only. Omit to restore the captured opener; return null to leave focus to the application. */
356
358
  returnFocus: {