@wardic/core 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) 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 +12 -6
  8. package/dist/Batch.d.ts.map +1 -1
  9. package/dist/Batch.js +374 -30
  10. package/dist/Batch.js.map +1 -1
  11. package/dist/Clock.d.ts +16 -0
  12. package/dist/Clock.d.ts.map +1 -1
  13. package/dist/Clock.js +22 -8
  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 +14 -8
  25. package/dist/DragRecognizer.d.ts.map +1 -1
  26. package/dist/DragRecognizer.js +93 -34
  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 +11 -8
  34. package/dist/InputFeed.d.ts.map +1 -1
  35. package/dist/InputFeed.js +18 -37
  36. package/dist/InputFeed.js.map +1 -1
  37. package/dist/InputSource.d.ts +3 -3
  38. package/dist/InputSource.js +2 -2
  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 +16 -9
  46. package/dist/LiveValue.d.ts.map +1 -1
  47. package/dist/LiveValue.js +204 -27
  48. package/dist/LiveValue.js.map +1 -1
  49. package/dist/Machine.d.ts +21 -8
  50. package/dist/Machine.d.ts.map +1 -1
  51. package/dist/Machine.js +184 -60
  52. package/dist/Machine.js.map +1 -1
  53. package/dist/Playback.d.ts.map +1 -1
  54. package/dist/Playback.js +16 -9
  55. package/dist/Playback.js.map +1 -1
  56. package/dist/Projection.d.ts +9 -9
  57. package/dist/Projection.js +2 -2
  58. package/dist/Recognizer.d.ts +2 -2
  59. package/dist/Recognizer.d.ts.map +1 -1
  60. package/dist/Recognizer.js +15 -10
  61. package/dist/Recognizer.js.map +1 -1
  62. package/dist/ReducedMotion.d.ts +4 -4
  63. package/dist/ReducedMotion.js +6 -6
  64. package/dist/Renderer.d.ts +5 -5
  65. package/dist/Renderer.js +6 -6
  66. package/dist/Renderer.js.map +1 -1
  67. package/dist/Reorder.d.ts +1 -1
  68. package/dist/Reorder.d.ts.map +1 -1
  69. package/dist/Reorder.js +2 -1
  70. package/dist/Reorder.js.map +1 -1
  71. package/dist/ScrollSource.d.ts +1 -1
  72. package/dist/ScrollSource.d.ts.map +1 -1
  73. package/dist/Sequence.d.ts +1 -1
  74. package/dist/SharedSource.d.ts +3 -3
  75. package/dist/SharedSource.js +5 -5
  76. package/dist/SharedSource.js.map +1 -1
  77. package/dist/Spring.d.ts.map +1 -1
  78. package/dist/Spring.js +2 -1
  79. package/dist/Spring.js.map +1 -1
  80. package/dist/Values.d.ts +2 -2
  81. package/dist/Values.js +1 -1
  82. package/dist/index.d.ts +1 -1
  83. package/dist/index.js +1 -1
  84. package/dist/internal/carried.d.ts +13 -0
  85. package/dist/internal/carried.d.ts.map +1 -0
  86. package/dist/internal/carried.js +23 -0
  87. package/dist/internal/carried.js.map +1 -0
  88. package/dist/internal/firstSteps.d.ts +66 -0
  89. package/dist/internal/firstSteps.d.ts.map +1 -0
  90. package/dist/internal/firstSteps.js +107 -0
  91. package/dist/internal/firstSteps.js.map +1 -0
  92. package/dist/internal/frameLoop.d.ts +11 -3
  93. package/dist/internal/frameLoop.d.ts.map +1 -1
  94. package/dist/internal/frameLoop.js +190 -39
  95. package/dist/internal/frameLoop.js.map +1 -1
  96. package/dist/internal/guarded.d.ts +16 -0
  97. package/dist/internal/guarded.d.ts.map +1 -0
  98. package/dist/internal/guarded.js +68 -0
  99. package/dist/internal/guarded.js.map +1 -0
  100. package/dist/internal/lerpsNumbers.d.ts +11 -0
  101. package/dist/internal/lerpsNumbers.d.ts.map +1 -0
  102. package/dist/internal/lerpsNumbers.js +38 -0
  103. package/dist/internal/lerpsNumbers.js.map +1 -0
  104. package/dist/internal/options.d.ts +7 -7
  105. package/dist/internal/options.d.ts.map +1 -1
  106. package/dist/internal/options.js +10 -10
  107. package/dist/internal/options.js.map +1 -1
  108. package/dist/internal/stepper.d.ts +21 -4
  109. package/dist/internal/stepper.d.ts.map +1 -1
  110. package/dist/internal/stepper.js +21 -5
  111. package/dist/internal/stepper.js.map +1 -1
  112. package/dist/internal/tracing.d.ts +1 -1
  113. package/dist/internal/tracing.js +1 -1
  114. package/dist/unstable/AnimationControls.d.ts +45 -39
  115. package/dist/unstable/AnimationControls.d.ts.map +1 -1
  116. package/dist/unstable/AnimationControls.js +59 -35
  117. package/dist/unstable/AnimationControls.js.map +1 -1
  118. package/dist/unstable/AppearHandoff.d.ts +11 -5
  119. package/dist/unstable/AppearHandoff.d.ts.map +1 -1
  120. package/dist/unstable/AppearHandoff.js.map +1 -1
  121. package/dist/unstable/BatchCalls.d.ts +2 -2
  122. package/dist/unstable/BatchCalls.js +5 -5
  123. package/dist/unstable/Config.d.ts +21 -17
  124. package/dist/unstable/Config.d.ts.map +1 -1
  125. package/dist/unstable/Config.js.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 +54 -50
  131. package/dist/unstable/FlushGate.d.ts.map +1 -1
  132. package/dist/unstable/FlushGate.js +201 -77
  133. package/dist/unstable/FlushGate.js.map +1 -1
  134. package/dist/unstable/FrameEffects.d.ts +6 -3
  135. package/dist/unstable/FrameEffects.d.ts.map +1 -1
  136. package/dist/unstable/FrameEffects.js +14 -3
  137. package/dist/unstable/FrameEffects.js.map +1 -1
  138. package/dist/unstable/FrameTime.d.ts +1 -1
  139. package/dist/unstable/FrameTime.js +1 -1
  140. package/dist/unstable/Imperative.d.ts +42 -13
  141. package/dist/unstable/Imperative.d.ts.map +1 -1
  142. package/dist/unstable/Imperative.js +279 -88
  143. package/dist/unstable/Imperative.js.map +1 -1
  144. package/dist/unstable/MeasuredPairs.d.ts +6 -2
  145. package/dist/unstable/MeasuredPairs.d.ts.map +1 -1
  146. package/dist/unstable/MeasuredPairs.js.map +1 -1
  147. package/dist/unstable/OwnValues.js +1 -1
  148. package/dist/unstable/PresenceRecord.d.ts +30 -26
  149. package/dist/unstable/PresenceRecord.d.ts.map +1 -1
  150. package/dist/unstable/PresenceRecord.js +8 -8
  151. package/dist/unstable/PresenceRecord.js.map +1 -1
  152. package/dist/unstable/Projector.d.ts +34 -0
  153. package/dist/unstable/Projector.d.ts.map +1 -0
  154. package/dist/unstable/Projector.js +9 -0
  155. package/dist/unstable/Projector.js.map +1 -0
  156. package/dist/unstable/Report.d.ts +8 -1
  157. package/dist/unstable/Report.d.ts.map +1 -1
  158. package/dist/unstable/Report.js +18 -2
  159. package/dist/unstable/Report.js.map +1 -1
  160. package/dist/unstable/RetargetLegs.d.ts +7 -1
  161. package/dist/unstable/RetargetLegs.d.ts.map +1 -1
  162. package/dist/unstable/RetargetLegs.js +24 -8
  163. package/dist/unstable/RetargetLegs.js.map +1 -1
  164. package/dist/unstable/Spine.d.ts +123 -68
  165. package/dist/unstable/Spine.d.ts.map +1 -1
  166. package/dist/unstable/Spine.js +319 -167
  167. package/dist/unstable/Spine.js.map +1 -1
  168. package/dist/unstable/Stops.d.ts +3 -3
  169. package/dist/unstable/Stops.js +4 -4
  170. package/dist/unstable/Subject.d.ts +2 -2
  171. package/dist/unstable/Subject.js +2 -2
  172. package/dist/unstable/Timelines.d.ts +11 -11
  173. package/dist/unstable/Timelines.d.ts.map +1 -1
  174. package/dist/unstable/Timelines.js +3 -3
  175. package/dist/unstable/VariantTarget.d.ts +32 -10
  176. package/dist/unstable/VariantTarget.d.ts.map +1 -1
  177. package/dist/unstable/VariantTarget.js +73 -20
  178. package/dist/unstable/VariantTarget.js.map +1 -1
  179. package/dist/unstable/VariantTree.d.ts +68 -34
  180. package/dist/unstable/VariantTree.d.ts.map +1 -1
  181. package/dist/unstable/VariantTree.js +83 -36
  182. package/dist/unstable/VariantTree.js.map +1 -1
  183. package/dist/unstable/WardicConfigValue.d.ts +13 -13
  184. package/dist/unstable/WardicConfigValue.d.ts.map +1 -1
  185. package/dist/unstable/WardicConfigValue.js +4 -4
  186. package/dist/unstable/WardicConfigValue.js.map +1 -1
  187. package/package.json +1 -1
  188. package/src/Arc.ts +3 -3
  189. package/src/BaseValue.ts +18 -21
  190. package/src/Batch.ts +391 -27
  191. package/src/Clock.ts +29 -8
  192. package/src/DefaultTransition.ts +5 -3
  193. package/src/Drag.ts +32 -14
  194. package/src/DragActivity.ts +3 -3
  195. package/src/DragRecognizer.ts +118 -41
  196. package/src/Easing.ts +1 -1
  197. package/src/Frame.ts +5 -3
  198. package/src/InputFeed.ts +39 -42
  199. package/src/InputSource.ts +5 -5
  200. package/src/Interpolator.ts +3 -3
  201. package/src/InterpolatorRegistry.ts +22 -13
  202. package/src/LiveValue.ts +186 -30
  203. package/src/Machine.ts +252 -81
  204. package/src/Playback.ts +15 -9
  205. package/src/Projection.ts +9 -9
  206. package/src/Recognizer.ts +16 -10
  207. package/src/ReducedMotion.ts +6 -6
  208. package/src/Renderer.ts +6 -6
  209. package/src/Reorder.ts +3 -2
  210. package/src/ScrollSource.ts +1 -1
  211. package/src/Sequence.ts +1 -1
  212. package/src/SharedSource.ts +5 -5
  213. package/src/Spring.ts +2 -1
  214. package/src/Values.ts +2 -2
  215. package/src/index.ts +1 -1
  216. package/src/internal/carried.ts +22 -0
  217. package/src/internal/firstSteps.ts +139 -0
  218. package/src/internal/frameLoop.ts +203 -41
  219. package/src/internal/guarded.ts +69 -0
  220. package/src/internal/lerpsNumbers.ts +53 -0
  221. package/src/internal/options.ts +10 -10
  222. package/src/internal/stepper.ts +33 -6
  223. package/src/internal/tracing.ts +1 -1
  224. package/src/unstable/AnimationControls.ts +88 -57
  225. package/src/unstable/AppearHandoff.ts +13 -6
  226. package/src/unstable/BatchCalls.ts +5 -5
  227. package/src/unstable/Config.ts +23 -17
  228. package/src/unstable/FirstSteps.ts +26 -0
  229. package/src/unstable/FlushGate.ts +250 -108
  230. package/src/unstable/FrameEffects.ts +17 -4
  231. package/src/unstable/FrameTime.ts +1 -1
  232. package/src/unstable/Imperative.ts +342 -101
  233. package/src/unstable/MeasuredPairs.ts +7 -1
  234. package/src/unstable/OwnValues.ts +1 -1
  235. package/src/unstable/PresenceRecord.ts +33 -29
  236. package/src/unstable/Projector.ts +45 -0
  237. package/src/unstable/Report.ts +20 -2
  238. package/src/unstable/RetargetLegs.ts +24 -9
  239. package/src/unstable/Spine.ts +399 -202
  240. package/src/unstable/Stops.ts +6 -6
  241. package/src/unstable/Subject.ts +2 -2
  242. package/src/unstable/Timelines.ts +12 -12
  243. package/src/unstable/VariantTarget.ts +102 -23
  244. package/src/unstable/VariantTree.ts +123 -42
  245. package/src/unstable/WardicConfigValue.ts +13 -13
