@getcortexlabs/mavis-core 0.1.0-alpha.8 → 0.1.0-rc.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) 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 +30 -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/date-input.d.ts +10 -0
  19. package/dist/date-input.d.ts.map +1 -0
  20. package/dist/date-input.js +58 -0
  21. package/dist/date-input.js.map +1 -0
  22. package/dist/date-time.d.ts +19 -0
  23. package/dist/date-time.d.ts.map +1 -0
  24. package/dist/date-time.js +27 -0
  25. package/dist/date-time.js.map +1 -0
  26. package/dist/discovery.d.ts +49 -0
  27. package/dist/discovery.d.ts.map +1 -0
  28. package/dist/discovery.js +80 -0
  29. package/dist/discovery.js.map +1 -0
  30. package/dist/experimental-regions.d.ts +10 -0
  31. package/dist/experimental-regions.d.ts.map +1 -1
  32. package/dist/experimental-regions.js +23 -0
  33. package/dist/experimental-regions.js.map +1 -1
  34. package/dist/experimental.d.ts +5 -0
  35. package/dist/experimental.d.ts.map +1 -1
  36. package/dist/experimental.js +29 -0
  37. package/dist/experimental.js.map +1 -1
  38. package/dist/grid.d.ts +3 -0
  39. package/dist/grid.d.ts.map +1 -0
  40. package/dist/grid.js +16 -0
  41. package/dist/grid.js.map +1 -0
  42. package/dist/index.d.ts +17 -3
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +13 -1
  45. package/dist/index.js.map +1 -1
  46. package/dist/input.d.ts +4 -0
  47. package/dist/input.d.ts.map +1 -1
  48. package/dist/input.js.map +1 -1
  49. package/dist/interactive.d.ts +36 -0
  50. package/dist/interactive.d.ts.map +1 -0
  51. package/dist/interactive.js +61 -0
  52. package/dist/interactive.js.map +1 -0
  53. package/dist/link.d.ts +24 -0
  54. package/dist/link.d.ts.map +1 -1
  55. package/dist/link.js +41 -0
  56. package/dist/link.js.map +1 -1
  57. package/dist/motion.d.ts +8 -0
  58. package/dist/motion.d.ts.map +1 -1
  59. package/dist/motion.js +11 -0
  60. package/dist/motion.js.map +1 -1
  61. package/dist/navigation-transition.d.ts +10 -0
  62. package/dist/navigation-transition.d.ts.map +1 -0
  63. package/dist/navigation-transition.js +10 -0
  64. package/dist/navigation-transition.js.map +1 -0
  65. package/dist/number-flow-format.d.ts +16 -0
  66. package/dist/number-flow-format.d.ts.map +1 -0
  67. package/dist/number-flow-format.js +49 -0
  68. package/dist/number-flow-format.js.map +1 -0
  69. package/dist/popover.d.ts +17 -0
  70. package/dist/popover.d.ts.map +1 -0
  71. package/dist/popover.js +19 -0
  72. package/dist/popover.js.map +1 -0
  73. package/dist/section-scroll.d.ts +14 -0
  74. package/dist/section-scroll.d.ts.map +1 -0
  75. package/dist/section-scroll.js +28 -0
  76. package/dist/section-scroll.js.map +1 -0
  77. package/dist/sheet.d.ts +7 -0
  78. package/dist/sheet.d.ts.map +1 -1
  79. package/dist/time.d.ts +34 -0
  80. package/dist/time.d.ts.map +1 -0
  81. package/dist/time.js +78 -0
  82. package/dist/time.js.map +1 -0
  83. package/dist/vue/carousel.d.ts +13 -0
  84. package/dist/vue/carousel.d.ts.map +1 -0
  85. package/dist/vue/carousel.js +136 -0
  86. package/dist/vue/carousel.js.map +1 -0
  87. package/dist/vue/chart.d.ts +194 -0
  88. package/dist/vue/chart.d.ts.map +1 -0
  89. package/dist/vue/chart.js +245 -0
  90. package/dist/vue/chart.js.map +1 -0
  91. package/dist/vue/command-palette.d.ts +129 -0
  92. package/dist/vue/command-palette.d.ts.map +1 -0
  93. package/dist/vue/command-palette.js +190 -0
  94. package/dist/vue/command-palette.js.map +1 -0
  95. package/dist/vue/component-motion.d.ts +17 -0
  96. package/dist/vue/component-motion.d.ts.map +1 -0
  97. package/dist/vue/component-motion.js +83 -0
  98. package/dist/vue/component-motion.js.map +1 -0
  99. package/dist/vue/component-props.d.ts +1505 -402
  100. package/dist/vue/component-props.d.ts.map +1 -1
  101. package/dist/vue/component-props.js +28 -0
  102. package/dist/vue/component-props.js.map +1 -1
  103. package/dist/vue/configurator-props.d.ts +21 -0
  104. package/dist/vue/configurator-props.d.ts.map +1 -1
  105. package/dist/vue/configurator-props.js +6 -0
  106. package/dist/vue/configurator-props.js.map +1 -1
  107. package/dist/vue/configurator.d.ts +3 -3
  108. package/dist/vue/configurator.d.ts.map +1 -1
  109. package/dist/vue/configurator.js +3 -1
  110. package/dist/vue/configurator.js.map +1 -1
  111. package/dist/vue/data-table.d.ts +17 -0
  112. package/dist/vue/data-table.d.ts.map +1 -0
  113. package/dist/vue/data-table.js +133 -0
  114. package/dist/vue/data-table.js.map +1 -0
  115. package/dist/vue/date-calendar.d.ts +2 -0
  116. package/dist/vue/date-calendar.d.ts.map +1 -1
  117. package/dist/vue/date-calendar.js +20 -1
  118. package/dist/vue/date-calendar.js.map +1 -1
  119. package/dist/vue/date-picker.d.ts +48 -13
  120. package/dist/vue/date-picker.d.ts.map +1 -1
  121. package/dist/vue/date-picker.js +67 -74
  122. package/dist/vue/date-picker.js.map +1 -1
  123. package/dist/vue/date-props.d.ts +15 -0
  124. package/dist/vue/date-props.d.ts.map +1 -1
  125. package/dist/vue/date-props.js +4 -0
  126. package/dist/vue/date-props.js.map +1 -1
  127. package/dist/vue/discovery-components.d.ts +50 -0
  128. package/dist/vue/discovery-components.d.ts.map +1 -0
  129. package/dist/vue/discovery-components.js +2 -0
  130. package/dist/vue/discovery-components.js.map +1 -0
  131. package/dist/vue/discovery-controls.d.ts +197 -0
  132. package/dist/vue/discovery-controls.d.ts.map +1 -0
  133. package/dist/vue/discovery-controls.js +185 -0
  134. package/dist/vue/discovery-controls.js.map +1 -0
  135. package/dist/vue/discovery-props.d.ts +249 -0
  136. package/dist/vue/discovery-props.d.ts.map +1 -0
  137. package/dist/vue/discovery-props.js +87 -0
  138. package/dist/vue/discovery-props.js.map +1 -0
  139. package/dist/vue/global-components.d.ts +134 -2
  140. package/dist/vue/global-components.d.ts.map +1 -1
  141. package/dist/vue/index.d.ts +27 -1
  142. package/dist/vue/index.d.ts.map +1 -1
  143. package/dist/vue/index.js +23 -1
  144. package/dist/vue/index.js.map +1 -1
  145. package/dist/vue/interactive-components.d.ts +31 -0
  146. package/dist/vue/interactive-components.d.ts.map +1 -0
  147. package/dist/vue/interactive-components.js +2 -0
  148. package/dist/vue/interactive-components.js.map +1 -0
  149. package/dist/vue/interactive-props.d.ts +254 -0
  150. package/dist/vue/interactive-props.d.ts.map +1 -0
  151. package/dist/vue/interactive-props.js +85 -0
  152. package/dist/vue/interactive-props.js.map +1 -0
  153. package/dist/vue/list-motion.d.ts +7 -0
  154. package/dist/vue/list-motion.d.ts.map +1 -0
  155. package/dist/vue/list-motion.js +28 -0
  156. package/dist/vue/list-motion.js.map +1 -0
  157. package/dist/vue/menu.d.ts +122 -0
  158. package/dist/vue/menu.d.ts.map +1 -0
  159. package/dist/vue/menu.js +79 -0
  160. package/dist/vue/menu.js.map +1 -0
  161. package/dist/vue/navigation-controls.d.ts +125 -0
  162. package/dist/vue/navigation-controls.d.ts.map +1 -0
  163. package/dist/vue/navigation-controls.js +130 -0
  164. package/dist/vue/navigation-controls.js.map +1 -0
  165. package/dist/vue/navigation-props.d.ts +283 -0
  166. package/dist/vue/navigation-props.d.ts.map +1 -0
  167. package/dist/vue/navigation-props.js +82 -0
  168. package/dist/vue/navigation-props.js.map +1 -0
  169. package/dist/vue/navigation.d.ts +7 -0
  170. package/dist/vue/navigation.d.ts.map +1 -0
  171. package/dist/vue/navigation.js +15 -0
  172. package/dist/vue/navigation.js.map +1 -0
  173. package/dist/vue/number-flow.d.ts +75 -0
  174. package/dist/vue/number-flow.d.ts.map +1 -0
  175. package/dist/vue/number-flow.js +57 -0
  176. package/dist/vue/number-flow.js.map +1 -0
  177. package/dist/vue/partition.d.ts +15 -0
  178. package/dist/vue/partition.d.ts.map +1 -0
  179. package/dist/vue/partition.js +42 -0
  180. package/dist/vue/partition.js.map +1 -0
  181. package/dist/vue/platform.d.ts +37 -0
  182. package/dist/vue/platform.d.ts.map +1 -0
  183. package/dist/vue/platform.js +46 -0
  184. package/dist/vue/platform.js.map +1 -0
  185. package/dist/vue/props.d.ts +233 -36
  186. package/dist/vue/props.d.ts.map +1 -1
  187. package/dist/vue/props.js +15 -1
  188. package/dist/vue/props.js.map +1 -1
  189. package/dist/vue/sortable-list.d.ts +24 -0
  190. package/dist/vue/sortable-list.d.ts.map +1 -0
  191. package/dist/vue/sortable-list.js +251 -0
  192. package/dist/vue/sortable-list.js.map +1 -0
  193. package/dist/vue/swipe-actions.d.ts +96 -0
  194. package/dist/vue/swipe-actions.d.ts.map +1 -0
  195. package/dist/vue/swipe-actions.js +174 -0
  196. package/dist/vue/swipe-actions.js.map +1 -0
  197. package/dist/vue/time-picker.d.ts +488 -0
  198. package/dist/vue/time-picker.d.ts.map +1 -0
  199. package/dist/vue/time-picker.js +190 -0
  200. package/dist/vue/time-picker.js.map +1 -0
  201. package/dist/vue/tree-view.d.ts +111 -0
  202. package/dist/vue/tree-view.d.ts.map +1 -0
  203. package/dist/vue/tree-view.js +204 -0
  204. package/dist/vue/tree-view.js.map +1 -0
  205. package/dist/vue/virtual-list.d.ts +26 -0
  206. package/dist/vue/virtual-list.d.ts.map +1 -0
  207. package/dist/vue/virtual-list.js +2 -0
  208. package/dist/vue/virtual-list.js.map +1 -0
  209. package/dist/vue/wayfinding-controls.d.ts +199 -0
  210. package/dist/vue/wayfinding-controls.d.ts.map +1 -0
  211. package/dist/vue/wayfinding-controls.js +330 -0
  212. package/dist/vue/wayfinding-controls.js.map +1 -0
  213. package/dist/vue/wayfinding-props.d.ts +221 -0
  214. package/dist/vue/wayfinding-props.d.ts.map +1 -0
  215. package/dist/vue/wayfinding-props.js +86 -0
  216. package/dist/vue/wayfinding-props.js.map +1 -0
  217. package/dist/vue/workflows.d.ts +2 -2
  218. package/dist/vue/workflows.d.ts.map +1 -1
  219. package/dist/vue/workflows.js +17 -4
  220. package/dist/vue/workflows.js.map +1 -1
  221. package/dist/wayfinding.d.ts +50 -0
  222. package/dist/wayfinding.d.ts.map +1 -0
  223. package/dist/wayfinding.js +54 -0
  224. package/dist/wayfinding.js.map +1 -0
  225. package/package.json +2 -2
  226. package/src/capabilities.ts +31 -4
  227. package/src/chart.ts +151 -0
  228. package/src/collections.ts +87 -0
  229. package/src/contracts.ts +2 -0
  230. package/src/date-input.ts +87 -0
  231. package/src/date-time.ts +37 -0
  232. package/src/discovery.ts +139 -0
  233. package/src/experimental-regions.ts +29 -0
  234. package/src/experimental.ts +40 -0
  235. package/src/grid.ts +19 -0
  236. package/src/index.ts +24 -3
  237. package/src/input.ts +5 -0
  238. package/src/interactive.ts +91 -0
  239. package/src/link.ts +63 -0
  240. package/src/motion.ts +14 -0
  241. package/src/navigation-transition.ts +14 -0
  242. package/src/number-flow-format.ts +68 -0
  243. package/src/popover.ts +38 -0
  244. package/src/section-scroll.ts +46 -0
  245. package/src/sheet.ts +11 -0
  246. package/src/time.ts +83 -0
  247. package/src/vue/carousel.ts +198 -0
  248. package/src/vue/chart.ts +337 -0
  249. package/src/vue/command-palette.ts +235 -0
  250. package/src/vue/component-motion.ts +109 -0
  251. package/src/vue/component-props.ts +57 -0
  252. package/src/vue/configurator-props.ts +6 -0
  253. package/src/vue/configurator.ts +3 -1
  254. package/src/vue/data-table.ts +190 -0
  255. package/src/vue/date-calendar.ts +30 -1
  256. package/src/vue/date-picker.ts +81 -85
  257. package/src/vue/date-props.ts +5 -0
  258. package/src/vue/discovery-components.ts +60 -0
  259. package/src/vue/discovery-controls.ts +241 -0
  260. package/src/vue/discovery-props.ts +92 -0
  261. package/src/vue/global-components.ts +124 -2
  262. package/src/vue/index.ts +46 -0
  263. package/src/vue/interactive-components.ts +29 -0
  264. package/src/vue/interactive-props.ts +90 -0
  265. package/src/vue/list-motion.ts +31 -0
  266. package/src/vue/menu.ts +100 -0
  267. package/src/vue/navigation-controls.ts +159 -0
  268. package/src/vue/navigation-props.ts +87 -0
  269. package/src/vue/navigation.ts +16 -0
  270. package/src/vue/number-flow.ts +83 -0
  271. package/src/vue/partition.ts +49 -0
  272. package/src/vue/platform.ts +73 -0
  273. package/src/vue/props.ts +16 -1
  274. package/src/vue/sortable-list.ts +308 -0
  275. package/src/vue/swipe-actions.ts +226 -0
  276. package/src/vue/time-picker.ts +227 -0
  277. package/src/vue/tree-view.ts +259 -0
  278. package/src/vue/virtual-list.ts +28 -0
  279. package/src/vue/wayfinding-controls.ts +430 -0
  280. package/src/vue/wayfinding-props.ts +97 -0
  281. package/src/vue/workflows.ts +17 -4
  282. package/src/wayfinding.ts +85 -0
