@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
@@ -163,6 +163,14 @@ export interface ReorderControllerOptions<V> {
163
163
  /** Hears each **Reorder hold**'s end, once, whatever ended it; after `onReorderEnd` when it moved. */
164
164
  // #348.
165
165
  readonly onHoldEnd?: ((end: ReorderHoldEnd<V>) => void) | undefined
166
+ /**
167
+ * What makes two of the app's values one item, where its list makes them again (a refetch, a store's
168
+ * copy): the group matches by it (core's `GroupOptions.key`), and so does the controller, in an item's
169
+ * index, its element, its hold and its lift, and in its check of an order it asked for. So an item made
170
+ * again keeps its place, its drag and its keyboard lift. Left out, values match by identity.
171
+ */
172
+ // Probe: hooks-first, the Reorder round.
173
+ readonly key?: ((value: V) => unknown) | undefined
166
174
  /** The app's axis, overriding detection; `None` to detect. */
167
175
  readonly axis?: (() => Option.Option<Reorder.Axis>) | undefined
168
176
  /** Called when the detected axis changes (once the items are laid out, or {@link ReorderController.resolve}). */
@@ -274,7 +282,19 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
274
282
  let asked: ReadonlyArray<V> | undefined
275
283
  /** The app's axis, if it sets one. */
276
284
  const appAxis = (): Option.Option<Reorder.Axis> => Option.flatMap(Option.fromUndefinedOr(options.axis), (axis) => axis())
285
+ /** What an item is known by: its `key`, else the value itself. */
286
+ const idOf: (value: V) => unknown = UndefinedOr.match(options.key, { onUndefined: () => identity, onDefined: identity })
287
+ /** Whether two values are one item, as the group matches them. */
288
+ const same = (self: V, that: V): boolean => idOf(self) === idOf(that)
289
+ /** Whether two orders hold the same items in the same order, as the group matches them. */
290
+ const sameItems = Arr.makeEquivalence(same)
291
+ /**
292
+ * `value` as the app's values hold it now, for what the controller tells the app: the object made again
293
+ * under its `key`, where an item kept its first; itself without a key, or once it has left them.
294
+ */
295
+ const latest = (value: V): V => Option.getOrElse(Arr.findFirst(options.values(), (v) => same(v, value)), () => value)
277
296
  const group = Reorder.make<V>({
297
+ key: options.key,
278
298
  values: options.values,
279
299
  onReorder: (values) => {
280
300
  // A copy of what it hands on: an app that keeps that array, a store's own, may change it in place (#721).
@@ -290,6 +310,8 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
290
310
  }),
291
311
  debug,
292
312
  })
313
+ /** Whether `value` is the lifted item. */
314
+ const isLiftedValue = (value: V): boolean => Option.exists(Reorder.liftedValue(group), (lifted) => same(lifted, value))
293
315
 
294
316
  let detected: Reorder.Axis = "y"
295
317
  let reported: Reorder.Axis | undefined
@@ -302,14 +324,14 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
302
324
  if (Predicate.isNotUndefined(options.onAxis)) options.onAxis(detected)
303
325
  }
304
326
  // --- The keyboard reorder (ADR-0037) ---------------------------------------
305
- /** The lifted item's element, its handle and its `onLift`, by value, while it's registered. */
327
+ /** The lifted item's element, its handle and its `onLift`, by what it's known by (`idOf`), while it's registered. */
306
328
  interface Keyed {
307
329
  readonly element: () => Option.Option<Element>
308
330
  handle: Option.Option<ReorderItemHandle>
309
331
  readonly onLift: (lifted: boolean) => void
310
332
  }
311
- const keyed = new Map<V, Keyed>()
312
- const keyedOf = (value: V): Option.Option<Keyed> => Option.fromUndefinedOr(keyed.get(value))
333
+ const keyed = new Map<unknown, Keyed>()
334
+ const keyedOf = (value: V): Option.Option<Keyed> => Option.fromUndefinedOr(keyed.get(idOf(value)))
313
335
  const elementOf = (value: V): Option.Option<Element> => Option.flatMap(keyedOf(value), (k) => k.element())
314
336
  // The item whose new place the next layout lays out, to scroll into view then.
