stimeo-ui 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/dist/controllers/alert_dialog_controller.js +32 -5
  3. package/dist/controllers/alert_dialog_controller.js.map +1 -1
  4. package/dist/controllers/announcer_controller.d.ts +32 -6
  5. package/dist/controllers/announcer_controller.js +255 -20
  6. package/dist/controllers/announcer_controller.js.map +1 -1
  7. package/dist/controllers/aspect_ratio_controller.d.ts +2 -2
  8. package/dist/controllers/aspect_ratio_controller.js +1 -1
  9. package/dist/controllers/aspect_ratio_controller.js.map +1 -1
  10. package/dist/controllers/breadcrumb_controller.js +5 -1
  11. package/dist/controllers/breadcrumb_controller.js.map +1 -1
  12. package/dist/controllers/carousel_controller.js +5 -1
  13. package/dist/controllers/carousel_controller.js.map +1 -1
  14. package/dist/controllers/clipboard_controller.js +8 -3
  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 +4 -1
  18. package/dist/controllers/collapsible_controller.js.map +1 -1
  19. package/dist/controllers/color_picker_controller.d.ts +4 -3
  20. package/dist/controllers/color_picker_controller.js +52 -2
  21. package/dist/controllers/color_picker_controller.js.map +1 -1
  22. package/dist/controllers/combobox_controller.js.map +1 -1
  23. package/dist/controllers/command_palette_controller.js +32 -5
  24. package/dist/controllers/command_palette_controller.js.map +1 -1
  25. package/dist/controllers/confirm_controller.js +32 -5
  26. package/dist/controllers/confirm_controller.js.map +1 -1
  27. package/dist/controllers/context_menu_controller.d.ts +1 -1
  28. package/dist/controllers/context_menu_controller.js +2 -2
  29. package/dist/controllers/context_menu_controller.js.map +1 -1
  30. package/dist/controllers/countdown_controller.d.ts +24 -8
  31. package/dist/controllers/countdown_controller.js +117 -13
  32. package/dist/controllers/countdown_controller.js.map +1 -1
  33. package/dist/controllers/date_range_picker_controller.d.ts +4 -1
  34. package/dist/controllers/date_range_picker_controller.js +55 -1
  35. package/dist/controllers/date_range_picker_controller.js.map +1 -1
  36. package/dist/controllers/dialog_controller.js +32 -5
  37. package/dist/controllers/dialog_controller.js.map +1 -1
  38. package/dist/controllers/direct_upload_controller.d.ts +1 -1
  39. package/dist/controllers/direct_upload_controller.js +3 -3
  40. package/dist/controllers/direct_upload_controller.js.map +1 -1
  41. package/dist/controllers/dismissible_controller.js.map +1 -1
  42. package/dist/controllers/drawer_controller.js +32 -5
  43. package/dist/controllers/drawer_controller.js.map +1 -1
  44. package/dist/controllers/empty_state_controller.d.ts +36 -11
  45. package/dist/controllers/empty_state_controller.js +128 -23
  46. package/dist/controllers/empty_state_controller.js.map +1 -1
  47. package/dist/controllers/flash_controller.d.ts +25 -5
  48. package/dist/controllers/flash_controller.js +161 -21
  49. package/dist/controllers/flash_controller.js.map +1 -1
  50. package/dist/controllers/focus_controller.js +32 -5
  51. package/dist/controllers/focus_controller.js.map +1 -1
  52. package/dist/controllers/form_validation_controller.js +8 -2
  53. package/dist/controllers/form_validation_controller.js.map +1 -1
  54. package/dist/controllers/frame_loading_controller.d.ts +31 -3
  55. package/dist/controllers/frame_loading_controller.js +261 -27
  56. package/dist/controllers/frame_loading_controller.js.map +1 -1
  57. package/dist/controllers/highlight_controller.d.ts +8 -4
  58. package/dist/controllers/highlight_controller.js +38 -1
  59. package/dist/controllers/highlight_controller.js.map +1 -1
  60. package/dist/controllers/idle_controller.d.ts +2 -1
  61. package/dist/controllers/idle_controller.js +13 -2
  62. package/dist/controllers/idle_controller.js.map +1 -1
  63. package/dist/controllers/listbox_controller.js.map +1 -1
  64. package/dist/controllers/local_time_controller.d.ts +19 -3
  65. package/dist/controllers/local_time_controller.js +102 -6
  66. package/dist/controllers/local_time_controller.js.map +1 -1
  67. package/dist/controllers/masonry_controller.d.ts +1 -1
  68. package/dist/controllers/masonry_controller.js +1 -1
  69. package/dist/controllers/masonry_controller.js.map +1 -1
  70. package/dist/controllers/meter_controller.d.ts +22 -2
  71. package/dist/controllers/meter_controller.js +147 -26
  72. package/dist/controllers/meter_controller.js.map +1 -1
  73. package/dist/controllers/multi_select_controller.js.map +1 -1
  74. package/dist/controllers/network_status_controller.d.ts +25 -11
  75. package/dist/controllers/network_status_controller.js +29 -11
  76. package/dist/controllers/network_status_controller.js.map +1 -1
  77. package/dist/controllers/number_input_controller.d.ts +8 -0
  78. package/dist/controllers/number_input_controller.js +191 -24
  79. package/dist/controllers/number_input_controller.js.map +1 -1
  80. package/dist/controllers/overflow_menu_controller.js +34 -7
  81. package/dist/controllers/overflow_menu_controller.js.map +1 -1
  82. package/dist/controllers/pagination_controller.js +5 -1
  83. package/dist/controllers/pagination_controller.js.map +1 -1
  84. package/dist/controllers/password_strength_controller.d.ts +1 -1
  85. package/dist/controllers/password_strength_controller.js +1 -1
  86. package/dist/controllers/password_strength_controller.js.map +1 -1
  87. package/dist/controllers/pointer_drag_controller.js +10 -0
  88. package/dist/controllers/pointer_drag_controller.js.map +1 -1
  89. package/dist/controllers/portal_controller.js +10 -0
  90. package/dist/controllers/portal_controller.js.map +1 -1
  91. package/dist/controllers/progress_controller.d.ts +17 -2
  92. package/dist/controllers/progress_controller.js +123 -12
  93. package/dist/controllers/progress_controller.js.map +1 -1
  94. package/dist/controllers/range_slider_controller.d.ts +27 -1
  95. package/dist/controllers/range_slider_controller.js +449 -93
  96. package/dist/controllers/range_slider_controller.js.map +1 -1
  97. package/dist/controllers/rating_controller.d.ts +4 -1
  98. package/dist/controllers/rating_controller.js +55 -0
  99. package/dist/controllers/rating_controller.js.map +1 -1
  100. package/dist/controllers/relative_time_controller.d.ts +13 -0
  101. package/dist/controllers/relative_time_controller.js +135 -12
  102. package/dist/controllers/relative_time_controller.js.map +1 -1
  103. package/dist/controllers/scroll_area_controller.d.ts +1 -1
  104. package/dist/controllers/scroll_area_controller.js +1 -1
  105. package/dist/controllers/scroll_area_controller.js.map +1 -1
  106. package/dist/controllers/separator_controller.js +13 -17
  107. package/dist/controllers/separator_controller.js.map +1 -1
  108. package/dist/controllers/sidebar_controller.d.ts +1 -11
  109. package/dist/controllers/sidebar_controller.js +37 -8
  110. package/dist/controllers/sidebar_controller.js.map +1 -1
  111. package/dist/controllers/skeleton_controller.d.ts +7 -2
  112. package/dist/controllers/skeleton_controller.js +143 -22
  113. package/dist/controllers/skeleton_controller.js.map +1 -1
  114. package/dist/controllers/slider_controller.d.ts +17 -1
  115. package/dist/controllers/slider_controller.js +342 -50
  116. package/dist/controllers/slider_controller.js.map +1 -1
  117. package/dist/controllers/spinner_controller.d.ts +50 -12
  118. package/dist/controllers/spinner_controller.js +244 -28
  119. package/dist/controllers/spinner_controller.js.map +1 -1
  120. package/dist/controllers/step_indicator_controller.d.ts +13 -2
  121. package/dist/controllers/step_indicator_controller.js +85 -6
  122. package/dist/controllers/step_indicator_controller.js.map +1 -1
  123. package/dist/controllers/stepper_controller.js +2 -0
  124. package/dist/controllers/stepper_controller.js.map +1 -1
  125. package/dist/controllers/stick_to_bottom_controller.d.ts +26 -2
  126. package/dist/controllers/stick_to_bottom_controller.js +60 -10
  127. package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
  128. package/dist/controllers/switch_controller.d.ts +12 -8
  129. package/dist/controllers/switch_controller.js +162 -18
  130. package/dist/controllers/switch_controller.js.map +1 -1
  131. package/dist/controllers/textarea_autosize_controller.js +1 -1
  132. package/dist/controllers/textarea_autosize_controller.js.map +1 -1
  133. package/dist/controllers/time_picker_controller.d.ts +3 -0
  134. package/dist/controllers/time_picker_controller.js +6 -3
  135. package/dist/controllers/time_picker_controller.js.map +1 -1
  136. package/dist/controllers/tree_view_controller.d.ts +1 -2
  137. package/dist/controllers/tree_view_controller.js +19 -1
  138. package/dist/controllers/tree_view_controller.js.map +1 -1
  139. package/dist/index.js +2278 -596
  140. package/dist/index.js.map +1 -1
  141. package/dist/inspector/cli.d.ts +76 -1
  142. package/dist/inspector/cli.js +937 -76
  143. package/dist/inspector/cli.js.map +1 -1
  144. package/dist/inspector/cli_bin.js +997 -78
  145. package/dist/inspector/cli_bin.js.map +1 -1
  146. package/dist/inspector/examples.json +20 -20
  147. package/dist/inspector/manifest.json +428 -33
  148. package/package.json +3 -3
