@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
@@ -17,11 +17,12 @@
17
17
  * per-frame hot path, so — exactly like core's `applyTo` per-frame writes and
18
18
  * the Clock's `tick` — they stay quiet (no span, no per-call log).
19
19
  */
20
- import * as BaseValue from "@wardic/core/BaseValue"
21
20
  import type * as Point from "@wardic/core/Point"
22
21
  import * as Projection from "@wardic/core/Projection"
23
22
  import * as Renderer from "@wardic/core/Renderer"
24
23
  import { dashCase, isSvgInner, setSvgAttrs, splitPatch } from "./svg.ts"
24
+ import { LENGTH_KEY_SET } from "./length-keys.ts"
25
+ import * as TransformKeys from "./transform-keys.ts"
25
26
  import * as Arr from "effect/Array"
26
27
  import * as Bool from "effect/Boolean"
27
28
  import * as Layer from "effect/Layer"
@@ -30,18 +31,21 @@ import * as Predicate from "effect/Predicate"
30
31
  import * as UndefinedOr from "effect/UndefinedOr"
31
32
 
32
33
  /**
33
- * CSS transform functions in their canonical emission order: translate group,
34
- * then scale, then rotate, then skew. `project` walks this list and emits a
34
+ * CSS transform functions in their canonical emission order: the element's own
35
+ * depth, then the translate group, then scale, then rotate, then skew. `project` walks this list and emits a
35
36
  * func for each key that is present in `values` and not at its identity, so the
36
37
  * resulting `transform` string is always grouped in this order regardless of
37
38
  * input key order.
38
39
  *
39
40
  * `key` is the property name accepted on engine values (shorthands `x`/`y`/`z`
40
- * included); `fn` is the CSS function name it renders as; `identity` is core's
41
- * (ADR-0022), the value at which `project` leaves the key out (ADR-0023).
41
+ * included); `fn` is the CSS function name it renders as; `identity` is the DOM's
42
+ * (core's, ADR-0022, and the DOM's own), the value at which `project` leaves the key out (ADR-0023).
43
+ * The element's own depth is left out below it too (`TransformKeys.drawsDepth`).
42
44
  */
43
45
  // Exported for the Batch writer (#665), which draws a member's transform in the same order.
44
46
  export const TRANSFORM_FUNCS: ReadonlyArray<{ readonly key: string; readonly fn: string; readonly identity: number }> = [
47
+ // The element's own depth (#887), Motion's `transformPerspective`: first, so it projects what follows.
48
+ { key: TransformKeys.PERSPECTIVE, fn: "perspective" },
45
49
  // translate group — shorthands x/y/z map onto translateX/Y/Z
46
50
  { key: "x", fn: "translateX" },
47
51
  { key: "y", fn: "translateY" },
@@ -64,7 +68,15 @@ export const TRANSFORM_FUNCS: ReadonlyArray<{ readonly key: string; readonly fn:
64
68
  // skew group
65
69
  { key: "skewX", fn: "skewX" },
66
70
  { key: "skewY", fn: "skewY" },
67
- ].map((f) => ({ ...f, identity: UndefinedOr.getOrThrow(BaseValue.TRANSFORM_IDENTITY[f.key]) }))
71
+ ].map((f) => ({ ...f, identity: UndefinedOr.getOrThrow(TransformKeys.TRANSFORM_IDENTITY[f.key]) }))
72
+
73
+ /**
74
+ * What a plain render walks: every transform function but the element's own depth, which it draws ahead
75
+ * of them in a statement of its own.
76
+ */
77
+ // #887 (ADR-0073, *Amendment (#887)*, Q8): one more step in the walk cost an element at rest 13% in Maglev,
78
+ // 4% in Bun; a read ahead of it, nothing (the cost gate's variants).
79
+ const WALKED_FUNCS = TRANSFORM_FUNCS.filter((f) => f.key !== TransformKeys.PERSPECTIVE)
68
80
 
