stimeo-ui 0.2.1 → 0.4.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 (219) hide show
  1. package/CHANGELOG.md +160 -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.js +10 -0
  5. package/dist/controllers/accordion_controller.js.map +1 -1
  6. package/dist/controllers/alert_dialog_controller.js +32 -5
  7. package/dist/controllers/alert_dialog_controller.js.map +1 -1
  8. package/dist/controllers/announcer_controller.d.ts +32 -6
  9. package/dist/controllers/announcer_controller.js +255 -20
  10. package/dist/controllers/announcer_controller.js.map +1 -1
  11. package/dist/controllers/breadcrumb_controller.d.ts +97 -10
  12. package/dist/controllers/breadcrumb_controller.js +225 -13
  13. package/dist/controllers/breadcrumb_controller.js.map +1 -1
  14. package/dist/controllers/calendar_controller.d.ts +11 -1
  15. package/dist/controllers/calendar_controller.js +89 -22
  16. package/dist/controllers/calendar_controller.js.map +1 -1
  17. package/dist/controllers/carousel_controller.d.ts +16 -1
  18. package/dist/controllers/carousel_controller.js +47 -6
  19. package/dist/controllers/carousel_controller.js.map +1 -1
  20. package/dist/controllers/collapsible_controller.js +2 -2
  21. package/dist/controllers/collapsible_controller.js.map +1 -1
  22. package/dist/controllers/color_picker_controller.d.ts +14 -2
  23. package/dist/controllers/color_picker_controller.js +92 -7
  24. package/dist/controllers/color_picker_controller.js.map +1 -1
  25. package/dist/controllers/combobox_controller.d.ts +14 -1
  26. package/dist/controllers/combobox_controller.js +162 -23
  27. package/dist/controllers/combobox_controller.js.map +1 -1
  28. package/dist/controllers/command_palette_controller.d.ts +2 -0
  29. package/dist/controllers/command_palette_controller.js +226 -22
  30. package/dist/controllers/command_palette_controller.js.map +1 -1
  31. package/dist/controllers/confirm_controller.js +32 -5
  32. package/dist/controllers/confirm_controller.js.map +1 -1
  33. package/dist/controllers/context_menu_controller.d.ts +7 -6
  34. package/dist/controllers/context_menu_controller.js +32 -10
  35. package/dist/controllers/context_menu_controller.js.map +1 -1
  36. package/dist/controllers/count_up_controller.js.map +1 -1
  37. package/dist/controllers/countdown_controller.d.ts +19 -5
  38. package/dist/controllers/countdown_controller.js +112 -12
  39. package/dist/controllers/countdown_controller.js.map +1 -1
  40. package/dist/controllers/data_grid_controller.d.ts +19 -1
  41. package/dist/controllers/data_grid_controller.js +82 -4
  42. package/dist/controllers/data_grid_controller.js.map +1 -1
  43. package/dist/controllers/date_range_picker_controller.d.ts +5 -1
  44. package/dist/controllers/date_range_picker_controller.js +77 -3
  45. package/dist/controllers/date_range_picker_controller.js.map +1 -1
  46. package/dist/controllers/dialog_controller.js +32 -5
  47. package/dist/controllers/dialog_controller.js.map +1 -1
  48. package/dist/controllers/dismissible_controller.js.map +1 -1
  49. package/dist/controllers/drawer_controller.js +32 -5
  50. package/dist/controllers/drawer_controller.js.map +1 -1
  51. package/dist/controllers/dropdown_controller.d.ts +1 -2
  52. package/dist/controllers/dropdown_controller.js.map +1 -1
  53. package/dist/controllers/editable_controller.js +1 -0
  54. package/dist/controllers/editable_controller.js.map +1 -1
  55. package/dist/controllers/empty_state_controller.d.ts +9 -4
  56. package/dist/controllers/empty_state_controller.js +24 -10
  57. package/dist/controllers/empty_state_controller.js.map +1 -1
  58. package/dist/controllers/focus_controller.d.ts +1 -1
  59. package/dist/controllers/focus_controller.js +32 -5
  60. package/dist/controllers/focus_controller.js.map +1 -1
  61. package/dist/controllers/form_field_controller.js.map +1 -1
  62. package/dist/controllers/form_validation_controller.js +1 -1
  63. package/dist/controllers/form_validation_controller.js.map +1 -1
  64. package/dist/controllers/frame_loading_controller.d.ts +14 -3
  65. package/dist/controllers/frame_loading_controller.js +177 -15
  66. package/dist/controllers/frame_loading_controller.js.map +1 -1
  67. package/dist/controllers/highlight_controller.js.map +1 -1
  68. package/dist/controllers/hover_card_controller.d.ts +1 -1
  69. package/dist/controllers/hover_card_controller.js.map +1 -1
  70. package/dist/controllers/intersection_controller.js +36 -11
  71. package/dist/controllers/intersection_controller.js.map +1 -1
  72. package/dist/controllers/lazy_frame_controller.js +31 -10
  73. package/dist/controllers/lazy_frame_controller.js.map +1 -1
  74. package/dist/controllers/listbox_controller.d.ts +9 -2
  75. package/dist/controllers/listbox_controller.js +257 -53
  76. package/dist/controllers/listbox_controller.js.map +1 -1
  77. package/dist/controllers/local_time_controller.d.ts +19 -3
  78. package/dist/controllers/local_time_controller.js +102 -8
  79. package/dist/controllers/local_time_controller.js.map +1 -1
  80. package/dist/controllers/menu_controller.d.ts +29 -11
  81. package/dist/controllers/menu_controller.js +104 -17
  82. package/dist/controllers/menu_controller.js.map +1 -1
  83. package/dist/controllers/menubar_controller.d.ts +91 -11
  84. package/dist/controllers/menubar_controller.js +415 -63
  85. package/dist/controllers/menubar_controller.js.map +1 -1
  86. package/dist/controllers/meter_controller.d.ts +22 -2
  87. package/dist/controllers/meter_controller.js +145 -26
  88. package/dist/controllers/meter_controller.js.map +1 -1
  89. package/dist/controllers/multi_select_controller.d.ts +31 -5
  90. package/dist/controllers/multi_select_controller.js +312 -29
  91. package/dist/controllers/multi_select_controller.js.map +1 -1
  92. package/dist/controllers/navigation_menu_controller.d.ts +65 -18
  93. package/dist/controllers/navigation_menu_controller.js +154 -27
  94. package/dist/controllers/navigation_menu_controller.js.map +1 -1
  95. package/dist/controllers/nested_form_controller.d.ts +4 -5
  96. package/dist/controllers/nested_form_controller.js.map +1 -1
  97. package/dist/controllers/network_status_controller.d.ts +13 -1
  98. package/dist/controllers/network_status_controller.js +28 -8
  99. package/dist/controllers/network_status_controller.js.map +1 -1
  100. package/dist/controllers/number_input_controller.d.ts +1 -1
  101. package/dist/controllers/number_input_controller.js +7 -0
  102. package/dist/controllers/number_input_controller.js.map +1 -1
  103. package/dist/controllers/otp_controller.js +18 -1
  104. package/dist/controllers/otp_controller.js.map +1 -1
  105. package/dist/controllers/overflow_indicator_controller.d.ts +3 -2
  106. package/dist/controllers/overflow_indicator_controller.js +81 -13
  107. package/dist/controllers/overflow_indicator_controller.js.map +1 -1
  108. package/dist/controllers/overflow_menu_controller.d.ts +78 -19
  109. package/dist/controllers/overflow_menu_controller.js +408 -57
  110. package/dist/controllers/overflow_menu_controller.js.map +1 -1
  111. package/dist/controllers/pagination_controller.d.ts +36 -5
  112. package/dist/controllers/pagination_controller.js +163 -32
  113. package/dist/controllers/pagination_controller.js.map +1 -1
  114. package/dist/controllers/persist_controller.js +6 -6
  115. package/dist/controllers/persist_controller.js.map +1 -1
  116. package/dist/controllers/pointer_drag_controller.d.ts +2 -3
  117. package/dist/controllers/pointer_drag_controller.js +9 -1
  118. package/dist/controllers/pointer_drag_controller.js.map +1 -1
  119. package/dist/controllers/popover_controller.d.ts +1 -2
  120. package/dist/controllers/popover_controller.js +2 -2
  121. package/dist/controllers/popover_controller.js.map +1 -1
  122. package/dist/controllers/portal_controller.d.ts +4 -4
  123. package/dist/controllers/portal_controller.js.map +1 -1
  124. package/dist/controllers/progress_controller.d.ts +16 -1
  125. package/dist/controllers/progress_controller.js +116 -9
  126. package/dist/controllers/progress_controller.js.map +1 -1
  127. package/dist/controllers/radio_group_controller.js +22 -3
  128. package/dist/controllers/radio_group_controller.js.map +1 -1
  129. package/dist/controllers/range_slider_controller.d.ts +18 -5
  130. package/dist/controllers/range_slider_controller.js +100 -9
  131. package/dist/controllers/range_slider_controller.js.map +1 -1
  132. package/dist/controllers/rating_controller.d.ts +4 -1
  133. package/dist/controllers/rating_controller.js +69 -2
  134. package/dist/controllers/rating_controller.js.map +1 -1
  135. package/dist/controllers/read_more_controller.js +63 -19
  136. package/dist/controllers/read_more_controller.js.map +1 -1
  137. package/dist/controllers/reading_progress_controller.js.map +1 -1
  138. package/dist/controllers/relative_time_controller.d.ts +13 -0
  139. package/dist/controllers/relative_time_controller.js +133 -12
  140. package/dist/controllers/relative_time_controller.js.map +1 -1
  141. package/dist/controllers/resizable_controller.d.ts +3 -1
  142. package/dist/controllers/resizable_controller.js +65 -1
  143. package/dist/controllers/resizable_controller.js.map +1 -1
  144. package/dist/controllers/roving_controller.js +17 -2
  145. package/dist/controllers/roving_controller.js.map +1 -1
  146. package/dist/controllers/scroll_area_controller.js +86 -12
  147. package/dist/controllers/scroll_area_controller.js.map +1 -1
  148. package/dist/controllers/scroll_restore_controller.js +1 -1
  149. package/dist/controllers/scroll_restore_controller.js.map +1 -1
  150. package/dist/controllers/scroll_visibility_controller.d.ts +6 -3
  151. package/dist/controllers/scroll_visibility_controller.js +33 -3
  152. package/dist/controllers/scroll_visibility_controller.js.map +1 -1
  153. package/dist/controllers/scrollspy_controller.d.ts +64 -15
  154. package/dist/controllers/scrollspy_controller.js +346 -73
  155. package/dist/controllers/scrollspy_controller.js.map +1 -1
  156. package/dist/controllers/separator_controller.d.ts +20 -5
  157. package/dist/controllers/separator_controller.js +9 -0
  158. package/dist/controllers/separator_controller.js.map +1 -1
  159. package/dist/controllers/sidebar_controller.d.ts +2 -12
  160. package/dist/controllers/sidebar_controller.js +37 -8
  161. package/dist/controllers/sidebar_controller.js.map +1 -1
  162. package/dist/controllers/skeleton_controller.d.ts +7 -2
  163. package/dist/controllers/skeleton_controller.js +73 -20
  164. package/dist/controllers/skeleton_controller.js.map +1 -1
  165. package/dist/controllers/slider_controller.d.ts +11 -1
  166. package/dist/controllers/slider_controller.js +49 -8
  167. package/dist/controllers/slider_controller.js.map +1 -1
  168. package/dist/controllers/sortable_controller.d.ts +3 -1
  169. package/dist/controllers/sortable_controller.js +34 -3
  170. package/dist/controllers/sortable_controller.js.map +1 -1
  171. package/dist/controllers/spinner_controller.d.ts +37 -4
  172. package/dist/controllers/spinner_controller.js +228 -27
  173. package/dist/controllers/spinner_controller.js.map +1 -1
  174. package/dist/controllers/step_indicator_controller.d.ts +12 -1
  175. package/dist/controllers/step_indicator_controller.js +82 -5
  176. package/dist/controllers/step_indicator_controller.js.map +1 -1
  177. package/dist/controllers/stick_to_bottom_controller.d.ts +31 -8
  178. package/dist/controllers/stick_to_bottom_controller.js +61 -10
  179. package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
  180. package/dist/controllers/sticky_observer_controller.js +32 -11
  181. package/dist/controllers/sticky_observer_controller.js.map +1 -1
  182. package/dist/controllers/submit_once_controller.d.ts +2 -2
  183. package/dist/controllers/submit_once_controller.js.map +1 -1
  184. package/dist/controllers/switch_controller.js +1 -0
  185. package/dist/controllers/switch_controller.js.map +1 -1
  186. package/dist/controllers/tabs_controller.d.ts +11 -3
  187. package/dist/controllers/tabs_controller.js +26 -3
  188. package/dist/controllers/tabs_controller.js.map +1 -1
  189. package/dist/controllers/tags_input_controller.js +22 -2
  190. package/dist/controllers/tags_input_controller.js.map +1 -1
  191. package/dist/controllers/theme_controller.d.ts +1 -1
  192. package/dist/controllers/theme_controller.js +22 -3
  193. package/dist/controllers/theme_controller.js.map +1 -1
  194. package/dist/controllers/time_picker_controller.js +20 -1
  195. package/dist/controllers/time_picker_controller.js.map +1 -1
  196. package/dist/controllers/toast_controller.d.ts +4 -5
  197. package/dist/controllers/toast_controller.js +4 -5
  198. package/dist/controllers/toast_controller.js.map +1 -1
  199. package/dist/controllers/toggle_group_controller.js +23 -2
  200. package/dist/controllers/toggle_group_controller.js.map +1 -1
  201. package/dist/controllers/toolbar_controller.d.ts +53 -13
  202. package/dist/controllers/toolbar_controller.js +230 -31
  203. package/dist/controllers/toolbar_controller.js.map +1 -1
  204. package/dist/controllers/tooltip_controller.d.ts +1 -1
  205. package/dist/controllers/tooltip_controller.js.map +1 -1
  206. package/dist/controllers/transition_controller.js.map +1 -1
  207. package/dist/controllers/tree_view_controller.d.ts +87 -6
  208. package/dist/controllers/tree_view_controller.js +467 -51
  209. package/dist/controllers/tree_view_controller.js.map +1 -1
  210. package/dist/index.js +4507 -907
  211. package/dist/index.js.map +1 -1
  212. package/dist/inspector/cli.d.ts +375 -39
  213. package/dist/inspector/cli.js +1009 -86
  214. package/dist/inspector/cli.js.map +1 -1
  215. package/dist/inspector/cli_bin.js +1200 -120
  216. package/dist/inspector/cli_bin.js.map +1 -1
  217. package/dist/inspector/examples.json +28 -28
  218. package/dist/inspector/manifest.json +1060 -132
  219. package/package.json +5 -6
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/safe_timeout.ts","../../src/controllers/announcer_controller.ts"],"names":[],"mappings":";;;;;AAwBA,IAAe,gBAAf,MAA6B;AAAA;AAAA,EAER,GAAA,uBAAU,GAAA,EAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAczC,MAAM,EAAA,EAAkB;AACtB,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,MAAA,CAAO,EAAE,CAAA,EAAG;AACvB,MAAA,IAAA,CAAK,OAAO,EAAE,CAAA;AAAA,IAChB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAA,GAAiB;AACf,IAAA,KAAA,MAAW,EAAA,IAAM,KAAK,GAAA,EAAK;AACzB,MAAA,IAAA,CAAK,OAAO,EAAE,CAAA;AAAA,IAChB;AACA,IAAA,IAAA,CAAK,IAAI,KAAA,EAAM;AAAA,EACjB;AAAA;AAAA,EAGA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,KAAK,GAAA,CAAI,IAAA;AAAA,EAClB;AACF,CAAA;AAmBO,IAAM,WAAA,GAAN,cAA0B,aAAA,CAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO7C,GAAA,CAAI,UAAsB,KAAA,EAAuB;AAC/C,IAAA,MAAM,EAAA,GAAK,IAAA,CAAK,QAAA,CAAS,MAAM;AAC7B,MAAA,IAAA,CAAK,GAAA,CAAI,OAAO,EAAE,CAAA;AAClB,MAAA,QAAA,EAAS;AAAA,IACX,GAAG,KAAK,CAAA;AACR,IAAA,IAAA,CAAK,GAAA,CAAI,IAAI,EAAE,CAAA;AACf,IAAA,OAAO,EAAA;AAAA,EACT;AAAA,EAEU,QAAA,CAAS,UAAsB,KAAA,EAAuB;AAC9D,IAAA,OAAO,MAAA,CAAO,UAA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B,IAAA,IAAA,CAAK,OAAA,CAAQ,YAAY,MAAM,CAAA;AAC/B,IAAA,IAAA,CAAK,UAAA,CAAW,GAAA,CAAI,KAAA,EAAO,MAAM,CAAA;AACjC,IAAA,OAAO,MAAA;AAAA,EACT;AAAA;AAAA,EAGA,mBAAmB,MAAA,EAAgC;AACjD,IAAA,IAAI,MAAA,IAAU,OAAO,MAAA,KAAW,QAAA,IAAY,aAAa,MAAA,EAAQ;AAC/D,MAAA,MAAM,QAAS,MAAA,CAAmC,OAAA;AAClD,MAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,CAAM,MAAA,GAAS,GAAG,OAAO,KAAA;AAAA,IAC5D;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA,EAGA,qBAAqB,MAAA,EAA0B;AAC7C,IAAA,OACE,CAAC,CAAC,MAAA,IACF,OAAO,MAAA,KAAW,QAAA,IACjB,OAAmC,SAAA,KAAc,IAAA;AAAA,EAEtD;AACF;AASO,SAAS,aAAa,IAAA,EAAyB;AACpD,EAAA,MAAM,EAAE,OAAM,GAAI,IAAA;AAClB,EAAA,KAAA,CAAM,QAAA,GAAW,UAAA;AACjB,EAAA,KAAA,CAAM,KAAA,GAAQ,KAAA;AACd,EAAA,KAAA,CAAM,MAAA,GAAS,KAAA;AACf,EAAA,KAAA,CAAM,MAAA,GAAS,MAAA;AACf,EAAA,KAAA,CAAM,OAAA,GAAU,GAAA;AAChB,EAAA,KAAA,CAAM,MAAA,GAAS,GAAA;AACf,EAAA,KAAA,CAAM,QAAA,GAAW,QAAA;AACjB,EAAA,KAAA,CAAM,IAAA,GAAO,eAAA;AACb,EAAA,KAAA,CAAM,QAAA,GAAW,YAAA;AACjB,EAAA,KAAA,CAAM,UAAA,GAAa,QAAA;AACrB","file":"announcer_controller.js","sourcesContent":["/**\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 { SafeTimeout } from \"../utils/safe_timeout\";\n\n/**\n * Headless, shared **live-region announcer** — a polite/assertive screen-reader\n * announcement base (no dedicated APG pattern; follows the WAI-ARIA \"Alert\" /\n * \"Status\" live-region guidance and WCAG 2.2 **4.1.3 Status Messages**).\n *\n * Markup contract (identifier: `stimeo--announcer`):\n * <!-- Place once per page; the consumer visually hides the regions in CSS. -->\n * <div data-controller=\"stimeo--announcer\">\n * <div data-stimeo--announcer-target=\"polite\" aria-live=\"polite\" aria-atomic=\"true\"></div>\n * <div data-stimeo--announcer-target=\"assertive\" aria-live=\"assertive\" aria-atomic=\"true\"></div>\n * </div>\n *\n * <!-- Attribute-only trigger: declare the activation event explicitly. -->\n * <button data-action=\"click->stimeo--announcer#announce\"\n * data-stimeo--announcer-message-param=\"Saved\"\n * data-stimeo--announcer-assertive-param=\"false\">Save</button>\n *\n * <!-- Programmatic trigger (e.g. from another controller / Turbo Stream). -->\n * window.dispatchEvent(new CustomEvent(\"stimeo--announcer:announce\", {\n * detail: { message: \"12 results\", assertive: false },\n * }))\n *\n * The announcer is the shared substrate other controllers (Auto-Submit, Flash,\n * Bulk Select, …) lean on instead of each carrying their own live region.\n *\n * @remarks\n * Behavior only, with **one deliberate exception**: when a `polite`/`assertive`\n * target is absent the controller *generates* the missing region and applies the\n * canonical visually-hidden inline style (see {@link visuallyHide}). A live region\n * must exist and be visually hidden to do its job, and a generated node has no\n * consumer CSS hook to hide it; consumers who want to own styling supply their own\n * targets. The controller never moves focus — announcements must not steal it\n * (WCAG 2.2 4.1.3). Listeners and clear timers are torn down on `disconnect()`\n * (Turbo included), and any generated regions are removed.\n */\nexport class AnnouncerController extends Controller<HTMLElement> {\n static override targets = [\"polite\", \"assertive\"];\n static override values = {\n clearAfter: { type: Number, default: 1000 },\n dedupeReannounce: { type: Boolean, default: true },\n };\n static actions = [\"announce\"] as const;\n\n declare readonly politeTarget: HTMLElement;\n declare readonly assertiveTarget: HTMLElement;\n declare readonly hasPoliteTarget: boolean;\n declare readonly hasAssertiveTarget: boolean;\n\n declare clearAfterValue: number;\n declare dedupeReannounceValue: boolean;\n\n /** Clear/re-announce timers; one `clearAll()` in disconnect tears them all down. */\n readonly #timers = new SafeTimeout();\n\n /** Live regions generated to stand in for absent targets, for teardown. */\n readonly #generated = new Map<\"assertive\" | \"polite\", HTMLElement>();\n\n /**\n * Guards against handling the same CustomEvent twice. An event dispatched on\n * the controller element with `bubbles: true` reaches both the element and the\n * `window` listener; this WeakSet ensures it announces only once.\n */\n readonly #handled = new WeakSet<Event>();\n\n /** Receives programmatic announcements at the element or bubbled to `window`. */\n readonly #onAnnounceEvent = (event: Event): void => {\n if (this.#handled.has(event)) return;\n this.#handled.add(event);\n const detail = (event as CustomEvent<unknown>).detail;\n const message = this.#messageFromDetail(detail);\n if (!message) return;\n this.#announce(message, this.#assertiveFromDetail(detail));\n };\n\n override connect(): void {\n this.element.addEventListener(\"stimeo--announcer:announce\", this.#onAnnounceEvent);\n window.addEventListener(\"stimeo--announcer:announce\", this.#onAnnounceEvent);\n }\n\n override disconnect(): void {\n this.element.removeEventListener(\"stimeo--announcer:announce\", this.#onAnnounceEvent);\n window.removeEventListener(\"stimeo--announcer:announce\", this.#onAnnounceEvent);\n this.#timers.clearAll();\n for (const region of this.#generated.values()) {\n region.remove();\n }\n this.#generated.clear();\n }\n\n /**\n * Announces a message. Reads the text from a Stimulus action param\n * (`message`, plus optional `assertive`) for attribute-only triggers, falling\n * back to a CustomEvent `detail` when the same handler is wired to an event.\n * An empty/non-string message is ignored so untrusted payloads cannot blank\n * the region.\n */\n announce(event: Event): void {\n const params = (event as { params?: Record<string, unknown> }).params;\n const fromParam = params?.message;\n const message =\n typeof fromParam === \"string\" && fromParam.length > 0\n ? fromParam\n : this.#messageFromDetail((event as CustomEvent<unknown>).detail);\n if (!message) return;\n\n const assertive =\n params?.assertive === true ||\n this.#assertiveFromDetail((event as CustomEvent<unknown>).detail);\n this.#announce(message, assertive);\n }\n\n /**\n * Writes `message` into the matching live region and schedules its clear.\n *\n * When the region already holds the same text, an aria-atomic region is not\n * re-read by assistive tech (the node did not change). If `dedupeReannounce`\n * is on, the text is cleared and re-set on a later task so the mutation is\n * observed and announced again.\n */\n #announce(message: string, assertive: boolean): void {\n const region = this.#regionFor(assertive ? \"assertive\" : \"polite\");\n\n if (this.dedupeReannounceValue && region.textContent === message) {\n region.textContent = \"\";\n this.#timers.set(() => {\n region.textContent = message;\n this.#scheduleClear(region, message);\n }, 0);\n return;\n }\n\n region.textContent = message;\n this.#scheduleClear(region, message);\n }\n\n /** Clears the region after `clearAfter` ms, unless a newer message replaced it. */\n #scheduleClear(region: HTMLElement, message: string): void {\n if (this.clearAfterValue <= 0) return;\n this.#timers.set(() => {\n if (region.textContent === message) region.textContent = \"\";\n }, this.clearAfterValue);\n }\n\n /** Resolves the live region for a politeness level, generating it if absent. */\n #regionFor(level: \"assertive\" | \"polite\"): HTMLElement {\n if (level === \"assertive\" && this.hasAssertiveTarget) return this.assertiveTarget;\n if (level === \"polite\" && this.hasPoliteTarget) return this.politeTarget;\n\n const existing = this.#generated.get(level);\n if (existing) return existing;\n\n const region = document.createElement(\"div\");\n region.setAttribute(\"aria-live\", level);\n region.setAttribute(\"aria-atomic\", \"true\");\n visuallyHide(region);\n this.element.appendChild(region);\n this.#generated.set(level, region);\n return region;\n }\n\n /** Extracts a non-empty string `message` from a CustomEvent detail, else null. */\n #messageFromDetail(detail: unknown): string | null {\n if (detail && typeof detail === \"object\" && \"message\" in detail) {\n const value = (detail as Record<string, unknown>).message;\n if (typeof value === \"string\" && value.length > 0) return value;\n }\n return null;\n }\n\n /** Reads an `assertive === true` flag from a CustomEvent detail (default polite). */\n #assertiveFromDetail(detail: unknown): boolean {\n return (\n !!detail &&\n typeof detail === \"object\" &&\n (detail as Record<string, unknown>).assertive === true\n );\n }\n}\n\n/**\n * Applies the canonical visually-hidden (\"sr-only\") inline style to a generated\n * live region so its text is announced without being seen. Inline so the library\n * stays self-contained when the consumer provides no target/CSS of its own.\n *\n * Pure (no `this`); exported for direct unit testing.\n */\nexport function visuallyHide(node: HTMLElement): void {\n const { style } = node;\n style.position = \"absolute\";\n style.width = \"1px\";\n style.height = \"1px\";\n style.margin = \"-1px\";\n style.padding = \"0\";\n style.border = \"0\";\n style.overflow = \"hidden\";\n style.clip = \"rect(0 0 0 0)\";\n style.clipPath = \"inset(50%)\";\n style.whiteSpace = \"nowrap\";\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/before_cache_reset.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/safe_timeout.ts","../../src/controllers/announcer_controller.ts"],"names":[],"mappings":";;;;;AA2CO,IAAM,gBAAA,GAAN,MAAM,iBAAA,CAAiB;AAAA;AAAA,EAE5B,OAAgB,YAAA,mBAAe,IAAI,GAAA,EAAsB;AAAA;AAAA,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AAA,CAAM,QAAA,GAAW,YAAA;AACjB,EAAA,KAAA,CAAM,UAAA,GAAa,QAAA;AACrB","file":"announcer_controller.js","sourcesContent":["/**\n * Runs a controller's \"return to the initial state\" pass just before Turbo\n * caches the page.\n *\n * **`disconnect()` cannot do this job, for two independent reasons.** Turbo\n * queues the clone from this event rather than taking it here, and the body swap\n * that runs the controller's `disconnect()` is queued separately — so which of\n * the two lands first is not something a controller can rely on, and a rewind\n * written in `disconnect()` may reach only the DOM being thrown away. In the\n * other direction, `disconnect()` also fires on an in-page move (Stimulus tears\n * down and reconnects the same element), where rewinding would wipe a\n * legitimately in-progress interaction — a spinner mid-load would vanish. One\n * timing is unreliable, the other is too eager; `turbo:before-cache` is the only\n * point that is exactly \"the page is about to be frozen\".\n *\n * Scope is the subscription only: registering on `activate()`, unregistering on\n * `deactivate()`, and one shared document listener no matter how many instances\n * are live. *What* to return to its initial state — which `data-state`, which\n * `hidden`, which `aria-busy` — stays in the controller, because no two\n * consumers answer it the same way (the `MicrotaskCoalescer` split).\n *\n * **Rewind state, not appearance.** The pass writes attributes the controller\n * itself owns; the visual result of those attributes is the consumer's CSS, and\n * a library that reached for style or class names would be guessing at markup\n * it does not own.\n *\n * Both entry points are idempotent, so the lifecycle hooks can call them\n * unconditionally: a second `activate()` does not double-subscribe and does not\n * make the callback run twice, and `deactivate()` on an instance that never\n * subscribed is a no-op.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #beforeCache = new BeforeCacheReset(() => this.#rewind());\n *\n * connect() { this.#beforeCache.activate(); }\n * disconnect() { this.#beforeCache.deactivate(); }\n * ```\n */\nexport class BeforeCacheReset {\n /** Every subscribed instance, iterated by the one shared document listener. */\n static readonly #subscribers = new Set<BeforeCacheReset>();\n\n /** The shared listener; installed while at least one instance is subscribed. */\n static readonly #onBeforeCache = (): void => {\n for (const subscriber of BeforeCacheReset.#subscribers) subscriber.#rewind();\n };\n\n readonly #rewind: () => void;\n\n /** @param rewind - the pass that returns this controller's state to its initial form. */\n constructor(rewind: () => void) {\n this.#rewind = rewind;\n }\n\n /** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */\n activate(): void {\n const first = BeforeCacheReset.#subscribers.size === 0;\n BeforeCacheReset.#subscribers.add(this);\n if (first) {\n document.addEventListener(\"turbo:before-cache\", BeforeCacheReset.#onBeforeCache);\n }\n }\n\n /** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */\n deactivate(): void {\n BeforeCacheReset.#subscribers.delete(this);\n if (BeforeCacheReset.#subscribers.size > 0) return;\n document.removeEventListener(\"turbo:before-cache\", BeforeCacheReset.#onBeforeCache);\n }\n}\n","/**\n * Collapses many target callbacks from one DOM mutation into a single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element, so\n * replacing a list of N options delivers N callbacks — but the useful unit of\n * work is \"reconcile against the DOM that resulted\", once, after the batch has\n * settled. Every controller that owns a reconcilable target set needs the same\n * shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers the *initial* target callbacks\n * ahead of `connect()`. Reconciling there would compute a fallback against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\n });\n }\n}\n","/**\n * 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 { BeforeCacheReset } from \"../utils/before_cache_reset\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/** The two politeness levels this controller keeps a region for. */\nconst LEVELS = [\"polite\", \"assertive\"] as const;\n\n/** One of the politeness levels in {@link LEVELS}. */\ntype Level = (typeof LEVELS)[number];\n\n/**\n * Headless, shared **live-region announcer** — a polite/assertive screen-reader\n * announcement base (no dedicated APG pattern; follows the WAI-ARIA \"Alert\" /\n * \"Status\" live-region guidance and WCAG 2.2 **4.1.3 Status Messages**).\n *\n * Markup contract (identifier: `stimeo--announcer`):\n * <!-- Place once per page; the consumer visually hides the regions in CSS. -->\n * <div data-controller=\"stimeo--announcer\">\n * <div data-stimeo--announcer-target=\"polite\" aria-live=\"polite\" aria-atomic=\"true\"></div>\n * <div data-stimeo--announcer-target=\"assertive\" aria-live=\"assertive\" aria-atomic=\"true\"></div>\n * </div>\n *\n * <!-- Attribute-only trigger: declare the activation event explicitly. -->\n * <button data-action=\"click->stimeo--announcer#announce\"\n * data-stimeo--announcer-message-param=\"Saved\"\n * data-stimeo--announcer-assertive-param=\"false\">Save</button>\n *\n * <!-- Programmatic trigger (e.g. from another controller / Turbo Stream). -->\n * window.dispatchEvent(new CustomEvent(\"stimeo--announcer:announce\", {\n * detail: { message: \"12 results\", assertive: false },\n * }))\n *\n * The announcer is the shared substrate other controllers (Auto-Submit, Flash,\n * Bulk Select, …) lean on instead of each carrying their own live region.\n *\n * @remarks\n * Behavior only, with **one deliberate exception**: when a `polite`/`assertive`\n * target is absent the controller *generates* the missing region **on connect**\n * and applies the canonical visually-hidden inline style (see {@link visuallyHide}).\n * A live region must exist and be visually hidden to do its job, and a generated\n * node has no consumer CSS hook to hide it; consumers who want to own styling\n * supply their own targets. Generation happens up front rather than on the first\n * announcement because assistive tech reports changes to a region it already\n * knows about — a region created and written within one task loses that first\n * message. The controller never moves focus — announcements must not steal it\n * (WCAG 2.2 4.1.3). Listeners and clear timers are torn down on `disconnect()`\n * (Turbo included), and any generated regions are removed — from the cached\n * snapshot too, via {@link BeforeCacheReset}, because `connect()` cannot reuse a\n * restored region (it carries no target attribute) and would pair another one\n * with it on every visit.\n *\n * **Messages are queued, one write per task.** Assistive tech announces what it\n * observes changing, so two messages written into one region within a single task\n * are one observed change and the earlier message is never read. Each politeness\n * has its own FIFO — an assertive message never waits behind polite ones — and a\n * message is written only in a task where its region already existed.\n *\n * **The region set is kept whole while connected.** Exactly one region per\n * politeness is present: an authored target retires the stand-in generated for it,\n * losing one materialises a stand-in again, and a generated region removed by a\n * morph (it is absent from the server's HTML, so a morph drops it) is put back\n * without waiting for the next message.\n */\nexport class AnnouncerController extends Controller<HTMLElement> {\n static override targets = [\"polite\", \"assertive\"];\n static override values = {\n clearAfter: { type: Number, default: 1000 },\n dedupeReannounce: { type: Boolean, default: true },\n };\n static actions = [\"announce\"] as const;\n\n declare readonly politeTarget: HTMLElement;\n declare readonly assertiveTarget: HTMLElement;\n declare readonly hasPoliteTarget: boolean;\n declare readonly hasAssertiveTarget: boolean;\n\n declare clearAfterValue: number;\n declare dedupeReannounceValue: boolean;\n\n /** Clear/re-announce timers; one `clearAll()` in disconnect tears them all down. */\n readonly #timers = new SafeTimeout();\n\n /** Live regions generated to stand in for absent targets, for teardown. */\n readonly #generated = new Map<Level, HTMLElement>();\n\n /** Messages waiting to be written, oldest first, one queue per politeness. */\n readonly #queues = new Map<Level, string[]>();\n\n /** Politeness levels whose next drain is already armed. */\n readonly #draining = new Set<Level>();\n\n /** Collapses a batch of target callbacks (and morph removals) into one pass. */\n readonly #reconcile = new MicrotaskCoalescer(() => this.#reconcileRegions());\n\n /**\n * Watches the host's own children for a generated region disappearing. A morph\n * drops it — the server's HTML never had it — and no target callback reports\n * that, because a generated region carries no target attribute. `subtree` stays\n * off so writing a message inside a region does not re-enter this pass.\n */\n readonly #hostWatch = new MutationObserver(() => {\n this.#reconcile.schedule();\n });\n\n /** Rewinds to an announceable initial state for the snapshot; see the remarks. */\n readonly #beforeCache = new BeforeCacheReset(() => this.#rewindForCache());\n\n /**\n * The one timer a region may have outstanding — its dedupe re-set, then its\n * auto-clear. Held weakly so a swapped-out target is not retained; a leftover\n * id is harmless because {@link SafeTimeout.clear} no-ops on an id it does not\n * own.\n */\n readonly #pending = new WeakMap<HTMLElement, number>();\n\n /**\n * Guards against handling the same CustomEvent twice. An event dispatched on\n * the controller element with `bubbles: true` reaches both the element and the\n * `window` listener; this WeakSet ensures it announces only once.\n */\n readonly #handled = new WeakSet<Event>();\n\n /** Receives programmatic announcements at the element or bubbled to `window`. */\n readonly #onAnnounceEvent = (event: Event): void => {\n if (this.#handled.has(event)) return;\n this.#handled.add(event);\n const detail = (event as CustomEvent<unknown>).detail;\n const message = this.#messageFromDetail(detail);\n if (!message) return;\n this.#announce(message, this.#assertiveFromDetail(detail));\n };\n\n override connect(): void {\n this.#reconcile.activate();\n this.#beforeCache.activate();\n // Materialise any missing region now, so it is in the accessibility tree\n // before the first message rather than appearing with it.\n this.#reconcileRegions();\n this.#hostWatch.observe(this.element, { childList: true });\n this.element.addEventListener(\"stimeo--announcer:announce\", this.#onAnnounceEvent);\n window.addEventListener(\"stimeo--announcer:announce\", this.#onAnnounceEvent);\n }\n\n override disconnect(): void {\n this.#reconcile.cancel();\n this.#hostWatch.disconnect();\n this.#beforeCache.deactivate();\n this.element.removeEventListener(\"stimeo--announcer:announce\", this.#onAnnounceEvent);\n window.removeEventListener(\"stimeo--announcer:announce\", this.#onAnnounceEvent);\n this.#timers.clearAll();\n this.#queues.clear();\n this.#draining.clear();\n this.#removeGenerated();\n }\n\n /** Retires the stand-in once the consumer supplies a polite region. */\n politeTargetConnected(): void {\n this.#reconcile.schedule();\n }\n\n /** Materialises a stand-in once the consumer's polite region goes away. */\n politeTargetDisconnected(): void {\n this.#reconcile.schedule();\n }\n\n /** Retires the stand-in once the consumer supplies an assertive region. */\n assertiveTargetConnected(): void {\n this.#reconcile.schedule();\n }\n\n /** Materialises a stand-in once the consumer's assertive region goes away. */\n assertiveTargetDisconnected(): void {\n this.#reconcile.schedule();\n }\n\n /**\n * Brings the region set back to exactly one region per politeness and reports\n * whether anything had to be created.\n *\n * A region created here is not written to in the same task: assistive tech\n * reports changes to regions it already knows about, so {@link drain} waits a\n * task whenever this says a region is new.\n */\n #reconcileRegions(): boolean {\n let created = false;\n for (const level of LEVELS) {\n if (this.#hasTargetFor(level)) {\n // The consumer owns this politeness now; a stand-in would be a second\n // region for it, and an empty one nothing ever writes to.\n const generated = this.#generated.get(level);\n if (generated) {\n generated.remove();\n this.#generated.delete(level);\n }\n continue;\n }\n const existing = this.#generated.get(level);\n if (existing?.isConnected) continue;\n this.#generated.set(level, this.#createRegion(level));\n created = true;\n }\n return created;\n }\n\n /** Whether the consumer supplied a target for `level`. */\n #hasTargetFor(level: Level): boolean {\n return level === \"assertive\" ? this.hasAssertiveTarget : this.hasPoliteTarget;\n }\n\n /** Builds a visually hidden live region for `level` and attaches it. */\n #createRegion(level: Level): HTMLElement {\n const region = document.createElement(\"div\");\n region.setAttribute(\"aria-live\", level);\n region.setAttribute(\"aria-atomic\", \"true\");\n visuallyHide(region);\n this.element.appendChild(region);\n return region;\n }\n\n /**\n * Removes and forgets every region this controller generated. Authored targets\n * belong to the consumer and are left untouched. Forgetting them is what keeps\n * the live page working after a snapshot rewind: the next announcement finds an\n * empty map and materialises a fresh region.\n */\n #removeGenerated(): void {\n for (const region of this.#generated.values()) {\n region.remove();\n }\n this.#generated.clear();\n }\n\n /**\n * Announces a message. Reads the text from a Stimulus action param\n * (`message`, plus optional `assertive`) for attribute-only triggers, falling\n * back to a CustomEvent `detail` when the same handler is wired to an event.\n * An empty/non-string message is ignored so untrusted payloads cannot blank\n * the region.\n */\n announce(event: Event): void {\n const params = (event as { params?: Record<string, unknown> }).params;\n const fromParam = params?.message;\n const message =\n typeof fromParam === \"string\" && fromParam.length > 0\n ? fromParam\n : this.#messageFromDetail((event as CustomEvent<unknown>).detail);\n if (!message) return;\n\n const assertive =\n params?.assertive === true ||\n this.#assertiveFromDetail((event as CustomEvent<unknown>).detail);\n this.#announce(message, assertive);\n }\n\n /**\n * Queues `message` for its politeness and arms the drain.\n *\n * Queuing is what makes a burst audible: assistive tech announces the changes it\n * observes, so several messages written into one region within a single task are\n * one change and only the last is read.\n */\n #announce(message: string, assertive: boolean): void {\n const level: Level = assertive ? \"assertive\" : \"polite\";\n const queue = this.#queues.get(level);\n if (queue) {\n queue.push(message);\n } else {\n this.#queues.set(level, [message]);\n }\n this.#scheduleDrain(level);\n }\n\n /** Arms one drain pass for `level`; further messages ride the pass already armed. */\n #scheduleDrain(level: Level): void {\n if (this.#draining.has(level)) return;\n this.#draining.add(level);\n this.#timers.set(() => {\n this.#draining.delete(level);\n this.#drain(level);\n }, 0);\n }\n\n /**\n * Writes one queued message, then arms the next pass while the queue holds more.\n *\n * Two steps take a whole pass without consuming the message: materialising a\n * region (it has to be in the accessibility tree before the text arrives) and\n * emptying a region that already holds this exact text (an unchanged node is not\n * re-read, so `dedupeReannounce` clears first and writes on the following pass).\n */\n #drain(level: Level): void {\n const queue = this.#queues.get(level);\n const message = queue?.[0];\n if (queue === undefined || message === undefined) return;\n\n if (this.#reconcileRegions()) {\n this.#scheduleDrain(level);\n return;\n }\n\n const region = this.#regionFor(level);\n if (this.dedupeReannounceValue && region.textContent === message) {\n this.#cancelPending(region);\n region.textContent = \"\";\n this.#scheduleDrain(level);\n return;\n }\n\n queue.shift();\n this.#cancelPending(region);\n region.textContent = message;\n this.#scheduleClear(region, message);\n if (queue.length > 0) this.#scheduleDrain(level);\n }\n\n /** Clears the region after `clearAfter` ms, unless a newer message replaced it. */\n #scheduleClear(region: HTMLElement, message: string): void {\n if (this.clearAfterValue <= 0) return;\n this.#schedule(\n region,\n () => {\n if (region.textContent === message) region.textContent = \"\";\n },\n this.clearAfterValue,\n );\n }\n\n /**\n * Arms `region`'s single pending timer. Callers reach here with the slot\n * already free — `#announce` releases it, and a fired timer clears its own\n * entry below — so this does not cancel again.\n */\n #schedule(region: HTMLElement, callback: () => void, delay: number): void {\n const id = this.#timers.set(() => {\n // Drop the id as it fires: platform timer ids are recycled, and a stale\n // one left here could later cancel the *other* region's live timer.\n this.#pending.delete(region);\n callback();\n }, delay);\n this.#pending.set(region, id);\n }\n\n /** Releases `region`'s pending timer, if it has one. */\n #cancelPending(region: HTMLElement): void {\n // `SafeTimeout.clear` ignores an id it does not own, so the \"no pending\n // timer\" case needs no branch of its own.\n this.#timers.clear(this.#pending.get(region) ?? -1);\n this.#pending.delete(region);\n }\n\n /**\n * Resolves the live region for a politeness level.\n *\n * The remembered stand-in is used only while it is still in the document: a morph\n * can drop it, and writing into the detached node would announce nothing at all.\n */\n #regionFor(level: Level): HTMLElement {\n if (level === \"assertive\" && this.hasAssertiveTarget) return this.assertiveTarget;\n if (level === \"polite\" && this.hasPoliteTarget) return this.politeTarget;\n\n const existing = this.#generated.get(level);\n if (existing?.isConnected) return existing;\n\n const region = this.#createRegion(level);\n this.#generated.set(level, region);\n return region;\n }\n\n /**\n * Restores the announceable initial state for the snapshot Turbo is about to\n * take: queued and displayed messages go, generated regions go, and the live\n * page — which keeps running when a visit is aborted — gets its regions back on\n * the next task, after the clone.\n */\n #rewindForCache(): void {\n this.#queues.clear();\n this.#draining.clear();\n this.#timers.clearAll();\n for (const level of LEVELS) {\n if (this.#hasTargetFor(level)) {\n const target = level === \"assertive\" ? this.assertiveTarget : this.politeTarget;\n target.textContent = \"\";\n }\n }\n this.#removeGenerated();\n this.#timers.set(() => this.#reconcileRegions(), 0);\n }\n\n /** Extracts a non-empty string `message` from a CustomEvent detail, else null. */\n #messageFromDetail(detail: unknown): string | null {\n if (detail && typeof detail === \"object\" && \"message\" in detail) {\n const value = (detail as Record<string, unknown>).message;\n if (typeof value === \"string\" && value.length > 0) return value;\n }\n return null;\n }\n\n /** Reads an `assertive === true` flag from a CustomEvent detail (default polite). */\n #assertiveFromDetail(detail: unknown): boolean {\n return (\n !!detail &&\n typeof detail === \"object\" &&\n (detail as Record<string, unknown>).assertive === true\n );\n }\n}\n\n/**\n * Applies the canonical visually-hidden (\"sr-only\") inline style to a generated\n * live region so its text is announced without being seen. Inline so the library\n * stays self-contained when the consumer provides no target/CSS of its own.\n *\n * Pure (no `this`); exported for direct unit testing.\n */\nexport function visuallyHide(node: HTMLElement): void {\n const { style } = node;\n style.position = \"absolute\";\n style.width = \"1px\";\n style.height = \"1px\";\n style.margin = \"-1px\";\n style.padding = \"0\";\n style.border = \"0\";\n style.overflow = \"hidden\";\n style.clip = \"rect(0 0 0 0)\";\n style.clipPath = \"inset(50%)\";\n style.whiteSpace = \"nowrap\";\n}\n"]}
@@ -8,13 +8,13 @@ import { Controller } from '@hotwired/stimulus';
8
8
  * <ol data-stimeo--breadcrumb-target="list">
