@getcortexlabs/mavis-web 0.1.0-alpha.4 → 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 +5 -3
- package/dist/components/DateCalendar.d.ts +95 -0
- package/dist/components/DateCalendar.d.ts.map +1 -0
- package/dist/components/DateCalendar.js +157 -0
- package/dist/components/DateCalendar.js.map +1 -0
- package/dist/components/MAccordion.d.ts +19 -9
- package/dist/components/MAccordion.d.ts.map +1 -1
- package/dist/components/MAlert.d.ts +20 -10
- package/dist/components/MAlert.d.ts.map +1 -1
- package/dist/components/MAvatar.d.ts +13 -7
- package/dist/components/MAvatar.d.ts.map +1 -1
- package/dist/components/MBadge.d.ts +12 -6
- package/dist/components/MBadge.d.ts.map +1 -1
- package/dist/components/MButton.d.ts +129 -41
- 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 +89 -15
- 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 +20 -10
- package/dist/components/MCheckbox.d.ts.map +1 -1
- package/dist/components/MCheckbox.js +22 -3
- package/dist/components/MCheckbox.js.map +1 -1
- package/dist/components/MChip.d.ts +22 -12
- package/dist/components/MChip.d.ts.map +1 -1
- package/dist/components/MCombobox.d.ts +282 -0
- package/dist/components/MCombobox.d.ts.map +1 -0
- package/dist/components/MCombobox.js +440 -0
- package/dist/components/MCombobox.js.map +1 -0
- package/dist/components/MDatePicker.d.ts +1302 -0
- package/dist/components/MDatePicker.d.ts.map +1 -0
- package/dist/components/MDatePicker.js +31 -0
- package/dist/components/MDatePicker.js.map +1 -0
- package/dist/components/MDialog.d.ts +7 -5
- package/dist/components/MDialog.d.ts.map +1 -1
- package/dist/components/MEmptyState.d.ts +19 -9
- package/dist/components/MEmptyState.d.ts.map +1 -1
- package/dist/components/MFilePicker.d.ts +112 -0
- package/dist/components/MFilePicker.d.ts.map +1 -0
- package/dist/components/MFilePicker.js +193 -0
- package/dist/components/MFilePicker.js.map +1 -0
- package/dist/components/MIcon.d.ts +4 -2
- package/dist/components/MIcon.d.ts.map +1 -1
- package/dist/components/MInput.d.ts +135 -63
- package/dist/components/MInput.d.ts.map +1 -1
- package/dist/components/MInput.js +20 -4
- 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 +26 -12
- package/dist/components/MListItem.d.ts.map +1 -1
- package/dist/components/MProgress.d.ts +18 -8
- package/dist/components/MProgress.d.ts.map +1 -1
- package/dist/components/MRadioGroup.d.ts +19 -9
- package/dist/components/MRadioGroup.d.ts.map +1 -1
- package/dist/components/MRadioGroup.js +22 -0
- package/dist/components/MRadioGroup.js.map +1 -1
- package/dist/components/MReveal.d.ts +71 -35
- 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/MScreen.d.ts +12 -6
- package/dist/components/MScreen.d.ts.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +19 -9
- package/dist/components/MSegmentedControl.d.ts.map +1 -1
- package/dist/components/MSelect.d.ts +21 -11
- package/dist/components/MSelect.d.ts.map +1 -1
- package/dist/components/MSeparator.d.ts +4 -2
- package/dist/components/MSeparator.d.ts.map +1 -1
- package/dist/components/MSheet.d.ts +18 -12
- package/dist/components/MSheet.d.ts.map +1 -1
- package/dist/components/MSheet.js +1 -1
- package/dist/components/MSheet.js.map +1 -1
- package/dist/components/MSkeleton.d.ts +16 -8
- package/dist/components/MSkeleton.d.ts.map +1 -1
- package/dist/components/MSlider.d.ts +10 -6
- package/dist/components/MSlider.d.ts.map +1 -1
- package/dist/components/MSlider.js +12 -1
- package/dist/components/MSlider.js.map +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 +19 -9
- package/dist/components/MSwitch.d.ts.map +1 -1
- package/dist/components/MSwitch.js +3 -3
- package/dist/components/MSwitch.js.map +1 -1
- package/dist/components/MTabs.d.ts +19 -9
- package/dist/components/MTabs.d.ts.map +1 -1
- package/dist/components/MText.d.ts +44 -28
- package/dist/components/MText.d.ts.map +1 -1
- package/dist/components/MText.js +6 -6
- package/dist/components/MText.js.map +1 -1
- package/dist/components/layout.d.ts +367 -81
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +14 -12
- package/dist/components/layout.js.map +1 -1
- package/dist/components/workflows.d.ts +251 -0
- package/dist/components/workflows.d.ts.map +1 -0
- package/dist/components/workflows.js +23 -0
- package/dist/components/workflows.js.map +1 -0
- 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/files.d.ts +6 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +82 -0
- package/dist/files.js.map +1 -0
- package/dist/hydration.d.ts +3 -0
- package/dist/hydration.d.ts.map +1 -0
- package/dist/hydration.js +20 -0
- package/dist/hydration.js.map +1 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -2
- package/dist/index.js.map +1 -1
- package/dist/motion-context.d.ts +13 -0
- package/dist/motion-context.d.ts.map +1 -0
- package/dist/motion-context.js +33 -0
- package/dist/motion-context.js.map +1 -0
- package/dist/motion-region.d.ts +16 -0
- package/dist/motion-region.d.ts.map +1 -0
- package/dist/motion-region.js +164 -0
- package/dist/motion-region.js.map +1 -0
- package/dist/motion-surface.d.ts +6 -2
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +71 -11
- package/dist/motion-surface.js.map +1 -1
- package/dist/motion.d.ts +3 -3
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +47 -30
- 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/screen-viewport.d.ts.map +1 -1
- package/dist/screen-viewport.js +5 -0
- package/dist/screen-viewport.js.map +1 -1
- 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/sheet-motion.d.ts.map +1 -1
- package/dist/sheet-motion.js +96 -62
- package/dist/sheet-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/DateCalendar.ts +213 -0
- package/src/components/MButton.ts +17 -7
- package/src/components/MCard.ts +45 -27
- package/src/components/MCheckbox.ts +25 -3
- package/src/components/MCombobox.ts +510 -0
- package/src/components/MDatePicker.ts +31 -0
- package/src/components/MFilePicker.ts +233 -0
- package/src/components/MInput.ts +24 -4
- package/src/components/MLink.ts +85 -0
- package/src/components/MRadioGroup.ts +26 -0
- package/src/components/MReveal.ts +57 -64
- package/src/components/MSheet.ts +1 -1
- package/src/components/MSlider.ts +18 -1
- 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 +15 -12
- package/src/components/workflows.ts +27 -0
- package/src/connected-motion.ts +23 -0
- package/src/experimental.ts +29 -0
- package/src/files.ts +77 -0
- package/src/hydration.ts +21 -0
- package/src/index.ts +36 -1
- package/src/motion-context.ts +35 -0
- package/src/motion-region.ts +198 -0
- package/src/motion-surface.ts +87 -12
- package/src/motion.ts +53 -47
- package/src/navigation.ts +44 -0
- package/src/reveal-motion.ts +59 -0
- package/src/screen-viewport.ts +4 -0
- package/src/scroll-motion.ts +16 -15
- package/src/sheet-motion.ts +86 -57
- package/src/style.css +6 -0
- package/src/tokens.ts +29 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { onBeforeUnmount, provide, shallowRef, watch, type VNode } from 'vue'
|
|
2
|
+
import {
|
|
3
|
+
bindMotionRegion,
|
|
4
|
+
type MotionRegion,
|
|
5
|
+
type MotionRegionAdapter,
|
|
6
|
+
} from '@getcortexlabs/mavis-core/experimental'
|
|
7
|
+
import { createMotionContext, motionContextKey } from './motion-context.js'
|
|
8
|
+
import { webSurfaceTarget } from './motion-surface.js'
|
|
9
|
+
import { webScrollElement } from './scroll-motion.js'
|
|
10
|
+
import type { WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
11
|
+
import { useConnectedMotion } from './connected-motion.js'
|
|
12
|
+
|
|
13
|
+
const regions = new WeakMap<MotionRegionAdapter, { target: HTMLElement; runtime: WebRuntime }>()
|
|
14
|
+
export function webRegion(adapter: MotionRegionAdapter) {
|
|
15
|
+
const region = regions.get(adapter)
|
|
16
|
+
if (!region) throw new TypeError('Use a mounted Web motion region.')
|
|
17
|
+
return region
|
|
18
|
+
}
|
|
19
|
+
function regionAdapter(runtime: WebRuntime, target: HTMLElement): MotionRegionAdapter {
|
|
20
|
+
const resolve = (surface: Parameters<typeof webSurfaceTarget>[0]) => {
|
|
21
|
+
const value = webSurfaceTarget(surface)
|
|
22
|
+
if (value.runtime !== runtime || !target.contains(value.target))
|
|
23
|
+
throw new TypeError('Declare each surface inside this motion region.')
|
|
24
|
+
return value.target
|
|
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
|
+
)
|
|
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
|
+
},
|
|
87
|
+
kind: 'web',
|
|
88
|
+
viewportEnter(surfaces, options) {
|
|
89
|
+
const control = runtime.viewportEnter(surfaces.map(resolve), {
|
|
90
|
+
keyframes: options.frames ?? { opacity: [0, 1], y: [20, 0] },
|
|
91
|
+
transition: { duration: 450, ...options.transition, stagger: options.stagger ?? 70 },
|
|
92
|
+
root: options.root && webScrollElement(options.root),
|
|
93
|
+
rootMargin: `${options.margin ?? 0}px`,
|
|
94
|
+
threshold: options.threshold,
|
|
95
|
+
once: options.once,
|
|
96
|
+
disabled: options.disabled,
|
|
97
|
+
})
|
|
98
|
+
return {
|
|
99
|
+
execution: target.ownerDocument.defaultView!.IntersectionObserver
|
|
100
|
+
? 'intersection-observer'
|
|
101
|
+
: 'static',
|
|
102
|
+
get pending() {
|
|
103
|
+
return control.pending
|
|
104
|
+
},
|
|
105
|
+
get completed() {
|
|
106
|
+
return control.completed
|
|
107
|
+
},
|
|
108
|
+
update: (state) => control.update(state),
|
|
109
|
+
refresh: () => control.refresh(),
|
|
110
|
+
dispose: () => control.dispose(),
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
sharedLayout(options) {
|
|
114
|
+
const control = runtime.sharedLayout(target, options)
|
|
115
|
+
return {
|
|
116
|
+
get active() {
|
|
117
|
+
return control.active
|
|
118
|
+
},
|
|
119
|
+
attach: (surface, identity) => control.attach(resolve(surface), identity),
|
|
120
|
+
transition: (change, options) => control.transition(change, options),
|
|
121
|
+
cancel: () => control.cancel(),
|
|
122
|
+
dispose: () => control.dispose(),
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
diagnostics(options) {
|
|
126
|
+
const control = runtime.diagnostics(options)
|
|
127
|
+
return {
|
|
128
|
+
snapshot: () => ({
|
|
129
|
+
...control.snapshot(),
|
|
130
|
+
identity: options.identity,
|
|
131
|
+
execution: 'jolt-web' as const,
|
|
132
|
+
}),
|
|
133
|
+
clear: () => control.clear(),
|
|
134
|
+
dispose: () => control.dispose(),
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
}
|
|
138
|
+
regions.set(adapter, { target, runtime })
|
|
139
|
+
return adapter
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The MBox is the stable input/layout region, separate from every animated child. */
|
|
143
|
+
export function useMotionRegion(reference: () => MotionRegion | undefined) {
|
|
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
|
+
}
|
|
152
|
+
const context = createMotionContext()
|
|
153
|
+
provide(motionContextKey, context)
|
|
154
|
+
const element = shallowRef<HTMLElement>()
|
|
155
|
+
let release: (() => void) | undefined
|
|
156
|
+
const clear = () => {
|
|
157
|
+
release?.()
|
|
158
|
+
release = undefined
|
|
159
|
+
}
|
|
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)
|
|
167
|
+
try {
|
|
168
|
+
const unbind = bindMotionRegion(region, adapter)
|
|
169
|
+
release = () => {
|
|
170
|
+
try {
|
|
171
|
+
unbind()
|
|
172
|
+
} finally {
|
|
173
|
+
regions.delete(adapter)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
} catch (error) {
|
|
177
|
+
regions.delete(adapter)
|
|
178
|
+
throw error
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
{ immediate: true, flush: 'post' },
|
|
182
|
+
)
|
|
183
|
+
return () => {
|
|
184
|
+
stop()
|
|
185
|
+
clear()
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
onBeforeUnmount(clear)
|
|
189
|
+
return {
|
|
190
|
+
onVnodeMounted: (node: VNode) => {
|
|
191
|
+
element.value = node.el as HTMLElement
|
|
192
|
+
},
|
|
193
|
+
onVnodeBeforeUnmount: () => {
|
|
194
|
+
element.value = undefined
|
|
195
|
+
clear()
|
|
196
|
+
},
|
|
197
|
+
}
|
|
198
|
+
}
|
package/src/motion-surface.ts
CHANGED
|
@@ -1,21 +1,89 @@
|
|
|
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'
|
|
9
|
+
import { webRegion } from './motion-region.js'
|
|
10
|
+
|
|
11
|
+
const targets = new WeakMap<MotionSurfaceAdapter, { runtime: WebRuntime; target: HTMLElement }>()
|
|
12
|
+
export function webSurfaceTarget(adapter: MotionSurfaceAdapter) {
|
|
13
|
+
const target = targets.get(adapter)
|
|
14
|
+
if (!target) throw new TypeError('Use a Web motion surface.')
|
|
15
|
+
return target
|
|
16
|
+
}
|
|
4
17
|
|
|
5
18
|
/** Application motion uses the same Jolt context as this component's press layer. */
|
|
6
|
-
export function webMotionSurface(
|
|
7
|
-
|
|
8
|
-
|
|
19
|
+
export function webMotionSurface(
|
|
20
|
+
runtime: WebRuntime,
|
|
21
|
+
target: HTMLElement,
|
|
22
|
+
enabled: () => boolean,
|
|
23
|
+
owner: WebRuntime | WebMotionScope = runtime,
|
|
24
|
+
sources = new WeakMap<object, WebReadableValue>(),
|
|
25
|
+
refreshes = new Map<object, () => void>(),
|
|
26
|
+
) {
|
|
9
27
|
const adapter: MotionSurfaceAdapter = {
|
|
28
|
+
use(setup) {
|
|
29
|
+
const scope = runtime.scope()
|
|
30
|
+
try {
|
|
31
|
+
scope.use((child) =>
|
|
32
|
+
setup(webMotionSurface(runtime, target, enabled, child, sources, refreshes).adapter),
|
|
33
|
+
)
|
|
34
|
+
} catch (error) {
|
|
35
|
+
scope.dispose()
|
|
36
|
+
throw error
|
|
37
|
+
}
|
|
38
|
+
return () => scope.dispose()
|
|
39
|
+
},
|
|
40
|
+
pointerFollow(region, options) {
|
|
41
|
+
const input = webRegion(region)
|
|
42
|
+
if (input.runtime !== runtime || input.target === target || !input.target.contains(target))
|
|
43
|
+
throw new TypeError('Use a separate enclosing motion region for pointer input.')
|
|
44
|
+
const pointer = owner.pointerFollow(input.target, {
|
|
45
|
+
...options,
|
|
46
|
+
disabled: options.disabled || !enabled(),
|
|
47
|
+
})
|
|
48
|
+
let disabled = options.disabled ?? false
|
|
49
|
+
const refresh = () => pointer.update({ disabled: disabled || !enabled() })
|
|
50
|
+
refreshes.set(pointer, refresh)
|
|
51
|
+
// The pointer owns its values; wrappers are borrowed by Mavis bindings.
|
|
52
|
+
const wrap = (value: WebReadableValue) => {
|
|
53
|
+
const borrowed = { get: () => value.get(), dispose() {} }
|
|
54
|
+
sources.set(borrowed, value)
|
|
55
|
+
return borrowed
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
x: wrap(pointer.x),
|
|
59
|
+
y: wrap(pointer.y),
|
|
60
|
+
execution: 'hover',
|
|
61
|
+
get active() {
|
|
62
|
+
return pointer.active
|
|
63
|
+
},
|
|
64
|
+
update(state) {
|
|
65
|
+
disabled = state.disabled
|
|
66
|
+
refresh()
|
|
67
|
+
},
|
|
68
|
+
refresh: () => pointer.refresh(),
|
|
69
|
+
dispose() {
|
|
70
|
+
refreshes.delete(pointer)
|
|
71
|
+
pointer.dispose()
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
},
|
|
10
75
|
refresh: () => runtime.refresh(target),
|
|
11
76
|
scrollLinked: (source, frames, options) =>
|
|
12
|
-
|
|
77
|
+
owner.scrollLinked(webScrollElement(source), target, frames, options),
|
|
13
78
|
map(source, input, output, options) {
|
|
14
|
-
|
|
79
|
+
const value = sources.get(source) ?? (source as WebReadableValue)
|
|
80
|
+
return 'map' in owner
|
|
81
|
+
? owner.map(value, input, output, options)
|
|
82
|
+
: value.to(input, output, options)
|
|
15
83
|
},
|
|
16
84
|
springValue(source, options) {
|
|
17
85
|
// Keep the runtime's private value identity; it rejects values from other contexts.
|
|
18
|
-
const spring =
|
|
86
|
+
const spring = owner.springValue(source as ReturnType<WebRuntime['motionValue']>, options)
|
|
19
87
|
const wrapper = {
|
|
20
88
|
get: () => spring.get(),
|
|
21
89
|
getVelocity: () => spring.getVelocity(),
|
|
@@ -33,12 +101,18 @@ export function webMotionSurface(runtime: WebRuntime, target: HTMLElement, enabl
|
|
|
33
101
|
return wrapper
|
|
34
102
|
},
|
|
35
103
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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),
|
|
110
|
+
animate: (values, options) => owner.animate(target, values, options),
|
|
111
|
+
set: (values) => owner.set(target, values),
|
|
112
|
+
motionValue: (initial) => owner.motionValue(initial),
|
|
39
113
|
bind(values) {
|
|
40
114
|
// Spring wrappers retain their public handle, rather than registering a second clock.
|
|
41
|
-
return
|
|
115
|
+
return owner.bind(
|
|
42
116
|
target,
|
|
43
117
|
Object.fromEntries(
|
|
44
118
|
Object.entries(values).map(([key, value]) => [key, sources.get(value) ?? value]),
|
|
@@ -46,7 +120,7 @@ export function webMotionSurface(runtime: WebRuntime, target: HTMLElement, enabl
|
|
|
46
120
|
)
|
|
47
121
|
},
|
|
48
122
|
drag(options) {
|
|
49
|
-
const drag =
|
|
123
|
+
const drag = owner.drag(target, { ...options, disabled: !enabled() })
|
|
50
124
|
let paused = false
|
|
51
125
|
const refresh = () => {
|
|
52
126
|
const disabled = paused || !enabled()
|
|
@@ -77,6 +151,7 @@ export function webMotionSurface(runtime: WebRuntime, target: HTMLElement, enabl
|
|
|
77
151
|
}
|
|
78
152
|
},
|
|
79
153
|
}
|
|
154
|
+
targets.set(adapter, { runtime, target })
|
|
80
155
|
return {
|
|
81
156
|
adapter,
|
|
82
157
|
refresh: () => {
|
package/src/motion.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
onBeforeUnmount,
|
|
5
|
-
shallowRef,
|
|
6
|
-
watch,
|
|
7
|
-
type Ref,
|
|
8
|
-
type VNode,
|
|
9
|
-
} from 'vue'
|
|
10
|
-
import { createWebRuntime, type WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
11
|
-
import { pressMotion, type MavisTheme } from '@getcortexlabs/mavis-core'
|
|
1
|
+
import { onBeforeUnmount, shallowRef, watch, type Ref, type VNode } from 'vue'
|
|
2
|
+
import type { WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
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'
|
|
6
|
+
import { useMotionContext } from './motion-context.js'
|
|
7
|
+
import { useConnectedMotion } from './connected-motion.js'
|
|
14
8
|
|
|
15
9
|
// Chip keeps its separate CSS feedback until its interaction contract is migrated.
|
|
16
10
|
export function pressStyle(scale: number) {
|
|
@@ -22,7 +16,7 @@ export function attachWebPress(
|
|
|
22
16
|
target: HTMLElement,
|
|
23
17
|
runtime: WebRuntime,
|
|
24
18
|
enabled: () => boolean,
|
|
25
|
-
scale: () => number
|
|
19
|
+
scale: () => number | Readonly<MotionTheme>,
|
|
26
20
|
applicationSurface: () => boolean = () => false,
|
|
27
21
|
) {
|
|
28
22
|
const window = target.ownerDocument.defaultView!
|
|
@@ -203,18 +197,37 @@ export function usePressFeedback(
|
|
|
203
197
|
motionEnabled: () => boolean = enabled,
|
|
204
198
|
) {
|
|
205
199
|
const element = shallowRef<HTMLElement | null>(null)
|
|
200
|
+
const context = useMotionContext()
|
|
201
|
+
let attached: HTMLElement | undefined
|
|
206
202
|
let runtime: WebRuntime | undefined
|
|
207
203
|
let feedback: ReturnType<typeof attachWebPress> | undefined
|
|
208
204
|
let unbind: (() => void) | undefined
|
|
209
205
|
let application: ReturnType<typeof webMotionSurface> | undefined
|
|
210
206
|
const release = () => {
|
|
211
|
-
unbind
|
|
207
|
+
const cleanup = unbind,
|
|
208
|
+
press = feedback,
|
|
209
|
+
host = runtime,
|
|
210
|
+
target = attached
|
|
212
211
|
unbind = undefined
|
|
213
212
|
application = undefined
|
|
214
|
-
feedback?.dispose()
|
|
215
213
|
feedback = undefined
|
|
216
|
-
|
|
214
|
+
attached = undefined
|
|
217
215
|
runtime = undefined
|
|
216
|
+
const errors: unknown[] = []
|
|
217
|
+
for (const dispose of [
|
|
218
|
+
cleanup,
|
|
219
|
+
() => press?.dispose(),
|
|
220
|
+
() => {
|
|
221
|
+
if (target) host?.release(target)
|
|
222
|
+
},
|
|
223
|
+
]) {
|
|
224
|
+
try {
|
|
225
|
+
dispose?.()
|
|
226
|
+
} catch (error) {
|
|
227
|
+
errors.push(error)
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (errors.length) throw new AggregateError(errors, 'Web motion presentation cleanup failed.')
|
|
218
231
|
}
|
|
219
232
|
const bind = () => {
|
|
220
233
|
unbind?.()
|
|
@@ -222,42 +235,35 @@ export function usePressFeedback(
|
|
|
222
235
|
const target = element.value
|
|
223
236
|
const current = runtime
|
|
224
237
|
if (target && current && surface?.()) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
238
|
+
try {
|
|
239
|
+
feedback?.observeGeometry()
|
|
240
|
+
application = webMotionSurface(current, target, motionEnabled)
|
|
241
|
+
unbind = bindMotionSurface(surface()!, application.adapter)
|
|
242
|
+
} catch (error) {
|
|
243
|
+
release()
|
|
244
|
+
throw error
|
|
245
|
+
}
|
|
228
246
|
}
|
|
229
247
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
let active = true
|
|
244
|
-
watch(
|
|
245
|
-
element,
|
|
246
|
-
() => {
|
|
248
|
+
useConnectedMotion(element, context, (host, target) => {
|
|
249
|
+
runtime = host
|
|
250
|
+
attached = target
|
|
251
|
+
try {
|
|
252
|
+
feedback = attachWebPress(
|
|
253
|
+
target,
|
|
254
|
+
runtime,
|
|
255
|
+
enabled,
|
|
256
|
+
() => theme.value.motion,
|
|
257
|
+
() => Boolean(surface?.()),
|
|
258
|
+
)
|
|
259
|
+
bind()
|
|
260
|
+
} catch (error) {
|
|
247
261
|
release()
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
)
|
|
252
|
-
onActivated(() => {
|
|
253
|
-
active = true
|
|
254
|
-
attach()
|
|
255
|
-
})
|
|
256
|
-
onDeactivated(() => {
|
|
257
|
-
active = false
|
|
258
|
-
release()
|
|
262
|
+
throw error
|
|
263
|
+
}
|
|
264
|
+
return release
|
|
259
265
|
})
|
|
260
|
-
watch([enabled, () => theme.value.motion
|
|
266
|
+
watch([enabled, () => theme.value.motion], () => feedback?.refresh(), {
|
|
261
267
|
flush: 'pre',
|
|
262
268
|
})
|
|
263
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/screen-viewport.ts
CHANGED
|
@@ -25,6 +25,10 @@ export function useScreenViewport(scroll: () => boolean) {
|
|
|
25
25
|
const viewportTop = viewport ? viewport.pageTop - window.scrollY : 0
|
|
26
26
|
const top = Math.max(area.top, viewportTop) + 8
|
|
27
27
|
const bottom = Math.min(area.bottom, viewportTop + (viewport?.height ?? innerHeight)) - 8
|
|
28
|
+
// A focused container can span the whole viewport. Safari focuses a tab
|
|
29
|
+
// panel on mouse-down inside it; moving it to an edge here can move the
|
|
30
|
+
// clicked control away before mouse-up. Its visible portion is sufficient.
|
|
31
|
+
if (bounds.height > bottom - top && bounds.bottom > top && bounds.top < bottom) return
|
|
28
32
|
if (bounds.bottom > bottom) screen.scrollTop += Math.ceil(bounds.bottom - bottom)
|
|
29
33
|
else if (bounds.top < top) screen.scrollTop += Math.floor(bounds.top - top)
|
|
30
34
|
}
|
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
|
}
|