@getcortexlabs/mavis-core 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 +2 -2
- package/dist/advanced-collections.d.ts +74 -0
- package/dist/advanced-collections.d.ts.map +1 -0
- package/dist/advanced-collections.js +129 -0
- package/dist/advanced-collections.js.map +1 -0
- package/dist/capabilities.d.ts +7 -7
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +29 -4
- package/dist/capabilities.js.map +1 -1
- package/dist/creative-controls.d.ts +47 -0
- package/dist/creative-controls.d.ts.map +1 -0
- package/dist/creative-controls.js +112 -0
- package/dist/creative-controls.js.map +1 -0
- package/dist/dashboard.d.ts +72 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +115 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/image-crop.d.ts +49 -0
- package/dist/image-crop.d.ts.map +1 -0
- package/dist/image-crop.js +71 -0
- package/dist/image-crop.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/scheduler.d.ts +45 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +142 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/screen-components.d.ts +45 -0
- package/dist/screen-components.d.ts.map +1 -0
- package/dist/screen-components.js +23 -0
- package/dist/screen-components.js.map +1 -0
- package/dist/vue/advanced-collections.d.ts +486 -0
- package/dist/vue/advanced-collections.d.ts.map +1 -0
- package/dist/vue/advanced-collections.js +476 -0
- package/dist/vue/advanced-collections.js.map +1 -0
- package/dist/vue/advanced-props.d.ts +398 -0
- package/dist/vue/advanced-props.d.ts.map +1 -0
- package/dist/vue/advanced-props.js +128 -0
- package/dist/vue/advanced-props.js.map +1 -0
- package/dist/vue/animated-text.d.ts +101 -0
- package/dist/vue/animated-text.d.ts.map +1 -0
- package/dist/vue/animated-text.js +56 -0
- package/dist/vue/animated-text.js.map +1 -0
- package/dist/vue/chart.d.ts +1 -1
- package/dist/vue/command-palette.d.ts +3 -3
- package/dist/vue/component-props.d.ts +1045 -0
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +29 -0
- package/dist/vue/component-props.js.map +1 -1
- package/dist/vue/composer.d.ts +159 -0
- package/dist/vue/composer.d.ts.map +1 -0
- package/dist/vue/composer.js +142 -0
- package/dist/vue/composer.js.map +1 -0
- package/dist/vue/configurator.d.ts +5 -5
- package/dist/vue/creative-controls.d.ts +328 -0
- package/dist/vue/creative-controls.d.ts.map +1 -0
- package/dist/vue/creative-controls.js +396 -0
- package/dist/vue/creative-controls.js.map +1 -0
- package/dist/vue/creative-props.d.ts +260 -0
- package/dist/vue/creative-props.d.ts.map +1 -0
- package/dist/vue/creative-props.js +92 -0
- package/dist/vue/creative-props.js.map +1 -0
- package/dist/vue/dashboard-charts.d.ts +240 -0
- package/dist/vue/dashboard-charts.d.ts.map +1 -0
- package/dist/vue/dashboard-charts.js +263 -0
- package/dist/vue/dashboard-charts.js.map +1 -0
- package/dist/vue/dashboard-effects.d.ts +211 -0
- package/dist/vue/dashboard-effects.d.ts.map +1 -0
- package/dist/vue/dashboard-effects.js +235 -0
- package/dist/vue/dashboard-effects.js.map +1 -0
- package/dist/vue/dashboard-props.d.ts +244 -0
- package/dist/vue/dashboard-props.d.ts.map +1 -0
- package/dist/vue/dashboard-props.js +94 -0
- package/dist/vue/dashboard-props.js.map +1 -0
- package/dist/vue/date-picker.d.ts +8 -8
- package/dist/vue/discovery-controls.d.ts +2 -2
- package/dist/vue/global-components.d.ts +152 -0
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/image-cropper.d.ts +187 -0
- package/dist/vue/image-cropper.d.ts.map +1 -0
- package/dist/vue/image-cropper.js +310 -0
- package/dist/vue/image-cropper.js.map +1 -0
- package/dist/vue/index.d.ts +20 -0
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +20 -0
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/kanban.d.ts +150 -0
- package/dist/vue/kanban.d.ts.map +1 -0
- package/dist/vue/kanban.js +267 -0
- package/dist/vue/kanban.js.map +1 -0
- package/dist/vue/marquee.d.ts +96 -0
- package/dist/vue/marquee.d.ts.map +1 -0
- package/dist/vue/marquee.js +186 -0
- package/dist/vue/marquee.js.map +1 -0
- package/dist/vue/menu.d.ts +2 -2
- package/dist/vue/navigation-controls.d.ts +1 -1
- package/dist/vue/pin-cell.d.ts +14 -0
- package/dist/vue/pin-cell.d.ts.map +1 -0
- package/dist/vue/pin-cell.js +19 -0
- package/dist/vue/pin-cell.js.map +1 -0
- package/dist/vue/pin-input.d.ts +14 -0
- package/dist/vue/pin-input.d.ts.map +1 -0
- package/dist/vue/pin-input.js +23 -0
- package/dist/vue/pin-input.js.map +1 -0
- package/dist/vue/scheduler.d.ts +229 -0
- package/dist/vue/scheduler.d.ts.map +1 -0
- package/dist/vue/scheduler.js +363 -0
- package/dist/vue/scheduler.js.map +1 -0
- package/dist/vue/screen-component-props.d.ts +236 -0
- package/dist/vue/screen-component-props.d.ts.map +1 -0
- package/dist/vue/screen-component-props.js +90 -0
- package/dist/vue/screen-component-props.js.map +1 -0
- package/dist/vue/scroll-frame.d.ts +223 -0
- package/dist/vue/scroll-frame.d.ts.map +1 -0
- package/dist/vue/scroll-frame.js +346 -0
- package/dist/vue/scroll-frame.js.map +1 -0
- package/dist/vue/speed-dial.d.ts +73 -0
- package/dist/vue/speed-dial.d.ts.map +1 -0
- package/dist/vue/speed-dial.js +78 -0
- package/dist/vue/speed-dial.js.map +1 -0
- package/dist/vue/swipe-actions.d.ts +1 -1
- package/dist/vue/swipe-deck.d.ts +120 -0
- package/dist/vue/swipe-deck.d.ts.map +1 -0
- package/dist/vue/swipe-deck.js +229 -0
- package/dist/vue/swipe-deck.js.map +1 -0
- package/dist/vue/time-picker.d.ts +6 -6
- package/dist/vue/tour.d.ts +120 -0
- package/dist/vue/tour.d.ts.map +1 -0
- package/dist/vue/tour.js +165 -0
- package/dist/vue/tour.js.map +1 -0
- package/dist/vue/tree-view.d.ts +1 -1
- package/dist/vue/wayfinding-controls.d.ts +2 -2
- package/dist/vue/workflows.d.ts +3 -3
- package/package.json +1 -1
- package/src/advanced-collections.ts +199 -0
- package/src/capabilities.ts +30 -4
- package/src/creative-controls.ts +169 -0
- package/src/dashboard.ts +164 -0
- package/src/image-crop.ts +125 -0
- package/src/index.ts +11 -0
- package/src/scheduler.ts +194 -0
- package/src/screen-components.ts +59 -0
- package/src/vue/advanced-collections.ts +679 -0
- package/src/vue/advanced-props.ts +144 -0
- package/src/vue/animated-text.ts +72 -0
- package/src/vue/component-props.ts +61 -0
- package/src/vue/composer.ts +192 -0
- package/src/vue/creative-controls.ts +524 -0
- package/src/vue/creative-props.ts +94 -0
- package/src/vue/dashboard-charts.ts +346 -0
- package/src/vue/dashboard-effects.ts +304 -0
- package/src/vue/dashboard-props.ts +95 -0
- package/src/vue/global-components.ts +162 -0
- package/src/vue/image-cropper.ts +413 -0
- package/src/vue/index.ts +28 -0
- package/src/vue/kanban.ts +360 -0
- package/src/vue/marquee.ts +248 -0
- package/src/vue/pin-cell.ts +26 -0
- package/src/vue/pin-input.ts +31 -0
- package/src/vue/scheduler.ts +505 -0
- package/src/vue/screen-component-props.ts +92 -0
- package/src/vue/scroll-frame.ts +429 -0
- package/src/vue/speed-dial.ts +108 -0
- package/src/vue/swipe-deck.ts +277 -0
- package/src/vue/tour.ts +239 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { PropType } from '@vue/runtime-core'
|
|
2
|
+
import type { KanbanCard, KanbanColumn, DonutSegment, SparklinePoint } from '../dashboard.js'
|
|
3
|
+
const label = { type: String, required: true as const }
|
|
4
|
+
const animated = { type: Boolean, default: true }
|
|
5
|
+
const colors = {
|
|
6
|
+
type: Array as PropType<readonly string[]>,
|
|
7
|
+
default: () => ['#9C5270', '#51847B', '#D5AD6C'],
|
|
8
|
+
}
|
|
9
|
+
export const kanbanProps = {
|
|
10
|
+
id: String,
|
|
11
|
+
label,
|
|
12
|
+
columns: { type: Array as PropType<readonly KanbanColumn[]>, required: true as const },
|
|
13
|
+
modelValue: { type: Array as PropType<readonly KanbanCard[]>, required: true as const },
|
|
14
|
+
query: { type: String, default: '' },
|
|
15
|
+
disabled: Boolean,
|
|
16
|
+
animated,
|
|
17
|
+
draggable: { type: Boolean, default: true },
|
|
18
|
+
moveLabel: { type: String, default: 'Move card' },
|
|
19
|
+
upLabel: { type: String, default: 'Move up' },
|
|
20
|
+
downLabel: { type: String, default: 'Move down' },
|
|
21
|
+
emptyLabel: { type: String, default: 'No cards' },
|
|
22
|
+
fullLabel: { type: String, default: 'Column full' },
|
|
23
|
+
}
|
|
24
|
+
export const donutChartProps = {
|
|
25
|
+
id: String,
|
|
26
|
+
label,
|
|
27
|
+
segments: { type: Array as PropType<readonly DonutSegment[]>, required: true as const },
|
|
28
|
+
modelValue: { type: String as PropType<string | null>, default: null },
|
|
29
|
+
size: { type: Number, default: 220 },
|
|
30
|
+
strokeWidth: { type: Number, default: 12 },
|
|
31
|
+
animated,
|
|
32
|
+
animateNumber: Boolean,
|
|
33
|
+
disabled: Boolean,
|
|
34
|
+
totalLabel: { type: String, default: 'Total' },
|
|
35
|
+
emptyLabel: { type: String, default: 'No data' },
|
|
36
|
+
formatValue: Function as PropType<(value: number) => string>,
|
|
37
|
+
}
|
|
38
|
+
export const sparklineProps = {
|
|
39
|
+
id: String,
|
|
40
|
+
label,
|
|
41
|
+
points: { type: Array as PropType<readonly SparklinePoint[]>, required: true as const },
|
|
42
|
+
domain: Array as unknown as PropType<readonly [number, number]>,
|
|
43
|
+
height: { type: Number, default: 64 },
|
|
44
|
+
color: String,
|
|
45
|
+
animated,
|
|
46
|
+
showData: Boolean,
|
|
47
|
+
dataLabel: { type: String, default: 'View data' },
|
|
48
|
+
emptyLabel: { type: String, default: 'No data' },
|
|
49
|
+
formatValue: Function as PropType<(value: number) => string>,
|
|
50
|
+
}
|
|
51
|
+
const background = {
|
|
52
|
+
id: String,
|
|
53
|
+
colors,
|
|
54
|
+
height: { type: Number, default: 280 },
|
|
55
|
+
radius: { type: String as PropType<'none' | 'sm' | 'md' | 'lg' | 'full'>, default: 'lg' },
|
|
56
|
+
}
|
|
57
|
+
export const gradientBackgroundProps = {
|
|
58
|
+
...background,
|
|
59
|
+
angle: { type: Number, default: 130 },
|
|
60
|
+
animated,
|
|
61
|
+
active: Boolean,
|
|
62
|
+
duration: { type: Number, default: 12000 },
|
|
63
|
+
}
|
|
64
|
+
export const particleFieldProps = {
|
|
65
|
+
...background,
|
|
66
|
+
active: Boolean,
|
|
67
|
+
density: { type: Number, default: 12 },
|
|
68
|
+
speed: { type: Number, default: 28 },
|
|
69
|
+
lifetime: { type: Number, default: 3000 },
|
|
70
|
+
duration: Number,
|
|
71
|
+
size: { type: Number, default: 3 },
|
|
72
|
+
shape: { type: String as PropType<'circle' | 'rectangle' | 'ring'>, default: 'circle' },
|
|
73
|
+
backgroundColor: { type: String, default: '#202A32' },
|
|
74
|
+
}
|
|
75
|
+
export const confettiProps = {
|
|
76
|
+
id: String,
|
|
77
|
+
colors,
|
|
78
|
+
trigger: { type: [String, Number], default: 0 },
|
|
79
|
+
count: { type: Number, default: 70 },
|
|
80
|
+
disabled: Boolean,
|
|
81
|
+
}
|
|
82
|
+
export const dashboardEnvironmentProps = { interactive: Boolean }
|
|
83
|
+
export const dashboardPlotProps = { height: { type: Number, required: true as const } }
|
|
84
|
+
export const dashboardShapeProps = {
|
|
85
|
+
d: { type: String, required: true as const },
|
|
86
|
+
viewBox: {
|
|
87
|
+
type: Array as unknown as PropType<readonly [number, number, number, number]>,
|
|
88
|
+
required: true as const,
|
|
89
|
+
},
|
|
90
|
+
color: { type: String, required: true as const },
|
|
91
|
+
strokeWidth: { type: Number, default: 2 },
|
|
92
|
+
start: { type: Number, default: 0 },
|
|
93
|
+
end: { type: Number, default: 1 },
|
|
94
|
+
animated,
|
|
95
|
+
}
|
|
@@ -29,6 +29,168 @@ type SheetEvents = {
|
|
|
29
29
|
/** Template props come from the same declarations used by both renderers. */
|
|
30
30
|
declare module '@vue/runtime-core' {
|
|
31
31
|
export interface GlobalComponents {
|
|
32
|
+
MTreeSelect: DefineComponent<
|
|
33
|
+
ComponentProps['MTreeSelect'] & {
|
|
34
|
+
'onUpdate:modelValue'?: (value: string[]) => void
|
|
35
|
+
'onUpdate:expanded'?: (value: string[]) => void
|
|
36
|
+
}
|
|
37
|
+
>
|
|
38
|
+
MMasonry: DefineComponent<ComponentProps['MMasonry']> & {
|
|
39
|
+
new (): {
|
|
40
|
+
$slots: {
|
|
41
|
+
item?: (props: {
|
|
42
|
+
item: import('../advanced-collections.js').MasonryItem
|
|
43
|
+
index: number
|
|
44
|
+
width: number
|
|
45
|
+
}) => unknown
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
MHeatmap: DefineComponent<
|
|
50
|
+
ComponentProps['MHeatmap'] & { 'onUpdate:modelValue'?: (date: CivilDate) => void }
|
|
51
|
+
>
|
|
52
|
+
MNotificationCenter: DefineComponent<
|
|
53
|
+
ComponentProps['MNotificationCenter'] & {
|
|
54
|
+
'onUpdate:modelValue'?: (
|
|
55
|
+
items: import('../advanced-collections.js').MavisNotification[],
|
|
56
|
+
) => void
|
|
57
|
+
'onUpdate:filter'?: (filter: 'all' | 'unread') => void
|
|
58
|
+
onAction?: (id: string) => void
|
|
59
|
+
}
|
|
60
|
+
>
|
|
61
|
+
MImageCropper: DefineComponent<
|
|
62
|
+
ComponentProps['MImageCropper'] & {
|
|
63
|
+
'onUpdate:modelValue'?: (crop: import('../image-crop.js').ImageCrop) => void
|
|
64
|
+
onExport?: (image: import('../image-crop.js').CropExport) => void
|
|
65
|
+
onError?: (failure: { stage: 'load' | 'export'; message: string }) => void
|
|
66
|
+
onLoad?: (size: { width: number; height: number }) => void
|
|
67
|
+
}
|
|
68
|
+
> & { new (): { export(): Promise<import('../image-crop.js').CropExport | undefined> } }
|
|
69
|
+
MScheduler: DefineComponent<
|
|
70
|
+
ComponentProps['MScheduler'] & {
|
|
71
|
+
'onUpdate:modelValue'?: (events: import('../scheduler.js').SchedulerEvent[]) => void
|
|
72
|
+
'onUpdate:date'?: (date: string) => void
|
|
73
|
+
onChange?: (change: import('../scheduler.js').SchedulerChange) => void
|
|
74
|
+
onSelect?: (id: string) => void
|
|
75
|
+
onError?: (message: string) => void
|
|
76
|
+
}
|
|
77
|
+
>
|
|
78
|
+
MKanban: DefineComponent<
|
|
79
|
+
ComponentProps['MKanban'] & {
|
|
80
|
+
'onUpdate:modelValue'?: (cards: import('../dashboard.js').KanbanCard[]) => void
|
|
81
|
+
onMove?: (move: import('../dashboard.js').KanbanMove) => void
|
|
82
|
+
}
|
|
83
|
+
> & {
|
|
84
|
+
new (): {
|
|
85
|
+
$slots: {
|
|
86
|
+
card?: (props: {
|
|
87
|
+
card: import('../dashboard.js').KanbanCard
|
|
88
|
+
column: import('../dashboard.js').KanbanColumn
|
|
89
|
+
}) => unknown
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
MDonutChart: DefineComponent<
|
|
94
|
+
ComponentProps['MDonutChart'] & { 'onUpdate:modelValue'?: (value: string | null) => void }
|
|
95
|
+
>
|
|
96
|
+
MSparkline: DefineComponent<ComponentProps['MSparkline']>
|
|
97
|
+
MGradientBackground: DefineComponent<ComponentProps['MGradientBackground']>
|
|
98
|
+
MParticleField: DefineComponent<ComponentProps['MParticleField']>
|
|
99
|
+
MConfetti: DefineComponent<
|
|
100
|
+
ComponentProps['MConfetti'] & {
|
|
101
|
+
onBurst?: () => void
|
|
102
|
+
onSkipped?: (reason: 'disabled' | 'reduced-motion' | 'unavailable') => void
|
|
103
|
+
}
|
|
104
|
+
> & { new (): { burst(): void; stop(): void } }
|
|
105
|
+
|
|
106
|
+
MColorPicker: DefineComponent<
|
|
107
|
+
ComponentProps['MColorPicker'] & { 'onUpdate:modelValue'?: (value: string) => void }
|
|
108
|
+
>
|
|
109
|
+
MGauge: DefineComponent<ComponentProps['MGauge']>
|
|
110
|
+
MSwipeDeck: DefineComponent<
|
|
111
|
+
ComponentProps['MSwipeDeck'] & {
|
|
112
|
+
'onUpdate:modelValue'?: (value: ChoiceValue | null) => void
|
|
113
|
+
onDecide?: (event: {
|
|
114
|
+
item: import('../creative-controls.js').SwipeCard
|
|
115
|
+
decision: import('../creative-controls.js').SwipeDecision
|
|
116
|
+
}) => void
|
|
117
|
+
onUndo?: () => void
|
|
118
|
+
}
|
|
119
|
+
>
|
|
120
|
+
MTour: DefineComponent<
|
|
121
|
+
ComponentProps['MTour'] & {
|
|
122
|
+
'onUpdate:modelValue'?: (value: string | null) => void
|
|
123
|
+
onMissing?: (id: string) => void
|
|
124
|
+
onFinish?: (reason: string) => void
|
|
125
|
+
}
|
|
126
|
+
>
|
|
127
|
+
MTourTarget: DefineComponent<ComponentProps['MTourTarget']>
|
|
128
|
+
MTransferList: DefineComponent<
|
|
129
|
+
ComponentProps['MTransferList'] & { 'onUpdate:modelValue'?: (values: ChoiceValue[]) => void }
|
|
130
|
+
>
|
|
131
|
+
MMarquee: DefineComponent<
|
|
132
|
+
ComponentProps['MMarquee'] & { 'onUpdate:paused'?: (paused: boolean) => void }
|
|
133
|
+
>
|
|
134
|
+
|
|
135
|
+
MAnimatedText: DefineComponent<ComponentProps['MAnimatedText']> & { new (): { replay(): void } }
|
|
136
|
+
MPinInput: DefineComponent<
|
|
137
|
+
ComponentProps['MPinInput'] & InputEvents & { onComplete?: (value: string) => void },
|
|
138
|
+
InputHandle
|
|
139
|
+
>
|
|
140
|
+
MSpeedDial: DefineComponent<
|
|
141
|
+
ComponentProps['MSpeedDial'] & {
|
|
142
|
+
'onUpdate:open'?: (open: boolean) => void
|
|
143
|
+
onSelect?: (
|
|
144
|
+
value: ChoiceValue,
|
|
145
|
+
action: import('../screen-components.js').SpeedDialAction,
|
|
146
|
+
) => void
|
|
147
|
+
onClose?: (reason: string) => void
|
|
148
|
+
}
|
|
149
|
+
>
|
|
150
|
+
MComposer: DefineComponent<
|
|
151
|
+
ComponentProps['MComposer'] &
|
|
152
|
+
Omit<InputEvents, 'onSubmit'> & {
|
|
153
|
+
onSubmit?: (message: import('../screen-components.js').ComposerMessage) => void
|
|
154
|
+
onAttach?: () => void
|
|
155
|
+
'onUpdate:attachments'?: (
|
|
156
|
+
items: import('../screen-components.js').ComposerAttachment[],
|
|
157
|
+
) => void
|
|
158
|
+
},
|
|
159
|
+
InputHandle
|
|
160
|
+
> & { new (): { $slots: { default?: () => unknown } } }
|
|
161
|
+
MCollapsibleHeader: DefineComponent<
|
|
162
|
+
ComponentProps['MCollapsibleHeader'] & { onBack?: () => void }
|
|
163
|
+
> & {
|
|
164
|
+
new (): {
|
|
165
|
+
scrollToTop(animated?: boolean): void
|
|
166
|
+
$slots: {
|
|
167
|
+
default?: () => unknown
|
|
168
|
+
artwork?: () => unknown
|
|
169
|
+
leading?: () => unknown
|
|
170
|
+
actions?: () => unknown
|
|
171
|
+
section?: () => unknown
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
MRefreshControl: DefineComponent<
|
|
176
|
+
ComponentProps['MRefreshControl'] & {
|
|
177
|
+
onStateChange?: (state: import('../screen-components.js').RefreshState) => void
|
|
178
|
+
onError?: (error: unknown) => void
|
|
179
|
+
}
|
|
180
|
+
> & {
|
|
181
|
+
new (): {
|
|
182
|
+
refresh(): Promise<boolean>
|
|
183
|
+
cancel(): void
|
|
184
|
+
$slots: {
|
|
185
|
+
default?: (scope: {
|
|
186
|
+
state: import('../screen-components.js').RefreshState
|
|
187
|
+
refresh(): Promise<boolean>
|
|
188
|
+
cancel(): void
|
|
189
|
+
}) => unknown
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
32
194
|
MSortableList: import('./interactive-components.js').SortableListComponent
|
|
33
195
|
MNumberFlow: DefineComponent<ComponentProps['MNumberFlow']>
|
|
34
196
|
MSwipeActions: DefineComponent<
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
markRaw,
|
|
6
|
+
mergeProps,
|
|
7
|
+
onMounted,
|
|
8
|
+
onActivated,
|
|
9
|
+
onDeactivated,
|
|
10
|
+
onScopeDispose,
|
|
11
|
+
ref,
|
|
12
|
+
shallowRef,
|
|
13
|
+
watch,
|
|
14
|
+
type Component,
|
|
15
|
+
} from '@vue/runtime-core'
|
|
16
|
+
import { createMotionSurface } from '../experimental.js'
|
|
17
|
+
import { componentMotion } from '../motion.js'
|
|
18
|
+
import {
|
|
19
|
+
fitImageCrop,
|
|
20
|
+
validateImageCrop,
|
|
21
|
+
moveImageCrop,
|
|
22
|
+
zoomImageCrop,
|
|
23
|
+
cropPresentation,
|
|
24
|
+
type ImageCrop,
|
|
25
|
+
type CropSource,
|
|
26
|
+
type CropExport,
|
|
27
|
+
type CropRotation,
|
|
28
|
+
} from '../image-crop.js'
|
|
29
|
+
import { imageCropperProps, type AdvancedGesture } from './advanced-props.js'
|
|
30
|
+
import type { AdvancedUI } from './advanced-collections.js'
|
|
31
|
+
import { useMavisTheme } from './theme.js'
|
|
32
|
+
export function createImageCropper(
|
|
33
|
+
ui: AdvancedUI & { CropPreview: Component },
|
|
34
|
+
platform: 'web' | 'native',
|
|
35
|
+
load: (src: string) => Promise<CropSource>,
|
|
36
|
+
) {
|
|
37
|
+
return defineComponent({
|
|
38
|
+
name: 'MImageCropper',
|
|
39
|
+
inheritAttrs: false,
|
|
40
|
+
props: imageCropperProps,
|
|
41
|
+
emits: {
|
|
42
|
+
'update:modelValue': (_v: ImageCrop) => true,
|
|
43
|
+
export: (_v: CropExport) => true,
|
|
44
|
+
load: (_v: { width: number; height: number }) => true,
|
|
45
|
+
error: (_v: { stage: 'load' | 'export'; message: string }) => true,
|
|
46
|
+
},
|
|
47
|
+
setup(props, { attrs, emit, expose }) {
|
|
48
|
+
const source = shallowRef<CropSource>(),
|
|
49
|
+
width = ref(320),
|
|
50
|
+
error = ref(''),
|
|
51
|
+
loading = ref(false),
|
|
52
|
+
exporting = ref(false),
|
|
53
|
+
draft = ref<ImageCrop>(),
|
|
54
|
+
surface = markRaw(createMotionSurface()),
|
|
55
|
+
{ theme } = useMavisTheme()
|
|
56
|
+
let active = false,
|
|
57
|
+
epoch = 0,
|
|
58
|
+
gestureBase: ImageCrop | undefined,
|
|
59
|
+
gestureWidth = 0
|
|
60
|
+
const effective = computed(() => {
|
|
61
|
+
if (!source.value) return undefined
|
|
62
|
+
const value =
|
|
63
|
+
draft.value ?? props.modelValue ?? fitImageCrop(source.value, props.aspectRatio)
|
|
64
|
+
return validateImageCrop(source.value, value, props.aspectRatio)
|
|
65
|
+
})
|
|
66
|
+
const zoom = computed(() =>
|
|
67
|
+
source.value && effective.value
|
|
68
|
+
? fitImageCrop(source.value, props.aspectRatio, effective.value.rotation).width /
|
|
69
|
+
effective.value.width
|
|
70
|
+
: 1,
|
|
71
|
+
)
|
|
72
|
+
function fail(stage: 'load' | 'export', failure: unknown) {
|
|
73
|
+
error.value = failure instanceof Error ? failure.message : String(failure)
|
|
74
|
+
emit('error', { stage, message: error.value })
|
|
75
|
+
}
|
|
76
|
+
function discard() {
|
|
77
|
+
epoch++
|
|
78
|
+
source.value?.dispose()
|
|
79
|
+
source.value = undefined
|
|
80
|
+
draft.value = undefined
|
|
81
|
+
gestureBase = undefined
|
|
82
|
+
loading.value = false
|
|
83
|
+
exporting.value = false
|
|
84
|
+
}
|
|
85
|
+
async function fetchSource() {
|
|
86
|
+
discard()
|
|
87
|
+
if (!active || !props.src) return
|
|
88
|
+
const request = epoch
|
|
89
|
+
loading.value = true
|
|
90
|
+
error.value = ''
|
|
91
|
+
try {
|
|
92
|
+
const result = await load(props.src)
|
|
93
|
+
if (!active || request !== epoch) {
|
|
94
|
+
result.dispose()
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
if (result.width * result.height > 40000000) {
|
|
98
|
+
result.dispose()
|
|
99
|
+
throw new RangeError('ImageCropper supports decoded images up to 40 megapixels.')
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
validateImageCrop(
|
|
103
|
+
result,
|
|
104
|
+
props.modelValue ?? fitImageCrop(result, props.aspectRatio),
|
|
105
|
+
props.aspectRatio,
|
|
106
|
+
)
|
|
107
|
+
} catch (error) {
|
|
108
|
+
result.dispose()
|
|
109
|
+
throw error
|
|
110
|
+
}
|
|
111
|
+
source.value = markRaw(result)
|
|
112
|
+
emit('load', { width: result.width, height: result.height })
|
|
113
|
+
} catch (e) {
|
|
114
|
+
if (request === epoch) fail('load', e)
|
|
115
|
+
} finally {
|
|
116
|
+
if (request === epoch) loading.value = false
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
onMounted(() => {
|
|
120
|
+
active = true
|
|
121
|
+
void fetchSource()
|
|
122
|
+
})
|
|
123
|
+
onActivated(() => {
|
|
124
|
+
if (!active) {
|
|
125
|
+
active = true
|
|
126
|
+
void fetchSource()
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
onDeactivated(() => {
|
|
130
|
+
active = false
|
|
131
|
+
discard()
|
|
132
|
+
})
|
|
133
|
+
onScopeDispose(() => {
|
|
134
|
+
active = false
|
|
135
|
+
discard()
|
|
136
|
+
})
|
|
137
|
+
watch(
|
|
138
|
+
() => props.src,
|
|
139
|
+
() => {
|
|
140
|
+
if (active) void fetchSource()
|
|
141
|
+
},
|
|
142
|
+
)
|
|
143
|
+
watch(
|
|
144
|
+
() => [props.disabled, props.modelValue, props.aspectRatio],
|
|
145
|
+
() => {
|
|
146
|
+
draft.value = undefined
|
|
147
|
+
gestureBase = undefined
|
|
148
|
+
},
|
|
149
|
+
{ flush: 'sync', deep: true },
|
|
150
|
+
)
|
|
151
|
+
onScopeDispose(
|
|
152
|
+
surface.use((owner) => {
|
|
153
|
+
let initialized = false
|
|
154
|
+
return watch(
|
|
155
|
+
() => [effective.value, width.value, props.animated, draft.value],
|
|
156
|
+
() => {
|
|
157
|
+
const crop = effective.value,
|
|
158
|
+
image = source.value
|
|
159
|
+
if (!crop || !image) return
|
|
160
|
+
const presentation = cropPresentation(image, crop, width.value),
|
|
161
|
+
values = { x: presentation.x, y: presentation.y, rotate: presentation.rotation }
|
|
162
|
+
if (initialized && props.animated && !draft.value)
|
|
163
|
+
owner.animate(values, componentMotion(theme.value, 'selection'))
|
|
164
|
+
else owner.set(values)
|
|
165
|
+
initialized = true
|
|
166
|
+
},
|
|
167
|
+
{ immediate: true, flush: 'post' },
|
|
168
|
+
)
|
|
169
|
+
}),
|
|
170
|
+
)
|
|
171
|
+
function choose(value: ImageCrop) {
|
|
172
|
+
if (!props.disabled && source.value) {
|
|
173
|
+
validateImageCrop(source.value, value, props.aspectRatio)
|
|
174
|
+
emit('update:modelValue', value)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function gesture(event: AdvancedGesture) {
|
|
178
|
+
const image = source.value,
|
|
179
|
+
crop = effective.value
|
|
180
|
+
if (!image || !crop || props.disabled) return
|
|
181
|
+
if (event.phase === 'start') {
|
|
182
|
+
gestureBase = { ...crop }
|
|
183
|
+
gestureWidth = width.value
|
|
184
|
+
}
|
|
185
|
+
if (event.phase === 'move' && gestureBase) {
|
|
186
|
+
const base = gestureBase
|
|
187
|
+
const z = zoomImageCrop(
|
|
188
|
+
image,
|
|
189
|
+
base,
|
|
190
|
+
Math.min(
|
|
191
|
+
8,
|
|
192
|
+
Math.max(
|
|
193
|
+
1,
|
|
194
|
+
(fitImageCrop(image, props.aspectRatio, base.rotation).width / base.width) *
|
|
195
|
+
event.scale,
|
|
196
|
+
),
|
|
197
|
+
),
|
|
198
|
+
)
|
|
199
|
+
draft.value = moveImageCrop(
|
|
200
|
+
image,
|
|
201
|
+
z,
|
|
202
|
+
(-event.x * base.width) / gestureWidth,
|
|
203
|
+
(-event.y * base.width) / gestureWidth,
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
if (event.phase === 'end') {
|
|
207
|
+
const value = draft.value
|
|
208
|
+
gestureBase = undefined
|
|
209
|
+
draft.value = undefined
|
|
210
|
+
if (value) choose(value)
|
|
211
|
+
}
|
|
212
|
+
if (event.phase === 'cancel') {
|
|
213
|
+
gestureBase = undefined
|
|
214
|
+
draft.value = undefined
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function pan(x: number, y: number) {
|
|
218
|
+
if (source.value && effective.value)
|
|
219
|
+
choose(
|
|
220
|
+
moveImageCrop(
|
|
221
|
+
source.value,
|
|
222
|
+
effective.value,
|
|
223
|
+
(x * effective.value.width) / 20,
|
|
224
|
+
(y * effective.value.height) / 20,
|
|
225
|
+
),
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
async function exportImage() {
|
|
229
|
+
if (props.disabled || exporting.value || !source.value || !effective.value) return
|
|
230
|
+
const request = epoch,
|
|
231
|
+
image = source.value,
|
|
232
|
+
crop = { ...effective.value }
|
|
233
|
+
exporting.value = true
|
|
234
|
+
error.value = ''
|
|
235
|
+
try {
|
|
236
|
+
const result = await image.export(crop, props.output)
|
|
237
|
+
if (!active || request !== epoch || props.disabled) {
|
|
238
|
+
await result.dispose()
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
emit('export', result)
|
|
242
|
+
return result
|
|
243
|
+
} catch (e) {
|
|
244
|
+
if (request === epoch) fail('export', e)
|
|
245
|
+
} finally {
|
|
246
|
+
if (request === epoch) exporting.value = false
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
expose({ export: exportImage })
|
|
250
|
+
return () =>
|
|
251
|
+
h(
|
|
252
|
+
ui.Host,
|
|
253
|
+
mergeProps(attrs, {
|
|
254
|
+
id: props.id,
|
|
255
|
+
label: props.label,
|
|
256
|
+
...(platform === 'web' ? { class: 'm-image-cropper' } : {}),
|
|
257
|
+
}),
|
|
258
|
+
() =>
|
|
259
|
+
h(ui.Column, { gap: 'md' }, () => [
|
|
260
|
+
h(ui.Text, { text: props.label, variant: 'heading' }),
|
|
261
|
+
h(
|
|
262
|
+
ui.Measure,
|
|
263
|
+
{
|
|
264
|
+
onWidth: (v: number) => {
|
|
265
|
+
if (v > 0 && Math.abs(width.value - v) > 0.5) {
|
|
266
|
+
gestureBase = undefined
|
|
267
|
+
draft.value = undefined
|
|
268
|
+
width.value = v
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
() =>
|
|
273
|
+
h(
|
|
274
|
+
ui.Gesture,
|
|
275
|
+
{
|
|
276
|
+
label: props.moveLabel,
|
|
277
|
+
disabled: props.disabled || !source.value,
|
|
278
|
+
onGesture: gesture,
|
|
279
|
+
onStep: (v: { x: number; y: number }) => pan(-v.x, -v.y),
|
|
280
|
+
},
|
|
281
|
+
() =>
|
|
282
|
+
h(
|
|
283
|
+
ui.Box,
|
|
284
|
+
{
|
|
285
|
+
backgroundColor: '#20232A',
|
|
286
|
+
radius: 'lg',
|
|
287
|
+
clipToBounds: true,
|
|
288
|
+
height: width.value / props.aspectRatio,
|
|
289
|
+
width: '100%',
|
|
290
|
+
...(platform === 'web'
|
|
291
|
+
? { style: { overflow: 'hidden', position: 'relative' } }
|
|
292
|
+
: {}),
|
|
293
|
+
},
|
|
294
|
+
() => {
|
|
295
|
+
const crop = effective.value,
|
|
296
|
+
image = source.value
|
|
297
|
+
if (!crop || !image)
|
|
298
|
+
return [
|
|
299
|
+
h(ui.Text, {
|
|
300
|
+
text: loading.value
|
|
301
|
+
? props.loadingLabel
|
|
302
|
+
: error.value || props.loadingLabel,
|
|
303
|
+
tone: 'muted',
|
|
304
|
+
}),
|
|
305
|
+
]
|
|
306
|
+
const presentation = cropPresentation(image, crop, width.value)
|
|
307
|
+
return [
|
|
308
|
+
h(ui.CropPreview, {
|
|
309
|
+
source: image,
|
|
310
|
+
width: presentation.width,
|
|
311
|
+
height: presentation.height,
|
|
312
|
+
motionSurface: surface,
|
|
313
|
+
}),
|
|
314
|
+
h(ui.Box, {
|
|
315
|
+
width: '100%',
|
|
316
|
+
height: '100%',
|
|
317
|
+
borderWidth: 1,
|
|
318
|
+
borderColor: '#FFFFFF',
|
|
319
|
+
accessibilityHidden: true,
|
|
320
|
+
isUserInteractionEnabled: false,
|
|
321
|
+
...(platform === 'web'
|
|
322
|
+
? {
|
|
323
|
+
style: {
|
|
324
|
+
position: 'absolute',
|
|
325
|
+
inset: 0,
|
|
326
|
+
pointerEvents: 'none',
|
|
327
|
+
border: '1px solid #FFFFFF',
|
|
328
|
+
boxSizing: 'border-box',
|
|
329
|
+
backgroundImage:
|
|
330
|
+
'linear-gradient(90deg, transparent 33%, #ffffff50 33%, #ffffff50 33.4%, transparent 33.4%, transparent 66%, #ffffff50 66%, #ffffff50 66.4%, transparent 66.4%)',
|
|
331
|
+
},
|
|
332
|
+
}
|
|
333
|
+
: {}),
|
|
334
|
+
}),
|
|
335
|
+
]
|
|
336
|
+
},
|
|
337
|
+
),
|
|
338
|
+
),
|
|
339
|
+
),
|
|
340
|
+
error.value
|
|
341
|
+
? h(ui.Text, {
|
|
342
|
+
text: error.value,
|
|
343
|
+
...(platform === 'web' ? { role: 'alert' } : {}),
|
|
344
|
+
})
|
|
345
|
+
: null,
|
|
346
|
+
h(ui.Slider, {
|
|
347
|
+
label: props.zoomLabel,
|
|
348
|
+
min: 1,
|
|
349
|
+
max: 8,
|
|
350
|
+
step: 0.1,
|
|
351
|
+
modelValue: zoom.value,
|
|
352
|
+
disabled: props.disabled || !source.value,
|
|
353
|
+
'onUpdate:modelValue': (v: number) => {
|
|
354
|
+
if (source.value && effective.value)
|
|
355
|
+
choose(zoomImageCrop(source.value, effective.value, v))
|
|
356
|
+
},
|
|
357
|
+
}),
|
|
358
|
+
h(ui.Row, { gap: 'xs', wrap: true }, () =>
|
|
359
|
+
[
|
|
360
|
+
[props.leftLabel, -1, 0],
|
|
361
|
+
[props.rightLabel, 1, 0],
|
|
362
|
+
[props.upLabel, 0, -1],
|
|
363
|
+
[props.downLabel, 0, 1],
|
|
364
|
+
].map(([label, x, y]) =>
|
|
365
|
+
h(ui.Button, {
|
|
366
|
+
text: label,
|
|
367
|
+
variant: 'ghost',
|
|
368
|
+
size: 'sm',
|
|
369
|
+
disabled: props.disabled || !source.value,
|
|
370
|
+
onClick: () => pan(x as number, y as number),
|
|
371
|
+
}),
|
|
372
|
+
),
|
|
373
|
+
),
|
|
374
|
+
h(
|
|
375
|
+
ui.Stack,
|
|
376
|
+
{ direction: 'column', responsive: { at: 520, direction: 'row' }, gap: 'sm' },
|
|
377
|
+
() => [
|
|
378
|
+
h(ui.Button, {
|
|
379
|
+
text: props.rotateLabel,
|
|
380
|
+
variant: 'secondary',
|
|
381
|
+
disabled: props.disabled || !source.value,
|
|
382
|
+
onClick: () => {
|
|
383
|
+
if (source.value && effective.value)
|
|
384
|
+
choose(
|
|
385
|
+
fitImageCrop(
|
|
386
|
+
source.value,
|
|
387
|
+
props.aspectRatio,
|
|
388
|
+
((effective.value.rotation + 90) % 360) as CropRotation,
|
|
389
|
+
),
|
|
390
|
+
)
|
|
391
|
+
},
|
|
392
|
+
}),
|
|
393
|
+
h(ui.Button, {
|
|
394
|
+
text: props.resetLabel,
|
|
395
|
+
variant: 'ghost',
|
|
396
|
+
disabled: props.disabled || !source.value,
|
|
397
|
+
onClick: () => {
|
|
398
|
+
if (source.value) choose(fitImageCrop(source.value, props.aspectRatio))
|
|
399
|
+
},
|
|
400
|
+
}),
|
|
401
|
+
h(ui.Button, {
|
|
402
|
+
text: props.exportLabel,
|
|
403
|
+
loading: exporting.value,
|
|
404
|
+
disabled: props.disabled || !source.value || exporting.value,
|
|
405
|
+
onClick: () => void exportImage(),
|
|
406
|
+
}),
|
|
407
|
+
],
|
|
408
|
+
),
|
|
409
|
+
]),
|
|
410
|
+
)
|
|
411
|
+
},
|
|
412
|
+
})
|
|
413
|
+
}
|