@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.js CHANGED
@@ -1,17 +1,54 @@
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
- };
51
+ #defaults = defaults;
15
52
  #settings;
16
53
  #detailsElements;
17
54
  #summaryElements;
@@ -31,8 +68,8 @@ var Disclosure = class _Disclosure {
31
68
  return;
32
69
  }
33
70
  this.#rootElement = root;
34
- this.#defaults = this.#resolveOptions(this.#defaults, _Disclosure.defaults);
35
- this.#settings = this.#resolveOptions(this.#defaults, options);
71
+ this.#defaults = resolveOptions(this.#defaults, _Disclosure.defaults);
72
+ this.#settings = resolveOptions(this.#defaults, options);
36
73
  matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
37
74
  const NOT_NESTED = ":not(:scope summary + * *)";
38
75
  this.#detailsElements = [
@@ -255,37 +292,6 @@ var Disclosure = class _Disclosure {
255
292
  #isFocusable(element) {
256
293
  return element.tabIndex >= 0;
257
294
  }
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
295
  async #waitAnimationsFinish() {
290
296
  const promises = [];
291
297
  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.4",
3
+ "version": "2.2.0",
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.0"
59
59
  }
60
60
  }