@wardic/dom 1.0.0-rc.8 → 1.0.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 (86) hide show
  1. package/dist/Appear.d.ts +7 -1
  2. package/dist/Appear.d.ts.map +1 -1
  3. package/dist/Appear.js +7 -1
  4. package/dist/Appear.js.map +1 -1
  5. package/dist/DomBatch.d.ts +20 -0
  6. package/dist/DomBatch.d.ts.map +1 -0
  7. package/dist/DomBatch.js +23 -0
  8. package/dist/DomBatch.js.map +1 -0
  9. package/dist/DomInput.d.ts +2 -1
  10. package/dist/DomInput.d.ts.map +1 -1
  11. package/dist/DomInput.js +3 -1
  12. package/dist/DomInput.js.map +1 -1
  13. package/dist/KeyboardPress.d.ts +16 -0
  14. package/dist/KeyboardPress.d.ts.map +1 -0
  15. package/dist/KeyboardPress.js +17 -0
  16. package/dist/KeyboardPress.js.map +1 -0
  17. package/dist/ReorderController.d.ts +24 -4
  18. package/dist/ReorderController.d.ts.map +1 -1
  19. package/dist/ReorderController.js +38 -4
  20. package/dist/ReorderController.js.map +1 -1
  21. package/dist/index.d.ts +5 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +3 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/internal/appear-slot.d.ts +23 -0
  26. package/dist/internal/appear-slot.d.ts.map +1 -0
  27. package/dist/internal/appear-slot.js +29 -0
  28. package/dist/internal/appear-slot.js.map +1 -0
  29. package/dist/internal/appear.d.ts +84 -16
  30. package/dist/internal/appear.d.ts.map +1 -1
  31. package/dist/internal/appear.js +302 -61
  32. package/dist/internal/appear.js.map +1 -1
  33. package/dist/internal/batch-writer.d.ts +16 -0
  34. package/dist/internal/batch-writer.d.ts.map +1 -0
  35. package/dist/internal/batch-writer.js +77 -0
  36. package/dist/internal/batch-writer.js.map +1 -0
  37. package/dist/internal/gate.d.ts +3 -2
  38. package/dist/internal/gate.d.ts.map +1 -1
  39. package/dist/internal/gate.js +5 -1
  40. package/dist/internal/gate.js.map +1 -1
  41. package/dist/internal/input.d.ts +0 -6
  42. package/dist/internal/input.d.ts.map +1 -1
  43. package/dist/internal/input.js +205 -23
  44. package/dist/internal/input.js.map +1 -1
  45. package/dist/internal/keyboard-press.d.ts +7 -0
  46. package/dist/internal/keyboard-press.d.ts.map +1 -0
  47. package/dist/internal/keyboard-press.js +45 -0
  48. package/dist/internal/keyboard-press.js.map +1 -0
  49. package/dist/internal/measure.d.ts +7 -0
  50. package/dist/internal/measure.d.ts.map +1 -1
  51. package/dist/internal/measure.js +19 -1
  52. package/dist/internal/measure.js.map +1 -1
  53. package/dist/internal/projection.d.ts +13 -5
  54. package/dist/internal/projection.d.ts.map +1 -1
  55. package/dist/internal/projection.js +271 -33
  56. package/dist/internal/projection.js.map +1 -1
  57. package/dist/internal/renderer.d.ts +18 -0
  58. package/dist/internal/renderer.d.ts.map +1 -1
  59. package/dist/internal/renderer.js +4 -2
  60. package/dist/internal/renderer.js.map +1 -1
  61. package/dist/internal/reorder.d.ts +28 -13
  62. package/dist/internal/reorder.d.ts.map +1 -1
  63. package/dist/internal/reorder.js +55 -26
  64. package/dist/internal/reorder.js.map +1 -1
  65. package/dist/internal/reveal.d.ts +7 -3
  66. package/dist/internal/reveal.d.ts.map +1 -1
  67. package/dist/internal/reveal.js +8 -3
  68. package/dist/internal/reveal.js.map +1 -1
  69. package/package.json +4 -4
  70. package/src/Appear.ts +12 -3
  71. package/src/DomBatch.ts +22 -0
  72. package/src/DomInput.ts +2 -1
  73. package/src/KeyboardPress.ts +16 -0
  74. package/src/ReorderController.ts +54 -4
  75. package/src/index.ts +5 -3
  76. package/src/internal/appear-slot.ts +32 -0
  77. package/src/internal/appear.ts +462 -67
  78. package/src/internal/batch-writer.ts +95 -0
  79. package/src/internal/gate.ts +7 -3
  80. package/src/internal/input.ts +209 -25
  81. package/src/internal/keyboard-press.ts +45 -0
  82. package/src/internal/measure.ts +17 -1
  83. package/src/internal/projection.ts +272 -38
  84. package/src/internal/renderer.ts +4 -2
  85. package/src/internal/reorder.ts +85 -39
  86. package/src/internal/reveal.ts +10 -4
@@ -24,7 +24,10 @@
24
24
  * coordinator. A running node whose box didn't change is left alone. A trigger
25
25
  * during the pass's own flush repeats it (at most 5 rounds). Every node the pass
26
26
  * seeded takes its first step at the Frame loop's next tick, whose end flushes the
