stimeo-ui 0.1.0.pre.beta.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +149 -0
  3. data/README.md +6 -6
  4. data/dist/controllers/alert_dialog_controller.js +318 -0
  5. data/dist/controllers/auto_submit_controller.js +56 -21
  6. data/dist/controllers/carousel_controller.js +272 -0
  7. data/dist/controllers/character_counter_controller.js +52 -15
  8. data/dist/controllers/clipboard_controller.js +144 -0
  9. data/dist/controllers/collapsible_controller.js +327 -0
  10. data/dist/controllers/color_picker_controller.js +213 -0
  11. data/dist/controllers/combobox_controller.js +64 -3
  12. data/dist/controllers/command_palette_controller.js +243 -39
  13. data/dist/controllers/confirm_controller.js +94 -8
  14. data/dist/controllers/context_menu_controller.js +191 -13
  15. data/dist/controllers/count_up_controller.js +8 -1
  16. data/dist/controllers/countdown_controller.js +2 -2
  17. data/dist/controllers/currency_input_controller.js +147 -0
  18. data/dist/controllers/data_grid_controller.js +168 -0
  19. data/dist/controllers/date_range_picker_controller.js +417 -0
  20. data/dist/controllers/dialog_controller.js +94 -8
  21. data/dist/controllers/dismissible_controller.js +117 -0
  22. data/dist/controllers/drawer_controller.js +630 -0
  23. data/dist/controllers/dropdown_controller.js +139 -16
  24. data/dist/controllers/editable_controller.js +168 -0
  25. data/dist/controllers/file_dropzone_controller.js +165 -0
  26. data/dist/controllers/filter_controller.js +86 -0
  27. data/dist/controllers/flash_controller.js +36 -5
  28. data/dist/controllers/focus_controller.js +94 -8
  29. data/dist/controllers/form_validation_controller.js +2 -2
  30. data/dist/controllers/highlight_controller.js +6 -4
  31. data/dist/controllers/hover_card_controller.js +103 -27
  32. data/dist/controllers/intersection_controller.js +41 -18
  33. data/dist/controllers/lazy_frame_controller.js +33 -11
  34. data/dist/controllers/listbox_controller.js +1 -0
  35. data/dist/controllers/masonry_controller.js +142 -0
  36. data/dist/controllers/menu_controller.js +181 -8
  37. data/dist/controllers/menubar_controller.js +433 -0
  38. data/dist/controllers/multi_select_controller.js +472 -0
  39. data/dist/controllers/navigation_menu_controller.js +384 -0
  40. data/dist/controllers/otp_controller.js +62 -22
  41. data/dist/controllers/overflow_indicator_controller.js +178 -27
  42. data/dist/controllers/password_reveal_controller.js +117 -0
  43. data/dist/controllers/pointer_drag_controller.js +3 -3
  44. data/dist/controllers/popover_controller.js +118 -27
  45. data/dist/controllers/range_slider_controller.js +166 -0
  46. data/dist/controllers/read_more_controller.js +194 -0
  47. data/dist/controllers/scroll_area_controller.js +15 -2
  48. data/dist/controllers/scroll_restore_controller.js +93 -0
  49. data/dist/controllers/scroll_visibility_controller.js +8 -4
  50. data/dist/controllers/scrollspy_controller.js +33 -11
  51. data/dist/controllers/separator_controller.js +87 -0
  52. data/dist/controllers/sidebar_controller.js +761 -0
  53. data/dist/controllers/stepper_controller.js +28 -12
  54. data/dist/controllers/stick_to_bottom_controller.js +8 -4
  55. data/dist/controllers/sticky_observer_controller.js +88 -20
  56. data/dist/controllers/tags_input_controller.js +275 -0
  57. data/dist/controllers/theme_controller.js +20 -10
  58. data/dist/controllers/time_picker_controller.js +212 -0
  59. data/dist/controllers/toast_controller.js +144 -38
  60. data/dist/controllers/tooltip_controller.js +148 -42
  61. data/dist/controllers/transition_controller.js +153 -38
  62. data/dist/controllers/tree_view_controller.js +275 -0
  63. data/dist/index.js +1644 -643
  64. data/lib/stimeo/ui/version.rb +5 -4
  65. metadata +28 -2
