@wardic/core 1.3.2 → 1.4.1
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 +15 -5
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +218 -20
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +7 -7
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +17 -16
- 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 +5 -4
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +37 -14
- 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 +1 -1
- package/dist/InputFeed.js +2 -2
- 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 +7 -6
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +45 -14
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +7 -4
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +146 -45
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +6 -1
- 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 +4 -3
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +49 -20
- 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 +1 -1
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +102 -81
- package/dist/internal/frameLoop.js.map +1 -1
- 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 +13 -2
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +16 -1
- 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 +37 -38
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +39 -36
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +5 -5
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/BatchCalls.d.ts +2 -2
- package/dist/unstable/BatchCalls.js +5 -5
- package/dist/unstable/Config.d.ts +19 -19
- package/dist/unstable/Config.d.ts.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 +53 -51
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +56 -49
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +2 -2
- package/dist/unstable/FrameEffects.js +2 -2
- package/dist/unstable/FrameTime.d.ts +1 -1
- package/dist/unstable/FrameTime.js +1 -1
- package/dist/unstable/Imperative.d.ts +29 -9
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +79 -47
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/OwnValues.js +1 -1
- package/dist/unstable/PresenceRecord.d.ts +26 -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 +1 -1
- package/dist/unstable/Report.js +1 -1
- package/dist/unstable/RetargetLegs.d.ts +1 -1
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +9 -8
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +81 -72
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +152 -150
- 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 +7 -7
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +11 -11
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +36 -36
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +33 -33
- 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 +236 -22
- package/src/Clock.ts +18 -17
- package/src/DefaultTransition.ts +5 -3
- package/src/Drag.ts +32 -14
- package/src/DragActivity.ts +3 -3
- package/src/DragRecognizer.ts +41 -16
- package/src/Easing.ts +1 -1
- package/src/Frame.ts +5 -3
- package/src/InputFeed.ts +2 -2
- package/src/InputSource.ts +5 -5
- package/src/Interpolator.ts +3 -3
- package/src/InterpolatorRegistry.ts +22 -13
- package/src/LiveValue.ts +47 -17
- package/src/Machine.ts +199 -61
- package/src/Playback.ts +5 -1
- package/src/Projection.ts +9 -9
- package/src/Recognizer.ts +69 -38
- 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 +103 -87
- package/src/internal/lerpsNumbers.ts +53 -0
- package/src/internal/options.ts +10 -10
- package/src/internal/stepper.ts +20 -2
- package/src/internal/tracing.ts +1 -1
- package/src/unstable/AnimationControls.ts +59 -56
- package/src/unstable/AppearHandoff.ts +6 -6
- package/src/unstable/BatchCalls.ts +5 -5
- package/src/unstable/Config.ts +19 -19
- package/src/unstable/FirstSteps.ts +26 -0
- package/src/unstable/FlushGate.ts +92 -82
- package/src/unstable/FrameEffects.ts +2 -2
- package/src/unstable/FrameTime.ts +1 -1
- package/src/unstable/Imperative.ts +126 -56
- package/src/unstable/OwnValues.ts +1 -1
- package/src/unstable/PresenceRecord.ts +29 -29
- package/src/unstable/Projector.ts +45 -0
- package/src/unstable/Report.ts +1 -1
- package/src/unstable/RetargetLegs.ts +10 -9
- package/src/unstable/Spine.ts +190 -188
- 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 +13 -13
- package/src/unstable/VariantTree.ts +42 -42
- package/src/unstable/WardicConfigValue.ts +13 -13
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* An Environment says what its Subjects are and how a plain one starts ({@link Subjects}), and what
|
|
5
5
|
* its Batches are ({@link Batches}); each binding's `createAnimate()` builds on it.
|
|
6
6
|
*
|
|
7
|
-
* - **A
|
|
8
|
-
* call takes the keys it animates, which stay where it leaves them until the
|
|
7
|
+
* - **A Ward's Subject** animates through its own spine, registered here while it's mounted: the
|
|
8
|
+
* call takes the keys it animates, which stay where it leaves them until the Subject's own target
|
|
9
9
|
* for them changes (Motion's latest-wins).
|
|
10
10
|
* - **A plain Subject** animates through a spine of its own (#433's Q4), with no config, presence or
|
|
11
11
|
* layout node: it starts from the Subject's Own value (ADR-0022) and keeps its values for the next
|
|
@@ -58,21 +58,21 @@ import * as Predicate from "effect/Predicate"
|
|
|
58
58
|
import * as Rec from "effect/Record"
|
|
59
59
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
60
60
|
|
|
61
|
-
/** What an Imperative animation animates a
|
|
62
|
-
type Animatable = Pick<Spine.
|
|
61
|
+
/** What an Imperative animation animates a Ward's Subject through: what its spine hands over (`host`). */
|
|
62
|
+
type Animatable = Pick<Spine.SubjectSpine, "host">
|
|
63
63
|
|
|
64
|
-
/** Each mounted
|
|
65
|
-
// Module state (#460, Q7): each
|
|
66
|
-
const
|
|
64
|
+
/** Each mounted Ward's Subject's spine (Motion's `visualElementStore`), by its Subject. */
|
|
65
|
+
// Module state (#460, Q7): each Ward's Subject's animatable, held weakly by the Subject.
|
|
66
|
+
const wardedSubjects = new WeakMap<object, Animatable>()
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
-
* Register a mounted
|
|
69
|
+
* Register a mounted Ward's Subject's spine for the Imperative animations of its Subject (#433): until
|
|
70
70
|
* the returned function, which its unmount calls.
|
|
71
71
|
*/
|
|
72
72
|
export const registerAnimatable = (subject: object, spine: Animatable): (() => void) => {
|
|
73
|
-
|
|
73
|
+
wardedSubjects.set(subject, spine)
|
|
74
74
|
return () => {
|
|
75
|
-
if (
|
|
75
|
+
if (wardedSubjects.get(subject) === spine) wardedSubjects.delete(subject)
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -98,13 +98,13 @@ export interface AnimateEnv {
|
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
100
|
* An Environment's Subjects, for `animate`: what its first argument names, and where a plain one
|
|
101
|
-
* starts.
|
|
102
|
-
* objects.
|
|
101
|
+
* starts. `@wardic/dom`'s are its own kind, the strings it looks up in the scope, and lists of them; a scene's,
|
|
102
|
+
* its objects.
|
|
103
103
|
*/
|
|
104
104
|
export interface Subjects<S extends object> {
|
|
105
105
|
/** The Subjects `given` names, inside `scope` (a binding's scope, or `undefined`): none when it names none. */
|
|
106
106
|
readonly resolve: (given: unknown, scope: unknown) => ReadonlyArray<S>
|
|
107
|
-
/** A plain Subject's Base-value links (ADR-0022): its Own values, and
|
|
107
|
+
/** A plain Subject's Base-value links (ADR-0022): its Own values, and `@wardic/dom`'s Starting style. */
|
|
108
108
|
readonly startLinksOf: (subject: S) => Spine.StartLinks
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -209,7 +209,7 @@ export interface Ports<S extends object> {
|
|
|
209
209
|
|
|
210
210
|
/** A plain Subject's spine (#433's Q4), its values, and how many of its animations run, which keep it in the gate. */
|
|
211
211
|
interface Plain {
|
|
212
|
-
readonly spine: Spine.
|
|
212
|
+
readonly spine: Spine.SubjectSpine
|
|
213
213
|
readonly snapshot: Spine.Snapshot
|
|
214
214
|
readonly id: string
|
|
215
215
|
running: number
|
|
@@ -238,11 +238,11 @@ const plainOf = <S extends object>(env: AnimateEnv, subjects: Subjects<S>, subje
|
|
|
238
238
|
if (Predicate.isNotUndefined(known)) return known
|
|
239
239
|
const id = `wardic-animate-${plainIds++}`
|
|
240
240
|
const snapshot: Spine.Snapshot = Spine.emptySnapshotOf({})
|
|
241
|
-
const spine = Spine.
|
|
241
|
+
const spine = Spine.makeSubjectSpine({
|
|
242
242
|
runtime: env.runtime,
|
|
243
243
|
gate: env.gate,
|
|
244
244
|
id,
|
|
245
|
-
|
|
245
|
+
subject,
|
|
246
246
|
tag: undefined,
|
|
247
247
|
config: () => NO_CONFIG,
|
|
248
248
|
parent: undefined,
|
|
@@ -273,7 +273,7 @@ const plainOf = <S extends object>(env: AnimateEnv, subjects: Subjects<S>, subje
|
|
|
273
273
|
|
|
274
274
|
/**
|
|
275
275
|
* `transition` with `skipAnimations` when its scope's animations are skipped (#468, Motion's
|
|
276
|
-
* `useAnimate`, which hands its config's to each animation): a
|
|
276
|
+
* `useAnimate`, which hands its config's to each animation): a Ward's Subject's own config can skip it
|
|
277
277
|
* too, and a plain Subject has none.
|
|
278
278
|
*/
|
|
279
279
|
const skippedIn = (env: AnimateEnv, transition: Config.WardicTransition | undefined): Config.WardicTransition | undefined => {
|
|
@@ -352,7 +352,7 @@ const endFree = (owner: Spine.Running | undefined): boolean => {
|
|
|
352
352
|
// #746 (ADR-0067, *Amendment (#746)*, decision 10): here, not in the spine, so an app that never animates
|
|
353
353
|
// imperatively ships none of it; the spine hands over what it takes (`SpineHost`).
|
|
354
354
|
const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target, given: Config.WardicTransition | undefined, head: Playback.Playhead, hooks: Spine.ImperativeHooks): Spine.ImperativeTrack => {
|
|
355
|
-
const { snapshot, owners, keepTheRest,
|
|
355
|
+
const { snapshot, owners, keepTheRest, subject, positionalKeys, defaultTransition, unitScale, readVelocity, gate, forget, endLeg, live, own, legProgram, legEnded, turnBack, id, recordFrame, runtime, subjectRules, measuredPairs, variableValues } = host
|
|
356
356
|
/** A leg of an Imperative animation, forked as a Retarget's are; it lands on its track. */
|
|
357
357
|
// Data-first: a pipe's curried forms are two closures more for every leg (#618, H1).
|
|
358
358
|
const runImperative = (running: Spine.Running, program: Effect.Effect<unknown, never, WardicServices.WardicServices>): void => {
|
|
@@ -391,7 +391,7 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
|
|
|
391
391
|
const reduce = host.reducedMotion()
|
|
392
392
|
const skipped = host.skipAnimations()
|
|
393
393
|
let measured: RetargetLegs.MeasuredPairs | undefined
|
|
394
|
-
if (Bool.and(Bool.not(Bool.or(reduce, skipped)), Predicate.isNotUndefined(measuring))) measured = Spine.measuredOf(measuredPairs,
|
|
394
|
+
if (Bool.and(Bool.not(Bool.or(reduce, skipped)), Predicate.isNotUndefined(measuring))) measured = Spine.measuredOf(measuredPairs, subject, UndefinedOr.getOrThrow(measuring), from, to, snapshot.values, stops, runtime, id)
|
|
395
395
|
// Built once: a seek or a replay runs the same legs, from the same start, with the same velocities.
|
|
396
396
|
const built = RetargetLegs.legsOf(from, to, given, reduce, skipped, positionalKeys, defaultTransition, readVelocity, undefined, stops, measured, snapshot.values, rests, unitScale)
|
|
397
397
|
const variables = Spine.holdsVariable(variableValues, from, to, stops)
|
|
@@ -449,7 +449,7 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
|
|
|
449
449
|
}
|
|
450
450
|
/**
|
|
451
451
|
* Its Transition end's keys put back as they were before it was set (Q5): at a cancel, a seek or a
|
|
452
|
-
* replay, each a key no leg has drawn since, a later call's or the
|
|
452
|
+
* replay, each a key no leg has drawn since, a later call's or the Subject's own. The next landing
|
|
453
453
|
* sets them again.
|
|
454
454
|
*/
|
|
455
455
|
const putBack = (): void => {
|
|
@@ -463,10 +463,10 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
|
|
|
463
463
|
// frame, its keys landed from its start, so a take before then takes nothing in flight, as Motion's
|
|
464
464
|
// skipped value makes no animation. Its machine read only for a leg that lost a key.
|
|
465
465
|
const snaps = (i: number): boolean => Machine.durationOf(machineOf(UndefinedOr.getOrThrow(built[i]))) === 0
|
|
466
|
-
// A leg the
|
|
466
|
+
// A leg the Subject's own Retarget carried on, toward the same target, as its own (Q7): the call has lost it.
|
|
467
467
|
let carried = false
|
|
468
468
|
// Taken (#896's Q3, #951): a key it animates taken from its leg mid-flight, by a later animation or the
|
|
469
|
-
//
|
|
469
|
+
// Subject's own target, or a leg carried off whole. A leg that lost one has fewer than it started
|
|
470
470
|
// with; one taken after its leg landed doesn't count, as Motion's, nor one that snaps.
|
|
471
471
|
const taken = (): boolean => {
|
|
472
472
|
if (carried) return true
|
|
@@ -509,7 +509,7 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
|
|
|
509
509
|
}
|
|
510
510
|
/**
|
|
511
511
|
* A leg of this run ended **Superseded** (#951), told at its end, as it settles nothing of this
|
|
512
|
-
* track's: carried on by the
|
|
512
|
+
* track's: carried on by the Subject's own Retarget as its own, its landing the Retarget's now (Q7);
|
|
513
513
|
* or with every key taken, a count of 0 (only a take lowers it), which `taken` reads. Either counts
|
|
514
514
|
* toward the track's landing, which finds it taken.
|
|
515
515
|
*/
|
|
@@ -534,7 +534,7 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
|
|
|
534
534
|
if (head.speed < 0) return false
|
|
535
535
|
return head.time >= duration()
|
|
536
536
|
}
|
|
537
|
-
// A key another leg draws: a later animation's, or the
|
|
537
|
+
// A key another leg draws: a later animation's, or the Subject's own.
|
|
538
538
|
const drawnByAnother = (key: string): boolean => Predicate.isNotUndefined(owners.get(key))
|
|
539
539
|
const run = (): void => {
|
|
540
540
|
runs++
|
|
@@ -568,7 +568,7 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
|
|
|
568
568
|
const duration = (): number =>
|
|
569
569
|
Arr.reduce(built, 0, (longest, leg) => Math.max(longest, Machine.durationOf(machineOf(leg))))
|
|
570
570
|
const machineOf = (leg: RetargetLegs.Leg): Machine.Machine<Frame.Frame<unknown>> => {
|
|
571
|
-
if (leg._tag === "Blend") return runtime.runSync(Effect.suspend(leg.machine).pipe(InterpolatorRegistry.withKeyRules(
|
|
571
|
+
if (leg._tag === "Blend") return runtime.runSync(Effect.suspend(leg.machine).pipe(InterpolatorRegistry.withKeyRules(subjectRules)))
|
|
572
572
|
return leg.machine() as Machine.Machine<Frame.Frame<unknown>>
|
|
573
573
|
}
|
|
574
574
|
const stop = (): void => {
|
|
@@ -581,7 +581,7 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
|
|
|
581
581
|
|
|
582
582
|
/**
|
|
583
583
|
* A call's transition on its target's own (#896, ADR-0061 *Amendment (#896)*, Q1): the options' fields
|
|
584
|
-
* laid over the target's, shallowly, as `inherit: true` lays a target's over its
|
|
584
|
+
* laid over the target's, shallowly, as `inherit: true` lays a target's over its Subject's. Motion's
|
|
585
585
|
* `animate` reads the options alone.
|
|
586
586
|
*/
|
|
587
587
|
// Its own handed back as it is with no options, so the legs' decode cache (#66) holds for it. Its
|
|
@@ -597,7 +597,7 @@ interface Readied<S extends object> {
|
|
|
597
597
|
readonly subject: S
|
|
598
598
|
readonly target: VariantTarget.Target
|
|
599
599
|
readonly host: Spine.SpineHost
|
|
600
|
-
/** Its plain spine: `undefined` for a
|
|
600
|
+
/** Its plain spine: `undefined` for a Ward's Subject's, which runs through the Subject's own. */
|
|
601
601
|
readonly plain: Plain | undefined
|
|
602
602
|
}
|
|
603
603
|
|
|
@@ -614,7 +614,7 @@ const readiedOf = <S extends object>(env: AnimateEnv, subjects: Subjects<S>, sub
|
|
|
614
614
|
// A function given as the target (past the types) that throws is an error at the call, as a key it
|
|
615
615
|
// can't take is: the call takes nothing (#979; ADR-0074 keeps a refusal at the call a throw).
|
|
616
616
|
if (Option.isSome(target.failure)) throw target.failure.value.defect
|
|
617
|
-
const own =
|
|
617
|
+
const own = wardedSubjects.get(subject)
|
|
618
618
|
if (Predicate.isNotUndefined(own)) return readOwnValues({ subject, target, host: own.host(), plain: undefined })
|
|
619
619
|
const plain = plainOf(env, subjects, subject)
|
|
620
620
|
return readOwnValues({ subject, target, host: plain.spine.host(), plain })
|
|
@@ -635,7 +635,7 @@ const readOwnValues = <S extends object>(readied: Readied<S>): Readied<S> => {
|
|
|
635
635
|
}
|
|
636
636
|
|
|
637
637
|
/**
|
|
638
|
-
* A readied Subject's animation (`readiedOf`): through its spine when it's a
|
|
638
|
+
* A readied Subject's animation (`readiedOf`): through its spine when it's a Ward's Subject's, else through
|
|
639
639
|
* its plain spine, in the gate while any of its animations runs.
|
|
640
640
|
*/
|
|
641
641
|
const trackOf = <S extends object>(env: AnimateEnv, readied: Readied<S>, given: Config.WardicTransition | undefined, head: Playback.Playhead, settled: (landed: boolean) => void): Spine.ImperativeTrack => {
|
|
@@ -761,6 +761,12 @@ const skipsBatchCall = (env: AnimateEnv, options: WardicAnimateOptions | undefin
|
|
|
761
761
|
/** Where an animation is: `"idle"`, `"running"`, `"paused"` or `"finished"`. Motion's `AnimationPlayState`. */
|
|
762
762
|
export type WardicPlayState = "idle" | "running" | "paused" | "finished"
|
|
763
763
|
|
|
764
|
+
/** How an animation ended: whether it landed. */
|
|
765
|
+
export interface WardicAnimationEnd {
|
|
766
|
+
/** It arrived: it landed at its end, or `complete()` took it there. False when it was stopped, cancelled or taken over. */
|
|
767
|
+
readonly landed: boolean
|
|
768
|
+
}
|
|
769
|
+
|
|
764
770
|
/**
|
|
765
771
|
* What `animate` returns: an animation's controls, and a promise of its landing, so it can be awaited.
|
|
766
772
|
* Motion's `AnimationPlaybackControls`.
|
|
@@ -783,6 +789,22 @@ export interface WardicPlaybackControls extends PromiseLike<void> {
|
|
|
783
789
|
* animation takes one of its keys, as Motion's.
|
|
784
790
|
*/
|
|
785
791
|
readonly finished: Promise<void>
|
|
792
|
+
/**
|
|
793
|
+
* Resolves once it ends, however it ends, with whether it landed: `landed` at its landing or
|
|
794
|
+
* `complete()`, and not at `stop()`, `cancel()`, or once a later animation takes one of its keys.
|
|
795
|
+
* It never rejects. Each time it plays has its own: played again, sought or completed after it ended,
|
|
796
|
+
* it gives a new one.
|
|
797
|
+
*
|
|
798
|
+
* @example
|
|
799
|
+
* setBusy(true)
|
|
800
|
+
* try {
|
|
801
|
+
* await controls.ended
|
|
802
|
+
* } finally {
|
|
803
|
+
* setBusy(false)
|
|
804
|
+
* }
|
|
805
|
+
*/
|
|
806
|
+
// #955 (ADR-0061, *Amendment (#955)*): Wardic's own, beside Motion's `finished`.
|
|
807
|
+
readonly ended: Promise<WardicAnimationEnd>
|
|
786
808
|
/** Play it on: from where it's paused, or again from its start once it's finished or cancelled. Not after `stop()`. */
|
|
787
809
|
readonly play: () => void
|
|
788
810
|
/** Hold it where it is. */
|
|
@@ -802,6 +824,57 @@ export interface AnimationWatch {
|
|
|
802
824
|
readonly ended: (controls: WardicPlaybackControls, landed: boolean) => void
|
|
803
825
|
}
|
|
804
826
|
|
|
827
|
+
/**
|
|
828
|
+
* A run's outcome as a promise: made at its first read, resolved once, and renewed for the next run. A run
|
|
829
|
+
* is what the scope's watch hears of an animation, from a start to its end.
|
|
830
|
+
*/
|
|
831
|
+
interface RunPromise<A> {
|
|
832
|
+
/** This run's promise, made as it's first read: resolved already when the run has its outcome. */
|
|
833
|
+
readonly get: () => Promise<A>
|
|
834
|
+
/** The run's outcome, `value`, read yet or not. */
|
|
835
|
+
readonly resolve: (value: A) => void
|
|
836
|
+
/** A new run: the next read makes a new promise. */
|
|
837
|
+
readonly renew: () => void
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/** A promise of each run's outcome, nothing made until it's read (#955: `finished` and `ended`). */
|
|
841
|
+
const runPromiseOf = <A>(): RunPromise<A> => {
|
|
842
|
+
let promise: Promise<A> | undefined
|
|
843
|
+
let settle: ((value: A) => void) | undefined
|
|
844
|
+
let outcome: Option.Option<A> = Option.none()
|
|
845
|
+
return {
|
|
846
|
+
get: () => {
|
|
847
|
+
if (Predicate.isNotUndefined(promise)) return promise
|
|
848
|
+
promise = Option.match(outcome, {
|
|
849
|
+
onSome: (value) => Promise.resolve(value),
|
|
850
|
+
onNone: () =>
|
|
851
|
+
new Promise<A>((settleWith) => {
|
|
852
|
+
settle = settleWith
|
|
853
|
+
}),
|
|
854
|
+
})
|
|
855
|
+
return promise
|
|
856
|
+
},
|
|
857
|
+
resolve: (value) => {
|
|
858
|
+
outcome = Option.some(value)
|
|
859
|
+
if (Predicate.isNotUndefined(settle)) settle(value)
|
|
860
|
+
},
|
|
861
|
+
renew: () => {
|
|
862
|
+
promise = undefined
|
|
863
|
+
settle = undefined
|
|
864
|
+
outcome = Option.none()
|
|
865
|
+
},
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/** A run that landed, as `ended` gives it. */
|
|
870
|
+
const LANDED: WardicAnimationEnd = Object.freeze({ landed: true })
|
|
871
|
+
|
|
872
|
+
/** A run that ended without landing: stopped, cancelled or taken over. */
|
|
873
|
+
const NOT_LANDED: WardicAnimationEnd = Object.freeze({ landed: false })
|
|
874
|
+
|
|
875
|
+
/** How a run ended, as `ended` gives it. */
|
|
876
|
+
const endOf: (landed: boolean) => WardicAnimationEnd = /*#__PURE__*/ Bool.match({ onTrue: () => LANDED, onFalse: () => NOT_LANDED })
|
|
877
|
+
|
|
805
878
|
/** Playback controls over `tracks`, all run through `head`, started now: a throw from `onComplete` reported on `runtime`. */
|
|
806
879
|
const controlsOf = (
|
|
807
880
|
tracks: ReadonlyArray<Spine.ImperativeTrack>,
|
|
@@ -818,9 +891,9 @@ const controlsOf = (
|
|
|
818
891
|
let landed = 0
|
|
819
892
|
// Whether a Subject's part ended without landing, a key of it taken by a later animation (#951).
|
|
820
893
|
let anyTaken = false
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
894
|
+
const finished = runPromiseOf<void>()
|
|
895
|
+
// Each run's end, however it ended (#955): a run is what `watch` hears, from its start to its end.
|
|
896
|
+
const ended = runPromiseOf<WardicAnimationEnd>()
|
|
824
897
|
let duration: number | undefined
|
|
825
898
|
const durationNow = (): number => {
|
|
826
899
|
if (Predicate.isUndefined(duration)) duration = Arr.reduce(tracks, 0, (longest, track) => Math.max(longest, track.duration()))
|
|
@@ -831,20 +904,23 @@ const controlsOf = (
|
|
|
831
904
|
anyTaken = false
|
|
832
905
|
Arr.forEach(tracks, (track) => track.run())
|
|
833
906
|
}
|
|
834
|
-
const fresh = (): void => {
|
|
835
|
-
finished = undefined
|
|
836
|
-
resolve = undefined
|
|
837
|
-
isResolved = false
|
|
838
|
-
}
|
|
839
907
|
const end = (how: WardicPlayState, landedNow: boolean): void => {
|
|
840
908
|
const was = state
|
|
841
909
|
state = how
|
|
842
|
-
if (Bool.or(was === "running", was === "paused"))
|
|
910
|
+
if (Bool.or(was === "running", was === "paused")) {
|
|
911
|
+
ended.resolve(endOf(landedNow))
|
|
912
|
+
watch.ended(controls, landedNow)
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
// A new run, from an end: its own `ended`, and the watch told it started.
|
|
916
|
+
const newRun = (): void => {
|
|
917
|
+
ended.renew()
|
|
918
|
+
watch.started(controls)
|
|
843
919
|
}
|
|
844
920
|
const restart = (): void => {
|
|
845
921
|
const was = state
|
|
846
922
|
state = "running"
|
|
847
|
-
if (Bool.or(was === "finished", was === "idle"))
|
|
923
|
+
if (Bool.or(was === "finished", was === "idle")) newRun()
|
|
848
924
|
}
|
|
849
925
|
const controls: WardicPlaybackControls = {
|
|
850
926
|
get time() {
|
|
@@ -856,8 +932,8 @@ const controlsOf = (
|
|
|
856
932
|
if (state !== "running") {
|
|
857
933
|
Playback.pause(head)
|
|
858
934
|
if (Bool.or(state === "finished", state === "idle")) {
|
|
859
|
-
|
|
860
|
-
|
|
935
|
+
finished.renew()
|
|
936
|
+
newRun()
|
|
861
937
|
}
|
|
862
938
|
state = "paused"
|
|
863
939
|
}
|
|
@@ -876,16 +952,10 @@ const controlsOf = (
|
|
|
876
952
|
return state
|
|
877
953
|
},
|
|
878
954
|
get finished() {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
new Promise<void>((done) => {
|
|
884
|
-
resolve = done
|
|
885
|
-
}),
|
|
886
|
-
})
|
|
887
|
-
}
|
|
888
|
-
return finished
|
|
955
|
+
return finished.get()
|
|
956
|
+
},
|
|
957
|
+
get ended() {
|
|
958
|
+
return ended.get()
|
|
889
959
|
},
|
|
890
960
|
then: (onResolve, onReject) => controls.finished.then(onResolve, onReject),
|
|
891
961
|
play: () => {
|
|
@@ -897,7 +967,7 @@ const controlsOf = (
|
|
|
897
967
|
}
|
|
898
968
|
if (state === "running") return
|
|
899
969
|
// Again from its start: its end when it plays backwards.
|
|
900
|
-
|
|
970
|
+
finished.renew()
|
|
901
971
|
Playback.play(head)
|
|
902
972
|
Playback.seek(head, Bool.match(head.speed < 0, { onTrue: durationNow, onFalse: () => 0 }))
|
|
903
973
|
restart()
|
|
@@ -936,8 +1006,7 @@ const controlsOf = (
|
|
|
936
1006
|
stopped = true
|
|
937
1007
|
return end("idle", false)
|
|
938
1008
|
}
|
|
939
|
-
|
|
940
|
-
UndefinedOr.map(resolve, (done) => done())
|
|
1009
|
+
finished.resolve(undefined)
|
|
941
1010
|
// Finished before its onComplete runs, as Motion's `finish()`: a throw there leaves it finished, and
|
|
942
1011
|
// is reported each time it lands (#977; ADR-0074, *Amendment (#979, group A)*).
|
|
943
1012
|
end("finished", true)
|
|
@@ -961,6 +1030,7 @@ export const finishedControls = (): WardicPlaybackControls => {
|
|
|
961
1030
|
duration: 0,
|
|
962
1031
|
state: "finished",
|
|
963
1032
|
finished: done,
|
|
1033
|
+
ended: Promise.resolve(LANDED),
|
|
964
1034
|
then: (onResolve, onReject) => done.then(onResolve, onReject),
|
|
965
1035
|
play: constVoid,
|
|
966
1036
|
pause: constVoid,
|
|
@@ -1071,7 +1141,7 @@ const builtAtRun = (build: () => Spine.ImperativeTrack): Spine.ImperativeTrack =
|
|
|
1071
1141
|
* An **Animation scope**'s `animate` (#433), over an Environment's {@link Ports}: `animate(subject,
|
|
1072
1142
|
* target, options?)`, a Batch's `animate(batch, target, options?)` and `animate(sequence, options?)`,
|
|
1073
1143
|
* each returning its Playback controls. `scope()` is handed to the Environment's {@link Subjects.resolve}
|
|
1074
|
-
* (
|
|
1144
|
+
* (`@wardic/dom` looks its strings up inside it); each animation is told to `watch` as it starts and
|
|
1075
1145
|
* ends. Every Subject's legs start in the call, on the loop by the end of its task. An Environment
|
|
1076
1146
|
* types its own overloads over it.
|
|
1077
1147
|
*
|
|
@@ -1223,7 +1293,7 @@ const subjectsIn = <S extends object>(batches: Batches<S>, subjects: ReadonlyArr
|
|
|
1223
1293
|
|
|
1224
1294
|
/**
|
|
1225
1295
|
* A sequence's steps for core (#433): labels as they are; a Segment of Subjects' Subjects (a string
|
|
1226
|
-
* the Environment resolves,
|
|
1296
|
+
* the Environment resolves, looked up once a sequence, inside `scope`), values and each
|
|
1227
1297
|
* value's transition; a function Segment's own value, from 0 to 1 unless it gives its stops.
|
|
1228
1298
|
*/
|
|
1229
1299
|
const stepsOf = <S extends object>(ports: Ports<S>, sequence: ReadonlyArray<unknown>, scope: unknown, defaults: Config.WardicTransition | undefined): ReadonlyArray<Sequence.Step<S | Callback | BatchMember>> => {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// Unstable: ADR-0071, decision 5. #672 (PR2-Q1, PR2-Q2; ADR-0071's *Amendment (#672)*): a port, so the
|
|
14
14
|
// spine and `live-style` read their Environment's values through it, not through dom. A provider
|
|
15
15
|
// resolves it once into its record when its Environment gives one, else its DOM binding gives the
|
|
16
|
-
// DOM's (PR2-Q4: so `DomLive` ships none of it to an app that never reads it); each
|
|
16
|
+
// DOM's (PR2-Q4: so `DomLive` ships none of it to an app that never reads it); each Subject's spine gets it in its options. Each member is a plain
|
|
17
17
|
// function: `valueLike` runs on a Follow leg's every step.
|
|
18
18
|
import * as Context from "effect/Context"
|
|
19
19
|
import type * as Option from "effect/Option"
|
|
@@ -26,8 +26,8 @@ import * as UndefinedOr from "effect/UndefinedOr"
|
|
|
26
26
|
* the child's owner so the parent-driven exit reads them after the child leaves.
|
|
27
27
|
*/
|
|
28
28
|
export interface PresenceRecord<E extends Subject.Subject = Subject.Subject> {
|
|
29
|
-
/** The child's root Subject (the same `
|
|
30
|
-
readonly
|
|
29
|
+
/** The child's root Subject (the same `subject` the spine wires). */
|
|
30
|
+
readonly subject: E
|
|
31
31
|
/** The latest emitted value-map, updated by the spine each frame. */
|
|
32
32
|
readonly snapshot: { current: Values.Values }
|
|
33
33
|
/**
|
|
@@ -38,13 +38,13 @@ export interface PresenceRecord<E extends Subject.Subject = Subject.Subject> {
|
|
|
38
38
|
readonly exitOf: (custom: unknown, inherited: Config.WardicVariantLabels | undefined) => PresenceExit
|
|
39
39
|
/**
|
|
40
40
|
* Where it sits in the variant tree, decided at setup as the tree is: whether it joins the
|
|
41
|
-
* nearest
|
|
41
|
+
* nearest Subject that provides a context (a **Variant child**, which then exits on that one's
|
|
42
42
|
* exit name, in its stagger), whether its own Variant children join it, and whether it's a twin
|
|
43
43
|
* (a `layoutId`, whose crossfade replaces its exit). Left out: none of them.
|
|
44
44
|
*/
|
|
45
45
|
readonly tree?: PresenceTree
|
|
46
46
|
/**
|
|
47
|
-
* Where an exit key with no value in `snapshot` starts: its value as the
|
|
47
|
+
* Where an exit key with no value in `snapshot` starts: its value as the Subject was given it (in
|
|
48
48
|
* `@wardic/dom`, its `style`), else its Own value, read from the Subject kept at the exit, in the
|
|
49
49
|
* shape of `like` (the key's exit target). `undefined` starts it at its target. Optional: a record
|
|
50
50
|
* without it starts such a key at its target.
|
|
@@ -67,11 +67,11 @@ export interface PresenceRecord<E extends Subject.Subject = Subject.Subject> {
|
|
|
67
67
|
readonly skipAnimations?: (() => boolean) | undefined
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
/** Where a
|
|
70
|
+
/** Where a Ward's Subject starts when its child takes over from a leaver (#286, ADR-0048): the values and velocities it's drawn at. */
|
|
71
71
|
export interface PresenceSeed {
|
|
72
72
|
readonly values: Values.Values
|
|
73
73
|
readonly velocities: Readonly<Record<string, number>>
|
|
74
|
-
/** Where the
|
|
74
|
+
/** Where the Subject it takes over from was drawn, in the Root frame: a layout node moves from there. */
|
|
75
75
|
readonly box?: Box.Box | undefined
|
|
76
76
|
/** The crossfade factor a twin it takes over from had faded out to: its handover's fade goes on from there. */
|
|
77
77
|
readonly fade?: number | undefined
|
|
@@ -88,7 +88,7 @@ export interface PresenceExit {
|
|
|
88
88
|
readonly name: Config.WardicVariantLabels | undefined
|
|
89
89
|
/**
|
|
90
90
|
* A list's exit by name (#297): each name's keys (those it's the last to set) on its own transition,
|
|
91
|
-
* else the
|
|
91
|
+
* else the Subject's, and its orchestration for its Variant children's keys of that name. Every
|
|
92
92
|
* name has one, keys or none. Left out for a single name or a values map: the whole exit is one.
|
|
93
93
|
*/
|
|
94
94
|
readonly groups?: ReadonlyArray<ExitGroup> | undefined
|
|
@@ -121,17 +121,17 @@ export interface PresenceContextValue<E extends Subject.Subject = Subject.Subjec
|
|
|
121
121
|
*/
|
|
122
122
|
readonly register: (rec: PresenceRecord<E>) => () => void
|
|
123
123
|
/**
|
|
124
|
-
* Whether
|
|
124
|
+
* Whether a Subject setting up now starts at its `animate`, with nothing animating at mount:
|
|
125
125
|
* `<AnimatePresence initial={false}>`, during its first render (Motion's
|
|
126
126
|
* `presenceContext.initial`). A child that enters later animates in. Optional: left out, never.
|
|
127
127
|
*/
|
|
128
128
|
readonly blocksInitial?: () => boolean
|
|
129
129
|
/**
|
|
130
|
-
* Whether
|
|
130
|
+
* Whether a Subject setting up now is inside a child `mode="wait"` holds back: `undefined`
|
|
131
131
|
* when it isn't, and it starts now. Else `start` is called once the child is shown, and the
|
|
132
|
-
* call returned cancels that (the
|
|
132
|
+
* call returned cancels that (the Subject gone first). Optional: left out, never.
|
|
133
133
|
*/
|
|
134
|
-
readonly hold?: (
|
|
134
|
+
readonly hold?: (subject: E, start: () => void) => (() => void) | undefined
|
|
135
135
|
/**
|
|
136
136
|
* A presence hook's registration: `usePresence`'s and `useIsPresent`'s.
|
|
137
137
|
* Optional: left out, nothing is watched.
|
|
@@ -140,39 +140,39 @@ export interface PresenceContextValue<E extends Subject.Subject = Subject.Subjec
|
|
|
140
140
|
/** The presence's `custom`, reactive: `usePresenceData`'s. Left out, `undefined`. */
|
|
141
141
|
readonly data?: () => unknown
|
|
142
142
|
/**
|
|
143
|
-
* A
|
|
143
|
+
* A Ward's Subject made: its `key` and whether it's a twin, told as the Subject is
|
|
144
144
|
* made, before the presence decides what it shows (so `mode="wait"` doesn't hold a child
|
|
145
|
-
* back under its key), and before any of its child's wards mount (so the
|
|
145
|
+
* back under its key), and before any of its child's wards mount (so the Subjects inside pair).
|
|
146
146
|
* Optional: left out, no child is keyed.
|
|
147
147
|
*/
|
|
148
|
-
readonly made?: (
|
|
148
|
+
readonly made?: (subject: E, key: string | number | undefined, twin: boolean) => void
|
|
149
149
|
/**
|
|
150
|
-
* Where
|
|
150
|
+
* Where a Subject mounting now starts, when its child takes over from a leaver: asked once,
|
|
151
151
|
* before its first Retarget. `undefined`: as it would. Optional: left out, never.
|
|
152
152
|
*/
|
|
153
|
-
readonly takeOverOf?: (
|
|
153
|
+
readonly takeOverOf?: (subject: E) => PresenceSeed | undefined
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
/** Tell `presence` a
|
|
157
|
-
export const presenceMade = <E extends Subject.Subject>(presence: PresenceContextValue<E> | undefined,
|
|
156
|
+
/** Tell `presence` a Ward's Subject was made ({@link PresenceContextValue.made}): nothing without one. */
|
|
157
|
+
export const presenceMade = <E extends Subject.Subject>(presence: PresenceContextValue<E> | undefined, subject: E, key: string | number | undefined, twin: boolean): void => {
|
|
158
158
|
if (Predicate.isUndefined(presence)) return
|
|
159
|
-
UndefinedOr.map(presence.made, (tell) => tell(
|
|
159
|
+
UndefinedOr.map(presence.made, (tell) => tell(subject, key, twin))
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
/** Where `
|
|
163
|
-
export const presenceSeedOf = <E extends Subject.Subject>(presence: PresenceContextValue<E> | undefined,
|
|
162
|
+
/** Where `subject` starts as it mounts, taking over from a leaver ({@link PresenceContextValue.takeOverOf}): `undefined` as it would. */
|
|
163
|
+
export const presenceSeedOf = <E extends Subject.Subject>(presence: PresenceContextValue<E> | undefined, subject: E): PresenceSeed | undefined => {
|
|
164
164
|
if (Predicate.isUndefined(presence)) return undefined
|
|
165
|
-
return UndefinedOr.map(presence.takeOverOf, (of) => of(
|
|
165
|
+
return UndefinedOr.map(presence.takeOverOf, (of) => of(subject))
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
|
-
* What a presence hook registers (#277's PR 5b, ADR-0048): its
|
|
170
|
-
* belongs to, and what it's told. Kept until that child goes, the presence goes, or its
|
|
169
|
+
* What a presence hook registers (#277's PR 5b, ADR-0048): its Subject, whose leaving child it
|
|
170
|
+
* belongs to, and what it's told. Kept until that child goes, the presence goes, or its Subject
|
|
171
171
|
* goes some other way.
|
|
172
172
|
*/
|
|
173
173
|
export interface PresenceWatch<E extends Subject.Subject = Subject.Subject> {
|
|
174
|
-
/** Its
|
|
175
|
-
readonly
|
|
174
|
+
/** Its Subject, once it has one: the child that holds it is the one it belongs to. */
|
|
175
|
+
readonly subject: () => E | undefined
|
|
176
176
|
/** Whether it holds its child as it leaves, until `release` is called (`usePresence`). */
|
|
177
177
|
readonly holds: boolean
|
|
178
178
|
/**
|
|
@@ -191,7 +191,7 @@ export interface PresenceWatch<E extends Subject.Subject = Subject.Subject> {
|
|
|
191
191
|
readonly interrupted?: () => void
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
/** Whether `presence` holds
|
|
194
|
+
/** Whether `presence` holds a Subject setting up now at its `animate` ({@link PresenceContextValue.blocksInitial}). */
|
|
195
195
|
export const presenceBlocksInitial = <E extends Subject.Subject>(presence: PresenceContextValue<E> | undefined): boolean =>
|
|
196
196
|
UndefinedOr.match(presence, {
|
|
197
197
|
onUndefined: constFalse,
|
|
@@ -202,5 +202,5 @@ export const presenceBlocksInitial = <E extends Subject.Subject>(presence: Prese
|
|
|
202
202
|
* Whether `el` waits for its child to be shown ({@link PresenceContextValue.hold}): the call
|
|
203
203
|
* that cancels `start`, or `undefined` when it starts now.
|
|
204
204
|
*/
|
|
205
|
-
export const presenceHold = <E extends Subject.Subject>(presence: PresenceContextValue<E> | undefined,
|
|
206
|
-
UndefinedOr.map(presence, (p) => UndefinedOr.map(p.hold, (hold) => hold(
|
|
205
|
+
export const presenceHold = <E extends Subject.Subject>(presence: PresenceContextValue<E> | undefined, subject: E, start: () => void): (() => void) | undefined =>
|
|
206
|
+
UndefinedOr.map(presence, (p) => UndefinedOr.map(p.hold, (hold) => hold(subject, start)))
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Renderer's **projector**: one target's own `project`. It projects a target's values as its Renderer's
|
|
3
|
+
* `project` does, into a patch it keeps and rewrites in place at its next call, so a target that moves every
|
|
4
|
+
* frame is given no new patch each frame. The Flush gate makes one for each target it registers, from its
|
|
5
|
+
* Renderer, and commits each patch before the next call. A Renderer without one is projected with its
|
|
6
|
+
* `project`.
|
|
7
|
+
*
|
|
8
|
+
* A projector rides on its Renderer's value, so a Renderer given in place of an Environment's own has none,
|
|
9
|
+
* and its own `project` is the one used.
|
|
10
|
+
*
|
|
11
|
+
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import * as Projector from "@wardic/core/unstable/Projector"
|
|
15
|
+
*
|
|
16
|
+
* const renderer = Projector.attach({ project, commit }, makeProjector)
|
|
17
|
+
* Projector.makerOf(renderer) // Option.some(makeProjector)
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
// #1030 (ADR-0034, *Amendment (#1030)*): on the Renderer's value, under this module's key, so the stable
|
|
22
|
+
// `Renderer` keeps its shape and a Renderer provided over an Environment's (a test's, one that adds a key)
|
|
23
|
+
// is projected with its own `project`.
|
|
24
|
+
import type * as Renderer from "../Renderer.ts"
|
|
25
|
+
import type * as Option from "effect/Option"
|
|
26
|
+
import * as Predicate from "effect/Predicate"
|
|
27
|
+
import { carriedOf, carry } from "../internal/carried.ts"
|
|
28
|
+
|
|
29
|
+
/** One target's projector: its values' patch, which it may rewrite at its next call. */
|
|
30
|
+
export type Projector = (values: Record<string, unknown>) => Renderer.Patch
|
|
31
|
+
|
|
32
|
+
/** Makes one target's projector. */
|
|
33
|
+
export type Make = () => Projector
|
|
34
|
+
|
|
35
|
+
/** A Renderer: its `project` and its `commit`. */
|
|
36
|
+
type Service = Renderer.Renderer["Service"]
|
|
37
|
+
|
|
38
|
+
/** Where a Renderer's value carries its projector's maker. */
|
|
39
|
+
const KEY: unique symbol = Symbol.for("@wardic/core/unstable/Projector")
|
|
40
|
+
|
|
41
|
+
/** `renderer`, carrying `make`, which makes a projector for each of its targets. */
|
|
42
|
+
export const attach = (renderer: Service, make: Make): Service => carry(renderer, KEY, make)
|
|
43
|
+
|
|
44
|
+
/** What makes `renderer`'s projectors: `None` for a Renderer that carries none. */
|
|
45
|
+
export const makerOf = (renderer: Service): Option.Option<Make> => carriedOf(renderer, KEY, Predicate.isFunction) as Option.Option<Make>
|
package/src/unstable/Report.ts
CHANGED
|
@@ -67,7 +67,7 @@ export const debugKept: Effect.Effect<boolean> = /*#__PURE__*/ Effect.map(Refere
|
|
|
67
67
|
* A lifecycle debug log for `scope` (`wardic.projection`, say): `log(event, annotations?)` logs
|
|
68
68
|
* `scope: event` at Debug, forked on `runner`, with the annotations. Whether a Debug log would be kept
|
|
69
69
|
* is read once, here ({@link debugKept}): when it wouldn't, `on` is `false` and `log` returns at once,
|
|
70
|
-
* forking nothing. A site that builds its annotations per
|
|
70
|
+
* forking nothing. A site that builds its annotations per Subject checks `on` first.
|
|
71
71
|
*/
|
|
72
72
|
// #618 (M4): each call forked a fiber whatever the level, 0.3-0.5 µs to log nothing (one per layout
|
|
73
73
|
// node's mount and unmount); core's Frame loop reads the level once as this does (frameLoop.ts).
|