stimeo-ui 0.2.0 → 0.3.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 (227) hide show
  1. package/CHANGELOG.md +163 -0
  2. package/dist/cable/index.d.ts +16 -16
  3. package/dist/cable/index.js.map +1 -1
  4. package/dist/controllers/accordion_controller.d.ts +3 -2
  5. package/dist/controllers/accordion_controller.js +10 -0
  6. package/dist/controllers/accordion_controller.js.map +1 -1
  7. package/dist/controllers/alert_dialog_controller.d.ts +64 -0
  8. package/dist/controllers/alert_dialog_controller.js +318 -0
  9. package/dist/controllers/alert_dialog_controller.js.map +1 -0
  10. package/dist/controllers/breadcrumb_controller.d.ts +97 -10
  11. package/dist/controllers/breadcrumb_controller.js +225 -13
  12. package/dist/controllers/breadcrumb_controller.js.map +1 -1
  13. package/dist/controllers/calendar_controller.d.ts +11 -1
  14. package/dist/controllers/calendar_controller.js +89 -22
  15. package/dist/controllers/calendar_controller.js.map +1 -1
  16. package/dist/controllers/carousel_controller.d.ts +115 -0
  17. package/dist/controllers/carousel_controller.js +313 -0
  18. package/dist/controllers/carousel_controller.js.map +1 -0
  19. package/dist/controllers/clipboard_controller.d.ts +72 -0
  20. package/dist/controllers/clipboard_controller.js +144 -0
  21. package/dist/controllers/clipboard_controller.js.map +1 -0
  22. package/dist/controllers/collapsible_controller.d.ts +70 -0
  23. package/dist/controllers/collapsible_controller.js +327 -0
  24. package/dist/controllers/collapsible_controller.js.map +1 -0
  25. package/dist/controllers/color_picker_controller.d.ts +87 -0
  26. package/dist/controllers/color_picker_controller.js +252 -0
  27. package/dist/controllers/color_picker_controller.js.map +1 -0
  28. package/dist/controllers/combobox_controller.d.ts +14 -1
  29. package/dist/controllers/combobox_controller.js +162 -23
  30. package/dist/controllers/combobox_controller.js.map +1 -1
  31. package/dist/controllers/command_palette_controller.d.ts +2 -0
  32. package/dist/controllers/command_palette_controller.js +194 -17
  33. package/dist/controllers/command_palette_controller.js.map +1 -1
  34. package/dist/controllers/confirm_controller.js.map +1 -1
  35. package/dist/controllers/context_menu_controller.d.ts +7 -6
  36. package/dist/controllers/context_menu_controller.js +32 -10
  37. package/dist/controllers/context_menu_controller.js.map +1 -1
  38. package/dist/controllers/count_up_controller.js +8 -1
  39. package/dist/controllers/count_up_controller.js.map +1 -1
  40. package/dist/controllers/currency_input_controller.d.ts +72 -0
  41. package/dist/controllers/currency_input_controller.js +147 -0
  42. package/dist/controllers/currency_input_controller.js.map +1 -0
  43. package/dist/controllers/data_grid_controller.d.ts +89 -0
  44. package/dist/controllers/data_grid_controller.js +246 -0
  45. package/dist/controllers/data_grid_controller.js.map +1 -0
  46. package/dist/controllers/date_range_picker_controller.d.ts +88 -0
  47. package/dist/controllers/date_range_picker_controller.js +441 -0
  48. package/dist/controllers/date_range_picker_controller.js.map +1 -0
  49. package/dist/controllers/dialog_controller.js.map +1 -1
  50. package/dist/controllers/dismissible_controller.d.ts +57 -0
  51. package/dist/controllers/dismissible_controller.js +117 -0
  52. package/dist/controllers/dismissible_controller.js.map +1 -0
  53. package/dist/controllers/drawer_controller.d.ts +96 -0
  54. package/dist/controllers/drawer_controller.js +630 -0
  55. package/dist/controllers/drawer_controller.js.map +1 -0
  56. package/dist/controllers/dropdown_controller.d.ts +1 -2
  57. package/dist/controllers/dropdown_controller.js.map +1 -1
  58. package/dist/controllers/editable_controller.d.ts +73 -0
  59. package/dist/controllers/editable_controller.js +169 -0
  60. package/dist/controllers/editable_controller.js.map +1 -0
  61. package/dist/controllers/file_dropzone_controller.d.ts +92 -0
  62. package/dist/controllers/file_dropzone_controller.js +165 -0
  63. package/dist/controllers/file_dropzone_controller.js.map +1 -0
  64. package/dist/controllers/filter_controller.d.ts +60 -0
  65. package/dist/controllers/filter_controller.js +86 -0
  66. package/dist/controllers/filter_controller.js.map +1 -0
  67. package/dist/controllers/flash_controller.js +36 -5
  68. package/dist/controllers/flash_controller.js.map +1 -1
  69. package/dist/controllers/focus_controller.d.ts +1 -1
  70. package/dist/controllers/focus_controller.js.map +1 -1
  71. package/dist/controllers/form_field_controller.js.map +1 -1
  72. package/dist/controllers/form_validation_controller.js +1 -1
  73. package/dist/controllers/form_validation_controller.js.map +1 -1
  74. package/dist/controllers/highlight_controller.js +6 -4
  75. package/dist/controllers/highlight_controller.js.map +1 -1
  76. package/dist/controllers/hover_card_controller.d.ts +1 -1
  77. package/dist/controllers/hover_card_controller.js.map +1 -1
  78. package/dist/controllers/intersection_controller.js +67 -19
  79. package/dist/controllers/intersection_controller.js.map +1 -1
  80. package/dist/controllers/lazy_frame_controller.js +54 -11
  81. package/dist/controllers/lazy_frame_controller.js.map +1 -1
  82. package/dist/controllers/listbox_controller.d.ts +9 -2
  83. package/dist/controllers/listbox_controller.js +257 -53
  84. package/dist/controllers/listbox_controller.js.map +1 -1
  85. package/dist/controllers/local_time_controller.js +2 -2
  86. package/dist/controllers/local_time_controller.js.map +1 -1
  87. package/dist/controllers/masonry_controller.d.ts +54 -0
  88. package/dist/controllers/masonry_controller.js +142 -0
  89. package/dist/controllers/masonry_controller.js.map +1 -0
  90. package/dist/controllers/menu_controller.d.ts +29 -11
  91. package/dist/controllers/menu_controller.js +104 -17
  92. package/dist/controllers/menu_controller.js.map +1 -1
  93. package/dist/controllers/menubar_controller.d.ts +142 -0
  94. package/dist/controllers/menubar_controller.js +785 -0
  95. package/dist/controllers/menubar_controller.js.map +1 -0
  96. package/dist/controllers/meter_controller.js.map +1 -1
  97. package/dist/controllers/multi_select_controller.d.ts +141 -0
  98. package/dist/controllers/multi_select_controller.js +755 -0
  99. package/dist/controllers/multi_select_controller.js.map +1 -0
  100. package/dist/controllers/navigation_menu_controller.d.ts +146 -0
  101. package/dist/controllers/navigation_menu_controller.js +511 -0
  102. package/dist/controllers/navigation_menu_controller.js.map +1 -0
  103. package/dist/controllers/nested_form_controller.d.ts +4 -5
  104. package/dist/controllers/nested_form_controller.js.map +1 -1
  105. package/dist/controllers/number_input_controller.d.ts +1 -1
  106. package/dist/controllers/number_input_controller.js +7 -0
  107. package/dist/controllers/number_input_controller.js.map +1 -1
  108. package/dist/controllers/otp_controller.js +18 -1
  109. package/dist/controllers/otp_controller.js.map +1 -1
  110. package/dist/controllers/overflow_indicator_controller.d.ts +15 -6
  111. package/dist/controllers/overflow_indicator_controller.js +246 -27
  112. package/dist/controllers/overflow_indicator_controller.js.map +1 -1
  113. package/dist/controllers/overflow_menu_controller.d.ts +78 -19
  114. package/dist/controllers/overflow_menu_controller.js +381 -57
  115. package/dist/controllers/overflow_menu_controller.js.map +1 -1
  116. package/dist/controllers/pagination_controller.d.ts +36 -5
  117. package/dist/controllers/pagination_controller.js +163 -32
  118. package/dist/controllers/pagination_controller.js.map +1 -1
  119. package/dist/controllers/password_reveal_controller.d.ts +49 -0
  120. package/dist/controllers/password_reveal_controller.js +117 -0
  121. package/dist/controllers/password_reveal_controller.js.map +1 -0
  122. package/dist/controllers/persist_controller.js +6 -6
  123. package/dist/controllers/persist_controller.js.map +1 -1
  124. package/dist/controllers/pointer_drag_controller.d.ts +2 -3
  125. package/dist/controllers/pointer_drag_controller.js +9 -1
  126. package/dist/controllers/pointer_drag_controller.js.map +1 -1
  127. package/dist/controllers/popover_controller.d.ts +1 -2
  128. package/dist/controllers/popover_controller.js +2 -2
  129. package/dist/controllers/popover_controller.js.map +1 -1
  130. package/dist/controllers/portal_controller.d.ts +4 -4
  131. package/dist/controllers/portal_controller.js.map +1 -1
  132. package/dist/controllers/progress_controller.js.map +1 -1
  133. package/dist/controllers/radio_group_controller.js +22 -3
  134. package/dist/controllers/radio_group_controller.js.map +1 -1
  135. package/dist/controllers/range_slider_controller.d.ts +97 -0
  136. package/dist/controllers/range_slider_controller.js +192 -0
  137. package/dist/controllers/range_slider_controller.js.map +1 -0
  138. package/dist/controllers/rating_controller.js +16 -2
  139. package/dist/controllers/rating_controller.js.map +1 -1
  140. package/dist/controllers/read_more_controller.d.ts +52 -0
  141. package/dist/controllers/read_more_controller.js +238 -0
  142. package/dist/controllers/read_more_controller.js.map +1 -0
  143. package/dist/controllers/reading_progress_controller.js.map +1 -1
  144. package/dist/controllers/resizable_controller.d.ts +3 -1
  145. package/dist/controllers/resizable_controller.js +65 -1
  146. package/dist/controllers/resizable_controller.js.map +1 -1
  147. package/dist/controllers/roving_controller.js +17 -2
  148. package/dist/controllers/roving_controller.js.map +1 -1
  149. package/dist/controllers/scroll_area_controller.js +101 -14
  150. package/dist/controllers/scroll_area_controller.js.map +1 -1
  151. package/dist/controllers/scroll_restore_controller.d.ts +54 -0
  152. package/dist/controllers/scroll_restore_controller.js +93 -0
  153. package/dist/controllers/scroll_restore_controller.js.map +1 -0
  154. package/dist/controllers/scroll_visibility_controller.d.ts +6 -3
  155. package/dist/controllers/scroll_visibility_controller.js +40 -6
  156. package/dist/controllers/scroll_visibility_controller.js.map +1 -1
  157. package/dist/controllers/scrollspy_controller.d.ts +64 -15
  158. package/dist/controllers/scrollspy_controller.js +369 -74
  159. package/dist/controllers/scrollspy_controller.js.map +1 -1
  160. package/dist/controllers/separator_controller.d.ts +69 -0
  161. package/dist/controllers/separator_controller.js +96 -0
  162. package/dist/controllers/separator_controller.js.map +1 -0
  163. package/dist/controllers/sidebar_controller.d.ts +107 -0
  164. package/dist/controllers/sidebar_controller.js +761 -0
  165. package/dist/controllers/sidebar_controller.js.map +1 -0
  166. package/dist/controllers/skeleton_controller.js +1 -1
  167. package/dist/controllers/skeleton_controller.js.map +1 -1
  168. package/dist/controllers/slider_controller.d.ts +11 -1
  169. package/dist/controllers/slider_controller.js +32 -6
  170. package/dist/controllers/slider_controller.js.map +1 -1
  171. package/dist/controllers/sortable_controller.d.ts +3 -1
  172. package/dist/controllers/sortable_controller.js +34 -3
  173. package/dist/controllers/sortable_controller.js.map +1 -1
  174. package/dist/controllers/spinner_controller.js +1 -1
  175. package/dist/controllers/spinner_controller.js.map +1 -1
  176. package/dist/controllers/stepper_controller.d.ts +4 -0
  177. package/dist/controllers/stepper_controller.js +28 -12
  178. package/dist/controllers/stepper_controller.js.map +1 -1
  179. package/dist/controllers/stick_to_bottom_controller.d.ts +5 -6
  180. package/dist/controllers/stick_to_bottom_controller.js +9 -4
  181. package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
  182. package/dist/controllers/sticky_observer_controller.d.ts +17 -4
  183. package/dist/controllers/sticky_observer_controller.js +109 -20
  184. package/dist/controllers/sticky_observer_controller.js.map +1 -1
  185. package/dist/controllers/submit_once_controller.d.ts +2 -2
  186. package/dist/controllers/submit_once_controller.js.map +1 -1
  187. package/dist/controllers/switch_controller.js +1 -0
  188. package/dist/controllers/switch_controller.js.map +1 -1
  189. package/dist/controllers/tabs_controller.d.ts +13 -4
  190. package/dist/controllers/tabs_controller.js +26 -3
  191. package/dist/controllers/tabs_controller.js.map +1 -1
  192. package/dist/controllers/tags_input_controller.d.ts +91 -0
  193. package/dist/controllers/tags_input_controller.js +295 -0
  194. package/dist/controllers/tags_input_controller.js.map +1 -0
  195. package/dist/controllers/theme_controller.d.ts +1 -1
  196. package/dist/controllers/theme_controller.js +42 -13
  197. package/dist/controllers/theme_controller.js.map +1 -1
  198. package/dist/controllers/time_picker_controller.d.ts +67 -0
  199. package/dist/controllers/time_picker_controller.js +231 -0
  200. package/dist/controllers/time_picker_controller.js.map +1 -0
  201. package/dist/controllers/toast_controller.d.ts +5 -14
  202. package/dist/controllers/toast_controller.js +40 -14
  203. package/dist/controllers/toast_controller.js.map +1 -1
  204. package/dist/controllers/toggle_group_controller.js +23 -2
  205. package/dist/controllers/toggle_group_controller.js.map +1 -1
  206. package/dist/controllers/toolbar_controller.d.ts +53 -13
  207. package/dist/controllers/toolbar_controller.js +230 -31
  208. package/dist/controllers/toolbar_controller.js.map +1 -1
  209. package/dist/controllers/tooltip_controller.d.ts +1 -1
  210. package/dist/controllers/tooltip_controller.js.map +1 -1
  211. package/dist/controllers/transition_controller.d.ts +14 -8
  212. package/dist/controllers/transition_controller.js +153 -38
  213. package/dist/controllers/transition_controller.js.map +1 -1
  214. package/dist/controllers/tree_view_controller.d.ts +135 -0
  215. package/dist/controllers/tree_view_controller.js +691 -0
  216. package/dist/controllers/tree_view_controller.js.map +1 -0
  217. package/dist/index.d.ts +27 -1818
  218. package/dist/index.js +4256 -915
  219. package/dist/index.js.map +1 -1
  220. package/dist/inspector/cli.d.ts +375 -39
  221. package/dist/inspector/cli.js +228 -14
  222. package/dist/inspector/cli.js.map +1 -1
  223. package/dist/inspector/cli_bin.js +419 -48
  224. package/dist/inspector/cli_bin.js.map +1 -1
  225. package/dist/inspector/examples.json +26 -26
  226. package/dist/inspector/manifest.json +1054 -127
  227. package/package.json +5 -6