@@ -0,0 +1,212 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+
3
+ // src/controllers/time_picker_controller.ts
4
+ var AM = 0;
5
+ var PM = 1;
6
+ var TimePickerController = class extends Controller {
7
+ static targets = ["segment", "field"];
8
+ static values = {
9
+ hourCycle: { type: Number, default: 24 },
10
+ step: { type: Number, default: 1 },
11
+ seconds: { type: Boolean, default: false },
12
+ wrap: { type: Boolean, default: true }
13
+ };
14
+ static actions = ["onKeydown"];
15
+ static events = ["change"];
16
+ /** Current numeric value per segment kind (hours are the *displayed* hours). */
17
+ #state = { hour: 0, minute: 0, second: 0, meridiem: AM };
18
+ /** Direct-entry digit buffer and the segment it belongs to. */
19
+ #typeBuffer = "";
20
+ #typeSegment = null;
21
+ /** Last composed field value, to suppress duplicate `change` dispatches. */
22
+ #lastValue = "";
23
+ /** Seeds each segment from its initial `aria-valuenow` and syncs the field. */
24
+ connect() {
25
+ for (const segment of this.segmentTargets) {
26
+ const kind = this.#kindOf(segment);
27
+ if (!kind) continue;
28
+ const now = Number(segment.getAttribute("aria-valuenow"));
29
+ const { min, max } = this.#bounds(kind);
30
+ this.#state[kind] = Number.isFinite(now) ? Math.min(max, Math.max(min, now)) : min;
31
+ }
32
+ for (const segment of this.segmentTargets) this.#renderSegment(segment);
33
+ this.#syncField(false);
34
+ }
35
+ /** Handles stepping, inter-segment focus moves, jumps, and direct entry. */
36
+ onKeydown(event) {
37
+ const segment = event.target?.closest(
38
+ "[data-stimeo--time-picker-target='segment']"
39
+ );
40
+ const kind = segment ? this.#kindOf(segment) : null;
41
+ if (!segment || !kind) return;
42
+ switch (event.key) {
43
+ case "ArrowUp":
44
+ event.preventDefault();
45
+ this.#step(kind, this.#delta(kind));
46
+ break;
47
+ case "ArrowDown":
48
+ event.preventDefault();
49
+ this.#step(kind, -this.#delta(kind));
50
+ break;
51
+ case "ArrowLeft":
52
+ event.preventDefault();
53
+ this.#focusSibling(segment, -1);
54
+ break;
55
+ case "ArrowRight":
56
+ event.preventDefault();
57
+ this.#focusSibling(segment, 1);
58
+ break;
59
+ case "Home":
60
+ event.preventDefault();
61
+ this.#set(kind, this.#bounds(kind).min);
62
+ break;
63
+ case "End":
64
+ event.preventDefault();
65
+ this.#set(kind, this.#bounds(kind).max);
66
+ break;
67
+ default:
68
+ if (/^[0-9]$/.test(event.key)) {
69
+ event.preventDefault();
70
+ this.#typeDigit(segment, kind, event.key);
71
+ }
72
+ return;
73
+ }
74
+ this.#typeBuffer = "";
75
+ this.#typeSegment = null;
76
+ }
77
+ /** The per-step delta: minutes step by `step`, others by 1, meridiem toggles. */
78
+ #delta(kind) {
79
+ return kind === "minute" ? this.stepValue : 1;
80
+ }
81
+ /** Steps a segment, wrapping at its bounds and carrying over when enabled. */
82
+ #step(kind, delta) {
83
+ if (kind === "meridiem") {
84
+ this.#set("meridiem", this.#state.meridiem === AM ? PM : AM);
85
+ return;
86
+ }
87
+ const { min, max } = this.#bounds(kind);
88
+ const span = max - min + 1;
89
+ const raw = this.#state[kind] + delta;
90
+ if (raw > max || raw < min) {
91
+ if (!this.wrapValue) {
92
+ this.#set(kind, Math.min(max, Math.max(min, raw)));
93
+ return;
94
+ }
95
+ const wrapped = ((raw - min) % span + span) % span + min;
96
+ const carry = Math.floor((raw - min) / span);
97
+ this.#set(kind, wrapped);
98
+ this.#carry(kind, carry);
99
+ return;
100
+ }
101
+ this.#set(kind, raw);
102
+ }
103
+ /** Propagates a wrap carry from `kind` into the next larger segment. */
104
+ #carry(kind, amount) {
105
+ if (amount === 0) return;
106
+ if (kind === "second") this.#step("minute", amount);
107
+ else if (kind === "minute") this.#step("hour", amount);
108
+ }
109
+ /**
110
+ * Sets a segment's value (clamped to its `[min, max]` bounds), re-renders it,
111
+ * and resyncs the composed field. Clamping here guards the direct-entry path:
112
+ * typing `0` into a 12-hour hour (min 1) must not commit an out-of-range
113
+ * `aria-valuenow="0"`. The stepping path already passes in-bounds values, so
114
+ * the clamp is a no-op there.
115
+ */
116
+ #set(kind, value) {
117
+ const { min, max } = this.#bounds(kind);
118
+ this.#state[kind] = Math.min(max, Math.max(min, value));
119
+ const segment = this.segmentTargets.find((s) => this.#kindOf(s) === kind);
120
+ if (segment) this.#renderSegment(segment);
121
+ this.#syncField(true);
122
+ }
123
+ /** Accumulates a typed digit, committing and advancing after two digits. */
124
+ #typeDigit(segment, kind, digit) {
125
+ if (kind === "meridiem") return;
126
+ if (this.#typeSegment !== kind) this.#typeBuffer = "";
127
+ this.#typeSegment = kind;
128
+ const { max } = this.#bounds(kind);
129
+ const candidate = Number(`${this.#typeBuffer}${digit}`);
130
+ if (candidate <= max) this.#typeBuffer = `${this.#typeBuffer}${digit}`;
131
+ else this.#typeBuffer = digit;
132
+ this.#set(kind, Number(this.#typeBuffer));
133
+ if (this.#typeBuffer.length >= 2 || Number(this.#typeBuffer) * 10 > max) {
134
+ this.#typeBuffer = "";
135
+ this.#typeSegment = null;
136
+ this.#focusSibling(segment, 1);
137
+ }
138
+ }
139
+ /** Moves focus to the previous/next segment, if one exists. */
140
+ #focusSibling(segment, direction) {
141
+ const index = this.segmentTargets.indexOf(segment);
142
+ const next = this.segmentTargets[index + direction];
143
+ next?.focus();
144
+ }
145
+ /** Reflects a segment's current value onto its ARIA/text representation. */
146
+ #renderSegment(segment) {
147
+ const kind = this.#kindOf(segment);
148
+ if (!kind) return;
149
+ const value = this.#state[kind];
150
+ if (kind === "meridiem") {
151
+ const text2 = value === PM ? "PM" : "AM";
152
+ segment.setAttribute("aria-valuenow", String(value));
153
+ segment.setAttribute("aria-valuetext", text2);
154
+ segment.setAttribute("aria-valuemin", String(AM));
155
+ segment.setAttribute("aria-valuemax", String(PM));
156
+ segment.textContent = text2;
157
+ return;
158
+ }
159
+ const { min, max } = this.#bounds(kind);
160
+ const text = String(value).padStart(2, "0");
161
+ segment.setAttribute("aria-valuenow", String(value));
162
+ segment.setAttribute("aria-valuetext", text);
163
+ segment.setAttribute("aria-valuemin", String(min));
164
+ segment.setAttribute("aria-valuemax", String(max));
165
+ segment.textContent = text;
166
+ }
167
+ /** Composes `HH:MM[:SS]` (24-hour) into the hidden field; dispatches `change`. */
168
+ #syncField(notify) {
169
+ const h24 = this.#hours24();
170
+ const parts = [pad(h24), pad(this.#state.minute)];
171
+ if (this.secondsValue) parts.push(pad(this.#state.second));
172
+ const value = parts.join(":");
173
+ if (this.hasFieldTarget && this.fieldTarget.value !== value) {
174
+ this.fieldTarget.value = value;
175
+ }
176
+ if (notify && value !== this.#lastValue) this.dispatch("change", { detail: { value } });
177
+ this.#lastValue = value;
178
+ }
179
+ /** Converts the displayed hour (+ meridiem in 12-hour mode) to 24-hour. */
180
+ #hours24() {
181
+ if (this.hourCycleValue !== 12) return this.#state.hour;
182
+ const base = this.#state.hour % 12;
183
+ return base + (this.#state.meridiem === PM ? 12 : 0);
184
+ }
185
+ /** The inclusive `[min, max]` bounds for a segment kind. */
186
+ #bounds(kind) {
187
+ switch (kind) {
188
+ case "hour":
189
+ return this.hourCycleValue === 12 ? { min: 1, max: 12 } : { min: 0, max: 23 };
190
+ case "minute":
191
+ case "second":
192
+ return { min: 0, max: 59 };
193
+ case "meridiem":
194
+ return { min: AM, max: PM };
195
+ }
196
+ }
197
+ /** Reads a segment's declared kind, or null when absent/invalid. */
198
+ #kindOf(segment) {
199
+ const kind = segment.getAttribute("data-segment");
200
+ if (kind === "hour" || kind === "minute" || kind === "second" || kind === "meridiem") {
201
+ return kind;
202
+ }
203
+ return null;
204
+ }
205
+ };
206
+ function pad(value) {
207
+ return String(value).padStart(2, "0");
208
+ }
209
+
210
+ export { TimePickerController };
211
+ //# sourceMappingURL=time_picker_controller.js.map
212
+ //# sourceMappingURL=time_picker_controller.js.map
@@ -55,7 +55,42 @@ var SafeTimeout = class extends TimerRegistry {
55
55
  }
56
56
  };
