@wardic/core 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Arc.d.ts +2 -2
- package/dist/Arc.js +1 -1
- package/dist/BaseValue.d.ts +11 -10
- package/dist/BaseValue.d.ts.map +1 -1
- package/dist/BaseValue.js +12 -15
- package/dist/BaseValue.js.map +1 -1
- package/dist/Batch.d.ts +12 -6
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +374 -30
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +16 -0
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +22 -8
- package/dist/Clock.js.map +1 -1
- package/dist/DefaultTransition.d.ts +3 -2
- package/dist/DefaultTransition.d.ts.map +1 -1
- package/dist/DefaultTransition.js +5 -3
- package/dist/DefaultTransition.js.map +1 -1
- package/dist/Drag.d.ts +24 -9
- package/dist/Drag.d.ts.map +1 -1
- package/dist/Drag.js +10 -10
- package/dist/Drag.js.map +1 -1
- package/dist/DragActivity.js +3 -3
- package/dist/DragRecognizer.d.ts +14 -8
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +93 -34
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/Easing.d.ts +1 -1
- package/dist/Easing.js +1 -1
- package/dist/Frame.d.ts.map +1 -1
- package/dist/Frame.js +5 -3
- package/dist/Frame.js.map +1 -1
- package/dist/InputFeed.d.ts +11 -8
- package/dist/InputFeed.d.ts.map +1 -1
- package/dist/InputFeed.js +18 -37
- package/dist/InputFeed.js.map +1 -1
- package/dist/InputSource.d.ts +3 -3
- package/dist/InputSource.js +2 -2
- package/dist/Interpolator.d.ts +2 -2
- package/dist/Interpolator.js +2 -2
- package/dist/InterpolatorRegistry.d.ts +29 -15
- package/dist/InterpolatorRegistry.d.ts.map +1 -1
- package/dist/InterpolatorRegistry.js +17 -8
- package/dist/InterpolatorRegistry.js.map +1 -1
- package/dist/LiveValue.d.ts +16 -9
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +204 -27
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +21 -8
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +184 -60
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +16 -9
- package/dist/Playback.js.map +1 -1
- package/dist/Projection.d.ts +9 -9
- package/dist/Projection.js +2 -2
- package/dist/Recognizer.d.ts +2 -2
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +15 -10
- package/dist/Recognizer.js.map +1 -1
- package/dist/ReducedMotion.d.ts +4 -4
- package/dist/ReducedMotion.js +6 -6
- package/dist/Renderer.d.ts +5 -5
- package/dist/Renderer.js +6 -6
- package/dist/Renderer.js.map +1 -1
- package/dist/Reorder.d.ts +1 -1
- package/dist/Reorder.d.ts.map +1 -1
- package/dist/Reorder.js +2 -1
- package/dist/Reorder.js.map +1 -1
- package/dist/ScrollSource.d.ts +1 -1
- package/dist/ScrollSource.d.ts.map +1 -1
- package/dist/Sequence.d.ts +1 -1
- package/dist/SharedSource.d.ts +3 -3
- package/dist/SharedSource.js +5 -5
- package/dist/SharedSource.js.map +1 -1
- package/dist/Spring.d.ts.map +1 -1
- package/dist/Spring.js +2 -1
- package/dist/Spring.js.map +1 -1
- package/dist/Values.d.ts +2 -2
- package/dist/Values.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/carried.d.ts +13 -0
- package/dist/internal/carried.d.ts.map +1 -0
- package/dist/internal/carried.js +23 -0
- package/dist/internal/carried.js.map +1 -0
- package/dist/internal/firstSteps.d.ts +66 -0
- package/dist/internal/firstSteps.d.ts.map +1 -0
- package/dist/internal/firstSteps.js +107 -0
- package/dist/internal/firstSteps.js.map +1 -0
- package/dist/internal/frameLoop.d.ts +11 -3
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +190 -39
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/guarded.d.ts +16 -0
- package/dist/internal/guarded.d.ts.map +1 -0
- package/dist/internal/guarded.js +68 -0
- package/dist/internal/guarded.js.map +1 -0
- package/dist/internal/lerpsNumbers.d.ts +11 -0
- package/dist/internal/lerpsNumbers.d.ts.map +1 -0
- package/dist/internal/lerpsNumbers.js +38 -0
- package/dist/internal/lerpsNumbers.js.map +1 -0
- package/dist/internal/options.d.ts +7 -7
- package/dist/internal/options.d.ts.map +1 -1
- package/dist/internal/options.js +10 -10
- package/dist/internal/options.js.map +1 -1
- package/dist/internal/stepper.d.ts +21 -4
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +21 -5
- package/dist/internal/stepper.js.map +1 -1
- package/dist/internal/tracing.d.ts +1 -1
- package/dist/internal/tracing.js +1 -1
- package/dist/unstable/AnimationControls.d.ts +45 -39
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +59 -35
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +11 -5
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/AppearHandoff.js.map +1 -1
- package/dist/unstable/BatchCalls.d.ts +2 -2
- package/dist/unstable/BatchCalls.js +5 -5
- package/dist/unstable/Config.d.ts +21 -17
- package/dist/unstable/Config.d.ts.map +1 -1
- package/dist/unstable/Config.js.map +1 -1
- package/dist/unstable/FirstSteps.d.ts +25 -0
- package/dist/unstable/FirstSteps.d.ts.map +1 -0
- package/dist/unstable/FirstSteps.js +2 -0
- package/dist/unstable/FirstSteps.js.map +1 -0
- package/dist/unstable/FlushGate.d.ts +54 -50
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +201 -77
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +6 -3
- package/dist/unstable/FrameEffects.d.ts.map +1 -1
- package/dist/unstable/FrameEffects.js +14 -3
- package/dist/unstable/FrameEffects.js.map +1 -1
- package/dist/unstable/FrameTime.d.ts +1 -1
- package/dist/unstable/FrameTime.js +1 -1
- package/dist/unstable/Imperative.d.ts +42 -13
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +279 -88
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/MeasuredPairs.d.ts +6 -2
- package/dist/unstable/MeasuredPairs.d.ts.map +1 -1
- package/dist/unstable/MeasuredPairs.js.map +1 -1
- package/dist/unstable/OwnValues.js +1 -1
- package/dist/unstable/PresenceRecord.d.ts +30 -26
- package/dist/unstable/PresenceRecord.d.ts.map +1 -1
- package/dist/unstable/PresenceRecord.js +8 -8
- package/dist/unstable/PresenceRecord.js.map +1 -1
- package/dist/unstable/Projector.d.ts +34 -0
- package/dist/unstable/Projector.d.ts.map +1 -0
- package/dist/unstable/Projector.js +9 -0
- package/dist/unstable/Projector.js.map +1 -0
- package/dist/unstable/Report.d.ts +8 -1
- package/dist/unstable/Report.d.ts.map +1 -1
- package/dist/unstable/Report.js +18 -2
- package/dist/unstable/Report.js.map +1 -1
- package/dist/unstable/RetargetLegs.d.ts +7 -1
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +24 -8
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +123 -68
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +319 -167
- package/dist/unstable/Spine.js.map +1 -1
- package/dist/unstable/Stops.d.ts +3 -3
- package/dist/unstable/Stops.js +4 -4
- package/dist/unstable/Subject.d.ts +2 -2
- package/dist/unstable/Subject.js +2 -2
- package/dist/unstable/Timelines.d.ts +11 -11
- package/dist/unstable/Timelines.d.ts.map +1 -1
- package/dist/unstable/Timelines.js +3 -3
- package/dist/unstable/VariantTarget.d.ts +32 -10
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +73 -20
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +68 -34
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +83 -36
- package/dist/unstable/VariantTree.js.map +1 -1
- package/dist/unstable/WardicConfigValue.d.ts +13 -13
- package/dist/unstable/WardicConfigValue.d.ts.map +1 -1
- package/dist/unstable/WardicConfigValue.js +4 -4
- package/dist/unstable/WardicConfigValue.js.map +1 -1
- package/package.json +1 -1
- package/src/Arc.ts +3 -3
- package/src/BaseValue.ts +18 -21
- package/src/Batch.ts +391 -27
- package/src/Clock.ts +29 -8
- package/src/DefaultTransition.ts +5 -3
- package/src/Drag.ts +32 -14
- package/src/DragActivity.ts +3 -3
- package/src/DragRecognizer.ts +118 -41
- package/src/Easing.ts +1 -1
- package/src/Frame.ts +5 -3
- package/src/InputFeed.ts +39 -42
- package/src/InputSource.ts +5 -5
- package/src/Interpolator.ts +3 -3
- package/src/InterpolatorRegistry.ts +22 -13
- package/src/LiveValue.ts +186 -30
- package/src/Machine.ts +252 -81
- package/src/Playback.ts +15 -9
- package/src/Projection.ts +9 -9
- package/src/Recognizer.ts +16 -10
- package/src/ReducedMotion.ts +6 -6
- package/src/Renderer.ts +6 -6
- package/src/Reorder.ts +3 -2
- package/src/ScrollSource.ts +1 -1
- package/src/Sequence.ts +1 -1
- package/src/SharedSource.ts +5 -5
- package/src/Spring.ts +2 -1
- package/src/Values.ts +2 -2
- package/src/index.ts +1 -1
- package/src/internal/carried.ts +22 -0
- package/src/internal/firstSteps.ts +139 -0
- package/src/internal/frameLoop.ts +203 -41
- package/src/internal/guarded.ts +69 -0
- package/src/internal/lerpsNumbers.ts +53 -0
- package/src/internal/options.ts +10 -10
- package/src/internal/stepper.ts +33 -6
- package/src/internal/tracing.ts +1 -1
- package/src/unstable/AnimationControls.ts +88 -57
- package/src/unstable/AppearHandoff.ts +13 -6
- package/src/unstable/BatchCalls.ts +5 -5
- package/src/unstable/Config.ts +23 -17
- package/src/unstable/FirstSteps.ts +26 -0
- package/src/unstable/FlushGate.ts +250 -108
- package/src/unstable/FrameEffects.ts +17 -4
- package/src/unstable/FrameTime.ts +1 -1
- package/src/unstable/Imperative.ts +342 -101
- package/src/unstable/MeasuredPairs.ts +7 -1
- package/src/unstable/OwnValues.ts +1 -1
- package/src/unstable/PresenceRecord.ts +33 -29
- package/src/unstable/Projector.ts +45 -0
- package/src/unstable/Report.ts +20 -2
- package/src/unstable/RetargetLegs.ts +24 -9
- package/src/unstable/Spine.ts +399 -202
- package/src/unstable/Stops.ts +6 -6
- package/src/unstable/Subject.ts +2 -2
- package/src/unstable/Timelines.ts +12 -12
- package/src/unstable/VariantTarget.ts +102 -23
- package/src/unstable/VariantTree.ts +123 -42
- package/src/unstable/WardicConfigValue.ts +13 -13
|
@@ -14,21 +14,22 @@ import * as Cause from "effect/Cause";
|
|
|
14
14
|
import * as Effect from "effect/Effect";
|
|
15
15
|
import * as Exit from "effect/Exit";
|
|
16
16
|
import { constTrue, constVoid, identity } from "effect/Function";
|
|
17
|
+
import * as Option from "effect/Option";
|
|
17
18
|
import * as Predicate from "effect/Predicate";
|
|
18
19
|
import * as Rec from "effect/Record";
|
|
19
20
|
import * as UndefinedOr from "effect/UndefinedOr";
|
|
20
|
-
/** Each mounted
|
|
21
|
-
// Module state (#460, Q7): each
|
|
22
|
-
const
|
|
21
|
+
/** Each mounted Ward's Subject's spine (Motion's `visualElementStore`), by its Subject. */
|
|
22
|
+
// Module state (#460, Q7): each Ward's Subject's animatable, held weakly by the Subject.
|
|
23
|
+
const wardedSubjects = new WeakMap();
|
|
23
24
|
/**
|
|
24
|
-
* Register a mounted
|
|
25
|
+
* Register a mounted Ward's Subject's spine for the Imperative animations of its Subject (#433): until
|
|
25
26
|
* the returned function, which its unmount calls.
|
|
26
27
|
*/
|
|
27
28
|
export const registerAnimatable = (subject, spine) => {
|
|
28
|
-
|
|
29
|
+
wardedSubjects.set(subject, spine);
|
|
29
30
|
return () => {
|
|
30
|
-
if (
|
|
31
|
-
|
|
31
|
+
if (wardedSubjects.get(subject) === spine)
|
|
32
|
+
wardedSubjects.delete(subject);
|
|
32
33
|
};
|
|
33
34
|
};
|
|
34
35
|
/** An Environment with no Batches. */
|
|
@@ -59,11 +60,11 @@ const plainOf = (env, subjects, subject) => {
|
|
|
59
60
|
return known;
|
|
60
61
|
const id = `wardic-animate-${plainIds++}`;
|
|
61
62
|
const snapshot = Spine.emptySnapshotOf({});
|
|
62
|
-
const spine = Spine.
|
|
63
|
+
const spine = Spine.makeSubjectSpine({
|
|
63
64
|
runtime: env.runtime,
|
|
64
65
|
gate: env.gate,
|
|
65
66
|
id,
|
|
66
|
-
|
|
67
|
+
subject,
|
|
67
68
|
tag: undefined,
|
|
68
69
|
config: () => NO_CONFIG,
|
|
69
70
|
parent: undefined,
|
|
@@ -76,7 +77,7 @@ const plainOf = (env, subjects, subject) => {
|
|
|
76
77
|
ownValues: env.ownValues,
|
|
77
78
|
measuredPairs: env.measuredPairs,
|
|
78
79
|
variableValues: env.variableValues,
|
|
79
|
-
start: { initialValues: {}, initialLink: {}, startedLink: {}, quiet: false },
|
|
80
|
+
start: { initialValues: {}, initialLink: {}, startedLink: {}, quiet: false, failure: Option.none() },
|
|
80
81
|
snapshot,
|
|
81
82
|
reuse: Spine.makeReuse(),
|
|
82
83
|
links: subjects.startLinksOf(subject),
|
|
@@ -93,7 +94,7 @@ const plainOf = (env, subjects, subject) => {
|
|
|
93
94
|
};
|
|
94
95
|
/**
|
|
95
96
|
* `transition` with `skipAnimations` when its scope's animations are skipped (#468, Motion's
|
|
96
|
-
* `useAnimate`, which hands its config's to each animation): a
|
|
97
|
+
* `useAnimate`, which hands its config's to each animation): a Ward's Subject's own config can skip it
|
|
97
98
|
* too, and a plain Subject has none.
|
|
98
99
|
*/
|
|
99
100
|
const skippedIn = (env, transition) => {
|
|
@@ -124,8 +125,12 @@ const lastTargetsOf = (host) => UndefinedOr.match(host.lastResolution(), { onUnd
|
|
|
124
125
|
/**
|
|
125
126
|
* `key` taken by an Imperative animation from whatever runs it (#433): noted in `taking` with `noted`,
|
|
126
127
|
* the target the Override stack has for it now, no longer returning, its Timeline value stopped, given
|
|
127
|
-
* up by its owner, owned, and started where it's drawn toward `like`, noted in `started`.
|
|
128
|
+
* up by its owner, owned, and started where it's drawn toward `like`, noted in `started`. Its Own value
|
|
129
|
+
* is read before it's taken, by the call (`readiedOf`) or the landing (`settableOrReported`); a run's
|
|
130
|
+
* retake at a replay reads none, the call having read it.
|
|
128
131
|
*/
|
|
132
|
+
// #973 (ADR-0061, *Amendment (#973)*, Q3): read here, a key refused at the call had already taken the keys
|
|
133
|
+
// before it, of its Subject and of a list's earlier Subjects, ending the animations that drew them.
|
|
129
134
|
const takeKey = (host, taking, key, noted, like, started) => {
|
|
130
135
|
taking.set(key, noted);
|
|
131
136
|
host.returning().delete(key);
|
|
@@ -136,9 +141,16 @@ const takeKey = (host, taking, key, noted, like, started) => {
|
|
|
136
141
|
const owner = host.owners.get(key);
|
|
137
142
|
if (Predicate.isNotUndefined(owner))
|
|
138
143
|
host.giveUp(key, owner);
|
|
144
|
+
host.startKey(key, like, started);
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* `key`'s Own value read, where it has no `initial` value: a key the Subject lacks, or can't write, is
|
|
148
|
+
* its Environment's error, naming it.
|
|
149
|
+
*/
|
|
150
|
+
// Per key at a call and at a landing, the hot path (effect-first.md): a statement.
|
|
151
|
+
const readOwn = (host, key) => {
|
|
139
152
|
if (!Object.hasOwn(host.initialValues, key))
|
|
140
153
|
host.ownValue(key);
|
|
141
|
-
host.startKey(key, like, started);
|
|
142
154
|
};
|
|
143
155
|
/** Whether a Transition end may set a key drawn by `owner`: none draws it, or its leg is done. */
|
|
144
156
|
const endFree = (owner) => {
|
|
@@ -153,12 +165,14 @@ const endFree = (owner) => {
|
|
|
153
165
|
* Its legs start where the keys are drawn, with their velocity, on `given` (a key with none of its own
|
|
154
166
|
* on its Default transition), reduced motion as the provider says, and run through `head` once
|
|
155
167
|
* {@link Spine.ImperativeTrack.run} is called. Once they land, none taken, its target's Transition
|
|
156
|
-
* end is set (#896), and put back by a cancel or a run again.
|
|
168
|
+
* end is set (#896), and put back by a cancel or a run again. Its keys, the end's too, were read before
|
|
169
|
+
* it's made (`readiedOf`); one the Subject can no longer set by a landing is reported there and left as it
|
|
170
|
+
* is, and the rest of the end set (#970).
|
|
157
171
|
*/
|
|
158
172
|
// #746 (ADR-0067, *Amendment (#746)*, decision 10): here, not in the spine, so an app that never animates
|
|
159
173
|
// imperatively ships none of it; the spine hands over what it takes (`SpineHost`).
|
|
160
174
|
const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
161
|
-
const { snapshot, owners, keepTheRest,
|
|
175
|
+
const { snapshot, owners, keepTheRest, subject, positionalKeys, defaultTransition, unitScale, readVelocity, gate, forget, endLeg, live, own, legProgram, legEnded, turnBack, id, recordFrame, runtime, subjectRules, measuredPairs, variableValues } = host;
|
|
162
176
|
/** A leg of an Imperative animation, forked as a Retarget's are; it lands on its track. */
|
|
163
177
|
// Data-first: a pipe's curried forms are two closures more for every leg (#618, H1).
|
|
164
178
|
const runImperative = (running, program) => {
|
|
@@ -170,6 +184,7 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
170
184
|
})));
|
|
171
185
|
};
|
|
172
186
|
const to = target.values;
|
|
187
|
+
const ends = target.transitionEnd;
|
|
173
188
|
const before = lastTargetsOf(host);
|
|
174
189
|
const started = {};
|
|
175
190
|
let measuring;
|
|
@@ -199,14 +214,13 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
199
214
|
const skipped = host.skipAnimations();
|
|
200
215
|
let measured;
|
|
201
216
|
if (Bool.and(Bool.not(Bool.or(reduce, skipped)), Predicate.isNotUndefined(measuring)))
|
|
202
|
-
measured = Spine.measuredOf(measuredPairs,
|
|
217
|
+
measured = Spine.measuredOf(measuredPairs, subject, UndefinedOr.getOrThrow(measuring), from, to, snapshot.values, stops, runtime, id);
|
|
203
218
|
// Built once: a seek or a replay runs the same legs, from the same start, with the same velocities.
|
|
204
219
|
const built = RetargetLegs.legsOf(from, to, given, reduce, skipped, positionalKeys, defaultTransition, readVelocity, undefined, stops, measured, snapshot.values, rests, unitScale);
|
|
205
220
|
const variables = Spine.holdsVariable(variableValues, from, to, stops);
|
|
206
221
|
const legs = Arr.map(built, (leg) => RetargetLegs.mapMachine(leg, Playback.drive(head)));
|
|
207
222
|
let runnings = Spine.NO_RUNNING;
|
|
208
223
|
let left = 0;
|
|
209
|
-
const ends = target.transitionEnd;
|
|
210
224
|
// What its Transition end's keys were before it set them (Q5): `undefined` until it has.
|
|
211
225
|
let overwritten;
|
|
212
226
|
// Its runs, stops and cancels, counted: what a landing waiting on a flush checks it's still for.
|
|
@@ -237,8 +251,21 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
237
251
|
takeKey(host, takingNow, key, targetsNow[key], UndefinedOr.getOrThrow(values[key]), startedNow);
|
|
238
252
|
});
|
|
239
253
|
};
|
|
254
|
+
// Whether an end's `key` can still be set, else reported: one its Subject has lost, or can no longer
|
|
255
|
+
// write, since the call read it is reported at the landing and left as it is, and the rest of the end is
|
|
256
|
+
// set (#970).
|
|
257
|
+
const settableOrReported = (key) => {
|
|
258
|
+
try {
|
|
259
|
+
readOwn(host, key);
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
catch (defect) {
|
|
263
|
+
runtime.runFork(Report.failure(`wardic.animate: a Transition end's "${key}" couldn't be set, the rest of it set and the animation landed`, Cause.die(defect)));
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
240
267
|
const writeEnds = (values) => {
|
|
241
|
-
const free = Rec.filter(values, (_, key) => endFree(owners.get(key)));
|
|
268
|
+
const free = Rec.filter(values, (_, key) => endFree(owners.get(key)) && settableOrReported(key));
|
|
242
269
|
if (Rec.isEmptyRecord(free))
|
|
243
270
|
return;
|
|
244
271
|
takeEach(free, constTrue);
|
|
@@ -249,7 +276,7 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
249
276
|
};
|
|
250
277
|
/**
|
|
251
278
|
* Its Transition end's keys put back as they were before it was set (Q5): at a cancel, a seek or a
|
|
252
|
-
* replay, each a key no leg has drawn since, a later call's or the
|
|
279
|
+
* replay, each a key no leg has drawn since, a later call's or the Subject's own. The next landing
|
|
253
280
|
* sets them again.
|
|
254
281
|
*/
|
|
255
282
|
const putBack = () => {
|
|
@@ -265,10 +292,10 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
265
292
|
// frame, its keys landed from its start, so a take before then takes nothing in flight, as Motion's
|
|
266
293
|
// skipped value makes no animation. Its machine read only for a leg that lost a key.
|
|
267
294
|
const snaps = (i) => Machine.durationOf(machineOf(UndefinedOr.getOrThrow(built[i]))) === 0;
|
|
268
|
-
// A leg the
|
|
295
|
+
// A leg the Subject's own Retarget carried on, toward the same target, as its own (Q7): the call has lost it.
|
|
269
296
|
let carried = false;
|
|
270
297
|
// Taken (#896's Q3, #951): a key it animates taken from its leg mid-flight, by a later animation or the
|
|
271
|
-
//
|
|
298
|
+
// Subject's own target, or a leg carried off whole. A leg that lost one has fewer than it started
|
|
272
299
|
// with; one taken after its leg landed doesn't count, as Motion's, nor one that snaps.
|
|
273
300
|
const taken = () => {
|
|
274
301
|
if (carried)
|
|
@@ -317,7 +344,7 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
317
344
|
};
|
|
318
345
|
/**
|
|
319
346
|
* A leg of this run ended **Superseded** (#951), told at its end, as it settles nothing of this
|
|
320
|
-
* track's: carried on by the
|
|
347
|
+
* track's: carried on by the Subject's own Retarget as its own, its landing the Retarget's now (Q7);
|
|
321
348
|
* or with every key taken, a count of 0 (only a take lowers it), which `taken` reads. Either counts
|
|
322
349
|
* toward the track's landing, which finds it taken.
|
|
323
350
|
*/
|
|
@@ -345,7 +372,7 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
345
372
|
return false;
|
|
346
373
|
return head.time >= duration();
|
|
347
374
|
};
|
|
348
|
-
// A key another leg draws: a later animation's, or the
|
|
375
|
+
// A key another leg draws: a later animation's, or the Subject's own.
|
|
349
376
|
const drawnByAnother = (key) => Predicate.isNotUndefined(owners.get(key));
|
|
350
377
|
const run = () => {
|
|
351
378
|
runs++;
|
|
@@ -382,7 +409,7 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
382
409
|
const duration = () => Arr.reduce(built, 0, (longest, leg) => Math.max(longest, Machine.durationOf(machineOf(leg))));
|
|
383
410
|
const machineOf = (leg) => {
|
|
384
411
|
if (leg._tag === "Blend")
|
|
385
|
-
return runtime.runSync(Effect.suspend(leg.machine).pipe(InterpolatorRegistry.withKeyRules(
|
|
412
|
+
return runtime.runSync(Effect.suspend(leg.machine).pipe(InterpolatorRegistry.withKeyRules(subjectRules)));
|
|
386
413
|
return leg.machine();
|
|
387
414
|
};
|
|
388
415
|
const stop = () => {
|
|
@@ -394,7 +421,7 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
394
421
|
};
|
|
395
422
|
/**
|
|
396
423
|
* A call's transition on its target's own (#896, ADR-0061 *Amendment (#896)*, Q1): the options' fields
|
|
397
|
-
* laid over the target's, shallowly, as `inherit: true` lays a target's over its
|
|
424
|
+
* laid over the target's, shallowly, as `inherit: true` lays a target's over its Subject's. Motion's
|
|
398
425
|
* `animate` reads the options alone.
|
|
399
426
|
*/
|
|
400
427
|
// Its own handed back as it is with no options, so the legs' decode cache (#66) holds for it. Its
|
|
@@ -407,17 +434,49 @@ const overOwn = (own, given) => {
|
|
|
407
434
|
return { ...own, ...given };
|
|
408
435
|
};
|
|
409
436
|
/**
|
|
410
|
-
*
|
|
411
|
-
*
|
|
437
|
+
* `subject`'s animation of `variant`, readied: each key the target names, its Transition end's then its
|
|
438
|
+
* values', read as its Environment reads it, so one the Subject can't take is an error now, naming it.
|
|
439
|
+
* A call readies each of its Subjects before it builds any track ({@link trackOf}), so a call refused here
|
|
440
|
+
* has taken nothing: an animation it would have taken a key from runs on.
|
|
412
441
|
*/
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
const
|
|
417
|
-
|
|
442
|
+
// #973 (ADR-0061, *Amendment (#973)*, Q1): tracks took their keys as each was built, so a later key's
|
|
443
|
+
// refusal, its Subject's or a later Subject's, ended the animations that drew the keys taken before it.
|
|
444
|
+
const readiedOf = (env, subjects, subject, variant) => {
|
|
445
|
+
const target = VariantTarget.resolveTarget(variant, undefined, undefined, VariantTarget.NO_VARIANT_STATE);
|
|
446
|
+
// A function given as the target (past the types) that throws is an error at the call, as a key it
|
|
447
|
+
// can't take is: the call takes nothing (#979; ADR-0074 keeps a refusal at the call a throw).
|
|
448
|
+
if (Option.isSome(target.failure))
|
|
449
|
+
throw target.failure.value.defect;
|
|
450
|
+
const own = wardedSubjects.get(subject);
|
|
418
451
|
if (Predicate.isNotUndefined(own))
|
|
419
|
-
return
|
|
452
|
+
return readOwnValues({ subject, target, host: own.host(), plain: undefined });
|
|
420
453
|
const plain = plainOf(env, subjects, subject);
|
|
454
|
+
return readOwnValues({ subject, target, host: plain.spine.host(), plain });
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* `readied`'s Own values read, its Transition end's keys then its target's: an error the Environment's
|
|
458
|
+
* read throws is thrown, naming the first key it can't take.
|
|
459
|
+
*/
|
|
460
|
+
// Its end's first, as #970 read them, so a key refused in both names the end's. Per key at a call, the hot
|
|
461
|
+
// path (effect-first.md): statements, a loop's body its closure.
|
|
462
|
+
const readOwnValues = (readied) => {
|
|
463
|
+
const { host, target } = readied;
|
|
464
|
+
const ends = target.transitionEnd;
|
|
465
|
+
if (Predicate.isNotUndefined(ends))
|
|
466
|
+
Arr.forEach(Rec.keys(ends), (key) => readOwn(host, key));
|
|
467
|
+
Arr.forEach(Rec.keys(target.values), (key) => readOwn(host, key));
|
|
468
|
+
return readied;
|
|
469
|
+
};
|
|
470
|
+
/**
|
|
471
|
+
* A readied Subject's animation (`readiedOf`): through its spine when it's a Ward's Subject's, else through
|
|
472
|
+
* its plain spine, in the gate while any of its animations runs.
|
|
473
|
+
*/
|
|
474
|
+
const trackOf = (env, readied, given, head, settled) => {
|
|
475
|
+
const { subject, target, host, plain } = readied;
|
|
476
|
+
const hooks = { settled, failed: constVoid };
|
|
477
|
+
const transition = skippedIn(env, overOwn(target.transition, given));
|
|
478
|
+
if (Predicate.isUndefined(plain))
|
|
479
|
+
return imperativeTrackOf(host, target, transition, head, hooks);
|
|
421
480
|
// In the gate while it runs; out once its last animation is done, after the flush of its last frame.
|
|
422
481
|
let live = false;
|
|
423
482
|
const enter = () => {
|
|
@@ -443,7 +502,7 @@ const trackOf = (env, subjects, subject, target, given, head, settled) => {
|
|
|
443
502
|
plain.unregister();
|
|
444
503
|
});
|
|
445
504
|
};
|
|
446
|
-
const track = imperativeTrackOf(
|
|
505
|
+
const track = imperativeTrackOf(host, target, transition, head, {
|
|
447
506
|
settled: (landed) => {
|
|
448
507
|
leave();
|
|
449
508
|
settled(landed);
|
|
@@ -500,16 +559,51 @@ const skipsBatchCall = (env, options) => {
|
|
|
500
559
|
return true;
|
|
501
560
|
return UndefinedOr.match(options, { onUndefined: () => false, onDefined: (given) => given.skipAnimations === true });
|
|
502
561
|
};
|
|
503
|
-
/**
|
|
504
|
-
const
|
|
562
|
+
/** A promise of each run's outcome, nothing made until it's read (#955: `finished` and `ended`). */
|
|
563
|
+
const runPromiseOf = () => {
|
|
564
|
+
let promise;
|
|
565
|
+
let settle;
|
|
566
|
+
let outcome = Option.none();
|
|
567
|
+
return {
|
|
568
|
+
get: () => {
|
|
569
|
+
if (Predicate.isNotUndefined(promise))
|
|
570
|
+
return promise;
|
|
571
|
+
promise = Option.match(outcome, {
|
|
572
|
+
onSome: (value) => Promise.resolve(value),
|
|
573
|
+
onNone: () => new Promise((settleWith) => {
|
|
574
|
+
settle = settleWith;
|
|
575
|
+
}),
|
|
576
|
+
});
|
|
577
|
+
return promise;
|
|
578
|
+
},
|
|
579
|
+
resolve: (value) => {
|
|
580
|
+
outcome = Option.some(value);
|
|
581
|
+
if (Predicate.isNotUndefined(settle))
|
|
582
|
+
settle(value);
|
|
583
|
+
},
|
|
584
|
+
renew: () => {
|
|
585
|
+
promise = undefined;
|
|
586
|
+
settle = undefined;
|
|
587
|
+
outcome = Option.none();
|
|
588
|
+
},
|
|
589
|
+
};
|
|
590
|
+
};
|
|
591
|
+
/** A run that landed, as `ended` gives it. */
|
|
592
|
+
const LANDED = Object.freeze({ landed: true });
|
|
593
|
+
/** A run that ended without landing: stopped, cancelled or taken over. */
|
|
594
|
+
const NOT_LANDED = Object.freeze({ landed: false });
|
|
595
|
+
/** How a run ended, as `ended` gives it. */
|
|
596
|
+
const endOf = /*#__PURE__*/ Bool.match({ onTrue: () => LANDED, onFalse: () => NOT_LANDED });
|
|
597
|
+
/** Playback controls over `tracks`, all run through `head`, started now: a throw from `onComplete` reported on `runtime`. */
|
|
598
|
+
const controlsOf = (tracks, head, watch, onComplete, runtime) => {
|
|
505
599
|
let state = "running";
|
|
506
600
|
let stopped = false;
|
|
507
601
|
let landed = 0;
|
|
508
602
|
// Whether a Subject's part ended without landing, a key of it taken by a later animation (#951).
|
|
509
603
|
let anyTaken = false;
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
604
|
+
const finished = runPromiseOf();
|
|
605
|
+
// Each run's end, however it ended (#955): a run is what `watch` hears, from its start to its end.
|
|
606
|
+
const ended = runPromiseOf();
|
|
513
607
|
let duration;
|
|
514
608
|
const durationNow = () => {
|
|
515
609
|
if (Predicate.isUndefined(duration))
|
|
@@ -521,22 +615,24 @@ const controlsOf = (tracks, head, watch, onComplete) => {
|
|
|
521
615
|
anyTaken = false;
|
|
522
616
|
Arr.forEach(tracks, (track) => track.run());
|
|
523
617
|
};
|
|
524
|
-
const fresh = () => {
|
|
525
|
-
finished = undefined;
|
|
526
|
-
resolve = undefined;
|
|
527
|
-
isResolved = false;
|
|
528
|
-
};
|
|
529
618
|
const end = (how, landedNow) => {
|
|
530
619
|
const was = state;
|
|
531
620
|
state = how;
|
|
532
|
-
if (Bool.or(was === "running", was === "paused"))
|
|
621
|
+
if (Bool.or(was === "running", was === "paused")) {
|
|
622
|
+
ended.resolve(endOf(landedNow));
|
|
533
623
|
watch.ended(controls, landedNow);
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
// A new run, from an end: its own `ended`, and the watch told it started.
|
|
627
|
+
const newRun = () => {
|
|
628
|
+
ended.renew();
|
|
629
|
+
watch.started(controls);
|
|
534
630
|
};
|
|
535
631
|
const restart = () => {
|
|
536
632
|
const was = state;
|
|
537
633
|
state = "running";
|
|
538
634
|
if (Bool.or(was === "finished", was === "idle"))
|
|
539
|
-
|
|
635
|
+
newRun();
|
|
540
636
|
};
|
|
541
637
|
const controls = {
|
|
542
638
|
get time() {
|
|
@@ -548,8 +644,8 @@ const controlsOf = (tracks, head, watch, onComplete) => {
|
|
|
548
644
|
if (state !== "running") {
|
|
549
645
|
Playback.pause(head);
|
|
550
646
|
if (Bool.or(state === "finished", state === "idle")) {
|
|
551
|
-
|
|
552
|
-
|
|
647
|
+
finished.renew();
|
|
648
|
+
newRun();
|
|
553
649
|
}
|
|
554
650
|
state = "paused";
|
|
555
651
|
}
|
|
@@ -568,15 +664,10 @@ const controlsOf = (tracks, head, watch, onComplete) => {
|
|
|
568
664
|
return state;
|
|
569
665
|
},
|
|
570
666
|
get finished() {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
resolve = done;
|
|
576
|
-
}),
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
return finished;
|
|
667
|
+
return finished.get();
|
|
668
|
+
},
|
|
669
|
+
get ended() {
|
|
670
|
+
return ended.get();
|
|
580
671
|
},
|
|
581
672
|
then: (onResolve, onReject) => controls.finished.then(onResolve, onReject),
|
|
582
673
|
play: () => {
|
|
@@ -590,7 +681,7 @@ const controlsOf = (tracks, head, watch, onComplete) => {
|
|
|
590
681
|
if (state === "running")
|
|
591
682
|
return;
|
|
592
683
|
// Again from its start: its end when it plays backwards.
|
|
593
|
-
|
|
684
|
+
finished.renew();
|
|
594
685
|
Playback.play(head);
|
|
595
686
|
Playback.seek(head, Bool.match(head.speed < 0, { onTrue: durationNow, onFalse: () => 0 }));
|
|
596
687
|
restart();
|
|
@@ -635,10 +726,18 @@ const controlsOf = (tracks, head, watch, onComplete) => {
|
|
|
635
726
|
stopped = true;
|
|
636
727
|
return end("idle", false);
|
|
637
728
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
729
|
+
finished.resolve(undefined);
|
|
730
|
+
// Finished before its onComplete runs, as Motion's `finish()`: a throw there leaves it finished, and
|
|
731
|
+
// is reported each time it lands (#977; ADR-0074, *Amendment (#979, group A)*).
|
|
641
732
|
end("finished", true);
|
|
733
|
+
UndefinedOr.map(onComplete, (complete) => {
|
|
734
|
+
try {
|
|
735
|
+
complete();
|
|
736
|
+
}
|
|
737
|
+
catch (defect) {
|
|
738
|
+
runtime.runFork(Report.failure("wardic.animate: an onComplete failed", Cause.die(defect)));
|
|
739
|
+
}
|
|
740
|
+
});
|
|
642
741
|
};
|
|
643
742
|
return { controls, settledOne };
|
|
644
743
|
};
|
|
@@ -651,6 +750,7 @@ export const finishedControls = () => {
|
|
|
651
750
|
duration: 0,
|
|
652
751
|
state: "finished",
|
|
653
752
|
finished: done,
|
|
753
|
+
ended: Promise.resolve(LANDED),
|
|
654
754
|
then: (onResolve, onReject) => done.then(onResolve, onReject),
|
|
655
755
|
play: constVoid,
|
|
656
756
|
pause: constVoid,
|
|
@@ -663,25 +763,59 @@ export const finishedControls = () => {
|
|
|
663
763
|
* An animation of `count` tracks started (#433): its controls over them, through one Playhead, told
|
|
664
764
|
* to `watch`, each track run. Finished at once with none.
|
|
665
765
|
*/
|
|
666
|
-
const started = (watch, count, onComplete, tracksOf) => {
|
|
766
|
+
const started = (runtime, watch, count, onComplete, tracksOf) => {
|
|
667
767
|
if (count === 0)
|
|
668
768
|
return finishedControls();
|
|
669
769
|
const head = Playback.make();
|
|
670
770
|
let settledOne = constVoid;
|
|
671
771
|
const tracks = tracksOf(head, (landedOne) => settledOne(landedOne));
|
|
672
|
-
const made = controlsOf(tracks, head, watch, onComplete);
|
|
772
|
+
const made = controlsOf(tracks, head, watch, onComplete, runtime);
|
|
673
773
|
settledOne = made.settledOne;
|
|
674
774
|
watch.started(made.controls);
|
|
675
|
-
|
|
775
|
+
// A run that refuses the call (a Batch part's `delay` that throws, at its first play) stops it, so its
|
|
776
|
+
// scope hears it end, and the throw goes on to the call (#979, row 20).
|
|
777
|
+
try {
|
|
778
|
+
Arr.forEach(tracks, (track) => track.run());
|
|
779
|
+
}
|
|
780
|
+
catch (defect) {
|
|
781
|
+
made.controls.stop();
|
|
782
|
+
throw defect;
|
|
783
|
+
}
|
|
676
784
|
return made.controls;
|
|
677
785
|
};
|
|
786
|
+
/**
|
|
787
|
+
* A track built as it first runs: a mixed call's plain Subject, whose keys are taken only once the Batch
|
|
788
|
+
* parts before it have run, a Batch part's `delay` among what they call. Stopped or cancelled before it
|
|
789
|
+
* runs, it has taken nothing.
|
|
790
|
+
*/
|
|
791
|
+
const builtAtRun = (build) => {
|
|
792
|
+
let built;
|
|
793
|
+
const track = () => {
|
|
794
|
+
if (Predicate.isUndefined(built))
|
|
795
|
+
built = build();
|
|
796
|
+
return built;
|
|
797
|
+
};
|
|
798
|
+
return {
|
|
799
|
+
run: () => track().run(),
|
|
800
|
+
stop: () => UndefinedOr.map(built, (made) => made.stop()),
|
|
801
|
+
cancel: () => UndefinedOr.map(built, (made) => made.cancel()),
|
|
802
|
+
duration: () => track().duration(),
|
|
803
|
+
};
|
|
804
|
+
};
|
|
678
805
|
/**
|
|
679
806
|
* An **Animation scope**'s `animate` (#433), over an Environment's {@link Ports}: `animate(subject,
|
|
680
807
|
* target, options?)`, a Batch's `animate(batch, target, options?)` and `animate(sequence, options?)`,
|
|
681
808
|
* each returning its Playback controls. `scope()` is handed to the Environment's {@link Subjects.resolve}
|
|
682
|
-
* (
|
|
809
|
+
* (`@wardic/dom` looks its strings up inside it); each animation is told to `watch` as it starts and
|
|
683
810
|
* ends. Every Subject's legs start in the call, on the loop by the end of its task. An Environment
|
|
684
811
|
* types its own overloads over it.
|
|
812
|
+
*
|
|
813
|
+
* A key a target or its Transition end names that a Subject can't take (its Environment's own value
|
|
814
|
+
* read throws: a key it lacks, say) is an error at the call, naming it, and so is a `delay` function that
|
|
815
|
+
* throws. The call then takes nothing from any of its Subjects: an animation it would have taken a key
|
|
816
|
+
* from runs on.
|
|
817
|
+
* A Transition end's key a Subject can no longer set when it lands is reported, left as it is, and the
|
|
818
|
+
* rest of its end set: the call lands.
|
|
685
819
|
*/
|
|
686
820
|
export const make = (env, ports, scope, watch) => (first, second, third) => {
|
|
687
821
|
if (isSequence(first))
|
|
@@ -690,7 +824,7 @@ export const make = (env, ports, scope, watch) => (first, second, third) => {
|
|
|
690
824
|
const batch = ports.batches.entryOf(first);
|
|
691
825
|
if (Predicate.isNotUndefined(batch)) {
|
|
692
826
|
const members = batch.binding.namedOf(batch);
|
|
693
|
-
return started(watch, 1, UndefinedOr.map(third, (given) => given.onComplete), (head, settled) => [
|
|
827
|
+
return started(env.runtime, watch, 1, UndefinedOr.map(third, (given) => given.onComplete), (head, settled) => [
|
|
694
828
|
batchTrackOf(env, batch.binding, second, members, third, head, settled),
|
|
695
829
|
]);
|
|
696
830
|
}
|
|
@@ -700,14 +834,29 @@ export const make = (env, ports, scope, watch) => (first, second, third) => {
|
|
|
700
834
|
// No member's Subject among them: each Subject's track, building no parts (bench:solid --batch's
|
|
701
835
|
// per-element page, a call per element: 8.2 -> 8.5 ms at 1,000 with the parts built for every call; #665).
|
|
702
836
|
if (Bool.not(ports.batches.hasMembers(subjects))) {
|
|
703
|
-
return started(watch, subjects.length, onComplete, (head, settled) =>
|
|
837
|
+
return started(env.runtime, watch, subjects.length, onComplete, (head, settled) => {
|
|
838
|
+
// One Subject: readied, then its track, which takes its keys once they're all read.
|
|
839
|
+
if (subjects.length === 1)
|
|
840
|
+
return [trackOf(env, readiedOf(env, ports.subjects, subjects[0], target), transitionFor(third, 0, 1), head, settled)];
|
|
841
|
+
// Every Subject readied, and its transition worked out (a `delay(i, n)` called), before any track takes a key (#973; #979, row 20).
|
|
842
|
+
const readied = Arr.map(subjects, (subject) => readiedOf(env, ports.subjects, subject, target));
|
|
843
|
+
const transitions = Arr.map(subjects, (_, index) => transitionFor(third, index, subjects.length));
|
|
844
|
+
return Arr.zipWith(readied, transitions, (each, transition) => trackOf(env, each, transition, head, settled));
|
|
845
|
+
});
|
|
704
846
|
}
|
|
705
847
|
// A Batch's members' Subjects as one call over them, with its keys; the rest of each Subject's on its own (#665, Q14, Q35).
|
|
706
848
|
const parts = ports.batches.callPartsOf(subjects, target);
|
|
707
|
-
return started(watch, parts.members.length + parts.subjects.length, onComplete, (head, settled) =>
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
849
|
+
return started(env.runtime, watch, parts.members.length + parts.subjects.length, onComplete, (head, settled) => {
|
|
850
|
+
// A Batch's track takes nothing until it runs; every other Subject readied, and its transition worked
|
|
851
|
+
// out, before any track is built (#973). The Batch parts run first, and each other Subject's track is
|
|
852
|
+
// built as it runs, so a Batch part's `delay` that throws takes nothing either (#979, row 20).
|
|
853
|
+
const readied = Arr.map(parts.subjects, (part) => readiedOf(env, ports.subjects, part.subject, part.target));
|
|
854
|
+
const transitions = Arr.map(parts.subjects, (part) => transitionFor(third, part.index, subjects.length));
|
|
855
|
+
return [
|
|
856
|
+
...Arr.map(parts.members, (part) => batchTrackOf(env, part.binding, part.target, part.members, third, head, settled)),
|
|
857
|
+
...Arr.zipWith(readied, transitions, (each, transition) => builtAtRun(() => trackOf(env, each, transition, head, settled))),
|
|
858
|
+
];
|
|
859
|
+
});
|
|
711
860
|
};
|
|
712
861
|
// --- Sequences (#433's PR 2) ------------------------------------------------------------------
|
|
713
862
|
/** Whether `given` is a sequence rather than a subject (#433, Motion's `isSequence`): a list with a Segment, itself a list, in it; a list of Subjects has none. A binding whose `animate` is its own tells the forms apart by it (#798). */
|
|
@@ -720,6 +869,8 @@ const VALUE = "value";
|
|
|
720
869
|
const ZERO_TO_ONE = [0, 1];
|
|
721
870
|
/** No fields. */
|
|
722
871
|
const NO_FIELDS = {};
|
|
872
|
+
/** What a function Segment's callback, or its run, failing is reported as. */
|
|
873
|
+
const SEGMENT_FAILED = "wardic.animate: a function Segment failed";
|
|
723
874
|
/**
|
|
724
875
|
* What a Segment's transition doesn't take from the sequence's `defaultTransition` (Motion's): its
|
|
725
876
|
* delay, times and repeat, which are each Segment's own, and a value's own transitions.
|
|
@@ -759,8 +910,10 @@ const segmentTransitionOf = (options, key, defaults) => {
|
|
|
759
910
|
});
|
|
760
911
|
return Bool.match(Predicate.isUndefined(delay), { onTrue: () => run, onFalse: () => ({ ...run, delay }) });
|
|
761
912
|
};
|
|
913
|
+
/** Whether a function Segment's second part is its value: a number, a string or a list of stops. Anything else is its options. */
|
|
914
|
+
const isFunctionSegmentValue = /*#__PURE__*/ Predicate.or(/*#__PURE__*/ Predicate.or(Predicate.isNumber, Predicate.isString), Arr.isArray);
|
|
762
915
|
/** Whether a Segment's value is one: a number, a string, `null` or Keyframes. */
|
|
763
|
-
const isSegmentValue = /*#__PURE__*/ Predicate.or(
|
|
916
|
+
const isSegmentValue = /*#__PURE__*/ Predicate.or(isFunctionSegmentValue, Predicate.isNull);
|
|
764
917
|
/** A Segment's values: those that are a value, `null` or Keyframes. */
|
|
765
918
|
const segmentValuesOf = (target) => Rec.filter(target, isSegmentValue);
|
|
766
919
|
/** Each of `values`' keys' transition in a Segment. */
|
|
@@ -778,7 +931,7 @@ const subjectsIn = (batches, subjects, target) => {
|
|
|
778
931
|
};
|
|
779
932
|
/**
|
|
780
933
|
* A sequence's steps for core (#433): labels as they are; a Segment of Subjects' Subjects (a string
|
|
781
|
-
* the Environment resolves,
|
|
934
|
+
* the Environment resolves, looked up once a sequence, inside `scope`), values and each
|
|
782
935
|
* value's transition; a function Segment's own value, from 0 to 1 unless it gives its stops.
|
|
783
936
|
*/
|
|
784
937
|
const stepsOf = (ports, sequence, scope, defaults) => {
|
|
@@ -809,9 +962,12 @@ const stepsOf = (ports, sequence, scope, defaults) => {
|
|
|
809
962
|
}
|
|
810
963
|
if (Predicate.isFunction(parts[0])) {
|
|
811
964
|
const call = parts[0];
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
const options = Bool.match(
|
|
965
|
+
// #975 (ADR-0061, *Amendment (#975)*): two parts are a value and no options when the second is one,
|
|
966
|
+
// as Motion's `[value, keyframes]`; read as options, a number was dropped, and an array's `at` threw.
|
|
967
|
+
const [given, options] = Bool.match(Bool.or(parts.length === 3, isFunctionSegmentValue(parts[1])), {
|
|
968
|
+
onTrue: () => [parts[1], parts[2]],
|
|
969
|
+
onFalse: () => [ZERO_TO_ONE, parts[1]],
|
|
970
|
+
});
|
|
815
971
|
const target = { [VALUE]: given };
|
|
816
972
|
return { subjects: [{ call }], target, transitions: segmentTransitionsOf(target, options, defaults), at: atOf(options) };
|
|
817
973
|
}
|
|
@@ -840,7 +996,9 @@ export const segmentAnimates = (ports, segment, scope) => {
|
|
|
840
996
|
/**
|
|
841
997
|
* A function Segment's value animated (#433): its stops, a first `null` 0, through the
|
|
842
998
|
* Interpolators on its tween over the sequence, each frame told to its callback. Cancelled, the
|
|
843
|
-
* callback hears its first stop again, as Motion's motion value is set back.
|
|
999
|
+
* callback hears its first stop again, as Motion's motion value is set back. A callback that throws is
|
|
1000
|
+
* reported, once a run of throws, and told the next frame's value all the same; one that throws on a
|
|
1001
|
+
* cancel, each time, the call's cancel going on.
|
|
844
1002
|
*/
|
|
845
1003
|
const callbackTrackOf = (env, callback, animation, head, settled) => {
|
|
846
1004
|
const stops = RetargetLegs.filledStops(UndefinedOr.getOrThrow(animation.keyframes[VALUE]), 0);
|
|
@@ -851,6 +1009,8 @@ const callbackTrackOf = (env, callback, animation, head, settled) => {
|
|
|
851
1009
|
onFalse: () => Machine.keyframesValues({ [VALUE]: stops }, options),
|
|
852
1010
|
});
|
|
853
1011
|
let fiber;
|
|
1012
|
+
// Its callback threw, reported, and hasn't returned since (#979, row 18).
|
|
1013
|
+
let failing = false;
|
|
854
1014
|
const end = () => {
|
|
855
1015
|
if (Predicate.isUndefined(fiber))
|
|
856
1016
|
return;
|
|
@@ -862,12 +1022,26 @@ const callbackTrackOf = (env, callback, animation, head, settled) => {
|
|
|
862
1022
|
};
|
|
863
1023
|
const landed = (exit) => Exit.match(exit, {
|
|
864
1024
|
onSuccess: () => Effect.sync(() => settled(true)),
|
|
865
|
-
onFailure: (cause) => Bool.match(Cause.hasInterruptsOnly(cause), { onTrue: () => Effect.void, onFalse: () => Report.failure(
|
|
1025
|
+
onFailure: (cause) => Bool.match(Cause.hasInterruptsOnly(cause), { onTrue: () => Effect.void, onFalse: () => Report.failure(SEGMENT_FAILED, cause) }),
|
|
866
1026
|
});
|
|
867
1027
|
const run = () => {
|
|
868
1028
|
end();
|
|
1029
|
+
// A run of its own: a throw in it is reported, whatever the last run's last call did.
|
|
1030
|
+
failing = false;
|
|
869
1031
|
fiber = env.runtime.runFork(machine.pipe(Effect.map(Playback.drive(head)), Effect.flatMap(Machine.run((frame) => {
|
|
870
|
-
|
|
1032
|
+
const value = UndefinedOr.getOrThrow(frame.value[VALUE]);
|
|
1033
|
+
// Its callback's throw is its own: told again next frame, its Segment landing as its stops do (ADR-0074).
|
|
1034
|
+
try {
|
|
1035
|
+
callback.call(value);
|
|
1036
|
+
if (failing)
|
|
1037
|
+
failing = false;
|
|
1038
|
+
}
|
|
1039
|
+
catch (defect) {
|
|
1040
|
+
if (!failing) {
|
|
1041
|
+
failing = true;
|
|
1042
|
+
env.runtime.runFork(Report.failure(SEGMENT_FAILED, Cause.die(defect)));
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
871
1045
|
return undefined;
|
|
872
1046
|
})), Effect.onExit(landed)));
|
|
873
1047
|
};
|
|
@@ -876,7 +1050,14 @@ const callbackTrackOf = (env, callback, animation, head, settled) => {
|
|
|
876
1050
|
stop: end,
|
|
877
1051
|
cancel: () => {
|
|
878
1052
|
end();
|
|
879
|
-
|
|
1053
|
+
const first = UndefinedOr.getOrThrow(stops[0]);
|
|
1054
|
+
// Told its first stop once its run has ended: a throw there is reported, and the call's cancel goes on (#979, row 19).
|
|
1055
|
+
try {
|
|
1056
|
+
callback.call(first);
|
|
1057
|
+
}
|
|
1058
|
+
catch (defect) {
|
|
1059
|
+
env.runtime.runFork(Report.failure("wardic.animate: a function Segment's cancel failed", Cause.die(defect)));
|
|
1060
|
+
}
|
|
880
1061
|
},
|
|
881
1062
|
duration: () => Machine.durationOf(env.runtime.runSync(machine)),
|
|
882
1063
|
};
|
|
@@ -896,14 +1077,24 @@ const sequenceOf = (env, ports, scope, watch, sequence, options) => {
|
|
|
896
1077
|
const compiled = Arr.fromIterable(Sequence.compile(stepsOf(ports, sequence, scope, defaults), whole));
|
|
897
1078
|
// Each Batch's members as one track, their other keys their Subjects' (#665, Q40).
|
|
898
1079
|
const parts = ports.batches.sequencePartsOf(compiled);
|
|
899
|
-
return started(watch, compiled.length, UndefinedOr.map(options, (given) => given.onComplete), (head, settled) =>
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
1080
|
+
return started(env.runtime, watch, compiled.length, UndefinedOr.map(options, (given) => given.onComplete), (head, settled) => {
|
|
1081
|
+
// Every Segment's Subject readied before any track takes a key, a later one's refusal taking nothing (#973).
|
|
1082
|
+
const readied = Arr.map(parts.others, ([subject, animation]) => segmentReadiedOf(env, ports.subjects, subject, animation));
|
|
1083
|
+
return [
|
|
1084
|
+
...Arr.map(parts.others, ([subject, animation], i) => {
|
|
1085
|
+
if (isCallback(subject))
|
|
1086
|
+
return callbackTrackOf(env, subject, animation, head, settled);
|
|
1087
|
+
return trackOf(env, UndefinedOr.getOrThrow(readied[i]), animation.transition, head, settled);
|
|
1088
|
+
}),
|
|
1089
|
+
...Arr.map(parts.batches, (part) => part.binding.sequenceTrack({ members: part.members, animations: part.animations, reducedMotion: env.reducedMotion(), skipAnimations: env.skipAnimations(), head, settled: () => settled(true), taken: () => settled(false) })),
|
|
1090
|
+
];
|
|
1091
|
+
});
|
|
1092
|
+
};
|
|
1093
|
+
/** A sequence's Subject readied (`readiedOf`) for its compiled animation: none for a function Segment's callback, which has no keys. */
|
|
1094
|
+
const segmentReadiedOf = (env, subjects, subject, animation) => {
|
|
1095
|
+
if (isCallback(subject))
|
|
1096
|
+
return undefined;
|
|
1097
|
+
return readiedOf(env, subjects, subject, animation.keyframes);
|
|
907
1098
|
};
|
|
908
1099
|
/** `watch`, with `also` told each start and end after it, when given: a scope's own watch beside its owner's (#433), a binding's beside a scope's (#798). */
|
|
909
1100
|
export const alsoTold = (watch, also) => UndefinedOr.match(also, {
|