@wardic/dom 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +2 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/internal/batch-writer.d.ts.map +1 -1
  5. package/dist/internal/batch-writer.js +9 -13
  6. package/dist/internal/batch-writer.js.map +1 -1
  7. package/dist/internal/clock.d.ts +3 -3
  8. package/dist/internal/clock.d.ts.map +1 -1
  9. package/dist/internal/clock.js +25 -7
  10. package/dist/internal/clock.js.map +1 -1
  11. package/dist/internal/default-transition.d.ts +2 -2
  12. package/dist/internal/default-transition.d.ts.map +1 -1
  13. package/dist/internal/default-transition.js +23 -9
  14. package/dist/internal/default-transition.js.map +1 -1
  15. package/dist/internal/projection.d.ts.map +1 -1
  16. package/dist/internal/projection.js +42 -7
  17. package/dist/internal/projection.js.map +1 -1
  18. package/dist/internal/renderer.d.ts +36 -14
  19. package/dist/internal/renderer.d.ts.map +1 -1
  20. package/dist/internal/renderer.js +213 -118
  21. package/dist/internal/renderer.js.map +1 -1
  22. package/dist/internal/starting-style.js +5 -5
  23. package/dist/internal/transform-keys.d.ts +3 -2
  24. package/dist/internal/transform-keys.d.ts.map +1 -1
  25. package/dist/internal/transform-keys.js +21 -9
  26. package/dist/internal/transform-keys.js.map +1 -1
  27. package/dist/unstable/BatchMembers.js +1 -1
  28. package/dist/unstable/DragTrack.d.ts.map +1 -1
  29. package/dist/unstable/DragTrack.js +3 -2
  30. package/dist/unstable/DragTrack.js.map +1 -1
  31. package/dist/unstable/ElementSetup.js +1 -1
  32. package/dist/unstable/GestureFeatures.d.ts +6 -1
  33. package/dist/unstable/GestureFeatures.d.ts.map +1 -1
  34. package/dist/unstable/GestureFeatures.js +8 -3
  35. package/dist/unstable/GestureFeatures.js.map +1 -1
  36. package/dist/unstable/GestureInfo.d.ts +11 -0
  37. package/dist/unstable/GestureInfo.d.ts.map +1 -1
  38. package/dist/unstable/GestureInfo.js +8 -0
  39. package/dist/unstable/GestureInfo.js.map +1 -1
  40. package/dist/unstable/Imperative.d.ts +1 -1
  41. package/dist/unstable/Imperative.d.ts.map +1 -1
  42. package/dist/unstable/Imperative.js.map +1 -1
  43. package/dist/unstable/MemberHold.js +1 -1
  44. package/dist/unstable/MemberHold.js.map +1 -1
  45. package/dist/unstable/PresenceController.js +14 -14
  46. package/dist/unstable/WardConfig.d.ts +5 -5
  47. package/dist/unstable/WardConfig.d.ts.map +1 -1
  48. package/dist/unstable/features/TimelineKeys.js +1 -1
  49. package/package.json +3 -3
  50. package/src/index.ts +2 -2
  51. package/src/internal/batch-writer.ts +9 -14
  52. package/src/internal/clock.ts +25 -7
  53. package/src/internal/default-transition.ts +22 -8
  54. package/src/internal/projection.ts +49 -7
  55. package/src/internal/renderer.ts +243 -122
  56. package/src/internal/starting-style.ts +5 -5
  57. package/src/internal/transform-keys.ts +21 -9
  58. package/src/unstable/BatchMembers.ts +1 -1
  59. package/src/unstable/DragTrack.ts +3 -2
  60. package/src/unstable/ElementSetup.ts +1 -1
  61. package/src/unstable/GestureFeatures.ts +15 -3
  62. package/src/unstable/GestureInfo.ts +24 -0
  63. package/src/unstable/Imperative.ts +1 -0
  64. package/src/unstable/MemberHold.ts +1 -1
  65. package/src/unstable/PresenceController.ts +14 -14
  66. package/src/unstable/WardConfig.ts +5 -5
  67. package/src/unstable/features/TimelineKeys.ts +1 -1
