stimeo-ui 0.18.1 → 0.18.2

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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/dist/cable/index.js +6 -5
  4. data/dist/controllers/alert_dialog_controller.js +89 -45
  5. data/dist/controllers/announcer_controller.js +22 -9
  6. data/dist/controllers/auto_submit_controller.js +77 -11
  7. data/dist/controllers/bulk_select_controller.js +6 -9
  8. data/dist/controllers/character_counter_controller.js +77 -11
  9. data/dist/controllers/clipboard_controller.js +6 -5
  10. data/dist/controllers/combobox_controller.js +71 -6
  11. data/dist/controllers/command_palette_controller.js +160 -51
  12. data/dist/controllers/conditional_fields_controller.js +84 -44
  13. data/dist/controllers/confirm_controller.js +89 -45
  14. data/dist/controllers/context_menu_controller.js +1 -1
  15. data/dist/controllers/countdown_controller.js +6 -5
  16. data/dist/controllers/currency_input_controller.js +71 -6
  17. data/dist/controllers/data_grid_controller.js +77 -42
  18. data/dist/controllers/date_range_picker_controller.js +2 -1
  19. data/dist/controllers/dialog_controller.js +89 -45
  20. data/dist/controllers/direct_upload_controller.js +6 -5
  21. data/dist/controllers/dismissible_controller.js +11 -7
  22. data/dist/controllers/drawer_controller.js +89 -45
  23. data/dist/controllers/dropdown_controller.js +1 -1
  24. data/dist/controllers/editable_controller.js +71 -6
  25. data/dist/controllers/empty_state_controller.js +6 -5
  26. data/dist/controllers/file_dropzone_controller.js +13 -11
  27. data/dist/controllers/flash_controller.js +6 -5
  28. data/dist/controllers/focus_controller.js +89 -45
  29. data/dist/controllers/form_field_controller.js +6 -5
  30. data/dist/controllers/form_validation_controller.js +11 -7
  31. data/dist/controllers/frame_loading_controller.js +50 -16
  32. data/dist/controllers/hover_card_controller.js +1 -1
  33. data/dist/controllers/input_mask_controller.js +94 -36
  34. data/dist/controllers/intersection_controller.js +61 -29
  35. data/dist/controllers/lazy_frame_controller.js +61 -29
  36. data/dist/controllers/listbox_controller.js +80 -47
  37. data/dist/controllers/local_time_controller.js +1 -7
  38. data/dist/controllers/menu_controller.js +1 -1
  39. data/dist/controllers/menubar_controller.js +4 -6
  40. data/dist/controllers/meter_controller.js +6 -5
  41. data/dist/controllers/multi_select_controller.js +86 -21
  42. data/dist/controllers/navigation_menu_controller.js +1 -1
  43. data/dist/controllers/nested_form_controller.js +17 -12
  44. data/dist/controllers/network_status_controller.js +6 -5
  45. data/dist/controllers/number_input_controller.js +154 -66
  46. data/dist/controllers/otp_controller.js +71 -6
  47. data/dist/controllers/overflow_menu_controller.js +7 -2
  48. data/dist/controllers/pagination_controller.js +7 -2
  49. data/dist/controllers/password_strength_controller.js +6 -5
  50. data/dist/controllers/popover_controller.js +12 -8
  51. data/dist/controllers/progress_controller.js +6 -5
  52. data/dist/controllers/radio_group_controller.js +85 -49
  53. data/dist/controllers/range_slider_controller.js +72 -54
  54. data/dist/controllers/relative_time_controller.js +1 -7
  55. data/dist/controllers/roving_controller.js +7 -2
  56. data/dist/controllers/scroll_area_controller.js +11 -7
  57. data/dist/controllers/scrollspy_controller.js +61 -29
  58. data/dist/controllers/separator_controller.js +72 -54
  59. data/dist/controllers/sidebar_controller.js +89 -45
  60. data/dist/controllers/skeleton_controller.js +50 -16
  61. data/dist/controllers/slider_controller.js +72 -54
  62. data/dist/controllers/sortable_controller.js +6 -5
  63. data/dist/controllers/spinner_controller.js +50 -16
  64. data/dist/controllers/sticky_observer_controller.js +61 -29
  65. data/dist/controllers/submit_once_controller.js +6 -5
  66. data/dist/controllers/switch_controller.js +84 -44
  67. data/dist/controllers/tags_input_controller.js +83 -20
  68. data/dist/controllers/time_picker_controller.js +77 -42
  69. data/dist/controllers/toggle_group_controller.js +84 -44
  70. data/dist/controllers/toolbar_controller.js +78 -8
  71. data/dist/controllers/tooltip_controller.js +1 -1
  72. data/dist/controllers/tree_view_controller.js +87 -49
  73. data/dist/index.js +503 -286
  74. data/lib/stimeo/ui/version.rb +1 -1
  75. metadata +2 -2
