stimeo-ui 0.15.0 → 0.16.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 (267) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/README.md +120 -0
  3. package/dist/cable/index.js +63 -15
  4. package/dist/cable/index.js.map +1 -1
  5. package/dist/controllers/accordion_controller.d.ts +30 -3
  6. package/dist/controllers/accordion_controller.js +98 -9
  7. package/dist/controllers/accordion_controller.js.map +1 -1
  8. package/dist/controllers/alert_dialog_controller.d.ts +8 -7
  9. package/dist/controllers/alert_dialog_controller.js.map +1 -1
  10. package/dist/controllers/announcer_controller.d.ts +3 -2
  11. package/dist/controllers/announcer_controller.js +8 -1
  12. package/dist/controllers/announcer_controller.js.map +1 -1
  13. package/dist/controllers/auto_submit_controller.js +43 -2
  14. package/dist/controllers/auto_submit_controller.js.map +1 -1
  15. package/dist/controllers/avatar_controller.js +1 -1
  16. package/dist/controllers/avatar_controller.js.map +1 -1
  17. package/dist/controllers/breadcrumb_controller.d.ts +10 -7
  18. package/dist/controllers/breadcrumb_controller.js +9 -8
  19. package/dist/controllers/breadcrumb_controller.js.map +1 -1
  20. package/dist/controllers/bulk_select_controller.d.ts +4 -4
  21. package/dist/controllers/bulk_select_controller.js +7 -6
  22. package/dist/controllers/bulk_select_controller.js.map +1 -1
  23. package/dist/controllers/calendar_controller.d.ts +85 -23
  24. package/dist/controllers/calendar_controller.js +323 -123
  25. package/dist/controllers/calendar_controller.js.map +1 -1
  26. package/dist/controllers/carousel_controller.d.ts +67 -22
  27. package/dist/controllers/carousel_controller.js +263 -38
  28. package/dist/controllers/carousel_controller.js.map +1 -1
  29. package/dist/controllers/character_counter_controller.d.ts +1 -1
  30. package/dist/controllers/character_counter_controller.js +40 -2
  31. package/dist/controllers/character_counter_controller.js.map +1 -1
  32. package/dist/controllers/checkbox_controller.js +54 -10
  33. package/dist/controllers/checkbox_controller.js.map +1 -1
  34. package/dist/controllers/clipboard_controller.d.ts +28 -2
  35. package/dist/controllers/clipboard_controller.js +63 -5
  36. package/dist/controllers/clipboard_controller.js.map +1 -1
  37. package/dist/controllers/collapsible_controller.d.ts +25 -1
  38. package/dist/controllers/collapsible_controller.js +99 -14
  39. package/dist/controllers/collapsible_controller.js.map +1 -1
  40. package/dist/controllers/color_picker_controller.d.ts +29 -8
  41. package/dist/controllers/color_picker_controller.js +80 -34
  42. package/dist/controllers/color_picker_controller.js.map +1 -1
  43. package/dist/controllers/combobox_controller.d.ts +10 -1
  44. package/dist/controllers/combobox_controller.js +106 -16
  45. package/dist/controllers/combobox_controller.js.map +1 -1
  46. package/dist/controllers/command_palette_controller.d.ts +3 -3
  47. package/dist/controllers/command_palette_controller.js +35 -3
  48. package/dist/controllers/command_palette_controller.js.map +1 -1
  49. package/dist/controllers/conditional_fields_controller.js +56 -11
  50. package/dist/controllers/conditional_fields_controller.js.map +1 -1
  51. package/dist/controllers/confirm_controller.js +3 -0
  52. package/dist/controllers/confirm_controller.js.map +1 -1
  53. package/dist/controllers/context_menu_controller.d.ts +6 -0
  54. package/dist/controllers/context_menu_controller.js +32 -12
  55. package/dist/controllers/context_menu_controller.js.map +1 -1
  56. package/dist/controllers/countdown_controller.d.ts +30 -1
  57. package/dist/controllers/countdown_controller.js +129 -26
  58. package/dist/controllers/countdown_controller.js.map +1 -1
  59. package/dist/controllers/currency_input_controller.d.ts +74 -15
  60. package/dist/controllers/currency_input_controller.js +205 -58
  61. package/dist/controllers/currency_input_controller.js.map +1 -1
  62. package/dist/controllers/data_grid_controller.d.ts +63 -18
  63. package/dist/controllers/data_grid_controller.js +195 -29
  64. package/dist/controllers/data_grid_controller.js.map +1 -1
  65. package/dist/controllers/date_range_picker_controller.d.ts +34 -6
  66. package/dist/controllers/date_range_picker_controller.js +139 -27
  67. package/dist/controllers/date_range_picker_controller.js.map +1 -1
  68. package/dist/controllers/dialog_controller.d.ts +10 -3
  69. package/dist/controllers/dialog_controller.js +35 -8
  70. package/dist/controllers/dialog_controller.js.map +1 -1
  71. package/dist/controllers/direct_upload_controller.js +22 -4
  72. package/dist/controllers/direct_upload_controller.js.map +1 -1
  73. package/dist/controllers/dirty_form_controller.d.ts +2 -2
  74. package/dist/controllers/dirty_form_controller.js +14 -1
  75. package/dist/controllers/dirty_form_controller.js.map +1 -1
  76. package/dist/controllers/dismissible_controller.js +1 -0
  77. package/dist/controllers/dismissible_controller.js.map +1 -1
  78. package/dist/controllers/drawer_controller.d.ts +18 -10
  79. package/dist/controllers/drawer_controller.js +54 -19
  80. package/dist/controllers/drawer_controller.js.map +1 -1
  81. package/dist/controllers/dropdown_controller.d.ts +9 -3
  82. package/dist/controllers/dropdown_controller.js +36 -9
  83. package/dist/controllers/dropdown_controller.js.map +1 -1
  84. package/dist/controllers/editable_controller.js +34 -0
  85. package/dist/controllers/editable_controller.js.map +1 -1
  86. package/dist/controllers/file_dropzone_controller.js +144 -51
  87. package/dist/controllers/file_dropzone_controller.js.map +1 -1
  88. package/dist/controllers/filter_controller.d.ts +10 -4
  89. package/dist/controllers/filter_controller.js +20 -6
  90. package/dist/controllers/filter_controller.js.map +1 -1
  91. package/dist/controllers/flash_controller.d.ts +26 -6
  92. package/dist/controllers/flash_controller.js +305 -46
  93. package/dist/controllers/flash_controller.js.map +1 -1
  94. package/dist/controllers/focus_controller.js +1 -0
  95. package/dist/controllers/focus_controller.js.map +1 -1
  96. package/dist/controllers/form_field_controller.js +7 -5
  97. package/dist/controllers/form_field_controller.js.map +1 -1
  98. package/dist/controllers/form_validation_controller.js +19 -13
  99. package/dist/controllers/form_validation_controller.js.map +1 -1
  100. package/dist/controllers/frame_loading_controller.js +16 -2
  101. package/dist/controllers/frame_loading_controller.js.map +1 -1
  102. package/dist/controllers/highlight_controller.js +19 -2
  103. package/dist/controllers/highlight_controller.js.map +1 -1
  104. package/dist/controllers/hover_card_controller.d.ts +10 -2
  105. package/dist/controllers/hover_card_controller.js +40 -14
  106. package/dist/controllers/hover_card_controller.js.map +1 -1
  107. package/dist/controllers/idle_controller.d.ts +16 -3
  108. package/dist/controllers/idle_controller.js +90 -5
  109. package/dist/controllers/idle_controller.js.map +1 -1
  110. package/dist/controllers/input_mask_controller.d.ts +5 -2
  111. package/dist/controllers/input_mask_controller.js +65 -9
  112. package/dist/controllers/input_mask_controller.js.map +1 -1
  113. package/dist/controllers/intersection_controller.js +3 -0
  114. package/dist/controllers/intersection_controller.js.map +1 -1
  115. package/dist/controllers/lazy_frame_controller.js +11 -2
  116. package/dist/controllers/lazy_frame_controller.js.map +1 -1
  117. package/dist/controllers/listbox_controller.d.ts +50 -8
  118. package/dist/controllers/listbox_controller.js +203 -45
  119. package/dist/controllers/listbox_controller.js.map +1 -1
  120. package/dist/controllers/masonry_controller.js +0 -2
  121. package/dist/controllers/masonry_controller.js.map +1 -1
  122. package/dist/controllers/menu_controller.d.ts +9 -3
  123. package/dist/controllers/menu_controller.js +45 -16
  124. package/dist/controllers/menu_controller.js.map +1 -1
  125. package/dist/controllers/menubar_controller.d.ts +11 -0
  126. package/dist/controllers/menubar_controller.js +58 -24
  127. package/dist/controllers/menubar_controller.js.map +1 -1
  128. package/dist/controllers/meter_controller.js +9 -5
  129. package/dist/controllers/meter_controller.js.map +1 -1
  130. package/dist/controllers/multi_select_controller.d.ts +18 -3
  131. package/dist/controllers/multi_select_controller.js +278 -104
  132. package/dist/controllers/multi_select_controller.js.map +1 -1
  133. package/dist/controllers/navigation_menu_controller.d.ts +11 -0
  134. package/dist/controllers/navigation_menu_controller.js +48 -15
  135. package/dist/controllers/navigation_menu_controller.js.map +1 -1
  136. package/dist/controllers/nested_form_controller.js +37 -8
  137. package/dist/controllers/nested_form_controller.js.map +1 -1
  138. package/dist/controllers/network_status_controller.js +9 -1
  139. package/dist/controllers/network_status_controller.js.map +1 -1
  140. package/dist/controllers/number_input_controller.d.ts +36 -8
  141. package/dist/controllers/number_input_controller.js +124 -21
  142. package/dist/controllers/number_input_controller.js.map +1 -1
  143. package/dist/controllers/optimistic_controller.js +14 -1
  144. package/dist/controllers/optimistic_controller.js.map +1 -1
  145. package/dist/controllers/otp_controller.d.ts +22 -7
  146. package/dist/controllers/otp_controller.js +198 -55
  147. package/dist/controllers/otp_controller.js.map +1 -1
  148. package/dist/controllers/overflow_indicator_controller.d.ts +8 -12
  149. package/dist/controllers/overflow_indicator_controller.js +84 -13
  150. package/dist/controllers/overflow_indicator_controller.js.map +1 -1
  151. package/dist/controllers/overflow_menu_controller.d.ts +26 -6
  152. package/dist/controllers/overflow_menu_controller.js +112 -41
  153. package/dist/controllers/overflow_menu_controller.js.map +1 -1
  154. package/dist/controllers/pagination_controller.d.ts +19 -11
  155. package/dist/controllers/pagination_controller.js +74 -28
  156. package/dist/controllers/pagination_controller.js.map +1 -1
  157. package/dist/controllers/password_reveal_controller.d.ts +15 -1
  158. package/dist/controllers/password_reveal_controller.js +59 -2
  159. package/dist/controllers/password_reveal_controller.js.map +1 -1
  160. package/dist/controllers/persist_controller.js +30 -8
  161. package/dist/controllers/persist_controller.js.map +1 -1
  162. package/dist/controllers/pointer_drag_controller.js +131 -52
  163. package/dist/controllers/pointer_drag_controller.js.map +1 -1
  164. package/dist/controllers/popover_controller.d.ts +9 -3
  165. package/dist/controllers/popover_controller.js +45 -11
  166. package/dist/controllers/popover_controller.js.map +1 -1
  167. package/dist/controllers/portal_controller.d.ts +1 -1
  168. package/dist/controllers/portal_controller.js +6 -2
  169. package/dist/controllers/portal_controller.js.map +1 -1
  170. package/dist/controllers/preview_guard_controller.js +16 -1
  171. package/dist/controllers/preview_guard_controller.js.map +1 -1
  172. package/dist/controllers/progress_controller.js +8 -4
  173. package/dist/controllers/progress_controller.js.map +1 -1
  174. package/dist/controllers/radio_group_controller.d.ts +6 -4
  175. package/dist/controllers/radio_group_controller.js +42 -17
  176. package/dist/controllers/radio_group_controller.js.map +1 -1
  177. package/dist/controllers/range_slider_controller.d.ts +49 -1
  178. package/dist/controllers/range_slider_controller.js +88 -42
  179. package/dist/controllers/range_slider_controller.js.map +1 -1
  180. package/dist/controllers/rating_controller.d.ts +14 -3
  181. package/dist/controllers/rating_controller.js +39 -15
  182. package/dist/controllers/rating_controller.js.map +1 -1
  183. package/dist/controllers/read_more_controller.d.ts +24 -2
  184. package/dist/controllers/read_more_controller.js +69 -2
  185. package/dist/controllers/read_more_controller.js.map +1 -1
  186. package/dist/controllers/resizable_controller.d.ts +16 -2
  187. package/dist/controllers/resizable_controller.js +82 -22
  188. package/dist/controllers/resizable_controller.js.map +1 -1
  189. package/dist/controllers/scroll_area_controller.js +5 -1
  190. package/dist/controllers/scroll_area_controller.js.map +1 -1
  191. package/dist/controllers/scroll_visibility_controller.js +0 -1
  192. package/dist/controllers/scroll_visibility_controller.js.map +1 -1
  193. package/dist/controllers/scrollspy_controller.d.ts +3 -2
  194. package/dist/controllers/scrollspy_controller.js +6 -0
  195. package/dist/controllers/scrollspy_controller.js.map +1 -1
  196. package/dist/controllers/separator_controller.d.ts +41 -14
  197. package/dist/controllers/separator_controller.js +66 -37
  198. package/dist/controllers/separator_controller.js.map +1 -1
  199. package/dist/controllers/sidebar_controller.d.ts +20 -3
  200. package/dist/controllers/sidebar_controller.js +77 -18
  201. package/dist/controllers/sidebar_controller.js.map +1 -1
  202. package/dist/controllers/skeleton_controller.js +6 -1
  203. package/dist/controllers/skeleton_controller.js.map +1 -1
  204. package/dist/controllers/slider_controller.d.ts +45 -7
  205. package/dist/controllers/slider_controller.js +82 -47
  206. package/dist/controllers/slider_controller.js.map +1 -1
  207. package/dist/controllers/smart_sticky_header_controller.js +11 -1
  208. package/dist/controllers/smart_sticky_header_controller.js.map +1 -1
  209. package/dist/controllers/sortable_controller.js +17 -2
  210. package/dist/controllers/sortable_controller.js.map +1 -1
  211. package/dist/controllers/spinner_controller.js +10 -2
  212. package/dist/controllers/spinner_controller.js.map +1 -1
  213. package/dist/controllers/step_indicator_controller.d.ts +19 -17
  214. package/dist/controllers/step_indicator_controller.js +18 -17
  215. package/dist/controllers/step_indicator_controller.js.map +1 -1
  216. package/dist/controllers/stepper_controller.d.ts +34 -9
  217. package/dist/controllers/stepper_controller.js +101 -19
  218. package/dist/controllers/stepper_controller.js.map +1 -1
  219. package/dist/controllers/stick_to_bottom_controller.d.ts +19 -0
  220. package/dist/controllers/stick_to_bottom_controller.js +75 -5
  221. package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
  222. package/dist/controllers/submit_once_controller.d.ts +3 -2
  223. package/dist/controllers/submit_once_controller.js +16 -3
  224. package/dist/controllers/submit_once_controller.js.map +1 -1
  225. package/dist/controllers/switch_controller.d.ts +29 -7
  226. package/dist/controllers/switch_controller.js +101 -10
  227. package/dist/controllers/switch_controller.js.map +1 -1
  228. package/dist/controllers/tabs_controller.d.ts +12 -0
  229. package/dist/controllers/tabs_controller.js +21 -2
  230. package/dist/controllers/tabs_controller.js.map +1 -1
  231. package/dist/controllers/tags_input_controller.d.ts +15 -3
  232. package/dist/controllers/tags_input_controller.js +209 -59
  233. package/dist/controllers/tags_input_controller.js.map +1 -1
  234. package/dist/controllers/theme_controller.d.ts +20 -3
  235. package/dist/controllers/theme_controller.js +64 -14
  236. package/dist/controllers/theme_controller.js.map +1 -1
  237. package/dist/controllers/time_picker_controller.js +23 -8
  238. package/dist/controllers/time_picker_controller.js.map +1 -1
  239. package/dist/controllers/toast_controller.d.ts +52 -15
  240. package/dist/controllers/toast_controller.js +337 -54
  241. package/dist/controllers/toast_controller.js.map +1 -1
  242. package/dist/controllers/toggle_group_controller.d.ts +49 -7
  243. package/dist/controllers/toggle_group_controller.js +159 -23
  244. package/dist/controllers/toggle_group_controller.js.map +1 -1
  245. package/dist/controllers/toolbar_controller.js +32 -0
  246. package/dist/controllers/toolbar_controller.js.map +1 -1
  247. package/dist/controllers/tooltip_controller.d.ts +8 -0
  248. package/dist/controllers/tooltip_controller.js +39 -13
  249. package/dist/controllers/tooltip_controller.js.map +1 -1
  250. package/dist/controllers/transition_controller.js +4 -0
  251. package/dist/controllers/transition_controller.js.map +1 -1
  252. package/dist/controllers/tree_view_controller.d.ts +39 -8
  253. package/dist/controllers/tree_view_controller.js +169 -16
  254. package/dist/controllers/tree_view_controller.js.map +1 -1
  255. package/dist/index.d.ts +28 -1
  256. package/dist/index.js +4588 -1535
  257. package/dist/index.js.map +1 -1
  258. package/dist/inspector/cli.d.ts +72 -6
  259. package/dist/inspector/cli.js +262 -51
  260. package/dist/inspector/cli.js.map +1 -1
  261. package/dist/inspector/cli_bin.js +309 -51
  262. package/dist/inspector/cli_bin.js.map +1 -1
  263. package/dist/inspector/examples.json +40 -40
  264. package/dist/inspector/manifest.json +525 -59
  265. package/dist/positioning/index.js +2 -0
  266. package/dist/positioning/index.js.map +1 -1
  267. package/package.json +2 -2
