@getcortexlabs/mavis-core 0.1.0-rc.11.1 → 0.1.0-rc.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) 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 +23 -4
  5. package/dist/capabilities.js.map +1 -1
  6. package/dist/creative-controls.d.ts +47 -0
  7. package/dist/creative-controls.d.ts.map +1 -0
  8. package/dist/creative-controls.js +112 -0
  9. package/dist/creative-controls.js.map +1 -0
  10. package/dist/dashboard.d.ts +72 -0
  11. package/dist/dashboard.d.ts.map +1 -0
  12. package/dist/dashboard.js +115 -0
  13. package/dist/dashboard.js.map +1 -0
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +3 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/screen-components.d.ts +45 -0
  19. package/dist/screen-components.d.ts.map +1 -0
  20. package/dist/screen-components.js +23 -0
  21. package/dist/screen-components.js.map +1 -0
  22. package/dist/vue/animated-text.d.ts +101 -0
  23. package/dist/vue/animated-text.d.ts.map +1 -0
  24. package/dist/vue/animated-text.js +56 -0
  25. package/dist/vue/animated-text.js.map +1 -0
  26. package/dist/vue/component-props.d.ts +692 -3
  27. package/dist/vue/component-props.d.ts.map +1 -1
  28. package/dist/vue/component-props.js +22 -0
  29. package/dist/vue/component-props.js.map +1 -1
  30. package/dist/vue/composer.d.ts +159 -0
  31. package/dist/vue/composer.d.ts.map +1 -0
  32. package/dist/vue/composer.js +142 -0
  33. package/dist/vue/composer.js.map +1 -0
  34. package/dist/vue/configurator.d.ts +1 -1
  35. package/dist/vue/creative-controls.d.ts +328 -0
  36. package/dist/vue/creative-controls.d.ts.map +1 -0
  37. package/dist/vue/creative-controls.js +396 -0
  38. package/dist/vue/creative-controls.js.map +1 -0
  39. package/dist/vue/creative-props.d.ts +260 -0
  40. package/dist/vue/creative-props.d.ts.map +1 -0
  41. package/dist/vue/creative-props.js +92 -0
  42. package/dist/vue/creative-props.js.map +1 -0
  43. package/dist/vue/dashboard-charts.d.ts +240 -0
  44. package/dist/vue/dashboard-charts.d.ts.map +1 -0
  45. package/dist/vue/dashboard-charts.js +263 -0
  46. package/dist/vue/dashboard-charts.js.map +1 -0
  47. package/dist/vue/dashboard-effects.d.ts +211 -0
  48. package/dist/vue/dashboard-effects.d.ts.map +1 -0
  49. package/dist/vue/dashboard-effects.js +235 -0
  50. package/dist/vue/dashboard-effects.js.map +1 -0
  51. package/dist/vue/dashboard-props.d.ts +244 -0
  52. package/dist/vue/dashboard-props.d.ts.map +1 -0
  53. package/dist/vue/dashboard-props.js +94 -0
  54. package/dist/vue/dashboard-props.js.map +1 -0
  55. package/dist/vue/discovery-controls.d.ts +1 -1
  56. package/dist/vue/global-components.d.ts +106 -0
  57. package/dist/vue/global-components.d.ts.map +1 -1
  58. package/dist/vue/index.d.ts +16 -0
  59. package/dist/vue/index.d.ts.map +1 -1
  60. package/dist/vue/index.js +16 -0
  61. package/dist/vue/index.js.map +1 -1
  62. package/dist/vue/kanban.d.ts +150 -0
  63. package/dist/vue/kanban.d.ts.map +1 -0
  64. package/dist/vue/kanban.js +267 -0
  65. package/dist/vue/kanban.js.map +1 -0
  66. package/dist/vue/marquee.d.ts +96 -0
  67. package/dist/vue/marquee.d.ts.map +1 -0
  68. package/dist/vue/marquee.js +186 -0
  69. package/dist/vue/marquee.js.map +1 -0
  70. package/dist/vue/pin-cell.d.ts +14 -0
  71. package/dist/vue/pin-cell.d.ts.map +1 -0
  72. package/dist/vue/pin-cell.js +19 -0
  73. package/dist/vue/pin-cell.js.map +1 -0
  74. package/dist/vue/pin-input.d.ts +14 -0
  75. package/dist/vue/pin-input.d.ts.map +1 -0
  76. package/dist/vue/pin-input.js +23 -0
  77. package/dist/vue/pin-input.js.map +1 -0
  78. package/dist/vue/props.d.ts +6 -6
  79. package/dist/vue/screen-component-props.d.ts +236 -0
  80. package/dist/vue/screen-component-props.d.ts.map +1 -0
  81. package/dist/vue/screen-component-props.js +90 -0
  82. package/dist/vue/screen-component-props.js.map +1 -0
  83. package/dist/vue/scroll-frame.d.ts +223 -0
  84. package/dist/vue/scroll-frame.d.ts.map +1 -0
  85. package/dist/vue/scroll-frame.js +346 -0
  86. package/dist/vue/scroll-frame.js.map +1 -0
  87. package/dist/vue/speed-dial.d.ts +73 -0
  88. package/dist/vue/speed-dial.d.ts.map +1 -0
  89. package/dist/vue/speed-dial.js +78 -0
  90. package/dist/vue/speed-dial.js.map +1 -0
  91. package/dist/vue/swipe-deck.d.ts +120 -0
  92. package/dist/vue/swipe-deck.d.ts.map +1 -0
  93. package/dist/vue/swipe-deck.js +229 -0
  94. package/dist/vue/swipe-deck.js.map +1 -0
  95. package/dist/vue/time-picker.d.ts +2 -2
  96. package/dist/vue/tour.d.ts +120 -0
  97. package/dist/vue/tour.d.ts.map +1 -0
  98. package/dist/vue/tour.js +165 -0
  99. package/dist/vue/tour.js.map +1 -0
  100. package/dist/vue/tree-view.d.ts +1 -1
  101. package/package.json +1 -1
  102. package/src/capabilities.ts +24 -4
  103. package/src/creative-controls.ts +169 -0
  104. package/src/dashboard.ts +164 -0
  105. package/src/index.ts +5 -0
  106. package/src/screen-components.ts +59 -0
  107. package/src/vue/animated-text.ts +72 -0
  108. package/src/vue/component-props.ts +47 -0
  109. package/src/vue/composer.ts +192 -0
  110. package/src/vue/creative-controls.ts +524 -0
  111. package/src/vue/creative-props.ts +94 -0
  112. package/src/vue/dashboard-charts.ts +346 -0
  113. package/src/vue/dashboard-effects.ts +304 -0
  114. package/src/vue/dashboard-props.ts +95 -0
  115. package/src/vue/global-components.ts +116 -0
  116. package/src/vue/index.ts +20 -0
  117. package/src/vue/kanban.ts +360 -0
  118. package/src/vue/marquee.ts +248 -0
  119. package/src/vue/pin-cell.ts +26 -0
  120. package/src/vue/pin-input.ts +31 -0
  121. package/src/vue/screen-component-props.ts +92 -0
  122. package/src/vue/scroll-frame.ts +429 -0
  123. package/src/vue/speed-dial.ts +108 -0
  124. package/src/vue/swipe-deck.ts +277 -0
  125. package/src/vue/tour.ts +239 -0
