stimeo-ui 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist/controllers/accordion_controller.js.map +1 -1
  3. package/dist/controllers/alert_dialog_controller.js +17 -7
  4. package/dist/controllers/alert_dialog_controller.js.map +1 -1
  5. package/dist/controllers/announcer_controller.js +1 -1
  6. package/dist/controllers/announcer_controller.js.map +1 -1
  7. package/dist/controllers/auto_submit_controller.js.map +1 -1
  8. package/dist/controllers/avatar_controller.js.map +1 -1
  9. package/dist/controllers/breadcrumb_controller.js.map +1 -1
  10. package/dist/controllers/bulk_select_controller.js +2 -2
  11. package/dist/controllers/bulk_select_controller.js.map +1 -1
  12. package/dist/controllers/calendar_controller.js.map +1 -1
  13. package/dist/controllers/carousel_controller.js.map +1 -1
  14. package/dist/controllers/character_counter_controller.js.map +1 -1
  15. package/dist/controllers/clipboard_controller.js.map +1 -1
  16. package/dist/controllers/collapsible_controller.d.ts +1 -1
  17. package/dist/controllers/collapsible_controller.js +1 -1
  18. package/dist/controllers/collapsible_controller.js.map +1 -1
  19. package/dist/controllers/color_picker_controller.d.ts +1 -1
  20. package/dist/controllers/color_picker_controller.js.map +1 -1
  21. package/dist/controllers/combobox_controller.js.map +1 -1
  22. package/dist/controllers/command_palette_controller.js +15 -5
  23. package/dist/controllers/command_palette_controller.js.map +1 -1
  24. package/dist/controllers/conditional_fields_controller.js.map +1 -1
  25. package/dist/controllers/confirm_controller.js +15 -5
  26. package/dist/controllers/confirm_controller.js.map +1 -1
  27. package/dist/controllers/context_menu_controller.d.ts +5 -4
  28. package/dist/controllers/context_menu_controller.js.map +1 -1
  29. package/dist/controllers/count_up_controller.js.map +1 -1
  30. package/dist/controllers/countdown_controller.js +1 -1
  31. package/dist/controllers/countdown_controller.js.map +1 -1
  32. package/dist/controllers/data_grid_controller.js +1 -1
  33. package/dist/controllers/data_grid_controller.js.map +1 -1
  34. package/dist/controllers/date_range_picker_controller.js.map +1 -1
  35. package/dist/controllers/dialog_controller.js +15 -5
  36. package/dist/controllers/dialog_controller.js.map +1 -1
  37. package/dist/controllers/direct_upload_controller.d.ts +2 -2
  38. package/dist/controllers/direct_upload_controller.js +1 -5
  39. package/dist/controllers/direct_upload_controller.js.map +1 -1
  40. package/dist/controllers/dismissible_controller.js.map +1 -1
  41. package/dist/controllers/drawer_controller.d.ts +2 -2
  42. package/dist/controllers/drawer_controller.js +17 -7
  43. package/dist/controllers/drawer_controller.js.map +1 -1
  44. package/dist/controllers/file_dropzone_controller.js.map +1 -1
  45. package/dist/controllers/flash_controller.js.map +1 -1
  46. package/dist/controllers/focus_controller.d.ts +5 -0
  47. package/dist/controllers/focus_controller.js +45 -7
  48. package/dist/controllers/focus_controller.js.map +1 -1
  49. package/dist/controllers/form_field_controller.js +1 -1
  50. package/dist/controllers/form_field_controller.js.map +1 -1
  51. package/dist/controllers/form_validation_controller.js.map +1 -1
  52. package/dist/controllers/frame_loading_controller.js.map +1 -1
  53. package/dist/controllers/highlight_controller.js.map +1 -1
  54. package/dist/controllers/input_mask_controller.js.map +1 -1
  55. package/dist/controllers/intersection_controller.d.ts +4 -3
  56. package/dist/controllers/intersection_controller.js.map +1 -1
  57. package/dist/controllers/lazy_frame_controller.d.ts +2 -2
  58. package/dist/controllers/lazy_frame_controller.js.map +1 -1
  59. package/dist/controllers/listbox_controller.js.map +1 -1
  60. package/dist/controllers/masonry_controller.d.ts +3 -1
  61. package/dist/controllers/masonry_controller.js.map +1 -1
  62. package/dist/controllers/menu_controller.d.ts +1 -1
  63. package/dist/controllers/menu_controller.js.map +1 -1
  64. package/dist/controllers/menubar_controller.js +2 -2
  65. package/dist/controllers/menubar_controller.js.map +1 -1
  66. package/dist/controllers/meter_controller.d.ts +1 -1
  67. package/dist/controllers/meter_controller.js.map +1 -1
  68. package/dist/controllers/multi_select_controller.js +1 -1
  69. package/dist/controllers/multi_select_controller.js.map +1 -1
  70. package/dist/controllers/navigation_menu_controller.js.map +1 -1
  71. package/dist/controllers/nested_form_controller.js.map +1 -1
  72. package/dist/controllers/number_input_controller.js.map +1 -1
  73. package/dist/controllers/otp_controller.js.map +1 -1
  74. package/dist/controllers/overflow_indicator_controller.js.map +1 -1
  75. package/dist/controllers/overflow_menu_controller.js +2 -2
  76. package/dist/controllers/overflow_menu_controller.js.map +1 -1
  77. package/dist/controllers/pagination_controller.d.ts +1 -1
  78. package/dist/controllers/pagination_controller.js.map +1 -1
  79. package/dist/controllers/password_reveal_controller.d.ts +27 -2
  80. package/dist/controllers/password_reveal_controller.js +102 -3
  81. package/dist/controllers/password_reveal_controller.js.map +1 -1
  82. package/dist/controllers/password_strength_controller.d.ts +71 -17
  83. package/dist/controllers/password_strength_controller.js +287 -42
  84. package/dist/controllers/password_strength_controller.js.map +1 -1
  85. package/dist/controllers/pointer_drag_controller.d.ts +3 -2
  86. package/dist/controllers/pointer_drag_controller.js.map +1 -1
  87. package/dist/controllers/popover_controller.js.map +1 -1
  88. package/dist/controllers/portal_controller.d.ts +1 -1
  89. package/dist/controllers/portal_controller.js.map +1 -1
  90. package/dist/controllers/progress_controller.js.map +1 -1
  91. package/dist/controllers/radio_group_controller.js.map +1 -1
  92. package/dist/controllers/range_slider_controller.js.map +1 -1
  93. package/dist/controllers/rating_controller.js.map +1 -1
  94. package/dist/controllers/read_more_controller.js.map +1 -1
  95. package/dist/controllers/relative_time_controller.js.map +1 -1
  96. package/dist/controllers/reset_before_cache_controller.d.ts +1 -2
  97. package/dist/controllers/reset_before_cache_controller.js.map +1 -1
  98. package/dist/controllers/resizable_controller.d.ts +1 -1
  99. package/dist/controllers/resizable_controller.js +1 -1
  100. package/dist/controllers/resizable_controller.js.map +1 -1
  101. package/dist/controllers/roving_controller.d.ts +2 -1
  102. package/dist/controllers/roving_controller.js.map +1 -1
  103. package/dist/controllers/scroll_area_controller.js.map +1 -1
  104. package/dist/controllers/scroll_restore_controller.d.ts +33 -11
  105. package/dist/controllers/scroll_restore_controller.js +127 -27
  106. package/dist/controllers/scroll_restore_controller.js.map +1 -1
  107. package/dist/controllers/scroll_visibility_controller.d.ts +42 -10
  108. package/dist/controllers/scroll_visibility_controller.js +167 -14
  109. package/dist/controllers/scroll_visibility_controller.js.map +1 -1
  110. package/dist/controllers/scrollspy_controller.js.map +1 -1
  111. package/dist/controllers/separator_controller.js.map +1 -1
  112. package/dist/controllers/sidebar_controller.js +15 -5
  113. package/dist/controllers/sidebar_controller.js.map +1 -1
  114. package/dist/controllers/skeleton_controller.js.map +1 -1
  115. package/dist/controllers/slider_controller.js.map +1 -1
  116. package/dist/controllers/spinner_controller.js.map +1 -1
  117. package/dist/controllers/step_indicator_controller.js +0 -5
  118. package/dist/controllers/step_indicator_controller.js.map +1 -1
  119. package/dist/controllers/stick_to_bottom_controller.d.ts +3 -2
  120. package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
  121. package/dist/controllers/submit_once_controller.js.map +1 -1
  122. package/dist/controllers/switch_controller.js.map +1 -1
  123. package/dist/controllers/tabs_controller.js.map +1 -1
  124. package/dist/controllers/tags_input_controller.js.map +1 -1
  125. package/dist/controllers/textarea_autosize_controller.js.map +1 -1
  126. package/dist/controllers/theme_controller.d.ts +32 -6
  127. package/dist/controllers/theme_controller.js +151 -40
  128. package/dist/controllers/theme_controller.js.map +1 -1
  129. package/dist/controllers/time_picker_controller.js.map +1 -1
  130. package/dist/controllers/toast_controller.d.ts +2 -2
  131. package/dist/controllers/toast_controller.js +2 -2
  132. package/dist/controllers/toast_controller.js.map +1 -1
  133. package/dist/controllers/toggle_group_controller.js.map +1 -1
  134. package/dist/controllers/toolbar_controller.js.map +1 -1
  135. package/dist/controllers/transition_controller.d.ts +11 -7
  136. package/dist/controllers/transition_controller.js +79 -15
  137. package/dist/controllers/transition_controller.js.map +1 -1
  138. package/dist/controllers/tree_view_controller.js.map +1 -1
  139. package/dist/index.d.ts +6 -3
  140. package/dist/index.js +740 -178
  141. package/dist/index.js.map +1 -1
  142. package/dist/inspector/cli.d.ts +3 -4
  143. package/dist/inspector/cli.js +1 -0
  144. package/dist/inspector/cli.js.map +1 -1
  145. package/dist/inspector/cli_bin.js +6 -5
  146. package/dist/inspector/cli_bin.js.map +1 -1
  147. package/dist/inspector/examples.json +3 -3
  148. package/dist/inspector/manifest.json +7 -4
  149. package/dist/positioning/index.d.ts +18 -4
  150. package/dist/positioning/index.js +84 -25
  151. package/dist/positioning/index.js.map +1 -1
  152. package/package.json +5 -5
