@y14e/disclosure-css 2.1.3 → 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 +269 -261
- package/dist/index.bundle.js +269 -261
- package/dist/index.cjs +20 -12
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +20 -12
- package/package.json +5 -5
package/dist/index.bundle.js
CHANGED
|
@@ -89,81 +89,105 @@ function resolveOptions(options) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
// node_modules/power-focusable/dist/index.js
|
|
92
|
+
function getComposedChildren(node) {
|
|
93
|
+
if (node instanceof ShadowRoot) {
|
|
94
|
+
return [...node.children];
|
|
95
|
+
}
|
|
96
|
+
if (!(node instanceof Element)) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
if (node instanceof HTMLSlotElement) {
|
|
100
|
+
const assigned = node.assignedElements({ flatten: true });
|
|
101
|
+
if (assigned.length) {
|
|
102
|
+
return assigned;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
106
|
+
return [...node.shadowRoot.children];
|
|
107
|
+
}
|
|
108
|
+
return [...node.children];
|
|
109
|
+
}
|
|
92
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"])';
|
|
93
|
-
var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
|
|
94
|
-
|
|
95
|
-
""
|
|
96
|
-
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(/(,\s*)?\[tabindex="-1"\]/g, "");
|
|
112
|
+
function focusElement(element) {
|
|
113
|
+
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
114
|
+
}
|
|
115
|
+
function getActiveElement() {
|
|
116
|
+
let current = document.activeElement;
|
|
117
|
+
while (current?.shadowRoot?.activeElement) {
|
|
118
|
+
current = current.shadowRoot.activeElement;
|
|
101
119
|
}
|
|
102
|
-
|
|
103
|
-
|
|
120
|
+
return current;
|
|
121
|
+
}
|
|
122
|
+
function getTabIndex(element) {
|
|
123
|
+
return "tabIndex" in element ? Number(element.tabIndex) : 0;
|
|
124
|
+
}
|
|
125
|
+
function isDisabled(element) {
|
|
126
|
+
return "disabled" in element && !!element.disabled;
|
|
127
|
+
}
|
|
128
|
+
function isFormControl(element) {
|
|
129
|
+
return ["BUTTON", "INPUT", "SELECT", "TEXTAREA"].includes(element.tagName);
|
|
130
|
+
}
|
|
131
|
+
function isInert(element) {
|
|
132
|
+
return "inert" in element && !!element.inert;
|
|
133
|
+
}
|
|
134
|
+
function isUngroupedRadio(element) {
|
|
135
|
+
return element.type === "radio" && !!element.name;
|
|
136
|
+
}
|
|
137
|
+
function resolveOptions2(options) {
|
|
138
|
+
let {
|
|
139
|
+
anchor = getActiveElement(),
|
|
140
|
+
composed = false,
|
|
104
141
|
filter,
|
|
105
142
|
include,
|
|
106
|
-
skipNegativeTabIndexCheck,
|
|
107
|
-
skipVisibilityCheck
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (!
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
skipNegativeTabIndexCheck,
|
|
116
|
-
skipVisibilityCheck
|
|
117
|
-
}) && candidates.push(match);
|
|
143
|
+
skipNegativeTabIndexCheck = false,
|
|
144
|
+
skipVisibilityCheck = false,
|
|
145
|
+
wrap = false
|
|
146
|
+
} = options;
|
|
147
|
+
if (!(anchor instanceof Element)) {
|
|
148
|
+
const active = getActiveElement();
|
|
149
|
+
if (active instanceof Element) {
|
|
150
|
+
console.warn("Invalid anchor element. Fallback: active element.");
|
|
151
|
+
anchor = active;
|
|
118
152
|
}
|
|
119
|
-
} else {
|
|
120
|
-
let traverse2 = function(node) {
|
|
121
|
-
if (isFocusable(node, {
|
|
122
|
-
skipNegativeTabIndexCheck,
|
|
123
|
-
skipVisibilityCheck
|
|
124
|
-
}) || include?.(node)) {
|
|
125
|
-
candidates.push(node);
|
|
126
|
-
}
|
|
127
|
-
(!composed ? [...node.children] : getComposedChildren(node)).map(
|
|
128
|
-
traverse2
|
|
129
|
-
);
|
|
130
|
-
};
|
|
131
|
-
(!composed ? [...container.children] : getComposedChildren(container)).map(
|
|
132
|
-
traverse2
|
|
133
|
-
);
|
|
134
153
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
function isFocusable(element, options = {}) {
|
|
140
|
-
if (!(element instanceof Element)) {
|
|
141
|
-
console.warn("Invalid element");
|
|
142
|
-
return false;
|
|
154
|
+
if (typeof composed !== "boolean") {
|
|
155
|
+
console.warn("Invalid composed option. Fallback: false.");
|
|
156
|
+
composed = false;
|
|
143
157
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
158
|
+
if (filter !== void 0 && typeof filter !== "function") {
|
|
159
|
+
console.warn(
|
|
160
|
+
"Invalid filter function. Fallback: no filter function (undefined)."
|
|
161
|
+
);
|
|
162
|
+
filter = void 0;
|
|
147
163
|
}
|
|
148
|
-
if (
|
|
149
|
-
|
|
164
|
+
if (include !== void 0 && typeof include !== "function") {
|
|
165
|
+
console.warn(
|
|
166
|
+
"Invalid include function. Fallback: no include function (undefined)."
|
|
167
|
+
);
|
|
168
|
+
include = void 0;
|
|
150
169
|
}
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return false;
|
|
170
|
+
if (typeof skipNegativeTabIndexCheck !== "boolean") {
|
|
171
|
+
console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
|
|
172
|
+
skipNegativeTabIndexCheck = false;
|
|
155
173
|
}
|
|
156
|
-
if (
|
|
157
|
-
|
|
174
|
+
if (typeof skipVisibilityCheck !== "boolean") {
|
|
175
|
+
console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
|
|
176
|
+
skipVisibilityCheck = false;
|
|
158
177
|
}
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
visibilityProperty: true
|
|
163
|
-
})) {
|
|
164
|
-
return false;
|
|
178
|
+
if (typeof wrap !== "boolean") {
|
|
179
|
+
console.warn("Invalid wrap option. Fallback: false.");
|
|
180
|
+
wrap = false;
|
|
165
181
|
}
|
|
166
|
-
return
|
|
182
|
+
return {
|
|
183
|
+
anchor,
|
|
184
|
+
composed,
|
|
185
|
+
filter,
|
|
186
|
+
include,
|
|
187
|
+
skipNegativeTabIndexCheck,
|
|
188
|
+
skipVisibilityCheck,
|
|
189
|
+
wrap
|
|
190
|
+
};
|
|
167
191
|
}
|
|
168
192
|
function isDisabledDeep(element) {
|
|
169
193
|
let current = element;
|
|
@@ -245,107 +269,193 @@ function sortByTabIndex(elements) {
|
|
|
245
269
|
}
|
|
246
270
|
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
247
271
|
}
|
|
248
|
-
function
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (!(node instanceof Element)) {
|
|
253
|
-
return [];
|
|
272
|
+
function getFocusables(container = document.body, options = {}) {
|
|
273
|
+
if (!(container instanceof Element)) {
|
|
274
|
+
console.warn("Invalid container element. Fallback: <body> element.");
|
|
275
|
+
container = document.body;
|
|
254
276
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
277
|
+
const {
|
|
278
|
+
composed,
|
|
279
|
+
filter,
|
|
280
|
+
include,
|
|
281
|
+
skipNegativeTabIndexCheck,
|
|
282
|
+
skipVisibilityCheck
|
|
283
|
+
} = resolveOptions2(options);
|
|
284
|
+
const candidates = [];
|
|
285
|
+
if (!composed && !include) {
|
|
286
|
+
for (const match of container.querySelectorAll(
|
|
287
|
+
!skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR : FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX
|
|
288
|
+
)) {
|
|
289
|
+
match && isFocusable(match, {
|
|
290
|
+
skipNegativeTabIndexCheck,
|
|
291
|
+
skipVisibilityCheck
|
|
292
|
+
}) && candidates.push(match);
|
|
259
293
|
}
|
|
294
|
+
} else {
|
|
295
|
+
let traverse2 = function(node) {
|
|
296
|
+
if (isFocusable(node, {
|
|
297
|
+
skipNegativeTabIndexCheck,
|
|
298
|
+
skipVisibilityCheck
|
|
299
|
+
}) || include?.(node)) {
|
|
300
|
+
candidates.push(node);
|
|
301
|
+
}
|
|
302
|
+
(!composed ? [...node.children] : getComposedChildren(node)).map(
|
|
303
|
+
traverse2
|
|
304
|
+
);
|
|
305
|
+
};
|
|
306
|
+
(!composed ? [...container.children] : getComposedChildren(container)).map(
|
|
307
|
+
traverse2
|
|
308
|
+
);
|
|
260
309
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return [...node.children];
|
|
265
|
-
}
|
|
266
|
-
function focusElement(element) {
|
|
267
|
-
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
310
|
+
return normalizeRadioGroup(
|
|
311
|
+
sortByTabIndex(!filter ? candidates : candidates.filter(filter))
|
|
312
|
+
);
|
|
268
313
|
}
|
|
269
|
-
function
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
314
|
+
function isFocusable(element, options = {}) {
|
|
315
|
+
if (!(element instanceof Element)) {
|
|
316
|
+
console.warn("Invalid element");
|
|
317
|
+
return false;
|
|
273
318
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
319
|
+
const { skipNegativeTabIndexCheck, skipVisibilityCheck } = resolveOptions2(options);
|
|
320
|
+
if (element.hasAttribute("hidden") || isInert(element)) {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
if (!skipNegativeTabIndexCheck && getTabIndex(element) < 0) {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
if (!element.matches(
|
|
327
|
+
!skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR : FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX
|
|
328
|
+
)) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
if (isDisabledDeep(element)) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
if (!skipVisibilityCheck && !element.checkVisibility({
|
|
335
|
+
contentVisibilityAuto: true,
|
|
336
|
+
opacityProperty: true,
|
|
337
|
+
visibilityProperty: true
|
|
338
|
+
})) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
return true;
|
|
281
342
|
}
|
|
282
|
-
|
|
283
|
-
|
|
343
|
+
|
|
344
|
+
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
345
|
+
function getCellCoords(cell) {
|
|
346
|
+
const { left, top, width, height } = cell.getBoundingClientRect();
|
|
347
|
+
return { x: left + width / 2, y: top + height / 2 };
|
|
284
348
|
}
|
|
285
|
-
function
|
|
286
|
-
|
|
349
|
+
function getCellsOfActiveRow(cells) {
|
|
350
|
+
const active = getActiveElement();
|
|
351
|
+
if (!(active instanceof Element)) {
|
|
352
|
+
return [];
|
|
353
|
+
}
|
|
354
|
+
const activeRect = active.getBoundingClientRect();
|
|
355
|
+
return cells.filter((cell) => {
|
|
356
|
+
const cellRect = cell.getBoundingClientRect();
|
|
357
|
+
return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
|
|
358
|
+
});
|
|
287
359
|
}
|
|
288
|
-
function
|
|
289
|
-
|
|
360
|
+
function getNextCell(cells, key, wrap) {
|
|
361
|
+
const active = getActiveElement();
|
|
362
|
+
if (!(active instanceof Element)) {
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
const activeCoords = getCellCoords(active);
|
|
366
|
+
let min = Infinity;
|
|
367
|
+
let result = null;
|
|
368
|
+
for (const cell of cells) {
|
|
369
|
+
if (cell === active) {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
const cellCoords = getCellCoords(cell);
|
|
373
|
+
const distances = {
|
|
374
|
+
x: Math.abs(cellCoords.x - activeCoords.x),
|
|
375
|
+
y: Math.abs(cellCoords.y - activeCoords.y)
|
|
376
|
+
};
|
|
377
|
+
if (key === "ArrowUp" && cellCoords.y < activeCoords.y && distances.x < distances.y || key === "ArrowDown" && cellCoords.y > activeCoords.y && distances.x < distances.y) {
|
|
378
|
+
const distance = distances.x ** 2 + distances.y ** 2;
|
|
379
|
+
if (distance < min) {
|
|
380
|
+
min = distance;
|
|
381
|
+
result = cell;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (!result && wrap) {
|
|
386
|
+
let max = -Infinity;
|
|
387
|
+
for (const cell of cells) {
|
|
388
|
+
if (cell === active) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
const cellCoords = getCellCoords(cell);
|
|
392
|
+
if (Math.abs(cellCoords.x - activeCoords.x) < cell.getBoundingClientRect().width / 2) {
|
|
393
|
+
const distance = key === "ArrowUp" ? cellCoords.y - activeCoords.y : activeCoords.y - cellCoords.y;
|
|
394
|
+
if (distance > max) {
|
|
395
|
+
max = distance;
|
|
396
|
+
result = cell;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return result;
|
|
290
402
|
}
|
|
291
|
-
|
|
403
|
+
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
404
|
+
function resolveOptions3(options) {
|
|
292
405
|
let {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
406
|
+
direction = "both",
|
|
407
|
+
navigationOnly = false,
|
|
408
|
+
noMemory = false,
|
|
409
|
+
noStart = false,
|
|
410
|
+
selector = "",
|
|
411
|
+
typeahead = false,
|
|
299
412
|
wrap = false
|
|
300
413
|
} = options;
|
|
301
|
-
if (
|
|
302
|
-
|
|
303
|
-
if (active instanceof Element) {
|
|
304
|
-
console.warn("Invalid anchor element. Fallback: active element.");
|
|
305
|
-
anchor = active;
|
|
306
|
-
}
|
|
414
|
+
if (typeof direction === "string") {
|
|
415
|
+
direction = direction.toLowerCase();
|
|
307
416
|
}
|
|
308
|
-
if (
|
|
309
|
-
console.warn("Invalid
|
|
310
|
-
|
|
417
|
+
if (!DIRECTIONS.includes(direction)) {
|
|
418
|
+
console.warn("Invalid direction option. Fallback: 'both'.");
|
|
419
|
+
direction = "both";
|
|
311
420
|
}
|
|
312
|
-
if (
|
|
313
|
-
console.warn(
|
|
314
|
-
|
|
315
|
-
);
|
|
316
|
-
filter = void 0;
|
|
421
|
+
if (typeof navigationOnly !== "boolean") {
|
|
422
|
+
console.warn("Invalid navigationOnly option. Fallback: false.");
|
|
423
|
+
navigationOnly = false;
|
|
317
424
|
}
|
|
318
|
-
if (
|
|
319
|
-
console.warn(
|
|
320
|
-
|
|
321
|
-
);
|
|
322
|
-
include = void 0;
|
|
425
|
+
if (typeof noMemory !== "boolean") {
|
|
426
|
+
console.warn("Invalid noMemory option. Fallback: false.");
|
|
427
|
+
noMemory = false;
|
|
323
428
|
}
|
|
324
|
-
if (typeof
|
|
325
|
-
console.warn("Invalid
|
|
326
|
-
|
|
429
|
+
if (typeof noStart !== "boolean") {
|
|
430
|
+
console.warn("Invalid noStart option. Fallback: false.");
|
|
431
|
+
noStart = false;
|
|
327
432
|
}
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
|
|
433
|
+
if (selector !== "") {
|
|
434
|
+
try {
|
|
435
|
+
document.querySelector(selector);
|
|
436
|
+
} catch {
|
|
437
|
+
console.warn("Invalid selector. Fallback: no selector string.");
|
|
438
|
+
selector = "";
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (typeof typeahead !== "boolean") {
|
|
442
|
+
console.warn("Invalid typeahead option. Fallback: false.");
|
|
443
|
+
typeahead = false;
|
|
331
444
|
}
|
|
332
445
|
if (typeof wrap !== "boolean") {
|
|
333
446
|
console.warn("Invalid wrap option. Fallback: false.");
|
|
334
447
|
wrap = false;
|
|
335
448
|
}
|
|
336
449
|
return {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
450
|
+
direction,
|
|
451
|
+
navigationOnly,
|
|
452
|
+
noMemory,
|
|
453
|
+
noStart,
|
|
454
|
+
selector,
|
|
455
|
+
typeahead,
|
|
343
456
|
wrap
|
|
344
457
|
};
|
|
345
458
|
}
|
|
346
|
-
|
|
347
|
-
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
348
|
-
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
349
459
|
function createRovingTabIndex(container, options = {}) {
|
|
350
460
|
if (!(container instanceof Element)) {
|
|
351
461
|
console.warn("Invalid container element");
|
|
@@ -366,7 +476,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
366
476
|
#isDestroyed = false;
|
|
367
477
|
constructor(container, options = {}) {
|
|
368
478
|
this.#container = container;
|
|
369
|
-
this.#settings =
|
|
479
|
+
this.#settings = resolveOptions3(options);
|
|
370
480
|
this.#selectorFilter = this.#createSelectorFilter();
|
|
371
481
|
this.#initialize();
|
|
372
482
|
}
|
|
@@ -547,20 +657,8 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
547
657
|
const { selector } = this.#settings;
|
|
548
658
|
return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
|
|
549
659
|
}
|
|
550
|
-
#getCellCoords(cell) {
|
|
551
|
-
const { left, top, width, height } = cell.getBoundingClientRect();
|
|
552
|
-
return { x: left + width / 2, y: top + height / 2 };
|
|
553
|
-
}
|
|
554
660
|
#getCellsOfActiveRow() {
|
|
555
|
-
|
|
556
|
-
if (!(active instanceof Element)) {
|
|
557
|
-
return [];
|
|
558
|
-
}
|
|
559
|
-
const activeRect = active.getBoundingClientRect();
|
|
560
|
-
return this.#getFocusables().filter((cell) => {
|
|
561
|
-
const cellRect = cell.getBoundingClientRect();
|
|
562
|
-
return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
|
|
563
|
-
});
|
|
661
|
+
return getCellsOfActiveRow(this.#getFocusables());
|
|
564
662
|
}
|
|
565
663
|
#getFocusables() {
|
|
566
664
|
return getFocusables(this.#container, {
|
|
@@ -571,111 +669,28 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
571
669
|
});
|
|
572
670
|
}
|
|
573
671
|
#getNextCell(key, wrap) {
|
|
574
|
-
|
|
575
|
-
const active = getActiveElement();
|
|
576
|
-
if (!(active instanceof Element)) {
|
|
577
|
-
return null;
|
|
578
|
-
}
|
|
579
|
-
const activeCoords = this.#getCellCoords(active);
|
|
580
|
-
let min = Infinity;
|
|
581
|
-
let result = null;
|
|
582
|
-
for (const cell of cells) {
|
|
583
|
-
if (cell === active) {
|
|
584
|
-
continue;
|
|
585
|
-
}
|
|
586
|
-
const cellCoords = this.#getCellCoords(cell);
|
|
587
|
-
const distances = {
|
|
588
|
-
x: Math.abs(cellCoords.x - activeCoords.x),
|
|
589
|
-
y: Math.abs(cellCoords.y - activeCoords.y)
|
|
590
|
-
};
|
|
591
|
-
if (key === "ArrowUp" && cellCoords.y < activeCoords.y && distances.x < distances.y || key === "ArrowDown" && cellCoords.y > activeCoords.y && distances.x < distances.y) {
|
|
592
|
-
const distance = distances.x ** 2 + distances.y ** 2;
|
|
593
|
-
if (distance < min) {
|
|
594
|
-
min = distance;
|
|
595
|
-
result = cell;
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
if (!result && wrap) {
|
|
600
|
-
let max = -Infinity;
|
|
601
|
-
for (const cell of cells) {
|
|
602
|
-
if (cell === active) {
|
|
603
|
-
continue;
|
|
604
|
-
}
|
|
605
|
-
const cellCoords = this.#getCellCoords(cell);
|
|
606
|
-
if (Math.abs(cellCoords.x - activeCoords.x) < cell.getBoundingClientRect().width / 2) {
|
|
607
|
-
const distance = key === "ArrowUp" ? cellCoords.y - activeCoords.y : activeCoords.y - cellCoords.y;
|
|
608
|
-
if (distance > max) {
|
|
609
|
-
max = distance;
|
|
610
|
-
result = cell;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
return result;
|
|
616
|
-
}
|
|
617
|
-
#resolveOptions(options) {
|
|
618
|
-
let {
|
|
619
|
-
direction = "both",
|
|
620
|
-
navigationOnly = false,
|
|
621
|
-
noMemory = false,
|
|
622
|
-
noStart = false,
|
|
623
|
-
selector = "",
|
|
624
|
-
typeahead = false,
|
|
625
|
-
wrap = false
|
|
626
|
-
} = options;
|
|
627
|
-
if (typeof direction === "string") {
|
|
628
|
-
direction = direction.toLowerCase();
|
|
629
|
-
}
|
|
630
|
-
if (!DIRECTIONS.includes(direction)) {
|
|
631
|
-
console.warn("Invalid direction option. Fallback: 'both'.");
|
|
632
|
-
direction = "both";
|
|
633
|
-
}
|
|
634
|
-
if (typeof navigationOnly !== "boolean") {
|
|
635
|
-
console.warn("Invalid navigationOnly option. Fallback: false.");
|
|
636
|
-
navigationOnly = false;
|
|
637
|
-
}
|
|
638
|
-
if (typeof noMemory !== "boolean") {
|
|
639
|
-
console.warn("Invalid noMemory option. Fallback: false.");
|
|
640
|
-
noMemory = false;
|
|
641
|
-
}
|
|
642
|
-
if (typeof noStart !== "boolean") {
|
|
643
|
-
console.warn("Invalid noStart option. Fallback: false.");
|
|
644
|
-
noStart = false;
|
|
645
|
-
}
|
|
646
|
-
if (selector !== "") {
|
|
647
|
-
try {
|
|
648
|
-
document.querySelector(selector);
|
|
649
|
-
} catch {
|
|
650
|
-
console.warn("Invalid selector. Fallback: no selector string.");
|
|
651
|
-
selector = "";
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
if (typeof typeahead !== "boolean") {
|
|
655
|
-
console.warn("Invalid typeahead option. Fallback: false.");
|
|
656
|
-
typeahead = false;
|
|
657
|
-
}
|
|
658
|
-
if (typeof wrap !== "boolean") {
|
|
659
|
-
console.warn("Invalid wrap option. Fallback: false.");
|
|
660
|
-
wrap = false;
|
|
661
|
-
}
|
|
662
|
-
return {
|
|
663
|
-
direction,
|
|
664
|
-
navigationOnly,
|
|
665
|
-
noMemory,
|
|
666
|
-
noStart,
|
|
667
|
-
selector,
|
|
668
|
-
typeahead,
|
|
669
|
-
wrap
|
|
670
|
-
};
|
|
672
|
+
return getNextCell(this.#getFocusables(), key, wrap);
|
|
671
673
|
}
|
|
672
674
|
};
|
|
673
675
|
|
|
676
|
+
// src/defaults.ts
|
|
677
|
+
var defaults = { collapsible: true };
|
|
678
|
+
|
|
679
|
+
// src/options.ts
|
|
680
|
+
function resolveOptions4(defaults2, source) {
|
|
681
|
+
const merged = { ...defaults2, ...source };
|
|
682
|
+
if (typeof merged.collapsible !== "boolean") {
|
|
683
|
+
const collapsible = defaults2.collapsible;
|
|
684
|
+
console.warn(`Invalid collapsible option. Fallback: ${collapsible}.`);
|
|
685
|
+
merged.collapsible = collapsible;
|
|
686
|
+
}
|
|
687
|
+
return merged;
|
|
688
|
+
}
|
|
689
|
+
|
|
674
690
|
// src/index.ts
|
|
675
691
|
var Disclosure = class _Disclosure {
|
|
676
692
|
static defaults = {};
|
|
677
693
|
#rootElement;
|
|
678
|
-
#defaults = { collapsible: true };
|
|
679
694
|
#settings;
|
|
680
695
|
#detailsElements;
|
|
681
696
|
#summaryElements;
|
|
@@ -693,8 +708,10 @@ var Disclosure = class _Disclosure {
|
|
|
693
708
|
return;
|
|
694
709
|
}
|
|
695
710
|
this.#rootElement = root;
|
|
696
|
-
this.#
|
|
697
|
-
|
|
711
|
+
this.#settings = resolveOptions4(
|
|
712
|
+
resolveOptions4(defaults, _Disclosure.defaults),
|
|
713
|
+
options
|
|
714
|
+
);
|
|
698
715
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
699
716
|
this.#detailsElements = [
|
|
700
717
|
...this.#rootElement.querySelectorAll(
|
|
@@ -823,15 +840,6 @@ var Disclosure = class _Disclosure {
|
|
|
823
840
|
#isFocusable(element) {
|
|
824
841
|
return element.tabIndex >= 0;
|
|
825
842
|
}
|
|
826
|
-
#resolveOptions(target, source) {
|
|
827
|
-
const merged = { ...target, ...source };
|
|
828
|
-
if (typeof merged.collapsible !== "boolean") {
|
|
829
|
-
const collapsible = this.#defaults.collapsible;
|
|
830
|
-
console.warn(`Invalid collapsible option. Fallback: ${collapsible}.`);
|
|
831
|
-
merged.collapsible = collapsible;
|
|
832
|
-
}
|
|
833
|
-
return merged;
|
|
834
|
-
}
|
|
835
843
|
};
|
|
836
844
|
|
|
837
845
|
export { Disclosure };
|
package/dist/index.cjs
CHANGED
|
@@ -3,11 +3,26 @@
|
|
|
3
3
|
var attributeUtils = require('@y14e/attribute-utils');
|
|
4
4
|
var rovingTabindex = require('@y14e/roving-tabindex');
|
|
5
5
|
|
|
6
|
+
// src/index.ts
|
|
7
|
+
|
|
8
|
+
// src/defaults.ts
|
|
9
|
+
var defaults = { collapsible: true };
|
|
10
|
+
|
|
11
|
+
// src/options.ts
|
|
12
|
+
function resolveOptions(defaults2, source) {
|
|
13
|
+
const merged = { ...defaults2, ...source };
|
|
14
|
+
if (typeof merged.collapsible !== "boolean") {
|
|
15
|
+
const collapsible = defaults2.collapsible;
|
|
16
|
+
console.warn(`Invalid collapsible option. Fallback: ${collapsible}.`);
|
|
17
|
+
merged.collapsible = collapsible;
|
|
18
|
+
}
|
|
19
|
+
return merged;
|
|
20
|
+
}
|
|
21
|
+
|
|
6
22
|
// src/index.ts
|
|
7
23
|
var Disclosure = class _Disclosure {
|
|
8
24
|
static defaults = {};
|
|
9
25
|
#rootElement;
|
|
10
|
-
#defaults = { collapsible: true };
|
|
11
26
|
#settings;
|
|
12
27
|
#detailsElements;
|
|
13
28
|
#summaryElements;
|
|
@@ -25,8 +40,10 @@ var Disclosure = class _Disclosure {
|
|
|
25
40
|
return;
|
|
26
41
|
}
|
|
27
42
|
this.#rootElement = root;
|
|
28
|
-
this.#
|
|
29
|
-
|
|
43
|
+
this.#settings = resolveOptions(
|
|
44
|
+
resolveOptions(defaults, _Disclosure.defaults),
|
|
45
|
+
options
|
|
46
|
+
);
|
|
30
47
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
31
48
|
this.#detailsElements = [
|
|
32
49
|
...this.#rootElement.querySelectorAll(
|
|
@@ -155,15 +172,6 @@ var Disclosure = class _Disclosure {
|
|
|
155
172
|
#isFocusable(element) {
|
|
156
173
|
return element.tabIndex >= 0;
|
|
157
174
|
}
|
|
158
|
-
#resolveOptions(target, source) {
|
|
159
|
-
const merged = { ...target, ...source };
|
|
160
|
-
if (typeof merged.collapsible !== "boolean") {
|
|
161
|
-
const collapsible = this.#defaults.collapsible;
|
|
162
|
-
console.warn(`Invalid collapsible option. Fallback: ${collapsible}.`);
|
|
163
|
-
merged.collapsible = collapsible;
|
|
164
|
-
}
|
|
165
|
-
return merged;
|
|
166
|
-
}
|
|
167
175
|
};
|
|
168
176
|
|
|
169
177
|
exports.Disclosure = Disclosure;
|