stimeo-ui 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/dist/controllers/announcer_controller.js.map +1 -1
  3. package/dist/controllers/aspect_ratio_controller.d.ts +3 -5
  4. package/dist/controllers/aspect_ratio_controller.js +19 -11
  5. package/dist/controllers/aspect_ratio_controller.js.map +1 -1
  6. package/dist/controllers/avatar_controller.d.ts +36 -15
  7. package/dist/controllers/avatar_controller.js +195 -40
  8. package/dist/controllers/avatar_controller.js.map +1 -1
  9. package/dist/controllers/breadcrumb_controller.js +5 -1
  10. package/dist/controllers/breadcrumb_controller.js.map +1 -1
  11. package/dist/controllers/carousel_controller.d.ts +12 -3
  12. package/dist/controllers/carousel_controller.js +90 -10
  13. package/dist/controllers/carousel_controller.js.map +1 -1
  14. package/dist/controllers/checkbox_controller.d.ts +31 -5
  15. package/dist/controllers/checkbox_controller.js +136 -25
  16. package/dist/controllers/checkbox_controller.js.map +1 -1
  17. package/dist/controllers/clipboard_controller.js +8 -3
  18. package/dist/controllers/clipboard_controller.js.map +1 -1
  19. package/dist/controllers/collapsible_controller.d.ts +1 -1
  20. package/dist/controllers/collapsible_controller.js +4 -1
  21. package/dist/controllers/collapsible_controller.js.map +1 -1
  22. package/dist/controllers/color_picker_controller.d.ts +9 -3
  23. package/dist/controllers/color_picker_controller.js +41 -11
  24. package/dist/controllers/color_picker_controller.js.map +1 -1
  25. package/dist/controllers/combobox_controller.js.map +1 -1
  26. package/dist/controllers/command_palette_controller.js.map +1 -1
  27. package/dist/controllers/context_menu_controller.d.ts +1 -1
  28. package/dist/controllers/context_menu_controller.js +2 -2
  29. package/dist/controllers/context_menu_controller.js.map +1 -1
  30. package/dist/controllers/countdown_controller.d.ts +5 -3
  31. package/dist/controllers/countdown_controller.js +5 -1
  32. package/dist/controllers/countdown_controller.js.map +1 -1
  33. package/dist/controllers/date_range_picker_controller.d.ts +23 -4
  34. package/dist/controllers/date_range_picker_controller.js +162 -31
  35. package/dist/controllers/date_range_picker_controller.js.map +1 -1
  36. package/dist/controllers/direct_upload_controller.d.ts +1 -1
  37. package/dist/controllers/direct_upload_controller.js +3 -3
  38. package/dist/controllers/direct_upload_controller.js.map +1 -1
  39. package/dist/controllers/empty_state_controller.d.ts +27 -7
  40. package/dist/controllers/empty_state_controller.js +107 -16
  41. package/dist/controllers/empty_state_controller.js.map +1 -1
  42. package/dist/controllers/file_dropzone_controller.d.ts +7 -1
  43. package/dist/controllers/file_dropzone_controller.js +26 -3
  44. package/dist/controllers/file_dropzone_controller.js.map +1 -1
  45. package/dist/controllers/flash_controller.d.ts +25 -5
  46. package/dist/controllers/flash_controller.js +161 -21
  47. package/dist/controllers/flash_controller.js.map +1 -1
  48. package/dist/controllers/focus_controller.d.ts +2 -3
  49. package/dist/controllers/focus_controller.js.map +1 -1
  50. package/dist/controllers/form_validation_controller.js +8 -2
  51. package/dist/controllers/form_validation_controller.js.map +1 -1
  52. package/dist/controllers/frame_loading_controller.d.ts +19 -2
  53. package/dist/controllers/frame_loading_controller.js +94 -22
  54. package/dist/controllers/frame_loading_controller.js.map +1 -1
  55. package/dist/controllers/highlight_controller.d.ts +8 -4
  56. package/dist/controllers/highlight_controller.js +38 -1
  57. package/dist/controllers/highlight_controller.js.map +1 -1
  58. package/dist/controllers/hover_card_controller.d.ts +2 -2
  59. package/dist/controllers/hover_card_controller.js.map +1 -1
  60. package/dist/controllers/idle_controller.d.ts +5 -4
  61. package/dist/controllers/idle_controller.js +39 -6
  62. package/dist/controllers/idle_controller.js.map +1 -1
  63. package/dist/controllers/listbox_controller.js.map +1 -1
  64. package/dist/controllers/local_time_controller.js +2 -0
  65. package/dist/controllers/local_time_controller.js.map +1 -1
  66. package/dist/controllers/masonry_controller.d.ts +1 -1
  67. package/dist/controllers/masonry_controller.js +1 -1
  68. package/dist/controllers/masonry_controller.js.map +1 -1
  69. package/dist/controllers/menubar_controller.js +5 -3
  70. package/dist/controllers/menubar_controller.js.map +1 -1
  71. package/dist/controllers/meter_controller.js +3 -1
  72. package/dist/controllers/meter_controller.js.map +1 -1
  73. package/dist/controllers/multi_select_controller.d.ts +46 -12
  74. package/dist/controllers/multi_select_controller.js +460 -151
  75. package/dist/controllers/multi_select_controller.js.map +1 -1
  76. package/dist/controllers/network_status_controller.d.ts +15 -13
  77. package/dist/controllers/network_status_controller.js +1 -3
  78. package/dist/controllers/network_status_controller.js.map +1 -1
  79. package/dist/controllers/number_input_controller.d.ts +29 -3
  80. package/dist/controllers/number_input_controller.js +455 -64
  81. package/dist/controllers/number_input_controller.js.map +1 -1
  82. package/dist/controllers/overflow_menu_controller.js +5 -1
  83. package/dist/controllers/overflow_menu_controller.js.map +1 -1
  84. package/dist/controllers/pagination_controller.js +38 -1
  85. package/dist/controllers/pagination_controller.js.map +1 -1
  86. package/dist/controllers/password_strength_controller.d.ts +4 -4
  87. package/dist/controllers/password_strength_controller.js +21 -3
  88. package/dist/controllers/password_strength_controller.js.map +1 -1
  89. package/dist/controllers/persist_controller.d.ts +4 -4
  90. package/dist/controllers/persist_controller.js +24 -5
  91. package/dist/controllers/persist_controller.js.map +1 -1
  92. package/dist/controllers/pointer_drag_controller.js +10 -0
  93. package/dist/controllers/pointer_drag_controller.js.map +1 -1
  94. package/dist/controllers/popover_controller.d.ts +2 -2
  95. package/dist/controllers/popover_controller.js.map +1 -1
  96. package/dist/controllers/portal_controller.d.ts +1 -2
  97. package/dist/controllers/portal_controller.js +10 -0
  98. package/dist/controllers/portal_controller.js.map +1 -1
  99. package/dist/controllers/progress_controller.d.ts +1 -1
  100. package/dist/controllers/progress_controller.js +7 -3
  101. package/dist/controllers/progress_controller.js.map +1 -1
  102. package/dist/controllers/radio_group_controller.d.ts +41 -15
  103. package/dist/controllers/radio_group_controller.js +540 -56
  104. package/dist/controllers/radio_group_controller.js.map +1 -1
  105. package/dist/controllers/range_slider_controller.d.ts +23 -0
  106. package/dist/controllers/range_slider_controller.js +385 -94
  107. package/dist/controllers/range_slider_controller.js.map +1 -1
  108. package/dist/controllers/rating_controller.d.ts +36 -31
  109. package/dist/controllers/rating_controller.js +274 -89
  110. package/dist/controllers/rating_controller.js.map +1 -1
  111. package/dist/controllers/relative_time_controller.js +2 -0
  112. package/dist/controllers/relative_time_controller.js.map +1 -1
  113. package/dist/controllers/resizable_controller.js +33 -0
  114. package/dist/controllers/resizable_controller.js.map +1 -1
  115. package/dist/controllers/roving_controller.d.ts +4 -0
  116. package/dist/controllers/roving_controller.js +60 -5
  117. package/dist/controllers/roving_controller.js.map +1 -1
  118. package/dist/controllers/scroll_area_controller.d.ts +7 -1
  119. package/dist/controllers/scroll_area_controller.js +155 -23
  120. package/dist/controllers/scroll_area_controller.js.map +1 -1
  121. package/dist/controllers/scroll_visibility_controller.js +33 -0
  122. package/dist/controllers/scroll_visibility_controller.js.map +1 -1
  123. package/dist/controllers/separator_controller.js +13 -17
  124. package/dist/controllers/separator_controller.js.map +1 -1
  125. package/dist/controllers/skeleton_controller.d.ts +2 -2
  126. package/dist/controllers/skeleton_controller.js +71 -3
  127. package/dist/controllers/skeleton_controller.js.map +1 -1
  128. package/dist/controllers/slider_controller.d.ts +17 -1
  129. package/dist/controllers/slider_controller.js +325 -48
  130. package/dist/controllers/slider_controller.js.map +1 -1
  131. package/dist/controllers/spinner_controller.d.ts +15 -10
  132. package/dist/controllers/spinner_controller.js +18 -3
  133. package/dist/controllers/spinner_controller.js.map +1 -1
  134. package/dist/controllers/step_indicator_controller.d.ts +1 -1
  135. package/dist/controllers/step_indicator_controller.js +3 -1
  136. package/dist/controllers/step_indicator_controller.js.map +1 -1
  137. package/dist/controllers/stepper_controller.js +2 -0
  138. package/dist/controllers/stepper_controller.js.map +1 -1
  139. package/dist/controllers/switch_controller.d.ts +12 -8
  140. package/dist/controllers/switch_controller.js +162 -18
  141. package/dist/controllers/switch_controller.js.map +1 -1
  142. package/dist/controllers/tags_input_controller.d.ts +41 -11
  143. package/dist/controllers/tags_input_controller.js +356 -120
  144. package/dist/controllers/tags_input_controller.js.map +1 -1
  145. package/dist/controllers/textarea_autosize_controller.js +1 -1
  146. package/dist/controllers/textarea_autosize_controller.js.map +1 -1
  147. package/dist/controllers/time_picker_controller.d.ts +42 -10
  148. package/dist/controllers/time_picker_controller.js +296 -104
  149. package/dist/controllers/time_picker_controller.js.map +1 -1
  150. package/dist/controllers/toggle_group_controller.d.ts +39 -13
  151. package/dist/controllers/toggle_group_controller.js +378 -55
  152. package/dist/controllers/toggle_group_controller.js.map +1 -1
  153. package/dist/controllers/toolbar_controller.js +5 -3
  154. package/dist/controllers/toolbar_controller.js.map +1 -1
  155. package/dist/controllers/tooltip_controller.d.ts +2 -2
  156. package/dist/controllers/tooltip_controller.js.map +1 -1
  157. package/dist/controllers/transition_controller.d.ts +2 -3
  158. package/dist/controllers/transition_controller.js.map +1 -1
  159. package/dist/controllers/tree_view_controller.d.ts +1 -2
  160. package/dist/controllers/tree_view_controller.js +24 -4
  161. package/dist/controllers/tree_view_controller.js.map +1 -1
  162. package/dist/index.js +3811 -1048
  163. package/dist/index.js.map +1 -1
  164. package/dist/inspector/cli.d.ts +92 -4
  165. package/dist/inspector/cli.js +174 -6
  166. package/dist/inspector/cli.js.map +1 -1
  167. package/dist/inspector/cli_bin.js +234 -8
  168. package/dist/inspector/cli_bin.js.map +1 -1
  169. package/dist/inspector/examples.json +24 -24
  170. package/dist/inspector/manifest.json +573 -59
  171. package/dist/positioning/index.d.ts +2 -2
  172. package/dist/positioning/index.js.map +1 -1
  173. package/package.json +3 -3
