@wardic/core 1.3.2 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Arc.d.ts +2 -2
- package/dist/Arc.js +1 -1
- package/dist/BaseValue.d.ts +11 -10
- package/dist/BaseValue.d.ts.map +1 -1
- package/dist/BaseValue.js +12 -15
- package/dist/BaseValue.js.map +1 -1
- package/dist/Batch.d.ts +15 -5
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +218 -20
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +7 -7
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +17 -16
- package/dist/Clock.js.map +1 -1
- package/dist/DefaultTransition.d.ts +3 -2
- package/dist/DefaultTransition.d.ts.map +1 -1
- package/dist/DefaultTransition.js +5 -3
- package/dist/DefaultTransition.js.map +1 -1
- package/dist/Drag.d.ts +24 -9
- package/dist/Drag.d.ts.map +1 -1
- package/dist/Drag.js +10 -10
- package/dist/Drag.js.map +1 -1
- package/dist/DragActivity.js +3 -3
- package/dist/DragRecognizer.d.ts +5 -4
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +37 -14
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/Easing.d.ts +1 -1
- package/dist/Easing.js +1 -1
- package/dist/Frame.d.ts.map +1 -1
- package/dist/Frame.js +5 -3
- package/dist/Frame.js.map +1 -1
- package/dist/InputFeed.d.ts +1 -1
- package/dist/InputFeed.js +2 -2
- package/dist/InputSource.d.ts +3 -3
- package/dist/InputSource.js +2 -2
- package/dist/Interpolator.d.ts +2 -2
- package/dist/Interpolator.js +2 -2
- package/dist/InterpolatorRegistry.d.ts +29 -15
- package/dist/InterpolatorRegistry.d.ts.map +1 -1
- package/dist/InterpolatorRegistry.js +17 -8
- package/dist/InterpolatorRegistry.js.map +1 -1
- package/dist/LiveValue.d.ts +7 -6
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +45 -14
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +7 -4
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +146 -45
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +6 -1
- package/dist/Playback.js.map +1 -1
- package/dist/Projection.d.ts +9 -9
- package/dist/Projection.js +2 -2
- package/dist/Recognizer.d.ts +4 -3
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +49 -20
- package/dist/Recognizer.js.map +1 -1
- package/dist/ReducedMotion.d.ts +4 -4
- package/dist/ReducedMotion.js +6 -6
- package/dist/Renderer.d.ts +5 -5
- package/dist/Renderer.js +6 -6
- package/dist/Renderer.js.map +1 -1
- package/dist/Reorder.d.ts +1 -1
- package/dist/Reorder.d.ts.map +1 -1
- package/dist/Reorder.js +2 -1
- package/dist/Reorder.js.map +1 -1
- package/dist/ScrollSource.d.ts +1 -1
- package/dist/ScrollSource.d.ts.map +1 -1
- package/dist/Sequence.d.ts +1 -1
- package/dist/SharedSource.d.ts +3 -3
- package/dist/SharedSource.js +5 -5
- package/dist/SharedSource.js.map +1 -1
- package/dist/Spring.d.ts.map +1 -1
- package/dist/Spring.js +2 -1
- package/dist/Spring.js.map +1 -1
- package/dist/Values.d.ts +2 -2
- package/dist/Values.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/carried.d.ts +13 -0
- package/dist/internal/carried.d.ts.map +1 -0
- package/dist/internal/carried.js +23 -0
- package/dist/internal/carried.js.map +1 -0
- package/dist/internal/firstSteps.d.ts +66 -0
- package/dist/internal/firstSteps.d.ts.map +1 -0
- package/dist/internal/firstSteps.js +107 -0
- package/dist/internal/firstSteps.js.map +1 -0
- package/dist/internal/frameLoop.d.ts +1 -1
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +102 -81
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/lerpsNumbers.d.ts +11 -0
- package/dist/internal/lerpsNumbers.d.ts.map +1 -0
- package/dist/internal/lerpsNumbers.js +38 -0
- package/dist/internal/lerpsNumbers.js.map +1 -0
- package/dist/internal/options.d.ts +7 -7
- package/dist/internal/options.d.ts.map +1 -1
- package/dist/internal/options.js +10 -10
- package/dist/internal/options.js.map +1 -1
- package/dist/internal/stepper.d.ts +13 -2
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +16 -1
- package/dist/internal/stepper.js.map +1 -1
- package/dist/internal/tracing.d.ts +1 -1
- package/dist/internal/tracing.js +1 -1
- package/dist/unstable/AnimationControls.d.ts +37 -38
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +39 -36
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +5 -5
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/BatchCalls.d.ts +2 -2
- package/dist/unstable/BatchCalls.js +5 -5
- package/dist/unstable/Config.d.ts +19 -19
- package/dist/unstable/Config.d.ts.map +1 -1
- package/dist/unstable/FirstSteps.d.ts +25 -0
- package/dist/unstable/FirstSteps.d.ts.map +1 -0
- package/dist/unstable/FirstSteps.js +2 -0
- package/dist/unstable/FirstSteps.js.map +1 -0
- package/dist/unstable/FlushGate.d.ts +53 -51
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +56 -49
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +2 -2
- package/dist/unstable/FrameEffects.js +2 -2
- package/dist/unstable/FrameTime.d.ts +1 -1
- package/dist/unstable/FrameTime.js +1 -1
- package/dist/unstable/Imperative.d.ts +29 -9
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +79 -47
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/OwnValues.js +1 -1
- package/dist/unstable/PresenceRecord.d.ts +26 -26
- package/dist/unstable/PresenceRecord.d.ts.map +1 -1
- package/dist/unstable/PresenceRecord.js +8 -8
- package/dist/unstable/PresenceRecord.js.map +1 -1
- package/dist/unstable/Projector.d.ts +34 -0
- package/dist/unstable/Projector.d.ts.map +1 -0
- package/dist/unstable/Projector.js +9 -0
- package/dist/unstable/Projector.js.map +1 -0
- package/dist/unstable/Report.d.ts +1 -1
- package/dist/unstable/Report.js +1 -1
- package/dist/unstable/RetargetLegs.d.ts +1 -1
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +9 -8
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +81 -72
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +152 -150
- package/dist/unstable/Spine.js.map +1 -1
- package/dist/unstable/Stops.d.ts +3 -3
- package/dist/unstable/Stops.js +4 -4
- package/dist/unstable/Subject.d.ts +2 -2
- package/dist/unstable/Subject.js +2 -2
- package/dist/unstable/Timelines.d.ts +11 -11
- package/dist/unstable/Timelines.d.ts.map +1 -1
- package/dist/unstable/Timelines.js +3 -3
- package/dist/unstable/VariantTarget.d.ts +7 -7
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +11 -11
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +36 -36
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +33 -33
- package/dist/unstable/VariantTree.js.map +1 -1
- package/dist/unstable/WardicConfigValue.d.ts +13 -13
- package/dist/unstable/WardicConfigValue.d.ts.map +1 -1
- package/dist/unstable/WardicConfigValue.js +4 -4
- package/dist/unstable/WardicConfigValue.js.map +1 -1
- package/package.json +1 -1
- package/src/Arc.ts +3 -3
- package/src/BaseValue.ts +18 -21
- package/src/Batch.ts +236 -22
- package/src/Clock.ts +18 -17
- package/src/DefaultTransition.ts +5 -3
- package/src/Drag.ts +32 -14
- package/src/DragActivity.ts +3 -3
- package/src/DragRecognizer.ts +41 -16
- package/src/Easing.ts +1 -1
- package/src/Frame.ts +5 -3
- package/src/InputFeed.ts +2 -2
- package/src/InputSource.ts +5 -5
- package/src/Interpolator.ts +3 -3
- package/src/InterpolatorRegistry.ts +22 -13
- package/src/LiveValue.ts +47 -17
- package/src/Machine.ts +199 -61
- package/src/Playback.ts +5 -1
- package/src/Projection.ts +9 -9
- package/src/Recognizer.ts +69 -38
- package/src/ReducedMotion.ts +6 -6
- package/src/Renderer.ts +6 -6
- package/src/Reorder.ts +3 -2
- package/src/ScrollSource.ts +1 -1
- package/src/Sequence.ts +1 -1
- package/src/SharedSource.ts +5 -5
- package/src/Spring.ts +2 -1
- package/src/Values.ts +2 -2
- package/src/index.ts +1 -1
- package/src/internal/carried.ts +22 -0
- package/src/internal/firstSteps.ts +139 -0
- package/src/internal/frameLoop.ts +103 -87
- package/src/internal/lerpsNumbers.ts +53 -0
- package/src/internal/options.ts +10 -10
- package/src/internal/stepper.ts +20 -2
- package/src/internal/tracing.ts +1 -1
- package/src/unstable/AnimationControls.ts +59 -56
- package/src/unstable/AppearHandoff.ts +6 -6
- package/src/unstable/BatchCalls.ts +5 -5
- package/src/unstable/Config.ts +19 -19
- package/src/unstable/FirstSteps.ts +26 -0
- package/src/unstable/FlushGate.ts +92 -82
- package/src/unstable/FrameEffects.ts +2 -2
- package/src/unstable/FrameTime.ts +1 -1
- package/src/unstable/Imperative.ts +126 -56
- package/src/unstable/OwnValues.ts +1 -1
- package/src/unstable/PresenceRecord.ts +29 -29
- package/src/unstable/Projector.ts +45 -0
- package/src/unstable/Report.ts +1 -1
- package/src/unstable/RetargetLegs.ts +10 -9
- package/src/unstable/Spine.ts +190 -188
- package/src/unstable/Stops.ts +6 -6
- package/src/unstable/Subject.ts +2 -2
- package/src/unstable/Timelines.ts +12 -12
- package/src/unstable/VariantTarget.ts +13 -13
- package/src/unstable/VariantTree.ts +42 -42
- package/src/unstable/WardicConfigValue.ts +13 -13
package/src/Batch.ts
CHANGED
|
@@ -24,13 +24,14 @@ import * as Effect from "effect/Effect"
|
|
|
24
24
|
import { identity } from "effect/Function"
|
|
25
25
|
import * as Inspectable from "effect/Inspectable"
|
|
26
26
|
import * as Match from "effect/Match"
|
|
27
|
+
import * as Option from "effect/Option"
|
|
27
28
|
import { type Pipeable, pipeArguments } from "effect/Pipeable"
|
|
28
29
|
import * as Predicate from "effect/Predicate"
|
|
29
30
|
import type { Invariant } from "effect/Types"
|
|
30
31
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
31
32
|
import type * as Easing from "./Easing.ts"
|
|
32
33
|
import type * as Frame from "./Frame.ts"
|
|
33
|
-
import
|
|
34
|
+
import * as FrameLoop from "./FrameLoop.ts"
|
|
34
35
|
import * as Machine from "./Machine.ts"
|
|
35
36
|
import type * as Playback from "./Playback.ts"
|
|
36
37
|
import * as Scalar from "./Scalar.ts"
|
|
@@ -38,6 +39,7 @@ import * as Spring from "./Spring.ts"
|
|
|
38
39
|
import * as UnitScale from "./UnitScale.ts"
|
|
39
40
|
import * as Report from "./unstable/Report.ts"
|
|
40
41
|
import { dual } from "./internal/dual.ts"
|
|
42
|
+
import * as FirstSteps from "./internal/firstSteps.ts"
|
|
41
43
|
import { tickOf, writableOf } from "./internal/playhead.ts"
|
|
42
44
|
import { resolveKeyframes } from "./internal/keyframes.ts"
|
|
43
45
|
import { checked, fn, literals, nonNegative, positive, union } from "./internal/options.ts"
|
|
@@ -180,7 +182,7 @@ const COUNTED = 8
|
|
|
180
182
|
* `elapsed` `NaN` until then. It's in `startList`, which each step's start pass reads before the loops.
|
|
181
183
|
*/
|
|
182
184
|
const STARTS = 16
|
|
183
|
-
/** The start pass drew it this step: its loop keeps it, unstepped, and clears the flag. */
|
|
185
|
+
/** The start pass or the owing pass drew it this step: its loop keeps it, unstepped, and clears the flag. */
|
|
184
186
|
const STARTED = 32
|
|
185
187
|
/**
|
|
186
188
|
* Its values changed outside a step (it entered, took a new Subject, a change started it from a given value,
|
|
@@ -228,6 +230,22 @@ interface State<S> {
|
|
|
228
230
|
flags: Uint8Array
|
|
229
231
|
/** The slots a `leave` freed, the next `enter`'s. */
|
|
230
232
|
readonly free: Array<number>
|
|
233
|
+
/**
|
|
234
|
+
* What each member owes of a long task's time (`FirstSteps`): its first step (`NaN`, or less than 0 for one
|
|
235
|
+
* set off in the Late window of a frame told late by its lag), then its first frame's lateness, which its second
|
|
236
|
+
* leaves out, then 0. 0 for a member that started partway (`startAt`), which keeps the frame timeline's time, and where
|
|
237
|
+
* the Frame loop tells no late frame.
|
|
238
|
+
*/
|
|
239
|
+
owed: Float64Array
|
|
240
|
+
/** How many members owe: while none does, every member steps at the tick's dt. */
|
|
241
|
+
owing: number
|
|
242
|
+
/**
|
|
243
|
+
* What the members a run starts with owe, all alike, until its first step (`FirstSteps`), 0 after: told at
|
|
244
|
+
* that step, they owe each, or, on time, nothing.
|
|
245
|
+
*/
|
|
246
|
+
startOwing: number
|
|
247
|
+
/** The Frame loop's ticks as the late-frame rule reads them, from the Batch's first run on. */
|
|
248
|
+
ticks: FirstSteps.Reader | undefined
|
|
231
249
|
/** Each `STARTS` member's `startAt`, by slot, read once at its first step. */
|
|
232
250
|
readonly startAts: Array<((slot: number) => number) | undefined>
|
|
233
251
|
/** The `STARTS` members, in the order their changes came: the next step's start pass. */
|
|
@@ -269,6 +287,8 @@ interface State<S> {
|
|
|
269
287
|
readonly onFrame: () => void
|
|
270
288
|
/** How many steps it has taken: a driven change works its tick out once in each. */
|
|
271
289
|
frame: number
|
|
290
|
+
/** The step's dt, unclamped: a driven change that owes works its tick out of it. */
|
|
291
|
+
frameDt: number
|
|
272
292
|
/** The run stepping it now, by its number, or 0 for none. */
|
|
273
293
|
running: number
|
|
274
294
|
/** How many runs it has had: the next one's number. */
|
|
@@ -466,6 +486,10 @@ export const make = <S>(options: Options<S>): Batch<S> => {
|
|
|
466
486
|
movers: new Int32Array(capacity),
|
|
467
487
|
flags: new Uint8Array(capacity),
|
|
468
488
|
free: [],
|
|
489
|
+
owed: new Float64Array(capacity),
|
|
490
|
+
owing: 0,
|
|
491
|
+
startOwing: 0,
|
|
492
|
+
ticks: undefined,
|
|
469
493
|
startAts: [],
|
|
470
494
|
startList: [],
|
|
471
495
|
plainList: new Int32Array(capacity),
|
|
@@ -488,6 +512,7 @@ export const make = <S>(options: Options<S>): Batch<S> => {
|
|
|
488
512
|
flush: UndefinedOr.match(options.writer.flush, { onUndefined: () => noop, onDefined: identity }),
|
|
489
513
|
onFrame: UndefinedOr.match(options.onFrame, { onUndefined: () => noop, onDefined: identity }),
|
|
490
514
|
frame: 0,
|
|
515
|
+
frameDt: 0,
|
|
491
516
|
running: 0,
|
|
492
517
|
runs: 0,
|
|
493
518
|
services: Context.empty(),
|
|
@@ -559,7 +584,11 @@ export const enter: {
|
|
|
559
584
|
state.subjects[slot] = subject
|
|
560
585
|
// A start a member that left never took isn't this one's.
|
|
561
586
|
// Drawn at its first step, at its start, though a delay holds it there.
|
|
562
|
-
|
|
587
|
+
const flag = (state.flags[slot] & ~(STARTS | STARTED)) | LIVE | DUE
|
|
588
|
+
state.flags[slot] = flag
|
|
589
|
+
// A slot the member before left while it moved is still in its list, stepped as a moving member's: the new
|
|
590
|
+
// one owes its first steps from now while the run goes on (#1028), as one set off is; a run's start counts it.
|
|
591
|
+
if ((flag & (IN_PLAIN | IN_RULED)) !== 0 && state.running !== 0) owes(state, slot, owingNow(state))
|
|
563
592
|
const base = slot * state.stride
|
|
564
593
|
Arr.forEach(state.keys, (key, k) => {
|
|
565
594
|
const given = start[key]
|
|
@@ -596,15 +625,16 @@ export const leave: {
|
|
|
596
625
|
if ((state.flags[slot] & LIVE) === 0) return
|
|
597
626
|
state.flags[slot] = state.flags[slot] & ~LIVE
|
|
598
627
|
state.subjects[slot] = undefined
|
|
628
|
+
owesNothing(state, slot)
|
|
599
629
|
state.free.push(slot)
|
|
600
630
|
})
|
|
601
631
|
|
|
602
632
|
/**
|
|
603
633
|
* The member at `slot` is drawn on `subject` from now on: its values, speed, targets and delays carry
|
|
604
|
-
* on as they were. For
|
|
634
|
+
* on as they were. For a Subject its framework made again for the same member.
|
|
605
635
|
*
|
|
606
636
|
* @example
|
|
607
|
-
* Batch.replace(grid, slot,
|
|
637
|
+
* Batch.replace(grid, slot, subject)
|
|
608
638
|
*/
|
|
609
639
|
export const replace: {
|
|
610
640
|
<S>(slot: number, subject: S): (self: Batch<S>) => void
|
|
@@ -651,6 +681,7 @@ const grow = <S>(state: State<S>, capacity: number): void => {
|
|
|
651
681
|
state.pending = grown(state.pending, size)
|
|
652
682
|
state.movers = grown(state.movers, capacity)
|
|
653
683
|
state.flags = grown(state.flags, capacity)
|
|
684
|
+
state.owed = grown(state.owed, capacity)
|
|
654
685
|
state.plainList = grown(state.plainList, capacity)
|
|
655
686
|
state.ruledList = grown(state.ruledList, capacity)
|
|
656
687
|
}
|
|
@@ -757,6 +788,9 @@ export const retarget: {
|
|
|
757
788
|
const driven = state.animations.size > 0
|
|
758
789
|
// Started partway (#706): each key it turns waits, `elapsed` `NaN`, for its member's first step to read where.
|
|
759
790
|
const startAt = UndefinedOr.map(options, (bag) => bag.startAt)
|
|
791
|
+
// While its run goes on, a member it sets off from rest owes its first steps (#1028), read once.
|
|
792
|
+
let owing = 0
|
|
793
|
+
if (state.running !== 0) owing = owingNow(state)
|
|
760
794
|
let fresh = 0
|
|
761
795
|
if (Predicate.isNotUndefined(startAt)) fresh = Number.NaN
|
|
762
796
|
let setOff = 0
|
|
@@ -803,7 +837,12 @@ export const retarget: {
|
|
|
803
837
|
state.startAts[slot] = startAt
|
|
804
838
|
}
|
|
805
839
|
flags[slot] = flag
|
|
806
|
-
if ((flag & (IN_PLAIN | IN_RULED)) === 0)
|
|
840
|
+
if ((flag & (IN_PLAIN | IN_RULED)) === 0) {
|
|
841
|
+
setOff++
|
|
842
|
+
// Set off from rest while its run goes on: it owes its first steps (#1028), unless its first step
|
|
843
|
+
// takes an Appear animation over (`startedPartway`). A run that starts owes its members' at its start.
|
|
844
|
+
owes(state, slot, owing)
|
|
845
|
+
}
|
|
807
846
|
// Into the ruled list, out of the plain one (which drops it at its next step); else into the plain
|
|
808
847
|
// list, if it's in neither.
|
|
809
848
|
if (ruled && (flag & IN_RULED) === 0) {
|
|
@@ -821,6 +860,97 @@ export const retarget: {
|
|
|
821
860
|
return setOff
|
|
822
861
|
})
|
|
823
862
|
|
|
863
|
+
// --- A member's first steps (#1028) ------------------------------------------------
|
|
864
|
+
//
|
|
865
|
+
// A Batch is one run on the Frame loop, on the frame timeline, so the late-frame rule a run of its own keeps
|
|
866
|
+
// (`FirstSteps`, #1026) is kept here per member: a member set off from rest takes none of a long task's time
|
|
867
|
+
// from before it moved. Per member at a change and at a run's start; per frame, only while one owes.
|
|
868
|
+
|
|
869
|
+
/** What a member or a Playhead set off now owes (`FirstSteps.madeOwing`): 0, nothing, before the Batch's first run. */
|
|
870
|
+
const owingNow = <S>(state: State<S>): number => {
|
|
871
|
+
const ticks = state.ticks
|
|
872
|
+
if (Predicate.isUndefined(ticks)) return 0
|
|
873
|
+
return ticks.madeOwing()
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/** The member at `slot` owes `owing` (0, nothing). */
|
|
877
|
+
// Per member at a change, what they owe read once for all of them.
|
|
878
|
+
const owes = <S>(state: State<S>, slot: number, owing: number): void => {
|
|
879
|
+
if (owing === 0) return
|
|
880
|
+
if (state.owed[slot] === 0) state.owing = state.owing + 1
|
|
881
|
+
state.owed[slot] = owing
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/** The member at `slot` owes nothing: it rests, left, or keeps the frame timeline's time. */
|
|
885
|
+
const owesNothing = <S>(state: State<S>, slot: number): void => {
|
|
886
|
+
if (state.owed[slot] === 0) return
|
|
887
|
+
state.owed[slot] = 0
|
|
888
|
+
state.owing = state.owing - 1
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/** The dt now of a member or a Playhead that owes `owed`: the step's, what it owes left out, clamped. */
|
|
892
|
+
// Per member or Playhead that owes, in a step: twice a play or a set-off at most.
|
|
893
|
+
const owingDt = <S>(state: State<S>, owed: number): number => {
|
|
894
|
+
const ticks = state.ticks
|
|
895
|
+
let dt = state.frameDt
|
|
896
|
+
if (Predicate.isNotUndefined(ticks)) dt = ticks.owingDt(owed, dt)
|
|
897
|
+
return Math.min(dt, Machine.MAX_DT)
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/** What a member or a Playhead that owed `owed` owes after its step now. */
|
|
901
|
+
const owedAfter = <S>(state: State<S>, owed: number): number => {
|
|
902
|
+
const ticks = state.ticks
|
|
903
|
+
if (Predicate.isUndefined(ticks)) return 0
|
|
904
|
+
return ticks.owedAfter(owed)
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* A run's start: the members it starts with owe their first steps from now, all alike, kept once for the
|
|
909
|
+
* Batch (`startOwing`) until its first step tells whether they owe each. What one owed of a run before is
|
|
910
|
+
* forgotten.
|
|
911
|
+
*/
|
|
912
|
+
// Once a run: nothing per member, so a run that starts on time costs what it did.
|
|
913
|
+
const runStarts = <S>(state: State<S>): void => {
|
|
914
|
+
if (state.owing > 0) {
|
|
915
|
+
state.owed.fill(0)
|
|
916
|
+
state.owing = 0
|
|
917
|
+
}
|
|
918
|
+
state.startOwing = owingNow(state)
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* The run's first step: whether the members it started with take the tick's dt. Where they don't, each one
|
|
923
|
+
* moving owes its first steps as they did, and each change a Playhead drives its first ticks: one taking an
|
|
924
|
+
* Appear animation over (the start pass drew it) and one set off or played since, owing its own, aside.
|
|
925
|
+
*/
|
|
926
|
+
// Once a run, at its first step; per member only where that step's frame came late.
|
|
927
|
+
const startOwes = <S>(state: State<S>): void => {
|
|
928
|
+
const owing = state.startOwing
|
|
929
|
+
state.startOwing = 0
|
|
930
|
+
if (owingDt(state, owing) === Math.min(state.frameDt, Machine.MAX_DT) && owedAfter(state, owing) === 0) return
|
|
931
|
+
owesFromNow(state, state.plainList, state.plainCount, IN_PLAIN, owing)
|
|
932
|
+
owesFromNow(state, state.ruledList, state.ruledCount, IN_RULED, owing)
|
|
933
|
+
// And each change a Playhead drives that it started with, played before it, but one played since.
|
|
934
|
+
for (const animation of state.animations) {
|
|
935
|
+
if (animation.owed !== 0) continue
|
|
936
|
+
animation.owed = owing
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/** Each live member of `list`'s first `count` still in it (`inList`), not drawn this step nor owing, owes as `owing`. */
|
|
941
|
+
const owesFromNow = <S>(state: State<S>, list: Int32Array, count: number, inList: number, owing: number): void => {
|
|
942
|
+
const { flags, owed } = state
|
|
943
|
+
let added = 0
|
|
944
|
+
for (let a = 0; a < count; a++) {
|
|
945
|
+
const slot = list[a]
|
|
946
|
+
if ((flags[slot] & (LIVE | inList | STARTED)) !== (LIVE | inList)) continue
|
|
947
|
+
if (owed[slot] !== 0) continue
|
|
948
|
+
owed[slot] = owing
|
|
949
|
+
added++
|
|
950
|
+
}
|
|
951
|
+
state.owing = state.owing + added
|
|
952
|
+
}
|
|
953
|
+
|
|
824
954
|
/**
|
|
825
955
|
* `defect`, a failure on the Batch's path named by `message`, logged and handed to the ErrorReporters of
|
|
826
956
|
* what it runs on, annotated with its member's slot where it's one member's.
|
|
@@ -887,10 +1017,14 @@ export const step = <S>(self: Batch<S>, dt: number): boolean => {
|
|
|
887
1017
|
const state = stateOf(self)
|
|
888
1018
|
const clamped = Math.min(dt, Machine.MAX_DT)
|
|
889
1019
|
state.frame = state.frame + 1
|
|
1020
|
+
state.frameDt = dt
|
|
890
1021
|
// Whether a member's write or start throws in this step: a `draw`'s between steps isn't one (#977).
|
|
891
1022
|
state.writeThrewInStep = false
|
|
892
1023
|
state.startThrewInStep = false
|
|
893
1024
|
if (state.startList.length > 0) startPass(state, clamped)
|
|
1025
|
+
// A member that owes its first steps steps by its own dt, out of the loops (#1028).
|
|
1026
|
+
if (state.startOwing !== 0) startOwes(state)
|
|
1027
|
+
if (state.owing > 0) owingPass(state, clamped)
|
|
894
1028
|
if (state.plainCount > 0) stepPlain(state, clamped)
|
|
895
1029
|
if (state.ruledCount > 0) stepRuled(state, clamped)
|
|
896
1030
|
// Each change's landing its own: a callback that throws leaves the others to land (#977).
|
|
@@ -925,7 +1059,7 @@ export const step = <S>(self: Batch<S>, dt: number): boolean => {
|
|
|
925
1059
|
|
|
926
1060
|
/**
|
|
927
1061
|
* Writes every member where it is now, with no step, then flushes the writer: a change that started its
|
|
928
|
-
* members from their targets (`retarget`'s `from`),
|
|
1062
|
+
* members from their targets (`retarget`'s `from`), committed now, before the frame is drawn, where the run would
|
|
929
1063
|
* draw it at its next tick.
|
|
930
1064
|
*/
|
|
931
1065
|
// #712: a Batch Reorder group's first read of its element places its items at once. Once a change, over
|
|
@@ -1388,6 +1522,11 @@ interface AnimationState<S> {
|
|
|
1388
1522
|
dt: number
|
|
1389
1523
|
/** Played from partway through: its first step lands where it was played from, as a driven machine's (`Playback.drive`). */
|
|
1390
1524
|
landing: boolean
|
|
1525
|
+
/**
|
|
1526
|
+
* What its Playhead owes of a long task's time (`FirstSteps`), as a member does: from its play while the
|
|
1527
|
+
* run goes on, or from the run's start, its first ticks leave it out.
|
|
1528
|
+
*/
|
|
1529
|
+
owed: number
|
|
1391
1530
|
/** Each member it moves, by rank, its first key's index in `ats`, and one past the last's; whether each has been told it landed. */
|
|
1392
1531
|
firsts: Int32Array
|
|
1393
1532
|
told: Uint8Array
|
|
@@ -1433,18 +1572,25 @@ const drivenStep = <S>(animation: AnimationState<S>, clamped: number, frame: num
|
|
|
1433
1572
|
if (animation.frame === frame) return animation.dt
|
|
1434
1573
|
animation.frame = frame
|
|
1435
1574
|
const head = animation.options.head
|
|
1575
|
+
// Its tick: the frame's, less a long task's time while its Playhead owes its first ticks (#1028).
|
|
1576
|
+
let tick = clamped
|
|
1577
|
+
const owed = animation.owed
|
|
1578
|
+
if (owed !== 0) {
|
|
1579
|
+
tick = owingDt(animation.state, owed)
|
|
1580
|
+
animation.owed = owedAfter(animation.state, owed)
|
|
1581
|
+
}
|
|
1436
1582
|
let by = 0
|
|
1437
1583
|
// Played from partway through, its first step lands there, whatever the `dt`, as `Playback.drive`'s does.
|
|
1438
1584
|
const landing = animation.landing
|
|
1439
1585
|
animation.landing = false
|
|
1440
|
-
if (!landing && !head.paused) by = tickOf(head,
|
|
1586
|
+
if (!landing && !head.paused) by = tickOf(head, tick, Machine.MAX_DT)
|
|
1441
1587
|
animation.dt = by
|
|
1442
1588
|
animation.time = Math.max(0, animation.time + by)
|
|
1443
1589
|
writableOf(head).time = animation.time
|
|
1444
1590
|
return by
|
|
1445
1591
|
}
|
|
1446
1592
|
|
|
1447
|
-
/** Whether the key at `at` is held by a paused Playhead: it hands on no speed, as a held
|
|
1593
|
+
/** Whether the key at `at` is held by a paused Playhead: it hands on no speed, as a held Subject's frames read 0 (#464). */
|
|
1448
1594
|
// Per key per change, while a driven change plays.
|
|
1449
1595
|
const heldAt = <S>(state: State<S>, at: number): boolean => {
|
|
1450
1596
|
const driver = state.drivers[state.rules[at]]
|
|
@@ -1542,6 +1688,9 @@ const startedPartway = <S>(state: State<S>, slot: number, dt: number): boolean =
|
|
|
1542
1688
|
}
|
|
1543
1689
|
const base = slot * stride
|
|
1544
1690
|
const started = !Number.isNaN(time)
|
|
1691
|
+
// Taking its Appear animation over, it keeps the frame timeline's time, where that animation's is (#1026);
|
|
1692
|
+
// from its start, `NaN`, it takes over nothing and owes its first steps as any member set off (#1028).
|
|
1693
|
+
if (started) owesNothing(state, slot)
|
|
1545
1694
|
for (let k = 0; k < stride; k++) {
|
|
1546
1695
|
const at = base + k
|
|
1547
1696
|
const turned = Number.isNaN(elapsed[at])
|
|
@@ -1569,11 +1718,70 @@ const startedPartway = <S>(state: State<S>, slot: number, dt: number): boolean =
|
|
|
1569
1718
|
return started
|
|
1570
1719
|
}
|
|
1571
1720
|
|
|
1721
|
+
/**
|
|
1722
|
+
* Each step's owing pass, before the loops and after the start pass: each member that owes its first steps
|
|
1723
|
+
* takes its step's dt (the tick's, less what it owes). One whose dt that leaves less is
|
|
1724
|
+
* stepped by it here, drawn, and flagged `STARTED` so its loop keeps it unstepped; one at the tick's, by its
|
|
1725
|
+
* loop. A key a Playhead drives keeps its Playhead's step.
|
|
1726
|
+
*/
|
|
1727
|
+
// #1028: once or twice a member, after a change that sets it off, so out of the loops, as the start pass is
|
|
1728
|
+
// (#706): with a member's own dt read in them, Bun's ruled step ran 5% slower with no member owing.
|
|
1729
|
+
const owingPass = <S>(state: State<S>, clamped: number): void => {
|
|
1730
|
+
owingIn(state, state.plainList, state.plainCount, clamped)
|
|
1731
|
+
owingIn(state, state.ruledList, state.ruledCount, clamped)
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
/** The owing pass over `list`'s first `count`: a member that left, or one drawn this step already, skipped. */
|
|
1735
|
+
const owingIn = <S>(state: State<S>, list: Int32Array, count: number, clamped: number): void => {
|
|
1736
|
+
const { flags, owed } = state
|
|
1737
|
+
for (let a = 0; a < count; a++) {
|
|
1738
|
+
const slot = list[a]
|
|
1739
|
+
const was = owed[slot]
|
|
1740
|
+
if (was === 0) continue
|
|
1741
|
+
if ((flags[slot] & (LIVE | STARTED)) !== LIVE) continue
|
|
1742
|
+
const own = owingDt(state, was)
|
|
1743
|
+
const after = owedAfter(state, was)
|
|
1744
|
+
owed[slot] = after
|
|
1745
|
+
if (after === 0) state.owing = state.owing - 1
|
|
1746
|
+
// At the tick's own dt (an on-time first step), its loop steps it.
|
|
1747
|
+
if (own !== clamped) stepOwing(state, slot, clamped, own)
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
/** The member at `slot` a step of `own` on, each key as the loops step it, drawn, and kept from its loop this step. */
|
|
1752
|
+
const stepOwing = <S>(state: State<S>, slot: number, clamped: number, own: number): void => {
|
|
1753
|
+
const { stride, rules, drivers } = state
|
|
1754
|
+
const base = slot * stride
|
|
1755
|
+
for (let k = 0; k < stride; k++) {
|
|
1756
|
+
const at = base + k
|
|
1757
|
+
const rule = rules[at]
|
|
1758
|
+
const driver = drivers[rule]
|
|
1759
|
+
if (Predicate.isUndefined(driver)) {
|
|
1760
|
+
stepKey(state, at, rule, own)
|
|
1761
|
+
continue
|
|
1762
|
+
}
|
|
1763
|
+
// Its Playhead's step this frame, worked out once a step whichever reads it first.
|
|
1764
|
+
const driven = drivenStep(driver, clamped, state.frame)
|
|
1765
|
+
if (driven < 0) {
|
|
1766
|
+
stepBack(state, at, rule, driven)
|
|
1767
|
+
continue
|
|
1768
|
+
}
|
|
1769
|
+
stepKey(state, at, rule, driven)
|
|
1770
|
+
}
|
|
1771
|
+
state.flags[slot] = (state.flags[slot] & ~DUE) | STARTED
|
|
1772
|
+
try {
|
|
1773
|
+
state.write(state.subjects[slot] as S, state.positions, base)
|
|
1774
|
+
} catch (defect) {
|
|
1775
|
+
writeFailed(state, slot, defect)
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1572
1779
|
/**
|
|
1573
1780
|
* The key at `at` a step of `dt` on, as the loops step it: a tween's, keyframes', or a spring's by its
|
|
1574
1781
|
* matrix for the part past its delay, landing by its thresholds or its duration.
|
|
1575
1782
|
*/
|
|
1576
|
-
// Rare: a key the loops don't reach this step, of a member started partway that another change moves
|
|
1783
|
+
// Rare: a key the loops don't reach this step, of a member started partway that another change moves, or of
|
|
1784
|
+
// a member that owes its first steps (#1028).
|
|
1577
1785
|
const stepKey = <S>(state: State<S>, at: number, rule: number, dt: number): void => {
|
|
1578
1786
|
const entry = state.entries[rule]
|
|
1579
1787
|
const time = state.elapsed[at] + dt
|
|
@@ -1830,6 +2038,7 @@ const animationFor = <S>(
|
|
|
1830
2038
|
frame: 0,
|
|
1831
2039
|
dt: 0,
|
|
1832
2040
|
landing: false,
|
|
2041
|
+
owed: 0,
|
|
1833
2042
|
tracks: [],
|
|
1834
2043
|
indexAt: new Int32Array(0),
|
|
1835
2044
|
firsts: new Int32Array(0),
|
|
@@ -2113,7 +2322,7 @@ const playRules = <S>(animation: AnimationState<S>): void => {
|
|
|
2113
2322
|
/**
|
|
2114
2323
|
* Plays `animation` from its Playhead's time: from its start at 0, its change worked out then, and from
|
|
2115
2324
|
* wherever a seek put the time, every key it moves taken again there. It returns how many members it
|
|
2116
|
-
* sets off from rest. One that moves nothing lands at once, as
|
|
2325
|
+
* sets off from rest. One that moves nothing lands at once, as a Subject's call with no key does.
|
|
2117
2326
|
*/
|
|
2118
2327
|
export const play = (self: Animation): number => {
|
|
2119
2328
|
const animation = animationOf(self)
|
|
@@ -2130,6 +2339,10 @@ export const play = (self: Animation): number => {
|
|
|
2130
2339
|
animation.playing = true
|
|
2131
2340
|
animation.time = time
|
|
2132
2341
|
animation.landing = time > 0
|
|
2342
|
+
// Played while the run goes on, its Playhead owes its first ticks from now (#1028); played at rest, from
|
|
2343
|
+
// the run's start, as the run's members.
|
|
2344
|
+
animation.owed = 0
|
|
2345
|
+
if (state.running !== 0) animation.owed = owingNow(state)
|
|
2133
2346
|
state.animations.add(animation)
|
|
2134
2347
|
// Once a play, per key it moves: each key's entry, then each entry held once for it and driven by it.
|
|
2135
2348
|
playRules(animation)
|
|
@@ -2316,6 +2529,10 @@ const machineOf = <S>(self: Batch<S>, id: number): Machine.Machine<Frame.Frame<n
|
|
|
2316
2529
|
})
|
|
2317
2530
|
}
|
|
2318
2531
|
|
|
2532
|
+
/** A Batch run's options: on the frame timeline, its members keeping the late-frame rule each. */
|
|
2533
|
+
// #1026, #1028.
|
|
2534
|
+
const ON_THE_FRAME_TIMELINE: Machine.RunOptions = { onFrameTimeline: true }
|
|
2535
|
+
|
|
2319
2536
|
/**
|
|
2320
2537
|
* Runs `self` on the Frame loop while any member moves, from the next tick: each tick steps every
|
|
2321
2538
|
* moving member and writes it. It succeeds once nothing moves. While one runs, another does nothing,
|
|
@@ -2326,13 +2543,10 @@ const machineOf = <S>(self: Batch<S>, id: number): Machine.Machine<Frame.Frame<n
|
|
|
2326
2543
|
* Batch.retarget(grid, slots, targetOf)
|
|
2327
2544
|
* runtime.runFork(Batch.run(grid))
|
|
2328
2545
|
*/
|
|
2329
|
-
/** A Batch run's options (#1026): on the frame timeline while members take their Appear animations over, or not. */
|
|
2330
|
-
const TAKING_OVER: Machine.RunOptions = { onFrameTimeline: true }
|
|
2331
|
-
const ON_ITS_OWN: Machine.RunOptions = {}
|
|
2332
2546
|
|
|
2333
2547
|
// One run, not a fiber per member (ADR-0069, decision 10). Its span is `wardic.batch`.
|
|
2334
|
-
export const run
|
|
2335
|
-
Effect.contextWith((services: Context.Context<
|
|
2548
|
+
export const run = <S>(self: Batch<S>): Effect.Effect<void, never, FrameLoop.FrameLoop> =>
|
|
2549
|
+
Effect.contextWith((services: Context.Context<FrameLoop.FrameLoop>) => {
|
|
2336
2550
|
const state = stateOf(self)
|
|
2337
2551
|
if (state.running !== 0) return Effect.void
|
|
2338
2552
|
// Its failures are reported on what it runs on, the Environment's Logger and ErrorReporters, kept
|
|
@@ -2342,13 +2556,13 @@ export const run =<S>(self: Batch<S>): Effect.Effect<void, never, FrameLoop.Fram
|
|
|
2342
2556
|
const id = state.runs + 1
|
|
2343
2557
|
state.runs = id
|
|
2344
2558
|
state.running = id
|
|
2345
|
-
//
|
|
2346
|
-
//
|
|
2347
|
-
//
|
|
2348
|
-
|
|
2349
|
-
|
|
2559
|
+
// The run keeps the frame timeline's time, where a member taking its Appear animation over has its
|
|
2560
|
+
// `currentTime` (#1026). Every other member takes no long task's time from before it moved (#1028):
|
|
2561
|
+
// those moving now owe their first steps, and those set off while it runs, at their change.
|
|
2562
|
+
state.ticks = Option.getOrUndefined(FirstSteps.readerOf(Context.get(services, FrameLoop.FrameLoop)))
|
|
2563
|
+
runStarts(state)
|
|
2350
2564
|
return Effect.ensuring(
|
|
2351
|
-
Effect.asVoid(Machine.run(machineOf(self, id), ignore,
|
|
2565
|
+
Effect.asVoid(Machine.run(machineOf(self, id), ignore, ON_THE_FRAME_TIMELINE)),
|
|
2352
2566
|
Effect.sync(() => {
|
|
2353
2567
|
if (state.running === id) state.running = 0
|
|
2354
2568
|
}),
|
package/src/Clock.ts
CHANGED
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
//
|
|
23
23
|
// Cold start (ADR-0017, ADR-0033): the subscription that starts an idle loop gets its first tick at the
|
|
24
24
|
// next Refresh frame, as a warm start does, with `dt = NOMINAL_DT`: `dt` stays nominal until two Refresh
|
|
25
|
-
// frame timestamps exist, then it is the measured interval. The flush gate
|
|
26
|
-
// the end of the Frame loop's tick, in that Refresh frame, so a Cold start's first step
|
|
27
|
-
// first Refresh frame. (Until #73 the gate
|
|
25
|
+
// frame timestamps exist, then it is the measured interval. The flush gate commits what a tick writes at
|
|
26
|
+
// the end of the Frame loop's tick, in that Refresh frame, so a Cold start's first step is drawn in the
|
|
27
|
+
// first Refresh frame. (Until #73 the gate's writes were drawn a frame later, and a Priming tick at the end of the
|
|
28
28
|
// subscribing task made up for it.) The loop never goes through the Effect scheduler: it starts
|
|
29
29
|
// synchronously, waits for the end of its task via `Microtask.next` (so a subscription made and dropped
|
|
30
30
|
// in one task requests no Refresh frame), and requests each next Refresh frame inside the current one's
|
|
@@ -97,20 +97,20 @@ export const NOMINAL_DT = 1 / 60
|
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* How an Environment's Refresh frames run late ({@link LateFrames}): by their timestamps alone, or, once a
|
|
100
|
-
* frame's callback ran more than `ranAfter` ms after its timestamp, late, a long task
|
|
100
|
+
* frame's callback ran more than `ranAfter` ms after its timestamp, late, a long task delaying it.
|
|
101
101
|
*/
|
|
102
102
|
export type LateFrameTiming = "timestamp" | { readonly ranAfter: number }
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
|
-
* Whether the Frame loop tells a
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
105
|
+
* Whether the Frame loop tells a Refresh frame a long task delayed, a late frame: not by default. For an Environment whose frame
|
|
106
|
+
* timestamps are on its Clock's `now()`'s timebase, as `@wardic/dom`'s are, a frame that ran more than `ranAfter`
|
|
107
|
+
* ms after its timestamp, and one whose gap from the frame before is well past the frames' interval. A long task
|
|
108
|
+
* delays a frame, so a frame's dt holds the task's time. A run made in that task didn't exist before its first
|
|
109
|
+
* frame ran, and the loop leaves that time out of its first steps. The Clock's time stays the frames' timestamps,
|
|
110
|
+
* what every other run and reading counts.
|
|
111
111
|
*/
|
|
112
|
-
//
|
|
113
|
-
// whose times are its host's, keep the default.
|
|
112
|
+
// #1026; the gap since #1050 (ADR-0027 *Amendment (#1050)*). `@wardic/dom` provides its own line to its Frame loop
|
|
113
|
+
// (`DomLive`'s `LateFramesDomLive`); `@wardic/object`'s pumped frames, whose times are its host's, keep the default.
|
|
114
114
|
export const LateFrames: Context.Reference<LateFrameTiming> = /*#__PURE__*/ Context.Reference<LateFrameTiming>("@wardic/core/Clock/LateFrames", {
|
|
115
115
|
defaultValue: () => "timestamp",
|
|
116
116
|
})
|
|
@@ -199,15 +199,16 @@ export const fromRefreshFrames: <Handle>(
|
|
|
199
199
|
* THE SINGLE UPDATE PATH. dt is NOMINAL_DT with no earlier Refresh frame, else (t - lastTime) / 1000.
|
|
200
200
|
*
|
|
201
201
|
* A Refresh frame whose timestamp REPEATS the previous one is timed by the
|
|
202
|
-
* elapsed `now()` since the previous frame instead:
|
|
203
|
-
* right after an input and
|
|
204
|
-
* otherwise advance nothing
|
|
205
|
-
*
|
|
206
|
-
*
|
|
202
|
+
* elapsed `now()` since the previous frame instead: an Environment may run a second
|
|
203
|
+
* frame right after an input and pass it the previous frame's timestamp, which would
|
|
204
|
+
* otherwise advance nothing. The next frame then gets the rest of the interval, and a
|
|
205
|
+
* dt never goes below 0. There is no upper clamp here: that is the consumer boundary's
|
|
206
|
+
* (`MAX_DT`).
|
|
207
207
|
*
|
|
208
208
|
* Hands dt to every subscriber. Hot path — intentionally unlogged; one `now()` read per
|
|
209
209
|
* Refresh frame.
|
|
210
210
|
*/
|
|
211
|
+
// Firefox runs that second frame (#18; ADR-0017, amended by #2).
|
|
211
212
|
const tick = (t: number): Effect.Effect<void> =>
|
|
212
213
|
Effect.sync(() => {
|
|
213
214
|
const at = now()
|
package/src/DefaultTransition.ts
CHANGED
|
@@ -88,7 +88,7 @@ const transformFor = (key: string, target: number | string): Transition =>
|
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* The transition `key` runs on toward `target` by its name, as Motion picks it: a transform but a scale
|
|
91
|
-
* (`x`, `
|
|
91
|
+
* (`x`, `rotateY`, `rotateZ`…) on a spring of 500 / 25, at rest under 10 a second; a scale on a spring of
|
|
92
92
|
* 550, critically damped toward 0, else damped 30; any other key on a 0.3 s tween, eased by the cubic
|
|
93
93
|
* Bézier (0.25, 0.1, 0.35, 1). The same object for the same answer.
|
|
94
94
|
*
|
|
@@ -98,13 +98,15 @@ const transformFor = (key: string, target: number | string): Transition =>
|
|
|
98
98
|
*/
|
|
99
99
|
// Motion's `getDefaultTransition` (`motion-dom/src/animation/utils/default-transitions.ts` at 16c6122).
|
|
100
100
|
// #882 (ADR-0073, *Amendment (#882)*, Q2): dom's table (ADR-0051, #357), moved here, so a scene's keys run
|
|
101
|
-
// on what
|
|
101
|
+
// on what `@wardic/dom`'s do (ADR-0073, decision 22). dom's `DomDefaultTransition` and `@wardic/object`'s run
|
|
102
|
+
// their own transform keys as a twin's here (#887, #1002, ADR-0073 *Amendment (#1002)* Q3).
|
|
102
103
|
export const byKey = (key: string, target: number | string): Transition =>
|
|
103
104
|
Bool.match(Option.isSome(BaseValue.transformIdentity(key)), { onTrue: () => transformFor(key, target), onFalse: () => EASE })
|
|
104
105
|
|
|
105
106
|
/**
|
|
106
107
|
* The Default transition by key: {@link byKey} for each key, and {@link KEYFRAMES_TWEEN} through more
|
|
107
|
-
* than two stops.
|
|
108
|
+
* than two stops. An Environment's whose transform keys are core's; one with keys of its own gives them
|
|
109
|
+
* a transition too, as `@wardic/dom` and `@wardic/object` do.
|
|
108
110
|
*
|
|
109
111
|
* @example
|
|
110
112
|
* program.pipe(Effect.provide(DefaultTransition.layerByKey))
|
package/src/Drag.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A drag's samples and what shapes them: `Sample`, what `DragRecognizer`'s drags give at each step;
|
|
3
3
|
* `Axis`, the axes one moves on; and the constraints a binding applies to a sample's `offset`, with a
|
|
4
|
-
* rubber band past them (`constrain`, `within`, `withinBounds`), or to keep
|
|
5
|
-
* container (`boundsWithin`, `keepPlace` after a resize). A binding moves the
|
|
4
|
+
* rubber band past them (`constrain`, `within`, `withinBounds`), or to keep a Subject inside a
|
|
5
|
+
* container (`boundsWithin`, `keepPlace` after a resize). A binding moves the Subject from the
|
|
6
6
|
* shaped samples, and flings it at the end.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
@@ -38,9 +38,9 @@ export interface Sample {
|
|
|
38
38
|
readonly velocity: Point.Point
|
|
39
39
|
/**
|
|
40
40
|
* `"start"` once it's past its threshold, `"move"` as it moves, `"end"` at its release or a cancel. A
|
|
41
|
-
* cancel ends at the last move's point, with
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* cancel ends at the last move's point, with no velocity. A drag whose release was lost ends at the
|
|
42
|
+
* pointer's first move with no button pressed, or at its next down: an `"end"` at the last pressed
|
|
43
|
+
* point, with no delta and no velocity. How it ended is its `endedBy`.
|
|
44
44
|
*/
|
|
45
45
|
// A `pointercancel`'s own coordinates aren't the pointer's (Chromium's carries (0, 0)). The lost
|
|
46
46
|
// release is a **Stale gesture** (ADR-0019).
|
|
@@ -59,11 +59,29 @@ export interface Sample {
|
|
|
59
59
|
/**
|
|
60
60
|
* `true` on an `"end"` its watch's `cancel` gave: the drag ended where it is, which a binding
|
|
61
61
|
* releases with no fling and tells no app. Absent on every other sample.
|
|
62
|
+
*
|
|
63
|
+
* @deprecated `endedBy === "controls"` says the same. It goes at the next major.
|
|
62
64
|
*/
|
|
63
|
-
// #431, Motion's drag controls' `cancel
|
|
65
|
+
// #431, Motion's drag controls' `cancel`; deprecated by #1042.
|
|
64
66
|
readonly cancelled?: boolean
|
|
67
|
+
/** How the drag ended, on its `"end"` ({@link EndedBy}). Absent on a `"start"` and a `"move"`. */
|
|
68
|
+
// #1042.
|
|
69
|
+
readonly endedBy?: EndedBy
|
|
65
70
|
}
|
|
66
71
|
|
|
72
|
+
/**
|
|
73
|
+
* How a drag ended:
|
|
74
|
+
*
|
|
75
|
+
* - `"release"`: its pointer let go, or its drag controls' `stop()` ended it as a release would.
|
|
76
|
+
* - `"cancel"`: the platform took its pointer away, its Environment's cancel (a touch taken to scroll, a
|
|
77
|
+
* system gesture). It ends at its last point with no velocity, so it doesn't fling.
|
|
78
|
+
* - `"lost"`: its release never came (a **Stale gesture**), found at its pointer's next move with no
|
|
79
|
+
* button pressed, or its next down. No velocity either.
|
|
80
|
+
* - `"controls"`: its drag controls' `cancel()` ended it where it is.
|
|
81
|
+
*/
|
|
82
|
+
// #1042 (ADR-0019, *Amendment (#1042)*).
|
|
83
|
+
export type EndedBy = "release" | "cancel" | "lost" | "controls"
|
|
84
|
+
|
|
67
85
|
/** A range on one axis. Either end can be left out: `{ min: 0 }` holds it above 0, and lets it go as far as it likes the other way. */
|
|
68
86
|
export interface AxisRange {
|
|
69
87
|
/** The least it goes to. */
|
|
@@ -111,8 +129,8 @@ const aboveMax = (v: number, range: AxisRange, elastic: number): Option.Option<n
|
|
|
111
129
|
* Drag.constrain(130, { min: 0, max: 100 }, 0.35) // 110.5
|
|
112
130
|
*/
|
|
113
131
|
// Below `min`: `min - (min - v) * elastic`; above `max`: `max + (v - max) * elastic`. Positional: a
|
|
114
|
-
// drag whose constraints bound the
|
|
115
|
-
//
|
|
132
|
+
// drag whose constraints bound the Subject's x/y applies it where the gesture's offset meets where the
|
|
133
|
+
// Subject started (ADR-0016, *Amendment (#140)*).
|
|
116
134
|
export const constrain = (v: number, range: AxisRange | undefined, elastic: number): number =>
|
|
117
135
|
Option.fromUndefinedOr(range).pipe(
|
|
118
136
|
Option.flatMap((r) => Option.orElse(belowMin(v, r, elastic), () => aboveMax(v, r, elastic))),
|
|
@@ -140,9 +158,9 @@ const rangeWithin = (near: number, far: number, containerNear: number, container
|
|
|
140
158
|
}
|
|
141
159
|
|
|
142
160
|
/**
|
|
143
|
-
* The bounds on
|
|
144
|
-
* constraints given
|
|
145
|
-
* dragged to show what overflows and no further. `own` is the
|
|
161
|
+
* The bounds on a Subject's x and y that keep its box inside `container`, as Motion's drag
|
|
162
|
+
* constraints given a container. On an axis where the box is the bigger they turn around, so it can be
|
|
163
|
+
* dragged to show what overflows and no further. `own` is the Subject's box with no x or y of its own:
|
|
146
164
|
* its layout box.
|
|
147
165
|
*
|
|
148
166
|
* @example
|
|
@@ -162,7 +180,7 @@ const sameRange = (a: AxisRange | undefined, b: AxisRange | undefined): boolean
|
|
|
162
180
|
onDefined: (ra) => UndefinedOr.match(b, { onUndefined: () => false, onDefined: (rb) => Bool.and(ra.min === rb.min, ra.max === rb.max) }),
|
|
163
181
|
})
|
|
164
182
|
|
|
165
|
-
/** Whether two bounds are the same on both axes: a resize that changed neither leaves
|
|
183
|
+
/** Whether two bounds are the same on both axes: a resize that changed neither leaves a Subject where it is. */
|
|
166
184
|
// #273.
|
|
167
185
|
export const sameBounds = (a: Bounds, b: Bounds): boolean => Bool.and(sameRange(a.x, b.x), sameRange(a.y, b.y))
|
|
168
186
|
|
|
@@ -185,7 +203,7 @@ const keptOn = (value: number, from: AxisRange | undefined, to: AxisRange | unde
|
|
|
185
203
|
})
|
|
186
204
|
|
|
187
205
|
/**
|
|
188
|
-
* `position` moved to keep its place, from `from` within `to`:
|
|
206
|
+
* `position` moved to keep its place, from `from` within `to`: a Subject's x and y after a resize
|
|
189
207
|
* changes the bounds that keep it inside its container, as Motion's. Only on the axes `axis` moves,
|
|
190
208
|
* and where both bounds have both ends; elsewhere it stays.
|
|
191
209
|
*/
|
|
@@ -223,7 +241,7 @@ export const within: {
|
|
|
223
241
|
|
|
224
242
|
/**
|
|
225
243
|
* A drag's samples with each one's `offset` kept within `bounds`, as `within` keeps one: for a Stream of
|
|
226
|
-
* them. `delta` and `velocity` stay the pointer's: a binding places the
|
|
244
|
+
* them. `delta` and `velocity` stay the pointer's: a binding places the Subject from `offset`, and the
|
|
227
245
|
* others stay a true record of how the pointer moved.
|
|
228
246
|
*
|
|
229
247
|
* @example
|