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
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
  }
@@ -5781,43 +5937,66 @@ var CommandPaletteController = class _CommandPaletteController extends Controlle
5781
5937
 
5782
5938
  var AuthoredMutationWatcher = class {
5783
5939
  #onAuthored;
5784
- #claims = null;
5785
- #observer = null;
5940
+ #lifetime = null;
5786
5941
  constructor(onAuthored) {
5787
5942
  this.#onAuthored = onAuthored;
5788
5943
  }
5789
5944
  observe(root, options) {
5790
- this.disconnect();
5791
- const observer = new MutationObserver((records) => {
5792
- if (this.#observer !== observer) return;
5793
- const authored = this.#filter(records);
5794
- if (authored.length > 0) this.#onAuthored(authored);
5795
- });
5796
- this.#observer = observer;
5797
- this.#claims = { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() };
5798
- observer.observe(root, {
5799
- attributes: true,
5800
- attributeFilter: [...options.attributes],
5801
- subtree: options.subtree ?? false,
5802
- childList: options.childList ?? false
5803
- });
5804
- if (options.ancestorAttributes) {
5805
- let ancestor = root.parentElement;
5806
- while (ancestor) {
5807
- observer.observe(ancestor, {
5808
- attributes: true,
5809
- attributeFilter: [...options.ancestorAttributes]
5810
- });
5811
- 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;
5812
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
+ }
5985
+ }
5986
+ lifetime.active = true;
5987
+ } catch (error) {
5988
+ this.#release(lifetime, observer);
5989
+ throw error;
5813
5990
  }
5814
5991
  }
5815
5992
  claim(target, name, value) {
5816
- const claims = this.#claims?.attributes;
5817
- 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);
5818
5997
  if (!attributes) {
5819
5998
  attributes = /* @__PURE__ */ new Map();
5820
- claims?.set(target, attributes);
5999
+ claims.set(target, attributes);
5821
6000
  }
5822
6001
  const pending = attributes.get(name);
5823
6002
  attributes.set(name, { value, count: (pending?.count ?? 0) + 1 });
@@ -5826,37 +6005,49 @@ var AuthoredMutationWatcher = class {
5826
6005
  this.claim(target, name, target.getAttribute(name));
5827
6006
  }
5828
6007
  claimChildList(target, added, removed) {
5829
- const claims = this.#claims?.children;
5830
- 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() };
5831
6012
  for (const node of added) pending.added.set(node, (pending.added.get(node) ?? 0) + 1);
5832
6013
  for (const node of removed) pending.removed.set(node, (pending.removed.get(node) ?? 0) + 1);
5833
- claims?.set(target, pending);
6014
+ claims.set(target, pending);
5834
6015
  }
5835
6016
  take() {
5836
- 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 : [];
5837
6023
  }
5838
6024
  disconnect() {
5839
- this.#observer?.disconnect();
5840
- this.#observer = null;
5841
- this.#claims = null;
5842
- }
5843
- #filter(records) {
5844
- const authored = records.filter((record) => !this.#consume(record));
5845
- this.#claims?.attributes.clear();
5846
- 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();
5847
6038
  return authored;
5848
6039
  }
5849
- #consume(record) {
6040
+ #consume(record, claims) {
5850
6041
  if (record.type === "attributes") {
5851
6042
  const target = record.target;
5852
- const pending2 = this.#claims?.attributes.get(target)?.get(record.attributeName);
6043
+ const pending2 = claims.attributes.get(target)?.get(record.attributeName);
5853
6044
  if (!pending2 || pending2.count === 0 || target.getAttribute(record.attributeName) !== pending2.value) {
5854
6045
  return false;
5855
6046
  }
5856
6047
  pending2.count -= 1;
5857
6048
  return true;
5858
6049
  }
5859
- const pending = this.#claims?.children.get(record.target);
6050
+ const pending = claims.children.get(record.target);
5860
6051
  if (!pending) return false;
5861
6052
  const added = [...record.addedNodes];
5862
6053
  const removed = [...record.removedNodes];