315
337
  const reveal = MutableRef.make(Option.none<V>())
@@ -329,40 +351,42 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
329
351
  ...(Reorder.defaultAnnouncements as Reorder.Announcements<V>),
330
352
  ...Option.getOrUndefined(Option.flatMap(Option.fromUndefinedOr(options.announcements), (announcements) => announcements())),
331
353
  })
332
- const say = (kind: keyof Reorder.Announcements<V>, value: V, placement: Reorder.Placement): string =>
333
- wording()[kind]({ value, label: labelOf(elementOf(value), value), position: placement.position, count: placement.count })
354
+ const say = (kind: keyof Reorder.Announcements<V>, value: V, placement: Reorder.Placement): string => {
355
+ const now = latest(value)
356
+ return wording()[kind]({ value: now, label: labelOf(elementOf(value), now), position: placement.position, count: placement.count })
357
+ }
334
358
 
335
359
  /** Raise the lifted item (or lower it) and tell its binding (its `whileDrag`). */
336
360
  const setLifted = (value: V, lifted: boolean): void => {
337
- const k = keyed.get(value)
361
+ const k = keyed.get(idOf(value))
338
362
  if (Predicate.isUndefined(k)) return
339
363
  if (Option.isSome(k.handle)) k.handle.value.setLifted(lifted)
340
364
  k.onLift(lifted)
341
365
  }
342
- /** `value`'s index in the app's values now. */
343
- const indexOf = (value: V): number => options.values().indexOf(value)
366
+ /** `value`'s index in the app's values now, found as the group matches its items; -1 when it isn't there. */
367
+ const indexOf = (value: V): number => Option.getOrElse(Arr.findFirstIndex(options.values(), (v) => same(v, value)), () => -1)
344
368
  /** The end of a user's reorder of `value`, begun at `from`: told when it moved (#257 item 3). */
345
369
  const ended = (value: V, from: number): void => {
346
370
  const to = indexOf(value)
347
371
  if (to === from) return
348
- UndefinedOr.map(options.onReorderEnd, (tell) => tell({ values: [...options.values()], value, from, to }))
372
+ UndefinedOr.map(options.onReorderEnd, (tell) => tell({ values: [...options.values()], value: latest(value), from, to }))
349
373
  }
350
374
  // --- Holds (#348) ------------------------------------------------------------
351
375
  /** The open **Reorder hold**: the item in hand, how it was taken, and its index then. One at a time. */
352
376
  let held: Option.Option<{ readonly value: V; readonly from: number; readonly by: "drag" | "lift" }> = Option.none()
353
377
  /** Whether `value`'s drag is the open hold: a drag a later hold took over tells nothing more. */
354
- const holdsDrag = (value: V): boolean => Option.exists(held, (h) => h.by === "drag" && h.value === value)
378
+ const holdsDrag = (value: V): boolean => Option.exists(held, (h) => h.by === "drag" && same(h.value, value))
355
379
  const holdStart = (value: V, from: number, by: "drag" | "lift"): void => {
356
380
  held = Option.some({ value, from, by })
357
- UndefinedOr.map(options.onHoldStart, (tell) => tell({ value, from }))
381
+ UndefinedOr.map(options.onHoldStart, (tell) => tell({ value: latest(value), from }))
358
382
  }
359
383
  /** End `value`'s hold, `how`: told once, and only for the open one. */
360
384
  const holdEnd = (value: V, how: ReorderHoldHow): void =>
