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
@@ -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 setAttributeIfChanged(element, name, value, beforeWrite) {
@@ -180,7 +181,50 @@ function isCompositionInputType(inputType) {
180
181
  return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
181
182
  }
182
183
  var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
183
- var textOf = (element) => element.value;
184
+ var textOf = (element) => {
185
+ if ("value" in element) return element.value;
186
+ return element instanceof Element ? element.textContent : void 0;
187
+ };
188
+ var nodesOf = (element) => {
189
+ const nodes = [];
190
+ if ("value" in element || !(element instanceof Element)) return nodes;
191
+ const walker = element.ownerDocument.createTreeWalker(element);
192
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
193
+ return nodes;
194
+ };
195
+ var folded = (text) => text.replaceAll("\xA0", " ");
196
+ var startOf = (node, data, replaced, caret) => {
197
+ const text = folded(node.data);
198
+ const composed = folded(data);
199
+ if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
200
+ return replaced.startOffset;
201
+ }
202
+ const start = text.lastIndexOf(composed, caret);
203
+ return start !== -1 && start + composed.length >= caret ? start : -1;
204
+ };
205
+ var spotOf = (element, replaced, data) => {
206
+ if ("value" in element || !(element instanceof Element)) return null;
207
+ const selection = element.ownerDocument.getSelection();
208
+ const node = selection?.focusNode;
209
+ if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
210
+ const range = element.ownerDocument.createRange();
211
+ const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
212
+ if (start === -1) {
213
+ range.selectNodeContents(node);
214
+ } else {
215
+ range.setStart(node, start);
216
+ range.setEnd(node, start + data.length);
217
+ }
218
+ return range;
219
+ };
220
+ var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
221
+ var rewritten = ({ element, text, nodes, spot }) => {
222
+ if (spot !== null) {
223
+ return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
224
+ }
225
+ const current = nodesOf(element);
226
+ return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
227
+ };
184
228
  var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
185
229
  var CompositionTracker = class {
186
230
  #observedTargets = /* @__PURE__ */ new Set();
@@ -271,11 +315,11 @@ var CompositionTracker = class {
271
315
  }
272
316
  #settle() {
273
317
  const composition = this.#composition;
274
- if (composition === null) return;
275
- const { target, element, text } = composition;
318
+ if (composition === null || !this.#observedTargets.has(composition.target)) return;
319
+ const { target, element } = composition;
276
320
  if (target instanceof Node && element instanceof Node && !target.contains(element)) {
277
321
  this.#composition = null;
278
- } else if (textOf(element) !== text) {
322
+ } else if (rewritten(composition)) {
279
323
  this.#abandon(false);
280
324
  }
281
325
  }
@@ -300,7 +344,14 @@ var CompositionTracker = class {
300
344
  this.#owe(true);
301
345
  const target = event.currentTarget;
302
346
  const element = event.target;
303
- this.#composition = { target, element, text: textOf(element) };
347
+ this.#composition = {
348
+ target,
349
+ element,
350
+ text: textOf(element),
351
+ nodes: nodesOf(element),
352
+ spot: spotOf(element, null, void 0),
353
+ replaced: null
354
+ };
304
355
  this.#runAbandon();
305
356
  this.#onStart?.(event);
306
357
  };
@@ -324,6 +375,10 @@ var CompositionTracker = class {
324
375
  if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
325
376
  this.#abandon(true);
326
377
  }
378
+ const composition = this.#composition;
379
+ if (composition !== null && event.target === composition.element) {
380
+ composition.replaced = replacedBy(event);
381
+ }
327
382
  this.#runAbandon();
328
383
  };
329
384
  #handleInput = (event) => {
@@ -331,6 +386,15 @@ var CompositionTracker = class {
331
386
  const { isTrusted, isComposing, inputType } = event;
332
387
  if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
333
388
  composition.text = textOf(composition.element);
389
+ composition.nodes = nodesOf(composition.element);
390
+ if (isCompositionInputType(inputType)) {
391
+ composition.spot = spotOf(
392
+ composition.element,
393
+ composition.replaced,
394
+ event.data
395
+ );
396
+ }
397
+ composition.replaced = null;
334
398
  } else {
335
399
  this.#settle();
336
400
  }