package/dist/Batch.js CHANGED
@@ -18,19 +18,24 @@
18
18
  // a member's keys at `slot * stride + k` (#663's shape); stepped by `Spring.matrixFor`'s exact step
19
19
  // (#370), the probe's loop (`.tmp/564-canvas/perf/group.ts` on `probe/564-canvas`).
20
20
  import * as Arr from "effect/Array";
21
+ import * as Cause from "effect/Cause";
22
+ import * as Context from "effect/Context";
21
23
  import * as Effect from "effect/Effect";
22
24
  import { identity } from "effect/Function";
23
25
  import * as Inspectable from "effect/Inspectable";
24
- import * as Iter from "effect/Iterable";
25
26
  import * as Match from "effect/Match";
27
+ import * as Option from "effect/Option";
26
28
  import { pipeArguments } from "effect/Pipeable";
27
29
  import * as Predicate from "effect/Predicate";
28
30
  import * as UndefinedOr from "effect/UndefinedOr";
31
+ import * as FrameLoop from "./FrameLoop.js";
29
32
  import * as Machine from "./Machine.js";
30
33
  import * as Scalar from "./Scalar.js";
31
34
  import * as Spring from "./Spring.js";
32
35
  import * as UnitScale from "./UnitScale.js";
36
+ import * as Report from "./unstable/Report.js";
33
37
  import { dual } from "./internal/dual.js";
