stimeo-ui 0.18.2 → 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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/dist/controllers/alert_dialog_controller.js +246 -42
  4. data/dist/controllers/auto_submit_controller.js +26 -5
  5. data/dist/controllers/avatar_controller.js +29 -9
  6. data/dist/controllers/breadcrumb_controller.js +205 -17
  7. data/dist/controllers/bulk_select_controller.js +25 -4
  8. data/dist/controllers/calendar_controller.js +242 -7
  9. data/dist/controllers/carousel_controller.js +70 -15
  10. data/dist/controllers/character_counter_controller.js +26 -5
  11. data/dist/controllers/collapsible_controller.js +35 -8
  12. data/dist/controllers/combobox_controller.js +84 -20
  13. data/dist/controllers/command_palette_controller.js +296 -77
  14. data/dist/controllers/confirm_controller.js +225 -34
  15. data/dist/controllers/context_menu_controller.js +58 -29
  16. data/dist/controllers/currency_input_controller.js +1 -1
  17. data/dist/controllers/data_grid_controller.js +196 -9
  18. data/dist/controllers/date_range_picker_controller.js +25 -4
  19. data/dist/controllers/dialog_controller.js +252 -45
  20. data/dist/controllers/dismissible_controller.js +57 -11
  21. data/dist/controllers/drawer_controller.js +284 -58
  22. data/dist/controllers/dropdown_controller.js +63 -51
  23. data/dist/controllers/editable_controller.js +69 -6
  24. data/dist/controllers/empty_state_controller.js +187 -4
  25. data/dist/controllers/file_dropzone_controller.js +300 -12
  26. data/dist/controllers/filter_controller.js +194 -5
  27. data/dist/controllers/flash_controller.js +199 -12
  28. data/dist/controllers/focus_controller.js +195 -23
  29. data/dist/controllers/form_field_controller.js +65 -9
  30. data/dist/controllers/frame_loading_controller.js +25 -4
  31. data/dist/controllers/hover_card_controller.js +107 -38
  32. data/dist/controllers/input_mask_controller.js +1 -1
  33. data/dist/controllers/listbox_controller.js +94 -36
  34. data/dist/controllers/menu_controller.js +44 -23
  35. data/dist/controllers/menubar_controller.js +228 -46
  36. data/dist/controllers/meter_controller.js +25 -4
  37. data/dist/controllers/multi_select_controller.js +110 -42
  38. data/dist/controllers/nested_form_controller.js +258 -9
  39. data/dist/controllers/network_status_controller.js +25 -4
  40. data/dist/controllers/number_input_controller.js +26 -5
  41. data/dist/controllers/otp_controller.js +26 -5
  42. data/dist/controllers/overflow_menu_controller.js +183 -22
  43. data/dist/controllers/pagination_controller.js +179 -22
  44. data/dist/controllers/password_reveal_controller.js +25 -4
  45. data/dist/controllers/popover_controller.js +454 -34
  46. data/dist/controllers/progress_controller.js +25 -4
  47. data/dist/controllers/radio_group_controller.js +195 -40
  48. data/dist/controllers/rating_controller.js +58 -10
  49. data/dist/controllers/read_more_controller.js +191 -25
  50. data/dist/controllers/roving_controller.js +197 -6
  51. data/dist/controllers/scroll_area_controller.js +50 -12
  52. data/dist/controllers/scroll_visibility_controller.js +25 -4
  53. data/dist/controllers/scrollspy_controller.js +179 -3
  54. data/dist/controllers/separator_controller.js +25 -4
  55. data/dist/controllers/sidebar_controller.js +290 -93
  56. data/dist/controllers/skeleton_controller.js +25 -4
  57. data/dist/controllers/spinner_controller.js +25 -4
  58. data/dist/controllers/step_indicator_controller.js +181 -6
  59. data/dist/controllers/stepper_controller.js +188 -6
  60. data/dist/controllers/sticky_observer_controller.js +25 -4
  61. data/dist/controllers/submit_once_controller.js +25 -4
  62. data/dist/controllers/tabs_controller.js +189 -3
  63. data/dist/controllers/tags_input_controller.js +210 -9
  64. data/dist/controllers/theme_controller.js +192 -5
  65. data/dist/controllers/toast_controller.js +478 -16
  66. data/dist/controllers/toggle_group_controller.js +198 -35
  67. data/dist/controllers/toolbar_controller.js +198 -7
  68. data/dist/controllers/tooltip_controller.js +243 -45
  69. data/dist/controllers/tree_view_controller.js +200 -8
  70. data/dist/index.js +1764 -739
  71. data/lib/stimeo/ui/version.rb +1 -1
  72. metadata +2 -2
