@rafaelaugusto/jolt 0.1.0-rc.13 → 0.1.0-rc.15
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/animate.d.ts +2 -0
- package/dist/animate.d.ts.map +1 -1
- package/dist/animate.js +4 -4
- package/dist/animate.js.map +1 -1
- package/dist/core/drop.d.ts +34 -1
- package/dist/core/drop.d.ts.map +1 -1
- package/dist/core/drop.js +93 -8
- package/dist/core/drop.js.map +1 -1
- package/dist/core/layout-exit.d.ts +16 -0
- package/dist/core/layout-exit.d.ts.map +1 -0
- package/dist/core/layout-exit.js +29 -0
- package/dist/core/layout-exit.js.map +1 -0
- package/dist/core/list-changes.d.ts +52 -0
- package/dist/core/list-changes.d.ts.map +1 -0
- package/dist/core/list-changes.js +153 -0
- package/dist/core/list-changes.js.map +1 -0
- package/dist/core/loading.d.ts +125 -0
- package/dist/core/loading.d.ts.map +1 -0
- package/dist/core/loading.js +119 -0
- package/dist/core/loading.js.map +1 -0
- package/dist/core/numeric-map.d.ts +3 -0
- package/dist/core/numeric-map.d.ts.map +1 -1
- package/dist/core/numeric-map.js +1 -1
- package/dist/core/numeric-map.js.map +1 -1
- package/dist/core/pointer.d.ts +1 -1
- package/dist/core/preset-recipe.d.ts +2 -2
- package/dist/core/preset-recipe.d.ts.map +1 -1
- package/dist/core/preset-recipe.js +3 -1
- package/dist/core/preset-recipe.js.map +1 -1
- package/dist/core/scalar-program.d.ts +22 -0
- package/dist/core/scalar-program.d.ts.map +1 -0
- package/dist/core/scalar-program.js +47 -0
- package/dist/core/scalar-program.js.map +1 -0
- package/dist/core/scalar.d.ts +25 -0
- package/dist/core/scalar.d.ts.map +1 -0
- package/dist/core/scalar.js +84 -0
- package/dist/core/scalar.js.map +1 -0
- package/dist/core/text-pieces.d.ts +18 -0
- package/dist/core/text-pieces.d.ts.map +1 -0
- package/dist/core/text-pieces.js +43 -0
- package/dist/core/text-pieces.js.map +1 -0
- package/dist/drag.d.ts +7 -1
- package/dist/drag.d.ts.map +1 -1
- package/dist/drag.js +72 -37
- package/dist/drag.js.map +1 -1
- package/dist/drop-zones.d.ts +1 -1
- package/dist/drop-zones.d.ts.map +1 -1
- package/dist/drop-zones.js +2 -0
- package/dist/drop-zones.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +7 -2
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/layout-exit.d.ts +19 -0
- package/dist/layout-exit.d.ts.map +1 -0
- package/dist/layout-exit.js +105 -0
- package/dist/layout-exit.js.map +1 -0
- package/dist/layout.d.ts +5 -0
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +50 -2
- package/dist/layout.js.map +1 -1
- package/dist/list-changes.d.ts +14 -0
- package/dist/list-changes.d.ts.map +1 -0
- package/dist/list-changes.js +251 -0
- package/dist/list-changes.js.map +1 -0
- package/dist/list-focus.d.ts +10 -0
- package/dist/list-focus.d.ts.map +1 -0
- package/dist/list-focus.js +103 -0
- package/dist/list-focus.js.map +1 -0
- package/dist/live-spring-driver.d.ts +2 -0
- package/dist/live-spring-driver.d.ts.map +1 -1
- package/dist/live-spring-driver.js +12 -0
- package/dist/live-spring-driver.js.map +1 -1
- package/dist/loader.d.ts +2 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +17 -15
- package/dist/loader.js.map +1 -1
- package/dist/motion-value.d.ts +52 -19
- package/dist/motion-value.d.ts.map +1 -1
- package/dist/motion-value.js +615 -40
- package/dist/motion-value.js.map +1 -1
- package/dist/reveal.d.ts.map +1 -1
- package/dist/reveal.js +4 -3
- package/dist/reveal.js.map +1 -1
- package/dist/scroll-linked.d.ts +2 -1
- package/dist/scroll-linked.d.ts.map +1 -1
- package/dist/scroll-linked.js +101 -4
- package/dist/scroll-linked.js.map +1 -1
- package/dist/scroll-source.d.ts +18 -0
- package/dist/scroll-source.d.ts.map +1 -0
- package/dist/scroll-source.js +28 -0
- package/dist/scroll-source.js.map +1 -0
- package/dist/shared-layout/native.d.ts +1 -0
- package/dist/shared-layout/native.d.ts.map +1 -1
- package/dist/shared-layout/native.js +2 -0
- package/dist/shared-layout/native.js.map +1 -1
- package/dist/shimmer.d.ts.map +1 -1
- package/dist/shimmer.js +6 -4
- package/dist/shimmer.js.map +1 -1
- package/dist/value-track.d.ts +4 -0
- package/dist/value-track.d.ts.map +1 -1
- package/dist/value-track.js +3 -0
- package/dist/value-track.js.map +1 -1
- package/dist/vue/index.d.ts +45 -1
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +41 -2
- package/dist/vue/index.js.map +1 -1
- package/dist/web/drag.d.ts +8 -0
- package/dist/web/drag.d.ts.map +1 -1
- package/dist/web/drag.js +68 -14
- package/dist/web/drag.js.map +1 -1
- package/dist/web/drop-zones.d.ts +2 -2
- package/dist/web/drop-zones.d.ts.map +1 -1
- package/dist/web/drop-zones.js +21 -4
- package/dist/web/drop-zones.js.map +1 -1
- package/dist/web/layout-exit.d.ts +9 -0
- package/dist/web/layout-exit.d.ts.map +1 -0
- package/dist/web/layout-exit.js +148 -0
- package/dist/web/layout-exit.js.map +1 -0
- package/dist/web/layout.d.ts +25 -8
- package/dist/web/layout.d.ts.map +1 -1
- package/dist/web/layout.js +83 -2
- package/dist/web/layout.js.map +1 -1
- package/dist/web/list-changes.d.ts +41 -0
- package/dist/web/list-changes.d.ts.map +1 -0
- package/dist/web/list-changes.js +126 -0
- package/dist/web/list-changes.js.map +1 -0
- package/dist/web/loading.d.ts +2 -1
- package/dist/web/loading.d.ts.map +1 -1
- package/dist/web/loading.js +19 -15
- package/dist/web/loading.js.map +1 -1
- package/dist/web/pointer.d.ts +2 -0
- package/dist/web/pointer.d.ts.map +1 -1
- package/dist/web/pointer.js +13 -0
- package/dist/web/pointer.js.map +1 -1
- package/dist/web/presentation-copy.d.ts +9 -0
- package/dist/web/presentation-copy.d.ts.map +1 -0
- package/dist/web/presentation-copy.js +104 -0
- package/dist/web/presentation-copy.js.map +1 -0
- package/dist/web/public.d.ts +6 -1
- package/dist/web/public.d.ts.map +1 -1
- package/dist/web/public.js +1 -0
- package/dist/web/public.js.map +1 -1
- package/dist/web/reveal.d.ts.map +1 -1
- package/dist/web/reveal.js +4 -3
- package/dist/web/reveal.js.map +1 -1
- package/dist/web/runtime.d.ts +7 -7
- package/dist/web/runtime.d.ts.map +1 -1
- package/dist/web/runtime.js +85 -8
- package/dist/web/runtime.js.map +1 -1
- package/dist/web/scroll.d.ts +12 -1
- package/dist/web/scroll.d.ts.map +1 -1
- package/dist/web/scroll.js +25 -0
- package/dist/web/scroll.js.map +1 -1
- package/dist/web/shared-layout.d.ts.map +1 -1
- package/dist/web/shared-layout.js +2 -101
- package/dist/web/shared-layout.js.map +1 -1
- package/dist/web/spring-value.d.ts +3 -2
- package/dist/web/spring-value.d.ts.map +1 -1
- package/dist/web/spring-value.js +5 -5
- package/dist/web/spring-value.js.map +1 -1
- package/dist/web/text-effect.d.ts.map +1 -1
- package/dist/web/text-effect.js +10 -16
- package/dist/web/text-effect.js.map +1 -1
- package/dist/web/value.d.ts +43 -4
- package/dist/web/value.d.ts.map +1 -1
- package/dist/web/value.js +139 -6
- package/dist/web/value.js.map +1 -1
- package/dist/web/vue/index.d.ts +49 -2
- package/dist/web/vue/index.d.ts.map +1 -1
- package/dist/web/vue/index.js +45 -2
- package/dist/web/vue/index.js.map +1 -1
- package/package.json +13 -3
- package/platforms/android/java/org/rafaelaugusto/jolt/LiveSpring.java +52 -6
- package/platforms/android/java/org/rafaelaugusto/jolt/PointerInput.java +26 -4
- package/platforms/android/java/org/rafaelaugusto/jolt/ScalarProgram.java +76 -0
- package/platforms/android/java/org/rafaelaugusto/jolt/ScrollSource.java +86 -0
- package/platforms/android/java/org/rafaelaugusto/jolt/SharedLayoutFlight.java +8 -2
- package/platforms/ios/src/JoltLiveSpring.h +2 -0
- package/platforms/ios/src/JoltLiveSpring.m +52 -6
- package/platforms/ios/src/JoltScalarProgram.h +9 -0
- package/platforms/ios/src/JoltScalarProgram.m +80 -0
- package/platforms/ios/src/JoltScrollSource.h +11 -0
- package/platforms/ios/src/JoltScrollSource.m +57 -0
- package/platforms/ios/src/JoltSharedLayoutFlight.h +1 -0
- package/platforms/ios/src/JoltSharedLayoutFlight.m +7 -1
- package/platforms/ios/src/module.modulemap +1 -0
- package/src/android-plugin.d.ts +25 -0
- package/src/animate.ts +4 -4
- package/src/core/drop.ts +123 -5
- package/src/core/layout-exit.ts +43 -0
- package/src/core/list-changes.ts +206 -0
- package/src/core/loading.ts +172 -0
- package/src/core/numeric-map.ts +1 -1
- package/src/core/preset-recipe.ts +6 -2
- package/src/core/scalar-program.ts +69 -0
- package/src/core/scalar.ts +125 -0
- package/src/core/text-pieces.ts +52 -0
- package/src/drag.ts +81 -38
- package/src/drop-zones.ts +13 -3
- package/src/engine.ts +8 -3
- package/src/index.ts +8 -0
- package/src/ios-plugin.d.ts +17 -0
- package/src/layout-exit.ts +120 -0
- package/src/layout.ts +57 -1
- package/src/list-changes.ts +317 -0
- package/src/list-focus.ts +101 -0
- package/src/live-spring-driver.ts +18 -0
- package/src/loader.ts +23 -20
- package/src/motion-value.ts +689 -50
- package/src/reveal.ts +4 -3
- package/src/scroll-linked.ts +121 -5
- package/src/scroll-source.ts +60 -0
- package/src/shared-layout/native.ts +3 -0
- package/src/shimmer.ts +6 -4
- package/src/value-track.ts +7 -0
- package/src/vue/index.ts +51 -0
- package/src/web/drag.ts +70 -12
- package/src/web/drop-zones.ts +31 -6
- package/src/web/layout-exit.ts +179 -0
- package/src/web/layout.ts +103 -2
- package/src/web/list-changes.ts +194 -0
- package/src/web/loading.ts +38 -17
- package/src/web/pointer.ts +14 -0
- package/src/web/presentation-copy.ts +125 -0
- package/src/web/public.ts +17 -0
- package/src/web/reveal.ts +7 -8
- package/src/web/runtime.ts +116 -9
- package/src/web/scroll.ts +41 -0
- package/src/web/shared-layout.ts +3 -115
- package/src/web/spring-value.ts +7 -6
- package/src/web/text-effect.ts +20 -17
- package/src/web/value.ts +167 -12
- package/src/web/vue/index.ts +51 -0
package/dist/motion-value.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createNativeScrollSource, nativeScrollAvailable, } from './scroll-source.js';
|
|
2
|
+
import { scalarOperations, } from './core/scalar.js';
|
|
3
|
+
import { scalarProgram } from './core/scalar-program.js';
|
|
4
|
+
import { numericMap } from './core/numeric-map.js';
|
|
5
|
+
import { Application, isIOS, Color, ScrollView, } from '@nativescript/core';
|
|
2
6
|
import { isLiveEdge, isLivePaint, livePaintChanges, overlapsLivePaint, validateLivePaint, } from './live-paint.js';
|
|
3
7
|
import { toViews } from './animate.js';
|
|
4
8
|
import { colorMixer, isColorProperty, parseColor, validateColorTarget, } from './color.js';
|
|
@@ -15,7 +19,7 @@ import { createTrack, instantTrack } from './track.js';
|
|
|
15
19
|
import { resolveTransition, springs, } from './transition.js';
|
|
16
20
|
import { playbackSource } from './playback.js';
|
|
17
21
|
import { TimedAnimation } from './timed-animation.js';
|
|
18
|
-
import { compositionSpan, valueTrack } from './value-track.js';
|
|
22
|
+
import { compositionSpan, valueTrack, sampledValueTrack, } from './value-track.js';
|
|
19
23
|
import { ValueObservers, } from './value-observers.js';
|
|
20
24
|
const bound = new WeakMap();
|
|
21
25
|
class Derived {
|
|
@@ -23,27 +27,102 @@ class Derived {
|
|
|
23
27
|
read;
|
|
24
28
|
color;
|
|
25
29
|
mappings;
|
|
30
|
+
disposedMapping = false;
|
|
31
|
+
frozenMapping;
|
|
32
|
+
releases = new Set();
|
|
33
|
+
endings = new Set();
|
|
34
|
+
get disposed() {
|
|
35
|
+
return this.disposedMapping || (this.source?.disposed ?? false);
|
|
36
|
+
}
|
|
37
|
+
onDispose(callback) {
|
|
38
|
+
this.endings.add(callback);
|
|
39
|
+
return () => {
|
|
40
|
+
this.endings.delete(callback);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
dispose() {
|
|
44
|
+
this.finishDerived();
|
|
45
|
+
}
|
|
46
|
+
finishDerived() {
|
|
47
|
+
if (this.disposedMapping)
|
|
48
|
+
return;
|
|
49
|
+
if (this.source)
|
|
50
|
+
this.frozenMapping = this.read(this.root.raw());
|
|
51
|
+
this.disposedMapping = true;
|
|
52
|
+
for (const stop of this.releases)
|
|
53
|
+
stop();
|
|
54
|
+
this.releases.clear();
|
|
55
|
+
for (const binding of [...this.root.bindings])
|
|
56
|
+
if (binding.source === this)
|
|
57
|
+
release(binding);
|
|
58
|
+
for (const callback of [...this.endings])
|
|
59
|
+
callback();
|
|
60
|
+
this.endings.clear();
|
|
61
|
+
}
|
|
62
|
+
getVelocity() {
|
|
63
|
+
if (this.color || this.disposed)
|
|
64
|
+
return 0;
|
|
65
|
+
let value = this.root.raw(), velocity = this.root.rawVelocity();
|
|
66
|
+
for (const map of this.mappings) {
|
|
67
|
+
const last = map.input.length - 1;
|
|
68
|
+
if (map.clamp && value <= map.input[0]) {
|
|
69
|
+
value = map.output[0];
|
|
70
|
+
velocity = 0;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (map.clamp && value >= map.input[last]) {
|
|
74
|
+
value = map.output[last];
|
|
75
|
+
velocity = 0;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
let i = 0;
|
|
79
|
+
while (i < last - 1 && value > map.input[i + 1])
|
|
80
|
+
i++;
|
|
81
|
+
const span = map.input[i + 1] - map.input[i], slope = span > 0 ? (map.output[i + 1] - map.output[i]) / span : 0;
|
|
82
|
+
const fraction = span > 0 ? (value - map.input[i]) / span : value < map.input[i] ? 0 : 1;
|
|
83
|
+
value = map.output[i] + (map.output[i + 1] - map.output[i]) * fraction;
|
|
84
|
+
velocity *= slope;
|
|
85
|
+
}
|
|
86
|
+
return velocity;
|
|
87
|
+
}
|
|
26
88
|
constructor(source, read, color, mappings = []) {
|
|
27
89
|
this.source = source;
|
|
28
90
|
this.read = read;
|
|
29
91
|
this.color = color;
|
|
30
92
|
this.mappings = mappings;
|
|
93
|
+
Object.assign(this, scalarOperations((op, operand, maximum) => {
|
|
94
|
+
if (this.color || this.disposed)
|
|
95
|
+
throw new TypeError('Scalar operations require a live numeric source.');
|
|
96
|
+
if (operand !== undefined &&
|
|
97
|
+
!(operand instanceof Derived) &&
|
|
98
|
+
(typeof operand !== 'number' || !Number.isFinite(operand)))
|
|
99
|
+
throw new TypeError('Expected a finite number or a Jolt numeric value.');
|
|
100
|
+
return new GraphRoot(this, op, operand, maximum);
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
get depth() {
|
|
104
|
+
return this.source ? this.source.depth + this.mappings.length : 0;
|
|
31
105
|
}
|
|
32
106
|
get root() {
|
|
33
107
|
return this.source ?? this;
|
|
34
108
|
}
|
|
35
109
|
get() {
|
|
36
|
-
const value = this.read(this.root.raw());
|
|
110
|
+
const value = this.frozenMapping ?? this.read(this.root.raw());
|
|
37
111
|
return this.color ? new Color(value) : value;
|
|
38
112
|
}
|
|
39
113
|
subscribe(listener, options) {
|
|
40
|
-
|
|
114
|
+
if (this.disposed)
|
|
115
|
+
throw new Error('The value is disposed.');
|
|
116
|
+
const release = this.root.retainObservation();
|
|
41
117
|
try {
|
|
42
118
|
const stop = this.root.observers.subscribe(this.read, this.color, listener, options);
|
|
43
|
-
|
|
119
|
+
const cleanup = () => {
|
|
44
120
|
stop();
|
|
45
121
|
release();
|
|
122
|
+
this.releases.delete(cleanup);
|
|
46
123
|
};
|
|
124
|
+
this.releases.add(cleanup);
|
|
125
|
+
return cleanup;
|
|
47
126
|
}
|
|
48
127
|
catch (error) {
|
|
49
128
|
release();
|
|
@@ -53,6 +132,8 @@ class Derived {
|
|
|
53
132
|
to(input, output, options) {
|
|
54
133
|
if (this.color)
|
|
55
134
|
throw new TypeError('A color cannot be mapped again.');
|
|
135
|
+
if (this.disposed)
|
|
136
|
+
throw new Error('The value is disposed.');
|
|
56
137
|
const map = mapping(input, output, options);
|
|
57
138
|
const read = this.read;
|
|
58
139
|
return new Derived(this.root, (value) => map.read(read(value)), map.color, [
|
|
@@ -66,7 +147,53 @@ class Derived {
|
|
|
66
147
|
]);
|
|
67
148
|
}
|
|
68
149
|
}
|
|
150
|
+
function retainAll(values, retain) {
|
|
151
|
+
const releases = [];
|
|
152
|
+
try {
|
|
153
|
+
for (const value of values)
|
|
154
|
+
releases.push(retain(value));
|
|
155
|
+
return releases;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
for (const release of releases.reverse())
|
|
159
|
+
release();
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
69
163
|
class Root extends Derived {
|
|
164
|
+
observations = 0;
|
|
165
|
+
observationListeners = new Set();
|
|
166
|
+
get observed() {
|
|
167
|
+
return this.observations > 0;
|
|
168
|
+
}
|
|
169
|
+
observationDemandChanged() {
|
|
170
|
+
for (const callback of [...this.observationListeners])
|
|
171
|
+
callback();
|
|
172
|
+
}
|
|
173
|
+
retainObservation() {
|
|
174
|
+
if (this.disposed)
|
|
175
|
+
throw new Error('The value is disposed.');
|
|
176
|
+
this.observations++;
|
|
177
|
+
let release;
|
|
178
|
+
try {
|
|
179
|
+
this.observationDemandChanged();
|
|
180
|
+
release = this.retainConsumer();
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
this.observations--;
|
|
184
|
+
this.observationDemandChanged();
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
let ended = false;
|
|
188
|
+
return () => {
|
|
189
|
+
if (ended)
|
|
190
|
+
return;
|
|
191
|
+
ended = true;
|
|
192
|
+
release();
|
|
193
|
+
this.observations--;
|
|
194
|
+
this.observationDemandChanged();
|
|
195
|
+
};
|
|
196
|
+
}
|
|
70
197
|
consumers = 0;
|
|
71
198
|
demandListeners = new Set();
|
|
72
199
|
get demanded() {
|
|
@@ -117,6 +244,47 @@ class Root extends Derived {
|
|
|
117
244
|
result += this.part(key, time);
|
|
118
245
|
return result;
|
|
119
246
|
}
|
|
247
|
+
rawVelocity() {
|
|
248
|
+
return this.disposed
|
|
249
|
+
? 0
|
|
250
|
+
: [...this.runs.keys()].reduce((sum, key) => sum + this.channelVelocity(key), 0);
|
|
251
|
+
}
|
|
252
|
+
snapshot() {
|
|
253
|
+
const now = getDriver().now();
|
|
254
|
+
let rest = 0;
|
|
255
|
+
const parts = [];
|
|
256
|
+
for (const [key, value] of this.rests)
|
|
257
|
+
if (!this.runs.has(key))
|
|
258
|
+
rest += value;
|
|
259
|
+
for (const [key, run] of this.runs) {
|
|
260
|
+
if (run.animation.paused)
|
|
261
|
+
rest += this.part(key, now);
|
|
262
|
+
else
|
|
263
|
+
parts.push({
|
|
264
|
+
track: run.track,
|
|
265
|
+
base: run.base,
|
|
266
|
+
span: run.span,
|
|
267
|
+
elapsed: this.runTime(run, now),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
return { rest, parts };
|
|
271
|
+
}
|
|
272
|
+
dispose() {
|
|
273
|
+
if (this.disposed)
|
|
274
|
+
return;
|
|
275
|
+
this.stop();
|
|
276
|
+
for (const binding of [...this.bindings])
|
|
277
|
+
release(binding);
|
|
278
|
+
this.cancelPresentation?.();
|
|
279
|
+
this.composer?.dispose();
|
|
280
|
+
this.composer = undefined;
|
|
281
|
+
this.observers.clear();
|
|
282
|
+
super.dispose();
|
|
283
|
+
for (const listener of [...this.listeners])
|
|
284
|
+
listener();
|
|
285
|
+
this.listeners.clear();
|
|
286
|
+
this.demandListeners.clear();
|
|
287
|
+
}
|
|
120
288
|
/** Drag input owns only the base; bounds and snap points stay in base units. */
|
|
121
289
|
base() {
|
|
122
290
|
return this.part('');
|
|
@@ -133,11 +301,11 @@ class Root extends Derived {
|
|
|
133
301
|
/** Internal development snapshot; reading it installs no observers. */
|
|
134
302
|
inspect() {
|
|
135
303
|
return {
|
|
136
|
-
velocity: [...this.runs.keys()].reduce((sum, key) => sum + this.
|
|
304
|
+
velocity: [...this.runs.keys()].reduce((sum, key) => sum + this.channelVelocity(key), 0),
|
|
137
305
|
resources: this.bindings.size + this.listeners.size + this.observers.size + this.runs.size,
|
|
138
306
|
};
|
|
139
307
|
}
|
|
140
|
-
|
|
308
|
+
channelVelocity(key) {
|
|
141
309
|
const run = this.runs.get(key);
|
|
142
310
|
if (!run || run.animation.paused)
|
|
143
311
|
return 0;
|
|
@@ -145,6 +313,8 @@ class Root extends Derived {
|
|
|
145
313
|
}
|
|
146
314
|
animate(target, transition = {}) {
|
|
147
315
|
const options = typeof transition === 'string' ? springOf(transition) : transition;
|
|
316
|
+
if (this.disposed)
|
|
317
|
+
throw new Error('The value is disposed.');
|
|
148
318
|
const key = options.layer === undefined ? '' : layerName(options.layer);
|
|
149
319
|
const from = this.part(key);
|
|
150
320
|
const frames = (typeof target === 'number' ? [null, target] : [...target]).map((frame) => (frame === null ? from : frame));
|
|
@@ -155,7 +325,7 @@ class Root extends Derived {
|
|
|
155
325
|
const resolved = resolveTransition(options, 'x', frames.length);
|
|
156
326
|
const base = Math.min(...frames);
|
|
157
327
|
const span = Math.max(...frames) - base;
|
|
158
|
-
const velocity = this.
|
|
328
|
+
const velocity = this.channelVelocity(key);
|
|
159
329
|
if (resolved.curve.type === 'gravity') {
|
|
160
330
|
// Acceleration and velocity belong to the value's units, not normalized progress.
|
|
161
331
|
const track = createTrack('x', frames, resolved, velocity);
|
|
@@ -219,6 +389,8 @@ class Root extends Derived {
|
|
|
219
389
|
return animation;
|
|
220
390
|
}
|
|
221
391
|
set(value) {
|
|
392
|
+
if (this.disposed)
|
|
393
|
+
throw new Error('The value is disposed.');
|
|
222
394
|
if (!Number.isFinite(value))
|
|
223
395
|
throw new RangeError(`A motion value takes a finite number, got ${value}.`);
|
|
224
396
|
for (const key of [...this.runs.keys()])
|
|
@@ -449,6 +621,16 @@ class Root extends Derived {
|
|
|
449
621
|
}
|
|
450
622
|
class SpringRoot extends Root {
|
|
451
623
|
input;
|
|
624
|
+
observerSource;
|
|
625
|
+
observationDemandChanged() {
|
|
626
|
+
if (this.observed && !this.observerSource)
|
|
627
|
+
this.observerSource = this.input.root.retainObservation();
|
|
628
|
+
else if (!this.observed) {
|
|
629
|
+
this.observerSource?.();
|
|
630
|
+
this.observerSource = undefined;
|
|
631
|
+
}
|
|
632
|
+
super.observationDemandChanged();
|
|
633
|
+
}
|
|
452
634
|
releaseDemand;
|
|
453
635
|
externalActive = false;
|
|
454
636
|
demandChanged() {
|
|
@@ -514,14 +696,15 @@ class SpringRoot extends Root {
|
|
|
514
696
|
throw new RangeError('springValue bounce must be finite.');
|
|
515
697
|
super(initial);
|
|
516
698
|
this.input = input;
|
|
517
|
-
this.node = liveSpringDriver().create(initial, physics, instant || reducedMotion());
|
|
518
699
|
const root = source.root;
|
|
700
|
+
const graphLease = root instanceof GraphRoot && root.live ? root.nativeLease() : undefined;
|
|
701
|
+
this.node = liveSpringDriver().create(initial, physics, instant || reducedMotion());
|
|
519
702
|
try {
|
|
520
703
|
let update;
|
|
521
|
-
if (root instanceof SpringRoot) {
|
|
704
|
+
if (root instanceof SpringRoot || graphLease) {
|
|
522
705
|
if (root.disposed)
|
|
523
706
|
throw new Error('Cannot follow a disposed spring value.');
|
|
524
|
-
this.node.follow(root.node, source.mappings);
|
|
707
|
+
this.node.follow(graphLease?.node ?? root.node, source.mappings);
|
|
525
708
|
update = () => this.notify();
|
|
526
709
|
}
|
|
527
710
|
else {
|
|
@@ -562,6 +745,7 @@ class SpringRoot extends Root {
|
|
|
562
745
|
root.listeners.add(update);
|
|
563
746
|
this.releaseSource = () => {
|
|
564
747
|
root.listeners.delete(update);
|
|
748
|
+
graphLease?.release();
|
|
565
749
|
};
|
|
566
750
|
this.releaseReduced = onReducedMotion((reduced) => {
|
|
567
751
|
this.node.reduced(instant || reduced);
|
|
@@ -612,7 +796,10 @@ class SpringRoot extends Root {
|
|
|
612
796
|
this.notify();
|
|
613
797
|
}
|
|
614
798
|
getVelocity() {
|
|
615
|
-
return this.
|
|
799
|
+
return this.rawVelocity();
|
|
800
|
+
}
|
|
801
|
+
rawVelocity() {
|
|
802
|
+
return this.ended || this.held || this.background ? 0 : this.node.velocity();
|
|
616
803
|
}
|
|
617
804
|
plan() {
|
|
618
805
|
throw new TypeError('A live spring cannot be sampled as a fixed track. Bind it to transforms or opacity.');
|
|
@@ -628,6 +815,8 @@ class SpringRoot extends Root {
|
|
|
628
815
|
this.ended = true;
|
|
629
816
|
this.demandChanged();
|
|
630
817
|
this.releaseSource();
|
|
818
|
+
this.observerSource?.();
|
|
819
|
+
this.observerSource = undefined;
|
|
631
820
|
this.releaseReduced();
|
|
632
821
|
Application.off(Application.suspendEvent, this.suspend);
|
|
633
822
|
Application.off(Application.resumeEvent, this.resume);
|
|
@@ -635,6 +824,7 @@ class SpringRoot extends Root {
|
|
|
635
824
|
release(binding);
|
|
636
825
|
this.node.dispose();
|
|
637
826
|
this.observers.clear();
|
|
827
|
+
this.finishDerived();
|
|
638
828
|
for (const listener of [...this.listeners])
|
|
639
829
|
listener();
|
|
640
830
|
this.listeners.clear();
|
|
@@ -670,6 +860,285 @@ export function liveValueInput(value) {
|
|
|
670
860
|
},
|
|
671
861
|
};
|
|
672
862
|
}
|
|
863
|
+
/** Compile finite sources once; live sources stay in the native evaluator's ordered frame batch. */
|
|
864
|
+
class GraphRoot extends Root {
|
|
865
|
+
left;
|
|
866
|
+
operation;
|
|
867
|
+
right;
|
|
868
|
+
maximum;
|
|
869
|
+
level;
|
|
870
|
+
sources;
|
|
871
|
+
program;
|
|
872
|
+
live;
|
|
873
|
+
evaluate;
|
|
874
|
+
stops = [];
|
|
875
|
+
demandStops = [];
|
|
876
|
+
observerStops = [];
|
|
877
|
+
graphNode;
|
|
878
|
+
bridges = [];
|
|
879
|
+
leases = 0;
|
|
880
|
+
cached;
|
|
881
|
+
last;
|
|
882
|
+
suspendGraph = () => this.graphNode?.paused(true);
|
|
883
|
+
resumeGraph = () => this.graphNode?.paused(false);
|
|
884
|
+
constructor(left, operation, right, maximum) {
|
|
885
|
+
const sources = [...new Set([left, ...(right instanceof Derived ? [right] : [])])];
|
|
886
|
+
if (sources.some((source) => source.color || source.disposed || source.depth >= 32))
|
|
887
|
+
throw new TypeError('Scalar operations need live numeric sources within 32 levels.');
|
|
888
|
+
const graph = compileGraph(left, operation, right, maximum);
|
|
889
|
+
const evaluate = scalarProgram(graph.program, graph.sources.length);
|
|
890
|
+
const initial = evaluate(graph.sources.map((root) => ({ value: root.raw(), velocity: root.rawVelocity() })));
|
|
891
|
+
super(initial.value);
|
|
892
|
+
this.left = left;
|
|
893
|
+
this.operation = operation;
|
|
894
|
+
this.right = right;
|
|
895
|
+
this.maximum = maximum;
|
|
896
|
+
this.last = initial;
|
|
897
|
+
this.sources = graph.sources;
|
|
898
|
+
this.program = graph.program;
|
|
899
|
+
this.evaluate = evaluate;
|
|
900
|
+
this.level = Math.max(...sources.map((source) => source.depth)) + 1;
|
|
901
|
+
this.live = this.sources.some((root) => root instanceof SpringRoot);
|
|
902
|
+
const update = () => {
|
|
903
|
+
if (this.disposed)
|
|
904
|
+
return;
|
|
905
|
+
if (sources.some((source) => source.disposed) ||
|
|
906
|
+
this.sources.some((root) => root.disposed)) {
|
|
907
|
+
this.dispose();
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
this.cached = undefined;
|
|
911
|
+
for (const { root, node } of this.bridges) {
|
|
912
|
+
const snapshot = root.inputs(getDriver().now());
|
|
913
|
+
node.inputs(snapshot.rest, snapshot.inputs);
|
|
914
|
+
}
|
|
915
|
+
this.changed();
|
|
916
|
+
};
|
|
917
|
+
for (const root of this.sources) {
|
|
918
|
+
root.listeners.add(update);
|
|
919
|
+
this.stops.push(() => root.listeners.delete(update));
|
|
920
|
+
}
|
|
921
|
+
for (const source of sources)
|
|
922
|
+
this.stops.push(source.onDispose(() => this.dispose()));
|
|
923
|
+
Application.on(Application.suspendEvent, this.suspendGraph);
|
|
924
|
+
Application.on(Application.resumeEvent, this.resumeGraph);
|
|
925
|
+
}
|
|
926
|
+
get depth() {
|
|
927
|
+
return this.level ?? 0;
|
|
928
|
+
}
|
|
929
|
+
raw() {
|
|
930
|
+
if (this.disposed)
|
|
931
|
+
return this.last.value;
|
|
932
|
+
return this.evaluate(this.sources.map((root) => ({ value: root.raw(), velocity: root.rawVelocity() }))).value;
|
|
933
|
+
}
|
|
934
|
+
rawVelocity() {
|
|
935
|
+
return this.disposed
|
|
936
|
+
? 0
|
|
937
|
+
: this.evaluate(this.sources.map((root) => ({
|
|
938
|
+
value: root.raw(),
|
|
939
|
+
velocity: root.rawVelocity(),
|
|
940
|
+
}))).velocity;
|
|
941
|
+
}
|
|
942
|
+
get running() {
|
|
943
|
+
return !this.disposed && this.sources.some((root) => root.running);
|
|
944
|
+
}
|
|
945
|
+
demandChanged() {
|
|
946
|
+
const active = !this.disposed && (this.demanded || this.leases > 0);
|
|
947
|
+
if (active && !this.demandStops.length)
|
|
948
|
+
this.demandStops = retainAll(this.sources, (root) => root.retainConsumer());
|
|
949
|
+
else if (!active) {
|
|
950
|
+
for (const stop of this.demandStops)
|
|
951
|
+
stop();
|
|
952
|
+
this.demandStops = [];
|
|
953
|
+
}
|
|
954
|
+
super.demandChanged();
|
|
955
|
+
}
|
|
956
|
+
observationDemandChanged() {
|
|
957
|
+
if (this.observed && !this.observerStops.length)
|
|
958
|
+
this.observerStops = retainAll(this.sources, (root) => root.retainObservation());
|
|
959
|
+
else if (!this.observed) {
|
|
960
|
+
for (const stop of this.observerStops)
|
|
961
|
+
stop();
|
|
962
|
+
this.observerStops = [];
|
|
963
|
+
}
|
|
964
|
+
super.observationDemandChanged();
|
|
965
|
+
}
|
|
966
|
+
timeline() {
|
|
967
|
+
return this.sources.map((root) => root.snapshot());
|
|
968
|
+
}
|
|
969
|
+
composerNode() {
|
|
970
|
+
const snapshots = this.timeline();
|
|
971
|
+
if (!this.live &&
|
|
972
|
+
!compositionSpan(snapshots.flatMap((snapshot) => snapshot.parts))?.windowed)
|
|
973
|
+
return undefined;
|
|
974
|
+
return this.ensureNode();
|
|
975
|
+
}
|
|
976
|
+
nativeLease() {
|
|
977
|
+
const node = this.ensureNode();
|
|
978
|
+
this.leases++;
|
|
979
|
+
try {
|
|
980
|
+
this.demandChanged();
|
|
981
|
+
}
|
|
982
|
+
catch (error) {
|
|
983
|
+
this.leases--;
|
|
984
|
+
this.demandChanged();
|
|
985
|
+
this.settle();
|
|
986
|
+
throw error;
|
|
987
|
+
}
|
|
988
|
+
let released = false;
|
|
989
|
+
return {
|
|
990
|
+
node,
|
|
991
|
+
release: () => {
|
|
992
|
+
if (released)
|
|
993
|
+
return;
|
|
994
|
+
released = true;
|
|
995
|
+
this.leases--;
|
|
996
|
+
this.demandChanged();
|
|
997
|
+
this.settle();
|
|
998
|
+
},
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
ensureNode() {
|
|
1002
|
+
if (this.graphNode)
|
|
1003
|
+
return this.graphNode;
|
|
1004
|
+
const driver = liveSpringDriver();
|
|
1005
|
+
try {
|
|
1006
|
+
const inputs = this.sources.map((root) => {
|
|
1007
|
+
if (root instanceof SpringRoot)
|
|
1008
|
+
return root.node;
|
|
1009
|
+
const node = driver.create(root.raw(), stillPhysics, true);
|
|
1010
|
+
this.bridges.push({ root, node });
|
|
1011
|
+
const snapshot = root.inputs(getDriver().now());
|
|
1012
|
+
node.inputs(snapshot.rest, snapshot.inputs);
|
|
1013
|
+
return node;
|
|
1014
|
+
});
|
|
1015
|
+
const node = driver.create(this.raw(), stillPhysics, true);
|
|
1016
|
+
this.graphNode = node;
|
|
1017
|
+
if (!node.compute)
|
|
1018
|
+
throw new Error('Combined live values need rebuilt Jolt native classes.');
|
|
1019
|
+
node.compute(inputs, this.program);
|
|
1020
|
+
return node;
|
|
1021
|
+
}
|
|
1022
|
+
catch (error) {
|
|
1023
|
+
this.clearNode();
|
|
1024
|
+
throw error;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
clearNode() {
|
|
1028
|
+
this.graphNode?.dispose();
|
|
1029
|
+
this.graphNode = undefined;
|
|
1030
|
+
for (const { node } of this.bridges)
|
|
1031
|
+
node.dispose();
|
|
1032
|
+
this.bridges = [];
|
|
1033
|
+
}
|
|
1034
|
+
settle() {
|
|
1035
|
+
if (!this.demanded && !this.leases)
|
|
1036
|
+
this.clearNode();
|
|
1037
|
+
}
|
|
1038
|
+
presentationTrack() {
|
|
1039
|
+
if (this.cached)
|
|
1040
|
+
return this.cached;
|
|
1041
|
+
const snapshots = this.timeline();
|
|
1042
|
+
const at = (time) => this.evaluate(snapshots.map((snapshot) => ({
|
|
1043
|
+
value: snapshot.parts.reduce((sum, part) => sum + part.base + part.span * part.track.valueAt(part.elapsed + time), snapshot.rest),
|
|
1044
|
+
velocity: snapshot.parts.reduce((sum, part) => sum + part.span * part.track.velocityAt(part.elapsed + time), 0),
|
|
1045
|
+
}))).value;
|
|
1046
|
+
const { track } = sampledValueTrack(snapshots.flatMap((snapshot) => snapshot.parts), at);
|
|
1047
|
+
return (this.cached = { track, started: getDriver().now() });
|
|
1048
|
+
}
|
|
1049
|
+
plan(binding) {
|
|
1050
|
+
const source = this.presentationTrack().track;
|
|
1051
|
+
const at = (value) => isDecorationProperty(binding.property)
|
|
1052
|
+
? clampDecoration(binding.property, binding.read(value))
|
|
1053
|
+
: binding.read(value);
|
|
1054
|
+
return {
|
|
1055
|
+
property: binding.property,
|
|
1056
|
+
keyframes: [],
|
|
1057
|
+
transition: still,
|
|
1058
|
+
track: () => {
|
|
1059
|
+
if (reducedMotion() &&
|
|
1060
|
+
binding.property !== 'opacity' &&
|
|
1061
|
+
!isColorProperty(binding.property))
|
|
1062
|
+
return instantTrack(binding.property, at(source.to));
|
|
1063
|
+
return {
|
|
1064
|
+
...source,
|
|
1065
|
+
property: binding.property,
|
|
1066
|
+
values: source.values.map(at),
|
|
1067
|
+
to: at(source.to),
|
|
1068
|
+
valueAt: (time) => at(source.valueAt(time)),
|
|
1069
|
+
velocityAt: (time) => (at(source.valueAt(time + 0.5)) - at(source.valueAt(time - 0.5))) * 1000,
|
|
1070
|
+
};
|
|
1071
|
+
},
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
elapsed() {
|
|
1075
|
+
return getDriver().now() - this.presentationTrack().started;
|
|
1076
|
+
}
|
|
1077
|
+
captureTime() {
|
|
1078
|
+
const start = this.presentationTrack().started;
|
|
1079
|
+
return () => getDriver().now() - start;
|
|
1080
|
+
}
|
|
1081
|
+
dispose() {
|
|
1082
|
+
if (this.disposed)
|
|
1083
|
+
return;
|
|
1084
|
+
this.last = { value: this.raw(), velocity: 0 };
|
|
1085
|
+
for (const stop of this.stops)
|
|
1086
|
+
stop();
|
|
1087
|
+
this.stops = [];
|
|
1088
|
+
for (const stop of this.observerStops)
|
|
1089
|
+
stop();
|
|
1090
|
+
this.observerStops = [];
|
|
1091
|
+
for (const stop of this.demandStops)
|
|
1092
|
+
stop();
|
|
1093
|
+
this.demandStops = [];
|
|
1094
|
+
Application.off(Application.suspendEvent, this.suspendGraph);
|
|
1095
|
+
Application.off(Application.resumeEvent, this.resumeGraph);
|
|
1096
|
+
super.dispose();
|
|
1097
|
+
this.clearNode();
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
function compileGraph(left, operation, right, maximum) {
|
|
1101
|
+
const sources = [], program = [];
|
|
1102
|
+
const known = new Map();
|
|
1103
|
+
const append = (node) => {
|
|
1104
|
+
program.push(node);
|
|
1105
|
+
return program.length - 1;
|
|
1106
|
+
};
|
|
1107
|
+
const walk = (value) => {
|
|
1108
|
+
if (typeof value === 'number')
|
|
1109
|
+
return append({ op: 'constant', value });
|
|
1110
|
+
const cached = known.get(value);
|
|
1111
|
+
if (cached !== undefined)
|
|
1112
|
+
return cached;
|
|
1113
|
+
const root = value.root;
|
|
1114
|
+
let index;
|
|
1115
|
+
if (root instanceof GraphRoot) {
|
|
1116
|
+
const a = walk(root.left), b = root.right === undefined ? undefined : walk(root.right);
|
|
1117
|
+
index = append({ op: root.operation, a, b, maximum: root.maximum });
|
|
1118
|
+
}
|
|
1119
|
+
else {
|
|
1120
|
+
let input = sources.indexOf(root);
|
|
1121
|
+
if (input < 0) {
|
|
1122
|
+
input = sources.length;
|
|
1123
|
+
sources.push(root);
|
|
1124
|
+
}
|
|
1125
|
+
index = append({ op: 'input', a: input });
|
|
1126
|
+
}
|
|
1127
|
+
for (const map of value.mappings)
|
|
1128
|
+
index = append({
|
|
1129
|
+
op: 'map',
|
|
1130
|
+
a: index,
|
|
1131
|
+
input: map.input,
|
|
1132
|
+
output: map.output,
|
|
1133
|
+
clamp: map.clamp,
|
|
1134
|
+
});
|
|
1135
|
+
known.set(value, index);
|
|
1136
|
+
return index;
|
|
1137
|
+
};
|
|
1138
|
+
const a = walk(left), b = right === undefined ? undefined : walk(right);
|
|
1139
|
+
append({ op: operation, a, b, maximum });
|
|
1140
|
+
return { sources, program };
|
|
1141
|
+
}
|
|
673
1142
|
function layerName(name) {
|
|
674
1143
|
if (typeof name !== 'string' || !name.length)
|
|
675
1144
|
throw new TypeError('A layer is named by a nonempty string.');
|
|
@@ -694,7 +1163,9 @@ export function motionValue(initial = 0) {
|
|
|
694
1163
|
return new Root(initial);
|
|
695
1164
|
}
|
|
696
1165
|
export function isMotionValue(target) {
|
|
697
|
-
return target instanceof Root &&
|
|
1166
|
+
return (target instanceof Root &&
|
|
1167
|
+
!(target instanceof SpringRoot) &&
|
|
1168
|
+
!(target instanceof GraphRoot));
|
|
698
1169
|
}
|
|
699
1170
|
export function asRoot(value) {
|
|
700
1171
|
return value;
|
|
@@ -715,6 +1186,8 @@ export function bind(target, bindings) {
|
|
|
715
1186
|
for (const [key, source] of Object.entries(bindings)) {
|
|
716
1187
|
if (source === undefined)
|
|
717
1188
|
continue;
|
|
1189
|
+
if (source instanceof Derived && source.disposed)
|
|
1190
|
+
throw new Error('The value is disposed.');
|
|
718
1191
|
if (!(source instanceof Derived))
|
|
719
1192
|
throw new TypeError(`"${key}" needs a motion value, got ${String(source)}.`);
|
|
720
1193
|
const properties = key === 'scale'
|
|
@@ -779,6 +1252,7 @@ function attach(view, property, source) {
|
|
|
779
1252
|
return attachSpring(view, property, source, root);
|
|
780
1253
|
let native, composer;
|
|
781
1254
|
let releaseMix;
|
|
1255
|
+
let releaseDemand;
|
|
782
1256
|
const detach = () => {
|
|
783
1257
|
if (!native)
|
|
784
1258
|
return;
|
|
@@ -786,6 +1260,9 @@ function attach(view, property, source) {
|
|
|
786
1260
|
releaseMix?.();
|
|
787
1261
|
releaseMix = undefined;
|
|
788
1262
|
native = composer = undefined;
|
|
1263
|
+
releaseDemand?.();
|
|
1264
|
+
releaseDemand = undefined;
|
|
1265
|
+
root.settle();
|
|
789
1266
|
syncLiveSprings(view);
|
|
790
1267
|
};
|
|
791
1268
|
const binding = {
|
|
@@ -797,7 +1274,9 @@ function attach(view, property, source) {
|
|
|
797
1274
|
sync() {
|
|
798
1275
|
if (!view.isLoaded || !view.nativeViewProtected)
|
|
799
1276
|
return;
|
|
800
|
-
const node = layerable(property) && !source.color
|
|
1277
|
+
const node = root instanceof GraphRoot || (layerable(property) && !source.color)
|
|
1278
|
+
? root.composerNode()
|
|
1279
|
+
: undefined;
|
|
801
1280
|
if (node) {
|
|
802
1281
|
if (composer === node)
|
|
803
1282
|
return;
|
|
@@ -808,6 +1287,7 @@ function attach(view, property, source) {
|
|
|
808
1287
|
const handle = node.bind(view, property, source.mappings);
|
|
809
1288
|
native = handle;
|
|
810
1289
|
composer = node;
|
|
1290
|
+
releaseDemand = root.retainConsumer();
|
|
811
1291
|
releaseMix = mixFor(view, property).attachLive({
|
|
812
1292
|
read: () => handle.value(),
|
|
813
1293
|
layers: (layers) => handle.layers(layers),
|
|
@@ -1226,52 +1706,147 @@ function springOf(name) {
|
|
|
1226
1706
|
throw new Error(`Unknown spring "${name}".`);
|
|
1227
1707
|
return springs[name];
|
|
1228
1708
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
* bind(header, { y: offset.to([0, 120], [0, -60]), opacity: offset.to([0, 80], [1, 0]) })
|
|
1235
|
-
* ```
|
|
1236
|
-
*/
|
|
1709
|
+
const scrollDiagnostics = new WeakMap();
|
|
1710
|
+
/** Development audit; counts Jolt callbacks, not events emitted independently by NativeScript Core. */
|
|
1711
|
+
export function inspectScrollValue(value) {
|
|
1712
|
+
return scrollDiagnostics.get(value)?.();
|
|
1713
|
+
}
|
|
1237
1714
|
export function scrollValue(scrollView, options = {}) {
|
|
1238
|
-
|
|
1715
|
+
if (!options ||
|
|
1716
|
+
typeof options !== 'object' ||
|
|
1717
|
+
Object.keys(options).some((key) => !['axis', 'execution', 'rowHeight'].includes(key)))
|
|
1718
|
+
throw new TypeError('Expected scroll value options.');
|
|
1719
|
+
const axis = options.axis ?? 'y', execution = options.execution ?? 'auto', rowHeight = options.rowHeight ?? 0;
|
|
1239
1720
|
if (axis !== 'x' && axis !== 'y')
|
|
1240
1721
|
throw new TypeError('Scroll axis must be "x" or "y".');
|
|
1241
|
-
|
|
1242
|
-
|
|
1722
|
+
if (!['auto', 'native', 'javascript'].includes(execution) ||
|
|
1723
|
+
!Number.isFinite(rowHeight) ||
|
|
1724
|
+
rowHeight < 0)
|
|
1725
|
+
throw new TypeError('Expected a valid execution path and a nonnegative fixed rowHeight.');
|
|
1726
|
+
const native = execution !== 'javascript' && nativeScrollAvailable();
|
|
1727
|
+
if (!native && execution === 'native')
|
|
1728
|
+
throw new Error('Native scroll values need rebuilt Jolt classes.');
|
|
1729
|
+
const initial = new Root(0), root = native ? new SpringRoot(initial, { duration: 0 }) : initial;
|
|
1730
|
+
const disposeRoot = root.dispose.bind(root);
|
|
1731
|
+
let source, handle, ended = false, background = false;
|
|
1732
|
+
let updates = 0, callbacks = 0;
|
|
1733
|
+
const adjusted = (offset) => {
|
|
1734
|
+
const inset = isIOS ? source?.nativeViewProtected?.adjustedContentInset : undefined;
|
|
1735
|
+
return offset + (inset ? (axis === 'x' ? inset.left : inset.top) : 0);
|
|
1736
|
+
};
|
|
1243
1737
|
const read = () => {
|
|
1244
|
-
if (
|
|
1738
|
+
if (handle) {
|
|
1739
|
+
handle.refresh();
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
if (!(source instanceof ScrollView) || native)
|
|
1245
1743
|
return;
|
|
1246
|
-
const offset = axis === 'x' ? source.horizontalOffset : source.verticalOffset;
|
|
1247
|
-
if (Number.isFinite(offset) && offset !== root.raw())
|
|
1744
|
+
const offset = adjusted(axis === 'x' ? source.horizontalOffset : source.verticalOffset);
|
|
1745
|
+
if (Number.isFinite(offset) && offset !== root.raw()) {
|
|
1746
|
+
updates++;
|
|
1248
1747
|
root.set(offset);
|
|
1748
|
+
}
|
|
1249
1749
|
};
|
|
1250
1750
|
const onScroll = (event) => {
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1751
|
+
if (ended || background)
|
|
1752
|
+
return;
|
|
1753
|
+
callbacks++;
|
|
1754
|
+
const scroll = event, offset = adjusted(axis === 'x' ? scroll.scrollX : scroll.scrollY);
|
|
1755
|
+
if (Number.isFinite(offset) && offset !== root.raw()) {
|
|
1756
|
+
updates++;
|
|
1254
1757
|
root.set(offset);
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
const observe = () => handle?.observe(root.observed);
|
|
1761
|
+
const detachNative = () => {
|
|
1762
|
+
handle?.dispose();
|
|
1763
|
+
handle = undefined;
|
|
1764
|
+
};
|
|
1765
|
+
const attach = () => {
|
|
1766
|
+
if (ended || background)
|
|
1767
|
+
return;
|
|
1768
|
+
if (!native) {
|
|
1769
|
+
read();
|
|
1770
|
+
return;
|
|
1771
|
+
}
|
|
1772
|
+
if (handle || !source?.isLoaded || !source.nativeViewProtected)
|
|
1773
|
+
return;
|
|
1774
|
+
handle = createNativeScrollSource(source, root.node, axis, rowHeight, () => root.notify());
|
|
1775
|
+
observe();
|
|
1776
|
+
root.notify();
|
|
1777
|
+
};
|
|
1778
|
+
const suspend = () => {
|
|
1779
|
+
background = true;
|
|
1780
|
+
handle?.enabled(false);
|
|
1781
|
+
};
|
|
1782
|
+
const resume = () => {
|
|
1783
|
+
background = false;
|
|
1784
|
+
attach();
|
|
1785
|
+
handle?.enabled(true);
|
|
1786
|
+
read();
|
|
1255
1787
|
};
|
|
1256
1788
|
const detach = () => {
|
|
1789
|
+
detachNative();
|
|
1257
1790
|
source?.off(ScrollView.scrollEvent, onScroll);
|
|
1258
|
-
source?.off('loaded',
|
|
1791
|
+
source?.off('loaded', attach);
|
|
1792
|
+
source?.off('unloaded', detachNative);
|
|
1259
1793
|
source = undefined;
|
|
1260
1794
|
};
|
|
1261
1795
|
const ref = (target) => {
|
|
1796
|
+
if (ended) {
|
|
1797
|
+
if (target === null)
|
|
1798
|
+
return;
|
|
1799
|
+
throw new Error('The scroll value is disposed.');
|
|
1800
|
+
}
|
|
1262
1801
|
const next = target === null ? undefined : toViews(target)[0];
|
|
1263
1802
|
if (next === source)
|
|
1264
1803
|
return;
|
|
1265
|
-
if (next
|
|
1266
|
-
throw new TypeError('
|
|
1804
|
+
if (next && !native && !(next instanceof ScrollView))
|
|
1805
|
+
throw new TypeError('JavaScript scroll values require a NativeScript ScrollView; native list input needs rebuilt classes.');
|
|
1267
1806
|
detach();
|
|
1268
1807
|
source = next;
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1808
|
+
if (!native)
|
|
1809
|
+
source?.on(ScrollView.scrollEvent, onScroll);
|
|
1810
|
+
source?.on('loaded', attach);
|
|
1811
|
+
source?.on('unloaded', detachNative);
|
|
1812
|
+
try {
|
|
1813
|
+
attach();
|
|
1814
|
+
}
|
|
1815
|
+
catch (error) {
|
|
1816
|
+
detach();
|
|
1817
|
+
throw error;
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
const dispose = () => {
|
|
1821
|
+
if (ended)
|
|
1822
|
+
return;
|
|
1823
|
+
ended = true;
|
|
1824
|
+
detach();
|
|
1825
|
+
root.observationListeners.delete(observe);
|
|
1826
|
+
Application.off(Application.suspendEvent, suspend);
|
|
1827
|
+
Application.off(Application.resumeEvent, resume);
|
|
1828
|
+
disposeRoot();
|
|
1829
|
+
if (native)
|
|
1830
|
+
initial.dispose();
|
|
1272
1831
|
};
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1832
|
+
root.observationListeners.add(observe);
|
|
1833
|
+
Application.on(Application.suspendEvent, suspend);
|
|
1834
|
+
Application.on(Application.resumeEvent, resume);
|
|
1835
|
+
const result = Object.assign(root, {
|
|
1836
|
+
ref,
|
|
1837
|
+
dispose,
|
|
1838
|
+
refresh: read,
|
|
1839
|
+
execution: native ? 'native' : 'javascript',
|
|
1840
|
+
});
|
|
1841
|
+
scrollDiagnostics.set(result, () => handle?.snapshot() ?? { offset: root.raw(), updates, callbacks });
|
|
1842
|
+
try {
|
|
1843
|
+
if (scrollView)
|
|
1844
|
+
ref(scrollView);
|
|
1845
|
+
}
|
|
1846
|
+
catch (error) {
|
|
1847
|
+
dispose();
|
|
1848
|
+
throw error;
|
|
1849
|
+
}
|
|
1850
|
+
return result;
|
|
1276
1851
|
}
|
|
1277
1852
|
//# sourceMappingURL=motion-value.js.map
|