9
9
  * <li><a href="/">Home</a></li>
10
10
  * <li data-stimeo--breadcrumb-target="ellipsis" hidden>
11
- * <button type="button" aria-expanded="false" aria-controls="bc-collapsed"
11
+ * <button type="button" aria-expanded="false" aria-controls="bc-a bc-b"
12
12
  * aria-label="Show full path"
13
13
  * data-stimeo--breadcrumb-target="trigger"
14
- * data-action="stimeo--breadcrumb#toggle">…</button>
14
+ * data-action="click->stimeo--breadcrumb#toggle">…</button>
15
15
  * </li>
16
- * <li id="bc-collapsed" data-stimeo--breadcrumb-target="collapsible"><a href="/a">Section A</a></li>
17
- * <li data-stimeo--breadcrumb-target="collapsible"><a href="/a/b">Sub B</a></li>
16
+ * <li id="bc-a" data-stimeo--breadcrumb-target="collapsible"><a href="/a">Section A</a></li>
17
+ * <li id="bc-b" data-stimeo--breadcrumb-target="collapsible"><a href="/a/b">Sub B</a></li>
18
18
  * <li><a href="/a/b/c" aria-current="page">Item C</a></li>
19
19
  * </ol>
20
20
  * </nav>
@@ -31,16 +31,59 @@ import { Controller } from '@hotwired/stimulus';
31
31
  * placed between the leading and trailing items that must always stay visible.
