@wardic/core 1.3.0 → 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 +195 -24
- 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/BatchCalls.d.ts +16 -1
- package/dist/unstable/BatchCalls.d.ts.map +1 -1
- package/dist/unstable/BatchCalls.js +8 -0
- package/dist/unstable/BatchCalls.js.map +1 -1
- package/dist/unstable/Config.d.ts +16 -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 +42 -11
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +413 -77
- 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 +62 -10
- 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 +210 -20
- 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/BatchCalls.ts +20 -2
- package/src/unstable/Config.ts +24 -1
- package/src/unstable/FlushGate.ts +169 -37
- package/src/unstable/FrameEffects.ts +15 -2
- package/src/unstable/Imperative.ts +447 -89
- 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 +244 -43
- package/src/unstable/VariantTarget.ts +93 -14
- package/src/unstable/VariantTree.ts +87 -6
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()
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
* run gets at its start when the check is on, so the tick is the same either way.
|
|
55
55
|
*
|
|
56
56
|
* Internal (ADR-0028, decision 11): the service's shape (`run`, `runLast`, `afterTick`,
|
|
57
|
-
* `inLateWindow`) and `make`, behind `FrameLoop.layer`.
|
|
57
|
+
* `inLateWindow`, `tickCount`, `hint`) and `make`, behind `FrameLoop.layer`.
|
|
58
58
|
*/
|
|
59
59
|
import * as Arr from "effect/Array"
|
|
60
60
|
import * as Bool from "effect/Boolean"
|
|
@@ -80,6 +80,7 @@ import type * as Frame from "../Frame.ts"
|
|
|
80
80
|
import * as Supersede from "../Supersede.ts"
|
|
81
81
|
import type * as FrameLoop from "../FrameLoop.ts"
|
|
82
82
|
import type * as Machine from "../Machine.ts"
|
|
83
|
+
import * as Report from "../unstable/Report.ts"
|
|
83
84
|
import { none, SpansGiven, traced } from "./tracing.ts"
|
|
84
85
|
|
|
85
86
|
// @wardic/core compiles against ES2022 alone, which does not declare `performance` (see
|
|
@@ -88,11 +89,13 @@ declare const performance: { readonly now: () => number }
|
|
|
88
89
|
// The same for `queueMicrotask` (see Microtask.ts): the Late window's end (#680).
|
|
89
90
|
declare const queueMicrotask: (callback: () => void) => void
|
|
90
91
|
|
|
91
|
-
/** A run's options: the token it joins, so its caller can end it with others. */
|
|
92
|
-
// #200.
|
|
92
|
+
/** A run's options: the token it joins, so its caller can end it with others, and its timeline. */
|
|
93
|
+
// #200; #1026.
|
|
93
94
|
export interface RunOptions {
|
|
94
95
|
/** The token: `Supersede.end` on it ends every run that joined it. */
|
|
95
|
-
readonly supersede
|
|
96
|
+
readonly supersede?: Supersede.Supersede | undefined
|
|
97
|
+
/** Its start read from the frame timeline: it steps at the ticks' dt from its first frame ({@link dtOf}). */
|
|
98
|
+
readonly onFrameTimeline?: boolean | undefined
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
/** `run`'s and `runLast`'s shape: a run given a token can also end `Superseded`. */
|
|
@@ -140,6 +143,13 @@ export interface Shape {
|
|
|
140
143
|
// ADR-0027 *Amendment (#680)* (was `ticking()`, #673): the projection's Measure pass reads it at a
|
|
141
144
|
// trigger, to know it will run after its frame's tick.
|
|
142
145
|
readonly inLateWindow: () => boolean
|
|
146
|
+
/**
|
|
147
|
+
* How many ticks the loop has run: 0 before any. Neither a Late round nor a binding's hint window is a
|
|
148
|
+
* tick, so a run's Late step reads the count it was started at, and any step at a later tick a greater one.
|
|
149
|
+
*/
|
|
150
|
+
// #991 (ADR-0043, *Amendment (#991)*): `velocity` tells its run's Late step by it. Not the Clock's
|
|
151
|
+
// `frameAt`, which repeats on Firefox's frame after an input (#18) and is `NaN` before any frame.
|
|
152
|
+
readonly tickCount: () => number
|
|
143
153
|
/**
|
|
144
154
|
* A binding's hint: its code runs inside the Refresh frame whose time is `frameTime`, after the
|
|
145
155
|
* frame's tick, as a binding that renders in a frame callback of its own does (ADR-0071 decision 32).
|
|
@@ -156,6 +166,8 @@ export interface Shape {
|
|
|
156
166
|
/** One hook on the loop's ticks, one object per `afterTick`, so removing it removes only that one. */
|
|
157
167
|
interface Hook {
|
|
158
168
|
readonly hook: (dt: number) => undefined
|
|
169
|
+
/** Whether its calls are throwing: reported at the first, again once one has returned. */
|
|
170
|
+
failing: boolean
|
|
159
171
|
}
|
|
160
172
|
|
|
161
173
|
/** One run on the loop. */
|
|
@@ -175,11 +187,36 @@ interface Entry {
|
|
|
175
187
|
late: boolean
|
|
176
188
|
/** Its span, when traced: marked `late` at its Late step (#680). */
|
|
177
189
|
readonly span: Tracer.Span | undefined
|
|
190
|
+
/**
|
|
191
|
+
* What a long task held of its first frames, in seconds, for it to leave out (#1026, `firstDt`): `NaN`
|
|
192
|
+
* until its first step, then what of that frame a long task held, which its second step leaves out, then
|
|
193
|
+
* 0. 0 from the start for a run on the frame timeline, and on an Environment that tells no late frame.
|
|
194
|
+
*/
|
|
195
|
+
owed: number
|
|
196
|
+
/** When it was made, on the Clock's `now()` (ms), where `owed` starts `NaN`. */
|
|
197
|
+
readonly madeAt: number
|
|
198
|
+
/** Made in the Late window of a frame a long task held: what it held, in seconds, which a first step at a later tick leaves out. */
|
|
199
|
+
readonly madeLate: number
|
|
178
200
|
}
|
|
179
201
|
|
|
180
202
|
/** How many Late rounds a window runs before the rest wait for the next tick: the Measure pass's cap (#680). */
|
|
181
203
|
const MAX_LATE_ROUNDS = 5
|
|
182
204
|
|
|
205
|
+
/** The line past which a Refresh frame ran late, in ms (`Clock.LateFrames`): `NaN` where none is told. */
|
|
206
|
+
const lateAfterOf = (timing: Clock.LateFrameTiming): number => {
|
|
207
|
+
if (timing === "timestamp") return Number.NaN
|
|
208
|
+
return timing.ranAfter
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Whether a run keeps the frame timeline's time (`RunOptions.onFrameTimeline`). */
|
|
212
|
+
const onFrameTimeline = (options: RunOptions | undefined): boolean => {
|
|
213
|
+
if (Predicate.isUndefined(options)) return false
|
|
214
|
+
return options.onFrameTimeline === true
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** `dt`, less `left` seconds left out of it: a nominal frame at least, and never more than `dt`. */
|
|
218
|
+
const leavingOut = (dt: number, left: number): number => Math.min(dt, Math.max(dt - left, Clock.NOMINAL_DT))
|
|
219
|
+
|
|
183
220
|
/**
|
|
184
221
|
* The Frame loop's metrics: the running animations, the runs that settled and failed, and each tick's
|
|
185
222
|
* ms. None unless an app gives them (`FrameLoop.layerMetrics`, #518), so an app that reads none ships and
|
|
@@ -304,6 +341,10 @@ export const make = Effect.fnUntraced(
|
|
|
304
341
|
const clock = yield* Clock.Clock
|
|
305
342
|
// The burst runs here, under the Layer's build context, never in a caller's.
|
|
306
343
|
const buildContext = yield* Effect.context<Clock.Clock | Scope.Scope>()
|
|
344
|
+
/** A hook's throw, reported on what the loop was built with: its failure path. */
|
|
345
|
+
const hookFailed = (defect: unknown): void => {
|
|
346
|
+
Effect.runForkWith(buildContext)(Report.failure("wardic.frameLoop: an afterTick hook failed", Cause.die(defect)))
|
|
347
|
+
}
|
|
307
348
|
// The burst's fiber (#746: what a `FiberHandle` held, in a field, so an app ships no FiberHandle): a
|
|
308
349
|
// new burst's replaces it, interrupting it, and the loop's Scope interrupts it and lets it go. Once
|
|
309
350
|
// that Scope has closed, the loop takes no run (`entered`), as the handle's closed state had it.
|
|
@@ -346,6 +387,16 @@ export const make = Effect.fnUntraced(
|
|
|
346
387
|
// The dt of the tick that opened the window: a Late step's. A nominal frame before any tick, for a
|
|
347
388
|
// window a hint opens while idle (#791).
|
|
348
389
|
let windowDt = Clock.NOMINAL_DT
|
|
390
|
+
// The ticks run, for `tickCount` (#991): one add a tick.
|
|
391
|
+
let ticked = 0
|
|
392
|
+
// A late frame, as the Environment tells one (#1026, `Clock.LateFrames`): the line, in ms, `NaN` for
|
|
393
|
+
// none. Telling one, each tick reads its frame's timestamp and when it ran, on the Clock's `now()`, and
|
|
394
|
+
// what a long task held of it, in seconds; a window a hint opens tells nothing.
|
|
395
|
+
const lateAfter = lateAfterOf(yield* Clock.LateFrames)
|
|
396
|
+
const tellsLate = !Number.isNaN(lateAfter)
|
|
397
|
+
let windowRanAt = Number.NaN
|
|
398
|
+
let windowLate = 0
|
|
399
|
+
let lastStamp = Number.NaN
|
|
349
400
|
// The `run` runs added in the window, in add order: their Late step is due. The `runLast` runs added
|
|
350
401
|
// in it take none, and are marked only so the dt-0 step leaves them out: they step at the next tick.
|
|
351
402
|
const lateFirst: Array<Entry> = []
|
|
@@ -379,11 +430,60 @@ export const make = Effect.fnUntraced(
|
|
|
379
430
|
}
|
|
380
431
|
// The loop's own hook, the first: the counts reach the counters at the end of every tick, and
|
|
381
432
|
// `tick`, the per-frame path, is as it was (#542).
|
|
382
|
-
hooks = [{ hook: countEnds }]
|
|
433
|
+
hooks = [{ hook: countEnds, failing: false }]
|
|
383
434
|
|
|
384
435
|
// Per frame (ADR-0025): plain calls only, in the one `Stream.map` call per tick (ADR-0027,
|
|
385
436
|
// decision 8); counted loops, statement `if`s, a `try` per entry (it costs nothing measurable).
|
|
386
437
|
|
|
438
|
+
/**
|
|
439
|
+
* The tick's frame, told late or on time (#1026): late once its callback ran past the line after its
|
|
440
|
+
* timestamp, a long task holding it. A frame that repeats the one before's timestamp (Firefox's after
|
|
441
|
+
* an input), which the Clock times by `now()`, is on time. Once a tick, where late frames are told.
|
|
442
|
+
*/
|
|
443
|
+
const tellLate = (): void => {
|
|
444
|
+
const stamp = clock.frameAt()
|
|
445
|
+
const ranAt = clock.now()
|
|
446
|
+
let late = 0
|
|
447
|
+
if (stamp !== lastStamp && ranAt - stamp > lateAfter) late = (ranAt - stamp) / 1000
|
|
448
|
+
lastStamp = stamp
|
|
449
|
+
windowRanAt = ranAt
|
|
450
|
+
windowLate = late
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* The dt `entry` steps at (#1026): the tick's, but a run takes none of a long task's time from before it
|
|
455
|
+
* was on the page. A long task delays a frame, whose timestamp is the time it was due, from before the
|
|
456
|
+
* task, so the next frame's dt holds the task's time. A run made in that task leaves out what that
|
|
457
|
+
* frame was held of its second step; one made in that frame's Late window and first stepped at the next
|
|
458
|
+
* tick, of its first; and one that waited past the line for its first frame (Motion's
|
|
459
|
+
* `MAX_START_DELAY`, however its frame is stamped) begins there, a 60 Hz frame at most. What was
|
|
460
|
+
* running catches up, as before; a run on the frame timeline keeps the ticks' dt. Per frame: a field
|
|
461
|
+
* read, and nothing made.
|
|
462
|
+
*/
|
|
463
|
+
const dtOf = (entry: Entry, dt: number): number => {
|
|
464
|
+
const owed = entry.owed
|
|
465
|
+
if (owed === 0) return dt
|
|
466
|
+
if (owed > 0) {
|
|
467
|
+
entry.owed = 0
|
|
468
|
+
return leavingOut(dt, owed)
|
|
469
|
+
}
|
|
470
|
+
return firstDt(entry, dt, entry.madeLate)
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/** A run's first step (`owed` `NaN`): what of its frame a long task held, owed to its second; `before` left out. */
|
|
474
|
+
const firstDt = (entry: Entry, dt: number, before: number): number => {
|
|
475
|
+
entry.owed = windowLate
|
|
476
|
+
if (windowRanAt - entry.madeAt > lateAfter) return Math.min(dt, Clock.NOMINAL_DT)
|
|
477
|
+
if (before > 0) return leavingOut(dt, before)
|
|
478
|
+
return dt
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/** A Late step's dt: its first step, in the window it was made in, with nothing of the window's left out. */
|
|
482
|
+
const lateDtOf = (entry: Entry, dt: number): number => {
|
|
483
|
+
if (entry.owed === 0) return dt
|
|
484
|
+
return firstDt(entry, dt, 0)
|
|
485
|
+
}
|
|
486
|
+
|
|
387
487
|
/**
|
|
388
488
|
* Step the last lane's first `count` entries, in add order, as `tick` steps the others. Per frame,
|
|
389
489
|
* and only while it holds a run.
|
|
@@ -393,8 +493,9 @@ export const make = Effect.fnUntraced(
|
|
|
393
493
|
const entry = lastEntries[i]
|
|
394
494
|
if (entry.removed) continue
|
|
395
495
|
try {
|
|
396
|
-
const
|
|
397
|
-
entry.
|
|
496
|
+
const at = dtOf(entry, dt)
|
|
497
|
+
const frame = entry.step(at)
|
|
498
|
+
entry.sink(frame, at)
|
|
398
499
|
if (entry.settles && frame.done) end(entry, Exit.succeed(frame))
|
|
399
500
|
} catch (defect) {
|
|
400
501
|
end(entry, dieNamed(entry.name, defect))
|
|
@@ -418,11 +519,13 @@ export const make = Effect.fnUntraced(
|
|
|
418
519
|
// The first lane's loops stay inline in `tick`: moved into a function shared with the last lane,
|
|
419
520
|
// Node's `chase/loop` ran 55% slower (`bench:core`, ADR-0027 *Amendment (#137)*).
|
|
420
521
|
const tick = (dt: number): boolean => {
|
|
522
|
+
ticked++
|
|
421
523
|
// A window this tick finds open is the last frame's, its checkpoint not yet run (back-to-back
|
|
422
524
|
// frames in a test): its runs are on the lanes, so this tick steps them.
|
|
423
525
|
if (lateFirst.length + lateLast.length > 0) dropLate()
|
|
424
526
|
windowOpen = true
|
|
425
527
|
windowDt = dt
|
|
528
|
+
if (tellsLate) tellLate()
|
|
426
529
|
// The tick's start, read only for the metrics' histogram (#518).
|
|
427
530
|
let t0 = 0
|
|
428
531
|
if (Predicate.isNotUndefined(metrics)) t0 = performance.now()
|
|
@@ -434,8 +537,9 @@ export const make = Effect.fnUntraced(
|
|
|
434
537
|
const entry = entries[i]
|
|
435
538
|
if (entry.removed) continue
|
|
436
539
|
try {
|
|
437
|
-
const
|
|
438
|
-
entry.
|
|
540
|
+
const at = dtOf(entry, dt)
|
|
541
|
+
const frame = entry.step(at)
|
|
542
|
+
entry.sink(frame, at)
|
|
439
543
|
if (entry.settles && frame.done) end(entry, Exit.succeed(frame))
|
|
440
544
|
} catch (defect) {
|
|
441
545
|
end(entry, dieNamed(entry.name, defect))
|
|
@@ -459,8 +563,19 @@ export const make = Effect.fnUntraced(
|
|
|
459
563
|
}
|
|
460
564
|
// The end of the tick: everything for this Refresh frame is written (ADR-0033). After
|
|
461
565
|
// `tickMs`, which stays the cost of the steps alone.
|
|
566
|
+
// Each hook's own (#979, ADR-0074): one that throws is reported once until a call returns, and the
|
|
567
|
+
// others run. A try per hook, around its direct call, its flag cleared only when it's set.
|
|
462
568
|
const ended = hooks
|
|
463
|
-
for (let i = 0; i < ended.length; i++)
|
|
569
|
+
for (let i = 0; i < ended.length; i++) {
|
|
570
|
+
const added = ended[i]
|
|
571
|
+
try {
|
|
572
|
+
added.hook(dt)
|
|
573
|
+
if (added.failing) added.failing = false
|
|
574
|
+
} catch (defect) {
|
|
575
|
+
if (!added.failing) hookFailed(defect)
|
|
576
|
+
added.failing = true
|
|
577
|
+
}
|
|
578
|
+
}
|
|
464
579
|
// The window stays open to the end of this frame's microtasks, which take the Late steps (#680).
|
|
465
580
|
if (!windowQueued) {
|
|
466
581
|
windowQueued = true
|
|
@@ -486,11 +601,14 @@ export const make = Effect.fnUntraced(
|
|
|
486
601
|
list.length = left
|
|
487
602
|
}
|
|
488
603
|
|
|
489
|
-
/**
|
|
490
|
-
|
|
604
|
+
/**
|
|
605
|
+
* One step of `entry` at `at`: its Frame to its sink, its settle, or its defect, as a tick's. A Late
|
|
606
|
+
* step's dt is its first's (`lateDtOf`); a dt-0 step leaves what it owes as it was.
|
|
607
|
+
*/
|
|
608
|
+
const stepOne = (entry: Entry, at: number): void => {
|
|
491
609
|
try {
|
|
492
|
-
const frame = entry.step(
|
|
493
|
-
entry.sink(frame,
|
|
610
|
+
const frame = entry.step(at)
|
|
611
|
+
entry.sink(frame, at)
|
|
494
612
|
if (entry.settles && frame.done) end(entry, Exit.succeed(frame))
|
|
495
613
|
} catch (defect) {
|
|
496
614
|
end(entry, dieNamed(entry.name, defect))
|
|
@@ -502,7 +620,7 @@ export const make = Effect.fnUntraced(
|
|
|
502
620
|
entry.late = false
|
|
503
621
|
if (entry.removed) return false
|
|
504
622
|
if (Predicate.isNotUndefined(entry.span)) entry.span.attribute("late", true)
|
|
505
|
-
stepOne(entry, windowDt)
|
|
623
|
+
stepOne(entry, lateDtOf(entry, windowDt))
|
|
506
624
|
return true
|
|
507
625
|
}
|
|
508
626
|
|
|
@@ -525,7 +643,17 @@ export const make = Effect.fnUntraced(
|
|
|
525
643
|
}
|
|
526
644
|
dropFirst(lateFirst, firstCount)
|
|
527
645
|
const again = hooks
|
|
528
|
-
|
|
646
|
+
// As the tick's (#979).
|
|
647
|
+
for (let i = 0; i < again.length; i++) {
|
|
648
|
+
const added = again[i]
|
|
649
|
+
try {
|
|
650
|
+
added.hook(windowDt)
|
|
651
|
+
if (added.failing) added.failing = false
|
|
652
|
+
} catch (defect) {
|
|
653
|
+
if (!added.failing) hookFailed(defect)
|
|
654
|
+
added.failing = true
|
|
655
|
+
}
|
|
656
|
+
}
|
|
529
657
|
}
|
|
530
658
|
|
|
531
659
|
/**
|
|
@@ -572,14 +700,19 @@ export const make = Effect.fnUntraced(
|
|
|
572
700
|
if (windowOpen) return
|
|
573
701
|
if (bursting && clock.frameAt() !== frameTime) return
|
|
574
702
|
windowOpen = true
|
|
703
|
+
// No tick told its frame (#1026): a run made in it is told nothing late.
|
|
704
|
+
windowRanAt = Number.NaN
|
|
705
|
+
windowLate = 0
|
|
575
706
|
if (!windowQueued) {
|
|
576
707
|
windowQueued = true
|
|
577
708
|
queueMicrotask(endLateWindow)
|
|
578
709
|
}
|
|
579
710
|
}
|
|
580
711
|
|
|
712
|
+
const tickCount = (): number => ticked
|
|
713
|
+
|
|
581
714
|
const afterTick = (hook: (dt: number) => undefined): Effect.Effect<void, never, Scope.Scope> => {
|
|
582
|
-
const added: Hook = { hook }
|
|
715
|
+
const added: Hook = { hook, failing: false }
|
|
583
716
|
return Effect.acquireRelease(
|
|
584
717
|
Effect.sync(() => {
|
|
585
718
|
hooks = Arr.append(hooks, added)
|
|
@@ -709,6 +842,16 @@ export const make = Effect.fnUntraced(
|
|
|
709
842
|
if (closed) return Effect.interrupt
|
|
710
843
|
let checkedSink: FrameLoop.Sink<F> = sink
|
|
711
844
|
if (check) checkedSink = checked(sink)
|
|
845
|
+
// What a long task held of its first frames (#1026), where late frames are told and it isn't on the
|
|
846
|
+
// frame timeline: when it was made, and, made in a window, what its frame was held.
|
|
847
|
+
let owed = 0
|
|
848
|
+
let madeAt = Number.NaN
|
|
849
|
+
let madeLate = 0
|
|
850
|
+
if (tellsLate && !onFrameTimeline(options)) {
|
|
851
|
+
owed = Number.NaN
|
|
852
|
+
madeAt = clock.now()
|
|
853
|
+
if (windowOpen) madeLate = windowLate
|
|
854
|
+
}
|
|
712
855
|
const entry: Entry = {
|
|
713
856
|
name: machine.span.name,
|
|
714
857
|
step: machine.start(),
|
|
@@ -718,16 +861,19 @@ export const make = Effect.fnUntraced(
|
|
|
718
861
|
removed: false,
|
|
719
862
|
late: windowOpen,
|
|
720
863
|
span,
|
|
864
|
+
owed,
|
|
865
|
+
madeAt,
|
|
866
|
+
madeLate,
|
|
721
867
|
}
|
|
722
868
|
lane.push(entry)
|
|
723
869
|
if (entry.late) late.push(entry)
|
|
724
|
-
if (Predicate.isNotUndefined(options)) joinSupersede(options.supersede, entry)
|
|
870
|
+
if (Predicate.isNotUndefined(options) && Predicate.isNotUndefined(options.supersede)) joinSupersede(options.supersede, entry)
|
|
725
871
|
return Effect.as(startBurst, entry)
|
|
726
872
|
}
|
|
727
873
|
|
|
728
874
|
const inLateWindow = (): boolean => windowOpen
|
|
729
875
|
|
|
730
|
-
return { run: runIn(entries, lateFirst), runLast: runIn(lastEntries, lateLast), afterTick, inLateWindow, hint } satisfies Shape
|
|
876
|
+
return { run: runIn(entries, lateFirst), runLast: runIn(lastEntries, lateLast), afterTick, inLateWindow, tickCount, hint } satisfies Shape
|
|
731
877
|
},
|
|
732
878
|
(self) => traced(self, "wardic.frameloop.make"),
|
|
733
879
|
)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A watch's handler, guarded (#318, ADR-0055): a run of throws from it, from its first to the next call
|
|
3
|
+
* that returns, goes to the watch's `onDefect` at its first, else, with none, is reported then on the
|
|
4
|
+
* context the watch started in, and the watch goes on. `InputFeed`'s watches and its `switched` are built
|
|
5
|
+
* on it, and Recognizer's keys, which hand `switched` the context of the watch that opens them.
|
|
6
|
+
*/
|
|
7
|
+
// #979, row 27 (ADR-0074): with no `onDefect`, a throw went up the platform's dispatch, so a shared feed's
|
|
8
|
+
// later subscribers (a ward's own hover on the same element), a later node on the event's path and a later
|
|
9
|
+
// member missed the event. Every watch of Wardic's own passes an `onDefect`, each a binding's report.
|
|
10
|
+
// #979 group I, row 26 (decision 3): `onDefect` heard every throw, so a handler throwing at each move was
|
|
11
|
+
// logged at each; it hears a run's first now, as the report with none does. A watch of many members
|
|
12
|
+
// (`watchDragAmong`) is one handler, so its members share a run.
|
|
13
|
+
import * as Cause from "effect/Cause"
|
|
14
|
+
import type * as Context from "effect/Context"
|
|
15
|
+
import * as Effect from "effect/Effect"
|
|
16
|
+
import { constVoid } from "effect/Function"
|
|
17
|
+
import * as Predicate from "effect/Predicate"
|
|
18
|
+
import * as UndefinedOr from "effect/UndefinedOr"
|
|
19
|
+
import type { InputFeed, OnDefect, Switch } from "../InputFeed.ts"
|
|
20
|
+
import * as Report from "../unstable/Report.ts"
|
|
21
|
+
|
|
22
|
+
/** A watch's handler that threw, with no `onDefect` to take it. */
|
|
23
|
+
const HANDLER_FAILED = "wardic.input: a watch's handler failed"
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The context a watch with no `onDefect` reports on: the one it starts in, read only for such a watch.
|
|
27
|
+
* `undefined` with an `onDefect`, which takes the throws.
|
|
28
|
+
*/
|
|
29
|
+
export const contextFor = (onDefect: OnDefect | undefined): Effect.Effect<Context.Context<never> | undefined> =>
|
|
30
|
+
UndefinedOr.match(onDefect, { onDefined: () => Effect.succeed(undefined), onUndefined: () => Effect.context<never>() })
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* `handle`, a run of throws from it (from its first throw to the next call that returns) handed to
|
|
34
|
+
* `onDefect` at its first; with none, reported then on `context`. The next event is heard either way.
|
|
35
|
+
*/
|
|
36
|
+
export const guarded = <A>(handle: (event: A) => void, onDefect: OnDefect | undefined, context: Context.Context<never> | undefined): ((event: A) => void) => {
|
|
37
|
+
const tell = UndefinedOr.match(onDefect, {
|
|
38
|
+
onDefined: (defect) => (error: unknown) => defect(Cause.die(error)),
|
|
39
|
+
onUndefined: () => (error: unknown) => Report.failureOn(context, HANDLER_FAILED, Cause.die(error)),
|
|
40
|
+
})
|
|
41
|
+
let failing = false
|
|
42
|
+
return (event: A): void => {
|
|
43
|
+
try {
|
|
44
|
+
handle(event)
|
|
45
|
+
if (failing) failing = false
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (failing) return
|
|
48
|
+
failing = true
|
|
49
|
+
tell(error)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** `InputFeed.switched`, its handler guarded with `context` for a throw with no `onDefect`. */
|
|
55
|
+
export const switchedOn = <A>(feed: InputFeed<A>, handle: (event: A) => void, onDefect: OnDefect | undefined, context: Context.Context<never> | undefined): Switch => {
|
|
56
|
+
const on = guarded(handle, onDefect, context)
|
|
57
|
+
let stop: (() => void) | undefined
|
|
58
|
+
return {
|
|
59
|
+
open: () => {
|
|
60
|
+
if (Predicate.isUndefined(stop)) stop = feed(on, constVoid)
|
|
61
|
+
},
|
|
62
|
+
close: () => {
|
|
63
|
+
if (Predicate.isUndefined(stop)) return
|
|
64
|
+
const running = stop
|
|
65
|
+
stop = undefined
|
|
66
|
+
running()
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/internal/stepper.ts
CHANGED
|
@@ -42,8 +42,15 @@ export const durationOf = (duration: number): number => {
|
|
|
42
42
|
|
|
43
43
|
// --- Tween -------------------------------------------------------------------
|
|
44
44
|
|
|
45
|
+
/** A tween run's time, rewritten in place each tick (#895): a field, which V8 rewrites where it is. */
|
|
45
46
|
export interface TweenState {
|
|
46
|
-
|
|
47
|
+
elapsed: number
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A run's own Frame, rewritten in place each tick (#895): a tween's, a blend's. */
|
|
51
|
+
export interface WritableFrame<A> {
|
|
52
|
+
value: A
|
|
53
|
+
done: boolean
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
/** A tween's options with every default filled in. */
|
|
@@ -102,19 +109,21 @@ export const resolveTween: (options: TweenOptions) => ResolvedTween = /*#__PURE_
|
|
|
102
109
|
|
|
103
110
|
export const initTween = (): TweenState => ({ elapsed: 0 })
|
|
104
111
|
|
|
105
|
-
/** One frame of a resolved tween. */
|
|
112
|
+
/** One frame of a resolved tween, into its run's `state` and `frame`: nothing made (#895). */
|
|
106
113
|
export const stepTween = (
|
|
107
114
|
state: TweenState,
|
|
115
|
+
frame: WritableFrame<number>,
|
|
108
116
|
dt: number,
|
|
109
117
|
from: number,
|
|
110
118
|
to: number,
|
|
111
119
|
tween: ResolvedTween,
|
|
112
|
-
):
|
|
120
|
+
): void => {
|
|
113
121
|
const elapsed = state.elapsed + dt
|
|
122
|
+
state.elapsed = elapsed
|
|
114
123
|
const active = Math.max(0, elapsed - tween.delay)
|
|
115
124
|
const t = Scalar.clamp(active / tween.duration, 0, 1)
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
frame.value = Scalar.lerp(from, to, tween.ease(t))
|
|
126
|
+
frame.done = elapsed >= tween.delay + tween.duration
|
|
118
127
|
}
|
|
119
128
|
|
|
120
129
|
// --- A run of repeats, and keyframes (#226) ----------------------------------
|