38
+ import * as FirstSteps from "./internal/firstSteps.js";
34
39
  import { tickOf, writableOf } from "./internal/playhead.js";
35
40
  import { resolveKeyframes } from "./internal/keyframes.js";
36
41
  import { checked, fn, literals, nonNegative, positive, union } from "./internal/options.js";
@@ -71,7 +76,7 @@ const COUNTED = 8;
71
76
  * `elapsed` `NaN` until then. It's in `startList`, which each step's start pass reads before the loops.
72
77
  */
73
78
  const STARTS = 16;
74
- /** The start pass drew it this step: its loop keeps it, unstepped, and clears the flag. */
79
+ /** The start pass or the owing pass drew it this step: its loop keeps it, unstepped, and clears the flag. */
75
80
  const STARTED = 32;
76
81
  /**
77
82
  * Its values changed outside a step (it entered, took a new Subject, a change started it from a given value,
@@ -247,6 +252,10 @@ export const make = (options) => {
247
252
  movers: new Int32Array(capacity),
248
253
  flags: new Uint8Array(capacity),
249
254
  free: [],
255
+ owed: new Float64Array(capacity),
256
+ owing: 0,
257
+ startOwing: 0,
258
+ ticks: undefined,
250
259
  startAts: [],
251
260
  startList: [],
252
261
  plainList: new Int32Array(capacity),
@@ -269,8 +278,16 @@ export const make = (options) => {
269
278
  flush: UndefinedOr.match(options.writer.flush, { onUndefined: () => noop, onDefined: identity }),
270
279
  onFrame: UndefinedOr.match(options.onFrame, { onUndefined: () => noop, onDefined: identity }),
271
280
  frame: 0,
281
+ frameDt: 0,
272
282
  running: 0,
273
283
  runs: 0,
284
+ services: Context.empty(),
285
+ writeThrewInStep: false,
286
+ writeReported: false,
287
+ startThrewInStep: false,
288
+ startReported: false,
289
+ flushReported: false,
290
+ onFrameReported: false,
274
291
  };
275
292
  // The Batch's own transitions, pinned: the first entries, rule 0 the first key's.
276
293
  state.ownRules = rulesOf(state, options.transition, unnamedKey(state));
@@ -323,7 +340,12 @@ export const enter = dual(3, (self, subject, start) => {
323
340
  state.subjects[slot] = subject;
324
341
  // A start a member that left never took isn't this one's.
325
342
  // Drawn at its first step, at its start, though a delay holds it there.
326
- state.flags[slot] = (state.flags[slot] & ~(STARTS | STARTED)) | LIVE | DUE;
343
+ const flag = (state.flags[slot] & ~(STARTS | STARTED)) | LIVE | DUE;
344
+ state.flags[slot] = flag;
345
+ // A slot the member before left while it moved is still in its list, stepped as a moving member's: the new
346
+ // one owes its first steps from now while the run goes on (#1028), as one set off is; a run's start counts it.
347
+ if ((flag & (IN_PLAIN | IN_RULED)) !== 0 && state.running !== 0)
348
+ owes(state, slot, owingNow(state));
327
349
  const base = slot * state.stride;
328
350
  Arr.forEach(state.keys, (key, k) => {
329
351
  const given = start[key];
@@ -358,14 +380,15 @@ export const leave = dual(2, (self, slot) => {
358
380
  return;
359
381
  state.flags[slot] = state.flags[slot] & ~LIVE;
360
382
  state.subjects[slot] = undefined;
383
+ owesNothing(state, slot);
361
384
  state.free.push(slot);
362
385
  });
363
386
  /**
364
387
  * The member at `slot` is drawn on `subject` from now on: its values, speed, targets and delays carry
365
- * on as they were. For an element its framework made again for the same member.
388
+ * on as they were. For a Subject its framework made again for the same member.
366
389
  *
367
390
  * @example
368
- * Batch.replace(grid, slot, element)
391
+ * Batch.replace(grid, slot, subject)
369
392
  */
