@y14e/disclosure 2.2.5 → 3.0.1
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 +6 -6
- package/dist/index.bundle.cjs +54 -74
- package/dist/index.bundle.js +54 -74
- package/dist/index.cjs +26 -28
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +26 -28
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -23,10 +23,10 @@ import { Disclosure } from 'https://esm.unpkg.com/@y14e/disclosure@<x.x.x>';
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
25
|
```ts
|
|
26
|
-
new Disclosure(
|
|
26
|
+
new Disclosure(element, options);
|
|
27
27
|
// => Disclosure
|
|
28
28
|
//
|
|
29
|
-
//
|
|
29
|
+
// element: HTMLElement
|
|
30
30
|
// options (optional): DisclosureOptions
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -60,10 +60,10 @@ new Disclosure(root);
|
|
|
60
60
|
|
|
61
61
|
## 📦 APIs
|
|
62
62
|
|
|
63
|
-
### `
|
|
63
|
+
### `close`
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
|
-
disclosure.
|
|
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
|
-
### `
|
|
83
|
+
### `open`
|
|
84
84
|
|
|
85
85
|
```ts
|
|
86
|
-
disclosure.
|
|
86
|
+
disclosure.open(details);
|
|
87
87
|
// => void
|
|
88
88
|
//
|
|
89
89
|
// details: HTMLDetailsElement
|
package/dist/index.bundle.cjs
CHANGED
|
@@ -66,25 +66,17 @@ function isValid(element, name, token) {
|
|
|
66
66
|
return true;
|
|
67
67
|
}
|
|
68
68
|
function resolveOptions(options) {
|
|
69
|
-
let {
|
|
70
|
-
caseInsensitive = false,
|
|
71
|
-
parse = DEFAULT_PARSER,
|
|
72
|
-
serialize = DEFAULT_SERIALIZER
|
|
73
|
-
} = options;
|
|
69
|
+
let { caseInsensitive = false, parse = DEFAULT_PARSER, serialize = DEFAULT_SERIALIZER } = options;
|
|
74
70
|
if (typeof caseInsensitive !== "boolean") {
|
|
75
71
|
console.warn("Invalid caseInsensitive option. Fallback: false.");
|
|
76
72
|
caseInsensitive = false;
|
|
77
73
|
}
|
|
78
74
|
if (typeof parse !== "function") {
|
|
79
|
-
console.warn(
|
|
80
|
-
"Invalid parser. Fallback: default parser (splits by whitespace)."
|
|
81
|
-
);
|
|
75
|
+
console.warn("Invalid parser. Fallback: default parser (splits by whitespace).");
|
|
82
76
|
parse = DEFAULT_PARSER;
|
|
83
77
|
}
|
|
84
78
|
if (typeof serialize !== "function") {
|
|
85
|
-
console.warn(
|
|
86
|
-
"Invalid serializer. Fallback: default serializer (joins by whitespace)."
|
|
87
|
-
);
|
|
79
|
+
console.warn("Invalid serializer. Fallback: default serializer (joins by whitespace).");
|
|
88
80
|
serialize = DEFAULT_SERIALIZER;
|
|
89
81
|
}
|
|
90
82
|
return { caseInsensitive, parse, serialize };
|
|
@@ -239,7 +231,7 @@ function normalizeRadioGroup(elements) {
|
|
|
239
231
|
(radios.get(name) ?? radios.set(name, []).get(name))?.push(element);
|
|
240
232
|
}
|
|
241
233
|
if (!map) {
|
|
242
|
-
return elements;
|
|
234
|
+
return elements.slice();
|
|
243
235
|
}
|
|
244
236
|
const placeholder = /* @__PURE__ */ new Set();
|
|
245
237
|
for (const v of map.values()) {
|
|
@@ -250,20 +242,12 @@ function normalizeRadioGroup(elements) {
|
|
|
250
242
|
}
|
|
251
243
|
}
|
|
252
244
|
}
|
|
253
|
-
return elements.filter(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
return !isUngroupedRadio(element) || placeholder.has(element);
|
|
258
|
-
});
|
|
245
|
+
return elements.filter(
|
|
246
|
+
(e) => !(e instanceof HTMLInputElement) || !isUngroupedRadio(e) || placeholder.has(e)
|
|
247
|
+
);
|
|
259
248
|
}
|
|
260
249
|
function sortByTabIndex(elements) {
|
|
261
|
-
|
|
262
|
-
const natural = [];
|
|
263
|
-
for (const element of elements) {
|
|
264
|
-
(getTabIndex(element) > 0 ? ordered : natural).push(element);
|
|
265
|
-
}
|
|
266
|
-
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
250
|
+
return elements.filter((e) => getTabIndex(e) > 0).sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(elements.filter((e) => getTabIndex(e) <= 0));
|
|
267
251
|
}
|
|
268
252
|
function getFocusables(container = document.body, options = {}) {
|
|
269
253
|
if (!(container instanceof Element)) {
|
|
@@ -321,44 +305,41 @@ function isFocusable(element, options = {}) {
|
|
|
321
305
|
|
|
322
306
|
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
323
307
|
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
324
|
-
function
|
|
325
|
-
const {
|
|
326
|
-
return { x:
|
|
308
|
+
function getCellRect(cell) {
|
|
309
|
+
const { x, y, width: w, height: h } = cell.getBoundingClientRect();
|
|
310
|
+
return { w, x: x + w / 2, y: y + h / 2 };
|
|
327
311
|
}
|
|
328
|
-
function getNextCell(cells, key,
|
|
312
|
+
function getNextCell(cells, key, isWrap) {
|
|
329
313
|
const active = getActiveElement();
|
|
330
314
|
if (!(active instanceof Element)) {
|
|
331
315
|
return null;
|
|
332
316
|
}
|
|
333
|
-
const
|
|
317
|
+
const { x: ax, y: ay } = getCellRect(active);
|
|
334
318
|
let min = Infinity;
|
|
335
319
|
let result = null;
|
|
336
320
|
for (const cell of cells) {
|
|
337
321
|
if (cell === active) {
|
|
338
322
|
continue;
|
|
339
323
|
}
|
|
340
|
-
const
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
};
|
|
345
|
-
if (key === "ArrowUp" && cellCenter.y < activeCenter.y && distances.x < distances.y || key === "ArrowDown" && cellCenter.y > activeCenter.y && distances.x < distances.y) {
|
|
346
|
-
const distance = distances.x ** 2 + distances.y ** 2;
|
|
324
|
+
const { x: cx, y: cy } = getCellRect(cell);
|
|
325
|
+
const [dx, dy] = [Math.abs(cx - ax), Math.abs(cy - ay)];
|
|
326
|
+
if (key === "ArrowUp" && cy < ay && dx < dy || key === "ArrowDown" && cy > ay && dx < dy) {
|
|
327
|
+
const distance = dx ** 2 + dy ** 2;
|
|
347
328
|
if (distance < min) {
|
|
348
329
|
min = distance;
|
|
349
330
|
result = cell;
|
|
350
331
|
}
|
|
351
332
|
}
|
|
352
333
|
}
|
|
353
|
-
if (!result &&
|
|
334
|
+
if (!result && isWrap) {
|
|
354
335
|
let max = -Infinity;
|
|
355
336
|
for (const cell of cells) {
|
|
356
337
|
if (cell === active) {
|
|
357
338
|
continue;
|
|
358
339
|
}
|
|
359
|
-
const
|
|
360
|
-
if (Math.abs(
|
|
361
|
-
const distance = key === "ArrowUp" ?
|
|
340
|
+
const { x: cx, y: cy, w: cw } = getCellRect(cell);
|
|
341
|
+
if (Math.abs(cx - ax) < cw / 2) {
|
|
342
|
+
const distance = key === "ArrowUp" ? cy - ay : ay - cy;
|
|
362
343
|
if (distance > max) {
|
|
363
344
|
max = distance;
|
|
364
345
|
result = cell;
|
|
@@ -368,11 +349,11 @@ function getNextCell(cells, key, wrap) {
|
|
|
368
349
|
}
|
|
369
350
|
return result;
|
|
370
351
|
}
|
|
371
|
-
function getSameRowCells(cells,
|
|
372
|
-
const
|
|
352
|
+
function getSameRowCells(cells, anchor) {
|
|
353
|
+
const { y: ay, bottom: ab } = anchor.getBoundingClientRect();
|
|
373
354
|
return cells.filter((cell) => {
|
|
374
|
-
const
|
|
375
|
-
return
|
|
355
|
+
const { y: cy, bottom: cb } = cell.getBoundingClientRect();
|
|
356
|
+
return cy < ab && cb > ay;
|
|
376
357
|
});
|
|
377
358
|
}
|
|
378
359
|
function resolveOptions3(options) {
|
|
@@ -588,6 +569,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
588
569
|
continue;
|
|
589
570
|
}
|
|
590
571
|
if (_RovingTabIndex.#initialized.has(focusable)) {
|
|
572
|
+
console.warn("Skipping duplicate initialization:", focusable);
|
|
591
573
|
continue;
|
|
592
574
|
}
|
|
593
575
|
this.#focusables.add(focusable);
|
|
@@ -647,8 +629,8 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
647
629
|
skipVisibilityCheck: true
|
|
648
630
|
});
|
|
649
631
|
}
|
|
650
|
-
#getNextCell(key,
|
|
651
|
-
return getNextCell(this.#getFocusables(), key,
|
|
632
|
+
#getNextCell(key, isWrap) {
|
|
633
|
+
return getNextCell(this.#getFocusables(), key, isWrap);
|
|
652
634
|
}
|
|
653
635
|
#getSameRowCells() {
|
|
654
636
|
const active = getActiveElement();
|
|
@@ -700,7 +682,7 @@ function resolveOptions4(defaults2, source) {
|
|
|
700
682
|
// src/index.ts
|
|
701
683
|
var Disclosure = class _Disclosure {
|
|
702
684
|
static defaults = {};
|
|
703
|
-
#
|
|
685
|
+
#element;
|
|
704
686
|
#settings;
|
|
705
687
|
#detailsElements;
|
|
706
688
|
#summaryElements;
|
|
@@ -711,36 +693,36 @@ var Disclosure = class _Disclosure {
|
|
|
711
693
|
#observers = [];
|
|
712
694
|
#cleanupRovingTabIndex = null;
|
|
713
695
|
#isDestroyed = false;
|
|
714
|
-
constructor(
|
|
715
|
-
if (!(
|
|
716
|
-
throw new TypeError("Invalid
|
|
696
|
+
constructor(element, options = {}) {
|
|
697
|
+
if (!(element instanceof HTMLElement)) {
|
|
698
|
+
throw new TypeError("Invalid element");
|
|
717
699
|
}
|
|
718
|
-
if (
|
|
700
|
+
if (element.hasAttribute("data-disclosure-initialized")) {
|
|
719
701
|
console.warn("Already initialized");
|
|
720
702
|
return;
|
|
721
703
|
}
|
|
722
|
-
this.#
|
|
704
|
+
this.#element = element;
|
|
723
705
|
this.#settings = resolveOptions4(resolveOptions4(defaults, _Disclosure.defaults), options);
|
|
724
706
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
725
707
|
this.#settings.animation.duration = 0;
|
|
726
708
|
}
|
|
727
709
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
728
710
|
this.#detailsElements = [
|
|
729
|
-
...this.#
|
|
711
|
+
...this.#element.querySelectorAll(`details${NOT_NESTED}`)
|
|
730
712
|
];
|
|
731
713
|
if (!this.#detailsElements.length) {
|
|
732
714
|
console.warn("Missing <details> elements");
|
|
733
715
|
return;
|
|
734
716
|
}
|
|
735
717
|
this.#summaryElements = [
|
|
736
|
-
...this.#
|
|
718
|
+
...this.#element.querySelectorAll(`summary${NOT_NESTED}`)
|
|
737
719
|
];
|
|
738
720
|
if (!this.#summaryElements.length) {
|
|
739
721
|
console.warn("Missing <summary> elements");
|
|
740
722
|
return;
|
|
741
723
|
}
|
|
742
724
|
this.#contentElements = [
|
|
743
|
-
...this.#
|
|
725
|
+
...this.#element.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
744
726
|
];
|
|
745
727
|
if (!this.#contentElements.length) {
|
|
746
728
|
console.warn("Missing content elements");
|
|
@@ -753,13 +735,13 @@ var Disclosure = class _Disclosure {
|
|
|
753
735
|
return;
|
|
754
736
|
}
|
|
755
737
|
const binding = this.#createBinding(details, summary, content);
|
|
756
|
-
[details, summary, content].forEach((
|
|
757
|
-
this.#bindings.set(
|
|
738
|
+
[details, summary, content].forEach((element2) => {
|
|
739
|
+
this.#bindings.set(element2, binding);
|
|
758
740
|
});
|
|
759
741
|
});
|
|
760
742
|
this.#initialize();
|
|
761
743
|
}
|
|
762
|
-
|
|
744
|
+
close(details) {
|
|
763
745
|
if (this.#isDestroyed) {
|
|
764
746
|
return;
|
|
765
747
|
}
|
|
@@ -798,9 +780,9 @@ var Disclosure = class _Disclosure {
|
|
|
798
780
|
restoreAttributes(this.#summaryElements);
|
|
799
781
|
this.#summaryElements.length = 0;
|
|
800
782
|
this.#contentElements.length = 0;
|
|
801
|
-
this.#
|
|
783
|
+
this.#element.removeAttribute("data-disclosure-initialized");
|
|
802
784
|
}
|
|
803
|
-
|
|
785
|
+
open(details) {
|
|
804
786
|
if (this.#isDestroyed) {
|
|
805
787
|
return;
|
|
806
788
|
}
|
|
@@ -834,13 +816,13 @@ var Disclosure = class _Disclosure {
|
|
|
834
816
|
}
|
|
835
817
|
summary.addEventListener("click", this.#onSummaryClick, { signal });
|
|
836
818
|
});
|
|
837
|
-
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#
|
|
819
|
+
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#element, {
|
|
838
820
|
direction: "vertical",
|
|
839
821
|
navigationOnly: true,
|
|
840
822
|
selector: "summary:not(:scope summary + * *)",
|
|
841
823
|
wrap: true
|
|
842
824
|
});
|
|
843
|
-
this.#
|
|
825
|
+
this.#element.setAttribute("data-disclosure-initialized", "");
|
|
844
826
|
}
|
|
845
827
|
#onSummaryClick = (event) => {
|
|
846
828
|
event.preventDefault();
|
|
@@ -865,20 +847,20 @@ var Disclosure = class _Disclosure {
|
|
|
865
847
|
content.style.removeProperty(name2);
|
|
866
848
|
}
|
|
867
849
|
}
|
|
868
|
-
#toggle(details,
|
|
869
|
-
if (details.hasAttribute("data-disclosure-open") ===
|
|
850
|
+
#toggle(details, isOpen, isProgrammatic = false) {
|
|
851
|
+
if (details.hasAttribute("data-disclosure-open") === isOpen) {
|
|
870
852
|
return;
|
|
871
853
|
}
|
|
872
|
-
if (!
|
|
854
|
+
if (!isOpen && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
873
855
|
return;
|
|
874
856
|
}
|
|
875
857
|
const name = details.getAttribute("data-disclosure-name");
|
|
876
|
-
if (name &&
|
|
858
|
+
if (name && isOpen) {
|
|
877
859
|
details.removeAttribute("name");
|
|
878
|
-
const
|
|
860
|
+
const opened = this.#detailsElements.find(
|
|
879
861
|
(d) => d.hasAttribute("data-disclosure-open") && d.getAttribute("data-disclosure-name") === name
|
|
880
862
|
);
|
|
881
|
-
|
|
863
|
+
opened && this.#toggle(opened, false, true);
|
|
882
864
|
}
|
|
883
865
|
const binding = this.#bindings.get(details);
|
|
884
866
|
if (!binding) {
|
|
@@ -887,12 +869,12 @@ var Disclosure = class _Disclosure {
|
|
|
887
869
|
const { content } = binding;
|
|
888
870
|
const startSize = details.open ? content.offsetHeight : 0;
|
|
889
871
|
binding.animation?.cancel();
|
|
890
|
-
if (
|
|
872
|
+
if (isOpen) {
|
|
891
873
|
details.open = true;
|
|
892
874
|
}
|
|
893
|
-
const endSize =
|
|
875
|
+
const endSize = isOpen ? content.scrollHeight : 0;
|
|
894
876
|
binding.animation?.cancel();
|
|
895
|
-
details.toggleAttribute("data-disclosure-open",
|
|
877
|
+
details.toggleAttribute("data-disclosure-open", isOpen);
|
|
896
878
|
content.style.setProperty("overflow", "clip");
|
|
897
879
|
const { duration, easing } = this.#settings.animation;
|
|
898
880
|
const animation = content.animate(
|
|
@@ -938,9 +920,7 @@ var Disclosure = class _Disclosure {
|
|
|
938
920
|
}
|
|
939
921
|
};
|
|
940
922
|
function waitAnimationFinish(animation) {
|
|
941
|
-
return ["finished", "idle"].includes(animation.playState) ? Promise.resolve() : new Promise(
|
|
942
|
-
(resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
|
|
943
|
-
);
|
|
923
|
+
return ["finished", "idle"].includes(animation.playState) ? Promise.resolve() : new Promise((r) => animation.addEventListener("finish", () => r(), { once: true }));
|
|
944
924
|
}
|
|
945
925
|
|
|
946
926
|
exports.Disclosure = Disclosure;
|
package/dist/index.bundle.js
CHANGED
|
@@ -64,25 +64,17 @@ function isValid(element, name, token) {
|
|
|
64
64
|
return true;
|
|
65
65
|
}
|
|
66
66
|
function resolveOptions(options) {
|
|
67
|
-
let {
|
|
68
|
-
caseInsensitive = false,
|
|
69
|
-
parse = DEFAULT_PARSER,
|
|
70
|
-
serialize = DEFAULT_SERIALIZER
|
|
71
|
-
} = options;
|
|
67
|
+
let { caseInsensitive = false, parse = DEFAULT_PARSER, serialize = DEFAULT_SERIALIZER } = options;
|
|
72
68
|
if (typeof caseInsensitive !== "boolean") {
|
|
73
69
|
console.warn("Invalid caseInsensitive option. Fallback: false.");
|
|
74
70
|
caseInsensitive = false;
|
|
75
71
|
}
|
|
76
72
|
if (typeof parse !== "function") {
|
|
77
|
-
console.warn(
|
|
78
|
-
"Invalid parser. Fallback: default parser (splits by whitespace)."
|
|
79
|
-
);
|
|
73
|
+
console.warn("Invalid parser. Fallback: default parser (splits by whitespace).");
|
|
80
74
|
parse = DEFAULT_PARSER;
|
|
81
75
|
}
|
|
82
76
|
if (typeof serialize !== "function") {
|
|
83
|
-
console.warn(
|
|
84
|
-
"Invalid serializer. Fallback: default serializer (joins by whitespace)."
|
|
85
|
-
);
|
|
77
|
+
console.warn("Invalid serializer. Fallback: default serializer (joins by whitespace).");
|
|
86
78
|
serialize = DEFAULT_SERIALIZER;
|
|
87
79
|
}
|
|
88
80
|
return { caseInsensitive, parse, serialize };
|
|
@@ -237,7 +229,7 @@ function normalizeRadioGroup(elements) {
|
|
|
237
229
|
(radios.get(name) ?? radios.set(name, []).get(name))?.push(element);
|
|
238
230
|
}
|
|
239
231
|
if (!map) {
|
|
240
|
-
return elements;
|
|
232
|
+
return elements.slice();
|
|
241
233
|
}
|
|
242
234
|
const placeholder = /* @__PURE__ */ new Set();
|
|
243
235
|
for (const v of map.values()) {
|
|
@@ -248,20 +240,12 @@ function normalizeRadioGroup(elements) {
|
|
|
248
240
|
}
|
|
249
241
|
}
|
|
250
242
|
}
|
|
251
|
-
return elements.filter(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
return !isUngroupedRadio(element) || placeholder.has(element);
|
|
256
|
-
});
|
|
243
|
+
return elements.filter(
|
|
244
|
+
(e) => !(e instanceof HTMLInputElement) || !isUngroupedRadio(e) || placeholder.has(e)
|
|
245
|
+
);
|
|
257
246
|
}
|
|
258
247
|
function sortByTabIndex(elements) {
|
|
259
|
-
|
|
260
|
-
const natural = [];
|
|
261
|
-
for (const element of elements) {
|
|
262
|
-
(getTabIndex(element) > 0 ? ordered : natural).push(element);
|
|
263
|
-
}
|
|
264
|
-
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
248
|
+
return elements.filter((e) => getTabIndex(e) > 0).sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(elements.filter((e) => getTabIndex(e) <= 0));
|
|
265
249
|
}
|
|
266
250
|
function getFocusables(container = document.body, options = {}) {
|
|
267
251
|
if (!(container instanceof Element)) {
|
|
@@ -319,44 +303,41 @@ function isFocusable(element, options = {}) {
|
|
|
319
303
|
|
|
320
304
|
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
321
305
|
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
322
|
-
function
|
|
323
|
-
const {
|
|
324
|
-
return { x:
|
|
306
|
+
function getCellRect(cell) {
|
|
307
|
+
const { x, y, width: w, height: h } = cell.getBoundingClientRect();
|
|
308
|
+
return { w, x: x + w / 2, y: y + h / 2 };
|
|
325
309
|
}
|
|
326
|
-
function getNextCell(cells, key,
|
|
310
|
+
function getNextCell(cells, key, isWrap) {
|
|
327
311
|
const active = getActiveElement();
|
|
328
312
|
if (!(active instanceof Element)) {
|
|
329
313
|
return null;
|
|
330
314
|
}
|
|
331
|
-
const
|
|
315
|
+
const { x: ax, y: ay } = getCellRect(active);
|
|
332
316
|
let min = Infinity;
|
|
333
317
|
let result = null;
|
|
334
318
|
for (const cell of cells) {
|
|
335
319
|
if (cell === active) {
|
|
336
320
|
continue;
|
|
337
321
|
}
|
|
338
|
-
const
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
};
|
|
343
|
-
if (key === "ArrowUp" && cellCenter.y < activeCenter.y && distances.x < distances.y || key === "ArrowDown" && cellCenter.y > activeCenter.y && distances.x < distances.y) {
|
|
344
|
-
const distance = distances.x ** 2 + distances.y ** 2;
|
|
322
|
+
const { x: cx, y: cy } = getCellRect(cell);
|
|
323
|
+
const [dx, dy] = [Math.abs(cx - ax), Math.abs(cy - ay)];
|
|
324
|
+
if (key === "ArrowUp" && cy < ay && dx < dy || key === "ArrowDown" && cy > ay && dx < dy) {
|
|
325
|
+
const distance = dx ** 2 + dy ** 2;
|
|
345
326
|
if (distance < min) {
|
|
346
327
|
min = distance;
|
|
347
328
|
result = cell;
|
|
348
329
|
}
|
|
349
330
|
}
|
|
350
331
|
}
|
|
351
|
-
if (!result &&
|
|
332
|
+
if (!result && isWrap) {
|
|
352
333
|
let max = -Infinity;
|
|
353
334
|
for (const cell of cells) {
|
|
354
335
|
if (cell === active) {
|
|
355
336
|
continue;
|
|
356
337
|
}
|
|
357
|
-
const
|
|
358
|
-
if (Math.abs(
|
|
359
|
-
const distance = key === "ArrowUp" ?
|
|
338
|
+
const { x: cx, y: cy, w: cw } = getCellRect(cell);
|
|
339
|
+
if (Math.abs(cx - ax) < cw / 2) {
|
|
340
|
+
const distance = key === "ArrowUp" ? cy - ay : ay - cy;
|
|
360
341
|
if (distance > max) {
|
|
361
342
|
max = distance;
|
|
362
343
|
result = cell;
|
|
@@ -366,11 +347,11 @@ function getNextCell(cells, key, wrap) {
|
|
|
366
347
|
}
|
|
367
348
|
return result;
|
|
368
349
|
}
|
|
369
|
-
function getSameRowCells(cells,
|
|
370
|
-
const
|
|
350
|
+
function getSameRowCells(cells, anchor) {
|
|
351
|
+
const { y: ay, bottom: ab } = anchor.getBoundingClientRect();
|
|
371
352
|
return cells.filter((cell) => {
|
|
372
|
-
const
|
|
373
|
-
return
|
|
353
|
+
const { y: cy, bottom: cb } = cell.getBoundingClientRect();
|
|
354
|
+
return cy < ab && cb > ay;
|
|
374
355
|
});
|
|
375
356
|
}
|
|
376
357
|
function resolveOptions3(options) {
|
|
@@ -586,6 +567,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
586
567
|
continue;
|
|
587
568
|
}
|
|
588
569
|
if (_RovingTabIndex.#initialized.has(focusable)) {
|
|
570
|
+
console.warn("Skipping duplicate initialization:", focusable);
|
|
589
571
|
continue;
|
|
590
572
|
}
|
|
591
573
|
this.#focusables.add(focusable);
|
|
@@ -645,8 +627,8 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
645
627
|
skipVisibilityCheck: true
|
|
646
628
|
});
|
|
647
629
|
}
|
|
648
|
-
#getNextCell(key,
|
|
649
|
-
return getNextCell(this.#getFocusables(), key,
|
|
630
|
+
#getNextCell(key, isWrap) {
|
|
631
|
+
return getNextCell(this.#getFocusables(), key, isWrap);
|
|
650
632
|
}
|
|
651
633
|
#getSameRowCells() {
|
|
652
634
|
const active = getActiveElement();
|
|
@@ -698,7 +680,7 @@ function resolveOptions4(defaults2, source) {
|
|
|
698
680
|
// src/index.ts
|
|
699
681
|
var Disclosure = class _Disclosure {
|
|
700
682
|
static defaults = {};
|
|
701
|
-
#
|
|
683
|
+
#element;
|
|
702
684
|
#settings;
|
|
703
685
|
#detailsElements;
|
|
704
686
|
#summaryElements;
|
|
@@ -709,36 +691,36 @@ var Disclosure = class _Disclosure {
|
|
|
709
691
|
#observers = [];
|
|
710
692
|
#cleanupRovingTabIndex = null;
|
|
711
693
|
#isDestroyed = false;
|
|
712
|
-
constructor(
|
|
713
|
-
if (!(
|
|
714
|
-
throw new TypeError("Invalid
|
|
694
|
+
constructor(element, options = {}) {
|
|
695
|
+
if (!(element instanceof HTMLElement)) {
|
|
696
|
+
throw new TypeError("Invalid element");
|
|
715
697
|
}
|
|
716
|
-
if (
|
|
698
|
+
if (element.hasAttribute("data-disclosure-initialized")) {
|
|
717
699
|
console.warn("Already initialized");
|
|
718
700
|
return;
|
|
719
701
|
}
|
|
720
|
-
this.#
|
|
702
|
+
this.#element = element;
|
|
721
703
|
this.#settings = resolveOptions4(resolveOptions4(defaults, _Disclosure.defaults), options);
|
|
722
704
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
723
705
|
this.#settings.animation.duration = 0;
|
|
724
706
|
}
|
|
725
707
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
726
708
|
this.#detailsElements = [
|
|
727
|
-
...this.#
|
|
709
|
+
...this.#element.querySelectorAll(`details${NOT_NESTED}`)
|
|
728
710
|
];
|
|
729
711
|
if (!this.#detailsElements.length) {
|
|
730
712
|
console.warn("Missing <details> elements");
|
|
731
713
|
return;
|
|
732
714
|
}
|
|
733
715
|
this.#summaryElements = [
|
|
734
|
-
...this.#
|
|
716
|
+
...this.#element.querySelectorAll(`summary${NOT_NESTED}`)
|
|
735
717
|
];
|
|
736
718
|
if (!this.#summaryElements.length) {
|
|
737
719
|
console.warn("Missing <summary> elements");
|
|
738
720
|
return;
|
|
739
721
|
}
|
|
740
722
|
this.#contentElements = [
|
|
741
|
-
...this.#
|
|
723
|
+
...this.#element.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
742
724
|
];
|
|
743
725
|
if (!this.#contentElements.length) {
|
|
744
726
|
console.warn("Missing content elements");
|
|
@@ -751,13 +733,13 @@ var Disclosure = class _Disclosure {
|
|
|
751
733
|
return;
|
|
752
734
|
}
|
|
753
735
|
const binding = this.#createBinding(details, summary, content);
|
|
754
|
-
[details, summary, content].forEach((
|
|
755
|
-
this.#bindings.set(
|
|
736
|
+
[details, summary, content].forEach((element2) => {
|
|
737
|
+
this.#bindings.set(element2, binding);
|
|
756
738
|
});
|
|
757
739
|
});
|
|
758
740
|
this.#initialize();
|
|
759
741
|
}
|
|
760
|
-
|
|
742
|
+
close(details) {
|
|
761
743
|
if (this.#isDestroyed) {
|
|
762
744
|
return;
|
|
763
745
|
}
|
|
@@ -796,9 +778,9 @@ var Disclosure = class _Disclosure {
|
|
|
796
778
|
restoreAttributes(this.#summaryElements);
|
|
797
779
|
this.#summaryElements.length = 0;
|
|
798
780
|
this.#contentElements.length = 0;
|
|
799
|
-
this.#
|
|
781
|
+
this.#element.removeAttribute("data-disclosure-initialized");
|
|
800
782
|
}
|
|
801
|
-
|
|
783
|
+
open(details) {
|
|
802
784
|
if (this.#isDestroyed) {
|
|
803
785
|
return;
|
|
804
786
|
}
|
|
@@ -832,13 +814,13 @@ var Disclosure = class _Disclosure {
|
|
|
832
814
|
}
|
|
833
815
|
summary.addEventListener("click", this.#onSummaryClick, { signal });
|
|
834
816
|
});
|
|
835
|
-
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#
|
|
817
|
+
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#element, {
|
|
836
818
|
direction: "vertical",
|
|
837
819
|
navigationOnly: true,
|
|
838
820
|
selector: "summary:not(:scope summary + * *)",
|
|
839
821
|
wrap: true
|
|
840
822
|
});
|
|
841
|
-
this.#
|
|
823
|
+
this.#element.setAttribute("data-disclosure-initialized", "");
|
|
842
824
|
}
|
|
843
825
|
#onSummaryClick = (event) => {
|
|
844
826
|
event.preventDefault();
|
|
@@ -863,20 +845,20 @@ var Disclosure = class _Disclosure {
|
|
|
863
845
|
content.style.removeProperty(name2);
|
|
864
846
|
}
|
|
865
847
|
}
|
|
866
|
-
#toggle(details,
|
|
867
|
-
if (details.hasAttribute("data-disclosure-open") ===
|
|
848
|
+
#toggle(details, isOpen, isProgrammatic = false) {
|
|
849
|
+
if (details.hasAttribute("data-disclosure-open") === isOpen) {
|
|
868
850
|
return;
|
|
869
851
|
}
|
|
870
|
-
if (!
|
|
852
|
+
if (!isOpen && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
871
853
|
return;
|
|
872
854
|
}
|
|
873
855
|
const name = details.getAttribute("data-disclosure-name");
|
|
874
|
-
if (name &&
|
|
856
|
+
if (name && isOpen) {
|
|
875
857
|
details.removeAttribute("name");
|
|
876
|
-
const
|
|
858
|
+
const opened = this.#detailsElements.find(
|
|
877
859
|
(d) => d.hasAttribute("data-disclosure-open") && d.getAttribute("data-disclosure-name") === name
|
|
878
860
|
);
|
|
879
|
-
|
|
861
|
+
opened && this.#toggle(opened, false, true);
|
|
880
862
|
}
|
|
881
863
|
const binding = this.#bindings.get(details);
|
|
882
864
|
if (!binding) {
|
|
@@ -885,12 +867,12 @@ var Disclosure = class _Disclosure {
|
|
|
885
867
|
const { content } = binding;
|
|
886
868
|
const startSize = details.open ? content.offsetHeight : 0;
|
|
887
869
|
binding.animation?.cancel();
|
|
888
|
-
if (
|
|
870
|
+
if (isOpen) {
|
|
889
871
|
details.open = true;
|
|
890
872
|
}
|
|
891
|
-
const endSize =
|
|
873
|
+
const endSize = isOpen ? content.scrollHeight : 0;
|
|
892
874
|
binding.animation?.cancel();
|
|
893
|
-
details.toggleAttribute("data-disclosure-open",
|
|
875
|
+
details.toggleAttribute("data-disclosure-open", isOpen);
|
|
894
876
|
content.style.setProperty("overflow", "clip");
|
|
895
877
|
const { duration, easing } = this.#settings.animation;
|
|
896
878
|
const animation = content.animate(
|
|
@@ -936,9 +918,7 @@ var Disclosure = class _Disclosure {
|
|
|
936
918
|
}
|
|
937
919
|
};
|
|
938
920
|
function waitAnimationFinish(animation) {
|
|
939
|
-
return ["finished", "idle"].includes(animation.playState) ? Promise.resolve() : new Promise(
|
|
940
|
-
(resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
|
|
941
|
-
);
|
|
921
|
+
return ["finished", "idle"].includes(animation.playState) ? Promise.resolve() : new Promise((r) => animation.addEventListener("finish", () => r(), { once: true }));
|
|
942
922
|
}
|
|
943
923
|
|
|
944
924
|
export { Disclosure };
|
package/dist/index.cjs
CHANGED
|
@@ -49,7 +49,7 @@ function resolveOptions(defaults2, source) {
|
|
|
49
49
|
// src/index.ts
|
|
50
50
|
var Disclosure = class _Disclosure {
|
|
51
51
|
static defaults = {};
|
|
52
|
-
#
|
|
52
|
+
#element;
|
|
53
53
|
#settings;
|
|
54
54
|
#detailsElements;
|
|
55
55
|
#summaryElements;
|
|
@@ -60,36 +60,36 @@ var Disclosure = class _Disclosure {
|
|
|
60
60
|
#observers = [];
|
|
61
61
|
#cleanupRovingTabIndex = null;
|
|
62
62
|
#isDestroyed = false;
|
|
63
|
-
constructor(
|
|
64
|
-
if (!(
|
|
65
|
-
throw new TypeError("Invalid
|
|
63
|
+
constructor(element, options = {}) {
|
|
64
|
+
if (!(element instanceof HTMLElement)) {
|
|
65
|
+
throw new TypeError("Invalid element");
|
|
66
66
|
}
|
|
67
|
-
if (
|
|
67
|
+
if (element.hasAttribute("data-disclosure-initialized")) {
|
|
68
68
|
console.warn("Already initialized");
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
this.#
|
|
71
|
+
this.#element = element;
|
|
72
72
|
this.#settings = resolveOptions(resolveOptions(defaults, _Disclosure.defaults), options);
|
|
73
73
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
74
74
|
this.#settings.animation.duration = 0;
|
|
75
75
|
}
|
|
76
76
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
77
77
|
this.#detailsElements = [
|
|
78
|
-
...this.#
|
|
78
|
+
...this.#element.querySelectorAll(`details${NOT_NESTED}`)
|
|
79
79
|
];
|
|
80
80
|
if (!this.#detailsElements.length) {
|
|
81
81
|
console.warn("Missing <details> elements");
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
84
|
this.#summaryElements = [
|
|
85
|
-
...this.#
|
|
85
|
+
...this.#element.querySelectorAll(`summary${NOT_NESTED}`)
|
|
86
86
|
];
|
|
87
87
|
if (!this.#summaryElements.length) {
|
|
88
88
|
console.warn("Missing <summary> elements");
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
91
|
this.#contentElements = [
|
|
92
|
-
...this.#
|
|
92
|
+
...this.#element.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
93
93
|
];
|
|
94
94
|
if (!this.#contentElements.length) {
|
|
95
95
|
console.warn("Missing content elements");
|
|
@@ -102,13 +102,13 @@ var Disclosure = class _Disclosure {
|
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
104
|
const binding = this.#createBinding(details, summary, content);
|
|
105
|
-
[details, summary, content].forEach((
|
|
106
|
-
this.#bindings.set(
|
|
105
|
+
[details, summary, content].forEach((element2) => {
|
|
106
|
+
this.#bindings.set(element2, binding);
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
this.#initialize();
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
close(details) {
|
|
112
112
|
if (this.#isDestroyed) {
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
@@ -147,9 +147,9 @@ var Disclosure = class _Disclosure {
|
|
|
147
147
|
attributeUtils.restoreAttributes(this.#summaryElements);
|
|
148
148
|
this.#summaryElements.length = 0;
|
|
149
149
|
this.#contentElements.length = 0;
|
|
150
|
-
this.#
|
|
150
|
+
this.#element.removeAttribute("data-disclosure-initialized");
|
|
151
151
|
}
|
|
152
|
-
|
|
152
|
+
open(details) {
|
|
153
153
|
if (this.#isDestroyed) {
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
@@ -183,13 +183,13 @@ var Disclosure = class _Disclosure {
|
|
|
183
183
|
}
|
|
184
184
|
summary.addEventListener("click", this.#onSummaryClick, { signal });
|
|
185
185
|
});
|
|
186
|
-
this.#cleanupRovingTabIndex = rovingTabindex.createRovingTabIndex(this.#
|
|
186
|
+
this.#cleanupRovingTabIndex = rovingTabindex.createRovingTabIndex(this.#element, {
|
|
187
187
|
direction: "vertical",
|
|
188
188
|
navigationOnly: true,
|
|
189
189
|
selector: "summary:not(:scope summary + * *)",
|
|
190
190
|
wrap: true
|
|
191
191
|
});
|
|
192
|
-
this.#
|
|
192
|
+
this.#element.setAttribute("data-disclosure-initialized", "");
|
|
193
193
|
}
|
|
194
194
|
#onSummaryClick = (event) => {
|
|
195
195
|
event.preventDefault();
|
|
@@ -214,20 +214,20 @@ var Disclosure = class _Disclosure {
|
|
|
214
214
|
content.style.removeProperty(name2);
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
#toggle(details,
|
|
218
|
-
if (details.hasAttribute("data-disclosure-open") ===
|
|
217
|
+
#toggle(details, isOpen, isProgrammatic = false) {
|
|
218
|
+
if (details.hasAttribute("data-disclosure-open") === isOpen) {
|
|
219
219
|
return;
|
|
220
220
|
}
|
|
221
|
-
if (!
|
|
221
|
+
if (!isOpen && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
222
222
|
return;
|
|
223
223
|
}
|
|
224
224
|
const name = details.getAttribute("data-disclosure-name");
|
|
225
|
-
if (name &&
|
|
225
|
+
if (name && isOpen) {
|
|
226
226
|
details.removeAttribute("name");
|
|
227
|
-
const
|
|
227
|
+
const opened = this.#detailsElements.find(
|
|
228
228
|
(d) => d.hasAttribute("data-disclosure-open") && d.getAttribute("data-disclosure-name") === name
|
|
229
229
|
);
|
|
230
|
-
|
|
230
|
+
opened && this.#toggle(opened, false, true);
|
|
231
231
|
}
|
|
232
232
|
const binding = this.#bindings.get(details);
|
|
233
233
|
if (!binding) {
|
|
@@ -236,12 +236,12 @@ var Disclosure = class _Disclosure {
|
|
|
236
236
|
const { content } = binding;
|
|
237
237
|
const startSize = details.open ? content.offsetHeight : 0;
|
|
238
238
|
binding.animation?.cancel();
|
|
239
|
-
if (
|
|
239
|
+
if (isOpen) {
|
|
240
240
|
details.open = true;
|
|
241
241
|
}
|
|
242
|
-
const endSize =
|
|
242
|
+
const endSize = isOpen ? content.scrollHeight : 0;
|
|
243
243
|
binding.animation?.cancel();
|
|
244
|
-
details.toggleAttribute("data-disclosure-open",
|
|
244
|
+
details.toggleAttribute("data-disclosure-open", isOpen);
|
|
245
245
|
content.style.setProperty("overflow", "clip");
|
|
246
246
|
const { duration, easing } = this.#settings.animation;
|
|
247
247
|
const animation = content.animate(
|
|
@@ -287,9 +287,7 @@ var Disclosure = class _Disclosure {
|
|
|
287
287
|
}
|
|
288
288
|
};
|
|
289
289
|
function waitAnimationFinish(animation) {
|
|
290
|
-
return ["finished", "idle"].includes(animation.playState) ? Promise.resolve() : new Promise(
|
|
291
|
-
(resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
|
|
292
|
-
);
|
|
290
|
+
return ["finished", "idle"].includes(animation.playState) ? Promise.resolve() : new Promise((r) => animation.addEventListener("finish", () => r(), { once: true }));
|
|
293
291
|
}
|
|
294
292
|
|
|
295
293
|
exports.Disclosure = Disclosure;
|
package/dist/index.d.cts
CHANGED
|
@@ -9,10 +9,10 @@ interface DisclosureOptions {
|
|
|
9
9
|
declare class Disclosure {
|
|
10
10
|
#private;
|
|
11
11
|
static defaults: Partial<DisclosureOptions>;
|
|
12
|
-
constructor(
|
|
13
|
-
|
|
12
|
+
constructor(element: HTMLElement, options?: Partial<DisclosureOptions>);
|
|
13
|
+
close(details: HTMLDetailsElement): void;
|
|
14
14
|
destroy(force?: boolean): Promise<void>;
|
|
15
|
-
|
|
15
|
+
open(details: HTMLDetailsElement): void;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export { Disclosure, type DisclosureOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ interface DisclosureOptions {
|
|
|
9
9
|
declare class Disclosure {
|
|
10
10
|
#private;
|
|
11
11
|
static defaults: Partial<DisclosureOptions>;
|
|
12
|
-
constructor(
|
|
13
|
-
|
|
12
|
+
constructor(element: HTMLElement, options?: Partial<DisclosureOptions>);
|
|
13
|
+
close(details: HTMLDetailsElement): void;
|
|
14
14
|
destroy(force?: boolean): Promise<void>;
|
|
15
|
-
|
|
15
|
+
open(details: HTMLDetailsElement): void;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export { Disclosure, type DisclosureOptions };
|
package/dist/index.js
CHANGED
|
@@ -47,7 +47,7 @@ function resolveOptions(defaults2, source) {
|
|
|
47
47
|
// src/index.ts
|
|
48
48
|
var Disclosure = class _Disclosure {
|
|
49
49
|
static defaults = {};
|
|
50
|
-
#
|
|
50
|
+
#element;
|
|
51
51
|
#settings;
|
|
52
52
|
#detailsElements;
|
|
53
53
|
#summaryElements;
|
|
@@ -58,36 +58,36 @@ var Disclosure = class _Disclosure {
|
|
|
58
58
|
#observers = [];
|
|
59
59
|
#cleanupRovingTabIndex = null;
|
|
60
60
|
#isDestroyed = false;
|
|
61
|
-
constructor(
|
|
62
|
-
if (!(
|
|
63
|
-
throw new TypeError("Invalid
|
|
61
|
+
constructor(element, options = {}) {
|
|
62
|
+
if (!(element instanceof HTMLElement)) {
|
|
63
|
+
throw new TypeError("Invalid element");
|
|
64
64
|
}
|
|
65
|
-
if (
|
|
65
|
+
if (element.hasAttribute("data-disclosure-initialized")) {
|
|
66
66
|
console.warn("Already initialized");
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
|
-
this.#
|
|
69
|
+
this.#element = element;
|
|
70
70
|
this.#settings = resolveOptions(resolveOptions(defaults, _Disclosure.defaults), options);
|
|
71
71
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
72
72
|
this.#settings.animation.duration = 0;
|
|
73
73
|
}
|
|
74
74
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
75
75
|
this.#detailsElements = [
|
|
76
|
-
...this.#
|
|
76
|
+
...this.#element.querySelectorAll(`details${NOT_NESTED}`)
|
|
77
77
|
];
|
|
78
78
|
if (!this.#detailsElements.length) {
|
|
79
79
|
console.warn("Missing <details> elements");
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
82
|
this.#summaryElements = [
|
|
83
|
-
...this.#
|
|
83
|
+
...this.#element.querySelectorAll(`summary${NOT_NESTED}`)
|
|
84
84
|
];
|
|
85
85
|
if (!this.#summaryElements.length) {
|
|
86
86
|
console.warn("Missing <summary> elements");
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
this.#contentElements = [
|
|
90
|
-
...this.#
|
|
90
|
+
...this.#element.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
91
91
|
];
|
|
92
92
|
if (!this.#contentElements.length) {
|
|
93
93
|
console.warn("Missing content elements");
|
|
@@ -100,13 +100,13 @@ var Disclosure = class _Disclosure {
|
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
const binding = this.#createBinding(details, summary, content);
|
|
103
|
-
[details, summary, content].forEach((
|
|
104
|
-
this.#bindings.set(
|
|
103
|
+
[details, summary, content].forEach((element2) => {
|
|
104
|
+
this.#bindings.set(element2, binding);
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
107
|
this.#initialize();
|
|
108
108
|
}
|
|
109
|
-
|
|
109
|
+
close(details) {
|
|
110
110
|
if (this.#isDestroyed) {
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
@@ -145,9 +145,9 @@ var Disclosure = class _Disclosure {
|
|
|
145
145
|
restoreAttributes(this.#summaryElements);
|
|
146
146
|
this.#summaryElements.length = 0;
|
|
147
147
|
this.#contentElements.length = 0;
|
|
148
|
-
this.#
|
|
148
|
+
this.#element.removeAttribute("data-disclosure-initialized");
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
open(details) {
|
|
151
151
|
if (this.#isDestroyed) {
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
@@ -181,13 +181,13 @@ var Disclosure = class _Disclosure {
|
|
|
181
181
|
}
|
|
182
182
|
summary.addEventListener("click", this.#onSummaryClick, { signal });
|
|
183
183
|
});
|
|
184
|
-
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#
|
|
184
|
+
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#element, {
|
|
185
185
|
direction: "vertical",
|
|
186
186
|
navigationOnly: true,
|
|
187
187
|
selector: "summary:not(:scope summary + * *)",
|
|
188
188
|
wrap: true
|
|
189
189
|
});
|
|
190
|
-
this.#
|
|
190
|
+
this.#element.setAttribute("data-disclosure-initialized", "");
|
|
191
191
|
}
|
|
192
192
|
#onSummaryClick = (event) => {
|
|
193
193
|
event.preventDefault();
|
|
@@ -212,20 +212,20 @@ var Disclosure = class _Disclosure {
|
|
|
212
212
|
content.style.removeProperty(name2);
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
#toggle(details,
|
|
216
|
-
if (details.hasAttribute("data-disclosure-open") ===
|
|
215
|
+
#toggle(details, isOpen, isProgrammatic = false) {
|
|
216
|
+
if (details.hasAttribute("data-disclosure-open") === isOpen) {
|
|
217
217
|
return;
|
|
218
218
|
}
|
|
219
|
-
if (!
|
|
219
|
+
if (!isOpen && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
220
220
|
return;
|
|
221
221
|
}
|
|
222
222
|
const name = details.getAttribute("data-disclosure-name");
|
|
223
|
-
if (name &&
|
|
223
|
+
if (name && isOpen) {
|
|
224
224
|
details.removeAttribute("name");
|
|
225
|
-
const
|
|
225
|
+
const opened = this.#detailsElements.find(
|
|
226
226
|
(d) => d.hasAttribute("data-disclosure-open") && d.getAttribute("data-disclosure-name") === name
|
|
227
227
|
);
|
|
228
|
-
|
|
228
|
+
opened && this.#toggle(opened, false, true);
|
|
229
229
|
}
|
|
230
230
|
const binding = this.#bindings.get(details);
|
|
231
231
|
if (!binding) {
|
|
@@ -234,12 +234,12 @@ var Disclosure = class _Disclosure {
|
|
|
234
234
|
const { content } = binding;
|
|
235
235
|
const startSize = details.open ? content.offsetHeight : 0;
|
|
236
236
|
binding.animation?.cancel();
|
|
237
|
-
if (
|
|
237
|
+
if (isOpen) {
|
|
238
238
|
details.open = true;
|
|
239
239
|
}
|
|
240
|
-
const endSize =
|
|
240
|
+
const endSize = isOpen ? content.scrollHeight : 0;
|
|
241
241
|
binding.animation?.cancel();
|
|
242
|
-
details.toggleAttribute("data-disclosure-open",
|
|
242
|
+
details.toggleAttribute("data-disclosure-open", isOpen);
|
|
243
243
|
content.style.setProperty("overflow", "clip");
|
|
244
244
|
const { duration, easing } = this.#settings.animation;
|
|
245
245
|
const animation = content.animate(
|
|
@@ -285,9 +285,7 @@ var Disclosure = class _Disclosure {
|
|
|
285
285
|
}
|
|
286
286
|
};
|
|
287
287
|
function waitAnimationFinish(animation) {
|
|
288
|
-
return ["finished", "idle"].includes(animation.playState) ? Promise.resolve() : new Promise(
|
|
289
|
-
(resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
|
|
290
|
-
);
|
|
288
|
+
return ["finished", "idle"].includes(animation.playState) ? Promise.resolve() : new Promise((r) => animation.addEventListener("finish", () => r(), { once: true }));
|
|
291
289
|
}
|
|
292
290
|
|
|
293
291
|
export { Disclosure };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/disclosure",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "WAI-ARIA compliant disclosure pattern implementation in TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"a11y",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"esbuild": true
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@y14e/attribute-utils": "^2.0.
|
|
58
|
-
"@y14e/roving-tabindex": "^3.5.
|
|
57
|
+
"@y14e/attribute-utils": "^2.0.21",
|
|
58
|
+
"@y14e/roving-tabindex": "^3.5.9"
|
|
59
59
|
}
|
|
60
60
|
}
|