@@ -29,6 +29,29 @@ function ownerOf(candidates, node) {
29
29
  return candidates[ownerIndex(candidates, node)] ?? null;
30
30
  }
31
31
 
32
+ // src/utils/field_mirror.ts
33
+ function writeFields(container, values, { name, form = "" }) {
34
+ const current = [...container.children];
35
+ const submits = current.length === values.length && current.every(
36
+ (child, index) => child instanceof HTMLInputElement && child.type === "hidden" && child.value === values[index] && child.name === name && (child.getAttribute("form") ?? "") === form
37
+ );
38
+ if (submits) return false;
39
+ container.replaceChildren(
40
+ ...values.map((value) => {
41
+ const input = document.createElement("input");
42
+ input.type = "hidden";
43
+ input.name = name;
44
+ input.value = value;
45
+ if (form !== "") input.setAttribute("form", form);
46
+ return input;
47
+ })
48
+ );
49
+ return true;
50
+ }
51
+ function commitField(target) {
52
+ target.dispatchEvent(new Event("change", { bubbles: true }));
53
+ }
54
+
32
55
  // src/utils/focus_candidate.ts
33
56
  function inheritsFieldsetDisabled(control) {
34
57
  let fieldset = control.closest("fieldset[disabled]");
@@ -57,6 +80,39 @@ function isInteractiveHost(element) {
57
80
  return false;
58
81
  }
59
82
 
83
+ // src/utils/microtask_coalescer.ts
84
+ var MicrotaskCoalescer = class {
85
+ #run;
86
+ #queued = false;
87
+ #active = false;
88
+ #generation = 0;
89
+ /** @param run - the single reconciliation pass, invoked at most once per batch. */
90
+ constructor(run) {
91
+ this.#run = run;
92
+ }
93
+ /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */
94
+ activate() {
95
+ this.#active = true;
96
+ }
97
+ /** Closes the window and drops any pending pass; call from `disconnect()`. */
98
+ cancel() {
99
+ this.#active = false;
100
+ this.#queued = false;
101
+ this.#generation += 1;
102
+ }
103
+ /** Requests one pass after the batch settles. Idempotent; inert outside the window. */
104
+ schedule() {
105
+ if (!this.#active || this.#queued) return;
106
+ this.#queued = true;
107
+ const generation = this.#generation;
108
+ queueMicrotask(() => {
109
+ if (generation !== this.#generation || !this.#queued || !this.#active) return;
110
+ this.#queued = false;
111
+ this.#run();
112
+ });
113
+ }
114
+ };
115
+
60
116
  // src/utils/roving_tabindex.ts
61
117
  var RovingTabindex = class {
62
118
  /** Returns the current ordered item elements; called on every operation. */
@@ -100,6 +156,7 @@ function rovingMove(current, length, delta, wrap) {
100
156
  // src/controllers/toggle_group_controller.ts
101
157
  var ITEM_ATTRIBUTES = [
102
158
  "aria-pressed",
159
+ "data-value",
103
160
  "disabled",
104
161
  "hidden",
105
162
  "type",
@@ -109,24 +166,37 @@ var ITEM_ATTRIBUTES = [
109
166
  ];
110
167
  var hasModifier = (event) => event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
111
168
  var ToggleGroupController = class extends Controller {
112
- static targets = ["item"];
169
+ static targets = ["item", "fields"];
113
170
  static values = {
114
- mode: { type: String, default: "multiple" }
171
+ mode: { type: String, default: "multiple" },
172
+ name: { type: String, default: "values[]" },
173
+ form: { type: String, default: "" }
115
174
  };
116
175
  static actions = ["onKeydown", "toggle"];
117
- static events = ["change"];
176
+ static events = ["change", "reconcile"];
118
177
  #roving = new RovingTabindex(() => this.#managedTargets);
119
178
  #handledEvents = /* @__PURE__ */ new WeakSet();
120
179
  #managedItems = /* @__PURE__ */ new Set();
121
180
  #originalTabindex = /* @__PURE__ */ new Map();
122
181
  #ownedPressed = /* @__PURE__ */ new Set();
123
182
  #internalPressedValues = /* @__PURE__ */ new Map();
183
+ /** One pass per batch of item, Value, and retained-element changes. */
184
+ #pass = new MicrotaskCoalescer(() => this.#reconcileDom());
124
185
  #observer = null;
125
186
  #connected = false;
187
+ /** The pressed set last published: read on connect, then committed or reported. */
188
+ #committedValues = [];
189
+ /**
190
+ * How many presses the user has committed, so a press whose reports are still
191
+ * going out can tell that a listener has committed a newer one meanwhile.
192
+ */
193
+ #presses = 0;
126
194
  /**
127
195
  * Normalizes state and establishes one roving entry point. A single authored
128
196
  * `tabindex="0"` survives reconnect; otherwise the first pressed, navigable
129
- * item wins, falling back to the first navigable item.
197
+ * item wins, falling back to the first navigable item. The pressed set it
198
+ * settles on is the one a later move is measured from; connecting reports
199
+ * nothing.
130
200
  */
131
201
  connect() {
132
202
  const currentItems = new Set(this.itemTargets);
@@ -140,6 +210,8 @@ var ToggleGroupController = class extends Controller {
140
210
  for (const item of this.itemTargets) this.#reconcileHost(item, false);
141
211
  this.#normalizeSelection();
142
212
  this.#ensureTabStop(preferred);
213
+ this.#mirrorFields(false);
214
+ this.#committedValues = this.#pressedValues();
143
215
  this.element.addEventListener("click", this.#onClickCapture, true);
144
216
  this.element.addEventListener("keydown", this.#onKeydownCapture, true);
145
217
  this.element.addEventListener("click", this.#onClick);
@@ -147,11 +219,16 @@ var ToggleGroupController = class extends Controller {
147
219
  this.element.addEventListener("focusin", this.#onFocusin);
148
220
  this.#connected = true;
149
221
  this.#internalPressedValues.clear();
222
+ this.#pass.activate();
150
223
  this.#observeMutations();
151
224
  }
152
- /** Releases every listener and observer while retaining DOM state for Turbo cache/reconnect. */
225
+ /**
226
+ * Releases every listener, the observer, and a pass still queued, while
227
+ * retaining DOM state for Turbo cache/reconnect.
228
+ */
153
229
  disconnect() {
154
230
  this.#connected = false;
231
+ this.#pass.cancel();
155
232
  this.element.removeEventListener("click", this.#onClickCapture, true);
156
233
  this.element.removeEventListener("keydown", this.#onKeydownCapture, true);
157
234
  this.element.removeEventListener("click", this.#onClick);
@@ -161,25 +238,29 @@ var ToggleGroupController = class extends Controller {
161
238
  this.#observer = null;
162
239
  this.#internalPressedValues.clear();
163
240
  }
164
- /** Drops a newly connected item from the Tab sequence before reconciling the group. */
241
+ /** Drops a newly connected item from the Tab sequence before the batch is reconciled. */
165
242
  itemTargetConnected(item) {
166
243
  if (!this.#connected) return;
167
244
  this.#reconcileHost(item, true);
168
- this.#normalizeSelection();
169
- this.#ensureTabStop();
245
+ this.#pass.schedule();
170
246
  }
171
- /** Restores attributes owned only while an element is an item and repairs the Tab stop. */
247
+ /** Restores attributes owned only while an element is an item, then reconciles the batch. */
172
248
  itemTargetDisconnected(item) {
173
249
  if (!this.#connected) return;
174
250
  this.#releaseItem(item);
175
- this.#normalizeSelection();
176
- this.#ensureTabStop();
251
+ this.#pass.schedule();
177
252
  }
178
253
  /** Reconciles the single-selection invariant when the Stimulus Value changes. */
179
254
  modeValueChanged() {
180
- if (!this.#connected) return;
181
- this.#normalizeSelection();
182
- this.#ensureTabStop();
255
+ this.#pass.schedule();
256
+ }
257
+ /** Rebuilds the submitted fields when the public name changes at runtime. */
258
+ nameValueChanged() {
259
+ this.#pass.schedule();
260
+ }
261
+ /** Repoints the submitted fields when the owning form changes at runtime. */
262
+ formValueChanged() {
263
+ this.#pass.schedule();
183
264
  }
184
265
  /**
185
266
  * Toggles the action's item. Per-item action wiring is optional because click
@@ -272,7 +353,17 @@ var ToggleGroupController = class extends Controller {
272
353
  event.preventDefault();
273
354
  if (destination) this.#setActive(destination, true);
274
355
  }
275
- /** Applies one user toggle and dispatches the documented change detail. */
356
+ /**
357
+ * Applies one user toggle and dispatches the documented change detail. The set
358
+ * it leaves is taken as published before either report goes out, so a
359
+ * listener that presses again or writes `aria-pressed` is measured from it. A
360
+ * listener of the native `change` that presses again has had that newer press
361
+ * reported, so this press's `change` would describe a set that is gone and is
362
+ * not dispatched.
363
+ *
364
+ * @stimeoRuntimeOnly `mode` is the rule this one press follows; the lasting single-press
365
+ * normalisation is a render root of its own.
366
+ */
276
367
  #toggleItem(item) {
277
368
  if (!this.#isSupportedHost(item) || this.#isActivationDisabled(item)) return;
278
369
  if (!this.#managedItems.has(item)) this.#reconcileHost(item, true);
@@ -284,15 +375,58 @@ var ToggleGroupController = class extends Controller {
284
375
  this.#setPressed(item, willPress);
285
376
  }
286
377
  this.#setActive(item);
378
+ const values = this.#pressedValues();
379
+ this.#committedValues = values;
380
+ this.#presses += 1;
381
+ const press = this.#presses;
382
+ this.#mirrorFields(true);
383
+ if (press !== this.#presses) return;
287
384
  this.dispatch("change", {
288
- detail: { value: this.#itemValue(item), pressed: willPress, values: this.#pressedValues() }
385
+ detail: { value: this.#itemValue(item), pressed: willPress, values: [...values] }
289
386
  });
290
387
  }
291
- /** Reconciles supported hosts, pressed state, and the roving invariant after a DOM mutation. */
292
- #reconcile() {
388
+ /**
389
+ * Mirrors the pressed values into the optional fields container.
390
+ *
391
+ * @stimeoRenderRoot
392
+ */
393
+ #mirrorFields(notify) {
394
+ if (!this.hasFieldsTarget) return;
395
+ const options = { name: this.nameValue, form: this.formValue };
396
+ if (writeFields(this.fieldsTarget, this.#pressedValues(), options) && notify) {
397
+ commitField(this.fieldsTarget);
398
+ }
399
+ }
400
+ /**
401
+ * Reconciles supported hosts, pressed state, the roving invariant, and the
402
+ * fields after the page changed the group, then reports a pressed set that
403
+ * moved. Records still queued are read first, so an author's write is not lost
404
+ * when observation is suspended for this pass's own writes; observation resumes
405
+ * before the report, so an edit a listener makes is seen by the next pass.
406
+ */
407
+ #reconcileDom() {
408
+ const observer = this.#observer;
409
+ if (observer) {
410
+ this.#releaseAuthoredPressed(observer.takeRecords());
411
+ observer.disconnect();
412
+ }
293
413
  for (const item of this.itemTargets) this.#reconcileHost(item, true);
294
414
  this.#normalizeSelection();
295
415
  this.#ensureTabStop();
416
+ this.#mirrorFields(false);
417
+ this.#internalPressedValues.clear();
418
+ if (observer) this.#observeWith(observer);
419
+ this.#reportMove();
420
+ }
421
+ /** Reports a pressed set that moved since the one this group last published. */
422
+ #reportMove() {
423
+ const values = this.#pressedValues();
424
+ const previous = this.#committedValues;
425
+ if (values.length === previous.length && values.every((value, i) => value === previous[i])) {
426
+ return;
427
+ }
428
+ this.#committedValues = values;
429
+ this.dispatch("reconcile", { detail: { values: [...values] } });
296
430
  }
297
431
  /** Begins or ends ownership according to the item's current host semantics. */
298
432
  #reconcileHost(item, dropFromTabSequence) {
@@ -328,7 +462,11 @@ var ToggleGroupController = class extends Controller {
328
462
  item.setAttribute("aria-pressed", "false");
329
463
  }
330
464
  }
331
- /** Makes the first DOM-ordered pressed item the sole pressed item in single mode. */
465
+ /**
466
+ * Makes the first DOM-ordered pressed item the sole pressed item in single mode.
467
+ *
468
+ * @stimeoRenderRoot
469
+ */
332
470
  #normalizeSelection() {
333
471
  for (const item of this.#managedTargets) this.#normalizePressed(item);
334
472
  if (this.modeValue !== "single") return;
@@ -377,7 +515,7 @@ var ToggleGroupController = class extends Controller {
377
515
  }
378
516
  /** Whether the closest Toggle Group scope around a target is this instance. */
379
517
  #ownsEventTarget(target) {
380
- return target instanceof Element && target.closest('[data-controller~="stimeo--toggle-group"]') === this.element;
518
+ return target instanceof Element && target.closest(`[data-controller~="${this.identifier}"]`) === this.element;
381
519
  }
382
520
  /** Hosts whose activation model can be owned without conflicting native behavior. */
383
521
  #isSupportedHost(item) {
@@ -425,9 +563,7 @@ var ToggleGroupController = class extends Controller {
425
563
  #observeMutations() {
426
564
  const observer = new MutationObserver((records) => {
427
565
  this.#releaseAuthoredPressed(records);
428
- observer.disconnect();
429
- this.#reconcile();
430
- this.#observeWith(observer);
566
+ this.#pass.schedule();
431
567
  });
432
568
  this.#observer = observer;
433
569
  this.#observeWith(observer);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/logical_scroll.ts","../../src/utils/arrow_step.ts","../../src/utils/event_owner.ts","../../src/utils/focus_candidate.ts","../../src/utils/interactive_host.ts","../../src/utils/roving_tabindex.ts","../../src/controllers/toggle_group_controller.ts"],"names":[],"mappings":";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AA,EAGA,IAAI,eAAA,GAAiC;AACnC,IAAA,OAAO,IAAA,CAAK,YAAY,MAAA,CAAO,CAAC,SAAS,IAAA,CAAK,aAAA,CAAc,GAAA,CAAI,IAAI,CAAC,CAAA;AAAA,EACvE;AAAA;AAAA,EAGA,IAAI,eAAA,GAAiC;AACnC,IAAA,OAAO,IAAA,CAAK,gBAAgB,MAAA,CAAO,CAAC,SAAS,IAAA,CAAK,YAAA,CAAa,IAAI,CAAC,CAAA;AAAA,EACtE;AAAA;AAAA,EAGA,WAAW,IAAA,EAA4B;AACrC,IAAA,OAAO,IAAA,CAAK,YAAA,CAAa,cAAc,CAAA,KAAM,MAAA;AAAA,EAC/C;AAAA;AAAA,EAGA,WAAA,CAAY,MAAmB,OAAA,EAAwB;AACrD,IAAA,MAAM,KAAA,GAAQ,UAAU,MAAA,GAAS,OAAA;AACjC,IAAA,IAAA,CAAK,sBAAA,CAAuB,GAAA,CAAI,IAAA,EAAM,KAAK,CAAA;AAC3C,IAAA,IAAA,CAAK,YAAA,CAAa,gBAAgB,KAAK,CAAA;AAAA,EACzC;AAAA;AAAA,EAGA,cAAA,GAA2B;AACzB,IAAA,OAAO,KAAK,eAAA,CACT,MAAA,CAAO,CAAC,IAAA,KAAS,KAAK,UAAA,CAAW,IAAI,CAAC,CAAA,CACtC,IAAI,CAAC,IAAA,KAAS,IAAA,CAAK,UAAA,CAAW,IAAI,CAAC,CAAA;AAAA,EACxC;AAAA;AAAA,EAGA,WAAW,IAAA,EAA2B;AACpC,IAAA,OAAO,IAAA,CAAK,YAAA,CAAa,YAAY,CAAA,IAAK,EAAA;AAAA,EAC5C;AACF","file":"toggle_group_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/**\n * True when a press arrived carrying any modifier, for the keys the browser and\n * the OS own outright: return without calling `preventDefault()` and without\n * moving any state.\n *\n * `Control+Home` and `Control+End` jump the document to its ends, and a widget\n * that swallows them makes the shortcut work or not depending on where focus\n * happens to sit. {@link isReservedArrowChord} answers the same question for the\n * arrows, but returns `false` for every other key so that this one can decide.\n *\n * There is no `allow` list here on purpose. APG assigns no modifier chord to\n * `Home`/`End`, so a widget that wanted one would be claiming a combination the\n * pattern never gave it.\n *\n * @example\n * ```ts\n * case \"Home\":\n * case \"End\":\n * if (hasModifierChord(event)) return;\n * ```\n */\nexport function hasModifierChord(event: KeyboardEvent): boolean {\n return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;\n}\n","/**\n * Resolves which of a controller's elements owns a node.\n *\n * A delegated listener hears events from a whole subtree, so the handler's first\n * job is almost always the same question: which item, handle, or control does\n * this `event.target` belong to? The same question comes up for a\n * `MutationRecord.target`, for `document.activeElement`, and for a\n * `relatedTarget` on the way out of a hover region.\n *\n * The answer is `Node.contains()`, which is **inclusive** — an element contains\n * itself — so testing the candidate for identity as well would be redundant.\n *\n * **The guard is what makes this safe to call with a raw event target.**\n * `event.target` is typed `EventTarget | null`, and `contains()` takes a `Node?`:\n * browsers throw `TypeError` for anything else, and `window` — the everyday\n * `EventTarget` that is not a `Node` — is what an event dispatched at it carries.\n * Narrowing here means a caller never has to cast, and the rule cannot drift\n * between the places that ask the question.\n *\n * Scope stays with the caller. These helpers say *which candidate owns the node*,\n * not *whether the node belongs to this controller at all* — a component with\n * nested instances of itself decides that first (by comparing the closest\n * annotated ancestor) and passes the candidates it owns.\n */\n\n/**\n * Index in `candidates` of the first one that is, or contains, `node`.\n *\n * `-1` when none does, when `node` is absent, and when it is an `EventTarget`\n * that is not a `Node`. Candidates are tested in array order, so a nested pair\n * resolves to whichever the caller listed first.\n */\nexport function ownerIndex<T extends Element>(\n candidates: readonly T[],\n node: EventTarget | null | undefined,\n): number {\n if (!(node instanceof Node)) return -1;\n return candidates.findIndex((candidate) => candidate.contains(node));\n}\n\n/**\n * The first candidate that is, or contains, `node`; `null` when none does.\n *\n * A miss indexes the array at `-1`, which reads as `undefined` and lands on the\n * same `null` the absent cases produce.\n */\nexport function ownerOf<T extends Element>(\n candidates: readonly T[],\n node: EventTarget | null | undefined,\n): T | null {\n return candidates[ownerIndex(candidates, node)] ?? null;\n}\n","/**\n * Whether a disabled `<fieldset>` ancestor actually reaches `control`.\n *\n * HTML exempts the contents of a fieldset's **first direct-child `<legend>`**, and\n * the exemption is per fieldset — a control legal in one legend can still be\n * disabled by a second, outer fieldset, so the walk continues upward.\n *\n * Exported on its own for callers that need the disabled-inheritance rule without\n * the rest of {@link canTakeFocus} — a control's availability check, or a `hidden`\n * walk bounded at a widget root, which is a different rule to compose with.\n */\nexport function inheritsFieldsetDisabled(control: HTMLElement): boolean {\n let fieldset: Element | null = control.closest(\"fieldset[disabled]\");\n while (fieldset) {\n const legend = Array.from(fieldset.children).find((child) => child.tagName === \"LEGEND\");\n if (!legend?.contains(control)) return true;\n fieldset = fieldset.parentElement?.closest(\"fieldset[disabled]\") ?? null;\n }\n return false;\n}\n\n/**\n * Whether an element can actually take focus, checked **before** `focus()` runs.\n *\n * A controller that must move focus off a control it is about to disable or hide\n * picks a destination and calls `focus()` on it. If that destination cannot take\n * focus, the call **fails silently**: `hidden` and natively `disabled` elements\n * swallow it, so the caret stays in the subtree that is disappearing and lands on\n * `<body>` a frame later — the exact outcome the rescue exists to prevent, minus\n * any signal that it happened.\n *\n * Testing after the fact is the obvious alternative and is deliberately not the\n * rule. Reading `document.activeElement` back only works in a real browser, and\n * looping over candidates that way performs a real focus move per failure —\n * observable to assistive technology. Checking first costs nothing and catches\n * the cases that actually occur.\n *\n * **`aria-disabled` is not disqualifying.** It is the attribute an author uses\n * for a control that must stay *discoverable*, and the roving contract keeps\n * such items reachable. Only the four conditions that make the platform refuse\n * focus are checked: `hidden` / `inert` (an ancestor's counts),\n * `input[type=\"hidden\"]`, the native `disabled` property, and `disabled`\n * inherited from an ancestor `fieldset`. CSS-only invisibility is handled by\n * {@link isRenderedForFocus} when a consumer needs sequential-focus semantics.\n *\n * Reading `:disabled` instead of walking the fieldset chain would be shorter, but\n * that pseudo-class is not evaluated consistently outside real browsers and this\n * has to be right headlessly too. happy-dom in particular focuses a `<button>`\n * inside a disabled fieldset where a real engine refuses, so the inheritance is\n * spelled out rather than delegated.\n *\n * What a consumer does when nothing survives is its own call: some fall back to\n * their landmark, while a widget whose caret already sits somewhere legitimate\n * refuses the move outright rather than relocating it.\n *\n * @example\n * ```ts\n * const target = candidates.find(canTakeFocus);\n * if (target) target.focus();\n * else {\n * this.#tabindex.lend(this.element); // nothing left: fall back to the landmark\n * this.element.focus();\n * }\n * ```\n *\n * @param element - the candidate destination\n */\nexport function canTakeFocus(element: HTMLElement): boolean {\n if (element.closest(\"[hidden], [inert]\")) return false;\n if (element instanceof HTMLInputElement && element.type === \"hidden\") return false;\n if (!(\"disabled\" in element)) return true;\n if ((element as HTMLElement & { disabled: boolean }).disabled) return false;\n return !inheritsFieldsetDisabled(element);\n}\n\n/** Elements whose semantics or authored attributes can place them in sequential focus order. */\nexport const TAB_STOP_CANDIDATE_SELECTOR = [\n \"a[href]\",\n \"area[href]\",\n \"button\",\n \"input\",\n \"select\",\n \"textarea\",\n \"summary\",\n \"iframe\",\n \"audio[controls]\",\n \"video[controls]\",\n \"[tabindex]\",\n \"[contenteditable]\",\n].join(\",\");\n\n/** Optional browser visibility API used to exclude CSS-hidden candidates. */\ninterface VisibilityCheckable {\n checkVisibility?: (options?: { visibilityProperty?: boolean }) => boolean;\n}\n\n/** Whether CSS visibility allows an otherwise eligible element to participate in focus order. */\nexport function isRenderedForFocus(element: HTMLElement): boolean {\n const check = (element as HTMLElement & VisibilityCheckable).checkVisibility;\n return typeof check === \"function\" ? check.call(element, { visibilityProperty: true }) : true;\n}\n\n/** Parses an authored `tabindex`; invalid syntax has no explicit focus-order meaning. */\nfunction authoredTabindex(element: HTMLElement): number | null {\n const value = element.getAttribute(\"tabindex\");\n if (value === null || !/^[+-]?\\d+$/.test(value.trim())) return null;\n return Number(value);\n}\n\n/** Whether the element's native semantics place it in sequential focus order. */\nfunction hasNativeTabStop(element: HTMLElement): boolean {\n if (element instanceof HTMLAnchorElement || element instanceof HTMLAreaElement) {\n return element.hasAttribute(\"href\");\n }\n if (\n element instanceof HTMLButtonElement ||\n element instanceof HTMLSelectElement ||\n element instanceof HTMLTextAreaElement\n ) {\n return true;\n }\n if (element instanceof HTMLInputElement) return element.type !== \"hidden\";\n if (element instanceof HTMLIFrameElement) return true;\n if (element.tagName === \"AUDIO\" || element.tagName === \"VIDEO\") {\n return element.hasAttribute(\"controls\");\n }\n if (element instanceof HTMLElement && element.tagName === \"SUMMARY\") {\n const details = element.parentElement;\n return (\n details instanceof HTMLDetailsElement &&\n Array.from(details.children).find((child) => child.tagName === \"SUMMARY\") === element\n );\n }\n return false;\n}\n\n/** Whether an explicit `contenteditable` value creates an editable tab stop. */\nfunction hasEditableTabStop(element: HTMLElement): boolean {\n const value = element.getAttribute(\"contenteditable\")?.toLowerCase();\n return value === \"\" || value === \"true\" || value === \"plaintext-only\";\n}\n\n/**\n * Whether an element is a usable sequential Tab stop right now.\n *\n * Native semantics, authored `tabindex`, editable hosts, inherited disabled state,\n * HTML `hidden`/`inert`, and CSS visibility are evaluated together. `aria-disabled`\n * remains focusable because it communicates unavailability without removing the\n * control from discovery order.\n */\nexport function isTabStop(element: HTMLElement): boolean {\n if (!canTakeFocus(element) || !isRenderedForFocus(element)) return false;\n\n const tabindex = authoredTabindex(element);\n if (tabindex !== null) return tabindex >= 0;\n return hasNativeTabStop(element) || hasEditableTabStop(element);\n}\n\n/** Returns every usable sequential Tab stop below `root` in document order. */\nexport function tabStopsWithin(root: ParentNode): HTMLElement[] {\n return Array.from(root.querySelectorAll<HTMLElement>(TAB_STOP_CANDIDATE_SELECTOR)).filter(\n isTabStop,\n );\n}\n\n/** Returns the first usable sequential Tab stop below `root`, if one exists. */\nexport function firstTabStop(root: ParentNode): HTMLElement | null {\n for (const candidate of root.querySelectorAll<HTMLElement>(TAB_STOP_CANDIDATE_SELECTOR)) {\n if (isTabStop(candidate)) return candidate;\n }\n return null;\n}\n\n/** Whether `root` contains at least one usable sequential Tab stop. */\nexport function hasTabStop(root: ParentNode): boolean {\n return firstTabStop(root) !== null;\n}\n","/**\n * Native interactive elements whose built-in activation must not be replaced\n * wholesale by a controller. Deliberately excludes `[tabindex]`: a generic\n * element made focusable is the supported host for several headless patterns.\n * Contenteditable is handled by {@link isInteractiveHost} because its state is\n * inherited and its keywords are ASCII-case-insensitive.\n */\nexport const INTERACTIVE_HOST_SELECTOR =\n \"button, input, select, textarea, label, a[href], area[href], summary, details, audio[controls], video[controls], iframe, object, embed\";\n\n/**\n * Whether an element owns native activation or an inherited editing surface.\n *\n * The `contenteditable` missing and invalid states inherit. Walking explicitly\n * also keeps `contenteditable=\"false\"` as a real boundary inside an editable\n * ancestor instead of treating any ancestor attribute as decisive.\n */\nexport function isInteractiveHost(element: HTMLElement): boolean {\n if (element.matches(INTERACTIVE_HOST_SELECTOR)) return true;\n\n let current: HTMLElement | null = element;\n while (current) {\n const raw = current.getAttribute(\"contenteditable\");\n if (raw !== null) {\n const value = raw.trim().toLowerCase();\n if (value === \"false\") return false;\n if (value === \"\" || value === \"true\" || value === \"plaintext-only\") return true;\n }\n current = current.parentElement;\n }\n return false;\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, logicalArrowStep } from \"../utils/arrow_step\";\nimport { ownerOf } from \"../utils/event_owner\";\nimport { inheritsFieldsetDisabled } from \"../utils/focus_candidate\";\nimport { isInteractiveHost } from \"../utils/interactive_host\";\nimport { RovingTabindex, rovingMove } from \"../utils/roving_tabindex\";\n\n/** Item attributes whose retained-element changes can alter this controller's contract. */\nconst ITEM_ATTRIBUTES = [\n \"aria-pressed\",\n \"disabled\",\n \"hidden\",\n \"type\",\n \"href\",\n \"contenteditable\",\n \"controls\",\n];\n\n/** Modifier keys that keep document-level Home/End shortcuts outside the widget. */\nconst hasModifier = (event: KeyboardEvent): boolean =>\n event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;\n\n/**\n * Headless, accessible toggle-button group behavior.\n *\n * Markup contract (identifier: `stimeo--toggle-group`):\n * <div data-controller=\"stimeo--toggle-group\"\n * data-stimeo--toggle-group-mode-value=\"single\"\n * role=\"group\" aria-label=\"Text style\">\n * <button type=\"button\" aria-pressed=\"true\" tabindex=\"0\" data-value=\"bold\"\n * data-stimeo--toggle-group-target=\"item\">Bold</button>\n * <!-- more items; exactly one navigable item has tabindex=0 -->\n * </div>\n *\n * Implements the WAI-ARIA APG **Button (toggle)** pattern with **Toolbar**-style\n * roving navigation. Each item's pressed state is `aria-pressed` (the accessible\n * name never changes); the group is a single Tab stop. For strict mutually\n * exclusive selection with radio semantics, use\n * {@link RadioGroupController | Radio Group} instead.\n *\n * `change` dispatches `{ value: string, pressed: boolean, values: string[] }`.\n *\n * @remarks\n * Behavior only — the consumer styles off `[aria-pressed=\"true\"]`. A supported\n * item is either `<button type=\"button\">` or a non-interactive host such as\n * `<div role=\"button\">`; other native interactive elements retain their own\n * activation model and this controller stands down on them.\n *\n * Click handling and keydown handling are delegated from the group, so items\n * added at runtime need only the `item` target. Per-item `data-action` bindings\n * to {@link toggle} and {@link onKeydown} remain supported and are idempotent\n * when combined with delegation.\n *\n * Behavior provided:\n * - Click (or Space/Enter) toggles an item. In `single` mode pressing one item\n * releases the others (0 or 1 pressed); `multiple` allows any number.\n * - `ArrowRight`/`ArrowDown` move focus to the next navigable item,\n * `ArrowLeft`/`ArrowUp` to the previous (wrapping); `Home`/`End` to the\n * first/last. Native-disabled and hidden items are skipped. ARIA-disabled\n * items remain discoverable in the roving order but cannot be activated.\n * - `stimeo--toggle-group:change` is dispatched only for user activation. Its\n * detail is `{ value: string, pressed: boolean, values: string[] }`, where\n * `values` is the DOM-ordered value list of every item left pressed.\n */\nexport class ToggleGroupController extends Controller<HTMLElement> {\n static override targets = [\"item\"];\n static override values = {\n mode: { type: String, default: \"multiple\" },\n };\n static actions = [\"onKeydown\", \"toggle\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly itemTargets: HTMLElement[];\n declare modeValue: string;\n\n readonly #roving = new RovingTabindex(() => this.#managedTargets);\n readonly #handledEvents = new WeakSet<Event>();\n readonly #managedItems = new Set<HTMLElement>();\n readonly #originalTabindex = new Map<HTMLElement, string | null>();\n readonly #ownedPressed = new Set<HTMLElement>();\n readonly #internalPressedValues = new Map<HTMLElement, string>();\n #observer: MutationObserver | null = null;\n #connected = false;\n\n /**\n * Normalizes state and establishes one roving entry point. A single authored\n * `tabindex=\"0\"` survives reconnect; otherwise the first pressed, navigable\n * item wins, falling back to the first navigable item.\n */\n override connect(): void {\n const currentItems = new Set(this.itemTargets);\n for (const item of this.#managedItems) {\n if (!currentItems.has(item)) this.#releaseItem(item);\n }\n const authoredStops = this.itemTargets.filter(\n (item) =>\n this.#isSupportedHost(item) &&\n item.getAttribute(\"tabindex\") === \"0\" &&\n this.#isNavigable(item),\n );\n const preferred = authoredStops.length === 1 ? authoredStops[0] : null;\n\n for (const item of this.itemTargets) this.#reconcileHost(item, false);\n this.#normalizeSelection();\n this.#ensureTabStop(preferred);\n\n this.element.addEventListener(\"click\", this.#onClickCapture, true);\n this.element.addEventListener(\"keydown\", this.#onKeydownCapture, true);\n this.element.addEventListener(\"click\", this.#onClick);\n this.element.addEventListener(\"keydown\", this.#onKeydown);\n this.element.addEventListener(\"focusin\", this.#onFocusin);\n this.#connected = true;\n // Writes made before observation started cannot produce records and must\n // not be mistaken for a later retained-element morph.\n this.#internalPressedValues.clear();\n this.#observeMutations();\n }\n\n /** Releases every listener and observer while retaining DOM state for Turbo cache/reconnect. */\n override disconnect(): void {\n this.#connected = false;\n this.element.removeEventListener(\"click\", this.#onClickCapture, true);\n this.element.removeEventListener(\"keydown\", this.#onKeydownCapture, true);\n this.element.removeEventListener(\"click\", this.#onClick);\n this.element.removeEventListener(\"keydown\", this.#onKeydown);\n this.element.removeEventListener(\"focusin\", this.#onFocusin);\n this.#observer?.disconnect();\n this.#observer = null;\n this.#internalPressedValues.clear();\n }\n\n /** Drops a newly connected item from the Tab sequence before reconciling the group. */\n itemTargetConnected(item: HTMLElement): void {\n if (!this.#connected) return;\n this.#reconcileHost(item, true);\n this.#normalizeSelection();\n this.#ensureTabStop();\n }\n\n /** Restores attributes owned only while an element is an item and repairs the Tab stop. */\n itemTargetDisconnected(item: HTMLElement): void {\n if (!this.#connected) return;\n this.#releaseItem(item);\n this.#normalizeSelection();\n this.#ensureTabStop();\n }\n\n /** Reconciles the single-selection invariant when the Stimulus Value changes. */\n modeValueChanged(): void {\n if (!this.#connected) return;\n this.#normalizeSelection();\n this.#ensureTabStop();\n }\n\n /**\n * Toggles the action's item. Per-item action wiring is optional because click\n * is also delegated from the group.\n */\n toggle(event: Event): void {\n if (event.defaultPrevented) return;\n const item = event.currentTarget as HTMLElement | null;\n if (!item || !this.itemTargets.includes(item)) return;\n this.#handledEvents.add(event);\n this.#toggleItem(item);\n }\n\n /**\n * Moves focus or activates the action's item. Per-item action wiring is\n * optional because keydown is also delegated from the group.\n */\n onKeydown(event: KeyboardEvent): void {\n const item = event.currentTarget as HTMLElement | null;\n if (!item || !this.itemTargets.includes(item)) return;\n this.#handleKeydown(event, item);\n }\n\n /** Blocks disabled activation before per-item or consumer event handlers run. */\n readonly #onClickCapture = (event: MouseEvent): void => {\n const item = this.#itemForEventTarget(event.target);\n if (!item || !this.#isSupportedHost(item) || !this.#isActivationDisabled(item)) return;\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n\n /** Blocks disabled keyboard activation while leaving navigation keys available. */\n readonly #onKeydownCapture = (event: KeyboardEvent): void => {\n if (event.key !== \" \" && event.key !== \"Enter\") return;\n const item = this.#itemForEventTarget(event.target);\n if (!item || !this.#isSupportedHost(item) || !this.#isActivationDisabled(item)) return;\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n\n /** Delegated click path for static and runtime-added items without actions. */\n readonly #onClick = (event: MouseEvent): void => {\n if (this.#handledEvents.delete(event) || event.defaultPrevented) return;\n const item = this.#itemForEventTarget(event.target);\n if (item) this.#toggleItem(item);\n };\n\n /** Delegated keydown path for static and runtime-added items without actions. */\n readonly #onKeydown = (event: KeyboardEvent): void => {\n const item = this.#itemForEventTarget(event.target);\n if (item) this.#handleKeydown(event, item);\n };\n\n /** Keeps programmatic and pointer focus as the group's next Tab entry point. */\n readonly #onFocusin = (event: FocusEvent): void => {\n const item = this.#itemForEventTarget(event.target);\n if (!item || !this.#isNavigable(item)) return;\n this.#setActive(item);\n };\n\n /** Applies the APG navigation and activation key map to one supported item. */\n #handleKeydown(event: KeyboardEvent, item: HTMLElement): void {\n if (event.defaultPrevented || !this.#isSupportedHost(item)) return;\n if (event.isComposing) return;\n if (isReservedArrowChord(event)) return;\n if ((event.key === \"Home\" || event.key === \"End\") && hasModifier(event)) return;\n\n if (!this.#managedItems.has(item)) this.#reconcileHost(item, true);\n this.#ensureTabStop();\n const items = this.#managedTargets;\n const current = items.indexOf(item);\n\n if (event.key === \" \" || event.key === \"Enter\") {\n if (this.#isActivationDisabled(item)) {\n event.preventDefault();\n event.stopImmediatePropagation();\n return;\n }\n if (item instanceof HTMLButtonElement) {\n if (event.repeat) event.preventDefault();\n return;\n }\n event.preventDefault();\n if (!event.repeat) this.#toggleItem(item);\n return;\n }\n\n const step = logicalArrowStep(event.key, this.element);\n let destination: HTMLElement | undefined;\n if (step !== 0) {\n destination = this.#nextNavigable(current, step);\n } else if (event.key === \"Home\") {\n destination = this.#navigableItems[0];\n } else if (event.key === \"End\") {\n const navigable = this.#navigableItems;\n destination = navigable[navigable.length - 1];\n } else {\n return;\n }\n\n event.preventDefault();\n if (destination) this.#setActive(destination, true);\n }\n\n /** Applies one user toggle and dispatches the documented change detail. */\n #toggleItem(item: HTMLElement): void {\n if (!this.#isSupportedHost(item) || this.#isActivationDisabled(item)) return;\n if (!this.#managedItems.has(item)) this.#reconcileHost(item, true);\n const willPress = !this.#isPressed(item);\n if (this.modeValue === \"single\") {\n for (const other of this.#managedTargets)\n this.#setPressed(other, other === item && willPress);\n } else {\n this.#setPressed(item, willPress);\n }\n this.#setActive(item);\n this.dispatch(\"change\", {\n detail: { value: this.#itemValue(item), pressed: willPress, values: this.#pressedValues() },\n });\n }\n\n /** Reconciles supported hosts, pressed state, and the roving invariant after a DOM mutation. */\n #reconcile(): void {\n for (const item of this.itemTargets) this.#reconcileHost(item, true);\n this.#normalizeSelection();\n this.#ensureTabStop();\n }\n\n /** Begins or ends ownership according to the item's current host semantics. */\n #reconcileHost(item: HTMLElement, dropFromTabSequence: boolean): void {\n if (!this.#isSupportedHost(item)) {\n this.#releaseItem(item);\n return;\n }\n if (!this.#managedItems.has(item)) {\n this.#managedItems.add(item);\n this.#originalTabindex.set(item, item.getAttribute(\"tabindex\"));\n if (dropFromTabSequence) item.tabIndex = -1;\n }\n this.#normalizePressed(item);\n }\n\n /** Restores only defaults owned because an element belonged to this group. */\n #releaseItem(item: HTMLElement): void {\n if (!this.#managedItems.delete(item)) return;\n const original = this.#originalTabindex.get(item);\n if (original === null) item.removeAttribute(\"tabindex\");\n else if (original !== undefined) item.setAttribute(\"tabindex\", original);\n this.#originalTabindex.delete(item);\n if (this.#ownedPressed.delete(item)) item.removeAttribute(\"aria-pressed\");\n this.#internalPressedValues.delete(item);\n }\n\n /** Supplies a missing pressed state and normalizes invalid ARIA tokens. */\n #normalizePressed(item: HTMLElement): void {\n const value = item.getAttribute(\"aria-pressed\");\n if (value === null) {\n this.#ownedPressed.add(item);\n this.#internalPressedValues.set(item, \"false\");\n item.setAttribute(\"aria-pressed\", \"false\");\n } else if (value !== \"true\" && value !== \"false\") {\n item.setAttribute(\"aria-pressed\", \"false\");\n }\n }\n\n /** Makes the first DOM-ordered pressed item the sole pressed item in single mode. */\n #normalizeSelection(): void {\n for (const item of this.#managedTargets) this.#normalizePressed(item);\n if (this.modeValue !== \"single\") return;\n let found = false;\n for (const item of this.#managedTargets) {\n if (!this.#isPressed(item)) continue;\n if (!found) found = true;\n else this.#setPressed(item, false);\n }\n }\n\n /** Keeps one navigable Tab stop, preferring current DOM state after initial connect. */\n #ensureTabStop(initialPreference?: HTMLElement | null): void {\n const navigable = this.#navigableItems;\n let active: HTMLElement | undefined;\n if (initialPreference !== undefined) {\n active = initialPreference ?? undefined;\n } else {\n const current = this.#managedTargets.filter(\n (item) => item.tabIndex === 0 && this.#isNavigable(item),\n );\n if (current.length === 1) active = current[0];\n }\n active ??= navigable.find((item) => this.#isPressed(item));\n active ??= navigable[0];\n this.#setActive(active ?? null);\n }\n\n /** Moves through the full item order until a navigable destination is found. */\n #nextNavigable(fromIndex: number, delta: 1 | -1): HTMLElement | undefined {\n const items = this.#managedTargets;\n let index = fromIndex;\n for (let step = 0; step < items.length; step++) {\n index = rovingMove(index, items.length, delta, \"wrap\");\n const candidate = items[index];\n if (candidate && this.#isNavigable(candidate)) return candidate;\n }\n return undefined;\n }\n\n /** Assigns the single roving Tab stop and optionally moves DOM focus. */\n #setActive(item: HTMLElement | null, focus = false): void {\n this.#roving.setActive(this.#managedTargets.indexOf(item as HTMLElement), { focus });\n }\n\n /** Finds this group's item containing an event target, excluding nested groups. */\n #itemForEventTarget(target: EventTarget | null): HTMLElement | null {\n if (!this.#ownsEventTarget(target)) return null;\n return ownerOf(this.itemTargets, target);\n }\n\n /** Whether the closest Toggle Group scope around a target is this instance. */\n #ownsEventTarget(target: EventTarget | null): boolean {\n return (\n target instanceof Element &&\n target.closest('[data-controller~=\"stimeo--toggle-group\"]') === this.element\n );\n }\n\n /** Hosts whose activation model can be owned without conflicting native behavior. */\n #isSupportedHost(item: HTMLElement): boolean {\n if (item instanceof HTMLButtonElement) return item.type === \"button\";\n return !isInteractiveHost(item);\n }\n\n /** Items eligible for roving focus (ARIA-disabled deliberately remains eligible). */\n #isNavigable(item: HTMLElement): boolean {\n if (!this.#isSupportedHost(item) || this.#isHidden(item)) return false;\n if (!(item instanceof HTMLButtonElement)) return true;\n return !item.disabled && !inheritsFieldsetDisabled(item);\n }\n\n /** Whether hidden applies on the path from an item up to the group root. */\n #isHidden(item: HTMLElement): boolean {\n let current: HTMLElement | null = item;\n while (current && current !== this.element) {\n if (current.hasAttribute(\"hidden\")) return true;\n current = current.parentElement;\n }\n return false;\n }\n\n /** Whether ARIA, visibility, or native HTML semantics suppress activation. */\n #isActivationDisabled(item: HTMLElement): boolean {\n if (!this.#isNavigable(item)) return true;\n let current: HTMLElement | null = item;\n while (current) {\n if (current.getAttribute(\"aria-disabled\") === \"true\") return true;\n current = current.parentElement;\n }\n return false;\n }\n\n /** Releases default ownership when a Turbo morph authors `aria-pressed`. */\n #releaseAuthoredPressed(records: MutationRecord[]): void {\n for (const record of records) {\n if (record.attributeName !== \"aria-pressed\") continue;\n const item = record.target as HTMLElement;\n const value = item.getAttribute(\"aria-pressed\");\n if (value !== null && this.#internalPressedValues.get(item) !== value) {\n this.#ownedPressed.delete(item);\n }\n }\n this.#internalPressedValues.clear();\n }\n\n /** Watches target membership, retained item hosts/state, and inherited host/fieldset state. */\n #observeMutations(): void {\n const observer = new MutationObserver((records) => {\n this.#releaseAuthoredPressed(records);\n observer.disconnect();\n this.#reconcile();\n this.#observeWith(observer);\n });\n this.#observer = observer;\n this.#observeWith(observer);\n }\n\n /** Registers every root and ancestor observation on one observer instance. */\n #observeWith(observer: MutationObserver): void {\n observer.observe(this.element, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: ITEM_ATTRIBUTES,\n });\n let ancestor = this.element.parentElement;\n while (ancestor) {\n observer.observe(ancestor, {\n attributes: true,\n attributeFilter: [\"contenteditable\", \"disabled\"],\n });\n ancestor = ancestor.parentElement;\n }\n }\n\n /** Supported targets currently managed by the roving primitive. */\n get #managedTargets(): HTMLElement[] {\n return this.itemTargets.filter((item) => this.#managedItems.has(item));\n }\n\n /** Managed items eligible for the roving Tab stop. */\n get #navigableItems(): HTMLElement[] {\n return this.#managedTargets.filter((item) => this.#isNavigable(item));\n }\n\n /** Whether an item is currently pressed. */\n #isPressed(item: HTMLElement): boolean {\n return item.getAttribute(\"aria-pressed\") === \"true\";\n }\n\n /** Reflects pressed state while distinguishing controller writes from authored morphs. */\n #setPressed(item: HTMLElement, pressed: boolean): void {\n const value = pressed ? \"true\" : \"false\";\n this.#internalPressedValues.set(item, value);\n item.setAttribute(\"aria-pressed\", value);\n }\n\n /** The DOM-ordered values of every currently pressed managed item. */\n #pressedValues(): string[] {\n return this.#managedTargets\n .filter((item) => this.#isPressed(item))\n .map((item) => this.#itemValue(item));\n }\n\n /** An item's value (`data-value`, defaulting to empty). */\n #itemValue(item: HTMLElement): string {\n return item.getAttribute(\"data-value\") ?? \"\";\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/logical_scroll.ts","../../src/utils/arrow_step.ts","../../src/utils/event_owner.ts","../../src/utils/field_mirror.ts","../../src/utils/focus_candidate.ts","../../src/utils/interactive_host.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/roving_tabindex.ts","../../src/controllers/toggle_group_controller.ts"],"names":[],"mappings":";;;;;AAiBO,SAAS,MAAM,OAAA,EAA2B;AAC/C,EAAA,OAAO,MAAA,CAAO,gBAAA,CAAiB,OAAO,CAAA,CAAE,SAAA,KAAc,KAAA;AACxD;;;ACiBO,SAAS,gBAAA,CAAiB,KAAa,OAAA,EAA8B;AAC1E,EAAA,IAAI,GAAA,KAAQ,aAAa,OAAO,CAAA;AAChC,EAAA,IAAI,GAAA,KAAQ,WAAW,OAAO,EAAA;AAC9B,EAAA,IAAI,GAAA,KAAQ,YAAA,IAAgB,GAAA,KAAQ,WAAA,EAAa,OAAO,CAAA;AACxD,EAAA,MAAM,OAAA,GAAU,KAAA,CAAM,OAAO,CAAA,GAAI,WAAA,GAAc,Y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;AACD,MAAA,QAAA,GAAW,QAAA,CAAS,aAAA;AAAA,IACtB;AAAA,EACF;AAAA;AAAA,EAGA,IAAI,eAAA,GAAiC;AACnC,IAAA,OAAO,IAAA,CAAK,YAAY,MAAA,CAAO,CAAC,SAAS,IAAA,CAAK,aAAA,CAAc,GAAA,CAAI,IAAI,CAAC,CAAA;AAAA,EACvE;AAAA;AAAA,EAGA,IAAI,eAAA,GAAiC;AACnC,IAAA,OAAO,IAAA,CAAK,gBAAgB,MAAA,CAAO,CAAC,SAAS,IAAA,CAAK,YAAA,CAAa,IAAI,CAAC,CAAA;AAAA,EACtE;AAAA;AAAA,EAGA,WAAW,IAAA,EAA4B;AACrC,IAAA,OAAO,IAAA,CAAK,YAAA,CAAa,cAAc,CAAA,KAAM,MAAA;AAAA,EAC/C;AAAA;AAAA,EAGA,WAAA,CAAY,MAAmB,OAAA,EAAwB;AACrD,IAAA,MAAM,KAAA,GAAQ,UAAU,MAAA,GAAS,OAAA;AACjC,IAAA,IAAA,CAAK,sBAAA,CAAuB,GAAA,CAAI,IAAA,EAAM,KAAK,CAAA;AAC3C,IAAA,IAAA,CAAK,YAAA,CAAa,gBAAgB,KAAK,CAAA;AAAA,EACzC;AAAA;AAAA,EAGA,cAAA,GAA2B;AACzB,IAAA,OAAO,KAAK,eAAA,CACT,MAAA,CAAO,CAAC,IAAA,KAAS,KAAK,UAAA,CAAW,IAAI,CAAC,CAAA,CACtC,IAAI,CAAC,IAAA,KAAS,IAAA,CAAK,UAAA,CAAW,IAAI,CAAC,CAAA;AAAA,EACxC;AAAA;AAAA,EAGA,WAAW,IAAA,EAA2B;AACpC,IAAA,OAAO,IAAA,CAAK,YAAA,CAAa,YAAY,CAAA,IAAK,EAAA;AAAA,EAC5C;AACF","file":"toggle_group_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/**\n * True when a press arrived carrying any modifier, for the keys the browser and\n * the OS own outright: return without calling `preventDefault()` and without\n * moving any state.\n *\n * `Control+Home` and `Control+End` jump the document to its ends, and a widget\n * that swallows them makes the shortcut work or not depending on where focus\n * happens to sit. {@link isReservedArrowChord} answers the same question for the\n * arrows, but returns `false` for every other key so that this one can decide.\n *\n * There is no `allow` list here on purpose. APG assigns no modifier chord to\n * `Home`/`End`, so a widget that wanted one would be claiming a combination the\n * pattern never gave it.\n *\n * @example\n * ```ts\n * case \"Home\":\n * case \"End\":\n * if (hasModifierChord(event)) return;\n * ```\n */\nexport function hasModifierChord(event: KeyboardEvent): boolean {\n return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;\n}\n","/**\n * Resolves which of a controller's elements owns a node.\n *\n * A delegated listener hears events from a whole subtree, so the handler's first\n * job is almost always the same question: which item, handle, or control does\n * this `event.target` belong to? The same question comes up for a\n * `MutationRecord.target`, for `document.activeElement`, and for a\n * `relatedTarget` on the way out of a hover region.\n *\n * The answer is `Node.contains()`, which is **inclusive** — an element contains\n * itself — so testing the candidate for identity as well would be redundant.\n *\n * **The guard is what makes this safe to call with a raw event target.**\n * `event.target` is typed `EventTarget | null`, and `contains()` takes a `Node?`:\n * browsers throw `TypeError` for anything else, and `window` — the everyday\n * `EventTarget` that is not a `Node` — is what an event dispatched at it carries.\n * Narrowing here means a caller never has to cast, and the rule cannot drift\n * between the places that ask the question.\n *\n * Scope stays with the caller. These helpers say *which candidate owns the node*,\n * not *whether the node belongs to this controller at all* — a component with\n * nested instances of itself decides that first (by comparing the closest\n * annotated ancestor) and passes the candidates it owns.\n */\n\n/**\n * Index in `candidates` of the first one that is, or contains, `node`.\n *\n * `-1` when none does, when `node` is absent, and when it is an `EventTarget`\n * that is not a `Node`. Candidates are tested in array order, so a nested pair\n * resolves to whichever the caller listed first.\n */\nexport function ownerIndex<T extends Element>(\n candidates: readonly T[],\n node: EventTarget | null | undefined,\n): number {\n if (!(node instanceof Node)) return -1;\n return candidates.findIndex((candidate) => candidate.contains(node));\n}\n\n/**\n * The first candidate that is, or contains, `node`; `null` when none does.\n *\n * A miss indexes the array at `-1`, which reads as `undefined` and lands on the\n * same `null` the absent cases produce.\n */\nexport function ownerOf<T extends Element>(\n candidates: readonly T[],\n node: EventTarget | null | undefined,\n): T | null {\n return candidates[ownerIndex(candidates, node)] ?? null;\n}\n","/**\n * The hidden form fields a widget keeps in step with the state it owns.\n *\n * A widget whose value lives in ARIA attributes submits nothing on its own, so\n * it mirrors that value into `<input type=\"hidden\">` — one field for a single\n * value, a container of generated fields for a set. The mirror is one-way: the\n * widget's own state stays the source of truth and the field is what the form\n * reads.\n *\n * The write and the report are separate calls because they answer to different\n * rules. A mirror is refreshed on connect, after a morph, and whenever the\n * widget repairs itself — none of which a form should treat as an edit. Only\n * the user's own commit reports one, which is why {@link commitField} is never\n * folded into the writes.\n */\n\n/** How a widget's generated fields identify themselves to the form. */\nexport interface GeneratedFieldOptions {\n /** The `name` every generated input submits under. */\n readonly name: string;\n /** The `form` id, for a widget that sits outside the form it submits to. */\n readonly form?: string;\n}\n\n/**\n * Mirrors one value into a hidden field.\n *\n * @returns Whether the field's value moved.\n *\n * @example\n * ```ts\n * if (writeField(this.fieldTarget, String(value)) && userDriven) {\n * commitField(this.fieldTarget);\n * }\n * ```\n */\nexport function writeField(field: HTMLInputElement, value: string): boolean {\n if (field.value === value) return false;\n field.value = value;\n return true;\n}\n\n/**\n * Mirrors a set of values into `container` as generated hidden fields, in the\n * order given.\n *\n * A container that already submits exactly this set is left untouched, children\n * and all — the mirror is refreshed far more often than it moves (every connect,\n * morph and repair), and a rebuild that changes nothing is still a DOM mutation\n * a consumer's observer and a `:empty` rule can see.\n *\n * @returns Whether the submitted set moved — its values, their order, the\n * `name`, or the `form`.\n */\nexport function writeFields(\n container: HTMLElement,\n values: readonly string[],\n { name, form = \"\" }: GeneratedFieldOptions,\n): boolean {\n const current = [...container.children];\n const submits =\n current.length === values.length &&\n current.every(\n (child, index) =>\n child instanceof HTMLInputElement &&\n child.type === \"hidden\" &&\n child.value === values[index] &&\n child.name === name &&\n (child.getAttribute(\"form\") ?? \"\") === form,\n );\n if (submits) return false;\n\n container.replaceChildren(\n ...values.map((value) => {\n const input = document.createElement(\"input\");\n input.type = \"hidden\";\n input.name = name;\n input.value = value;\n if (form !== \"\") input.setAttribute(\"form\", form);\n return input;\n }),\n );\n return true;\n}\n\n/**\n * Reports a committed value from `target` the way a native form control does:\n * one bubbling, non-cancelable `change`.\n *\n * Call it only for a move the user made. Form-level behaviors listen for this —\n * validation re-checks, auto-submit — and a mirror refreshed by a morph or a\n * repair is not something the user submitted.\n *\n * `target` is the element that carries the value: the hidden field for a single\n * mirrored value, the container for a generated set (whose own inputs are\n * replaced on every write), or a widget's own native control where that is what\n * the form reads.\n */\nexport function commitField(target: HTMLElement): void {\n target.dispatchEvent(new Event(\"change\", { bubbles: true }));\n}\n\n/**\n * Reports an edit a widget made on the user's behalf, the way the browser\n * reports its own: one bubbling `input`, then one bubbling `change`.\n *\n * This is for a widget that owns the stepping or picking its *own* native\n * control would otherwise do — writing `control.value` from script fires\n * nothing, so a form listening for either event never hears the edit. Use\n * {@link commitField} instead where the element is a mirror of state held\n * elsewhere: a hidden field has no native edit to imitate, so it reports the\n * commit alone.\n *\n * Call it only for a move the user made, and only where the widget really did\n * the writing — an edit the browser already reported would be doubled.\n */\nexport function commitEdit(control: HTMLElement): void {\n control.dispatchEvent(new Event(\"input\", { bubbles: true }));\n control.dispatchEvent(new Event(\"change\", { bubbles: true }));\n}\n","/**\n * Whether a disabled `<fieldset>` ancestor actually reaches `control`.\n *\n * HTML exempts the contents of a fieldset's **first direct-child `<legend>`**, and\n * the exemption is per fieldset — a control legal in one legend can still be\n * disabled by a second, outer fieldset, so the walk continues upward.\n *\n * Exported on its own for callers that need the disabled-inheritance rule without\n * the rest of {@link canTakeFocus} — a control's availability check, or a `hidden`\n * walk bounded at a widget root, which is a different rule to compose with.\n */\nexport function inheritsFieldsetDisabled(control: HTMLElement): boolean {\n let fieldset: Element | null = control.closest(\"fieldset[disabled]\");\n while (fieldset) {\n const legend = Array.from(fieldset.children).find((child) => child.tagName === \"LEGEND\");\n if (!legend?.contains(control)) return true;\n fieldset = fieldset.parentElement?.closest(\"fieldset[disabled]\") ?? null;\n }\n return false;\n}\n\n/**\n * Whether an element can actually take focus, checked **before** `focus()` runs.\n *\n * A controller that must move focus off a control it is about to disable or hide\n * picks a destination and calls `focus()` on it. If that destination cannot take\n * focus, the call **fails silently**: `hidden` and natively `disabled` elements\n * swallow it, so the caret stays in the subtree that is disappearing and lands on\n * `<body>` a frame later — the exact outcome the rescue exists to prevent, minus\n * any signal that it happened.\n *\n * Testing after the fact is the obvious alternative and is deliberately not the\n * rule. Reading `document.activeElement` back only works in a real browser, and\n * looping over candidates that way performs a real focus move per failure —\n * observable to assistive technology. Checking first costs nothing and catches\n * the cases that actually occur.\n *\n * **`aria-disabled` is not disqualifying.** It is the attribute an author uses\n * for a control that must stay *discoverable*, and the roving contract keeps\n * such items reachable. Only the four conditions that make the platform refuse\n * focus are checked: `hidden` / `inert` (an ancestor's counts),\n * `input[type=\"hidden\"]`, the native `disabled` property, and `disabled`\n * inherited from an ancestor `fieldset`. CSS-only invisibility is handled by\n * {@link isRenderedForFocus} when a consumer needs sequential-focus semantics.\n *\n * Reading `:disabled` instead of walking the fieldset chain would be shorter, but\n * that pseudo-class is not evaluated consistently outside real browsers and this\n * has to be right headlessly too. happy-dom in particular focuses a `<button>`\n * inside a disabled fieldset where a real engine refuses, so the inheritance is\n * spelled out rather than delegated.\n *\n * What a consumer does when nothing survives is its own call: some fall back to\n * their landmark, while a widget whose caret already sits somewhere legitimate\n * refuses the move outright rather than relocating it.\n *\n * @example\n * ```ts\n * const target = candidates.find(canTakeFocus);\n * if (target) target.focus();\n * else {\n * this.#tabindex.lend(this.element); // nothing left: fall back to the landmark\n * this.element.focus();\n * }\n * ```\n *\n * @param element - the candidate destination\n */\nexport function canTakeFocus(element: HTMLElement): boolean {\n if (element.closest(\"[hidden], [inert]\")) return false;\n if (element instanceof HTMLInputElement && element.type === \"hidden\") return false;\n if (!(\"disabled\" in element)) return true;\n if ((element as HTMLElement & { disabled: boolean }).disabled) return false;\n return !inheritsFieldsetDisabled(element);\n}\n\n/** Elements whose semantics or authored attributes can place them in sequential focus order. */\nexport const TAB_STOP_CANDIDATE_SELECTOR = [\n \"a[href]\",\n \"area[href]\",\n \"button\",\n \"input\",\n \"select\",\n \"textarea\",\n \"summary\",\n \"iframe\",\n \"audio[controls]\",\n \"video[controls]\",\n \"[tabindex]\",\n \"[contenteditable]\",\n].join(\",\");\n\n/** Optional browser visibility API used to exclude CSS-hidden candidates. */\ninterface VisibilityCheckable {\n checkVisibility?: (options?: { visibilityProperty?: boolean }) => boolean;\n}\n\n/** Whether CSS visibility allows an otherwise eligible element to participate in focus order. */\nexport function isRenderedForFocus(element: HTMLElement): boolean {\n const check = (element as HTMLElement & VisibilityCheckable).checkVisibility;\n return typeof check === \"function\" ? check.call(element, { visibilityProperty: true }) : true;\n}\n\n/** Parses an authored `tabindex`; invalid syntax has no explicit focus-order meaning. */\nfunction authoredTabindex(element: HTMLElement): number | null {\n const value = element.getAttribute(\"tabindex\");\n if (value === null || !/^[+-]?\\d+$/.test(value.trim())) return null;\n return Number(value);\n}\n\n/** Whether the element's native semantics place it in sequential focus order. */\nfunction hasNativeTabStop(element: HTMLElement): boolean {\n if (element instanceof HTMLAnchorElement || element instanceof HTMLAreaElement) {\n return element.hasAttribute(\"href\");\n }\n if (\n element instanceof HTMLButtonElement ||\n element instanceof HTMLSelectElement ||\n element instanceof HTMLTextAreaElement\n ) {\n return true;\n }\n if (element instanceof HTMLInputElement) return element.type !== \"hidden\";\n if (element instanceof HTMLIFrameElement) return true;\n if (element.tagName === \"AUDIO\" || element.tagName === \"VIDEO\") {\n return element.hasAttribute(\"controls\");\n }\n if (element instanceof HTMLElement && element.tagName === \"SUMMARY\") {\n const details = element.parentElement;\n return (\n details instanceof HTMLDetailsElement &&\n Array.from(details.children).find((child) => child.tagName === \"SUMMARY\") === element\n );\n }\n return false;\n}\n\n/** Whether an explicit `contenteditable` value creates an editable tab stop. */\nfunction hasEditableTabStop(element: HTMLElement): boolean {\n const value = element.getAttribute(\"contenteditable\")?.toLowerCase();\n return value === \"\" || value === \"true\" || value === \"plaintext-only\";\n}\n\n/**\n * Whether an element is a usable sequential Tab stop right now.\n *\n * Native semantics, authored `tabindex`, editable hosts, inherited disabled state,\n * HTML `hidden`/`inert`, and CSS visibility are evaluated together. `aria-disabled`\n * remains focusable because it communicates unavailability without removing the\n * control from discovery order.\n */\nexport function isTabStop(element: HTMLElement): boolean {\n if (!canTakeFocus(element) || !isRenderedForFocus(element)) return false;\n\n const tabindex = authoredTabindex(element);\n if (tabindex !== null) return tabindex >= 0;\n return hasNativeTabStop(element) || hasEditableTabStop(element);\n}\n\n/** Returns every usable sequential Tab stop below `root` in document order. */\nexport function tabStopsWithin(root: ParentNode): HTMLElement[] {\n return Array.from(root.querySelectorAll<HTMLElement>(TAB_STOP_CANDIDATE_SELECTOR)).filter(\n isTabStop,\n );\n}\n\n/** Returns the first usable sequential Tab stop below `root`, if one exists. */\nexport function firstTabStop(root: ParentNode): HTMLElement | null {\n for (const candidate of root.querySelectorAll<HTMLElement>(TAB_STOP_CANDIDATE_SELECTOR)) {\n if (isTabStop(candidate)) return candidate;\n }\n return null;\n}\n\n/** Whether `root` contains at least one usable sequential Tab stop. */\nexport function hasTabStop(root: ParentNode): boolean {\n return firstTabStop(root) !== null;\n}\n","/**\n * Native interactive elements whose built-in activation must not be replaced\n * wholesale by a controller. Deliberately excludes `[tabindex]`: a generic\n * element made focusable is the supported host for several headless patterns.\n * Contenteditable is handled by {@link isInteractiveHost} because its state is\n * inherited and its keywords are ASCII-case-insensitive.\n */\nexport const INTERACTIVE_HOST_SELECTOR =\n \"button, input, select, textarea, label, a[href], area[href], summary, details, audio[controls], video[controls], iframe, object, embed\";\n\n/**\n * Whether an element owns native activation or an inherited editing surface.\n *\n * The `contenteditable` missing and invalid states inherit. Walking explicitly\n * also keeps `contenteditable=\"false\"` as a real boundary inside an editable\n * ancestor instead of treating any ancestor attribute as decisive.\n */\nexport function isInteractiveHost(element: HTMLElement): boolean {\n if (element.matches(INTERACTIVE_HOST_SELECTOR)) return true;\n\n let current: HTMLElement | null = element;\n while (current) {\n const raw = current.getAttribute(\"contenteditable\");\n if (raw !== null) {\n const value = raw.trim().toLowerCase();\n if (value === \"false\") return false;\n if (value === \"\" || value === \"true\" || value === \"plaintext-only\") return true;\n }\n current = current.parentElement;\n }\n return false;\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, logicalArrowStep } from \"../utils/arrow_step\";\nimport { ownerOf } from \"../utils/event_owner\";\nimport { commitField, writeFields } from \"../utils/field_mirror\";\nimport { inheritsFieldsetDisabled } from \"../utils/focus_candidate\";\nimport { isInteractiveHost } from \"../utils/interactive_host\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\nimport { RovingTabindex, rovingMove } from \"../utils/roving_tabindex\";\n\n/** Item attributes whose retained-element changes can alter this controller's contract. */\nconst ITEM_ATTRIBUTES = [\n \"aria-pressed\",\n \"data-value\",\n \"disabled\",\n \"hidden\",\n \"type\",\n \"href\",\n \"contenteditable\",\n \"controls\",\n];\n\n/** Modifier keys that keep document-level Home/End shortcuts outside the widget. */\nconst hasModifier = (event: KeyboardEvent): boolean =>\n event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;\n\n/**\n * Headless, accessible toggle-button group behavior.\n *\n * Markup contract (identifier: `stimeo--toggle-group`):\n * <div data-controller=\"stimeo--toggle-group\"\n * data-stimeo--toggle-group-mode-value=\"single\"\n * data-stimeo--toggle-group-name-value=\"styles[]\"\n * role=\"group\" aria-label=\"Text style\">\n * <div data-stimeo--toggle-group-target=\"fields\"></div>\n * <button type=\"button\" aria-pressed=\"true\" tabindex=\"0\" data-value=\"bold\"\n * data-stimeo--toggle-group-target=\"item\">Bold</button>\n * <!-- more items; exactly one navigable item has tabindex=0 -->\n * </div>\n *\n * Implements the WAI-ARIA APG **Button (toggle)** pattern with **Toolbar**-style\n * roving navigation. Each item's pressed state is `aria-pressed` (the accessible\n * name never changes); the group is a single Tab stop. For strict mutually\n * exclusive selection with radio semantics, use\n * {@link RadioGroupController | Radio Group} instead.\n *\n * `change` dispatches `{ value: string, pressed: boolean, values: string[] }`;\n * `reconcile` dispatches `{ values: string[] }`.\n *\n * @remarks\n * Behavior only — the consumer styles off `[aria-pressed=\"true\"]`. A supported\n * item is either `<button type=\"button\">` or a non-interactive host such as\n * `<div role=\"button\">`; other native interactive elements retain their own\n * activation model and this controller stands down on them.\n *\n * Click handling and keydown handling are delegated from the group, so items\n * added at runtime need only the `item` target. Per-item `data-action` bindings\n * to {@link toggle} and {@link onKeydown} remain supported and are idempotent\n * when combined with delegation.\n *\n * Behavior provided:\n * - Click (or Space/Enter) toggles an item. In `single` mode pressing one item\n * releases the others (0 or 1 pressed); `multiple` allows any number.\n * - `ArrowRight`/`ArrowDown` move focus to the next navigable item,\n * `ArrowLeft`/`ArrowUp` to the previous (wrapping); `Home`/`End` to the\n * first/last. Native-disabled and hidden items are skipped. ARIA-disabled\n * items remain discoverable in the roving order but cannot be activated.\n * - `stimeo--toggle-group:change` is dispatched only for user activation. Its\n * detail is `{ value: string, pressed: boolean, values: string[] }`, where\n * `values` is the DOM-ordered value list of every item left pressed. A press\n * that a listener of its native `change` replaces with a press of its own\n * dispatches no `change`: the newer press reports itself, so every `change`\n * describes the set as it is when it goes out.\n * - `stimeo--toggle-group:reconcile` reports a pressed set the page moved\n * instead — items arriving or leaving, a `mode` change, an in-place\n * `aria-pressed` or `data-value` write, first-wins in `single` mode, a host\n * the group stands down on — once per batch and never on connect. Its detail\n * is `{ values: string[] }` alone, unlike `change`: a page-driven move changes\n * the set, not one item's press.\n * - With a `fields` target the pressed values are mirrored into `name`d hidden\n * inputs so the group can be submitted and read server-side — one per pressed\n * item in DOM order, so `single` mode submits 0 or 1. `form` points them at a\n * `<form>` by id when the group sits outside it. A toggle the user made emits\n * a native bubbling `change` from the container, the way a form control does,\n * so `stimeo--auto-submit` and form-level validation hear it. The mirror is\n * refreshed silently on connect, on item churn, whenever `mode`, `name` or\n * `form` changes, and — through the group's own mutation observer — when the\n * container itself is replaced.\n */\nexport class ToggleGroupController extends Controller<HTMLElement> {\n static override targets = [\"item\", \"fields\"];\n static override values = {\n mode: { type: String, default: \"multiple\" },\n name: { type: String, default: \"values[]\" },\n form: { type: String, default: \"\" },\n };\n static actions = [\"onKeydown\", \"toggle\"] as const;\n static events = [\"change\", \"reconcile\"] as const;\n\n declare readonly itemTargets: HTMLElement[];\n declare readonly fieldsTarget: HTMLElement;\n declare readonly hasFieldsTarget: boolean;\n declare modeValue: string;\n declare nameValue: string;\n declare formValue: string;\n\n readonly #roving = new RovingTabindex(() => this.#managedTargets);\n readonly #handledEvents = new WeakSet<Event>();\n readonly #managedItems = new Set<HTMLElement>();\n readonly #originalTabindex = new Map<HTMLElement, string | null>();\n readonly #ownedPressed = new Set<HTMLElement>();\n readonly #internalPressedValues = new Map<HTMLElement, string>();\n /** One pass per batch of item, Value, and retained-element changes. */\n readonly #pass = new MicrotaskCoalescer(() => this.#reconcileDom());\n #observer: MutationObserver | null = null;\n #connected = false;\n /** The pressed set last published: read on connect, then committed or reported. */\n #committedValues: string[] = [];\n /**\n * How many presses the user has committed, so a press whose reports are still\n * going out can tell that a listener has committed a newer one meanwhile.\n */\n #presses = 0;\n\n /**\n * Normalizes state and establishes one roving entry point. A single authored\n * `tabindex=\"0\"` survives reconnect; otherwise the first pressed, navigable\n * item wins, falling back to the first navigable item. The pressed set it\n * settles on is the one a later move is measured from; connecting reports\n * nothing.\n */\n override connect(): void {\n const currentItems = new Set(this.itemTargets);\n for (const item of this.#managedItems) {\n if (!currentItems.has(item)) this.#releaseItem(item);\n }\n const authoredStops = this.itemTargets.filter(\n (item) =>\n this.#isSupportedHost(item) &&\n item.getAttribute(\"tabindex\") === \"0\" &&\n this.#isNavigable(item),\n );\n const preferred = authoredStops.length === 1 ? authoredStops[0] : null;\n\n for (const item of this.itemTargets) this.#reconcileHost(item, false);\n this.#normalizeSelection();\n this.#ensureTabStop(preferred);\n this.#mirrorFields(false);\n this.#committedValues = this.#pressedValues();\n\n this.element.addEventListener(\"click\", this.#onClickCapture, true);\n this.element.addEventListener(\"keydown\", this.#onKeydownCapture, true);\n this.element.addEventListener(\"click\", this.#onClick);\n this.element.addEventListener(\"keydown\", this.#onKeydown);\n this.element.addEventListener(\"focusin\", this.#onFocusin);\n this.#connected = true;\n // Writes made before observation started cannot produce records and must\n // not be mistaken for a later retained-element morph.\n this.#internalPressedValues.clear();\n this.#pass.activate();\n this.#observeMutations();\n }\n\n /**\n * Releases every listener, the observer, and a pass still queued, while\n * retaining DOM state for Turbo cache/reconnect.\n */\n override disconnect(): void {\n this.#connected = false;\n this.#pass.cancel();\n this.element.removeEventListener(\"click\", this.#onClickCapture, true);\n this.element.removeEventListener(\"keydown\", this.#onKeydownCapture, true);\n this.element.removeEventListener(\"click\", this.#onClick);\n this.element.removeEventListener(\"keydown\", this.#onKeydown);\n this.element.removeEventListener(\"focusin\", this.#onFocusin);\n this.#observer?.disconnect();\n this.#observer = null;\n this.#internalPressedValues.clear();\n }\n\n /** Drops a newly connected item from the Tab sequence before the batch is reconciled. */\n itemTargetConnected(item: HTMLElement): void {\n if (!this.#connected) return;\n this.#reconcileHost(item, true);\n this.#pass.schedule();\n }\n\n /** Restores attributes owned only while an element is an item, then reconciles the batch. */\n itemTargetDisconnected(item: HTMLElement): void {\n if (!this.#connected) return;\n this.#releaseItem(item);\n this.#pass.schedule();\n }\n\n /** Reconciles the single-selection invariant when the Stimulus Value changes. */\n modeValueChanged(): void {\n this.#pass.schedule();\n }\n\n /** Rebuilds the submitted fields when the public name changes at runtime. */\n nameValueChanged(): void {\n this.#pass.schedule();\n }\n\n /** Repoints the submitted fields when the owning form changes at runtime. */\n formValueChanged(): void {\n this.#pass.schedule();\n }\n\n /**\n * Toggles the action's item. Per-item action wiring is optional because click\n * is also delegated from the group.\n */\n toggle(event: Event): void {\n if (event.defaultPrevented) return;\n const item = event.currentTarget as HTMLElement | null;\n if (!item || !this.itemTargets.includes(item)) return;\n this.#handledEvents.add(event);\n this.#toggleItem(item);\n }\n\n /**\n * Moves focus or activates the action's item. Per-item action wiring is\n * optional because keydown is also delegated from the group.\n */\n onKeydown(event: KeyboardEvent): void {\n const item = event.currentTarget as HTMLElement | null;\n if (!item || !this.itemTargets.includes(item)) return;\n this.#handleKeydown(event, item);\n }\n\n /** Blocks disabled activation before per-item or consumer event handlers run. */\n readonly #onClickCapture = (event: MouseEvent): void => {\n const item = this.#itemForEventTarget(event.target);\n if (!item || !this.#isSupportedHost(item) || !this.#isActivationDisabled(item)) return;\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n\n /** Blocks disabled keyboard activation while leaving navigation keys available. */\n readonly #onKeydownCapture = (event: KeyboardEvent): void => {\n if (event.key !== \" \" && event.key !== \"Enter\") return;\n const item = this.#itemForEventTarget(event.target);\n if (!item || !this.#isSupportedHost(item) || !this.#isActivationDisabled(item)) return;\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n\n /** Delegated click path for static and runtime-added items without actions. */\n readonly #onClick = (event: MouseEvent): void => {\n if (this.#handledEvents.delete(event) || event.defaultPrevented) return;\n const item = this.#itemForEventTarget(event.target);\n if (item) this.#toggleItem(item);\n };\n\n /** Delegated keydown path for static and runtime-added items without actions. */\n readonly #onKeydown = (event: KeyboardEvent): void => {\n const item = this.#itemForEventTarget(event.target);\n if (item) this.#handleKeydown(event, item);\n };\n\n /** Keeps programmatic and pointer focus as the group's next Tab entry point. */\n readonly #onFocusin = (event: FocusEvent): void => {\n const item = this.#itemForEventTarget(event.target);\n if (!item || !this.#isNavigable(item)) return;\n this.#setActive(item);\n };\n\n /** Applies the APG navigation and activation key map to one supported item. */\n #handleKeydown(event: KeyboardEvent, item: HTMLElement): void {\n if (event.defaultPrevented || !this.#isSupportedHost(item)) return;\n if (event.isComposing) return;\n if (isReservedArrowChord(event)) return;\n if ((event.key === \"Home\" || event.key === \"End\") && hasModifier(event)) return;\n\n if (!this.#managedItems.has(item)) this.#reconcileHost(item, true);\n this.#ensureTabStop();\n const items = this.#managedTargets;\n const current = items.indexOf(item);\n\n if (event.key === \" \" || event.key === \"Enter\") {\n if (this.#isActivationDisabled(item)) {\n event.preventDefault();\n event.stopImmediatePropagation();\n return;\n }\n if (item instanceof HTMLButtonElement) {\n if (event.repeat) event.preventDefault();\n return;\n }\n event.preventDefault();\n if (!event.repeat) this.#toggleItem(item);\n return;\n }\n\n const step = logicalArrowStep(event.key, this.element);\n let destination: HTMLElement | undefined;\n if (step !== 0) {\n destination = this.#nextNavigable(current, step);\n } else if (event.key === \"Home\") {\n destination = this.#navigableItems[0];\n } else if (event.key === \"End\") {\n const navigable = this.#navigableItems;\n destination = navigable[navigable.length - 1];\n } else {\n return;\n }\n\n event.preventDefault();\n if (destination) this.#setActive(destination, true);\n }\n\n /**\n * Applies one user toggle and dispatches the documented change detail. The set\n * it leaves is taken as published before either report goes out, so a\n * listener that presses again or writes `aria-pressed` is measured from it. A\n * listener of the native `change` that presses again has had that newer press\n * reported, so this press's `change` would describe a set that is gone and is\n * not dispatched.\n *\n * @stimeoRuntimeOnly `mode` is the rule this one press follows; the lasting single-press\n * normalisation is a render root of its own.\n */\n #toggleItem(item: HTMLElement): void {\n if (!this.#isSupportedHost(item) || this.#isActivationDisabled(item)) return;\n if (!this.#managedItems.has(item)) this.#reconcileHost(item, true);\n const willPress = !this.#isPressed(item);\n if (this.modeValue === \"single\") {\n for (const other of this.#managedTargets)\n this.#setPressed(other, other === item && willPress);\n } else {\n this.#setPressed(item, willPress);\n }\n this.#setActive(item);\n const values = this.#pressedValues();\n this.#committedValues = values;\n this.#presses += 1;\n const press = this.#presses;\n this.#mirrorFields(true);\n if (press !== this.#presses) return;\n this.dispatch(\"change\", {\n detail: { value: this.#itemValue(item), pressed: willPress, values: [...values] },\n });\n }\n\n /**\n * Mirrors the pressed values into the optional fields container.\n *\n * @stimeoRenderRoot\n */\n #mirrorFields(notify: boolean): void {\n if (!this.hasFieldsTarget) return;\n const options = { name: this.nameValue, form: this.formValue };\n if (writeFields(this.fieldsTarget, this.#pressedValues(), options) && notify) {\n commitField(this.fieldsTarget);\n }\n }\n\n /**\n * Reconciles supported hosts, pressed state, the roving invariant, and the\n * fields after the page changed the group, then reports a pressed set that\n * moved. Records still queued are read first, so an author's write is not lost\n * when observation is suspended for this pass's own writes; observation resumes\n * before the report, so an edit a listener makes is seen by the next pass.\n */\n #reconcileDom(): void {\n const observer = this.#observer;\n if (observer) {\n this.#releaseAuthoredPressed(observer.takeRecords());\n observer.disconnect();\n }\n for (const item of this.itemTargets) this.#reconcileHost(item, true);\n this.#normalizeSelection();\n this.#ensureTabStop();\n this.#mirrorFields(false);\n // Writes made while observation was suspended produce no records.\n this.#internalPressedValues.clear();\n if (observer) this.#observeWith(observer);\n this.#reportMove();\n }\n\n /** Reports a pressed set that moved since the one this group last published. */\n #reportMove(): void {\n const values = this.#pressedValues();\n const previous = this.#committedValues;\n if (values.length === previous.length && values.every((value, i) => value === previous[i])) {\n return;\n }\n this.#committedValues = values;\n this.dispatch(\"reconcile\", { detail: { values: [...values] } });\n }\n\n /** Begins or ends ownership according to the item's current host semantics. */\n #reconcileHost(item: HTMLElement, dropFromTabSequence: boolean): void {\n if (!this.#isSupportedHost(item)) {\n this.#releaseItem(item);\n return;\n }\n if (!this.#managedItems.has(item)) {\n this.#managedItems.add(item);\n this.#originalTabindex.set(item, item.getAttribute(\"tabindex\"));\n if (dropFromTabSequence) item.tabIndex = -1;\n }\n this.#normalizePressed(item);\n }\n\n /** Restores only defaults owned because an element belonged to this group. */\n #releaseItem(item: HTMLElement): void {\n if (!this.#managedItems.delete(item)) return;\n const original = this.#originalTabindex.get(item);\n if (original === null) item.removeAttribute(\"tabindex\");\n else if (original !== undefined) item.setAttribute(\"tabindex\", original);\n this.#originalTabindex.delete(item);\n if (this.#ownedPressed.delete(item)) item.removeAttribute(\"aria-pressed\");\n this.#internalPressedValues.delete(item);\n }\n\n /** Supplies a missing pressed state and normalizes invalid ARIA tokens. */\n #normalizePressed(item: HTMLElement): void {\n const value = item.getAttribute(\"aria-pressed\");\n if (value === null) {\n this.#ownedPressed.add(item);\n this.#internalPressedValues.set(item, \"false\");\n item.setAttribute(\"aria-pressed\", \"false\");\n } else if (value !== \"true\" && value !== \"false\") {\n item.setAttribute(\"aria-pressed\", \"false\");\n }\n }\n\n /**\n * Makes the first DOM-ordered pressed item the sole pressed item in single mode.\n *\n * @stimeoRenderRoot\n */\n #normalizeSelection(): void {\n for (const item of this.#managedTargets) this.#normalizePressed(item);\n if (this.modeValue !== \"single\") return;\n let found = false;\n for (const item of this.#managedTargets) {\n if (!this.#isPressed(item)) continue;\n if (!found) found = true;\n else this.#setPressed(item, false);\n }\n }\n\n /** Keeps one navigable Tab stop, preferring current DOM state after initial connect. */\n #ensureTabStop(initialPreference?: HTMLElement | null): void {\n const navigable = this.#navigableItems;\n let active: HTMLElement | undefined;\n if (initialPreference !== undefined) {\n active = initialPreference ?? undefined;\n } else {\n const current = this.#managedTargets.filter(\n (item) => item.tabIndex === 0 && this.#isNavigable(item),\n );\n if (current.length === 1) active = current[0];\n }\n active ??= navigable.find((item) => this.#isPressed(item));\n active ??= navigable[0];\n this.#setActive(active ?? null);\n }\n\n /** Moves through the full item order until a navigable destination is found. */\n #nextNavigable(fromIndex: number, delta: 1 | -1): HTMLElement | undefined {\n const items = this.#managedTargets;\n let index = fromIndex;\n for (let step = 0; step < items.length; step++) {\n index = rovingMove(index, items.length, delta, \"wrap\");\n const candidate = items[index];\n if (candidate && this.#isNavigable(candidate)) return candidate;\n }\n return undefined;\n }\n\n /** Assigns the single roving Tab stop and optionally moves DOM focus. */\n #setActive(item: HTMLElement | null, focus = false): void {\n this.#roving.setActive(this.#managedTargets.indexOf(item as HTMLElement), { focus });\n }\n\n /** Finds this group's item containing an event target, excluding nested groups. */\n #itemForEventTarget(target: EventTarget | null): HTMLElement | null {\n if (!this.#ownsEventTarget(target)) return null;\n return ownerOf(this.itemTargets, target);\n }\n\n /** Whether the closest Toggle Group scope around a target is this instance. */\n #ownsEventTarget(target: EventTarget | null): boolean {\n return (\n target instanceof Element &&\n target.closest(`[data-controller~=\"${this.identifier}\"]`) === this.element\n );\n }\n\n /** Hosts whose activation model can be owned without conflicting native behavior. */\n #isSupportedHost(item: HTMLElement): boolean {\n if (item instanceof HTMLButtonElement) return item.type === \"button\";\n return !isInteractiveHost(item);\n }\n\n /** Items eligible for roving focus (ARIA-disabled deliberately remains eligible). */\n #isNavigable(item: HTMLElement): boolean {\n if (!this.#isSupportedHost(item) || this.#isHidden(item)) return false;\n if (!(item instanceof HTMLButtonElement)) return true;\n return !item.disabled && !inheritsFieldsetDisabled(item);\n }\n\n /** Whether hidden applies on the path from an item up to the group root. */\n #isHidden(item: HTMLElement): boolean {\n let current: HTMLElement | null = item;\n while (current && current !== this.element) {\n if (current.hasAttribute(\"hidden\")) return true;\n current = current.parentElement;\n }\n return false;\n }\n\n /** Whether ARIA, visibility, or native HTML semantics suppress activation. */\n #isActivationDisabled(item: HTMLElement): boolean {\n if (!this.#isNavigable(item)) return true;\n let current: HTMLElement | null = item;\n while (current) {\n if (current.getAttribute(\"aria-disabled\") === \"true\") return true;\n current = current.parentElement;\n }\n return false;\n }\n\n /** Releases default ownership when a Turbo morph authors `aria-pressed`. */\n #releaseAuthoredPressed(records: MutationRecord[]): void {\n for (const record of records) {\n if (record.attributeName !== \"aria-pressed\") continue;\n const item = record.target as HTMLElement;\n const value = item.getAttribute(\"aria-pressed\");\n if (value !== null && this.#internalPressedValues.get(item) !== value) {\n this.#ownedPressed.delete(item);\n }\n }\n this.#internalPressedValues.clear();\n }\n\n /** Watches target membership, retained item hosts/state, and inherited host/fieldset state. */\n #observeMutations(): void {\n const observer = new MutationObserver((records) => {\n this.#releaseAuthoredPressed(records);\n this.#pass.schedule();\n });\n this.#observer = observer;\n this.#observeWith(observer);\n }\n\n /** Registers every root and ancestor observation on one observer instance. */\n #observeWith(observer: MutationObserver): void {\n observer.observe(this.element, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: ITEM_ATTRIBUTES,\n });\n let ancestor = this.element.parentElement;\n while (ancestor) {\n observer.observe(ancestor, {\n attributes: true,\n attributeFilter: [\"contenteditable\", \"disabled\"],\n });\n ancestor = ancestor.parentElement;\n }\n }\n\n /** Supported targets currently managed by the roving primitive. */\n get #managedTargets(): HTMLElement[] {\n return this.itemTargets.filter((item) => this.#managedItems.has(item));\n }\n\n /** Managed items eligible for the roving Tab stop. */\n get #navigableItems(): HTMLElement[] {\n return this.#managedTargets.filter((item) => this.#isNavigable(item));\n }\n\n /** Whether an item is currently pressed. */\n #isPressed(item: HTMLElement): boolean {\n return item.getAttribute(\"aria-pressed\") === \"true\";\n }\n\n /** Reflects pressed state while distinguishing controller writes from authored morphs. */\n #setPressed(item: HTMLElement, pressed: boolean): void {\n const value = pressed ? \"true\" : \"false\";\n this.#internalPressedValues.set(item, value);\n item.setAttribute(\"aria-pressed\", value);\n }\n\n /** The DOM-ordered values of every currently pressed managed item. */\n #pressedValues(): string[] {\n return this.#managedTargets\n .filter((item) => this.#isPressed(item))\n .map((item) => this.#itemValue(item));\n }\n\n /** An item's value (`data-value`, defaulting to empty). */\n #itemValue(item: HTMLElement): string {\n return item.getAttribute(\"data-value\") ?? \"\";\n }\n}\n"]}