@wardic/dom 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 (143) 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 +32 -16
  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 +27 -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 +28 -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 +180 -46
  49. package/dist/internal/projection.js.map +1 -1
  50. package/dist/internal/renderer.d.ts +59 -27
  51. package/dist/internal/renderer.d.ts.map +1 -1
  52. package/dist/internal/renderer.js +241 -207
  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/starting-style.js +5 -5
  58. package/dist/internal/transform-keys.d.ts +23 -0
  59. package/dist/internal/transform-keys.d.ts.map +1 -0
  60. package/dist/internal/transform-keys.js +55 -0
  61. package/dist/internal/transform-keys.js.map +1 -0
  62. package/dist/unstable/AppearAnimations.d.ts +2 -1
  63. package/dist/unstable/AppearAnimations.d.ts.map +1 -1
  64. package/dist/unstable/AppearAnimations.js +73 -22
  65. package/dist/unstable/AppearAnimations.js.map +1 -1
  66. package/dist/unstable/BatchMembers.d.ts +2 -2
  67. package/dist/unstable/BatchMembers.d.ts.map +1 -1
  68. package/dist/unstable/BatchMembers.js +30 -7
  69. package/dist/unstable/BatchMembers.js.map +1 -1
  70. package/dist/unstable/DomValues.js +1 -1
  71. package/dist/unstable/DomValues.js.map +1 -1
  72. package/dist/unstable/DragTrack.d.ts +2 -2
  73. package/dist/unstable/DragTrack.d.ts.map +1 -1
  74. package/dist/unstable/DragTrack.js +37 -10
  75. package/dist/unstable/DragTrack.js.map +1 -1
  76. package/dist/unstable/ElementSetup.d.ts.map +1 -1
  77. package/dist/unstable/ElementSetup.js +3 -2
  78. package/dist/unstable/ElementSetup.js.map +1 -1
  79. package/dist/unstable/GestureFeatures.d.ts +8 -2
  80. package/dist/unstable/GestureFeatures.d.ts.map +1 -1
  81. package/dist/unstable/GestureFeatures.js +26 -40
  82. package/dist/unstable/GestureFeatures.js.map +1 -1
  83. package/dist/unstable/GestureInfo.d.ts +11 -0
  84. package/dist/unstable/GestureInfo.d.ts.map +1 -1
  85. package/dist/unstable/GestureInfo.js +8 -0
  86. package/dist/unstable/GestureInfo.js.map +1 -1
  87. package/dist/unstable/Imperative.d.ts +1 -1
  88. package/dist/unstable/Imperative.d.ts.map +1 -1
  89. package/dist/unstable/Imperative.js.map +1 -1
  90. package/dist/unstable/LiveStyle.d.ts +28 -2
  91. package/dist/unstable/LiveStyle.d.ts.map +1 -1
  92. package/dist/unstable/LiveStyle.js +8 -32
  93. package/dist/unstable/LiveStyle.js.map +1 -1
  94. package/dist/unstable/MemberHold.js +3 -3
  95. package/dist/unstable/MemberHold.js.map +1 -1
  96. package/dist/unstable/PointerValues.d.ts.map +1 -1
  97. package/dist/unstable/PointerValues.js +82 -8
  98. package/dist/unstable/PointerValues.js.map +1 -1
  99. package/dist/unstable/PresenceController.d.ts +5 -2
  100. package/dist/unstable/PresenceController.d.ts.map +1 -1
  101. package/dist/unstable/PresenceController.js +82 -55
  102. package/dist/unstable/PresenceController.js.map +1 -1
  103. package/dist/unstable/ReorderInput.d.ts +2 -2
  104. package/dist/unstable/ReorderInput.js +2 -2
  105. package/dist/unstable/WardConfig.d.ts +18 -9
  106. package/dist/unstable/WardConfig.d.ts.map +1 -1
  107. package/dist/unstable/WardConfig.js.map +1 -1
  108. package/dist/unstable/features/TimelineKeys.d.ts.map +1 -1
  109. package/dist/unstable/features/TimelineKeys.js +19 -3
  110. package/dist/unstable/features/TimelineKeys.js.map +1 -1
  111. package/package.json +3 -3
  112. package/src/MeasuredPair.ts +21 -1
  113. package/src/index.ts +4 -1
  114. package/src/internal/appear.ts +20 -2
  115. package/src/internal/batch-handoff.ts +19 -11
  116. package/src/internal/batch-writer.ts +32 -16
  117. package/src/internal/clock.ts +28 -0
  118. package/src/internal/default-transition.ts +28 -4
  119. package/src/internal/failing.ts +37 -0
  120. package/src/internal/length-keys.ts +80 -0
  121. package/src/internal/measured-pairs.ts +58 -22
  122. package/src/internal/own-values.ts +2 -2
  123. package/src/internal/positional-keys.ts +4 -2
  124. package/src/internal/projection.ts +190 -44
  125. package/src/internal/renderer.ts +272 -198
  126. package/src/internal/scroll.ts +24 -2
  127. package/src/internal/starting-style.ts +5 -5
  128. package/src/internal/transform-keys.ts +59 -0
  129. package/src/unstable/AppearAnimations.ts +73 -24
  130. package/src/unstable/BatchMembers.ts +33 -9
  131. package/src/unstable/DomValues.ts +1 -1
  132. package/src/unstable/DragTrack.ts +49 -14
  133. package/src/unstable/ElementSetup.ts +3 -2
  134. package/src/unstable/GestureFeatures.ts +38 -47
  135. package/src/unstable/GestureInfo.ts +24 -0
  136. package/src/unstable/Imperative.ts +1 -0
  137. package/src/unstable/LiveStyle.ts +12 -8
  138. package/src/unstable/MemberHold.ts +3 -3
  139. package/src/unstable/PointerValues.ts +73 -8
  140. package/src/unstable/PresenceController.ts +80 -54
  141. package/src/unstable/ReorderInput.ts +2 -2
  142. package/src/unstable/WardConfig.ts +22 -10
  143. package/src/unstable/features/TimelineKeys.ts +20 -3
