@wardic/core 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/BaseValue.d.ts +1 -1
  2. package/dist/BaseValue.js +2 -2
  3. package/dist/BaseValue.js.map +1 -1
  4. package/dist/Batch.d.ts +5 -9
  5. package/dist/Batch.d.ts.map +1 -1
  6. package/dist/Batch.js +166 -20
  7. package/dist/Batch.js.map +1 -1
  8. package/dist/Clock.d.ts +16 -0
  9. package/dist/Clock.d.ts.map +1 -1
  10. package/dist/Clock.js +13 -0
  11. package/dist/Clock.js.map +1 -1
  12. package/dist/DragRecognizer.d.ts +10 -5
  13. package/dist/DragRecognizer.d.ts.map +1 -1
  14. package/dist/DragRecognizer.js +60 -24
  15. package/dist/DragRecognizer.js.map +1 -1
  16. package/dist/Frame.js +1 -1
  17. package/dist/Frame.js.map +1 -1
  18. package/dist/InputFeed.d.ts +10 -7
  19. package/dist/InputFeed.d.ts.map +1 -1
  20. package/dist/InputFeed.js +16 -35
  21. package/dist/InputFeed.js.map +1 -1
  22. package/dist/LiveValue.d.ts +9 -3
  23. package/dist/LiveValue.d.ts.map +1 -1
  24. package/dist/LiveValue.js +160 -14
  25. package/dist/LiveValue.js.map +1 -1
  26. package/dist/Machine.d.ts +16 -6
  27. package/dist/Machine.d.ts.map +1 -1
  28. package/dist/Machine.js +50 -27
  29. package/dist/Machine.js.map +1 -1
  30. package/dist/Playback.d.ts.map +1 -1
  31. package/dist/Playback.js +10 -8
  32. package/dist/Playback.js.map +1 -1
  33. package/dist/Recognizer.d.ts +1 -1
  34. package/dist/Recognizer.d.ts.map +1 -1
  35. package/dist/Recognizer.js +9 -4
  36. package/dist/Recognizer.js.map +1 -1
  37. package/dist/internal/frameLoop.d.ts +10 -2
  38. package/dist/internal/frameLoop.d.ts.map +1 -1
  39. package/dist/internal/frameLoop.js +148 -18
  40. package/dist/internal/frameLoop.js.map +1 -1
  41. package/dist/internal/guarded.d.ts +16 -0
  42. package/dist/internal/guarded.d.ts.map +1 -0
  43. package/dist/internal/guarded.js +68 -0
  44. package/dist/internal/guarded.js.map +1 -0
  45. package/dist/internal/stepper.d.ts +9 -3
  46. package/dist/internal/stepper.d.ts.map +1 -1
  47. package/dist/internal/stepper.js +5 -4
  48. package/dist/internal/stepper.js.map +1 -1
  49. package/dist/unstable/AnimationControls.d.ts +15 -8
  50. package/dist/unstable/AnimationControls.d.ts.map +1 -1
  51. package/dist/unstable/AnimationControls.js +36 -15
  52. package/dist/unstable/AnimationControls.js.map +1 -1
  53. package/dist/unstable/AppearHandoff.d.ts +6 -0
  54. package/dist/unstable/AppearHandoff.d.ts.map +1 -1
  55. package/dist/unstable/AppearHandoff.js.map +1 -1
  56. package/dist/unstable/Config.d.ts +5 -1
  57. package/dist/unstable/Config.d.ts.map +1 -1
  58. package/dist/unstable/Config.js.map +1 -1
  59. package/dist/unstable/FlushGate.d.ts +4 -2
  60. package/dist/unstable/FlushGate.d.ts.map +1 -1
  61. package/dist/unstable/FlushGate.js +155 -38
  62. package/dist/unstable/FlushGate.js.map +1 -1
  63. package/dist/unstable/FrameEffects.d.ts +4 -1
  64. package/dist/unstable/FrameEffects.d.ts.map +1 -1
  65. package/dist/unstable/FrameEffects.js +12 -1
  66. package/dist/unstable/FrameEffects.js.map +1 -1
  67. package/dist/unstable/Imperative.d.ts +13 -4
  68. package/dist/unstable/Imperative.d.ts.map +1 -1
  69. package/dist/unstable/Imperative.js +202 -43
  70. package/dist/unstable/Imperative.js.map +1 -1
  71. package/dist/unstable/MeasuredPairs.d.ts +6 -2
  72. package/dist/unstable/MeasuredPairs.d.ts.map +1 -1
  73. package/dist/unstable/MeasuredPairs.js.map +1 -1
  74. package/dist/unstable/PresenceRecord.d.ts +4 -0
  75. package/dist/unstable/PresenceRecord.d.ts.map +1 -1
  76. package/dist/unstable/PresenceRecord.js.map +1 -1
  77. package/dist/unstable/Report.d.ts +7 -0
  78. package/dist/unstable/Report.d.ts.map +1 -1
  79. package/dist/unstable/Report.js +17 -1
  80. package/dist/unstable/Report.js.map +1 -1
  81. package/dist/unstable/RetargetLegs.d.ts +6 -0
  82. package/dist/unstable/RetargetLegs.d.ts.map +1 -1
  83. package/dist/unstable/RetargetLegs.js +15 -0
  84. package/dist/unstable/RetargetLegs.js.map +1 -1
  85. package/dist/unstable/Spine.d.ts +53 -7
  86. package/dist/unstable/Spine.d.ts.map +1 -1
  87. package/dist/unstable/Spine.js +190 -40
  88. package/dist/unstable/Spine.js.map +1 -1
  89. package/dist/unstable/VariantTarget.d.ts +25 -3
  90. package/dist/unstable/VariantTarget.d.ts.map +1 -1
  91. package/dist/unstable/VariantTarget.js +66 -13
  92. package/dist/unstable/VariantTarget.js.map +1 -1
  93. package/dist/unstable/VariantTree.d.ts +37 -3
  94. package/dist/unstable/VariantTree.d.ts.map +1 -1
  95. package/dist/unstable/VariantTree.js +54 -7
  96. package/dist/unstable/VariantTree.js.map +1 -1
  97. package/package.json +1 -1
  98. package/src/BaseValue.ts +2 -2
  99. package/src/Batch.ts +167 -17
  100. package/src/Clock.ts +20 -0
  101. package/src/DragRecognizer.ts +82 -30
  102. package/src/Frame.ts +1 -1
  103. package/src/InputFeed.ts +37 -40
  104. package/src/LiveValue.ts +140 -14
  105. package/src/Machine.ts +67 -34
  106. package/src/Playback.ts +10 -8
  107. package/src/Recognizer.ts +9 -3
  108. package/src/internal/frameLoop.ts +165 -19
  109. package/src/internal/guarded.ts +69 -0
  110. package/src/internal/stepper.ts +14 -5
  111. package/src/unstable/AnimationControls.ts +49 -21
  112. package/src/unstable/AppearHandoff.ts +7 -0
  113. package/src/unstable/Config.ts +7 -1
  114. package/src/unstable/FlushGate.ts +169 -37
  115. package/src/unstable/FrameEffects.ts +15 -2
  116. package/src/unstable/Imperative.ts +219 -48
  117. package/src/unstable/MeasuredPairs.ts +7 -1
  118. package/src/unstable/PresenceRecord.ts +4 -0
  119. package/src/unstable/Report.ts +19 -1
  120. package/src/unstable/RetargetLegs.ts +14 -0
  121. package/src/unstable/Spine.ts +235 -40
  122. package/src/unstable/VariantTarget.ts +93 -14
  123. package/src/unstable/VariantTree.ts +87 -6
