@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,524 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
markRaw,
|
|
6
|
+
mergeProps,
|
|
7
|
+
nextTick,
|
|
8
|
+
onScopeDispose,
|
|
9
|
+
ref,
|
|
10
|
+
watch,
|
|
11
|
+
type Component,
|
|
12
|
+
} from '@vue/runtime-core'
|
|
13
|
+
import {
|
|
14
|
+
colorHex,
|
|
15
|
+
colorHsv,
|
|
16
|
+
hsvColor,
|
|
17
|
+
parseColor,
|
|
18
|
+
gaugeGeometry,
|
|
19
|
+
transferValues,
|
|
20
|
+
type HsvColor,
|
|
21
|
+
} from '../creative-controls.js'
|
|
22
|
+
import { createMotionSurface, type MotionGradient } from '../experimental.js'
|
|
23
|
+
import { colorPickerProps, gaugeProps, transferListProps } from './creative-props.js'
|
|
24
|
+
import { useComponentLayout } from './component-motion.js'
|
|
25
|
+
import { useMavisTheme } from './theme.js'
|
|
26
|
+
import { componentMotion } from '../motion.js'
|
|
27
|
+
import { choiceKey, validateChoices, type ChoiceValue } from '../choice.js'
|
|
28
|
+
|
|
29
|
+
export interface CreativeUI {
|
|
30
|
+
Box: Component
|
|
31
|
+
Column: Component
|
|
32
|
+
Row: Component
|
|
33
|
+
Stack: Component
|
|
34
|
+
Card: Component
|
|
35
|
+
Text: Component
|
|
36
|
+
Button: Component
|
|
37
|
+
Input: Component
|
|
38
|
+
Slider: Component
|
|
39
|
+
Checkbox: Component
|
|
40
|
+
NumberFlow: Component
|
|
41
|
+
Image: Component
|
|
42
|
+
GaugeFallback: Component
|
|
43
|
+
}
|
|
44
|
+
export function createColorPicker(ui: CreativeUI, platform: 'web' | 'native') {
|
|
45
|
+
return defineComponent({
|
|
46
|
+
name: 'MColorPicker',
|
|
47
|
+
inheritAttrs: false,
|
|
48
|
+
props: colorPickerProps,
|
|
49
|
+
emits: { 'update:modelValue': (_color: string) => true },
|
|
50
|
+
setup(props, { attrs, emit }) {
|
|
51
|
+
const { theme } = useMavisTheme()
|
|
52
|
+
const color = computed(() => {
|
|
53
|
+
const parsed = parseColor(props.modelValue)
|
|
54
|
+
if (!parsed) throw new TypeError('MColorPicker modelValue must be HEX or RGB(A).')
|
|
55
|
+
return parsed
|
|
56
|
+
})
|
|
57
|
+
const hue = ref(colorHsv(color.value).h)
|
|
58
|
+
const hsv = computed(() => {
|
|
59
|
+
const value = colorHsv(color.value)
|
|
60
|
+
return { ...value, h: value.s && value.v ? value.h : hue.value }
|
|
61
|
+
})
|
|
62
|
+
const draft = ref(props.modelValue),
|
|
63
|
+
invalid = ref(false)
|
|
64
|
+
const surface = markRaw(createMotionSurface())
|
|
65
|
+
const colors = () => [
|
|
66
|
+
colorHex({ ...color.value, a: 1 }),
|
|
67
|
+
colorHex(hsvColor({ ...hsv.value, v: Math.max(15, hsv.value.v * 0.65), a: 1 })),
|
|
68
|
+
]
|
|
69
|
+
let gradient: MotionGradient | undefined
|
|
70
|
+
onScopeDispose(
|
|
71
|
+
surface.use((owner) => {
|
|
72
|
+
if (!owner.supports('gradient')) return
|
|
73
|
+
gradient = owner.gradient({ type: 'linear', colors: colors(), angle: 130 })
|
|
74
|
+
return () => {
|
|
75
|
+
gradient?.dispose()
|
|
76
|
+
gradient = undefined
|
|
77
|
+
}
|
|
78
|
+
}),
|
|
79
|
+
)
|
|
80
|
+
watch(
|
|
81
|
+
() => props.modelValue,
|
|
82
|
+
() => {
|
|
83
|
+
draft.value = props.modelValue
|
|
84
|
+
invalid.value = false
|
|
85
|
+
if (hsv.value.s && hsv.value.v) hue.value = hsv.value.h
|
|
86
|
+
if (props.animated)
|
|
87
|
+
gradient?.animate({ colors: colors() }, componentMotion(theme.value, 'data'))
|
|
88
|
+
else gradient?.set({ colors: colors() })
|
|
89
|
+
},
|
|
90
|
+
)
|
|
91
|
+
watch(
|
|
92
|
+
() => props.animated,
|
|
93
|
+
(animated) => {
|
|
94
|
+
if (!animated) {
|
|
95
|
+
gradient?.stop()
|
|
96
|
+
gradient?.set({ colors: colors() })
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
)
|
|
100
|
+
function choose(value: string) {
|
|
101
|
+
if (props.disabled || props.readonly) return
|
|
102
|
+
const parsed = parseColor(value)
|
|
103
|
+
invalid.value = !parsed
|
|
104
|
+
if (parsed) {
|
|
105
|
+
emit('update:modelValue', colorHex(parsed, props.alpha))
|
|
106
|
+
void nextTick(() => {
|
|
107
|
+
draft.value = props.modelValue
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function channel(key: keyof HsvColor, value: number) {
|
|
112
|
+
if (props.disabled || props.readonly) return
|
|
113
|
+
if (key === 'h') hue.value = value
|
|
114
|
+
choose(
|
|
115
|
+
colorHex(
|
|
116
|
+
hsvColor({ ...hsv.value, [key]: key === 'a' ? value / 100 : value }),
|
|
117
|
+
props.alpha,
|
|
118
|
+
),
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
return () =>
|
|
122
|
+
h(
|
|
123
|
+
ui.Column,
|
|
124
|
+
mergeProps(attrs, {
|
|
125
|
+
id: props.id,
|
|
126
|
+
gap: 'md',
|
|
127
|
+
...(platform === 'web'
|
|
128
|
+
? { role: 'group', 'aria-label': props.label, class: 'm-color-picker' }
|
|
129
|
+
: { accessibilityLabel: props.label }),
|
|
130
|
+
}),
|
|
131
|
+
{
|
|
132
|
+
default: () => [
|
|
133
|
+
h(ui.Text, { text: props.label, variant: 'heading' }),
|
|
134
|
+
h(ui.Box, {
|
|
135
|
+
motionSurface: surface,
|
|
136
|
+
backgroundColor: colorHex(color.value),
|
|
137
|
+
height: 112,
|
|
138
|
+
radius: 'lg',
|
|
139
|
+
padding: 'lg',
|
|
140
|
+
accessibilityHidden: true,
|
|
141
|
+
}),
|
|
142
|
+
h(ui.Input, {
|
|
143
|
+
label: props.colorLabel,
|
|
144
|
+
modelValue: draft.value,
|
|
145
|
+
disabled: props.disabled,
|
|
146
|
+
readonly: props.readonly,
|
|
147
|
+
error: invalid.value ? props.invalidLabel : undefined,
|
|
148
|
+
'onUpdate:modelValue': (value: string) => {
|
|
149
|
+
draft.value = value
|
|
150
|
+
const parsed = parseColor(value)
|
|
151
|
+
invalid.value = !parsed
|
|
152
|
+
if (parsed && !props.disabled && !props.readonly)
|
|
153
|
+
emit('update:modelValue', colorHex(parsed, props.alpha))
|
|
154
|
+
},
|
|
155
|
+
onBlur: () => {
|
|
156
|
+
if (!invalid.value) draft.value = props.modelValue
|
|
157
|
+
},
|
|
158
|
+
}),
|
|
159
|
+
...(
|
|
160
|
+
[
|
|
161
|
+
['h', props.hueLabel, 360],
|
|
162
|
+
['s', props.saturationLabel, 100],
|
|
163
|
+
['v', props.brightnessLabel, 100],
|
|
164
|
+
...(props.alpha ? [['a', props.alphaLabel, 100]] : []),
|
|
165
|
+
] as [keyof HsvColor, string, number][]
|
|
166
|
+
).map(([key, label, max]) => {
|
|
167
|
+
const value =
|
|
168
|
+
key === 'a' ? Math.round(hsv.value.a * 100) : Math.round(hsv.value[key])
|
|
169
|
+
return h(
|
|
170
|
+
ui.Column,
|
|
171
|
+
{ key, gap: 'xs' },
|
|
172
|
+
{
|
|
173
|
+
default: () => [
|
|
174
|
+
h(
|
|
175
|
+
ui.Row,
|
|
176
|
+
{ justify: 'between', gap: 'sm' },
|
|
177
|
+
{
|
|
178
|
+
default: () => [
|
|
179
|
+
h(ui.Text, { text: label, variant: 'caption' }),
|
|
180
|
+
h(ui.Text, {
|
|
181
|
+
text: `${value}${key === 'h' ? '°' : '%'}`,
|
|
182
|
+
variant: 'caption',
|
|
183
|
+
tone: 'muted',
|
|
184
|
+
}),
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
),
|
|
188
|
+
h(ui.Slider, {
|
|
189
|
+
label,
|
|
190
|
+
modelValue: value,
|
|
191
|
+
max,
|
|
192
|
+
disabled: props.disabled || props.readonly,
|
|
193
|
+
'onUpdate:modelValue': (value: number) => channel(key, value),
|
|
194
|
+
}),
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
)
|
|
198
|
+
}),
|
|
199
|
+
h(ui.Text, { text: props.paletteLabel, variant: 'caption' }),
|
|
200
|
+
h(
|
|
201
|
+
ui.Row,
|
|
202
|
+
{ gap: 'xs', wrap: true },
|
|
203
|
+
{
|
|
204
|
+
default: () =>
|
|
205
|
+
props.palette.map((value, index) => {
|
|
206
|
+
const parsed = parseColor(value)
|
|
207
|
+
if (!parsed) throw new TypeError('Invalid palette color.')
|
|
208
|
+
const hex = colorHex(parsed, props.alpha)
|
|
209
|
+
return h(
|
|
210
|
+
ui.Button,
|
|
211
|
+
{
|
|
212
|
+
key: `${index}:${value}`,
|
|
213
|
+
text: hex,
|
|
214
|
+
size: 'sm',
|
|
215
|
+
variant:
|
|
216
|
+
hex === colorHex(color.value, props.alpha) ? 'primary' : 'secondary',
|
|
217
|
+
disabled: props.disabled || props.readonly,
|
|
218
|
+
...(platform === 'web'
|
|
219
|
+
? { 'aria-pressed': hex === colorHex(color.value, props.alpha) }
|
|
220
|
+
: {}),
|
|
221
|
+
onClick: () => choose(value),
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
leading: () =>
|
|
225
|
+
h(ui.Box, {
|
|
226
|
+
width: 18,
|
|
227
|
+
height: 18,
|
|
228
|
+
radius: 'full',
|
|
229
|
+
backgroundColor: hex,
|
|
230
|
+
borderColor: theme.value.colors.border,
|
|
231
|
+
borderWidth: 1,
|
|
232
|
+
}),
|
|
233
|
+
},
|
|
234
|
+
)
|
|
235
|
+
}),
|
|
236
|
+
},
|
|
237
|
+
),
|
|
238
|
+
],
|
|
239
|
+
},
|
|
240
|
+
)
|
|
241
|
+
},
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
export function createGauge(ui: CreativeUI, platform: 'web' | 'native') {
|
|
245
|
+
return defineComponent({
|
|
246
|
+
name: 'MGauge',
|
|
247
|
+
inheritAttrs: false,
|
|
248
|
+
props: gaugeProps,
|
|
249
|
+
setup(props, { attrs }) {
|
|
250
|
+
const { theme } = useMavisTheme()
|
|
251
|
+
const geometry = computed(() => gaugeGeometry(props.value, props.min, props.max, props.semi))
|
|
252
|
+
const surface = markRaw(createMotionSurface()),
|
|
253
|
+
track = markRaw(createMotionSurface())
|
|
254
|
+
const ready = ref(false)
|
|
255
|
+
const paint = (owner: typeof surface, foreground: boolean) => {
|
|
256
|
+
let dispose = () => {}
|
|
257
|
+
const stop = watch(
|
|
258
|
+
() => [props.semi, props.strokeWidth, props.color, theme.value],
|
|
259
|
+
() => {
|
|
260
|
+
dispose()
|
|
261
|
+
if (!owner.supports('shape')) return
|
|
262
|
+
const g = geometry.value
|
|
263
|
+
const shape = owner.shape({
|
|
264
|
+
d: g.path,
|
|
265
|
+
viewBox: g.viewBox,
|
|
266
|
+
fill: 'transparent',
|
|
267
|
+
stroke: foreground
|
|
268
|
+
? (props.color ?? theme.value.colors.primary)
|
|
269
|
+
: theme.value.colors.border,
|
|
270
|
+
strokeWidth: props.strokeWidth,
|
|
271
|
+
lineCap: 'round',
|
|
272
|
+
strokeEnd: foreground ? g.ratio : 1,
|
|
273
|
+
})
|
|
274
|
+
if (foreground) ready.value = true
|
|
275
|
+
const unwatch = foreground
|
|
276
|
+
? watch(
|
|
277
|
+
() => [geometry.value.ratio, props.animated],
|
|
278
|
+
() => {
|
|
279
|
+
if (props.animated)
|
|
280
|
+
shape.animate(
|
|
281
|
+
{ strokeEnd: geometry.value.ratio },
|
|
282
|
+
componentMotion(theme.value, 'data'),
|
|
283
|
+
)
|
|
284
|
+
else shape.set({ strokeEnd: geometry.value.ratio })
|
|
285
|
+
},
|
|
286
|
+
)
|
|
287
|
+
: () => {}
|
|
288
|
+
dispose = () => {
|
|
289
|
+
unwatch()
|
|
290
|
+
shape.dispose()
|
|
291
|
+
if (foreground) ready.value = false
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
{ immediate: true },
|
|
295
|
+
)
|
|
296
|
+
return () => {
|
|
297
|
+
stop()
|
|
298
|
+
dispose()
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
onScopeDispose(surface.use((owner) => paint(owner, true)))
|
|
302
|
+
onScopeDispose(track.use((owner) => paint(owner, false)))
|
|
303
|
+
return () => {
|
|
304
|
+
if (
|
|
305
|
+
!Number.isFinite(props.size) ||
|
|
306
|
+
props.size < 80 ||
|
|
307
|
+
!Number.isFinite(props.strokeWidth) ||
|
|
308
|
+
props.strokeWidth <= 0 ||
|
|
309
|
+
props.strokeWidth > 18
|
|
310
|
+
)
|
|
311
|
+
throw new RangeError('Gauge size must be at least 80 and strokeWidth in (0, 18].')
|
|
312
|
+
const value = geometry.value.value,
|
|
313
|
+
display = (props.formatValue?.(value) ?? String(value)) + props.suffix
|
|
314
|
+
const height = props.size * (props.semi ? 0.58 : 1)
|
|
315
|
+
return h(
|
|
316
|
+
ui.Column,
|
|
317
|
+
mergeProps(attrs, {
|
|
318
|
+
id: props.id,
|
|
319
|
+
gap: 'sm',
|
|
320
|
+
align: 'center',
|
|
321
|
+
...(platform === 'web'
|
|
322
|
+
? {
|
|
323
|
+
class: 'm-gauge',
|
|
324
|
+
role: 'meter',
|
|
325
|
+
'aria-label': props.label,
|
|
326
|
+
'aria-valuemin': props.min,
|
|
327
|
+
'aria-valuemax': props.max,
|
|
328
|
+
'aria-valuenow': value,
|
|
329
|
+
'aria-valuetext': display,
|
|
330
|
+
}
|
|
331
|
+
: { accessibilityLabel: `${props.label}: ${display}`, accessible: true }),
|
|
332
|
+
}),
|
|
333
|
+
{
|
|
334
|
+
default: () => [
|
|
335
|
+
h(
|
|
336
|
+
ui.Box,
|
|
337
|
+
{
|
|
338
|
+
width: props.size,
|
|
339
|
+
height,
|
|
340
|
+
accessibilityHidden: true,
|
|
341
|
+
...(platform === 'web' ? { style: { display: 'grid', maxWidth: '100%' } } : {}),
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
default: () => [
|
|
345
|
+
h(ui.GaugeFallback, {
|
|
346
|
+
geometry: geometry.value,
|
|
347
|
+
size: props.size,
|
|
348
|
+
strokeWidth: props.strokeWidth,
|
|
349
|
+
color: props.color ?? theme.value.colors.primary,
|
|
350
|
+
track: theme.value.colors.border,
|
|
351
|
+
hidden: ready.value,
|
|
352
|
+
}),
|
|
353
|
+
...[track, surface].map((motionSurface, i) =>
|
|
354
|
+
h(ui.Box, {
|
|
355
|
+
key: i,
|
|
356
|
+
motionSurface,
|
|
357
|
+
width: '100%',
|
|
358
|
+
height: '100%',
|
|
359
|
+
...(platform === 'web'
|
|
360
|
+
? { style: { gridArea: '1 / 1', pointerEvents: 'none' } }
|
|
361
|
+
: {}),
|
|
362
|
+
}),
|
|
363
|
+
),
|
|
364
|
+
],
|
|
365
|
+
},
|
|
366
|
+
),
|
|
367
|
+
h(ui.NumberFlow, {
|
|
368
|
+
value,
|
|
369
|
+
animated: props.animateNumber && props.animated,
|
|
370
|
+
formatValue: (n: number) =>
|
|
371
|
+
(props.formatValue?.(n) ?? String(Math.round(n * 100) / 100)) + props.suffix,
|
|
372
|
+
accessibilityHidden: true,
|
|
373
|
+
variant: 'display',
|
|
374
|
+
}),
|
|
375
|
+
h(ui.Text, { text: props.label, variant: 'caption', accessibilityHidden: true }),
|
|
376
|
+
],
|
|
377
|
+
},
|
|
378
|
+
)
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
export function createTransferList(ui: CreativeUI, platform: 'web' | 'native') {
|
|
384
|
+
return defineComponent({
|
|
385
|
+
name: 'MTransferList',
|
|
386
|
+
inheritAttrs: false,
|
|
387
|
+
props: transferListProps,
|
|
388
|
+
emits: { 'update:modelValue': (_values: ChoiceValue[]) => true },
|
|
389
|
+
setup(props, { attrs, emit }) {
|
|
390
|
+
const checked = ref<ChoiceValue[]>([]),
|
|
391
|
+
search = ref(['', ''])
|
|
392
|
+
const region = useComponentLayout(
|
|
393
|
+
() => [props.modelValue, props.options, search.value],
|
|
394
|
+
true,
|
|
395
|
+
() => props.animated,
|
|
396
|
+
)
|
|
397
|
+
watch(
|
|
398
|
+
() => [props.options, props.modelValue],
|
|
399
|
+
() => {
|
|
400
|
+
checked.value = checked.value.filter((value) =>
|
|
401
|
+
props.options.some((option) => option.value === value && !option.disabled),
|
|
402
|
+
)
|
|
403
|
+
},
|
|
404
|
+
{ deep: true },
|
|
405
|
+
)
|
|
406
|
+
const side = (selected: boolean) =>
|
|
407
|
+
props.options.filter((option) => props.modelValue.includes(option.value) === selected)
|
|
408
|
+
function move(selected: boolean) {
|
|
409
|
+
if (props.disabled) return
|
|
410
|
+
const values = side(selected)
|
|
411
|
+
.filter((option) => checked.value.includes(option.value) && !option.disabled)
|
|
412
|
+
.map((option) => option.value)
|
|
413
|
+
emit(
|
|
414
|
+
'update:modelValue',
|
|
415
|
+
transferValues(props.options, props.modelValue, values, selected ? 'remove' : 'add'),
|
|
416
|
+
)
|
|
417
|
+
void nextTick(() => {
|
|
418
|
+
checked.value = checked.value.filter(
|
|
419
|
+
(value) => !values.includes(value) || props.modelValue.includes(value) === selected,
|
|
420
|
+
)
|
|
421
|
+
})
|
|
422
|
+
}
|
|
423
|
+
return () => {
|
|
424
|
+
validateChoices(props.options, null)
|
|
425
|
+
return h(
|
|
426
|
+
ui.Column,
|
|
427
|
+
mergeProps(attrs, {
|
|
428
|
+
id: props.id,
|
|
429
|
+
gap: 'md',
|
|
430
|
+
...(platform === 'web'
|
|
431
|
+
? { role: 'group', 'aria-label': props.label, class: 'm-transfer-list' }
|
|
432
|
+
: { accessibilityLabel: props.label }),
|
|
433
|
+
}),
|
|
434
|
+
{
|
|
435
|
+
default: () => [
|
|
436
|
+
h(ui.Text, { text: props.label, variant: 'heading' }),
|
|
437
|
+
h(
|
|
438
|
+
ui.Stack,
|
|
439
|
+
{
|
|
440
|
+
direction: 'column',
|
|
441
|
+
responsive: { at: 620, direction: 'row' },
|
|
442
|
+
gap: 'md',
|
|
443
|
+
align: 'stretch',
|
|
444
|
+
motionRegion: region,
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
default: () =>
|
|
448
|
+
[false, true].map((selected, index) => {
|
|
449
|
+
const label = selected ? props.selectedLabel : props.availableLabel
|
|
450
|
+
const visible = side(selected).filter((option) =>
|
|
451
|
+
option.label
|
|
452
|
+
.toLowerCase()
|
|
453
|
+
.includes(search.value[index]!.trim().toLowerCase()),
|
|
454
|
+
)
|
|
455
|
+
return h(
|
|
456
|
+
ui.Card,
|
|
457
|
+
{ key: index, padding: 'md', grow: 1, shrink: 1 },
|
|
458
|
+
{
|
|
459
|
+
default: () =>
|
|
460
|
+
h(
|
|
461
|
+
ui.Column,
|
|
462
|
+
{
|
|
463
|
+
gap: 'sm',
|
|
464
|
+
...(platform === 'web'
|
|
465
|
+
? { role: 'group', 'aria-label': label }
|
|
466
|
+
: {}),
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
default: () => [
|
|
470
|
+
h(ui.Text, {
|
|
471
|
+
text: `${label} · ${side(selected).length}`,
|
|
472
|
+
variant: 'heading',
|
|
473
|
+
}),
|
|
474
|
+
h(ui.Input, {
|
|
475
|
+
label: `${props.searchLabel}: ${label}`,
|
|
476
|
+
disabled: props.disabled,
|
|
477
|
+
modelValue: search.value[index],
|
|
478
|
+
'onUpdate:modelValue': (value: string) => {
|
|
479
|
+
search.value[index] = value
|
|
480
|
+
},
|
|
481
|
+
}),
|
|
482
|
+
...visible.map((option) =>
|
|
483
|
+
h(ui.Checkbox, {
|
|
484
|
+
key: choiceKey(option.value),
|
|
485
|
+
label: option.label,
|
|
486
|
+
disabled: props.disabled || option.disabled,
|
|
487
|
+
modelValue: checked.value.includes(option.value),
|
|
488
|
+
'onUpdate:modelValue': (value: boolean) => {
|
|
489
|
+
if (props.disabled || option.disabled) return
|
|
490
|
+
checked.value = value
|
|
491
|
+
? [...new Set([...checked.value, option.value])]
|
|
492
|
+
: checked.value.filter((id) => id !== option.value)
|
|
493
|
+
},
|
|
494
|
+
}),
|
|
495
|
+
),
|
|
496
|
+
!visible.length
|
|
497
|
+
? h(ui.Text, { text: props.emptyLabel, tone: 'muted' })
|
|
498
|
+
: null,
|
|
499
|
+
h(ui.Button, {
|
|
500
|
+
text: selected ? props.removeLabel : props.addLabel,
|
|
501
|
+
variant: 'secondary',
|
|
502
|
+
disabled:
|
|
503
|
+
props.disabled ||
|
|
504
|
+
!side(selected).some(
|
|
505
|
+
(option) =>
|
|
506
|
+
!option.disabled && checked.value.includes(option.value),
|
|
507
|
+
),
|
|
508
|
+
onClick: () => move(selected),
|
|
509
|
+
}),
|
|
510
|
+
],
|
|
511
|
+
},
|
|
512
|
+
),
|
|
513
|
+
},
|
|
514
|
+
)
|
|
515
|
+
}),
|
|
516
|
+
},
|
|
517
|
+
),
|
|
518
|
+
],
|
|
519
|
+
},
|
|
520
|
+
)
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
})
|
|
524
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { PropType } from '@vue/runtime-core'
|
|
2
|
+
import type { ChoiceOption, ChoiceValue } from '../choice.js'
|
|
3
|
+
import type { MarqueeItem, SwipeCard, TourStep } from '../creative-controls.js'
|
|
4
|
+
const label = { type: String, required: true as const }
|
|
5
|
+
const animated = { type: Boolean, default: true }
|
|
6
|
+
export const colorPickerProps = {
|
|
7
|
+
id: String,
|
|
8
|
+
label,
|
|
9
|
+
modelValue: { type: String, default: '#9C5270' },
|
|
10
|
+
disabled: Boolean,
|
|
11
|
+
readonly: Boolean,
|
|
12
|
+
alpha: Boolean,
|
|
13
|
+
animated,
|
|
14
|
+
palette: {
|
|
15
|
+
type: Array as PropType<readonly string[]>,
|
|
16
|
+
default: () => ['#9C5270', '#51847B', '#BF733E', '#6366A4', '#213A32', '#E6C88E'],
|
|
17
|
+
},
|
|
18
|
+
colorLabel: { type: String, default: 'HEX or RGB' },
|
|
19
|
+
hueLabel: { type: String, default: 'Hue' },
|
|
20
|
+
saturationLabel: { type: String, default: 'Saturation' },
|
|
21
|
+
brightnessLabel: { type: String, default: 'Brightness' },
|
|
22
|
+
alphaLabel: { type: String, default: 'Opacity' },
|
|
23
|
+
paletteLabel: { type: String, default: 'Palette' },
|
|
24
|
+
invalidLabel: { type: String, default: 'Enter a valid HEX or RGB color.' },
|
|
25
|
+
}
|
|
26
|
+
export const swipeDeckProps = {
|
|
27
|
+
id: String,
|
|
28
|
+
label,
|
|
29
|
+
items: { type: Array as PropType<readonly SwipeCard[]>, required: true as const },
|
|
30
|
+
modelValue: { type: [String, Number] as PropType<ChoiceValue | null>, default: null },
|
|
31
|
+
disabled: Boolean,
|
|
32
|
+
animated,
|
|
33
|
+
height: { type: Number, default: 340 },
|
|
34
|
+
threshold: { type: Number, default: 90 },
|
|
35
|
+
acceptLabel: { type: String, default: 'Keep' },
|
|
36
|
+
rejectLabel: { type: String, default: 'Pass' },
|
|
37
|
+
undoLabel: { type: String, default: 'Undo' },
|
|
38
|
+
canUndo: Boolean,
|
|
39
|
+
emptyLabel: { type: String, default: 'All caught up.' },
|
|
40
|
+
}
|
|
41
|
+
export const gaugeProps = {
|
|
42
|
+
id: String,
|
|
43
|
+
label,
|
|
44
|
+
value: { type: Number, required: true as const },
|
|
45
|
+
min: { type: Number, default: 0 },
|
|
46
|
+
max: { type: Number, default: 100 },
|
|
47
|
+
size: { type: Number, default: 220 },
|
|
48
|
+
strokeWidth: { type: Number, default: 7 },
|
|
49
|
+
semi: Boolean,
|
|
50
|
+
animated,
|
|
51
|
+
animateNumber: Boolean,
|
|
52
|
+
color: String,
|
|
53
|
+
suffix: { type: String, default: '' },
|
|
54
|
+
formatValue: Function as PropType<(value: number) => string>,
|
|
55
|
+
}
|
|
56
|
+
export const transferListProps = {
|
|
57
|
+
id: String,
|
|
58
|
+
label,
|
|
59
|
+
options: { type: Array as PropType<readonly ChoiceOption[]>, required: true as const },
|
|
60
|
+
modelValue: { type: Array as PropType<readonly ChoiceValue[]>, default: () => [] },
|
|
61
|
+
disabled: Boolean,
|
|
62
|
+
animated,
|
|
63
|
+
availableLabel: { type: String, default: 'Available' },
|
|
64
|
+
selectedLabel: { type: String, default: 'Selected' },
|
|
65
|
+
searchLabel: { type: String, default: 'Filter' },
|
|
66
|
+
addLabel: { type: String, default: 'Add selected' },
|
|
67
|
+
removeLabel: { type: String, default: 'Remove selected' },
|
|
68
|
+
emptyLabel: { type: String, default: 'No matches' },
|
|
69
|
+
}
|
|
70
|
+
export const tourProps = {
|
|
71
|
+
id: String,
|
|
72
|
+
label,
|
|
73
|
+
steps: { type: Array as PropType<readonly TourStep[]>, required: true as const },
|
|
74
|
+
modelValue: { type: String as PropType<string | null>, default: null },
|
|
75
|
+
animated,
|
|
76
|
+
nextLabel: { type: String, default: 'Next' },
|
|
77
|
+
backLabel: { type: String, default: 'Back' },
|
|
78
|
+
skipLabel: { type: String, default: 'End tour' },
|
|
79
|
+
finishLabel: { type: String, default: 'Finish' },
|
|
80
|
+
}
|
|
81
|
+
export const tourTargetProps = { name: { type: String, required: true as const } }
|
|
82
|
+
export const marqueeProps = {
|
|
83
|
+
id: String,
|
|
84
|
+
label,
|
|
85
|
+
items: { type: Array as PropType<readonly MarqueeItem[]>, required: true as const },
|
|
86
|
+
autoplay: Boolean,
|
|
87
|
+
paused: Boolean,
|
|
88
|
+
speed: { type: Number, default: 35 },
|
|
89
|
+
direction: { type: String as PropType<'left' | 'right'>, default: 'left' },
|
|
90
|
+
itemWidth: { type: Number, default: 180 },
|
|
91
|
+
gap: { type: Number, default: 16 },
|
|
92
|
+
playLabel: { type: String, default: 'Play motion' },
|
|
93
|
+
pauseLabel: { type: String, default: 'Pause motion' },
|
|
94
|
+
}
|