@y14e/disclosure 2.2.4 → 3.0.0

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.
package/README.md CHANGED
@@ -60,10 +60,10 @@ new Disclosure(root);
60
60
 
61
61
  ## 📦 APIs
62
62
 
63
- ### `collapse`
63
+ ### `close`
64
64
 
65
65
  ```ts
66
- disclosure.collapse(details);
66
+ disclosure.close(details);
67
67
  // => void
68
68
  //
69
69
  // details: HTMLDetailsElement
@@ -80,10 +80,10 @@ disclosure.destroy(force);
80
80
  // force (optional): If true, skips waiting for animations to finish.
81
81
  ```
82
82
 
83
- ### `expand`
83
+ ### `open`
84
84
 
85
85
  ```ts
86
- disclosure.expand(details);
86
+ disclosure.open(details);
87
87
  // => void
88
88
  //
89
89
  // details: HTMLDetailsElement
@@ -91,26 +91,29 @@ function resolveOptions(options) {
91
91
  }
92
92
 
93
93
  // node_modules/power-focusable/dist/index.js
94
- function getComposedChildren(node) {
95
- if (node instanceof ShadowRoot) {
96
- return [...node.children];
94
+ function getComposedChildren(element) {
95
+ if (element instanceof ShadowRoot) {
96
+ return [...element.children];
97
97
  }
98
- if (!(node instanceof Element)) {
98
+ if (!(element instanceof Element)) {
99
99
  return [];
100
100
  }
101
- if (node instanceof HTMLSlotElement) {
102
- const assigned = node.assignedElements({ flatten: true });
101
+ if (element instanceof HTMLSlotElement) {
102
+ const assigned = element.assignedElements({ flatten: true });
103
103
  if (assigned.length) {
104
104
  return assigned;
105
105
  }
106
106
  }
107
- if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
108
- return [...node.shadowRoot.children];
107
+ if (element instanceof HTMLElement && element.shadowRoot?.mode === "open") {
108
+ return [...element.shadowRoot.children];
109
109
  }
110
- return [...node.children];
110
+ return [...element.children];
111
111
  }
112
112
  var FOCUSABLE_SELECTOR = ':is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])';
113
- var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(/(,\s*)?\[tabindex="-1"\]/g, "");
113
+ var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
114
+ /(,\s*)?\[tabindex="-1"\]/g,
115
+ ""
116
+ );
114
117
  function focusElement(element) {
115
118
  "focus" in element && typeof element.focus === "function" && element.focus();
116
119
  }
@@ -122,7 +125,7 @@ function getActiveElement() {
122
125
  return current;
123
126
  }
124
127
  function getTabIndex(element) {
125
- return "tabIndex" in element ? Number(element.tabIndex) : 0;
128
+ return "tabIndex" in element ? Number(element.tabIndex) : -1;
126
129
  }
127
130
  function isDisabled(element) {
128
131
  return "disabled" in element && !!element.disabled;
@@ -133,8 +136,8 @@ function isFormControl(element) {
133
136
  function isInert(element) {
134
137
  return "inert" in element && !!element.inert;
135
138
  }
136
- function isUngroupedRadio(element) {
137
- return element.type === "radio" && !!element.name;
139
+ function isUngroupedRadio(input) {
140
+ return input.type === "radio" && !!input.name;
138
141
  }
139
142
  function resolveOptions2(options) {
140
143
  let {
@@ -158,15 +161,11 @@ function resolveOptions2(options) {
158
161
  composed = false;
159
162
  }
160
163
  if (filter !== void 0 && typeof filter !== "function") {
161
- console.warn(
162
- "Invalid filter function. Fallback: no filter function (undefined)."
163
- );
164
+ console.warn("Invalid filter function. Fallback: no filter function (undefined).");
164
165
  filter = void 0;
165
166
  }
166
167
  if (include !== void 0 && typeof include !== "function") {
167
- console.warn(
168
- "Invalid include function. Fallback: no include function (undefined)."
169
- );
168
+ console.warn("Invalid include function. Fallback: no include function (undefined).");
170
169
  include = void 0;
171
170
  }
172
171
  if (typeof skipNegativeTabIndexCheck !== "boolean") {
@@ -211,10 +210,8 @@ function isDisabledDeep(element) {
211
210
  if (isInert(current)) {
212
211
  return true;
213
212
  }
214
- if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current)) {
215
- if (!current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
216
- return true;
217
- }
213
+ if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current) && !current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
214
+ return true;
218
215
  }
219
216
  current = current.parentNode;
220
217
  }
@@ -223,10 +220,7 @@ function isDisabledDeep(element) {
223
220
  function normalizeRadioGroup(elements) {
224
221
  let map = null;
225
222
  for (const element of elements) {
226
- if (!(element instanceof HTMLInputElement)) {
227
- continue;
228
- }
229
- if (!isUngroupedRadio(element)) {
223
+ if (!(element instanceof HTMLInputElement) || !isUngroupedRadio(element)) {
230
224
  continue;
231
225
  }
232
226
  if (!map) {
@@ -276,42 +270,24 @@ function getFocusables(container = document.body, options = {}) {
276
270
  console.warn("Invalid container element. Fallback: <body> element.");
277
271
  container = document.body;
278
272
  }
279
- const {
280
- composed,
281
- filter,
282
- include,
283
- skipNegativeTabIndexCheck,
284
- skipVisibilityCheck
285
- } = resolveOptions2(options);
273
+ const { composed, filter, include, skipNegativeTabIndexCheck, skipVisibilityCheck } = resolveOptions2(options);
286
274
  const candidates = [];
287
275
  if (!composed && !include) {
288
276
  for (const match of container.querySelectorAll(
289
277
  !skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR : FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX
290
278
  )) {
291
- match && isFocusable(match, {
292
- skipNegativeTabIndexCheck,
293
- skipVisibilityCheck
294
- }) && candidates.push(match);
279
+ match && isFocusable(match, { skipNegativeTabIndexCheck, skipVisibilityCheck }) && candidates.push(match);
295
280
  }
296
281
  } else {
297
- let traverse2 = function(node) {
298
- if (isFocusable(node, {
299
- skipNegativeTabIndexCheck,
300
- skipVisibilityCheck
301
- }) || include?.(node)) {
302
- candidates.push(node);
282
+ let traverse2 = function(element) {
283
+ if (isFocusable(element, { skipNegativeTabIndexCheck, skipVisibilityCheck }) || include?.(element)) {
284
+ candidates.push(element);
303
285
  }
304
- (!composed ? [...node.children] : getComposedChildren(node)).map(
305
- traverse2
306
- );
286
+ (!composed ? [...element.children] : getComposedChildren(element)).map(traverse2);
307
287
  };
308
- (!composed ? [...container.children] : getComposedChildren(container)).map(
309
- traverse2
310
- );
288
+ (!composed ? [...container.children] : getComposedChildren(container)).map(traverse2);
311
289
  }
312
- return normalizeRadioGroup(
313
- sortByTabIndex(!filter ? candidates : candidates.filter(filter))
314
- );
290
+ return normalizeRadioGroup(sortByTabIndex(!filter ? candidates : candidates.filter(filter)));
315
291
  }
316
292
  function isFocusable(element, options = {}) {
317
293
  if (!(element instanceof Element)) {
@@ -345,39 +321,28 @@ function isFocusable(element, options = {}) {
345
321
 
346
322
  // node_modules/@y14e/roving-tabindex/dist/index.js
347
323
  var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
348
- function getCellCoords(cell) {
324
+ function getCellCenter(cell) {
349
325
  const { left, top, width, height } = cell.getBoundingClientRect();
350
326
  return { x: left + width / 2, y: top + height / 2 };
351
327
  }
352
- function getCellsOfActiveRow(cells) {
353
- const active = getActiveElement();
354
- if (!(active instanceof Element)) {
355
- return [];
356
- }
357
- const activeRect = active.getBoundingClientRect();
358
- return cells.filter((cell) => {
359
- const cellRect = cell.getBoundingClientRect();
360
- return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
361
- });
362
- }
363
328
  function getNextCell(cells, key, wrap) {
364
329
  const active = getActiveElement();
365
330
  if (!(active instanceof Element)) {
366
331
  return null;
367
332
  }
368
- const activeCoords = getCellCoords(active);
333
+ const activeCenter = getCellCenter(active);
369
334
  let min = Infinity;
370
335
  let result = null;
371
336
  for (const cell of cells) {
372
337
  if (cell === active) {
373
338
  continue;
374
339
  }
375
- const cellCoords = getCellCoords(cell);
340
+ const cellCenter = getCellCenter(cell);
376
341
  const distances = {
377
- x: Math.abs(cellCoords.x - activeCoords.x),
378
- y: Math.abs(cellCoords.y - activeCoords.y)
342
+ x: Math.abs(cellCenter.x - activeCenter.x),
343
+ y: Math.abs(cellCenter.y - activeCenter.y)
379
344
  };
380
- if (key === "ArrowUp" && cellCoords.y < activeCoords.y && distances.x < distances.y || key === "ArrowDown" && cellCoords.y > activeCoords.y && distances.x < distances.y) {
345
+ if (key === "ArrowUp" && cellCenter.y < activeCenter.y && distances.x < distances.y || key === "ArrowDown" && cellCenter.y > activeCenter.y && distances.x < distances.y) {
381
346
  const distance = distances.x ** 2 + distances.y ** 2;
382
347
  if (distance < min) {
383
348
  min = distance;
@@ -391,9 +356,9 @@ function getNextCell(cells, key, wrap) {
391
356
  if (cell === active) {
392
357
  continue;
393
358
  }
394
- const cellCoords = getCellCoords(cell);
395
- if (Math.abs(cellCoords.x - activeCoords.x) < cell.getBoundingClientRect().width / 2) {
396
- const distance = key === "ArrowUp" ? cellCoords.y - activeCoords.y : activeCoords.y - cellCoords.y;
359
+ const cellCenter = getCellCenter(cell);
360
+ if (Math.abs(cellCenter.x - activeCenter.x) < cell.getBoundingClientRect().width / 2) {
361
+ const distance = key === "ArrowUp" ? cellCenter.y - activeCenter.y : activeCenter.y - cellCenter.y;
397
362
  if (distance > max) {
398
363
  max = distance;
399
364
  result = cell;
@@ -403,6 +368,13 @@ function getNextCell(cells, key, wrap) {
403
368
  }
404
369
  return result;
405
370
  }
371
+ function getSameRowCells(cells, current) {
372
+ const currentRect = current.getBoundingClientRect();
373
+ return cells.filter((cell) => {
374
+ const cellRect = cell.getBoundingClientRect();
375
+ return cellRect.top < currentRect.bottom && cellRect.bottom > currentRect.top;
376
+ });
377
+ }
406
378
  function resolveOptions3(options) {
407
379
  let {
408
380
  direction = "both",
@@ -414,7 +386,11 @@ function resolveOptions3(options) {
414
386
  wrap = false
415
387
  } = options;
416
388
  if (typeof direction === "string") {
417
- direction = direction.toLowerCase();
389
+ const lower = direction.toLowerCase();
390
+ const found = DIRECTIONS.find((d) => d === lower);
391
+ if (found) {
392
+ direction = found;
393
+ }
418
394
  }
419
395
  if (typeof direction === "string" && !DIRECTIONS.includes(direction) || typeof direction === "function" && !DIRECTIONS.includes(direction())) {
420
396
  console.warn("Invalid direction option. Fallback: 'both'.");
@@ -448,15 +424,7 @@ function resolveOptions3(options) {
448
424
  console.warn("Invalid wrap option. Fallback: false.");
449
425
  wrap = false;
450
426
  }
451
- return {
452
- direction,
453
- navigationOnly,
454
- noMemory,
455
- noStart,
456
- selector,
457
- typeahead,
458
- wrap
459
- };
427
+ return { direction, navigationOnly, noMemory, noStart, selector, typeahead, wrap };
460
428
  }
461
429
  function createRovingTabIndex(container, options = {}) {
462
430
  if (!(container instanceof Element)) {
@@ -502,20 +470,27 @@ var RovingTabIndex = class _RovingTabIndex {
502
470
  this.#controller = new AbortController();
503
471
  const { signal } = this.#controller;
504
472
  container.addEventListener("focusin", this.#onFocusIn, { signal });
505
- this.#settings.noMemory && container.addEventListener("focusout", this.#onFocusOut, {
506
- signal
507
- });
473
+ this.#settings.noMemory && container.addEventListener("focusout", this.#onFocusOut, { signal });
508
474
  container.addEventListener("keydown", this.#onKeyDown, { signal });
509
475
  }
510
476
  #onFocusIn = (event) => {
477
+ if (!(event instanceof FocusEvent)) {
478
+ return;
479
+ }
511
480
  const { target } = event;
512
481
  target instanceof Element && this.#update(target);
513
482
  };
514
483
  #onFocusOut = (event) => {
484
+ if (!(event instanceof FocusEvent)) {
485
+ return;
486
+ }
515
487
  const target = event.relatedTarget;
516
488
  (!(target instanceof Element) || !this.#focusables.has(target)) && this.#update();
517
489
  };
518
490
  #onKeyDown = (event) => {
491
+ if (!(event instanceof KeyboardEvent)) {
492
+ return;
493
+ }
519
494
  const direction = this.#getDirection();
520
495
  const isGrid = direction === "grid";
521
496
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
@@ -523,21 +498,20 @@ var RovingTabIndex = class _RovingTabIndex {
523
498
  return;
524
499
  }
525
500
  const isBoth = direction === "both";
501
+ const is2D = isGrid || isBoth;
526
502
  const isHorizontal = direction === "horizontal";
527
- const { typeahead, wrap = false } = this.#settings;
503
+ const { typeahead, wrap } = this.#settings;
528
504
  if (![
529
505
  "End",
530
506
  "Home",
531
- ...isGrid || isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
532
- ...isGrid || isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
507
+ ...is2D ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
508
+ ...is2D ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
533
509
  ].includes(key)) {
534
510
  if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
535
511
  return;
536
512
  }
537
513
  }
538
- const candidates = this.#getFocusables().filter(
539
- (f) => this.#focusables.has(f)
540
- );
514
+ const candidates = this.#getFocusables().filter((f) => this.#focusables.has(f));
541
515
  const active = getActiveElement();
542
516
  if (!(active instanceof Element)) {
543
517
  return;
@@ -554,7 +528,7 @@ var RovingTabIndex = class _RovingTabIndex {
554
528
  case "Home": {
555
529
  const rawIndex = key === "End" ? -1 : 0;
556
530
  if (isGrid && !ctrlKey) {
557
- const cell = this.#getCellsOfActiveRow().at(rawIndex);
531
+ const cell = this.#getSameRowCells().at(rawIndex);
558
532
  newIndex = cell ? candidates.indexOf(cell) : activeIndex;
559
533
  break;
560
534
  }
@@ -571,11 +545,12 @@ var RovingTabIndex = class _RovingTabIndex {
571
545
  break;
572
546
  }
573
547
  if (isGrid) {
574
- target = this.#getCellsOfActiveRow();
548
+ target = this.#getSameRowCells();
575
549
  }
576
550
  const isPrevious = ["ArrowLeft", "ArrowUp"].includes(key);
577
551
  const rawIndex = (isGrid ? target.indexOf(active) : activeIndex) + (isPrevious ? -1 : 1);
578
- newIndex = isPrevious ? !wrap ? Math.max(rawIndex, 0) : rawIndex : !wrap ? Math.min(rawIndex, target.length - 1) : rawIndex % target.length;
552
+ const { length } = target;
553
+ newIndex = isPrevious ? !wrap ? Math.max(rawIndex, 0) : rawIndex : !wrap ? Math.min(rawIndex, length - 1) : rawIndex % length;
579
554
  break;
580
555
  }
581
556
  default: {
@@ -583,9 +558,7 @@ var RovingTabIndex = class _RovingTabIndex {
583
558
  this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
584
559
  );
585
560
  target = candidates.filter((c) => focusablesByFirstChar.has(c));
586
- const afterIndex = target.findIndex(
587
- (f) => candidates.indexOf(f) > activeIndex
588
- );
561
+ const afterIndex = target.findIndex((f) => candidates.indexOf(f) > activeIndex);
589
562
  newIndex = afterIndex >= 0 ? afterIndex : 0;
590
563
  }
591
564
  }
@@ -615,6 +588,7 @@ var RovingTabIndex = class _RovingTabIndex {
615
588
  continue;
616
589
  }
617
590
  if (_RovingTabIndex.#initialized.has(focusable)) {
591
+ console.warn("Skipping duplicate initialization:", focusable);
618
592
  continue;
619
593
  }
620
594
  this.#focusables.add(focusable);
@@ -634,9 +608,7 @@ var RovingTabIndex = class _RovingTabIndex {
634
608
  if (char) {
635
609
  keys.add(char);
636
610
  saveAttributes(focusable, "aria-keyshortcuts");
637
- addAttributeToken(focusable, "aria-keyshortcuts", char, {
638
- caseInsensitive: true
639
- });
611
+ addAttributeToken(focusable, "aria-keyshortcuts", char, { caseInsensitive: true });
640
612
  }
641
613
  for (const key of keys) {
642
614
  const focusables = this.#focusablesByFirstChar.get(key) ?? [];
@@ -660,9 +632,6 @@ var RovingTabIndex = class _RovingTabIndex {
660
632
  const { selector } = this.#settings;
661
633
  return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
662
634
  }
663
- #getCellsOfActiveRow() {
664
- return getCellsOfActiveRow(this.#getFocusables());
665
- }
666
635
  #getDirection() {
667
636
  const { direction } = this.#settings;
668
637
  if (typeof direction === "string") {
@@ -682,6 +651,10 @@ var RovingTabIndex = class _RovingTabIndex {
682
651
  #getNextCell(key, wrap) {
683
652
  return getNextCell(this.#getFocusables(), key, wrap);
684
653
  }
654
+ #getSameRowCells() {
655
+ const active = getActiveElement();
656
+ return active instanceof Element ? getSameRowCells(this.#getFocusables(), active) : [];
657
+ }
685
658
  };
686
659
 
687
660
  // src/defaults.ts
@@ -748,36 +721,27 @@ var Disclosure = class _Disclosure {
748
721
  return;
749
722
  }
750
723
  this.#rootElement = root;
751
- this.#settings = resolveOptions4(
752
- resolveOptions4(defaults, _Disclosure.defaults),
753
- options
754
- );
724
+ this.#settings = resolveOptions4(resolveOptions4(defaults, _Disclosure.defaults), options);
755
725
  if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
756
726
  this.#settings.animation.duration = 0;
757
727
  }
758
728
  const NOT_NESTED = ":not(:scope summary + * *)";
759
729
  this.#detailsElements = [
760
- ...this.#rootElement.querySelectorAll(
761
- `details${NOT_NESTED}`
762
- )
730
+ ...this.#rootElement.querySelectorAll(`details${NOT_NESTED}`)
763
731
  ];
764
732
  if (!this.#detailsElements.length) {
765
733
  console.warn("Missing <details> elements");
766
734
  return;
767
735
  }
768
736
  this.#summaryElements = [
769
- ...this.#rootElement.querySelectorAll(
770
- `summary${NOT_NESTED}`
771
- )
737
+ ...this.#rootElement.querySelectorAll(`summary${NOT_NESTED}`)
772
738
  ];
773
739
  if (!this.#summaryElements.length) {
774
740
  console.warn("Missing <summary> elements");
775
741
  return;
776
742
  }
777
743
  this.#contentElements = [
778
- ...this.#rootElement.querySelectorAll(
779
- `summary${NOT_NESTED} + *`
780
- )
744
+ ...this.#rootElement.querySelectorAll(`summary${NOT_NESTED} + *`)
781
745
  ];
782
746
  if (!this.#contentElements.length) {
783
747
  console.warn("Missing content elements");
@@ -796,11 +760,11 @@ var Disclosure = class _Disclosure {
796
760
  });
797
761
  this.#initialize();
798
762
  }
799
- collapse(details) {
763
+ close(details) {
800
764
  if (this.#isDestroyed) {
801
765
  return;
802
766
  }
803
- if (!(details instanceof HTMLDetailsElement) || !this.#bindings.has(details)) {
767
+ if (!this.#isValidDetails(details)) {
804
768
  console.warn("Invalid <details> element");
805
769
  return;
806
770
  }
@@ -837,22 +801,18 @@ var Disclosure = class _Disclosure {
837
801
  this.#contentElements.length = 0;
838
802
  this.#rootElement.removeAttribute("data-disclosure-initialized");
839
803
  }
840
- expand(details) {
804
+ open(details) {
841
805
  if (this.#isDestroyed) {
842
806
  return;
843
807
  }
844
- if (!(details instanceof HTMLDetailsElement) || !this.#bindings.has(details)) {
808
+ if (!this.#isValidDetails(details)) {
845
809
  console.warn("Invalid <details> element");
846
810
  return;
847
811
  }
848
812
  this.#toggle(details, true);
849
813
  }
850
814
  #initialize() {
851
- saveAttributes(this.#summaryElements, [
852
- "aria-disabled",
853
- "style",
854
- "tabindex"
855
- ]);
815
+ saveAttributes(this.#summaryElements, ["aria-disabled", "style", "tabindex"]);
856
816
  this.#eventController = new AbortController();
857
817
  const { signal } = this.#eventController;
858
818
  this.#detailsElements.forEach((details, i) => {
@@ -906,22 +866,20 @@ var Disclosure = class _Disclosure {
906
866
  content.style.removeProperty(name2);
907
867
  }
908
868
  }
909
- #toggle(details, isExpand, isProgrammatic = false) {
910
- if (details.hasAttribute("data-disclosure-open") === isExpand) {
869
+ #toggle(details, isOpen, isProgrammatic = false) {
870
+ if (details.hasAttribute("data-disclosure-open") === isOpen) {
911
871
  return;
912
872
  }
913
- if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
914
- (d) => d.hasAttribute("data-disclosure-open")
915
- ).length <= 1) {
873
+ if (!isOpen && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
916
874
  return;
917
875
  }
918
876
  const name = details.getAttribute("data-disclosure-name");
919
- if (name && isExpand) {
877
+ if (name && isOpen) {
920
878
  details.removeAttribute("name");
921
- const expanded = this.#detailsElements.find(
879
+ const opened = this.#detailsElements.find(
922
880
  (d) => d.hasAttribute("data-disclosure-open") && d.getAttribute("data-disclosure-name") === name
923
881
  );
924
- expanded && this.#toggle(expanded, false, true);
882
+ opened && this.#toggle(opened, false, true);
925
883
  }
926
884
  const binding = this.#bindings.get(details);
927
885
  if (!binding) {
@@ -930,12 +888,12 @@ var Disclosure = class _Disclosure {
930
888
  const { content } = binding;
931
889
  const startSize = details.open ? content.offsetHeight : 0;
932
890
  binding.animation?.cancel();
933
- if (isExpand) {
891
+ if (isOpen) {
934
892
  details.open = true;
935
893
  }
936
- const endSize = isExpand ? content.scrollHeight : 0;
894
+ const endSize = isOpen ? content.scrollHeight : 0;
937
895
  binding.animation?.cancel();
938
- details.toggleAttribute("data-disclosure-open", isExpand);
896
+ details.toggleAttribute("data-disclosure-open", isOpen);
939
897
  content.style.setProperty("overflow", "clip");
940
898
  const { duration, easing } = this.#settings.animation;
941
899
  const animation = content.animate(
@@ -968,6 +926,9 @@ var Disclosure = class _Disclosure {
968
926
  #isFocusable(element) {
969
927
  return element.tabIndex >= 0;
970
928
  }
929
+ #isValidDetails(details) {
930
+ return details instanceof HTMLDetailsElement && this.#bindings.has(details);
931
+ }
971
932
  async #waitAnimationsFinish() {
972
933
  const promises = [];
973
934
  for (const content of this.#contentElements) {