@@ -1,37 +1,59 @@
1
1
  import { Controller } from '@hotwired/stimulus';
2
2
 
3
3
  /**
4
- * Headless loading-indicator behavior built on the live-region + `aria-busy`
5
- * practice (no dedicated APG pattern).
4
+ * Headless loading-indicator behavior built on the `aria-busy` practice (no
5
+ * dedicated APG pattern).
6
6
  *
7
7
  * Markup contract (identifier: `stimeo--spinner`):
8
8
  * <div data-controller="stimeo--spinner"
9
9
  * data-stimeo--spinner-delay-value="150"
10
10
  * data-stimeo--spinner-min-duration-value="500"
11
+ * data-stimeo--spinner-timeout-value="0"
12
+ * data-stimeo--spinner-announce-text-value="Loading…"
13
+ * data-stimeo--spinner-announce-ready-text-value="Loading finished."
11
14
  * data-action="loading:start->stimeo--spinner#start
12
15
  * loading:stop->stimeo--spinner#stop">
13
- * <div role="status" aria-live="polite" hidden
14
- * data-stimeo--spinner-target="indicator">
16
+ * <div hidden data-stimeo--spinner-target="indicator">
15
17
  * <span data-stimeo--spinner-target="message">Loading…</span>
16
18
  * </div>
17
19
  * <div aria-busy="false" data-stimeo--spinner-target="region"></div>
18
20
  * </div>
19
21
  *
20
- * The indicator is a `role="status"` live region carrying *text* (never an icon
21
- * alone) so screen readers announce loading; the controlled `region` mirrors the
22
- * busy state via `aria-busy`. Two timers tame flicker: `delay` suppresses the
23
- * spinner for fast operations, and `minDuration` keeps it visible long enough to
24
- * be perceived once shown.
22
+ * The indicator is the visual half — its text plus a spinner the consumer marks
23
+ * `aria-hidden="true"` — and the controlled `region` mirrors the busy state via
24
+ * `aria-busy`. Assistive tech hears the transition through `announceText` /
25
+ * `announceReadyText`, which go to the page's announcer: an indicator that only
26
+ * becomes visible at the moment of the change is not reliably read, and giving it
27
+ * live-region semantics on top of the announcement would say it twice. Two timers
28
+ * tame flicker: `delay` suppresses the spinner for fast operations, and
29
+ * `minDuration` keeps it visible long enough to be perceived once shown.
30
+ * `timeout` is the opt-in safety net for the case the consumer's `stop` never
31
+ * arrives.
32
+ *
33
+ * Events (all with an empty `detail`):
34
+ * - `stimeo--spinner:show` — the indicator became visible, after `delay`.
35
+ * - `stimeo--spinner:hide` — the indicator went away, after `minDuration`.
36
+ * - `stimeo--spinner:timeout` — `timeout` elapsed with the load still running;
37
+ * the controller then ends it exactly as `stop` would, so a `hide` follows.
25
38
  *
26
39
  * @remarks
27
40
  * Behavior only — the visual spinner is the consumer's, alongside the text and
28
- * `aria-hidden="true"`. Both timers are owned by {@link SafeTimeout} and torn
29
- * down on `disconnect()` (Turbo navigation included).
41
+ * `aria-hidden="true"`. Both timers are owned by {@link SafeTimeout}, kept across
42
+ * an in-page move and dropped on a real detach via {@link DetachGate}, while the
43
+ * loading state a cached page would freeze is rewound by {@link BeforeCacheReset}.
30
44
  */
