@y14e/disclosure 2.1.4 → 2.2.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/dist/index.bundle.cjs +296 -289
- package/dist/index.bundle.js +296 -289
- package/dist/index.cjs +47 -40
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +47 -40
- package/package.json +5 -5
package/dist/index.bundle.cjs
CHANGED
|
@@ -91,81 +91,105 @@ function resolveOptions(options) {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// node_modules/power-focusable/dist/index.js
|
|
94
|
+
function getComposedChildren(node) {
|
|
95
|
+
if (node instanceof ShadowRoot) {
|
|
96
|
+
return [...node.children];
|
|
97
|
+
}
|
|
98
|
+
if (!(node instanceof Element)) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
if (node instanceof HTMLSlotElement) {
|
|
102
|
+
const assigned = node.assignedElements({ flatten: true });
|
|
103
|
+
if (assigned.length) {
|
|
104
|
+
return assigned;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
108
|
+
return [...node.shadowRoot.children];
|
|
109
|
+
}
|
|
110
|
+
return [...node.children];
|
|
111
|
+
}
|
|
94
112
|
var FOCUSABLE_SELECTOR = ':is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])';
|
|
95
|
-
var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
|
|
96
|
-
|
|
97
|
-
""
|
|
98
|
-
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(/(,\s*)?\[tabindex="-1"\]/g, "");
|
|
114
|
+
function focusElement(element) {
|
|
115
|
+
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
116
|
+
}
|
|
117
|
+
function getActiveElement() {
|
|
118
|
+
let current = document.activeElement;
|
|
119
|
+
while (current?.shadowRoot?.activeElement) {
|
|
120
|
+
current = current.shadowRoot.activeElement;
|
|
103
121
|
}
|
|
104
|
-
|
|
105
|
-
|
|
122
|
+
return current;
|
|
123
|
+
}
|
|
124
|
+
function getTabIndex(element) {
|
|
125
|
+
return "tabIndex" in element ? Number(element.tabIndex) : 0;
|
|
126
|
+
}
|
|
127
|
+
function isDisabled(element) {
|
|
128
|
+
return "disabled" in element && !!element.disabled;
|
|
129
|
+
}
|
|
130
|
+
function isFormControl(element) {
|
|
131
|
+
return ["BUTTON", "INPUT", "SELECT", "TEXTAREA"].includes(element.tagName);
|
|
132
|
+
}
|
|
133
|
+
function isInert(element) {
|
|
134
|
+
return "inert" in element && !!element.inert;
|
|
135
|
+
}
|
|
136
|
+
function isUngroupedRadio(element) {
|
|
137
|
+
return element.type === "radio" && !!element.name;
|
|
138
|
+
}
|
|
139
|
+
function resolveOptions2(options) {
|
|
140
|
+
let {
|
|
141
|
+
anchor = getActiveElement(),
|
|
142
|
+
composed = false,
|
|
106
143
|
filter,
|
|
107
144
|
include,
|
|
108
|
-
skipNegativeTabIndexCheck,
|
|
109
|
-
skipVisibilityCheck
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (!
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
skipNegativeTabIndexCheck,
|
|
118
|
-
skipVisibilityCheck
|
|
119
|
-
}) && candidates.push(match);
|
|
145
|
+
skipNegativeTabIndexCheck = false,
|
|
146
|
+
skipVisibilityCheck = false,
|
|
147
|
+
wrap = false
|
|
148
|
+
} = options;
|
|
149
|
+
if (!(anchor instanceof Element)) {
|
|
150
|
+
const active = getActiveElement();
|
|
151
|
+
if (active instanceof Element) {
|
|
152
|
+
console.warn("Invalid anchor element. Fallback: active element.");
|
|
153
|
+
anchor = active;
|
|
120
154
|
}
|
|
121
|
-
} else {
|
|
122
|
-
let traverse2 = function(node) {
|
|
123
|
-
if (isFocusable(node, {
|
|
124
|
-
skipNegativeTabIndexCheck,
|
|
125
|
-
skipVisibilityCheck
|
|
126
|
-
}) || include?.(node)) {
|
|
127
|
-
candidates.push(node);
|
|
128
|
-
}
|
|
129
|
-
(!composed ? [...node.children] : getComposedChildren(node)).map(
|
|
130
|
-
traverse2
|
|
131
|
-
);
|
|
132
|
-
};
|
|
133
|
-
(!composed ? [...container.children] : getComposedChildren(container)).map(
|
|
134
|
-
traverse2
|
|
135
|
-
);
|
|
136
155
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
function isFocusable(element, options = {}) {
|
|
142
|
-
if (!(element instanceof Element)) {
|
|
143
|
-
console.warn("Invalid element");
|
|
144
|
-
return false;
|
|
156
|
+
if (typeof composed !== "boolean") {
|
|
157
|
+
console.warn("Invalid composed option. Fallback: false.");
|
|
158
|
+
composed = false;
|
|
145
159
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
160
|
+
if (filter !== void 0 && typeof filter !== "function") {
|
|
161
|
+
console.warn(
|
|
162
|
+
"Invalid filter function. Fallback: no filter function (undefined)."
|
|
163
|
+
);
|
|
164
|
+
filter = void 0;
|
|
149
165
|
}
|
|
150
|
-
if (
|
|
151
|
-
|
|
166
|
+
if (include !== void 0 && typeof include !== "function") {
|
|
167
|
+
console.warn(
|
|
168
|
+
"Invalid include function. Fallback: no include function (undefined)."
|
|
169
|
+
);
|
|
170
|
+
include = void 0;
|
|
152
171
|
}
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return false;
|
|
172
|
+
if (typeof skipNegativeTabIndexCheck !== "boolean") {
|
|
173
|
+
console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
|
|
174
|
+
skipNegativeTabIndexCheck = false;
|
|
157
175
|
}
|
|
158
|
-
if (
|
|
159
|
-
|
|
176
|
+
if (typeof skipVisibilityCheck !== "boolean") {
|
|
177
|
+
console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
|
|
178
|
+
skipVisibilityCheck = false;
|
|
160
179
|
}
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
visibilityProperty: true
|
|
165
|
-
})) {
|
|
166
|
-
return false;
|
|
180
|
+
if (typeof wrap !== "boolean") {
|
|
181
|
+
console.warn("Invalid wrap option. Fallback: false.");
|
|
182
|
+
wrap = false;
|
|
167
183
|
}
|
|
168
|
-
return
|
|
184
|
+
return {
|
|
185
|
+
anchor,
|
|
186
|
+
composed,
|
|
187
|
+
filter,
|
|
188
|
+
include,
|
|
189
|
+
skipNegativeTabIndexCheck,
|
|
190
|
+
skipVisibilityCheck,
|
|
191
|
+
wrap
|
|
192
|
+
};
|
|
169
193
|
}
|
|
170
194
|
function isDisabledDeep(element) {
|
|
171
195
|
let current = element;
|
|
@@ -247,107 +271,193 @@ function sortByTabIndex(elements) {
|
|
|
247
271
|
}
|
|
248
272
|
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
249
273
|
}
|
|
250
|
-
function
|
|
251
|
-
if (
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (!(node instanceof Element)) {
|
|
255
|
-
return [];
|
|
274
|
+
function getFocusables(container = document.body, options = {}) {
|
|
275
|
+
if (!(container instanceof Element)) {
|
|
276
|
+
console.warn("Invalid container element. Fallback: <body> element.");
|
|
277
|
+
container = document.body;
|
|
256
278
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
279
|
+
const {
|
|
280
|
+
composed,
|
|
281
|
+
filter,
|
|
282
|
+
include,
|
|
283
|
+
skipNegativeTabIndexCheck,
|
|
284
|
+
skipVisibilityCheck
|
|
285
|
+
} = resolveOptions2(options);
|
|
286
|
+
const candidates = [];
|
|
287
|
+
if (!composed && !include) {
|
|
288
|
+
for (const match of container.querySelectorAll(
|
|
289
|
+
!skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR : FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX
|
|
290
|
+
)) {
|
|
291
|
+
match && isFocusable(match, {
|
|
292
|
+
skipNegativeTabIndexCheck,
|
|
293
|
+
skipVisibilityCheck
|
|
294
|
+
}) && candidates.push(match);
|
|
261
295
|
}
|
|
296
|
+
} else {
|
|
297
|
+
let traverse2 = function(node) {
|
|
298
|
+
if (isFocusable(node, {
|
|
299
|
+
skipNegativeTabIndexCheck,
|
|
300
|
+
skipVisibilityCheck
|
|
301
|
+
}) || include?.(node)) {
|
|
302
|
+
candidates.push(node);
|
|
303
|
+
}
|
|
304
|
+
(!composed ? [...node.children] : getComposedChildren(node)).map(
|
|
305
|
+
traverse2
|
|
306
|
+
);
|
|
307
|
+
};
|
|
308
|
+
(!composed ? [...container.children] : getComposedChildren(container)).map(
|
|
309
|
+
traverse2
|
|
310
|
+
);
|
|
262
311
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return [...node.children];
|
|
267
|
-
}
|
|
268
|
-
function focusElement(element) {
|
|
269
|
-
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
312
|
+
return normalizeRadioGroup(
|
|
313
|
+
sortByTabIndex(!filter ? candidates : candidates.filter(filter))
|
|
314
|
+
);
|
|
270
315
|
}
|
|
271
|
-
function
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
316
|
+
function isFocusable(element, options = {}) {
|
|
317
|
+
if (!(element instanceof Element)) {
|
|
318
|
+
console.warn("Invalid element");
|
|
319
|
+
return false;
|
|
275
320
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
321
|
+
const { skipNegativeTabIndexCheck, skipVisibilityCheck } = resolveOptions2(options);
|
|
322
|
+
if (element.hasAttribute("hidden") || isInert(element)) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
if (!skipNegativeTabIndexCheck && getTabIndex(element) < 0) {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
if (!element.matches(
|
|
329
|
+
!skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR : FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX
|
|
330
|
+
)) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
if (isDisabledDeep(element)) {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
if (!skipVisibilityCheck && !element.checkVisibility({
|
|
337
|
+
contentVisibilityAuto: true,
|
|
338
|
+
opacityProperty: true,
|
|
339
|
+
visibilityProperty: true
|
|
340
|
+
})) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
return true;
|
|
283
344
|
}
|
|
284
|
-
|
|
285
|
-
|
|
345
|
+
|
|
346
|
+
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
347
|
+
function getCellCoords(cell) {
|
|
348
|
+
const { left, top, width, height } = cell.getBoundingClientRect();
|
|
349
|
+
return { x: left + width / 2, y: top + height / 2 };
|
|
286
350
|
}
|
|
287
|
-
function
|
|
288
|
-
|
|
351
|
+
function getCellsOfActiveRow(cells) {
|
|
352
|
+
const active = getActiveElement();
|
|
353
|
+
if (!(active instanceof Element)) {
|
|
354
|
+
return [];
|
|
355
|
+
}
|
|
356
|
+
const activeRect = active.getBoundingClientRect();
|
|
357
|
+
return cells.filter((cell) => {
|
|
358
|
+
const cellRect = cell.getBoundingClientRect();
|
|
359
|
+
return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
|
|
360
|
+
});
|
|
289
361
|
}
|
|
290
|
-
function
|
|
291
|
-
|
|
362
|
+
function getNextCell(cells, key, wrap) {
|
|
363
|
+
const active = getActiveElement();
|
|
364
|
+
if (!(active instanceof Element)) {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
const activeCoords = getCellCoords(active);
|
|
368
|
+
let min = Infinity;
|
|
369
|
+
let result = null;
|
|
370
|
+
for (const cell of cells) {
|
|
371
|
+
if (cell === active) {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
const cellCoords = getCellCoords(cell);
|
|
375
|
+
const distances = {
|
|
376
|
+
x: Math.abs(cellCoords.x - activeCoords.x),
|
|
377
|
+
y: Math.abs(cellCoords.y - activeCoords.y)
|
|
378
|
+
};
|
|
379
|
+
if (key === "ArrowUp" && cellCoords.y < activeCoords.y && distances.x < distances.y || key === "ArrowDown" && cellCoords.y > activeCoords.y && distances.x < distances.y) {
|
|
380
|
+
const distance = distances.x ** 2 + distances.y ** 2;
|
|
381
|
+
if (distance < min) {
|
|
382
|
+
min = distance;
|
|
383
|
+
result = cell;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (!result && wrap) {
|
|
388
|
+
let max = -Infinity;
|
|
389
|
+
for (const cell of cells) {
|
|
390
|
+
if (cell === active) {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
const cellCoords = getCellCoords(cell);
|
|
394
|
+
if (Math.abs(cellCoords.x - activeCoords.x) < cell.getBoundingClientRect().width / 2) {
|
|
395
|
+
const distance = key === "ArrowUp" ? cellCoords.y - activeCoords.y : activeCoords.y - cellCoords.y;
|
|
396
|
+
if (distance > max) {
|
|
397
|
+
max = distance;
|
|
398
|
+
result = cell;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return result;
|
|
292
404
|
}
|
|
293
|
-
|
|
405
|
+
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
406
|
+
function resolveOptions3(options) {
|
|
294
407
|
let {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
408
|
+
direction = "both",
|
|
409
|
+
navigationOnly = false,
|
|
410
|
+
noMemory = false,
|
|
411
|
+
noStart = false,
|
|
412
|
+
selector = "",
|
|
413
|
+
typeahead = false,
|
|
301
414
|
wrap = false
|
|
302
415
|
} = options;
|
|
303
|
-
if (
|
|
304
|
-
|
|
305
|
-
if (active instanceof Element) {
|
|
306
|
-
console.warn("Invalid anchor element. Fallback: active element.");
|
|
307
|
-
anchor = active;
|
|
308
|
-
}
|
|
416
|
+
if (typeof direction === "string") {
|
|
417
|
+
direction = direction.toLowerCase();
|
|
309
418
|
}
|
|
310
|
-
if (
|
|
311
|
-
console.warn("Invalid
|
|
312
|
-
|
|
419
|
+
if (!DIRECTIONS.includes(direction)) {
|
|
420
|
+
console.warn("Invalid direction option. Fallback: 'both'.");
|
|
421
|
+
direction = "both";
|
|
313
422
|
}
|
|
314
|
-
if (
|
|
315
|
-
console.warn(
|
|
316
|
-
|
|
317
|
-
);
|
|
318
|
-
filter = void 0;
|
|
423
|
+
if (typeof navigationOnly !== "boolean") {
|
|
424
|
+
console.warn("Invalid navigationOnly option. Fallback: false.");
|
|
425
|
+
navigationOnly = false;
|
|
319
426
|
}
|
|
320
|
-
if (
|
|
321
|
-
console.warn(
|
|
322
|
-
|
|
323
|
-
);
|
|
324
|
-
include = void 0;
|
|
427
|
+
if (typeof noMemory !== "boolean") {
|
|
428
|
+
console.warn("Invalid noMemory option. Fallback: false.");
|
|
429
|
+
noMemory = false;
|
|
325
430
|
}
|
|
326
|
-
if (typeof
|
|
327
|
-
console.warn("Invalid
|
|
328
|
-
|
|
431
|
+
if (typeof noStart !== "boolean") {
|
|
432
|
+
console.warn("Invalid noStart option. Fallback: false.");
|
|
433
|
+
noStart = false;
|
|
329
434
|
}
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
|
|
435
|
+
if (selector !== "") {
|
|
436
|
+
try {
|
|
437
|
+
document.querySelector(selector);
|
|
438
|
+
} catch {
|
|
439
|
+
console.warn("Invalid selector. Fallback: no selector string.");
|
|
440
|
+
selector = "";
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (typeof typeahead !== "boolean") {
|
|
444
|
+
console.warn("Invalid typeahead option. Fallback: false.");
|
|
445
|
+
typeahead = false;
|
|
333
446
|
}
|
|
334
447
|
if (typeof wrap !== "boolean") {
|
|
335
448
|
console.warn("Invalid wrap option. Fallback: false.");
|
|
336
449
|
wrap = false;
|
|
337
450
|
}
|
|
338
451
|
return {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
452
|
+
direction,
|
|
453
|
+
navigationOnly,
|
|
454
|
+
noMemory,
|
|
455
|
+
noStart,
|
|
456
|
+
selector,
|
|
457
|
+
typeahead,
|
|
345
458
|
wrap
|
|
346
459
|
};
|
|
347
460
|
}
|
|
348
|
-
|
|
349
|
-
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
350
|
-
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
351
461
|
function createRovingTabIndex(container, options = {}) {
|
|
352
462
|
if (!(container instanceof Element)) {
|
|
353
463
|
console.warn("Invalid container element");
|
|
@@ -368,7 +478,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
368
478
|
#isDestroyed = false;
|
|
369
479
|
constructor(container, options = {}) {
|
|
370
480
|
this.#container = container;
|
|
371
|
-
this.#settings =
|
|
481
|
+
this.#settings = resolveOptions3(options);
|
|
372
482
|
this.#selectorFilter = this.#createSelectorFilter();
|
|
373
483
|
this.#initialize();
|
|
374
484
|
}
|
|
@@ -549,20 +659,8 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
549
659
|
const { selector } = this.#settings;
|
|
550
660
|
return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
|
|
551
661
|
}
|
|
552
|
-
#getCellCoords(cell) {
|
|
553
|
-
const { left, top, width, height } = cell.getBoundingClientRect();
|
|
554
|
-
return { x: left + width / 2, y: top + height / 2 };
|
|
555
|
-
}
|
|
556
662
|
#getCellsOfActiveRow() {
|
|
557
|
-
|
|
558
|
-
if (!(active instanceof Element)) {
|
|
559
|
-
return [];
|
|
560
|
-
}
|
|
561
|
-
const activeRect = active.getBoundingClientRect();
|
|
562
|
-
return this.#getFocusables().filter((cell) => {
|
|
563
|
-
const cellRect = cell.getBoundingClientRect();
|
|
564
|
-
return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
|
|
565
|
-
});
|
|
663
|
+
return getCellsOfActiveRow(this.#getFocusables());
|
|
566
664
|
}
|
|
567
665
|
#getFocusables() {
|
|
568
666
|
return getFocusables(this.#container, {
|
|
@@ -573,117 +671,55 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
573
671
|
});
|
|
574
672
|
}
|
|
575
673
|
#getNextCell(key, wrap) {
|
|
576
|
-
|
|
577
|
-
const active = getActiveElement();
|
|
578
|
-
if (!(active instanceof Element)) {
|
|
579
|
-
return null;
|
|
580
|
-
}
|
|
581
|
-
const activeCoords = this.#getCellCoords(active);
|
|
582
|
-
let min = Infinity;
|
|
583
|
-
let result = null;
|
|
584
|
-
for (const cell of cells) {
|
|
585
|
-
if (cell === active) {
|
|
586
|
-
continue;
|
|
587
|
-
}
|
|
588
|
-
const cellCoords = this.#getCellCoords(cell);
|
|
589
|
-
const distances = {
|
|
590
|
-
x: Math.abs(cellCoords.x - activeCoords.x),
|
|
591
|
-
y: Math.abs(cellCoords.y - activeCoords.y)
|
|
592
|
-
};
|
|
593
|
-
if (key === "ArrowUp" && cellCoords.y < activeCoords.y && distances.x < distances.y || key === "ArrowDown" && cellCoords.y > activeCoords.y && distances.x < distances.y) {
|
|
594
|
-
const distance = distances.x ** 2 + distances.y ** 2;
|
|
595
|
-
if (distance < min) {
|
|
596
|
-
min = distance;
|
|
597
|
-
result = cell;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
if (!result && wrap) {
|
|
602
|
-
let max = -Infinity;
|
|
603
|
-
for (const cell of cells) {
|
|
604
|
-
if (cell === active) {
|
|
605
|
-
continue;
|
|
606
|
-
}
|
|
607
|
-
const cellCoords = this.#getCellCoords(cell);
|
|
608
|
-
if (Math.abs(cellCoords.x - activeCoords.x) < cell.getBoundingClientRect().width / 2) {
|
|
609
|
-
const distance = key === "ArrowUp" ? cellCoords.y - activeCoords.y : activeCoords.y - cellCoords.y;
|
|
610
|
-
if (distance > max) {
|
|
611
|
-
max = distance;
|
|
612
|
-
result = cell;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
return result;
|
|
618
|
-
}
|
|
619
|
-
#resolveOptions(options) {
|
|
620
|
-
let {
|
|
621
|
-
direction = "both",
|
|
622
|
-
navigationOnly = false,
|
|
623
|
-
noMemory = false,
|
|
624
|
-
noStart = false,
|
|
625
|
-
selector = "",
|
|
626
|
-
typeahead = false,
|
|
627
|
-
wrap = false
|
|
628
|
-
} = options;
|
|
629
|
-
if (typeof direction === "string") {
|
|
630
|
-
direction = direction.toLowerCase();
|
|
631
|
-
}
|
|
632
|
-
if (!DIRECTIONS.includes(direction)) {
|
|
633
|
-
console.warn("Invalid direction option. Fallback: 'both'.");
|
|
634
|
-
direction = "both";
|
|
635
|
-
}
|
|
636
|
-
if (typeof navigationOnly !== "boolean") {
|
|
637
|
-
console.warn("Invalid navigationOnly option. Fallback: false.");
|
|
638
|
-
navigationOnly = false;
|
|
639
|
-
}
|
|
640
|
-
if (typeof noMemory !== "boolean") {
|
|
641
|
-
console.warn("Invalid noMemory option. Fallback: false.");
|
|
642
|
-
noMemory = false;
|
|
643
|
-
}
|
|
644
|
-
if (typeof noStart !== "boolean") {
|
|
645
|
-
console.warn("Invalid noStart option. Fallback: false.");
|
|
646
|
-
noStart = false;
|
|
647
|
-
}
|
|
648
|
-
if (selector !== "") {
|
|
649
|
-
try {
|
|
650
|
-
document.querySelector(selector);
|
|
651
|
-
} catch {
|
|
652
|
-
console.warn("Invalid selector. Fallback: no selector string.");
|
|
653
|
-
selector = "";
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
if (typeof typeahead !== "boolean") {
|
|
657
|
-
console.warn("Invalid typeahead option. Fallback: false.");
|
|
658
|
-
typeahead = false;
|
|
659
|
-
}
|
|
660
|
-
if (typeof wrap !== "boolean") {
|
|
661
|
-
console.warn("Invalid wrap option. Fallback: false.");
|
|
662
|
-
wrap = false;
|
|
663
|
-
}
|
|
664
|
-
return {
|
|
665
|
-
direction,
|
|
666
|
-
navigationOnly,
|
|
667
|
-
noMemory,
|
|
668
|
-
noStart,
|
|
669
|
-
selector,
|
|
670
|
-
typeahead,
|
|
671
|
-
wrap
|
|
672
|
-
};
|
|
674
|
+
return getNextCell(this.#getFocusables(), key, wrap);
|
|
673
675
|
}
|
|
674
676
|
};
|
|
675
677
|
|
|
678
|
+
// src/defaults.ts
|
|
679
|
+
var defaults = {
|
|
680
|
+
animation: {
|
|
681
|
+
duration: 300,
|
|
682
|
+
easing: "ease"
|
|
683
|
+
},
|
|
684
|
+
collapsible: true
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
// src/options.ts
|
|
688
|
+
function resolveOptions4(defaults2, source) {
|
|
689
|
+
const merged = {
|
|
690
|
+
...defaults2,
|
|
691
|
+
...source,
|
|
692
|
+
animation: { ...defaults2.animation, ...source.animation ?? {} }
|
|
693
|
+
};
|
|
694
|
+
const mergedAnimation = merged.animation;
|
|
695
|
+
const duration = mergedAnimation.duration;
|
|
696
|
+
const defaultAnimation = defaults2.animation;
|
|
697
|
+
if (typeof duration !== "number" || Number.isNaN(duration)) {
|
|
698
|
+
const duration2 = defaultAnimation.duration;
|
|
699
|
+
console.warn(`Invalid animation duration. Fallback: ${duration2} (ms).`);
|
|
700
|
+
mergedAnimation.duration = duration2;
|
|
701
|
+
}
|
|
702
|
+
if (duration < 0) {
|
|
703
|
+
console.warn("Invalid animation duration. Fallback: 0 (ms).");
|
|
704
|
+
mergedAnimation.duration = 0;
|
|
705
|
+
}
|
|
706
|
+
if (!CSS.supports("animation-timing-function", mergedAnimation.easing)) {
|
|
707
|
+
const easing = defaultAnimation.easing;
|
|
708
|
+
console.warn(`Invalid animation easing. Fallback: '${easing}'.`);
|
|
709
|
+
mergedAnimation.easing = easing;
|
|
710
|
+
}
|
|
711
|
+
if (typeof merged.collapsible !== "boolean") {
|
|
712
|
+
const collapsible = defaults2.collapsible;
|
|
713
|
+
console.warn(`Invalid collapsible option. Fallback: ${collapsible}.`);
|
|
714
|
+
merged.collapsible = collapsible;
|
|
715
|
+
}
|
|
716
|
+
return merged;
|
|
717
|
+
}
|
|
718
|
+
|
|
676
719
|
// src/index.ts
|
|
677
720
|
var Disclosure = class _Disclosure {
|
|
678
721
|
static defaults = {};
|
|
679
722
|
#rootElement;
|
|
680
|
-
#defaults = {
|
|
681
|
-
animation: {
|
|
682
|
-
duration: 300,
|
|
683
|
-
easing: "ease"
|
|
684
|
-
},
|
|
685
|
-
collapsible: true
|
|
686
|
-
};
|
|
687
723
|
#settings;
|
|
688
724
|
#detailsElements;
|
|
689
725
|
#summaryElements;
|
|
@@ -703,8 +739,10 @@ var Disclosure = class _Disclosure {
|
|
|
703
739
|
return;
|
|
704
740
|
}
|
|
705
741
|
this.#rootElement = root;
|
|
706
|
-
this.#
|
|
707
|
-
|
|
742
|
+
this.#settings = resolveOptions4(
|
|
743
|
+
resolveOptions4(defaults, _Disclosure.defaults),
|
|
744
|
+
options
|
|
745
|
+
);
|
|
708
746
|
matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
|
|
709
747
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
710
748
|
this.#detailsElements = [
|
|
@@ -927,37 +965,6 @@ var Disclosure = class _Disclosure {
|
|
|
927
965
|
#isFocusable(element) {
|
|
928
966
|
return element.tabIndex >= 0;
|
|
929
967
|
}
|
|
930
|
-
#resolveOptions(target, source) {
|
|
931
|
-
const merged = {
|
|
932
|
-
...target,
|
|
933
|
-
...source,
|
|
934
|
-
animation: { ...target.animation, ...source.animation ?? {} }
|
|
935
|
-
};
|
|
936
|
-
const mergedAnimation = merged.animation;
|
|
937
|
-
const duration = mergedAnimation.duration;
|
|
938
|
-
const defaults = this.#defaults;
|
|
939
|
-
const defaultAnimation = defaults.animation;
|
|
940
|
-
if (typeof duration !== "number" || Number.isNaN(duration)) {
|
|
941
|
-
const duration2 = defaultAnimation.duration;
|
|
942
|
-
console.warn(`Invalid animation duration. Fallback: ${duration2} (ms).`);
|
|
943
|
-
mergedAnimation.duration = duration2;
|
|
944
|
-
}
|
|
945
|
-
if (duration < 0) {
|
|
946
|
-
console.warn("Invalid animation duration. Fallback: 0 (ms).");
|
|
947
|
-
mergedAnimation.duration = 0;
|
|
948
|
-
}
|
|
949
|
-
if (!CSS.supports("animation-timing-function", mergedAnimation.easing)) {
|
|
950
|
-
const easing = defaultAnimation.easing;
|
|
951
|
-
console.warn(`Invalid animation easing. Fallback: '${easing}'.`);
|
|
952
|
-
mergedAnimation.easing = easing;
|
|
953
|
-
}
|
|
954
|
-
if (typeof merged.collapsible !== "boolean") {
|
|
955
|
-
const collapsible = defaults.collapsible;
|
|
956
|
-
console.warn(`Invalid collapsible option. Fallback: ${collapsible}.`);
|
|
957
|
-
merged.collapsible = collapsible;
|
|
958
|
-
}
|
|
959
|
-
return merged;
|
|
960
|
-
}
|
|
961
968
|
async #waitAnimationsFinish() {
|
|
962
969
|
const promises = [];
|
|
963
970
|
for (const content of this.#contentElements) {
|