@@ -127,16 +127,19 @@ export const exitTargetOf = (config: ExitConfig, presenceCustom: unknown, state:
127
127
  // A list (#297): merged, and each name's own keys on its own transition.
128
128
  const targets = VariantTarget.resolveTargets(entry, config.variants, custom, state)
129
129
  const merged = VariantTarget.mergedOf(targets)
130
+ // One of its names' resolvers threw (#979, Q3): it leaves without the whole exit, as with one name.
131
+ if (Option.isSome(merged.failure)) return { values: {}, transition: config.transition, name, keyframes: undefined, failure: merged.failure }
130
132
  return {
131
133
  values: merged.values,
132
134
  transition: VariantTarget.transitionOfTarget(merged.transition, config.transition),
133
135
  name,
134
136
  groups: exitGroupsOf(targets, config.transition),
135
137
  keyframes: merged.keyframes,
138
+ failure: merged.failure,
136
139
  }
137
140
  }
138
141
  const target = VariantTarget.resolveTarget(entry, config.variants, custom, state)
139
- return { values: target.values, transition: VariantTarget.transitionOfTarget(target.transition, config.transition), name, keyframes: target.keyframes }
142
+ return { values: target.values, transition: VariantTarget.transitionOfTarget(target.transition, config.transition), name, keyframes: target.keyframes, failure: target.failure }
140
143
  }
141
144
 
142
145
  /** A list's exit groups (#297): each name, with the keys it's the last to set, on its own transition else `element`. */
@@ -203,13 +206,6 @@ const keyTransitionOf = (
203
206
  return groupTransitionOf(resolution, groups, Option.getOrElse(Arr.findFirstIndex(groups, (group) => group.has(key)), () => -1), transition, element, undefined, identity)
204
207
  }
205
208
 
206
- /** Whether `given` gives `key` a velocity (#448, Motion's `valueTransition.velocity`): it kicks the key, so it animates though at its target. */
207
- const givesVelocity = (given: Config.WardicTransition | undefined, key: string): boolean => {
208
- const own = RetargetLegs.transitionForKey(given, key) as { readonly velocity?: unknown } | undefined
209
- if (Predicate.isUndefined(own)) return false
210
- return Bool.and(Predicate.isNumber(own.velocity), own.velocity !== 0)
211
- }
212
-
213
209
  /** A key's velocity in the Snapshot, 0 with none (#448). Per key, per Retarget: a guard. */
