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
@@ -196,7 +196,50 @@ function isCompositionInputType(inputType) {
196
196
  return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
197
197
  }
198
198
  var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
199
- var textOf = (element) => element.value;
199
+ var textOf = (element) => {
200
+ if ("value" in element) return element.value;
201
+ return element instanceof Element ? element.textContent : void 0;
202
+ };
203
+ var nodesOf = (element) => {
204
+ const nodes = [];
205
+ if ("value" in element || !(element instanceof Element)) return nodes;
206
+ const walker = element.ownerDocument.createTreeWalker(element);
207
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
208
+ return nodes;
209
+ };
210
+ var folded = (text) => text.replaceAll("\xA0", " ");
211
+ var startOf = (node, data, replaced, caret) => {
212
+ const text = folded(node.data);
213
+ const composed = folded(data);
214
+ if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
215
+ return replaced.startOffset;
216
+ }
217
+ const start = text.lastIndexOf(composed, caret);
218
+ return start !== -1 && start + composed.length >= caret ? start : -1;
219
+ };
220
+ var spotOf = (element, replaced, data) => {
221
+ if ("value" in element || !(element instanceof Element)) return null;
222
+ const selection = element.ownerDocument.getSelection();
223
+ const node = selection?.focusNode;
224
+ if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
225
+ const range = element.ownerDocument.createRange();
226
+ const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
227
+ if (start === -1) {
228
+ range.selectNodeContents(node);
229
+ } else {
230
+ range.setStart(node, start);
231
+ range.setEnd(node, start + data.length);
232
+ }
233
+ return range;
234
+ };
235
+ var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
236
+ var rewritten = ({ element, text, nodes, spot }) => {
237
+ if (spot !== null) {
238
+ return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
239
+ }
240
+ const current = nodesOf(element);
241
+ return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
242
+ };
200
243
  var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
201
244
  var CompositionTracker = class {
202
245
  #observedTargets = /* @__PURE__ */ new Set();
@@ -287,11 +330,11 @@ var CompositionTracker = class {
287
330
  }
288
331
  #settle() {
289
332
  const composition = this.#composition;
290
- if (composition === null) return;
291
- const { target, element, text } = composition;
333
+ if (composition === null || !this.#observedTargets.has(composition.target)) return;
334
+ const { target, element } = composition;
292
335
  if (target instanceof Node && element instanceof Node && !target.contains(element)) {
293
336
  this.#composition = null;
294
- } else if (textOf(element) !== text) {
337
+ } else if (rewritten(composition)) {
295
338
  this.#abandon(false);
296
339
  }
297
340
  }
@@ -316,7 +359,14 @@ var CompositionTracker = class {
316
359
  this.#owe(true);
317
360
  const target = event.currentTarget;
318
361
  const element = event.target;
319
- this.#composition = { target, element, text: textOf(element) };
362
+ this.#composition = {
363
+ target,
364
+ element,
365
+ text: textOf(element),
366
+ nodes: nodesOf(element),
367
+ spot: spotOf(element, null, void 0),
368
+ replaced: null
369
+ };
320
370
  this.#runAbandon();
321
371
  this.#onStart?.(event);
322
372
  };
@@ -340,6 +390,10 @@ var CompositionTracker = class {
340
390
  if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
341
391
  this.#abandon(true);
342
392
  }
393
+ const composition = this.#composition;
394
+ if (composition !== null && event.target === composition.element) {
395
+ composition.replaced = replacedBy(event);
396
+ }
343
397
  this.#runAbandon();
344
398
  };
345
399
  #handleInput = (event) => {
@@ -347,6 +401,15 @@ var CompositionTracker = class {
347
401
  const { isTrusted, isComposing, inputType } = event;
348
402
  if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
349
403
  composition.text = textOf(composition.element);
404
+ composition.nodes = nodesOf(composition.element);
405
+ if (isCompositionInputType(inputType)) {
406
+ composition.spot = spotOf(
407
+ composition.element,
408
+ composition.replaced,
409
+ event.data
410
+ );
411
+ }
412
+ composition.replaced = null;
350
413
  } else {
351
414
  this.#settle();
352
415
  }
