@wardic/dom 1.3.2 → 1.5.0-next.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 (112) hide show
  1. package/dist/Color.d.ts +2 -1
  2. package/dist/Color.d.ts.map +1 -1
  3. package/dist/Color.js +3 -1
  4. package/dist/Color.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 +2 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/internal/batch-writer.d.ts.map +1 -1
  10. package/dist/internal/batch-writer.js +9 -13
  11. package/dist/internal/batch-writer.js.map +1 -1
  12. package/dist/internal/clock.d.ts +3 -3
  13. package/dist/internal/clock.d.ts.map +1 -1
  14. package/dist/internal/clock.js +25 -7
  15. package/dist/internal/clock.js.map +1 -1
  16. package/dist/internal/colorSpaces.d.ts +8 -0
  17. package/dist/internal/colorSpaces.d.ts.map +1 -0
  18. package/dist/internal/colorSpaces.js +26 -0
  19. package/dist/internal/colorSpaces.js.map +1 -0
  20. package/dist/internal/colors.d.ts +0 -7
  21. package/dist/internal/colors.d.ts.map +1 -1
  22. package/dist/internal/colors.js +3 -15
  23. package/dist/internal/colors.js.map +1 -1
  24. package/dist/internal/default-transition.d.ts +2 -2
  25. package/dist/internal/default-transition.d.ts.map +1 -1
  26. package/dist/internal/default-transition.js +23 -9
  27. package/dist/internal/default-transition.js.map +1 -1
  28. package/dist/internal/input.d.ts.map +1 -1
  29. package/dist/internal/input.js +18 -0
  30. package/dist/internal/input.js.map +1 -1
  31. package/dist/internal/layout-box.d.ts +29 -0
  32. package/dist/internal/layout-box.d.ts.map +1 -0
  33. package/dist/internal/layout-box.js +48 -0
  34. package/dist/internal/layout-box.js.map +1 -0
  35. package/dist/internal/measure.d.ts +1 -19
  36. package/dist/internal/measure.d.ts.map +1 -1
  37. package/dist/internal/measure.js +4 -47
  38. package/dist/internal/measure.js.map +1 -1
  39. package/dist/internal/projection.d.ts +5 -1
  40. package/dist/internal/projection.d.ts.map +1 -1
  41. package/dist/internal/projection.js +45 -10
  42. package/dist/internal/projection.js.map +1 -1
  43. package/dist/internal/renderer.d.ts +36 -14
  44. package/dist/internal/renderer.d.ts.map +1 -1
  45. package/dist/internal/renderer.js +213 -118
  46. package/dist/internal/renderer.js.map +1 -1
  47. package/dist/internal/reorder.d.ts +7 -0
  48. package/dist/internal/reorder.d.ts.map +1 -1
  49. package/dist/internal/reorder.js +41 -21
  50. package/dist/internal/reorder.js.map +1 -1
  51. package/dist/internal/starting-style.js +5 -5
  52. package/dist/internal/transform-keys.d.ts +3 -2
  53. package/dist/internal/transform-keys.d.ts.map +1 -1
  54. package/dist/internal/transform-keys.js +21 -9
  55. package/dist/internal/transform-keys.js.map +1 -1
  56. package/dist/unstable/BatchMembers.js +1 -1
  57. package/dist/unstable/DragTrack.d.ts +1 -1
  58. package/dist/unstable/DragTrack.d.ts.map +1 -1
  59. package/dist/unstable/DragTrack.js +16 -4
  60. package/dist/unstable/DragTrack.js.map +1 -1
  61. package/dist/unstable/ElementSetup.js +1 -1
  62. package/dist/unstable/Feature.d.ts +3 -2
  63. package/dist/unstable/Feature.d.ts.map +1 -1
  64. package/dist/unstable/Feature.js +3 -2
  65. package/dist/unstable/Feature.js.map +1 -1
  66. package/dist/unstable/GestureFeatures.d.ts +6 -1
  67. package/dist/unstable/GestureFeatures.d.ts.map +1 -1
  68. package/dist/unstable/GestureFeatures.js +8 -3
  69. package/dist/unstable/GestureFeatures.js.map +1 -1
  70. package/dist/unstable/GestureInfo.d.ts +11 -0
  71. package/dist/unstable/GestureInfo.d.ts.map +1 -1
  72. package/dist/unstable/GestureInfo.js +8 -0
  73. package/dist/unstable/GestureInfo.js.map +1 -1
  74. package/dist/unstable/Imperative.d.ts +1 -1
  75. package/dist/unstable/Imperative.d.ts.map +1 -1
  76. package/dist/unstable/Imperative.js.map +1 -1
  77. package/dist/unstable/MemberHold.js +1 -1
  78. package/dist/unstable/MemberHold.js.map +1 -1
  79. package/dist/unstable/PresenceController.d.ts +36 -0
  80. package/dist/unstable/PresenceController.d.ts.map +1 -1
  81. package/dist/unstable/PresenceController.js +41 -17
  82. package/dist/unstable/PresenceController.js.map +1 -1
  83. package/dist/unstable/WardConfig.d.ts +5 -5
  84. package/dist/unstable/WardConfig.d.ts.map +1 -1
  85. package/dist/unstable/features/TimelineKeys.js +1 -1
  86. package/package.json +3 -3
  87. package/src/Color.ts +2 -1
  88. package/src/index.ts +2 -2
  89. package/src/internal/batch-writer.ts +9 -14
  90. package/src/internal/clock.ts +25 -7
  91. package/src/internal/colorSpaces.ts +27 -0
  92. package/src/internal/colors.ts +3 -36
  93. package/src/internal/default-transition.ts +22 -8
  94. package/src/internal/input.ts +18 -0
  95. package/src/internal/layout-box.ts +57 -0
  96. package/src/internal/measure.ts +4 -47
  97. package/src/internal/projection.ts +58 -12
  98. package/src/internal/renderer.ts +243 -122
  99. package/src/internal/reorder.ts +51 -24
  100. package/src/internal/starting-style.ts +5 -5
  101. package/src/internal/transform-keys.ts +21 -9
  102. package/src/unstable/BatchMembers.ts +1 -1
  103. package/src/unstable/DragTrack.ts +25 -5
  104. package/src/unstable/ElementSetup.ts +1 -1
  105. package/src/unstable/Feature.ts +4 -3
  106. package/src/unstable/GestureFeatures.ts +15 -3
  107. package/src/unstable/GestureInfo.ts +24 -0
  108. package/src/unstable/Imperative.ts +1 -0
  109. package/src/unstable/MemberHold.ts +1 -1
  110. package/src/unstable/PresenceController.ts +42 -19
  111. package/src/unstable/WardConfig.ts +5 -5
  112. package/src/unstable/features/TimelineKeys.ts +1 -1
