foldkit-primitives 0.9.0 → 0.10.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 (59) hide show
  1. package/README.md +31 -1
  2. package/dist/device/index.d.mts +69 -36
  3. package/dist/device/index.d.mts.map +1 -1
  4. package/dist/device/index.mjs +34 -34
  5. package/dist/device/index.mjs.map +1 -1
  6. package/dist/dom/index.d.mts +68 -19
  7. package/dist/dom/index.d.mts.map +1 -1
  8. package/dist/dom/index.mjs +32 -25
  9. package/dist/dom/index.mjs.map +1 -1
  10. package/dist/{editable-text-BbsPOATY.d.mts → editable-text-Dvm-Fuqs.d.mts} +65 -3
  11. package/dist/editable-text-Dvm-Fuqs.d.mts.map +1 -0
  12. package/dist/events/index.d.mts +52 -31
  13. package/dist/events/index.d.mts.map +1 -1
  14. package/dist/events/index.mjs +40 -28
  15. package/dist/events/index.mjs.map +1 -1
  16. package/dist/{follow-tab-stop-BDxyoUPQ.mjs → follow-tab-stop-Ci1tqAIW.mjs} +63 -61
  17. package/dist/follow-tab-stop-Ci1tqAIW.mjs.map +1 -0
  18. package/dist/{index-Cppf-lBx.d.mts → index-CmmxqSEi.d.mts} +34 -15
  19. package/dist/index-CmmxqSEi.d.mts.map +1 -0
  20. package/dist/index.d.mts +3 -3
  21. package/dist/index.mjs +3 -3
  22. package/dist/{input-modality-m6v7__Xs.mjs → input-modality-BXD383jg.mjs} +9 -9
  23. package/dist/input-modality-BXD383jg.mjs.map +1 -0
  24. package/dist/{input-modality-DGOhAknO.d.mts → input-modality-BY-bSrEc.d.mts} +9 -2
  25. package/dist/input-modality-BY-bSrEc.d.mts.map +1 -0
  26. package/dist/interaction/index.d.mts +118 -118
  27. package/dist/interaction/index.d.mts.map +1 -1
  28. package/dist/interaction/index.mjs +3 -3
  29. package/dist/interaction/index.mjs.map +1 -1
  30. package/dist/media/index.d.mts +24 -3
  31. package/dist/media/index.d.mts.map +1 -1
  32. package/dist/media/index.mjs +23 -13
  33. package/dist/media/index.mjs.map +1 -1
  34. package/dist/motion/index.d.mts +1 -1
  35. package/dist/motion/index.mjs +1 -2
  36. package/dist/{motion-DGGBZ0wt.mjs → motion-DmFDppRn.mjs} +20 -20
  37. package/dist/{motion-DGGBZ0wt.mjs.map → motion-DmFDppRn.mjs.map} +1 -1
  38. package/dist/net/index.d.mts +63 -25
  39. package/dist/net/index.d.mts.map +1 -1
  40. package/dist/net/index.mjs +31 -31
  41. package/dist/net/index.mjs.map +1 -1
  42. package/dist/observers/index.d.mts +25 -0
  43. package/dist/observers/index.d.mts.map +1 -1
  44. package/dist/observers/index.mjs +22 -22
  45. package/dist/observers/index.mjs.map +1 -1
  46. package/dist/state/index.d.mts +98 -44
  47. package/dist/state/index.d.mts.map +1 -1
  48. package/dist/state/index.mjs +39 -39
  49. package/dist/state/index.mjs.map +1 -1
  50. package/dist/time/index.d.mts +35 -5
  51. package/dist/time/index.d.mts.map +1 -1
  52. package/dist/time/index.mjs +20 -20
  53. package/dist/time/index.mjs.map +1 -1
  54. package/package.json +14 -14
  55. package/dist/editable-text-BbsPOATY.d.mts.map +0 -1
  56. package/dist/follow-tab-stop-BDxyoUPQ.mjs.map +0 -1
  57. package/dist/index-Cppf-lBx.d.mts.map +0 -1
  58. package/dist/input-modality-DGOhAknO.d.mts.map +0 -1
  59. package/dist/input-modality-m6v7__Xs.mjs.map +0 -1
@@ -2,13 +2,6 @@ import { Effect, Queue, Schema, Stream } from "effect";
2
2
  import * as Mount from "foldkit/mount";
3
3
  import * as Dom from "foldkit/dom";
4
4
  //#region src/dom/focus-scope.ts