31
45
  declare class SpinnerController extends Controller<HTMLElement> {
32
46
  #private;
33
47
  static targets: string[];
34
48
  static values: {
49
+ announceText: {
50
+ type: StringConstructor;
51
+ default: string;
52
+ };
53
+ announceReadyText: {
54
+ type: StringConstructor;
55
+ default: string;
56
+ };
35
57
  delay: {
36
58
  type: NumberConstructor;
37
59
  default: number;
@@ -40,9 +62,13 @@ declare class SpinnerController extends Controller<HTMLElement> {
40
62
  type: NumberConstructor;
41
63
  default: number;
42
64
  };
65
+ timeout: {
66
+ type: NumberConstructor;
67
+ default: number;
68
+ };
43
69
  };
44
70
  static actions: readonly ["start", "stop"];
45
- static events: readonly ["hide", "show"];
71
+ static events: readonly ["hide", "show", "timeout"];
46
72
  readonly indicatorTarget: HTMLElement;
47
73
  readonly regionTarget: HTMLElement;
48
74
  readonly messageTarget: HTMLElement;
@@ -51,7 +77,19 @@ declare class SpinnerController extends Controller<HTMLElement> {
51
77
  readonly hasMessageTarget: boolean;
52
78
  delayValue: number;
53
79
  minDurationValue: number;
80
+ timeoutValue: number;
81
+ announceTextValue: string;
82
+ announceReadyTextValue: string;
54
83
  connect(): void;
84
+ /**
85
+ * Re-applies the current phase to an indicator that arrived after `connect()`.
86
+ *
87
+ * A Turbo Stream can swap the indicator for a fresh node mid-load, and that node
88
+ * carries the markup contract's `hidden`. Without this the spinner would vanish
89
+ * while `data-state` still says `loading`, and nothing but the next cycle would
90
+ * bring it back.
91
+ */
92
+ indicatorTargetConnected(target: HTMLElement): void;
55
93
  disconnect(): void;
56
94
  /** Begins loading. Honors `delay` before the spinner actually appears. */
57
95
  start(): void;
@@ -2,6 +2,162 @@ import { Controller } from '@hotwired/stimulus';
2
2
 
3
3
  // src/controllers/spinner_controller.ts
4
4
 
5
+ // src/utils/announce.ts
6
+ function announce(message, options = {}) {
7
+ const text = message.trim();
8
+ if (text.length === 0) return;
9
+ window.dispatchEvent(
10
+ new CustomEvent("stimeo--announcer:announce", {
11
+ detail: { message: text, assertive: options.assertive === true }
12
+ })
13
+ );
14
+ }
15
+ function fillTemplate(template, values) {
16
+ return template.replace(/\{([a-zA-Z][a-zA-Z0-9]*)\}/g, (match, name) => {
17
+ const replacement = values[name];
18
+ return replacement === void 0 ? match : String(replacement);
19
+ });
20
+ }
21
+
22
+ // src/utils/before_cache_reset.ts
23
+ var BeforeCacheReset = class _BeforeCacheReset {
24
+ /** Every subscribed instance, iterated by the one shared document listener. */
25
+ static #subscribers = /* @__PURE__ */ new Set();
26
+ /** The shared listener; installed while at least one instance is subscribed. */
27
+ static #onBeforeCache = () => {
28
+ for (const subscriber of _BeforeCacheReset.#subscribers) subscriber.#rewind();
29
+ };
30
+ #rewind;
31
+ /** @param rewind - the pass that returns this controller's state to its initial form. */
32
+ constructor(rewind) {
33
+ this.#rewind = rewind;
34
+ }
35
+ /** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */
36
+ activate() {
37
+ const first = _BeforeCacheReset.#subscribers.size === 0;
38
+ _BeforeCacheReset.#subscribers.add(this);
39
+ if (first) {
40
+ document.addEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
41
+ }
42
+ }
43
+ /** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */
44
+ deactivate() {
45
+ _BeforeCacheReset.#subscribers.delete(this);
46
+ if (_BeforeCacheReset.#subscribers.size > 0) return;
47
+ document.removeEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
48
+ }
49
+ };
50
+
51
+ // src/utils/default_attribute.ts
52
+ function setDefaultAttribute(element, name, value) {
53
+ if (element.hasAttribute(name)) return false;
54
+ element.setAttribute(name, value);
55
+ return true;
56
+ }
57
+
58
+ // src/utils/detach_gate.ts
59
+ var DetachGate = class _DetachGate {
60
+ /** Set while a probe is queued, waiting for a reconnect to cancel it. */
61
+ #pending = false;
62
+ /**
63
+ * True while a probe is queued — the last disconnect was ambiguous and no
64
+ * reconnect has cancelled it yet. Read it from `connect()` to tell the
65
+ * reconnect half of an in-page move from a first connect: a controller whose
66
+ * initialisation restarts a measurement (a min-duration floor, an elapsed
67
+ * counter) must skip it for the move, where nothing actually restarted.
68
+ */
69
+ get pending() {
70
+ return this.#pending;
71
+ }
72
+ /**
73
+ * True when the disconnect is definitely a real detach — the element left
74
+ * the document, or `data-controller` no longer lists the identifier. False
75
+ * means ambiguous (in-page move or observed-root exit), NOT "alive".
76
+ */
77
+ static isDetached(host) {
78
+ if (!host.element.isConnected) return true;
79
+ const tokens = (host.element.getAttribute("data-controller") ?? "").split(/\s+/);
80
+ return !tokens.includes(host.identifier);
81
+ }
82
+ /**
83
+ * Call from `disconnect()`: runs `teardown` synchronously on a definite
84
+ * detach (fast path), otherwise defers it one microtask — a reconnect
85
+ * ({@link cancel} from `connect()`) keeps the state, no reconnect runs it.
86
+ * One microtask is the whole probe window: Stimulus reconnects a moved
87
+ * element within the same mutation batch, before the checkpoint drains.
88
+ */
89
+ disconnected(host, teardown) {
90
+ if (_DetachGate.isDetached(host)) {
91
+ this.#pending = false;
92
+ teardown();
93
+ return;
94
+ }
95
+ this.#pending = true;
96
+ queueMicrotask(() => {
97
+ if (!this.#pending) return;
98
+ this.#pending = false;
99
+ teardown();
100
+ });
101
+ }
102
+ /**
103
+ * Disarms a pending probe. Call from `connect()` (the reconnect that proves
104
+ * an in-page move) and from the head of any teardown path not routed through
105
+ * {@link disconnected} (disabled-toggle, Escape), so an orphaned probe can
106
+ * never run the teardown a second time.
107
+ */
108
+ cancel() {
109
+ this.#pending = false;
110
+ }
111
+ };
112
+
113
+ // src/utils/min_duration_floor.ts
114
+ var MinDurationFloor = class {
115
+ #timers;
116
+ /** Pending finish timer id, or `null` when nothing is held back. */
117
+ #timerId = null;
118
+ /** Epoch ms the floor is measured from. */
119
+ #since = 0;
120
+ /** @param timers - the controller's registry; the floor schedules into it. */
121
+ constructor(timers) {
122
+ this.#timers = timers;
123
+ }
124
+ /** Starts the floor: call when the state being held becomes visible. */
125
+ begin() {
126
+ this.#since = Date.now();
127
+ }
128
+ /** True while a finish is held back waiting for the floor to elapse. */
129
+ get pending() {
130
+ return this.#timerId !== null;
131
+ }
132
+ /**
133
+ * Runs `finish` once the floor has elapsed, immediately when it already has.
134
+ *
135
+ * A held-back finish is **replaced**, never stacked: only the most recently
136
+ * queued id is cancellable, so a second timer would outlive every cancel and
137
+ * end a state that has since restarted. Controllers that want the first signal
138
+ * to win guard on {@link pending} before calling.
139
+ */
140
+ schedule(minDuration, finish) {
141
+ this.cancel();
142
+ const remaining = minDuration - (Date.now() - this.#since);
143
+ if (remaining > 0) {
144
+ this.#timerId = this.#timers.set(() => {
145
+ this.#timerId = null;
146
+ finish();
147
+ }, remaining);
148
+ } else {
149
+ finish();
150
+ }
151
+ }
152
+ /** Drops a held-back finish. Safe when none is queued, or after a bulk clear. */
153
+ cancel() {
154
+ if (this.#timerId !== null) {
155
+ this.#timers.clear(this.#timerId);
156
+ this.#timerId = null;
157
+ }
158
+ }
159
+ };
160
+
5
161
  // src/utils/safe_timeout.ts
6
162
  var TimerRegistry = class {
7
163
  /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */
@@ -59,38 +215,59 @@ var SafeTimeout = class extends TimerRegistry {
59
215
  var SpinnerController = class extends Controller {
60
216
  static targets = ["indicator", "region", "message"];
61
217
  static values = {
218
+ announceText: { type: String, default: "" },
219
+ announceReadyText: { type: String, default: "" },
62
220
  delay: { type: Number, default: 0 },
63
- minDuration: { type: Number, default: 0 }
221
+ minDuration: { type: Number, default: 0 },
222
+ timeout: { type: Number, default: 0 }
64
223
  };
65
224
  static actions = ["start", "stop"];
66
- static events = ["hide", "show"];
225
+ static events = ["hide", "show", "timeout"];
67
226
  #timers = new SafeTimeout();
227
+ #floor = new MinDurationFloor(this.#timers);
228
+ #gate = new DetachGate();
229
+ #beforeCache = new BeforeCacheReset(() => this.#rewindForCache());
68
230
  /** Pending show-delay timer id, or `null` when no start is awaiting its delay. */
69
231
  #delayTimerId = null;
70
- /** Pending min-duration hide timer id, or `null` when none is scheduled. */
71
- #hideTimerId = null;
72
- /** Epoch ms when the spinner became visible; `minDuration` is measured from it. */
73
- #shownAt = 0;
232
+ /** Pending safety-net timer id, or `null` when `timeout` is off or not armed. */
233
+ #timeoutTimerId = null;
74
234
  connect() {
75
- if (!this.element.hasAttribute("data-state")) {
235
+ this.#gate.cancel();
236
+ this.#beforeCache.activate();
237
+ if (this.#state === "pending" && this.#delayTimerId === null) {
238
+ this.#setBusy(false);
76
239
  this.element.setAttribute("data-state", "idle");
240
+ return;
77
241
  }
242
+ setDefaultAttribute(this.element, "data-state", "idle");
243
+ }
244
+ /**
245
+ * Re-applies the current phase to an indicator that arrived after `connect()`.
246
+ *
247
+ * A Turbo Stream can swap the indicator for a fresh node mid-load, and that node
248
+ * carries the markup contract's `hidden`. Without this the spinner would vanish
249
+ * while `data-state` still says `loading`, and nothing but the next cycle would
250
+ * bring it back.
251
+ */
252
+ indicatorTargetConnected(target) {
253
+ target.hidden = this.#state !== "loading";
78
254
  }
79
255
  disconnect() {
80
- this.#timers.clearAll();
81
- this.#delayTimerId = null;
82
- this.#hideTimerId = null;
256
+ this.#beforeCache.deactivate();
257
+ this.#gate.disconnected(this, () => this.#teardown());
83
258
  }
84
259
  /** Begins loading. Honors `delay` before the spinner actually appears. */
85
260
  start() {
86
261
  if (this.#state === "loading") {
87
262
  this.#setBusy(true);
88
- this.#cancelHide();
263
+ this.#floor.cancel();
264
+ this.#armTimeout();
89
265
  return;
90
266
  }
91
267
  if (this.#state !== "idle") return;
92
268
  this.#setBusy(true);
93
- this.#cancelHide();
269
+ this.#floor.cancel();
270
+ this.#armTimeout();
94
271
  if (this.delayValue > 0) {
95
272
  this.element.setAttribute("data-state", "pending");
96
273
  this.#delayTimerId = this.#timers.set(() => {
@@ -104,6 +281,7 @@ var SpinnerController = class extends Controller {
104
281
  /** Ends loading. Honors `minDuration` so a shown spinner does not flicker. */
105
282
  stop() {
106
283
  const state = this.#state;
284
+ this.#cancelTimeout();
107
285
  if (state === "pending") {
108
286
  this.#cancelDelay();
109
287
  this.#setBusy(false);
@@ -112,28 +290,52 @@ var SpinnerController = class extends Controller {
112
290
  }
113
291
  if (state !== "loading") return;
114
292
  this.#setBusy(false);
115
- const remaining = this.minDurationValue - (Date.now() - this.#shownAt);
116
- if (remaining > 0) {
117
- this.#hideTimerId = this.#timers.set(() => {
118
- this.#hideTimerId = null;
119
- this.#hide();
120
- }, remaining);
121
- } else {
122
- this.#hide();
123
- }
293
+ this.#floor.schedule(this.minDurationValue, () => this.#hide());
124
294
  }
125
295
  /** Reveals the indicator, marks the moment shown, and announces via the live region. */
126
296
  #show() {
127
- this.#shownAt = Date.now();
297
+ this.#floor.begin();
298
+ this.#setBusy(true);
128
299
  if (this.hasIndicatorTarget) this.indicatorTarget.hidden = false;
129
300
  this.element.setAttribute("data-state", "loading");
130
301
  this.dispatch("show", { detail: {} });
302
+ announce(fillTemplate(this.announceTextValue, {}));
131
303
  }
132
304
  /** Hides the indicator and returns to the idle state. */
133
305
  #hide() {
134
306
  if (this.hasIndicatorTarget) this.indicatorTarget.hidden = true;
135
307
  this.element.setAttribute("data-state", "idle");
136
308
  this.dispatch("hide", { detail: {} });
309
+ announce(fillTemplate(this.announceReadyTextValue, {}));
310
+ }
311
+ /**
312
+ * Drops both timers on a real detach. The markup keeps whatever it last held: an
313
+ * element on its way out of the document has no reader left, and one whose
314
+ * `data-controller` dropped the identifier no longer resolves its own targets, so
315
+ * the rollback could only ever be partial. The snapshot is rewound where it is
316
+ * still whole, on `turbo:before-cache`.
317
+ */
318
+ #teardown() {
319
+ this.#gate.cancel();
320
+ this.#timers.clearAll();
321
+ this.#delayTimerId = null;
322
+ this.#timeoutTimerId = null;
323
+ this.#floor.cancel();
324
+ }
325
+ /**
326
+ * Returns the loading state to idle for the snapshot Turbo is about to take,
327
+ * so a page reached with the Back button is not restored mid-load with a
328
+ * spinner nothing can stop. State only: `data-state`, the indicator's `hidden`,
329
+ * and `aria-busy`. No `hide` is dispatched — the load was never observed to
330
+ * finish, and a snapshot rewind is not a lifecycle event the consumer can act
331
+ * on. The live page keeps its timers, so a navigation that never completes
332
+ * leaves the running cycle intact.
333
+ */
334
+ #rewindForCache() {
335
+ this.#cancelTimeout();
336
+ this.#setBusy(false);
337
+ if (this.hasIndicatorTarget) this.indicatorTarget.hidden = true;
338
+ this.element.setAttribute("data-state", "idle");
137
339
  }
138
340
  /** Reflects busy state onto the controlled region (if present). */
139
341
  #setBusy(busy) {
@@ -141,18 +343,32 @@ var SpinnerController = class extends Controller {
141
343
  this.regionTarget.setAttribute("aria-busy", String(busy));
142
344
  }
143
345
  }
346
+ /**
347
+ * Arms the safety net so a `stop` that never arrives cannot strand the spinner.
348
+ * Off by default: the consumer owns the async work, so only it knows whether a
349
+ * ceiling makes sense. Re-arming on a restart measures from the newest start.
350
+ */
351
+ #armTimeout() {
352
+ this.#cancelTimeout();
353
+ if (this.timeoutValue <= 0) return;
354
+ this.#timeoutTimerId = this.#timers.set(() => {
355
+ this.#timeoutTimerId = null;
356
+ this.dispatch("timeout", { detail: {} });
357
+ this.stop();
358
+ }, this.timeoutValue);
359
+ }
360
+ #cancelTimeout() {
361
+ if (this.#timeoutTimerId !== null) {
362
+ this.#timers.clear(this.#timeoutTimerId);
363
+ this.#timeoutTimerId = null;
364
+ }
365
+ }
144
366
  #cancelDelay() {
145
367
  if (this.#delayTimerId !== null) {
146
368
  this.#timers.clear(this.#delayTimerId);
147
369
  this.#delayTimerId = null;
148
370
  }
149
371
  }
150
- #cancelHide() {
151
- if (this.#hideTimerId !== null) {
152
- this.#timers.clear(this.#hideTimerId);
153
- this.#hideTimerId = null;
154
- }
155
- }
156
372
  /** Current lifecycle phase as reflected on `data-state`. */
157
373
  get #state() {
158
374
  return this.element.getAttribute("data-state") ?? "idle";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/safe_timeout.ts","../../src/controllers/spinner_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,GAAe;AACjB,IAAA,OAAO,KAAK,GAAA,CAAI,IAAA;AAAA,EAClB;AACF,CAAA;AAmBO,IAAM,WAAA,GAAN,cAA0B,aAAA,CAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO7C,GAAA,CAAI,UAAsB,KAAA,EAAuB;AAC/C,IAAA,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;AAAA,EAEA,YAAA,GAAqB;AACnB,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;AAAA,EACF;AAAA,EAEA,WAAA,GAAoB;AAClB,IAAA,IAAI,IAAA,CAAK,iBAAiB,IAAA,EAAM;AAC9B,MAAA,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,IAAA,CAAK,YAAY,CAAA;AACpC,MAAA,IAAA,CAAK,YAAA,GAAe,IAAA;AAAA,IACtB;AAAA,EACF;AAAA;AAAA,EAGA,IAAI,MAAA,GAAiB;AACnB,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,YAAY,CAAA,IAAK,MAAA;AAAA,EACpD;AACF","file":"spinner_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 loading-indicator behavior built on the live-region + `aria-busy`\n * practice (no dedicated APG pattern).\n *\n * Markup contract (identifier: `stimeo--spinner`):\n * <div data-controller=\"stimeo--spinner\"\n * data-stimeo--spinner-delay-value=\"150\"\n * data-stimeo--spinner-min-duration-value=\"500\"\n * data-action=\"loading:start->stimeo--spinner#start\n * loading:stop->stimeo--spinner#stop\">\n * <div role=\"status\" aria-live=\"polite\" hidden\n * data-stimeo--spinner-target=\"indicator\">\n * <span data-stimeo--spinner-target=\"message\">Loading…</span>\n * </div>\n * <div aria-busy=\"false\" data-stimeo--spinner-target=\"region\"></div>\n * </div>\n *\n * The indicator is a `role=\"status\"` live region carrying *text* (never an icon\n * alone) so screen readers announce loading; the controlled `region` mirrors the\n * busy state via `aria-busy`. Two timers tame flicker: `delay` suppresses the\n * spinner for fast operations, and `minDuration` keeps it visible long enough to\n * be perceived once shown.\n *\n * @remarks\n * Behavior only — the visual spinner is the consumer's, alongside the text and\n * `aria-hidden=\"true\"`. Both timers are owned by {@link SafeTimeout} and torn\n * down on `disconnect()` (Turbo navigation included).\n */\nexport class SpinnerController extends Controller<HTMLElement> {\n static override targets = [\"indicator\", \"region\", \"message\"];\n static override values = {\n delay: { type: Number, default: 0 },\n minDuration: { type: Number, default: 0 },\n };\n static actions = [\"start\", \"stop\"] as const;\n static events = [\"hide\", \"show\"] as const;\n\n declare readonly indicatorTarget: HTMLElement;\n declare readonly regionTarget: HTMLElement;\n declare readonly messageTarget: HTMLElement;\n declare readonly hasIndicatorTarget: boolean;\n declare readonly hasRegionTarget: boolean;\n declare readonly hasMessageTarget: boolean;\n\n declare delayValue: number;\n declare minDurationValue: number;\n\n readonly #timers = new SafeTimeout();\n\n /** Pending show-delay timer id, or `null` when no start is awaiting its delay. */\n #delayTimerId: number | null = null;\n /** Pending min-duration hide timer id, or `null` when none is scheduled. */\n #hideTimerId: number | null = null;\n /** Epoch ms when the spinner became visible; `minDuration` is measured from it. */\n #shownAt = 0;\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 this.#delayTimerId = null;\n this.#hideTimerId = null;\n }\n\n /** Begins loading. Honors `delay` before the spinner actually appears. */\n start(): void {\n if (this.#state === \"loading\") {\n // Already shown (possibly waiting out `minDuration` after a stop): a quick\n // stop→start within that window must keep the spinner visible. Restore the\n // busy state and cancel the pending hide instead of returning a no-op, which\n // would let the stale hide fire and flicker the spinner away mid-load.\n this.#setBusy(true);\n this.#cancelHide();\n return;\n }\n if (this.#state !== \"idle\") return;\n this.#setBusy(true);\n // A pending hide from a previous cycle is now stale.\n this.#cancelHide();\n if (this.delayValue > 0) {\n this.element.setAttribute(\"data-state\", \"pending\");\n this.#delayTimerId = this.#timers.set(() => {\n this.#delayTimerId = null;\n this.#show();\n }, this.delayValue);\n } else {\n this.#show();\n }\n }\n\n /** Ends loading. Honors `minDuration` so a shown spinner does not flicker. */\n stop(): void {\n const state = this.#state;\n if (state === \"pending\") {\n // The delay never elapsed — the spinner never appeared, so just cancel.\n this.#cancelDelay();\n this.#setBusy(false);\n this.element.setAttribute(\"data-state\", \"idle\");\n return;\n }\n if (state !== \"loading\") return;\n\n this.#setBusy(false);\n const remaining = this.minDurationValue - (Date.now() - this.#shownAt);\n if (remaining > 0) {\n this.#hideTimerId = this.#timers.set(() => {\n this.#hideTimerId = null;\n this.#hide();\n }, remaining);\n } else {\n this.#hide();\n }\n }\n\n /** Reveals the indicator, marks the moment shown, and announces via the live region. */\n #show(): void {\n this.#shownAt = Date.now();\n if (this.hasIndicatorTarget) this.indicatorTarget.hidden = false;\n this.element.setAttribute(\"data-state\", \"loading\");\n this.dispatch(\"show\", { detail: {} });\n }\n\n /** Hides the indicator and returns to the idle state. */\n #hide(): void {\n if (this.hasIndicatorTarget) this.indicatorTarget.hidden = true;\n this.element.setAttribute(\"data-state\", \"idle\");\n this.dispatch(\"hide\", { detail: {} });\n }\n\n /** Reflects busy state onto the controlled region (if present). */\n #setBusy(busy: boolean): void {\n if (this.hasRegionTarget) {\n this.regionTarget.setAttribute(\"aria-busy\", String(busy));\n }\n }\n\n #cancelDelay(): void {\n if (this.#delayTimerId !== null) {\n this.#timers.clear(this.#delayTimerId);\n this.#delayTimerId = null;\n }\n }\n\n #cancelHide(): void {\n if (this.#hideTimerId !== null) {\n this.#timers.clear(this.#hideTimerId);\n this.#hideTimerId = null;\n }\n }\n\n /** Current lifecycle phase as reflected on `data-state`. */\n get #state(): string {\n return this.element.getAttribute(\"data-state\") ?? \"idle\";\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/announce.ts","../../src/utils/before_cache_reset.ts","../../src/utils/default_attribute.ts","../../src/utils/detach_gate.ts","../../src/utils/min_duration_floor.ts","../../src/utils/safe_timeout.ts","../../src/controllers/spinner_controller.ts"],"names":[],"mappings":";;;;;AAoBO,SAAS,QAAA,CAAS,OAAA,EAAiB,OAAA,GAAmC,EAAC,EAAS;AACrF,EAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,EAAK;AAC1B,EAAA,IAAI,IAAA,CAAK,WAAW,CAAA,EAAG;AACvB,EAAA,MAAA,CAAO,aAAA;AAAA,IACL,IAAI,YAAY,4BAAA,EAA8B;AAAA,MAC5C,QAAQ,EAAE,OAAA,EAAS,MAAM,SAAA,EAAW,OAAA,CAAQ,cAAc,IAAA;AAAK,KAChE;AAAA,GACH;AACF;AAUO,SAAS,YAAA,CAAa,UAAkB,MAAA,EAAiD;AAC9F,EAAA,OAAO,QAAA,CAAS,OAAA,CAAQ,6BAAA,EAA+B,CAAC,OAAO,IAAA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I,IAAA,CAAK,oBAAoB,IAAA,EAAM;AACjC,MAAA,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,IAAA,CAAK,eAAe,CAAA;AACvC,MAAA,IAAA,CAAK,eAAA,GAAkB,IAAA;AAAA,IACzB;AAAA,EACF;AAAA,EAEA,YAAA,GAAqB;AACnB,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;AAAA,EACF;AAAA;AAAA,EAGA,IAAI,MAAA,GAAiB;AACnB,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,YAAY,CAAA,IAAK,MAAA;AAAA,EACpD;AACF","file":"spinner_controller.js","sourcesContent":["/**\n * Sends one message to the page's shared `stimeo--announcer`.\n *\n * A component that has to reach assistive tech does not carry a live region of its\n * own: a region only announces what changes *after* assistive tech already knows\n * about it, which a region that appears (or is un-hidden) with its message cannot\n * satisfy. The one region that can is the announcer sitting in the page from the\n * start, so state changes are handed to it as an event and it does the reading.\n *\n * The event goes to `window` because the announcer is usually a sibling high in the\n * document rather than an ancestor of the component dispatching it.\n *\n * Wording comes from the consumer — the library ships no English strings — so an\n * empty message is silently dropped and nothing is announced.\n *\n * @example\n * ```ts\n * announce(this.announceTextValue, { assertive: false });\n * ```\n */\nexport function announce(message: string, options: { assertive?: boolean } = {}): void {\n const text = message.trim();\n if (text.length === 0) return;\n window.dispatchEvent(\n new CustomEvent(\"stimeo--announcer:announce\", {\n detail: { message: text, assertive: options.assertive === true },\n }),\n );\n}\n\n/**\n * Fills `{name}` placeholders in an announcement template from `values`.\n *\n * The same substitution the value-text templates use, so a consumer writes\n * `\"{percent}% complete\"` in one attribute and gets the same rules everywhere. A\n * placeholder with no matching entry is left as authored rather than blanked, which\n * keeps a typo visible instead of silently swallowing the word.\n */\nexport function fillTemplate(template: string, values: Record<string, string | number>): string {\n return template.replace(/\\{([a-zA-Z][a-zA-Z0-9]*)\\}/g, (match, name: string) => {\n const replacement = values[name];\n return replacement === undefined ? match : String(replacement);\n });\n}\n","/**\n * Runs a controller's \"return to the initial state\" pass just before Turbo\n * caches the page.\n *\n * **`disconnect()` cannot do this job, for two independent reasons.** Turbo\n * queues the clone from this event rather than taking it here, and the body swap\n * that runs the controller's `disconnect()` is queued separately — so which of\n * the two lands first is not something a controller can rely on, and a rewind\n * written in `disconnect()` may reach only the DOM being thrown away. In the\n * other direction, `disconnect()` also fires on an in-page move (Stimulus tears\n * down and reconnects the same element), where rewinding would wipe a\n * legitimately in-progress interaction — a spinner mid-load would vanish. One\n * timing is unreliable, the other is too eager; `turbo:before-cache` is the only\n * point that is exactly \"the page is about to be frozen\".\n *\n * Scope is the subscription only: registering on `activate()`, unregistering on\n * `deactivate()`, and one shared document listener no matter how many instances\n * are live. *What* to return to its initial state — which `data-state`, which\n * `hidden`, which `aria-busy` — stays in the controller, because no two\n * consumers answer it the same way (the `MicrotaskCoalescer` split).\n *\n * **Rewind state, not appearance.** The pass writes attributes the controller\n * itself owns; the visual result of those attributes is the consumer's CSS, and\n * a library that reached for style or class names would be guessing at markup\n * it does not own.\n *\n * Both entry points are idempotent, so the lifecycle hooks can call them\n * unconditionally: a second `activate()` does not double-subscribe and does not\n * make the callback run twice, and `deactivate()` on an instance that never\n * subscribed is a no-op.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #beforeCache = new BeforeCacheReset(() => this.#rewind());\n *\n * connect() { this.#beforeCache.activate(); }\n * disconnect() { this.#beforeCache.deactivate(); }\n * ```\n */\nexport class BeforeCacheReset {\n /** Every subscribed instance, iterated by the one shared document listener. */\n static readonly #subscribers = new Set<BeforeCacheReset>();\n\n /** The shared listener; installed while at least one instance is subscribed. */\n static readonly #onBeforeCache = (): void => {\n for (const subscriber of BeforeCacheReset.#subscribers) subscriber.#rewind();\n };\n\n readonly #rewind: () => void;\n\n /** @param rewind - the pass that returns this controller's state to its initial form. */\n constructor(rewind: () => void) {\n this.#rewind = rewind;\n }\n\n /** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */\n activate(): void {\n const first = BeforeCacheReset.#subscribers.size === 0;\n BeforeCacheReset.#subscribers.add(this);\n if (first) {\n document.addEventListener(\"turbo:before-cache\", BeforeCacheReset.#onBeforeCache);\n }\n }\n\n /** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */\n deactivate(): void {\n BeforeCacheReset.#subscribers.delete(this);\n if (BeforeCacheReset.#subscribers.size > 0) return;\n document.removeEventListener(\"turbo:before-cache\", BeforeCacheReset.#onBeforeCache);\n }\n}\n","/**\n * Adds an attribute default without displacing an authored value.\n *\n * Attribute presence — including an authored empty string — is the ownership\n * boundary. The return value lets a caller remember that it supplied the\n * default when that caller must later restore the authored state.\n *\n * @param element - Element that owns the attribute\n * @param name - Attribute name\n * @param value - Value to write only when the attribute is absent\n * @returns Whether this call added the attribute\n */\nexport function setDefaultAttribute(element: Element, name: string, value: string): boolean {\n if (element.hasAttribute(name)) return false;\n element.setAttribute(name, value);\n return true;\n}\n","/**\n * Shared \"in-page move vs real detach\" discriminator for `disconnect()`.\n *\n * A mid-session `disconnect()` whose element is still in the document is\n * ambiguous. It can be:\n *\n * - an **in-page move** — a consumer (sortable, a teleport) re-inserted the\n * element; Stimulus reconnects the SAME instance in the same mutation batch\n * and the controller's runtime state must survive;\n * - a **detach that keeps the element** — `data-controller` no longer lists the\n * identifier (a Turbo 8 morph), or the element moved outside the observed\n * root (a scoped `Application.start(root)`, a shadow root); no reconnect will\n * ever come and the controller must tear down or it leaks its sessions,\n * document listeners, and moved nodes.\n *\n * Neither available signal decides this alone. A synchronous `data-controller`\n * token check catches the morph case but misses an observed-root exit (the\n * token stays, the reconnect never comes). Deferring teardown one microtask and\n * letting `connect()` cancel it catches the root exit, but leans on Stimulus\n * reconnecting moved elements within the same mutation batch — internal\n * behavior, not a public contract. {@link DetachGate} composes both: the token\n * check is the synchronous fast path (no probe, no reliance on batching), the\n * microtask probe is the fallback for the genuinely ambiguous remainder.\n *\n * Policy stays with the consumer (the `SafeTimeout` / `FocusTrap` lineage —\n * this util owns the discrimination only):\n *\n * - **Probe** ({@link disconnected}) when the teardown must eventually happen —\n * live drag sessions, document listeners, teleported *content*. Call\n * {@link cancel} from `connect()` (a reconnect means in-page move) and from\n * the head of any direct teardown path (see below).\n * - **Keep** (bare {@link DetachGate.isDetached}) when undoing the ambiguous\n * case would fight the controller's own effect: a controller that moves its\n * OWN element (portal's no-`content` form) exits a scoped observed root as\n * its normal job — a probe-driven teardown would restore the element into\n * the root, reconnect, re-teleport, and disconnect again, forever. Such\n * controllers keep their state on an ambiguous disconnect and tear down only\n * on {@link DetachGate.isDetached}.\n *\n * Event convention for probe consumers: teardown into a dead (detached) tree is\n * silent — consumers restore from their own `connect()`; a detach that keeps the\n * tree alive must end an in-flight session with a `cancel` event, or composing\n * consumers strand their session bookkeeping.\n */\n\n/** The slice of a Stimulus controller the gate inspects. */\nexport interface DetachGateHost {\n readonly element: Element;\n readonly identifier: string;\n}\n\n/**\n * Per-controller-instance gate deciding whether a `disconnect()` is a real\n * detach. Hold one per controller (`#gate = new DetachGate()`) — Stimulus\n * reuses the instance across reconnects, so the pending probe state carries\n * over exactly as the protocol needs.\n *\n * @example\n * ```ts\n * #gate = new DetachGate();\n *\n * connect(): void {\n * this.#gate.cancel(); // a reconnect: the element moved in-page\n * // …\n * }\n *\n * disconnect(): void {\n * this.#gate.disconnected(this, () => this.#teardown());\n * }\n *\n * #teardown(): void {\n * this.#gate.cancel(); // disarm a still-queued probe (double-run guard)\n * // …\n * }\n * ```\n */\nexport class DetachGate {\n /** Set while a probe is queued, waiting for a reconnect to cancel it. */\n #pending = false;\n\n /**\n * True while a probe is queued — the last disconnect was ambiguous and no\n * reconnect has cancelled it yet. Read it from `connect()` to tell the\n * reconnect half of an in-page move from a first connect: a controller whose\n * initialisation restarts a measurement (a min-duration floor, an elapsed\n * counter) must skip it for the move, where nothing actually restarted.\n */\n get pending(): boolean {\n return this.#pending;\n }\n\n /**\n * True when the disconnect is definitely a real detach — the element left\n * the document, or `data-controller` no longer lists the identifier. False\n * means ambiguous (in-page move or observed-root exit), NOT \"alive\".\n */\n static isDetached(host: DetachGateHost): boolean {\n if (!host.element.isConnected) return true;\n const tokens = (host.element.getAttribute(\"data-controller\") ?? \"\").split(/\\s+/);\n return !tokens.includes(host.identifier);\n }\n\n /**\n * Call from `disconnect()`: runs `teardown` synchronously on a definite\n * detach (fast path), otherwise defers it one microtask — a reconnect\n * ({@link cancel} from `connect()`) keeps the state, no reconnect runs it.\n * One microtask is the whole probe window: Stimulus reconnects a moved\n * element within the same mutation batch, before the checkpoint drains.\n */\n disconnected(host: DetachGateHost, teardown: () => void): void {\n if (DetachGate.isDetached(host)) {\n // Also disarms a probe a previous ambiguous disconnect left queued\n // (defer, element removed, disconnect again) — exactly one teardown.\n this.#pending = false;\n teardown();\n return;\n }\n this.#pending = true;\n queueMicrotask(() => {\n if (!this.#pending) return;\n this.#pending = false;\n teardown();\n });\n }\n\n /**\n * Disarms a pending probe. Call from `connect()` (the reconnect that proves\n * an in-page move) and from the head of any teardown path not routed through\n * {@link disconnected} (disabled-toggle, Escape), so an orphaned probe can\n * never run the teardown a second time.\n */\n cancel(): void {\n this.#pending = false;\n }\n}\n","import type { SafeTimeout } from \"./safe_timeout\";\n\n/**\n * Holds a transient state visible for a minimum time before letting it end.\n *\n * A loading indicator that appears and disappears within a few frames reads as a\n * flicker rather than as feedback, so several controllers keep one up for a floor\n * of `minDuration` milliseconds measured from the moment it became visible. The\n * shape is always the same: note the moment, and when the end signal arrives\n * either run it now, because the floor has already passed, or hold it on a timer\n * for whatever is left.\n *\n * The floor **borrows** a {@link SafeTimeout} instead of owning one, so a\n * controller that also schedules other work (a show delay) keeps every timer in a\n * single registry and one `clearAll()` in its teardown still drops them all.\n * Cancelling after such a bulk clear is safe: the registry no-ops on an id it no\n * longer holds.\n *\n * Scope is the floor itself. **When an end signal is allowed to arrive at all\n * stays with the controller**, because the answers differ — one keeps the first\n * queued finish and ignores repeats, another lets the newest replace it — and\n * flattening that into a shared default would silently change what the consumers\n * already promise.\n *\n * @example\n * ```ts\n * readonly #timers = new SafeTimeout();\n * readonly #floor = new MinDurationFloor(this.#timers);\n *\n * #show() { this.#floor.begin(); … }\n * stop() { this.#floor.schedule(this.minDurationValue, () => this.#hide()); }\n * ```\n */\nexport class MinDurationFloor {\n readonly #timers: SafeTimeout;\n\n /** Pending finish timer id, or `null` when nothing is held back. */\n #timerId: number | null = null;\n\n /** Epoch ms the floor is measured from. */\n #since = 0;\n\n /** @param timers - the controller's registry; the floor schedules into it. */\n constructor(timers: SafeTimeout) {\n this.#timers = timers;\n }\n\n /** Starts the floor: call when the state being held becomes visible. */\n begin(): void {\n this.#since = Date.now();\n }\n\n /** True while a finish is held back waiting for the floor to elapse. */\n get pending(): boolean {\n return this.#timerId !== null;\n }\n\n /**\n * Runs `finish` once the floor has elapsed, immediately when it already has.\n *\n * A held-back finish is **replaced**, never stacked: only the most recently\n * queued id is cancellable, so a second timer would outlive every cancel and\n * end a state that has since restarted. Controllers that want the first signal\n * to win guard on {@link pending} before calling.\n */\n schedule(minDuration: number, finish: () => void): void {\n this.cancel();\n const remaining = minDuration - (Date.now() - this.#since);\n if (remaining > 0) {\n this.#timerId = this.#timers.set(() => {\n this.#timerId = null;\n finish();\n }, remaining);\n } else {\n finish();\n }\n }\n\n /** Drops a held-back finish. Safe when none is queued, or after a bulk clear. */\n cancel(): void {\n if (this.#timerId !== null) {\n this.#timers.clear(this.#timerId);\n this.#timerId = null;\n }\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 { Controller } from \"@hotwired/stimulus\";\nimport { announce, fillTemplate } from \"../utils/announce\";\nimport { BeforeCacheReset } from \"../utils/before_cache_reset\";\nimport { setDefaultAttribute } from \"../utils/default_attribute\";\nimport { DetachGate } from \"../utils/detach_gate\";\nimport { MinDurationFloor } from \"../utils/min_duration_floor\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/**\n * Headless loading-indicator behavior built on the `aria-busy` practice (no\n * dedicated APG pattern).\n *\n * Markup contract (identifier: `stimeo--spinner`):\n * <div data-controller=\"stimeo--spinner\"\n * data-stimeo--spinner-delay-value=\"150\"\n * data-stimeo--spinner-min-duration-value=\"500\"\n * data-stimeo--spinner-timeout-value=\"0\"\n * data-stimeo--spinner-announce-text-value=\"Loading…\"\n * data-stimeo--spinner-announce-ready-text-value=\"Loading finished.\"\n * data-action=\"loading:start->stimeo--spinner#start\n * loading:stop->stimeo--spinner#stop\">\n * <div hidden data-stimeo--spinner-target=\"indicator\">\n * <span data-stimeo--spinner-target=\"message\">Loading…</span>\n * </div>\n * <div aria-busy=\"false\" data-stimeo--spinner-target=\"region\"></div>\n * </div>\n *\n * The indicator is the visual half — its text plus a spinner the consumer marks\n * `aria-hidden=\"true\"` — and the controlled `region` mirrors the busy state via\n * `aria-busy`. Assistive tech hears the transition through `announceText` /\n * `announceReadyText`, which go to the page's announcer: an indicator that only\n * becomes visible at the moment of the change is not reliably read, and giving it\n * live-region semantics on top of the announcement would say it twice. Two timers\n * tame flicker: `delay` suppresses the spinner for fast operations, and\n * `minDuration` keeps it visible long enough to be perceived once shown.\n * `timeout` is the opt-in safety net for the case the consumer's `stop` never\n * arrives.\n *\n * Events (all with an empty `detail`):\n * - `stimeo--spinner:show` — the indicator became visible, after `delay`.\n * - `stimeo--spinner:hide` — the indicator went away, after `minDuration`.\n * - `stimeo--spinner:timeout` — `timeout` elapsed with the load still running;\n * the controller then ends it exactly as `stop` would, so a `hide` follows.\n *\n * @remarks\n * Behavior only — the visual spinner is the consumer's, alongside the text and\n * `aria-hidden=\"true\"`. Both timers are owned by {@link SafeTimeout}, kept across\n * an in-page move and dropped on a real detach via {@link DetachGate}, while the\n * loading state a cached page would freeze is rewound by {@link BeforeCacheReset}.\n */\nexport class SpinnerController extends Controller<HTMLElement> {\n static override targets = [\"indicator\", \"region\", \"message\"];\n static override values = {\n announceText: { type: String, default: \"\" },\n announceReadyText: { type: String, default: \"\" },\n delay: { type: Number, default: 0 },\n minDuration: { type: Number, default: 0 },\n timeout: { type: Number, default: 0 },\n };\n static actions = [\"start\", \"stop\"] as const;\n static events = [\"hide\", \"show\", \"timeout\"] as const;\n\n declare readonly indicatorTarget: HTMLElement;\n declare readonly regionTarget: HTMLElement;\n declare readonly messageTarget: HTMLElement;\n declare readonly hasIndicatorTarget: boolean;\n declare readonly hasRegionTarget: boolean;\n declare readonly hasMessageTarget: boolean;\n\n declare delayValue: number;\n declare minDurationValue: number;\n declare timeoutValue: number;\n declare announceTextValue: string;\n declare announceReadyTextValue: string;\n\n readonly #timers = new SafeTimeout();\n readonly #floor = new MinDurationFloor(this.#timers);\n readonly #gate = new DetachGate();\n readonly #beforeCache = new BeforeCacheReset(() => this.#rewindForCache());\n\n /** Pending show-delay timer id, or `null` when no start is awaiting its delay. */\n #delayTimerId: number | null = null;\n /** Pending safety-net timer id, or `null` when `timeout` is off or not armed. */\n #timeoutTimerId: number | null = null;\n\n override connect(): void {\n this.#gate.cancel();\n this.#beforeCache.activate();\n if (this.#state === \"pending\" && this.#delayTimerId === null) {\n // `pending` lives exactly as long as its show-delay timer. Reading it back with\n // no timer of this instance behind it means the markup outlived the timer — a\n // restored snapshot, or an element re-attached too late to count as a move — so\n // nothing is left to advance it and `start()` would refuse every later load.\n // Fall back to idle, dropping the busy flag the interrupted `start()` set.\n this.#setBusy(false);\n this.element.setAttribute(\"data-state\", \"idle\");\n return;\n }\n setDefaultAttribute(this.element, \"data-state\", \"idle\");\n }\n\n /**\n * Re-applies the current phase to an indicator that arrived after `connect()`.\n *\n * A Turbo Stream can swap the indicator for a fresh node mid-load, and that node\n * carries the markup contract's `hidden`. Without this the spinner would vanish\n * while `data-state` still says `loading`, and nothing but the next cycle would\n * bring it back.\n */\n indicatorTargetConnected(target: HTMLElement): void {\n target.hidden = this.#state !== \"loading\";\n }\n\n override disconnect(): void {\n // Symmetric with `connect()` regardless of why the disconnect came: an in-page\n // move re-subscribes, and only the timers are held back for the reconnect.\n this.#beforeCache.deactivate();\n this.#gate.disconnected(this, () => this.#teardown());\n }\n\n /** Begins loading. Honors `delay` before the spinner actually appears. */\n start(): void {\n if (this.#state === \"loading\") {\n // Already shown (possibly waiting out `minDuration` after a stop): a quick\n // stop→start within that window must keep the spinner visible. Restore the\n // busy state and cancel the pending hide instead of returning a no-op, which\n // would let the stale hide fire and flicker the spinner away mid-load.\n this.#setBusy(true);\n this.#floor.cancel();\n this.#armTimeout();\n return;\n }\n if (this.#state !== \"idle\") return;\n this.#setBusy(true);\n // A hide held back from a previous cycle is now stale.\n this.#floor.cancel();\n this.#armTimeout();\n if (this.delayValue > 0) {\n this.element.setAttribute(\"data-state\", \"pending\");\n this.#delayTimerId = this.#timers.set(() => {\n this.#delayTimerId = null;\n this.#show();\n }, this.delayValue);\n } else {\n this.#show();\n }\n }\n\n /** Ends loading. Honors `minDuration` so a shown spinner does not flicker. */\n stop(): void {\n const state = this.#state;\n this.#cancelTimeout();\n if (state === \"pending\") {\n // The delay never elapsed — the spinner never appeared, so just cancel.\n this.#cancelDelay();\n this.#setBusy(false);\n this.element.setAttribute(\"data-state\", \"idle\");\n return;\n }\n if (state !== \"loading\") return;\n\n this.#setBusy(false);\n this.#floor.schedule(this.minDurationValue, () => this.#hide());\n }\n\n /** Reveals the indicator, marks the moment shown, and announces via the live region. */\n #show(): void {\n this.#floor.begin();\n // A visible spinner always means a busy region. Re-asserting it costs nothing on\n // the direct path and closes the one where a snapshot rewind cleared the flag\n // while the show-delay timer it deliberately spared was still armed.\n this.#setBusy(true);\n if (this.hasIndicatorTarget) this.indicatorTarget.hidden = false;\n this.element.setAttribute(\"data-state\", \"loading\");\n this.dispatch(\"show\", { detail: {} });\n // loading ↔ ready is the transition worth reading; the spinner itself is\n // visual and carries no words.\n announce(fillTemplate(this.announceTextValue, {}));\n }\n\n /** Hides the indicator and returns to the idle state. */\n #hide(): void {\n if (this.hasIndicatorTarget) this.indicatorTarget.hidden = true;\n this.element.setAttribute(\"data-state\", \"idle\");\n this.dispatch(\"hide\", { detail: {} });\n announce(fillTemplate(this.announceReadyTextValue, {}));\n }\n\n /**\n * Drops both timers on a real detach. The markup keeps whatever it last held: an\n * element on its way out of the document has no reader left, and one whose\n * `data-controller` dropped the identifier no longer resolves its own targets, so\n * the rollback could only ever be partial. The snapshot is rewound where it is\n * still whole, on `turbo:before-cache`.\n */\n #teardown(): void {\n this.#gate.cancel();\n this.#timers.clearAll();\n this.#delayTimerId = null;\n this.#timeoutTimerId = null;\n this.#floor.cancel();\n }\n\n /**\n * Returns the loading state to idle for the snapshot Turbo is about to take,\n * so a page reached with the Back button is not restored mid-load with a\n * spinner nothing can stop. State only: `data-state`, the indicator's `hidden`,\n * and `aria-busy`. No `hide` is dispatched — the load was never observed to\n * finish, and a snapshot rewind is not a lifecycle event the consumer can act\n * on. The live page keeps its timers, so a navigation that never completes\n * leaves the running cycle intact.\n */\n #rewindForCache(): void {\n this.#cancelTimeout();\n this.#setBusy(false);\n if (this.hasIndicatorTarget) this.indicatorTarget.hidden = true;\n this.element.setAttribute(\"data-state\", \"idle\");\n }\n\n /** Reflects busy state onto the controlled region (if present). */\n #setBusy(busy: boolean): void {\n if (this.hasRegionTarget) {\n this.regionTarget.setAttribute(\"aria-busy\", String(busy));\n }\n }\n\n /**\n * Arms the safety net so a `stop` that never arrives cannot strand the spinner.\n * Off by default: the consumer owns the async work, so only it knows whether a\n * ceiling makes sense. Re-arming on a restart measures from the newest start.\n */\n #armTimeout(): void {\n this.#cancelTimeout();\n if (this.timeoutValue <= 0) return;\n this.#timeoutTimerId = this.#timers.set(() => {\n this.#timeoutTimerId = null;\n this.dispatch(\"timeout\", { detail: {} });\n this.stop();\n }, this.timeoutValue);\n }\n\n #cancelTimeout(): void {\n if (this.#timeoutTimerId !== null) {\n this.#timers.clear(this.#timeoutTimerId);\n this.#timeoutTimerId = null;\n }\n }\n\n #cancelDelay(): void {\n if (this.#delayTimerId !== null) {\n this.#timers.clear(this.#delayTimerId);\n this.#delayTimerId = null;\n }\n }\n\n /** Current lifecycle phase as reflected on `data-state`. */\n get #state(): string {\n return this.element.getAttribute(\"data-state\") ?? \"idle\";\n }\n}\n"]}
