@wardic/core 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Arc.d.ts +2 -2
- package/dist/Arc.js +1 -1
- package/dist/BaseValue.d.ts +11 -10
- package/dist/BaseValue.d.ts.map +1 -1
- package/dist/BaseValue.js +12 -15
- package/dist/BaseValue.js.map +1 -1
- package/dist/Batch.d.ts +12 -6
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +374 -30
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +16 -0
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +22 -8
- package/dist/Clock.js.map +1 -1
- package/dist/DefaultTransition.d.ts +3 -2
- package/dist/DefaultTransition.d.ts.map +1 -1
- package/dist/DefaultTransition.js +5 -3
- package/dist/DefaultTransition.js.map +1 -1
- package/dist/Drag.d.ts +24 -9
- package/dist/Drag.d.ts.map +1 -1
- package/dist/Drag.js +10 -10
- package/dist/Drag.js.map +1 -1
- package/dist/DragActivity.js +3 -3
- package/dist/DragRecognizer.d.ts +14 -8
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +93 -34
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/Easing.d.ts +1 -1
- package/dist/Easing.js +1 -1
- package/dist/Frame.d.ts.map +1 -1
- package/dist/Frame.js +5 -3
- package/dist/Frame.js.map +1 -1
- package/dist/InputFeed.d.ts +11 -8
- package/dist/InputFeed.d.ts.map +1 -1
- package/dist/InputFeed.js +18 -37
- package/dist/InputFeed.js.map +1 -1
- package/dist/InputSource.d.ts +3 -3
- package/dist/InputSource.js +2 -2
- package/dist/Interpolator.d.ts +2 -2
- package/dist/Interpolator.js +2 -2
- package/dist/InterpolatorRegistry.d.ts +29 -15
- package/dist/InterpolatorRegistry.d.ts.map +1 -1
- package/dist/InterpolatorRegistry.js +17 -8
- package/dist/InterpolatorRegistry.js.map +1 -1
- package/dist/LiveValue.d.ts +16 -9
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +204 -27
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +21 -8
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +184 -60
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +16 -9
- package/dist/Playback.js.map +1 -1
- package/dist/Projection.d.ts +9 -9
- package/dist/Projection.js +2 -2
- package/dist/Recognizer.d.ts +2 -2
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +15 -10
- package/dist/Recognizer.js.map +1 -1
- package/dist/ReducedMotion.d.ts +4 -4
- package/dist/ReducedMotion.js +6 -6
- package/dist/Renderer.d.ts +5 -5
- package/dist/Renderer.js +6 -6
- package/dist/Renderer.js.map +1 -1
- package/dist/Reorder.d.ts +1 -1
- package/dist/Reorder.d.ts.map +1 -1
- package/dist/Reorder.js +2 -1
- package/dist/Reorder.js.map +1 -1
- package/dist/ScrollSource.d.ts +1 -1
- package/dist/ScrollSource.d.ts.map +1 -1
- package/dist/Sequence.d.ts +1 -1
- package/dist/SharedSource.d.ts +3 -3
- package/dist/SharedSource.js +5 -5
- package/dist/SharedSource.js.map +1 -1
- package/dist/Spring.d.ts.map +1 -1
- package/dist/Spring.js +2 -1
- package/dist/Spring.js.map +1 -1
- package/dist/Values.d.ts +2 -2
- package/dist/Values.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/carried.d.ts +13 -0
- package/dist/internal/carried.d.ts.map +1 -0
- package/dist/internal/carried.js +23 -0
- package/dist/internal/carried.js.map +1 -0
- package/dist/internal/firstSteps.d.ts +66 -0
- package/dist/internal/firstSteps.d.ts.map +1 -0
- package/dist/internal/firstSteps.js +107 -0
- package/dist/internal/firstSteps.js.map +1 -0
- package/dist/internal/frameLoop.d.ts +11 -3
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +190 -39
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/guarded.d.ts +16 -0
- package/dist/internal/guarded.d.ts.map +1 -0
- package/dist/internal/guarded.js +68 -0
- package/dist/internal/guarded.js.map +1 -0
- package/dist/internal/lerpsNumbers.d.ts +11 -0
- package/dist/internal/lerpsNumbers.d.ts.map +1 -0
- package/dist/internal/lerpsNumbers.js +38 -0
- package/dist/internal/lerpsNumbers.js.map +1 -0
- package/dist/internal/options.d.ts +7 -7
- package/dist/internal/options.d.ts.map +1 -1
- package/dist/internal/options.js +10 -10
- package/dist/internal/options.js.map +1 -1
- package/dist/internal/stepper.d.ts +21 -4
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +21 -5
- package/dist/internal/stepper.js.map +1 -1
- package/dist/internal/tracing.d.ts +1 -1
- package/dist/internal/tracing.js +1 -1
- package/dist/unstable/AnimationControls.d.ts +45 -39
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +59 -35
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +11 -5
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/AppearHandoff.js.map +1 -1
- package/dist/unstable/BatchCalls.d.ts +2 -2
- package/dist/unstable/BatchCalls.js +5 -5
- package/dist/unstable/Config.d.ts +21 -17
- package/dist/unstable/Config.d.ts.map +1 -1
- package/dist/unstable/Config.js.map +1 -1
- package/dist/unstable/FirstSteps.d.ts +25 -0
- package/dist/unstable/FirstSteps.d.ts.map +1 -0
- package/dist/unstable/FirstSteps.js +2 -0
- package/dist/unstable/FirstSteps.js.map +1 -0
- package/dist/unstable/FlushGate.d.ts +54 -50
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +201 -77
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +6 -3
- package/dist/unstable/FrameEffects.d.ts.map +1 -1
- package/dist/unstable/FrameEffects.js +14 -3
- package/dist/unstable/FrameEffects.js.map +1 -1
- package/dist/unstable/FrameTime.d.ts +1 -1
- package/dist/unstable/FrameTime.js +1 -1
- package/dist/unstable/Imperative.d.ts +42 -13
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +279 -88
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/MeasuredPairs.d.ts +6 -2
- package/dist/unstable/MeasuredPairs.d.ts.map +1 -1
- package/dist/unstable/MeasuredPairs.js.map +1 -1
- package/dist/unstable/OwnValues.js +1 -1
- package/dist/unstable/PresenceRecord.d.ts +30 -26
- package/dist/unstable/PresenceRecord.d.ts.map +1 -1
- package/dist/unstable/PresenceRecord.js +8 -8
- package/dist/unstable/PresenceRecord.js.map +1 -1
- package/dist/unstable/Projector.d.ts +34 -0
- package/dist/unstable/Projector.d.ts.map +1 -0
- package/dist/unstable/Projector.js +9 -0
- package/dist/unstable/Projector.js.map +1 -0
- package/dist/unstable/Report.d.ts +8 -1
- package/dist/unstable/Report.d.ts.map +1 -1
- package/dist/unstable/Report.js +18 -2
- package/dist/unstable/Report.js.map +1 -1
- package/dist/unstable/RetargetLegs.d.ts +7 -1
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +24 -8
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +123 -68
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +319 -167
- package/dist/unstable/Spine.js.map +1 -1
- package/dist/unstable/Stops.d.ts +3 -3
- package/dist/unstable/Stops.js +4 -4
- package/dist/unstable/Subject.d.ts +2 -2
- package/dist/unstable/Subject.js +2 -2
- package/dist/unstable/Timelines.d.ts +11 -11
- package/dist/unstable/Timelines.d.ts.map +1 -1
- package/dist/unstable/Timelines.js +3 -3
- package/dist/unstable/VariantTarget.d.ts +32 -10
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +73 -20
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +68 -34
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +83 -36
- package/dist/unstable/VariantTree.js.map +1 -1
- package/dist/unstable/WardicConfigValue.d.ts +13 -13
- package/dist/unstable/WardicConfigValue.d.ts.map +1 -1
- package/dist/unstable/WardicConfigValue.js +4 -4
- package/dist/unstable/WardicConfigValue.js.map +1 -1
- package/package.json +1 -1
- package/src/Arc.ts +3 -3
- package/src/BaseValue.ts +18 -21
- package/src/Batch.ts +391 -27
- package/src/Clock.ts +29 -8
- package/src/DefaultTransition.ts +5 -3
- package/src/Drag.ts +32 -14
- package/src/DragActivity.ts +3 -3
- package/src/DragRecognizer.ts +118 -41
- package/src/Easing.ts +1 -1
- package/src/Frame.ts +5 -3
- package/src/InputFeed.ts +39 -42
- package/src/InputSource.ts +5 -5
- package/src/Interpolator.ts +3 -3
- package/src/InterpolatorRegistry.ts +22 -13
- package/src/LiveValue.ts +186 -30
- package/src/Machine.ts +252 -81
- package/src/Playback.ts +15 -9
- package/src/Projection.ts +9 -9
- package/src/Recognizer.ts +16 -10
- package/src/ReducedMotion.ts +6 -6
- package/src/Renderer.ts +6 -6
- package/src/Reorder.ts +3 -2
- package/src/ScrollSource.ts +1 -1
- package/src/Sequence.ts +1 -1
- package/src/SharedSource.ts +5 -5
- package/src/Spring.ts +2 -1
- package/src/Values.ts +2 -2
- package/src/index.ts +1 -1
- package/src/internal/carried.ts +22 -0
- package/src/internal/firstSteps.ts +139 -0
- package/src/internal/frameLoop.ts +203 -41
- package/src/internal/guarded.ts +69 -0
- package/src/internal/lerpsNumbers.ts +53 -0
- package/src/internal/options.ts +10 -10
- package/src/internal/stepper.ts +33 -6
- package/src/internal/tracing.ts +1 -1
- package/src/unstable/AnimationControls.ts +88 -57
- package/src/unstable/AppearHandoff.ts +13 -6
- package/src/unstable/BatchCalls.ts +5 -5
- package/src/unstable/Config.ts +23 -17
- package/src/unstable/FirstSteps.ts +26 -0
- package/src/unstable/FlushGate.ts +250 -108
- package/src/unstable/FrameEffects.ts +17 -4
- package/src/unstable/FrameTime.ts +1 -1
- package/src/unstable/Imperative.ts +342 -101
- package/src/unstable/MeasuredPairs.ts +7 -1
- package/src/unstable/OwnValues.ts +1 -1
- package/src/unstable/PresenceRecord.ts +33 -29
- package/src/unstable/Projector.ts +45 -0
- package/src/unstable/Report.ts +20 -2
- package/src/unstable/RetargetLegs.ts +24 -9
- package/src/unstable/Spine.ts +399 -202
- package/src/unstable/Stops.ts +6 -6
- package/src/unstable/Subject.ts +2 -2
- package/src/unstable/Timelines.ts +12 -12
- package/src/unstable/VariantTarget.ts +102 -23
- package/src/unstable/VariantTree.ts +123 -42
- package/src/unstable/WardicConfigValue.ts +13 -13
package/src/Machine.ts
CHANGED
|
@@ -51,6 +51,7 @@ import * as Frame from "./Frame.ts"
|
|
|
51
51
|
import * as FrameLoop from "./FrameLoop.ts"
|
|
52
52
|
import * as InterpolatorRegistry from "./InterpolatorRegistry.ts"
|
|
53
53
|
import { sourceOf } from "./internal/driven.ts"
|
|
54
|
+
import * as LerpsNumbers from "./internal/lerpsNumbers.ts"
|
|
54
55
|
import { cachedResolver, checked, finite } from "./internal/options.ts"
|
|
55
56
|
import {
|
|
56
57
|
initDecay,
|
|
@@ -70,9 +71,12 @@ import {
|
|
|
70
71
|
stopTimesOf,
|
|
71
72
|
timeIn,
|
|
72
73
|
stepTween,
|
|
74
|
+
type WritableFrame,
|
|
73
75
|
TweenFields,
|
|
76
|
+
TweenFrame,
|
|
74
77
|
} from "./internal/stepper.ts"
|
|
75
78
|
import * as Inertia from "./Inertia.ts"
|
|
79
|
+
import * as Scalar from "./Scalar.ts"
|
|
76
80
|
import type * as Point from "./Point.ts"
|
|
77
81
|
import * as Spring from "./Spring.ts"
|
|
78
82
|
import * as UnitScale from "./UnitScale.ts"
|
|
@@ -95,7 +99,8 @@ export interface Machine<out F extends Frame.Frame<unknown>> extends Pipeable, I
|
|
|
95
99
|
readonly [TypeId]: { readonly _F: Covariant<F> }
|
|
96
100
|
/**
|
|
97
101
|
* One run: a step from each tick's `dt` (seconds, as the Clock reports it) to that tick's
|
|
98
|
-
* Frame. Each run holds its own state, so a machine can be started any number of times.
|
|
102
|
+
* Frame. Each run holds its own state, so a machine can be started any number of times. A Frame
|
|
103
|
+
* is the run's until its next step, which may rewrite it in place: copy one to keep it.
|
|
99
104
|
*/
|
|
100
105
|
readonly start: () => (dt: number) => F
|
|
101
106
|
/**
|
|
@@ -165,7 +170,7 @@ export const isMachine = (u: unknown): u is Machine<Frame.Frame<unknown>> => Pre
|
|
|
165
170
|
*/
|
|
166
171
|
// Every constructor clamps each step's `dt` here once (#78), in its leaves' steps and in `delay`'s hold,
|
|
167
172
|
// so both drivers clamp and no stepper needs to defend itself; dom's projection pass clamps its own.
|
|
168
|
-
// Inline, not a `clampDt` layer: a layer is one more call per
|
|
173
|
+
// Inline, not a `clampDt` layer: a layer is one more call per Subject per frame, which V8 doesn't
|
|
169
174
|
// inline (ADR-0028, *Implementation in #94*). Why 500 ms (#23, ADR-0017 *Amendment (#23)*): a stall up
|
|
170
175
|
// to it reaches each consumer whole, so a tween, a spring, decay, inertia or a layout animation lands
|
|
171
176
|
// where wall time puts it, as Motion's time-based animations do; a longer one advances it 500 ms. It
|
|
@@ -729,13 +734,12 @@ const isMultiPhysics = (frame: Frame.Frame<unknown>): frame is Frame.MultiPhysic
|
|
|
729
734
|
Predicate.isObject((frame as Frame.MultiPhysics).velocity)
|
|
730
735
|
|
|
731
736
|
/**
|
|
732
|
-
* A Frame its Stream consumer owns
|
|
733
|
-
*
|
|
734
|
-
*
|
|
735
|
-
* per-frame path (ADR-0025): statement `if`s and plain calls.
|
|
737
|
+
* A Frame its Stream consumer owns, copied, since a step may rewrite it in place: a record `value`, and
|
|
738
|
+
* a record `velocity` beside it (`springValues`, ADR-0030 decision 11), and any other Frame whole (a
|
|
739
|
+
* tween's, ADR-0030 *Amendment (#895)*). On the per-frame path (ADR-0025): statement `if`s and plain calls.
|
|
736
740
|
*/
|
|
737
741
|
const owned = <F extends Frame.Frame<unknown>>(frame: F): F => {
|
|
738
|
-
if (!Predicate.isObject(frame.value)) return frame
|
|
742
|
+
if (!Predicate.isObject(frame.value)) return { ...frame }
|
|
739
743
|
if (isMultiPhysics(frame)) {
|
|
740
744
|
// A `springValues` Frame's arrays are its run's, rewritten each tick: its copy is its records alone (#663).
|
|
741
745
|
if (Frame.isSpringValues(frame)) return { value: { ...frame.value }, velocity: { ...frame.velocity }, done: frame.done } as unknown as F
|
|
@@ -759,10 +763,10 @@ export type Streamed<F> = F extends Frame.SpringValues ? Frame.MultiPhysics : F
|
|
|
759
763
|
* yield* Machine.toStream(fadeIn).pipe(Stream.runForEach((frame) => Effect.sync(() => draw(frame.value))))
|
|
760
764
|
*/
|
|
761
765
|
// Each subscription's run under the machine's one span, with a `<name>: subscribe` debug log annotated
|
|
762
|
-
// with its attributes; per-frame work is unlogged.
|
|
763
|
-
// emitted, so a consumer that collects Frames never sees one rewritten (ADR-0030, decision 11). A
|
|
766
|
+
// with its attributes; per-frame work is unlogged. Every Frame is copied (`owned`) before it's
|
|
767
|
+
// emitted, so a consumer that collects Frames never sees one rewritten (ADR-0030, decision 11; #895). A
|
|
764
768
|
// Stream, not a Channel: measured 2026-11-02, Stream's own layers were ~5% of a pull of the Clock's
|
|
765
|
-
// ticks, and
|
|
769
|
+
// ticks, and Subjects never use `toStream`, so a Channel would gain nothing measurable (#618, M5).
|
|
766
770
|
export const toStream = <F extends Frame.Frame<unknown>>(self: Machine<F>): Stream.Stream<Streamed<F>, never, Clock.Clock> =>
|
|
767
771
|
Stream.unwrap(
|
|
768
772
|
Effect.gen(function* () {
|
|
@@ -793,8 +797,8 @@ export const toStream = <F extends Frame.Frame<unknown>>(self: Machine<F>): Stre
|
|
|
793
797
|
// A plain call, typed `(frame) => undefined`, so a sink that returns an Effect doesn't compile
|
|
794
798
|
// (ADR-0027, decision 8). Dies if the step or the sink throws, or with the loop's own failure. One span
|
|
795
799
|
// per run, with a `<name>: start` debug log. The token (#200, ADR-0027 *Amendment (#200)*): it leaves the
|
|
796
|
-
// loop at once, as an interrupted run does, about a sixth of the cost. `springValues
|
|
797
|
-
// per run (ADR-0030, decision 11). A machine built with a service: `Effect.flatMap(Machine.run(sink))`.
|
|
800
|
+
// loop at once, as an interrupted run does, about a sixth of the cost. `springValues`, a tween, the
|
|
801
|
+
// blends and `keyframesValues` rewrite one Frame per run (ADR-0030, decision 11 and *Amendments (#895, #1031)*). A machine built with a service: `Effect.flatMap(Machine.run(sink))`.
|
|
798
802
|
export const run: {
|
|
799
803
|
<F extends Frame.Frame<unknown>>(sink: FrameLoop.Sink<F>): (self: Machine<F>) => Effect.Effect<F, never, FrameLoop.FrameLoop>
|
|
800
804
|
<F extends Frame.Frame<unknown>>(
|
|
@@ -814,26 +818,36 @@ export const run: {
|
|
|
814
818
|
FrameLoop.FrameLoop.use((loop) => loop.run(self, sink, options as RunOptions)),
|
|
815
819
|
)
|
|
816
820
|
|
|
817
|
-
/**
|
|
818
|
-
|
|
821
|
+
/**
|
|
822
|
+
* `run`'s options: the token the run joins, so `Supersede.end` ends it with the others; and whether the
|
|
823
|
+
* run keeps the frame timeline's time, so the Frame loop never leaves a late frame's time out of its first
|
|
824
|
+
* steps (`Clock.LateFrames`): one whose start is read from it (an Appear animation's `currentTime`), or one
|
|
825
|
+
* that reports the frames' time rather than animating from a start (`LiveValue.time`, `eachFrame` and
|
|
826
|
+
* `velocity`).
|
|
827
|
+
*/
|
|
828
|
+
// #200; #1026: a run on a clock of its own (a video's `currentTime`, its own `performance.now()` reads) leaves
|
|
829
|
+
// `onFrameTimeline` out, and is right that way: the Frame loop's dt isn't its time.
|
|
819
830
|
export interface RunOptions {
|
|
820
|
-
readonly supersede
|
|
831
|
+
readonly supersede?: Supersede.Supersede | undefined
|
|
832
|
+
readonly onFrameTimeline?: boolean | undefined
|
|
821
833
|
}
|
|
822
834
|
|
|
823
835
|
// --- The leaves --------------------------------------------------------------
|
|
824
836
|
|
|
825
837
|
/** A tween's step from 0 elapsed: `tween`'s, and each of `animate`'s and `keyframes`' Intervals. */
|
|
838
|
+
// In place (#895, ADR-0030 *Amendment (#895)*): its time and its Frame are its run's, made at `start()` and
|
|
839
|
+
// rewritten each tick, as `springValues`' are (decision 11); `toStream` copies what it emits.
|
|
826
840
|
const tweenLeaf = (from: number, to: number, tween: ResolvedTween, span: Span): Machine<Frame.Frame<number>> =>
|
|
827
841
|
make({
|
|
828
842
|
settles: true,
|
|
829
843
|
span,
|
|
830
844
|
start: () => {
|
|
831
|
-
|
|
845
|
+
const state = initTween()
|
|
846
|
+
const frame = new TweenFrame(from)
|
|
832
847
|
// Per frame (ADR-0025): the tween resolved when the machine is built, `dt` clamped (#78).
|
|
833
848
|
return (dt) => {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
return { value: result.value, done: result.done }
|
|
849
|
+
stepTween(state, frame, Math.min(dt, MAX_DT), from, to, tween)
|
|
850
|
+
return frame
|
|
837
851
|
}
|
|
838
852
|
},
|
|
839
853
|
})
|
|
@@ -845,7 +859,8 @@ const tweenSpan = (from: number, to: number, duration: number): Span => ({
|
|
|
845
859
|
})
|
|
846
860
|
|
|
847
861
|
/**
|
|
848
|
-
* A tween from `from` to `to` over `options.duration`, eased by its `ease`, after its `delay`.
|
|
862
|
+
* A tween from `from` to `to` over `options.duration`, eased by its `ease`, after its `delay`. Its Frame is
|
|
863
|
+
* the run's, rewritten every tick: copy one to keep it.
|
|
849
864
|
*
|
|
850
865
|
* @example
|
|
851
866
|
* const slide = Machine.tween(0, 240, { duration: 0.4, ease: "easeInOut" })
|
|
@@ -1369,13 +1384,14 @@ const resolveAnimate: (options: AnimateOptions) => ResolvedAnimate = cachedResol
|
|
|
1369
1384
|
* `"mirror"`), and `reverse` swaps its ends. `delay` holds once, before the first play, as Motion's
|
|
1370
1385
|
* does, and `repeatDelay` after each play but the last, where it ended. Each play starts the moment the
|
|
1371
1386
|
* one before ends; a finite `repeat` settles once the last ends, and `repeat: Infinity` never settles.
|
|
1387
|
+
* Its Frame may be the run's, rewritten every tick: copy one to keep it.
|
|
1372
1388
|
*
|
|
1373
1389
|
* @example
|
|
1374
1390
|
* const breathe = Machine.animate(1, 1.08, { duration: 1.2, ease: "easeInOut", repeat: Infinity, repeatType: "mirror" })
|
|
1375
1391
|
*/
|
|
1376
1392
|
// #77, #91. One leaf over one frame time, as Motion's `JSAnimation` is (#226): each step adds its `dt`
|
|
1377
1393
|
// (clamped at `MAX_DT`) and reads the run's pass, the time into it and its direction off the total, so a
|
|
1378
|
-
// tick across a turn
|
|
1394
|
+
// tick across a turn draws that tick's value, not the turn. Then `delay(options.delay)`, and its own
|
|
1379
1395
|
// span, `wardic.animate`.
|
|
1380
1396
|
export const animate = (from: number, to: number, options: AnimateOptions = NO_OPTIONS): Machine<Frame.Frame<number>> => {
|
|
1381
1397
|
const resolved = resolveAnimate(options)
|
|
@@ -1472,27 +1488,82 @@ export const keyframes = (stops: ReadonlyArray<number>, options: KeyframesOption
|
|
|
1472
1488
|
/** One key's blend at a progress `t`, given whether that progress Frame is the run's last. */
|
|
1473
1489
|
type Blender = InterpolatorRegistry.KeyBlend
|
|
1474
1490
|
|
|
1491
|
+
/** An `InterpolatorRegistry`'s service. */
|
|
1492
|
+
type Registry = InterpolatorRegistry.InterpolatorRegistry["Service"]
|
|
1493
|
+
|
|
1494
|
+
/**
|
|
1495
|
+
* How a key moves from one value to the next, decided once per leg: a `Lerp` is a pair of numbers core's
|
|
1496
|
+
* number blend takes, computed in the run's loop from its ends; a `Blend` is any other, through its blender.
|
|
1497
|
+
*/
|
|
1498
|
+
// #1036 (ADR-0030, *Amendment (#1036)*): the number blend's frames with no call to make.
|
|
1499
|
+
type Plan =
|
|
1500
|
+
| { readonly _tag: "Lerp"; readonly from: number; readonly to: number }
|
|
1501
|
+
| { readonly _tag: "Blend"; readonly blend: Blender }
|
|
1502
|
+
|
|
1503
|
+
/** A key's plan through its blender. */
|
|
1504
|
+
const blendPlan = (blend: Blender): Plan => ({ _tag: "Blend", blend })
|
|
1505
|
+
|
|
1506
|
+
/** A key's plan computed in the loop, from `from` to `to`. */
|
|
1507
|
+
const lerpPlan = (from: number, to: number): Plan => ({ _tag: "Lerp", from, to })
|
|
1508
|
+
|
|
1475
1509
|
/**
|
|
1476
|
-
*
|
|
1510
|
+
* A leg's plans laid out for its run's loop: key `i`'s blender at `blenders[i]`, `null` for a `Lerp`, whose
|
|
1511
|
+
* ends are at `2i` and `2i + 1` of `ends`.
|
|
1512
|
+
*/
|
|
1513
|
+
// #1036: the layout measured fastest. A key that isn't a `Lerp` reads what it read before; a flag and each end in
|
|
1514
|
+
// arrays of their own lost most of keyframes' gain, and cost 4–9% where no key was a `Lerp`. The ends in a plain
|
|
1515
|
+
// array: a `Float64Array` cost each start 230–565 B more, and no less a frame.
|
|
1516
|
+
interface Lanes {
|
|
1517
|
+
readonly blenders: ReadonlyArray<Blender | null>
|
|
1518
|
+
readonly ends: ReadonlyArray<number>
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
/** A plan's blender, `null` for a `Lerp`. */
|
|
1522
|
+
const blenderOf = (plan: Plan): Blender | null => {
|
|
1523
|
+
if (plan._tag === "Lerp") return null
|
|
1524
|
+
return plan.blend
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
/** `plans`, laid out. */
|
|
1528
|
+
const lanesOf = (plans: ReadonlyArray<Plan>): Lanes => {
|
|
1529
|
+
// Per leg (#460): `Arr`'s loops.
|
|
1530
|
+
const ends = new Array<number>(2 * plans.length).fill(0)
|
|
1531
|
+
Arr.forEach(plans, (plan, i) => {
|
|
1532
|
+
if (plan._tag === "Blend") return
|
|
1533
|
+
ends[2 * i] = plan.from
|
|
1534
|
+
ends[2 * i + 1] = plan.to
|
|
1535
|
+
})
|
|
1536
|
+
return { blenders: Arr.map(plans, blenderOf), ends }
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
/** Each key of a leg, in `to`'s order, and its lanes. */
|
|
1540
|
+
interface KeyLanes {
|
|
1541
|
+
readonly keys: ReadonlyArray<string>
|
|
1542
|
+
readonly lanes: Lanes
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
/**
|
|
1546
|
+
* Each key's plan from `from[key]` (its target when absent) to `to[key]`, built once through the
|
|
1477
1547
|
* `InterpolatorRegistry`.
|
|
1478
1548
|
*
|
|
1479
1549
|
* - **A Key rule first** (ADR-0035): the Environment's rule for the key by name, when one takes the
|
|
1480
1550
|
* pair, gives the key's whole blend. Core holds none. `@wardic/dom`'s keep a key that hides an
|
|
1481
|
-
*
|
|
1551
|
+
* Subject at its old value until the run's last Frame (ADR-0024, decision 4), grow a value from its
|
|
1482
1552
|
* Animatable none (ADR-0015, *Amendment (#61)*), and blend a list item by item.
|
|
1483
1553
|
* - **Else by value**: the registry's blend. A pair it can't blend is a Discrete pair and switches
|
|
1484
|
-
* at the first Frame past 0 (ADR-0024, decision 3).
|
|
1554
|
+
* at the first Frame past 0 (ADR-0024, decision 3). A pair of numbers the registry blends with
|
|
1555
|
+
* core's number blend is a `Lerp`.
|
|
1485
1556
|
*/
|
|
1486
|
-
const
|
|
1557
|
+
const keyLanesFor: (
|
|
1487
1558
|
from: Readonly<Values.Values>,
|
|
1488
1559
|
to: Readonly<Values.Values>,
|
|
1489
|
-
) => Effect.Effect<
|
|
1560
|
+
) => Effect.Effect<KeyLanes, never, InterpolatorRegistry.InterpolatorRegistry> =
|
|
1490
1561
|
// Per leg (#460): one Effect a key, in `to`'s order, and no record built between.
|
|
1491
1562
|
Effect.fnUntraced(function* (from: Readonly<Values.Values>, to: Readonly<Values.Values>) {
|
|
1492
|
-
const
|
|
1563
|
+
const plan = yield* planner
|
|
1493
1564
|
const keys = Rec.keys(to)
|
|
1494
|
-
const
|
|
1495
|
-
return
|
|
1565
|
+
const plans = yield* Effect.forEach(keys, (key) => plan(key, startOf(from, key, to[key]), to[key]))
|
|
1566
|
+
return { keys, lanes: lanesOf(plans) }
|
|
1496
1567
|
})
|
|
1497
1568
|
|
|
1498
1569
|
/** `key`'s start in `from`, else its target `b`: a statement (#460), as `Rec.get` reads an own key. */
|
|
@@ -1501,58 +1572,137 @@ const startOf = (from: Values.Values, key: string, b: number | string): number |
|
|
|
1501
1572
|
return from[key]
|
|
1502
1573
|
}
|
|
1503
1574
|
|
|
1504
|
-
/** `key`'s
|
|
1505
|
-
|
|
1575
|
+
/** A leg's planner: `key`'s plan from `a` to `b` ({@link keyLanesFor}'s, and each of a keyframes Interval's, #429). */
|
|
1576
|
+
type Planner = (key: string, a: number | string, b: number | string) => Effect.Effect<Plan>
|
|
1577
|
+
|
|
1578
|
+
/** `registry`'s planner, its number check read once a leg. */
|
|
1579
|
+
const plannerOf = (registry: Registry): Planner => {
|
|
1580
|
+
const lerps = LerpsNumbers.lerpsNumbersOf(registry)
|
|
1581
|
+
// Per key, each leg (#460): statements. #1036: a Key rule is asked first, and keeps any pair it takes; the
|
|
1582
|
+
// registry then says whether core's number blend reads a pair of numbers, not a kind an app registered ahead.
|
|
1583
|
+
return (key, a, b) => {
|
|
1584
|
+
const ruled = registry.keyBlendOf(key, a, b)
|
|
1585
|
+
if (Option.isSome(ruled)) return Effect.map(ruled.value, blendPlan)
|
|
1586
|
+
if (Predicate.isString(a)) return resolvedPlan(registry, a, b)
|
|
1587
|
+
if (Predicate.isString(b)) return resolvedPlan(registry, a, b)
|
|
1588
|
+
if (lerps(a, b)) return Effect.succeed(lerpPlan(a, b))
|
|
1589
|
+
return resolvedPlan(registry, a, b)
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
/** The Environment's planner. */
|
|
1594
|
+
const planner: Effect.Effect<Planner, never, InterpolatorRegistry.InterpolatorRegistry> = Effect.map(InterpolatorRegistry.InterpolatorRegistry, plannerOf)
|
|
1595
|
+
|
|
1596
|
+
/** The registry's blend of `a` and `b`, as a plan. */
|
|
1597
|
+
const resolvedPlan = (registry: Registry, a: number | string, b: number | string): Effect.Effect<Plan> =>
|
|
1506
1598
|
// No rule takes it: the registry's blend, through a blender made here, as before #61. A blender
|
|
1507
1599
|
// made by one shared factory for every key made its call site megamorphic, and Node's string
|
|
1508
1600
|
// workloads 7–9% slower per frame (#61's bench).
|
|
1509
|
-
|
|
1601
|
+
Effect.map(registry.resolve(a, b), (blend) => blendPlan((t) => blend(t)))
|
|
1510
1602
|
|
|
1511
1603
|
/**
|
|
1512
|
-
*
|
|
1513
|
-
*
|
|
1514
|
-
*
|
|
1604
|
+
* A blend run's record of `keys`, each key there from the start, unset: a number stored there each frame is
|
|
1605
|
+
* boxed once, and every copy of the record takes that box as it is. Made empty, V8 would keep a number
|
|
1606
|
+
* key's field a raw number, and a copy that reads it would box it again.
|
|
1515
1607
|
*/
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1608
|
+
// #1031 (ADR-0030, *Amendment (#1031)*): Chromium's `Object.assign` boxed each number at each of the Blend
|
|
1609
|
+
// sink's three copies a frame (the Snapshot, `keepFrame`'s record, the gate's `write`), 12 B a key each. V8
|
|
1610
|
+
// decides a field's form from its first value: `null` keeps it one that holds anything.
|
|
1611
|
+
// Per Subject at mount (#540): a loop. It runs at each run's start, a mount's and a Retarget's, over the items, each
|
|
1612
|
+
// key read by a function made once, so a start makes its record and nothing else: an `Arr.map` of the keys and an
|
|
1613
|
+
// `Arr.reduce` cost each start 300 B, and bench:solid's bytes per element per round +2% (#1031).
|
|
1614
|
+
const seededRecordOf = <A>(items: ReadonlyArray<A>, keyOf: (item: A) => string): Record<string, number | string> => {
|
|
1615
|
+
const record: Record<string, number | string | null> = {}
|
|
1616
|
+
for (let i = 0; i < items.length; i++) {
|
|
1617
|
+
const key = keyOf(items[i])
|
|
1618
|
+
// `__proto__` would set the record's prototype, not add a key: its first store meets it as before.
|
|
1619
|
+
if (key !== "__proto__") record[key] = null
|
|
1620
|
+
}
|
|
1621
|
+
return record as Record<string, number | string>
|
|
1524
1622
|
}
|
|
1525
1623
|
|
|
1624
|
+
/** A keyframes Track's key. */
|
|
1625
|
+
const trackKey = (track: Track): string => track.key
|
|
1626
|
+
|
|
1627
|
+
/**
|
|
1628
|
+
* `progress`'s run with every key blended at the progress `at` reads off its Frame. On the per-frame path
|
|
1629
|
+
* (ADR-0025): a loop over the keys and their lanes, laid out with the leg, not `Rec.map`, which spreads the
|
|
1630
|
+
* record and then reassigns every key.
|
|
1631
|
+
*/
|
|
1632
|
+
// #63 measured `Rec.map` 1.6× this loop in Chromium, 2.3× in JSC.
|
|
1633
|
+
// In place (#895, ADR-0030 *Amendment (#895)*): its record and its Frame are its run's, made at `start()` and
|
|
1634
|
+
// rewritten each tick, as `springValues`' are (decision 11); `toStream` copies what it emits.
|
|
1635
|
+
const blendedBy = <F extends Frame.Frame<unknown>>(
|
|
1636
|
+
progress: Machine<F>,
|
|
1637
|
+
{ keys, lanes }: KeyLanes,
|
|
1638
|
+
at: (frame: F) => number,
|
|
1639
|
+
): Machine<Frame.Frame<Values.Values>> =>
|
|
1640
|
+
make({
|
|
1641
|
+
settles: progress.settles,
|
|
1642
|
+
span: progress.span,
|
|
1643
|
+
start: () => {
|
|
1644
|
+
const step = progress.start()
|
|
1645
|
+
const frame: WritableFrame<Record<string, number | string>> = { value: seededRecordOf(keys, identity), done: false }
|
|
1646
|
+
const { blenders, ends } = lanes
|
|
1647
|
+
return (dt) => {
|
|
1648
|
+
const stepped = step(dt)
|
|
1649
|
+
const t = at(stepped)
|
|
1650
|
+
const done = stepped.done
|
|
1651
|
+
const value = frame.value
|
|
1652
|
+
// A `Lerp` through `Scalar.lerp`, the number blend's own step, so its frames are that blend's. In each
|
|
1653
|
+
// loop, not a function both call: called, one key's frame allocated 36.8 B in Node, not 20.8 (#1036).
|
|
1654
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1655
|
+
const blend = blenders[i]
|
|
1656
|
+
if (Predicate.isNull(blend)) {
|
|
1657
|
+
value[keys[i]] = Scalar.lerp(ends[2 * i], ends[2 * i + 1], t)
|
|
1658
|
+
continue
|
|
1659
|
+
}
|
|
1660
|
+
value[keys[i]] = blend(t, done)
|
|
1661
|
+
}
|
|
1662
|
+
frame.done = done
|
|
1663
|
+
return frame
|
|
1664
|
+
}
|
|
1665
|
+
},
|
|
1666
|
+
})
|
|
1667
|
+
|
|
1668
|
+
/** A tween's progress, 0 to 1. */
|
|
1669
|
+
const tweenProgressOf = (frame: Frame.Frame<number>): number => frame.value
|
|
1670
|
+
|
|
1671
|
+
/** A progress spring's progress, 0 to 1 from its 0 to 100 (#663: its one key by index). */
|
|
1672
|
+
const springProgressOf = (frame: Frame.SpringValues): number => frame.positions[0] / 100
|
|
1673
|
+
|
|
1526
1674
|
/**
|
|
1527
1675
|
* A bag of values tweened from `from` to `to`, each key blended as its Environment blends it: numbers,
|
|
1528
1676
|
* unit strings, complex values, and its own kinds, such as `@wardic/dom`'s colours. One tween drives every
|
|
1529
1677
|
* key, so the repeats and `delay` apply to the whole bag. A pair that can't blend switches at the first
|
|
1530
|
-
* frame; the Environment can hold a key until the last, as `@wardic/dom` does a key that hides
|
|
1531
|
-
* Building it needs the `InterpolatorRegistry`, once.
|
|
1678
|
+
* frame; the Environment can hold a key until the last, as `@wardic/dom` does a key that hides a Subject.
|
|
1679
|
+
* Building it needs the `InterpolatorRegistry`, once. Its Frame and its record are the run's, rewritten
|
|
1680
|
+
* every tick: copy one to keep it.
|
|
1532
1681
|
*
|
|
1533
1682
|
* @example
|
|
1534
1683
|
* const fade = yield* Machine.animateValues({ opacity: 0, color: "#bf616a" }, { opacity: 1, color: "#a3be8c" }, { duration: 0.3 })
|
|
1535
1684
|
*/
|
|
1536
1685
|
// One `animate(0, 1, options)` progress drives every key; `done` is its Frame's. Key rules: ADR-0024,
|
|
1537
|
-
// ADR-0035. The registry is consulted once: each key resolves to a pure blender
|
|
1538
|
-
//
|
|
1686
|
+
// ADR-0035. The registry is consulted once: each key resolves to a pure blender, or, a pair of numbers
|
|
1687
|
+
// core's number blend takes, to its ends (#1036); per tick, a direct call for each key but those.
|
|
1539
1688
|
export const animateValues = (
|
|
1540
1689
|
from: Readonly<Values.Values>,
|
|
1541
1690
|
to: Readonly<Values.Values>,
|
|
1542
1691
|
options: AnimateOptions = NO_OPTIONS,
|
|
1543
1692
|
): Effect.Effect<Machine<Frame.Frame<Values.Values>>, never, InterpolatorRegistry.InterpolatorRegistry> =>
|
|
1544
1693
|
// Per leg (#460): the combinators called data-first.
|
|
1545
|
-
Effect.map(
|
|
1694
|
+
Effect.map(keyLanesFor(from, to), (keyed) =>
|
|
1546
1695
|
withSpan(
|
|
1547
|
-
|
|
1696
|
+
blendedBy(animate(0, 1, options), keyed, tweenProgressOf),
|
|
1548
1697
|
"wardic.animateValues",
|
|
1549
|
-
{ attributes: { keys:
|
|
1698
|
+
{ attributes: { keys: keyed.keys.length } },
|
|
1550
1699
|
))
|
|
1551
1700
|
|
|
1552
1701
|
/**
|
|
1553
1702
|
* A bag of values blended from `from` to `to` by one spring's progress: the spring runs from rest on a
|
|
1554
1703
|
* 0 to 100 progress, and each key is blended at progress / 100. It's how a spring moves values that
|
|
1555
|
-
* aren't numbers, a colour or a unit string, as Motion's spring does.
|
|
1704
|
+
* aren't numbers, a colour or a unit string, as Motion's spring does. Its Frame and its record are the
|
|
1705
|
+
* run's, rewritten every tick: copy one to keep it.
|
|
1556
1706
|
*
|
|
1557
1707
|
* - **The progress spans 0 to 100**, as a number going 100 would, so `restDelta` and `restSpeed` mean
|
|
1558
1708
|
* the same for both, and a string key beside an `x` going 0 to 100 lands with it.
|
|
@@ -1569,41 +1719,40 @@ export const springBlend = (
|
|
|
1569
1719
|
options: SpringOptions = NO_OPTIONS,
|
|
1570
1720
|
): Effect.Effect<Machine<Frame.Frame<Values.Values>>, never, InterpolatorRegistry.InterpolatorRegistry> =>
|
|
1571
1721
|
// Per leg (#460): the combinators called data-first.
|
|
1572
|
-
Effect.map(
|
|
1722
|
+
Effect.map(keyLanesFor(from, to), (keyed) =>
|
|
1573
1723
|
withSpan(
|
|
1574
1724
|
// Its one key read by index (#663).
|
|
1575
|
-
|
|
1576
|
-
blendAt(blenders, frame.positions[0] / 100, frame.done)),
|
|
1725
|
+
blendedBy(springValues({ progress: 100 }, options, { from: { progress: 0 }, velocity: { progress: 0 }, records: "value" }), keyed, springProgressOf),
|
|
1577
1726
|
"wardic.springBlend",
|
|
1578
|
-
{ attributes: { keys:
|
|
1727
|
+
{ attributes: { keys: keyed.keys.length } },
|
|
1579
1728
|
))
|
|
1580
1729
|
|
|
1581
1730
|
/**
|
|
1582
|
-
* One key's keyframes in a bag (#429): its stops' times in a pass, and
|
|
1583
|
-
* read from first to last (`forward`) and, when a pass can read them from last to first,
|
|
1584
|
-
* too (`backward`), as Motion's mirrored generator builds its own.
|
|
1731
|
+
* One key's keyframes in a bag (#429): its stops' times in a pass, and each Interval's plan, laid out,
|
|
1732
|
+
* read from first to last (`forward`, `forwardEnds`) and, when a pass can read them from last to first,
|
|
1733
|
+
* that way too (`backward`, `backwardEnds`), as Motion's mirrored generator builds its own.
|
|
1585
1734
|
*/
|
|
1735
|
+
// #1036: each direction's lanes flat on the Track, read in one step a frame. Read through a `Lanes` record,
|
|
1736
|
+
// keyframes with no `Lerp` (an app's number kind registered ahead) ran 7% slower a frame in Bun.
|
|
1586
1737
|
interface Track {
|
|
1587
1738
|
readonly key: string
|
|
1588
1739
|
readonly stopTimes: ReadonlyArray<number>
|
|
1589
|
-
readonly forward:
|
|
1590
|
-
readonly
|
|
1740
|
+
readonly forward: Lanes["blenders"]
|
|
1741
|
+
readonly forwardEnds: Lanes["ends"]
|
|
1742
|
+
readonly backward: Lanes["blenders"]
|
|
1743
|
+
readonly backwardEnds: Lanes["ends"]
|
|
1591
1744
|
}
|
|
1592
1745
|
|
|
1593
|
-
/** No
|
|
1594
|
-
const
|
|
1746
|
+
/** No lanes: a Track whose passes never read its stops from last to first. */
|
|
1747
|
+
const NO_LANES: Lanes = { blenders: [], ends: [] }
|
|
1595
1748
|
|
|
1596
|
-
/** `key`'s
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1599
|
-
key: string,
|
|
1600
|
-
stops: ReadonlyArray<number | string>,
|
|
1601
|
-
): Effect.Effect<ReadonlyArray<Blender>> =>
|
|
1602
|
-
Effect.all(Arr.map(Arr.range(0, stops.length - 2), (i) => blenderFor(registry, key, stops[i], stops[i + 1])))
|
|
1749
|
+
/** `key`'s plan for each Interval through `stops` (two or more), laid out. */
|
|
1750
|
+
const intervalLanes = (plan: Planner, key: string, stops: ReadonlyArray<number | string>): Effect.Effect<Lanes> =>
|
|
1751
|
+
Effect.map(Effect.all(Arr.map(Arr.range(0, stops.length - 2), (i) => plan(key, stops[i], stops[i + 1]))), lanesOf)
|
|
1603
1752
|
|
|
1604
1753
|
/** `key`'s Track through `given` in a pass of `duration` seconds, its stops at `times` when there's one each. */
|
|
1605
1754
|
const trackFor = (
|
|
1606
|
-
|
|
1755
|
+
plan: Planner,
|
|
1607
1756
|
key: string,
|
|
1608
1757
|
given: Arr.NonEmptyReadonlyArray<number | string>,
|
|
1609
1758
|
times: ReadonlyArray<number> | undefined,
|
|
@@ -1612,9 +1761,16 @@ const trackFor = (
|
|
|
1612
1761
|
): Effect.Effect<Track> => {
|
|
1613
1762
|
const stops = stopsOf(given, given[0])
|
|
1614
1763
|
return Effect.all({
|
|
1615
|
-
forward:
|
|
1616
|
-
backward: Bool.match(flips, { onTrue: () =>
|
|
1617
|
-
}).pipe(Effect.map(({ forward, backward }): Track => ({
|
|
1764
|
+
forward: intervalLanes(plan, key, stops),
|
|
1765
|
+
backward: Bool.match(flips, { onTrue: () => intervalLanes(plan, key, Arr.reverse(stops)), onFalse: () => Effect.succeed(NO_LANES) }),
|
|
1766
|
+
}).pipe(Effect.map(({ forward, backward }): Track => ({
|
|
1767
|
+
key,
|
|
1768
|
+
stopTimes: stopTimesOf(stops.length, times, duration),
|
|
1769
|
+
forward: forward.blenders,
|
|
1770
|
+
forwardEnds: forward.ends,
|
|
1771
|
+
backward: backward.blenders,
|
|
1772
|
+
backwardEnds: backward.ends,
|
|
1773
|
+
})))
|
|
1618
1774
|
}
|
|
1619
1775
|
|
|
1620
1776
|
/**
|
|
@@ -1622,7 +1778,8 @@ const trackFor = (
|
|
|
1622
1778
|
* blends it, as `animateValues`' are. One run drives every key: its `duration`, `ease` (one, or one per
|
|
1623
1779
|
* stretch) and repeats are the bag's. Each key has its own stops, at their places in `times` when there's
|
|
1624
1780
|
* one per stop, evenly spaced otherwise. A key with one stop holds it, and one with none is left out.
|
|
1625
|
-
* Building it needs the `InterpolatorRegistry`, once.
|
|
1781
|
+
* Building it needs the `InterpolatorRegistry`, once. Its Frame and its record are the run's, rewritten
|
|
1782
|
+
* every tick: copy one to keep it.
|
|
1626
1783
|
*/
|
|
1627
1784
|
// #429. An Interval blends as a pair does: a Discrete pair switches at its first Frame past 0, and a Key
|
|
1628
1785
|
// rule that holds a key until the run's last Frame (`@wardic/dom`'s for a key that hides an element) sees only the
|
|
@@ -1635,36 +1792,50 @@ export const keyframesValues: (
|
|
|
1635
1792
|
function* (stops: Readonly<Record<string, ReadonlyArray<number | string>>>, options: KeyframesOptions = NO_OPTIONS) {
|
|
1636
1793
|
const resolved = resolveKeyframes(options)
|
|
1637
1794
|
const { run, eases, reverse } = resolved
|
|
1638
|
-
const
|
|
1795
|
+
const plan = yield* planner
|
|
1639
1796
|
const flips = Bool.or(reverse, run.mirrors)
|
|
1640
1797
|
const duration = run.tween.duration
|
|
1641
1798
|
const tracks = yield* Effect.all(
|
|
1642
1799
|
Arr.filterMap(Rec.toEntries(stops), ([key, given]) =>
|
|
1643
1800
|
Arr.match(given, {
|
|
1644
1801
|
onEmpty: () => Result.failVoid,
|
|
1645
|
-
onNonEmpty: (some) => Result.succeed(trackFor(
|
|
1802
|
+
onNonEmpty: (some) => Result.succeed(trackFor(plan, key, some, resolved.times, duration, flips)),
|
|
1646
1803
|
})),
|
|
1647
1804
|
)
|
|
1648
1805
|
const machine = make({
|
|
1649
1806
|
settles: Number.isFinite(resolved.repeat),
|
|
1650
1807
|
span: { name: "wardic.keyframesValues", attributes: {} },
|
|
1651
1808
|
start: () => {
|
|
1652
|
-
let
|
|
1809
|
+
// Its time on a field, which V8 rewrites where it is: a closure's `let` boxed each frame's number (#1031).
|
|
1810
|
+
const state = initTween()
|
|
1653
1811
|
const pass: Pass = { within: 0, reversed: false, flipped: false }
|
|
1812
|
+
// In place (#1031): its record and its Frame are its run's, rewritten each tick, as `blendedBy`'s are.
|
|
1813
|
+
const frame: WritableFrame<Record<string, number | string>> = { value: seededRecordOf(tracks, trackKey), done: false }
|
|
1654
1814
|
// Per frame (ADR-0025): one time, `dt` clamped (#78); a loop over the Tracks built with the machine.
|
|
1655
1815
|
return (dt): Frame.Frame<Values.Values> => {
|
|
1656
|
-
elapsed
|
|
1816
|
+
const elapsed = state.elapsed + Math.min(dt, MAX_DT)
|
|
1817
|
+
state.elapsed = elapsed
|
|
1657
1818
|
const done = passAt(elapsed, run, reverse, pass)
|
|
1658
1819
|
const time = timeIn(pass, duration)
|
|
1659
|
-
const value
|
|
1820
|
+
const value = frame.value
|
|
1660
1821
|
for (const track of tracks) {
|
|
1661
1822
|
const i = intervalAt(time, track.stopTimes)
|
|
1662
1823
|
const eased = eases[i % eases.length](intervalProgress(time, track.stopTimes, i))
|
|
1663
1824
|
let blenders = track.forward
|
|
1664
1825
|
if (pass.flipped) blenders = track.backward
|
|
1665
|
-
|
|
1826
|
+
// A `Lerp` through `Scalar.lerp`, as `blendedBy`'s loop computes one (#1036). Its ends are read
|
|
1827
|
+
// only for a `Lerp`: read for every Interval, a bag of string keys ran 5–6% slower a frame in Bun.
|
|
1828
|
+
const blend = blenders[i]
|
|
1829
|
+
if (Predicate.isNull(blend)) {
|
|
1830
|
+
let ends = track.forwardEnds
|
|
1831
|
+
if (pass.flipped) ends = track.backwardEnds
|
|
1832
|
+
value[track.key] = Scalar.lerp(ends[2 * i], ends[2 * i + 1], eased)
|
|
1833
|
+
continue
|
|
1834
|
+
}
|
|
1835
|
+
value[track.key] = blend(eased, done)
|
|
1666
1836
|
}
|
|
1667
|
-
|
|
1837
|
+
frame.done = done
|
|
1838
|
+
return frame
|
|
1668
1839
|
}
|
|
1669
1840
|
},
|
|
1670
1841
|
})
|
package/src/Playback.ts
CHANGED
|
@@ -127,7 +127,9 @@ export const drive: {
|
|
|
127
127
|
start: () => {
|
|
128
128
|
const writable = writableOf(head)
|
|
129
129
|
const at = head.time
|
|
130
|
-
|
|
130
|
+
// Its own time, on a field (#895): a number a closure holds is boxed again at every store. Not the
|
|
131
|
+
// head's: every machine driven through it keeps its own, and writes it there.
|
|
132
|
+
const own = { time: at }
|
|
131
133
|
let step = runFrom(self, at)
|
|
132
134
|
// Its first tick lands at `at` when it starts partway through, whatever the `dt`.
|
|
133
135
|
let landing = at > 0
|
|
@@ -138,7 +140,7 @@ export const drive: {
|
|
|
138
140
|
if (landing) {
|
|
139
141
|
landing = false
|
|
140
142
|
last = step(0)
|
|
141
|
-
writable.time = time
|
|
143
|
+
writable.time = own.time
|
|
142
144
|
return last
|
|
143
145
|
}
|
|
144
146
|
if (head.paused) {
|
|
@@ -147,18 +149,22 @@ export const drive: {
|
|
|
147
149
|
return held
|
|
148
150
|
}
|
|
149
151
|
held = undefined
|
|
150
|
-
|
|
152
|
+
// At speed 1 within the clamp, the frame's own `dt` (#1031): a number made here is boxed again as it's
|
|
153
|
+
// passed to a step V8 hasn't inlined, 16 B a run a frame, and whether it's inlined turns on when its
|
|
154
|
+
// optimised code was compiled. `tickOf` gives that same number.
|
|
155
|
+
let by = dt
|
|
156
|
+
if (head.speed !== 1 || dt > Machine.MAX_DT) by = tickOf(head, dt, Machine.MAX_DT)
|
|
151
157
|
if (by >= 0) {
|
|
152
|
-
time += by
|
|
153
|
-
writable.time = time
|
|
158
|
+
own.time += by
|
|
159
|
+
writable.time = own.time
|
|
154
160
|
last = step(by)
|
|
155
161
|
return last
|
|
156
162
|
}
|
|
157
|
-
time = Math.max(0, time + by)
|
|
158
|
-
writable.time = time
|
|
159
|
-
step = runFrom(self, time)
|
|
163
|
+
own.time = Math.max(0, own.time + by)
|
|
164
|
+
writable.time = own.time
|
|
165
|
+
step = runFrom(self, own.time)
|
|
160
166
|
last = step(0)
|
|
161
|
-
if (time === 0) return settled(last)
|
|
167
|
+
if (own.time === 0) return settled(last)
|
|
162
168
|
return last
|
|
163
169
|
}
|
|
164
170
|
},
|