@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
@@ -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
@@ -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,8 @@ 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"
84
+ import * as FirstSteps from "./firstSteps.ts"
83
85
  import { none, SpansGiven, traced } from "./tracing.ts"
84
86
 
85
87
  // @wardic/core compiles against ES2022 alone, which does not declare `performance` (see
@@ -88,11 +90,13 @@ declare const performance: { readonly now: () => number }
88
90
  // The same for `queueMicrotask` (see Microtask.ts): the Late window's end (#680).
89
91
  declare const queueMicrotask: (callback: () => void) => void
90
92
 
91
- /** A run's options: the token it joins, so its caller can end it with others. */
92
- // #200.
93
+ /** A run's options: the token it joins, so its caller can end it with others, and its timeline. */
94
+ // #200; #1026.
93
95
  export interface RunOptions {
94
96
  /** The token: `Supersede.end` on it ends every run that joined it. */
95
- readonly supersede: Supersede.Supersede
97
+ readonly supersede?: Supersede.Supersede | undefined
98
+ /** Its start read from the frame timeline: it steps at the ticks' dt from its first frame ({@link dtOf}). */
99
+ readonly onFrameTimeline?: boolean | undefined
96
100
  }
97
101
 
98
102
  /** `run`'s and `runLast`'s shape: a run given a token can also end `Superseded`. */
