stimeo-ui 0.9.0 → 0.10.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 (152) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist/controllers/accordion_controller.js.map +1 -1
  3. package/dist/controllers/alert_dialog_controller.js +17 -7
  4. package/dist/controllers/alert_dialog_controller.js.map +1 -1
  5. package/dist/controllers/announcer_controller.js +1 -1
  6. package/dist/controllers/announcer_controller.js.map +1 -1
  7. package/dist/controllers/auto_submit_controller.js.map +1 -1
  8. package/dist/controllers/avatar_controller.js.map +1 -1
  9. package/dist/controllers/breadcrumb_controller.js.map +1 -1
  10. package/dist/controllers/bulk_select_controller.js +2 -2
  11. package/dist/controllers/bulk_select_controller.js.map +1 -1
  12. package/dist/controllers/calendar_controller.js.map +1 -1
  13. package/dist/controllers/carousel_controller.js.map +1 -1
  14. package/dist/controllers/character_counter_controller.js.map +1 -1
  15. package/dist/controllers/clipboard_controller.js.map +1 -1
  16. package/dist/controllers/collapsible_controller.d.ts +1 -1
  17. package/dist/controllers/collapsible_controller.js +1 -1
  18. package/dist/controllers/collapsible_controller.js.map +1 -1
  19. package/dist/controllers/color_picker_controller.d.ts +1 -1
  20. package/dist/controllers/color_picker_controller.js.map +1 -1
  21. package/dist/controllers/combobox_controller.js.map +1 -1
  22. package/dist/controllers/command_palette_controller.js +15 -5
  23. package/dist/controllers/command_palette_controller.js.map +1 -1
  24. package/dist/controllers/conditional_fields_controller.js.map +1 -1
  25. package/dist/controllers/confirm_controller.js +15 -5
  26. package/dist/controllers/confirm_controller.js.map +1 -1
  27. package/dist/controllers/context_menu_controller.d.ts +5 -4
  28. package/dist/controllers/context_menu_controller.js.map +1 -1
  29. package/dist/controllers/count_up_controller.js.map +1 -1
  30. package/dist/controllers/countdown_controller.js +1 -1
  31. package/dist/controllers/countdown_controller.js.map +1 -1
  32. package/dist/controllers/data_grid_controller.js +1 -1
  33. package/dist/controllers/data_grid_controller.js.map +1 -1
  34. package/dist/controllers/date_range_picker_controller.js.map +1 -1
  35. package/dist/controllers/dialog_controller.js +15 -5
  36. package/dist/controllers/dialog_controller.js.map +1 -1
  37. package/dist/controllers/direct_upload_controller.d.ts +2 -2
  38. package/dist/controllers/direct_upload_controller.js +1 -5
  39. package/dist/controllers/direct_upload_controller.js.map +1 -1
  40. package/dist/controllers/dismissible_controller.js.map +1 -1
  41. package/dist/controllers/drawer_controller.d.ts +2 -2
  42. package/dist/controllers/drawer_controller.js +17 -7
  43. package/dist/controllers/drawer_controller.js.map +1 -1
  44. package/dist/controllers/file_dropzone_controller.js.map +1 -1
  45. package/dist/controllers/flash_controller.js.map +1 -1
  46. package/dist/controllers/focus_controller.d.ts +5 -0
  47. package/dist/controllers/focus_controller.js +45 -7
  48. package/dist/controllers/focus_controller.js.map +1 -1
  49. package/dist/controllers/form_field_controller.js +1 -1
  50. package/dist/controllers/form_field_controller.js.map +1 -1
  51. package/dist/controllers/form_validation_controller.js.map +1 -1
  52. package/dist/controllers/frame_loading_controller.js.map +1 -1
  53. package/dist/controllers/highlight_controller.js.map +1 -1
  54. package/dist/controllers/input_mask_controller.js.map +1 -1
  55. package/dist/controllers/intersection_controller.d.ts +4 -3
  56. package/dist/controllers/intersection_controller.js.map +1 -1
  57. package/dist/controllers/lazy_frame_controller.d.ts +2 -2
  58. package/dist/controllers/lazy_frame_controller.js.map +1 -1
  59. package/dist/controllers/listbox_controller.js.map +1 -1
  60. package/dist/controllers/masonry_controller.d.ts +3 -1
  61. package/dist/controllers/masonry_controller.js.map +1 -1
  62. package/dist/controllers/menu_controller.d.ts +1 -1
  63. package/dist/controllers/menu_controller.js.map +1 -1
  64. package/dist/controllers/menubar_controller.js +2 -2
  65. package/dist/controllers/menubar_controller.js.map +1 -1
  66. package/dist/controllers/meter_controller.d.ts +1 -1
  67. package/dist/controllers/meter_controller.js.map +1 -1
  68. package/dist/controllers/multi_select_controller.js +1 -1
  69. package/dist/controllers/multi_select_controller.js.map +1 -1
  70. package/dist/controllers/navigation_menu_controller.js.map +1 -1
  71. package/dist/controllers/nested_form_controller.js.map +1 -1
  72. package/dist/controllers/number_input_controller.js.map +1 -1
  73. package/dist/controllers/otp_controller.js.map +1 -1
  74. package/dist/controllers/overflow_indicator_controller.js.map +1 -1
  75. package/dist/controllers/overflow_menu_controller.js +2 -2
  76. package/dist/controllers/overflow_menu_controller.js.map +1 -1
  77. package/dist/controllers/pagination_controller.d.ts +1 -1
  78. package/dist/controllers/pagination_controller.js.map +1 -1
  79. package/dist/controllers/password_reveal_controller.d.ts +27 -2
  80. package/dist/controllers/password_reveal_controller.js +102 -3
  81. package/dist/controllers/password_reveal_controller.js.map +1 -1
  82. package/dist/controllers/password_strength_controller.d.ts +71 -17
  83. package/dist/controllers/password_strength_controller.js +287 -42
  84. package/dist/controllers/password_strength_controller.js.map +1 -1
  85. package/dist/controllers/pointer_drag_controller.d.ts +3 -2
  86. package/dist/controllers/pointer_drag_controller.js.map +1 -1
  87. package/dist/controllers/popover_controller.js.map +1 -1
  88. package/dist/controllers/portal_controller.d.ts +1 -1
  89. package/dist/controllers/portal_controller.js.map +1 -1
  90. package/dist/controllers/progress_controller.js.map +1 -1
  91. package/dist/controllers/radio_group_controller.js.map +1 -1
  92. package/dist/controllers/range_slider_controller.js.map +1 -1
  93. package/dist/controllers/rating_controller.js.map +1 -1
  94. package/dist/controllers/read_more_controller.js.map +1 -1
  95. package/dist/controllers/relative_time_controller.js.map +1 -1
  96. package/dist/controllers/reset_before_cache_controller.d.ts +1 -2
  97. package/dist/controllers/reset_before_cache_controller.js.map +1 -1
  98. package/dist/controllers/resizable_controller.d.ts +1 -1
  99. package/dist/controllers/resizable_controller.js +1 -1
  100. package/dist/controllers/resizable_controller.js.map +1 -1
  101. package/dist/controllers/roving_controller.d.ts +2 -1
  102. package/dist/controllers/roving_controller.js.map +1 -1
  103. package/dist/controllers/scroll_area_controller.js.map +1 -1
  104. package/dist/controllers/scroll_restore_controller.d.ts +33 -11
  105. package/dist/controllers/scroll_restore_controller.js +127 -27
  106. package/dist/controllers/scroll_restore_controller.js.map +1 -1
  107. package/dist/controllers/scroll_visibility_controller.d.ts +42 -10
  108. package/dist/controllers/scroll_visibility_controller.js +167 -14
  109. package/dist/controllers/scroll_visibility_controller.js.map +1 -1
  110. package/dist/controllers/scrollspy_controller.js.map +1 -1
  111. package/dist/controllers/separator_controller.js.map +1 -1
  112. package/dist/controllers/sidebar_controller.js +15 -5
  113. package/dist/controllers/sidebar_controller.js.map +1 -1
  114. package/dist/controllers/skeleton_controller.js.map +1 -1
  115. package/dist/controllers/slider_controller.js.map +1 -1
  116. package/dist/controllers/spinner_controller.js.map +1 -1
  117. package/dist/controllers/step_indicator_controller.js +0 -5
  118. package/dist/controllers/step_indicator_controller.js.map +1 -1
  119. package/dist/controllers/stick_to_bottom_controller.d.ts +3 -2
  120. package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
  121. package/dist/controllers/submit_once_controller.js.map +1 -1
  122. package/dist/controllers/switch_controller.js.map +1 -1
  123. package/dist/controllers/tabs_controller.js.map +1 -1
  124. package/dist/controllers/tags_input_controller.js.map +1 -1
  125. package/dist/controllers/textarea_autosize_controller.js.map +1 -1
  126. package/dist/controllers/theme_controller.d.ts +32 -6
  127. package/dist/controllers/theme_controller.js +151 -40
  128. package/dist/controllers/theme_controller.js.map +1 -1
  129. package/dist/controllers/time_picker_controller.js.map +1 -1
  130. package/dist/controllers/toast_controller.d.ts +2 -2
  131. package/dist/controllers/toast_controller.js +2 -2
  132. package/dist/controllers/toast_controller.js.map +1 -1
  133. package/dist/controllers/toggle_group_controller.js.map +1 -1
  134. package/dist/controllers/toolbar_controller.js.map +1 -1
  135. package/dist/controllers/transition_controller.d.ts +11 -7
  136. package/dist/controllers/transition_controller.js +79 -15
  137. package/dist/controllers/transition_controller.js.map +1 -1
  138. package/dist/controllers/tree_view_controller.js.map +1 -1
  139. package/dist/index.d.ts +6 -3
  140. package/dist/index.js +740 -178
  141. package/dist/index.js.map +1 -1
  142. package/dist/inspector/cli.d.ts +3 -4
  143. package/dist/inspector/cli.js +1 -0
  144. package/dist/inspector/cli.js.map +1 -1
  145. package/dist/inspector/cli_bin.js +6 -5
  146. package/dist/inspector/cli_bin.js.map +1 -1
  147. package/dist/inspector/examples.json +3 -3
  148. package/dist/inspector/manifest.json +7 -4
  149. package/dist/positioning/index.d.ts +18 -4
  150. package/dist/positioning/index.js +84 -25
  151. package/dist/positioning/index.js.map +1 -1
  152. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/reduced_motion.ts","../../src/utils/before_cache_reset.ts","../../src/utils/tabindex_loan.ts","../../src/controllers/scroll_visibility_controller.ts"],"names":[],"mappings":";;;;;AAmBO,SAAS,oBAAA,GAAgC;AAC9C,EAAA,OACE,OAAO,MAAA,CAAO,UAAA,KAAe,cAC7B,MAAA,CAAO,UAAA,CAAW,kCAAkC,CAAA,CAAE,OAAA;AAE1D;;;ACmBO,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,OAAA,EAAQ;AAAA,EAC7E,CAAA;AAAA,EAES,OAAA;AAAA;AAAA,EAGT,YAAY,MAAA,EAAoB;AAC9B,IAAA,IAAA,CAAK,OAAA,GAAU,MAAA;AAAA,EACjB;AAAA;AAAA,EAGA,QAAA,GAAiB;AACf,IAAA,MAAM,KAAA,GAAQ,iBAAA,CAAiB,YAAA,CAAa,IAAA,KAAS,CAAA;AACrD,IAAA,iBAAA,CAAiB,YAAA,CAAa,IAAI,IAAI,CAAA;AACtC,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,QAAA,CAAS,gBAAA,CAAiB,oBAAA,EAAsB,iBAAA,CAAiB,cAAc,CAA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e,CAAA;AACpB,IAAA,IAAA,CAAK,YAAY,WAAW,CAAA;AAAA,EAC9B;AAAA;AAAA,EAGA,YAAY,IAAA,EAAqB;AAC/B,IAAA,IAAI,IAAA,KAAS,KAAK,QAAA,EAAU;AAC5B,IAAA,IAAA,CAAK,QAAA,GAAW,IAAA;AAChB,IAAA,IAAI,IAAA,CAAK,gBAAA,EAAkB,IAAA,CAAK,aAAA,CAAc,SAAS,CAAC,IAAA;AACxD,IAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,YAAA,EAAc,IAAA,GAAO,YAAY,QAAQ,CAAA;AACnE,IAAA,IAAA,CAAK,QAAA,CAAS,UAAU,EAAE,MAAA,EAAQ,EAAE,OAAA,EAAS,IAAA,IAAQ,CAAA;AAAA,EACvD;AAAA;AAAA,EAGA,oBAAA,GAA6C;AAC3C,IAAA,IAAI,KAAK,SAAA,EAAW;AAClB,MAAA,MAAM,IAAA,GAAO,QAAA,CAAS,aAAA,CAA2B,IAAA,CAAK,SAAS,CAAA;AAC/D,MAAA,IAAI,MAAM,OAAO,IAAA;AAAA,IACnB;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AAAA,EAEA,QAAA,GAAmB;AACjB,IAAA,IAAI,IAAA,CAAK,kBAAkB,MAAA,EAAQ;AACjC,MAAA,OAAO,MAAA,CAAO,OAAA,IAAW,MAAA,CAAO,WAAA,IAAe,CAAA;AAAA,IACjD;AACA,IAAA,OAAQ,KAAK,aAAA,CAA8B,SAAA;AAAA,EAC7C;AACF","file":"scroll_visibility_controller.js","sourcesContent":["/**\n * Shared `prefers-reduced-motion` lookup for the motion-aware controllers\n * (count-up, highlight, overflow-indicator, scroll-visibility, stick-to-bottom,\n * transition).\n *\n * This one-liner keeps the media query string and the environment guard\n * single-sourced across them. The preference is intentionally re-read on every\n * call — the controllers check it at each animation/scroll start (WCAG 2.2\n * **2.3.3**), so flipping the OS setting takes effect immediately without any\n * listener or cache bookkeeping here.\n */\n\n/**\n * Whether the user currently requests reduced motion.\n *\n * @returns `true` when `(prefers-reduced-motion: reduce)` matches; `false`\n * otherwise, including environments without `window.matchMedia` (treated as\n * \"no preference\").\n */\nexport function prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n}\n","/**\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","import { BeforeCacheReset } from \"./before_cache_reset\";\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 * Every live loan also owns a shared `turbo:before-cache` subscription. The loan\n * is returned before Turbo can copy it into a snapshot, so consumers get cache\n * safety without duplicating a lifecycle hook; `returnAll()` removes the\n * subscription again as soon as no loan remains.\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 /** Returns live loans before Turbo can copy them into its page snapshot. */\n readonly #beforeCache = new BeforeCacheReset(() => this.returnAll());\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 // Subscribe only while a real loan exists. Keeping this guarantee here means\n // every consumer is Turbo-safe without another lifecycle hook to remember.\n this.#beforeCache.activate();\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 this.#beforeCache.deactivate();\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { prefersReducedMotion } from \"../utils/reduced_motion\";\nimport { TabindexLoan } from \"../utils/tabindex_loan\";\n\n/**\n * Headless **Scroll Visibility** behavior: shows or hides an element based on\n * scroll amount or direction (back-to-top buttons, hide-on-scroll headers). No\n * dedicated APG pattern; when the element is a button it follows the Button\n * practice.\n *\n * Markup contract (identifier: `stimeo--scroll-visibility`):\n * <div data-controller=\"stimeo--scroll-visibility\"\n * data-stimeo--scroll-visibility-offset-value=\"400\"\n * data-stimeo--scroll-visibility-mode-value=\"offset\">\n * <button type=\"button\" hidden\n * data-stimeo--scroll-visibility-target=\"element\"\n * data-action=\"stimeo--scroll-visibility#toTop\">Back to top</button>\n * </div>\n *\n * In `offset` mode the element is shown once the scroll source is scrolled past\n * `offset` px; in `direction` mode it is hidden while scrolling down and shown\n * while scrolling up. Visibility is reflected through the `hidden` attribute (so a\n * hidden control also leaves the focus order) and `data-state`.\n *\n * By default the **window** is the scroll source. When the page itself does not\n * scroll — e.g. a fixed-height app shell whose main column scrolls in a container\n * (`overflow: auto`) — point `root` at that container (a CSS selector) so the\n * controller observes the element's scroll instead of the (never-scrolling)\n * window. `toTop` then scrolls that same container.\n *\n * `change` dispatches `{ visible: boolean }`.\n *\n * @remarks\n * Behavior only — the look and any transition are the consumer's CSS. The scroll\n * listener is `passive`, coalesced through `requestAnimationFrame`, and removed on\n * `disconnect()` (Turbo navigation included). `toTop` honors\n * `prefers-reduced-motion` by forcing an instant jump independently of the\n * consumer's CSS `scroll-behavior`, and can move focus to a `focusSelector`\n * target (given `tabindex=\"-1\"` if needed) to keep keyboard users oriented\n * after the scroll. A live disconnect removes only a `tabindex=\"-1\"` this\n * controller instance added; authored tabindex values remain. This teardown does\n * not claim to rewrite a Turbo cache snapshot that was cloned before disconnect.\n */\nexport class ScrollVisibilityController extends Controller<HTMLElement> {\n static override targets = [\"element\"];\n static override values = {\n offset: { type: Number, default: 400 },\n mode: { type: String, default: \"offset\" },\n focusSelector: { type: String, default: \"\" },\n root: { type: String, default: \"\" },\n };\n static actions = [\"toTop\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly elementTarget: HTMLElement;\n declare readonly hasElementTarget: boolean;\n\n declare offsetValue: number;\n declare modeValue: string;\n declare focusSelectorValue: string;\n declare rootValue: string;\n\n /** Pending rAF id that coalesces scroll bursts into one measurement. */\n #rafId: number | null = null;\n /** Previous scroll position, for `direction` mode delta detection. */\n #lastScrollY = 0;\n /** Current visibility, tracked to dispatch `change` only on real transitions. */\n #visible: boolean | null = null;\n /**\n * The observed scroll source: a container element when `root` resolves, else\n * the window. Captured on connect so teardown detaches from the same source.\n */\n #scrollSource: HTMLElement | Window = window;\n /** Focus targets this instance lent a `tabindex` to. */\n readonly #tabindex = new TabindexLoan();\n\n readonly #onScroll = (): void => {\n if (this.#rafId !== null) return;\n this.#rafId = requestAnimationFrame(() => {\n this.#rafId = null;\n this.#evaluate();\n });\n };\n\n override connect(): void {\n this.#scrollSource = this.#resolveScrollSource();\n this.#lastScrollY = this.#scrollY();\n this.#scrollSource.addEventListener(\"scroll\", this.#onScroll, { passive: true });\n this.#evaluate();\n }\n\n override disconnect(): void {\n this.#scrollSource.removeEventListener(\"scroll\", this.#onScroll);\n if (this.#rafId !== null) {\n cancelAnimationFrame(this.#rafId);\n this.#rafId = null;\n }\n this.#tabindex.returnAll();\n this.#visible = null;\n }\n\n /** Scrolls the source to the top and, optionally, moves focus to a safe target. */\n toTop(): void {\n const behavior: ScrollBehavior = prefersReducedMotion() ? \"instant\" : \"smooth\";\n this.#scrollSource.scrollTo({ top: 0, behavior });\n if (this.focusSelectorValue) {\n const target = document.querySelector<HTMLElement>(this.focusSelectorValue);\n if (target) {\n this.#tabindex.lend(target);\n target.focus();\n }\n }\n }\n\n /** Decides the next visibility from the current scroll state and applies it. */\n #evaluate(): void {\n const y = this.#scrollY();\n let nextVisible: boolean;\n if (this.modeValue === \"direction\") {\n // Near the very top, always reveal so a hide-on-scroll header is never\n // stranded off-screen when the page cannot scroll up any further.\n if (y <= this.offsetValue) {\n nextVisible = true;\n } else {\n nextVisible = y < this.#lastScrollY; // scrolling up reveals, down hides\n }\n } else {\n nextVisible = y > this.offsetValue;\n }\n this.#lastScrollY = y;\n this.#setVisible(nextVisible);\n }\n\n /** Applies visibility to the target, syncing `hidden`, `data-state`, `change`. */\n #setVisible(next: boolean): void {\n if (next === this.#visible) return;\n this.#visible = next;\n if (this.hasElementTarget) this.elementTarget.hidden = !next;\n this.element.setAttribute(\"data-state\", next ? \"visible\" : \"hidden\");\n this.dispatch(\"change\", { detail: { visible: next } });\n }\n\n /** Resolves the scroll source from `root` (falling back to the window). */\n #resolveScrollSource(): HTMLElement | Window {\n if (this.rootValue) {\n const root = document.querySelector<HTMLElement>(this.rootValue);\n if (root) return root;\n }\n return window;\n }\n\n #scrollY(): number {\n if (this.#scrollSource === window) {\n return window.scrollY ?? window.pageYOffset ?? 0;\n }\n return (this.#scrollSource as HTMLElement).scrollTop;\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/blur_deferral.ts","../../src/utils/reduced_motion.ts","../../src/utils/before_cache_reset.ts","../../src/utils/tabindex_loan.ts","../../src/controllers/scroll_visibility_controller.ts"],"names":[],"mappings":";;;;;AAoDO,IAAM,eAAN,MAAwD;AAAA;AAAA,EAEpD,QAAA,uBAAe,GAAA,EAAmB;AAAA;AAAA,EAElC,UAAA;AAAA;AAAA,EAGT,YAAY,SAAA,EAAiC;AAC3C,IAAA,IAAA,CAAK,UAAA,GAAa,SAAA;AAAA,EACpB;AAAA;AAAA,EAGA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,KAAK,QAAA,CAAS,IAAA;AAAA,EACvB;AAAA;AAAA,EAGA,IAAI,QAAA,GAAgB;AAClB,IAAA,OAAO,CAAC,GAAG,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA;AAAA,EACjC;AAAA;AAAA,EAGA,IAAI,OAAA,EAAqB;AACvB,IAAA,OAAO,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,OAAO,CAAA;AAAA,EAClC;AAAA;AAAA,EAGA,MAAM,OAAA,EAAkB;AACtB,IAAA,IAAI,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,OAAO,CAAA,EAAG;AAChC,IAAA,MAAM,SAAS,MAAY;AACzB,MAAA,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AO,WAAA,IAAe,CAAA;AAAA,IACjD;AACA,IAAA,OAAQ,KAAK,aAAA,CAA8B,SAAA;AAAA,EAC7C;AACF","file":"scroll_visibility_controller.js","sourcesContent":["/**\n * Shared bookkeeping for updates that must wait until an element loses focus.\n *\n * A control that becomes redundant while the user is standing on it cannot be\n * removed from the page immediately: hiding a focused element (or turning it\n * into a native `disabled` one) drops focus to `<body>`, stranding a keyboard\n * user mid-widget. The fix every affected controller reached for is the same —\n * keep the element reachable, hold the destructive update, listen for `blur`,\n * and apply it then.\n *\n * {@link BlurDeferral} owns *only* the registry part of that: which elements are\n * currently holding an update back, attaching and detaching the `blur` listener,\n * and guaranteeing teardown. It is deliberately **policy-free** — what the\n * interim state looks like (`aria-disabled`, an ownership marker, nothing at\n * all), and what the deferred update actually is, stay in the controller, which\n * receives the element back through its release callback.\n *\n * Three contracts are worth stating up front, because each one is a hazard the\n * consumers would otherwise hit:\n *\n * - **The release callback fires only on a real `blur`.** `release()` /\n * `releaseAll()` *cancel* a deferral; they do not complete it. Conflating the\n * two makes `overflow-indicator` disable a button that just left the boundary.\n * - **`elements` is a snapshot.** Iterating the live key set while releasing\n * inside the loop is the failure this registry exists to prevent.\n * - **The entry is detached before the callback runs**, so a controller that\n * decides the update is still unsafe can simply defer again.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and contracts belong on the members.\n *\n * @example\n * ```ts\n * readonly #deferred = new BlurDeferral<HTMLElement>((trigger) => {\n * if (this.#connected) this.#evaluate();\n * });\n *\n * #hide(trigger: HTMLElement) {\n * if (document.activeElement === trigger) {\n * this.#deferred.deferOnly(trigger); // stays visible until blur\n * return;\n * }\n * this.#deferred.releaseAll();\n * trigger.hidden = true;\n * }\n *\n * disconnect() {\n * this.#deferred.releaseAll();\n * }\n * ```\n */\nexport class BlurDeferral<T extends HTMLElement = HTMLElement> {\n /** Elements currently holding an update back, mapped to their `blur` listener. */\n readonly #pending = new Map<T, () => void>();\n /** Called after a pending element blurs and has been detached. */\n readonly #onRelease: (element: T) => void;\n\n /** @param onRelease - Invoked once `element` actually blurs; never on `release`. */\n constructor(onRelease: (element: T) => void) {\n this.#onRelease = onRelease;\n }\n\n /** Number of elements currently holding an update back. */\n get size(): number {\n return this.#pending.size;\n }\n\n /** Snapshot of the pending elements, safe to iterate while releasing them. */\n get elements(): T[] {\n return [...this.#pending.keys()];\n }\n\n /** Whether `element` is currently holding an update back. */\n has(element: T): boolean {\n return this.#pending.has(element);\n }\n\n /** Holds an update back until `element` blurs. Idempotent (no stacked listeners). */\n defer(element: T): void {\n if (this.#pending.has(element)) return;\n const onBlur = (): void => {\n this.#detach(element);\n this.#onRelease(element);\n };\n this.#pending.set(element, onBlur);\n element.addEventListener(\"blur\", onBlur);\n }\n\n /** Defers `element` as the only pending entry, cancelling any others. */\n deferOnly(element: T): void {\n for (const pending of this.elements) {\n if (pending !== element) this.#detach(pending);\n }\n this.defer(element);\n }\n\n /** Cancels `element`'s deferral without completing it; no-ops when not pending. */\n release(element: T): void {\n this.#detach(element);\n }\n\n /** Cancels every deferral without completing any of them. */\n releaseAll(): void {\n for (const element of this.elements) this.#detach(element);\n }\n\n /** Removes the `blur` listener for `element` and forgets it. */\n #detach(element: T): void {\n const onBlur = this.#pending.get(element);\n if (onBlur) element.removeEventListener(\"blur\", onBlur);\n this.#pending.delete(element);\n }\n}\n","/**\n * Shared `prefers-reduced-motion` lookup for the motion-aware controllers\n *.\n *\n * This one-liner keeps the media query string and the environment guard\n * single-sourced across them. The preference is intentionally re-read on every\n * call — the controllers check it at each animation/scroll start (WCAG 2.2\n * **2.3.3**), so flipping the OS setting takes effect immediately without any\n * listener or cache bookkeeping here.\n */\n\n/**\n * Whether the user currently requests reduced motion.\n *\n * @returns `true` when `(prefers-reduced-motion: reduce)` matches; `false`\n * otherwise, including environments without `window.matchMedia` (treated as\n * \"no preference\").\n */\nexport function prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n}\n","/**\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.\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","import { BeforeCacheReset } from \"./before_cache_reset\";\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 * Every live loan also owns a shared `turbo:before-cache` subscription. The loan\n * is returned before Turbo can copy it into a snapshot, so consumers get cache\n * safety without duplicating a lifecycle hook; `returnAll()` removes the\n * subscription again as soon as no loan remains.\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 /** Returns live loans before Turbo can copy them into its page snapshot. */\n readonly #beforeCache = new BeforeCacheReset(() => this.returnAll());\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 // Subscribe only while a real loan exists. Keeping this guarantee here means\n // every consumer is Turbo-safe without another lifecycle hook to remember.\n this.#beforeCache.activate();\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 this.#beforeCache.deactivate();\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { BlurDeferral } from \"../utils/blur_deferral\";\nimport { prefersReducedMotion } from \"../utils/reduced_motion\";\nimport { TabindexLoan } from \"../utils/tabindex_loan\";\n\n/** Default scroll threshold in px, and what a non-finite declaration falls back to. */\nconst DEFAULT_OFFSET = 400;\n\n/**\n * Headless **Scroll Visibility** behavior: shows or hides an element based on\n * scroll amount or direction (back-to-top buttons, hide-on-scroll headers). No\n * dedicated APG pattern; when the element is a button it follows the Button\n * practice.\n *\n * Markup contract (identifier: `stimeo--scroll-visibility`):\n * <div data-controller=\"stimeo--scroll-visibility\"\n * data-stimeo--scroll-visibility-offset-value=\"400\"\n * data-stimeo--scroll-visibility-mode-value=\"offset\">\n * <button type=\"button\" hidden\n * data-stimeo--scroll-visibility-target=\"element\"\n * data-action=\"stimeo--scroll-visibility#toTop\">Back to top</button>\n * </div>\n *\n * In `offset` mode the element is shown once the scroll source is scrolled past\n * `offset` px; in `direction` mode it is hidden while scrolling down and shown\n * while scrolling up. A `scroll` that carries no vertical movement — a\n * horizontal scroll, an overscroll bounce — has no direction, so `direction`\n * mode leaves the current visibility alone. Visibility is reflected through the\n * `hidden` attribute (so a hidden control also leaves the focus order) and\n * `data-state`.\n *\n * By default the **window** is the scroll source. When the page itself does not\n * scroll — e.g. a fixed-height app shell whose main column scrolls in a container\n * (`overflow: auto`) — point `root` at that container (a CSS selector) so the\n * controller observes the element's scroll instead of the (never-scrolling)\n * window. `toTop` then scrolls that same container.\n *\n * `change` dispatches `{ visible: boolean }` on transitions only: connecting\n * reflects the current scroll state onto the hooks without announcing it, so a\n * Turbo restore does not replay the state the snapshot already carries.\n *\n * @remarks\n * Behavior only — the look and any transition are the consumer's CSS. The scroll\n * listener is `passive`, coalesced through `requestAnimationFrame`, and removed on\n * `disconnect()` (Turbo navigation included). `offset` / `mode` are re-read at\n * runtime, so a Turbo morph that swaps either attribute is followed without\n * waiting for the next scroll; a selector (`root`, `focusSelector`) or a\n * threshold that cannot be parsed reads as its default, keeping the rest of the\n * element alive. **A scroll never hides the control while it owns focus**: that\n * hide waits for it to blur and is decided again from the scroll position at that\n * moment. `toTop` honors `prefers-reduced-motion` by forcing an\n * instant jump independently of the consumer's CSS `scroll-behavior`, and can\n * move focus to a `focusSelector` target (given `tabindex=\"-1\"` if needed, and\n * focused without scrolling so the smooth scroll survives) to keep keyboard\n * users oriented after the scroll. A live disconnect removes only a\n * `tabindex=\"-1\"` this controller instance added; authored tabindex values\n * remain. This teardown does not claim to rewrite a Turbo cache snapshot that\n * was cloned before disconnect.\n */\nexport class ScrollVisibilityController extends Controller<HTMLElement> {\n static override targets = [\"element\"];\n static override values = {\n offset: { type: Number, default: DEFAULT_OFFSET },\n mode: { type: String, default: \"offset\" },\n focusSelector: { type: String, default: \"\" },\n root: { type: String, default: \"\" },\n };\n static actions = [\"toTop\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly elementTarget: HTMLElement;\n declare readonly hasElementTarget: boolean;\n\n declare offsetValue: number;\n declare modeValue: string;\n declare focusSelectorValue: string;\n declare rootValue: string;\n\n /** Pending rAF id that coalesces scroll bursts into one measurement. */\n #rafId: number | null = null;\n /** Previous scroll position, for `direction` mode delta detection. */\n #lastScrollY = 0;\n /** Current visibility, tracked to dispatch `change` only on real transitions. */\n #visible: boolean | null = null;\n /**\n * The observed scroll source: a container element when `root` resolves, else\n * the window. Captured on connect so teardown detaches from the same source.\n */\n #scrollSource: HTMLElement | Window = window;\n /**\n * Gates the declaration callbacks to the connected window.\n *\n * Stimulus delivers a Value callback ahead of `connect()` and again for every\n * runtime change; without the gate, merely connecting would evaluate — and\n * announce — before `connect()` runs its own first reflection.\n */\n #connected = false;\n /** Validated threshold; a non-finite declaration reads as the default. */\n #offset = DEFAULT_OFFSET;\n /** Validated `root` selector; an unparsable declaration reads as absent. */\n #rootSelector = \"\";\n /** Validated `focusSelector`; an unparsable declaration reads as absent. */\n #focusSelector = \"\";\n /** Focus targets this instance lent a `tabindex` to. */\n readonly #tabindex = new TabindexLoan();\n /**\n * The hide held back while the control itself owns focus.\n *\n * Completing the deferral re-runs the ordinary evaluation rather than applying\n * the stale decision: by the time focus leaves, the scroll position may have\n * moved back past the threshold.\n */\n readonly #pendingHide = new BlurDeferral((): void => {\n if (this.#connected) this.#evaluate();\n });\n\n readonly #onScroll = (): void => {\n if (this.#rafId !== null) return;\n this.#rafId = requestAnimationFrame(() => {\n this.#rafId = null;\n this.#evaluate();\n });\n };\n\n override connect(): void {\n this.#scrollSource = this.#resolveScrollSource();\n this.#lastScrollY = this.#scrollY();\n this.#scrollSource.addEventListener(\"scroll\", this.#onScroll, { passive: true });\n this.#evaluate(false);\n this.#connected = true;\n }\n\n override disconnect(): void {\n this.#connected = false;\n this.#scrollSource.removeEventListener(\"scroll\", this.#onScroll);\n if (this.#rafId !== null) {\n cancelAnimationFrame(this.#rafId);\n this.#rafId = null;\n }\n this.#pendingHide.releaseAll();\n this.#tabindex.returnAll();\n this.#visible = null;\n }\n\n /** Writes the current visibility onto a control that arrives after connect. */\n elementTargetConnected(element: HTMLElement): void {\n if (this.#visible !== null) element.hidden = !this.#visible;\n }\n\n /** Drops a held-back hide together with the control it was waiting on. */\n elementTargetDisconnected(): void {\n // At most one hide is ever held back, and it rides an element inside the\n // target — the focus owner, which may be a descendant rather than the\n // target itself. Losing the target ends that wait either way.\n this.#pendingHide.releaseAll();\n }\n\n /**\n * Validates `offset` once, then re-renders.\n *\n * Re-renders when application code (or a Turbo morph) changes `offset` at\n * runtime. A declaration that is not a finite number reads as the default, so\n * the comparison path never sees `NaN` — which would answer `false` to every\n * comparison and strand the element (in `direction` mode, even the guarantee\n * that the very top always reveals).\n */\n offsetValueChanged(): void {\n this.#offset = Number.isFinite(this.offsetValue) ? this.offsetValue : DEFAULT_OFFSET;\n if (this.#connected) this.#evaluate();\n }\n\n /** Re-renders when application code (or a Turbo morph) changes `mode` at runtime. */\n modeValueChanged(): void {\n if (this.#connected) this.#evaluate();\n }\n\n /** Validates `root` once so connect never parses a selector that throws. */\n rootValueChanged(): void {\n this.#rootSelector = this.#validSelector(this.rootValue);\n }\n\n /** Validates `focusSelector` once so `toTop` never parses a selector that throws. */\n focusSelectorValueChanged(): void {\n this.#focusSelector = this.#validSelector(this.focusSelectorValue);\n }\n\n /** Scrolls the source to the top and, optionally, moves focus to a safe target. */\n toTop(): void {\n const behavior: ScrollBehavior = prefersReducedMotion() ? \"instant\" : \"smooth\";\n this.#scrollSource.scrollTo({ top: 0, behavior });\n if (this.#focusSelector) {\n const target = document.querySelector<HTMLElement>(this.#focusSelector);\n if (target) {\n this.#tabindex.lend(target);\n // Focusing scrolls the target into view by default, which lands the page\n // instantly and discards the scroll above.\n target.focus({ preventScroll: true });\n }\n }\n }\n\n /**\n * Decides the next visibility from the current scroll state and applies it.\n *\n * @param notify - whether a transition announces itself. The reflection\n * `connect()` performs is the current state, not a change.\n *\n * @stimeoRenderRoot\n */\n #evaluate(notify = true): void {\n const y = this.#scrollY();\n let nextVisible: boolean;\n if (this.modeValue === \"direction\") {\n // Near the very top, always reveal so a hide-on-scroll header is never\n // stranded off-screen when the page cannot scroll up any further.\n if (y <= this.#offset) {\n nextVisible = true;\n } else if (y === this.#lastScrollY) {\n // No vertical movement carries no direction, so it decides nothing.\n return;\n } else {\n nextVisible = y < this.#lastScrollY; // scrolling up reveals, down hides\n }\n } else {\n nextVisible = y > this.#offset;\n }\n this.#lastScrollY = y;\n this.#setVisible(nextVisible, notify);\n }\n\n /** Applies visibility to the target, syncing `hidden`, `data-state`, `change`. */\n #setVisible(next: boolean, notify: boolean): void {\n if (next === this.#visible) return;\n const focused = !next && this.hasElementTarget ? this.#focusedWithin() : null;\n if (focused) {\n // Hiding the element that holds focus drops it to the document body,\n // stranding a keyboard user mid-interaction (WCAG 2.4.7 / 2.4.11). Hold\n // the hide until it blurs; the state stays what the user can still see.\n this.#pendingHide.deferOnly(focused);\n return;\n }\n this.#visible = next;\n if (this.hasElementTarget) this.elementTarget.hidden = !next;\n this.element.setAttribute(\"data-state\", next ? \"visible\" : \"hidden\");\n if (notify) this.dispatch(\"change\", { detail: { visible: next } });\n }\n\n /** Resolves the scroll source from `root` (falling back to the window). */\n #resolveScrollSource(): HTMLElement | Window {\n if (this.#rootSelector) {\n const root = document.querySelector<HTMLElement>(this.#rootSelector);\n if (root) return root;\n }\n return window;\n }\n\n /**\n * The focus owner inside the target, or `null` when focus is elsewhere.\n *\n * `blur` does not bubble, so the deferral has to ride the focused element\n * itself: waiting on a container that never receives the event would hold the\n * hide forever.\n */\n #focusedWithin(): HTMLElement | null {\n const focused = document.activeElement;\n if (focused instanceof HTMLElement && this.elementTarget.contains(focused)) return focused;\n return null;\n }\n\n /** Returns `declared` when it parses as a selector, and `\"\"` when it does not. */\n #validSelector(declared: string): string {\n if (declared.length > 0) {\n try {\n this.element.matches(declared);\n return declared;\n } catch {\n // Unparsable selector: fall through to the default below.\n }\n }\n return \"\";\n }\n\n #scrollY(): number {\n if (this.#scrollSource === window) {\n return window.scrollY ?? window.pageYOffset ?? 0;\n }\n return (this.#scrollSource as HTMLElement).scrollTop;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/intersection_watcher.ts","../../src/utils/reduced_motion.ts","../../src/controllers/scrollspy_controller.ts"],"names":[],"mappings":";;;;;AAmDO,IAAM,sBAAN,MAA0B;AAAA,EACtB,UAAA;AAAA,EACT,SAAA,GAAyC,IAAA;AAAA,EACzC,OAAA,GAAU,KAAA;AAAA,EACV,sBAAA,GAAyB,KAAA;AAAA,EAEzB,YAAY,SAAA,EAA2D;AACrE,IAAA,IAAA,CAAK,UAAA,GAAa,SAAA;AAAA,EACpB;AAAA;AAAA,EAGA,IAAI,MAAA,GAAkB;AACpB,IAAA,OAAO,IAAA,CAAK,OAAA;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,qBAAA,GAAiC;AACnC,IAAA,OAAO,IAAA,CAAK,sBAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,KAAA,CAAM,OAAA,EAAuC,OAAA,GAAoC,EAAC,EAAY;AAC5F,IAAA,IAAA,CAAK,IAAA,EAAK;AACV,IAAA,IAAI,OAAO,oBAAA,KAAyB,WAAA,EAAa,OAAO,KAAA;AACxD,IAAA,MAAM,OAAO,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,GAAK,OAAA,GAAiC,CAAC,OAAkB,CAAA;AAC3F,IAAA,IAAI,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG,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AK,WAAA,EAAa;AACnC,MAAA,IAAI,IAAA,CAAK,YAAA,CAAa,cAAc,CAAA,KAAM,UAAA,EAAY;AACtD,MAAA,MAAM,EAAA,GAAK,IAAA,CAAK,YAAA,CAAa,IAAI,CAAA;AACjC,MAAA,IAAI,IAAI,OAAO,EAAA;AAAA,IACjB;AACA,IAAA,OAAO,EAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,aAAa,IAAA,EAAkC;AAC7C,IAAA,OACE,IAAA,CAAK,WAAA,CAAY,IAAA,CAAK,YAAA,CAAa,MAAM,CAAC,CAAA,IAC1C,IAAA,CAAK,WAAA,CAAY,IAAA,CAAK,YAAA,CAAa,WAAW,CAAC,CAAA;AAAA,EAEnD;AAAA;AAAA,EAGA,YAAY,KAAA,EAAqC;AAC/C,IAAA,IAAI,CAAC,KAAA,EAAO,UAAA,CAAW,GAAG,GAAG,OAAO,IAAA;AACpC,IAAA,OAAO,KAAA,CAAM,SAAA,CAAU,CAAC,CAAA,IAAK,IAAA;AAAA,EAC/B;AACF","file":"scrollspy_controller.js","sourcesContent":["/**\n * Shared `IntersectionObserver` plumbing for Stimeo's scroll-triggered\n * controllers (`intersection`, `scrollspy`, `sticky-observer`, `lazy-frame`).\n *\n * It centralizes the `IntersectionObserver` support guard, root resolution from\n * a selector, observer creation/teardown, the **active guard** (the browser may\n * flush a final queued callback batch right after `disconnect()`, and a\n * detached controller must not mutate possibly-cached DOM), and the\n * unobserve→observe **re-arm** that re-delivers the current state even when the\n * target never leaves the viewport.\n *\n * Like {@link RovingTabindex} and `FocusTrap`, this is a policy-free internal\n * util: what an intersection *means* (a spied link, a stuck header, a lazy\n * load) stays in each controller. The public `stimeo--intersection` controller\n * is its thin declarative face.\n */\n/**\n * Whether `entry`'s target sits entirely before the root's **start (top)** edge —\n * the \"scrolled past the top\" half of a non-intersecting entry, as opposed to\n * \"not reached yet\" below the root.\n *\n * A target with no layout box (`display: none`, a `hidden` ancestor, a collapsed\n * `<details>`) is reported with an **empty rect**, whose `bottom` of `0` would\n * otherwise satisfy `bottom <= rootTop` for a viewport root and read as \"passed\"\n * even though the target was never scrolled anywhere. An empty rect carries no\n * position at all, so it is deliberately never \"before the edge\"; what a caller\n * publishes for that case is its own policy (both consumers treat it as the\n * neutral \"not passed\"/\"not stuck\", and the real rect that arrives once the\n * target is laid out re-establishes the true state).\n */\nexport function isBeforeRootStart(entry: IntersectionObserverEntry): boolean {\n const rect = entry.boundingClientRect;\n if (rect.width === 0 && rect.height === 0) return false;\n // rootBounds is null for a cross-origin/removed root; fall back to the\n // viewport origin.\n const rootTop = entry.rootBounds?.top ?? 0;\n return rect.bottom <= rootTop;\n}\n\nexport interface IntersectionWatchOptions {\n /**\n * The observation root. Pass an element (or `null` for the viewport) when\n * the caller already resolved it; omit to resolve from `rootSelector`.\n */\n root?: Element | null;\n /** Selector for the observation root; empty/omitted = viewport. */\n rootSelector?: string;\n rootMargin?: string;\n threshold?: number | number[];\n}\n\nexport class IntersectionWatcher {\n readonly #onEntries: (entries: IntersectionObserverEntry[]) => void;\n #observer: IntersectionObserver | null = null;\n #active = false;\n #usingPlatformDefaults = false;\n\n constructor(onEntries: (entries: IntersectionObserverEntry[]) => void) {\n this.#onEntries = onEntries;\n }\n\n /** Whether an observer is live (started, `IntersectionObserver` supported). */\n get active(): boolean {\n return this.#active;\n }\n\n /** Whether the live observer discarded configured options after construction failed. */\n get usingPlatformDefaults(): boolean {\n return this.#usingPlatformDefaults;\n }\n\n /**\n * (Re)creates the observer and observes `targets`. Returns `false` — leaving\n * the watcher inert — without `IntersectionObserver` support (very old\n * browsers; the caller's no-JS fallback stays in charge) or with no targets.\n * If initial construction with the configured options fails, the watcher\n * warns and retries once with the same root and platform defaults.\n *\n * @throws The fallback constructor error if both construction attempts fail,\n * or whatever the platform throws from `observe()`. The exception is passed\n * through unchanged, but the watcher rolls back first: every target observed\n * so far is released and `active` stays `false`, so a caller that retries\n * starts from a clean slate.\n */\n start(targets: Element | readonly Element[], options: IntersectionWatchOptions = {}): boolean {\n this.stop();\n if (typeof IntersectionObserver === \"undefined\") return false;\n const list = Array.isArray(targets) ? (targets as readonly Element[]) : [targets as Element];\n if (list.length === 0) return false;\n\n const root =\n \"root\" in options\n ? (options.root ?? null)\n : options.rootSelector\n ? document.querySelector(options.rootSelector)\n : null;\n\n let observer: IntersectionObserver | null = null;\n try {\n const onEntries = (entries: IntersectionObserverEntry[]): void => {\n // Identity matters across an immediate restart: the old observer can\n // flush a queued batch after the new observer has made `active` true.\n if (this.#active && this.#observer === observer) this.#onEntries(entries);\n };\n try {\n observer = new IntersectionObserver(onEntries, {\n root,\n rootMargin: options.rootMargin,\n threshold: options.threshold,\n });\n } catch (error) {\n console.warn(\n \"Stimeo UI: IntersectionObserver could not be constructed with the configured options; retrying with platform defaults.\",\n error,\n );\n observer = new IntersectionObserver(onEntries, { root });\n this.#usingPlatformDefaults = true;\n }\n for (const target of list) observer.observe(target);\n this.#observer = observer;\n this.#active = true;\n return true;\n } catch (error) {\n // A constructor or partial observe failure must not leave earlier targets\n // observed or report an active watcher. Preserve the platform exception.\n observer?.disconnect();\n this.#observer = null;\n this.#active = false;\n this.#usingPlatformDefaults = false;\n throw error;\n }\n }\n\n /**\n * Re-delivers `target`'s CURRENT intersection state: `IntersectionObserver`\n * only reports *changes*, but `observe()` always reports the present state,\n * so unobserve→observe turns \"still intersecting\" into a fresh callback.\n *\n * @throws Whatever `unobserve()`/`observe()` throws. The watcher is stopped\n * first, so it never stays live with a half-rearmed target.\n */\n rearm(target: Element): void {\n if (!this.#observer) return;\n try {\n this.#observer.unobserve(target);\n this.#observer.observe(target);\n } catch (error) {\n this.stop();\n throw error;\n }\n }\n\n /** Severs the observer; late queued callbacks become no-ops via the guard. */\n stop(): void {\n this.#active = false;\n this.#observer?.disconnect();\n this.#observer = null;\n this.#usingPlatformDefaults = false;\n }\n}\n","/**\n * Shared `prefers-reduced-motion` lookup for the motion-aware controllers\n * (count-up, highlight, overflow-indicator, scroll-visibility, stick-to-bottom,\n * transition).\n *\n * This one-liner keeps the media query string and the environment guard\n * single-sourced across them. The preference is intentionally re-read on every\n * call — the controllers check it at each animation/scroll start (WCAG 2.2\n * **2.3.3**), so flipping the OS setting takes effect immediately without any\n * listener or cache bookkeeping here.\n */\n\n/**\n * Whether the user currently requests reduced motion.\n *\n * @returns `true` when `(prefers-reduced-motion: reduce)` matches; `false`\n * otherwise, including environments without `window.matchMedia` (treated as\n * \"no preference\").\n */\nexport function prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { IntersectionWatcher } from \"../utils/intersection_watcher\";\nimport { prefersReducedMotion } from \"../utils/reduced_motion\";\n\n/**\n * The attributes a link may anchor its section with, and therefore the only\n * ones whose rewrite has to re-sync the observation set. `aria-current` — the\n * attribute this controller writes itself — is deliberately absent, so\n * publishing the current location cannot feed back into a rebuild.\n */\nconst ANCHOR_ATTRIBUTES = [\"href\", \"data-href\"];\n\n/**\n * Headless, accessible **Scrollspy**: keeps a table of contents in sync with the\n * section the reader is currently in, published as `aria-current=\"location\"`.\n * There is no dedicated APG widget; it follows the `aria-current`\n * current-location practice inside a `<nav>` landmark.\n *\n * Markup contract (identifier: `stimeo--scrollspy`):\n * <nav data-controller=\"stimeo--scrollspy\"\n * data-stimeo--scrollspy-offset-value=\"80\"\n * data-stimeo--scrollspy-root-selector-value=\".content\"\n * aria-label=\"Table of contents\">\n * <a href=\"#intro\" data-stimeo--scrollspy-target=\"link\"\n * data-action=\"click->stimeo--scrollspy#scrollTo\">Intro</a>\n * <a href=\"#usage\" data-stimeo--scrollspy-target=\"link\"\n * data-action=\"click->stimeo--scrollspy#scrollTo\">Usage</a>\n * </nav>\n * <div class=\"content\">\n * <section id=\"intro\">…</section>\n * <section id=\"usage\">…</section>\n * </div>\n *\n * The active section is the one whose top edge sits closest to the **trigger\n * line**: `offset` px below the top of the *scroll root* — the `rootSelector`\n * container, or the viewport when that value is empty. It is not the viewport\n * top whenever a nested container is spied on. Intersecting sections win; when\n * none intersects (between two sections, scrolled past the last one) the\n * closest tracked section keeps the highlight, so a table of contents never\n * goes blank.\n *\n * `data-action` on the links is optional and opts into {@link scrollTo}, which\n * scrolls the nested container instead of bouncing the whole window.\n *\n * `change` dispatches `{ id: string, link: HTMLElement }`.\n *\n * @remarks\n * Behavior only — how a current link looks is the consumer's CSS\n * (`[aria-current=\"location\"] { … }`). `connect()` reads the current location\n * back from the DOM so a Turbo cache restore re-establishes it without a\n * redundant `change`, and `disconnect()` severs every resource acquired here:\n * the observers, the scroll listener, and any pending frame or queued rebuild.\n *\n * **What is followed automatically**, and what is not (the boundary a consumer\n * has to know, because everything outside it needs a re-`connect()`):\n *\n * - `link` targets added or removed — Stimulus's target callbacks.\n * - a `link` target's `href` / `data-href` rewritten in place — a Turbo 8 morph\n * keeps the element *and* its target marker, so no target callback fires;\n * {@link ANCHOR_ATTRIBUTES} is watched for exactly this case.\n * - the reader's scroll position, including inside a stretch where no section\n * crosses an observation threshold.\n *\n * Not followed: a *split* lifecycle in which the nav survives while the scroll\n * root or the sections are replaced underneath it. `rootSelector` is resolved\n * against the whole document and re-resolved once the cached container leaves\n * it, but section elements are looked up only while the observation set is\n * (re)built — swap those alone and nothing tells this controller to look again.\n */\nexport class ScrollspyController extends Controller<HTMLElement> {\n static override targets = [\"link\"];\n static override values = {\n offset: { type: Number, default: 0 },\n rootMargin: { type: String, default: \"\" },\n rootSelector: { type: String, default: \"\" },\n focusSection: { type: Boolean, default: false },\n };\n static actions = [\"scrollTo\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly linkTargets: HTMLElement[];\n\n declare offsetValue: number;\n declare rootMarginValue: string;\n declare rootSelectorValue: string;\n declare focusSectionValue: boolean;\n\n /**\n * The one offset shared by observation, active-section selection, and\n * scrolling. Stimulus parses a malformed Number Value as `NaN`; degrading it\n * to the declared default keeps every path aligned instead of only repairing\n * the observer margin while selection and scrolling still receive `NaN`.\n */\n get #offset(): number {\n return Number.isFinite(this.offsetValue) ? this.offsetValue : 0;\n }\n\n /** Shared IO plumbing (support guard, active guard, teardown). */\n readonly #watcher = new IntersectionWatcher((entries) => this.#onIntersection(entries));\n #isConnected = false;\n\n /**\n * Sections currently tracked, by id. Only the *latest reported* intersection\n * flag is stored — never a coordinate. Positions are re-measured when the\n * active section is evaluated, so a section observed several batches ago is\n * never compared against a trigger line computed now.\n */\n #intersectionStates = new Map<string, { element: Element; isIntersecting: boolean }>();\n\n /** Current active section ID; comparing it suppresses duplicate `change` events. */\n #activeSectionId = \"\";\n\n /**\n * Scroll root resolved when the observer was (re)built; `null` = viewport.\n * Cached so a click and every intersection batch reuse the element the\n * observer is actually watching instead of re-querying the document.\n */\n #rootElement: HTMLElement | null = null;\n\n /**\n * The source the `scroll` listener is currently attached to — the resolved\n * root, or the window while the viewport is spied. `null` means \"nothing\n * attached\", so teardown always detaches from the source it attached to\n * rather than from whatever the selector resolves to now.\n */\n #scrollSource: HTMLElement | Window | null = null;\n\n /** Pending re-evaluation frame; coalesces a scroll burst into one measurement. */\n #frame: number | null = null;\n\n /** Watches the link targets' anchor attributes for an in-place morph rewrite. */\n #anchorObserver: MutationObserver | null = null;\n\n /** True while a coalesced observation rebuild is queued; see {@link #scheduleResync}. */\n #resyncQueued = false;\n\n override connect(): void {\n this.#isConnected = true;\n this.#observeAnchorAttributes();\n this.#initializeObserver();\n }\n\n override disconnect(): void {\n this.#isConnected = false;\n // Dropping the flag is what discards a rebuild queued moments ago: the\n // drain reads it, so the queued microtask becomes a no-op.\n this.#resyncQueued = false;\n this.#watcher.stop();\n this.#anchorObserver?.disconnect();\n this.#anchorObserver = null;\n this.#detachScrollListener();\n if (this.#frame !== null) {\n cancelAnimationFrame(this.#frame);\n this.#frame = null;\n }\n this.#intersectionStates.clear();\n this.#activeSectionId = \"\";\n this.#rootElement = null;\n }\n\n /**\n * Re-initializes the observer if the offset or rootMargin values change dynamically.\n */\n offsetValueChanged(): void {\n if (!this.#isConnected) return;\n this.#initializeObserver();\n }\n\n rootMarginValueChanged(): void {\n if (!this.#isConnected) return;\n this.#initializeObserver();\n }\n\n rootSelectorValueChanged(): void {\n if (!this.#isConnected) return;\n this.#initializeObserver();\n }\n\n /**\n * Re-syncs the observation set when a Turbo Stream/morph swaps the table of\n * contents. Stimulus fires these before `connect()` for the links already in\n * the markup, hence the guard: the initial observer is built exactly once, by\n * `connect()`.\n */\n linkTargetConnected(): void {\n if (this.#isConnected) this.#scheduleResync();\n }\n\n linkTargetDisconnected(): void {\n if (this.#isConnected) this.#scheduleResync();\n }\n\n /**\n * Queues **one** observation rebuild for the current mutation batch.\n *\n * A single Turbo morph can append one link, drop another, and rewrite a\n * third's `href`, and those arrive through two independent channels —\n * Stimulus's target callbacks and {@link #anchorObserver}. Each channel just\n * raises the flag and queues a drain; the first drain to run does the work and\n * clears it, so every later drain in the same batch finds nothing to do and\n * the set is rebuilt once instead of three times. `disconnect()` clears the\n * same flag, which is how a queued rebuild is dropped rather than run against\n * a detached controller.\n */\n #scheduleResync(): void {\n this.#resyncQueued = true;\n queueMicrotask(this.#drainResync);\n }\n\n readonly #drainResync = (): void => {\n if (!this.#resyncQueued) return;\n this.#resyncQueued = false;\n this.#initializeObserver();\n };\n\n /**\n * Watches the link targets' anchor attributes so an in-place rewrite re-syncs.\n *\n * A Turbo 8 morph keeps the element **and** its `data-*-target` marker and\n * only rewrites attributes, so Stimulus fires no target callback: without\n * this, a link re-pointed from `#intro` to `#faq` would keep the controller\n * observing `#intro` for the rest of the page's life. The filter is exactly\n * {@link ANCHOR_ATTRIBUTES}; guarding on `MutationObserver` keeps the\n * controller usable where the API is absent, matching `IntersectionWatcher`'s\n * own support guard.\n */\n #observeAnchorAttributes(): void {\n if (typeof MutationObserver !== \"undefined\") {\n this.#anchorObserver = new MutationObserver(this.#onAnchorMutation);\n this.#anchorObserver.observe(this.element, {\n subtree: true,\n attributes: true,\n attributeFilter: ANCHOR_ATTRIBUTES,\n });\n }\n }\n\n /**\n * Rebuilds only for a rewrite on a *current* link target. The observer is\n * scoped to this controller's element, but that subtree also holds links the\n * author never marked as targets (a \"back to top\" anchor, a nested nav), and\n * those anchor nothing here.\n */\n readonly #onAnchorMutation = (records: MutationRecord[]): void => {\n const links = this.linkTargets;\n for (const record of records) {\n if (!links.includes(record.target as HTMLElement)) continue;\n this.#scheduleResync();\n return;\n }\n };\n\n /**\n * Scrolls to the section the clicked link anchors, honoring `offset` and any\n * nested scroll container (a plain fragment jump would scroll the window).\n *\n * Honors `prefers-reduced-motion` (WCAG 2.2 **2.3.3**) by forcing an instant\n * jump independently of the consumer's CSS `scroll-behavior`. With\n * `focusSection` enabled it also moves the sequential focus starting point\n * into the destination; the URL fragment is deliberately not touched.\n */\n scrollTo(event: Event): void {\n const link = event.currentTarget as HTMLElement;\n const id = this.#getAnchorId(link);\n if (!id) return;\n\n event.preventDefault();\n\n const targetElement = document.getElementById(id);\n if (!targetElement) return;\n\n const behavior: ScrollBehavior = prefersReducedMotion() ? \"instant\" : \"smooth\";\n const rootElement = this.#scrollRoot();\n const targetRect = targetElement.getBoundingClientRect();\n const offset = this.#offset;\n\n if (rootElement) {\n const containerRect = rootElement.getBoundingClientRect();\n const scrollPosition = rootElement.scrollTop + (targetRect.top - containerRect.top) - offset;\n\n rootElement.scrollTo({ top: scrollPosition, behavior });\n } else {\n const scrollPosition = window.scrollY + targetRect.top - offset;\n\n window.scrollTo({ top: scrollPosition, behavior });\n }\n\n if (this.focusSectionValue) this.#focusSection(targetElement);\n }\n\n /**\n * Moves the sequential focus starting point into the section `scrollTo` just\n * jumped to, so the next Tab continues *inside* the destination instead of\n * resuming in the table of contents (`preventDefault()` alone would leave the\n * starting point on the link). Opt-in through `focusSection`, because moving\n * focus is a decision only the consuming page can make.\n *\n * `tabindex=\"-1\"` is established only when the section is not already\n * focusable and is never removed, so an author-owned tabindex is left alone.\n * `preventScroll` keeps the focus call from cancelling the smooth scroll\n * started just above.\n */\n #focusSection(section: HTMLElement): void {\n if (!section.hasAttribute(\"tabindex\")) section.setAttribute(\"tabindex\", \"-1\");\n section.focus({ preventScroll: true });\n }\n\n /**\n * The cached scroll root, re-resolved when the cached element has left the\n * document (a Turbo morph replaced the container) so `scrollTo` never\n * scrolls a detached node.\n */\n #scrollRoot(): HTMLElement | null {\n if (this.#rootElement && !this.#rootElement.isConnected) {\n this.#rootElement = this.#queryRootElement();\n }\n return this.#rootElement;\n }\n\n /**\n * Resolves `rootSelector` to a scrollable element.\n *\n * @returns The container, or `null` meaning \"spy the viewport\" when the value\n * is empty, matches nothing, matches a non-HTML element (an SVG node is not a\n * scroll container), or is not a valid selector — a typo in a data attribute\n * must degrade to viewport spying, not leave the controller inert.\n */\n #queryRootElement(): HTMLElement | null {\n if (!this.rootSelectorValue) return null;\n try {\n const root = document.querySelector(this.rootSelectorValue);\n return root instanceof HTMLElement ? root : null;\n } catch {\n return null;\n }\n }\n\n /**\n * Re-evaluates once per frame while the reader scrolls.\n *\n * `IntersectionObserver` reports **threshold crossings**, not positions, so a\n * reader moving inside one long section — or across a gap wider than the\n * observation band — produces no batch at all and the highlight would stay\n * frozen at whatever the last crossing decided. That would make the current\n * location depend on the *route* to a position instead of the position: a\n * stepwise scroll crosses thresholds an instant jump to the same offset never\n * does. Listening to the scroll source closes the gap, and because both paths\n * end in {@link #evaluateActiveSection} — which measures section rects and the\n * root's top edge at that instant — they converge on the same answer.\n */\n readonly #onScroll = (): void => {\n if (this.#frame !== null) return;\n this.#frame = requestAnimationFrame(() => {\n this.#frame = null;\n this.#evaluateActiveSection();\n });\n };\n\n /**\n * Points the `scroll` listener at whatever the reader actually scrolls: the\n * resolved root, or the window when the viewport is spied.\n *\n * The detach is unconditional, so rebuilding the observation set (a Value\n * change, a morph) **moves** the listener rather than stacking a second one on\n * a container the reader has stopped scrolling.\n */\n #syncScrollListener(): void {\n this.#detachScrollListener();\n this.#scrollSource = this.#rootElement ?? window;\n this.#scrollSource.addEventListener(\"scroll\", this.#onScroll, { passive: true });\n }\n\n #detachScrollListener(): void {\n this.#scrollSource?.removeEventListener(\"scroll\", this.#onScroll);\n this.#scrollSource = null;\n }\n\n #initializeObserver(): void {\n this.#watcher.stop();\n this.#intersectionStates.clear();\n // The DOM is the source of truth for the current location **only when this\n // controller has none of its own** — a fresh `connect()`, which is also the\n // Turbo cache-restore case, where the links still carry `aria-current` from\n // the snapshot. Adopting it there makes the observer's first batch a silent\n // confirmation instead of a duplicate `change`.\n //\n // On a *live* rebuild the memory wins, because the DOM has stopped meaning\n // what this controller wrote: an anchor rewritten underneath us leaves\n // `aria-current` on a link that now points somewhere else, so reading it\n // back would hand the current location to a section the reader never\n // scrolled to — and then announce the correction as a `change`, as if they\n // had travelled there and back.\n this.#activeSectionId = this.#activeSectionId || this.#activeIdFromDom();\n this.#rootElement = this.#queryRootElement();\n this.#syncScrollListener();\n\n if (this.linkTargets.length === 0) return;\n\n // Negate the numeric value so a valid negative offset becomes a positive margin.\n const margin = this.rootMarginValue || `${-this.#offset}px 0px -80% 0px`;\n\n // Observe each target section mapped by the href anchors.\n const sections: Element[] = [];\n for (const link of this.linkTargets) {\n const id = this.#getAnchorId(link);\n if (!id) continue;\n const section = document.getElementById(id);\n if (section && !sections.includes(section)) sections.push(section);\n }\n\n this.#watcher.start(sections, {\n root: this.#rootElement,\n rootMargin: margin,\n threshold: [0, 0.2, 0.4, 0.6, 0.8, 1], // Multiple thresholds handle large sections safely\n });\n\n // Republish the adopted location over the *current* link set. Evaluation\n // writes attributes only when the winning section changes, so a link added\n // — or re-anchored — while the reader stays put would otherwise never be\n // marked: a mobile table of contents rendered after the sidebar one would\n // stay blank until the reader happened to cross into another section.\n //\n // Unconditional, including when the adopted location is empty: a link whose\n // anchor was rewritten to something that resolves nowhere cannot be the\n // reader's location, and this controller is the one that published the\n // attribute saying it was, so it is the one that has to take it back.\n this.#syncActiveStates(false);\n }\n\n readonly #onIntersection = (entries: IntersectionObserverEntry[]): void => {\n // Defense in depth. `IntersectionWatcher` already drops a batch the browser\n // flushes after `stop()` (its active/identity guard), so this flag is the\n // second line that keeps a detached controller from mutating `aria-current`\n // on (possibly cached) links.\n const isDetached = !this.#isConnected;\n if (isDetached) return;\n\n for (const entry of entries) {\n const sectionId = entry.target.id;\n if (!sectionId) continue;\n\n this.#intersectionStates.set(sectionId, {\n element: entry.target,\n isIntersecting: entry.isIntersecting,\n });\n }\n\n this.#evaluateActiveSection();\n };\n\n /**\n * Picks the section closest to the trigger line and publishes it.\n *\n * Every coordinate is read **now**: the section rects *and* the root's top\n * edge share one measurement instant. Comparing an entry's recorded\n * `boundingClientRect.top` (captured whenever that section last crossed a\n * threshold) against a freshly computed trigger line mixes two moments in\n * time, which would make the result depend on how the reader arrived at a\n * position — a smooth scroll and an instant jump to the same offset disagree.\n */\n #evaluateActiveSection(): void {\n // The trigger line is `offset` px below the top of the scroll root. When a\n // nested `rootSelector` container is used it is not at the viewport top, so\n // the line must be measured from the container's current top — comparing the\n // viewport-based rect top against a bare `offset` would otherwise pick the\n // section nearest the viewport top, not the container's.\n const rootEl = this.#scrollRoot();\n const triggerLine = (rootEl ? rootEl.getBoundingClientRect().top : 0) + this.#offset;\n\n let intersectingId = \"\";\n let intersectingDistance = Number.POSITIVE_INFINITY;\n let trackedId = \"\";\n let trackedDistance = Number.POSITIVE_INFINITY;\n\n for (const [id, state] of this.#intersectionStates) {\n const rect = state.element.getBoundingClientRect();\n // A section with no layout box (`display: none`, a collapsed `<details>`,\n // an undisplayed Turbo Frame) is reported with an empty rect whose `top`\n // of 0 carries no position at all. Letting it compete would hand it the\n // fallback below; it re-enters the race once it is actually laid out.\n if (rect.width === 0 && rect.height === 0) continue;\n\n const distance = Math.abs(rect.top - triggerLine);\n if (distance < trackedDistance) {\n trackedDistance = distance;\n trackedId = id;\n }\n if (state.isIntersecting && distance < intersectingDistance) {\n intersectingDistance = distance;\n intersectingId = id;\n }\n }\n\n // Fallback: when no section currently intersects (e.g. scrolled past the\n // bottom, or between sections), keep the tracked section whose top is\n // closest to the trigger line so something stays highlighted.\n const bestId = intersectingId || trackedId;\n\n if (bestId && bestId !== this.#activeSectionId) {\n this.#activeSectionId = bestId;\n this.#syncActiveStates(true);\n }\n }\n\n /**\n * Writes `aria-current` across the current link set, optionally announcing.\n *\n * The two halves are separate because they answer different questions.\n * *Attributes* must be idempotently re-established whenever the link set\n * changes, even though the reader has not moved — otherwise a link that\n * appears (or is re-anchored) while its section is already current never gets\n * marked. *The `change` event* announces that the reader moved, so it fires\n * only from the evaluation path; re-publishing over a new link set is not\n * news, and dispatching there would make a rebuild look like navigation.\n *\n * @param announce Whether this sync represents a change of current section.\n */\n #syncActiveStates(announce: boolean): void {\n // Every link anchoring the active section is marked, not just the first:\n // a page may render the same table of contents twice (a sidebar and a\n // collapsed mobile menu) and both must show the current location.\n const activeLinks = this.linkTargets.filter(\n (link) => this.#getAnchorId(link) === this.#activeSectionId,\n );\n\n for (const link of this.linkTargets) {\n if (activeLinks.includes(link)) {\n link.setAttribute(\"aria-current\", \"location\");\n } else if (link.getAttribute(\"aria-current\") === \"location\") {\n // Reclaim only the value this controller publishes, so an author-owned\n // `aria-current=\"page\"` on a table-of-contents link survives.\n link.removeAttribute(\"aria-current\");\n }\n }\n\n if (!announce) return;\n\n const primaryLink = activeLinks[0];\n if (primaryLink) {\n this.dispatch(\"change\", { detail: { id: this.#activeSectionId, link: primaryLink } });\n }\n }\n\n /**\n * The current location already encoded in the DOM, i.e. the section anchored\n * by the first link carrying this controller's `aria-current=\"location\"`.\n * Empty when no link claims it (a genuinely fresh render).\n */\n #activeIdFromDom(): string {\n for (const link of this.linkTargets) {\n if (link.getAttribute(\"aria-current\") !== \"location\") continue;\n const id = this.#getAnchorId(link);\n if (id) return id;\n }\n return \"\";\n }\n\n /**\n * The section id a link anchors, resolved in a fixed order:\n *\n * 1. `href`, when it is a non-empty same-document fragment — the contract.\n * 2. otherwise `data-href`'s fragment — the fallback for a link whose `href`\n * must stay a real URL (a server-rendered permalink) or that is not an\n * `<a>` at all.\n * 3. otherwise `null`: the link anchors nothing here and is not observed.\n *\n * Step 2 is reached whenever `href` yields nothing usable — absent, `\"#\"`, or\n * a real URL — which is the whole point of the fallback: `href=\"/guide/usage\"`\n * with `data-href=\"#usage\"` is a permalink that also spies, and picking the\n * first *present* attribute instead of the first *usable* one would silently\n * exclude exactly that markup. When both are valid fragments `href` wins.\n */\n #getAnchorId(link: HTMLElement): string | null {\n return (\n this.#fragmentId(link.getAttribute(\"href\")) ??\n this.#fragmentId(link.getAttribute(\"data-href\"))\n );\n }\n\n /** The id in a `#fragment` value; `null` for absent, empty, or non-fragment. */\n #fragmentId(value: string | null): string | null {\n if (!value?.startsWith(\"#\")) return null;\n return value.substring(1) || null;\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/intersection_watcher.ts","../../src/utils/reduced_motion.ts","../../src/controllers/scrollspy_controller.ts"],"names":[],"mappings":";;;;;AAmDO,IAAM,sBAAN,MAA0B;AAAA,EACtB,UAAA;AAAA,EACT,SAAA,GAAyC,IAAA;AAAA,EACzC,OAAA,GAAU,KAAA;AAAA,EACV,sBAAA,GAAyB,KAAA;AAAA,EAEzB,YAAY,SAAA,EAA2D;AACrE,IAAA,IAAA,CAAK,UAAA,GAAa,SAAA;AAAA,EACpB;AAAA;AAAA,EAGA,IAAI,MAAA,GAAkB;AACpB,IAAA,OAAO,IAAA,CAAK,OAAA;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,qBAAA,GAAiC;AACnC,IAAA,OAAO,IAAA,CAAK,sBAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,KAAA,CAAM,OAAA,EAAuC,OAAA,GAAoC,EAAC,EAAY;AAC5F,IAAA,IAAA,CAAK,IAAA,EAAK;AACV,IAA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,EAAQ,EAAE,EAAA,EAAI,IAAA,CAAK,gBAAA,EAAkB,IAAA,EAAM,WAAA,EAAY,EAAG,CAAA;AAAA,IACtF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,gBAAA,GAA2B;AACzB,IAAA,KAAA,MAAW,IAAA,IAAQ,KAAK,WAAA,EAAa;AACnC,MAAA,IAAI,IAAA,CAAK,YAAA,CAAa,cAAc,CAAA,KAAM,UAAA,EAAY;AACtD,MAAA,MAAM,EAAA,GAAK,IAAA,CAAK,YAAA,CAAa,IAAI,CAAA;AACjC,MAAA,IAAI,IAAI,OAAO,EAAA;AAAA,IACjB;AACA,IAAA,OAAO,EAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,aAAa,IAAA,EAAkC;AAC7C,IAAA,OACE,IAAA,CAAK,WAAA,CAAY,IAAA,CAAK,YAAA,CAAa,MAAM,CAAC,CAAA,IAC1C,IAAA,CAAK,WAAA,CAAY,IAAA,CAAK,YAAA,CAAa,WAAW,CAAC,CAAA;AAAA,EAEnD;AAAA;AAAA,EAGA,YAAY,KAAA,EAAqC;AAC/C,IAAA,IAAI,CAAC,KAAA,EAAO,UAAA,CAAW,GAAG,GAAG,OAAO,IAAA;AACpC,IAAA,OAAO,KAAA,CAAM,SAAA,CAAU,CAAC,CAAA,IAAK,IAAA;AAAA,EAC/B;AACF","file":"scrollspy_controller.js","sourcesContent":["/**\n * Shared `IntersectionObserver` plumbing for Stimeo's scroll-triggered\n * controllers (`intersection`, `scrollspy`, `sticky-observer`, `lazy-frame`).\n *\n * It centralizes the `IntersectionObserver` support guard, root resolution from\n * a selector, observer creation/teardown, the **active guard** (the browser may\n * flush a final queued callback batch right after `disconnect()`, and a\n * detached controller must not mutate possibly-cached DOM), and the\n * unobserve→observe **re-arm** that re-delivers the current state even when the\n * target never leaves the viewport.\n *\n * Like {@link RovingTabindex} and `FocusTrap`, this is a policy-free internal\n * util: what an intersection *means* (a spied link, a stuck header, a lazy\n * load) stays in each controller. The public `stimeo--intersection` controller\n * is its thin declarative face.\n */\n/**\n * Whether `entry`'s target sits entirely before the root's **start (top)** edge —\n * the \"scrolled past the top\" half of a non-intersecting entry, as opposed to\n * \"not reached yet\" below the root.\n *\n * A target with no layout box (`display: none`, a `hidden` ancestor, a collapsed\n * `<details>`) is reported with an **empty rect**, whose `bottom` of `0` would\n * otherwise satisfy `bottom <= rootTop` for a viewport root and read as \"passed\"\n * even though the target was never scrolled anywhere. An empty rect carries no\n * position at all, so it is deliberately never \"before the edge\"; what a caller\n * publishes for that case is its own policy (both consumers treat it as the\n * neutral \"not passed\"/\"not stuck\", and the real rect that arrives once the\n * target is laid out re-establishes the true state).\n */\nexport function isBeforeRootStart(entry: IntersectionObserverEntry): boolean {\n const rect = entry.boundingClientRect;\n if (rect.width === 0 && rect.height === 0) return false;\n // rootBounds is null for a cross-origin/removed root; fall back to the\n // viewport origin.\n const rootTop = entry.rootBounds?.top ?? 0;\n return rect.bottom <= rootTop;\n}\n\nexport interface IntersectionWatchOptions {\n /**\n * The observation root. Pass an element (or `null` for the viewport) when\n * the caller already resolved it; omit to resolve from `rootSelector`.\n */\n root?: Element | null;\n /** Selector for the observation root; empty/omitted = viewport. */\n rootSelector?: string;\n rootMargin?: string;\n threshold?: number | number[];\n}\n\nexport class IntersectionWatcher {\n readonly #onEntries: (entries: IntersectionObserverEntry[]) => void;\n #observer: IntersectionObserver | null = null;\n #active = false;\n #usingPlatformDefaults = false;\n\n constructor(onEntries: (entries: IntersectionObserverEntry[]) => void) {\n this.#onEntries = onEntries;\n }\n\n /** Whether an observer is live (started, `IntersectionObserver` supported). */\n get active(): boolean {\n return this.#active;\n }\n\n /** Whether the live observer discarded configured options after construction failed. */\n get usingPlatformDefaults(): boolean {\n return this.#usingPlatformDefaults;\n }\n\n /**\n * (Re)creates the observer and observes `targets`. Returns `false` — leaving\n * the watcher inert — without `IntersectionObserver` support (very old\n * browsers; the caller's no-JS fallback stays in charge) or with no targets.\n * If initial construction with the configured options fails, the watcher\n * warns and retries once with the same root and platform defaults.\n *\n * @throws The fallback constructor error if both construction attempts fail,\n * or whatever the platform throws from `observe()`. The exception is passed\n * through unchanged, but the watcher rolls back first: every target observed\n * so far is released and `active` stays `false`, so a caller that retries\n * starts from a clean slate.\n */\n start(targets: Element | readonly Element[], options: IntersectionWatchOptions = {}): boolean {\n this.stop();\n if (typeof IntersectionObserver === \"undefined\") return false;\n const list = Array.isArray(targets) ? (targets as readonly Element[]) : [targets as Element];\n if (list.length === 0) return false;\n\n const root =\n \"root\" in options\n ? (options.root ?? null)\n : options.rootSelector\n ? document.querySelector(options.rootSelector)\n : null;\n\n let observer: IntersectionObserver | null = null;\n try {\n const onEntries = (entries: IntersectionObserverEntry[]): void => {\n // Identity matters across an immediate restart: the old observer can\n // flush a queued batch after the new observer has made `active` true.\n if (this.#active && this.#observer === observer) this.#onEntries(entries);\n };\n try {\n observer = new IntersectionObserver(onEntries, {\n root,\n rootMargin: options.rootMargin,\n threshold: options.threshold,\n });\n } catch (error) {\n console.warn(\n \"Stimeo UI: IntersectionObserver could not be constructed with the configured options; retrying with platform defaults.\",\n error,\n );\n observer = new IntersectionObserver(onEntries, { root });\n this.#usingPlatformDefaults = true;\n }\n for (const target of list) observer.observe(target);\n this.#observer = observer;\n this.#active = true;\n return true;\n } catch (error) {\n // A constructor or partial observe failure must not leave earlier targets\n // observed or report an active watcher. Preserve the platform exception.\n observer?.disconnect();\n this.#observer = null;\n this.#active = false;\n this.#usingPlatformDefaults = false;\n throw error;\n }\n }\n\n /**\n * Re-delivers `target`'s CURRENT intersection state: `IntersectionObserver`\n * only reports *changes*, but `observe()` always reports the present state,\n * so unobserve→observe turns \"still intersecting\" into a fresh callback.\n *\n * @throws Whatever `unobserve()`/`observe()` throws. The watcher is stopped\n * first, so it never stays live with a half-rearmed target.\n */\n rearm(target: Element): void {\n if (!this.#observer) return;\n try {\n this.#observer.unobserve(target);\n this.#observer.observe(target);\n } catch (error) {\n this.stop();\n throw error;\n }\n }\n\n /** Severs the observer; late queued callbacks become no-ops via the guard. */\n stop(): void {\n this.#active = false;\n this.#observer?.disconnect();\n this.#observer = null;\n this.#usingPlatformDefaults = false;\n }\n}\n","/**\n * Shared `prefers-reduced-motion` lookup for the motion-aware controllers\n *.\n *\n * This one-liner keeps the media query string and the environment guard\n * single-sourced across them. The preference is intentionally re-read on every\n * call — the controllers check it at each animation/scroll start (WCAG 2.2\n * **2.3.3**), so flipping the OS setting takes effect immediately without any\n * listener or cache bookkeeping here.\n */\n\n/**\n * Whether the user currently requests reduced motion.\n *\n * @returns `true` when `(prefers-reduced-motion: reduce)` matches; `false`\n * otherwise, including environments without `window.matchMedia` (treated as\n * \"no preference\").\n */\nexport function prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { IntersectionWatcher } from \"../utils/intersection_watcher\";\nimport { prefersReducedMotion } from \"../utils/reduced_motion\";\n\n/**\n * The attributes a link may anchor its section with, and therefore the only\n * ones whose rewrite has to re-sync the observation set. `aria-current` — the\n * attribute this controller writes itself — is deliberately absent, so\n * publishing the current location cannot feed back into a rebuild.\n */\nconst ANCHOR_ATTRIBUTES = [\"href\", \"data-href\"];\n\n/**\n * Headless, accessible **Scrollspy**: keeps a table of contents in sync with the\n * section the reader is currently in, published as `aria-current=\"location\"`.\n * There is no dedicated APG widget; it follows the `aria-current`\n * current-location practice inside a `<nav>` landmark.\n *\n * Markup contract (identifier: `stimeo--scrollspy`):\n * <nav data-controller=\"stimeo--scrollspy\"\n * data-stimeo--scrollspy-offset-value=\"80\"\n * data-stimeo--scrollspy-root-selector-value=\".content\"\n * aria-label=\"Table of contents\">\n * <a href=\"#intro\" data-stimeo--scrollspy-target=\"link\"\n * data-action=\"click->stimeo--scrollspy#scrollTo\">Intro</a>\n * <a href=\"#usage\" data-stimeo--scrollspy-target=\"link\"\n * data-action=\"click->stimeo--scrollspy#scrollTo\">Usage</a>\n * </nav>\n * <div class=\"content\">\n * <section id=\"intro\">…</section>\n * <section id=\"usage\">…</section>\n * </div>\n *\n * The active section is the one whose top edge sits closest to the **trigger\n * line**: `offset` px below the top of the *scroll root* — the `rootSelector`\n * container, or the viewport when that value is empty. It is not the viewport\n * top whenever a nested container is spied on. Intersecting sections win; when\n * none intersects (between two sections, scrolled past the last one) the\n * closest tracked section keeps the highlight, so a table of contents never\n * goes blank.\n *\n * `data-action` on the links is optional and opts into {@link scrollTo}, which\n * scrolls the nested container instead of bouncing the whole window.\n *\n * `change` dispatches `{ id: string, link: HTMLElement }`.\n *\n * @remarks\n * Behavior only — how a current link looks is the consumer's CSS\n * (`[aria-current=\"location\"] { … }`). `connect()` reads the current location\n * back from the DOM so a Turbo cache restore re-establishes it without a\n * redundant `change`, and `disconnect()` severs every resource acquired here:\n * the observers, the scroll listener, and any pending frame or queued rebuild.\n *\n * **What is followed automatically**, and what is not (the boundary a consumer\n * has to know, because everything outside it needs a re-`connect()`):\n *\n * - `link` targets added or removed — Stimulus's target callbacks.\n * - a `link` target's `href` / `data-href` rewritten in place — a Turbo 8 morph\n * keeps the element *and* its target marker, so no target callback fires;\n * {@link ANCHOR_ATTRIBUTES} is watched for exactly this case.\n * - the reader's scroll position, including inside a stretch where no section\n * crosses an observation threshold.\n *\n * Not followed: a *split* lifecycle in which the nav survives while the scroll\n * root or the sections are replaced underneath it. `rootSelector` is resolved\n * against the whole document and re-resolved once the cached container leaves\n * it, but section elements are looked up only while the observation set is\n * (re)built — swap those alone and nothing tells this controller to look again.\n */\nexport class ScrollspyController extends Controller<HTMLElement> {\n static override targets = [\"link\"];\n static override values = {\n offset: { type: Number, default: 0 },\n rootMargin: { type: String, default: \"\" },\n rootSelector: { type: String, default: \"\" },\n focusSection: { type: Boolean, default: false },\n };\n static actions = [\"scrollTo\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly linkTargets: HTMLElement[];\n\n declare offsetValue: number;\n declare rootMarginValue: string;\n declare rootSelectorValue: string;\n declare focusSectionValue: boolean;\n\n /**\n * The one offset shared by observation, active-section selection, and\n * scrolling. Stimulus parses a malformed Number Value as `NaN`; degrading it\n * to the declared default keeps every path aligned instead of only repairing\n * the observer margin while selection and scrolling still receive `NaN`.\n */\n get #offset(): number {\n return Number.isFinite(this.offsetValue) ? this.offsetValue : 0;\n }\n\n /** Shared IO plumbing (support guard, active guard, teardown). */\n readonly #watcher = new IntersectionWatcher((entries) => this.#onIntersection(entries));\n #isConnected = false;\n\n /**\n * Sections currently tracked, by id. Only the *latest reported* intersection\n * flag is stored — never a coordinate. Positions are re-measured when the\n * active section is evaluated, so a section observed several batches ago is\n * never compared against a trigger line computed now.\n */\n #intersectionStates = new Map<string, { element: Element; isIntersecting: boolean }>();\n\n /** Current active section ID; comparing it suppresses duplicate `change` events. */\n #activeSectionId = \"\";\n\n /**\n * Scroll root resolved when the observer was (re)built; `null` = viewport.\n * Cached so a click and every intersection batch reuse the element the\n * observer is actually watching instead of re-querying the document.\n */\n #rootElement: HTMLElement | null = null;\n\n /**\n * The source the `scroll` listener is currently attached to — the resolved\n * root, or the window while the viewport is spied. `null` means \"nothing\n * attached\", so teardown always detaches from the source it attached to\n * rather than from whatever the selector resolves to now.\n */\n #scrollSource: HTMLElement | Window | null = null;\n\n /** Pending re-evaluation frame; coalesces a scroll burst into one measurement. */\n #frame: number | null = null;\n\n /** Watches the link targets' anchor attributes for an in-place morph rewrite. */\n #anchorObserver: MutationObserver | null = null;\n\n /** True while a coalesced observation rebuild is queued; see {@link #scheduleResync}. */\n #resyncQueued = false;\n\n override connect(): void {\n this.#isConnected = true;\n this.#observeAnchorAttributes();\n this.#initializeObserver();\n }\n\n override disconnect(): void {\n this.#isConnected = false;\n // Dropping the flag is what discards a rebuild queued moments ago: the\n // drain reads it, so the queued microtask becomes a no-op.\n this.#resyncQueued = false;\n this.#watcher.stop();\n this.#anchorObserver?.disconnect();\n this.#anchorObserver = null;\n this.#detachScrollListener();\n if (this.#frame !== null) {\n cancelAnimationFrame(this.#frame);\n this.#frame = null;\n }\n this.#intersectionStates.clear();\n this.#activeSectionId = \"\";\n this.#rootElement = null;\n }\n\n /**\n * Re-initializes the observer if the offset or rootMargin values change dynamically.\n */\n offsetValueChanged(): void {\n if (!this.#isConnected) return;\n this.#initializeObserver();\n }\n\n rootMarginValueChanged(): void {\n if (!this.#isConnected) return;\n this.#initializeObserver();\n }\n\n rootSelectorValueChanged(): void {\n if (!this.#isConnected) return;\n this.#initializeObserver();\n }\n\n /**\n * Re-syncs the observation set when a Turbo Stream/morph swaps the table of\n * contents. Stimulus fires these before `connect()` for the links already in\n * the markup, hence the guard: the initial observer is built exactly once, by\n * `connect()`.\n */\n linkTargetConnected(): void {\n if (this.#isConnected) this.#scheduleResync();\n }\n\n linkTargetDisconnected(): void {\n if (this.#isConnected) this.#scheduleResync();\n }\n\n /**\n * Queues **one** observation rebuild for the current mutation batch.\n *\n * A single Turbo morph can append one link, drop another, and rewrite a\n * third's `href`, and those arrive through two independent channels —\n * Stimulus's target callbacks and {@link #anchorObserver}. Each channel just\n * raises the flag and queues a drain; the first drain to run does the work and\n * clears it, so every later drain in the same batch finds nothing to do and\n * the set is rebuilt once instead of three times. `disconnect()` clears the\n * same flag, which is how a queued rebuild is dropped rather than run against\n * a detached controller.\n */\n #scheduleResync(): void {\n this.#resyncQueued = true;\n queueMicrotask(this.#drainResync);\n }\n\n readonly #drainResync = (): void => {\n if (!this.#resyncQueued) return;\n this.#resyncQueued = false;\n this.#initializeObserver();\n };\n\n /**\n * Watches the link targets' anchor attributes so an in-place rewrite re-syncs.\n *\n * A Turbo 8 morph keeps the element **and** its `data-*-target` marker and\n * only rewrites attributes, so Stimulus fires no target callback: without\n * this, a link re-pointed from `#intro` to `#faq` would keep the controller\n * observing `#intro` for the rest of the page's life. The filter is exactly\n * {@link ANCHOR_ATTRIBUTES}; guarding on `MutationObserver` keeps the\n * controller usable where the API is absent, matching `IntersectionWatcher`'s\n * own support guard.\n */\n #observeAnchorAttributes(): void {\n if (typeof MutationObserver !== \"undefined\") {\n this.#anchorObserver = new MutationObserver(this.#onAnchorMutation);\n this.#anchorObserver.observe(this.element, {\n subtree: true,\n attributes: true,\n attributeFilter: ANCHOR_ATTRIBUTES,\n });\n }\n }\n\n /**\n * Rebuilds only for a rewrite on a *current* link target. The observer is\n * scoped to this controller's element, but that subtree also holds links the\n * author never marked as targets (a \"back to top\" anchor, a nested nav), and\n * those anchor nothing here.\n */\n readonly #onAnchorMutation = (records: MutationRecord[]): void => {\n const links = this.linkTargets;\n for (const record of records) {\n if (!links.includes(record.target as HTMLElement)) continue;\n this.#scheduleResync();\n return;\n }\n };\n\n /**\n * Scrolls to the section the clicked link anchors, honoring `offset` and any\n * nested scroll container (a plain fragment jump would scroll the window).\n *\n * Honors `prefers-reduced-motion` (WCAG 2.2 **2.3.3**) by forcing an instant\n * jump independently of the consumer's CSS `scroll-behavior`. With\n * `focusSection` enabled it also moves the sequential focus starting point\n * into the destination; the URL fragment is deliberately not touched.\n */\n scrollTo(event: Event): void {\n const link = event.currentTarget as HTMLElement;\n const id = this.#getAnchorId(link);\n if (!id) return;\n\n event.preventDefault();\n\n const targetElement = document.getElementById(id);\n if (!targetElement) return;\n\n const behavior: ScrollBehavior = prefersReducedMotion() ? \"instant\" : \"smooth\";\n const rootElement = this.#scrollRoot();\n const targetRect = targetElement.getBoundingClientRect();\n const offset = this.#offset;\n\n if (rootElement) {\n const containerRect = rootElement.getBoundingClientRect();\n const scrollPosition = rootElement.scrollTop + (targetRect.top - containerRect.top) - offset;\n\n rootElement.scrollTo({ top: scrollPosition, behavior });\n } else {\n const scrollPosition = window.scrollY + targetRect.top - offset;\n\n window.scrollTo({ top: scrollPosition, behavior });\n }\n\n if (this.focusSectionValue) this.#focusSection(targetElement);\n }\n\n /**\n * Moves the sequential focus starting point into the section `scrollTo` just\n * jumped to, so the next Tab continues *inside* the destination instead of\n * resuming in the table of contents (`preventDefault()` alone would leave the\n * starting point on the link). Opt-in through `focusSection`, because moving\n * focus is a decision only the consuming page can make.\n *\n * `tabindex=\"-1\"` is established only when the section is not already\n * focusable and is never removed, so an author-owned tabindex is left alone.\n * `preventScroll` keeps the focus call from cancelling the smooth scroll\n * started just above.\n */\n #focusSection(section: HTMLElement): void {\n if (!section.hasAttribute(\"tabindex\")) section.setAttribute(\"tabindex\", \"-1\");\n section.focus({ preventScroll: true });\n }\n\n /**\n * The cached scroll root, re-resolved when the cached element has left the\n * document (a Turbo morph replaced the container) so `scrollTo` never\n * scrolls a detached node.\n */\n #scrollRoot(): HTMLElement | null {\n if (this.#rootElement && !this.#rootElement.isConnected) {\n this.#rootElement = this.#queryRootElement();\n }\n return this.#rootElement;\n }\n\n /**\n * Resolves `rootSelector` to a scrollable element.\n *\n * @returns The container, or `null` meaning \"spy the viewport\" when the value\n * is empty, matches nothing, matches a non-HTML element (an SVG node is not a\n * scroll container), or is not a valid selector — a typo in a data attribute\n * must degrade to viewport spying, not leave the controller inert.\n */\n #queryRootElement(): HTMLElement | null {\n if (!this.rootSelectorValue) return null;\n try {\n const root = document.querySelector(this.rootSelectorValue);\n return root instanceof HTMLElement ? root : null;\n } catch {\n return null;\n }\n }\n\n /**\n * Re-evaluates once per frame while the reader scrolls.\n *\n * `IntersectionObserver` reports **threshold crossings**, not positions, so a\n * reader moving inside one long section — or across a gap wider than the\n * observation band — produces no batch at all and the highlight would stay\n * frozen at whatever the last crossing decided. That would make the current\n * location depend on the *route* to a position instead of the position: a\n * stepwise scroll crosses thresholds an instant jump to the same offset never\n * does. Listening to the scroll source closes the gap, and because both paths\n * end in {@link #evaluateActiveSection} — which measures section rects and the\n * root's top edge at that instant — they converge on the same answer.\n */\n readonly #onScroll = (): void => {\n if (this.#frame !== null) return;\n this.#frame = requestAnimationFrame(() => {\n this.#frame = null;\n this.#evaluateActiveSection();\n });\n };\n\n /**\n * Points the `scroll` listener at whatever the reader actually scrolls: the\n * resolved root, or the window when the viewport is spied.\n *\n * The detach is unconditional, so rebuilding the observation set (a Value\n * change, a morph) **moves** the listener rather than stacking a second one on\n * a container the reader has stopped scrolling.\n */\n #syncScrollListener(): void {\n this.#detachScrollListener();\n this.#scrollSource = this.#rootElement ?? window;\n this.#scrollSource.addEventListener(\"scroll\", this.#onScroll, { passive: true });\n }\n\n #detachScrollListener(): void {\n this.#scrollSource?.removeEventListener(\"scroll\", this.#onScroll);\n this.#scrollSource = null;\n }\n\n #initializeObserver(): void {\n this.#watcher.stop();\n this.#intersectionStates.clear();\n // The DOM is the source of truth for the current location **only when this\n // controller has none of its own** — a fresh `connect()`, which is also the\n // Turbo cache-restore case, where the links still carry `aria-current` from\n // the snapshot. Adopting it there makes the observer's first batch a silent\n // confirmation instead of a duplicate `change`.\n //\n // On a *live* rebuild the memory wins, because the DOM has stopped meaning\n // what this controller wrote: an anchor rewritten underneath us leaves\n // `aria-current` on a link that now points somewhere else, so reading it\n // back would hand the current location to a section the reader never\n // scrolled to — and then announce the correction as a `change`, as if they\n // had travelled there and back.\n this.#activeSectionId = this.#activeSectionId || this.#activeIdFromDom();\n this.#rootElement = this.#queryRootElement();\n this.#syncScrollListener();\n\n if (this.linkTargets.length === 0) return;\n\n // Negate the numeric value so a valid negative offset becomes a positive margin.\n const margin = this.rootMarginValue || `${-this.#offset}px 0px -80% 0px`;\n\n // Observe each target section mapped by the href anchors.\n const sections: Element[] = [];\n for (const link of this.linkTargets) {\n const id = this.#getAnchorId(link);\n if (!id) continue;\n const section = document.getElementById(id);\n if (section && !sections.includes(section)) sections.push(section);\n }\n\n this.#watcher.start(sections, {\n root: this.#rootElement,\n rootMargin: margin,\n threshold: [0, 0.2, 0.4, 0.6, 0.8, 1], // Multiple thresholds handle large sections safely\n });\n\n // Republish the adopted location over the *current* link set. Evaluation\n // writes attributes only when the winning section changes, so a link added\n // — or re-anchored — while the reader stays put would otherwise never be\n // marked: a mobile table of contents rendered after the sidebar one would\n // stay blank until the reader happened to cross into another section.\n //\n // Unconditional, including when the adopted location is empty: a link whose\n // anchor was rewritten to something that resolves nowhere cannot be the\n // reader's location, and this controller is the one that published the\n // attribute saying it was, so it is the one that has to take it back.\n this.#syncActiveStates(false);\n }\n\n readonly #onIntersection = (entries: IntersectionObserverEntry[]): void => {\n // Defense in depth. `IntersectionWatcher` already drops a batch the browser\n // flushes after `stop()` (its active/identity guard), so this flag is the\n // second line that keeps a detached controller from mutating `aria-current`\n // on (possibly cached) links.\n const isDetached = !this.#isConnected;\n if (isDetached) return;\n\n for (const entry of entries) {\n const sectionId = entry.target.id;\n if (!sectionId) continue;\n\n this.#intersectionStates.set(sectionId, {\n element: entry.target,\n isIntersecting: entry.isIntersecting,\n });\n }\n\n this.#evaluateActiveSection();\n };\n\n /**\n * Picks the section closest to the trigger line and publishes it.\n *\n * Every coordinate is read **now**: the section rects *and* the root's top\n * edge share one measurement instant. Comparing an entry's recorded\n * `boundingClientRect.top` (captured whenever that section last crossed a\n * threshold) against a freshly computed trigger line mixes two moments in\n * time, which would make the result depend on how the reader arrived at a\n * position — a smooth scroll and an instant jump to the same offset disagree.\n */\n #evaluateActiveSection(): void {\n // The trigger line is `offset` px below the top of the scroll root. When a\n // nested `rootSelector` container is used it is not at the viewport top, so\n // the line must be measured from the container's current top — comparing the\n // viewport-based rect top against a bare `offset` would otherwise pick the\n // section nearest the viewport top, not the container's.\n const rootEl = this.#scrollRoot();\n const triggerLine = (rootEl ? rootEl.getBoundingClientRect().top : 0) + this.#offset;\n\n let intersectingId = \"\";\n let intersectingDistance = Number.POSITIVE_INFINITY;\n let trackedId = \"\";\n let trackedDistance = Number.POSITIVE_INFINITY;\n\n for (const [id, state] of this.#intersectionStates) {\n const rect = state.element.getBoundingClientRect();\n // A section with no layout box (`display: none`, a collapsed `<details>`,\n // an undisplayed Turbo Frame) is reported with an empty rect whose `top`\n // of 0 carries no position at all. Letting it compete would hand it the\n // fallback below; it re-enters the race once it is actually laid out.\n if (rect.width === 0 && rect.height === 0) continue;\n\n const distance = Math.abs(rect.top - triggerLine);\n if (distance < trackedDistance) {\n trackedDistance = distance;\n trackedId = id;\n }\n if (state.isIntersecting && distance < intersectingDistance) {\n intersectingDistance = distance;\n intersectingId = id;\n }\n }\n\n // Fallback: when no section currently intersects (e.g. scrolled past the\n // bottom, or between sections), keep the tracked section whose top is\n // closest to the trigger line so something stays highlighted.\n const bestId = intersectingId || trackedId;\n\n if (bestId && bestId !== this.#activeSectionId) {\n this.#activeSectionId = bestId;\n this.#syncActiveStates(true);\n }\n }\n\n /**\n * Writes `aria-current` across the current link set, optionally announcing.\n *\n * The two halves are separate because they answer different questions.\n * *Attributes* must be idempotently re-established whenever the link set\n * changes, even though the reader has not moved — otherwise a link that\n * appears (or is re-anchored) while its section is already current never gets\n * marked. *The `change` event* announces that the reader moved, so it fires\n * only from the evaluation path; re-publishing over a new link set is not\n * news, and dispatching there would make a rebuild look like navigation.\n *\n * @param announce Whether this sync represents a change of current section.\n */\n #syncActiveStates(announce: boolean): void {\n // Every link anchoring the active section is marked, not just the first:\n // a page may render the same table of contents twice (a sidebar and a\n // collapsed mobile menu) and both must show the current location.\n const activeLinks = this.linkTargets.filter(\n (link) => this.#getAnchorId(link) === this.#activeSectionId,\n );\n\n for (const link of this.linkTargets) {\n if (activeLinks.includes(link)) {\n link.setAttribute(\"aria-current\", \"location\");\n } else if (link.getAttribute(\"aria-current\") === \"location\") {\n // Reclaim only the value this controller publishes, so an author-owned\n // `aria-current=\"page\"` on a table-of-contents link survives.\n link.removeAttribute(\"aria-current\");\n }\n }\n\n if (!announce) return;\n\n const primaryLink = activeLinks[0];\n if (primaryLink) {\n this.dispatch(\"change\", { detail: { id: this.#activeSectionId, link: primaryLink } });\n }\n }\n\n /**\n * The current location already encoded in the DOM, i.e. the section anchored\n * by the first link carrying this controller's `aria-current=\"location\"`.\n * Empty when no link claims it (a genuinely fresh render).\n */\n #activeIdFromDom(): string {\n for (const link of this.linkTargets) {\n if (link.getAttribute(\"aria-current\") !== \"location\") continue;\n const id = this.#getAnchorId(link);\n if (id) return id;\n }\n return \"\";\n }\n\n /**\n * The section id a link anchors, resolved in a fixed order:\n *\n * 1. `href`, when it is a non-empty same-document fragment — the contract.\n * 2. otherwise `data-href`'s fragment — the fallback for a link whose `href`\n * must stay a real URL (a server-rendered permalink) or that is not an\n * `<a>` at all.\n * 3. otherwise `null`: the link anchors nothing here and is not observed.\n *\n * Step 2 is reached whenever `href` yields nothing usable — absent, `\"#\"`, or\n * a real URL — which is the whole point of the fallback: `href=\"/guide/usage\"`\n * with `data-href=\"#usage\"` is a permalink that also spies, and picking the\n * first *present* attribute instead of the first *usable* one would silently\n * exclude exactly that markup. When both are valid fragments `href` wins.\n */\n #getAnchorId(link: HTMLElement): string | null {\n return (\n this.#fragmentId(link.getAttribute(\"href\")) ??\n this.#fragmentId(link.getAttribute(\"data-href\"))\n );\n }\n\n /** The id in a `#fragment` value; `null` for absent, empty, or non-fragment. */\n #fragmentId(value: string | null): string | null {\n if (!value?.startsWith(\"#\")) return null;\n return value.substring(1) || null;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/arrow_step.ts","../../src/utils/attribute_lease.ts","../../src/utils/before_cache_reset.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/stepped_value.ts","../../src/controllers/separator_controller.ts"],"names":["position"],"mappings":";;;;;AA+FO,SAAS,oBAAA,CACd,KAAA,EACA,KAAA,GAAkC,EAAC,EAC1B;AACT,EAAA,IAAI,CAAC,KAAA,CAAM,GAAA,CAAI,UAAA,CAAW,OAAO,GAAG,OAAO,KAAA;AAC3C,EAAA,OACG,KAAA,CAAM,MAAA,IAAU,CAAC,KAAA,CAAM,QAAA,CAAS,KAAK,CAAA,IACrC,KAAA,CAAM,OAAA,IAAW,CAAC,KAAA,CAAM,QAAA,CAAS,MAAM,KACvC,KAAA,CAAM,OAAA,IAAW,CAAC,KAAA,CAAM,QA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AGA,iBAAA,GAA0B;AACxB,IAAA,IAAA,CAAK,KAAA,CAAM,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AAC9B,IAAA,IAAA,CAAK,SAAA,CAAU,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AAClC,IAAA,IAAA,CAAK,YAAA,CAAa,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AACrC,IAAA,IAAA,CAAK,QAAA,CAAS,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AACjC,IAAA,IAAA,CAAK,QAAA,CAAS,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AACjC,IAAA,IAAA,CAAK,QAAA,CAAS,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AAAA,EACnC;AAAA;AAAA,EAGA,eAAA,GAAwB;AACtB,IAAA,IAAA,CAAK,SAAS,MAAA,EAAO;AACrB,IAAA,IAAA,CAAK,iBAAA,EAAkB;AAAA,EACzB;AACF","file":"separator_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","/** One temporarily controlled attribute value and the authored value it displaced. */\ninterface AttributeLeaseRecord {\n readonly original: string | null;\n written: string | null;\n}\n\n/**\n * Temporarily controls one attribute across a changing set of elements.\n *\n * The first write remembers the authored value, including the distinction between\n * an absent attribute and an authored empty string. Returning a lease restores that\n * value only while the attribute still matches the controller's last write. If a\n * consumer changed it in the meantime, the consumer owns the new value and teardown\n * leaves it alone.\n *\n * A `null` write deliberately removes the attribute while retaining the lease. This\n * is useful for derived ARIA whose valid absence is itself controller state, such as\n * an unbounded `aria-valuemin` or a blank spinbutton's `aria-valuenow`.\n *\n * The lease has no lifecycle of its own, so it never subscribes to document events.\n * A consumer that must not let a derived value become the authored baseline of a\n * cached page returns its leases from its own `turbo:before-cache` rewind, where the\n * matching `disconnect()` also releases the subscription.\n */\nexport class AttributeLease<T extends Element = Element> {\n readonly #attribute: string;\n readonly #records = new Map<T, AttributeLeaseRecord>();\n\n /** @param attribute - The attribute whose temporary values this lease owns. */\n constructor(attribute: string) {\n this.#attribute = attribute;\n }\n\n /** Writes or removes the leased attribute while preserving its authored value. */\n write(element: T, value: string | null): void {\n const existing = this.#records.get(element);\n if (existing) {\n existing.written = value;\n } else {\n this.#records.set(element, {\n original: element.getAttribute(this.#attribute),\n written: value,\n });\n }\n\n this.#reflect(element, value);\n }\n\n /** Returns one lease without overwriting a value subsequently authored by a consumer. */\n return(element: T): void {\n const record = this.#records.get(element);\n if (!record) return;\n this.#records.delete(element);\n const stillOwned = element.getAttribute(this.#attribute) === record.written;\n if (stillOwned) this.#reflect(element, record.original);\n }\n\n /** Reflects only a real value transition, avoiding self-triggered mutation work. */\n #reflect(element: T, value: string | null): void {\n if (element.getAttribute(this.#attribute) === value) return;\n if (value === null) element.removeAttribute(this.#attribute);\n else element.setAttribute(this.#attribute, value);\n }\n\n /** Returns every outstanding lease using the same ownership check as {@link return}. */\n returnAll(): void {\n for (const element of Array.from(this.#records.keys())) this.return(element);\n }\n}\n","/**\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 Stimulus lifecycle callbacks from one DOM mutation into a\n * single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element and\n * `<name>ValueChanged` once per changed attribute. Replacing a list of N options\n * or morphing several render Values therefore delivers N callbacks — but the\n * useful unit of work is \"reconcile against the resulting declarative input\",\n * once, after the batch has settled. Every controller with reconcilable targets\n * or render Values needs the same shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers initial target and Value callbacks\n * ahead of `connect()`. Reconciling there would compute output against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\n });\n }\n}\n","/** Configuration for a value constrained to a stepped numeric range. */\nexport interface SteppedRange {\n /** Inclusive lower endpoint. May be infinite for an unbounded control. */\n readonly min: number;\n /** Inclusive upper endpoint. May be infinite for an unbounded control. */\n readonly max: number;\n /** Requested step. Non-finite and non-positive values fall back to `1`. */\n readonly step: number;\n /** Step-grid origin. Defaults to a finite `min`, otherwise `0`. */\n readonly base?: number;\n}\n\n/** The positive finite step used at runtime and by keyboard stepping. */\nexport function effectiveStep(step: number): number {\n return Number.isFinite(step) && step > 0 ? step : 1;\n}\n\n/**\n * Clamps a raw value and selects its nearest allowed value.\n *\n * The allowed set is the step grid plus each finite range endpoint. Keeping the\n * endpoints in that set makes an authored `aria-valuemin`/`aria-valuemax`\n * truthful even when the upper endpoint is not aligned to the grid. A value\n * exactly between two allowed values resolves upward.\n */\nexport function snapSteppedValue(raw: number, range: SteppedRange): number {\n if (!(range.min <= range.max)) return finiteFallback(range.min, range.max);\n\n const input = Number.isNaN(raw) ? finiteFallback(range.min, range.max) : raw;\n const clamped = Math.min(range.max, Math.max(range.min, input));\n const step = effectiveStep(range.step);\n const base = stepBase(range);\n const candidates: number[] = [];\n\n if (Number.isFinite(range.min)) candidates.push(range.min);\n if (Number.isFinite(range.max)) candidates.push(range.max);\n\n const gridPosition = (clamped - base) / step;\n if (Number.isFinite(gridPosition)) {\n addGridCandidate(candidates, Math.floor(gridPosition), range, base, step);\n addGridCandidate(candidates, Math.ceil(gridPosition), range, base, step);\n }\n\n if (candidates.length === 0) return clamped;\n let nearest = candidates[0] as number;\n let nearestDistance = Math.abs(clamped - nearest);\n for (const candidate of candidates.slice(1)) {\n const distance = Math.abs(clamped - candidate);\n if (\n distance < nearestDistance ||\n (nearlyEqual(distance, nearestDistance) && candidate > nearest)\n ) {\n nearest = candidate;\n nearestDistance = distance;\n }\n }\n return nearest;\n}\n\n/**\n * Moves through the ordered allowed-value set by an integer number of steps.\n *\n * This differs from adding `step * count` and snapping afterward at an\n * off-grid endpoint: with `max=94, step=10`, one decrement from `94` must land\n * on `90`, and one increment from `90` must reach the advertised maximum `94`.\n */\nexport function stepSteppedValue(current: number, count: number, range: SteppedRange): number {\n const value = snapSteppedValue(current, range);\n const distance = Math.abs(Math.trunc(count));\n if (!Number.isFinite(distance) || distance === 0) return value;\n const direction = Math.sign(count);\n const adjacent = adjacentSteppedValue(value, direction, range);\n\n // The first move accounts for a possibly off-grid endpoint. From there a\n // direct grid jump is equivalent to repeated adjacency, and avoids work that\n // grows with Page-step magnitudes or programmatic counts.\n const raw = adjacent + direction * (distance - 1) * effectiveStep(range.step);\n return snapSteppedValue(raw, range);\n}\n\n/** Returns the next member of the ordered endpoint-plus-grid set. */\nfunction adjacentSteppedValue(current: number, direction: number, range: SteppedRange): number {\n const step = effectiveStep(range.step);\n const base = stepBase(range);\n const candidates: number[] = [];\n\n if (direction > 0) {\n const position = (current - base) / step;\n if (Number.isFinite(position)) {\n let gridIndex = Math.floor(position) + 1;\n let candidate = cleanGridValue(base + gridIndex * step, base, step);\n if (candidate < current || nearlyEqual(candidate, current)) {\n gridIndex += 1;\n candidate = cleanGridValue(base + gridIndex * step, base, step);\n }\n if (\n candidate > current &&\n !nearlyEqual(candidate, current) &&\n within(candidate, range.min, range.max)\n ) {\n candidates.push(clamp(candidate, range));\n }\n }\n return clamp(Math.min(...candidates), range);\n }\n\n const position = (current - base) / step;\n if (Number.isFinite(position)) {\n let gridIndex = Math.ceil(position) - 1;\n let candidate = cleanGridValue(base + gridIndex * step, base, step);\n if (candidate > current || nearlyEqual(candidate, current)) {\n gridIndex -= 1;\n candidate = cleanGridValue(base + gridIndex * step, base, step);\n }\n if (\n candidate < current &&\n !nearlyEqual(candidate, current) &&\n within(candidate, range.min, range.max)\n ) {\n candidates.push(clamp(candidate, range));\n }\n }\n return clamp(Math.max(...candidates), range);\n}\n\n/** Adds one grid value when it falls inside the inclusive range. */\nfunction addGridCandidate(\n candidates: number[],\n index: number,\n range: SteppedRange,\n base: number,\n step: number,\n): void {\n const candidate = cleanGridValue(base + index * step, base, step);\n if (within(candidate, range.min, range.max)) candidates.push(clamp(candidate, range));\n}\n\n/** A finite authored base wins; otherwise the finite lower bound or zero does. */\nfunction stepBase(range: SteppedRange): number {\n if (range.base !== undefined && Number.isFinite(range.base)) return range.base;\n return Number.isFinite(range.min) ? range.min : 0;\n}\n\n/** Removes binary noise without discarding significant integer-place digits. */\nfunction cleanGridValue(value: number, base: number, step: number): number {\n const precision = Math.max(decimalPlaces(base), decimalPlaces(step));\n // `toFixed` accepts at most 100 fractional digits. Below that limit it rounds\n // according to the authored grid precision rather than an arbitrary total\n // significant-digit count, which keeps unit steps distinct at large bases.\n return precision <= 100 ? Number(value.toFixed(precision)) : value;\n}\n\n/** Number of fractional decimal places represented by a finite JS number. */\nfunction decimalPlaces(value: number): number {\n const [coefficient = \"\", exponentText] = Math.abs(value).toString().toLowerCase().split(\"e\");\n const fractionLength = coefficient.split(\".\")[1]?.length ?? 0;\n const exponent = exponentText === undefined ? 0 : Number(exponentText);\n return Math.max(0, fractionLength - exponent);\n}\n\n/** Inclusive range check tolerant only of arithmetic noise at an endpoint. */\nfunction within(value: number, min: number, max: number): boolean {\n return (value > min || nearlyEqual(value, min)) && (value < max || nearlyEqual(value, max));\n}\n\n/** Clamps a candidate whose only overshoot may be floating-point noise. */\nfunction clamp(value: number, range: SteppedRange): number {\n return Math.min(range.max, Math.max(range.min, value));\n}\n\n/** Relative comparison used only to collapse arithmetic noise, not real steps. */\nfunction nearlyEqual(left: number, right: number): boolean {\n const scale = Math.max(Math.abs(left), Math.abs(right));\n return (\n Number.isFinite(left) &&\n Number.isFinite(right) &&\n Math.abs(left - right) <= Number.EPSILON * scale\n );\n}\n\n/** Stable fallback for malformed ranges or `NaN` input. */\nfunction finiteFallback(min: number, max: number): number {\n if (Number.isFinite(min)) return min;\n if (Number.isFinite(max)) return max;\n return 0;\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\nimport { AttributeLease } from \"../utils/attribute_lease\";\nimport { BeforeCacheReset } from \"../utils/before_cache_reset\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\nimport { type SteppedRange, snapSteppedValue, stepSteppedValue } from \"../utils/stepped_value\";\n\nconst DEFAULT_MIN = 0;\nconst DEFAULT_MAX = 100;\n\n/**\n * Headless **Separator** behavior. The normative source depends on the case:\n * a decorative divider follows the WAI-ARIA `separator` role\n * (https://www.w3.org/TR/wai-aria-1.2/#separator), while the focusable,\n * value-bearing divider follows the APG Window Splitter pattern\n * (https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/).\n *\n * Markup contract (identifier: `stimeo--separator`):\n * <!-- decorative -->\n * <div data-controller=\"stimeo--separator\"\n * data-stimeo--separator-orientation-value=\"horizontal\"></div>\n *\n * <!-- focusable, value-bearing -->\n * <div data-controller=\"stimeo--separator\"\n * aria-labelledby=\"sidebar-heading\" aria-controls=\"sidebar\"\n * data-stimeo--separator-orientation-value=\"vertical\"\n * data-stimeo--separator-focusable-value=\"true\"\n * data-stimeo--separator-min-value=\"0\"\n * data-stimeo--separator-max-value=\"100\"\n * data-stimeo--separator-step-value=\"1\"\n * data-stimeo--separator-value-value=\"50\"\n * data-action=\"keydown->stimeo--separator#onKeydown\"></div>\n *\n * The Stimulus Values are the live inputs. The controller reflects them as\n * `role`, `tabindex`, `aria-orientation`, and the range ARIA while connected,\n * then restores the attributes it displaced on disconnect and before Turbo\n * caches the page. Existing finite range ARIA is hydrated into otherwise\n * absent Values once, which preserves progressively enhanced server markup\n * without leaving two live sources of truth.\n *\n * `change` dispatches `{ value: number }`.\n *\n * @remarks\n * Behavior only — line drawing is the consumer's CSS. The axis follows Window\n * Splitter: a vertical divider takes ArrowLeft/ArrowRight, a horizontal one\n * takes ArrowUp/ArrowDown. Which end counts as an increase is not defined\n * there, so it follows the slider convention (ArrowRight/ArrowUp increase).\n * Home/End are optional in the pattern and are implemented here; F6 is not.\n *\n * Runtime Value changes repaint silently. A maximum below the effective\n * minimum collapses to that minimum; non-finite bounds use `0`/`100`, and an\n * invalid or non-positive step uses `1`. Finite endpoints remain reachable even\n * when they do not align to the step grid.\n *\n * Because no position is ever applied here, two Window Splitter requirements\n * fall to the consumer: `aria-controls` naming the **primary** pane — the one\n * whose size the value reports — and `Enter` to toggle collapse/restore, since\n * collapsing applies a position — {@link ResizableController} implements that\n * key for the same divider. Because the increment direction is fixed, the\n * primary pane can only be the left one for a vertical splitter and the bottom\n * one for a horizontal splitter: those are the panes that grow as\n * ArrowRight/ArrowUp raise the value.\n */\nexport class SeparatorController extends Controller<HTMLElement> {\n static override values = {\n orientation: { type: String, default: \"horizontal\" },\n focusable: { type: Boolean, default: false },\n min: { type: Number, default: DEFAULT_MIN },\n max: { type: Number, default: DEFAULT_MAX },\n step: { type: Number, default: 1 },\n value: { type: Number, default: DEFAULT_MIN },\n };\n static actions = [\"onKeydown\"] as const;\n static events = [\"change\"] as const;\n\n declare orientationValue: string;\n declare focusableValue: boolean;\n declare minValue: number;\n declare maxValue: number;\n declare stepValue: number;\n declare valueValue: number;\n\n readonly #role = new AttributeLease<HTMLElement>(\"role\");\n readonly #tabindex = new AttributeLease<HTMLElement>(\"tabindex\");\n readonly #orientation = new AttributeLease<HTMLElement>(\"aria-orientation\");\n readonly #minimum = new AttributeLease<HTMLElement>(\"aria-valuemin\");\n readonly #maximum = new AttributeLease<HTMLElement>(\"aria-valuemax\");\n readonly #current = new AttributeLease<HTMLElement>(\"aria-valuenow\");\n\n /** Collapses a morph that changes several render Values into one silent repaint. */\n readonly #repaint = new MicrotaskCoalescer(() => this.#render());\n\n /** Restores authored semantics before Turbo snapshots the element. */\n readonly #beforeCache = new BeforeCacheReset(() => this.#rewindForCache());\n\n /** Hydrates legacy ARIA input once, normalizes the current Value, and renders. */\n override connect(): void {\n this.#hydrateValues();\n this.#repaint.activate();\n this.#beforeCache.activate();\n const value = this.#currentValue();\n if (!Object.is(this.valueValue, value)) this.valueValue = value;\n this.#render();\n }\n\n /** Cancels repaint work and returns every semantic attribute this instance controlled. */\n override disconnect(): void {\n this.#repaint.cancel();\n this.#beforeCache.deactivate();\n this.#returnAttributes();\n }\n\n /** Silently repaints an orientation changed by application code or a Turbo morph. */\n orientationValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Silently adds or removes the focusable range semantics at runtime. */\n focusableValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Silently repaints a minimum changed by application code or a Turbo morph. */\n minValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Silently repaints a maximum changed by application code or a Turbo morph. */\n maxValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Silently repaints a step changed by application code or a Turbo morph. */\n stepValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Silently repaints a current value changed by application code or a Turbo morph. */\n valueValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Adjusts the value on arrow / Home / End keys (focusable variant only). */\n onKeydown(event: KeyboardEvent): void {\n if (isReservedArrowChord(event) || !this.focusableValue) return;\n\n const horizontal = this.#effectiveOrientation === \"horizontal\";\n const range = this.#effectiveRange;\n const current = snapSteppedValue(this.valueValue, range);\n let next: number | null = null;\n switch (event.key) {\n case \"ArrowUp\":\n if (horizontal) next = stepSteppedValue(current, 1, range);\n break;\n case \"ArrowDown\":\n if (horizontal) next = stepSteppedValue(current, -1, range);\n break;\n case \"ArrowRight\":\n if (!horizontal) next = stepSteppedValue(current, 1, range);\n break;\n case \"ArrowLeft\":\n if (!horizontal) next = stepSteppedValue(current, -1, range);\n break;\n case \"Home\":\n next = range.min;\n break;\n case \"End\":\n next = range.max;\n break;\n default:\n return;\n }\n if (next === null) return;\n\n event.preventDefault();\n this.#commit(next, current);\n }\n\n /** Stores a normalized user value, renders immediately, and reports real changes. */\n #commit(raw: number, previous: number): void {\n const value = snapSteppedValue(raw, this.#effectiveRange);\n if (!Object.is(this.valueValue, value)) this.valueValue = value;\n this.#render();\n if (value !== previous) this.dispatch(\"change\", { detail: { value } });\n }\n\n /**\n * Reflects live Values into the connected element without dispatching.\n *\n * @stimeoRenderRoot\n */\n #render(): void {\n const range = this.#effectiveRange;\n const value = snapSteppedValue(this.valueValue, range);\n this.#role.write(this.element, \"separator\");\n this.#orientation.write(this.element, this.#effectiveOrientation);\n\n if (!this.focusableValue) {\n this.#tabindex.write(this.element, null);\n this.#minimum.write(this.element, null);\n this.#maximum.write(this.element, null);\n this.#current.write(this.element, null);\n return;\n }\n\n this.#tabindex.write(this.element, \"0\");\n this.#minimum.write(this.element, String(range.min));\n this.#maximum.write(this.element, String(range.max));\n this.#current.write(this.element, String(value));\n }\n\n /** Effective orientation; unknown strings fall back to the horizontal contract. */\n get #effectiveOrientation(): \"horizontal\" | \"vertical\" {\n return this.orientationValue === \"vertical\" ? \"vertical\" : \"horizontal\";\n }\n\n /** Finite, ordered range shared by rendering and keyboard stepping. */\n get #effectiveRange(): SteppedRange {\n const min = Number.isFinite(this.minValue) ? this.minValue : DEFAULT_MIN;\n const candidateMax = Number.isFinite(this.maxValue) ? this.maxValue : DEFAULT_MAX;\n return {\n min,\n max: Math.max(min, candidateMax),\n step: this.stepValue,\n base: min,\n };\n }\n\n /** Current normalized value derived from the live declarative inputs. */\n #currentValue(): number {\n return snapSteppedValue(this.valueValue, this.#effectiveRange);\n }\n\n /** Copies valid authored ARIA into Values only when no explicit Value exists. */\n #hydrateValues(): void {\n if (!this.#hasInput(\"orientation\")) {\n const orientation = this.element.getAttribute(\"aria-orientation\");\n if (orientation === \"horizontal\" || orientation === \"vertical\") {\n this.orientationValue = orientation;\n }\n }\n\n const min = this.#finiteAttribute(\"aria-valuemin\");\n if (!this.#hasInput(\"min\") && min !== null) this.minValue = min;\n const max = this.#finiteAttribute(\"aria-valuemax\");\n if (!this.#hasInput(\"max\") && max !== null) this.maxValue = max;\n const value = this.#finiteAttribute(\"aria-valuenow\");\n if (!this.#hasInput(\"value\") && value !== null) this.valueValue = value;\n }\n\n /** Whether the author supplied the namespaced Value instead of using its default. */\n #hasInput(name: \"orientation\" | \"min\" | \"max\" | \"value\"): boolean {\n return this.element.hasAttribute(`data-${this.identifier}-${name}-value`);\n }\n\n /** Strict finite-number parser for the one-time progressive-enhancement bridge. */\n #finiteAttribute(name: string): number | null {\n const raw = this.element.getAttribute(name);\n if (raw === null || raw.trim() === \"\") return null;\n const value = Number(raw);\n return Number.isFinite(value) ? value : null;\n }\n\n /** Returns attributes without overwriting values a consumer changed after render. */\n #returnAttributes(): void {\n this.#role.return(this.element);\n this.#tabindex.return(this.element);\n this.#orientation.return(this.element);\n this.#minimum.return(this.element);\n this.#maximum.return(this.element);\n this.#current.return(this.element);\n }\n\n /** Prevents a queued Value repaint from racing Turbo's restored snapshot. */\n #rewindForCache(): void {\n this.#repaint.cancel();\n this.#returnAttributes();\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/arrow_step.ts","../../src/utils/attribute_lease.ts","../../src/utils/before_cache_reset.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/stepped_value.ts","../../src/controllers/separator_controller.ts"],"names":["position"],"mappings":";;;;;AA+FO,SAAS,oBAAA,CACd,KAAA,EACA,KAAA,GAAkC,EAAC,EAC1B;AACT,EAAA,IAAI,CAAC,KAAA,CAAM,GAAA,CAAI,UAAA,CAAW,OAAO,GAAG,OAAO,KAAA;AAC3C,EAAA,OACG,KAAA,CAAM,MAAA,IAAU,CAAC,KAAA,CAAM,QAAA,CAAS,KAAK,CAAA,IACrC,KAAA,CAAM,OAAA,IAAW,CAAC,KAAA,CAAM,QAAA,CAAS,MAAM,KACvC,KAAA,CAAM,OAAA,IAAW,CAAC,KAAA,CAAM,QAAA,CAAS,MAAM,CAAA,IACvC,KAAA,CAAM,QAAA,IAAY,CAAC,KAAA,CAAM,QAAA,CAAS,OAAO,CAAA;AAE9C;;;AClFO,IAAM,iB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AAA,CAAU,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AAClC,IAAA,IAAA,CAAK,YAAA,CAAa,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AACrC,IAAA,IAAA,CAAK,QAAA,CAAS,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AACjC,IAAA,IAAA,CAAK,QAAA,CAAS,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AACjC,IAAA,IAAA,CAAK,QAAA,CAAS,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AAAA,EACnC;AAAA;AAAA,EAGA,eAAA,GAAwB;AACtB,IAAA,IAAA,CAAK,SAAS,MAAA,EAAO;AACrB,IAAA,IAAA,CAAK,iBAAA,EAAkB;AAAA,EACzB;AACF","file":"separator_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/**\n * True when a press arrived carrying any modifier, for the keys the browser and\n * the OS own outright: return without calling `preventDefault()` and without\n * moving any state.\n *\n * `Control+Home` and `Control+End` jump the document to its ends, and a widget\n * that swallows them makes the shortcut work or not depending on where focus\n * happens to sit. {@link isReservedArrowChord} answers the same question for the\n * arrows, but returns `false` for every other key so that this one can decide.\n *\n * There is no `allow` list here on purpose. APG assigns no modifier chord to\n * `Home`/`End`, so a widget that wanted one would be claiming a combination the\n * pattern never gave it.\n *\n * @example\n * ```ts\n * case \"Home\":\n * case \"End\":\n * if (hasModifierChord(event)) return;\n * ```\n */\nexport function hasModifierChord(event: KeyboardEvent): boolean {\n return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;\n}\n","/** One temporarily controlled attribute value and the authored value it displaced. */\ninterface AttributeLeaseRecord {\n readonly original: string | null;\n written: string | null;\n}\n\n/**\n * Temporarily controls one attribute across a changing set of elements.\n *\n * The first write remembers the authored value, including the distinction between\n * an absent attribute and an authored empty string. Returning a lease restores that\n * value only while the attribute still matches the controller's last write. If a\n * consumer changed it in the meantime, the consumer owns the new value and teardown\n * leaves it alone.\n *\n * A `null` write deliberately removes the attribute while retaining the lease. This\n * is useful for derived ARIA whose valid absence is itself controller state, such as\n * an unbounded `aria-valuemin` or a blank spinbutton's `aria-valuenow`.\n *\n * The lease has no lifecycle of its own, so it never subscribes to document events.\n * A consumer that must not let a derived value become the authored baseline of a\n * cached page returns its leases from its own `turbo:before-cache` rewind, where the\n * matching `disconnect()` also releases the subscription.\n */\nexport class AttributeLease<T extends Element = Element> {\n readonly #attribute: string;\n readonly #records = new Map<T, AttributeLeaseRecord>();\n\n /** @param attribute - The attribute whose temporary values this lease owns. */\n constructor(attribute: string) {\n this.#attribute = attribute;\n }\n\n /** Writes or removes the leased attribute while preserving its authored value. */\n write(element: T, value: string | null): void {\n const existing = this.#records.get(element);\n if (existing) {\n existing.written = value;\n } else {\n this.#records.set(element, {\n original: element.getAttribute(this.#attribute),\n written: value,\n });\n }\n\n this.#reflect(element, value);\n }\n\n /** Returns one lease without overwriting a value subsequently authored by a consumer. */\n return(element: T): void {\n const record = this.#records.get(element);\n if (!record) return;\n this.#records.delete(element);\n const stillOwned = element.getAttribute(this.#attribute) === record.written;\n if (stillOwned) this.#reflect(element, record.original);\n }\n\n /** Reflects only a real value transition, avoiding self-triggered mutation work. */\n #reflect(element: T, value: string | null): void {\n if (element.getAttribute(this.#attribute) === value) return;\n if (value === null) element.removeAttribute(this.#attribute);\n else element.setAttribute(this.#attribute, value);\n }\n\n /** Returns every outstanding lease using the same ownership check as {@link return}. */\n returnAll(): void {\n for (const element of Array.from(this.#records.keys())) this.return(element);\n }\n}\n","/**\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.\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 Stimulus lifecycle callbacks from one DOM mutation into a\n * single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element and\n * `<name>ValueChanged` once per changed attribute. Replacing a list of N options\n * or morphing several render Values therefore delivers N callbacks — but the\n * useful unit of work is \"reconcile against the resulting declarative input\",\n * once, after the batch has settled. Every controller with reconcilable targets\n * or render Values needs the same shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers initial target and Value callbacks\n * ahead of `connect()`. Reconciling there would compute output against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\n });\n }\n}\n","/** Configuration for a value constrained to a stepped numeric range. */\nexport interface SteppedRange {\n /** Inclusive lower endpoint. May be infinite for an unbounded control. */\n readonly min: number;\n /** Inclusive upper endpoint. May be infinite for an unbounded control. */\n readonly max: number;\n /** Requested step. Non-finite and non-positive values fall back to `1`. */\n readonly step: number;\n /** Step-grid origin. Defaults to a finite `min`, otherwise `0`. */\n readonly base?: number;\n}\n\n/** The positive finite step used at runtime and by keyboard stepping. */\nexport function effectiveStep(step: number): number {\n return Number.isFinite(step) && step > 0 ? step : 1;\n}\n\n/**\n * Clamps a raw value and selects its nearest allowed value.\n *\n * The allowed set is the step grid plus each finite range endpoint. Keeping the\n * endpoints in that set makes an authored `aria-valuemin`/`aria-valuemax`\n * truthful even when the upper endpoint is not aligned to the grid. A value\n * exactly between two allowed values resolves upward.\n */\nexport function snapSteppedValue(raw: number, range: SteppedRange): number {\n if (!(range.min <= range.max)) return finiteFallback(range.min, range.max);\n\n const input = Number.isNaN(raw) ? finiteFallback(range.min, range.max) : raw;\n const clamped = Math.min(range.max, Math.max(range.min, input));\n const step = effectiveStep(range.step);\n const base = stepBase(range);\n const candidates: number[] = [];\n\n if (Number.isFinite(range.min)) candidates.push(range.min);\n if (Number.isFinite(range.max)) candidates.push(range.max);\n\n const gridPosition = (clamped - base) / step;\n if (Number.isFinite(gridPosition)) {\n addGridCandidate(candidates, Math.floor(gridPosition), range, base, step);\n addGridCandidate(candidates, Math.ceil(gridPosition), range, base, step);\n }\n\n if (candidates.length === 0) return clamped;\n let nearest = candidates[0] as number;\n let nearestDistance = Math.abs(clamped - nearest);\n for (const candidate of candidates.slice(1)) {\n const distance = Math.abs(clamped - candidate);\n if (\n distance < nearestDistance ||\n (nearlyEqual(distance, nearestDistance) && candidate > nearest)\n ) {\n nearest = candidate;\n nearestDistance = distance;\n }\n }\n return nearest;\n}\n\n/**\n * Moves through the ordered allowed-value set by an integer number of steps.\n *\n * This differs from adding `step * count` and snapping afterward at an\n * off-grid endpoint: with `max=94, step=10`, one decrement from `94` must land\n * on `90`, and one increment from `90` must reach the advertised maximum `94`.\n */\nexport function stepSteppedValue(current: number, count: number, range: SteppedRange): number {\n const value = snapSteppedValue(current, range);\n const distance = Math.abs(Math.trunc(count));\n if (!Number.isFinite(distance) || distance === 0) return value;\n const direction = Math.sign(count);\n const adjacent = adjacentSteppedValue(value, direction, range);\n\n // The first move accounts for a possibly off-grid endpoint. From there a\n // direct grid jump is equivalent to repeated adjacency, and avoids work that\n // grows with Page-step magnitudes or programmatic counts.\n const raw = adjacent + direction * (distance - 1) * effectiveStep(range.step);\n return snapSteppedValue(raw, range);\n}\n\n/** Returns the next member of the ordered endpoint-plus-grid set. */\nfunction adjacentSteppedValue(current: number, direction: number, range: SteppedRange): number {\n const step = effectiveStep(range.step);\n const base = stepBase(range);\n const candidates: number[] = [];\n\n if (direction > 0) {\n const position = (current - base) / step;\n if (Number.isFinite(position)) {\n let gridIndex = Math.floor(position) + 1;\n let candidate = cleanGridValue(base + gridIndex * step, base, step);\n if (candidate < current || nearlyEqual(candidate, current)) {\n gridIndex += 1;\n candidate = cleanGridValue(base + gridIndex * step, base, step);\n }\n if (\n candidate > current &&\n !nearlyEqual(candidate, current) &&\n within(candidate, range.min, range.max)\n ) {\n candidates.push(clamp(candidate, range));\n }\n }\n return clamp(Math.min(...candidates), range);\n }\n\n const position = (current - base) / step;\n if (Number.isFinite(position)) {\n let gridIndex = Math.ceil(position) - 1;\n let candidate = cleanGridValue(base + gridIndex * step, base, step);\n if (candidate > current || nearlyEqual(candidate, current)) {\n gridIndex -= 1;\n candidate = cleanGridValue(base + gridIndex * step, base, step);\n }\n if (\n candidate < current &&\n !nearlyEqual(candidate, current) &&\n within(candidate, range.min, range.max)\n ) {\n candidates.push(clamp(candidate, range));\n }\n }\n return clamp(Math.max(...candidates), range);\n}\n\n/** Adds one grid value when it falls inside the inclusive range. */\nfunction addGridCandidate(\n candidates: number[],\n index: number,\n range: SteppedRange,\n base: number,\n step: number,\n): void {\n const candidate = cleanGridValue(base + index * step, base, step);\n if (within(candidate, range.min, range.max)) candidates.push(clamp(candidate, range));\n}\n\n/** A finite authored base wins; otherwise the finite lower bound or zero does. */\nfunction stepBase(range: SteppedRange): number {\n if (range.base !== undefined && Number.isFinite(range.base)) return range.base;\n return Number.isFinite(range.min) ? range.min : 0;\n}\n\n/** Removes binary noise without discarding significant integer-place digits. */\nfunction cleanGridValue(value: number, base: number, step: number): number {\n const precision = Math.max(decimalPlaces(base), decimalPlaces(step));\n // `toFixed` accepts at most 100 fractional digits. Below that limit it rounds\n // according to the authored grid precision rather than an arbitrary total\n // significant-digit count, which keeps unit steps distinct at large bases.\n return precision <= 100 ? Number(value.toFixed(precision)) : value;\n}\n\n/** Number of fractional decimal places represented by a finite JS number. */\nfunction decimalPlaces(value: number): number {\n const [coefficient = \"\", exponentText] = Math.abs(value).toString().toLowerCase().split(\"e\");\n const fractionLength = coefficient.split(\".\")[1]?.length ?? 0;\n const exponent = exponentText === undefined ? 0 : Number(exponentText);\n return Math.max(0, fractionLength - exponent);\n}\n\n/** Inclusive range check tolerant only of arithmetic noise at an endpoint. */\nfunction within(value: number, min: number, max: number): boolean {\n return (value > min || nearlyEqual(value, min)) && (value < max || nearlyEqual(value, max));\n}\n\n/** Clamps a candidate whose only overshoot may be floating-point noise. */\nfunction clamp(value: number, range: SteppedRange): number {\n return Math.min(range.max, Math.max(range.min, value));\n}\n\n/** Relative comparison used only to collapse arithmetic noise, not real steps. */\nfunction nearlyEqual(left: number, right: number): boolean {\n const scale = Math.max(Math.abs(left), Math.abs(right));\n return (\n Number.isFinite(left) &&\n Number.isFinite(right) &&\n Math.abs(left - right) <= Number.EPSILON * scale\n );\n}\n\n/** Stable fallback for malformed ranges or `NaN` input. */\nfunction finiteFallback(min: number, max: number): number {\n if (Number.isFinite(min)) return min;\n if (Number.isFinite(max)) return max;\n return 0;\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\nimport { AttributeLease } from \"../utils/attribute_lease\";\nimport { BeforeCacheReset } from \"../utils/before_cache_reset\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\nimport { type SteppedRange, snapSteppedValue, stepSteppedValue } from \"../utils/stepped_value\";\n\nconst DEFAULT_MIN = 0;\nconst DEFAULT_MAX = 100;\n\n/**\n * Headless **Separator** behavior. The normative source depends on the case:\n * a decorative divider follows the WAI-ARIA `separator` role\n * (https://www.w3.org/TR/wai-aria-1.2/#separator), while the focusable,\n * value-bearing divider follows the APG Window Splitter pattern\n * (https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/).\n *\n * Markup contract (identifier: `stimeo--separator`):\n * <!-- decorative -->\n * <div data-controller=\"stimeo--separator\"\n * data-stimeo--separator-orientation-value=\"horizontal\"></div>\n *\n * <!-- focusable, value-bearing -->\n * <div data-controller=\"stimeo--separator\"\n * aria-labelledby=\"sidebar-heading\" aria-controls=\"sidebar\"\n * data-stimeo--separator-orientation-value=\"vertical\"\n * data-stimeo--separator-focusable-value=\"true\"\n * data-stimeo--separator-min-value=\"0\"\n * data-stimeo--separator-max-value=\"100\"\n * data-stimeo--separator-step-value=\"1\"\n * data-stimeo--separator-value-value=\"50\"\n * data-action=\"keydown->stimeo--separator#onKeydown\"></div>\n *\n * The Stimulus Values are the live inputs. The controller reflects them as\n * `role`, `tabindex`, `aria-orientation`, and the range ARIA while connected,\n * then restores the attributes it displaced on disconnect and before Turbo\n * caches the page. Existing finite range ARIA is hydrated into otherwise\n * absent Values once, which preserves progressively enhanced server markup\n * without leaving two live sources of truth.\n *\n * `change` dispatches `{ value: number }`.\n *\n * @remarks\n * Behavior only — line drawing is the consumer's CSS. The axis follows Window\n * Splitter: a vertical divider takes ArrowLeft/ArrowRight, a horizontal one\n * takes ArrowUp/ArrowDown. Which end counts as an increase is not defined\n * there, so it follows the slider convention (ArrowRight/ArrowUp increase).\n * Home/End are optional in the pattern and are implemented here; F6 is not.\n *\n * Runtime Value changes repaint silently. A maximum below the effective\n * minimum collapses to that minimum; non-finite bounds use `0`/`100`, and an\n * invalid or non-positive step uses `1`. Finite endpoints remain reachable even\n * when they do not align to the step grid.\n *\n * Because no position is ever applied here, two Window Splitter requirements\n * fall to the consumer: `aria-controls` naming the **primary** pane — the one\n * whose size the value reports — and `Enter` to toggle collapse/restore, since\n * collapsing applies a position — {@link ResizableController} implements that\n * key for the same divider. Because the increment direction is fixed, the\n * primary pane can only be the left one for a vertical splitter and the bottom\n * one for a horizontal splitter: those are the panes that grow as\n * ArrowRight/ArrowUp raise the value.\n */\nexport class SeparatorController extends Controller<HTMLElement> {\n static override values = {\n orientation: { type: String, default: \"horizontal\" },\n focusable: { type: Boolean, default: false },\n min: { type: Number, default: DEFAULT_MIN },\n max: { type: Number, default: DEFAULT_MAX },\n step: { type: Number, default: 1 },\n value: { type: Number, default: DEFAULT_MIN },\n };\n static actions = [\"onKeydown\"] as const;\n static events = [\"change\"] as const;\n\n declare orientationValue: string;\n declare focusableValue: boolean;\n declare minValue: number;\n declare maxValue: number;\n declare stepValue: number;\n declare valueValue: number;\n\n readonly #role = new AttributeLease<HTMLElement>(\"role\");\n readonly #tabindex = new AttributeLease<HTMLElement>(\"tabindex\");\n readonly #orientation = new AttributeLease<HTMLElement>(\"aria-orientation\");\n readonly #minimum = new AttributeLease<HTMLElement>(\"aria-valuemin\");\n readonly #maximum = new AttributeLease<HTMLElement>(\"aria-valuemax\");\n readonly #current = new AttributeLease<HTMLElement>(\"aria-valuenow\");\n\n /** Collapses a morph that changes several render Values into one silent repaint. */\n readonly #repaint = new MicrotaskCoalescer(() => this.#render());\n\n /** Restores authored semantics before Turbo snapshots the element. */\n readonly #beforeCache = new BeforeCacheReset(() => this.#rewindForCache());\n\n /** Hydrates legacy ARIA input once, normalizes the current Value, and renders. */\n override connect(): void {\n this.#hydrateValues();\n this.#repaint.activate();\n this.#beforeCache.activate();\n const value = this.#currentValue();\n if (!Object.is(this.valueValue, value)) this.valueValue = value;\n this.#render();\n }\n\n /** Cancels repaint work and returns every semantic attribute this instance controlled. */\n override disconnect(): void {\n this.#repaint.cancel();\n this.#beforeCache.deactivate();\n this.#returnAttributes();\n }\n\n /** Silently repaints an orientation changed by application code or a Turbo morph. */\n orientationValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Silently adds or removes the focusable range semantics at runtime. */\n focusableValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Silently repaints a minimum changed by application code or a Turbo morph. */\n minValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Silently repaints a maximum changed by application code or a Turbo morph. */\n maxValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Silently repaints a step changed by application code or a Turbo morph. */\n stepValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Silently repaints a current value changed by application code or a Turbo morph. */\n valueValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Adjusts the value on arrow / Home / End keys (focusable variant only). */\n onKeydown(event: KeyboardEvent): void {\n if (isReservedArrowChord(event) || !this.focusableValue) return;\n\n const horizontal = this.#effectiveOrientation === \"horizontal\";\n const range = this.#effectiveRange;\n const current = snapSteppedValue(this.valueValue, range);\n let next: number | null = null;\n switch (event.key) {\n case \"ArrowUp\":\n if (horizontal) next = stepSteppedValue(current, 1, range);\n break;\n case \"ArrowDown\":\n if (horizontal) next = stepSteppedValue(current, -1, range);\n break;\n case \"ArrowRight\":\n if (!horizontal) next = stepSteppedValue(current, 1, range);\n break;\n case \"ArrowLeft\":\n if (!horizontal) next = stepSteppedValue(current, -1, range);\n break;\n case \"Home\":\n next = range.min;\n break;\n case \"End\":\n next = range.max;\n break;\n default:\n return;\n }\n if (next === null) return;\n\n event.preventDefault();\n this.#commit(next, current);\n }\n\n /** Stores a normalized user value, renders immediately, and reports real changes. */\n #commit(raw: number, previous: number): void {\n const value = snapSteppedValue(raw, this.#effectiveRange);\n if (!Object.is(this.valueValue, value)) this.valueValue = value;\n this.#render();\n if (value !== previous) this.dispatch(\"change\", { detail: { value } });\n }\n\n /**\n * Reflects live Values into the connected element without dispatching.\n *\n * @stimeoRenderRoot\n */\n #render(): void {\n const range = this.#effectiveRange;\n const value = snapSteppedValue(this.valueValue, range);\n this.#role.write(this.element, \"separator\");\n this.#orientation.write(this.element, this.#effectiveOrientation);\n\n if (!this.focusableValue) {\n this.#tabindex.write(this.element, null);\n this.#minimum.write(this.element, null);\n this.#maximum.write(this.element, null);\n this.#current.write(this.element, null);\n return;\n }\n\n this.#tabindex.write(this.element, \"0\");\n this.#minimum.write(this.element, String(range.min));\n this.#maximum.write(this.element, String(range.max));\n this.#current.write(this.element, String(value));\n }\n\n /** Effective orientation; unknown strings fall back to the horizontal contract. */\n get #effectiveOrientation(): \"horizontal\" | \"vertical\" {\n return this.orientationValue === \"vertical\" ? \"vertical\" : \"horizontal\";\n }\n\n /** Finite, ordered range shared by rendering and keyboard stepping. */\n get #effectiveRange(): SteppedRange {\n const min = Number.isFinite(this.minValue) ? this.minValue : DEFAULT_MIN;\n const candidateMax = Number.isFinite(this.maxValue) ? this.maxValue : DEFAULT_MAX;\n return {\n min,\n max: Math.max(min, candidateMax),\n step: this.stepValue,\n base: min,\n };\n }\n\n /** Current normalized value derived from the live declarative inputs. */\n #currentValue(): number {\n return snapSteppedValue(this.valueValue, this.#effectiveRange);\n }\n\n /** Copies valid authored ARIA into Values only when no explicit Value exists. */\n #hydrateValues(): void {\n if (!this.#hasInput(\"orientation\")) {\n const orientation = this.element.getAttribute(\"aria-orientation\");\n if (orientation === \"horizontal\" || orientation === \"vertical\") {\n this.orientationValue = orientation;\n }\n }\n\n const min = this.#finiteAttribute(\"aria-valuemin\");\n if (!this.#hasInput(\"min\") && min !== null) this.minValue = min;\n const max = this.#finiteAttribute(\"aria-valuemax\");\n if (!this.#hasInput(\"max\") && max !== null) this.maxValue = max;\n const value = this.#finiteAttribute(\"aria-valuenow\");\n if (!this.#hasInput(\"value\") && value !== null) this.valueValue = value;\n }\n\n /** Whether the author supplied the namespaced Value instead of using its default. */\n #hasInput(name: \"orientation\" | \"min\" | \"max\" | \"value\"): boolean {\n return this.element.hasAttribute(`data-${this.identifier}-${name}-value`);\n }\n\n /** Strict finite-number parser for the one-time progressive-enhancement bridge. */\n #finiteAttribute(name: string): number | null {\n const raw = this.element.getAttribute(name);\n if (raw === null || raw.trim() === \"\") return null;\n const value = Number(raw);\n return Number.isFinite(value) ? value : null;\n }\n\n /** Returns attributes without overwriting values a consumer changed after render. */\n #returnAttributes(): void {\n this.#role.return(this.element);\n this.#tabindex.return(this.element);\n this.#orientation.return(this.element);\n this.#minimum.return(this.element);\n this.#maximum.return(this.element);\n this.#current.return(this.element);\n }\n\n /** Prevents a queued Value repaint from racing Turbo's restored snapshot. */\n #rewindForCache(): void {\n this.#repaint.cancel();\n this.#returnAttributes();\n }\n}\n"]}