stimeo-ui 0.18.0 → 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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +52 -2
  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 +161 -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 +13 -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 +72 -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 +117 -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 +107 -22
  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/pointer_drag_controller.js +6 -1
  51. data/dist/controllers/popover_controller.js +21 -8
  52. data/dist/controllers/progress_controller.js +6 -5
  53. data/dist/controllers/radio_group_controller.js +85 -49
  54. data/dist/controllers/range_slider_controller.js +72 -54
  55. data/dist/controllers/relative_time_controller.js +1 -7
  56. data/dist/controllers/roving_controller.js +7 -2
  57. data/dist/controllers/scroll_area_controller.js +11 -7
  58. data/dist/controllers/scrollspy_controller.js +61 -29
  59. data/dist/controllers/separator_controller.js +72 -54
  60. data/dist/controllers/sidebar_controller.js +89 -45
  61. data/dist/controllers/skeleton_controller.js +50 -16
  62. data/dist/controllers/slider_controller.js +72 -54
  63. data/dist/controllers/sortable_controller.js +6 -5
  64. data/dist/controllers/spinner_controller.js +50 -16
  65. data/dist/controllers/sticky_observer_controller.js +61 -29
  66. data/dist/controllers/submit_once_controller.js +6 -5
  67. data/dist/controllers/switch_controller.js +84 -44
  68. data/dist/controllers/tags_input_controller.js +83 -20
  69. data/dist/controllers/time_picker_controller.js +77 -42
  70. data/dist/controllers/toggle_group_controller.js +84 -44
  71. data/dist/controllers/toolbar_controller.js +78 -8
  72. data/dist/controllers/tooltip_controller.js +1 -1
  73. data/dist/controllers/tree_view_controller.js +87 -49
  74. data/dist/index.js +566 -288
  75. data/lib/stimeo/ui/version.rb +1 -1
  76. metadata +2 -2
data/dist/index.js CHANGED
@@ -530,6 +530,7 @@ var EscapeLayer = class _EscapeLayer {
530
530
  );
531
531
  #active = null;
532
532
  activate(ownerDocument = document, options) {
533
+ const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
533
534
  this.deactivate();
534
535
  let registry2 = _EscapeLayer.#registries.get(ownerDocument);
535
536
  if (!registry2) {
@@ -537,7 +538,6 @@ var EscapeLayer = class _EscapeLayer {
537
538
  _EscapeLayer.#registries.set(ownerDocument, registry2);
538
539
  ownerDocument.addEventListener("keydown", registry2.onKeydown);
539
540
  }
540
- const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
541
541
  registry2.stack.push(entry);
542
542
  this.#active = { document: ownerDocument, entry };
543
543
  }
@@ -586,11 +586,16 @@ var EscapeLayer = class _EscapeLayer {
586
586
  }
587
587
  };
588
588
 
589
+ var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
589
590
  function inheritsFieldsetDisabled(control) {
590
591
  let fieldset = control.closest("fieldset[disabled]");
591
592
  while (fieldset) {
592
- const legend = Array.from(fieldset.children).find((child) => child.tagName === "LEGEND");
593
- if (!legend?.contains(control)) return true;
593
+ if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
594
+ const legend = Array.from(fieldset.children).find(
595
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
596
+ );
597
+ if (!legend?.contains(control)) return true;
598
+ }
594
599
  fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
595
600
  }
596
601
  return false;
@@ -663,11 +668,10 @@ function hasNativeTabStop(element) {
663
668
  if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
664
669
  return element.hasAttribute("controls");
665
670
  }
666
- if (element instanceof HTMLElement && element.tagName === "SUMMARY") {
667
- const details = element.parentElement;
668
- return details instanceof HTMLDetailsElement && Array.from(details.children).find((child) => child.tagName === "SUMMARY") === element;
669
- }
670
- return false;
671
+ const details = element.parentElement;
672
+ return details instanceof HTMLDetailsElement && Array.from(details.children).find(
673
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "summary"
674
+ ) === element;
671
675
  }
