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