@@ -20,6 +20,7 @@ function announce(message, options = {}) {
20
20
 
21
21
  function setAttributeIfChanged(element, name, value, beforeWrite) {
22
22
  if (element.getAttribute(name) === value) return false;
23
+ beforeWrite?.();
23
24
  if (value === null) element.removeAttribute(name);
24
25
  else element.setAttribute(name, value);
25
26
  return true;
@@ -93,14 +94,34 @@ var AttributeLease = class {
93
94
  const names = registry.names;
94
95
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
95
96
  }
96
- write(element, value) {
97
+ write(element, value, beforeWrite) {
97
98
  const stack = attributeStack(element, this.#attribute);
98
99
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
99
100
  this.#held.add(element);
100
101
  const shows = !this.#covered(element, stack, hold);
101
102
  hold.written = value;
102
103
  this.#mark(element, stack);
103
- if (shows) this.#reflect(element, value);
104
+ if (shows) this.#reflect(element, value, beforeWrite);
105
+ }
106
+ adopt(element, options = {}) {
107
+ const known = registry.stacks.get(element)?.has(this.#attribute);
108
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
109
+ const stack = attributeStack(element, this.#attribute);
110
+ const hold = this.#take(stack);
111
+ if (!hold) return false;
112
+ const current = element.getAttribute(this.#attribute);
113
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
114
+ return false;
115
+ }
116
+ this.#held.add(element);
117
+ hold.original = current;
118
+ hold.linked = false;
119
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
120
+ if (!above.linked) break;
121
+ above.original = current;
122
+ }
123
+ this.#mark(element, stack);
124
+ return true;
104
125
  }
105
126
  return(element) {
106
127
  const held = this.#held.delete(element);
@@ -166,8 +187,8 @@ var AttributeLease = class {
166
187
  setAttributeIfChanged(element, name, recorded);
167
188
  }
168
189
  }
169
- #reflect(element, value) {
170
- setAttributeIfChanged(element, this.#attribute, value);
190
+ #reflect(element, value, beforeWrite) {
191
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
171
192
  }
172
193
  };
173
194
 
@@ -194,6 +215,12 @@ function flatTreeParent(element) {
194
215
  if (parent instanceof ShadowRoot) return parent.host;
195
216
  return parent instanceof Element ? parent : null;
196
217
  }
218
+ function flatTreeContains(ancestor, element) {
219
+ for (let node = element; node; node = flatTreeParent(node)) {
220
+ if (node === ancestor) return true;
221
+ }
222
+ return false;
223
+ }
197
224
  function canTakeFocus(element) {
198
225
  for (let node = element; node; node = flatTreeParent(node)) {
199
226
  if (unslotted(node) || node.matches("[hidden], [inert]")) return false;
@@ -253,12 +280,234 @@ function isTabStop(element) {
253
280
  if (tabindex !== null) return tabindex >= 0;
254
281
  return hasNativeTabStop(element) || hasEditableTabStop(element);
255
282
  }
256
- function firstTabStop(root) {
257
- for (const candidate of root.querySelectorAll(TAB_STOP_CANDIDATE_SELECTOR)) {
258
- if (isTabStop(candidate)) return candidate;
283
+ function isRadio(element) {
284
+ return element instanceof HTMLInputElement && element.type === "radio";
285
+ }
286
+ function sameRadioGroup(a, b) {
287
+ return a.name !== "" && a.name === b.name && a.form === b.form && a.getRootNode() === b.getRootNode();
288
+ }
289
+ function isInEditableContent(element) {
290
+ for (let node = element.parentElement; node; node = node.parentElement) {
291
+ if (node.getAttribute("contenteditable")?.toLowerCase() === "false") return false;
292
+ if (hasEditableTabStop(node)) return true;
293
+ }
294
+ return false;
295
+ }
296
+ var XLINK_NAMESPACE = "http://www.w3.org/1999/xlink";
297
+ function isSvgLink(element) {
298
+ return element instanceof SVGElement && element.localName === "a" && (element.hasAttribute("href") || element.hasAttributeNS(XLINK_NAMESPACE, "href"));
299
+ }
300
+ function hasRenderedImage(area) {
301
+ const map = area.closest("map");
302
+ const key = map?.name || map?.id;
303
+ if (!map || !key) return false;
304
+ const root = map.getRootNode();
305
+ return Array.from(root.querySelectorAll("img[usemap]")).some(
306
+ (image) => image.getAttribute("usemap") === `#${key}` && isRenderedForFocus(image)
307
+ );
308
+ }
309
+ function isFocusableInOrder(element) {
310
+ const tabindex = authoredTabindex(element);
311
+ return (tabindex === null || tabindex >= 0) && canTakeFocus(element);
312
+ }
313
+ function extraStop(element) {
314
+ if (element instanceof HTMLAreaElement) {
315
+ const focusable = element.hasAttribute("href") || authoredTabindex(element) !== null;
316
+ return focusable && isFocusableInOrder(element) && hasRenderedImage(element);
317
+ }
318
+ if (element instanceof HTMLObjectElement) {
319
+ return isFocusableInOrder(element) && isRenderedForFocus(element) && element.contentWindow !== null;
320
+ }
321
+ if (isSvgLink(element))
322
+ return isFocusableInOrder(element) && isRenderedForFocus(element);
323
+ return null;
324
+ }
325
+ function isSequentialStop(element) {
326
+ const stop = extraStop(element) ?? (element.matches(TAB_STOP_CANDIDATE_SELECTOR) && isTabStop(element));
327
+ if (!stop) return false;
328
+ const link = element instanceof HTMLAnchorElement || element instanceof HTMLAreaElement || isSvgLink(element);
329
+ return !(link && authoredTabindex(element) === null && isInEditableContent(element));
330
+ }
331
+ function ownedScope(element) {
332
+ if (element.shadowRoot) return Array.from(element.shadowRoot.children);
333
+ if (element instanceof HTMLSlotElement) {
334
+ return element.assignedNodes().length > 0 ? element.assignedElements() : Array.from(element.children);
259
335
  }
260
336
  return null;
261
337
  }
338
+ function orderScope(elements, walk) {
339
+ const entries = [];
340
+ const visit = (element) => {
341
+ const isFrom = element === walk.from;
342
+ if (isFrom && walk.side !== "after") walk.fromAt = walk.tree.length;
343
+ const tabindex = authoredTabindex(element) ?? 0;
344
+ let stop = null;
345
+ if ((element instanceof HTMLElement || element instanceof SVGElement) && isSequentialStop(element)) {
346
+ stop = element;
347
+ walk.tree.push(element);
348
+ }
349
+ const owned = ownedScope(element);
350
+ if (owned) {
351
+ if (tabindex >= 0) {
352
+ entries.push({ tabindex, stops: [...stop ? [stop] : [], ...orderScope(owned, walk)] });
353
+ } else if (walk.from && flatTreeContains(element, walk.from) && (!isFrom || walk.side === "on")) {
354
+ walk.fromAt = walk.tree.length;
355
+ walk.excludedScope = element;
356
+ orderScope(owned, {
357
+ from: walk.from,
358
+ side: walk.side,
359
+ tree: walk.tree,
360
+ fromAt: -1,
361
+ excludedScope: null
362
+ });
363
+ }
364
+ if (isFrom && walk.side === "after") walk.fromAt = walk.tree.length;
365
+ return;
366
+ }
367
+ if (stop) entries.push({ tabindex, stops: [stop] });
368
+ for (const child of Array.from(element.children)) visit(child);
369
+ if (isFrom && walk.side === "after") walk.fromAt = walk.tree.length;
370
+ };
371
+ for (const element of elements) visit(element);
372
+ const positive = entries.filter((entry) => entry.tabindex > 0);
373
+ positive.sort((a, b) => a.tabindex - b.tabindex);
374
+ const rest = entries.filter((entry) => entry.tabindex === 0);
375
+ return [...positive, ...rest].flatMap((entry) => entry.stops);
376
+ }
377
+ function passesRadioRule(element, tree, focusedRadio, backward) {
378
+ if (!isRadio(element) || element.checked) return true;
379
+ const group = tree.filter(
380
+ (stop) => stop === element || isRadio(stop) && sameRadioGroup(stop, element)
381
+ );
382
+ if (group.some((radio) => radio.checked)) return false;
383
+ if (group[backward ? group.length - 1 : 0] !== element) return false;
384
+ return focusedRadio === null || !sameRadioGroup(focusedRadio, element);
385
+ }
386
+ function startIndex(order, walk, backward, isStop) {
387
+ if (walk.fromAt < 0) return backward ? order.length - 1 : 0;
388
+ const at = walk.side === "on" ? order.indexOf(walk.from) : -1;
389
+ if (at >= 0) return backward ? at - 1 : at + 1;
390
+ const neighbour = backward ? walk.tree.slice(0, walk.fromAt).reverse().find(isStop) : walk.tree.slice(walk.fromAt).find(isStop);
391
+ if (neighbour) return order.indexOf(neighbour);
392
+ return backward ? -1 : order.length;
393
+ }
394
+ function movesWithin(root, from, backward, wrap, radioContext, side = "on", position = { holder: null }) {
395
+ const walk = {
396
+ from,
397
+ side,
398
+ tree: [],
399
+ fromAt: from === root ? 0 : -1,
400
+ excludedScope: null
401
+ };
402
+ const order = orderScope(ownedScope(root) ?? Array.from(root.children), walk);
403
+ const radios = radioContext ?? {
404
+ tree: walk.tree,
405
+ focusedRadio: side === "on" && walk.fromAt >= 0 && isRadio(from) ? from : null
406
+ };
407
+ const isStop = (element) => passesRadioRule(element, radios.tree, radios.focusedRadio, backward);
408
+ const holds = (element) => position.holder !== null && flatTreeContains(element, position.holder);
409
+ const start = startIndex(
410
+ order,
411
+ walk,
412
+ backward,
413
+ (element) => order.includes(element) && isStop(element) && !holds(element)
414
+ );
415
+ const remaining = backward ? order.slice(0, start + 1).reverse() : order.slice(start);
416
+ const wrapped = wrap ? backward ? order.slice(start + 1).reverse() : order.slice(0, start) : [];
417
+ const excluded = walk.excludedScope;
418
+ const prefix = excluded && !(backward && from === excluded) ? movesWithin(
419
+ excluded,
420
+ from === excluded ? null : from,
421
+ backward,
422
+ false,
423
+ radios,
424
+ side,
425
+ position
426
+ ) : [];
427
+ return [
428
+ ...prefix,
429
+ ...[...remaining, ...wrapped].filter(
430
+ (element) => (side !== "on" || element !== from) && isStop(element)
431
+ )
432
+ ];
433
+ }
434
+ function flatParentNode(node) {
435
+ const parent = node.parentNode;
436
+ if (parent instanceof Element && parent.shadowRoot) {
437
+ for (const slot of parent.shadowRoot.querySelectorAll("slot")) {
438
+ if (slot.assignedNodes().includes(node)) return slot;
439
+ }
440
+ }
441
+ return parent instanceof ShadowRoot ? parent.host : parent;
442
+ }
443
+ function flatChildNodes(node) {
444
+ if (node instanceof Element && node.shadowRoot) return Array.from(node.shadowRoot.childNodes);
445
+ if (node instanceof HTMLSlotElement) {
446
+ const assigned = node.assignedNodes();
447
+ return assigned.length > 0 ? assigned : Array.from(node.childNodes);
448
+ }
449
+ return Array.from(node.childNodes);
450
+ }
451
+ function flatNodeAfter(node, root) {
452
+ for (let current = node; current && current !== root; ) {
453
+ const parent = flatParentNode(current);
454
+ if (!parent) return null;
455
+ const siblings = flatChildNodes(parent);
456
+ const index = siblings.indexOf(current);
457
+ const next = index >= 0 ? siblings[index + 1] : void 0;
458
+ if (next) return next;
459
+ current = parent;
460
+ }
461
+ return null;
462
+ }
463
+ function flatElementBefore(node, root) {
464
+ for (let current = node; current && current !== root; ) {
465
+ const parent = flatParentNode(current);
466
+ if (!parent) return null;
467
+ const siblings = flatChildNodes(parent);
468
+ for (let index = siblings.indexOf(current) - 1; index >= 0; index--) {
469
+ const sibling = siblings[index];
470
+ if (sibling instanceof Element) return sibling;
471
+ }
472
+ current = parent;
473
+ }
474
+ return null;
475
+ }
476
+ function elementAfterPosition(container, offset, root) {
477
+ const owner = container instanceof ShadowRoot ? container.host : container;
478
+ const child = container.childNodes[offset];
479
+ const previous = container.childNodes[offset - 1];
480
+ let node = child ?? (previous ? flatNodeAfter(previous, root) : flatChildNodes(owner)[0] ?? flatNodeAfter(owner, root));
481
+ while (node && !(node instanceof Element)) {
482
+ node = flatChildNodes(node)[0] ?? flatNodeAfter(node, root);
483
+ }
484
+ return node;
485
+ }
486
+ function elementBeforePosition(container, offset, root) {
487
+ const child = container.childNodes[offset];
488
+ if (child) return flatElementBefore(child, root);
489
+ const previous = container.childNodes[offset - 1];
490
+ if (previous) return previous instanceof Element ? previous : flatElementBefore(previous, root);
491
+ return flatElementBefore(container instanceof ShadowRoot ? container.host : container, root);
492
+ }
493
+ function elementHoldingPosition(container, offset) {
494
+ if (container instanceof Element && container.shadowRoot) {
495
+ const near = container.childNodes[offset] ?? container.childNodes[offset - 1];
496
+ return near ? flatParentNode(near) : container;
497
+ }
498
+ if (container instanceof Element) return container;
499
+ if (container instanceof ShadowRoot) return container.host;
500
+ return flatParentNode(container);
501
+ }
502
+ function sequentialTabStops(root, from = null, backward = false) {
503
+ if (!(from instanceof Range)) return movesWithin(root, from, backward, true);
504
+ const container = backward ? from.startContainer : from.endContainer;
505
+ const offset = backward ? from.startOffset : from.endOffset;
506
+ const anchor = backward ? elementBeforePosition(container, offset, root) : elementAfterPosition(container, offset, root);
507
+ return movesWithin(root, anchor, backward, true, void 0, backward ? "after" : "before", {
508
+ holder: elementHoldingPosition(container, offset)
509
+ });
510
+ }
262
511
  function deepActiveElement(ownerDocument) {
263
512
  let active = ownerDocument.activeElement;
264
513
  while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;
@@ -624,7 +873,7 @@ var NestedFormController = class _NestedFormController extends Controller {
624
873
  if (node !== row) node.remove();
625
874
  }
626
875
  this.#refresh();
627
- firstTabStop(row)?.focus();
876
+ sequentialTabStops(row)[0]?.focus();
628
877
  this.dispatch("add", { detail: { index, element: row } });
629
878
  this.#announce();
630
879
  }
@@ -659,7 +908,7 @@ var NestedFormController = class _NestedFormController extends Controller {
659
908
  const rows = this.#effectiveRows;
660
909
  const ordered = [...rows.slice(position), ...rows.slice(0, position).reverse()];
661
910
  for (const row of ordered) {
662
- const stop = firstTabStop(row);
911
+ const [stop] = sequentialTabStops(row);
663
912
  if (stop) {
664
913
  stop.focus();
665
914
  return;
@@ -20,6 +20,7 @@ function announce(message, options = {}) {
20
20
 
21
21
  function setAttributeIfChanged(element, name, value, beforeWrite) {
22
22
  if (element.getAttribute(name) === value) return false;
23
+ beforeWrite?.();
23
24
  if (value === null) element.removeAttribute(name);
24
25
  else element.setAttribute(name, value);
25
26
  return true;
@@ -93,14 +94,34 @@ var AttributeLease = class {
93
94
  const names = registry.names;
94
95
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
95
96
  }
96
- write(element, value) {
97
+ write(element, value, beforeWrite) {
97
98
  const stack = attributeStack(element, this.#attribute);
98
99
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
99
100
  this.#held.add(element);
100
101
  const shows = !this.#covered(element, stack, hold);
101
102
  hold.written = value;
102
103
  this.#mark(element, stack);
103
- if (shows) this.#reflect(element, value);
104
+ if (shows) this.#reflect(element, value, beforeWrite);
105
+ }
106
+ adopt(element, options = {}) {
107
+ const known = registry.stacks.get(element)?.has(this.#attribute);
108
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
109
+ const stack = attributeStack(element, this.#attribute);
110
+ const hold = this.#take(stack);
111
+ if (!hold) return false;
112
+ const current = element.getAttribute(this.#attribute);
113
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
114
+ return false;
115
+ }
116
+ this.#held.add(element);
117
+ hold.original = current;
118
+ hold.linked = false;
119
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
120
+ if (!above.linked) break;
121
+ above.original = current;
122
+ }
123
+ this.#mark(element, stack);
124
+ return true;
104
125
  }
105
126
  return(element) {
106
127
  const held = this.#held.delete(element);
@@ -166,8 +187,8 @@ var AttributeLease = class {
166
187
  setAttributeIfChanged(element, name, recorded);
167
188
  }
168
189
  }
169
- #reflect(element, value) {
170
- setAttributeIfChanged(element, this.#attribute, value);
190
+ #reflect(element, value, beforeWrite) {
191
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
171
192
  }
172
193
  };
173
194
 
@@ -10,6 +10,7 @@ function hasModifierChord(event) {
10
10
 
11
11
  function setAttributeIfChanged(element, name, value, beforeWrite) {
12
12
  if (element.getAttribute(name) === value) return false;
13
+ beforeWrite?.();
13
14
  if (value === null) element.removeAttribute(name);
14
15
  else element.setAttribute(name, value);
15
16
  return true;
@@ -83,14 +84,34 @@ var AttributeLease = class {
83
84
  const names = registry.names;
84
85
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
85
86
  }
86
- write(element, value) {
87
+ write(element, value, beforeWrite) {
87
88
  const stack = attributeStack(element, this.#attribute);
88
89
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
89
90
  this.#held.add(element);
90
91
  const shows = !this.#covered(element, stack, hold);
91
92
  hold.written = value;
92
93
  this.#mark(element, stack);
93
- if (shows) this.#reflect(element, value);
94
+ if (shows) this.#reflect(element, value, beforeWrite);
95
+ }
96
+ adopt(element, options = {}) {
97
+ const known = registry.stacks.get(element)?.has(this.#attribute);
98
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
99
+ const stack = attributeStack(element, this.#attribute);
100
+ const hold = this.#take(stack);
101
+ if (!hold) return false;
102
+ const current = element.getAttribute(this.#attribute);
103
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
104
+ return false;
105
+ }
106
+ this.#held.add(element);
107
+ hold.original = current;
108
+ hold.linked = false;
109
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
110
+ if (!above.linked) break;
111
+ above.original = current;
112
+ }
113
+ this.#mark(element, stack);
114
+ return true;
94
115
  }
95
116
  return(element) {
96
117
  const held = this.#held.delete(element);
@@ -156,8 +177,8 @@ var AttributeLease = class {
156
177
  setAttributeIfChanged(element, name, recorded);
157
178
  }
158
179
  }
159
- #reflect(element, value) {
160
- setAttributeIfChanged(element, this.#attribute, value);
180
+ #reflect(element, value, beforeWrite) {
181
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
161
182
  }
162
183
  };
163
184
 
@@ -318,7 +339,7 @@ var CompositionTracker = class {
318
339
  this.#confirmedTarget = null;
319
340
  if (confirmed === null || confirmed !== event.target) return false;
320
341
  const inputType = event.inputType;
321
- return !inputType || isCompositionInputType(inputType);
342
+ return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
322
343
  }
323
344
  #release(target) {
324
345
  target.removeEventListener("compositionstart", this.#handleStart);
@@ -45,6 +45,7 @@ function hasModifierChord(event) {
45
45
 
46
46
  function setAttributeIfChanged(element, name, value, beforeWrite) {
47
47
  if (element.getAttribute(name) === value) return false;
48
+ beforeWrite?.();
48
49
  if (value === null) element.removeAttribute(name);
49
50
  else element.setAttribute(name, value);
50
51
  return true;
@@ -108,14 +109,34 @@ var AttributeLease = class {
108
109
  const names = registry.names;
109
110
  names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
110
111
  }
111
- write(element, value) {
112
+ write(element, value, beforeWrite) {
112
113
  const stack = attributeStack(element, this.#attribute);
113
114
  const hold = this.#take(stack) ?? this.#acquire(element, stack);
114
115
  this.#held.add(element);
115
116
  const shows = !this.#covered(element, stack, hold);
116
117
  hold.written = value;
117
118
  this.#mark(element, stack);
118
- if (shows) this.#reflect(element, value);
119
+ if (shows) this.#reflect(element, value, beforeWrite);
120
+ }
121
+ adopt(element, options = {}) {
122
+ const known = registry.stacks.get(element)?.has(this.#attribute);
123
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
124
+ const stack = attributeStack(element, this.#attribute);
125
+ const hold = this.#take(stack);
126
+ if (!hold) return false;
127
+ const current = element.getAttribute(this.#attribute);
128
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
129
+ return false;
130
+ }
131
+ this.#held.add(element);
132
+ hold.original = current;
133
+ hold.linked = false;
134
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
135
+ if (!above.linked) break;
136
+ above.original = current;
137
+ }
138
+ this.#mark(element, stack);
139
+ return true;
119
140
  }
120
141
  return(element) {
121
142
  const held = this.#held.delete(element);
@@ -181,8 +202,8 @@ var AttributeLease = class {
181
202
  setAttributeIfChanged(element, name, recorded);
182
203
  }
183
204
  }
184
- #reflect(element, value) {
185
- setAttributeIfChanged(element, this.#attribute, value);
205
+ #reflect(element, value, beforeWrite) {
206
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
186
207
  }
187
208
  };
188
209
 
@@ -300,7 +321,7 @@ var CompositionTracker = class {
300
321
  this.#confirmedTarget = null;
301
322
  if (confirmed === null || confirmed !== event.target) return false;
302
323
  const inputType = event.inputType;
303
- return !inputType || isCompositionInputType(inputType);
324
+ return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
304
325
  }
305
326
  #release(target) {
306
327
  target.removeEventListener("compositionstart", this.#handleStart);