stimeo-ui 0.4.0 → 0.5.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 +68 -0
- package/dist/controllers/announcer_controller.js.map +1 -1
- package/dist/controllers/aspect_ratio_controller.d.ts +2 -2
- package/dist/controllers/aspect_ratio_controller.js +1 -1
- package/dist/controllers/aspect_ratio_controller.js.map +1 -1
- package/dist/controllers/breadcrumb_controller.js +5 -1
- package/dist/controllers/breadcrumb_controller.js.map +1 -1
- package/dist/controllers/carousel_controller.js +5 -1
- package/dist/controllers/carousel_controller.js.map +1 -1
- package/dist/controllers/clipboard_controller.js +8 -3
- package/dist/controllers/clipboard_controller.js.map +1 -1
- package/dist/controllers/collapsible_controller.d.ts +1 -1
- package/dist/controllers/collapsible_controller.js +4 -1
- package/dist/controllers/collapsible_controller.js.map +1 -1
- package/dist/controllers/color_picker_controller.d.ts +2 -2
- package/dist/controllers/color_picker_controller.js +6 -2
- package/dist/controllers/color_picker_controller.js.map +1 -1
- package/dist/controllers/combobox_controller.js.map +1 -1
- package/dist/controllers/command_palette_controller.js.map +1 -1
- package/dist/controllers/context_menu_controller.d.ts +1 -1
- package/dist/controllers/context_menu_controller.js +2 -2
- package/dist/controllers/context_menu_controller.js.map +1 -1
- package/dist/controllers/countdown_controller.d.ts +5 -3
- package/dist/controllers/countdown_controller.js +5 -1
- package/dist/controllers/countdown_controller.js.map +1 -1
- package/dist/controllers/date_range_picker_controller.js +5 -1
- package/dist/controllers/date_range_picker_controller.js.map +1 -1
- package/dist/controllers/direct_upload_controller.d.ts +1 -1
- package/dist/controllers/direct_upload_controller.js +3 -3
- package/dist/controllers/direct_upload_controller.js.map +1 -1
- package/dist/controllers/empty_state_controller.d.ts +27 -7
- package/dist/controllers/empty_state_controller.js +107 -16
- package/dist/controllers/empty_state_controller.js.map +1 -1
- package/dist/controllers/flash_controller.d.ts +25 -5
- package/dist/controllers/flash_controller.js +161 -21
- package/dist/controllers/flash_controller.js.map +1 -1
- package/dist/controllers/form_validation_controller.js +8 -2
- package/dist/controllers/form_validation_controller.js.map +1 -1
- package/dist/controllers/frame_loading_controller.d.ts +19 -2
- package/dist/controllers/frame_loading_controller.js +94 -22
- package/dist/controllers/frame_loading_controller.js.map +1 -1
- package/dist/controllers/highlight_controller.d.ts +8 -4
- package/dist/controllers/highlight_controller.js +38 -1
- package/dist/controllers/highlight_controller.js.map +1 -1
- package/dist/controllers/idle_controller.d.ts +2 -1
- package/dist/controllers/idle_controller.js +13 -2
- package/dist/controllers/idle_controller.js.map +1 -1
- package/dist/controllers/listbox_controller.js.map +1 -1
- package/dist/controllers/local_time_controller.js +2 -0
- package/dist/controllers/local_time_controller.js.map +1 -1
- package/dist/controllers/masonry_controller.d.ts +1 -1
- package/dist/controllers/masonry_controller.js +1 -1
- package/dist/controllers/masonry_controller.js.map +1 -1
- package/dist/controllers/meter_controller.js +3 -1
- package/dist/controllers/meter_controller.js.map +1 -1
- package/dist/controllers/multi_select_controller.js.map +1 -1
- package/dist/controllers/network_status_controller.d.ts +15 -13
- package/dist/controllers/network_status_controller.js +1 -3
- package/dist/controllers/network_status_controller.js.map +1 -1
- package/dist/controllers/number_input_controller.d.ts +8 -0
- package/dist/controllers/number_input_controller.js +191 -24
- package/dist/controllers/number_input_controller.js.map +1 -1
- package/dist/controllers/overflow_menu_controller.js +1 -1
- package/dist/controllers/overflow_menu_controller.js.map +1 -1
- package/dist/controllers/pagination_controller.js +5 -1
- package/dist/controllers/pagination_controller.js.map +1 -1
- package/dist/controllers/password_strength_controller.d.ts +1 -1
- package/dist/controllers/password_strength_controller.js +1 -1
- package/dist/controllers/password_strength_controller.js.map +1 -1
- package/dist/controllers/pointer_drag_controller.js +10 -0
- package/dist/controllers/pointer_drag_controller.js.map +1 -1
- package/dist/controllers/portal_controller.js +10 -0
- package/dist/controllers/portal_controller.js.map +1 -1
- package/dist/controllers/progress_controller.d.ts +1 -1
- package/dist/controllers/progress_controller.js +7 -3
- package/dist/controllers/progress_controller.js.map +1 -1
- package/dist/controllers/range_slider_controller.d.ts +23 -0
- package/dist/controllers/range_slider_controller.js +385 -94
- package/dist/controllers/range_slider_controller.js.map +1 -1
- package/dist/controllers/rating_controller.js +2 -0
- package/dist/controllers/rating_controller.js.map +1 -1
- package/dist/controllers/relative_time_controller.js +2 -0
- package/dist/controllers/relative_time_controller.js.map +1 -1
- package/dist/controllers/scroll_area_controller.d.ts +1 -1
- package/dist/controllers/scroll_area_controller.js +1 -1
- package/dist/controllers/scroll_area_controller.js.map +1 -1
- package/dist/controllers/separator_controller.js +13 -17
- package/dist/controllers/separator_controller.js.map +1 -1
- package/dist/controllers/skeleton_controller.d.ts +2 -2
- package/dist/controllers/skeleton_controller.js +71 -3
- package/dist/controllers/skeleton_controller.js.map +1 -1
- package/dist/controllers/slider_controller.d.ts +17 -1
- package/dist/controllers/slider_controller.js +325 -48
- package/dist/controllers/slider_controller.js.map +1 -1
- package/dist/controllers/spinner_controller.d.ts +15 -10
- package/dist/controllers/spinner_controller.js +18 -3
- package/dist/controllers/spinner_controller.js.map +1 -1
- package/dist/controllers/step_indicator_controller.d.ts +1 -1
- package/dist/controllers/step_indicator_controller.js +3 -1
- package/dist/controllers/step_indicator_controller.js.map +1 -1
- package/dist/controllers/stepper_controller.js +2 -0
- package/dist/controllers/stepper_controller.js.map +1 -1
- package/dist/controllers/switch_controller.d.ts +12 -8
- package/dist/controllers/switch_controller.js +162 -18
- package/dist/controllers/switch_controller.js.map +1 -1
- package/dist/controllers/textarea_autosize_controller.js +1 -1
- package/dist/controllers/textarea_autosize_controller.js.map +1 -1
- package/dist/controllers/time_picker_controller.d.ts +3 -0
- package/dist/controllers/time_picker_controller.js +6 -3
- package/dist/controllers/time_picker_controller.js.map +1 -1
- package/dist/controllers/tree_view_controller.d.ts +1 -2
- package/dist/controllers/tree_view_controller.js +19 -1
- package/dist/controllers/tree_view_controller.js.map +1 -1
- package/dist/index.js +1214 -307
- package/dist/index.js.map +1 -1
- package/dist/inspector/cli.d.ts +76 -1
- package/dist/inspector/cli.js +152 -0
- package/dist/inspector/cli.js.map +1 -1
- package/dist/inspector/cli_bin.js +212 -2
- package/dist/inspector/cli_bin.js.map +1 -1
- package/dist/inspector/examples.json +17 -17
- package/dist/inspector/manifest.json +408 -26
- package/package.json +3 -3
|
@@ -12,6 +12,16 @@ function isReservedArrowChord(event, allow = []) {
|
|
|
12
12
|
var DetachGate = class _DetachGate {
|
|
13
13
|
/** Set while a probe is queued, waiting for a reconnect to cancel it. */
|
|
14
14
|
#pending = false;
|
|
15
|
+
/**
|
|
16
|
+
* True while a probe is queued — the last disconnect was ambiguous and no
|
|
17
|
+
* reconnect has cancelled it yet. Read it from `connect()` to tell the
|
|
18
|
+
* reconnect half of an in-page move from a first connect: a controller whose
|
|
19
|
+
* initialisation restarts a measurement (a min-duration floor, an elapsed
|
|
20
|
+
* counter) must skip it for the move, where nothing actually restarted.
|
|
21
|
+
*/
|
|
22
|
+
get pending() {
|
|
23
|
+
return this.#pending;
|
|
24
|
+
}
|
|
15
25
|
/**
|
|
16
26
|
* True when the disconnect is definitely a real detach — the element left
|
|
17
27
|
* the document, or `data-controller` no longer lists the identifier. False
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/arrow_step.ts","../../src/utils/detach_gate.ts","../../src/controllers/pointer_drag_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,M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AAU,CAAA;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AACF","file":"pointer_drag_controller.js","sourcesContent":["import { isRtl } from \"./logical_scroll\";\n\n/**\n * Turns an arrow key into a **logical** step: `+1` for \"next\", `-1` for\n * \"previous\", `0` when the key names neither.\n *\n * APG defines the horizontal pair as *next / previous* and says a vertical\n * arrangement swaps in Down/Up for the same meaning — so the pair is one axis's\n * spelling of an order, and the order reverses with the writing direction. Only\n * the horizontal pair reverses. Down/Up name an axis the writing direction does\n * not mirror, and returning them unchanged is the point: many controllers fold\n * both pairs into one branch, where swapping the branches under RTL would flip\n * the vertical axis too — a bug that reads as \"the arrows work\" until someone\n * presses Down.\n *\n * **Direction is read from the element the caller passes, which should be the\n * container that lays the items out** — not the focused child. A child may carry\n * its own `dir` (an LTR input inside an RTL form is ordinary authoring), and\n * probing per handler makes two handlers disagree at the boundary between them.\n *\n * This decides direction only. Whether the axis is even active (an\n * `orientation=\"horizontal\"` widget ignoring Down/Up), how far the step lands,\n * and what wrapping does all stay with the caller.\n *\n * **It encodes the list-order convention: `ArrowDown` is *next*.** Widgets that\n * pair the arrows by *value* instead — `ArrowUp` meaning \"more\", as a rating or a\n * slider does — must not use this, or their vertical axis inverts. Reverse the\n * horizontal pair on its own there.\n *\n * @example\n * ```ts\n * const step = logicalArrowStep(event.key, this.element);\n * if (step === 0) return;\n * this.#roving.setActive(rovingMove(current, length, step, \"wrap\"), { focus: true });\n * ```\n */\nexport function logicalArrowStep(key: string, element: Element): 1 | -1 | 0 {\n if (key === \"ArrowDown\") return 1;\n if (key === \"ArrowUp\") return -1;\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return 0;\n const forward = isRtl(element) ? \"ArrowLeft\" : \"ArrowRight\";\n return key === forward ? 1 : -1;\n}\n\n/**\n * Rewrites `key` so an existing LTR-shaped branch keeps working under RTL:\n * `ArrowRight` and `ArrowLeft` trade places, everything else passes through.\n *\n * The alternative — negating a delta — silently breaks handlers whose two\n * horizontal branches are **not mirror images**. A grid that clamps one edge but\n * not the other, or a segmented field guarding `index > 0` on one side and\n * `index < length - 1` on the other, ends up applying the wrong guard to the\n * wrong direction. Swapping the key leaves each branch, guards and all, exactly\n * where its author put it.\n *\n * Same rule as {@link logicalArrowStep} about which element to read: pass the\n * container that lays the items out, not the focused child.\n *\n * @example\n * ```ts\n * switch (logicalArrowKey(event.key, this.element)) {\n * case \"ArrowLeft\": // \"previous\" — whatever direction that is on screen\n * ```\n */\nexport function logicalArrowKey(key: string, element: Element): string {\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return key;\n if (!isRtl(element)) return key;\n return key === \"ArrowRight\" ? \"ArrowLeft\" : \"ArrowRight\";\n}\n\n/** Modifiers a widget may claim on an arrow key, named for the `allow` list. */\nexport type ArrowModifier = \"alt\" | \"ctrl\" | \"meta\" | \"shift\";\n\n/**\n * True when an arrow key arrived carrying a modifier the widget must leave to\n * the browser: return without calling `preventDefault()` and without moving any\n * state.\n *\n * A bare arrow belongs to the widget; a chorded one usually does not.\n * `Alt`/`Meta` plus a horizontal arrow is history back/forward on every desktop\n * browser, and a widget that swallows it makes the shortcut work or not\n * depending on where focus happens to sit — a coin-flip the user cannot see.\n *\n * `allow` is for the combinations APG assigns to a pattern **and the widget\n * actually implements** — today only Combobox's optional `Alt+Down`/`Alt+Up`.\n * Listing one the widget does not implement defeats the point: the chord then\n * runs the plain-arrow branch, which is exactly what this guard exists to stop.\n * Non-arrow keys return `false`, so chorded letters and\n * `Control+Home`/`Control+End` are untouched.\n *\n * @example\n * ```ts\n * if (isReservedArrowChord(event)) return;\n * ```\n */\nexport function isReservedArrowChord(\n event: KeyboardEvent,\n allow: readonly ArrowModifier[] = [],\n): boolean {\n if (!event.key.startsWith(\"Arrow\")) return false;\n return (\n (event.altKey && !allow.includes(\"alt\")) ||\n (event.ctrlKey && !allow.includes(\"ctrl\")) ||\n (event.metaKey && !allow.includes(\"meta\")) ||\n (event.shiftKey && !allow.includes(\"shift\"))\n );\n}\n","/**\n * Shared \"in-page move vs real detach\" discriminator for `disconnect()`.\n *\n * A mid-session `disconnect()` whose element is still in the document is\n * ambiguous. It can be:\n *\n * - an **in-page move** — a consumer (sortable, a teleport) re-inserted the\n * element; Stimulus reconnects the SAME instance in the same mutation batch\n * and the controller's runtime state must survive;\n * - a **detach that keeps the element** — `data-controller` no longer lists the\n * identifier (a Turbo 8 morph), or the element moved outside the observed\n * root (a scoped `Application.start(root)`, a shadow root); no reconnect will\n * ever come and the controller must tear down or it leaks its sessions,\n * document listeners, and moved nodes.\n *\n * Neither available signal decides this alone. A synchronous `data-controller`\n * token check catches the morph case but misses an observed-root exit (the\n * token stays, the reconnect never comes). Deferring teardown one microtask and\n * letting `connect()` cancel it catches the root exit, but leans on Stimulus\n * reconnecting moved elements within the same mutation batch — internal\n * behavior, not a public contract. {@link DetachGate} composes both: the token\n * check is the synchronous fast path (no probe, no reliance on batching), the\n * microtask probe is the fallback for the genuinely ambiguous remainder.\n *\n * Policy stays with the consumer (the `SafeTimeout` / `FocusTrap` lineage —\n * this util owns the discrimination only):\n *\n * - **Probe** ({@link disconnected}) when the teardown must eventually happen —\n * live drag sessions, document listeners, teleported *content*. Call\n * {@link cancel} from `connect()` (a reconnect means in-page move) and from\n * the head of any direct teardown path (see below).\n * - **Keep** (bare {@link DetachGate.isDetached}) when undoing the ambiguous\n * case would fight the controller's own effect: a controller that moves its\n * OWN element (portal's no-`content` form) exits a scoped observed root as\n * its normal job — a probe-driven teardown would restore the element into\n * the root, reconnect, re-teleport, and disconnect again, forever. Such\n * controllers keep their state on an ambiguous disconnect and tear down only\n * on {@link DetachGate.isDetached}.\n *\n * Event convention for probe consumers: teardown into a dead (detached) tree is\n * silent — consumers restore from their own `connect()`; a detach that keeps the\n * tree alive must end an in-flight session with a `cancel` event, or composing\n * consumers strand their session bookkeeping.\n */\n\n/** The slice of a Stimulus controller the gate inspects. */\nexport interface DetachGateHost {\n readonly element: Element;\n readonly identifier: string;\n}\n\n/**\n * Per-controller-instance gate deciding whether a `disconnect()` is a real\n * detach. Hold one per controller (`#gate = new DetachGate()`) — Stimulus\n * reuses the instance across reconnects, so the pending probe state carries\n * over exactly as the protocol needs.\n *\n * @example\n * ```ts\n * #gate = new DetachGate();\n *\n * connect(): void {\n * this.#gate.cancel(); // a reconnect: the element moved in-page\n * // …\n * }\n *\n * disconnect(): void {\n * this.#gate.disconnected(this, () => this.#teardown());\n * }\n *\n * #teardown(): void {\n * this.#gate.cancel(); // disarm a still-queued probe (double-run guard)\n * // …\n * }\n * ```\n */\nexport class DetachGate {\n /** Set while a probe is queued, waiting for a reconnect to cancel it. */\n #pending = false;\n\n /**\n * True when the disconnect is definitely a real detach — the element left\n * the document, or `data-controller` no longer lists the identifier. False\n * means ambiguous (in-page move or observed-root exit), NOT \"alive\".\n */\n static isDetached(host: DetachGateHost): boolean {\n if (!host.element.isConnected) return true;\n const tokens = (host.element.getAttribute(\"data-controller\") ?? \"\").split(/\\s+/);\n return !tokens.includes(host.identifier);\n }\n\n /**\n * Call from `disconnect()`: runs `teardown` synchronously on a definite\n * detach (fast path), otherwise defers it one microtask — a reconnect\n * ({@link cancel} from `connect()`) keeps the state, no reconnect runs it.\n * One microtask is the whole probe window: Stimulus reconnects a moved\n * element within the same mutation batch, before the checkpoint drains.\n */\n disconnected(host: DetachGateHost, teardown: () => void): void {\n if (DetachGate.isDetached(host)) {\n // Also disarms a probe a previous ambiguous disconnect left queued\n // (defer, element removed, disconnect again) — exactly one teardown.\n this.#pending = false;\n teardown();\n return;\n }\n this.#pending = true;\n queueMicrotask(() => {\n if (!this.#pending) return;\n this.#pending = false;\n teardown();\n });\n }\n\n /**\n * Disarms a pending probe. Call from `connect()` (the reconnect that proves\n * an in-page move) and from the head of any teardown path not routed through\n * {@link disconnected} (disabled-toggle, Escape), so an orphaned probe can\n * never run the teardown a second time.\n */\n cancel(): void {\n this.#pending = false;\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\nimport { DetachGate } from \"../utils/detach_gate\";\n\n/** How a drag session was initiated; surfaced in every event detail. */\ntype DragPointerType = \"mouse\" | \"touch\" | \"pen\" | \"keyboard\";\n\n/** A pointer drag in flight (from `pointerdown` until up/cancel). */\ninterface PointerSession {\n pointerId: number;\n handle: HTMLElement;\n originX: number;\n originY: number;\n /** True once the movement passed `threshold` and `start` was dispatched. */\n started: boolean;\n /** Last axis-filtered deltas, reported again by `end`. */\n dx: number;\n dy: number;\n pointerType: DragPointerType;\n}\n\n/** A keyboard \"grabbed\" session (Space/Enter on the handle until drop/cancel). */\ninterface KeyboardSession {\n handle: HTMLElement;\n /** Cumulative synthetic deltas accumulated by the arrow keys. */\n dx: number;\n dy: number;\n}\n\n/**\n * Headless **pointer-drag primitive**: a normalized pointer/touch/mouse drag\n * lifecycle with a built-in keyboard alternative. It deliberately does NOT decide\n * what a drag *means* (reorder, dismiss, resize…) — it only emits a clean,\n * accessibility-friendly drag signal that higher-level behaviors (sortable,\n * swipe-actions, bottom-sheet, split-pane…) compose from. No dedicated APG\n * pattern exists for drag-and-drop; the keyboard model below is the accepted\n * alternative-input technique (WCAG 2.1.1 / 2.5.7 Dragging Movements). Core\n * (zero dependencies).\n *\n * Markup contract (identifier: `stimeo--pointer-drag`):\n * <li data-controller=\"stimeo--pointer-drag\"\n * data-stimeo--pointer-drag-axis-value=\"y\">\n * <button data-stimeo--pointer-drag-target=\"handle\" aria-label=\"Reorder\">⠿</button>\n * </li>\n *\n * The `handle` target is optional — without one, the controller element itself\n * is the handle. Pointer flow: `pointerdown` on a handle arms the drag; once the\n * axis-filtered movement exceeds `threshold`, `start` fires, every subsequent\n * movement fires `move` (deltas cumulative from the origin), and release fires\n * `end` (`pointercancel` → `cancel`). Keyboard flow: Space/Enter on the handle\n * grabs (`start`, `data-grabbed`), the arrow keys emit synthetic `move` events of\n * `keyboardStep` px each, Space/Enter drops (`end`) and Escape cancels — so every\n * consumer gets a keyboard path for free.\n *\n * @remarks\n * Behavior only: consumers own all visuals (ghost, placeholder, transforms) by\n * reacting to the events and the `data-dragging` / `data-grabbed` hooks. The one\n * deliberate exception is the opt-in `follow` value for the \"just move the\n * element\" case: it applies the in-flight deltas to the element's CSS\n * `translate` (a property independent of `transform`, so authored transforms\n * survive), commits the offset on drop and restores it on cancel — the exact\n * boilerplate every simple consumer would otherwise re-write. With `follow` the\n * element's inline `translate` belongs to this controller (`connect()` re-reads\n * a committed `<x>px <y>px` offset, so Turbo restores stay consistent). ARIA 1.1\n * deprecated `aria-grabbed`/`aria-dropeffect`, so the grabbed state is\n * published as `data-grabbed` and the *meaning* of a drag must be announced by\n * the consumer (pair with `stimeo--announcer`). `touch-action` on the handles is\n * derived from `axis` (marker-guarded, authored values win) so the page does not\n * pan mid-drag. Deltas are physical (client coordinates): RTL semantics belong\n * to the consumer. `disconnect()` (Turbo navigation included) tears down any\n * active session — except across an in-page move, which the session survives\n * (the full lifecycle contract lives on `disconnect()`); `connect()` clears\n * stale hooks a Turbo cache restore may have preserved (a drag cannot survive\n * a navigation).\n */\nexport class PointerDragController extends Controller<HTMLElement> {\n static override targets = [\"handle\"];\n static override values = {\n axis: { type: String, default: \"both\" },\n threshold: { type: Number, default: 3 },\n keyboardStep: { type: Number, default: 10 },\n disabled: { type: Boolean, default: false },\n follow: { type: Boolean, default: false },\n };\n static events = [\"start\", \"move\", \"end\", \"cancel\"] as const;\n\n declare readonly handleTargets: HTMLElement[];\n declare readonly hasHandleTarget: boolean;\n declare axisValue: string;\n declare thresholdValue: number;\n declare keyboardStepValue: number;\n declare disabledValue: boolean;\n declare followValue: boolean;\n\n /** Marker attribute recording that this controller set the touch-action. */\n static readonly #TOUCH_ACTION_MARKER = \"data-pointer-drag-touch-action\";\n /** Marker attribute recording that this controller set `tabindex`. */\n static readonly #TABINDEX_MARKER = \"data-pointer-drag-tabindex\";\n\n #pointer: PointerSession | null = null;\n #keyboard: KeyboardSession | null = null;\n /** Committed follow offset from past drops; a new drag's deltas add onto it. */\n #followBase = { x: 0, y: 0 };\n /** Aborts in-progress pointer-drag listeners on drag end / teardown. */\n #dragAbort: AbortController | null = null;\n /** Decides whether a mid-session disconnect() is an in-page move or a detach. */\n readonly #gate = new DetachGate();\n\n override connect(): void {\n // A reconnect disarms the probe a mid-session disconnect() armed — the\n // element was moved in-page and the session survives (see disconnect).\n this.#gate.cancel();\n // Transient drag state cannot survive a navigation: clear hooks a Turbo\n // cache restore may have snapshotted mid-drag (idempotent reconnect). But a\n // session preserved across an in-page move keeps its hooks.\n if (!this.#pointer) this.element.removeAttribute(\"data-dragging\");\n if (!this.#keyboard) this.element.removeAttribute(\"data-grabbed\");\n // Follow mode owns the element's inline `translate`: re-read a committed\n // offset so reconnects (Turbo cache restore included) keep accumulating from\n // where the element visually sits. A session surviving an in-page move keeps\n // its base — mid-drag inline state must not be committed as a new base.\n if (this.followValue && !this.#pointer && !this.#keyboard) {\n this.#followBase = this.#parseFollowBase();\n }\n // Delegated on the container so dynamically added handles need no per-element\n // data-action.\n this.element.addEventListener(\"pointerdown\", this.#onPointerDown);\n this.element.addEventListener(\"keydown\", this.#onKeydown);\n if (!this.hasHandleTarget) this.#prepareHandle(this.element);\n }\n\n override disconnect(): void {\n this.element.removeEventListener(\"pointerdown\", this.#onPointerDown);\n this.element.removeEventListener(\"keydown\", this.#onKeydown);\n // A mid-session disconnect on a STILL-connected element is ambiguous: an\n // in-page move (a consumer like sortable re-inserts the item mid-grab —\n // Stimulus reconnects the same instance in the same mutation batch, and\n // the session must survive) vs a real detach that keeps the element\n // (`data-controller` removed, Turbo morph, element moved outside the\n // observed root). DetachGate discriminates: the token check is the\n // synchronous fast path (a morph's teardown — and its `cancel` — fires in\n // the same tick), the one-microtask probe cancelled by connect() covers\n // the rest — a detached-in-place controller never leaks its session or\n // document listeners. Probe only while a session needs protecting; an\n // idle controller tears down synchronously either way.\n if (this.#pointer || this.#keyboard) {\n this.#gate.disconnected(this, () => this.#teardown());\n return;\n }\n this.#teardown();\n }\n\n /** Prepares handles added at runtime (touch-action + focusability). */\n handleTargetConnected(handle: HTMLElement): void {\n this.#prepareHandle(handle);\n }\n\n handleTargetDisconnected(handle: HTMLElement): void {\n // A handle REMOVED mid-session can never deliver its keydown (the delegated\n // listener sits on the container it left), so the session would leak — and\n // the one-session guard would then reject every future pointerdown. End it\n // silently: the DOM is changing under the user, same as disconnect. But\n // target callbacks ALSO fire when the CONTROLLER disconnects (Stimulus\n // stops the target observer — including the in-page move a live session\n // must survive): a handle still inside the element was not removed, so\n // that case is left to disconnect()'s deferred probe.\n if (!this.element.contains(handle)) {\n if (this.#pointer?.handle === handle) this.#endPointerSession();\n if (this.#keyboard?.handle === handle) this.#clearKeyboardSession();\n }\n this.#restoreHandle(handle);\n }\n\n /** Re-derives the handles' touch-action when the axis changes. */\n axisValueChanged(): void {\n for (const handle of this.#handles()) {\n if (handle.hasAttribute(PointerDragController.#TOUCH_ACTION_MARKER)) {\n handle.style.touchAction = this.#touchActionForAxis();\n }\n }\n }\n\n /** Cancels any in-flight session when the controller is disabled mid-drag. */\n disabledValueChanged(): void {\n if (!this.disabledValue) return;\n if (this.#pointer?.started || this.#keyboard) {\n this.#dispatchCancel(this.#keyboard ? \"keyboard\" : (this.#pointer?.pointerType ?? \"mouse\"));\n }\n this.#teardownSessions();\n }\n\n /** Arms a pointer drag on a handle; `start` waits for the threshold. */\n readonly #onPointerDown = (event: PointerEvent): void => {\n // One session at a time: ignore a second pointerdown (multi-touch, an\n // errant tap, a grabbed keyboard session) so an in-flight drag is never\n // silently overwritten and its captured pointer orphaned.\n if (this.disabledValue || this.#pointer || this.#keyboard || event.button !== 0) return;\n const handle = this.#handleFor(event.target);\n if (!handle) return;\n\n // Suppress text selection / native image drag; restore the focus the\n // suppressed default would have given, so Escape and the keyboard path\n // stay reachable right after a pointer interaction (WCAG 2.1.1).\n event.preventDefault();\n handle.focus();\n\n this.#pointer = {\n pointerId: event.pointerId,\n handle,\n originX: event.clientX,\n originY: event.clientY,\n started: false,\n dx: 0,\n dy: 0,\n pointerType: this.#pointerTypeOf(event),\n };\n\n // Pointer capture keeps fast drags delivering to the handle even when the\n // pointer strays outside it — but a consumer may re-insert the dragged\n // element mid-drag (sortable's live reorder), which silently releases the\n // capture. Tracking listeners therefore live on the DOCUMENT (captured\n // events bubble there; uncaptured ones fire there anyway), and the\n // AbortController releases them on drag end and disconnect() (Turbo included).\n handle.setPointerCapture(event.pointerId);\n this.#dragAbort?.abort();\n const abort = new AbortController();\n this.#dragAbort = abort;\n document.addEventListener(\"pointermove\", this.#onPointerMove, { signal: abort.signal });\n document.addEventListener(\"pointerup\", this.#onPointerUp, { signal: abort.signal });\n document.addEventListener(\"pointercancel\", this.#onPointerCancel, { signal: abort.signal });\n };\n\n readonly #onPointerMove = (event: PointerEvent): void => {\n const session = this.#pointer;\n if (!session || event.pointerId !== session.pointerId) return;\n\n const [dx, dy] = this.#filterAxis(\n event.clientX - session.originX,\n event.clientY - session.originY,\n );\n if (!session.started) {\n if (Math.hypot(dx, dy) < this.thresholdValue) return;\n session.started = true;\n this.element.setAttribute(\"data-dragging\", \"true\");\n this.dispatch(\"start\", {\n detail: { x: event.clientX, y: event.clientY, pointerType: session.pointerType },\n });\n }\n\n session.dx = dx;\n session.dy = dy;\n this.#followMove(dx, dy);\n this.dispatch(\"move\", {\n detail: { dx, dy, x: event.clientX, y: event.clientY, pointerType: session.pointerType },\n });\n };\n\n readonly #onPointerUp = (event: PointerEvent): void => {\n const session = this.#pointer;\n if (!session || event.pointerId !== session.pointerId) return;\n const { started, dx, dy, pointerType } = session;\n this.#endPointerSession();\n // Below the threshold the gesture was a plain click, not a drag: stay silent.\n if (!started) return;\n this.#followCommit(dx, dy);\n this.dispatch(\"end\", { detail: { dx, dy, pointerType } });\n };\n\n /** OS gesture / scroll takeover interrupted the drag: cancel, don't drop. */\n readonly #onPointerCancel = (event: PointerEvent): void => {\n const session = this.#pointer;\n if (!session || event.pointerId !== session.pointerId) return;\n const { started, pointerType } = session;\n this.#endPointerSession();\n if (started) this.#dispatchCancel(pointerType);\n };\n\n /** Keyboard alternative: Space/Enter grab & drop, arrows move, Escape cancels. */\n readonly #onKeydown = (event: KeyboardEvent): void => {\n if (this.disabledValue) return;\n const handle = this.#handleFor(event.target);\n if (!handle) return;\n\n // A descendant widget that already claimed the key (a nested roving list, a\n // segmented field inside the handle) must not ALSO drive the drag —\n // composition depends on this yield. This controller is the \"grabbed drag\n // handle\" that the other yields name as the widget they defer to, so it owes\n // the same courtesy downward.\n if (event.defaultPrevented) return;\n // A chorded arrow belongs to the browser. \"Someone already consumed it\"\n // outranks that, so it is checked after the yield above.\n if (isReservedArrowChord(event)) return;\n\n // Escape cancels whichever session is live (pointer drag or keyboard grab).\n if (event.key === \"Escape\") {\n // A press an inner handler already owned is yielded at the top of this\n // handler. What is checked here is the IME half: a press during a\n // composition steers the conversion, not the drag.\n if (event.isComposing) return;\n if (this.#pointer?.started) {\n const { pointerType } = this.#pointer;\n this.#teardownSessions();\n event.preventDefault();\n this.#dispatchCancel(pointerType);\n } else if (this.#keyboard) {\n this.#teardownSessions();\n event.preventDefault();\n this.#dispatchCancel(\"keyboard\");\n }\n return;\n }\n\n if (event.key === \" \" || event.key === \"Enter\") {\n // A live pointer drag owns the session: pressing Space mid-drag (the\n // pointerdown focused the handle) must not start a parallel grab.\n if (this.#pointer) return;\n event.preventDefault();\n if (this.#keyboard) this.#dropKeyboard();\n else this.#grabKeyboard(handle);\n return;\n }\n\n if (!this.#keyboard) return;\n const step = this.#keyboardDelta(event.key);\n if (!step) return;\n // Consume every arrow while grabbed (even on a locked axis) so the page\n // never scrolls mid-grab; only allowed-axis arrows emit a move.\n event.preventDefault();\n const [dx, dy] = this.#filterAxis(step[0], step[1]);\n if (dx === 0 && dy === 0) return;\n this.#keyboard.dx += dx;\n this.#keyboard.dy += dy;\n this.#followMove(this.#keyboard.dx, this.#keyboard.dy);\n this.dispatch(\"move\", {\n detail: {\n dx: this.#keyboard.dx,\n dy: this.#keyboard.dy,\n x: this.#keyboard.dx,\n y: this.#keyboard.dy,\n pointerType: \"keyboard\",\n },\n });\n };\n\n /** Enters the grabbed mode: `data-grabbed` on element + handle, then `start`. */\n #grabKeyboard(handle: HTMLElement): void {\n this.#keyboard = { handle, dx: 0, dy: 0 };\n this.element.setAttribute(\"data-grabbed\", \"true\");\n handle.setAttribute(\"data-grabbed\", \"true\");\n this.dispatch(\"start\", { detail: { x: 0, y: 0, pointerType: \"keyboard\" } });\n }\n\n #dropKeyboard(): void {\n const session = this.#keyboard;\n if (!session) return;\n this.#clearKeyboardSession();\n this.#followCommit(session.dx, session.dy);\n this.dispatch(\"end\", { detail: { dx: session.dx, dy: session.dy, pointerType: \"keyboard\" } });\n }\n\n /** Maps an arrow key to a raw (unfiltered) `keyboardStep` delta. */\n #keyboardDelta(key: string): [number, number] | null {\n const step = this.keyboardStepValue;\n switch (key) {\n case \"ArrowRight\":\n return [step, 0];\n case \"ArrowLeft\":\n return [-step, 0];\n case \"ArrowDown\":\n return [0, step];\n case \"ArrowUp\":\n return [0, -step];\n default:\n return null;\n }\n }\n\n /** Zeroes the delta on the locked axis (`axis` = x | y | both). */\n #filterAxis(dx: number, dy: number): [number, number] {\n if (this.axisValue === \"x\") return [dx, 0];\n if (this.axisValue === \"y\") return [0, dy];\n return [dx, dy];\n }\n\n /** Releases capture + listeners and clears the pointer session and its hook. */\n #endPointerSession(): void {\n this.#releasePointerCapture();\n this.#pointer = null;\n this.#dragAbort?.abort();\n this.#dragAbort = null;\n this.element.removeAttribute(\"data-dragging\");\n }\n\n /** Releases the pointer capture the active session set (idempotent, safe). */\n #releasePointerCapture(): void {\n const session = this.#pointer;\n if (session?.handle.hasPointerCapture(session.pointerId)) {\n session.handle.releasePointerCapture(session.pointerId);\n }\n }\n\n #clearKeyboardSession(): void {\n this.#keyboard?.handle.removeAttribute(\"data-grabbed\");\n this.#keyboard = null;\n this.element.removeAttribute(\"data-grabbed\");\n }\n\n /**\n * Full teardown for a controller whose element is going away or lost its\n * controller. Into a dead (detached) tree it is silent — consumers restore\n * from their own `connect()`, not from a cancel event. But a detach that\n * KEEPS the element (Turbo morph, `data-controller` removed) leaves the\n * consumers alive and listening: an in-flight session must end in `cancel`\n * there, or a composer like sortable strands its one-at-a-time session\n * bookkeeping forever.\n */\n #teardown(): void {\n // Disarm any probe still queued: without this, an immediate teardown\n // (element removed right after a deferring disconnect) would let the\n // orphaned probe run #teardown a second time — a double cancel.\n this.#gate.cancel();\n const interrupted = this.#pointer?.started\n ? this.#pointer.pointerType\n : this.#keyboard\n ? (\"keyboard\" as const)\n : null;\n this.#teardownSessions();\n for (const handle of this.#handles()) this.#restoreHandle(handle);\n if (interrupted && this.element.isConnected) this.#dispatchCancel(interrupted);\n }\n\n /**\n * Silently tears down whatever session is live (disconnect / disabled /\n * Escape). Composed from the two single-session teardowns so pointer and\n * keyboard cleanup cannot diverge as either path evolves.\n */\n #teardownSessions(): void {\n this.#endPointerSession();\n this.#clearKeyboardSession();\n }\n\n #dispatchCancel(pointerType: DragPointerType): void {\n // Every cancel path funnels here, so follow's snap-back can never be missed\n // (Escape, pointercancel, mid-session disable, detach-that-keeps-the-element).\n this.#followReset();\n this.dispatch(\"cancel\", { detail: { pointerType } });\n }\n\n /** Applies the in-flight offset to the element's `translate` (follow only). */\n #followMove(dx: number, dy: number): void {\n if (!this.followValue) return;\n this.#applyFollow(this.#followBase.x + dx, this.#followBase.y + dy);\n }\n\n /** Folds a drop's deltas into the committed base offset (follow only). */\n #followCommit(dx: number, dy: number): void {\n if (!this.followValue) return;\n this.#followBase = { x: this.#followBase.x + dx, y: this.#followBase.y + dy };\n this.#applyFollow(this.#followBase.x, this.#followBase.y);\n }\n\n /** Snaps back to the committed position (follow only) — the cancel contract. */\n #followReset(): void {\n if (!this.followValue) return;\n this.#applyFollow(this.#followBase.x, this.#followBase.y);\n }\n\n /**\n * Writes the offset as the standalone CSS `translate` property — independent\n * of `transform`, so an authored transform (scale, rotate…) is never\n * clobbered. At the origin the property is removed to keep the DOM clean.\n */\n #applyFollow(x: number, y: number): void {\n if (x === 0 && y === 0) this.element.style.removeProperty(\"translate\");\n else this.element.style.setProperty(\"translate\", `${x}px ${y}px`);\n }\n\n /**\n * Reads a committed follow offset back from the inline `translate`. Only the\n * controller's own `<x>px <y>px` shape is recognized; anything else (an\n * authored percentage, `none`, an empty string) starts the base at 0 — follow\n * mode owns this property, per the class contract.\n */\n #parseFollowBase(): { x: number; y: number } {\n const raw = this.element.style.getPropertyValue(\"translate\").trim();\n const match = /^(-?\\d+(?:\\.\\d+)?)px(?:\\s+(-?\\d+(?:\\.\\d+)?)px)?$/.exec(raw);\n if (!match) return { x: 0, y: 0 };\n return { x: Number(match[1]), y: Number(match[2] ?? \"0\") };\n }\n\n /** The active handles: the `handle` targets, else the element itself. */\n #handles(): HTMLElement[] {\n return this.hasHandleTarget ? this.handleTargets : [this.element];\n }\n\n /** Resolves the handle owning an event target (the handle or a descendant). */\n #handleFor(target: EventTarget | null): HTMLElement | null {\n const node = target as Node | null;\n if (!node) return null;\n return this.#handles().find((handle) => handle === node || handle.contains(node)) ?? null;\n }\n\n #pointerTypeOf(event: PointerEvent): DragPointerType {\n const type = event.pointerType;\n if (type === \"touch\" || type === \"pen\") return type;\n return \"mouse\";\n }\n\n /** `touch-action` that lets the page keep panning on the locked axis only. */\n #touchActionForAxis(): string {\n if (this.axisValue === \"x\") return \"pan-y\";\n if (this.axisValue === \"y\") return \"pan-x\";\n return \"none\";\n }\n\n /**\n * Establishes the handle contract: a `touch-action` derived from `axis`\n * (marker-guarded so an authored inline value wins and reconnects stay\n * idempotent) and focusability for the keyboard path (`tabindex=\"0\"` only when\n * the author supplied none — prefer a real `<button>` handle). Both additions\n * are marker-owned so `#restoreHandle` reverts them symmetrically on teardown.\n */\n #prepareHandle(handle: HTMLElement): void {\n if (\n handle.style.touchAction === \"\" ||\n handle.hasAttribute(PointerDragController.#TOUCH_ACTION_MARKER)\n ) {\n handle.style.touchAction = this.#touchActionForAxis();\n handle.setAttribute(PointerDragController.#TOUCH_ACTION_MARKER, \"true\");\n }\n if (handle.tabIndex < 0 && !handle.hasAttribute(\"tabindex\")) {\n handle.setAttribute(\"tabindex\", \"0\");\n handle.setAttribute(PointerDragController.#TABINDEX_MARKER, \"true\");\n }\n }\n\n /** Reverts the marker-owned touch-action + tabindex (authored values untouched). */\n #restoreHandle(handle: HTMLElement): void {\n if (handle.hasAttribute(PointerDragController.#TOUCH_ACTION_MARKER)) {\n handle.style.touchAction = \"\";\n handle.removeAttribute(PointerDragController.#TOUCH_ACTION_MARKER);\n }\n if (handle.hasAttribute(PointerDragController.#TABINDEX_MARKER)) {\n handle.removeAttribute(PointerDragController.#TABINDEX_MARKER);\n // Only remove what is verifiably still ours and safe to remove: another\n // owner (e.g. a roving list) may have rewritten the value since, and\n // stripping tabindex off the focused element would blur it to <body>\n // (losing the user's place — worse than leaking one tab stop).\n if (handle.getAttribute(\"tabindex\") === \"0\" && document.activeElement !== handle) {\n handle.removeAttribute(\"tabindex\");\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/arrow_step.ts","../../src/utils/detach_gate.ts","../../src/controllers/pointer_drag_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;;;AC9BO,IAAM,UAAA,GAAN,MAAM,WAAA,CAAW;AAAA;AAAA,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,IACF;AAAA,EACF;AACF","file":"pointer_drag_controller.js","sourcesContent":["import { isRtl } from \"./logical_scroll\";\n\n/**\n * Turns an arrow key into a **logical** step: `+1` for \"next\", `-1` for\n * \"previous\", `0` when the key names neither.\n *\n * APG defines the horizontal pair as *next / previous* and says a vertical\n * arrangement swaps in Down/Up for the same meaning — so the pair is one axis's\n * spelling of an order, and the order reverses with the writing direction. Only\n * the horizontal pair reverses. Down/Up name an axis the writing direction does\n * not mirror, and returning them unchanged is the point: many controllers fold\n * both pairs into one branch, where swapping the branches under RTL would flip\n * the vertical axis too — a bug that reads as \"the arrows work\" until someone\n * presses Down.\n *\n * **Direction is read from the element the caller passes, which should be the\n * container that lays the items out** — not the focused child. A child may carry\n * its own `dir` (an LTR input inside an RTL form is ordinary authoring), and\n * probing per handler makes two handlers disagree at the boundary between them.\n *\n * This decides direction only. Whether the axis is even active (an\n * `orientation=\"horizontal\"` widget ignoring Down/Up), how far the step lands,\n * and what wrapping does all stay with the caller.\n *\n * **It encodes the list-order convention: `ArrowDown` is *next*.** Widgets that\n * pair the arrows by *value* instead — `ArrowUp` meaning \"more\", as a rating or a\n * slider does — must not use this, or their vertical axis inverts. Reverse the\n * horizontal pair on its own there.\n *\n * @example\n * ```ts\n * const step = logicalArrowStep(event.key, this.element);\n * if (step === 0) return;\n * this.#roving.setActive(rovingMove(current, length, step, \"wrap\"), { focus: true });\n * ```\n */\nexport function logicalArrowStep(key: string, element: Element): 1 | -1 | 0 {\n if (key === \"ArrowDown\") return 1;\n if (key === \"ArrowUp\") return -1;\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return 0;\n const forward = isRtl(element) ? \"ArrowLeft\" : \"ArrowRight\";\n return key === forward ? 1 : -1;\n}\n\n/**\n * Rewrites `key` so an existing LTR-shaped branch keeps working under RTL:\n * `ArrowRight` and `ArrowLeft` trade places, everything else passes through.\n *\n * The alternative — negating a delta — silently breaks handlers whose two\n * horizontal branches are **not mirror images**. A grid that clamps one edge but\n * not the other, or a segmented field guarding `index > 0` on one side and\n * `index < length - 1` on the other, ends up applying the wrong guard to the\n * wrong direction. Swapping the key leaves each branch, guards and all, exactly\n * where its author put it.\n *\n * Same rule as {@link logicalArrowStep} about which element to read: pass the\n * container that lays the items out, not the focused child.\n *\n * @example\n * ```ts\n * switch (logicalArrowKey(event.key, this.element)) {\n * case \"ArrowLeft\": // \"previous\" — whatever direction that is on screen\n * ```\n */\nexport function logicalArrowKey(key: string, element: Element): string {\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return key;\n if (!isRtl(element)) return key;\n return key === \"ArrowRight\" ? \"ArrowLeft\" : \"ArrowRight\";\n}\n\n/** Modifiers a widget may claim on an arrow key, named for the `allow` list. */\nexport type ArrowModifier = \"alt\" | \"ctrl\" | \"meta\" | \"shift\";\n\n/**\n * True when an arrow key arrived carrying a modifier the widget must leave to\n * the browser: return without calling `preventDefault()` and without moving any\n * state.\n *\n * A bare arrow belongs to the widget; a chorded one usually does not.\n * `Alt`/`Meta` plus a horizontal arrow is history back/forward on every desktop\n * browser, and a widget that swallows it makes the shortcut work or not\n * depending on where focus happens to sit — a coin-flip the user cannot see.\n *\n * `allow` is for the combinations APG assigns to a pattern **and the widget\n * actually implements** — today only Combobox's optional `Alt+Down`/`Alt+Up`.\n * Listing one the widget does not implement defeats the point: the chord then\n * runs the plain-arrow branch, which is exactly what this guard exists to stop.\n * Non-arrow keys return `false`, so chorded letters and\n * `Control+Home`/`Control+End` are untouched.\n *\n * @example\n * ```ts\n * if (isReservedArrowChord(event)) return;\n * ```\n */\nexport function isReservedArrowChord(\n event: KeyboardEvent,\n allow: readonly ArrowModifier[] = [],\n): boolean {\n if (!event.key.startsWith(\"Arrow\")) return false;\n return (\n (event.altKey && !allow.includes(\"alt\")) ||\n (event.ctrlKey && !allow.includes(\"ctrl\")) ||\n (event.metaKey && !allow.includes(\"meta\")) ||\n (event.shiftKey && !allow.includes(\"shift\"))\n );\n}\n","/**\n * Shared \"in-page move vs real detach\" discriminator for `disconnect()`.\n *\n * A mid-session `disconnect()` whose element is still in the document is\n * ambiguous. It can be:\n *\n * - an **in-page move** — a consumer (sortable, a teleport) re-inserted the\n * element; Stimulus reconnects the SAME instance in the same mutation batch\n * and the controller's runtime state must survive;\n * - a **detach that keeps the element** — `data-controller` no longer lists the\n * identifier (a Turbo 8 morph), or the element moved outside the observed\n * root (a scoped `Application.start(root)`, a shadow root); no reconnect will\n * ever come and the controller must tear down or it leaks its sessions,\n * document listeners, and moved nodes.\n *\n * Neither available signal decides this alone. A synchronous `data-controller`\n * token check catches the morph case but misses an observed-root exit (the\n * token stays, the reconnect never comes). Deferring teardown one microtask and\n * letting `connect()` cancel it catches the root exit, but leans on Stimulus\n * reconnecting moved elements within the same mutation batch — internal\n * behavior, not a public contract. {@link DetachGate} composes both: the token\n * check is the synchronous fast path (no probe, no reliance on batching), the\n * microtask probe is the fallback for the genuinely ambiguous remainder.\n *\n * Policy stays with the consumer (the `SafeTimeout` / `FocusTrap` lineage —\n * this util owns the discrimination only):\n *\n * - **Probe** ({@link disconnected}) when the teardown must eventually happen —\n * live drag sessions, document listeners, teleported *content*. Call\n * {@link cancel} from `connect()` (a reconnect means in-page move) and from\n * the head of any direct teardown path (see below).\n * - **Keep** (bare {@link DetachGate.isDetached}) when undoing the ambiguous\n * case would fight the controller's own effect: a controller that moves its\n * OWN element (portal's no-`content` form) exits a scoped observed root as\n * its normal job — a probe-driven teardown would restore the element into\n * the root, reconnect, re-teleport, and disconnect again, forever. Such\n * controllers keep their state on an ambiguous disconnect and tear down only\n * on {@link DetachGate.isDetached}.\n *\n * Event convention for probe consumers: teardown into a dead (detached) tree is\n * silent — consumers restore from their own `connect()`; a detach that keeps the\n * tree alive must end an in-flight session with a `cancel` event, or composing\n * consumers strand their session bookkeeping.\n */\n\n/** The slice of a Stimulus controller the gate inspects. */\nexport interface DetachGateHost {\n readonly element: Element;\n readonly identifier: string;\n}\n\n/**\n * Per-controller-instance gate deciding whether a `disconnect()` is a real\n * detach. Hold one per controller (`#gate = new DetachGate()`) — Stimulus\n * reuses the instance across reconnects, so the pending probe state carries\n * over exactly as the protocol needs.\n *\n * @example\n * ```ts\n * #gate = new DetachGate();\n *\n * connect(): void {\n * this.#gate.cancel(); // a reconnect: the element moved in-page\n * // …\n * }\n *\n * disconnect(): void {\n * this.#gate.disconnected(this, () => this.#teardown());\n * }\n *\n * #teardown(): void {\n * this.#gate.cancel(); // disarm a still-queued probe (double-run guard)\n * // …\n * }\n * ```\n */\nexport class DetachGate {\n /** Set while a probe is queued, waiting for a reconnect to cancel it. */\n #pending = false;\n\n /**\n * True while a probe is queued — the last disconnect was ambiguous and no\n * reconnect has cancelled it yet. Read it from `connect()` to tell the\n * reconnect half of an in-page move from a first connect: a controller whose\n * initialisation restarts a measurement (a min-duration floor, an elapsed\n * counter) must skip it for the move, where nothing actually restarted.\n */\n get pending(): boolean {\n return this.#pending;\n }\n\n /**\n * True when the disconnect is definitely a real detach — the element left\n * the document, or `data-controller` no longer lists the identifier. False\n * means ambiguous (in-page move or observed-root exit), NOT \"alive\".\n */\n static isDetached(host: DetachGateHost): boolean {\n if (!host.element.isConnected) return true;\n const tokens = (host.element.getAttribute(\"data-controller\") ?? \"\").split(/\\s+/);\n return !tokens.includes(host.identifier);\n }\n\n /**\n * Call from `disconnect()`: runs `teardown` synchronously on a definite\n * detach (fast path), otherwise defers it one microtask — a reconnect\n * ({@link cancel} from `connect()`) keeps the state, no reconnect runs it.\n * One microtask is the whole probe window: Stimulus reconnects a moved\n * element within the same mutation batch, before the checkpoint drains.\n */\n disconnected(host: DetachGateHost, teardown: () => void): void {\n if (DetachGate.isDetached(host)) {\n // Also disarms a probe a previous ambiguous disconnect left queued\n // (defer, element removed, disconnect again) — exactly one teardown.\n this.#pending = false;\n teardown();\n return;\n }\n this.#pending = true;\n queueMicrotask(() => {\n if (!this.#pending) return;\n this.#pending = false;\n teardown();\n });\n }\n\n /**\n * Disarms a pending probe. Call from `connect()` (the reconnect that proves\n * an in-page move) and from the head of any teardown path not routed through\n * {@link disconnected} (disabled-toggle, Escape), so an orphaned probe can\n * never run the teardown a second time.\n */\n cancel(): void {\n this.#pending = false;\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord } from \"../utils/arrow_step\";\nimport { DetachGate } from \"../utils/detach_gate\";\n\n/** How a drag session was initiated; surfaced in every event detail. */\ntype DragPointerType = \"mouse\" | \"touch\" | \"pen\" | \"keyboard\";\n\n/** A pointer drag in flight (from `pointerdown` until up/cancel). */\ninterface PointerSession {\n pointerId: number;\n handle: HTMLElement;\n originX: number;\n originY: number;\n /** True once the movement passed `threshold` and `start` was dispatched. */\n started: boolean;\n /** Last axis-filtered deltas, reported again by `end`. */\n dx: number;\n dy: number;\n pointerType: DragPointerType;\n}\n\n/** A keyboard \"grabbed\" session (Space/Enter on the handle until drop/cancel). */\ninterface KeyboardSession {\n handle: HTMLElement;\n /** Cumulative synthetic deltas accumulated by the arrow keys. */\n dx: number;\n dy: number;\n}\n\n/**\n * Headless **pointer-drag primitive**: a normalized pointer/touch/mouse drag\n * lifecycle with a built-in keyboard alternative. It deliberately does NOT decide\n * what a drag *means* (reorder, dismiss, resize…) — it only emits a clean,\n * accessibility-friendly drag signal that higher-level behaviors (sortable,\n * swipe-actions, bottom-sheet, split-pane…) compose from. No dedicated APG\n * pattern exists for drag-and-drop; the keyboard model below is the accepted\n * alternative-input technique (WCAG 2.1.1 / 2.5.7 Dragging Movements). Core\n * (zero dependencies).\n *\n * Markup contract (identifier: `stimeo--pointer-drag`):\n * <li data-controller=\"stimeo--pointer-drag\"\n * data-stimeo--pointer-drag-axis-value=\"y\">\n * <button data-stimeo--pointer-drag-target=\"handle\" aria-label=\"Reorder\">⠿</button>\n * </li>\n *\n * The `handle` target is optional — without one, the controller element itself\n * is the handle. Pointer flow: `pointerdown` on a handle arms the drag; once the\n * axis-filtered movement exceeds `threshold`, `start` fires, every subsequent\n * movement fires `move` (deltas cumulative from the origin), and release fires\n * `end` (`pointercancel` → `cancel`). Keyboard flow: Space/Enter on the handle\n * grabs (`start`, `data-grabbed`), the arrow keys emit synthetic `move` events of\n * `keyboardStep` px each, Space/Enter drops (`end`) and Escape cancels — so every\n * consumer gets a keyboard path for free.\n *\n * @remarks\n * Behavior only: consumers own all visuals (ghost, placeholder, transforms) by\n * reacting to the events and the `data-dragging` / `data-grabbed` hooks. The one\n * deliberate exception is the opt-in `follow` value for the \"just move the\n * element\" case: it applies the in-flight deltas to the element's CSS\n * `translate` (a property independent of `transform`, so authored transforms\n * survive), commits the offset on drop and restores it on cancel — the exact\n * boilerplate every simple consumer would otherwise re-write. With `follow` the\n * element's inline `translate` belongs to this controller (`connect()` re-reads\n * a committed `<x>px <y>px` offset, so Turbo restores stay consistent). ARIA 1.1\n * deprecated `aria-grabbed`/`aria-dropeffect`, so the grabbed state is\n * published as `data-grabbed` and the *meaning* of a drag must be announced by\n * the consumer (pair with `stimeo--announcer`). `touch-action` on the handles is\n * derived from `axis` (marker-guarded, authored values win) so the page does not\n * pan mid-drag. Deltas are physical (client coordinates): RTL semantics belong\n * to the consumer. `disconnect()` (Turbo navigation included) tears down any\n * active session — except across an in-page move, which the session survives\n * (the full lifecycle contract lives on `disconnect()`); `connect()` clears\n * stale hooks a Turbo cache restore may have preserved (a drag cannot survive\n * a navigation).\n */\nexport class PointerDragController extends Controller<HTMLElement> {\n static override targets = [\"handle\"];\n static override values = {\n axis: { type: String, default: \"both\" },\n threshold: { type: Number, default: 3 },\n keyboardStep: { type: Number, default: 10 },\n disabled: { type: Boolean, default: false },\n follow: { type: Boolean, default: false },\n };\n static events = [\"start\", \"move\", \"end\", \"cancel\"] as const;\n\n declare readonly handleTargets: HTMLElement[];\n declare readonly hasHandleTarget: boolean;\n declare axisValue: string;\n declare thresholdValue: number;\n declare keyboardStepValue: number;\n declare disabledValue: boolean;\n declare followValue: boolean;\n\n /** Marker attribute recording that this controller set the touch-action. */\n static readonly #TOUCH_ACTION_MARKER = \"data-pointer-drag-touch-action\";\n /** Marker attribute recording that this controller set `tabindex`. */\n static readonly #TABINDEX_MARKER = \"data-pointer-drag-tabindex\";\n\n #pointer: PointerSession | null = null;\n #keyboard: KeyboardSession | null = null;\n /** Committed follow offset from past drops; a new drag's deltas add onto it. */\n #followBase = { x: 0, y: 0 };\n /** Aborts in-progress pointer-drag listeners on drag end / teardown. */\n #dragAbort: AbortController | null = null;\n /** Decides whether a mid-session disconnect() is an in-page move or a detach. */\n readonly #gate = new DetachGate();\n\n override connect(): void {\n // A reconnect disarms the probe a mid-session disconnect() armed — the\n // element was moved in-page and the session survives (see disconnect).\n this.#gate.cancel();\n // Transient drag state cannot survive a navigation: clear hooks a Turbo\n // cache restore may have snapshotted mid-drag (idempotent reconnect). But a\n // session preserved across an in-page move keeps its hooks.\n if (!this.#pointer) this.element.removeAttribute(\"data-dragging\");\n if (!this.#keyboard) this.element.removeAttribute(\"data-grabbed\");\n // Follow mode owns the element's inline `translate`: re-read a committed\n // offset so reconnects (Turbo cache restore included) keep accumulating from\n // where the element visually sits. A session surviving an in-page move keeps\n // its base — mid-drag inline state must not be committed as a new base.\n if (this.followValue && !this.#pointer && !this.#keyboard) {\n this.#followBase = this.#parseFollowBase();\n }\n // Delegated on the container so dynamically added handles need no per-element\n // data-action.\n this.element.addEventListener(\"pointerdown\", this.#onPointerDown);\n this.element.addEventListener(\"keydown\", this.#onKeydown);\n if (!this.hasHandleTarget) this.#prepareHandle(this.element);\n }\n\n override disconnect(): void {\n this.element.removeEventListener(\"pointerdown\", this.#onPointerDown);\n this.element.removeEventListener(\"keydown\", this.#onKeydown);\n // A mid-session disconnect on a STILL-connected element is ambiguous: an\n // in-page move (a consumer like sortable re-inserts the item mid-grab —\n // Stimulus reconnects the same instance in the same mutation batch, and\n // the session must survive) vs a real detach that keeps the element\n // (`data-controller` removed, Turbo morph, element moved outside the\n // observed root). DetachGate discriminates: the token check is the\n // synchronous fast path (a morph's teardown — and its `cancel` — fires in\n // the same tick), the one-microtask probe cancelled by connect() covers\n // the rest — a detached-in-place controller never leaks its session or\n // document listeners. Probe only while a session needs protecting; an\n // idle controller tears down synchronously either way.\n if (this.#pointer || this.#keyboard) {\n this.#gate.disconnected(this, () => this.#teardown());\n return;\n }\n this.#teardown();\n }\n\n /** Prepares handles added at runtime (touch-action + focusability). */\n handleTargetConnected(handle: HTMLElement): void {\n this.#prepareHandle(handle);\n }\n\n handleTargetDisconnected(handle: HTMLElement): void {\n // A handle REMOVED mid-session can never deliver its keydown (the delegated\n // listener sits on the container it left), so the session would leak — and\n // the one-session guard would then reject every future pointerdown. End it\n // silently: the DOM is changing under the user, same as disconnect. But\n // target callbacks ALSO fire when the CONTROLLER disconnects (Stimulus\n // stops the target observer — including the in-page move a live session\n // must survive): a handle still inside the element was not removed, so\n // that case is left to disconnect()'s deferred probe.\n if (!this.element.contains(handle)) {\n if (this.#pointer?.handle === handle) this.#endPointerSession();\n if (this.#keyboard?.handle === handle) this.#clearKeyboardSession();\n }\n this.#restoreHandle(handle);\n }\n\n /** Re-derives the handles' touch-action when the axis changes. */\n axisValueChanged(): void {\n for (const handle of this.#handles()) {\n if (handle.hasAttribute(PointerDragController.#TOUCH_ACTION_MARKER)) {\n handle.style.touchAction = this.#touchActionForAxis();\n }\n }\n }\n\n /** Cancels any in-flight session when the controller is disabled mid-drag. */\n disabledValueChanged(): void {\n if (!this.disabledValue) return;\n if (this.#pointer?.started || this.#keyboard) {\n this.#dispatchCancel(this.#keyboard ? \"keyboard\" : (this.#pointer?.pointerType ?? \"mouse\"));\n }\n this.#teardownSessions();\n }\n\n /** Arms a pointer drag on a handle; `start` waits for the threshold. */\n readonly #onPointerDown = (event: PointerEvent): void => {\n // One session at a time: ignore a second pointerdown (multi-touch, an\n // errant tap, a grabbed keyboard session) so an in-flight drag is never\n // silently overwritten and its captured pointer orphaned.\n if (this.disabledValue || this.#pointer || this.#keyboard || event.button !== 0) return;\n const handle = this.#handleFor(event.target);\n if (!handle) return;\n\n // Suppress text selection / native image drag; restore the focus the\n // suppressed default would have given, so Escape and the keyboard path\n // stay reachable right after a pointer interaction (WCAG 2.1.1).\n event.preventDefault();\n handle.focus();\n\n this.#pointer = {\n pointerId: event.pointerId,\n handle,\n originX: event.clientX,\n originY: event.clientY,\n started: false,\n dx: 0,\n dy: 0,\n pointerType: this.#pointerTypeOf(event),\n };\n\n // Pointer capture keeps fast drags delivering to the handle even when the\n // pointer strays outside it — but a consumer may re-insert the dragged\n // element mid-drag (sortable's live reorder), which silently releases the\n // capture. Tracking listeners therefore live on the DOCUMENT (captured\n // events bubble there; uncaptured ones fire there anyway), and the\n // AbortController releases them on drag end and disconnect() (Turbo included).\n handle.setPointerCapture(event.pointerId);\n this.#dragAbort?.abort();\n const abort = new AbortController();\n this.#dragAbort = abort;\n document.addEventListener(\"pointermove\", this.#onPointerMove, { signal: abort.signal });\n document.addEventListener(\"pointerup\", this.#onPointerUp, { signal: abort.signal });\n document.addEventListener(\"pointercancel\", this.#onPointerCancel, { signal: abort.signal });\n };\n\n readonly #onPointerMove = (event: PointerEvent): void => {\n const session = this.#pointer;\n if (!session || event.pointerId !== session.pointerId) return;\n\n const [dx, dy] = this.#filterAxis(\n event.clientX - session.originX,\n event.clientY - session.originY,\n );\n if (!session.started) {\n if (Math.hypot(dx, dy) < this.thresholdValue) return;\n session.started = true;\n this.element.setAttribute(\"data-dragging\", \"true\");\n this.dispatch(\"start\", {\n detail: { x: event.clientX, y: event.clientY, pointerType: session.pointerType },\n });\n }\n\n session.dx = dx;\n session.dy = dy;\n this.#followMove(dx, dy);\n this.dispatch(\"move\", {\n detail: { dx, dy, x: event.clientX, y: event.clientY, pointerType: session.pointerType },\n });\n };\n\n readonly #onPointerUp = (event: PointerEvent): void => {\n const session = this.#pointer;\n if (!session || event.pointerId !== session.pointerId) return;\n const { started, dx, dy, pointerType } = session;\n this.#endPointerSession();\n // Below the threshold the gesture was a plain click, not a drag: stay silent.\n if (!started) return;\n this.#followCommit(dx, dy);\n this.dispatch(\"end\", { detail: { dx, dy, pointerType } });\n };\n\n /** OS gesture / scroll takeover interrupted the drag: cancel, don't drop. */\n readonly #onPointerCancel = (event: PointerEvent): void => {\n const session = this.#pointer;\n if (!session || event.pointerId !== session.pointerId) return;\n const { started, pointerType } = session;\n this.#endPointerSession();\n if (started) this.#dispatchCancel(pointerType);\n };\n\n /** Keyboard alternative: Space/Enter grab & drop, arrows move, Escape cancels. */\n readonly #onKeydown = (event: KeyboardEvent): void => {\n if (this.disabledValue) return;\n const handle = this.#handleFor(event.target);\n if (!handle) return;\n\n // A descendant widget that already claimed the key (a nested roving list, a\n // segmented field inside the handle) must not ALSO drive the drag —\n // composition depends on this yield. This controller is the \"grabbed drag\n // handle\" that the other yields name as the widget they defer to, so it owes\n // the same courtesy downward.\n if (event.defaultPrevented) return;\n // A chorded arrow belongs to the browser. \"Someone already consumed it\"\n // outranks that, so it is checked after the yield above.\n if (isReservedArrowChord(event)) return;\n\n // Escape cancels whichever session is live (pointer drag or keyboard grab).\n if (event.key === \"Escape\") {\n // A press an inner handler already owned is yielded at the top of this\n // handler. What is checked here is the IME half: a press during a\n // composition steers the conversion, not the drag.\n if (event.isComposing) return;\n if (this.#pointer?.started) {\n const { pointerType } = this.#pointer;\n this.#teardownSessions();\n event.preventDefault();\n this.#dispatchCancel(pointerType);\n } else if (this.#keyboard) {\n this.#teardownSessions();\n event.preventDefault();\n this.#dispatchCancel(\"keyboard\");\n }\n return;\n }\n\n if (event.key === \" \" || event.key === \"Enter\") {\n // A live pointer drag owns the session: pressing Space mid-drag (the\n // pointerdown focused the handle) must not start a parallel grab.\n if (this.#pointer) return;\n event.preventDefault();\n if (this.#keyboard) this.#dropKeyboard();\n else this.#grabKeyboard(handle);\n return;\n }\n\n if (!this.#keyboard) return;\n const step = this.#keyboardDelta(event.key);\n if (!step) return;\n // Consume every arrow while grabbed (even on a locked axis) so the page\n // never scrolls mid-grab; only allowed-axis arrows emit a move.\n event.preventDefault();\n const [dx, dy] = this.#filterAxis(step[0], step[1]);\n if (dx === 0 && dy === 0) return;\n this.#keyboard.dx += dx;\n this.#keyboard.dy += dy;\n this.#followMove(this.#keyboard.dx, this.#keyboard.dy);\n this.dispatch(\"move\", {\n detail: {\n dx: this.#keyboard.dx,\n dy: this.#keyboard.dy,\n x: this.#keyboard.dx,\n y: this.#keyboard.dy,\n pointerType: \"keyboard\",\n },\n });\n };\n\n /** Enters the grabbed mode: `data-grabbed` on element + handle, then `start`. */\n #grabKeyboard(handle: HTMLElement): void {\n this.#keyboard = { handle, dx: 0, dy: 0 };\n this.element.setAttribute(\"data-grabbed\", \"true\");\n handle.setAttribute(\"data-grabbed\", \"true\");\n this.dispatch(\"start\", { detail: { x: 0, y: 0, pointerType: \"keyboard\" } });\n }\n\n #dropKeyboard(): void {\n const session = this.#keyboard;\n if (!session) return;\n this.#clearKeyboardSession();\n this.#followCommit(session.dx, session.dy);\n this.dispatch(\"end\", { detail: { dx: session.dx, dy: session.dy, pointerType: \"keyboard\" } });\n }\n\n /** Maps an arrow key to a raw (unfiltered) `keyboardStep` delta. */\n #keyboardDelta(key: string): [number, number] | null {\n const step = this.keyboardStepValue;\n switch (key) {\n case \"ArrowRight\":\n return [step, 0];\n case \"ArrowLeft\":\n return [-step, 0];\n case \"ArrowDown\":\n return [0, step];\n case \"ArrowUp\":\n return [0, -step];\n default:\n return null;\n }\n }\n\n /** Zeroes the delta on the locked axis (`axis` = x | y | both). */\n #filterAxis(dx: number, dy: number): [number, number] {\n if (this.axisValue === \"x\") return [dx, 0];\n if (this.axisValue === \"y\") return [0, dy];\n return [dx, dy];\n }\n\n /** Releases capture + listeners and clears the pointer session and its hook. */\n #endPointerSession(): void {\n this.#releasePointerCapture();\n this.#pointer = null;\n this.#dragAbort?.abort();\n this.#dragAbort = null;\n this.element.removeAttribute(\"data-dragging\");\n }\n\n /** Releases the pointer capture the active session set (idempotent, safe). */\n #releasePointerCapture(): void {\n const session = this.#pointer;\n if (session?.handle.hasPointerCapture(session.pointerId)) {\n session.handle.releasePointerCapture(session.pointerId);\n }\n }\n\n #clearKeyboardSession(): void {\n this.#keyboard?.handle.removeAttribute(\"data-grabbed\");\n this.#keyboard = null;\n this.element.removeAttribute(\"data-grabbed\");\n }\n\n /**\n * Full teardown for a controller whose element is going away or lost its\n * controller. Into a dead (detached) tree it is silent — consumers restore\n * from their own `connect()`, not from a cancel event. But a detach that\n * KEEPS the element (Turbo morph, `data-controller` removed) leaves the\n * consumers alive and listening: an in-flight session must end in `cancel`\n * there, or a composer like sortable strands its one-at-a-time session\n * bookkeeping forever.\n */\n #teardown(): void {\n // Disarm any probe still queued: without this, an immediate teardown\n // (element removed right after a deferring disconnect) would let the\n // orphaned probe run #teardown a second time — a double cancel.\n this.#gate.cancel();\n const interrupted = this.#pointer?.started\n ? this.#pointer.pointerType\n : this.#keyboard\n ? (\"keyboard\" as const)\n : null;\n this.#teardownSessions();\n for (const handle of this.#handles()) this.#restoreHandle(handle);\n if (interrupted && this.element.isConnected) this.#dispatchCancel(interrupted);\n }\n\n /**\n * Silently tears down whatever session is live (disconnect / disabled /\n * Escape). Composed from the two single-session teardowns so pointer and\n * keyboard cleanup cannot diverge as either path evolves.\n */\n #teardownSessions(): void {\n this.#endPointerSession();\n this.#clearKeyboardSession();\n }\n\n #dispatchCancel(pointerType: DragPointerType): void {\n // Every cancel path funnels here, so follow's snap-back can never be missed\n // (Escape, pointercancel, mid-session disable, detach-that-keeps-the-element).\n this.#followReset();\n this.dispatch(\"cancel\", { detail: { pointerType } });\n }\n\n /** Applies the in-flight offset to the element's `translate` (follow only). */\n #followMove(dx: number, dy: number): void {\n if (!this.followValue) return;\n this.#applyFollow(this.#followBase.x + dx, this.#followBase.y + dy);\n }\n\n /** Folds a drop's deltas into the committed base offset (follow only). */\n #followCommit(dx: number, dy: number): void {\n if (!this.followValue) return;\n this.#followBase = { x: this.#followBase.x + dx, y: this.#followBase.y + dy };\n this.#applyFollow(this.#followBase.x, this.#followBase.y);\n }\n\n /** Snaps back to the committed position (follow only) — the cancel contract. */\n #followReset(): void {\n if (!this.followValue) return;\n this.#applyFollow(this.#followBase.x, this.#followBase.y);\n }\n\n /**\n * Writes the offset as the standalone CSS `translate` property — independent\n * of `transform`, so an authored transform (scale, rotate…) is never\n * clobbered. At the origin the property is removed to keep the DOM clean.\n */\n #applyFollow(x: number, y: number): void {\n if (x === 0 && y === 0) this.element.style.removeProperty(\"translate\");\n else this.element.style.setProperty(\"translate\", `${x}px ${y}px`);\n }\n\n /**\n * Reads a committed follow offset back from the inline `translate`. Only the\n * controller's own `<x>px <y>px` shape is recognized; anything else (an\n * authored percentage, `none`, an empty string) starts the base at 0 — follow\n * mode owns this property, per the class contract.\n */\n #parseFollowBase(): { x: number; y: number } {\n const raw = this.element.style.getPropertyValue(\"translate\").trim();\n const match = /^(-?\\d+(?:\\.\\d+)?)px(?:\\s+(-?\\d+(?:\\.\\d+)?)px)?$/.exec(raw);\n if (!match) return { x: 0, y: 0 };\n return { x: Number(match[1]), y: Number(match[2] ?? \"0\") };\n }\n\n /** The active handles: the `handle` targets, else the element itself. */\n #handles(): HTMLElement[] {\n return this.hasHandleTarget ? this.handleTargets : [this.element];\n }\n\n /** Resolves the handle owning an event target (the handle or a descendant). */\n #handleFor(target: EventTarget | null): HTMLElement | null {\n const node = target as Node | null;\n if (!node) return null;\n return this.#handles().find((handle) => handle === node || handle.contains(node)) ?? null;\n }\n\n #pointerTypeOf(event: PointerEvent): DragPointerType {\n const type = event.pointerType;\n if (type === \"touch\" || type === \"pen\") return type;\n return \"mouse\";\n }\n\n /** `touch-action` that lets the page keep panning on the locked axis only. */\n #touchActionForAxis(): string {\n if (this.axisValue === \"x\") return \"pan-y\";\n if (this.axisValue === \"y\") return \"pan-x\";\n return \"none\";\n }\n\n /**\n * Establishes the handle contract: a `touch-action` derived from `axis`\n * (marker-guarded so an authored inline value wins and reconnects stay\n * idempotent) and focusability for the keyboard path (`tabindex=\"0\"` only when\n * the author supplied none — prefer a real `<button>` handle). Both additions\n * are marker-owned so `#restoreHandle` reverts them symmetrically on teardown.\n */\n #prepareHandle(handle: HTMLElement): void {\n if (\n handle.style.touchAction === \"\" ||\n handle.hasAttribute(PointerDragController.#TOUCH_ACTION_MARKER)\n ) {\n handle.style.touchAction = this.#touchActionForAxis();\n handle.setAttribute(PointerDragController.#TOUCH_ACTION_MARKER, \"true\");\n }\n if (handle.tabIndex < 0 && !handle.hasAttribute(\"tabindex\")) {\n handle.setAttribute(\"tabindex\", \"0\");\n handle.setAttribute(PointerDragController.#TABINDEX_MARKER, \"true\");\n }\n }\n\n /** Reverts the marker-owned touch-action + tabindex (authored values untouched). */\n #restoreHandle(handle: HTMLElement): void {\n if (handle.hasAttribute(PointerDragController.#TOUCH_ACTION_MARKER)) {\n handle.style.touchAction = \"\";\n handle.removeAttribute(PointerDragController.#TOUCH_ACTION_MARKER);\n }\n if (handle.hasAttribute(PointerDragController.#TABINDEX_MARKER)) {\n handle.removeAttribute(PointerDragController.#TABINDEX_MARKER);\n // Only remove what is verifiably still ours and safe to remove: another\n // owner (e.g. a roving list) may have rewritten the value since, and\n // stripping tabindex off the focused element would blur it to <body>\n // (losing the user's place — worse than leaking one tab stop).\n if (handle.getAttribute(\"tabindex\") === \"0\" && document.activeElement !== handle) {\n handle.removeAttribute(\"tabindex\");\n }\n }\n }\n}\n"]}
|
|
@@ -6,6 +6,16 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
6
6
|
var DetachGate = class _DetachGate {
|
|
7
7
|
/** Set while a probe is queued, waiting for a reconnect to cancel it. */
|
|
8
8
|
#pending = false;
|
|
9
|
+
/**
|
|
10
|
+
* True while a probe is queued — the last disconnect was ambiguous and no
|
|
11
|
+
* reconnect has cancelled it yet. Read it from `connect()` to tell the
|
|
12
|
+
* reconnect half of an in-page move from a first connect: a controller whose
|
|
13
|
+
* initialisation restarts a measurement (a min-duration floor, an elapsed
|
|
14
|
+
* counter) must skip it for the move, where nothing actually restarted.
|
|
15
|
+
*/
|
|
16
|
+
get pending() {
|
|
17
|
+
return this.#pending;
|
|
18
|
+
}
|
|
9
19
|
/**
|
|
10
20
|
* True when the disconnect is definitely a real detach — the element left
|
|
11
21
|
* the document, or `data-controller` no longer lists the identifier. False
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/detach_gate.ts","../../src/controllers/portal_controller.ts"],"names":[],"mappings":";;;;;AA4EO,IAAM,UAAA,GAAN,MAAM,WAAA,CAAW;AAAA;AAAA,EAEtB,QAAA,GAAW,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOX,OAAO,WAAW,IAAA,EAA+B;AAC/C,IAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,WAAA,EAAa,OAAO,IAAA;AACtC,IAAA,MAAM,MAAA,GAAA,CAAU,KAAK,OAAA,CAAQ,YAAA,CAAa,iBAAiB,CAAA,IAAK,EAAA,EAAI,MAAM,KAAK,CAAA;AAC/E,IAAA,OAAO,CAAC,MAAA,CAAO,QAAA,CAAS,IAAA,CAAK,UAAU,CAAA;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,YAAA,CAAa,MAAsB,QAAA,EAA4B;AAC7D,IAAA,IAAI,WAAA,CAAW,UAAA,CAAW,IAAI,CAAA,EAAG;AAG/B,MAAA,IAAA,CAAK,QAAA,GAAW,KAAA;AAChB,MAAA,QAAA,EAAS;AACT,MAAA;AAAA,IACF;AACA,IAAA,IAAA,CAAK,QAAA,GAAW,IAAA;AAChB,IAAA,cAAA,CAAe,MAAM;AACnB,MAAA,IAAI,CAAC,KAAK,QAAA,EAAU;AACpB,MAAA,IAAA,CAAK,QAAA,GAAW,KAAA;AAChB,MAAA,QAAA,EAAS;AAAA,IACX,CAAC,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAA,GAAe;AACb,IAAA,IAAA,CAAK,QAAA,GAAW,KAAA;AAAA,EAClB;AACF,CAAA;;;AClHA,IAAM,WAAA,uBAAkB,O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AACnB,IAAA,IAAA,CAAK,SAAS,SAAA,EAAW,EAAE,MAAA,EAAQ,IAAI,CAAA;AAAA,EACzC;AAAA;AAAA,EAGA,YAAA,GAA+B;AAC7B,IAAA,MAAM,QAAA,GAAW,IAAA,CAAK,OAAA,CAAQ,IAAA,EAAK;AACnC,IAAA,IAAI,CAAC,UAAU,OAAO,IAAA;AACtB,IAAA,IAAI;AACF,MAAA,OAAO,QAAA,CAAS,cAAc,QAAQ,CAAA;AAAA,IACxC,CAAA,CAAA,MAAQ;AACN,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AACF","file":"portal_controller.js","sourcesContent":["/**\n * Shared \"in-page move vs real detach\" discriminator for `disconnect()`.\n *\n * A mid-session `disconnect()` whose element is still in the document is\n * ambiguous. It can be:\n *\n * - an **in-page move** — a consumer (sortable, a teleport) re-inserted the\n * element; Stimulus reconnects the SAME instance in the same mutation batch\n * and the controller's runtime state must survive;\n * - a **detach that keeps the element** — `data-controller` no longer lists the\n * identifier (a Turbo 8 morph), or the element moved outside the observed\n * root (a scoped `Application.start(root)`, a shadow root); no reconnect will\n * ever come and the controller must tear down or it leaks its sessions,\n * document listeners, and moved nodes.\n *\n * Neither available signal decides this alone. A synchronous `data-controller`\n * token check catches the morph case but misses an observed-root exit (the\n * token stays, the reconnect never comes). Deferring teardown one microtask and\n * letting `connect()` cancel it catches the root exit, but leans on Stimulus\n * reconnecting moved elements within the same mutation batch — internal\n * behavior, not a public contract. {@link DetachGate} composes both: the token\n * check is the synchronous fast path (no probe, no reliance on batching), the\n * microtask probe is the fallback for the genuinely ambiguous remainder.\n *\n * Policy stays with the consumer (the `SafeTimeout` / `FocusTrap` lineage —\n * this util owns the discrimination only):\n *\n * - **Probe** ({@link disconnected}) when the teardown must eventually happen —\n * live drag sessions, document listeners, teleported *content*. Call\n * {@link cancel} from `connect()` (a reconnect means in-page move) and from\n * the head of any direct teardown path (see below).\n * - **Keep** (bare {@link DetachGate.isDetached}) when undoing the ambiguous\n * case would fight the controller's own effect: a controller that moves its\n * OWN element (portal's no-`content` form) exits a scoped observed root as\n * its normal job — a probe-driven teardown would restore the element into\n * the root, reconnect, re-teleport, and disconnect again, forever. Such\n * controllers keep their state on an ambiguous disconnect and tear down only\n * on {@link DetachGate.isDetached}.\n *\n * Event convention for probe consumers: teardown into a dead (detached) tree is\n * silent — consumers restore from their own `connect()`; a detach that keeps the\n * tree alive must end an in-flight session with a `cancel` event, or composing\n * consumers strand their session bookkeeping.\n */\n\n/** The slice of a Stimulus controller the gate inspects. */\nexport interface DetachGateHost {\n readonly element: Element;\n readonly identifier: string;\n}\n\n/**\n * Per-controller-instance gate deciding whether a `disconnect()` is a real\n * detach. Hold one per controller (`#gate = new DetachGate()`) — Stimulus\n * reuses the instance across reconnects, so the pending probe state carries\n * over exactly as the protocol needs.\n *\n * @example\n * ```ts\n * #gate = new DetachGate();\n *\n * connect(): void {\n * this.#gate.cancel(); // a reconnect: the element moved in-page\n * // …\n * }\n *\n * disconnect(): void {\n * this.#gate.disconnected(this, () => this.#teardown());\n * }\n *\n * #teardown(): void {\n * this.#gate.cancel(); // disarm a still-queued probe (double-run guard)\n * // …\n * }\n * ```\n */\nexport class DetachGate {\n /** Set while a probe is queued, waiting for a reconnect to cancel it. */\n #pending = false;\n\n /**\n * True when the disconnect is definitely a real detach — the element left\n * the document, or `data-controller` no longer lists the identifier. False\n * means ambiguous (in-page move or observed-root exit), NOT \"alive\".\n */\n static isDetached(host: DetachGateHost): boolean {\n if (!host.element.isConnected) return true;\n const tokens = (host.element.getAttribute(\"data-controller\") ?? \"\").split(/\\s+/);\n return !tokens.includes(host.identifier);\n }\n\n /**\n * Call from `disconnect()`: runs `teardown` synchronously on a definite\n * detach (fast path), otherwise defers it one microtask — a reconnect\n * ({@link cancel} from `connect()`) keeps the state, no reconnect runs it.\n * One microtask is the whole probe window: Stimulus reconnects a moved\n * element within the same mutation batch, before the checkpoint drains.\n */\n disconnected(host: DetachGateHost, teardown: () => void): void {\n if (DetachGate.isDetached(host)) {\n // Also disarms a probe a previous ambiguous disconnect left queued\n // (defer, element removed, disconnect again) — exactly one teardown.\n this.#pending = false;\n teardown();\n return;\n }\n this.#pending = true;\n queueMicrotask(() => {\n if (!this.#pending) return;\n this.#pending = false;\n teardown();\n });\n }\n\n /**\n * Disarms a pending probe. Call from `connect()` (the reconnect that proves\n * an in-page move) and from the head of any teardown path not routed through\n * {@link disconnected} (disabled-toggle, Escape), so an orphaned probe can\n * never run the teardown a second time.\n */\n cancel(): void {\n this.#pending = false;\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { DetachGate } from \"../utils/detach_gate\";\n\n/**\n * Teleport bookkeeping keyed by the controller element (stable across the\n * connect/disconnect churn some DOM runtimes emit when an observed element is moved).\n * Holds the moved node and its placeholder so any controller instance for that element\n * can finish the teardown.\n */\nconst portalState = new WeakMap<Element, { node: HTMLElement; placeholder: Comment }>();\n\n/**\n * Headless **portal / teleport**: moves an element to another place in the DOM (e.g.\n * directly under `body`) on connect and cleans up on disconnect — the shared substrate\n * for overlays that must escape an ancestor's `overflow: hidden`, `transform`, or\n * stacking context (no APG pattern; a DOM utility). Counterpart to Radix `Portal` /\n * Alpine `x-teleport`.\n *\n * Markup contract (identifier: `stimeo--portal`):\n * <div data-controller=\"stimeo--portal\" data-stimeo--portal-to-value=\"body\">\n * <div data-stimeo--portal-target=\"content\">Teleported content</div>\n * </div>\n *\n * Moves `content` (or `this.element` when no `content` target) into the first element\n * matching `to` (default `body`), `append`ed or `prepend`ed per `position`. A comment\n * placeholder records the original spot so `disconnect()` can return the node there\n * (when `restore`) — or remove it — leaving no orphan behind. The moved node carries\n * `data-portaled`.\n *\n * @remarks\n * Behavior only — no positioning (pair with `stimeo-ui/positioning`) and no focus\n * trapping (pair with a Focus Scope / the overlay). Moving a Stimulus element within\n * the same document does not re-fire connect/disconnect, so the move is safe. For Turbo\n * compatibility prefer the `content`-target form: the controller then stays on the\n * in-place source, so its `disconnect()` fires when the original container is replaced\n * and the teleported node is restored/removed rather than orphaned under `body`. The\n * move is idempotent (guarded by the placeholder) and reversed on `disconnect()` (Turbo\n * navigation included). The \"in-page move vs real detach\" split on `disconnect()` is\n * {@link DetachGate}; in the `content` form the source element may even leave a\n * scoped application's observed root and the content is still restored, while the\n * no-`content` form teleporting itself out of the observed root is fire-and-forget\n * by design (see `disconnect()`).\n */\nexport class PortalController extends Controller<HTMLElement> {\n static override targets = [\"content\"];\n static override values = {\n to: { type: String, default: \"body\" },\n position: { type: String, default: \"append\" },\n restore: { type: Boolean, default: true },\n };\n static events = [\"mount\", \"unmount\"] as const;\n\n declare readonly contentTarget: HTMLElement;\n declare readonly hasContentTarget: boolean;\n\n declare toValue: string;\n declare positionValue: string;\n declare restoreValue: boolean;\n\n /** Decides whether a `disconnect()` is an in-page move or a real detach. */\n readonly #gate = new DetachGate();\n\n override connect(): void {\n // A reconnect proves an in-page move of the source element: disarm the\n // probe the mid-move disconnect() deferred (see disconnect).\n this.#gate.cancel();\n if (portalState.has(this.element)) return; // already portaled here (idempotent)\n const node = this.hasContentTarget ? this.contentTarget : this.element;\n const destination = this.#destination();\n if (!destination || destination === node || node.contains(destination)) return;\n\n const placeholder = document.createComment(\"stimeo--portal\");\n node.parentNode?.insertBefore(placeholder, node);\n portalState.set(this.element, { node, placeholder });\n\n if (this.positionValue === \"prepend\") {\n destination.prepend(node);\n } else {\n destination.appendChild(node);\n }\n node.setAttribute(\"data-portaled\", \"true\");\n this.dispatch(\"mount\", { detail: { target: destination } });\n }\n\n override disconnect(): void {\n const state = portalState.get(this.element);\n if (!state) return;\n if (state.node === this.element) {\n // No-`content` form: the teleported node IS the controller element, so the\n // teleport itself may exit a scoped application's observed root — the controller\n // doing its job, not a detach. A probe-driven restore would re-enter the root,\n // reconnect, re-teleport and disconnect again, forever. So an ambiguous\n // disconnect (in the document, identifier still listed — also the churn a\n // self-move emits in some runtimes) KEEPS the teleport, and only a definite\n // detach — the element left the DOM, or `data-controller` no longer lists us\n // (a Turbo 8 morph) — restores. The cost, by design: a teleport that left the\n // observed root is fire-and-forget (Stimulus never fires for it again).\n if (!DetachGate.isDetached(this)) return;\n this.#restore(state);\n return;\n }\n // `content` form: the controller element stays put, so its own teleport emits no\n // churn — an ambiguous disconnect means the SOURCE element moved. In-page, the\n // same-batch reconnect cancels the probe and the teleport survives; out of the\n // observed root, no reconnect comes and the probe restores, so the content is\n // never stranded at the destination with a dead owner.\n this.#gate.disconnected(this, () => {\n const current = portalState.get(this.element);\n if (current) this.#restore(current);\n });\n }\n\n /** Returns the node to its placeholder (or removes it) and clears the bookkeeping. */\n #restore(state: { node: HTMLElement; placeholder: Comment }): void {\n portalState.delete(this.element);\n const { node, placeholder } = state;\n\n node.removeAttribute(\"data-portaled\");\n if (this.restoreValue && placeholder.parentNode) {\n placeholder.parentNode.insertBefore(node, placeholder);\n } else {\n node.remove();\n }\n placeholder.remove();\n this.dispatch(\"unmount\", { detail: {} });\n }\n\n /** Resolves the destination for `to`, tolerating an invalid selector. */\n #destination(): Element | null {\n const selector = this.toValue.trim();\n if (!selector) return null;\n try {\n return document.querySelector(selector);\n } catch {\n return null;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/detach_gate.ts","../../src/controllers/portal_controller.ts"],"names":[],"mappings":";;;;;AA4EO,IAAM,UAAA,GAAN,MAAM,WAAA,CAAW;AAAA;AAAA,EAEtB,QAAA,GAAW,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASX,IAAI,OAAA,GAAmB;AACrB,IAAA,OAAO,IAAA,CAAK,QAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,WAAW,IAAA,EAA+B;AAC/C,IAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,WAAA,EAAa,OAAO,IAAA;AACtC,IAAA,MAAM,MAAA,GAAA,CAAU,KAAK,OAAA,CAAQ,YAAA,CAAa,iBAAiB,CAAA,IAAK,EAAA,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AACnB,MAAA;AAAA,IACF;AAMA,IAAA,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,IAAA,EAAM,MAAM;AAClC,MAAA,MAAM,OAAA,GAAU,WAAA,CAAY,GAAA,CAAI,IAAA,CAAK,OAAO,CAAA;AAC5C,MAAA,IAAI,OAAA,EAAS,IAAA,CAAK,QAAA,CAAS,OAAO,CAAA;AAAA,IACpC,CAAC,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,SAAS,KAAA,EAA0D;AACjE,IAAA,WAAA,CAAY,MAAA,CAAO,KAAK,OAAO,CAAA;AAC/B,IAAA,MAAM,EAAE,IAAA,EAAM,WAAA,EAAY,GAAI,KAAA;AAE9B,IAAA,IAAA,CAAK,gBAAgB,eAAe,CAAA;AACpC,IAAA,IAAI,IAAA,CAAK,YAAA,IAAgB,WAAA,CAAY,UAAA,EAAY;AAC/C,MAAA,WAAA,CAAY,UAAA,CAAW,YAAA,CAAa,IAAA,EAAM,WAAW,CAAA;AAAA,IACvD,CAAA,MAAO;AACL,MAAA,IAAA,CAAK,MAAA,EAAO;AAAA,IACd;AACA,IAAA,WAAA,CAAY,MAAA,EAAO;AACnB,IAAA,IAAA,CAAK,SAAS,SAAA,EAAW,EAAE,MAAA,EAAQ,IAAI,CAAA;AAAA,EACzC;AAAA;AAAA,EAGA,YAAA,GAA+B;AAC7B,IAAA,MAAM,QAAA,GAAW,IAAA,CAAK,OAAA,CAAQ,IAAA,EAAK;AACnC,IAAA,IAAI,CAAC,UAAU,OAAO,IAAA;AACtB,IAAA,IAAI;AACF,MAAA,OAAO,QAAA,CAAS,cAAc,QAAQ,CAAA;AAAA,IACxC,CAAA,CAAA,MAAQ;AACN,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AACF","file":"portal_controller.js","sourcesContent":["/**\n * Shared \"in-page move vs real detach\" discriminator for `disconnect()`.\n *\n * A mid-session `disconnect()` whose element is still in the document is\n * ambiguous. It can be:\n *\n * - an **in-page move** — a consumer (sortable, a teleport) re-inserted the\n * element; Stimulus reconnects the SAME instance in the same mutation batch\n * and the controller's runtime state must survive;\n * - a **detach that keeps the element** — `data-controller` no longer lists the\n * identifier (a Turbo 8 morph), or the element moved outside the observed\n * root (a scoped `Application.start(root)`, a shadow root); no reconnect will\n * ever come and the controller must tear down or it leaks its sessions,\n * document listeners, and moved nodes.\n *\n * Neither available signal decides this alone. A synchronous `data-controller`\n * token check catches the morph case but misses an observed-root exit (the\n * token stays, the reconnect never comes). Deferring teardown one microtask and\n * letting `connect()` cancel it catches the root exit, but leans on Stimulus\n * reconnecting moved elements within the same mutation batch — internal\n * behavior, not a public contract. {@link DetachGate} composes both: the token\n * check is the synchronous fast path (no probe, no reliance on batching), the\n * microtask probe is the fallback for the genuinely ambiguous remainder.\n *\n * Policy stays with the consumer (the `SafeTimeout` / `FocusTrap` lineage —\n * this util owns the discrimination only):\n *\n * - **Probe** ({@link disconnected}) when the teardown must eventually happen —\n * live drag sessions, document listeners, teleported *content*. Call\n * {@link cancel} from `connect()` (a reconnect means in-page move) and from\n * the head of any direct teardown path (see below).\n * - **Keep** (bare {@link DetachGate.isDetached}) when undoing the ambiguous\n * case would fight the controller's own effect: a controller that moves its\n * OWN element (portal's no-`content` form) exits a scoped observed root as\n * its normal job — a probe-driven teardown would restore the element into\n * the root, reconnect, re-teleport, and disconnect again, forever. Such\n * controllers keep their state on an ambiguous disconnect and tear down only\n * on {@link DetachGate.isDetached}.\n *\n * Event convention for probe consumers: teardown into a dead (detached) tree is\n * silent — consumers restore from their own `connect()`; a detach that keeps the\n * tree alive must end an in-flight session with a `cancel` event, or composing\n * consumers strand their session bookkeeping.\n */\n\n/** The slice of a Stimulus controller the gate inspects. */\nexport interface DetachGateHost {\n readonly element: Element;\n readonly identifier: string;\n}\n\n/**\n * Per-controller-instance gate deciding whether a `disconnect()` is a real\n * detach. Hold one per controller (`#gate = new DetachGate()`) — Stimulus\n * reuses the instance across reconnects, so the pending probe state carries\n * over exactly as the protocol needs.\n *\n * @example\n * ```ts\n * #gate = new DetachGate();\n *\n * connect(): void {\n * this.#gate.cancel(); // a reconnect: the element moved in-page\n * // …\n * }\n *\n * disconnect(): void {\n * this.#gate.disconnected(this, () => this.#teardown());\n * }\n *\n * #teardown(): void {\n * this.#gate.cancel(); // disarm a still-queued probe (double-run guard)\n * // …\n * }\n * ```\n */\nexport class DetachGate {\n /** Set while a probe is queued, waiting for a reconnect to cancel it. */\n #pending = false;\n\n /**\n * True while a probe is queued — the last disconnect was ambiguous and no\n * reconnect has cancelled it yet. Read it from `connect()` to tell the\n * reconnect half of an in-page move from a first connect: a controller whose\n * initialisation restarts a measurement (a min-duration floor, an elapsed\n * counter) must skip it for the move, where nothing actually restarted.\n */\n get pending(): boolean {\n return this.#pending;\n }\n\n /**\n * True when the disconnect is definitely a real detach — the element left\n * the document, or `data-controller` no longer lists the identifier. False\n * means ambiguous (in-page move or observed-root exit), NOT \"alive\".\n */\n static isDetached(host: DetachGateHost): boolean {\n if (!host.element.isConnected) return true;\n const tokens = (host.element.getAttribute(\"data-controller\") ?? \"\").split(/\\s+/);\n return !tokens.includes(host.identifier);\n }\n\n /**\n * Call from `disconnect()`: runs `teardown` synchronously on a definite\n * detach (fast path), otherwise defers it one microtask — a reconnect\n * ({@link cancel} from `connect()`) keeps the state, no reconnect runs it.\n * One microtask is the whole probe window: Stimulus reconnects a moved\n * element within the same mutation batch, before the checkpoint drains.\n */\n disconnected(host: DetachGateHost, teardown: () => void): void {\n if (DetachGate.isDetached(host)) {\n // Also disarms a probe a previous ambiguous disconnect left queued\n // (defer, element removed, disconnect again) — exactly one teardown.\n this.#pending = false;\n teardown();\n return;\n }\n this.#pending = true;\n queueMicrotask(() => {\n if (!this.#pending) return;\n this.#pending = false;\n teardown();\n });\n }\n\n /**\n * Disarms a pending probe. Call from `connect()` (the reconnect that proves\n * an in-page move) and from the head of any teardown path not routed through\n * {@link disconnected} (disabled-toggle, Escape), so an orphaned probe can\n * never run the teardown a second time.\n */\n cancel(): void {\n this.#pending = false;\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { DetachGate } from \"../utils/detach_gate\";\n\n/**\n * Teleport bookkeeping keyed by the controller element (stable across the\n * connect/disconnect churn some DOM runtimes emit when an observed element is moved).\n * Holds the moved node and its placeholder so any controller instance for that element\n * can finish the teardown.\n */\nconst portalState = new WeakMap<Element, { node: HTMLElement; placeholder: Comment }>();\n\n/**\n * Headless **portal / teleport**: moves an element to another place in the DOM (e.g.\n * directly under `body`) on connect and cleans up on disconnect — the shared substrate\n * for overlays that must escape an ancestor's `overflow: hidden`, `transform`, or\n * stacking context (no APG pattern; a DOM utility). Counterpart to Radix `Portal` /\n * Alpine `x-teleport`.\n *\n * Markup contract (identifier: `stimeo--portal`):\n * <div data-controller=\"stimeo--portal\" data-stimeo--portal-to-value=\"body\">\n * <div data-stimeo--portal-target=\"content\">Teleported content</div>\n * </div>\n *\n * Moves `content` (or `this.element` when no `content` target) into the first element\n * matching `to` (default `body`), `append`ed or `prepend`ed per `position`. A comment\n * placeholder records the original spot so `disconnect()` can return the node there\n * (when `restore`) — or remove it — leaving no orphan behind. The moved node carries\n * `data-portaled`.\n *\n * @remarks\n * Behavior only — no positioning (pair with `stimeo-ui/positioning`) and no focus\n * trapping (pair with a Focus Scope / the overlay). Moving a Stimulus element within\n * the same document does not re-fire connect/disconnect, so the move is safe. For Turbo\n * compatibility prefer the `content`-target form: the controller then stays on the\n * in-place source, so its `disconnect()` fires when the original container is replaced\n * and the teleported node is restored/removed rather than orphaned under `body`. The\n * move is idempotent (guarded by the placeholder) and reversed on `disconnect()` (Turbo\n * navigation included). The \"in-page move vs real detach\" split on `disconnect()` is\n * {@link DetachGate}; in the `content` form the source element may even leave a\n * scoped application's observed root and the content is still restored, while the\n * no-`content` form teleporting itself out of the observed root is fire-and-forget\n * by design (see `disconnect()`).\n */\nexport class PortalController extends Controller<HTMLElement> {\n static override targets = [\"content\"];\n static override values = {\n to: { type: String, default: \"body\" },\n position: { type: String, default: \"append\" },\n restore: { type: Boolean, default: true },\n };\n static events = [\"mount\", \"unmount\"] as const;\n\n declare readonly contentTarget: HTMLElement;\n declare readonly hasContentTarget: boolean;\n\n declare toValue: string;\n declare positionValue: string;\n declare restoreValue: boolean;\n\n /** Decides whether a `disconnect()` is an in-page move or a real detach. */\n readonly #gate = new DetachGate();\n\n override connect(): void {\n // A reconnect proves an in-page move of the source element: disarm the\n // probe the mid-move disconnect() deferred (see disconnect).\n this.#gate.cancel();\n if (portalState.has(this.element)) return; // already portaled here (idempotent)\n const node = this.hasContentTarget ? this.contentTarget : this.element;\n const destination = this.#destination();\n if (!destination || destination === node || node.contains(destination)) return;\n\n const placeholder = document.createComment(\"stimeo--portal\");\n node.parentNode?.insertBefore(placeholder, node);\n portalState.set(this.element, { node, placeholder });\n\n if (this.positionValue === \"prepend\") {\n destination.prepend(node);\n } else {\n destination.appendChild(node);\n }\n node.setAttribute(\"data-portaled\", \"true\");\n this.dispatch(\"mount\", { detail: { target: destination } });\n }\n\n override disconnect(): void {\n const state = portalState.get(this.element);\n if (!state) return;\n if (state.node === this.element) {\n // No-`content` form: the teleported node IS the controller element, so the\n // teleport itself may exit a scoped application's observed root — the controller\n // doing its job, not a detach. A probe-driven restore would re-enter the root,\n // reconnect, re-teleport and disconnect again, forever. So an ambiguous\n // disconnect (in the document, identifier still listed — also the churn a\n // self-move emits in some runtimes) KEEPS the teleport, and only a definite\n // detach — the element left the DOM, or `data-controller` no longer lists us\n // (a Turbo 8 morph) — restores. The cost, by design: a teleport that left the\n // observed root is fire-and-forget (Stimulus never fires for it again).\n if (!DetachGate.isDetached(this)) return;\n this.#restore(state);\n return;\n }\n // `content` form: the controller element stays put, so its own teleport emits no\n // churn — an ambiguous disconnect means the SOURCE element moved. In-page, the\n // same-batch reconnect cancels the probe and the teleport survives; out of the\n // observed root, no reconnect comes and the probe restores, so the content is\n // never stranded at the destination with a dead owner.\n this.#gate.disconnected(this, () => {\n const current = portalState.get(this.element);\n if (current) this.#restore(current);\n });\n }\n\n /** Returns the node to its placeholder (or removes it) and clears the bookkeeping. */\n #restore(state: { node: HTMLElement; placeholder: Comment }): void {\n portalState.delete(this.element);\n const { node, placeholder } = state;\n\n node.removeAttribute(\"data-portaled\");\n if (this.restoreValue && placeholder.parentNode) {\n placeholder.parentNode.insertBefore(node, placeholder);\n } else {\n node.remove();\n }\n placeholder.remove();\n this.dispatch(\"unmount\", { detail: {} });\n }\n\n /** Resolves the destination for `to`, tolerating an invalid selector. */\n #destination(): Element | null {\n const selector = this.toValue.trim();\n if (!selector) return null;\n try {\n return document.querySelector(selector);\n } catch {\n return null;\n }\n }\n}\n"]}
|
|
@@ -29,7 +29,7 @@ type SetValueEvent = Event & {
|
|
|
29
29
|
* deliberately distinct from {@link MeterController}'s point-in-time `meter`. The
|
|
30
30
|
* controller owns value normalization and ARIA value-attribute synchronization;
|
|
31
31
|
* the bar's width/animation is the consumer's, driven off the
|
|
32
|
-
* `--stimeo
|
|
32
|
+
* `--stimeo--progress-ratio` (0–1) custom property and `data-state`.
|
|
33
33
|
*
|
|
34
34
|
* @remarks
|
|
35
35
|
* Behavior only — no styling is emitted. An indeterminate bar drops
|
|
@@ -153,20 +153,24 @@ var ProgressController = class extends Controller {
|
|
|
153
153
|
get #ratio() {
|
|
154
154
|
return rangeFraction(this.valueValue, this.minValue, this.maxValue);
|
|
155
155
|
}
|
|
156
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* Reflects value/range/indeterminate onto ARIA, `data-state`, and the ratio.
|
|
158
|
+
*
|
|
159
|
+
* @stimeoRenderRoot
|
|
160
|
+
*/
|
|
157
161
|
#render() {
|
|
158
162
|
this.element.setAttribute("aria-valuemin", String(this.minValue));
|
|
159
163
|
this.element.setAttribute("aria-valuemax", String(this.maxValue));
|
|
160
164
|
if (this.indeterminateValue) {
|
|
161
165
|
this.element.removeAttribute("aria-valuenow");
|
|
162
166
|
this.#clearOwnValueText();
|
|
163
|
-
this.element.style.removeProperty("--stimeo
|
|
167
|
+
this.element.style.removeProperty("--stimeo--progress-ratio");
|
|
164
168
|
this.element.setAttribute("data-state", "indeterminate");
|
|
165
169
|
return;
|
|
166
170
|
}
|
|
167
171
|
const value = this.#clamp(this.valueValue);
|
|
168
172
|
this.element.setAttribute("aria-valuenow", String(value));
|
|
169
|
-
this.element.style.setProperty("--stimeo
|
|
173
|
+
this.element.style.setProperty("--stimeo--progress-ratio", String(this.#ratio));
|
|
170
174
|
this.element.setAttribute("data-state", "determinate");
|
|
171
175
|
this.#applyValueText(value);
|
|
172
176
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/announce.ts","../../src/utils/coerce.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/range.ts","../../src/controllers/progress_controller.ts"],"names":[],"mappings":";;;;;AAoBO,SAAS,QAAA,CAAS,OAAA,EAAiB,OAAA,GAAmC,EAAC,EAAS;AACrF,EAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,EAAK;AAC1B,EAAA,IAAI,IAAA,CAAK,WAAW,CAAA,EAAG;AACvB,EAAA,MAAA,CAAO,aAAA;AAAA,IACL,IAAI,YAAY,4BAAA,EAA8B;AAAA,MAC5C,QAAQ,EAAE,OAAA,EAAS,MAAM,SAAA,EAAW,OAAA,CAAQ,cAAc,IAAA;AAAK,KAChE;AAAA,GACH;AACF;AAUO,SAAS,YAAA,CAAa,UAAkB,MAAA,EAAiD;AAC9F,EAAA,OAAO,QAAA,CAAS,OAAA,CAAQ,6BAAA,EAA+B,CAAC,OAAO,IAAA,KAAiB;AAC9E,IAAA,MAAM,WAAA,GAAc,OAAO,IAAI,CAAA;AAC/B,IAAA,OAAO,WAAA,KAAgB,MAAA,GAAY,KAAA,GAAQ,MAAA,CAAO,WAAW,CAAA;AAAA,EAC/D,CAAC,CAAA;AACH;;;AC5BO,SAAS,eAAe,GAAA,EAAwD;AACrF,EAAA,IAAI,QAAQ,IAAA,IAAQ,GAAA,KAAQ,MAAA,IAAa,GAAA,KAAQ,IAA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AA,CAAQ,YAAA,CAAa,gBAAA,EAAkB,EAAE,CAAA;AAAA,EAChD;AAAA;AAAA,EAGA,kBAAA,GAA2B;AACzB,IAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,gBAAgB,CAAA,EAAG;AAClD,IAAA,IAAA,CAAK,OAAA,CAAQ,gBAAgB,gBAAgB,CAAA;AAC7C,IAAA,IAAA,CAAK,OAAA,CAAQ,gBAAgB,gBAAgB,CAAA;AAAA,EAC/C;AACF","file":"progress_controller.js","sourcesContent":["/**\n * Sends one message to the page's shared `stimeo--announcer`.\n *\n * A component that has to reach assistive tech does not carry a live region of its\n * own: a region only announces what changes *after* assistive tech already knows\n * about it, which a region that appears (or is un-hidden) with its message cannot\n * satisfy. The one region that can is the announcer sitting in the page from the\n * start, so state changes are handed to it as an event and it does the reading.\n *\n * The event goes to `window` because the announcer is usually a sibling high in the\n * document rather than an ancestor of the component dispatching it.\n *\n * Wording comes from the consumer — the library ships no English strings — so an\n * empty message is silently dropped and nothing is announced.\n *\n * @example\n * ```ts\n * announce(this.announceTextValue, { assertive: false });\n * ```\n */\nexport function announce(message: string, options: { assertive?: boolean } = {}): void {\n const text = message.trim();\n if (text.length === 0) return;\n window.dispatchEvent(\n new CustomEvent(\"stimeo--announcer:announce\", {\n detail: { message: text, assertive: options.assertive === true },\n }),\n );\n}\n\n/**\n * Fills `{name}` placeholders in an announcement template from `values`.\n *\n * The same substitution the value-text templates use, so a consumer writes\n * `\"{percent}% complete\"` in one attribute and gets the same rules everywhere. A\n * placeholder with no matching entry is left as authored rather than blanked, which\n * keeps a typo visible instead of silently swallowing the word.\n */\nexport function fillTemplate(template: string, values: Record<string, string | number>): string {\n return template.replace(/\\{([a-zA-Z][a-zA-Z0-9]*)\\}/g, (match, name: string) => {\n const replacement = values[name];\n return replacement === undefined ? match : String(replacement);\n });\n}\n","/**\n * Numeric coercion shared by the value-bearing controllers (progress, meter,\n * color-picker).\n *\n * Stimulus already coerces numeric action params to numbers, but a value can also\n * arrive as a string — via a `*:set` CustomEvent `detail`, or an action param\n * whose attribute does not look numeric. Centralizing the parse keeps `setValue`\n * tolerant of either form while rejecting anything that is not a finite number.\n */\n\n/**\n * Coerces `raw` to a finite number, or returns `null` when it is absent, empty,\n * or not parseable. Empty strings are treated as \"no value\" rather than `0`, so a\n * stray blank param cannot silently reset the value.\n */\nexport function toFiniteNumber(raw: number | string | null | undefined): number | null {\n if (raw === null || raw === undefined || raw === \"\") return null;\n const value = typeof raw === \"number\" ? raw : Number(raw);\n return Number.isFinite(value) ? value : null;\n}\n","/**\n * Collapses many target callbacks from one DOM mutation into a single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element, so\n * replacing a list of N options delivers N callbacks — but the useful unit of\n * work is \"reconcile against the DOM that resulted\", once, after the batch has\n * settled. Every controller that owns a reconcilable target set needs the same\n * shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers the *initial* target callbacks\n * ahead of `connect()`. Reconciling there would compute a fallback against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\n });\n }\n}\n","/**\n * Range normalization shared by the value-bearing controllers (progress, meter,\n * slider, range-slider).\n *\n * Each of them publishes \"where the value sits inside `[min, max]`\" as a CSS\n * custom property the consumer multiplies a track by, and each has to answer the\n * same degenerate cases: empty and inverted ranges cannot express progress, and\n * malformed Number Values can produce `NaN`. Keeping the rule in one place is\n * what makes those answers identical across the four.\n */\n\n/**\n * Fraction of `[min, max]` that `value` occupies, always within `[0, 1]`.\n *\n * `value` is clamped into the range first, so a value outside it reports a full\n * or empty track rather than pushing the fraction past the ends.\n *\n * An empty, inverted, or non-numeric range yields `0`. That is a deliberate\n * floor rather than a computed result: `min === max` would produce `NaN`, and\n * `min > max` would report a full track for a value that is really out of range.\n * Non-finite results are floored for the same reason. These results reach\n * assistive tech, because the same fraction drives the percentage substituted\n * into `aria-valuetext`.\n */\nexport function rangeFraction(value: number, min: number, max: number): number {\n const span = max - min;\n if (!(span > 0)) return 0;\n\n const clamped = Math.min(max, Math.max(min, value));\n let fraction: number;\n if (Number.isFinite(span)) {\n fraction = (clamped - min) / span;\n } else {\n // Scaling preserves the ratio when two finite endpoints straddle zero so\n // widely that their subtraction overflows to Infinity.\n const scale = Math.max(Math.abs(min), Math.abs(max));\n fraction = (clamped / scale - min / scale) / (max / scale - min / scale);\n }\n\n if (!Number.isFinite(fraction)) return 0;\n return Math.min(1, Math.max(0, fraction));\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { announce, fillTemplate } from \"../utils/announce\";\nimport { toFiniteNumber } from \"../utils/coerce\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\nimport { rangeFraction } from \"../utils/range\";\n\n/**\n * Event shape `setValue` accepts: an action param `amount` or a `detail.value`.\n * Both are typed `number | string` because, while Stimulus coerces numeric action\n * params to numbers, a `progress:set` CustomEvent (or a non-numeric-looking param)\n * may carry a string; {@link ProgressController.setValue} normalizes either form.\n */\ntype SetValueEvent = Event & {\n params?: { amount?: number | string };\n detail?: { value?: number | string };\n};\n\n/**\n * Marks an `aria-valuetext` this controller wrote, so a render takes back only\n * its own text. `aria-valuetext` is shared: a consumer may author it instead of\n * supplying a template, and that text is theirs to keep across renders.\n */\nconst OWNED_VALUE_TEXT = \"data-stimeo--progress-owns-valuetext\";\n\n/**\n * Headless progress-bar behavior backed by the WAI-ARIA `progressbar` role.\n *\n * Markup contract (identifier: `stimeo--progress`):\n * <div data-controller=\"stimeo--progress\" role=\"progressbar\"\n * aria-label=\"Upload\" aria-valuemin=\"0\" aria-valuemax=\"100\" aria-valuenow=\"0\"\n * data-stimeo--progress-value-value=\"0\"\n * data-action=\"progress:set->stimeo--progress#setValue\">\n * <div data-stimeo--progress-target=\"bar\"></div>\n * </div>\n *\n * This is the *progress over time* role (a task advancing toward completion),\n * deliberately distinct from {@link MeterController}'s point-in-time `meter`. The\n * controller owns value normalization and ARIA value-attribute synchronization;\n * the bar's width/animation is the consumer's, driven off the\n * `--stimeo-progress-ratio` (0–1) custom property and `data-state`.\n *\n * @remarks\n * Behavior only — no styling is emitted. An indeterminate bar drops\n * `aria-valuenow` (per ARIA) so assistive tech announces \"busy\" rather than a\n * stale value; the consumer animates the indeterminate look off\n * `data-state=\"indeterminate\"`.\n */\nexport class ProgressController extends Controller<HTMLElement> {\n static override targets = [\"bar\"];\n static override values = {\n value: { type: Number, default: 0 },\n min: { type: Number, default: 0 },\n max: { type: Number, default: 100 },\n indeterminate: { type: Boolean, default: false },\n valueText: { type: String, default: \"\" },\n announceText: { type: String, default: \"\" },\n };\n static actions = [\"setValue\"] as const;\n static events = [\"change\", \"complete\"] as const;\n\n declare readonly barTarget: HTMLElement;\n declare readonly hasBarTarget: boolean;\n\n declare valueValue: number;\n declare minValue: number;\n declare maxValue: number;\n declare indeterminateValue: boolean;\n declare valueTextValue: string;\n declare announceTextValue: string;\n\n /**\n * Collapses a morph that swaps several render inputs at once into one repaint.\n * A single update usually rewrites the whole set, and each Value would otherwise\n * repaint on its own.\n */\n readonly #repaint = new MicrotaskCoalescer(() => {\n this.#render();\n });\n\n override connect(): void {\n this.#repaint.activate();\n this.#render();\n }\n\n /** Closes the window in which a queued repaint may still run. */\n override disconnect(): void {\n this.#repaint.cancel();\n }\n\n /**\n * Updates the progress value from an action param (`amount`) or a\n * `detail.value` CustomEvent, normalizes it into range, syncs ARIA, and\n * dispatches `change` (always) plus `complete` when `max` is reached.\n */\n setValue(event: SetValueEvent): void {\n const next = toFiniteNumber(event.params?.amount ?? event.detail?.value);\n if (next === null) return;\n const value = this.#clamp(next);\n this.valueValue = value;\n this.indeterminateValue = false;\n this.#render();\n this.dispatch(\"change\", { detail: { value, ratio: this.#ratio } });\n if (value >= this.maxValue) {\n this.dispatch(\"complete\", { detail: { value } });\n // Reaching the end is the transition worth reading out; the running numbers in\n // between are state the consumer can see, not news.\n announce(\n fillTemplate(this.announceTextValue, { value, percent: Math.round(this.#ratio * 100) }),\n );\n }\n }\n\n /** Repaints when application code (or a Turbo morph) changes `indeterminate` at runtime. */\n indeterminateValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `value` at runtime. */\n valueValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `min` at runtime. */\n minValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `max` at runtime. */\n maxValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `valueText` at runtime. */\n valueTextValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Clamps `raw` into the configured `[min, max]` range. */\n #clamp(raw: number): number {\n return Math.min(this.maxValue, Math.max(this.minValue, raw));\n }\n\n /** Current fraction of the range in `[0, 1]`; `0` when the range is empty. */\n get #ratio(): number {\n return rangeFraction(this.valueValue, this.minValue, this.maxValue);\n }\n\n /** Reflects value/range/indeterminate onto ARIA, `data-state`, and the ratio. */\n #render(): void {\n this.element.setAttribute(\"aria-valuemin\", String(this.minValue));\n this.element.setAttribute(\"aria-valuemax\", String(this.maxValue));\n\n if (this.indeterminateValue) {\n this.element.removeAttribute(\"aria-valuenow\");\n // `aria-valuetext` outranks `aria-valuenow` for assistive tech, so a text\n // this controller derived from a value would announce the very number the\n // indeterminate state drops.\n this.#clearOwnValueText();\n this.element.style.removeProperty(\"--stimeo-progress-ratio\");\n this.element.setAttribute(\"data-state\", \"indeterminate\");\n return;\n }\n\n const value = this.#clamp(this.valueValue);\n this.element.setAttribute(\"aria-valuenow\", String(value));\n this.element.style.setProperty(\"--stimeo-progress-ratio\", String(this.#ratio));\n this.element.setAttribute(\"data-state\", \"determinate\");\n this.#applyValueText(value);\n }\n\n /**\n * Sets `aria-valuetext` from the consumer-provided template, substituting\n * `{value}` and `{percent}`. Left to the consumer so the human-readable text\n * stays i18n-neutral in the library. With no template the attribute belongs to\n * the consumer, so only a text this controller wrote is taken back\n * ({@link OWNED_VALUE_TEXT}).\n */\n #applyValueText(value: number): void {\n if (this.valueTextValue.length === 0) {\n this.#clearOwnValueText();\n return;\n }\n const percent = Math.round(this.#ratio * 100);\n const text = this.valueTextValue\n .replaceAll(\"{value}\", String(value))\n .replaceAll(\"{percent}\", String(percent));\n this.element.setAttribute(\"aria-valuetext\", text);\n this.element.setAttribute(OWNED_VALUE_TEXT, \"\");\n }\n\n /** Removes `aria-valuetext` only when this controller is the one that wrote it. */\n #clearOwnValueText(): void {\n if (!this.element.hasAttribute(OWNED_VALUE_TEXT)) return;\n this.element.removeAttribute(\"aria-valuetext\");\n this.element.removeAttribute(OWNED_VALUE_TEXT);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/announce.ts","../../src/utils/coerce.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/range.ts","../../src/controllers/progress_controller.ts"],"names":[],"mappings":";;;;;AAoBO,SAAS,QAAA,CAAS,OAAA,EAAiB,OAAA,GAAmC,EAAC,EAAS;AACrF,EAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,EAAK;AAC1B,EAAA,IAAI,IAAA,CAAK,WAAW,CAAA,EAAG;AACvB,EAAA,MAAA,CAAO,aAAA;AAAA,IACL,IAAI,YAAY,4BAAA,EAA8B;AAAA,MAC5C,QAAQ,EAAE,OAAA,EAAS,MAAM,SAAA,EAAW,OAAA,CAAQ,cAAc,IAAA;AAAK,KAChE;AAAA,GACH;AACF;AAUO,SAAS,YAAA,CAAa,UAAkB,MAAA,EAAiD;AAC9F,EAAA,OAAO,QAAA,CAAS,OAAA,CAAQ,6BAAA,EAA+B,CAAC,OAAO,IAAA,KAAiB;AAC9E,IAAA,MAAM,WAAA,GAAc,OAAO,IAAI,CAAA;AAC/B,IAAA,OAAO,WAAA,KAAgB,MAAA,GAAY,KAAA,GAAQ,MAAA,CAAO,WAAW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CAAC,CAAA,CACnC,UAAA,CAAW,WAAA,EAAa,MAAA,CAAO,OAAO,CAAC,CAAA;AAC1C,IAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,gBAAA,EAAkB,IAAI,CAAA;AAChD,IAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,gBAAA,EAAkB,EAAE,CAAA;AAAA,EAChD;AAAA;AAAA,EAGA,kBAAA,GAA2B;AACzB,IAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,gBAAgB,CAAA,EAAG;AAClD,IAAA,IAAA,CAAK,OAAA,CAAQ,gBAAgB,gBAAgB,CAAA;AAC7C,IAAA,IAAA,CAAK,OAAA,CAAQ,gBAAgB,gBAAgB,CAAA;AAAA,EAC/C;AACF","file":"progress_controller.js","sourcesContent":["/**\n * Sends one message to the page's shared `stimeo--announcer`.\n *\n * A component that has to reach assistive tech does not carry a live region of its\n * own: a region only announces what changes *after* assistive tech already knows\n * about it, which a region that appears (or is un-hidden) with its message cannot\n * satisfy. The one region that can is the announcer sitting in the page from the\n * start, so state changes are handed to it as an event and it does the reading.\n *\n * The event goes to `window` because the announcer is usually a sibling high in the\n * document rather than an ancestor of the component dispatching it.\n *\n * Wording comes from the consumer — the library ships no English strings — so an\n * empty message is silently dropped and nothing is announced.\n *\n * @example\n * ```ts\n * announce(this.announceTextValue, { assertive: false });\n * ```\n */\nexport function announce(message: string, options: { assertive?: boolean } = {}): void {\n const text = message.trim();\n if (text.length === 0) return;\n window.dispatchEvent(\n new CustomEvent(\"stimeo--announcer:announce\", {\n detail: { message: text, assertive: options.assertive === true },\n }),\n );\n}\n\n/**\n * Fills `{name}` placeholders in an announcement template from `values`.\n *\n * The same substitution the value-text templates use, so a consumer writes\n * `\"{percent}% complete\"` in one attribute and gets the same rules everywhere. A\n * placeholder with no matching entry is left as authored rather than blanked, which\n * keeps a typo visible instead of silently swallowing the word.\n */\nexport function fillTemplate(template: string, values: Record<string, string | number>): string {\n return template.replace(/\\{([a-zA-Z][a-zA-Z0-9]*)\\}/g, (match, name: string) => {\n const replacement = values[name];\n return replacement === undefined ? match : String(replacement);\n });\n}\n","/**\n * Numeric coercion shared by the value-bearing controllers (progress, meter,\n * color-picker).\n *\n * Stimulus already coerces numeric action params to numbers, but a value can also\n * arrive as a string — via a `*:set` CustomEvent `detail`, or an action param\n * whose attribute does not look numeric. Centralizing the parse keeps `setValue`\n * tolerant of either form while rejecting anything that is not a finite number.\n */\n\n/**\n * Coerces `raw` to a finite number, or returns `null` when it is absent, empty,\n * or not parseable. Empty strings are treated as \"no value\" rather than `0`, so a\n * stray blank param cannot silently reset the value.\n */\nexport function toFiniteNumber(raw: number | string | null | undefined): number | null {\n if (raw === null || raw === undefined || raw === \"\") return null;\n const value = typeof raw === \"number\" ? raw : Number(raw);\n return Number.isFinite(value) ? value : null;\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 * Range normalization shared by the value-bearing controllers (progress, meter,\n * slider, range-slider).\n *\n * Each of them publishes \"where the value sits inside `[min, max]`\" as a CSS\n * custom property the consumer multiplies a track by, and each has to answer the\n * same degenerate cases: empty and inverted ranges cannot express progress, and\n * malformed Number Values can produce `NaN`. Keeping the rule in one place is\n * what makes those answers identical across the four.\n */\n\n/**\n * Fraction of `[min, max]` that `value` occupies, always within `[0, 1]`.\n *\n * `value` is clamped into the range first, so a value outside it reports a full\n * or empty track rather than pushing the fraction past the ends.\n *\n * An empty, inverted, or non-numeric range yields `0`. That is a deliberate\n * floor rather than a computed result: `min === max` would produce `NaN`, and\n * `min > max` would report a full track for a value that is really out of range.\n * Non-finite results are floored for the same reason. These results reach\n * assistive tech, because the same fraction drives the percentage substituted\n * into `aria-valuetext`.\n */\nexport function rangeFraction(value: number, min: number, max: number): number {\n const span = max - min;\n if (!(span > 0)) return 0;\n\n const clamped = Math.min(max, Math.max(min, value));\n let fraction: number;\n if (Number.isFinite(span)) {\n fraction = (clamped - min) / span;\n } else {\n // Scaling preserves the ratio when two finite endpoints straddle zero so\n // widely that their subtraction overflows to Infinity.\n const scale = Math.max(Math.abs(min), Math.abs(max));\n fraction = (clamped / scale - min / scale) / (max / scale - min / scale);\n }\n\n if (!Number.isFinite(fraction)) return 0;\n return Math.min(1, Math.max(0, fraction));\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { announce, fillTemplate } from \"../utils/announce\";\nimport { toFiniteNumber } from \"../utils/coerce\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\nimport { rangeFraction } from \"../utils/range\";\n\n/**\n * Event shape `setValue` accepts: an action param `amount` or a `detail.value`.\n * Both are typed `number | string` because, while Stimulus coerces numeric action\n * params to numbers, a `progress:set` CustomEvent (or a non-numeric-looking param)\n * may carry a string; {@link ProgressController.setValue} normalizes either form.\n */\ntype SetValueEvent = Event & {\n params?: { amount?: number | string };\n detail?: { value?: number | string };\n};\n\n/**\n * Marks an `aria-valuetext` this controller wrote, so a render takes back only\n * its own text. `aria-valuetext` is shared: a consumer may author it instead of\n * supplying a template, and that text is theirs to keep across renders.\n */\nconst OWNED_VALUE_TEXT = \"data-stimeo--progress-owns-valuetext\";\n\n/**\n * Headless progress-bar behavior backed by the WAI-ARIA `progressbar` role.\n *\n * Markup contract (identifier: `stimeo--progress`):\n * <div data-controller=\"stimeo--progress\" role=\"progressbar\"\n * aria-label=\"Upload\" aria-valuemin=\"0\" aria-valuemax=\"100\" aria-valuenow=\"0\"\n * data-stimeo--progress-value-value=\"0\"\n * data-action=\"progress:set->stimeo--progress#setValue\">\n * <div data-stimeo--progress-target=\"bar\"></div>\n * </div>\n *\n * This is the *progress over time* role (a task advancing toward completion),\n * deliberately distinct from {@link MeterController}'s point-in-time `meter`. The\n * controller owns value normalization and ARIA value-attribute synchronization;\n * the bar's width/animation is the consumer's, driven off the\n * `--stimeo--progress-ratio` (0–1) custom property and `data-state`.\n *\n * @remarks\n * Behavior only — no styling is emitted. An indeterminate bar drops\n * `aria-valuenow` (per ARIA) so assistive tech announces \"busy\" rather than a\n * stale value; the consumer animates the indeterminate look off\n * `data-state=\"indeterminate\"`.\n */\nexport class ProgressController extends Controller<HTMLElement> {\n static override targets = [\"bar\"];\n static override values = {\n value: { type: Number, default: 0 },\n min: { type: Number, default: 0 },\n max: { type: Number, default: 100 },\n indeterminate: { type: Boolean, default: false },\n valueText: { type: String, default: \"\" },\n announceText: { type: String, default: \"\" },\n };\n static actions = [\"setValue\"] as const;\n static events = [\"change\", \"complete\"] as const;\n\n declare readonly barTarget: HTMLElement;\n declare readonly hasBarTarget: boolean;\n\n declare valueValue: number;\n declare minValue: number;\n declare maxValue: number;\n declare indeterminateValue: boolean;\n declare valueTextValue: string;\n declare announceTextValue: string;\n\n /**\n * Collapses a morph that swaps several render inputs at once into one repaint.\n * A single update usually rewrites the whole set, and each Value would otherwise\n * repaint on its own.\n */\n readonly #repaint = new MicrotaskCoalescer(() => {\n this.#render();\n });\n\n override connect(): void {\n this.#repaint.activate();\n this.#render();\n }\n\n /** Closes the window in which a queued repaint may still run. */\n override disconnect(): void {\n this.#repaint.cancel();\n }\n\n /**\n * Updates the progress value from an action param (`amount`) or a\n * `detail.value` CustomEvent, normalizes it into range, syncs ARIA, and\n * dispatches `change` (always) plus `complete` when `max` is reached.\n */\n setValue(event: SetValueEvent): void {\n const next = toFiniteNumber(event.params?.amount ?? event.detail?.value);\n if (next === null) return;\n const value = this.#clamp(next);\n this.valueValue = value;\n this.indeterminateValue = false;\n this.#render();\n this.dispatch(\"change\", { detail: { value, ratio: this.#ratio } });\n if (value >= this.maxValue) {\n this.dispatch(\"complete\", { detail: { value } });\n // Reaching the end is the transition worth reading out; the running numbers in\n // between are state the consumer can see, not news.\n announce(\n fillTemplate(this.announceTextValue, { value, percent: Math.round(this.#ratio * 100) }),\n );\n }\n }\n\n /** Repaints when application code (or a Turbo morph) changes `indeterminate` at runtime. */\n indeterminateValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `value` at runtime. */\n valueValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `min` at runtime. */\n minValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `max` at runtime. */\n maxValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `valueText` at runtime. */\n valueTextValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Clamps `raw` into the configured `[min, max]` range. */\n #clamp(raw: number): number {\n return Math.min(this.maxValue, Math.max(this.minValue, raw));\n }\n\n /** Current fraction of the range in `[0, 1]`; `0` when the range is empty. */\n get #ratio(): number {\n return rangeFraction(this.valueValue, this.minValue, this.maxValue);\n }\n\n /**\n * Reflects value/range/indeterminate onto ARIA, `data-state`, and the ratio.\n *\n * @stimeoRenderRoot\n */\n #render(): void {\n this.element.setAttribute(\"aria-valuemin\", String(this.minValue));\n this.element.setAttribute(\"aria-valuemax\", String(this.maxValue));\n\n if (this.indeterminateValue) {\n this.element.removeAttribute(\"aria-valuenow\");\n // `aria-valuetext` outranks `aria-valuenow` for assistive tech, so a text\n // this controller derived from a value would announce the very number the\n // indeterminate state drops.\n this.#clearOwnValueText();\n this.element.style.removeProperty(\"--stimeo--progress-ratio\");\n this.element.setAttribute(\"data-state\", \"indeterminate\");\n return;\n }\n\n const value = this.#clamp(this.valueValue);\n this.element.setAttribute(\"aria-valuenow\", String(value));\n this.element.style.setProperty(\"--stimeo--progress-ratio\", String(this.#ratio));\n this.element.setAttribute(\"data-state\", \"determinate\");\n this.#applyValueText(value);\n }\n\n /**\n * Sets `aria-valuetext` from the consumer-provided template, substituting\n * `{value}` and `{percent}`. Left to the consumer so the human-readable text\n * stays i18n-neutral in the library. With no template the attribute belongs to\n * the consumer, so only a text this controller wrote is taken back\n * ({@link OWNED_VALUE_TEXT}).\n */\n #applyValueText(value: number): void {\n if (this.valueTextValue.length === 0) {\n this.#clearOwnValueText();\n return;\n }\n const percent = Math.round(this.#ratio * 100);\n const text = this.valueTextValue\n .replaceAll(\"{value}\", String(value))\n .replaceAll(\"{percent}\", String(percent));\n this.element.setAttribute(\"aria-valuetext\", text);\n this.element.setAttribute(OWNED_VALUE_TEXT, \"\");\n }\n\n /** Removes `aria-valuetext` only when this controller is the one that wrote it. */\n #clearOwnValueText(): void {\n if (!this.element.hasAttribute(OWNED_VALUE_TEXT)) return;\n this.element.removeAttribute(\"aria-valuetext\");\n this.element.removeAttribute(OWNED_VALUE_TEXT);\n }\n}\n"]}
|
|
@@ -35,6 +35,13 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
35
35
|
* step; `Home`/`End` jump to that thumb's movable min/max; `PageUp`/`PageDown`
|
|
36
36
|
* move by ten steps. A thumb never crosses the other.
|
|
37
37
|
* - Pointer press/drag on the track moves the nearest thumb.
|
|
38
|
+
* When the thumbs overlap, a press above their shared value selects `end`
|
|
39
|
+
* and a press below selects `start`, so the pair remains expandable.
|
|
40
|
+
* - `min`, `max`, `start`, and `end` must be finite. Invalid runtime endpoints
|
|
41
|
+
* fall back to `0`/`100`; invalid thumb Values fall back to the corresponding
|
|
42
|
+
* effective endpoint. A `max` below `min` collapses the range to `min`.
|
|
43
|
+
* - `step` must be finite and positive; invalid runtime input falls back to `1`.
|
|
44
|
+
* Finite movable endpoints remain allowed off the shared step grid.
|
|
38
45
|
*
|
|
39
46
|
* The fractions are value ratios, not positions, so only the consumer knows
|
|
40
47
|
* whether their track mirrors under RTL. Set `logicalTrack` to declare that it
|
|
@@ -91,6 +98,22 @@ declare class RangeSliderController extends Controller<HTMLElement> {
|
|
|
91
98
|
minValueChanged(): void;
|
|
92
99
|
/** Repaints when application code (or a Turbo morph) changes `max` at runtime. */
|
|
93
100
|
maxValueChanged(): void;
|
|
101
|
+
/** Repaints when application code (or a Turbo morph) changes `step` at runtime. */
|
|
102
|
+
stepValueChanged(): void;
|
|
103
|
+
/** Repaints when application code (or a Turbo morph) changes `start` at runtime. */
|
|
104
|
+
startValueChanged(): void;
|
|
105
|
+
/** Repaints when application code (or a Turbo morph) changes `end` at runtime. */
|
|
106
|
+
endValueChanged(): void;
|
|
107
|
+
/** Hydrates a replacement start thumb and restores live-drag focus ownership. */
|
|
108
|
+
startThumbTargetConnected(thumb: HTMLElement): void;
|
|
109
|
+
/** Drops a stale start-thumb reference without orphaning the track gesture. */
|
|
110
|
+
startThumbTargetDisconnected(thumb: HTMLElement): void;
|
|
111
|
+
/** Hydrates a replacement end thumb and restores live-drag focus ownership. */
|
|
112
|
+
endThumbTargetConnected(thumb: HTMLElement): void;
|
|
113
|
+
/** Drops a stale end-thumb reference without orphaning the track gesture. */
|
|
114
|
+
endThumbTargetDisconnected(thumb: HTMLElement): void;
|
|
115
|
+
/** Ends a gesture whose geometry target disappeared or ceased being a target. */
|
|
116
|
+
trackTargetDisconnected(track: HTMLElement): void;
|
|
94
117
|
/** Keyboard stepping for whichever thumb is focused (the action's element). */
|
|
95
118
|
onKeydown(event: KeyboardEvent): void;
|
|
96
119
|
/** Begins a pointer drag on the track, moving the thumb nearest the press. */
|