@@ -176,8 +176,20 @@ export interface Telling {
176
176
  readonly invoke: (handler: unknown, args: ReadonlyArray<unknown>) => void
177
177
  /** Report that the callback `name` threw `defect`. */
178
178
  readonly report: (name: GestureCallbackName, defect: unknown) => void
179
+ /**
180
+ * Whether a drag's and a pan's end callbacks are told how it ended, as `endedBy` (#1042): Solid 1's
181
+ * are. Absent, their info is a move's, as Foldkit's is.
182
+ */
183
+ readonly tellsEndedBy?: boolean | undefined
179
184
  }
180
185
 
186
+ /** A drag's or a pan's sample's info: an end's with how it ended, where its binding tells it (#1042). */
187
+ const movementInfoOf = (tellsEndedBy: boolean, sample: Drag.Sample): GestureInfo.WardicDragInfo =>
188
+ Bool.match(Bool.and(tellsEndedBy, sample.phase === "end"), {
189
+ onTrue: (): GestureInfo.WardicDragInfo => GestureInfo.dragEndInfoOf(sample),
190
+ onFalse: () => GestureInfo.dragInfoOf(sample),
191
+ })
192
+
181
193
  /**
182
194
  * What tells an element's gestures to its config's callbacks, for every binding (#273, ADR-0047):
183
195
  * Motion's `(event, info)`, the platform's own event carried through (`raw`), then the info
@@ -203,7 +215,7 @@ type MovementCallback = "onDragStart" | "onDragEnd" | "onPanStart" | "onPanEnd"
203
215
 
204
216
  /** A {@link GestureTeller} over `telling`'s config, invoking and reporting as the binding says. */
205
217
  // #793 (PR 2): solid's `gestureCallbacksOf`, moved to dom for both bindings: each gives how a handler is invoked.
