@getcortexlabs/mavis-web 0.1.0-alpha.6 → 0.1.0-alpha.8
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/collection-motion.d.ts +4 -0
- package/dist/collection-motion.d.ts.map +1 -0
- package/dist/collection-motion.js +97 -0
- package/dist/collection-motion.js.map +1 -0
- package/dist/components/ChoicePaint.d.ts +17 -0
- package/dist/components/ChoicePaint.d.ts.map +1 -0
- package/dist/components/ChoicePaint.js +81 -0
- package/dist/components/ChoicePaint.js.map +1 -0
- package/dist/components/DateCalendar.d.ts +3 -3
- package/dist/components/LoadingDecoration.d.ts +116 -0
- package/dist/components/LoadingDecoration.d.ts.map +1 -0
- package/dist/components/LoadingDecoration.js +35 -0
- package/dist/components/LoadingDecoration.js.map +1 -0
- package/dist/components/MAccordion.d.ts +1 -1
- package/dist/components/MAlert.d.ts +1 -1
- package/dist/components/MAvatar.d.ts +2 -2
- package/dist/components/MBadge.d.ts +1 -1
- package/dist/components/MButton.d.ts +36 -14
- package/dist/components/MButton.d.ts.map +1 -1
- package/dist/components/MButton.js +15 -1
- package/dist/components/MButton.js.map +1 -1
- package/dist/components/MCard.d.ts +6 -5
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +9 -2
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MCheckbox.d.ts +1 -1
- package/dist/components/MCheckbox.d.ts.map +1 -1
- package/dist/components/MCheckbox.js +8 -3
- package/dist/components/MCheckbox.js.map +1 -1
- package/dist/components/MChip.d.ts +3 -3
- package/dist/components/MCombobox.d.ts +1 -1
- package/dist/components/MCombobox.d.ts.map +1 -1
- package/dist/components/MCombobox.js +10 -0
- package/dist/components/MCombobox.js.map +1 -1
- package/dist/components/MDatePicker.d.ts +16 -16
- package/dist/components/MDialog.d.ts +4 -1
- package/dist/components/MDialog.d.ts.map +1 -1
- package/dist/components/MDialog.js +69 -4
- package/dist/components/MDialog.js.map +1 -1
- package/dist/components/MEmptyState.d.ts +2 -2
- package/dist/components/MFilePicker.d.ts +2 -2
- package/dist/components/MIcon.d.ts +19 -1
- package/dist/components/MIcon.d.ts.map +1 -1
- package/dist/components/MIcon.js +6 -2
- package/dist/components/MIcon.js.map +1 -1
- package/dist/components/MImage.d.ts +203 -0
- package/dist/components/MImage.d.ts.map +1 -0
- package/dist/components/MImage.js +148 -0
- package/dist/components/MImage.js.map +1 -0
- package/dist/components/MInput.d.ts +6 -6
- package/dist/components/MLink.d.ts +3 -3
- package/dist/components/MListItem.d.ts +1 -1
- package/dist/components/MProgress.d.ts +3 -3
- package/dist/components/MRadioGroup.d.ts +1 -1
- package/dist/components/MRadioGroup.d.ts.map +1 -1
- package/dist/components/MRadioGroup.js +5 -3
- package/dist/components/MRadioGroup.js.map +1 -1
- package/dist/components/MReveal.d.ts +11 -11
- package/dist/components/MScreen.d.ts +9 -0
- package/dist/components/MScreen.d.ts.map +1 -1
- package/dist/components/MScreen.js +37 -24
- package/dist/components/MScreen.js.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +1 -1
- package/dist/components/MSelect.d.ts +1 -1
- package/dist/components/MSelect.d.ts.map +1 -1
- package/dist/components/MSelect.js +6 -0
- package/dist/components/MSelect.js.map +1 -1
- package/dist/components/MSeparator.d.ts +1 -1
- package/dist/components/MSheet.d.ts +5 -5
- package/dist/components/MSheet.d.ts.map +1 -1
- package/dist/components/MSheet.js +20 -13
- package/dist/components/MSheet.js.map +1 -1
- package/dist/components/MSkeleton.d.ts +12 -1
- package/dist/components/MSkeleton.d.ts.map +1 -1
- package/dist/components/MSkeleton.js +10 -4
- package/dist/components/MSkeleton.js.map +1 -1
- package/dist/components/MStack.d.ts +13 -13
- package/dist/components/MSwitch.d.ts +1 -1
- package/dist/components/MSwitch.d.ts.map +1 -1
- package/dist/components/MSwitch.js +9 -2
- package/dist/components/MSwitch.js.map +1 -1
- package/dist/components/MTabs.d.ts +1 -1
- package/dist/components/MText.d.ts +17 -6
- package/dist/components/MText.d.ts.map +1 -1
- package/dist/components/MText.js +8 -3
- package/dist/components/MText.js.map +1 -1
- package/dist/components/configurator.d.ts +541 -0
- package/dist/components/configurator.d.ts.map +1 -0
- package/dist/components/configurator.js +20 -0
- package/dist/components/configurator.js.map +1 -0
- package/dist/components/layout.d.ts +46 -35
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +3 -1
- package/dist/components/layout.js.map +1 -1
- package/dist/components/workflows.d.ts +1 -1
- package/dist/experimental.d.ts +2 -0
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +4 -0
- package/dist/experimental.js.map +1 -1
- package/dist/image-effects.d.ts +11 -0
- package/dist/image-effects.d.ts.map +1 -0
- package/dist/image-effects.js +65 -0
- package/dist/image-effects.js.map +1 -0
- package/dist/index.d.ts +3 -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.map +1 -1
- package/dist/motion-region.js +10 -1
- package/dist/motion-region.js.map +1 -1
- package/dist/motion-surface.d.ts +5 -1
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +107 -4
- package/dist/motion-surface.js.map +1 -1
- package/dist/platform-motion.d.ts +4 -0
- package/dist/platform-motion.d.ts.map +1 -0
- package/dist/platform-motion.js +23 -0
- package/dist/platform-motion.js.map +1 -0
- package/dist/scroll-motion.d.ts.map +1 -1
- package/dist/scroll-motion.js +17 -4
- package/dist/scroll-motion.js.map +1 -1
- package/dist/sheet-motion.d.ts +6 -2
- package/dist/sheet-motion.d.ts.map +1 -1
- package/dist/sheet-motion.js +56 -155
- package/dist/sheet-motion.js.map +1 -1
- package/dist/surface-effects.d.ts +4 -0
- package/dist/surface-effects.d.ts.map +1 -0
- package/dist/surface-effects.js +28 -0
- package/dist/surface-effects.js.map +1 -0
- package/dist/use-motion-surface.d.ts +8 -0
- package/dist/use-motion-surface.d.ts.map +1 -0
- package/dist/use-motion-surface.js +33 -0
- package/dist/use-motion-surface.js.map +1 -0
- package/dist/visual-effects.d.ts +4 -0
- package/dist/visual-effects.d.ts.map +1 -0
- package/dist/visual-effects.js +120 -0
- package/dist/visual-effects.js.map +1 -0
- package/package.json +3 -3
- package/src/collection-motion.ts +107 -0
- package/src/components/ChoicePaint.ts +96 -0
- package/src/components/LoadingDecoration.ts +39 -0
- package/src/components/MButton.ts +15 -1
- package/src/components/MCard.ts +9 -1
- package/src/components/MCheckbox.ts +14 -3
- package/src/components/MCombobox.ts +10 -0
- package/src/components/MDialog.ts +78 -4
- package/src/components/MIcon.ts +10 -1
- package/src/components/MImage.ts +168 -0
- package/src/components/MRadioGroup.ts +9 -3
- package/src/components/MScreen.ts +26 -2
- package/src/components/MSelect.ts +5 -0
- package/src/components/MSheet.ts +29 -18
- package/src/components/MSkeleton.ts +13 -4
- package/src/components/MSwitch.ts +14 -3
- package/src/components/MText.ts +11 -2
- package/src/components/configurator.ts +24 -0
- package/src/components/layout.ts +3 -0
- package/src/experimental.ts +8 -0
- package/src/image-effects.ts +78 -0
- package/src/index.ts +8 -0
- package/src/motion-region.ts +10 -1
- package/src/motion-surface.ts +107 -4
- package/src/platform-motion.ts +36 -0
- package/src/scroll-motion.ts +15 -3
- package/src/sheet-motion.ts +51 -152
- package/src/style.css +31 -15
- package/src/surface-effects.ts +33 -0
- package/src/use-motion-surface.ts +43 -0
- package/src/visual-effects.ts +139 -0
package/src/experimental.ts
CHANGED
|
@@ -3,6 +3,14 @@ import type { WebMotionScope, WebMotionResource } from '@rafaelaugusto/jolt/web'
|
|
|
3
3
|
import { regionState, type MotionRegion } from '@getcortexlabs/mavis-core/experimental'
|
|
4
4
|
import { webRegion } from './motion-region.js'
|
|
5
5
|
|
|
6
|
+
/** Call from an explicit application action; a request does not prove physical vibration. */
|
|
7
|
+
export function requestMavisWebHaptic(
|
|
8
|
+
region: MotionRegion,
|
|
9
|
+
style: import('@rafaelaugusto/jolt/web').HapticStyle,
|
|
10
|
+
): import('@rafaelaugusto/jolt/web').WebHapticResult {
|
|
11
|
+
return webRegion(regionState(region).adapter).runtime.haptic(style)
|
|
12
|
+
}
|
|
13
|
+
|
|
6
14
|
/**
|
|
7
15
|
* Web-only composition for application HTML/SVG inside a declared MBox region.
|
|
8
16
|
* Borrows the very same Jolt context as the region's component press surfaces.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MotionImageEffectName,
|
|
3
|
+
MotionImageEffectOptions,
|
|
4
|
+
MotionPlayback,
|
|
5
|
+
} from '@getcortexlabs/mavis-core/experimental'
|
|
6
|
+
import type { WebRuntime, WebMotionScope } from '@rafaelaugusto/jolt/web'
|
|
7
|
+
|
|
8
|
+
type Presentation = {
|
|
9
|
+
current(): boolean
|
|
10
|
+
commit(src: string): Promise<boolean>
|
|
11
|
+
}
|
|
12
|
+
const images = new WeakMap<HTMLImageElement, Presentation>()
|
|
13
|
+
const preparations = new WeakMap<HTMLImageElement, object>()
|
|
14
|
+
export function registerMotionImage(target: HTMLImageElement, presentation: Presentation) {
|
|
15
|
+
images.set(target, presentation)
|
|
16
|
+
return () => {
|
|
17
|
+
if (images.get(target) === presentation) images.delete(target)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function loadedMotionImage(target: HTMLElement): HTMLImageElement {
|
|
21
|
+
const image = target as HTMLImageElement
|
|
22
|
+
if (!images.has(image) || !image.complete || !image.naturalWidth)
|
|
23
|
+
throw new TypeError('Use the ready motionSurface of MImage for pixel effects.')
|
|
24
|
+
return image
|
|
25
|
+
}
|
|
26
|
+
export async function webImageEffect(
|
|
27
|
+
owner: WebRuntime | WebMotionScope,
|
|
28
|
+
target: HTMLElement,
|
|
29
|
+
name: MotionImageEffectName,
|
|
30
|
+
options: MotionImageEffectOptions = {},
|
|
31
|
+
live: () => boolean = () => true,
|
|
32
|
+
) {
|
|
33
|
+
const image = loadedMotionImage(target),
|
|
34
|
+
presentation = images.get(image)!
|
|
35
|
+
const { to, ...rest } = options
|
|
36
|
+
const preparation = {}
|
|
37
|
+
preparations.set(image, preparation)
|
|
38
|
+
let destination: HTMLImageElement | undefined
|
|
39
|
+
if (to !== undefined) {
|
|
40
|
+
if (name !== 'dissolve' || !to.trim())
|
|
41
|
+
throw new TypeError('Only dissolve accepts a nonempty destination source.')
|
|
42
|
+
destination = new image.ownerDocument.defaultView!.Image()
|
|
43
|
+
destination.crossOrigin = image.crossOrigin ?? 'anonymous'
|
|
44
|
+
destination.src = to
|
|
45
|
+
await destination.decode()
|
|
46
|
+
}
|
|
47
|
+
if (
|
|
48
|
+
!live() ||
|
|
49
|
+
preparations.get(image) !== preparation ||
|
|
50
|
+
!presentation.current() ||
|
|
51
|
+
images.get(image) !== presentation ||
|
|
52
|
+
!image.isConnected
|
|
53
|
+
)
|
|
54
|
+
throw new Error('Image presentation changed while preparing the effect.')
|
|
55
|
+
const previous = image.src
|
|
56
|
+
const raw = owner.imageEffect(image, name, {
|
|
57
|
+
...rest,
|
|
58
|
+
...(destination ? { to: destination } : {}),
|
|
59
|
+
})
|
|
60
|
+
const finished = raw.finished.then(async (success) => {
|
|
61
|
+
if (!success || !to || raw.progress !== 1) return success
|
|
62
|
+
if (!presentation.current() || images.get(image) !== presentation) return false
|
|
63
|
+
if (!live()) {
|
|
64
|
+
if (image.src === destination?.src) image.src = previous
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
return presentation.commit(to)
|
|
68
|
+
})
|
|
69
|
+
return new Proxy(raw as MotionPlayback, {
|
|
70
|
+
get(target, key) {
|
|
71
|
+
if (key === 'then') return undefined
|
|
72
|
+
if (key === 'finished') return finished
|
|
73
|
+
const value = Reflect.get(target, key, target)
|
|
74
|
+
return typeof value === 'function' ? value.bind(target) : value
|
|
75
|
+
},
|
|
76
|
+
set: (target, key, value) => Reflect.set(target, key, value, target),
|
|
77
|
+
})
|
|
78
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { MNumberInput, MMultiSelect } from './components/configurator.js'
|
|
2
|
+
import { MImage } from './components/MImage.js'
|
|
1
3
|
import { MStack } from './components/MStack.js'
|
|
2
4
|
export { themeVariables, useMavisTokens } from './tokens.js'
|
|
3
5
|
import { MLink } from './components/MLink.js'
|
|
@@ -81,6 +83,9 @@ export {
|
|
|
81
83
|
MSheet,
|
|
82
84
|
MDatePicker,
|
|
83
85
|
MDateRangePicker,
|
|
86
|
+
MNumberInput,
|
|
87
|
+
MMultiSelect,
|
|
88
|
+
MImage,
|
|
84
89
|
MCombobox,
|
|
85
90
|
MFilePicker,
|
|
86
91
|
MFormGroup,
|
|
@@ -152,6 +157,9 @@ export function createMavis(options: MavisOptions = {}) {
|
|
|
152
157
|
MSheet,
|
|
153
158
|
MDatePicker,
|
|
154
159
|
MDateRangePicker,
|
|
160
|
+
MNumberInput,
|
|
161
|
+
MMultiSelect,
|
|
162
|
+
MImage,
|
|
155
163
|
MCombobox,
|
|
156
164
|
MFilePicker,
|
|
157
165
|
MFormGroup,
|
package/src/motion-region.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { webSurfaceTarget } from './motion-surface.js'
|
|
|
9
9
|
import { webScrollElement } from './scroll-motion.js'
|
|
10
10
|
import type { WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
11
11
|
import { useConnectedMotion } from './connected-motion.js'
|
|
12
|
+
import { webCollectionMotion } from './collection-motion.js'
|
|
13
|
+
import { webPlatformMotion } from './platform-motion.js'
|
|
12
14
|
|
|
13
15
|
const regions = new WeakMap<MotionRegionAdapter, { target: HTMLElement; runtime: WebRuntime }>()
|
|
14
16
|
export function webRegion(adapter: MotionRegionAdapter) {
|
|
@@ -39,6 +41,8 @@ function regionAdapter(runtime: WebRuntime, target: HTMLElement): MotionRegionAd
|
|
|
39
41
|
: ([resolve(step[0]), step[1], step[2]] as const),
|
|
40
42
|
)
|
|
41
43
|
const adapter: MotionRegionAdapter = {
|
|
44
|
+
...webPlatformMotion(runtime, target, resolve),
|
|
45
|
+
...webCollectionMotion(runtime, target, resolve),
|
|
42
46
|
sequence: (items) =>
|
|
43
47
|
runtime.sequence(steps(items) as unknown as Parameters<WebRuntime['sequence']>[0]),
|
|
44
48
|
timeline: (items) =>
|
|
@@ -88,7 +92,12 @@ function regionAdapter(runtime: WebRuntime, target: HTMLElement): MotionRegionAd
|
|
|
88
92
|
viewportEnter(surfaces, options) {
|
|
89
93
|
const control = runtime.viewportEnter(surfaces.map(resolve), {
|
|
90
94
|
keyframes: options.frames ?? { opacity: [0, 1], y: [20, 0] },
|
|
91
|
-
transition: {
|
|
95
|
+
transition: {
|
|
96
|
+
...(options.transition?.type === 'gravity'
|
|
97
|
+
? options.transition
|
|
98
|
+
: { duration: 450, ...options.transition }),
|
|
99
|
+
stagger: options.stagger ?? 70,
|
|
100
|
+
},
|
|
92
101
|
root: options.root && webScrollElement(options.root),
|
|
93
102
|
rootMargin: `${options.margin ?? 0}px`,
|
|
94
103
|
threshold: options.threshold,
|
package/src/motion-surface.ts
CHANGED
|
@@ -7,6 +7,27 @@ import type {
|
|
|
7
7
|
} from '@rafaelaugusto/jolt/web'
|
|
8
8
|
import type { MotionSurfaceAdapter } from '@getcortexlabs/mavis-core/experimental'
|
|
9
9
|
import { webRegion } from './motion-region.js'
|
|
10
|
+
import { webVisualEffects } from './visual-effects.js'
|
|
11
|
+
|
|
12
|
+
const boundPaint = new WeakMap<HTMLElement, Map<string, number>>()
|
|
13
|
+
const paintKeys = new Set([
|
|
14
|
+
'backgroundColor',
|
|
15
|
+
'borderColor',
|
|
16
|
+
'color',
|
|
17
|
+
'borderRadius',
|
|
18
|
+
'borderWidth',
|
|
19
|
+
])
|
|
20
|
+
/** Vue may rerender slots while an application value owns paint on this element. */
|
|
21
|
+
export function preserveBoundPaint(target: HTMLElement | undefined) {
|
|
22
|
+
return target
|
|
23
|
+
? Object.fromEntries(
|
|
24
|
+
[...(boundPaint.get(target)?.keys() ?? [])].map((key) => [
|
|
25
|
+
key,
|
|
26
|
+
target.style[key as 'backgroundColor'],
|
|
27
|
+
]),
|
|
28
|
+
)
|
|
29
|
+
: {}
|
|
30
|
+
}
|
|
10
31
|
|
|
11
32
|
const targets = new WeakMap<MotionSurfaceAdapter, { runtime: WebRuntime; target: HTMLElement }>()
|
|
12
33
|
export function webSurfaceTarget(adapter: MotionSurfaceAdapter) {
|
|
@@ -23,13 +44,58 @@ export function webMotionSurface(
|
|
|
23
44
|
owner: WebRuntime | WebMotionScope = runtime,
|
|
24
45
|
sources = new WeakMap<object, WebReadableValue>(),
|
|
25
46
|
refreshes = new Map<object, () => void>(),
|
|
47
|
+
plainText: () => boolean = () => false,
|
|
26
48
|
) {
|
|
27
49
|
const adapter: MotionSurfaceAdapter = {
|
|
50
|
+
...webVisualEffects(owner, target, sources, plainText),
|
|
51
|
+
sensor(kind, options) {
|
|
52
|
+
const sensor = owner.sensor(kind, options)
|
|
53
|
+
const wrap = (value: WebReadableValue) => {
|
|
54
|
+
const borrowed = { get: () => value.get(), dispose() {} }
|
|
55
|
+
sources.set(borrowed, value)
|
|
56
|
+
return borrowed
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
kind,
|
|
60
|
+
x: wrap(sensor.x),
|
|
61
|
+
y: wrap(sensor.y),
|
|
62
|
+
z: wrap(sensor.z),
|
|
63
|
+
quaternion:
|
|
64
|
+
sensor.kind === 'rotation'
|
|
65
|
+
? {
|
|
66
|
+
x: wrap(sensor.quaternion.x),
|
|
67
|
+
y: wrap(sensor.quaternion.y),
|
|
68
|
+
z: wrap(sensor.quaternion.z),
|
|
69
|
+
w: wrap(sensor.quaternion.w),
|
|
70
|
+
}
|
|
71
|
+
: undefined,
|
|
72
|
+
get status() {
|
|
73
|
+
return sensor.status
|
|
74
|
+
},
|
|
75
|
+
get available() {
|
|
76
|
+
return sensor.available
|
|
77
|
+
},
|
|
78
|
+
get paused() {
|
|
79
|
+
return sensor.paused
|
|
80
|
+
},
|
|
81
|
+
pause: () => sensor.pause(),
|
|
82
|
+
resume: () => sensor.play(),
|
|
83
|
+
recenter: () => {
|
|
84
|
+
if (sensor.kind === 'rotation') sensor.recenter()
|
|
85
|
+
},
|
|
86
|
+
requestPermission: () => sensor.requestPermission(),
|
|
87
|
+
snapshot: () => sensor.snapshot(),
|
|
88
|
+
dispose: () => sensor.dispose(),
|
|
89
|
+
}
|
|
90
|
+
},
|
|
28
91
|
use(setup) {
|
|
29
92
|
const scope = runtime.scope()
|
|
30
93
|
try {
|
|
31
94
|
scope.use((child) =>
|
|
32
|
-
setup(
|
|
95
|
+
setup(
|
|
96
|
+
webMotionSurface(runtime, target, enabled, child, sources, refreshes, plainText)
|
|
97
|
+
.adapter,
|
|
98
|
+
),
|
|
33
99
|
)
|
|
34
100
|
} catch (error) {
|
|
35
101
|
scope.dispose()
|
|
@@ -81,6 +147,10 @@ export function webMotionSurface(
|
|
|
81
147
|
? owner.map(value, input, output, options)
|
|
82
148
|
: value.to(input, output, options)
|
|
83
149
|
},
|
|
150
|
+
mapColor(source, input, output) {
|
|
151
|
+
const value = sources.get(source) ?? (source as WebReadableValue)
|
|
152
|
+
return 'map' in owner ? owner.map(value, input, output) : value.to(input, output)
|
|
153
|
+
},
|
|
84
154
|
springValue(source, options) {
|
|
85
155
|
// Keep the runtime's private value identity; it rejects values from other contexts.
|
|
86
156
|
const spring = owner.springValue(source as ReturnType<WebRuntime['motionValue']>, options)
|
|
@@ -112,15 +182,48 @@ export function webMotionSurface(
|
|
|
112
182
|
motionValue: (initial) => owner.motionValue(initial),
|
|
113
183
|
bind(values) {
|
|
114
184
|
// Spring wrappers retain their public handle, rather than registering a second clock.
|
|
115
|
-
|
|
185
|
+
const binding = owner.bind(
|
|
116
186
|
target,
|
|
117
187
|
Object.fromEntries(
|
|
118
188
|
Object.entries(values).map(([key, value]) => [key, sources.get(value) ?? value]),
|
|
119
|
-
) as
|
|
189
|
+
) as Parameters<WebRuntime['bind']>[1],
|
|
120
190
|
)
|
|
191
|
+
let counts = boundPaint.get(target)
|
|
192
|
+
if (!counts) boundPaint.set(target, (counts = new Map()))
|
|
193
|
+
const keys = Object.keys(values).filter((key) => paintKeys.has(key))
|
|
194
|
+
for (const key of keys) counts.set(key, (counts.get(key) ?? 0) + 1)
|
|
195
|
+
let disposed = false
|
|
196
|
+
return {
|
|
197
|
+
dispose() {
|
|
198
|
+
if (disposed) return
|
|
199
|
+
disposed = true
|
|
200
|
+
try {
|
|
201
|
+
binding.dispose()
|
|
202
|
+
} finally {
|
|
203
|
+
for (const key of keys) {
|
|
204
|
+
const count = counts!.get(key)! - 1
|
|
205
|
+
if (count) counts!.set(key, count)
|
|
206
|
+
else counts!.delete(key)
|
|
207
|
+
}
|
|
208
|
+
if (!counts!.size) boundPaint.delete(target)
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
}
|
|
121
212
|
},
|
|
122
213
|
drag(options) {
|
|
123
|
-
const drag = owner.drag(target, {
|
|
214
|
+
const drag = owner.drag(target, {
|
|
215
|
+
...options,
|
|
216
|
+
disabled: !enabled(),
|
|
217
|
+
onRelease: options.onRelease
|
|
218
|
+
? (event) =>
|
|
219
|
+
options.onRelease!({
|
|
220
|
+
x: event.x,
|
|
221
|
+
y: event.y,
|
|
222
|
+
velocityX: event.velocity.x,
|
|
223
|
+
velocityY: event.velocity.y,
|
|
224
|
+
})
|
|
225
|
+
: undefined,
|
|
226
|
+
})
|
|
124
227
|
let paused = false
|
|
125
228
|
const refresh = () => {
|
|
126
229
|
const disabled = paused || !enabled()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
2
|
+
import type {
|
|
3
|
+
MotionRegionAdapter,
|
|
4
|
+
MotionSurfaceAdapter,
|
|
5
|
+
} from '@getcortexlabs/mavis-core/experimental'
|
|
6
|
+
|
|
7
|
+
export function webPlatformMotion(
|
|
8
|
+
runtime: WebRuntime,
|
|
9
|
+
target: HTMLElement,
|
|
10
|
+
resolve: (surface: MotionSurfaceAdapter) => HTMLElement,
|
|
11
|
+
): Pick<MotionRegionAdapter, 'onKeyboard' | 'physicsWorld'> {
|
|
12
|
+
return {
|
|
13
|
+
onKeyboard: (callback) => runtime.onKeyboard(callback),
|
|
14
|
+
async physicsWorld(bodies, options) {
|
|
15
|
+
const world = runtime.physicsWorld(
|
|
16
|
+
target,
|
|
17
|
+
bodies.map(({ target, ...body }) => ({ ...body, view: resolve(target) })),
|
|
18
|
+
options,
|
|
19
|
+
)
|
|
20
|
+
return {
|
|
21
|
+
get paused() {
|
|
22
|
+
return world.paused
|
|
23
|
+
},
|
|
24
|
+
pause: () => world.pause(),
|
|
25
|
+
resume: () => world.play(),
|
|
26
|
+
reset: () => world.reset(),
|
|
27
|
+
impulse: (id, value) => world.impulse(id, value),
|
|
28
|
+
attach: (id, value) => world.attach(id, value),
|
|
29
|
+
spring: (id, value) => world.spring(id, value),
|
|
30
|
+
snapTo: (id, index) => world.snapTo(id, index),
|
|
31
|
+
snapshot: () => world.snapshot(),
|
|
32
|
+
dispose: () => world.dispose(),
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/scroll-motion.ts
CHANGED
|
@@ -39,10 +39,21 @@ export function useScrollMotion(
|
|
|
39
39
|
// A ScrollTimeline can become inactive when content no longer overflows. Rebase
|
|
40
40
|
// its retained pose on layout changes too, without observing values every frame.
|
|
41
41
|
const resize = new view.ResizeObserver(refresh)
|
|
42
|
+
const observed = new Set<Element>()
|
|
42
43
|
const observe = () => {
|
|
43
|
-
|
|
44
|
-
resize.
|
|
45
|
-
|
|
44
|
+
// Keep existing observations across text/subtree mutations. Re-observing an
|
|
45
|
+
// unchanged ancestor during resize delivery can trigger a WebKit resize loop.
|
|
46
|
+
const wanted = new Set<Element>([target, ...target.children])
|
|
47
|
+
for (const node of observed) {
|
|
48
|
+
if (wanted.has(node)) continue
|
|
49
|
+
resize.unobserve(node)
|
|
50
|
+
observed.delete(node)
|
|
51
|
+
}
|
|
52
|
+
for (const node of wanted) {
|
|
53
|
+
if (observed.has(node)) continue
|
|
54
|
+
resize.observe(node)
|
|
55
|
+
observed.add(node)
|
|
56
|
+
}
|
|
46
57
|
}
|
|
47
58
|
const mutations = new view.MutationObserver(() => {
|
|
48
59
|
observe()
|
|
@@ -55,6 +66,7 @@ export function useScrollMotion(
|
|
|
55
66
|
release = () => {
|
|
56
67
|
disposed = true
|
|
57
68
|
resize.disconnect()
|
|
69
|
+
observed.clear()
|
|
58
70
|
mutations.disconnect()
|
|
59
71
|
target.ownerDocument.fonts?.removeEventListener('loadingdone', refresh)
|
|
60
72
|
view.removeEventListener('resize', refresh)
|
package/src/sheet-motion.ts
CHANGED
|
@@ -1,181 +1,80 @@
|
|
|
1
|
-
import { createWebRuntime, type
|
|
1
|
+
import { createWebRuntime, type WebBottomSheet } from '@rafaelaugusto/jolt/web'
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/** Jolt owns snap geometry, keyboard placement, gestures and nested-scroll handoff. */
|
|
4
4
|
export function sheetMotion(
|
|
5
5
|
dialog: HTMLDialogElement,
|
|
6
6
|
panel: HTMLElement,
|
|
7
|
-
handle: HTMLElement
|
|
8
|
-
|
|
7
|
+
handle: HTMLElement,
|
|
8
|
+
options: () => { dismissible: boolean; fullscreen: boolean; label: string },
|
|
9
9
|
closed: () => void,
|
|
10
10
|
swiped: () => void,
|
|
11
11
|
) {
|
|
12
|
-
const view = panel.ownerDocument.defaultView!
|
|
13
|
-
const abort = new view.AbortController()
|
|
14
12
|
const runtime = createWebRuntime(panel.ownerDocument)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let
|
|
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
|
-
}
|
|
39
|
-
const listen = (target: EventTarget, event: string, listener: EventListener, capture = false) =>
|
|
40
|
-
target.addEventListener(event, listener, { signal: abort.signal, capture, passive: true })
|
|
41
|
-
|
|
42
|
-
const play = () => {
|
|
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
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Jolt owns recognition/capture/velocity. Gate its input to the dedicated handle using
|
|
64
|
-
// its supported disabled state, leaving pointer events and scrolling in the body intact.
|
|
65
|
-
listen(
|
|
66
|
-
panel,
|
|
67
|
-
'pointerdown',
|
|
68
|
-
((event: PointerEvent) => {
|
|
69
|
-
const allowed = Boolean(open && dismissible() && handle?.contains(event.target as Node))
|
|
70
|
-
gesture?.update({ disabled: !allowed })
|
|
71
|
-
if (allowed && event.isPrimary && event.button === 0) contact = event.pointerId
|
|
72
|
-
}) as EventListener,
|
|
73
|
-
true,
|
|
74
|
-
)
|
|
75
|
-
// Safari otherwise focuses the non-focusable handle's ancestor and scrolls the
|
|
76
|
-
// underlying Screen. Preserve the current modal focus without cancelling pointer input.
|
|
77
|
-
handle?.addEventListener('mousedown', (event) => event.preventDefault(), {
|
|
78
|
-
signal: abort.signal,
|
|
79
|
-
})
|
|
80
|
-
|
|
13
|
+
const content = panel.querySelector<HTMLElement>('.m-sheet-content')!
|
|
14
|
+
const scrollView = panel.querySelector<HTMLElement>('.m-sheet-body')!
|
|
15
|
+
let sheet: WebBottomSheet | undefined,
|
|
16
|
+
disposed = false,
|
|
17
|
+
open = true,
|
|
18
|
+
settledClosed = false
|
|
19
|
+
let configuration = ''
|
|
81
20
|
const attach = () => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
}
|
|
21
|
+
const settings = options()
|
|
22
|
+
configuration = JSON.stringify(settings)
|
|
23
|
+
sheet?.dispose()
|
|
24
|
+
sheet = runtime.bottomSheet(panel, {
|
|
25
|
+
host: dialog,
|
|
26
|
+
handle,
|
|
27
|
+
content,
|
|
28
|
+
scrollView,
|
|
29
|
+
snap: [settings.fullscreen ? '100%' : 'content'],
|
|
30
|
+
safeArea: { top: settings.fullscreen ? 0 : 24 },
|
|
31
|
+
dismissible: settings.dismissible,
|
|
32
|
+
label: settings.label,
|
|
33
|
+
spring: { duration: 420, bounce: 0 },
|
|
34
|
+
onDismiss() {
|
|
35
|
+
settledClosed = true
|
|
36
|
+
if (disposed) return
|
|
37
|
+
if (open) swiped()
|
|
38
|
+
else closed()
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
dialog.dataset.motion = 'jolt-bottom-sheet'
|
|
115
42
|
}
|
|
116
43
|
try {
|
|
117
|
-
viewport()
|
|
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 })
|
|
121
44
|
attach()
|
|
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()
|
|
145
|
-
})
|
|
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
45
|
} catch {
|
|
154
|
-
|
|
46
|
+
sheet?.dispose()
|
|
47
|
+
runtime.dispose()
|
|
48
|
+
dialog.dataset.motion = 'static'
|
|
155
49
|
}
|
|
156
50
|
return {
|
|
157
51
|
show() {
|
|
52
|
+
if (disposed) return
|
|
158
53
|
open = true
|
|
159
|
-
|
|
54
|
+
settledClosed = false
|
|
55
|
+
sheet?.open()
|
|
160
56
|
},
|
|
161
57
|
hide() {
|
|
58
|
+
if (disposed) return
|
|
162
59
|
open = false
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
60
|
+
// Jolt's non-dismissible Web controller also rejects programmatic dismiss.
|
|
61
|
+
// Removing this presentation remains Mavis's responsibility.
|
|
62
|
+
if (!sheet || !options().dismissible || settledClosed) closed()
|
|
63
|
+
else sheet.dismiss()
|
|
166
64
|
},
|
|
167
65
|
refresh() {
|
|
168
|
-
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
66
|
+
if (disposed || !sheet) return
|
|
67
|
+
if (JSON.stringify(options()) !== configuration) {
|
|
68
|
+
attach()
|
|
69
|
+
if (open) sheet!.open()
|
|
70
|
+
} else sheet.remeasure()
|
|
173
71
|
},
|
|
174
72
|
dispose() {
|
|
175
73
|
if (disposed) return
|
|
176
74
|
disposed = true
|
|
177
|
-
|
|
178
|
-
|
|
75
|
+
sheet?.dispose()
|
|
76
|
+
runtime.dispose()
|
|
77
|
+
delete dialog.dataset.motion
|
|
179
78
|
},
|
|
180
79
|
}
|
|
181
80
|
}
|