@getcortexlabs/mavis-core 0.1.0-rc.12.2 → 0.1.0-rc.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/capabilities.d.ts +4 -4
- package/dist/capabilities.js +4 -4
- package/dist/capabilities.js.map +1 -1
- package/dist/contracts.d.ts +8 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +1 -0
- package/dist/contracts.js.map +1 -1
- package/dist/experimental-depth.d.ts +45 -0
- package/dist/experimental-depth.d.ts.map +1 -0
- package/dist/experimental-depth.js +179 -0
- package/dist/experimental-depth.js.map +1 -0
- package/dist/experimental-effects.d.ts +1 -1
- package/dist/experimental-effects.d.ts.map +1 -1
- package/dist/experimental-effects.js.map +1 -1
- package/dist/experimental-playback.d.ts +3 -3
- package/dist/experimental-playback.d.ts.map +1 -1
- package/dist/experimental-playback.js.map +1 -1
- package/dist/experimental-regions.d.ts +13 -3
- package/dist/experimental-regions.d.ts.map +1 -1
- package/dist/experimental-regions.js.map +1 -1
- package/dist/experimental-sensors.d.ts +2 -1
- package/dist/experimental-sensors.d.ts.map +1 -1
- package/dist/experimental.d.ts +20 -5
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +19 -2
- package/dist/experimental.js.map +1 -1
- package/dist/vue/component-motion.d.ts.map +1 -1
- package/dist/vue/component-motion.js +4 -2
- package/dist/vue/component-motion.js.map +1 -1
- package/dist/vue/component-props.d.ts +5 -0
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/props.d.ts +10 -0
- package/dist/vue/props.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/capabilities.ts +4 -4
- package/src/contracts.ts +1 -0
- package/src/experimental-depth.ts +215 -0
- package/src/experimental-effects.ts +1 -0
- package/src/experimental-playback.ts +4 -3
- package/src/experimental-regions.ts +13 -3
- package/src/experimental-sensors.ts +2 -1
- package/src/experimental.ts +49 -7
- package/src/vue/component-motion.ts +4 -2
package/src/capabilities.ts
CHANGED
|
@@ -105,11 +105,11 @@ export type CapabilityStatus = 'experimental' | 'planned' | 'unsupported' | 'unv
|
|
|
105
105
|
export const targetCapabilities = {
|
|
106
106
|
version: 1,
|
|
107
107
|
source: 'repository',
|
|
108
|
-
publishedBaseline: '0.1.0-rc.
|
|
108
|
+
publishedBaseline: '0.1.0-rc.13',
|
|
109
109
|
developmentMotion: {
|
|
110
110
|
availability: 'published',
|
|
111
111
|
joltCommit: null,
|
|
112
|
-
publishedJoltRelease: '0.1.0-rc.
|
|
112
|
+
publishedJoltRelease: '0.1.0-rc.13',
|
|
113
113
|
features: {
|
|
114
114
|
gradient: ['web', 'ios', 'android'],
|
|
115
115
|
loadingEffects: ['web', 'ios'],
|
|
@@ -135,7 +135,7 @@ export const targetCapabilities = {
|
|
|
135
135
|
streaming: 'unverified',
|
|
136
136
|
rsc: 'unsupported',
|
|
137
137
|
},
|
|
138
|
-
motion: { engine: 'jolt', minimum: '0.1.0-rc.
|
|
138
|
+
motion: { engine: 'jolt', minimum: '0.1.0-rc.13', start: 'client-mount' },
|
|
139
139
|
ssr: {
|
|
140
140
|
availability: '0.1.0-alpha.5',
|
|
141
141
|
host: 'nuxt',
|
|
@@ -178,7 +178,7 @@ export const targetCapabilities = {
|
|
|
178
178
|
streaming: 'unsupported',
|
|
179
179
|
rsc: 'unsupported',
|
|
180
180
|
},
|
|
181
|
-
motion: { engine: 'jolt', minimum: '0.1.0-rc.
|
|
181
|
+
motion: { engine: 'jolt', minimum: '0.1.0-rc.13', start: 'native-loaded' },
|
|
182
182
|
},
|
|
183
183
|
],
|
|
184
184
|
planned: [
|
package/src/contracts.ts
CHANGED
|
@@ -89,6 +89,7 @@ export const motionBoxContract = {
|
|
|
89
89
|
runtimeOnly: true,
|
|
90
90
|
}),
|
|
91
91
|
motionRegion: property<MotionRegion>()({ kind: 'object', default: undefined, runtimeOnly: true }),
|
|
92
|
+
perspective: number({ kind: 'number', default: undefined }),
|
|
92
93
|
}
|
|
93
94
|
export type Align = 'start' | 'center' | 'end' | 'stretch'
|
|
94
95
|
export type Justify = 'start' | 'center' | 'end' | 'between' | 'around'
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type { MotionVector } from './experimental-platforms.js'
|
|
2
|
+
import type { Shadow } from './theme/types.js'
|
|
3
|
+
|
|
4
|
+
export type MotionPathSegment =
|
|
5
|
+
| { to: MotionVector; control?: undefined }
|
|
6
|
+
| { to: MotionVector; control: MotionVector }
|
|
7
|
+
| { to: MotionVector; control: readonly [MotionVector, MotionVector] }
|
|
8
|
+
export interface MotionPathBounds {
|
|
9
|
+
readonly left: number
|
|
10
|
+
readonly top: number
|
|
11
|
+
readonly right: number
|
|
12
|
+
readonly bottom: number
|
|
13
|
+
}
|
|
14
|
+
/** A translation path in CSS pixels on Web and device-independent pixels on NativeScript. */
|
|
15
|
+
export interface MotionPath {
|
|
16
|
+
readonly data: string
|
|
17
|
+
readonly bounds: MotionPathBounds
|
|
18
|
+
/** Where the surface rests afterwards, with the forward tangent in degrees. */
|
|
19
|
+
readonly end: Readonly<MotionVector & { rotate: number }>
|
|
20
|
+
}
|
|
21
|
+
export type MotionShadowValues = Partial<
|
|
22
|
+
Record<'shadowOpacity' | 'shadowRadius' | 'shadowOffsetX' | 'shadowOffsetY', number>
|
|
23
|
+
>
|
|
24
|
+
|
|
25
|
+
const paths = new WeakSet<MotionPath>()
|
|
26
|
+
const limit = 1e5
|
|
27
|
+
const round = (value: number) => Number(value.toFixed(3))
|
|
28
|
+
const point = (value: MotionVector | undefined, name: string): MotionVector => {
|
|
29
|
+
if (
|
|
30
|
+
!value ||
|
|
31
|
+
typeof value !== 'object' ||
|
|
32
|
+
!Number.isFinite(value.x) ||
|
|
33
|
+
!Number.isFinite(value.y) ||
|
|
34
|
+
Math.abs(value.x) > limit ||
|
|
35
|
+
Math.abs(value.y) > limit
|
|
36
|
+
)
|
|
37
|
+
throw new RangeError(`Path ${name} needs finite x and y within ${limit} pixels/DIPs.`)
|
|
38
|
+
return { x: round(value.x), y: round(value.y) }
|
|
39
|
+
}
|
|
40
|
+
const bezier = (points: readonly number[], t: number) => {
|
|
41
|
+
let values = [...points]
|
|
42
|
+
while (values.length > 1)
|
|
43
|
+
values = values.slice(1).map((value, index) => values[index]! + (value - values[index]!) * t)
|
|
44
|
+
return values[0]!
|
|
45
|
+
}
|
|
46
|
+
const turns = (points: readonly number[]) => {
|
|
47
|
+
if (points.length === 3) {
|
|
48
|
+
const divisor = points[0]! - 2 * points[1]! + points[2]!
|
|
49
|
+
return divisor === 0 ? [] : [(points[0]! - points[1]!) / divisor]
|
|
50
|
+
}
|
|
51
|
+
const a = -points[0]! + 3 * points[1]! - 3 * points[2]! + points[3]!
|
|
52
|
+
const b = 2 * (points[0]! - 2 * points[1]! + points[2]!)
|
|
53
|
+
const c = points[1]! - points[0]!
|
|
54
|
+
if (a === 0) return b === 0 ? [] : [-c / b]
|
|
55
|
+
const root = b * b - 4 * a * c
|
|
56
|
+
if (root < 0) return []
|
|
57
|
+
return [(-b + Math.sqrt(root)) / (2 * a), (-b - Math.sqrt(root)) / (2 * a)]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Lines, quadratic and cubic curves in one continuous path, with bounds known up front. */
|
|
61
|
+
export function motionPath(start: MotionVector, ...segments: MotionPathSegment[]): MotionPath {
|
|
62
|
+
if (segments.length < 1 || segments.length > 64)
|
|
63
|
+
throw new RangeError('A motion path needs between 1 and 64 segments.')
|
|
64
|
+
let from = point(start, 'start')
|
|
65
|
+
let data = `M ${from.x} ${from.y}`
|
|
66
|
+
const xs = [from.x]
|
|
67
|
+
const ys = [from.y]
|
|
68
|
+
let rotate = 0
|
|
69
|
+
segments.forEach((segment, index) => {
|
|
70
|
+
const to = point(segment?.to, `segment ${index + 1} end`)
|
|
71
|
+
const controls = (
|
|
72
|
+
segment.control === undefined
|
|
73
|
+
? []
|
|
74
|
+
: Array.isArray(segment.control)
|
|
75
|
+
? segment.control
|
|
76
|
+
: [segment.control]
|
|
77
|
+
).map((value, at) => point(value as MotionVector, `segment ${index + 1} control ${at + 1}`))
|
|
78
|
+
if (controls.length > 2) throw new RangeError('A path segment takes one or two control points.')
|
|
79
|
+
const all = [from, ...controls, to]
|
|
80
|
+
if (all.every((value) => value.x === from.x && value.y === from.y))
|
|
81
|
+
throw new RangeError(`Path segment ${index + 1} has no length.`)
|
|
82
|
+
data += ` ${'LQC'[controls.length]} ${[...controls, to].map((value) => `${value.x} ${value.y}`).join(' ')}`
|
|
83
|
+
for (const [axis, values] of [
|
|
84
|
+
['x', xs],
|
|
85
|
+
['y', ys],
|
|
86
|
+
] as const) {
|
|
87
|
+
const line = all.map((value) => value[axis])
|
|
88
|
+
values.push(to[axis])
|
|
89
|
+
if (controls.length)
|
|
90
|
+
for (const t of turns(line)) if (t > 0 && t < 1) values.push(bezier(line, t))
|
|
91
|
+
}
|
|
92
|
+
const tangent = all
|
|
93
|
+
.slice(0, -1)
|
|
94
|
+
.reverse()
|
|
95
|
+
.find((value) => value.x !== to.x || value.y !== to.y)!
|
|
96
|
+
rotate = (Math.atan2(to.y - tangent.y, to.x - tangent.x) * 180) / Math.PI
|
|
97
|
+
from = to
|
|
98
|
+
})
|
|
99
|
+
const path: MotionPath = Object.freeze({
|
|
100
|
+
data,
|
|
101
|
+
bounds: Object.freeze({
|
|
102
|
+
left: round(Math.min(...xs)),
|
|
103
|
+
top: round(Math.min(...ys)),
|
|
104
|
+
right: round(Math.max(...xs)),
|
|
105
|
+
bottom: round(Math.max(...ys)),
|
|
106
|
+
}),
|
|
107
|
+
end: Object.freeze({ x: from.x, y: from.y, rotate: round(rotate) }),
|
|
108
|
+
})
|
|
109
|
+
paths.add(path)
|
|
110
|
+
return path
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const planar = ['x', 'y', 'rotate', 'scale', 'scaleX', 'scaleY', 'opacity', 'rotateX', 'rotateY']
|
|
114
|
+
const shadows = ['shadowOpacity', 'shadowRadius', 'shadowOffsetX', 'shadowOffsetY']
|
|
115
|
+
/** The channels a path replaces, so renderers can release them from other owners. */
|
|
116
|
+
export function motionChannels(values: Record<string, unknown>) {
|
|
117
|
+
return Object.keys(values).flatMap((key) =>
|
|
118
|
+
key === 'path' ? ['x', 'y', ...(values.orient ? ['rotate'] : [])] : key === 'orient' ? [] : key,
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
/** Renderer input: the descriptor becomes the path string both engines read. */
|
|
122
|
+
export function motionKeyframes<T extends { path?: MotionPath }>(
|
|
123
|
+
values: T,
|
|
124
|
+
): Omit<T, 'path'> & { path?: string } {
|
|
125
|
+
const { path, ...channels } = values
|
|
126
|
+
return path === undefined ? channels : { ...channels, path: path.data }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Rejects a request before a renderer replaces the motion already running. */
|
|
130
|
+
export function validateMotion(
|
|
131
|
+
values: Record<string, unknown>,
|
|
132
|
+
frames: boolean,
|
|
133
|
+
supportsShadow: () => boolean,
|
|
134
|
+
) {
|
|
135
|
+
if (!values || typeof values !== 'object') throw new TypeError('Motion needs an object.')
|
|
136
|
+
const keys = Object.keys(values).filter((key) => values[key] !== undefined)
|
|
137
|
+
for (const key of keys) {
|
|
138
|
+
const value = values[key]
|
|
139
|
+
if (frames && key === 'path') {
|
|
140
|
+
if (!paths.has(value as MotionPath))
|
|
141
|
+
throw new TypeError('Use motionPath() to declare a path.')
|
|
142
|
+
continue
|
|
143
|
+
}
|
|
144
|
+
if (frames && key === 'orient') {
|
|
145
|
+
if (typeof value !== 'boolean') throw new TypeError('Path orient must be a boolean.')
|
|
146
|
+
continue
|
|
147
|
+
}
|
|
148
|
+
if (!planar.includes(key) && !shadows.includes(key))
|
|
149
|
+
throw new TypeError(`Unsupported motion property "${key}".`)
|
|
150
|
+
const list = frames && Array.isArray(value) ? value : [value]
|
|
151
|
+
if (
|
|
152
|
+
!list.length ||
|
|
153
|
+
list.length > 1024 ||
|
|
154
|
+
list.some((entry) => !(frames && entry === null) && !Number.isFinite(entry))
|
|
155
|
+
)
|
|
156
|
+
throw new TypeError(`Motion property "${key}" needs finite numbers.`)
|
|
157
|
+
const numbers = list.filter((entry): entry is number => entry !== null)
|
|
158
|
+
if (key === 'shadowOpacity' && numbers.some((entry) => entry < 0 || entry > 1))
|
|
159
|
+
throw new RangeError('Shadow opacity must be between 0 and 1.')
|
|
160
|
+
if (key === 'shadowRadius' && numbers.some((entry) => entry < 0))
|
|
161
|
+
throw new RangeError('Shadow radius cannot be negative.')
|
|
162
|
+
}
|
|
163
|
+
if (keys.includes('orient') && !keys.includes('path'))
|
|
164
|
+
throw new TypeError('Path orient needs a path.')
|
|
165
|
+
if (keys.includes('path')) {
|
|
166
|
+
if (keys.includes('x') || keys.includes('y'))
|
|
167
|
+
throw new TypeError('A path owns x and y. Remove them or drop the path.')
|
|
168
|
+
if (values.orient === true && keys.includes('rotate'))
|
|
169
|
+
throw new TypeError('An oriented path owns rotate. Remove it or turn orient off.')
|
|
170
|
+
}
|
|
171
|
+
if (keys.some((key) => shadows.includes(key)) && !supportsShadow())
|
|
172
|
+
throw new Error(
|
|
173
|
+
'Shadow motion is unavailable on this surface. Check supports("shadow") and keep the static shadow.',
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Projection distance for the rotateX/rotateY of a box's direct children. */
|
|
178
|
+
export function resolvePerspective(value: number | undefined) {
|
|
179
|
+
if (value === undefined) return undefined
|
|
180
|
+
if (!Number.isFinite(value) || value < 1 || value > limit)
|
|
181
|
+
throw new RangeError('Perspective must be between 1 and 100000 pixels/DIPs.')
|
|
182
|
+
return value
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** A theme elevation as shadow channels, so a recipe moves between the theme's own shadows. */
|
|
186
|
+
export function elevationMotion(shadow: Readonly<Shadow>): Required<MotionShadowValues> {
|
|
187
|
+
if (shadow.spread !== 0) throw new RangeError('Shadow motion needs an elevation without spread.')
|
|
188
|
+
const color = shadow.color.trim().toLowerCase()
|
|
189
|
+
const parts = /^rgba?\(([^)]*)\)$/
|
|
190
|
+
.exec(color)?.[1]
|
|
191
|
+
?.split(/[\s,/]+/)
|
|
192
|
+
.filter(Boolean)
|
|
193
|
+
const alpha =
|
|
194
|
+
color === 'transparent'
|
|
195
|
+
? 0
|
|
196
|
+
: parts
|
|
197
|
+
? parts.length > 3
|
|
198
|
+
? parts[3]!.endsWith('%')
|
|
199
|
+
? parseFloat(parts[3]!) / 100
|
|
200
|
+
: Number(parts[3])
|
|
201
|
+
: 1
|
|
202
|
+
: /^#(?:[\da-f]{4}|[\da-f]{8})$/.test(color)
|
|
203
|
+
? parseInt(color.length === 5 ? color[4]!.repeat(2) : color.slice(7), 16) / 255
|
|
204
|
+
: /^#(?:[\da-f]{3}|[\da-f]{6})$/.test(color)
|
|
205
|
+
? 1
|
|
206
|
+
: Number.NaN
|
|
207
|
+
if (!Number.isFinite(alpha) || alpha < 0 || alpha > 1)
|
|
208
|
+
throw new TypeError('Shadow motion reads rgb(), rgba(), hex or transparent colors.')
|
|
209
|
+
return {
|
|
210
|
+
shadowOpacity: round(alpha),
|
|
211
|
+
shadowRadius: shadow.blur / 2,
|
|
212
|
+
shadowOffsetX: shadow.x,
|
|
213
|
+
shadowOffsetY: shadow.y,
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
MotionPlayback,
|
|
3
|
-
|
|
3
|
+
MotionChannelFrames,
|
|
4
4
|
MotionOptions,
|
|
5
5
|
MotionSurface,
|
|
6
6
|
MotionSurfaceAdapter,
|
|
@@ -31,9 +31,10 @@ export interface MotionDecayOptions {
|
|
|
31
31
|
}
|
|
32
32
|
export type MotionPosition = number | '<' | `${'+' | '-'}${number}`
|
|
33
33
|
export type MotionStep<T = MotionSurface> =
|
|
34
|
-
readonly [T,
|
|
34
|
+
| readonly [T, MotionChannelFrames, (MotionOptions & { at?: MotionPosition })?]
|
|
35
|
+
| (() => MotionPlayback)
|
|
35
36
|
export type MotionTimelineStep<T = MotionSurface> =
|
|
36
|
-
| readonly [T,
|
|
37
|
+
| readonly [T, MotionChannelFrames, (MotionOptions & { at?: MotionPosition })?]
|
|
37
38
|
| (() => MotionControlledPlayback)
|
|
38
39
|
| { at?: MotionPosition; run: () => MotionControlledPlayback }
|
|
39
40
|
export type MotionStateDefinitions<K extends string = string> = Record<
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
type MotionSurfaceAdapter,
|
|
32
32
|
type MotionBinding,
|
|
33
33
|
type MotionReadable,
|
|
34
|
-
type
|
|
34
|
+
type MotionChannelFrames,
|
|
35
35
|
type MotionOptions,
|
|
36
36
|
type MotionSpringOptions,
|
|
37
37
|
type MotionScrollSource,
|
|
@@ -47,19 +47,29 @@ export interface MotionPointerOptions {
|
|
|
47
47
|
disabled?: boolean
|
|
48
48
|
}
|
|
49
49
|
export interface MotionPointer extends MotionBinding {
|
|
50
|
+
/** Web: viewport CSS pixels from the region's center. NativeScript: the region's local DIPs. */
|
|
50
51
|
readonly x: MotionReadable
|
|
51
52
|
readonly y: MotionReadable
|
|
53
|
+
/** 1 while a hovering pointer is inside the region; 0 outside, disabled, suspended or without hover. */
|
|
54
|
+
readonly presence: MotionReadable
|
|
52
55
|
readonly active: boolean
|
|
56
|
+
/**
|
|
57
|
+
* Whether the mounted region has a hover API on this platform. It does not detect a connected
|
|
58
|
+
* mouse: an iPad without a pointer is available and stays at rest; an iPhone is not available.
|
|
59
|
+
*/
|
|
60
|
+
readonly available: boolean
|
|
61
|
+
/** `hover` while input can arrive; `static` when the values only ever hold their resting state. */
|
|
53
62
|
readonly execution: 'hover' | 'static'
|
|
54
63
|
update(state: { disabled: boolean }): void
|
|
55
64
|
refresh(): void
|
|
56
65
|
}
|
|
57
|
-
export type MotionPointerAdapter = Omit<MotionPointer, 'disposed' | 'x' | 'y'> & {
|
|
66
|
+
export type MotionPointerAdapter = Omit<MotionPointer, 'disposed' | 'x' | 'y' | 'presence'> & {
|
|
58
67
|
x: Pick<MotionReadable, 'get' | 'dispose'>
|
|
59
68
|
y: Pick<MotionReadable, 'get' | 'dispose'>
|
|
69
|
+
presence: Pick<MotionReadable, 'get' | 'dispose'>
|
|
60
70
|
}
|
|
61
71
|
export interface MotionViewportOptions {
|
|
62
|
-
frames?:
|
|
72
|
+
frames?: MotionChannelFrames
|
|
63
73
|
transition?: MotionOptions
|
|
64
74
|
stagger?: number
|
|
65
75
|
root?: MotionScrollSource
|
|
@@ -24,7 +24,8 @@ export interface MotionSensorSnapshot {
|
|
|
24
24
|
timestamp: number | null
|
|
25
25
|
samples: number
|
|
26
26
|
values: number[]
|
|
27
|
-
|
|
27
|
+
/** `replay` means Jolt is playing synthetic samples; it never proves hardware availability. */
|
|
28
|
+
backend: 'native' | 'device-orientation' | 'device-motion' | 'replay' | 'none'
|
|
28
29
|
reason?: string
|
|
29
30
|
}
|
|
30
31
|
export interface MotionSensor<T = MotionReadable> extends MotionBinding {
|
package/src/experimental.ts
CHANGED
|
@@ -13,6 +13,18 @@ export * from './experimental-effects.js'
|
|
|
13
13
|
export * from './experimental-collections.js'
|
|
14
14
|
export * from './experimental-surfaces.js'
|
|
15
15
|
export * from './experimental-platforms.js'
|
|
16
|
+
export {
|
|
17
|
+
motionPath,
|
|
18
|
+
motionChannels,
|
|
19
|
+
motionKeyframes,
|
|
20
|
+
resolvePerspective,
|
|
21
|
+
elevationMotion,
|
|
22
|
+
type MotionPath,
|
|
23
|
+
type MotionPathBounds,
|
|
24
|
+
type MotionPathSegment,
|
|
25
|
+
type MotionShadowValues,
|
|
26
|
+
} from './experimental-depth.js'
|
|
27
|
+
import { validateMotion, type MotionPath, type MotionShadowValues } from './experimental-depth.js'
|
|
16
28
|
import {
|
|
17
29
|
mapGradientBindings,
|
|
18
30
|
type MotionVisualSurface,
|
|
@@ -38,10 +50,25 @@ import type {
|
|
|
38
50
|
MotionSensorOptions,
|
|
39
51
|
MotionSensorAdapter,
|
|
40
52
|
} from './experimental-sensors.js'
|
|
41
|
-
export type
|
|
53
|
+
export type MotionPlanarValues = Partial<
|
|
42
54
|
Record<'scale' | 'scaleX' | 'scaleY' | 'x' | 'y' | 'rotate' | 'opacity', number>
|
|
43
55
|
>
|
|
44
|
-
|
|
56
|
+
/** rotateX and rotateY read their projection from the nearest box that declares `perspective`. */
|
|
57
|
+
export type MotionValues = MotionPlanarValues & Partial<Record<'rotateX' | 'rotateY', number>>
|
|
58
|
+
/** Shadow channels animate one existing shadow where `supports('shadow')` is true. */
|
|
59
|
+
export type MotionPoseValues = MotionValues & MotionShadowValues
|
|
60
|
+
/** Region sequences, timelines and states take these numeric channels. */
|
|
61
|
+
export type MotionChannelFrames = {
|
|
62
|
+
[K in keyof MotionValues]?: number | readonly (number | null)[]
|
|
63
|
+
}
|
|
64
|
+
export type MotionFrames = MotionChannelFrames & {
|
|
65
|
+
[K in keyof MotionShadowValues]?: number | readonly (number | null)[]
|
|
66
|
+
} & {
|
|
67
|
+
/** Owns x and y for the whole playback. */
|
|
68
|
+
path?: MotionPath
|
|
69
|
+
/** Faces the path's forward tangent, and then also owns rotate. */
|
|
70
|
+
orient?: boolean
|
|
71
|
+
}
|
|
45
72
|
export type MotionOptions = (
|
|
46
73
|
| {
|
|
47
74
|
type?: 'spring' | 'tween'
|
|
@@ -78,7 +105,7 @@ export interface MotionSurface extends MotionVisualSurface {
|
|
|
78
105
|
sensor(kind: MotionSensorKind, options?: MotionSensorOptions): MotionSensor
|
|
79
106
|
readonly available: boolean
|
|
80
107
|
animate(values: MotionFrames, options?: MotionOptions): MotionControlledPlayback
|
|
81
|
-
set(values:
|
|
108
|
+
set(values: MotionPoseValues): MotionPlayback
|
|
82
109
|
/** Runs once per mount/load. Its resources belong to that presentation. */
|
|
83
110
|
onAvailable(setup: () => void | (() => void)): () => void
|
|
84
111
|
/** A child owner, recreated on mount/load. Late work must use the supplied child. */
|
|
@@ -175,7 +202,7 @@ export interface MotionSurfaceAdapter extends Partial<MotionVisualAdapter> {
|
|
|
175
202
|
use?(setup: (adapter: MotionSurfaceAdapter) => () => void): () => void
|
|
176
203
|
pointerFollow?(region: MotionRegionAdapter, options: MotionPointerOptions): MotionPointerAdapter
|
|
177
204
|
animate(values: MotionFrames, options?: MotionOptions): MotionPlayback
|
|
178
|
-
set(values:
|
|
205
|
+
set(values: MotionPoseValues): MotionPlayback
|
|
179
206
|
animateValue?(
|
|
180
207
|
value: MotionValueAdapter,
|
|
181
208
|
frames: number | readonly (number | null)[],
|
|
@@ -218,7 +245,7 @@ export interface MotionSurfaceAdapter extends Partial<MotionVisualAdapter> {
|
|
|
218
245
|
}
|
|
219
246
|
|
|
220
247
|
/** CSS pixels on Web, device-independent pixels on NativeScript. Vertical only. */
|
|
221
|
-
export type MotionScrollFrames = Partial<Record<keyof
|
|
248
|
+
export type MotionScrollFrames = Partial<Record<keyof MotionPlanarValues, readonly number[]>>
|
|
222
249
|
export interface MotionScrollOptions {
|
|
223
250
|
range: readonly [number, number]
|
|
224
251
|
execution?: 'auto' | 'scheduler'
|
|
@@ -581,9 +608,15 @@ export function createMotionSurface(): MotionSurface {
|
|
|
581
608
|
for (const value of Object.values(values))
|
|
582
609
|
gravityFrames(Array.isArray(value) ? value : [value], options)
|
|
583
610
|
}
|
|
611
|
+
const binding = current()
|
|
612
|
+
validateMotion(values, true, () => binding.adapter.supports?.('shadow') ?? false)
|
|
584
613
|
return run((adapter) => adapter.animate(values, options))
|
|
585
614
|
},
|
|
586
|
-
set
|
|
615
|
+
set(values) {
|
|
616
|
+
const binding = current()
|
|
617
|
+
validateMotion(values, false, () => binding.adapter.supports?.('shadow') ?? false)
|
|
618
|
+
return run((adapter) => adapter.set(values))
|
|
619
|
+
},
|
|
587
620
|
supports: (effect) => current().adapter.supports?.(effect) ?? false,
|
|
588
621
|
particles(options) {
|
|
589
622
|
const binding = current()
|
|
@@ -835,10 +868,18 @@ export function createMotionSurface(): MotionSurface {
|
|
|
835
868
|
const raw = binding.adapter.pointerFollow(state.adapter, options)
|
|
836
869
|
const x = ownValue(binding, raw.x, false)
|
|
837
870
|
const y = ownValue(binding, raw.y, false)
|
|
871
|
+
const presence = ownValue(binding, raw.presence, false)
|
|
838
872
|
const control = own(binding, {
|
|
839
873
|
x,
|
|
840
874
|
y,
|
|
841
|
-
|
|
875
|
+
presence,
|
|
876
|
+
// Hover can become available after the native view loads.
|
|
877
|
+
get execution() {
|
|
878
|
+
return raw.execution
|
|
879
|
+
},
|
|
880
|
+
get available() {
|
|
881
|
+
return raw.available
|
|
882
|
+
},
|
|
842
883
|
get active() {
|
|
843
884
|
return raw.active
|
|
844
885
|
},
|
|
@@ -848,6 +889,7 @@ export function createMotionSurface(): MotionSurface {
|
|
|
848
889
|
state.resources.delete(control)
|
|
849
890
|
x.dispose()
|
|
850
891
|
y.dispose()
|
|
892
|
+
presence.dispose()
|
|
851
893
|
raw.dispose()
|
|
852
894
|
},
|
|
853
895
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { markRaw, onScopeDispose, watch, type WatchSource } from '@vue/runtime-core'
|
|
1
|
+
import { markRaw, nextTick, onScopeDispose, watch, type WatchSource } from '@vue/runtime-core'
|
|
2
2
|
import {
|
|
3
3
|
createMotionRegion,
|
|
4
4
|
createMotionSurface,
|
|
@@ -104,6 +104,8 @@ export function useComponentContent(source?: WatchSource, appear = true) {
|
|
|
104
104
|
if (appear) play()
|
|
105
105
|
}),
|
|
106
106
|
)
|
|
107
|
-
|
|
107
|
+
// After the whole flush: content that leaves the DOM releases its surface first, so a
|
|
108
|
+
// message removed while its text changes is never animated detached.
|
|
109
|
+
if (source) watch(source, () => void nextTick(play), { flush: 'post' })
|
|
108
110
|
return surface
|
|
109
111
|
}
|