@rafaelaugusto/jolt 0.1.0-rc.12 → 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/core/circle-math.d.ts.map +1 -1
- package/dist/core/easing.d.ts +8 -0
- package/dist/core/easing.d.ts.map +1 -1
- package/dist/core/easing.js +12 -4
- package/dist/core/easing.js.map +1 -1
- package/dist/core/gesture-math.d.ts.map +1 -1
- package/dist/core/gradient-text.d.ts +24 -0
- package/dist/core/gradient-text.d.ts.map +1 -0
- package/dist/core/gradient-text.js +30 -0
- package/dist/core/gradient-text.js.map +1 -0
- package/dist/core/inspection-plot.d.ts +11 -0
- package/dist/core/inspection-plot.d.ts.map +1 -0
- package/dist/core/inspection-plot.js +57 -0
- package/dist/core/inspection-plot.js.map +1 -0
- package/dist/core/motion-behaviors.d.ts +68 -0
- package/dist/core/motion-behaviors.d.ts.map +1 -0
- package/dist/core/motion-behaviors.js +276 -0
- package/dist/core/motion-behaviors.js.map +1 -0
- package/dist/core/numeric-map.js.map +1 -1
- package/dist/core/particle-motion.d.ts +8 -0
- package/dist/core/particle-motion.d.ts.map +1 -0
- package/dist/core/particle-motion.js +11 -0
- package/dist/core/particle-motion.js.map +1 -0
- package/dist/core/pointer.d.ts +1 -1
- package/dist/core/preset-recipe.d.ts +20 -0
- package/dist/core/preset-recipe.d.ts.map +1 -0
- package/dist/core/preset-recipe.js +79 -0
- package/dist/core/preset-recipe.js.map +1 -0
- package/dist/core/reorder.d.ts +5 -0
- package/dist/core/reorder.d.ts.map +1 -1
- package/dist/core/reorder.js +17 -0
- package/dist/core/reorder.js.map +1 -1
- package/dist/core/rig.d.ts +73 -0
- package/dist/core/rig.d.ts.map +1 -0
- package/dist/core/rig.js +99 -0
- package/dist/core/rig.js.map +1 -0
- package/dist/core/scroll-header.js.map +1 -1
- package/dist/core/sensor-kinds.d.ts +1 -1
- package/dist/core/sensor-kinds.d.ts.map +1 -1
- package/dist/core/sensor-replay.d.ts +10 -0
- package/dist/core/sensor-replay.d.ts.map +1 -0
- package/dist/core/sensor-replay.js +32 -0
- package/dist/core/sensor-replay.js.map +1 -0
- package/dist/gradient-text/index.d.ts +2 -10
- package/dist/gradient-text/index.d.ts.map +1 -1
- package/dist/gradient-text/index.js +2 -25
- package/dist/gradient-text/index.js.map +1 -1
- package/dist/gradient-text/native.d.ts +2 -8
- package/dist/gradient-text/native.d.ts.map +1 -1
- package/dist/gradient-text/native.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector/plot.d.ts +1 -3
- package/dist/inspector/plot.d.ts.map +1 -1
- package/dist/inspector/plot.js +1 -22
- package/dist/inspector/plot.js.map +1 -1
- package/dist/motion-behaviors.d.ts +5 -54
- package/dist/motion-behaviors.d.ts.map +1 -1
- package/dist/motion-behaviors.js +18 -267
- package/dist/motion-behaviors.js.map +1 -1
- package/dist/rig/index.d.ts +2 -27
- package/dist/rig/index.d.ts.map +1 -1
- package/dist/rig/index.js +5 -89
- package/dist/rig/index.js.map +1 -1
- package/dist/testing/sensors.d.ts +2 -9
- package/dist/testing/sensors.d.ts.map +1 -1
- package/dist/testing/sensors.js +3 -21
- package/dist/testing/sensors.js.map +1 -1
- package/dist/web/angular/index.d.ts +62 -0
- package/dist/web/angular/index.d.ts.map +1 -0
- package/dist/web/angular/index.js +190 -0
- package/dist/web/angular/index.js.map +1 -0
- package/dist/web/behaviors.d.ts +5 -0
- package/dist/web/behaviors.d.ts.map +1 -0
- package/dist/web/behaviors.js +2 -0
- package/dist/web/behaviors.js.map +1 -0
- package/dist/web/bottom-sheet.js.map +1 -1
- package/dist/web/compose.js.map +1 -1
- package/dist/web/curve.js.map +1 -1
- package/dist/web/decay.js.map +1 -1
- package/dist/web/diagnostics.d.ts +1 -1
- package/dist/web/diagnostics.d.ts.map +1 -1
- package/dist/web/diagnostics.js.map +1 -1
- package/dist/web/drag.d.ts +11 -11
- package/dist/web/drag.d.ts.map +1 -1
- package/dist/web/effect.d.ts +2 -1
- package/dist/web/effect.d.ts.map +1 -1
- package/dist/web/effect.js +11 -4
- package/dist/web/effect.js.map +1 -1
- package/dist/web/frameworks/binding.d.ts +39 -0
- package/dist/web/frameworks/binding.d.ts.map +1 -0
- package/dist/web/frameworks/binding.js +356 -0
- package/dist/web/frameworks/binding.js.map +1 -0
- package/dist/web/gestures.js.map +1 -1
- package/dist/web/gradient-css.d.ts +2 -0
- package/dist/web/gradient-css.d.ts.map +1 -0
- package/dist/web/gradient-css.js +5 -0
- package/dist/web/gradient-css.js.map +1 -0
- package/dist/web/gradient-text.d.ts +24 -0
- package/dist/web/gradient-text.d.ts.map +1 -0
- package/dist/web/gradient-text.js +179 -0
- package/dist/web/gradient-text.js.map +1 -0
- package/dist/web/gradient.d.ts.map +1 -1
- package/dist/web/gradient.js +2 -1
- package/dist/web/gradient.js.map +1 -1
- package/dist/web/image-surface.d.ts.map +1 -1
- package/dist/web/image-surface.js.map +1 -1
- package/dist/web/inspector.d.ts +24 -0
- package/dist/web/inspector.d.ts.map +1 -1
- package/dist/web/inspector.js +76 -5
- package/dist/web/inspector.js.map +1 -1
- package/dist/web/interaction.d.ts +4 -0
- package/dist/web/interaction.d.ts.map +1 -1
- package/dist/web/interaction.js.map +1 -1
- package/dist/web/keyboard.js.map +1 -1
- package/dist/web/layout.d.ts +75 -75
- package/dist/web/layout.d.ts.map +1 -1
- package/dist/web/layout.js.map +1 -1
- package/dist/web/particles.d.ts.map +1 -1
- package/dist/web/particles.js +5 -6
- package/dist/web/particles.js.map +1 -1
- package/dist/web/plan.d.ts +2 -0
- package/dist/web/plan.d.ts.map +1 -1
- package/dist/web/plan.js.map +1 -1
- package/dist/web/press.js.map +1 -1
- package/dist/web/progress.d.ts.map +1 -1
- package/dist/web/properties.d.ts +4 -4
- package/dist/web/properties.d.ts.map +1 -1
- package/dist/web/property.d.ts.map +1 -1
- package/dist/web/property.js.map +1 -1
- package/dist/web/public.d.ts +19 -3
- package/dist/web/public.d.ts.map +1 -1
- package/dist/web/public.js +9 -0
- package/dist/web/public.js.map +1 -1
- package/dist/web/react/index.d.ts +12 -0
- package/dist/web/react/index.d.ts.map +1 -0
- package/dist/web/react/index.js +119 -0
- package/dist/web/react/index.js.map +1 -0
- package/dist/web/reorder.d.ts.map +1 -1
- package/dist/web/reorder.js +23 -2
- package/dist/web/reorder.js.map +1 -1
- package/dist/web/rig.d.ts +43 -0
- package/dist/web/rig.d.ts.map +1 -0
- package/dist/web/rig.js +307 -0
- package/dist/web/rig.js.map +1 -0
- package/dist/web/runtime.d.ts +37 -25
- package/dist/web/runtime.d.ts.map +1 -1
- package/dist/web/runtime.js +111 -8
- package/dist/web/runtime.js.map +1 -1
- package/dist/web/scheduler.d.ts.map +1 -1
- package/dist/web/scheduler.js.map +1 -1
- package/dist/web/scope.d.ts +7 -1
- package/dist/web/scope.d.ts.map +1 -1
- package/dist/web/scope.js +16 -2
- package/dist/web/scope.js.map +1 -1
- package/dist/web/scroll-header.js.map +1 -1
- package/dist/web/scroll-range.d.ts.map +1 -1
- package/dist/web/scroll-range.js.map +1 -1
- package/dist/web/scroll.d.ts +1 -1
- package/dist/web/scroll.d.ts.map +1 -1
- package/dist/web/scroll.js.map +1 -1
- package/dist/web/sensor-replay-bridge.d.ts +16 -0
- package/dist/web/sensor-replay-bridge.d.ts.map +1 -0
- package/dist/web/sensor-replay-bridge.js +12 -0
- package/dist/web/sensor-replay-bridge.js.map +1 -0
- package/dist/web/sensor-replay.d.ts +22 -0
- package/dist/web/sensor-replay.d.ts.map +1 -0
- package/dist/web/sensor-replay.js +124 -0
- package/dist/web/sensor-replay.js.map +1 -0
- package/dist/web/sensors.d.ts +14 -5
- package/dist/web/sensors.d.ts.map +1 -1
- package/dist/web/sensors.js +159 -41
- package/dist/web/sensors.js.map +1 -1
- package/dist/web/shape.d.ts +2 -0
- package/dist/web/shape.d.ts.map +1 -1
- package/dist/web/shape.js +44 -12
- package/dist/web/shape.js.map +1 -1
- package/dist/web/shared-layout.js.map +1 -1
- package/dist/web/size.d.ts.map +1 -1
- package/dist/web/size.js.map +1 -1
- package/dist/web/solid/index.d.ts +16 -0
- package/dist/web/solid/index.d.ts.map +1 -0
- package/dist/web/solid/index.js +89 -0
- package/dist/web/solid/index.js.map +1 -0
- package/dist/web/spring-value.d.ts.map +1 -1
- package/dist/web/spring-value.js.map +1 -1
- package/dist/web/stroke.d.ts.map +1 -1
- package/dist/web/stroke.js.map +1 -1
- package/dist/web/style.d.ts.map +1 -1
- package/dist/web/style.js.map +1 -1
- package/dist/web/surface-effect.d.ts.map +1 -1
- package/dist/web/surface-effect.js.map +1 -1
- package/dist/web/svelte/index.d.ts +50 -0
- package/dist/web/svelte/index.d.ts.map +1 -0
- package/dist/web/svelte/index.js +68 -0
- package/dist/web/svelte/index.js.map +1 -0
- package/dist/web/testing.d.ts +1 -0
- package/dist/web/testing.d.ts.map +1 -1
- package/dist/web/testing.js +1 -0
- package/dist/web/testing.js.map +1 -1
- package/dist/web/timers.d.ts.map +1 -1
- package/dist/web/timers.js.map +1 -1
- package/dist/web/types.d.ts.map +1 -1
- package/dist/web/value-playback.d.ts +17 -17
- package/dist/web/value-playback.js.map +1 -1
- package/dist/web/value.d.ts.map +1 -1
- package/dist/web/value.js.map +1 -1
- package/dist/web/viewport.js.map +1 -1
- package/dist/web/vue/index.d.ts +12 -3
- package/dist/web/vue/index.d.ts.map +1 -1
- package/dist/web/vue/index.js +115 -35
- package/dist/web/vue/index.js.map +1 -1
- package/package.json +35 -6
- package/src/core/easing.ts +12 -4
- package/src/core/gradient-text.ts +56 -0
- package/src/core/inspection-plot.ts +74 -0
- package/src/core/motion-behaviors.ts +337 -0
- package/src/core/particle-motion.ts +20 -0
- package/src/core/preset-recipe.ts +111 -0
- package/src/core/reorder.ts +23 -0
- package/src/core/rig.ts +149 -0
- package/src/core/sensor-replay.ts +48 -0
- package/src/gradient-text/index.ts +7 -43
- package/src/gradient-text/native.ts +2 -7
- package/src/index.ts +6 -0
- package/src/inspector/plot.ts +1 -27
- package/src/motion-behaviors.ts +34 -316
- package/src/rig/index.ts +25 -124
- package/src/testing/sensors.ts +4 -36
- package/src/web/angular/index.ts +171 -0
- package/src/web/behaviors.ts +12 -0
- package/src/web/effect.ts +10 -5
- package/src/web/frameworks/binding.ts +408 -0
- package/src/web/gradient-css.ts +8 -0
- package/src/web/gradient-text.ts +234 -0
- package/src/web/gradient.ts +2 -1
- package/src/web/inspector.ts +80 -5
- package/src/web/interaction.ts +4 -0
- package/src/web/particles.ts +15 -9
- package/src/web/plan.ts +2 -0
- package/src/web/public.ts +51 -4
- package/src/web/react/index.ts +208 -0
- package/src/web/reorder.ts +21 -3
- package/src/web/rig.ts +377 -0
- package/src/web/runtime.ts +128 -11
- package/src/web/scope.ts +32 -4
- package/src/web/sensor-replay-bridge.ts +23 -0
- package/src/web/sensor-replay.ts +140 -0
- package/src/web/sensors.ts +179 -57
- package/src/web/shape.ts +42 -9
- package/src/web/solid/index.ts +102 -0
- package/src/web/svelte/index.ts +88 -0
- package/src/web/testing.ts +6 -0
- package/src/web/vue/index.ts +122 -31
package/src/web/runtime.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import { createGradientText, type WebGradientTextOptions } from './gradient-text.js'
|
|
2
|
+
import { limitRigTrack, type RigChannel, type RigDefinition } from '../core/rig.js'
|
|
3
|
+
import { createRig, type WebRig } from './rig.js'
|
|
4
|
+
import {
|
|
5
|
+
createMotionBehaviors,
|
|
6
|
+
type MotionBehaviors,
|
|
7
|
+
type MotionBehaviorsOptions,
|
|
8
|
+
} from '../core/motion-behaviors.js'
|
|
9
|
+
import type { WebMotionBehavior } from './behaviors.js'
|
|
1
10
|
import {
|
|
2
11
|
createTimelineCues,
|
|
3
12
|
type TimelineCue,
|
|
@@ -978,6 +987,8 @@ export class WebRuntime {
|
|
|
978
987
|
private readonly playbacks = new WeakSet<MotionAnimation>()
|
|
979
988
|
private readonly paths = new Map<SVGGeometryElement, StrokeSurface>()
|
|
980
989
|
private readonly itemAnimations = new Set<WebItemsAnimation>()
|
|
990
|
+
private readonly behaviorControllers = new Set<MotionBehaviors>()
|
|
991
|
+
private readonly rigControllers = new Set<WebRig>()
|
|
981
992
|
private readonly stateControllers = new Set<WebMotionStates>()
|
|
982
993
|
private readonly groups = new Set<MotionAnimation>()
|
|
983
994
|
private readonly groupVisibility = new Set<() => void>()
|
|
@@ -1062,6 +1073,27 @@ export class WebRuntime {
|
|
|
1062
1073
|
(this.settings.reducedMotion === 'user' && this.preference.matches)
|
|
1063
1074
|
)
|
|
1064
1075
|
}
|
|
1076
|
+
reducedMotion() {
|
|
1077
|
+
this.assert()
|
|
1078
|
+
return this.reduced()
|
|
1079
|
+
}
|
|
1080
|
+
onReducedMotion(listener: (reduced: boolean) => void) {
|
|
1081
|
+
this.assert()
|
|
1082
|
+
if (typeof listener !== 'function')
|
|
1083
|
+
throw new TypeError('Expected a reduced-motion listener.')
|
|
1084
|
+
let previous = this.reduced()
|
|
1085
|
+
const changed = () => {
|
|
1086
|
+
const next = this.reduced()
|
|
1087
|
+
if (next === previous) return
|
|
1088
|
+
previous = next
|
|
1089
|
+
try {
|
|
1090
|
+
listener(next)
|
|
1091
|
+
} catch (error) {
|
|
1092
|
+
this.report(error)
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
return this.watchPreference(changed)
|
|
1096
|
+
}
|
|
1065
1097
|
private validate(
|
|
1066
1098
|
options: WebConfig,
|
|
1067
1099
|
current: Required<WebConfig>,
|
|
@@ -1081,6 +1113,27 @@ export class WebRuntime {
|
|
|
1081
1113
|
this.settings = this.validate(options, this.settings)
|
|
1082
1114
|
this.preferenceChanged()
|
|
1083
1115
|
}
|
|
1116
|
+
motionBehaviors<const D extends Record<string, WebMotionBehavior>>(
|
|
1117
|
+
definitions: D,
|
|
1118
|
+
options: MotionBehaviorsOptions<Extract<keyof D, string>> = {},
|
|
1119
|
+
): MotionBehaviors<Extract<keyof D, string>> {
|
|
1120
|
+
this.assert()
|
|
1121
|
+
const controller: MotionBehaviors<Extract<keyof D, string>> = createMotionBehaviors(
|
|
1122
|
+
definitions,
|
|
1123
|
+
options,
|
|
1124
|
+
{
|
|
1125
|
+
scope: () => this.scope(),
|
|
1126
|
+
hidden: () => this.document.hidden,
|
|
1127
|
+
visibility: (callback) => {
|
|
1128
|
+
this.groupVisibility.add(callback)
|
|
1129
|
+
return () => this.groupVisibility.delete(callback)
|
|
1130
|
+
},
|
|
1131
|
+
disposed: () => this.behaviorControllers.delete(controller),
|
|
1132
|
+
},
|
|
1133
|
+
)
|
|
1134
|
+
this.behaviorControllers.add(controller)
|
|
1135
|
+
return controller
|
|
1136
|
+
}
|
|
1084
1137
|
scope(setup?: (scope: WebMotionScope) => void): WebMotionScope {
|
|
1085
1138
|
this.assert()
|
|
1086
1139
|
if (setup !== undefined && typeof setup !== 'function')
|
|
@@ -1116,7 +1169,7 @@ export class WebRuntime {
|
|
|
1116
1169
|
diagnostics(options: WebDiagnosticsOptions): WebDiagnostics {
|
|
1117
1170
|
this.assert()
|
|
1118
1171
|
if (this.diagnostic) throw new Error('This runtime already has a diagnostics owner.')
|
|
1119
|
-
const collector = new DiagnosticCollector(
|
|
1172
|
+
const collector: DiagnosticCollector = new DiagnosticCollector(
|
|
1120
1173
|
options,
|
|
1121
1174
|
() => this.diagnosticSnapshot(collector),
|
|
1122
1175
|
() => {
|
|
@@ -2467,7 +2520,8 @@ export class WebRuntime {
|
|
|
2467
2520
|
timeScale: this.settings.timeScale,
|
|
2468
2521
|
reducedMotion: this.reduced(),
|
|
2469
2522
|
})
|
|
2470
|
-
|
|
2523
|
+
const bounded = limitRigTrack(track, plan.range)
|
|
2524
|
+
return { plan, track: bounded, points: flatten(bounded, this.maxKeyframes) }
|
|
2471
2525
|
})
|
|
2472
2526
|
compiled.push({ surface, plans: tracks })
|
|
2473
2527
|
}
|
|
@@ -2643,6 +2697,7 @@ export class WebRuntime {
|
|
|
2643
2697
|
motionValue: this.motionValue.bind(this),
|
|
2644
2698
|
animate: this.animate.bind(this),
|
|
2645
2699
|
bindLayer: this.bindInLayer.bind(this),
|
|
2700
|
+
geometry: this.geometryLease.bind(this),
|
|
2646
2701
|
layer: (name) => `jolt:interaction:${name}:${++this.nextInteraction}`,
|
|
2647
2702
|
gestures: this.gestures.bind(this),
|
|
2648
2703
|
bind: this.bind.bind(this),
|
|
@@ -2755,14 +2810,14 @@ export class WebRuntime {
|
|
|
2755
2810
|
kind: 'rotation',
|
|
2756
2811
|
options?: WebSensorOptions,
|
|
2757
2812
|
): import('./sensors.js').WebRotationSensor
|
|
2758
|
-
sensor(
|
|
2759
|
-
kind:
|
|
2813
|
+
sensor<K extends import('../core/sensor-kinds.js').VectorSensorKind>(
|
|
2814
|
+
kind: K,
|
|
2760
2815
|
options?: WebSensorOptions,
|
|
2761
|
-
): import('./sensors.js').
|
|
2816
|
+
): import('./sensors.js').WebVectorSensor<K>
|
|
2762
2817
|
sensor(
|
|
2763
2818
|
kind: WebSensorKind,
|
|
2764
2819
|
options?: WebSensorOptions,
|
|
2765
|
-
): import('./sensors.js').WebRotationSensor | import('./sensors.js').
|
|
2820
|
+
): import('./sensors.js').WebRotationSensor | import('./sensors.js').WebVectorSensor
|
|
2766
2821
|
sensor(kind: WebSensorKind, options: WebSensorOptions = {}) {
|
|
2767
2822
|
this.assert()
|
|
2768
2823
|
return createSensor(kind, options, this.platformHost(), (initial) => {
|
|
@@ -2853,6 +2908,60 @@ export class WebRuntime {
|
|
|
2853
2908
|
return createImageEffect(target, effect, options, this.effectHost())
|
|
2854
2909
|
}
|
|
2855
2910
|
|
|
2911
|
+
gradientText(target: HTMLElement, options: WebGradientTextOptions) {
|
|
2912
|
+
this.assert()
|
|
2913
|
+
return createGradientText(target, options, this.effectHost())
|
|
2914
|
+
}
|
|
2915
|
+
rig2d(
|
|
2916
|
+
definition: RigDefinition,
|
|
2917
|
+
targets: Record<string, HTMLElement | null> = {},
|
|
2918
|
+
): WebRig {
|
|
2919
|
+
this.assert()
|
|
2920
|
+
const read = (target: HTMLElement, property: RigChannel, model = false): number => {
|
|
2921
|
+
const surface = this.surfaces.get(target),
|
|
2922
|
+
key = keyOf(property),
|
|
2923
|
+
entry = surface?.state.entries.get(key)
|
|
2924
|
+
return entry
|
|
2925
|
+
? model
|
|
2926
|
+
? entry.track.to
|
|
2927
|
+
: sampled(entry.points, entry.owner.time(this.now()))
|
|
2928
|
+
: (surface?.state.bindings.get(key)?.source.get() ??
|
|
2929
|
+
surface?.state.rest.get(key)?.value ??
|
|
2930
|
+
readProperty(target, property))
|
|
2931
|
+
}
|
|
2932
|
+
let rig: WebRig | undefined
|
|
2933
|
+
rig = createRig(definition, targets, {
|
|
2934
|
+
document: this.document,
|
|
2935
|
+
scope: () => this.scope(),
|
|
2936
|
+
validate: (target) => {
|
|
2937
|
+
this.targets(target)
|
|
2938
|
+
;(this.surfaces.get(target) ?? new Surface(this, target)).assert()
|
|
2939
|
+
},
|
|
2940
|
+
read,
|
|
2941
|
+
revision: (target, property) => this.ownership.get(target, keyOf(property)),
|
|
2942
|
+
set: (target, values) => {
|
|
2943
|
+
this.set(target, values)
|
|
2944
|
+
},
|
|
2945
|
+
refresh: (target) => {
|
|
2946
|
+
if (this.surfaces.has(target)) this.refresh(target)
|
|
2947
|
+
},
|
|
2948
|
+
animate: (batch, transition) => {
|
|
2949
|
+
const elements = batch.map((item) => item.target)
|
|
2950
|
+
const plans = batch.map((item) =>
|
|
2951
|
+
prepare(item.values, transition, this.presets, 1)[0]!.map((plan) => ({
|
|
2952
|
+
...plan,
|
|
2953
|
+
range: plan.property === 'rotate' ? item.rotation : undefined,
|
|
2954
|
+
})),
|
|
2955
|
+
)
|
|
2956
|
+
return this.play(elements, {}, undefined, undefined, plans)
|
|
2957
|
+
},
|
|
2958
|
+
forget: () => {
|
|
2959
|
+
if (rig) this.rigControllers.delete(rig)
|
|
2960
|
+
},
|
|
2961
|
+
})
|
|
2962
|
+
this.rigControllers.add(rig)
|
|
2963
|
+
return rig
|
|
2964
|
+
}
|
|
2856
2965
|
gradient(target: HTMLElement, options: WebGradientOptions) {
|
|
2857
2966
|
this.assert()
|
|
2858
2967
|
return createGradient(target, options, this.effectHost())
|
|
@@ -3389,10 +3498,14 @@ export class WebRuntime {
|
|
|
3389
3498
|
private preferenceChanged = () => {
|
|
3390
3499
|
if (this.disposed) return
|
|
3391
3500
|
const reduced = this.reduced()
|
|
3392
|
-
|
|
3501
|
+
const changed = reduced !== this.reported
|
|
3393
3502
|
this.reported = reduced
|
|
3394
|
-
|
|
3503
|
+
// A resource can attach after MediaQueryList.matches changes but before its
|
|
3504
|
+
// queued change event. Reconcile it even when rapid changes end at the last
|
|
3505
|
+
// reported preference; otherwise a newly paused sensor can remain paused.
|
|
3395
3506
|
for (const listener of [...this.preferenceListeners]) listener()
|
|
3507
|
+
if (!changed) return
|
|
3508
|
+
if (reduced) this.diagnosticEvent('reduced-motion')
|
|
3396
3509
|
for (const value of this.values)
|
|
3397
3510
|
if (value instanceof SpringValueNode) value.preferenceChanged()
|
|
3398
3511
|
for (const size of this.sizes.values()) size.reduced()
|
|
@@ -3502,7 +3615,7 @@ export class WebRuntime {
|
|
|
3502
3615
|
target.ownerDocument !== this.document ||
|
|
3503
3616
|
!target.getClientRects().length
|
|
3504
3617
|
)
|
|
3505
|
-
this.release(target)
|
|
3618
|
+
this.release(target, true)
|
|
3506
3619
|
for (const entries of [...this.interactions.values()])
|
|
3507
3620
|
for (const refresh of [...entries.values()]) refresh()
|
|
3508
3621
|
for (const press of this.presses.values()) press.refresh()
|
|
@@ -3526,12 +3639,12 @@ export class WebRuntime {
|
|
|
3526
3639
|
}
|
|
3527
3640
|
}
|
|
3528
3641
|
|
|
3529
|
-
release(target: HTMLElement) {
|
|
3642
|
+
release(target: HTMLElement, detached = false) {
|
|
3530
3643
|
const surface = this.surfaces.get(target)
|
|
3531
3644
|
// Mark first: controller cleanup can dispose bound values and re-enter unbind.
|
|
3532
3645
|
if (surface) surface.disposed = true
|
|
3533
3646
|
for (const resource of [...(this.interactions.get(target)?.keys() ?? [])])
|
|
3534
|
-
resource.dispose()
|
|
3647
|
+
if (!detached || !resource.retainDetached?.()) resource.dispose()
|
|
3535
3648
|
if (this.surfaces.has(target)) this.diagnosticEvent('released', undefined, target)
|
|
3536
3649
|
this.layouts.get(target)?.stop()
|
|
3537
3650
|
this.layouts.delete(target)
|
|
@@ -3645,6 +3758,8 @@ export class WebRuntime {
|
|
|
3645
3758
|
this.disposed = true
|
|
3646
3759
|
const errors: unknown[] = []
|
|
3647
3760
|
for (const resource of [
|
|
3761
|
+
...this.behaviorControllers,
|
|
3762
|
+
...this.rigControllers,
|
|
3648
3763
|
...this.scopes,
|
|
3649
3764
|
...[...this.interactions.values()].flatMap((entries) => [...entries.keys()]),
|
|
3650
3765
|
...[...this.drags.values()].map((drag) => drag.handle),
|
|
@@ -3664,6 +3779,8 @@ export class WebRuntime {
|
|
|
3664
3779
|
}
|
|
3665
3780
|
}
|
|
3666
3781
|
this.paths.clear()
|
|
3782
|
+
this.behaviorControllers.clear()
|
|
3783
|
+
this.rigControllers.clear()
|
|
3667
3784
|
this.stateControllers.clear()
|
|
3668
3785
|
this.itemAnimations.clear()
|
|
3669
3786
|
this.scopes.clear()
|
package/src/web/scope.ts
CHANGED
|
@@ -26,6 +26,8 @@ type Factories = Pick<
|
|
|
26
26
|
| 'liquid'
|
|
27
27
|
| 'imageEffect'
|
|
28
28
|
| 'gradient'
|
|
29
|
+
| 'gradientText'
|
|
30
|
+
| 'rig2d'
|
|
29
31
|
| 'reveal'
|
|
30
32
|
| 'conceal'
|
|
31
33
|
| 'animateText'
|
|
@@ -36,6 +38,7 @@ type Factories = Pick<
|
|
|
36
38
|
| 'decay'
|
|
37
39
|
| 'drawPath'
|
|
38
40
|
| 'motionStates'
|
|
41
|
+
| 'motionBehaviors'
|
|
39
42
|
| 'sequence'
|
|
40
43
|
| 'timeline'
|
|
41
44
|
| 'withTimelineCues'
|
|
@@ -78,6 +81,12 @@ export interface WebMotionScope extends Factories {
|
|
|
78
81
|
readonly size: number
|
|
79
82
|
/** Idempotent adoption. Non-playable resources are disposed on suspension. */
|
|
80
83
|
add<T extends WebMotionResource>(resource: T): T
|
|
84
|
+
/** Keep static resources and settled playback until explicit release/reset/disposal. */
|
|
85
|
+
retain<T extends WebMotionResource>(resource: T): T
|
|
86
|
+
/** Construct once and retain; clean up newly created resources if adoption fails. */
|
|
87
|
+
resource<T extends WebMotionResource>(setup: () => T): T
|
|
88
|
+
/** Dispose one owned resource; leave borrowed/unowned resources alone. */
|
|
89
|
+
release(resource: WebMotionResource): void
|
|
81
90
|
/** Document a borrowed resource. It is never paused, stopped or disposed here. */
|
|
82
91
|
borrow<T extends WebMotionResource>(resource: T): T
|
|
83
92
|
scope(setup?: (scope: WebMotionScope) => void): WebMotionScope
|
|
@@ -184,14 +193,21 @@ export function createWebScope(
|
|
|
184
193
|
const adopt = <T extends WebMotionResource>(resource: T, retain = false): T => {
|
|
185
194
|
assert(true)
|
|
186
195
|
validate(resource)
|
|
187
|
-
|
|
196
|
+
const existing = adopted.get(resource)
|
|
197
|
+
if (existing) {
|
|
198
|
+
if (retain && !existing.retain)
|
|
199
|
+
throw new Error(
|
|
200
|
+
'Resource already belongs to this scope with a different lifetime.',
|
|
201
|
+
)
|
|
202
|
+
return resource
|
|
203
|
+
}
|
|
188
204
|
const entry: Entry = { resource, retain }
|
|
189
205
|
adopted.set(resource, entry)
|
|
190
206
|
owners.set(resource, identity)
|
|
191
207
|
entries.add(entry)
|
|
192
208
|
trace?.('adopted', resource)
|
|
193
209
|
const finished = (resource as Controlled).finished
|
|
194
|
-
if (finished) {
|
|
210
|
+
if (!retain && finished) {
|
|
195
211
|
const settled = () => {
|
|
196
212
|
if (entry.resource !== resource) return
|
|
197
213
|
detach(entry)
|
|
@@ -263,6 +279,12 @@ export function createWebScope(
|
|
|
263
279
|
return entries.size
|
|
264
280
|
},
|
|
265
281
|
add: (resource) => adopt(resource),
|
|
282
|
+
retain: (resource) => adopt(resource, true),
|
|
283
|
+
resource: (setup) => start(setup, true),
|
|
284
|
+
release(resource) {
|
|
285
|
+
const entry = adopted.get(resource)
|
|
286
|
+
if (entry) remove(entry)
|
|
287
|
+
},
|
|
266
288
|
borrow(resource) {
|
|
267
289
|
assert()
|
|
268
290
|
validateBorrow(resource)
|
|
@@ -277,13 +299,17 @@ export function createWebScope(
|
|
|
277
299
|
sharedNavigationEntry: (...args) =>
|
|
278
300
|
start(() => runtime.sharedNavigationEntry(...args)),
|
|
279
301
|
glass: (...args) => start(() => runtime.glass(...args)),
|
|
280
|
-
sensor: ((
|
|
281
|
-
|
|
302
|
+
sensor: ((
|
|
303
|
+
kind: import('./sensors.js').WebSensorKind,
|
|
304
|
+
options?: import('./sensors.js').WebSensorOptions,
|
|
305
|
+
) => start(() => runtime.sensor(kind, options))) as WebMotionScope['sensor'],
|
|
282
306
|
blur: (...args) => start(() => runtime.blur(...args)),
|
|
283
307
|
shape: (...args) => start(() => runtime.shape(...args)),
|
|
284
308
|
drawBatch: (...args) => start(() => runtime.drawBatch(...args), true),
|
|
285
309
|
liquid: (...args) => start(() => runtime.liquid(...args)),
|
|
286
310
|
imageEffect: (...args) => start(() => runtime.imageEffect(...args)),
|
|
311
|
+
rig2d: (...args) => start(() => runtime.rig2d(...args)),
|
|
312
|
+
gradientText: (...args) => start(() => runtime.gradientText(...args)),
|
|
287
313
|
gradient: (...args) => start(() => runtime.gradient(...args)),
|
|
288
314
|
reveal: (...args) => start(() => runtime.reveal(...args)),
|
|
289
315
|
conceal: (...args) => start(() => runtime.conceal(...args)),
|
|
@@ -293,6 +319,8 @@ export function createWebScope(
|
|
|
293
319
|
loader: (...args) => start(() => runtime.loader(...args)),
|
|
294
320
|
animateItems: (...args) => start(() => runtime.animateItems(...args)),
|
|
295
321
|
drawPath: (...args) => start(() => runtime.drawPath(...args)),
|
|
322
|
+
motionBehaviors: (definitions, options) =>
|
|
323
|
+
start(() => runtime.motionBehaviors(definitions, options)),
|
|
296
324
|
motionStates: (targets, definitions, options) =>
|
|
297
325
|
start(() => runtime.motionStates(targets, definitions, options)),
|
|
298
326
|
sequence: (...args) => start(() => runtime.sequence(...args)),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SensorSample } from '../core/sensor-replay.js'
|
|
2
|
+
export interface SensorReplaySession {
|
|
3
|
+
allowed(active: boolean): void
|
|
4
|
+
dispose(): void
|
|
5
|
+
}
|
|
6
|
+
export interface SensorReplayControl {
|
|
7
|
+
now(): number
|
|
8
|
+
after(ms: number, action: () => void): () => void
|
|
9
|
+
inject(sample: SensorSample): void
|
|
10
|
+
end(): void
|
|
11
|
+
}
|
|
12
|
+
type Driver = (session: SensorReplaySession) => SensorReplayControl
|
|
13
|
+
const drivers = new WeakMap<object, Driver>()
|
|
14
|
+
export function registerSensorReplay(source: object, driver: Driver) {
|
|
15
|
+
drivers.set(source, driver)
|
|
16
|
+
return () => drivers.delete(source)
|
|
17
|
+
}
|
|
18
|
+
export function sensorReplayDriver(source: object): Driver {
|
|
19
|
+
const driver = drivers.get(source)
|
|
20
|
+
if (!driver)
|
|
21
|
+
throw new TypeError('Replay requires a live Web sensor from this Jolt module.')
|
|
22
|
+
return driver
|
|
23
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { validateSensorSamples, type SensorSample } from '../core/sensor-replay.js'
|
|
2
|
+
import { sensorReplayDriver, type SensorReplayControl } from './sensor-replay-bridge.js'
|
|
3
|
+
import type { WebSensor } from './sensors.js'
|
|
4
|
+
export type { SensorSample } from '../core/sensor-replay.js'
|
|
5
|
+
export interface SensorReplayOptions {
|
|
6
|
+
manual?: boolean
|
|
7
|
+
}
|
|
8
|
+
export interface SensorReplay {
|
|
9
|
+
readonly finished: Promise<boolean>
|
|
10
|
+
readonly paused: boolean
|
|
11
|
+
readonly disposed: boolean
|
|
12
|
+
readonly time: number
|
|
13
|
+
readonly duration: number
|
|
14
|
+
/** Manual mode only; monotonic relative time. No simulated intermediate hardware readings. */
|
|
15
|
+
advanceTo(milliseconds: number): void
|
|
16
|
+
pause(): void
|
|
17
|
+
play(): void
|
|
18
|
+
stop(): void
|
|
19
|
+
dispose(): void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Explicit synthetic input. It never grants permission or proves hardware availability. */
|
|
23
|
+
export function replaySensor(
|
|
24
|
+
source: WebSensor,
|
|
25
|
+
input: readonly SensorSample[],
|
|
26
|
+
options: SensorReplayOptions = {},
|
|
27
|
+
): SensorReplay {
|
|
28
|
+
const samples = validateSensorSamples(source.kind, input)
|
|
29
|
+
if (options.manual !== undefined && typeof options.manual !== 'boolean')
|
|
30
|
+
throw new TypeError('manual must be boolean.')
|
|
31
|
+
const begin = sensorReplayDriver(source)
|
|
32
|
+
let driver: SensorReplayControl | undefined, timer: (() => void) | undefined
|
|
33
|
+
let elapsed = 0,
|
|
34
|
+
started = 0,
|
|
35
|
+
index = 0,
|
|
36
|
+
allowed = false,
|
|
37
|
+
held = false,
|
|
38
|
+
running = false,
|
|
39
|
+
ended = false
|
|
40
|
+
const duration = samples.at(-1)!.time
|
|
41
|
+
let resolve!: (completed: boolean) => void
|
|
42
|
+
const finished = new Promise<boolean>((done) => {
|
|
43
|
+
resolve = done
|
|
44
|
+
})
|
|
45
|
+
const time = () => Math.min(duration, elapsed + (running ? driver!.now() - started : 0))
|
|
46
|
+
const freeze = () => {
|
|
47
|
+
if (running) elapsed = time()
|
|
48
|
+
running = false
|
|
49
|
+
timer?.()
|
|
50
|
+
timer = undefined
|
|
51
|
+
}
|
|
52
|
+
const finish = (completed: boolean) => {
|
|
53
|
+
if (ended) return
|
|
54
|
+
freeze()
|
|
55
|
+
ended = true
|
|
56
|
+
const current = driver
|
|
57
|
+
driver = undefined
|
|
58
|
+
samples.length = 0
|
|
59
|
+
try {
|
|
60
|
+
current?.end()
|
|
61
|
+
} finally {
|
|
62
|
+
resolve(completed)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const apply = (at: number) => {
|
|
66
|
+
elapsed = at
|
|
67
|
+
while (
|
|
68
|
+
!ended &&
|
|
69
|
+
allowed &&
|
|
70
|
+
!held &&
|
|
71
|
+
index < samples.length &&
|
|
72
|
+
samples[index]!.time <= at
|
|
73
|
+
)
|
|
74
|
+
driver!.inject(samples[index++]!)
|
|
75
|
+
if (!ended && index === samples.length) finish(true)
|
|
76
|
+
}
|
|
77
|
+
const schedule = () => {
|
|
78
|
+
if (!driver || ended) return
|
|
79
|
+
freeze()
|
|
80
|
+
if (!allowed || held || options.manual) return
|
|
81
|
+
started = driver.now()
|
|
82
|
+
running = true
|
|
83
|
+
timer = driver.after(Math.max(0, samples[index]!.time - elapsed), () => {
|
|
84
|
+
const at = time()
|
|
85
|
+
freeze()
|
|
86
|
+
apply(at)
|
|
87
|
+
if (!ended) schedule()
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
driver = begin({
|
|
91
|
+
allowed(active) {
|
|
92
|
+
if (allowed === active) return
|
|
93
|
+
// Capture the old running clock before changing permission/demand state.
|
|
94
|
+
if (driver) freeze()
|
|
95
|
+
allowed = active
|
|
96
|
+
if (driver) schedule()
|
|
97
|
+
},
|
|
98
|
+
dispose: () => finish(false),
|
|
99
|
+
})
|
|
100
|
+
if (ended) {
|
|
101
|
+
driver.end()
|
|
102
|
+
driver = undefined
|
|
103
|
+
} else schedule()
|
|
104
|
+
return {
|
|
105
|
+
finished,
|
|
106
|
+
get paused() {
|
|
107
|
+
return held || !allowed
|
|
108
|
+
},
|
|
109
|
+
get disposed() {
|
|
110
|
+
return ended
|
|
111
|
+
},
|
|
112
|
+
get time() {
|
|
113
|
+
return time()
|
|
114
|
+
},
|
|
115
|
+
duration,
|
|
116
|
+
advanceTo(at) {
|
|
117
|
+
if (!options.manual) throw new Error('advanceTo requires manual replay.')
|
|
118
|
+
if (ended) throw new Error('Replay has finished.')
|
|
119
|
+
if (!Number.isFinite(at) || at < elapsed || at > duration)
|
|
120
|
+
throw new RangeError('Replay time must increase within its duration.')
|
|
121
|
+
if (held || !allowed)
|
|
122
|
+
throw new Error('Replay is paused or has no active sensor consumers.')
|
|
123
|
+
apply(at)
|
|
124
|
+
},
|
|
125
|
+
pause() {
|
|
126
|
+
if (!ended) {
|
|
127
|
+
freeze()
|
|
128
|
+
held = true
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
play() {
|
|
132
|
+
if (!ended) {
|
|
133
|
+
held = false
|
|
134
|
+
schedule()
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
stop: () => finish(false),
|
|
138
|
+
dispose: () => finish(false),
|
|
139
|
+
}
|
|
140
|
+
}
|