@@ -2,6 +2,61 @@ import { Controller } from '@hotwired/stimulus';
2
2
 
3
3
  // src/controllers/overflow_indicator_controller.ts
4
4
 
5
+ // src/utils/blur_deferral.ts
6
+ var BlurDeferral = class {
7
+ /** Elements currently holding an update back, mapped to their `blur` listener. */
8
+ #pending = /* @__PURE__ */ new Map();
9
+ /** Called after a pending element blurs and has been detached. */
10
+ #onRelease;
11
+ /** @param onRelease - Invoked once `element` actually blurs; never on `release`. */
12
+ constructor(onRelease) {
13
+ this.#onRelease = onRelease;
14
+ }
15
+ /** Number of elements currently holding an update back. */
16
+ get size() {
17
+ return this.#pending.size;
18
+ }
19
+ /** Snapshot of the pending elements, safe to iterate while releasing them. */
20
+ get elements() {
21
+ return [...this.#pending.keys()];
22
+ }
23
+ /** Whether `element` is currently holding an update back. */
24
+ has(element) {
25
+ return this.#pending.has(element);
26
+ }
27
+ /** Holds an update back until `element` blurs. Idempotent (no stacked listeners). */
28
+ defer(element) {
29
+ if (this.#pending.has(element)) return;
30
+ const onBlur = () => {
31
+ this.#detach(element);
32
+ this.#onRelease(element);
33
+ };
34
+ this.#pending.set(element, onBlur);
35
+ element.addEventListener("blur", onBlur);
36
+ }
37
+ /** Defers `element` as the only pending entry, cancelling any others. */
38
+ deferOnly(element) {
39
+ for (const pending of this.elements) {
40
+ if (pending !== element) this.#detach(pending);
41
+ }
42
+ this.defer(element);
43
+ }
44
+ /** Cancels `element`'s deferral without completing it; no-ops when not pending. */
45
+ release(element) {
46
+ this.#detach(element);
47
+ }
48
+ /** Cancels every deferral without completing any of them. */
49
+ releaseAll() {
50
+ for (const element of this.elements) this.#detach(element);
51
+ }
52
+ /** Removes the `blur` listener for `element` and forgets it. */
53
+ #detach(element) {
54
+ const onBlur = this.#pending.get(element);
55
+ if (onBlur) element.removeEventListener("blur", onBlur);
56
+ this.#pending.delete(element);
57
+ }
58
+ };
59
+
5
60
  // src/utils/layout_observer.ts
6
61
  var LayoutObserver = class {
7
62
  #callback;
@@ -58,7 +113,30 @@ var LayoutObserver = class {
58
113
  }
59
114
  };
60
115
 
116
+ // src/utils/logical_scroll.ts
117
+ function isRtl(element) {
118
+ return window.getComputedStyle(element).direction === "rtl";
119
+ }
120
+ function logicalScrollMetrics(element, horizontal) {
121
+ const max = Math.max(
122
+ 0,
123
+ horizontal ? element.scrollWidth - element.clientWidth : element.scrollHeight - element.clientHeight
124
+ );
125
+ const raw = horizontal ? element.scrollLeft : element.scrollTop;
126
+ const position = horizontal && isRtl(element) ? -raw : raw;
127
+ return { position: Math.min(max, Math.max(0, position)), max };
128
+ }
129
+ function physicalScrollDelta(element, horizontal, logicalDelta) {
130
+ return horizontal && isRtl(element) ? -logicalDelta : logicalDelta;
131
+ }
132
+
133
+ // src/utils/reduced_motion.ts
134
+ function prefersReducedMotion() {
135
+ return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
136
+ }
137
+
61
138
  // src/controllers/overflow_indicator_controller.ts
139
+ var DIRECTION_BUTTON_SELECTOR = "[data-stimeo--overflow-indicator-direction-param]";
62
140
  var OverflowIndicatorController = class extends Controller {
63
141
  static targets = ["viewport"];
64
142
  static values = {
@@ -67,38 +145,59 @@ var OverflowIndicatorController = class extends Controller {
67
145
  };
68
146
  static actions = ["scrollByPage", "update"];
69
147
  static events = ["change"];
70
- #layout = new LayoutObserver(() => this.update());
148
+ #layout = new LayoutObserver(() => {
149
+ if (this.#connected) this.update();
150
+ });
151
+ #connected = false;
152
+ #observedViewport = null;
153
+ #observedContent = /* @__PURE__ */ new Set();
71
154
  #mutationObserver = null;
155
+ /**
156
+ * Boundary buttons whose native `disabled` is held back while they hold focus.
157
+ *
158
+ * Completing the deferral is what actually disables the button, so the release
159
+ * callback — unlike {@link #cancelPendingButtonDisable} — applies it.
160
+ */
161
+ #pendingButtonDisables = new BlurDeferral((button) => {
162
+ this.#restorePendingMarkers(button);
163
+ if (!button.disabled) this.#disableButton(button);
164
+ });
72
165
  /** Last reported room, so `change` fires only on transitions. */
