@wardic/core 1.3.2 → 1.5.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/dist/Arc.d.ts +2 -2
  2. package/dist/Arc.js +1 -1
  3. package/dist/BaseValue.d.ts +11 -10
  4. package/dist/BaseValue.d.ts.map +1 -1
  5. package/dist/BaseValue.js +12 -15
  6. package/dist/BaseValue.js.map +1 -1
  7. package/dist/Batch.d.ts +15 -5
  8. package/dist/Batch.d.ts.map +1 -1
  9. package/dist/Batch.js +218 -20
  10. package/dist/Batch.js.map +1 -1
  11. package/dist/Clock.d.ts +7 -7
  12. package/dist/Clock.d.ts.map +1 -1
  13. package/dist/Clock.js +17 -16
  14. package/dist/Clock.js.map +1 -1
  15. package/dist/DefaultTransition.d.ts +3 -2
  16. package/dist/DefaultTransition.d.ts.map +1 -1
  17. package/dist/DefaultTransition.js +5 -3
  18. package/dist/DefaultTransition.js.map +1 -1
  19. package/dist/Drag.d.ts +24 -9
  20. package/dist/Drag.d.ts.map +1 -1
  21. package/dist/Drag.js +10 -10
  22. package/dist/Drag.js.map +1 -1
  23. package/dist/DragActivity.js +3 -3
  24. package/dist/DragRecognizer.d.ts +8 -6
  25. package/dist/DragRecognizer.d.ts.map +1 -1
  26. package/dist/DragRecognizer.js +51 -16
  27. package/dist/DragRecognizer.js.map +1 -1
  28. package/dist/Easing.d.ts +1 -1
  29. package/dist/Easing.js +1 -1
  30. package/dist/Frame.d.ts.map +1 -1
  31. package/dist/Frame.js +5 -3
  32. package/dist/Frame.js.map +1 -1
  33. package/dist/InputFeed.d.ts +1 -1
  34. package/dist/InputFeed.js +2 -2
  35. package/dist/InputSource.d.ts +9 -3
  36. package/dist/InputSource.d.ts.map +1 -1
  37. package/dist/InputSource.js +2 -2
  38. package/dist/InputSource.js.map +1 -1
  39. package/dist/Interpolator.d.ts +2 -2
  40. package/dist/Interpolator.js +2 -2
  41. package/dist/InterpolatorRegistry.d.ts +29 -15
  42. package/dist/InterpolatorRegistry.d.ts.map +1 -1
  43. package/dist/InterpolatorRegistry.js +17 -8
  44. package/dist/InterpolatorRegistry.js.map +1 -1
  45. package/dist/LiveValue.d.ts +7 -6
  46. package/dist/LiveValue.d.ts.map +1 -1
  47. package/dist/LiveValue.js +45 -14
  48. package/dist/LiveValue.js.map +1 -1
  49. package/dist/Machine.d.ts +7 -4
  50. package/dist/Machine.d.ts.map +1 -1
  51. package/dist/Machine.js +146 -45
  52. package/dist/Machine.js.map +1 -1
  53. package/dist/Playback.d.ts.map +1 -1
  54. package/dist/Playback.js +6 -1
  55. package/dist/Playback.js.map +1 -1
  56. package/dist/Projection.d.ts +8 -19
  57. package/dist/Projection.d.ts.map +1 -1
  58. package/dist/Projection.js +3 -19
  59. package/dist/Projection.js.map +1 -1
  60. package/dist/Recognizer.d.ts +1 -1
  61. package/dist/Recognizer.d.ts.map +1 -1
  62. package/dist/Recognizer.js +22 -7
  63. package/dist/Recognizer.js.map +1 -1
  64. package/dist/ReducedMotion.d.ts +4 -4
  65. package/dist/ReducedMotion.js +6 -6
  66. package/dist/Renderer.d.ts +5 -5
  67. package/dist/Renderer.js +6 -6
  68. package/dist/Renderer.js.map +1 -1
  69. package/dist/Reorder.d.ts +12 -2
  70. package/dist/Reorder.d.ts.map +1 -1
  71. package/dist/Reorder.js +65 -37
  72. package/dist/Reorder.js.map +1 -1
  73. package/dist/ScrollSource.d.ts +1 -1
  74. package/dist/ScrollSource.d.ts.map +1 -1
  75. package/dist/Sequence.d.ts +1 -1
  76. package/dist/SharedSource.d.ts +3 -3
  77. package/dist/SharedSource.js +5 -5
  78. package/dist/SharedSource.js.map +1 -1
  79. package/dist/Spring.d.ts.map +1 -1
  80. package/dist/Spring.js +2 -1
  81. package/dist/Spring.js.map +1 -1
  82. package/dist/Values.d.ts +2 -2
  83. package/dist/Values.js +1 -1
  84. package/dist/index.d.ts +1 -1
  85. package/dist/index.js +1 -1
  86. package/dist/internal/carried.d.ts +13 -0
  87. package/dist/internal/carried.d.ts.map +1 -0
  88. package/dist/internal/carried.js +23 -0
  89. package/dist/internal/carried.js.map +1 -0
  90. package/dist/internal/firstSteps.d.ts +66 -0
  91. package/dist/internal/firstSteps.d.ts.map +1 -0
  92. package/dist/internal/firstSteps.js +107 -0
  93. package/dist/internal/firstSteps.js.map +1 -0
  94. package/dist/internal/frameLoop.d.ts +1 -1
  95. package/dist/internal/frameLoop.d.ts.map +1 -1
  96. package/dist/internal/frameLoop.js +102 -81
  97. package/dist/internal/frameLoop.js.map +1 -1
  98. package/dist/internal/lerpsNumbers.d.ts +11 -0
  99. package/dist/internal/lerpsNumbers.d.ts.map +1 -0
  100. package/dist/internal/lerpsNumbers.js +38 -0
  101. package/dist/internal/lerpsNumbers.js.map +1 -0
  102. package/dist/internal/options.d.ts +7 -7
  103. package/dist/internal/options.d.ts.map +1 -1
  104. package/dist/internal/options.js +10 -10
  105. package/dist/internal/options.js.map +1 -1
  106. package/dist/internal/projectionRest.d.ts +22 -0
  107. package/dist/internal/projectionRest.d.ts.map +1 -0
  108. package/dist/internal/projectionRest.js +20 -0
  109. package/dist/internal/projectionRest.js.map +1 -0
  110. package/dist/internal/stepper.d.ts +13 -2
  111. package/dist/internal/stepper.d.ts.map +1 -1
  112. package/dist/internal/stepper.js +16 -1
  113. package/dist/internal/stepper.js.map +1 -1
  114. package/dist/internal/tracing.d.ts +1 -1
  115. package/dist/internal/tracing.js +1 -1
  116. package/dist/unstable/AnimationControls.d.ts +37 -38
  117. package/dist/unstable/AnimationControls.d.ts.map +1 -1
  118. package/dist/unstable/AnimationControls.js +39 -36
  119. package/dist/unstable/AnimationControls.js.map +1 -1
  120. package/dist/unstable/AppearHandoff.d.ts +5 -5
  121. package/dist/unstable/AppearHandoff.d.ts.map +1 -1
  122. package/dist/unstable/BatchCalls.d.ts +2 -2
  123. package/dist/unstable/BatchCalls.js +5 -5
  124. package/dist/unstable/Config.d.ts +19 -19
  125. package/dist/unstable/Config.d.ts.map +1 -1
  126. package/dist/unstable/FirstSteps.d.ts +25 -0
  127. package/dist/unstable/FirstSteps.d.ts.map +1 -0
  128. package/dist/unstable/FirstSteps.js +2 -0
  129. package/dist/unstable/FirstSteps.js.map +1 -0
  130. package/dist/unstable/FlushGate.d.ts +53 -51
  131. package/dist/unstable/FlushGate.d.ts.map +1 -1
  132. package/dist/unstable/FlushGate.js +56 -49
  133. package/dist/unstable/FlushGate.js.map +1 -1
  134. package/dist/unstable/FrameEffects.d.ts +2 -2
  135. package/dist/unstable/FrameEffects.js +2 -2
  136. package/dist/unstable/FrameTime.d.ts +1 -1
  137. package/dist/unstable/FrameTime.js +1 -1
  138. package/dist/unstable/Imperative.d.ts +29 -9
  139. package/dist/unstable/Imperative.d.ts.map +1 -1
  140. package/dist/unstable/Imperative.js +79 -47
  141. package/dist/unstable/Imperative.js.map +1 -1
  142. package/dist/unstable/OwnValues.js +1 -1
  143. package/dist/unstable/PresenceRecord.d.ts +31 -27
  144. package/dist/unstable/PresenceRecord.d.ts.map +1 -1
  145. package/dist/unstable/PresenceRecord.js +8 -8
  146. package/dist/unstable/PresenceRecord.js.map +1 -1
  147. package/dist/unstable/Projector.d.ts +34 -0
  148. package/dist/unstable/Projector.d.ts.map +1 -0
  149. package/dist/unstable/Projector.js +9 -0
  150. package/dist/unstable/Projector.js.map +1 -0
  151. package/dist/unstable/Report.d.ts +1 -1
  152. package/dist/unstable/Report.js +1 -1
  153. package/dist/unstable/RetargetLegs.d.ts +1 -1
  154. package/dist/unstable/RetargetLegs.d.ts.map +1 -1
  155. package/dist/unstable/RetargetLegs.js +9 -8
  156. package/dist/unstable/RetargetLegs.js.map +1 -1
  157. package/dist/unstable/Spine.d.ts +81 -72
  158. package/dist/unstable/Spine.d.ts.map +1 -1
  159. package/dist/unstable/Spine.js +171 -164
  160. package/dist/unstable/Spine.js.map +1 -1
  161. package/dist/unstable/Stops.d.ts +3 -3
  162. package/dist/unstable/Stops.js +4 -4
  163. package/dist/unstable/Subject.d.ts +2 -2
  164. package/dist/unstable/Subject.js +2 -2
  165. package/dist/unstable/Timelines.d.ts +11 -11
  166. package/dist/unstable/Timelines.d.ts.map +1 -1
  167. package/dist/unstable/Timelines.js +3 -3
  168. package/dist/unstable/VariantTarget.d.ts +7 -7
  169. package/dist/unstable/VariantTarget.d.ts.map +1 -1
  170. package/dist/unstable/VariantTarget.js +11 -11
  171. package/dist/unstable/VariantTarget.js.map +1 -1
  172. package/dist/unstable/VariantTree.d.ts +43 -36
  173. package/dist/unstable/VariantTree.d.ts.map +1 -1
  174. package/dist/unstable/VariantTree.js +34 -34
  175. package/dist/unstable/VariantTree.js.map +1 -1
  176. package/dist/unstable/WardicConfigValue.d.ts +13 -13
  177. package/dist/unstable/WardicConfigValue.d.ts.map +1 -1
  178. package/dist/unstable/WardicConfigValue.js +4 -4
  179. package/dist/unstable/WardicConfigValue.js.map +1 -1
  180. package/package.json +1 -1
  181. package/src/Arc.ts +3 -3
  182. package/src/BaseValue.ts +18 -21
  183. package/src/Batch.ts +236 -22
  184. package/src/Clock.ts +18 -17
  185. package/src/DefaultTransition.ts +5 -3
  186. package/src/Drag.ts +32 -14
  187. package/src/DragActivity.ts +3 -3
  188. package/src/DragRecognizer.ts +65 -23
  189. package/src/Easing.ts +1 -1
  190. package/src/Frame.ts +5 -3
  191. package/src/InputFeed.ts +2 -2
  192. package/src/InputSource.ts +12 -5
  193. package/src/Interpolator.ts +3 -3
  194. package/src/InterpolatorRegistry.ts +22 -13
  195. package/src/LiveValue.ts +47 -17
  196. package/src/Machine.ts +199 -61
  197. package/src/Playback.ts +5 -1
  198. package/src/Projection.ts +10 -28
  199. package/src/Recognizer.ts +24 -8
  200. package/src/ReducedMotion.ts +6 -6
  201. package/src/Renderer.ts +6 -6
  202. package/src/Reorder.ts +84 -38
  203. package/src/ScrollSource.ts +1 -1
  204. package/src/Sequence.ts +1 -1
  205. package/src/SharedSource.ts +5 -5
  206. package/src/Spring.ts +2 -1
  207. package/src/Values.ts +2 -2
  208. package/src/index.ts +1 -1
  209. package/src/internal/carried.ts +22 -0
  210. package/src/internal/firstSteps.ts +139 -0
  211. package/src/internal/frameLoop.ts +103 -87
  212. package/src/internal/lerpsNumbers.ts +53 -0
  213. package/src/internal/options.ts +10 -10
  214. package/src/internal/projectionRest.ts +31 -0
  215. package/src/internal/stepper.ts +20 -2
  216. package/src/internal/tracing.ts +1 -1
  217. package/src/unstable/AnimationControls.ts +59 -56
  218. package/src/unstable/AppearHandoff.ts +6 -6
  219. package/src/unstable/BatchCalls.ts +5 -5
  220. package/src/unstable/Config.ts +19 -19
  221. package/src/unstable/FirstSteps.ts +26 -0
  222. package/src/unstable/FlushGate.ts +92 -82
  223. package/src/unstable/FrameEffects.ts +2 -2
  224. package/src/unstable/FrameTime.ts +1 -1
  225. package/src/unstable/Imperative.ts +126 -56
  226. package/src/unstable/OwnValues.ts +1 -1
  227. package/src/unstable/PresenceRecord.ts +34 -30
  228. package/src/unstable/Projector.ts +45 -0
  229. package/src/unstable/Report.ts +1 -1
  230. package/src/unstable/RetargetLegs.ts +10 -9
  231. package/src/unstable/Spine.ts +210 -201
  232. package/src/unstable/Stops.ts +6 -6
  233. package/src/unstable/Subject.ts +2 -2
  234. package/src/unstable/Timelines.ts +12 -12
  235. package/src/unstable/VariantTarget.ts +13 -13
  236. package/src/unstable/VariantTree.ts +50 -43
  237. package/src/unstable/WardicConfigValue.ts +13 -13
