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/relative_time_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,UA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AA;AAAA,IACT;AAEA,IAAA,MAAM,KAAA,GAAQ,MAAM,IAAA,CAAK,CAAC,MAAM,UAAA,GAAa,CAAA,CAAE,KAAK,CAAA,IAAK,UAAA;AACzD,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,OAAA,GAAU,MAAM,EAAE,CAAA;AAC3C,IAAA,IAAA,CAAK,QAAQ,WAAA,GAAc,IAAA,CAAK,WAAW,MAAA,CAAO,KAAA,EAAO,MAAM,IAAI,CAAA;AACnE,IAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,YAAA,EAAc,UAAU,CAAA;AAIlD,IAAA,MAAM,SAAA,GAAY,MAAM,IAAA,KAAS,QAAA,IAAY,MAAM,IAAA,KAAS,QAAA,GAAW,MAAS,KAAA,CAAM,EAAA;AACtF,IAAA,OAAO,IAAA,CAAK,IAAI,IAAA,CAAK,iBAAA,EAAmB,KAAK,GAAA,CAAI,SAAA,EAAW,KAAU,CAAC,CAAA;AAAA,EACzE;AAAA;AAAA,EAGA,IAAI,UAAA,GAAsC;AACxC,IAAA,OAAO,IAAI,KAAK,kBAAA,CAAmB,IAAA,CAAK,SAAS,EAAE,OAAA,EAAS,QAAQ,CAAA;AAAA,EACtE;AAAA;AAAA,EAGA,IAAI,OAAA,GAA8B;AAChC,IAAA,OAAO,KAAK,WAAA,IAAe,IAAA,CAAK,QAAQ,IAAA,IAAQ,QAAA,CAAS,gBAAgB,IAAA,IAAQ,MAAA;AAAA,EACnF;AACF","file":"relative_time_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/** A time scale: the upper bound (seconds) it covers and its `Intl` unit/divisor. */\ninterface TimeScale {\n limit: number;\n unit: Intl.RelativeTimeFormatUnit;\n ms: number;\n}\n\n/** Coarsest scale, used as the fallback for anything a year or older. */\nconst YEAR_SCALE: TimeScale = { limit: Number.POSITIVE_INFINITY, unit: \"year\", ms: 31_557_600_000 };\n\n/** Boundaries (in seconds) and the `Intl` unit/divisor used at each scale. */\nconst UNITS: readonly TimeScale[] = [\n { limit: 60, unit: \"second\", ms: 1000 },\n { limit: 3600, unit: \"minute\", ms: 60_000 },\n { limit: 86_400, unit: \"hour\", ms: 3_600_000 },\n { limit: 604_800, unit: \"day\", ms: 86_400_000 },\n { limit: 2_629_800, unit: \"week\", ms: 604_800_000 },\n { limit: 31_557_600, unit: \"month\", ms: 2_629_800_000 },\n YEAR_SCALE,\n];\n\n/**\n * Headless relative-time behavior: renders an absolute timestamp as \"3 minutes\n * ago\" / \"in 2 days\" and keeps it fresh. No dedicated APG pattern; it follows\n * the HTML `<time>` semantics.\n *\n * Markup contract (identifier: `stimeo--relative-time`):\n * <time data-controller=\"stimeo--relative-time\"\n * datetime=\"2026-05-30T12:00:00+09:00\" title=\"2026-05-30 12:00\"\n * data-stimeo--relative-time-locale-value=\"ja\">2026-05-30 12:00</time>\n *\n * Computes the difference from `datetime` to now and formats it with\n * `Intl.RelativeTimeFormat` (a browser standard — no added dependency). The\n * polling interval widens as the timestamp ages (seconds → minutes → hours →\n * days). Past a `threshold`, it falls back to the authored absolute text.\n *\n * @remarks\n * Behavior only. The machine-readable `datetime` attribute is left untouched\n * while only the visible text updates, and the element is intentionally **not**\n * a live region (silent updates, no announcement interruptions). The polling\n * timer is owned by {@link SafeTimeout} and torn down on `disconnect()` (Turbo\n * navigation included).\n */\nexport class RelativeTimeController extends Controller<HTMLElement> {\n static override values = {\n locale: { type: String, default: \"\" },\n threshold: { type: Number, default: 0 },\n tickInterval: { type: Number, default: 60_000 },\n };\n\n declare localeValue: string;\n declare thresholdValue: number;\n declare tickIntervalValue: number;\n\n readonly #timers = new SafeTimeout();\n\n /** Epoch ms parsed from `datetime`; `NaN` when absent or invalid. */\n #targetMs = Number.NaN;\n /** The authored absolute text, restored when the threshold fallback kicks in. */\n #absoluteText = \"\";\n\n override connect(): void {\n // Don't adopt already-rendered relative text as the absolute fallback: after a\n // Turbo morph that preserved the live \"3 minutes ago\" text, a fresh re-connect\n // would otherwise capture that relative string as `#absoluteText`. Only read the\n // authored textContent before the element has been rendered to a relative form.\n if (this.element.getAttribute(\"data-state\") !== \"relative\") {\n this.#absoluteText = (this.element.textContent ?? \"\").trim();\n }\n this.#targetMs = Date.parse(this.element.getAttribute(\"datetime\") ?? \"\");\n if (Number.isNaN(this.#targetMs)) return;\n this.#schedule();\n }\n\n override disconnect(): void {\n this.#timers.clearAll();\n }\n\n /** Renders the current representation and reschedules unless it is now absolute. */\n #schedule(): void {\n const nextDelay = this.#applyAndComputeDelay();\n if (nextDelay !== null) {\n this.#timers.set(() => this.#schedule(), nextDelay);\n }\n }\n\n /**\n * Updates the visible text and returns the next poll delay (ms), or `null`\n * once the absolute fallback is shown (which never changes, so stop polling).\n */\n #applyAndComputeDelay(): number | null {\n const deltaMs = this.#targetMs - Date.now();\n const absSeconds = Math.abs(deltaMs) / 1000;\n\n // Only switch to the absolute fallback when we actually hold authored absolute\n // text; otherwise (e.g. it could not be recovered after a morph) keep rendering\n // the relative form rather than blanking the element.\n if (this.thresholdValue > 0 && absSeconds >= this.thresholdValue && this.#absoluteText) {\n this.element.textContent = this.#absoluteText;\n this.element.setAttribute(\"data-state\", \"absolute\");\n return null;\n }\n\n const scale = UNITS.find((u) => absSeconds < u.limit) ?? YEAR_SCALE;\n const value = Math.round(deltaMs / scale.ms);\n this.element.textContent = this.#formatter.format(value, scale.unit);\n this.element.setAttribute(\"data-state\", \"relative\");\n\n // Poll no finer than the configured minimum; widen for coarser units so an\n // hours-old stamp is not re-rendered every minute.\n const unitFloor = scale.unit === \"second\" || scale.unit === \"minute\" ? 60_000 : scale.ms;\n return Math.max(this.tickIntervalValue, Math.min(unitFloor, 86_400_000));\n }\n\n /** A `RelativeTimeFormat` for the resolved locale (`numeric: \"auto\"`). */\n get #formatter(): Intl.RelativeTimeFormat {\n return new Intl.RelativeTimeFormat(this.#locale, { numeric: \"auto\" });\n }\n\n /** Locale precedence: the value, then the element's `lang`, then the document's. */\n get #locale(): string | undefined {\n return this.localeValue || this.element.lang || document.documentElement.lang || undefined;\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/before_cache_reset.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/safe_timeout.ts","../../src/controllers/relative_time_controller.ts"],"names":[],"mappings":";;;;;AA2CO,IAAM,gBAAA,GAAN,MAAM,iBAAA,CAAiB;AAAA;AAAA,EAE5B,OAAgB,YAAA,mBAAe,IAAI,GAAA,EAAsB;AAAA;AAAA,EAGzD,OAAgB,iBAAiB,MAAY;AAC3C,IAAA,KAAA,MAAW,UAAA,IAAc,iBAAA,CAAiB,YAAA,EAAc,UAAA,CAAW,OAA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AAe,IAAA,CAAK,OAAA,CAAQ,QAAQ,QAAQ,CAAA,EAAG,YAAA,CAAa,MAAM,CAAA,IAAK,MAAA;AAAA,EACrF;AACF","file":"relative_time_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/** A time scale: the upper bound (seconds) it covers and its `Intl` unit/divisor. */\ninterface TimeScale {\n limit: number;\n unit: Intl.RelativeTimeFormatUnit;\n ms: number;\n}\n\n/** Coarsest scale, used as the fallback for anything a year or older. */\nconst YEAR_SCALE: TimeScale = { limit: Number.POSITIVE_INFINITY, unit: \"year\", ms: 31_557_600_000 };\n\n/** Boundaries (in seconds) and the `Intl` unit/divisor used at each scale. */\nconst UNITS: readonly TimeScale[] = [\n { limit: 60, unit: \"second\", ms: 1000 },\n { limit: 3600, unit: \"minute\", ms: 60_000 },\n { limit: 86_400, unit: \"hour\", ms: 3_600_000 },\n { limit: 604_800, unit: \"day\", ms: 86_400_000 },\n { limit: 2_629_800, unit: \"week\", ms: 604_800_000 },\n { limit: 31_557_600, unit: \"month\", ms: 2_629_800_000 },\n YEAR_SCALE,\n];\n\n/**\n * Headless relative-time behavior: renders an absolute timestamp as \"3 minutes\n * ago\" / \"in 2 days\" and keeps it fresh. No dedicated APG pattern; it follows\n * the HTML `<time>` semantics.\n *\n * Markup contract (identifier: `stimeo--relative-time`):\n * <time data-controller=\"stimeo--relative-time\"\n * datetime=\"2026-05-30T12:00:00+09:00\" title=\"2026-05-30 12:00\"\n * data-stimeo--relative-time-locale-value=\"ja\">2026-05-30 12:00</time>\n *\n * Computes the difference from `datetime` to now and formats it with\n * `Intl.RelativeTimeFormat` (a browser standard — no added dependency). The\n * polling interval widens as the timestamp ages (seconds → minutes → hours →\n * days). Past a `threshold`, it falls back to the authored absolute text.\n *\n * @remarks\n * Behavior only. The machine-readable `datetime` attribute is left untouched\n * while only the visible text updates, and the element is intentionally **not**\n * a live region (silent updates, no announcement interruptions). The polling\n * timer is owned by {@link SafeTimeout} and torn down on `disconnect()` (Turbo\n * navigation included).\n *\n * Render inputs are followed at runtime: a morph that swaps `locale`, `threshold`,\n * or `tickInterval` on the live element repaints through one coalesced pass\n * ({@link MicrotaskCoalescer}) rather than leaving the reading frozen. The authored\n * absolute text goes back on the element via {@link BeforeCacheReset} before Turbo\n * caches the page — a snapshot taken mid-render would carry the relative form\n * alone, and that is a form `connect()` must not adopt as the fallback.\n */\nexport class RelativeTimeController extends Controller<HTMLElement> {\n static override values = {\n locale: { type: String, default: \"\" },\n threshold: { type: Number, default: 0 },\n tickInterval: { type: Number, default: 60_000 },\n };\n\n declare localeValue: string;\n declare thresholdValue: number;\n declare tickIntervalValue: number;\n\n readonly #timers = new SafeTimeout();\n /** Collapses a morph that swaps several render inputs at once into one repaint. */\n readonly #resync = new MicrotaskCoalescer(() => this.#resyncToValues());\n readonly #beforeCache = new BeforeCacheReset(() => this.#rewindForCache());\n\n /** Epoch ms parsed from `datetime`; `NaN` when absent or invalid. */\n #targetMs = Number.NaN;\n /** The authored absolute text, restored when the threshold fallback kicks in. */\n #absoluteText = \"\";\n\n override connect(): void {\n this.#resync.activate();\n this.#beforeCache.activate();\n // Don't adopt already-rendered relative text as the absolute fallback: on a\n // re-connect against a tree that still holds the live \"3 minutes ago\" text, that\n // relative string would otherwise become `#absoluteText`. Only read the authored\n // textContent before the element has been rendered to a relative form.\n if (this.element.getAttribute(\"data-state\") !== \"relative\") {\n this.#absoluteText = (this.element.textContent ?? \"\").trim();\n }\n this.#targetMs = Date.parse(this.element.getAttribute(\"datetime\") ?? \"\");\n if (Number.isNaN(this.#targetMs)) return;\n this.#schedule();\n }\n\n override disconnect(): void {\n this.#resync.cancel();\n this.#beforeCache.deactivate();\n this.#timers.clearAll();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `locale` at runtime. */\n localeValueChanged(): void {\n this.#resync.schedule();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `threshold` at runtime. */\n thresholdValueChanged(): void {\n this.#resync.schedule();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `tickInterval` at runtime. */\n tickIntervalValueChanged(): void {\n this.#resync.schedule();\n }\n\n /**\n * Renders against the current Values and re-arms the poll from now.\n *\n * Render only: it emits no event, and clearing first keeps the single self-arming\n * timer single — scheduling on top of a pending one would double the poll rate for\n * the rest of the session. A stamp whose `datetime` never parsed has nothing to\n * render, and one that already reached its terminal fallback simply renders it\n * again and stops.\n */\n #resyncToValues(): void {\n if (Number.isNaN(this.#targetMs)) return;\n this.#timers.clearAll();\n this.#schedule();\n }\n\n /**\n * Restores the authored absolute text and the pre-render state for the snapshot\n * Turbo is about to take, leaving the live page's poll timer alone.\n *\n * With no authored text held there is nothing to restore, and `data-state` has to\n * stay as it is: that marker is what tells the next `connect()` the visible text is\n * a rendered relative form rather than an absolute fallback to hold on to.\n */\n #rewindForCache(): void {\n if (!this.#absoluteText) return;\n this.element.textContent = this.#absoluteText;\n this.element.removeAttribute(\"data-state\");\n }\n\n /** Renders the current representation and reschedules unless polling can stop. */\n #schedule(): void {\n const nextDelay = this.#applyAndComputeDelay();\n if (nextDelay !== null) {\n this.#timers.set(() => this.#schedule(), nextDelay);\n }\n }\n\n /**\n * Updates the visible text and returns the next poll delay (ms), or `null` when\n * polling can stop: a *past* timestamp that fell back to the absolute text can\n * never leave it again, and a locale the runtime rejects has nothing to render\n * until that value is corrected.\n */\n #applyAndComputeDelay(): number | null {\n const deltaMs = this.#targetMs - Date.now();\n const absSeconds = Math.abs(deltaMs) / 1000;\n\n const scale = UNITS.find((u) => absSeconds < u.limit) ?? YEAR_SCALE;\n // Poll no finer than the configured minimum; widen for coarser units so an\n // hours-old stamp is not re-rendered every minute.\n const unitFloor = scale.unit === \"second\" || scale.unit === \"minute\" ? 60_000 : scale.ms;\n const nextDelay = Math.max(this.tickIntervalValue, Math.min(unitFloor, 86_400_000));\n\n // Only switch to the absolute fallback when we actually hold authored absolute\n // text; otherwise (e.g. it could not be recovered after a morph) keep rendering\n // the relative form rather than blanking the element.\n if (this.thresholdValue > 0 && absSeconds >= this.thresholdValue && this.#absoluteText) {\n this.element.textContent = this.#absoluteText;\n this.element.setAttribute(\"data-state\", \"absolute\");\n // A past stamp only ages further, so its fallback is final and polling stops. A\n // future one moves back under the threshold, so keep polling and land 1ms past\n // the crossing: the poll cadence is far coarser than the instant the fallback\n // stops being the correct representation, and the floor does not apply to a hop\n // that exists to leave the fallback rather than to refresh a reading.\n if (deltaMs <= 0) return null;\n return Math.min(nextDelay, deltaMs - this.thresholdValue * 1000 + 1);\n }\n\n const formatter = this.#formatter;\n // Nothing to render in a locale the runtime rejects: leaving the element as\n // authored beats blanking it or guessing at another language.\n if (formatter === null) return null;\n const value = Math.round(deltaMs / scale.ms);\n this.element.textContent = formatter.format(value, scale.unit);\n this.element.setAttribute(\"data-state\", \"relative\");\n return nextDelay;\n }\n\n /**\n * A `RelativeTimeFormat` for the resolved locale (`numeric: \"auto\"`), or `null`\n * when the runtime rejects that locale.\n */\n get #formatter(): Intl.RelativeTimeFormat | null {\n try {\n return new Intl.RelativeTimeFormat(this.#locale, { numeric: \"auto\" });\n } catch {\n // A malformed locale must not break the page: the authored absolute text stays\n // as the graceful fallback, and a corrected value renders on the next pass.\n return null;\n }\n }\n\n /** Locale precedence: the value, then the nearest `lang` up the ancestor chain. */\n get #locale(): string | undefined {\n return this.localeValue || this.element.closest(\"[lang]\")?.getAttribute(\"lang\") || undefined;\n }\n}\n"]}
@@ -23,7 +23,9 @@ import { Controller } from '@hotwired/stimulus';
23
23
  * even when pointers quickly stray outside the separator area.