69
81
  /**
70
82
  * Whether a transform value is at its identity (ADR-0023), Motion's test
@@ -79,14 +91,15 @@ const isIdentity = (value: unknown, identity: number): boolean => {
79
91
  }
80
92
 
81
93
  /**
82
- * Whether `key`'s `value` adds to the element's `transform` (#240): a transform key off its identity, a
94
+ * Whether `key`'s `value` adds to the element's `transform` (#240): a transform key it draws, a
83
95
  * `transform` string, the projection's value or a Transform template. A Timeline value drawing
84
96
  * `transform` runs only while nothing else does. Per frame: statements.
85
97
  */
86
98
  export const addsToTransform = (key: string, value: unknown): boolean => {
87
99
  if (key === Projection.KEY || key === TEMPLATE_KEY || key === "transform") return true
88
- const identity = BaseValue.TRANSFORM_IDENTITY[key]
100
+ const identity = TransformKeys.TRANSFORM_IDENTITY[key]
89
101
  if (Predicate.isUndefined(identity)) return false
102
+ if (key === TransformKeys.PERSPECTIVE) return TransformKeys.drawsDepth(value)
90
103
  return !isIdentity(value, identity)
91
104
  }
92
105
 
@@ -101,11 +114,12 @@ type TransformUnit = "px" | "deg" | ""
101
114
 
102
115
  /**
103
116
  * Default-unit map for transform values: translate (and the x/y/z shorthands)
104
- * are lengths → `px`; rotate/skew are angles → `deg`; scale* are unitless.
117
+ * are lengths → `px`, as is the element's own depth; rotate/skew are angles → `deg`; scale* are unitless.
105
118
  * A value that is already a string is used verbatim (explicit units honoured),
106
119
  * so this map only drives the formatting of bare numbers.
107
120
  */