@@ -140,12 +144,19 @@ export interface Shape {
140
144
  // ADR-0027 *Amendment (#680)* (was `ticking()`, #673): the projection's Measure pass reads it at a
141
145
  // trigger, to know it will run after its frame's tick.
142
146
  readonly inLateWindow: () => boolean
147
+ /**
148
+ * How many ticks the loop has run: 0 before any. Neither a Late round nor a binding's hint window is a
149
+ * tick, so a run's Late step reads the count it was started at, and any step at a later tick a greater one.
150
+ */
151
+ // #991 (ADR-0043, *Amendment (#991)*): `velocity` tells its run's Late step by it. Not the Clock's
152
+ // `frameAt`, which repeats on Firefox's frame after an input (#18) and is `NaN` before any frame.
153
+ readonly tickCount: () => number
143
154
  /**
144
155
  * A binding's hint: its code runs inside the Refresh frame whose time is `frameTime`, after the
145
156
  * frame's tick, as a binding that renders in a frame callback of its own does (ADR-0071 decision 32).
146
157
  * Opens the **Late window** when a burst's last tick was this frame's (`Clock.frameAt`) or no burst runs
147
158
  * (no tick is coming this frame), so the runs added after it, in the rest of the callback and its
148
- * 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
149
160
  * tick still to come in the frame, nothing: that tick is their first step. Idle, the Late step's dt is
150
161
  * the last tick's, or a nominal frame before any.
151
162
  */
@@ -156,6 +167,8 @@ export interface Shape {
156
167
  /** One hook on the loop's ticks, one object per `afterTick`, so removing it removes only that one. */
157
168
  interface Hook {
158
169
  readonly hook: (dt: number) => undefined
170
+ /** Whether its calls are throwing: reported at the first, again once one has returned. */
171
+ failing: boolean
159
172
  }
160
173
 
161
174
  /** One run on the loop. */
@@ -175,11 +188,29 @@ interface Entry {
175
188
  late: boolean
176
189
  /** Its span, when traced: marked `late` at its Late step (#680). */
177
190
  readonly span: Tracer.Span | undefined
191
+ /**
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.
195
+ */
196
+ owed: number
178
197
  }
179
198
 
180
199
  /** How many Late rounds a window runs before the rest wait for the next tick: the Measure pass's cap (#680). */
181
200
  const MAX_LATE_ROUNDS = 5
182
201
 
202
+ /** The line past which a Refresh frame ran late, in ms (`Clock.LateFrames`): `NaN` where none is told. */
203
+ const lateAfterOf = (timing: Clock.LateFrameTiming): number => {
204
+ if (timing === "timestamp") return Number.NaN
205
+ return timing.ranAfter
206
+ }
207
+
208
+ /** Whether a run keeps the frame timeline's time (`RunOptions.onFrameTimeline`). */
209
+ const onFrameTimeline = (options: RunOptions | undefined): boolean => {
210
+ if (Predicate.isUndefined(options)) return false
211
+ return options.onFrameTimeline === true
212
+ }
213
+
183
214
  /**
184
215
  * The Frame loop's metrics: the running animations, the runs that settled and failed, and each tick's
185
216
  * ms. None unless an app gives them (`FrameLoop.layerMetrics`, #518), so an app that reads none ships and
@@ -304,6 +335,10 @@ export const make = Effect.fnUntraced(
304
335
  const clock = yield* Clock.Clock
305
336
  // The burst runs here, under the Layer's build context, never in a caller's.
306
337
  const buildContext = yield* Effect.context<Clock.Clock | Scope.Scope>()
338
+ /** A hook's throw, reported on what the loop was built with: its failure path. */
339
+ const hookFailed = (defect: unknown): void => {
340
+ Effect.runForkWith(buildContext)(Report.failure("wardic.frameLoop: an afterTick hook failed", Cause.die(defect)))
341
+ }
307
342
  // The burst's fiber (#746: what a `FiberHandle` held, in a field, so an app ships no FiberHandle): a
308
343
  // new burst's replaces it, interrupting it, and the loop's Scope interrupts it and lets it go. Once
309
344
  // that Scope has closed, the loop takes no run (`entered`), as the handle's closed state had it.
@@ -339,13 +374,39 @@ export const make = Effect.fnUntraced(
339
374
  // is held (#81).
340
375
  let bursting = false
341
376
  // The Late window (ADR-0027 *Amendment (#680)*): open from a tick's first step until the microtask
342
- // 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
343
378
  // it before a checkpoint (a test firing frames back to back).
344
- let windowOpen = false
345
- let windowQueued = false
379
+ let lateWindowOpen = false
380
+ let lateWindowQueued = false
346
381
  // The dt of the tick that opened the window: a Late step's. A nominal frame before any tick, for a
347
382
  // window a hint opens while idle (#791).
348
- let windowDt = Clock.NOMINAL_DT
383
+ let tickDt = Clock.NOMINAL_DT
384
+ // The ticks run, for `tickCount` (#991): one add a tick.
385
+ let ticked = 0
386
+ // A late frame, as the Environment tells one (#1026, `Clock.LateFrames`): the line, in ms, `NaN` for
387
+ // none. Telling one, each tick reads its frame's timestamp and when it ran, on the Clock's `now()`, and
388
+ // how late it is by its lag, in seconds (`tickLateByLag`); a hint's window while the loop idles tells nothing.
389
+ const lateAfter = lateAfterOf(yield* Clock.LateFrames)
390
+ const tellsLate = !Number.isNaN(lateAfter)
391
+ let tickLateByLag = 0
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
349
410
  // The `run` runs added in the window, in add order: their Late step is due. The `runLast` runs added
350
411
  // in it take none, and are marked only so the dt-0 step leaves them out: they step at the next tick.
351
412
  const lateFirst: Array<Entry> = []
@@ -379,11 +440,65 @@ export const make = Effect.fnUntraced(
379
440
  }
380
441
  // The loop's own hook, the first: the counts reach the counters at the end of every tick, and
381
442
  // `tick`, the per-frame path, is as it was (#542).
382
- hooks = [{ hook: countEnds }]
443
+ hooks = [{ hook: countEnds, failing: false }]
383
444
 
384
445
  // Per frame (ADR-0025): plain calls only, in the one `Stream.map` call per tick (ADR-0027,
385
446
  // decision 8); counted loops, statement `if`s, a `try` per entry (it costs nothing measurable).
386
447
 
448
+ /**
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.
455
+ */
456
+ // A repeated timestamp: Firefox's frame right after an input (#18; ADR-0017, amended by #2).
457
+ const tellLate = (): void => {
458
+ const stamp = clock.frameAt()
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
473
+ lastStamp = stamp
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),
488
+ }
489
+
490
+ /**
491
+ * The dt `entry` steps at (#1026): the tick's, but a run takes none of a long task's time from before it
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.
494
+ */
495
+ const dtOf = (entry: Entry, dt: number): number => {
496
+ const owed = entry.owed
497
+ if (owed === 0) return dt
498
+ entry.owed = reader.owedAfter(owed)
499
+ return reader.owingDt(owed, dt)
500
+ }
501
+
387
502
  /**
388
503
  * Step the last lane's first `count` entries, in add order, as `tick` steps the others. Per frame,
389
504
  * and only while it holds a run.
@@ -393,8 +508,9 @@ export const make = Effect.fnUntraced(
393
508
  const entry = lastEntries[i]
394
509
  if (entry.removed) continue
395
510
  try {
396
- const frame = entry.step(dt)
397
- entry.sink(frame, dt)
511
+ const at = dtOf(entry, dt)
512
+ const frame = entry.step(at)
513
+ entry.sink(frame, at)
398
514
  if (entry.settles && frame.done) end(entry, Exit.succeed(frame))
399
515
  } catch (defect) {
400
516
  end(entry, dieNamed(entry.name, defect))
@@ -418,11 +534,13 @@ export const make = Effect.fnUntraced(
418
534
  // The first lane's loops stay inline in `tick`: moved into a function shared with the last lane,
419
535
  // Node's `chase/loop` ran 55% slower (`bench:core`, ADR-0027 *Amendment (#137)*).
420
536
  const tick = (dt: number): boolean => {
537
+ ticked++
421
538
  // A window this tick finds open is the last frame's, its checkpoint not yet run (back-to-back
422
539
  // frames in a test): its runs are on the lanes, so this tick steps them.
423
540
  if (lateFirst.length + lateLast.length > 0) dropLate()
424
- windowOpen = true
425
- windowDt = dt
541
+ lateWindowOpen = true
542
+ tickDt = dt
543
+ if (tellsLate) tellLate()
426
544
  // The tick's start, read only for the metrics' histogram (#518).
427
545
  let t0 = 0
428
546
  if (Predicate.isNotUndefined(metrics)) t0 = performance.now()
@@ -430,12 +548,14 @@ export const make = Effect.fnUntraced(
430
548
  // Late step at the window's end, a `runLast` run waits for the next tick (#680).
431
549
  const count = entries.length
432
550
  const lastCount = lastEntries.length
551
+ tickStepping = true
433
552
  for (let i = 0; i < count; i++) {
434
553
  const entry = entries[i]
435
554
  if (entry.removed) continue
436
555
  try {
437
- const frame = entry.step(dt)
438
- entry.sink(frame, dt)
556
+ const at = dtOf(entry, dt)
557
+ const frame = entry.step(at)
558
+ entry.sink(frame, at)
439
559
  if (entry.settles && frame.done) end(entry, Exit.succeed(frame))
440
560
  } catch (defect) {
441
561
  end(entry, dieNamed(entry.name, defect))
@@ -443,6 +563,7 @@ export const make = Effect.fnUntraced(
443
563
  }
444
564
  // The last lane, after every other run (ADR-0027, *Amendment (#137)*).
445
565
  if (lastCount > 0) stepLast(lastCount, dt)
566
+ tickStepping = false
446
567
  // Drop the removed entries in place, keeping order (and those added during the pass).
447
568
  let kept = 0
448
569
  for (let i = 0; i < entries.length; i++) {
@@ -459,11 +580,22 @@ export const make = Effect.fnUntraced(
459
580
  }
460
581
  // The end of the tick: everything for this Refresh frame is written (ADR-0033). After
461
582
  // `tickMs`, which stays the cost of the steps alone.
583
+ // Each hook's own (#979, ADR-0074): one that throws is reported once until a call returns, and the
584
+ // others run. A try per hook, around its direct call, its flag cleared only when it's set.
462
585
  const ended = hooks
463
- for (let i = 0; i < ended.length; i++) ended[i].hook(dt)
586
+ for (let i = 0; i < ended.length; i++) {
587
+ const added = ended[i]
588
+ try {
589
+ added.hook(dt)
590
+ if (added.failing) added.failing = false
591
+ } catch (defect) {
592
+ if (!added.failing) hookFailed(defect)
593
+ added.failing = true
594
+ }
595
+ }
464
596
  // The window stays open to the end of this frame's microtasks, which take the Late steps (#680).
465
- if (!windowQueued) {
466
- windowQueued = true
597
+ if (!lateWindowQueued) {
598
+ lateWindowQueued = true
467
599
  queueMicrotask(endLateWindow)
468
600
  }
469
601
  // The burst ends with no run left, counted after the hooks: one a hook started (the flush
@@ -486,11 +618,14 @@ export const make = Effect.fnUntraced(
486
618
  list.length = left
487
619
  }
488
620
 
489
- /** One step of `entry` at `dt`: its Frame to its sink, its settle, or its defect, as a tick's. */
490
- const stepOne = (entry: Entry, dt: number): void => {
621
+ /**
622
+ * One step of `entry` at `at`: its Frame to its sink, its settle, or its defect, as a tick's. A Late
623
+ * step's dt is its first's; a dt-0 step leaves what it owes as it was.
624
+ */
625
+ const stepOne = (entry: Entry, at: number): void => {
491
626
  try {
492
- const frame = entry.step(dt)
493
- entry.sink(frame, dt)
627
+ const frame = entry.step(at)
628
+ entry.sink(frame, at)
494
629
  if (entry.settles && frame.done) end(entry, Exit.succeed(frame))
495
630
  } catch (defect) {
496
631
  end(entry, dieNamed(entry.name, defect))
@@ -502,7 +637,7 @@ export const make = Effect.fnUntraced(
502
637
  entry.late = false
503
638
  if (entry.removed) return false
504
639
  if (Predicate.isNotUndefined(entry.span)) entry.span.attribute("late", true)
505
- stepOne(entry, windowDt)
640
+ stepOne(entry, dtOf(entry, tickDt))
506
641
  return true
507
642
  }
508
643
 
@@ -525,7 +660,17 @@ export const make = Effect.fnUntraced(
525
660
  }
526
661
  dropFirst(lateFirst, firstCount)
527
662
  const again = hooks
528
- for (let i = 0; i < again.length; i++) again[i].hook(windowDt)
663
+ // As the tick's (#979).
664
+ for (let i = 0; i < again.length; i++) {
665
+ const added = again[i]
666
+ try {
667
+ added.hook(tickDt)
668
+ if (added.failing) added.failing = false
669
+ } catch (defect) {
670
+ if (!added.failing) hookFailed(defect)
671
+ added.failing = true
672
+ }
673
+ }
529
674
  }
530
675
 
531
676
  /**
@@ -533,8 +678,8 @@ export const make = Effect.fnUntraced(
533
678
  * left past the cap steps at the next tick. A hook that throws ends every run, as in a tick (Q15).
534
679
  */
535
680
  const endLateWindow = (): void => {
536
- windowQueued = false
537
- if (!windowOpen) return
681
+ lateWindowQueued = false
682
+ if (!lateWindowOpen) return
538
683
  let rounds = 0
539
684
  try {
540
685
  while (lateFirst.length > 0 && rounds < MAX_LATE_ROUNDS) {
@@ -547,7 +692,7 @@ export const make = Effect.fnUntraced(
547
692
  }
548
693
  // Past the cap, the first lane's rest step at the next tick; the last lane's were never due.
549
694
  if (lateFirst.length + lateLast.length > 0) dropLate()
550
- windowOpen = false
695
+ lateWindowOpen = false
551
696
  }
552
697
 
553
698
  /**
@@ -569,17 +714,25 @@ export const make = Effect.fnUntraced(
569
714
 
570
715
  /** A binding's hint (above): the window opened under the rule, closed by the microtask it queues. */
571
716
  const hint = (frameTime: number): void => {
572
- if (windowOpen) return
717
+ if (lateWindowOpen) return
573
718
  if (bursting && clock.frameAt() !== frameTime) return
574
- windowOpen = true
575
- if (!windowQueued) {
576
- 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
577
728
  queueMicrotask(endLateWindow)
578
729
  }
579
730
  }
580
731
 
732
+ const tickCount = (): number => ticked
733
+
581
734
  const afterTick = (hook: (dt: number) => undefined): Effect.Effect<void, never, Scope.Scope> => {
582
- const added: Hook = { hook }
735
+ const added: Hook = { hook, failing: false }
583
736
  return Effect.acquireRelease(
584
737
  Effect.sync(() => {
585
738
  hooks = Arr.append(hooks, added)
@@ -607,7 +760,7 @@ export const make = Effect.fnUntraced(
607
760
  // A burst that failed closes the window: no later call is in it (#673, TK3; #680). One that ran out
608
761
  // of runs leaves it open, so a run started after its last tick, in its frame, takes its Late step.
609
762
  if (failed) {
610
- windowOpen = false
763
+ lateWindowOpen = false
611
764
  dropLate()
612
765
  }
613
766
  Arr.forEach(Arr.appendAll(entries.splice(0), lastEntries.splice(0)), (entry) => {
@@ -636,6 +789,8 @@ export const make = Effect.fnUntraced(
636
789
  onTrue: () => Effect.void,
637
790
  onFalse: () => {
638
791
  bursting = true
792
+ // The time since the last burst's last frame is no frame's gap (#1048).
793
+ gapFrom = Number.NaN
639
794
  // Detached and started at once, as `FiberHandle.run` forks: no scheduler hop before the
640
795
  // subscription, and no caller's fiber its parent.
641
796
  return Effect.map(Effect.forkDetach(ticking, START_NOW), hold)
@@ -709,6 +864,10 @@ export const make = Effect.fnUntraced(
709
864
  if (closed) return Effect.interrupt
710
865
  let checkedSink: FrameLoop.Sink<F> = sink
711
866
  if (check) checkedSink = checked(sink)
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.
869
+ let owed = 0
870
+ if (tellsLate && !onFrameTimeline(options)) owed = reader.madeOwing()
712
871
  const entry: Entry = {
713
872
  name: machine.span.name,
714
873
  step: machine.start(),
@@ -716,18 +875,21 @@ export const make = Effect.fnUntraced(
716
875
  settles: machine.settles,
717
876
  settled: Deferred.makeUnsafe<Frame.Frame<unknown> | Supersede.Superseded>(),
718
877
  removed: false,
719
- late: windowOpen,
878
+ late: lateWindowOpen,
720
879
  span,
880
+ owed,
721
881
  }
722
882
  lane.push(entry)
723
883
  if (entry.late) late.push(entry)
724
- if (Predicate.isNotUndefined(options)) joinSupersede(options.supersede, entry)
884
+ if (Predicate.isNotUndefined(options) && Predicate.isNotUndefined(options.supersede)) joinSupersede(options.supersede, entry)
725
885
  return Effect.as(startBurst, entry)
726
886
  }
727
887
 
728
- const inLateWindow = (): boolean => windowOpen
888
+ const inLateWindow = (): boolean => lateWindowOpen
729
889
 
730
- return { run: runIn(entries, lateFirst), runLast: runIn(lastEntries, lateLast), afterTick, inLateWindow, 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)
731
893
  },
732
894
  (self) => traced(self, "wardic.frameloop.make"),
733
895
  )
@@ -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
+ }
@@ -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.