@y14e/disclosure-css 1.3.10 → 1.3.11
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 +704 -0
- package/dist/index.bundle.js +702 -0
- package/dist/index.cjs +8 -566
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -563
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -1,524 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var DEFAULT_SERIALIZER = (tokens) => tokens.join(" ");
|
|
6
|
-
function addTokenToAttribute(element, attribute, token, options = {}) {
|
|
7
|
-
const {
|
|
8
|
-
caseInsensitive = false,
|
|
9
|
-
parse = DEFAULT_PARSER,
|
|
10
|
-
serialize = DEFAULT_SERIALIZER
|
|
11
|
-
} = options;
|
|
12
|
-
const value = element.getAttribute(attribute)?.trim();
|
|
13
|
-
const tokens = value ? parse(value).filter(Boolean) : [];
|
|
14
|
-
if (caseInsensitive) {
|
|
15
|
-
const lower = token.toLowerCase();
|
|
16
|
-
if (tokens.every((token2) => token2.toLowerCase() !== lower)) {
|
|
17
|
-
tokens.push(token);
|
|
18
|
-
element.setAttribute(attribute, serialize(tokens));
|
|
19
|
-
}
|
|
20
|
-
} else {
|
|
21
|
-
const set = new Set(tokens);
|
|
22
|
-
set.add(token);
|
|
23
|
-
element.setAttribute(attribute, serialize([...set]));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
27
|
-
function restoreAttributes(elements) {
|
|
28
|
-
for (const element of elements) {
|
|
29
|
-
const snapshot = snapshots.get(element);
|
|
30
|
-
if (!snapshot) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
for (const [attribute, value] of snapshot.entries()) {
|
|
34
|
-
value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
|
|
35
|
-
}
|
|
36
|
-
snapshots.delete(element);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function saveAttributes(elements, attributes) {
|
|
40
|
-
elements.forEach((element) => {
|
|
41
|
-
let snapshot = snapshots.get(element);
|
|
42
|
-
if (!snapshot) {
|
|
43
|
-
snapshot = /* @__PURE__ */ new Map();
|
|
44
|
-
snapshots.set(element, snapshot);
|
|
45
|
-
}
|
|
46
|
-
attributes.forEach((attribute) => {
|
|
47
|
-
snapshot.set(attribute, element.getAttribute(attribute));
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
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"])`;
|
|
52
|
-
function getFocusables(container = document.body, options = {}) {
|
|
53
|
-
if (!(container instanceof Element)) {
|
|
54
|
-
console.warn("Invalid container element. Fallback: <body> element.");
|
|
55
|
-
container = document.body;
|
|
56
|
-
}
|
|
57
|
-
let {
|
|
58
|
-
composed = false,
|
|
59
|
-
filter,
|
|
60
|
-
include,
|
|
61
|
-
skipNegativeTabIndexCheck = false,
|
|
62
|
-
skipVisibilityCheck = false
|
|
63
|
-
} = options;
|
|
64
|
-
if (typeof composed !== "boolean") {
|
|
65
|
-
console.warn("Invalid composed option. Fallback: false.");
|
|
66
|
-
composed = false;
|
|
67
|
-
}
|
|
68
|
-
if (typeof filter !== "undefined" && typeof filter !== "function") {
|
|
69
|
-
console.warn(
|
|
70
|
-
"Invalid filter function. Fallback: no filter function (undefined)."
|
|
71
|
-
);
|
|
72
|
-
filter = void 0;
|
|
73
|
-
}
|
|
74
|
-
if (typeof include !== "undefined" && typeof include !== "function") {
|
|
75
|
-
console.warn(
|
|
76
|
-
"Invalid include function. Fallback: no include function (undefined)."
|
|
77
|
-
);
|
|
78
|
-
include = void 0;
|
|
79
|
-
}
|
|
80
|
-
if (typeof skipNegativeTabIndexCheck !== "boolean") {
|
|
81
|
-
console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
|
|
82
|
-
skipNegativeTabIndexCheck = false;
|
|
83
|
-
}
|
|
84
|
-
if (typeof skipVisibilityCheck !== "boolean") {
|
|
85
|
-
console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
|
|
86
|
-
skipVisibilityCheck = false;
|
|
87
|
-
}
|
|
88
|
-
const elements = [];
|
|
89
|
-
if (composed || include) {
|
|
90
|
-
let traverse2 = function(node) {
|
|
91
|
-
if (!(node instanceof Element)) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (isFocusable(node, { skipNegativeTabIndexCheck, skipVisibilityCheck }) || include?.(node)) {
|
|
95
|
-
elements[elements.length] = node;
|
|
96
|
-
}
|
|
97
|
-
const children = getComposedChildren(node);
|
|
98
|
-
for (let i = 0, l = children.length; i < l; i++) {
|
|
99
|
-
const child = children[i];
|
|
100
|
-
child && traverse2(child);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
traverse2(container);
|
|
104
|
-
} else {
|
|
105
|
-
const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
106
|
-
for (let i = 0, l = candidates.length; i < l; i++) {
|
|
107
|
-
const candidate = candidates[i];
|
|
108
|
-
if (candidate && isFocusable(candidate, {
|
|
109
|
-
skipNegativeTabIndexCheck,
|
|
110
|
-
skipVisibilityCheck
|
|
111
|
-
})) {
|
|
112
|
-
elements[elements.length] = candidate;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const unfiltered = normalizeRadioGroup(sortByTabIndex(elements));
|
|
117
|
-
return filter ? unfiltered.filter(filter) : unfiltered;
|
|
118
|
-
}
|
|
119
|
-
function isFocusable(element, options = {}) {
|
|
120
|
-
if (!(element instanceof Element)) {
|
|
121
|
-
console.warn("Invalid element");
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
let { skipNegativeTabIndexCheck = false, skipVisibilityCheck = false } = options;
|
|
125
|
-
if (typeof skipNegativeTabIndexCheck !== "boolean") {
|
|
126
|
-
console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
|
|
127
|
-
skipNegativeTabIndexCheck = false;
|
|
128
|
-
}
|
|
129
|
-
if (typeof skipVisibilityCheck !== "boolean") {
|
|
130
|
-
console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
|
|
131
|
-
skipVisibilityCheck = false;
|
|
132
|
-
}
|
|
133
|
-
if (element.hasAttribute("hidden") || isInert(element)) {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
if (!skipNegativeTabIndexCheck && getTabIndex(element) < 0) {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
if (!element.matches(
|
|
140
|
-
skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR.replace(/(,\s*)?\[tabindex="-1"\]/g, "") : FOCUSABLE_SELECTOR
|
|
141
|
-
)) {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
if (isDisabledDeep(element)) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
if (!skipVisibilityCheck && !element.checkVisibility({
|
|
148
|
-
contentVisibilityAuto: true,
|
|
149
|
-
opacityProperty: true,
|
|
150
|
-
visibilityProperty: true
|
|
151
|
-
})) {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
return true;
|
|
155
|
-
}
|
|
156
|
-
function isDisabledDeep(element) {
|
|
157
|
-
let current = element;
|
|
158
|
-
while (current) {
|
|
159
|
-
if (current instanceof ShadowRoot) {
|
|
160
|
-
if (current.mode !== "open") {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
current = current.host;
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
if (!(current instanceof Element)) {
|
|
167
|
-
current = current.parentNode;
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
if (current === element && isFormControl(current) && isDisabled(current)) {
|
|
171
|
-
return true;
|
|
172
|
-
}
|
|
173
|
-
if (isInert(current)) {
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current)) {
|
|
177
|
-
if (!current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
current = current.parentNode;
|
|
182
|
-
}
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
function normalizeRadioGroup(elements) {
|
|
186
|
-
let map = null;
|
|
187
|
-
for (let i = 0, l = elements.length; i < l; i++) {
|
|
188
|
-
const element = elements[i];
|
|
189
|
-
if (!(element instanceof HTMLInputElement)) {
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
if (!isUngroupedRadio(element)) {
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
if (!map) {
|
|
196
|
-
map = /* @__PURE__ */ new Map();
|
|
197
|
-
}
|
|
198
|
-
const key = `${element.form?.id ?? "no-form"}::${element.name}`;
|
|
199
|
-
const group = map.get(key) ?? map.set(key, []).get(key);
|
|
200
|
-
if (group) {
|
|
201
|
-
group[group.length] = element;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (!map) {
|
|
205
|
-
return elements;
|
|
206
|
-
}
|
|
207
|
-
const placeholder = /* @__PURE__ */ new Set();
|
|
208
|
-
for (const group of map.values()) {
|
|
209
|
-
placeholder.add(group.find((radio) => radio.checked) ?? group[0]);
|
|
210
|
-
}
|
|
211
|
-
return elements.filter(
|
|
212
|
-
(element) => isUngroupedRadio(element) ? placeholder.has(element) : true
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
function sortByTabIndex(elements) {
|
|
216
|
-
const ordered = [];
|
|
217
|
-
const natural = [];
|
|
218
|
-
for (let i = 0, l = elements.length; i < l; i++) {
|
|
219
|
-
const element = elements[i];
|
|
220
|
-
if (element) {
|
|
221
|
-
const target = getTabIndex(element) > 0 ? ordered : natural;
|
|
222
|
-
target[target.length] = element;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
|
|
226
|
-
let count = 0;
|
|
227
|
-
const sorted = new Array(ordered.length + natural.length);
|
|
228
|
-
for (let i = 0, l = ordered.length; i < l; i++) {
|
|
229
|
-
sorted[count++] = ordered[i];
|
|
230
|
-
}
|
|
231
|
-
for (let i = 0, l = natural.length; i < l; i++) {
|
|
232
|
-
sorted[count++] = natural[i];
|
|
233
|
-
}
|
|
234
|
-
return sorted;
|
|
235
|
-
}
|
|
236
|
-
function getComposedChildren(node) {
|
|
237
|
-
if (node instanceof ShadowRoot) {
|
|
238
|
-
return getChildren(node);
|
|
239
|
-
}
|
|
240
|
-
if (!(node instanceof Element)) {
|
|
241
|
-
return [];
|
|
242
|
-
}
|
|
243
|
-
if (node instanceof HTMLSlotElement) {
|
|
244
|
-
const assigned = node.assignedElements({ flatten: true });
|
|
245
|
-
if (assigned.length) {
|
|
246
|
-
return assigned;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
250
|
-
return getChildren(node.shadowRoot);
|
|
251
|
-
}
|
|
252
|
-
return getChildren(node);
|
|
253
|
-
}
|
|
254
|
-
function focusElement(element) {
|
|
255
|
-
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
256
|
-
}
|
|
257
|
-
function getActiveElement() {
|
|
258
|
-
let current = document.activeElement;
|
|
259
|
-
while (current?.shadowRoot?.activeElement) {
|
|
260
|
-
current = current.shadowRoot.activeElement;
|
|
261
|
-
}
|
|
262
|
-
return current;
|
|
263
|
-
}
|
|
264
|
-
function getChildren(node) {
|
|
265
|
-
const elements = [];
|
|
266
|
-
for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
|
|
267
|
-
elements[elements.length] = child;
|
|
268
|
-
}
|
|
269
|
-
return elements;
|
|
270
|
-
}
|
|
271
|
-
function getTabIndex(element) {
|
|
272
|
-
return "tabIndex" in element ? Number(element.tabIndex) : 0;
|
|
273
|
-
}
|
|
274
|
-
function isDisabled(element) {
|
|
275
|
-
return "disabled" in element && !!element.disabled;
|
|
276
|
-
}
|
|
277
|
-
function isFormControl(element) {
|
|
278
|
-
const name = element.tagName;
|
|
279
|
-
return name === "BUTTON" || name === "INPUT" || name === "SELECT" || name === "TEXTAREA";
|
|
280
|
-
}
|
|
281
|
-
function isInert(element) {
|
|
282
|
-
return "inert" in element && !!element.inert;
|
|
283
|
-
}
|
|
284
|
-
function isUngroupedRadio(element) {
|
|
285
|
-
return element instanceof HTMLInputElement && element.type === "radio" && !!element.name;
|
|
286
|
-
}
|
|
287
|
-
function createRovingTabIndex(container, options = {}) {
|
|
288
|
-
if (!(container instanceof Element)) {
|
|
289
|
-
console.warn("Invalid container element");
|
|
290
|
-
return () => {
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
const roving = new RovingTabIndex(container, options);
|
|
294
|
-
return () => roving.destroy();
|
|
295
|
-
}
|
|
296
|
-
var RovingTabIndex = class {
|
|
297
|
-
#container;
|
|
298
|
-
#settings;
|
|
299
|
-
#focusables = /* @__PURE__ */ new Set();
|
|
300
|
-
#focusablesByFirstChar = /* @__PURE__ */ new Map();
|
|
301
|
-
#selectorFilter;
|
|
302
|
-
#controller = null;
|
|
303
|
-
#isDestroyed = false;
|
|
304
|
-
constructor(container, options = {}) {
|
|
305
|
-
this.#container = container;
|
|
306
|
-
let {
|
|
307
|
-
direction,
|
|
308
|
-
navigationOnly = false,
|
|
309
|
-
noMemory = false,
|
|
310
|
-
noStart = false,
|
|
311
|
-
selector,
|
|
312
|
-
typeahead = false,
|
|
313
|
-
wrap = false
|
|
314
|
-
} = options;
|
|
315
|
-
if (typeof direction !== "undefined" && !["horizontal", "vertical"].includes(direction)) {
|
|
316
|
-
console.warn("Invalid direction option. Fallback: both (undefined).");
|
|
317
|
-
direction = void 0;
|
|
318
|
-
}
|
|
319
|
-
if (typeof navigationOnly !== "boolean") {
|
|
320
|
-
console.warn("Invalid navigationOnly option. Fallback: false.");
|
|
321
|
-
navigationOnly = false;
|
|
322
|
-
}
|
|
323
|
-
if (typeof noMemory !== "boolean") {
|
|
324
|
-
console.warn("Invalid noMemory option. Fallback: false.");
|
|
325
|
-
noMemory = false;
|
|
326
|
-
}
|
|
327
|
-
if (typeof noStart !== "boolean") {
|
|
328
|
-
console.warn("Invalid noStart option. Fallback: false.");
|
|
329
|
-
noStart = false;
|
|
330
|
-
}
|
|
331
|
-
if (typeof selector !== "undefined" && (typeof selector !== "string" || !selector.trim())) {
|
|
332
|
-
console.warn(
|
|
333
|
-
"Invalid selector. Fallback: all focusable elements (undefined)."
|
|
334
|
-
);
|
|
335
|
-
selector = void 0;
|
|
336
|
-
}
|
|
337
|
-
if (typeof typeahead !== "boolean") {
|
|
338
|
-
console.warn("Invalid typeahead option. Fallback: false.");
|
|
339
|
-
typeahead = false;
|
|
340
|
-
}
|
|
341
|
-
if (typeof wrap !== "boolean") {
|
|
342
|
-
console.warn("Invalid wrap option. Fallback: false.");
|
|
343
|
-
wrap = false;
|
|
344
|
-
}
|
|
345
|
-
this.#settings = {
|
|
346
|
-
navigationOnly,
|
|
347
|
-
noMemory,
|
|
348
|
-
noStart,
|
|
349
|
-
typeahead,
|
|
350
|
-
wrap
|
|
351
|
-
};
|
|
352
|
-
direction && Object.assign(this.#settings, { direction });
|
|
353
|
-
selector && Object.assign(this.#settings, { selector });
|
|
354
|
-
this.#selectorFilter = this.#createSelectorFilter();
|
|
355
|
-
this.#initialize();
|
|
356
|
-
}
|
|
357
|
-
destroy() {
|
|
358
|
-
if (this.#isDestroyed) {
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
this.#isDestroyed = true;
|
|
362
|
-
this.#controller?.abort();
|
|
363
|
-
this.#controller = null;
|
|
364
|
-
restoreAttributes([...this.#focusables]);
|
|
365
|
-
this.#focusables.clear();
|
|
366
|
-
this.#focusablesByFirstChar.clear();
|
|
367
|
-
this.#container.removeAttribute("data-roving-tabindex-initialized");
|
|
368
|
-
}
|
|
369
|
-
#initialize() {
|
|
370
|
-
this.#update(document.activeElement);
|
|
371
|
-
this.#controller = new AbortController();
|
|
372
|
-
const { signal } = this.#controller;
|
|
373
|
-
document.addEventListener("focusin", this.#onFocusIn, {
|
|
374
|
-
capture: true,
|
|
375
|
-
signal
|
|
376
|
-
});
|
|
377
|
-
document.addEventListener("keydown", this.#onKeyDown, {
|
|
378
|
-
capture: true,
|
|
379
|
-
signal
|
|
380
|
-
});
|
|
381
|
-
this.#container.setAttribute("data-roving-tabindex-initialized", "");
|
|
382
|
-
}
|
|
383
|
-
#onFocusIn = (event) => {
|
|
384
|
-
const { target } = event;
|
|
385
|
-
if (!(target instanceof Element)) {
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
const isFocusable22 = this.#focusables.has(target);
|
|
389
|
-
this.#settings.noMemory && !isFocusable22 ? this.#update(null) : isFocusable22 && this.#update(target);
|
|
390
|
-
};
|
|
391
|
-
#onKeyDown = (event) => {
|
|
392
|
-
if (!event.composedPath().includes(this.#container)) {
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
396
|
-
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
const { direction, typeahead, wrap } = this.#settings;
|
|
400
|
-
const isBoth = !direction;
|
|
401
|
-
const isHorizontal = direction === "horizontal";
|
|
402
|
-
if (![
|
|
403
|
-
"End",
|
|
404
|
-
"Home",
|
|
405
|
-
...isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
|
|
406
|
-
...isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
|
|
407
|
-
].includes(key)) {
|
|
408
|
-
if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
const active = getActiveElement();
|
|
413
|
-
if (!(active instanceof HTMLElement)) {
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
const current = this.#getFocusables();
|
|
417
|
-
if (!current.includes(active)) {
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
event.preventDefault();
|
|
421
|
-
const currentIndex = current.indexOf(active);
|
|
422
|
-
let newIndex;
|
|
423
|
-
let target = current;
|
|
424
|
-
switch (key) {
|
|
425
|
-
case "End":
|
|
426
|
-
newIndex = -1;
|
|
427
|
-
break;
|
|
428
|
-
case "Home":
|
|
429
|
-
newIndex = 0;
|
|
430
|
-
break;
|
|
431
|
-
case "ArrowLeft":
|
|
432
|
-
case "ArrowUp": {
|
|
433
|
-
const rawIndex = currentIndex - 1;
|
|
434
|
-
newIndex = wrap ? rawIndex : Math.max(rawIndex, 0);
|
|
435
|
-
break;
|
|
436
|
-
}
|
|
437
|
-
case "ArrowRight":
|
|
438
|
-
case "ArrowDown": {
|
|
439
|
-
const rawIndex = currentIndex + 1;
|
|
440
|
-
newIndex = wrap ? rawIndex % current.length : Math.min(rawIndex, current.length - 1);
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
default: {
|
|
444
|
-
target = this.#focusablesByFirstChar.get(key.toUpperCase()) ?? [];
|
|
445
|
-
const foundIndex = target.findIndex(
|
|
446
|
-
(focusable2) => current.indexOf(focusable2) > currentIndex
|
|
447
|
-
);
|
|
448
|
-
newIndex = foundIndex >= 0 ? foundIndex : 0;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
const focusable = target.at(newIndex);
|
|
452
|
-
focusable && focusElement(focusable);
|
|
453
|
-
};
|
|
454
|
-
#update(active) {
|
|
455
|
-
const current = new Set(this.#getFocusables());
|
|
456
|
-
for (const focusable of this.#focusables) {
|
|
457
|
-
if (!current.has(focusable)) {
|
|
458
|
-
focusable.isConnected && restoreAttributes([focusable]);
|
|
459
|
-
this.#focusables.delete(focusable);
|
|
460
|
-
this.#focusablesByFirstChar.forEach((focusables) => {
|
|
461
|
-
const index = focusables.indexOf(focusable);
|
|
462
|
-
index >= 0 && focusables.splice(index, 1);
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
const { navigationOnly, noStart, typeahead } = this.#settings;
|
|
467
|
-
for (const focusable of current) {
|
|
468
|
-
if (this.#focusables.has(focusable)) {
|
|
469
|
-
continue;
|
|
470
|
-
}
|
|
471
|
-
this.#focusables.add(focusable);
|
|
472
|
-
if (!navigationOnly) {
|
|
473
|
-
saveAttributes([focusable], ["tabindex"]);
|
|
474
|
-
focusable.setAttribute("tabindex", "-1");
|
|
475
|
-
}
|
|
476
|
-
if (!typeahead) {
|
|
477
|
-
continue;
|
|
478
|
-
}
|
|
479
|
-
const char = focusable.textContent?.trim()?.at(0)?.toUpperCase();
|
|
480
|
-
const value = focusable.ariaKeyShortcuts?.trim();
|
|
481
|
-
const keys = new Set(
|
|
482
|
-
value ? value.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
|
|
483
|
-
);
|
|
484
|
-
if (char) {
|
|
485
|
-
keys.add(char);
|
|
486
|
-
saveAttributes([focusable], ["aria-keyshortcuts"]);
|
|
487
|
-
addTokenToAttribute(focusable, "aria-keyshortcuts", char, {
|
|
488
|
-
caseInsensitive: true
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
keys.forEach((key) => {
|
|
492
|
-
const focusables = this.#focusablesByFirstChar.get(key) ?? [];
|
|
493
|
-
focusables.push(focusable);
|
|
494
|
-
this.#focusablesByFirstChar.set(key, focusables);
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
if (!navigationOnly) {
|
|
498
|
-
if (active && this.#focusables.has(active)) {
|
|
499
|
-
this.#focusables.forEach((focusable) => {
|
|
500
|
-
focusable.setAttribute("tabindex", focusable === active ? "0" : "-1");
|
|
501
|
-
});
|
|
502
|
-
} else {
|
|
503
|
-
[...this.#focusables].forEach((focusable, i) => {
|
|
504
|
-
focusable.setAttribute("tabindex", i || noStart ? "-1" : "0");
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
#createSelectorFilter() {
|
|
510
|
-
const { selector } = this.#settings;
|
|
511
|
-
return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
|
|
512
|
-
}
|
|
513
|
-
#getFocusables() {
|
|
514
|
-
return getFocusables(this.#container, {
|
|
515
|
-
composed: true,
|
|
516
|
-
filter: this.#selectorFilter,
|
|
517
|
-
skipNegativeTabIndexCheck: !this.#settings.navigationOnly,
|
|
518
|
-
skipVisibilityCheck: true
|
|
519
|
-
});
|
|
520
|
-
}
|
|
521
|
-
};
|
|
3
|
+
var attributesUtils = require('@y14e/attributes-utils');
|
|
4
|
+
var rovingTabindex = require('@y14e/roving-tabindex');
|
|
522
5
|
|
|
523
6
|
// src/index.ts
|
|
524
7
|
var Disclosure = class {
|
|
@@ -597,7 +80,7 @@ var Disclosure = class {
|
|
|
597
80
|
this.#cleanupRovingTabIndex?.();
|
|
598
81
|
this.#cleanupRovingTabIndex = null;
|
|
599
82
|
this.#detailsElements.length = 0;
|
|
600
|
-
restoreAttributes(this.#summaryElements);
|
|
83
|
+
attributesUtils.restoreAttributes(this.#summaryElements);
|
|
601
84
|
this.#summaryElements.length = 0;
|
|
602
85
|
this.#contentElements.length = 0;
|
|
603
86
|
this.#rootElement.removeAttribute("data-disclosure-initialized");
|
|
@@ -613,17 +96,17 @@ var Disclosure = class {
|
|
|
613
96
|
this.#toggle(details, true);
|
|
614
97
|
}
|
|
615
98
|
#initialize() {
|
|
616
|
-
saveAttributes(this.#summaryElements, [
|
|
99
|
+
attributesUtils.saveAttributes(this.#summaryElements, [
|
|
617
100
|
"aria-disabled",
|
|
618
101
|
"style",
|
|
619
102
|
"tabindex"
|
|
620
103
|
]);
|
|
621
|
-
this.#summaryElements.filter((summary) => !
|
|
104
|
+
this.#summaryElements.filter((summary) => !isFocusable(summary)).forEach((summary) => {
|
|
622
105
|
summary.setAttribute("aria-disabled", "true");
|
|
623
106
|
summary.setAttribute("tabindex", "-1");
|
|
624
107
|
summary.style.setProperty("pointer-events", "none");
|
|
625
108
|
});
|
|
626
|
-
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#rootElement, {
|
|
109
|
+
this.#cleanupRovingTabIndex = rovingTabindex.createRovingTabIndex(this.#rootElement, {
|
|
627
110
|
direction: "vertical",
|
|
628
111
|
navigationOnly: true,
|
|
629
112
|
selector: "summary:not(:scope summary + * *)",
|
|
@@ -640,7 +123,7 @@ var Disclosure = class {
|
|
|
640
123
|
function createBinding(details, summary, content) {
|
|
641
124
|
return { details, summary, content };
|
|
642
125
|
}
|
|
643
|
-
function
|
|
126
|
+
function isFocusable(element) {
|
|
644
127
|
return element.tabIndex >= 0;
|
|
645
128
|
}
|
|
646
129
|
/**
|
|
@@ -648,52 +131,11 @@ function isFocusable2(element) {
|
|
|
648
131
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
649
132
|
* Using the <details> and <summary> element.
|
|
650
133
|
*
|
|
651
|
-
* @version 1.3.
|
|
134
|
+
* @version 1.3.11
|
|
652
135
|
* @author Yusuke Kamiyamane
|
|
653
136
|
* @license MIT
|
|
654
137
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
655
138
|
* @see {@link https://github.com/y14e/disclosure-css}
|
|
656
139
|
*/
|
|
657
|
-
/*! Bundled license information:
|
|
658
|
-
|
|
659
|
-
@y14e/roving-tabindex/dist/index.js:
|
|
660
|
-
(**
|
|
661
|
-
* Roving Tabindex
|
|
662
|
-
* Lightweight roving tabindex utility with fully focus management.
|
|
663
|
-
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
664
|
-
*
|
|
665
|
-
* @version 3.0.8
|
|
666
|
-
* @author Yusuke Kamiyamane
|
|
667
|
-
* @license MIT
|
|
668
|
-
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
669
|
-
* @see {@link https://github.com/y14e/roving-tabindex}
|
|
670
|
-
*)
|
|
671
|
-
(*! Bundled license information:
|
|
672
|
-
|
|
673
|
-
@y14e/attributes-utils/dist/index.js:
|
|
674
|
-
(**
|
|
675
|
-
* Attributes Utils
|
|
676
|
-
*
|
|
677
|
-
* @version 1.1.2
|
|
678
|
-
* @author Yusuke Kamiyamane
|
|
679
|
-
* @license MIT
|
|
680
|
-
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
681
|
-
* @see {@link https://github.com/y14e/attributes-utils}
|
|
682
|
-
*)
|
|
683
|
-
|
|
684
|
-
power-focusable/dist/index.js:
|
|
685
|
-
(**
|
|
686
|
-
* Power Focusable
|
|
687
|
-
* High-precision focus management utility with full composed tree support.
|
|
688
|
-
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
689
|
-
*
|
|
690
|
-
* @version 4.3.3
|
|
691
|
-
* @author Yusuke Kamiyamane
|
|
692
|
-
* @license MIT
|
|
693
|
-
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
694
|
-
* @see {@link https://github.com/y14e/power-focusable}
|
|
695
|
-
*)
|
|
696
|
-
*)
|
|
697
|
-
*/
|
|
698
140
|
|
|
699
141
|
module.exports = Disclosure;
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED