@getcortexlabs/mavis-core 0.1.0-alpha.4 → 0.1.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/app-icons.d.ts +27 -0
- package/dist/app-icons.d.ts.map +1 -0
- package/dist/app-icons.js +42 -0
- package/dist/app-icons.js.map +1 -0
- package/dist/capabilities.d.ts +119 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +144 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/combobox.d.ts +42 -0
- package/dist/combobox.d.ts.map +1 -0
- package/dist/combobox.js +159 -0
- package/dist/combobox.js.map +1 -0
- package/dist/contracts.d.ts +1261 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +249 -0
- package/dist/contracts.js.map +1 -0
- package/dist/date.d.ts +96 -0
- package/dist/date.d.ts.map +1 -0
- package/dist/date.js +235 -0
- package/dist/date.js.map +1 -0
- package/dist/experimental-playback.d.ts +63 -0
- package/dist/experimental-playback.d.ts.map +1 -0
- package/dist/experimental-playback.js +46 -0
- package/dist/experimental-playback.js.map +1 -0
- package/dist/experimental-regions.d.ts +154 -0
- package/dist/experimental-regions.d.ts.map +1 -0
- package/dist/experimental-regions.js +440 -0
- package/dist/experimental-regions.js.map +1 -0
- package/dist/experimental.d.ts +42 -3
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +200 -30
- package/dist/experimental.js.map +1 -1
- package/dist/files.d.ts +87 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +328 -0
- package/dist/files.js.map +1 -0
- package/dist/form.d.ts +39 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +170 -0
- package/dist/form.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/link.d.ts +12 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +19 -0
- package/dist/link.js.map +1 -0
- package/dist/motion.d.ts +29 -4
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +55 -3
- package/dist/motion.js.map +1 -1
- package/dist/navigation.d.ts +22 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +54 -0
- package/dist/navigation.js.map +1 -0
- package/dist/responsive.d.ts +18 -0
- package/dist/responsive.d.ts.map +1 -0
- package/dist/responsive.js +35 -0
- package/dist/responsive.js.map +1 -0
- package/dist/theme/themes.js +3 -3
- package/dist/theme/themes.js.map +1 -1
- package/dist/theme/types.d.ts +12 -3
- package/dist/theme/types.d.ts.map +1 -1
- package/dist/vue/combobox.d.ts +155 -0
- package/dist/vue/combobox.d.ts.map +1 -0
- package/dist/vue/combobox.js +195 -0
- package/dist/vue/combobox.js.map +1 -0
- package/dist/vue/component-props.d.ts +2176 -0
- package/dist/vue/component-props.d.ts.map +1 -0
- package/dist/vue/component-props.js +18 -0
- package/dist/vue/component-props.js.map +1 -0
- package/dist/vue/contracts.d.ts +18 -0
- package/dist/vue/contracts.d.ts.map +1 -0
- package/dist/vue/contracts.js +24 -0
- package/dist/vue/contracts.js.map +1 -0
- package/dist/vue/date-calendar.d.ts +64 -0
- package/dist/vue/date-calendar.d.ts.map +1 -0
- package/dist/vue/date-calendar.js +65 -0
- package/dist/vue/date-calendar.js.map +1 -0
- package/dist/vue/date-picker.d.ts +965 -0
- package/dist/vue/date-picker.d.ts.map +1 -0
- package/dist/vue/date-picker.js +341 -0
- package/dist/vue/date-picker.js.map +1 -0
- package/dist/vue/date-props.d.ts +263 -0
- package/dist/vue/date-props.d.ts.map +1 -0
- package/dist/vue/date-props.js +77 -0
- package/dist/vue/date-props.js.map +1 -0
- package/dist/vue/files.d.ts +53 -0
- package/dist/vue/files.d.ts.map +1 -0
- package/dist/vue/files.js +40 -0
- package/dist/vue/files.js.map +1 -0
- package/dist/vue/forms.d.ts +4 -0
- package/dist/vue/forms.d.ts.map +1 -0
- package/dist/vue/forms.js +15 -0
- package/dist/vue/forms.js.map +1 -0
- package/dist/vue/global-components.d.ts +40 -2
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +15 -3
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +12 -2
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/inline-content.d.ts +3 -1
- package/dist/vue/inline-content.d.ts.map +1 -1
- package/dist/vue/layout-context.d.ts +4 -2
- package/dist/vue/layout-context.d.ts.map +1 -1
- package/dist/vue/layout-context.js +7 -2
- package/dist/vue/layout-context.js.map +1 -1
- package/dist/vue/props.d.ts +1392 -496
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +39 -116
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/reveal-state.d.ts +18 -0
- package/dist/vue/reveal-state.d.ts.map +1 -0
- package/dist/vue/reveal-state.js +76 -0
- package/dist/vue/reveal-state.js.map +1 -0
- package/dist/vue/theme.d.ts +42 -0
- package/dist/vue/theme.d.ts.map +1 -1
- package/dist/vue/workflow-props.d.ts +110 -0
- package/dist/vue/workflow-props.d.ts.map +1 -0
- package/dist/vue/workflow-props.js +37 -0
- package/dist/vue/workflow-props.js.map +1 -0
- package/dist/vue/workflows.d.ts +267 -0
- package/dist/vue/workflows.d.ts.map +1 -0
- package/dist/vue/workflows.js +200 -0
- package/dist/vue/workflows.js.map +1 -0
- package/package.json +1 -1
- package/src/app-icons.ts +57 -0
- package/src/capabilities.ts +147 -0
- package/src/combobox.ts +198 -0
- package/src/contracts.ts +305 -0
- package/src/date.ts +280 -0
- package/src/experimental-playback.ts +115 -0
- package/src/experimental-regions.ts +614 -0
- package/src/experimental.ts +239 -25
- package/src/files.ts +408 -0
- package/src/form.ts +190 -0
- package/src/index.ts +23 -1
- package/src/link.ts +28 -0
- package/src/motion.ts +61 -3
- package/src/navigation.ts +61 -0
- package/src/responsive.ts +61 -0
- package/src/theme/themes.ts +3 -3
- package/src/theme/types.ts +13 -1
- package/src/vue/combobox.ts +238 -0
- package/src/vue/component-props.ts +24 -0
- package/src/vue/contracts.ts +39 -0
- package/src/vue/date-calendar.ts +76 -0
- package/src/vue/date-picker.ts +414 -0
- package/src/vue/date-props.ts +84 -0
- package/src/vue/files.ts +53 -0
- package/src/vue/forms.ts +20 -0
- package/src/vue/global-components.ts +49 -3
- package/src/vue/index.ts +19 -3
- package/src/vue/layout-context.ts +10 -3
- package/src/vue/props.ts +57 -127
- package/src/vue/reveal-state.ts +83 -0
- package/src/vue/workflow-props.ts +41 -0
- package/src/vue/workflows.ts +257 -0
package/src/experimental.ts
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
controlledMotionPlayback,
|
|
3
|
+
motionPlaybackAdapter,
|
|
4
|
+
type MotionControlledPlayback,
|
|
5
|
+
type MotionValueOptions,
|
|
6
|
+
type MotionDecayOptions,
|
|
7
|
+
} from './experimental-playback.js'
|
|
8
|
+
export * from './experimental-playback.js'
|
|
1
9
|
/** Experimental, single-surface motion contract. No platform objects cross this boundary. */
|
|
10
|
+
import {
|
|
11
|
+
regionState,
|
|
12
|
+
validatePointer,
|
|
13
|
+
type MotionRegion,
|
|
14
|
+
type MotionRegionAdapter,
|
|
15
|
+
type MotionPointerOptions,
|
|
16
|
+
type MotionPointer,
|
|
17
|
+
type MotionPointerAdapter,
|
|
18
|
+
} from './experimental-regions.js'
|
|
19
|
+
export * from './experimental-regions.js'
|
|
2
20
|
export type MotionValues = Partial<
|
|
3
21
|
Record<'scale' | 'scaleX' | 'scaleY' | 'x' | 'y' | 'rotate' | 'opacity', number>
|
|
4
22
|
>
|
|
@@ -8,6 +26,7 @@ export interface MotionOptions {
|
|
|
8
26
|
duration?: number
|
|
9
27
|
bounce?: number
|
|
10
28
|
ease?: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut'
|
|
29
|
+
delay?: number
|
|
11
30
|
}
|
|
12
31
|
export interface MotionPlayback {
|
|
13
32
|
readonly finished: Promise<boolean>
|
|
@@ -15,10 +34,24 @@ export interface MotionPlayback {
|
|
|
15
34
|
}
|
|
16
35
|
export interface MotionSurface {
|
|
17
36
|
readonly available: boolean
|
|
18
|
-
animate(values: MotionFrames, options?: MotionOptions):
|
|
37
|
+
animate(values: MotionFrames, options?: MotionOptions): MotionControlledPlayback
|
|
19
38
|
set(values: MotionValues): MotionPlayback
|
|
20
39
|
/** Runs once per mount/load. Its resources belong to that presentation. */
|
|
21
40
|
onAvailable(setup: () => void | (() => void)): () => void
|
|
41
|
+
/** A child owner, recreated on mount/load. Late work must use the supplied child. */
|
|
42
|
+
use(setup: (motion: MotionSurface) => void | (() => void)): () => void
|
|
43
|
+
pointerFollow(region: MotionRegion, options?: MotionPointerOptions): MotionPointer
|
|
44
|
+
animateValue(
|
|
45
|
+
value: MotionValue,
|
|
46
|
+
frames: number | readonly (number | null)[],
|
|
47
|
+
options?: MotionValueOptions,
|
|
48
|
+
): MotionControlledPlayback
|
|
49
|
+
stopValue(value: MotionValue, options?: { layer?: string }): void
|
|
50
|
+
playbackProgress(playback: MotionControlledPlayback): MotionReadable
|
|
51
|
+
decay(
|
|
52
|
+
velocity: { x?: number; y?: number },
|
|
53
|
+
options?: MotionDecayOptions,
|
|
54
|
+
): MotionControlledPlayback
|
|
22
55
|
motionValue(initial: number): MotionValue
|
|
23
56
|
springValue(source: MotionValue, options?: MotionSpringOptions): MotionSpring
|
|
24
57
|
bind(values: MotionBindings): MotionBinding
|
|
@@ -65,7 +98,9 @@ export type MotionBindings = Partial<Record<keyof MotionValues, MotionReadable>>
|
|
|
65
98
|
export interface MotionDragOptions {
|
|
66
99
|
axis: 'x' | 'y'
|
|
67
100
|
bounds?: { left?: number; right?: number; top?: number; bottom?: number }
|
|
68
|
-
snap
|
|
101
|
+
snap?: { x?: readonly number[]; y?: readonly number[] }
|
|
102
|
+
friction?: number
|
|
103
|
+
onRelease?: (event: { x: number; y: number; velocityX: number; velocityY: number }) => void
|
|
69
104
|
}
|
|
70
105
|
export interface MotionDrag extends MotionBinding {
|
|
71
106
|
readonly dragging: boolean
|
|
@@ -79,8 +114,19 @@ export type MotionValueAdapter = Pick<MotionValue, 'get' | 'set' | 'dispose'>
|
|
|
79
114
|
export type MotionSpringAdapter = Omit<MotionSpring, 'disposed' | 'to'>
|
|
80
115
|
export type MotionDragAdapter = Omit<MotionDrag, 'disposed'>
|
|
81
116
|
export interface MotionSurfaceAdapter {
|
|
117
|
+
/** The renderer borrows its host runtime and owns only this child's resources. */
|
|
118
|
+
use?(setup: (adapter: MotionSurfaceAdapter) => () => void): () => void
|
|
119
|
+
pointerFollow?(region: MotionRegionAdapter, options: MotionPointerOptions): MotionPointerAdapter
|
|
82
120
|
animate(values: MotionFrames, options?: MotionOptions): MotionPlayback
|
|
83
121
|
set(values: MotionValues): MotionPlayback
|
|
122
|
+
animateValue?(
|
|
123
|
+
value: MotionValueAdapter,
|
|
124
|
+
frames: number | readonly (number | null)[],
|
|
125
|
+
options?: MotionValueOptions,
|
|
126
|
+
): MotionPlayback
|
|
127
|
+
stopValue?(value: MotionValueAdapter, options?: { layer?: string }): void
|
|
128
|
+
playbackProgress?(playback: MotionPlayback): Pick<MotionReadable, 'get' | 'dispose'>
|
|
129
|
+
decay?(velocity: { x?: number; y?: number }, options?: MotionDecayOptions): MotionPlayback
|
|
84
130
|
motionValue?(initial: number): MotionValueAdapter
|
|
85
131
|
springValue?(source: MotionValueAdapter, options?: MotionSpringOptions): MotionSpringAdapter
|
|
86
132
|
bind?(values: Partial<Record<keyof MotionValues, Pick<MotionReadable, 'get' | 'dispose'>>>): {
|
|
@@ -128,6 +174,11 @@ type ScrollState = {
|
|
|
128
174
|
}
|
|
129
175
|
const scrollSources = new WeakMap<MotionScrollSource, ScrollState | undefined>()
|
|
130
176
|
const scrollSetups = new WeakMap<MotionScrollSource, Set<() => void | (() => void)>>()
|
|
177
|
+
export function motionScrollAdapter(source: MotionScrollSource): MotionScrollAdapter {
|
|
178
|
+
const state = scrollSources.get(source)
|
|
179
|
+
if (!state) throw new Error('Scroll source is unavailable.')
|
|
180
|
+
return state.adapter
|
|
181
|
+
}
|
|
131
182
|
|
|
132
183
|
export function createMotionScrollSource(): MotionScrollSource {
|
|
133
184
|
const source: MotionScrollSource = {
|
|
@@ -233,9 +284,17 @@ type Binding = {
|
|
|
233
284
|
adapter: MotionSurfaceAdapter
|
|
234
285
|
active: Set<MotionPlayback>
|
|
235
286
|
resources: Set<Resource>
|
|
287
|
+
cleanup: Set<() => void>
|
|
236
288
|
valid: boolean
|
|
289
|
+
context: object
|
|
237
290
|
}
|
|
238
291
|
const bindings = new WeakMap<MotionSurface, Binding | undefined>()
|
|
292
|
+
/** Renderer bridge; the identity has no platform object in it. */
|
|
293
|
+
export function motionSurfaceAdapter(surface: MotionSurface): MotionSurfaceAdapter {
|
|
294
|
+
const binding = bindings.get(surface)
|
|
295
|
+
if (!binding?.valid) throw new Error('Motion surface is unavailable.')
|
|
296
|
+
return binding.adapter
|
|
297
|
+
}
|
|
239
298
|
const setups = new WeakMap<MotionSurface, Set<() => void | (() => void)>>()
|
|
240
299
|
type ValueState = {
|
|
241
300
|
binding: Binding
|
|
@@ -246,6 +305,7 @@ type ValueState = {
|
|
|
246
305
|
}
|
|
247
306
|
const values = new WeakMap<MotionReadable, ValueState>()
|
|
248
307
|
const dependencies = new WeakMap<Resource, Set<Set<Resource>>>()
|
|
308
|
+
const playbackOwners = new WeakMap<MotionPlayback, Binding>()
|
|
249
309
|
function depend(parent: ValueState, resource: Resource) {
|
|
250
310
|
parent.dependents.add(resource)
|
|
251
311
|
let groups = dependencies.get(resource)
|
|
@@ -266,9 +326,21 @@ function own<T extends Resource>(binding: Binding, raw: T): T & MotionBinding {
|
|
|
266
326
|
for (const group of dependencies.get(handle) ?? []) group.delete(handle)
|
|
267
327
|
dependencies.delete(handle)
|
|
268
328
|
const state = values.get(handle as unknown as MotionReadable)
|
|
269
|
-
|
|
329
|
+
const errors: unknown[] = []
|
|
330
|
+
for (const dependent of state?.dependents ?? []) {
|
|
331
|
+
try {
|
|
332
|
+
dependent.dispose()
|
|
333
|
+
} catch (error) {
|
|
334
|
+
errors.push(error)
|
|
335
|
+
}
|
|
336
|
+
}
|
|
270
337
|
state?.dependents.clear()
|
|
271
|
-
|
|
338
|
+
try {
|
|
339
|
+
target.dispose()
|
|
340
|
+
} catch (error) {
|
|
341
|
+
errors.push(error)
|
|
342
|
+
}
|
|
343
|
+
if (errors.length) throw new AggregateError(errors, 'Motion resource cleanup failed.')
|
|
272
344
|
}
|
|
273
345
|
if (disposed || !binding.valid) throw new Error('This motion resource is disposed.')
|
|
274
346
|
const value = Reflect.get(target, key, target)
|
|
@@ -339,21 +411,28 @@ export function createMotionSurface(): MotionSurface {
|
|
|
339
411
|
}
|
|
340
412
|
const source = (value: MotionReadable, binding: Binding, input = false) => {
|
|
341
413
|
const state = values.get(value)
|
|
342
|
-
if (
|
|
414
|
+
if (
|
|
415
|
+
!state ||
|
|
416
|
+
state.binding.context !== binding.context ||
|
|
417
|
+
value.disposed ||
|
|
418
|
+
(input && !state.input)
|
|
419
|
+
)
|
|
343
420
|
throw new TypeError('Use a live value from this surface and presentation.')
|
|
344
421
|
return state
|
|
345
422
|
}
|
|
346
|
-
const run = (
|
|
423
|
+
const run = (
|
|
424
|
+
invoke: (adapter: MotionSurfaceAdapter) => MotionPlayback,
|
|
425
|
+
): MotionControlledPlayback => {
|
|
347
426
|
const binding = current()
|
|
348
427
|
const playback = invoke(binding.adapter)
|
|
349
428
|
binding.active.add(playback)
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
finished: playback.finished,
|
|
353
|
-
stop() {
|
|
354
|
-
if (binding.valid) playback.stop()
|
|
355
|
-
},
|
|
429
|
+
const forget = () => {
|
|
430
|
+
binding.active.delete(playback)
|
|
356
431
|
}
|
|
432
|
+
void playback.finished.then(forget, forget)
|
|
433
|
+
const handle = controlledMotionPlayback(playback, () => binding.valid)
|
|
434
|
+
playbackOwners.set(handle, binding)
|
|
435
|
+
return handle
|
|
357
436
|
}
|
|
358
437
|
const surface: MotionSurface = {
|
|
359
438
|
get available() {
|
|
@@ -361,6 +440,59 @@ export function createMotionSurface(): MotionSurface {
|
|
|
361
440
|
},
|
|
362
441
|
animate: (values, options) => run((adapter) => adapter.animate(values, options)),
|
|
363
442
|
set: (values) => run((adapter) => adapter.set(values)),
|
|
443
|
+
use(setup) {
|
|
444
|
+
return surface.onAvailable(() => {
|
|
445
|
+
const binding = current()
|
|
446
|
+
const start = (adapter: MotionSurfaceAdapter) => {
|
|
447
|
+
const child = createMotionSurface()
|
|
448
|
+
const unbind = bindMotionSurface(child, adapter, binding.context)
|
|
449
|
+
let cleanup: void | (() => void)
|
|
450
|
+
try {
|
|
451
|
+
cleanup = setup(child)
|
|
452
|
+
if (cleanup !== undefined && typeof cleanup !== 'function')
|
|
453
|
+
throw new TypeError('Motion setup must return a cleanup function, not a promise.')
|
|
454
|
+
} catch (error) {
|
|
455
|
+
unbind()
|
|
456
|
+
throw error
|
|
457
|
+
}
|
|
458
|
+
return () => {
|
|
459
|
+
try {
|
|
460
|
+
cleanup?.()
|
|
461
|
+
} finally {
|
|
462
|
+
unbind()
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return binding.adapter.use?.(start) ?? start(binding.adapter)
|
|
467
|
+
})
|
|
468
|
+
},
|
|
469
|
+
pointerFollow(region, options = {}) {
|
|
470
|
+
const binding = current()
|
|
471
|
+
validatePointer(options)
|
|
472
|
+
const state = regionState(region)
|
|
473
|
+
if (!binding.adapter.pointerFollow) throw new Error('Pointer input is unavailable.')
|
|
474
|
+
const raw = binding.adapter.pointerFollow(state.adapter, options)
|
|
475
|
+
const x = ownValue(binding, raw.x, false)
|
|
476
|
+
const y = ownValue(binding, raw.y, false)
|
|
477
|
+
const control = own(binding, {
|
|
478
|
+
x,
|
|
479
|
+
y,
|
|
480
|
+
execution: raw.execution,
|
|
481
|
+
get active() {
|
|
482
|
+
return raw.active
|
|
483
|
+
},
|
|
484
|
+
update: (state: { disabled: boolean }) => raw.update(state),
|
|
485
|
+
refresh: () => raw.refresh(),
|
|
486
|
+
dispose() {
|
|
487
|
+
state.resources.delete(control)
|
|
488
|
+
x.dispose()
|
|
489
|
+
y.dispose()
|
|
490
|
+
raw.dispose()
|
|
491
|
+
},
|
|
492
|
+
})
|
|
493
|
+
state.resources.add(control)
|
|
494
|
+
return control
|
|
495
|
+
},
|
|
364
496
|
onAvailable(setup) {
|
|
365
497
|
let cleanup: (() => void) | undefined
|
|
366
498
|
const invoke = () => {
|
|
@@ -382,20 +514,31 @@ export function createMotionSurface(): MotionSurface {
|
|
|
382
514
|
cleanup = () => {
|
|
383
515
|
if (disposed) return
|
|
384
516
|
disposed = true
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
517
|
+
binding.cleanup.delete(cleanup!)
|
|
518
|
+
const errors: unknown[] = []
|
|
519
|
+
for (const dispose of [
|
|
520
|
+
() => release?.(),
|
|
521
|
+
...resources.reverse().map((resource) => () => resource.dispose()),
|
|
522
|
+
...playback.map((handle) => () => {
|
|
523
|
+
if (binding.active.has(handle)) handle.stop()
|
|
524
|
+
}),
|
|
525
|
+
]) {
|
|
526
|
+
try {
|
|
527
|
+
dispose()
|
|
528
|
+
} catch (error) {
|
|
529
|
+
errors.push(error)
|
|
530
|
+
}
|
|
391
531
|
}
|
|
532
|
+
cleanup = undefined
|
|
533
|
+
if (errors.length) throw new AggregateError(errors, 'Motion setup cleanup failed.')
|
|
392
534
|
}
|
|
535
|
+
binding.cleanup.add(cleanup)
|
|
393
536
|
return cleanup
|
|
394
537
|
}
|
|
395
538
|
setups.get(surface)!.add(invoke)
|
|
396
539
|
if (surface.available) {
|
|
397
540
|
try {
|
|
398
|
-
|
|
541
|
+
invoke()
|
|
399
542
|
} catch (error) {
|
|
400
543
|
setups.get(surface)!.delete(invoke)
|
|
401
544
|
throw error
|
|
@@ -407,6 +550,46 @@ export function createMotionSurface(): MotionSurface {
|
|
|
407
550
|
cleanup = undefined
|
|
408
551
|
}
|
|
409
552
|
},
|
|
553
|
+
animateValue(value, frames, options) {
|
|
554
|
+
const binding = current()
|
|
555
|
+
const parent = source(value, binding, true)
|
|
556
|
+
if (!binding.adapter.animateValue) throw new Error('Scalar playback is unavailable.')
|
|
557
|
+
const handle = run((adapter) =>
|
|
558
|
+
adapter.animateValue!(parent.raw as MotionValueAdapter, frames, options),
|
|
559
|
+
)
|
|
560
|
+
const dependent = { dispose: () => handle.stop() }
|
|
561
|
+
depend(parent, dependent)
|
|
562
|
+
const forget = () => {
|
|
563
|
+
parent.dependents.delete(dependent)
|
|
564
|
+
dependencies.delete(dependent)
|
|
565
|
+
}
|
|
566
|
+
void handle.finished.then(forget, forget)
|
|
567
|
+
return handle
|
|
568
|
+
},
|
|
569
|
+
stopValue(value, options) {
|
|
570
|
+
const binding = current()
|
|
571
|
+
const parent = source(value, binding, true)
|
|
572
|
+
if (!binding.adapter.stopValue) throw new Error('Scalar playback is unavailable.')
|
|
573
|
+
binding.adapter.stopValue(parent.raw as MotionValueAdapter, options)
|
|
574
|
+
},
|
|
575
|
+
playbackProgress(playback) {
|
|
576
|
+
const binding = current()
|
|
577
|
+
const owner = playbackOwners.get(playback)
|
|
578
|
+
if (!owner?.valid || owner.context !== binding.context)
|
|
579
|
+
throw new TypeError('Use playback from this surface and presentation.')
|
|
580
|
+
if (!binding.adapter.playbackProgress) throw new Error('Playback progress is unavailable.')
|
|
581
|
+
return ownValue(
|
|
582
|
+
binding,
|
|
583
|
+
binding.adapter.playbackProgress(motionPlaybackAdapter(playback)),
|
|
584
|
+
false,
|
|
585
|
+
)
|
|
586
|
+
},
|
|
587
|
+
decay(velocity, options) {
|
|
588
|
+
return run((adapter) => {
|
|
589
|
+
if (!adapter.decay) throw new Error('Decay playback is unavailable.')
|
|
590
|
+
return adapter.decay(velocity, options)
|
|
591
|
+
})
|
|
592
|
+
},
|
|
410
593
|
motionValue(initial) {
|
|
411
594
|
const binding = current()
|
|
412
595
|
if (!binding.adapter.motionValue) throw new Error('Continuous motion is unavailable.')
|
|
@@ -471,23 +654,54 @@ export function createMotionSurface(): MotionSurface {
|
|
|
471
654
|
export function bindMotionSurface(
|
|
472
655
|
surface: MotionSurface,
|
|
473
656
|
adapter: MotionSurfaceAdapter,
|
|
657
|
+
context: object = {},
|
|
474
658
|
): () => void {
|
|
475
659
|
if (!bindings.has(surface)) throw new TypeError('Use createMotionSurface() to declare a surface.')
|
|
476
660
|
const invalidate = (binding: Binding) => {
|
|
477
661
|
binding.valid = false
|
|
478
|
-
|
|
662
|
+
const errors: unknown[] = []
|
|
663
|
+
for (const cleanup of [...binding.cleanup].reverse()) {
|
|
664
|
+
try {
|
|
665
|
+
cleanup()
|
|
666
|
+
} catch (error) {
|
|
667
|
+
errors.push(error)
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
binding.cleanup.clear()
|
|
671
|
+
for (const playback of binding.active) {
|
|
672
|
+
try {
|
|
673
|
+
playback.stop()
|
|
674
|
+
} catch (error) {
|
|
675
|
+
errors.push(error)
|
|
676
|
+
}
|
|
677
|
+
}
|
|
479
678
|
binding.active.clear()
|
|
480
|
-
for (const resource of [...binding.resources].reverse())
|
|
679
|
+
for (const resource of [...binding.resources].reverse()) {
|
|
680
|
+
try {
|
|
681
|
+
resource.dispose()
|
|
682
|
+
} catch (error) {
|
|
683
|
+
errors.push(error)
|
|
684
|
+
}
|
|
685
|
+
}
|
|
481
686
|
binding.resources.clear()
|
|
687
|
+
if (errors.length) throw new AggregateError(errors, 'Motion cleanup failed.')
|
|
482
688
|
}
|
|
483
689
|
const previous = bindings.get(surface)
|
|
484
690
|
if (previous) invalidate(previous)
|
|
485
|
-
const binding: Binding = {
|
|
691
|
+
const binding: Binding = {
|
|
692
|
+
adapter,
|
|
693
|
+
active: new Set(),
|
|
694
|
+
resources: new Set(),
|
|
695
|
+
cleanup: new Set(),
|
|
696
|
+
valid: true,
|
|
697
|
+
context,
|
|
698
|
+
}
|
|
486
699
|
bindings.set(surface, binding)
|
|
487
700
|
try {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
701
|
+
// A setup can register a child while the surface is already available. That
|
|
702
|
+
// child starts immediately; a live Set iteration would run it a second time.
|
|
703
|
+
for (const setup of [...setups.get(surface)!]) {
|
|
704
|
+
setup()
|
|
491
705
|
}
|
|
492
706
|
} catch (error) {
|
|
493
707
|
invalidate(binding)
|