672
676
  function hasEditableTabStop(element) {
673
677
  const value = element.getAttribute("contenteditable")?.toLowerCase();
@@ -744,8 +748,7 @@ function isSequentialStop(element) {
744
748
  function ownedScope(element) {
745
749
  if (element.shadowRoot) return Array.from(element.shadowRoot.children);
746
750
  if (element instanceof HTMLSlotElement) {
747
- const assigned = element.assignedElements();
748
- return assigned.length > 0 ? assigned : Array.from(element.children);
751
+ return element.assignedNodes().length > 0 ? element.assignedElements() : Array.from(element.children);
749
752
  }
750
753
  return null;
751
754
  }
@@ -754,12 +757,19 @@ function orderScope(elements, walk) {
754
757
  const visit = (element) => {
755
758
  if (element === walk.from) walk.fromAt = walk.tree.length;
756
759
  const tabindex = authoredTabindex(element) ?? 0;
757
- const stop = (element instanceof HTMLElement || element instanceof SVGElement) && isSequentialStop(element) ? element : null;
758
- if (stop) walk.tree.push(stop);
760
+ let stop = null;
761
+ if ((element instanceof HTMLElement || element instanceof SVGElement) && isSequentialStop(element)) {
762
+ stop = element;
763
+ walk.tree.push(element);
764
+ }
759
765
  const owned = ownedScope(element);
760
766
  if (owned) {
761
767
  if (tabindex >= 0) {
762
768
  entries.push({ tabindex, stops: [...stop ? [stop] : [], ...orderScope(owned, walk)] });
769
+ } else if (walk.from && flatTreeContains(element, walk.from)) {
770
+ walk.fromAt = walk.tree.length;
771
+ walk.excludedScope = element;
772
+ orderScope(owned, { from: walk.from, tree: walk.tree, fromAt: -1, excludedScope: null });
763
773
  }
764
774
  return;
765
775
  }
@@ -787,16 +797,38 @@ function startIndex(order, walk, backward, isStop) {
787
797
  if (at >= 0) return backward ? at - 1 : at + 1;
788
798
  const neighbour = backward ? walk.tree.slice(0, walk.fromAt).reverse().find(isStop) : walk.tree.slice(walk.fromAt).find(isStop);
789
799
  if (neighbour) return order.indexOf(neighbour);
790
- return backward ? order.length - 1 : 0;
800
+ return backward ? -1 : order.length;
791
801
  }
792
- function sequentialTabStops(root, from = null, backward = false) {
793
- const walk = { from, tree: [], fromAt: from === root ? 0 : -1 };
802
+ function movesWithin(root, from, backward, wrap, radioContext) {
803
+ const walk = {
804
+ from,
805
+ tree: [],
806
+ fromAt: from === root ? 0 : -1,
807
+ excludedScope: null
808
+ };
794
809
  const order = orderScope(ownedScope(root) ?? Array.from(root.children), walk);
795
- const focusedRadio = walk.fromAt >= 0 && isRadio(from) ? from : null;
796
- const isStop = (element) => passesRadioRule(element, walk.tree, focusedRadio);
797
- const start = startIndex(order, walk, backward, isStop);
798
- const visited = backward ? [...order.slice(0, start + 1).reverse(), ...order.slice(start + 1).reverse()] : [...order.slice(start), ...order.slice(0, start)];
799
- return visited.filter((element) => element !== from && isStop(element));
810
+ const radios = radioContext ?? {
811
+ tree: walk.tree,
812
+ focusedRadio: walk.fromAt >= 0 && isRadio(from) ? from : null
813
+ };
814
+ const isStop = (element) => passesRadioRule(element, radios.tree, radios.focusedRadio);
815
+ const start = startIndex(
816
+ order,
817
+ walk,
818
+ backward,
819
+ (element) => order.includes(element) && isStop(element)
820
+ );
821
+ const remaining = backward ? order.slice(0, start + 1).reverse() : order.slice(start);
822
+ const wrapped = wrap ? backward ? order.slice(start + 1).reverse() : order.slice(0, start) : [];
823
+ const excluded = walk.excludedScope;
824
+ const prefix = excluded && !(backward && from === excluded) ? movesWithin(excluded, from === excluded ? null : from, backward, false, radios) : [];
825
+ return [
826
+ ...prefix,
827
+ ...[...remaining, ...wrapped].filter((element) => element !== from && isStop(element))
828
+ ];
829
+ }
830
+ function sequentialTabStops(root, from = null, backward = false) {
831
+ return movesWithin(root, from, backward, true);
800
832
  }
801
833
  function deepActiveElement(ownerDocument) {
802
834
  let active = ownerDocument.activeElement;
@@ -983,7 +1015,10 @@ var FocusTrap = class _FocusTrap {
983
1015
  constructor(getContainer, options = {}) {
984
1016
  this.#getContainer = getContainer;
985
1017
  this.#options = options;
986
- this.#entry = {
1018
+ this.#entry = this.#createEntry();
1019
+ }
1020
+ #createEntry() {
1021
+ return {
987
1022
  container: () => this.#readContainer(),
988
1023
  moveFocus: (backward) => this.#moveFocus(backward),
989
1024
  refocus: () => this.#refocus(),
@@ -999,6 +1034,7 @@ var FocusTrap = class _FocusTrap {
999
1034
  activate() {
1000
1035
  if (this.#activeState) return;
1001
1036
  _FocusTrap.#sweep();
1037
+ this.#entry = this.#createEntry();
1002
1038
  this.#activeState = true;
1003
1039
  this.#openers = _FocusTrap.#focusPath();
1004
1040
  this.#entry.openedFrom = _FocusTrap.#trapHolding(this.#openers[0] ?? null);
@@ -1015,14 +1051,20 @@ var FocusTrap = class _FocusTrap {
1015
1051
  this.#returnTabindexes();
1016
1052
  return;
1017
1053
  }
1054
+ const entry = this.#entry;
1055
+ const openers = this.#openers;
1056
+ this.#openers = [];
1018
1057
  this.#activeState = false;
1019
1058
  this.#escapeLayer.deactivate();
1020
- const above = this.#leaveStack();
1021
- this.#unlockScroll();
1059
+ const above = this.#leaveStack(entry);
1060
+ this.#unlockScroll(entry);
1022
1061
  _FocusTrap.#reconcileBackground(document);
1023
- const wayBack = this.#handOver(above);
1024
- if (restoreFocus) this.#restore(wayBack, above);
1025
- this.#returnTabindexes();
1062
+ try {
1063
+ const wayBack = this.#handOver(entry, openers, above);
1064
+ if (restoreFocus) this.#restore(wayBack, above);
1065
+ } finally {
1066
+ this.#returnTabindexes();
1067
+ }
1026
1068
  }
1027
1069
  connect() {
1028
1070
  this.#gate.cancel();
@@ -1061,9 +1103,9 @@ var FocusTrap = class _FocusTrap {
1061
1103
  }
1062
1104
  registry2.stack.push(this.#entry);
1063
1105
  }
1064
- #leaveStack() {
1106
+ #leaveStack(entry) {
1065
1107
  const registry2 = _FocusTrap.#registry(document);
1066
- const index = registry2.stack.indexOf(this.#entry);
1108
+ const index = registry2.stack.indexOf(entry);
1067
1109
  const above = registry2.stack.slice(index + 1);
1068
1110
  registry2.stack.splice(index, 1);
1069
1111
  if (registry2.stack.length === 0) {
@@ -1087,21 +1129,23 @@ var FocusTrap = class _FocusTrap {
1087
1129
  }
1088
1130
  return null;
1089
1131
  }
1090
- #handOver(above) {
1091
- const entry = this.#entry;
1092
- const wayBack = [
1093
- ...this.#openers,
1094
- this.#options.fallbackFocus?.() ?? null,
1095
- ...entry.handedBack
1096
- ].filter((element) => element !== null);
1097
- for (const trap of above) {
1098
- if (trap.openedFrom !== entry) continue;
1099
- trap.handedBack = [...trap.handedBack, ...wayBack];
1100
- trap.openedFrom = entry.openedFrom;
1101
- }
1102
- this.#openers = [];
1132
+ #handOver(entry, openers, above) {
1133
+ const wayBack = [...openers];
1134
+ const parent = entry.openedFrom;
1135
+ const handedBack = entry.handedBack;
1103
1136
  entry.openedFrom = null;
1104
1137
  entry.handedBack = [];
1138
+ try {
1139
+ const fallback = this.#options.fallbackFocus?.();
1140
+ if (fallback) wayBack.push(fallback);
1141
+ } finally {
1142
+ wayBack.push(...handedBack);
1143
+ for (const trap of above) {
1144
+ if (trap.openedFrom !== entry) continue;
1145
+ trap.handedBack = [...trap.handedBack, ...wayBack];
1146
+ trap.openedFrom = parent;
1147
+ }
1148
+ }
1105
1149
  return wayBack;
1106
1150
  }
1107
1151
  #restore(wayBack, above) {
@@ -1151,11 +1195,11 @@ var FocusTrap = class _FocusTrap {
1151
1195
  this.#entry.lockedBody = body;
1152
1196
  body.style.overflow = "hidden";
1153
1197
  }
1154
- #unlockScroll() {
1198
+ #unlockScroll(entry) {
1155
1199
  const registry2 = _FocusTrap.#registry(document);
1156
- const body = this.#entry.lockedBody;
1157
- this.#entry.lockedBody = null;
1158
- if (!registry2.scrollLocks.delete(this.#entry) || !body) return;
1200
+ const body = entry.lockedBody;
1201
+ entry.lockedBody = null;
1202
+ if (!registry2.scrollLocks.delete(entry) || !body) return;
1159
1203
  if (!_FocusTrap.#isLocked(registry2, body)) _FocusTrap.#unlock(body);
1160
1204
  }
1161
1205
  static #isLocked(registry2, body) {
@@ -1437,6 +1481,27 @@ var AlertDialogController = class extends Controller {
1437
1481
  }
1438
1482
  };
1439
1483
 
1484
+ function fillTemplate(template, values) {
1485
+ return template.replace(/\{([a-zA-Z][a-zA-Z0-9]*)\}/g, (match, name) => {
1486
+ const replacement = Object.hasOwn(values, name) ? values[name] : void 0;
1487
+ return replacement === void 0 ? match : String(replacement);
1488
+ });
1489
+ }
1490
+
1491
+ var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
1492
+ function announcesAfterFocus(event) {
1493
+ return event[afterFocus] === true;
1494
+ }
1495
+ function announce(message, options = {}) {
1496
+ const text = message.trim();
1497
+ if (text.length === 0) return;
1498
+ const event = new CustomEvent("stimeo--announcer:announce", {
1499
+ detail: { message: text, assertive: options.assertive === true }
1500
+ });
1501
+ if (options.afterFocus) event[afterFocus] = true;
1502
+ window.dispatchEvent(event);
1503
+ }
1504
+
1440
1505
  var MAX_TIMER_DELAY_MS = 2147483647;
1441
1506
 
1442
1507
  var TimerRegistry = class {
@@ -1456,6 +1521,22 @@ var TimerRegistry = class {
1456
1521
  return this.ids.size;
1457
1522
  }
1458
1523
  };
1524
+ var TimeoutRegistration = class {
1525
+ #registration;
1526
+ constructor(owner, id) {
1527
+ this.#registration = { owner, id };
1528
+ }
1529
+ get pending() {
1530
+ return this.#registration !== null;
1531
+ }
1532
+ cancel() {
1533
+ const registration = this.#registration;
1534
+ if (registration) registration.owner.clear(registration.id);
1535
+ }
1536
+ expire() {
1537
+ this.#registration = null;
1538
+ }
1539
+ };
1459
1540
  var SafeTimeout = class extends TimerRegistry {
1460
1541
  set(callback, delay) {
1461
1542
  const id = this.schedule(() => {
@@ -1472,6 +1553,29 @@ var SafeTimeout = class extends TimerRegistry {
1472
1553
  window.clearTimeout(id);
1473
1554
  }
1474
1555
  };
1556
+ var TaskTimeout = class extends SafeTimeout {
1557
+ #tasks = /* @__PURE__ */ new Map();
1558
+ setTask(callback, delay) {
1559
+ const id = this.set(() => {
1560
+ this.#tasks.delete(id);
1561
+ registration.expire();
1562
+ callback();
1563
+ }, delay);
1564
+ const registration = new TimeoutRegistration(this, id);
1565
+ this.#tasks.set(id, registration);
1566
+ return registration;
1567
+ }
1568
+ clear(id) {
1569
+ this.#tasks.get(id)?.expire();
1570
+ this.#tasks.delete(id);
1571
+ super.clear(id);
1572
+ }
1573
+ clearAll() {
1574
+ for (const registration of this.#tasks.values()) registration.expire();
1575
+ this.#tasks.clear();
1576
+ super.clearAll();
1577
+ }
1578
+ };
1475
1579
  var SafeInterval = class extends TimerRegistry {
1476
1580
  set(callback, delay) {
1477
1581
  const id = this.schedule(callback, delay);
@@ -1652,6 +1756,7 @@ var OwnedText = class {
1652
1756
  };
1653
1757
 
1654
1758
  var LEVELS = ["polite", "assertive"];
1759
+ var FOCUS_SETTLE_MS = 500;
1655
1760
  var STAND_IN = "stand-in";
1656
1761
  var ANNOUNCED = "announced";
1657
1762
  var AnnouncerController = class _AnnouncerController extends Controller {
@@ -1687,7 +1792,7 @@ var AnnouncerController = class _AnnouncerController extends Controller {
1687
1792
  const detail = event.detail;
1688
1793
  const message = this.#messageFromDetail(detail);
1689
1794
  if (!message) return;
1690
- this.#announce(message, this.#assertiveFromDetail(detail));
1795
+ this.#announce(message, this.#assertiveFromDetail(detail), announcesAfterFocus(event));
1691
1796
  };
1692
1797
  connect() {
1693
1798
  const moved = this.#gate.pending;
@@ -1771,30 +1876,37 @@ var AnnouncerController = class _AnnouncerController extends Controller {
1771
1876
  const message = typeof fromParam === "string" && fromParam.length > 0 ? fromParam : this.#messageFromDetail(event.detail);
1772
1877
  if (!message) return;
1773
1878
  const assertive = params?.assertive === true || this.#assertiveFromDetail(event.detail);
1774
- this.#announce(message, assertive);
1879
+ this.#announce(message, assertive, announcesAfterFocus(event));
1775
1880
  }
1776
- #announce(message, assertive) {
1881
+ #announce(text, assertive, afterFocus2) {
1777
1882
  const level = assertive ? "assertive" : "polite";
1883
+ const announcement = { text, afterFocus: !assertive && afterFocus2 };
1778
1884
  const queue = this.#queues.get(level);
1779
1885
  if (queue) {
1780
- queue.push(message);
1886
+ queue.push(announcement);
1781
1887
  } else {
1782
- this.#queues.set(level, [message]);
1888
+ this.#queues.set(level, [announcement]);
1783
1889
  }
1784
1890
  this.#scheduleDrain(level);
1785
1891
  }
1786
- #scheduleDrain(level) {
1892
+ #scheduleDrain(level, delay = 0) {
1787
1893
  if (this.#draining.has(level)) return;
1788
1894
  this.#draining.add(level);
1789
1895
  this.#timers.set(() => {
1790
1896
  this.#draining.delete(level);
1791
1897
  this.#drain(level);
1792
- }, 0);
1898
+ }, delay);
1793
1899
  }
1794
1900
  #drain(level) {
1795
1901
  const queue = this.#queues.get(level);
1796
- const message = queue?.[0];
1797
- if (queue === void 0 || message === void 0) return;
1902
+ const announcement = queue?.[0];
1903
+ if (queue === void 0 || announcement === void 0) return;
1904
+ if (announcement.afterFocus) {
1905
+ announcement.afterFocus = false;
1906
+ this.#scheduleDrain(level, FOCUS_SETTLE_MS);
1907
+ return;
1908
+ }
1909
+ const message = announcement.text;
1798
1910
  const created = this.#reconcileRegions();
1799
1911
  const region = this.#regionFor(level);
1800
1912
  if (created || region === void 0) {
@@ -1891,23 +2003,6 @@ var AspectRatioController = class extends Controller {
1891
2003
  }
1892
2004
  };
1893
2005
 
1894
- function fillTemplate(template, values) {
1895
- return template.replace(/\{([a-zA-Z][a-zA-Z0-9]*)\}/g, (match, name) => {
1896
- const replacement = Object.hasOwn(values, name) ? values[name] : void 0;
1897
- return replacement === void 0 ? match : String(replacement);
1898
- });
1899
- }
1900
-
1901
- function announce(message, options = {}) {
1902
- const text = message.trim();
1903
- if (text.length === 0) return;
1904
- window.dispatchEvent(
1905
- new CustomEvent("stimeo--announcer:announce", {
1906
- detail: { message: text, assertive: options.assertive === true }
1907
- })
1908
- );
1909
- }
1910
-
1911
2006
  var COMPOSITION_INPUT_TYPES = /* @__PURE__ */ new Set([
1912
2007
  "insertCompositionText",
1913
2008
  "insertFromComposition",
@@ -1918,7 +2013,50 @@ function isCompositionInputType(inputType) {
1918
2013
  return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
1919
2014
  }
1920
2015
  var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
1921
- var textOf = (element) => element.value;
2016
+ var textOf = (element) => {
2017
+ if ("value" in element) return element.value;
2018
+ return element instanceof Element ? element.textContent : void 0;
2019
+ };
2020
+ var nodesOf = (element) => {
2021
+ const nodes = [];
2022
+ if ("value" in element || !(element instanceof Element)) return nodes;
2023
+ const walker = element.ownerDocument.createTreeWalker(element);
2024
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
2025
+ return nodes;
2026
+ };
2027
+ var folded = (text) => text.replaceAll("\xA0", " ");
2028
+ var startOf = (node, data, replaced, caret) => {
2029
+ const text = folded(node.data);
2030
+ const composed = folded(data);
2031
+ if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
2032
+ return replaced.startOffset;
2033
+ }
2034
+ const start = text.lastIndexOf(composed, caret);
2035
+ return start !== -1 && start + composed.length >= caret ? start : -1;
2036
+ };
2037
+ var spotOf = (element, replaced, data) => {
2038
+ if ("value" in element || !(element instanceof Element)) return null;
2039
+ const selection = element.ownerDocument.getSelection();
2040
+ const node = selection?.focusNode;
2041
+ if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
2042
+ const range = element.ownerDocument.createRange();
2043
+ const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
2044
+ if (start === -1) {
2045
+ range.selectNodeContents(node);
2046
+ } else {
2047
+ range.setStart(node, start);
2048
+ range.setEnd(node, start + data.length);
2049
+ }
2050
+ return range;
2051
+ };
2052
+ var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
2053
+ var rewritten = ({ element, text, nodes, spot }) => {
2054
+ if (spot !== null) {
2055
+ return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
2056
+ }
2057
+ const current = nodesOf(element);
2058
+ return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
2059
+ };
1922
2060
  var holdsFocus2 = (element) => element instanceof Node && element.getRootNode().activeElement === element;
1923
2061
  var CompositionTracker = class {
1924
2062
  #observedTargets = /* @__PURE__ */ new Set();
@@ -2009,11 +2147,11 @@ var CompositionTracker = class {
2009
2147
  }
2010
2148
  #settle() {
2011
2149
  const composition = this.#composition;
2012
- if (composition === null) return;
2013
- const { target, element, text } = composition;
2150
+ if (composition === null || !this.#observedTargets.has(composition.target)) return;
2151
+ const { target, element } = composition;
2014
2152
  if (target instanceof Node && element instanceof Node && !target.contains(element)) {
2015
2153
  this.#composition = null;
2016
- } else if (textOf(element) !== text) {
2154
+ } else if (rewritten(composition)) {
2017
2155
  this.#abandon(false);
2018
2156
  }
2019
2157
  }
@@ -2038,7 +2176,14 @@ var CompositionTracker = class {
2038
2176
  this.#owe(true);
2039
2177
  const target = event.currentTarget;
2040
2178
  const element = event.target;
2041
- this.#composition = { target, element, text: textOf(element) };
2179
+ this.#composition = {
2180
+ target,
2181
+ element,
2182
+ text: textOf(element),
2183
+ nodes: nodesOf(element),
2184
+ spot: spotOf(element, null, void 0),
2185
+ replaced: null
2186
+ };
2042
2187
  this.#runAbandon();
2043
2188
  this.#onStart?.(event);
2044
2189
  };
@@ -2062,6 +2207,10 @@ var CompositionTracker = class {
2062
2207
  if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
2063
2208
  this.#abandon(true);
2064
2209
  }
2210
+ const composition = this.#composition;
2211
+ if (composition !== null && event.target === composition.element) {
2212
+ composition.replaced = replacedBy(event);
2213
+ }
2065
2214
  this.#runAbandon();
2066
2215
  };
2067
2216
  #handleInput = (event) => {
@@ -2069,6 +2218,15 @@ var CompositionTracker = class {
2069
2218
  const { isTrusted, isComposing, inputType } = event;
2070
2219
  if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
2071
2220
  composition.text = textOf(composition.element);
2221
+ composition.nodes = nodesOf(composition.element);
2222
+ if (isCompositionInputType(inputType)) {
2223
+ composition.spot = spotOf(
2224
+ composition.element,
2225
+ composition.replaced,
2226
+ event.data
2227
+ );
2228
+ }
2229
+ composition.replaced = null;
2072
2230
  } else {
2073
2231
  this.#settle();
2074
2232
  }
@@ -2089,7 +2247,9 @@ var CompositionTracker = class {
2089
2247
  const composition = this.#composition;
2090
2248
  if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
2091
2249
  const detail = event.detail;
2092
- if (detail?.attributeName === "value") event.preventDefault();
2250
+ if (detail?.attributeName === "value" && "value" in composition.element) {
2251
+ event.preventDefault();
2252
+ }
2093
2253
  };
2094
2254
  };
2095
2255
 
@@ -2633,10 +2793,6 @@ var BulkSelectController = class _BulkSelectController extends Controller {
2633
2793
  }
2634
2794
  clear() {
2635
2795
  for (const item of this.itemTargets) item.checked = false;
2636
- if (this.hasAllTarget) {
2637
- this.allTarget.checked = false;
2638
- this.allTarget.indeterminate = false;
2639
- }
2640
2796
  this.#exitAllPages();
2641
2797
  this.#reportChange(this.#recompute());
2642
2798
  }
@@ -5735,6 +5891,7 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
5735
5891
  return this.hasDialogTarget && !this.dialogTarget.hidden;
5736
5892
  }
5737
5893
  #onGlobalKeydown = (event) => {
5894
+ if (event.defaultPrevented) return;
5738
5895
  if (this.#composition.isComposing(event) || !this.#matchesHotkey(event)) return;
5739
5896
  event.preventDefault();
5740
5897
  this.toggle();
@@ -5780,43 +5937,66 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
5780
5937
 
5781
5938
  var AuthoredMutationWatcher = class {
5782
5939
  #onAuthored;
5783
- #claims = null;
5784
- #observer = null;
5940
+ #lifetime = null;
5785
5941
  constructor(onAuthored) {
5786
5942
  this.#onAuthored = onAuthored;
5787
5943
  }
5788
5944
  observe(root, options) {
5789
- this.disconnect();
5790
- const observer = new MutationObserver((records) => {
5791
- if (this.#observer !== observer) return;
5792
- const authored = this.#filter(records);
5793
- if (authored.length > 0) this.#onAuthored(authored);
5794
- });
5795
- this.#observer = observer;
5796
- this.#claims = { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() };
5797
- observer.observe(root, {
5798
- attributes: true,
5799
- attributeFilter: [...options.attributes],
5800
- subtree: options.subtree ?? false,
5801
- childList: options.childList ?? false
5802
- });
5803
- if (options.ancestorAttributes) {
5804
- let ancestor = root.parentElement;
5805
- while (ancestor) {
5806
- observer.observe(ancestor, {
5807
- attributes: true,
5808
- attributeFilter: [...options.ancestorAttributes]
5809
- });
5810
- ancestor = ancestor.parentElement;
5945
+ const previous = this.#lifetime;
5946
+ const lifetime = {
5947
+ observer: null,
5948
+ active: false,
5949
+ claims: { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() }
5950
+ };
5951
+ this.#lifetime = lifetime;
5952
+ let observer = null;
5953
+ try {
5954
+ if (previous) this.#release(previous);
5955
+ if (this.#lifetime !== lifetime) return;
5956
+ const attributes = [...options.attributes];
5957
+ const subtree = options.subtree ?? false;
5958
+ const childList = options.childList ?? false;
5959
+ const inherited = options.ancestorAttributes;
5960
+ const ancestorAttributes = inherited ? [...inherited] : null;
5961
+ if (this.#lifetime !== lifetime) return;
5962
+ observer = new MutationObserver((records) => {
5963
+ const authored = this.#filter(records, lifetime.claims);
5964
+ if (this.#lifetime === lifetime && lifetime.active && authored.length > 0) {
5965
+ this.#onAuthored(authored);
5966
+ }
5967
+ });
5968
+ if (this.#lifetime !== lifetime) return;
5969
+ lifetime.observer = observer;
5970
+ observer.observe(root, { attributes: true, attributeFilter: attributes, subtree, childList });
5971
+ if (this.#lifetime !== lifetime) {
5972
+ this.#release(lifetime, observer);
5973
+ return;
5974
+ }
5975
+ if (ancestorAttributes) {
5976
+ let ancestor = root.parentElement;
5977
+ while (ancestor) {
5978
+ observer.observe(ancestor, { attributes: true, attributeFilter: ancestorAttributes });
5979
+ if (this.#lifetime !== lifetime) {
5980
+ this.#release(lifetime, observer);
5981
+ return;
5982
+ }
5983
+ ancestor = ancestor.parentElement;
5984
+ }
5811
5985
  }
5986
+ lifetime.active = true;
5987
+ } catch (error) {
5988
+ this.#release(lifetime, observer);
5989
+ throw error;
5812
5990
  }
5813
5991
  }
5814
5992
  claim(target, name, value) {
5815
- const claims = this.#claims?.attributes;
5816
- let attributes = claims?.get(target);
5993
+ const lifetime = this.#lifetime;
5994
+ if (!lifetime?.active) return;
5995
+ const claims = lifetime.claims.attributes;
5996
+ let attributes = claims.get(target);
5817
5997
  if (!attributes) {
5818
5998
  attributes = /* @__PURE__ */ new Map();
5819
- claims?.set(target, attributes);
5999
+ claims.set(target, attributes);
5820
6000
  }
5821
6001
  const pending = attributes.get(name);
5822
6002
  attributes.set(name, { value, count: (pending?.count ?? 0) + 1 });
@@ -5825,37 +6005,49 @@ var AuthoredMutationWatcher = class {
5825
6005
  this.claim(target, name, target.getAttribute(name));
5826
6006
  }
5827
6007
  claimChildList(target, added, removed) {
5828
- const claims = this.#claims?.children;
5829
- const pending = claims?.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
6008
+ const lifetime = this.#lifetime;
6009
+ if (!lifetime?.active) return;
6010
+ const claims = lifetime.claims.children;
6011
+ const pending = claims.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
5830
6012
  for (const node of added) pending.added.set(node, (pending.added.get(node) ?? 0) + 1);
5831
6013
  for (const node of removed) pending.removed.set(node, (pending.removed.get(node) ?? 0) + 1);
5832
- claims?.set(target, pending);
6014
+ claims.set(target, pending);
5833
6015
  }
5834
6016
  take() {
5835
- return this.#filter(this.#observer?.takeRecords() ?? []);
6017
+ const lifetime = this.#lifetime;
6018
+ const observer = lifetime?.observer;
6019
+ if (!lifetime?.active || !observer) return [];
6020
+ const records = observer.takeRecords();
6021
+ const authored = this.#filter(records, lifetime.claims);
6022
+ return this.#lifetime === lifetime && lifetime.active ? authored : [];
5836
6023
  }
5837
6024
  disconnect() {
5838
- this.#observer?.disconnect();
5839
- this.#observer = null;
5840
- this.#claims = null;
5841
- }
5842
- #filter(records) {
5843
- const authored = records.filter((record) => !this.#consume(record));
5844
- this.#claims?.attributes.clear();
5845
- this.#claims?.children.clear();
6025
+ const lifetime = this.#lifetime;
6026
+ if (lifetime) this.#release(lifetime);
6027
+ }
6028
+ #release(lifetime, observer = lifetime.observer) {
6029
+ if (this.#lifetime === lifetime) this.#lifetime = null;
6030
+ lifetime.claims.attributes.clear();
6031
+ lifetime.claims.children.clear();
6032
+ observer?.disconnect();
6033
+ }
6034
+ #filter(records, claims) {
6035
+ const authored = records.filter((record) => !this.#consume(record, claims));
6036
+ claims.attributes.clear();
6037
+ claims.children.clear();
5846
6038
  return authored;
5847
6039
  }
5848
- #consume(record) {
6040
+ #consume(record, claims) {
5849
6041
  if (record.type === "attributes") {
5850
6042
  const target = record.target;
5851
- const pending2 = this.#claims?.attributes.get(target)?.get(record.attributeName);
6043
+ const pending2 = claims.attributes.get(target)?.get(record.attributeName);
5852
6044
  if (!pending2 || pending2.count === 0 || target.getAttribute(record.attributeName) !== pending2.value) {
5853
6045
  return false;
5854
6046
  }
5855
6047
  pending2.count -= 1;
5856
6048
  return true;
5857
6049
  }
5858
- const pending = this.#claims?.children.get(record.target);
6050
+ const pending = claims.children.get(record.target);
5859
6051
  if (!pending) return false;
5860
6052
  const added = [...record.addedNodes];
5861
6053
  const removed = [...record.removedNodes];
@@ -8045,7 +8237,8 @@ var DateRangePickerController = class extends Controller {
8045
8237
  if (!el || !date) continue;
8046
8238
  const iso = toISODateString(date);
8047
8239
  el.setAttribute("data-date", iso);
8048
- el.textContent = String(date.getDate());
8240
+ const dayText = String(date.getDate());
8241
+ if (el.textContent !== dayText) el.textContent = dayText;
8049
8242
  el.setAttribute("data-outside", String(date.getMonth() !== month - 1));
8050
8243
  el.setAttribute("data-today", String(iso === todayStr));
8051
8244
  el.setAttribute("tabindex", iso === focusedStr ? "0" : "-1");
@@ -8319,10 +8512,6 @@ function matchingPart(root, selector) {
8319
8512
  return root.matches(selector) ? root : root.querySelector(selector);
8320
8513
  }
8321
8514
  function writeLabel(slot, text) {
8322
- if (slot.childElementCount === 0) {
8323
- slot.textContent = text;
8324
- return;
8325
- }
8326
8515
  let first = null;
8327
8516
  for (const node of Array.from(slot.childNodes)) {
8328
8517
  if (node.nodeType !== Node.TEXT_NODE) continue;
@@ -9037,6 +9226,8 @@ var DismissibleController = class extends Controller {
9037
9226
  if (document.activeElement === candidate) return;
9038
9227
  }
9039
9228
  document.body.focus();
9229
+ const remaining = document.activeElement;
9230
+ if (remaining instanceof HTMLElement && root.contains(remaining)) remaining.blur();
9040
9231
  }
9041
9232
  *#focusFallbacks(root) {
9042
9233
  const explicitFallback = this.hasFallbackTarget ? this.fallbackTarget : null;
@@ -9482,6 +9673,7 @@ var EditableController = class extends Controller {
9482
9673
  this.#revertValue = null;
9483
9674
  }
9484
9675
  onDisplayKeydown(event) {
9676
+ if (event.defaultPrevented) return;
9485
9677
  if (event.key === "F2") {
9486
9678
  event.preventDefault();
9487
9679
  this.edit();
@@ -10904,7 +11096,7 @@ var FormValidationController = class _FormValidationController extends Controlle
10904
11096
 
10905
11097
  var MinDurationFloor = class {
10906
11098
  #timers;
10907
- #timerId = null;
11099
+ #task = null;
10908
11100
  #since = 0;
10909
11101
  constructor(timers) {
10910
11102
  this.#timers = timers;
@@ -10913,25 +11105,19 @@ var MinDurationFloor = class {
10913
11105
  this.#since = Date.now();
10914
11106
  }
10915
11107
  get pending() {
10916
- return this.#timerId !== null;
11108
+ return this.#task?.pending ?? false;
10917
11109
  }
10918
11110
  schedule(minDuration, finish) {
10919
11111
  this.cancel();
10920
11112
  const remaining = minDuration - (Date.now() - this.#since);
10921
11113
  if (remaining > 0) {
10922
- this.#timerId = this.#timers.set(() => {
10923
- this.#timerId = null;
10924
- finish();
10925
- }, remaining);
11114
+ this.#task = this.#timers.setTask(finish, remaining);
10926
11115
  } else {
10927
11116
  finish();
10928
11117
  }
10929
11118
  }
10930
11119
  cancel() {
10931
- if (this.#timerId !== null) {
10932
- this.#timers.clear(this.#timerId);
10933
- this.#timerId = null;
10934
- }
11120
+ this.#task?.cancel();
10935
11121
  }
10936
11122
  };
10937
11123
 
@@ -10948,7 +11134,7 @@ var FrameLoadingController = class _FrameLoadingController extends Controller {
10948
11134
  minDuration: NUMBER_BOUNDS.timer
10949
11135
  };
10950
11136
  static events = ["start", "end", "reconcile"];
10951
- #timeouts = new SafeTimeout();
11137
+ #timeouts = new TaskTimeout();
10952
11138
  #floor = new MinDurationFloor(this.#timeouts);
10953
11139
  #gate = new DetachGate();
10954
11140
  #listeners = new ListenerSet();
@@ -11600,7 +11786,8 @@ function applyMask(value, pattern, tokens) {
11600
11786
  } else {
11601
11787
  masked += patternChar;
11602
11788
  tokenFlags.push(false);
11603
- if (halfWidthChar(value[valueIndex] ?? "") === halfWidthChar(patternChar)) valueIndex += 1;
11789
+ const literal = value.slice(valueIndex, valueIndex + patternChar.length);
11790
+ if (halfWidthChar(literal) === halfWidthChar(patternChar)) valueIndex += patternChar.length;
11604
11791
  }
11605
11792
  }
11606
11793
  return {
@@ -11636,14 +11823,16 @@ function deletionOf(event) {
11636
11823
  if (!inputType.startsWith("delete")) return null;
11637
11824
  return inputType.endsWith("Forward") ? "forward" : "backward";
11638
11825
  }
11639
- function tokenCharOffset(tokenFlags, n) {
11640
- let seen = 0;
11641
- for (let i = 0; i < tokenFlags.length; i += 1) {
11642
- if (!tokenFlags[i]) continue;
11643
- seen += 1;
11644
- if (seen === n) return i;
11645
- }
11646
- return -1;
11826
+ function tokenBoundary(pattern, tokenFlags, tokensBefore) {
11827
+ const characters = pattern[Symbol.iterator]();
11828
+ let offset = 0;
11829
+ for (const token of tokenFlags) {
11830
+ if (token && tokensBefore === 0) break;
11831
+ const character = characters.next().value ?? "";
11832
+ if (token) tokensBefore -= 1;
11833
+ offset += token ? 1 : character.length;
11834
+ }
11835
+ return offset;
11647
11836
  }
11648
11837
  var InputMaskController = class extends Controller {
11649
11838
  get #unmaskAttribute() {
@@ -11666,6 +11855,27 @@ var InputMaskController = class extends Controller {
11666
11855
  #textBeforeComposition = "";
11667
11856
  #formatted = null;
11668
11857
  #shown = { result: null, empty: true };
11858
+ #edits = new ListenerSet();
11859
+ #onBeforeInput = (event) => {
11860
+ const data = event.data;
11861
+ if (event.defaultPrevented || !event.cancelable || event.inputType !== "insertText" || data === null || Array.from(data).length !== 1 || !this.#started || this.#composition.isComposing(event))
11862
+ return;
11863
+ const input = this.element;
11864
+ const start = input.selectionStart;
11865
+ const end = input.selectionEnd;
11866
+ if (start === null || end === null || start === end || input.readOnly || input.disabled || inheritsFieldsetDisabled(input) || !input.isConnected || !this.application.element.contains(input) || !(input.getAttribute("data-controller") ?? "").split(/\s+/).includes(this.identifier) || this.patternValue === "" || this.#formatted !== this.#declared || input.value !== this.#lastValue)
11867
+ return;
11868
+ const prefix = applyMask(input.value.slice(0, start), this.patternValue, this.#tokens);
11869
+ for (const character of Array.from(this.patternValue).slice(prefix.tokenFlags.length)) {
11870
+ const token = this.#tokens.get(character);
11871
+ if (token) {
11872
+ if (acceptedForm(token, data) === null) event.preventDefault();
11873
+ return;
11874
+ }
11875
+ if (halfWidthChar(data) === halfWidthChar(character)) return;
11876
+ }
11877
+ event.preventDefault();
11878
+ };
11669
11879
  #composition = new CompositionTracker({
11670
11880
  onStart: () => {
11671
11881
  this.#textBeforeComposition = this.element.value;
@@ -11701,6 +11911,7 @@ var InputMaskController = class extends Controller {
11701
11911
  this.#morph.observe(this.element);
11702
11912
  this.#started = true;
11703
11913
  this.#composition.observe(this.element);
11914
+ this.#edits.add(this.element, "beforeinput", this.#onBeforeInput);
11704
11915
  if (!this.unmaskToHiddenValue) this.#withdraw();
11705
11916
  if (this.#composition.isComposing()) {
11706
11917
  this.#reformat("reconcile");
@@ -11715,6 +11926,7 @@ var InputMaskController = class extends Controller {
11715
11926
  disconnect() {
11716
11927
  this.#morph.disconnect();
11717
11928
  this.#started = false;
11929
+ this.#edits.dispose();
11718
11930
  this.#composition.disconnect();
11719
11931
  this.#adoption.clearAll();
11720
11932
  this.#gate.disconnected(this, () => this.#retractRaw());
@@ -11744,8 +11956,8 @@ var InputMaskController = class extends Controller {
11744
11956
  let result = applyMask(raw, this.patternValue, this.#tokens);
11745
11957
  if (deletion !== null && result.masked === this.#lastValue) {
11746
11958
  const target = deletion === "backward" ? anchor : anchor + 1;
11747
- const offset = tokenCharOffset(result.tokenFlags, target);
11748
- if (offset >= 0) {
11959
+ const offset = tokenBoundary(this.patternValue, result.tokenFlags, target - 1);
11960
+ if (offset < result.masked.length) {
11749
11961
  anchor = target - 1;
11750
11962
  result = applyMask(
11751
11963
  result.masked.slice(0, offset) + result.masked.slice(offset + 1),
@@ -11761,7 +11973,7 @@ var InputMaskController = class extends Controller {
11761
11973
  }
11762
11974
  if (input.value !== result.masked) {
11763
11975
  input.value = result.masked;
11764
- this.#restoreCaret(result.tokenFlags, anchor);
11976
+ this.#restoreCaret(tokenBoundary(this.patternValue, result.tokenFlags, anchor));
11765
11977
  }
11766
11978
  this.#publish(result, result.masked);
11767
11979
  if (result.masked === this.#lastValue) return;
@@ -11823,22 +12035,7 @@ var InputMaskController = class extends Controller {
11823
12035
  #significantBefore(prefix) {
11824
12036
  return applyMask(prefix, this.patternValue, this.#tokens).unmasked.length;
11825
12037
  }
11826
- #restoreCaret(tokenFlags, n) {
11827
- let position;
11828
- if (n <= 0) {
11829
- let i = 0;
11830
- while (i < tokenFlags.length && !tokenFlags[i]) i += 1;
11831
- position = i;
11832
- } else {
11833
- const offset = tokenCharOffset(tokenFlags, n);
11834
- if (offset < 0) {
11835
- position = tokenFlags.length;
11836
- } else {
11837
- let j = offset + 1;
11838
- while (j < tokenFlags.length && !tokenFlags[j]) j += 1;
11839
- position = j;
11840
- }
11841
- }
12038
+ #restoreCaret(position) {
11842
12039
  try {
11843
12040
  this.element.setSelectionRange(position, position);
11844
12041
  } catch {
@@ -11888,70 +12085,102 @@ function queryRoot(selector) {
11888
12085
  }
11889
12086
  var IntersectionWatcher = class {
11890
12087
  #onEntries;
11891
- #observer = null;
11892
- #active = false;
11893
- #usingPlatformDefaults = false;
12088
+ #session = null;
11894
12089
  constructor(onEntries) {
11895
12090
  this.#onEntries = onEntries;
11896
12091
  }
11897
12092
  get active() {
11898
- return this.#active;
12093
+ return this.#session?.active ?? false;
11899
12094
  }
11900
12095
  get usingPlatformDefaults() {
11901
- return this.#usingPlatformDefaults;
12096
+ return this.#session?.usingPlatformDefaults ?? false;
11902
12097
  }
11903
12098
  start(targets, options = {}) {
11904
- this.stop();
11905
- if (typeof IntersectionObserver === "undefined") return false;
11906
- const list = Array.isArray(targets) ? targets : [targets];
11907
- if (list.length === 0) return false;
11908
- const root = "root" in options ? options.root ?? null : queryRoot(options.rootSelector);
12099
+ const previous = this.#session;
12100
+ const session = {
12101
+ observer: null,
12102
+ active: false,
12103
+ usingPlatformDefaults: false
12104
+ };
12105
+ this.#session = session;
11909
12106
  let observer = null;
11910
12107
  try {
12108
+ if (previous) this.#release(previous);
12109
+ if (this.#session !== session) return false;
12110
+ if (typeof IntersectionObserver === "undefined") return false;
12111
+ const list = Array.isArray(targets) ? targets : [targets];
12112
+ const empty = list.length === 0;
12113
+ if (this.#session !== session) return false;
12114
+ if (empty) return false;
12115
+ const root = "root" in options ? options.root ?? null : queryRoot(options.rootSelector);
12116
+ if (this.#session !== session) return false;
11911
12117
  const onEntries = (entries) => {
11912
- if (this.#active && this.#observer === observer) this.#onEntries(entries);
12118
+ if (this.#session === session && session.active) this.#onEntries(entries);
11913
12119
  };
12120
+ let usingPlatformDefaults = false;
11914
12121
  try {
11915
- observer = new IntersectionObserver(onEntries, {
12122
+ const configured = {
11916
12123
  root,
11917
12124
  rootMargin: options.rootMargin,
11918
12125
  threshold: options.threshold
11919
- });
12126
+ };
12127
+ if (this.#session !== session) return false;
12128
+ observer = new IntersectionObserver(onEntries, configured);
11920
12129
  } catch (error) {
12130
+ if (this.#session !== session) return false;
11921
12131
  console.warn(
11922
12132
  "Stimeo UI: IntersectionObserver could not be constructed with the configured options; retrying with platform defaults.",
11923
12133
  error
11924
12134
  );
12135
+ if (this.#session !== session) return false;
11925
12136
  observer = new IntersectionObserver(onEntries, { root });
11926
- this.#usingPlatformDefaults = true;
12137
+ usingPlatformDefaults = true;
11927
12138
  }
11928
- for (const target of list) observer.observe(target);
11929
- this.#observer = observer;
11930
- this.#active = true;
12139
+ if (this.#session !== session) {
12140
+ this.#release(session, observer);
12141
+ return false;
12142
+ }
12143
+ session.observer = observer;
12144
+ for (const target of list) {
12145
+ if (this.#session !== session) return false;
12146
+ observer.observe(target);
12147
+ if (this.#session !== session) {
12148
+ this.#release(session, observer);
12149
+ return false;
12150
+ }
12151
+ }
12152
+ if (this.#session !== session) return false;
12153
+ session.usingPlatformDefaults = usingPlatformDefaults;
12154
+ session.active = true;
11931
12155
  return true;
11932
12156
  } catch (error) {
11933
- observer?.disconnect();
11934
- this.#observer = null;
11935
- this.#active = false;
11936
- this.#usingPlatformDefaults = false;
12157
+ this.#release(session, observer);
11937
12158
  throw error;
11938
12159
  }
11939
12160
  }
11940
12161
  rearm(target) {
11941
- if (!this.#observer) return;
12162
+ const session = this.#session;
12163
+ const observer = session?.observer;
12164
+ if (!session?.active || !observer) return;
11942
12165
  try {
11943
- this.#observer.unobserve(target);
11944
- this.#observer.observe(target);
12166
+ observer.unobserve(target);
12167
+ if (this.#session !== session) return;
12168
+ observer.observe(target);
12169
+ if (this.#session !== session) this.#release(session, observer);
11945
12170
  } catch (error) {
11946
- this.stop();
12171
+ if (this.#session === session) this.#session = null;
12172
+ this.#release(session, observer);
11947
12173
  throw error;
11948
12174
  }
11949
12175
  }
11950
12176
  stop() {
11951
- this.#active = false;
11952
- this.#observer?.disconnect();
11953
- this.#observer = null;
11954
- this.#usingPlatformDefaults = false;
12177
+ const session = this.#session;
12178
+ this.#session = null;
12179
+ if (session) this.#release(session);
12180
+ }
12181
+ #release(session, observer = session.observer) {
12182
+ session.observer = null;
12183
+ observer?.disconnect();
11955
12184
  }
11956
12185
  };
11957
12186
 
@@ -12197,7 +12426,6 @@ var Typeahead = class {
12197
12426
  #timers = new SafeTimeout();
12198
12427
  #resetMs;
12199
12428
  #query = "";
12200
- #timerId = 0;
12201
12429
  constructor({ resetMs = TYPEAHEAD_RESET_MS } = {}) {
12202
12430
  this.#resetMs = resetMs;
12203
12431
  }
@@ -12208,14 +12436,13 @@ var Typeahead = class {
12208
12436
  const char = key.toLowerCase();
12209
12437
  const repeated = this.#query.length > 0 && [...this.#query].every((c) => c === char);
12210
12438
  this.#query = repeated ? char : this.#query + char;
12211
- this.#timers.clear(this.#timerId);
12212
- this.#timerId = this.#timers.set(() => this.reset(), this.#resetMs);
12439
+ this.#timers.clearAll();
12440
+ this.#timers.set(() => this.reset(), this.#resetMs);
12213
12441
  return this.#query;
12214
12442
  }
12215
12443
  reset() {
12216
12444
  this.#query = "";
12217
- this.#timers.clear(this.#timerId);
12218
- this.#timerId = 0;
12445
+ this.#timers.clearAll();
12219
12446
  }
12220
12447
  };
12221
12448
  function isTypeaheadKey(event) {
@@ -12636,13 +12863,7 @@ function readDatetime(element) {
12636
12863
  const minute = Number(minuteText);
12637
12864
  const second = Number(secondText);
12638
12865
  if (hour === 24 && (minute !== 0 || second !== 0 || /[1-9]/.test(fraction))) return null;
12639
- let offset = zone;
12640
- if (zone !== "Z") {
12641
- const digits = zone.slice(1).replace(":", "");
12642
- const offsetHour = digits.slice(0, 2);
12643
- const offsetMinute = digits.slice(2);
12644
- offset = `${zone[0]}${offsetHour}:${offsetMinute}`;
12645
- }
12866
+ const offset = zone.replace(/^([+-]\d{2})(\d{2})$/, "$1:$2");
12646
12867
  const milliseconds = fraction.slice(0, 3).padEnd(3, "0");
12647
12868
  const canonical = `${yearText}-${monthText}-${dayText}T${hourText}:${minuteText}:${secondText}.${milliseconds}${offset}`;
12648
12869
  const instant = Date.parse(canonical);
@@ -13885,7 +14106,9 @@ var MultiSelectController = class _MultiSelectController extends Controller {
13885
14106
  focusAfterEnd: () => this.#focusInput()
13886
14107
  });
13887
14108
  #listeners = new ListenerSet();
14109
+ #tab = null;
13888
14110
  connect() {
14111
+ this.#tab = null;
13889
14112
  this.#tabindex.reclaim(this.element);
13890
14113
  this.#rows.connect();
13891
14114
  this.#normalizeSelection([]);
@@ -13897,6 +14120,9 @@ var MultiSelectController = class _MultiSelectController extends Controller {
13897
14120
  this.#selectionValues = this.#values;
13898
14121
  this.#syncFields();
13899
14122
  this.#listeners.add(document, "click", this.#onOutsideClick, { capture: true });
14123
+ this.#listeners.add(this.element, "keydown", this.#onTab);
14124
+ for (const type of ["focus", "keydown", "keyup", "pointerdown"])
14125
+ this.#listeners.add(document, type, this.#trackTab, { capture: true });
13900
14126
  this.#connected = true;
13901
14127
  this.#reconcile.observe(this.element);
13902
14128
  }
@@ -13918,6 +14144,7 @@ var MultiSelectController = class _MultiSelectController extends Controller {
13918
14144
  this.#composition.disconnect();
13919
14145
  this.#chipRow.disconnect();
13920
14146
  this.#listeners.dispose();
14147
+ this.#tab = null;
13921
14148
  this.#releaseTabindex();
13922
14149
  }
13923
14150
  optionTargetConnected() {
@@ -14087,7 +14314,11 @@ var MultiSelectController = class _MultiSelectController extends Controller {
14087
14314
  this.#setActive(visible[0] ?? null);
14088
14315
  this.dispatch("filter", { detail: { query } });
14089
14316
  }
14090
- open() {
14317
+ open(event) {
14318
+ if (event instanceof FocusEvent && event === this.#tab) {
14319
+ this.#tab = null;
14320
+ return;
14321
+ }
14091
14322
  if (!this.hasListTarget || !this.hasInputTarget) {
14092
14323
  this.#reflectEmpty();
14093
14324
  return;
@@ -14174,6 +14405,16 @@ var MultiSelectController = class _MultiSelectController extends Controller {
14174
14405
  break;
14175
14406
  }
14176
14407
  }
14408
+ #onTab = (event) => {
14409
+ if (event.key !== "Tab" || event.defaultPrevented || event.isComposing || !this.hasTagsTarget || !this.tagsTarget.contains(event.target))
14410
+ return;
14411
+ this.#tab = event;
14412
+ this.close();
14413
+ };
14414
+ #trackTab = (event) => {
14415
+ const key = this.#tab;
14416
+ this.#tab = event.type === "focus" && key instanceof KeyboardEvent && !key.defaultPrevented && event.target === this.inputTargets[0] ? event : null;
14417
+ };
14177
14418
  toggleOption(source) {
14178
14419
  const { event, host, origin, reason } = actionSource(source);
14179
14420
  if (origin && origin.closest(`[data-controller~="${this.identifier}"]`) !== this.element)
@@ -14280,14 +14521,17 @@ var MultiSelectController = class _MultiSelectController extends Controller {
14280
14521
  tag?.remove();
14281
14522
  }
14282
14523
  #removeTagAt(index, focus = "neighbor") {
14283
- const tag = this.tagTargets[index];
14524
+ const tags = this.tagTargets;
14525
+ const tag = tags[index];
14284
14526
  if (!tag) return;
14527
+ const afterFocus2 = focus === "neighbor" && tags.length === 1 && this.hasInputTarget;
14285
14528
  const value = tag.dataset.value ?? "";
14286
14529
  const option = this.optionTargets.find((candidate) => this.#optionValue(candidate) === value);
14287
14530
  if (option) option.setAttribute("aria-selected", "false");
14288
14531
  tag.remove();
14289
14532
  this.#refreshRoving();
14290
- if (!this.#publishSelection(false, option ? this.#optionLabel(option) : value, value)) return;
14533
+ const label = option ? this.#optionLabel(option) : value;
14534
+ if (!this.#publishSelection(false, label, value, "user", afterFocus2)) return;
14291
14535
  if (focus === "input") {
14292
14536
  this.#focusInput();
14293
14537
  return;
@@ -14324,7 +14568,7 @@ var MultiSelectController = class _MultiSelectController extends Controller {
14324
14568
  const options = { name: this.nameValue, form: this.formValue };
14325
14569
  return writeFields(this.fieldsTarget, this.#values, options);
14326
14570
  }
14327
- #publishSelection(selected, label, value, reason = "user") {
14571
+ #publishSelection(selected, label, value, reason = "user", afterFocus2 = false) {
14328
14572
  const values = this.#values;
14329
14573
  const changed = !this.#sameSelection(this.#selectionValues, values);
14330
14574
  const fieldChanged = this.#syncFields();
@@ -14333,7 +14577,7 @@ var MultiSelectController = class _MultiSelectController extends Controller {
14333
14577
  const token = this.#moves.record();
14334
14578
  if (fieldChanged) commitField(this.fieldsTarget);
14335
14579
  if (!this.#moves.isLatest(token)) return false;
14336
- this.#announceTransition(selected, label, value, values.length);
14580
+ this.#announceTransition(selected, label, value, values.length, afterFocus2);
14337
14581
  if (!this.#moves.isLatest(token)) return false;
14338
14582
  this.dispatch("change", { detail: { values, reason } });
14339
14583
  return this.#moves.isLatest(token);
@@ -14341,9 +14585,9 @@ var MultiSelectController = class _MultiSelectController extends Controller {
14341
14585
  #refreshRoving() {
14342
14586
  this.#chipRow.ensureTabStop();
14343
14587
  }
14344
- #announceTransition(selected, label, value, count) {
14588
+ #announceTransition(selected, label, value, count, afterFocus2 = false) {
14345
14589
  const template = selected ? this.announceTextValue : this.announceRemovedTextValue;
14346
- announce(fillTemplate(template, { label, value, count }));
14590
+ announce(fillTemplate(template, { label, value, count }), { afterFocus: afterFocus2 });
14347
14591
  }
14348
14592
  #sameSelection(left, right) {
14349
14593
  if (left.length !== right.length) return false;
@@ -15013,25 +15257,22 @@ function snapSteppedValue(raw, range) {
15013
15257
  if (!(range.min <= range.max)) return finiteFallback(range.min, range.max);
15014
15258
  const input = Number.isNaN(raw) ? finiteFallback(range.min, range.max) : raw;
15015
15259
  const clamped = Math.min(range.max, Math.max(range.min, input));
15016
- const step = effectiveStep(range.step);
15017
- const base = stepBase(range);
15260
+ const grid = stepGrid(range);
15018
15261
  const candidates = [];
15019
15262
  if (Number.isFinite(range.min)) candidates.push(range.min);
15020
15263
  if (Number.isFinite(range.max)) candidates.push(range.max);
15021
- const gridPosition = (clamped - base) / step;
15022
- if (Number.isFinite(gridPosition)) {
15023
- addGridCandidate(candidates, Math.floor(gridPosition), range, base, step);
15024
- addGridCandidate(candidates, Math.ceil(gridPosition), range, base, step);
15264
+ const position = gridPosition(clamped, grid);
15265
+ if (Number.isFinite(position)) {
15266
+ for (const index of [Math.floor(position), Math.ceil(position)]) {
15267
+ const candidate = gridValue(index, grid);
15268
+ if (inRange(candidate, range)) candidates.push(candidate);
15269
+ }
15025
15270
  }
15026
15271
  if (candidates.length === 0) return clamped;
15027
15272
  let nearest = candidates[0];
15028
- let nearestDistance = Math.abs(clamped - nearest);
15029
15273
  for (const candidate of candidates.slice(1)) {
15030
- const distance = Math.abs(clamped - candidate);
15031
- if (distance < nearestDistance || nearlyEqual(distance, nearestDistance) && candidate > nearest) {
15032
- nearest = candidate;
15033
- nearestDistance = distance;
15034
- }
15274
+ const nearer = isMidpoint(clamped, candidate, nearest, range, grid) ? candidate > nearest : Math.abs(clamped - candidate) < Math.abs(clamped - nearest);
15275
+ if (nearer) nearest = candidate;
15035
15276
  }
15036
15277
  return nearest;
15037
15278
  }
@@ -15040,46 +15281,36 @@ function stepSteppedValue(current, count, range) {
15040
15281
  const distance = Math.abs(Math.trunc(count));
15041
15282
  if (!Number.isFinite(distance) || distance === 0) return value;
15042
15283
  const direction = Math.sign(count);
15043
- const adjacent = adjacentSteppedValue(value, direction, range);
15284
+ const adjacent = nextGridValue(value, direction, range);
15285
+ if (adjacent === value) return value;
15044
15286
  const raw = adjacent + direction * (distance - 1) * effectiveStep(range.step);
15045
- return snapSteppedValue(raw, range);
15287
+ const endpoint = direction > 0 ? range.max : range.min;
15288
+ return Number.isFinite(raw) || Number.isFinite(endpoint) ? snapSteppedValue(raw, range) : value;
15289
+ }
15290
+ function nextGridValue(current, direction, range) {
15291
+ const grid = stepGrid(range);
15292
+ const position = gridPosition(current, grid);
15293
+ if (!Number.isFinite(position)) return current;
15294
+ const index = direction > 0 ? Math.floor(position) + 1 : Math.ceil(position) - 1;
15295
+ const first = gridValue(index, grid);
15296
+ if (direction * (first - current) > 0 && !sameGridValue(first, current, grid.step)) {
15297
+ return first;
15298
+ }
15299
+ const second = gridValue(index + direction, grid);
15300
+ return direction * (second - current) > 0 ? second : current;
15046
15301
  }
15047
- function adjacentSteppedValue(current, direction, range) {
15302
+ function stepGrid(range) {
15048
15303
  const step = effectiveStep(range.step);
15049
15304
  const base = stepBase(range);
15050
- const candidates = [];
15051
- if (direction > 0) {
15052
- const position2 = (current - base) / step;
15053
- if (Number.isFinite(position2)) {
15054
- let gridIndex = Math.floor(position2) + 1;
15055
- let candidate = cleanGridValue(base + gridIndex * step, base, step);
15056
- if (candidate < current || nearlyEqual(candidate, current)) {
15057
- gridIndex += 1;
15058
- candidate = cleanGridValue(base + gridIndex * step, base, step);
15059
- }
15060
- if (candidate > current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
15061
- candidates.push(clamp(candidate, range));
15062
- }
15063
- }
15064
- return clamp(Math.min(...candidates), range);
15065
- }
15066
- const position = (current - base) / step;
15067
- if (Number.isFinite(position)) {
15068
- let gridIndex = Math.ceil(position) - 1;
15069
- let candidate = cleanGridValue(base + gridIndex * step, base, step);
15070
- if (candidate > current || nearlyEqual(candidate, current)) {
15071
- gridIndex -= 1;
15072
- candidate = cleanGridValue(base + gridIndex * step, base, step);
15073
- }
15074
- if (candidate < current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
15075
- candidates.push(clamp(candidate, range));
15076
- }
15077
- }
15078
- return clamp(Math.max(...candidates), range);
15305
+ const near = base - Math.trunc(base / step) * step;
15306
+ const origin = cleanGridValue(Number.isFinite(near) ? near % step : base % step, base, step);
15307
+ return { step, base, origin };
15308
+ }
15309
+ function gridPosition(value, grid) {
15310
+ return value / grid.step - grid.origin / grid.step;
15079
15311
  }
15080
- function addGridCandidate(candidates, index, range, base, step) {
15081
- const candidate = cleanGridValue(base + index * step, base, step);
15082
- if (within(candidate, range.min, range.max)) candidates.push(clamp(candidate, range));
15312
+ function gridValue(index, grid) {
15313
+ return cleanGridValue(grid.origin + index * grid.step, grid.base, grid.step);
15083
15314
  }
15084
15315
  function stepBase(range) {
15085
15316
  if (range.base !== void 0 && Number.isFinite(range.base)) return range.base;
@@ -15095,15 +15326,46 @@ function decimalPlaces(value) {
15095
15326
  const exponent = exponentText === void 0 ? 0 : Number(exponentText);
15096
15327
  return Math.max(0, fractionLength - exponent);
15097
15328
  }
15098
- function within(value, min, max) {
15099
- return (value > min || nearlyEqual(value, min)) && (value < max || nearlyEqual(value, max));
15329
+ function inRange(value, range) {
15330
+ return Number.isFinite(value) && value >= range.min && value <= range.max;
15331
+ }
15332
+ function sameGridValue(left, right, step) {
15333
+ const rounding = Number.EPSILON * Math.max(Math.abs(left), Math.abs(right));
15334
+ return Math.abs(left - right) <= Math.min(rounding, step / 4);
15100
15335
  }
15101
- function clamp(value, range) {
15102
- return Math.min(range.max, Math.max(range.min, value));
15336
+ function isMidpoint(value, left, right, range, grid) {
15337
+ const imbalance = Math.abs(Math.abs(value - left) - Math.abs(value - right));
15338
+ const rounding = 4 * Number.EPSILON * Math.max(Math.abs(value), Math.abs(left), Math.abs(right));
15339
+ if (!(imbalance <= rounding)) return false;
15340
+ if (imbalance <= Math.abs(left - right) / 4) return true;
15341
+ const lower = Math.min(left, right);
15342
+ const upper = Math.max(left, right);
15343
+ return value > lower && value < upper && isDecimalMidpoint(value, lower, upper, range, grid);
15103
15344
  }
15104
- function nearlyEqual(left, right) {
15105
- const scale = Math.max(Math.abs(left), Math.abs(right));
15106
- return Number.isFinite(left) && Number.isFinite(right) && Math.abs(left - right) <= Number.EPSILON * scale;
15345
+ function isDecimalMidpoint(value, lower, upper, range, grid) {
15346
+ const raw = decimalParts(value);
15347
+ const base = decimalParts(grid.base);
15348
+ const step = decimalParts(grid.step);
15349
+ const min = decimalParts(lower);
15350
+ const max = decimalParts(upper);
15351
+ const place = Math.min(raw.place, base.place, step.place, min.place, max.place);
15352
+ const units = (part) => part.units * 10n ** BigInt(part.place - place);
15353
+ const origin = units(base);
15354
+ const stride = units(step);
15355
+ const rawUnits = units(raw);
15356
+ const remainder = (rawUnits - origin) % stride;
15357
+ const below = rawUnits - (remainder < 0n ? remainder + stride : remainder);
15358
+ const above = below + stride;
15359
+ const minUnits = units(min);
15360
+ const maxUnits = units(max);
15361
+ const lowerUnits = lower === range.min && minUnits > below ? minUnits : below;
15362
+ const upperUnits = upper === range.max && maxUnits < above ? maxUnits : above;
15363
+ return Number(`${lowerUnits}e${place}`) === lower && Number(`${upperUnits}e${place}`) === upper && Number(`${(lowerUnits + upperUnits) * 5n}e${place - 1}`) === value;
15364
+ }
15365
+ function decimalParts(value) {
15366
+ const [coefficient = "", exponent = "0"] = value.toString().split("e");
15367
+ const [whole = "", fraction = ""] = coefficient.split(".");
15368
+ return { units: BigInt(whole + fraction), place: Number(exponent) - fraction.length };
15107
15369
  }
15108
15370
  function finiteFallback(min, max) {
15109
15371
  if (Number.isFinite(min)) return min;
@@ -15302,16 +15564,17 @@ var NumberInputController = class _NumberInputController extends Controller {
15302
15564
  next = this.#safePageStep > 0 ? this.#currentValue() - this.#safePageStep : stepSteppedValue(this.#currentValue(), -10, this.#steppedRange);
15303
15565
  break;
15304
15566
  case "Home":
15305
- if (!Number.isFinite(this.#safeMin)) return;
15306
15567
  next = this.#safeMin;
15307
15568
  break;
15308
15569
  case "End":
15309
- if (!Number.isFinite(this.#safeMax)) return;
15310
15570
  next = this.#safeMax;
15311
15571
  break;
15312
15572
  default:
15313
15573
  return;
15314
15574
  }
15575
+ if (next === Number.POSITIVE_INFINITY) next = this.#safeMax;
15576
+ if (next === Number.NEGATIVE_INFINITY) next = this.#safeMin;
15577
+ if (!Number.isFinite(next)) return;
15315
15578
  event.preventDefault();
15316
15579
  this.#commit(next, true);
15317
15580
  }
@@ -15499,12 +15762,16 @@ var NumberInputController = class _NumberInputController extends Controller {
15499
15762
  }
15500
15763
  #updateButtons(value, range) {
15501
15764
  const move = this.#move;
15502
- for (const button of this.incrementTargets) {
15503
- this.#toggleButton(button, value < range.max, move);
15765
+ const increments = this.incrementTargets;
15766
+ const canIncrement = increments.length > 0 && value < range.max && stepSteppedValue(value, 1, range) > value;
15767
+ for (const button of increments) {
15768
+ this.#toggleButton(button, canIncrement, move);
15504
15769
  if (!this.#moves.isLatest(move)) return;
15505
15770
  }
15506
- for (const button of this.decrementTargets) {
15507
- this.#toggleButton(button, value > range.min, move);
15771
+ const decrements = this.decrementTargets;
15772
+ const canDecrement = decrements.length > 0 && value > range.min && stepSteppedValue(value, -1, range) < value;
15773
+ for (const button of decrements) {
15774
+ this.#toggleButton(button, canDecrement, move);
15508
15775
  if (!this.#moves.isLatest(move)) return;
15509
15776
  }
15510
15777
  }
@@ -17986,6 +18253,7 @@ var PointerDragController = class _PointerDragController extends Controller {
17986
18253
  #tabindex = new TabindexLoan("0", this.identifier, { preserveFocus: true });
17987
18254
  #pointer = null;
17988
18255
  #keyboard = null;
18256
+ #connected = false;
17989
18257
  #keyboardFocusSession = null;
17990
18258
  #listeners = new ListenerSet();
17991
18259
  #shadowFocus = new ListenerSet();
@@ -17999,6 +18267,7 @@ var PointerDragController = class _PointerDragController extends Controller {
17999
18267
  this.#reflectSession();
18000
18268
  });
18001
18269
  connect() {
18270
+ this.#connected = true;
18002
18271
  this.#morphRender.observe(this.element);
18003
18272
  if (!this.#pointer && !this.#keyboard) this.#followOutput = null;
18004
18273
  this.#gate.cancel();
@@ -18016,6 +18285,7 @@ var PointerDragController = class _PointerDragController extends Controller {
18016
18285
  }
18017
18286
  }
18018
18287
  disconnect() {
18288
+ this.#connected = false;
18019
18289
  this.#morphRender.disconnect();
18020
18290
  this.#listeners.dispose();
18021
18291
  this.#shadowFocus.dispose();
@@ -18042,7 +18312,9 @@ var PointerDragController = class _PointerDragController extends Controller {
18042
18312
  }
18043
18313
  handleTargetDisconnected(handle) {
18044
18314
  this.#restoreHandle(handle);
18045
- if (this.element.contains(handle)) return;
18315
+ if (!this.#connected) return;
18316
+ if (this.element.contains(handle) && (this.handleTargets.includes(handle) || DetachGate.isDetached(this)))
18317
+ return;
18046
18318
  const interrupted = this.#pointer?.handle === handle && this.#pointer.started ? this.#pointer.pointerType : this.#keyboard?.handle === handle ? "keyboard" : null;
18047
18319
  if (this.#pointer?.handle === handle) this.#endPointerSession();
18048
18320
  if (this.#keyboard?.handle === handle) this.#clearKeyboardSession();
@@ -18397,6 +18669,7 @@ var PopoverController = class extends Controller {
18397
18669
  this.#close("api");
18398
18670
  this.#listeners.add(document, "click", this.#onOutsideClick, { capture: true });
18399
18671
  this.#listeners.add(this.element, "focusout", this.#onFocusOut);
18672
+ this.#listeners.add(document, "focusin", this.#onDocumentFocusIn, { capture: true });
18400
18673
  this.#connected = true;
18401
18674
  this.#reporting = true;
18402
18675
  }
@@ -18503,6 +18776,14 @@ var PopoverController = class extends Controller {
18503
18776
  if (!(next instanceof Node) || this.element.contains(next)) return;
18504
18777
  this.#close("focus");
18505
18778
  };
18779
+ #onDocumentFocusIn = (event) => {
18780
+ if (!this.#closable) return;
18781
+ const target = event.target;
18782
+ if (!(target instanceof Node) || target === document.body || this.element.contains(target)) {
18783
+ return;
18784
+ }
18785
+ this.#close("focus");
18786
+ };
18506
18787
  get #isOpen() {
18507
18788
  return this.hasPanelTarget && !this.panelTarget.hidden;
18508
18789
  }
@@ -19308,11 +19589,7 @@ var RadioGroupController = class extends Controller {
19308
19589
  #releaseRadio(radio) {
19309
19590
  this.#managedRadios.delete(radio);
19310
19591
  const original = this.#originalTabindex.get(radio);
19311
- if (original === null) {
19312
- this.#writeAttribute(radio, "tabindex", null);
19313
- } else if (original !== void 0) {
19314
- this.#writeAttribute(radio, "tabindex", original);
19315
- }
19592
+ if (original !== void 0) this.#writeAttribute(radio, "tabindex", original);
19316
19593
  this.#originalTabindex.delete(radio);
19317
19594
  if (this.#ownedChecked.delete(radio)) {
19318
19595
  this.#writeAttribute(radio, "aria-checked", null);
@@ -22348,7 +22625,7 @@ var SkeletonController = class _SkeletonController extends Controller {
22348
22625
  };
22349
22626
  static actions = ["ready", "reset"];
22350
22627
  static events = ["ready"];
22351
- #timers = new SafeTimeout();
22628
+ #timers = new TaskTimeout();
22352
22629
  #floor = new MinDurationFloor(this.#timers);
22353
22630
  #gate = new DetachGate();
22354
22631
  #hidden = new AttributeLease("hidden", this.identifier);
@@ -22984,7 +23261,7 @@ var SpinnerController = class _SpinnerController extends Controller {
22984
23261
  };
22985
23262
  static actions = ["start", "stop"];
22986
23263
  static events = ["hide", "show", "timeout", "reconcile"];
22987
- #timers = new SafeTimeout();
23264
+ #timers = new TaskTimeout();
22988
23265
  #floor = new MinDurationFloor(this.#timers);
22989
23266
  #gate = new DetachGate();
22990
23267
  #busyLease = new AttributeLease("aria-busy", this.identifier);
@@ -24280,7 +24557,8 @@ var TagsInputController = class _TagsInputController extends Controller {
24280
24557
  const value = tag.dataset.value ?? "";
24281
24558
  tag.remove();
24282
24559
  const tags = this.#values;
24283
- if (!this.#publishTags(tags, false, value)) return;
24560
+ const afterFocus2 = focus === "neighbor" && tags.length === 0 && this.hasInputTarget;
24561
+ if (!this.#publishTags(tags, false, value, afterFocus2)) return;
24284
24562
  if (focus === "input") {
24285
24563
  this.#focusInput();
24286
24564
  return;
@@ -24304,7 +24582,7 @@ var TagsInputController = class _TagsInputController extends Controller {
24304
24582
  this.#chipRow.ensureTabStop();
24305
24583
  return fieldChanged;
24306
24584
  }
24307
- #publishTags(tags, added, value) {
24585
+ #publishTags(tags, added, value, afterFocus2 = false) {
24308
24586
  const changed = !this.#sameTags(this.#tagValues, tags);
24309
24587
  const fieldChanged = this.#syncState(tags);
24310
24588
  this.#tagValues = tags;
@@ -24312,7 +24590,7 @@ var TagsInputController = class _TagsInputController extends Controller {
24312
24590
  const token = this.#moves.record();
24313
24591
  if (fieldChanged) commitField(this.fieldsTarget);
24314
24592
  if (!this.#moves.isLatest(token)) return false;
24315
- this.#announceTransition(added, value, tags.length);
24593
+ this.#announceTransition(added, value, tags.length, afterFocus2);
24316
24594
  if (!this.#moves.isLatest(token)) return false;
24317
24595
  this.dispatch("change", { detail: { tags } });
24318
24596
  return this.#moves.isLatest(token);
@@ -24327,9 +24605,9 @@ var TagsInputController = class _TagsInputController extends Controller {
24327
24605
  this.dispatch("reconcile", { detail: { tags } });
24328
24606
  }
24329
24607
  }
24330
- #announceTransition(added, value, count) {
24608
+ #announceTransition(added, value, count, afterFocus2) {
24331
24609
  const template = added ? this.announceTextValue : this.announceRemovedTextValue;
24332
- announce(fillTemplate(template, { label: value, value, count }));
24610
+ announce(fillTemplate(template, { label: value, value, count }), { afterFocus: afterFocus2 });
24333
24611
  }
24334
24612
  #reject(value, reason) {
24335
24613
  this.dispatch("reject", { detail: { value, reason } });