206
- export const gestureTellerOf = ({ config, invoke, report }: Telling): GestureTeller => {
218
+ export const gestureTellerOf = ({ config, invoke, report, tellsEndedBy }: Telling): GestureTeller => {
207
219
  const guard = callbackGuard(report)
208
220
  /** Tell the config's `name`, if it has one, `args`: reported at a run of throws' first. */
209
221
  const tell = (name: GestureCallbackName, ...args: ReadonlyArray<unknown>): void => {
@@ -222,7 +234,7 @@ export const gestureTellerOf = ({ config, invoke, report }: Telling): GestureTel
222
234
  const each = Bool.match(sample.phase !== "end", { onTrue: () => c[every], onFalse: constUndefined })
223
235
  if (Bool.and(Predicate.isUndefined(own), Predicate.isUndefined(each))) return
224
236
  const raw = sample.raw as PointerEvent
225
- const info = GestureInfo.dragInfoOf(sample)
237
+ const info = movementInfoOf(tellsEndedBy === true, sample)
226
238
  UndefinedOr.map(named, (key) => UndefinedOr.map(own, (handler) => guard(key, () => invoke(handler, [raw, info]))))
227
239
  UndefinedOr.map(each, (handler) => guard(every, () => invoke(handler, [raw, info])))
228
240
  }
@@ -238,7 +250,7 @@ export const gestureTellerOf = ({ config, invoke, report }: Telling): GestureTel
238
250
  },
239
251
  dragged: (sample) => {
240
252
  // A drag its controls cancelled (#431) ends untold, as Motion's `cancel` tells no `onDragEnd`.
241
- if (sample.cancelled === true) return
253
+ if (sample.endedBy === "controls") return
242
254
  // A direction-locked drag's lock, at its start, before `onDragStart` (Motion's order).
243
255
  if (Bool.and(sample.phase === "start", config().dragDirectionLock === true)) tell("onDirectionLock", sample.axis as "x" | "y")
244
256
  moved(DRAG_CALLBACK[sample.phase], "onDrag", sample)
@@ -13,6 +13,7 @@
13
13
  import type * as Drag from "@wardic/core/Drag"
14
14
  import type * as InputSource from "@wardic/core/InputSource"
15
15
  import type * as Recognizer from "@wardic/core/Recognizer"
16
+ import * as Match from "effect/Match"
16
17
 
17
18
  /** A point in the viewport. */
18
19
  export interface WardicPoint {
@@ -38,6 +39,16 @@ export interface WardicDragInfo {
38
39
  readonly velocity: WardicPoint
39
40
  }
40
41
 
42
+ /** A drag's or a pan's end (Motion's `PanInfo` at `onDragEnd`): its {@link WardicDragInfo}, and how it ended (#1042). */
43
+ export interface WardicDragEndInfo extends WardicDragInfo {
44
+ /**
45
+ * How it ended: `"release"`, let go; `"cancel"`, the platform took the pointer away (a `pointercancel`:
46
+ * the page scrolled under a touch), which doesn't fling; `"lost"`, its release never came (a **Stale
47
+ * gesture**). A drag its controls cancelled tells no end.
48
+ */
49
+ readonly endedBy: Exclude<Drag.EndedBy, "controls">
50
+ }
51
+
41
52
  /** How a press was made: by a pointer, or a **Keyboard press**. */
42
53
  export type WardicPressInput = "pointer" | "keyboard"
43
54
 
@@ -71,6 +82,19 @@ export const pointInfoOf = (event: InputSource.PointerLikeEvent): WardicPointInf
71
82
  /** What a drag's or a pan's sample carries for its info. */
72
83
  type Sampled = Pick<Drag.Sample, "point" | "scroll" | "offset" | "delta" | "velocity">
73
84
 
85
+ /**
86
+ * How a told end ended (#1042): a pointer's cancel, a lost release, or a release. Drag controls' cancel
87
+ * is never told, and a pan has none. Built once, at module load.
88
+ */
89
+ const endedByOf: (sample: Pick<Drag.Sample, "endedBy">) => WardicDragEndInfo["endedBy"] = /*#__PURE__*/ Match.type<Pick<Drag.Sample, "endedBy">>().pipe(
90
+ Match.when({ endedBy: "cancel" }, (): WardicDragEndInfo["endedBy"] => "cancel"),
91
+ Match.when({ endedBy: "lost" }, (): WardicDragEndInfo["endedBy"] => "lost"),
92
+ Match.orElse((): WardicDragEndInfo["endedBy"] => "release"),
93
+ )
94
+
95
+ /** A drag's or a pan's end sample's info: {@link dragInfoOf}'s, and how it ended (#1042). */
96
+ export const dragEndInfoOf = (sample: Sampled & Pick<Drag.Sample, "endedBy">): WardicDragEndInfo => ({ ...dragInfoOf(sample), endedBy: endedByOf(sample) })
97
+
74
98
  /** A drag sample's info: its point less the scroll its hold counted into it, and its own offset, delta and velocity. */
75
99
  export const dragInfoOf = (sample: Sampled): WardicDragInfo => ({
76
100
  point: { x: sample.point.x - sample.scroll.x, y: sample.point.y - sample.scroll.y },
@@ -41,6 +41,7 @@ export type {
41
41
  AnimateEnv,
42
42
  AnimationWatch,
43
43
  WardicAnimateOptions,
44
+ WardicAnimationEnd,
44
45
  WardicFunctionSegment,
45
46
  WardicPlaybackControls,
46
47
  WardicPlayState,
@@ -61,7 +61,7 @@ export const provideBatchHolds = (): void => Spine.provideMemberHolds(BATCH_HOLD
61
61
 
62
62
  /** A Batch member's element's {@link Spine.MemberHold}. */
63
63
  const makeMemberHold = (host: Spine.HoldHost): Spine.MemberHold => {
64
- const { element, gate, id, snapshot } = host
64
+ const { subject: element, gate, id, snapshot } = host
65
65
  // The groups it holds now, each with the Batch's keys in it; the member it took them from; and whether
66
66
  // a drag holds `x`/`y`, from its first read or write to its hand-back.
67
67
  const held = new Map<BatchMembers.BatchGroup, ReadonlyArray<string>>()
@@ -885,9 +885,9 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
885
885
 
886
886
  const ctx: PresenceContextValue = {
887
887
  register: (rec) => {
888
- registry.set(rec.element, rec)
888
+ registry.set(rec.subject, rec)
889
889
  return () => {
890
- registry.delete(rec.element)
890
+ registry.delete(rec.subject)
891
891
  }
892
892
  },
893
893
  blocksInitial: () => options.initial() === false && firstRender,
@@ -1077,9 +1077,9 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1077
1077
  */
1078
1078
  const driveExit = (el: Element, rec: PresenceRecord | undefined, custom: unknown): void => {
1079
1079
  const parts = partsOf(el)
1080
- exitParts.set(el, Arr.map(parts, (part) => part.element))
1080
+ exitParts.set(el, Arr.map(parts, (part) => part.subject))
1081
1081
  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))
1082
+ const byElement = new Map<Element, PresenceRecord>(Arr.map([...own, ...parts], (r) => [r.subject, r] as const))
1083
1083
  // The nearest element inside the child its Variant children join: one that provides a context.
1084
1084
  const providerOf = (node: Element | null): PresenceRecord | undefined => {
1085
1085
  if (node === null) return undefined
@@ -1091,7 +1091,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1091
1091
  const joinsTo = new Map<PresenceRecord, PresenceRecord>()
1092
1092
  Arr.forEach(parts, (part) => {
1093
1093
  if (Bool.not(treeOf(part).joins)) return
1094
- UndefinedOr.map(providerOf(part.element.parentElement), (provider) => joinsTo.set(part, provider))
1094
+ UndefinedOr.map(providerOf(part.subject.parentElement), (provider) => joinsTo.set(part, provider))
1095
1095
  })
1096
1096
  const joinersOf = (provider: PresenceRecord): ReadonlyArray<PresenceRecord> => Arr.filter(parts, (part) => joinsTo.get(part) === provider)
1097
1097
  const nodeOf = (node: PresenceRecord, inherited: WardConfig.WardicVariantLabels | undefined): ExitNode => {
@@ -1220,7 +1220,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1220
1220
  const preparedOf = (rec: PresenceRecord, exit: CorePresenceRecord.PresenceExit): PreparedExit => {
1221
1221
  const known = prepared.get(exit)
1222
1222
  if (Predicate.isNotUndefined(known)) return known
1223
- const el = rec.element
1223
+ const el = rec.subject
1224
1224
  const to = exit.values
1225
1225
  // Seeded from the element's last snapshot, so its exit departs continuously. A key it never
1226
1226
  // animated starts from its Base value's start links (ADR-0022), else at its target.
@@ -1482,7 +1482,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1482
1482
  const watchesIn = (el: Element): ReadonlyArray<PresenceWatch> => {
1483
1483
  if (Predicate.isUndefined(watchesWithin)) {
1484
1484
  const index = new Map<Element, Array<PresenceWatch>>()
1485
- Iter.forEach(watches, (watch) => UndefinedOr.map(watch.element(), (at) => indexUp(index, at, watch)))
1485
+ Iter.forEach(watches, (watch) => UndefinedOr.map(watch.subject(), (at) => indexUp(index, at, watch)))
1486
1486
  watchesWithin = index
1487
1487
  }
1488
1488
  return Arr.filter(UndefinedOr.match(watchesWithin.get(el), { onUndefined: (): ReadonlyArray<PresenceWatch> => [], onDefined: identity }), (watch) => watches.has(watch))
@@ -1521,7 +1521,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1521
1521
 
1522
1522
  /** A hook whose element left the page some other way, dropped (#277's PR 5b): not one a held child holds. */
1523
1523
  const dropDetachedWatch = (watch: PresenceWatch): void => {
1524
- UndefinedOr.map(watch.element(), (at) => {
1524
+ UndefinedOr.map(watch.subject(), (at) => {
1525
1525
  if (Bool.or(at.isConnected, isHeld(at))) return
1526
1526
  watches.delete(watch)
1527
1527
  watch.gone()
@@ -1538,7 +1538,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1538
1538
  * else its last values, at the velocities its own animation left them.
1539
1539
  */
1540
1540
  const drawnOf = (rec: PresenceRecord): Drawn =>
1541
- UndefinedOr.match(draws.get(rec.element), {
1541
+ UndefinedOr.match(draws.get(rec.subject), {
1542
1542
  onUndefined: (): Drawn => ({
1543
1543
  values: valuesDrawn(rec.snapshot.current),
1544
1544
  velocities: UndefinedOr.match(rec.velocities, { onUndefined: () => NO_VELOCITIES, onDefined: (of) => ({ ...of() }) }),
@@ -1580,7 +1580,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1580
1580
  /** Where a leaver and the Wardic elements inside it paint now, in the Root frame: each one on the page. */
1581
1581
  const boxesOf = (leaver: Element): ReadonlyMap<Element, Box.Box> => {
1582
1582
  const boxes = new Map<Element, Box.Box>()
1583
- Arr.forEach([leaver, ...Arr.map(partsOf(leaver), (part) => part.element)], (el) =>
1583
+ Arr.forEach([leaver, ...Arr.map(partsOf(leaver), (part) => part.subject)], (el) =>
1584
1584
  Option.map(projection.rootBoxOf(el), (box) => boxes.set(el, box)))
1585
1585
  return boxes
1586
1586
  }
@@ -1612,8 +1612,8 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1612
1612
  // Each as drawn, and where it painted: a layout node moves from there (#286's PR 2).
1613
1613
  const boxes = UndefinedOr.match(leaverBoxes.get(leaver), { onUndefined: (): ReadonlyMap<Element, Box.Box> => NO_BOXES, onDefined: identity })
1614
1614
  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)
1615
+ const seedOf = (rec: PresenceRecord): Drawn => ({ ...drawnOf(rec), box: boxes.get(rec.subject) })
1616
+ const paired = sameShape(Arr.map(before, (part) => part.subject), after)
1617
1617
  if (paired) Arr.forEach(Arr.zip(before, after), ([part, into]) => seeds.set(into, seedOf(part)))
1618
1618
  debug("leave: taken over", { parts: before.length, paired })
1619
1619
  // A twin crossfading out (Q8: D): its leaving Follower goes at once, uncompleted, and the new
@@ -1632,7 +1632,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1632
1632
  // Leaving in this change: it goes as Solid took it, its records and hooks with it.
1633
1633
  takenOver.add(leaver)
1634
1634
  pops.delete(leaver)
1635
- Arr.forEach([from, ...before], (rec) => registry.delete(rec.element))
1635
+ Arr.forEach([from, ...before], (rec) => registry.delete(rec.subject))
1636
1636
  Arr.forEach(watchesIn(leaver), (watch) => {
1637
1637
  watches.delete(watch)
1638
1638
  watch.gone()
@@ -1780,7 +1780,7 @@ export const propagateTo = (parent: PresenceContextValue | undefined, propagate:
1780
1780
  let disposed = false
1781
1781
  let leaving = false
1782
1782
  ;(watch as (watch: PresenceWatch) => void)({
1783
- element: presence.anchor,
1783
+ subject: presence.anchor,
1784
1784
  holds: true,
1785
1785
  leave: (_custom, release) => {
1786
1786
  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.