57
57
 
58
+ // src/utils/transition_completion.ts
59
+ function timeMs(value) {
60
+ const trimmed = value.trim();
61
+ const amount = Number.parseFloat(trimmed);
62
+ if (!Number.isFinite(amount)) return 0;
63
+ if (trimmed.endsWith("ms")) return amount;
64
+ if (trimmed.endsWith("s")) return amount * 1e3;
65
+ return 0;
66
+ }
67
+ function cssList(value) {
68
+ return value.split(",").map((item) => item.trim()).filter(Boolean);
69
+ }
70
+ function transitionTimings(style) {
71
+ const properties = cssList(style.transitionProperty);
72
+ const durations = cssList(style.transitionDuration).map(timeMs);
73
+ const delays = cssList(style.transitionDelay).map(timeMs);
74
+ const effectiveProperties = properties.length > 0 ? properties : Array.from({ length: Math.max(durations.length, delays.length, 1) }, () => "all");
75
+ const effectiveDurations = durations.length > 0 ? durations : [0];
76
+ const effectiveDelays = delays.length > 0 ? delays : [0];
77
+ return effectiveProperties.filter((property) => property !== "none").map((property, index) => ({
78
+ property,
79
+ totalMs: Math.max(
80
+ 0,
81
+ (effectiveDurations[index % effectiveDurations.length] ?? 0) + (effectiveDelays[index % effectiveDelays.length] ?? 0)
82
+ )
83
+ }));
84
+ }
85
+ function maxTotalMs(timings) {
86
+ return timings.reduce((max, { totalMs }) => Math.max(max, totalMs), 0);
87
+ }
88
+ function maxTransitionTotalMs(style) {
89
+ return maxTotalMs(transitionTimings(style));
90
+ }
91
+
58
92
  // src/controllers/toast_controller.ts