@@ -0,0 +1,346 @@
1
+ import {
2
+ computed,
3
+ defineComponent,
4
+ h,
5
+ markRaw,
6
+ mergeProps,
7
+ onScopeDispose,
8
+ ref,
9
+ watch,
10
+ type Component,
11
+ } from '@vue/runtime-core'
12
+ import { dashboardNumber, donutGeometry, donutPath, sparklineGeometry } from '../dashboard.js'
13
+ import { createMotionSurface, type MotionShape } from '../experimental.js'
14
+ import { componentMotion } from '../motion.js'
15
+ import { dashboardShapeProps, donutChartProps, sparklineProps } from './dashboard-props.js'
16
+ import { useMavisTheme } from './theme.js'
17
+
18
+ export interface DashboardUI {
19
+ Box: Component
20
+ Column: Component
21
+ Row: Component
22
+ Stack: Component
23
+ Text: Component
24
+ Button: Component
25
+ NumberFlow: Component
26
+ Shape: Component
27
+ Environment: Component
28
+ Plot: Component
29
+ }
30
+ /** Same Jolt shape presentation on SVG and native layers, with canonical SSR fallback. */
31
+ export function createDashboardShape(
32
+ Box: Component,
33
+ Fallback: Component,
34
+ platform: 'web' | 'native',
35
+ ) {
36
+ return defineComponent({
37
+ name: 'MDashboardShape',
38
+ inheritAttrs: false,
39
+ props: dashboardShapeProps,
40
+ setup(props, { attrs }) {
41
+ const { theme } = useMavisTheme(),
42
+ surface = markRaw(createMotionSurface()),
43
+ ready = ref(false)
44
+ let shape: MotionShape | undefined
45
+ onScopeDispose(
46
+ surface.use((owner) => {
47
+ const stop = watch(
48
+ () => [...props.viewBox, props.color, props.strokeWidth].join('|'),
49
+ () => {
50
+ shape?.dispose()
51
+ shape = undefined
52
+ ready.value = false
53
+ if (!owner.supports('shape')) return
54
+ shape = owner.shape({
55
+ d: props.d,
56
+ viewBox: props.viewBox,
57
+ stroke: props.color,
58
+ fill: 'transparent',
59
+ strokeWidth: props.strokeWidth,
60
+ lineCap: 'round',
61
+ lineJoin: 'round',
62
+ strokeStart: props.start,
63
+ strokeEnd: props.animated ? props.start : props.end,
64
+ })
65
+ ready.value = true
66
+ if (props.animated)
67
+ shape.animate({ strokeEnd: props.end }, componentMotion(theme.value, 'data'))
68
+ },
69
+ { immediate: true },
70
+ )
71
+ return () => {
72
+ stop()
73
+ shape?.dispose()
74
+ shape = undefined
75
+ ready.value = false
76
+ }
77
+ }),
78
+ )
79
+ watch(
80
+ () => [props.d, props.start, props.end, props.animated] as const,
81
+ (next, previous) => {
82
+ if (!shape) return
83
+ const values = { d: props.d, strokeStart: props.start, strokeEnd: props.end }
84
+ // Different null gaps/point counts cannot be interpolated as one path.
85
+ const compatible =
86
+ previous?.[0].replace(/[^MLAZ]/g, '') === next[0].replace(/[^MLAZ]/g, '')
87
+ if (props.animated && compatible)
88
+ shape.animate(values, componentMotion(theme.value, 'data'))
89
+ else {
90
+ shape.stop()
91
+ shape.set(values)
92
+ }
93
+ },
94
+ )
95
+ return () =>
96
+ h(
97
+ Box,
98
+ mergeProps(attrs, {
99
+ motionSurface: surface,
100
+ width: '100%',
101
+ height: '100%',
102
+ accessibilityHidden: true,
103
+ ...(platform === 'web'
104
+ ? {
105
+ style: {
106
+ gridArea: '1 / 1',
107
+ pointerEvents: 'none',
108
+ minWidth: 0,
109
+ minHeight: 0,
110
+ position: 'relative',
111
+ overflow: 'hidden',
112
+ },
113
+ }
114
+ : { isUserInteractionEnabled: false }),
115
+ }),
116
+ () => h(Fallback, { ...props, hidden: ready.value }),
117
+ )
118
+ },
119
+ })
120
+ }
121
+ export function createDonutChart(ui: DashboardUI, platform: 'web' | 'native') {
122
+ return defineComponent({
123
+ name: 'MDonutChart',
124
+ inheritAttrs: false,
125
+ props: donutChartProps,
126
+ emits: { 'update:modelValue': (_value: string | null) => true },
127
+ setup(props, { attrs, emit }) {
128
+ const { theme } = useMavisTheme(),
129
+ geometry = computed(() => donutGeometry(props.segments))
130
+ const format = (n: number) => props.formatValue?.(n) ?? String(Math.round(n * 100) / 100)
131
+ return () => {
132
+ dashboardNumber(props.size, 100, 800, 'size')
133
+ dashboardNumber(props.strokeWidth, 1, 20, 'strokeWidth')
134
+ const selected = geometry.value.segments.find((s) => s.id === props.modelValue)
135
+ const palette = [
136
+ theme.value.colors.primary,
137
+ '#51847B',
138
+ '#BF733E',
139
+ '#6366A4',
140
+ '#B75959',
141
+ '#527F9C',
142
+ ]
143
+ return h(
144
+ ui.Column,
145
+ mergeProps(attrs, {
146
+ id: props.id,
147
+ gap: 'md',
148
+ ...(platform === 'web'
149
+ ? { class: 'm-donut-chart', role: 'group', 'aria-label': props.label }
150
+ : { accessibilityLabel: props.label }),
151
+ }),
152
+ () => [
153
+ h(ui.Text, { text: props.label, variant: 'heading' }),
154
+ h(
155
+ ui.Box,
156
+ {
157
+ width: props.size,
158
+ height: props.size,
159
+ ...(platform === 'web'
160
+ ? {
161
+ style: {
162
+ display: 'grid',
163
+ maxWidth: '100%',
164
+ aspectRatio: '1',
165
+ height: 'auto',
166
+ },
167
+ }
168
+ : {}),
169
+ accessibilityHidden: true,
170
+ },
171
+ () => [
172
+ h(ui.Shape, {
173
+ d: donutPath,
174
+ viewBox: [0, 0, 100, 100],
175
+ color: theme.value.colors.border,
176
+ strokeWidth: props.strokeWidth,
177
+ animated: false,
178
+ }),
179
+ ...geometry.value.segments
180
+ .filter((s) => s.ratio > 0)
181
+ .map((s) => {
182
+ const index = props.segments.findIndex((v) => v.id === s.id),
183
+ gap = Math.min(s.ratio / 4, 0.008)
184
+ return h(ui.Shape, {
185
+ key: s.id,
186
+ d: donutPath,
187
+ viewBox: [0, 0, 100, 100],
188
+ color: s.color ?? palette[index % palette.length],
189
+ strokeWidth: props.strokeWidth + (selected?.id === s.id ? 2 : 0),
190
+ start: s.start + gap,
191
+ end: s.end - gap,
192
+ animated: props.animated,
193
+ ...(platform === 'web'
194
+ ? { style: { opacity: selected && selected.id !== s.id ? 0.35 : 1 } }
195
+ : { opacity: selected && selected.id !== s.id ? 0.35 : 1 }),
196
+ })
197
+ }),
198
+ h(
199
+ ui.Column,
200
+ {
201
+ align: 'center',
202
+ justify: 'center',
203
+ ...(platform === 'web'
204
+ ? { style: { gridArea: '1 / 1', pointerEvents: 'none' } }
205
+ : { verticalAlignment: 'middle' }),
206
+ },
207
+ () => [
208
+ h(ui.NumberFlow, {
209
+ value: selected?.value ?? geometry.value.total,
210
+ animated: props.animated && props.animateNumber,
211
+ formatValue: format,
212
+ variant: 'display',
213
+ }),
214
+ h(ui.Text, {
215
+ text: selected?.label ?? props.totalLabel,
216
+ variant: 'caption',
217
+ tone: 'muted',
218
+ }),
219
+ ],
220
+ ),
221
+ ],
222
+ ),
223
+ h(ui.Text, {
224
+ text: `${props.totalLabel}: ${format(geometry.value.total)}`,
225
+ variant: 'caption',
226
+ ...(platform === 'web' ? { 'aria-live': 'polite', class: 'm-sr-only' } : {}),
227
+ }),
228
+ geometry.value.total === 0
229
+ ? h(ui.Text, { text: props.emptyLabel, tone: 'muted' })
230
+ : null,
231
+ ...geometry.value.segments.map((s, index) =>
232
+ h(
233
+ ui.Button,
234
+ {
235
+ key: s.id,
236
+ text: `${s.label} · ${format(s.value)} · ${Math.round(s.ratio * 100)}%`,
237
+ variant: selected?.id === s.id ? 'secondary' : 'ghost',
238
+ disabled: props.disabled,
239
+ ...(platform === 'web'
240
+ ? { 'aria-pressed': selected?.id === s.id }
241
+ : { accessibilityState: { selected: selected?.id === s.id } }),
242
+ onClick: () => {
243
+ if (!props.disabled)
244
+ emit('update:modelValue', selected?.id === s.id ? null : s.id)
245
+ },
246
+ },
247
+ {
248
+ leading: () =>
249
+ h(ui.Box, {
250
+ width: 10,
251
+ height: 10,
252
+ radius: 'full',
253
+ backgroundColor: s.color ?? palette[index % palette.length],
254
+ accessibilityHidden: true,
255
+ }),
256
+ },
257
+ ),
258
+ ),
259
+ ],
260
+ )
261
+ }
262
+ },
263
+ })
264
+ }
265
+ export function createSparkline(ui: DashboardUI, platform: 'web' | 'native') {
266
+ return defineComponent({
267
+ name: 'MSparkline',
268
+ inheritAttrs: false,
269
+ props: sparklineProps,
270
+ setup(props, { attrs }) {
271
+ const { theme } = useMavisTheme(),
272
+ open = ref(false),
273
+ width = ref(100)
274
+ const geometry = computed(() =>
275
+ sparklineGeometry(props.points, props.domain, width.value, props.height),
276
+ )
277
+ return () => {
278
+ dashboardNumber(props.height, 24, 240, 'height')
279
+ const data = props.points.filter((p) => p.value !== null),
280
+ last = data.at(-1),
281
+ first = data[0]
282
+ const format = (n: number) => props.formatValue?.(n) ?? String(n)
283
+ const summary =
284
+ last && first
285
+ ? `${props.label}: ${format(last.value!)} (${first.label}: ${format(first.value!)}, ${last.label}: ${format(last.value!)})`
286
+ : `${props.label}: ${props.emptyLabel}`
287
+ return h(
288
+ ui.Column,
289
+ mergeProps(attrs, {
290
+ id: props.id,
291
+ gap: 'xs',
292
+ ...(platform === 'web'
293
+ ? { class: 'm-sparkline', role: 'group', 'aria-label': props.label }
294
+ : { accessibilityLabel: props.label }),
295
+ }),
296
+ () => [
297
+ h(
298
+ ui.Plot,
299
+ {
300
+ height: props.height,
301
+ onWidth: (value: number) => {
302
+ if (Number.isFinite(value) && value > 0) width.value = value
303
+ },
304
+ width: '100%',
305
+ accessibilityHidden: true,
306
+ ...(platform === 'web' ? { style: { display: 'grid', minWidth: 0 } } : {}),
307
+ },
308
+ () =>
309
+ geometry.value.paths.map((path) =>
310
+ h(ui.Shape, {
311
+ key: path.id,
312
+ d: path.d,
313
+ viewBox: [0, 0, width.value, props.height],
314
+ color: props.color ?? theme.value.colors.primary,
315
+ strokeWidth: 2.5,
316
+ animated: props.animated,
317
+ }),
318
+ ),
319
+ ),
320
+ h(ui.Text, { text: summary, variant: 'caption', tone: 'muted' }),
321
+ h(ui.Button, {
322
+ text: props.dataLabel,
323
+ size: 'sm',
324
+ variant: 'ghost',
325
+ ...(platform === 'web' ? { 'aria-expanded': open.value || props.showData } : {}),
326
+ onClick: () => {
327
+ open.value = !open.value
328
+ },
329
+ }),
330
+ open.value || props.showData
331
+ ? h(ui.Column, { gap: 'xs' }, () =>
332
+ props.points.map((p) =>
333
+ h(ui.Text, {
334
+ key: p.id,
335
+ text: `${p.label}: ${p.value === null ? '—' : format(p.value)}`,
336
+ variant: 'caption',
337
+ }),
338
+ ),
339
+ )
340
+ : null,
341
+ ],
342
+ )
343
+ }
344
+ },
345
+ })
346
+ }
@@ -0,0 +1,304 @@
1
+ import {
2
+ computed,
3
+ defineComponent,
4
+ h,
5
+ markRaw,
6
+ mergeProps,
7
+ onScopeDispose,
8
+ ref,
9
+ watch,
10
+ } from '@vue/runtime-core'
11
+ import { dashboardNumber, effectColors } from '../dashboard.js'
12
+ import {
13
+ createMotionSurface,
14
+ type MotionDecoration,
15
+ type MotionGradient,
16
+ type MotionPlayback,
17
+ } from '../experimental.js'
18
+ import { componentMotion } from '../motion.js'
19
+ import { confettiProps, gradientBackgroundProps, particleFieldProps } from './dashboard-props.js'
20
+ import type { DashboardUI } from './dashboard-charts.js'
21
+ import { useMavisTheme } from './theme.js'
22
+
23
+ export interface DashboardEnvironment {
24
+ reduced: boolean
25
+ paused: boolean
26
+ }
27
+ export function createDashboardEffects(ui: DashboardUI, platform: 'web' | 'native') {
28
+ const MGradientBackground = defineComponent({
29
+ name: 'MGradientBackground',
30
+ inheritAttrs: false,
31
+ props: gradientBackgroundProps,
32
+ setup(props, { attrs, slots }) {
33
+ const { theme } = useMavisTheme(),
34
+ surface = markRaw(createMotionSurface()),
35
+ environment = ref<DashboardEnvironment>({ reduced: true, paused: true })
36
+ let gradient: MotionGradient | undefined,
37
+ playback: MotionPlayback | undefined,
38
+ generation = 0
39
+ const running = computed(
40
+ () =>
41
+ props.active && props.animated && !environment.value.reduced && !environment.value.paused,
42
+ )
43
+ function stop() {
44
+ generation++
45
+ playback?.stop()
46
+ playback = undefined
47
+ gradient?.stop()
48
+ }
49
+ function loop(angle: number) {
50
+ if (!running.value || !gradient) return
51
+ const token = generation,
52
+ started = Date.now()
53
+ playback = gradient.animate(
54
+ { angle: angle + 180 },
55
+ { type: 'tween', duration: props.duration, ease: 'linear' },
56
+ )
57
+ void playback.finished.then((done) => {
58
+ if (done && token === generation && Date.now() - started > 16) loop(angle + 180)
59
+ })
60
+ }
61
+ function update() {
62
+ stop()
63
+ if (!gradient) return
64
+ const values = {
65
+ colors: effectColors(props.colors),
66
+ angle: dashboardNumber(props.angle, -36000, 36000, 'angle'),
67
+ }
68
+ if (props.animated && !environment.value.reduced && !environment.value.paused)
69
+ gradient.animate(values, componentMotion(theme.value, 'data'))
70
+ else gradient.set(values)
71
+ if (running.value) loop(props.angle)
72
+ }
73
+ onScopeDispose(
74
+ surface.use((owner) => {
75
+ if (!owner.supports('gradient')) return
76
+ gradient = owner.gradient({
77
+ type: 'linear',
78
+ colors: effectColors(props.colors),
79
+ angle: props.angle,
80
+ })
81
+ update()
82
+ return () => {
83
+ stop()
84
+ gradient?.dispose()
85
+ gradient = undefined
86
+ }
87
+ }),
88
+ )
89
+ watch(
90
+ () => [
91
+ props.colors,
92
+ props.angle,
93
+ props.duration,
94
+ props.animated,
95
+ running.value,
96
+ environment.value,
97
+ ],
98
+ update,
99
+ { deep: true },
100
+ )
101
+ return () => {
102
+ dashboardNumber(props.height, 40, 1600, 'height')
103
+ dashboardNumber(props.duration, 1000, 120000, 'duration')
104
+ effectColors(props.colors)
105
+ return h(
106
+ ui.Environment,
107
+ {
108
+ onEnvironment: (value: DashboardEnvironment) => {
109
+ environment.value = value
110
+ },
111
+ },
112
+ () =>
113
+ h(
114
+ ui.Box,
115
+ mergeProps(attrs, {
116
+ id: props.id,
117
+ height: props.height,
118
+ width: '100%',
119
+ radius: props.radius,
120
+ motionSurface: surface,
121
+ backgroundColor: props.colors[0],
122
+ ...(platform === 'web'
123
+ ? {
124
+ class: 'm-gradient-background',
125
+ style: {
126
+ overflow: 'hidden',
127
+ backgroundImage: `linear-gradient(${props.angle}deg, ${props.colors.join(', ')})`,
128
+ },
129
+ }
130
+ : { clipToBounds: true }),
131
+ }),
132
+ slots.default,
133
+ ),
134
+ )
135
+ }
136
+ },
137
+ })
138
+ const MParticleField = defineComponent({
139
+ name: 'MParticleField',
140
+ inheritAttrs: false,
141
+ props: particleFieldProps,
142
+ setup(props, { attrs, slots }) {
143
+ const surface = markRaw(createMotionSurface()),
144
+ environment = ref<DashboardEnvironment>({ reduced: true, paused: true })
145
+ let decoration: MotionDecoration | undefined
146
+ function stop() {
147
+ decoration?.dispose()
148
+ decoration = undefined
149
+ }
150
+ function update() {
151
+ stop()
152
+ if (
153
+ !surface.available ||
154
+ !surface.supports('particles') ||
155
+ !props.active ||
156
+ environment.value.reduced ||
157
+ environment.value.paused
158
+ )
159
+ return
160
+ decoration = surface.particles({
161
+ colors: props.colors,
162
+ rate: props.density,
163
+ velocity: props.speed,
164
+ lifetime: props.lifetime,
165
+ duration: props.duration,
166
+ size: props.size,
167
+ shape: props.shape,
168
+ source: 'bottom',
169
+ angle: -90,
170
+ spread: 80,
171
+ gravity: 0,
172
+ fadeOut: true,
173
+ })
174
+ }
175
+ onScopeDispose(
176
+ surface.use(() => {
177
+ update()
178
+ return stop
179
+ }),
180
+ )
181
+ watch(
182
+ () => [
183
+ props.active,
184
+ props.colors,
185
+ props.density,
186
+ props.speed,
187
+ props.lifetime,
188
+ props.duration,
189
+ props.size,
190
+ props.shape,
191
+ environment.value,
192
+ ],
193
+ update,
194
+ { deep: true },
195
+ )
196
+ return () => {
197
+ dashboardNumber(props.height, 40, 1600, 'height')
198
+ dashboardNumber(props.density, 1, 60, 'density')
199
+ dashboardNumber(props.speed, 0, 300, 'speed')
200
+ dashboardNumber(props.lifetime, 100, 5000, 'lifetime')
201
+ dashboardNumber(props.size, 1, 24, 'size')
202
+ effectColors(props.colors)
203
+ if (props.duration !== undefined) dashboardNumber(props.duration, 100, 60000, 'duration')
204
+ return h(
205
+ ui.Environment,
206
+ {
207
+ onEnvironment: (value: DashboardEnvironment) => {
208
+ environment.value = value
209
+ },
210
+ },
211
+ () =>
212
+ h(
213
+ ui.Box,
214
+ mergeProps(attrs, {
215
+ id: props.id,
216
+ height: props.height,
217
+ width: '100%',
218
+ radius: props.radius,
219
+ motionSurface: surface,
220
+ backgroundColor: props.backgroundColor,
221
+ ...(platform === 'web'
222
+ ? { class: 'm-particle-field', style: { overflow: 'hidden' } }
223
+ : { clipToBounds: true }),
224
+ }),
225
+ slots.default,
226
+ ),
227
+ )
228
+ }
229
+ },
230
+ })
231
+ const MConfetti = defineComponent({
232
+ name: 'MConfetti',
233
+ inheritAttrs: false,
234
+ props: confettiProps,
235
+ emits: {
236
+ burst: () => true,
237
+ skipped: (_reason: 'disabled' | 'reduced-motion' | 'unavailable') => true,
238
+ },
239
+ setup(props, { attrs, slots, emit, expose }) {
240
+ const surface = markRaw(createMotionSurface()),
241
+ environment = ref<DashboardEnvironment>({ reduced: true, paused: true })
242
+ let decoration: MotionDecoration | undefined
243
+ function stop() {
244
+ decoration?.dispose()
245
+ decoration = undefined
246
+ }
247
+ function burst() {
248
+ stop()
249
+ const reason = props.disabled
250
+ ? 'disabled'
251
+ : environment.value.reduced
252
+ ? 'reduced-motion'
253
+ : environment.value.paused || !surface.available || !surface.supports('confetti')
254
+ ? 'unavailable'
255
+ : null
256
+ if (reason) {
257
+ emit('skipped', reason)
258
+ return
259
+ }
260
+ decoration = surface.confetti({
261
+ count: dashboardNumber(props.count, 1, 180, 'count'),
262
+ colors: effectColors(props.colors),
263
+ })
264
+ emit('burst')
265
+ }
266
+ expose({ burst, stop })
267
+ onScopeDispose(surface.use(() => stop))
268
+ // Initial token and hydration do not celebrate. Only an explicit subsequent request does.
269
+ watch(() => props.trigger, burst)
270
+ watch(
271
+ () => [props.disabled, environment.value],
272
+ () => {
273
+ if (props.disabled || environment.value.reduced || environment.value.paused) stop()
274
+ },
275
+ { deep: true },
276
+ )
277
+ return () => {
278
+ dashboardNumber(props.count, 1, 180, 'count')
279
+ effectColors(props.colors)
280
+ return h(
281
+ ui.Environment,
282
+ {
283
+ interactive: true,
284
+ onEnvironment: (value: DashboardEnvironment) => {
285
+ environment.value = value
286
+ },
287
+ },
288
+ () =>
289
+ h(
290
+ ui.Box,
291
+ mergeProps(attrs, {
292
+ id: props.id,
293
+ width: '100%',
294
+ motionSurface: surface,
295
+ ...(platform === 'web' ? { class: 'm-confetti' } : {}),
296
+ }),
297
+ slots.default,
298
+ ),
299
+ )
300
+ }
301
+ },
302
+ })
303
+ return { MGradientBackground, MParticleField, MConfetti }
304
+ }