32
32
  *
33
33
  * Behavior provided:
34
- * - Detects overflow via {@link LayoutObserver} (element + viewport resize).
34
+ * - Detects overflow via {@link LayoutObserver} (element + viewport resize) and a
35
+ * `MutationObserver` on the list (content edits, Turbo Stream / morph item
36
+ * swaps); the public `update` action re-measures on demand.
35
37
  * - While overflowing and not expanded, hides the `collapsible` items and shows
36
- * the `ellipsis` item; when it fits, shows everything and hides the ellipsis.
38
+ * the `ellipsis` item; when it fits, shows everything, hides the ellipsis and
39
+ * resets the expanded state (so a later collapse starts collapsed).
37
40
  * - The disclosure `trigger` toggles `aria-expanded` and the collapsed items,
38
- * dispatching `stimeo--breadcrumb:toggle`.
41
+ * dispatching `stimeo--breadcrumb:toggle`. `toggle` is a no-op (no state
42
+ * change, no event) while the trail fits, so a hidden trigger can never be
43
+ * left reporting `aria-expanded="true"`.
44
+ *
45
+ * Layout requirements the behavior depends on:
46
+ * - **The list must not wrap** (`white-space: nowrap` / `flex-wrap: nowrap`). A
47
+ * wrapping list grows in height instead of scroll width, so
48
+ * `scrollWidth === clientWidth` always holds and overflow is never detected.
49
+ * - **The list width must follow its container** (no shrink-to-fit / intrinsic
50
+ * width). Overflow is re-measured synchronously inside the resize
51
+ * notification, so a list that widens to its content would never report
52
+ * overflow. There is deliberately no debounce: the pass is one write → one
53
+ * forced read → one write on a single element.
54
+ * - Consumers must not neutralize `[hidden]` (e.g. `display: inline-flex` on the
55
+ * items wins over the UA's `[hidden] { display: none }`); collapsing is
56
+ * expressed exclusively through the `hidden` attribute.
57
+ *
58
+ * Ownership of `hidden`: this controller owns the attribute on an element **for as
59
+ * long as that element is a `collapsible` target and the controller is connected**.
60
+ * Outside that window it does not write it:
61
+ * - lose the marker while connected → the element becomes an always-visible item
62
+ * and the controller clears the `hidden` it owned;
63
+ * - controller `disconnect()` → the collapsed state is left in the DOM on purpose,
64
+ * because that DOM is what Turbo caches and restores.
65
+ *
66
+ * A consumer that also wants to own `hidden` on the same element (for a reason of
67
+ * its own) is not supported: `#measureOverflow` clears it on every measurement to
68
+ * read the expanded width.
69
+ *
70
+ * Focus safety: hiding the element the user is standing on would drop focus to
71
+ * `<body>`. When a collapse would hide the focused item, focus moves to the
72
+ * disclosure `trigger` first; when the ellipsis would be hidden while it holds
73
+ * focus, the hide waits for `blur`.
74
+ *
75
+ * **Fail-safe when the disclosure is incomplete.** Collapsing needs all of
76
+ * `list`, one `collapsible`, `ellipsis`, and `trigger`; miss any and the trail
77
+ * degrades to a plain APG breadcrumb (every item visible, ellipsis hidden,
78
+ * `aria-expanded="false"`, `toggle` a silent no-op). Hiding the middle items
79
+ * with no control that can reveal them puts the path out of reach for good — a
80
+ * too-wide trail is the cheaper failure. Watched at runtime, so a swap that
81
+ * breaks the set releases the items and one that completes it starts collapsing.
39
82
  */
40
83
  declare class BreadcrumbController extends Controller<HTMLElement> {
41
84
  #private;
42
85
  static targets: string[];
43
- static actions: readonly ["toggle"];
86
+ static actions: readonly ["toggle", "update"];
44
87
  static events: readonly ["toggle"];
45
88
  readonly listTarget: HTMLElement;
46
89
  readonly collapsibleTargets: HTMLElement[];
@@ -51,10 +94,54 @@ declare class BreadcrumbController extends Controller<HTMLElement> {
51
94
  readonly hasTriggerTarget: boolean;
52
95
  /** Starts observing for overflow and renders the initial state. */
53
96
  connect(): void;
54
- /** Releases the resize observation (Turbo navigation included). */
97
+ /** Releases the resize/mutation observation (Turbo navigation included). */
55
98
  disconnect(): void;
56
- /** Expands or re-collapses the trail and dispatches `toggle`. */
99
+ listTargetConnected(): void;
100
+ listTargetDisconnected(): void;
101
+ collapsibleTargetConnected(): void;
102
+ /**
103
+ * Re-measures when the disclosure set gains or loses a member. The set is a
104
+ * precondition for collapsing at all, so it needs the same watching the list
105
+ * and items get: without these callbacks a swap that breaks or completes the
106
+ * set would only take effect at the next resize or list mutation, which may
107
+ * never come.
108
+ */
109
+ ellipsisTargetConnected(): void;
110
+ ellipsisTargetDisconnected(): void;
111
+ triggerTargetConnected(): void;
112
+ triggerTargetDisconnected(): void;
113
+ /**
114
+ * Hands `hidden` back when an element stops being a `collapsible` target.
115
+ *
116
+ * The marker is the source of truth for what may be collapsed, so an element
117
+ * that loses it while the controller is live is an always-visible item again —
118
+ * and `#render` only walks the *current* targets, so nothing else would ever
119
+ * clear the `hidden` this controller put there.
120
+ *
121
+ * The `#connected` guard is load-bearing, not defensive. Stimulus fires this
122
+ * callback for **every** target during teardown as well (`Context.disconnect()`
123
+ * stops the target observer after `disconnect()` has run), and there the
124
+ * collapsed DOM must survive untouched so Turbo's cache restores the trail in
125
+ * the state the user left it (see the ownership note in {@link BreadcrumbController}).
126
+ *
127
+ * @param element - the element that just left the `collapsible` target set
128
+ */
129
+ collapsibleTargetDisconnected(element: HTMLElement): void;
130
+ /**
131
+ * Expands or re-collapses the trail and dispatches `toggle`.
132
+ *
133
+ * No-op while the trail fits: there is nothing collapsed to reveal, and the
134
+ * (hidden) trigger would otherwise keep a stale `aria-expanded="true"` that
135
+ * surfaces pre-expanded the next time the trail overflows. No event is
136
+ * dispatched in that case.
137
+ */
57
138
  toggle(): void;
139
+ /**
140
+ * Re-measures overflow and re-renders. Wired to resizes and list mutations;
141
+ * exposed as an action so consumers can re-measure after a change the
142
+ * observers cannot see (e.g. a web font swap that only alters text width).
143
+ */
144
+ update(): void;
58
145
  }
59
146
 
60
147
  export { BreadcrumbController };
@@ -2,6 +2,61 @@ import { Controller } from '@hotwired/stimulus';
2
2
 
3
3
  // src/controllers/breadcrumb_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;
@@ -59,37 +114,152 @@ var LayoutObserver = class {
59
114
  };
60
115
 
61
116
  // src/controllers/breadcrumb_controller.ts
117
+ var OVERFLOW_EPSILON = 1;
62
118
  var BreadcrumbController = class extends Controller {
63
119
  static targets = ["list", "collapsible", "ellipsis", "trigger"];
64
- static actions = ["toggle"];
120
+ static actions = ["toggle", "update"];
65
121
  static events = ["toggle"];
122
+ /** Guards target callbacks that can fire outside the connected window. */
123
+ #connected = false;
66
124
  /** Whether the trail currently overflows its container. */
67
125
  #overflowing = false;
68
126
  /** Whether the user has expanded the collapsed items via the disclosure. */
69
127
  #expanded = false;
70
- #layout = new LayoutObserver(() => this.#update());
128
+ /** The list element currently observed (resize + mutations), if any. */
129
+ #observedList = null;
130
+ #listMutations = null;
131
+ #layout = new LayoutObserver(() => this.update());
132
+ #onListMutation = () => {
133
+ this.update();
134
+ };
135
+ /** Holds the ellipsis hide back while it contains focus; re-renders on blur. */
136
+ #deferredHide = new BlurDeferral(() => {
137
+ this.#render();
138
+ });
71
139
  /** Starts observing for overflow and renders the initial state. */
