@y14e/disclosure 2.1.3 → 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.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 = this.#resolveOptions(this.#defaults, _Disclosure.defaults);
37
- this.#settings = this.#resolveOptions(this.#defaults, options);
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
@@ -5,6 +5,7 @@ interface DisclosureOptions {
5
5
  };
6
6
  collapsible: boolean;
7
7
  }
8
+
8
9
  declare class Disclosure {
9
10
  #private;
10
11
  static defaults: Partial<DisclosureOptions>;
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ interface DisclosureOptions {
5
5
  };
6
6
  collapsible: boolean;
7
7
  }
8
+
8
9
  declare class Disclosure {
9
10
  #private;
10
11
  static defaults: Partial<DisclosureOptions>;
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.3",
3
+ "version": "2.2.0",
4
4
  "description": "WAI-ARIA compliant disclosure pattern implementation in TypeScript",
5
5
  "keywords": [
6
6
  "a11y",
@@ -54,7 +54,7 @@
54
54
  "esbuild": true
55
55
  },
56
56
  "dependencies": {
57
- "@y14e/attribute-utils": "^2.0.13",
58
- "@y14e/roving-tabindex": "^3.3.4"
57
+ "@y14e/attribute-utils": "^2.0.16",
58
+ "@y14e/roving-tabindex": "^3.4.0"
59
59
  }
60
60
  }