@getcortexlabs/mavis-core 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/dist/capabilities.d.ts +19 -6
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +19 -3
- package/dist/capabilities.js.map +1 -1
- package/dist/choice-motion.d.ts +14 -0
- package/dist/choice-motion.d.ts.map +1 -0
- package/dist/choice-motion.js +5 -0
- package/dist/choice-motion.js.map +1 -0
- package/dist/contracts.d.ts +42 -2
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +17 -0
- package/dist/contracts.js.map +1 -1
- package/dist/dialog.d.ts +1 -1
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +1 -0
- package/dist/dialog.js.map +1 -1
- package/dist/experimental-collections.d.ts +82 -0
- package/dist/experimental-collections.d.ts.map +1 -0
- package/dist/experimental-collections.js +8 -0
- package/dist/experimental-collections.js.map +1 -0
- package/dist/experimental-effects.d.ts +107 -0
- package/dist/experimental-effects.d.ts.map +1 -0
- package/dist/experimental-effects.js +24 -0
- package/dist/experimental-effects.js.map +1 -0
- package/dist/experimental-platforms.d.ts +94 -0
- package/dist/experimental-platforms.d.ts.map +1 -0
- package/dist/experimental-platforms.js +2 -0
- package/dist/experimental-platforms.js.map +1 -0
- package/dist/experimental-playback.d.ts +2 -2
- package/dist/experimental-playback.d.ts.map +1 -1
- package/dist/experimental-regions.d.ts +17 -2
- package/dist/experimental-regions.d.ts.map +1 -1
- package/dist/experimental-regions.js +91 -0
- package/dist/experimental-regions.js.map +1 -1
- package/dist/experimental-sensors.d.ts +42 -0
- package/dist/experimental-sensors.d.ts.map +1 -0
- package/dist/experimental-sensors.js +2 -0
- package/dist/experimental-sensors.js.map +1 -0
- package/dist/experimental-surfaces.d.ts +127 -0
- package/dist/experimental-surfaces.d.ts.map +1 -0
- package/dist/experimental-surfaces.js +2 -0
- package/dist/experimental-surfaces.js.map +1 -0
- package/dist/experimental.d.ts +37 -6
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +289 -5
- package/dist/experimental.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/multi-select.d.ts +4 -0
- package/dist/multi-select.d.ts.map +1 -0
- package/dist/multi-select.js +23 -0
- package/dist/multi-select.js.map +1 -0
- package/dist/number-input.d.ts +21 -0
- package/dist/number-input.d.ts.map +1 -0
- package/dist/number-input.js +63 -0
- package/dist/number-input.js.map +1 -0
- package/dist/vue/component-props.d.ts +309 -20
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +4 -0
- package/dist/vue/component-props.js.map +1 -1
- package/dist/vue/configurator-props.d.ts +256 -0
- package/dist/vue/configurator-props.d.ts.map +1 -0
- package/dist/vue/configurator-props.js +57 -0
- package/dist/vue/configurator-props.js.map +1 -0
- package/dist/vue/configurator.d.ts +403 -0
- package/dist/vue/configurator.d.ts.map +1 -0
- package/dist/vue/configurator.js +287 -0
- package/dist/vue/configurator.js.map +1 -0
- package/dist/vue/date-picker.d.ts +8 -8
- package/dist/vue/global-components.d.ts +14 -0
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +3 -0
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +3 -0
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/loading-effect.d.ts +7 -0
- package/dist/vue/loading-effect.d.ts.map +1 -0
- package/dist/vue/loading-effect.js +32 -0
- package/dist/vue/loading-effect.js.map +1 -0
- package/dist/vue/props.d.ts +123 -43
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +7 -0
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/workflows.d.ts +1 -1
- package/package.json +1 -1
- package/src/capabilities.ts +19 -3
- package/src/choice-motion.ts +12 -0
- package/src/contracts.ts +17 -0
- package/src/dialog.ts +3 -1
- package/src/experimental-collections.ts +87 -0
- package/src/experimental-effects.ts +146 -0
- package/src/experimental-platforms.ts +96 -0
- package/src/experimental-playback.ts +1 -1
- package/src/experimental-regions.ts +136 -2
- package/src/experimental-sensors.ts +50 -0
- package/src/experimental-surfaces.ts +124 -0
- package/src/experimental.ts +367 -20
- package/src/index.ts +4 -0
- package/src/multi-select.ts +30 -0
- package/src/number-input.ts +80 -0
- package/src/vue/component-props.ts +4 -0
- package/src/vue/configurator-props.ts +61 -0
- package/src/vue/configurator.ts +350 -0
- package/src/vue/global-components.ts +16 -0
- package/src/vue/index.ts +4 -0
- package/src/vue/loading-effect.ts +44 -0
- package/src/vue/props.ts +8 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { MotionBinding, MotionOptions, MotionPlayback } from './experimental.js'
|
|
2
|
+
import type { MotionControlledPlayback } from './experimental-playback.js'
|
|
3
|
+
|
|
4
|
+
/** The common renderer subset. Distances are CSS pixels on Web and DIPs on native. */
|
|
5
|
+
export interface MotionParticleOptions {
|
|
6
|
+
colors?: readonly string[]
|
|
7
|
+
shape?: 'circle' | 'rectangle' | 'ring'
|
|
8
|
+
source?: 'center' | 'top' | 'bottom'
|
|
9
|
+
rate?: number
|
|
10
|
+
lifetime?: number
|
|
11
|
+
size?: number
|
|
12
|
+
velocity?: number
|
|
13
|
+
velocityRange?: number
|
|
14
|
+
angle?: number
|
|
15
|
+
spread?: number
|
|
16
|
+
gravity?: number
|
|
17
|
+
spin?: number
|
|
18
|
+
spinRange?: number
|
|
19
|
+
fadeOut?: boolean
|
|
20
|
+
duration?: number
|
|
21
|
+
}
|
|
22
|
+
export interface MotionConfettiOptions {
|
|
23
|
+
count?: number
|
|
24
|
+
colors?: readonly string[]
|
|
25
|
+
}
|
|
26
|
+
export interface MotionDecoration extends MotionBinding {
|
|
27
|
+
readonly supported: boolean
|
|
28
|
+
}
|
|
29
|
+
export interface MotionBlurOptions {
|
|
30
|
+
amount?: number
|
|
31
|
+
radius?: number
|
|
32
|
+
style?: 'system' | 'light' | 'dark'
|
|
33
|
+
}
|
|
34
|
+
export interface MotionBlur extends MotionBinding {
|
|
35
|
+
animate(amount: number, options?: MotionOptions): MotionControlledPlayback
|
|
36
|
+
set(amount: number): void
|
|
37
|
+
stop(): void
|
|
38
|
+
snapshot(): { amount: number; appliedAmount: number; backend: string; attached: boolean }
|
|
39
|
+
}
|
|
40
|
+
export interface MotionShapeValues {
|
|
41
|
+
d?: string
|
|
42
|
+
strokeStart?: number
|
|
43
|
+
strokeEnd?: number
|
|
44
|
+
}
|
|
45
|
+
export interface MotionShapeOptions extends MotionShapeValues {
|
|
46
|
+
d: string
|
|
47
|
+
viewBox: readonly [number, number, number, number]
|
|
48
|
+
stroke?: string
|
|
49
|
+
fill?: string
|
|
50
|
+
strokeWidth?: number
|
|
51
|
+
lineCap?: 'butt' | 'round' | 'square'
|
|
52
|
+
lineJoin?: 'miter' | 'round' | 'bevel'
|
|
53
|
+
fillRule?: 'nonzero' | 'evenodd'
|
|
54
|
+
}
|
|
55
|
+
export interface MotionShape extends MotionBinding {
|
|
56
|
+
animate(values: MotionShapeValues, options?: MotionOptions): MotionControlledPlayback
|
|
57
|
+
set(values: MotionShapeValues): void
|
|
58
|
+
stop(): void
|
|
59
|
+
}
|
|
60
|
+
export interface MotionLiquid extends MotionDecoration {
|
|
61
|
+
pause(): void
|
|
62
|
+
resume(): void
|
|
63
|
+
}
|
|
64
|
+
export interface MotionLiquidOptions {
|
|
65
|
+
intensity?: number
|
|
66
|
+
duration?: number
|
|
67
|
+
}
|
|
68
|
+
export type MotionImageEffectName = 'ripple' | 'distortion' | 'dissolve'
|
|
69
|
+
export interface MotionImagePlayback extends MotionControlledPlayback {
|
|
70
|
+
reverse(): void
|
|
71
|
+
finish(): void
|
|
72
|
+
}
|
|
73
|
+
export interface MotionImageEffectOptions {
|
|
74
|
+
origin?: { x: number; y: number }
|
|
75
|
+
amplitude?: number
|
|
76
|
+
radius?: number
|
|
77
|
+
duration?: number
|
|
78
|
+
seed?: number
|
|
79
|
+
/** A source URL, prepared by MImage before starting. Success emits update:src. */
|
|
80
|
+
to?: string
|
|
81
|
+
paused?: boolean
|
|
82
|
+
}
|
|
83
|
+
export type MotionSymbolEffectName = 'bounce' | 'pulse' | 'scale' | 'variableColor'
|
|
84
|
+
export interface MotionSymbolOptions {
|
|
85
|
+
speed?: number
|
|
86
|
+
repeat?: boolean
|
|
87
|
+
}
|
|
88
|
+
export interface MotionKeyboardFollowOptions {
|
|
89
|
+
offset?: number
|
|
90
|
+
}
|
|
91
|
+
export interface MotionSurfaceEffects {
|
|
92
|
+
particles(options?: MotionParticleOptions): MotionDecoration
|
|
93
|
+
confetti(options?: MotionConfettiOptions): MotionDecoration
|
|
94
|
+
blur(options?: MotionBlurOptions): MotionBlur
|
|
95
|
+
shape(options: MotionShapeOptions): MotionShape
|
|
96
|
+
/** Only a loaded MImage target, not its layout wrapper. */
|
|
97
|
+
liquid(options?: MotionLiquidOptions): MotionLiquid
|
|
98
|
+
imageEffect(
|
|
99
|
+
name: MotionImageEffectName,
|
|
100
|
+
options?: MotionImageEffectOptions,
|
|
101
|
+
): Promise<MotionImagePlayback>
|
|
102
|
+
/** MIcon artwork: Web supports glyphs; native requires an iOS system-symbol image. */
|
|
103
|
+
symbolEffect(name: MotionSymbolEffectName, options?: MotionSymbolOptions): MotionPlayback
|
|
104
|
+
/** Use a dedicated, untranslated composer surface. */
|
|
105
|
+
followKeyboard(options?: MotionKeyboardFollowOptions): MotionBinding
|
|
106
|
+
}
|
|
107
|
+
export interface MotionSurfaceEffectsAdapter {
|
|
108
|
+
particles(options?: MotionParticleOptions): Omit<MotionDecoration, 'disposed'>
|
|
109
|
+
confetti(options?: MotionConfettiOptions): Omit<MotionDecoration, 'disposed'>
|
|
110
|
+
blur(options?: MotionBlurOptions): Omit<MotionBlur, 'disposed' | 'animate'> & {
|
|
111
|
+
animate(amount: number, options?: MotionOptions): MotionPlayback
|
|
112
|
+
}
|
|
113
|
+
shape(options: MotionShapeOptions): Omit<MotionShape, 'disposed' | 'animate'> & {
|
|
114
|
+
animate(values: MotionShapeValues, options?: MotionOptions): MotionPlayback
|
|
115
|
+
}
|
|
116
|
+
liquid(options?: MotionLiquidOptions): Omit<MotionLiquid, 'disposed'>
|
|
117
|
+
imageEffect(
|
|
118
|
+
name: MotionImageEffectName,
|
|
119
|
+
options: MotionImageEffectOptions | undefined,
|
|
120
|
+
live: () => boolean,
|
|
121
|
+
): Promise<MotionPlayback>
|
|
122
|
+
symbolEffect(name: MotionSymbolEffectName, options?: MotionSymbolOptions): MotionPlayback
|
|
123
|
+
followKeyboard(options?: MotionKeyboardFollowOptions): { dispose(): void }
|
|
124
|
+
}
|
package/src/experimental.ts
CHANGED
|
@@ -6,6 +6,17 @@ import {
|
|
|
6
6
|
type MotionDecayOptions,
|
|
7
7
|
} from './experimental-playback.js'
|
|
8
8
|
export * from './experimental-playback.js'
|
|
9
|
+
export * from './experimental-effects.js'
|
|
10
|
+
export * from './experimental-collections.js'
|
|
11
|
+
export * from './experimental-surfaces.js'
|
|
12
|
+
export * from './experimental-platforms.js'
|
|
13
|
+
import {
|
|
14
|
+
mapGradientBindings,
|
|
15
|
+
type MotionVisualSurface,
|
|
16
|
+
type MotionVisualAdapter,
|
|
17
|
+
type MotionGradient,
|
|
18
|
+
type MotionCircular,
|
|
19
|
+
} from './experimental-effects.js'
|
|
9
20
|
/** Experimental, single-surface motion contract. No platform objects cross this boundary. */
|
|
10
21
|
import {
|
|
11
22
|
regionState,
|
|
@@ -17,22 +28,51 @@ import {
|
|
|
17
28
|
type MotionPointerAdapter,
|
|
18
29
|
} from './experimental-regions.js'
|
|
19
30
|
export * from './experimental-regions.js'
|
|
31
|
+
export * from './experimental-sensors.js'
|
|
32
|
+
import type {
|
|
33
|
+
MotionSensor,
|
|
34
|
+
MotionSensorKind,
|
|
35
|
+
MotionSensorOptions,
|
|
36
|
+
MotionSensorAdapter,
|
|
37
|
+
} from './experimental-sensors.js'
|
|
20
38
|
export type MotionValues = Partial<
|
|
21
39
|
Record<'scale' | 'scaleX' | 'scaleY' | 'x' | 'y' | 'rotate' | 'opacity', number>
|
|
22
40
|
>
|
|
23
41
|
export type MotionFrames = { [K in keyof MotionValues]?: number | readonly (number | null)[] }
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
42
|
+
export type MotionOptions = (
|
|
43
|
+
| {
|
|
44
|
+
type?: 'spring' | 'tween'
|
|
45
|
+
duration?: number
|
|
46
|
+
bounce?: number
|
|
47
|
+
ease?: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut'
|
|
48
|
+
acceleration?: never
|
|
49
|
+
restitution?: never
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
type: 'gravity'
|
|
53
|
+
acceleration?: number
|
|
54
|
+
restitution?: number
|
|
55
|
+
duration?: never
|
|
56
|
+
bounce?: never
|
|
57
|
+
ease?: never
|
|
58
|
+
}
|
|
59
|
+
) & {
|
|
60
|
+
velocity?: number
|
|
29
61
|
delay?: number
|
|
62
|
+
haptic?:
|
|
63
|
+
| 'light'
|
|
64
|
+
| 'medium'
|
|
65
|
+
| 'heavy'
|
|
66
|
+
| false
|
|
67
|
+
| { style: 'light' | 'medium' | 'heavy'; times?: readonly number[] }
|
|
30
68
|
}
|
|
69
|
+
|
|
31
70
|
export interface MotionPlayback {
|
|
32
71
|
readonly finished: Promise<boolean>
|
|
33
72
|
stop(): void
|
|
34
73
|
}
|
|
35
|
-
export interface MotionSurface {
|
|
74
|
+
export interface MotionSurface extends MotionVisualSurface {
|
|
75
|
+
sensor(kind: MotionSensorKind, options?: MotionSensorOptions): MotionSensor
|
|
36
76
|
readonly available: boolean
|
|
37
77
|
animate(values: MotionFrames, options?: MotionOptions): MotionControlledPlayback
|
|
38
78
|
set(values: MotionValues): MotionPlayback
|
|
@@ -68,6 +108,9 @@ export interface MotionBinding {
|
|
|
68
108
|
readonly disposed: boolean
|
|
69
109
|
dispose(): void
|
|
70
110
|
}
|
|
111
|
+
export interface MotionColor extends MotionBinding {
|
|
112
|
+
get(): string
|
|
113
|
+
}
|
|
71
114
|
export interface MotionReadable extends MotionBinding {
|
|
72
115
|
get(): number
|
|
73
116
|
to(
|
|
@@ -75,6 +118,7 @@ export interface MotionReadable extends MotionBinding {
|
|
|
75
118
|
output: readonly number[],
|
|
76
119
|
options?: { clamp?: boolean },
|
|
77
120
|
): MotionReadable
|
|
121
|
+
to(input: readonly number[], output: readonly string[]): MotionColor
|
|
78
122
|
}
|
|
79
123
|
export interface MotionValue extends MotionReadable {
|
|
80
124
|
set(value: number): void
|
|
@@ -94,7 +138,10 @@ export interface MotionSpringOptions {
|
|
|
94
138
|
restDelta?: number
|
|
95
139
|
restSpeed?: number
|
|
96
140
|
}
|
|
97
|
-
export type MotionBindings = Partial<
|
|
141
|
+
export type MotionBindings = Partial<
|
|
142
|
+
Record<keyof MotionValues | 'borderRadius' | 'borderWidth', MotionReadable>
|
|
143
|
+
> &
|
|
144
|
+
Partial<Record<'backgroundColor' | 'borderColor' | 'color', MotionColor>>
|
|
98
145
|
export interface MotionDragOptions {
|
|
99
146
|
axis: 'x' | 'y'
|
|
100
147
|
bounds?: { left?: number; right?: number; top?: number; bottom?: number }
|
|
@@ -113,7 +160,8 @@ export interface MotionDrag extends MotionBinding {
|
|
|
113
160
|
export type MotionValueAdapter = Pick<MotionValue, 'get' | 'set' | 'dispose'>
|
|
114
161
|
export type MotionSpringAdapter = Omit<MotionSpring, 'disposed' | 'to'>
|
|
115
162
|
export type MotionDragAdapter = Omit<MotionDrag, 'disposed'>
|
|
116
|
-
export interface MotionSurfaceAdapter {
|
|
163
|
+
export interface MotionSurfaceAdapter extends Partial<MotionVisualAdapter> {
|
|
164
|
+
sensor?(kind: MotionSensorKind, options?: MotionSensorOptions): MotionSensorAdapter
|
|
117
165
|
/** The renderer borrows its host runtime and owns only this child's resources. */
|
|
118
166
|
use?(setup: (adapter: MotionSurfaceAdapter) => () => void): () => void
|
|
119
167
|
pointerFollow?(region: MotionRegionAdapter, options: MotionPointerOptions): MotionPointerAdapter
|
|
@@ -129,7 +177,9 @@ export interface MotionSurfaceAdapter {
|
|
|
129
177
|
decay?(velocity: { x?: number; y?: number }, options?: MotionDecayOptions): MotionPlayback
|
|
130
178
|
motionValue?(initial: number): MotionValueAdapter
|
|
131
179
|
springValue?(source: MotionValueAdapter, options?: MotionSpringOptions): MotionSpringAdapter
|
|
132
|
-
bind?(values:
|
|
180
|
+
bind?(values: {
|
|
181
|
+
[K in keyof MotionBindings]?: Pick<NonNullable<MotionBindings[K]>, 'get' | 'dispose'>
|
|
182
|
+
}): {
|
|
133
183
|
dispose(): void
|
|
134
184
|
}
|
|
135
185
|
drag?(options: MotionDragOptions): MotionDragAdapter
|
|
@@ -139,6 +189,11 @@ export interface MotionSurfaceAdapter {
|
|
|
139
189
|
frames: MotionScrollFrames,
|
|
140
190
|
options: MotionScrollOptions,
|
|
141
191
|
): Omit<MotionScrollLink, 'disposed'>
|
|
192
|
+
mapColor?(
|
|
193
|
+
source: Pick<MotionReadable, 'get' | 'dispose'>,
|
|
194
|
+
input: readonly number[],
|
|
195
|
+
output: readonly string[],
|
|
196
|
+
): Pick<MotionColor, 'get' | 'dispose'>
|
|
142
197
|
map?(
|
|
143
198
|
source: Pick<MotionReadable, 'get' | 'dispose'>,
|
|
144
199
|
input: readonly number[],
|
|
@@ -298,12 +353,12 @@ export function motionSurfaceAdapter(surface: MotionSurface): MotionSurfaceAdapt
|
|
|
298
353
|
const setups = new WeakMap<MotionSurface, Set<() => void | (() => void)>>()
|
|
299
354
|
type ValueState = {
|
|
300
355
|
binding: Binding
|
|
301
|
-
raw: Pick<MotionReadable, 'get' | 'dispose'>
|
|
356
|
+
raw: Pick<MotionReadable, 'get' | 'dispose'> | Pick<MotionColor, 'get' | 'dispose'>
|
|
302
357
|
input: boolean
|
|
303
358
|
depth: number
|
|
304
359
|
dependents: Set<Resource>
|
|
305
360
|
}
|
|
306
|
-
const values = new WeakMap<MotionReadable, ValueState>()
|
|
361
|
+
const values = new WeakMap<MotionReadable | MotionColor, ValueState>()
|
|
307
362
|
const dependencies = new WeakMap<Resource, Set<Set<Resource>>>()
|
|
308
363
|
const playbackOwners = new WeakMap<MotionPlayback, Binding>()
|
|
309
364
|
function depend(parent: ValueState, resource: Resource) {
|
|
@@ -363,8 +418,11 @@ function ownValue<T extends Pick<MotionReadable, 'get' | 'dispose'>>(
|
|
|
363
418
|
parent?: ValueState,
|
|
364
419
|
): T & MotionReadable {
|
|
365
420
|
const mapped = Object.assign({}, raw, {
|
|
366
|
-
to(
|
|
367
|
-
|
|
421
|
+
to(
|
|
422
|
+
input: readonly number[],
|
|
423
|
+
output: readonly (number | string)[],
|
|
424
|
+
options?: { clamp?: boolean },
|
|
425
|
+
) {
|
|
368
426
|
const state = values.get(value)!
|
|
369
427
|
if (state.depth >= 32)
|
|
370
428
|
throw new RangeError('Motion mappings support at most 32 derived levels.')
|
|
@@ -374,23 +432,52 @@ function ownValue<T extends Pick<MotionReadable, 'get' | 'dispose'>>(
|
|
|
374
432
|
input.length < 2 ||
|
|
375
433
|
input.length > 1024 ||
|
|
376
434
|
input.length !== output.length ||
|
|
377
|
-
!
|
|
435
|
+
!input.every(Number.isFinite) ||
|
|
436
|
+
!(
|
|
437
|
+
output.every(Number.isFinite) ||
|
|
438
|
+
output.every(
|
|
439
|
+
(value) => typeof value === 'string' && /^#[0-9a-f]{6}(?:[0-9a-f]{2})?$/i.test(value),
|
|
440
|
+
)
|
|
441
|
+
)
|
|
378
442
|
)
|
|
379
|
-
throw new TypeError(
|
|
443
|
+
throw new TypeError(
|
|
444
|
+
'A map needs 2–1024 finite input/output pairs of numbers or hex colors.',
|
|
445
|
+
)
|
|
380
446
|
if (
|
|
381
447
|
options &&
|
|
382
448
|
(Object.keys(options).some((key) => key !== 'clamp') ||
|
|
383
449
|
(options.clamp !== undefined && typeof options.clamp !== 'boolean'))
|
|
384
450
|
)
|
|
385
451
|
throw new TypeError('Mapping options support only a boolean clamp.')
|
|
386
|
-
|
|
452
|
+
if (typeof output[0] === 'string') {
|
|
453
|
+
if (options) throw new TypeError('Color maps use clamped ranges without options.')
|
|
454
|
+
if (!binding.adapter.mapColor) throw new Error('Color mappings are unavailable.')
|
|
455
|
+
const rawColor = binding.adapter.mapColor(raw, input, output as readonly string[])
|
|
456
|
+
const color = own(binding, rawColor)
|
|
457
|
+
values.set(color, {
|
|
458
|
+
binding,
|
|
459
|
+
raw: rawColor,
|
|
460
|
+
input: false,
|
|
461
|
+
depth: state.depth + 1,
|
|
462
|
+
dependents: new Set(),
|
|
463
|
+
})
|
|
464
|
+
depend(state, color)
|
|
465
|
+
return color
|
|
466
|
+
}
|
|
467
|
+
if (!binding.adapter.map) throw new Error('Numeric mappings are unavailable.')
|
|
468
|
+
return ownValue(
|
|
469
|
+
binding,
|
|
470
|
+
binding.adapter.map(raw, input, output as readonly number[], options),
|
|
471
|
+
false,
|
|
472
|
+
state,
|
|
473
|
+
)
|
|
387
474
|
},
|
|
388
475
|
})
|
|
389
476
|
// Preserve getters such as moving/paused; Object.assign would snapshot them.
|
|
390
477
|
const descriptors = Object.getOwnPropertyDescriptors(raw)
|
|
391
478
|
delete (descriptors as Record<string, PropertyDescriptor>).to
|
|
392
479
|
Object.defineProperties(mapped, descriptors)
|
|
393
|
-
const value = own(binding, mapped)
|
|
480
|
+
const value = own(binding, mapped) as T & MotionReadable
|
|
394
481
|
values.set(value, {
|
|
395
482
|
binding,
|
|
396
483
|
raw,
|
|
@@ -399,17 +486,50 @@ function ownValue<T extends Pick<MotionReadable, 'get' | 'dispose'>>(
|
|
|
399
486
|
dependents: new Set(),
|
|
400
487
|
})
|
|
401
488
|
if (parent) depend(parent, value)
|
|
402
|
-
return value
|
|
489
|
+
return value as T & MotionReadable
|
|
403
490
|
}
|
|
404
491
|
|
|
405
492
|
export function createMotionSurface(): MotionSurface {
|
|
493
|
+
// Validate the portable gravity contract before a renderer relinquishes scroll ownership.
|
|
494
|
+
// Trajectory compilation, velocity inheritance and playback remain entirely in Jolt.
|
|
495
|
+
const gravityFrames = (frames: readonly unknown[], options?: MotionOptions) => {
|
|
496
|
+
if (options?.type !== 'gravity') return
|
|
497
|
+
if (
|
|
498
|
+
frames.length < 1 ||
|
|
499
|
+
frames.length > 2 ||
|
|
500
|
+
frames.some(
|
|
501
|
+
(value, index) =>
|
|
502
|
+
!(index === 0 && frames.length === 2 && value === null) &&
|
|
503
|
+
(typeof value !== 'number' || !Number.isFinite(value)),
|
|
504
|
+
)
|
|
505
|
+
)
|
|
506
|
+
throw new TypeError('Gravity needs one fixed numeric landing position.')
|
|
507
|
+
if (
|
|
508
|
+
options.acceleration !== undefined &&
|
|
509
|
+
(!Number.isFinite(options.acceleration) || options.acceleration <= 0)
|
|
510
|
+
)
|
|
511
|
+
throw new RangeError('Gravity acceleration must be finite and positive.')
|
|
512
|
+
if (
|
|
513
|
+
options.restitution !== undefined &&
|
|
514
|
+
(!Number.isFinite(options.restitution) || options.restitution < 0 || options.restitution >= 1)
|
|
515
|
+
)
|
|
516
|
+
throw new RangeError('Gravity restitution must be in [0, 1).')
|
|
517
|
+
if (options.velocity !== undefined && !Number.isFinite(options.velocity))
|
|
518
|
+
throw new RangeError('Gravity velocity must be finite.')
|
|
519
|
+
if (
|
|
520
|
+
options.duration !== undefined ||
|
|
521
|
+
options.ease !== undefined ||
|
|
522
|
+
options.bounce !== undefined
|
|
523
|
+
)
|
|
524
|
+
throw new TypeError('Gravity timing comes from physics.')
|
|
525
|
+
}
|
|
406
526
|
const current = () => {
|
|
407
527
|
const binding = bindings.get(surface)
|
|
408
528
|
if (!binding?.valid)
|
|
409
529
|
throw new Error('Motion surface is unavailable. Wait for the component to mount/load.')
|
|
410
530
|
return binding
|
|
411
531
|
}
|
|
412
|
-
const source = (value: MotionReadable, binding: Binding, input = false) => {
|
|
532
|
+
const source = (value: MotionReadable | MotionColor, binding: Binding, input = false) => {
|
|
413
533
|
const state = values.get(value)
|
|
414
534
|
if (
|
|
415
535
|
!state ||
|
|
@@ -438,8 +558,171 @@ export function createMotionSurface(): MotionSurface {
|
|
|
438
558
|
get available() {
|
|
439
559
|
return Boolean(bindings.get(surface)?.valid)
|
|
440
560
|
},
|
|
441
|
-
animate
|
|
561
|
+
animate(values, options) {
|
|
562
|
+
if (options?.type === 'gravity') {
|
|
563
|
+
const keys = Object.keys(values)
|
|
564
|
+
if (!keys.length || keys.some((key) => key !== 'x' && key !== 'y'))
|
|
565
|
+
throw new TypeError('Gravity applies only to x/y or a numeric motion value.')
|
|
566
|
+
for (const value of Object.values(values))
|
|
567
|
+
gravityFrames(Array.isArray(value) ? value : [value], options)
|
|
568
|
+
}
|
|
569
|
+
return run((adapter) => adapter.animate(values, options))
|
|
570
|
+
},
|
|
442
571
|
set: (values) => run((adapter) => adapter.set(values)),
|
|
572
|
+
supports: (effect) => current().adapter.supports?.(effect) ?? false,
|
|
573
|
+
particles(options) {
|
|
574
|
+
const binding = current()
|
|
575
|
+
if (!binding.adapter.particles) throw new Error('Particles are unavailable.')
|
|
576
|
+
return own(binding, binding.adapter.particles(options))
|
|
577
|
+
},
|
|
578
|
+
confetti(options) {
|
|
579
|
+
const binding = current()
|
|
580
|
+
if (!binding.adapter.confetti) throw new Error('Confetti is unavailable.')
|
|
581
|
+
return own(binding, binding.adapter.confetti(options))
|
|
582
|
+
},
|
|
583
|
+
blur(options) {
|
|
584
|
+
const binding = current()
|
|
585
|
+
if (!binding.adapter.blur) throw new Error('Blur is unavailable.')
|
|
586
|
+
const raw = binding.adapter.blur(options)
|
|
587
|
+
return own(binding, {
|
|
588
|
+
animate: (amount: number, timing?: MotionOptions) => run(() => raw.animate(amount, timing)),
|
|
589
|
+
set: (amount: number) => raw.set(amount),
|
|
590
|
+
stop: () => raw.stop(),
|
|
591
|
+
snapshot: () => raw.snapshot(),
|
|
592
|
+
dispose: () => raw.dispose(),
|
|
593
|
+
})
|
|
594
|
+
},
|
|
595
|
+
shape(options) {
|
|
596
|
+
const binding = current()
|
|
597
|
+
if (!binding.adapter.shape) throw new Error('Shapes are unavailable.')
|
|
598
|
+
const raw = binding.adapter.shape(options)
|
|
599
|
+
return own(binding, {
|
|
600
|
+
animate: (
|
|
601
|
+
values: import('./experimental-surfaces.js').MotionShapeValues,
|
|
602
|
+
timing?: MotionOptions,
|
|
603
|
+
) => run(() => raw.animate(values, timing)),
|
|
604
|
+
set: (values: import('./experimental-surfaces.js').MotionShapeValues) => raw.set(values),
|
|
605
|
+
stop: () => raw.stop(),
|
|
606
|
+
dispose: () => raw.dispose(),
|
|
607
|
+
})
|
|
608
|
+
},
|
|
609
|
+
liquid(options) {
|
|
610
|
+
const binding = current()
|
|
611
|
+
if (!binding.adapter.liquid) throw new Error('Liquid images are unavailable.')
|
|
612
|
+
return own(binding, binding.adapter.liquid(options))
|
|
613
|
+
},
|
|
614
|
+
async imageEffect(name, options) {
|
|
615
|
+
const binding = current()
|
|
616
|
+
if (!binding.adapter.imageEffect) throw new Error('Image effects are unavailable.')
|
|
617
|
+
const raw = await binding.adapter.imageEffect(name, options, () => binding.valid)
|
|
618
|
+
if (!binding.valid) {
|
|
619
|
+
raw.stop()
|
|
620
|
+
throw new Error('Image presentation changed while preparing the effect.')
|
|
621
|
+
}
|
|
622
|
+
const control = run(() => raw)
|
|
623
|
+
// Keep the controlled playback accessors live while adding image-specific controls.
|
|
624
|
+
return Object.defineProperties(control, {
|
|
625
|
+
reverse: {
|
|
626
|
+
value: () => {
|
|
627
|
+
if (!binding.valid) throw new Error('Image presentation is disposed.')
|
|
628
|
+
;(raw as MotionPlayback & { reverse(): void }).reverse()
|
|
629
|
+
},
|
|
630
|
+
},
|
|
631
|
+
finish: {
|
|
632
|
+
value: () => {
|
|
633
|
+
if (!binding.valid) throw new Error('Image presentation is disposed.')
|
|
634
|
+
;(raw as MotionPlayback & { finish(): void }).finish()
|
|
635
|
+
},
|
|
636
|
+
},
|
|
637
|
+
}) as import('./experimental-surfaces.js').MotionImagePlayback
|
|
638
|
+
},
|
|
639
|
+
symbolEffect: (name, options) =>
|
|
640
|
+
run((adapter) => {
|
|
641
|
+
if (!adapter.symbolEffect) throw new Error('Icon effects are unavailable.')
|
|
642
|
+
return adapter.symbolEffect(name, options)
|
|
643
|
+
}),
|
|
644
|
+
followKeyboard(options) {
|
|
645
|
+
const binding = current()
|
|
646
|
+
if (!binding.adapter.followKeyboard) throw new Error('Keyboard following is unavailable.')
|
|
647
|
+
if (options?.offset !== undefined && (!Number.isFinite(options.offset) || options.offset < 0))
|
|
648
|
+
throw new RangeError('Keyboard offset must be finite and nonnegative.')
|
|
649
|
+
return own(binding, binding.adapter.followKeyboard(options))
|
|
650
|
+
},
|
|
651
|
+
gradient(options) {
|
|
652
|
+
const binding = current()
|
|
653
|
+
if (!binding.adapter.gradient) throw new Error('Gradients are unavailable.')
|
|
654
|
+
const raw = binding.adapter.gradient(options)
|
|
655
|
+
const children = new Set<MotionBinding>()
|
|
656
|
+
return own<Omit<MotionGradient, 'disposed'>>(binding, {
|
|
657
|
+
type: raw.type,
|
|
658
|
+
get suspended() {
|
|
659
|
+
return raw.suspended
|
|
660
|
+
},
|
|
661
|
+
animate: (values, options) => run(() => raw.animate(values, options)),
|
|
662
|
+
set: (values) => raw.set(values),
|
|
663
|
+
stop: () => raw.stop(),
|
|
664
|
+
suspend: () => raw.suspend(),
|
|
665
|
+
resume: () => raw.resume(),
|
|
666
|
+
bind(input) {
|
|
667
|
+
const parents = new Set<ValueState>()
|
|
668
|
+
const unwrap = (value: MotionReadable | MotionColor) => {
|
|
669
|
+
const state = source(value, binding)
|
|
670
|
+
parents.add(state)
|
|
671
|
+
return state.raw
|
|
672
|
+
}
|
|
673
|
+
const values = mapGradientBindings(
|
|
674
|
+
input,
|
|
675
|
+
(value) => unwrap(value) as Pick<MotionReadable, 'get' | 'dispose'>,
|
|
676
|
+
(value) => unwrap(value) as Pick<MotionColor, 'get' | 'dispose'>,
|
|
677
|
+
)
|
|
678
|
+
const linked = raw.bind(values)
|
|
679
|
+
const handle = own(binding, {
|
|
680
|
+
dispose() {
|
|
681
|
+
children.delete(handle)
|
|
682
|
+
linked.dispose()
|
|
683
|
+
},
|
|
684
|
+
})
|
|
685
|
+
children.add(handle)
|
|
686
|
+
for (const parent of parents) depend(parent, handle)
|
|
687
|
+
return handle
|
|
688
|
+
},
|
|
689
|
+
dispose() {
|
|
690
|
+
for (const child of [...children]) child.dispose()
|
|
691
|
+
raw.dispose()
|
|
692
|
+
},
|
|
693
|
+
})
|
|
694
|
+
},
|
|
695
|
+
shimmer(options) {
|
|
696
|
+
const binding = current()
|
|
697
|
+
if (!binding.adapter.shimmer) throw new Error('Shimmer is unavailable.')
|
|
698
|
+
return own(binding, binding.adapter.shimmer(options))
|
|
699
|
+
},
|
|
700
|
+
loader(options) {
|
|
701
|
+
const binding = current()
|
|
702
|
+
if (!binding.adapter.loader) throw new Error('Loaders are unavailable.')
|
|
703
|
+
return own(binding, binding.adapter.loader(options))
|
|
704
|
+
},
|
|
705
|
+
circular() {
|
|
706
|
+
const binding = current()
|
|
707
|
+
if (!binding.adapter.circular) throw new Error('Circular visibility is unavailable.')
|
|
708
|
+
const raw = binding.adapter.circular()
|
|
709
|
+
return own<Omit<MotionCircular, 'disposed'>>(binding, {
|
|
710
|
+
supported: raw.supported,
|
|
711
|
+
reveal: (options) => run(() => raw.reveal(options)),
|
|
712
|
+
conceal: (options) => run(() => raw.conceal(options)),
|
|
713
|
+
dispose: () => raw.dispose(),
|
|
714
|
+
})
|
|
715
|
+
},
|
|
716
|
+
animateText: (options) =>
|
|
717
|
+
run((adapter) => {
|
|
718
|
+
if (!adapter.animateText) throw new Error('Text entrance is unavailable.')
|
|
719
|
+
return adapter.animateText(options)
|
|
720
|
+
}),
|
|
721
|
+
rollTo: (value, options) =>
|
|
722
|
+
run((adapter) => {
|
|
723
|
+
if (!adapter.rollTo) throw new Error('Rolling text is unavailable.')
|
|
724
|
+
return adapter.rollTo(value, options)
|
|
725
|
+
}),
|
|
443
726
|
use(setup) {
|
|
444
727
|
return surface.onAvailable(() => {
|
|
445
728
|
const binding = current()
|
|
@@ -466,6 +749,69 @@ export function createMotionSurface(): MotionSurface {
|
|
|
466
749
|
return binding.adapter.use?.(start) ?? start(binding.adapter)
|
|
467
750
|
})
|
|
468
751
|
},
|
|
752
|
+
sensor(kind, options) {
|
|
753
|
+
const binding = current()
|
|
754
|
+
if (!binding.adapter.sensor) throw new Error('Sensor input is unavailable.')
|
|
755
|
+
const raw = binding.adapter.sensor(kind, options)
|
|
756
|
+
const values: MotionReadable[] = []
|
|
757
|
+
const wrap = (value: Pick<MotionValueAdapter, 'get' | 'dispose'>) => {
|
|
758
|
+
const result = ownValue(binding, value, false)
|
|
759
|
+
values.push(result)
|
|
760
|
+
return result
|
|
761
|
+
}
|
|
762
|
+
const x = wrap(raw.x),
|
|
763
|
+
y = wrap(raw.y),
|
|
764
|
+
z = wrap(raw.z)
|
|
765
|
+
const quaternion = raw.quaternion && {
|
|
766
|
+
x: wrap(raw.quaternion.x),
|
|
767
|
+
y: wrap(raw.quaternion.y),
|
|
768
|
+
z: wrap(raw.quaternion.z),
|
|
769
|
+
w: wrap(raw.quaternion.w),
|
|
770
|
+
}
|
|
771
|
+
let disposed = false
|
|
772
|
+
const assert = () => {
|
|
773
|
+
if (disposed || !binding.valid) throw new Error('Sensor presentation is disposed.')
|
|
774
|
+
}
|
|
775
|
+
return own(binding, {
|
|
776
|
+
kind: raw.kind,
|
|
777
|
+
x,
|
|
778
|
+
y,
|
|
779
|
+
z,
|
|
780
|
+
quaternion,
|
|
781
|
+
get status() {
|
|
782
|
+
return disposed ? ('disposed' as const) : raw.status
|
|
783
|
+
},
|
|
784
|
+
get available() {
|
|
785
|
+
return !disposed && raw.available
|
|
786
|
+
},
|
|
787
|
+
get paused() {
|
|
788
|
+
return raw.paused
|
|
789
|
+
},
|
|
790
|
+
pause() {
|
|
791
|
+
assert()
|
|
792
|
+
raw.pause()
|
|
793
|
+
},
|
|
794
|
+
resume() {
|
|
795
|
+
assert()
|
|
796
|
+
raw.resume()
|
|
797
|
+
},
|
|
798
|
+
recenter() {
|
|
799
|
+
assert()
|
|
800
|
+
raw.recenter()
|
|
801
|
+
},
|
|
802
|
+
async requestPermission() {
|
|
803
|
+
assert()
|
|
804
|
+
const result = await raw.requestPermission()
|
|
805
|
+
return disposed || !binding.valid ? ('unavailable' as const) : result
|
|
806
|
+
},
|
|
807
|
+
snapshot: () => raw.snapshot(),
|
|
808
|
+
dispose() {
|
|
809
|
+
disposed = true
|
|
810
|
+
for (const value of values) value.dispose()
|
|
811
|
+
raw.dispose()
|
|
812
|
+
},
|
|
813
|
+
})
|
|
814
|
+
},
|
|
469
815
|
pointerFollow(region, options = {}) {
|
|
470
816
|
const binding = current()
|
|
471
817
|
validatePointer(options)
|
|
@@ -551,6 +897,7 @@ export function createMotionSurface(): MotionSurface {
|
|
|
551
897
|
}
|
|
552
898
|
},
|
|
553
899
|
animateValue(value, frames, options) {
|
|
900
|
+
gravityFrames(Array.isArray(frames) ? frames : [frames], options)
|
|
554
901
|
const binding = current()
|
|
555
902
|
const parent = source(value, binding, true)
|
|
556
903
|
if (!binding.adapter.animateValue) throw new Error('Scalar playback is unavailable.')
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { choiceKey, validateChoices, type ChoiceOption, type ChoiceValue } from './choice.js'
|
|
2
|
+
|
|
3
|
+
export function validateMultiSelection(
|
|
4
|
+
options: readonly ChoiceOption[],
|
|
5
|
+
values: readonly ChoiceValue[],
|
|
6
|
+
max?: number,
|
|
7
|
+
) {
|
|
8
|
+
validateChoices(options, null)
|
|
9
|
+
if (max !== undefined && (!Number.isInteger(max) || max < 1))
|
|
10
|
+
throw new RangeError('maxSelected must be a positive integer.')
|
|
11
|
+
const keys = values.map(choiceKey)
|
|
12
|
+
if (new Set(keys).size !== keys.length) throw new RangeError('Selected values must be unique.')
|
|
13
|
+
if (values.some((value) => !options.some((option) => option.value === value)))
|
|
14
|
+
throw new RangeError('Each selected value needs a matching option.')
|
|
15
|
+
if (max !== undefined && values.length > max)
|
|
16
|
+
throw new RangeError('Selection exceeds maxSelected.')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function toggleMultiSelection(
|
|
20
|
+
options: readonly ChoiceOption[],
|
|
21
|
+
values: readonly ChoiceValue[],
|
|
22
|
+
value: ChoiceValue,
|
|
23
|
+
max?: number,
|
|
24
|
+
) {
|
|
25
|
+
validateMultiSelection(options, values, max)
|
|
26
|
+
const option = options.find((item) => item.value === value)
|
|
27
|
+
if (!option || option.disabled) return null
|
|
28
|
+
if (values.includes(value)) return values.filter((item) => item !== value)
|
|
29
|
+
return max !== undefined && values.length >= max ? null : [...values, value]
|
|
30
|
+
}
|