stimeo-ui 0.4.0 → 0.6.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 (173) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/dist/controllers/announcer_controller.js.map +1 -1
  3. package/dist/controllers/aspect_ratio_controller.d.ts +3 -5
  4. package/dist/controllers/aspect_ratio_controller.js +19 -11
  5. package/dist/controllers/aspect_ratio_controller.js.map +1 -1
  6. package/dist/controllers/avatar_controller.d.ts +36 -15
  7. package/dist/controllers/avatar_controller.js +195 -40
  8. package/dist/controllers/avatar_controller.js.map +1 -1
  9. package/dist/controllers/breadcrumb_controller.js +5 -1
  10. package/dist/controllers/breadcrumb_controller.js.map +1 -1
  11. package/dist/controllers/carousel_controller.d.ts +12 -3
  12. package/dist/controllers/carousel_controller.js +90 -10
  13. package/dist/controllers/carousel_controller.js.map +1 -1
  14. package/dist/controllers/checkbox_controller.d.ts +31 -5
  15. package/dist/controllers/checkbox_controller.js +136 -25
  16. package/dist/controllers/checkbox_controller.js.map +1 -1
  17. package/dist/controllers/clipboard_controller.js +8 -3
  18. package/dist/controllers/clipboard_controller.js.map +1 -1
  19. package/dist/controllers/collapsible_controller.d.ts +1 -1
  20. package/dist/controllers/collapsible_controller.js +4 -1
  21. package/dist/controllers/collapsible_controller.js.map +1 -1
  22. package/dist/controllers/color_picker_controller.d.ts +9 -3
  23. package/dist/controllers/color_picker_controller.js +41 -11
  24. package/dist/controllers/color_picker_controller.js.map +1 -1
  25. package/dist/controllers/combobox_controller.js.map +1 -1
  26. package/dist/controllers/command_palette_controller.js.map +1 -1
  27. package/dist/controllers/context_menu_controller.d.ts +1 -1
  28. package/dist/controllers/context_menu_controller.js +2 -2
  29. package/dist/controllers/context_menu_controller.js.map +1 -1
  30. package/dist/controllers/countdown_controller.d.ts +5 -3
  31. package/dist/controllers/countdown_controller.js +5 -1
  32. package/dist/controllers/countdown_controller.js.map +1 -1
  33. package/dist/controllers/date_range_picker_controller.d.ts +23 -4
  34. package/dist/controllers/date_range_picker_controller.js +162 -31
  35. package/dist/controllers/date_range_picker_controller.js.map +1 -1
  36. package/dist/controllers/direct_upload_controller.d.ts +1 -1
  37. package/dist/controllers/direct_upload_controller.js +3 -3
  38. package/dist/controllers/direct_upload_controller.js.map +1 -1
  39. package/dist/controllers/empty_state_controller.d.ts +27 -7
  40. package/dist/controllers/empty_state_controller.js +107 -16
  41. package/dist/controllers/empty_state_controller.js.map +1 -1
  42. package/dist/controllers/file_dropzone_controller.d.ts +7 -1
  43. package/dist/controllers/file_dropzone_controller.js +26 -3
  44. package/dist/controllers/file_dropzone_controller.js.map +1 -1
  45. package/dist/controllers/flash_controller.d.ts +25 -5
  46. package/dist/controllers/flash_controller.js +161 -21
  47. package/dist/controllers/flash_controller.js.map +1 -1
  48. package/dist/controllers/focus_controller.d.ts +2 -3
  49. package/dist/controllers/focus_controller.js.map +1 -1
  50. package/dist/controllers/form_validation_controller.js +8 -2
  51. package/dist/controllers/form_validation_controller.js.map +1 -1
  52. package/dist/controllers/frame_loading_controller.d.ts +19 -2
  53. package/dist/controllers/frame_loading_controller.js +94 -22
  54. package/dist/controllers/frame_loading_controller.js.map +1 -1
  55. package/dist/controllers/highlight_controller.d.ts +8 -4
  56. package/dist/controllers/highlight_controller.js +38 -1
  57. package/dist/controllers/highlight_controller.js.map +1 -1
  58. package/dist/controllers/hover_card_controller.d.ts +2 -2
  59. package/dist/controllers/hover_card_controller.js.map +1 -1
  60. package/dist/controllers/idle_controller.d.ts +5 -4
  61. package/dist/controllers/idle_controller.js +39 -6
  62. package/dist/controllers/idle_controller.js.map +1 -1
  63. package/dist/controllers/listbox_controller.js.map +1 -1
  64. package/dist/controllers/local_time_controller.js +2 -0
  65. package/dist/controllers/local_time_controller.js.map +1 -1
  66. package/dist/controllers/masonry_controller.d.ts +1 -1
  67. package/dist/controllers/masonry_controller.js +1 -1
  68. package/dist/controllers/masonry_controller.js.map +1 -1
  69. package/dist/controllers/menubar_controller.js +5 -3
  70. package/dist/controllers/menubar_controller.js.map +1 -1
  71. package/dist/controllers/meter_controller.js +3 -1
  72. package/dist/controllers/meter_controller.js.map +1 -1
  73. package/dist/controllers/multi_select_controller.d.ts +46 -12
  74. package/dist/controllers/multi_select_controller.js +460 -151
  75. package/dist/controllers/multi_select_controller.js.map +1 -1
  76. package/dist/controllers/network_status_controller.d.ts +15 -13
  77. package/dist/controllers/network_status_controller.js +1 -3
  78. package/dist/controllers/network_status_controller.js.map +1 -1
  79. package/dist/controllers/number_input_controller.d.ts +29 -3
  80. package/dist/controllers/number_input_controller.js +455 -64
  81. package/dist/controllers/number_input_controller.js.map +1 -1
  82. package/dist/controllers/overflow_menu_controller.js +5 -1
  83. package/dist/controllers/overflow_menu_controller.js.map +1 -1
  84. package/dist/controllers/pagination_controller.js +38 -1
  85. package/dist/controllers/pagination_controller.js.map +1 -1
  86. package/dist/controllers/password_strength_controller.d.ts +4 -4
  87. package/dist/controllers/password_strength_controller.js +21 -3
  88. package/dist/controllers/password_strength_controller.js.map +1 -1
  89. package/dist/controllers/persist_controller.d.ts +4 -4
  90. package/dist/controllers/persist_controller.js +24 -5
  91. package/dist/controllers/persist_controller.js.map +1 -1
  92. package/dist/controllers/pointer_drag_controller.js +10 -0
  93. package/dist/controllers/pointer_drag_controller.js.map +1 -1
  94. package/dist/controllers/popover_controller.d.ts +2 -2
  95. package/dist/controllers/popover_controller.js.map +1 -1
  96. package/dist/controllers/portal_controller.d.ts +1 -2
  97. package/dist/controllers/portal_controller.js +10 -0
  98. package/dist/controllers/portal_controller.js.map +1 -1
  99. package/dist/controllers/progress_controller.d.ts +1 -1
  100. package/dist/controllers/progress_controller.js +7 -3
  101. package/dist/controllers/progress_controller.js.map +1 -1
  102. package/dist/controllers/radio_group_controller.d.ts +41 -15
  103. package/dist/controllers/radio_group_controller.js +540 -56
  104. package/dist/controllers/radio_group_controller.js.map +1 -1
  105. package/dist/controllers/range_slider_controller.d.ts +23 -0
  106. package/dist/controllers/range_slider_controller.js +385 -94
  107. package/dist/controllers/range_slider_controller.js.map +1 -1
  108. package/dist/controllers/rating_controller.d.ts +36 -31
  109. package/dist/controllers/rating_controller.js +274 -89
  110. package/dist/controllers/rating_controller.js.map +1 -1
  111. package/dist/controllers/relative_time_controller.js +2 -0
  112. package/dist/controllers/relative_time_controller.js.map +1 -1
  113. package/dist/controllers/resizable_controller.js +33 -0
  114. package/dist/controllers/resizable_controller.js.map +1 -1
  115. package/dist/controllers/roving_controller.d.ts +4 -0
  116. package/dist/controllers/roving_controller.js +60 -5
  117. package/dist/controllers/roving_controller.js.map +1 -1
  118. package/dist/controllers/scroll_area_controller.d.ts +7 -1
  119. package/dist/controllers/scroll_area_controller.js +155 -23
  120. package/dist/controllers/scroll_area_controller.js.map +1 -1
  121. package/dist/controllers/scroll_visibility_controller.js +33 -0
  122. package/dist/controllers/scroll_visibility_controller.js.map +1 -1
  123. package/dist/controllers/separator_controller.js +13 -17
  124. package/dist/controllers/separator_controller.js.map +1 -1
  125. package/dist/controllers/skeleton_controller.d.ts +2 -2
  126. package/dist/controllers/skeleton_controller.js +71 -3
  127. package/dist/controllers/skeleton_controller.js.map +1 -1
  128. package/dist/controllers/slider_controller.d.ts +17 -1
  129. package/dist/controllers/slider_controller.js +325 -48
  130. package/dist/controllers/slider_controller.js.map +1 -1
  131. package/dist/controllers/spinner_controller.d.ts +15 -10
  132. package/dist/controllers/spinner_controller.js +18 -3
  133. package/dist/controllers/spinner_controller.js.map +1 -1
  134. package/dist/controllers/step_indicator_controller.d.ts +1 -1
  135. package/dist/controllers/step_indicator_controller.js +3 -1
  136. package/dist/controllers/step_indicator_controller.js.map +1 -1
  137. package/dist/controllers/stepper_controller.js +2 -0
  138. package/dist/controllers/stepper_controller.js.map +1 -1
  139. package/dist/controllers/switch_controller.d.ts +12 -8
  140. package/dist/controllers/switch_controller.js +162 -18
  141. package/dist/controllers/switch_controller.js.map +1 -1
  142. package/dist/controllers/tags_input_controller.d.ts +41 -11
  143. package/dist/controllers/tags_input_controller.js +356 -120
  144. package/dist/controllers/tags_input_controller.js.map +1 -1
  145. package/dist/controllers/textarea_autosize_controller.js +1 -1
  146. package/dist/controllers/textarea_autosize_controller.js.map +1 -1
  147. package/dist/controllers/time_picker_controller.d.ts +42 -10
  148. package/dist/controllers/time_picker_controller.js +296 -104
  149. package/dist/controllers/time_picker_controller.js.map +1 -1
  150. package/dist/controllers/toggle_group_controller.d.ts +39 -13
  151. package/dist/controllers/toggle_group_controller.js +378 -55
  152. package/dist/controllers/toggle_group_controller.js.map +1 -1
  153. package/dist/controllers/toolbar_controller.js +5 -3
  154. package/dist/controllers/toolbar_controller.js.map +1 -1
  155. package/dist/controllers/tooltip_controller.d.ts +2 -2
  156. package/dist/controllers/tooltip_controller.js.map +1 -1
  157. package/dist/controllers/transition_controller.d.ts +2 -3
  158. package/dist/controllers/transition_controller.js.map +1 -1
  159. package/dist/controllers/tree_view_controller.d.ts +1 -2
  160. package/dist/controllers/tree_view_controller.js +24 -4
  161. package/dist/controllers/tree_view_controller.js.map +1 -1
  162. package/dist/index.js +3811 -1048
  163. package/dist/index.js.map +1 -1
  164. package/dist/inspector/cli.d.ts +92 -4
  165. package/dist/inspector/cli.js +174 -6
  166. package/dist/inspector/cli.js.map +1 -1
  167. package/dist/inspector/cli_bin.js +234 -8
  168. package/dist/inspector/cli_bin.js.map +1 -1
  169. package/dist/inspector/examples.json +24 -24
  170. package/dist/inspector/manifest.json +573 -59
  171. package/dist/positioning/index.d.ts +2 -2
  172. package/dist/positioning/index.js.map +1 -1
  173. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/layout_observer.ts","../../src/utils/logical_scroll.ts","../../src/utils/tabindex_loan.ts","../../src/controllers/scroll_area_controller.ts"],"names":[],"mappings":";;;;;AAgDO,IAAM,iBAAN,MAAqB;AAAA,EACjB,SAAA;AAAA,EACA,sBAAA;AAAA,EACT,eAAA,GAAyC,IAAA;AAAA,EACzC,kBAAA,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AAA,EAAM,CAAA,GAAI,IAAA;AAAA,EACtF;AAAA,EAEA,mBAAmB,EAAA,EAA0B;AAC3C,IAAA,OAAO,GAAG,YAAA,CAAa,YAAY,CAAA,IAAK,EAAA,CAAG,aAAa,iBAAiB,CAAA;AAAA,EAC3E;AACF","file":"scroll_area_controller.js","sourcesContent":["/**\n * Unified element-size and viewport observation for Stimeo controllers.\n *\n * Layout-sensitive widgets (sliders, resizable panes, scroll spies, popovers)\n * need to react both to their *own* box changing — via {@link ResizeObserver} —\n * and to the *viewport* changing — via the `window` `resize` event. Wiring those\n * two sources by hand in every controller risks leaked listeners on\n * `disconnect()`. {@link LayoutObserver} owns both behind one callback and one\n * {@link LayoutObserver.disconnect | disconnect()} that releases everything.\n *\n * Behavior only: the helper reports *that* layout changed; it never reads or\n * writes styles. Consumers decide what to recompute.\n */\n\n/** Invoked whenever an observed element or the viewport changes size. */\nexport type LayoutCallback = () => void;\n\n/** Constructs a {@link ResizeObserver}; injectable so tests stay deterministic. */\nexport type ResizeObserverFactory = (callback: ResizeObserverCallback) => ResizeObserver;\n\n/** Options for {@link LayoutObserver}. */\nexport interface LayoutObserverOptions {\n /**\n * Factory for the {@link ResizeObserver} used by {@link LayoutObserver.observe}.\n * Defaults to the global constructor; override it in tests, or to no-op in\n * environments where `ResizeObserver` is unavailable.\n */\n resizeObserverFactory?: ResizeObserverFactory;\n}\n\n/**\n * Observes element resizes and/or viewport resizes through a single callback,\n * with guaranteed teardown.\n *\n * @example\n * ```ts\n * #layout = new LayoutObserver(() => this.#reposition());\n *\n * connect() {\n * this.#layout.observe(this.panelTarget);\n * this.#layout.observeViewport();\n * }\n *\n * disconnect() {\n * this.#layout.disconnect();\n * }\n * ```\n */\nexport class LayoutObserver {\n readonly #callback: LayoutCallback;\n readonly #resizeObserverFactory: ResizeObserverFactory | null;\n #resizeObserver: ResizeObserver | null = null;\n #observingViewport = false;\n\n /** Stable bound handler so add/removeEventListener target the same reference. */\n readonly #handleViewportResize = (): void => {\n this.#callback();\n };\n\n constructor(callback: LayoutCallback, options: LayoutObserverOptions = {}) {\n this.#callback = callback;\n this.#resizeObserverFactory =\n options.resizeObserverFactory ??\n (typeof ResizeObserver === \"undefined\" ? null : (cb) => new ResizeObserver(cb));\n }\n\n /**\n * Starts observing an element's size. Repeated calls observe additional\n * elements through the same shared observer. No-ops when no\n * `ResizeObserver` implementation is available.\n */\n observe(element: Element): void {\n if (!this.#resizeObserverFactory) return;\n if (!this.#resizeObserver) {\n this.#resizeObserver = this.#resizeObserverFactory(() => {\n this.#callback();\n });\n }\n this.#resizeObserver.observe(element);\n }\n\n /** Stops observing a single element while leaving any others in place. */\n unobserve(element: Element): void {\n this.#resizeObserver?.unobserve(element);\n }\n\n /** Starts observing viewport resizes. Idempotent: the listener is added once. */\n observeViewport(): void {\n if (this.#observingViewport) return;\n this.#observingViewport = true;\n window.addEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /** Stops observing viewport resizes without affecting element observation. */\n unobserveViewport(): void {\n if (!this.#observingViewport) return;\n this.#observingViewport = false;\n window.removeEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /**\n * Releases every observation: disconnects the {@link ResizeObserver} and\n * removes the viewport listener. Safe to call multiple times. Call this from a\n * controller's `disconnect()`.\n */\n disconnect(): void {\n this.#resizeObserver?.disconnect();\n this.#resizeObserver = null;\n this.unobserveViewport();\n }\n}\n","/** Normalized scroll position and maximum distance on one logical axis. */\nexport interface LogicalScrollMetrics {\n position: number;\n max: number;\n}\n\n/**\n * Whether horizontal scrolling on `element` follows right-to-left inline flow.\n *\n * Resolved from the **computed** `direction`, so the authoring contract is the\n * usual `dir=\"rtl\"` (or a stylesheet) on the element or any ancestor.\n *\n * Scope: horizontal writing modes. A vertical writing mode (`writing-mode:\n * vertical-rl`) also inverts the horizontal axis, which this check does not\n * model — vertical writing modes are out of scope for the scroll utilities\n * (their consumers describe axes as horizontal/vertical, not inline/block).\n */\nexport function isRtl(element: Element): boolean {\n return window.getComputedStyle(element).direction === \"rtl\";\n}\n\n/**\n * Returns scroll distance from the logical start edge.\n *\n * CSSOM View exposes standards-mode RTL horizontal offsets as `0` at the inline\n * start (right) and increasingly negative values toward the inline end (left).\n * The normalized position is always clamped to `[0, max]`, which also absorbs\n * Safari's elastic overscroll values.\n */\nexport function logicalScrollMetrics(\n element: HTMLElement,\n horizontal: boolean,\n): LogicalScrollMetrics {\n const max = Math.max(\n 0,\n horizontal\n ? element.scrollWidth - element.clientWidth\n : element.scrollHeight - element.clientHeight,\n );\n const raw = horizontal ? element.scrollLeft : element.scrollTop;\n const position = horizontal && isRtl(element) ? -raw : raw;\n return { position: Math.min(max, Math.max(0, position)), max };\n}\n\n/**\n * Converts a logical start/end delta to the physical value accepted by\n * `Element.scrollBy`.\n */\nexport function physicalScrollDelta(\n element: HTMLElement,\n horizontal: boolean,\n logicalDelta: number,\n): number {\n return horizontal && isRtl(element) ? -logicalDelta : logicalDelta;\n}\n","/**\n * Shared bookkeeping for a `tabindex` a controller lends an element temporarily.\n *\n * A controller that must move focus somewhere the author never made focusable\n * (a landmark root, a scroll destination) reaches for the same trick: add a\n * `tabindex` just-in-time and hand it back once it is no longer needed. The\n * borrow is the easy half; the return is what the two conditions below are for.\n *\n * **Returning needs two conditions, not one.** Owning the borrow is not enough:\n * the attribute must also still hold the value this instance wrote. A consumer\n * that changed it afterwards — `tabindex=\"0\"` to make the root its own Tab stop\n * — owns it now, and removing it there silently discards authored markup. The\n * bookkeeping is dropped either way, since the loan is over regardless of who\n * ends up owning the value.\n *\n * **Never borrow over an existing value.** An element that already carries a\n * `tabindex` is the author's to control, so there is nothing to lend and nothing\n * to return.\n *\n * The registry is keyed by element, so a controller borrowing on a single\n * element (`this.element`) and one borrowing across a changing set of targets\n * use the same API — the single-element case is a set of one. It holds no\n * opinion about *when* to borrow or where focus goes next; that stays in the\n * controller.\n *\n * **The API is deliberately two methods.** This file's own doc block is dropped\n * from `dist`, but every member comment is inlined into **each** consumer entry\n * (`tsup` builds with `splitting: false`), so rationale belongs here, only the\n * contract belongs on the members, and every method no consumer calls is still\n * paid for once per consumer entry.\n *\n * @example\n * ```ts\n * readonly #tabindex = new TabindexLoan();\n *\n * #rescueFocus() {\n * this.#tabindex.lend(this.element);\n * this.element.focus();\n * }\n *\n * disconnect() {\n * this.#tabindex.returnAll();\n * }\n * ```\n */\nexport class TabindexLoan<T extends HTMLElement = HTMLElement> {\n readonly #value: string;\n readonly #lent = new Set<T>();\n\n /**\n * @param value - the `tabindex` to lend. `\"-1\"` (the default) is\n * programmatically focusable but not a Tab stop; `\"0\"` is a real Tab stop,\n * which a scroll region with no focusable content of its own needs.\n */\n constructor(value: string = \"-1\") {\n this.#value = value;\n }\n\n /** Lends `element` the value; no-ops when it already carries a `tabindex`. */\n lend(element: T): void {\n if (element.hasAttribute(\"tabindex\")) return;\n element.setAttribute(\"tabindex\", this.#value);\n this.#lent.add(element);\n }\n\n /** Takes back every loan whose value is still the one that was lent. */\n returnAll(): void {\n for (const element of this.#lent) {\n if (element.getAttribute(\"tabindex\") === this.#value) element.removeAttribute(\"tabindex\");\n }\n this.#lent.clear();\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { LayoutObserver } from \"../utils/layout_observer\";\nimport { logicalScrollMetrics } from \"../utils/logical_scroll\";\nimport { TabindexLoan } from \"../utils/tabindex_loan\";\n\n/** A CSS selector for natively focusable / author-focusable descendants. */\nconst FOCUSABLE_SELECTOR = [\n \"a[href]\",\n \"button:not([disabled])\",\n \"input:not([disabled])\",\n \"select:not([disabled])\",\n \"textarea:not([disabled])\",\n \"[tabindex]:not([tabindex='-1'])\",\n \"[contenteditable='true']\",\n].join(\",\");\n\n/** Distance from an edge (px) treated as fully reached; absorbs sub-pixel scroll. */\nconst EDGE_EPSILON = 1;\n\n/** `Element.checkVisibility` (widely available); absent in older engines. */\ninterface VisibilityCheckable {\n checkVisibility?: (options?: { visibilityProperty?: boolean }) => boolean;\n}\n\n/**\n * Headless **Scroll Area** behavior: keyboard reachability and scroll-state hooks\n * for a natively scrolling region. No custom scrollbar — the native one is\n * respected; this only adds a11y and CSS state.\n *\n * Markup contract (identifier: `stimeo--scroll-area`):\n * <div data-controller=\"stimeo--scroll-area\"\n * data-stimeo--scroll-area-orientation-value=\"vertical\">\n * <div data-stimeo--scroll-area-target=\"viewport\" aria-label=\"Log output\">\n * <!-- long content -->\n * </div>\n * </div>\n *\n * When the content overflows and the viewport holds no focusable elements of its\n * own, the viewport is made keyboard-scrollable (`tabindex=\"0\"`, plus `role=\"region\"`\n * when it already has an accessible name). Scroll position is published as\n * `data-scroll` (`start`/`middle`/`end`), overflow as `data-overflow`, and progress\n * as `--stimeo-scroll-progress` (0–1) so consumer CSS can draw scroll shadows.\n *\n * @remarks\n * Behavior only. The `scroll` listener and {@link LayoutObserver} (element +\n * viewport resize) are torn down on `disconnect()` (Turbo navigation included).\n * `role=\"region\"` is added only when the viewport is already named, so a scrollable\n * region never becomes an unlabeled landmark.\n */\nexport class ScrollAreaController extends Controller<HTMLElement> {\n static override targets = [\"viewport\"];\n static override values = {\n orientation: { type: String, default: \"vertical\" },\n };\n static events = [\"reach\"] as const;\n\n declare readonly viewportTarget: HTMLElement;\n declare readonly hasViewportTarget: boolean;\n\n declare orientationValue: string;\n\n readonly #layout = new LayoutObserver(() => this.#update());\n /** Re-checks the tab stop when the viewport's focusable content comes or goes. */\n #content: MutationObserver | null = null;\n /** Last edge reported via `reach`, so the event fires once per arrival. */\n #lastEdge: \"start\" | \"end\" | null = null;\n /** Whether this controller added `tabindex`, so teardown only removes its own. */\n readonly #tabindex = new TabindexLoan(\"0\");\n /** Whether this controller added `role=\"region\"`, for symmetric teardown. */\n #addedRole = false;\n\n readonly #onScroll = (): void => {\n this.#update();\n };\n\n override connect(): void {\n if (!this.hasViewportTarget) return;\n this.viewportTarget.addEventListener(\"scroll\", this.#onScroll, { passive: true });\n this.#layout.observe(this.viewportTarget);\n this.#layout.observeViewport();\n // Overflow follows the box, but focusability follows the content, and the two\n // change independently: revealing a button inside a fixed-height viewport fires\n // no resize and no scroll. Without this the tab stop would be stale until the\n // next unrelated event.\n //\n // No `attributeFilter`: what makes a control appear is not confined to its own\n // attributes — a state hook on an ancestor (`[data-has-new] .jump { display: block }`)\n // flips it just as well, and that set cannot be enumerated.\n //\n // The overflow value is re-measured here rather than reused. A content change moves\n // the scroll extent without touching the viewport's own box, so a fixed-height\n // viewport fires no resize when its content shrinks — reusing a cached value would\n // hand the tab stop to a box that does not scroll. Position and `reach` are\n // deliberately left alone: the event contract is arrival at an edge, and a content\n // change is not an arrival.\n if (typeof MutationObserver !== \"undefined\") {\n this.#content = new MutationObserver(() => {\n if (!this.hasViewportTarget) return;\n const vp = this.viewportTarget;\n this.#syncKeyboardReach(vp, this.#syncOverflow(vp));\n });\n this.#content.observe(this.viewportTarget, {\n subtree: true,\n childList: true,\n attributes: true,\n });\n }\n this.#update();\n }\n\n override disconnect(): void {\n if (this.hasViewportTarget) {\n this.viewportTarget.removeEventListener(\"scroll\", this.#onScroll);\n // Remove only the keyboard-reach attributes this controller added, so a\n // Turbo cache snapshot never preserves a controller-owned tab stop /\n // landmark (controller-added state must not outlive the controller).\n this.#clearAddedAttributes(this.viewportTarget);\n }\n this.#layout.disconnect();\n this.#content?.disconnect();\n this.#content = null;\n this.#lastEdge = null;\n }\n\n /** Re-measures overflow and scroll position and reflects the state hooks. */\n #update(): void {\n if (!this.hasViewportTarget) return;\n const vp = this.viewportTarget;\n const overflowing = this.#syncOverflow(vp);\n this.#syncKeyboardReach(vp, overflowing);\n\n const { position, progress } = this.#measurePosition(vp);\n this.element.setAttribute(\"data-scroll\", position);\n this.element.style.setProperty(\"--stimeo-scroll-progress\", String(progress));\n\n const edge = position === \"start\" ? \"start\" : position === \"end\" ? \"end\" : null;\n if (overflowing && edge && edge !== this.#lastEdge) {\n this.#lastEdge = edge;\n this.dispatch(\"reach\", { detail: { edge } });\n } else if (!edge) {\n this.#lastEdge = null;\n }\n }\n\n /** Whether the viewport can scroll on the configured axis. */\n /**\n * Measures overflow and reflects the `data-overflow` hook.\n *\n * The write is skipped when the value is unchanged. An identical `setAttribute` still\n * queues a MutationRecord, and markup that puts the viewport target on the controller\n * element itself would then have the content observer trigger its own next callback.\n */\n #syncOverflow(vp: HTMLElement): boolean {\n const overflowing = this.#measureOverflow(vp);\n const next = overflowing ? \"true\" : \"false\";\n if (this.element.getAttribute(\"data-overflow\") !== next) {\n this.element.setAttribute(\"data-overflow\", next);\n }\n return overflowing;\n }\n\n #measureOverflow(vp: HTMLElement): boolean {\n const o = this.orientationValue;\n const vertical = o !== \"horizontal\" && vp.scrollHeight > vp.clientHeight + EDGE_EPSILON;\n const horizontal = o !== \"vertical\" && vp.scrollWidth > vp.clientWidth + EDGE_EPSILON;\n return vertical || horizontal;\n }\n\n /**\n * Reports the scroll position bucket and 0–1 progress on the primary axis. For\n * `both`, the vertical axis is used when it overflows, otherwise the horizontal.\n */\n #measurePosition(vp: HTMLElement): {\n position: \"start\" | \"middle\" | \"end\";\n progress: number;\n } {\n const horizontalPrimary =\n this.orientationValue === \"horizontal\" ||\n (this.orientationValue === \"both\" && vp.scrollHeight <= vp.clientHeight + EDGE_EPSILON);\n\n const { position: scrollPos, max: maxScroll } = logicalScrollMetrics(vp, horizontalPrimary);\n\n if (maxScroll <= EDGE_EPSILON) return { position: \"start\", progress: 0 };\n\n const progress = Math.min(1, Math.max(0, scrollPos / maxScroll));\n if (scrollPos <= EDGE_EPSILON) return { position: \"start\", progress };\n if (scrollPos >= maxScroll - EDGE_EPSILON) return { position: \"end\", progress };\n return { position: \"middle\", progress };\n }\n\n /**\n * Makes the viewport keyboard-scrollable when it overflows and contains no\n * focusable elements of its own (avoiding a double tab stop). Adds `role=\"region\"`\n * only when the viewport already carries an accessible name.\n */\n #syncKeyboardReach(vp: HTMLElement, overflowing: boolean): void {\n const wantsTabindex = overflowing && !this.#hasFocusableContent(vp);\n\n if (wantsTabindex) {\n this.#tabindex.lend(vp);\n if (!vp.hasAttribute(\"role\") && this.#hasAccessibleName(vp)) {\n vp.setAttribute(\"role\", \"region\");\n this.#addedRole = true;\n }\n } else {\n this.#clearAddedAttributes(vp);\n }\n }\n\n /** Removes (and resets the flags for) only the attributes this controller added. */\n #clearAddedAttributes(vp: HTMLElement): void {\n this.#tabindex.returnAll();\n if (this.#addedRole) {\n vp.removeAttribute(\"role\");\n this.#addedRole = false;\n }\n }\n\n /**\n * Whether the viewport owns something the user can Tab to *right now*.\n *\n * The selector alone is not enough: a `display: none` button still matches it,\n * so a viewport whose only control is revealed on demand would never get a tab\n * stop — leaving it unreachable by keyboard exactly while it has nothing else to\n * offer. Only rendered candidates count.\n */\n #hasFocusableContent(vp: HTMLElement): boolean {\n return Array.from(vp.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).some((el) =>\n this.#isRendered(el),\n );\n }\n\n /**\n * Whether `el` is actually rendered, and so can hold focus.\n *\n * `checkVisibility()` answers this for every way CSS can remove a box, including\n * a class-driven `display: none` that no attribute reveals. The `hidden` walk in\n * front of it is not redundant: it is the one case a DOM-only environment with no\n * layout engine has to be told about explicitly.\n */\n #isRendered(el: HTMLElement): boolean {\n if (el.closest(\"[hidden]\") !== null) return false;\n const check = (el as HTMLElement & VisibilityCheckable).checkVisibility;\n return typeof check === \"function\" ? check.call(el, { visibilityProperty: true }) : true;\n }\n\n #hasAccessibleName(vp: HTMLElement): boolean {\n return vp.hasAttribute(\"aria-label\") || vp.hasAttribute(\"aria-labelledby\");\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/attribute_lease.ts","../../src/utils/layout_observer.ts","../../src/utils/logical_scroll.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/before_cache_reset.ts","../../src/utils/tabindex_loan.ts","../../src/controllers/scroll_area_controller.ts"],"names":[],"mappings":";;;;;AAmBO,IAAM,iBAAN,MAAkD;AAAA,EAC9C,UAAA;AAAA,EACA,QAAA,uBAAe,GAAA,EAA6B;AAAA;AAAA,EAGrD,YAAY,SAAA,EAAmB;AAC7B,IA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AAAA;AAAA,EAGA,sBAAsB,EAAA,EAAuB;AAC3C,IAAA,IAAA,CAAK,UAAU,SAAA,EAAU;AACzB,IAAA,IAAA,CAAK,KAAA,CAAM,OAAO,EAAE,CAAA;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,qBAAqB,EAAA,EAA0B;AAC7C,IAAA,OAAO,MAAM,IAAA,CAAK,EAAA,CAAG,gBAAA,CAA8B,kBAAkB,CAAC,CAAA,CAAE,IAAA;AAAA,MAAK,CAAC,EAAA,KAC5E,IAAA,CAAK,WAAA,CAAY,EAAE;AAAA,KACrB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,YAAY,EAAA,EAA0B;AACpC,IAAA,IAAI,EAAA,CAAG,OAAA,CAAQ,UAAU,CAAA,KAAM,MAAM,OAAO,KAAA;AAC5C,IAAA,MAAM,QAAS,EAAA,CAAyC,eAAA;AACxD,IAAA,OAAO,OAAO,KAAA,KAAU,UAAA,GAAa,KAAA,CAAM,IAAA,CAAK,IAAI,EAAE,kBAAA,EAAoB,IAAA,EAAM,CAAA,GAAI,IAAA;AAAA,EACtF;AAAA,EAEA,mBAAmB,EAAA,EAA0B;AAC3C,IAAA,OAAO,GAAG,YAAA,CAAa,YAAY,CAAA,IAAK,EAAA,CAAG,aAAa,iBAAiB,CAAA;AAAA,EAC3E;AACF","file":"scroll_area_controller.js","sourcesContent":["/** 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 */\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 if (value === null) element.removeAttribute(this.#attribute);\n else element.setAttribute(this.#attribute, 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 if (element.getAttribute(this.#attribute) !== record.written) return;\n\n if (record.original === null) element.removeAttribute(this.#attribute);\n else element.setAttribute(this.#attribute, record.original);\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 * Unified element-size and viewport observation for Stimeo controllers.\n *\n * Layout-sensitive widgets (sliders, resizable panes, scroll spies, popovers)\n * need to react both to their *own* box changing — via {@link ResizeObserver} —\n * and to the *viewport* changing — via the `window` `resize` event. Wiring those\n * two sources by hand in every controller risks leaked listeners on\n * `disconnect()`. {@link LayoutObserver} owns both behind one callback and one\n * {@link LayoutObserver.disconnect | disconnect()} that releases everything.\n *\n * Behavior only: the helper reports *that* layout changed; it never reads or\n * writes styles. Consumers decide what to recompute.\n */\n\n/** Invoked whenever an observed element or the viewport changes size. */\nexport type LayoutCallback = () => void;\n\n/** Constructs a {@link ResizeObserver}; injectable so tests stay deterministic. */\nexport type ResizeObserverFactory = (callback: ResizeObserverCallback) => ResizeObserver;\n\n/** Options for {@link LayoutObserver}. */\nexport interface LayoutObserverOptions {\n /**\n * Factory for the {@link ResizeObserver} used by {@link LayoutObserver.observe}.\n * Defaults to the global constructor; override it in tests, or to no-op in\n * environments where `ResizeObserver` is unavailable.\n */\n resizeObserverFactory?: ResizeObserverFactory;\n}\n\n/**\n * Observes element resizes and/or viewport resizes through a single callback,\n * with guaranteed teardown.\n *\n * @example\n * ```ts\n * #layout = new LayoutObserver(() => this.#reposition());\n *\n * connect() {\n * this.#layout.observe(this.panelTarget);\n * this.#layout.observeViewport();\n * }\n *\n * disconnect() {\n * this.#layout.disconnect();\n * }\n * ```\n */\nexport class LayoutObserver {\n readonly #callback: LayoutCallback;\n readonly #resizeObserverFactory: ResizeObserverFactory | null;\n #resizeObserver: ResizeObserver | null = null;\n #observingViewport = false;\n\n /** Stable bound handler so add/removeEventListener target the same reference. */\n readonly #handleViewportResize = (): void => {\n this.#callback();\n };\n\n constructor(callback: LayoutCallback, options: LayoutObserverOptions = {}) {\n this.#callback = callback;\n this.#resizeObserverFactory =\n options.resizeObserverFactory ??\n (typeof ResizeObserver === \"undefined\" ? null : (cb) => new ResizeObserver(cb));\n }\n\n /**\n * Starts observing an element's size. Repeated calls observe additional\n * elements through the same shared observer. No-ops when no\n * `ResizeObserver` implementation is available.\n */\n observe(element: Element): void {\n if (!this.#resizeObserverFactory) return;\n if (!this.#resizeObserver) {\n this.#resizeObserver = this.#resizeObserverFactory(() => {\n this.#callback();\n });\n }\n this.#resizeObserver.observe(element);\n }\n\n /** Stops observing a single element while leaving any others in place. */\n unobserve(element: Element): void {\n this.#resizeObserver?.unobserve(element);\n }\n\n /** Starts observing viewport resizes. Idempotent: the listener is added once. */\n observeViewport(): void {\n if (this.#observingViewport) return;\n this.#observingViewport = true;\n window.addEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /** Stops observing viewport resizes without affecting element observation. */\n unobserveViewport(): void {\n if (!this.#observingViewport) return;\n this.#observingViewport = false;\n window.removeEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /**\n * Releases every observation: disconnects the {@link ResizeObserver} and\n * removes the viewport listener. Safe to call multiple times. Call this from a\n * controller's `disconnect()`.\n */\n disconnect(): void {\n this.#resizeObserver?.disconnect();\n this.#resizeObserver = null;\n this.unobserveViewport();\n }\n}\n","/** Normalized scroll position and maximum distance on one logical axis. */\nexport interface LogicalScrollMetrics {\n position: number;\n max: number;\n}\n\n/**\n * Whether horizontal scrolling on `element` follows right-to-left inline flow.\n *\n * Resolved from the **computed** `direction`, so the authoring contract is the\n * usual `dir=\"rtl\"` (or a stylesheet) on the element or any ancestor.\n *\n * Scope: horizontal writing modes. A vertical writing mode (`writing-mode:\n * vertical-rl`) also inverts the horizontal axis, which this check does not\n * model — vertical writing modes are out of scope for the scroll utilities\n * (their consumers describe axes as horizontal/vertical, not inline/block).\n */\nexport function isRtl(element: Element): boolean {\n return window.getComputedStyle(element).direction === \"rtl\";\n}\n\n/**\n * Returns scroll distance from the logical start edge.\n *\n * CSSOM View exposes standards-mode RTL horizontal offsets as `0` at the inline\n * start (right) and increasingly negative values toward the inline end (left).\n * The normalized position is always clamped to `[0, max]`, which also absorbs\n * Safari's elastic overscroll values.\n */\nexport function logicalScrollMetrics(\n element: HTMLElement,\n horizontal: boolean,\n): LogicalScrollMetrics {\n const max = Math.max(\n 0,\n horizontal\n ? element.scrollWidth - element.clientWidth\n : element.scrollHeight - element.clientHeight,\n );\n const raw = horizontal ? element.scrollLeft : element.scrollTop;\n const position = horizontal && isRtl(element) ? -raw : raw;\n return { position: Math.min(max, Math.max(0, position)), max };\n}\n\n/**\n * Converts a logical start/end delta to the physical value accepted by\n * `Element.scrollBy`.\n */\nexport function physicalScrollDelta(\n element: HTMLElement,\n horizontal: boolean,\n logicalDelta: number,\n): number {\n return horizontal && isRtl(element) ? -logicalDelta : logicalDelta;\n}\n","/**\n * 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","/**\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 { AttributeLease } from \"../utils/attribute_lease\";\nimport { LayoutObserver } from \"../utils/layout_observer\";\nimport { logicalScrollMetrics } from \"../utils/logical_scroll\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\nimport { TabindexLoan } from \"../utils/tabindex_loan\";\n\n/** A CSS selector for natively focusable / author-focusable descendants. */\nconst FOCUSABLE_SELECTOR = [\n \"a[href]\",\n \"button:not([disabled])\",\n \"input:not([disabled])\",\n \"select:not([disabled])\",\n \"textarea:not([disabled])\",\n \"[tabindex]:not([tabindex='-1'])\",\n \"[contenteditable='true']\",\n].join(\",\");\n\n/** Distance from an edge (px) treated as fully reached; absorbs sub-pixel scroll. */\nconst EDGE_EPSILON = 1;\n\n/** `Element.checkVisibility` (widely available); absent in older engines. */\ninterface VisibilityCheckable {\n checkVisibility?: (options?: { visibilityProperty?: boolean }) => boolean;\n}\n\n/**\n * Headless **Scroll Area** behavior: keyboard reachability and scroll-state hooks\n * for a natively scrolling region. No custom scrollbar — the native one is\n * respected; this only adds a11y and CSS state.\n *\n * Markup contract (identifier: `stimeo--scroll-area`):\n * <div data-controller=\"stimeo--scroll-area\"\n * data-stimeo--scroll-area-orientation-value=\"vertical\">\n * <div data-stimeo--scroll-area-target=\"viewport\" aria-label=\"Log output\">\n * <!-- long content -->\n * </div>\n * </div>\n *\n * When the content overflows and the viewport holds no focusable elements of its\n * own, the viewport is made keyboard-scrollable (`tabindex=\"0\"`, plus `role=\"region\"`\n * when it already has an accessible name). Scroll position is published as\n * `data-scroll` (`start`/`middle`/`end`), overflow as `data-overflow`, and progress\n * as `--stimeo--scroll-progress` (0–1) so consumer CSS can draw scroll shadows.\n *\n * @remarks\n * Behavior only. The `scroll` listener and {@link LayoutObserver} (element +\n * viewport resize) are torn down on `disconnect()` (Turbo navigation included).\n * Runtime replacement of the viewport rebinds those resources and the content\n * observer as one lifecycle unit.\n * `role=\"region\"` is added only when the viewport is already named, so a scrollable\n * region never becomes an unlabeled landmark.\n */\nexport class ScrollAreaController extends Controller<HTMLElement> {\n static override targets = [\"viewport\"];\n static override values = {\n orientation: { type: String, default: \"vertical\" },\n };\n static events = [\"reach\"] as const;\n\n declare readonly viewportTarget: HTMLElement;\n declare readonly hasViewportTarget: boolean;\n\n declare orientationValue: string;\n\n readonly #layout = new LayoutObserver(() => this.#update());\n /** Current element receiving scroll, resize, mutation, and keyboard-reach behavior. */\n #viewport: HTMLElement | null = null;\n /** Guards target callbacks before connect and after disconnect. */\n #connected = false;\n /** Collapses target replacement callbacks into one final-DOM rebind. */\n readonly #rebind = new MicrotaskCoalescer(() => this.#syncViewport());\n /** Re-checks the tab stop when the viewport's focusable content comes or goes. */\n #content: MutationObserver | null = null;\n /** Last edge reported via `reach`, so the event fires once per arrival. */\n #lastEdge: \"start\" | \"end\" | null = null;\n /** Whether this controller added `tabindex`, so teardown only removes its own. */\n readonly #tabindex = new TabindexLoan(\"0\");\n /** Temporarily owns a derived `role=\"region\"` without losing an authored replacement. */\n readonly #role = new AttributeLease<HTMLElement>(\"role\");\n\n readonly #onScroll = (): void => {\n this.#update();\n };\n\n override connect(): void {\n this.#connected = true;\n this.#rebind.activate();\n this.#layout.observeViewport();\n this.#syncViewport();\n }\n\n /** Schedules a complete observer/listener rebind for a runtime viewport target. */\n viewportTargetConnected(): void {\n this.#rebind.schedule();\n }\n\n /** Schedules cleanup or replacement binding after a viewport leaves. */\n viewportTargetDisconnected(): void {\n this.#rebind.schedule();\n }\n\n /** Rebinds every viewport-owned resource against the final target in this mutation batch. */\n #syncViewport(): void {\n if (!this.#connected) return;\n const next = this.hasViewportTarget ? this.viewportTarget : null;\n if (next === this.#viewport) {\n this.#update();\n return;\n }\n if (this.#viewport) this.#unbindViewport(this.#viewport);\n this.#viewport = next;\n if (!next) return;\n\n next.addEventListener(\"scroll\", this.#onScroll, { passive: true });\n this.#layout.observe(next);\n // Overflow follows the box, but focusability follows the content, and the two\n // change independently: revealing a button inside a fixed-height viewport fires\n // no resize and no scroll. Without this the tab stop would be stale until the\n // next unrelated event.\n //\n // No `attributeFilter`: what makes a control appear is not confined to its own\n // attributes — a state hook on an ancestor (`[data-has-new] .jump { display: block }`)\n // flips it just as well, and that set cannot be enumerated.\n //\n // The overflow value is re-measured here rather than reused. A content change moves\n // the scroll extent without touching the viewport's own box, so a fixed-height\n // viewport fires no resize when its content shrinks — reusing a cached value would\n // hand the tab stop to a box that does not scroll. Position and `reach` are\n // deliberately left alone: the event contract is arrival at an edge, and a content\n // change is not an arrival.\n if (typeof MutationObserver !== \"undefined\") {\n this.#content = new MutationObserver(() => {\n if (this.#viewport !== next) return;\n this.#syncKeyboardReach(next, this.#syncOverflow(next));\n });\n this.#content.observe(next, {\n subtree: true,\n childList: true,\n attributes: true,\n });\n }\n this.#update();\n }\n\n override disconnect(): void {\n this.#connected = false;\n this.#rebind.cancel();\n if (this.#viewport) this.#unbindViewport(this.#viewport);\n this.#layout.disconnect();\n this.#lastEdge = null;\n }\n\n /** Releases every resource and derived attribute owned by one former viewport. */\n #unbindViewport(viewport: HTMLElement): void {\n viewport.removeEventListener(\"scroll\", this.#onScroll);\n this.#layout.unobserve(viewport);\n this.#content?.disconnect();\n this.#content = null;\n // Remove only the keyboard-reach attributes this controller added, so a\n // Turbo cache snapshot never preserves a controller-owned tab stop /\n // landmark (controller-added state must not outlive the controller).\n this.#clearAddedAttributes(viewport);\n if (this.#viewport === viewport) this.#viewport = null;\n this.#lastEdge = null;\n }\n\n /** Re-measures overflow and scroll position and reflects the state hooks. */\n #update(): void {\n const vp = this.#viewport;\n if (!vp) return;\n const overflowing = this.#syncOverflow(vp);\n this.#syncKeyboardReach(vp, overflowing);\n\n const { position, progress } = this.#measurePosition(vp);\n this.element.setAttribute(\"data-scroll\", position);\n this.element.style.setProperty(\"--stimeo--scroll-progress\", String(progress));\n\n const edge = position === \"start\" ? \"start\" : position === \"end\" ? \"end\" : null;\n if (overflowing && edge && edge !== this.#lastEdge) {\n this.#lastEdge = edge;\n this.dispatch(\"reach\", { detail: { edge } });\n } else if (!edge) {\n this.#lastEdge = null;\n }\n }\n\n /**\n * Measures overflow and reflects the `data-overflow` hook.\n *\n * The write is skipped when the value is unchanged. An identical `setAttribute` still\n * queues a MutationRecord, and markup that puts the viewport target on the controller\n * element itself would then have the content observer trigger its own next callback.\n */\n #syncOverflow(vp: HTMLElement): boolean {\n const overflowing = this.#measureOverflow(vp);\n const next = overflowing ? \"true\" : \"false\";\n if (this.element.getAttribute(\"data-overflow\") !== next) {\n this.element.setAttribute(\"data-overflow\", next);\n }\n return overflowing;\n }\n\n #measureOverflow(vp: HTMLElement): boolean {\n const o = this.orientationValue;\n const vertical = o !== \"horizontal\" && vp.scrollHeight > vp.clientHeight + EDGE_EPSILON;\n const horizontal = o !== \"vertical\" && vp.scrollWidth > vp.clientWidth + EDGE_EPSILON;\n return vertical || horizontal;\n }\n\n /**\n * Reports the scroll position bucket and 0–1 progress on the primary axis. For\n * `both`, the vertical axis is used when it overflows, otherwise the horizontal.\n */\n #measurePosition(vp: HTMLElement): {\n position: \"start\" | \"middle\" | \"end\";\n progress: number;\n } {\n const horizontalPrimary =\n this.orientationValue === \"horizontal\" ||\n (this.orientationValue === \"both\" && vp.scrollHeight <= vp.clientHeight + EDGE_EPSILON);\n\n const { position: scrollPos, max: maxScroll } = logicalScrollMetrics(vp, horizontalPrimary);\n\n if (maxScroll <= EDGE_EPSILON) return { position: \"start\", progress: 0 };\n\n const progress = Math.min(1, Math.max(0, scrollPos / maxScroll));\n if (scrollPos <= EDGE_EPSILON) return { position: \"start\", progress };\n if (scrollPos >= maxScroll - EDGE_EPSILON) return { position: \"end\", progress };\n return { position: \"middle\", progress };\n }\n\n /**\n * Makes the viewport keyboard-scrollable when it overflows and contains no\n * focusable elements of its own (avoiding a double tab stop). Adds `role=\"region\"`\n * only when the viewport already carries an accessible name.\n */\n #syncKeyboardReach(vp: HTMLElement, overflowing: boolean): void {\n const wantsTabindex = overflowing && !this.#hasFocusableContent(vp);\n\n if (wantsTabindex) {\n this.#tabindex.lend(vp);\n if (!vp.hasAttribute(\"role\") && this.#hasAccessibleName(vp)) {\n this.#role.write(vp, \"region\");\n }\n } else {\n this.#clearAddedAttributes(vp);\n }\n }\n\n /** Removes (and resets the flags for) only the attributes this controller added. */\n #clearAddedAttributes(vp: HTMLElement): void {\n this.#tabindex.returnAll();\n this.#role.return(vp);\n }\n\n /**\n * Whether the viewport owns something the user can Tab to *right now*.\n *\n * The selector alone is not enough: a `display: none` button still matches it,\n * so a viewport whose only control is revealed on demand would never get a tab\n * stop — leaving it unreachable by keyboard exactly while it has nothing else to\n * offer. Only rendered candidates count.\n */\n #hasFocusableContent(vp: HTMLElement): boolean {\n return Array.from(vp.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).some((el) =>\n this.#isRendered(el),\n );\n }\n\n /**\n * Whether `el` is actually rendered, and so can hold focus.\n *\n * `checkVisibility()` answers this for every way CSS can remove a box, including\n * a class-driven `display: none` that no attribute reveals. The `hidden` walk in\n * front of it is not redundant: it is the one case a DOM-only environment with no\n * layout engine has to be told about explicitly.\n */\n #isRendered(el: HTMLElement): boolean {\n if (el.closest(\"[hidden]\") !== null) return false;\n const check = (el as HTMLElement & VisibilityCheckable).checkVisibility;\n return typeof check === \"function\" ? check.call(el, { visibilityProperty: true }) : true;\n }\n\n #hasAccessibleName(vp: HTMLElement): boolean {\n return vp.hasAttribute(\"aria-label\") || vp.hasAttribute(\"aria-labelledby\");\n }\n}\n"]}
@@ -7,10 +7,41 @@ function prefersReducedMotion() {
7
7
  return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
8
8
  }
9
9
 
10
+ // src/utils/before_cache_reset.ts
11
+ var BeforeCacheReset = class _BeforeCacheReset {
12
+ /** Every subscribed instance, iterated by the one shared document listener. */
13
+ static #subscribers = /* @__PURE__ */ new Set();
14
+ /** The shared listener; installed while at least one instance is subscribed. */
15
+ static #onBeforeCache = () => {
16
+ for (const subscriber of _BeforeCacheReset.#subscribers) subscriber.#rewind();
17
+ };
18
+ #rewind;
19
+ /** @param rewind - the pass that returns this controller's state to its initial form. */
20
+ constructor(rewind) {
21
+ this.#rewind = rewind;
22
+ }
23
+ /** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */
24
+ activate() {
25
+ const first = _BeforeCacheReset.#subscribers.size === 0;
26
+ _BeforeCacheReset.#subscribers.add(this);
27
+ if (first) {
28
+ document.addEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
29
+ }
30
+ }
31
+ /** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */
32
+ deactivate() {
33
+ _BeforeCacheReset.#subscribers.delete(this);
34
+ if (_BeforeCacheReset.#subscribers.size > 0) return;
35
+ document.removeEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
36
+ }
37
+ };
38
+
10
39
  // src/utils/tabindex_loan.ts
11
40
  var TabindexLoan = class {
12
41
  #value;
13
42
  #lent = /* @__PURE__ */ new Set();
43
+ /** Returns live loans before Turbo can copy them into its page snapshot. */
44
+ #beforeCache = new BeforeCacheReset(() => this.returnAll());
14
45
  /**
15
46
  * @param value - the `tabindex` to lend. `"-1"` (the default) is
16
47
  * programmatically focusable but not a Tab stop; `"0"` is a real Tab stop,
@@ -24,6 +55,7 @@ var TabindexLoan = class {
24
55
  if (element.hasAttribute("tabindex")) return;
25
56
  element.setAttribute("tabindex", this.#value);
26
57
  this.#lent.add(element);
58
+ this.#beforeCache.activate();
27
59
  }
28
60
  /** Takes back every loan whose value is still the one that was lent. */
29
61
  returnAll() {
@@ -31,6 +63,7 @@ var TabindexLoan = class {
31
63
  if (element.getAttribute("tabindex") === this.#value) element.removeAttribute("tabindex");
32
64
  }
33
65
  this.#lent.clear();
66
+ this.#beforeCache.deactivate();
34
67
  }
35
68
  };
36
69
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/reduced_motion.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,cAC7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A,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 * Shared bookkeeping for a `tabindex` a controller lends an element temporarily.\n *\n * A controller that must move focus somewhere the author never made focusable\n * (a landmark root, a scroll destination) reaches for the same trick: add a\n * `tabindex` just-in-time and hand it back once it is no longer needed. The\n * borrow is the easy half; the return is what the two conditions below are for.\n *\n * **Returning needs two conditions, not one.** Owning the borrow is not enough:\n * the attribute must also still hold the value this instance wrote. A consumer\n * that changed it afterwards — `tabindex=\"0\"` to make the root its own Tab stop\n * — owns it now, and removing it there silently discards authored markup. The\n * bookkeeping is dropped either way, since the loan is over regardless of who\n * ends up owning the value.\n *\n * **Never borrow over an existing value.** An element that already carries a\n * `tabindex` is the author's to control, so there is nothing to lend and nothing\n * to return.\n *\n * The registry is keyed by element, so a controller borrowing on a single\n * element (`this.element`) and one borrowing across a changing set of targets\n * use the same API — the single-element case is a set of one. It holds no\n * opinion about *when* to borrow or where focus goes next; that stays in the\n * controller.\n *\n * **The API is deliberately two methods.** This file's own doc block is dropped\n * from `dist`, but every member comment is inlined into **each** consumer entry\n * (`tsup` builds with `splitting: false`), so rationale belongs here, only the\n * contract belongs on the members, and every method no consumer calls is still\n * paid for once per consumer entry.\n *\n * @example\n * ```ts\n * readonly #tabindex = new TabindexLoan();\n *\n * #rescueFocus() {\n * this.#tabindex.lend(this.element);\n * this.element.focus();\n * }\n *\n * disconnect() {\n * this.#tabindex.returnAll();\n * }\n * ```\n */\nexport class TabindexLoan<T extends HTMLElement = HTMLElement> {\n readonly #value: string;\n readonly #lent = new Set<T>();\n\n /**\n * @param value - the `tabindex` to lend. `\"-1\"` (the default) is\n * programmatically focusable but not a Tab stop; `\"0\"` is a real Tab stop,\n * which a scroll region with no focusable content of its own needs.\n */\n constructor(value: string = \"-1\") {\n this.#value = value;\n }\n\n /** Lends `element` the value; no-ops when it already carries a `tabindex`. */\n lend(element: T): void {\n if (element.hasAttribute(\"tabindex\")) return;\n element.setAttribute(\"tabindex\", this.#value);\n this.#lent.add(element);\n }\n\n /** Takes back every loan whose value is still the one that was lent. */\n returnAll(): void {\n for (const element of this.#lent) {\n if (element.getAttribute(\"tabindex\") === this.#value) element.removeAttribute(\"tabindex\");\n }\n this.#lent.clear();\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { 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 * @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/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,CA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AAA,MAAO;AACL,QAAA,WAAA,GAAc,IAAI,IAAA,CAAK,YAAA;AAAA,MACzB;AAAA,IACF,CAAA,MAAO;AACL,MAAA,WAAA,GAAc,IAAI,IAAA,CAAK,WAAA;AAAA,IACzB;AACA,IAAA,IAAA,CAAK,YAAA,GAAe,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 * @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"]}
@@ -8,6 +8,13 @@ function isReservedArrowChord(event, allow = []) {
8
8
  return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
9
9
  }
10
10
 
11
+ // src/utils/default_attribute.ts
12
+ function setDefaultAttribute(element, name, value) {
13
+ if (element.hasAttribute(name)) return false;
14
+ element.setAttribute(name, value);
15
+ return true;
16
+ }
17
+
11
18
  // src/controllers/separator_controller.ts
12
19
  var SeparatorController = class extends Controller {
13
20
  static values = {
@@ -18,19 +25,13 @@ var SeparatorController = class extends Controller {
18
25
  static actions = ["onKeydown"];
19
26
  static events = ["change"];
20
27
  connect() {
21
- if (!this.element.hasAttribute("role")) {
22
- this.element.setAttribute("role", "separator");
23
- }
24
- if (!this.element.hasAttribute("aria-orientation")) {
25
- this.element.setAttribute("aria-orientation", this.orientationValue);
26
- }
28
+ setDefaultAttribute(this.element, "role", "separator");
29
+ setDefaultAttribute(this.element, "aria-orientation", this.orientationValue);
27
30
  if (this.focusableValue) {
28
- if (!this.element.hasAttribute("tabindex")) {
29
- this.element.setAttribute("tabindex", "0");
30
- }
31
- this.#setDefault("aria-valuemin", "0");
32
- this.#setDefault("aria-valuemax", "100");
33
- this.#setDefault("aria-valuenow", String(this.#clamp(this.#value)));
31
+ setDefaultAttribute(this.element, "tabindex", "0");
32
+ setDefaultAttribute(this.element, "aria-valuemin", "0");
33
+ setDefaultAttribute(this.element, "aria-valuemax", "100");
34
+ setDefaultAttribute(this.element, "aria-valuenow", String(this.#clamp(this.#value)));
34
35
  }
35
36
  }
36
37
  /** Adjusts the value on arrow / Home / End keys (focusable variant only). */
@@ -84,11 +85,6 @@ var SeparatorController = class extends Controller {
84
85
  const parsed = Number.parseFloat(this.element.getAttribute(name) ?? "");
85
86
  return Number.isNaN(parsed) ? fallback : parsed;
86
87
  }
87
- #setDefault(name, value) {
88
- if (!this.element.hasAttribute(name)) {
89
- this.element.setAttribute(name, value);
90
- }
91
- }
92
88
  };
93
89
 
94
90
  export { SeparatorController };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/arrow_step.ts","../../src/controllers/separator_controller.ts"],"names":[],"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;;;AC/DO,IAAM,mBAAA,GAAN,cAAkC,UAAA,CAAwB;AAAA,EAC/D,OAAgB,MAAA,GAA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,EAAO,OAAA,IAAW,CAAA;AAAA,EACxD;AAAA,EAEA,IAAI,MAAA,GAAiB;AACnB,IAAA,OAAO,IAAA,CAAK,YAAA,CAAa,eAAA,EAAiB,CAAC,CAAA;AAAA,EAC7C;AAAA,EAEA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,IAAA,CAAK,YAAA,CAAa,eAAA,EAAiB,CAAC,CAAA;AAAA,EAC7C;AAAA,EAEA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,IAAA,CAAK,YAAA,CAAa,eAAA,EAAiB,GAAG,CAAA;AAAA,EAC/C;AAAA,EAEA,OAAO,KAAA,EAAuB;AAC5B,IAAA,OAAO,IAAA,CAAK,IAAI,IAAA,CAAK,IAAA,EAAM,KAAK,GAAA,CAAI,IAAA,CAAK,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA,EACvD;AAAA,EAEA,YAAA,CAAa,MAAc,QAAA,EAA0B;AACnD,IAAA,MAAM,MAAA,GAAS,OAAO,UAAA,CAAW,IAAA,CAAK,QAAQ,YAAA,CAAa,IAAI,KAAK,EAAE,CAAA;AACtE,IAAA,OAAO,MAAA,CAAO,KAAA,CAAM,MAAM,CAAA,GAAI,QAAA,GAAW,MAAA;AAAA,EAC3C;AAAA,EAEA,WAAA,CAAY,MAAc,KAAA,EAAqB;AAC7C,IAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,IAAI,CAAA,EAAG;AACpC,MAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,IAAA,EAAM,KAAK,CAAA;AAAA,IACvC;AAAA,EACF;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","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\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\" role=\"separator\"\n * data-stimeo--separator-orientation-value=\"horizontal\"></div>\n *\n * <!-- focusable, value-bearing -->\n * <div data-controller=\"stimeo--separator\" role=\"separator\" tabindex=\"0\"\n * aria-labelledby=\"sidebar-heading\" aria-controls=\"sidebar\"\n * aria-orientation=\"vertical\"\n * aria-valuemin=\"0\" aria-valuemax=\"100\" aria-valuenow=\"50\"\n * data-stimeo--separator-focusable-value=\"true\"\n * data-action=\"keydown->stimeo--separator#onKeydown\"></div>\n *\n * Most separators are static (`role=\"separator\"` + `aria-orientation`); this\n * controller adds those semantics and, for the optional **focusable** variant,\n * keeps `aria-valuenow` in sync and emits arrow-key value changes. The actual\n * pane resize/drag is out of scope — that belongs to {@link ResizableController}.\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 * 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 primary pane can only\n * be the left one for a vertical splitter and the bottom one for a horizontal\n * splitter: those are the panes that grow as 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 step: { type: Number, default: 1 },\n };\n static actions = [\"onKeydown\"] as const;\n static events = [\"change\"] as const;\n\n declare orientationValue: string;\n declare focusableValue: boolean;\n declare stepValue: number;\n\n override connect(): void {\n if (!this.element.hasAttribute(\"role\")) {\n this.element.setAttribute(\"role\", \"separator\");\n }\n if (!this.element.hasAttribute(\"aria-orientation\")) {\n this.element.setAttribute(\"aria-orientation\", this.orientationValue);\n }\n\n if (this.focusableValue) {\n if (!this.element.hasAttribute(\"tabindex\")) {\n this.element.setAttribute(\"tabindex\", \"0\");\n }\n // A value-bearing separator needs a bounded range; default it if the\n // consumer left any bound off so arrow keys have something to clamp to.\n this.#setDefault(\"aria-valuemin\", \"0\");\n this.#setDefault(\"aria-valuemax\", \"100\");\n this.#setDefault(\"aria-valuenow\", String(this.#clamp(this.#value)));\n }\n }\n\n /** Adjusts the value on arrow / Home / End keys (focusable variant only). */\n onKeydown(event: KeyboardEvent): void {\n if (isReservedArrowChord(event)) return;\n if (!this.focusableValue) return;\n\n // `aria-orientation` is the source of truth (connect seeds it from the\n // orientation value when the consumer left it off), so the focusable variant\n // that sets the attribute directly drives the axis correctly.\n const horizontal = this.element.getAttribute(\"aria-orientation\") !== \"vertical\";\n let next: number | null = null;\n switch (event.key) {\n case \"ArrowUp\":\n if (horizontal) next = this.#value + this.stepValue;\n break;\n case \"ArrowDown\":\n if (horizontal) next = this.#value - this.stepValue;\n break;\n case \"ArrowRight\":\n if (!horizontal) next = this.#value + this.stepValue;\n break;\n case \"ArrowLeft\":\n if (!horizontal) next = this.#value - this.stepValue;\n break;\n case \"Home\":\n next = this.#min;\n break;\n case \"End\":\n next = this.#max;\n break;\n default:\n return;\n }\n if (next === null) return;\n\n event.preventDefault();\n const clamped = this.#clamp(next);\n if (clamped === this.#value) return;\n\n this.element.setAttribute(\"aria-valuenow\", String(clamped));\n this.dispatch(\"change\", { detail: { value: clamped } });\n }\n\n get #value(): number {\n return this.#numericAttr(\"aria-valuenow\", 0);\n }\n\n get #min(): number {\n return this.#numericAttr(\"aria-valuemin\", 0);\n }\n\n get #max(): number {\n return this.#numericAttr(\"aria-valuemax\", 100);\n }\n\n #clamp(value: number): number {\n return Math.min(this.#max, Math.max(this.#min, value));\n }\n\n #numericAttr(name: string, fallback: number): number {\n const parsed = Number.parseFloat(this.element.getAttribute(name) ?? \"\");\n return Number.isNaN(parsed) ? fallback : parsed;\n }\n\n #setDefault(name: string, value: string): void {\n if (!this.element.hasAttribute(name)) {\n this.element.setAttribute(name, value);\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/arrow_step.ts","../../src/utils/default_attribute.ts","../../src/controllers/separator_controller.ts"],"names":[],"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;;;AC9FO,SAAS,mBAAA,CAAoB,OAAA,EAAkB,IAAA,EAAc,KAAA,EAAwB;AAC1F,EAAA,IAAI,OAAA,CAAQ,YAAA,CAAa,IAAI,CAAA,EAAG,OAAO,KAAA;AACvC,EAAA,OAAA,CAAQ,YAAA,CAAa,MAAM,KAAK,CAAA;AAChC,EAAA,OAAO,IAAA;AACT;;;AC4BO,IAAM,mBAAA,GAAN,cAAkC,UAAA,CAAwB;AAAA,EAC/D,OAAgB,MAAA,GAAS;AAAA,IACvB,WAAA,EAAa,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,YAAA,EAAa;AAAA,IACnD,SAAA,EAAW,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,KAAA,EAAM;AAAA,IAC3C,IAAA,EAAM,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,CAAA;AAAE,GACnC;AAAA,EACA,OAAO,OAAA,GAAU,CAAC,WAAW,CAAA;AAAA,EAC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AAK,CAAC,CAAA;AAAA,EACvD;AAAA,EAEA,YAAA,CAAa,MAAc,QAAA,EAA0B;AACnD,IAAA,MAAM,MAAA,GAAS,OAAO,UAAA,CAAW,IAAA,CAAK,QAAQ,YAAA,CAAa,IAAI,KAAK,EAAE,CAAA;AACtE,IAAA,OAAO,MAAA,CAAO,KAAA,CAAM,MAAM,CAAA,GAAI,QAAA,GAAW,MAAA;AAAA,EAC3C;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 * Adds an attribute default without displacing an authored value.\n *\n * Attribute presence — including an authored empty string — is the ownership\n * boundary. The return value lets a caller remember that it supplied the\n * default when that caller must later restore the authored state.\n *\n * @param element - Element that owns the attribute\n * @param name - Attribute name\n * @param value - Value to write only when the attribute is absent\n * @returns Whether this call added the attribute\n */\nexport function setDefaultAttribute(element: Element, name: string, value: string): boolean {\n if (element.hasAttribute(name)) return false;\n element.setAttribute(name, value);\n return true;\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\nimport { setDefaultAttribute } from \"../utils/default_attribute\";\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\" role=\"separator\"\n * data-stimeo--separator-orientation-value=\"horizontal\"></div>\n *\n * <!-- focusable, value-bearing -->\n * <div data-controller=\"stimeo--separator\" role=\"separator\" tabindex=\"0\"\n * aria-labelledby=\"sidebar-heading\" aria-controls=\"sidebar\"\n * aria-orientation=\"vertical\"\n * aria-valuemin=\"0\" aria-valuemax=\"100\" aria-valuenow=\"50\"\n * data-stimeo--separator-focusable-value=\"true\"\n * data-action=\"keydown->stimeo--separator#onKeydown\"></div>\n *\n * Most separators are static (`role=\"separator\"` + `aria-orientation`); this\n * controller adds those semantics and, for the optional **focusable** variant,\n * keeps `aria-valuenow` in sync and emits arrow-key value changes. The actual\n * pane resize/drag is out of scope — that belongs to {@link ResizableController}.\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 * 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 primary pane can only\n * be the left one for a vertical splitter and the bottom one for a horizontal\n * splitter: those are the panes that grow as 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 step: { type: Number, default: 1 },\n };\n static actions = [\"onKeydown\"] as const;\n static events = [\"change\"] as const;\n\n declare orientationValue: string;\n declare focusableValue: boolean;\n declare stepValue: number;\n\n override connect(): void {\n setDefaultAttribute(this.element, \"role\", \"separator\");\n setDefaultAttribute(this.element, \"aria-orientation\", this.orientationValue);\n\n if (this.focusableValue) {\n setDefaultAttribute(this.element, \"tabindex\", \"0\");\n // A value-bearing separator needs a bounded range; default it if the\n // consumer left any bound off so arrow keys have something to clamp to.\n setDefaultAttribute(this.element, \"aria-valuemin\", \"0\");\n setDefaultAttribute(this.element, \"aria-valuemax\", \"100\");\n setDefaultAttribute(this.element, \"aria-valuenow\", String(this.#clamp(this.#value)));\n }\n }\n\n /** Adjusts the value on arrow / Home / End keys (focusable variant only). */\n onKeydown(event: KeyboardEvent): void {\n if (isReservedArrowChord(event)) return;\n if (!this.focusableValue) return;\n\n // `aria-orientation` is the source of truth (connect seeds it from the\n // orientation value when the consumer left it off), so the focusable variant\n // that sets the attribute directly drives the axis correctly.\n const horizontal = this.element.getAttribute(\"aria-orientation\") !== \"vertical\";\n let next: number | null = null;\n switch (event.key) {\n case \"ArrowUp\":\n if (horizontal) next = this.#value + this.stepValue;\n break;\n case \"ArrowDown\":\n if (horizontal) next = this.#value - this.stepValue;\n break;\n case \"ArrowRight\":\n if (!horizontal) next = this.#value + this.stepValue;\n break;\n case \"ArrowLeft\":\n if (!horizontal) next = this.#value - this.stepValue;\n break;\n case \"Home\":\n next = this.#min;\n break;\n case \"End\":\n next = this.#max;\n break;\n default:\n return;\n }\n if (next === null) return;\n\n event.preventDefault();\n const clamped = this.#clamp(next);\n if (clamped === this.#value) return;\n\n this.element.setAttribute(\"aria-valuenow\", String(clamped));\n this.dispatch(\"change\", { detail: { value: clamped } });\n }\n\n get #value(): number {\n return this.#numericAttr(\"aria-valuenow\", 0);\n }\n\n get #min(): number {\n return this.#numericAttr(\"aria-valuemin\", 0);\n }\n\n get #max(): number {\n return this.#numericAttr(\"aria-valuemax\", 100);\n }\n\n #clamp(value: number): number {\n return Math.min(this.#max, Math.max(this.#min, value));\n }\n\n #numericAttr(name: string, fallback: number): number {\n const parsed = Number.parseFloat(this.element.getAttribute(name) ?? \"\");\n return Number.isNaN(parsed) ? fallback : parsed;\n }\n}\n"]}
@@ -20,8 +20,8 @@ import { Controller } from '@hotwired/stimulus';
20
20
  *
21
21
  * @remarks
22
22
  * Behavior only — skeleton shapes/animation are the consumer's. The
23
- * min-duration wait is held by {@link MinDurationFloor} on a {@link SafeTimeout}
24
- * torn down on `disconnect()` (Turbo navigation included).
23
+ * min-duration wait is held by {@link MinDurationFloor} on a {@link SafeTimeout},
24
+ * kept across an in-page move and dropped on a real detach via {@link DetachGate}.
25
25
  */
26
26
  declare class SkeletonController extends Controller<HTMLElement> {
27
27
  #private;
@@ -19,6 +19,61 @@ function fillTemplate(template, values) {
19
19
  });
20
20
  }
21
21
 
22
+ // src/utils/detach_gate.ts
23
+ var DetachGate = class _DetachGate {
24
+ /** Set while a probe is queued, waiting for a reconnect to cancel it. */
25
+ #pending = false;
26
+ /**
27
+ * True while a probe is queued — the last disconnect was ambiguous and no
28
+ * reconnect has cancelled it yet. Read it from `connect()` to tell the
29
+ * reconnect half of an in-page move from a first connect: a controller whose
30
+ * initialisation restarts a measurement (a min-duration floor, an elapsed
31
+ * counter) must skip it for the move, where nothing actually restarted.
32
+ */
33
+ get pending() {
34
+ return this.#pending;
35
+ }
36
+ /**
37
+ * True when the disconnect is definitely a real detach — the element left
38
+ * the document, or `data-controller` no longer lists the identifier. False
39
+ * means ambiguous (in-page move or observed-root exit), NOT "alive".
40
+ */
41
+ static isDetached(host) {
42
+ if (!host.element.isConnected) return true;
43
+ const tokens = (host.element.getAttribute("data-controller") ?? "").split(/\s+/);
44
+ return !tokens.includes(host.identifier);
45
+ }
46
+ /**
47
+ * Call from `disconnect()`: runs `teardown` synchronously on a definite
48
+ * detach (fast path), otherwise defers it one microtask — a reconnect
49
+ * ({@link cancel} from `connect()`) keeps the state, no reconnect runs it.
50
+ * One microtask is the whole probe window: Stimulus reconnects a moved
51
+ * element within the same mutation batch, before the checkpoint drains.
52
+ */
53
+ disconnected(host, teardown) {
54
+ if (_DetachGate.isDetached(host)) {
55
+ this.#pending = false;
56
+ teardown();
57
+ return;
58
+ }
59
+ this.#pending = true;
60
+ queueMicrotask(() => {
61
+ if (!this.#pending) return;
62
+ this.#pending = false;
63
+ teardown();
64
+ });
65
+ }
66
+ /**
67
+ * Disarms a pending probe. Call from `connect()` (the reconnect that proves
68
+ * an in-page move) and from the head of any teardown path not routed through
69
+ * {@link disconnected} (disabled-toggle, Escape), so an orphaned probe can
70
+ * never run the teardown a second time.
71
+ */
72
+ cancel() {
73
+ this.#pending = false;
74
+ }
75
+ };
76
+
22
77
  // src/utils/min_duration_floor.ts
23
78
  var MinDurationFloor = class {
24
79
  #timers;
@@ -131,14 +186,16 @@ var SkeletonController = class extends Controller {
131
186
  static events = ["ready"];
132
187
  #timers = new SafeTimeout();
133
188
  #floor = new MinDurationFloor(this.#timers);
189
+ #gate = new DetachGate();
134
190
  connect() {
135
- if (this.#state !== "ready") {
191
+ const moved = this.#gate.pending;
192
+ this.#gate.cancel();
193
+ if (!moved && this.#state !== "ready") {
136
194
  this.#enterLoading();
137
195
  }
138
196
  }
139
197
  disconnect() {
140
- this.#timers.clearAll();
141
- this.#floor.cancel();
198
+ this.#gate.disconnected(this, () => this.#teardown());
142
199
  }
143
200
  /** Swaps to the real content. Honors `minDuration` to prevent a flash. */
144
201
  ready() {
@@ -167,6 +224,17 @@ var SkeletonController = class extends Controller {
167
224
  this.dispatch("ready", { detail: {} });
168
225
  announce(fillTemplate(this.announceReadyTextValue, {}));
169
226
  }
227
+ /**
228
+ * Drops the held reveal on a real detach. The markup keeps whatever it last
229
+ * held: an element on its way out of the document has no reader left, and one
230
+ * whose `data-controller` dropped the identifier no longer resolves its own
231
+ * targets, so the rollback could only ever be partial.
232
+ */
233
+ #teardown() {
234
+ this.#gate.cancel();
235
+ this.#timers.clearAll();
236
+ this.#floor.cancel();
237
+ }
170
238
  /** Current lifecycle phase as reflected on `data-state`. */
171
239
  get #state() {
172
240
  return this.element.getAttribute("data-state") ?? "loading";