@@ -2,6 +2,35 @@ import { Controller } from '@hotwired/stimulus';
2
2
 
3
3
  // src/controllers/transition_controller.ts
4
4
 
5
+ // src/utils/before_cache_reset.ts
6
+ var BeforeCacheReset = class _BeforeCacheReset {
7
+ /** Every subscribed instance, iterated by the one shared document listener. */
8
+ static #subscribers = /* @__PURE__ */ new Set();
9
+ /** The shared listener; installed while at least one instance is subscribed. */
10
+ static #onBeforeCache = () => {
11
+ for (const subscriber of _BeforeCacheReset.#subscribers) subscriber.#rewind();
12
+ };
13
+ #rewind;
14
+ /** @param rewind - the pass that returns this controller's state to its initial form. */
15
+ constructor(rewind) {
16
+ this.#rewind = rewind;
17
+ }
18
+ /** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */
19
+ activate() {
20
+ const first = _BeforeCacheReset.#subscribers.size === 0;
21
+ _BeforeCacheReset.#subscribers.add(this);
22
+ if (first) {
23
+ document.addEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
24
+ }
25
+ }
26
+ /** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */
27
+ deactivate() {
28
+ _BeforeCacheReset.#subscribers.delete(this);
29
+ if (_BeforeCacheReset.#subscribers.size > 0) return;
30
+ document.removeEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
31
+ }
32
+ };
33
+
5
34
  // src/utils/reduced_motion.ts
6
35
  function prefersReducedMotion() {
7
36
  return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
@@ -217,12 +246,21 @@ var TransitionController = class extends Controller {
217
246
  static events = ["entered", "left"];
218
247
  /** Owns the cancellable completion wait (terminal events + bounded fallback). */
219
248
  #transition = new TransitionCompletion();
249
+ /** Rewinds a half-applied stage before Turbo copies the page into its snapshot. */
250
+ #beforeCache = new BeforeCacheReset(() => this.#rewindForCache());
220
251
  #rafId = null;
252
+ /**
253
+ * Stage classes this controller put on the element. Removing by declaration
254
+ * instead would take a token the consumer also authored, and would strand the
255
+ * token that was applied when a Value changes mid-transition.
256
+ */
257
+ #staged = /* @__PURE__ */ new Set();
221
258
  connect() {
222
- this.#strip();
223
- this.element.setAttribute("data-transition-state", this.element.hidden ? "left" : "entered");
259
+ this.#beforeCache.activate();
260
+ this.#settleState();
224
261
  }
225
262
  disconnect() {
263
+ this.#beforeCache.deactivate();
226
264
  this.#cancel();
227
265
  }
228
266
  /** Shows the element with the enter transition. */
@@ -252,6 +290,7 @@ var TransitionController = class extends Controller {
252
290
  const from = isEnter ? this.enterFromValue : this.leaveFromValue;
253
291
  const to = isEnter ? this.enterToValue : this.leaveToValue;
254
292
  this.#add(base, from);
293
+ void this.element.offsetWidth;
255
294
  this.#rafId = this.#raf(() => {
256
295
  this.#rafId = null;
257
296
  this.#remove(from);
@@ -273,6 +312,21 @@ var TransitionController = class extends Controller {
273
312
  this.dispatch("left", { detail: {} });
274
313
  }
275
314
  }
315
+ /** Writes the state hook the element's visibility implies. */
316
+ #settleState() {
317
+ this.element.setAttribute("data-transition-state", this.element.hidden ? "left" : "entered");
318
+ }
319
+ /**
320
+ * Returns the element to a settled state before Turbo copies the page.
321
+ *
322
+ * The snapshot is taken while the controller is still connected, so stripping on
323
+ * the next `connect()` would only repair the page after it has been painted from
324
+ * the cache. The pass is silent: `connect()` derives the state again on restore.
325
+ */
326
+ #rewindForCache() {
327
+ this.#cancel();
328
+ this.#settleState();
329
+ }
276
330
  /** Cancels any in-flight transition (interruption / teardown). */
277
331
  #cancel() {
278
332
  if (this.#rafId !== null) {
@@ -282,24 +336,34 @@ var TransitionController = class extends Controller {
282
336
  this.#transition.cancel();
283
337
  this.#strip();
284
338
  }
339
+ /**
340
+ * Applies the stage tokens this controller does not already find on the
341
+ * element, and claims exactly those.
342
+ *
343
+ * A token already on the element is left unclaimed: it is either the consumer's
344
+ * standing class or one an earlier stage of this transition already claimed, and
345
+ * in neither case may this call take ownership of it. That is what keeps a
346
+ * standing class the consumer also named as a stage Value; the cost is that such
347
+ * a token cannot be staged, so the property it drives resolves from their CSS.
348
+ */
285
349
  #add(...lists) {
286
- const tokens = lists.flatMap(tokensOf);
287
- if (tokens.length > 0) this.element.classList.add(...tokens);
350
+ for (const token of lists.flatMap(tokensOf)) {
351
+ if (this.element.classList.contains(token)) continue;
352
+ this.element.classList.add(token);
353
+ this.#staged.add(token);
354
+ }
288
355
  }
356
+ /** Drops the named tokens that are this controller's to drop. */
289
357
  #remove(...lists) {
290
- const tokens = lists.flatMap(tokensOf);
291
- if (tokens.length > 0) this.element.classList.remove(...tokens);
358
+ for (const token of lists.flatMap(tokensOf)) {
359
+ if (!this.#staged.delete(token)) continue;
360
+ this.element.classList.remove(token);
361
+ }
292
362
  }
293
- /** Removes every stage class so no half-applied state lingers. */
363
+ /** Removes every stage class this controller applied, so none lingers. */
294
364
  #strip() {
295
- this.#remove(
296
- this.enterValue,
297
- this.enterFromValue,
298
- this.enterToValue,
299
- this.leaveValue,
300
- this.leaveFromValue,
301
- this.leaveToValue
302
- );
365
+ this.element.classList.remove(...this.#staged);
366
+ this.#staged.clear();
303
367
  }
