@wardic/dom 1.3.0 → 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 (136) hide show
  1. package/dist/MeasuredPair.d.ts +14 -1
  2. package/dist/MeasuredPair.d.ts.map +1 -1
  3. package/dist/MeasuredPair.js +11 -13
  4. package/dist/MeasuredPair.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/internal/appear.d.ts +6 -0
  10. package/dist/internal/appear.d.ts.map +1 -1
  11. package/dist/internal/appear.js +20 -2
  12. package/dist/internal/appear.js.map +1 -1
  13. package/dist/internal/batch-handoff.d.ts.map +1 -1
  14. package/dist/internal/batch-handoff.js +25 -15
  15. package/dist/internal/batch-handoff.js.map +1 -1
  16. package/dist/internal/batch-writer.d.ts +1 -1
  17. package/dist/internal/batch-writer.d.ts.map +1 -1
  18. package/dist/internal/batch-writer.js +26 -6
  19. package/dist/internal/batch-writer.js.map +1 -1
  20. package/dist/internal/clock.d.ts +6 -0
  21. package/dist/internal/clock.d.ts.map +1 -1
  22. package/dist/internal/clock.js +9 -0
  23. package/dist/internal/clock.js.map +1 -1
  24. package/dist/internal/default-transition.d.ts +3 -2
  25. package/dist/internal/default-transition.d.ts.map +1 -1
  26. package/dist/internal/default-transition.js +14 -3
  27. package/dist/internal/default-transition.js.map +1 -1
  28. package/dist/internal/failing.d.ts +9 -0
  29. package/dist/internal/failing.d.ts.map +1 -0
  30. package/dist/internal/failing.js +33 -0
  31. package/dist/internal/failing.js.map +1 -0
  32. package/dist/internal/length-keys.d.ts +19 -0
  33. package/dist/internal/length-keys.d.ts.map +1 -0
  34. package/dist/internal/length-keys.js +77 -0
  35. package/dist/internal/length-keys.js.map +1 -0
  36. package/dist/internal/measured-pairs.d.ts +3 -2
  37. package/dist/internal/measured-pairs.d.ts.map +1 -1
  38. package/dist/internal/measured-pairs.js +60 -23
  39. package/dist/internal/measured-pairs.js.map +1 -1
  40. package/dist/internal/own-values.d.ts.map +1 -1
  41. package/dist/internal/own-values.js +2 -2
  42. package/dist/internal/own-values.js.map +1 -1
  43. package/dist/internal/positional-keys.d.ts +1 -1
  44. package/dist/internal/positional-keys.d.ts.map +1 -1
  45. package/dist/internal/positional-keys.js +4 -2
  46. package/dist/internal/positional-keys.js.map +1 -1
  47. package/dist/internal/projection.d.ts.map +1 -1
  48. package/dist/internal/projection.js +138 -39
  49. package/dist/internal/projection.js.map +1 -1
  50. package/dist/internal/renderer.d.ts +26 -16
  51. package/dist/internal/renderer.d.ts.map +1 -1
  52. package/dist/internal/renderer.js +45 -106
  53. package/dist/internal/renderer.js.map +1 -1
  54. package/dist/internal/scroll.d.ts.map +1 -1
  55. package/dist/internal/scroll.js +26 -2
  56. package/dist/internal/scroll.js.map +1 -1
  57. package/dist/internal/transform-keys.d.ts +22 -0
  58. package/dist/internal/transform-keys.d.ts.map +1 -0
  59. package/dist/internal/transform-keys.js +43 -0
  60. package/dist/internal/transform-keys.js.map +1 -0
  61. package/dist/unstable/AppearAnimations.d.ts +2 -1
  62. package/dist/unstable/AppearAnimations.d.ts.map +1 -1
  63. package/dist/unstable/AppearAnimations.js +73 -22
  64. package/dist/unstable/AppearAnimations.js.map +1 -1
  65. package/dist/unstable/BatchMembers.d.ts +6 -2
  66. package/dist/unstable/BatchMembers.d.ts.map +1 -1
  67. package/dist/unstable/BatchMembers.js +30 -7
  68. package/dist/unstable/BatchMembers.js.map +1 -1
  69. package/dist/unstable/DomValues.js +1 -1
  70. package/dist/unstable/DomValues.js.map +1 -1
  71. package/dist/unstable/DragTrack.d.ts +2 -2
  72. package/dist/unstable/DragTrack.d.ts.map +1 -1
  73. package/dist/unstable/DragTrack.js +34 -8
  74. package/dist/unstable/DragTrack.js.map +1 -1
  75. package/dist/unstable/ElementSetup.d.ts.map +1 -1
  76. package/dist/unstable/ElementSetup.js +2 -1
  77. package/dist/unstable/ElementSetup.js.map +1 -1
  78. package/dist/unstable/GestureFeatures.d.ts +2 -1
  79. package/dist/unstable/GestureFeatures.d.ts.map +1 -1
  80. package/dist/unstable/GestureFeatures.js +18 -37
  81. package/dist/unstable/GestureFeatures.js.map +1 -1
  82. package/dist/unstable/Imperative.d.ts +2 -1
  83. package/dist/unstable/Imperative.d.ts.map +1 -1
  84. package/dist/unstable/Imperative.js.map +1 -1
  85. package/dist/unstable/LiveStyle.d.ts +28 -2
  86. package/dist/unstable/LiveStyle.d.ts.map +1 -1
  87. package/dist/unstable/LiveStyle.js +8 -32
  88. package/dist/unstable/LiveStyle.js.map +1 -1
  89. package/dist/unstable/MemberHold.js +2 -2
  90. package/dist/unstable/MemberHold.js.map +1 -1
  91. package/dist/unstable/PointerValues.d.ts.map +1 -1
  92. package/dist/unstable/PointerValues.js +82 -8
  93. package/dist/unstable/PointerValues.js.map +1 -1
  94. package/dist/unstable/PresenceController.d.ts +5 -2
  95. package/dist/unstable/PresenceController.d.ts.map +1 -1
  96. package/dist/unstable/PresenceController.js +68 -41
  97. package/dist/unstable/PresenceController.js.map +1 -1
  98. package/dist/unstable/ReorderInput.d.ts +2 -2
  99. package/dist/unstable/ReorderInput.js +2 -2
  100. package/dist/unstable/WardConfig.d.ts +13 -4
  101. package/dist/unstable/WardConfig.d.ts.map +1 -1
  102. package/dist/unstable/WardConfig.js.map +1 -1
  103. package/dist/unstable/features/TimelineKeys.d.ts.map +1 -1
  104. package/dist/unstable/features/TimelineKeys.js +18 -2
  105. package/dist/unstable/features/TimelineKeys.js.map +1 -1
  106. package/package.json +3 -3
  107. package/src/MeasuredPair.ts +21 -1
  108. package/src/index.ts +4 -1
  109. package/src/internal/appear.ts +20 -2
  110. package/src/internal/batch-handoff.ts +19 -11
  111. package/src/internal/batch-writer.ts +27 -6
  112. package/src/internal/clock.ts +10 -0
  113. package/src/internal/default-transition.ts +14 -4
  114. package/src/internal/failing.ts +37 -0
  115. package/src/internal/length-keys.ts +80 -0
  116. package/src/internal/measured-pairs.ts +58 -22
  117. package/src/internal/own-values.ts +2 -2
  118. package/src/internal/positional-keys.ts +4 -2
  119. package/src/internal/projection.ts +141 -37
  120. package/src/internal/renderer.ts +45 -92
  121. package/src/internal/scroll.ts +24 -2
  122. package/src/internal/transform-keys.ts +47 -0
  123. package/src/unstable/AppearAnimations.ts +73 -24
  124. package/src/unstable/BatchMembers.ts +38 -10
  125. package/src/unstable/DomValues.ts +1 -1
  126. package/src/unstable/DragTrack.ts +46 -12
  127. package/src/unstable/ElementSetup.ts +2 -1
  128. package/src/unstable/GestureFeatures.ts +23 -44
  129. package/src/unstable/Imperative.ts +2 -1
  130. package/src/unstable/LiveStyle.ts +12 -8
  131. package/src/unstable/MemberHold.ts +2 -2
  132. package/src/unstable/PointerValues.ts +73 -8
  133. package/src/unstable/PresenceController.ts +66 -40
  134. package/src/unstable/ReorderInput.ts +2 -2
  135. package/src/unstable/WardConfig.ts +17 -5
  136. package/src/unstable/features/TimelineKeys.ts +19 -2
