@wardic/core 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BaseValue.d.ts +1 -1
- package/dist/BaseValue.js +2 -2
- package/dist/BaseValue.js.map +1 -1
- package/dist/Batch.d.ts +5 -9
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +166 -20
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +16 -0
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +13 -0
- package/dist/Clock.js.map +1 -1
- package/dist/DragRecognizer.d.ts +10 -5
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +60 -24
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/Frame.js +1 -1
- package/dist/Frame.js.map +1 -1
- package/dist/InputFeed.d.ts +10 -7
- package/dist/InputFeed.d.ts.map +1 -1
- package/dist/InputFeed.js +16 -35
- package/dist/InputFeed.js.map +1 -1
- package/dist/LiveValue.d.ts +9 -3
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +160 -14
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +16 -6
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +50 -27
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +10 -8
- package/dist/Playback.js.map +1 -1
- package/dist/Recognizer.d.ts +1 -1
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +9 -4
- package/dist/Recognizer.js.map +1 -1
- package/dist/internal/frameLoop.d.ts +10 -2
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +148 -18
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/guarded.d.ts +16 -0
- package/dist/internal/guarded.d.ts.map +1 -0
- package/dist/internal/guarded.js +68 -0
- package/dist/internal/guarded.js.map +1 -0
- package/dist/internal/stepper.d.ts +9 -3
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +5 -4
- package/dist/internal/stepper.js.map +1 -1
- package/dist/unstable/AnimationControls.d.ts +15 -8
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +36 -15
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +6 -0
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/AppearHandoff.js.map +1 -1
- package/dist/unstable/Config.d.ts +5 -1
- package/dist/unstable/Config.d.ts.map +1 -1
- package/dist/unstable/Config.js.map +1 -1
- package/dist/unstable/FlushGate.d.ts +4 -2
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +155 -38
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +4 -1
- package/dist/unstable/FrameEffects.d.ts.map +1 -1
- package/dist/unstable/FrameEffects.js +12 -1
- package/dist/unstable/FrameEffects.js.map +1 -1
- package/dist/unstable/Imperative.d.ts +13 -4
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +202 -43
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/MeasuredPairs.d.ts +6 -2
- package/dist/unstable/MeasuredPairs.d.ts.map +1 -1
- package/dist/unstable/MeasuredPairs.js.map +1 -1
- package/dist/unstable/PresenceRecord.d.ts +4 -0
- package/dist/unstable/PresenceRecord.d.ts.map +1 -1
- package/dist/unstable/PresenceRecord.js.map +1 -1
- package/dist/unstable/Report.d.ts +7 -0
- package/dist/unstable/Report.d.ts.map +1 -1
- package/dist/unstable/Report.js +17 -1
- package/dist/unstable/Report.js.map +1 -1
- package/dist/unstable/RetargetLegs.d.ts +6 -0
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +15 -0
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +53 -7
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +190 -40
- package/dist/unstable/Spine.js.map +1 -1
- package/dist/unstable/VariantTarget.d.ts +25 -3
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +66 -13
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +37 -3
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +54 -7
- package/dist/unstable/VariantTree.js.map +1 -1
- package/package.json +1 -1
- package/src/BaseValue.ts +2 -2
- package/src/Batch.ts +167 -17
- package/src/Clock.ts +20 -0
- package/src/DragRecognizer.ts +82 -30
- package/src/Frame.ts +1 -1
- package/src/InputFeed.ts +37 -40
- package/src/LiveValue.ts +140 -14
- package/src/Machine.ts +67 -34
- package/src/Playback.ts +10 -8
- package/src/Recognizer.ts +9 -3
- package/src/internal/frameLoop.ts +165 -19
- package/src/internal/guarded.ts +69 -0
- package/src/internal/stepper.ts +14 -5
- package/src/unstable/AnimationControls.ts +49 -21
- package/src/unstable/AppearHandoff.ts +7 -0
- package/src/unstable/Config.ts +7 -1
- package/src/unstable/FlushGate.ts +169 -37
- package/src/unstable/FrameEffects.ts +15 -2
- package/src/unstable/Imperative.ts +219 -48
- package/src/unstable/MeasuredPairs.ts +7 -1
- package/src/unstable/PresenceRecord.ts +4 -0
- package/src/unstable/Report.ts +19 -1
- package/src/unstable/RetargetLegs.ts +14 -0
- package/src/unstable/Spine.ts +235 -40
- package/src/unstable/VariantTarget.ts +93 -14
- package/src/unstable/VariantTree.ts +87 -6
package/src/LiveValue.ts
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
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"
|
|
@@ -40,6 +41,7 @@ import * as Machine from "./Machine.ts"
|
|
|
40
41
|
import * as ScrollSource from "./ScrollSource.ts"
|
|
41
42
|
import * as Supersede from "./Supersede.ts"
|
|
42
43
|
import { dual } from "./internal/dual.ts"
|
|
44
|
+
import * as Report from "./unstable/Report.ts"
|
|
43
45
|
|
|
44
46
|
/** A blend between two outputs, as Motion's `MixerFactory`: made once per stretch, then read at each progress through it, 0 to 1. */
|
|
45
47
|
// #440.
|
|
@@ -164,7 +166,8 @@ const interpolateWith: <O>(
|
|
|
164
166
|
|
|
165
167
|
/**
|
|
166
168
|
* `source` mapped through ranges, as `interpolate` maps a number: an Atom that follows `source`, mapped
|
|
167
|
-
* afresh at each change.
|
|
169
|
+
* afresh at each change. A `mixer` that throws keeps the value it gave last, and is logged once until it
|
|
170
|
+
* returns; one that throws for its first value throws to whatever reads it then.
|
|
168
171
|
*
|
|
169
172
|
* @example
|
|
170
173
|
* const scale = yield* LiveValue.transform(scrollY, [0, 300], [1, 0.8])
|
|
@@ -173,7 +176,28 @@ export const transform: {
|
|
|
173
176
|
<O extends number | string>(source: Atom.Atom<number>, input: ReadonlyArray<number>, output: ReadonlyArray<O>, options?: TransformOptions<O>): Effect.Effect<Atom.Atom<O>, never, InterpolatorRegistry.InterpolatorRegistry>
|
|
174
177
|
<O>(source: Atom.Atom<number>, input: ReadonlyArray<number>, output: ReadonlyArray<O>, options: MixedTransformOptions<O>): Effect.Effect<Atom.Atom<O>, never, InterpolatorRegistry.InterpolatorRegistry>
|
|
175
178
|
} = <O>(source: Atom.Atom<number>, input: ReadonlyArray<number>, output: ReadonlyArray<O>, options: TransformOptions<O> = {}) =>
|
|
176
|
-
Effect.
|
|
179
|
+
Effect.zipWith(interpolateWith(input, output, options), Effect.context<never>(), (map, context) => {
|
|
180
|
+
// An app's `mixer` that throws: its last value kept, reported at the first throw of a run of them, again
|
|
181
|
+
// after a clean one; with none yet to keep, its first value's throw is its reader's (#979). The try is in
|
|
182
|
+
// the read itself, around a direct call: a helper called from it measured a few points a change on Bun.
|
|
183
|
+
let last: O | undefined
|
|
184
|
+
let kept = false
|
|
185
|
+
let failing = false
|
|
186
|
+
const read = (get: Atom.AtomContext): O => {
|
|
187
|
+
const v = get(source)
|
|
188
|
+
try {
|
|
189
|
+
last = map(v)
|
|
190
|
+
kept = true
|
|
191
|
+
if (failing) failing = false
|
|
192
|
+
} catch (defect) {
|
|
193
|
+
if (!kept) throw defect
|
|
194
|
+
if (!failing) Report.failureOn(context, MIXER_FAILED, Cause.die(defect))
|
|
195
|
+
failing = true
|
|
196
|
+
}
|
|
197
|
+
return last as O
|
|
198
|
+
}
|
|
199
|
+
return transformedFrom(Atom.make(read), source, input, output, options)
|
|
200
|
+
})
|
|
177
201
|
|
|
178
202
|
/** `v`'s stretch, as Motion's: the first that ends above it, else the last. Read on each change of the source. */
|
|
179
203
|
const stretchAt = <O>(stretches: Arr.NonEmptyReadonlyArray<Stretch<O>>, v: number): Stretch<O> =>
|
|
@@ -377,6 +401,18 @@ const velocityOfFrame = (frame: Frame.Frame<number>): number => {
|
|
|
377
401
|
return velocity
|
|
378
402
|
}
|
|
379
403
|
|
|
404
|
+
// #979, group D (ADR-0074): a run goes on past an Atom over it, or under it, that throws, its failure
|
|
405
|
+
// reported on what it was built with (`Report.failureOn`), off the per-frame path.
|
|
406
|
+
|
|
407
|
+
/** A run's dependent that threw at its write: an app's Atom over its value, say. */
|
|
408
|
+
const DEPENDENT_FAILED = "wardic.liveValue: its dependent failed"
|
|
409
|
+
|
|
410
|
+
/** A run's source that threw as it was read: an app's Atom under it, say. */
|
|
411
|
+
const SOURCE_FAILED = "wardic.liveValue: its source failed"
|
|
412
|
+
|
|
413
|
+
/** A transform's ranges that threw: an app's `mixer`. */
|
|
414
|
+
const MIXER_FAILED = "wardic.transform: its mixer failed"
|
|
415
|
+
|
|
380
416
|
const FOLLOW_SPAN: Machine.Span = { name: "wardic.follow", attributes: {} }
|
|
381
417
|
|
|
382
418
|
/**
|
|
@@ -395,6 +431,9 @@ const FOLLOW_SPAN: Machine.Span = { name: "wardic.follow", attributes: {} }
|
|
|
395
431
|
* is a `jump`; with `skipAnimations`, or while `skipped()` says so, every change is. Its run and its
|
|
396
432
|
* subscription end with the Scope.
|
|
397
433
|
*
|
|
434
|
+
* A source that throws as it's read is followed to where it was last read, and an Atom over it that throws
|
|
435
|
+
* doesn't stop it: each is logged once until it reads, or is written, cleanly.
|
|
436
|
+
*
|
|
398
437
|
* @example
|
|
399
438
|
* const eased = yield* LiveValue.follow(target, { type: "tween", duration: 0.4, ease: "easeOut" })
|
|
400
439
|
*/
|
|
@@ -408,6 +447,7 @@ export const follow: (
|
|
|
408
447
|
) => Effect.Effect<Followed, never, FrameLoop.FrameLoop | AtomRegistry.AtomRegistry | Scope.Scope> = Effect.fnUntraced(
|
|
409
448
|
function* (source: Atom.Atom<number>, options: FollowOptions = {}, skipped: () => boolean = constFalse) {
|
|
410
449
|
const registry = yield* AtomRegistry.AtomRegistry
|
|
450
|
+
const context = yield* Effect.context<never>()
|
|
411
451
|
const { skipInitialAnimation, skipAnimations, ...transition } = options
|
|
412
452
|
const plan = planOf(transition as FollowTransition)
|
|
413
453
|
const skips = Bool.match(skipAnimations === true, { onTrue: () => constTrue, onFalse: () => skipped })
|
|
@@ -423,7 +463,22 @@ export const follow: (
|
|
|
423
463
|
let changed = false
|
|
424
464
|
// Whether the source's next change is a jump: its first, with `skipInitialAnimation`.
|
|
425
465
|
let skipping = skipInitialAnimation === true
|
|
426
|
-
|
|
466
|
+
// A source that throws (an app's Atom under it): a run steering toward it keeps its last read,
|
|
467
|
+
// reported at the first throw of a run of them, again after a clean read (#979).
|
|
468
|
+
let lastTarget = registry.get(out)
|
|
469
|
+
let sourceFailing = false
|
|
470
|
+
const target = (): number => {
|
|
471
|
+
try {
|
|
472
|
+
lastTarget = registry.get(source)
|
|
473
|
+
if (sourceFailing) sourceFailing = false
|
|
474
|
+
} catch (defect) {
|
|
475
|
+
if (!sourceFailing) Report.failureOn(context, SOURCE_FAILED, Cause.die(defect))
|
|
476
|
+
sourceFailing = true
|
|
477
|
+
}
|
|
478
|
+
return lastTarget
|
|
479
|
+
}
|
|
480
|
+
// Whether its writes are throwing back a dependent's failure, reported as the source's are.
|
|
481
|
+
let failing = false
|
|
427
482
|
/** One run: the plan's, from where `out` is, started again from where it's reached at the step after a change. */
|
|
428
483
|
const machine = Machine.make({
|
|
429
484
|
settles: false,
|
|
@@ -464,7 +519,15 @@ export const follow: (
|
|
|
464
519
|
machine.pipe(
|
|
465
520
|
Machine.run(
|
|
466
521
|
(frame) => {
|
|
467
|
-
registry
|
|
522
|
+
// Per frame, a try around the direct call: the registry has set it and told its other
|
|
523
|
+
// listeners before a dependent's throw comes back (an app's Atom over it), so the run goes on.
|
|
524
|
+
try {
|
|
525
|
+
registry.set(out, frame.value)
|
|
526
|
+
if (failing) failing = false
|
|
527
|
+
} catch (defect) {
|
|
528
|
+
if (!failing) Report.failureOn(context, DEPENDENT_FAILED, Cause.die(defect))
|
|
529
|
+
failing = true
|
|
530
|
+
}
|
|
468
531
|
velocity = velocityOfFrame(frame)
|
|
469
532
|
// At rest on the source: end the run; the next change starts another.
|
|
470
533
|
if (frame.done) {
|
|
@@ -681,14 +744,18 @@ const numberMachine = (name: string, settles: boolean, start: () => (dt: number)
|
|
|
681
744
|
* How fast `source` is changing, in its units a second, as Motion's `useVelocity`: 0 to begin with, and
|
|
682
745
|
* from each change on, each frame's change over the frame's time, until a frame finds no change, sets 0
|
|
683
746
|
* and stops. Nothing runs while the source rests. A velocity is a value too: `velocity(velocity(x))` is
|
|
684
|
-
* acceleration. Its run ends with the Scope.
|
|
747
|
+
* acceleration. Its run ends with the Scope. A source that throws as it's read reads as still, and an Atom
|
|
748
|
+
* over it that throws doesn't stop it: each is logged once until it reads, or is written, cleanly.
|
|
685
749
|
*
|
|
686
750
|
* @example
|
|
687
751
|
* const speed = yield* LiveValue.velocity(scrollY)
|
|
688
752
|
*/
|
|
689
|
-
// Each tick's `dt` is clamped at `Machine.MAX_DT`, as every run's is.
|
|
690
|
-
// read by an `afterTick` hook, not the run's own last read: a run started inside a
|
|
691
|
-
// step
|
|
753
|
+
// Each tick's `dt` is clamped at `Machine.MAX_DT`, as every run's is. A step reads the change "since the end
|
|
754
|
+
// of the tick before", read by an `afterTick` hook, not the run's own last read: a run started inside a
|
|
755
|
+
// tick whose Late step doesn't come (back-to-back frames, or past the Late rounds) takes its first step at
|
|
756
|
+
// the next tick, and would otherwise count two frames' change over one `dt`. Its Late step, at the loop's
|
|
757
|
+
// tick count it started at, reads from the source before the change that started it, since the tick's hook
|
|
758
|
+
// has read past that change by then (#991, ADR-0043 *Amendment (#991)*).
|
|
692
759
|
export const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<number>, never, FrameLoop.FrameLoop | AtomRegistry.AtomRegistry | Scope.Scope> = Effect.fnUntraced(
|
|
693
760
|
function* (source: Atom.Atom<number>) {
|
|
694
761
|
const registry = yield* AtomRegistry.AtomRegistry
|
|
@@ -696,30 +763,76 @@ export const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<nu
|
|
|
696
763
|
const out = Atom.make(0)
|
|
697
764
|
const unmount = registry.mount(out)
|
|
698
765
|
const run = yield* FiberHandle.makeRuntime<FrameLoop.FrameLoop, never, unknown>()
|
|
699
|
-
|
|
766
|
+
const context = yield* Effect.context<never>()
|
|
767
|
+
// A source that throws (an app's Atom under it) reads as still, its last read kept, reported at the
|
|
768
|
+
// first throw of a run of them, again after a clean read; its writes as follow's are (#979).
|
|
769
|
+
// Each read's try is written where it reads, around a direct call: a reader called from both measured
|
|
770
|
+
// +16% on Bun's velocity frame. A flag is cleared only when it's set: a check on the clean path.
|
|
771
|
+
let sourceFailing = false
|
|
772
|
+
let failing = false
|
|
773
|
+
// The source at the end of the tick before: where each tick's change is read from. A read that throws
|
|
774
|
+
// keeps it.
|
|
700
775
|
let previous = registry.get(source)
|
|
776
|
+
// A run's start (#991): the source from before the change that started it, the loop's tick count then,
|
|
777
|
+
// and whether its first step is still due (only that step can be its Late step).
|
|
778
|
+
let seed = previous
|
|
779
|
+
let startedAt = 0
|
|
780
|
+
let firstDue = false
|
|
701
781
|
const loop = yield* FrameLoop.FrameLoop
|
|
702
782
|
yield* loop.afterTick(() => {
|
|
703
|
-
|
|
783
|
+
try {
|
|
784
|
+
previous = registry.get(source)
|
|
785
|
+
if (sourceFailing) sourceFailing = false
|
|
786
|
+
} catch (defect) {
|
|
787
|
+
if (!sourceFailing) Report.failureOn(context, SOURCE_FAILED, Cause.die(defect))
|
|
788
|
+
sourceFailing = true
|
|
789
|
+
}
|
|
704
790
|
return undefined
|
|
705
791
|
})
|
|
706
792
|
// A jump of the source isn't motion: the change is read from where it jumped to.
|
|
707
793
|
const unhear = onJump(registry, source, (value) => {
|
|
708
794
|
previous = value
|
|
795
|
+
seed = value
|
|
709
796
|
})
|
|
710
797
|
// One token for its lifetime, and one run program, started afresh on the change after a rest:
|
|
711
798
|
// a change while a run goes costs a check, nothing built.
|
|
712
799
|
const token = Supersede.make()
|
|
713
800
|
let running = false
|
|
801
|
+
// Where a run's first step reads its change from, clearing its due flag: its Late step, at the tick
|
|
802
|
+
// count it started at, from the source before the change that started it (the tick's hook has moved
|
|
803
|
+
// `previous` past it); one at a later tick, from the end of the tick before, as every later step does.
|
|
804
|
+
const takeFirstFrom = (): number => {
|
|
805
|
+
firstDue = false
|
|
806
|
+
if (loop.tickCount() === startedAt) return seed
|
|
807
|
+
return previous
|
|
808
|
+
}
|
|
714
809
|
const program = numberMachine("wardic.velocity", true, () => (dt) => {
|
|
715
810
|
const step = Math.min(dt, Machine.MAX_DT)
|
|
716
811
|
// A tick in no time (never from the Clock) reads as still.
|
|
717
812
|
if (step === 0) return { value: 0, done: true }
|
|
718
|
-
|
|
813
|
+
// A check on every later step: the first's alone reads the tick count (#991).
|
|
814
|
+
let before = previous
|
|
815
|
+
if (firstDue) before = takeFirstFrom()
|
|
816
|
+
// A read that throws reads as still.
|
|
817
|
+
let now = before
|
|
818
|
+
try {
|
|
819
|
+
now = registry.get(source)
|
|
820
|
+
if (sourceFailing) sourceFailing = false
|
|
821
|
+
} catch (defect) {
|
|
822
|
+
if (!sourceFailing) Report.failureOn(context, SOURCE_FAILED, Cause.die(defect))
|
|
823
|
+
sourceFailing = true
|
|
824
|
+
}
|
|
825
|
+
const v = (now - before) / step
|
|
719
826
|
return { value: v, done: v === 0 }
|
|
720
827
|
}).pipe(
|
|
721
828
|
Machine.run((frame) => {
|
|
722
|
-
|
|
829
|
+
try {
|
|
830
|
+
registry.set(out, frame.value)
|
|
831
|
+
if (failing) failing = false
|
|
832
|
+
} catch (defect) {
|
|
833
|
+
if (!failing) Report.failureOn(context, DEPENDENT_FAILED, Cause.die(defect))
|
|
834
|
+
failing = true
|
|
835
|
+
}
|
|
723
836
|
if (frame.done) running = false
|
|
724
837
|
return undefined
|
|
725
838
|
}, { supersede: token }),
|
|
@@ -727,6 +840,9 @@ export const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<nu
|
|
|
727
840
|
const follow = (): void => {
|
|
728
841
|
if (running) return
|
|
729
842
|
running = true
|
|
843
|
+
seed = previous
|
|
844
|
+
startedAt = loop.tickCount()
|
|
845
|
+
firstDue = true
|
|
730
846
|
run(program, { onlyIfMissing: true })
|
|
731
847
|
}
|
|
732
848
|
const unsubscribe = registry.subscribe(source, follow)
|
|
@@ -742,7 +858,8 @@ export const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<nu
|
|
|
742
858
|
|
|
743
859
|
/**
|
|
744
860
|
* Milliseconds since it started, as Motion's `useTime`: wall time, minutes the app spent hidden included. It
|
|
745
|
-
* keeps the Clock ticking every frame while it runs; its run ends with the Scope.
|
|
861
|
+
* keeps the Clock ticking every frame while it runs; its run ends with the Scope. An Atom over it that
|
|
862
|
+
* throws doesn't stop it: that's logged once until it's written cleanly.
|
|
746
863
|
*
|
|
747
864
|
* @example
|
|
748
865
|
* const rotate = yield* LiveValue.transform(yield* LiveValue.time(), [0, 4000], [0, 360], { clamp: false })
|
|
@@ -754,6 +871,9 @@ export const time: () => Effect.Effect<Atom.Atom<number>, never, FrameLoop.Frame
|
|
|
754
871
|
const out = Atom.make(0)
|
|
755
872
|
const unmount = registry.mount(out)
|
|
756
873
|
const run = yield* FiberHandle.makeRuntime<FrameLoop.FrameLoop, never, unknown>()
|
|
874
|
+
// Past a dependent that throws, it goes on counting, reported as follow's writes are (#979).
|
|
875
|
+
const context = yield* Effect.context<never>()
|
|
876
|
+
let failing = false
|
|
757
877
|
const token = Supersede.make()
|
|
758
878
|
const elapsed = numberMachine("wardic.time", false, () => {
|
|
759
879
|
let ms = 0
|
|
@@ -765,7 +885,13 @@ export const time: () => Effect.Effect<Atom.Atom<number>, never, FrameLoop.Frame
|
|
|
765
885
|
run(
|
|
766
886
|
elapsed.pipe(
|
|
767
887
|
Machine.run((frame) => {
|
|
768
|
-
|
|
888
|
+
try {
|
|
889
|
+
registry.set(out, frame.value)
|
|
890
|
+
if (failing) failing = false
|
|
891
|
+
} catch (defect) {
|
|
892
|
+
if (!failing) Report.failureOn(context, DEPENDENT_FAILED, Cause.die(defect))
|
|
893
|
+
failing = true
|
|
894
|
+
}
|
|
769
895
|
return undefined
|
|
770
896
|
}, { supersede: token }),
|
|
771
897
|
),
|
package/src/Machine.ts
CHANGED
|
@@ -70,6 +70,7 @@ import {
|
|
|
70
70
|
stopTimesOf,
|
|
71
71
|
timeIn,
|
|
72
72
|
stepTween,
|
|
73
|
+
type WritableFrame,
|
|
73
74
|
TweenFields,
|
|
74
75
|
} from "./internal/stepper.ts"
|
|
75
76
|
import * as Inertia from "./Inertia.ts"
|
|
@@ -95,7 +96,8 @@ export interface Machine<out F extends Frame.Frame<unknown>> extends Pipeable, I
|
|
|
95
96
|
readonly [TypeId]: { readonly _F: Covariant<F> }
|
|
96
97
|
/**
|
|
97
98
|
* 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.
|
|
99
|
+
* Frame. Each run holds its own state, so a machine can be started any number of times. A Frame
|
|
100
|
+
* is the run's until its next step, which may rewrite it in place: copy one to keep it.
|
|
99
101
|
*/
|
|
100
102
|
readonly start: () => (dt: number) => F
|
|
101
103
|
/**
|
|
@@ -729,13 +731,12 @@ const isMultiPhysics = (frame: Frame.Frame<unknown>): frame is Frame.MultiPhysic
|
|
|
729
731
|
Predicate.isObject((frame as Frame.MultiPhysics).velocity)
|
|
730
732
|
|
|
731
733
|
/**
|
|
732
|
-
* A Frame its Stream consumer owns
|
|
733
|
-
*
|
|
734
|
-
*
|
|
735
|
-
* per-frame path (ADR-0025): statement `if`s and plain calls.
|
|
734
|
+
* A Frame its Stream consumer owns, copied, since a step may rewrite it in place: a record `value`, and
|
|
735
|
+
* a record `velocity` beside it (`springValues`, ADR-0030 decision 11), and any other Frame whole (a
|
|
736
|
+
* tween's, ADR-0030 *Amendment (#895)*). On the per-frame path (ADR-0025): statement `if`s and plain calls.
|
|
736
737
|
*/
|
|
737
738
|
const owned = <F extends Frame.Frame<unknown>>(frame: F): F => {
|
|
738
|
-
if (!Predicate.isObject(frame.value)) return frame
|
|
739
|
+
if (!Predicate.isObject(frame.value)) return { ...frame }
|
|
739
740
|
if (isMultiPhysics(frame)) {
|
|
740
741
|
// A `springValues` Frame's arrays are its run's, rewritten each tick: its copy is its records alone (#663).
|
|
741
742
|
if (Frame.isSpringValues(frame)) return { value: { ...frame.value }, velocity: { ...frame.velocity }, done: frame.done } as unknown as F
|
|
@@ -759,8 +760,8 @@ export type Streamed<F> = F extends Frame.SpringValues ? Frame.MultiPhysics : F
|
|
|
759
760
|
* yield* Machine.toStream(fadeIn).pipe(Stream.runForEach((frame) => Effect.sync(() => draw(frame.value))))
|
|
760
761
|
*/
|
|
761
762
|
// 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
|
|
763
|
+
// with its attributes; per-frame work is unlogged. Every Frame is copied (`owned`) before it's
|
|
764
|
+
// emitted, so a consumer that collects Frames never sees one rewritten (ADR-0030, decision 11; #895). A
|
|
764
765
|
// Stream, not a Channel: measured 2026-11-02, Stream's own layers were ~5% of a pull of the Clock's
|
|
765
766
|
// ticks, and elements never use `toStream`, so a Channel would gain nothing measurable (#618, M5).
|
|
766
767
|
export const toStream = <F extends Frame.Frame<unknown>>(self: Machine<F>): Stream.Stream<Streamed<F>, never, Clock.Clock> =>
|
|
@@ -793,8 +794,8 @@ export const toStream = <F extends Frame.Frame<unknown>>(self: Machine<F>): Stre
|
|
|
793
794
|
// A plain call, typed `(frame) => undefined`, so a sink that returns an Effect doesn't compile
|
|
794
795
|
// (ADR-0027, decision 8). Dies if the step or the sink throws, or with the loop's own failure. One span
|
|
795
796
|
// 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))`.
|
|
797
|
+
// loop at once, as an interrupted run does, about a sixth of the cost. `springValues`, a tween and the
|
|
798
|
+
// blends rewrite one Frame per run (ADR-0030, decision 11 and *Amendment (#895)*). A machine built with a service: `Effect.flatMap(Machine.run(sink))`.
|
|
798
799
|
export const run: {
|
|
799
800
|
<F extends Frame.Frame<unknown>>(sink: FrameLoop.Sink<F>): (self: Machine<F>) => Effect.Effect<F, never, FrameLoop.FrameLoop>
|
|
800
801
|
<F extends Frame.Frame<unknown>>(
|
|
@@ -814,26 +815,34 @@ export const run: {
|
|
|
814
815
|
FrameLoop.FrameLoop.use((loop) => loop.run(self, sink, options as RunOptions)),
|
|
815
816
|
)
|
|
816
817
|
|
|
817
|
-
/**
|
|
818
|
-
|
|
818
|
+
/**
|
|
819
|
+
* `run`'s options: the token the run joins, so `Supersede.end` ends it with the others; and whether the
|
|
820
|
+
* run keeps the frame timeline's time, its start read from it (an Appear animation's `currentTime`), so
|
|
821
|
+
* the Frame loop never leaves a late frame's time out of its first steps (`Clock.LateFrames`).
|
|
822
|
+
*/
|
|
823
|
+
// #200; #1026: a run on wall time (a video's `currentTime`, `performance.now()`) leaves `onFrameTimeline`
|
|
824
|
+
// out, and is right that way.
|
|
819
825
|
export interface RunOptions {
|
|
820
|
-
readonly supersede
|
|
826
|
+
readonly supersede?: Supersede.Supersede | undefined
|
|
827
|
+
readonly onFrameTimeline?: boolean | undefined
|
|
821
828
|
}
|
|
822
829
|
|
|
823
830
|
// --- The leaves --------------------------------------------------------------
|
|
824
831
|
|
|
825
832
|
/** A tween's step from 0 elapsed: `tween`'s, and each of `animate`'s and `keyframes`' Intervals. */
|
|
833
|
+
// In place (#895, ADR-0030 *Amendment (#895)*): its time and its Frame are its run's, made at `start()` and
|
|
834
|
+
// rewritten each tick, as `springValues`' are (decision 11); `toStream` copies what it emits.
|
|
826
835
|
const tweenLeaf = (from: number, to: number, tween: ResolvedTween, span: Span): Machine<Frame.Frame<number>> =>
|
|
827
836
|
make({
|
|
828
837
|
settles: true,
|
|
829
838
|
span,
|
|
830
839
|
start: () => {
|
|
831
|
-
|
|
840
|
+
const state = initTween()
|
|
841
|
+
const frame: WritableFrame<number> = { value: from, done: false }
|
|
832
842
|
// Per frame (ADR-0025): the tween resolved when the machine is built, `dt` clamped (#78).
|
|
833
843
|
return (dt) => {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
return { value: result.value, done: result.done }
|
|
844
|
+
stepTween(state, frame, Math.min(dt, MAX_DT), from, to, tween)
|
|
845
|
+
return frame
|
|
837
846
|
}
|
|
838
847
|
},
|
|
839
848
|
})
|
|
@@ -845,7 +854,8 @@ const tweenSpan = (from: number, to: number, duration: number): Span => ({
|
|
|
845
854
|
})
|
|
846
855
|
|
|
847
856
|
/**
|
|
848
|
-
* A tween from `from` to `to` over `options.duration`, eased by its `ease`, after its `delay`.
|
|
857
|
+
* A tween from `from` to `to` over `options.duration`, eased by its `ease`, after its `delay`. Its Frame is
|
|
858
|
+
* the run's, rewritten every tick: copy one to keep it.
|
|
849
859
|
*
|
|
850
860
|
* @example
|
|
851
861
|
* const slide = Machine.tween(0, 240, { duration: 0.4, ease: "easeInOut" })
|
|
@@ -1369,6 +1379,7 @@ const resolveAnimate: (options: AnimateOptions) => ResolvedAnimate = cachedResol
|
|
|
1369
1379
|
* `"mirror"`), and `reverse` swaps its ends. `delay` holds once, before the first play, as Motion's
|
|
1370
1380
|
* does, and `repeatDelay` after each play but the last, where it ended. Each play starts the moment the
|
|
1371
1381
|
* one before ends; a finite `repeat` settles once the last ends, and `repeat: Infinity` never settles.
|
|
1382
|
+
* Its Frame may be the run's, rewritten every tick: copy one to keep it.
|
|
1372
1383
|
*
|
|
1373
1384
|
* @example
|
|
1374
1385
|
* const breathe = Machine.animate(1, 1.08, { duration: 1.2, ease: "easeInOut", repeat: Infinity, repeatType: "mirror" })
|
|
@@ -1509,26 +1520,48 @@ const blenderFor = (registry: InterpolatorRegistry.InterpolatorRegistry["Service
|
|
|
1509
1520
|
Option.getOrElse(registry.keyBlendOf(key, a, b), () => Effect.map(registry.resolve(a, b), (blend): Blender => (t) => blend(t)))
|
|
1510
1521
|
|
|
1511
1522
|
/**
|
|
1512
|
-
*
|
|
1513
|
-
* `[key, blender]` pairs built with the machine, not `Rec.map`, which spreads the
|
|
1514
|
-
* reassigns every key (#63 measured `Rec.map` 1.6× this loop in Chromium, 2.3× in JSC).
|
|
1523
|
+
* `progress`'s run with every key blended at the progress `at` reads off its Frame. On the per-frame path
|
|
1524
|
+
* (ADR-0025): a loop over the `[key, blender]` pairs built with the machine, not `Rec.map`, which spreads the
|
|
1525
|
+
* record and then reassigns every key (#63 measured `Rec.map` 1.6× this loop in Chromium, 2.3× in JSC).
|
|
1515
1526
|
*/
|
|
1516
|
-
|
|
1527
|
+
// In place (#895, ADR-0030 *Amendment (#895)*): its record and its Frame are its run's, made at `start()` and
|
|
1528
|
+
// rewritten each tick, as `springValues`' are (decision 11); `toStream` copies what it emits.
|
|
1529
|
+
const blendedBy = <F extends Frame.Frame<unknown>>(
|
|
1530
|
+
progress: Machine<F>,
|
|
1517
1531
|
blenders: ReadonlyArray<readonly [key: string, blend: Blender]>,
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1532
|
+
at: (frame: F) => number,
|
|
1533
|
+
): Machine<Frame.Frame<Values.Values>> =>
|
|
1534
|
+
make({
|
|
1535
|
+
settles: progress.settles,
|
|
1536
|
+
span: progress.span,
|
|
1537
|
+
start: () => {
|
|
1538
|
+
const step = progress.start()
|
|
1539
|
+
const frame: WritableFrame<Record<string, number | string>> = { value: {}, done: false }
|
|
1540
|
+
return (dt) => {
|
|
1541
|
+
const stepped = step(dt)
|
|
1542
|
+
const t = at(stepped)
|
|
1543
|
+
const done = stepped.done
|
|
1544
|
+
const value = frame.value
|
|
1545
|
+
for (const pair of blenders) value[pair[0]] = pair[1](t, done)
|
|
1546
|
+
frame.done = done
|
|
1547
|
+
return frame
|
|
1548
|
+
}
|
|
1549
|
+
},
|
|
1550
|
+
})
|
|
1551
|
+
|
|
1552
|
+
/** A tween's progress, 0 to 1. */
|
|
1553
|
+
const tweenProgressOf = (frame: Frame.Frame<number>): number => frame.value
|
|
1554
|
+
|
|
1555
|
+
/** A progress spring's progress, 0 to 1 from its 0 to 100 (#663: its one key by index). */
|
|
1556
|
+
const springProgressOf = (frame: Frame.SpringValues): number => frame.positions[0] / 100
|
|
1525
1557
|
|
|
1526
1558
|
/**
|
|
1527
1559
|
* A bag of values tweened from `from` to `to`, each key blended as its Environment blends it: numbers,
|
|
1528
1560
|
* unit strings, complex values, and its own kinds, such as `@wardic/dom`'s colours. One tween drives every
|
|
1529
1561
|
* key, so the repeats and `delay` apply to the whole bag. A pair that can't blend switches at the first
|
|
1530
1562
|
* frame; the Environment can hold a key until the last, as `@wardic/dom` does a key that hides an element.
|
|
1531
|
-
* Building it needs the `InterpolatorRegistry`, once.
|
|
1563
|
+
* Building it needs the `InterpolatorRegistry`, once. Its Frame and its record are the run's, rewritten
|
|
1564
|
+
* every tick: copy one to keep it.
|
|
1532
1565
|
*
|
|
1533
1566
|
* @example
|
|
1534
1567
|
* const fade = yield* Machine.animateValues({ opacity: 0, color: "#bf616a" }, { opacity: 1, color: "#a3be8c" }, { duration: 0.3 })
|
|
@@ -1544,7 +1577,7 @@ export const animateValues = (
|
|
|
1544
1577
|
// Per leg (#460): the combinators called data-first.
|
|
1545
1578
|
Effect.map(blendersFor(from, to), (blenders) =>
|
|
1546
1579
|
withSpan(
|
|
1547
|
-
|
|
1580
|
+
blendedBy(animate(0, 1, options), blenders, tweenProgressOf),
|
|
1548
1581
|
"wardic.animateValues",
|
|
1549
1582
|
{ attributes: { keys: blenders.length } },
|
|
1550
1583
|
))
|
|
@@ -1552,7 +1585,8 @@ export const animateValues = (
|
|
|
1552
1585
|
/**
|
|
1553
1586
|
* A bag of values blended from `from` to `to` by one spring's progress: the spring runs from rest on a
|
|
1554
1587
|
* 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.
|
|
1588
|
+
* aren't numbers, a colour or a unit string, as Motion's spring does. Its Frame and its record are the
|
|
1589
|
+
* run's, rewritten every tick: copy one to keep it.
|
|
1556
1590
|
*
|
|
1557
1591
|
* - **The progress spans 0 to 100**, as a number going 100 would, so `restDelta` and `restSpeed` mean
|
|
1558
1592
|
* the same for both, and a string key beside an `x` going 0 to 100 lands with it.
|
|
@@ -1572,8 +1606,7 @@ export const springBlend = (
|
|
|
1572
1606
|
Effect.map(blendersFor(from, to), (blenders) =>
|
|
1573
1607
|
withSpan(
|
|
1574
1608
|
// Its one key read by index (#663).
|
|
1575
|
-
|
|
1576
|
-
blendAt(blenders, frame.positions[0] / 100, frame.done)),
|
|
1609
|
+
blendedBy(springValues({ progress: 100 }, options, { from: { progress: 0 }, velocity: { progress: 0 }, records: "value" }), blenders, springProgressOf),
|
|
1577
1610
|
"wardic.springBlend",
|
|
1578
1611
|
{ attributes: { keys: blenders.length } },
|
|
1579
1612
|
))
|
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) {
|
|
@@ -149,16 +151,16 @@ export const drive: {
|
|
|
149
151
|
held = undefined
|
|
150
152
|
const by = tickOf(head, dt, Machine.MAX_DT)
|
|
151
153
|
if (by >= 0) {
|
|
152
|
-
time += by
|
|
153
|
-
writable.time = time
|
|
154
|
+
own.time += by
|
|
155
|
+
writable.time = own.time
|
|
154
156
|
last = step(by)
|
|
155
157
|
return last
|
|
156
158
|
}
|
|
157
|
-
time = Math.max(0, time + by)
|
|
158
|
-
writable.time = time
|
|
159
|
-
step = runFrom(self, time)
|
|
159
|
+
own.time = Math.max(0, own.time + by)
|
|
160
|
+
writable.time = own.time
|
|
161
|
+
step = runFrom(self, own.time)
|
|
160
162
|
last = step(0)
|
|
161
|
-
if (time === 0) return settled(last)
|
|
163
|
+
if (own.time === 0) return settled(last)
|
|
162
164
|
return last
|
|
163
165
|
}
|
|
164
166
|
},
|
package/src/Recognizer.ts
CHANGED
|
@@ -32,6 +32,7 @@ import * as InputFeed from "./InputFeed.ts"
|
|
|
32
32
|
import * as InputSource from "./InputSource.ts"
|
|
33
33
|
import * as PressClaims from "./PressClaims.ts"
|
|
34
34
|
import * as Probe from "./Probe.ts"
|
|
35
|
+
import { contextFor, switchedOn } from "./internal/guarded.ts"
|
|
35
36
|
import { tracedScoped } from "./internal/tracing.ts"
|
|
36
37
|
import { amongFeed, streamOf, watchFeed } from "./internal/watch.ts"
|
|
37
38
|
import type { AmongHandlers } from "./internal/watch.ts"
|
|
@@ -187,7 +188,7 @@ export interface HoverHandlers extends InputFeed.Handlers<Edge> {
|
|
|
187
188
|
/**
|
|
188
189
|
* Watches hover on `target` while the Scope is open: `handlers.on` hears each start and end, as
|
|
189
190
|
* `hoverEvents` tells them, and `handlers.onMove` each move over it while the hover is on, inside the
|
|
190
|
-
* pointer event's dispatch. A
|
|
191
|
+
* pointer event's dispatch. A run of throws from either goes to `handlers.onDefect` at its first.
|
|
191
192
|
*
|
|
192
193
|
* @example
|
|
193
194
|
* yield* Recognizer.watchHover(card, {
|
|
@@ -560,6 +561,8 @@ export const watchPress: (
|
|
|
560
561
|
if (told.phase === "start") claims.mark(event, target, Bool.not(propagates()))
|
|
561
562
|
}
|
|
562
563
|
const focusWithin = input.focusWithin
|
|
564
|
+
// What its keys' switch reports a throw on with no `onDefect` (#979, row 27): this watch's context.
|
|
565
|
+
const context = yield* contextFor(handlers.onDefect)
|
|
563
566
|
const state = MutableRef.make(noPress)
|
|
564
567
|
const feeds = MutableRef.make(feedsWatched(keys, Predicate.isNotUndefined(focusWithin)))
|
|
565
568
|
// The keys while focus is within the target (#460): made at the first focus, let go with the watches.
|
|
@@ -601,7 +604,7 @@ export const watchPress: (
|
|
|
601
604
|
}
|
|
602
605
|
// Keys only while focus is within the target (#460), from a focus, or from now when it already is.
|
|
603
606
|
const openKeys = (): void => {
|
|
604
|
-
if (Predicate.isUndefined(keysNow)) keysNow =
|
|
607
|
+
if (Predicate.isUndefined(keysNow)) keysNow = switchedOn(input.keyboard(target), onKey(), handlers.onDefect, context)
|
|
605
608
|
keysNow.open()
|
|
606
609
|
}
|
|
607
610
|
const blurs = onFocus()
|
|
@@ -660,6 +663,8 @@ export const watchPressAmong: (
|
|
|
660
663
|
const pointer = yield* amongFeed(input.pointerAmong, "pointerAmong")
|
|
661
664
|
const focusAmong = input.focusAmong
|
|
662
665
|
const keys = Bool.and(keysPressOf(options), Predicate.isNotUndefined(focusAmong))
|
|
666
|
+
// What each target's keys report a throw on with no `onDefect` (#979, row 27): this watch's context.
|
|
667
|
+
const context = yield* contextFor(handlers.onDefect)
|
|
663
668
|
const keyed = whileKeysOn(keysOnOf(options))
|
|
664
669
|
const propagates = propagatesOf(options)
|
|
665
670
|
// Each target with a press held, and each focused target's keys.
|
|
@@ -709,13 +714,14 @@ export const watchPressAmong: (
|
|
|
709
714
|
marking(event, told)
|
|
710
715
|
takeSpace(event, told)
|
|
711
716
|
}
|
|
712
|
-
const keysNow =
|
|
717
|
+
const keysNow = switchedOn(
|
|
713
718
|
input.keyboard(target),
|
|
714
719
|
keyed((event) => {
|
|
715
720
|
stepOn(target, event, keyStep(activity, claims, target), keyPressOf, keyTaken)
|
|
716
721
|
return true
|
|
717
722
|
}),
|
|
718
723
|
handlers.onDefect,
|
|
724
|
+
context,
|
|
719
725
|
)
|
|
720
726
|
keysOf.set(target, keysNow)
|
|
721
727
|
keysNow.open()
|