72
140
  connect() {
73
- if (this.hasListTarget) this.#layout.observe(this.listTarget);
141
+ this.#connected = true;
142
+ this.#expanded = this.#initialExpanded();
74
143
  this.#layout.observeViewport();
75
- this.#update();
144
+ this.#syncListObservation();
145
+ this.update();
76
146
  }
77
- /** Releases the resize observation (Turbo navigation included). */
147
+ /** Releases the resize/mutation observation (Turbo navigation included). */
78
148
  disconnect() {
149
+ this.#connected = false;
150
+ this.#deferredHide.releaseAll();
151
+ this.#stopObservingList();
79
152
  this.#layout.disconnect();
80
153
  }
81
- /** Expands or re-collapses the trail and dispatches `toggle`. */
154
+ listTargetConnected() {
155
+ this.#resync();
156
+ }
157
+ listTargetDisconnected() {
158
+ this.#resync();
159
+ }
160
+ collapsibleTargetConnected() {
161
+ this.#resync();
162
+ }
163
+ /**
164
+ * Re-measures when the disclosure set gains or loses a member. The set is a
165
+ * precondition for collapsing at all, so it needs the same watching the list
166
+ * and items get: without these callbacks a swap that breaks or completes the
167
+ * set would only take effect at the next resize or list mutation, which may
168
+ * never come.
169
+ */
170
+ ellipsisTargetConnected() {
171
+ this.#resync();
172
+ }
173
+ ellipsisTargetDisconnected() {
174
+ this.#resync();
175
+ }
176
+ triggerTargetConnected() {
177
+ this.#resync();
178
+ }
179
+ triggerTargetDisconnected() {
180
+ this.#resync();
181
+ }
182
+ /**
183
+ * Hands `hidden` back when an element stops being a `collapsible` target.
184
+ *
185
+ * The marker is the source of truth for what may be collapsed, so an element
186
+ * that loses it while the controller is live is an always-visible item again —
187
+ * and `#render` only walks the *current* targets, so nothing else would ever
188
+ * clear the `hidden` this controller put there.
189
+ *
190
+ * The `#connected` guard is load-bearing, not defensive. Stimulus fires this
191
+ * callback for **every** target during teardown as well (`Context.disconnect()`
192
+ * stops the target observer after `disconnect()` has run), and there the
193
+ * collapsed DOM must survive untouched so Turbo's cache restores the trail in
194
+ * the state the user left it (see the ownership note in {@link BreadcrumbController}).
195
+ *
196
+ * @param element - the element that just left the `collapsible` target set
197
+ */
198
+ collapsibleTargetDisconnected(element) {
199
+ if (this.#connected) element.hidden = false;
200
+ this.#resync();
201
+ }
202
+ /**
203
+ * Expands or re-collapses the trail and dispatches `toggle`.
204
+ *
205
+ * No-op while the trail fits: there is nothing collapsed to reveal, and the
206
+ * (hidden) trigger would otherwise keep a stale `aria-expanded="true"` that
207
+ * surfaces pre-expanded the next time the trail overflows. No event is
208
+ * dispatched in that case.
209
+ */
82
210
  toggle() {
211
+ if (!this.#connected || !this.#overflowing) return;
83
212
  this.#expanded = !this.#expanded;
84
213
  this.#render();
85
214
  this.dispatch("toggle", { detail: { expanded: this.#expanded } });
86
215
  }
87
- /** Re-measures overflow and re-renders (e.g. on resize). */
88
- #update() {
216
+ /**
217
+ * Re-measures overflow and re-renders. Wired to resizes and list mutations;
218
+ * exposed as an action so consumers can re-measure after a change the
219
+ * observers cannot see (e.g. a web font swap that only alters text width).
220
+ */
221
+ update() {
222
+ if (!this.#connected) return;
89
223
  this.#overflowing = this.#measureOverflow();
90
224
  if (!this.#overflowing) this.#expanded = false;
91
225
  this.#render();
92
226
  }
227
+ /** Re-attaches the list observation (targets may have been swapped) and re-measures. */
228
+ #resync() {
229
+ if (!this.#connected) return;
230
+ this.#syncListObservation();
231
+ this.update();
232
+ }
233
+ /** Reads the expanded state back from its DOM home (the trigger's `aria-expanded`). */
234
+ #initialExpanded() {
235
+ return this.hasTriggerTarget && this.triggerTarget.getAttribute("aria-expanded") === "true";
236
+ }
237
+ /**
238
+ * Points the resize + mutation observation at the current `list` target.
239
+ *
240
+ * The list is re-resolved rather than captured at connect so a target swapped
241
+ * at runtime (Turbo Stream replacement of the `<ol>`) is observed too. Only
242
+ * `childList` / `subtree` / `characterData` are watched — deliberately **not**
243
+ * `attributes`, which the controller's own `hidden` writes would re-trigger.
244
+ */
245
+ #syncListObservation() {
246
+ const next = this.hasListTarget ? this.listTarget : null;
247
+ if (next === this.#observedList) return;
248
+ this.#stopObservingList();
249
+ if (!next) return;
250
+ this.#observedList = next;
251
+ this.#layout.observe(next);
252
+ if (typeof MutationObserver !== "undefined") {
253
+ this.#listMutations = new MutationObserver(this.#onListMutation);
254
+ this.#listMutations.observe(next, { childList: true, subtree: true, characterData: true });
255
+ }
256
+ }
257
+ #stopObservingList() {
258
+ if (this.#observedList) this.#layout.unobserve(this.#observedList);
259
+ this.#observedList = null;
260
+ this.#listMutations?.disconnect();
261
+ this.#listMutations = null;
262
+ }
93
263
  /**
94
264
  * Measures overflow against the **fully expanded** layout so hiding items does
95
265
  * not make the condition oscillate. Reveals every item, then compares the list's
@@ -100,21 +270,63 @@ var BreadcrumbController = class extends Controller {
100
270
  * check is independent of any padding/border on the host — comparing against the
101
271
  * host's `clientWidth` would over-report the available space by its padding and
102
272
  * miss real overflow in a padded container.
273
+ *
274
+ * With no `collapsible` items there is nothing to collapse, so the trail is
275
+ * never reported as overflowing (which also keeps the disclosure out of the
276
+ * tab order — a button controlling nothing).
277
+ *
278
+ * The full disclosure set is a precondition: collapsing without an `ellipsis`
279
+ * *and* a `trigger` would hide items behind a control that does not exist, so
280
+ * an incomplete set reports "not overflowing" and `#render` degrades the trail
281
+ * to a plain breadcrumb. Losing layout is recoverable; losing the path is not.
103
282
  */
104
283
  #measureOverflow() {
105
- if (!this.hasListTarget) return false;
284
+ if (!this.hasListTarget || this.collapsibleTargets.length === 0) return false;
285
+ if (!this.hasEllipsisTarget || !this.hasTriggerTarget) return false;
106
286
  for (const item of this.collapsibleTargets) item.hidden = false;
107
- if (this.hasEllipsisTarget) this.ellipsisTarget.hidden = true;
108
- return this.listTarget.scrollWidth > this.listTarget.clientWidth;
287
+ this.ellipsisTarget.hidden = true;
288
+ return this.listTarget.scrollWidth > this.listTarget.clientWidth + OVERFLOW_EPSILON;
109
289
  }
110
290
  /** Applies the collapsed/expanded state to the items, ellipsis, and trigger. */
111
291
  #render() {
112
292
  const collapsed = this.#overflowing && !this.#expanded;
293
+ const showEllipsis = this.#overflowing && this.collapsibleTargets.length > 0;
294
+ const rescueFocus = collapsed && this.hasTriggerTarget && this.collapsibleTargets.some((i) => this.#holdsFocus(i));
113
295
  for (const item of this.collapsibleTargets) item.hidden = collapsed;
114
- if (this.hasEllipsisTarget) this.ellipsisTarget.hidden = !this.#overflowing;
296
+ if (this.hasEllipsisTarget) this.#applyEllipsisVisibility(showEllipsis);
115
297
  if (this.hasTriggerTarget) {
116
- this.triggerTarget.setAttribute("aria-expanded", this.#expanded ? "true" : "false");
298
+ const expanded = this.#overflowing && this.#expanded;
299
+ this.triggerTarget.setAttribute("aria-expanded", expanded ? "true" : "false");
300
+ }
301
+ if (rescueFocus) this.triggerTarget.focus();
302
+ }
303
+ /**
304
+ * Shows or hides the ellipsis item, deferring a hide that would blur the user.
305
+ *
306
+ * Hiding the element that currently holds focus drops focus to `<body>`, so the
307
+ * hide waits for that element's `blur` and is re-applied then (the shared
308
+ * `BlurDeferral` registry).
309
+ */
310
+ #applyEllipsisVisibility(show) {
311
+ const ellipsis = this.ellipsisTarget;
312
+ if (show) {
313
+ this.#deferredHide.releaseAll();
314
+ ellipsis.hidden = false;
315
+ return;
316
+ }
317
+ const active = document.activeElement;
318
+ if (active instanceof HTMLElement && ellipsis.contains(active)) {
319
+ ellipsis.hidden = false;
320
+ this.#deferredHide.deferOnly(active);
321
+ return;
117
322
  }
323
+ this.#deferredHide.releaseAll();
324
+ ellipsis.hidden = true;
325
+ }
326
+ /** Whether `element` contains (or is) the currently focused element. */
327
+ #holdsFocus(element) {
328
+ const active = document.activeElement;
329
+ return active instanceof HTMLElement && element.contains(active);
118
330
  }
119
331
  };
120
332