@@ -2,7 +2,7 @@
2
2
  * The **Frame loop**'s implementation (ADR-0027), behind the `FrameLoop` module's service and
3
3
  * `layer` (ADR-0028, decision 11): one fiber per burst that steps every running
4
4
  * Primitive's machine once per tick, in one pass, and hands each its Frame. Each animation used
5
- * to be a fiber running its own `Stream`; at 1,000 elements that machinery was about 90% of a
5
+ * to be a fiber running its own `Stream`; at 1,000 Subjects that machinery was about 90% of a
6
6
  * Primitive's per-frame cost.
7
7
  *
8
8
  * - **A run** is `run(machine, sink)`: an entry added, its Frames handed to `sink` from the loop's
@@ -24,13 +24,13 @@
24
24
  * starts while the ending burst resumes its runs (#81).
25
25
  * - **The end of a tick** calls each `afterTick` hook, with the tick's dt, after every step and sink
26
26
  * and the continuations of the runs that settled in it, the tick that ends a burst included. The flush
27
- * gate flushes there, so a value paints in the Refresh frame that computed it (ADR-0033). A run
27
+ * gate flushes there, so a value is drawn in the Refresh frame that computed it (ADR-0033). A run
28
28
  * a hook starts keeps the burst: whether it ends is counted after the hooks (#209).
29
29
  * - **The Late window** runs from a tick's first step until a microtask the tick queues at its end
30
30
  * (ADR-0027 *Amendment (#680)*): what starts in it is drawn in that tick's Refresh frame, after the
31
31
  * tick. A run `run` added in it, during the tick or in a microtask the tick's own code queued (Solid
32
32
  * 2's effects, a promise it resolved), takes its **Late step** in that microtask: one step at the
33
- * tick's dt, and the hooks again, so the frame paints it, not its origin. A round whose steps or hooks
33
+ * tick's dt, and the hooks again, so the frame draws it, not its origin. A round whose steps or hooks
34
34
  * add more runs is followed by another, at most `MAX_LATE_ROUNDS`; the rest step at the next tick. A
35
35
  * `runLast` run takes none: the projection's coordinator, its one caller, would step again the nodes
36
36
  * an after-tick Measure pass already stepped. One the tick stepped steps again at dt 0 after a round
@@ -81,6 +81,7 @@ 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
83
  import * as Report from "../unstable/Report.ts"
84
+ import * as FirstSteps from "./firstSteps.ts"
84
85
  import { none, SpansGiven, traced } from "./tracing.ts"
85
86
 
86
87
  // @wardic/core compiles against ES2022 alone, which does not declare `performance` (see
@@ -155,7 +156,7 @@ export interface Shape {
155
156
  * frame's tick, as a binding that renders in a frame callback of its own does (ADR-0071 decision 32).
156
157
  * Opens the **Late window** when a burst's last tick was this frame's (`Clock.frameAt`) or no burst runs
157
158
  * (no tick is coming this frame), so the runs added after it, in the rest of the callback and its
158
- * microtasks, take their Late step and paint in this frame, and a queued Measure pass runs as an after-tick one. With a
159
+ * microtasks, take their Late step and are drawn in this frame, and a queued Measure pass runs as an after-tick one. With a
159
160
  * tick still to come in the frame, nothing: that tick is their first step. Idle, the Late step's dt is
160
161
  * the last tick's, or a nominal frame before any.
161
162
  */
@@ -188,15 +189,11 @@ interface Entry {
188
189
  /** Its span, when traced: marked `late` at its Late step (#680). */
189
190
  readonly span: Tracer.Span | undefined
190
191
  /**
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.
192
+ * What it owes of a long task's time (`FirstSteps`, #1026): its first step, until it's taken, then that
193
+ * frame's lateness, which its second step leaves out, then 0. 0 from the start for a run on
194
+ * the frame timeline, and on an Environment that tells no late frame.
194
195
  */
195
196
  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
200
197
  }
201
198
 
202
199
  /** How many Late rounds a window runs before the rest wait for the next tick: the Measure pass's cap (#680). */
@@ -214,9 +211,6 @@ const onFrameTimeline = (options: RunOptions | undefined): boolean => {
214
211
  return options.onFrameTimeline === true
215
212
  }
216
213
 
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
-
220
214
  /**
221
215
  * The Frame loop's metrics: the running animations, the runs that settled and failed, and each tick's
222
216
  * ms. None unless an app gives them (`FrameLoop.layerMetrics`, #518), so an app that reads none ships and
@@ -380,23 +374,39 @@ export const make = Effect.fnUntraced(
380
374
  // is held (#81).
381
375
  let bursting = false
382
376
  // The Late window (ADR-0027 *Amendment (#680)*): open from a tick's first step until the microtask
383
- // queued at its end has run. `windowQueued` keeps one microtask per window, however many ticks open
377
+ // queued at its end has run. `lateWindowQueued` keeps one microtask per window, however many ticks open
384
378
  // it before a checkpoint (a test firing frames back to back).
385
- let windowOpen = false
386
- let windowQueued = false
379
+ let lateWindowOpen = false
380
+ let lateWindowQueued = false
387
381
  // The dt of the tick that opened the window: a Late step's. A nominal frame before any tick, for a
388
382
  // window a hint opens while idle (#791).
389
- let windowDt = Clock.NOMINAL_DT
383
+ let tickDt = Clock.NOMINAL_DT
390
384
  // The ticks run, for `tickCount` (#991): one add a tick.
391
385
  let ticked = 0
392
386
  // A late frame, as the Environment tells one (#1026, `Clock.LateFrames`): the line, in ms, `NaN` for
393
387
  // 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.
388
+ // how late it is by its lag, in seconds (`tickLateByLag`); a hint's window while the loop idles tells nothing.
395
389
  const lateAfter = lateAfterOf(yield* Clock.LateFrames)
396
390
  const tellsLate = !Number.isNaN(lateAfter)
397
- let windowRanAt = Number.NaN
398
- let windowLate = 0
391
+ let tickLateByLag = 0
399
392
  let lastStamp = Number.NaN
393
+ // The frames' interval (`frameInterval`), once a tick, from the last five gaps between their timestamps, and
394
+ // how late the tick's frame is by its gap (`tickLateByGap`), in seconds (`FirstSteps.intervalOf`, `lateByGap`;
395
+ // #1048, #1050). The time between
396
+ // bursts is no frame's gap: a burst's first tick times none (`gapFrom` is `NaN` from its start), nor does a
397
+ // frame that repeats the one before's timestamp. A gap the loop hasn't timed is a 60 Hz frame's.
398
+ let gapFrom = Number.NaN
399
+ // The four gaps before the tick's, newest first.
400
+ let gapBefore1 = FirstSteps.NOMINAL_FRAME_MS
401
+ let gapBefore2 = FirstSteps.NOMINAL_FRAME_MS
402
+ let gapBefore3 = FirstSteps.NOMINAL_FRAME_MS
403
+ let gapBefore4 = FirstSteps.NOMINAL_FRAME_MS
404
+ let frameInterval = Clock.NOMINAL_DT
405
+ let tickLateByGap = 0
406
+ // Whether the tick is stepping its runs now (#1028): a step in its window after them is a Late step, the
407
+ // loop's own or one a run takes there itself (the projection's after-tick step), and a member made in the
408
+ // window owes it none of the window's frame, whose dt it takes.
409
+ let tickStepping = false
400
410
  // The `run` runs added in the window, in add order: their Late step is due. The `runLast` runs added
401
411
  // in it take none, and are marked only so the dt-0 step leaves them out: they step at the next tick.
402
412
  const lateFirst: Array<Entry> = []
@@ -436,52 +446,57 @@ export const make = Effect.fnUntraced(
436
446
  // decision 8); counted loops, statement `if`s, a `try` per entry (it costs nothing measurable).
437
447
 
438
448
  /**
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.
449
+ * The tick's frame, told late or on time (#1026): late by its lag once its callback ran past the line after
450
+ * its timestamp, a long task delaying it (`FirstSteps.lateByLag`). A frame that repeats the one before's
451
+ * timestamp (a runtime's second frame after an input), which the Clock times by `now()`, is on time. Its gap
452
+ * from the frame before, in a burst, times the frames' interval, and tells whether a long task delayed it,
453
+ * however it's stamped (`FirstSteps.lateByGap`). Once a tick, where late frames are told: the rule's numbers come from
454
+ * `FirstSteps`, and this keeps them.
442
455
  */
456
+ // A repeated timestamp: Firefox's frame right after an input (#18; ADR-0017, amended by #2).
443
457
  const tellLate = (): void => {
444
458
  const stamp = clock.frameAt()
445
- const ranAt = clock.now()
446
- let late = 0
447
- if (stamp !== lastStamp && ranAt - stamp > lateAfter) late = (ranAt - stamp) / 1000
459
+ tickLateByLag = 0
460
+ if (stamp !== lastStamp) tickLateByLag = FirstSteps.lateByLag(clock.now() - stamp, lateAfter) / 1000
461
+ tickLateByGap = 0
462
+ const gap = stamp - gapFrom
463
+ if (gap > 0) {
464
+ const interval = FirstSteps.intervalOf(gap, gapBefore1, gapBefore2, gapBefore3, gapBefore4)
465
+ tickLateByGap = FirstSteps.lateByGap(gap, interval) / 1000
466
+ frameInterval = interval / 1000
467
+ gapBefore4 = gapBefore3
468
+ gapBefore3 = gapBefore2
469
+ gapBefore2 = gapBefore1
470
+ gapBefore1 = gap
471
+ }
472
+ gapFrom = stamp
448
473
  lastStamp = stamp
449
- windowRanAt = ranAt
450
- windowLate = late
474
+ }
475
+
476
+ /**
477
+ * The loop's ticks as the rule reads them (`FirstSteps`): its own entries' dt, and a run's that keeps the
478
+ * rule per member, a Batch's, carried on the service (#1028). Its reads are the loop's own fields.
479
+ */
480
+ const reader: FirstSteps.Reader = {
481
+ madeOwing: () => {
482
+ if (!tellsLate) return 0
483
+ if (lateWindowOpen) return FirstSteps.madeOwing(tickLateByLag)
484
+ return FirstSteps.madeOwing(0)
485
+ },
486
+ owingDt: (owed, dt) => FirstSteps.owingDt(owed, dt, lateWindowOpen && !tickStepping, tickLateByGap, frameInterval),
487
+ owedAfter: (owed) => FirstSteps.owedAfter(owed, tickLateByLag),
451
488
  }
452
489
 
453
490
  /**
454
491
  * 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.
492
+ * began (`FirstSteps`). What was running catches up, as before; a run on the frame timeline keeps the
493
+ * ticks' dt. Per frame: a field read, and nothing made.
462
494
  */
463
495
  const dtOf = (entry: Entry, dt: number): number => {
464
496
  const owed = entry.owed
465
497
  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)
498
+ entry.owed = reader.owedAfter(owed)
499
+ return reader.owingDt(owed, dt)
485
500
  }
486
501
 
487
502
  /**
@@ -523,8 +538,8 @@ export const make = Effect.fnUntraced(
523
538
  // A window this tick finds open is the last frame's, its checkpoint not yet run (back-to-back
524
539
  // frames in a test): its runs are on the lanes, so this tick steps them.
525
540
  if (lateFirst.length + lateLast.length > 0) dropLate()
526
- windowOpen = true
527
- windowDt = dt
541
+ lateWindowOpen = true
542
+ tickDt = dt
528
543
  if (tellsLate) tellLate()
529
544
  // The tick's start, read only for the metrics' histogram (#518).
530
545
  let t0 = 0
@@ -533,6 +548,7 @@ export const make = Effect.fnUntraced(
533
548
  // Late step at the window's end, a `runLast` run waits for the next tick (#680).
534
549
  const count = entries.length
535
550
  const lastCount = lastEntries.length
551
+ tickStepping = true
536
552
  for (let i = 0; i < count; i++) {
537
553
  const entry = entries[i]
538
554
  if (entry.removed) continue
@@ -547,6 +563,7 @@ export const make = Effect.fnUntraced(
547
563
  }
548
564
  // The last lane, after every other run (ADR-0027, *Amendment (#137)*).
549
565
  if (lastCount > 0) stepLast(lastCount, dt)
566
+ tickStepping = false
550
567
  // Drop the removed entries in place, keeping order (and those added during the pass).
551
568
  let kept = 0
552
569
  for (let i = 0; i < entries.length; i++) {
@@ -577,8 +594,8 @@ export const make = Effect.fnUntraced(
577
594
  }
578
595
  }
579
596
  // The window stays open to the end of this frame's microtasks, which take the Late steps (#680).
580
- if (!windowQueued) {
581
- windowQueued = true
597
+ if (!lateWindowQueued) {
598
+ lateWindowQueued = true
582
599
  queueMicrotask(endLateWindow)
583
600
  }
584
601
  // The burst ends with no run left, counted after the hooks: one a hook started (the flush
@@ -603,7 +620,7 @@ export const make = Effect.fnUntraced(
603
620
 
604
621
  /**
605
622
  * 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.
623
+ * step's dt is its first's; a dt-0 step leaves what it owes as it was.
607
624
  */
608
625
  const stepOne = (entry: Entry, at: number): void => {
609
626
  try {
@@ -620,7 +637,7 @@ export const make = Effect.fnUntraced(
620
637
  entry.late = false
621
638
  if (entry.removed) return false
622
639
  if (Predicate.isNotUndefined(entry.span)) entry.span.attribute("late", true)
623
- stepOne(entry, lateDtOf(entry, windowDt))
640
+ stepOne(entry, dtOf(entry, tickDt))
624
641
  return true
625
642
  }
626
643
 
@@ -647,7 +664,7 @@ export const make = Effect.fnUntraced(
647
664
  for (let i = 0; i < again.length; i++) {
648
665
  const added = again[i]
649
666
  try {
650
- added.hook(windowDt)
667
+ added.hook(tickDt)
651
668
  if (added.failing) added.failing = false
652
669
  } catch (defect) {
653
670
  if (!added.failing) hookFailed(defect)
@@ -661,8 +678,8 @@ export const make = Effect.fnUntraced(
661
678
  * left past the cap steps at the next tick. A hook that throws ends every run, as in a tick (Q15).
662
679
  */
663
680
  const endLateWindow = (): void => {
664
- windowQueued = false
665
- if (!windowOpen) return
681
+ lateWindowQueued = false
682
+ if (!lateWindowOpen) return
666
683
  let rounds = 0
667
684
  try {
668
685
  while (lateFirst.length > 0 && rounds < MAX_LATE_ROUNDS) {
@@ -675,7 +692,7 @@ export const make = Effect.fnUntraced(
675
692
  }
676
693
  // Past the cap, the first lane's rest step at the next tick; the last lane's were never due.
677
694
  if (lateFirst.length + lateLast.length > 0) dropLate()
678
- windowOpen = false
695
+ lateWindowOpen = false
679
696
  }
680
697
 
681
698
  /**
@@ -697,14 +714,17 @@ export const make = Effect.fnUntraced(
697
714
 
698
715
  /** A binding's hint (above): the window opened under the rule, closed by the microtask it queues. */
699
716
  const hint = (frameTime: number): void => {
700
- if (windowOpen) return
717
+ if (lateWindowOpen) return
701
718
  if (bursting && clock.frameAt() !== frameTime) return
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
706
- if (!windowQueued) {
707
- windowQueued = true
719
+ lateWindowOpen = true
720
+ // Idle, no tick told its frame (#1026): a run made in it is told nothing late. While a burst runs, it's
721
+ // the frame the last tick told, which still stands (#1050).
722
+ if (!bursting) {
723
+ tickLateByLag = 0
724
+ tickLateByGap = 0
725
+ }
726
+ if (!lateWindowQueued) {
727
+ lateWindowQueued = true
708
728
  queueMicrotask(endLateWindow)
709
729
  }
710
730
  }
@@ -740,7 +760,7 @@ export const make = Effect.fnUntraced(
740
760
  // A burst that failed closes the window: no later call is in it (#673, TK3; #680). One that ran out
741
761
  // of runs leaves it open, so a run started after its last tick, in its frame, takes its Late step.
742
762
  if (failed) {
743
- windowOpen = false
763
+ lateWindowOpen = false
744
764
  dropLate()
745
765
  }
746
766
  Arr.forEach(Arr.appendAll(entries.splice(0), lastEntries.splice(0)), (entry) => {
@@ -769,6 +789,8 @@ export const make = Effect.fnUntraced(
769
789
  onTrue: () => Effect.void,
770
790
  onFalse: () => {
771
791
  bursting = true
792
+ // The time since the last burst's last frame is no frame's gap (#1048).
793
+ gapFrom = Number.NaN
772
794
  // Detached and started at once, as `FiberHandle.run` forks: no scheduler hop before the
773
795
  // subscription, and no caller's fiber its parent.
774
796
  return Effect.map(Effect.forkDetach(ticking, START_NOW), hold)
@@ -842,16 +864,10 @@ export const make = Effect.fnUntraced(
842
864
  if (closed) return Effect.interrupt
843
865
  let checkedSink: FrameLoop.Sink<F> = sink
844
866
  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.
867
+ // What it owes of its first frames' lateness (#1026), where late frames are told and it isn't on the
868
+ // frame timeline: its first step owed, made in a window or not.
847
869
  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
- }
870
+ if (tellsLate && !onFrameTimeline(options)) owed = reader.madeOwing()
855
871
  const entry: Entry = {
856
872
  name: machine.span.name,
857
873
  step: machine.start(),
@@ -859,11 +875,9 @@ export const make = Effect.fnUntraced(
859
875
  settles: machine.settles,
860
876
  settled: Deferred.makeUnsafe<Frame.Frame<unknown> | Supersede.Superseded>(),
861
877
  removed: false,
862
- late: windowOpen,
878
+ late: lateWindowOpen,
863
879
  span,
864
880
  owed,
865
- madeAt,
866
- madeLate,
867
881
  }
868
882
  lane.push(entry)
869
883
  if (entry.late) late.push(entry)
@@ -871,9 +885,11 @@ export const make = Effect.fnUntraced(
871
885
  return Effect.as(startBurst, entry)
872
886
  }
873
887
 
874
- const inLateWindow = (): boolean => windowOpen
888
+ const inLateWindow = (): boolean => lateWindowOpen
875
889
 
876
- return { run: runIn(entries, lateFirst), runLast: runIn(lastEntries, lateLast), afterTick, inLateWindow, tickCount, hint } satisfies Shape
890
+ const shape = { run: runIn(entries, lateFirst), runLast: runIn(lastEntries, lateLast), afterTick, inLateWindow, tickCount, hint } satisfies Shape
891
+ // Its `Reader`, carried beside the stable shape (#1028): a Batch keeps the rule per member by it.
892
+ return FirstSteps.carrying(shape, reader)
877
893
  },
878
894
  (self) => traced(self, "wardic.frameloop.make"),
879
895
  )
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Whether a registry blends a pair of numbers with core's `Interpolator.number`: the first of its kinds that
3
+ * reads both is that one itself. A blend machine asks once per leg, for a pair no Key rule takes, and computes
4
+ * such a pair's frames in its own loop, with no blend to call. A registry made by core's `make` carries the
5
+ * check; any other says no to every pair, and its pairs blend through what it resolves.
6
+ *
7
+ * @internal
8
+ */
9
+ // #1036 (ADR-0030, *Amendment (#1036)*): carried on the registry's value, as #1030's projector is on the
10
+ // Renderer's, so the stable `InterpolatorRegistry` keeps its shape. Internal: only core reads it, under a key
11
+ // no other module can name. A spread of the registry carries it too: `withKeyRules`' keeps it, and a registry an
12
+ // app makes from core's with a `resolve` of its own doesn't use it, since it answers for core's `resolve` alone.
13
+ import * as Option from "effect/Option"
14
+ import * as Predicate from "effect/Predicate"
15
+ import type * as InterpolatorRegistry from "../InterpolatorRegistry.ts"
16
+ import { carriedOf, carry } from "./carried.ts"
17
+
18
+ /** Whether a pair of numbers blends through core's `Interpolator.number`. */
19
+ export type LerpsNumbers = (from: number, to: number) => boolean
20
+
21
+ /** An `InterpolatorRegistry`'s service. */
22
+ type Service = InterpolatorRegistry.InterpolatorRegistry["Service"]
23
+
24
+ /** What a registry carries: its check, and the `resolve` it answers for. */
25
+ interface Carried {
26
+ readonly resolve: Service["resolve"]
27
+ readonly lerps: LerpsNumbers
28
+ }
29
+
30
+ /** Whether a value is what `attach` carries. Only `attach` writes `KEY`, so its fields are read as they are. */
31
+ const isCarried = Predicate.and(Predicate.hasProperty("resolve"), Predicate.hasProperty("lerps")) as Predicate.Refinement<unknown, Carried>
32
+
33
+ /** Where a registry's value carries it. */
34
+ const KEY: unique symbol = Symbol("@wardic/core/internal/lerpsNumbers")
35
+
36
+ /** The check of a registry that carries none, or one made with a `resolve` of its own: no pair. */
37
+ const NEVER: LerpsNumbers = () => false
38
+
39
+ /** `registry`, carrying `lerps`, which answers for its `resolve`. */
40
+ export const attach = (registry: Service, lerps: LerpsNumbers): Service => {
41
+ const carried: Carried = { resolve: registry.resolve, lerps }
42
+ return carry(registry, KEY, carried)
43
+ }
44
+
45
+ /** `registry`'s check, or one that says no to every pair when it carries none for its `resolve`. */
46
+ export const lerpsNumbersOf = (registry: Service): LerpsNumbers => {
47
+ // Per leg (#460): statements.
48
+ const carried = carriedOf(registry, KEY, isCarried)
49
+ if (Option.isNone(carried)) return NEVER
50
+ const { resolve, lerps } = carried.value
51
+ if (resolve !== registry.resolve) return NEVER
52
+ return lerps
53
+ }
@@ -12,8 +12,8 @@
12
12
  * field takes its default; a given one is checked. Then a bag's cross-field `check`, if any, reads
13
13
  * the filled fields.
14
14
  *
15
- * Each resolver checks once per bag: its result is cached by the bag's identity, so a Wardic
16
- * element's `transition`, the same object across its Retargets, is checked once. A bag is read
15
+ * Each resolver checks once per bag: its result is cached by the bag's identity, so a Ward's
16
+ * Subject's `transition`, the same object across its Retargets, is checked once. A bag is read
17
17
  * once and never again: one changed after its first check keeps the first result (the bags are
18
18
  * `readonly` in their types). None of this is on the per-frame path: a resolver runs when an
19
19
  * animation is built or started.
@@ -183,25 +183,25 @@ export const union = <const Cs extends ReadonlyArray<Check<any>>>(members: Cs):
183
183
 
184
184
  const NOT_ARRAY = expected("array")
185
185
 
186
- /** `element`'s failure for the value at index `i`, under it, or `None`. */
186
+ /** The item check's failure for the value at index `i`, under it, or `None`. */
187
187
  const elementFailure = (element: Check<unknown>, value: unknown, i: number): Option.Option<string> => {
188
188
  const checked = element(value)
189
189
  if (checked === true) return Option.none()
190
190
  return Option.some(under(`[${i}]`, checked))
191
191
  }
192
192
 
193
- /** The first of `values` that `element` rejects, its failure under its index, or `true`. */
193
+ /** The first of `values` the item check rejects, its failure under its index, or `true`. */
194
194
  const elementsOf = (element: Check<unknown>, values: ReadonlyArray<unknown>): true | string =>
195
195
  Option.getOrElse(Arr.findFirst(values, (value, i) => elementFailure(element, value, i)), (): true => true)
196
196
 
197
- /** An array, each element passing `element`. */
197
+ /** An array, each item passing the item check. */
198
198
  export const array = <A>(element: Check<A>): Check<ReadonlyArray<A>> =>
199
199
  make("array", Arr.isArray, (value) => {
200
200
  if (!Arr.isArray(value)) return NOT_ARRAY
201
201
  return elementsOf(element, value)
202
202
  })
203
203
 
204
- /** An array of one element or more, each passing `element`: an empty one is missing its first. */
204
+ /** An array of one item or more, each passing the item check: an empty one is missing its first. */
205
205
  export const nonEmptyArray = <A>(element: Check<A>): Check<Arr.NonEmptyReadonlyArray<A>> =>
206
206
  make("array", Arr.isArray, (value) => {
207
207
  if (!Arr.isArray(value)) return NOT_ARRAY
@@ -209,13 +209,13 @@ export const nonEmptyArray = <A>(element: Check<A>): Check<Arr.NonEmptyReadonlyA
209
209
  return elementsOf(element, value)
210
210
  })
211
211
 
212
- /** The tuple `elements`' failure at index `i` of `values`: missing, or its element's. */
212
+ /** The tuple's failure at index `i` of `values`: missing, or its item check's. */
213
213
  const tupleElementFailure = (values: ReadonlyArray<unknown>) => (element: Check<unknown>, i: number): Option.Option<string> => {
214
214
  if (i >= values.length) return Option.some(under(`[${i}]`, MISSING))
215
215
  return elementFailure(element, values[i], i)
216
216
  }
217
217
 
218
- /** An array of exactly `elements`' length, each passing its own: a missing one, then one past the end, fail. */
218
+ /** An array of exactly the tuple's length, each item passing its own check: a missing one, then one past the end, fail. */
219
219
  export const tuple = <const Cs extends ReadonlyArray<Check<any>>>(elements: Cs): Check<{ readonly [K in keyof Cs]: TypeOf<Cs[K]> }> =>
220
220
  make("array", Arr.isArray, (value) => {
221
221
  if (!Arr.isArray(value)) return NOT_ARRAY
@@ -226,8 +226,8 @@ export const tuple = <const Cs extends ReadonlyArray<Check<any>>>(elements: Cs):
226
226
  })
227
227
 
228
228
  /**
229
- * A cubic Bézier's four numbers, `[x1, y1, x2, y2]`: its x's from 0 to 1, as CSS's `cubic-bezier()`
230
- * takes them, its y's any finite number, so a curve may overshoot.
229
+ * A cubic Bézier's four numbers, `[x1, y1, x2, y2]`: its x's from 0 to 1, so the curve is a
230
+ * function of time, its y's any finite number, so a curve may overshoot.
231
231
  */
232
232
  // #618 (decision 9): any four finite numbers passed, and an x outside 0-1 threw bezier-easing's own
233
233
  // Error as the curve was made.
@@ -0,0 +1,31 @@
1
+ /**
2
+ * `Projection`'s key and its value at rest, in a module of their own (probe: hooks-first), apart from
3
+ * `Projection.ts`'s box maths. Every app's renderer reads these two; the maths is the layout
4
+ * Feature's alone. A bundler splits by module, not by function: with both in one module, an app that
5
+ * might fetch the layout Feature later carried the maths in its first chunk.
6
+ *
7
+ * @module
8
+ */
9
+ import type { AxisDelta, Value } from "../Projection.ts"
10
+
11
+ /**
12
+ * The key a projection pass writes each node's `Value` under, each frame, for its Environment's renderer
13
+ * to draw as one transform with the Subject's own rotation and skew. Namespaced, `@projection`, so it
14
+ * never collides with an animated key.
15
+ */
16
+ // ADR-0009. `@wardic/dom`'s renderer's `project()` reads it in place of its normal transform grouping.
17
+ // The contract between the binding's coordinator (the writer) and the renderer (the reader); it lives in
18
+ // core because that is their only shared dependency.
19
+ export const KEY = "@projection"
20
+
21
+ /** An axis with nothing to project: no shift, no scale. */
22
+ const REST_AXIS: AxisDelta = { translate: 0, scale: 1, origin: 0.5, originPoint: 0 }
23
+
24
+ /**
25
+ * A node drawn at its own box: no delta, no ancestors' scale. The renderer draws it with the Subject's
26
+ * own rotation, skew and scale, and leaves its own move out, as it draws a layout node at rest. What a
27
+ * server, which measures nothing, draws a layout node's starting style and mount animation with.
28
+ */
29
+ // #245; the projection owns its translate (ADR-0016); ADR-0021 (the server measures nothing): the
30
+ // Starting style and the Appear animation.
31
+ export const AT_REST: Value = { delta: { x: REST_AXIS, y: REST_AXIS }, treeScale: { x: 1, y: 1 } }
@@ -47,12 +47,29 @@ export interface TweenState {
47
47
  elapsed: number
48
48
  }
49
49
 
50
- /** A run's own Frame, rewritten in place each tick (#895): a tween's, a blend's. */
50
+ /** A run's own Frame, rewritten in place each tick (#895): a blend's and the keyframes step's, a tween's as a {@link TweenFrame}. */
51
51
  export interface WritableFrame<A> {
52
52
  value: A
53
53
  done: boolean
54
54
  }
55
55
 
56
+ /**
57
+ * A tween's own Frame, rewritten in place each tick: a class of its own, so no Frame whose `value` is a
58
+ * record shares its hidden class, and V8 keeps its `value` a number field it rewrites where it is. Its
59
+ * fields are assigned in the constructor, not declared with values: a field declared that way starts as
60
+ * `undefined`, and V8 would keep it able to hold anything, boxing each number stored in it.
61
+ */
62
+ // #1031 (ADR-0030, *Amendment (#1031)*): as a `{ value, done }` literal it shared `blendedBy`'s Frame's hidden
63
+ // class, whose `value` is a record, so each frame's number was boxed into it, 16 B a Subject.
64
+ export class TweenFrame implements WritableFrame<number> {
65
+ declare value: number
66
+ declare done: boolean
67
+ constructor(value: number) {
68
+ this.value = value
69
+ this.done = false
70
+ }
71
+ }
72
+
56
73
  /** A tween's options with every default filled in. */
57
74
  export interface ResolvedTween {
58
75
  /** Seconds before it moves. */
@@ -169,13 +186,14 @@ export interface Pass {
169
186
  }
170
187
 
171
188
  /**
172
- * Where a run is `t` seconds in, by Motion's `JSAnimation` iteration math (motion-dom 13.3.0): every
189
+ * Where a run is `t` seconds in, by Motion's `JSAnimation` iteration math: every
173
190
  * pass and every gap is a stretch of one time, so a pass starts the moment the one before it ends,
174
191
  * wherever that falls in a tick (#226). A gap holds where its pass ended. Every other pass is
175
192
  * turned by its `repeatType`, and `flip` (`reverse`) reads every pass's stops from last to first,
176
193
  * Motion's mirrored generator (#429). Written into `pass`; whether the run has ended. Per frame
177
194
  * (ADR-0025): arithmetic and statement `if`s.
178
195
  */
196
+ // `motion-dom` 13.3.0's `JSAnimation`.
179
197
  export const passAt = (t: number, run: ResolvedRun, flip: boolean, pass: Pass): boolean => {
180
198
  const cycle = run.cycle
181
199
  const total = run.total
@@ -97,7 +97,7 @@ export const tracedScoped = <A, E, R>(
97
97
  /**
98
98
  * `self` under the span `name` when the fiber running it is traced and the app gives spans; as it is
99
99
  * otherwise. Decided once, when the stream is run, and the pull handed on is `self`'s own: a
100
- * `Stream.unwrap` here suspended every pull, per element per frame for a Stream consumer (+4–6% on
100
+ * `Stream.unwrap` here suspended every pull, per stream per frame for a Stream consumer (+4–6% on
101
101
  * Bun's `ticksOnly`). `Shape.tracedStream` hands `self` back untraced, which is how it's told.
102
102
  */
103
103
  export const tracedStream = <A, E, R>(self: Stream.Stream<A, E, R>, name: string, options: Spans.Options = {}): Stream.Stream<A, E, R> => {