stimeo-ui 0.18.1 → 0.19.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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +54 -0
  3. data/dist/cable/index.js +6 -5
  4. data/dist/controllers/alert_dialog_controller.js +324 -76
  5. data/dist/controllers/announcer_controller.js +22 -9
  6. data/dist/controllers/auto_submit_controller.js +103 -16
  7. data/dist/controllers/avatar_controller.js +29 -9
  8. data/dist/controllers/breadcrumb_controller.js +205 -17
  9. data/dist/controllers/bulk_select_controller.js +31 -13
  10. data/dist/controllers/calendar_controller.js +242 -7
  11. data/dist/controllers/carousel_controller.js +70 -15
  12. data/dist/controllers/character_counter_controller.js +103 -16
  13. data/dist/controllers/clipboard_controller.js +6 -5
  14. data/dist/controllers/collapsible_controller.js +35 -8
  15. data/dist/controllers/combobox_controller.js +155 -26
  16. data/dist/controllers/command_palette_controller.js +445 -117
  17. data/dist/controllers/conditional_fields_controller.js +84 -44
  18. data/dist/controllers/confirm_controller.js +303 -68
  19. data/dist/controllers/context_menu_controller.js +59 -30
  20. data/dist/controllers/countdown_controller.js +6 -5
  21. data/dist/controllers/currency_input_controller.js +72 -7
  22. data/dist/controllers/data_grid_controller.js +273 -51
  23. data/dist/controllers/date_range_picker_controller.js +27 -5
  24. data/dist/controllers/dialog_controller.js +330 -79
  25. data/dist/controllers/direct_upload_controller.js +6 -5
  26. data/dist/controllers/dismissible_controller.js +68 -18
  27. data/dist/controllers/drawer_controller.js +362 -92
  28. data/dist/controllers/dropdown_controller.js +64 -52
  29. data/dist/controllers/editable_controller.js +140 -12
  30. data/dist/controllers/empty_state_controller.js +193 -9
  31. data/dist/controllers/file_dropzone_controller.js +313 -23
  32. data/dist/controllers/filter_controller.js +194 -5
  33. data/dist/controllers/flash_controller.js +205 -17
  34. data/dist/controllers/focus_controller.js +273 -57
  35. data/dist/controllers/form_field_controller.js +71 -14
  36. data/dist/controllers/form_validation_controller.js +11 -7
  37. data/dist/controllers/frame_loading_controller.js +75 -20
  38. data/dist/controllers/hover_card_controller.js +108 -39
  39. data/dist/controllers/input_mask_controller.js +95 -37
  40. data/dist/controllers/intersection_controller.js +61 -29
  41. data/dist/controllers/lazy_frame_controller.js +61 -29
  42. data/dist/controllers/listbox_controller.js +174 -83
  43. data/dist/controllers/local_time_controller.js +1 -7
  44. data/dist/controllers/menu_controller.js +45 -24
  45. data/dist/controllers/menubar_controller.js +232 -52
  46. data/dist/controllers/meter_controller.js +31 -9
  47. data/dist/controllers/multi_select_controller.js +195 -62
  48. data/dist/controllers/navigation_menu_controller.js +1 -1
  49. data/dist/controllers/nested_form_controller.js +275 -21
  50. data/dist/controllers/network_status_controller.js +31 -9
  51. data/dist/controllers/number_input_controller.js +180 -71
  52. data/dist/controllers/otp_controller.js +97 -11
  53. data/dist/controllers/overflow_menu_controller.js +190 -24
  54. data/dist/controllers/pagination_controller.js +186 -24
  55. data/dist/controllers/password_reveal_controller.js +25 -4
  56. data/dist/controllers/password_strength_controller.js +6 -5
  57. data/dist/controllers/popover_controller.js +466 -42
  58. data/dist/controllers/progress_controller.js +31 -9
  59. data/dist/controllers/radio_group_controller.js +279 -88
  60. data/dist/controllers/range_slider_controller.js +72 -54
  61. data/dist/controllers/rating_controller.js +58 -10
  62. data/dist/controllers/read_more_controller.js +191 -25
  63. data/dist/controllers/relative_time_controller.js +1 -7
  64. data/dist/controllers/roving_controller.js +204 -8
  65. data/dist/controllers/scroll_area_controller.js +61 -19
  66. data/dist/controllers/scroll_visibility_controller.js +25 -4
  67. data/dist/controllers/scrollspy_controller.js +240 -32
  68. data/dist/controllers/separator_controller.js +97 -58
  69. data/dist/controllers/sidebar_controller.js +368 -127
  70. data/dist/controllers/skeleton_controller.js +75 -20
  71. data/dist/controllers/slider_controller.js +72 -54
  72. data/dist/controllers/sortable_controller.js +6 -5
  73. data/dist/controllers/spinner_controller.js +75 -20
  74. data/dist/controllers/step_indicator_controller.js +181 -6
  75. data/dist/controllers/stepper_controller.js +188 -6
  76. data/dist/controllers/sticky_observer_controller.js +86 -33
  77. data/dist/controllers/submit_once_controller.js +31 -9
  78. data/dist/controllers/switch_controller.js +84 -44
  79. data/dist/controllers/tabs_controller.js +189 -3
  80. data/dist/controllers/tags_input_controller.js +293 -29
  81. data/dist/controllers/theme_controller.js +192 -5
  82. data/dist/controllers/time_picker_controller.js +77 -42
  83. data/dist/controllers/toast_controller.js +478 -16
  84. data/dist/controllers/toggle_group_controller.js +282 -79
  85. data/dist/controllers/toolbar_controller.js +276 -15
  86. data/dist/controllers/tooltip_controller.js +244 -46
  87. data/dist/controllers/tree_view_controller.js +287 -57
  88. data/dist/index.js +2258 -1016
  89. data/lib/stimeo/ui/version.rb +1 -1
  90. metadata +2 -2
