@wardic/dom 1.0.0-rc.9 → 1.0.1

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 (82) 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.js +1 -1
  50. package/dist/internal/measure.js.map +1 -1
  51. package/dist/internal/projection.js +1 -1
  52. package/dist/internal/projection.js.map +1 -1
  53. package/dist/internal/renderer.d.ts +18 -0
  54. package/dist/internal/renderer.d.ts.map +1 -1
  55. package/dist/internal/renderer.js +4 -2
  56. package/dist/internal/renderer.js.map +1 -1
  57. package/dist/internal/reorder.d.ts +28 -13
  58. package/dist/internal/reorder.d.ts.map +1 -1
  59. package/dist/internal/reorder.js +55 -26
  60. package/dist/internal/reorder.js.map +1 -1
  61. package/dist/internal/reveal.d.ts +7 -3
  62. package/dist/internal/reveal.d.ts.map +1 -1
  63. package/dist/internal/reveal.js +8 -3
  64. package/dist/internal/reveal.js.map +1 -1
  65. package/package.json +4 -4
  66. package/src/Appear.ts +12 -3
  67. package/src/DomBatch.ts +22 -0
  68. package/src/DomInput.ts +2 -1
  69. package/src/KeyboardPress.ts +16 -0
  70. package/src/ReorderController.ts +54 -4
  71. package/src/index.ts +5 -3
  72. package/src/internal/appear-slot.ts +32 -0
  73. package/src/internal/appear.ts +462 -67
  74. package/src/internal/batch-writer.ts +95 -0
  75. package/src/internal/gate.ts +7 -3
  76. package/src/internal/input.ts +209 -25
  77. package/src/internal/keyboard-press.ts +45 -0
  78. package/src/internal/measure.ts +1 -1
  79. package/src/internal/projection.ts +1 -1
  80. package/src/internal/renderer.ts +4 -2
  81. package/src/internal/reorder.ts +85 -39
  82. package/src/internal/reveal.ts +10 -4
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The DOM's writer for a Batch (#665): each moving member's `transform` and `opacity`, written onto
3
+ * its element's style as it steps, as `DomRenderer.project` draws the same values.
4
+ *
5
+ * @module
6
+ */
7
+ // ADR-0069 decision 11 and *Amendment (#665)*, ADR-0070 *Amendment (#665)*: the DOM's keys are core's
8
+ // transform keys and `opacity`, numbers in their `px`, `deg` or no unit. A Batch writes outside the
9
+ // Flush gate (ADR-0034, *Amendment (#665)*), so its write is a `setProperty` per moving member.
10
+ import type * as Batch from "@wardic/core/Batch"
11
+ import * as Arr from "effect/Array"
12
+ import * as Bool from "effect/Boolean"
13
+ import * as Option from "effect/Option"
14
+ import * as Predicate from "effect/Predicate"
15
+ import * as Result from "effect/Result"
16
+ import { TRANSFORM_FUNCS, unitOf } from "./renderer.ts"
17
+
18
+ /** A transform function a Batch writes: its key's index in the Batch, what goes either side of its value, and its identity. */
19
+ interface Part {
20
+ readonly k: number
21
+ readonly open: string
22
+ readonly close: string
23
+ readonly identity: number
24
+ }
25
+
26
+ /** The transform functions a member draws: the renderer's, less a path's turn, which an arc's element draws (#438). */
27
+ const FUNCS = Arr.filter(TRANSFORM_FUNCS, (func) => func.key !== "pathRotation")
28
+
29
+ /** The keys the DOM's writer draws: those transform keys and `opacity`. */
30
+ const DRAWS: ReadonlySet<string> = new Set([...Arr.map(FUNCS, (func) => func.key), "opacity"])
31
+
32
+ /** Each transform function's key, what goes either side of its value, and its identity, in the renderer's order: what `forKeys` and `styleOf` draw. */
33
+ const FUNC_PARTS: ReadonlyArray<Omit<Part, "k"> & { readonly key: string }> = Arr.map(FUNCS, (func) => ({
34
+ key: func.key,
35
+ open: `${func.fn}(`,
36
+ close: `${unitOf(func.key)})`,
37
+ identity: func.identity,
38
+ }))
39
+
40
+ /** A Batch's write, for its keys in their order: built once, when the Batch is made. */
41
+ const forKeys = (keys: ReadonlyArray<string>): ((el: Element, positions: Float64Array, base: number) => void) => {
42
+ const parts: ReadonlyArray<Part> = Arr.filterMap(FUNC_PARTS, (part) =>
43
+ Option.match(Arr.findFirstIndex(keys, (key) => key === part.key), {
44
+ onNone: () => Result.failVoid,
45
+ onSome: (k) => Result.succeed({ k, open: part.open, close: part.close, identity: part.identity }),
46
+ }))
47
+ const count = parts.length
48
+ // Its index for the per-frame write, or -1 for none: a plain read there (ADR-0025, the per-frame path).
49
+ const opacityAt = Option.getOrElse(Arr.findFirstIndex(keys, (key) => key === "opacity"), () => -1)
50
+ // Per frame, per moving member (ADR-0025, *Amendment (#69)*): a counted loop over its transform
51
+ // functions in the renderer's order, each left out at its identity, the string built by concatenation
52
+ // as the renderer's is (ADR-0034); `none` when every one is at its identity (ADR-0023).
53
+ return (el, positions, base) => {
54
+ const style = (el as HTMLElement).style
55
+ if (count > 0) {
56
+ let transform = ""
57
+ let separator = ""
58
+ for (let p = 0; p < count; p++) {
59
+ const part = parts[p]
60
+ const value = positions[base + part.k]
61
+ if (value === part.identity) continue
62
+ transform = transform + separator + part.open + value + part.close
63
+ separator = " "
64
+ }
65
+ if (transform === "") transform = "none"
66
+ style.setProperty("transform", transform)
67
+ }
68
+ if (opacityAt !== -1) style.setProperty("opacity", String(positions[base + opacityAt]))
69
+ }
70
+ }
71
+
72
+ /**
73
+ * A member's style as a server writes it (#665's PR 6, Q63): `values`' `transform` and `opacity`, the
74
+ * strings `forKeys`' write draws them with, each left out at its identity. What the client then writes
75
+ * at the member's arrival is the same, so its element doesn't move at hydration.
76
+ */
77
+ export const styleOf = (values: Readonly<Record<string, number>>): Readonly<Record<string, string>> => {
78
+ const style: Record<string, string> = {}
79
+ // Once a member on a server: in the renderer's order, as `forKeys`' write.
80
+ const functions = Arr.filterMap(FUNC_PARTS, (part) => {
81
+ const value = values[part.key]
82
+ if (Bool.or(Predicate.isUndefined(value), value === part.identity)) return Result.failVoid
83
+ return Result.succeed(part.open + value + part.close)
84
+ })
85
+ if (functions.length > 0) style.transform = functions.join(" ")
86
+ const opacity = values.opacity
87
+ if (Bool.and(Predicate.isNotUndefined(opacity), opacity !== 1)) style.opacity = String(opacity)
88
+ return style
89
+ }
90
+
91
+ /** The DOM's Batch writer: an element's `transform` and `opacity`. */
92
+ export const writer: Batch.Writer<Element> = {
93
+ writes: (key) => DRAWS.has(key),
94
+ forKeys,
95
+ }
@@ -177,9 +177,11 @@ export interface FlushGate {
177
177
  * value-map and schedule a flush, which writes `restore[key]` (CSS text) for a key it had
178
178
  * written, or else the inline value it overwrote, and tells the sink (`onHeld`). A key the
179
179
  * entry doesn't hold, or an unknown id, is a no-op. A binding releases a key back at its `style`
180
- * value, so a later `style` change shows at rest. A later `write` brings the key back.
180
+ * value, so a later `style` change shows at rest. A later `write` brings the key back. A property in
181
+ * `keep` (`transform` for its keys) is left as it's drawn when it drops out: another writer draws it next.
181
182
  */
182
- readonly release: (id: string, keys: ReadonlyArray<string>, restore?: Readonly<Record<string, string>>) => void
183
+ // `keep`: #665's PR 4, a Batch member's group handed back to its Batch, whose writer draws it from then on.
184
+ readonly release: (id: string, keys: ReadonlyArray<string>, restore?: Readonly<Record<string, string>>, keep?: ReadonlyArray<string>) => void
183
185
  /**
184
186
  * The element's value for `id`'s `key`, live: an `Atom` set as each write that
185
187
  * changes it lands, so it's the value the next commit draws, before the Renderer projects it
@@ -548,9 +550,11 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
548
550
  commitAll(entries, held)
549
551
  }
550
552
 
551
- const release: FlushGate["release"] = (id, keys, restore) => {
553
+ const release: FlushGate["release"] = (id, keys, restore, keep) => {
552
554
  const entry = accumulator.get(id)
553
555
  if (Predicate.isUndefined(entry)) return
556
+ // A property another writer draws next: dropped from what's saved, so its drop-out writes nothing.
557
+ if (Predicate.isNotUndefined(keep)) for (const property of keep) entry.committed.delete(property)
554
558
  let released = false
555
559
  for (const key of keys) {
556
560
  if (!Object.hasOwn(entry.values, key)) continue
@@ -51,6 +51,7 @@ import * as Arr from "effect/Array"
51
51
  import * as Bool from "effect/Boolean"
52
52
  import * as Effect from "effect/Effect"
53
53
  import { constTrue, constVoid, identity } from "effect/Function"
54
+ import * as Iter from "effect/Iterable"
54
55
  import * as Layer from "effect/Layer"
55
56
  import * as Match from "effect/Match"
56
57
  import * as Option from "effect/Option"
@@ -360,31 +361,6 @@ const keyActionOf = (key: InputSource.Key, at: EventTarget | null): InputSource.
360
361
  return "none"
361
362
  }
362
363
 
363
- /** The HTML elements that take the keyboard's focus of themselves (#427): a link only with its `href`. */
364
- const FOCUSABLE_ELEMENTS: ReadonlySet<string> = new Set(["BUTTON", "INPUT", "SELECT", "TEXTAREA", "SUMMARY", "IFRAME"])
365
-
366
- /** Whether `el` takes focus of itself: a control, a link, an editable region, or one given a `tabindex`. */
367
- const takesFocus = (el: HTMLElement): boolean =>
368
- Bool.some([
369
- FOCUSABLE_ELEMENTS.has(el.tagName),
370
- Bool.and(Bool.or(el.tagName === "A", el.tagName === "AREA"), el.hasAttribute("href")),
371
- el.isContentEditable,
372
- el.hasAttribute("tabindex"),
373
- ])
374
-
375
- /**
376
- * Makes a pressable element focusable, as Motion's press does: an HTML element that doesn't take focus
377
- * of itself, with no `tabindex`, gets `tabindex="0"`, so a key can press it. An SVG element, or one
378
- * already focusable, is left as it is. Called at mount, on the client.
379
- */
380
- // #427: a **Keyboard press**.
381
- export const makeFocusable = (target: unknown): void => {
382
- if (Bool.not(Predicate.hasProperty(target, "isContentEditable"))) return
383
- const el = target as HTMLElement
384
- if (takesFocus(el)) return
385
- el.tabIndex = 0
386
- }
387
-
388
364
  /** A key as the engine's portable event: core's key name, and the page's `preventDefault` as `handled`/`handle()`. */
389
365
  const toKeyboard = (type: InputSource.KeyboardLikeEvent["type"], ev: KeyboardEvent, target: unknown): InputSource.KeyboardLikeEvent => {
390
366
  const key = keyOf(ev.key)
@@ -528,6 +504,209 @@ const focusWithin = (target: unknown): boolean => {
528
504
  return (target as Node).contains(active)
529
505
  }
530
506
 
507
+ // --- Feeds over many targets (#665's PR 5, Q56): a Batch's members, from one listener set ------------
508
+
509
+ /**
510
+ * The pointer events a feed over many targets hears, at its window in the bubble phase: after the page's
511
+ * handlers and each element's own listeners, so a press inside a member has marked its **Press claim**
512
+ * by then (#439). No `pointermove`: a held pointer's moves come through its page-wide feed, and a move
513
+ * that isn't held changes no hover or press.
514
+ */
515
+ const AMONG_POINTER: ReadonlyArray<string> = ["pointerover", "pointerout", "pointerdown", "pointerup", "pointercancel"]
516
+
517
+ /** `node`'s parent, a shadow root's host for the root: the composed tree's. */
518
+ const parentOf = (node: Node): Node | null => {
519
+ const parent = node.parentNode
520
+ if (Predicate.isNull(parent)) return null
521
+ if (parent.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
522
+ const host = (parent as ShadowRoot).host
523
+ if (Predicate.isNotUndefined(host)) return host
524
+ }
525
+ return parent
526
+ }
527
+
528
+ /** What names the member a node is, `Option.none()` for none: core's `pointerAmong`'s and `focusAmong`'s. */
529
+ type MemberOf = (node: unknown) => Option.Option<unknown>
530
+
531
+ /** The members `node` is or is inside, innermost first, as `memberOf` names them: for a node with no path, a `relatedTarget`. */
532
+ // Per pointer event over the page (#665).
533
+ const membersFrom = (node: EventTarget | null, memberOf: MemberOf): ReadonlyArray<unknown> => {
534
+ const found: Array<unknown> = []
535
+ if (isNode(node)) membersUp(node as Node, memberOf, found)
536
+ return found
537
+ }
538
+
539
+ /** `at`'s member, then its ancestors', up the composed tree, into `found`: a recursion as deep as the node. */
540
+ const membersUp = (at: Node, memberOf: MemberOf, found: Array<unknown>): void => {
541
+ Option.map(memberOf(at), (member) => found.push(member))
542
+ const parent = parentOf(at)
543
+ if (Predicate.isNotNull(parent)) membersUp(parent, memberOf, found)
544
+ }
545
+
546
+ /** The members an event passed through, innermost first: its composed path's, so a member in a shadow root counts. */
547
+ const membersOnPath = (ev: Event, memberOf: MemberOf): ReadonlyArray<unknown> => {
548
+ const found: Array<unknown> = []
549
+ Arr.forEach(ev.composedPath(), (node) => {
550
+ Option.map(memberOf(node), (member) => found.push(member))
551
+ })
552
+ return found
553
+ }
554
+
555
+ /** A member's held pointer, while one pressed on it is held: how its events reach it, and what stops it. */
556
+ interface HeldMember {
557
+ toTarget: ((event: InputSource.PointerLikeEvent, raw: unknown) => void) | undefined
558
+ readonly pointers: Set<number>
559
+ stop: () => void
560
+ }
561
+
562
+ /**
563
+ * The pointer events over `memberOf`'s members, each told with its member (core's `pointerAmong`): their
564
+ * enters and leaves, from `pointerover` and `pointerout` (a member's from where the pointer was, outside
565
+ * it; nested members each once, enters outermost first and leaves innermost first, as the DOM's
566
+ * `pointerenter` and `pointerleave`), the downs, releases and cancels over each, and once one goes down on
567
+ * a member, that pointer's events wherever they land, through core's `heldPointer`, made for the member
568
+ * at the down and let go once nothing it pressed is held.
569
+ */
570
+ // The page's window: a member in an iframe's document is heard by none (a feed over many targets has no one
571
+ // target whose window to take, as each per-target feed does).
572
+ const pointerAmongOf = (memberOf: MemberOf): InputFeed.InputFeed<InputSource.TargetEvent<InputSource.PointerLikeEvent>> => (emit) => {
573
+ const win = window
574
+ const held = new Map<unknown, HeldMember>()
575
+ /** `member`'s event: through its held pointer while it has one, else told at once. */
576
+ const deliver = (member: unknown, event: InputSource.PointerLikeEvent, raw: unknown): void => {
577
+ const holding = held.get(member)
578
+ if (Predicate.isUndefined(holding)) return emit({ target: member, event })
579
+ const toTarget = holding.toTarget
580
+ if (Predicate.isUndefined(toTarget)) return emit({ target: member, event })
581
+ toTarget(event, raw)
582
+ }
583
+ /** `member`'s held pointer, made for a down on it. */
584
+ const holdOn = (member: unknown): HeldMember => {
585
+ const known = held.get(member)
586
+ if (Predicate.isNotUndefined(known)) return known
587
+ const made: HeldMember = { toTarget: undefined, pointers: new Set(), stop: constVoid }
588
+ held.set(member, made)
589
+ made.stop = InputSource.heldPointer({
590
+ target: (toTarget) => {
591
+ made.toTarget = toTarget
592
+ return () => {
593
+ made.toTarget = undefined
594
+ }
595
+ },
596
+ global: feedOf(windowOf(member), HELD_POINTER_EVENTS, CAPTURE_PASSIVE, landedOn(member)),
597
+ scroll: scrollFeedOf(member),
598
+ })(
599
+ (event) => {
600
+ emit({ target: member, event })
601
+ // Let go once nothing pressed on it is held: after this dispatch, which may still reach it.
602
+ if (event.type === "down") {
603
+ if (event.adopted !== true) made.pointers.add(event.pointerId)
604
+ return
605
+ }
606
+ if (Bool.not(endsHoldOf(event))) return
607
+ made.pointers.delete(event.pointerId)
608
+ if (made.pointers.size > 0) return
609
+ queueMicrotask(() => {
610
+ if (Bool.or(made.pointers.size > 0, held.get(member) !== made)) return
611
+ held.delete(member)
612
+ made.stop()
613
+ })
614
+ },
615
+ constVoid,
616
+ )
617
+ return made
618
+ }
619
+ /** The members `ev` crossed into (`pointerover`) or out of (`pointerout`): on its path, not where the pointer came from or went. */
620
+ const crossed = (ev: PointerEvent): ReadonlyArray<unknown> => {
621
+ const other = membersFrom(ev.relatedTarget, memberOf)
622
+ // By reference: `Arr.contains`' structural equality would walk a DOM node.
623
+ return Arr.filter(membersOnPath(ev, memberOf), (member) => Bool.not(Arr.some(other, (outside) => outside === member)))
624
+ }
625
+ /** A down, a release or a cancel: each member it passed through hears it, innermost first, a down holding it. */
626
+ const toEach = (ev: PointerEvent): void => {
627
+ const members = membersOnPath(ev, memberOf)
628
+ if (members.length === 0) return
629
+ const event = toPointer(UndefinedOr.getOrThrow(POINTER_TYPE[ev.type]), ev)
630
+ Arr.forEach(members, (member) => {
631
+ if (event.type === "down") holdOn(member)
632
+ deliver(member, event, ev)
633
+ })
634
+ }
635
+ // Each event type's handling, made once a subscription: one record read an event.
636
+ const byType: Readonly<Record<string, (ev: PointerEvent) => void>> = {
637
+ pointerover: (ev) => {
638
+ const entered = crossed(ev)
639
+ if (entered.length === 0) return
640
+ const event = toPointer("enter", ev)
641
+ // Outermost first, as `pointerenter`.
642
+ Arr.forEach(Arr.reverse(entered), (member) => deliver(member, event, ev))
643
+ },
644
+ pointerout: (ev) => {
645
+ const left = crossed(ev)
646
+ if (left.length === 0) return
647
+ const event = toPointer("leave", ev)
648
+ Arr.forEach(left, (member) => deliver(member, event, ev))
649
+ },
650
+ pointerdown: toEach,
651
+ pointerup: toEach,
652
+ pointercancel: toEach,
653
+ }
654
+ const listener = (raw: Event): void => UndefinedOr.getOrThrow(byType[raw.type])(raw as PointerEvent)
655
+ Arr.forEach(AMONG_POINTER, (type) => win.addEventListener(type, listener, PASSIVE))
656
+ return () => {
657
+ Arr.forEach(AMONG_POINTER, (type) => win.removeEventListener(type, listener, PASSIVE))
658
+ Iter.forEach(held, ([, holding]) => holding.stop())
659
+ held.clear()
660
+ }
661
+ }
662
+
663
+ /** Whether `event` ends its pointer's hold: its release, its cancel, or a move with no button pressed. */
664
+ const endsHoldOf = (event: InputSource.PointerLikeEvent): boolean => {
665
+ if (event.type === "up") return true
666
+ if (event.type === "cancel") return true
667
+ return Bool.and(event.type === "move", Bool.not(event.pressed))
668
+ }
669
+
670
+ /** The element focus is on in `doc`, inside any shadow root it's in; `null` for none but the page's own. */
671
+ const deepActiveOf = (doc: Document): Element | null => {
672
+ const active = doc.activeElement
673
+ if (Bool.or(Predicate.isNull(active), active === doc.body)) return null
674
+ return innermostActive(active as Element)
675
+ }
676
+
677
+ /** The element focus is on inside `el`'s shadow root, and inside its, else `el`. */
678
+ const innermostActive = (el: Element): Element => {
679
+ const root = el.shadowRoot
680
+ if (Predicate.isNull(root)) return el
681
+ const inner = root.activeElement
682
+ if (Predicate.isNull(inner)) return el
683
+ return innermostActive(inner)
684
+ }
685
+
686
+ /**
687
+ * The focus and blur of `memberOf`'s members and of what's inside each (core's `focusAmong`): `focusin`
688
+ * and `focusout` on the window in the capture phase, as a target's own feed hears them (#460), told to
689
+ * each member on the event's path, innermost first, a member's own when the path starts at it. A focus
690
+ * already within a member at subscribe is told as its focus first, so its keys press it from now, as a
691
+ * per-target press opens its keys when `focusWithin` says so.
692
+ */
693
+ const focusAmongOf = (memberOf: MemberOf): InputFeed.InputFeed<InputSource.TargetEvent<InputSource.FocusLikeEvent>> => (emit) => {
694
+ const win = window
695
+ const listener = (raw: Event): void => {
696
+ const ev = raw as FocusEvent
697
+ const members = membersOnPath(ev, memberOf)
698
+ if (members.length === 0) return
699
+ Arr.forEach(members, (member) => emit({ target: member, event: toPathFocus(ev, member) }))
700
+ }
701
+ const active = deepActiveOf(win.document)
702
+ if (Predicate.isNotNull(active)) {
703
+ Arr.forEach(membersFrom(active, memberOf), (member) =>
704
+ emit({ target: member, event: { type: "focus", timeStamp: win.performance.now(), visible: focusVisible(active), fromTarget: active === member } }))
705
+ }
706
+ Arr.forEach(FOCUS.types, (type) => win.addEventListener(type, listener, FOCUS.capture))
707
+ return () => Arr.forEach(FOCUS.types, (type) => win.removeEventListener(type, listener, FOCUS.capture))
708
+ }
709
+
531
710
  /**
532
711
  * The DOM's **Input feeds** (#318): each shared per target by core's `InputFeed.byTarget`, so a
533
712
  * target's hover, press and drag start one listener-set, not three. `pointer`'s target, page-wide
@@ -558,6 +737,9 @@ const make = Effect.gen(function* () {
558
737
  )
559
738
  const focus = InputFeed.byTarget(focusOf)
560
739
  const keyboard = InputFeed.byTarget(keyboardOf)
740
+ // Feeds over many targets (#665's PR 5): one listener set for each `memberOf`, shared by its watches.
741
+ const pointerAmong = InputFeed.byTarget((memberOf) => pointerAmongOf(memberOf as MemberOf))
742
+ const focusAmong = InputFeed.byTarget((memberOf) => focusAmongOf(memberOf as MemberOf))
561
743
 
562
744
  return InputSource.InputSource.of({
563
745
  pointer,
@@ -566,6 +748,8 @@ const make = Effect.gen(function* () {
566
748
  keyboard,
567
749
  focusWithin,
568
750
  adoptPointer: adoptPointerIn(adopters),
751
+ pointerAmong,
752
+ focusAmong,
569
753
  })
570
754
  })
571
755
 
@@ -0,0 +1,45 @@
1
+ /**
2
+ * A Keyboard press's focusability (#427): the element a press's keys reach must take focus. A module of
3
+ * its own (#709), so a binding makes an element focusable as it mounts without loading the DOM's input.
4
+ *
5
+ * @internal
6
+ */
7
+ import * as Predicate from "effect/Predicate"
8
+
9
+ /** The HTML elements that take the keyboard's focus of themselves (#427). */
10
+ const FOCUSABLE_ELEMENTS: ReadonlySet<string> = new Set(["BUTTON", "INPUT", "SELECT", "TEXTAREA", "SUMMARY", "IFRAME"])
11
+
12
+ /** The links, which take focus with their `href`. */
13
+ const LINK_ELEMENTS: ReadonlySet<string> = new Set(["A", "AREA"])
14
+
15
+ /** Whether `el` takes focus of itself: a control, one given a `tabindex`, a link, or an editable region. */
16
+ const takesFocus = (el: HTMLElement): boolean => {
17
+ // Per pressable element at mount (#709): statements, the cheapest reads first, each only if needed.
18
+ const tag = el.tagName
19
+ if (FOCUSABLE_ELEMENTS.has(tag)) return true
20
+ if (el.hasAttribute("tabindex")) return true
21
+ if (LINK_ELEMENTS.has(tag)) {
22
+ if (el.hasAttribute("href")) return true
23
+ }
24
+ return el.isContentEditable
25
+ }
26
+
27
+ /** Whether `target` is an HTML element: `Predicate.hasProperty(target, "isContentEditable")`'s own test. */
28
+ const isHtmlElement = (target: unknown): target is HTMLElement => {
29
+ // Per pressable element at mount (#709): statements, without `hasProperty`'s `dual` call.
30
+ return Predicate.isObjectKeyword(target) && "isContentEditable" in target
31
+ }
32
+
33
+ /**
34
+ * Makes a pressable element focusable, as Motion's press does: an HTML element that doesn't take focus
35
+ * of itself, with no `tabindex`, gets `tabindex="0"`, so a key can press it. An SVG element, or one
36
+ * already focusable, is left as it is. Called at mount, on the client.
37
+ */
38
+ // #427: a **Keyboard press**.
39
+ export const makeFocusable = (target: unknown): void => {
40
+ // Per pressable element at mount (#709): statements.
41
+ if (isHtmlElement(target)) {
42
+ if (takesFocus(target)) return
43
+ target.tabIndex = 0
44
+ }
45
+ }
@@ -20,7 +20,7 @@ import { constVoid } from "effect/Function"
20
20
  import * as Option from "effect/Option"
21
21
  import * as Predicate from "effect/Predicate"
22
22
  import * as Str from "effect/String"
23
- import { pending as appearRuns } from "./appear.ts"
23
+ import { pending as appearRuns } from "./appear-slot.ts"
24
24
 
25
25
  /**
26
26
  * The document timeline's time, in ms. Inside a Refresh frame (its rAF callbacks, their microtasks,
@@ -120,7 +120,7 @@ import {
120
120
  } from "./measure.ts"
121
121
  import { DEFAULT_DRAG_TRANSITION, DEFAULT_LAYOUT_TRANSITION, type DragTransition, type LayoutTransition } from "./projection-defaults.ts"
122
122
  import { counted, watchPage, type Watched } from "./content-watch.ts"
123
- import { pending as appearRuns } from "./appear.ts"
123
+ import { pending as appearRuns } from "./appear-slot.ts"
124
124
  import { debugOf, reportFailure } from "./report.ts"
125
125
  import { blendRadius, borderRadiusCorrector, isUnitScale, SCALE_CORRECTORS, type ScaleCorrector, type ScaleCorrectorEntry, scaleRadius, ZERO_RADIUS } from "./scale-correction.ts"
126
126
  import { dashCase } from "./svg.ts"
@@ -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