@@ -100,6 +100,10 @@ interface Request {
100
100
  readonly element: HTMLElement
101
101
  readonly slots: ReadonlyArray<Slot>
102
102
  readonly values: Values.Values
103
+ /** Its asker's, told what its write threw (#979, row 8). */
104
+ readonly failed: (defect: unknown) => void
105
+ /** Whether its write threw: its pairs are left unread. */
106
+ threw: boolean
103
107
  }
104
108
 
105
109
  // Module state (#460, Q7): each pair its batch has read, by the pair as asked, kept as long as its asker
@@ -122,16 +126,18 @@ let scheduled = false
122
126
  /**
123
127
  * Measures `pairs` on `element` at the end of this task, with every other element's in the same batch:
124
128
  * each pair, as asked, {@link measured} before the next tick. `values` are what the element draws now,
125
- * its other transforms among them.
129
+ * its other transforms among them. Writing them can throw (a Transform template among `values`): then
130
+ * its pairs are never measured, `failed` is told, and the rest of the batch goes on.
126
131
  */
127
- // #430's Q2.
132
+ // #430's Q2. #979, row 8 (ADR-0074): `failed`, its asker's, which reports through its own runtime.
128
133
  export const measure = (
129
134
  element: HTMLElement,
130
135
  pairs: Readonly<Record<string, { readonly from: number | string; readonly to: number | string }>>,
131
136
  values: Values.Values,
137
+ failed: (defect: unknown) => void,
132
138
  ): Readonly<Record<string, Requested>> => {
133
139
  const made = Rec.map(pairs, ({ from, to }, key): Requested => ({ key, from, to }))
134
- queued.push({ element, slots: Arr.map(Rec.values(made), (pair): Slot => ({ pair, fromPx: undefined, toPx: undefined })), values })
140
+ queued.push({ element, slots: Arr.map(Rec.values(made), (pair): Slot => ({ pair, fromPx: undefined, toPx: undefined })), values, failed, threw: false })
135
141
  if (Bool.not(scheduled)) {
136
142
  scheduled = true
137
143
  queueMicrotask(flush)
@@ -207,35 +213,42 @@ const savedOf = (element: HTMLElement, property: string): Saved => ({ element, p
207
213
 
208
214
  /**
209
215
  * Write `pairs`' translates at their `end` through the element's whole transform, keeping what was
210
- * there: the browser lays out any unit, `-100%` included (#594).
216
+ * there in `saved` before it's written: the browser lays out any unit, `-100%` included (#594).
211
217
  */
212
- const writeTranslates = (request: Request, slots: ReadonlyArray<Slot>, end: "from" | "to"): ReadonlyArray<Saved> => {
213
- if (slots.length === 0) return []
218
+ const writeTranslates = (request: Request, slots: ReadonlyArray<Slot>, end: "from" | "to", saved: Array<Saved>): void => {
219
+ if (slots.length === 0) return
214
220
  const { element, values } = request
215
- const saved = savedOf(element, "transform")
216
221
  const transform = project({ ...values, ...Rec.fromEntries(Arr.map(slots, ({ pair }) => [pair.key, pair[end]] as const)) })["transform"]
222
+ saved.push(savedOf(element, "transform"))
217
223
  element.style.setProperty("transform", UndefinedOr.match(transform as string | undefined, { onUndefined: () => "none", onDefined: String }))
218
- return [saved]
219
224
  }
220
225
 
221
- /** Write each pair's target inline on its element, keeping what was there; a translate through the element's whole transform. */
222
- const writeTargets = (request: Request): ReadonlyArray<Saved> => {
226
+ /**
227
+ * Write each pair's target inline on its element, keeping what was there in `saved` before each is
228
+ * written; a translate through the element's whole transform.
229
+ */
230
+ const writeTargets = (request: Request, saved: Array<Saved>): void => {
223
231
  const unread = Arr.filter(request.slots, (slot) => Predicate.isUndefined(slot.toPx))
224
- const saved: Array<Saved> = [...writeTranslates(request, Arr.filter(unread, (slot) => TRANSLATES.has(slot.pair.key)), "to")]
232
+ writeTranslates(request, Arr.filter(unread, (slot) => TRANSLATES.has(slot.pair.key)), "to", saved)
225
233
  Arr.forEach(unread, ({ pair }) => {
226
234
  if (TRANSLATES.has(pair.key)) return
227
235
  saved.push(savedOf(request.element, pair.key))
228
236
  request.element.style.setProperty(pair.key, cssOf(pair.to))
229
237
  })
230
- return saved
231
238
  }
232
239
 
233
240
  /**
234
241
  * Write each translate pair's start not in px, as a target is (#594): a layout element's transform at
235
242
  * this moment is its projection's, or held off for its Measure pass, so reading it as it is gave 0.
236
243
  */
237
- const writeTranslateStarts = (request: Request): ReadonlyArray<Saved> =>
238
- writeTranslates(request, Arr.filter(request.slots, (slot) => Bool.and(TRANSLATES.has(slot.pair.key), Predicate.isUndefined(slot.fromPx))), "from")
244
+ const writeTranslateStarts = (request: Request, saved: Array<Saved>): void =>
245
+ writeTranslates(request, Arr.filter(request.slots, (slot) => Bool.and(TRANSLATES.has(slot.pair.key), Predicate.isUndefined(slot.fromPx))), "from", saved)
246
+
247
+ /** `request`'s write threw: its pairs are left unread, so its animation switches, and its asker is told. */
248
+ const requestThrew = (request: Request, defect: unknown): void => {
249
+ request.threw = true
250
+ request.failed(defect)
251
+ }
239
252
 
240
253
  /** Put back what {@link writeTargets} replaced. */
241
254
  const restore = (saved: ReadonlyArray<Saved>): void =>
@@ -260,27 +273,49 @@ const flush = (): void => {
260
273
  slot.toPx = givenPx(slot.pair.to)
261
274
  slot.fromPx = givenPx(slot.pair.from)
262
275
  }))
276
+ // #979, row 8 (ADR-0074): each request's write is its own, in a `try` of its own in each write's loop.
277
+ // One that throws (an exit's Transform template, say) is left unread, its asker told, and the rest of
278
+ // the batch goes on, every style written so far put back: before, its throw ended the batch
279
+ // uncaught, every pair in it voided and the targets written before it left inline.
263
280
  // WRITE, READ, WRITE: each translate's start not in px, written alone and read (#594).
264
- const starts = Arr.flatMap(batch, writeTranslateStarts)
265
- if (Arr.isArrayNonEmpty(starts)) {
266
- try {
281
+ const starts: Array<Saved> = []
282
+ try {
283
+ Arr.forEach(batch, (request) => {
284
+ try {
285
+ writeTranslateStarts(request, starts)
286
+ } catch (defect) {
287
+ requestThrew(request, defect)
288
+ }
289
+ })
290
+ if (Arr.isArrayNonEmpty(starts)) {
267
291
  Arr.forEach(batch, (request, i) => Arr.forEach(request.slots, (slot) => {
292
+ if (request.threw) return
268
293
  if (Bool.and(TRANSLATES.has(slot.pair.key), Predicate.isUndefined(slot.fromPx))) slot.fromPx = readPx(request.element, UndefinedOr.getOrThrow(styles[i]), slot.pair.key)
269
294
  }))
270
- } finally {
271
- restore(starts)
272
295
  }
296
+ } finally {
297
+ restore(starts)
273
298
  }
274
299
  // READ: each other start not already in px, as the element lays out now.
275
300
  Arr.forEach(batch, (request, i) => Arr.forEach(request.slots, (slot) => {
301
+ if (request.threw) return
276
302
  if (Predicate.isUndefined(slot.fromPx)) slot.fromPx = readPx(request.element, UndefinedOr.getOrThrow(styles[i]), slot.pair.key)
277
303
  }))
278
304
  const scrollY = globalThis.scrollY
279
- // WRITE: each target, inline.
280
- const saved = Arr.flatMap(batch, writeTargets)
305
+ const saved: Array<Saved> = []
281
306
  try {
307
+ // WRITE: each target, inline.
308
+ Arr.forEach(batch, (request) => {
309
+ if (request.threw) return
310
+ try {
311
+ writeTargets(request, saved)
312
+ } catch (defect) {
313
+ requestThrew(request, defect)
314
+ }
315
+ })
282
316
  // READ: each target not already in px, laid out once.
283
317
  Arr.forEach(batch, (request, i) => Arr.forEach(request.slots, (slot) => {
318
+ if (request.threw) return
284
319
  if (Predicate.isUndefined(slot.toPx)) slot.toPx = readPx(request.element, UndefinedOr.getOrThrow(styles[i]), slot.pair.key)
285
320
  }))
286
321
  } finally {
@@ -288,8 +323,9 @@ const flush = (): void => {
288
323
  restore(saved)
289
324
  if (globalThis.scrollY !== scrollY) globalThis.scrollTo(globalThis.scrollX, scrollY)
290
325
  }
291
- // Each pair read at both ends, as a record of its own.
326
+ // Each pair read at both ends, as a record of its own: none of a request whose write threw.
292
327
  Arr.forEach(batch, (request) => Arr.forEach(request.slots, ({ pair, fromPx, toPx }) => {
328
+ if (request.threw) return
293
329
  if (Predicate.isUndefined(fromPx)) return
294
330
  if (Predicate.isUndefined(toPx)) return
295
331
  if (Bool.and(Number.isFinite(fromPx), Number.isFinite(toPx))) read.set(pair, { ...pair, fromPx, toPx })
@@ -10,7 +10,6 @@
10
10
  * Observability: per element and cold (once per key), so quiet; the spine logs what it
11
11
  * started from and returned to.
12
12
  */
13
- import * as BaseValue from "@wardic/core/BaseValue"
14
13
  import * as Interpolator from "@wardic/core/Interpolator"
15
14
  import * as Bool from "effect/Boolean"
16
15
  import * as Match from "effect/Match"
@@ -20,6 +19,7 @@ import * as Predicate from "effect/Predicate"
20
19
  import * as Str from "effect/String"
21
20
  import { parseCssText } from "./starting-style.ts"
22
21
  import { dashCase, isSvgInner, svgAttrNameOf } from "./svg.ts"
22
+ import * as TransformKeys from "./transform-keys.ts"
23
23
 
24
24
  /** An element's own value for a key: the raw value read, a string, a transform key's identity, or `None`. */
25
25
  export type OwnValue = (key: string) => Option.Option<number | string>
@@ -53,7 +53,7 @@ export const ownValues = (element: Element): OwnValue => {
53
53
  onFalse: () => Option.none(),
54
54
  })
55
55
  const read = (key: string): Option.Option<number | string> =>
56
- Option.orElse(BaseValue.transformIdentity(key), () =>
56
+ Option.orElse(TransformKeys.transformIdentity(key), () =>
57
57
  Option.orElse(attributeOf(key), () => nonEmpty(computedStyle().getPropertyValue(dashCase(key)).trim()))
58
58
  )
59
59
  return (key) =>
@@ -10,6 +10,7 @@ import * as ReducedMotion from "@wardic/core/ReducedMotion"
10
10
  import * as Layer from "effect/Layer"
11
11
  import * as Predicate from "effect/Predicate"
12
12
  import { dashCase } from "./svg.ts"
13
+ import * as TransformKeys from "./transform-keys.ts"
13
14
 
14
15
  /** The box's position and size, as CSS properties. */
15
16
  const BOX_KEYS: ReadonlySet<string> = new Set(["width", "height", "top", "left", "right", "bottom"])
@@ -17,8 +18,9 @@ const BOX_KEYS: ReadonlySet<string> = new Set(["width", "height", "top", "left",
17
18
  /** A key of the box's position or size, written as a CSS name or in camelCase. */
18
19
  const isBoxKey: Predicate.Predicate<string> = (key) => BOX_KEYS.has(dashCase(key))
19
20
 
20
- /** Whether reduced motion lands `key` at once: a transform, or a key that places or sizes the box. */
21
- export const isPositional: Predicate.Predicate<string> = Predicate.or(ReducedMotion.isTransform, isBoxKey)
21
+ /** Whether reduced motion lands `key` at once: one of the DOM's transforms, or a key that places or sizes the box. */
22
+ // #887 (Q11): the DOM's transforms, core's and its own, so its depth lands at once, as Motion's does.
23
+ export const isPositional: Predicate.Predicate<string> = Predicate.or(TransformKeys.isTransformKey, isBoxKey)
22
24
 
23
25
  /** The DOM Environment's `ReducedMotion.PositionalKeys`. */
24
26
  export const PositionalKeysDomLive: Layer.Layer<ReducedMotion.PositionalKeys> = Layer.succeed(ReducedMotion.PositionalKeys, { isPositional })
@@ -125,6 +125,7 @@ import { pending as appearRuns } from "./appear-slot.ts"
125
125
  import * as Report from "@wardic/core/unstable/Report"
126
126
  import { blendRadius, borderRadiusCorrector, isUnitScale, SCALE_CORRECTORS, type ScaleCorrector, type ScaleCorrectorEntry, scaleRadius, ZERO_RADIUS } from "./scale-correction.ts"
127
127
  import { dashCase } from "./svg.ts"
128
+ import * as Failing from "./failing.ts"
128
129
 
129
130
  /**
130
131
  * What the engine writes each node's projection through: a `FlushGate` is one, so the engine never
@@ -1247,6 +1248,9 @@ interface NodeState {
1247
1248
  /** Called as a Measure pass that measures it begins, and with its box after the read (#443); most nodes have neither. */
1248
1249
  readonly onBeforeMeasure: (() => void) | undefined
1249
1250
  readonly onMeasure: ((box: Box.Box, prev: Option.Option<Box.Box>) => void) | undefined
1251
+ /** The names of the app's callbacks on it whose last call threw, made at the first throw: most nodes never see one. */
1252
+ // #979 group I, row 29 (ADR-0074 decision 3).
1253
+ failing: Set<LayoutCallbackName> | undefined
1250
1254
  /**
1251
1255
  * What the node's handover blends from (ADR-0010 *Amendment (#166)*): the twin's radius, rotation
1252
1256
  * and, for a Switch, opacity, as they were drawn as it began. Eased into the node's own over the
@@ -1418,6 +1422,17 @@ interface NodeState {
1418
1422
  customBases: Readonly<Record<string, string>> | undefined
1419
1423
  /** Whether an app's corrector's value is written corrected now (so it's put back once at rest). */
1420
1424
  customCorrected: boolean
1425
+ // --- the app's code, its own (#979, row 5; ADR-0074): each reported once a run of throws ---
1426
+ /** Whether its layout animation's ease threw at its last call. */
1427
+ easeFailing: boolean
1428
+ /** The app's correctors that threw for it at their last call: made at the first throw. */
1429
+ failingCorrectors: Set<CustomCorrector> | undefined
1430
+ /** Whether its write threw at its last call, as a leaving node writes straight onto its element. */
1431
+ writeFailing: boolean
1432
+ /** Whether its Transform template threw as a Measure pass held it for the read. */
1433
+ heldFailing: boolean
1434
+ /** Its Transform template's last result, which a pass holds it at when the template throws: `none` before one. */
1435
+ lastHeld: string
1421
1436
  // --- drag (ADR-0016) ---
1422
1437
  /** Whether this node is being dragged: its target follows the pointer (no spring), held active. */
1423
1438
  dragging: boolean
@@ -1479,6 +1494,8 @@ interface LastPass {
1479
1494
  * `handleLeave` brought it back.
1480
1495
  */
1481
1496
  interface Leaver {
1497
+ /** Its node's id: a node it comes back as is reported by it (#979, row 5). */
1498
+ readonly id: string
1482
1499
  readonly element: HTMLElement
1483
1500
  /** Its last pass; `undefined` when it never had one, and then it can't come back. */
1484
1501
  readonly last: LastPass | undefined
@@ -1552,17 +1569,6 @@ const NO_OWN_TRANSLATE = (): Point.Point => NO_TRANSLATE
1552
1569
  /** No values registered for an element (#443): an app's corrector reads its base then. */
1553
1570
  const NO_VALUES: Readonly<Record<string, unknown>> = {}
1554
1571
 
1555
- /**
1556
- * The transform a Measure pass holds `node` at (#443): its Transform template's, `none` for a node
1557
- * with none (Motion's `resetTransform`), which is what an at-rest node already draws (#674). Per pass
1558
- * per node: a field read and an early return.
1559
- */
1560
- const heldTransformFor = (node: { readonly heldTransform: (() => string) | undefined }): string => {
1561
- const held = node.heldTransform
1562
- if (Predicate.isUndefined(held)) return "none"
1563
- return held()
1564
- }
1565
-
1566
1572
  /** No own rotation or opacity of its own: a node the binding gives none, or a leaving one (*Amendment (#166)*). */
1567
1573
  const NO_OWN_ROTATE = (): number => 0
1568
1574
  const NO_OWN_OPACITY = (): number => 1
@@ -1599,6 +1605,10 @@ const SIZE_EPSILON = 0.01
1599
1605
 
1600
1606
  /** No layout animation callback: a node the binding gives none (#191). */
1601
1607
  const NO_CALLBACK = (): Option.Option<() => void> => Option.none()
1608
+
1609
+ /** An app's callback on a layout node, by the name its report gives it. */
1610
+ type LayoutCallbackName = "onLayoutAnimationStart" | "onLayoutAnimationComplete" | "onDragTransitionEnd" | "onBeforeLayoutMeasure" | "onLayoutMeasure"
1611
+
1602
1612
  /** A call with no options. */
1603
1613
  const NO_ANIMATE_LAYOUT_OPTIONS: AnimateLayoutOptions = {}
1604
1614
 
@@ -1991,7 +2001,16 @@ export const makeProjectionSystem = (
1991
2001
  const patch = projectionPatchOf(value, corrected)
1992
2002
  // A leaving node is driven directly: its gate registration is gone.
1993
2003
  if (node.leaving) {
1994
- renderer.commit(node.element, renderer.project(withExitValues(node, patch)))
2004
+ // #979, row 5 (ADR-0074): as the gate takes each element's write on its own (#969), a leaver's
2005
+ // write that throws (its Transform template's, say) leaves it as it was drawn, and every other
2006
+ // node goes on: before, it failed the coordinator's run, so every layout animation stopped.
2007
+ try {
2008
+ renderer.commit(node.element, renderer.project(withExitValues(node, patch)))
2009
+ if (node.writeFailing) node.writeFailing = false
2010
+ } catch (defect) {
2011
+ if (!node.writeFailing) runtime.runFork(Effect.annotateLogs(Report.failure("wardic.projection: a leaving node's write failed", Cause.die(defect)), { id: node.id }))
2012
+ node.writeFailing = true
2013
+ }
1995
2014
  return
1996
2015
  }
1997
2016
  sink.write(node.id, patch)
@@ -2053,12 +2072,35 @@ export const makeProjectionSystem = (
2053
2072
  for (const key of corrector.writes) out[key] = String(latest)
2054
2073
  continue
2055
2074
  }
2056
- const corrected = String(corrector.correct(latest, { target: node.lastTarget as Box.Box, treeScale, projectionDelta: node.lastDelta }))
2075
+ // #979, row 5 (ADR-0074): the app's corrector is its node's own. One that throws leaves its keys
2076
+ // at their last value this frame, and the node's other keys and every other node go on: before,
2077
+ // it failed the coordinator's run, or the Measure pass that seeded it, so nothing moved.
2078
+ let corrected: string
2079
+ try {
2080
+ corrected = String(corrector.correct(latest, { target: node.lastTarget as Box.Box, treeScale, projectionDelta: node.lastDelta }))
2081
+ const failing = node.failingCorrectors
2082
+ if (Predicate.isNotUndefined(failing)) failing.delete(corrector)
2083
+ } catch (defect) {
2084
+ correctorFailed(node, corrector, defect)
2085
+ continue
2086
+ }
2057
2087
  for (const key of corrector.writes) out[key] = corrected
2058
2088
  }
2059
2089
  return out
2060
2090
  }
2061
2091
 
2092
+ /** `corrector` threw for `node`: reported at its first throw of a run, until a clean call. */
2093
+ const correctorFailed = (node: NodeState, corrector: CustomCorrector, defect: unknown): void => {
2094
+ let failing = node.failingCorrectors
2095
+ if (Predicate.isUndefined(failing)) {
2096
+ failing = new Set()
2097
+ node.failingCorrectors = failing
2098
+ }
2099
+ if (failing.has(corrector)) return
2100
+ failing.add(corrector)
2101
+ runtime.runFork(Effect.annotateLogs(Report.failure("wardic.projection: a scale corrector failed", Cause.die(defect)), { id: node.id, key: corrector.key }))
2102
+ }
2103
+
2062
2104
  /** An app's corrector's value for `node` (#443): its own for the key, a number or a string, else its base, else none. */
2063
2105
  const latestFor = (node: NodeState, corrector: CustomCorrector, values: Readonly<Record<string, unknown>>): string | number | undefined => {
2064
2106
  const own = values[corrector.key]
@@ -3597,7 +3639,7 @@ export const makeProjectionSystem = (
3597
3639
  UndefinedOr.match(wrapperLinkOf(child, twin.shift), { onUndefined: () => links, onDefined: (link) => withLink(links, link, child) }),
3598
3640
  ),
3599
3641
  })
3600
- const follower = makeLeavingNode(leaver.element, layoutId, last, undefined, undefined, chain)
3642
+ const follower = makeLeavingNode(leaver.id, leaver.element, layoutId, last, undefined, undefined, chain)
3601
3643
  follower.fade = readOpacity(leaver.element)
3602
3644
  addNode(follower)
3603
3645
  elementToNode.set(leaver.element, follower)
@@ -3629,7 +3671,7 @@ export const makeProjectionSystem = (
3629
3671
  const holdNode = (node: NodeState): void => {
3630
3672
  const last = lastPassOf(node)
3631
3673
  if (Predicate.isUndefined(last)) return
3632
- hold({ element: node.element, last, layoutAnchor: node.layoutAnchor, twin: undefined, reintroduced: false, pastTask: false })
3674
+ hold({ id: node.id, element: node.element, last, layoutAnchor: node.layoutAnchor, twin: undefined, reintroduced: false, pastTask: false })
3633
3675
  }
3634
3676
 
3635
3677
  /**
@@ -3648,7 +3690,7 @@ export const makeProjectionSystem = (
3648
3690
  // Seen as it goes, at the page's scroll now (#480): a scroll after, a router's at a navigation, comes out.
3649
3691
  const seed = UndefinedOr.map(seedBox, (box) => seedOf(node, layoutId, box, look, measureDocumentScroll()))
3650
3692
  if (Predicate.isUndefined(last) && Predicate.isUndefined(seedBox)) return
3651
- hold({ element: node.element, last, layoutAnchor: node.layoutAnchor, twin: { layoutId, chain: node.paintChain, shift, seed }, reintroduced: false, pastTask: false })
3693
+ hold({ id: node.id, element: node.element, last, layoutAnchor: node.layoutAnchor, twin: { layoutId, chain: node.paintChain, shift, seed }, reintroduced: false, pastTask: false })
3652
3694
  }
3653
3695
 
3654
3696
  /**
@@ -3764,12 +3806,13 @@ export const makeProjectionSystem = (
3764
3806
  /** The nodes a Measure round measured that have an `onLayoutMeasure` (#443), told at its end. Reused: most rounds tell none. */
3765
3807
  const measuredNow: Array<{ readonly node: NodeState; readonly box: Box.Box; readonly prev: Box.Box | undefined }> = []
3766
3808
 
3767
- /** Call an app's measure hook (#443): a throw is reported, and the pass goes on. */
3768
- const callMeasureHook = (hook: () => void, name: string): void => {
3809
+ /** Call `node`'s measure hook `name` (#443): a throw is reported at its run's first, and the pass goes on. */
3810
+ const callMeasureHook = (node: NodeState, hook: () => void, name: "onBeforeLayoutMeasure" | "onLayoutMeasure"): void => {
3769
3811
  try {
3770
3812
  hook()
3813
+ Failing.endRunOf(node, name)
3771
3814
  } catch (defect) {
3772
- runtime.runFork(Report.failure(`wardic.projection: an ${name} failed`, Cause.die(defect)))
3815
+ if (Failing.firstThrowOf(node, name)) runtime.runFork(Report.failure(`wardic.projection: an ${name} failed`, Cause.die(defect)))
3773
3816
  }
3774
3817
  }
3775
3818
 
@@ -3812,9 +3855,26 @@ export const makeProjectionSystem = (
3812
3855
  const savedTransforms: Array<string | undefined> = []
3813
3856
  for (const node of ordered) {
3814
3857
  // Its app's `onBeforeLayoutMeasure` (#443), before its transform is held for the read.
3815
- if (Predicate.isNotUndefined(node.onBeforeMeasure)) callMeasureHook(node.onBeforeMeasure, "onBeforeLayoutMeasure")
3858
+ if (Predicate.isNotUndefined(node.onBeforeMeasure)) callMeasureHook(node, node.onBeforeMeasure, "onBeforeLayoutMeasure")
3816
3859
  const own = node.element.style.transform
3817
- const held = heldTransformFor(node)
3860
+ // Its Transform template's, `none` for a node with none (Motion's `resetTransform`), which is
3861
+ // what an at-rest node already draws (#674). Per pass per node: a field read.
3862
+ let held = "none"
3863
+ const template = node.heldTransform
3864
+ // #979, row 13 (ADR-0074): the app's template is its node's own. One that throws holds its node
3865
+ // where its last call did, so a static part of it is still measured, and the pass goes on:
3866
+ // before, the throw ended it here, every node held before it left held and nothing seeded.
3867
+ if (Predicate.isNotUndefined(template)) {
3868
+ try {
3869
+ held = template()
3870
+ node.lastHeld = held
3871
+ if (node.heldFailing) node.heldFailing = false
3872
+ } catch (defect) {
3873
+ if (!node.heldFailing) runtime.runFork(Effect.annotateLogs(Report.failure("wardic.projection: a transformTemplate failed at a Measure pass", Cause.die(defect)), { id: node.id }))
3874
+ node.heldFailing = true
3875
+ held = node.lastHeld
3876
+ }
3877
+ }
3818
3878
  // A server's Appear animation not yet handed off (#245, ADR-0044 *Amendment (#245)*): its CSS
3819
3879
  // transform beats an inline one, but not an important one. Its timeline runs on; the restore
3820
3880
  // below gives the old value back, at its own priority.
@@ -4011,6 +4071,11 @@ export const makeProjectionSystem = (
4011
4071
  // --- WRITE: FLIP detection + seeding, on the already-measured boxes. ------
4012
4072
  for (let i = 0; i < ordered.length; i++) {
4013
4073
  const node = ordered[i]
4074
+ // A node never measured whose element isn't on the page yet (#1024): held off it by a boundary
4075
+ // that waits, as a Solid 2 `<Loading>` holds an element whose ward was made outside it, it reads
4076
+ // 0x0 at the viewport's origin, and a later pass would grow it from there. It's left unmeasured:
4077
+ // its first box is the one a pass reads once it's on the page, which doesn't animate.
4078
+ if (Bool.and(Predicate.isUndefined(node.retained), Bool.not(node.element.isConnected))) continue
4014
4079
  // A `display: contents` element has no box (ADR-0009 *Amendment (#9)*): its rect is 0x0 at
4015
4080
  // the viewport's origin, which a scroll would read as a move. It never animates or carries a
4016
4081
  // delta, and what it holds projects as if it weren't there.
@@ -4268,7 +4333,7 @@ export const makeProjectionSystem = (
4268
4333
  if (measuredNow.length > 0) {
4269
4334
  for (const { node, box, prev } of measuredNow.splice(0)) {
4270
4335
  const tell = node.onMeasure
4271
- if (Predicate.isNotUndefined(tell)) callMeasureHook(() => tell(box, Option.fromUndefinedOr(prev)), "onLayoutMeasure")
4336
+ if (Predicate.isNotUndefined(tell)) callMeasureHook(node, () => tell(box, Option.fromUndefinedOr(prev)), "onLayoutMeasure")
4272
4337
  }
4273
4338
  }
4274
4339
  deriveGroup(groupOf(changed))
@@ -4400,7 +4465,7 @@ export const makeProjectionSystem = (
4400
4465
  inAfterTickStep = false
4401
4466
  }
4402
4467
  if (Arr.isArrayNonEmpty(flightStarts)) {
4403
- for (const node of flightStarts.splice(0)) callAppIfAny(node.onLayoutAnimationStart(), "onLayoutAnimationStart")
4468
+ for (const node of flightStarts.splice(0)) callAppIfAny(node, node.onLayoutAnimationStart, "onLayoutAnimationStart")
4404
4469
  }
4405
4470
  return stepped.size
4406
4471
  }
@@ -4437,6 +4502,7 @@ export const makeProjectionSystem = (
4437
4502
  }
4438
4503
 
4439
4504
  /** Call an app's `callback` (#191): one that throws is reported, and the engine goes on. */
4505
+ // Each time: an `onSettled` is called once (#979 group I, ADR-0074 decision 3).
4440
4506
  const callApp = (callback: () => void, name: string): void => {
4441
4507
  try {
4442
4508
  callback()
@@ -4445,9 +4511,22 @@ export const makeProjectionSystem = (
4445
4511
  }
4446
4512
  }
4447
4513
 
4448
- /** The app's callback, if it gave one: called as {@link callApp} calls it. */
4449
- const callAppIfAny = (callback: Option.Option<() => void>, name: string): void => {
4450
- if (Option.isSome(callback)) callApp(callback.value, name)
4514
+ /**
4515
+ * `node`'s app callback `name`, read from `callbackOf` and called if it gave one: a throw from either is
4516
+ * reported at the first of a run of its throws, its next clean call ending the run, and the engine goes on.
4517
+ */
4518
+ // #191; once a run, #979 group I (row 29). The read in the try too (ADR-0074's open list): a binding's
4519
+ // getter can be the app's config (Solid 1's `createWard` accessor), and one that threw came out of the
4520
+ // tick's hook, the nodes after it in the tick's list missing their callbacks.
4521
+ const callAppIfAny = (node: NodeState, callbackOf: () => Option.Option<() => void>, name: LayoutCallbackName): void => {
4522
+ try {
4523
+ const callback = callbackOf()
4524
+ if (Option.isNone(callback)) return
4525
+ callback.value()
4526
+ Failing.endRunOf(node, name)
4527
+ } catch (defect) {
4528
+ if (Failing.firstThrowOf(node, name)) runtime.runFork(Report.failure(`wardic.projection: ${name} failed`, Cause.die(defect)))
4529
+ }
4451
4530
  }
4452
4531
 
4453
4532
  /** Whether `flight` still runs on `node`: not landed, not replaced by a restart, not cut short, not unmounted. */
@@ -4497,13 +4576,13 @@ export const makeProjectionSystem = (
4497
4576
  tickFrame = frameTime()
4498
4577
  tickDt = dt
4499
4578
  if (Arr.isArrayNonEmpty(flightStarts)) {
4500
- for (const node of flightStarts.splice(0)) callAppIfAny(node.onLayoutAnimationStart(), "onLayoutAnimationStart")
4579
+ for (const node of flightStarts.splice(0)) callAppIfAny(node, node.onLayoutAnimationStart, "onLayoutAnimationStart")
4501
4580
  }
4502
4581
  if (Arr.isArrayNonEmpty(flightLands)) {
4503
- for (const node of flightLands.splice(0)) callAppIfAny(node.onLayoutAnimationComplete(), "onLayoutAnimationComplete")
4582
+ for (const node of flightLands.splice(0)) callAppIfAny(node, node.onLayoutAnimationComplete, "onLayoutAnimationComplete")
4504
4583
  }
4505
4584
  if (Arr.isArrayNonEmpty(releaseEnds)) {
4506
- for (const node of releaseEnds.splice(0)) callAppIfAny(node.onReleaseEnd(), "onDragTransitionEnd")
4585
+ for (const node of releaseEnds.splice(0)) callAppIfAny(node, node.onReleaseEnd, "onDragTransitionEnd")
4507
4586
  }
4508
4587
  checkSettlings()
4509
4588
  return undefined
@@ -4780,7 +4859,17 @@ export const makeProjectionSystem = (
4780
4859
  const active = flight.elapsed - timing.delay
4781
4860
  if (active < 0) return false
4782
4861
  const t = Math.min(1, active / timing.duration)
4783
- flight.position = timing.ease(t)
4862
+ // #979, row 5 (ADR-0074): the app's ease is its node's own. One that throws leaves the node where
4863
+ // its last ease put it, landing on its target on time, and the coordinator's other nodes go on:
4864
+ // before, it failed the coordinator's run, so every layout animation stopped.
4865
+ try {
4866
+ flight.position = timing.ease(t)
4867
+ if (node.easeFailing) node.easeFailing = false
4868
+ } catch (defect) {
4869
+ if (!node.easeFailing) runtime.runFork(Effect.annotateLogs(Report.failure("wardic.projection: a layout animation's ease failed", Cause.die(defect)), { id: node.id }))
4870
+ node.easeFailing = true
4871
+ if (t >= 1) flight.position = 1
4872
+ }
4784
4873
  return t >= 1
4785
4874
  }
4786
4875
 
@@ -5156,9 +5245,10 @@ export const makeProjectionSystem = (
5156
5245
  /**
5157
5246
  * The coordinator's end, told apart (ADR-0027, decision 7): a settle, or an
5158
5247
  * interruption (a stop outside its step, the system's dispose), is nothing; anything
5159
- * else (a step that threw, the Frame loop's own failure) is logged and reported
5248
+ * else (a step whose own code threw, the Frame loop's own failure) is logged and reported
5160
5249
  * (`Report.failure`, ADR-0030 decision 4). Its nodes then wait where the last step left
5161
- * them, and the next trigger starts a fresh run.
5250
+ * them, and the next trigger starts a fresh run. An app's code on the step is its node's
5251
+ * own, caught where it's called (#979, row 5), so it never ends the run.
5162
5252
  */
5163
5253
  const coordinatorEnded = (exit: Exit.Exit<unknown>): Effect.Effect<void> =>
5164
5254
  Exit.match(exit, {
@@ -5300,6 +5390,7 @@ export const makeProjectionSystem = (
5300
5390
  * its last pass.
5301
5391
  */
5302
5392
  const makeLeavingNode = (
5393
+ id: string,
5303
5394
  el: HTMLElement,
5304
5395
  layoutId: string | undefined,
5305
5396
  recent: LastPass,
@@ -5307,7 +5398,8 @@ export const makeProjectionSystem = (
5307
5398
  layoutAnchor: Point.Point | false | undefined,
5308
5399
  chain: ReadonlyArray<PaintLink> | undefined,
5309
5400
  ): NodeState => ({
5310
- id: "", // a leaving Follower is driven via the Renderer, not the gate — no id needed
5401
+ // Driven through the Renderer, not the gate: its id names it in its reports alone.
5402
+ id,
5311
5403
  element: el,
5312
5404
  transition: Option.none,
5313
5405
  path: Option.none,
@@ -5327,6 +5419,7 @@ export const makeProjectionSystem = (
5327
5419
  heldTransform: undefined,
5328
5420
  onBeforeMeasure: undefined,
5329
5421
  onMeasure: undefined,
5422
+ failing: undefined,
5330
5423
  blend: undefined,
5331
5424
  seedBlend: undefined,
5332
5425
  seedScroll: undefined,
@@ -5360,6 +5453,11 @@ export const makeProjectionSystem = (
5360
5453
  corrected: false,
5361
5454
  customBases: readCustomBases(el),
5362
5455
  customCorrected: false,
5456
+ easeFailing: false,
5457
+ failingCorrectors: undefined,
5458
+ writeFailing: false,
5459
+ heldFailing: false,
5460
+ lastHeld: "none",
5363
5461
  isScroll: false,
5364
5462
  scroll: { x: 0, y: 0 },
5365
5463
  isScrollRoot: false,
@@ -5441,7 +5539,7 @@ export const makeProjectionSystem = (
5441
5539
  if (Predicate.isUndefined(last)) return false
5442
5540
  const stack = stacks.get(layoutId)
5443
5541
  if (Predicate.isUndefined(stack)) return false
5444
- const follower = makeLeavingNode(el, layoutId, last, onDone, undefined, undefined)
5542
+ const follower = makeLeavingNode(recent.id, el, layoutId, last, onDone, undefined, undefined)
5445
5543
  recent.reintroduced = true
5446
5544
  addNode(follower)
5447
5545
  elementToNode.set(el, follower)
@@ -5516,7 +5614,7 @@ export const makeProjectionSystem = (
5516
5614
  // Not onto a Lead that is leaving itself (#682): it has no handover to ride.
5517
5615
  if (lead.leaving) return
5518
5616
  if (Bool.not(takesOver(lead))) return
5519
- const twin = makeLeavingNode(inner, held.layoutId, last, () => undefined, undefined, chainOf(held))
5617
+ const twin = makeLeavingNode(recent.id, inner, held.layoutId, last, () => undefined, undefined, chainOf(held))
5520
5618
  recent.reintroduced = true
5521
5619
  addNode(twin)
5522
5620
  elementToNode.set(inner, twin)
@@ -5539,7 +5637,7 @@ export const makeProjectionSystem = (
5539
5637
  if (recent.reintroduced) return
5540
5638
  if (Bool.not(contains(container, inner))) return
5541
5639
  recent.reintroduced = true
5542
- const node = makeLeavingNode(inner, undefined, last, undefined, recent.layoutAnchor, undefined)
5640
+ const node = makeLeavingNode(recent.id, inner, undefined, last, undefined, recent.layoutAnchor, undefined)
5543
5641
  addNode(node)
5544
5642
  elementToNode.set(inner, node)
5545
5643
  carried.push(node)
@@ -5870,6 +5968,7 @@ export const makeProjectionSystem = (
5870
5968
  heldTransform: opts.heldTransform,
5871
5969
  onBeforeMeasure: opts.onBeforeMeasure,
5872
5970
  onMeasure: opts.onMeasure,
5971
+ failing: undefined,
5873
5972
  blend: undefined,
5874
5973
  seedBlend: undefined,
5875
5974
  seedScroll: undefined,
@@ -5903,6 +6002,11 @@ export const makeProjectionSystem = (
5903
6002
  corrected: false,
5904
6003
  customBases: undefined,
5905
6004
  customCorrected: false,
6005
+ easeFailing: false,
6006
+ failingCorrectors: undefined,
6007
+ writeFailing: false,
6008
+ heldFailing: false,
6009
+ lastHeld: "none",
5906
6010
  isScroll: opts.layoutScroll === true,
5907
6011
  scroll: { x: 0, y: 0 },
5908
6012
  isScrollRoot: false,
@@ -6069,7 +6173,7 @@ export const makeProjectionSystem = (
6069
6173
  if (active.size === 0) stopTicking()
6070
6174
  // No release runs, so it has ended (#273): told from a microtask, as Motion's instant one resolves.
6071
6175
  queueMicrotask(() => {
6072
- if (nodes.has(node)) callAppIfAny(node.onReleaseEnd(), "onDragTransitionEnd")
6176
+ if (nodes.has(node)) callAppIfAny(node, node.onReleaseEnd, "onDragTransitionEnd")
6073
6177
  })
6074
6178
  return
6075
6179
  }