@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
@@ -4,8 +4,8 @@
4
4
  * An Environment says what its Subjects are and how a plain one starts ({@link Subjects}), and what
5
5
  * its Batches are ({@link Batches}); each binding's `createAnimate()` builds on it.
6
6
  *
7
- * - **A Wardic element** animates through its own spine, registered here while it's mounted: the
8
- * call takes the keys it animates, which stay where it leaves them until the element's own target
7
+ * - **A Ward's Subject** animates through its own spine, registered here while it's mounted: the
8
+ * call takes the keys it animates, which stay where it leaves them until the Subject's own target
9
9
  * for them changes (Motion's latest-wins).
10
10
  * - **A plain Subject** animates through a spine of its own (#433's Q4), with no config, presence or
11
11
  * layout node: it starts from the Subject's Own value (ADR-0022) and keeps its values for the next
@@ -53,25 +53,26 @@ import * as Effect from "effect/Effect"
53
53
  import * as Exit from "effect/Exit"
54
54
  import type * as Fiber from "effect/Fiber"
55
55
  import { constTrue, constVoid, identity } from "effect/Function"
56
+ import * as Option from "effect/Option"
56
57
  import * as Predicate from "effect/Predicate"
57
58
  import * as Rec from "effect/Record"
58
59
  import * as UndefinedOr from "effect/UndefinedOr"
59
60
 
60
- /** What an Imperative animation animates a Wardic element through: what its spine hands over (`host`). */
61
- type Animatable = Pick<Spine.ElementSpine, "host">
61
+ /** What an Imperative animation animates a Ward's Subject through: what its spine hands over (`host`). */
62
+ type Animatable = Pick<Spine.SubjectSpine, "host">
62
63
 
63
- /** Each mounted Wardic element's spine (Motion's `visualElementStore`), by its Subject. */
64
- // Module state (#460, Q7): each Wardic element's animatable, held weakly by its Subject.
65
- const wardicElements = new WeakMap<object, Animatable>()
64
+ /** Each mounted Ward's Subject's spine (Motion's `visualElementStore`), by its Subject. */
65
+ // Module state (#460, Q7): each Ward's Subject's animatable, held weakly by the Subject.
66
+ const wardedSubjects = new WeakMap<object, Animatable>()
66
67
 
67
68
  /**
68
- * Register a mounted Wardic element's spine for the Imperative animations of its Subject (#433): until
69
+ * Register a mounted Ward's Subject's spine for the Imperative animations of its Subject (#433): until
69
70
  * the returned function, which its unmount calls.
70
71
  */
71
72
  export const registerAnimatable = (subject: object, spine: Animatable): (() => void) => {
72
- wardicElements.set(subject, spine)
73
+ wardedSubjects.set(subject, spine)
73
74
  return () => {
74
- if (wardicElements.get(subject) === spine) wardicElements.delete(subject)
75
+ if (wardedSubjects.get(subject) === spine) wardedSubjects.delete(subject)
75
76
  }
76
77
  }
77
78
 
@@ -97,13 +98,13 @@ export interface AnimateEnv {
97
98
 
98
99
  /**
99
100
  * An Environment's Subjects, for `animate`: what its first argument names, and where a plain one
100
- * starts. The DOM's are elements, selectors looked up in the scope and lists of them; a scene's, its
101
- * objects.
101
+ * starts. `@wardic/dom`'s are its own kind, the strings it looks up in the scope, and lists of them; a scene's,
102
+ * its objects.
102
103
  */
103
104
  export interface Subjects<S extends object> {
104
105
  /** The Subjects `given` names, inside `scope` (a binding's scope, or `undefined`): none when it names none. */
105
106
  readonly resolve: (given: unknown, scope: unknown) => ReadonlyArray<S>
106
- /** A plain Subject's Base-value links (ADR-0022): its Own values, and the DOM's Starting style. */
107
+ /** A plain Subject's Base-value links (ADR-0022): its Own values, and `@wardic/dom`'s Starting style. */
107
108
  readonly startLinksOf: (subject: S) => Spine.StartLinks
108
109
  }
109
110
 
@@ -208,7 +209,7 @@ export interface Ports<S extends object> {
208
209
 
209
210
  /** A plain Subject's spine (#433's Q4), its values, and how many of its animations run, which keep it in the gate. */
210
211
  interface Plain {
211
- readonly spine: Spine.ElementSpine
212
+ readonly spine: Spine.SubjectSpine
212
213
  readonly snapshot: Spine.Snapshot
213
214
  readonly id: string
214
215
  running: number
@@ -237,11 +238,11 @@ const plainOf = <S extends object>(env: AnimateEnv, subjects: Subjects<S>, subje
237
238
  if (Predicate.isNotUndefined(known)) return known
238
239
  const id = `wardic-animate-${plainIds++}`
239
240
  const snapshot: Spine.Snapshot = Spine.emptySnapshotOf({})
240
- const spine = Spine.makeElementSpine({
241
+ const spine = Spine.makeSubjectSpine({
241
242
  runtime: env.runtime,
242
243
  gate: env.gate,
243
244
  id,
244
- element: subject,
245
+ subject,
245
246
  tag: undefined,
246
247
  config: () => NO_CONFIG,
247
248
  parent: undefined,
@@ -254,7 +255,7 @@ const plainOf = <S extends object>(env: AnimateEnv, subjects: Subjects<S>, subje
254
255
  ownValues: env.ownValues,
255
256
  measuredPairs: env.measuredPairs,
256
257
  variableValues: env.variableValues,
257
- start: { initialValues: {}, initialLink: {}, startedLink: {}, quiet: false },
258
+ start: { initialValues: {}, initialLink: {}, startedLink: {}, quiet: false, failure: Option.none() },
258
259
  snapshot,
259
260
  reuse: Spine.makeReuse(),
260
261
  links: subjects.startLinksOf(subject),
@@ -272,7 +273,7 @@ const plainOf = <S extends object>(env: AnimateEnv, subjects: Subjects<S>, subje
272
273
 
273
274
  /**
274
275
  * `transition` with `skipAnimations` when its scope's animations are skipped (#468, Motion's
275
- * `useAnimate`, which hands its config's to each animation): a Wardic element's own config can skip it
276
+ * `useAnimate`, which hands its config's to each animation): a Ward's Subject's own config can skip it
276
277
  * too, and a plain Subject has none.
277
278
  */
278
279
  const skippedIn = (env: AnimateEnv, transition: Config.WardicTransition | undefined): Config.WardicTransition | undefined => {
@@ -305,8 +306,12 @@ const lastTargetsOf = (host: Spine.SpineHost): Values.Values => UndefinedOr.matc
305
306
  /**
306
307
  * `key` taken by an Imperative animation from whatever runs it (#433): noted in `taking` with `noted`,
307
308
  * the target the Override stack has for it now, no longer returning, its Timeline value stopped, given
308
- * up by its owner, owned, and started where it's drawn toward `like`, noted in `started`.
309
+ * up by its owner, owned, and started where it's drawn toward `like`, noted in `started`. Its Own value
310
+ * is read before it's taken, by the call (`readiedOf`) or the landing (`settableOrReported`); a run's
311
+ * retake at a replay reads none, the call having read it.
309
312
  */
313
+ // #973 (ADR-0061, *Amendment (#973)*, Q3): read here, a key refused at the call had already taken the keys
314
+ // before it, of its Subject and of a list's earlier Subjects, ending the animations that drew them.
310
315
  const takeKey = (host: Spine.SpineHost, taking: Map<string, number | string | undefined>, key: string, noted: number | string | undefined, like: number | string, started: Record<string, string>): void => {
311
316
  taking.set(key, noted)
312
317
  host.returning().delete(key)
@@ -315,10 +320,18 @@ const takeKey = (host: Spine.SpineHost, taking: Map<string, number | string | un
315
320
  if (Predicate.isNotUndefined(timelineKeys)) timelineKeys.taken(key)
316
321
  const owner = host.owners.get(key)
317
322
  if (Predicate.isNotUndefined(owner)) host.giveUp(key, owner)
318
- if (!Object.hasOwn(host.initialValues, key)) host.ownValue(key)
319
323
  host.startKey(key, like, started)
320
324
  }
321
325
 
326
+ /**
327
+ * `key`'s Own value read, where it has no `initial` value: a key the Subject lacks, or can't write, is
328
+ * its Environment's error, naming it.
329
+ */
330
+ // Per key at a call and at a landing, the hot path (effect-first.md): a statement.
331
+ const readOwn = (host: Spine.SpineHost, key: string): void => {
332
+ if (!Object.hasOwn(host.initialValues, key)) host.ownValue(key)
333
+ }
334
+
322
335
  /** Whether a Transition end may set a key drawn by `owner`: none draws it, or its leg is done. */
323
336
  const endFree = (owner: Spine.Running | undefined): boolean => {
324
337
  if (Predicate.isUndefined(owner)) return true
@@ -332,12 +345,14 @@ const endFree = (owner: Spine.Running | undefined): boolean => {
332
345
  * Its legs start where the keys are drawn, with their velocity, on `given` (a key with none of its own
333
346
  * on its Default transition), reduced motion as the provider says, and run through `head` once
334
347
  * {@link Spine.ImperativeTrack.run} is called. Once they land, none taken, its target's Transition
335
- * end is set (#896), and put back by a cancel or a run again.
348
+ * end is set (#896), and put back by a cancel or a run again. Its keys, the end's too, were read before
349
+ * it's made (`readiedOf`); one the Subject can no longer set by a landing is reported there and left as it
350
+ * is, and the rest of the end set (#970).
336
351
  */
337
352
  // #746 (ADR-0067, *Amendment (#746)*, decision 10): here, not in the spine, so an app that never animates
338
353
  // imperatively ships none of it; the spine hands over what it takes (`SpineHost`).
339
354
  const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target, given: Config.WardicTransition | undefined, head: Playback.Playhead, hooks: Spine.ImperativeHooks): Spine.ImperativeTrack => {
340
- const { snapshot, owners, keepTheRest, element, positionalKeys, defaultTransition, unitScale, readVelocity, gate, forget, endLeg, live, own, legProgram, legEnded, turnBack, id, recordFrame, runtime, elementRules, measuredPairs, variableValues } = host
355
+ const { snapshot, owners, keepTheRest, subject, positionalKeys, defaultTransition, unitScale, readVelocity, gate, forget, endLeg, live, own, legProgram, legEnded, turnBack, id, recordFrame, runtime, subjectRules, measuredPairs, variableValues } = host
341
356
  /** A leg of an Imperative animation, forked as a Retarget's are; it lands on its track. */
342
357
  // Data-first: a pipe's curried forms are two closures more for every leg (#618, H1).
343
358
  const runImperative = (running: Spine.Running, program: Effect.Effect<unknown, never, WardicServices.WardicServices>): void => {
@@ -348,6 +363,7 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
348
363
  })))
349
364
  }
350
365
  const to = target.values
366
+ const ends = target.transitionEnd
351
367
  const before = lastTargetsOf(host)
352
368
  const started: Record<string, string> = {}
353
369
  let measuring: Array<string> | undefined
@@ -375,14 +391,13 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
375
391
  const reduce = host.reducedMotion()
376
392
  const skipped = host.skipAnimations()
377
393
  let measured: RetargetLegs.MeasuredPairs | undefined
378
- if (Bool.and(Bool.not(Bool.or(reduce, skipped)), Predicate.isNotUndefined(measuring))) measured = Spine.measuredOf(measuredPairs, element, UndefinedOr.getOrThrow(measuring), from, to, snapshot.values, stops)
394
+ if (Bool.and(Bool.not(Bool.or(reduce, skipped)), Predicate.isNotUndefined(measuring))) measured = Spine.measuredOf(measuredPairs, subject, UndefinedOr.getOrThrow(measuring), from, to, snapshot.values, stops, runtime, id)
379
395
  // Built once: a seek or a replay runs the same legs, from the same start, with the same velocities.
380
396
  const built = RetargetLegs.legsOf(from, to, given, reduce, skipped, positionalKeys, defaultTransition, readVelocity, undefined, stops, measured, snapshot.values, rests, unitScale)
381
397
  const variables = Spine.holdsVariable(variableValues, from, to, stops)
382
398
  const legs = Arr.map(built, (leg) => RetargetLegs.mapMachine(leg, Playback.drive(head)))
383
399
  let runnings: ReadonlyArray<Spine.Running> = Spine.NO_RUNNING
384
400
  let left = 0
385
- const ends = target.transitionEnd
386
401
  // What its Transition end's keys were before it set them (Q5): `undefined` until it has.
387
402
  let overwritten: Values.Values | undefined
388
403
  // Its runs, stops and cancels, counted: what a landing waiting on a flush checks it's still for.
@@ -412,8 +427,20 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
412
427
  if (only(key)) takeKey(host, takingNow, key, targetsNow[key], UndefinedOr.getOrThrow(values[key]), startedNow)
413
428
  })
414
429
  }
430
+ // Whether an end's `key` can still be set, else reported: one its Subject has lost, or can no longer
431
+ // write, since the call read it is reported at the landing and left as it is, and the rest of the end is
432
+ // set (#970).
433
+ const settableOrReported = (key: string): boolean => {
434
+ try {
435
+ readOwn(host, key)
436
+ return true
437
+ } catch (defect) {
438
+ runtime.runFork(Report.failure(`wardic.animate: a Transition end's "${key}" couldn't be set, the rest of it set and the animation landed`, Cause.die(defect)))
439
+ return false
440
+ }
441
+ }
415
442
  const writeEnds = (values: Values.Values): void => {
416
- const free = Rec.filter(values, (_, key) => endFree(owners.get(key)))
443
+ const free = Rec.filter(values, (_, key) => endFree(owners.get(key)) && settableOrReported(key))
417
444
  if (Rec.isEmptyRecord(free)) return
418
445
  takeEach(free, constTrue)
419
446
  // Kept from an earlier landing a run from its end didn't put back: what they were before any.
@@ -422,7 +449,7 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
422
449
  }
423
450
  /**
424
451
  * Its Transition end's keys put back as they were before it was set (Q5): at a cancel, a seek or a
425
- * replay, each a key no leg has drawn since, a later call's or the element's own. The next landing
452
+ * replay, each a key no leg has drawn since, a later call's or the Subject's own. The next landing
426
453
  * sets them again.
427
454
  */
428
455
  const putBack = (): void => {
@@ -436,10 +463,10 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
436
463
  // frame, its keys landed from its start, so a take before then takes nothing in flight, as Motion's
437
464
  // skipped value makes no animation. Its machine read only for a leg that lost a key.
438
465
  const snaps = (i: number): boolean => Machine.durationOf(machineOf(UndefinedOr.getOrThrow(built[i]))) === 0
439
- // A leg the element's own Retarget carried on, toward the same target, as its own (Q7): the call has lost it.
466
+ // A leg the Subject's own Retarget carried on, toward the same target, as its own (Q7): the call has lost it.
440
467
  let carried = false
441
468
  // Taken (#896's Q3, #951): a key it animates taken from its leg mid-flight, by a later animation or the
442
- // element's own target, or a leg carried off whole. A leg that lost one has fewer than it started
469
+ // Subject's own target, or a leg carried off whole. A leg that lost one has fewer than it started
443
470
  // with; one taken after its leg landed doesn't count, as Motion's, nor one that snaps.
444
471
  const taken = (): boolean => {
445
472
  if (carried) return true
@@ -482,7 +509,7 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
482
509
  }
483
510
  /**
484
511
  * A leg of this run ended **Superseded** (#951), told at its end, as it settles nothing of this
485
- * track's: carried on by the element's own Retarget as its own, its landing the Retarget's now (Q7);
512
+ * track's: carried on by the Subject's own Retarget as its own, its landing the Retarget's now (Q7);
486
513
  * or with every key taken, a count of 0 (only a take lowers it), which `taken` reads. Either counts
487
514
  * toward the track's landing, which finds it taken.
488
515
  */
@@ -507,7 +534,7 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
507
534
  if (head.speed < 0) return false
508
535
  return head.time >= duration()
509
536
  }
510
- // A key another leg draws: a later animation's, or the element's own.
537
+ // A key another leg draws: a later animation's, or the Subject's own.
511
538
  const drawnByAnother = (key: string): boolean => Predicate.isNotUndefined(owners.get(key))
512
539
  const run = (): void => {
513
540
  runs++
@@ -541,7 +568,7 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
541
568
  const duration = (): number =>
542
569
  Arr.reduce(built, 0, (longest, leg) => Math.max(longest, Machine.durationOf(machineOf(leg))))
543
570
  const machineOf = (leg: RetargetLegs.Leg): Machine.Machine<Frame.Frame<unknown>> => {
544
- if (leg._tag === "Blend") return runtime.runSync(Effect.suspend(leg.machine).pipe(InterpolatorRegistry.withKeyRules(elementRules)))
571
+ if (leg._tag === "Blend") return runtime.runSync(Effect.suspend(leg.machine).pipe(InterpolatorRegistry.withKeyRules(subjectRules)))
545
572
  return leg.machine() as Machine.Machine<Frame.Frame<unknown>>
546
573
  }
547
574
  const stop = (): void => {
@@ -554,7 +581,7 @@ const imperativeTrackOf = (host: Spine.SpineHost, target: VariantTarget.Target,
554
581
 
555
582
  /**
556
583
  * A call's transition on its target's own (#896, ADR-0061 *Amendment (#896)*, Q1): the options' fields
557
- * laid over the target's, shallowly, as `inherit: true` lays a target's over its element's. Motion's
584
+ * laid over the target's, shallowly, as `inherit: true` lays a target's over its Subject's. Motion's
558
585
  * `animate` reads the options alone.
559
586
  */
560
587
  // Its own handed back as it is with no options, so the legs' decode cache (#66) holds for it. Its
@@ -565,17 +592,57 @@ const overOwn = (own: Config.WardicVariantTransition | undefined, given: Config.
565
592
  return { ...own, ...given } as Config.WardicTransition
566
593
  }
567
594
 
595
+ /** A Subject's animation, its keys read and none taken yet: its target, and the spine it runs through. */
596
+ interface Readied<S extends object> {
597
+ readonly subject: S
598
+ readonly target: VariantTarget.Target
599
+ readonly host: Spine.SpineHost
600
+ /** Its plain spine: `undefined` for a Ward's Subject's, which runs through the Subject's own. */
601
+ readonly plain: Plain | undefined
602
+ }
603
+
568
604
  /**
569
- * A Subject's animation of `target`: through its spine when it's a Wardic element's, else through its
570
- * plain spine, in the gate while any of its animations runs.
605
+ * `subject`'s animation of `variant`, readied: each key the target names, its Transition end's then its
606
+ * values', read as its Environment reads it, so one the Subject can't take is an error now, naming it.
607
+ * A call readies each of its Subjects before it builds any track ({@link trackOf}), so a call refused here
608
+ * has taken nothing: an animation it would have taken a key from runs on.
571
609
  */
572
- const trackOf = <S extends object>(env: AnimateEnv, subjects: Subjects<S>, subject: S, target: Config.WardicVariant, given: Config.WardicTransition | undefined, head: Playback.Playhead, settled: (landed: boolean) => void): Spine.ImperativeTrack => {
573
- const resolved = VariantTarget.resolveTarget(target, undefined, undefined, VariantTarget.NO_VARIANT_STATE)
574
- const own = wardicElements.get(subject)
575
- const hooks = { settled, failed: constVoid }
576
- const transition = skippedIn(env, overOwn(resolved.transition, given))
577
- if (Predicate.isNotUndefined(own)) return imperativeTrackOf(own.host(), resolved, transition, head, hooks)
610
+ // #973 (ADR-0061, *Amendment (#973)*, Q1): tracks took their keys as each was built, so a later key's
611
+ // refusal, its Subject's or a later Subject's, ended the animations that drew the keys taken before it.
612
+ const readiedOf = <S extends object>(env: AnimateEnv, subjects: Subjects<S>, subject: S, variant: Config.WardicVariant): Readied<S> => {
613
+ const target = VariantTarget.resolveTarget(variant, undefined, undefined, VariantTarget.NO_VARIANT_STATE)
614
+ // A function given as the target (past the types) that throws is an error at the call, as a key it
615
+ // can't take is: the call takes nothing (#979; ADR-0074 keeps a refusal at the call a throw).
616
+ if (Option.isSome(target.failure)) throw target.failure.value.defect
617
+ const own = wardedSubjects.get(subject)
618
+ if (Predicate.isNotUndefined(own)) return readOwnValues({ subject, target, host: own.host(), plain: undefined })
578
619
  const plain = plainOf(env, subjects, subject)
620
+ return readOwnValues({ subject, target, host: plain.spine.host(), plain })
621
+ }
622
+
623
+ /**
624
+ * `readied`'s Own values read, its Transition end's keys then its target's: an error the Environment's
625
+ * read throws is thrown, naming the first key it can't take.
626
+ */
627
+ // Its end's first, as #970 read them, so a key refused in both names the end's. Per key at a call, the hot
628
+ // path (effect-first.md): statements, a loop's body its closure.
629
+ const readOwnValues = <S extends object>(readied: Readied<S>): Readied<S> => {
630
+ const { host, target } = readied
631
+ const ends = target.transitionEnd
632
+ if (Predicate.isNotUndefined(ends)) Arr.forEach(Rec.keys(ends), (key) => readOwn(host, key))
633
+ Arr.forEach(Rec.keys(target.values), (key) => readOwn(host, key))
634
+ return readied
635
+ }
636
+
637
+ /**
638
+ * A readied Subject's animation (`readiedOf`): through its spine when it's a Ward's Subject's, else through
639
+ * its plain spine, in the gate while any of its animations runs.
640
+ */
641
+ const trackOf = <S extends object>(env: AnimateEnv, readied: Readied<S>, given: Config.WardicTransition | undefined, head: Playback.Playhead, settled: (landed: boolean) => void): Spine.ImperativeTrack => {
642
+ const { subject, target, host, plain } = readied
643
+ const hooks = { settled, failed: constVoid }
644
+ const transition = skippedIn(env, overOwn(target.transition, given))
645
+ if (Predicate.isUndefined(plain)) return imperativeTrackOf(host, target, transition, head, hooks)
579
646
  // In the gate while it runs; out once its last animation is done, after the flush of its last frame.
580
647
  let live = false
581
648
  const enter = (): void => {
@@ -596,7 +663,7 @@ const trackOf = <S extends object>(env: AnimateEnv, subjects: Subjects<S>, subje
596
663
  if (plain.running === 0) plain.unregister()
597
664
  })
598
665
  }
599
- const track = imperativeTrackOf(plain.spine.host(), resolved, transition, head, {
666
+ const track = imperativeTrackOf(host, target, transition, head, {
600
667
  settled: (landed) => {
601
668
  leave()
602
669
  settled(landed)
@@ -640,8 +707,9 @@ interface EachDelay {
640
707
  /**
641
708
  * `animate`'s options: a transition, laid field by field over the target's own, its `delay` a number,
642
709
  * or a function of each Subject's index and their count, such as `stagger(0.05)`; and `onComplete`,
643
- * called as it lands, each Subject's `transitionEnd` already set. Motion's, though Motion's `animate`
644
- * runs on the options alone.
710
+ * called as it lands, each Subject's `transitionEnd` already set and the animation already `"finished"`,
711
+ * so one that throws is reported and leaves it finished. Motion's, though Motion's `animate` runs on the
712
+ * options alone.
645
713
  */
646
714
  export type WardicAnimateOptions = AnimateOptionsOver<Config.WardicTransition>
647
715
 
@@ -693,6 +761,12 @@ const skipsBatchCall = (env: AnimateEnv, options: WardicAnimateOptions | undefin
693
761
  /** Where an animation is: `"idle"`, `"running"`, `"paused"` or `"finished"`. Motion's `AnimationPlayState`. */
694
762
  export type WardicPlayState = "idle" | "running" | "paused" | "finished"
695
763
 
764
+ /** How an animation ended: whether it landed. */
765
+ export interface WardicAnimationEnd {
766
+ /** It arrived: it landed at its end, or `complete()` took it there. False when it was stopped, cancelled or taken over. */
767
+ readonly landed: boolean
768
+ }
769
+
696
770
  /**
697
771
  * What `animate` returns: an animation's controls, and a promise of its landing, so it can be awaited.
698
772
  * Motion's `AnimationPlaybackControls`.
@@ -715,6 +789,22 @@ export interface WardicPlaybackControls extends PromiseLike<void> {
715
789
  * animation takes one of its keys, as Motion's.
716
790
  */
717
791
  readonly finished: Promise<void>
792
+ /**
793
+ * Resolves once it ends, however it ends, with whether it landed: `landed` at its landing or
794
+ * `complete()`, and not at `stop()`, `cancel()`, or once a later animation takes one of its keys.
795
+ * It never rejects. Each time it plays has its own: played again, sought or completed after it ended,
796
+ * it gives a new one.
797
+ *
798
+ * @example
799
+ * setBusy(true)
800
+ * try {
801
+ * await controls.ended
802
+ * } finally {
803
+ * setBusy(false)
804
+ * }
805
+ */
806
+ // #955 (ADR-0061, *Amendment (#955)*): Wardic's own, beside Motion's `finished`.
807
+ readonly ended: Promise<WardicAnimationEnd>
718
808
  /** Play it on: from where it's paused, or again from its start once it's finished or cancelled. Not after `stop()`. */
719
809
  readonly play: () => void
720
810
  /** Hold it where it is. */
@@ -734,8 +824,65 @@ export interface AnimationWatch {
734
824
  readonly ended: (controls: WardicPlaybackControls, landed: boolean) => void
735
825
  }
736
826
 
737
- /** Playback controls over `tracks`, all run through `head`, started now. */
738
- const controlsOf = (tracks: ReadonlyArray<Spine.ImperativeTrack>, head: Playback.Playhead, watch: AnimationWatch, onComplete: (() => void) | undefined): {
827
+ /**
828
+ * A run's outcome as a promise: made at its first read, resolved once, and renewed for the next run. A run
829
+ * is what the scope's watch hears of an animation, from a start to its end.
830
+ */
831
+ interface RunPromise<A> {
832
+ /** This run's promise, made as it's first read: resolved already when the run has its outcome. */
833
+ readonly get: () => Promise<A>
834
+ /** The run's outcome, `value`, read yet or not. */
835
+ readonly resolve: (value: A) => void
836
+ /** A new run: the next read makes a new promise. */
837
+ readonly renew: () => void
838
+ }
839
+
840
+ /** A promise of each run's outcome, nothing made until it's read (#955: `finished` and `ended`). */
841
+ const runPromiseOf = <A>(): RunPromise<A> => {
842
+ let promise: Promise<A> | undefined
843
+ let settle: ((value: A) => void) | undefined
844
+ let outcome: Option.Option<A> = Option.none()
845
+ return {
846
+ get: () => {
847
+ if (Predicate.isNotUndefined(promise)) return promise
848
+ promise = Option.match(outcome, {
849
+ onSome: (value) => Promise.resolve(value),
850
+ onNone: () =>
851
+ new Promise<A>((settleWith) => {
852
+ settle = settleWith
853
+ }),
854
+ })
855
+ return promise
856
+ },
857
+ resolve: (value) => {
858
+ outcome = Option.some(value)
859
+ if (Predicate.isNotUndefined(settle)) settle(value)
860
+ },
861
+ renew: () => {
862
+ promise = undefined
863
+ settle = undefined
864
+ outcome = Option.none()
865
+ },
866
+ }
867
+ }
868
+
869
+ /** A run that landed, as `ended` gives it. */
870
+ const LANDED: WardicAnimationEnd = Object.freeze({ landed: true })
871
+
872
+ /** A run that ended without landing: stopped, cancelled or taken over. */
873
+ const NOT_LANDED: WardicAnimationEnd = Object.freeze({ landed: false })
874
+
875
+ /** How a run ended, as `ended` gives it. */
876
+ const endOf: (landed: boolean) => WardicAnimationEnd = /*#__PURE__*/ Bool.match({ onTrue: () => LANDED, onFalse: () => NOT_LANDED })
877
+
878
+ /** Playback controls over `tracks`, all run through `head`, started now: a throw from `onComplete` reported on `runtime`. */
879
+ const controlsOf = (
880
+ tracks: ReadonlyArray<Spine.ImperativeTrack>,
881
+ head: Playback.Playhead,
882
+ watch: AnimationWatch,
883
+ onComplete: (() => void) | undefined,
884
+ runtime: AnimateEnv["runtime"],
885
+ ): {
739
886
  readonly controls: WardicPlaybackControls
740
887
  readonly settledOne: (landed: boolean) => void
741
888
  } => {
@@ -744,9 +891,9 @@ const controlsOf = (tracks: ReadonlyArray<Spine.ImperativeTrack>, head: Playback
744
891
  let landed = 0
745
892
  // Whether a Subject's part ended without landing, a key of it taken by a later animation (#951).
746
893
  let anyTaken = false
747
- let resolve: (() => void) | undefined
748
- let finished: Promise<void> | undefined
749
- let isResolved = false
894
+ const finished = runPromiseOf<void>()
895
+ // Each run's end, however it ended (#955): a run is what `watch` hears, from its start to its end.
896
+ const ended = runPromiseOf<WardicAnimationEnd>()
750
897
  let duration: number | undefined
751
898
  const durationNow = (): number => {
752
899
  if (Predicate.isUndefined(duration)) duration = Arr.reduce(tracks, 0, (longest, track) => Math.max(longest, track.duration()))
@@ -757,20 +904,23 @@ const controlsOf = (tracks: ReadonlyArray<Spine.ImperativeTrack>, head: Playback
757
904
  anyTaken = false
758
905
  Arr.forEach(tracks, (track) => track.run())
759
906
  }
760
- const fresh = (): void => {
761
- finished = undefined
762
- resolve = undefined
763
- isResolved = false
764
- }
765
907
  const end = (how: WardicPlayState, landedNow: boolean): void => {
766
908
  const was = state
767
909
  state = how
768
- if (Bool.or(was === "running", was === "paused")) watch.ended(controls, landedNow)
910
+ if (Bool.or(was === "running", was === "paused")) {
911
+ ended.resolve(endOf(landedNow))
912
+ watch.ended(controls, landedNow)
913
+ }
914
+ }
915
+ // A new run, from an end: its own `ended`, and the watch told it started.
916
+ const newRun = (): void => {
917
+ ended.renew()
918
+ watch.started(controls)
769
919
  }
770
920
  const restart = (): void => {
771
921
  const was = state
772
922
  state = "running"
773
- if (Bool.or(was === "finished", was === "idle")) watch.started(controls)
923
+ if (Bool.or(was === "finished", was === "idle")) newRun()
774
924
  }
775
925
  const controls: WardicPlaybackControls = {
776
926
  get time() {
@@ -782,8 +932,8 @@ const controlsOf = (tracks: ReadonlyArray<Spine.ImperativeTrack>, head: Playback
782
932
  if (state !== "running") {
783
933
  Playback.pause(head)
784
934
  if (Bool.or(state === "finished", state === "idle")) {
785
- fresh()
786
- watch.started(controls)
935
+ finished.renew()
936
+ newRun()
787
937
  }
788
938
  state = "paused"
789
939
  }
@@ -802,16 +952,10 @@ const controlsOf = (tracks: ReadonlyArray<Spine.ImperativeTrack>, head: Playback
802
952
  return state
803
953
  },
804
954
  get finished() {
805
- if (Predicate.isUndefined(finished)) {
806
- finished = Bool.match(isResolved, {
807
- onTrue: () => Promise.resolve(),
808
- onFalse: () =>
809
- new Promise<void>((done) => {
810
- resolve = done
811
- }),
812
- })
813
- }
814
- return finished
955
+ return finished.get()
956
+ },
957
+ get ended() {
958
+ return ended.get()
815
959
  },
816
960
  then: (onResolve, onReject) => controls.finished.then(onResolve, onReject),
817
961
  play: () => {
@@ -823,7 +967,7 @@ const controlsOf = (tracks: ReadonlyArray<Spine.ImperativeTrack>, head: Playback
823
967
  }
824
968
  if (state === "running") return
825
969
  // Again from its start: its end when it plays backwards.
826
- fresh()
970
+ finished.renew()
827
971
  Playback.play(head)
828
972
  Playback.seek(head, Bool.match(head.speed < 0, { onTrue: durationNow, onFalse: () => 0 }))
829
973
  restart()
@@ -862,10 +1006,17 @@ const controlsOf = (tracks: ReadonlyArray<Spine.ImperativeTrack>, head: Playback
862
1006
  stopped = true
863
1007
  return end("idle", false)
864
1008
  }
865
- isResolved = true
866
- UndefinedOr.map(resolve, (done) => done())
867
- UndefinedOr.map(onComplete, (complete) => complete())
1009
+ finished.resolve(undefined)
1010
+ // Finished before its onComplete runs, as Motion's `finish()`: a throw there leaves it finished, and
1011
+ // is reported each time it lands (#977; ADR-0074, *Amendment (#979, group A)*).
868
1012
  end("finished", true)
1013
+ UndefinedOr.map(onComplete, (complete) => {
1014
+ try {
1015
+ complete()
1016
+ } catch (defect) {
1017
+ runtime.runFork(Report.failure("wardic.animate: an onComplete failed", Cause.die(defect)))
1018
+ }
1019
+ })
869
1020
  }
870
1021
  return { controls, settledOne }
871
1022
  }
@@ -879,6 +1030,7 @@ export const finishedControls = (): WardicPlaybackControls => {
879
1030
  duration: 0,
880
1031
  state: "finished",
881
1032
  finished: done,
1033
+ ended: Promise.resolve(LANDED),
882
1034
  then: (onResolve, onReject) => done.then(onResolve, onReject),
883
1035
  play: constVoid,
884
1036
  pause: constVoid,
@@ -913,13 +1065,14 @@ export type WardicSegmentTarget = Omit<Config.WardicTargetValues, "transition">
913
1065
  /**
914
1066
  * A function Segment, `[callback, value?, options?]`: its callback is given a value each frame, from 0
915
1067
  * to 1 unless it gives its own stops, for what isn't a Subject's own value. Motion's, in place of its
916
- * motion value Segments.
1068
+ * motion value Segments. A callback that throws is reported, once until it returns, and given the next
1069
+ * frame's value all the same: its Segment, and its sequence, land as their stops do.
917
1070
  */
918
1071
  export type WardicFunctionSegment =
919
1072
  | readonly [callback: (value: number) => void]
920
1073
  | readonly [callback: (value: number) => void, options: WardicSegmentOptions]
921
- | readonly [callback: (value: number) => void, value: number | Config.WardicKeyframes<number>, options: WardicSegmentOptions]
922
- | readonly [callback: (value: string) => void, value: string | Config.WardicKeyframes<string>, options: WardicSegmentOptions]
1074
+ | readonly [callback: (value: number) => void, value: number | Config.WardicKeyframes<number>, options?: WardicSegmentOptions]
1075
+ | readonly [callback: (value: string) => void, value: string | Config.WardicKeyframes<string>, options?: WardicSegmentOptions]
923
1076
 
924
1077
  /**
925
1078
  * A sequence's options: `duration`, the whole sequence scaled to it; `delay`; `repeat`, `repeatType`
@@ -941,6 +1094,7 @@ export interface WardicSequenceOptions {
941
1094
  * to `watch`, each track run. Finished at once with none.
942
1095
  */
943
1096
  const started = (
1097
+ runtime: AnimateEnv["runtime"],
944
1098
  watch: AnimationWatch,
945
1099
  count: number,
946
1100
  onComplete: (() => void) | undefined,
@@ -950,20 +1104,53 @@ const started = (
950
1104
  const head = Playback.make()
951
1105
  let settledOne: (landed: boolean) => void = constVoid
952
1106
  const tracks = tracksOf(head, (landedOne) => settledOne(landedOne))
953
- const made = controlsOf(tracks, head, watch, onComplete)
1107
+ const made = controlsOf(tracks, head, watch, onComplete, runtime)
954
1108
  settledOne = made.settledOne
955
1109
  watch.started(made.controls)
956
- Arr.forEach(tracks, (track) => track.run())
1110
+ // A run that refuses the call (a Batch part's `delay` that throws, at its first play) stops it, so its
1111
+ // scope hears it end, and the throw goes on to the call (#979, row 20).
1112
+ try {
1113
+ Arr.forEach(tracks, (track) => track.run())
1114
+ } catch (defect) {
1115
+ made.controls.stop()
1116
+ throw defect
1117
+ }
957
1118
  return made.controls
958
1119
  }
959
1120
 
1121
+ /**
1122
+ * A track built as it first runs: a mixed call's plain Subject, whose keys are taken only once the Batch
1123
+ * parts before it have run, a Batch part's `delay` among what they call. Stopped or cancelled before it
1124
+ * runs, it has taken nothing.
1125
+ */
1126
+ const builtAtRun = (build: () => Spine.ImperativeTrack): Spine.ImperativeTrack => {
1127
+ let built: Spine.ImperativeTrack | undefined
1128
+ const track = (): Spine.ImperativeTrack => {
1129
+ if (Predicate.isUndefined(built)) built = build()
1130
+ return built
1131
+ }
1132
+ return {
1133
+ run: () => track().run(),
1134
+ stop: () => UndefinedOr.map(built, (made) => made.stop()),
1135
+ cancel: () => UndefinedOr.map(built, (made) => made.cancel()),
1136
+ duration: () => track().duration(),
1137
+ }
1138
+ }
1139
+
960
1140
  /**
961
1141
  * An **Animation scope**'s `animate` (#433), over an Environment's {@link Ports}: `animate(subject,
962
1142
  * target, options?)`, a Batch's `animate(batch, target, options?)` and `animate(sequence, options?)`,
963
1143
  * each returning its Playback controls. `scope()` is handed to the Environment's {@link Subjects.resolve}
964
- * (the DOM's selectors are looked up inside it); each animation is told to `watch` as it starts and
1144
+ * (`@wardic/dom` looks its strings up inside it); each animation is told to `watch` as it starts and
965
1145
  * ends. Every Subject's legs start in the call, on the loop by the end of its task. An Environment
966
1146
  * types its own overloads over it.
1147
+ *
1148
+ * A key a target or its Transition end names that a Subject can't take (its Environment's own value
1149
+ * read throws: a key it lacks, say) is an error at the call, naming it, and so is a `delay` function that
1150
+ * throws. The call then takes nothing from any of its Subjects: an animation it would have taken a key
1151
+ * from runs on.
1152
+ * A Transition end's key a Subject can no longer set when it lands is reported, left as it is, and the
1153
+ * rest of its end set: the call lands.
967
1154
  */
968
1155
  export const make = <S extends object>(env: AnimateEnv, ports: Ports<S>, scope: () => unknown, watch: AnimationWatch) =>
969
1156
  (first: unknown, second?: unknown, third?: WardicAnimateOptions): WardicPlaybackControls => {
@@ -972,7 +1159,7 @@ export const make = <S extends object>(env: AnimateEnv, ports: Ports<S>, scope:
972
1159
  const batch = ports.batches.entryOf(first)
973
1160
  if (Predicate.isNotUndefined(batch)) {
974
1161
  const members = batch.binding.namedOf(batch)
975
- return started(watch, 1, UndefinedOr.map(third, (given) => given.onComplete), (head, settled) => [
1162
+ return started(env.runtime, watch, 1, UndefinedOr.map(third, (given) => given.onComplete), (head, settled) => [
976
1163
  batchTrackOf(env, batch.binding, second as Readonly<Record<string, unknown>>, members, third, head, settled),
977
1164
  ])
978
1165
  }
@@ -982,15 +1169,28 @@ export const make = <S extends object>(env: AnimateEnv, ports: Ports<S>, scope:
982
1169
  // No member's Subject among them: each Subject's track, building no parts (bench:solid --batch's
983
1170
  // per-element page, a call per element: 8.2 -> 8.5 ms at 1,000 with the parts built for every call; #665).
984
1171
  if (Bool.not(ports.batches.hasMembers(subjects))) {
985
- return started(watch, subjects.length, onComplete, (head, settled) =>
986
- Arr.map(subjects, (subject, index) => trackOf(env, ports.subjects, subject, target, transitionFor(third, index, subjects.length), head, settled)))
1172
+ return started(env.runtime, watch, subjects.length, onComplete, (head, settled) => {
1173
+ // One Subject: readied, then its track, which takes its keys once they're all read.
1174
+ if (subjects.length === 1) return [trackOf(env, readiedOf(env, ports.subjects, subjects[0], target), transitionFor(third, 0, 1), head, settled)]
1175
+ // Every Subject readied, and its transition worked out (a `delay(i, n)` called), before any track takes a key (#973; #979, row 20).
1176
+ const readied = Arr.map(subjects, (subject) => readiedOf(env, ports.subjects, subject, target))
1177
+ const transitions = Arr.map(subjects, (_, index) => transitionFor(third, index, subjects.length))
1178
+ return Arr.zipWith(readied, transitions, (each, transition) => trackOf(env, each, transition, head, settled))
1179
+ })
987
1180
  }
988
1181
  // A Batch's members' Subjects as one call over them, with its keys; the rest of each Subject's on its own (#665, Q14, Q35).
989
1182
  const parts = ports.batches.callPartsOf(subjects, target)
990
- return started(watch, parts.members.length + parts.subjects.length, onComplete, (head, settled) => [
991
- ...Arr.map(parts.members, (part) => batchTrackOf(env, part.binding, part.target, part.members, third, head, settled)),
992
- ...Arr.map(parts.subjects, (part) => trackOf(env, ports.subjects, part.subject, part.target as Config.WardicVariant, transitionFor(third, part.index, subjects.length), head, settled)),
993
- ])
1183
+ return started(env.runtime, watch, parts.members.length + parts.subjects.length, onComplete, (head, settled) => {
1184
+ // A Batch's track takes nothing until it runs; every other Subject readied, and its transition worked
1185
+ // out, before any track is built (#973). The Batch parts run first, and each other Subject's track is
1186
+ // built as it runs, so a Batch part's `delay` that throws takes nothing either (#979, row 20).
1187
+ const readied = Arr.map(parts.subjects, (part) => readiedOf(env, ports.subjects, part.subject, part.target as Config.WardicVariant))
1188
+ const transitions = Arr.map(parts.subjects, (part) => transitionFor(third, part.index, subjects.length))
1189
+ return [
1190
+ ...Arr.map(parts.members, (part) => batchTrackOf(env, part.binding, part.target, part.members, third, head, settled)),
1191
+ ...Arr.zipWith(readied, transitions, (each, transition) => builtAtRun(() => trackOf(env, each, transition, head, settled))),
1192
+ ]
1193
+ })
994
1194
  }
995
1195
 
996
1196
  // --- Sequences (#433's PR 2) ------------------------------------------------------------------
@@ -1016,6 +1216,9 @@ const ZERO_TO_ONE: ReadonlyArray<number> = [0, 1]
1016
1216
  /** No fields. */
1017
1217
  const NO_FIELDS: Readonly<Record<string, unknown>> = {}
1018
1218
 
1219
+ /** What a function Segment's callback, or its run, failing is reported as. */
1220
+ const SEGMENT_FAILED = "wardic.animate: a function Segment failed"
1221
+
1019
1222
  /**
1020
1223
  * What a Segment's transition doesn't take from the sequence's `defaultTransition` (Motion's): its
1021
1224
  * delay, times and repeat, which are each Segment's own, and a value's own transitions.
@@ -1062,8 +1265,11 @@ const segmentTransitionOf = (options: WardicSegmentOptions | undefined, key: str
1062
1265
  return Bool.match(Predicate.isUndefined(delay), { onTrue: () => run, onFalse: () => ({ ...run, delay }) as Sequence.Transition })
1063
1266
  }
1064
1267
 
1268
+ /** Whether a function Segment's second part is its value: a number, a string or a list of stops. Anything else is its options. */
1269
+ const isFunctionSegmentValue: Predicate.Predicate<unknown> = /*#__PURE__*/ Predicate.or(/*#__PURE__*/ Predicate.or(Predicate.isNumber, Predicate.isString), Arr.isArray)
1270
+
1065
1271
  /** Whether a Segment's value is one: a number, a string, `null` or Keyframes. */
1066
- const isSegmentValue: Predicate.Predicate<unknown> = /*#__PURE__*/ Predicate.or(/*#__PURE__*/ Predicate.or(Predicate.isNumber, Predicate.isString), /*#__PURE__*/ Predicate.or(Predicate.isNull, Arr.isArray))
1272
+ const isSegmentValue: Predicate.Predicate<unknown> = /*#__PURE__*/ Predicate.or(isFunctionSegmentValue, Predicate.isNull)
1067
1273
 
1068
1274
  /** A Segment's values: those that are a value, `null` or Keyframes. */
1069
1275
  const segmentValuesOf = (target: WardicSegmentTarget): Readonly<Record<string, Sequence.Stop | ReadonlyArray<Sequence.Stop>>> =>
@@ -1087,7 +1293,7 @@ const subjectsIn = <S extends object>(batches: Batches<S>, subjects: ReadonlyArr
1087
1293
 
1088
1294
  /**
1089
1295
  * A sequence's steps for core (#433): labels as they are; a Segment of Subjects' Subjects (a string
1090
- * the Environment resolves, a DOM selector, looked up once a sequence, inside `scope`), values and each
1296
+ * the Environment resolves, looked up once a sequence, inside `scope`), values and each
1091
1297
  * value's transition; a function Segment's own value, from 0 to 1 unless it gives its stops.
1092
1298
  */
1093
1299
  const stepsOf = <S extends object>(ports: Ports<S>, sequence: ReadonlyArray<unknown>, scope: unknown, defaults: Config.WardicTransition | undefined): ReadonlyArray<Sequence.Step<S | Callback | BatchMember>> => {
@@ -1114,9 +1320,12 @@ const stepsOf = <S extends object>(ports: Ports<S>, sequence: ReadonlyArray<unkn
1114
1320
  }
1115
1321
  if (Predicate.isFunction(parts[0])) {
1116
1322
  const call = parts[0] as (value: number | string) => void
1117
- const three = parts.length === 3
1118
- const given = Bool.match(three, { onTrue: () => parts[1] as Sequence.Stop | ReadonlyArray<Sequence.Stop>, onFalse: () => ZERO_TO_ONE })
1119
- const options = Bool.match(three, { onTrue: () => parts[2], onFalse: () => parts[1] }) as WardicSegmentOptions | undefined
1323
+ // #975 (ADR-0061, *Amendment (#975)*): two parts are a value and no options when the second is one,
1324
+ // as Motion's `[value, keyframes]`; read as options, a number was dropped, and an array's `at` threw.
1325
+ const [given, options] = Bool.match(Bool.or(parts.length === 3, isFunctionSegmentValue(parts[1])), {
1326
+ onTrue: () => [parts[1] as Sequence.Stop | ReadonlyArray<Sequence.Stop>, parts[2] as WardicSegmentOptions | undefined] as const,
1327
+ onFalse: () => [ZERO_TO_ONE, parts[1] as WardicSegmentOptions | undefined] as const,
1328
+ })
1120
1329
  const target = { [VALUE]: given }
1121
1330
  return { subjects: [{ call }], target, transitions: segmentTransitionsOf(target, options, defaults), at: atOf(options) }
1122
1331
  }
@@ -1143,7 +1352,9 @@ export const segmentAnimates = <S extends object>(ports: Ports<S>, segment: unkn
1143
1352
  /**
1144
1353
  * A function Segment's value animated (#433): its stops, a first `null` 0, through the
1145
1354
  * Interpolators on its tween over the sequence, each frame told to its callback. Cancelled, the
1146
- * callback hears its first stop again, as Motion's motion value is set back.
1355
+ * callback hears its first stop again, as Motion's motion value is set back. A callback that throws is
1356
+ * reported, once a run of throws, and told the next frame's value all the same; one that throws on a
1357
+ * cancel, each time, the call's cancel going on.
1147
1358
  */
1148
1359
  const callbackTrackOf = (env: AnimateEnv, callback: Callback, animation: Sequence.Animation, head: Playback.Playhead, settled: (landed: boolean) => void): Spine.ImperativeTrack => {
1149
1360
  const stops = RetargetLegs.filledStops(UndefinedOr.getOrThrow(animation.keyframes[VALUE]), 0)
@@ -1154,6 +1365,8 @@ const callbackTrackOf = (env: AnimateEnv, callback: Callback, animation: Sequenc
1154
1365
  onFalse: () => Machine.keyframesValues({ [VALUE]: stops }, options),
1155
1366
  })
1156
1367
  let fiber: Fiber.Fiber<unknown> | undefined
1368
+ // Its callback threw, reported, and hasn't returned since (#979, row 18).
1369
+ let failing = false
1157
1370
  const end = (): void => {
1158
1371
  if (Predicate.isUndefined(fiber)) return
1159
1372
  const running = fiber
@@ -1164,15 +1377,27 @@ const callbackTrackOf = (env: AnimateEnv, callback: Callback, animation: Sequenc
1164
1377
  const landed = (exit: Exit.Exit<unknown>): Effect.Effect<void> =>
1165
1378
  Exit.match(exit, {
1166
1379
  onSuccess: () => Effect.sync(() => settled(true)),
1167
- onFailure: (cause) => Bool.match(Cause.hasInterruptsOnly(cause), { onTrue: () => Effect.void, onFalse: () => Report.failure("wardic.animate: a function Segment failed", cause) }),
1380
+ onFailure: (cause) => Bool.match(Cause.hasInterruptsOnly(cause), { onTrue: () => Effect.void, onFalse: () => Report.failure(SEGMENT_FAILED, cause) }),
1168
1381
  })
1169
1382
  const run = (): void => {
1170
1383
  end()
1384
+ // A run of its own: a throw in it is reported, whatever the last run's last call did.
1385
+ failing = false
1171
1386
  fiber = env.runtime.runFork(
1172
1387
  machine.pipe(
1173
1388
  Effect.map(Playback.drive(head)),
1174
1389
  Effect.flatMap(Machine.run((frame) => {
1175
- callback.call(UndefinedOr.getOrThrow(frame.value[VALUE]))
1390
+ const value = UndefinedOr.getOrThrow(frame.value[VALUE])
1391
+ // Its callback's throw is its own: told again next frame, its Segment landing as its stops do (ADR-0074).
1392
+ try {
1393
+ callback.call(value)
1394
+ if (failing) failing = false
1395
+ } catch (defect) {
1396
+ if (!failing) {
1397
+ failing = true
1398
+ env.runtime.runFork(Report.failure(SEGMENT_FAILED, Cause.die(defect)))
1399
+ }
1400
+ }
1176
1401
  return undefined
1177
1402
  })),
1178
1403
  Effect.onExit(landed),
@@ -1184,7 +1409,13 @@ const callbackTrackOf = (env: AnimateEnv, callback: Callback, animation: Sequenc
1184
1409
  stop: end,
1185
1410
  cancel: () => {
1186
1411
  end()
1187
- callback.call(UndefinedOr.getOrThrow(stops[0]))
1412
+ const first = UndefinedOr.getOrThrow(stops[0])
1413
+ // Told its first stop once its run has ended: a throw there is reported, and the call's cancel goes on (#979, row 19).
1414
+ try {
1415
+ callback.call(first)
1416
+ } catch (defect) {
1417
+ env.runtime.runFork(Report.failure("wardic.animate: a function Segment's cancel failed", Cause.die(defect)))
1418
+ }
1188
1419
  },
1189
1420
  duration: () => Machine.durationOf(env.runtime.runSync(machine)),
1190
1421
  }
@@ -1205,14 +1436,24 @@ const sequenceOf = <S extends object>(env: AnimateEnv, ports: Ports<S>, scope: u
1205
1436
  const compiled = Arr.fromIterable(Sequence.compile(stepsOf(ports, sequence, scope, defaults), whole))
1206
1437
  // Each Batch's members as one track, their other keys their Subjects' (#665, Q40).
1207
1438
  const parts = ports.batches.sequencePartsOf<S | Callback>(compiled)
1208
- return started(watch, compiled.length, UndefinedOr.map(options, (given) => given.onComplete), (head, settled) => [
1209
- ...Arr.map(parts.others, ([subject, animation]) => {
1210
- if (isCallback(subject)) return callbackTrackOf(env, subject, animation, head, settled)
1211
- return trackOf(env, ports.subjects, subject as S, animation.keyframes as Config.WardicVariant, animation.transition as Config.WardicTransition, head, settled)
1212
- }),
1213
- ...Arr.map(parts.batches, (part) =>
1214
- part.binding.sequenceTrack({ members: part.members, animations: part.animations, reducedMotion: env.reducedMotion(), skipAnimations: env.skipAnimations(), head, settled: () => settled(true), taken: () => settled(false) })),
1215
- ])
1439
+ return started(env.runtime, watch, compiled.length, UndefinedOr.map(options, (given) => given.onComplete), (head, settled) => {
1440
+ // Every Segment's Subject readied before any track takes a key, a later one's refusal taking nothing (#973).
1441
+ const readied = Arr.map(parts.others, ([subject, animation]) => segmentReadiedOf(env, ports.subjects, subject, animation))
1442
+ return [
1443
+ ...Arr.map(parts.others, ([subject, animation], i) => {
1444
+ if (isCallback(subject)) return callbackTrackOf(env, subject, animation, head, settled)
1445
+ return trackOf(env, UndefinedOr.getOrThrow(readied[i]), animation.transition as Config.WardicTransition, head, settled)
1446
+ }),
1447
+ ...Arr.map(parts.batches, (part) =>
1448
+ part.binding.sequenceTrack({ members: part.members, animations: part.animations, reducedMotion: env.reducedMotion(), skipAnimations: env.skipAnimations(), head, settled: () => settled(true), taken: () => settled(false) })),
1449
+ ]
1450
+ })
1451
+ }
1452
+
1453
+ /** A sequence's Subject readied (`readiedOf`) for its compiled animation: none for a function Segment's callback, which has no keys. */
1454
+ const segmentReadiedOf = <S extends object>(env: AnimateEnv, subjects: Subjects<S>, subject: S | Callback, animation: Sequence.Animation): Readied<S> | undefined => {
1455
+ if (isCallback(subject)) return undefined
1456
+ return readiedOf(env, subjects, subject as S, animation.keyframes as Config.WardicVariant)
1216
1457
  }
1217
1458
 
1218
1459
  /** `watch`, with `also` told each start and end after it, when given: a scope's own watch beside its owner's (#433), a binding's beside a scope's (#798). */