@@ -13,6 +13,39 @@ function isReservedArrowChord(event, allow = []) {
13
13
  return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
14
14
  }
15
15
 
16
+ // src/utils/microtask_coalescer.ts
17
+ var MicrotaskCoalescer = class {
18
+ #run;
19
+ #queued = false;
20
+ #active = false;
21
+ #generation = 0;
22
+ /** @param run - the single reconciliation pass, invoked at most once per batch. */
23
+ constructor(run) {
24
+ this.#run = run;
25
+ }
26
+ /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */
27
+ activate() {
28
+ this.#active = true;
29
+ }
30
+ /** Closes the window and drops any pending pass; call from `disconnect()`. */
31
+ cancel() {
32
+ this.#active = false;
33
+ this.#queued = false;
34
+ this.#generation += 1;
35
+ }
36
+ /** Requests one pass after the batch settles. Idempotent; inert outside the window. */
37
+ schedule() {
38
+ if (!this.#active || this.#queued) return;
39
+ this.#queued = true;
40
+ const generation = this.#generation;
41
+ queueMicrotask(() => {
42
+ if (generation !== this.#generation || !this.#queued || !this.#active) return;
43
+ this.#queued = false;
44
+ this.#run();
45
+ });
46
+ }
47
+ };
48
+
16
49
  // src/utils/roving_tabindex.ts
17
50
  var RovingTabindex = class {
18
51
  /** Returns the current ordered item elements; called on every operation. */
@@ -35,10 +68,12 @@ var RovingTabindex = class {
35
68
  * "nothing is currently tabbable".
36
69
  *
37
70
  * @param index - Position of the item to make tabbable.
38
- * @param options - Pass `{ focus: true }` to also move DOM focus to that item.
71
+ * @param options - Pass `{ focus: true }` to also move DOM focus to that item,
72
+ * and `items` to reuse an event-scoped collection snapshot.
39
73
  */
40
- setActive(index, { focus = false } = {}) {
41
- const items = this.#getItems();
74
+ setActive(index, options = {}) {
75
+ const { focus = false } = options;
76
+ const items = options.items ?? this.#getItems();
42
77
  items.forEach((item, i) => {
43
78
  item.tabIndex = i === index ? 0 : -1;
44
79
  });
@@ -62,16 +97,31 @@ var RovingController = class extends Controller {
62
97
  };
63
98
  static events = ["change"];
64
99
  #roving = new RovingTabindex(() => this.itemTargets);
100
+ #reconcile = new MicrotaskCoalescer(() => this.#ensureTabStop());
101
+ #connected = false;
65
102
  connect() {
66
- const active = this.#roving.activeIndex;
67
- this.#roving.setActive(active === -1 ? 0 : active);
103
+ this.#ensureTabStop();
68
104
  this.element.addEventListener("keydown", this.#onKeydown);
69
105
  this.element.addEventListener("focusin", this.#onFocusin);
106
+ this.#connected = true;
107
+ this.#reconcile.activate();
70
108
  }
71
109
  disconnect() {
110
+ this.#connected = false;
111
+ this.#reconcile.cancel();
72
112
  this.element.removeEventListener("keydown", this.#onKeydown);
73
113
  this.element.removeEventListener("focusin", this.#onFocusin);
74
114
  }
115
+ /** Drops a runtime-added item from the Tab sequence before batch reconciliation. */
116
+ itemTargetConnected(item) {
117
+ if (!this.#connected) return;
118
+ item.tabIndex = -1;
119
+ this.#reconcile.schedule();
120
+ }
121
+ /** Re-establishes the single Tab stop after an item leaves the target set. */
122
+ itemTargetDisconnected() {
123
+ this.#reconcile.schedule();
124
+ }
75
125
  /** Arrow keys move focus + the tab stop; Home/End jump to the ends. */
76
126
  #onKeydown = (event) => {
77
127
  if (event.defaultPrevented) return;
@@ -125,6 +175,11 @@ var RovingController = class extends Controller {
125
175
  this.dispatch("change", { detail: { index, item: this.itemTargets[index] } });
126
176
  }
127
177
  }
178
+ /** Keeps the first existing Tab stop, falling back to the first live item. */
179
+ #ensureTabStop() {
180
+ const active = this.#roving.activeIndex;
181
+ this.#roving.setActive(active === -1 ? 0 : active);
182
+ }
128
183
  };
129
184
 
130
185
  export { RovingController };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/logical_scroll.ts","../../src/utils/arrow_step.ts","../../src/utils/roving_tabindex.ts","../../src/controllers/roving_controller.ts"],"names":[],"mappings":";;;;;AAiBO,SAAS,MAAM,OAAA,EAA2B;AAC/C,EAAA,OAAO,MAAA,CAAO,gBAAA,CAAiB,OAAO,CAAA,CAAE,SAAA,KAAc,KAAA;AACxD;;;AC4EO,SAAS,oBAAA,CACd,KAAA,EACA,KAAA,GAAkC,EAAC,EAC1B;AACT,EAAA,IAAI,CAAC,KAAA,CAAM,GAAA,CAAI,UAAA,CAAW,OAAO,GAAG,OAAO,KAAA;AAC3C,EAAA,OACG,KAAA,CAAM,MAAA,IAAU,CAAC,KAAA,CAAM,QAAA,CAAS,KAAK,CA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":"roving_controller.js","sourcesContent":["/** Normalized scroll position and maximum distance on one logical axis. */\nexport interface LogicalScrollMetrics {\n position: number;\n max: number;\n}\n\n/**\n * Whether horizontal scrolling on `element` follows right-to-left inline flow.\n *\n * Resolved from the **computed** `direction`, so the authoring contract is the\n * usual `dir=\"rtl\"` (or a stylesheet) on the element or any ancestor.\n *\n * Scope: horizontal writing modes. A vertical writing mode (`writing-mode:\n * vertical-rl`) also inverts the horizontal axis, which this check does not\n * model — vertical writing modes are out of scope for the scroll utilities\n * (their consumers describe axes as horizontal/vertical, not inline/block).\n */\nexport function isRtl(element: Element): boolean {\n return window.getComputedStyle(element).direction === \"rtl\";\n}\n\n/**\n * Returns scroll distance from the logical start edge.\n *\n * CSSOM View exposes standards-mode RTL horizontal offsets as `0` at the inline\n * start (right) and increasingly negative values toward the inline end (left).\n * The normalized position is always clamped to `[0, max]`, which also absorbs\n * Safari's elastic overscroll values.\n */\nexport function logicalScrollMetrics(\n element: HTMLElement,\n horizontal: boolean,\n): LogicalScrollMetrics {\n const max = Math.max(\n 0,\n horizontal\n ? element.scrollWidth - element.clientWidth\n : element.scrollHeight - element.clientHeight,\n );\n const raw = horizontal ? element.scrollLeft : element.scrollTop;\n const position = horizontal && isRtl(element) ? -raw : raw;\n return { position: Math.min(max, Math.max(0, position)), max };\n}\n\n/**\n * Converts a logical start/end delta to the physical value accepted by\n * `Element.scrollBy`.\n */\nexport function physicalScrollDelta(\n element: HTMLElement,\n horizontal: boolean,\n logicalDelta: number,\n): number {\n return horizontal && isRtl(element) ? -logicalDelta : logicalDelta;\n}\n","import { isRtl } from \"./logical_scroll\";\n\n/**\n * Turns an arrow key into a **logical** step: `+1` for \"next\", `-1` for\n * \"previous\", `0` when the key names neither.\n *\n * APG defines the horizontal pair as *next / previous* and says a vertical\n * arrangement swaps in Down/Up for the same meaning — so the pair is one axis's\n * spelling of an order, and the order reverses with the writing direction. Only\n * the horizontal pair reverses. Down/Up name an axis the writing direction does\n * not mirror, and returning them unchanged is the point: many controllers fold\n * both pairs into one branch, where swapping the branches under RTL would flip\n * the vertical axis too — a bug that reads as \"the arrows work\" until someone\n * presses Down.\n *\n * **Direction is read from the element the caller passes, which should be the\n * container that lays the items out** — not the focused child. A child may carry\n * its own `dir` (an LTR input inside an RTL form is ordinary authoring), and\n * probing per handler makes two handlers disagree at the boundary between them.\n *\n * This decides direction only. Whether the axis is even active (an\n * `orientation=\"horizontal\"` widget ignoring Down/Up), how far the step lands,\n * and what wrapping does all stay with the caller.\n *\n * **It encodes the list-order convention: `ArrowDown` is *next*.** Widgets that\n * pair the arrows by *value* instead — `ArrowUp` meaning \"more\", as a rating or a\n * slider does — must not use this, or their vertical axis inverts. Reverse the\n * horizontal pair on its own there.\n *\n * @example\n * ```ts\n * const step = logicalArrowStep(event.key, this.element);\n * if (step === 0) return;\n * this.#roving.setActive(rovingMove(current, length, step, \"wrap\"), { focus: true });\n * ```\n */\nexport function logicalArrowStep(key: string, element: Element): 1 | -1 | 0 {\n if (key === \"ArrowDown\") return 1;\n if (key === \"ArrowUp\") return -1;\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return 0;\n const forward = isRtl(element) ? \"ArrowLeft\" : \"ArrowRight\";\n return key === forward ? 1 : -1;\n}\n\n/**\n * Rewrites `key` so an existing LTR-shaped branch keeps working under RTL:\n * `ArrowRight` and `ArrowLeft` trade places, everything else passes through.\n *\n * The alternative — negating a delta — silently breaks handlers whose two\n * horizontal branches are **not mirror images**. A grid that clamps one edge but\n * not the other, or a segmented field guarding `index > 0` on one side and\n * `index < length - 1` on the other, ends up applying the wrong guard to the\n * wrong direction. Swapping the key leaves each branch, guards and all, exactly\n * where its author put it.\n *\n * Same rule as {@link logicalArrowStep} about which element to read: pass the\n * container that lays the items out, not the focused child.\n *\n * @example\n * ```ts\n * switch (logicalArrowKey(event.key, this.element)) {\n * case \"ArrowLeft\": // \"previous\" — whatever direction that is on screen\n * ```\n */\nexport function logicalArrowKey(key: string, element: Element): string {\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return key;\n if (!isRtl(element)) return key;\n return key === \"ArrowRight\" ? \"ArrowLeft\" : \"ArrowRight\";\n}\n\n/** Modifiers a widget may claim on an arrow key, named for the `allow` list. */\nexport type ArrowModifier = \"alt\" | \"ctrl\" | \"meta\" | \"shift\";\n\n/**\n * True when an arrow key arrived carrying a modifier the widget must leave to\n * the browser: return without calling `preventDefault()` and without moving any\n * state.\n *\n * A bare arrow belongs to the widget; a chorded one usually does not.\n * `Alt`/`Meta` plus a horizontal arrow is history back/forward on every desktop\n * browser, and a widget that swallows it makes the shortcut work or not\n * depending on where focus happens to sit — a coin-flip the user cannot see.\n *\n * `allow` is for the combinations APG assigns to a pattern **and the widget\n * actually implements** — today only Combobox's optional `Alt+Down`/`Alt+Up`.\n * Listing one the widget does not implement defeats the point: the chord then\n * runs the plain-arrow branch, which is exactly what this guard exists to stop.\n * Non-arrow keys return `false`, so chorded letters and\n * `Control+Home`/`Control+End` are untouched.\n *\n * @example\n * ```ts\n * if (isReservedArrowChord(event)) return;\n * ```\n */\nexport function isReservedArrowChord(\n event: KeyboardEvent,\n allow: readonly ArrowModifier[] = [],\n): boolean {\n if (!event.key.startsWith(\"Arrow\")) return false;\n return (\n (event.altKey && !allow.includes(\"alt\")) ||\n (event.ctrlKey && !allow.includes(\"ctrl\")) ||\n (event.metaKey && !allow.includes(\"meta\")) ||\n (event.shiftKey && !allow.includes(\"shift\"))\n );\n}\n","/**\n * Low-level roving-tabindex primitive shared by composite-widget controllers.\n *\n * The APG roving-tabindex pattern keeps a composite widget a single Tab stop:\n * exactly one item is in the Tab sequence (`tabindex=\"0\"`) while the rest are\n * removed from it (`tabindex=\"-1\"`), and the arrow keys move both DOM focus and\n * that single tabbable position together. {@link RovingTabindex} owns *only* that\n * mechanical bookkeeping — \"which one item is tabbable, and move focus there\".\n *\n * It is intentionally **policy-free**. Orientation, wrapping vs. clamping,\n * selection-follows-focus, typeahead, and `Home`/`End` semantics differ per APG\n * pattern (Radio Group, Toolbar, Rating, …); folding them into one helper would\n * flatten those widgets to a lowest common denominator and lose each pattern's\n * correctness. Those decisions therefore stay in each controller, which calls\n * {@link RovingTabindex.setActive} with an index it computed itself (optionally\n * via the pure {@link rovingMove} helper).\n *\n * @remarks\n * Items are read lazily through a getter so a controller can add or remove\n * targets (Stimulus re-scans the DOM) without re-wiring this helper.\n */\nexport class RovingTabindex {\n /** Returns the current ordered item elements; called on every operation. */\n readonly #getItems: () => HTMLElement[];\n\n /**\n * @param getItems - Returns the current ordered item elements. Called on every\n * operation so the live target list is always used.\n */\n constructor(getItems: () => HTMLElement[]) {\n this.#getItems = getItems;\n }\n\n /** Index of the currently tabbable item (`tabindex=\"0\"`), or `-1` if none. */\n get activeIndex(): number {\n return this.#getItems().findIndex((item) => item.tabIndex === 0);\n }\n\n /**\n * Makes exactly the item at `index` tabbable (`tabindex=\"0\"`) and removes every\n * other item from the Tab sequence (`tabindex=\"-1\"`). An out-of-range `index`\n * (e.g. `-1`) leaves all items at `-1`, which a controller can use to express\n * \"nothing is currently tabbable\".\n *\n * @param index - Position of the item to make tabbable.\n * @param options - Pass `{ focus: true }` to also move DOM focus to that item.\n */\n setActive(index: number, { focus = false }: { focus?: boolean } = {}): void {\n const items = this.#getItems();\n items.forEach((item, i) => {\n item.tabIndex = i === index ? 0 : -1;\n });\n if (focus) items[index]?.focus();\n }\n}\n\n/** Edge behavior for {@link rovingMove}: cycle past the ends, or stop at them. */\nexport type RovingWrap = \"wrap\" | \"clamp\";\n\n/**\n * Pure helper that resolves the target index for a one-step directional move.\n *\n * Keyboard/orientation mapping stays in the caller: it decides that a key means\n * `delta` `+1` (next) or `-1` (previous) and whether the widget should `\"wrap\"`\n * (Radio Group, Toolbar) or `\"clamp\"` at the ends.\n *\n * @param current - The index focus is moving from.\n * @param length - Number of items in the set.\n * @param delta - `+1` to move to the next item, `-1` for the previous.\n * @param wrap - `\"wrap\"` cycles around the ends; `\"clamp\"` stops at them.\n * @returns The resolved index, or `-1` when there are no items.\n */\nexport function rovingMove(\n current: number,\n length: number,\n delta: number,\n wrap: RovingWrap,\n): number {\n if (length === 0) return -1;\n const next = current + delta;\n if (wrap === \"wrap\") return (next + length) % length;\n return Math.min(length - 1, Math.max(0, next));\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\nimport { isRtl } from \"../utils/logical_scroll\";\nimport { RovingTabindex, type RovingWrap, rovingMove } from \"../utils/roving_tabindex\";\n\n/**\n * Headless **roving tabindex**: makes a set of `item`s a single Tab stop and\n * moves focus between them with the arrow keys — the APG roving-tabindex\n * technique, surfaced as a standalone controller. It is the policy layer over the\n * shared {@link RovingTabindex} util (counterpart to Focus Scope over `FocusTrap`),\n * giving the orientation / wrap / Home-End the util deliberately leaves out. No\n * dedicated APG pattern; it is the keyboard primitive Toolbar / Menu / Radio Group\n * and friends build on. Core (zero dependencies).\n *\n * Markup contract (identifier: `stimeo--roving`):\n * <div data-controller=\"stimeo--roving\"\n * data-stimeo--roving-orientation-value=\"horizontal\">\n * <button data-stimeo--roving-target=\"item\">A</button>\n * <button data-stimeo--roving-target=\"item\">B</button>\n * <button data-stimeo--roving-target=\"item\">C</button>\n * </div>\n *\n * Exactly one item is tabbable (`tabindex=\"0\"`); the arrow keys (per\n * `orientation`) move focus and that tab stop together, `Home`/`End` jump to the\n * ends (`homeEnd`), and `wrap` cycles past the ends or clamps at them. Listeners\n * are **delegated on the container** — `keydown` for movement and `focusin` to\n * sync the tab stop when focus arrives by click or programmatically — so\n * dynamically added/removed items need no per-item `data-action`. It emits\n * `change` whenever the tabbable item changes.\n *\n * @remarks\n * Behavior only: it owns `tabindex` and focus movement, nothing else. It does\n * **not** assign roles (`role=\"toolbar\"`/`\"radiogroup\"` is the author's), manage\n * selection / selection-follows-focus, typeahead, or activation (`Enter`/`Space`)\n * — those stay with the consuming pattern. `connect()` is idempotent: it keeps an\n * existing tab stop (reads it back from the DOM) and only defaults to the first\n * item when none is set, so a Turbo cache restore / morph never resets the user's\n * position. The delegated listeners are torn down on `disconnect()`.\n */\nexport class RovingController extends Controller<HTMLElement> {\n static override targets = [\"item\"];\n static override values = {\n orientation: { type: String, default: \"horizontal\" },\n wrap: { type: Boolean, default: true },\n homeEnd: { type: Boolean, default: true },\n };\n static events = [\"change\"] as const;\n\n declare readonly itemTargets: HTMLElement[];\n declare orientationValue: string;\n declare wrapValue: boolean;\n declare homeEndValue: boolean;\n\n readonly #roving = new RovingTabindex(() => this.itemTargets);\n\n override connect(): void {\n // Establish the single tab stop from the DOM (source of truth): keep an\n // existing tabbable item, else default to the first. Silent — no change event\n // for the initial mount.\n const active = this.#roving.activeIndex;\n this.#roving.setActive(active === -1 ? 0 : active);\n this.element.addEventListener(\"keydown\", this.#onKeydown);\n this.element.addEventListener(\"focusin\", this.#onFocusin);\n }\n\n override disconnect(): void {\n this.element.removeEventListener(\"keydown\", this.#onKeydown);\n this.element.removeEventListener(\"focusin\", this.#onFocusin);\n }\n\n /** Arrow keys move focus + the tab stop; Home/End jump to the ends. */\n readonly #onKeydown = (event: KeyboardEvent): void => {\n // A descendant widget that already claimed the key (e.g. a grabbed\n // `stimeo--pointer-drag` handle consuming arrows to move an item) must not\n // ALSO move the roving focus — composition depends on this yield.\n if (event.defaultPrevented) return;\n if (isReservedArrowChord(event)) return;\n const items = this.itemTargets;\n const current = this.#indexOf(event.target);\n if (current === -1) return;\n\n const length = items.length;\n const wrap: RovingWrap = this.wrapValue ? \"wrap\" : \"clamp\";\n const orientation = this.orientationValue;\n const horizontal = orientation === \"horizontal\" || orientation === \"both\";\n const vertical = orientation === \"vertical\" || orientation === \"both\";\n\n // Logical, not physical. APG defines these as \"next / previous\n // control\", and says a vertical arrangement swaps in Down/Up for the same\n // meaning — so the pair is one axis's spelling of an order, and the order\n // reverses with the writing direction. Read from the controller element: the\n // container is what lays the items out, and a child may carry its own `dir`\n // (an LTR input inside an RTL form is ordinary authoring).\n // Only the horizontal pair reverses; `orientation=\"both\"` keeps Down/Up as-is.\n const rtl = horizontal && isRtl(this.element);\n const forwardKey = rtl ? \"ArrowLeft\" : \"ArrowRight\";\n const backwardKey = rtl ? \"ArrowRight\" : \"ArrowLeft\";\n\n let next: number;\n if ((horizontal && event.key === forwardKey) || (vertical && event.key === \"ArrowDown\")) {\n next = rovingMove(current, length, 1, wrap);\n } else if ((horizontal && event.key === backwardKey) || (vertical && event.key === \"ArrowUp\")) {\n next = rovingMove(current, length, -1, wrap);\n } else if (this.homeEndValue && event.key === \"Home\") {\n next = 0;\n } else if (this.homeEndValue && event.key === \"End\") {\n next = length - 1;\n } else {\n return;\n }\n\n event.preventDefault();\n this.#activate(next, true);\n };\n\n /**\n * Syncs the single tab stop to an item that received focus by other means\n * (click, programmatic `focus()`), so returning via Tab lands on it. The\n * keyboard path's own `focus()` re-enters here but is a no-op (index unchanged).\n */\n readonly #onFocusin = (event: FocusEvent): void => {\n const index = this.#indexOf(event.target);\n if (index !== -1) this.#activate(index, false);\n };\n\n /** Resolves the item index owning an event target (the item or a descendant). */\n #indexOf(target: EventTarget | null): number {\n const node = target as Node | null;\n if (!node) return -1;\n return this.itemTargets.findIndex((item) => item === node || item.contains(node));\n }\n\n /** Makes `index` the tab stop (optionally focusing it), emitting `change` once. */\n #activate(index: number, focus: boolean): void {\n const previous = this.#roving.activeIndex;\n this.#roving.setActive(index, { focus });\n if (index !== previous) {\n this.dispatch(\"change\", { detail: { index, item: this.itemTargets[index] } });\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/logical_scroll.ts","../../src/utils/arrow_step.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/roving_tabindex.ts","../../src/controllers/roving_controller.ts"],"names":[],"mappings":";;;;;AAiBO,SAAS,MAAM,OAAA,EAA2B;AAC/C,EAAA,OAAO,MAAA,CAAO,gBAAA,CAAiB,OAAO,CAAA,CAAE,SAAA,KAAc,KAAA;AACxD;;;AC4EO,SAAS,oBAAA,CACd,KAAA,EACA,KAAA,GAAkC,EAAC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sB;AAC7C,IAAA,MAAM,QAAA,GAAW,KAAK,OAAA,CAAQ,WAAA;AAC9B,IAAA,IAAA,CAAK,OAAA,CAAQ,SAAA,CAAU,KAAA,EAAO,EAAE,OAAO,CAAA;AACvC,IAAA,IAAI,UAAU,QAAA,EAAU;AACtB,MAAA,IAAA,CAAK,QAAA,CAAS,QAAA,EAAU,EAAE,MAAA,EAAQ,EAAE,KAAA,EAAO,IAAA,EAAM,IAAA,CAAK,WAAA,CAAY,KAAK,CAAA,EAAE,EAAG,CAAA;AAAA,IAC9E;AAAA,EACF;AAAA;AAAA,EAGA,cAAA,GAAuB;AACrB,IAAA,MAAM,MAAA,GAAS,KAAK,OAAA,CAAQ,WAAA;AAC5B,IAAA,IAAA,CAAK,OAAA,CAAQ,SAAA,CAAU,MAAA,KAAW,EAAA,GAAK,IAAI,MAAM,CAAA;AAAA,EACnD;AACF","file":"roving_controller.js","sourcesContent":["/** Normalized scroll position and maximum distance on one logical axis. */\nexport interface LogicalScrollMetrics {\n position: number;\n max: number;\n}\n\n/**\n * Whether horizontal scrolling on `element` follows right-to-left inline flow.\n *\n * Resolved from the **computed** `direction`, so the authoring contract is the\n * usual `dir=\"rtl\"` (or a stylesheet) on the element or any ancestor.\n *\n * Scope: horizontal writing modes. A vertical writing mode (`writing-mode:\n * vertical-rl`) also inverts the horizontal axis, which this check does not\n * model — vertical writing modes are out of scope for the scroll utilities\n * (their consumers describe axes as horizontal/vertical, not inline/block).\n */\nexport function isRtl(element: Element): boolean {\n return window.getComputedStyle(element).direction === \"rtl\";\n}\n\n/**\n * Returns scroll distance from the logical start edge.\n *\n * CSSOM View exposes standards-mode RTL horizontal offsets as `0` at the inline\n * start (right) and increasingly negative values toward the inline end (left).\n * The normalized position is always clamped to `[0, max]`, which also absorbs\n * Safari's elastic overscroll values.\n */\nexport function logicalScrollMetrics(\n element: HTMLElement,\n horizontal: boolean,\n): LogicalScrollMetrics {\n const max = Math.max(\n 0,\n horizontal\n ? element.scrollWidth - element.clientWidth\n : element.scrollHeight - element.clientHeight,\n );\n const raw = horizontal ? element.scrollLeft : element.scrollTop;\n const position = horizontal && isRtl(element) ? -raw : raw;\n return { position: Math.min(max, Math.max(0, position)), max };\n}\n\n/**\n * Converts a logical start/end delta to the physical value accepted by\n * `Element.scrollBy`.\n */\nexport function physicalScrollDelta(\n element: HTMLElement,\n horizontal: boolean,\n logicalDelta: number,\n): number {\n return horizontal && isRtl(element) ? -logicalDelta : logicalDelta;\n}\n","import { isRtl } from \"./logical_scroll\";\n\n/**\n * Turns an arrow key into a **logical** step: `+1` for \"next\", `-1` for\n * \"previous\", `0` when the key names neither.\n *\n * APG defines the horizontal pair as *next / previous* and says a vertical\n * arrangement swaps in Down/Up for the same meaning — so the pair is one axis's\n * spelling of an order, and the order reverses with the writing direction. Only\n * the horizontal pair reverses. Down/Up name an axis the writing direction does\n * not mirror, and returning them unchanged is the point: many controllers fold\n * both pairs into one branch, where swapping the branches under RTL would flip\n * the vertical axis too — a bug that reads as \"the arrows work\" until someone\n * presses Down.\n *\n * **Direction is read from the element the caller passes, which should be the\n * container that lays the items out** — not the focused child. A child may carry\n * its own `dir` (an LTR input inside an RTL form is ordinary authoring), and\n * probing per handler makes two handlers disagree at the boundary between them.\n *\n * This decides direction only. Whether the axis is even active (an\n * `orientation=\"horizontal\"` widget ignoring Down/Up), how far the step lands,\n * and what wrapping does all stay with the caller.\n *\n * **It encodes the list-order convention: `ArrowDown` is *next*.** Widgets that\n * pair the arrows by *value* instead — `ArrowUp` meaning \"more\", as a rating or a\n * slider does — must not use this, or their vertical axis inverts. Reverse the\n * horizontal pair on its own there.\n *\n * @example\n * ```ts\n * const step = logicalArrowStep(event.key, this.element);\n * if (step === 0) return;\n * this.#roving.setActive(rovingMove(current, length, step, \"wrap\"), { focus: true });\n * ```\n */\nexport function logicalArrowStep(key: string, element: Element): 1 | -1 | 0 {\n if (key === \"ArrowDown\") return 1;\n if (key === \"ArrowUp\") return -1;\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return 0;\n const forward = isRtl(element) ? \"ArrowLeft\" : \"ArrowRight\";\n return key === forward ? 1 : -1;\n}\n\n/**\n * Rewrites `key` so an existing LTR-shaped branch keeps working under RTL:\n * `ArrowRight` and `ArrowLeft` trade places, everything else passes through.\n *\n * The alternative — negating a delta — silently breaks handlers whose two\n * horizontal branches are **not mirror images**. A grid that clamps one edge but\n * not the other, or a segmented field guarding `index > 0` on one side and\n * `index < length - 1` on the other, ends up applying the wrong guard to the\n * wrong direction. Swapping the key leaves each branch, guards and all, exactly\n * where its author put it.\n *\n * Same rule as {@link logicalArrowStep} about which element to read: pass the\n * container that lays the items out, not the focused child.\n *\n * @example\n * ```ts\n * switch (logicalArrowKey(event.key, this.element)) {\n * case \"ArrowLeft\": // \"previous\" — whatever direction that is on screen\n * ```\n */\nexport function logicalArrowKey(key: string, element: Element): string {\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return key;\n if (!isRtl(element)) return key;\n return key === \"ArrowRight\" ? \"ArrowLeft\" : \"ArrowRight\";\n}\n\n/** Modifiers a widget may claim on an arrow key, named for the `allow` list. */\nexport type ArrowModifier = \"alt\" | \"ctrl\" | \"meta\" | \"shift\";\n\n/**\n * True when an arrow key arrived carrying a modifier the widget must leave to\n * the browser: return without calling `preventDefault()` and without moving any\n * state.\n *\n * A bare arrow belongs to the widget; a chorded one usually does not.\n * `Alt`/`Meta` plus a horizontal arrow is history back/forward on every desktop\n * browser, and a widget that swallows it makes the shortcut work or not\n * depending on where focus happens to sit — a coin-flip the user cannot see.\n *\n * `allow` is for the combinations APG assigns to a pattern **and the widget\n * actually implements** — today only Combobox's optional `Alt+Down`/`Alt+Up`.\n * Listing one the widget does not implement defeats the point: the chord then\n * runs the plain-arrow branch, which is exactly what this guard exists to stop.\n * Non-arrow keys return `false`, so chorded letters and\n * `Control+Home`/`Control+End` are untouched.\n *\n * @example\n * ```ts\n * if (isReservedArrowChord(event)) return;\n * ```\n */\nexport function isReservedArrowChord(\n event: KeyboardEvent,\n allow: readonly ArrowModifier[] = [],\n): boolean {\n if (!event.key.startsWith(\"Arrow\")) return false;\n return (\n (event.altKey && !allow.includes(\"alt\")) ||\n (event.ctrlKey && !allow.includes(\"ctrl\")) ||\n (event.metaKey && !allow.includes(\"meta\")) ||\n (event.shiftKey && !allow.includes(\"shift\"))\n );\n}\n","/**\n * Collapses many Stimulus lifecycle callbacks from one DOM mutation into a\n * single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element and\n * `<name>ValueChanged` once per changed attribute. Replacing a list of N options\n * or morphing several render Values therefore delivers N callbacks — but the\n * useful unit of work is \"reconcile against the resulting declarative input\",\n * once, after the batch has settled. Every controller with reconcilable targets\n * or render Values needs the same shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers initial target and Value callbacks\n * ahead of `connect()`. Reconciling there would compute output against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\n });\n }\n}\n","/**\n * Low-level roving-tabindex primitive shared by composite-widget controllers.\n *\n * The APG roving-tabindex pattern keeps a composite widget a single Tab stop:\n * exactly one item is in the Tab sequence (`tabindex=\"0\"`) while the rest are\n * removed from it (`tabindex=\"-1\"`), and the arrow keys move both DOM focus and\n * that single tabbable position together. {@link RovingTabindex} owns *only* that\n * mechanical bookkeeping — \"which one item is tabbable, and move focus there\".\n *\n * It is intentionally **policy-free**. Orientation, wrapping vs. clamping,\n * selection-follows-focus, typeahead, and `Home`/`End` semantics differ per APG\n * pattern (Radio Group, Toolbar, Rating, …); folding them into one helper would\n * flatten those widgets to a lowest common denominator and lose each pattern's\n * correctness. Those decisions therefore stay in each controller, which calls\n * {@link RovingTabindex.setActive} with an index it computed itself (optionally\n * via the pure {@link rovingMove} helper).\n *\n * @remarks\n * Items are read lazily through a getter so a controller can add or remove\n * targets (Stimulus re-scans the DOM) without re-wiring this helper. A caller\n * that already captured one event-scoped snapshot may pass it to\n * {@link RovingTabindex.setActive}, avoiding a second live-target scan while\n * preserving one coherent collection for the whole operation.\n */\nexport class RovingTabindex {\n /** Returns the current ordered item elements; called on every operation. */\n readonly #getItems: () => HTMLElement[];\n\n /**\n * @param getItems - Returns the current ordered item elements. Called on every\n * operation so the live target list is always used.\n */\n constructor(getItems: () => HTMLElement[]) {\n this.#getItems = getItems;\n }\n\n /** Index of the currently tabbable item (`tabindex=\"0\"`), or `-1` if none. */\n get activeIndex(): number {\n return this.#getItems().findIndex((item) => item.tabIndex === 0);\n }\n\n /**\n * Makes exactly the item at `index` tabbable (`tabindex=\"0\"`) and removes every\n * other item from the Tab sequence (`tabindex=\"-1\"`). An out-of-range `index`\n * (e.g. `-1`) leaves all items at `-1`, which a controller can use to express\n * \"nothing is currently tabbable\".\n *\n * @param index - Position of the item to make tabbable.\n * @param options - Pass `{ focus: true }` to also move DOM focus to that item,\n * and `items` to reuse an event-scoped collection snapshot.\n */\n setActive(\n index: number,\n options: { focus?: boolean; items?: readonly HTMLElement[] } = {},\n ): void {\n const { focus = false } = options;\n const items = options.items ?? this.#getItems();\n items.forEach((item, i) => {\n item.tabIndex = i === index ? 0 : -1;\n });\n if (focus) items[index]?.focus();\n }\n}\n\n/** Edge behavior for {@link rovingMove}: cycle past the ends, or stop at them. */\nexport type RovingWrap = \"wrap\" | \"clamp\";\n\n/**\n * Pure helper that resolves the target index for a one-step directional move.\n *\n * Keyboard/orientation mapping stays in the caller: it decides that a key means\n * `delta` `+1` (next) or `-1` (previous) and whether the widget should `\"wrap\"`\n * (Radio Group, Toolbar) or `\"clamp\"` at the ends.\n *\n * @param current - The index focus is moving from.\n * @param length - Number of items in the set.\n * @param delta - `+1` to move to the next item, `-1` for the previous.\n * @param wrap - `\"wrap\"` cycles around the ends; `\"clamp\"` stops at them.\n * @returns The resolved index, or `-1` when there are no items.\n */\nexport function rovingMove(\n current: number,\n length: number,\n delta: number,\n wrap: RovingWrap,\n): number {\n if (length === 0) return -1;\n const next = current + delta;\n if (wrap === \"wrap\") return (next + length) % length;\n return Math.min(length - 1, Math.max(0, next));\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\nimport { isRtl } from \"../utils/logical_scroll\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\nimport { RovingTabindex, type RovingWrap, rovingMove } from \"../utils/roving_tabindex\";\n\n/**\n * Headless **roving tabindex**: makes a set of `item`s a single Tab stop and\n * moves focus between them with the arrow keys — the APG roving-tabindex\n * technique, surfaced as a standalone controller. It is the policy layer over the\n * shared {@link RovingTabindex} util (counterpart to Focus Scope over `FocusTrap`),\n * giving the orientation / wrap / Home-End the util deliberately leaves out. No\n * dedicated APG pattern; it is the keyboard primitive Toolbar / Menu / Radio Group\n * and friends build on. Core (zero dependencies).\n *\n * Markup contract (identifier: `stimeo--roving`):\n * <div data-controller=\"stimeo--roving\"\n * data-stimeo--roving-orientation-value=\"horizontal\">\n * <button data-stimeo--roving-target=\"item\">A</button>\n * <button data-stimeo--roving-target=\"item\">B</button>\n * <button data-stimeo--roving-target=\"item\">C</button>\n * </div>\n *\n * Exactly one item is tabbable (`tabindex=\"0\"`); the arrow keys (per\n * `orientation`) move focus and that tab stop together, `Home`/`End` jump to the\n * ends (`homeEnd`), and `wrap` cycles past the ends or clamps at them. Listeners\n * are **delegated on the container** — `keydown` for movement and `focusin` to\n * sync the tab stop when focus arrives by click or programmatically — so\n * dynamically added/removed items need no per-item `data-action`. It emits\n * `change` whenever the tabbable item changes.\n *\n * @remarks\n * Behavior only: it owns `tabindex` and focus movement, nothing else. It does\n * **not** assign roles (`role=\"toolbar\"`/`\"radiogroup\"` is the author's), manage\n * selection / selection-follows-focus, typeahead, or activation (`Enter`/`Space`)\n * — those stay with the consuming pattern. `connect()` is idempotent: it keeps an\n * existing tab stop (reads it back from the DOM) and only defaults to the first\n * item when none is set, so a Turbo cache restore / morph never resets the user's\n * position. The delegated listeners are torn down on `disconnect()`.\n */\nexport class RovingController extends Controller<HTMLElement> {\n static override targets = [\"item\"];\n static override values = {\n orientation: { type: String, default: \"horizontal\" },\n wrap: { type: Boolean, default: true },\n homeEnd: { type: Boolean, default: true },\n };\n static events = [\"change\"] as const;\n\n declare readonly itemTargets: HTMLElement[];\n declare orientationValue: string;\n declare wrapValue: boolean;\n declare homeEndValue: boolean;\n\n readonly #roving = new RovingTabindex(() => this.itemTargets);\n readonly #reconcile = new MicrotaskCoalescer(() => this.#ensureTabStop());\n #connected = false;\n\n override connect(): void {\n // Establish the single tab stop from the DOM (source of truth): keep an\n // existing tabbable item, else default to the first. Silent — no change event\n // for the initial mount.\n this.#ensureTabStop();\n this.element.addEventListener(\"keydown\", this.#onKeydown);\n this.element.addEventListener(\"focusin\", this.#onFocusin);\n this.#connected = true;\n this.#reconcile.activate();\n }\n\n override disconnect(): void {\n this.#connected = false;\n this.#reconcile.cancel();\n this.element.removeEventListener(\"keydown\", this.#onKeydown);\n this.element.removeEventListener(\"focusin\", this.#onFocusin);\n }\n\n /** Drops a runtime-added item from the Tab sequence before batch reconciliation. */\n itemTargetConnected(item: HTMLElement): void {\n if (!this.#connected) return;\n item.tabIndex = -1;\n this.#reconcile.schedule();\n }\n\n /** Re-establishes the single Tab stop after an item leaves the target set. */\n itemTargetDisconnected(): void {\n this.#reconcile.schedule();\n }\n\n /** Arrow keys move focus + the tab stop; Home/End jump to the ends. */\n readonly #onKeydown = (event: KeyboardEvent): void => {\n // A descendant widget that already claimed the key (e.g. a grabbed\n // `stimeo--pointer-drag` handle consuming arrows to move an item) must not\n // ALSO move the roving focus — composition depends on this yield.\n if (event.defaultPrevented) return;\n if (isReservedArrowChord(event)) return;\n const items = this.itemTargets;\n const current = this.#indexOf(event.target);\n if (current === -1) return;\n\n const length = items.length;\n const wrap: RovingWrap = this.wrapValue ? \"wrap\" : \"clamp\";\n const orientation = this.orientationValue;\n const horizontal = orientation === \"horizontal\" || orientation === \"both\";\n const vertical = orientation === \"vertical\" || orientation === \"both\";\n\n // Logical, not physical. APG defines these as \"next / previous\n // control\", and says a vertical arrangement swaps in Down/Up for the same\n // meaning — so the pair is one axis's spelling of an order, and the order\n // reverses with the writing direction. Read from the controller element: the\n // container is what lays the items out, and a child may carry its own `dir`\n // (an LTR input inside an RTL form is ordinary authoring).\n // Only the horizontal pair reverses; `orientation=\"both\"` keeps Down/Up as-is.\n const rtl = horizontal && isRtl(this.element);\n const forwardKey = rtl ? \"ArrowLeft\" : \"ArrowRight\";\n const backwardKey = rtl ? \"ArrowRight\" : \"ArrowLeft\";\n\n let next: number;\n if ((horizontal && event.key === forwardKey) || (vertical && event.key === \"ArrowDown\")) {\n next = rovingMove(current, length, 1, wrap);\n } else if ((horizontal && event.key === backwardKey) || (vertical && event.key === \"ArrowUp\")) {\n next = rovingMove(current, length, -1, wrap);\n } else if (this.homeEndValue && event.key === \"Home\") {\n next = 0;\n } else if (this.homeEndValue && event.key === \"End\") {\n next = length - 1;\n } else {\n return;\n }\n\n event.preventDefault();\n this.#activate(next, true);\n };\n\n /**\n * Syncs the single tab stop to an item that received focus by other means\n * (click, programmatic `focus()`), so returning via Tab lands on it. The\n * keyboard path's own `focus()` re-enters here but is a no-op (index unchanged).\n */\n readonly #onFocusin = (event: FocusEvent): void => {\n const index = this.#indexOf(event.target);\n if (index !== -1) this.#activate(index, false);\n };\n\n /** Resolves the item index owning an event target (the item or a descendant). */\n #indexOf(target: EventTarget | null): number {\n const node = target as Node | null;\n if (!node) return -1;\n return this.itemTargets.findIndex((item) => item === node || item.contains(node));\n }\n\n /** Makes `index` the tab stop (optionally focusing it), emitting `change` once. */\n #activate(index: number, focus: boolean): void {\n const previous = this.#roving.activeIndex;\n this.#roving.setActive(index, { focus });\n if (index !== previous) {\n this.dispatch(\"change\", { detail: { index, item: this.itemTargets[index] } });\n }\n }\n\n /** Keeps the first existing Tab stop, falling back to the first live item. */\n #ensureTabStop(): void {\n const active = this.#roving.activeIndex;\n this.#roving.setActive(active === -1 ? 0 : active);\n }\n}\n"]}
@@ -17,11 +17,13 @@ import { Controller } from '@hotwired/stimulus';
17
17
  * own, the viewport is made keyboard-scrollable (`tabindex="0"`, plus `role="region"`
18
18
  * when it already has an accessible name). Scroll position is published as
19
19
  * `data-scroll` (`start`/`middle`/`end`), overflow as `data-overflow`, and progress
20
- * as `--stimeo-scroll-progress` (0–1) so consumer CSS can draw scroll shadows.
20
+ * as `--stimeo--scroll-progress` (0–1) so consumer CSS can draw scroll shadows.
21
21
  *
22
22
  * @remarks
23
23
  * Behavior only. The `scroll` listener and {@link LayoutObserver} (element +
24
24
  * viewport resize) are torn down on `disconnect()` (Turbo navigation included).
25
+ * Runtime replacement of the viewport rebinds those resources and the content
26
+ * observer as one lifecycle unit.
25
27
  * `role="region"` is added only when the viewport is already named, so a scrollable
26
28
  * region never becomes an unlabeled landmark.
27
29
  */
@@ -39,6 +41,10 @@ declare class ScrollAreaController extends Controller<HTMLElement> {
39
41
  readonly hasViewportTarget: boolean;
40
42
  orientationValue: string;
41
43
  connect(): void;
44
+ /** Schedules a complete observer/listener rebind for a runtime viewport target. */
45
+ viewportTargetConnected(): void;
46
+ /** Schedules cleanup or replacement binding after a viewport leaves. */
47
+ viewportTargetDisconnected(): void;
42
48
  disconnect(): void;
43
49
  }
44
50
 
@@ -2,6 +2,43 @@ import { Controller } from '@hotwired/stimulus';
2
2
 
3
3
  // src/controllers/scroll_area_controller.ts
4
4
 
5
+ // src/utils/attribute_lease.ts
6
+ var AttributeLease = class {
7
+ #attribute;
8
+ #records = /* @__PURE__ */ new Map();
9
+ /** @param attribute - The attribute whose temporary values this lease owns. */
10
+ constructor(attribute) {
11
+ this.#attribute = attribute;
12
+ }
13
+ /** Writes or removes the leased attribute while preserving its authored value. */
14
+ write(element, value) {
15
+ const existing = this.#records.get(element);
16
+ if (existing) {
17
+ existing.written = value;
18
+ } else {
19
+ this.#records.set(element, {
20
+ original: element.getAttribute(this.#attribute),
21
+ written: value
22
+ });
23
+ }
24
+ if (value === null) element.removeAttribute(this.#attribute);
25
+ else element.setAttribute(this.#attribute, value);
26
+ }
27
+ /** Returns one lease without overwriting a value subsequently authored by a consumer. */
28
+ return(element) {
29
+ const record = this.#records.get(element);
30
+ if (!record) return;
31
+ this.#records.delete(element);
32
+ if (element.getAttribute(this.#attribute) !== record.written) return;
33
+ if (record.original === null) element.removeAttribute(this.#attribute);
34
+ else element.setAttribute(this.#attribute, record.original);
35
+ }
36
+ /** Returns every outstanding lease using the same ownership check as {@link return}. */
37
+ returnAll() {
38
+ for (const element of Array.from(this.#records.keys())) this.return(element);
39
+ }
40
+ };
41
+
5
42
  // src/utils/layout_observer.ts
6
43
  var LayoutObserver = class {
7
44
  #callback;
@@ -72,10 +109,74 @@ function logicalScrollMetrics(element, horizontal) {
72
109
  return { position: Math.min(max, Math.max(0, position)), max };
73
110
  }
74
111
 
112
+ // src/utils/microtask_coalescer.ts
113
+ var MicrotaskCoalescer = class {
114
+ #run;
115
+ #queued = false;
116
+ #active = false;
117
+ #generation = 0;
118
+ /** @param run - the single reconciliation pass, invoked at most once per batch. */
119
+ constructor(run) {
120
+ this.#run = run;
121
+ }
122
+ /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */
123
+ activate() {
124
+ this.#active = true;
125
+ }
126
+ /** Closes the window and drops any pending pass; call from `disconnect()`. */
127
+ cancel() {
128
+ this.#active = false;
129
+ this.#queued = false;
130
+ this.#generation += 1;
131
+ }
132
+ /** Requests one pass after the batch settles. Idempotent; inert outside the window. */
133
+ schedule() {
134
+ if (!this.#active || this.#queued) return;
135
+ this.#queued = true;
136
+ const generation = this.#generation;
137
+ queueMicrotask(() => {
138
+ if (generation !== this.#generation || !this.#queued || !this.#active) return;
139
+ this.#queued = false;
140
+ this.#run();
141
+ });
142
+ }
143
+ };
144
+
145
+ // src/utils/before_cache_reset.ts
146
+ var BeforeCacheReset = class _BeforeCacheReset {
147
+ /** Every subscribed instance, iterated by the one shared document listener. */
148
+ static #subscribers = /* @__PURE__ */ new Set();
149
+ /** The shared listener; installed while at least one instance is subscribed. */
150
+ static #onBeforeCache = () => {
151
+ for (const subscriber of _BeforeCacheReset.#subscribers) subscriber.#rewind();
152
+ };
153
+ #rewind;
154
+ /** @param rewind - the pass that returns this controller's state to its initial form. */
155
+ constructor(rewind) {
156
+ this.#rewind = rewind;
157
+ }
158
+ /** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */
159
+ activate() {
160
+ const first = _BeforeCacheReset.#subscribers.size === 0;
161
+ _BeforeCacheReset.#subscribers.add(this);
162
+ if (first) {
163
+ document.addEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
164
+ }
165
+ }
166
+ /** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */
167
+ deactivate() {
168
+ _BeforeCacheReset.#subscribers.delete(this);
169
+ if (_BeforeCacheReset.#subscribers.size > 0) return;
170
+ document.removeEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
171
+ }
172
+ };
173
+
75
174
  // src/utils/tabindex_loan.ts
76
175
  var TabindexLoan = class {
77
176
  #value;
78
177
  #lent = /* @__PURE__ */ new Set();
178
+ /** Returns live loans before Turbo can copy them into its page snapshot. */
179
+ #beforeCache = new BeforeCacheReset(() => this.returnAll());
79
180
  /**
80
181
  * @param value - the `tabindex` to lend. `"-1"` (the default) is
81
182
  * programmatically focusable but not a Tab stop; `"0"` is a real Tab stop,
@@ -89,6 +190,7 @@ var TabindexLoan = class {
89
190
  if (element.hasAttribute("tabindex")) return;
90
191
  element.setAttribute("tabindex", this.#value);
91
192
  this.#lent.add(element);
193
+ this.#beforeCache.activate();
92
194
  }
93
195
  /** Takes back every loan whose value is still the one that was lent. */
94
196
  returnAll() {
@@ -96,6 +198,7 @@ var TabindexLoan = class {
96
198
  if (element.getAttribute("tabindex") === this.#value) element.removeAttribute("tabindex");
97
199
  }
98
200
  this.#lent.clear();
201
+ this.#beforeCache.deactivate();
99
202
  }
100
203
  };
101
204
 
@@ -117,29 +220,56 @@ var ScrollAreaController = class extends Controller {
117
220
  };
118
221
  static events = ["reach"];
119
222
  #layout = new LayoutObserver(() => this.#update());
223
+ /** Current element receiving scroll, resize, mutation, and keyboard-reach behavior. */
224
+ #viewport = null;
225
+ /** Guards target callbacks before connect and after disconnect. */
226
+ #connected = false;
227
+ /** Collapses target replacement callbacks into one final-DOM rebind. */
228
+ #rebind = new MicrotaskCoalescer(() => this.#syncViewport());
120
229
  /** Re-checks the tab stop when the viewport's focusable content comes or goes. */
121
230
  #content = null;
122
231
  /** Last edge reported via `reach`, so the event fires once per arrival. */
123
232
  #lastEdge = null;
124
233
  /** Whether this controller added `tabindex`, so teardown only removes its own. */
125
234
  #tabindex = new TabindexLoan("0");
126
- /** Whether this controller added `role="region"`, for symmetric teardown. */
127
- #addedRole = false;
235
+ /** Temporarily owns a derived `role="region"` without losing an authored replacement. */
236
+ #role = new AttributeLease("role");
128
237
  #onScroll = () => {
129
238
  this.#update();
130
239
  };
131
240
  connect() {
132
- if (!this.hasViewportTarget) return;
133
- this.viewportTarget.addEventListener("scroll", this.#onScroll, { passive: true });
134
- this.#layout.observe(this.viewportTarget);
241
+ this.#connected = true;
242
+ this.#rebind.activate();
135
243
  this.#layout.observeViewport();
244
+ this.#syncViewport();
245
+ }
246
+ /** Schedules a complete observer/listener rebind for a runtime viewport target. */
247
+ viewportTargetConnected() {
248
+ this.#rebind.schedule();
249
+ }
250
+ /** Schedules cleanup or replacement binding after a viewport leaves. */
251
+ viewportTargetDisconnected() {
252
+ this.#rebind.schedule();
253
+ }
254
+ /** Rebinds every viewport-owned resource against the final target in this mutation batch. */
255
+ #syncViewport() {
256
+ if (!this.#connected) return;
257
+ const next = this.hasViewportTarget ? this.viewportTarget : null;
258
+ if (next === this.#viewport) {
259
+ this.#update();
260
+ return;
261
+ }
262
+ if (this.#viewport) this.#unbindViewport(this.#viewport);
263
+ this.#viewport = next;
264
+ if (!next) return;
265
+ next.addEventListener("scroll", this.#onScroll, { passive: true });
266
+ this.#layout.observe(next);
136
267
  if (typeof MutationObserver !== "undefined") {
137
268
  this.#content = new MutationObserver(() => {
138
- if (!this.hasViewportTarget) return;
139
- const vp = this.viewportTarget;
140
- this.#syncKeyboardReach(vp, this.#syncOverflow(vp));
269
+ if (this.#viewport !== next) return;
270
+ this.#syncKeyboardReach(next, this.#syncOverflow(next));
141
271
  });
142
- this.#content.observe(this.viewportTarget, {
272
+ this.#content.observe(next, {
143
273
  subtree: true,
144
274
  childList: true,
145
275
  attributes: true
@@ -148,24 +278,31 @@ var ScrollAreaController = class extends Controller {
148
278
  this.#update();
149
279
  }
150
280
  disconnect() {
151
- if (this.hasViewportTarget) {
152
- this.viewportTarget.removeEventListener("scroll", this.#onScroll);
153
- this.#clearAddedAttributes(this.viewportTarget);
154
- }
281
+ this.#connected = false;
282
+ this.#rebind.cancel();
283
+ if (this.#viewport) this.#unbindViewport(this.#viewport);
155
284
  this.#layout.disconnect();
285
+ this.#lastEdge = null;
286
+ }
287
+ /** Releases every resource and derived attribute owned by one former viewport. */
288
+ #unbindViewport(viewport) {
289
+ viewport.removeEventListener("scroll", this.#onScroll);
290
+ this.#layout.unobserve(viewport);
156
291
  this.#content?.disconnect();
157
292
  this.#content = null;
293
+ this.#clearAddedAttributes(viewport);
294
+ if (this.#viewport === viewport) this.#viewport = null;
158
295
  this.#lastEdge = null;
159
296
  }
160
297
  /** Re-measures overflow and scroll position and reflects the state hooks. */
161
298
  #update() {
162
- if (!this.hasViewportTarget) return;
163
- const vp = this.viewportTarget;
299
+ const vp = this.#viewport;
300
+ if (!vp) return;
164
301
  const overflowing = this.#syncOverflow(vp);
165
302
  this.#syncKeyboardReach(vp, overflowing);
166
303
  const { position, progress } = this.#measurePosition(vp);
167
304
  this.element.setAttribute("data-scroll", position);
168
- this.element.style.setProperty("--stimeo-scroll-progress", String(progress));
305
+ this.element.style.setProperty("--stimeo--scroll-progress", String(progress));
169
306
  const edge = position === "start" ? "start" : position === "end" ? "end" : null;
170
307
  if (overflowing && edge && edge !== this.#lastEdge) {
171
308
  this.#lastEdge = edge;
@@ -174,7 +311,6 @@ var ScrollAreaController = class extends Controller {
174
311
  this.#lastEdge = null;
175
312
  }
176
313
  }
177
- /** Whether the viewport can scroll on the configured axis. */
178
314
  /**
179
315
  * Measures overflow and reflects the `data-overflow` hook.
180
316
  *
@@ -219,8 +355,7 @@ var ScrollAreaController = class extends Controller {
219
355
  if (wantsTabindex) {
220
356
  this.#tabindex.lend(vp);
221
357
  if (!vp.hasAttribute("role") && this.#hasAccessibleName(vp)) {
222
- vp.setAttribute("role", "region");
223
- this.#addedRole = true;
358
+ this.#role.write(vp, "region");
224
359
  }
225
360
  } else {
226
361
  this.#clearAddedAttributes(vp);
@@ -229,10 +364,7 @@ var ScrollAreaController = class extends Controller {
229
364
  /** Removes (and resets the flags for) only the attributes this controller added. */
230
365
  #clearAddedAttributes(vp) {
231
366
  this.#tabindex.returnAll();
232
- if (this.#addedRole) {
233
- vp.removeAttribute("role");
234
- this.#addedRole = false;
235
- }
367
+ this.#role.return(vp);
236
368
  }
237
369
  /**
238
370
  * Whether the viewport owns something the user can Tab to *right now*.