214
210
  const velocityOf = (snapshot: { readonly velocities: Readonly<Record<string, number>> }, key: string): number => {
215
211
  const velocity = snapshot.velocities[key]
@@ -349,10 +345,12 @@ export interface OverrideEntry {
349
345
  readonly ends: Values.Values
350
346
  /** Its target's **Keyframes** (#429): each such key's stops, its value in `values` their last. */
351
347
  readonly keyframes: VariantTarget.Keyframes | undefined
348
+ /** Its target's resolver that threw, and its variant's name (#979): it has none of that target's values. */
349
+ readonly failure: Option.Option<VariantTarget.VariantFailure>
352
350
  }
353
351
 
354
352
  /** A gesture layer that's off: nothing is resolved for it. */
355
- const OFF: OverrideEntry = { active: false, values: {}, transition: undefined, name: undefined, ends: {}, keyframes: undefined }
353
+ const OFF: OverrideEntry = { active: false, values: {}, transition: undefined, name: undefined, ends: {}, keyframes: undefined, failure: VariantTarget.NO_FAILURE }
356
354
 
357
355
  /**
358
356
  * A gesture layer (#291), while it's on (its own, or its provider's): its own `while*` (a target, or
@@ -501,6 +499,9 @@ const gatedLandingOf = (onFrame: ((done: boolean) => void) | undefined): Landing
501
499
  * other key is given up, and a leg left with none is ended.
502
500
  */
503
501
  export interface Running extends Machine.RunOptions {
502
+ readonly supersede: Supersede.Supersede
503
+ /** It picks an Appear animation up where it has got, on the frame timeline (#1026): a Handoff's first legs. */
504
+ readonly onFrameTimeline: boolean
504
505
  /** Each key it animates, with the target its Retarget gave it. */
505
506
  readonly targets: Values.Values
506
507
  /** The resolution of the Retarget that started it: a `when` gate holds that change's legs. */
@@ -524,7 +525,10 @@ export interface Running extends Machine.RunOptions {
524
525
  frames: number
525
526
  /** When it drew its last frame, on {@link FrameTime.frameNow}'s clock; -Infinity before its first (#464). */
526
527
  lastAt: number
527
- /** A Blend leg's last frame's values, and the ones before them (the Snapshot's, before its first) (#464). */
528
+ /**
529
+ * A Blend leg's last frame's values, and the ones before them (the Snapshot's, before its first) (#464):
530
+ * two records of its own, swapped each frame (`keepFrame`).
531
+ */
528
532
  last: Values.Values | undefined
529
533
  before: Values.Values | undefined
530
534
  /** The time, in ms, its last frame's step covered: its run's dt then, which a Blend's change is over (#865). */
@@ -705,9 +709,13 @@ const TURNED_BACK: Values.Values = { [PATH_ROTATION]: 0 }
705
709
  */
706
710
  export type Owners = Map<string, Running | undefined>
707
711
 
708
- /** A leg over the keys of `to` (#325), counting toward `landing`: the spine gives it the keys. */
709
- export const runningOf = (to: Values.Values, resolution: Resolution, landing: Landing, kind: RetargetLegs.Leg["_tag"]): Running => ({
712
+ /**
713
+ * A leg over the keys of `to` (#325), counting toward `landing`: the spine gives it the keys. A Handoff's
714
+ * leg is `onFrameTimeline` (#1026).
715
+ */
716
+ export const runningOf = (to: Values.Values, resolution: Resolution, landing: Landing, kind: RetargetLegs.Leg["_tag"], onFrameTimeline = false): Running => ({
710
717
  supersede: Supersede.make(),
718
+ onFrameTimeline,
711
719
  targets: to,
712
720
  resolution,
713
721
  count: 0,
@@ -751,6 +759,28 @@ const blendVelocityOf = (running: Running, key: string): number => {
751
759
  return (((last as number) - (before as number)) * 1000) / apart
752
760
  }
753
761
 
762
+ /**
763
+ * A Blend leg's last two frames' values, kept for its velocity (#464): two records of its own, swapped each
764
+ * frame, the frame's values copied into the newer, since its Frame is its run's, rewritten each tick. Before
765
+ * its first frame, the Snapshot's values are its older. A leg that lands on its first frame keeps none: its
766
+ * velocity is 0.
767
+ */
768
+ // #895: per frame, plain calls; its two records made at its first frame, nothing after.
769
+ const keepFrame = (running: Running, frame: Frame.Frame<Values.Values>, snapshotValues: Values.Values): void => {
770
+ const older = running.last
771
+ if (Predicate.isUndefined(older)) {
772
+ if (frame.done) return
773
+ running.before = { ...snapshotValues }
774
+ running.last = { ...frame.value }
775
+ return
776
+ }
777
+ // Set with `last` at its first frame: present by construction.
778
+ const newer = UndefinedOr.getOrThrow(running.before)
779
+ Object.assign(newer, frame.value)
780
+ running.before = older
781
+ running.last = newer
782
+ }
783
+
754
784
  /** A leg's frame drawn (#325) at `now`: its last lands the keys it draws. Per frame: plain calls. */
755
785
  const drew = (running: Running, done: boolean, now: number): void => {
756
786
  if (done) running.done = true
@@ -1010,6 +1040,7 @@ const layerOf = (target: VariantTarget.Target, name: string | undefined): Overri
1010
1040
  name,
1011
1041
  ends: endsOfTarget(target),
1012
1042
  keyframes: target.keyframes,
1043
+ failure: target.failure,
1013
1044
  })
1014
1045
 
1015
1046
  /** A list's target as an active entry (#297). */
@@ -1182,9 +1213,10 @@ const measuringOf = (found: ReadonlyArray<string> | undefined, keyframes: Keyfra
1182
1213
  /**
1183
1214
  * A Retarget's Measured pairs (#430): each of `keys` whose start and target are one, asked of the
1184
1215
  * end-of-task batch with the values the element draws now, but a key with Keyframes of more than two
1185
- * stops (`many`, #460). `undefined` with none.
1216
+ * stops (`many`, #460). `undefined` with none. When the batch can't take them, they switch, as pairs
1217
+ * it couldn't read do, reported on `runtime` with the element's `id`.
1186
1218
  */
1187
- export const measuredOf = (measured: MeasuredPairs.Shape, element: Subject.Subject, keys: ReadonlyArray<string>, from: Values.Values, to: Values.Values, values: Values.Values, many: RetargetLegs.StopsByKey | undefined): RetargetLegs.MeasuredPairs | undefined => {
1219
+ export const measuredOf = (measured: MeasuredPairs.Shape, element: Subject.Subject, keys: ReadonlyArray<string>, from: Values.Values, to: Values.Values, values: Values.Values, many: RetargetLegs.StopsByKey | undefined, runtime: Pick<WardicServices.Runner<never>, "runFork">, id: string): RetargetLegs.MeasuredPairs | undefined => {
1188
1220
  const pairs: Record<string, { readonly from: number | string; readonly to: number | string }> = {}
1189
1221
  Arr.forEach(keys, (key) => {
1190
1222
  if (RetargetLegs.hasManyStops(many, key)) return
@@ -1194,9 +1226,21 @@ export const measuredOf = (measured: MeasuredPairs.Shape, element: Subject.Subje
1194
1226
  if (measured.needs(key, start as number | string, target as number | string)) pairs[key] = { from: start as number | string, to: target as number | string }
1195
1227
  })
1196
1228
  if (Rec.isEmptyRecord(pairs)) return undefined
1197
- return measured.measure(element, pairs, values)
1229
+ // Its report made only for pairs asked, not once an element (#979, row 8): nearly every Retarget asks none.
1230
+ return measured.measure(element, pairs, values, pairsFailedOn("wardic.spine: a Retarget's Measured pairs failed", runtime, { id }))
1198
1231
  }
1199
1232
 
1233
+ /** How Measured pairs the batch couldn't take are reported under `message`, on `runtime`, each time (#979, row 8). */
1234
+ const pairsFailedOn =
1235
+ (message: string, runtime: Pick<WardicServices.Runner<never>, "runFork">, annotations: Readonly<Record<string, unknown>>) =>
1236
+ (defect: unknown): void => {
1237
+ runtime.runFork(Effect.annotateLogs(Report.failure(message, Cause.die(defect)), annotations))
1238
+ }
1239
+
1240
+ /** How an exit's Measured pairs the batch couldn't take (its Transform template threw) are reported, on `runtime`. */
1241
+ export const exitMeasuredFailedOn = (runtime: Pick<WardicServices.Runner<never>, "runFork">): ((defect: unknown) => void) =>
1242
+ pairsFailedOn("wardic.presence: an exit's Measured pairs failed", runtime, {})
1243
+
1200
1244
  /** A key's Keyframes in `keyframes` (#429): per key, per Retarget, so a guard, nothing made. */
1201
1245
  const keyframesAtOf = (keyframes: KeyframesNow | undefined, key: string): KeyframesAt | undefined => {
1202
1246
  if (Predicate.isUndefined(keyframes)) return undefined
@@ -1374,16 +1418,29 @@ const nameSettlesOf = (
1374
1418
  /**
1375
1419
  * Solid 1's animation callbacks (#257, Motion's props): each Retarget's start and settle told to the
1376
1420
  * config's `onAnimationStart` / `onAnimationComplete`, with its `definition`, as the Retarget read
1377
- * the config. A callback that throws is reported, and the element animates on. The Solid 2 binding's
1378
- * config has neither: it hands the same facts over as async values.
1421
+ * the config. A callback that throws is reported at the first of a run of throws, its next clean call
1422
+ * ending the run, and the element animates on. The Solid 2 binding's config has neither: it hands the
1423
+ * same facts over as async values.
1379
1424
  */
1380
1425
  export const animationCallbacks = (runtime: WardicServices.Runner<WardicServices.WardicServices>, id: string): AnimationHooks => {
1381
- // Per Retarget, per element: the callback looked up first, and nothing made without one.
1382
- const tell = (name: "onAnimationStart" | "onAnimationComplete", callback: (definition: Config.WardicAnimationDefinition) => void, definition: Config.WardicAnimationDefinition): void => {
1426
+ // #979 group I, row 25 (ADR-0074 decision 3): a run is one callback's throws at its consecutive calls,
1427
+ // each name of a list one call, so a clean name ends it. Two lets, nothing more made per element.
1428
+ let startFailing = false
1429
+ let completeFailing = false
1430
+ // Per Retarget, per element: the callback looked up first, and nothing made without one. Whether it threw,
1431
+ // reported at a run's first throw (`failing` says one is on).
1432
+ const tell = (
1433
+ name: "onAnimationStart" | "onAnimationComplete",
1434
+ callback: (definition: Config.WardicAnimationDefinition) => void,
1435
+ definition: Config.WardicAnimationDefinition,
1436
+ failing: boolean,
1437
+ ): boolean => {
1383
1438
  try {
1384
1439
  callback(definition)
1440
+ return false
1385
1441
  } catch (defect) {
1386
- runtime.runFork(Report.failure(`wardic.spine: ${name} failed`, Cause.die(defect)).pipe(Effect.annotateLogs({ id })))
1442
+ if (!failing) runtime.runFork(Report.failure(`wardic.spine: ${name} failed`, Cause.die(defect)).pipe(Effect.annotateLogs({ id })))
1443
+ return true
1387
1444
  }
1388
1445
  }
1389
1446
  return {
@@ -1393,10 +1450,12 @@ export const animationCallbacks = (runtime: WardicServices.Runner<WardicServices
1393
1450
  if (Predicate.isUndefined(callback)) return
1394
1451
  const definition = definitionOf(resolution, previous)
1395
1452
  if (Arr.isArray(definition)) {
1396
- Arr.forEach(definition as ReadonlyArray<string>, (name) => tell("onAnimationStart", callback, name))
1453
+ Arr.forEach(definition as ReadonlyArray<string>, (name) => {
1454
+ startFailing = tell("onAnimationStart", callback, name, startFailing)
1455
+ })
1397
1456
  return
1398
1457
  }
1399
- tell("onAnimationStart", callback, definition)
1458
+ startFailing = tell("onAnimationStart", callback, definition, startFailing)
1400
1459
  },
1401
1460
  // A list's names were each told as they settled (`namesSettled`).
1402
1461
  settled: (resolution, previous, config) => {
@@ -1404,12 +1463,14 @@ export const animationCallbacks = (runtime: WardicServices.Runner<WardicServices
1404
1463
  if (Predicate.isUndefined(callback)) return
1405
1464
  const definition = definitionOf(resolution, previous)
1406
1465
  if (Arr.isArray(definition)) return
1407
- tell("onAnimationComplete", callback, definition)
1466
+ completeFailing = tell("onAnimationComplete", callback, definition, completeFailing)
1408
1467
  },
1409
1468
  namesSettled: (names, config) => {
1410
1469
  const callback = config.onAnimationComplete
1411
1470
  if (Predicate.isUndefined(callback)) return
1412
- Arr.forEach(names, (name) => tell("onAnimationComplete", callback, name))
1471
+ Arr.forEach(names, (name) => {
1472
+ completeFailing = tell("onAnimationComplete", callback, name, completeFailing)
1473
+ })
1413
1474
  },
1414
1475
  }
1415
1476
  }
@@ -1446,7 +1507,7 @@ const baseTargetOf = (
1446
1507
  ): VariantTarget.Target => {
1447
1508
  if (Predicate.isNotUndefined(own)) return VariantTarget.resolveTarget(own, variants, custom, state)
1448
1509
  if (Predicate.isNotUndefined(variant)) return VariantTarget.resolveTarget(variant, variants, custom, state)
1449
- return { values: initialLink, transition: undefined, transitionEnd: undefined, keyframes: undefined }
1510
+ return { values: initialLink, transition: undefined, transitionEnd: undefined, keyframes: undefined, failure: VariantTarget.NO_FAILURE }
1450
1511
  }
1451
1512
 
1452
1513
  /**
@@ -1581,6 +1642,8 @@ export interface Start {
1581
1642
  * landing with nothing to animate, is told to no one.
1582
1643
  */
1583
1644
  readonly quiet: boolean
1645
+ /** The first of its variants whose resolver threw as it was set up (#979): that entry gave no values. */
1646
+ readonly failure: Option.Option<VariantTarget.VariantFailure>
1584
1647
  }
1585
1648
 
1586
1649
  /**
@@ -1595,15 +1658,134 @@ export const startOf = (
1595
1658
  untrack: Reactivity.Reactivity["untrack"],
1596
1659
  ): Start => {
1597
1660
  const startedAtAnimate = VariantTree.startsAtAnimate(config, parent, presenceBlocks)
1598
- const initialValues = VariantTree.startingValuesOf(config, parent, presenceBlocks, untrack)
1661
+ // Its variants resolved once (#277), what a resolver among them threw beside them (#979): one value
1662
+ // for an element with no variants, so its start makes nothing more (bench:solid's mount).
1663
+ const variants = VariantTarget.startingVariantsOf(config.variants, config.custom)
1664
+ const initialValues = VariantTree.startingValuesFrom(config, parent, presenceBlocks, untrack, variants.variants)
1599
1665
  return {
1600
1666
  quiet: VariantTree.startsQuiet(config, parent, presenceBlocks, untrack),
1601
1667
  initialValues,
1602
1668
  initialLink: Bool.match(startedAtAnimate, { onTrue: () => ({}), onFalse: () => initialValues }),
1603
1669
  startedLink: Bool.match(startedAtAnimate, { onTrue: () => initialValues, onFalse: () => ({}) }),
1670
+ failure: variants.failure,
1604
1671
  }
1605
1672
  }
1606
1673
 
1674
+ /** How a variant's failure is reported under `message`, on a runtime: at Error, its cause what the resolver threw, annotated with the variant's name. */
1675
+ const failedOn =
1676
+ (message: string) =>
1677
+ (runtime: Pick<WardicServices.Runner<never>, "runFork">) =>
1678
+ (failure: VariantTarget.VariantFailure): void => {
1679
+ runtime.runFork(Effect.annotateLogs(Report.failure(message, Cause.die(failure.defect)), { variant: failure.name }))
1680
+ }
1681
+
1682
+ /** How an element's variant that throws is reported, on its runtime. */
1683
+ const variantFailedOn = failedOn("wardic.ward: a variant failed")
1684
+
1685
+ /** How an exit whose resolver throws is reported, on `runtime`, each time an element leaves: its element leaves without it (#979). */
1686
+ export const exitVariantFailedOn: (runtime: Pick<WardicServices.Runner<never>, "runFork">) => (failure: VariantTarget.VariantFailure) => void = failedOn(
1687
+ "wardic.presence: an exit variant failed",
1688
+ )
1689
+
1690
+ /** An element's variant failure reported on Effect's default runtime: a server render's, which holds no app reporters (#979). */
1691
+ export const variantFailedOnServer: (failure: VariantTarget.VariantFailure) => void = /*#__PURE__*/ variantFailedOn(VariantTree.ON_SERVER)
1692
+
1693
+ /** The first of a list of entries' failures: built once, as it's asked per Retarget (#460, compose once). */
1694
+ const firstFailureOf = Arr.findFirst<OverrideEntry, VariantTarget.VariantFailure>((layer) => layer.failure)
1695
+
1696
+ /** The first of a resolution's entries' resolvers that threw, and its variant's name (#979). */
1697
+ export const failureOf = (resolution: Resolution): Option.Option<VariantTarget.VariantFailure> => firstFailureOf(resolution.layers)
1698
+
1699
+ /**
1700
+ * An element's dynamic variants that throw: its last good resolution, and each variant failing now with
1701
+ * the places that saw it fail. One an element, made by its binding with `report` on its runtime, and
1702
+ * read through {@link keptOf}, {@link reportStart} and {@link orchestrationOf}: each variant is
1703
+ * reported once, until it resolves again.
1704
+ */
1705
+ export interface VariantFailures extends VariantTree.DelayFailures {
1706
+ /** Its last resolution with no failure: what {@link keptOf} gives while one carries a failure. */
1707
+ last: Resolution | undefined
1708
+ /** Each failing variant, by name, and where it was seen; made at the first failure: most elements never have one. */
1709
+ failing: Map<string, number> | undefined
1710
+ /** The runtime its failures are reported on, at Error. */
1711
+ readonly runtime: Pick<WardicServices.Runner<never>, "runFork">
1712
+ }
1713
+
1714
+ /** An element's {@link VariantFailures}, none failing yet, reported on `runtime`. */
1715
+ // #979 (bench:solid's mount): one plain object an element, read by the functions below, not closures, and
1716
+ // holding its runtime: its report is made only at a failure. A report made once a runtime and found in a
1717
+ // WeakMap cost Solid 1's mount 6% (the lookup, an element).
1718
+ export const variantFailuresOf = (runtime: Pick<WardicServices.Runner<never>, "runFork">): VariantFailures => ({ last: undefined, failing: undefined, delayFailing: false, runtime })
1719
+
1720
+ /** Where a variant's failure was seen, until each resolves it again: its element's resolutions, and its orchestration. */
1721
+ const RESOLVING = 1
1722
+ const ORCHESTRATING = 2
1723
+
1724
+ // #979 (ADR-0074; Q6 and its review): a resolver's throw is its element's alone. Each variant, by name,
1725
+ // is reported as it starts failing and fails until every place that saw it fail resolves it again, so
1726
+ // a throw its resolutions and its orchestration both see is reported once. Setup resolves with no
1727
+ // values, as orchestration does, so a setup failure counts for both: a resolver that throws only with
1728
+ // no values isn't reported again at the first change its orchestration reads.
1729
+ const failedAt = (failures: VariantFailures, failure: VariantTarget.VariantFailure, at: number): void => {
1730
+ const name = UndefinedOr.match(failure.name, { onDefined: identity, onUndefined: () => "" })
1731
+ if (Predicate.isUndefined(failures.failing)) failures.failing = new Map()
1732
+ const before = failures.failing.get(name)
1733
+ if (Predicate.isUndefined(before)) {
1734
+ failures.failing.set(name, at)
1735
+ variantFailedOn(failures.runtime)(failure)
1736
+ return
1737
+ }
1738
+ failures.failing.set(name, before | at)
1739
+ }
1740
+
1741
+ const resolvedAt = (failing: Map<string, number>, name: string | undefined, at: number): void => {
1742
+ if (Predicate.isUndefined(name)) return
1743
+ const before = failing.get(name)
1744
+ if (Predicate.isUndefined(before)) return
1745
+ const after = before & ~at
1746
+ if (after === 0) {
1747
+ failing.delete(name)
1748
+ return
1749
+ }
1750
+ failing.set(name, after)
1751
+ }
1752
+
1753
+ /** `next`, else, while it carries a failure, the element's last good resolution: it keeps its target. */
1754
+ // Per Retarget, per element (#460, compose once): statements; nothing done while nothing fails.
1755
+ export const keptOf = (failures: VariantFailures, next: Resolution): Resolution => {
1756
+ const failure = failureOf(next)
1757
+ if (Option.isSome(failure)) {
1758
+ failedAt(failures, failure.value, RESOLVING)
1759
+ // The first one has no last good one: its failed entry resolved to nothing.
1760
+ const last = failures.last
1761
+ if (Predicate.isUndefined(last)) return next
1762
+ return last
1763
+ }
1764
+ failures.last = next
1765
+ const failing = failures.failing
1766
+ if (Predicate.isUndefined(failing) || failing.size === 0) return next
1767
+ Arr.forEach(next.layers, (layer) => resolvedAt(failing, layer.name, RESOLVING))
1768
+ return next
1769
+ }
1770
+
1771
+ /** A start's failure, setup's or a re-entry's fresh start's: setup resolves as orchestration does, so it stands for both until each resolves the variant again. */
1772
+ export const reportStart = (failures: VariantFailures, start: Start): void => {
1773
+ if (Option.isSome(start.failure)) failedAt(failures, start.failure.value, RESOLVING | ORCHESTRATING)
1774
+ }
1775
+
1776
+ /** What an element's orchestration resolves, told to its failures: made by a variant node that orchestrates. */
1777
+ export const orchestrationOf =
1778
+ (failures: VariantFailures): VariantTarget.Orchestrated =>
1779
+ (entry, failure) => {
1780
+ if (Option.isSome(failure)) {
1781
+ failedAt(failures, failure.value, ORCHESTRATING)
1782
+ return
1783
+ }
1784
+ const failing = failures.failing
1785
+ if (Predicate.isUndefined(failing) || failing.size === 0) return
1786
+ Arr.forEach(Arr.ensure(entry), (name) => resolvedAt(failing, name, ORCHESTRATING))
1787
+ }
1788
+
1607
1789
  /**
1608
1790
  * The Snapshot: each key's last emitted value, a number or a string, and the numeric velocities.
1609
1791
  * A Retarget starts each key from where it is, with its velocity carried across the seam (ADR-0005,
@@ -2431,19 +2613,15 @@ export const makeElementSpine = (options: ElementSpineOptions): ElementSpine =>
2431
2613
  }, running)
2432
2614
  )
2433
2615
  }
2434
- // A snap's or a blend's frames: merged into the Snapshot (ADR-0004), as the spring's are. A blend's
2435
- // last two are kept, its keys' velocities read from them (#464): the frame's own values, which a
2436
- // blend makes anew each frame (`values` writes one object for a leg that lost keys).
2616
+ // A snap's or a blend's frames: merged into the Snapshot (ADR-0004) in place, as the spring's are
2617
+ // (#659; #895: a spread made a record per element per frame). A blend's last two are kept for its keys'
2618
+ // velocities (#464), copied, since its Frame is its run's, rewritten each tick (`keepFrame`).
2437
2619
  const sink = (frame: Frame.Frame<Values.Values>, dt: number): undefined => {
2438
2620
  const value = running.values(frame.value)
2439
- let before = running.last
2440
- // Its first frame: from the Snapshot's values.
2441
- if (Predicate.isUndefined(before)) before = snapshot.values
2442
- running.before = before
2621
+ keepFrame(running, frame, snapshot.values)
2443
2622
  // Over the time its step covered (#865), its first's included: its run's dt, in ms.
2444
2623
  running.lastStep = dt * 1000
2445
- running.last = frame.value
2446
- snapshot.values = { ...snapshot.values, ...value }
2624
+ Object.assign(snapshot.values, value)
2447
2625
  gate.write(id, value)
2448
2626
  recordFrame(value)
2449
2627
  drew(running, frame.done, snapshot.now())
@@ -2857,7 +3035,7 @@ export const makeElementSpine = (options: ElementSpineOptions): ElementSpine =>
2857
3035
  // Its transition asked last, for a key already there alone: per key, per Retarget. A quiet
2858
3036
  // mount's never asks (#475): Motion animates nothing at a first render that starts at its
2859
3037
  // `animate`, whatever velocity its transition gives (`animation-state.ts`, `shouldAnimate`).
2860
- if (still && Predicate.isUndefined(stops) && (quiet || !givesVelocity(keyTransitionOf(resolution, groups, key, transition, elementTransition), key))) {
3038
+ if (still && Predicate.isUndefined(stops) && (quiet || !RetargetLegs.givesVelocity(keyTransitionOf(resolution, groups, key, transition, elementTransition), key))) {
2861
3039
  if (Predicate.isUndefined(stays)) stays = new Set()
2862
3040
  stays.add(key)
2863
3041
  if (Predicate.isUndefined(there)) there = {}
@@ -2877,6 +3055,19 @@ export const makeElementSpine = (options: ElementSpineOptions): ElementSpine =>
2877
3055
  resolvedNow = t
2878
3056
  owners.forEach(giveUpUnresolved)
2879
3057
  keepTheRest()
3058
+ // A key only `initial` sets stays where it put it (#1022), as Motion keeps it: at the first Retarget, one
3059
+ // the resolved target doesn't name joins the keys already there, written with them as the element's first
3060
+ // commit takes its Starting style off. The gate keeps it after; a later layer that sets it returns it as
3061
+ // any. A Batch member's are its Batch's, which draws its groups.
3062
+ if (Predicate.isUndefined(lastResolution)) {
3063
+ if (Predicate.isUndefined(member)) {
3064
+ Arr.forEach(Rec.keys(initialValues), (key) => {
3065
+ if (Object.hasOwn(resolved, key)) return
3066
+ if (Predicate.isUndefined(there)) there = {}
3067
+ there[key] = UndefinedOr.getOrThrow(snapshot.values[key])
3068
+ })
3069
+ }
3070
+ }
2880
3071
  // The keys this Retarget starts legs for: all of them, unless some stay.
2881
3072
  let fresh: Values.Values = t
2882
3073
  if (Predicate.isNotUndefined(stays)) {
@@ -2954,7 +3145,7 @@ export const makeElementSpine = (options: ElementSpineOptions): ElementSpine =>
2954
3145
  // animation is skipped (#468): the keys found above, and those Keyframes of two stops start from their first.
2955
3146
  let measured: RetargetLegs.MeasuredPairs | undefined
2956
3147
  if (!reduce && !skipped && (Predicate.isNotUndefined(measuring) || Predicate.isNotUndefined(keyframesNow))) {
2957
- measured = measuredOf(measuredPairs, element, measuringOf(measuring, keyframesNow), from, fresh, snapshot.values, manyStops)
3148
+ measured = measuredOf(measuredPairs, element, measuringOf(measuring, keyframesNow), from, fresh, snapshot.values, manyStops, runtime, id)
2958
3149
  }
2959
3150
  let told: ToldNames | undefined
2960
3151
  if (!silent) told = namesToldOf(animation, resolution, lastResolution)
@@ -2973,12 +3164,16 @@ export const makeElementSpine = (options: ElementSpineOptions): ElementSpine =>
2973
3164
  legGroups = split.tags
2974
3165
  }
2975
3166
  // The Handoff (#48, ADR-0044 decision 6): the first Retarget that starts picks the Appear
2976
- // animation up as far in as it has got, read at the legs' first tick.
3167
+ // animation up as far in as it has got, read at the legs' first tick. Its legs keep the frame
3168
+ // timeline's time, where the Appear animation's `currentTime` is (#1026).
3169
+ let takenOver = false
2977
3170
  if (Predicate.isNotUndefined(handoff)) {
3171
+ takenOver = true
2978
3172
  const taken = handoff
2979
3173
  handoff = undefined
2980
3174
  if (Predicate.isNotUndefined(diagnostics)) {
2981
- diagnostics.checkHandoff(runtime, id, taken, { tag, from, to: fresh, transition: baseTransition, reduced: reduce, layout: isLayoutNode(c), stops: manyStops, ...AppearHandoff.skippedField(skipped), ...templateField(c.transformTemplate) })
3175
+ // With the keys it leaves where they are (#1004), which the server's rule holds beside the moving ones.
3176
+ diagnostics.checkHandoff(runtime, id, taken, { tag, from, to: fresh, transition: baseTransition, reduced: reduce, layout: isLayoutNode(c), stops: manyStops, ...AppearHandoff.skippedField(skipped), ...templateField(c.transformTemplate), held: there })
2982
3177
  }
2983
3178
  const at = AppearHandoff.startAtOf(taken, baseTransition, delayOf(transition))
2984
3179
  retargetLegs = Arr.map(retargetLegs, (one) => RetargetLegs.startingAt(one, at))
@@ -3022,7 +3217,7 @@ export const makeElementSpine = (options: ElementSpineOptions): ElementSpine =>
3022
3217
  // leg draws the keys it animates (#325) until a later Retarget takes them.
3023
3218
  Arr.forEach(retargetLegs, (leg: RetargetLegs.Leg, i): void => {
3024
3219
  if (Predicate.isNotUndefined(legGates)) gateNow = legGates[i]
3025
- const running = runningOf(leg.to, resolution, landing, leg._tag)
3220
+ const running = runningOf(leg.to, resolution, landing, leg._tag, takenOver)
3026
3221
  own(running)
3027
3222
  runLeg(running, legProgram(leg, running, variables))
3028
3223
  })