27
- * gate, so it moves in that Refresh frame whatever the Clock's state (ADR-0033).
27
+ * gate, so it moves in that Refresh frame whatever the Clock's state (ADR-0033). A
28
+ * pass that runs after its frame's tick, before the paint (a trigger during a tick,
29
+ * or the engine's observer delivery), takes the first step of the nodes it seeded
30
+ * itself, so they move in that frame too (ADR-0018 *Amendment (#673)*).
28
31
  * - COORDINATOR (one run on the Environment's Frame loop while >=1 node animates,
29
32
  * Q4; ADR-0027, #75): each tick steps every active node's progress spring, then
30
33
  * `deriveAll()` walks the active nodes TOP-DOWN (ancestors first) computing
@@ -59,6 +62,7 @@
59
62
  * `measure.ts` is the port's surface, and #16 maps what this file still does inline.
60
63
  */
61
64
  import * as Box from "@wardic/core/Box"
65
+ import * as Clock from "@wardic/core/Clock"
62
66
  import type * as Frame from "@wardic/core/Frame"
63
67
  import * as FrameLoop from "@wardic/core/FrameLoop"
64
68
  import * as Inertia from "@wardic/core/Inertia"
@@ -110,12 +114,13 @@ import {
110
114
  transitionRunning,
111
115
  contains,
112
116
  readCustomBases as readCustomBasesOf,
117
+ frameTime,
113
118
  readOpacity,
114
119
  readStickyShifts,
115
120
  } from "./measure.ts"
116
121
  import { DEFAULT_DRAG_TRANSITION, DEFAULT_LAYOUT_TRANSITION, type DragTransition, type LayoutTransition } from "./projection-defaults.ts"
117
122
  import { counted, watchPage, type Watched } from "./content-watch.ts"
118
- import { pending as appearRuns } from "./appear.ts"
123
+ import { pending as appearRuns } from "./appear-slot.ts"
119
124
  import { debugOf, reportFailure } from "./report.ts"
120
125
  import { blendRadius, borderRadiusCorrector, isUnitScale, SCALE_CORRECTORS, type ScaleCorrector, type ScaleCorrectorEntry, scaleRadius, ZERO_RADIUS } from "./scale-correction.ts"
121
126
  import { dashCase } from "./svg.ts"
@@ -531,6 +536,12 @@ type PaintLink =
531
536
  /** No links: an ancestor that doesn't move the twin, or the top of the chain. */
532
537
  const NO_LINKS: ReadonlyArray<PaintLink> = []
533
538
 
539
+ /**
540
+ * The map of an ancestor that drew no transform at the pass (#687): a Wardic element at identity,
541
+ * linked so a translate or scale it starts after the pass is followed.
542
+ */
543
+ const IDENTITY_MAP: PaintMap = { sx: 1, sy: 1, tx: 0, ty: 0 }
544
+
534
545
  /**
535
546
  * An axis-aligned map, `p → s·p + t` on each axis: a translate and a scale (ADR-0012, *Amendment
536
547
  * (#137)*). What a twin's ancestors' transforms do to its box, composed.
@@ -818,10 +829,13 @@ export interface RegisterNodeOptions {
818
829
  // #468.
819
830
  readonly skipAnimations?: () => boolean
820
831
  /**
821
- * The node's **Layout mode**, read at each layout animation's start: which parts of a layout change it
822
- * animates. Default `true`, position and size.
832
+ * The node's **Layout mode**, read at each layout animation's start, at each Measure pass for a
833
+ * `layoutRoot` until it isolates, and each frame for a Follower: which parts of a layout change it
834
+ * animates. Default `true`, position and size. `false`: none, for a node with no layout of its own (a
835
+ * `layoutRoot` or a `layoutScroll` alone, as Motion's): a move takes its new box at once, and a
836
+ * `layoutRoot` with it rides its ancestors' layout animations.
823
837
  */
824
- // ADR-0009, *Amendment (#42)*.
838
+ // ADR-0009, *Amendments (#42, #691)*.
825
839
  readonly layoutMode?: () => Projection.LayoutMode
826
840
  /**
827
841
  * The element's own scale per axis: its `scale` times its `scaleX` or `scaleY`, which the renderer
@@ -887,8 +901,10 @@ export interface RegisterNodeOptions {
887
901
  readonly layoutScroll?: boolean
888
902
  /**
889
903
  * Marks the element a layout root, as Motion's `layoutRoot`: it never animates its own layout change,
890
- * landing on it at once, and its subtree's projections stop at it, so a change outside it doesn't move
891
- * what's inside.
904
+ * landing on it at once, and its subtree's projections stop at it, placed against it. With a Layout mode
905
+ * other than `false` it also stays at its new box while an ancestor's layout animation runs, so a change
906
+ * outside it doesn't move what's inside, from the Measure pass that first finds it one, and from then on;
907
+ * with `false` it rides that animation, as Motion's `layoutRoot` with no `layout`.
892
908
  */
893
909
  // Self-snaps; bounds delta accumulation and the relativeParent search for its subtree; a persistent
894
910
  // relative anchor.
@@ -1216,7 +1232,7 @@ interface NodeState {
1216
1232
  readonly reducedMotion: () => boolean
1217
1233
  /** Whether the node's animations are skipped now (#468), read at each (re)start and release: its own, else never. */
1218
1234
  readonly skipAnimations: () => boolean
1219
- /** The node's Layout mode, read at each layout animation's start (ADR-0009, *Amendment (#42)*). */
1235
+ /** The node's Layout mode, read at each layout animation's start, at each pass for a layoutRoot until it isolates, and each frame for a Follower (ADR-0009, *Amendments (#42, #691)*). */
1220
1236
  readonly layoutMode: () => Projection.LayoutMode
1221
1237
  /** The element's own scale per axis, drawn on top of its projection (ADR-0010 *Amendment (#8)*). */
1222
1238
  readonly ownScale: () => Point.Point
@@ -1342,6 +1358,12 @@ interface NodeState {
1342
1358
  passPainted: Box.Box | undefined
1343
1359
  /** Marked a stable projection sub-root (ADR-0013): self-snaps, bounds the relative-parent search, persistent relativeParent. */
1344
1360
  readonly layoutRoot: boolean
1361
+ /**
1362
+ * Whether it isolates its subtree from its ancestors' layout animations (ADR-0013, *Amendment (#33)*):
1363
+ * a layoutRoot a Measure pass has found a Layout mode other than `false`, then for good, as Motion's
1364
+ * (#691). Kept here, so a frame reads a field, not the binding.
1365
+ */
1366
+ isolating: boolean
1345
1367
  /** This node's relative-projection anchor (ADR-0013): a 0–1 Point, or `false` to force absolute. */
1346
1368
  readonly layoutAnchor: Point.Point | false | undefined
1347
1369
  /** Last measured untransformed box (the FLIP "First"); `undefined` until first measure. */
@@ -1358,6 +1380,12 @@ interface NodeState {
1358
1380
  layoutBox: Box.Box | undefined
1359
1381
  /** Its layout animation's progress (0→1), a spring's or a tween's (ADR-0009 *Amendment (#171)*); `undefined` at rest. */
1360
1382
  flight: Flight | undefined
1383
+ /**
1384
+ * The frame time of the last coordinator tick that stepped it while it was still flying (ADR-0018
1385
+ * *Amendment (#673)*): a pass after that tick, in the same frame, doesn't step it again. A landing
1386
+ * clears it, so a node seeded again as it lands does take that pass's step.
1387
+ */
1388
+ steppedAt: number
1361
1389
  animating: boolean
1362
1390
  // --- tree (recomputed each measure pass via DOM-ancestry walk) ---
1363
1391
  /** Nearest ancestor projection node, or `undefined` at the root. */
@@ -1524,12 +1552,13 @@ const NO_OWN_TRANSLATE = (): Point.Point => NO_TRANSLATE
1524
1552
  const NO_VALUES: Readonly<Record<string, unknown>> = {}
1525
1553
 
1526
1554
  /**
1527
- * The transform a Measure pass holds `node` at (#443): its Transform template's, `""` (cleared) for a
1528
- * node with none. Per pass per node: a field read and an early return.
1555
+ * The transform a Measure pass holds `node` at (#443): its Transform template's, `none` for a node
1556
+ * with none (Motion's `resetTransform`), which is what an at-rest node already draws (#674). Per pass
1557
+ * per node: a field read and an early return.
1529
1558
  */
1530
1559
  const heldTransformFor = (node: { readonly heldTransform: (() => string) | undefined }): string => {
1531
1560
  const held = node.heldTransform
1532
- if (Predicate.isUndefined(held)) return ""
1561
+ if (Predicate.isUndefined(held)) return "none"
1533
1562
  return held()
1534
1563
  }
1535
1564
 
@@ -1810,6 +1839,9 @@ export const makeProjectionSystem = (
1810
1839
  // The coordinator's run on the Frame loop (#75): at most one, from the first node that
1811
1840
  // animates until none does. In the same Scope, so disposing the system interrupts it.
1812
1841
  const coordinator = runtime.runSync(FiberHandle.make<void, never>().pipe(Scope.provide(scope)))
1842
+ // The Environment's Frame loop: the coordinator runs on it, the engine's hook is on its ticks, and a
1843
+ // trigger reads whether its Late window is open (#673, #680).
1844
+ const loop = runtime.runSync(Effect.service(FrameLoop.FrameLoop))
1813
1845
  // Whether the coordinator's step is running: a stop from inside it settles the run.
1814
1846
  let inStep = false
1815
1847
  // The turn a turning flight's curve gives at its target just placed (#438), for `derive` to draw:
@@ -1821,6 +1853,17 @@ export const makeProjectionSystem = (
1821
1853
  let passQueued = false
1822
1854
  let inPass = false
1823
1855
  let triggeredDuringPass = false
1856
+ // An after-tick pass (ADR-0018 *Amendment (#673)*): whether the queued pass runs after its frame's
1857
+ // tick, before the paint, as every trigger for it did (one during a Frame loop tick, its hooks
1858
+ // included; one during the engine's observer delivery; one during an after-tick pass's own step);
1859
+ // whether the observer is delivering; and whether an after-tick pass's step is being applied.
1860
+ let passAfterTick = false
1861
+ let inDelivery = false
1862
+ let inAfterTickStep = false
1863
+ // The frame time and dt of the Frame loop's last tick, from the engine's `afterTick` hook: an
1864
+ // after-tick pass in that frame steps at its dt. `-2` before any, which no frame time equals.
1865
+ let tickFrame = -2
1866
+ let tickDt = 0
1824
1867
  // Whether a **Declared layout change** in this task has taken its Measurements (#4): the end-of-task
1825
1868
  // pass, which animates from them, clears it.
1826
1869
  let declared = false
@@ -2081,6 +2124,19 @@ export const makeProjectionSystem = (
2081
2124
  return stack[i - 1]
2082
2125
  }
2083
2126
 
2127
+ /**
2128
+ * The newest twin below `stack[from]` that isn't leaving, with its index: the one a Lead that leaves
2129
+ * hands over to (#682). Motion's `NodeStack.relegate` promotes only a member still present, so a
2130
+ * twin on a page that is leaving too never takes over. `undefined` when every one is leaving.
2131
+ */
2132
+ const presentBelow = (stack: ReadonlyArray<NodeState>, from: number): readonly [NodeState, number] | undefined => {
2133
+ for (let i = from - 1; i >= 0; i--) {
2134
+ const node = stack[i]
2135
+ if (Predicate.isNotUndefined(node) && Bool.not(node.leaving)) return [node, i]
2136
+ }
2137
+ return undefined
2138
+ }
2139
+
2084
2140
  /** Whether `node` is a Follower: in a `layoutId` stack but NOT its (newest-live) Lead. */
2085
2141
  const isFollower = (node: NodeState): boolean =>
2086
2142
  Predicate.isNotUndefined(node.layoutId) && leadOf(node.layoutId) !== node
@@ -2601,8 +2657,9 @@ export const makeProjectionSystem = (
2601
2657
  */
2602
2658
  const layoutTargetOf = (node: NodeState, box: Box.Box): Box.Box => {
2603
2659
  // ISOLATED (ADR-0013, *Amendment (#33)*): a layoutRoot sits at its new box, its projection
2604
- // counter-acting its ancestors' layout animations; only their transforms carry it.
2605
- if (node.layoutRoot) return offsetBox(box, carryOf(node))
2660
+ // counter-acting its ancestors' layout animations; only their transforms carry it. Not one with no
2661
+ // layout of its own (Layout mode `false`, #691): it rides them, as Motion's does.
2662
+ if (node.isolating) return offsetBox(box, carryOf(node))
2606
2663
  const rp = relativeParentOf(node)
2607
2664
  const rpBox = boxOf(rp)
2608
2665
  if (Predicate.isNotUndefined(rp) && Predicate.isNotUndefined(rpBox) && Predicate.isNotUndefined(rp.lastTarget)) {
@@ -3003,6 +3060,36 @@ export const makeProjectionSystem = (
3003
3060
  return UndefinedOr.map(linksAt(el, reads, shift, documentScroll), (own) => Arr.appendAll(above, own))
3004
3061
  }
3005
3062
 
3063
+ /**
3064
+ * The Wardic elements above `el` up to `<body>` that draw no transform now (#687), into `out`: not a
3065
+ * projection node (linked for its own scale already), not one this pass read for its transform
3066
+ * (`reads`), not one a running transition holds. `walked` keeps a walk from going over what an
3067
+ * earlier twin's walked. Touches no DOM but the parent links. Read phase only.
3068
+ */
3069
+ const untransformedAbove = (el: HTMLElement | null, reads: ReadonlyMap<Element, AncestorRead>, walked: Set<Element>, out: Array<Element>): void => {
3070
+ let at = el
3071
+ while (Predicate.isNotNull(at)) {
3072
+ if (isDocumentTop(at)) return
3073
+ // Walked from another twin, and so everything above it too.
3074
+ if (walked.has(at)) return
3075
+ walked.add(at)
3076
+ const candidate = at
3077
+ at = at.parentElement
3078
+ if (elementToNode.has(candidate)) continue
3079
+ if (Bool.not(elementValues.has(candidate))) continue
3080
+ if (reads.has(candidate)) continue
3081
+ if (passUnheld.has(candidate)) continue
3082
+ out.push(candidate)
3083
+ }
3084
+ }
3085
+
3086
+ /** `el`'s transform origin on the page: its box as read now, and its computed `transform-origin`. Read phase only. */
3087
+ const pageOriginOf = (el: Element): Point.Point => {
3088
+ const box = el.getBoundingClientRect()
3089
+ const origin = transformOriginOf(el)
3090
+ return { x: box.left + origin.x, y: box.top + origin.y }
3091
+ }
3092
+
3006
3093
  /**
3007
3094
  * The ancestors of twin `node` whose transforms move it, outermost first, in its frame (ADR-0012,
3008
3095
  * *Amendment (#137)*): each element this pass found moving it, and each projection node above it,
@@ -3719,16 +3806,25 @@ export const makeProjectionSystem = (
3719
3806
  // so this is still the minimal set, not a widening.
3720
3807
  // A templated element is held at its Transform template's with no transform of Wardic's (#443,
3721
3808
  // Motion's `transformTemplate(values, "")`), so a static part of it, such as centring, is measured.
3722
- const savedTransforms: Array<string> = []
3809
+ // A node that already draws what it's held at, as every at-rest node does (`none`), isn't written
3810
+ // or restored (#674, Motion's `resetTransform` skips it too): `undefined` in `savedTransforms`.
3811
+ const savedTransforms: Array<string | undefined> = []
3723
3812
  for (const node of ordered) {
3724
3813
  // Its app's `onBeforeLayoutMeasure` (#443), before its transform is held for the read.
3725
3814
  if (Predicate.isNotUndefined(node.onBeforeMeasure)) callMeasureHook(node.onBeforeMeasure, "onBeforeLayoutMeasure")
3726
- savedTransforms.push(node.element.style.transform)
3727
- node.element.style.transform = heldTransformFor(node)
3815
+ const own = node.element.style.transform
3816
+ const held = heldTransformFor(node)
3728
3817
  // A server's Appear animation not yet handed off (#245, ADR-0044 *Amendment (#245)*): its CSS
3729
3818
  // transform beats an inline one, but not an important one. Its timeline runs on; the restore
3730
3819
  // below gives the old value back, at its own priority.
3731
- if (appearRuns(node.element)) node.element.style.setProperty("transform", "none", "important")
3820
+ const appearing = appearRuns(node.element)
3821
+ if (Bool.and(own === held, Bool.not(appearing))) {
3822
+ savedTransforms.push(undefined)
3823
+ continue
3824
+ }
3825
+ savedTransforms.push(own)
3826
+ node.element.style.transform = held
3827
+ if (appearing) node.element.style.setProperty("transform", "none", "important")
3732
3828
  }
3733
3829
 
3734
3830
  // --- READ: no DOM writes until the next banner. ---------------------------
@@ -3829,13 +3925,23 @@ export const makeProjectionSystem = (
3829
3925
  holds = Arr.map(wanted, ([el, style]) => holdTransform(el, style))
3830
3926
  // --- READ: each one's box, held, and so its transform origin on the page. ------
3831
3927
  Arr.forEach(wanted, ([el], k) => {
3832
- const box = el.getBoundingClientRect()
3833
- const origin = transformOriginOf(el)
3928
+ const origin = pageOriginOf(el)
3834
3929
  ancestorReads.set(el, {
3835
- origin: { x: box.left + origin.x, y: box.top + origin.y },
3836
- pass: UndefinedOr.map(passTransforms[k], (m) => mapAbout({ x: box.left + origin.x, y: box.top + origin.y }, m.e, m.f, m.a, m.d)),
3930
+ origin,
3931
+ pass: UndefinedOr.map(passTransforms[k], (m) => mapAbout(origin, m.e, m.f, m.a, m.d)),
3837
3932
  })
3838
3933
  })
3934
+ // Each moved twin's Wardic ancestors at identity (#687): read as the others are, so its chain links
3935
+ // them, and a translate or scale one starts after this pass is followed. Only when a twin moved.
3936
+ let walked: Set<Element> | undefined
3937
+ for (let i = 0; i < ordered.length; i++) {
3938
+ if (Predicate.isUndefined(ordered[i].layoutId)) continue
3939
+ if (Bool.not(moved[i])) continue
3940
+ if (Predicate.isUndefined(walked)) walked = new Set<Element>()
3941
+ const untransformed: Array<Element> = []
3942
+ untransformedAbove(ordered[i].element.parentElement, ancestorReads, walked, untransformed)
3943
+ for (const el of untransformed) ancestorReads.set(el, { origin: pageOriginOf(el), pass: IDENTITY_MAP })
3944
+ }
3839
3945
  // --- READ: those nodes' boxes again, with nothing transformed. ----------
3840
3946
  if (Arr.isArrayNonEmpty(wanted)) {
3841
3947
  for (const i of under) {
@@ -3857,7 +3963,10 @@ export const makeProjectionSystem = (
3857
3963
  // replaced could only ever strand one), and the gate's `flush` has no
3858
3964
  // `finally` of its own, so it would stay latched mid-flush.
3859
3965
  releaseTransforms(holds)
3860
- for (let i = 0; i < ordered.length; i++) ordered[i].element.style.transform = savedTransforms[i]
3966
+ for (let i = 0; i < ordered.length; i++) {
3967
+ const saved = savedTransforms[i]
3968
+ if (Predicate.isNotUndefined(saved)) ordered[i].element.style.transform = saved
3969
+ }
3861
3970
  }
3862
3971
 
3863
3972
  // Each moved twin's paint deltas, between its box and its box as painted, both in its
@@ -3909,6 +4018,12 @@ export const makeProjectionSystem = (
3909
4018
  dropBox(node)
3910
4019
  continue
3911
4020
  }
4021
+ // Whether a layoutRoot isolates its subtree (ADR-0013, *Amendment (#33)*): from the first pass that
4022
+ // finds it a layout of its own, and from then on, as Motion's (its `didUpdate` handler, attached once
4023
+ // `layout` or `layoutId` is set, at mount or a later change, is never taken off). One only a
4024
+ // `layoutRoot` makes (Layout mode `false`) is its subtree's frame and no more (#691). Read here, and
4025
+ // only until then: a read each frame cost bench:solid's page scene 7–12% at 330 roots, and each pass 5%.
4026
+ if (node.layoutRoot && !node.isolating) node.isolating = node.layoutMode() !== false
3912
4027
  // Store the box in the SCROLL-STABLE frame (ADR-0012), so a scroll change
3913
4028
  // between triggers doesn't leak into the delta. Every scroll offset was
3914
4029
  // sampled in the read phase, so the whole ancestor chain is available.
@@ -4050,10 +4165,12 @@ export const makeProjectionSystem = (
4050
4165
  // moves from where the leaver painted, as a layout change, no handover: rebased as a
4051
4166
  // Switch seed is, and drawn there on its first frame, its own scale divided out. A Switch
4052
4167
  // seed the same leaving twin left is passed over: the key decides where it comes from.
4168
+ // Shaped by its Layout mode before the check, as a restart's is: one that leaves nothing to
4169
+ // move, a node with no layout of its own (Layout mode `false`, #691) among them, starts none.
4053
4170
  if (Predicate.isNotUndefined(enteredFrom)) {
4054
- const origin = undrawnFor(node, unpaintedOf(node, offsetUnlessZero(enteredFrom, rootFrameShift(node, documentScroll))))
4171
+ const origin = shapedOrigin(node, undrawnFor(node, unpaintedOf(node, offsetUnlessZero(enteredFrom, rootFrameShift(node, documentScroll)))), newBox)
4055
4172
  if (Bool.not(boxesEqual(origin, newBox))) {
4056
- node.origin = shapedOrigin(node, origin, newBox)
4173
+ node.origin = origin
4057
4174
  node.layoutBox = newBox
4058
4175
  node.flight = startFlight(node)
4059
4176
  node.animating = true
@@ -4162,7 +4279,9 @@ export const makeProjectionSystem = (
4162
4279
  * of `sink.flushPass(round)` until a round ends with no new trigger (a trigger
4163
4280
  * during a round comes from an effect in its flush), at most {@link MAX_ROUNDS};
4164
4281
  * past the cap the rest runs as a fresh Measure pass in the next task. The nodes it
4165
- * seeded take their first step at the Frame loop's next tick (ADR-0033). Traced as one
4282
+ * seeded take their first step at the Frame loop's next tick (ADR-0033), or, in a pass that runs
4283
+ * after its frame's tick, in the pass itself, after its rounds (ADR-0018 *Amendment (#673)*): how
4284
+ * many is its span's `stepped`. Traced as one
4166
4285
  * `wardic.projection.measure` span annotated with the
4167
4286
  * node counts, how many nodes it seeded, how many it gave a slot-only update in a
4168
4287
  * dragged subtree (`dragBlocked`), how many rounds it ran, and whether a window
@@ -4170,6 +4289,8 @@ export const makeProjectionSystem = (
4170
4289
  */
4171
4290
  const measurePass: Effect.Effect<void> = Effect.suspend(() => {
4172
4291
  passQueued = false
4292
+ const afterTick = passAfterTick
4293
+ passAfterTick = false
4173
4294
  // A Declared layout change's Measurements serve this pass, and the next task's call takes its own.
4174
4295
  declared = false
4175
4296
  const seeded = new Set<NodeState>()
@@ -4200,6 +4321,9 @@ export const makeProjectionSystem = (
4200
4321
  // The nodes whose own size this pass took (#453): the next delivery finds its own.
4201
4322
  ownSized.clear()
4202
4323
  }
4324
+ // After its frame's tick, the nodes it seeded take their first step now, painted in this frame (#673).
4325
+ let stepped = 0
4326
+ if (afterTick) stepped = stepAfterTick(seeded)
4203
4327
  for (const listener of passEndListeners) {
4204
4328
  try {
4205
4329
  listener()
@@ -4219,6 +4343,7 @@ export const makeProjectionSystem = (
4219
4343
  nodes: nodes.size,
4220
4344
  active: active.size,
4221
4345
  seeded: seeded.size,
4346
+ stepped,
4222
4347
  dragBlocked: dragBlocked.size,
4223
4348
  rounds,
4224
4349
  blocked,
@@ -4226,6 +4351,59 @@ export const makeProjectionSystem = (
4226
4351
  })
4227
4352
  }).pipe(Effect.withSpan("wardic.projection.measure", undefined, { captureStackTrace: false }))
4228
4353
 
4354
+ /**
4355
+ * Whether a trigger now comes after its frame's tick and before its paint, known from where it runs
4356
+ * (ADR-0018 *Amendment (#673)*): in the Frame loop's Late window, from a tick's first step through the
4357
+ * microtasks its frame's code queued (the gate's flush and the app effects in it, the engine's
4358
+ * callbacks, Solid 2's effect flush; ADR-0027 *Amendment (#680)*); during the engine's observer
4359
+ * delivery, which follows a frame's rAF callbacks; or during an after-tick pass's own step. App code in
4360
+ * a later rAF callback, or in an app observer, can't be told from a task after the paint, so its pass
4361
+ * holds a frame as before.
4362
+ */
4363
+ const afterTickNow = (): boolean => {
4364
+ if (inDelivery) return true
4365
+ if (inAfterTickStep) return true
4366
+ return loop.inLateWindow()
4367
+ }
4368
+
4369
+ /**
4370
+ * An after-tick pass's step (ADR-0018 *Amendment (#673)*): each node it seeded that this frame's tick
4371
+ * didn't step, still flying, takes one step, and their group is derived and applied at once, so the
4372
+ * frame paints the first step and not the origin. At the dt of the tick that ran in this frame, as
4373
+ * every other node advanced by; `NOMINAL_DT` when none did (a Cold start). Its start callbacks follow,
4374
+ * after the frame is in the DOM (ADR-0039). A flight this step brings to rest lands at the next tick.
4375
+ * How many it stepped: the pass's `stepped`.
4376
+ */
4377
+ const stepAfterTick = (seeded: ReadonlySet<NodeState>): number => {
4378
+ if (seeded.size === 0) return 0
4379
+ // Inside the frame here, where the timeline's time is the frame's timestamp exactly (#673's probe).
4380
+ const at = frameTime()
4381
+ let dt = Clock.NOMINAL_DT
4382
+ if (tickFrame === at) dt = Math.min(tickDt, Machine.MAX_DT)
4383
+ const stepped = new Set<NodeState>()
4384
+ for (const node of seeded) {
4385
+ if (node.steppedAt === at) continue
4386
+ if (!active.has(node)) continue
4387
+ if (Predicate.isUndefined(node.flight)) continue
4388
+ if (node.dragging) continue
4389
+ stepFlight(node, dt)
4390
+ noteFlight(node, false)
4391
+ node.steppedAt = at
4392
+ stepped.add(node)
4393
+ }
4394
+ if (stepped.size === 0) return 0
4395
+ inAfterTickStep = true
4396
+ try {
4397
+ sink.flushPass(() => deriveGroup(groupOf(stepped)))
4398
+ } finally {
4399
+ inAfterTickStep = false
4400
+ }
4401
+ if (Arr.isArrayNonEmpty(flightStarts)) {
4402
+ for (const node of flightStarts.splice(0)) callAppIfAny(node.onLayoutAnimationStart(), "onLayoutAnimationStart")
4403
+ }
4404
+ return stepped.size
4405
+ }
4406
+
4229
4407
  /**
4230
4408
  * Queue the Measure pass for the end of the current task (one per task, however
4231
4409
  * many triggers). A trigger while a pass runs its rounds repeats the pass instead.
@@ -4238,8 +4416,14 @@ export const makeProjectionSystem = (
4238
4416
  triggeredDuringPass = true
4239
4417
  return
4240
4418
  }
4241
- if (passQueued) return
4419
+ // A pass runs after the tick only when every trigger for it did (#673).
4420
+ const after = afterTickNow()
4421
+ if (passQueued) {
4422
+ if (!after) passAfterTick = false
4423
+ return
4424
+ }
4242
4425
  passQueued = true
4426
+ passAfterTick = after
4243
4427
  FiberSet.addUnsafe(
4244
4428
  taskFibers,
4245
4429
  runtime.runFork(
@@ -4307,7 +4491,10 @@ export const makeProjectionSystem = (
4307
4491
  * whose flights have all ended. The Frame loop calls its hooks in the order they were added, and the
4308
4492
  * provider adds its gate's first, so the frame is in the DOM. Per frame: nothing to do is two reads.
4309
4493
  */
4310
- const afterTick = (): undefined => {
4494
+ const afterTick = (dt: number): undefined => {
4495
+ // This tick's frame and dt, for an after-tick pass in the same frame (#673): one read a tick.
4496
+ tickFrame = frameTime()
4497
+ tickDt = dt
4311
4498
  if (Arr.isArrayNonEmpty(flightStarts)) {
4312
4499
  for (const node of flightStarts.splice(0)) callAppIfAny(node.onLayoutAnimationStart(), "onLayoutAnimationStart")
4313
4500
  }
@@ -4320,7 +4507,7 @@ export const makeProjectionSystem = (
4320
4507
  checkSettlings()
4321
4508
  return undefined
4322
4509
  }
4323
- runtime.runSync(FrameLoop.FrameLoop.use((loop) => loop.afterTick(afterTick)).pipe(Scope.provide(scope)))
4510
+ runtime.runSync(loop.afterTick(afterTick).pipe(Scope.provide(scope)))
4324
4511
 
4325
4512
  /**
4326
4513
  * A **Declared layout change**'s Measurements (#4, ADR-0038): one slot-only round over every node at
@@ -4537,10 +4724,13 @@ export const makeProjectionSystem = (
4537
4724
  const settled: Array<NodeState> = []
4538
4725
  // 0) The first frame after a change: things there kept where they were seen (#480).
4539
4726
  if (seenKeeps.size + unseen.size > 0) settleSeen()
4727
+ // This frame's time, stamped on each node it steps, so a pass after it doesn't step one again (#673).
4728
+ const at = frameTime()
4540
4729
  // 1) Step every active node's springs (no derive yet — the tree-aware derive needs
4541
4730
  // ALL springs advanced before computing parent-first): its layout animation's
4542
4731
  // progress, and its Release offset's two axes. It settles when both are at rest.
4543
4732
  for (const node of active) {
4733
+ node.steppedAt = at
4544
4734
  // A dragging node (ADR-0016) follows the pointer — kept active + derived each frame,
4545
4735
  // never settled. A layout animation its grab left running goes on under it.
4546
4736
  if (node.dragging) {
@@ -4627,6 +4817,8 @@ export const makeProjectionSystem = (
4627
4817
  // The running nodes placed in these landing nodes' frames go on from where they paint (#144).
4628
4818
  landFrames(settled)
4629
4819
  for (const node of settled) {
4820
+ // Landed: a pass after this tick that seeds it again steps it, its last step being its landing's (#673).
4821
+ node.steppedAt = Number.NaN
4630
4822
  node.releasing = false
4631
4823
  node.release = undefined
4632
4824
  node.animating = false
@@ -5030,6 +5222,23 @@ export const makeProjectionSystem = (
5030
5222
  runtime.runFork(FiberHandle.clear(coordinator))
5031
5223
  }
5032
5224
 
5225
+ /**
5226
+ * A disposed Lead's hand-over (#682): the newest twin in `stack` that isn't leaving becomes the Lead,
5227
+ * promoted from `leaver`'s box. With none, nothing takes over, and every twin left, each leaving,
5228
+ * ends its handover now.
5229
+ */
5230
+ const handOverFrom = (leaver: NodeState, stack: Array<NodeState>): void => {
5231
+ const next = presentBelow(stack, stack.length)
5232
+ if (Predicate.isNotUndefined(next)) {
5233
+ const [twin, i] = next
5234
+ stack.splice(i, 1)
5235
+ stack.push(twin)
5236
+ promoteFrom(twin, leaver)
5237
+ return
5238
+ }
5239
+ for (const twin of [...stack]) finishLeaver(twin)
5240
+ }
5241
+
5033
5242
  /** Promote `node` to an animating Lead from `fromBox` → its own box (un-hide + move home). */
5034
5243
  const promoteFrom = (node: NodeState, from: NodeState): void => {
5035
5244
  const ownBox = node.retained
@@ -5138,6 +5347,7 @@ export const makeProjectionSystem = (
5138
5347
  origin: undefined,
5139
5348
  layoutBox: recent.box,
5140
5349
  flight: undefined,
5350
+ steppedAt: Number.NaN,
5141
5351
  animating: false,
5142
5352
  parent: undefined,
5143
5353
  depth: 0,
@@ -5169,6 +5379,7 @@ export const makeProjectionSystem = (
5169
5379
  passDelta: IDENTITY_DELTA,
5170
5380
  passPainted: undefined,
5171
5381
  layoutRoot: false,
5382
+ isolating: false,
5172
5383
  layoutAnchor,
5173
5384
  dragging: false,
5174
5385
  grabBox: undefined,
@@ -5194,16 +5405,19 @@ export const makeProjectionSystem = (
5194
5405
  // later dispose then SKIPS removal), demote it to a Follower, and promote the twin.
5195
5406
  if (Predicate.isNotUndefined(live)) {
5196
5407
  const stack = stacks.get(layoutId)
5408
+ if (Predicate.isUndefined(stack)) return false
5197
5409
  const isLead = leadOf(layoutId) === live
5198
- const twin = Bool.match(isLead, { onTrue: () => priorLeadOf(live), onFalse: () => leadOf(layoutId) })
5199
- if (Predicate.isUndefined(twin) || twin === live || Predicate.isUndefined(stack)) return false // lone leave
5410
+ // A Lead hands over only to a twin that isn't leaving (#682): with none, a lone leave, and it
5411
+ // goes on as the Lead while presence runs its own exit, as Motion's relegate leaves it.
5412
+ const below = Bool.match(isLead, { onTrue: () => presentBelow(stack, stack.indexOf(live)), onFalse: () => undefined })
5413
+ const twin = Bool.match(isLead, { onTrue: () => UndefinedOr.map(below, ([node]) => node), onFalse: () => leadOf(layoutId) })
5414
+ if (Predicate.isUndefined(twin) || twin === live) return false // lone leave
5200
5415
  live.leaving = true
5201
5416
  live.onLeaveDone = onDone
5202
- if (isLead) {
5203
- // Swap so the twin becomes the Lead (last); el becomes a Follower below it.
5204
- const last = stack.length - 1
5205
- stack[last - 1] = live
5206
- stack[last] = twin
5417
+ if (Predicate.isNotUndefined(below)) {
5418
+ // The twin becomes the Lead (last); el stays below it, a Follower.
5419
+ stack.splice(below[1], 1)
5420
+ stack.push(twin)
5207
5421
  promoteFrom(twin, live)
5208
5422
  }
5209
5423
  // After a possible swap, re-read the (new) Lead — never assert it exists.
@@ -5220,6 +5434,8 @@ export const makeProjectionSystem = (
5220
5434
  // transient leaving Follower from the recorded box (the re-introduce model).
5221
5435
  const lead = leadOf(layoutId)
5222
5436
  if (Predicate.isUndefined(lead) || lead.element === el || Predicate.isUndefined(recent)) return false
5437
+ // No twin to come back to but one leaving itself (#682).
5438
+ if (lead.leaving) return false
5223
5439
  const last = recent.last
5224
5440
  if (Predicate.isUndefined(last)) return false
5225
5441
  const stack = stacks.get(layoutId)
@@ -5296,6 +5512,8 @@ export const makeProjectionSystem = (
5296
5512
  if (Predicate.isUndefined(lead)) return
5297
5513
  if (Predicate.isUndefined(stack)) return
5298
5514
  if (lead.element === inner) return
5515
+ // Not onto a Lead that is leaving itself (#682): it has no handover to ride.
5516
+ if (lead.leaving) return
5299
5517
  if (Bool.not(takesOver(lead))) return
5300
5518
  const twin = makeLeavingNode(inner, held.layoutId, last, () => undefined, undefined, chainOf(held))
5301
5519
  recent.reintroduced = true
@@ -5594,6 +5812,16 @@ export const makeProjectionSystem = (
5594
5812
  * Motion's projection never sees it; beside a real resize, the pass gives them a slot-only update.
5595
5813
  */
5596
5814
  const onObserved = (entries: ReadonlyArray<ResizeObserverEntry>): void => {
5815
+ // A pass this delivery queues runs after its frame's tick, before its paint (#673).
5816
+ inDelivery = true
5817
+ try {
5818
+ delivered(entries)
5819
+ } finally {
5820
+ inDelivery = false
5821
+ }
5822
+ }
5823
+ /** {@link onObserved}'s delivery, read. */
5824
+ const delivered = (entries: ReadonlyArray<ResizeObserverEntry>): void => {
5597
5825
  // A node's own resize runs a pass, which reads the page as well.
5598
5826
  const unmeasured = Arr.filter(entries, Predicate.not(alreadyMeasured))
5599
5827
  if (Arr.isArrayNonEmpty(unmeasured)) {
@@ -5662,6 +5890,7 @@ export const makeProjectionSystem = (
5662
5890
  origin: undefined,
5663
5891
  layoutBox: undefined,
5664
5892
  flight: undefined,
5893
+ steppedAt: Number.NaN,
5665
5894
  animating: false,
5666
5895
  parent: undefined,
5667
5896
  depth: 0,
@@ -5691,6 +5920,8 @@ export const makeProjectionSystem = (
5691
5920
  passDelta: IDENTITY_DELTA,
5692
5921
  passPainted: undefined,
5693
5922
  layoutRoot: opts.layoutRoot === true,
5923
+ // Set at its first Measure pass, before any frame derives it.
5924
+ isolating: false,
5694
5925
  layoutAnchor: opts.layoutAnchor,
5695
5926
  dragging: false,
5696
5927
  grabBox: undefined,
@@ -5891,8 +6122,11 @@ export const makeProjectionSystem = (
5891
6122
  active.delete(node)
5892
6123
  deleteNode(node)
5893
6124
  painted.delete(node)
5894
- // Stack relegation / promotion (ADR-0010): a leaving Lead promotes the new
5895
- // newest node, animating it FROM the leaver's box (un-hide + move home).
6125
+ // Stack relegation / promotion (ADR-0010): a Lead that leaves promotes the newest twin
6126
+ // that isn't leaving, animating it FROM the leaver's box (un-hide + move home), as Motion's
6127
+ // relegate does. With none, every twin left is leaving with its page: nothing takes over, and
6128
+ // the leaver stays where it's drawn, and their handovers end now, so their pages go once
6129
+ // their own exits do (#682).
5896
6130
  if (Predicate.isNotUndefined(node.layoutId)) {
5897
6131
  const stack = stacks.get(node.layoutId)
5898
6132
  if (Predicate.isNotUndefined(stack)) {
@@ -5900,7 +6134,7 @@ export const makeProjectionSystem = (
5900
6134
  const i = stack.indexOf(node)
5901
6135
  if (i >= 0) stack.splice(i, 1)
5902
6136
  if (stack.length === 0) stacks.delete(node.layoutId)
5903
- if (stack.length > 0 && wasLead) promoteFrom(stack[stack.length - 1], node)
6137
+ if (stack.length > 0 && wasLead) handOverFrom(node, stack)
5904
6138
  }
5905
6139
  }
5906
6140
  if (active.size === 0) stopTicking()
@@ -38,7 +38,8 @@ import * as UndefinedOr from "effect/UndefinedOr"
38
38
  * included); `fn` is the CSS function name it renders as; `identity` is core's
39
39
  * (ADR-0022), the value at which `project` leaves the key out (ADR-0023).
40
40
  */
41
- const TRANSFORM_FUNCS: ReadonlyArray<{ readonly key: string; readonly fn: string; readonly identity: number }> = [
41
+ // Exported for the Batch writer (#665), which draws a member's transform in the same order.
42
+ export const TRANSFORM_FUNCS: ReadonlyArray<{ readonly key: string; readonly fn: string; readonly identity: number }> = [
42
43
  // translate group — shorthands x/y/z map onto translateX/Y/Z
43
44
  { key: "x", fn: "translateX" },
44
45
  { key: "y", fn: "translateY" },
@@ -197,7 +198,8 @@ const formatTransformValue = (key: string, value: unknown): string => {
197
198
  }
198
199
 
199
200
  /** A transform key's default unit; none for a key the table doesn't name. */
200
- const unitOf = (key: string): TransformUnit => {
201
+ // Exported for the Batch writer (#665).
202
+ export const unitOf = (key: string): TransformUnit => {
201
203
  const unit: TransformUnit | undefined = TRANSFORM_UNITS[key]
202
204
  if (Predicate.isUndefined(unit)) return ""
203
205
  return unit