@y14e/disclosure 3.0.0 → 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 +2 -2
- package/dist/index.bundle.cjs +42 -63
- package/dist/index.bundle.js +42 -63
- package/dist/index.cjs +15 -17
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +15 -17
- 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
|
|
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) {
|
|
@@ -648,8 +629,8 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
648
629
|
skipVisibilityCheck: true
|
|
649
630
|
});
|
|
650
631
|
}
|
|
651
|
-
#getNextCell(key,
|
|
652
|
-
return getNextCell(this.#getFocusables(), key,
|
|
632
|
+
#getNextCell(key, isWrap) {
|
|
633
|
+
return getNextCell(this.#getFocusables(), key, isWrap);
|
|
653
634
|
}
|
|
654
635
|
#getSameRowCells() {
|
|
655
636
|
const active = getActiveElement();
|
|
@@ -701,7 +682,7 @@ function resolveOptions4(defaults2, source) {
|
|
|
701
682
|
// src/index.ts
|
|
702
683
|
var Disclosure = class _Disclosure {
|
|
703
684
|
static defaults = {};
|
|
704
|
-
#
|
|
685
|
+
#element;
|
|
705
686
|
#settings;
|
|
706
687
|
#detailsElements;
|
|
707
688
|
#summaryElements;
|
|
@@ -712,36 +693,36 @@ var Disclosure = class _Disclosure {
|
|
|
712
693
|
#observers = [];
|
|
713
694
|
#cleanupRovingTabIndex = null;
|
|
714
695
|
#isDestroyed = false;
|
|
715
|
-
constructor(
|
|
716
|
-
if (!(
|
|
717
|
-
throw new TypeError("Invalid
|
|
696
|
+
constructor(element, options = {}) {
|
|
697
|
+
if (!(element instanceof HTMLElement)) {
|
|
698
|
+
throw new TypeError("Invalid element");
|
|
718
699
|
}
|
|
719
|
-
if (
|
|
700
|
+
if (element.hasAttribute("data-disclosure-initialized")) {
|
|
720
701
|
console.warn("Already initialized");
|
|
721
702
|
return;
|
|
722
703
|
}
|
|
723
|
-
this.#
|
|
704
|
+
this.#element = element;
|
|
724
705
|
this.#settings = resolveOptions4(resolveOptions4(defaults, _Disclosure.defaults), options);
|
|
725
706
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
726
707
|
this.#settings.animation.duration = 0;
|
|
727
708
|
}
|
|
728
709
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
729
710
|
this.#detailsElements = [
|
|
730
|
-
...this.#
|
|
711
|
+
...this.#element.querySelectorAll(`details${NOT_NESTED}`)
|
|
731
712
|
];
|
|
732
713
|
if (!this.#detailsElements.length) {
|
|
733
714
|
console.warn("Missing <details> elements");
|
|
734
715
|
return;
|
|
735
716
|
}
|
|
736
717
|
this.#summaryElements = [
|
|
737
|
-
...this.#
|
|
718
|
+
...this.#element.querySelectorAll(`summary${NOT_NESTED}`)
|
|
738
719
|
];
|
|
739
720
|
if (!this.#summaryElements.length) {
|
|
740
721
|
console.warn("Missing <summary> elements");
|
|
741
722
|
return;
|
|
742
723
|
}
|
|
743
724
|
this.#contentElements = [
|
|
744
|
-
...this.#
|
|
725
|
+
...this.#element.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
745
726
|
];
|
|
746
727
|
if (!this.#contentElements.length) {
|
|
747
728
|
console.warn("Missing content elements");
|
|
@@ -754,8 +735,8 @@ var Disclosure = class _Disclosure {
|
|
|
754
735
|
return;
|
|
755
736
|
}
|
|
756
737
|
const binding = this.#createBinding(details, summary, content);
|
|
757
|
-
[details, summary, content].forEach((
|
|
758
|
-
this.#bindings.set(
|
|
738
|
+
[details, summary, content].forEach((element2) => {
|
|
739
|
+
this.#bindings.set(element2, binding);
|
|
759
740
|
});
|
|
760
741
|
});
|
|
761
742
|
this.#initialize();
|
|
@@ -799,7 +780,7 @@ var Disclosure = class _Disclosure {
|
|
|
799
780
|
restoreAttributes(this.#summaryElements);
|
|
800
781
|
this.#summaryElements.length = 0;
|
|
801
782
|
this.#contentElements.length = 0;
|
|
802
|
-
this.#
|
|
783
|
+
this.#element.removeAttribute("data-disclosure-initialized");
|
|
803
784
|
}
|
|
804
785
|
open(details) {
|
|
805
786
|
if (this.#isDestroyed) {
|
|
@@ -835,13 +816,13 @@ var Disclosure = class _Disclosure {
|
|
|
835
816
|
}
|
|
836
817
|
summary.addEventListener("click", this.#onSummaryClick, { signal });
|
|
837
818
|
});
|
|
838
|
-
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#
|
|
819
|
+
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#element, {
|
|
839
820
|
direction: "vertical",
|
|
840
821
|
navigationOnly: true,
|
|
841
822
|
selector: "summary:not(:scope summary + * *)",
|
|
842
823
|
wrap: true
|
|
843
824
|
});
|
|
844
|
-
this.#
|
|
825
|
+
this.#element.setAttribute("data-disclosure-initialized", "");
|
|
845
826
|
}
|
|
846
827
|
#onSummaryClick = (event) => {
|
|
847
828
|
event.preventDefault();
|
|
@@ -939,9 +920,7 @@ var Disclosure = class _Disclosure {
|
|
|
939
920
|
}
|
|
940
921
|
};
|
|
941
922
|
function waitAnimationFinish(animation) {
|
|
942
|
-
return ["finished", "idle"].includes(animation.playState) ? Promise.resolve() : new Promise(
|
|
943
|
-
(resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
|
|
944
|
-
);
|
|
923
|
+
return ["finished", "idle"].includes(animation.playState) ? Promise.resolve() : new Promise((r) => animation.addEventListener("finish", () => r(), { once: true }));
|
|
945
924
|
}
|
|
946
925
|
|
|
947
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) {
|
|
@@ -646,8 +627,8 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
646
627
|
skipVisibilityCheck: true
|
|
647
628
|
});
|
|
648
629
|
}
|
|
649
|
-
#getNextCell(key,
|
|
650
|
-
return getNextCell(this.#getFocusables(), key,
|
|
630
|
+
#getNextCell(key, isWrap) {
|
|
631
|
+
return getNextCell(this.#getFocusables(), key, isWrap);
|
|
651
632
|
}
|
|
652
633
|
#getSameRowCells() {
|
|
653
634
|
const active = getActiveElement();
|
|
@@ -699,7 +680,7 @@ function resolveOptions4(defaults2, source) {
|
|
|
699
680
|
// src/index.ts
|
|
700
681
|
var Disclosure = class _Disclosure {
|
|
701
682
|
static defaults = {};
|
|
702
|
-
#
|
|
683
|
+
#element;
|
|
703
684
|
#settings;
|
|
704
685
|
#detailsElements;
|
|
705
686
|
#summaryElements;
|
|
@@ -710,36 +691,36 @@ var Disclosure = class _Disclosure {
|
|
|
710
691
|
#observers = [];
|
|
711
692
|
#cleanupRovingTabIndex = null;
|
|
712
693
|
#isDestroyed = false;
|
|
713
|
-
constructor(
|
|
714
|
-
if (!(
|
|
715
|
-
throw new TypeError("Invalid
|
|
694
|
+
constructor(element, options = {}) {
|
|
695
|
+
if (!(element instanceof HTMLElement)) {
|
|
696
|
+
throw new TypeError("Invalid element");
|
|
716
697
|
}
|
|
717
|
-
if (
|
|
698
|
+
if (element.hasAttribute("data-disclosure-initialized")) {
|
|
718
699
|
console.warn("Already initialized");
|
|
719
700
|
return;
|
|
720
701
|
}
|
|
721
|
-
this.#
|
|
702
|
+
this.#element = element;
|
|
722
703
|
this.#settings = resolveOptions4(resolveOptions4(defaults, _Disclosure.defaults), options);
|
|
723
704
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
724
705
|
this.#settings.animation.duration = 0;
|
|
725
706
|
}
|
|
726
707
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
727
708
|
this.#detailsElements = [
|
|
728
|
-
...this.#
|
|
709
|
+
...this.#element.querySelectorAll(`details${NOT_NESTED}`)
|
|
729
710
|
];
|
|
730
711
|
if (!this.#detailsElements.length) {
|
|
731
712
|
console.warn("Missing <details> elements");
|
|
732
713
|
return;
|
|
733
714
|
}
|
|
734
715
|
this.#summaryElements = [
|
|
735
|
-
...this.#
|
|
716
|
+
...this.#element.querySelectorAll(`summary${NOT_NESTED}`)
|
|
736
717
|
];
|
|
737
718
|
if (!this.#summaryElements.length) {
|
|
738
719
|
console.warn("Missing <summary> elements");
|
|
739
720
|
return;
|
|
740
721
|
}
|
|
741
722
|
this.#contentElements = [
|
|
742
|
-
...this.#
|
|
723
|
+
...this.#element.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
743
724
|
];
|
|
744
725
|
if (!this.#contentElements.length) {
|
|
745
726
|
console.warn("Missing content elements");
|
|
@@ -752,8 +733,8 @@ var Disclosure = class _Disclosure {
|
|
|
752
733
|
return;
|
|
753
734
|
}
|
|
754
735
|
const binding = this.#createBinding(details, summary, content);
|
|
755
|
-
[details, summary, content].forEach((
|
|
756
|
-
this.#bindings.set(
|
|
736
|
+
[details, summary, content].forEach((element2) => {
|
|
737
|
+
this.#bindings.set(element2, binding);
|
|
757
738
|
});
|
|
758
739
|
});
|
|
759
740
|
this.#initialize();
|
|
@@ -797,7 +778,7 @@ var Disclosure = class _Disclosure {
|
|
|
797
778
|
restoreAttributes(this.#summaryElements);
|
|
798
779
|
this.#summaryElements.length = 0;
|
|
799
780
|
this.#contentElements.length = 0;
|
|
800
|
-
this.#
|
|
781
|
+
this.#element.removeAttribute("data-disclosure-initialized");
|
|
801
782
|
}
|
|
802
783
|
open(details) {
|
|
803
784
|
if (this.#isDestroyed) {
|
|
@@ -833,13 +814,13 @@ var Disclosure = class _Disclosure {
|
|
|
833
814
|
}
|
|
834
815
|
summary.addEventListener("click", this.#onSummaryClick, { signal });
|
|
835
816
|
});
|
|
836
|
-
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#
|
|
817
|
+
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#element, {
|
|
837
818
|
direction: "vertical",
|
|
838
819
|
navigationOnly: true,
|
|
839
820
|
selector: "summary:not(:scope summary + * *)",
|
|
840
821
|
wrap: true
|
|
841
822
|
});
|
|
842
|
-
this.#
|
|
823
|
+
this.#element.setAttribute("data-disclosure-initialized", "");
|
|
843
824
|
}
|
|
844
825
|
#onSummaryClick = (event) => {
|
|
845
826
|
event.preventDefault();
|
|
@@ -937,9 +918,7 @@ var Disclosure = class _Disclosure {
|
|
|
937
918
|
}
|
|
938
919
|
};
|
|
939
920
|
function waitAnimationFinish(animation) {
|
|
940
|
-
return ["finished", "idle"].includes(animation.playState) ? Promise.resolve() : new Promise(
|
|
941
|
-
(resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
|
|
942
|
-
);
|
|
921
|
+
return ["finished", "idle"].includes(animation.playState) ? Promise.resolve() : new Promise((r) => animation.addEventListener("finish", () => r(), { once: true }));
|
|
943
922
|
}
|
|
944
923
|
|
|
945
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,8 +102,8 @@ 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();
|
|
@@ -147,7 +147,7 @@ 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) {
|
|
@@ -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();
|
|
@@ -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,7 +9,7 @@ interface DisclosureOptions {
|
|
|
9
9
|
declare class Disclosure {
|
|
10
10
|
#private;
|
|
11
11
|
static defaults: Partial<DisclosureOptions>;
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(element: HTMLElement, options?: Partial<DisclosureOptions>);
|
|
13
13
|
close(details: HTMLDetailsElement): void;
|
|
14
14
|
destroy(force?: boolean): Promise<void>;
|
|
15
15
|
open(details: HTMLDetailsElement): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ interface DisclosureOptions {
|
|
|
9
9
|
declare class Disclosure {
|
|
10
10
|
#private;
|
|
11
11
|
static defaults: Partial<DisclosureOptions>;
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(element: HTMLElement, options?: Partial<DisclosureOptions>);
|
|
13
13
|
close(details: HTMLDetailsElement): void;
|
|
14
14
|
destroy(force?: boolean): Promise<void>;
|
|
15
15
|
open(details: HTMLDetailsElement): void;
|
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,8 +100,8 @@ 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();
|
|
@@ -145,7 +145,7 @@ 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) {
|
|
@@ -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();
|
|
@@ -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.0.
|
|
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
|
}
|