@@ -28,8 +28,10 @@
28
28
  */
29
29
  import * as ScrollSource from "@wardic/core/ScrollSource"
30
30
  import * as SharedSource from "@wardic/core/SharedSource"
31
+ import * as Report from "@wardic/core/unstable/Report"
31
32
  import * as Arr from "effect/Array"
32
33
  import * as Bool from "effect/Boolean"
34
+ import * as Cause from "effect/Cause"
33
35
  import * as Effect from "effect/Effect"
34
36
  import { identity } from "effect/Function"
35
37
  import * as Iter from "effect/Iterable"
@@ -329,9 +331,18 @@ const open = (element: Element): Container => {
329
331
  return container
330
332
  }
331
333
 
332
- /** A reader of a container's scroll: the container's listeners held from `containers` while its Scope is open. */
334
+ /** A reader's Atom whose dependent threw as it was set: an app's Atom over the scroll, say. */
335
+ const DEPENDENT_FAILED = "wardic.scroll: its dependent failed"
336
+
337
+ /**
338
+ * A reader of a container's scroll: the container's listeners held from `containers` while its Scope is
339
+ * open, a failure reported on the context it's read in.
340
+ */
333
341
  const readerOf = (registry: AtomRegistry.AtomRegistry, containers: (element: Element) => Effect.Effect<Container, never, Scope.Scope>) =>
