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
@@ -0,0 +1,511 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+
3
+ // src/controllers/navigation_menu_controller.ts
4
+
5
+ // src/utils/logical_scroll.ts
6
+ function isRtl(element) {
7
+ return window.getComputedStyle(element).direction === "rtl";
8
+ }
9
+
10
+ // src/utils/arrow_step.ts
11
+ function isReservedArrowChord(event, allow = []) {
12
+ if (!event.key.startsWith("Arrow")) return false;
13
+ return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
14
+ }
15
+
16
+ // src/utils/escape_layer.ts
17
+ function claimsWhileFocusWithin(element) {
18
+ return () => {
19
+ const active = element.ownerDocument.activeElement;
20
+ return active === null || active === element.ownerDocument.body || element.contains(active);
21
+ };
22
+ }
23
+ var EscapeLayer = class _EscapeLayer {
24
+ static #registries = /* @__PURE__ */ new WeakMap();
25
+ #ownerDocument = null;
26
+ /** Dismissal callback while active; `null` when inactive. */
27
+ #onDismiss = null;
28
+ /** Live predicate deciding whether the layer claims a press; `null` = always. */
29
+ #claims = null;
30
+ /**
31
+ * Activates this layer at the top of its document's Escape stack, installing
32
+ * the document's shared resolver listener if this is its first layer.
33
+ * Re-activating an already-active layer moves it to the top.
34
+ */
35
+ activate(ownerDocument = document, options) {
36
+ this.deactivate();
37
+ let registry = _EscapeLayer.#registries.get(ownerDocument);
38
+ if (!registry) {
39
+ registry = _EscapeLayer.#createRegistry();
40
+ _EscapeLayer.#registries.set(ownerDocument, registry);
41
+ ownerDocument.addEventListener("keydown", registry.onKeydown);
42
+ }
43
+ registry.stack.push(this);
44
+ this.#ownerDocument = ownerDocument;
45
+ this.#onDismiss = options.onDismiss;
46
+ this.#claims = options.claims ?? null;
47
+ }
48
+ /**
49
+ * Removes this layer from its document's Escape stack, uninstalling the
50
+ * shared listener when the stack empties. Safe to call when inactive.
51
+ */
52
+ deactivate() {
53
+ const ownerDocument = this.#ownerDocument;
54
+ if (!ownerDocument) return;
55
+ const registry = _EscapeLayer.#registries.get(ownerDocument);
56
+ if (registry) {
57
+ const index = registry.stack.lastIndexOf(this);
58
+ if (index >= 0) registry.stack.splice(index, 1);
59
+ if (registry.stack.length === 0) {
60
+ ownerDocument.removeEventListener("keydown", registry.onKeydown);
61
+ _EscapeLayer.#registries.delete(ownerDocument);
62
+ }
63
+ }
64
+ this.#ownerDocument = null;
65
+ this.#onDismiss = null;
66
+ this.#claims = null;
67
+ }
68
+ /**
69
+ * Whether this active layer would own a press right now: it is the topmost
70
+ * layer whose {@link EscapeLayerOptions.claims} passes. Exposed for tests
71
+ * and diagnostics — production dismissal goes through the shared listener.
72
+ */
73
+ get ownsEscape() {
74
+ const ownerDocument = this.#ownerDocument;
75
+ if (!ownerDocument) return false;
76
+ const registry = _EscapeLayer.#registries.get(ownerDocument);
77
+ if (!registry) return false;
78
+ return _EscapeLayer.#resolveOwner(registry.stack) === this;
79
+ }
80
+ /** Builds a document's registry with its shared resolver listener. */
81
+ static #createRegistry() {
82
+ const registry = {
83
+ stack: [],
84
+ onKeydown: (event) => {
85
+ if (event.key !== "Escape" || event.defaultPrevented || event.isComposing) return;
86
+ const owner = _EscapeLayer.#resolveOwner(registry.stack);
87
+ if (!owner) return;
88
+ event.preventDefault();
89
+ owner.#onDismiss?.();
90
+ }
91
+ };
92
+ return registry;
93
+ }
94
+ /** The topmost stack layer whose claims predicate passes, or `null`. */
95
+ static #resolveOwner(stack) {
96
+ for (let index = stack.length - 1; index >= 0; index--) {
97
+ const layer = stack[index];
98
+ if (!layer) continue;
99
+ if (layer.#claims && !layer.#claims()) continue;
100
+ return layer;
101
+ }
102
+ return null;
103
+ }
104
+ };
105
+
106
+ // src/utils/safe_timeout.ts
107
+ var TimerRegistry = class {
108
+ /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */
109
+ ids = /* @__PURE__ */ new Set();
110
+ /**
111
+ * Cancels a single tracked timer.
112
+ *
113
+ * No-ops if the id is unknown (already cleared, fired, or never owned by this
114
+ * registry), so callers can clear defensively without guarding.
115
+ */
116
+ clear(id) {
117
+ if (this.ids.delete(id)) {
118
+ this.cancel(id);
119
+ }
120
+ }
121
+ /**
122
+ * Cancels every tracked timer. Call this from a controller's `disconnect()`
123
+ * to guarantee no timer outlives the element.
124
+ */
125
+ clearAll() {
126
+ for (const id of this.ids) {
127
+ this.cancel(id);
128
+ }
129
+ this.ids.clear();
130
+ }
131
+ /** Number of timers currently tracked (pending). */
132
+ get size() {
133
+ return this.ids.size;
134
+ }
135
+ };
136
+ var SafeTimeout = class extends TimerRegistry {
137
+ /**
138
+ * Schedules `callback` after `delay` ms and returns the timer id.
139
+ *
140
+ * The id is removed from the registry automatically when the timeout fires,
141
+ * so {@link TimerRegistry.size | size} reflects only still-pending timers.
142
+ */
143
+ set(callback, delay) {
144
+ const id = this.schedule(() => {
145
+ this.ids.delete(id);
146
+ callback();
147
+ }, delay);
148
+ this.ids.add(id);
149
+ return id;
150
+ }
151
+ schedule(callback, delay) {
152
+ return window.setTimeout(callback, delay);
153
+ }
154
+ cancel(id) {
155
+ window.clearTimeout(id);
156
+ }
157
+ };
158
+
159
+ // src/controllers/navigation_menu_controller.ts
160
+ var NavigationMenuController = class extends Controller {
161
+ static targets = ["trigger", "panel", "hoverArea"];
162
+ static values = {
163
+ openOnHover: { type: Boolean, default: false },
164
+ hoverDelay: { type: Number, default: 150 }
165
+ };
166
+ static actions = ["onTriggerKeydown", "toggle"];
167
+ /** Open/close delay timers for hover mode; cleared together on disconnect. */
168
+ #hoverTimers = new SafeTimeout();
169
+ /**
170
+ * Elements currently carrying hover listeners. Removal always mirrors this
171
+ * set (not a recomputed target snapshot), so a rebuild driven by target churn
172
+ * can never strand a listener on an element that stopped being a target.
173
+ */
174
+ #hoverWired = /* @__PURE__ */ new Set();
175
+ /**
176
+ * The trigger whose hover region the pointer currently occupies, if any. Only
177
+ * the click semantics under `openOnHover` read it (see {@link toggle}).
178
+ */
179
+ #hoveredTrigger = null;
180
+ /**
181
+ * Whether the controller is between `connect()` and `disconnect()`. Stimulus
182
+ * disconnects the controller **before** disconnecting its targets, so the
183
+ * target callbacks below also fire during teardown; without this flag their
184
+ * rebuild would re-wire hover listeners onto an already-disconnected nav.
185
+ */
186
+ #connected = false;
187
+ /** Escape-stack membership while any panel is open; the shared resolver dismisses via it. */
188
+ #escapeLayer = new EscapeLayer();
189
+ /** Establishes the closed baseline and the dismissal listeners. */
190
+ connect() {
191
+ this.#connected = true;
192
+ this.#closeAll();
193
+ document.addEventListener("click", this.#onOutsideClick, true);
194
+ this.element.addEventListener("focusout", this.#onFocusOut);
195
+ if (this.openOnHoverValue) this.#addHoverListeners();
196
+ }
197
+ /** Removes every listener, pending hover timer, and stack membership taken while connected. */
198
+ disconnect() {
199
+ this.#connected = false;
200
+ this.#escapeLayer.deactivate();
201
+ document.removeEventListener("click", this.#onOutsideClick, true);
202
+ this.element.removeEventListener("focusout", this.#onFocusOut);
203
+ this.#removeHoverListeners();
204
+ this.#hoverTimers.clearAll();
205
+ }
206
+ /**
207
+ * Follows a runtime flip of `openOnHover` (a morph or a scripted attribute
208
+ * change) by wiring or unwiring the hover listeners in place. Stimulus also
209
+ * fires this once before `connect()`, which the `#connected` guard skips —
210
+ * `connect()` owns the initial wiring.
211
+ */
212
+ openOnHoverValueChanged() {
213
+ if (!this.#connected) return;
214
+ if (this.openOnHoverValue) this.#addHoverListeners();
215
+ else this.#removeHoverListeners();
216
+ }
217
+ /** Re-wires hover listeners when a target is added after connect (Turbo Streams etc.). */
218
+ triggerTargetConnected() {
219
+ this.#rewireHoverListeners();
220
+ }
221
+ /** Re-wires hover listeners when a target is removed while connected. */
222
+ triggerTargetDisconnected() {
223
+ this.#rewireHoverListeners();
224
+ }
225
+ /** See {@link NavigationMenuController.triggerTargetConnected}. */
226
+ panelTargetConnected() {
227
+ this.#rewireHoverListeners();
228
+ }
229
+ /** See {@link NavigationMenuController.triggerTargetDisconnected}. */
230
+ panelTargetDisconnected() {
231
+ this.#rewireHoverListeners();
232
+ }
233
+ /** See {@link NavigationMenuController.triggerTargetConnected}. */
234
+ hoverAreaTargetConnected() {
235
+ this.#rewireHoverListeners();
236
+ }
237
+ /** See {@link NavigationMenuController.triggerTargetDisconnected}. */
238
+ hoverAreaTargetDisconnected() {
239
+ this.#rewireHoverListeners();
240
+ }
241
+ /**
242
+ * Toggles a trigger's panel (single-open). Bound via `data-action` (click).
243
+ *
244
+ * An explicit activation always wins over a scheduled hover open/close, so any
245
+ * pending hover timer is dropped first — otherwise a close scheduled just
246
+ * before the click would fire into the freshly opened panel.
247
+ *
248
+ * Under `openOnHover`, closing a panel the pointer itself is holding open is
249
+ * refused: the pointer stays put, `mouseenter` does not re-fire, and the panel
250
+ * would be unopenable until the pointer left and came back. Keyboard
251
+ * activation (pointer elsewhere) still toggles it closed, and `Escape` and
252
+ * outside clicks dismiss either way.
253
+ */
254
+ toggle(event) {
255
+ const trigger = event.currentTarget;
256
+ this.#hoverTimers.clearAll();
257
+ if (!this.#isExpanded(trigger)) {
258
+ this.#openPanel(trigger);
259
+ return;
260
+ }
261
+ if (this.openOnHoverValue && this.#hoveredTrigger === trigger) return;
262
+ this.#closePanel(trigger);
263
+ }
264
+ /**
265
+ * `ArrowLeft`/`ArrowRight` move focus between triggers (keeping Tab order).
266
+ *
267
+ * Only navigable triggers are destinations, so a `hidden` or disabled item
268
+ * never swallows the press. A modified arrow belongs to the browser or OS
269
+ * (`Alt+←`/`Alt+→` is history back/forward), and with no destination at all
270
+ * (a single-trigger nav) the press is left to the page — `preventDefault()` is
271
+ * called only when focus actually moves, keeping the scroll-suppression
272
+ * contract honest.
273
+ */
274
+ onTriggerKeydown(event) {
275
+ if (event.defaultPrevented) return;
276
+ if (event.key !== "ArrowRight" && event.key !== "ArrowLeft") return;
277
+ if (isReservedArrowChord(event)) return;
278
+ const current = event.currentTarget;
279
+ const triggers = this.triggerTargets.filter(
280
+ (trigger) => trigger === current || this.#isNavigable(trigger)
281
+ );
282
+ const index = triggers.indexOf(current);
283
+ if (index === -1 || triggers.length < 2) return;
284
+ event.preventDefault();
285
+ const forward = isRtl(this.element) ? "ArrowLeft" : "ArrowRight";
286
+ const step = event.key === forward ? 1 : -1;
287
+ triggers[(index + step + triggers.length) % triggers.length]?.focus();
288
+ }
289
+ /**
290
+ * Opens `trigger`'s panel, closing any other open panel first. Re-opening an
291
+ * already-open panel only re-asserts the Escape layer: the close/open
292
+ * round-trip would rewrite `aria-expanded` and `hidden` for no state change.
293
+ */
294
+ #openPanel(trigger) {
295
+ if (trigger.getAttribute("aria-disabled") === "true") return;
296
+ if (this.#isExpanded(trigger)) {
297
+ this.#syncEscapeLayer();
298
+ return;
299
+ }
300
+ this.#closeAll();
301
+ const panel = this.#panelFor(trigger);
302
+ if (!panel) return;
303
+ panel.hidden = false;
304
+ trigger.setAttribute("aria-expanded", "true");
305
+ this.#syncEscapeLayer();
306
+ }
307
+ /** Closes `trigger`'s panel and reflects the collapsed state. */
308
+ #closePanel(trigger) {
309
+ const panel = this.#panelFor(trigger);
310
+ if (panel) panel.hidden = true;
311
+ trigger.setAttribute("aria-expanded", "false");
312
+ this.#syncEscapeLayer();
313
+ }
314
+ /**
315
+ * Closes every open panel and normalizes `aria-expanded="false"` on **all**
316
+ * triggers, so a trigger whose panel was hidden by other means cannot keep
317
+ * advertising an open panel.
318
+ */
319
+ #closeAll() {
320
+ for (const trigger of this.triggerTargets) this.#closePanel(trigger);
321
+ }
322
+ /**
323
+ * Whether a trigger can receive arrow-key focus: not `hidden`, not a natively
324
+ * `disabled` control (mirrors `toolbar`). CSS-only visibility cannot be
325
+ * detected headlessly and stays the consumer's responsibility.
326
+ *
327
+ * **`aria-disabled="true"` stays reachable.** APG separates the attributes by
328
+ * intent: `disabled` is for controls a neighbour makes inferable, while
329
+ * `aria-disabled` marks one that must remain *discoverable* — and a nav
330
+ * section the user cannot even arrow to is a section they cannot learn exists.
331
+ * Opening is suppressed separately, so the trigger announces itself and does
332
+ * nothing.
333
+ */
334
+ #isNavigable(trigger) {
335
+ if (trigger.hasAttribute("hidden")) return false;
336
+ return !trigger.disabled;
337
+ }
338
+ /**
339
+ * Aligns Escape-stack membership with the open state: joins (or re-asserts to
340
+ * the top) while a panel is open, leaves once none is. Re-asserting when the
341
+ * user switches panels is deliberate — the nav is again the newest layer.
342
+ */
343
+ #syncEscapeLayer() {
344
+ if (this.#isAnyOpen) {
345
+ this.#escapeLayer.activate(document, {
346
+ onDismiss: () => this.#closeAndRestore(),
347
+ claims: claimsWhileFocusWithin(this.element)
348
+ });
349
+ } else {
350
+ this.#escapeLayer.deactivate();
351
+ }
352
+ }
353
+ /**
354
+ * Closes any open panel and returns focus to its trigger (Escape path). A
355
+ * pending hover open would otherwise re-open the panel the user just
356
+ * dismissed, so the reservation is dropped with it.
357
+ */
358
+ #closeAndRestore() {
359
+ const open = this.#openTrigger;
360
+ if (!open) return;
361
+ this.#hoverTimers.clearAll();
362
+ this.#closePanel(open);
363
+ open.focus();
364
+ }
365
+ /** Closes panels when a click lands outside the nav element. */
366
+ #onOutsideClick = (event) => {
367
+ if (this.#isAnyOpen && !this.element.contains(event.target)) this.#closeAll();
368
+ };
369
+ /**
370
+ * Closes (without restoring focus) when focus leaves the nav for a known
371
+ * external destination. A null/non-Node destination is indeterminate:
372
+ * browsers use it for clicks on non-focusable content and for window
373
+ * deactivation, so those never close the nav here (matching the popover
374
+ * convention) — the outside-click handler decides pointer dismissal, and the
375
+ * Escape stack's body-focus claim keeps keyboard dismissal working.
376
+ */
377
+ #onFocusOut = (event) => {
378
+ const next = event.relatedTarget;
379
+ if (!(next instanceof Node) || this.element.contains(next)) return;
380
+ this.#closeAll();
381
+ };
382
+ /** Opens a trigger's panel after the hover delay (hover mode). */
383
+ #onPointerEnter = (event) => {
384
+ const trigger = this.#triggerForHover(event.currentTarget);
385
+ if (!trigger) return;
386
+ this.#hoveredTrigger = trigger;
387
+ this.#hoverTimers.clearAll();
388
+ this.#hoverTimers.set(() => this.#openFromHover(trigger), this.hoverDelayValue);
389
+ };
390
+ /**
391
+ * Closes the open panel after the hover delay (hover mode) — unless the
392
+ * pointer moved directly into another part of the hover region (an adjacent
393
+ * trigger, panel, or hoverArea): crossing a shared edge must not schedule a
394
+ * spurious close, e.g. a hoverArea whose panel sits outside it as a sibling.
395
+ */
396
+ #onPointerLeave = (event) => {
397
+ const next = event instanceof MouseEvent ? event.relatedTarget : null;
398
+ if (next instanceof Node && this.#hoverElements.some((el) => el.contains(next))) return;
399
+ this.#hoveredTrigger = null;
400
+ this.#hoverTimers.clearAll();
401
+ this.#hoverTimers.set(() => this.#closeFromHover(), this.hoverDelayValue);
402
+ };
403
+ /**
404
+ * Hover-driven open. Switching panels would hide the outgoing one, so focus
405
+ * standing inside it is handed back to its trigger first: pointer movement
406
+ * must never send focus to the body (the keyboard user would lose their
407
+ * place). Focus outside the closing panel is left alone.
408
+ */
409
+ #openFromHover(trigger) {
410
+ if (trigger.getAttribute("aria-disabled") === "true") return;
411
+ const open = this.#openTrigger;
412
+ if (open && open !== trigger && this.#holdsFocus(this.#panelFor(open))) open.focus();
413
+ this.#openPanel(trigger);
414
+ }
415
+ /**
416
+ * Hover-driven close: skipped while focus sits inside the panel it would hide,
417
+ * for the same no-focus-loss reason (cf. `hover_card`'s delayed close). The
418
+ * panel then stays open until `Escape`, an outside click, or focus leaving the
419
+ * nav dismisses it — all of which restore or keep focus deliberately.
420
+ */
421
+ #closeFromHover() {
422
+ const open = this.#openTrigger;
423
+ if (open && this.#holdsFocus(this.#panelFor(open))) return;
424
+ this.#closeAll();
425
+ }
426
+ /** Whether `panel` exists and currently contains the focused element. */
427
+ #holdsFocus(panel) {
428
+ return panel?.contains(document.activeElement) ?? false;
429
+ }
430
+ /** Wires hover open/close on each hover element (opt-in), tracking what was wired. */
431
+ #addHoverListeners() {
432
+ for (const element of this.#hoverElements) {
433
+ element.addEventListener("mouseenter", this.#onPointerEnter);
434
+ element.addEventListener("mouseleave", this.#onPointerLeave);
435
+ this.#hoverWired.add(element);
436
+ }
437
+ }
438
+ /** Removes the hover listeners from exactly the elements that were wired. */
439
+ #removeHoverListeners() {
440
+ for (const element of this.#hoverWired) {
441
+ element.removeEventListener("mouseenter", this.#onPointerEnter);
442
+ element.removeEventListener("mouseleave", this.#onPointerLeave);
443
+ }
444
+ this.#hoverWired.clear();
445
+ this.#hoveredTrigger = null;
446
+ }
447
+ /**
448
+ * Rebuilds the hover wiring from the current targets. Target callbacks call
449
+ * this so items added or removed after connect (e.g. a Turbo Stream append)
450
+ * participate in hover; the wired-set removal keeps the rebuild symmetric.
451
+ * Stimulus fires those callbacks during teardown too, hence the `#connected`
452
+ * guard — a rebuild after `disconnect()` would resurrect the listeners.
453
+ */
454
+ #rewireHoverListeners() {
455
+ if (!this.#connected || !this.openOnHoverValue) return;
456
+ this.#removeHoverListeners();
457
+ this.#addHoverListeners();
458
+ }
459
+ /**
460
+ * Elements that participate in hover: each `hoverArea`, plus every trigger and
461
+ * panel **not** wrapped by one. A wrapped trigger/panel must defer to its
462
+ * wrapper — its own mouseleave would otherwise schedule a close while the
463
+ * pointer is still inside the area (mouseenter does not re-fire on the wrapper
464
+ * when moving among its descendants), flickering the panel shut.
465
+ */
466
+ get #hoverElements() {
467
+ const areas = this.hoverAreaTargets;
468
+ const covered = (element) => areas.some((area) => area.contains(element));
469
+ return [
470
+ ...areas,
471
+ ...this.triggerTargets.filter((trigger) => !covered(trigger)),
472
+ ...this.panelTargets.filter((panel) => !covered(panel))
473
+ ];
474
+ }
475
+ /**
476
+ * Resolves the trigger for a hovered element: the trigger itself, the trigger
477
+ * controlling a hovered panel, or the first trigger contained in a hovered
478
+ * `hoverArea` wrapper.
479
+ */
480
+ #triggerForHover(element) {
481
+ if (this.triggerTargets.includes(element)) return element;
482
+ if (this.panelTargets.includes(element)) {
483
+ return this.triggerTargets.find((trigger) => this.#panelFor(trigger) === element) ?? null;
484
+ }
485
+ if (this.hoverAreaTargets.includes(element)) {
486
+ return this.triggerTargets.find((trigger) => element.contains(trigger)) ?? null;
487
+ }
488
+ return null;
489
+ }
490
+ /** The panel controlled by `trigger` (matched by `aria-controls`/`id`). */
491
+ #panelFor(trigger) {
492
+ const id = trigger.getAttribute("aria-controls");
493
+ return id ? this.panelTargets.find((panel) => panel.id === id) ?? null : null;
494
+ }
495
+ /** Whether `trigger`'s panel is currently expanded. */
496
+ #isExpanded(trigger) {
497
+ return trigger.getAttribute("aria-expanded") === "true";
498
+ }
499
+ /** The trigger whose panel is currently open, if any. */
500
+ get #openTrigger() {
501
+ return this.triggerTargets.find((trigger) => this.#isExpanded(trigger)) ?? null;
502
+ }
503
+ /** Whether any panel is currently open. */
504
+ get #isAnyOpen() {
505
+ return this.#openTrigger !== null;
506
+ }
507
+ };
508
+
509
+ export { NavigationMenuController };
510
+ //# sourceMappingURL=navigation_menu_controller.js.map
511
+ //# sourceMappingURL=navigation_menu_controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/logical_scroll.ts","../../src/utils/arrow_step.ts","../../src/utils/escape_layer.ts","../../src/utils/safe_timeout.ts","../../src/controllers/navigation_menu_controller.ts"],"names":[],"mappings":";;;;;AAiBO,SAAS,MAAM,OAAA,EAA2B;AAC/C,EAAA,OAAO,MAAA,CAAO,gBAAA,CAAiB,OAAO,CAAA,CAAE,SAAA,KAAc,KAAA;AACxD;;;AC4EO,SAAS,oBAAA,CACd,KAAA,EACA,KAAA,GAAkC,EAAC,EA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AAAA;AAAA,EAGA,IAAI,UAAA,GAAsB;AACxB,IAAA,OAAO,KAAK,YAAA,KAAiB,IAAA;AAAA,EAC/B;AACF","file":"navigation_menu_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 * Single resolver for layered Escape dismissal.\n *\n * Every Escape-dismissable overlay layer (modal focus traps, disclosure\n * overlays like dropdown/popover/menu, and hover-triggered transient layers)\n * registers here while it is open. One document-level listener per document\n * resolves each press to exactly one owner and invokes that layer's\n * {@link EscapeLayerOptions.onDismiss} — controllers never listen for a\n * dismissing Escape themselves.\n *\n * @remarks\n * Each document owns an activation-ordered stack. The owner of a press is the\n * **topmost layer whose {@link EscapeLayerOptions.claims} passes**; a layer\n * that declines is transparent, so a background overlay opened behind a modal\n * never blocks it. Because a layer opened from within another is necessarily\n * activated later, LIFO order is also inner-first for nested layers — no DOM\n * inspection is needed.\n *\n * The shared listener runs in the document bubble phase and honors\n * `event.defaultPrevented`, so an element-level widget handler that consumes\n * Escape first (an editor cancelling its edit, a combobox closing its list)\n * always wins over every registered layer — the deepest handler resolves the\n * press. A keydown that is part of an IME composition (`event.isComposing`)\n * cancels the composition, never a layer, and is ignored here for every layer\n * at once.\n *\n * A WeakMap keeps documents collectible; the listener is installed only while\n * a document's stack is non-empty, and controller lifecycle hooks guarantee\n * that disconnected layers never remain registered.\n */\n\n/** Behavior a layer registers when it activates. */\nexport interface EscapeLayerOptions {\n /**\n * Dismisses the layer. Called by the shared resolver when this layer owns a\n * press; the resolver has already consumed the event (`preventDefault()`),\n * so the callback only needs to close and place focus per the widget's\n * contract.\n */\n onDismiss: () => void;\n /**\n * Whether the layer claims the current press. Evaluated per press, so it can\n * depend on live state (e.g. \"focus is inside me or fell to the body\"). A\n * declining layer is skipped and the next layer down is consulted; omitting\n * it means the layer always claims while active.\n */\n claims?: () => boolean;\n}\n\n/** A document's stack plus the one shared listener bound to it. */\ninterface EscapeLayerRegistry {\n stack: EscapeLayer[];\n onKeydown: (event: KeyboardEvent) => void;\n}\n\n/**\n * Claims predicate shared by the click-opened disclosure overlays (dropdown /\n * popover / navigation-menu / menu / context-menu / menubar): the layer claims\n * a press while focus is inside `element`, or after focus fell to the body —\n * a click on non-focusable overlay content blurs to `<body>`, and Escape must\n * still close the overlay (the \"body-focus rescue\"). A press made after focus\n * moved to another interactive element is declined, so closing never yanks\n * focus away from where the user deliberately went.\n */\nexport function claimsWhileFocusWithin(element: Element): () => boolean {\n return () => {\n const active = element.ownerDocument.activeElement;\n return active === null || active === element.ownerDocument.body || element.contains(active);\n };\n}\n\nexport class EscapeLayer {\n static readonly #registries = new WeakMap<Document, EscapeLayerRegistry>();\n\n #ownerDocument: Document | null = null;\n /** Dismissal callback while active; `null` when inactive. */\n #onDismiss: (() => void) | null = null;\n /** Live predicate deciding whether the layer claims a press; `null` = always. */\n #claims: (() => boolean) | null = null;\n\n /**\n * Activates this layer at the top of its document's Escape stack, installing\n * the document's shared resolver listener if this is its first layer.\n * Re-activating an already-active layer moves it to the top.\n */\n activate(ownerDocument: Document = document, options: EscapeLayerOptions): void {\n this.deactivate();\n let registry = EscapeLayer.#registries.get(ownerDocument);\n if (!registry) {\n registry = EscapeLayer.#createRegistry();\n EscapeLayer.#registries.set(ownerDocument, registry);\n ownerDocument.addEventListener(\"keydown\", registry.onKeydown);\n }\n registry.stack.push(this);\n this.#ownerDocument = ownerDocument;\n this.#onDismiss = options.onDismiss;\n this.#claims = options.claims ?? null;\n }\n\n /**\n * Removes this layer from its document's Escape stack, uninstalling the\n * shared listener when the stack empties. Safe to call when inactive.\n */\n deactivate(): void {\n const ownerDocument = this.#ownerDocument;\n if (!ownerDocument) return;\n\n const registry = EscapeLayer.#registries.get(ownerDocument);\n if (registry) {\n const index = registry.stack.lastIndexOf(this);\n if (index >= 0) registry.stack.splice(index, 1);\n if (registry.stack.length === 0) {\n ownerDocument.removeEventListener(\"keydown\", registry.onKeydown);\n EscapeLayer.#registries.delete(ownerDocument);\n }\n }\n this.#ownerDocument = null;\n this.#onDismiss = null;\n this.#claims = null;\n }\n\n /**\n * Whether this active layer would own a press right now: it is the topmost\n * layer whose {@link EscapeLayerOptions.claims} passes. Exposed for tests\n * and diagnostics — production dismissal goes through the shared listener.\n */\n get ownsEscape(): boolean {\n const ownerDocument = this.#ownerDocument;\n if (!ownerDocument) return false;\n const registry = EscapeLayer.#registries.get(ownerDocument);\n if (!registry) return false;\n return EscapeLayer.#resolveOwner(registry.stack) === this;\n }\n\n /** Builds a document's registry with its shared resolver listener. */\n static #createRegistry(): EscapeLayerRegistry {\n const registry: EscapeLayerRegistry = {\n stack: [],\n onKeydown: (event: KeyboardEvent): void => {\n if (event.key !== \"Escape\" || event.defaultPrevented || event.isComposing) return;\n const owner = EscapeLayer.#resolveOwner(registry.stack);\n if (!owner) return;\n event.preventDefault();\n owner.#onDismiss?.();\n },\n };\n return registry;\n }\n\n /** The topmost stack layer whose claims predicate passes, or `null`. */\n static #resolveOwner(stack: EscapeLayer[]): EscapeLayer | null {\n for (let index = stack.length - 1; index >= 0; index--) {\n const layer = stack[index];\n if (!layer) continue;\n if (layer.#claims && !layer.#claims()) continue;\n return layer;\n }\n return null;\n }\n}\n","/**\n * Self-cleaning timer registries shared by Stimeo controllers.\n *\n * Stimulus controllers frequently schedule `setTimeout` / `setInterval` work\n * (auto-dismiss, debouncing, polling). When the element leaves the DOM — a\n * Turbo Drive navigation, a Turbo Stream replacement, or any `disconnect()` —\n * orphaned timers keep firing against a detached controller, leaking memory and\n * mutating stale state. {@link SafeTimeout} and {@link SafeInterval} track every\n * timer they create so a single {@link TimerRegistry.clearAll | clearAll()} call\n * in `disconnect()` tears them all down.\n *\n * These are intentionally low-level primitives: they own *registration and\n * cleanup only*. Higher-level policy (pause/resume, remaining-time accounting)\n * stays in the individual controllers so per-widget semantics are not flattened\n * into a lowest-common-denominator helper.\n */\n\n/**\n * Shared registry bookkeeping for the timeout/interval variants.\n *\n * Subclasses provide the scheduling primitive ({@link schedule}) and its matching\n * canceller ({@link cancel}); this base owns the set of live ids plus the\n * per-id and bulk teardown shared by both.\n */\nabstract class TimerRegistry {\n /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */\n protected readonly ids = new Set<number>();\n\n /** Schedules the underlying platform timer and returns its id. */\n protected abstract schedule(callback: () => void, delay: number): number;\n\n /** Cancels the underlying platform timer for `id`. */\n protected abstract cancel(id: number): void;\n\n /**\n * Cancels a single tracked timer.\n *\n * No-ops if the id is unknown (already cleared, fired, or never owned by this\n * registry), so callers can clear defensively without guarding.\n */\n clear(id: number): void {\n if (this.ids.delete(id)) {\n this.cancel(id);\n }\n }\n\n /**\n * Cancels every tracked timer. Call this from a controller's `disconnect()`\n * to guarantee no timer outlives the element.\n */\n clearAll(): void {\n for (const id of this.ids) {\n this.cancel(id);\n }\n this.ids.clear();\n }\n\n /** Number of timers currently tracked (pending). */\n get size(): number {\n return this.ids.size;\n }\n}\n\n/**\n * `setTimeout` wrapper that auto-forgets each timer once it fires and supports\n * bulk teardown on disconnect.\n *\n * @example\n * ```ts\n * #timers = new SafeTimeout();\n *\n * connect() {\n * this.#timers.set(() => this.dismiss(), 5000);\n * }\n *\n * disconnect() {\n * this.#timers.clearAll();\n * }\n * ```\n */\nexport class SafeTimeout extends TimerRegistry {\n /**\n * Schedules `callback` after `delay` ms and returns the timer id.\n *\n * The id is removed from the registry automatically when the timeout fires,\n * so {@link TimerRegistry.size | size} reflects only still-pending timers.\n */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(() => {\n this.ids.delete(id);\n callback();\n }, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setTimeout(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearTimeout(id);\n }\n}\n\n/**\n * `setInterval` wrapper that tracks every interval for bulk teardown on\n * disconnect. Unlike {@link SafeTimeout}, intervals are retained until they are\n * explicitly cleared because they fire repeatedly.\n *\n * @example\n * ```ts\n * #intervals = new SafeInterval();\n *\n * connect() {\n * this.#intervals.set(() => this.tick(), 1000);\n * }\n *\n * disconnect() {\n * this.#intervals.clearAll();\n * }\n * ```\n */\nexport class SafeInterval extends TimerRegistry {\n /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(callback, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setInterval(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearInterval(id);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\nimport { claimsWhileFocusWithin, EscapeLayer } from \"../utils/escape_layer\";\nimport { isRtl } from \"../utils/logical_scroll\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/**\n * Headless, accessible **navigation menu** behavior (disclosure navigation).\n *\n * Markup contract (identifier: `stimeo--navigation-menu`):\n * <nav data-controller=\"stimeo--navigation-menu\" aria-label=\"Main\">\n * <ul>\n * <li>\n * <button data-stimeo--navigation-menu-target=\"trigger\"\n * aria-expanded=\"false\" aria-controls=\"nav-products\"\n * data-action=\"click->stimeo--navigation-menu#toggle\n * keydown->stimeo--navigation-menu#onTriggerKeydown\">\n * Products\n * </button>\n * <div id=\"nav-products\" data-stimeo--navigation-menu-target=\"panel\" hidden>\n * <a href=\"/a\">Product A</a><a href=\"/b\">Product B</a>\n * </div>\n * </li>\n * </ul>\n * </nav>\n *\n * Implements the WAI-ARIA APG **Disclosure** navigation pattern: each top-level\n * button toggles its sub-panel (`aria-expanded` + `hidden` synced), only one panel\n * is open at a time, and the panel content is a plain set of links (not a\n * `role=\"menu\"`). Focus is **not** trapped — `Tab` moves through the links\n * naturally. `Escape` closes the open panel and returns focus to its trigger.\n * While a panel is open the nav is a layer on the shared {@link EscapeLayer}\n * stack; it claims a press only while focus is inside the nav or fell to the\n * body (a click on non-focusable panel content), so one keypress closes exactly\n * one layer. An outside click, or focus leaving the nav for a known external\n * destination, closes it. `ArrowLeft`/`ArrowRight` move focus between the\n * *navigable* triggers without rewriting `tabindex` (they keep their natural Tab\n * order); a modified press (`Alt`/`Ctrl`/`Meta`/`Shift`, e.g. the browser's\n * `Alt+←` history back) is left to the browser. Hover open/close is opt-in via\n * `openOnHover`.\n *\n * Every `panel` must be a **descendant of the nav element**: Stimulus resolves\n * targets within the controller's own scope, so a panel moved outside it (a\n * portal) never becomes a `panel` target and its trigger then opens nothing.\n *\n * By default the hover region is each trigger and its panel. An optional\n * `hoverArea` target widens it: mark a wrapper that contains **exactly one**\n * trigger (e.g. the `<li>` holding a top-level *link*, its disclosure button, and\n * its panel — the APG \"Disclosure Navigation with Top-Level Links\" arrangement)\n * and hovering anywhere over that wrapper opens the contained trigger's panel.\n * Wrapping several triggers at once (marking the whole `<ul>`, say) is not\n * supported: every hover over the area then resolves to the *first* contained\n * trigger. A trigger or panel inside a `hoverArea` defers to the wrapper (its own\n * edges stop scheduling open/close), so pointer movement within the area never\n * flickers the panel. Keep a trigger's panel inside its `hoverArea`: a panel left\n * outside simply falls back to the default two-region behavior — moving straight\n * across a shared edge never schedules a close (the leave handler checks\n * `relatedTarget`), and `hoverDelay` bridges the pointer's travel across an\n * actual gap. Targets added or removed **while connected** (e.g. a Turbo Stream\n * append) re-wire the hover listeners via Stimulus target callbacks; the same\n * callbacks also run during Stimulus teardown, so they no-op once disconnected.\n * Flipping `openOnHover` at runtime wires or unwires the listeners in place.\n * `hoverArea` has no effect unless `openOnHover` is enabled.\n *\n * Pointer-driven closing never hides focused content — hiding the panel would\n * take the focused link with it and drop focus to the body. So a hover *leave*\n * keeps the panel open while focus is inside it, and a hover *switch* to another\n * trigger returns focus to the outgoing trigger before hiding its panel. For the\n * same reason, while `openOnHover` is on, a click on a trigger whose hover region\n * the pointer currently occupies is a no-op: closing it would leave it unopenable\n * until the pointer left and re-entered (`mouseenter` does not re-fire in place).\n * `Escape` and outside clicks dismiss regardless.\n *\n * @remarks\n * Behavior only. Panel layout, mega-menu styling, and animation are the\n * consumer's CSS. Static placement is CSS; viewport-edge collision avoidance is\n * delegated to the opt-in `stimeo-ui/positioning` module (never imported here, so\n * the core stays zero-dependency). For an app command menu with arrow roving and\n * `role=\"menu\"`, use `stimeo--menubar` instead.\n */\nexport class NavigationMenuController extends Controller<HTMLElement> {\n static override targets = [\"trigger\", \"panel\", \"hoverArea\"];\n static override values = {\n openOnHover: { type: Boolean, default: false },\n hoverDelay: { type: Number, default: 150 },\n };\n static actions = [\"onTriggerKeydown\", \"toggle\"] as const;\n\n declare readonly triggerTargets: HTMLElement[];\n declare readonly panelTargets: HTMLElement[];\n declare readonly hoverAreaTargets: HTMLElement[];\n\n declare openOnHoverValue: boolean;\n declare hoverDelayValue: number;\n\n /** Open/close delay timers for hover mode; cleared together on disconnect. */\n readonly #hoverTimers = new SafeTimeout();\n\n /**\n * Elements currently carrying hover listeners. Removal always mirrors this\n * set (not a recomputed target snapshot), so a rebuild driven by target churn\n * can never strand a listener on an element that stopped being a target.\n */\n readonly #hoverWired = new Set<HTMLElement>();\n\n /**\n * The trigger whose hover region the pointer currently occupies, if any. Only\n * the click semantics under `openOnHover` read it (see {@link toggle}).\n */\n #hoveredTrigger: HTMLElement | null = null;\n\n /**\n * Whether the controller is between `connect()` and `disconnect()`. Stimulus\n * disconnects the controller **before** disconnecting its targets, so the\n * target callbacks below also fire during teardown; without this flag their\n * rebuild would re-wire hover listeners onto an already-disconnected nav.\n */\n #connected = false;\n\n /** Escape-stack membership while any panel is open; the shared resolver dismisses via it. */\n readonly #escapeLayer = new EscapeLayer();\n\n /** Establishes the closed baseline and the dismissal listeners. */\n override connect(): void {\n this.#connected = true;\n this.#closeAll();\n document.addEventListener(\"click\", this.#onOutsideClick, true);\n this.element.addEventListener(\"focusout\", this.#onFocusOut);\n if (this.openOnHoverValue) this.#addHoverListeners();\n }\n\n /** Removes every listener, pending hover timer, and stack membership taken while connected. */\n override disconnect(): void {\n this.#connected = false;\n this.#escapeLayer.deactivate();\n document.removeEventListener(\"click\", this.#onOutsideClick, true);\n this.element.removeEventListener(\"focusout\", this.#onFocusOut);\n this.#removeHoverListeners();\n this.#hoverTimers.clearAll();\n }\n\n /**\n * Follows a runtime flip of `openOnHover` (a morph or a scripted attribute\n * change) by wiring or unwiring the hover listeners in place. Stimulus also\n * fires this once before `connect()`, which the `#connected` guard skips —\n * `connect()` owns the initial wiring.\n */\n openOnHoverValueChanged(): void {\n if (!this.#connected) return;\n if (this.openOnHoverValue) this.#addHoverListeners();\n else this.#removeHoverListeners();\n }\n\n /** Re-wires hover listeners when a target is added after connect (Turbo Streams etc.). */\n triggerTargetConnected(): void {\n this.#rewireHoverListeners();\n }\n\n /** Re-wires hover listeners when a target is removed while connected. */\n triggerTargetDisconnected(): void {\n this.#rewireHoverListeners();\n }\n\n /** See {@link NavigationMenuController.triggerTargetConnected}. */\n panelTargetConnected(): void {\n this.#rewireHoverListeners();\n }\n\n /** See {@link NavigationMenuController.triggerTargetDisconnected}. */\n panelTargetDisconnected(): void {\n this.#rewireHoverListeners();\n }\n\n /** See {@link NavigationMenuController.triggerTargetConnected}. */\n hoverAreaTargetConnected(): void {\n this.#rewireHoverListeners();\n }\n\n /** See {@link NavigationMenuController.triggerTargetDisconnected}. */\n hoverAreaTargetDisconnected(): void {\n this.#rewireHoverListeners();\n }\n\n /**\n * Toggles a trigger's panel (single-open). Bound via `data-action` (click).\n *\n * An explicit activation always wins over a scheduled hover open/close, so any\n * pending hover timer is dropped first — otherwise a close scheduled just\n * before the click would fire into the freshly opened panel.\n *\n * Under `openOnHover`, closing a panel the pointer itself is holding open is\n * refused: the pointer stays put, `mouseenter` does not re-fire, and the panel\n * would be unopenable until the pointer left and came back. Keyboard\n * activation (pointer elsewhere) still toggles it closed, and `Escape` and\n * outside clicks dismiss either way.\n */\n toggle(event: Event): void {\n const trigger = event.currentTarget as HTMLElement;\n this.#hoverTimers.clearAll();\n if (!this.#isExpanded(trigger)) {\n this.#openPanel(trigger);\n return;\n }\n if (this.openOnHoverValue && this.#hoveredTrigger === trigger) return;\n this.#closePanel(trigger);\n }\n\n /**\n * `ArrowLeft`/`ArrowRight` move focus between triggers (keeping Tab order).\n *\n * Only navigable triggers are destinations, so a `hidden` or disabled item\n * never swallows the press. A modified arrow belongs to the browser or OS\n * (`Alt+←`/`Alt+→` is history back/forward), and with no destination at all\n * (a single-trigger nav) the press is left to the page — `preventDefault()` is\n * called only when focus actually moves, keeping the scroll-suppression\n * contract honest.\n */\n onTriggerKeydown(event: KeyboardEvent): void {\n // A descendant widget that already claimed the key must not ALSO move the\n // trigger focus — composition depends on this yield. It runs ahead of the\n // modifier check, so a claimed press is yielded whether or not it carries a\n // modifier.\n if (event.defaultPrevented) return;\n if (event.key !== \"ArrowRight\" && event.key !== \"ArrowLeft\") return;\n if (isReservedArrowChord(event)) return;\n\n const current = event.currentTarget as HTMLElement;\n // The focused trigger stays in the ring even when it is not navigable\n // itself, so arrows still lead *out* of a trigger disabled while focused.\n const triggers = this.triggerTargets.filter(\n (trigger) => trigger === current || this.#isNavigable(trigger),\n );\n const index = triggers.indexOf(current);\n if (index === -1 || triggers.length < 2) return;\n\n event.preventDefault();\n // Logical, not physical: the triggers are an ordered row, so which one is\n // \"next\" follows the writing direction. Read from the controller element —\n // the nav lays the triggers out, and a trigger may carry its own `dir`.\n const forward = isRtl(this.element) ? \"ArrowLeft\" : \"ArrowRight\";\n const step = event.key === forward ? 1 : -1;\n triggers[(index + step + triggers.length) % triggers.length]?.focus();\n }\n\n /**\n * Opens `trigger`'s panel, closing any other open panel first. Re-opening an\n * already-open panel only re-asserts the Escape layer: the close/open\n * round-trip would rewrite `aria-expanded` and `hidden` for no state change.\n */\n #openPanel(trigger: HTMLElement): void {\n // Guarded here rather than in `toggle`, because hover reaches this method\n // without going through it. Reaching an `aria-disabled` trigger is what the\n // attribute asks for — opening its panel is the activation it forbids, and\n // opening a popup counts as activation.\n if (trigger.getAttribute(\"aria-disabled\") === \"true\") return;\n if (this.#isExpanded(trigger)) {\n this.#syncEscapeLayer();\n return;\n }\n this.#closeAll();\n const panel = this.#panelFor(trigger);\n if (!panel) return;\n panel.hidden = false;\n trigger.setAttribute(\"aria-expanded\", \"true\");\n this.#syncEscapeLayer();\n }\n\n /** Closes `trigger`'s panel and reflects the collapsed state. */\n #closePanel(trigger: HTMLElement): void {\n const panel = this.#panelFor(trigger);\n if (panel) panel.hidden = true;\n trigger.setAttribute(\"aria-expanded\", \"false\");\n this.#syncEscapeLayer();\n }\n\n /**\n * Closes every open panel and normalizes `aria-expanded=\"false\"` on **all**\n * triggers, so a trigger whose panel was hidden by other means cannot keep\n * advertising an open panel.\n */\n #closeAll(): void {\n for (const trigger of this.triggerTargets) this.#closePanel(trigger);\n }\n\n /**\n * Whether a trigger can receive arrow-key focus: not `hidden`, not a natively\n * `disabled` control (mirrors `toolbar`). CSS-only visibility cannot be\n * detected headlessly and stays the consumer's responsibility.\n *\n * **`aria-disabled=\"true\"` stays reachable.** APG separates the attributes by\n * intent: `disabled` is for controls a neighbour makes inferable, while\n * `aria-disabled` marks one that must remain *discoverable* — and a nav\n * section the user cannot even arrow to is a section they cannot learn exists.\n * Opening is suppressed separately, so the trigger announces itself and does\n * nothing.\n */\n #isNavigable(trigger: HTMLElement): boolean {\n if (trigger.hasAttribute(\"hidden\")) return false;\n return !(trigger as HTMLButtonElement | HTMLInputElement).disabled;\n }\n\n /**\n * Aligns Escape-stack membership with the open state: joins (or re-asserts to\n * the top) while a panel is open, leaves once none is. Re-asserting when the\n * user switches panels is deliberate — the nav is again the newest layer.\n */\n #syncEscapeLayer(): void {\n if (this.#isAnyOpen) {\n this.#escapeLayer.activate(document, {\n onDismiss: () => this.#closeAndRestore(),\n claims: claimsWhileFocusWithin(this.element),\n });\n } else {\n this.#escapeLayer.deactivate();\n }\n }\n\n /**\n * Closes any open panel and returns focus to its trigger (Escape path). A\n * pending hover open would otherwise re-open the panel the user just\n * dismissed, so the reservation is dropped with it.\n */\n #closeAndRestore(): void {\n const open = this.#openTrigger;\n if (!open) return;\n this.#hoverTimers.clearAll();\n this.#closePanel(open);\n open.focus();\n }\n\n /** Closes panels when a click lands outside the nav element. */\n readonly #onOutsideClick = (event: MouseEvent): void => {\n if (this.#isAnyOpen && !this.element.contains(event.target as Node)) this.#closeAll();\n };\n\n /**\n * Closes (without restoring focus) when focus leaves the nav for a known\n * external destination. A null/non-Node destination is indeterminate:\n * browsers use it for clicks on non-focusable content and for window\n * deactivation, so those never close the nav here (matching the popover\n * convention) — the outside-click handler decides pointer dismissal, and the\n * Escape stack's body-focus claim keeps keyboard dismissal working.\n */\n readonly #onFocusOut = (event: FocusEvent): void => {\n const next = event.relatedTarget;\n if (!(next instanceof Node) || this.element.contains(next)) return;\n this.#closeAll();\n };\n\n /** Opens a trigger's panel after the hover delay (hover mode). */\n readonly #onPointerEnter = (event: Event): void => {\n const trigger = this.#triggerForHover(event.currentTarget as HTMLElement);\n if (!trigger) return;\n this.#hoveredTrigger = trigger;\n this.#hoverTimers.clearAll();\n this.#hoverTimers.set(() => this.#openFromHover(trigger), this.hoverDelayValue);\n };\n\n /**\n * Closes the open panel after the hover delay (hover mode) — unless the\n * pointer moved directly into another part of the hover region (an adjacent\n * trigger, panel, or hoverArea): crossing a shared edge must not schedule a\n * spurious close, e.g. a hoverArea whose panel sits outside it as a sibling.\n */\n readonly #onPointerLeave = (event: Event): void => {\n const next = event instanceof MouseEvent ? event.relatedTarget : null;\n if (next instanceof Node && this.#hoverElements.some((el) => el.contains(next))) return;\n this.#hoveredTrigger = null;\n this.#hoverTimers.clearAll();\n this.#hoverTimers.set(() => this.#closeFromHover(), this.hoverDelayValue);\n };\n\n /**\n * Hover-driven open. Switching panels would hide the outgoing one, so focus\n * standing inside it is handed back to its trigger first: pointer movement\n * must never send focus to the body (the keyboard user would lose their\n * place). Focus outside the closing panel is left alone.\n */\n #openFromHover(trigger: HTMLElement): void {\n // Checked before the rescue below, not only inside `#openPanel`. The rescue\n // exists to get focus out of a panel that is about to be hidden; when the\n // destination refuses to open, nothing is hidden and moving focus buys\n // nothing — it just walks the caret out of a panel that stays open.\n if (trigger.getAttribute(\"aria-disabled\") === \"true\") return;\n const open = this.#openTrigger;\n if (open && open !== trigger && this.#holdsFocus(this.#panelFor(open))) open.focus();\n this.#openPanel(trigger);\n }\n\n /**\n * Hover-driven close: skipped while focus sits inside the panel it would hide,\n * for the same no-focus-loss reason (cf. `hover_card`'s delayed close). The\n * panel then stays open until `Escape`, an outside click, or focus leaving the\n * nav dismisses it — all of which restore or keep focus deliberately.\n */\n #closeFromHover(): void {\n const open = this.#openTrigger;\n if (open && this.#holdsFocus(this.#panelFor(open))) return;\n this.#closeAll();\n }\n\n /** Whether `panel` exists and currently contains the focused element. */\n #holdsFocus(panel: HTMLElement | null): boolean {\n return panel?.contains(document.activeElement) ?? false;\n }\n\n /** Wires hover open/close on each hover element (opt-in), tracking what was wired. */\n #addHoverListeners(): void {\n for (const element of this.#hoverElements) {\n element.addEventListener(\"mouseenter\", this.#onPointerEnter);\n element.addEventListener(\"mouseleave\", this.#onPointerLeave);\n this.#hoverWired.add(element);\n }\n }\n\n /** Removes the hover listeners from exactly the elements that were wired. */\n #removeHoverListeners(): void {\n for (const element of this.#hoverWired) {\n element.removeEventListener(\"mouseenter\", this.#onPointerEnter);\n element.removeEventListener(\"mouseleave\", this.#onPointerLeave);\n }\n this.#hoverWired.clear();\n this.#hoveredTrigger = null;\n }\n\n /**\n * Rebuilds the hover wiring from the current targets. Target callbacks call\n * this so items added or removed after connect (e.g. a Turbo Stream append)\n * participate in hover; the wired-set removal keeps the rebuild symmetric.\n * Stimulus fires those callbacks during teardown too, hence the `#connected`\n * guard — a rebuild after `disconnect()` would resurrect the listeners.\n */\n #rewireHoverListeners(): void {\n if (!this.#connected || !this.openOnHoverValue) return;\n this.#removeHoverListeners();\n this.#addHoverListeners();\n }\n\n /**\n * Elements that participate in hover: each `hoverArea`, plus every trigger and\n * panel **not** wrapped by one. A wrapped trigger/panel must defer to its\n * wrapper — its own mouseleave would otherwise schedule a close while the\n * pointer is still inside the area (mouseenter does not re-fire on the wrapper\n * when moving among its descendants), flickering the panel shut.\n */\n get #hoverElements(): HTMLElement[] {\n const areas = this.hoverAreaTargets;\n const covered = (element: HTMLElement): boolean => areas.some((area) => area.contains(element));\n return [\n ...areas,\n ...this.triggerTargets.filter((trigger) => !covered(trigger)),\n ...this.panelTargets.filter((panel) => !covered(panel)),\n ];\n }\n\n /**\n * Resolves the trigger for a hovered element: the trigger itself, the trigger\n * controlling a hovered panel, or the first trigger contained in a hovered\n * `hoverArea` wrapper.\n */\n #triggerForHover(element: HTMLElement): HTMLElement | null {\n if (this.triggerTargets.includes(element)) return element;\n if (this.panelTargets.includes(element)) {\n return this.triggerTargets.find((trigger) => this.#panelFor(trigger) === element) ?? null;\n }\n if (this.hoverAreaTargets.includes(element)) {\n return this.triggerTargets.find((trigger) => element.contains(trigger)) ?? null;\n }\n return null;\n }\n\n /** The panel controlled by `trigger` (matched by `aria-controls`/`id`). */\n #panelFor(trigger: HTMLElement): HTMLElement | null {\n const id = trigger.getAttribute(\"aria-controls\");\n // Resolve against this controller's own panel targets (not a global id\n // lookup) so it stays scoped to this nav instance.\n return id ? (this.panelTargets.find((panel) => panel.id === id) ?? null) : null;\n }\n\n /** Whether `trigger`'s panel is currently expanded. */\n #isExpanded(trigger: HTMLElement): boolean {\n return trigger.getAttribute(\"aria-expanded\") === \"true\";\n }\n\n /** The trigger whose panel is currently open, if any. */\n get #openTrigger(): HTMLElement | null {\n return this.triggerTargets.find((trigger) => this.#isExpanded(trigger)) ?? null;\n }\n\n /** Whether any panel is currently open. */\n get #isAnyOpen(): boolean {\n return this.#openTrigger !== null;\n }\n}\n"]}
@@ -28,11 +28,10 @@ import { Controller } from '@hotwired/stimulus';
28
28
  * (inserted nodes + each `_destroy` hidden input); there is no module-scope index
29
29
  * counter, so the controller stays idempotent across Turbo swaps. Remove buttons
30
30
  * are handled by **delegation** on the container, so dynamically-added rows work
31
- * without per-row `data-action` (see `stimulus-lifecycle-turbo`). Adding a row moves
32
- * focus to its first control and removing returns focus to a neighbor (WCAG 2.2
33
- * 2.4.3); count changes are announced through the shared `stimeo--announcer`
34
- * (WCAG 2.2 4.1.3) when `announce` + `countMessage` are set. The delegated listener
35
- * is removed on `disconnect()`.
31
+ * without per-row `data-action`. Adding a row moves focus to its first control and
32
+ * removing returns focus to a neighbor (WCAG 2.2 2.4.3); count changes are announced
33
+ * through the shared `stimeo--announcer` (WCAG 2.2 4.1.3) when `announce` +
34
+ * `countMessage` are set. The delegated listener is removed on `disconnect()`.
36
35
  */
37
36
  declare class NestedFormController extends Controller<HTMLElement> {
38
37
  #private;