361
- Option.match(Option.filter(held, (h) => h.value === value), {
385
+ Option.match(Option.filter(held, (h) => same(h.value, value)), {
362
386
  onNone: constVoid,
363
387
  onSome: (h) => {
364
388
  held = Option.none()
365
- UndefinedOr.map(options.onHoldEnd, (tell) => tell({ values: [...options.values()], value, from: h.from, to: indexOf(value), how }))
389
+ UndefinedOr.map(options.onHoldEnd, (tell) => tell({ values: [...options.values()], value: latest(value), from: h.from, to: indexOf(value), how }))
366
390
  },
367
391
  })
368
392
 
@@ -409,7 +433,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
409
433
  if (Bool.not(event.fromTarget)) return
410
434
  // Keys during a pointer drag are left alone.
411
435
  if (Reorder.isDragging(group)) return
412
- const lifted = Option.contains(Reorder.liftedValue(group), value)
436
+ const lifted = isLiftedValue(value)
413
437
  Option.match(Reorder.keyIntent(event.key), {
414
438
  onNone: constVoid,
415
439
  onSome: (intent) =>
@@ -514,7 +538,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
514
538
  // Its index at the drag's start, for its `onReorderEnd` (#257 item 3).
515
539
  let draggedFrom = -1
516
540
  const k: Keyed = { element: itemElement, handle: Option.none(), onLift }
517
- keyed.set(value, k)
541
+ keyed.set(idOf(value), k)
518
542
  const end = (): void => {
519
543
  inGesture = false
520
544
  Reorder.dragEnd(group, value)
@@ -536,7 +560,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
536
560
  layoutVersion: handle.layoutVersion,
537
561
  })
538
562
  k.handle = Option.some(handle)
539
- keyed.set(value, k)
563
+ keyed.set(idOf(value), k)
540
564
  return () => {
541
565
  if (Option.contains(k.handle, handle)) k.handle = Option.none()
542
566
  unregister()
@@ -571,20 +595,20 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
571
595
  },
572
596
  onKey: onKeyOf(value),
573
597
  onBlur: () => {
574
- if (Bool.not(Option.contains(Reorder.liftedValue(group), value))) return
598
+ if (Bool.not(isLiftedValue(value))) return
575
599
  // A reorder can blur the node it moves; focus was put back on it, so it's no interruption.
576
600
  if (focused(value)) return
577
601
  dropLifted()
578
602
  },
579
603
  onPress: () => {
580
- if (Option.contains(Reorder.liftedValue(group), value)) dropLifted()
604
+ if (isLiftedValue(value)) dropLifted()
581
605
  },
582
606
  dispose: () => {
583
607
  if (inGesture) end()
584
608
  // Unmounted while lifted: the lift ends, unsaid.
585
- if (Option.contains(Reorder.liftedValue(group), value)) Reorder.drop(group, value)
609
+ if (isLiftedValue(value)) Reorder.drop(group, value)
586
610
  holdEnd(value, "unmount")
587
- if (keyed.get(value) === k) keyed.delete(value)
611
+ if (keyed.get(idOf(value)) === k) keyed.delete(idOf(value))
588
612
  },
589
613
  }
590
614
  }
@@ -610,7 +634,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
610
634
  valuesChanged: () => {
611
635
  // The app changed `values` itself while an item is lifted: it's dropped at its new place. The group's
612
636
  // own order is told by its items, not its array: a binding reads a store's order as a new one (#721).
613
- if (Option.isSome(Reorder.liftedValue(group)) && Bool.not(isAsked(asked, options.values()))) dropLifted()
637
+ if (Option.isSome(Reorder.liftedValue(group)) && Bool.not(isAsked(asked, options.values(), sameItems))) dropLifted()
614
638
  wiring.layOut()
615
639
  },
616
640
  dispose: () => {
@@ -625,9 +649,12 @@ const noop = (): void => {}
625
649
  /** Whether two orders hold the same items in the same order. */
626
650
  export const sameOrder: Equivalence.Equivalence<ReadonlyArray<unknown>> = Arr.makeEquivalence(Equivalence.strictEqual())
627
651
 
628
- /** Whether `values` is the order the group last asked for (ADR-0037, *Amendment (#721)*): its items, in its order. */
629
- const isAsked = (asked: ReadonlyArray<unknown> | undefined, values: ReadonlyArray<unknown>): boolean =>
630
- UndefinedOr.match(asked, { onUndefined: constFalse, onDefined: (order) => sameOrder(order, values) })
652
+ /**
653
+ * Whether `values` is the order the group last asked for (ADR-0037, *Amendment (#721)*): its items, in its
654
+ * order, matched as the group matches them (`sameItems`: by `key` where it's given).
655
+ */
656
+ const isAsked = <V>(asked: ReadonlyArray<V> | undefined, values: ReadonlyArray<V>, sameItems: Equivalence.Equivalence<ReadonlyArray<V>>): boolean =>
657
+ UndefinedOr.match(asked, { onUndefined: constFalse, onDefined: (order) => sameItems(order, values) })
631
658
 
632
659
  /**
633
660
  * A {@link ReorderController} for a server render (ADR-0021), where there's no projection
@@ -86,14 +86,14 @@ export type StyleRecord = Readonly<Record<string, unknown>>
86
86
 
87
87
  /** A style given as CSS text, parsed; a record as it is. */
88
88
  const recordOf = (input: object | string): StyleRecord => {
89
- // Per element at mount (#540): statements.
89
+ // Per Subject at mount (#540): statements.
90
90
  if (Predicate.isString(input)) return parseCssText(input)
91
91
  return input as StyleRecord
92
92
  }
93
93
 
94
94
  /** A style given as CSS text, parsed; a record as it is; none, an empty record. */
95
95
  const recordOfInput = (input: StyleInput): StyleRecord => {
96
- // Per element at mount (#540): statements.
96
+ // Per Subject at mount (#540): statements.
97
97
  if (Predicate.isUndefined(input)) return {}
98
98
  return recordOf(input)
99
99
  }
@@ -135,7 +135,7 @@ export const over: {
135
135
  (that: StyleInput): (self: StyleInput) => StyleRecord
136
136
  (self: StyleInput, that: StyleInput): StyleRecord
137
137
  } = dual(2, (self: StyleInput, that: StyleInput): StyleRecord => {
138
- // Per element at mount (#540): statements.
138
+ // Per Subject at mount (#540): statements.
139
139
  if (Predicate.isUndefined(that)) return recordOfInput(self)
140
140
  if (Predicate.isUndefined(self)) return recordOf(that)
141
141
  return layered(recordOf(self), recordOf(that))
@@ -143,7 +143,7 @@ export const over: {
143
143
 
144
144
  /** Whether `key`, a CSS property, is one of the gate's held patch keys: by its name, or its name dash-cased. */
145
145
  const isHeld = (held: ReadonlyArray<string>, key: string): boolean => {
146
- // Per element at mount (#540): a loop.
146
+ // Per Subject at mount (#540): a loop.
147
147
  for (const patchKey of held) {
148
148
  if (patchKey === key || dashCase(patchKey) === key) return true
149
149
  }
@@ -163,7 +163,7 @@ export const without: {
163
163
  (held: ReadonlyArray<string>): (self: StyleInput) => StyleRecord
164
164
  (self: StyleInput, held: ReadonlyArray<string>): StyleRecord
165
165
  } = dual(2, (self: StyleInput, held: ReadonlyArray<string>): StyleRecord => {
166
- // Per element at mount (#540): a loop.
166
+ // Per Subject at mount (#540): a loop.
167
167
  const record = recordOfInput(self)
168
168
  const out: Record<string, unknown> = {}
169
169
  for (const key of Object.keys(record)) {
@@ -1,15 +1,17 @@
1
1
  /**
2
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.
3
+ * own, which no other Environment draws as the DOM does: `translateX`, `translateY` and `translateZ` beside
4
+ * `x`, `y` and `z`, the turn in the page's plane (`rotate`), the skews and the element's own depth
5
+ * (`transformPerspective`). Every DOM reader of a transform key reads this table, so the DOM's own keys
6
+ * are transforms to each of them: the renderer, Own values, a Batch's members, Appear, reduced motion and
7
+ * the Default transition.
6
8
  *
7
9
  * @module
8
10
  */
9
11
  // #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.
12
+ // adds the box's keys to core's transforms, this adds the DOM's own transform keys to core's: the depth
13
+ // (#887), and the six core named until #1002 (ADR-0073, *Amendment (#1002)*), Motion's names, which came
14
+ // over with its list in #47. TK1 pins that no dom source reads core's table but this module.
13
15
  import * as BaseValue from "@wardic/core/BaseValue"
14
16
  import * as Option from "effect/Option"
15
17
  import * as Predicate from "effect/Predicate"
@@ -19,10 +21,20 @@ import * as Rec from "effect/Record"
19
21
  export const PERSPECTIVE = "transformPerspective"
20
22
 
21
23
  /**
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
+ * Each of the DOM's transform keys, with its identity: core's, and the DOM's own 0s, no translation, turn
25
+ * or skew. {@link PERSPECTIVE}'s 0 is no perspective, not a depth: it's left out of the transform, as
26
+ * Motion's is.
24
27
  */
25
- export const TRANSFORM_IDENTITY: Readonly<Record<string, number>> = Object.freeze({ ...BaseValue.TRANSFORM_IDENTITY, [PERSPECTIVE]: 0 })
28
+ export const TRANSFORM_IDENTITY: Readonly<Record<string, number>> = Object.freeze({
29
+ ...BaseValue.TRANSFORM_IDENTITY,
30
+ translateX: 0,
31
+ translateY: 0,
32
+ translateZ: 0,
33
+ rotate: 0,
34
+ skewX: 0,
35
+ skewY: 0,
36
+ [PERSPECTIVE]: 0,
37
+ })
26
38
 
27
39
  /** A DOM transform key's identity (see {@link TRANSFORM_IDENTITY}), or `None` for any other key, prototype names included. */
28
40
  export const transformIdentity = (key: string): Option.Option<number> => Rec.get(TRANSFORM_IDENTITY, key)
@@ -1756,7 +1756,7 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
1756
1756
  watchedOn[i] = el
1757
1757
  const entry = entries[i]
1758
1758
  watch({
1759
- element: () => el,
1759
+ subject: () => el,
1760
1760
  holds: true,
1761
1761
  leave: (custom, release) => memberLeft(i, entry, el, custom, release),
1762
1762
  gone: () => watchGone(i, entry, el),
@@ -140,7 +140,9 @@ export interface DragTrackConfig {
140
140
  * Motion's `dragListener`: `false`, the element's own presses start no drag and stop no
141
141
  * release; only its **Drag controls**' starts do. Default `true`.
142
142
  */
143
- readonly listen?: boolean | undefined
143
+ // A predicate, asked of each down (probe: behaviour-runes): an element that drags from part of itself
144
+ // alone hears a press there, and any press while it doesn't (the hooks' Grips).
145
+ readonly listen?: boolean | ((down: InputSource.PointerLikeEvent) => boolean) | undefined
144
146
  }
145
147
 
146
148
  /** The drag props a track's config is read from: an element's, its axis and its constraints resolved by the binding. */
@@ -451,6 +453,23 @@ const isGrab: Predicate.Predicate<InputSource.PointerLikeEvent> = Predicate.and(
451
453
  /** A down the element adopted from its **Drag controls** (#431). */
452
454
  const isAdopted: Predicate.Predicate<InputSource.PointerLikeEvent> = (e) => e.adopted === true
453
455
 
456
+ /** A drag's `listen`: whether it hears its own presses, or which of them. */
457
+ type Listen = boolean | ((down: InputSource.PointerLikeEvent) => boolean)
458
+
459
+ /**
460
+ * Which downs grab, by the drag's `listen` (#431): every grab, only an adopted one, or one it's asked of
461
+ * and says it hears, or adopted (probe: behaviour-runes, the hooks' Grips). Built once, at module load.
462
+ */
463
+ const grabsOf: (listen: Listen) => Predicate.Predicate<InputSource.PointerLikeEvent> = Match.type<Listen>().pipe(
464
+ Match.when(true, () => isGrab),
465
+ Match.when(false, () => Predicate.and(isGrab, isAdopted)),
466
+ Match.orElse((hears) => (e: InputSource.PointerLikeEvent): boolean => {
467
+ if (Bool.not(isGrab(e))) return false
468
+ if (hears(e)) return true
469
+ return isAdopted(e)
470
+ }),
471
+ )
472
+
454
473
  /**
455
474
  * A layout node's snap to the cursor ended with no drag (#431): its drag ended at rest, back to its
456
475
  * slot. Whether there was one. A module's, not a track's (#507): a track given no Drag controls never
@@ -828,7 +847,7 @@ export const driveDragTrack = (opts: DragTrackOptions): DragTrack => {
828
847
  onDefined: (at) => () => toDragAxis(at()),
829
848
  })
830
849
  const { propagation = false } = config
831
- const listens = config.listen !== false
850
+ const listens = UndefinedOr.match(config.listen, { onUndefined: (): Listen => true, onDefined: identity })
832
851
 
833
852
  // --- Drag controls (#431), only for an element given them (#507) ----------------------------
834
853
  const controlled = Predicate.isNotUndefined(opts.controls)
@@ -878,9 +897,10 @@ export const driveDragTrack = (opts: DragTrackOptions): DragTrack => {
878
897
  FiberHandle.clear(releasing).pipe(Effect.andThen(measureAtStart), Effect.andThen(Effect.sync(() => follow(sample, state, opts))))),
879
898
  Match.when("move", () =>
880
899
  FiberHandle.clear(releasing).pipe(Effect.andThen(Effect.sync(() => follow(sample, state, opts))))),
881
- // A cancelled end (#431) stays where it is: no release, `x`/`y` handed back.
900
+ // An end drag controls cancelled (#431) stays where it is: no release, `x`/`y` handed back. Any
901
+ // other is released, a pointer's cancel too, which carries no velocity and so doesn't fling (#1042).
882
902
  Match.when("end", () =>
883
- Bool.match(sample.cancelled === true, {
903
+ Bool.match(sample.endedBy === "controls", {
884
904
  onTrue: () => Effect.sync(() => UndefinedOr.match(opts.projection, { onUndefined: () => opts.setDragging(false), onDefined: constVoid })),
885
905
  onFalse: () => releaseFrom(sample),
886
906
  }).pipe(Effect.andThen(Effect.sync(() => reportSample(opts, sample))))),
@@ -959,7 +979,7 @@ export const driveDragTrack = (opts: DragTrackOptions): DragTrack => {
959
979
  onDefect,
960
980
  })
961
981
  // A down grabs when the drag listens to it (#431): with `listen: false`, only an adopted one.
962
- const grabs = Bool.match(listens, { onTrue: () => isGrab, onFalse: () => Predicate.and(isGrab, isAdopted) })
982
+ const grabs = grabsOf(listens)
963
983
  // The adoptable feed with controls (#507), so a grab hears an adopted down; the plain one without.
964
984
  const pointerFeed = Bool.match(controlled, { onTrue: () => InputSource.adoptablePointerOf(input, element), onFalse: () => input.pointer(element) })
965
985
  yield* InputFeed.watch(pointerFeed, {
@@ -239,7 +239,7 @@ const filled = new WeakMap<ValueReads, ElementValueReads>()
239
239
  * nothing.
240
240
  */
241
241
  export const valueReadsOf = (given: ValueReads): ElementValueReads => {
242
- // Per element at mount (#540): statements. `DomLive` gives none: the DOM's, with no lookup.
242
+ // Per Subject at mount (#540): statements. `DomLive` gives none: the DOM's, with no lookup.
243
243
  if (Bool.and(Predicate.isUndefined(given.ownValues), Bool.and(Predicate.isUndefined(given.measuredPairs), Predicate.isUndefined(given.variableValues)))) return DOM_VALUE_READS
244
244
  const kept = filled.get(given)
245
245
  if (Predicate.isNotUndefined(kept)) return kept
@@ -471,10 +471,11 @@ export const unreadColorIn = (values: Readonly<Record<string, unknown>>): string
471
471
 
472
472
  /**
473
473
  * Development's word on a Complete element under a `strict` section (#511, ADR-0067 decision 7,
474
- * Motion's), naming the binding's `complete` forms and the `slim` ones to use.
474
+ * Motion's), naming the binding's `complete` forms and the `slim` ones to use, and `under`, where
475
+ * its `strict` was given: by default Solid 1's, a provider or a `LazyWardic`.
475
476
  */
476
- export const strictMessage = (complete: string, slim: string): string =>
477
- `wardic: a Complete element (${complete}) is rendered under a strict WardicProvider or LazyWardic. ` +
477
+ export const strictMessage = (complete: string, slim: string, under: string = "a strict WardicProvider or LazyWardic"): string =>
478
+ `wardic: a Complete element (${complete}) is rendered under ${under}. ` +
478
479
  `It brings every Feature's code with it; render the Slim element (${slim}) instead.`
479
480
 
480
481
  /** What development's word on a missing `layout` Feature names (#511): the props that need it. */
@@ -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>>()