334
342
  Effect.fnUntraced(function* (options: ScrollSource.Options = {}) {
343
+ // Where its failure is reported (#979, row 14): the reader's, a provider's runtime with the app's
344
+ // logger, which a source's own build never sees (an app's layers sit beside it).
345
+ const context = yield* Effect.context<never>()
335
346
  const element = UndefinedOr.match(options.container as Element | undefined, { onUndefined: pageOf, onDefined: (given) => given })
336
347
  const container = yield* containers(element)
337
348
  const measure = measureOf(element, options)
@@ -339,11 +350,22 @@ const readerOf = (registry: AtomRegistry.AtomRegistry, containers: (element: Ele
339
350
  // Mounted while read, not kept alive: a kept-alive Atom's node never leaves the registry.
340
351
  const atom = Atom.make(last)
341
352
  const unmount = registry.mount(atom)
353
+ // #979, row 14 (ADR-0074): a dependent of its Atom that throws, an app's Atom over the scroll, is this
354
+ // reader's own: the Atom holds the scroll, and the container's later readers still hear the event.
355
+ // Before, the throw stopped the container's listener there, uncaught, every event. Reported once a
356
+ // run of throws, its flag cleared only when it's set.
357
+ let failing = false
342
358
  const read = (): void => {
343
359
  const next = measure()
344
360
  if (sameScroll(last, next)) return
345
361
  last = next
346
- registry.set(atom, next)
362
+ try {
363
+ registry.set(atom, next)
364
+ if (failing) failing = false
365
+ } catch (defect) {
366
+ if (!failing) Report.failureOn(context, DEPENDENT_FAILED, Cause.die(defect))
367
+ failing = true
368
+ }
347
369
  }
348
370
  yield* Effect.acquireRelease(
349
371
  Effect.sync(() => container.readers.add(read)),
@@ -86,14 +86,14 @@ export type StyleRecord = Readonly<Record<string, unknown>>
86
86
 
87
87
  /** A style given as CSS text, parsed; a record as it is. */
88
88
  const recordOf = (input: object | string): StyleRecord => {
89
- // Per element at mount (#540): statements.
89
+ // Per Subject at mount (#540): statements.
90
90
  if (Predicate.isString(input)) return parseCssText(input)
91
91
  return input as StyleRecord
92
92
  }
93
93
 
94
94
  /** A style given as CSS text, parsed; a record as it is; none, an empty record. */
95
95
  const recordOfInput = (input: StyleInput): StyleRecord => {
96
- // Per element at mount (#540): statements.
96
+ // Per Subject at mount (#540): statements.
97
97
  if (Predicate.isUndefined(input)) return {}
98
98
  return recordOf(input)
99
99
  }
@@ -135,7 +135,7 @@ export const over: {
135
135
  (that: StyleInput): (self: StyleInput) => StyleRecord
136
136
  (self: StyleInput, that: StyleInput): StyleRecord
137
137
  } = dual(2, (self: StyleInput, that: StyleInput): StyleRecord => {
138
- // Per element at mount (#540): statements.
138
+ // Per Subject at mount (#540): statements.
139
139
  if (Predicate.isUndefined(that)) return recordOfInput(self)
140
140
  if (Predicate.isUndefined(self)) return recordOf(that)
141
141
  return layered(recordOf(self), recordOf(that))
@@ -143,7 +143,7 @@ export const over: {
143
143
 
144
144
  /** Whether `key`, a CSS property, is one of the gate's held patch keys: by its name, or its name dash-cased. */
145
145
  const isHeld = (held: ReadonlyArray<string>, key: string): boolean => {
146
- // Per element at mount (#540): a loop.
146
+ // Per Subject at mount (#540): a loop.
147
147
  for (const patchKey of held) {
148
148
  if (patchKey === key || dashCase(patchKey) === key) return true
149
149
  }
@@ -163,7 +163,7 @@ export const without: {
163
163
  (held: ReadonlyArray<string>): (self: StyleInput) => StyleRecord
164
164
  (self: StyleInput, held: ReadonlyArray<string>): StyleRecord
165
165
  } = dual(2, (self: StyleInput, held: ReadonlyArray<string>): StyleRecord => {
166
- // Per element at mount (#540): a loop.
166
+ // Per Subject at mount (#540): a loop.
167
167
  const record = recordOfInput(self)
168
168
  const out: Record<string, unknown> = {}
169
169
  for (const key of Object.keys(record)) {
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The DOM's transform keys, each with its identity: core's (`BaseValue.TRANSFORM_IDENTITY`), and the DOM's
3
+ * own, which no other Environment draws as the DOM does: `translateX`, `translateY` and `translateZ` beside
4
+ * `x`, `y` and `z`, the turn in the page's plane (`rotate`), the skews and the element's own depth
5
+ * (`transformPerspective`). Every DOM reader of a transform key reads this table, so the DOM's own keys
6
+ * are transforms to each of them: the renderer, Own values, a Batch's members, Appear, reduced motion and
7
+ * the Default transition.
8
+ *
9
+ * @module
10
+ */
11
+ // #887 (ADR-0073, *Amendment (#887)*, Q1): core names no key only the page draws. As `positional-keys.ts`
12
+ // adds the box's keys to core's transforms, this adds the DOM's own transform keys to core's: the depth
13
+ // (#887), and the six core named until #1002 (ADR-0073, *Amendment (#1002)*), Motion's names, which came
14
+ // over with its list in #47. TK1 pins that no dom source reads core's table but this module.
15
+ import * as BaseValue from "@wardic/core/BaseValue"
16
+ import * as Option from "effect/Option"
17
+ import * as Predicate from "effect/Predicate"
18
+ import * as Rec from "effect/Record"
19
+
20
+ /** An element's own depth, Motion's key: `perspective()` at the head of its transform, in px. */
21
+ export const PERSPECTIVE = "transformPerspective"
22
+
23
+ /**
24
+ * Each of the DOM's transform keys, with its identity: core's, and the DOM's own 0s, no translation, turn
25
+ * or skew. {@link PERSPECTIVE}'s 0 is no perspective, not a depth: it's left out of the transform, as
26
+ * Motion's is.
27
+ */
28
+ export const TRANSFORM_IDENTITY: Readonly<Record<string, number>> = Object.freeze({
29
+ ...BaseValue.TRANSFORM_IDENTITY,
30
+ translateX: 0,
31
+ translateY: 0,
32
+ translateZ: 0,
33
+ rotate: 0,
34
+ skewX: 0,
35
+ skewY: 0,
36
+ [PERSPECTIVE]: 0,
37
+ })
38
+
39
+ /** A DOM transform key's identity (see {@link TRANSFORM_IDENTITY}), or `None` for any other key, prototype names included. */
40
+ export const transformIdentity = (key: string): Option.Option<number> => Rec.get(TRANSFORM_IDENTITY, key)
41
+
42
+ /** The DOM's transform keys, for a membership test a frame can make. */
43
+ export const TRANSFORM_KEYS: ReadonlySet<string> = new Set(Object.keys(TRANSFORM_IDENTITY))
44
+
45
+ /** Whether `key` is one of the DOM's transform keys. */
46
+ export const isTransformKey = (key: string): boolean => TRANSFORM_KEYS.has(key)
47
+
48
+ /**
49
+ * Whether the element's own depth draws a `perspective()`: above its identity, 0, which is no
50
+ * perspective. A depth below 0 isn't drawn either: CSS refuses a negative `perspective()`, and the whole
51
+ * `transform` with it, so a spring's overshoot past 0 draws no perspective. A string is read as Motion
52
+ * reads one, by `parseFloat`, and drawn when it can't be read (`var(--d)`). Per frame: statements.
53
+ */
54
+ // #887 (ADR-0073, *Amendment (#887)*, Q3): the renderer's, a projected element's and a Batch member's.
55
+ export const drawsDepth = (value: unknown): boolean => {
56
+ if (Predicate.isNumber(value)) return value > 0
57
+ const read = Number.parseFloat(String(value))
58
+ return Number.isNaN(read) || read > 0
59
+ }
@@ -47,6 +47,8 @@ import * as AppearHandoff from "@wardic/core/unstable/AppearHandoff"
47
47
  import type * as WardConfig from "./WardConfig.ts"
48
48
  import * as RetargetLegs from "@wardic/core/unstable/RetargetLegs"
49
49
  import * as ServerInterpolators from "./ServerInterpolators.ts"
50
+ import { DEPTH_MOVES_REASON } from "../internal/appear.ts"
51
+ import * as TransformKeys from "../internal/transform-keys.ts"
50
52
  import type * as VariantTarget from "@wardic/core/unstable/VariantTarget"
51
53
  import * as VariantTree from "@wardic/core/unstable/VariantTree"
52
54
 
@@ -109,7 +111,8 @@ const baseKeys = /*#__PURE__*/ new WeakMap<Values.Values, Option.Option<string>>
109
111
  */
110
112
  export const keyOf = (m: AppearHandoff.MountAnimation): Option.Option<string> => {
111
113
  const base = Option.getOrElse(Option.fromUndefinedOr(baseKeys.get(m.from)), () => {
112
- const computed = canonical({ from: m.from, to: m.to, transition: keyedTransitionOf(m), stops: m.stops })
114
+ // Its held keys (#1004) only when it holds any, so every other key's text is as it was.
115
+ const computed = canonical({ from: m.from, to: m.to, transition: keyedTransitionOf(m), stops: m.stops, ...UndefinedOr.match(heldOf(m), { onUndefined: () => ({}), onDefined: (held) => ({ held }) }) })
113
116
  baseKeys.set(m.from, computed)
114
117
  return computed
115
118
  })
@@ -142,10 +145,11 @@ const sampledTransition = (transition: WardConfig.WardicTransition | undefined):
142
145
 
143
146
  /**
144
147
  * One machine of a Retarget's legs, run together: each step steps every leg not yet settled, and
145
- * merges their values; it settles with the last. What a server samples. Built with the DOM's
148
+ * merges their values over `held`, the keys it holds where they are; it settles with the last. What a
149
+ * server samples. Built with the DOM's
146
150
  * Interpolators (a server projects with the DOM's `project`, ADR-0021 decision 2).
147
151
  */
148
- const together = (legs: ReadonlyArray<RetargetLegs.Leg>): Machine.Machine<Frame.Frame<Values.Values>> => {
152
+ const together = (legs: ReadonlyArray<RetargetLegs.Leg>, held: Values.Values | undefined): Machine.Machine<Frame.Frame<Values.Values>> => {
149
153
  const machines = Effect.runSync(
150
154
  ServerInterpolators.withServerInterpolators(Effect.all(Arr.map(legs, (leg): Effect.Effect<Machine.Machine<Frame.Frame<unknown>>, never, InterpolatorRegistry.InterpolatorRegistry> => machineOfLeg(leg)))),
151
155
  )
@@ -155,7 +159,7 @@ const together = (legs: ReadonlyArray<RetargetLegs.Leg>): Machine.Machine<Frame.
155
159
  start: () => {
156
160
  const runs = Arr.map(machines, (machine, i) => ({ step: machine.start(), key: keyOfLeg(legs[i] as RetargetLegs.Leg), last: Option.none<Frame.Frame<unknown>>() }))
157
161
  return (dt) => {
158
- const value: Record<string, number | string> = {}
162
+ const value: Record<string, number | string> = { ...held }
159
163
  const done = Arr.reduce(runs, true, (all, run) => {
160
164
  const frame = Option.getOrElse(Option.filter(run.last, (last) => last.done), () => run.step(dt))
161
165
  run.last = Option.some(frame)
@@ -201,6 +205,25 @@ const foreverByValue = (m: AppearHandoff.MountAnimation): boolean => {
201
205
  return Bool.or(AppearHandoff.repeatsForever(m.transition), Arr.some(runsOn, AppearHandoff.repeatsForever))
202
206
  }
203
207
 
208
+ /**
209
+ * The keys a mount animation's rule holds in every stop: its transform keys left where they are, when its
210
+ * rule writes a `transform`, which replaces the element's whole: beside a moving transform key, and in
211
+ * every stop of a layout node's, drawn through its projection, and of a templated element's. `undefined`
212
+ * with none, and when the rule writes no `transform`, the element's own style holding them.
213
+ */
214
+ // #1004 (ADR-0044, *Amendment (#1004)*): one left out jumped while the CSS played, and back at the Handoff.
215
+ const heldOf = (m: AppearHandoff.MountAnimation): Values.Values | undefined => {
216
+ if (Predicate.isUndefined(m.held)) return undefined
217
+ if (Bool.not(writesTransform(m))) return undefined
218
+ const held = Rec.filter(m.held, (_, key) => TransformKeys.isTransformKey(key))
219
+ if (Rec.isEmptyRecord(held)) return undefined
220
+ return held
221
+ }
222
+
223
+ /** Whether a mount animation's rule writes a `transform` in its stops: a transform key moves, or it's a layout node's or a templated element's. */
224
+ const writesTransform = (m: AppearHandoff.MountAnimation): boolean =>
225
+ Bool.or(Bool.or(m.layout, Predicate.isNotUndefined(m.template)), Arr.some(Rec.keys(m.to), TransformKeys.isTransformKey))
226
+
204
227
  /** A mount animation's spec for the DOM's sampler, or why it has none. */
205
228
  export const specOf = (m: AppearHandoff.MountAnimation): Result.Result<Appear.Spec, string> =>
206
229
  Option.match(keyOf(m), {
@@ -218,11 +241,12 @@ export const specOf = (m: AppearHandoff.MountAnimation): Result.Result<Appear.Sp
218
241
  projected: m.layout,
219
242
  template: m.template,
220
243
  // Skipped (#468): every key's snap, landing on its first frame, a rule of 0 s.
221
- machine: () =>
222
- Bool.match(forever, {
223
- onTrue: () => Machine.holdAfter(together(RetargetLegs.legsOf(m.from, m.to, transition, m.reduced, skipped, DOM_POSITIONAL, DOM_DEFAULTS, RetargetLegs.NO_VELOCITY, undefined, m.stops)), repeatDelay),
224
- onFalse: () => together(RetargetLegs.legsOf(m.from, m.to, transition, m.reduced, skipped, DOM_POSITIONAL, DOM_DEFAULTS, RetargetLegs.NO_VELOCITY, undefined, m.stops)),
225
- }),
244
+ machine: () => {
245
+ // Its held keys as where the element is now, the client's snapshot (#1019): a Path's axis that isn't a
246
+ // number, there, takes it no path, as on the client.
247
+ const legs = together(RetargetLegs.legsOf(m.from, m.to, transition, m.reduced, skipped, DOM_POSITIONAL, DOM_DEFAULTS, RetargetLegs.NO_VELOCITY, undefined, m.stops, undefined, m.held), heldOf(m))
248
+ return Bool.match(forever, { onTrue: () => Machine.holdAfter(legs, repeatDelay), onFalse: () => legs })
249
+ },
226
250
  })
227
251
  },
228
252
  })
@@ -230,8 +254,10 @@ export const specOf = (m: AppearHandoff.MountAnimation): Result.Result<Appear.Sp
230
254
  /**
231
255
  * Why a mount animation can't play before hydration, or `None` when it can (decision 4): a key
232
256
  * starting from anything but `initial`, a value the DOM reads from the element (`auto`, `var()`),
233
- * or a start that can't take its target's shape (a length pair in two units).
257
+ * a start that can't take its target's shape (a length pair in two units), or the element's own
258
+ * depth, `transformPerspective`, which CSS blends unlike Wardic. `to` holds the keys that move.
234
259
  */
260
+ // #887 (ADR-0073, *Amendment (#887)*, Q13): the depth, as a Batch's rule leaves it (`appear.ts`'s `DEPTH_MOVES_REASON`).
235
261
  export const unplayable = (initial: Values.Values, to: Values.Values): Option.Option<string> =>
236
262
  Arr.findFirst(Rec.toEntries(to), ([key, target]) =>
237
263
  Option.match(Option.fromUndefinedOr(initial[key]), {
@@ -243,7 +269,7 @@ export const unplayable = (initial: Values.Values, to: Values.Values): Option.Op
243
269
  // A start that can't take its target's shape, a length in another unit among them (ADR-0024).
244
270
  Bool.match(Option.isNone(OwnValues.valueLike(start, target)), {
245
271
  onTrue: () => Option.some(`${key}'s start and target don't take one shape`),
246
- onFalse: () => Option.none(),
272
+ onFalse: () => Bool.match(key === TransformKeys.PERSPECTIVE, { onTrue: () => Option.some(DEPTH_MOVES_REASON), onFalse: () => Option.none() }),
247
273
  }),
248
274
  }),
249
275
  }))
@@ -427,7 +453,9 @@ export const serverAppear = (reducedMotion: ReducedMotion.Config, explain?: (mes
427
453
  const write = (batch: ReadonlyArray<Entry>): string => {
428
454
  // Each entry's plays are its own setting's (#434): the normal ones always, the reduced ones under
429
455
  // the media query when an entry follows the user.
430
- const resolve = (pick: "normal" | "reduced") => timings(batch, pick)
456
+ // A `delayChildren` function that throws, reported once a write (#979).
457
+ const delays = VariantTree.eventDelayFailuresOf(VariantTree.ON_SERVER)
458
+ const resolve = (pick: "normal" | "reduced") => timings(batch, pick, delays)
431
459
  const normal = resolve("normal")
432
460
  const reduced = Bool.match(Arr.some(batch, isUser), { onTrue: () => Option.some(resolve("reduced")), onFalse: () => Option.none<Timings>() })
433
461
  const settings = Arr.prepend(Option.toArray(reduced), normal)
@@ -509,7 +537,7 @@ export const serverAppear = (reducedMotion: ReducedMotion.Config, explain?: (mes
509
537
  * is among that group's children in its batch, and it doesn't wait on the leader (decision 5 of
510
538
  * *Amendment (#245)*). The shell's batch is every entry, so nothing changes for it.
511
539
  */
512
- const timings = (entries: ReadonlyArray<Entry>, pick: "normal" | "reduced"): Timings => {
540
+ const timings = (entries: ReadonlyArray<Entry>, pick: "normal" | "reduced", delays: VariantTree.DelayFailures): Timings => {
513
541
  const memo = new Map<Entry, Result.Result<{ readonly play: TimedPlay; readonly settled: number }, string>>()
514
542
  let geometry = false
515
543
  const inBatch = new Set(entries)
@@ -554,7 +582,7 @@ const timings = (entries: ReadonlyArray<Entry>, pick: "normal" | "reduced"): Tim
554
582
  })
555
583
  /** When `entry` starts: its stagger, after its parent under `beforeChildren`, after its children under `afterChildren`. */
556
584
  const startOf = (entry: Entry): Result.Result<number, string> =>
557
- Result.flatMap(afterParent(entry), (afterLeader) => Result.map(afterChildren(entry), (afterKids) => Math.max(afterLeader, afterKids) + ownStaggerOf(entry, childrenOf)))
585
+ Result.flatMap(afterParent(entry), (afterLeader) => Result.map(afterChildren(entry), (afterKids) => Math.max(afterLeader, afterKids) + ownStaggerOf(entry, childrenOf, delays)))
558
586
  // A leader written earlier started at first paint: a late child doesn't wait on it.
559
587
  const afterParent = (entry: Entry): Result.Result<number, string> =>
560
588
  Option.match(Option.filter(entry.group, (g) => Bool.and(g.when === "beforeChildren", inBatch.has(g.leader))), {
@@ -634,23 +662,23 @@ const groupSupports = (
634
662
  }
635
663
 
636
664
  /** An entry's own stagger: none when it's skipped (#468), as its client's snap has no delay; its `when` waits still hold. */
637
- const ownStaggerOf = (entry: Entry, childrenOf: (g: AppearGroup) => ReadonlyArray<Entry>): number => {
665
+ const ownStaggerOf = (entry: Entry, childrenOf: (g: AppearGroup) => ReadonlyArray<Entry>, delays: VariantTree.DelayFailures): number => {
638
666
  if (entry.skipped) return 0
639
- return staggerOf(entry, childrenOf)
667
+ return staggerOf(entry, childrenOf, delays)
640
668
  }
641
669
 
642
670
  /**
643
671
  * A Variant child's stagger: its parent's `delayChildren` plus its place (ADR-0007), as the client
644
672
  * works it out, among the group's children in its batch (`childrenOf`, #245).
645
673
  */
646
- const staggerOf = (entry: Entry, childrenOf: (g: AppearGroup) => ReadonlyArray<Entry>): number =>
674
+ const staggerOf = (entry: Entry, childrenOf: (g: AppearGroup) => ReadonlyArray<Entry>, delays: VariantTree.DelayFailures): number =>
647
675
  Option.match(entry.group, {
648
676
  onNone: () => 0,
649
677
  onSome: (g) => {
650
678
  const children = childrenOf(g)
651
679
  const n = children.length
652
680
  const i = children.indexOf(entry)
653
- return VariantTree.childDelayOf(g.stagger, i, n)
681
+ return VariantTree.childDelayOf(g.stagger, i, n, delays)
654
682
  },
655
683
  })
656
684
 
@@ -704,21 +732,41 @@ export const enterServer = (
704
732
  } => {
705
733
  // Its starts and targets once, both plays sharing them (and so their key's text, `keyOf`). A key
706
734
  // already at its target, coerced to its shape, is left out, as the client's first Retarget starts
707
- // it no leg (#448); a Keyframes key never is, and starts at its first stop, unless the mount starts
708
- // at its `animate`, when nothing plays (#429, Motion's).
735
+ // it no leg (#448), unless its transition kicks it (#1018); a Keyframes key never is, and starts at
736
+ // its first stop, unless the mount starts at its `animate`, when nothing plays (#429, Motion's).
737
+ // The keys left out stay still, held where they are (#1004), as the client writes them beside the moving ones.
709
738
  const mount = Option.flatMap(el.to, (to) => {
710
- const moving = Rec.filter(to, (target, key) =>
711
- Bool.match(hasStops(el.keyframes, key), { onTrue: () => Bool.not(el.quiet), onFalse: () => Bool.not(atTarget(el.initial[key], target)) }))
739
+ // One at its target moves when its transition kicks it, as the client's does (#1018), unless the mount
740
+ // starts at its `animate`, when nothing plays (#475): a quiet mount never asks. A number alone: a string,
741
+ // the element's own `auto` among them, isn't kicked, and is left out, so its element's other keys play.
742
+ const kicked = (target: number | string, key: string): boolean => {
743
+ if (el.quiet) return false
744
+ if (Bool.not(Predicate.isNumber(target))) return false
745
+ return RetargetLegs.givesVelocity(el.transition, key)
746
+ }
747
+ const moves = (target: number | string, key: string): boolean =>
748
+ Bool.match(hasStops(el.keyframes, key), {
749
+ onTrue: () => Bool.not(el.quiet),
750
+ onFalse: () => Bool.match(atTarget(el.initial[key], target), { onTrue: () => kicked(target, key), onFalse: () => true }),
751
+ })
752
+ // A Path couples `x` and `y` (#438): with either moving, the other goes along it from its own value, as the
753
+ // client's spine has it (#1019), a number alone: one that isn't takes no path on the client either. The still
754
+ // keys are `moves`'s, so one it puts back stays held, as the client keeps it among its keys already there:
755
+ // both sides' mount animations match.
756
+ const moving = RetargetLegs.withPathAxes(Rec.filter(to, moves), Rec.filter(to, (target) => Predicate.isNumber(target)), el.transition)
757
+ // With them, the keys only `initial` sets, which stay where it put them (#1022), as the client keeps them.
758
+ const still = { ...Rec.filter(el.initial, (_, key) => Bool.not(Object.hasOwn(to, key))), ...Rec.filter(to, (target, key) => Bool.not(moves(target, key))) }
712
759
  return Bool.match(Rec.isEmptyRecord(moving), {
713
760
  onTrue: () => Option.none(),
714
- onFalse: () => Option.some(Result.map(playable(el, moving), (prepared): RetargetLegs.KeyframesStart & { readonly to: Values.Values } => startedOf(prepared, el.keyframes))),
761
+ onFalse: () =>
762
+ Option.some(Result.map(playable(el, moving), (prepared): RetargetLegs.KeyframesStart & { readonly to: Values.Values; readonly still: Values.Values } => ({ ...startedOf(prepared, el.keyframes), still }))),
715
763
  })
716
764
  })
717
765
  // Skipped (#468): its config's, or its whole transition's own, as the client's legs read them.
718
766
  const skipped = Bool.or(el.skipAnimations === true, UndefinedOr.match(el.transition, { onUndefined: () => false, onDefined: (t) => t.skipAnimations === true }))
719
767
  const play = (reduced: boolean): Option.Option<Result.Result<AppearHandoff.MountAnimation, string>> =>
720
768
  Option.map(mount, (prepared) =>
721
- Result.map(prepared, ({ from, to, stops }): AppearHandoff.MountAnimation => ({
769
+ Result.map(prepared, ({ from, to, stops, still }): AppearHandoff.MountAnimation => ({
722
770
  tag: el.tag,
723
771
  from,
724
772
  to,
@@ -728,6 +776,7 @@ export const enterServer = (
728
776
  stops,
729
777
  ...AppearHandoff.skippedField(skipped),
730
778
  ...UndefinedOr.match(el.template, { onUndefined: () => ({}), onDefined: (template) => ({ template }) }),
779
+ held: still,
731
780
  })))
732
781
  const plays = Bool.match(skipped, {
733
782
  onTrue: () => {
@@ -24,7 +24,6 @@
24
24
  // ADR-0070 decisions 10–15 and *Amendment (#665)*. The DOM's writer, imported here so an app that never
25
25
  // makes a Batch ships none of it (ADR-0070, *Amendment (#665)*).
26
26
  import * as Batch from "@wardic/core/Batch"
27
- import * as BaseValue from "@wardic/core/BaseValue"
28
27
  import type * as DefaultTransition from "@wardic/core/DefaultTransition"
29
28
  import * as Playback from "@wardic/core/Playback"
30
29
  import * as ReducedMotion from "@wardic/core/ReducedMotion"
@@ -58,16 +57,19 @@ import * as BatchCalls from "@wardic/core/unstable/BatchCalls"
58
57
  import { delayedBy, INSTANT, isFirstStop, isPair, type KeyPlan, memberTransitionsOf, staggerOf, unstaggered } from "@wardic/core/unstable/BatchCalls"
59
58
  import type * as WardicServices from "@wardic/core/unstable/WardicServices"
60
59
  import * as WardicConfigValue from "@wardic/core/unstable/WardicConfigValue"
60
+ import * as TransformKeys from "../internal/transform-keys.ts"
61
61
 
62
62
  /** The keys a Batch's members animate on the DOM: the transforms and `opacity`, as numbers. */
63
+ // #887: the element's own depth, and `scaleZ`, which #883 drew but never typed.
63
64
  export type WardicBatchKey =
65
+ | "transformPerspective"
64
66
  | "x" | "y" | "z" | "translateX" | "translateY" | "translateZ"
65
- | "scale" | "scaleX" | "scaleY"
67
+ | "scale" | "scaleX" | "scaleY" | "scaleZ"
66
68
  | "rotate" | "rotateX" | "rotateY" | "rotateZ"
67
69
  | "skewX" | "skewY"
68
70
  | "opacity"
69
71
 
70
- /** A member's values: numbers on its keys, in `px` for a move, degrees for a turn, unitless for a scale and `opacity`. */
72
+ /** A member's values: numbers on its keys, in `px` for a move and a depth, degrees for a turn, unitless for a scale and `opacity`. */
71
73
  export type WardicBatchValues = { readonly [K in WardicBatchKey]?: number }
72
74
 
73
75
  /**
@@ -450,7 +452,7 @@ export type BatchGroup = "transform" | "opacity"
450
452
  /** The group `key` is drawn in on the DOM: a transform key's `transform`, `opacity`'s own, or none. */
451
453
  export const batchGroupOf = (key: string): BatchGroup | undefined => {
452
454
  if (key === "opacity") return "opacity"
453
- if (Predicate.isNotUndefined(BaseValue.TRANSFORM_IDENTITY[key])) return "transform"
455
+ if (Predicate.isNotUndefined(TransformKeys.TRANSFORM_IDENTITY[key])) return "transform"
454
456
  return undefined
455
457
  }
456
458
 
@@ -663,7 +665,7 @@ const noMember = (i: number, count: number): never => fail(`it has no member ${i
663
665
  /** Each key's identity: a transform's, and `opacity`'s 1, an element's own with no style of its own. */
664
666
  // Per member per key at mount (#540): statements.
665
667
  export const identityOf = (key: string): number => {
666
- const identity = BaseValue.TRANSFORM_IDENTITY[key]
668
+ const identity = TransformKeys.TRANSFORM_IDENTITY[key]
667
669
  if (Predicate.isUndefined(identity)) return 1
668
670
  return identity
669
671
  }
@@ -873,6 +875,10 @@ export const markLayoutElement = (element: Element): void => {
873
875
  LAYOUT_ELEMENTS.add(element)
874
876
  }
875
877
 
878
+ /** The error for a member's element with no inline style: one of a foreign namespace. */
879
+ const stylelessMember = (element: Element): string =>
880
+ `a member's element (${elementName(element)}) has no inline style for the Batch to draw its \`transform\` and \`opacity\` on: give it an HTML, SVG or MathML element`
881
+
876
882
  /** The error for a layout node on a Batch member's element. */
877
883
  const layoutOnMember = (element: Element): string =>
878
884
  `a member's element (${elementName(element)}) has \`layout\` or \`layoutId\`: the Batch draws its transform, under which the projection measures it. Give its Wardic element no layout, or leave it out of the Batch`
@@ -1750,7 +1756,7 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
1750
1756
  watchedOn[i] = el
1751
1757
  const entry = entries[i]
1752
1758
  watch({
1753
- element: () => el,
1759
+ subject: () => el,
1754
1760
  holds: true,
1755
1761
  leave: (custom, release) => memberLeft(i, entry, el, custom, release),
1756
1762
  gone: () => watchGone(i, entry, el),
@@ -1815,13 +1821,19 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
1815
1821
  if (disposed) return Arr.forEach(going, cutExit)
1816
1822
  const exitTargets = new Float64Array(capacity * stride).fill(Number.NaN)
1817
1823
  const moving: Array<number> = []
1818
- // Per leaver at its exit (#665): statements. An exit that fails is reported, and lets its element go.
1824
+ // Per leaver at its exit (#665): statements. An exit that fails lets its element go, and is reported
1825
+ // once for this task's leavers: one exit function called for each (#979 group I, row 29; ADR-0074
1826
+ // decision 3, an event's run, as an exit's stagger is).
1827
+ let reported = false
1819
1828
  Arr.forEach(going, (i) => {
1820
1829
  try {
1821
1830
  targetsInto(exitTargets, i, exitValuesOf(i, UndefinedOr.getOrThrow(exits[i]).custom))
1822
1831
  moving.push(i)
1823
1832
  } catch (defect) {
1824
- env.runtime.runFork(Report.failure("createBatch: a member's exit failed", Cause.die(defect)))
1833
+ if (!reported) {
1834
+ reported = true
1835
+ env.runtime.runFork(Report.failure("createBatch: a member's exit failed", Cause.die(defect)))
1836
+ }
1825
1837
  cutExit(i)
1826
1838
  if (unlisted.has(i)) leaveBatch(i)
1827
1839
  }
@@ -2209,7 +2221,17 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
2209
2221
  * them, one a change didn't move among them, or each one the Handoff's code never came for.
2210
2222
  */
2211
2223
  const releaseAppearing = (): void => {
2212
- Iter.forEach(appearing, (slot) => UndefinedOr.map(elementOf[memberOf[slot] as number] as (Element & ElementCSSInlineStyle) | undefined, Appear.release))
2224
+ // Each member's own: one that throws leaves the others let go, reported once a release (#977).
2225
+ let failed = false
2226
+ Iter.forEach(appearing, (slot) => {
2227
+ try {
2228
+ UndefinedOr.map(elementOf[memberOf[slot] as number] as (Element & ElementCSSInlineStyle) | undefined, Appear.release)
2229
+ } catch (defect) {
2230
+ if (failed) return
2231
+ failed = true
2232
+ env.runtime.runFork(Report.failure("wardic.batch: a member's Appear release failed", Cause.die(defect)))
2233
+ }
2234
+ })
2213
2235
  appearing.clear()
2214
2236
  handoffAt = undefined
2215
2237
  }
@@ -2646,6 +2668,8 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
2646
2668
  // can't be a member: the projection measures it under the transform the Batch draws.
2647
2669
  if (drawnByAnother(el)) return fail(`an element (${elementName(el)}) is a member of two Batches: one Batch draws an element's \`transform\` and \`opacity\``)
2648
2670
  if (LAYOUT_ELEMENTS.has(el)) return fail(layoutOnMember(el))
2671
+ // Its inline style is what the Batch draws: one with none is refused before it's entered (#977, Q6).
2672
+ if (Predicate.isUndefined((el as Partial<ElementCSSInlineStyle>).style)) return fail(stylelessMember(el))
2649
2673
  const was = elementOf[i]
2650
2674
  if (Predicate.isNotUndefined(was)) forget(was, i)
2651
2675
  elementOf[i] = el
@@ -36,7 +36,7 @@ const withRead = (pair: Requested): MeasuredPairs.Requested => ({ ...pair, measu
36
36
  /** The DOM's Measured pairs: a pair whose units don't blend, measured on its element at the end of the task. */
37
37
  export const measuredPairs: MeasuredPairs.Shape = {
38
38
  needs,
39
- measure: (subject, pairs, values) => Rec.map(measure(subject as HTMLElement, pairs, values), withRead),
39
+ measure: (subject, pairs, values, failed) => Rec.map(measure(subject as HTMLElement, pairs, values, failed), withRead),
40
40
  }
41
41
 
42
42
  /** The DOM's Variable values: a `var(--x)`, resolved on its element as each leg starts. */