@@ -367,7 +430,9 @@ var CompositionTracker = class {
367
430
  const composition = this.#composition;
368
431
  if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
369
432
  const detail = event.detail;
370
- if (detail?.attributeName === "value") event.preventDefault();
433
+ if (detail?.attributeName === "value" && "value" in composition.element) {
434
+ event.preventDefault();
435
+ }
371
436
  };
372
437
  };
373
438
 
@@ -8,11 +8,16 @@ function ownerOf(candidates, node) {
8
8
  return candidates[ownerIndex(candidates, node)] ?? null;
9
9
  }
10
10
 
11
+ var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
11
12
  function inheritsFieldsetDisabled(control) {
12
13
  let fieldset = control.closest("fieldset[disabled]");
13
14
  while (fieldset) {
14
- const legend = Array.from(fieldset.children).find((child) => child.tagName === "LEGEND");
15
- if (!legend?.contains(control)) return true;
15
+ if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
16
+ const legend = Array.from(fieldset.children).find(
17
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
18
+ );
19
+ if (!legend?.contains(control)) return true;
20
+ }
16
21
  fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
17
22
  }
18
23
  return false;
@@ -22,11 +22,16 @@ function actionSource(source) {
22
22
  };
23
23
  }
24
24
 
25
+ var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
25
26
  function inheritsFieldsetDisabled(control) {
26
27
  let fieldset = control.closest("fieldset[disabled]");
27
28
  while (fieldset) {
28
- const legend = Array.from(fieldset.children).find((child) => child.tagName === "LEGEND");
29
- if (!legend?.contains(control)) return true;
29
+ if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
30
+ const legend = Array.from(fieldset.children).find(
31
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
32
+ );
33
+ if (!legend?.contains(control)) return true;
34
+ }
30
35
  fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
31
36
  }
32
37
  return false;
@@ -7,14 +7,15 @@ function fillTemplate(template, values) {
7
7
  });
8
8
  }
9
9
 
10
+ var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
10
11
  function announce(message, options = {}) {
11
12
  const text = message.trim();
12
13
  if (text.length === 0) return;
13
- window.dispatchEvent(
14
- new CustomEvent("stimeo--announcer:announce", {
15
- detail: { message: text, assertive: options.assertive === true }
16
- })
17
- );
14
+ const event = new CustomEvent("stimeo--announcer:announce", {
15
+ detail: { message: text, assertive: options.assertive === true }
16
+ });
17
+ if (options.afterFocus) event[afterFocus] = true;
18
+ window.dispatchEvent(event);
18
19
  }
19
20
 
20
21
  var NUMBER_BOUNDS = {
@@ -166,6 +166,7 @@ var EscapeLayer = class _EscapeLayer {
166
166
  );
167
167
  #active = null;
168
168
  activate(ownerDocument = document, options) {
169
+ const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
169
170
  this.deactivate();
170
171
  let registry2 = _EscapeLayer.#registries.get(ownerDocument);
171
172
  if (!registry2) {
@@ -173,7 +174,6 @@ var EscapeLayer = class _EscapeLayer {
173
174
  _EscapeLayer.#registries.set(ownerDocument, registry2);
174
175
  ownerDocument.addEventListener("keydown", registry2.onKeydown);
175
176
  }
176
- const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
177
177
  registry2.stack.push(entry);
178
178
  this.#active = { document: ownerDocument, entry };
179
179
  }
@@ -222,11 +222,16 @@ var EscapeLayer = class _EscapeLayer {
222
222
  }
223
223
  };
224
224
 
225
+ var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
225
226
  function inheritsFieldsetDisabled(control) {
226
227
  let fieldset = control.closest("fieldset[disabled]");
227
228
  while (fieldset) {
228
- const legend = Array.from(fieldset.children).find((child) => child.tagName === "LEGEND");
229
- if (!legend?.contains(control)) return true;
229
+ if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
230
+ const legend = Array.from(fieldset.children).find(
231
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
232
+ );
233
+ if (!legend?.contains(control)) return true;
234
+ }
230
235
  fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
231
236
  }
232
237
  return false;
@@ -284,11 +289,10 @@ function hasNativeTabStop(element) {
284
289
  if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
285
290
  return element.hasAttribute("controls");
286
291
  }
287
- if (element instanceof HTMLElement && element.tagName === "SUMMARY") {
288
- const details = element.parentElement;
289
- return details instanceof HTMLDetailsElement && Array.from(details.children).find((child) => child.tagName === "SUMMARY") === element;
290
- }
291
- return false;
292
+ const details = element.parentElement;
293
+ return details instanceof HTMLDetailsElement && Array.from(details.children).find(
294
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "summary"
295
+ ) === element;
292
296
  }