@@ -8046,7 +8237,8 @@ var DateRangePickerController = class extends Controller {
8046
8237
  if (!el || !date) continue;
8047
8238
  const iso = toISODateString(date);
8048
8239
  el.setAttribute("data-date", iso);
8049
- el.textContent = String(date.getDate());
8240
+ const dayText = String(date.getDate());
8241
+ if (el.textContent !== dayText) el.textContent = dayText;
8050
8242
  el.setAttribute("data-outside", String(date.getMonth() !== month - 1));
8051
8243
  el.setAttribute("data-today", String(iso === todayStr));
8052
8244
  el.setAttribute("tabindex", iso === focusedStr ? "0" : "-1");
@@ -8320,10 +8512,6 @@ function matchingPart(root, selector) {
8320
8512
  return root.matches(selector) ? root : root.querySelector(selector);
8321
8513
  }
8322
8514
  function writeLabel(slot, text) {
8323
- if (slot.childElementCount === 0) {
8324
- slot.textContent = text;
8325
- return;
8326
- }
8327
8515
  let first = null;
8328
8516
  for (const node of Array.from(slot.childNodes)) {
8329
8517
  if (node.nodeType !== Node.TEXT_NODE) continue;
@@ -10908,7 +11096,7 @@ var FormValidationController = class _FormValidationController extends Controlle
10908
11096
 
10909
11097
  var MinDurationFloor = class {
10910
11098
  #timers;
10911
- #timerId = null;
11099
+ #task = null;
10912
11100
  #since = 0;
10913
11101
  constructor(timers) {
10914
11102
  this.#timers = timers;
@@ -10917,25 +11105,19 @@ var MinDurationFloor = class {
10917
11105
  this.#since = Date.now();
10918
11106
  }
10919
11107
  get pending() {
10920
- return this.#timerId !== null;
11108
+ return this.#task?.pending ?? false;
10921
11109
  }
10922
11110
  schedule(minDuration, finish) {
10923
11111
  this.cancel();
10924
11112
  const remaining = minDuration - (Date.now() - this.#since);
10925
11113
  if (remaining > 0) {
10926
- this.#timerId = this.#timers.set(() => {
10927
- this.#timerId = null;
10928
- finish();
10929
- }, remaining);
11114
+ this.#task = this.#timers.setTask(finish, remaining);
10930
11115
  } else {
10931
11116
  finish();
10932
11117
  }
10933
11118
  }
10934
11119
  cancel() {
10935
- if (this.#timerId !== null) {
10936
- this.#timers.clear(this.#timerId);
10937
- this.#timerId = null;
10938
- }
11120
+ this.#task?.cancel();
10939
11121
  }
10940
11122
  };
10941
11123
 
@@ -10952,7 +11134,7 @@ var FrameLoadingController = class _FrameLoadingController extends Controller {
10952
11134
  minDuration: NUMBER_BOUNDS.timer
10953
11135
  };
10954
11136
  static events = ["start", "end", "reconcile"];
10955
- #timeouts = new SafeTimeout();
11137
+ #timeouts = new TaskTimeout();
10956
11138
  #floor = new MinDurationFloor(this.#timeouts);
10957
11139
  #gate = new DetachGate();
10958
11140
  #listeners = new ListenerSet();
@@ -11604,7 +11786,8 @@ function applyMask(value, pattern, tokens) {
11604
11786
  } else {
11605
11787
  masked += patternChar;
11606
11788
  tokenFlags.push(false);
11607
- 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;
11608
11791
  }
11609
11792
  }
11610
11793
  return {
@@ -11640,14 +11823,16 @@ function deletionOf(event) {
11640
11823
  if (!inputType.startsWith("delete")) return null;
11641
11824
  return inputType.endsWith("Forward") ? "forward" : "backward";
11642
11825
  }
11643
- function tokenCharOffset(tokenFlags, n) {
11644
- let seen = 0;
11645
- for (let i = 0; i < tokenFlags.length; i += 1) {
11646
- if (!tokenFlags[i]) continue;
11647
- seen += 1;
11648
- if (seen === n) return i;
11649
- }
11650
- 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;
11651
11836
  }
11652
11837
  var InputMaskController = class extends Controller {
11653
11838
  get #unmaskAttribute() {
@@ -11771,8 +11956,8 @@ var InputMaskController = class extends Controller {
11771
11956
  let result = applyMask(raw, this.patternValue, this.#tokens);
11772
11957
  if (deletion !== null && result.masked === this.#lastValue) {
11773
11958
  const target = deletion === "backward" ? anchor : anchor + 1;
11774
- const offset = tokenCharOffset(result.tokenFlags, target);
11775
- if (offset >= 0) {
11959
+ const offset = tokenBoundary(this.patternValue, result.tokenFlags, target - 1);
11960
+ if (offset < result.masked.length) {
11776
11961
  anchor = target - 1;
11777
11962
  result = applyMask(
11778
11963
  result.masked.slice(0, offset) + result.masked.slice(offset + 1),
@@ -11788,7 +11973,7 @@ var InputMaskController = class extends Controller {
11788
11973
  }
11789
11974
  if (input.value !== result.masked) {
11790
11975
  input.value = result.masked;
11791
- this.#restoreCaret(result.tokenFlags, anchor);
11976
+ this.#restoreCaret(tokenBoundary(this.patternValue, result.tokenFlags, anchor));
11792
11977
  }
11793
11978
  this.#publish(result, result.masked);
11794
11979
  if (result.masked === this.#lastValue) return;
@@ -11850,22 +12035,7 @@ var InputMaskController = class extends Controller {
11850
12035
  #significantBefore(prefix) {
11851
12036
  return applyMask(prefix, this.patternValue, this.#tokens).unmasked.length;
11852
12037
  }
11853
- #restoreCaret(tokenFlags, n) {
11854
- let position;
11855
- if (n <= 0) {
11856
- let i = 0;
11857
- while (i < tokenFlags.length && !tokenFlags[i]) i += 1;
11858
- position = i;
11859
- } else {
11860
- const offset = tokenCharOffset(tokenFlags, n);
11861
- if (offset < 0) {
11862
- position = tokenFlags.length;
11863
- } else {
11864
- let j = offset + 1;
11865
- while (j < tokenFlags.length && !tokenFlags[j]) j += 1;
11866
- position = j;
11867
- }
11868
- }
12038
+ #restoreCaret(position) {
11869
12039
  try {
11870
12040
  this.element.setSelectionRange(position, position);
11871
12041
  } catch {
@@ -11915,70 +12085,102 @@ function queryRoot(selector) {
11915
12085
  }
11916
12086
  var IntersectionWatcher = class {
11917
12087
  #onEntries;
11918
- #observer = null;
11919
- #active = false;
11920
- #usingPlatformDefaults = false;
12088
+ #session = null;
11921
12089
  constructor(onEntries) {
11922
12090
  this.#onEntries = onEntries;
11923
12091
  }
11924
12092
  get active() {
11925
- return this.#active;
12093
+ return this.#session?.active ?? false;
11926
12094
  }
11927
12095
  get usingPlatformDefaults() {
11928
- return this.#usingPlatformDefaults;
12096
+ return this.#session?.usingPlatformDefaults ?? false;
11929
12097
  }
11930
12098
  start(targets, options = {}) {
11931
- this.stop();
11932
- if (typeof IntersectionObserver === "undefined") return false;
11933
- const list = Array.isArray(targets) ? targets : [targets];
11934
- if (list.length === 0) return false;
11935
- 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;
11936
12106
  let observer = null;
11937
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;
11938
12117
  const onEntries = (entries) => {
11939
- if (this.#active && this.#observer === observer) this.#onEntries(entries);
12118
+ if (this.#session === session && session.active) this.#onEntries(entries);
11940
12119
  };
12120
+ let usingPlatformDefaults = false;
11941
12121
  try {
11942
- observer = new IntersectionObserver(onEntries, {
12122
+ const configured = {
11943
12123
  root,
11944
12124
  rootMargin: options.rootMargin,
11945
12125
  threshold: options.threshold
11946
- });
12126
+ };
12127
+ if (this.#session !== session) return false;
12128
+ observer = new IntersectionObserver(onEntries, configured);
11947
12129
  } catch (error) {
12130
+ if (this.#session !== session) return false;
11948
12131
  console.warn(
11949
12132
  "Stimeo UI: IntersectionObserver could not be constructed with the configured options; retrying with platform defaults.",
11950
12133
  error
11951
12134
  );
12135
+ if (this.#session !== session) return false;
11952
12136
  observer = new IntersectionObserver(onEntries, { root });
11953
- this.#usingPlatformDefaults = true;
12137
+ usingPlatformDefaults = true;
11954
12138
  }
11955
- for (const target of list) observer.observe(target);
11956
- this.#observer = observer;
11957
- 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;
11958
12155
  return true;
11959
12156
  } catch (error) {
11960
- observer?.disconnect();
11961
- this.#observer = null;
11962
- this.#active = false;
11963
- this.#usingPlatformDefaults = false;
12157
+ this.#release(session, observer);
11964
12158
  throw error;
11965
12159
  }
11966
12160
  }
11967
12161
  rearm(target) {
11968
- if (!this.#observer) return;
12162
+ const session = this.#session;
12163
+ const observer = session?.observer;
12164
+ if (!session?.active || !observer) return;
11969
12165
  try {
11970
- this.#observer.unobserve(target);
11971
- 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);
11972
12170
  } catch (error) {
11973
- this.stop();
12171
+ if (this.#session === session) this.#session = null;
12172
+ this.#release(session, observer);
11974
12173
  throw error;
11975
12174
  }
11976
12175
  }
11977
12176
  stop() {
11978
- this.#active = false;
11979
- this.#observer?.disconnect();
11980
- this.#observer = null;
11981
- 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();
11982
12184
  }
11983
12185
  };
11984
12186
 
@@ -12224,7 +12426,6 @@ var Typeahead = class {
12224
12426
  #timers = new SafeTimeout();
12225
12427
  #resetMs;
12226
12428
  #query = "";
12227
- #timerId = 0;
12228
12429
  constructor({ resetMs = TYPEAHEAD_RESET_MS } = {}) {
12229
12430
  this.#resetMs = resetMs;
12230
12431
  }
@@ -12235,14 +12436,13 @@ var Typeahead = class {
12235
12436
  const char = key.toLowerCase();
12236
12437
  const repeated = this.#query.length > 0 && [...this.#query].every((c) => c === char);
12237
12438
  this.#query = repeated ? char : this.#query + char;
12238
- this.#timers.clear(this.#timerId);
12239
- this.#timerId = this.#timers.set(() => this.reset(), this.#resetMs);
12439
+ this.#timers.clearAll();
12440
+ this.#timers.set(() => this.reset(), this.#resetMs);
12240
12441
  return this.#query;
12241
12442
  }
12242
12443
  reset() {
12243
12444
  this.#query = "";
12244
- this.#timers.clear(this.#timerId);
12245
- this.#timerId = 0;
12445
+ this.#timers.clearAll();
12246
12446
  }
12247
12447
  };
12248
12448
  function isTypeaheadKey(event) {
@@ -12663,13 +12863,7 @@ function readDatetime(element) {
12663
12863
  const minute = Number(minuteText);
12664
12864
  const second = Number(secondText);
12665
12865
  if (hour === 24 && (minute !== 0 || second !== 0 || /[1-9]/.test(fraction))) return null;
12666
- let offset = zone;
12667
- if (zone !== "Z") {
12668
- const digits = zone.slice(1).replace(":", "");
12669
- const offsetHour = digits.slice(0, 2);
12670
- const offsetMinute = digits.slice(2);
12671
- offset = `${zone[0]}${offsetHour}:${offsetMinute}`;
12672
- }
12866
+ const offset = zone.replace(/^([+-]\d{2})(\d{2})$/, "$1:$2");
12673
12867
  const milliseconds = fraction.slice(0, 3).padEnd(3, "0");
12674
12868
  const canonical = `${yearText}-${monthText}-${dayText}T${hourText}:${minuteText}:${secondText}.${milliseconds}${offset}`;
12675
12869
  const instant = Date.parse(canonical);
@@ -14327,14 +14521,17 @@ var MultiSelectController = class _MultiSelectController extends Controller {
14327
14521
  tag?.remove();
14328
14522
  }
14329
14523
  #removeTagAt(index, focus = "neighbor") {
14330
- const tag = this.tagTargets[index];
14524
+ const tags = this.tagTargets;
14525
+ const tag = tags[index];
14331
14526
  if (!tag) return;
14527
+ const afterFocus2 = focus === "neighbor" && tags.length === 1 && this.hasInputTarget;
14332
14528
  const value = tag.dataset.value ?? "";
14333
14529
  const option = this.optionTargets.find((candidate) => this.#optionValue(candidate) === value);
14334
14530
  if (option) option.setAttribute("aria-selected", "false");
14335
14531
  tag.remove();
14336
14532
  this.#refreshRoving();
14337
- 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;
14338
14535
  if (focus === "input") {
14339
14536
  this.#focusInput();
14340
14537
  return;
@@ -14371,7 +14568,7 @@ var MultiSelectController = class _MultiSelectController extends Controller {
14371
14568
  const options = { name: this.nameValue, form: this.formValue };
14372
14569
  return writeFields(this.fieldsTarget, this.#values, options);
14373
14570
  }
14374
- #publishSelection(selected, label, value, reason = "user") {
14571
+ #publishSelection(selected, label, value, reason = "user", afterFocus2 = false) {
14375
14572
  const values = this.#values;
14376
14573
  const changed = !this.#sameSelection(this.#selectionValues, values);
14377
14574
  const fieldChanged = this.#syncFields();
@@ -14380,7 +14577,7 @@ var MultiSelectController = class _MultiSelectController extends Controller {
14380
14577
  const token = this.#moves.record();
14381
14578
  if (fieldChanged) commitField(this.fieldsTarget);
14382
14579
  if (!this.#moves.isLatest(token)) return false;
14383
- this.#announceTransition(selected, label, value, values.length);
14580
+ this.#announceTransition(selected, label, value, values.length, afterFocus2);
14384
14581
  if (!this.#moves.isLatest(token)) return false;
14385
14582
  this.dispatch("change", { detail: { values, reason } });
14386
14583
  return this.#moves.isLatest(token);
@@ -14388,9 +14585,9 @@ var MultiSelectController = class _MultiSelectController extends Controller {
14388
14585
  #refreshRoving() {
14389
14586
  this.#chipRow.ensureTabStop();
14390
14587
  }
14391
- #announceTransition(selected, label, value, count) {
14588
+ #announceTransition(selected, label, value, count, afterFocus2 = false) {
14392
14589
  const template = selected ? this.announceTextValue : this.announceRemovedTextValue;
14393
- announce(fillTemplate(template, { label, value, count }));
14590
+ announce(fillTemplate(template, { label, value, count }), { afterFocus: afterFocus2 });
14394
14591
  }
14395
14592
  #sameSelection(left, right) {
14396
14593
  if (left.length !== right.length) return false;
@@ -15060,25 +15257,22 @@ function snapSteppedValue(raw, range) {
15060
15257
  if (!(range.min <= range.max)) return finiteFallback(range.min, range.max);
15061
15258
  const input = Number.isNaN(raw) ? finiteFallback(range.min, range.max) : raw;
15062
15259
  const clamped = Math.min(range.max, Math.max(range.min, input));
15063
- const step = effectiveStep(range.step);
15064
- const base = stepBase(range);
15260
+ const grid = stepGrid(range);
15065
15261
  const candidates = [];
15066
15262
  if (Number.isFinite(range.min)) candidates.push(range.min);
15067
15263
  if (Number.isFinite(range.max)) candidates.push(range.max);
15068
- const gridPosition = (clamped - base) / step;
15069
- if (Number.isFinite(gridPosition)) {
15070
- addGridCandidate(candidates, Math.floor(gridPosition), range, base, step);
15071
- 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
+ }
15072
15270
  }
15073
15271
  if (candidates.length === 0) return clamped;
15074
15272
  let nearest = candidates[0];
15075
- let nearestDistance = Math.abs(clamped - nearest);
15076
15273
  for (const candidate of candidates.slice(1)) {
15077
- const distance = Math.abs(clamped - candidate);
15078
- if (distance < nearestDistance || nearlyEqual(distance, nearestDistance) && candidate > nearest) {
15079
- nearest = candidate;
15080
- nearestDistance = distance;
15081
- }
15274
+ const nearer = isMidpoint(clamped, candidate, nearest, range, grid) ? candidate > nearest : Math.abs(clamped - candidate) < Math.abs(clamped - nearest);
15275
+ if (nearer) nearest = candidate;
15082
15276
  }
15083
15277
  return nearest;
15084
15278
  }
@@ -15087,46 +15281,36 @@ function stepSteppedValue(current, count, range) {
15087
15281
  const distance = Math.abs(Math.trunc(count));
15088
15282
  if (!Number.isFinite(distance) || distance === 0) return value;
15089
15283
  const direction = Math.sign(count);
15090
- const adjacent = adjacentSteppedValue(value, direction, range);
15284
+ const adjacent = nextGridValue(value, direction, range);
15285
+ if (adjacent === value) return value;
15091
15286
  const raw = adjacent + direction * (distance - 1) * effectiveStep(range.step);
15092
- 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;
15093
15289
  }
15094
- function adjacentSteppedValue(current, direction, range) {
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;
15301
+ }
15302
+ function stepGrid(range) {
15095
15303
  const step = effectiveStep(range.step);
15096
15304
  const base = stepBase(range);
15097
- const candidates = [];
15098
- if (direction > 0) {
15099
- const position2 = (current - base) / step;
15100
- if (Number.isFinite(position2)) {
15101
- let gridIndex = Math.floor(position2) + 1;
15102
- let candidate = cleanGridValue(base + gridIndex * step, base, step);
15103
- if (candidate < current || nearlyEqual(candidate, current)) {
15104
- gridIndex += 1;
15105
- candidate = cleanGridValue(base + gridIndex * step, base, step);
15106
- }
15107
- if (candidate > current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
15108
- candidates.push(clamp(candidate, range));
15109
- }
15110
- }
15111
- return clamp(Math.min(...candidates), range);
15112
- }
15113
- const position = (current - base) / step;
15114
- if (Number.isFinite(position)) {
15115
- let gridIndex = Math.ceil(position) - 1;
15116
- let candidate = cleanGridValue(base + gridIndex * step, base, step);
15117
- if (candidate > current || nearlyEqual(candidate, current)) {
15118
- gridIndex -= 1;
15119
- candidate = cleanGridValue(base + gridIndex * step, base, step);
15120
- }
15121
- if (candidate < current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
15122
- candidates.push(clamp(candidate, range));
15123
- }
15124
- }
15125
- 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;
15126
15311
  }
15127
- function addGridCandidate(candidates, index, range, base, step) {
15128
- const candidate = cleanGridValue(base + index * step, base, step);
15129
- 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);
15130
15314
  }
15131
15315
  function stepBase(range) {
15132
15316
  if (range.base !== void 0 && Number.isFinite(range.base)) return range.base;
@@ -15142,15 +15326,46 @@ function decimalPlaces(value) {
15142
15326
  const exponent = exponentText === void 0 ? 0 : Number(exponentText);
15143
15327
  return Math.max(0, fractionLength - exponent);
15144
15328
  }
15145
- function within(value, min, max) {
15146
- 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;
15147
15331
  }
15148
- function clamp(value, range) {
15149
- return Math.min(range.max, Math.max(range.min, value));
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);
15150
15335
  }
15151
- function nearlyEqual(left, right) {
15152
- const scale = Math.max(Math.abs(left), Math.abs(right));
15153
- return Number.isFinite(left) && Number.isFinite(right) && Math.abs(left - right) <= Number.EPSILON * scale;
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);
15344
+ }
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 };
15154
15369
  }
15155
15370
  function finiteFallback(min, max) {
15156
15371
  if (Number.isFinite(min)) return min;
@@ -15349,16 +15564,17 @@ var NumberInputController = class _NumberInputController extends Controller {
15349
15564
  next = this.#safePageStep > 0 ? this.#currentValue() - this.#safePageStep : stepSteppedValue(this.#currentValue(), -10, this.#steppedRange);
15350
15565
  break;
15351
15566
  case "Home":
15352
- if (!Number.isFinite(this.#safeMin)) return;
15353
15567
  next = this.#safeMin;
15354
15568
  break;
15355
15569
  case "End":
15356
- if (!Number.isFinite(this.#safeMax)) return;
15357
15570
  next = this.#safeMax;
15358
15571
  break;
15359
15572
  default:
15360
15573
  return;
15361
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;
15362
15578
  event.preventDefault();
15363
15579
  this.#commit(next, true);
15364
15580
  }
@@ -15546,12 +15762,16 @@ var NumberInputController = class _NumberInputController extends Controller {
15546
15762
  }
15547
15763
  #updateButtons(value, range) {
15548
15764
  const move = this.#move;
15549
- for (const button of this.incrementTargets) {
15550
- 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);
15551
15769
  if (!this.#moves.isLatest(move)) return;
15552
15770
  }
15553
- for (const button of this.decrementTargets) {
15554
- 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);
15555
15775
  if (!this.#moves.isLatest(move)) return;
15556
15776
  }
15557
15777
  }
@@ -19369,11 +19589,7 @@ var RadioGroupController = class extends Controller {
19369
19589
  #releaseRadio(radio) {
19370
19590
  this.#managedRadios.delete(radio);
19371
19591
  const original = this.#originalTabindex.get(radio);
19372
- if (original === null) {
19373
- this.#writeAttribute(radio, "tabindex", null);
19374
- } else if (original !== void 0) {
19375
- this.#writeAttribute(radio, "tabindex", original);
19376
- }
19592
+ if (original !== void 0) this.#writeAttribute(radio, "tabindex", original);
19377
19593
  this.#originalTabindex.delete(radio);
19378
19594
  if (this.#ownedChecked.delete(radio)) {
19379
19595
  this.#writeAttribute(radio, "aria-checked", null);
@@ -22409,7 +22625,7 @@ var SkeletonController = class _SkeletonController extends Controller {
22409
22625
  };
22410
22626
  static actions = ["ready", "reset"];
22411
22627
  static events = ["ready"];
22412
- #timers = new SafeTimeout();
22628
+ #timers = new TaskTimeout();
22413
22629
  #floor = new MinDurationFloor(this.#timers);
22414
22630
  #gate = new DetachGate();
22415
22631
  #hidden = new AttributeLease("hidden", this.identifier);
@@ -23045,7 +23261,7 @@ var SpinnerController = class _SpinnerController extends Controller {
23045
23261
  };
23046
23262
  static actions = ["start", "stop"];
23047
23263
  static events = ["hide", "show", "timeout", "reconcile"];
23048
- #timers = new SafeTimeout();
23264
+ #timers = new TaskTimeout();
23049
23265
  #floor = new MinDurationFloor(this.#timers);
23050
23266
  #gate = new DetachGate();
23051
23267
  #busyLease = new AttributeLease("aria-busy", this.identifier);
@@ -24341,7 +24557,8 @@ var TagsInputController = class _TagsInputController extends Controller {
24341
24557
  const value = tag.dataset.value ?? "";
24342
24558
  tag.remove();
24343
24559
  const tags = this.#values;
24344
- 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;
24345
24562
  if (focus === "input") {
24346
24563
  this.#focusInput();
24347
24564
  return;
@@ -24365,7 +24582,7 @@ var TagsInputController = class _TagsInputController extends Controller {
24365
24582
  this.#chipRow.ensureTabStop();
24366
24583
  return fieldChanged;
24367
24584
  }
24368
- #publishTags(tags, added, value) {
24585
+ #publishTags(tags, added, value, afterFocus2 = false) {
24369
24586
  const changed = !this.#sameTags(this.#tagValues, tags);
24370
24587
  const fieldChanged = this.#syncState(tags);
24371
24588
  this.#tagValues = tags;
@@ -24373,7 +24590,7 @@ var TagsInputController = class _TagsInputController extends Controller {
24373
24590
  const token = this.#moves.record();
24374
24591
  if (fieldChanged) commitField(this.fieldsTarget);
24375
24592
  if (!this.#moves.isLatest(token)) return false;
24376
- this.#announceTransition(added, value, tags.length);
24593
+ this.#announceTransition(added, value, tags.length, afterFocus2);
24377
24594
  if (!this.#moves.isLatest(token)) return false;
24378
24595
  this.dispatch("change", { detail: { tags } });
24379
24596
  return this.#moves.isLatest(token);
@@ -24388,9 +24605,9 @@ var TagsInputController = class _TagsInputController extends Controller {
24388
24605
  this.dispatch("reconcile", { detail: { tags } });
24389
24606
  }
24390
24607
  }
24391
- #announceTransition(added, value, count) {
24608
+ #announceTransition(added, value, count, afterFocus2) {
24392
24609
  const template = added ? this.announceTextValue : this.announceRemovedTextValue;
24393
- announce(fillTemplate(template, { label: value, value, count }));
24610
+ announce(fillTemplate(template, { label: value, value, count }), { afterFocus: afterFocus2 });
24394
24611
  }
24395
24612
  #reject(value, reason) {
24396
24613
  this.dispatch("reject", { detail: { value, reason } });