@wardic/core 1.3.0 → 1.3.2
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/BaseValue.d.ts +1 -1
- package/dist/BaseValue.js +2 -2
- package/dist/BaseValue.js.map +1 -1
- package/dist/Batch.d.ts +5 -9
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +195 -24
- 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 +13 -0
- package/dist/Clock.js.map +1 -1
- package/dist/DragRecognizer.d.ts +10 -5
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +60 -24
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/Frame.js +1 -1
- package/dist/Frame.js.map +1 -1
- package/dist/InputFeed.d.ts +10 -7
- package/dist/InputFeed.d.ts.map +1 -1
- package/dist/InputFeed.js +16 -35
- package/dist/InputFeed.js.map +1 -1
- package/dist/LiveValue.d.ts +9 -3
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +160 -14
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +16 -6
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +50 -27
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +10 -8
- package/dist/Playback.js.map +1 -1
- package/dist/Recognizer.d.ts +1 -1
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +9 -4
- package/dist/Recognizer.js.map +1 -1
- package/dist/internal/frameLoop.d.ts +10 -2
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +148 -18
- 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/stepper.d.ts +9 -3
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +5 -4
- package/dist/internal/stepper.js.map +1 -1
- package/dist/unstable/AnimationControls.d.ts +15 -8
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +36 -15
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +6 -0
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/AppearHandoff.js.map +1 -1
- package/dist/unstable/BatchCalls.d.ts +16 -1
- package/dist/unstable/BatchCalls.d.ts.map +1 -1
- package/dist/unstable/BatchCalls.js +8 -0
- package/dist/unstable/BatchCalls.js.map +1 -1
- package/dist/unstable/Config.d.ts +16 -1
- package/dist/unstable/Config.d.ts.map +1 -1
- package/dist/unstable/Config.js.map +1 -1
- package/dist/unstable/FlushGate.d.ts +4 -2
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +155 -38
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +4 -1
- package/dist/unstable/FrameEffects.d.ts.map +1 -1
- package/dist/unstable/FrameEffects.js +12 -1
- package/dist/unstable/FrameEffects.js.map +1 -1
- package/dist/unstable/Imperative.d.ts +42 -11
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +413 -77
- 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/PresenceRecord.d.ts +4 -0
- package/dist/unstable/PresenceRecord.d.ts.map +1 -1
- package/dist/unstable/PresenceRecord.js.map +1 -1
- package/dist/unstable/Report.d.ts +7 -0
- package/dist/unstable/Report.d.ts.map +1 -1
- package/dist/unstable/Report.js +17 -1
- package/dist/unstable/Report.js.map +1 -1
- package/dist/unstable/RetargetLegs.d.ts +6 -0
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +15 -0
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +62 -10
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +190 -40
- package/dist/unstable/Spine.js.map +1 -1
- package/dist/unstable/VariantTarget.d.ts +25 -3
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +66 -13
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +37 -3
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +54 -7
- package/dist/unstable/VariantTree.js.map +1 -1
- package/package.json +1 -1
- package/src/BaseValue.ts +2 -2
- package/src/Batch.ts +210 -20
- package/src/Clock.ts +20 -0
- package/src/DragRecognizer.ts +82 -30
- package/src/Frame.ts +1 -1
- package/src/InputFeed.ts +37 -40
- package/src/LiveValue.ts +140 -14
- package/src/Machine.ts +67 -34
- package/src/Playback.ts +10 -8
- package/src/Recognizer.ts +9 -3
- package/src/internal/frameLoop.ts +165 -19
- package/src/internal/guarded.ts +69 -0
- package/src/internal/stepper.ts +14 -5
- package/src/unstable/AnimationControls.ts +49 -21
- package/src/unstable/AppearHandoff.ts +7 -0
- package/src/unstable/BatchCalls.ts +20 -2
- package/src/unstable/Config.ts +24 -1
- package/src/unstable/FlushGate.ts +169 -37
- package/src/unstable/FrameEffects.ts +15 -2
- package/src/unstable/Imperative.ts +447 -89
- package/src/unstable/MeasuredPairs.ts +7 -1
- package/src/unstable/PresenceRecord.ts +4 -0
- package/src/unstable/Report.ts +19 -1
- package/src/unstable/RetargetLegs.ts +14 -0
- package/src/unstable/Spine.ts +244 -43
- package/src/unstable/VariantTarget.ts +93 -14
- package/src/unstable/VariantTree.ts +87 -6
|
@@ -13,7 +13,8 @@ import * as Bool from "effect/Boolean";
|
|
|
13
13
|
import * as Cause from "effect/Cause";
|
|
14
14
|
import * as Effect from "effect/Effect";
|
|
15
15
|
import * as Exit from "effect/Exit";
|
|
16
|
-
import { constVoid, identity } from "effect/Function";
|
|
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";
|
|
@@ -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),
|
|
@@ -119,25 +120,72 @@ const IMPERATIVE = {
|
|
|
119
120
|
keyframes: undefined,
|
|
120
121
|
change: undefined,
|
|
121
122
|
};
|
|
123
|
+
/** The target the Override stack had for each key at the spine's last Retarget: what a taken key is noted with. */
|
|
124
|
+
const lastTargetsOf = (host) => UndefinedOr.match(host.lastResolution(), { onUndefined: () => Spine.NO_VALUES, onDefined: (last) => last.resolved });
|
|
125
|
+
/**
|
|
126
|
+
* `key` taken by an Imperative animation from whatever runs it (#433): noted in `taking` with `noted`,
|
|
127
|
+
* the target the Override stack has for it now, no longer returning, its Timeline value stopped, given
|
|
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.
|
|
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.
|
|
134
|
+
const takeKey = (host, taking, key, noted, like, started) => {
|
|
135
|
+
taking.set(key, noted);
|
|
136
|
+
host.returning().delete(key);
|
|
137
|
+
// Its Timeline value stops while the animation draws the key (#240).
|
|
138
|
+
const timelineKeys = host.timelineKeys();
|
|
139
|
+
if (Predicate.isNotUndefined(timelineKeys))
|
|
140
|
+
timelineKeys.taken(key);
|
|
141
|
+
const owner = host.owners.get(key);
|
|
142
|
+
if (Predicate.isNotUndefined(owner))
|
|
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) => {
|
|
152
|
+
if (!Object.hasOwn(host.initialValues, key))
|
|
153
|
+
host.ownValue(key);
|
|
154
|
+
};
|
|
155
|
+
/** Whether a Transition end may set a key drawn by `owner`: none draws it, or its leg is done. */
|
|
156
|
+
const endFree = (owner) => {
|
|
157
|
+
if (Predicate.isUndefined(owner))
|
|
158
|
+
return true;
|
|
159
|
+
return owner.done;
|
|
160
|
+
};
|
|
122
161
|
/**
|
|
123
162
|
* An **Imperative animation** of a Subject (#433), through its spine's `host`: it takes `target`'s
|
|
124
163
|
* keys from whatever runs them, each noted with the target the Override stack has for it now, so a
|
|
125
164
|
* Retarget leaves it where the animation leaves it until that target changes (Motion's latest-wins).
|
|
126
165
|
* Its legs start where the keys are drawn, with their velocity, on `given` (a key with none of its own
|
|
127
166
|
* on its Default transition), reduced motion as the provider says, and run through `head` once
|
|
128
|
-
* {@link Spine.ImperativeTrack.run} is called.
|
|
167
|
+
* {@link Spine.ImperativeTrack.run} is called. Once they land, none taken, its target's Transition
|
|
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).
|
|
129
171
|
*/
|
|
130
172
|
// #746 (ADR-0067, *Amendment (#746)*, decision 10): here, not in the spine, so an app that never animates
|
|
131
173
|
// imperatively ships none of it; the spine hands over what it takes (`SpineHost`).
|
|
132
174
|
const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
133
|
-
const { snapshot, owners,
|
|
175
|
+
const { snapshot, owners, keepTheRest, element, positionalKeys, defaultTransition, unitScale, readVelocity, gate, forget, endLeg, live, own, legProgram, legEnded, turnBack, id, recordFrame, runtime, elementRules, measuredPairs, variableValues } = host;
|
|
134
176
|
/** A leg of an Imperative animation, forked as a Retarget's are; it lands on its track. */
|
|
135
177
|
// Data-first: a pipe's curried forms are two closures more for every leg (#618, H1).
|
|
136
178
|
const runImperative = (running, program) => {
|
|
137
|
-
|
|
179
|
+
const at = runs;
|
|
180
|
+
running.fiber = runtime.runFork(Effect.asVoid(Effect.onExit(program, (exit) => {
|
|
181
|
+
if (at === runs)
|
|
182
|
+
supersededAt(running);
|
|
183
|
+
return legEnded(running)(exit);
|
|
184
|
+
})));
|
|
138
185
|
};
|
|
139
186
|
const to = target.values;
|
|
140
|
-
const
|
|
187
|
+
const ends = target.transitionEnd;
|
|
188
|
+
const before = lastTargetsOf(host);
|
|
141
189
|
const started = {};
|
|
142
190
|
let measuring;
|
|
143
191
|
// Each key taken from whatever runs it, noted with its target now, and started where it's drawn.
|
|
@@ -146,19 +194,8 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
146
194
|
// Where a Path's axis this target leaves out rests (#574), before its keys are taken below.
|
|
147
195
|
const rests = Spine.restsOf(owners, to);
|
|
148
196
|
Arr.forEach(Rec.keys(to), (key) => {
|
|
149
|
-
takenNow.set(key, before[key]);
|
|
150
|
-
host.returning().delete(key);
|
|
151
|
-
// Its Timeline value stops while the animation draws the key (#240).
|
|
152
|
-
const timelineKeys = host.timelineKeys();
|
|
153
|
-
if (Predicate.isNotUndefined(timelineKeys))
|
|
154
|
-
timelineKeys.taken(key);
|
|
155
|
-
const owner = owners.get(key);
|
|
156
|
-
if (Predicate.isNotUndefined(owner))
|
|
157
|
-
giveUp(key, owner);
|
|
158
|
-
if (!Object.hasOwn(initialValues, key))
|
|
159
|
-
ownValue(key);
|
|
160
197
|
const like = UndefinedOr.getOrThrow(to[key]);
|
|
161
|
-
|
|
198
|
+
takeKey(host, takenNow, key, before[key], like, started);
|
|
162
199
|
if (measuredPairs.needs(key, UndefinedOr.getOrThrow(snapshot.values[key]), like)) {
|
|
163
200
|
if (Predicate.isUndefined(measuring))
|
|
164
201
|
measuring = [];
|
|
@@ -177,30 +214,176 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
177
214
|
const skipped = host.skipAnimations();
|
|
178
215
|
let measured;
|
|
179
216
|
if (Bool.and(Bool.not(Bool.or(reduce, skipped)), Predicate.isNotUndefined(measuring)))
|
|
180
|
-
measured = Spine.measuredOf(measuredPairs, element, UndefinedOr.getOrThrow(measuring), from, to, snapshot.values, stops);
|
|
217
|
+
measured = Spine.measuredOf(measuredPairs, element, UndefinedOr.getOrThrow(measuring), from, to, snapshot.values, stops, runtime, id);
|
|
181
218
|
// Built once: a seek or a replay runs the same legs, from the same start, with the same velocities.
|
|
182
219
|
const built = RetargetLegs.legsOf(from, to, given, reduce, skipped, positionalKeys, defaultTransition, readVelocity, undefined, stops, measured, snapshot.values, rests, unitScale);
|
|
183
220
|
const variables = Spine.holdsVariable(variableValues, from, to, stops);
|
|
184
221
|
const legs = Arr.map(built, (leg) => RetargetLegs.mapMachine(leg, Playback.drive(head)));
|
|
185
222
|
let runnings = Spine.NO_RUNNING;
|
|
186
223
|
let left = 0;
|
|
224
|
+
// What its Transition end's keys were before it set them (Q5): `undefined` until it has.
|
|
225
|
+
let overwritten;
|
|
226
|
+
// Its runs, stops and cancels, counted: what a landing waiting on a flush checks it's still for.
|
|
227
|
+
let runs = 0;
|
|
228
|
+
// `values` drawn at once, at rest: newer than the legs that let them go (#464).
|
|
229
|
+
const setAtRest = (values) => {
|
|
230
|
+
snapshot.values = { ...snapshot.values, ...values };
|
|
231
|
+
snapshot.velocities = { ...snapshot.velocities, ...Rec.map(values, () => 0) };
|
|
232
|
+
const now = snapshot.now();
|
|
233
|
+
Arr.forEach(Rec.keys(values), (key) => {
|
|
234
|
+
snapshot.drawnAt[key] = now;
|
|
235
|
+
});
|
|
236
|
+
gate.write(id, values);
|
|
237
|
+
recordFrame(values);
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* Its **Transition end** set (#896, ADR-0061 *Amendment (#896)*, Q2 and Q4): each key no leg draws
|
|
241
|
+
* now taken as the keys it animates are, started where it's drawn, then set at once.
|
|
242
|
+
*/
|
|
243
|
+
// Each of `values`' keys `only` picks taken as the call took its own (`takeKey`), noted with the
|
|
244
|
+
// Override stack's targets now: an end's keys as it's set, a run's again as it starts (#951).
|
|
245
|
+
const takeEach = (values, only) => {
|
|
246
|
+
const takingNow = host.taking();
|
|
247
|
+
const targetsNow = lastTargetsOf(host);
|
|
248
|
+
const startedNow = {};
|
|
249
|
+
Arr.forEach(Rec.keys(values), (key) => {
|
|
250
|
+
if (only(key))
|
|
251
|
+
takeKey(host, takingNow, key, targetsNow[key], UndefinedOr.getOrThrow(values[key]), startedNow);
|
|
252
|
+
});
|
|
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
|
+
};
|
|
267
|
+
const writeEnds = (values) => {
|
|
268
|
+
const free = Rec.filter(values, (_, key) => endFree(owners.get(key)) && settableOrReported(key));
|
|
269
|
+
if (Rec.isEmptyRecord(free))
|
|
270
|
+
return;
|
|
271
|
+
takeEach(free, constTrue);
|
|
272
|
+
// Kept from an earlier landing a run from its end didn't put back: what they were before any.
|
|
273
|
+
if (Predicate.isUndefined(overwritten))
|
|
274
|
+
overwritten = Rec.map(free, (_, key) => UndefinedOr.getOrThrow(snapshot.values[key]));
|
|
275
|
+
setAtRest(free);
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Its Transition end's keys put back as they were before it was set (Q5): at a cancel, a seek or a
|
|
279
|
+
* replay, each a key no leg has drawn since, a later call's or the element's own. The next landing
|
|
280
|
+
* sets them again.
|
|
281
|
+
*/
|
|
282
|
+
const putBack = () => {
|
|
283
|
+
if (Predicate.isUndefined(overwritten))
|
|
284
|
+
return;
|
|
285
|
+
// Its take left each without an owner: one since is a later animation's, which wins.
|
|
286
|
+
const back = Rec.filter(overwritten, (_, key) => Predicate.isUndefined(owners.get(key)));
|
|
287
|
+
overwritten = undefined;
|
|
288
|
+
if (Bool.not(Rec.isEmptyRecord(back)))
|
|
289
|
+
setAtRest(back);
|
|
290
|
+
};
|
|
291
|
+
// Whether its `i`th leg snaps (#468's skip, reduced motion's positional keys): it lands on its next
|
|
292
|
+
// frame, its keys landed from its start, so a take before then takes nothing in flight, as Motion's
|
|
293
|
+
// skipped value makes no animation. Its machine read only for a leg that lost a key.
|
|
294
|
+
const snaps = (i) => Machine.durationOf(machineOf(UndefinedOr.getOrThrow(built[i]))) === 0;
|
|
295
|
+
// A leg the element's own Retarget carried on, toward the same target, as its own (Q7): the call has lost it.
|
|
296
|
+
let carried = false;
|
|
297
|
+
// Taken (#896's Q3, #951): a key it animates taken from its leg mid-flight, by a later animation or the
|
|
298
|
+
// element's own target, or a leg carried off whole. A leg that lost one has fewer than it started
|
|
299
|
+
// with; one taken after its leg landed doesn't count, as Motion's, nor one that snaps.
|
|
300
|
+
const taken = () => {
|
|
301
|
+
if (carried)
|
|
302
|
+
return true;
|
|
303
|
+
return Arr.some(runnings, (running, i) => Bool.and(running.count < Rec.size(running.targets), Bool.not(snaps(i))));
|
|
304
|
+
};
|
|
305
|
+
// Landed: its Transition end set at the flush after its last leg's frame, then the landing told
|
|
306
|
+
// after the flush that draws it, so the landing includes it (ADR-0057 decision 4). Taken, it ends
|
|
307
|
+
// without landing, its end dropped, as Motion's call never resolves (ADR-0061 *Amendment (#951)*).
|
|
308
|
+
// A run, a stop or a cancel since makes each wait stale: a take reported synchronously, then a seek
|
|
309
|
+
// in the same task, or a stop between its end and its landing, tells none.
|
|
310
|
+
const landed = () => {
|
|
311
|
+
const at = runs;
|
|
312
|
+
if (taken()) {
|
|
313
|
+
return gate.afterFlush(() => {
|
|
314
|
+
if (at === runs)
|
|
315
|
+
hooks.settled(false);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
if (Predicate.isUndefined(ends)) {
|
|
319
|
+
return gate.afterFlush(() => {
|
|
320
|
+
if (at === runs)
|
|
321
|
+
hooks.settled(true);
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
gate.afterFlush(() => {
|
|
325
|
+
if (at !== runs)
|
|
326
|
+
return;
|
|
327
|
+
writeEnds(ends);
|
|
328
|
+
gate.afterFlush(() => {
|
|
329
|
+
if (at === runs)
|
|
330
|
+
hooks.settled(true);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
// A leg landed, or was Superseded (#951): the last lands the track, or finds it taken.
|
|
335
|
+
const legDone = () => {
|
|
336
|
+
left--;
|
|
337
|
+
if (left === 0)
|
|
338
|
+
landed();
|
|
339
|
+
};
|
|
187
340
|
const landing = {
|
|
188
341
|
report: constVoid,
|
|
189
|
-
settled:
|
|
190
|
-
left--;
|
|
191
|
-
if (left === 0)
|
|
192
|
-
gate.afterFlush(hooks.settled);
|
|
193
|
-
},
|
|
342
|
+
settled: legDone,
|
|
194
343
|
failed: hooks.failed,
|
|
195
344
|
};
|
|
345
|
+
/**
|
|
346
|
+
* A leg of this run ended **Superseded** (#951), told at its end, as it settles nothing of this
|
|
347
|
+
* track's: carried on by the element's own Retarget as its own, its landing the Retarget's now (Q7);
|
|
348
|
+
* or with every key taken, a count of 0 (only a take lowers it), which `taken` reads. Either counts
|
|
349
|
+
* toward the track's landing, which finds it taken.
|
|
350
|
+
*/
|
|
351
|
+
// Here, not in the spine, so an app with no Imperative animation pays nothing for it.
|
|
352
|
+
const supersededAt = (running) => {
|
|
353
|
+
if (running.landing !== landing) {
|
|
354
|
+
carried = true;
|
|
355
|
+
return legDone();
|
|
356
|
+
}
|
|
357
|
+
if (running.count === 0)
|
|
358
|
+
legDone();
|
|
359
|
+
};
|
|
196
360
|
// Its legs ended where they are: the keys they draw are drawn by none.
|
|
197
361
|
const end = () => Arr.forEach(runnings, (running) => {
|
|
198
362
|
forget(running);
|
|
199
363
|
if (Bool.not(running.done))
|
|
200
364
|
endLeg(running);
|
|
201
365
|
});
|
|
366
|
+
// Whether a run starts at its end, going forward, its end set: it lands at once, so its end stays,
|
|
367
|
+
// with no frame without it (a seek to the end, `complete()`). Its duration read only then.
|
|
368
|
+
const fromItsEnd = () => {
|
|
369
|
+
if (Predicate.isUndefined(overwritten))
|
|
370
|
+
return false;
|
|
371
|
+
if (head.speed < 0)
|
|
372
|
+
return false;
|
|
373
|
+
return head.time >= duration();
|
|
374
|
+
};
|
|
375
|
+
// A key another leg draws: a later animation's, or the element's own.
|
|
376
|
+
const drawnByAnother = (key) => Predicate.isNotUndefined(owners.get(key));
|
|
202
377
|
const run = () => {
|
|
378
|
+
runs++;
|
|
203
379
|
end();
|
|
380
|
+
carried = false;
|
|
381
|
+
// Run again, it takes each of its keys from whatever draws it now, as the call took them (#951): one
|
|
382
|
+
// leg draws a key. The first run's are taken already.
|
|
383
|
+
if (runs > 1)
|
|
384
|
+
takeEach(to, drawnByAnother);
|
|
385
|
+
if (Bool.not(fromItsEnd()))
|
|
386
|
+
putBack();
|
|
204
387
|
left = legs.length;
|
|
205
388
|
Spine.tellStarted(live, legs);
|
|
206
389
|
runnings = Arr.map(legs, (leg) => {
|
|
@@ -211,20 +394,15 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
211
394
|
});
|
|
212
395
|
// A target with no key lands at once.
|
|
213
396
|
if (left === 0)
|
|
214
|
-
|
|
397
|
+
landed();
|
|
215
398
|
};
|
|
216
399
|
const cancel = () => {
|
|
400
|
+
runs++;
|
|
217
401
|
end();
|
|
218
402
|
turnBack();
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const now = snapshot.now();
|
|
223
|
-
Arr.forEach(Rec.keys(from), (key) => {
|
|
224
|
-
snapshot.drawnAt[key] = now;
|
|
225
|
-
});
|
|
226
|
-
gate.write(id, from);
|
|
227
|
-
recordFrame(from);
|
|
403
|
+
putBack();
|
|
404
|
+
// Put back at once, its keys where it started them.
|
|
405
|
+
setAtRest(from);
|
|
228
406
|
};
|
|
229
407
|
// Each leg's machine, run from its start to rest, apart from the Playhead, which it would move: a
|
|
230
408
|
// blend's built with the Subject's Key rules.
|
|
@@ -235,23 +413,70 @@ const imperativeTrackOf = (host, target, given, head, hooks) => {
|
|
|
235
413
|
return leg.machine();
|
|
236
414
|
};
|
|
237
415
|
const stop = () => {
|
|
416
|
+
runs++;
|
|
238
417
|
end();
|
|
239
418
|
turnBack();
|
|
240
419
|
};
|
|
241
420
|
return { run, stop, cancel, duration };
|
|
242
421
|
};
|
|
243
422
|
/**
|
|
244
|
-
* A
|
|
245
|
-
*
|
|
423
|
+
* A call's transition on its target's own (#896, ADR-0061 *Amendment (#896)*, Q1): the options' fields
|
|
424
|
+
* laid over the target's, shallowly, as `inherit: true` lays a target's over its element's. Motion's
|
|
425
|
+
* `animate` reads the options alone.
|
|
426
|
+
*/
|
|
427
|
+
// Its own handed back as it is with no options, so the legs' decode cache (#66) holds for it. Its
|
|
428
|
+
// `inherit` has nothing above it in a call: the legs read none (`RetargetLegs`' `NOT_DEFINING`).
|
|
429
|
+
const overOwn = (own, given) => {
|
|
430
|
+
if (Predicate.isUndefined(own))
|
|
431
|
+
return given;
|
|
432
|
+
if (Predicate.isUndefined(given))
|
|
433
|
+
return own;
|
|
434
|
+
return { ...own, ...given };
|
|
435
|
+
};
|
|
436
|
+
/**
|
|
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.
|
|
246
441
|
*/
|
|
247
|
-
|
|
248
|
-
|
|
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;
|
|
249
450
|
const own = wardicElements.get(subject);
|
|
250
|
-
const hooks = { settled, failed: constVoid };
|
|
251
|
-
const transition = skippedIn(env, given);
|
|
252
451
|
if (Predicate.isNotUndefined(own))
|
|
253
|
-
return
|
|
452
|
+
return readOwnValues({ subject, target, host: own.host(), plain: undefined });
|
|
254
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 Wardic element'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);
|
|
255
480
|
// In the gate while it runs; out once its last animation is done, after the flush of its last frame.
|
|
256
481
|
let live = false;
|
|
257
482
|
const enter = () => {
|
|
@@ -277,10 +502,10 @@ const trackOf = (env, subjects, subject, target, given, head, settled) => {
|
|
|
277
502
|
plain.unregister();
|
|
278
503
|
});
|
|
279
504
|
};
|
|
280
|
-
const track = imperativeTrackOf(
|
|
281
|
-
settled: () => {
|
|
505
|
+
const track = imperativeTrackOf(host, target, transition, head, {
|
|
506
|
+
settled: (landed) => {
|
|
282
507
|
leave();
|
|
283
|
-
settled();
|
|
508
|
+
settled(landed);
|
|
284
509
|
},
|
|
285
510
|
failed: () => leave(),
|
|
286
511
|
});
|
|
@@ -324,7 +549,8 @@ const batchTrackOf = (env, binding, target, members, options, head, settled) =>
|
|
|
324
549
|
reducedMotion: env.reducedMotion(),
|
|
325
550
|
skipAnimations: skipsBatchCall(env, options),
|
|
326
551
|
head,
|
|
327
|
-
settled,
|
|
552
|
+
settled: () => settled(true),
|
|
553
|
+
taken: () => settled(false),
|
|
328
554
|
members,
|
|
329
555
|
});
|
|
330
556
|
/** Whether a Batch call lands at once: its scope's animations are skipped, or its own `skipAnimations` (#468). */
|
|
@@ -333,11 +559,13 @@ const skipsBatchCall = (env, options) => {
|
|
|
333
559
|
return true;
|
|
334
560
|
return UndefinedOr.match(options, { onUndefined: () => false, onDefined: (given) => given.skipAnimations === true });
|
|
335
561
|
};
|
|
336
|
-
/** Playback controls over `tracks`, all run through `head`, started now
|
|
337
|
-
const controlsOf = (tracks, head, watch, onComplete) => {
|
|
562
|
+
/** Playback controls over `tracks`, all run through `head`, started now: a throw from `onComplete` reported on `runtime`. */
|
|
563
|
+
const controlsOf = (tracks, head, watch, onComplete, runtime) => {
|
|
338
564
|
let state = "running";
|
|
339
565
|
let stopped = false;
|
|
340
566
|
let landed = 0;
|
|
567
|
+
// Whether a Subject's part ended without landing, a key of it taken by a later animation (#951).
|
|
568
|
+
let anyTaken = false;
|
|
341
569
|
let resolve;
|
|
342
570
|
let finished;
|
|
343
571
|
let isResolved = false;
|
|
@@ -349,6 +577,7 @@ const controlsOf = (tracks, head, watch, onComplete) => {
|
|
|
349
577
|
};
|
|
350
578
|
const runAll = () => {
|
|
351
579
|
landed = 0;
|
|
580
|
+
anyTaken = false;
|
|
352
581
|
Arr.forEach(tracks, (track) => track.run());
|
|
353
582
|
};
|
|
354
583
|
const fresh = () => {
|
|
@@ -453,15 +682,31 @@ const controlsOf = (tracks, head, watch, onComplete) => {
|
|
|
453
682
|
runAll();
|
|
454
683
|
},
|
|
455
684
|
};
|
|
456
|
-
// Each Subject's legs landed: the last lands the animation
|
|
457
|
-
|
|
685
|
+
// Each Subject's legs landed, or ended with a key taken: the last lands the animation, or, with one
|
|
686
|
+
// taken, ends it without landing, as a stop does (#951, Q1 and Q5). Motion's never resolves then.
|
|
687
|
+
const settledOne = (landedOne) => {
|
|
458
688
|
landed++;
|
|
689
|
+
if (Bool.not(landedOne))
|
|
690
|
+
anyTaken = true;
|
|
459
691
|
if (landed < tracks.length)
|
|
460
692
|
return;
|
|
693
|
+
if (anyTaken) {
|
|
694
|
+
stopped = true;
|
|
695
|
+
return end("idle", false);
|
|
696
|
+
}
|
|
461
697
|
isResolved = true;
|
|
462
698
|
UndefinedOr.map(resolve, (done) => done());
|
|
463
|
-
|
|
699
|
+
// Finished before its onComplete runs, as Motion's `finish()`: a throw there leaves it finished, and
|
|
700
|
+
// is reported each time it lands (#977; ADR-0074, *Amendment (#979, group A)*).
|
|
464
701
|
end("finished", true);
|
|
702
|
+
UndefinedOr.map(onComplete, (complete) => {
|
|
703
|
+
try {
|
|
704
|
+
complete();
|
|
705
|
+
}
|
|
706
|
+
catch (defect) {
|
|
707
|
+
runtime.runFork(Report.failure("wardic.animate: an onComplete failed", Cause.die(defect)));
|
|
708
|
+
}
|
|
709
|
+
});
|
|
465
710
|
};
|
|
466
711
|
return { controls, settledOne };
|
|
467
712
|
};
|
|
@@ -486,18 +731,45 @@ export const finishedControls = () => {
|
|
|
486
731
|
* An animation of `count` tracks started (#433): its controls over them, through one Playhead, told
|
|
487
732
|
* to `watch`, each track run. Finished at once with none.
|
|
488
733
|
*/
|
|
489
|
-
const started = (watch, count, onComplete, tracksOf) => {
|
|
734
|
+
const started = (runtime, watch, count, onComplete, tracksOf) => {
|
|
490
735
|
if (count === 0)
|
|
491
736
|
return finishedControls();
|
|
492
737
|
const head = Playback.make();
|
|
493
738
|
let settledOne = constVoid;
|
|
494
|
-
const tracks = tracksOf(head, () => settledOne());
|
|
495
|
-
const made = controlsOf(tracks, head, watch, onComplete);
|
|
739
|
+
const tracks = tracksOf(head, (landedOne) => settledOne(landedOne));
|
|
740
|
+
const made = controlsOf(tracks, head, watch, onComplete, runtime);
|
|
496
741
|
settledOne = made.settledOne;
|
|
497
742
|
watch.started(made.controls);
|
|
498
|
-
|
|
743
|
+
// A run that refuses the call (a Batch part's `delay` that throws, at its first play) stops it, so its
|
|
744
|
+
// scope hears it end, and the throw goes on to the call (#979, row 20).
|
|
745
|
+
try {
|
|
746
|
+
Arr.forEach(tracks, (track) => track.run());
|
|
747
|
+
}
|
|
748
|
+
catch (defect) {
|
|
749
|
+
made.controls.stop();
|
|
750
|
+
throw defect;
|
|
751
|
+
}
|
|
499
752
|
return made.controls;
|
|
500
753
|
};
|
|
754
|
+
/**
|
|
755
|
+
* A track built as it first runs: a mixed call's plain Subject, whose keys are taken only once the Batch
|
|
756
|
+
* parts before it have run, a Batch part's `delay` among what they call. Stopped or cancelled before it
|
|
757
|
+
* runs, it has taken nothing.
|
|
758
|
+
*/
|
|
759
|
+
const builtAtRun = (build) => {
|
|
760
|
+
let built;
|
|
761
|
+
const track = () => {
|
|
762
|
+
if (Predicate.isUndefined(built))
|
|
763
|
+
built = build();
|
|
764
|
+
return built;
|
|
765
|
+
};
|
|
766
|
+
return {
|
|
767
|
+
run: () => track().run(),
|
|
768
|
+
stop: () => UndefinedOr.map(built, (made) => made.stop()),
|
|
769
|
+
cancel: () => UndefinedOr.map(built, (made) => made.cancel()),
|
|
770
|
+
duration: () => track().duration(),
|
|
771
|
+
};
|
|
772
|
+
};
|
|
501
773
|
/**
|
|
502
774
|
* An **Animation scope**'s `animate` (#433), over an Environment's {@link Ports}: `animate(subject,
|
|
503
775
|
* target, options?)`, a Batch's `animate(batch, target, options?)` and `animate(sequence, options?)`,
|
|
@@ -505,6 +777,13 @@ const started = (watch, count, onComplete, tracksOf) => {
|
|
|
505
777
|
* (the DOM's selectors are looked up inside it); each animation is told to `watch` as it starts and
|
|
506
778
|
* ends. Every Subject's legs start in the call, on the loop by the end of its task. An Environment
|
|
507
779
|
* types its own overloads over it.
|
|
780
|
+
*
|
|
781
|
+
* A key a target or its Transition end names that a Subject can't take (its Environment's own value
|
|
782
|
+
* read throws: a key it lacks, say) is an error at the call, naming it, and so is a `delay` function that
|
|
783
|
+
* throws. The call then takes nothing from any of its Subjects: an animation it would have taken a key
|
|
784
|
+
* from runs on.
|
|
785
|
+
* A Transition end's key a Subject can no longer set when it lands is reported, left as it is, and the
|
|
786
|
+
* rest of its end set: the call lands.
|
|
508
787
|
*/
|
|
509
788
|
export const make = (env, ports, scope, watch) => (first, second, third) => {
|
|
510
789
|
if (isSequence(first))
|
|
@@ -513,7 +792,7 @@ export const make = (env, ports, scope, watch) => (first, second, third) => {
|
|
|
513
792
|
const batch = ports.batches.entryOf(first);
|
|
514
793
|
if (Predicate.isNotUndefined(batch)) {
|
|
515
794
|
const members = batch.binding.namedOf(batch);
|
|
516
|
-
return started(watch, 1, UndefinedOr.map(third, (given) => given.onComplete), (head, settled) => [
|
|
795
|
+
return started(env.runtime, watch, 1, UndefinedOr.map(third, (given) => given.onComplete), (head, settled) => [
|
|
517
796
|
batchTrackOf(env, batch.binding, second, members, third, head, settled),
|
|
518
797
|
]);
|
|
519
798
|
}
|
|
@@ -523,14 +802,29 @@ export const make = (env, ports, scope, watch) => (first, second, third) => {
|
|
|
523
802
|
// No member's Subject among them: each Subject's track, building no parts (bench:solid --batch's
|
|
524
803
|
// per-element page, a call per element: 8.2 -> 8.5 ms at 1,000 with the parts built for every call; #665).
|
|
525
804
|
if (Bool.not(ports.batches.hasMembers(subjects))) {
|
|
526
|
-
return started(watch, subjects.length, onComplete, (head, settled) =>
|
|
805
|
+
return started(env.runtime, watch, subjects.length, onComplete, (head, settled) => {
|
|
806
|
+
// One Subject: readied, then its track, which takes its keys once they're all read.
|
|
807
|
+
if (subjects.length === 1)
|
|
808
|
+
return [trackOf(env, readiedOf(env, ports.subjects, subjects[0], target), transitionFor(third, 0, 1), head, settled)];
|
|
809
|
+
// Every Subject readied, and its transition worked out (a `delay(i, n)` called), before any track takes a key (#973; #979, row 20).
|
|
810
|
+
const readied = Arr.map(subjects, (subject) => readiedOf(env, ports.subjects, subject, target));
|
|
811
|
+
const transitions = Arr.map(subjects, (_, index) => transitionFor(third, index, subjects.length));
|
|
812
|
+
return Arr.zipWith(readied, transitions, (each, transition) => trackOf(env, each, transition, head, settled));
|
|
813
|
+
});
|
|
527
814
|
}
|
|
528
815
|
// 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).
|
|
529
816
|
const parts = ports.batches.callPartsOf(subjects, target);
|
|
530
|
-
return started(watch, parts.members.length + parts.subjects.length, onComplete, (head, settled) =>
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
817
|
+
return started(env.runtime, watch, parts.members.length + parts.subjects.length, onComplete, (head, settled) => {
|
|
818
|
+
// A Batch's track takes nothing until it runs; every other Subject readied, and its transition worked
|
|
819
|
+
// out, before any track is built (#973). The Batch parts run first, and each other Subject's track is
|
|
820
|
+
// built as it runs, so a Batch part's `delay` that throws takes nothing either (#979, row 20).
|
|
821
|
+
const readied = Arr.map(parts.subjects, (part) => readiedOf(env, ports.subjects, part.subject, part.target));
|
|
822
|
+
const transitions = Arr.map(parts.subjects, (part) => transitionFor(third, part.index, subjects.length));
|
|
823
|
+
return [
|
|
824
|
+
...Arr.map(parts.members, (part) => batchTrackOf(env, part.binding, part.target, part.members, third, head, settled)),
|
|
825
|
+
...Arr.zipWith(readied, transitions, (each, transition) => builtAtRun(() => trackOf(env, each, transition, head, settled))),
|
|
826
|
+
];
|
|
827
|
+
});
|
|
534
828
|
};
|
|
535
829
|
// --- Sequences (#433's PR 2) ------------------------------------------------------------------
|
|
536
830
|
/** 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). */
|
|
@@ -543,6 +837,8 @@ const VALUE = "value";
|
|
|
543
837
|
const ZERO_TO_ONE = [0, 1];
|
|
544
838
|
/** No fields. */
|
|
545
839
|
const NO_FIELDS = {};
|
|
840
|
+
/** What a function Segment's callback, or its run, failing is reported as. */
|
|
841
|
+
const SEGMENT_FAILED = "wardic.animate: a function Segment failed";
|
|
546
842
|
/**
|
|
547
843
|
* What a Segment's transition doesn't take from the sequence's `defaultTransition` (Motion's): its
|
|
548
844
|
* delay, times and repeat, which are each Segment's own, and a value's own transitions.
|
|
@@ -582,8 +878,10 @@ const segmentTransitionOf = (options, key, defaults) => {
|
|
|
582
878
|
});
|
|
583
879
|
return Bool.match(Predicate.isUndefined(delay), { onTrue: () => run, onFalse: () => ({ ...run, delay }) });
|
|
584
880
|
};
|
|
881
|
+
/** Whether a function Segment's second part is its value: a number, a string or a list of stops. Anything else is its options. */
|
|
882
|
+
const isFunctionSegmentValue = /*#__PURE__*/ Predicate.or(/*#__PURE__*/ Predicate.or(Predicate.isNumber, Predicate.isString), Arr.isArray);
|
|
585
883
|
/** Whether a Segment's value is one: a number, a string, `null` or Keyframes. */
|
|
586
|
-
const isSegmentValue = /*#__PURE__*/ Predicate.or(
|
|
884
|
+
const isSegmentValue = /*#__PURE__*/ Predicate.or(isFunctionSegmentValue, Predicate.isNull);
|
|
587
885
|
/** A Segment's values: those that are a value, `null` or Keyframes. */
|
|
588
886
|
const segmentValuesOf = (target) => Rec.filter(target, isSegmentValue);
|
|
589
887
|
/** Each of `values`' keys' transition in a Segment. */
|
|
@@ -632,9 +930,12 @@ const stepsOf = (ports, sequence, scope, defaults) => {
|
|
|
632
930
|
}
|
|
633
931
|
if (Predicate.isFunction(parts[0])) {
|
|
634
932
|
const call = parts[0];
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
const options = Bool.match(
|
|
933
|
+
// #975 (ADR-0061, *Amendment (#975)*): two parts are a value and no options when the second is one,
|
|
934
|
+
// as Motion's `[value, keyframes]`; read as options, a number was dropped, and an array's `at` threw.
|
|
935
|
+
const [given, options] = Bool.match(Bool.or(parts.length === 3, isFunctionSegmentValue(parts[1])), {
|
|
936
|
+
onTrue: () => [parts[1], parts[2]],
|
|
937
|
+
onFalse: () => [ZERO_TO_ONE, parts[1]],
|
|
938
|
+
});
|
|
638
939
|
const target = { [VALUE]: given };
|
|
639
940
|
return { subjects: [{ call }], target, transitions: segmentTransitionsOf(target, options, defaults), at: atOf(options) };
|
|
640
941
|
}
|
|
@@ -663,7 +964,9 @@ export const segmentAnimates = (ports, segment, scope) => {
|
|
|
663
964
|
/**
|
|
664
965
|
* A function Segment's value animated (#433): its stops, a first `null` 0, through the
|
|
665
966
|
* Interpolators on its tween over the sequence, each frame told to its callback. Cancelled, the
|
|
666
|
-
* callback hears its first stop again, as Motion's motion value is set back.
|
|
967
|
+
* callback hears its first stop again, as Motion's motion value is set back. A callback that throws is
|
|
968
|
+
* reported, once a run of throws, and told the next frame's value all the same; one that throws on a
|
|
969
|
+
* cancel, each time, the call's cancel going on.
|
|
667
970
|
*/
|
|
668
971
|
const callbackTrackOf = (env, callback, animation, head, settled) => {
|
|
669
972
|
const stops = RetargetLegs.filledStops(UndefinedOr.getOrThrow(animation.keyframes[VALUE]), 0);
|
|
@@ -674,6 +977,8 @@ const callbackTrackOf = (env, callback, animation, head, settled) => {
|
|
|
674
977
|
onFalse: () => Machine.keyframesValues({ [VALUE]: stops }, options),
|
|
675
978
|
});
|
|
676
979
|
let fiber;
|
|
980
|
+
// Its callback threw, reported, and hasn't returned since (#979, row 18).
|
|
981
|
+
let failing = false;
|
|
677
982
|
const end = () => {
|
|
678
983
|
if (Predicate.isUndefined(fiber))
|
|
679
984
|
return;
|
|
@@ -684,13 +989,27 @@ const callbackTrackOf = (env, callback, animation, head, settled) => {
|
|
|
684
989
|
running.interruptUnsafe();
|
|
685
990
|
};
|
|
686
991
|
const landed = (exit) => Exit.match(exit, {
|
|
687
|
-
onSuccess: () => Effect.sync(settled),
|
|
688
|
-
onFailure: (cause) => Bool.match(Cause.hasInterruptsOnly(cause), { onTrue: () => Effect.void, onFalse: () => Report.failure(
|
|
992
|
+
onSuccess: () => Effect.sync(() => settled(true)),
|
|
993
|
+
onFailure: (cause) => Bool.match(Cause.hasInterruptsOnly(cause), { onTrue: () => Effect.void, onFalse: () => Report.failure(SEGMENT_FAILED, cause) }),
|
|
689
994
|
});
|
|
690
995
|
const run = () => {
|
|
691
996
|
end();
|
|
997
|
+
// A run of its own: a throw in it is reported, whatever the last run's last call did.
|
|
998
|
+
failing = false;
|
|
692
999
|
fiber = env.runtime.runFork(machine.pipe(Effect.map(Playback.drive(head)), Effect.flatMap(Machine.run((frame) => {
|
|
693
|
-
|
|
1000
|
+
const value = UndefinedOr.getOrThrow(frame.value[VALUE]);
|
|
1001
|
+
// Its callback's throw is its own: told again next frame, its Segment landing as its stops do (ADR-0074).
|
|
1002
|
+
try {
|
|
1003
|
+
callback.call(value);
|
|
1004
|
+
if (failing)
|
|
1005
|
+
failing = false;
|
|
1006
|
+
}
|
|
1007
|
+
catch (defect) {
|
|
1008
|
+
if (!failing) {
|
|
1009
|
+
failing = true;
|
|
1010
|
+
env.runtime.runFork(Report.failure(SEGMENT_FAILED, Cause.die(defect)));
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
694
1013
|
return undefined;
|
|
695
1014
|
})), Effect.onExit(landed)));
|
|
696
1015
|
};
|
|
@@ -699,7 +1018,14 @@ const callbackTrackOf = (env, callback, animation, head, settled) => {
|
|
|
699
1018
|
stop: end,
|
|
700
1019
|
cancel: () => {
|
|
701
1020
|
end();
|
|
702
|
-
|
|
1021
|
+
const first = UndefinedOr.getOrThrow(stops[0]);
|
|
1022
|
+
// Told its first stop once its run has ended: a throw there is reported, and the call's cancel goes on (#979, row 19).
|
|
1023
|
+
try {
|
|
1024
|
+
callback.call(first);
|
|
1025
|
+
}
|
|
1026
|
+
catch (defect) {
|
|
1027
|
+
env.runtime.runFork(Report.failure("wardic.animate: a function Segment's cancel failed", Cause.die(defect)));
|
|
1028
|
+
}
|
|
703
1029
|
},
|
|
704
1030
|
duration: () => Machine.durationOf(env.runtime.runSync(machine)),
|
|
705
1031
|
};
|
|
@@ -719,14 +1045,24 @@ const sequenceOf = (env, ports, scope, watch, sequence, options) => {
|
|
|
719
1045
|
const compiled = Arr.fromIterable(Sequence.compile(stepsOf(ports, sequence, scope, defaults), whole));
|
|
720
1046
|
// Each Batch's members as one track, their other keys their Subjects' (#665, Q40).
|
|
721
1047
|
const parts = ports.batches.sequencePartsOf(compiled);
|
|
722
|
-
return started(watch, compiled.length, UndefinedOr.map(options, (given) => given.onComplete), (head, settled) =>
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
1048
|
+
return started(env.runtime, watch, compiled.length, UndefinedOr.map(options, (given) => given.onComplete), (head, settled) => {
|
|
1049
|
+
// Every Segment's Subject readied before any track takes a key, a later one's refusal taking nothing (#973).
|
|
1050
|
+
const readied = Arr.map(parts.others, ([subject, animation]) => segmentReadiedOf(env, ports.subjects, subject, animation));
|
|
1051
|
+
return [
|
|
1052
|
+
...Arr.map(parts.others, ([subject, animation], i) => {
|
|
1053
|
+
if (isCallback(subject))
|
|
1054
|
+
return callbackTrackOf(env, subject, animation, head, settled);
|
|
1055
|
+
return trackOf(env, UndefinedOr.getOrThrow(readied[i]), animation.transition, head, settled);
|
|
1056
|
+
}),
|
|
1057
|
+
...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) })),
|
|
1058
|
+
];
|
|
1059
|
+
});
|
|
1060
|
+
};
|
|
1061
|
+
/** A sequence's Subject readied (`readiedOf`) for its compiled animation: none for a function Segment's callback, which has no keys. */
|
|
1062
|
+
const segmentReadiedOf = (env, subjects, subject, animation) => {
|
|
1063
|
+
if (isCallback(subject))
|
|
1064
|
+
return undefined;
|
|
1065
|
+
return readiedOf(env, subjects, subject, animation.keyframes);
|
|
730
1066
|
};
|
|
731
1067
|
/** `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). */
|
|
732
1068
|
export const alsoTold = (watch, also) => UndefinedOr.match(also, {
|