@@ -20,11 +20,12 @@ import { Controller } from '@hotwired/stimulus';
20
20
  * @remarks
21
21
  * Behavior only. Each step `<li>` gets a `data-state` (`complete`/`current`/
22
22
  * `upcoming`) derived from the current index; the consumer draws the circles,
23
- * lines, and numbers from those hooks. A `--stimeo-step-indicator-ratio`
23
+ * lines, and numbers from those hooks. A `--stimeo--step-indicator-ratio`
24
24
  * (0–1) custom property on the root expresses overall progress for CSS.
25
25
  *
26
26
  * Behavior provided:
27
27
  * - Reflects `current` onto each step's `data-state` and `aria-current`.
28
+ * - Re-derives every step when the step set changes at runtime.
28
29
  * - `setCurrent` (bound to an event whose `detail.current` is the 0-based index)
29
30
  * updates the current step and dispatches `stimeo--step-indicator:change`.
30
31
  */
@@ -43,9 +44,19 @@ declare class StepIndicatorController extends Controller<HTMLElement> {
43
44
  currentValue: number;
44
45
  /** Renders the initial state from the `current` value. */
45
46
  connect(): void;
47
+ /** Closes the window in which a queued repaint may still run. */
48
+ disconnect(): void;
49
+ /** Syncs a step appended or replaced at runtime (the consumer owns the list). */
50
+ stepTargetConnected(): void;
51
+ /** Re-derives the remaining steps when one is removed at runtime. */
52
+ stepTargetDisconnected(): void;
53
+ /** Repaints when application code (or a Turbo morph) changes `current` at runtime. */
54
+ currentValueChanged(): void;
46
55
  /**
47
56
  * Updates the current step from an external event (`detail.current`, 0-based)
48
- * and dispatches `change`. Out-of-range indices are clamped to the step set.
57
+ * and dispatches `change`. Out-of-range indices are clamped to the step set,
58
+ * and both sides of the no-op test are clamped, so moving onto the step an
59
+ * out-of-range `current` already renders is not reported as a change.
49
60
  */
50
61
  setCurrent(event: CustomEvent<{
51
62
  current?: number;