24
24
  * - Auto-clamped flex-percentage updates with bounds safety.
25
25
  * - Smooth step keyboard adjustments for Arrow keys based on vertical/horizontal orientation.
26
- * - Root-level CSS custom property `--stimeo--resizable-fraction` (0..1) to drive presentation styles.
26
+ * - Root-level CSS custom property `--stimeo--resizable-fraction` (0..1) driving
27
+ * presentation styles.
28
+ * - `F6` cycles focus through the panes, which the pattern lists as optional.
27
29
  *
28
30
  * @remarks
29
31
  * Behavior only. The controller adjusts the CSS custom property on the root element,
@@ -1,5 +1,40 @@
1
1
  import { Controller } from '@hotwired/stimulus';
2
2
 
3
+ // src/controllers/resizable_controller.ts
4
+
5
+ // src/utils/arrow_step.ts
6
+ function isReservedArrowChord(event, allow = []) {
7
+ if (!event.key.startsWith("Arrow")) return false;
8
+ return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
9
+ }
10
+
11
+ // src/utils/tabindex_loan.ts
12
+ var TabindexLoan = class {
13
+ #value;
14
+ #lent = /* @__PURE__ */ new Set();
15
+ /**
16
+ * @param value - the `tabindex` to lend. `"-1"` (the default) is
17
+ * programmatically focusable but not a Tab stop; `"0"` is a real Tab stop,
18
+ * which a scroll region with no focusable content of its own needs.
19
+ */
20
+ constructor(value = "-1") {
21
+ this.#value = value;
22
+ }
23
+ /** Lends `element` the value; no-ops when it already carries a `tabindex`. */
24
+ lend(element) {
25
+ if (element.hasAttribute("tabindex")) return;
26
+ element.setAttribute("tabindex", this.#value);
27
+ this.#lent.add(element);
28
+ }
29
+ /** Takes back every loan whose value is still the one that was lent. */
30
+ returnAll() {
31
+ for (const element of this.#lent) {
32
+ if (element.getAttribute("tabindex") === this.#value) element.removeAttribute("tabindex");
33
+ }
34
+ this.#lent.clear();
35
+ }
36
+ };
37
+
3
38
  // src/controllers/resizable_controller.ts
4
39
  var ResizableController = class extends Controller {
5
40
  static targets = ["primary", "secondary", "separator"];
@@ -11,18 +46,46 @@ var ResizableController = class extends Controller {
11
46
  };
12
47
  static actions = ["onKeydown", "onPointerDown", "toggle"];
13
48
  static events = ["change"];
14
- /** Track previously held value before collapse toggles. */
49
+ /** The value held before the current collapse, restored when toggling back. */
15
50
  #valueBeforeCollapse = 50;
16
51
  /** Aborts in-progress pointer-drag listeners when the drag ends or on teardown. */
17
52
  #dragAbort = null;
53
+ /** `tabindex` lent to a pane so `F6` can put focus on it; panes carry none. */
54
+ #paneTabindex = new TabindexLoan();
55
+ /** Releases the pane cycle listener bound in {@link connect}. */
56
+ #cycleAbort = null;
18
57
  connect() {
19
58
  this.#clampAndSync();
59
+ this.#cycleAbort = new AbortController();
60
+ this.element.addEventListener("keydown", this.#onCycleKeydown, {
61
+ signal: this.#cycleAbort.signal
62
+ });
20
63
  }
21
64
  /** Cancels any active pointer drag so listeners never leak past disconnect. */
22
65
  disconnect() {
23
66
  this.#dragAbort?.abort();
24
67
  this.#dragAbort = null;
68
+ this.#cycleAbort?.abort();
69
+ this.#cycleAbort = null;
70
+ this.#paneTabindex.returnAll();
25
71
  }
72
+ /** Moves focus to the next pane on `F6`, wrapping; entering at the first one. */
73
+ #onCycleKeydown = (event) => {
74
+ if (event.key !== "F6") return;
75
+ if (event.defaultPrevented) return;
76
+ if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
77
+ const panes = [];
78
+ if (this.hasPrimaryTarget) panes.push(this.primaryTarget);
79
+ if (this.hasSecondaryTarget) panes.push(this.secondaryTarget);
80
+ if (panes.length === 0) return;
81
+ const target = event.target;
82
+ const current = panes.findIndex((pane) => target instanceof Node && pane.contains(target));
83
+ const next = panes[(current + 1) % panes.length];
84
+ if (!next) return;
85
+ event.preventDefault();
86
+ this.#paneTabindex.lend(next);
87
+ next.focus();
88
+ };
26
89
  /**
27
90
  * Stimulus lifecycle callback when the valueValue changes.
28
91
  * Keeps CSS fractions and ARIA status completely aligned.
@@ -47,6 +110,7 @@ var ResizableController = class extends Controller {
47
110
  }
48
111
  /** Keydown adjustments for ArrowUp/Down/Left/Right and Home/End. */
49
112
  onKeydown(event) {
113
+ if (isReservedArrowChord(event)) return;
50
114
  if (!this.hasSeparatorTarget) return;
51
115
  const orientation = this.separatorTarget.getAttribute("aria-orientation") || "vertical";
52
116
  const isVertical = orientation === "vertical";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/controllers/resizable_controller.ts"],"names":[],"mappings":";;;AA+BO,IAAM,mBAAA,GAAN,cAAkC,UAAA,CAAwB;AAAA,EAC/D,OAAgB,OAAA,GAAU,CAAC,SAAA,EAAW,aAAa,WAAW,CAAA;AAAA,EAC9D,OAAgB,MAAA,GAAS;AAAA,IACvB,GAAA,EAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,CAAA,EAAE;AAAA,IAChC,GAAA,EAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,GAAA,EAAI;AAAA,IAClC,IAAA,EAAM,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,CAAA,EAAE;AAAA,IACjC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,EAAA;AAAG,GACrC;AAAA,EACA,OAAO,OAAA,GAAU,CAAC,WAAA,EAAa,iBAAiB,QAAQ,CAAA;AAAA,EACxD,OAAO,MAAA,GAAS,CAAC,QAAQ,CAAA;AAAA;AAAA,EAezB,oBAAA,GAAuB,EAAA;AAAA;AAAA,EAGvB,UAAA,GAAqC,IAAA;AAAA,EAE5B,OAAA,GAAgB;AACvB,IAAA,IAAA,CAAK,aAAA,EAAc;AAAA,EACrB;AAAA;AAAA,EAGS,UAAA,GAAmB;AAC1B,IAAA,IAAA,CAAK,YAAY,KAAA,EAAM;AACvB,IAAA,IA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,CAAO,QAAQ,CAAC,CAAA;AAE/E,IAAA,IAAI,KAAK,kBAAA,EAAoB;AAC3B,MAAA,IAAA,CAAK,eAAA,CAAgB,YAAA,CAAa,eAAA,EAAiB,MAAA,CAAO,OAAO,CAAC,CAAA;AAClE,MAAA,IAAA,CAAK,gBAAgB,YAAA,CAAa,eAAA,EAAiB,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAC,CAAA;AACxE,MAAA,IAAA,CAAK,gBAAgB,YAAA,CAAa,eAAA,EAAiB,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAC,CAAA;AAAA,IAC1E;AAAA,EACF;AAAA,EAEA,eAAA,GAAwB;AACtB,IAAA,MAAM,QAAA,GAAW,KAAK,UAAA,GAAa,GAAA;AACnC,IAAA,IAAA,CAAK,QAAA,CAAS,QAAA,EAAU,EAAE,MAAA,EAAQ,EAAE,OAAO,IAAA,CAAK,UAAA,EAAY,QAAA,EAAS,EAAG,CAAA;AAAA,EAC1E;AACF","file":"resizable_controller.js","sourcesContent":["import { Controller } from \"@hotwired/stimulus\";\n\n/**\n * Headless, highly accessible Window Splitter / Resizable panes logic.\n *\n * Markup contract (identifier: `stimeo--resizable`):\n * <div data-controller=\"stimeo--resizable\"\n * data-stimeo--resizable-min-value=\"20\"\n * data-stimeo--resizable-max-value=\"80\"\n * data-stimeo--resizable-value-value=\"50\">\n * <div data-stimeo--resizable-target=\"primary\" id=\"pane-1\">Pane A</div>\n * <div role=\"separator\" tabindex=\"0\" aria-orientation=\"vertical\"\n * aria-controls=\"pane-1\" aria-valuemin=\"20\" aria-valuemax=\"80\"\n * aria-valuenow=\"50\" aria-label=\"Resize splitter\"\n * data-stimeo--resizable-target=\"separator\"\n * data-action=\"pointerdown->stimeo--resizable#onPointerDown\n * keydown->stimeo--resizable#onKeydown\"></div>\n * <div data-stimeo--resizable-target=\"secondary\">Pane B</div>\n * </div>\n *\n * Implements the WAI-ARIA APG **Window Splitter** pattern:\n * - Robust dragging track using W3C `setPointerCapture` to ensure uninterrupted dragging\n * even when pointers quickly stray outside the separator area.\n * - Auto-clamped flex-percentage updates with bounds safety.\n * - Smooth step keyboard adjustments for Arrow keys based on vertical/horizontal orientation.\n * - Root-level CSS custom property `--stimeo--resizable-fraction` (0..1) to drive presentation styles.\n *\n * @remarks\n * Behavior only. The controller adjusts the CSS custom property on the root element,\n * updates ARIA values on the separator, and emits `stimeo--resizable:change` events.\n */\nexport class ResizableController extends Controller<HTMLElement> {\n static override targets = [\"primary\", \"secondary\", \"separator\"];\n static override values = {\n min: { type: Number, default: 0 },\n max: { type: Number, default: 100 },\n step: { type: Number, default: 1 },\n value: { type: Number, default: 50 },\n };\n static actions = [\"onKeydown\", \"onPointerDown\", \"toggle\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly primaryTarget: HTMLElement;\n declare readonly secondaryTarget: HTMLElement;\n declare readonly separatorTarget: HTMLElement;\n declare readonly hasPrimaryTarget: boolean;\n declare readonly hasSecondaryTarget: boolean;\n declare readonly hasSeparatorTarget: boolean;\n\n declare minValue: number;\n declare maxValue: number;\n declare stepValue: number;\n declare valueValue: number;\n\n /** Track previously held value before collapse toggles. */\n #valueBeforeCollapse = 50;\n\n /** Aborts in-progress pointer-drag listeners when the drag ends or on teardown. */\n #dragAbort: AbortController | null = null;\n\n override connect(): void {\n this.#clampAndSync();\n }\n\n /** Cancels any active pointer drag so listeners never leak past disconnect. */\n override disconnect(): void {\n this.#dragAbort?.abort();\n this.#dragAbort = null;\n }\n\n /**\n * Stimulus lifecycle callback when the valueValue changes.\n * Keeps CSS fractions and ARIA status completely aligned.\n */\n valueValueChanged(): void {\n this.#clampAndSync();\n }\n\n /** Starts active pointer drag tracking and locks capture. */\n onPointerDown(event: PointerEvent): void {\n if (!this.hasSeparatorTarget || event.button !== 0) return;\n\n event.preventDefault();\n\n const separator = this.separatorTarget;\n separator.setPointerCapture(event.pointerId);\n // preventDefault() above suppresses the implicit focus, so move focus\n // explicitly — otherwise keyboard (arrow) adjustments never reach the\n // separator after a pointer interaction (WCAG 2.1.1).\n separator.focus();\n\n this.element.setAttribute(\"data-dragging\", \"true\");\n\n this.#dragAbort?.abort();\n const abort = new AbortController();\n this.#dragAbort = abort;\n separator.addEventListener(\"pointermove\", this.#onPointerMove, { signal: abort.signal });\n separator.addEventListener(\"pointerup\", this.#onPointerUp, { signal: abort.signal });\n separator.addEventListener(\"pointercancel\", this.#onPointerUp, { signal: abort.signal });\n }\n\n /** Keydown adjustments for ArrowUp/Down/Left/Right and Home/End. */\n onKeydown(event: KeyboardEvent): void {\n if (!this.hasSeparatorTarget) return;\n\n const orientation = this.separatorTarget.getAttribute(\"aria-orientation\") || \"vertical\";\n const isVertical = orientation === \"vertical\";\n\n let handled = true;\n let nextValue = this.valueValue;\n\n switch (event.key) {\n case \"ArrowLeft\":\n if (isVertical) {\n nextValue -= this.stepValue;\n } else {\n handled = false;\n }\n break;\n case \"ArrowRight\":\n if (isVertical) {\n nextValue += this.stepValue;\n } else {\n handled = false;\n }\n break;\n case \"ArrowUp\":\n if (!isVertical) {\n nextValue -= this.stepValue;\n } else {\n handled = false;\n }\n break;\n case \"ArrowDown\":\n if (!isVertical) {\n nextValue += this.stepValue;\n } else {\n handled = false;\n }\n break;\n case \"Home\":\n nextValue = this.minValue;\n break;\n case \"End\":\n nextValue = this.maxValue;\n break;\n case \"Enter\":\n event.preventDefault();\n this.toggle();\n return;\n default:\n handled = false;\n break;\n }\n\n if (handled) {\n event.preventDefault();\n this.valueValue = Math.max(this.minValue, Math.min(nextValue, this.maxValue));\n this.#clampAndSync();\n this.#dispatchChange();\n }\n }\n\n /** Double-click or Enter to collapse/restore pane to min/max levels. */\n toggle(): void {\n const threshold = this.minValue + (this.maxValue - this.minValue) / 2;\n if (this.valueValue > this.minValue) {\n this.#valueBeforeCollapse = this.valueValue;\n this.valueValue = this.minValue;\n } else {\n this.valueValue =\n this.#valueBeforeCollapse >= threshold ? this.#valueBeforeCollapse : this.maxValue;\n }\n this.#clampAndSync();\n this.#dispatchChange();\n }\n\n readonly #onPointerMove = (event: PointerEvent): void => {\n if (!this.hasSeparatorTarget) return;\n\n const rect = this.element.getBoundingClientRect();\n const orientation = this.separatorTarget.getAttribute(\"aria-orientation\") || \"vertical\";\n const isVertical = orientation === \"vertical\";\n\n let fraction = 0.5;\n\n if (isVertical) {\n fraction = (event.clientX - rect.left) / rect.width;\n } else {\n fraction = (event.clientY - rect.top) / rect.height;\n }\n\n // Restrict within absolute boundaries\n fraction = Math.max(0, Math.min(fraction, 1));\n const percent = Math.round(fraction * 100);\n\n this.valueValue = Math.max(this.minValue, Math.min(percent, this.maxValue));\n this.#clampAndSync();\n };\n\n readonly #onPointerUp = (event: PointerEvent): void => {\n if (!this.hasSeparatorTarget) return;\n\n const separator = this.separatorTarget;\n separator.releasePointerCapture(event.pointerId);\n\n this.element.removeAttribute(\"data-dragging\");\n\n this.#dragAbort?.abort();\n this.#dragAbort = null;\n\n this.#dispatchChange();\n };\n\n #clampAndSync(): void {\n const clamped = Math.max(this.minValue, Math.min(this.valueValue, this.maxValue));\n\n // Keep the stored value in range so valueValue, ARIA, CSS, and dispatched\n // events never diverge (e.g. an initial value above max). Writing back\n // re-enters valueValueChanged once, but the value is already clamped there\n // so it does not recurse.\n if (this.valueValue !== clamped) {\n this.valueValue = clamped;\n }\n\n // Expose local fraction to consumer CSS custom property\n const fraction = clamped / 100;\n this.element.style.setProperty(\"--stimeo--resizable-fraction\", String(fraction));\n\n if (this.hasSeparatorTarget) {\n this.separatorTarget.setAttribute(\"aria-valuenow\", String(clamped));\n this.separatorTarget.setAttribute(\"aria-valuemin\", String(this.minValue));\n this.separatorTarget.setAttribute(\"aria-valuemax\", String(this.maxValue));\n }\n }\n\n #dispatchChange(): void {\n const fraction = this.valueValue / 100;\n this.dispatch(\"change\", { detail: { value: this.valueValue, fraction } });\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/arrow_step.ts","../../src/utils/tabindex_loan.ts","../../src/controllers/resizable_controller.ts"],"names":[],"mapp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,YAAA,CAAa,eAAA,EAAiB,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAC,CAAA;AAAA,IAC1E;AAAA,EACF;AAAA,EAEA,eAAA,GAAwB;AACtB,IAAA,MAAM,QAAA,GAAW,KAAK,UAAA,GAAa,GAAA;AACnC,IAAA,IAAA,CAAK,QAAA,CAAS,QAAA,EAAU,EAAE,MAAA,EAAQ,EAAE,OAAO,IAAA,CAAK,UAAA,EAAY,QAAA,EAAS,EAAG,CAAA;AAAA,EAC1E;AACF","file":"resizable_controller.js","sourcesContent":["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 * Shared bookkeeping for a `tabindex` a controller lends an element temporarily.\n *\n * A controller that must move focus somewhere the author never made focusable\n * (a landmark root, a scroll destination) reaches for the same trick: add a\n * `tabindex` just-in-time and hand it back once it is no longer needed. The\n * borrow is the easy half; the return is what the two conditions below are for.\n *\n * **Returning needs two conditions, not one.** Owning the borrow is not enough:\n * the attribute must also still hold the value this instance wrote. A consumer\n * that changed it afterwards — `tabindex=\"0\"` to make the root its own Tab stop\n * — owns it now, and removing it there silently discards authored markup. The\n * bookkeeping is dropped either way, since the loan is over regardless of who\n * ends up owning the value.\n *\n * **Never borrow over an existing value.** An element that already carries a\n * `tabindex` is the author's to control, so there is nothing to lend and nothing\n * to return.\n *\n * The registry is keyed by element, so a controller borrowing on a single\n * element (`this.element`) and one borrowing across a changing set of targets\n * use the same API — the single-element case is a set of one. It holds no\n * opinion about *when* to borrow or where focus goes next; that stays in the\n * controller.\n *\n * **The API is deliberately two methods.** This file's own doc block is dropped\n * from `dist`, but every member comment is inlined into **each** consumer entry\n * (`tsup` builds with `splitting: false`), so rationale belongs here, only the\n * contract belongs on the members, and every method no consumer calls is still\n * paid for once per consumer entry.\n *\n * @example\n * ```ts\n * readonly #tabindex = new TabindexLoan();\n *\n * #rescueFocus() {\n * this.#tabindex.lend(this.element);\n * this.element.focus();\n * }\n *\n * disconnect() {\n * this.#tabindex.returnAll();\n * }\n * ```\n */\nexport class TabindexLoan<T extends HTMLElement = HTMLElement> {\n readonly #value: string;\n readonly #lent = new Set<T>();\n\n /**\n * @param value - the `tabindex` to lend. `\"-1\"` (the default) is\n * programmatically focusable but not a Tab stop; `\"0\"` is a real Tab stop,\n * which a scroll region with no focusable content of its own needs.\n */\n constructor(value: string = \"-1\") {\n this.#value = value;\n }\n\n /** Lends `element` the value; no-ops when it already carries a `tabindex`. */\n lend(element: T): void {\n if (element.hasAttribute(\"tabindex\")) return;\n element.setAttribute(\"tabindex\", this.#value);\n this.#lent.add(element);\n }\n\n /** Takes back every loan whose value is still the one that was lent. */\n returnAll(): void {\n for (const element of this.#lent) {\n if (element.getAttribute(\"tabindex\") === this.#value) element.removeAttribute(\"tabindex\");\n }\n this.#lent.clear();\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\nimport { TabindexLoan } from \"../utils/tabindex_loan\";\n\n/**\n * Headless, highly accessible Window Splitter / Resizable panes logic.\n *\n * Markup contract (identifier: `stimeo--resizable`):\n * <div data-controller=\"stimeo--resizable\"\n * data-stimeo--resizable-min-value=\"20\"\n * data-stimeo--resizable-max-value=\"80\"\n * data-stimeo--resizable-value-value=\"50\">\n * <div data-stimeo--resizable-target=\"primary\" id=\"pane-1\">Pane A</div>\n * <div role=\"separator\" tabindex=\"0\" aria-orientation=\"vertical\"\n * aria-controls=\"pane-1\" aria-valuemin=\"20\" aria-valuemax=\"80\"\n * aria-valuenow=\"50\" aria-label=\"Resize splitter\"\n * data-stimeo--resizable-target=\"separator\"\n * data-action=\"pointerdown->stimeo--resizable#onPointerDown\n * keydown->stimeo--resizable#onKeydown\"></div>\n * <div data-stimeo--resizable-target=\"secondary\">Pane B</div>\n * </div>\n *\n * Implements the WAI-ARIA APG **Window Splitter** pattern:\n * - Robust dragging track using W3C `setPointerCapture` to ensure uninterrupted dragging\n * even when pointers quickly stray outside the separator area.\n * - Auto-clamped flex-percentage updates with bounds safety.\n * - Smooth step keyboard adjustments for Arrow keys based on vertical/horizontal orientation.\n * - Root-level CSS custom property `--stimeo--resizable-fraction` (0..1) driving\n * presentation styles.\n * - `F6` cycles focus through the panes, which the pattern lists as optional.\n *\n * @remarks\n * Behavior only. The controller adjusts the CSS custom property on the root element,\n * updates ARIA values on the separator, and emits `stimeo--resizable:change` events.\n */\nexport class ResizableController extends Controller<HTMLElement> {\n static override targets = [\"primary\", \"secondary\", \"separator\"];\n static override values = {\n min: { type: Number, default: 0 },\n max: { type: Number, default: 100 },\n step: { type: Number, default: 1 },\n value: { type: Number, default: 50 },\n };\n static actions = [\"onKeydown\", \"onPointerDown\", \"toggle\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly primaryTarget: HTMLElement;\n declare readonly secondaryTarget: HTMLElement;\n declare readonly separatorTarget: HTMLElement;\n declare readonly hasPrimaryTarget: boolean;\n declare readonly hasSecondaryTarget: boolean;\n declare readonly hasSeparatorTarget: boolean;\n\n declare minValue: number;\n declare maxValue: number;\n declare stepValue: number;\n declare valueValue: number;\n\n /** The value held before the current collapse, restored when toggling back. */\n #valueBeforeCollapse = 50;\n\n /** Aborts in-progress pointer-drag listeners when the drag ends or on teardown. */\n #dragAbort: AbortController | null = null;\n\n /** `tabindex` lent to a pane so `F6` can put focus on it; panes carry none. */\n readonly #paneTabindex = new TabindexLoan();\n\n /** Releases the pane cycle listener bound in {@link connect}. */\n #cycleAbort: AbortController | null = null;\n\n override connect(): void {\n this.#clampAndSync();\n // Bound on the root rather than the panes so the cycle continues once focus\n // has left the separator — the panes hold consumer markup and the next F6\n // arrives from inside one of them.\n this.#cycleAbort = new AbortController();\n this.element.addEventListener(\"keydown\", this.#onCycleKeydown, {\n signal: this.#cycleAbort.signal,\n });\n }\n\n /** Cancels any active pointer drag so listeners never leak past disconnect. */\n override disconnect(): void {\n this.#dragAbort?.abort();\n this.#dragAbort = null;\n this.#cycleAbort?.abort();\n this.#cycleAbort = null;\n this.#paneTabindex.returnAll();\n }\n\n /** Moves focus to the next pane on `F6`, wrapping; entering at the first one. */\n readonly #onCycleKeydown = (event: KeyboardEvent): void => {\n if (event.key !== \"F6\") return;\n // A descendant widget that already claimed the key must not ALSO cycle the\n // panes; this listener sees consumer markup, so composition depends on it.\n if (event.defaultPrevented) return;\n // The pattern binds a bare F6 only. A chorded one is the browser's or the\n // OS's (Ctrl+F6 cycles frames in several browsers).\n if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;\n\n const panes: HTMLElement[] = [];\n if (this.hasPrimaryTarget) panes.push(this.primaryTarget);\n if (this.hasSecondaryTarget) panes.push(this.secondaryTarget);\n if (panes.length === 0) return;\n\n const target = event.target as Node | null;\n const current = panes.findIndex((pane) => target instanceof Node && pane.contains(target));\n const next = panes[(current + 1) % panes.length];\n if (!next) return;\n\n event.preventDefault();\n this.#paneTabindex.lend(next);\n next.focus();\n };\n\n /**\n * Stimulus lifecycle callback when the valueValue changes.\n * Keeps CSS fractions and ARIA status completely aligned.\n */\n valueValueChanged(): void {\n this.#clampAndSync();\n }\n\n /** Starts active pointer drag tracking and locks capture. */\n onPointerDown(event: PointerEvent): void {\n if (!this.hasSeparatorTarget || event.button !== 0) return;\n\n event.preventDefault();\n\n const separator = this.separatorTarget;\n separator.setPointerCapture(event.pointerId);\n // preventDefault() above suppresses the implicit focus, so move focus\n // explicitly — otherwise keyboard (arrow) adjustments never reach the\n // separator after a pointer interaction (WCAG 2.1.1).\n separator.focus();\n\n this.element.setAttribute(\"data-dragging\", \"true\");\n\n this.#dragAbort?.abort();\n const abort = new AbortController();\n this.#dragAbort = abort;\n separator.addEventListener(\"pointermove\", this.#onPointerMove, { signal: abort.signal });\n separator.addEventListener(\"pointerup\", this.#onPointerUp, { signal: abort.signal });\n separator.addEventListener(\"pointercancel\", this.#onPointerUp, { signal: abort.signal });\n }\n\n /** Keydown adjustments for ArrowUp/Down/Left/Right and Home/End. */\n onKeydown(event: KeyboardEvent): void {\n if (isReservedArrowChord(event)) return;\n if (!this.hasSeparatorTarget) return;\n\n const orientation = this.separatorTarget.getAttribute(\"aria-orientation\") || \"vertical\";\n const isVertical = orientation === \"vertical\";\n\n let handled = true;\n let nextValue = this.valueValue;\n\n switch (event.key) {\n case \"ArrowLeft\":\n if (isVertical) {\n nextValue -= this.stepValue;\n } else {\n handled = false;\n }\n break;\n case \"ArrowRight\":\n if (isVertical) {\n nextValue += this.stepValue;\n } else {\n handled = false;\n }\n break;\n case \"ArrowUp\":\n if (!isVertical) {\n nextValue -= this.stepValue;\n } else {\n handled = false;\n }\n break;\n case \"ArrowDown\":\n if (!isVertical) {\n nextValue += this.stepValue;\n } else {\n handled = false;\n }\n break;\n case \"Home\":\n nextValue = this.minValue;\n break;\n case \"End\":\n nextValue = this.maxValue;\n break;\n case \"Enter\":\n event.preventDefault();\n this.toggle();\n return;\n default:\n handled = false;\n break;\n }\n\n if (handled) {\n event.preventDefault();\n this.valueValue = Math.max(this.minValue, Math.min(nextValue, this.maxValue));\n this.#clampAndSync();\n this.#dispatchChange();\n }\n }\n\n /** Double-click or Enter to collapse/restore pane to min/max levels. */\n toggle(): void {\n const threshold = this.minValue + (this.maxValue - this.minValue) / 2;\n if (this.valueValue > this.minValue) {\n this.#valueBeforeCollapse = this.valueValue;\n this.valueValue = this.minValue;\n } else {\n this.valueValue =\n this.#valueBeforeCollapse >= threshold ? this.#valueBeforeCollapse : this.maxValue;\n }\n this.#clampAndSync();\n this.#dispatchChange();\n }\n\n readonly #onPointerMove = (event: PointerEvent): void => {\n if (!this.hasSeparatorTarget) return;\n\n const rect = this.element.getBoundingClientRect();\n const orientation = this.separatorTarget.getAttribute(\"aria-orientation\") || \"vertical\";\n const isVertical = orientation === \"vertical\";\n\n let fraction = 0.5;\n\n if (isVertical) {\n fraction = (event.clientX - rect.left) / rect.width;\n } else {\n fraction = (event.clientY - rect.top) / rect.height;\n }\n\n // Restrict within absolute boundaries\n fraction = Math.max(0, Math.min(fraction, 1));\n const percent = Math.round(fraction * 100);\n\n this.valueValue = Math.max(this.minValue, Math.min(percent, this.maxValue));\n this.#clampAndSync();\n };\n\n readonly #onPointerUp = (event: PointerEvent): void => {\n if (!this.hasSeparatorTarget) return;\n\n const separator = this.separatorTarget;\n separator.releasePointerCapture(event.pointerId);\n\n this.element.removeAttribute(\"data-dragging\");\n\n this.#dragAbort?.abort();\n this.#dragAbort = null;\n\n this.#dispatchChange();\n };\n\n #clampAndSync(): void {\n const clamped = Math.max(this.minValue, Math.min(this.valueValue, this.maxValue));\n\n // Keep the stored value in range so valueValue, ARIA, CSS, and dispatched\n // events never diverge (e.g. an initial value above max). Writing back\n // re-enters valueValueChanged once, but the value is already clamped there\n // so it does not recurse.\n if (this.valueValue !== clamped) {\n this.valueValue = clamped;\n }\n\n // Expose local fraction to consumer CSS custom property\n const fraction = clamped / 100;\n this.element.style.setProperty(\"--stimeo--resizable-fraction\", String(fraction));\n\n if (this.hasSeparatorTarget) {\n this.separatorTarget.setAttribute(\"aria-valuenow\", String(clamped));\n this.separatorTarget.setAttribute(\"aria-valuemin\", String(this.minValue));\n this.separatorTarget.setAttribute(\"aria-valuemax\", String(this.maxValue));\n }\n }\n\n #dispatchChange(): void {\n const fraction = this.valueValue / 100;\n this.dispatch(\"change\", { detail: { value: this.valueValue, fraction } });\n }\n}\n"]}
