@getcortexlabs/mavis-web 0.1.0-alpha.5 → 0.1.0-alpha.6
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/MAccordion.d.ts +1 -1
- package/dist/components/MAlert.d.ts +1 -1
- package/dist/components/MAvatar.d.ts +1 -1
- package/dist/components/MButton.d.ts +55 -9
- package/dist/components/MButton.d.ts.map +1 -1
- package/dist/components/MButton.js +13 -8
- package/dist/components/MButton.js.map +1 -1
- package/dist/components/MCard.d.ts +49 -3
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +36 -30
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MCheckbox.d.ts +1 -1
- package/dist/components/MCheckbox.js +3 -3
- package/dist/components/MCheckbox.js.map +1 -1
- package/dist/components/MChip.d.ts +2 -2
- package/dist/components/MCombobox.d.ts +2 -2
- package/dist/components/MCombobox.js +3 -3
- package/dist/components/MCombobox.js.map +1 -1
- package/dist/components/MDatePicker.d.ts +56 -8
- package/dist/components/MDatePicker.d.ts.map +1 -1
- package/dist/components/MDatePicker.js +9 -0
- package/dist/components/MDatePicker.js.map +1 -1
- package/dist/components/MDialog.d.ts +1 -1
- package/dist/components/MEmptyState.d.ts +1 -1
- package/dist/components/MInput.d.ts +7 -7
- package/dist/components/MInput.js +3 -3
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MLink.d.ts +120 -0
- package/dist/components/MLink.d.ts.map +1 -0
- package/dist/components/MLink.js +75 -0
- package/dist/components/MLink.js.map +1 -0
- package/dist/components/MListItem.d.ts +3 -1
- package/dist/components/MListItem.d.ts.map +1 -1
- package/dist/components/MProgress.d.ts +1 -1
- package/dist/components/MRadioGroup.d.ts +1 -1
- package/dist/components/MReveal.d.ts +2 -2
- package/dist/components/MReveal.d.ts.map +1 -1
- package/dist/components/MReveal.js +39 -50
- package/dist/components/MReveal.js.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +1 -1
- package/dist/components/MSelect.d.ts +1 -1
- package/dist/components/MSheet.d.ts +1 -1
- package/dist/components/MSlider.d.ts +1 -1
- package/dist/components/MStack.d.ts +198 -0
- package/dist/components/MStack.d.ts.map +1 -0
- package/dist/components/MStack.js +62 -0
- package/dist/components/MStack.js.map +1 -0
- package/dist/components/MSwitch.d.ts +1 -1
- package/dist/components/MSwitch.js +3 -3
- package/dist/components/MSwitch.js.map +1 -1
- package/dist/components/MTabs.d.ts +1 -1
- package/dist/components/MText.d.ts +3 -3
- package/dist/components/MText.js +6 -6
- package/dist/components/MText.js.map +1 -1
- package/dist/components/layout.d.ts +179 -2
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +10 -10
- package/dist/components/layout.js.map +1 -1
- package/dist/connected-motion.d.ts +6 -0
- package/dist/connected-motion.d.ts.map +1 -0
- package/dist/connected-motion.js +18 -0
- package/dist/connected-motion.js.map +1 -0
- package/dist/experimental.d.ts +9 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +27 -0
- package/dist/experimental.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/motion-region.d.ts +3 -0
- package/dist/motion-region.d.ts.map +1 -1
- package/dist/motion-region.js +69 -39
- package/dist/motion-region.js.map +1 -1
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +4 -0
- package/dist/motion-surface.js.map +1 -1
- package/dist/motion.d.ts +2 -2
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +8 -27
- package/dist/motion.js.map +1 -1
- package/dist/navigation.d.ts +12 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +38 -0
- package/dist/navigation.js.map +1 -0
- package/dist/reveal-motion.d.ts +5 -0
- package/dist/reveal-motion.d.ts.map +1 -0
- package/dist/reveal-motion.js +53 -0
- package/dist/reveal-motion.js.map +1 -0
- package/dist/scroll-motion.d.ts.map +1 -1
- package/dist/scroll-motion.js +16 -14
- package/dist/scroll-motion.js.map +1 -1
- package/dist/tokens.d.ts +7 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +29 -0
- package/dist/tokens.js.map +1 -0
- package/package.json +7 -3
- package/src/components/MButton.ts +17 -7
- package/src/components/MCard.ts +45 -27
- package/src/components/MCheckbox.ts +3 -3
- package/src/components/MCombobox.ts +3 -3
- package/src/components/MDatePicker.ts +8 -0
- package/src/components/MInput.ts +3 -3
- package/src/components/MLink.ts +85 -0
- package/src/components/MReveal.ts +57 -64
- package/src/components/MStack.ts +90 -0
- package/src/components/MSwitch.ts +3 -3
- package/src/components/MText.ts +6 -6
- package/src/components/layout.ts +10 -10
- package/src/connected-motion.ts +23 -0
- package/src/experimental.ts +29 -0
- package/src/index.ts +7 -0
- package/src/motion-region.ts +94 -41
- package/src/motion-surface.ts +12 -1
- package/src/motion.ts +10 -40
- package/src/navigation.ts +44 -0
- package/src/reveal-motion.ts +59 -0
- package/src/scroll-motion.ts +16 -15
- package/src/style.css +6 -0
- package/src/tokens.ts +29 -0
package/src/motion-region.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
onActivated,
|
|
3
|
-
onDeactivated,
|
|
4
|
-
onBeforeUnmount,
|
|
5
|
-
provide,
|
|
6
|
-
shallowRef,
|
|
7
|
-
watch,
|
|
8
|
-
type VNode,
|
|
9
|
-
} from 'vue'
|
|
1
|
+
import { onBeforeUnmount, provide, shallowRef, watch, type VNode } from 'vue'
|
|
10
2
|
import {
|
|
11
3
|
bindMotionRegion,
|
|
12
4
|
type MotionRegion,
|
|
@@ -16,6 +8,7 @@ import { createMotionContext, motionContextKey } from './motion-context.js'
|
|
|
16
8
|
import { webSurfaceTarget } from './motion-surface.js'
|
|
17
9
|
import { webScrollElement } from './scroll-motion.js'
|
|
18
10
|
import type { WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
11
|
+
import { useConnectedMotion } from './connected-motion.js'
|
|
19
12
|
|
|
20
13
|
const regions = new WeakMap<MotionRegionAdapter, { target: HTMLElement; runtime: WebRuntime }>()
|
|
21
14
|
export function webRegion(adapter: MotionRegionAdapter) {
|
|
@@ -30,7 +23,67 @@ function regionAdapter(runtime: WebRuntime, target: HTMLElement): MotionRegionAd
|
|
|
30
23
|
throw new TypeError('Declare each surface inside this motion region.')
|
|
31
24
|
return value.target
|
|
32
25
|
}
|
|
26
|
+
const steps = (
|
|
27
|
+
items: readonly (
|
|
28
|
+
| import('@getcortexlabs/mavis-core/experimental').MotionStep<
|
|
29
|
+
import('@getcortexlabs/mavis-core/experimental').MotionSurfaceAdapter
|
|
30
|
+
>
|
|
31
|
+
| import('@getcortexlabs/mavis-core/experimental').MotionTimelineStep<
|
|
32
|
+
import('@getcortexlabs/mavis-core/experimental').MotionSurfaceAdapter
|
|
33
|
+
>
|
|
34
|
+
)[],
|
|
35
|
+
) =>
|
|
36
|
+
items.map((step) =>
|
|
37
|
+
typeof step === 'function' || 'run' in step
|
|
38
|
+
? step
|
|
39
|
+
: ([resolve(step[0]), step[1], step[2]] as const),
|
|
40
|
+
)
|
|
33
41
|
const adapter: MotionRegionAdapter = {
|
|
42
|
+
sequence: (items) =>
|
|
43
|
+
runtime.sequence(steps(items) as unknown as Parameters<WebRuntime['sequence']>[0]),
|
|
44
|
+
timeline: (items) =>
|
|
45
|
+
runtime.timeline(steps(items) as unknown as Parameters<WebRuntime['timeline']>[0]),
|
|
46
|
+
states(targets, definitions, options) {
|
|
47
|
+
const timing = (
|
|
48
|
+
input: import('@getcortexlabs/mavis-core/experimental').MotionStateTransition | undefined,
|
|
49
|
+
) => {
|
|
50
|
+
const { targets, ...transition } = input ?? {}
|
|
51
|
+
return { ...transition, ...targets }
|
|
52
|
+
}
|
|
53
|
+
const control = runtime.motionStates(
|
|
54
|
+
Object.fromEntries(
|
|
55
|
+
Object.entries(targets).map(([name, surface]) => [name, surface && resolve(surface)]),
|
|
56
|
+
),
|
|
57
|
+
Object.fromEntries(
|
|
58
|
+
Object.entries(definitions).map(([name, frames]) => [
|
|
59
|
+
name,
|
|
60
|
+
Object.fromEntries(
|
|
61
|
+
Object.entries(frames).filter(
|
|
62
|
+
(row): row is [string, NonNullable<(typeof row)[1]>] => row[1] !== undefined,
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
]),
|
|
66
|
+
),
|
|
67
|
+
{ transition: timing(options?.transition) },
|
|
68
|
+
)
|
|
69
|
+
return {
|
|
70
|
+
get current() {
|
|
71
|
+
return control.current
|
|
72
|
+
},
|
|
73
|
+
get settled() {
|
|
74
|
+
return control.settled
|
|
75
|
+
},
|
|
76
|
+
get paused() {
|
|
77
|
+
return control.paused
|
|
78
|
+
},
|
|
79
|
+
to: (name, transition) => control.to(name, timing(transition)),
|
|
80
|
+
attach: (name, surface) => control.attach(name, surface && resolve(surface)),
|
|
81
|
+
pause: () => control.pause(),
|
|
82
|
+
play: () => control.play(),
|
|
83
|
+
stop: () => control.stop(),
|
|
84
|
+
dispose: () => control.dispose(),
|
|
85
|
+
}
|
|
86
|
+
},
|
|
34
87
|
kind: 'web',
|
|
35
88
|
viewportEnter(surfaces, options) {
|
|
36
89
|
const control = runtime.viewportEnter(surfaces.map(resolve), {
|
|
@@ -89,48 +142,48 @@ function regionAdapter(runtime: WebRuntime, target: HTMLElement): MotionRegionAd
|
|
|
89
142
|
/** The MBox is the stable input/layout region, separate from every animated child. */
|
|
90
143
|
export function useMotionRegion(reference: () => MotionRegion | undefined) {
|
|
91
144
|
const declared = Boolean(reference())
|
|
145
|
+
if (!declared) {
|
|
146
|
+
watch(reference, (region) => {
|
|
147
|
+
if (region)
|
|
148
|
+
throw new Error('Declare motionRegion when mounting MBox; remount to add a region.')
|
|
149
|
+
})
|
|
150
|
+
return {}
|
|
151
|
+
}
|
|
92
152
|
const context = createMotionContext()
|
|
93
|
-
|
|
153
|
+
provide(motionContextKey, context)
|
|
94
154
|
const element = shallowRef<HTMLElement>()
|
|
95
|
-
let
|
|
96
|
-
release: (() => void) | undefined
|
|
155
|
+
let release: (() => void) | undefined
|
|
97
156
|
const clear = () => {
|
|
98
157
|
release?.()
|
|
99
158
|
release = undefined
|
|
100
159
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const lease = context.acquire(target.ownerDocument)
|
|
109
|
-
const adapter = regionAdapter(lease.runtime, target)
|
|
110
|
-
try {
|
|
111
|
-
const unbind = bindMotionRegion(region, adapter)
|
|
112
|
-
release = () => {
|
|
160
|
+
useConnectedMotion(element, context, (runtime, target) => {
|
|
161
|
+
const stop = watch(
|
|
162
|
+
reference,
|
|
163
|
+
(region) => {
|
|
164
|
+
clear()
|
|
165
|
+
if (!region) return
|
|
166
|
+
const adapter = regionAdapter(runtime, target)
|
|
113
167
|
try {
|
|
114
|
-
unbind()
|
|
115
|
-
|
|
168
|
+
const unbind = bindMotionRegion(region, adapter)
|
|
169
|
+
release = () => {
|
|
170
|
+
try {
|
|
171
|
+
unbind()
|
|
172
|
+
} finally {
|
|
173
|
+
regions.delete(adapter)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
} catch (error) {
|
|
116
177
|
regions.delete(adapter)
|
|
117
|
-
|
|
178
|
+
throw error
|
|
118
179
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
180
|
+
},
|
|
181
|
+
{ immediate: true, flush: 'post' },
|
|
182
|
+
)
|
|
183
|
+
return () => {
|
|
184
|
+
stop()
|
|
185
|
+
clear()
|
|
124
186
|
}
|
|
125
|
-
}
|
|
126
|
-
watch([element, reference], attach, { flush: 'post' })
|
|
127
|
-
onActivated(() => {
|
|
128
|
-
active = true
|
|
129
|
-
attach()
|
|
130
|
-
})
|
|
131
|
-
onDeactivated(() => {
|
|
132
|
-
active = false
|
|
133
|
-
clear()
|
|
134
187
|
})
|
|
135
188
|
onBeforeUnmount(clear)
|
|
136
189
|
return {
|
package/src/motion-surface.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { webScrollElement } from './scroll-motion.js'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
WebReadableValue,
|
|
4
|
+
WebRuntime,
|
|
5
|
+
WebMotionScope,
|
|
6
|
+
WebMotionValue,
|
|
7
|
+
} from '@rafaelaugusto/jolt/web'
|
|
3
8
|
import type { MotionSurfaceAdapter } from '@getcortexlabs/mavis-core/experimental'
|
|
4
9
|
import { webRegion } from './motion-region.js'
|
|
5
10
|
|
|
@@ -96,6 +101,12 @@ export function webMotionSurface(
|
|
|
96
101
|
return wrapper
|
|
97
102
|
},
|
|
98
103
|
|
|
104
|
+
animateValue: (value, frames, options) =>
|
|
105
|
+
owner.animate(value as WebMotionValue, frames, options),
|
|
106
|
+
stopValue: (value, options) => runtime.stop(value as WebMotionValue, options),
|
|
107
|
+
playbackProgress: (handle) =>
|
|
108
|
+
owner.playbackProgress(handle as Parameters<WebRuntime['playbackProgress']>[0]),
|
|
109
|
+
decay: (velocity, options) => owner.decay(target, velocity, options),
|
|
99
110
|
animate: (values, options) => owner.animate(target, values, options),
|
|
100
111
|
set: (values) => owner.set(target, values),
|
|
101
112
|
motionValue: (initial) => owner.motionValue(initial),
|
package/src/motion.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
onActivated,
|
|
3
|
-
onDeactivated,
|
|
4
|
-
onBeforeUnmount,
|
|
5
|
-
shallowRef,
|
|
6
|
-
watch,
|
|
7
|
-
type Ref,
|
|
8
|
-
type VNode,
|
|
9
|
-
} from 'vue'
|
|
1
|
+
import { onBeforeUnmount, shallowRef, watch, type Ref, type VNode } from 'vue'
|
|
10
2
|
import type { WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
11
|
-
import { pressMotion, type MavisTheme } from '@getcortexlabs/mavis-core'
|
|
3
|
+
import { pressMotion, type MotionTheme, type MavisTheme } from '@getcortexlabs/mavis-core'
|
|
12
4
|
import { bindMotionSurface, type MotionSurface } from '@getcortexlabs/mavis-core/experimental'
|
|
13
5
|
import { webMotionSurface } from './motion-surface.js'
|
|
14
6
|
import { useMotionContext } from './motion-context.js'
|
|
7
|
+
import { useConnectedMotion } from './connected-motion.js'
|
|
15
8
|
|
|
16
9
|
// Chip keeps its separate CSS feedback until its interaction contract is migrated.
|
|
17
10
|
export function pressStyle(scale: number) {
|
|
@@ -23,7 +16,7 @@ export function attachWebPress(
|
|
|
23
16
|
target: HTMLElement,
|
|
24
17
|
runtime: WebRuntime,
|
|
25
18
|
enabled: () => boolean,
|
|
26
|
-
scale: () => number
|
|
19
|
+
scale: () => number | Readonly<MotionTheme>,
|
|
27
20
|
applicationSurface: () => boolean = () => false,
|
|
28
21
|
) {
|
|
29
22
|
const window = target.ownerDocument.defaultView!
|
|
@@ -205,7 +198,6 @@ export function usePressFeedback(
|
|
|
205
198
|
) {
|
|
206
199
|
const element = shallowRef<HTMLElement | null>(null)
|
|
207
200
|
const context = useMotionContext()
|
|
208
|
-
let lease: ReturnType<typeof context.acquire> | undefined
|
|
209
201
|
let attached: HTMLElement | undefined
|
|
210
202
|
let runtime: WebRuntime | undefined
|
|
211
203
|
let feedback: ReturnType<typeof attachWebPress> | undefined
|
|
@@ -215,13 +207,11 @@ export function usePressFeedback(
|
|
|
215
207
|
const cleanup = unbind,
|
|
216
208
|
press = feedback,
|
|
217
209
|
host = runtime,
|
|
218
|
-
target = attached
|
|
219
|
-
ownership = lease
|
|
210
|
+
target = attached
|
|
220
211
|
unbind = undefined
|
|
221
212
|
application = undefined
|
|
222
213
|
feedback = undefined
|
|
223
214
|
attached = undefined
|
|
224
|
-
lease = undefined
|
|
225
215
|
runtime = undefined
|
|
226
216
|
const errors: unknown[] = []
|
|
227
217
|
for (const dispose of [
|
|
@@ -230,7 +220,6 @@ export function usePressFeedback(
|
|
|
230
220
|
() => {
|
|
231
221
|
if (target) host?.release(target)
|
|
232
222
|
},
|
|
233
|
-
() => ownership?.release(),
|
|
234
223
|
]) {
|
|
235
224
|
try {
|
|
236
225
|
dispose?.()
|
|
@@ -256,18 +245,15 @@ export function usePressFeedback(
|
|
|
256
245
|
}
|
|
257
246
|
}
|
|
258
247
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (!target || runtime) return
|
|
262
|
-
lease = context.acquire(target.ownerDocument)
|
|
263
|
-
runtime = lease.runtime
|
|
248
|
+
useConnectedMotion(element, context, (host, target) => {
|
|
249
|
+
runtime = host
|
|
264
250
|
attached = target
|
|
265
251
|
try {
|
|
266
252
|
feedback = attachWebPress(
|
|
267
253
|
target,
|
|
268
254
|
runtime,
|
|
269
255
|
enabled,
|
|
270
|
-
() => theme.value.motion
|
|
256
|
+
() => theme.value.motion,
|
|
271
257
|
() => Boolean(surface?.()),
|
|
272
258
|
)
|
|
273
259
|
bind()
|
|
@@ -275,25 +261,9 @@ export function usePressFeedback(
|
|
|
275
261
|
release()
|
|
276
262
|
throw error
|
|
277
263
|
}
|
|
278
|
-
|
|
279
|
-
let active = true
|
|
280
|
-
watch(
|
|
281
|
-
element,
|
|
282
|
-
() => {
|
|
283
|
-
release()
|
|
284
|
-
if (active) attach()
|
|
285
|
-
},
|
|
286
|
-
{ flush: 'post' },
|
|
287
|
-
)
|
|
288
|
-
onActivated(() => {
|
|
289
|
-
active = true
|
|
290
|
-
attach()
|
|
291
|
-
})
|
|
292
|
-
onDeactivated(() => {
|
|
293
|
-
active = false
|
|
294
|
-
release()
|
|
264
|
+
return release
|
|
295
265
|
})
|
|
296
|
-
watch([enabled, () => theme.value.motion
|
|
266
|
+
watch([enabled, () => theme.value.motion], () => feedback?.refresh(), {
|
|
297
267
|
flush: 'pre',
|
|
298
268
|
})
|
|
299
269
|
watch(() => surface?.(), bind, { flush: 'post' })
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { linkDestination, linkRel } from '@getcortexlabs/mavis-core'
|
|
2
|
+
import type { NavigationOptions } from '@getcortexlabs/mavis-core'
|
|
3
|
+
|
|
4
|
+
/** One real anchor; the application can supply a RouterLink custom-slot navigate callback. */
|
|
5
|
+
export function navigationAttrs(
|
|
6
|
+
options: NavigationOptions,
|
|
7
|
+
disabled: boolean,
|
|
8
|
+
activate: () => void,
|
|
9
|
+
fail: (error: unknown) => void,
|
|
10
|
+
) {
|
|
11
|
+
const href = linkDestination(options.href!)
|
|
12
|
+
return {
|
|
13
|
+
href: disabled ? undefined : href,
|
|
14
|
+
role: 'link',
|
|
15
|
+
target: options.target,
|
|
16
|
+
rel: linkRel(options.target ?? '_self', options.rel),
|
|
17
|
+
tabindex: disabled ? -1 : undefined,
|
|
18
|
+
'aria-disabled': disabled || undefined,
|
|
19
|
+
onClick(event: MouseEvent) {
|
|
20
|
+
if (disabled) {
|
|
21
|
+
event.preventDefault()
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
if (event.defaultPrevented) return
|
|
25
|
+
activate()
|
|
26
|
+
if (
|
|
27
|
+
!options.navigate ||
|
|
28
|
+
(options.target && options.target !== '_self') ||
|
|
29
|
+
event.button !== 0 ||
|
|
30
|
+
event.metaKey ||
|
|
31
|
+
event.ctrlKey ||
|
|
32
|
+
event.shiftKey ||
|
|
33
|
+
event.altKey
|
|
34
|
+
)
|
|
35
|
+
return
|
|
36
|
+
event.preventDefault()
|
|
37
|
+
try {
|
|
38
|
+
Promise.resolve(options.navigate(href)).catch(fail)
|
|
39
|
+
} catch (error) {
|
|
40
|
+
fail(error)
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { motionRecipe, type MavisTheme } from '@getcortexlabs/mavis-core'
|
|
2
|
+
import type { RevealHost } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import type { WebMotionContext } from './motion-context.js'
|
|
4
|
+
|
|
5
|
+
export function revealHost(
|
|
6
|
+
element: HTMLElement,
|
|
7
|
+
context: WebMotionContext,
|
|
8
|
+
theme: () => MavisTheme,
|
|
9
|
+
hidden: () => boolean,
|
|
10
|
+
): RevealHost {
|
|
11
|
+
let trigger: HTMLElement | undefined
|
|
12
|
+
// Initial SSR/KeepAlive presentation needs no animation or geometry acquisition.
|
|
13
|
+
let lease: ReturnType<typeof context.acquire> | undefined
|
|
14
|
+
const originalHeight = element.style.height
|
|
15
|
+
return {
|
|
16
|
+
animate(open, fromClosed) {
|
|
17
|
+
if (!element.isConnected) return { finished: Promise.resolve(true), stop() {} }
|
|
18
|
+
lease ??= context.acquire(element.ownerDocument)
|
|
19
|
+
const runtime = lease.runtime
|
|
20
|
+
if (fromClosed) {
|
|
21
|
+
element.style.height = '0px'
|
|
22
|
+
runtime.set(element, { opacity: 0 })
|
|
23
|
+
}
|
|
24
|
+
const recipe = motionRecipe(theme(), open ? 'enter' : 'exit')
|
|
25
|
+
const size = runtime.animateSize(element, { height: open ? 'auto' : 0 }, recipe.transition)
|
|
26
|
+
const opacity = runtime.animate(element, { opacity: open ? 1 : 0 }, recipe.transition)
|
|
27
|
+
return {
|
|
28
|
+
finished: size.finished,
|
|
29
|
+
stop() {
|
|
30
|
+
size.stop({ restore: true })
|
|
31
|
+
opacity.stop()
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
interactive(enabled) {
|
|
36
|
+
element.toggleAttribute('inert', !enabled || Boolean(hidden()))
|
|
37
|
+
if (!enabled || hidden()) element.setAttribute('aria-hidden', 'true')
|
|
38
|
+
else element.removeAttribute('aria-hidden')
|
|
39
|
+
},
|
|
40
|
+
captureFocus() {
|
|
41
|
+
const active = element.ownerDocument.activeElement
|
|
42
|
+
if (
|
|
43
|
+
active instanceof element.ownerDocument.defaultView!.HTMLElement &&
|
|
44
|
+
!element.contains(active)
|
|
45
|
+
)
|
|
46
|
+
trigger = active
|
|
47
|
+
},
|
|
48
|
+
restoreFocus() {
|
|
49
|
+
if (element.contains(element.ownerDocument.activeElement) && trigger?.isConnected)
|
|
50
|
+
trigger.focus({ preventScroll: true })
|
|
51
|
+
},
|
|
52
|
+
release() {
|
|
53
|
+
lease?.runtime.release(element)
|
|
54
|
+
lease?.release()
|
|
55
|
+
lease = undefined
|
|
56
|
+
element.style.height = originalHeight
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/scroll-motion.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { computed, watch, type Ref } from 'vue'
|
|
2
|
+
import { useConnectedMotion } from './connected-motion.js'
|
|
3
|
+
import { useMotionContext } from './motion-context.js'
|
|
2
4
|
import {
|
|
3
5
|
bindMotionScrollSource,
|
|
4
6
|
type MotionScrollAdapter,
|
|
@@ -17,17 +19,15 @@ export function useScrollMotion(
|
|
|
17
19
|
source: () => MotionScrollSource | undefined,
|
|
18
20
|
enabled: () => boolean,
|
|
19
21
|
) {
|
|
20
|
-
let active = true
|
|
21
22
|
let release: (() => void) | undefined
|
|
22
23
|
const clear = () => {
|
|
23
24
|
release?.()
|
|
24
25
|
release = undefined
|
|
25
26
|
}
|
|
26
|
-
const attach = () => {
|
|
27
|
+
const attach = (target: HTMLElement) => {
|
|
27
28
|
clear()
|
|
28
|
-
const reference = source()
|
|
29
|
-
|
|
30
|
-
if (!active || !enabled() || !reference || !target) return
|
|
29
|
+
const reference = source()
|
|
30
|
+
if (!enabled() || !reference) return
|
|
31
31
|
const adapter: MotionScrollAdapter = { kind: 'web' }
|
|
32
32
|
sources.set(adapter, target)
|
|
33
33
|
const unbind = bindMotionScrollSource(reference, adapter)
|
|
@@ -62,14 +62,15 @@ export function useScrollMotion(
|
|
|
62
62
|
sources.delete(adapter)
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
const target = computed(() => (enabled() && source() ? element.value : undefined))
|
|
66
|
+
useConnectedMotion(target, useMotionContext(), (_, connected) => {
|
|
67
|
+
const stop = watch([source, enabled], () => attach(connected), {
|
|
68
|
+
immediate: true,
|
|
69
|
+
flush: 'post',
|
|
70
|
+
})
|
|
71
|
+
return () => {
|
|
72
|
+
stop()
|
|
73
|
+
clear()
|
|
74
|
+
}
|
|
73
75
|
})
|
|
74
|
-
onBeforeUnmount(clear)
|
|
75
76
|
}
|
package/src/style.css
CHANGED
package/src/tokens.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { computed, type CSSProperties } from 'vue'
|
|
2
|
+
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { fontFamily, shadowStyle, type MavisTheme } from '@getcortexlabs/mavis-core'
|
|
4
|
+
|
|
5
|
+
/** CSS values for one theme scope. No document mutation or application singleton. */
|
|
6
|
+
export function themeVariables(theme: MavisTheme): CSSProperties {
|
|
7
|
+
const variables: Record<string, string | number> = {}
|
|
8
|
+
for (const [name, value] of Object.entries(theme.colors)) variables[`--m-color-${name}`] = value
|
|
9
|
+
for (const [name, value] of Object.entries(theme.space))
|
|
10
|
+
variables[`--m-space-${name}`] = `${value}px`
|
|
11
|
+
for (const [name, value] of Object.entries(theme.radius))
|
|
12
|
+
variables[`--m-radius-${name}`] = `${value}px`
|
|
13
|
+
for (const [name, value] of Object.entries(theme.elevation))
|
|
14
|
+
variables[`--m-elevation-${name}`] = shadowStyle(value)
|
|
15
|
+
for (const [name, type] of Object.entries(theme.typography)) {
|
|
16
|
+
variables[`--m-type-${name}-font-family`] = fontFamily(type.fontFamily, 'web')
|
|
17
|
+
variables[`--m-type-${name}-font-size`] = `${type.fontSize}px`
|
|
18
|
+
variables[`--m-type-${name}-font-weight`] = type.fontWeight
|
|
19
|
+
variables[`--m-type-${name}-line-height`] = type.lineHeight
|
|
20
|
+
variables[`--m-type-${name}-letter-spacing`] = `${type.letterSpacing}em`
|
|
21
|
+
}
|
|
22
|
+
return variables as CSSProperties
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Bind to a host's :style inside the desired MThemeProvider scope. Also works during SSR. */
|
|
26
|
+
export function useMavisTokens() {
|
|
27
|
+
const { theme } = useMavisTheme()
|
|
28
|
+
return computed(() => themeVariables(theme.value))
|
|
29
|
+
}
|