@@ -41,6 +41,180 @@ function hasModifierChord(event) {
41
41
  return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
42
42
  }
43
43
 
44
+ function setAttributeIfChanged(element, name, value, beforeWrite) {
45
+ if (element.getAttribute(name) === value) return false;
46
+ beforeWrite?.();
47
+ if (value === null) element.removeAttribute(name);
48
+ else element.setAttribute(name, value);
49
+ return true;
50
+ }
51
+
52
+ function sharedRegistry(key, create) {
53
+ const symbol = Symbol.for(key);
54
+ const scope = globalThis;
55
+ const existing = scope[symbol];
56
+ if (existing !== void 0) return existing;
57
+ const registry2 = create();
58
+ Object.defineProperty(globalThis, symbol, { value: registry2 });
59
+ return registry2;
60
+ }
61
+
62
+ var registry = sharedRegistry(
63
+ "stimeo-ui.attribute-lease.registry.v1",
64
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
65
+ );
66
+ function isAttributeValue(value) {
67
+ return value === null || typeof value === "string";
68
+ }
69
+ function readLeaseRecord(element, record) {
70
+ try {
71
+ const parsed = JSON.parse(element.getAttribute(record) ?? "null");
72
+ if (!Array.isArray(parsed)) return void 0;
73
+ const [original, written, ...rest] = parsed;
74
+ const linked = rest[0] !== false;
75
+ const beneath = linked ? rest : rest.slice(1);
76
+ if (!beneath.every((under) => typeof under === "string")) return void 0;
77
+ return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
78
+ } catch {
79
+ return void 0;
80
+ }
81
+ }
82
+ function attributeStack(element, attribute) {
83
+ const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
84
+ registry.stacks.set(element, byAttribute);
85
+ const known = byAttribute.get(attribute);
86
+ if (known) return known;
87
+ const found = [];
88
+ for (const record of registry.names.get(attribute) ?? []) {
89
+ const read = readLeaseRecord(element, record);
90
+ if (read) found.push({ ...read, record });
91
+ }
92
+ const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
93
+ const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
94
+ lease: null,
95
+ record,
96
+ written,
97
+ original,
98
+ linked: linked && index > 0
99
+ }));
100
+ byAttribute.set(attribute, stack);
101
+ return stack;
102
+ }
103
+ function findHold(stack, lease, record) {
104
+ return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
105
+ }
106
+ var AttributeLease = class {
107
+ #attribute;
108
+ #record;
109
+ #base;
110
+ #preserveAuthor;
111
+ #held = /* @__PURE__ */ new Set();
112
+ constructor(attribute, owner, options = {}) {
113
+ this.#attribute = attribute;
114
+ this.#record = `data-${owner}-${attribute}-lease`;
115
+ this.#base = options.base === true;
116
+ this.#preserveAuthor = options.preserveAuthor === true;
117
+ const names = registry.names;
118
+ names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
119
+ }
120
+ write(element, value, beforeWrite) {
121
+ const stack = attributeStack(element, this.#attribute);
122
+ const hold = this.#take(stack) ?? this.#acquire(element, stack);
123
+ this.#held.add(element);
124
+ const shows = !this.#covered(element, stack, hold);
125
+ hold.written = value;
126
+ this.#mark(element, stack);
127
+ if (shows) this.#reflect(element, value, beforeWrite);
128
+ }
129
+ adopt(element, options = {}) {
130
+ const known = registry.stacks.get(element)?.has(this.#attribute);
131
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
132
+ const stack = attributeStack(element, this.#attribute);
133
+ const hold = this.#take(stack);
134
+ if (!hold) return false;
135
+ const current = element.getAttribute(this.#attribute);
136
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
137
+ return false;
138
+ }
139
+ this.#held.add(element);
140
+ hold.original = current;
141
+ hold.linked = false;
142
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
143
+ if (!above.linked) break;
144
+ above.original = current;
145
+ }
146
+ this.#mark(element, stack);
147
+ return true;
148
+ }
149
+ return(element) {
150
+ const held = this.#held.delete(element);
151
+ const known = registry.stacks.get(element)?.has(this.#attribute);
152
+ const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
153
+ const hold = this.#take(stack);
154
+ if (!hold) return false;
155
+ const carries = element.getAttribute(this.#attribute) === hold.written;
156
+ const owns = carries && !this.#covered(element, stack, hold);
157
+ const index = stack.indexOf(hold);
158
+ stack.splice(index, 1);
159
+ const above = stack[index];
160
+ if (above) above.linked &&= hold.linked;
161
+ this.#mark(element, stack);
162
+ if (!owns) return true;
163
+ const below = hold.linked ? stack[index - 1] : void 0;
164
+ this.#reflect(element, below ? below.written : hold.original);
165
+ return true;
166
+ }
167
+ returnAll() {
168
+ for (const element of Array.from(this.#held)) this.return(element);
169
+ }
170
+ #take(stack) {
171
+ const hold = findHold(stack, this, this.#record);
172
+ if (hold) hold.lease = this;
173
+ return hold;
174
+ }
175
+ #acquire(element, stack) {
176
+ const current = element.getAttribute(this.#attribute);
177
+ const top = stack.at(-1);
178
+ const bottom = stack[0];
179
+ const over = top?.written === current ? top : void 0;
180
+ const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
181
+ const hold = {
182
+ lease: this,
183
+ record: this.#record,
184
+ written: current,
185
+ original: from ? from.original : current,
186
+ linked: !this.#base && over !== void 0
187
+ };
188
+ if (this.#base && bottom) {
189
+ bottom.linked = true;
190
+ stack.unshift(hold);
191
+ } else stack.push(hold);
192
+ return hold;
193
+ }
194
+ #covered(element, stack, hold) {
195
+ const current = element.getAttribute(this.#attribute);
196
+ return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
197
+ }
198
+ #mark(element, stack) {
199
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
200
+ stack.forEach((hold, index) => {
201
+ const names = stack.slice(0, index).map((under) => under.record);
202
+ const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
203
+ const marker = hold.linked || beneath.length === 0 ? [] : [false];
204
+ records.set(
205
+ hold.record,
206
+ hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
207
+ );
208
+ });
209
+ for (const [name, recorded] of records) {
210
+ setAttributeIfChanged(element, name, recorded);
211
+ }
212
+ }
213
+ #reflect(element, value, beforeWrite) {
214
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
215
+ }
216
+ };
217
+
44
218
  var ClickVerdicts = class {
45
219
  #verdicts = /* @__PURE__ */ new WeakMap();
46
220
  record(event, entries, refused) {
@@ -53,16 +227,6 @@ var ClickVerdicts = class {
53
227
  }
54
228
  };
55
229
 
56
- function sharedRegistry(key, create) {
57
- const symbol = Symbol.for(key);
58
- const scope = globalThis;
59
- const existing = scope[symbol];
60
- if (existing !== void 0) return existing;
61
- const registry = create();
62
- Object.defineProperty(globalThis, symbol, { value: registry });
63
- return registry;
64
- }
65
-
66
230
  function claimsWhileFocusWithin(element) {
67
231
  return () => {
68
232
  const active = element.ownerDocument.activeElement;
@@ -76,26 +240,26 @@ var EscapeLayer = class _EscapeLayer {
76
240
  );
77
241
  #active = null;
78
242
  activate(ownerDocument = document, options) {
243
+ const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
79
244
  this.deactivate();
80
- let registry = _EscapeLayer.#registries.get(ownerDocument);
81
- if (!registry) {
82
- registry = _EscapeLayer.#createRegistry();
83
- _EscapeLayer.#registries.set(ownerDocument, registry);
84
- ownerDocument.addEventListener("keydown", registry.onKeydown);
245
+ let registry2 = _EscapeLayer.#registries.get(ownerDocument);
246
+ if (!registry2) {
247
+ registry2 = _EscapeLayer.#createRegistry();
248
+ _EscapeLayer.#registries.set(ownerDocument, registry2);
249
+ ownerDocument.addEventListener("keydown", registry2.onKeydown);
85
250
  }
86
- const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
87
- registry.stack.push(entry);
251
+ registry2.stack.push(entry);
88
252
  this.#active = { document: ownerDocument, entry };
89
253
  }
90
254
  deactivate() {
91
255
  const active = this.#active;
92
256
  if (!active) return;
93
- const registry = _EscapeLayer.#registries.get(active.document);
94
- if (registry) {
95
- const index = registry.stack.lastIndexOf(active.entry);
96
- if (index >= 0) registry.stack.splice(index, 1);
97
- if (registry.stack.length === 0) {
98
- active.document.removeEventListener("keydown", registry.onKeydown);
257
+ const registry2 = _EscapeLayer.#registries.get(active.document);
258
+ if (registry2) {
259
+ const index = registry2.stack.lastIndexOf(active.entry);
260
+ if (index >= 0) registry2.stack.splice(index, 1);
261
+ if (registry2.stack.length === 0) {
262
+ active.document.removeEventListener("keydown", registry2.onKeydown);
99
263
  _EscapeLayer.#registries.delete(active.document);
100
264
  }
101
265
  }
@@ -104,22 +268,22 @@ var EscapeLayer = class _EscapeLayer {
104
268
  get ownsEscape() {
105
269
  const active = this.#active;
106
270
  if (!active) return false;
107
- const registry = _EscapeLayer.#registries.get(active.document);
108
- if (!registry) return false;
109
- return _EscapeLayer.#resolveOwner(registry.stack) === active.entry;
271
+ const registry2 = _EscapeLayer.#registries.get(active.document);
272
+ if (!registry2) return false;
273
+ return _EscapeLayer.#resolveOwner(registry2.stack) === active.entry;
110
274
  }
111
275
  static #createRegistry() {
112
- const registry = {
276
+ const registry2 = {
113
277
  stack: [],
114
278
  onKeydown: (event) => {
115
279
  if (event.key !== "Escape" || event.defaultPrevented || event.isComposing) return;
116
- const owner = _EscapeLayer.#resolveOwner(registry.stack);
280
+ const owner = _EscapeLayer.#resolveOwner(registry2.stack);
117
281
  if (!owner) return;
118
282
  event.preventDefault();
119
283
  owner.onDismiss();
120
284
  }
121
285
  };
122
- return registry;
286
+ return registry2;
123
287
  }
124
288
  static #resolveOwner(stack) {
125
289
  for (let index = stack.length - 1; index >= 0; index--) {
@@ -216,8 +380,12 @@ var MorphRenderWatcher = class {
216
380
 
217
381
  var RovingTabindex = class {
218
382
  #getItems;
219
- constructor(getItems) {
383
+ #write;
384
+ constructor(getItems, write = (item, tabindex) => {
385
+ item.tabIndex = tabindex;
386
+ }) {
220
387
  this.#getItems = getItems;
388
+ this.#write = write;
221
389
  }
222
390
  get activeIndex() {
223
391
  return this.#getItems().findIndex((item) => item.tabIndex === 0);
@@ -226,7 +394,7 @@ var RovingTabindex = class {
226
394
  const { focus = false } = options;
227
395
  const items = options.items ?? this.#getItems();
228
396
  items.forEach((item, i) => {
229
- item.tabIndex = i === index ? 0 : -1;
397
+ this.#write(item, i === index ? 0 : -1);
230
398
  });
231
399
  if (focus) items[index]?.focus();
232
400
  }
@@ -275,7 +443,6 @@ var Typeahead = class {
275
443
  #timers = new SafeTimeout();
276
444
  #resetMs;
277
445
  #query = "";
278
- #timerId = 0;
279
446
  constructor({ resetMs = TYPEAHEAD_RESET_MS } = {}) {
280
447
  this.#resetMs = resetMs;
281
448
  }
@@ -286,14 +453,13 @@ var Typeahead = class {
286
453
  const char = key.toLowerCase();
287
454
  const repeated = this.#query.length > 0 && [...this.#query].every((c) => c === char);
288
455
  this.#query = repeated ? char : this.#query + char;
289
- this.#timers.clear(this.#timerId);
290
- this.#timerId = this.#timers.set(() => this.reset(), this.#resetMs);
456
+ this.#timers.clearAll();
457
+ this.#timers.set(() => this.reset(), this.#resetMs);
291
458
  return this.#query;
292
459
  }
293
460
  reset() {
294
461
  this.#query = "";
295
- this.#timers.clear(this.#timerId);
296
- this.#timerId = 0;
462
+ this.#timers.clearAll();
297
463
  }
298
464
  };
299
465
  function isTypeaheadKey(event) {
@@ -321,7 +487,14 @@ var MenubarController = class extends Controller {
321
487
  static targets = ["top", "menu", "item"];
322
488
  static actions = ["activate", "onItemKeydown", "onTopKeydown", "toggle"];
323
489
  static events = ["close", "open"];
324
- #roving = new RovingTabindex(() => this.topTargets);
490
+ #tabindex = new AttributeLease("tabindex", this.identifier);
491
+ #expanded = new AttributeLease("aria-expanded", this.identifier);
492
+ #menuHidden = new AttributeLease("hidden", this.identifier);
493
+ #managedTops = /* @__PURE__ */ new WeakSet();
494
+ #roving = new RovingTabindex(
495
+ () => this.topTargets,
496
+ (top, value) => this.#writeTabindex(top, value)
497
+ );
325
498
  #typeahead = new Typeahead();
326
499
  #timers = new SafeTimeout();
327
500
  #escapeLayer = new EscapeLayer();
@@ -374,24 +547,31 @@ var MenubarController = class extends Controller {
374
547
  this.#timers.clearAll();
375
548
  }
376
549
  topTargetConnected(top) {
377
- if (!this.#connected) return;
378
- top.tabIndex = -1;
550
+ if (!this.#connected || this.#managedTops.has(top)) return;
551
+ this.#writeTabindex(top, -1);
379
552
  this.#reconcile();
380
553
  }
381
554
  topTargetDisconnected(top) {
382
- if (!this.#connected) return;
383
- top.tabIndex = -1;
384
- if (this.#isExpanded(top)) top.setAttribute("aria-expanded", "false");
385
- this.#reconcile();
555
+ if (!this.scope.containsElement(top) || !this.topTargets.includes(top)) {
556
+ this.#managedTops.delete(top);
557
+ this.#tabindex.return(top);
558
+ this.#expanded.return(top);
559
+ }
560
+ if (this.#connected) this.#reconcile();
561
+ }
562
+ #writeTabindex(top, value) {
563
+ this.#managedTops.add(top);
564
+ this.#tabindex.write(top, String(value));
386
565
  }
387
566
  menuTargetConnected() {
388
567
  if (!this.#connected) return;
389
568
  this.#reconcile();
390
569
  }
391
570
  menuTargetDisconnected(menu) {
392
- if (!this.#connected) return;
393
- if (!menu.hidden) menu.hidden = true;
394
- this.#reconcile();
571
+ if (!this.scope.containsElement(menu) || !this.menuTargets.includes(menu)) {
572
+ this.#menuHidden.return(menu);
573
+ }
574
+ if (this.#connected) this.#reconcile();
395
575
  }
396
576
  toggle(source) {
397
577
  const { event, host, origin, reason } = actionSource(source);
@@ -533,8 +713,8 @@ var MenubarController = class extends Controller {
533
713
  this.#timers.clearAll();
534
714
  const was = this.#isExpanded(opener);
535
715
  this.#closeAllMenus(reason, opener);
536
- menu.hidden = false;
537
- opener.setAttribute("aria-expanded", "true");
716
+ this.#menuHidden.write(menu, null);
717
+ this.#expanded.write(opener, "true");
538
718
  if (!was) this.#report("open", opener, menu, reason);
539
719
  if (!this.#isExpanded(opener)) return;
540
720
  this.#escapeLayer.activate(document, {
@@ -553,8 +733,8 @@ var MenubarController = class extends Controller {
553
733
  const menu = this.#menuFor(top);
554
734
  if (!menu) return;
555
735
  const was = this.#isExpanded(top);
556
- menu.hidden = true;
557
- top.setAttribute("aria-expanded", "false");
736
+ this.#menuHidden.write(menu, "");
737
+ this.#expanded.write(top, "false");
558
738
  if (was && !silent) this.#report("close", top, menu, reason);
559
739
  this.#syncEscapeLayer();
560
740
  }
@@ -612,13 +792,13 @@ var MenubarController = class extends Controller {
612
792
  for (const top of this.topTargets) {
613
793
  const own = this.#menuFor(top);
614
794
  if (this.#isExpanded(top) && (!own || own.hidden || !this.#isNavigable(top))) {
615
- top.setAttribute("aria-expanded", "false");
795
+ this.#expanded.write(top, "false");
616
796
  }
617
797
  }
618
798
  for (const menu of this.menuTargets) {
619
799
  if (menu.hidden) continue;
620
800
  const owner = this.#topFor(menu);
621
- if (!owner || !this.#isExpanded(owner)) menu.hidden = true;
801
+ if (!owner || !this.#isExpanded(owner)) this.#menuHidden.write(menu, "");
622
802
  }
623
803
  this.#ensureTabStop();
624
804
  this.#rescueFocus();
@@ -7,14 +7,15 @@ function fillTemplate(template, values) {
7
7
  });
8
8
  }
9
9
 
10
+ var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
10
11
  function announce(message, options = {}) {
11
12
  const text = message.trim();
12
13
  if (text.length === 0) return;
13
- window.dispatchEvent(
14
- new CustomEvent("stimeo--announcer:announce", {
15
- detail: { message: text, assertive: options.assertive === true }
16
- })
17
- );
14
+ const event = new CustomEvent("stimeo--announcer:announce", {
15
+ detail: { message: text, assertive: options.assertive === true }
16
+ });
17
+ if (options.afterFocus) event[afterFocus] = true;
18
+ window.dispatchEvent(event);
18
19
  }
19
20
 
20
21
  var NUMBER_BOUNDS = {
@@ -160,6 +161,7 @@ function clampRange(value, min, max) {
160
161
 
161
162
  function setAttributeIfChanged(element, name, value, beforeWrite) {
162
163
  if (element.getAttribute(name) === value) return false;
164
+ beforeWrite?.();
163
165
  if (value === null) element.removeAttribute(name);
164
166
  else element.setAttribute(name, value);
165
167
  return true;
@@ -245,14 +247,34 @@ var AttributeLease = class {
245
247
  const names = registry.names;
246
248
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
247
249
  }
248
- write(element, value) {
250
+ write(element, value, beforeWrite) {
249
251
  const stack = attributeStack(element, this.#attribute);
250
252
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
251
253
  this.#held.add(element);
252
254
  const shows = !this.#covered(element, stack, hold);
253
255
  hold.written = value;
254
256
  this.#mark(element, stack);
255
- if (shows) this.#reflect(element, value);
257
+ if (shows) this.#reflect(element, value, beforeWrite);
258
+ }
259
+ adopt(element, options = {}) {
260
+ const known = registry.stacks.get(element)?.has(this.#attribute);
261
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
262
+ const stack = attributeStack(element, this.#attribute);
263
+ const hold = this.#take(stack);
264
+ if (!hold) return false;
265
+ const current = element.getAttribute(this.#attribute);
266
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
267
+ return false;
268
+ }
269
+ this.#held.add(element);
270
+ hold.original = current;
271
+ hold.linked = false;
272
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
273
+ if (!above.linked) break;
274
+ above.original = current;
275
+ }
276
+ this.#mark(element, stack);
277
+ return true;
256
278
  }
257
279
  return(element) {
258
280
  const held = this.#held.delete(element);
@@ -318,8 +340,8 @@ var AttributeLease = class {
318
340
  setAttributeIfChanged(element, name, recorded);
319
341
  }
320
342
  }
321
- #reflect(element, value) {
322
- setAttributeIfChanged(element, this.#attribute, value);
343
+ #reflect(element, value, beforeWrite) {
344
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
323
345
  }
324
346
  };
325
347