@@ -319,7 +319,9 @@ const placedOf = (el: Element): Placed => ({
319
319
  * a right-to-left one flips). An HTML one's offsets are whole pixels, the DOM's `offsetTop`; an
320
320
  * `<svg>` root's are fractional, from rects (#744).
321
321
  */
322
- interface PopBox {
322
+ // Exported for the hooks-first probe's `show` and `wards` (probe: hooks-first): a ward that pops itself as it
323
+ // leaves measures and pins as a presence's leaver does. The presence's own use is unchanged.
324
+ export interface PopBox {
323
325
  /** The element it pins: an HTML one, or an outermost `<svg>` (#744). No other SVG element is popped (#702). */
324
326
  readonly el: HTMLElement | SVGSVGElement
325
327
  readonly width: number
@@ -340,7 +342,7 @@ export interface PopAnchors {
340
342
  * A leaver's border box's gap from its containing block's padding edge on each side, in the block's
341
343
  * own pixels (#744): what an HTML one reads from its offsets, and an `<svg>` root from rects.
342
344
  */
343
- interface EdgeGaps {
345
+ export interface EdgeGaps {
344
346
  readonly left: number
345
347
  readonly top: number
346
348
  readonly right: number
@@ -376,7 +378,7 @@ const gapsNowOf = (el: Element): EdgeGaps | undefined => {
376
378
  * With `ahead`, its gaps as a binding's snapshot measured them before its framework's change (#840), the
377
379
  * box is at those, not at the gaps the change has left it with.
378
380
  */
379
- const popBoxOf = (el: Element, anchors: PopAnchors, ahead: EdgeGaps | undefined): PopBox | undefined => {
381
+ export const popBoxOf = (el: Element, anchors: PopAnchors, ahead: EdgeGaps | undefined): PopBox | undefined => {
380
382
  if (isPopped(el)) return pinBoxOf(el, anchors, (measured) => UndefinedOr.match(ahead, { onUndefined: () => gapsNowOf(measured), onDefined: identity }))
381
383
  return undefined
382
384
  }
@@ -474,7 +476,7 @@ const svgGapsOf = (el: SVGSVGElement): EdgeGaps | undefined =>
474
476
  })
475
477
 
476
478
  /** Pin a leaver where `box` measured it, out of the flow, over any style of its own. */
477
- const pin = (box: PopBox): void => {
479
+ export const pin = (box: PopBox): void => {
478
480
  const style = box.el.style
479
481
  style.setProperty("position", "absolute", "important")
480
482
  style.setProperty("width", `${box.width}px`, "important")
@@ -885,9 +887,9 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
885
887
 
886
888
  const ctx: PresenceContextValue = {
887
889
  register: (rec) => {
888
- registry.set(rec.element, rec)
890
+ registry.set(rec.subject, rec)
889
891
  return () => {
890
- registry.delete(rec.element)
892
+ registry.delete(rec.subject)
891
893
  }
892
894
  },
893
895
  blocksInitial: () => options.initial() === false && firstRender,
@@ -924,6 +926,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
924
926
  // in-flight fiber bookkeeping. Idempotent. `completed`: its exit ended on its own (#257).
925
927
  const finishExit = (el: Element, completed = true): void => {
926
928
  exiting.delete(el)
929
+ const told = toldHooks.get(el)
927
930
  toldHooks.delete(el)
928
931
  registry.delete(el)
929
932
  draws.delete(el)
@@ -956,6 +959,26 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
956
959
  if (Bool.and(moves, affectsLayout())) projection.notify()
957
960
  // Told once the node is gone, as Motion's `onExitComplete` finds it (#257).
958
961
  leaveEnds(el, completed)
962
+ // The hooks told it left hear it has gone, its exit completed (an interrupted one's heard so already).
963
+ if (completed) UndefinedOr.map(told, (hooks) => Arr.forEach(hooks, (watch) => UndefinedOr.map(watch.ended, (ended) => ended())))
964
+ }
965
+
966
+ /**
967
+ * A hold a hook takes on a leaving child after it was told it left (its `leave`'s `hold`): one more
968
+ * part of the child's exit, ended by the release it hands back, once. Nothing for a child gone
969
+ * already, or one whose parts aren't counted (it went at once).
970
+ */
971
+ const holdLate = (el: Element, counted: boolean): (() => void) => {
972
+ if (Bool.not(counted)) return constVoid
973
+ const parts = pending.get(el)
974
+ if (Predicate.isUndefined(parts)) return constVoid
975
+ pending.set(el, parts + 1)
976
+ let released = false
977
+ return () => {
978
+ if (released) return
979
+ released = true
980
+ partDone(el)
981
+ }
959
982
  }
960
983
 
961
984
  // One of a leaving child's parts ended (#181): it goes with the last. A child already removed
@@ -1077,9 +1100,9 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1077
1100
  */
1078
1101
  const driveExit = (el: Element, rec: PresenceRecord | undefined, custom: unknown): void => {
1079
1102
  const parts = partsOf(el)
1080
- exitParts.set(el, Arr.map(parts, (part) => part.element))
1103
+ exitParts.set(el, Arr.map(parts, (part) => part.subject))
1081
1104
  const own = UndefinedOr.match(rec, { onUndefined: () => NO_OWN, onDefined: Arr.of })
1082
- const byElement = new Map<Element, PresenceRecord>(Arr.map([...own, ...parts], (r) => [r.element, r] as const))
1105
+ const byElement = new Map<Element, PresenceRecord>(Arr.map([...own, ...parts], (r) => [r.subject, r] as const))
1083
1106
  // The nearest element inside the child its Variant children join: one that provides a context.
1084
1107
  const providerOf = (node: Element | null): PresenceRecord | undefined => {
1085
1108
  if (node === null) return undefined
@@ -1091,7 +1114,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1091
1114
  const joinsTo = new Map<PresenceRecord, PresenceRecord>()
1092
1115
  Arr.forEach(parts, (part) => {
1093
1116
  if (Bool.not(treeOf(part).joins)) return
1094
- UndefinedOr.map(providerOf(part.element.parentElement), (provider) => joinsTo.set(part, provider))
1117
+ UndefinedOr.map(providerOf(part.subject.parentElement), (provider) => joinsTo.set(part, provider))
1095
1118
  })
1096
1119
  const joinersOf = (provider: PresenceRecord): ReadonlyArray<PresenceRecord> => Arr.filter(parts, (part) => joinsTo.get(part) === provider)
1097
1120
  const nodeOf = (node: PresenceRecord, inherited: WardConfig.WardicVariantLabels | undefined): ExitNode => {
@@ -1220,7 +1243,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1220
1243
  const preparedOf = (rec: PresenceRecord, exit: CorePresenceRecord.PresenceExit): PreparedExit => {
1221
1244
  const known = prepared.get(exit)
1222
1245
  if (Predicate.isNotUndefined(known)) return known
1223
- const el = rec.element
1246
+ const el = rec.subject
1224
1247
  const to = exit.values
1225
1248
  // Seeded from the element's last snapshot, so its exit departs continuously. A key it never
1226
1249
  // animated starts from its Base value's start links (ADR-0022), else at its target.
@@ -1482,7 +1505,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1482
1505
  const watchesIn = (el: Element): ReadonlyArray<PresenceWatch> => {
1483
1506
  if (Predicate.isUndefined(watchesWithin)) {
1484
1507
  const index = new Map<Element, Array<PresenceWatch>>()
1485
- Iter.forEach(watches, (watch) => UndefinedOr.map(watch.element(), (at) => indexUp(index, at, watch)))
1508
+ Iter.forEach(watches, (watch) => UndefinedOr.map(watch.subject(), (at) => indexUp(index, at, watch)))
1486
1509
  watchesWithin = index
1487
1510
  }
1488
1511
  return Arr.filter(UndefinedOr.match(watchesWithin.get(el), { onUndefined: (): ReadonlyArray<PresenceWatch> => [], onDefined: identity }), (watch) => watches.has(watch))
@@ -1511,7 +1534,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1511
1534
  partDone(el)
1512
1535
  }
1513
1536
  try {
1514
- watch.leave(custom, release)
1537
+ watch.leave(custom, release, () => holdLate(el, counted))
1515
1538
  } catch (defect) {
1516
1539
  runtime.runFork(Report.failure("wardic.presence: a usePresence callback failed", Cause.die(defect)))
1517
1540
  release()
@@ -1521,7 +1544,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1521
1544
 
1522
1545
  /** A hook whose element left the page some other way, dropped (#277's PR 5b): not one a held child holds. */
1523
1546
  const dropDetachedWatch = (watch: PresenceWatch): void => {
1524
- UndefinedOr.map(watch.element(), (at) => {
1547
+ UndefinedOr.map(watch.subject(), (at) => {
1525
1548
  if (Bool.or(at.isConnected, isHeld(at))) return
1526
1549
  watches.delete(watch)
1527
1550
  watch.gone()
@@ -1538,7 +1561,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1538
1561
  * else its last values, at the velocities its own animation left them.
1539
1562
  */
1540
1563
  const drawnOf = (rec: PresenceRecord): Drawn =>
1541
- UndefinedOr.match(draws.get(rec.element), {
1564
+ UndefinedOr.match(draws.get(rec.subject), {
1542
1565
  onUndefined: (): Drawn => ({
1543
1566
  values: valuesDrawn(rec.snapshot.current),
1544
1567
  velocities: UndefinedOr.match(rec.velocities, { onUndefined: () => NO_VELOCITIES, onDefined: (of) => ({ ...of() }) }),
@@ -1580,7 +1603,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1580
1603
  /** Where a leaver and the Wardic elements inside it paint now, in the Root frame: each one on the page. */
1581
1604
  const boxesOf = (leaver: Element): ReadonlyMap<Element, Box.Box> => {
1582
1605
  const boxes = new Map<Element, Box.Box>()
1583
- Arr.forEach([leaver, ...Arr.map(partsOf(leaver), (part) => part.element)], (el) =>
1606
+ Arr.forEach([leaver, ...Arr.map(partsOf(leaver), (part) => part.subject)], (el) =>
1584
1607
  Option.map(projection.rootBoxOf(el), (box) => boxes.set(el, box)))
1585
1608
  return boxes
1586
1609
  }
@@ -1612,8 +1635,8 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1612
1635
  // Each as drawn, and where it painted: a layout node moves from there (#286's PR 2).
1613
1636
  const boxes = UndefinedOr.match(leaverBoxes.get(leaver), { onUndefined: (): ReadonlyMap<Element, Box.Box> => NO_BOXES, onDefined: identity })
1614
1637
  leaverBoxes.delete(leaver)
1615
- const seedOf = (rec: PresenceRecord): Drawn => ({ ...drawnOf(rec), box: boxes.get(rec.element) })
1616
- const paired = sameShape(Arr.map(before, (part) => part.element), after)
1638
+ const seedOf = (rec: PresenceRecord): Drawn => ({ ...drawnOf(rec), box: boxes.get(rec.subject) })
1639
+ const paired = sameShape(Arr.map(before, (part) => part.subject), after)
1617
1640
  if (paired) Arr.forEach(Arr.zip(before, after), ([part, into]) => seeds.set(into, seedOf(part)))
1618
1641
  debug("leave: taken over", { parts: before.length, paired })
1619
1642
  // A twin crossfading out (Q8: D): its leaving Follower goes at once, uncompleted, and the new
@@ -1632,7 +1655,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1632
1655
  // Leaving in this change: it goes as Solid took it, its records and hooks with it.
1633
1656
  takenOver.add(leaver)
1634
1657
  pops.delete(leaver)
1635
- Arr.forEach([from, ...before], (rec) => registry.delete(rec.element))
1658
+ Arr.forEach([from, ...before], (rec) => registry.delete(rec.subject))
1636
1659
  Arr.forEach(watchesIn(leaver), (watch) => {
1637
1660
  watches.delete(watch)
1638
1661
  watch.gone()
@@ -1780,7 +1803,7 @@ export const propagateTo = (parent: PresenceContextValue | undefined, propagate:
1780
1803
  let disposed = false
1781
1804
  let leaving = false
1782
1805
  ;(watch as (watch: PresenceWatch) => void)({
1783
- element: presence.anchor,
1806
+ subject: presence.anchor,
1784
1807
  holds: true,
1785
1808
  leave: (_custom, release) => {
1786
1809
  leaving = true
@@ -20,7 +20,7 @@ import type * as ProjectionSystem from "../ProjectionSystem.ts"
20
20
  import type { WardicDragConstraints, WardicMeasureDragConstraints } from "./DragConstraints.ts"
21
21
  import type { WardicDragControls } from "./DragControls.ts"
22
22
  import type * as Feature from "./Feature.ts"
23
- import type { WardicDragInfo, WardicPointInfo, WardicPressEvent, WardicPressInfo } from "./GestureInfo.ts"
23
+ import type { WardicDragEndInfo, WardicDragInfo, WardicPointInfo, WardicPressEvent, WardicPressInfo } from "./GestureInfo.ts"
24
24
 
25
25
  /** What "in view" means: an element's `viewport`, and `createInView`'s. Motion's `viewport` and `useInView` options. */
26
26
  // #273, ADR-0047.
@@ -497,8 +497,8 @@ export interface WardPanConfig {
497
497
  readonly onPanStart?: (event: PointerEvent, info: WardicDragInfo) => void
498
498
  /** Called as the pan moves: at its start, and each move after. Solid 1; Solid 2's ward gives `"pan"`. */
499
499
  readonly onPan?: (event: PointerEvent, info: WardicDragInfo) => void
500
- /** Called when a pan that started ends, or is cancelled. Solid 1; Solid 2's ward gives `"panEnd"`. */
501
- readonly onPanEnd?: (event: PointerEvent, info: WardicDragInfo) => void
500
+ /** Called when a pan that started ends, or is cancelled, its info saying how (`endedBy`, #1042). Solid 1; Solid 2's ward gives `"panEnd"`. */
501
+ readonly onPanEnd?: (event: PointerEvent, info: WardicDragEndInfo) => void
502
502
  }
503
503
 
504
504
  /** The motion props the `drag` Feature reads: {@link WardConfig}'s `drag` group (#516). */
@@ -587,8 +587,8 @@ export interface WardDragConfig {
587
587
  readonly onDragStart?: (event: PointerEvent, info: WardicDragInfo) => void
588
588
  /** Called as the drag moves: at its start, and each move after. Solid 1; Solid 2's ward gives `"drag"`. */
589
589
  readonly onDrag?: (event: PointerEvent, info: WardicDragInfo) => void
590
- /** Called when the drag is let go. Solid 1; Solid 2's ward gives `"dragEnd"`. */
591
- readonly onDragEnd?: (event: PointerEvent, info: WardicDragInfo) => void
590
+ /** Called when the drag ends, its info saying how: let go, or taken away (`endedBy`, #1042). Solid 1; Solid 2's ward gives `"dragEnd"`. */
591
+ readonly onDragEnd?: (event: PointerEvent, info: WardicDragEndInfo) => void
592
592
  /** Called when the element comes to rest after it's let go. Not when a new grab stops it. Solid 1; Solid 2's ward gives `"dragTransitionEnd"`. */
593
593
  readonly onDragTransitionEnd?: () => void
594
594
  /** With `dragDirectionLock`: called with the axis a drag locked to, before `onDragStart`. Solid 1; Solid 2's ward gives `"directionLock"`. */
@@ -64,7 +64,7 @@ const TIMELINE_FAILED = "wardic.timeline: a Timeline value failed"
64
64
  const elementKeysOf = (options: Timelines.TimelineKeysOptions, unmounted: () => void): ElementKeys => {
65
65
  const { runtime, gate, id, live } = options
66
66
  // #672: the spine hands its Subject; a DOM binding's is its element, which a Timeline value follows.
67
- const element = options.element as Element
67
+ const element = options.subject as Element
68
68
  const made = new Map<string, Made>()
69
69
  // The keys that show their Live value, whatever runs them, each with the Atom it was shown from (none
70
70
  // for a plain accessor's): the ones `recheck` looks at again.