@@ -351,7 +415,9 @@ var CompositionTracker = class {
351
415
  const composition = this.#composition;
352
416
  if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
353
417
  const detail = event.detail;
354
- if (detail?.attributeName === "value") event.preventDefault();
418
+ if (detail?.attributeName === "value" && "value" in composition.element) {
419
+ event.preventDefault();
420
+ }
355
421
  };
356
422
  };
357
423
 
@@ -1,13 +1,14 @@
1
1
  import { Controller } from '@hotwired/stimulus';
2
2
 
3
+ var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
3
4
  function announce(message, options = {}) {
4
5
  const text = message.trim();
5
6
  if (text.length === 0) return;
6
- window.dispatchEvent(
7
- new CustomEvent("stimeo--announcer:announce", {
8
- detail: { message: text, assertive: options.assertive === true }
9
- })
10
- );
7
+ const event = new CustomEvent("stimeo--announcer:announce", {
8
+ detail: { message: text, assertive: options.assertive === true }
9
+ });
10
+ if (options.afterFocus) event[afterFocus] = true;
11
+ window.dispatchEvent(event);
11
12
  }
12
13
 
13
14
  function setDefaultAttribute(element, name, value) {
@@ -202,7 +202,50 @@ function isCompositionInputType(inputType) {
202
202
  return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
203
203
  }
204
204
  var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
205
- var textOf = (element) => element.value;
205
+ var textOf = (element) => {
206
+ if ("value" in element) return element.value;
207
+ return element instanceof Element ? element.textContent : void 0;
208
+ };
209
+ var nodesOf = (element) => {
210
+ const nodes = [];
211
+ if ("value" in element || !(element instanceof Element)) return nodes;
212
+ const walker = element.ownerDocument.createTreeWalker(element);
213
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
214
+ return nodes;
215
+ };
216
+ var folded = (text) => text.replaceAll("\xA0", " ");
217
+ var startOf = (node, data, replaced, caret) => {
218
+ const text = folded(node.data);
219
+ const composed = folded(data);
220
+ if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
221
+ return replaced.startOffset;
222
+ }
223
+ const start = text.lastIndexOf(composed, caret);
224
+ return start !== -1 && start + composed.length >= caret ? start : -1;
225
+ };
226
+ var spotOf = (element, replaced, data) => {
227
+ if ("value" in element || !(element instanceof Element)) return null;
228
+ const selection = element.ownerDocument.getSelection();
229
+ const node = selection?.focusNode;
230
+ if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
231
+ const range = element.ownerDocument.createRange();
232
+ const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
233
+ if (start === -1) {
234
+ range.selectNodeContents(node);
235
+ } else {
236
+ range.setStart(node, start);
237
+ range.setEnd(node, start + data.length);
238
+ }
239
+ return range;
240
+ };
241
+ var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
242
+ var rewritten = ({ element, text, nodes, spot }) => {
243
+ if (spot !== null) {
244
+ return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
245
+ }
246
+ const current = nodesOf(element);
247
+ return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
248
+ };
206
249
  var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
207
250
  var CompositionTracker = class {
208
251
  #observedTargets = /* @__PURE__ */ new Set();
@@ -293,11 +336,11 @@ var CompositionTracker = class {
293
336
  }
294
337
  #settle() {
295
338
  const composition = this.#composition;
296
- if (composition === null) return;
297
- const { target, element, text } = composition;
339
+ if (composition === null || !this.#observedTargets.has(composition.target)) return;
340
+ const { target, element } = composition;
298
341
  if (target instanceof Node && element instanceof Node && !target.contains(element)) {
299
342
  this.#composition = null;
300
- } else if (textOf(element) !== text) {
343
+ } else if (rewritten(composition)) {
301
344
  this.#abandon(false);
302
345
  }
303
346
  }
@@ -322,7 +365,14 @@ var CompositionTracker = class {
322
365
  this.#owe(true);
323
366
  const target = event.currentTarget;
324
367
  const element = event.target;
325
- this.#composition = { target, element, text: textOf(element) };
368
+ this.#composition = {
369
+ target,
370
+ element,
371
+ text: textOf(element),
372
+ nodes: nodesOf(element),
373
+ spot: spotOf(element, null, void 0),
374
+ replaced: null
375
+ };
326
376
  this.#runAbandon();
327
377
  this.#onStart?.(event);
328
378
  };
@@ -346,6 +396,10 @@ var CompositionTracker = class {
346
396
  if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
347
397
  this.#abandon(true);
348
398
  }