370
393
  export const replace = dual(3, (self, slot, subject) => {
371
394
  const state = stateOf(self);
@@ -409,6 +432,7 @@ const grow = (state, capacity) => {
409
432
  state.pending = grown(state.pending, size);
410
433
  state.movers = grown(state.movers, capacity);
411
434
  state.flags = grown(state.flags, capacity);
435
+ state.owed = grown(state.owed, capacity);
412
436
  state.plainList = grown(state.plainList, capacity);
413
437
  state.ruledList = grown(state.ruledList, capacity);
414
438
  };
@@ -520,6 +544,10 @@ export const retarget = dual(isBatch, (self, slots, targetOf, options) => {
520
544
  const driven = state.animations.size > 0;
521
545
  // Started partway (#706): each key it turns waits, `elapsed` `NaN`, for its member's first step to read where.
522
546
  const startAt = UndefinedOr.map(options, (bag) => bag.startAt);
547
+ // While its run goes on, a member it sets off from rest owes its first steps (#1028), read once.
548
+ let owing = 0;
549
+ if (state.running !== 0)
550
+ owing = owingNow(state);
523
551
  let fresh = 0;
524
552
  if (Predicate.isNotUndefined(startAt))
525
553
  fresh = Number.NaN;
@@ -574,8 +602,12 @@ export const retarget = dual(isBatch, (self, slots, targetOf, options) => {
574
602
  state.startAts[slot] = startAt;
575
603
  }
576
604
  flags[slot] = flag;
577
- if ((flag & (IN_PLAIN | IN_RULED)) === 0)
605
+ if ((flag & (IN_PLAIN | IN_RULED)) === 0) {
578
606
  setOff++;
607
+ // Set off from rest while its run goes on: it owes its first steps (#1028), unless its first step
608
+ // takes an Appear animation over (`startedPartway`). A run that starts owes its members' at its start.
609
+ owes(state, slot, owing);
610
+ }
579
611
  // Into the ruled list, out of the plain one (which drops it at its next step); else into the plain
580
612
  // list, if it's in neither.
581
613
  if (ruled && (flag & IN_RULED) === 0) {
@@ -592,6 +624,141 @@ export const retarget = dual(isBatch, (self, slots, targetOf, options) => {
592
624
  Arr.forEach(held, (rule) => release(state, rule));
593
625
  return setOff;
594
626
  });
627
+ // --- A member's first steps (#1028) ------------------------------------------------
628
+ //
629
+ // A Batch is one run on the Frame loop, on the frame timeline, so the late-frame rule a run of its own keeps
630
+ // (`FirstSteps`, #1026) is kept here per member: a member set off from rest takes none of a long task's time
631
+ // from before it moved. Per member at a change and at a run's start; per frame, only while one owes.
632
+ /** What a member or a Playhead set off now owes (`FirstSteps.madeOwing`): 0, nothing, before the Batch's first run. */
633
+ const owingNow = (state) => {
634
+ const ticks = state.ticks;
635
+ if (Predicate.isUndefined(ticks))
636
+ return 0;
637
+ return ticks.madeOwing();
638
+ };
639
+ /** The member at `slot` owes `owing` (0, nothing). */
640
+ // Per member at a change, what they owe read once for all of them.
641
+ const owes = (state, slot, owing) => {
642
+ if (owing === 0)
643
+ return;
644
+ if (state.owed[slot] === 0)
645
+ state.owing = state.owing + 1;
646
+ state.owed[slot] = owing;
647
+ };
648
+ /** The member at `slot` owes nothing: it rests, left, or keeps the frame timeline's time. */
649
+ const owesNothing = (state, slot) => {
650
+ if (state.owed[slot] === 0)
651
+ return;
652
+ state.owed[slot] = 0;
653
+ state.owing = state.owing - 1;
654
+ };
655
+ /** The dt now of a member or a Playhead that owes `owed`: the step's, what it owes left out, clamped. */
656
+ // Per member or Playhead that owes, in a step: twice a play or a set-off at most.
657
+ const owingDt = (state, owed) => {
658
+ const ticks = state.ticks;
659
+ let dt = state.frameDt;
660
+ if (Predicate.isNotUndefined(ticks))
661
+ dt = ticks.owingDt(owed, dt);
662
+ return Math.min(dt, Machine.MAX_DT);
663
+ };
664
+ /** What a member or a Playhead that owed `owed` owes after its step now. */
665
+ const owedAfter = (state, owed) => {
666
+ const ticks = state.ticks;
667
+ if (Predicate.isUndefined(ticks))
668
+ return 0;
669
+ return ticks.owedAfter(owed);
670
+ };
671
+ /**
672
+ * A run's start: the members it starts with owe their first steps from now, all alike, kept once for the
673
+ * Batch (`startOwing`) until its first step tells whether they owe each. What one owed of a run before is
674
+ * forgotten.
675
+ */
676
+ // Once a run: nothing per member, so a run that starts on time costs what it did.
677
+ const runStarts = (state) => {
678
+ if (state.owing > 0) {
679
+ state.owed.fill(0);
680
+ state.owing = 0;
681
+ }
682
+ state.startOwing = owingNow(state);
683
+ };
684
+ /**
685
+ * The run's first step: whether the members it started with take the tick's dt. Where they don't, each one
686
+ * moving owes its first steps as they did, and each change a Playhead drives its first ticks: one taking an
687
+ * Appear animation over (the start pass drew it) and one set off or played since, owing its own, aside.
688
+ */
689
+ // Once a run, at its first step; per member only where that step's frame came late.
690
+ const startOwes = (state) => {
691
+ const owing = state.startOwing;
692
+ state.startOwing = 0;
693
+ if (owingDt(state, owing) === Math.min(state.frameDt, Machine.MAX_DT) && owedAfter(state, owing) === 0)
694
+ return;
695
+ owesFromNow(state, state.plainList, state.plainCount, IN_PLAIN, owing);
696
+ owesFromNow(state, state.ruledList, state.ruledCount, IN_RULED, owing);
697
+ // And each change a Playhead drives that it started with, played before it, but one played since.
698
+ for (const animation of state.animations) {
699
+ if (animation.owed !== 0)
700
+ continue;
701
+ animation.owed = owing;
702
+ }
703
+ };
704
+ /** Each live member of `list`'s first `count` still in it (`inList`), not drawn this step nor owing, owes as `owing`. */
705
+ const owesFromNow = (state, list, count, inList, owing) => {
706
+ const { flags, owed } = state;
707
+ let added = 0;
708
+ for (let a = 0; a < count; a++) {
709
+ const slot = list[a];
710
+ if ((flags[slot] & (LIVE | inList | STARTED)) !== (LIVE | inList))
711
+ continue;
712
+ if (owed[slot] !== 0)
713
+ continue;
714
+ owed[slot] = owing;
715
+ added++;
716
+ }
717
+ state.owing = state.owing + added;
718
+ };
719
+ /**
720
+ * `defect`, a failure on the Batch's path named by `message`, logged and handed to the ErrorReporters of
721
+ * what it runs on, annotated with its member's slot where it's one member's.
722
+ */
723
+ // #977 (ADR-0074): one member's failure is its own. Its failure path, off the per-frame one.
724
+ const report = (state, message, defect, slot) => {
725
+ const failure = Report.failure(message, Cause.die(defect));
726
+ if (Predicate.isUndefined(slot)) {
727
+ Effect.runForkWith(state.services)(failure);
728
+ return;
729
+ }
730
+ Effect.runForkWith(state.services)(Effect.annotateLogs(failure, { member: slot }));
731
+ };
732
+ /** A member's write that threw: reported once, until a step writes every member clean. */
733
+ const writeFailed = (state, slot, defect) => {
734
+ state.writeThrewInStep = true;
735
+ if (state.writeReported)
736
+ return;
737
+ state.writeReported = true;
738
+ report(state, "wardic.batch: a member's write failed", defect, slot);
739
+ };
740
+ /** A member's start partway that threw: reported once, until a step starts every member clean. */
741
+ const startFailed = (state, slot, defect) => {
742
+ state.startThrewInStep = true;
743
+ if (state.startReported)
744
+ return;
745
+ state.startReported = true;
746
+ report(state, "wardic.batch: a member's start failed", defect, slot);
747
+ };
748
+ /** The writer's `flush`, a step's or a draw's: a throw reported once, until one returns. */
749
+ const flushed = (state) => {
750
+ try {
751
+ state.flush();
752
+ if (state.flushReported)
753
+ state.flushReported = false;
754
+ }
755
+ catch (defect) {
756
+ if (state.flushReported)
757
+ return;
758
+ state.flushReported = true;
759
+ report(state, "wardic.batch: its writer's flush failed", defect);
760
+ }
761
+ };
595
762
  /** Whether any member moves: one `step` would move. */
596
763
  export const isMoving = (self) => {
597
764
  const state = stateOf(self);
@@ -602,6 +769,11 @@ export const isMoving = (self) => {
602
769
  * outside a step set (an `enter`, a `replace`, a start from a given value, a play, seek, stop or cancel):
603
770
  * whether nothing moves now. One a delay or a paused Playhead holds still isn't written. The run on the
604
771
  * Frame loop calls it each tick.
772
+ *
773
+ * One member's failure is its own: a write or a start partway that throws is reported once, until a step
774
+ * runs every member's clean, and its member steps on with the others. A landing's callback that throws is
775
+ * reported each time, the other members told and the other changes landed; the writer's `flush` and
776
+ * `onFrame` once until they return. Each is reported on what the Batch last ran on.
605
777
  */
606
778
  // Per frame (ADR-0025, ADR-0030 decisions 10 and 11): `dt` clamped once (#78), then the two moving
607
779
  // lists. Each steps a key by `springValues`' exact step, or `Machine.tween`'s, its spring's matrix
@@ -610,16 +782,49 @@ export const step = (self, dt) => {
610
782
  const state = stateOf(self);
611
783
  const clamped = Math.min(dt, Machine.MAX_DT);
612
784
  state.frame = state.frame + 1;
785
+ state.frameDt = dt;
786
+ // Whether a member's write or start throws in this step: a `draw`'s between steps isn't one (#977).
787
+ state.writeThrewInStep = false;
788
+ state.startThrewInStep = false;
613
789
  if (state.startList.length > 0)
614
790
  startPass(state, clamped);
791
+ // A member that owes its first steps steps by its own dt, out of the loops (#1028).
792
+ if (state.startOwing !== 0)
793
+ startOwes(state);
794
+ if (state.owing > 0)
795
+ owingPass(state, clamped);
615
796
  if (state.plainCount > 0)
616
797
  stepPlain(state, clamped);
617
798
  if (state.ruledCount > 0)
618
799
  stepRuled(state, clamped);
619
- if (state.animations.size > 0)
620
- Iter.forEach(state.animations, checkLanding);
621
- state.flush();
622
- state.onFrame();
800
+ // Each change's landing its own: a callback that throws leaves the others to land (#977).
801
+ if (state.animations.size > 0) {
802
+ for (const animation of state.animations) {
803
+ try {
804
+ checkLanding(animation);
805
+ }
806
+ catch (defect) {
807
+ report(state, "wardic.batch: a change's landing failed", defect);
808
+ }
809
+ }
810
+ }
811
+ flushed(state);
812
+ try {
813
+ state.onFrame();
814
+ if (state.onFrameReported)
815
+ state.onFrameReported = false;
816
+ }
817
+ catch (defect) {
818
+ if (!state.onFrameReported) {
819
+ state.onFrameReported = true;
820
+ report(state, "wardic.batch: an onFrame failed", defect);
821
+ }
822
+ }
823
+ // A path that stepped clean is reported again at its next throw (#977).
824
+ if (!state.writeThrewInStep)
825
+ state.writeReported = false;
826
+ if (!state.startThrewInStep)
827
+ state.startReported = false;
623
828
  // Counted after `onFrame`: a change it makes keeps the run going.
624
829
  if (state.plainCount + state.ruledCount > 0)
625
830
  return false;
@@ -630,7 +835,7 @@ export const step = (self, dt) => {
630
835
  };
631
836
  /**
632
837
  * Writes every member where it is now, with no step, then flushes the writer: a change that started its
633
- * members from their targets (`retarget`'s `from`), drawn now, before the page paints, where the run would
838
+ * members from their targets (`retarget`'s `from`), committed now, before the frame is drawn, where the run would
634
839
  * draw it at its next tick.
635
840
  */
636
841
  // #712: a Batch Reorder group's first read of its element places its items at once. Once a change, over
@@ -642,9 +847,14 @@ export const draw = (self) => {
642
847
  if ((flags[slot] & LIVE) === 0)
643
848
  continue;
644
849
  flags[slot] = flags[slot] & ~DUE;
645
- write(subjects[slot], positions, slot * stride);
850
+ try {
851
+ write(subjects[slot], positions, slot * stride);
852
+ }
853
+ catch (defect) {
854
+ writeFailed(state, slot, defect);
855
+ }
646
856
  }
647
- state.flush();
857
+ flushed(state);
648
858
  };
649
859
  /**
650
860
  * At rest, every transition but the Batch's own is forgotten: no member moves, so no rule is read
@@ -736,8 +946,14 @@ const stepPlain = (state, clamped) => {
736
946
  elapsed[at] = time;
737
947
  }
738
948
  // One a delay holds still isn't written: an unchanged write is a style write all the same.
739
- if (moved)
740
- write(subjects[slot], positions, base);
949
+ if (moved) {
950
+ try {
951
+ write(subjects[slot], positions, base);
952
+ }
953
+ catch (defect) {
954
+ writeFailed(state, slot, defect);
955
+ }
956
+ }
741
957
  // At rest: still its member's, in neither list.
742
958
  if (still) {
743
959
  flags[slot] = LIVE;
@@ -876,8 +1092,14 @@ const stepRuled = (state, clamped) => {
876
1092
  positions[at] = position;
877
1093
  velocities[at] = speed;
878
1094
  }
879
- if (moved)
880
- write(subjects[slot], positions, base);
1095
+ if (moved) {
1096
+ try {
1097
+ write(subjects[slot], positions, base);
1098
+ }
1099
+ catch (defect) {
1100
+ writeFailed(state, slot, defect);
1101
+ }
1102
+ }
881
1103
  // At rest: still its member's, in neither list (a member is in one at most).
882
1104
  if (still) {
883
1105
  flags[slot] = LIVE;
@@ -988,8 +1210,14 @@ const stepRuledDriven = (state) => {
988
1210
  positions[at] = position;
989
1211
  velocities[at] = speed;
990
1212
  }
991
- if (moved)
992
- write(subjects[slot], positions, base);
1213
+ if (moved) {
1214
+ try {
1215
+ write(subjects[slot], positions, base);
1216
+ }
1217
+ catch (defect) {
1218
+ writeFailed(state, slot, defect);
1219
+ }
1220
+ }
993
1221
  // At rest: still its member's, in neither list (a member is in one at most).
994
1222
  if (still) {
995
1223
  flags[slot] = LIVE;
@@ -1036,18 +1264,25 @@ const drivenStep = (animation, clamped, frame) => {
1036
1264
  return animation.dt;
1037
1265
  animation.frame = frame;
1038
1266
  const head = animation.options.head;
1267
+ // Its tick: the frame's, less a long task's time while its Playhead owes its first ticks (#1028).
1268
+ let tick = clamped;
1269
+ const owed = animation.owed;
1270
+ if (owed !== 0) {
1271
+ tick = owingDt(animation.state, owed);
1272
+ animation.owed = owedAfter(animation.state, owed);
1273
+ }
1039
1274
  let by = 0;
1040
1275
  // Played from partway through, its first step lands there, whatever the `dt`, as `Playback.drive`'s does.
1041
1276
  const landing = animation.landing;
1042
1277
  animation.landing = false;
1043
1278
  if (!landing && !head.paused)
1044
- by = tickOf(head, clamped, Machine.MAX_DT);
1279
+ by = tickOf(head, tick, Machine.MAX_DT);
1045
1280
  animation.dt = by;
1046
1281
  animation.time = Math.max(0, animation.time + by);
1047
1282
  writableOf(head).time = animation.time;
1048
1283
  return by;
1049
1284
  };
1050
- /** Whether the key at `at` is held by a paused Playhead: it hands on no speed, as a held element's frames read 0 (#464). */
1285
+ /** 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). */
1051
1286
  // Per key per change, while a driven change plays.
1052
1287
  const heldAt = (state, at) => {
1053
1288
  const driver = state.drivers[state.rules[at]];
@@ -1140,9 +1375,20 @@ const startedPartway = (state, slot, dt) => {
1140
1375
  const { stride, elapsed, rules, positions, velocities, targets, originVelocities, startAts } = state;
1141
1376
  const startAt = UndefinedOr.getOrThrow(startAts[slot]);
1142
1377
  startAts[slot] = undefined;
1143
- const time = startAt(slot);
1378
+ // A start that throws is its member's: it starts from its start, as `NaN` gives (#977).
1379
+ let time = Number.NaN;
1380
+ try {
1381
+ time = startAt(slot);
1382
+ }
1383
+ catch (defect) {
1384
+ startFailed(state, slot, defect);
1385
+ }
1144
1386
  const base = slot * stride;
1145
1387
  const started = !Number.isNaN(time);
1388
+ // Taking its Appear animation over, it keeps the frame timeline's time, where that animation's is (#1026);
1389
+ // from its start, `NaN`, it takes over nothing and owes its first steps as any member set off (#1028).
1390
+ if (started)
1391
+ owesNothing(state, slot);
1146
1392
  for (let k = 0; k < stride; k++) {
1147
1393
  const at = base + k;
1148
1394
  const turned = Number.isNaN(elapsed[at]);
@@ -1164,15 +1410,81 @@ const startedPartway = (state, slot, dt) => {
1164
1410
  }
1165
1411
  if (started) {
1166
1412
  state.flags[slot] = state.flags[slot] & ~DUE;
1167
- state.write(state.subjects[slot], positions, base);
1413
+ try {
1414
+ state.write(state.subjects[slot], positions, base);
1415
+ }
1416
+ catch (defect) {
1417
+ writeFailed(state, slot, defect);
1418
+ }
1168
1419
  }
1169
1420
  return started;
1170
1421
  };
1422
+ /**
1423
+ * Each step's owing pass, before the loops and after the start pass: each member that owes its first steps
1424
+ * takes its step's dt (the tick's, less what it owes). One whose dt that leaves less is
1425
+ * stepped by it here, drawn, and flagged `STARTED` so its loop keeps it unstepped; one at the tick's, by its
1426
+ * loop. A key a Playhead drives keeps its Playhead's step.
1427
+ */
1428
+ // #1028: once or twice a member, after a change that sets it off, so out of the loops, as the start pass is
1429
+ // (#706): with a member's own dt read in them, Bun's ruled step ran 5% slower with no member owing.
1430
+ const owingPass = (state, clamped) => {
1431
+ owingIn(state, state.plainList, state.plainCount, clamped);
1432
+ owingIn(state, state.ruledList, state.ruledCount, clamped);
1433
+ };
1434
+ /** The owing pass over `list`'s first `count`: a member that left, or one drawn this step already, skipped. */
1435
+ const owingIn = (state, list, count, clamped) => {
1436
+ const { flags, owed } = state;
1437
+ for (let a = 0; a < count; a++) {
1438
+ const slot = list[a];
1439
+ const was = owed[slot];
1440
+ if (was === 0)
1441
+ continue;
1442
+ if ((flags[slot] & (LIVE | STARTED)) !== LIVE)
1443
+ continue;
1444
+ const own = owingDt(state, was);
1445
+ const after = owedAfter(state, was);
1446
+ owed[slot] = after;
1447
+ if (after === 0)
1448
+ state.owing = state.owing - 1;
1449
+ // At the tick's own dt (an on-time first step), its loop steps it.
1450
+ if (own !== clamped)
1451
+ stepOwing(state, slot, clamped, own);
1452
+ }
1453
+ };
1454
+ /** The member at `slot` a step of `own` on, each key as the loops step it, drawn, and kept from its loop this step. */
1455
+ const stepOwing = (state, slot, clamped, own) => {
1456
+ const { stride, rules, drivers } = state;
1457
+ const base = slot * stride;
1458
+ for (let k = 0; k < stride; k++) {
1459
+ const at = base + k;
1460
+ const rule = rules[at];
1461
+ const driver = drivers[rule];
1462
+ if (Predicate.isUndefined(driver)) {
1463
+ stepKey(state, at, rule, own);
1464
+ continue;
1465
+ }
1466
+ // Its Playhead's step this frame, worked out once a step whichever reads it first.
1467
+ const driven = drivenStep(driver, clamped, state.frame);
1468
+ if (driven < 0) {
1469
+ stepBack(state, at, rule, driven);
1470
+ continue;
1471
+ }
1472
+ stepKey(state, at, rule, driven);
1473
+ }
1474
+ state.flags[slot] = (state.flags[slot] & ~DUE) | STARTED;
1475
+ try {
1476
+ state.write(state.subjects[slot], state.positions, base);
1477
+ }
1478
+ catch (defect) {
1479
+ writeFailed(state, slot, defect);
1480
+ }
1481
+ };
1171
1482
  /**
1172
1483
  * The key at `at` a step of `dt` on, as the loops step it: a tween's, keyframes', or a spring's by its
1173
1484
  * matrix for the part past its delay, landing by its thresholds or its duration.
1174
1485
  */
1175
- // Rare: a key the loops don't reach this step, of a member started partway that another change moves.
1486
+ // Rare: a key the loops don't reach this step, of a member started partway that another change moves, or of
1487
+ // a member that owes its first steps (#1028).
1176
1488
  const stepKey = (state, at, rule, dt) => {
1177
1489
  const entry = state.entries[rule];
1178
1490
  const time = state.elapsed[at] + dt;
@@ -1251,7 +1563,15 @@ const tellIdle = (animation) => {
1251
1563
  const tell = animation.options.onMemberLanded;
1252
1564
  if (Predicate.isUndefined(tell))
1253
1565
  return;
1254
- Arr.forEach(animation.idle, (slot) => tell(slot));
1566
+ // Each member's own: a landing that throws leaves the others told (#977).
1567
+ Arr.forEach(animation.idle, (slot) => {
1568
+ try {
1569
+ tell(slot);
1570
+ }
1571
+ catch (defect) {
1572
+ report(animation.state, "wardic.batch: a member's landing failed", defect, slot);
1573
+ }
1574
+ });
1255
1575
  };
1256
1576
  /**
1257
1577
  * Each member `animation` moves told, once, as every key of it it still moves has landed (`onMemberLanded`):
@@ -1278,7 +1598,13 @@ const tellMembers = (animation, tell) => {
1278
1598
  if (!kept || !atRest)
1279
1599
  continue;
1280
1600
  told[r] = 1;
1281
- tell(slotAt(state, ats[firsts[r]]));
1601
+ const slot = slotAt(state, ats[firsts[r]]);
1602
+ try {
1603
+ tell(slot);
1604
+ }
1605
+ catch (defect) {
1606
+ report(state, "wardic.batch: a member's landing failed", defect, slot);
1607
+ }
1282
1608
  }
1283
1609
  };
1284
1610
  /**
@@ -1409,6 +1735,7 @@ const animationFor = (state, options, slots, moves) => {
1409
1735
  frame: 0,
1410
1736
  dt: 0,
1411
1737
  landing: false,
1738
+ owed: 0,
1412
1739
  tracks: [],
1413
1740
  indexAt: new Int32Array(0),
1414
1741
  firsts: new Int32Array(0),
@@ -1697,7 +2024,7 @@ const playRules = (animation) => {
1697
2024
  /**
1698
2025
  * Plays `animation` from its Playhead's time: from its start at 0, its change worked out then, and from
1699
2026
  * wherever a seek put the time, every key it moves taken again there. It returns how many members it
1700
- * sets off from rest. One that moves nothing lands at once, as an element's call with no key does.
2027
+ * sets off from rest. One that moves nothing lands at once, as a Subject's call with no key does.
1701
2028
  */
1702
2029
  export const play = (self) => {
1703
2030
  const animation = animationOf(self);
@@ -1715,6 +2042,11 @@ export const play = (self) => {
1715
2042
  animation.playing = true;
1716
2043
  animation.time = time;
1717
2044
  animation.landing = time > 0;
2045
+ // Played while the run goes on, its Playhead owes its first ticks from now (#1028); played at rest, from
2046
+ // the run's start, as the run's members.
2047
+ animation.owed = 0;
2048
+ if (state.running !== 0)
2049
+ animation.owed = owingNow(state);
1718
2050
  state.animations.add(animation);
1719
2051
  // Once a play, per key it moves: each key's entry, then each entry held once for it and driven by it.
1720
2052
  playRules(animation);
@@ -1903,26 +2235,38 @@ const machineOf = (self, id) => {
1903
2235
  },
1904
2236
  });
1905
2237
  };
2238
+ /** A Batch run's options: on the frame timeline, its members keeping the late-frame rule each. */
2239
+ // #1026, #1028.
2240
+ const ON_THE_FRAME_TIMELINE = { onFrameTimeline: true };
1906
2241
  /**
1907
2242
  * Runs `self` on the Frame loop while any member moves, from the next tick: each tick steps every
1908
2243
  * moving member and writes it. It succeeds once nothing moves. While one runs, another does nothing,
1909
- * so a binding calls it after each change.
2244
+ * so a binding calls it after each change. A member's failure is reported on the services it runs with,
2245
+ * the Environment's Logger and ErrorReporters, and the run goes on.
1910
2246
  *
1911
2247
  * @example
1912
2248
  * Batch.retarget(grid, slots, targetOf)
1913
2249
  * runtime.runFork(Batch.run(grid))
1914
2250
  */
1915
2251
  // One run, not a fiber per member (ADR-0069, decision 10). Its span is `wardic.batch`.
1916
- export const run = (self) => Effect.suspend(() => {
2252
+ export const run = (self) => Effect.contextWith((services) => {
1917
2253
  const state = stateOf(self);
1918
2254
  if (state.running !== 0)
1919
2255
  return Effect.void;
2256
+ // Its failures are reported on what it runs on, the Environment's Logger and ErrorReporters, kept
2257
+ // for a draw or a play between runs; a second run while one runs swaps nothing (#977).
2258
+ state.services = services;
1920
2259
  if (state.plainCount + state.ruledCount === 0)
1921
2260
  return Effect.void;
1922
2261
  const id = state.runs + 1;
1923
2262
  state.runs = id;
1924
2263
  state.running = id;
1925
- return Effect.ensuring(Effect.asVoid(Machine.run(machineOf(self, id), ignore)), Effect.sync(() => {
2264
+ // The run keeps the frame timeline's time, where a member taking its Appear animation over has its
2265
+ // `currentTime` (#1026). Every other member takes no long task's time from before it moved (#1028):
2266
+ // those moving now owe their first steps, and those set off while it runs, at their change.
2267
+ state.ticks = Option.getOrUndefined(FirstSteps.readerOf(Context.get(services, FrameLoop.FrameLoop)));
2268
+ runStarts(state);
2269
+ return Effect.ensuring(Effect.asVoid(Machine.run(machineOf(self, id), ignore, ON_THE_FRAME_TIMELINE)), Effect.sync(() => {
1926
2270
  if (state.running === id)
1927
2271
  state.running = 0;
1928
2272
  }));