@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.cjs
CHANGED
|
@@ -3,17 +3,53 @@
|
|
|
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
|
-
};
|
|
17
53
|
#settings;
|
|
18
54
|
#detailsElements;
|
|
19
55
|
#summaryElements;
|
|
@@ -33,8 +69,10 @@ var Disclosure = class _Disclosure {
|
|
|
33
69
|
return;
|
|
34
70
|
}
|
|
35
71
|
this.#rootElement = root;
|
|
36
|
-
this.#
|
|
37
|
-
|
|
72
|
+
this.#settings = resolveOptions(
|
|
73
|
+
resolveOptions(defaults, _Disclosure.defaults),
|
|
74
|
+
options
|
|
75
|
+
);
|
|
38
76
|
matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
|
|
39
77
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
40
78
|
this.#detailsElements = [
|
|
@@ -257,37 +295,6 @@ var Disclosure = class _Disclosure {
|
|
|
257
295
|
#isFocusable(element) {
|
|
258
296
|
return element.tabIndex >= 0;
|
|
259
297
|
}
|
|
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
298
|
async #waitAnimationsFinish() {
|
|
292
299
|
const promises = [];
|
|
293
300
|
for (const content of this.#contentElements) {
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,17 +1,53 @@
|
|
|
1
1
|
import { restoreAttributes, saveAttributes } from '@y14e/attribute-utils';
|
|
2
2
|
import { createRovingTabIndex } from '@y14e/roving-tabindex';
|
|
3
3
|
|
|
4
|
+
// src/index.ts
|
|
5
|
+
|
|
6
|
+
// src/defaults.ts
|
|
7
|
+
var defaults = {
|
|
8
|
+
animation: {
|
|
9
|
+
duration: 300,
|
|
10
|
+
easing: "ease"
|
|
11
|
+
},
|
|
12
|
+
collapsible: true
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// src/options.ts
|
|
16
|
+
function resolveOptions(defaults2, source) {
|
|
17
|
+
const merged = {
|
|
18
|
+
...defaults2,
|
|
19
|
+
...source,
|
|
20
|
+
animation: { ...defaults2.animation, ...source.animation ?? {} }
|
|
21
|
+
};
|
|
22
|
+
const mergedAnimation = merged.animation;
|
|
23
|
+
const duration = mergedAnimation.duration;
|
|
24
|
+
const defaultAnimation = defaults2.animation;
|
|
25
|
+
if (typeof duration !== "number" || Number.isNaN(duration)) {
|
|
26
|
+
const duration2 = defaultAnimation.duration;
|
|
27
|
+
console.warn(`Invalid animation duration. Fallback: ${duration2} (ms).`);
|
|
28
|
+
mergedAnimation.duration = duration2;
|
|
29
|
+
}
|
|
30
|
+
if (duration < 0) {
|
|
31
|
+
console.warn("Invalid animation duration. Fallback: 0 (ms).");
|
|
32
|
+
mergedAnimation.duration = 0;
|
|
33
|
+
}
|
|
34
|
+
if (!CSS.supports("animation-timing-function", mergedAnimation.easing)) {
|
|
35
|
+
const easing = defaultAnimation.easing;
|
|
36
|
+
console.warn(`Invalid animation easing. Fallback: '${easing}'.`);
|
|
37
|
+
mergedAnimation.easing = easing;
|
|
38
|
+
}
|
|
39
|
+
if (typeof merged.collapsible !== "boolean") {
|
|
40
|
+
const collapsible = defaults2.collapsible;
|
|
41
|
+
console.warn(`Invalid collapsible option. Fallback: ${collapsible}.`);
|
|
42
|
+
merged.collapsible = collapsible;
|
|
43
|
+
}
|
|
44
|
+
return merged;
|
|
45
|
+
}
|
|
46
|
+
|
|
4
47
|
// src/index.ts
|
|
5
48
|
var Disclosure = class _Disclosure {
|
|
6
49
|
static defaults = {};
|
|
7
50
|
#rootElement;
|
|
8
|
-
#defaults = {
|
|
9
|
-
animation: {
|
|
10
|
-
duration: 300,
|
|
11
|
-
easing: "ease"
|
|
12
|
-
},
|
|
13
|
-
collapsible: true
|
|
14
|
-
};
|
|
15
51
|
#settings;
|
|
16
52
|
#detailsElements;
|
|
17
53
|
#summaryElements;
|
|
@@ -31,8 +67,10 @@ var Disclosure = class _Disclosure {
|
|
|
31
67
|
return;
|
|
32
68
|
}
|
|
33
69
|
this.#rootElement = root;
|
|
34
|
-
this.#
|
|
35
|
-
|
|
70
|
+
this.#settings = resolveOptions(
|
|
71
|
+
resolveOptions(defaults, _Disclosure.defaults),
|
|
72
|
+
options
|
|
73
|
+
);
|
|
36
74
|
matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
|
|
37
75
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
38
76
|
this.#detailsElements = [
|
|
@@ -255,37 +293,6 @@ var Disclosure = class _Disclosure {
|
|
|
255
293
|
#isFocusable(element) {
|
|
256
294
|
return element.tabIndex >= 0;
|
|
257
295
|
}
|
|
258
|
-
#resolveOptions(target, source) {
|
|
259
|
-
const merged = {
|
|
260
|
-
...target,
|
|
261
|
-
...source,
|
|
262
|
-
animation: { ...target.animation, ...source.animation ?? {} }
|
|
263
|
-
};
|
|
264
|
-
const mergedAnimation = merged.animation;
|
|
265
|
-
const duration = mergedAnimation.duration;
|
|
266
|
-
const defaults = this.#defaults;
|
|
267
|
-
const defaultAnimation = defaults.animation;
|
|
268
|
-
if (typeof duration !== "number" || Number.isNaN(duration)) {
|
|
269
|
-
const duration2 = defaultAnimation.duration;
|
|
270
|
-
console.warn(`Invalid animation duration. Fallback: ${duration2} (ms).`);
|
|
271
|
-
mergedAnimation.duration = duration2;
|
|
272
|
-
}
|
|
273
|
-
if (duration < 0) {
|
|
274
|
-
console.warn("Invalid animation duration. Fallback: 0 (ms).");
|
|
275
|
-
mergedAnimation.duration = 0;
|
|
276
|
-
}
|
|
277
|
-
if (!CSS.supports("animation-timing-function", mergedAnimation.easing)) {
|
|
278
|
-
const easing = defaultAnimation.easing;
|
|
279
|
-
console.warn(`Invalid animation easing. Fallback: '${easing}'.`);
|
|
280
|
-
mergedAnimation.easing = easing;
|
|
281
|
-
}
|
|
282
|
-
if (typeof merged.collapsible !== "boolean") {
|
|
283
|
-
const collapsible = defaults.collapsible;
|
|
284
|
-
console.warn(`Invalid collapsible option. Fallback: ${collapsible}.`);
|
|
285
|
-
merged.collapsible = collapsible;
|
|
286
|
-
}
|
|
287
|
-
return merged;
|
|
288
|
-
}
|
|
289
296
|
async #waitAnimationsFinish() {
|
|
290
297
|
const promises = [];
|
|
291
298
|
for (const content of this.#contentElements) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/disclosure",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "WAI-ARIA compliant disclosure pattern implementation in TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"a11y",
|
|
@@ -42,10 +42,6 @@
|
|
|
42
42
|
"lint": "tsc --noEmit",
|
|
43
43
|
"prepublishOnly": "npm run build"
|
|
44
44
|
},
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"@y14e/attribute-utils": "^2.0.15",
|
|
47
|
-
"@y14e/roving-tabindex": "^3.3.8"
|
|
48
|
-
},
|
|
49
45
|
"devDependencies": {
|
|
50
46
|
"bun-types": "latest",
|
|
51
47
|
"tsup": "^8.0.0",
|
|
@@ -56,5 +52,9 @@
|
|
|
56
52
|
},
|
|
57
53
|
"allowScripts": {
|
|
58
54
|
"esbuild": true
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@y14e/attribute-utils": "^2.0.16",
|
|
58
|
+
"@y14e/roving-tabindex": "^3.4.1"
|
|
59
59
|
}
|
|
60
60
|
}
|