399
+ const composition = this.#composition;
400
+ if (composition !== null && event.target === composition.element) {
401
+ composition.replaced = replacedBy(event);
402
+ }
349
403
  this.#runAbandon();
350
404
  };
351
405
  #handleInput = (event) => {
@@ -353,6 +407,15 @@ var CompositionTracker = class {
353
407
  const { isTrusted, isComposing, inputType } = event;
354
408
  if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
355
409
  composition.text = textOf(composition.element);
410
+ composition.nodes = nodesOf(composition.element);
411
+ if (isCompositionInputType(inputType)) {
412
+ composition.spot = spotOf(
413
+ composition.element,
414
+ composition.replaced,
415
+ event.data
416
+ );
417
+ }
418
+ composition.replaced = null;
356
419
  } else {
357
420
  this.#settle();
358
421
  }
@@ -373,7 +436,9 @@ var CompositionTracker = class {
373
436
  const composition = this.#composition;
374
437
  if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
375
438
  const detail = event.detail;
376
- if (detail?.attributeName === "value") event.preventDefault();
439
+ if (detail?.attributeName === "value" && "value" in composition.element) {
440
+ event.preventDefault();
441
+ }
377
442
  };
378
443
  };
379
444
 
@@ -202,7 +202,50 @@ function isCompositionInputType(inputType) {
202
202
  return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
203
203
  }
204
204
  var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
205
- var textOf = (element) => element.value;
205
+ var textOf = (element) => {
206
+ if ("value" in element) return element.value;
207
+ return element instanceof Element ? element.textContent : void 0;
208
+ };
209
+ var nodesOf = (element) => {
210
+ const nodes = [];
211
+ if ("value" in element || !(element instanceof Element)) return nodes;
212
+ const walker = element.ownerDocument.createTreeWalker(element);
213
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
214
+ return nodes;
215
+ };
216
+ var folded = (text) => text.replaceAll("\xA0", " ");
217
+ var startOf = (node, data, replaced, caret) => {
218
+ const text = folded(node.data);
219
+ const composed = folded(data);
220
+ if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
221
+ return replaced.startOffset;
222
+ }
223
+ const start = text.lastIndexOf(composed, caret);
224
+ return start !== -1 && start + composed.length >= caret ? start : -1;
225
+ };
226
+ var spotOf = (element, replaced, data) => {
227
+ if ("value" in element || !(element instanceof Element)) return null;
228
+ const selection = element.ownerDocument.getSelection();
229
+ const node = selection?.focusNode;
230
+ if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
231
+ const range = element.ownerDocument.createRange();
232
+ const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
233
+ if (start === -1) {
234
+ range.selectNodeContents(node);
235
+ } else {
236
+ range.setStart(node, start);
237
+ range.setEnd(node, start + data.length);
238
+ }
239
+ return range;
240
+ };
241
+ var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
242
+ var rewritten = ({ element, text, nodes, spot }) => {
243
+ if (spot !== null) {
244
+ return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
245
+ }
246
+ const current = nodesOf(element);
247
+ return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
248
+ };
206
249
  var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
207
250
  var CompositionTracker = class {
208
251
  #observedTargets = /* @__PURE__ */ new Set();
@@ -293,11 +336,11 @@ var CompositionTracker = class {
293
336
  }
294
337
  #settle() {
295
338
  const composition = this.#composition;
296
- if (composition === null) return;
297
- const { target, element, text } = composition;
339
+ if (composition === null || !this.#observedTargets.has(composition.target)) return;
340
+ const { target, element } = composition;
298
341
  if (target instanceof Node && element instanceof Node && !target.contains(element)) {
299
342
  this.#composition = null;
300
- } else if (textOf(element) !== text) {
343
+ } else if (rewritten(composition)) {
301
344
  this.#abandon(false);
302
345
  }
303
346
  }
@@ -322,7 +365,14 @@ var CompositionTracker = class {
322
365
  this.#owe(true);
323
366
  const target = event.currentTarget;
324
367
  const element = event.target;
325
- this.#composition = { target, element, text: textOf(element) };
368
+ this.#composition = {
369
+ target,
370
+ element,
371
+ text: textOf(element),
372
+ nodes: nodesOf(element),
373
+ spot: spotOf(element, null, void 0),
374
+ replaced: null
375
+ };
326
376
  this.#runAbandon();
327
377
  this.#onStart?.(event);
328
378
  };
@@ -346,6 +396,10 @@ var CompositionTracker = class {
346
396
  if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
347
397
  this.#abandon(true);
348
398
  }