@@ -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
+ }
@@ -0,0 +1,337 @@
1
+ import {
2
+ computed,
3
+ defineComponent,
4
+ h,
5
+ markRaw,
6
+ mergeProps,
7
+ onScopeDispose,
8
+ ref,
9
+ watch,
10
+ type Component,
11
+ type PropType,
12
+ } from '@vue/runtime-core'
13
+ import { chartGeometry, type ChartGeometry, type ChartSelection } from '../chart.js'
14
+ import { choiceKey, type ChoiceValue } from '../choice.js'
15
+ import { createMotionSurface } from '../experimental.js'
16
+ import { chartProps } from './wayfinding-props.js'
17
+ import { useMavisTheme } from './theme.js'
18
+
19
+ export const chartPlotProps = {
20
+ geometry: { type: Object as PropType<ChartGeometry>, required: true as const },
21
+ colors: { type: Array as PropType<readonly string[]>, required: true as const },
22
+ type: { type: String as PropType<'line' | 'bar'>, required: true as const },
23
+ height: { type: Number, required: true as const },
24
+ selected: {
25
+ type: Object as PropType<{ category: number; series: number } | null>,
26
+ default: null,
27
+ },
28
+ disabled: Boolean,
29
+ }
30
+ export function createChart(
31
+ ui: {
32
+ Row: Component
33
+ Column: Component
34
+ Box: Component
35
+ Text: Component
36
+ Button: Component
37
+ Reveal: Component
38
+ Select: Component
39
+ Plot: Component
40
+ },
41
+ platform: 'web' | 'native',
42
+ ) {
43
+ return defineComponent({
44
+ name: 'MChart',
45
+ inheritAttrs: false,
46
+ props: chartProps,
47
+ emits: {
48
+ 'update:modelValue': (_selection: ChartSelection | null) => true,
49
+ 'update:hiddenSeries': (_keys: ChoiceValue[]) => true,
50
+ },
51
+ setup(props, { attrs, emit }) {
52
+ const web = platform === 'web'
53
+ const { theme } = useMavisTheme()
54
+ const dataOpen = ref(props.showData)
55
+ watch(
56
+ () => props.showData,
57
+ (value) => {
58
+ dataOpen.value = value
59
+ },
60
+ )
61
+ const allGeometry = computed(() =>
62
+ chartGeometry(props.categories, props.series, props.domain),
63
+ )
64
+ const visible = computed(() =>
65
+ props.series.filter((series) => !props.hiddenSeries.includes(series.key)),
66
+ )
67
+ const geometry = computed(() => ({
68
+ ...allGeometry.value,
69
+ series: allGeometry.value.series.filter(
70
+ (series) => !props.hiddenSeries.includes(series.key),
71
+ ),
72
+ }))
73
+ const selected = computed(() => {
74
+ if (!props.modelValue) return null
75
+ const category = props.categories.findIndex(
76
+ (item) => item.key === props.modelValue!.category,
77
+ )
78
+ const series = visible.value.findIndex((item) => item.key === props.modelValue!.series)
79
+ return category < 0 || series < 0 ? null : { category, series }
80
+ })
81
+ const format = (value: number | null | undefined) =>
82
+ value == null ? props.missingLabel : (props.formatValue?.(value) ?? String(value))
83
+ const colors = computed(() => {
84
+ const palette = [
85
+ theme.value.colors.primary,
86
+ theme.value.colors.accent,
87
+ theme.value.colors.success,
88
+ theme.value.colors.warning,
89
+ theme.value.colors.danger,
90
+ theme.value.colors.muted,
91
+ theme.value.colors.text,
92
+ theme.value.colors.border,
93
+ ]
94
+ return visible.value.map(
95
+ (series) => series.color ?? palette[props.series.indexOf(series) % palette.length]!,
96
+ )
97
+ })
98
+ const summary = computed(() => {
99
+ const point = selected.value
100
+ if (!point) return props.description ?? props.label
101
+ const series = visible.value[point.series]!
102
+ return `${props.categories[point.category]!.label} · ${series.label}: ${format(series.values[point.category])}`
103
+ })
104
+ function choose(category: number, series: number) {
105
+ if (props.disabled || !props.categories[category] || !visible.value[series]) return
106
+ emit('update:modelValue', {
107
+ category: props.categories[category]!.key,
108
+ series: visible.value[series]!.key,
109
+ })
110
+ }
111
+ const surface = markRaw(createMotionSurface())
112
+ function animate() {
113
+ if (surface.available)
114
+ surface.animate(
115
+ { opacity: [0.35, 1], y: [6, 0] },
116
+ { duration: theme.value.motion.enterDuration, ease: 'easeOut' },
117
+ )
118
+ }
119
+ onScopeDispose(surface.use(animate))
120
+ return () => {
121
+ if (!props.label.trim()) throw new TypeError('Chart requires a label.')
122
+ if (!Number.isFinite(props.height) || props.height < 120 || props.height > 800)
123
+ throw new RangeError('Chart height must be between 120 and 800.')
124
+ if (!['line', 'bar'].includes(props.type))
125
+ throw new TypeError('Chart type must be line or bar.')
126
+ // Validate hidden series too; toggling a legend must never reveal invalid data.
127
+ const domain = allGeometry.value
128
+ const hasData = geometry.value.series.some((series) => series.points.some(Boolean))
129
+ return h(
130
+ ui.Column,
131
+ mergeProps({ id: props.id, gap: 'md' }, attrs, {
132
+ class: 'm-chart',
133
+ ...(web ? { role: 'group', 'aria-label': props.label } : {}),
134
+ }),
135
+ () => [
136
+ h(ui.Column, { gap: 'xs' }, () => [
137
+ h(ui.Text, { text: props.label, as: 'h2', variant: 'heading' }),
138
+ props.description
139
+ ? h(ui.Text, { text: props.description, tone: 'muted', variant: 'caption' })
140
+ : null,
141
+ ]),
142
+ h(ui.Row, { gap: 'xs', wrap: true }, () =>
143
+ props.series.map((series) => {
144
+ const shown = !props.hiddenSeries.includes(series.key)
145
+ return h(
146
+ ui.Button,
147
+ {
148
+ key: choiceKey(series.key),
149
+ text: series.label,
150
+ variant: shown ? 'secondary' : 'ghost',
151
+ size: 'sm',
152
+ disabled: props.disabled,
153
+ ...(web
154
+ ? { 'aria-pressed': shown }
155
+ : { accessibilityState: shown ? 'selected' : '' }),
156
+ onClick: () => {
157
+ if (!props.disabled)
158
+ emit(
159
+ 'update:hiddenSeries',
160
+ shown
161
+ ? [...props.hiddenSeries, series.key]
162
+ : props.hiddenSeries.filter((key) => key !== series.key),
163
+ )
164
+ },
165
+ },
166
+ {
167
+ leading: () =>
168
+ h(ui.Box, {
169
+ width: 8,
170
+ height: 8,
171
+ radius: 'full',
172
+ backgroundColor: shown
173
+ ? colors.value[visible.value.indexOf(series)]
174
+ : theme.value.colors.border,
175
+ accessibilityHidden: true,
176
+ }),
177
+ },
178
+ )
179
+ }),
180
+ ),
181
+ // An exact native column prevents measured plot shapes from expanding their own viewport.
182
+ h(
183
+ web ? ui.Row : 'GridLayout',
184
+ web ? { gap: 'xs', align: 'stretch' } : { columns: '56, *', height: props.height },
185
+ () => [
186
+ h(
187
+ ui.Column,
188
+ { col: 0, justify: 'between', width: 56, shrink: 0, height: props.height },
189
+ () =>
190
+ [...domain.ticks].reverse().map((value, index) =>
191
+ h(ui.Text, {
192
+ key: index,
193
+ text: format(value),
194
+ variant: 'caption',
195
+ tone: 'muted',
196
+ align: 'right',
197
+ }),
198
+ ),
199
+ ),
200
+ h(
201
+ ui.Box,
202
+ { col: 1, grow: 1, shrink: 1, height: props.height, motionSurface: surface },
203
+ () =>
204
+ hasData
205
+ ? h(ui.Plot, {
206
+ geometry: geometry.value,
207
+ colors: colors.value,
208
+ type: props.type,
209
+ height: props.height,
210
+ selected: selected.value,
211
+ disabled: props.disabled,
212
+ onSelect: choose,
213
+ })
214
+ : h(
215
+ ui.Column,
216
+ { height: props.height, justify: 'center', align: 'center' },
217
+ () => h(ui.Text, { text: props.emptyLabel, tone: 'muted' }),
218
+ ),
219
+ ),
220
+ ],
221
+ ),
222
+ props.categories.length
223
+ ? h(ui.Row, { justify: 'between', gap: 'sm' }, () => [
224
+ h(ui.Text, {
225
+ text: props.categories[0]!.label,
226
+ variant: 'caption',
227
+ tone: 'muted',
228
+ }),
229
+ props.categories.length > 1
230
+ ? h(ui.Text, {
231
+ text: props.categories[props.categories.length - 1]!.label,
232
+ variant: 'caption',
233
+ tone: 'muted',
234
+ align: 'right',
235
+ })
236
+ : null,
237
+ ])
238
+ : null,
239
+ h(ui.Text, {
240
+ text: summary.value,
241
+ weight: '600',
242
+ ...(web
243
+ ? { role: 'status', 'aria-live': 'polite', 'aria-atomic': 'true' }
244
+ : { accessibilityLiveRegion: 'polite' }),
245
+ }),
246
+ props.categories.length && visible.value.length
247
+ ? h(ui.Row, { gap: 'sm', wrap: true }, () => [
248
+ h(ui.Select, {
249
+ label: props.categoryLabel,
250
+ placeholder: props.categoryLabel,
251
+ grow: 1,
252
+ shrink: 1,
253
+ options: props.categories.map((item) => ({
254
+ value: item.key,
255
+ label: item.label,
256
+ })),
257
+ modelValue: props.modelValue?.category ?? null,
258
+ disabled: props.disabled,
259
+ 'onUpdate:modelValue': (key: ChoiceValue) =>
260
+ choose(
261
+ props.categories.findIndex((item) => item.key === key),
262
+ selected.value?.series ?? 0,
263
+ ),
264
+ }),
265
+ h(ui.Select, {
266
+ label: props.seriesLabel,
267
+ grow: 1,
268
+ shrink: 1,
269
+ options: visible.value.map((item) => ({ value: item.key, label: item.label })),
270
+ modelValue: visible.value[selected.value?.series ?? 0]!.key,
271
+ disabled: props.disabled,
272
+ 'onUpdate:modelValue': (key: ChoiceValue) =>
273
+ choose(
274
+ selected.value?.category ?? 0,
275
+ visible.value.findIndex((item) => item.key === key),
276
+ ),
277
+ }),
278
+ ])
279
+ : null,
280
+ h(ui.Row, { gap: 'sm', wrap: true }, () => [
281
+ h(ui.Button, {
282
+ text: dataOpen.value ? props.hideDataLabel : props.showDataLabel,
283
+ icon: 'table-2',
284
+ variant: 'ghost',
285
+ ...(web ? { 'aria-expanded': dataOpen.value } : {}),
286
+ onClick: () => {
287
+ dataOpen.value = !dataOpen.value
288
+ },
289
+ }),
290
+ selected.value
291
+ ? h(ui.Button, {
292
+ text: props.clearLabel,
293
+ variant: 'ghost',
294
+ disabled: props.disabled,
295
+ onClick: () => {
296
+ if (!props.disabled) emit('update:modelValue', null)
297
+ },
298
+ })
299
+ : null,
300
+ ]),
301
+ h(ui.Reveal, { show: dataOpen.value, gap: 'sm' }, () =>
302
+ h(
303
+ ui.Column,
304
+ { gap: 'sm', ...(web ? { role: 'list', 'aria-label': props.showDataLabel } : {}) },
305
+ () =>
306
+ props.categories.map((category, index) =>
307
+ h(
308
+ ui.Column,
309
+ {
310
+ key: choiceKey(category.key),
311
+ gap: 'xs',
312
+ padding: 'sm',
313
+ radius: 'md',
314
+ backgroundColor: theme.value.colors.surface,
315
+ ...(web ? { role: 'listitem' } : {}),
316
+ },
317
+ () => [
318
+ h(ui.Text, { text: category.label, weight: '600' }),
319
+ ...props.series.map((series) =>
320
+ h(ui.Text, {
321
+ key: choiceKey(series.key),
322
+ text: `${series.label}: ${format(series.values[index])}`,
323
+ variant: 'caption',
324
+ tone: 'muted',
325
+ }),
326
+ ),
327
+ ],
328
+ ),
329
+ ),
330
+ ),
331
+ ),
332
+ ],
333
+ )
334
+ }
335
+ },
336
+ })
337
+ }