stimeo-ui 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/dist/controllers/accordion_controller.d.ts +3 -2
  3. package/dist/controllers/accordion_controller.js.map +1 -1
  4. package/dist/controllers/alert_dialog_controller.d.ts +64 -0
  5. package/dist/controllers/alert_dialog_controller.js +318 -0
  6. package/dist/controllers/alert_dialog_controller.js.map +1 -0
  7. package/dist/controllers/carousel_controller.d.ts +100 -0
  8. package/dist/controllers/carousel_controller.js +272 -0
  9. package/dist/controllers/carousel_controller.js.map +1 -0
  10. package/dist/controllers/clipboard_controller.d.ts +72 -0
  11. package/dist/controllers/clipboard_controller.js +144 -0
  12. package/dist/controllers/clipboard_controller.js.map +1 -0
  13. package/dist/controllers/collapsible_controller.d.ts +70 -0
  14. package/dist/controllers/collapsible_controller.js +327 -0
  15. package/dist/controllers/collapsible_controller.js.map +1 -0
  16. package/dist/controllers/color_picker_controller.d.ts +76 -0
  17. package/dist/controllers/color_picker_controller.js +213 -0
  18. package/dist/controllers/color_picker_controller.js.map +1 -0
  19. package/dist/controllers/count_up_controller.js +8 -1
  20. package/dist/controllers/count_up_controller.js.map +1 -1
  21. package/dist/controllers/currency_input_controller.d.ts +72 -0
  22. package/dist/controllers/currency_input_controller.js +147 -0
  23. package/dist/controllers/currency_input_controller.js.map +1 -0
  24. package/dist/controllers/data_grid_controller.d.ts +71 -0
  25. package/dist/controllers/data_grid_controller.js +168 -0
  26. package/dist/controllers/data_grid_controller.js.map +1 -0
  27. package/dist/controllers/date_range_picker_controller.d.ts +87 -0
  28. package/dist/controllers/date_range_picker_controller.js +417 -0
  29. package/dist/controllers/date_range_picker_controller.js.map +1 -0
  30. package/dist/controllers/dismissible_controller.d.ts +57 -0
  31. package/dist/controllers/dismissible_controller.js +117 -0
  32. package/dist/controllers/dismissible_controller.js.map +1 -0
  33. package/dist/controllers/drawer_controller.d.ts +96 -0
  34. package/dist/controllers/drawer_controller.js +630 -0
  35. package/dist/controllers/drawer_controller.js.map +1 -0
  36. package/dist/controllers/editable_controller.d.ts +73 -0
  37. package/dist/controllers/editable_controller.js +168 -0
  38. package/dist/controllers/editable_controller.js.map +1 -0
  39. package/dist/controllers/file_dropzone_controller.d.ts +92 -0
  40. package/dist/controllers/file_dropzone_controller.js +165 -0
  41. package/dist/controllers/file_dropzone_controller.js.map +1 -0
  42. package/dist/controllers/filter_controller.d.ts +60 -0
  43. package/dist/controllers/filter_controller.js +86 -0
  44. package/dist/controllers/filter_controller.js.map +1 -0
  45. package/dist/controllers/flash_controller.js +36 -5
  46. package/dist/controllers/flash_controller.js.map +1 -1
  47. package/dist/controllers/highlight_controller.js +6 -4
  48. package/dist/controllers/highlight_controller.js.map +1 -1
  49. package/dist/controllers/intersection_controller.js +41 -18
  50. package/dist/controllers/intersection_controller.js.map +1 -1
  51. package/dist/controllers/lazy_frame_controller.js +33 -11
  52. package/dist/controllers/lazy_frame_controller.js.map +1 -1
  53. package/dist/controllers/masonry_controller.d.ts +54 -0
  54. package/dist/controllers/masonry_controller.js +142 -0
  55. package/dist/controllers/masonry_controller.js.map +1 -0
  56. package/dist/controllers/menubar_controller.d.ts +62 -0
  57. package/dist/controllers/menubar_controller.js +433 -0
  58. package/dist/controllers/menubar_controller.js.map +1 -0
  59. package/dist/controllers/multi_select_controller.d.ts +115 -0
  60. package/dist/controllers/multi_select_controller.js +472 -0
  61. package/dist/controllers/multi_select_controller.js.map +1 -0
  62. package/dist/controllers/navigation_menu_controller.d.ts +99 -0
  63. package/dist/controllers/navigation_menu_controller.js +384 -0
  64. package/dist/controllers/navigation_menu_controller.js.map +1 -0
  65. package/dist/controllers/overflow_indicator_controller.d.ts +12 -4
  66. package/dist/controllers/overflow_indicator_controller.js +178 -27
  67. package/dist/controllers/overflow_indicator_controller.js.map +1 -1
  68. package/dist/controllers/password_reveal_controller.d.ts +49 -0
  69. package/dist/controllers/password_reveal_controller.js +117 -0
  70. package/dist/controllers/password_reveal_controller.js.map +1 -0
  71. package/dist/controllers/range_slider_controller.d.ts +87 -0
  72. package/dist/controllers/range_slider_controller.js +166 -0
  73. package/dist/controllers/range_slider_controller.js.map +1 -0
  74. package/dist/controllers/read_more_controller.d.ts +52 -0
  75. package/dist/controllers/read_more_controller.js +194 -0
  76. package/dist/controllers/read_more_controller.js.map +1 -0
  77. package/dist/controllers/scroll_area_controller.js +15 -2
  78. package/dist/controllers/scroll_area_controller.js.map +1 -1
  79. package/dist/controllers/scroll_restore_controller.d.ts +54 -0
  80. package/dist/controllers/scroll_restore_controller.js +93 -0
  81. package/dist/controllers/scroll_restore_controller.js.map +1 -0
  82. package/dist/controllers/scroll_visibility_controller.js +8 -4
  83. package/dist/controllers/scroll_visibility_controller.js.map +1 -1
  84. package/dist/controllers/scrollspy_controller.js +33 -11
  85. package/dist/controllers/scrollspy_controller.js.map +1 -1
  86. package/dist/controllers/separator_controller.d.ts +54 -0
  87. package/dist/controllers/separator_controller.js +87 -0
  88. package/dist/controllers/separator_controller.js.map +1 -0
  89. package/dist/controllers/sidebar_controller.d.ts +107 -0
  90. package/dist/controllers/sidebar_controller.js +761 -0
  91. package/dist/controllers/sidebar_controller.js.map +1 -0
  92. package/dist/controllers/stepper_controller.d.ts +4 -0
  93. package/dist/controllers/stepper_controller.js +28 -12
  94. package/dist/controllers/stepper_controller.js.map +1 -1
  95. package/dist/controllers/stick_to_bottom_controller.js +8 -4
  96. package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
  97. package/dist/controllers/sticky_observer_controller.d.ts +17 -4
  98. package/dist/controllers/sticky_observer_controller.js +88 -20
  99. package/dist/controllers/sticky_observer_controller.js.map +1 -1
  100. package/dist/controllers/tabs_controller.d.ts +3 -2
  101. package/dist/controllers/tabs_controller.js.map +1 -1
  102. package/dist/controllers/tags_input_controller.d.ts +91 -0
  103. package/dist/controllers/tags_input_controller.js +275 -0
  104. package/dist/controllers/tags_input_controller.js.map +1 -0
  105. package/dist/controllers/theme_controller.js +20 -10
  106. package/dist/controllers/theme_controller.js.map +1 -1
  107. package/dist/controllers/time_picker_controller.d.ts +67 -0
  108. package/dist/controllers/time_picker_controller.js +212 -0
  109. package/dist/controllers/time_picker_controller.js.map +1 -0
  110. package/dist/controllers/toast_controller.d.ts +1 -9
  111. package/dist/controllers/toast_controller.js +36 -9
  112. package/dist/controllers/toast_controller.js.map +1 -1
  113. package/dist/controllers/transition_controller.d.ts +14 -8
  114. package/dist/controllers/transition_controller.js +153 -38
  115. package/dist/controllers/transition_controller.js.map +1 -1
  116. package/dist/controllers/tree_view_controller.d.ts +54 -0
  117. package/dist/controllers/tree_view_controller.js +275 -0
  118. package/dist/controllers/tree_view_controller.js.map +1 -0
  119. package/dist/index.d.ts +27 -1818
  120. package/dist/index.js +811 -295
  121. package/dist/index.js.map +1 -1
  122. package/dist/inspector/examples.json +2 -2
  123. package/dist/inspector/manifest.json +15 -3
  124. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/safe_timeout.ts","../../src/controllers/clipboard_controller.ts"],"names":[],"mappings":";;;;;AAwBA,IAAe,gBAAf,MAA6B;AAAA;AAAA,EAER,GAAA,uBAAU,GAAA,EAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAczC,MAAM,EAAA,EAAkB;AACtB,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,MAAA,CAAO,EAAE,CAAA,EAAG;AACvB,MAAA,IAAA,CAAK,OAAO,EAAE,CAAA;AAAA,IAChB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAA,GAAiB;AACf,IAAA,KAAA,MAAW,EAAA,IAAM,KAAK,GAAA,EAAK;AACzB,MAAA,IAAA,CAAK,OAAO,EAAE,CAAA;AAAA,IAChB;AACA,IAAA,IAAA,CAAK,IAAI,KAAA,EAAM;AAAA,EACjB;AAAA;AAAA,EAGA,IAAI,IAAA,GA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,IAAoB,MAAA,YAAkB,mBAAA,EAAqB;AAC/E,MAAA,OAAO,MAAA,CAAO,KAAA;AAAA,IAChB;AACA,IAAA,OAAO,OAAO,WAAA,IAAe,EAAA;AAAA,EAC/B;AAAA;AAAA,EAGA,cAAc,OAAA,EAAwB;AACpC,IAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,YAAA,EAAc,OAAA,GAAU,WAAW,OAAO,CAAA;AACpE,IAAA,IAAI,KAAK,iBAAA,EAAmB;AAC1B,MAAA,IAAA,CAAK,cAAA,CAAe,WAAA,GAAc,OAAA,GAAU,IAAA,CAAK,mBAAmB,IAAA,CAAK,eAAA;AAAA,IAC3E;AAIA,IAAA,IAAI,IAAA,CAAK,kBAAkB,IAAA,EAAM;AAC/B,MAAA,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,IAAA,CAAK,aAAa,CAAA;AACrC,MAAA,IAAA,CAAK,aAAA,GAAgB,IAAA;AAAA,IACvB;AACA,IAAA,IAAI,IAAA,CAAK,wBAAwB,CAAA,EAAG;AAClC,MAAA,IAAA,CAAK,aAAA,GAAgB,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,MAAM;AAC1C,QAAA,IAAA,CAAK,aAAA,GAAgB,IAAA;AACrB,QAAA,IAAA,CAAK,MAAA,EAAO;AAAA,MACd,CAAA,EAAG,KAAK,qBAAqB,CAAA;AAAA,IAC/B;AAAA,EACF;AAAA;AAAA,EAGA,MAAA,GAAe;AACb,IAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,YAAA,EAAc,MAAM,CAAA;AAC9C,IAAA,IAAI,KAAK,iBAAA,EAAmB;AAC1B,MAAA,IAAA,CAAK,eAAe,WAAA,GAAc,EAAA;AAAA,IACpC;AAAA,EACF;AACF","file":"clipboard_controller.js","sourcesContent":["/**\n * Self-cleaning timer registries shared by Stimeo controllers.\n *\n * Stimulus controllers frequently schedule `setTimeout` / `setInterval` work\n * (auto-dismiss, debouncing, polling). When the element leaves the DOM — a\n * Turbo Drive navigation, a Turbo Stream replacement, or any `disconnect()` —\n * orphaned timers keep firing against a detached controller, leaking memory and\n * mutating stale state. {@link SafeTimeout} and {@link SafeInterval} track every\n * timer they create so a single {@link TimerRegistry.clearAll | clearAll()} call\n * in `disconnect()` tears them all down.\n *\n * These are intentionally low-level primitives: they own *registration and\n * cleanup only*. Higher-level policy (pause/resume, remaining-time accounting)\n * stays in the individual controllers so per-widget semantics are not flattened\n * into a lowest-common-denominator helper.\n */\n\n/**\n * Shared registry bookkeeping for the timeout/interval variants.\n *\n * Subclasses provide the scheduling primitive ({@link schedule}) and its matching\n * canceller ({@link cancel}); this base owns the set of live ids plus the\n * per-id and bulk teardown shared by both.\n */\nabstract class TimerRegistry {\n /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */\n protected readonly ids = new Set<number>();\n\n /** Schedules the underlying platform timer and returns its id. */\n protected abstract schedule(callback: () => void, delay: number): number;\n\n /** Cancels the underlying platform timer for `id`. */\n protected abstract cancel(id: number): void;\n\n /**\n * Cancels a single tracked timer.\n *\n * No-ops if the id is unknown (already cleared, fired, or never owned by this\n * registry), so callers can clear defensively without guarding.\n */\n clear(id: number): void {\n if (this.ids.delete(id)) {\n this.cancel(id);\n }\n }\n\n /**\n * Cancels every tracked timer. Call this from a controller's `disconnect()`\n * to guarantee no timer outlives the element.\n */\n clearAll(): void {\n for (const id of this.ids) {\n this.cancel(id);\n }\n this.ids.clear();\n }\n\n /** Number of timers currently tracked (pending). */\n get size(): number {\n return this.ids.size;\n }\n}\n\n/**\n * `setTimeout` wrapper that auto-forgets each timer once it fires and supports\n * bulk teardown on disconnect.\n *\n * @example\n * ```ts\n * #timers = new SafeTimeout();\n *\n * connect() {\n * this.#timers.set(() => this.dismiss(), 5000);\n * }\n *\n * disconnect() {\n * this.#timers.clearAll();\n * }\n * ```\n */\nexport class SafeTimeout extends TimerRegistry {\n /**\n * Schedules `callback` after `delay` ms and returns the timer id.\n *\n * The id is removed from the registry automatically when the timeout fires,\n * so {@link TimerRegistry.size | size} reflects only still-pending timers.\n */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(() => {\n this.ids.delete(id);\n callback();\n }, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setTimeout(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearTimeout(id);\n }\n}\n\n/**\n * `setInterval` wrapper that tracks every interval for bulk teardown on\n * disconnect. Unlike {@link SafeTimeout}, intervals are retained until they are\n * explicitly cleared because they fire repeatedly.\n *\n * @example\n * ```ts\n * #intervals = new SafeInterval();\n *\n * connect() {\n * this.#intervals.set(() => this.tick(), 1000);\n * }\n *\n * disconnect() {\n * this.#intervals.clearAll();\n * }\n * ```\n */\nexport class SafeInterval extends TimerRegistry {\n /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(callback, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setInterval(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearInterval(id);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/**\n * Headless copy-to-clipboard behavior with a live-region completion notice.\n *\n * Markup contract (identifier: `stimeo--clipboard`):\n * <div data-controller=\"stimeo--clipboard\"\n * data-stimeo--clipboard-feedback-duration-value=\"2000\">\n * <input type=\"text\" value=\"https://example.com\" readonly\n * data-stimeo--clipboard-target=\"source\">\n * <button type=\"button\" data-stimeo--clipboard-target=\"button\"\n * data-action=\"stimeo--clipboard#copy\">Copy</button>\n * <span role=\"status\" aria-live=\"polite\"\n * data-stimeo--clipboard-target=\"feedback\"></span>\n * </div>\n *\n * No dedicated APG pattern; this follows the Button + live-region practice. The\n * copy uses the standard `navigator.clipboard` API (no extra dependency); when\n * it is unavailable or rejects, the failure is surfaced rather than silently\n * swallowed, and never communicated by icon alone — the `role=\"status\"` region\n * carries text so screen readers announce the outcome.\n *\n * @remarks\n * Behavior only — icon swaps and styling are the consumer's, keyed off\n * `data-state` (`idle` / `copied` / `error`). The completion notice clears\n * itself after `feedbackDuration`; that timer is torn down on disconnect (Turbo)\n * via {@link SafeTimeout}.\n */\nexport class ClipboardController extends Controller<HTMLElement> {\n static override targets = [\"source\", \"button\", \"feedback\"];\n static override values = {\n text: { type: String, default: \"\" },\n feedbackDuration: { type: Number, default: 2000 },\n copiedLabel: { type: String, default: \"Copied\" },\n errorLabel: { type: String, default: \"Copy failed\" },\n };\n static actions = [\"copy\"] as const;\n static events = [\"copy\"] as const;\n\n declare readonly sourceTarget: HTMLElement;\n declare readonly buttonTarget: HTMLElement;\n declare readonly feedbackTarget: HTMLElement;\n declare readonly hasSourceTarget: boolean;\n declare readonly hasButtonTarget: boolean;\n declare readonly hasFeedbackTarget: boolean;\n\n declare textValue: string;\n declare feedbackDurationValue: number;\n declare copiedLabelValue: string;\n declare errorLabelValue: string;\n\n /** Auto-clear timer for the completion notice; torn down on disconnect. */\n #timers = new SafeTimeout();\n\n /**\n * The pending auto-clear timer id, or `null` when none is scheduled. Tracked so\n * a rapid second copy cancels the first window instead of letting a stale timer\n * reset the freshly-shown notice early.\n */\n #resetTimerId: number | null = null;\n\n override connect(): void {\n if (!this.element.hasAttribute(\"data-state\")) {\n this.element.setAttribute(\"data-state\", \"idle\");\n }\n }\n\n override disconnect(): void {\n this.#timers.clearAll();\n }\n\n /**\n * Copies the resolved text and reports the outcome. Bound via `data-action`\n * (click). Always dispatches `stimeo--clipboard:copy` with `{ success, text }`\n * — including on failure — so consumers can react either way.\n */\n async copy(): Promise<void> {\n const text = this.#resolveText();\n let success = false;\n try {\n if (!navigator.clipboard?.writeText) throw new Error(\"Clipboard API unavailable\");\n await navigator.clipboard.writeText(text);\n success = true;\n } catch {\n success = false;\n }\n\n this.#reportResult(success);\n this.dispatch(\"copy\", { detail: { success, text } });\n }\n\n /**\n * The text to copy: the explicit `text` value when set, otherwise the source\n * target's current value (inputs/textareas) or text content.\n */\n #resolveText(): string {\n if (this.textValue.length > 0) return this.textValue;\n if (!this.hasSourceTarget) return \"\";\n const source = this.sourceTarget;\n if (source instanceof HTMLInputElement || source instanceof HTMLTextAreaElement) {\n return source.value;\n }\n return source.textContent ?? \"\";\n }\n\n /** Reflects the result on `data-state`, announces it, and schedules a reset. */\n #reportResult(success: boolean): void {\n this.element.setAttribute(\"data-state\", success ? \"copied\" : \"error\");\n if (this.hasFeedbackTarget) {\n this.feedbackTarget.textContent = success ? this.copiedLabelValue : this.errorLabelValue;\n }\n\n // Cancel any in-flight reset so consecutive copies restart the full window\n // rather than having the earlier timer clear the new notice prematurely.\n if (this.#resetTimerId !== null) {\n this.#timers.clear(this.#resetTimerId);\n this.#resetTimerId = null;\n }\n if (this.feedbackDurationValue > 0) {\n this.#resetTimerId = this.#timers.set(() => {\n this.#resetTimerId = null;\n this.#reset();\n }, this.feedbackDurationValue);\n }\n }\n\n /** Returns to the idle state and clears the completion notice. */\n #reset(): void {\n this.element.setAttribute(\"data-state\", \"idle\");\n if (this.hasFeedbackTarget) {\n this.feedbackTarget.textContent = \"\";\n }\n }\n}\n"]}
@@ -0,0 +1,70 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+
3
+ /**
4
+ * Headless, accessible single-disclosure (collapsible) behavior.
5
+ *
6
+ * Markup contract (identifier: `stimeo--collapsible`):
7
+ * <div data-controller="stimeo--collapsible">
8
+ * <button data-stimeo--collapsible-target="trigger"
9
+ * data-action="stimeo--collapsible#toggle"
10
+ * aria-expanded="false" aria-controls="more">Show details</button>
11
+ * <div id="more" data-stimeo--collapsible-target="content"
12
+ * data-state="closed" hidden>…</div>
13
+ * </div>
14
+ *
15
+ * Implements the WAI-ARIA APG **Disclosure** pattern for a single inline region.
16
+ * Unlike {@link AccordionController} it manages exactly one trigger/content pair
17
+ * with no sibling coordination, and unlike a dropdown the content expands in
18
+ * flow and never closes on an outside click.
19
+ *
20
+ * @remarks
21
+ * Behavior only — the consumer owns the height transition and all decoration.
22
+ * The controller keeps the open lifecycle ordered so `hidden` (effectively
23
+ * `display:none`) never blocks measurement or the transition:
24
+ * - **Open**: drop `hidden` → measure the natural height into
25
+ * `--stimeo-collapsible-content-height` → set `data-state="open"`.
26
+ * - **Close**: set `data-state="closed"` (CSS shrinks the height) → re-apply
27
+ * `hidden` once the transition settles. With no transition (or reduced motion,
28
+ * which the consumer's CSS expresses as a zero duration) it is applied
29
+ * immediately; an owned fallback covers missing terminal events.
30
+ */
31
+ declare class CollapsibleController extends Controller<HTMLElement> {
32
+ #private;
33
+ static targets: string[];
34
+ static values: {
35
+ open: {
36
+ type: BooleanConstructor;
37
+ default: boolean;
38
+ };
39
+ };
40
+ static actions: readonly ["toggle"];
41
+ readonly triggerTarget: HTMLElement;
42
+ readonly contentTarget: HTMLElement;
43
+ readonly hasTriggerTarget: boolean;
44
+ readonly hasContentTarget: boolean;
45
+ openValue: boolean;
46
+ /**
47
+ * Establishes the initial open/closed state without waiting for a close transition.
48
+ *
49
+ * The DOM is the source of truth on reconnect (Turbo cache restore / morph): an
50
+ * **explicit** state attribute — `aria-expanded="true"`/`"false"` (or, with no
51
+ * trigger, `data-state="open"`/`"closed"`) — is honored verbatim so a region the
52
+ * user opened *or* closed survives a back-navigation, even when the declarative
53
+ * `open` Value disagrees. An already-open region remains open without a
54
+ * close/reopen cycle. The Value only seeds a genuinely fresh render where no
55
+ * state attribute is present yet; any opening animation in that case belongs to
56
+ * the consumer's CSS. Mirrors `sidebar`'s `#restoreCollapsed`.
57
+ */
58
+ connect(): void;
59
+ disconnect(): void;
60
+ /** Reconciles a replacement trigger target with the content's live state. */
61
+ triggerTargetConnected(trigger: HTMLElement): void;
62
+ /** Reconciles a replacement content target with the disclosure's live state. */
63
+ contentTargetConnected(content: HTMLElement): void;
64
+ /** Cancels a wait tied to a content target that was removed or replaced. */
65
+ contentTargetDisconnected(): void;
66
+ /** Toggles the region open/closed. Bound via `data-action` (click). */
67
+ toggle(): void;
68
+ }
69
+
70
+ export { CollapsibleController };
@@ -0,0 +1,327 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+
3
+ // src/controllers/collapsible_controller.ts
4
+
5
+ // src/utils/safe_timeout.ts
6
+ var TimerRegistry = class {
7
+ /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */
8
+ ids = /* @__PURE__ */ new Set();
9
+ /**
10
+ * Cancels a single tracked timer.
11
+ *
12
+ * No-ops if the id is unknown (already cleared, fired, or never owned by this
13
+ * registry), so callers can clear defensively without guarding.
14
+ */
15
+ clear(id) {
16
+ if (this.ids.delete(id)) {
17
+ this.cancel(id);
18
+ }
19
+ }
20
+ /**
21
+ * Cancels every tracked timer. Call this from a controller's `disconnect()`
22
+ * to guarantee no timer outlives the element.
23
+ */
24
+ clearAll() {
25
+ for (const id of this.ids) {
26
+ this.cancel(id);
27
+ }
28
+ this.ids.clear();
29
+ }
30
+ /** Number of timers currently tracked (pending). */
31
+ get size() {
32
+ return this.ids.size;
33
+ }
34
+ };
35
+ var SafeTimeout = class extends TimerRegistry {
36
+ /**
37
+ * Schedules `callback` after `delay` ms and returns the timer id.
38
+ *
39
+ * The id is removed from the registry automatically when the timeout fires,
40
+ * so {@link TimerRegistry.size | size} reflects only still-pending timers.
41
+ */
42
+ set(callback, delay) {
43
+ const id = this.schedule(() => {
44
+ this.ids.delete(id);
45
+ callback();
46
+ }, delay);
47
+ this.ids.add(id);
48
+ return id;
49
+ }
50
+ schedule(callback, delay) {
51
+ return window.setTimeout(callback, delay);
52
+ }
53
+ cancel(id) {
54
+ window.clearTimeout(id);
55
+ }
56
+ };
57
+
58
+ // src/utils/transition_completion.ts
59
+ function timeMs(value) {
60
+ const trimmed = value.trim();
61
+ const amount = Number.parseFloat(trimmed);
62
+ if (!Number.isFinite(amount)) return 0;
63
+ if (trimmed.endsWith("ms")) return amount;
64
+ if (trimmed.endsWith("s")) return amount * 1e3;
65
+ return 0;
66
+ }
67
+ function cssList(value) {
68
+ return value.split(",").map((item) => item.trim()).filter(Boolean);
69
+ }
70
+ function transitionTimings(style) {
71
+ const properties = cssList(style.transitionProperty);
72
+ const durations = cssList(style.transitionDuration).map(timeMs);
73
+ const delays = cssList(style.transitionDelay).map(timeMs);
74
+ const effectiveProperties = properties.length > 0 ? properties : Array.from({ length: Math.max(durations.length, delays.length, 1) }, () => "all");
75
+ const effectiveDurations = durations.length > 0 ? durations : [0];
76
+ const effectiveDelays = delays.length > 0 ? delays : [0];
77
+ return effectiveProperties.filter((property) => property !== "none").map((property, index) => ({
78
+ property,
79
+ totalMs: Math.max(
80
+ 0,
81
+ (effectiveDurations[index % effectiveDurations.length] ?? 0) + (effectiveDelays[index % effectiveDelays.length] ?? 0)
82
+ )
83
+ }));
84
+ }
85
+ function maxTotalMs(timings) {
86
+ return timings.reduce((max, { totalMs }) => Math.max(max, totalMs), 0);
87
+ }
88
+ var TransitionCompletion = class {
89
+ #timers = new SafeTimeout();
90
+ #element = null;
91
+ #complete = null;
92
+ #pendingProperties = null;
93
+ #deadline = 0;
94
+ /**
95
+ * Replaces any prior wait and invokes `complete` synchronously for a 0ms
96
+ * transition (including when `getComputedStyle` is unavailable).
97
+ *
98
+ * With a positive `options.timeoutMs` the synchronous fast-path is skipped and
99
+ * the override replaces the auto-computed fallback (see {@link TransitionWaitOptions}).
100
+ */
101
+ wait(element, complete, options = {}) {
102
+ this.cancel();
103
+ const requested = options.timeoutMs ?? 0;
104
+ const override = Number.isFinite(requested) && requested > 0 ? requested : 0;
105
+ const timings = typeof window.getComputedStyle === "function" ? transitionTimings(window.getComputedStyle(element)) : [];
106
+ const maximum = maxTotalMs(timings);
107
+ if (maximum <= 0 && override <= 0) {
108
+ complete();
109
+ return;
110
+ }
111
+ this.#element = element;
112
+ this.#complete = complete;
113
+ this.#deadline = Date.now() + maximum;
114
+ const activeProperties = this.#activeTransitionProperties(element);
115
+ this.#pendingProperties = activeProperties.size > 0 ? activeProperties : this.#explicitPendingProperties(timings);
116
+ element.addEventListener("transitionend", this.#onTerminal);
117
+ element.addEventListener("transitioncancel", this.#onTerminal);
118
+ this.#timers.set(() => this.#finish(), override > 0 ? override : maximum + 50);
119
+ }
120
+ /** Cancels the pending wait without invoking its completion callback. */
121
+ cancel() {
122
+ this.#complete = null;
123
+ this.#teardown();
124
+ }
125
+ /**
126
+ * Handles terminal events from the observed element only.
127
+ *
128
+ * For explicit property lists, every declared positive-time property must
129
+ * settle. For `all`, no reliable property set exists, so an event can finish
130
+ * only after the computed maximum time; the safety timeout owns the usual path.
131
+ */
132
+ #onTerminal = (event) => {
133
+ if (event.target !== this.#element) return;
134
+ const transitionEvent = event;
135
+ if (transitionEvent.pseudoElement) return;
136
+ if (this.#pendingProperties) {
137
+ const propertyName = transitionEvent.propertyName;
138
+ const active = this.#activeTransitionProperties(this.#element);
139
+ if (active.has(propertyName)) return;
140
+ if (!this.#pendingProperties.delete(propertyName)) return;
141
+ if (this.#pendingProperties.size > 0) return;
142
+ if (active.size > 0) {
143
+ this.#pendingProperties = active;
144
+ return;
145
+ }
146
+ this.#finish();
147
+ return;
148
+ }
149
+ if (Date.now() >= this.#deadline) this.#finish();
150
+ };
151
+ /**
152
+ * Returns active CSS transition properties expanded to the names reported by
153
+ * terminal events. CSS animations and pseudo-element effects are excluded.
154
+ */
155
+ #activeTransitionProperties(element) {
156
+ if (!element || typeof element.getAnimations !== "function") return /* @__PURE__ */ new Set();
157
+ try {
158
+ const properties = element.getAnimations().flatMap((animation) => {
159
+ if (animation.playState === "idle" || animation.playState === "finished") return [];
160
+ const effect = animation.effect;
161
+ if (effect?.pseudoElement) return [];
162
+ const target = effect?.target;
163
+ if (target && target !== element) return [];
164
+ const property = animation.transitionProperty;
165
+ return typeof property === "string" && property.length > 0 ? [property] : [];
166
+ });
167
+ return new Set(properties);
168
+ } catch {
169
+ return /* @__PURE__ */ new Set();
170
+ }
171
+ }
172
+ /** Returns explicit positive-time properties, or `null` for the ambiguous `all`. */
173
+ #explicitPendingProperties(timings) {
174
+ if (timings.some(({ property }) => property === "all")) return null;
175
+ const pending = new Set(
176
+ timings.filter(({ totalMs }) => totalMs > 0).map(({ property }) => property)
177
+ );
178
+ return pending.size > 0 ? pending : null;
179
+ }
180
+ /** Completes exactly once, releasing listeners and the fallback before the callback. */
181
+ #finish() {
182
+ const complete = this.#complete;
183
+ if (!complete) return;
184
+ this.#complete = null;
185
+ this.#teardown();
186
+ complete();
187
+ }
188
+ /** Releases the exact element listeners and timer owned by the current wait. */
189
+ #teardown() {
190
+ this.#timers.clearAll();
191
+ this.#element?.removeEventListener("transitionend", this.#onTerminal);
192
+ this.#element?.removeEventListener("transitioncancel", this.#onTerminal);
193
+ this.#element = null;
194
+ this.#pendingProperties = null;
195
+ this.#deadline = 0;
196
+ }
197
+ };
198
+
199
+ // src/controllers/collapsible_controller.ts
200
+ var CollapsibleController = class extends Controller {
201
+ static targets = ["trigger", "content"];
202
+ static values = {
203
+ open: { type: Boolean, default: false }
204
+ };
205
+ static actions = ["toggle"];
206
+ /** Owns the cancellable close-transition wait and its bounded fallback. */
207
+ #transition = new TransitionCompletion();
208
+ /** Distinguishes dynamic target churn from the callbacks that precede `connect()`. */
209
+ #connected = false;
210
+ /**
211
+ * Establishes the initial open/closed state without waiting for a close transition.
212
+ *
213
+ * The DOM is the source of truth on reconnect (Turbo cache restore / morph): an
214
+ * **explicit** state attribute — `aria-expanded="true"`/`"false"` (or, with no
215
+ * trigger, `data-state="open"`/`"closed"`) — is honored verbatim so a region the
216
+ * user opened *or* closed survives a back-navigation, even when the declarative
217
+ * `open` Value disagrees. An already-open region remains open without a
218
+ * close/reopen cycle. The Value only seeds a genuinely fresh render where no
219
+ * state attribute is present yet; any opening animation in that case belongs to
220
+ * the consumer's CSS. Mirrors `sidebar`'s `#restoreCollapsed`.
221
+ */
222
+ connect() {
223
+ this.#connected = true;
224
+ this.#apply(this.#initialOpen(), false);
225
+ }
226
+ /** Resolves the connect-time state: explicit DOM state wins, else the `open` Value. */
227
+ #initialOpen() {
228
+ if (this.hasTriggerTarget) {
229
+ const expanded = this.triggerTarget.getAttribute("aria-expanded");
230
+ if (expanded === "true") return true;
231
+ if (expanded === "false") return false;
232
+ } else if (this.hasContentTarget) {
233
+ const state = this.contentTarget.getAttribute("data-state");
234
+ if (state === "open") return true;
235
+ if (state === "closed") return false;
236
+ }
237
+ return this.openValue;
238
+ }
239
+ disconnect() {
240
+ this.#connected = false;
241
+ this.#transition.cancel();
242
+ }
243
+ /** Reconciles a replacement trigger target with the content's live state. */
244
+ triggerTargetConnected(trigger) {
245
+ if (!this.#connected || !this.hasContentTarget) return;
246
+ trigger.setAttribute(
247
+ "aria-expanded",
248
+ this.contentTarget.getAttribute("data-state") === "open" ? "true" : "false"
249
+ );
250
+ }
251
+ /** Reconciles a replacement content target with the disclosure's live state. */
252
+ contentTargetConnected(content) {
253
+ if (!this.#connected) return;
254
+ this.#transition.cancel();
255
+ const open = this.hasTriggerTarget ? this.triggerTarget.getAttribute("aria-expanded") === "true" : content.getAttribute("data-state") === "open";
256
+ this.#applyContent(content, open, false);
257
+ }
258
+ /** Cancels a wait tied to a content target that was removed or replaced. */
259
+ contentTargetDisconnected() {
260
+ this.#transition.cancel();
261
+ }
262
+ /** Toggles the region open/closed. Bound via `data-action` (click). */
263
+ toggle() {
264
+ this.#apply(!this.#isOpen, true);
265
+ }
266
+ /**
267
+ * Whether the region is logically open. Read from `aria-expanded` (not the
268
+ * content's `hidden`) so a click *during* a close transition — when `hidden`
269
+ * is still deferred — correctly reopens instead of re-closing.
270
+ */
271
+ get #isOpen() {
272
+ if (this.hasTriggerTarget) {
273
+ return this.triggerTarget.getAttribute("aria-expanded") === "true";
274
+ }
275
+ return this.hasContentTarget && this.contentTarget.getAttribute("data-state") === "open";
276
+ }
277
+ /**
278
+ * Drives the disclosure to `open`, syncing the trigger's `aria-expanded` and
279
+ * the content's `hidden` / `data-state` / height variable in the order the
280
+ * spec requires.
281
+ *
282
+ * @param open - Target state.
283
+ * @param waitForCloseTransition - When `false` (initial `connect`) the close
284
+ * path applies `hidden` immediately. This flag does not suppress consumer CSS
285
+ * on the open path.
286
+ */
287
+ #apply(open, waitForCloseTransition) {
288
+ if (this.hasTriggerTarget) {
289
+ this.triggerTarget.setAttribute("aria-expanded", open ? "true" : "false");
290
+ }
291
+ if (!this.hasContentTarget) return;
292
+ const content = this.contentTarget;
293
+ this.#transition.cancel();
294
+ this.#applyContent(content, open, waitForCloseTransition);
295
+ }
296
+ /** Reflects one content target without relying on a later target lookup. */
297
+ #applyContent(content, open, waitForCloseTransition) {
298
+ if (open) {
299
+ content.hidden = false;
300
+ content.style.setProperty("--stimeo-collapsible-content-height", `${content.scrollHeight}px`);
301
+ content.setAttribute("data-state", "open");
302
+ return;
303
+ }
304
+ content.setAttribute("data-state", "closed");
305
+ if (waitForCloseTransition) {
306
+ this.#applyHiddenAfterTransition(content);
307
+ } else {
308
+ content.hidden = true;
309
+ }
310
+ }
311
+ /**
312
+ * Re-applies `hidden` once the close transition settles. Guarded against a
313
+ * reopen mid-transition; the shared waiter also guarantees a bounded fallback
314
+ * when the browser emits no terminal transition event.
315
+ */
316
+ #applyHiddenAfterTransition(content) {
317
+ this.#transition.wait(content, () => {
318
+ if (content.getAttribute("data-state") === "closed") {
319
+ content.hidden = true;
320
+ }
321
+ });
322
+ }
323
+ };
324
+
325
+ export { CollapsibleController };
326
+ //# sourceMappingURL=collapsible_controller.js.map
327
+ //# sourceMappingURL=collapsible_controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/safe_timeout.ts","../../src/utils/transition_completion.ts","../../src/controllers/collapsible_controller.ts"],"names":[],"mappings":";;;;;AAwBA,IAAe,gBAAf,MAA6B;AAAA;AAAA,EAER,GAAA,uBAAU,GAAA,EAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAczC,MAAM,EAAA,EAAkB;AACtB,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,MAAA,CAAO,EAAE,CAAA,EAAG;AACvB,MAAA,IAAA,CAAK,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U,IAAA,CAAK,aAAA;AACrB,IAAA,IAAA,CAAK,YAAY,MAAA,EAAO;AACxB,IAAA,IAAA,CAAK,aAAA,CAAc,OAAA,EAAS,IAAA,EAAM,sBAAsB,CAAA;AAAA,EAC1D;AAAA;AAAA,EAGA,aAAA,CAAc,OAAA,EAAsB,IAAA,EAAe,sBAAA,EAAuC;AACxF,IAAA,IAAI,IAAA,EAAM;AACR,MAAA,OAAA,CAAQ,MAAA,GAAS,KAAA;AAGjB,MAAA,OAAA,CAAQ,MAAM,WAAA,CAAY,qCAAA,EAAuC,CAAA,EAAG,OAAA,CAAQ,YAAY,CAAA,EAAA,CAAI,CAAA;AAC5F,MAAA,OAAA,CAAQ,YAAA,CAAa,cAAc,MAAM,CAAA;AACzC,MAAA;AAAA,IACF;AAEA,IAAA,OAAA,CAAQ,YAAA,CAAa,cAAc,QAAQ,CAAA;AAC3C,IAAA,IAAI,sBAAA,EAAwB;AAC1B,MAAA,IAAA,CAAK,4BAA4B,OAAO,CAAA;AAAA,IAC1C,CAAA,MAAO;AACL,MAAA,OAAA,CAAQ,MAAA,GAAS,IAAA;AAAA,IACnB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,4BAA4B,OAAA,EAA4B;AACtD,IAAA,IAAA,CAAK,WAAA,CAAY,IAAA,CAAK,OAAA,EAAS,MAAM;AACnC,MAAA,IAAI,OAAA,CAAQ,YAAA,CAAa,YAAY,CAAA,KAAM,QAAA,EAAU;AACnD,QAAA,OAAA,CAAQ,MAAA,GAAS,IAAA;AAAA,MACnB;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AACF","file":"collapsible_controller.js","sourcesContent":["/**\n * Self-cleaning timer registries shared by Stimeo controllers.\n *\n * Stimulus controllers frequently schedule `setTimeout` / `setInterval` work\n * (auto-dismiss, debouncing, polling). When the element leaves the DOM — a\n * Turbo Drive navigation, a Turbo Stream replacement, or any `disconnect()` —\n * orphaned timers keep firing against a detached controller, leaking memory and\n * mutating stale state. {@link SafeTimeout} and {@link SafeInterval} track every\n * timer they create so a single {@link TimerRegistry.clearAll | clearAll()} call\n * in `disconnect()` tears them all down.\n *\n * These are intentionally low-level primitives: they own *registration and\n * cleanup only*. Higher-level policy (pause/resume, remaining-time accounting)\n * stays in the individual controllers so per-widget semantics are not flattened\n * into a lowest-common-denominator helper.\n */\n\n/**\n * Shared registry bookkeeping for the timeout/interval variants.\n *\n * Subclasses provide the scheduling primitive ({@link schedule}) and its matching\n * canceller ({@link cancel}); this base owns the set of live ids plus the\n * per-id and bulk teardown shared by both.\n */\nabstract class TimerRegistry {\n /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */\n protected readonly ids = new Set<number>();\n\n /** Schedules the underlying platform timer and returns its id. */\n protected abstract schedule(callback: () => void, delay: number): number;\n\n /** Cancels the underlying platform timer for `id`. */\n protected abstract cancel(id: number): void;\n\n /**\n * Cancels a single tracked timer.\n *\n * No-ops if the id is unknown (already cleared, fired, or never owned by this\n * registry), so callers can clear defensively without guarding.\n */\n clear(id: number): void {\n if (this.ids.delete(id)) {\n this.cancel(id);\n }\n }\n\n /**\n * Cancels every tracked timer. Call this from a controller's `disconnect()`\n * to guarantee no timer outlives the element.\n */\n clearAll(): void {\n for (const id of this.ids) {\n this.cancel(id);\n }\n this.ids.clear();\n }\n\n /** Number of timers currently tracked (pending). */\n get size(): number {\n return this.ids.size;\n }\n}\n\n/**\n * `setTimeout` wrapper that auto-forgets each timer once it fires and supports\n * bulk teardown on disconnect.\n *\n * @example\n * ```ts\n * #timers = new SafeTimeout();\n *\n * connect() {\n * this.#timers.set(() => this.dismiss(), 5000);\n * }\n *\n * disconnect() {\n * this.#timers.clearAll();\n * }\n * ```\n */\nexport class SafeTimeout extends TimerRegistry {\n /**\n * Schedules `callback` after `delay` ms and returns the timer id.\n *\n * The id is removed from the registry automatically when the timeout fires,\n * so {@link TimerRegistry.size | size} reflects only still-pending timers.\n */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(() => {\n this.ids.delete(id);\n callback();\n }, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setTimeout(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearTimeout(id);\n }\n}\n\n/**\n * `setInterval` wrapper that tracks every interval for bulk teardown on\n * disconnect. Unlike {@link SafeTimeout}, intervals are retained until they are\n * explicitly cleared because they fire repeatedly.\n *\n * @example\n * ```ts\n * #intervals = new SafeInterval();\n *\n * connect() {\n * this.#intervals.set(() => this.tick(), 1000);\n * }\n *\n * disconnect() {\n * this.#intervals.clearAll();\n * }\n * ```\n */\nexport class SafeInterval extends TimerRegistry {\n /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(callback, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setInterval(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearInterval(id);\n }\n}\n","import { SafeTimeout } from \"./safe_timeout\";\n\n/** Computed transition fields needed to determine when an element has settled. */\nexport type TransitionStyle = Pick<\n CSSStyleDeclaration,\n \"transitionProperty\" | \"transitionDuration\" | \"transitionDelay\"\n>;\n\n/** Parsed transition property paired with its effective duration and delay. */\ninterface TransitionTiming {\n property: string;\n totalMs: number;\n}\n\n/** Parses a CSS `<time>` into milliseconds, returning `0` for malformed values. */\nfunction timeMs(value: string): number {\n const trimmed = value.trim();\n const amount = Number.parseFloat(trimmed);\n if (!Number.isFinite(amount)) return 0;\n if (trimmed.endsWith(\"ms\")) return amount;\n if (trimmed.endsWith(\"s\")) return amount * 1000;\n return 0;\n}\n\n/** Splits a computed comma-separated CSS list into normalized, non-empty items. */\nfunction cssList(value: string): string[] {\n return value\n .split(\",\")\n .map((item) => item.trim())\n .filter(Boolean);\n}\n\n/**\n * Pairs transition properties, durations, and delays using CSS list repetition.\n *\n * The `transition-property` list determines the number of transitions. Shorter\n * duration/delay lists repeat, while extra values are ignored. A negative delay\n * shortens the remaining wall-clock time, and a non-positive total is settled.\n */\nfunction transitionTimings(style: TransitionStyle): TransitionTiming[] {\n const properties = cssList(style.transitionProperty);\n const durations = cssList(style.transitionDuration).map(timeMs);\n const delays = cssList(style.transitionDelay).map(timeMs);\n const effectiveProperties =\n properties.length > 0\n ? properties\n : Array.from({ length: Math.max(durations.length, delays.length, 1) }, () => \"all\");\n const effectiveDurations = durations.length > 0 ? durations : [0];\n const effectiveDelays = delays.length > 0 ? delays : [0];\n\n return effectiveProperties\n .filter((property) => property !== \"none\")\n .map((property, index) => ({\n property,\n totalMs: Math.max(\n 0,\n (effectiveDurations[index % effectiveDurations.length] ?? 0) +\n (effectiveDelays[index % effectiveDelays.length] ?? 0),\n ),\n }));\n}\n\n/** Maximum total over already-parsed timings (0 when the list is empty). */\nfunction maxTotalMs(timings: TransitionTiming[]): number {\n return timings.reduce((max, { totalMs }) => Math.max(max, totalMs), 0);\n}\n\n/** Maximum effective transition duration plus delay, in milliseconds. */\nexport function maxTransitionTotalMs(style: TransitionStyle): number {\n return maxTotalMs(transitionTimings(style));\n}\n\n/** Optional tuning for a single {@link TransitionCompletion.wait} call. */\nexport interface TransitionWaitOptions {\n /**\n * Positive wall-clock override (ms) for the bounded fallback, replacing the\n * auto-computed `max + 50ms` timer verbatim. It also keeps the wait armed for\n * a computed 0ms transition (no synchronous completion): the consumer asserts\n * a transition budget that computed styles cannot see. Non-positive and\n * non-finite (`NaN` / `Infinity`) values are ignored.\n */\n timeoutMs?: number;\n}\n\n/**\n * Owns one cancellable wait for an element's CSS transitions to settle.\n *\n * When available, active CSS transitions provide their expanded property names.\n * Tracking those names lets shorthand declarations settle from their longhand\n * terminal events. A terminal event from an interrupted phase is ignored while a\n * replacement transition for the same property is still active. Because that set\n * is sampled when the wait is armed, a property whose transition only starts a\n * frame later would otherwise be settled over; the still-running set is therefore\n * re-read before completing and adopted when it is not yet empty. Without Web\n * Animations data, explicit transition properties retain the declared-property\n * behavior and the ambiguous `transition-property: all` form waits until the\n * computed maximum wall-clock time. A `max + 50ms` timeout is always armed\n * because browsers emit no terminal event when a property never transitions, an\n * ancestor disappears, or rendering is otherwise interrupted; a consumer with\n * better knowledge can replace that fallback via\n * {@link TransitionWaitOptions.timeoutMs}.\n */\nexport class TransitionCompletion {\n readonly #timers = new SafeTimeout();\n #element: HTMLElement | null = null;\n #complete: (() => void) | null = null;\n #pendingProperties: Set<string> | null = null;\n #deadline = 0;\n\n /**\n * Replaces any prior wait and invokes `complete` synchronously for a 0ms\n * transition (including when `getComputedStyle` is unavailable).\n *\n * With a positive `options.timeoutMs` the synchronous fast-path is skipped and\n * the override replaces the auto-computed fallback (see {@link TransitionWaitOptions}).\n */\n wait(element: HTMLElement, complete: () => void, options: TransitionWaitOptions = {}): void {\n this.cancel();\n\n const requested = options.timeoutMs ?? 0;\n const override = Number.isFinite(requested) && requested > 0 ? requested : 0;\n // A non-browser / partial-DOM environment cannot report a computable\n // transition, which is indistinguishable from a 0ms one.\n const timings =\n typeof window.getComputedStyle === \"function\"\n ? transitionTimings(window.getComputedStyle(element))\n : [];\n const maximum = maxTotalMs(timings);\n if (maximum <= 0 && override <= 0) {\n complete();\n return;\n }\n\n this.#element = element;\n this.#complete = complete;\n this.#deadline = Date.now() + maximum;\n const activeProperties = this.#activeTransitionProperties(element);\n this.#pendingProperties =\n activeProperties.size > 0 ? activeProperties : this.#explicitPendingProperties(timings);\n element.addEventListener(\"transitionend\", this.#onTerminal);\n element.addEventListener(\"transitioncancel\", this.#onTerminal);\n this.#timers.set(() => this.#finish(), override > 0 ? override : maximum + 50);\n }\n\n /** Cancels the pending wait without invoking its completion callback. */\n cancel(): void {\n this.#complete = null;\n this.#teardown();\n }\n\n /**\n * Handles terminal events from the observed element only.\n *\n * For explicit property lists, every declared positive-time property must\n * settle. For `all`, no reliable property set exists, so an event can finish\n * only after the computed maximum time; the safety timeout owns the usual path.\n */\n readonly #onTerminal = (event: Event): void => {\n if (event.target !== this.#element) return;\n const transitionEvent = event as TransitionEvent;\n // A pseudo-element's transition is reported with its originating element\n // as `target`; it must not settle the element's own transition.\n if (transitionEvent.pseudoElement) return;\n\n if (this.#pendingProperties) {\n const propertyName = transitionEvent.propertyName;\n const active = this.#activeTransitionProperties(this.#element);\n // An interrupted transition queues its cancel event before the replacement\n // phase starts, but dispatch can happen after the new wait is armed. The\n // replacement is then the active transition for this property, so the stale\n // terminal event must not settle the new phase.\n if (active.has(propertyName)) return;\n if (!this.#pendingProperties.delete(propertyName)) return;\n if (this.#pendingProperties.size > 0) return;\n // The tracked set is an arm-time snapshot, so a transition the phase starts\n // one frame later is absent from it. Re-reading the still-running set before\n // settling adopts those stragglers instead of completing over them; the\n // fallback timer stays armed, so this cannot extend the wait unboundedly.\n if (active.size > 0) {\n this.#pendingProperties = active;\n return;\n }\n this.#finish();\n return;\n }\n\n if (Date.now() >= this.#deadline) this.#finish();\n };\n\n /**\n * Returns active CSS transition properties expanded to the names reported by\n * terminal events. CSS animations and pseudo-element effects are excluded.\n */\n #activeTransitionProperties(element: HTMLElement | null): Set<string> {\n if (!element || typeof element.getAnimations !== \"function\") return new Set();\n\n try {\n const properties = element.getAnimations().flatMap((animation) => {\n if (animation.playState === \"idle\" || animation.playState === \"finished\") return [];\n const effect = animation.effect as KeyframeEffect | null;\n // A pseudo-element effect names the originating element as its target, so\n // `target` alone cannot separate it. Its terminal events are ignored, so\n // tracking its properties would only strand the wait on the fallback.\n if (effect?.pseudoElement) return [];\n const target = effect?.target;\n if (target && target !== element) return [];\n const property = (animation as Partial<CSSTransition>).transitionProperty;\n return typeof property === \"string\" && property.length > 0 ? [property] : [];\n });\n return new Set(properties);\n } catch {\n // Partial DOM implementations can expose getAnimations without supporting\n // it. The declared-property tracker and bounded timer remain safe fallbacks.\n return new Set();\n }\n }\n\n /** Returns explicit positive-time properties, or `null` for the ambiguous `all`. */\n #explicitPendingProperties(timings: TransitionTiming[]): Set<string> | null {\n if (timings.some(({ property }) => property === \"all\")) return null;\n const pending = new Set(\n timings.filter(({ totalMs }) => totalMs > 0).map(({ property }) => property),\n );\n // An empty set is only reachable through a timeout override (a 0ms transition\n // otherwise completes synchronously). With nothing to track, fall back to the\n // deadline rule so any terminal event can settle the wait, exactly like `all`.\n return pending.size > 0 ? pending : null;\n }\n\n /** Completes exactly once, releasing listeners and the fallback before the callback. */\n #finish(): void {\n const complete = this.#complete;\n if (!complete) return;\n this.#complete = null;\n this.#teardown();\n complete();\n }\n\n /** Releases the exact element listeners and timer owned by the current wait. */\n #teardown(): void {\n this.#timers.clearAll();\n this.#element?.removeEventListener(\"transitionend\", this.#onTerminal);\n this.#element?.removeEventListener(\"transitioncancel\", this.#onTerminal);\n this.#element = null;\n this.#pendingProperties = null;\n this.#deadline = 0;\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { TransitionCompletion } from \"../utils/transition_completion\";\n\n/**\n * Headless, accessible single-disclosure (collapsible) behavior.\n *\n * Markup contract (identifier: `stimeo--collapsible`):\n * <div data-controller=\"stimeo--collapsible\">\n * <button data-stimeo--collapsible-target=\"trigger\"\n * data-action=\"stimeo--collapsible#toggle\"\n * aria-expanded=\"false\" aria-controls=\"more\">Show details</button>\n * <div id=\"more\" data-stimeo--collapsible-target=\"content\"\n * data-state=\"closed\" hidden>…</div>\n * </div>\n *\n * Implements the WAI-ARIA APG **Disclosure** pattern for a single inline region.\n * Unlike {@link AccordionController} it manages exactly one trigger/content pair\n * with no sibling coordination, and unlike a dropdown the content expands in\n * flow and never closes on an outside click.\n *\n * @remarks\n * Behavior only — the consumer owns the height transition and all decoration.\n * The controller keeps the open lifecycle ordered so `hidden` (effectively\n * `display:none`) never blocks measurement or the transition:\n * - **Open**: drop `hidden` → measure the natural height into\n * `--stimeo-collapsible-content-height` → set `data-state=\"open\"`.\n * - **Close**: set `data-state=\"closed\"` (CSS shrinks the height) → re-apply\n * `hidden` once the transition settles. With no transition (or reduced motion,\n * which the consumer's CSS expresses as a zero duration) it is applied\n * immediately; an owned fallback covers missing terminal events.\n */\nexport class CollapsibleController extends Controller<HTMLElement> {\n static override targets = [\"trigger\", \"content\"];\n static override values = {\n open: { type: Boolean, default: false },\n };\n static actions = [\"toggle\"] as const;\n\n declare readonly triggerTarget: HTMLElement;\n declare readonly contentTarget: HTMLElement;\n declare readonly hasTriggerTarget: boolean;\n declare readonly hasContentTarget: boolean;\n\n declare openValue: boolean;\n\n /** Owns the cancellable close-transition wait and its bounded fallback. */\n readonly #transition = new TransitionCompletion();\n /** Distinguishes dynamic target churn from the callbacks that precede `connect()`. */\n #connected = false;\n\n /**\n * Establishes the initial open/closed state without waiting for a close transition.\n *\n * The DOM is the source of truth on reconnect (Turbo cache restore / morph): an\n * **explicit** state attribute — `aria-expanded=\"true\"`/`\"false\"` (or, with no\n * trigger, `data-state=\"open\"`/`\"closed\"`) — is honored verbatim so a region the\n * user opened *or* closed survives a back-navigation, even when the declarative\n * `open` Value disagrees. An already-open region remains open without a\n * close/reopen cycle. The Value only seeds a genuinely fresh render where no\n * state attribute is present yet; any opening animation in that case belongs to\n * the consumer's CSS. Mirrors `sidebar`'s `#restoreCollapsed`.\n */\n override connect(): void {\n this.#connected = true;\n this.#apply(this.#initialOpen(), false);\n }\n\n /** Resolves the connect-time state: explicit DOM state wins, else the `open` Value. */\n #initialOpen(): boolean {\n if (this.hasTriggerTarget) {\n const expanded = this.triggerTarget.getAttribute(\"aria-expanded\");\n if (expanded === \"true\") return true;\n if (expanded === \"false\") return false;\n } else if (this.hasContentTarget) {\n const state = this.contentTarget.getAttribute(\"data-state\");\n if (state === \"open\") return true;\n if (state === \"closed\") return false;\n }\n return this.openValue;\n }\n\n override disconnect(): void {\n this.#connected = false;\n this.#transition.cancel();\n }\n\n /** Reconciles a replacement trigger target with the content's live state. */\n triggerTargetConnected(trigger: HTMLElement): void {\n if (!this.#connected || !this.hasContentTarget) return;\n trigger.setAttribute(\n \"aria-expanded\",\n this.contentTarget.getAttribute(\"data-state\") === \"open\" ? \"true\" : \"false\",\n );\n }\n\n /** Reconciles a replacement content target with the disclosure's live state. */\n contentTargetConnected(content: HTMLElement): void {\n if (!this.#connected) return;\n this.#transition.cancel();\n const open = this.hasTriggerTarget\n ? this.triggerTarget.getAttribute(\"aria-expanded\") === \"true\"\n : content.getAttribute(\"data-state\") === \"open\";\n this.#applyContent(content, open, false);\n }\n\n /** Cancels a wait tied to a content target that was removed or replaced. */\n contentTargetDisconnected(): void {\n this.#transition.cancel();\n }\n\n /** Toggles the region open/closed. Bound via `data-action` (click). */\n toggle(): void {\n this.#apply(!this.#isOpen, true);\n }\n\n /**\n * Whether the region is logically open. Read from `aria-expanded` (not the\n * content's `hidden`) so a click *during* a close transition — when `hidden`\n * is still deferred — correctly reopens instead of re-closing.\n */\n get #isOpen(): boolean {\n if (this.hasTriggerTarget) {\n return this.triggerTarget.getAttribute(\"aria-expanded\") === \"true\";\n }\n return this.hasContentTarget && this.contentTarget.getAttribute(\"data-state\") === \"open\";\n }\n\n /**\n * Drives the disclosure to `open`, syncing the trigger's `aria-expanded` and\n * the content's `hidden` / `data-state` / height variable in the order the\n * spec requires.\n *\n * @param open - Target state.\n * @param waitForCloseTransition - When `false` (initial `connect`) the close\n * path applies `hidden` immediately. This flag does not suppress consumer CSS\n * on the open path.\n */\n #apply(open: boolean, waitForCloseTransition: boolean): void {\n if (this.hasTriggerTarget) {\n this.triggerTarget.setAttribute(\"aria-expanded\", open ? \"true\" : \"false\");\n }\n if (!this.hasContentTarget) return;\n\n const content = this.contentTarget;\n this.#transition.cancel();\n this.#applyContent(content, open, waitForCloseTransition);\n }\n\n /** Reflects one content target without relying on a later target lookup. */\n #applyContent(content: HTMLElement, open: boolean, waitForCloseTransition: boolean): void {\n if (open) {\n content.hidden = false;\n // Measure the natural height only once it is laid out (hidden removed) so\n // the consumer's `height` transition has a concrete target to animate to.\n content.style.setProperty(\"--stimeo-collapsible-content-height\", `${content.scrollHeight}px`);\n content.setAttribute(\"data-state\", \"open\");\n return;\n }\n\n content.setAttribute(\"data-state\", \"closed\");\n if (waitForCloseTransition) {\n this.#applyHiddenAfterTransition(content);\n } else {\n content.hidden = true;\n }\n }\n\n /**\n * Re-applies `hidden` once the close transition settles. Guarded against a\n * reopen mid-transition; the shared waiter also guarantees a bounded fallback\n * when the browser emits no terminal transition event.\n */\n #applyHiddenAfterTransition(content: HTMLElement): void {\n this.#transition.wait(content, () => {\n if (content.getAttribute(\"data-state\") === \"closed\") {\n content.hidden = true;\n }\n });\n }\n}\n"]}
@@ -0,0 +1,76 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+
3
+ /**
4
+ * Headless, accessible **Color Picker** behavior.
5
+ *
6
+ * Markup contract (identifier: `stimeo--color-picker`):
7
+ * <div data-controller="stimeo--color-picker"
8
+ * data-stimeo--color-picker-value-value="#3366cc">
9
+ * <div role="slider" aria-label="Hue" data-channel="hue" tabindex="0"
10
+ * aria-valuemin="0" aria-valuemax="360" aria-valuenow="210"
11
+ * data-stimeo--color-picker-target="slider"
12
+ * data-action="keydown->stimeo--color-picker#onKeydown
13
+ * pointerdown->stimeo--color-picker#onPointerDown"></div>
14
+ * <!-- saturation / lightness / alpha sliders share the same contract -->
15
+ * <input type="text" aria-label="Hex color"
16
+ * data-stimeo--color-picker-target="hex"
17
+ * data-action="change->stimeo--color-picker#onHexInput" />
18
+ * <div data-stimeo--color-picker-target="preview" aria-hidden="true"></div>
19
+ * <input type="hidden" data-stimeo--color-picker-target="field" />
20
+ * </div>
21
+ *
22
+ * Decomposes color selection into independent APG **Slider** channels (hue,
23
+ * saturation, lightness, optional alpha) instead of a 2-D palette, so every
24
+ * adjustment is keyboard- and screen-reader-operable. Each slider exposes
25
+ * `aria-valuenow` and a human-readable `aria-valuetext` (e.g. "Hue 210 degrees");
26
+ * the hex input stays two-way synced; the current color is published on the
27
+ * preview and root as the `--stimeo-color` custom property and mirrored into a
28
+ * hidden form field.
29
+ *
30
+ * @remarks
31
+ * Behavior only — the swatch/gradient visuals are the consumer's CSS/canvas, fed
32
+ * by `--stimeo-color`. Pointer-drag listeners on `document` are bound to an
33
+ * {@link AbortController} and released on drag end and on `disconnect()` (Turbo
34
+ * navigation included). Color is fully reconstructable from the `value` (hex), so
35
+ * there is no transient state to restore after a Turbo cache/morph.
36
+ *
37
+ * The internal model is integer HSL(A), so a hex → HSL → hex round-trip is not
38
+ * exactly bijective: a typed hex can normalize to a near (not identical) value
39
+ * once the HSL sliders are touched. This keeps the model small and zero-dep; use a
40
+ * dedicated color library on the consumer side if exact hex preservation matters.
41
+ */
42
+ declare class ColorPickerController extends Controller<HTMLElement> {
43
+ #private;
44
+ static targets: string[];
45
+ static values: {
46
+ value: {
47
+ type: StringConstructor;
48
+ default: string;
49
+ };
50
+ alpha: {
51
+ type: BooleanConstructor;
52
+ default: boolean;
53
+ };
54
+ };
55
+ static actions: readonly ["onHexInput", "onKeydown", "onPointerDown"];
56
+ static events: readonly ["change"];
57
+ readonly sliderTargets: HTMLElement[];
58
+ readonly hexTarget: HTMLInputElement;
59
+ readonly hasHexTarget: boolean;
60
+ readonly previewTargets: HTMLElement[];
61
+ readonly fieldTargets: HTMLInputElement[];
62
+ valueValue: string;
63
+ alphaValue: boolean;
64
+ /** Seeds the model from the initial hex value and renders every surface. */
65
+ connect(): void;
66
+ /** Cancels any active pointer drag so document listeners never leak. */
67
+ disconnect(): void;
68
+ /** Keyboard stepping on the focused channel slider (APG Slider model). */
69
+ onKeydown(event: KeyboardEvent): void;
70
+ /** Begins a pointer drag on a channel slider and tracks movement. */
71
+ onPointerDown(event: PointerEvent): void;
72
+ /** Parses the hex input on confirm and syncs every channel + surface. */
73
+ onHexInput(): void;
74
+ }
75
+
76
+ export { ColorPickerController };