399
+ const composition = this.#composition;
400
+ if (composition !== null && event.target === composition.element) {
401
+ composition.replaced = replacedBy(event);
402
+ }
349
403
  this.#runAbandon();
350
404
  };
351
405
  #handleInput = (event) => {
@@ -353,6 +407,15 @@ var CompositionTracker = class {
353
407
  const { isTrusted, isComposing, inputType } = event;
354
408
  if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
355
409
  composition.text = textOf(composition.element);
410
+ composition.nodes = nodesOf(composition.element);
411
+ if (isCompositionInputType(inputType)) {
412
+ composition.spot = spotOf(
413
+ composition.element,
414
+ composition.replaced,
415
+ event.data
416
+ );
417
+ }
418
+ composition.replaced = null;
356
419
  } else {
357
420
  this.#settle();
358
421
  }
@@ -373,7 +436,9 @@ var CompositionTracker = class {
373
436
  const composition = this.#composition;
374
437
  if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
375
438
  const detail = event.detail;
376
- if (detail?.attributeName === "value") event.preventDefault();
439
+ if (detail?.attributeName === "value" && "value" in composition.element) {
440
+ event.preventDefault();
441
+ }
377
442
  };
378
443
  };
379
444
 
@@ -421,6 +486,7 @@ var EscapeLayer = class _EscapeLayer {
421
486
  );
422
487
  #active = null;
423
488
  activate(ownerDocument = document, options) {
489
+ const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
424
490
  this.deactivate();
425
491
  let registry2 = _EscapeLayer.#registries.get(ownerDocument);
426
492
  if (!registry2) {
@@ -428,7 +494,6 @@ var EscapeLayer = class _EscapeLayer {
428
494
  _EscapeLayer.#registries.set(ownerDocument, registry2);
429
495
  ownerDocument.addEventListener("keydown", registry2.onKeydown);
430
496
  }
431
- const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
432
497
  registry2.stack.push(entry);
433
498
  this.#active = { document: ownerDocument, entry };
434
499
  }
@@ -477,11 +542,16 @@ var EscapeLayer = class _EscapeLayer {
477
542
  }
478
543
  };
479
544
 
545
+ var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
480
546
  function inheritsFieldsetDisabled(control) {
481
547
  let fieldset = control.closest("fieldset[disabled]");
482
548
  while (fieldset) {
483
- const legend = Array.from(fieldset.children).find((child) => child.tagName === "LEGEND");
484
- if (!legend?.contains(control)) return true;
549
+ if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
550
+ const legend = Array.from(fieldset.children).find(
551
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
552
+ );
553
+ if (!legend?.contains(control)) return true;
554
+ }
485
555
  fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
486
556
  }
487
557
  return false;
@@ -554,11 +624,10 @@ function hasNativeTabStop(element) {
554
624
  if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
555
625
  return element.hasAttribute("controls");
556
626
  }
557
- if (element instanceof HTMLElement && element.tagName === "SUMMARY") {
558
- const details = element.parentElement;
559
- return details instanceof HTMLDetailsElement && Array.from(details.children).find((child) => child.tagName === "SUMMARY") === element;
560
- }
561
- return false;
627
+ const details = element.parentElement;
628
+ return details instanceof HTMLDetailsElement && Array.from(details.children).find(
629
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "summary"
630
+ ) === element;
562
631
  }
