@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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The registry of value kinds: given two values, it finds the kind that blends them and returns the
|
|
3
3
|
* blend each frame calls. An Environment builds one over core's kinds and its own (`make`, or `layer`
|
|
4
4
|
* for core's alone), and adds Key rules, which blend a key by its name, as `@wardic/dom`'s keep a key
|
|
5
|
-
* that hides
|
|
5
|
+
* that hides a Subject at its old value until an animation's last frame. A binding resolves each pair once, as it builds an animation.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* import * as InterpolatorRegistry from "@wardic/core/InterpolatorRegistry"
|
|
@@ -22,6 +22,7 @@ import * as Option from "effect/Option";
|
|
|
22
22
|
import * as Predicate from "effect/Predicate";
|
|
23
23
|
import * as Interpolator from "./Interpolator.js";
|
|
24
24
|
import { dual } from "./internal/dual.js";
|
|
25
|
+
import * as LerpsNumbers from "./internal/lerpsNumbers.js";
|
|
25
26
|
// The registry is heterogeneous by design: its entries are `Interpolator.Entry<any, any>`.
|
|
26
27
|
/**
|
|
27
28
|
* The registry of value kinds: a pair of values in, and out the blend each frame calls. A new kind is
|
|
@@ -139,6 +140,14 @@ export const make = (initial = Interpolator.defaults, keyRules = []) => Effect.s
|
|
|
139
140
|
return Effect.succeed(discreteBlend(from, to));
|
|
140
141
|
return blendDecoded(decoded.value, from, to);
|
|
141
142
|
};
|
|
143
|
+
/** Whether a pair of numbers resolves to `Interpolator.number` itself: the first kind that reads it. */
|
|
144
|
+
// Per key, each leg (#460, compose once): statements. #1036: a blend machine computes such a pair in its loop.
|
|
145
|
+
const lerpsNumbers = (from, to) => {
|
|
146
|
+
const decoded = select(entries, from, to);
|
|
147
|
+
if (Option.isNone(decoded))
|
|
148
|
+
return false;
|
|
149
|
+
return decoded.value.entry === Interpolator.number;
|
|
150
|
+
};
|
|
142
151
|
/** A pair of strings, from the cache, or resolved and kept. */
|
|
143
152
|
const resolveCached = (from, to) => {
|
|
144
153
|
const kept = cache.get(from, to);
|
|
@@ -152,7 +161,7 @@ export const make = (initial = Interpolator.defaults, keyRules = []) => Effect.s
|
|
|
152
161
|
return resolveUncached(from, to);
|
|
153
162
|
});
|
|
154
163
|
MutableRef.set(chain, chainOf(rules, resolve, noRule));
|
|
155
|
-
return {
|
|
164
|
+
return LerpsNumbers.attach({
|
|
156
165
|
register: Effect.fnUntraced(function* (entry) {
|
|
157
166
|
entries.unshift(entry);
|
|
158
167
|
cache.clear();
|
|
@@ -167,24 +176,24 @@ export const make = (initial = Interpolator.defaults, keyRules = []) => Effect.s
|
|
|
167
176
|
}),
|
|
168
177
|
keyBlendOf: (key, from, to) => MutableRef.get(chain)(key, from, to),
|
|
169
178
|
forget: Effect.sync(() => cache.clear()),
|
|
170
|
-
};
|
|
179
|
+
}, lerpsNumbers);
|
|
171
180
|
});
|
|
172
181
|
/**
|
|
173
182
|
* `self` run with `rules` asked first, ahead of the registry's own Key rules, for that run alone: how a
|
|
174
|
-
* binding adds a rule bound to one
|
|
183
|
+
* binding adds a rule bound to one Subject, as `@wardic/dom`'s for its own variables, to that Subject's
|
|
175
184
|
* animations.
|
|
176
185
|
* Each rule's `next` is the rules after it, then the registry's, then by value. The registry itself is
|
|
177
|
-
* unchanged, so one
|
|
186
|
+
* unchanged, so one Subject's rule never reaches another's.
|
|
178
187
|
*
|
|
179
188
|
* @example
|
|
180
|
-
* yield* buildLegs.pipe(InterpolatorRegistry.withKeyRules([ruleOf(
|
|
189
|
+
* yield* buildLegs.pipe(InterpolatorRegistry.withKeyRules([ruleOf(subject)]))
|
|
181
190
|
*/
|
|
182
191
|
// ADR-0035, *Amendment (#55)*: `@wardic/dom`'s `variableValues(element)`.
|
|
183
192
|
export const withKeyRules = dual(2, (self, rules) => Effect.updateService(self, InterpolatorRegistry, (registry) => layeredOf(rules, registry)));
|
|
184
193
|
/**
|
|
185
194
|
* Each rule list's layered registries, by the registry under them: a binding binds one list to an
|
|
186
|
-
*
|
|
187
|
-
* Environment, not per leg. Weak, so
|
|
195
|
+
* Subject and wraps each leg it starts with it, so the chain is built once per Subject and
|
|
196
|
+
* Environment, not per leg. Weak, so a Subject's list goes with it.
|
|
188
197
|
*/
|
|
189
198
|
// Module state (#460, Q7): a cache held weakly by the object it's for, so it goes with it.
|
|
190
199
|
const layered = new WeakMap();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InterpolatorRegistry.js","sourceRoot":"","sources":["../src/InterpolatorRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,+FAA+F;AAC/F,uBAAuB;AACvB,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AACnC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,IAAI,EA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8B;IAC9B,IAAI,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACnC,IAAI,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;QACtC,UAAU,GAAG,IAAI,OAAO,EAAoB,CAAA;QAC5C,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAChC,CAAC;IACD,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IACrC,IAAI,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IAC/C,MAAM,IAAI,GAAY,EAAE,GAAG,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAA;IACxG,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IAC9B,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,2HAA2H;AAC3H,MAAM,CAAC,MAAM,KAAK,GAAsC,KAAK,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA"}
|
package/dist/LiveValue.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as Option from "effect/Option";
|
|
|
3
3
|
import * as Atom from "effect/reactivity/Atom";
|
|
4
4
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
5
5
|
import type * as Scope from "effect/Scope";
|
|
6
|
+
import * as Clock from "./Clock.ts";
|
|
6
7
|
import * as FrameLoop from "./FrameLoop.ts";
|
|
7
8
|
import * as Easing from "./Easing.ts";
|
|
8
9
|
import * as InterpolatorRegistry from "./InterpolatorRegistry.ts";
|
|
@@ -58,7 +59,8 @@ interface Interpolate {
|
|
|
58
59
|
export declare const interpolate: Interpolate;
|
|
59
60
|
/**
|
|
60
61
|
* `source` mapped through ranges, as `interpolate` maps a number: an Atom that follows `source`, mapped
|
|
61
|
-
* afresh at each change.
|
|
62
|
+
* afresh at each change. A `mixer` that throws keeps the value it gave last, and is logged once until it
|
|
63
|
+
* returns; one that throws for its first value throws to whatever reads it then.
|
|
62
64
|
*
|
|
63
65
|
* @example
|
|
64
66
|
* const scale = yield* LiveValue.transform(scrollY, [0, 300], [1, 0.8])
|
|
@@ -141,6 +143,9 @@ export declare const jump: {
|
|
|
141
143
|
* is a `jump`; with `skipAnimations`, or while `skipped()` says so, every change is. Its run and its
|
|
142
144
|
* subscription end with the Scope.
|
|
143
145
|
*
|
|
146
|
+
* A source that throws as it's read is followed to where it was last read, and an Atom over it that throws
|
|
147
|
+
* doesn't stop it: each is logged once until it reads, or is written, cleanly.
|
|
148
|
+
*
|
|
144
149
|
* @example
|
|
145
150
|
* const eased = yield* LiveValue.follow(target, { type: "tween", duration: 0.4, ease: "easeOut" })
|
|
146
151
|
*/
|
|
@@ -192,8 +197,8 @@ export interface ScrollTransform {
|
|
|
192
197
|
* How a Live value derives from a container's scroll, in no Environment's terms: the scroll it
|
|
193
198
|
* reads, as `scroll` was given it; whether it reads how far the container is scrolled (`current`) or
|
|
194
199
|
* its progress; on which axis; and each `transform` it went through since, in order. An Environment
|
|
195
|
-
* that can run a scroll-linked value with the scroll itself, as
|
|
196
|
-
*
|
|
200
|
+
* that can run a scroll-linked value with the scroll itself, as `@wardic/dom` can (a **Timeline value**),
|
|
201
|
+
* reads it to decide whether it can, and how.
|
|
197
202
|
*/
|
|
198
203
|
export interface ScrollDerivation {
|
|
199
204
|
/** The scroll's options, as `scroll` was given them. */
|
|
@@ -208,7 +213,7 @@ export interface ScrollDerivation {
|
|
|
208
213
|
/**
|
|
209
214
|
* Describe `atom` as deriving from a container's scroll as `source` does: for an Atom a binding
|
|
210
215
|
* keeps for a value's life and sets from `source`, made after it, as a `createScroll` does once its
|
|
211
|
-
*
|
|
216
|
+
* Subjects are there. A `transform` made over `atom` before then derives through it too. Called again,
|
|
212
217
|
* it derives as the new `source` does. `source` mustn't derive from `atom`.
|
|
213
218
|
*
|
|
214
219
|
* @example
|
|
@@ -225,8 +230,8 @@ export declare const derivesAs: {
|
|
|
225
230
|
* How `atom` derives from a container's scroll, now: one of `scroll`'s values, an Atom
|
|
226
231
|
* `derivesAs` one, or a `transform` over either, a `transform` over that, and so on; `None` for any
|
|
227
232
|
* other, a `spring` or a `velocity` of one among them. Read again while nothing it derives from
|
|
228
|
-
* changed, it's the same object. An Environment reads it to run the value
|
|
229
|
-
*
|
|
233
|
+
* changed, it's the same object. An Environment reads it to run the value with the scroll itself where it
|
|
234
|
+
* can, as `@wardic/dom` can (a **Timeline value**).
|
|
230
235
|
*
|
|
231
236
|
* @example
|
|
232
237
|
* const { scrollYProgress } = yield* LiveValue.scroll({ container })
|
|
@@ -239,15 +244,17 @@ export declare const scrollDerivationOf: (atom: Atom.Atom<unknown>) => Option.Op
|
|
|
239
244
|
* How fast `source` is changing, in its units a second, as Motion's `useVelocity`: 0 to begin with, and
|
|
240
245
|
* from each change on, each frame's change over the frame's time, until a frame finds no change, sets 0
|
|
241
246
|
* and stops. Nothing runs while the source rests. A velocity is a value too: `velocity(velocity(x))` is
|
|
242
|
-
* acceleration. Its run ends with the Scope.
|
|
247
|
+
* acceleration. Its run ends with the Scope. A source that throws as it's read reads as still, and an Atom
|
|
248
|
+
* over it that throws doesn't stop it: each is logged once until it reads, or is written, cleanly.
|
|
243
249
|
*
|
|
244
250
|
* @example
|
|
245
251
|
* const speed = yield* LiveValue.velocity(scrollY)
|
|
246
252
|
*/
|
|
247
|
-
export declare const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<number>, never, FrameLoop.FrameLoop | AtomRegistry.AtomRegistry | Scope.Scope>;
|
|
253
|
+
export declare const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<number>, never, Clock.Clock | FrameLoop.FrameLoop | AtomRegistry.AtomRegistry | Scope.Scope>;
|
|
248
254
|
/**
|
|
249
255
|
* Milliseconds since it started, as Motion's `useTime`: wall time, minutes the app spent hidden included. It
|
|
250
|
-
* keeps the Clock ticking every frame while it runs; its run ends with the Scope.
|
|
256
|
+
* keeps the Clock ticking every frame while it runs; its run ends with the Scope. An Atom over it that
|
|
257
|
+
* throws doesn't stop it: that's logged once until it's written cleanly.
|
|
251
258
|
*
|
|
252
259
|
* @example
|
|
253
260
|
* const rotate = yield* LiveValue.transform(yield* LiveValue.time(), [0, 4000], [0, 360], { clamp: false })
|
package/dist/LiveValue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveValue.d.ts","sourceRoot":"","sources":["../src/LiveValue.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LiveValue.d.ts","sourceRoot":"","sources":["../src/LiveValue.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAA;AAC9C,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAA;AAE9D,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,oBAAoB,MAAM,2BAA2B,CAAA;AAEjE,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAKjD,qIAAqI;AAErI,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,KAAK,CAAC,CAAA;AAE3D,6BAA6B;AAC7B,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,MAAM,GAAG,MAAM;IACn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,eAAO,MAAM,IAAI,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,SAAS,GAAG,YAAY,CAAC,YAAY,GAAG,KAAK,CAAC,KAAK,CAqC1H,CAAA;AAKJ;;;;;;;;;;;;;GAaG;AAIH,eAAO,MAAM,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,SAAS,GAAG,KAAK,CAAC,KAAK,CAkBrI,CAAA"}
|
package/dist/LiveValue.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Live values: values derived from other values as they change, each an `effect/reactivity` Atom an
|
|
3
|
-
*
|
|
3
|
+
* Subject's `style` can follow. `transform` maps one through ranges, `follow` and `spring` follow one on
|
|
4
4
|
* a transition, `velocity` tracks how fast one moves, `scroll` gives a container's scroll, `time` the
|
|
5
5
|
* time since it started, and `eachFrame` calls you every frame. A binding wraps them in its own
|
|
6
6
|
* reactive values, as Solid's `createSpring` and `createTransform` do.
|
|
@@ -12,14 +12,15 @@
|
|
|
12
12
|
* const x = yield* LiveValue.spring(pointerX, { stiffness: 300, damping: 30 })
|
|
13
13
|
* const opacity = yield* LiveValue.transform(x, [0, 200], [1, 0])
|
|
14
14
|
*/
|
|
15
|
-
// #130, ADR-0043: a Live value is one the user moves themselves, given in
|
|
16
|
-
// key's `style` link, which the
|
|
15
|
+
// #130, ADR-0043: a Live value is one the user moves themselves, given in a Subject's `style`: the
|
|
16
|
+
// key's `style` link, which the Subject follows while no entry of the Override stack sets it
|
|
17
17
|
// (CONTEXT.md). Its shared form is an Atom, as core's other live data is (`Probe.viewport`). Motion's
|
|
18
18
|
// `useTransform` (with a `mixer`, #440), `interpolate`, `followValue` (#441), `useSpring`,
|
|
19
19
|
// `MotionValue.jump` (#257 item 7), `useScroll` (#234), `useVelocity`, `useTime`, `useAnimationFrame`
|
|
20
20
|
// (#443). Tier 2 (ADR-0008): Effect-typed, for bindings, which wrap them.
|
|
21
21
|
import * as Arr from "effect/Array";
|
|
22
22
|
import * as Bool from "effect/Boolean";
|
|
23
|
+
import * as Cause from "effect/Cause";
|
|
23
24
|
import * as Context from "effect/Context";
|
|
24
25
|
import * as Effect from "effect/Effect";
|
|
25
26
|
import * as FiberHandle from "effect/FiberHandle";
|
|
@@ -31,6 +32,7 @@ import * as Atom from "effect/reactivity/Atom";
|
|
|
31
32
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
32
33
|
import * as Rec from "effect/Record";
|
|
33
34
|
import * as UndefinedOr from "effect/UndefinedOr";
|
|
35
|
+
import * as Clock from "./Clock.js";
|
|
34
36
|
import * as FrameLoop from "./FrameLoop.js";
|
|
35
37
|
import * as Easing from "./Easing.js";
|
|
36
38
|
import * as InterpolatorRegistry from "./InterpolatorRegistry.js";
|
|
@@ -38,6 +40,7 @@ import * as Machine from "./Machine.js";
|
|
|
38
40
|
import * as ScrollSource from "./ScrollSource.js";
|
|
39
41
|
import * as Supersede from "./Supersede.js";
|
|
40
42
|
import { dual } from "./internal/dual.js";
|
|
43
|
+
import * as Report from "./unstable/Report.js";
|
|
41
44
|
/** Stretch `i`'s easing (#360): the one for every stretch, or its own from a list, linear past the list's end, as Motion's. */
|
|
42
45
|
const easeOfStretch = (ease, i) => UndefinedOr.match(ease, {
|
|
43
46
|
onUndefined: () => Easing.linear,
|
|
@@ -104,12 +107,38 @@ const interpolateWith = Effect.fnUntraced(function* (input, output, options = {}
|
|
|
104
107
|
});
|
|
105
108
|
/**
|
|
106
109
|
* `source` mapped through ranges, as `interpolate` maps a number: an Atom that follows `source`, mapped
|
|
107
|
-
* afresh at each change.
|
|
110
|
+
* afresh at each change. A `mixer` that throws keeps the value it gave last, and is logged once until it
|
|
111
|
+
* returns; one that throws for its first value throws to whatever reads it then.
|
|
108
112
|
*
|
|
109
113
|
* @example
|
|
110
114
|
* const scale = yield* LiveValue.transform(scrollY, [0, 300], [1, 0.8])
|
|
111
115
|
*/
|
|
112
|
-
export const transform = (source, input, output, options = {}) => Effect.
|
|
116
|
+
export const transform = (source, input, output, options = {}) => Effect.zipWith(interpolateWith(input, output, options), Effect.context(), (map, context) => {
|
|
117
|
+
// An app's `mixer` that throws: its last value kept, reported at the first throw of a run of them, again
|
|
118
|
+
// after a clean one; with none yet to keep, its first value's throw is its reader's (#979). The try is in
|
|
119
|
+
// the read itself, around a direct call: a helper called from it measured a few points a change on Bun.
|
|
120
|
+
let last;
|
|
121
|
+
let kept = false;
|
|
122
|
+
let failing = false;
|
|
123
|
+
const read = (get) => {
|
|
124
|
+
const v = get(source);
|
|
125
|
+
try {
|
|
126
|
+
last = map(v);
|
|
127
|
+
kept = true;
|
|
128
|
+
if (failing)
|
|
129
|
+
failing = false;
|
|
130
|
+
}
|
|
131
|
+
catch (defect) {
|
|
132
|
+
if (!kept)
|
|
133
|
+
throw defect;
|
|
134
|
+
if (!failing)
|
|
135
|
+
Report.failureOn(context, MIXER_FAILED, Cause.die(defect));
|
|
136
|
+
failing = true;
|
|
137
|
+
}
|
|
138
|
+
return last;
|
|
139
|
+
};
|
|
140
|
+
return transformedFrom(Atom.make(read), source, input, output, options);
|
|
141
|
+
});
|
|
113
142
|
/** `v`'s stretch, as Motion's: the first that ends above it, else the last. Read on each change of the source. */
|
|
114
143
|
const stretchAt = (stretches, v) => Option.match(Arr.findFirst(stretches, (s) => v < s.to), { onNone: () => Arr.lastNonEmpty(stretches), onSome: identity });
|
|
115
144
|
/** `v`'s progress through `stretch`, as Motion's `progress`: 1 through a stretch of no length. */
|
|
@@ -172,7 +201,8 @@ export const jump = dual(2, Effect.fnUntraced(function* (atom, value) {
|
|
|
172
201
|
const registry = yield* AtomRegistry.AtomRegistry;
|
|
173
202
|
jumpIn(registry, atom, value);
|
|
174
203
|
}));
|
|
175
|
-
/** Motion's spring, for the physics a follow's spring leaves out (
|
|
204
|
+
/** Motion's spring, for the physics a follow's spring leaves out (Motion's `springDefaults`). */
|
|
205
|
+
// `motion-dom`'s `springDefaults`.
|
|
176
206
|
const MOTION_PHYSICS = { stiffness: 100, damping: 10, mass: 1 };
|
|
177
207
|
/** Motion's follower's rest thresholds, for those a spring or an inertia leaves out (`follow()`'s). */
|
|
178
208
|
const FOLLOW_REST = { restDelta: 0.001, restSpeed: 0.01 };
|
|
@@ -219,6 +249,14 @@ const velocityOfFrame = (frame) => {
|
|
|
219
249
|
return 0;
|
|
220
250
|
return velocity;
|
|
221
251
|
};
|
|
252
|
+
// #979, group D (ADR-0074): a run goes on past an Atom over it, or under it, that throws, its failure
|
|
253
|
+
// reported on what it was built with (`Report.failureOn`), off the per-frame path.
|
|
254
|
+
/** A run's dependent that threw at its write: an app's Atom over its value, say. */
|
|
255
|
+
const DEPENDENT_FAILED = "wardic.liveValue: its dependent failed";
|
|
256
|
+
/** A run's source that threw as it was read: an app's Atom under it, say. */
|
|
257
|
+
const SOURCE_FAILED = "wardic.liveValue: its source failed";
|
|
258
|
+
/** A transform's ranges that threw: an app's `mixer`. */
|
|
259
|
+
const MIXER_FAILED = "wardic.transform: its mixer failed";
|
|
222
260
|
const FOLLOW_SPAN = { name: "wardic.follow", attributes: {} };
|
|
223
261
|
/**
|
|
224
262
|
* A value that follows `source` on a transition, as Motion's `followValue`: it starts where the source
|
|
@@ -236,6 +274,9 @@ const FOLLOW_SPAN = { name: "wardic.follow", attributes: {} };
|
|
|
236
274
|
* is a `jump`; with `skipAnimations`, or while `skipped()` says so, every change is. Its run and its
|
|
237
275
|
* subscription end with the Scope.
|
|
238
276
|
*
|
|
277
|
+
* A source that throws as it's read is followed to where it was last read, and an Atom over it that throws
|
|
278
|
+
* doesn't stop it: each is logged once until it reads, or is written, cleanly.
|
|
279
|
+
*
|
|
239
280
|
* @example
|
|
240
281
|
* const eased = yield* LiveValue.follow(target, { type: "tween", duration: 0.4, ease: "easeOut" })
|
|
241
282
|
*/
|
|
@@ -244,6 +285,7 @@ const FOLLOW_SPAN = { name: "wardic.follow", attributes: {} };
|
|
|
244
285
|
// Atom is held in the registry until the Scope ends, and after it only while subscribed.
|
|
245
286
|
export const follow = Effect.fnUntraced(function* (source, options = {}, skipped = constFalse) {
|
|
246
287
|
const registry = yield* AtomRegistry.AtomRegistry;
|
|
288
|
+
const context = yield* Effect.context();
|
|
247
289
|
const { skipInitialAnimation, skipAnimations, ...transition } = options;
|
|
248
290
|
const plan = planOf(transition);
|
|
249
291
|
const skips = Bool.match(skipAnimations === true, { onTrue: () => constTrue, onFalse: () => skipped });
|
|
@@ -259,7 +301,25 @@ export const follow = Effect.fnUntraced(function* (source, options = {}, skipped
|
|
|
259
301
|
let changed = false;
|
|
260
302
|
// Whether the source's next change is a jump: its first, with `skipInitialAnimation`.
|
|
261
303
|
let skipping = skipInitialAnimation === true;
|
|
262
|
-
|
|
304
|
+
// A source that throws (an app's Atom under it): a run steering toward it keeps its last read,
|
|
305
|
+
// reported at the first throw of a run of them, again after a clean read (#979).
|
|
306
|
+
let lastTarget = registry.get(out);
|
|
307
|
+
let sourceFailing = false;
|
|
308
|
+
const target = () => {
|
|
309
|
+
try {
|
|
310
|
+
lastTarget = registry.get(source);
|
|
311
|
+
if (sourceFailing)
|
|
312
|
+
sourceFailing = false;
|
|
313
|
+
}
|
|
314
|
+
catch (defect) {
|
|
315
|
+
if (!sourceFailing)
|
|
316
|
+
Report.failureOn(context, SOURCE_FAILED, Cause.die(defect));
|
|
317
|
+
sourceFailing = true;
|
|
318
|
+
}
|
|
319
|
+
return lastTarget;
|
|
320
|
+
};
|
|
321
|
+
// Whether its writes are throwing back a dependent's failure, reported as the source's are.
|
|
322
|
+
let failing = false;
|
|
263
323
|
/** One run: the plan's, from where `out` is, started again from where it's reached at the step after a change. */
|
|
264
324
|
const machine = Machine.make({
|
|
265
325
|
settles: false,
|
|
@@ -299,7 +359,18 @@ export const follow = Effect.fnUntraced(function* (source, options = {}, skipped
|
|
|
299
359
|
token = Supersede.make();
|
|
300
360
|
const ending = token;
|
|
301
361
|
run(machine.pipe(Machine.run((frame) => {
|
|
302
|
-
registry
|
|
362
|
+
// Per frame, a try around the direct call: the registry has set it and told its other
|
|
363
|
+
// listeners before a dependent's throw comes back (an app's Atom over it), so the run goes on.
|
|
364
|
+
try {
|
|
365
|
+
registry.set(out, frame.value);
|
|
366
|
+
if (failing)
|
|
367
|
+
failing = false;
|
|
368
|
+
}
|
|
369
|
+
catch (defect) {
|
|
370
|
+
if (!failing)
|
|
371
|
+
Report.failureOn(context, DEPENDENT_FAILED, Cause.die(defect));
|
|
372
|
+
failing = true;
|
|
373
|
+
}
|
|
303
374
|
velocity = velocityOfFrame(frame);
|
|
304
375
|
// At rest on the source: end the run; the next change starts another.
|
|
305
376
|
if (frame.done) {
|
|
@@ -400,7 +471,7 @@ const derivationNow = (atom) => {
|
|
|
400
471
|
/**
|
|
401
472
|
* Describe `atom` as deriving from a container's scroll as `source` does: for an Atom a binding
|
|
402
473
|
* keeps for a value's life and sets from `source`, made after it, as a `createScroll` does once its
|
|
403
|
-
*
|
|
474
|
+
* Subjects are there. A `transform` made over `atom` before then derives through it too. Called again,
|
|
404
475
|
* it derives as the new `source` does. `source` mustn't derive from `atom`.
|
|
405
476
|
*
|
|
406
477
|
* @example
|
|
@@ -419,8 +490,8 @@ export const derivesAs = dual(2, (atom, source) => {
|
|
|
419
490
|
* How `atom` derives from a container's scroll, now: one of `scroll`'s values, an Atom
|
|
420
491
|
* `derivesAs` one, or a `transform` over either, a `transform` over that, and so on; `None` for any
|
|
421
492
|
* other, a `spring` or a `velocity` of one among them. Read again while nothing it derives from
|
|
422
|
-
* changed, it's the same object. An Environment reads it to run the value
|
|
423
|
-
*
|
|
493
|
+
* changed, it's the same object. An Environment reads it to run the value with the scroll itself where it
|
|
494
|
+
* can, as `@wardic/dom` can (a **Timeline value**).
|
|
424
495
|
*
|
|
425
496
|
* @example
|
|
426
497
|
* const { scrollYProgress } = yield* LiveValue.scroll({ container })
|
|
@@ -437,52 +508,142 @@ const numberMachine = (name, settles, start) => Machine.make({ settles, span: {
|
|
|
437
508
|
* How fast `source` is changing, in its units a second, as Motion's `useVelocity`: 0 to begin with, and
|
|
438
509
|
* from each change on, each frame's change over the frame's time, until a frame finds no change, sets 0
|
|
439
510
|
* and stops. Nothing runs while the source rests. A velocity is a value too: `velocity(velocity(x))` is
|
|
440
|
-
* acceleration. Its run ends with the Scope.
|
|
511
|
+
* acceleration. Its run ends with the Scope. A source that throws as it's read reads as still, and an Atom
|
|
512
|
+
* over it that throws doesn't stop it: each is logged once until it reads, or is written, cleanly.
|
|
441
513
|
*
|
|
442
514
|
* @example
|
|
443
515
|
* const speed = yield* LiveValue.velocity(scrollY)
|
|
444
516
|
*/
|
|
445
|
-
// Each tick's `dt` is clamped at `Machine.MAX_DT`, as every run's is.
|
|
446
|
-
// read by an `afterTick` hook, not the run's own last read: a run started inside a
|
|
447
|
-
// step
|
|
517
|
+
// Each tick's `dt` is clamped at `Machine.MAX_DT`, as every run's is. A step reads the change "since the end
|
|
518
|
+
// of the tick before", read by an `afterTick` hook, not the run's own last read: a run started inside a
|
|
519
|
+
// tick whose Late step doesn't come (back-to-back frames, or past the Late rounds) takes its first step at
|
|
520
|
+
// the next tick, and would otherwise count two frames' change over one `dt`. Its Late step, at the loop's
|
|
521
|
+
// tick count it started at, reads from the source before the change that started it, since the tick's hook
|
|
522
|
+
// has read past that change by then (#991, ADR-0043 *Amendment (#991)*). A change is over the time it took
|
|
523
|
+
// (#1046): the tick's dt, on the frame timeline, unless the time since the read at the run's own last step,
|
|
524
|
+
// a tick before, differs from it by more than half, a late frame's stamps misstating it either way (below).
|
|
448
525
|
export const velocity = Effect.fnUntraced(function* (source) {
|
|
449
526
|
const registry = yield* AtomRegistry.AtomRegistry;
|
|
450
527
|
// Mounted for the Scope, not kept alive: a kept-alive Atom's node never leaves the registry.
|
|
451
528
|
const out = Atom.make(0);
|
|
452
529
|
const unmount = registry.mount(out);
|
|
453
530
|
const run = yield* FiberHandle.makeRuntime();
|
|
454
|
-
|
|
531
|
+
const context = yield* Effect.context();
|
|
532
|
+
// A source that throws (an app's Atom under it) reads as still, its last read kept, reported at the
|
|
533
|
+
// first throw of a run of them, again after a clean read; its writes as follow's are (#979).
|
|
534
|
+
// Each read's try is written where it reads, around a direct call: a reader called from both measured
|
|
535
|
+
// +16% on Bun's velocity frame. A flag is cleared only when it's set: a check on the clean path.
|
|
536
|
+
let sourceFailing = false;
|
|
537
|
+
let failing = false;
|
|
538
|
+
// The source at the end of the tick before: where each tick's change is read from. A read that throws
|
|
539
|
+
// keeps it.
|
|
455
540
|
let previous = registry.get(source);
|
|
541
|
+
// A run's start (#991): the source from before the change that started it, the loop's tick count then,
|
|
542
|
+
// and whether its first step is still due (only that step can be its Late step).
|
|
543
|
+
let seed = previous;
|
|
544
|
+
let startedAt = 0;
|
|
545
|
+
let firstDue = false;
|
|
456
546
|
const loop = yield* FrameLoop.FrameLoop;
|
|
547
|
+
// When `previous` was read, on the Clock's `now()`, and at which tick; and the tick of the run's last
|
|
548
|
+
// step, `-1` before its first. A step right after the run's own last one divides its change by the time
|
|
549
|
+
// since that tick's read, which a late frame's stamps misstate (#1046): a running run keeps the loop
|
|
550
|
+
// ticking every frame, where the loop idles between runs and its tick count skips the frames it missed.
|
|
551
|
+
const clock = yield* Clock.Clock;
|
|
552
|
+
let previousAt = 0;
|
|
553
|
+
let previousTick = -1;
|
|
554
|
+
let stepTick = -1;
|
|
457
555
|
yield* loop.afterTick(() => {
|
|
458
|
-
|
|
556
|
+
try {
|
|
557
|
+
previous = registry.get(source);
|
|
558
|
+
previousAt = clock.now();
|
|
559
|
+
previousTick = loop.tickCount();
|
|
560
|
+
if (sourceFailing)
|
|
561
|
+
sourceFailing = false;
|
|
562
|
+
}
|
|
563
|
+
catch (defect) {
|
|
564
|
+
if (!sourceFailing)
|
|
565
|
+
Report.failureOn(context, SOURCE_FAILED, Cause.die(defect));
|
|
566
|
+
sourceFailing = true;
|
|
567
|
+
}
|
|
459
568
|
return undefined;
|
|
460
569
|
});
|
|
461
570
|
// A jump of the source isn't motion: the change is read from where it jumped to.
|
|
462
571
|
const unhear = onJump(registry, source, (value) => {
|
|
463
572
|
previous = value;
|
|
573
|
+
seed = value;
|
|
574
|
+
stepTick = -1;
|
|
464
575
|
});
|
|
465
576
|
// One token for its lifetime, and one run program, started afresh on the change after a rest:
|
|
466
577
|
// a change while a run goes costs a check, nothing built.
|
|
467
578
|
const token = Supersede.make();
|
|
468
579
|
let running = false;
|
|
580
|
+
// Where a run's first step reads its change from, clearing its due flag: its Late step, at the tick
|
|
581
|
+
// count it started at, from the source before the change that started it (the tick's hook has moved
|
|
582
|
+
// `previous` past it); one at a later tick, from the end of the tick before, as every later step does.
|
|
583
|
+
const takeFirstFrom = () => {
|
|
584
|
+
firstDue = false;
|
|
585
|
+
if (loop.tickCount() === startedAt)
|
|
586
|
+
return seed;
|
|
587
|
+
return previous;
|
|
588
|
+
};
|
|
469
589
|
const program = numberMachine("wardic.velocity", true, () => (dt) => {
|
|
470
|
-
|
|
590
|
+
// Over the tick's dt, unless, right after the run's own last step, the time since that tick's read
|
|
591
|
+
// differs from it by more than half: a late frame, whose stamps misstate it (#1046). An on-time frame's
|
|
592
|
+
// reads differ from its dt by their jitter, which the stamps don't have. A run's first step, its Late
|
|
593
|
+
// step among them, has no read of its own a tick before.
|
|
594
|
+
const tick = loop.tickCount();
|
|
595
|
+
let seconds = dt;
|
|
596
|
+
if (stepTick === tick - 1 && previousTick === stepTick) {
|
|
597
|
+
const since = (clock.now() - previousAt) / 1000;
|
|
598
|
+
if (Math.abs(since - dt) > dt / 2)
|
|
599
|
+
seconds = since;
|
|
600
|
+
}
|
|
601
|
+
stepTick = tick;
|
|
602
|
+
const step = Math.min(seconds, Machine.MAX_DT);
|
|
471
603
|
// A tick in no time (never from the Clock) reads as still.
|
|
472
604
|
if (step === 0)
|
|
473
605
|
return { value: 0, done: true };
|
|
474
|
-
|
|
606
|
+
// A check on every later step: the first's alone reads the tick count (#991).
|
|
607
|
+
let before = previous;
|
|
608
|
+
if (firstDue)
|
|
609
|
+
before = takeFirstFrom();
|
|
610
|
+
// A read that throws reads as still.
|
|
611
|
+
let now = before;
|
|
612
|
+
try {
|
|
613
|
+
now = registry.get(source);
|
|
614
|
+
if (sourceFailing)
|
|
615
|
+
sourceFailing = false;
|
|
616
|
+
}
|
|
617
|
+
catch (defect) {
|
|
618
|
+
if (!sourceFailing)
|
|
619
|
+
Report.failureOn(context, SOURCE_FAILED, Cause.die(defect));
|
|
620
|
+
sourceFailing = true;
|
|
621
|
+
}
|
|
622
|
+
const v = (now - before) / step;
|
|
475
623
|
return { value: v, done: v === 0 };
|
|
476
624
|
}).pipe(Machine.run((frame) => {
|
|
477
|
-
|
|
625
|
+
try {
|
|
626
|
+
registry.set(out, frame.value);
|
|
627
|
+
if (failing)
|
|
628
|
+
failing = false;
|
|
629
|
+
}
|
|
630
|
+
catch (defect) {
|
|
631
|
+
if (!failing)
|
|
632
|
+
Report.failureOn(context, DEPENDENT_FAILED, Cause.die(defect));
|
|
633
|
+
failing = true;
|
|
634
|
+
}
|
|
478
635
|
if (frame.done)
|
|
479
636
|
running = false;
|
|
480
637
|
return undefined;
|
|
481
|
-
}, { supersede: token }));
|
|
638
|
+
}, { supersede: token, onFrameTimeline: true }));
|
|
482
639
|
const follow = () => {
|
|
483
640
|
if (running)
|
|
484
641
|
return;
|
|
485
642
|
running = true;
|
|
643
|
+
seed = previous;
|
|
644
|
+
startedAt = loop.tickCount();
|
|
645
|
+
firstDue = true;
|
|
646
|
+
stepTick = -1;
|
|
486
647
|
run(program, { onlyIfMissing: true });
|
|
487
648
|
};
|
|
488
649
|
const unsubscribe = registry.subscribe(source, follow);
|
|
@@ -496,17 +657,23 @@ export const velocity = Effect.fnUntraced(function* (source) {
|
|
|
496
657
|
});
|
|
497
658
|
/**
|
|
498
659
|
* Milliseconds since it started, as Motion's `useTime`: wall time, minutes the app spent hidden included. It
|
|
499
|
-
* keeps the Clock ticking every frame while it runs; its run ends with the Scope.
|
|
660
|
+
* keeps the Clock ticking every frame while it runs; its run ends with the Scope. An Atom over it that
|
|
661
|
+
* throws doesn't stop it: that's logged once until it's written cleanly.
|
|
500
662
|
*
|
|
501
663
|
* @example
|
|
502
664
|
* const rotate = yield* LiveValue.transform(yield* LiveValue.time(), [0, 4000], [0, 360], { clamp: false })
|
|
503
665
|
*/
|
|
504
|
-
// A run on the Frame loop that never settles, adding each tick's `dt` as the Clock gives it, unclamped.
|
|
666
|
+
// A run on the Frame loop that never settles, adding each tick's `dt` as the Clock gives it, unclamped. On
|
|
667
|
+
// the frame timeline (#1046, ADR-0027 *Amendment (#1046)*): it reports the frames' time, so a late first frame's
|
|
668
|
+
// counts whole, where an animation made in a long task leaves it out.
|
|
505
669
|
export const time = Effect.fnUntraced(function* () {
|
|
506
670
|
const registry = yield* AtomRegistry.AtomRegistry;
|
|
507
671
|
const out = Atom.make(0);
|
|
508
672
|
const unmount = registry.mount(out);
|
|
509
673
|
const run = yield* FiberHandle.makeRuntime();
|
|
674
|
+
// Past a dependent that throws, it goes on counting, reported as follow's writes are (#979).
|
|
675
|
+
const context = yield* Effect.context();
|
|
676
|
+
let failing = false;
|
|
510
677
|
const token = Supersede.make();
|
|
511
678
|
const elapsed = numberMachine("wardic.time", false, () => {
|
|
512
679
|
let ms = 0;
|
|
@@ -516,9 +683,18 @@ export const time = Effect.fnUntraced(function* () {
|
|
|
516
683
|
};
|
|
517
684
|
});
|
|
518
685
|
run(elapsed.pipe(Machine.run((frame) => {
|
|
519
|
-
|
|
686
|
+
try {
|
|
687
|
+
registry.set(out, frame.value);
|
|
688
|
+
if (failing)
|
|
689
|
+
failing = false;
|
|
690
|
+
}
|
|
691
|
+
catch (defect) {
|
|
692
|
+
if (!failing)
|
|
693
|
+
Report.failureOn(context, DEPENDENT_FAILED, Cause.die(defect));
|
|
694
|
+
failing = true;
|
|
695
|
+
}
|
|
520
696
|
return undefined;
|
|
521
|
-
}, { supersede: token })));
|
|
697
|
+
}, { supersede: token, onFrameTimeline: true })));
|
|
522
698
|
yield* Effect.addFinalizer(() => Effect.sync(() => {
|
|
523
699
|
Supersede.end(token);
|
|
524
700
|
unmount();
|
|
@@ -542,7 +718,8 @@ const FRAME_DELTA = { minimum: 1, maximum: 40 };
|
|
|
542
718
|
* yield* LiveValue.eachFrame((time) => draw(context, time))
|
|
543
719
|
*/
|
|
544
720
|
// #443. A run's first frame after the Clock wakes is the Clock's nominal frame, 16.7 ms, as Motion's is.
|
|
545
|
-
// A throw is a run's defect (ADR-0027, decision 7).
|
|
721
|
+
// A throw is a run's defect (ADR-0027, decision 7). On the frame timeline (#1046): its time and delta are the
|
|
722
|
+
// frames' own, as Motion's `timestamp - initialTimestamp` is, a late frame's included.
|
|
546
723
|
export const eachFrame = Effect.fnUntraced(function* (callback) {
|
|
547
724
|
const run = yield* FiberHandle.makeRuntime();
|
|
548
725
|
const token = Supersede.make();
|
|
@@ -559,7 +736,7 @@ export const eachFrame = Effect.fnUntraced(function* (callback) {
|
|
|
559
736
|
return { value: ms, done: false };
|
|
560
737
|
};
|
|
561
738
|
});
|
|
562
|
-
run(frames.pipe(Machine.run(constUndefined, { supersede: token })));
|
|
739
|
+
run(frames.pipe(Machine.run(constUndefined, { supersede: token, onFrameTimeline: true })));
|
|
563
740
|
yield* Effect.addFinalizer(() => Effect.sync(() => Supersede.end(token)));
|
|
564
741
|
});
|
|
565
742
|
//# sourceMappingURL=LiveValue.js.map
|