293
297
  function hasEditableTabStop(element) {
294
298
  const value = element.getAttribute("contenteditable")?.toLowerCase();
@@ -7,14 +7,15 @@ function fillTemplate(template, values) {
7
7
  });
8
8
  }
9
9
 
10
+ var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
10
11
  function announce(message, options = {}) {
11
12
  const text = message.trim();
12
13
  if (text.length === 0) return;
13
- window.dispatchEvent(
14
- new CustomEvent("stimeo--announcer:announce", {
15
- detail: { message: text, assertive: options.assertive === true }
16
- })
17
- );
14
+ const event = new CustomEvent("stimeo--announcer:announce", {
15
+ detail: { message: text, assertive: options.assertive === true }
16
+ });
17
+ if (options.afterFocus) event[afterFocus] = true;
18
+ window.dispatchEvent(event);
18
19
  }
19
20
 
20
21
  var NUMBER_BOUNDS = {
@@ -51,43 +51,66 @@ function setAttributeIfChanged(element, name, value, beforeWrite) {
51
51
 
52
52
  var AuthoredMutationWatcher = class {
53
53
  #onAuthored;
54
- #claims = null;
55
- #observer = null;
54
+ #lifetime = null;
56
55
  constructor(onAuthored) {
57
56
  this.#onAuthored = onAuthored;
58
57
  }
59
58
  observe(root, options) {
60
- this.disconnect();
61
- const observer = new MutationObserver((records) => {
62
- if (this.#observer !== observer) return;
63
- const authored = this.#filter(records);
64
- if (authored.length > 0) this.#onAuthored(authored);
65
- });
66
- this.#observer = observer;
67
- this.#claims = { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() };
68
- observer.observe(root, {
69
- attributes: true,
70
- attributeFilter: [...options.attributes],
71
- subtree: options.subtree ?? false,
72
- childList: options.childList ?? false
73
- });
74
- if (options.ancestorAttributes) {
75
- let ancestor = root.parentElement;
76
- while (ancestor) {
77
- observer.observe(ancestor, {
78
- attributes: true,
79
- attributeFilter: [...options.ancestorAttributes]
80
- });
81
- ancestor = ancestor.parentElement;
59
+ const previous = this.#lifetime;
60
+ const lifetime = {
61
+ observer: null,
62
+ active: false,
63
+ claims: { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() }
64
+ };
65
+ this.#lifetime = lifetime;
66
+ let observer = null;
67
+ try {
68
+ if (previous) this.#release(previous);
69
+ if (this.#lifetime !== lifetime) return;
70
+ const attributes = [...options.attributes];
71
+ const subtree = options.subtree ?? false;
72
+ const childList = options.childList ?? false;
73
+ const inherited = options.ancestorAttributes;
74
+ const ancestorAttributes = inherited ? [...inherited] : null;
75
+ if (this.#lifetime !== lifetime) return;
76
+ observer = new MutationObserver((records) => {
77
+ const authored = this.#filter(records, lifetime.claims);
78
+ if (this.#lifetime === lifetime && lifetime.active && authored.length > 0) {
79
+ this.#onAuthored(authored);
80
+ }
81
+ });
82
+ if (this.#lifetime !== lifetime) return;
83
+ lifetime.observer = observer;
84
+ observer.observe(root, { attributes: true, attributeFilter: attributes, subtree, childList });
85
+ if (this.#lifetime !== lifetime) {
86
+ this.#release(lifetime, observer);
87
+ return;
82
88
  }
89
+ if (ancestorAttributes) {
90
+ let ancestor = root.parentElement;
91
+ while (ancestor) {
92
+ observer.observe(ancestor, { attributes: true, attributeFilter: ancestorAttributes });
93
+ if (this.#lifetime !== lifetime) {
94
+ this.#release(lifetime, observer);
95
+ return;
96
+ }
97
+ ancestor = ancestor.parentElement;
98
+ }
99
+ }
100
+ lifetime.active = true;
101
+ } catch (error) {
102
+ this.#release(lifetime, observer);
103
+ throw error;
83
104
  }
84
105
  }
85
106
  claim(target, name, value) {
86
- const claims = this.#claims?.attributes;
87
- let attributes = claims?.get(target);
107
+ const lifetime = this.#lifetime;
108
+ if (!lifetime?.active) return;
109
+ const claims = lifetime.claims.attributes;
110
+ let attributes = claims.get(target);
88
111
  if (!attributes) {
89
112
  attributes = /* @__PURE__ */ new Map();
90
- claims?.set(target, attributes);
113
+ claims.set(target, attributes);
91
114
  }
92
115
  const pending = attributes.get(name);
93
116
  attributes.set(name, { value, count: (pending?.count ?? 0) + 1 });
@@ -96,37 +119,49 @@ var AuthoredMutationWatcher = class {
96
119
  this.claim(target, name, target.getAttribute(name));
97
120
  }
98
121
  claimChildList(target, added, removed) {
99
- const claims = this.#claims?.children;
100
- const pending = claims?.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
122
+ const lifetime = this.#lifetime;
123
+ if (!lifetime?.active) return;
124
+ const claims = lifetime.claims.children;
125
+ const pending = claims.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
101
126
  for (const node of added) pending.added.set(node, (pending.added.get(node) ?? 0) + 1);
102
127
  for (const node of removed) pending.removed.set(node, (pending.removed.get(node) ?? 0) + 1);
103
- claims?.set(target, pending);
128
+ claims.set(target, pending);
104
129
  }
105
130
  take() {
106
- return this.#filter(this.#observer?.takeRecords() ?? []);
131
+ const lifetime = this.#lifetime;
132
+ const observer = lifetime?.observer;
133
+ if (!lifetime?.active || !observer) return [];
134
+ const records = observer.takeRecords();
135
+ const authored = this.#filter(records, lifetime.claims);
136
+ return this.#lifetime === lifetime && lifetime.active ? authored : [];
107
137
  }
108
138
  disconnect() {
109
- this.#observer?.disconnect();
110
- this.#observer = null;
111
- this.#claims = null;
112
- }
113
- #filter(records) {
114
- const authored = records.filter((record) => !this.#consume(record));
115
- this.#claims?.attributes.clear();
116
- this.#claims?.children.clear();
139
+ const lifetime = this.#lifetime;
140
+ if (lifetime) this.#release(lifetime);
141
+ }
142
+ #release(lifetime, observer = lifetime.observer) {
143
+ if (this.#lifetime === lifetime) this.#lifetime = null;
144
+ lifetime.claims.attributes.clear();
145
+ lifetime.claims.children.clear();
146
+ observer?.disconnect();
147
+ }
148
+ #filter(records, claims) {
149
+ const authored = records.filter((record) => !this.#consume(record, claims));
150
+ claims.attributes.clear();
151
+ claims.children.clear();
117
152
  return authored;
118
153
  }
119
- #consume(record) {
154
+ #consume(record, claims) {
120
155
  if (record.type === "attributes") {
121
156
  const target = record.target;
122
- const pending2 = this.#claims?.attributes.get(target)?.get(record.attributeName);
157
+ const pending2 = claims.attributes.get(target)?.get(record.attributeName);
123
158
  if (!pending2 || pending2.count === 0 || target.getAttribute(record.attributeName) !== pending2.value) {
124
159
  return false;
125
160
  }
126
161
  pending2.count -= 1;
127
162
  return true;
128
163
  }
129
- const pending = this.#claims?.children.get(record.target);
164
+ const pending = claims.children.get(record.target);
130
165
  if (!pending) return false;
131
166
  const added = [...record.addedNodes];
132
167
  const removed = [...record.removedNodes];
@@ -156,11 +191,16 @@ function commitField(target) {
156
191
  target.dispatchEvent(new Event("change", { bubbles: true }));
157
192
  }
158
193
 
194
+ var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
159
195
  function inheritsFieldsetDisabled(control) {
160
196
  let fieldset = control.closest("fieldset[disabled]");
161
197
  while (fieldset) {
162
- const legend = Array.from(fieldset.children).find((child) => child.tagName === "LEGEND");
163
- if (!legend?.contains(control)) return true;
198
+ if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
199
+ const legend = Array.from(fieldset.children).find(
200
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
201
+ );
202
+ if (!legend?.contains(control)) return true;
203
+ }
164
204
  fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
165
205
  }
166
206
  return false;
@@ -538,11 +578,7 @@ var RadioGroupController = class extends Controller {
538
578
  #releaseRadio(radio) {
539
579
  this.#managedRadios.delete(radio);
540
580
  const original = this.#originalTabindex.get(radio);
541
- if (original === null) {
542
- this.#writeAttribute(radio, "tabindex", null);
543
- } else if (original !== void 0) {
544
- this.#writeAttribute(radio, "tabindex", original);
545
- }
581
+ if (original !== void 0) this.#writeAttribute(radio, "tabindex", original);
546
582
  this.#originalTabindex.delete(radio);
547
583
  if (this.#ownedChecked.delete(radio)) {
548
584
  this.#writeAttribute(radio, "aria-checked", null);
@@ -227,25 +227,22 @@ function snapSteppedValue(raw, range) {
227
227
  if (!(range.min <= range.max)) return finiteFallback(range.min, range.max);
228
228
  const input = Number.isNaN(raw) ? finiteFallback(range.min, range.max) : raw;
229
229
  const clamped = Math.min(range.max, Math.max(range.min, input));
230
- const step = effectiveStep(range.step);
231
- const base = stepBase(range);
230
+ const grid = stepGrid(range);
232
231
  const candidates = [];
233
232
  if (Number.isFinite(range.min)) candidates.push(range.min);
234
233
  if (Number.isFinite(range.max)) candidates.push(range.max);
235
- const gridPosition = (clamped - base) / step;
236
- if (Number.isFinite(gridPosition)) {
237
- addGridCandidate(candidates, Math.floor(gridPosition), range, base, step);
238
- addGridCandidate(candidates, Math.ceil(gridPosition), range, base, step);
234
+ const position = gridPosition(clamped, grid);
235
+ if (Number.isFinite(position)) {
236
+ for (const index of [Math.floor(position), Math.ceil(position)]) {
237
+ const candidate = gridValue(index, grid);
238
+ if (inRange(candidate, range)) candidates.push(candidate);
239
+ }
239
240
  }
240
241
  if (candidates.length === 0) return clamped;
241
242
  let nearest = candidates[0];
242
- let nearestDistance = Math.abs(clamped - nearest);
243
243
  for (const candidate of candidates.slice(1)) {
244
- const distance = Math.abs(clamped - candidate);
245
- if (distance < nearestDistance || nearlyEqual(distance, nearestDistance) && candidate > nearest) {
246
- nearest = candidate;
247
- nearestDistance = distance;
248
- }
244
+ const nearer = isMidpoint(clamped, candidate, nearest, range, grid) ? candidate > nearest : Math.abs(clamped - candidate) < Math.abs(clamped - nearest);
245
+ if (nearer) nearest = candidate;
249
246
  }
250
247
  return nearest;
251
248
  }
@@ -254,46 +251,36 @@ function stepSteppedValue(current, count, range) {
254
251
  const distance = Math.abs(Math.trunc(count));
255
252
  if (!Number.isFinite(distance) || distance === 0) return value;
256
253
  const direction = Math.sign(count);
257
- const adjacent = adjacentSteppedValue(value, direction, range);
254
+ const adjacent = nextGridValue(value, direction, range);
255
+ if (adjacent === value) return value;
258
256
  const raw = adjacent + direction * (distance - 1) * effectiveStep(range.step);
259
- return snapSteppedValue(raw, range);
257
+ const endpoint = direction > 0 ? range.max : range.min;
258
+ return Number.isFinite(raw) || Number.isFinite(endpoint) ? snapSteppedValue(raw, range) : value;
260
259
  }
261
- function adjacentSteppedValue(current, direction, range) {
260
+ function nextGridValue(current, direction, range) {
261
+ const grid = stepGrid(range);
262
+ const position = gridPosition(current, grid);
263
+ if (!Number.isFinite(position)) return current;
264
+ const index = direction > 0 ? Math.floor(position) + 1 : Math.ceil(position) - 1;
265
+ const first = gridValue(index, grid);
266
+ if (direction * (first - current) > 0 && !sameGridValue(first, current, grid.step)) {
267
+ return first;
268
+ }
269
+ const second = gridValue(index + direction, grid);
270
+ return direction * (second - current) > 0 ? second : current;
271
+ }
272
+ function stepGrid(range) {
262
273
  const step = effectiveStep(range.step);
263
274
  const base = stepBase(range);
264
- const candidates = [];
265
- if (direction > 0) {
266
- const position2 = (current - base) / step;
267
- if (Number.isFinite(position2)) {
268
- let gridIndex = Math.floor(position2) + 1;
269
- let candidate = cleanGridValue(base + gridIndex * step, base, step);
270
- if (candidate < current || nearlyEqual(candidate, current)) {
271
- gridIndex += 1;
272
- candidate = cleanGridValue(base + gridIndex * step, base, step);
273
- }
274
- if (candidate > current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
275
- candidates.push(clamp(candidate, range));
276
- }
277
- }
278
- return clamp(Math.min(...candidates), range);
279
- }
280
- const position = (current - base) / step;
281
- if (Number.isFinite(position)) {
282
- let gridIndex = Math.ceil(position) - 1;
283
- let candidate = cleanGridValue(base + gridIndex * step, base, step);
284
- if (candidate > current || nearlyEqual(candidate, current)) {
285
- gridIndex -= 1;
286
- candidate = cleanGridValue(base + gridIndex * step, base, step);
287
- }
288
- if (candidate < current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
289
- candidates.push(clamp(candidate, range));
290
- }
291
- }
292
- return clamp(Math.max(...candidates), range);
275
+ const near = base - Math.trunc(base / step) * step;
276
+ const origin = cleanGridValue(Number.isFinite(near) ? near % step : base % step, base, step);
277
+ return { step, base, origin };
278
+ }
279
+ function gridPosition(value, grid) {
280
+ return value / grid.step - grid.origin / grid.step;
293
281
  }
294
- function addGridCandidate(candidates, index, range, base, step) {
295
- const candidate = cleanGridValue(base + index * step, base, step);
296
- if (within(candidate, range.min, range.max)) candidates.push(clamp(candidate, range));
282
+ function gridValue(index, grid) {
283
+ return cleanGridValue(grid.origin + index * grid.step, grid.base, grid.step);
297
284
  }
298
285
  function stepBase(range) {
299
286
  if (range.base !== void 0 && Number.isFinite(range.base)) return range.base;
@@ -309,15 +296,46 @@ function decimalPlaces(value) {
309
296
  const exponent = exponentText === void 0 ? 0 : Number(exponentText);
310
297
  return Math.max(0, fractionLength - exponent);
311
298
  }
312
- function within(value, min, max) {
313
- return (value > min || nearlyEqual(value, min)) && (value < max || nearlyEqual(value, max));
299
+ function inRange(value, range) {
300
+ return Number.isFinite(value) && value >= range.min && value <= range.max;
301
+ }
302
+ function sameGridValue(left, right, step) {
303
+ const rounding = Number.EPSILON * Math.max(Math.abs(left), Math.abs(right));
304
+ return Math.abs(left - right) <= Math.min(rounding, step / 4);
305
+ }
306
+ function isMidpoint(value, left, right, range, grid) {
307
+ const imbalance = Math.abs(Math.abs(value - left) - Math.abs(value - right));
308
+ const rounding = 4 * Number.EPSILON * Math.max(Math.abs(value), Math.abs(left), Math.abs(right));
309
+ if (!(imbalance <= rounding)) return false;
310
+ if (imbalance <= Math.abs(left - right) / 4) return true;
311
+ const lower = Math.min(left, right);
312
+ const upper = Math.max(left, right);
313
+ return value > lower && value < upper && isDecimalMidpoint(value, lower, upper, range, grid);
314
314
  }
315
- function clamp(value, range) {
316
- return Math.min(range.max, Math.max(range.min, value));
315
+ function isDecimalMidpoint(value, lower, upper, range, grid) {
316
+ const raw = decimalParts(value);
317
+ const base = decimalParts(grid.base);
318
+ const step = decimalParts(grid.step);
319
+ const min = decimalParts(lower);
320
+ const max = decimalParts(upper);
321
+ const place = Math.min(raw.place, base.place, step.place, min.place, max.place);
322
+ const units = (part) => part.units * 10n ** BigInt(part.place - place);
323
+ const origin = units(base);
324
+ const stride = units(step);
325
+ const rawUnits = units(raw);
326
+ const remainder = (rawUnits - origin) % stride;
327
+ const below = rawUnits - (remainder < 0n ? remainder + stride : remainder);
328
+ const above = below + stride;
329
+ const minUnits = units(min);
330
+ const maxUnits = units(max);
331
+ const lowerUnits = lower === range.min && minUnits > below ? minUnits : below;
332
+ const upperUnits = upper === range.max && maxUnits < above ? maxUnits : above;
333
+ return Number(`${lowerUnits}e${place}`) === lower && Number(`${upperUnits}e${place}`) === upper && Number(`${(lowerUnits + upperUnits) * 5n}e${place - 1}`) === value;
317
334
  }
318
- function nearlyEqual(left, right) {
319
- const scale = Math.max(Math.abs(left), Math.abs(right));
320
- return Number.isFinite(left) && Number.isFinite(right) && Math.abs(left - right) <= Number.EPSILON * scale;
335
+ function decimalParts(value) {
336
+ const [coefficient = "", exponent = "0"] = value.toString().split("e");
337
+ const [whole = "", fraction = ""] = coefficient.split(".");
338
+ return { units: BigInt(whole + fraction), place: Number(exponent) - fraction.length };
321
339
  }
322
340
  function finiteFallback(min, max) {
323
341
  if (Number.isFinite(min)) return min;
@@ -34,13 +34,7 @@ function readDatetime(element) {
34
34
  const minute = Number(minuteText);
35
35
  const second = Number(secondText);
36
36
  if (hour === 24 && (minute !== 0 || second !== 0 || /[1-9]/.test(fraction))) return null;
37
- let offset = zone;
38
- if (zone !== "Z") {
39
- const digits = zone.slice(1).replace(":", "");
40
- const offsetHour = digits.slice(0, 2);
41
- const offsetMinute = digits.slice(2);
42
- offset = `${zone[0]}${offsetHour}:${offsetMinute}`;
43
- }
37
+ const offset = zone.replace(/^([+-]\d{2})(\d{2})$/, "$1:$2");
44
38
  const milliseconds = fraction.slice(0, 3).padEnd(3, "0");
45
39
  const canonical = `${yearText}-${monthText}-${dayText}T${hourText}:${minuteText}:${secondText}.${milliseconds}${offset}`;
46
40
  const instant = Date.parse(canonical);
@@ -17,11 +17,16 @@ function ownerIndex(candidates, node) {
17
17
  return candidates.findIndex((candidate) => candidate.contains(node));
18
18
  }
19
19
 
20
+ var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
20
21
  function inheritsFieldsetDisabled(control) {
21
22
  let fieldset = control.closest("fieldset[disabled]");
22
23
  while (fieldset) {
23
- const legend = Array.from(fieldset.children).find((child) => child.tagName === "LEGEND");
24
- if (!legend?.contains(control)) return true;
24
+ if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
25
+ const legend = Array.from(fieldset.children).find(
26
+ (child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
27
+ );
28
+ if (!legend?.contains(control)) return true;
29
+ }
25
30
  fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
26
31
  }
27
32
  return false;