@@ -2,6 +2,17 @@ import { Controller } from '@hotwired/stimulus';
2
2
 
3
3
  // src/controllers/roving_controller.ts
4
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
+
5
16
  // src/utils/roving_tabindex.ts
6
17
  var RovingTabindex = class {
7
18
  /** Returns the current ordered item elements; called on every operation. */
@@ -64,6 +75,7 @@ var RovingController = class extends Controller {
64
75
  /** Arrow keys move focus + the tab stop; Home/End jump to the ends. */
65
76
  #onKeydown = (event) => {
66
77
  if (event.defaultPrevented) return;
78
+ if (isReservedArrowChord(event)) return;
67
79
  const items = this.itemTargets;
68
80
  const current = this.#indexOf(event.target);
69
81
  if (current === -1) return;
@@ -72,10 +84,13 @@ var RovingController = class extends Controller {
72
84
  const orientation = this.orientationValue;
73
85
  const horizontal = orientation === "horizontal" || orientation === "both";
74
86
  const vertical = orientation === "vertical" || orientation === "both";
87
+ const rtl = horizontal && isRtl(this.element);
88
+ const forwardKey = rtl ? "ArrowLeft" : "ArrowRight";
89
+ const backwardKey = rtl ? "ArrowRight" : "ArrowLeft";
75
90
  let next;
76
- if (horizontal && event.key === "ArrowRight" || vertical && event.key === "ArrowDown") {
91
+ if (horizontal && event.key === forwardKey || vertical && event.key === "ArrowDown") {
77
92
  next = rovingMove(current, length, 1, wrap);
78
- } else if (horizontal && event.key === "ArrowLeft" || vertical && event.key === "ArrowUp") {
93
+ } else if (horizontal && event.key === backwardKey || vertical && event.key === "ArrowUp") {
79
94
  next = rovingMove(current, length, -1, wrap);
80
95
  } else if (this.homeEndValue && event.key === "Home") {
81
96
  next = 0;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/roving_tabindex.ts","../../src/controllers/roving_controller.ts"],"names":[],"mappings":";;;;;AAqBO,IAAM,iBAAN,MAAqB;AAAA;AAAA,EAEjB,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMT,YAAY,QAAA,EAA+B;AACzC,IAAA,IAAA,CAAK,SAAA,GAAY,QAAA;AAAA,EACnB;AAAA;AAAA,EAGA,IAAI,WAAA,GAAsB;AACxB,IAAA,OAAO,IAAA,CAAK,WAAU,CAAE,SAAA,CAAU,CAAC,IAAA,KAAS,IAAA,CAAK,aAAa,CAAC,CAAA;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,UAAU,KAAA,EAAe,EAAE,QAAQ,KAAA,EAAM,GAAyB,EAAC,EAAS;AAC1E,IAAA,MAAM,KAAA,GAAQ,KAAK,SAA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IAAA,CAAK,OAAA,CAAQ,SAAA,CAAU,KAAA,EAAO,EAAE,OAAO,CAAA;AACvC,IAAA,IAAI,UAAU,QAAA,EAAU;AACtB,MAAA,IAAA,CAAK,QAAA,CAAS,QAAA,EAAU,EAAE,MAAA,EAAQ,EAAE,KAAA,EAAO,IAAA,EAAM,IAAA,CAAK,WAAA,CAAY,KAAK,CAAA,EAAE,EAAG,CAAA;AAAA,IAC9E;AAAA,EACF;AACF","file":"roving_controller.js","sourcesContent":["/**\n * Low-level roving-tabindex primitive shared by composite-widget controllers.\n *\n * The APG roving-tabindex pattern keeps a composite widget a single Tab stop:\n * exactly one item is in the Tab sequence (`tabindex=\"0\"`) while the rest are\n * removed from it (`tabindex=\"-1\"`), and the arrow keys move both DOM focus and\n * that single tabbable position together. {@link RovingTabindex} owns *only* that\n * mechanical bookkeeping — \"which one item is tabbable, and move focus there\".\n *\n * It is intentionally **policy-free**. Orientation, wrapping vs. clamping,\n * selection-follows-focus, typeahead, and `Home`/`End` semantics differ per APG\n * pattern (Radio Group, Toolbar, Rating, …); folding them into one helper would\n * flatten those widgets to a lowest common denominator and lose each pattern's\n * correctness. Those decisions therefore stay in each controller, which calls\n * {@link RovingTabindex.setActive} with an index it computed itself (optionally\n * via the pure {@link rovingMove} helper).\n *\n * @remarks\n * Items are read lazily through a getter so a controller can add or remove\n * targets (Stimulus re-scans the DOM) without re-wiring this helper.\n */\nexport class RovingTabindex {\n /** Returns the current ordered item elements; called on every operation. */\n readonly #getItems: () => HTMLElement[];\n\n /**\n * @param getItems - Returns the current ordered item elements. Called on every\n * operation so the live target list is always used.\n */\n constructor(getItems: () => HTMLElement[]) {\n this.#getItems = getItems;\n }\n\n /** Index of the currently tabbable item (`tabindex=\"0\"`), or `-1` if none. */\n get activeIndex(): number {\n return this.#getItems().findIndex((item) => item.tabIndex === 0);\n }\n\n /**\n * Makes exactly the item at `index` tabbable (`tabindex=\"0\"`) and removes every\n * other item from the Tab sequence (`tabindex=\"-1\"`). An out-of-range `index`\n * (e.g. `-1`) leaves all items at `-1`, which a controller can use to express\n * \"nothing is currently tabbable\".\n *\n * @param index - Position of the item to make tabbable.\n * @param options - Pass `{ focus: true }` to also move DOM focus to that item.\n */\n setActive(index: number, { focus = false }: { focus?: boolean } = {}): void {\n const items = this.#getItems();\n items.forEach((item, i) => {\n item.tabIndex = i === index ? 0 : -1;\n });\n if (focus) items[index]?.focus();\n }\n}\n\n/** Edge behavior for {@link rovingMove}: cycle past the ends, or stop at them. */\nexport type RovingWrap = \"wrap\" | \"clamp\";\n\n/**\n * Pure helper that resolves the target index for a one-step directional move.\n *\n * Keyboard/orientation mapping stays in the caller: it decides that a key means\n * `delta` `+1` (next) or `-1` (previous) and whether the widget should `\"wrap\"`\n * (Radio Group, Toolbar) or `\"clamp\"` at the ends.\n *\n * @param current - The index focus is moving from.\n * @param length - Number of items in the set.\n * @param delta - `+1` to move to the next item, `-1` for the previous.\n * @param wrap - `\"wrap\"` cycles around the ends; `\"clamp\"` stops at them.\n * @returns The resolved index, or `-1` when there are no items.\n */\nexport function rovingMove(\n current: number,\n length: number,\n delta: number,\n wrap: RovingWrap,\n): number {\n if (length === 0) return -1;\n const next = current + delta;\n if (wrap === \"wrap\") return (next + length) % length;\n return Math.min(length - 1, Math.max(0, next));\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { RovingTabindex, type RovingWrap, rovingMove } from \"../utils/roving_tabindex\";\n\n/**\n * Headless **roving tabindex**: makes a set of `item`s a single Tab stop and\n * moves focus between them with the arrow keys — the APG roving-tabindex\n * technique, surfaced as a standalone controller. It is the policy layer over the\n * shared {@link RovingTabindex} util (counterpart to Focus Scope over `FocusTrap`),\n * giving the orientation / wrap / Home-End the util deliberately leaves out. No\n * dedicated APG pattern; it is the keyboard primitive Toolbar / Menu / Radio Group\n * and friends build on. Core (zero dependencies).\n *\n * Markup contract (identifier: `stimeo--roving`):\n * <div data-controller=\"stimeo--roving\"\n * data-stimeo--roving-orientation-value=\"horizontal\">\n * <button data-stimeo--roving-target=\"item\">A</button>\n * <button data-stimeo--roving-target=\"item\">B</button>\n * <button data-stimeo--roving-target=\"item\">C</button>\n * </div>\n *\n * Exactly one item is tabbable (`tabindex=\"0\"`); the arrow keys (per\n * `orientation`) move focus and that tab stop together, `Home`/`End` jump to the\n * ends (`homeEnd`), and `wrap` cycles past the ends or clamps at them. Listeners\n * are **delegated on the container** — `keydown` for movement and `focusin` to\n * sync the tab stop when focus arrives by click or programmatically — so\n * dynamically added/removed items need no per-item `data-action`. It emits\n * `change` whenever the tabbable item changes.\n *\n * @remarks\n * Behavior only: it owns `tabindex` and focus movement, nothing else. It does\n * **not** assign roles (`role=\"toolbar\"`/`\"radiogroup\"` is the author's), manage\n * selection / selection-follows-focus, typeahead, or activation (`Enter`/`Space`)\n * — those stay with the consuming pattern. `connect()` is idempotent: it keeps an\n * existing tab stop (reads it back from the DOM) and only defaults to the first\n * item when none is set, so a Turbo cache restore / morph never resets the user's\n * position. The delegated listeners are torn down on `disconnect()`.\n */\nexport class RovingController extends Controller<HTMLElement> {\n static override targets = [\"item\"];\n static override values = {\n orientation: { type: String, default: \"horizontal\" },\n wrap: { type: Boolean, default: true },\n homeEnd: { type: Boolean, default: true },\n };\n static events = [\"change\"] as const;\n\n declare readonly itemTargets: HTMLElement[];\n declare orientationValue: string;\n declare wrapValue: boolean;\n declare homeEndValue: boolean;\n\n readonly #roving = new RovingTabindex(() => this.itemTargets);\n\n override connect(): void {\n // Establish the single tab stop from the DOM (source of truth): keep an\n // existing tabbable item, else default to the first. Silent — no change event\n // for the initial mount.\n const active = this.#roving.activeIndex;\n this.#roving.setActive(active === -1 ? 0 : active);\n this.element.addEventListener(\"keydown\", this.#onKeydown);\n this.element.addEventListener(\"focusin\", this.#onFocusin);\n }\n\n override disconnect(): void {\n this.element.removeEventListener(\"keydown\", this.#onKeydown);\n this.element.removeEventListener(\"focusin\", this.#onFocusin);\n }\n\n /** Arrow keys move focus + the tab stop; Home/End jump to the ends. */\n readonly #onKeydown = (event: KeyboardEvent): void => {\n // A descendant widget that already claimed the key (e.g. a grabbed\n // `stimeo--pointer-drag` handle consuming arrows to move an item) must not\n // ALSO move the roving focus — composition depends on this yield.\n if (event.defaultPrevented) return;\n const items = this.itemTargets;\n const current = this.#indexOf(event.target);\n if (current === -1) return;\n\n const length = items.length;\n const wrap: RovingWrap = this.wrapValue ? \"wrap\" : \"clamp\";\n const orientation = this.orientationValue;\n const horizontal = orientation === \"horizontal\" || orientation === \"both\";\n const vertical = orientation === \"vertical\" || orientation === \"both\";\n\n let next: number;\n if ((horizontal && event.key === \"ArrowRight\") || (vertical && event.key === \"ArrowDown\")) {\n next = rovingMove(current, length, 1, wrap);\n } else if ((horizontal && event.key === \"ArrowLeft\") || (vertical && event.key === \"ArrowUp\")) {\n next = rovingMove(current, length, -1, wrap);\n } else if (this.homeEndValue && event.key === \"Home\") {\n next = 0;\n } else if (this.homeEndValue && event.key === \"End\") {\n next = length - 1;\n } else {\n return;\n }\n\n event.preventDefault();\n this.#activate(next, true);\n };\n\n /**\n * Syncs the single tab stop to an item that received focus by other means\n * (click, programmatic `focus()`), so returning via Tab lands on it. The\n * keyboard path's own `focus()` re-enters here but is a no-op (index unchanged).\n */\n readonly #onFocusin = (event: FocusEvent): void => {\n const index = this.#indexOf(event.target);\n if (index !== -1) this.#activate(index, false);\n };\n\n /** Resolves the item index owning an event target (the item or a descendant). */\n #indexOf(target: EventTarget | null): number {\n const node = target as Node | null;\n if (!node) return -1;\n return this.itemTargets.findIndex((item) => item === node || item.contains(node));\n }\n\n /** Makes `index` the tab stop (optionally focusing it), emitting `change` once. */\n #activate(index: number, focus: boolean): void {\n const previous = this.#roving.activeIndex;\n this.#roving.setActive(index, { focus });\n if (index !== previous) {\n this.dispatch(\"change\", { detail: { index, item: this.itemTargets[index] } });\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/logical_scroll.ts","../../src/utils/arrow_step.ts","../../src/utils/roving_tabindex.ts","../../src/controllers/roving_controller.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Ae,KAAA,EAAsB;AAC7C,IAAA,MAAM,QAAA,GAAW,KAAK,OAAA,CAAQ,WAAA;AAC9B,IAAA,IAAA,CAAK,OAAA,CAAQ,SAAA,CAAU,KAAA,EAAO,EAAE,OAAO,CAAA;AACvC,IAAA,IAAI,UAAU,QAAA,EAAU;AACtB,MAAA,IAAA,CAAK,QAAA,CAAS,QAAA,EAAU,EAAE,MAAA,EAAQ,EAAE,KAAA,EAAO,IAAA,EAAM,IAAA,CAAK,WAAA,CAAY,KAAK,CAAA,EAAE,EAAG,CAAA;AAAA,IAC9E;AAAA,EACF;AACF","file":"roving_controller.js","sourcesContent":["/** Normalized scroll position and maximum distance on one logical axis. */\nexport interface LogicalScrollMetrics {\n position: number;\n max: number;\n}\n\n/**\n * Whether horizontal scrolling on `element` follows right-to-left inline flow.\n *\n * Resolved from the **computed** `direction`, so the authoring contract is the\n * usual `dir=\"rtl\"` (or a stylesheet) on the element or any ancestor.\n *\n * Scope: horizontal writing modes. A vertical writing mode (`writing-mode:\n * vertical-rl`) also inverts the horizontal axis, which this check does not\n * model — vertical writing modes are out of scope for the scroll utilities\n * (their consumers describe axes as horizontal/vertical, not inline/block).\n */\nexport function isRtl(element: Element): boolean {\n return window.getComputedStyle(element).direction === \"rtl\";\n}\n\n/**\n * Returns scroll distance from the logical start edge.\n *\n * CSSOM View exposes standards-mode RTL horizontal offsets as `0` at the inline\n * start (right) and increasingly negative values toward the inline end (left).\n * The normalized position is always clamped to `[0, max]`, which also absorbs\n * Safari's elastic overscroll values.\n */\nexport function logicalScrollMetrics(\n element: HTMLElement,\n horizontal: boolean,\n): LogicalScrollMetrics {\n const max = Math.max(\n 0,\n horizontal\n ? element.scrollWidth - element.clientWidth\n : element.scrollHeight - element.clientHeight,\n );\n const raw = horizontal ? element.scrollLeft : element.scrollTop;\n const position = horizontal && isRtl(element) ? -raw : raw;\n return { position: Math.min(max, Math.max(0, position)), max };\n}\n\n/**\n * Converts a logical start/end delta to the physical value accepted by\n * `Element.scrollBy`.\n */\nexport function physicalScrollDelta(\n element: HTMLElement,\n horizontal: boolean,\n logicalDelta: number,\n): number {\n return horizontal && isRtl(element) ? -logicalDelta : logicalDelta;\n}\n","import { isRtl } from \"./logical_scroll\";\n\n/**\n * Turns an arrow key into a **logical** step: `+1` for \"next\", `-1` for\n * \"previous\", `0` when the key names neither.\n *\n * APG defines the horizontal pair as *next / previous* and says a vertical\n * arrangement swaps in Down/Up for the same meaning — so the pair is one axis's\n * spelling of an order, and the order reverses with the writing direction. Only\n * the horizontal pair reverses. Down/Up name an axis the writing direction does\n * not mirror, and returning them unchanged is the point: many controllers fold\n * both pairs into one branch, where swapping the branches under RTL would flip\n * the vertical axis too — a bug that reads as \"the arrows work\" until someone\n * presses Down.\n *\n * **Direction is read from the element the caller passes, which should be the\n * container that lays the items out** — not the focused child. A child may carry\n * its own `dir` (an LTR input inside an RTL form is ordinary authoring), and\n * probing per handler makes two handlers disagree at the boundary between them.\n *\n * This decides direction only. Whether the axis is even active (an\n * `orientation=\"horizontal\"` widget ignoring Down/Up), how far the step lands,\n * and what wrapping does all stay with the caller.\n *\n * **It encodes the list-order convention: `ArrowDown` is *next*.** Widgets that\n * pair the arrows by *value* instead — `ArrowUp` meaning \"more\", as a rating or a\n * slider does — must not use this, or their vertical axis inverts. Reverse the\n * horizontal pair on its own there.\n *\n * @example\n * ```ts\n * const step = logicalArrowStep(event.key, this.element);\n * if (step === 0) return;\n * this.#roving.setActive(rovingMove(current, length, step, \"wrap\"), { focus: true });\n * ```\n */\nexport function logicalArrowStep(key: string, element: Element): 1 | -1 | 0 {\n if (key === \"ArrowDown\") return 1;\n if (key === \"ArrowUp\") return -1;\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return 0;\n const forward = isRtl(element) ? \"ArrowLeft\" : \"ArrowRight\";\n return key === forward ? 1 : -1;\n}\n\n/**\n * Rewrites `key` so an existing LTR-shaped branch keeps working under RTL:\n * `ArrowRight` and `ArrowLeft` trade places, everything else passes through.\n *\n * The alternative — negating a delta — silently breaks handlers whose two\n * horizontal branches are **not mirror images**. A grid that clamps one edge but\n * not the other, or a segmented field guarding `index > 0` on one side and\n * `index < length - 1` on the other, ends up applying the wrong guard to the\n * wrong direction. Swapping the key leaves each branch, guards and all, exactly\n * where its author put it.\n *\n * Same rule as {@link logicalArrowStep} about which element to read: pass the\n * container that lays the items out, not the focused child.\n *\n * @example\n * ```ts\n * switch (logicalArrowKey(event.key, this.element)) {\n * case \"ArrowLeft\": // \"previous\" — whatever direction that is on screen\n * ```\n */\nexport function logicalArrowKey(key: string, element: Element): string {\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return key;\n if (!isRtl(element)) return key;\n return key === \"ArrowRight\" ? \"ArrowLeft\" : \"ArrowRight\";\n}\n\n/** Modifiers a widget may claim on an arrow key, named for the `allow` list. */\nexport type ArrowModifier = \"alt\" | \"ctrl\" | \"meta\" | \"shift\";\n\n/**\n * True when an arrow key arrived carrying a modifier the widget must leave to\n * the browser: return without calling `preventDefault()` and without moving any\n * state.\n *\n * A bare arrow belongs to the widget; a chorded one usually does not.\n * `Alt`/`Meta` plus a horizontal arrow is history back/forward on every desktop\n * browser, and a widget that swallows it makes the shortcut work or not\n * depending on where focus happens to sit — a coin-flip the user cannot see.\n *\n * `allow` is for the combinations APG assigns to a pattern **and the widget\n * actually implements** — today only Combobox's optional `Alt+Down`/`Alt+Up`.\n * Listing one the widget does not implement defeats the point: the chord then\n * runs the plain-arrow branch, which is exactly what this guard exists to stop.\n * Non-arrow keys return `false`, so chorded letters and\n * `Control+Home`/`Control+End` are untouched.\n *\n * @example\n * ```ts\n * if (isReservedArrowChord(event)) return;\n * ```\n */\nexport function isReservedArrowChord(\n event: KeyboardEvent,\n allow: readonly ArrowModifier[] = [],\n): boolean {\n if (!event.key.startsWith(\"Arrow\")) return false;\n return (\n (event.altKey && !allow.includes(\"alt\")) ||\n (event.ctrlKey && !allow.includes(\"ctrl\")) ||\n (event.metaKey && !allow.includes(\"meta\")) ||\n (event.shiftKey && !allow.includes(\"shift\"))\n );\n}\n","/**\n * Low-level roving-tabindex primitive shared by composite-widget controllers.\n *\n * The APG roving-tabindex pattern keeps a composite widget a single Tab stop:\n * exactly one item is in the Tab sequence (`tabindex=\"0\"`) while the rest are\n * removed from it (`tabindex=\"-1\"`), and the arrow keys move both DOM focus and\n * that single tabbable position together. {@link RovingTabindex} owns *only* that\n * mechanical bookkeeping — \"which one item is tabbable, and move focus there\".\n *\n * It is intentionally **policy-free**. Orientation, wrapping vs. clamping,\n * selection-follows-focus, typeahead, and `Home`/`End` semantics differ per APG\n * pattern (Radio Group, Toolbar, Rating, …); folding them into one helper would\n * flatten those widgets to a lowest common denominator and lose each pattern's\n * correctness. Those decisions therefore stay in each controller, which calls\n * {@link RovingTabindex.setActive} with an index it computed itself (optionally\n * via the pure {@link rovingMove} helper).\n *\n * @remarks\n * Items are read lazily through a getter so a controller can add or remove\n * targets (Stimulus re-scans the DOM) without re-wiring this helper.\n */\nexport class RovingTabindex {\n /** Returns the current ordered item elements; called on every operation. */\n readonly #getItems: () => HTMLElement[];\n\n /**\n * @param getItems - Returns the current ordered item elements. Called on every\n * operation so the live target list is always used.\n */\n constructor(getItems: () => HTMLElement[]) {\n this.#getItems = getItems;\n }\n\n /** Index of the currently tabbable item (`tabindex=\"0\"`), or `-1` if none. */\n get activeIndex(): number {\n return this.#getItems().findIndex((item) => item.tabIndex === 0);\n }\n\n /**\n * Makes exactly the item at `index` tabbable (`tabindex=\"0\"`) and removes every\n * other item from the Tab sequence (`tabindex=\"-1\"`). An out-of-range `index`\n * (e.g. `-1`) leaves all items at `-1`, which a controller can use to express\n * \"nothing is currently tabbable\".\n *\n * @param index - Position of the item to make tabbable.\n * @param options - Pass `{ focus: true }` to also move DOM focus to that item.\n */\n setActive(index: number, { focus = false }: { focus?: boolean } = {}): void {\n const items = this.#getItems();\n items.forEach((item, i) => {\n item.tabIndex = i === index ? 0 : -1;\n });\n if (focus) items[index]?.focus();\n }\n}\n\n/** Edge behavior for {@link rovingMove}: cycle past the ends, or stop at them. */\nexport type RovingWrap = \"wrap\" | \"clamp\";\n\n/**\n * Pure helper that resolves the target index for a one-step directional move.\n *\n * Keyboard/orientation mapping stays in the caller: it decides that a key means\n * `delta` `+1` (next) or `-1` (previous) and whether the widget should `\"wrap\"`\n * (Radio Group, Toolbar) or `\"clamp\"` at the ends.\n *\n * @param current - The index focus is moving from.\n * @param length - Number of items in the set.\n * @param delta - `+1` to move to the next item, `-1` for the previous.\n * @param wrap - `\"wrap\"` cycles around the ends; `\"clamp\"` stops at them.\n * @returns The resolved index, or `-1` when there are no items.\n */\nexport function rovingMove(\n current: number,\n length: number,\n delta: number,\n wrap: RovingWrap,\n): number {\n if (length === 0) return -1;\n const next = current + delta;\n if (wrap === \"wrap\") return (next + length) % length;\n return Math.min(length - 1, Math.max(0, next));\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\nimport { isRtl } from \"../utils/logical_scroll\";\nimport { RovingTabindex, type RovingWrap, rovingMove } from \"../utils/roving_tabindex\";\n\n/**\n * Headless **roving tabindex**: makes a set of `item`s a single Tab stop and\n * moves focus between them with the arrow keys — the APG roving-tabindex\n * technique, surfaced as a standalone controller. It is the policy layer over the\n * shared {@link RovingTabindex} util (counterpart to Focus Scope over `FocusTrap`),\n * giving the orientation / wrap / Home-End the util deliberately leaves out. No\n * dedicated APG pattern; it is the keyboard primitive Toolbar / Menu / Radio Group\n * and friends build on. Core (zero dependencies).\n *\n * Markup contract (identifier: `stimeo--roving`):\n * <div data-controller=\"stimeo--roving\"\n * data-stimeo--roving-orientation-value=\"horizontal\">\n * <button data-stimeo--roving-target=\"item\">A</button>\n * <button data-stimeo--roving-target=\"item\">B</button>\n * <button data-stimeo--roving-target=\"item\">C</button>\n * </div>\n *\n * Exactly one item is tabbable (`tabindex=\"0\"`); the arrow keys (per\n * `orientation`) move focus and that tab stop together, `Home`/`End` jump to the\n * ends (`homeEnd`), and `wrap` cycles past the ends or clamps at them. Listeners\n * are **delegated on the container** — `keydown` for movement and `focusin` to\n * sync the tab stop when focus arrives by click or programmatically — so\n * dynamically added/removed items need no per-item `data-action`. It emits\n * `change` whenever the tabbable item changes.\n *\n * @remarks\n * Behavior only: it owns `tabindex` and focus movement, nothing else. It does\n * **not** assign roles (`role=\"toolbar\"`/`\"radiogroup\"` is the author's), manage\n * selection / selection-follows-focus, typeahead, or activation (`Enter`/`Space`)\n * — those stay with the consuming pattern. `connect()` is idempotent: it keeps an\n * existing tab stop (reads it back from the DOM) and only defaults to the first\n * item when none is set, so a Turbo cache restore / morph never resets the user's\n * position. The delegated listeners are torn down on `disconnect()`.\n */\nexport class RovingController extends Controller<HTMLElement> {\n static override targets = [\"item\"];\n static override values = {\n orientation: { type: String, default: \"horizontal\" },\n wrap: { type: Boolean, default: true },\n homeEnd: { type: Boolean, default: true },\n };\n static events = [\"change\"] as const;\n\n declare readonly itemTargets: HTMLElement[];\n declare orientationValue: string;\n declare wrapValue: boolean;\n declare homeEndValue: boolean;\n\n readonly #roving = new RovingTabindex(() => this.itemTargets);\n\n override connect(): void {\n // Establish the single tab stop from the DOM (source of truth): keep an\n // existing tabbable item, else default to the first. Silent — no change event\n // for the initial mount.\n const active = this.#roving.activeIndex;\n this.#roving.setActive(active === -1 ? 0 : active);\n this.element.addEventListener(\"keydown\", this.#onKeydown);\n this.element.addEventListener(\"focusin\", this.#onFocusin);\n }\n\n override disconnect(): void {\n this.element.removeEventListener(\"keydown\", this.#onKeydown);\n this.element.removeEventListener(\"focusin\", this.#onFocusin);\n }\n\n /** Arrow keys move focus + the tab stop; Home/End jump to the ends. */\n readonly #onKeydown = (event: KeyboardEvent): void => {\n // A descendant widget that already claimed the key (e.g. a grabbed\n // `stimeo--pointer-drag` handle consuming arrows to move an item) must not\n // ALSO move the roving focus — composition depends on this yield.\n if (event.defaultPrevented) return;\n if (isReservedArrowChord(event)) return;\n const items = this.itemTargets;\n const current = this.#indexOf(event.target);\n if (current === -1) return;\n\n const length = items.length;\n const wrap: RovingWrap = this.wrapValue ? \"wrap\" : \"clamp\";\n const orientation = this.orientationValue;\n const horizontal = orientation === \"horizontal\" || orientation === \"both\";\n const vertical = orientation === \"vertical\" || orientation === \"both\";\n\n // Logical, not physical. APG defines these as \"next / previous\n // control\", and says a vertical arrangement swaps in Down/Up for the same\n // meaning — so the pair is one axis's spelling of an order, and the order\n // reverses with the writing direction. Read from the controller element: the\n // container is what lays the items out, and a child may carry its own `dir`\n // (an LTR input inside an RTL form is ordinary authoring).\n // Only the horizontal pair reverses; `orientation=\"both\"` keeps Down/Up as-is.\n const rtl = horizontal && isRtl(this.element);\n const forwardKey = rtl ? \"ArrowLeft\" : \"ArrowRight\";\n const backwardKey = rtl ? \"ArrowRight\" : \"ArrowLeft\";\n\n let next: number;\n if ((horizontal && event.key === forwardKey) || (vertical && event.key === \"ArrowDown\")) {\n next = rovingMove(current, length, 1, wrap);\n } else if ((horizontal && event.key === backwardKey) || (vertical && event.key === \"ArrowUp\")) {\n next = rovingMove(current, length, -1, wrap);\n } else if (this.homeEndValue && event.key === \"Home\") {\n next = 0;\n } else if (this.homeEndValue && event.key === \"End\") {\n next = length - 1;\n } else {\n return;\n }\n\n event.preventDefault();\n this.#activate(next, true);\n };\n\n /**\n * Syncs the single tab stop to an item that received focus by other means\n * (click, programmatic `focus()`), so returning via Tab lands on it. The\n * keyboard path's own `focus()` re-enters here but is a no-op (index unchanged).\n */\n readonly #onFocusin = (event: FocusEvent): void => {\n const index = this.#indexOf(event.target);\n if (index !== -1) this.#activate(index, false);\n };\n\n /** Resolves the item index owning an event target (the item or a descendant). */\n #indexOf(target: EventTarget | null): number {\n const node = target as Node | null;\n if (!node) return -1;\n return this.itemTargets.findIndex((item) => item === node || item.contains(node));\n }\n\n /** Makes `index` the tab stop (optionally focusing it), emitting `change` once. */\n #activate(index: number, focus: boolean): void {\n const previous = this.#roving.activeIndex;\n this.#roving.setActive(index, { focus });\n if (index !== previous) {\n this.dispatch(\"change\", { detail: { index, item: this.itemTargets[index] } });\n }\n }\n}\n"]}
@@ -72,6 +72,33 @@ function logicalScrollMetrics(element, horizontal) {
72
72
  return { position: Math.min(max, Math.max(0, position)), max };
73
73
  }
74
74
 
75
+ // src/utils/tabindex_loan.ts
76
+ var TabindexLoan = class {
77
+ #value;
78
+ #lent = /* @__PURE__ */ new Set();
79
+ /**
80
+ * @param value - the `tabindex` to lend. `"-1"` (the default) is
81
+ * programmatically focusable but not a Tab stop; `"0"` is a real Tab stop,
82
+ * which a scroll region with no focusable content of its own needs.
83
+ */
84
+ constructor(value = "-1") {
85
+ this.#value = value;
86
+ }
87
+ /** Lends `element` the value; no-ops when it already carries a `tabindex`. */
88
+ lend(element) {
89
+ if (element.hasAttribute("tabindex")) return;
90
+ element.setAttribute("tabindex", this.#value);
91
+ this.#lent.add(element);
92
+ }
93
+ /** Takes back every loan whose value is still the one that was lent. */
94
+ returnAll() {
95
+ for (const element of this.#lent) {
96
+ if (element.getAttribute("tabindex") === this.#value) element.removeAttribute("tabindex");
97
+ }
98
+ this.#lent.clear();
99
+ }
100
+ };
101
+
75
102
  // src/controllers/scroll_area_controller.ts
76
103
  var FOCUSABLE_SELECTOR = [
77
104
  "a[href]",
@@ -90,10 +117,12 @@ var ScrollAreaController = class extends Controller {
90
117
  };
91
118
  static events = ["reach"];
92
119
  #layout = new LayoutObserver(() => this.#update());
120
+ /** Re-checks the tab stop when the viewport's focusable content comes or goes. */
121
+ #content = null;
93
122
  /** Last edge reported via `reach`, so the event fires once per arrival. */
94
123
  #lastEdge = null;
95
124
  /** Whether this controller added `tabindex`, so teardown only removes its own. */
96
- #addedTabindex = false;
125
+ #tabindex = new TabindexLoan("0");
97
126
  /** Whether this controller added `role="region"`, for symmetric teardown. */
98
127
  #addedRole = false;
99
128
  #onScroll = () => {
@@ -104,6 +133,18 @@ var ScrollAreaController = class extends Controller {
104
133
  this.viewportTarget.addEventListener("scroll", this.#onScroll, { passive: true });
105
134
  this.#layout.observe(this.viewportTarget);
106
135
  this.#layout.observeViewport();
136
+ if (typeof MutationObserver !== "undefined") {
137
+ this.#content = new MutationObserver(() => {
138
+ if (!this.hasViewportTarget) return;
139
+ const vp = this.viewportTarget;
140
+ this.#syncKeyboardReach(vp, this.#syncOverflow(vp));
141
+ });
142
+ this.#content.observe(this.viewportTarget, {
143
+ subtree: true,
144
+ childList: true,
145
+ attributes: true
146
+ });
147
+ }
107
148
  this.#update();
108
149
  }
109
150
  disconnect() {
@@ -112,14 +153,15 @@ var ScrollAreaController = class extends Controller {
112
153
  this.#clearAddedAttributes(this.viewportTarget);
113
154
  }
114
155
  this.#layout.disconnect();
156
+ this.#content?.disconnect();
157
+ this.#content = null;
115
158
  this.#lastEdge = null;
116
159
  }
117
160
  /** Re-measures overflow and scroll position and reflects the state hooks. */
118
161
  #update() {
119
162
  if (!this.hasViewportTarget) return;
120
163
  const vp = this.viewportTarget;
121
- const overflowing = this.#measureOverflow(vp);
122
- this.element.setAttribute("data-overflow", overflowing ? "true" : "false");
164
+ const overflowing = this.#syncOverflow(vp);
123
165
  this.#syncKeyboardReach(vp, overflowing);
124
166
  const { position, progress } = this.#measurePosition(vp);
125
167
  this.element.setAttribute("data-scroll", position);
@@ -133,6 +175,21 @@ var ScrollAreaController = class extends Controller {
133
175
  }
134
176
  }
135
177
  /** Whether the viewport can scroll on the configured axis. */
178
+ /**
179
+ * Measures overflow and reflects the `data-overflow` hook.
180
+ *
181
+ * The write is skipped when the value is unchanged. An identical `setAttribute` still
182
+ * queues a MutationRecord, and markup that puts the viewport target on the controller
183
+ * element itself would then have the content observer trigger its own next callback.
184
+ */
185
+ #syncOverflow(vp) {
186
+ const overflowing = this.#measureOverflow(vp);
187
+ const next = overflowing ? "true" : "false";
188
+ if (this.element.getAttribute("data-overflow") !== next) {
189
+ this.element.setAttribute("data-overflow", next);
190
+ }
191
+ return overflowing;
192
+ }
136
193
  #measureOverflow(vp) {
137
194
  const o = this.orientationValue;
138
195
  const vertical = o !== "horizontal" && vp.scrollHeight > vp.clientHeight + EDGE_EPSILON;
@@ -160,10 +217,7 @@ var ScrollAreaController = class extends Controller {
160
217
  #syncKeyboardReach(vp, overflowing) {
161
218
  const wantsTabindex = overflowing && !this.#hasFocusableContent(vp);
162
219
  if (wantsTabindex) {
163
- if (!vp.hasAttribute("tabindex")) {
164
- vp.setAttribute("tabindex", "0");
165
- this.#addedTabindex = true;
166
- }
220
+ this.#tabindex.lend(vp);
167
221
  if (!vp.hasAttribute("role") && this.#hasAccessibleName(vp)) {
168
222
  vp.setAttribute("role", "region");
169
223
  this.#addedRole = true;
@@ -174,17 +228,37 @@ var ScrollAreaController = class extends Controller {
174
228
  }
175
229
  /** Removes (and resets the flags for) only the attributes this controller added. */
176
230
  #clearAddedAttributes(vp) {
177
- if (this.#addedTabindex) {
178
- vp.removeAttribute("tabindex");
179
- this.#addedTabindex = false;
180
- }
231
+ this.#tabindex.returnAll();
181
232
  if (this.#addedRole) {
182
233
  vp.removeAttribute("role");
183
234
  this.#addedRole = false;
184
235
  }
185
236
  }
237
+ /**
238
+ * Whether the viewport owns something the user can Tab to *right now*.
239
+ *
240
+ * The selector alone is not enough: a `display: none` button still matches it,
241
+ * so a viewport whose only control is revealed on demand would never get a tab
242
+ * stop — leaving it unreachable by keyboard exactly while it has nothing else to
243
+ * offer. Only rendered candidates count.
244
+ */
186
245
  #hasFocusableContent(vp) {
187
- return vp.querySelector(FOCUSABLE_SELECTOR) !== null;
246
+ return Array.from(vp.querySelectorAll(FOCUSABLE_SELECTOR)).some(
247
+ (el) => this.#isRendered(el)
248
+ );
249
+ }
250
+ /**
251
+ * Whether `el` is actually rendered, and so can hold focus.
252
+ *
253
+ * `checkVisibility()` answers this for every way CSS can remove a box, including
254
+ * a class-driven `display: none` that no attribute reveals. The `hidden` walk in
255
+ * front of it is not redundant: it is the one case a DOM-only environment with no
256
+ * layout engine has to be told about explicitly.
257
+ */
258
+ #isRendered(el) {
259
+ if (el.closest("[hidden]") !== null) return false;
260
+ const check = el.checkVisibility;
261
+ return typeof check === "function" ? check.call(el, { visibilityProperty: true }) : true;
188
262
  }
189
263
  #hasAccessibleName(vp) {
190
264
  return vp.hasAttribute("aria-label") || vp.hasAttribute("aria-labelledby");