stimeo-ui 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +160 -0
- package/dist/cable/index.d.ts +16 -16
- package/dist/cable/index.js.map +1 -1
- package/dist/controllers/accordion_controller.js +10 -0
- package/dist/controllers/accordion_controller.js.map +1 -1
- package/dist/controllers/alert_dialog_controller.js +32 -5
- package/dist/controllers/alert_dialog_controller.js.map +1 -1
- package/dist/controllers/announcer_controller.d.ts +32 -6
- package/dist/controllers/announcer_controller.js +255 -20
- package/dist/controllers/announcer_controller.js.map +1 -1
- package/dist/controllers/breadcrumb_controller.d.ts +97 -10
- package/dist/controllers/breadcrumb_controller.js +225 -13
- package/dist/controllers/breadcrumb_controller.js.map +1 -1
- package/dist/controllers/calendar_controller.d.ts +11 -1
- package/dist/controllers/calendar_controller.js +89 -22
- package/dist/controllers/calendar_controller.js.map +1 -1
- package/dist/controllers/carousel_controller.d.ts +16 -1
- package/dist/controllers/carousel_controller.js +47 -6
- package/dist/controllers/carousel_controller.js.map +1 -1
- package/dist/controllers/collapsible_controller.js +2 -2
- package/dist/controllers/collapsible_controller.js.map +1 -1
- package/dist/controllers/color_picker_controller.d.ts +14 -2
- package/dist/controllers/color_picker_controller.js +92 -7
- package/dist/controllers/color_picker_controller.js.map +1 -1
- package/dist/controllers/combobox_controller.d.ts +14 -1
- package/dist/controllers/combobox_controller.js +162 -23
- package/dist/controllers/combobox_controller.js.map +1 -1
- package/dist/controllers/command_palette_controller.d.ts +2 -0
- package/dist/controllers/command_palette_controller.js +226 -22
- package/dist/controllers/command_palette_controller.js.map +1 -1
- package/dist/controllers/confirm_controller.js +32 -5
- package/dist/controllers/confirm_controller.js.map +1 -1
- package/dist/controllers/context_menu_controller.d.ts +7 -6
- package/dist/controllers/context_menu_controller.js +32 -10
- package/dist/controllers/context_menu_controller.js.map +1 -1
- package/dist/controllers/count_up_controller.js.map +1 -1
- package/dist/controllers/countdown_controller.d.ts +19 -5
- package/dist/controllers/countdown_controller.js +112 -12
- package/dist/controllers/countdown_controller.js.map +1 -1
- package/dist/controllers/data_grid_controller.d.ts +19 -1
- package/dist/controllers/data_grid_controller.js +82 -4
- package/dist/controllers/data_grid_controller.js.map +1 -1
- package/dist/controllers/date_range_picker_controller.d.ts +5 -1
- package/dist/controllers/date_range_picker_controller.js +77 -3
- package/dist/controllers/date_range_picker_controller.js.map +1 -1
- package/dist/controllers/dialog_controller.js +32 -5
- package/dist/controllers/dialog_controller.js.map +1 -1
- package/dist/controllers/dismissible_controller.js.map +1 -1
- package/dist/controllers/drawer_controller.js +32 -5
- package/dist/controllers/drawer_controller.js.map +1 -1
- package/dist/controllers/dropdown_controller.d.ts +1 -2
- package/dist/controllers/dropdown_controller.js.map +1 -1
- package/dist/controllers/editable_controller.js +1 -0
- package/dist/controllers/editable_controller.js.map +1 -1
- package/dist/controllers/empty_state_controller.d.ts +9 -4
- package/dist/controllers/empty_state_controller.js +24 -10
- package/dist/controllers/empty_state_controller.js.map +1 -1
- package/dist/controllers/focus_controller.d.ts +1 -1
- package/dist/controllers/focus_controller.js +32 -5
- package/dist/controllers/focus_controller.js.map +1 -1
- package/dist/controllers/form_field_controller.js.map +1 -1
- package/dist/controllers/form_validation_controller.js +1 -1
- package/dist/controllers/form_validation_controller.js.map +1 -1
- package/dist/controllers/frame_loading_controller.d.ts +14 -3
- package/dist/controllers/frame_loading_controller.js +177 -15
- package/dist/controllers/frame_loading_controller.js.map +1 -1
- package/dist/controllers/highlight_controller.js.map +1 -1
- package/dist/controllers/hover_card_controller.d.ts +1 -1
- package/dist/controllers/hover_card_controller.js.map +1 -1
- package/dist/controllers/intersection_controller.js +36 -11
- package/dist/controllers/intersection_controller.js.map +1 -1
- package/dist/controllers/lazy_frame_controller.js +31 -10
- package/dist/controllers/lazy_frame_controller.js.map +1 -1
- package/dist/controllers/listbox_controller.d.ts +9 -2
- package/dist/controllers/listbox_controller.js +257 -53
- package/dist/controllers/listbox_controller.js.map +1 -1
- package/dist/controllers/local_time_controller.d.ts +19 -3
- package/dist/controllers/local_time_controller.js +102 -8
- package/dist/controllers/local_time_controller.js.map +1 -1
- package/dist/controllers/menu_controller.d.ts +29 -11
- package/dist/controllers/menu_controller.js +104 -17
- package/dist/controllers/menu_controller.js.map +1 -1
- package/dist/controllers/menubar_controller.d.ts +91 -11
- package/dist/controllers/menubar_controller.js +415 -63
- package/dist/controllers/menubar_controller.js.map +1 -1
- package/dist/controllers/meter_controller.d.ts +22 -2
- package/dist/controllers/meter_controller.js +145 -26
- package/dist/controllers/meter_controller.js.map +1 -1
- package/dist/controllers/multi_select_controller.d.ts +31 -5
- package/dist/controllers/multi_select_controller.js +312 -29
- package/dist/controllers/multi_select_controller.js.map +1 -1
- package/dist/controllers/navigation_menu_controller.d.ts +65 -18
- package/dist/controllers/navigation_menu_controller.js +154 -27
- package/dist/controllers/navigation_menu_controller.js.map +1 -1
- package/dist/controllers/nested_form_controller.d.ts +4 -5
- package/dist/controllers/nested_form_controller.js.map +1 -1
- package/dist/controllers/network_status_controller.d.ts +13 -1
- package/dist/controllers/network_status_controller.js +28 -8
- package/dist/controllers/network_status_controller.js.map +1 -1
- package/dist/controllers/number_input_controller.d.ts +1 -1
- package/dist/controllers/number_input_controller.js +7 -0
- package/dist/controllers/number_input_controller.js.map +1 -1
- package/dist/controllers/otp_controller.js +18 -1
- package/dist/controllers/otp_controller.js.map +1 -1
- package/dist/controllers/overflow_indicator_controller.d.ts +3 -2
- package/dist/controllers/overflow_indicator_controller.js +81 -13
- package/dist/controllers/overflow_indicator_controller.js.map +1 -1
- package/dist/controllers/overflow_menu_controller.d.ts +78 -19
- package/dist/controllers/overflow_menu_controller.js +408 -57
- package/dist/controllers/overflow_menu_controller.js.map +1 -1
- package/dist/controllers/pagination_controller.d.ts +36 -5
- package/dist/controllers/pagination_controller.js +163 -32
- package/dist/controllers/pagination_controller.js.map +1 -1
- package/dist/controllers/persist_controller.js +6 -6
- package/dist/controllers/persist_controller.js.map +1 -1
- package/dist/controllers/pointer_drag_controller.d.ts +2 -3
- package/dist/controllers/pointer_drag_controller.js +9 -1
- package/dist/controllers/pointer_drag_controller.js.map +1 -1
- package/dist/controllers/popover_controller.d.ts +1 -2
- package/dist/controllers/popover_controller.js +2 -2
- package/dist/controllers/popover_controller.js.map +1 -1
- package/dist/controllers/portal_controller.d.ts +4 -4
- package/dist/controllers/portal_controller.js.map +1 -1
- package/dist/controllers/progress_controller.d.ts +16 -1
- package/dist/controllers/progress_controller.js +116 -9
- package/dist/controllers/progress_controller.js.map +1 -1
- package/dist/controllers/radio_group_controller.js +22 -3
- package/dist/controllers/radio_group_controller.js.map +1 -1
- package/dist/controllers/range_slider_controller.d.ts +18 -5
- package/dist/controllers/range_slider_controller.js +100 -9
- package/dist/controllers/range_slider_controller.js.map +1 -1
- package/dist/controllers/rating_controller.d.ts +4 -1
- package/dist/controllers/rating_controller.js +69 -2
- package/dist/controllers/rating_controller.js.map +1 -1
- package/dist/controllers/read_more_controller.js +63 -19
- package/dist/controllers/read_more_controller.js.map +1 -1
- package/dist/controllers/reading_progress_controller.js.map +1 -1
- package/dist/controllers/relative_time_controller.d.ts +13 -0
- package/dist/controllers/relative_time_controller.js +133 -12
- package/dist/controllers/relative_time_controller.js.map +1 -1
- package/dist/controllers/resizable_controller.d.ts +3 -1
- package/dist/controllers/resizable_controller.js +65 -1
- package/dist/controllers/resizable_controller.js.map +1 -1
- package/dist/controllers/roving_controller.js +17 -2
- package/dist/controllers/roving_controller.js.map +1 -1
- package/dist/controllers/scroll_area_controller.js +86 -12
- package/dist/controllers/scroll_area_controller.js.map +1 -1
- package/dist/controllers/scroll_restore_controller.js +1 -1
- package/dist/controllers/scroll_restore_controller.js.map +1 -1
- package/dist/controllers/scroll_visibility_controller.d.ts +6 -3
- package/dist/controllers/scroll_visibility_controller.js +33 -3
- package/dist/controllers/scroll_visibility_controller.js.map +1 -1
- package/dist/controllers/scrollspy_controller.d.ts +64 -15
- package/dist/controllers/scrollspy_controller.js +346 -73
- package/dist/controllers/scrollspy_controller.js.map +1 -1
- package/dist/controllers/separator_controller.d.ts +20 -5
- package/dist/controllers/separator_controller.js +9 -0
- package/dist/controllers/separator_controller.js.map +1 -1
- package/dist/controllers/sidebar_controller.d.ts +2 -12
- package/dist/controllers/sidebar_controller.js +37 -8
- package/dist/controllers/sidebar_controller.js.map +1 -1
- package/dist/controllers/skeleton_controller.d.ts +7 -2
- package/dist/controllers/skeleton_controller.js +73 -20
- package/dist/controllers/skeleton_controller.js.map +1 -1
- package/dist/controllers/slider_controller.d.ts +11 -1
- package/dist/controllers/slider_controller.js +49 -8
- package/dist/controllers/slider_controller.js.map +1 -1
- package/dist/controllers/sortable_controller.d.ts +3 -1
- package/dist/controllers/sortable_controller.js +34 -3
- package/dist/controllers/sortable_controller.js.map +1 -1
- package/dist/controllers/spinner_controller.d.ts +37 -4
- package/dist/controllers/spinner_controller.js +228 -27
- package/dist/controllers/spinner_controller.js.map +1 -1
- package/dist/controllers/step_indicator_controller.d.ts +12 -1
- package/dist/controllers/step_indicator_controller.js +82 -5
- package/dist/controllers/step_indicator_controller.js.map +1 -1
- package/dist/controllers/stick_to_bottom_controller.d.ts +31 -8
- package/dist/controllers/stick_to_bottom_controller.js +61 -10
- package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
- package/dist/controllers/sticky_observer_controller.js +32 -11
- package/dist/controllers/sticky_observer_controller.js.map +1 -1
- package/dist/controllers/submit_once_controller.d.ts +2 -2
- package/dist/controllers/submit_once_controller.js.map +1 -1
- package/dist/controllers/switch_controller.js +1 -0
- package/dist/controllers/switch_controller.js.map +1 -1
- package/dist/controllers/tabs_controller.d.ts +11 -3
- package/dist/controllers/tabs_controller.js +26 -3
- package/dist/controllers/tabs_controller.js.map +1 -1
- package/dist/controllers/tags_input_controller.js +22 -2
- package/dist/controllers/tags_input_controller.js.map +1 -1
- package/dist/controllers/theme_controller.d.ts +1 -1
- package/dist/controllers/theme_controller.js +22 -3
- package/dist/controllers/theme_controller.js.map +1 -1
- package/dist/controllers/time_picker_controller.js +20 -1
- package/dist/controllers/time_picker_controller.js.map +1 -1
- package/dist/controllers/toast_controller.d.ts +4 -5
- package/dist/controllers/toast_controller.js +4 -5
- package/dist/controllers/toast_controller.js.map +1 -1
- package/dist/controllers/toggle_group_controller.js +23 -2
- package/dist/controllers/toggle_group_controller.js.map +1 -1
- package/dist/controllers/toolbar_controller.d.ts +53 -13
- package/dist/controllers/toolbar_controller.js +230 -31
- package/dist/controllers/toolbar_controller.js.map +1 -1
- package/dist/controllers/tooltip_controller.d.ts +1 -1
- package/dist/controllers/tooltip_controller.js.map +1 -1
- package/dist/controllers/transition_controller.js.map +1 -1
- package/dist/controllers/tree_view_controller.d.ts +87 -6
- package/dist/controllers/tree_view_controller.js +467 -51
- package/dist/controllers/tree_view_controller.js.map +1 -1
- package/dist/index.js +4507 -907
- package/dist/index.js.map +1 -1
- package/dist/inspector/cli.d.ts +375 -39
- package/dist/inspector/cli.js +1009 -86
- package/dist/inspector/cli.js.map +1 -1
- package/dist/inspector/cli_bin.js +1200 -120
- package/dist/inspector/cli_bin.js.map +1 -1
- package/dist/inspector/examples.json +28 -28
- package/dist/inspector/manifest.json +1060 -132
- package/package.json +5 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/layout_observer.ts","../../src/utils/logical_scroll.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,GAAqB,KAAA;AAAA;AAAA,EAGZ,wBAAwB,MAAY;AAC3C,IAAA,IAAA,CAAK,SAAA,EAAU;AAAA,EACjB,CAAA;AAAA,EAEA,WAAA,CAAY,QAAA,EAA0B,OAAA,GAAiC,EAAC,EAAG;AACzE,IAAA,IAAA,CAAK,SAAA,GAAY,QAAA;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;AACvB,MAAA,EAAA,CAAG,gBAAgB,UAAU,CAAA;AAC7B,MAAA,IAAA,CAAK,cAAA,GAAiB,KAAA;AAAA,IACxB;AACA,IAAA,IAAI,KAAK,UAAA,EAAY;AACnB,MAAA,EAAA,CAAG,gBAAgB,MAAM,CAAA;AACzB,MAAA,IAAA,CAAK,UAAA,GAAa,KAAA;AAAA,IACpB;AAAA,EACF;AAAA,EAEA,qBAAqB,EAAA,EAA0B;AAC7C,IAAA,OAAO,EAAA,CAAG,aAAA,CAAc,kBAAkB,CAAA,KAAM,IAAA;AAAA,EAClD;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","import { Controller } from \"@hotwired/stimulus\";\nimport { LayoutObserver } from \"../utils/layout_observer\";\nimport { logicalScrollMetrics } from \"../utils/logical_scroll\";\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/**\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 /** 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 #addedTabindex = false;\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 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.#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.#measureOverflow(vp);\n\n this.element.setAttribute(\"data-overflow\", overflowing ? \"true\" : \"false\");\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 #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 if (!vp.hasAttribute(\"tabindex\")) {\n vp.setAttribute(\"tabindex\", \"0\");\n this.#addedTabindex = true;\n }\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 if (this.#addedTabindex) {\n vp.removeAttribute(\"tabindex\");\n this.#addedTabindex = false;\n }\n if (this.#addedRole) {\n vp.removeAttribute(\"role\");\n this.#addedRole = false;\n }\n }\n\n #hasFocusableContent(vp: HTMLElement): boolean {\n return vp.querySelector(FOCUSABLE_SELECTOR) !== null;\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/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,GAAqB,KAAA;AAAA;AAAA,EAGZ,wBAAwB,MAAY;AAC3C,IAAA,IAAA,CAAK,SAAA,EAAU;AAAA,EACj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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"]}
|
|
@@ -6,7 +6,7 @@ var ScrollRestoreController = class extends Controller {
|
|
|
6
6
|
key: { type: String, default: "" },
|
|
7
7
|
axis: { type: String, default: "vertical" }
|
|
8
8
|
};
|
|
9
|
-
/** Pending rAF id
|
|
9
|
+
/** Pending rAF id that coalesces scroll bursts into one save. */
|
|
10
10
|
#rafId = null;
|
|
11
11
|
/** Resolved storage key; empty disables persistence (no key and no id). */
|
|
12
12
|
#storageKey = "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/controllers/scroll_restore_controller.ts"],"names":[],"mappings":";;;AAyCO,IAAM,uBAAA,GAAN,cAAsC,UAAA,CAAwB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A,IAAA,IAAI,IAAA,CAAK,iBAAA,IAAqB,OAAO,IAAA,CAAK,SAAS,QAAA,EAAU;AAC3D,MAAA,IAAA,CAAK,OAAA,CAAQ,aAAa,IAAA,CAAK,IAAA;AAC/B,MAAA,IAAA,CAAK,YAAY,IAAA,CAAK,IAAA;AAAA,IACxB;AAAA,EACF;AAAA;AAAA,EAGA,WAAA,GAAsB;AACpB,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,QAAA,IAAY,IAAA,CAAK,OAAA,CAAQ,EAAA;AAC3C,IAAA,OAAO,IAAA,GAAO,CAAA,uBAAA,EAA0B,IAAI,CAAA,CAAA,GAAK,EAAA;AAAA,EACnD;AAAA,EAEA,IAAI,eAAA,GAA2B;AAC7B,IAAA,OAAO,KAAK,SAAA,KAAc,YAAA;AAAA,EAC5B;AAAA,EAEA,IAAI,iBAAA,GAA6B;AAC/B,IAAA,OAAO,IAAA,CAAK,SAAA,KAAc,YAAA,IAAgB,IAAA,CAAK,SAAA,KAAc,MAAA;AAAA,EAC/D;AACF","file":"scroll_restore_controller.js","sourcesContent":["import { Controller } from \"@hotwired/stimulus\";\n\n/** Persisted scroll position; fields are present only for the saved axis. */\ninterface StoredScroll {\n top?: number;\n left?: number;\n}\n\n/**\n * Headless **Scroll Restore** behavior: persists and restores the scroll\n * position of an inner scrolling region across Turbo Drive navigations (and full\n * reloads within the same tab session). No APG widget — a pure state-preservation\n * utility, like {@link import(\"./scroll_visibility_controller\").ScrollVisibilityController}\n * and the Sticky State Observer.\n *\n * Markup contract (identifier: `stimeo--scroll-restore`):\n * <div data-controller=\"stimeo--scroll-restore\"\n * data-stimeo--scroll-restore-key-value=\"sidebar\"\n * style=\"overflow: auto\">\n * …long content…\n * </div>\n *\n * Turbo swaps the whole `<body>` on navigation, so an inner scroll container is\n * rebuilt with `scrollTop` reset to 0. Rather than have every app hand-write a\n * controller for this (which contradicts a \"ship the behavior\" library), this\n * persists the offset under a stable key in `sessionStorage` and restores it on\n * `connect()`.\n *\n * @remarks\n * Behavior only — it sets no ARIA/`data-*`/CSS and never moves focus (restore is\n * a plain `scrollTop`/`scrollLeft` assignment). The `scroll` listener is internal\n * and `passive` (no consumer `data-action` needed): each event records the live\n * offset synchronously, and a `requestAnimationFrame` coalesces the writes to\n * `sessionStorage`. On `disconnect()` (Turbo navigation included) it flushes the\n * **last captured** offset rather than re-reading the element — by the time Turbo\n * fires `disconnect` it has already detached the node, whose `scrollTop` then\n * reads `0`, so a fresh read would clobber the saved position with `0`. Keying by\n * `key` (falling back to the element `id`) in `sessionStorage` makes it\n * multi-instance safe and survives full reloads — unlike a module-scope variable,\n * which only survives Turbo Drive and assumes a single instance.\n */\nexport class ScrollRestoreController extends Controller<HTMLElement> {\n static override values = {\n key: { type: String, default: \"\" },\n axis: { type: String, default: \"vertical\" },\n };\n\n declare keyValue: string;\n declare axisValue: string;\n\n /** Pending rAF id
|
|
1
|
+
{"version":3,"sources":["../../src/controllers/scroll_restore_controller.ts"],"names":[],"mappings":";;;AAyCO,IAAM,uBAAA,GAAN,cAAsC,UAAA,CAAwB;AAAA,EACnE,OAAgB,MAAA,GAAS;AAAA,IACvB,GAAA,EAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,EAAA,EAAG;AAAA,IACjC,IAAA,EAAM,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,UAAA;AAAW,GAC5C;AAAA;AAAA,EAMA,MAAA,GAAwB,IAAA;AAAA;AAAA,EAExB,WAAA,GAAc,EAAA;AAAA;AAAA,EAEd,QAAA,GAAW,CAAA;AAAA,EACX,SAAA,GAAY,CAAA;AAAA,EAEH,YAAY,MAAY;AAG/B,IAAA,IAAA,CAAK,QAAA,EAAS;AACd,IAAA,IAAI,IAAA,CAAK,WAAW,IAAA,EAAM;AAC1B,IAAA,IAAA,CAAK,MAAA,GAAS,sBAAsB,MAAM;AACxC,MAAA,IAAA,CAAK,MAAA,GAAS,IAAA;AACd,MAAA,IAAA,CAAK,QAAA,EAAS;AAAA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,CAAK,SAAA,KAAc,YAAA,IAAgB,IAAA,CAAK,SAAA,KAAc,MAAA;AAAA,EAC/D;AACF","file":"scroll_restore_controller.js","sourcesContent":["import { Controller } from \"@hotwired/stimulus\";\n\n/** Persisted scroll position; fields are present only for the saved axis. */\ninterface StoredScroll {\n top?: number;\n left?: number;\n}\n\n/**\n * Headless **Scroll Restore** behavior: persists and restores the scroll\n * position of an inner scrolling region across Turbo Drive navigations (and full\n * reloads within the same tab session). No APG widget — a pure state-preservation\n * utility, like {@link import(\"./scroll_visibility_controller\").ScrollVisibilityController}\n * and the Sticky State Observer.\n *\n * Markup contract (identifier: `stimeo--scroll-restore`):\n * <div data-controller=\"stimeo--scroll-restore\"\n * data-stimeo--scroll-restore-key-value=\"sidebar\"\n * style=\"overflow: auto\">\n * …long content…\n * </div>\n *\n * Turbo swaps the whole `<body>` on navigation, so an inner scroll container is\n * rebuilt with `scrollTop` reset to 0. Rather than have every app hand-write a\n * controller for this (which contradicts a \"ship the behavior\" library), this\n * persists the offset under a stable key in `sessionStorage` and restores it on\n * `connect()`.\n *\n * @remarks\n * Behavior only — it sets no ARIA/`data-*`/CSS and never moves focus (restore is\n * a plain `scrollTop`/`scrollLeft` assignment). The `scroll` listener is internal\n * and `passive` (no consumer `data-action` needed): each event records the live\n * offset synchronously, and a `requestAnimationFrame` coalesces the writes to\n * `sessionStorage`. On `disconnect()` (Turbo navigation included) it flushes the\n * **last captured** offset rather than re-reading the element — by the time Turbo\n * fires `disconnect` it has already detached the node, whose `scrollTop` then\n * reads `0`, so a fresh read would clobber the saved position with `0`. Keying by\n * `key` (falling back to the element `id`) in `sessionStorage` makes it\n * multi-instance safe and survives full reloads — unlike a module-scope variable,\n * which only survives Turbo Drive and assumes a single instance.\n */\nexport class ScrollRestoreController extends Controller<HTMLElement> {\n static override values = {\n key: { type: String, default: \"\" },\n axis: { type: String, default: \"vertical\" },\n };\n\n declare keyValue: string;\n declare axisValue: string;\n\n /** Pending rAF id that coalesces scroll bursts into one save. */\n #rafId: number | null = null;\n /** Resolved storage key; empty disables persistence (no key and no id). */\n #storageKey = \"\";\n /** Last offset captured while the element was live; persisted as-is on teardown. */\n #lastTop = 0;\n #lastLeft = 0;\n\n readonly #onScroll = (): void => {\n // Capture synchronously while the element is still connected and measurable;\n // the rAF only debounces the sessionStorage write, never the read.\n this.#capture();\n if (this.#rafId !== null) return;\n this.#rafId = requestAnimationFrame(() => {\n this.#rafId = null;\n this.#persist();\n });\n };\n\n override connect(): void {\n this.#storageKey = this.#resolveKey();\n if (!this.#storageKey) return; // No stable key → do nothing (avoid mixing pages).\n this.#restore();\n this.element.addEventListener(\"scroll\", this.#onScroll, { passive: true });\n }\n\n override disconnect(): void {\n if (!this.#storageKey) return;\n this.element.removeEventListener(\"scroll\", this.#onScroll);\n if (this.#rafId !== null) {\n cancelAnimationFrame(this.#rafId);\n this.#rafId = null;\n }\n // Flush the last captured offset (a throttled burst may have left the final\n // frame unsaved). We do NOT re-read the element here: Turbo detaches the node\n // before disconnect, so its scrollTop is 0 and would overwrite the real value.\n this.#persist();\n }\n\n /** Records the live scroll offset for the configured axis. */\n #capture(): void {\n if (this.#tracksVertical) this.#lastTop = this.element.scrollTop;\n if (this.#tracksHorizontal) this.#lastLeft = this.element.scrollLeft;\n }\n\n /** Persists the last captured scroll offset for the configured axis. */\n #persist(): void {\n const data: StoredScroll = {};\n if (this.#tracksVertical) data.top = this.#lastTop;\n if (this.#tracksHorizontal) data.left = this.#lastLeft;\n try {\n sessionStorage.setItem(this.#storageKey, JSON.stringify(data));\n } catch {\n // sessionStorage can throw (private mode / quota); persistence is best-effort.\n }\n }\n\n /** Applies the persisted scroll offset, if any, without moving focus. */\n #restore(): void {\n let raw: string | null = null;\n try {\n raw = sessionStorage.getItem(this.#storageKey);\n } catch {\n return;\n }\n if (raw === null) return;\n let data: StoredScroll;\n try {\n data = JSON.parse(raw) as StoredScroll;\n } catch {\n return;\n }\n // Seed the capture cache from the restored value so an immediate teardown\n // (before any scroll) re-persists the restored position, not 0. Guard by the\n // configured axis so a stale field from a different axis is never applied.\n if (this.#tracksVertical && typeof data.top === \"number\") {\n this.element.scrollTop = data.top;\n this.#lastTop = data.top;\n }\n if (this.#tracksHorizontal && typeof data.left === \"number\") {\n this.element.scrollLeft = data.left;\n this.#lastLeft = data.left;\n }\n }\n\n /** The `sessionStorage` key: explicit `key`, else the element `id`, else none. */\n #resolveKey(): string {\n const base = this.keyValue || this.element.id;\n return base ? `stimeo--scroll-restore:${base}` : \"\";\n }\n\n get #tracksVertical(): boolean {\n return this.axisValue !== \"horizontal\";\n }\n\n get #tracksHorizontal(): boolean {\n return this.axisValue === \"horizontal\" || this.axisValue === \"both\";\n }\n}\n"]}
|
|
@@ -30,9 +30,12 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
30
30
|
* Behavior only — the look and any transition are the consumer's CSS. The scroll
|
|
31
31
|
* listener is `passive`, coalesced through `requestAnimationFrame`, and removed on
|
|
32
32
|
* `disconnect()` (Turbo navigation included). `toTop` honors
|
|
33
|
-
* `prefers-reduced-motion` by
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* `prefers-reduced-motion` by forcing an instant jump independently of the
|
|
34
|
+
* consumer's CSS `scroll-behavior`, and can move focus to a `focusSelector`
|
|
35
|
+
* target (given `tabindex="-1"` if needed) to keep keyboard users oriented
|
|
36
|
+
* after the scroll. A live disconnect removes only a `tabindex="-1"` this
|
|
37
|
+
* controller instance added; authored tabindex values remain. This teardown does
|
|
38
|
+
* not claim to rewrite a Turbo cache snapshot that was cloned before disconnect.
|
|
36
39
|
*/
|
|
37
40
|
declare class ScrollVisibilityController extends Controller<HTMLElement> {
|
|
38
41
|
#private;
|
|
@@ -7,6 +7,33 @@ function prefersReducedMotion() {
|
|
|
7
7
|
return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
// src/utils/tabindex_loan.ts
|
|
11
|
+
var TabindexLoan = class {
|
|
12
|
+
#value;
|
|
13
|
+
#lent = /* @__PURE__ */ new Set();
|
|
14
|
+
/**
|
|
15
|
+
* @param value - the `tabindex` to lend. `"-1"` (the default) is
|
|
16
|
+
* programmatically focusable but not a Tab stop; `"0"` is a real Tab stop,
|
|
17
|
+
* which a scroll region with no focusable content of its own needs.
|
|
18
|
+
*/
|
|
19
|
+
constructor(value = "-1") {
|
|
20
|
+
this.#value = value;
|
|
21
|
+
}
|
|
22
|
+
/** Lends `element` the value; no-ops when it already carries a `tabindex`. */
|
|
23
|
+
lend(element) {
|
|
24
|
+
if (element.hasAttribute("tabindex")) return;
|
|
25
|
+
element.setAttribute("tabindex", this.#value);
|
|
26
|
+
this.#lent.add(element);
|
|
27
|
+
}
|
|
28
|
+
/** Takes back every loan whose value is still the one that was lent. */
|
|
29
|
+
returnAll() {
|
|
30
|
+
for (const element of this.#lent) {
|
|
31
|
+
if (element.getAttribute("tabindex") === this.#value) element.removeAttribute("tabindex");
|
|
32
|
+
}
|
|
33
|
+
this.#lent.clear();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
10
37
|
// src/controllers/scroll_visibility_controller.ts
|
|
11
38
|
var ScrollVisibilityController = class extends Controller {
|
|
12
39
|
static targets = ["element"];
|
|
@@ -18,7 +45,7 @@ var ScrollVisibilityController = class extends Controller {
|
|
|
18
45
|
};
|
|
19
46
|
static actions = ["toTop"];
|
|
20
47
|
static events = ["change"];
|
|
21
|
-
/** Pending rAF id
|
|
48
|
+
/** Pending rAF id that coalesces scroll bursts into one measurement. */
|
|
22
49
|
#rafId = null;
|
|
23
50
|
/** Previous scroll position, for `direction` mode delta detection. */
|
|
24
51
|
#lastScrollY = 0;
|
|
@@ -29,6 +56,8 @@ var ScrollVisibilityController = class extends Controller {
|
|
|
29
56
|
* the window. Captured on connect so teardown detaches from the same source.
|
|
30
57
|
*/
|
|
31
58
|
#scrollSource = window;
|
|
59
|
+
/** Focus targets this instance lent a `tabindex` to. */
|
|
60
|
+
#tabindex = new TabindexLoan();
|
|
32
61
|
#onScroll = () => {
|
|
33
62
|
if (this.#rafId !== null) return;
|
|
34
63
|
this.#rafId = requestAnimationFrame(() => {
|
|
@@ -48,16 +77,17 @@ var ScrollVisibilityController = class extends Controller {
|
|
|
48
77
|
cancelAnimationFrame(this.#rafId);
|
|
49
78
|
this.#rafId = null;
|
|
50
79
|
}
|
|
80
|
+
this.#tabindex.returnAll();
|
|
51
81
|
this.#visible = null;
|
|
52
82
|
}
|
|
53
83
|
/** Scrolls the source to the top and, optionally, moves focus to a safe target. */
|
|
54
84
|
toTop() {
|
|
55
|
-
const behavior = prefersReducedMotion() ? "
|
|
85
|
+
const behavior = prefersReducedMotion() ? "instant" : "smooth";
|
|
56
86
|
this.#scrollSource.scrollTo({ top: 0, behavior });
|
|
57
87
|
if (this.focusSelectorValue) {
|
|
58
88
|
const target = document.querySelector(this.focusSelectorValue);
|
|
59
89
|
if (target) {
|
|
60
|
-
|
|
90
|
+
this.#tabindex.lend(target);
|
|
61
91
|
target.focus();
|
|
62
92
|
}
|
|
63
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/reduced_motion.ts","../../src/controllers/scroll_visibility_controller.ts"],"names":[],"mappings":";;;;;AAoBO,SAAS,oBAAA,GAAgC;AAC9C,EAAA,OACE,OAAO,MAAA,CAAO,UAAA,KAAe,cAC7B,MAAA,CAAO,UAAA,CAAW,kCAAkC,CAAA,CAAE,OAAA;AAE1D;;;ACYO,IAAM,0BAAA,GAAN,cAAyC,UAAA,CAAwB;AAAA,EACtE,OAAgB,OAAA,GAAU,CAAC,SAAS,CAAA;AAAA,EACpC,OAAgB,MAAA,GAAS;AAAA,IACvB,MAAA,EAAQ,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,GAAA,EAAI;AAAA,IACrC,IAAA,EAAM,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,QAAA,EAAS;AAAA,IACxC,aAAA,EAAe,E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,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 * Each of those controllers used to duplicate the same guarded `matchMedia`\n * read; this one-liner keeps the media query string and the environment guard\n * single-sourced. The preference is intentionally re-read on every call — the\n * controllers check it at each animation/scroll start (WCAG 2.2 **2.3.3**), so\n * flipping the OS setting takes effect immediately without any listener or\n * cache bookkeeping here.\n */\n\n/**\n * Whether the user currently requests reduced motion.\n *\n * @returns `true` when `(prefers-reduced-motion: reduce)` matches; `false`\n * otherwise, including environments without `window.matchMedia` (treated as\n * \"no preference\").\n */\nexport function prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { prefersReducedMotion } from \"../utils/reduced_motion\";\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 falling back to an instant jump, and can move focus\n * to a `focusSelector` target (given `tabindex=\"-1\"` if needed) to keep keyboard\n * users oriented after the scroll.\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 used to coalesce scroll bursts into one measurement. */\n #rafId: number | null = null;\n /** Previous scroll position, for `direction` mode delta detection. */\n #lastScrollY = 0;\n /** Current visibility, tracked to dispatch `change` only on real transitions. */\n #visible: boolean | null = null;\n /**\n * The observed scroll source: a container element when `root` resolves, else\n * the window. Captured on connect so teardown detaches from the same source.\n */\n #scrollSource: HTMLElement | Window = window;\n\n 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.#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() ? \"auto\" : \"smooth\";\n this.#scrollSource.scrollTo({ top: 0, behavior });\n if (this.focusSelectorValue) {\n const target = document.querySelector<HTMLElement>(this.focusSelectorValue);\n if (target) {\n if (!target.hasAttribute(\"tabindex\")) target.setAttribute(\"tabindex\", \"-1\");\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/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;;;ACqBO,IAAM,eAAN,MAAwD;AAAA,EACpD,MAAA;AAAA,EACA,KAAA,uBAAY,GAAA,EAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO5B,WAAA,CAAY,QAAgB,IAAA,EAAM;AAChC,IAAA,IAAA,CAAK,MAAA,GAAS,KAAA;AAAA,EAChB;AAAA;AAAA,EAGA,KAAK,OAAA,EAAkB;AACrB,IAAA,IAAI,OAAA,CAAQ,YAAA,CAAa,UAAU,CAAA,EAAG;AACtC,IAAA,OAAA,CAAQ,YAAA,CAAa,UAAA,EAAY,IAAA,CAAK,MAAM,CAAA;AAC5C,IAAA,IAAA,CAAK,KAAA,CAAM,IAAI,OAAO,CAAA;AAAA,EACxB;AAAA;AAAA,EAGA,SAAA,GAAkB;AAChB,IAAA,KAAA,MAAW,OAAA,IAAW,KAAK,KAAA,EAAO;AAChC,MAAA,IAAI,OAAA,CAAQ,aAAa,UAAU,CAAA,KAAM,KAAK,MAAA,EAAQ,OAAA,CAAQ,gBAAgB,UAAU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,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 * 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,28 +1,59 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Headless, accessible Scrollspy
|
|
4
|
+
* Headless, accessible **Scrollspy**: keeps a table of contents in sync with the
|
|
5
|
+
* section the reader is currently in, published as `aria-current="location"`.
|
|
6
|
+
* There is no dedicated APG widget; it follows the `aria-current`
|
|
7
|
+
* current-location practice inside a `<nav>` landmark.
|
|
5
8
|
*
|
|
6
9
|
* Markup contract (identifier: `stimeo--scrollspy`):
|
|
7
10
|
* <nav data-controller="stimeo--scrollspy"
|
|
8
11
|
* data-stimeo--scrollspy-offset-value="80"
|
|
12
|
+
* data-stimeo--scrollspy-root-selector-value=".content"
|
|
9
13
|
* aria-label="Table of contents">
|
|
10
|
-
* <a href="#intro" data-stimeo--scrollspy-target="link"
|
|
11
|
-
*
|
|
14
|
+
* <a href="#intro" data-stimeo--scrollspy-target="link"
|
|
15
|
+
* data-action="click->stimeo--scrollspy#scrollTo">Intro</a>
|
|
16
|
+
* <a href="#usage" data-stimeo--scrollspy-target="link"
|
|
17
|
+
* data-action="click->stimeo--scrollspy#scrollTo">Usage</a>
|
|
12
18
|
* </nav>
|
|
13
|
-
* <
|
|
14
|
-
*
|
|
19
|
+
* <div class="content">
|
|
20
|
+
* <section id="intro">…</section>
|
|
21
|
+
* <section id="usage">…</section>
|
|
22
|
+
* </div>
|
|
15
23
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
24
|
+
* The active section is the one whose top edge sits closest to the **trigger
|
|
25
|
+
* line**: `offset` px below the top of the *scroll root* — the `rootSelector`
|
|
26
|
+
* container, or the viewport when that value is empty. It is not the viewport
|
|
27
|
+
* top whenever a nested container is spied on. Intersecting sections win; when
|
|
28
|
+
* none intersects (between two sections, scrolled past the last one) the
|
|
29
|
+
* closest tracked section keeps the highlight, so a table of contents never
|
|
30
|
+
* goes blank.
|
|
31
|
+
*
|
|
32
|
+
* `data-action` on the links is optional and opts into {@link scrollTo}, which
|
|
33
|
+
* scrolls the nested container instead of bouncing the whole window.
|
|
22
34
|
*
|
|
23
35
|
* @remarks
|
|
24
|
-
* Behavior only
|
|
25
|
-
*
|
|
36
|
+
* Behavior only — how a current link looks is the consumer's CSS
|
|
37
|
+
* (`[aria-current="location"] { … }`). `connect()` reads the current location
|
|
38
|
+
* back from the DOM so a Turbo cache restore re-establishes it without a
|
|
39
|
+
* redundant `change`, and `disconnect()` severs every resource acquired here:
|
|
40
|
+
* the observers, the scroll listener, and any pending frame or queued rebuild.
|
|
41
|
+
*
|
|
42
|
+
* **What is followed automatically**, and what is not (the boundary a consumer
|
|
43
|
+
* has to know, because everything outside it needs a re-`connect()`):
|
|
44
|
+
*
|
|
45
|
+
* - `link` targets added or removed — Stimulus's target callbacks.
|
|
46
|
+
* - a `link` target's `href` / `data-href` rewritten in place — a Turbo 8 morph
|
|
47
|
+
* keeps the element *and* its target marker, so no target callback fires;
|
|
48
|
+
* {@link ANCHOR_ATTRIBUTES} is watched for exactly this case.
|
|
49
|
+
* - the reader's scroll position, including inside a stretch where no section
|
|
50
|
+
* crosses an observation threshold.
|
|
51
|
+
*
|
|
52
|
+
* Not followed: a *split* lifecycle in which the nav survives while the scroll
|
|
53
|
+
* root or the sections are replaced underneath it. `rootSelector` is resolved
|
|
54
|
+
* against the whole document and re-resolved once the cached container leaves
|
|
55
|
+
* it, but section elements are looked up only while the observation set is
|
|
56
|
+
* (re)built — swap those alone and nothing tells this controller to look again.
|
|
26
57
|
*/
|
|
27
58
|
declare class ScrollspyController extends Controller<HTMLElement> {
|
|
28
59
|
#private;
|
|
@@ -40,6 +71,10 @@ declare class ScrollspyController extends Controller<HTMLElement> {
|
|
|
40
71
|
type: StringConstructor;
|
|
41
72
|
default: string;
|
|
42
73
|
};
|
|
74
|
+
focusSection: {
|
|
75
|
+
type: BooleanConstructor;
|
|
76
|
+
default: boolean;
|
|
77
|
+
};
|
|
43
78
|
};
|
|
44
79
|
static actions: readonly ["scrollTo"];
|
|
45
80
|
static events: readonly ["change"];
|
|
@@ -47,6 +82,7 @@ declare class ScrollspyController extends Controller<HTMLElement> {
|
|
|
47
82
|
offsetValue: number;
|
|
48
83
|
rootMarginValue: string;
|
|
49
84
|
rootSelectorValue: string;
|
|
85
|
+
focusSectionValue: boolean;
|
|
50
86
|
connect(): void;
|
|
51
87
|
disconnect(): void;
|
|
52
88
|
/**
|
|
@@ -56,8 +92,21 @@ declare class ScrollspyController extends Controller<HTMLElement> {
|
|
|
56
92
|
rootMarginValueChanged(): void;
|
|
57
93
|
rootSelectorValueChanged(): void;
|
|
58
94
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
95
|
+
* Re-syncs the observation set when a Turbo Stream/morph swaps the table of
|
|
96
|
+
* contents. Stimulus fires these before `connect()` for the links already in
|
|
97
|
+
* the markup, hence the guard: the initial observer is built exactly once, by
|
|
98
|
+
* `connect()`.
|
|
99
|
+
*/
|
|
100
|
+
linkTargetConnected(): void;
|
|
101
|
+
linkTargetDisconnected(): void;
|
|
102
|
+
/**
|
|
103
|
+
* Scrolls to the section the clicked link anchors, honoring `offset` and any
|
|
104
|
+
* nested scroll container (a plain fragment jump would scroll the window).
|
|
105
|
+
*
|
|
106
|
+
* Honors `prefers-reduced-motion` (WCAG 2.2 **2.3.3**) by forcing an instant
|
|
107
|
+
* jump independently of the consumer's CSS `scroll-behavior`. With
|
|
108
|
+
* `focusSection` enabled it also moves the sequential focus starting point
|
|
109
|
+
* into the destination; the URL fragment is deliberately not touched.
|
|
61
110
|
*/
|
|
62
111
|
scrollTo(event: Event): void;
|
|
63
112
|
}
|