@getcortexlabs/mavis-web 0.1.0-rc.11.1 → 0.1.0-rc.12.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.
- package/README.md +4 -4
- package/dist/components/DateCalendar.d.ts +1 -1
- package/dist/components/MButton.d.ts +3 -3
- package/dist/components/MCard.d.ts +1 -1
- package/dist/components/MChip.d.ts +1 -1
- package/dist/components/MCombobox.d.ts +4 -4
- package/dist/components/MDatePicker.d.ts +16 -16
- package/dist/components/MDialog.d.ts +3 -3
- package/dist/components/MFilePicker.d.ts +3 -3
- package/dist/components/MGrid.d.ts +1 -1
- package/dist/components/MImageCompare.d.ts +2 -2
- package/dist/components/MImageViewer.d.ts +5 -5
- package/dist/components/MInput.d.ts +2 -2
- package/dist/components/MLink.d.ts +1 -1
- package/dist/components/MListItem.d.ts +1 -1
- package/dist/components/MPinInput.d.ts +57 -0
- package/dist/components/MPinInput.d.ts.map +1 -0
- package/dist/components/MPinInput.js +159 -0
- package/dist/components/MPinInput.js.map +1 -0
- package/dist/components/MPopover.d.ts +1 -1
- package/dist/components/MPopover.d.ts.map +1 -1
- package/dist/components/MPopover.js +29 -19
- package/dist/components/MPopover.js.map +1 -1
- package/dist/components/MProgress.d.ts +1 -1
- package/dist/components/MRangeSlider.d.ts +1 -1
- package/dist/components/MResizablePanels.d.ts +4 -4
- package/dist/components/MSelect.d.ts +2 -2
- package/dist/components/MSeparator.d.ts +1 -1
- package/dist/components/MTimePicker.d.ts +12 -12
- package/dist/components/advanced.d.ts +852 -0
- package/dist/components/advanced.d.ts.map +1 -0
- package/dist/components/advanced.js +331 -0
- package/dist/components/advanced.js.map +1 -0
- package/dist/components/configurator.d.ts +7 -7
- package/dist/components/creative.d.ts +614 -0
- package/dist/components/creative.d.ts.map +1 -0
- package/dist/components/creative.js +191 -0
- package/dist/components/creative.js.map +1 -0
- package/dist/components/dashboard.d.ts +474 -0
- package/dist/components/dashboard.d.ts.map +1 -0
- package/dist/components/dashboard.js +286 -0
- package/dist/components/dashboard.js.map +1 -0
- package/dist/components/discovery.d.ts +3 -3
- package/dist/components/interactive.d.ts +1 -1
- package/dist/components/navigation.d.ts +3 -3
- package/dist/components/screen-components.d.ts +502 -0
- package/dist/components/screen-components.d.ts.map +1 -0
- package/dist/components/screen-components.js +67 -0
- package/dist/components/screen-components.js.map +1 -0
- package/dist/components/wayfinding.d.ts +6 -6
- package/dist/components/workflows.d.ts +3 -3
- package/dist/image-crop.d.ts +3 -0
- package/dist/image-crop.d.ts.map +1 -0
- package/dist/image-crop.js +62 -0
- package/dist/image-crop.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -1
- package/dist/use-motion-surface.d.ts.map +1 -1
- package/dist/use-motion-surface.js +27 -8
- package/dist/use-motion-surface.js.map +1 -1
- package/package.json +3 -3
- package/src/components/MPinInput.ts +194 -0
- package/src/components/MPopover.ts +33 -19
- package/src/components/advanced.ts +387 -0
- package/src/components/creative.ts +240 -0
- package/src/components/dashboard.ts +353 -0
- package/src/components/screen-components.ts +86 -0
- package/src/image-crop.ts +57 -0
- package/src/index.ts +84 -0
- package/src/use-motion-surface.ts +40 -15
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
h,
|
|
4
|
+
inject,
|
|
5
|
+
markRaw,
|
|
6
|
+
mergeProps,
|
|
7
|
+
onMounted,
|
|
8
|
+
onBeforeUnmount,
|
|
9
|
+
onActivated,
|
|
10
|
+
onDeactivated,
|
|
11
|
+
onScopeDispose,
|
|
12
|
+
ref,
|
|
13
|
+
watch,
|
|
14
|
+
} from 'vue'
|
|
15
|
+
import {
|
|
16
|
+
createDashboardShape,
|
|
17
|
+
createDonutChart,
|
|
18
|
+
createSparkline,
|
|
19
|
+
createDashboardEffects,
|
|
20
|
+
createKanban,
|
|
21
|
+
dashboardShapeProps,
|
|
22
|
+
dashboardEnvironmentProps,
|
|
23
|
+
dashboardPlotProps,
|
|
24
|
+
kanbanRegistryKey,
|
|
25
|
+
kanbanZoneProps,
|
|
26
|
+
kanbanDragProps,
|
|
27
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
28
|
+
import { createMotionSurface } from '@getcortexlabs/mavis-core/experimental'
|
|
29
|
+
import { MBox, MColumn, MRow } from './layout.js'
|
|
30
|
+
import { MStack } from './MStack.js'
|
|
31
|
+
import { MText } from './MText.js'
|
|
32
|
+
import { MButton } from './MButton.js'
|
|
33
|
+
import { MNumberFlow } from './interactive.js'
|
|
34
|
+
import { MMenu } from './navigation.js'
|
|
35
|
+
|
|
36
|
+
const Fallback = defineComponent({
|
|
37
|
+
props: { ...dashboardShapeProps, hidden: Boolean },
|
|
38
|
+
setup(props) {
|
|
39
|
+
return () =>
|
|
40
|
+
h(
|
|
41
|
+
'svg',
|
|
42
|
+
{
|
|
43
|
+
viewBox: props.viewBox.join(' '),
|
|
44
|
+
preserveAspectRatio: 'none',
|
|
45
|
+
'aria-hidden': true,
|
|
46
|
+
focusable: false,
|
|
47
|
+
style: {
|
|
48
|
+
display: 'block',
|
|
49
|
+
position: 'absolute',
|
|
50
|
+
inset: 0,
|
|
51
|
+
width: '100%',
|
|
52
|
+
height: '100%',
|
|
53
|
+
visibility: props.hidden ? 'hidden' : undefined,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
[
|
|
57
|
+
h('path', {
|
|
58
|
+
d: props.d,
|
|
59
|
+
fill: 'none',
|
|
60
|
+
stroke: props.color,
|
|
61
|
+
'stroke-width': props.strokeWidth,
|
|
62
|
+
'stroke-linecap': 'round',
|
|
63
|
+
'stroke-linejoin': 'round',
|
|
64
|
+
pathLength: 1,
|
|
65
|
+
'stroke-dasharray': `${Math.max(0, props.end - props.start)} 1`,
|
|
66
|
+
'stroke-dashoffset': -props.start,
|
|
67
|
+
}),
|
|
68
|
+
],
|
|
69
|
+
)
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
const Environment = defineComponent({
|
|
73
|
+
inheritAttrs: false,
|
|
74
|
+
props: dashboardEnvironmentProps,
|
|
75
|
+
emits: ['environment'],
|
|
76
|
+
setup(_props, { attrs, slots, emit }) {
|
|
77
|
+
const root = ref<HTMLElement>()
|
|
78
|
+
let attached = false,
|
|
79
|
+
visible = true,
|
|
80
|
+
media: MediaQueryList | undefined,
|
|
81
|
+
observer: IntersectionObserver | undefined
|
|
82
|
+
function update() {
|
|
83
|
+
emit('environment', {
|
|
84
|
+
reduced: media?.matches ?? true,
|
|
85
|
+
paused: !attached || document.hidden || !visible,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
function connect() {
|
|
89
|
+
if (attached || !root.value) return
|
|
90
|
+
attached = true
|
|
91
|
+
media = matchMedia('(prefers-reduced-motion: reduce)')
|
|
92
|
+
media.addEventListener('change', update)
|
|
93
|
+
document.addEventListener('visibilitychange', update)
|
|
94
|
+
observer = new IntersectionObserver(([entry]) => {
|
|
95
|
+
const next = entry?.isIntersecting ?? false
|
|
96
|
+
if (next !== visible) {
|
|
97
|
+
visible = next
|
|
98
|
+
update()
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
observer.observe(root.value)
|
|
102
|
+
update()
|
|
103
|
+
}
|
|
104
|
+
function disconnect() {
|
|
105
|
+
attached = false
|
|
106
|
+
media?.removeEventListener('change', update)
|
|
107
|
+
observer?.disconnect()
|
|
108
|
+
document.removeEventListener('visibilitychange', update)
|
|
109
|
+
update()
|
|
110
|
+
}
|
|
111
|
+
onMounted(connect)
|
|
112
|
+
onActivated(connect)
|
|
113
|
+
onDeactivated(disconnect)
|
|
114
|
+
onBeforeUnmount(disconnect)
|
|
115
|
+
return () =>
|
|
116
|
+
h(
|
|
117
|
+
'div',
|
|
118
|
+
mergeProps(attrs, { ref: root, style: { minWidth: 0, width: '100%' } }),
|
|
119
|
+
slots.default?.(),
|
|
120
|
+
)
|
|
121
|
+
},
|
|
122
|
+
})
|
|
123
|
+
const Zone = defineComponent({
|
|
124
|
+
inheritAttrs: false,
|
|
125
|
+
props: kanbanZoneProps,
|
|
126
|
+
setup(props, { attrs, slots }) {
|
|
127
|
+
const registry = inject(kanbanRegistryKey)!,
|
|
128
|
+
root = ref<HTMLElement>()
|
|
129
|
+
onMounted(() => registry.zones.set(props.column, () => root.value?.getBoundingClientRect()))
|
|
130
|
+
onBeforeUnmount(() => registry.zones.delete(props.column))
|
|
131
|
+
return () =>
|
|
132
|
+
h(
|
|
133
|
+
'div',
|
|
134
|
+
mergeProps(attrs, { ref: root, 'data-kanban-column': props.column }),
|
|
135
|
+
slots.default?.(),
|
|
136
|
+
)
|
|
137
|
+
},
|
|
138
|
+
})
|
|
139
|
+
const Drag = defineComponent({
|
|
140
|
+
inheritAttrs: false,
|
|
141
|
+
props: kanbanDragProps,
|
|
142
|
+
setup(props, { attrs, slots }) {
|
|
143
|
+
const registry = inject(kanbanRegistryKey)!,
|
|
144
|
+
root = ref<HTMLElement>(),
|
|
145
|
+
surface = markRaw(createMotionSurface()),
|
|
146
|
+
dragging = ref(false)
|
|
147
|
+
let pointer: number | undefined,
|
|
148
|
+
anchor: DOMRect | undefined,
|
|
149
|
+
startX = 0,
|
|
150
|
+
startY = 0,
|
|
151
|
+
handle: HTMLElement | undefined
|
|
152
|
+
function end(commit = false) {
|
|
153
|
+
const was = dragging.value
|
|
154
|
+
dragging.value = false
|
|
155
|
+
const id = pointer
|
|
156
|
+
pointer = undefined
|
|
157
|
+
if (id !== undefined && handle?.hasPointerCapture(id)) handle.releasePointerCapture(id)
|
|
158
|
+
window.removeEventListener('keydown', escape)
|
|
159
|
+
window.removeEventListener('scroll', cancel, true)
|
|
160
|
+
window.removeEventListener('resize', cancel)
|
|
161
|
+
if (surface.available) {
|
|
162
|
+
if (props.animated && !commit)
|
|
163
|
+
surface.animate({ x: 0, y: 0, scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
|
|
164
|
+
else surface.set({ x: 0, y: 0, scale: 1 })
|
|
165
|
+
}
|
|
166
|
+
if (was) registry.finish(commit)
|
|
167
|
+
}
|
|
168
|
+
const cancel = () => end(false)
|
|
169
|
+
const escape = (e: KeyboardEvent) => {
|
|
170
|
+
if (e.key === 'Escape') {
|
|
171
|
+
e.preventDefault()
|
|
172
|
+
cancel()
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
onMounted(() => {
|
|
176
|
+
registry.cards.set(props.cardId, () => root.value?.getBoundingClientRect())
|
|
177
|
+
registry.focus.set(props.cardId, () =>
|
|
178
|
+
root.value
|
|
179
|
+
?.querySelector<HTMLElement>('button:not(:disabled)')
|
|
180
|
+
?.focus({ preventScroll: true }),
|
|
181
|
+
)
|
|
182
|
+
})
|
|
183
|
+
onBeforeUnmount(() => {
|
|
184
|
+
cancel()
|
|
185
|
+
registry.cards.delete(props.cardId)
|
|
186
|
+
registry.focus.delete(props.cardId)
|
|
187
|
+
})
|
|
188
|
+
onDeactivated(cancel)
|
|
189
|
+
onScopeDispose(
|
|
190
|
+
surface.use(() => () => {
|
|
191
|
+
if (dragging.value) cancel()
|
|
192
|
+
}),
|
|
193
|
+
)
|
|
194
|
+
watch(
|
|
195
|
+
() => props.disabled,
|
|
196
|
+
(value) => {
|
|
197
|
+
if (value) cancel()
|
|
198
|
+
},
|
|
199
|
+
)
|
|
200
|
+
return () =>
|
|
201
|
+
h(
|
|
202
|
+
'div',
|
|
203
|
+
mergeProps(attrs, {
|
|
204
|
+
ref: root,
|
|
205
|
+
'data-kanban-card': props.cardId,
|
|
206
|
+
style: { position: 'relative', zIndex: dragging.value ? 20 : undefined },
|
|
207
|
+
}),
|
|
208
|
+
[
|
|
209
|
+
h(MBox, { motionSurface: surface }, () =>
|
|
210
|
+
h(MColumn, { gap: 'xs' }, () => [
|
|
211
|
+
h(
|
|
212
|
+
'button',
|
|
213
|
+
{
|
|
214
|
+
type: 'button',
|
|
215
|
+
disabled: props.disabled,
|
|
216
|
+
'aria-label': props.label,
|
|
217
|
+
'data-kanban-handle': props.cardId,
|
|
218
|
+
style: {
|
|
219
|
+
touchAction: 'none',
|
|
220
|
+
cursor: props.disabled ? 'default' : dragging.value ? 'grabbing' : 'grab',
|
|
221
|
+
minHeight: '36px',
|
|
222
|
+
width: '100%',
|
|
223
|
+
borderRadius: '8px',
|
|
224
|
+
color: 'inherit',
|
|
225
|
+
background: 'transparent',
|
|
226
|
+
border: '0',
|
|
227
|
+
opacity: props.disabled ? 0.4 : 0.65,
|
|
228
|
+
},
|
|
229
|
+
onPointerdown: (e: PointerEvent) => {
|
|
230
|
+
if (props.disabled || e.button !== 0 || !e.isPrimary || pointer !== undefined)
|
|
231
|
+
return
|
|
232
|
+
e.preventDefault()
|
|
233
|
+
handle = e.currentTarget as HTMLElement
|
|
234
|
+
handle.focus({ preventScroll: true })
|
|
235
|
+
pointer = e.pointerId
|
|
236
|
+
startX = e.clientX
|
|
237
|
+
startY = e.clientY
|
|
238
|
+
handle.setPointerCapture(pointer)
|
|
239
|
+
window.addEventListener('keydown', escape)
|
|
240
|
+
window.addEventListener('scroll', cancel, true)
|
|
241
|
+
window.addEventListener('resize', cancel)
|
|
242
|
+
},
|
|
243
|
+
onPointermove: (e: PointerEvent) => {
|
|
244
|
+
if (e.pointerId !== pointer) return
|
|
245
|
+
const x = e.clientX - startX,
|
|
246
|
+
y = e.clientY - startY
|
|
247
|
+
if (!dragging.value && Math.hypot(x, y) >= 6) {
|
|
248
|
+
if (!registry.begin(props.cardId, cancel)) {
|
|
249
|
+
cancel()
|
|
250
|
+
return
|
|
251
|
+
}
|
|
252
|
+
anchor = root.value?.getBoundingClientRect()
|
|
253
|
+
dragging.value = true
|
|
254
|
+
}
|
|
255
|
+
if (dragging.value && surface.available) {
|
|
256
|
+
const current = root.value?.getBoundingClientRect()
|
|
257
|
+
surface.set({
|
|
258
|
+
x: x + (anchor && current ? anchor.x - current.x : 0),
|
|
259
|
+
y: y + (anchor && current ? anchor.y - current.y : 0),
|
|
260
|
+
scale: 1.02,
|
|
261
|
+
})
|
|
262
|
+
registry.move(x, y)
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
onPointerup: (e: PointerEvent) => {
|
|
266
|
+
if (e.pointerId === pointer) end(true)
|
|
267
|
+
},
|
|
268
|
+
onPointercancel: cancel,
|
|
269
|
+
onLostpointercapture: () => {
|
|
270
|
+
if (pointer !== undefined) cancel()
|
|
271
|
+
},
|
|
272
|
+
onKeydown: (e: KeyboardEvent) => {
|
|
273
|
+
const direction = (
|
|
274
|
+
{
|
|
275
|
+
ArrowUp: 'up',
|
|
276
|
+
ArrowDown: 'down',
|
|
277
|
+
ArrowLeft: 'left',
|
|
278
|
+
ArrowRight: 'right',
|
|
279
|
+
} as const
|
|
280
|
+
)[e.key as 'ArrowUp']
|
|
281
|
+
if (direction && !props.disabled) {
|
|
282
|
+
e.preventDefault()
|
|
283
|
+
registry.keyboard(props.cardId, direction)
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
'⠿',
|
|
288
|
+
),
|
|
289
|
+
...(slots.default?.() ?? []),
|
|
290
|
+
]),
|
|
291
|
+
),
|
|
292
|
+
],
|
|
293
|
+
)
|
|
294
|
+
},
|
|
295
|
+
})
|
|
296
|
+
const Plot = defineComponent({
|
|
297
|
+
inheritAttrs: false,
|
|
298
|
+
props: dashboardPlotProps,
|
|
299
|
+
emits: ['width'],
|
|
300
|
+
setup(props, { attrs, slots, emit }) {
|
|
301
|
+
const root = ref<HTMLElement>()
|
|
302
|
+
let observer: ResizeObserver | undefined
|
|
303
|
+
function connect() {
|
|
304
|
+
if (observer || !root.value) return
|
|
305
|
+
const measure = () => emit('width', root.value?.clientWidth ?? 0)
|
|
306
|
+
observer = new ResizeObserver(measure)
|
|
307
|
+
observer.observe(root.value)
|
|
308
|
+
measure()
|
|
309
|
+
}
|
|
310
|
+
function disconnect() {
|
|
311
|
+
observer?.disconnect()
|
|
312
|
+
observer = undefined
|
|
313
|
+
}
|
|
314
|
+
onMounted(connect)
|
|
315
|
+
onActivated(connect)
|
|
316
|
+
onDeactivated(disconnect)
|
|
317
|
+
onBeforeUnmount(disconnect)
|
|
318
|
+
return () =>
|
|
319
|
+
h(
|
|
320
|
+
'div',
|
|
321
|
+
mergeProps(attrs, {
|
|
322
|
+
ref: root,
|
|
323
|
+
'data-sparkline-plot': '',
|
|
324
|
+
style: {
|
|
325
|
+
height: props.height + 'px',
|
|
326
|
+
width: '100%',
|
|
327
|
+
minWidth: 0,
|
|
328
|
+
minHeight: 0,
|
|
329
|
+
display: 'grid',
|
|
330
|
+
position: 'relative',
|
|
331
|
+
overflow: 'hidden',
|
|
332
|
+
},
|
|
333
|
+
}),
|
|
334
|
+
slots.default?.(),
|
|
335
|
+
)
|
|
336
|
+
},
|
|
337
|
+
})
|
|
338
|
+
const ui = {
|
|
339
|
+
Box: MBox,
|
|
340
|
+
Column: MColumn,
|
|
341
|
+
Row: MRow,
|
|
342
|
+
Stack: MStack,
|
|
343
|
+
Text: MText,
|
|
344
|
+
Button: MButton,
|
|
345
|
+
NumberFlow: MNumberFlow,
|
|
346
|
+
Shape: createDashboardShape(MBox, Fallback, 'web'),
|
|
347
|
+
Environment,
|
|
348
|
+
Plot,
|
|
349
|
+
}
|
|
350
|
+
export const MDonutChart = createDonutChart(ui, 'web')
|
|
351
|
+
export const MSparkline = createSparkline(ui, 'web')
|
|
352
|
+
export const { MGradientBackground, MParticleField, MConfetti } = createDashboardEffects(ui, 'web')
|
|
353
|
+
export const MKanban = createKanban({ ...ui, Zone, Drag, Menu: MMenu }, 'web')
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps, ref } from 'vue'
|
|
2
|
+
import {
|
|
3
|
+
createAnimatedText,
|
|
4
|
+
createComposer,
|
|
5
|
+
createSpeedDial,
|
|
6
|
+
createScrollComponents,
|
|
7
|
+
scrollFrameHostProps,
|
|
8
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
9
|
+
import { useMotionRegion } from '../motion-region.js'
|
|
10
|
+
import { useScrollMotion } from '../scroll-motion.js'
|
|
11
|
+
import { MBox, MColumn, MRow } from './layout.js'
|
|
12
|
+
import { MCard } from './MCard.js'
|
|
13
|
+
import { MText } from './MText.js'
|
|
14
|
+
import { MInput } from './MInput.js'
|
|
15
|
+
import { MImage } from './MImage.js'
|
|
16
|
+
import { MButton } from './MButton.js'
|
|
17
|
+
import { MChip } from './MChip.js'
|
|
18
|
+
import { MPopover } from './MPopover.js'
|
|
19
|
+
|
|
20
|
+
const Frame = defineComponent({
|
|
21
|
+
name: 'MScrollFrameHost',
|
|
22
|
+
inheritAttrs: false,
|
|
23
|
+
props: scrollFrameHostProps,
|
|
24
|
+
setup(props, { attrs, slots }) {
|
|
25
|
+
const motion = useMotionRegion(() => props.region)
|
|
26
|
+
const scroll = ref<HTMLElement>()
|
|
27
|
+
useScrollMotion(
|
|
28
|
+
scroll,
|
|
29
|
+
() => props.source,
|
|
30
|
+
() => true,
|
|
31
|
+
)
|
|
32
|
+
return () =>
|
|
33
|
+
h(
|
|
34
|
+
'div',
|
|
35
|
+
mergeProps(attrs, motion, {
|
|
36
|
+
class: 'm-scroll-frame',
|
|
37
|
+
style: {
|
|
38
|
+
position: 'relative',
|
|
39
|
+
height: `${props.height}px`,
|
|
40
|
+
minWidth: 0,
|
|
41
|
+
overflow: 'hidden',
|
|
42
|
+
isolation: 'isolate',
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
[
|
|
46
|
+
h(
|
|
47
|
+
'div',
|
|
48
|
+
{
|
|
49
|
+
ref: scroll,
|
|
50
|
+
role: 'region',
|
|
51
|
+
'aria-label': props.label,
|
|
52
|
+
tabindex: 0,
|
|
53
|
+
class: 'm-scroll-frame-content',
|
|
54
|
+
style: {
|
|
55
|
+
height: '100%',
|
|
56
|
+
overflowY: 'auto',
|
|
57
|
+
overscrollBehaviorY: 'contain',
|
|
58
|
+
display: 'flex',
|
|
59
|
+
flexDirection: 'column',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
[h(MColumn, {}, { default: () => slots.default?.() })],
|
|
63
|
+
),
|
|
64
|
+
slots.overlay?.(),
|
|
65
|
+
],
|
|
66
|
+
)
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
const ui = {
|
|
70
|
+
Box: MBox,
|
|
71
|
+
Card: MCard,
|
|
72
|
+
Column: MColumn,
|
|
73
|
+
Row: MRow,
|
|
74
|
+
Text: MText,
|
|
75
|
+
Input: MInput,
|
|
76
|
+
Button: MButton,
|
|
77
|
+
Chip: MChip,
|
|
78
|
+
Image: MImage,
|
|
79
|
+
Popover: MPopover,
|
|
80
|
+
Frame,
|
|
81
|
+
}
|
|
82
|
+
export const MAnimatedText = createAnimatedText(MText)
|
|
83
|
+
export const MComposer = createComposer(ui, 'web')
|
|
84
|
+
export const MSpeedDial = createSpeedDial(ui)
|
|
85
|
+
export const { MCollapsibleHeader, MRefreshControl } = createScrollComponents(ui, 'web')
|
|
86
|
+
export { MPinInput } from './MPinInput.js'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { cropOutputSize, validateImageCrop, type CropSource } from '@getcortexlabs/mavis-core'
|
|
2
|
+
export async function loadCropImage(src: string): Promise<CropSource> {
|
|
3
|
+
const image = new Image()
|
|
4
|
+
image.crossOrigin = 'anonymous'
|
|
5
|
+
image.src = src
|
|
6
|
+
await image.decode()
|
|
7
|
+
const width = image.naturalWidth,
|
|
8
|
+
height = image.naturalHeight
|
|
9
|
+
if (!width || !height || width * height > 40000000) {
|
|
10
|
+
image.src = ''
|
|
11
|
+
throw new RangeError('ImageCropper needs an image of at most 40 megapixels.')
|
|
12
|
+
}
|
|
13
|
+
let disposed = false
|
|
14
|
+
return {
|
|
15
|
+
width,
|
|
16
|
+
height,
|
|
17
|
+
preview: src,
|
|
18
|
+
dispose() {
|
|
19
|
+
disposed = true
|
|
20
|
+
image.src = ''
|
|
21
|
+
},
|
|
22
|
+
async export(crop, options) {
|
|
23
|
+
if (disposed) throw new Error('Image source has been released.')
|
|
24
|
+
validateImageCrop({ width, height }, crop)
|
|
25
|
+
const size = cropOutputSize(crop, options)
|
|
26
|
+
const canvas = document.createElement('canvas')
|
|
27
|
+
canvas.width = size.width
|
|
28
|
+
canvas.height = size.height
|
|
29
|
+
const ctx = canvas.getContext('2d')
|
|
30
|
+
if (!ctx) throw new Error('Canvas image export is unavailable.')
|
|
31
|
+
try {
|
|
32
|
+
if (options.mimeType === 'image/jpeg') {
|
|
33
|
+
ctx.fillStyle = '#FFFFFF'
|
|
34
|
+
ctx.fillRect(0, 0, size.width, size.height)
|
|
35
|
+
}
|
|
36
|
+
ctx.scale(size.width / crop.width, size.height / crop.height)
|
|
37
|
+
ctx.translate(-crop.x, -crop.y)
|
|
38
|
+
if (crop.rotation === 90) ctx.translate(height, 0)
|
|
39
|
+
if (crop.rotation === 180) ctx.translate(width, height)
|
|
40
|
+
if (crop.rotation === 270) ctx.translate(0, width)
|
|
41
|
+
ctx.rotate((crop.rotation * Math.PI) / 180)
|
|
42
|
+
ctx.drawImage(image, 0, 0)
|
|
43
|
+
const uri = canvas.toDataURL(options.mimeType, options.quality)
|
|
44
|
+
if (!uri.startsWith(`data:${options.mimeType};`))
|
|
45
|
+
throw new Error('Requested image encoding is unavailable.')
|
|
46
|
+
return { ...size, uri, mimeType: options.mimeType, async dispose() {} }
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Image export failed. Remote images must allow CORS. ${error instanceof Error ? error.message : String(error)}`,
|
|
50
|
+
)
|
|
51
|
+
} finally {
|
|
52
|
+
canvas.width = 0
|
|
53
|
+
canvas.height = 0
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MTreeSelect,
|
|
3
|
+
MMasonry,
|
|
4
|
+
MHeatmap,
|
|
5
|
+
MImageCropper,
|
|
6
|
+
MScheduler,
|
|
7
|
+
MNotificationCenter,
|
|
8
|
+
} from './components/advanced.js'
|
|
9
|
+
import {
|
|
10
|
+
MKanban,
|
|
11
|
+
MDonutChart,
|
|
12
|
+
MSparkline,
|
|
13
|
+
MGradientBackground,
|
|
14
|
+
MParticleField,
|
|
15
|
+
MConfetti,
|
|
16
|
+
} from './components/dashboard.js'
|
|
17
|
+
import {
|
|
18
|
+
MColorPicker,
|
|
19
|
+
MSwipeDeck,
|
|
20
|
+
MGauge,
|
|
21
|
+
MTour,
|
|
22
|
+
MTourTarget,
|
|
23
|
+
MTransferList,
|
|
24
|
+
MMarquee,
|
|
25
|
+
} from './components/creative.js'
|
|
26
|
+
import {
|
|
27
|
+
MCollapsibleHeader,
|
|
28
|
+
MRefreshControl,
|
|
29
|
+
MComposer,
|
|
30
|
+
MSpeedDial,
|
|
31
|
+
MPinInput,
|
|
32
|
+
MAnimatedText,
|
|
33
|
+
} from './components/screen-components.js'
|
|
1
34
|
import {
|
|
2
35
|
MImageViewer,
|
|
3
36
|
MNumberFlow,
|
|
@@ -65,6 +98,31 @@ import { MReveal } from './components/MReveal.js'
|
|
|
65
98
|
import { MSheet } from './components/MSheet.js'
|
|
66
99
|
|
|
67
100
|
export {
|
|
101
|
+
MTreeSelect,
|
|
102
|
+
MMasonry,
|
|
103
|
+
MHeatmap,
|
|
104
|
+
MImageCropper,
|
|
105
|
+
MScheduler,
|
|
106
|
+
MNotificationCenter,
|
|
107
|
+
MKanban,
|
|
108
|
+
MDonutChart,
|
|
109
|
+
MSparkline,
|
|
110
|
+
MGradientBackground,
|
|
111
|
+
MParticleField,
|
|
112
|
+
MConfetti,
|
|
113
|
+
MColorPicker,
|
|
114
|
+
MSwipeDeck,
|
|
115
|
+
MGauge,
|
|
116
|
+
MTour,
|
|
117
|
+
MTourTarget,
|
|
118
|
+
MTransferList,
|
|
119
|
+
MMarquee,
|
|
120
|
+
MCollapsibleHeader,
|
|
121
|
+
MRefreshControl,
|
|
122
|
+
MComposer,
|
|
123
|
+
MSpeedDial,
|
|
124
|
+
MPinInput,
|
|
125
|
+
MAnimatedText,
|
|
68
126
|
MImageViewer,
|
|
69
127
|
MNumberFlow,
|
|
70
128
|
MSortableList,
|
|
@@ -170,6 +228,32 @@ export function createMavis(options: MavisOptions = {}) {
|
|
|
170
228
|
if (components === false) return
|
|
171
229
|
for (const [name, component] of Object.entries(
|
|
172
230
|
components ?? {
|
|
231
|
+
MTreeSelect,
|
|
232
|
+
MMasonry,
|
|
233
|
+
MHeatmap,
|
|
234
|
+
MImageCropper,
|
|
235
|
+
MScheduler,
|
|
236
|
+
MNotificationCenter,
|
|
237
|
+
MKanban,
|
|
238
|
+
MDonutChart,
|
|
239
|
+
MSparkline,
|
|
240
|
+
MGradientBackground,
|
|
241
|
+
MParticleField,
|
|
242
|
+
MConfetti,
|
|
243
|
+
MColorPicker,
|
|
244
|
+
MSwipeDeck,
|
|
245
|
+
MGauge,
|
|
246
|
+
MTour,
|
|
247
|
+
MTourTarget,
|
|
248
|
+
MTransferList,
|
|
249
|
+
MMarquee,
|
|
250
|
+
MCollapsibleHeader,
|
|
251
|
+
MRefreshControl,
|
|
252
|
+
MComposer,
|
|
253
|
+
MSpeedDial,
|
|
254
|
+
MPinInput,
|
|
255
|
+
MAnimatedText,
|
|
256
|
+
|
|
173
257
|
MImageViewer,
|
|
174
258
|
MNumberFlow,
|
|
175
259
|
MSortableList,
|
|
@@ -12,24 +12,49 @@ export function useMotionSurface(
|
|
|
12
12
|
const element = shallowRef<HTMLElement>()
|
|
13
13
|
const connected = computed(() => (surface() ? element.value : undefined))
|
|
14
14
|
useConnectedMotion(connected, useMotionContext(), (runtime, target) => {
|
|
15
|
+
// Responsive layout can resize a declared surface before an animation ends.
|
|
16
|
+
// Keep Jolt's geometry lease alive until every playback has been released.
|
|
17
|
+
let geometry: ReturnType<typeof runtime.observeGeometry> | undefined
|
|
18
|
+
const display = target.ownerDocument.defaultView!.getComputedStyle(target).display
|
|
19
|
+
if (!['inline', 'none', 'contents'].includes(display)) {
|
|
20
|
+
runtime.set(target, { scale: 1 })
|
|
21
|
+
geometry = runtime.observeGeometry(target)
|
|
22
|
+
}
|
|
15
23
|
let release: (() => void) | undefined
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
release =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
let stop: () => void
|
|
25
|
+
try {
|
|
26
|
+
stop = watch(
|
|
27
|
+
surface,
|
|
28
|
+
(reference) => {
|
|
29
|
+
release?.()
|
|
30
|
+
release = undefined
|
|
31
|
+
if (reference)
|
|
32
|
+
release = bindMotionSurface(
|
|
33
|
+
reference,
|
|
34
|
+
webMotionSurface(
|
|
35
|
+
runtime,
|
|
36
|
+
target,
|
|
37
|
+
() => true,
|
|
38
|
+
runtime,
|
|
39
|
+
undefined,
|
|
40
|
+
undefined,
|
|
41
|
+
plainText,
|
|
42
|
+
).adapter,
|
|
43
|
+
)
|
|
44
|
+
},
|
|
45
|
+
{ immediate: true, flush: 'post' },
|
|
46
|
+
)
|
|
47
|
+
} catch (error) {
|
|
48
|
+
geometry?.dispose()
|
|
49
|
+
throw error
|
|
50
|
+
}
|
|
30
51
|
return () => {
|
|
31
52
|
stop()
|
|
32
|
-
|
|
53
|
+
try {
|
|
54
|
+
release?.()
|
|
55
|
+
} finally {
|
|
56
|
+
geometry?.dispose()
|
|
57
|
+
}
|
|
33
58
|
}
|
|
34
59
|
})
|
|
35
60
|
return {
|