108
121
  const TRANSFORM_UNITS: Record<string, TransformUnit> = {
122
+ [TransformKeys.PERSPECTIVE]: "px",
109
123
  x: "px",
110
124
  y: "px",
111
125
  z: "px",
@@ -125,84 +139,10 @@ const TRANSFORM_UNITS: Record<string, TransformUnit> = {
125
139
  skewY: "deg",
126
140
  }
127
141
 
128
- /**
129
- * Fast membership test for "is this key a transform key?": core's transform keys, the ones
130
- * it gives an identity (ADR-0022), so the two lists can't drift. Every one has a unit above.
131
- */
132
- const TRANSFORM_KEYS: ReadonlySet<string> = new Set(Object.keys(BaseValue.TRANSFORM_IDENTITY))
133
-
134
- /**
135
- * The CSS properties a bare number on is a length, drawn in `px`, spelled as Wardic's keys are
136
- * (`margin-top`): Motion's, and `min-width`, `min-height`, the gaps and `letter-spacing`. The Solid
137
- * bindings' value types take a number on these and on no other length, so a number never draws CSS a
138
- * browser drops. `line-height` isn't one: CSS reads its bare number as a multiple. A number on any other
139
- * key, `opacity`, `z-index`, a custom property, is drawn as it is; a string always is.
140
- */
141
- // #522: Motion's `numberValueTypes`' `px` keys; the bindings' `WardicValues`.
142
- export const LENGTH_KEYS = [
143
- "border-width",
144
- "border-top-width",
145
- "border-right-width",
146
- "border-bottom-width",
147
- "border-left-width",
148
- "border-radius",
149
- "border-top-left-radius",
150
- "border-top-right-radius",
151
- "border-bottom-right-radius",
152
- "border-bottom-left-radius",
153
- "width",
154
- "min-width",
155
- "max-width",
156
- "height",
157
- "min-height",
158
- "max-height",
159
- "top",
160
- "right",
161
- "bottom",
162
- "left",
163
- "inset",
164
- "inset-block",
165
- "inset-block-start",
166
- "inset-block-end",
167
- "inset-inline",
168
- "inset-inline-start",
169
- "inset-inline-end",
170
- "padding",
171
- "padding-top",
172
- "padding-right",
173
- "padding-bottom",
174
- "padding-left",
175
- "padding-block",
176
- "padding-block-start",
177
- "padding-block-end",
178
- "padding-inline",
179
- "padding-inline-start",
180
- "padding-inline-end",
181
- "margin",
182
- "margin-top",
183
- "margin-right",
184
- "margin-bottom",
185
- "margin-left",
186
- "margin-block",
187
- "margin-block-start",
188
- "margin-block-end",
189
- "margin-inline",
190
- "margin-inline-start",
191
- "margin-inline-end",
192
- "gap",
193
- "row-gap",
194
- "column-gap",
195
- "font-size",
196
- "letter-spacing",
197
- "background-position-x",
198
- "background-position-y",
199
- ] as const
200
-
201
- /** One of `LENGTH_KEYS`: a CSS property a bare number on is drawn in `px`. */
202
- export type LengthKey = (typeof LENGTH_KEYS)[number]
203
-
204
- /** {@link LENGTH_KEYS}, for a membership test a frame can make. */
205
- const LENGTH_KEY_SET: ReadonlySet<string> = new Set(LENGTH_KEYS)
142
+
143
+ // The lengths a bare number on is drawn in px: a module of their own, which `LiveStyle` reads too without
144
+ // bringing the renderer (#887; a three Stage's apps ship `LiveStyle`, not the renderer).
145
+ export { LENGTH_KEYS, type LengthKey } from "./length-keys.ts"
206
146
 
207
147
  /**
208
148
  * Format one transform value into its CSS func argument. Strings pass through
@@ -411,6 +351,10 @@ const buildProjectionTransform = (
411
351
  const translateByUnit = otherUnitTranslate(latest["translateX"], latest["translateY"])
412
352
  if (translateByUnit !== "") funcs.unshift(translateByUnit)
413
353
  if (ownByUnit !== "") funcs.unshift(ownByUnit)
354
+ // The element's own depth heads it all, as Motion's `buildProjectionTransform` puts it, so it projects
355
+ // what follows (#887).
356
+ const depth = latest[TransformKeys.PERSPECTIVE]
357
+ if (Predicate.isNotUndefined(depth) && TransformKeys.drawsDepth(depth)) funcs.unshift(`perspective(${formatTransformValue(TransformKeys.PERSPECTIVE, depth)})`)
414
358
  if (funcs.length === 0) return "none"
415
359
  return funcs.join(" ")
416
360
  }
@@ -498,14 +442,23 @@ const projectsNothing = (projection: Projection.Value): boolean => {
498
442
 
499
443
  /**
500
444
  * The transform keys a plain render draws (ADR-0023): each one present and not at its identity, in
501
- * the canonical order; `""` when every one present is at its identity; `undefined` with none. Built
502
- * by concatenation, not an array joined (ADR-0034): this runs per element per frame.
445
+ * the canonical order, the element's own depth first; `""` when every one present is at its identity;
446
+ * `undefined` with none. Built by concatenation, not an array joined (ADR-0034): this runs per element
447
+ * per frame.
503
448
  */
504
449
  const plainTransformOf = (values: Record<string, unknown>): string | undefined => {
505
450
  let transform = ""
506
451
  let separator = ""
507
452
  let present = false
508
- for (const { key, fn, identity } of TRANSFORM_FUNCS) {
453
+ const depth = values[TransformKeys.PERSPECTIVE]
454
+ if (Predicate.isNotUndefined(depth)) {
455
+ present = true
456
+ if (TransformKeys.drawsDepth(depth)) {
457
+ transform = `perspective(${formatTransformValue(TransformKeys.PERSPECTIVE, depth)})`
458
+ separator = " "
459
+ }
460
+ }
461
+ for (const { key, fn, identity } of WALKED_FUNCS) {
509
462
  if (!Object.hasOwn(values, key)) continue
510
463
  present = true
511
464
  const value = values[key]
@@ -609,7 +562,7 @@ export const project = (values: Readonly<Record<string, unknown>>): Renderer.Pat
609
562
  // Copy non-transform style keys (transform keys are consumed by the weave /
610
563
  // owned by the projection; the reserved keys never render).
611
564
  for (const key in values) {
612
- if (key === Projection.KEY || key === TEMPLATE_KEY || TRANSFORM_KEYS.has(key)) continue
565
+ if (key === Projection.KEY || key === TEMPLATE_KEY || TransformKeys.TRANSFORM_KEYS.has(key)) continue
613
566
  patch[key] = formatStyleValue(key, values[key])
614
567
  }
615
568
  // Shared-element crossfade (ADR-0010): compose the crossfade factor with the
@@ -635,7 +588,7 @@ export const project = (values: Readonly<Record<string, unknown>>): Renderer.Pat
635
588
 
636
589
  // Non-transform keys: copy across with default-unit handling.
637
590
  for (const key in values) {
638
- if (key === TEMPLATE_KEY || TRANSFORM_KEYS.has(key)) continue
591
+ if (key === TEMPLATE_KEY || TransformKeys.TRANSFORM_KEYS.has(key)) continue
639
592
  patch[key] = formatStyleValue(key, values[key])
640
593
  }
641
594
 
@@ -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)),
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The DOM's transform keys, each with its identity: core's (`BaseValue.TRANSFORM_IDENTITY`), and the DOM's
3
+ * own, `transformPerspective`, a depth no other Environment draws. Every DOM reader of a transform key
4
+ * reads this table, so the DOM's own keys are transforms to each of them: the renderer, Own values, a
5
+ * Batch's members, Appear, reduced motion and the Default transition.
6
+ *
7
+ * @module
8
+ */
9
+ // #887 (ADR-0073, *Amendment (#887)*, Q1): core names no key only the page draws. As `positional-keys.ts`
10
+ // adds the box's keys to core's transforms, this adds the DOM's own transform keys to core's. #1002 would
11
+ // move here, at a major, the six of core's that only the DOM draws. TK1 pins that no dom source reads
12
+ // core's table but this module.
13
+ import * as BaseValue from "@wardic/core/BaseValue"
14
+ import * as Option from "effect/Option"
15
+ import * as Predicate from "effect/Predicate"
16
+ import * as Rec from "effect/Record"
17
+
18
+ /** An element's own depth, Motion's key: `perspective()` at the head of its transform, in px. */
19
+ export const PERSPECTIVE = "transformPerspective"
20
+
21
+ /**
22
+ * Each of the DOM's transform keys, with its identity: core's, and {@link PERSPECTIVE}'s 0. That 0 is no
23
+ * perspective, not a depth: it's left out of the transform, as Motion's is.
24
+ */
25
+ export const TRANSFORM_IDENTITY: Readonly<Record<string, number>> = Object.freeze({ ...BaseValue.TRANSFORM_IDENTITY, [PERSPECTIVE]: 0 })
26
+
27
+ /** A DOM transform key's identity (see {@link TRANSFORM_IDENTITY}), or `None` for any other key, prototype names included. */
28
+ export const transformIdentity = (key: string): Option.Option<number> => Rec.get(TRANSFORM_IDENTITY, key)
29
+
30
+ /** The DOM's transform keys, for a membership test a frame can make. */
31
+ export const TRANSFORM_KEYS: ReadonlySet<string> = new Set(Object.keys(TRANSFORM_IDENTITY))
32
+
33
+ /** Whether `key` is one of the DOM's transform keys. */
34
+ export const isTransformKey = (key: string): boolean => TRANSFORM_KEYS.has(key)
35
+
36
+ /**
37
+ * Whether the element's own depth draws a `perspective()`: above its identity, 0, which is no
38
+ * perspective. A depth below 0 isn't drawn either: CSS refuses a negative `perspective()`, and the whole
39
+ * `transform` with it, so a spring's overshoot past 0 draws no perspective. A string is read as Motion
40
+ * reads one, by `parseFloat`, and drawn when it can't be read (`var(--d)`). Per frame: statements.
41
+ */
42
+ // #887 (ADR-0073, *Amendment (#887)*, Q3): the renderer's, a projected element's and a Batch member's.
43
+ export const drawsDepth = (value: unknown): boolean => {
44
+ if (Predicate.isNumber(value)) return value > 0
45
+ const read = Number.parseFloat(String(value))
46
+ return Number.isNaN(read) || read > 0
47
+ }
@@ -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: () => {