@@ -10,43 +10,66 @@ function setAttributeIfChanged(element, name, value, beforeWrite) {
10
10
 
11
11
  var AuthoredMutationWatcher = class {
12
12
  #onAuthored;
13
- #claims = null;
14
- #observer = null;
13
+ #lifetime = null;
15
14
  constructor(onAuthored) {
16
15
  this.#onAuthored = onAuthored;
17
16
  }
18
17
  observe(root, options) {
19
- this.disconnect();
20
- const observer = new MutationObserver((records) => {
21
- if (this.#observer !== observer) return;
22
- const authored = this.#filter(records);
23
- if (authored.length > 0) this.#onAuthored(authored);
24
- });
25
- this.#observer = observer;
26
- this.#claims = { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() };
27
- observer.observe(root, {
28
- attributes: true,
29
- attributeFilter: [...options.attributes],
30
- subtree: options.subtree ?? false,
31
- childList: options.childList ?? false
32
- });
33
- if (options.ancestorAttributes) {
34
- let ancestor = root.parentElement;
35
- while (ancestor) {
36
- observer.observe(ancestor, {
37
- attributes: true,
38
- attributeFilter: [...options.ancestorAttributes]
39
- });
40
- ancestor = ancestor.parentElement;
18
+ const previous = this.#lifetime;
19
+ const lifetime = {
20
+ observer: null,
21
+ active: false,
22
+ claims: { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() }
23
+ };
24
+ this.#lifetime = lifetime;
25
+ let observer = null;
26
+ try {
27
+ if (previous) this.#release(previous);
28
+ if (this.#lifetime !== lifetime) return;
29
+ const attributes = [...options.attributes];
30
+ const subtree = options.subtree ?? false;
31
+ const childList = options.childList ?? false;
32
+ const inherited = options.ancestorAttributes;
33
+ const ancestorAttributes = inherited ? [...inherited] : null;
34
+ if (this.#lifetime !== lifetime) return;
35
+ observer = new MutationObserver((records) => {
36
+ const authored = this.#filter(records, lifetime.claims);
37
+ if (this.#lifetime === lifetime && lifetime.active && authored.length > 0) {
38
+ this.#onAuthored(authored);
39
+ }
40
+ });
41
+ if (this.#lifetime !== lifetime) return;
42
+ lifetime.observer = observer;
43
+ observer.observe(root, { attributes: true, attributeFilter: attributes, subtree, childList });
44
+ if (this.#lifetime !== lifetime) {
45
+ this.#release(lifetime, observer);
46
+ return;
41
47
  }
48
+ if (ancestorAttributes) {
49
+ let ancestor = root.parentElement;
50
+ while (ancestor) {
51
+ observer.observe(ancestor, { attributes: true, attributeFilter: ancestorAttributes });
52
+ if (this.#lifetime !== lifetime) {
53
+ this.#release(lifetime, observer);
54
+ return;
55
+ }
56
+ ancestor = ancestor.parentElement;
57
+ }
58
+ }
59
+ lifetime.active = true;
60
+ } catch (error) {
61
+ this.#release(lifetime, observer);
62
+ throw error;
42
63
  }
43
64
  }
44
65
  claim(target, name, value) {
45
- const claims = this.#claims?.attributes;
46
- let attributes = claims?.get(target);
66
+ const lifetime = this.#lifetime;
67
+ if (!lifetime?.active) return;
68
+ const claims = lifetime.claims.attributes;
69
+ let attributes = claims.get(target);
47
70
  if (!attributes) {
48
71
  attributes = /* @__PURE__ */ new Map();
49
- claims?.set(target, attributes);
72
+ claims.set(target, attributes);
50
73
  }
51
74
  const pending = attributes.get(name);
52
75
  attributes.set(name, { value, count: (pending?.count ?? 0) + 1 });
@@ -55,37 +78,49 @@ var AuthoredMutationWatcher = class {
55
78
  this.claim(target, name, target.getAttribute(name));
56
79
  }
57
80
  claimChildList(target, added, removed) {
58
- const claims = this.#claims?.children;
59
- const pending = claims?.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
81
+ const lifetime = this.#lifetime;
82
+ if (!lifetime?.active) return;
83
+ const claims = lifetime.claims.children;
84
+ const pending = claims.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
60
85
  for (const node of added) pending.added.set(node, (pending.added.get(node) ?? 0) + 1);
61
86
  for (const node of removed) pending.removed.set(node, (pending.removed.get(node) ?? 0) + 1);
62
- claims?.set(target, pending);
87
+ claims.set(target, pending);
63
88
  }
64
89
  take() {
65
- return this.#filter(this.#observer?.takeRecords() ?? []);
90
+ const lifetime = this.#lifetime;
91
+ const observer = lifetime?.observer;
92
+ if (!lifetime?.active || !observer) return [];
93
+ const records = observer.takeRecords();
94
+ const authored = this.#filter(records, lifetime.claims);
95
+ return this.#lifetime === lifetime && lifetime.active ? authored : [];
66
96
  }
67
97
  disconnect() {
68
- this.#observer?.disconnect();
69
- this.#observer = null;
70
- this.#claims = null;
71
- }
72
- #filter(records) {
73
- const authored = records.filter((record) => !this.#consume(record));
74
- this.#claims?.attributes.clear();
75
- this.#claims?.children.clear();
98
+ const lifetime = this.#lifetime;
99
+ if (lifetime) this.#release(lifetime);
100
+ }
101
+ #release(lifetime, observer = lifetime.observer) {
102
+ if (this.#lifetime === lifetime) this.#lifetime = null;
103
+ lifetime.claims.attributes.clear();
104
+ lifetime.claims.children.clear();
105
+ observer?.disconnect();
106
+ }
107
+ #filter(records, claims) {
108
+ const authored = records.filter((record) => !this.#consume(record, claims));
109
+ claims.attributes.clear();
110
+ claims.children.clear();
76
111
  return authored;
77
112
  }
78
- #consume(record) {
113
+ #consume(record, claims) {
79
114
  if (record.type === "attributes") {
80
115
  const target = record.target;
81
- const pending2 = this.#claims?.attributes.get(target)?.get(record.attributeName);
116
+ const pending2 = claims.attributes.get(target)?.get(record.attributeName);
82
117
  if (!pending2 || pending2.count === 0 || target.getAttribute(record.attributeName) !== pending2.value) {
83
118
  return false;
84
119
  }
85
120
  pending2.count -= 1;
86
121
  return true;
87
122
  }
88
- const pending = this.#claims?.children.get(record.target);
123
+ const pending = claims.children.get(record.target);
89
124
  if (!pending) return false;
90
125
  const added = [...record.addedNodes];
91
126
  const removed = [...record.removedNodes];
@@ -113,11 +148,16 @@ function commitField(target) {
113
148
  target.dispatchEvent(new Event("change", { bubbles: true }));
114
149
  }
115
150
 
151
+ var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
116
152
  function inheritsFieldsetDisabled(control) {
117
153
  let fieldset = control.closest("fieldset[disabled]");
118
154
  while (fieldset) {
119
- const legend = Array.from(fieldset.children).find((child) => child.tagName === "LEGEND");
120
- if (!legend?.contains(control)) return true;
155
+ if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
156
+ const legend = Array.from(fieldset.children).find(
157
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
158
+ );
159
+ if (!legend?.contains(control)) return true;
160
+ }
121
161
  fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
122
162
  }
123
163
  return false;
@@ -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
  function isRtl(element) {
@@ -35,10 +36,6 @@ function matchingPart(root, selector) {
35
36
  return root.matches(selector) ? root : root.querySelector(selector);
36
37
  }
37
38
  function writeLabel(slot, text) {
38
- if (slot.childElementCount === 0) {
39
- slot.textContent = text;
40
- return;
41
- }
42
39
  let first = null;
43
40
  for (const node of Array.from(slot.childNodes)) {
44
41
  if (node.nodeType !== Node.TEXT_NODE) continue;
@@ -191,7 +188,50 @@ function isCompositionInputType(inputType) {
191
188
  return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
192
189
  }
193
190
  var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
194
- var textOf = (element) => element.value;
191
+ var textOf = (element) => {
192
+ if ("value" in element) return element.value;
193
+ return element instanceof Element ? element.textContent : void 0;
194
+ };
195
+ var nodesOf = (element) => {
196
+ const nodes = [];
197
+ if ("value" in element || !(element instanceof Element)) return nodes;
198
+ const walker = element.ownerDocument.createTreeWalker(element);
199
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
200
+ return nodes;
201
+ };
202
+ var folded = (text) => text.replaceAll("\xA0", " ");
203
+ var startOf = (node, data, replaced, caret) => {
204
+ const text = folded(node.data);
205
+ const composed = folded(data);
206
+ if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
207
+ return replaced.startOffset;
208
+ }
209
+ const start = text.lastIndexOf(composed, caret);
210
+ return start !== -1 && start + composed.length >= caret ? start : -1;
211
+ };
212
+ var spotOf = (element, replaced, data) => {
213
+ if ("value" in element || !(element instanceof Element)) return null;
214
+ const selection = element.ownerDocument.getSelection();
215
+ const node = selection?.focusNode;
216
+ if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
217
+ const range = element.ownerDocument.createRange();
218
+ const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
219
+ if (start === -1) {
220
+ range.selectNodeContents(node);
221
+ } else {
222
+ range.setStart(node, start);
223
+ range.setEnd(node, start + data.length);
224
+ }
225
+ return range;
226
+ };
227
+ var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
228
+ var rewritten = ({ element, text, nodes, spot }) => {
229
+ if (spot !== null) {
230
+ return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
231
+ }
232
+ const current = nodesOf(element);
233
+ return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
234
+ };
195
235
  var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
196
236
  var CompositionTracker = class {
197
237
  #observedTargets = /* @__PURE__ */ new Set();
@@ -282,11 +322,11 @@ var CompositionTracker = class {
282
322
  }
283
323
  #settle() {
284
324
  const composition = this.#composition;
285
- if (composition === null) return;
286
- const { target, element, text } = composition;
325
+ if (composition === null || !this.#observedTargets.has(composition.target)) return;
326
+ const { target, element } = composition;
287
327
  if (target instanceof Node && element instanceof Node && !target.contains(element)) {
288
328
  this.#composition = null;
289
- } else if (textOf(element) !== text) {
329
+ } else if (rewritten(composition)) {
290
330
  this.#abandon(false);
291
331
  }
292
332
  }
@@ -311,7 +351,14 @@ var CompositionTracker = class {
311
351
  this.#owe(true);
312
352
  const target = event.currentTarget;
313
353
  const element = event.target;
314
- this.#composition = { target, element, text: textOf(element) };
354
+ this.#composition = {
355
+ target,
356
+ element,
357
+ text: textOf(element),
358
+ nodes: nodesOf(element),
359
+ spot: spotOf(element, null, void 0),
360
+ replaced: null
361
+ };
315
362
  this.#runAbandon();
316
363
  this.#onStart?.(event);
317
364
  };
@@ -335,6 +382,10 @@ var CompositionTracker = class {
335
382
  if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
336
383
  this.#abandon(true);
337
384
  }
385
+ const composition = this.#composition;
386
+ if (composition !== null && event.target === composition.element) {
387
+ composition.replaced = replacedBy(event);
388
+ }
338
389
  this.#runAbandon();
339
390
  };
340
391
  #handleInput = (event) => {
@@ -342,6 +393,15 @@ var CompositionTracker = class {
342
393
  const { isTrusted, isComposing, inputType } = event;
343
394
  if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
344
395
  composition.text = textOf(composition.element);
396
+ composition.nodes = nodesOf(composition.element);
397
+ if (isCompositionInputType(inputType)) {
398
+ composition.spot = spotOf(
399
+ composition.element,
400
+ composition.replaced,
401
+ event.data
402
+ );
403
+ }
404
+ composition.replaced = null;
345
405
  } else {
346
406
  this.#settle();
347
407
  }
@@ -362,7 +422,9 @@ var CompositionTracker = class {
362
422
  const composition = this.#composition;
363
423
  if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
364
424
  const detail = event.detail;
365
- if (detail?.attributeName === "value") event.preventDefault();
425
+ if (detail?.attributeName === "value" && "value" in composition.element) {
426
+ event.preventDefault();
427
+ }
366
428
  };
367
429
  };
368
430
 
@@ -726,7 +788,8 @@ var TagsInputController = class _TagsInputController extends Controller {
726
788
  const value = tag.dataset.value ?? "";
727
789
  tag.remove();
728
790
  const tags = this.#values;
729
- if (!this.#publishTags(tags, false, value)) return;
791
+ const afterFocus2 = focus === "neighbor" && tags.length === 0 && this.hasInputTarget;
792
+ if (!this.#publishTags(tags, false, value, afterFocus2)) return;
730
793
  if (focus === "input") {
731
794
  this.#focusInput();
732
795
  return;
@@ -750,7 +813,7 @@ var TagsInputController = class _TagsInputController extends Controller {
750
813
  this.#chipRow.ensureTabStop();
751
814
  return fieldChanged;
752
815
  }
753
- #publishTags(tags, added, value) {
816
+ #publishTags(tags, added, value, afterFocus2 = false) {
754
817
  const changed = !this.#sameTags(this.#tagValues, tags);
755
818
  const fieldChanged = this.#syncState(tags);
756
819
  this.#tagValues = tags;
@@ -758,7 +821,7 @@ var TagsInputController = class _TagsInputController extends Controller {
758
821
  const token = this.#moves.record();
759
822
  if (fieldChanged) commitField(this.fieldsTarget);
760
823
  if (!this.#moves.isLatest(token)) return false;
761
- this.#announceTransition(added, value, tags.length);
824
+ this.#announceTransition(added, value, tags.length, afterFocus2);
762
825
  if (!this.#moves.isLatest(token)) return false;
763
826
  this.dispatch("change", { detail: { tags } });
764
827
  return this.#moves.isLatest(token);
@@ -773,9 +836,9 @@ var TagsInputController = class _TagsInputController extends Controller {
773
836
  this.dispatch("reconcile", { detail: { tags } });
774
837
  }
775
838
  }
776
- #announceTransition(added, value, count) {
839
+ #announceTransition(added, value, count, afterFocus2) {
777
840
  const template = added ? this.announceTextValue : this.announceRemovedTextValue;
778
- announce(fillTemplate(template, { label: value, value, count }));
841
+ announce(fillTemplate(template, { label: value, value, count }), { afterFocus: afterFocus2 });
779
842
  }
780
843
  #reject(value, reason) {
781
844
  this.dispatch("reject", { detail: { value, reason } });
@@ -27,43 +27,66 @@ function setAttributeIfChanged(element, name, value, beforeWrite) {
27
27
 
28
28
  var AuthoredMutationWatcher = class {
29
29
  #onAuthored;
30
- #claims = null;
31
- #observer = null;
30
+ #lifetime = null;
32
31
  constructor(onAuthored) {
33
32
  this.#onAuthored = onAuthored;
34
33
  }
35
34
  observe(root, options) {
36
- this.disconnect();
37
- const observer = new MutationObserver((records) => {
38
- if (this.#observer !== observer) return;
39
- const authored = this.#filter(records);
40
- if (authored.length > 0) this.#onAuthored(authored);
41
- });
42
- this.#observer = observer;
43
- this.#claims = { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() };
44
- observer.observe(root, {
45
- attributes: true,
46
- attributeFilter: [...options.attributes],
47
- subtree: options.subtree ?? false,
48
- childList: options.childList ?? false
49
- });
50
- if (options.ancestorAttributes) {
51
- let ancestor = root.parentElement;
52
- while (ancestor) {
53
- observer.observe(ancestor, {
54
- attributes: true,
55
- attributeFilter: [...options.ancestorAttributes]
56
- });
57
- ancestor = ancestor.parentElement;
35
+ const previous = this.#lifetime;
36
+ const lifetime = {
37
+ observer: null,
38
+ active: false,
39
+ claims: { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() }
40
+ };
41
+ this.#lifetime = lifetime;
42
+ let observer = null;
43
+ try {
44
+ if (previous) this.#release(previous);
45
+ if (this.#lifetime !== lifetime) return;
46
+ const attributes = [...options.attributes];
47
+ const subtree = options.subtree ?? false;
48
+ const childList = options.childList ?? false;
49
+ const inherited = options.ancestorAttributes;
50
+ const ancestorAttributes = inherited ? [...inherited] : null;
51
+ if (this.#lifetime !== lifetime) return;
52
+ observer = new MutationObserver((records) => {
53
+ const authored = this.#filter(records, lifetime.claims);
54
+ if (this.#lifetime === lifetime && lifetime.active && authored.length > 0) {
55
+ this.#onAuthored(authored);
56
+ }
57
+ });
58
+ if (this.#lifetime !== lifetime) return;
59
+ lifetime.observer = observer;
60
+ observer.observe(root, { attributes: true, attributeFilter: attributes, subtree, childList });
61
+ if (this.#lifetime !== lifetime) {
62
+ this.#release(lifetime, observer);
63
+ return;
64
+ }
65
+ if (ancestorAttributes) {
66
+ let ancestor = root.parentElement;
67
+ while (ancestor) {
68
+ observer.observe(ancestor, { attributes: true, attributeFilter: ancestorAttributes });
69
+ if (this.#lifetime !== lifetime) {
70
+ this.#release(lifetime, observer);
71
+ return;
72
+ }
73
+ ancestor = ancestor.parentElement;
74
+ }
58
75
  }
76
+ lifetime.active = true;
77
+ } catch (error) {
78
+ this.#release(lifetime, observer);
79
+ throw error;
59
80
  }
60
81
  }
61
82
  claim(target, name, value) {
62
- const claims = this.#claims?.attributes;
63
- let attributes = claims?.get(target);
83
+ const lifetime = this.#lifetime;
84
+ if (!lifetime?.active) return;
85
+ const claims = lifetime.claims.attributes;
86
+ let attributes = claims.get(target);
64
87
  if (!attributes) {
65
88
  attributes = /* @__PURE__ */ new Map();
66
- claims?.set(target, attributes);
89
+ claims.set(target, attributes);
67
90
  }
68
91
  const pending = attributes.get(name);
69
92
  attributes.set(name, { value, count: (pending?.count ?? 0) + 1 });
@@ -72,37 +95,49 @@ var AuthoredMutationWatcher = class {
72
95
  this.claim(target, name, target.getAttribute(name));
73
96
  }
74
97
  claimChildList(target, added, removed) {
75
- const claims = this.#claims?.children;
76
- const pending = claims?.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
98
+ const lifetime = this.#lifetime;
99
+ if (!lifetime?.active) return;
100
+ const claims = lifetime.claims.children;
101
+ const pending = claims.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
77
102
  for (const node of added) pending.added.set(node, (pending.added.get(node) ?? 0) + 1);
78
103
  for (const node of removed) pending.removed.set(node, (pending.removed.get(node) ?? 0) + 1);
79
- claims?.set(target, pending);
104
+ claims.set(target, pending);
80
105
  }
81
106
  take() {
82
- return this.#filter(this.#observer?.takeRecords() ?? []);
107
+ const lifetime = this.#lifetime;
108
+ const observer = lifetime?.observer;
109
+ if (!lifetime?.active || !observer) return [];
110
+ const records = observer.takeRecords();
111
+ const authored = this.#filter(records, lifetime.claims);
112
+ return this.#lifetime === lifetime && lifetime.active ? authored : [];
83
113
  }
84
114
  disconnect() {
85
- this.#observer?.disconnect();
86
- this.#observer = null;
87
- this.#claims = null;
88
- }
89
- #filter(records) {
90
- const authored = records.filter((record) => !this.#consume(record));
91
- this.#claims?.attributes.clear();
92
- this.#claims?.children.clear();
115
+ const lifetime = this.#lifetime;
116
+ if (lifetime) this.#release(lifetime);
117
+ }
118
+ #release(lifetime, observer = lifetime.observer) {
119
+ if (this.#lifetime === lifetime) this.#lifetime = null;
120
+ lifetime.claims.attributes.clear();
121
+ lifetime.claims.children.clear();
122
+ observer?.disconnect();
123
+ }
124
+ #filter(records, claims) {
125
+ const authored = records.filter((record) => !this.#consume(record, claims));
126
+ claims.attributes.clear();
127
+ claims.children.clear();
93
128
  return authored;
94
129
  }
95
- #consume(record) {
130
+ #consume(record, claims) {
96
131
  if (record.type === "attributes") {
97
132
  const target = record.target;
98
- const pending2 = this.#claims?.attributes.get(target)?.get(record.attributeName);
133
+ const pending2 = claims.attributes.get(target)?.get(record.attributeName);
99
134
  if (!pending2 || pending2.count === 0 || target.getAttribute(record.attributeName) !== pending2.value) {
100
135
  return false;
101
136
  }
102
137
  pending2.count -= 1;
103
138
  return true;
104
139
  }
105
- const pending = this.#claims?.children.get(record.target);
140
+ const pending = claims.children.get(record.target);
106
141
  if (!pending) return false;
107
142
  const added = [...record.addedNodes];
108
143
  const removed = [...record.removedNodes];