93
+ var DELEGATED_EVENTS = ["click", "focusin", "focusout", "keydown", "mouseover", "mouseout"];
59
94
  var ToastController = class extends Controller {
60
95
  static targets = ["list", "template", "item"];
61
96
  static values = {
@@ -76,34 +111,57 @@ var ToastController = class extends Controller {
76
111
  * Tracked so {@link disconnect} can cancel any that have not fired, preventing a
77
112
  * detached element from being mutated after it leaves the DOM (Turbo).
78
113
  */
79
- #rafHandles = /* @__PURE__ */ new Set();
114
+ #rafHandles = /* @__PURE__ */ new Map();
80
115
  /** Track active timeouts mapped by each toast element for safe cancellation. */
81
116
  #activeTimeouts = /* @__PURE__ */ new Map();
82
117
  /** Track active pause reasons (hover/focus) per toast for WCAG 2.2.1 pause/resume. */
83
118
  #pauseReasons = /* @__PURE__ */ new Map();
119
+ /** The stable list that owns delegated listeners for dynamically added items. */
120
+ #delegatedList = null;
84
121
  connect() {
122
+ this.#connectDelegatedEvents();
85
123
  this.enforceMaxLimit();
86
124
  for (const item of this.itemTargets) {
87
- if (!this.#activeTimeouts.has(item)) {
125
+ if (!this.#activeTimeouts.has(item) && item.dataset.state !== "leaving") {
88
126
  this.#startTimer(item);
89
127
  }
90
128
  }
91
129
  }
92
130
  disconnect() {
131
+ this.#disconnectDelegatedEvents();
93
132
  this.#timers.clearAll();
94
- for (const handle of this.#rafHandles) {
133
+ for (const handle of this.#rafHandles.values()) {
95
134
  window.cancelAnimationFrame(handle);
96
135
  }
97
136
  this.#rafHandles.clear();
98
137
  this.#activeTimeouts.clear();
99
138
  this.#pauseReasons.clear();
100
139
  }
140
+ /** Rebinds delegated interaction when Turbo replaces the list target in place. */
141
+ listTargetConnected(element) {
142
+ if (this.#delegatedList !== element) this.#connectDelegatedEvents(element);
143
+ }
144
+ /** Releases delegation only when the removed target is its current owner. */
145
+ listTargetDisconnected(element) {
146
+ if (this.#delegatedList === element) this.#disconnectDelegatedEvents();
147
+ }
101
148
  durationValueChanged() {
102
- if (this.durationValue > 0) {
103
- for (const item of this.itemTargets) {
104
- if (!this.#activeTimeouts.has(item)) {
105
- this.#startTimer(item);
106
- }
149
+ for (const item of this.itemTargets) {
150
+ if (item.dataset.state === "leaving") continue;
151
+ const pauseReasons = this.#pauseReasons.get(item);
152
+ this.#clearTimer(item);
153
+ if (this.durationValue <= 0) {
154
+ item.removeAttribute("data-paused");
155
+ } else if (pauseReasons && pauseReasons.size > 0) {
156
+ this.#pauseReasons.set(item, pauseReasons);
157
+ this.#activeTimeouts.set(item, {
158
+ id: 0,
159
+ startedAt: 0,
160
+ remaining: this.durationValue
161
+ });
162
+ item.setAttribute("data-paused", "true");
163
+ } else {
164
+ this.#startTimer(item);
107
165
  }
108
166
  }
109
167
  }
@@ -117,17 +175,21 @@ var ToastController = class extends Controller {
117
175
  */
118
176
  itemTargetConnected(element) {
119
177
  this.enforceMaxLimit();
178
+ if (element.dataset.state === "leaving" || element.parentNode !== this.listTarget) return;
120
179
  this.#startTimer(element);
121
180
  element.setAttribute("data-state", "entering");
181
+ this.#cancelAnimation(element);
122
182
  const handle = window.requestAnimationFrame(() => {
123
- this.#rafHandles.delete(handle);
183
+ this.#rafHandles.delete(element);
184
+ if (element.parentNode !== this.listTarget || element.dataset.state === "leaving") return;
124
185
  element.setAttribute("data-state", "visible");
125
186
  });
126
- this.#rafHandles.add(handle);
187
+ this.#rafHandles.set(element, handle);
127
188
  }
128
189
  /** Clears any active timer when a toast is removed from the DOM. */
129
190
  itemTargetDisconnected(element) {
130
191
  this.#clearTimer(element);
192
+ this.#cancelAnimation(element);
131
193
  }
132
194
  /**
133
195
  * Shows a new toast. Accepts its content from either a Stimulus action param
@@ -150,10 +212,9 @@ var ToastController = class extends Controller {
150
212
  const item = clone.querySelector("[data-stimeo--toast-target='item']");
151
213
  if (!item) return;
152
214
  const bodySlot = item.querySelector("[data-toast-slot='body']");
153
- if (bodySlot) {
154
- bodySlot.textContent = body;
155
- }
156
- item.setAttribute("role", this.#readField(event, "type") === "alert" ? "alert" : "status");
215
+ if (!bodySlot) return;
216
+ bodySlot.textContent = body;
217
+ bodySlot.setAttribute("role", this.#readField(event, "type") === "alert" ? "alert" : "status");
157
218
  this.listTarget.appendChild(item);
158
219
  this.dispatch("show", { detail: { item } });
159
220
  }
@@ -175,18 +236,15 @@ var ToastController = class extends Controller {
175
236
  }
176
237
  /** Dismisses the toast that contained the trigger. */
177
238
  dismiss(event) {
178
- const target = event.currentTarget || event.target;
179
- if (!target) return;
180
- const item = target.closest("[data-stimeo--toast-target='item']");
239
+ const item = this.#itemFromEvent(event);
181
240
  if (!item) return;
182
241
  this.#removeWithTransition(item, "user");
183
242
  }
184
243
  /** Dismisses the focused toast when Escape is pressed. */
185
244
  onKeydown(event) {
186
245
  if (event.key === "Escape") {
187
- const target = event.currentTarget || event.target;
188
- if (!target) return;
189
- const item = target.closest("[data-stimeo--toast-target='item']");
246
+ if (event.defaultPrevented || event.isComposing) return;
247
+ const item = this.#itemFromEvent(event);
190
248
  if (!item) return;
191
249
  event.preventDefault();
192
250
  this.#removeWithTransition(item, "user");
@@ -212,6 +270,10 @@ var ToastController = class extends Controller {
212
270
  this.#timers.clear(timeout.id);
213
271
  const elapsed = Date.now() - timeout.startedAt;
214
272
  const remaining = Math.max(0, timeout.remaining - elapsed);
273
+ if (remaining <= 0) {
274
+ this.#removeWithTransition(item, "timeout");
275
+ return;
276
+ }
215
277
  this.#activeTimeouts.set(item, { id: 0, startedAt: 0, remaining });
216
278
  item.setAttribute("data-paused", "true");
217
279
  }
@@ -223,14 +285,17 @@ var ToastController = class extends Controller {
223
285
  reasons.delete(this.#pauseReason(event));
224
286
  if (reasons.size > 0) return;
225
287
  const timeout = this.#activeTimeouts.get(item);
226
- if (!timeout || timeout.remaining <= 0) return;
288
+ if (!timeout) return;
289
+ if (timeout.id !== 0 || timeout.remaining <= 0) return;
227
290
  item.removeAttribute("data-paused");
228
291
  this.#startTimer(item, timeout.remaining);
229
292
  }
230
293
  /** Resolves the toast item element a pause/resume event targets. */
231
294
  #itemFromEvent(event) {
232
- const target = event.currentTarget || event.target;
233
- return target?.closest("[data-stimeo--toast-target='item']") ?? null;
295
+ const target = event.target instanceof Element ? event.target : event.currentTarget;
296
+ if (!(target instanceof Element) || !this.hasListTarget) return null;
297
+ const item = target.closest("[data-stimeo--toast-target='item']");
298
+ return item && this.listTarget.contains(item) ? item : null;
234
299
  }
235
300
  /** Classifies a pause/resume event as a hover or focus reason. */
236
301
  #pauseReason(event) {
@@ -246,7 +311,9 @@ var ToastController = class extends Controller {
246
311
  return reasons;
247
312
  }
248
313
  #startTimer(element, duration = this.durationValue) {
249
- if (duration <= 0) return;
314
+ if (duration <= 0 || element.dataset.state === "leaving" || element.parentNode !== this.listTarget) {
315
+ return;
316
+ }
250
317
  this.#clearTimer(element);
251
318
  const id = this.#timers.set(() => {
252
319
  this.#removeWithTransition(element, "timeout");
@@ -262,16 +329,16 @@ var ToastController = class extends Controller {
262
329
  this.#pauseReasons.delete(element);
263
330
  }
264
331
  #removeWithTransition(element, reason) {
332
+ if (element.dataset.state === "leaving" || element.parentNode !== this.listTarget) return;
265
333
  this.#clearTimer(element);
334
+ this.#cancelAnimation(element);
266
335
  element.setAttribute("data-state", "leaving");
267
336
  const finalize = () => {
268
- if (element.parentNode === this.listTarget) {
269
- this.listTarget.removeChild(element);
270
- }
337
+ if (element.parentNode !== this.listTarget) return;
338
+ this.listTarget.removeChild(element);
271
339
  this.dispatch("dismiss", { detail: { item: element, reason } });
272
340
  };
273
- const transitions = window.getComputedStyle(element).transitionDuration;
274
- const duration = cssTimeToMs(transitions);
341
+ const duration = maxTransitionTotalMs(window.getComputedStyle(element));
275
342
  if (duration > 0) {
276
343
  this.#timers.set(finalize, duration);
277
344
  } else {
@@ -289,22 +356,61 @@ var ToastController = class extends Controller {
289
356
  */
290
357
  enforceMaxLimit() {
291
358
  const currentItems = this.itemTargets;
292
- if (currentItems.length > this.maxValue) {
293
- const excessCount = currentItems.length - this.maxValue;
359
+ const max = Math.max(0, this.maxValue);
360
+ if (currentItems.length > max) {
361
+ const excessCount = currentItems.length - max;
294
362
  for (let i = 0; i < excessCount; i++) {
295
363
  const oldest = currentItems[i];
296
364
  if (oldest) this.#removeWithTransition(oldest, "timeout");
297
365
  }
298
366
  }
299
367
  }
368
+ /** Wires stable-container delegation so newly appended items work immediately. */
369
+ #connectDelegatedEvents(list = this.hasListTarget ? this.listTarget : null) {
370
+ this.#disconnectDelegatedEvents();
371
+ if (!list) return;
372
+ this.#delegatedList = list;
373
+ for (const type of DELEGATED_EVENTS) {
374
+ this.#delegatedList.addEventListener(type, this.#onListEvent);
375
+ }
376
+ }
377
+ /** Releases every delegated listener from the exact list that owns it. */
378
+ #disconnectDelegatedEvents() {
379
+ if (!this.#delegatedList) return;
380
+ for (const type of DELEGATED_EVENTS) {
381
+ this.#delegatedList.removeEventListener(type, this.#onListEvent);
382
+ }
383
+ this.#delegatedList = null;
384
+ }
385
+ /** Routes every delegated item interaction from the stable list. */
386
+ #onListEvent = (event) => {
387
+ if (event.type === "click") {
388
+ const target = event.target instanceof Element ? event.target : null;
389
+ const trigger = target?.closest("[data-toast-dismiss]");
390
+ if (trigger && this.#delegatedList?.contains(trigger)) this.dismiss(event);
391
+ } else if (event.type === "keydown") {
392
+ this.onKeydown(event);
393
+ } else if (this.#crossesItemBoundary(event)) {
394
+ if (event.type === "focusin" || event.type === "mouseover") this.pause(event);
395
+ else this.resume(event);
396
+ }
397
+ };
398
+ /** Whether a bubbling focus/pointer event enters or leaves a toast boundary. */
399
+ #crossesItemBoundary(event) {
400
+ const item = this.#itemFromEvent(event);
401
+ if (!item) return false;
402
+ const related = "relatedTarget" in event ? event.relatedTarget : null;
403
+ return !(related instanceof Node && item.contains(related));
404
+ }
405
+ /** Cancels the pending entering-to-visible frame owned by one item. */
406
+ #cancelAnimation(element) {
407
+ const handle = this.#rafHandles.get(element);
408
+ if (handle === void 0) return;
409
+ window.cancelAnimationFrame(handle);
410
+ this.#rafHandles.delete(element);
411
+ }
300
412
  };
301
- function cssTimeToMs(value) {
302
- const first = value.split(",")[0]?.trim() ?? "";
303
- const amount = Number.parseFloat(first);
304
- if (Number.isNaN(amount)) return 0;
305
- return first.endsWith("ms") ? amount : amount * 1e3;
306
- }
307
413
 
308
- export { ToastController, cssTimeToMs };
414
+ export { ToastController };
309
415
  //# sourceMappingURL=toast_controller.js.map
310
416
  //# sourceMappingURL=toast_controller.js.map