@getcortexlabs/mavis-web 0.1.0-alpha.4 → 0.1.0-alpha.5
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 +18 -8
- package/dist/components/MAccordion.d.ts.map +1 -1
- package/dist/components/MAlert.d.ts +21 -11
- package/dist/components/MAlert.d.ts.map +1 -1
- package/dist/components/MAvatar.d.ts +12 -6
- 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 +83 -41
- package/dist/components/MButton.d.ts.map +1 -1
- package/dist/components/MCard.d.ts +44 -16
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCheckbox.d.ts +19 -9
- package/dist/components/MCheckbox.d.ts.map +1 -1
- package/dist/components/MCheckbox.js +19 -0
- package/dist/components/MCheckbox.js.map +1 -1
- package/dist/components/MChip.d.ts +21 -11
- 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 +1254 -0
- package/dist/components/MDatePicker.d.ts.map +1 -0
- package/dist/components/MDatePicker.js +22 -0
- package/dist/components/MDatePicker.js.map +1 -0
- package/dist/components/MDialog.d.ts +8 -6
- 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 +17 -1
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MListItem.d.ts +23 -11
- package/dist/components/MListItem.d.ts.map +1 -1
- package/dist/components/MProgress.d.ts +19 -9
- package/dist/components/MProgress.d.ts.map +1 -1
- package/dist/components/MRadioGroup.d.ts +18 -8
- 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/MScreen.d.ts +12 -6
- package/dist/components/MScreen.d.ts.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +18 -8
- package/dist/components/MSegmentedControl.d.ts.map +1 -1
- package/dist/components/MSelect.d.ts +20 -10
- 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 +19 -13
- 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 +9 -5
- 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/MSwitch.d.ts +18 -8
- package/dist/components/MSwitch.d.ts.map +1 -1
- package/dist/components/MTabs.d.ts +18 -8
- package/dist/components/MTabs.d.ts.map +1 -1
- package/dist/components/MText.d.ts +45 -29
- package/dist/components/MText.d.ts.map +1 -1
- package/dist/components/layout.d.ts +193 -84
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +5 -3
- 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/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 +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -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 +13 -0
- package/dist/motion-region.d.ts.map +1 -0
- package/dist/motion-region.js +134 -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 +67 -11
- package/dist/motion-surface.js.map +1 -1
- package/dist/motion.d.ts +1 -1
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +46 -10
- package/dist/motion.js.map +1 -1
- 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/sheet-motion.d.ts.map +1 -1
- package/dist/sheet-motion.js +96 -62
- package/dist/sheet-motion.js.map +1 -1
- package/package.json +3 -3
- package/src/components/DateCalendar.ts +213 -0
- package/src/components/MCheckbox.ts +22 -0
- package/src/components/MCombobox.ts +510 -0
- package/src/components/MDatePicker.ts +23 -0
- package/src/components/MFilePicker.ts +233 -0
- package/src/components/MInput.ts +21 -1
- package/src/components/MRadioGroup.ts +26 -0
- package/src/components/MSheet.ts +1 -1
- package/src/components/MSlider.ts +18 -1
- package/src/components/layout.ts +5 -2
- package/src/components/workflows.ts +27 -0
- package/src/files.ts +77 -0
- package/src/hydration.ts +21 -0
- package/src/index.ts +29 -1
- package/src/motion-context.ts +35 -0
- package/src/motion-region.ts +145 -0
- package/src/motion-surface.ts +76 -12
- package/src/motion.ts +52 -16
- package/src/screen-viewport.ts +4 -0
- package/src/sheet-motion.ts +86 -57
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
onActivated,
|
|
3
|
+
onDeactivated,
|
|
4
|
+
onBeforeUnmount,
|
|
5
|
+
provide,
|
|
6
|
+
shallowRef,
|
|
7
|
+
watch,
|
|
8
|
+
type VNode,
|
|
9
|
+
} from 'vue'
|
|
10
|
+
import {
|
|
11
|
+
bindMotionRegion,
|
|
12
|
+
type MotionRegion,
|
|
13
|
+
type MotionRegionAdapter,
|
|
14
|
+
} from '@getcortexlabs/mavis-core/experimental'
|
|
15
|
+
import { createMotionContext, motionContextKey } from './motion-context.js'
|
|
16
|
+
import { webSurfaceTarget } from './motion-surface.js'
|
|
17
|
+
import { webScrollElement } from './scroll-motion.js'
|
|
18
|
+
import type { WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
19
|
+
|
|
20
|
+
const regions = new WeakMap<MotionRegionAdapter, { target: HTMLElement; runtime: WebRuntime }>()
|
|
21
|
+
export function webRegion(adapter: MotionRegionAdapter) {
|
|
22
|
+
const region = regions.get(adapter)
|
|
23
|
+
if (!region) throw new TypeError('Use a mounted Web motion region.')
|
|
24
|
+
return region
|
|
25
|
+
}
|
|
26
|
+
function regionAdapter(runtime: WebRuntime, target: HTMLElement): MotionRegionAdapter {
|
|
27
|
+
const resolve = (surface: Parameters<typeof webSurfaceTarget>[0]) => {
|
|
28
|
+
const value = webSurfaceTarget(surface)
|
|
29
|
+
if (value.runtime !== runtime || !target.contains(value.target))
|
|
30
|
+
throw new TypeError('Declare each surface inside this motion region.')
|
|
31
|
+
return value.target
|
|
32
|
+
}
|
|
33
|
+
const adapter: MotionRegionAdapter = {
|
|
34
|
+
kind: 'web',
|
|
35
|
+
viewportEnter(surfaces, options) {
|
|
36
|
+
const control = runtime.viewportEnter(surfaces.map(resolve), {
|
|
37
|
+
keyframes: options.frames ?? { opacity: [0, 1], y: [20, 0] },
|
|
38
|
+
transition: { duration: 450, ...options.transition, stagger: options.stagger ?? 70 },
|
|
39
|
+
root: options.root && webScrollElement(options.root),
|
|
40
|
+
rootMargin: `${options.margin ?? 0}px`,
|
|
41
|
+
threshold: options.threshold,
|
|
42
|
+
once: options.once,
|
|
43
|
+
disabled: options.disabled,
|
|
44
|
+
})
|
|
45
|
+
return {
|
|
46
|
+
execution: target.ownerDocument.defaultView!.IntersectionObserver
|
|
47
|
+
? 'intersection-observer'
|
|
48
|
+
: 'static',
|
|
49
|
+
get pending() {
|
|
50
|
+
return control.pending
|
|
51
|
+
},
|
|
52
|
+
get completed() {
|
|
53
|
+
return control.completed
|
|
54
|
+
},
|
|
55
|
+
update: (state) => control.update(state),
|
|
56
|
+
refresh: () => control.refresh(),
|
|
57
|
+
dispose: () => control.dispose(),
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
sharedLayout(options) {
|
|
61
|
+
const control = runtime.sharedLayout(target, options)
|
|
62
|
+
return {
|
|
63
|
+
get active() {
|
|
64
|
+
return control.active
|
|
65
|
+
},
|
|
66
|
+
attach: (surface, identity) => control.attach(resolve(surface), identity),
|
|
67
|
+
transition: (change, options) => control.transition(change, options),
|
|
68
|
+
cancel: () => control.cancel(),
|
|
69
|
+
dispose: () => control.dispose(),
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
diagnostics(options) {
|
|
73
|
+
const control = runtime.diagnostics(options)
|
|
74
|
+
return {
|
|
75
|
+
snapshot: () => ({
|
|
76
|
+
...control.snapshot(),
|
|
77
|
+
identity: options.identity,
|
|
78
|
+
execution: 'jolt-web' as const,
|
|
79
|
+
}),
|
|
80
|
+
clear: () => control.clear(),
|
|
81
|
+
dispose: () => control.dispose(),
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
regions.set(adapter, { target, runtime })
|
|
86
|
+
return adapter
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The MBox is the stable input/layout region, separate from every animated child. */
|
|
90
|
+
export function useMotionRegion(reference: () => MotionRegion | undefined) {
|
|
91
|
+
const declared = Boolean(reference())
|
|
92
|
+
const context = createMotionContext()
|
|
93
|
+
if (declared) provide(motionContextKey, context)
|
|
94
|
+
const element = shallowRef<HTMLElement>()
|
|
95
|
+
let active = true,
|
|
96
|
+
release: (() => void) | undefined
|
|
97
|
+
const clear = () => {
|
|
98
|
+
release?.()
|
|
99
|
+
release = undefined
|
|
100
|
+
}
|
|
101
|
+
const attach = () => {
|
|
102
|
+
clear()
|
|
103
|
+
const region = reference(),
|
|
104
|
+
target = element.value
|
|
105
|
+
if (!active || !region || !target) return
|
|
106
|
+
if (!declared)
|
|
107
|
+
throw new Error('Declare motionRegion when mounting MBox; remount to add a region.')
|
|
108
|
+
const lease = context.acquire(target.ownerDocument)
|
|
109
|
+
const adapter = regionAdapter(lease.runtime, target)
|
|
110
|
+
try {
|
|
111
|
+
const unbind = bindMotionRegion(region, adapter)
|
|
112
|
+
release = () => {
|
|
113
|
+
try {
|
|
114
|
+
unbind()
|
|
115
|
+
} finally {
|
|
116
|
+
regions.delete(adapter)
|
|
117
|
+
lease.release()
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
regions.delete(adapter)
|
|
122
|
+
lease.release()
|
|
123
|
+
throw error
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
watch([element, reference], attach, { flush: 'post' })
|
|
127
|
+
onActivated(() => {
|
|
128
|
+
active = true
|
|
129
|
+
attach()
|
|
130
|
+
})
|
|
131
|
+
onDeactivated(() => {
|
|
132
|
+
active = false
|
|
133
|
+
clear()
|
|
134
|
+
})
|
|
135
|
+
onBeforeUnmount(clear)
|
|
136
|
+
return {
|
|
137
|
+
onVnodeMounted: (node: VNode) => {
|
|
138
|
+
element.value = node.el as HTMLElement
|
|
139
|
+
},
|
|
140
|
+
onVnodeBeforeUnmount: () => {
|
|
141
|
+
element.value = undefined
|
|
142
|
+
clear()
|
|
143
|
+
},
|
|
144
|
+
}
|
|
145
|
+
}
|
package/src/motion-surface.ts
CHANGED
|
@@ -1,21 +1,84 @@
|
|
|
1
1
|
import { webScrollElement } from './scroll-motion.js'
|
|
2
|
-
import type { WebReadableValue, WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
2
|
+
import type { WebReadableValue, WebRuntime, WebMotionScope } from '@rafaelaugusto/jolt/web'
|
|
3
3
|
import type { MotionSurfaceAdapter } from '@getcortexlabs/mavis-core/experimental'
|
|
4
|
+
import { webRegion } from './motion-region.js'
|
|
5
|
+
|
|
6
|
+
const targets = new WeakMap<MotionSurfaceAdapter, { runtime: WebRuntime; target: HTMLElement }>()
|
|
7
|
+
export function webSurfaceTarget(adapter: MotionSurfaceAdapter) {
|
|
8
|
+
const target = targets.get(adapter)
|
|
9
|
+
if (!target) throw new TypeError('Use a Web motion surface.')
|
|
10
|
+
return target
|
|
11
|
+
}
|
|
4
12
|
|
|
5
13
|
/** Application motion uses the same Jolt context as this component's press layer. */
|
|
6
|
-
export function webMotionSurface(
|
|
7
|
-
|
|
8
|
-
|
|
14
|
+
export function webMotionSurface(
|
|
15
|
+
runtime: WebRuntime,
|
|
16
|
+
target: HTMLElement,
|
|
17
|
+
enabled: () => boolean,
|
|
18
|
+
owner: WebRuntime | WebMotionScope = runtime,
|
|
19
|
+
sources = new WeakMap<object, WebReadableValue>(),
|
|
20
|
+
refreshes = new Map<object, () => void>(),
|
|
21
|
+
) {
|
|
9
22
|
const adapter: MotionSurfaceAdapter = {
|
|
23
|
+
use(setup) {
|
|
24
|
+
const scope = runtime.scope()
|
|
25
|
+
try {
|
|
26
|
+
scope.use((child) =>
|
|
27
|
+
setup(webMotionSurface(runtime, target, enabled, child, sources, refreshes).adapter),
|
|
28
|
+
)
|
|
29
|
+
} catch (error) {
|
|
30
|
+
scope.dispose()
|
|
31
|
+
throw error
|
|
32
|
+
}
|
|
33
|
+
return () => scope.dispose()
|
|
34
|
+
},
|
|
35
|
+
pointerFollow(region, options) {
|
|
36
|
+
const input = webRegion(region)
|
|
37
|
+
if (input.runtime !== runtime || input.target === target || !input.target.contains(target))
|
|
38
|
+
throw new TypeError('Use a separate enclosing motion region for pointer input.')
|
|
39
|
+
const pointer = owner.pointerFollow(input.target, {
|
|
40
|
+
...options,
|
|
41
|
+
disabled: options.disabled || !enabled(),
|
|
42
|
+
})
|
|
43
|
+
let disabled = options.disabled ?? false
|
|
44
|
+
const refresh = () => pointer.update({ disabled: disabled || !enabled() })
|
|
45
|
+
refreshes.set(pointer, refresh)
|
|
46
|
+
// The pointer owns its values; wrappers are borrowed by Mavis bindings.
|
|
47
|
+
const wrap = (value: WebReadableValue) => {
|
|
48
|
+
const borrowed = { get: () => value.get(), dispose() {} }
|
|
49
|
+
sources.set(borrowed, value)
|
|
50
|
+
return borrowed
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
x: wrap(pointer.x),
|
|
54
|
+
y: wrap(pointer.y),
|
|
55
|
+
execution: 'hover',
|
|
56
|
+
get active() {
|
|
57
|
+
return pointer.active
|
|
58
|
+
},
|
|
59
|
+
update(state) {
|
|
60
|
+
disabled = state.disabled
|
|
61
|
+
refresh()
|
|
62
|
+
},
|
|
63
|
+
refresh: () => pointer.refresh(),
|
|
64
|
+
dispose() {
|
|
65
|
+
refreshes.delete(pointer)
|
|
66
|
+
pointer.dispose()
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
},
|
|
10
70
|
refresh: () => runtime.refresh(target),
|
|
11
71
|
scrollLinked: (source, frames, options) =>
|
|
12
|
-
|
|
72
|
+
owner.scrollLinked(webScrollElement(source), target, frames, options),
|
|
13
73
|
map(source, input, output, options) {
|
|
14
|
-
|
|
74
|
+
const value = sources.get(source) ?? (source as WebReadableValue)
|
|
75
|
+
return 'map' in owner
|
|
76
|
+
? owner.map(value, input, output, options)
|
|
77
|
+
: value.to(input, output, options)
|
|
15
78
|
},
|
|
16
79
|
springValue(source, options) {
|
|
17
80
|
// Keep the runtime's private value identity; it rejects values from other contexts.
|
|
18
|
-
const spring =
|
|
81
|
+
const spring = owner.springValue(source as ReturnType<WebRuntime['motionValue']>, options)
|
|
19
82
|
const wrapper = {
|
|
20
83
|
get: () => spring.get(),
|
|
21
84
|
getVelocity: () => spring.getVelocity(),
|
|
@@ -33,12 +96,12 @@ export function webMotionSurface(runtime: WebRuntime, target: HTMLElement, enabl
|
|
|
33
96
|
return wrapper
|
|
34
97
|
},
|
|
35
98
|
|
|
36
|
-
animate: (values, options) =>
|
|
37
|
-
set: (values) =>
|
|
38
|
-
motionValue: (initial) =>
|
|
99
|
+
animate: (values, options) => owner.animate(target, values, options),
|
|
100
|
+
set: (values) => owner.set(target, values),
|
|
101
|
+
motionValue: (initial) => owner.motionValue(initial),
|
|
39
102
|
bind(values) {
|
|
40
103
|
// Spring wrappers retain their public handle, rather than registering a second clock.
|
|
41
|
-
return
|
|
104
|
+
return owner.bind(
|
|
42
105
|
target,
|
|
43
106
|
Object.fromEntries(
|
|
44
107
|
Object.entries(values).map(([key, value]) => [key, sources.get(value) ?? value]),
|
|
@@ -46,7 +109,7 @@ export function webMotionSurface(runtime: WebRuntime, target: HTMLElement, enabl
|
|
|
46
109
|
)
|
|
47
110
|
},
|
|
48
111
|
drag(options) {
|
|
49
|
-
const drag =
|
|
112
|
+
const drag = owner.drag(target, { ...options, disabled: !enabled() })
|
|
50
113
|
let paused = false
|
|
51
114
|
const refresh = () => {
|
|
52
115
|
const disabled = paused || !enabled()
|
|
@@ -77,6 +140,7 @@ export function webMotionSurface(runtime: WebRuntime, target: HTMLElement, enabl
|
|
|
77
140
|
}
|
|
78
141
|
},
|
|
79
142
|
}
|
|
143
|
+
targets.set(adapter, { runtime, target })
|
|
80
144
|
return {
|
|
81
145
|
adapter,
|
|
82
146
|
refresh: () => {
|
package/src/motion.ts
CHANGED
|
@@ -7,10 +7,11 @@ import {
|
|
|
7
7
|
type Ref,
|
|
8
8
|
type VNode,
|
|
9
9
|
} from 'vue'
|
|
10
|
-
import {
|
|
10
|
+
import type { WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
11
11
|
import { pressMotion, type MavisTheme } from '@getcortexlabs/mavis-core'
|
|
12
12
|
import { bindMotionSurface, type MotionSurface } from '@getcortexlabs/mavis-core/experimental'
|
|
13
13
|
import { webMotionSurface } from './motion-surface.js'
|
|
14
|
+
import { useMotionContext } from './motion-context.js'
|
|
14
15
|
|
|
15
16
|
// Chip keeps its separate CSS feedback until its interaction contract is migrated.
|
|
16
17
|
export function pressStyle(scale: number) {
|
|
@@ -203,18 +204,41 @@ export function usePressFeedback(
|
|
|
203
204
|
motionEnabled: () => boolean = enabled,
|
|
204
205
|
) {
|
|
205
206
|
const element = shallowRef<HTMLElement | null>(null)
|
|
207
|
+
const context = useMotionContext()
|
|
208
|
+
let lease: ReturnType<typeof context.acquire> | undefined
|
|
209
|
+
let attached: HTMLElement | undefined
|
|
206
210
|
let runtime: WebRuntime | undefined
|
|
207
211
|
let feedback: ReturnType<typeof attachWebPress> | undefined
|
|
208
212
|
let unbind: (() => void) | undefined
|
|
209
213
|
let application: ReturnType<typeof webMotionSurface> | undefined
|
|
210
214
|
const release = () => {
|
|
211
|
-
unbind
|
|
215
|
+
const cleanup = unbind,
|
|
216
|
+
press = feedback,
|
|
217
|
+
host = runtime,
|
|
218
|
+
target = attached,
|
|
219
|
+
ownership = lease
|
|
212
220
|
unbind = undefined
|
|
213
221
|
application = undefined
|
|
214
|
-
feedback?.dispose()
|
|
215
222
|
feedback = undefined
|
|
216
|
-
|
|
223
|
+
attached = undefined
|
|
224
|
+
lease = undefined
|
|
217
225
|
runtime = undefined
|
|
226
|
+
const errors: unknown[] = []
|
|
227
|
+
for (const dispose of [
|
|
228
|
+
cleanup,
|
|
229
|
+
() => press?.dispose(),
|
|
230
|
+
() => {
|
|
231
|
+
if (target) host?.release(target)
|
|
232
|
+
},
|
|
233
|
+
() => ownership?.release(),
|
|
234
|
+
]) {
|
|
235
|
+
try {
|
|
236
|
+
dispose?.()
|
|
237
|
+
} catch (error) {
|
|
238
|
+
errors.push(error)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (errors.length) throw new AggregateError(errors, 'Web motion presentation cleanup failed.')
|
|
218
242
|
}
|
|
219
243
|
const bind = () => {
|
|
220
244
|
unbind?.()
|
|
@@ -222,23 +246,35 @@ export function usePressFeedback(
|
|
|
222
246
|
const target = element.value
|
|
223
247
|
const current = runtime
|
|
224
248
|
if (target && current && surface?.()) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
249
|
+
try {
|
|
250
|
+
feedback?.observeGeometry()
|
|
251
|
+
application = webMotionSurface(current, target, motionEnabled)
|
|
252
|
+
unbind = bindMotionSurface(surface()!, application.adapter)
|
|
253
|
+
} catch (error) {
|
|
254
|
+
release()
|
|
255
|
+
throw error
|
|
256
|
+
}
|
|
228
257
|
}
|
|
229
258
|
}
|
|
230
259
|
const attach = () => {
|
|
231
260
|
const target = element.value
|
|
232
261
|
if (!target || runtime) return
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
262
|
+
lease = context.acquire(target.ownerDocument)
|
|
263
|
+
runtime = lease.runtime
|
|
264
|
+
attached = target
|
|
265
|
+
try {
|
|
266
|
+
feedback = attachWebPress(
|
|
267
|
+
target,
|
|
268
|
+
runtime,
|
|
269
|
+
enabled,
|
|
270
|
+
() => theme.value.motion.pressScale,
|
|
271
|
+
() => Boolean(surface?.()),
|
|
272
|
+
)
|
|
273
|
+
bind()
|
|
274
|
+
} catch (error) {
|
|
275
|
+
release()
|
|
276
|
+
throw error
|
|
277
|
+
}
|
|
242
278
|
}
|
|
243
279
|
let active = true
|
|
244
280
|
watch(
|
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/sheet-motion.ts
CHANGED
|
@@ -19,21 +19,46 @@ export function sheetMotion(
|
|
|
19
19
|
let disposed = false
|
|
20
20
|
let generation = 0
|
|
21
21
|
let contact: number | undefined
|
|
22
|
+
let observer: ResizeObserver | undefined
|
|
23
|
+
let failed = false
|
|
24
|
+
const release = () => {
|
|
25
|
+
abort.abort()
|
|
26
|
+
observer?.disconnect()
|
|
27
|
+
gesture?.dispose()
|
|
28
|
+
gesture = undefined
|
|
29
|
+
playback?.stop()
|
|
30
|
+
runtime.dispose()
|
|
31
|
+
}
|
|
32
|
+
// Enhancement failure must never strand an open dialog, focus trap or scroll lock.
|
|
33
|
+
const fallback = () => {
|
|
34
|
+
failed = true
|
|
35
|
+
generation++
|
|
36
|
+
release()
|
|
37
|
+
if (!open) closed()
|
|
38
|
+
}
|
|
22
39
|
const listen = (target: EventTarget, event: string, listener: EventListener, capture = false) =>
|
|
23
40
|
target.addEventListener(event, listener, { signal: abort.signal, capture, passive: true })
|
|
24
41
|
|
|
25
42
|
const play = () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
if (failed) {
|
|
44
|
+
if (!open) closed()
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const current = ++generation
|
|
49
|
+
gesture?.cancel()
|
|
50
|
+
const animation = runtime.animate(
|
|
51
|
+
panel,
|
|
52
|
+
{ y: open ? 0 : height },
|
|
53
|
+
{ type: 'spring', duration: 420, bounce: 0 },
|
|
54
|
+
)
|
|
55
|
+
playback = animation
|
|
56
|
+
void animation.finished.then((finished) => {
|
|
57
|
+
if (finished && !disposed && generation === current && !open) closed()
|
|
58
|
+
})
|
|
59
|
+
} catch {
|
|
60
|
+
fallback()
|
|
61
|
+
}
|
|
37
62
|
}
|
|
38
63
|
// Jolt owns recognition/capture/velocity. Gate its input to the dedicated handle using
|
|
39
64
|
// its supported disabled state, leaving pointer events and scrolling in the body intact.
|
|
@@ -75,51 +100,59 @@ export function sheetMotion(
|
|
|
75
100
|
dialog.style.bottom = `${Math.max(0, view.innerHeight - available - (visual?.offsetTop ?? 0))}px`
|
|
76
101
|
}
|
|
77
102
|
const resize = () => {
|
|
78
|
-
if (disposed) return
|
|
103
|
+
if (disposed || failed) return
|
|
104
|
+
try {
|
|
105
|
+
viewport()
|
|
106
|
+
const next = panel.offsetHeight
|
|
107
|
+
if (Math.abs(next - height) < 1) return
|
|
108
|
+
height = next
|
|
109
|
+
contact = undefined
|
|
110
|
+
attach()
|
|
111
|
+
play()
|
|
112
|
+
} catch {
|
|
113
|
+
fallback()
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
79
117
|
viewport()
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
height
|
|
83
|
-
contact = undefined
|
|
118
|
+
height = panel.offsetHeight
|
|
119
|
+
// Transform origin stays at 0 0, so geometry changes do not require pivot rebasing.
|
|
120
|
+
runtime.set(panel, { y: height })
|
|
84
121
|
attach()
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (
|
|
122
|
+
listen(view, 'pointerup', ((event: PointerEvent) => {
|
|
123
|
+
if (contact !== event.pointerId) return
|
|
124
|
+
contact = undefined
|
|
125
|
+
const animation = gesture?.animation
|
|
126
|
+
if (!animation) return
|
|
127
|
+
const current = ++generation
|
|
128
|
+
void animation.finished.then((finished) => {
|
|
129
|
+
if (!finished || disposed || current !== generation || !open || !dismissible()) return
|
|
130
|
+
// A single read at completion; no per-frame subscription or second motion clock.
|
|
131
|
+
const matrix = new view.DOMMatrixReadOnly(view.getComputedStyle(panel).transform)
|
|
132
|
+
if (Math.abs(matrix.m42 - height) < 1) swiped()
|
|
133
|
+
})
|
|
134
|
+
}) as EventListener)
|
|
135
|
+
const cancelled = (event?: Event) => {
|
|
136
|
+
if (event && 'pointerId' in event && event.pointerId !== contact) return
|
|
137
|
+
if (contact === undefined) return
|
|
138
|
+
contact = undefined
|
|
139
|
+
if (open) play()
|
|
140
|
+
}
|
|
141
|
+
for (const type of ['pointercancel', 'lostpointercapture']) listen(view, type, cancelled)
|
|
142
|
+
listen(view, 'blur', cancelled)
|
|
143
|
+
listen(panel.ownerDocument, 'visibilitychange', () => {
|
|
144
|
+
if (panel.ownerDocument.hidden) cancelled()
|
|
103
145
|
})
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
listen(panel.ownerDocument, 'visibilitychange', () => {
|
|
114
|
-
if (panel.ownerDocument.hidden) cancelled()
|
|
115
|
-
})
|
|
116
|
-
listen(view, 'resize', resize)
|
|
117
|
-
if (view.visualViewport) {
|
|
118
|
-
listen(view.visualViewport, 'resize', resize)
|
|
119
|
-
listen(view.visualViewport, 'scroll', resize)
|
|
146
|
+
listen(view, 'resize', resize)
|
|
147
|
+
if (view.visualViewport) {
|
|
148
|
+
listen(view.visualViewport, 'resize', resize)
|
|
149
|
+
listen(view.visualViewport, 'scroll', resize)
|
|
150
|
+
}
|
|
151
|
+
observer = new view.ResizeObserver(resize)
|
|
152
|
+
observer.observe(panel)
|
|
153
|
+
} catch {
|
|
154
|
+
fallback()
|
|
120
155
|
}
|
|
121
|
-
const observer = new view.ResizeObserver(resize)
|
|
122
|
-
observer.observe(panel)
|
|
123
156
|
return {
|
|
124
157
|
show() {
|
|
125
158
|
open = true
|
|
@@ -142,11 +175,7 @@ export function sheetMotion(
|
|
|
142
175
|
if (disposed) return
|
|
143
176
|
disposed = true
|
|
144
177
|
generation++
|
|
145
|
-
|
|
146
|
-
observer.disconnect()
|
|
147
|
-
gesture?.dispose()
|
|
148
|
-
playback?.stop()
|
|
149
|
-
runtime.dispose()
|
|
178
|
+
release()
|
|
150
179
|
},
|
|
151
180
|
}
|
|
152
181
|
}
|