563
632
  function hasEditableTabStop(element) {
564
633
  const value = element.getAttribute("contenteditable")?.toLowerCase();
@@ -621,8 +690,7 @@ function isSequentialStop(element) {
621
690
  function ownedScope(element) {
622
691
  if (element.shadowRoot) return Array.from(element.shadowRoot.children);
623
692
  if (element instanceof HTMLSlotElement) {
624
- const assigned = element.assignedElements();
625
- return assigned.length > 0 ? assigned : Array.from(element.children);
693
+ return element.assignedNodes().length > 0 ? element.assignedElements() : Array.from(element.children);
626
694
  }
627
695
  return null;
628
696
  }
@@ -631,12 +699,19 @@ function orderScope(elements, walk) {
631
699
  const visit = (element) => {
632
700
  if (element === walk.from) walk.fromAt = walk.tree.length;
633
701
  const tabindex = authoredTabindex(element) ?? 0;
634
- const stop = (element instanceof HTMLElement || element instanceof SVGElement) && isSequentialStop(element) ? element : null;
635
- if (stop) walk.tree.push(stop);
702
+ let stop = null;
703
+ if ((element instanceof HTMLElement || element instanceof SVGElement) && isSequentialStop(element)) {
704
+ stop = element;
705
+ walk.tree.push(element);
706
+ }
636
707
  const owned = ownedScope(element);
637
708
  if (owned) {
638
709
  if (tabindex >= 0) {
639
710
  entries.push({ tabindex, stops: [...stop ? [stop] : [], ...orderScope(owned, walk)] });
711
+ } else if (walk.from && flatTreeContains(element, walk.from)) {
712
+ walk.fromAt = walk.tree.length;
713
+ walk.excludedScope = element;
714
+ orderScope(owned, { from: walk.from, tree: walk.tree, fromAt: -1, excludedScope: null });
640
715
  }
641
716
  return;
642
717
  }
@@ -664,16 +739,38 @@ function startIndex(order, walk, backward, isStop) {
664
739
  if (at >= 0) return backward ? at - 1 : at + 1;
665
740
  const neighbour = backward ? walk.tree.slice(0, walk.fromAt).reverse().find(isStop) : walk.tree.slice(walk.fromAt).find(isStop);
666
741
  if (neighbour) return order.indexOf(neighbour);
667
- return backward ? order.length - 1 : 0;
742
+ return backward ? -1 : order.length;
668
743
  }
669
- function sequentialTabStops(root, from = null, backward = false) {
670
- const walk = { from, tree: [], fromAt: from === root ? 0 : -1 };
744
+ function movesWithin(root, from, backward, wrap, radioContext) {
745
+ const walk = {
746
+ from,
747
+ tree: [],
748
+ fromAt: from === root ? 0 : -1,
749
+ excludedScope: null
750
+ };
671
751
  const order = orderScope(ownedScope(root) ?? Array.from(root.children), walk);
672
- const focusedRadio = walk.fromAt >= 0 && isRadio(from) ? from : null;
673
- const isStop = (element) => passesRadioRule(element, walk.tree, focusedRadio);
674
- const start = startIndex(order, walk, backward, isStop);
675
- const visited = backward ? [...order.slice(0, start + 1).reverse(), ...order.slice(start + 1).reverse()] : [...order.slice(start), ...order.slice(0, start)];
676
- return visited.filter((element) => element !== from && isStop(element));
752
+ const radios = radioContext ?? {
753
+ tree: walk.tree,
754
+ focusedRadio: walk.fromAt >= 0 && isRadio(from) ? from : null
755
+ };
756
+ const isStop = (element) => passesRadioRule(element, radios.tree, radios.focusedRadio);
757
+ const start = startIndex(
758
+ order,
759
+ walk,
760
+ backward,
761
+ (element) => order.includes(element) && isStop(element)
762
+ );
763
+ const remaining = backward ? order.slice(0, start + 1).reverse() : order.slice(start);
764
+ const wrapped = wrap ? backward ? order.slice(start + 1).reverse() : order.slice(0, start) : [];
765
+ const excluded = walk.excludedScope;
766
+ const prefix = excluded && !(backward && from === excluded) ? movesWithin(excluded, from === excluded ? null : from, backward, false, radios) : [];
767
+ return [
768
+ ...prefix,
769
+ ...[...remaining, ...wrapped].filter((element) => element !== from && isStop(element))
770
+ ];
771
+ }
772
+ function sequentialTabStops(root, from = null, backward = false) {
773
+ return movesWithin(root, from, backward, true);
677
774
  }
678
775
  function deepActiveElement(ownerDocument) {
679
776
  let active = ownerDocument.activeElement;
@@ -860,7 +957,10 @@ var FocusTrap = class _FocusTrap {
860
957
  constructor(getContainer, options = {}) {
861
958
  this.#getContainer = getContainer;
862
959
  this.#options = options;
863
- this.#entry = {
960
+ this.#entry = this.#createEntry();
961
+ }
962
+ #createEntry() {
963
+ return {
864
964
  container: () => this.#readContainer(),
865
965
  moveFocus: (backward) => this.#moveFocus(backward),
866
966
  refocus: () => this.#refocus(),
@@ -876,6 +976,7 @@ var FocusTrap = class _FocusTrap {
876
976
  activate() {
877
977
  if (this.#activeState) return;
878
978
  _FocusTrap.#sweep();
979
+ this.#entry = this.#createEntry();
879
980
  this.#activeState = true;
880
981
  this.#openers = _FocusTrap.#focusPath();
881
982
  this.#entry.openedFrom = _FocusTrap.#trapHolding(this.#openers[0] ?? null);
@@ -892,14 +993,20 @@ var FocusTrap = class _FocusTrap {
892
993
  this.#returnTabindexes();
893
994
  return;
894
995
  }
996
+ const entry = this.#entry;
997
+ const openers = this.#openers;
998
+ this.#openers = [];
895
999
  this.#activeState = false;
896
1000
  this.#escapeLayer.deactivate();
897
- const above = this.#leaveStack();
898
- this.#unlockScroll();
1001
+ const above = this.#leaveStack(entry);
1002
+ this.#unlockScroll(entry);
899
1003
  _FocusTrap.#reconcileBackground(document);
900
- const wayBack = this.#handOver(above);
901
- if (restoreFocus) this.#restore(wayBack, above);
902
- this.#returnTabindexes();
1004
+ try {
1005
+ const wayBack = this.#handOver(entry, openers, above);
1006
+ if (restoreFocus) this.#restore(wayBack, above);
1007
+ } finally {
1008
+ this.#returnTabindexes();
1009
+ }
903
1010
  }
904
1011
  connect() {
905
1012
  this.#gate.cancel();
@@ -938,9 +1045,9 @@ var FocusTrap = class _FocusTrap {
938
1045
  }
939
1046
  registry2.stack.push(this.#entry);
940
1047
  }
941
- #leaveStack() {
1048
+ #leaveStack(entry) {
942
1049
  const registry2 = _FocusTrap.#registry(document);
943
- const index = registry2.stack.indexOf(this.#entry);
1050
+ const index = registry2.stack.indexOf(entry);
944
1051
  const above = registry2.stack.slice(index + 1);
945
1052
  registry2.stack.splice(index, 1);
946
1053
  if (registry2.stack.length === 0) {
@@ -964,21 +1071,23 @@ var FocusTrap = class _FocusTrap {
964
1071
  }
965
1072
  return null;
966
1073
  }
967
- #handOver(above) {
968
- const entry = this.#entry;
969
- const wayBack = [
970
- ...this.#openers,
971
- this.#options.fallbackFocus?.() ?? null,
972
- ...entry.handedBack
973
- ].filter((element) => element !== null);
974
- for (const trap of above) {
975
- if (trap.openedFrom !== entry) continue;
976
- trap.handedBack = [...trap.handedBack, ...wayBack];
977
- trap.openedFrom = entry.openedFrom;
978
- }
979
- this.#openers = [];
1074
+ #handOver(entry, openers, above) {
1075
+ const wayBack = [...openers];
1076
+ const parent = entry.openedFrom;
1077
+ const handedBack = entry.handedBack;
980
1078
  entry.openedFrom = null;
981
1079
  entry.handedBack = [];
1080
+ try {
1081
+ const fallback = this.#options.fallbackFocus?.();
1082
+ if (fallback) wayBack.push(fallback);
1083
+ } finally {
1084
+ wayBack.push(...handedBack);
1085
+ for (const trap of above) {
1086
+ if (trap.openedFrom !== entry) continue;
1087
+ trap.handedBack = [...trap.handedBack, ...wayBack];
1088
+ trap.openedFrom = parent;
1089
+ }
1090
+ }
982
1091
  return wayBack;
983
1092
  }
984
1093
  #restore(wayBack, above) {
@@ -1028,11 +1137,11 @@ var FocusTrap = class _FocusTrap {
1028
1137
  this.#entry.lockedBody = body;
1029
1138
  body.style.overflow = "hidden";
1030
1139
  }
1031
- #unlockScroll() {
1140
+ #unlockScroll(entry) {
1032
1141
  const registry2 = _FocusTrap.#registry(document);
1033
- const body = this.#entry.lockedBody;
1034
- this.#entry.lockedBody = null;
1035
- if (!registry2.scrollLocks.delete(this.#entry) || !body) return;
1142
+ const body = entry.lockedBody;
1143
+ entry.lockedBody = null;
1144
+ if (!registry2.scrollLocks.delete(entry) || !body) return;
1036
1145
  if (!_FocusTrap.#isLocked(registry2, body)) _FocusTrap.#unlock(body);
1037
1146
  }
1038
1147
  static #isLocked(registry2, body) {