@y14e/disclosure 2.1.4 → 2.2.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/dist/index.bundle.cjs +238 -237
- package/dist/index.bundle.js +238 -237
- package/dist/index.cjs +46 -40
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +46 -40
- 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,135 @@ 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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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;
|
|
290
342
|
}
|
|
291
|
-
|
|
343
|
+
|
|
344
|
+
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
345
|
+
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
346
|
+
function resolveOptions3(options) {
|
|
292
347
|
let {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
348
|
+
direction = "both",
|
|
349
|
+
navigationOnly = false,
|
|
350
|
+
noMemory = false,
|
|
351
|
+
noStart = false,
|
|
352
|
+
selector = "",
|
|
353
|
+
typeahead = false,
|
|
299
354
|
wrap = false
|
|
300
355
|
} = options;
|
|
301
|
-
if (
|
|
302
|
-
|
|
303
|
-
if (active instanceof Element) {
|
|
304
|
-
console.warn("Invalid anchor element. Fallback: active element.");
|
|
305
|
-
anchor = active;
|
|
306
|
-
}
|
|
356
|
+
if (typeof direction === "string") {
|
|
357
|
+
direction = direction.toLowerCase();
|
|
307
358
|
}
|
|
308
|
-
if (
|
|
309
|
-
console.warn("Invalid
|
|
310
|
-
|
|
359
|
+
if (!DIRECTIONS.includes(direction)) {
|
|
360
|
+
console.warn("Invalid direction option. Fallback: 'both'.");
|
|
361
|
+
direction = "both";
|
|
311
362
|
}
|
|
312
|
-
if (
|
|
313
|
-
console.warn(
|
|
314
|
-
|
|
315
|
-
);
|
|
316
|
-
filter = void 0;
|
|
363
|
+
if (typeof navigationOnly !== "boolean") {
|
|
364
|
+
console.warn("Invalid navigationOnly option. Fallback: false.");
|
|
365
|
+
navigationOnly = false;
|
|
317
366
|
}
|
|
318
|
-
if (
|
|
319
|
-
console.warn(
|
|
320
|
-
|
|
321
|
-
);
|
|
322
|
-
include = void 0;
|
|
367
|
+
if (typeof noMemory !== "boolean") {
|
|
368
|
+
console.warn("Invalid noMemory option. Fallback: false.");
|
|
369
|
+
noMemory = false;
|
|
323
370
|
}
|
|
324
|
-
if (typeof
|
|
325
|
-
console.warn("Invalid
|
|
326
|
-
|
|
371
|
+
if (typeof noStart !== "boolean") {
|
|
372
|
+
console.warn("Invalid noStart option. Fallback: false.");
|
|
373
|
+
noStart = false;
|
|
327
374
|
}
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
|
|
375
|
+
if (selector !== "") {
|
|
376
|
+
try {
|
|
377
|
+
document.querySelector(selector);
|
|
378
|
+
} catch {
|
|
379
|
+
console.warn("Invalid selector. Fallback: no selector string.");
|
|
380
|
+
selector = "";
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (typeof typeahead !== "boolean") {
|
|
384
|
+
console.warn("Invalid typeahead option. Fallback: false.");
|
|
385
|
+
typeahead = false;
|
|
331
386
|
}
|
|
332
387
|
if (typeof wrap !== "boolean") {
|
|
333
388
|
console.warn("Invalid wrap option. Fallback: false.");
|
|
334
389
|
wrap = false;
|
|
335
390
|
}
|
|
336
391
|
return {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
392
|
+
direction,
|
|
393
|
+
navigationOnly,
|
|
394
|
+
noMemory,
|
|
395
|
+
noStart,
|
|
396
|
+
selector,
|
|
397
|
+
typeahead,
|
|
343
398
|
wrap
|
|
344
399
|
};
|
|
345
400
|
}
|
|
346
|
-
|
|
347
|
-
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
348
|
-
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
349
401
|
function createRovingTabIndex(container, options = {}) {
|
|
350
402
|
if (!(container instanceof Element)) {
|
|
351
403
|
console.warn("Invalid container element");
|
|
@@ -366,7 +418,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
366
418
|
#isDestroyed = false;
|
|
367
419
|
constructor(container, options = {}) {
|
|
368
420
|
this.#container = container;
|
|
369
|
-
this.#settings =
|
|
421
|
+
this.#settings = resolveOptions3(options);
|
|
370
422
|
this.#selectorFilter = this.#createSelectorFilter();
|
|
371
423
|
this.#initialize();
|
|
372
424
|
}
|
|
@@ -614,74 +666,54 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
614
666
|
}
|
|
615
667
|
return result;
|
|
616
668
|
}
|
|
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
|
-
};
|
|
671
|
-
}
|
|
672
669
|
};
|
|
673
670
|
|
|
671
|
+
// src/defaults.ts
|
|
672
|
+
var defaults = {
|
|
673
|
+
animation: {
|
|
674
|
+
duration: 300,
|
|
675
|
+
easing: "ease"
|
|
676
|
+
},
|
|
677
|
+
collapsible: true
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
// src/options.ts
|
|
681
|
+
function resolveOptions4(defaults2, source) {
|
|
682
|
+
const merged = {
|
|
683
|
+
...defaults2,
|
|
684
|
+
...source,
|
|
685
|
+
animation: { ...defaults2.animation, ...source.animation ?? {} }
|
|
686
|
+
};
|
|
687
|
+
const mergedAnimation = merged.animation;
|
|
688
|
+
const duration = mergedAnimation.duration;
|
|
689
|
+
const defaultAnimation = defaults2.animation;
|
|
690
|
+
if (typeof duration !== "number" || Number.isNaN(duration)) {
|
|
691
|
+
const duration2 = defaultAnimation.duration;
|
|
692
|
+
console.warn(`Invalid animation duration. Fallback: ${duration2} (ms).`);
|
|
693
|
+
mergedAnimation.duration = duration2;
|
|
694
|
+
}
|
|
695
|
+
if (duration < 0) {
|
|
696
|
+
console.warn("Invalid animation duration. Fallback: 0 (ms).");
|
|
697
|
+
mergedAnimation.duration = 0;
|
|
698
|
+
}
|
|
699
|
+
if (!CSS.supports("animation-timing-function", mergedAnimation.easing)) {
|
|
700
|
+
const easing = defaultAnimation.easing;
|
|
701
|
+
console.warn(`Invalid animation easing. Fallback: '${easing}'.`);
|
|
702
|
+
mergedAnimation.easing = easing;
|
|
703
|
+
}
|
|
704
|
+
if (typeof merged.collapsible !== "boolean") {
|
|
705
|
+
const collapsible = defaults2.collapsible;
|
|
706
|
+
console.warn(`Invalid collapsible option. Fallback: ${collapsible}.`);
|
|
707
|
+
merged.collapsible = collapsible;
|
|
708
|
+
}
|
|
709
|
+
return merged;
|
|
710
|
+
}
|
|
711
|
+
|
|
674
712
|
// src/index.ts
|
|
675
713
|
var Disclosure = class _Disclosure {
|
|
676
714
|
static defaults = {};
|
|
677
715
|
#rootElement;
|
|
678
|
-
#defaults =
|
|
679
|
-
animation: {
|
|
680
|
-
duration: 300,
|
|
681
|
-
easing: "ease"
|
|
682
|
-
},
|
|
683
|
-
collapsible: true
|
|
684
|
-
};
|
|
716
|
+
#defaults = defaults;
|
|
685
717
|
#settings;
|
|
686
718
|
#detailsElements;
|
|
687
719
|
#summaryElements;
|
|
@@ -701,8 +733,8 @@ var Disclosure = class _Disclosure {
|
|
|
701
733
|
return;
|
|
702
734
|
}
|
|
703
735
|
this.#rootElement = root;
|
|
704
|
-
this.#defaults =
|
|
705
|
-
this.#settings =
|
|
736
|
+
this.#defaults = resolveOptions4(this.#defaults, _Disclosure.defaults);
|
|
737
|
+
this.#settings = resolveOptions4(this.#defaults, options);
|
|
706
738
|
matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
|
|
707
739
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
708
740
|
this.#detailsElements = [
|
|
@@ -925,37 +957,6 @@ var Disclosure = class _Disclosure {
|
|
|
925
957
|
#isFocusable(element) {
|
|
926
958
|
return element.tabIndex >= 0;
|
|
927
959
|
}
|
|
928
|
-
#resolveOptions(target, source) {
|
|
929
|
-
const merged = {
|
|
930
|
-
...target,
|
|
931
|
-
...source,
|
|
932
|
-
animation: { ...target.animation, ...source.animation ?? {} }
|
|
933
|
-
};
|
|
934
|
-
const mergedAnimation = merged.animation;
|
|
935
|
-
const duration = mergedAnimation.duration;
|
|
936
|
-
const defaults = this.#defaults;
|
|
937
|
-
const defaultAnimation = defaults.animation;
|
|
938
|
-
if (typeof duration !== "number" || Number.isNaN(duration)) {
|
|
939
|
-
const duration2 = defaultAnimation.duration;
|
|
940
|
-
console.warn(`Invalid animation duration. Fallback: ${duration2} (ms).`);
|
|
941
|
-
mergedAnimation.duration = duration2;
|
|
942
|
-
}
|
|
943
|
-
if (duration < 0) {
|
|
944
|
-
console.warn("Invalid animation duration. Fallback: 0 (ms).");
|
|
945
|
-
mergedAnimation.duration = 0;
|
|
946
|
-
}
|
|
947
|
-
if (!CSS.supports("animation-timing-function", mergedAnimation.easing)) {
|
|
948
|
-
const easing = defaultAnimation.easing;
|
|
949
|
-
console.warn(`Invalid animation easing. Fallback: '${easing}'.`);
|
|
950
|
-
mergedAnimation.easing = easing;
|
|
951
|
-
}
|
|
952
|
-
if (typeof merged.collapsible !== "boolean") {
|
|
953
|
-
const collapsible = defaults.collapsible;
|
|
954
|
-
console.warn(`Invalid collapsible option. Fallback: ${collapsible}.`);
|
|
955
|
-
merged.collapsible = collapsible;
|
|
956
|
-
}
|
|
957
|
-
return merged;
|
|
958
|
-
}
|
|
959
960
|
async #waitAnimationsFinish() {
|
|
960
961
|
const promises = [];
|
|
961
962
|
for (const content of this.#contentElements) {
|
package/dist/index.cjs
CHANGED
|
@@ -3,17 +3,54 @@
|
|
|
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 = {
|
|
10
|
+
animation: {
|
|
11
|
+
duration: 300,
|
|
12
|
+
easing: "ease"
|
|
13
|
+
},
|
|
14
|
+
collapsible: true
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/options.ts
|
|
18
|
+
function resolveOptions(defaults2, source) {
|
|
19
|
+
const merged = {
|
|
20
|
+
...defaults2,
|
|
21
|
+
...source,
|
|
22
|
+
animation: { ...defaults2.animation, ...source.animation ?? {} }
|
|
23
|
+
};
|
|
24
|
+
const mergedAnimation = merged.animation;
|
|
25
|
+
const duration = mergedAnimation.duration;
|
|
26
|
+
const defaultAnimation = defaults2.animation;
|
|
27
|
+
if (typeof duration !== "number" || Number.isNaN(duration)) {
|
|
28
|
+
const duration2 = defaultAnimation.duration;
|
|
29
|
+
console.warn(`Invalid animation duration. Fallback: ${duration2} (ms).`);
|
|
30
|
+
mergedAnimation.duration = duration2;
|
|
31
|
+
}
|
|
32
|
+
if (duration < 0) {
|
|
33
|
+
console.warn("Invalid animation duration. Fallback: 0 (ms).");
|
|
34
|
+
mergedAnimation.duration = 0;
|
|
35
|
+
}
|
|
36
|
+
if (!CSS.supports("animation-timing-function", mergedAnimation.easing)) {
|
|
37
|
+
const easing = defaultAnimation.easing;
|
|
38
|
+
console.warn(`Invalid animation easing. Fallback: '${easing}'.`);
|
|
39
|
+
mergedAnimation.easing = easing;
|
|
40
|
+
}
|
|
41
|
+
if (typeof merged.collapsible !== "boolean") {
|
|
42
|
+
const collapsible = defaults2.collapsible;
|
|
43
|
+
console.warn(`Invalid collapsible option. Fallback: ${collapsible}.`);
|
|
44
|
+
merged.collapsible = collapsible;
|
|
45
|
+
}
|
|
46
|
+
return merged;
|
|
47
|
+
}
|
|
48
|
+
|
|
6
49
|
// src/index.ts
|
|
7
50
|
var Disclosure = class _Disclosure {
|
|
8
51
|
static defaults = {};
|
|
9
52
|
#rootElement;
|
|
10
|
-
#defaults =
|
|
11
|
-
animation: {
|
|
12
|
-
duration: 300,
|
|
13
|
-
easing: "ease"
|
|
14
|
-
},
|
|
15
|
-
collapsible: true
|
|
16
|
-
};
|
|
53
|
+
#defaults = defaults;
|
|
17
54
|
#settings;
|
|
18
55
|
#detailsElements;
|
|
19
56
|
#summaryElements;
|
|
@@ -33,8 +70,8 @@ var Disclosure = class _Disclosure {
|
|
|
33
70
|
return;
|
|
34
71
|
}
|
|
35
72
|
this.#rootElement = root;
|
|
36
|
-
this.#defaults =
|
|
37
|
-
this.#settings =
|
|
73
|
+
this.#defaults = resolveOptions(this.#defaults, _Disclosure.defaults);
|
|
74
|
+
this.#settings = resolveOptions(this.#defaults, options);
|
|
38
75
|
matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
|
|
39
76
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
40
77
|
this.#detailsElements = [
|
|
@@ -257,37 +294,6 @@ var Disclosure = class _Disclosure {
|
|
|
257
294
|
#isFocusable(element) {
|
|
258
295
|
return element.tabIndex >= 0;
|
|
259
296
|
}
|
|
260
|
-
#resolveOptions(target, source) {
|
|
261
|
-
const merged = {
|
|
262
|
-
...target,
|
|
263
|
-
...source,
|
|
264
|
-
animation: { ...target.animation, ...source.animation ?? {} }
|
|
265
|
-
};
|
|
266
|
-
const mergedAnimation = merged.animation;
|
|
267
|
-
const duration = mergedAnimation.duration;
|
|
268
|
-
const defaults = this.#defaults;
|
|
269
|
-
const defaultAnimation = defaults.animation;
|
|
270
|
-
if (typeof duration !== "number" || Number.isNaN(duration)) {
|
|
271
|
-
const duration2 = defaultAnimation.duration;
|
|
272
|
-
console.warn(`Invalid animation duration. Fallback: ${duration2} (ms).`);
|
|
273
|
-
mergedAnimation.duration = duration2;
|
|
274
|
-
}
|
|
275
|
-
if (duration < 0) {
|
|
276
|
-
console.warn("Invalid animation duration. Fallback: 0 (ms).");
|
|
277
|
-
mergedAnimation.duration = 0;
|
|
278
|
-
}
|
|
279
|
-
if (!CSS.supports("animation-timing-function", mergedAnimation.easing)) {
|
|
280
|
-
const easing = defaultAnimation.easing;
|
|
281
|
-
console.warn(`Invalid animation easing. Fallback: '${easing}'.`);
|
|
282
|
-
mergedAnimation.easing = easing;
|
|
283
|
-
}
|
|
284
|
-
if (typeof merged.collapsible !== "boolean") {
|
|
285
|
-
const collapsible = defaults.collapsible;
|
|
286
|
-
console.warn(`Invalid collapsible option. Fallback: ${collapsible}.`);
|
|
287
|
-
merged.collapsible = collapsible;
|
|
288
|
-
}
|
|
289
|
-
return merged;
|
|
290
|
-
}
|
|
291
297
|
async #waitAnimationsFinish() {
|
|
292
298
|
const promises = [];
|
|
293
299
|
for (const content of this.#contentElements) {
|
package/dist/index.d.cts
CHANGED