304
368
  #raf(callback) {
305
369
  if (typeof window.requestAnimationFrame === "function") {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/reduced_motion.ts","../../src/utils/safe_timeout.ts","../../src/utils/transition_completion.ts","../../src/controllers/transition_controller.ts"],"names":[],"mappings":";;;;;AAmBO,SAAS,oBAAA,GAAgC;AAC9C,EAAA,OACE,OAAO,MAAA,CAAO,UAAA,KAAe,cAC7B,MAAA,CAAO,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A,WAAW,KAAA,EAAuB;AAChC,IAAA,MAAM,MAAA,GAAS,KAAA,CAAM,OAAA,CAAQ,QAAQ,CAAA;AACrC,IAAA,IAAI,MAAA,CAAO,SAAS,CAAA,EAAG,IAAA,CAAK,QAAQ,SAAA,CAAU,MAAA,CAAO,GAAG,MAAM,CAAA;AAAA,EAChE;AAAA;AAAA,EAGA,MAAA,GAAe;AACb,IAAA,IAAA,CAAK,OAAA;AAAA,MACH,IAAA,CAAK,UAAA;AAAA,MACL,IAAA,CAAK,cAAA;AAAA,MACL,IAAA,CAAK,YAAA;AAAA,MACL,IAAA,CAAK,UAAA;AAAA,MACL,IAAA,CAAK,cAAA;AAAA,MACL,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AAAA,EAEA,KAAK,QAAA,EAA8B;AACjC,IAAA,IAAI,OAAO,MAAA,CAAO,qBAAA,KAA0B,UAAA,EAAY;AACtD,MAAA,OAAO,MAAA,CAAO,qBAAA,CAAsB,MAAM,QAAA,EAAU,CAAA;AAAA,IACtD;AACA,IAAA,OAAO,MAAA,CAAO,UAAA,CAAW,QAAA,EAAU,CAAC,CAAA;AAAA,EACtC;AAAA,EAEA,WAAW,EAAA,EAAkB;AAC3B,IAAA,IAAI,OAAO,MAAA,CAAO,oBAAA,KAAyB,UAAA,EAAY,MAAA,CAAO,qBAAqB,EAAE,CAAA;AAAA,SAChF,MAAA,CAAO,aAAa,EAAE,CAAA;AAAA,EAC7B;AACF","file":"transition_controller.js","sourcesContent":["/**\n * Shared `prefers-reduced-motion` lookup for the motion-aware controllers\n * (count-up, highlight, overflow-indicator, scroll-visibility, stick-to-bottom,\n * transition).\n *\n * This one-liner keeps the media query string and the environment guard\n * single-sourced across them. The preference is intentionally re-read on every\n * call — the controllers check it at each animation/scroll start (WCAG 2.2\n * **2.3.3**), so flipping the OS setting takes effect immediately without any\n * listener or cache bookkeeping here.\n */\n\n/**\n * Whether the user currently requests reduced motion.\n *\n * @returns `true` when `(prefers-reduced-motion: reduce)` matches; `false`\n * otherwise, including environments without `window.matchMedia` (treated as\n * \"no preference\").\n */\nexport function prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n}\n","/**\n * 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 { prefersReducedMotion } from \"../utils/reduced_motion\";\nimport { TransitionCompletion } from \"../utils/transition_completion\";\n\n/** Splits a space-separated class-list value into individual, non-empty tokens. */\nconst tokensOf = (value: string): string[] => value.split(/\\s+/).filter(Boolean);\n\n/**\n * Headless **enter/leave transition base**: stages CSS classes for showing and hiding\n * an element (the shared substrate other widgets can lean on instead of hand-rolling\n * it). No APG pattern; honors WCAG 2.2 **2.3.3** via `prefers-reduced-motion` and keeps\n * the visual state in sync with `hidden`.\n *\n * Markup contract (identifier: `stimeo--transition`):\n * <div data-controller=\"stimeo--transition\"\n * data-stimeo--transition-enter-value=\"ease-out duration-200\"\n * data-stimeo--transition-enter-from-value=\"opacity-0\"\n * data-stimeo--transition-enter-to-value=\"opacity-100\"\n * data-stimeo--transition-leave-value=\"ease-in duration-150\"\n * data-stimeo--transition-leave-from-value=\"opacity-100\"\n * data-stimeo--transition-leave-to-value=\"opacity-0\" hidden>…</div>\n *\n * `enter()` unhides the element, applies `enter` + `enterFrom`, then on the next frame\n * swaps `enterFrom` → `enterTo` so the CSS transition runs, and settles to `entered`\n * once the transition completes. `leave()` mirrors it and re-applies `hidden`.\n * `toggle()` reverses the current direction. The element carries `data-transition-state`\n * (`entering` / `entered` / `leaving` / `left`) and `entered` / `left` events fire on\n * completion.\n *\n * `entered` and `left` dispatch `{}`.\n *\n * @remarks\n * Behavior only — the animation itself is the consumer's CSS; this controls *when* the\n * stage classes are applied. Completion is owned by the shared\n * {@link TransitionCompletion}: every declared transition property must settle\n * (`transitionend` / `transitioncancel`, pseudo-element events excluded) with a\n * `max(duration + delay) + 50ms` bounded fallback, and a computed 0ms transition\n * settles synchronously at the staging frame. A positive `timeout` Value replaces the\n * fallback verbatim and keeps the wait armed even for a computed 0ms transition.\n * Under `prefers-reduced-motion: reduce` it switches instantly (no staging). An\n * interrupting call cancels the in-flight transition and starts the new one. State\n * lives solely in `hidden` / `data-transition-state`, and `connect()` reconciles to a\n * stable state (stripping any half-applied stage classes from a Turbo cache); the\n * terminal-event listeners, rAF, and fallback timer are released on `disconnect()`\n * (Turbo navigation included).\n */\nexport class TransitionController extends Controller<HTMLElement> {\n static override values = {\n enter: { type: String, default: \"\" },\n enterFrom: { type: String, default: \"\" },\n enterTo: { type: String, default: \"\" },\n leave: { type: String, default: \"\" },\n leaveFrom: { type: String, default: \"\" },\n leaveTo: { type: String, default: \"\" },\n timeout: { type: Number, default: 0 },\n };\n static actions = [\"enter\", \"leave\", \"toggle\"] as const;\n static events = [\"entered\", \"left\"] as const;\n\n declare enterValue: string;\n declare enterFromValue: string;\n declare enterToValue: string;\n declare leaveValue: string;\n declare leaveFromValue: string;\n declare leaveToValue: string;\n declare timeoutValue: number;\n\n /** Owns the cancellable completion wait (terminal events + bounded fallback). */\n readonly #transition = new TransitionCompletion();\n #rafId: number | null = null;\n\n override connect(): void {\n // Drop any half-applied stage classes a cache may have captured, then settle the\n // state hook to match the element's current visibility.\n this.#strip();\n this.element.setAttribute(\"data-transition-state\", this.element.hidden ? \"left\" : \"entered\");\n }\n\n override disconnect(): void {\n this.#cancel();\n }\n\n /** Shows the element with the enter transition. */\n enter(): void {\n this.#run(\"enter\");\n }\n\n /** Hides the element with the leave transition. */\n leave(): void {\n this.#run(\"leave\");\n }\n\n /** Reverses the current direction (enter when hidden/leaving, else leave). */\n toggle(): void {\n const state = this.element.getAttribute(\"data-transition-state\");\n if (state === \"entered\" || state === \"entering\") this.leave();\n else this.enter();\n }\n\n #run(kind: \"enter\" | \"leave\"): void {\n this.#cancel();\n const isEnter = kind === \"enter\";\n if (isEnter) this.element.hidden = false;\n this.element.setAttribute(\"data-transition-state\", isEnter ? \"entering\" : \"leaving\");\n\n if (prefersReducedMotion()) {\n this.#finish(kind);\n return;\n }\n\n const base = isEnter ? this.enterValue : this.leaveValue;\n const from = isEnter ? this.enterFromValue : this.leaveFromValue;\n const to = isEnter ? this.enterToValue : this.leaveToValue;\n\n this.#add(base, from);\n this.#rafId = this.#raf(() => {\n this.#rafId = null;\n this.#remove(from);\n this.#add(to);\n // The consumer's `timeout` Value (positive) replaces the auto-computed\n // fallback so an author-declared budget always wins over computed styles.\n this.#transition.wait(this.element, () => this.#finish(kind), {\n timeoutMs: this.timeoutValue,\n });\n });\n }\n\n /** Settles the element into the completed state, clearing the stage classes. */\n #finish(kind: \"enter\" | \"leave\"): void {\n this.#strip();\n if (kind === \"enter\") {\n this.element.setAttribute(\"data-transition-state\", \"entered\");\n this.dispatch(\"entered\", { detail: {} });\n } else {\n this.element.hidden = true;\n this.element.setAttribute(\"data-transition-state\", \"left\");\n this.dispatch(\"left\", { detail: {} });\n }\n }\n\n /** Cancels any in-flight transition (interruption / teardown). */\n #cancel(): void {\n if (this.#rafId !== null) {\n this.#cancelRaf(this.#rafId);\n this.#rafId = null;\n }\n this.#transition.cancel();\n this.#strip();\n }\n\n #add(...lists: string[]): void {\n const tokens = lists.flatMap(tokensOf);\n if (tokens.length > 0) this.element.classList.add(...tokens);\n }\n\n #remove(...lists: string[]): void {\n const tokens = lists.flatMap(tokensOf);\n if (tokens.length > 0) this.element.classList.remove(...tokens);\n }\n\n /** Removes every stage class so no half-applied state lingers. */\n #strip(): void {\n this.#remove(\n this.enterValue,\n this.enterFromValue,\n this.enterToValue,\n this.leaveValue,\n this.leaveFromValue,\n this.leaveToValue,\n );\n }\n\n #raf(callback: () => void): number {\n if (typeof window.requestAnimationFrame === \"function\") {\n return window.requestAnimationFrame(() => callback());\n }\n return window.setTimeout(callback, 0);\n }\n\n #cancelRaf(id: number): void {\n if (typeof window.cancelAnimationFrame === \"function\") window.cancelAnimationFrame(id);\n else window.clearTimeout(id);\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/before_cache_reset.ts","../../src/utils/reduced_motion.ts","../../src/utils/safe_timeout.ts","../../src/utils/transition_completion.ts","../../src/controllers/transition_controller.ts"],"names":[],"mappings":";;;;;AA2CO,IAAM,gBAAA,GAAN,MAAM,iBAAA,CAAiB;AAAA;AAAA,EAE5B,OAAgB,YAAA,mBAAe,IAAI,GAAA,EAAsB;AAAA;AAAA,EAGzD,OAAgB,iBAAiB,MAAY;AAC3C,IAAA,KAAA,MAAW,UAAA,IAAc,iBAAA,CAAiB,YAAA,EAAc,UAAA,CAAW,OAAA,EAAQ;AAAA,EAC7E,CAAA;AAAA,EAES,OAAA;AAAA;AAAA,EAGT,YAAY,MAAA,EAAoB;AAC9B,IAAA,IAAA,CAAK,OAAA,GAAU,MAAA;AAAA,EACjB;AAAA;AAAA,EAGA,QAAA,GAAiB;AACf,IAAA,MAAM,KAAA,GAAQ,iBAAA,CAAiB,YAAA,CAAa,IAAA,KAAS,CAAA;AACrD,I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IAAA,KAAA,MAAW,KAAA,IAAS,KAAA,CAAM,OAAA,CAAQ,QAAQ,CAAA,EAAG;AAC3C,MAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,MAAA,CAAO,KAAK,CAAA,EAAG;AACjC,MAAA,IAAA,CAAK,OAAA,CAAQ,SAAA,CAAU,MAAA,CAAO,KAAK,CAAA;AAAA,IACrC;AAAA,EACF;AAAA;AAAA,EAGA,MAAA,GAAe;AACb,IAAA,IAAA,CAAK,OAAA,CAAQ,SAAA,CAAU,MAAA,CAAO,GAAG,KAAK,OAAO,CAAA;AAC7C,IAAA,IAAA,CAAK,QAAQ,KAAA,EAAM;AAAA,EACrB;AAAA,EAEA,KAAK,QAAA,EAA8B;AACjC,IAAA,IAAI,OAAO,MAAA,CAAO,qBAAA,KAA0B,UAAA,EAAY;AACtD,MAAA,OAAO,MAAA,CAAO,qBAAA,CAAsB,MAAM,QAAA,EAAU,CAAA;AAAA,IACtD;AACA,IAAA,OAAO,MAAA,CAAO,UAAA,CAAW,QAAA,EAAU,CAAC,CAAA;AAAA,EACtC;AAAA,EAEA,WAAW,EAAA,EAAkB;AAC3B,IAAA,IAAI,OAAO,MAAA,CAAO,oBAAA,KAAyB,UAAA,EAAY,MAAA,CAAO,qBAAqB,EAAE,CAAA;AAAA,SAChF,MAAA,CAAO,aAAa,EAAE,CAAA;AAAA,EAC7B;AACF","file":"transition_controller.js","sourcesContent":["/**\n * Runs a controller's \"return to the initial state\" pass just before Turbo\n * caches the page.\n *\n * **`disconnect()` cannot do this job, for two independent reasons.** Turbo\n * queues the clone from this event rather than taking it here, and the body swap\n * that runs the controller's `disconnect()` is queued separately — so which of\n * the two lands first is not something a controller can rely on, and a rewind\n * written in `disconnect()` may reach only the DOM being thrown away. In the\n * other direction, `disconnect()` also fires on an in-page move (Stimulus tears\n * down and reconnects the same element), where rewinding would wipe a\n * legitimately in-progress interaction — a spinner mid-load would vanish. One\n * timing is unreliable, the other is too eager; `turbo:before-cache` is the only\n * point that is exactly \"the page is about to be frozen\".\n *\n * Scope is the subscription only: registering on `activate()`, unregistering on\n * `deactivate()`, and one shared document listener no matter how many instances\n * are live. *What* to return to its initial state — which `data-state`, which\n * `hidden`, which `aria-busy` — stays in the controller, because no two\n * consumers answer it the same way.\n *\n * **Rewind state, not appearance.** The pass writes attributes the controller\n * itself owns; the visual result of those attributes is the consumer's CSS, and\n * a library that reached for style or class names would be guessing at markup\n * it does not own.\n *\n * Both entry points are idempotent, so the lifecycle hooks can call them\n * unconditionally: a second `activate()` does not double-subscribe and does not\n * make the callback run twice, and `deactivate()` on an instance that never\n * subscribed is a no-op.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #beforeCache = new BeforeCacheReset(() => this.#rewind());\n *\n * connect() { this.#beforeCache.activate(); }\n * disconnect() { this.#beforeCache.deactivate(); }\n * ```\n */\nexport class BeforeCacheReset {\n /** Every subscribed instance, iterated by the one shared document listener. */\n static readonly #subscribers = new Set<BeforeCacheReset>();\n\n /** The shared listener; installed while at least one instance is subscribed. */\n static readonly #onBeforeCache = (): void => {\n for (const subscriber of BeforeCacheReset.#subscribers) subscriber.#rewind();\n };\n\n readonly #rewind: () => void;\n\n /** @param rewind - the pass that returns this controller's state to its initial form. */\n constructor(rewind: () => void) {\n this.#rewind = rewind;\n }\n\n /** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */\n activate(): void {\n const first = BeforeCacheReset.#subscribers.size === 0;\n BeforeCacheReset.#subscribers.add(this);\n if (first) {\n document.addEventListener(\"turbo:before-cache\", BeforeCacheReset.#onBeforeCache);\n }\n }\n\n /** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */\n deactivate(): void {\n BeforeCacheReset.#subscribers.delete(this);\n if (BeforeCacheReset.#subscribers.size > 0) return;\n document.removeEventListener(\"turbo:before-cache\", BeforeCacheReset.#onBeforeCache);\n }\n}\n","/**\n * Shared `prefers-reduced-motion` lookup for the motion-aware controllers\n *.\n *\n * This one-liner keeps the media query string and the environment guard\n * single-sourced across them. The preference is intentionally re-read on every\n * call — the controllers check it at each animation/scroll start (WCAG 2.2\n * **2.3.3**), so flipping the OS setting takes effect immediately without any\n * listener or cache bookkeeping here.\n */\n\n/**\n * Whether the user currently requests reduced motion.\n *\n * @returns `true` when `(prefers-reduced-motion: reduce)` matches; `false`\n * otherwise, including environments without `window.matchMedia` (treated as\n * \"no preference\").\n */\nexport function prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n}\n","/**\n * 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 { BeforeCacheReset } from \"../utils/before_cache_reset\";\nimport { prefersReducedMotion } from \"../utils/reduced_motion\";\nimport { TransitionCompletion } from \"../utils/transition_completion\";\n\n/** Splits a space-separated class-list value into individual, non-empty tokens. */\nconst tokensOf = (value: string): string[] => value.split(/\\s+/).filter(Boolean);\n\n/**\n * Headless **enter/leave transition base**: stages CSS classes for showing and hiding\n * an element (the shared substrate other widgets can lean on instead of hand-rolling\n * it). No APG pattern; honors WCAG 2.2 **2.3.3** via `prefers-reduced-motion` and keeps\n * the visual state in sync with `hidden`.\n *\n * Markup contract (identifier: `stimeo--transition`):\n * <div data-controller=\"stimeo--transition\"\n * data-stimeo--transition-enter-value=\"ease-out duration-200\"\n * data-stimeo--transition-enter-from-value=\"opacity-0\"\n * data-stimeo--transition-enter-to-value=\"opacity-100\"\n * data-stimeo--transition-leave-value=\"ease-in duration-150\"\n * data-stimeo--transition-leave-from-value=\"opacity-100\"\n * data-stimeo--transition-leave-to-value=\"opacity-0\" hidden>…</div>\n *\n * `enter()` unhides the element, applies `enter` + `enterFrom`, commits that frame,\n * then on the next frame swaps `enterFrom` → `enterTo` so the CSS transition runs, and\n * settles to `entered` once the transition completes. `leave()` mirrors it and re-applies `hidden`.\n * `toggle()` reverses the current direction. The element carries `data-transition-state`\n * (`entering` / `entered` / `leaving` / `left`) and `entered` / `left` events fire on\n * completion.\n *\n * `entered` and `left` dispatch `{}`.\n *\n * @remarks\n * Behavior only — the animation itself is the consumer's CSS; this controls *when* the\n * stage classes are applied. Completion is owned by the shared\n * {@link TransitionCompletion}: every declared transition property must settle\n * (`transitionend` / `transitioncancel`, pseudo-element events excluded) with a\n * `max(duration + delay) + 50ms` bounded fallback, and a computed 0ms transition\n * settles synchronously at the staging frame. A positive `timeout` Value replaces the\n * fallback verbatim and keeps the wait armed even for a computed 0ms transition.\n * Under `prefers-reduced-motion: reduce` it switches instantly (no staging). An\n * interrupting call cancels the in-flight transition and starts the new one. State\n * lives solely in `hidden` / `data-transition-state`, and `connect()` reconciles it to\n * the element's visibility. Only the classes this controller applied are ever removed:\n * a stage token already on the element is the consumer's standing class, so it is\n * neither claimed nor stripped — declare a token as a stage Value *or* author it, not\n * both, because a token held by the consumer cannot be staged and the property it\n * drives then resolves from their CSS alone. A half-applied stage is rewound on\n * `turbo:before-cache` so it never reaches a snapshot. The terminal-event listeners,\n * rAF, and fallback timer are released on `disconnect()` (Turbo navigation included).\n */\nexport class TransitionController extends Controller<HTMLElement> {\n static override values = {\n enter: { type: String, default: \"\" },\n enterFrom: { type: String, default: \"\" },\n enterTo: { type: String, default: \"\" },\n leave: { type: String, default: \"\" },\n leaveFrom: { type: String, default: \"\" },\n leaveTo: { type: String, default: \"\" },\n timeout: { type: Number, default: 0 },\n };\n static actions = [\"enter\", \"leave\", \"toggle\"] as const;\n static events = [\"entered\", \"left\"] as const;\n\n declare enterValue: string;\n declare enterFromValue: string;\n declare enterToValue: string;\n declare leaveValue: string;\n declare leaveFromValue: string;\n declare leaveToValue: string;\n declare timeoutValue: number;\n\n /** Owns the cancellable completion wait (terminal events + bounded fallback). */\n readonly #transition = new TransitionCompletion();\n /** Rewinds a half-applied stage before Turbo copies the page into its snapshot. */\n readonly #beforeCache = new BeforeCacheReset(() => this.#rewindForCache());\n #rafId: number | null = null;\n /**\n * Stage classes this controller put on the element. Removing by declaration\n * instead would take a token the consumer also authored, and would strand the\n * token that was applied when a Value changes mid-transition.\n */\n readonly #staged = new Set<string>();\n\n override connect(): void {\n this.#beforeCache.activate();\n // Settle the state hook to match the element's current visibility. Nothing is\n // stripped here: a stage token present at connect was not staged by this\n // instance, so it belongs to the consumer.\n this.#settleState();\n }\n\n override disconnect(): void {\n this.#beforeCache.deactivate();\n this.#cancel();\n }\n\n /** Shows the element with the enter transition. */\n enter(): void {\n this.#run(\"enter\");\n }\n\n /** Hides the element with the leave transition. */\n leave(): void {\n this.#run(\"leave\");\n }\n\n /** Reverses the current direction (enter when hidden/leaving, else leave). */\n toggle(): void {\n const state = this.element.getAttribute(\"data-transition-state\");\n if (state === \"entered\" || state === \"entering\") this.leave();\n else this.enter();\n }\n\n #run(kind: \"enter\" | \"leave\"): void {\n this.#cancel();\n const isEnter = kind === \"enter\";\n if (isEnter) this.element.hidden = false;\n this.element.setAttribute(\"data-transition-state\", isEnter ? \"entering\" : \"leaving\");\n\n if (prefersReducedMotion()) {\n this.#finish(kind);\n return;\n }\n\n const base = isEnter ? this.enterValue : this.leaveValue;\n const from = isEnter ? this.enterFromValue : this.leaveFromValue;\n const to = isEnter ? this.enterToValue : this.leaveToValue;\n\n this.#add(base, from);\n // Commit the \"from\" frame before the swap: a rAF callback runs before this\n // frame's style is computed, and an element arriving from `display: none` has no\n // before-change style, so the transition would never start and completion would\n // always fall back to the timer.\n void this.element.offsetWidth;\n this.#rafId = this.#raf(() => {\n this.#rafId = null;\n this.#remove(from);\n this.#add(to);\n // The consumer's `timeout` Value (positive) replaces the auto-computed\n // fallback so an author-declared budget always wins over computed styles.\n this.#transition.wait(this.element, () => this.#finish(kind), {\n timeoutMs: this.timeoutValue,\n });\n });\n }\n\n /** Settles the element into the completed state, clearing the stage classes. */\n #finish(kind: \"enter\" | \"leave\"): void {\n this.#strip();\n if (kind === \"enter\") {\n this.element.setAttribute(\"data-transition-state\", \"entered\");\n this.dispatch(\"entered\", { detail: {} });\n } else {\n this.element.hidden = true;\n this.element.setAttribute(\"data-transition-state\", \"left\");\n this.dispatch(\"left\", { detail: {} });\n }\n }\n\n /** Writes the state hook the element's visibility implies. */\n #settleState(): void {\n this.element.setAttribute(\"data-transition-state\", this.element.hidden ? \"left\" : \"entered\");\n }\n\n /**\n * Returns the element to a settled state before Turbo copies the page.\n *\n * The snapshot is taken while the controller is still connected, so stripping on\n * the next `connect()` would only repair the page after it has been painted from\n * the cache. The pass is silent: `connect()` derives the state again on restore.\n */\n #rewindForCache(): void {\n this.#cancel();\n this.#settleState();\n }\n\n /** Cancels any in-flight transition (interruption / teardown). */\n #cancel(): void {\n if (this.#rafId !== null) {\n this.#cancelRaf(this.#rafId);\n this.#rafId = null;\n }\n this.#transition.cancel();\n this.#strip();\n }\n\n /**\n * Applies the stage tokens this controller does not already find on the\n * element, and claims exactly those.\n *\n * A token already on the element is left unclaimed: it is either the consumer's\n * standing class or one an earlier stage of this transition already claimed, and\n * in neither case may this call take ownership of it. That is what keeps a\n * standing class the consumer also named as a stage Value; the cost is that such\n * a token cannot be staged, so the property it drives resolves from their CSS.\n */\n #add(...lists: string[]): void {\n for (const token of lists.flatMap(tokensOf)) {\n if (this.element.classList.contains(token)) continue;\n this.element.classList.add(token);\n this.#staged.add(token);\n }\n }\n\n /** Drops the named tokens that are this controller's to drop. */\n #remove(...lists: string[]): void {\n for (const token of lists.flatMap(tokensOf)) {\n if (!this.#staged.delete(token)) continue;\n this.element.classList.remove(token);\n }\n }\n\n /** Removes every stage class this controller applied, so none lingers. */\n #strip(): void {\n this.element.classList.remove(...this.#staged);\n this.#staged.clear();\n }\n\n #raf(callback: () => void): number {\n if (typeof window.requestAnimationFrame === \"function\") {\n return window.requestAnimationFrame(() => callback());\n }\n return window.setTimeout(callback, 0);\n }\n\n #cancelRaf(id: number): void {\n if (typeof window.cancelAnimationFrame === \"function\") window.cancelAnimationFrame(id);\n else window.clearTimeout(id);\n }\n}\n"]}