5
- /**
6
- * A focus scope as a Mount: on insert it remembers what was focused, focuses
7
- * an initial element inside, and with `contain` keeps Tab and Shift+Tab
8
- * cycling inside; on unmount it gives focus back. Nothing crosses to the
9
- * Model: which element had focus is a DOM fact, so this is element lifecycle,
10
- * not state. It emits no Messages.
11
- */
12
5
  const FOCUSABLE = [
13
6
  "a[href]",
14
7
  "button:not([disabled])",
@@ -30,6 +23,13 @@ const focusFirst = (elements) => {
30
23
  first.focus();
31
24
  return true;
32
25
  };
26
+ /**
27
+ * A focus scope as a Mount: on insert it remembers what was focused, focuses
28
+ * an initial element inside, and with `contain` keeps Tab and Shift+Tab
29
+ * cycling inside; on unmount it gives focus back. Nothing crosses to the
30
+ * Model: which element had focus is a DOM fact, so this is element lifecycle,
31
+ * not state. It emits no Messages.
32
+ */
33
33
  const FocusScope = Mount.defineStream("FocusScope", {
34
34
  messages: [Schema.Never],
35
35
  args: {
@@ -102,12 +102,14 @@ const FocusScope = Mount.defineStream("FocusScope", {
102
102
  *
103
103
  * Both emit no Messages; they are element lifecycle.
104
104
  */
105
+ /** Locks the document's scroll while the element is mounted; nested locks release with the last. */
105
106
  const ScrollLock = Mount.defineStream("ScrollLock", {
106
107
  messages: [Schema.Never],
107
108
  execute: () => Stream.callback(() => Effect.acquireRelease(Dom.lockScroll, () => Dom.unlockScroll))
108
109
  });
109
110
  const HIDE_OUTSIDE_ATTRIBUTE = "data-foldkit-plus-hide-outside";
110
111
  let minted = 0;
112
+ /** Makes everything outside the element inert while it is mounted, and restores it after. */
111
113
  const HideOutside = Mount.defineStream("HideOutside", {
112
114
  messages: [Schema.Never],
113
115
  execute: ({ element }) => Stream.callback(() => Effect.acquireRelease(Effect.gen(function* () {
@@ -119,13 +121,6 @@ const HideOutside = Mount.defineStream("HideOutside", {
119
121
  });
120
122
  //#endregion
121
123
  //#region src/dom/move.ts
122
- /**
123
- * Pointer movement on an element as a Mount: a primary-button pointer down
124
- * captures the pointer, each move reports the delta from where it started,
125
- * and up, cancel, or lost capture ends it. Nothing is decided here: a drag
126
- * threshold, a snap, or a constraint is the parent's `update`. Capture is
127
- * released with the Mount.
128
- */
129
124
  const MoveStarted = Schema.TaggedStruct("MoveStarted", {
130
125
  pointerId: Schema.Number,
131
126
  pointerType: Schema.String
@@ -142,6 +137,13 @@ const MoveEnded = Schema.TaggedStruct("MoveEnded", {
142
137
  /** `false` when the pointer was cancelled or capture was lost. */
143
138
  completed: Schema.Boolean
144
139
  });
140
+ /**
141
+ * Pointer movement on an element as a Mount: a primary-button pointer down
142
+ * captures the pointer, each move reports the delta from where it started,
143
+ * and up, cancel, or lost capture ends it. Nothing is decided here: a drag
144
+ * threshold, a snap, or a constraint is the parent's `update`. Capture is
145
+ * released with the Mount.
146
+ */
145
147
  const Move = Mount.defineStream("Move", {
146
148
  messages: [
147
149
  MoveStarted,
@@ -211,16 +213,6 @@ const Move = Mount.defineStream("Move", {
211
213
  });
212
214
  //#endregion
213
215
  //#region src/dom/targets.ts
214
- /**
215
- * Which marked descendant of an element the pointer is over, and which one was
216
- * pressed, as a Mount: one set of listeners on the container, not one per item.
217
- * A descendant is marked by an attribute whose value is its id, such as a
218
- * canvas's `data-composition-node` or a table's `data-row`. The nearest marked
219
- * ancestor of the event's target, inside the container, is the one reported.
220
- *
221
- * What hovering or pressing means (a selection, an outline, a menu) is the
222
- * parent's `update`.
223
- */
224
216
  const TargetHovered = Schema.TaggedStruct("TargetHovered", {
225
217
  /** The marked descendant under the pointer, or `null` when there is none. */
226
218
  id: Schema.NullOr(Schema.String) });
@@ -237,6 +229,16 @@ const targetOf = (container, from, attribute) => {
237
229
  const marked = from.closest(`[${attribute}]`);
238
230
  return marked !== null && container.contains(marked) ? marked.getAttribute(attribute) : null;
239
231
  };
232
+ /**
233
+ * Which marked descendant of an element the pointer is over, and which one was
234
+ * pressed, as a Mount: one set of listeners on the container, not one per item.
235
+ * A descendant is marked by an attribute whose value is its id, such as a
236
+ * canvas's `data-composition-node` or a table's `data-row`. The nearest marked
237
+ * ancestor of the event's target, inside the container, is the one reported.
238
+ *
239
+ * What hovering or pressing means (a selection, an outline, a menu) is the
240
+ * parent's `update`.
241
+ */
240
242
  const Targets = Mount.defineStream("Targets", {
241
243
  messages: [TargetHovered, TargetPressed],
242
244
  args: {
@@ -277,20 +279,6 @@ const Targets = Mount.defineStream("Targets", {
277
279
  });
278
280
  //#endregion
279
281
  //#region src/dom/pointer-drag.ts
280
- /**
281
- * Dragging one marked descendant of an element onto another, as a Mount. A
282
- * descendant is marked by an attribute whose value is its id, as `Targets`
283
- * marks them; a press on one that then moves past a threshold starts a drag,
284
- * and the pointer's place over another marked descendant is reported with the
285
- * zone of it the pointer is in: its first third (`before`), its middle
286
- * (`inside`), or its last third (`after`). Releasing drops, and Escape or a
287
- * cancelled pointer ends the drag with nothing dropped.
288
- *
289
- * It writes no roles, no `tabindex` and no key handling, so the marked
290
- * elements can be anything: a tree's rows, a canvas's nodes. The keyboard's way
291
- * to do what a drag does is the parent's to give. Geometry is measured when the
292
- * pointer moves and never kept; what a drop means is the parent's `update`.
293
- */
294
282
  const DragZone = Schema.Literals([
295
283
  "before",
296
284
  "inside",
@@ -344,6 +332,20 @@ const boxOf = (element) => {
344
332
  const child = element.firstElementChild;
345
333
  return child === null ? own : boxOf(child);
346
334
  };
335
+ /**
336
+ * Dragging one marked descendant of an element onto another, as a Mount. A
337
+ * descendant is marked by an attribute whose value is its id, as `Targets`
338
+ * marks them; a press on one that then moves past a threshold starts a drag,
339
+ * and the pointer's place over another marked descendant is reported with the
340
+ * zone of it the pointer is in: its first third (`before`), its middle
341
+ * (`inside`), or its last third (`after`). Releasing drops, and Escape or a
342
+ * cancelled pointer ends the drag with nothing dropped.
343
+ *
344
+ * It writes no roles, no `tabindex` and no key handling, so the marked
345
+ * elements can be anything: a tree's rows, a canvas's nodes. The keyboard's way
346
+ * to do what a drag does is the parent's to give. Geometry is measured when the
347
+ * pointer moves and never kept; what a drop means is the parent's `update`.
348
+ */
347
349
  const PointerDrag = Mount.defineStream("PointerDrag", {
348
350
  messages: [
349
351
  DragStarted,
@@ -538,28 +540,6 @@ const PointerDrag = Mount.defineStream("PointerDrag", {
538
540
  });
539
541
  //#endregion
540
542
  //#region src/dom/editable-text.ts
541
- /**
542
- * Text typed into an editable descendant of an element, as a Mount: one set of
543
- * listeners on the container, like `Targets`. A field is a descendant marked
544
- * by an attribute whose value names it, while it is `contenteditable`. The
545
- * view decides which one is; the Mount focuses it as it becomes so (made
546
- * editable, or drawn editable), with the caret at its end, and at no other
547
- * time. When Enter or Escape ends an edit and the view then removes the field
548
- * or makes it no longer editable, focus, left on nothing, comes back to the
549
- * container, so the next key reaches it; give the container a `tabindex`. A double-click on a marked field that is not editable yet asks for it
550
- * to be (`EditAsked`).
551
- *
552
- * It reads `innerText`, never `innerHTML`, so what arrives is text. A field is
553
- * one line unless it carries `aria-multiline="true"`: in one line, a line
554
- * break becomes a space. Nothing is reported while an input method composes;
555
- * the composed text arrives once, when it is done.
556
- *
557
- * Enter commits (Shift+Enter breaks a line in a multiline field), and so does
558
- * leaving the field. Escape cancels, and puts the text the field had when
559
- * editing began back in the DOM, since a view that stopped redrawing the field
560
- * while it was edited will not. Where the browser lacks `plaintext-only`, a
561
- * paste is inserted as text. What an edit means is the parent's `update`.
562
- */
563
543
  const TextEdited = Schema.TaggedStruct("TextEdited", {
564
544
  /** The field, by its marking attribute's value. */
565
545
  field: Schema.String,
@@ -599,6 +579,28 @@ const caretAtEnd = (field) => {
599
579
  };
600
580
  /** Whether a key press belongs to an input method still composing, not to the field. */
601
581
  const composing = (event) => event.isComposing || event.keyCode === 229;
582
+ /**
583
+ * Text typed into an editable descendant of an element, as a Mount: one set of
584
+ * listeners on the container, like `Targets`. A field is a descendant marked
585
+ * by an attribute whose value names it, while it is `contenteditable`. The
586
+ * view decides which one is; the Mount focuses it as it becomes so (made
587
+ * editable, or drawn editable), with the caret at its end, and at no other
588
+ * time. When Enter or Escape ends an edit and the view then removes the field
589
+ * or makes it no longer editable, focus, left on nothing, comes back to the
590
+ * container, so the next key reaches it; give the container a `tabindex`. A double-click on a marked field that is not editable yet asks for it
591
+ * to be (`EditAsked`).
592
+ *
593
+ * It reads `innerText`, never `innerHTML`, so what arrives is text. A field is
594
+ * one line unless it carries `aria-multiline="true"`: in one line, a line
595
+ * break becomes a space. Nothing is reported while an input method composes;
596
+ * the composed text arrives once, when it is done.
597
+ *
598
+ * Enter commits (Shift+Enter breaks a line in a multiline field), and so does
599
+ * leaving the field. Escape cancels, and puts the text the field had when
600
+ * editing began back in the DOM, since a view that stopped redrawing the field
601
+ * while it was edited will not. Where the browser lacks `plaintext-only`, a
602
+ * paste is inserted as text. What an edit means is the parent's `update`.
603
+ */
602
604
  const EditableText = Mount.defineStream("EditableText", {
603
605
  messages: [
604
606
  TextEdited,
@@ -817,4 +819,4 @@ const FollowTabStop = Mount.defineStream("FollowTabStop", {
817
819
  //#endregion
818
820
  export { MoveEnded as C, ScrollLock as D, HideOutside as E, FocusScope as O, Move as S, Moved as T, zoneOf as _, TextCommitted as a, Targets as b, DRAG_THRESHOLD as c, DragPlace as d, DragStarted as f, boxOf as g, PointerDrag as h, TextCancelled as i, tabbableWithin as k, DragCancelled as l, DraggedOver as m, EditAsked as n, TextEdited as o, DragZone as p, EditableText as r, textOf as s, FollowTabStop as t, DragDropped as u, TargetHovered as v, MoveStarted as w, targetOf as x, TargetPressed as y };
819
821
 
820
- //# sourceMappingURL=follow-tab-stop-BDxyoUPQ.mjs.map
822
+ //# sourceMappingURL=follow-tab-stop-Ci1tqAIW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"follow-tab-stop-Ci1tqAIW.mjs","names":[],"sources":["../src/dom/focus-scope.ts","../src/dom/layers.ts","../src/dom/move.ts","../src/dom/targets.ts","../src/dom/pointer-drag.ts","../src/dom/editable-text.ts","../src/dom/follow-tab-stop.ts"],"sourcesContent":["import { Effect, Schema, Stream } from 'effect'\nimport * as Mount from 'foldkit/mount'\n\nconst FOCUSABLE = [\n 'a[href]',\n 'button:not([disabled])',\n 'input:not([disabled]):not([type=\"hidden\"])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n '[tabindex]',\n '[contenteditable=\"true\"]',\n].join(', ')\n\nconst isVisible = (element: Element): boolean => {\n const probe = element as { checkVisibility?: () => boolean }\n return element.closest('[hidden], [inert]') === null && (probe.checkVisibility?.() ?? true)\n}\n\n/** Tabbable descendants in DOM order: focusable, visible, and not `tabindex=\"-1\"`. */\nexport const tabbableWithin = (root: Element): ReadonlyArray<HTMLElement> =>\n Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(\n element => element.tabIndex >= 0 && isVisible(element),\n )\n\nconst focusFirst = (elements: ReadonlyArray<HTMLElement>): boolean => {\n const first = elements[0]\n if (first === undefined) return false\n first.focus()\n return true\n}\n\n/**\n * A focus scope as a Mount: on insert it remembers what was focused, focuses\n * an initial element inside, and with `contain` keeps Tab and Shift+Tab\n * cycling inside; on unmount it gives focus back. Nothing crosses to the\n * Model: which element had focus is a DOM fact, so this is element lifecycle,\n * not state. It emits no Messages.\n */\nexport const FocusScope = Mount.defineStream('FocusScope', {\n messages: [Schema.Never],\n args: {\n /** Keep Tab, Shift+Tab, and a stray focus inside. */\n contain: Schema.Boolean,\n /** Give focus back to what had it, on unmount. */\n restore: Schema.Boolean,\n /** A selector inside the element to focus first; else the first tabbable\n * descendant, else the element itself when it is focusable. */\n initialFocus: Schema.NullOr(Schema.String),\n },\n execute: ({ element, contain, restore, initialFocus }) =>\n Stream.callback<never>(() =>\n Effect.acquireRelease(\n Effect.sync(() => {\n const ownerDocument = element.ownerDocument\n const previous = ownerDocument.activeElement\n const initial =\n initialFocus === null ? null : element.querySelector<HTMLElement>(initialFocus)\n if (initial !== null) initial.focus()\n else if (!focusFirst(tabbableWithin(element)) && element instanceof HTMLElement) {\n element.focus()\n }\n const onKeyDown = (event: Event) => {\n const key = event as KeyboardEvent\n if (key.key !== 'Tab') return\n const tabbable = tabbableWithin(element)\n const first = tabbable[0]\n const last = tabbable[tabbable.length - 1]\n if (first === undefined || last === undefined) {\n key.preventDefault()\n return\n }\n const active = ownerDocument.activeElement\n if (key.shiftKey && (active === first || !element.contains(active))) {\n key.preventDefault()\n last.focus()\n } else if (!key.shiftKey && (active === last || !element.contains(active))) {\n key.preventDefault()\n first.focus()\n }\n }\n const onFocusIn = (event: Event) => {\n const target = event.target\n if (target instanceof Node && element.contains(target)) return\n focusFirst(tabbableWithin(element))\n }\n if (contain) {\n element.addEventListener('keydown', onKeyDown)\n ownerDocument.addEventListener('focusin', onFocusIn)\n }\n return { previous, onKeyDown, onFocusIn, ownerDocument }\n }),\n ({ previous, onKeyDown, onFocusIn, ownerDocument }) =>\n Effect.sync(() => {\n if (contain) {\n element.removeEventListener('keydown', onKeyDown)\n ownerDocument.removeEventListener('focusin', onFocusIn)\n }\n if (restore && previous instanceof HTMLElement && ownerDocument.contains(previous)) {\n previous.focus()\n }\n }),\n ),\n ),\n})\n","/**\n * Two Mounts over Foldkit's own DOM helpers, for an overlay that is not a\n * native `<dialog>` or `popover`:\n *\n * - `ScrollLock` locks the document's scroll while mounted. Foldkit's lock is\n * refcounted, so nested overlays release it only when the last one goes.\n * - `HideOutside` marks everything outside the element inert while mounted,\n * through `Dom.inertOthers`, keyed by an id this Mount mints.\n *\n * Both emit no Messages; they are element lifecycle.\n */\nimport { Effect, Schema, Stream } from 'effect'\nimport * as Dom from 'foldkit/dom'\nimport * as Mount from 'foldkit/mount'\n\n/** Locks the document's scroll while the element is mounted; nested locks release with the last. */\nexport const ScrollLock = Mount.defineStream('ScrollLock', {\n messages: [Schema.Never],\n execute: () =>\n Stream.callback<never>(() => Effect.acquireRelease(Dom.lockScroll, () => Dom.unlockScroll)),\n})\n\nconst HIDE_OUTSIDE_ATTRIBUTE = 'data-foldkit-plus-hide-outside'\n\nlet minted = 0\n\n/** Makes everything outside the element inert while it is mounted, and restores it after. */\nexport const HideOutside = Mount.defineStream('HideOutside', {\n messages: [Schema.Never],\n execute: ({ element }) =>\n Stream.callback<never>(() =>\n Effect.acquireRelease(\n Effect.gen(function* () {\n // A per-mount id: Foldkit keys the inert set by it, so two overlays\n // restore independently. The attribute is how the element is found.\n const id = `hide-outside-${(minted += 1)}`\n element.setAttribute(HIDE_OUTSIDE_ATTRIBUTE, id)\n yield* Dom.inertOthers(id, [`[${HIDE_OUTSIDE_ATTRIBUTE}=\"${id}\"]`])\n return id\n }),\n id =>\n Effect.andThen(Dom.restoreInert(id), () =>\n Effect.sync(() => element.removeAttribute(HIDE_OUTSIDE_ATTRIBUTE)),\n ),\n ),\n ),\n})\n","import { Effect, Queue, Schema, Stream } from 'effect'\nimport * as Mount from 'foldkit/mount'\n\nexport const MoveStarted = Schema.TaggedStruct('MoveStarted', {\n pointerId: Schema.Number,\n pointerType: Schema.String,\n})\nexport type MoveStarted = typeof MoveStarted.Type\n\nexport const Moved = Schema.TaggedStruct('Moved', {\n pointerId: Schema.Number,\n /** From where the pointer went down, in CSS pixels. */\n deltaX: Schema.Number,\n deltaY: Schema.Number,\n pointerType: Schema.String,\n})\nexport type Moved = typeof Moved.Type\n\nexport const MoveEnded = Schema.TaggedStruct('MoveEnded', {\n pointerId: Schema.Number,\n /** `false` when the pointer was cancelled or capture was lost. */\n completed: Schema.Boolean,\n})\nexport type MoveEnded = typeof MoveEnded.Type\n\nexport type Fact = MoveStarted | Moved | MoveEnded\n\ntype PointerLike = Event & {\n readonly pointerId?: number\n readonly button?: number\n readonly pointerType?: string\n readonly clientX?: number\n readonly clientY?: number\n}\n\ntype Capturing = Element & {\n setPointerCapture?: (pointerId: number) => void\n releasePointerCapture?: (pointerId: number) => void\n}\n\n/**\n * Pointer movement on an element as a Mount: a primary-button pointer down\n * captures the pointer, each move reports the delta from where it started,\n * and up, cancel, or lost capture ends it. Nothing is decided here: a drag\n * threshold, a snap, or a constraint is the parent's `update`. Capture is\n * released with the Mount.\n */\nexport const Move = Mount.defineStream('Move', {\n messages: [MoveStarted, Moved, MoveEnded],\n execute: ({ element }) =>\n Stream.callback<Fact>(queue =>\n Effect.acquireRelease(\n Effect.sync(() => {\n const target = element as Capturing\n let active: {\n readonly pointerId: number\n readonly x: number\n readonly y: number\n } | null = null\n const offer = (fact: Fact) => Queue.offerUnsafe(queue, fact)\n const end = (pointerId: number, completed: boolean) => {\n if (active === null || active.pointerId !== pointerId) return\n active = null\n try {\n target.releasePointerCapture?.(pointerId)\n } catch {\n // Capture may already be gone; the end is still reported.\n }\n offer(MoveEnded.make({ pointerId, completed }))\n }\n const listeners: ReadonlyArray<readonly [string, (event: Event) => void]> = [\n [\n 'pointerdown',\n event => {\n const pointer = event as PointerLike\n if ((pointer.button ?? 0) !== 0 || active !== null) return\n const pointerId = pointer.pointerId ?? 0\n active = { pointerId, x: pointer.clientX ?? 0, y: pointer.clientY ?? 0 }\n try {\n target.setPointerCapture?.(pointerId)\n } catch {\n // Without capture the move still reports while over the element.\n }\n offer(MoveStarted.make({ pointerId, pointerType: pointer.pointerType ?? 'mouse' }))\n },\n ],\n [\n 'pointermove',\n event => {\n const pointer = event as PointerLike\n const pointerId = pointer.pointerId ?? 0\n if (active === null || active.pointerId !== pointerId) return\n offer(\n Moved.make({\n pointerId,\n deltaX: (pointer.clientX ?? 0) - active.x,\n deltaY: (pointer.clientY ?? 0) - active.y,\n pointerType: pointer.pointerType ?? 'mouse',\n }),\n )\n },\n ],\n ['pointerup', event => end((event as PointerLike).pointerId ?? 0, true)],\n ['pointercancel', event => end((event as PointerLike).pointerId ?? 0, false)],\n ['lostpointercapture', event => end((event as PointerLike).pointerId ?? 0, false)],\n ]\n for (const [type, listener] of listeners) element.addEventListener(type, listener)\n return { listeners, current: () => active }\n }),\n ({ listeners, current }) =>\n Effect.sync(() => {\n for (const [type, listener] of listeners) element.removeEventListener(type, listener)\n const pointer = current()\n if (pointer !== null) {\n try {\n ;(element as Capturing).releasePointerCapture?.(pointer.pointerId)\n } catch {\n // Already released.\n }\n }\n }),\n ),\n ),\n})\n","import { Effect, Queue, Schema, Stream } from 'effect'\nimport * as Mount from 'foldkit/mount'\n\nexport const TargetHovered = Schema.TaggedStruct('TargetHovered', {\n /** The marked descendant under the pointer, or `null` when there is none. */\n id: Schema.NullOr(Schema.String),\n})\nexport type TargetHovered = typeof TargetHovered.Type\n\nexport const TargetPressed = Schema.TaggedStruct('TargetPressed', {\n id: Schema.String,\n shiftKey: Schema.Boolean,\n altKey: Schema.Boolean,\n ctrlKey: Schema.Boolean,\n metaKey: Schema.Boolean,\n})\nexport type TargetPressed = typeof TargetPressed.Type\n\nexport type TargetFact = TargetHovered | TargetPressed\n\ntype Modified = Event & {\n readonly shiftKey?: boolean\n readonly altKey?: boolean\n readonly ctrlKey?: boolean\n readonly metaKey?: boolean\n}\n\n/** The id of the nearest marked element at or above `from`, inside `container`. */\nexport const targetOf = (container: Element, from: EventTarget | null, attribute: string) => {\n if (!(from instanceof Element)) return null\n const marked = from.closest(`[${attribute}]`)\n return marked !== null && container.contains(marked) ? marked.getAttribute(attribute) : null\n}\n\n/**\n * Which marked descendant of an element the pointer is over, and which one was\n * pressed, as a Mount: one set of listeners on the container, not one per item.\n * A descendant is marked by an attribute whose value is its id, such as a\n * canvas's `data-composition-node` or a table's `data-row`. The nearest marked\n * ancestor of the event's target, inside the container, is the one reported.\n *\n * What hovering or pressing means (a selection, an outline, a menu) is the\n * parent's `update`.\n */\nexport const Targets = Mount.defineStream('Targets', {\n messages: [TargetHovered, TargetPressed],\n args: {\n /** The attribute that marks a descendant, holding its id. */\n attribute: Schema.String,\n /** Prevent a press's default, such as a link navigating inside an editor's canvas. */\n preventDefault: Schema.Boolean,\n },\n execute: ({ element, attribute, preventDefault }) =>\n Stream.callback<TargetFact>(queue =>\n Effect.acquireRelease(\n Effect.sync(() => {\n let hovered: string | null = null\n const hover = (id: string | null) => {\n if (id === hovered) return\n hovered = id\n Queue.offerUnsafe(queue, TargetHovered.make({ id }))\n }\n const listeners: ReadonlyArray<readonly [string, (event: Event) => void]> = [\n ['pointerover', event => hover(targetOf(element, event.target, attribute))],\n ['pointerleave', () => hover(null)],\n [\n 'click',\n event => {\n const id = targetOf(element, event.target, attribute)\n if (id === null) return\n if (preventDefault) event.preventDefault()\n const modified = event as Modified\n Queue.offerUnsafe(\n queue,\n TargetPressed.make({\n id,\n shiftKey: modified.shiftKey === true,\n altKey: modified.altKey === true,\n ctrlKey: modified.ctrlKey === true,\n metaKey: modified.metaKey === true,\n }),\n )\n },\n ],\n ]\n for (const [type, listener] of listeners) element.addEventListener(type, listener)\n return listeners\n }),\n listeners =>\n Effect.sync(() => {\n for (const [type, listener] of listeners) element.removeEventListener(type, listener)\n }),\n ),\n ),\n})\n","import { Effect, Queue, Schema, Stream } from 'effect'\nimport * as Mount from 'foldkit/mount'\nimport { targetOf } from './targets.js'\n\nexport const DragZone = Schema.Literals(['before', 'inside', 'after'])\nexport type DragZone = typeof DragZone.Type\n\n/**\n * A marked descendant under the pointer, and the zone of it the pointer is in.\n * `part` is the value of the `part` attribute on the element found, such as\n * the empty Region of a node a drop goes into; a place with one is `inside`.\n */\nexport const DragPlace = Schema.Struct({\n id: Schema.String,\n zone: DragZone,\n part: Schema.optionalKey(Schema.String),\n})\nexport type DragPlace = typeof DragPlace.Type\n\nexport const DragStarted = Schema.TaggedStruct('DragStarted', {\n /** The marked descendant being dragged. */\n id: Schema.String,\n})\nexport type DragStarted = typeof DragStarted.Type\n\nexport const DraggedOver = Schema.TaggedStruct('DraggedOver', {\n /** Where the pointer is, or `null` over nothing marked, or over what is dragged. */\n over: Schema.NullOr(DragPlace),\n /**\n * For a drag onto `targets`: whether the pointer is inside the region they\n * are in, so `over: null` with `region: true` is its empty space (an empty\n * page, the space below the last node). Absent for a drag among its own.\n */\n region: Schema.optionalKey(Schema.Boolean),\n})\nexport type DraggedOver = typeof DraggedOver.Type\n\nexport const DragDropped = Schema.TaggedStruct('DragDropped', {\n id: Schema.String,\n over: Schema.NullOr(DragPlace),\n /** As `DraggedOver`'s: released inside the `targets` region. */\n region: Schema.optionalKey(Schema.Boolean),\n})\nexport type DragDropped = typeof DragDropped.Type\n\nexport const DragCancelled = Schema.TaggedStruct('DragCancelled', { id: Schema.String })\nexport type DragCancelled = typeof DragCancelled.Type\n\nexport type DragFact = DragStarted | DraggedOver | DragDropped | DragCancelled\n\n/** How far, in CSS pixels, a press moves before it is a drag rather than a click. */\nexport const DRAG_THRESHOLD = 4\n\ninterface Box {\n readonly top: number\n readonly height: number\n}\n\n/** The zone of a box a vertical position falls in, by thirds. */\nexport const zoneOf = (box: Box, y: number): DragZone => {\n if (box.height <= 0) return 'inside'\n const at = (y - box.top) / box.height\n return at < 1 / 3 ? 'before' : at > 2 / 3 ? 'after' : 'inside'\n}\n\n/**\n * An element's box. An element drawn as `display: contents` has none, so its\n * first child's stands for it, as an editor's node wrapper's does.\n */\nexport const boxOf = (element: Element): Box => {\n const own = element.getBoundingClientRect()\n if (own.width > 0 || own.height > 0) return own\n const child = element.firstElementChild\n return child === null ? own : boxOf(child)\n}\n\ntype Positioned = Event & {\n readonly clientX?: number\n readonly clientY?: number\n readonly button?: number\n readonly buttons?: number\n readonly pointerId?: number\n readonly key?: string\n}\n\n/**\n * Dragging one marked descendant of an element onto another, as a Mount. A\n * descendant is marked by an attribute whose value is its id, as `Targets`\n * marks them; a press on one that then moves past a threshold starts a drag,\n * and the pointer's place over another marked descendant is reported with the\n * zone of it the pointer is in: its first third (`before`), its middle\n * (`inside`), or its last third (`after`). Releasing drops, and Escape or a\n * cancelled pointer ends the drag with nothing dropped.\n *\n * It writes no roles, no `tabindex` and no key handling, so the marked\n * elements can be anything: a tree's rows, a canvas's nodes. The keyboard's way\n * to do what a drag does is the parent's to give. Geometry is measured when the\n * pointer moves and never kept; what a drop means is the parent's `update`.\n */\nexport const PointerDrag = Mount.defineStream('PointerDrag', {\n messages: [DragStarted, DraggedOver, DragDropped, DragCancelled],\n args: {\n /** The attribute that marks a descendant, holding its id. */\n attribute: Schema.String,\n /**\n * Where a drag may land, when not on the element's own marked descendants:\n * the elements marked by `attribute` inside the one `within` selects, such\n * as a palette's Blocks dragged onto a page. A drop's `over` is then one of\n * those; what is dragged is still one of the element's own. `within` is\n * looked for nearest first, under the element's closest ancestor that holds\n * a match, so two editors on one page each drop onto their own.\n */\n targets: Schema.optionalKey(Schema.Struct({ attribute: Schema.String, within: Schema.String })),\n /**\n * An attribute that names a part of what a drop lands on, on an element\n * also marked as one: a place over it carries the part and is `inside`.\n */\n part: Schema.optionalKey(Schema.String),\n },\n execute: ({ element, attribute, targets, part }) =>\n Stream.callback<DragFact>(queue =>\n Effect.acquireRelease(\n Effect.sync(() => {\n const owner = element.ownerDocument\n // What a drop lands on: the element's own marked descendants, or those of `targets`.\n const landsOn = targets?.attribute ?? attribute\n // Looked for at each move, so a redraw that replaced it is followed.\n const regionOf = (within: string): Element | null => {\n for (let at = element.parentElement; at !== null; at = at.parentElement) {\n const found = at.querySelector(within)\n if (found !== null) return found\n }\n return null\n }\n const find = (from: EventTarget | null) => {\n if (!(from instanceof Element)) return { marked: null, inRegion: false }\n const region = targets === undefined ? element : regionOf(targets.within)\n const marked = from.closest(`[${landsOn}]`)\n return {\n marked: marked !== null && region !== null && region.contains(marked) ? marked : null,\n // Only a drag onto `targets` tells its region's empty space from elsewhere.\n inRegion: targets !== undefined && region !== null && region.contains(from),\n }\n }\n // A press not yet a drag, or a drag under way: one pointer's, the first down.\n let pressed: {\n readonly id: string\n readonly pointer: number | undefined\n readonly x: number\n readonly y: number\n } | null = null\n let dragging: string | null = null\n let over: DragPlace | null = null\n let inRegion = false\n // The click that ends a drag is not a press on what it ends over.\n let swallowClick = false\n\n const placeAt = (event: Positioned) => {\n // Touch and pen capture the pointer to where it went down, so the\n // event's target is the dragged element: ask what is under it instead.\n const under =\n typeof owner.elementFromPoint === 'function' && event.clientX !== undefined\n ? owner.elementFromPoint(event.clientX, event.clientY ?? 0)\n : null\n const { marked, inRegion: region } = find(under ?? event.target)\n const id = marked?.getAttribute(landsOn) ?? null\n // Over itself is over nothing, where what is dragged is among what it lands on.\n const named = part === undefined ? null : (marked?.getAttribute(part) ?? null)\n const place: DragPlace | null =\n marked === null || id === null || (targets === undefined && id === dragging)\n ? null\n : named === null\n ? { id, zone: zoneOf(boxOf(marked), event.clientY ?? 0) }\n : { id, zone: 'inside', part: named }\n return { place, region }\n }\n /** The region flag a fact carries: only for a drag onto `targets`. */\n const withRegion = (region: boolean) => (targets === undefined ? {} : { region })\n const ours = (event: Positioned) =>\n pressed !== null &&\n (pressed.pointer === undefined || event.pointerId === pressed.pointer)\n // `inside`: the release was on the container, so its click will reach it.\n // The release is hit-tested again: the layout may have moved since\n // the last move (a scroll, a row that shifted), and the drop says\n // where the pointer was let go, not where it was last seen. A\n // release with no position of its own keeps the last move's answer.\n const end = (dropped: boolean, at?: Positioned, inside = false) => {\n const id = dragging\n if (id !== null && at?.clientX !== undefined && at.clientY !== undefined) {\n const { place, region } = placeAt(at)\n over = place\n inRegion = region\n }\n pressed = null\n dragging = null\n const last = over\n const lastRegion = inRegion\n over = null\n inRegion = false\n release()\n if (id === null) return\n swallowClick = dropped && inside\n Queue.offerUnsafe(\n queue,\n dropped\n ? DragDropped.make({ id, over: last, ...withRegion(lastRegion) })\n : DragCancelled.make({ id }),\n )\n }\n\n const onDocument: ReadonlyArray<readonly [string, (event: Event) => void]> = [\n [\n 'pointermove',\n event => {\n const positioned = event as Positioned\n if (!ours(positioned) || pressed === null) return\n // Released where no pointerup reached us, such as over a frame.\n if (positioned.buttons !== undefined && (positioned.buttons & 1) === 0)\n return end(false)\n if (dragging === null) {\n const moved = Math.hypot(\n (positioned.clientX ?? 0) - pressed.x,\n (positioned.clientY ?? 0) - pressed.y,\n )\n if (moved < DRAG_THRESHOLD) return\n dragging = pressed.id\n owner.getSelection()?.removeAllRanges()\n Queue.offerUnsafe(queue, DragStarted.make({ id: dragging }))\n }\n const { place, region } = placeAt(positioned)\n if (\n place?.id === over?.id &&\n place?.zone === over?.zone &&\n place?.part === over?.part &&\n region === inRegion\n )\n return\n over = place\n inRegion = region\n Queue.offerUnsafe(queue, DraggedOver.make({ over: place, ...withRegion(region) }))\n },\n ],\n [\n 'pointerup',\n event => {\n if (!ours(event as Positioned)) return\n if (dragging === null) end(false)\n else\n end(\n true,\n event as Positioned,\n event.target instanceof Node && element.contains(event.target),\n )\n },\n ],\n [\n 'pointercancel',\n event => {\n if (ours(event as Positioned)) end(false)\n },\n ],\n ]\n // Heard on the way down, and kept there: an Escape that ends a drag is the\n // drag's, not also the focused element's (a canvas that would deselect).\n const onEscape = (event: Event) => {\n if (pressed === null || (event as Positioned).key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n end(false)\n }\n // The document is listened to only while a press is under way.\n let listening = false\n const listen = () => {\n if (listening) return\n listening = true\n for (const [type, listener] of onDocument) owner.addEventListener(type, listener)\n owner.addEventListener('keydown', onEscape, true)\n }\n const release = () => {\n if (!listening) return\n listening = false\n for (const [type, listener] of onDocument) owner.removeEventListener(type, listener)\n owner.removeEventListener('keydown', onEscape, true)\n }\n\n const onElement: ReadonlyArray<readonly [string, (event: Event) => void, boolean]> = [\n [\n 'pointerdown',\n event => {\n const positioned = event as Positioned\n // Any press is past the drop a swallowed click was waiting for.\n swallowClick = false\n // A second pointer while one is down is not a new drag.\n if (pressed !== null) return\n if ((positioned.button ?? 0) !== 0) return\n // A press in text being edited selects text: it is no drag.\n if (\n event.target instanceof Element &&\n event.target.closest('[contenteditable]:not([contenteditable=\"false\"])') !== null\n )\n return\n const id = targetOf(element, event.target, attribute)\n if (id === null) return\n pressed = {\n id,\n pointer: positioned.pointerId,\n x: positioned.clientX ?? 0,\n y: positioned.clientY ?? 0,\n }\n listen()\n },\n false,\n ],\n [\n 'click',\n event => {\n if (!swallowClick) return\n swallowClick = false\n event.preventDefault()\n event.stopImmediatePropagation()\n },\n true,\n ],\n // A link or an image would start the browser's own drag instead.\n ['dragstart', event => event.preventDefault(), false],\n ]\n for (const [type, listener, capture] of onElement)\n element.addEventListener(type, listener, capture)\n return { onElement, release }\n }),\n ({ onElement, release }) =>\n Effect.sync(() => {\n for (const [type, listener, capture] of onElement)\n element.removeEventListener(type, listener, capture)\n release()\n }),\n ),\n ),\n})\n","import { Effect, Queue, Schema, Stream } from 'effect'\nimport * as Mount from 'foldkit/mount'\n\nexport const TextEdited = Schema.TaggedStruct('TextEdited', {\n /** The field, by its marking attribute's value. */\n field: Schema.String,\n text: Schema.String,\n})\nexport type TextEdited = typeof TextEdited.Type\n\nexport const TextCommitted = Schema.TaggedStruct('TextCommitted', {\n field: Schema.String,\n text: Schema.String,\n})\nexport type TextCommitted = typeof TextCommitted.Type\n\nexport const TextCancelled = Schema.TaggedStruct('TextCancelled', {\n field: Schema.String,\n /** The text the field had when editing began, which the DOM shows again. */\n initial: Schema.String,\n})\nexport type TextCancelled = typeof TextCancelled.Type\n\nexport const EditAsked = Schema.TaggedStruct('EditAsked', {\n /** A marked field, not editable yet, that was double-clicked. */\n field: Schema.String,\n})\nexport type EditAsked = typeof EditAsked.Type\n\nexport type TextFact = TextEdited | TextCommitted | TextCancelled | EditAsked\n\n/** Whether a field takes more than one line. */\nconst multiline = (element: HTMLElement) => element.getAttribute('aria-multiline') === 'true'\n\n/**\n * A field's text. A browser ends an edited element with a line break it adds\n * itself, which is not the author's; in one line, the author's breaks are spaces.\n */\nexport const textOf = (element: HTMLElement): string => {\n const text = element.innerText.replace(/\\r\\n?/g, '\\n').replace(/\\n$/, '')\n return multiline(element) ? text : text.replace(/\\n+/g, ' ')\n}\n\n/** Puts the caret at the end of a field, which focuses it too. */\nconst caretAtEnd = (field: HTMLElement) => {\n // Chromium also focuses on the selection below; no standard says a browser must.\n field.focus()\n const caret = document.createRange()\n caret.selectNodeContents(field)\n caret.collapse(false)\n const selection = window.getSelection()\n selection?.removeAllRanges()\n selection?.addRange(caret)\n}\n\n/** Whether a key press belongs to an input method still composing, not to the field. */\nconst composing = (event: KeyboardEvent) => event.isComposing || event.keyCode === 229\n\n/**\n * Text typed into an editable descendant of an element, as a Mount: one set of\n * listeners on the container, like `Targets`. A field is a descendant marked\n * by an attribute whose value names it, while it is `contenteditable`. The\n * view decides which one is; the Mount focuses it as it becomes so (made\n * editable, or drawn editable), with the caret at its end, and at no other\n * time. When Enter or Escape ends an edit and the view then removes the field\n * or makes it no longer editable, focus, left on nothing, comes back to the\n * container, so the next key reaches it; give the container a `tabindex`. A double-click on a marked field that is not editable yet asks for it\n * to be (`EditAsked`).\n *\n * It reads `innerText`, never `innerHTML`, so what arrives is text. A field is\n * one line unless it carries `aria-multiline=\"true\"`: in one line, a line\n * break becomes a space. Nothing is reported while an input method composes;\n * the composed text arrives once, when it is done.\n *\n * Enter commits (Shift+Enter breaks a line in a multiline field), and so does\n * leaving the field. Escape cancels, and puts the text the field had when\n * editing began back in the DOM, since a view that stopped redrawing the field\n * while it was edited will not. Where the browser lacks `plaintext-only`, a\n * paste is inserted as text. What an edit means is the parent's `update`.\n */\nexport const EditableText = Mount.defineStream('EditableText', {\n messages: [TextEdited, TextCommitted, TextCancelled, EditAsked],\n args: {\n /** The attribute that marks a field, holding its name. */\n attribute: Schema.String,\n },\n execute: ({ element, attribute }) =>\n Stream.callback<TextFact>(queue =>\n Effect.acquireRelease(\n Effect.sync(() => {\n /** The field being edited: its name, its text when editing began, and the last reported. */\n let current:\n | {\n readonly field: HTMLElement\n readonly name: string\n readonly initial: string\n reported: string\n ended: boolean\n }\n | undefined\n let composingText = false\n // A field whose edit a key ended: when it leaves with focus on nothing, focus\n // comes back to the container, where the keys that began the edit are.\n let ending: HTMLElement | undefined\n\n /** The marked field at or above an event's target, inside the container. */\n const markedOf = (target: EventTarget | null): HTMLElement | undefined => {\n if (!(target instanceof Element)) return undefined\n const field = target.closest(`[${attribute}]`)\n return field instanceof HTMLElement && element.contains(field) ? field : undefined\n }\n /** The same, while it is editable. */\n const fieldOf = (target: EventTarget | null): HTMLElement | undefined => {\n const field = markedOf(target)\n return field?.isContentEditable === true ? field : undefined\n }\n /** Begins an edit of `field`, unless one of it is under way: on focus, or typing. */\n const begin = (field: HTMLElement) => {\n if (current?.field === field && !current.ended) return current\n const text = textOf(field)\n current = {\n field,\n name: field.getAttribute(attribute) ?? '',\n initial: text,\n reported: text,\n ended: false,\n }\n return current\n }\n /**\n * The edit of `field`: the one under way or just ended, else one begun\n * now, for a field focused before these listeners came. An ended edit\n * reports nothing more, so the blur that follows a commit or a cancel\n * does not commit again.\n */\n const editOf = (field: HTMLElement) => (current?.field === field ? current : begin(field))\n const report = (field: HTMLElement) => {\n const edit = editOf(field)\n if (edit.ended) return\n const text = textOf(field)\n // A browser may follow a composition with an input of the same text.\n if (text === edit.reported) return\n edit.reported = text\n Queue.offerUnsafe(queue, TextEdited.make({ field: edit.name, text }))\n }\n const commit = (field: HTMLElement) => {\n const edit = editOf(field)\n if (edit.ended) return\n edit.ended = true\n Queue.offerUnsafe(queue, TextCommitted.make({ field: edit.name, text: textOf(field) }))\n }\n const cancel = (field: HTMLElement) => {\n const edit = editOf(field)\n if (edit.ended) return\n edit.ended = true\n field.innerText = edit.initial\n // Writing the text moved the caret to its start; typing on goes after it.\n caretAtEnd(field)\n Queue.offerUnsafe(\n queue,\n TextCancelled.make({ field: edit.name, initial: edit.initial }),\n )\n }\n\n const listeners: ReadonlyArray<readonly [string, (event: Event) => void]> = [\n [\n 'dblclick',\n event => {\n const field = markedOf(event.target)\n // In an editable field, a double-click selects a word.\n if (field === undefined || field.isContentEditable) return\n Queue.offerUnsafe(\n queue,\n EditAsked.make({ field: field.getAttribute(attribute) ?? '' }),\n )\n },\n ],\n [\n 'focusin',\n event => {\n // A composition that never ended, in a field left, holds no other field silent.\n composingText = false\n const field = fieldOf(event.target)\n if (field !== undefined) begin(field)\n },\n ],\n // Before the change: a field focused before these listeners came is begun here.\n [\n 'beforeinput',\n event => {\n const field = fieldOf(event.target)\n if (field !== undefined) begin(field)\n },\n ],\n ['compositionstart', () => (composingText = true)],\n [\n 'compositionend',\n event => {\n composingText = false\n const field = fieldOf(event.target)\n if (field !== undefined) report(field)\n },\n ],\n [\n 'input',\n event => {\n const field = fieldOf(event.target)\n if (field !== undefined && !composingText) report(field)\n },\n ],\n [\n 'keydown',\n event => {\n const field = fieldOf(event.target)\n const key = event as KeyboardEvent\n if (field === undefined || composing(key)) return\n if (key.key === 'Escape') {\n event.preventDefault()\n ending = field\n cancel(field)\n } else if (key.key === 'Enter' && !(key.shiftKey && multiline(field))) {\n event.preventDefault()\n ending = field\n commit(field)\n }\n },\n ],\n [\n 'focusout',\n event => {\n const field = fieldOf(event.target)\n if (field === undefined) return\n // Left while still there and editable, asked once the change that may have\n // taken it away is done: the author went elsewhere, and focus is theirs.\n queueMicrotask(() => {\n if (field === ending && field.isConnected && field.isContentEditable)\n ending = undefined\n })\n commit(field)\n },\n ],\n [\n 'paste',\n event => {\n const field = fieldOf(event.target)\n // `plaintext-only` pastes text itself; elsewhere, markup would arrive.\n if (field === undefined || field.contentEditable === 'plaintext-only') return\n const pasted = (event as ClipboardEvent).clipboardData?.getData('text/plain') ?? ''\n event.preventDefault()\n // `insertText` fires no `beforeinput`: begun here, a paste after Enter is an edit.\n begin(field)\n // As typing is, so the browser's undo takes it back; `textOf` makes one line of it.\n document.execCommand('insertText', false, pasted)\n },\n ],\n ]\n // Focuses a field as it becomes editable, and only then: made so, or drawn so.\n // A field editable all along, or another going away, moves no focus.\n const editable = `[${attribute}][contenteditable]:not([contenteditable=\"false\"])`\n const becoming = new MutationObserver(records => {\n if (ending !== undefined && !(ending.isConnected && ending.isContentEditable)) {\n ending = undefined\n const focused = document.activeElement\n if ((focused === null || focused === document.body) && element instanceof HTMLElement)\n element.focus({ preventScroll: true })\n }\n for (const record of records) {\n const changed =\n record.type === 'attributes' ? [record.target] : Array.from(record.addedNodes)\n for (const node of changed) {\n if (!(node instanceof HTMLElement)) continue\n const field = node.matches(editable) ? node : node.querySelector(editable)\n if (field instanceof HTMLElement) return caretAtEnd(field)\n }\n }\n })\n\n for (const [type, listener] of listeners) element.addEventListener(type, listener)\n // A field made editable, drawn editable, or leaving.\n becoming.observe(element, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: ['contenteditable'],\n })\n return { listeners, becoming }\n }),\n ({ listeners, becoming }) =>\n Effect.sync(() => {\n becoming.disconnect()\n for (const [type, listener] of listeners) element.removeEventListener(type, listener)\n }),\n ),\n ),\n})\n","import { Effect, Schema, Stream } from 'effect'\nimport * as Mount from 'foldkit/mount'\n\n/**\n * Keeps focus that is inside a container of roving tab stops on its stop, as a\n * Mount: when a transition moves the stop (a row made current by a command the\n * container did not see, such as a duplicate) or removes the focused\n * descendant (a deleted row), focus goes to the descendant with\n * `tabindex=\"0\"`. It sends no Message. Focus outside the container is never\n * taken, and focus the user moved away stays where it went.\n */\nexport const FollowTabStop = Mount.defineStream('FollowTabStop', {\n messages: [Schema.Never],\n execute: ({ element }) =>\n Stream.callback<never>(() =>\n Effect.acquireRelease(\n Effect.sync(() => {\n let within = element.contains(document.activeElement)\n const entered = () => {\n within = true\n }\n const left = (event: Event) => {\n const next = (event as FocusEvent).relatedTarget\n if (next instanceof Node && element.contains(next)) return\n const from = event.target\n // Asked once the change that may have taken it away is done: a descendant\n // removed with focus in it keeps the claim, one the user left does not.\n queueMicrotask(() => {\n if (!(from instanceof Node) || from.isConnected) within = false\n })\n }\n const follow = () => {\n if (!within) return\n const stop = element.querySelector('[tabindex=\"0\"]')\n const focused = document.activeElement\n if (!(stop instanceof HTMLElement) || stop === focused) return\n const lost = focused === null || focused === document.body\n const passed =\n focused !== null &&\n element.contains(focused) &&\n focused.getAttribute('tabindex') === '-1'\n if (lost || passed) stop.focus()\n }\n const changes = new MutationObserver(follow)\n element.addEventListener('focusin', entered)\n element.addEventListener('focusout', left)\n // A stop moved, or a descendant drawn or removed.\n changes.observe(element, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: ['tabindex'],\n })\n return () => {\n changes.disconnect()\n element.removeEventListener('focusin', entered)\n element.removeEventListener('focusout', left)\n }\n }),\n stop => Effect.sync(stop),\n ),\n ),\n})\n"],"mappings":";;;;AAGA,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,MAAM,aAAa,YAA8B;CAC/C,MAAM,QAAQ;CACd,OAAO,QAAQ,QAAQ,mBAAmB,MAAM,SAAS,MAAM,kBAAkB,KAAK;AACxF;;AAGA,MAAa,kBAAkB,SAC7B,MAAM,KAAK,KAAK,iBAA8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@ declare const PresenceMessage: import("foldkit/message").MessageUnion<{
27
27
  readonly Show: {};
28
28
  readonly Hide: {};
29
29
  readonly Hidden: {
30
- readonly generation: Schema.Number;
30
+ generation: Schema.Number;
31
31
  };
32
32
  }>;
33
33
  type PresenceMessage = typeof PresenceMessage.Type;
34
34
  /** Whether the content renders: shown or mid-exit. */
35
35
  declare const isVisible: (model: PresenceModel) => boolean;
36
+ /**
37
+ * Presence as a bundle: mount-transition state for exit animations. `Hide`
38
+ * starts a timed `hiding` phase; the `Hidden` fact it yields carries the
39
+ * generation it was scheduled under, so a `Show` in between wins and the
40
+ * late fact is ignored. The clock is Effect's, so tests drive it.
41
+ */
36
42
  declare const Presence: Bundle.Bundle<"Presence", {
37
43
  readonly durationMs: number;
38
44
  }, {
39
- readonly phase: "shown" | "hiding" | "hidden";
45
+ readonly phase: "hidden" | "hiding" | "shown";
40
46
  readonly generation: number;
41
47
  }, {
42
48
  readonly _tag: "Hidden";
43
49
  readonly generation: number;
44
- } | {
45
- readonly _tag: "Show";
46
50
  } | {
47
51
  readonly _tag: "Hide";
52
+ } | {
53
+ readonly _tag: "Show";
48
54
  }, never, never, never, void, {}, {}>;
49
55
  //#endregion
50
56
  //#region src/motion/spring.d.ts
@@ -58,15 +64,22 @@ declare const SpringMessage: import("foldkit/message").MessageUnion<{
58
64
  readonly Started: {};
59
65
  readonly Stopped: {};
60
66
  readonly Ticked: {
61
- readonly value: Schema.Number;
62
- readonly velocity: Schema.Number;
67
+ value: Schema.Number;
68
+ velocity: Schema.Number;
63
69
  };
64
70
  /** Carries the exact end value: the integrator stops near it, not on it. */
65
71
  readonly Finished: {
66
- readonly value: Schema.Number;
72
+ value: Schema.Number;
67
73
  };
68
74
  }>;
69
75
  type SpringMessage = typeof SpringMessage.Type;
76
+ /**
77
+ * A spring as a bundle: a number pulled toward a target with stiffness and
78
+ * damping, in the Model. Semi-implicit Euler at a fixed 16ms step, so the
79
+ * trajectory is deterministic under TestClock; the stream ends with
80
+ * Finished, and the value rests exactly at `to`. Underdamped springs
81
+ * overshoot — that is the point — but the rest value is still exact.
82
+ */
70
83
  declare const Spring: Bundle.Bundle<"Spring", {
71
84
  readonly from: number;
72
85
  readonly to: number;
@@ -77,6 +90,9 @@ declare const Spring: Bundle.Bundle<"Spring", {
77
90
  readonly velocity: number;
78
91
  readonly running: boolean;
79
92
  }, {
93
+ readonly _tag: "Finished";
94
+ readonly value: number;
95
+ } | {
80
96
  readonly _tag: "Started";
81
97
  } | {
82
98
  readonly _tag: "Stopped";
@@ -84,9 +100,6 @@ declare const Spring: Bundle.Bundle<"Spring", {
84
100
  readonly _tag: "Ticked";
85
101
  readonly value: number;
86
102
  readonly velocity: number;
87
- } | {
88
- readonly _tag: "Finished";
89
- readonly value: number;
90
103
  }, never, never, never, void, {}, {}>;
91
104
  //#endregion
92
105
  //#region src/motion/tween.d.ts
@@ -99,14 +112,20 @@ declare const TweenMessage: import("foldkit/message").MessageUnion<{
99
112
  readonly Started: {};
100
113
  readonly Stopped: {};
101
114
  readonly Ticked: {
102
- readonly value: Schema.Number;
115
+ value: Schema.Number;
103
116
  };
104
117
  /** Carries the exact end value: the stream may stop on either side of it. */
105
118
  readonly Finished: {
106
- readonly value: Schema.Number;
119
+ value: Schema.Number;
107
120
  };
108
121
  }>;
109
122
  type TweenMessage = typeof TweenMessage.Type;
123
+ /**
124
+ * A tween as a bundle: a number animated from one value to another over a
125
+ * duration, in the Model. Progress comes from Effect's clock, so tests drive
126
+ * it with TestClock; the stream ends with Finished, and the value rests at
127
+ * `to`. Linear interpolation only: easing curves stay the application's job.
128
+ */
110
129
  declare const Tween: Bundle.Bundle<"Tween", {
111
130
  readonly from: number;
112
131
  readonly to: number;
@@ -119,12 +138,12 @@ declare const Tween: Bundle.Bundle<"Tween", {
119
138
  } | {
120
139
  readonly _tag: "Stopped";
121
140
  } | {
122
- readonly _tag: "Ticked";
141
+ readonly _tag: "Finished";
123
142
  readonly value: number;
124
143
  } | {
125
- readonly _tag: "Finished";
144
+ readonly _tag: "Ticked";
126
145
  readonly value: number;
127
146
  }, never, never, never, void, {}, {}>;
128
147
  //#endregion
129
148
  export { SpringMessage as a, PresenceMessage as c, motion_d_exports as d, Spring as i, PresenceModel as l, TweenMessage as n, SpringModel as o, TweenModel as r, Presence as s, Tween as t, isVisible as u };
130
- //# sourceMappingURL=index-Cppf-lBx.d.mts.map
149
+ //# sourceMappingURL=index-CmmxqSEi.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-CmmxqSEi.d.mts","names":[],"sources":["../src/motion/motion.ts","../src/motion/presence.ts","../src/motion/spring.ts","../src/motion/tween.ts"],"mappings":";;;;;UAUiB;WACN,SAAS,OAAO;;;cAGd,eAAe;;cAGf,QAAK,qBAAuB,MAAM,MAAM;cAGxC,SAAS,MAAM,MAAM;cACrB,MAAM,MAAM,MAAM;;cAGlB,MAAM,MAAM,MAAM;;cAUlB,eAAe,OAAO;;;cC5BtB,eAAa,OAAA;;;;KAId,uBAAuB,cAAc;cAEpC,2CAAe;;;;IAGhB,YAAU,OAAA;;;KAEV,yBAAyB,gBAAgB;;cAGxC,YAAS,OAAW;;;;;;;cAQpB,UAAQ,OAAA;WAII;;;;;;;;;;;;;;cC1BZ,aAAW,OAAA;;;;;KAKZ,qBAAqB,YAAY;cAEhC,yCAAa;;;;IAGd,OAAK,OAAA;IAAiB,UAAQ,OAAA;;;;IAE5B,OAAK,OAAA;;;KAEP,uBAAuB,cAAc;;;;;;;;cAoBpC,QAAM,OAAA;;;;;;;;;;;;;;;;;;;;;;;cClCN,YAAU,OAAA;;;;KACX,oBAAoB,WAAW;cAE9B,wCAAY;;;;IAGb,OAAK,OAAA;;;;IAEH,OAAK,OAAA;;;KAEP,sBAAsB,aAAa;;;;;;;cAQlC,OAAK,OAAA"}
package/dist/index.d.mts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Coordinates, FullscreenMessage, Geolocation, GeolocationMessage, GeolocationModel, LiveStream, LiveStreamService, MediaDevice, MediaDevicesHandle, MediaDevicesMessage, MediaDevicesModel, MediaStreamConstraints, MediaStreamHandle, MediaStreamMessage, MediaStreamModel, MediaTrackHandle, PermissionState, PermissionStatusHandle, PermissionsHandle, PermissionsMessage, PermissionsModel, Watch, WatchService, enterFullscreen, exitFullscreen, fullscreenChanges, mediaDevices, mediaStream, permissions } from "./device/index.mjs";
2
- import { A as ScrollLock, C as targetOf, D as MoveStarted, E as MoveEnded, M as tabbableWithin, O as Moved, S as Targets, T as Move, _ as boxOf, a as TextEdited, b as TargetHovered, c as DRAG_THRESHOLD, d as DragFact, f as DragPlace, g as PointerDrag, h as DraggedOver, i as TextCommitted, j as FocusScope, k as HideOutside, l as DragCancelled, m as DragZone, n as EditableText, o as TextFact, p as DragStarted, r as TextCancelled, s as textOf, t as EditAsked, u as DragDropped, v as zoneOf, w as Fact, x as TargetPressed, y as TargetFact } from "./editable-text-BbsPOATY.mjs";
2
+ import { A as ScrollLock, C as targetOf, D as MoveStarted, E as MoveEnded, M as tabbableWithin, O as Moved, S as Targets, T as Move, _ as boxOf, a as TextEdited, b as TargetHovered, c as DRAG_THRESHOLD, d as DragFact, f as DragPlace, g as PointerDrag, h as DraggedOver, i as TextCommitted, j as FocusScope, k as HideOutside, l as DragCancelled, m as DragZone, n as EditableText, o as TextFact, p as DragStarted, r as TextCancelled, s as textOf, t as EditAsked, u as DragDropped, v as zoneOf, w as Fact, x as TargetPressed, y as TargetFact } from "./editable-text-Dvm-Fuqs.mjs";
3
3
  import { Autofocus, ClipboardMessage, ClipboardReadMessage, Focused, FollowTabStop, Input, InputMask, KeepInView, KeepScrollOptions, Measure, ScriptMessage, ShareData, ShareMessage, applyMask, copyText, keepScroll, loadScript, measured, pointedLinks, readText, share } from "./dom/index.mjs";
4
- import { a as modalityOfKey, i as Modality, n as InputModalityMessage, r as InputModalityModel, t as InputModality } from "./input-modality-DGOhAknO.mjs";
4
+ import { a as modalityOfKey, i as Modality, n as InputModalityMessage, r as InputModalityModel, t as InputModality } from "./input-modality-BY-bSrEc.mjs";
5
5
  import { ActiveElementMessage, Idle, IdleMessage, IdleModel, KeyPress, KeyboardMessage, PointerMessage, ScrollMessage, Visibility, VisibilityMessage, VisibilityModel, WindowSize, WindowSizeMessage, WindowSizeModel, activeElementEvents, keyboardEvents, matchHotkey, pointerEvents, scrollEvents } from "./events/index.mjs";
6
6
  import { Breakpoints, BreakpointsMessage, BreakpointsModel, MediaQuery, MediaQueryMessage, MediaQueryModel, Platform, PlatformHints, PrefersDark, PrefersReducedMotion, breakpointFor, isBrowser, isServer, platformFromUA } from "./media/index.mjs";
7
- import { a as SpringMessage, c as PresenceMessage, d as motion_d_exports, i as Spring, l as PresenceModel, n as TweenMessage, o as SpringModel, r as TweenModel, s as Presence, t as Tween, u as isVisible } from "./index-Cppf-lBx.mjs";
7
+ import { a as SpringMessage, c as PresenceMessage, d as motion_d_exports, i as Spring, l as PresenceModel, n as TweenMessage, o as SpringModel, r as TweenModel, s as Presence, t as Tween, u as isVisible } from "./index-CmmxqSEi.mjs";
8
8
  import { Acquired, AcquiredSource, BroadcastChannelHandle, BroadcastMessage, Conversation, ConversationHandler, Online, OnlineMessage, OnlineModel, SharedHost, SharedHostConnection, SharedHostOptions, Socket, SocketHandle, SocketService, SocketView, Source, SourceHandle, SourceService, SseMessage, SseModel, SseView, StartHost, WebSocketMessage, WebSocketModel, broadcastMessages, isLive, isOpen, postBroadcast, sse, viewOf, viewOfSse, websocket } from "./net/index.mjs";
9
9
  import { Bounds, Intersection, IntersectionChanged, Measured, Mutated, Mutation, Resize, Resized } from "./observers/index.mjs";
10
10
  import { History, HistoryModel, Locale, LocaleMessage, LocaleModel, MasonryPlacement, MeasureRow, Pagination, PaginationMessage, PaginationModel, RowMeasured, SelectionSet, SelectionSetMessage, SelectionSetModel, Viewport, ViewportScrolled, Virtual, VirtualLayout, VirtualMessage, VirtualModel, VirtualWindow, canRedo, canUndo, distanceToEnd, history, isAtEnd, isSelected, masonry, offset, offsetFor, pageCount, range, stickyHeader, totalHeight, visibleRange, windowFor } from "./state/index.mjs";
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { C as MoveEnded, D as ScrollLock, E as HideOutside, O as FocusScope, S as Move, T as Moved, _ as zoneOf, a as TextCommitted, b as Targets, c as DRAG_THRESHOLD, d as DragPlace, f as DragStarted, g as boxOf, h as PointerDrag, i as TextCancelled, k as tabbableWithin, l as DragCancelled, m as DraggedOver, n as EditAsked, o as TextEdited, p as DragZone, r as EditableText, s as textOf, t as FollowTabStop, u as DragDropped, v as TargetHovered, w as MoveStarted, x as targetOf, y as TargetPressed } from "./follow-tab-stop-BDxyoUPQ.mjs";
1
+ import { C as MoveEnded, D as ScrollLock, E as HideOutside, O as FocusScope, S as Move, T as Moved, _ as zoneOf, a as TextCommitted, b as Targets, c as DRAG_THRESHOLD, d as DragPlace, f as DragStarted, g as boxOf, h as PointerDrag, i as TextCancelled, k as tabbableWithin, l as DragCancelled, m as DraggedOver, n as EditAsked, o as TextEdited, p as DragZone, r as EditableText, s as textOf, t as FollowTabStop, u as DragDropped, v as TargetHovered, w as MoveStarted, x as targetOf, y as TargetPressed } from "./follow-tab-stop-Ci1tqAIW.mjs";
2
2
  import { Autofocus, ClipboardMessage, ClipboardReadMessage, Focused, Input, InputMask, KeepInView, Measure, ScriptMessage, ShareData, ShareMessage, applyMask, copyText, keepScroll, loadScript, measured, pointedLinks, readText, share } from "./dom/index.mjs";
3
3
  import { Coordinates, FullscreenMessage, Geolocation, GeolocationMessage, GeolocationModel, LiveStream, MediaDevice, MediaDevicesMessage, MediaDevicesModel, MediaStreamMessage, MediaStreamModel, PermissionState, PermissionsMessage, PermissionsModel, Watch, enterFullscreen, exitFullscreen, fullscreenChanges, mediaDevices, mediaStream, permissions } from "./device/index.mjs";
4
- import { a as modalityOfKey, i as Modality, n as InputModalityMessage, r as InputModalityModel, t as InputModality } from "./input-modality-m6v7__Xs.mjs";
4
+ import { a as modalityOfKey, i as Modality, n as InputModalityMessage, r as InputModalityModel, t as InputModality } from "./input-modality-BXD383jg.mjs";
5
5
  import { ActiveElementMessage, Idle, IdleMessage, IdleModel, KeyboardMessage, PointerMessage, ScrollMessage, Visibility, VisibilityMessage, VisibilityModel, WindowSize, WindowSizeMessage, WindowSizeModel, activeElementEvents, keyboardEvents, matchHotkey, pointerEvents, scrollEvents } from "./events/index.mjs";
6
6
  import { Breakpoints, BreakpointsMessage, BreakpointsModel, MediaQuery, MediaQueryMessage, MediaQueryModel, Platform, PrefersDark, PrefersReducedMotion, breakpointFor, isBrowser, isServer, platformFromUA } from "./media/index.mjs";
7
- import { a as SpringMessage, c as PresenceMessage, d as motion_exports, i as Spring, l as PresenceModel, n as TweenMessage, o as SpringModel, r as TweenModel, s as Presence, t as Tween, u as isVisible } from "./motion-DGGBZ0wt.mjs";
7
+ import { a as SpringMessage, c as PresenceMessage, d as motion_exports, i as Spring, l as PresenceModel, n as TweenMessage, o as SpringModel, r as TweenModel, s as Presence, t as Tween, u as isVisible } from "./motion-DmFDppRn.mjs";
8
8
  import { BroadcastMessage, Online, OnlineMessage, OnlineModel, SharedHost, Socket, SocketView, Source, SseMessage, SseModel, SseView, WebSocketMessage, WebSocketModel, broadcastMessages, isLive, isOpen, postBroadcast, sse, viewOf, viewOfSse, websocket } from "./net/index.mjs";
9
9
  import { Bounds, Intersection, IntersectionChanged, Measured, Mutated, Mutation, Resize, Resized } from "./observers/index.mjs";
10
10
  import { History, HistoryModel, Locale, LocaleMessage, LocaleModel, MeasureRow, Pagination, PaginationMessage, PaginationModel, RowMeasured, SelectionSet, SelectionSetMessage, SelectionSetModel, Viewport, ViewportScrolled, Virtual, VirtualMessage, VirtualModel, canRedo, canUndo, distanceToEnd, history, isAtEnd, isSelected, masonry, offset, offsetFor, pageCount, range, stickyHeader, totalHeight, visibleRange, windowFor } from "./state/index.mjs";
@@ -3,13 +3,6 @@ import { defineMessageUnion } from "foldkit/message";
3
3
  import * as Subscription from "foldkit/subscription";
4
4
  import { Bundle } from "foldkit-bundle";
5
5
  //#region src/events/input-modality.ts
6
- /**
7
- * Input modality as a bundle: whether the user last drove the page by
8
- * keyboard or by pointer. The browser reports the facts; the Model keeps the
9
- * answer, so a view can show a focus ring only for keyboard users without
10
- * reading the DOM, and a replay sees the same answer. CSS `:focus-visible`
11
- * is the floor; this is for JavaScript that must know.
12
- */
13
6
  const Modality = Schema.Literals([
14
7
  "keyboard",
15
8
  "pointer",
@@ -30,14 +23,21 @@ const modalityStream = () => {
30
23
  if (typeof window === "undefined") return Stream.empty;
31
24
  return Stream.mergeAll([Stream.fromEventListener(window, "keydown", { capture: true }).pipe(Stream.filter((event) => modalityOfKey(event.key) !== null), Stream.map(() => InputModalityMessage.Changed({ modality: "keyboard" }))), Stream.fromEventListener(window, "pointerdown", { capture: true }).pipe(Stream.map(() => InputModalityMessage.Changed({ modality: "pointer" })))], { concurrency: "unbounded" });
32
25
  };
26
+ /**
27
+ * Input modality as a bundle: whether the user last drove the page by
28
+ * keyboard or by pointer. The browser reports the facts; the Model keeps the
29
+ * answer, so a view can show a focus ring only for keyboard users without
30
+ * reading the DOM, and a replay sees the same answer. CSS `:focus-visible`
31
+ * is the floor; this is for JavaScript that must know.
32
+ */
33
33
  const InputModality = Bundle.make("InputModality", {
34
34
  Model: InputModalityModel,
35
35
  Message: InputModalityMessage,
36
36
  init: () => ({ model: { modality: "unknown" } }),
37
37
  update: (model, message) => model.modality === message.modality ? { model } : { model: { modality: message.modality } },
38
- subscriptions: () => Subscription.make()(() => ({ changes: Subscription.persistent(modalityStream()) }))
38
+ subscriptions: () => Subscription.make()(() => ({ changes: Subscription.persistentEntry(modalityStream()) }))
39
39
  });
40
40
  //#endregion
41
41
  export { modalityOfKey as a, Modality as i, InputModalityMessage as n, InputModalityModel as r, InputModality as t };
42
42
 
43
- //# sourceMappingURL=input-modality-m6v7__Xs.mjs.map
43
+ //# sourceMappingURL=input-modality-BXD383jg.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-modality-BXD383jg.mjs","names":[],"sources":["../src/events/input-modality.ts"],"sourcesContent":["import { Schema, Stream } from 'effect'\nimport { defineMessageUnion } from 'foldkit/message'\nimport * as Subscription from 'foldkit/subscription'\nimport { Bundle } from 'foldkit-bundle'\n\nexport const Modality = Schema.Literals(['keyboard', 'pointer', 'unknown'])\nexport type Modality = typeof Modality.Type\n\nexport const InputModalityModel = Schema.Struct({ modality: Modality })\nexport type InputModalityModel = typeof InputModalityModel.Type\n\nexport const InputModalityMessage = defineMessageUnion({ Changed: { modality: Modality } })\nexport type InputModalityMessage = typeof InputModalityMessage.Type\n\nconst MODIFIERS = new Set(['Shift', 'Control', 'Alt', 'Meta', 'CapsLock'])\n\n/** A modifier alone says nothing about how the page is being driven. */\nexport const modalityOfKey = (key: string): Modality | null =>\n MODIFIERS.has(key) ? null : 'keyboard'\n\nconst modalityStream = (): Stream.Stream<InputModalityMessage> => {\n if (typeof window === 'undefined') return Stream.empty\n return Stream.mergeAll(\n [\n Stream.fromEventListener<KeyboardEvent>(window, 'keydown', { capture: true }).pipe(\n Stream.filter(event => modalityOfKey(event.key) !== null),\n Stream.map(() => InputModalityMessage.Changed({ modality: 'keyboard' })),\n ),\n Stream.fromEventListener(window, 'pointerdown', { capture: true }).pipe(\n Stream.map(() => InputModalityMessage.Changed({ modality: 'pointer' })),\n ),\n ],\n { concurrency: 'unbounded' },\n )\n}\n\n/**\n * Input modality as a bundle: whether the user last drove the page by\n * keyboard or by pointer. The browser reports the facts; the Model keeps the\n * answer, so a view can show a focus ring only for keyboard users without\n * reading the DOM, and a replay sees the same answer. CSS `:focus-visible`\n * is the floor; this is for JavaScript that must know.\n */\nexport const InputModality = Bundle.make('InputModality', {\n Model: InputModalityModel,\n Message: InputModalityMessage,\n init: () => ({ model: { modality: 'unknown' as const } }),\n update: (model, message) =>\n model.modality === message.modality ? { model } : { model: { modality: message.modality } },\n subscriptions: (): Subscription.Subscriptions<InputModalityModel, InputModalityMessage> =>\n Subscription.make<InputModalityModel, InputModalityMessage>()(() => ({\n changes: Subscription.persistentEntry(modalityStream()),\n })),\n})\n"],"mappings":";;;;;AAKA,MAAa,WAAW,OAAO,SAAS;CAAC;CAAY;CAAW;AAAS,CAAC;AAG1E,MAAa,qBAAqB,OAAO,OAAO,EAAE,UAAU,SAAS,CAAC;AAGtE,MAAa,uBAAuB,mBAAmB,EAAE,SAAS,EAAE,UAAU,SAAS,EAAE,CAAC;AAG1F,MAAM,4BAAY,IAAI,IAAI;CAAC;CAAS;CAAW;CAAO;CAAQ;AAAU,CAAC;;AAGzE,MAAa,iBAAiB,QAC5B,UAAU,IAAI,GAAG,IAAI,OAAO;AAE9B,MAAM,uBAA4D;CAChE,IAAI,OAAO,WAAW,aAAa,OAAO,OAAO;CACjD,OAAO,OAAO,SACZ,CACE,OAAO,kBAAiC,QAAQ,WAAW,EAAE,SAAS,KAAK,CAAC,CAAC,CAAC,KAC5E,OAAO,QAAO,UAAS,cAAc,MAAM,GAAG,MAAM,IAAI,GACxD,OAAO,UAAU,qBAAqB,QAAQ,EAAE,UAAU,WAAW,CAAC,CAAC,CACzE,GACA,OAAO,kBAAkB,QAAQ,eAAe,EAAE,SAAS,KAAK,CAAC,CAAC,CAAC,KACjE,OAAO,UAAU,qBAAqB,QAAQ,EAAE,UAAU,UAAU,CAAC,CAAC,CACxE,CACF,GACA,EAAE,aAAa,YAAY,CAC7B;AACF;;;;;;;;AASA,MAAa,gBAAgB,OAAO,KAAK,iBAAiB;CACxD,OAAO;CACP,SAAS;CACT,aAAa,EAAE,OAAO,EAAE,UAAU,UAAmB,EAAE;CACvD,SAAS,OAAO,YACd,MAAM,aAAa,QAAQ,WAAW,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,UAAU,QAAQ,SAAS,EAAE;CAC5F,qBACE,aAAa,KAA+C,CAAC,QAAQ,EACnE,SAAS,aAAa,gBAAgB,eAAe,CAAC,EACxD,EAAE;AACN,CAAC"}
@@ -9,12 +9,19 @@ declare const InputModalityModel: Schema.Struct<{
9
9
  type InputModalityModel = typeof InputModalityModel.Type;
10
10
  declare const InputModalityMessage: import("foldkit/message").MessageUnion<{
11
11
  readonly Changed: {
12
- readonly modality: Schema.Literals<readonly ["keyboard", "pointer", "unknown"]>;
12
+ modality: Schema.Literals<readonly ["keyboard", "pointer", "unknown"]>;
13
13
  };
14
14
  }>;
15
15
  type InputModalityMessage = typeof InputModalityMessage.Type;
16
16
  /** A modifier alone says nothing about how the page is being driven. */
17
17
  declare const modalityOfKey: (key: string) => Modality | null;
18
+ /**
19
+ * Input modality as a bundle: whether the user last drove the page by
20
+ * keyboard or by pointer. The browser reports the facts; the Model keeps the
21
+ * answer, so a view can show a focus ring only for keyboard users without
22
+ * reading the DOM, and a replay sees the same answer. CSS `:focus-visible`
23
+ * is the floor; this is for JavaScript that must know.
24
+ */
18
25
  declare const InputModality: Bundle.Bundle<"InputModality", void, {
19
26
  readonly modality: "keyboard" | "pointer" | "unknown";
20
27
  }, {
@@ -23,4 +30,4 @@ declare const InputModality: Bundle.Bundle<"InputModality", void, {
23
30
  }, never, never, never, void, {}, {}>;
24
31
  //#endregion
25
32
  export { modalityOfKey as a, Modality as i, InputModalityMessage as n, InputModalityModel as r, InputModality as t };
26
- //# sourceMappingURL=input-modality-DGOhAknO.d.mts.map
33
+ //# sourceMappingURL=input-modality-BY-bSrEc.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-modality-BY-bSrEc.d.mts","names":[],"sources":["../src/events/input-modality.ts"],"mappings":";;;cAKa,UAAQ,OAAA;KACT,kBAAkB,SAAS;cAE1B,oBAAkB,OAAA;qBAAlB,OAAA;;KACD,4BAA4B,mBAAmB;cAE9C,gDAAoB;;IAAmC,UAAQ,OAAA;;;KAChE,8BAA8B,qBAAqB;;cAKlD,gBAAa,gBAAkB;;;;;;;;cA0B/B,eAAa,OAAA"}