73
166
  #state = null;
74
167
  connect() {
75
- if (!this.hasViewportTarget) return;
76
- this.#layout.observe(this.viewportTarget);
77
- this.#layout.observeViewport();
78
- if (typeof MutationObserver !== "undefined") {
79
- this.#mutationObserver = new MutationObserver(() => this.update());
80
- this.#mutationObserver.observe(this.viewportTarget, {
81
- childList: true,
82
- subtree: true,
83
- characterData: true
84
- });
85
- }
86
- this.update();
168
+ this.#connected = true;
169
+ this.#syncViewport();
87
170
  }
88
171
  disconnect() {
172
+ this.#connected = false;
173
+ this.#stopObservingViewport();
89
174
  this.#layout.disconnect();
90
- this.#mutationObserver?.disconnect();
91
- this.#mutationObserver = null;
175
+ this.#clearPendingButtonDisables();
92
176
  this.#state = null;
93
177
  }
94
- /** Re-measures remaining scroll room and reflects the state hooks. Public so it can be wired to the viewport's `scroll`. */
178
+ viewportTargetConnected() {
179
+ this.#syncViewport();
180
+ }
181
+ viewportTargetDisconnected(viewport) {
182
+ if (this.#observedViewport === viewport) this.#stopObservingViewport();
183
+ this.#syncViewport();
184
+ }
185
+ orientationValueChanged() {
186
+ if (this.#connected) this.update();
187
+ }
188
+ thresholdValueChanged() {
189
+ if (this.#connected) this.update();
190
+ }
191
+ /**
192
+ * Re-measures remaining scroll room and reflects the state hooks.
193
+ * Public so it can be wired to the viewport's `scroll`.
194
+ */
95
195
  update() {
96
196
  if (!this.hasViewportTarget) return;
97
197
  const vp = this.viewportTarget;
98
198
  const horizontal = this.orientationValue !== "vertical";
99
- const t = this.thresholdValue;
100
- const scrollPos = horizontal ? vp.scrollLeft : vp.scrollTop;
101
- const maxScroll = horizontal ? vp.scrollWidth - vp.clientWidth : vp.scrollHeight - vp.clientHeight;
199
+ const t = this.#threshold;
200
+ const { position: scrollPos, max: maxScroll } = logicalScrollMetrics(vp, horizontal);
102
201
  const start = scrollPos > t;
103
202
  const end = scrollPos < maxScroll - t;
104
203
  vp.setAttribute("data-overflow-start", start ? "true" : "false");
@@ -114,11 +213,13 @@ var OverflowIndicatorController = class extends Controller {
114
213
  if (!this.hasViewportTarget) return;
115
214
  const direction = this.#directionFromEvent(event);
116
215
  if (!direction) return;
216
+ if (this.#state && !this.#state[direction]) return;
117
217
  const vp = this.viewportTarget;
118
218
  const horizontal = this.orientationValue !== "vertical";
119
219
  const page = horizontal ? vp.clientWidth : vp.clientHeight;
120
- const delta = direction === "start" ? -page : page;
121
- const behavior = this.#prefersReducedMotion() ? "auto" : "smooth";
220
+ const logicalDelta = direction === "start" ? -page : page;
221
+ const delta = physicalScrollDelta(vp, horizontal, logicalDelta);
222
+ const behavior = prefersReducedMotion() ? "instant" : "smooth";
122
223
  if (horizontal) {
123
224
  vp.scrollBy({ left: delta, behavior });
124
225
  } else {
@@ -127,10 +228,16 @@ var OverflowIndicatorController = class extends Controller {
127
228
  }
128
229
  /** Mirrors remaining room onto any direction buttons by toggling `disabled`. */
129
230
  #syncButtons(start, end) {
130
- const buttons = this.element.querySelectorAll(
131
- "[data-stimeo--overflow-indicator-direction-param]"
132
- );
231
+ for (const button of this.#pendingButtonDisables.elements) {
232
+ if (!button.isConnected || button.closest("[data-controller~='stimeo--overflow-indicator']") !== this.element) {
233
+ this.#cancelPendingButtonDisable(button);
234
+ }
235
+ }
236
+ const buttons = this.element.querySelectorAll(DIRECTION_BUTTON_SELECTOR);
133
237
  for (const button of buttons) {
238
+ if (button.closest("[data-controller~='stimeo--overflow-indicator']") !== this.element) {
239
+ continue;
240
+ }
134
241
  const direction = button.getAttribute("data-stimeo--overflow-indicator-direction-param");
135
242
  if (direction === "start") this.#toggleButton(button, start);
136
243
  else if (direction === "end") this.#toggleButton(button, end);
@@ -143,7 +250,11 @@ var OverflowIndicatorController = class extends Controller {
143
250
  * whole control disabled) is therefore never blindly re-enabled.
144
251
  */
145
252
  #toggleButton(button, hasRoom) {
253
+ if (!this.#pendingButtonDisables.has(button) && button.hasAttribute("data-overflow-indicator-pending-disabled")) {
254
+ this.#cancelPendingButtonDisable(button);
255
+ }
146
256
  if (hasRoom) {
257
+ this.#cancelPendingButtonDisable(button);
147
258
  if (button.hasAttribute("data-overflow-indicator-disabled")) {
148
259
  button.disabled = false;
149
260
  button.removeAttribute("data-overflow-indicator-disabled");
@@ -151,17 +262,125 @@ var OverflowIndicatorController = class extends Controller {
151
262
  return;
152
263
  }
153
264
  if (button.disabled) return;
265
+ if (document.activeElement === button) {
266
+ this.#deferButtonDisable(button);
267
+ } else {
268
+ this.#disableButton(button);
269
+ }
270
+ }
271
+ /**
272
+ * Keeps a boundary button focusable until native blur, exposing its temporary
273
+ * inoperability with `aria-disabled` and making its action a no-op meanwhile.
274
+ */
275
+ #deferButtonDisable(button) {
276
+ if (this.#pendingButtonDisables.has(button)) return;
277
+ button.setAttribute("data-overflow-indicator-pending-disabled", "");
278
+ button.setAttribute(
279
+ "data-overflow-indicator-aria-disabled",
280
+ button.getAttribute("aria-disabled") ?? ""
281
+ );
282
+ button.setAttribute("aria-disabled", "true");
283
+ this.#pendingButtonDisables.defer(button);
284
+ }
285
+ #disableButton(button) {
154
286
  button.disabled = true;
155
287
  button.setAttribute("data-overflow-indicator-disabled", "");
156
288
  }
289
+ /** Cancels a pending disable without applying it, restoring the displaced state. */
290
+ #cancelPendingButtonDisable(button) {
291
+ this.#pendingButtonDisables.release(button);
292
+ this.#restorePendingMarkers(button);
293
+ }
294
+ /**
295
+ * Drops the pending marker and gives back the `aria-disabled` it displaced.
296
+ *
297
+ * Reads the displaced value from the DOM rather than memory: a Turbo snapshot is
298
+ * cloned before `disconnect()` runs, so a restored page can arrive with markers
299
+ * this instance never wrote.
300
+ */
301
+ #restorePendingMarkers(button) {
302
+ button.removeAttribute("data-overflow-indicator-pending-disabled");
303
+ const displaced = button.getAttribute("data-overflow-indicator-aria-disabled");
304
+ if (displaced !== null) {
305
+ button.removeAttribute("data-overflow-indicator-aria-disabled");
306
+ if (button.getAttribute("aria-disabled") === "true") {
307
+ if (displaced === "") button.removeAttribute("aria-disabled");
308
+ else button.setAttribute("aria-disabled", displaced);
309
+ }
310
+ }
311
+ }
312
+ #clearPendingButtonDisables() {
313
+ for (const button of this.#pendingButtonDisables.elements) {
314
+ this.#cancelPendingButtonDisable(button);
315
+ }
316
+ }
317
+ /** Moves resize/mutation/load observation to the current viewport target. */
318
+ #syncViewport() {
319
+ if (!this.#connected) return;
320
+ const next = this.hasViewportTarget ? this.viewportTarget : null;
321
+ if (next === this.#observedViewport) return;
322
+ this.#stopObservingViewport();
323
+ if (!next) return;
324
+ this.#observedViewport = next;
325
+ this.#layout.observe(next);
326
+ this.#layout.observeViewport();
327
+ next.addEventListener("load", this.#onContentLoad, true);
328
+ this.#syncContentObservation();
329
+ if (typeof MutationObserver !== "undefined") {
330
+ this.#mutationObserver = new MutationObserver(() => {
331
+ if (!this.#connected || this.#observedViewport !== next) return;
332
+ this.#syncContentObservation();
333
+ this.update();
334
+ });
335
+ this.#mutationObserver.observe(this.element, {
336
+ childList: true,
337
+ subtree: true,
338
+ characterData: true,
339
+ attributes: true,
340
+ attributeFilter: ["class", "style", "hidden"]
341
+ });
342
+ }
343
+ this.#state = null;
344
+ this.update();
345
+ }
346
+ /** Observes direct content boxes whose resize can change the viewport's scroll extent. */
347
+ #syncContentObservation() {
348
+ const next = new Set(this.#observedViewport?.children ?? []);
349
+ for (const content of this.#observedContent) {
350
+ if (!next.has(content)) {
351
+ this.#layout.unobserve(content);
352
+ this.#observedContent.delete(content);
353
+ }
354
+ }
355
+ for (const content of next) {
356
+ if (!this.#observedContent.has(content)) {
357
+ this.#observedContent.add(content);
358
+ this.#layout.observe(content);
359
+ }
360
+ }
361
+ }
362
+ #stopObservingViewport() {
363
+ this.#mutationObserver?.disconnect();
364
+ this.#mutationObserver = null;
365
+ this.#observedViewport?.removeEventListener("load", this.#onContentLoad, true);
366
+ if (this.#observedViewport) this.#layout.unobserve(this.#observedViewport);
367
+ for (const content of this.#observedContent) this.#layout.unobserve(content);
368
+ this.#observedContent.clear();
369
+ this.#observedViewport = null;
370
+ this.#layout.unobserveViewport();
371
+ }
372
+ #onContentLoad = () => {
373
+ if (this.#connected) this.update();
374
+ };
375
+ get #threshold() {
376
+ const value = this.thresholdValue;
377
+ return Number.isFinite(value) ? Math.max(0, value) : 1;
378
+ }
157
379
  #directionFromEvent(event) {
158
380
  const params = event.params;
159
381
  const direction = params?.direction;
160
382
  return direction === "start" || direction === "end" ? direction : null;
161
383
  }
162
- #prefersReducedMotion() {
163
- return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
164
- }
165
384
  };
166
385
 
167
386
  export { OverflowIndicatorController };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/layout_observer.ts","../../src/controllers/overflow_indicator_controller.ts"],"names":[],"mappings":";;;;;AAgDO,IAAM,iBAAN,MAAqB;AAAA,EACjB,SAAA;AAAA,EACA,sBAAA;AAAA,EACT,eAAA,GAAyC,IAAA;AAAA,EACzC,kBAAA,GAAqB,KAAA;AAAA;AAAA,EAGZ,wBAAwB,MAAY;AAC3C,IAAA,IAAA,CAAK,SAAA,EAAU;AAAA,EACjB,CAAA;AAAA,EAEA,WAAA,CAAY,QAAA,EAA0B,OAAA,GAAiC,EAAC,EAAG;AACzE,IAAA,IAAA,CAAK,SAAA,GAAY,QAAA;AACjB,IAAA,IAAA,CAAK,sBAAA,GACH,OAAA,CAAQ,qBAAA,KACP,OAAO,cAAA,KAAmB,WAAA,GAAc,IAAA,GAAO,CAAC,EAAA,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AAA,GAAW,KAAA;AAClB,QAAA,MAAA,CAAO,gBAAgB,kCAAkC,CAAA;AAAA,MAC3D;AACA,MAAA;AAAA,IACF;AACA,IAAA,IAAI,OAAO,QAAA,EAAU;AACrB,IAAA,MAAA,CAAO,QAAA,GAAW,IAAA;AAClB,IAAA,MAAA,CAAO,YAAA,CAAa,oCAAoC,EAAE,CAAA;AAAA,EAC5D;AAAA,EAEA,oBAAoB,KAAA,EAAsC;AACxD,IAAA,MAAM,SAAU,KAAA,CAAuD,MAAA;AACvE,IAAA,MAAM,YAAY,MAAA,EAAQ,SAAA;AAC1B,IAAA,OAAO,SAAA,KAAc,OAAA,IAAW,SAAA,KAAc,KAAA,GAAQ,SAAA,GAAY,IAAA;AAAA,EACpE;AAAA,EAEA,qBAAA,GAAiC;AAC/B,IAAA,OACE,OAAO,MAAA,CAAO,UAAA,KAAe,cAC7B,MAAA,CAAO,UAAA,CAAW,kCAAkC,CAAA,CAAE,OAAA;AAAA,EAE1D;AACF","file":"overflow_indicator_controller.js","sourcesContent":["/**\n * Unified element-size and viewport observation for Stimeo controllers.\n *\n * Layout-sensitive widgets (sliders, resizable panes, scroll spies, popovers)\n * need to react both to their *own* box changing — via {@link ResizeObserver} —\n * and to the *viewport* changing — via the `window` `resize` event. Wiring those\n * two sources by hand in every controller risks leaked listeners on\n * `disconnect()`. {@link LayoutObserver} owns both behind one callback and one\n * {@link LayoutObserver.disconnect | disconnect()} that releases everything.\n *\n * Behavior only: the helper reports *that* layout changed; it never reads or\n * writes styles. Consumers decide what to recompute.\n */\n\n/** Invoked whenever an observed element or the viewport changes size. */\nexport type LayoutCallback = () => void;\n\n/** Constructs a {@link ResizeObserver}; injectable so tests stay deterministic. */\nexport type ResizeObserverFactory = (callback: ResizeObserverCallback) => ResizeObserver;\n\n/** Options for {@link LayoutObserver}. */\nexport interface LayoutObserverOptions {\n /**\n * Factory for the {@link ResizeObserver} used by {@link LayoutObserver.observe}.\n * Defaults to the global constructor; override it in tests, or to no-op in\n * environments where `ResizeObserver` is unavailable.\n */\n resizeObserverFactory?: ResizeObserverFactory;\n}\n\n/**\n * Observes element resizes and/or viewport resizes through a single callback,\n * with guaranteed teardown.\n *\n * @example\n * ```ts\n * #layout = new LayoutObserver(() => this.#reposition());\n *\n * connect() {\n * this.#layout.observe(this.panelTarget);\n * this.#layout.observeViewport();\n * }\n *\n * disconnect() {\n * this.#layout.disconnect();\n * }\n * ```\n */\nexport class LayoutObserver {\n readonly #callback: LayoutCallback;\n readonly #resizeObserverFactory: ResizeObserverFactory | null;\n #resizeObserver: ResizeObserver | null = null;\n #observingViewport = false;\n\n /** Stable bound handler so add/removeEventListener target the same reference. */\n readonly #handleViewportResize = (): void => {\n this.#callback();\n };\n\n constructor(callback: LayoutCallback, options: LayoutObserverOptions = {}) {\n this.#callback = callback;\n this.#resizeObserverFactory =\n options.resizeObserverFactory ??\n (typeof ResizeObserver === \"undefined\" ? null : (cb) => new ResizeObserver(cb));\n }\n\n /**\n * Starts observing an element's size. Repeated calls observe additional\n * elements through the same shared observer. No-ops when no\n * `ResizeObserver` implementation is available.\n */\n observe(element: Element): void {\n if (!this.#resizeObserverFactory) return;\n if (!this.#resizeObserver) {\n this.#resizeObserver = this.#resizeObserverFactory(() => {\n this.#callback();\n });\n }\n this.#resizeObserver.observe(element);\n }\n\n /** Stops observing a single element while leaving any others in place. */\n unobserve(element: Element): void {\n this.#resizeObserver?.unobserve(element);\n }\n\n /** Starts observing viewport resizes. Idempotent: the listener is added once. */\n observeViewport(): void {\n if (this.#observingViewport) return;\n this.#observingViewport = true;\n window.addEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /** Stops observing viewport resizes without affecting element observation. */\n unobserveViewport(): void {\n if (!this.#observingViewport) return;\n this.#observingViewport = false;\n window.removeEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /**\n * Releases every observation: disconnects the {@link ResizeObserver} and\n * removes the viewport listener. Safe to call multiple times. Call this from a\n * controller's `disconnect()`.\n */\n disconnect(): void {\n this.#resizeObserver?.disconnect();\n this.#resizeObserver = null;\n this.unobserveViewport();\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { LayoutObserver } from \"../utils/layout_observer\";\n\n/**\n * Headless **Overflow Indicator**: detects whether a scroll container can still\n * scroll toward its start and/or end and publishes it as `data-overflow-start` /\n * `data-overflow-end`. No APG widget — a state-detection utility. Consumers draw\n * edge shadows or arrows in CSS to signal \"more content this way\".\n *\n * Markup contract (identifier: `stimeo--overflow-indicator`):\n * <div data-controller=\"stimeo--overflow-indicator\"\n * data-stimeo--overflow-indicator-orientation-value=\"horizontal\">\n * <button type=\"button\" aria-label=\"Prev\"\n * data-stimeo--overflow-indicator-direction-param=\"start\"\n * data-action=\"click->stimeo--overflow-indicator#scrollByPage\">‹</button>\n * <div data-stimeo--overflow-indicator-target=\"viewport\"\n * data-action=\"scroll->stimeo--overflow-indicator#update\"\n * tabindex=\"0\" role=\"region\" aria-label=\"Products\"\n * style=\"overflow-x: auto;\"><!-- items --></div>\n * <button type=\"button\" aria-label=\"Next\"\n * data-stimeo--overflow-indicator-direction-param=\"end\"\n * data-action=\"click->stimeo--overflow-indicator#scrollByPage\">›</button>\n * </div>\n *\n * The viewport's scroll position and size are watched (via the wired `scroll`\n * action, plus {@link LayoutObserver} for resize and a {@link MutationObserver}\n * for content changes). Optional page buttons scroll one viewport at a time and\n * have their `disabled` synced to the matching direction's remaining room.\n *\n * @remarks\n * Behavior only — shadows, arrows, and gradients are the consumer's CSS;\n * `data-overflow-*` carry no ARIA semantics. All observers/listeners are released\n * on `disconnect()` (Turbo navigation included). `scrollByPage` honors\n * `prefers-reduced-motion`.\n */\nexport class OverflowIndicatorController extends Controller<HTMLElement> {\n static override targets = [\"viewport\"];\n static override values = {\n orientation: { type: String, default: \"horizontal\" },\n threshold: { type: Number, default: 1 },\n };\n static actions = [\"scrollByPage\", \"update\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly viewportTarget: HTMLElement;\n declare readonly hasViewportTarget: boolean;\n\n declare orientationValue: string;\n declare thresholdValue: number;\n\n readonly #layout = new LayoutObserver(() => this.update());\n #mutationObserver: MutationObserver | null = null;\n /** Last reported room, so `change` fires only on transitions. */\n #state: { start: boolean; end: boolean } | null = null;\n\n override connect(): void {\n if (!this.hasViewportTarget) return;\n this.#layout.observe(this.viewportTarget);\n this.#layout.observeViewport();\n\n if (typeof MutationObserver !== \"undefined\") {\n this.#mutationObserver = new MutationObserver(() => this.update());\n this.#mutationObserver.observe(this.viewportTarget, {\n childList: true,\n subtree: true,\n characterData: true,\n });\n }\n this.update();\n }\n\n override disconnect(): void {\n this.#layout.disconnect();\n this.#mutationObserver?.disconnect();\n this.#mutationObserver = null;\n this.#state = null;\n }\n\n /** Re-measures remaining scroll room and reflects the state hooks. Public so it can be wired to the viewport's `scroll`. */\n update(): void {\n if (!this.hasViewportTarget) return;\n const vp = this.viewportTarget;\n const horizontal = this.orientationValue !== \"vertical\";\n const t = this.thresholdValue;\n\n const scrollPos = horizontal ? vp.scrollLeft : vp.scrollTop;\n const maxScroll = horizontal\n ? vp.scrollWidth - vp.clientWidth\n : vp.scrollHeight - vp.clientHeight;\n\n const start = scrollPos > t;\n const end = scrollPos < maxScroll - t;\n\n vp.setAttribute(\"data-overflow-start\", start ? \"true\" : \"false\");\n vp.setAttribute(\"data-overflow-end\", end ? \"true\" : \"false\");\n this.#syncButtons(start, end);\n\n if (!this.#state || this.#state.start !== start || this.#state.end !== end) {\n this.#state = { start, end };\n this.dispatch(\"change\", { detail: { start, end } });\n }\n }\n\n /** Scrolls one viewport page toward the `direction` param (`start`/`end`). */\n scrollByPage(event: Event): void {\n if (!this.hasViewportTarget) return;\n const direction = this.#directionFromEvent(event);\n if (!direction) return;\n\n const vp = this.viewportTarget;\n const horizontal = this.orientationValue !== \"vertical\";\n const page = horizontal ? vp.clientWidth : vp.clientHeight;\n const delta = direction === \"start\" ? -page : page;\n const behavior: ScrollBehavior = this.#prefersReducedMotion() ? \"auto\" : \"smooth\";\n\n if (horizontal) {\n vp.scrollBy({ left: delta, behavior });\n } else {\n vp.scrollBy({ top: delta, behavior });\n }\n }\n\n /** Mirrors remaining room onto any direction buttons by toggling `disabled`. */\n #syncButtons(start: boolean, end: boolean): void {\n const buttons = this.element.querySelectorAll<HTMLButtonElement>(\n \"[data-stimeo--overflow-indicator-direction-param]\",\n );\n for (const button of buttons) {\n const direction = button.getAttribute(\"data-stimeo--overflow-indicator-direction-param\");\n if (direction === \"start\") this.#toggleButton(button, start);\n else if (direction === \"end\") this.#toggleButton(button, end);\n }\n }\n\n /**\n * Reflects the remaining room onto a page button's `disabled`, owning only the\n * `disabled` it sets itself via a marker (`data-overflow-indicator-disabled`,\n * like `number-input`/`conditional-fields`). An author-disabled button (e.g. the\n * whole control disabled) is therefore never blindly re-enabled.\n */\n #toggleButton(button: HTMLButtonElement, hasRoom: boolean): void {\n if (hasRoom) {\n if (button.hasAttribute(\"data-overflow-indicator-disabled\")) {\n button.disabled = false;\n button.removeAttribute(\"data-overflow-indicator-disabled\");\n }\n return;\n }\n if (button.disabled) return; // already disabled (possibly by the author) — leave it\n button.disabled = true;\n button.setAttribute(\"data-overflow-indicator-disabled\", \"\");\n }\n\n #directionFromEvent(event: Event): \"start\" | \"end\" | null {\n const params = (event as Event & { params?: { direction?: unknown } }).params;\n const direction = params?.direction;\n return direction === \"start\" || direction === \"end\" ? direction : null;\n }\n\n #prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/blur_deferral.ts","../../src/utils/layout_observer.ts","../../src/utils/logical_scroll.ts","../../src/utils/reduced_motion.ts","../../src/controllers/overflow_indicator_controller.ts"],"names":[],"mappings":";;;;;AAoDO,IAAM,eAAN,MAAwD;AAAA;AAAA,EAEpD,QAAA,uBAAe,GAAA,EAAmB;AAAA;AAAA,EAElC,UAAA;AAAA;AAAA,EAGT,YAAY,SAAA,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,MAAA,EAAQ,SAAA;AAC1B,IAAA,OAAO,SAAA,KAAc,OAAA,IAAW,SAAA,KAAc,KAAA,GAAQ,SAAA,GAAY,IAAA;AAAA,EACpE;AACF","file":"overflow_indicator_controller.js","sourcesContent":["/**\n * Shared bookkeeping for updates that must wait until an element loses focus.\n *\n * A control that becomes redundant while the user is standing on it cannot be\n * removed from the page immediately: hiding a focused element (or turning it\n * into a native `disabled` one) drops focus to `<body>`, stranding a keyboard\n * user mid-widget. The fix every affected controller reached for is the same —\n * keep the element reachable, hold the destructive update, listen for `blur`,\n * and apply it then.\n *\n * {@link BlurDeferral} owns *only* the registry part of that: which elements are\n * currently holding an update back, attaching and detaching the `blur` listener,\n * and guaranteeing teardown. It is deliberately **policy-free** — what the\n * interim state looks like (`aria-disabled`, an ownership marker, nothing at\n * all), and what the deferred update actually is, stay in the controller, which\n * receives the element back through its release callback.\n *\n * Three contracts are worth stating up front, because each one is a hazard the\n * consumers would otherwise hit:\n *\n * - **The release callback fires only on a real `blur`.** `release()` /\n * `releaseAll()` *cancel* a deferral; they do not complete it. Conflating the\n * two makes `overflow-indicator` disable a button that just left the boundary.\n * - **`elements` is a snapshot.** Iterating the live key set while releasing\n * inside the loop is the failure this registry exists to prevent.\n * - **The entry is detached before the callback runs**, so a controller that\n * decides the update is still unsafe can simply defer again.\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 contracts belong on the members.\n *\n * @example\n * ```ts\n * readonly #deferred = new BlurDeferral<HTMLElement>((trigger) => {\n * if (this.#connected) this.#evaluate();\n * });\n *\n * #hide(trigger: HTMLElement) {\n * if (document.activeElement === trigger) {\n * this.#deferred.deferOnly(trigger); // stays visible until blur\n * return;\n * }\n * this.#deferred.releaseAll();\n * trigger.hidden = true;\n * }\n *\n * disconnect() {\n * this.#deferred.releaseAll();\n * }\n * ```\n */\nexport class BlurDeferral<T extends HTMLElement = HTMLElement> {\n /** Elements currently holding an update back, mapped to their `blur` listener. */\n readonly #pending = new Map<T, () => void>();\n /** Called after a pending element blurs and has been detached. */\n readonly #onRelease: (element: T) => void;\n\n /** @param onRelease - Invoked once `element` actually blurs; never on `release`. */\n constructor(onRelease: (element: T) => void) {\n this.#onRelease = onRelease;\n }\n\n /** Number of elements currently holding an update back. */\n get size(): number {\n return this.#pending.size;\n }\n\n /** Snapshot of the pending elements, safe to iterate while releasing them. */\n get elements(): T[] {\n return [...this.#pending.keys()];\n }\n\n /** Whether `element` is currently holding an update back. */\n has(element: T): boolean {\n return this.#pending.has(element);\n }\n\n /** Holds an update back until `element` blurs. Idempotent (no stacked listeners). */\n defer(element: T): void {\n if (this.#pending.has(element)) return;\n const onBlur = (): void => {\n this.#detach(element);\n this.#onRelease(element);\n };\n this.#pending.set(element, onBlur);\n element.addEventListener(\"blur\", onBlur);\n }\n\n /** Defers `element` as the only pending entry, cancelling any others. */\n deferOnly(element: T): void {\n for (const pending of this.elements) {\n if (pending !== element) this.#detach(pending);\n }\n this.defer(element);\n }\n\n /** Cancels `element`'s deferral without completing it; no-ops when not pending. */\n release(element: T): void {\n this.#detach(element);\n }\n\n /** Cancels every deferral without completing any of them. */\n releaseAll(): void {\n for (const element of this.elements) this.#detach(element);\n }\n\n /** Removes the `blur` listener for `element` and forgets it. */\n #detach(element: T): void {\n const onBlur = this.#pending.get(element);\n if (onBlur) element.removeEventListener(\"blur\", onBlur);\n this.#pending.delete(element);\n }\n}\n","/**\n * Unified element-size and viewport observation for Stimeo controllers.\n *\n * Layout-sensitive widgets (sliders, resizable panes, scroll spies, popovers)\n * need to react both to their *own* box changing — via {@link ResizeObserver} —\n * and to the *viewport* changing — via the `window` `resize` event. Wiring those\n * two sources by hand in every controller risks leaked listeners on\n * `disconnect()`. {@link LayoutObserver} owns both behind one callback and one\n * {@link LayoutObserver.disconnect | disconnect()} that releases everything.\n *\n * Behavior only: the helper reports *that* layout changed; it never reads or\n * writes styles. Consumers decide what to recompute.\n */\n\n/** Invoked whenever an observed element or the viewport changes size. */\nexport type LayoutCallback = () => void;\n\n/** Constructs a {@link ResizeObserver}; injectable so tests stay deterministic. */\nexport type ResizeObserverFactory = (callback: ResizeObserverCallback) => ResizeObserver;\n\n/** Options for {@link LayoutObserver}. */\nexport interface LayoutObserverOptions {\n /**\n * Factory for the {@link ResizeObserver} used by {@link LayoutObserver.observe}.\n * Defaults to the global constructor; override it in tests, or to no-op in\n * environments where `ResizeObserver` is unavailable.\n */\n resizeObserverFactory?: ResizeObserverFactory;\n}\n\n/**\n * Observes element resizes and/or viewport resizes through a single callback,\n * with guaranteed teardown.\n *\n * @example\n * ```ts\n * #layout = new LayoutObserver(() => this.#reposition());\n *\n * connect() {\n * this.#layout.observe(this.panelTarget);\n * this.#layout.observeViewport();\n * }\n *\n * disconnect() {\n * this.#layout.disconnect();\n * }\n * ```\n */\nexport class LayoutObserver {\n readonly #callback: LayoutCallback;\n readonly #resizeObserverFactory: ResizeObserverFactory | null;\n #resizeObserver: ResizeObserver | null = null;\n #observingViewport = false;\n\n /** Stable bound handler so add/removeEventListener target the same reference. */\n readonly #handleViewportResize = (): void => {\n this.#callback();\n };\n\n constructor(callback: LayoutCallback, options: LayoutObserverOptions = {}) {\n this.#callback = callback;\n this.#resizeObserverFactory =\n options.resizeObserverFactory ??\n (typeof ResizeObserver === \"undefined\" ? null : (cb) => new ResizeObserver(cb));\n }\n\n /**\n * Starts observing an element's size. Repeated calls observe additional\n * elements through the same shared observer. No-ops when no\n * `ResizeObserver` implementation is available.\n */\n observe(element: Element): void {\n if (!this.#resizeObserverFactory) return;\n if (!this.#resizeObserver) {\n this.#resizeObserver = this.#resizeObserverFactory(() => {\n this.#callback();\n });\n }\n this.#resizeObserver.observe(element);\n }\n\n /** Stops observing a single element while leaving any others in place. */\n unobserve(element: Element): void {\n this.#resizeObserver?.unobserve(element);\n }\n\n /** Starts observing viewport resizes. Idempotent: the listener is added once. */\n observeViewport(): void {\n if (this.#observingViewport) return;\n this.#observingViewport = true;\n window.addEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /** Stops observing viewport resizes without affecting element observation. */\n unobserveViewport(): void {\n if (!this.#observingViewport) return;\n this.#observingViewport = false;\n window.removeEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /**\n * Releases every observation: disconnects the {@link ResizeObserver} and\n * removes the viewport listener. Safe to call multiple times. Call this from a\n * controller's `disconnect()`.\n */\n disconnect(): void {\n this.#resizeObserver?.disconnect();\n this.#resizeObserver = null;\n this.unobserveViewport();\n }\n}\n","/** 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","/**\n * Shared `prefers-reduced-motion` lookup for the motion-aware controllers\n * (count-up, highlight, overflow-indicator, scroll-visibility, stick-to-bottom,\n * transition).\n *\n * This one-liner keeps the media query string and the environment guard\n * single-sourced across them. The preference is intentionally re-read on every\n * call — the controllers check it at each animation/scroll start (WCAG 2.2\n * **2.3.3**), so flipping the OS setting takes effect immediately without any\n * listener or cache bookkeeping here.\n */\n\n/**\n * Whether the user currently requests reduced motion.\n *\n * @returns `true` when `(prefers-reduced-motion: reduce)` matches; `false`\n * otherwise, including environments without `window.matchMedia` (treated as\n * \"no preference\").\n */\nexport function prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { BlurDeferral } from \"../utils/blur_deferral\";\nimport { LayoutObserver } from \"../utils/layout_observer\";\nimport { logicalScrollMetrics, physicalScrollDelta } from \"../utils/logical_scroll\";\nimport { prefersReducedMotion } from \"../utils/reduced_motion\";\n\nconst DIRECTION_BUTTON_SELECTOR = \"[data-stimeo--overflow-indicator-direction-param]\";\n\n/**\n * Headless **Overflow Indicator**: detects whether a scroll container can still\n * scroll toward its start and/or end and publishes it as `data-overflow-start` /\n * `data-overflow-end`. No APG widget — a state-detection utility. Consumers draw\n * edge shadows or arrows in CSS to signal \"more content this way\".\n *\n * Markup contract (identifier: `stimeo--overflow-indicator`):\n * <div data-controller=\"stimeo--overflow-indicator\"\n * data-stimeo--overflow-indicator-orientation-value=\"horizontal\">\n * <button type=\"button\" aria-label=\"Prev\"\n * data-stimeo--overflow-indicator-direction-param=\"start\"\n * data-action=\"click->stimeo--overflow-indicator#scrollByPage\">‹</button>\n * <div data-stimeo--overflow-indicator-target=\"viewport\"\n * data-action=\"scroll->stimeo--overflow-indicator#update\"\n * tabindex=\"0\" role=\"region\" aria-label=\"Products\"\n * style=\"overflow-x: auto;\"><!-- items --></div>\n * <button type=\"button\" aria-label=\"Next\"\n * data-stimeo--overflow-indicator-direction-param=\"end\"\n * data-action=\"click->stimeo--overflow-indicator#scrollByPage\">›</button>\n * </div>\n *\n * The viewport's scroll position and size are watched (via the wired `scroll`\n * action, plus {@link LayoutObserver} for viewport/content resize, a\n * {@link MutationObserver}, and descendant load events). Optional page buttons\n * scroll one logical viewport page at a time (including RTL) and have their\n * disabled state synced to the matching direction's remaining room.\n *\n * @remarks\n * Behavior only — shadows, arrows, and gradients are the consumer's CSS;\n * `data-overflow-*` carry no ARIA semantics. All observers/listeners are released\n * on `disconnect()` (Turbo navigation included). `scrollByPage` scrolls smoothly\n * by default and forces an instant jump under `prefers-reduced-motion`, regardless\n * of the consumer's CSS `scroll-behavior`.\n */\nexport class OverflowIndicatorController extends Controller<HTMLElement> {\n static override targets = [\"viewport\"];\n static override values = {\n orientation: { type: String, default: \"horizontal\" },\n threshold: { type: Number, default: 1 },\n };\n static actions = [\"scrollByPage\", \"update\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly viewportTarget: HTMLElement;\n declare readonly hasViewportTarget: boolean;\n\n declare orientationValue: string;\n declare thresholdValue: number;\n\n readonly #layout = new LayoutObserver(() => {\n if (this.#connected) this.update();\n });\n #connected = false;\n #observedViewport: HTMLElement | null = null;\n readonly #observedContent = new Set<Element>();\n #mutationObserver: MutationObserver | null = null;\n /**\n * Boundary buttons whose native `disabled` is held back while they hold focus.\n *\n * Completing the deferral is what actually disables the button, so the release\n * callback — unlike {@link #cancelPendingButtonDisable} — applies it.\n */\n readonly #pendingButtonDisables = new BlurDeferral<HTMLButtonElement>((button) => {\n this.#restorePendingMarkers(button);\n // If the author disabled it while focus was pending, do not claim ownership.\n if (!button.disabled) this.#disableButton(button);\n });\n /** Last reported room, so `change` fires only on transitions. */\n #state: { start: boolean; end: boolean } | null = null;\n\n override connect(): void {\n this.#connected = true;\n this.#syncViewport();\n }\n\n override disconnect(): void {\n this.#connected = false;\n this.#stopObservingViewport();\n this.#layout.disconnect();\n this.#clearPendingButtonDisables();\n this.#state = null;\n }\n\n viewportTargetConnected(): void {\n this.#syncViewport();\n }\n\n viewportTargetDisconnected(viewport: HTMLElement): void {\n if (this.#observedViewport === viewport) this.#stopObservingViewport();\n this.#syncViewport();\n }\n\n orientationValueChanged(): void {\n if (this.#connected) this.update();\n }\n\n thresholdValueChanged(): void {\n if (this.#connected) this.update();\n }\n\n /**\n * Re-measures remaining scroll room and reflects the state hooks.\n * Public so it can be wired to the viewport's `scroll`.\n */\n update(): void {\n if (!this.hasViewportTarget) return;\n const vp = this.viewportTarget;\n const horizontal = this.orientationValue !== \"vertical\";\n const t = this.#threshold;\n const { position: scrollPos, max: maxScroll } = logicalScrollMetrics(vp, horizontal);\n\n const start = scrollPos > t;\n const end = scrollPos < maxScroll - t;\n\n vp.setAttribute(\"data-overflow-start\", start ? \"true\" : \"false\");\n vp.setAttribute(\"data-overflow-end\", end ? \"true\" : \"false\");\n this.#syncButtons(start, end);\n\n if (!this.#state || this.#state.start !== start || this.#state.end !== end) {\n this.#state = { start, end };\n this.dispatch(\"change\", { detail: { start, end } });\n }\n }\n\n /** Scrolls one viewport page toward the `direction` param (`start`/`end`). */\n scrollByPage(event: Event): void {\n if (!this.hasViewportTarget) return;\n const direction = this.#directionFromEvent(event);\n if (!direction) return;\n if (this.#state && !this.#state[direction]) return;\n\n const vp = this.viewportTarget;\n const horizontal = this.orientationValue !== \"vertical\";\n const page = horizontal ? vp.clientWidth : vp.clientHeight;\n const logicalDelta = direction === \"start\" ? -page : page;\n const delta = physicalScrollDelta(vp, horizontal, logicalDelta);\n const behavior: ScrollBehavior = prefersReducedMotion() ? \"instant\" : \"smooth\";\n\n if (horizontal) {\n vp.scrollBy({ left: delta, behavior });\n } else {\n vp.scrollBy({ top: delta, behavior });\n }\n }\n\n /** Mirrors remaining room onto any direction buttons by toggling `disabled`. */\n #syncButtons(start: boolean, end: boolean): void {\n for (const button of this.#pendingButtonDisables.elements) {\n if (\n !button.isConnected ||\n button.closest(\"[data-controller~='stimeo--overflow-indicator']\") !== this.element\n ) {\n this.#cancelPendingButtonDisable(button);\n }\n }\n const buttons = this.element.querySelectorAll<HTMLButtonElement>(DIRECTION_BUTTON_SELECTOR);\n for (const button of buttons) {\n if (button.closest(\"[data-controller~='stimeo--overflow-indicator']\") !== this.element) {\n continue;\n }\n const direction = button.getAttribute(\"data-stimeo--overflow-indicator-direction-param\");\n if (direction === \"start\") this.#toggleButton(button, start);\n else if (direction === \"end\") this.#toggleButton(button, end);\n }\n }\n\n /**\n * Reflects the remaining room onto a page button's `disabled`, owning only the\n * `disabled` it sets itself via a marker (`data-overflow-indicator-disabled`,\n * like `number-input`/`conditional-fields`). An author-disabled button (e.g. the\n * whole control disabled) is therefore never blindly re-enabled.\n */\n #toggleButton(button: HTMLButtonElement, hasRoom: boolean): void {\n // A restored Turbo snapshot can carry pending markers from the previous visit\n // that this instance never created; release them from the DOM record before\n // deciding, or the displaced `aria-disabled` would never be given back.\n if (\n !this.#pendingButtonDisables.has(button) &&\n button.hasAttribute(\"data-overflow-indicator-pending-disabled\")\n ) {\n this.#cancelPendingButtonDisable(button);\n }\n if (hasRoom) {\n this.#cancelPendingButtonDisable(button);\n if (button.hasAttribute(\"data-overflow-indicator-disabled\")) {\n button.disabled = false;\n button.removeAttribute(\"data-overflow-indicator-disabled\");\n }\n return;\n }\n if (button.disabled) return; // already disabled (possibly by the author) — leave it\n if (document.activeElement === button) {\n this.#deferButtonDisable(button);\n } else {\n this.#disableButton(button);\n }\n }\n\n /**\n * Keeps a boundary button focusable until native blur, exposing its temporary\n * inoperability with `aria-disabled` and making its action a no-op meanwhile.\n */\n #deferButtonDisable(button: HTMLButtonElement): void {\n if (this.#pendingButtonDisables.has(button)) return;\n button.setAttribute(\"data-overflow-indicator-pending-disabled\", \"\");\n // The ownership marker carries the value we displace, so the DOM alone is\n // enough to undo it. A Turbo snapshot is cloned before `disconnect()` runs,\n // so a restored page arrives with these markers while the new instance has\n // no in-memory record of them — an empty marker means \"there was none\".\n button.setAttribute(\n \"data-overflow-indicator-aria-disabled\",\n button.getAttribute(\"aria-disabled\") ?? \"\",\n );\n button.setAttribute(\"aria-disabled\", \"true\");\n this.#pendingButtonDisables.defer(button);\n }\n\n #disableButton(button: HTMLButtonElement): void {\n button.disabled = true;\n button.setAttribute(\"data-overflow-indicator-disabled\", \"\");\n }\n\n /** Cancels a pending disable without applying it, restoring the displaced state. */\n #cancelPendingButtonDisable(button: HTMLButtonElement): void {\n this.#pendingButtonDisables.release(button);\n this.#restorePendingMarkers(button);\n }\n\n /**\n * Drops the pending marker and gives back the `aria-disabled` it displaced.\n *\n * Reads the displaced value from the DOM rather than memory: a Turbo snapshot is\n * cloned before `disconnect()` runs, so a restored page can arrive with markers\n * this instance never wrote.\n */\n #restorePendingMarkers(button: HTMLButtonElement): void {\n button.removeAttribute(\"data-overflow-indicator-pending-disabled\");\n const displaced = button.getAttribute(\"data-overflow-indicator-aria-disabled\");\n if (displaced !== null) {\n button.removeAttribute(\"data-overflow-indicator-aria-disabled\");\n if (button.getAttribute(\"aria-disabled\") === \"true\") {\n if (displaced === \"\") button.removeAttribute(\"aria-disabled\");\n else button.setAttribute(\"aria-disabled\", displaced);\n }\n }\n }\n\n #clearPendingButtonDisables(): void {\n for (const button of this.#pendingButtonDisables.elements) {\n this.#cancelPendingButtonDisable(button);\n }\n }\n\n /** Moves resize/mutation/load observation to the current viewport target. */\n #syncViewport(): void {\n if (!this.#connected) return;\n const next = this.hasViewportTarget ? this.viewportTarget : null;\n if (next === this.#observedViewport) return;\n this.#stopObservingViewport();\n if (!next) return;\n\n this.#observedViewport = next;\n this.#layout.observe(next);\n this.#layout.observeViewport();\n next.addEventListener(\"load\", this.#onContentLoad, true);\n this.#syncContentObservation();\n\n if (typeof MutationObserver !== \"undefined\") {\n this.#mutationObserver = new MutationObserver(() => {\n if (!this.#connected || this.#observedViewport !== next) return;\n this.#syncContentObservation();\n this.update();\n });\n this.#mutationObserver.observe(this.element, {\n childList: true,\n subtree: true,\n characterData: true,\n attributes: true,\n attributeFilter: [\"class\", \"style\", \"hidden\"],\n });\n }\n this.#state = null;\n this.update();\n }\n\n /** Observes direct content boxes whose resize can change the viewport's scroll extent. */\n #syncContentObservation(): void {\n const next = new Set<Element>(this.#observedViewport?.children ?? []);\n for (const content of this.#observedContent) {\n if (!next.has(content)) {\n this.#layout.unobserve(content);\n this.#observedContent.delete(content);\n }\n }\n for (const content of next) {\n if (!this.#observedContent.has(content)) {\n this.#observedContent.add(content);\n this.#layout.observe(content);\n }\n }\n }\n\n #stopObservingViewport(): void {\n this.#mutationObserver?.disconnect();\n this.#mutationObserver = null;\n this.#observedViewport?.removeEventListener(\"load\", this.#onContentLoad, true);\n if (this.#observedViewport) this.#layout.unobserve(this.#observedViewport);\n for (const content of this.#observedContent) this.#layout.unobserve(content);\n this.#observedContent.clear();\n this.#observedViewport = null;\n this.#layout.unobserveViewport();\n }\n\n readonly #onContentLoad = (): void => {\n if (this.#connected) this.update();\n };\n\n get #threshold(): number {\n const value = this.thresholdValue;\n return Number.isFinite(value) ? Math.max(0, value) : 1;\n }\n\n #directionFromEvent(event: Event): \"start\" | \"end\" | null {\n const params = (event as Event & { params?: { direction?: unknown } }).params;\n const direction = params?.direction;\n return direction === \"start\" || direction === \"end\" ? direction : null;\n }\n}\n"]}
@@ -7,33 +7,92 @@ import { Controller } from '@hotwired/stimulus';
7
7
  * composition; the menu's a11y is delegated to Menu, so it is not re-implemented).
8
8
  *
9
9
  * Markup contract (identifier: `stimeo--overflow-menu`):
10
- * <div data-controller="stimeo--overflow-menu" role="toolbar">
10
+ * <nav data-controller="stimeo--overflow-menu" aria-label="Actions">
11
11
  * <div data-stimeo--overflow-menu-target="items">
12
- * <a data-priority="1">Save</a><a data-priority="2">Duplicate</a><a>Delete</a>
12
+ * <button data-priority="1">Save</button>
13
+ * <button>Delete</button>
13
14
  * </div>
14
15
  * <div data-controller="stimeo--menu" data-stimeo--overflow-menu-target="more" hidden>
15
- * <button id="more-trigger" data-stimeo--menu-target="trigger">More</button>
16
- * <ul role="menu" aria-labelledby="more-trigger"
17
- * data-stimeo--menu-target="menu" hidden></ul>
16
+ * <button id="more-trigger" data-stimeo--menu-target="trigger"
17
+ * aria-haspopup="menu" aria-expanded="false"
18
+ * data-action="click->stimeo--menu#toggle
19
+ * keydown->stimeo--menu#onTriggerKeydown">More</button>
20
+ * <div role="menu" aria-labelledby="more-trigger"
21
+ * data-stimeo--menu-target="menu" hidden></div>
18
22
  * </div>
19
23
  * </div>
20
24
  *
21
- * On connect (and every debounced resize) it measures the items against the container
22
- * width and, when they overflow, banks the lowest-priority ones into the More menu
23
- * giving each `role="menuitem"` / `tabindex="-1"` and the menu's `item` target so Menu
24
- * drives it until the rest fit beside the More button. When nothing overflows the
25
- * More button is `hidden`. The controller element carries `data-overflowing` /
26
- * `data-overflow-count`, and a `change` event fires on each transition.
25
+ * This controller does not own the root's role. It ships none: a navigation bar is
26
+ * a named `<nav>` whose items stay in the normal Tab order. A consumer may add
27
+ * `role="toolbar"`, but that alone is not an APG Toolbar — the single-tab-stop
28
+ * roving is {@link ToolbarController}'s behavior, not this one's and a named
29
+ * role still needs `aria-label` / `aria-labelledby`.
30
+ *
31
+ * Two parts of that contract are load-bearing and easy to drop. The banked-items
32
+ * container is a permissive single `role="menu"` element this controller appends to
33
+ * directly; use a `<div>`, since a `<ul>` cannot directly own the moved controls. And the
34
+ * trigger's `data-action` is **required, not decoration**: without it the More button
35
+ * never opens, and `keydown->stimeo--menu#onTriggerKeydown` is what makes it reachable
36
+ * by keyboard at all (`Enter` / `Space` / `ArrowDown`). It is spelled out above rather
37
+ * than referenced, because the keyboard half of this contract lives *only* in the
38
+ * consumer's markup — nothing in this controller's source would reveal its absence.
39
+ * Items need no bindings of their own — Menu delegates their handling from its own
40
+ * element, so a control that only becomes a menu item at runtime is operable the
41
+ * moment it lands.
42
+ *
43
+ * On connect (and every debounced resize) it measures the items against the container's
44
+ * content width and, when they overflow, banks the lowest-priority ones into the More
45
+ * menu — giving each `role="menuitem"` / `tabindex="-1"` and the menu's `item` target so
46
+ * Menu drives it — until the rest fit beside the More button. When nothing overflows the
47
+ * More wrapper (button *and* menu) is `hidden`. The controller element carries
48
+ * `data-overflowing` / `data-overflow-count`, and a `change` event fires on connect and
49
+ * on every later transition.
27
50
  *
28
51
  * @remarks
29
- * Items are *moved* (not cloned). When a focused item retreats into the (collapsed)
30
- * menu it would otherwise be hidden and lose focus, so focus is redirected to the More
31
- * trigger. Priority: lower `data-priority` is kept longer; items without one drop first.
32
- * Behavior only no styling. The `ResizeObserver` and debounce timer are released on
33
- * `disconnect()` (Turbo navigation included); state is derived from the DOM each pass
34
- * (no module-scope state), so `connect()` re-syncs after a Turbo morph. Captures the
35
- * managed item set at connect; call the `update` action to re-measure after adding
36
- * items dynamically.
52
+ * **Measuring.** The container's width must not be derived from its content (give the bar
53
+ * an explicit width, `flex: 1`, or plain block layout): the More button is revealed before
54
+ * measuring, so a shrink-to-fit container always reports "items + gap + More" and nothing
55
+ * ever overflows. The budget is the container's *content box* (`clientWidth` minus its
56
+ * horizontal padding); the gap between items comes from the items container, the gap
57
+ * reserved for the More button from the bar itself. Item widths are cached (a natural
58
+ * width is location-independent) so a pass reads only the items in the bar one reflow,
59
+ * not two. The trade-off: an item whose content changes *while banked* (a locale switch, a
60
+ * badge update) keeps its stale width until it is back in the bar, so it may return one
61
+ * pass late; re-measuring it in place would cost a second reflow every pass. An item the
62
+ * author marked `hidden` is out of the budget, out of the drop order, and never banked; it
63
+ * holds its canonical slot and rejoins as soon as the attribute goes away. Toggling
64
+ * `hidden` is an attribute change, not a resize, so call `update` after it.
65
+ *
66
+ * **Moving.** Items are moved (never cloned), and only the nodes that are actually out of
67
+ * place — a pass that changes nothing touches no node, because re-inserting a node removes
68
+ * it first and the browser then drops focus to `<body>`. Where `moveBefore` is supported
69
+ * the move preserves focus and transient element state outright.
70
+ *
71
+ * **Focus.** When the focused item (or a descendant of it) *starts* retreating into a
72
+ * collapsed menu it would be hidden and lose focus, so focus is redirected to the More
73
+ * trigger (falling back to the More wrapper when the markup has no trigger — give it one,
74
+ * or focus is left to the browser). While the menu is expanded the item stays visible, so
75
+ * focus is left alone — unless the focused item is the one returning to the bar, which
76
+ * takes focus out of the wrapper and leaves the expanded menu with nothing that owns it;
77
+ * the menu is then closed and focus stays on the returned item. When the last banked item
78
+ * returns, the wrapper is about to be hidden: the menu is closed and focus is moved out of
79
+ * it to the last item that can actually hold it (`hidden` and disabled ones cannot), or to
80
+ * the root when none can.
81
+ *
82
+ * **Priority.** Lower `data-priority` is kept longer; a value that is absent, empty, or
83
+ * not a number ranks lowest and drops first.
84
+ *
85
+ * **Turbo.** The managed set and the canonical order are rebuilt *from the DOM* every
86
+ * pass, so a fresh `connect()` onto markup that already holds banked items (cache restore,
87
+ * a morph, a clone, server-rendered overflow) re-adopts them instead of orphaning them
88
+ * inside a wrapper it would then hide. Symmetrically, `disconnect()` and
89
+ * `turbo:before-cache` return every item to the bar, collapse the composed menu (so it
90
+ * releases its dismissal-stack membership rather than being snapshotted mid-gesture), and
91
+ * strip this controller's bookkeeping attributes, so a cached snapshot is always the
92
+ * pristine authored DOM. The `ResizeObserver` and debounce timer are released on
93
+ * `disconnect()` too.
94
+ *
95
+ * Behavior only — no styling.
37
96
  */
38
97
  declare class OverflowMenuController extends Controller<HTMLElement> {
39
98
  #private;