@y14e/accordion 1.2.6 → 1.2.8

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
@@ -1,5 +1,43 @@
1
1
  'use strict';
2
2
 
3
+ // node_modules/@y14e/attributes-utils/dist/index.js
4
+ function addTokenToAttribute(element, attribute, token) {
5
+ const tokens = new Set(
6
+ element.getAttribute(attribute)?.trim().split(/\s+/) ?? []
7
+ );
8
+ tokens.add(token);
9
+ element.setAttribute(attribute, [...tokens].join(" "));
10
+ }
11
+ var snapshots = /* @__PURE__ */ new WeakMap();
12
+ function restoreAttributes(elements) {
13
+ elements.forEach((element) => {
14
+ const snapshot = snapshots.get(element);
15
+ if (!snapshot) {
16
+ return;
17
+ }
18
+ for (const [attribute, value] of snapshot.entries()) {
19
+ if (value === null) {
20
+ element.removeAttribute(attribute);
21
+ } else {
22
+ element.setAttribute(attribute, value);
23
+ }
24
+ }
25
+ snapshots.delete(element);
26
+ });
27
+ }
28
+ function saveAttributes(elements, attributes) {
29
+ elements.forEach((element) => {
30
+ let snapshot = snapshots.get(element);
31
+ if (!snapshot) {
32
+ snapshot = /* @__PURE__ */ new Map();
33
+ snapshots.set(element, snapshot);
34
+ }
35
+ attributes.forEach((attribute) => {
36
+ snapshot.set(attribute, element.getAttribute(attribute));
37
+ });
38
+ });
39
+ }
40
+
3
41
  // src/index.ts
4
42
  var Accordion = class _Accordion {
5
43
  static defaults = {};
@@ -95,6 +133,7 @@ var Accordion = class _Accordion {
95
133
  });
96
134
  this.#animationController?.abort();
97
135
  this.#animationController = null;
136
+ restoreAttributes([...this.#triggerElements, ...this.#contentElements]);
98
137
  this.#triggerElements.length = 0;
99
138
  this.#contentElements.length = 0;
100
139
  this.#rootElement.removeAttribute("data-accordion-initialized");
@@ -102,12 +141,19 @@ var Accordion = class _Accordion {
102
141
  #initialize() {
103
142
  this.#eventController = new AbortController();
104
143
  const { signal } = this.#eventController;
144
+ saveAttributes(this.#triggerElements, [
145
+ "aria-controls",
146
+ "aria-label",
147
+ "id",
148
+ "tabindex"
149
+ ]);
105
150
  this.#triggerElements.forEach((trigger, i) => {
106
151
  const id = Math.random().toString(36).slice(-8);
107
152
  const content = this.#contentElements[i];
108
153
  if (!content) {
109
154
  return;
110
155
  }
156
+ saveAttributes([content], ["aria-labelledby", "id", "role"]);
111
157
  content.id ||= `accordion-content-${id}`;
112
158
  addTokenToAttribute(trigger, "aria-controls", content.id);
113
159
  trigger.setAttribute(
@@ -267,13 +313,6 @@ var Accordion = class _Accordion {
267
313
  await Promise.allSettled(promises);
268
314
  }
269
315
  };
270
- function addTokenToAttribute(element, attribute, token) {
271
- const tokens = new Set(
272
- element.getAttribute(attribute)?.trim().split(/\s+/) ?? []
273
- );
274
- tokens.add(token);
275
- element.setAttribute(attribute, [...tokens].join(" "));
276
- }
277
316
  function createBinding(trigger, content) {
278
317
  return { trigger, content, animation: null };
279
318
  }
@@ -300,11 +339,24 @@ function waitAnimationFinish(animation) {
300
339
  * Accordion
301
340
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
302
341
  *
303
- * @version 1.2.6
342
+ * @version 1.2.8
304
343
  * @author Yusuke Kamiyamane
305
344
  * @license MIT
306
345
  * @copyright Copyright (c) Yusuke Kamiyamane
307
346
  * @see {@link https://github.com/y14e/accordion}
308
347
  */
348
+ /*! Bundled license information:
349
+
350
+ @y14e/attributes-utils/dist/index.js:
351
+ (**
352
+ * Attributes Utils
353
+ *
354
+ * @version 1.0.0
355
+ * @author Yusuke Kamiyamane
356
+ * @license MIT
357
+ * @copyright Copyright (c) Yusuke Kamiyamane
358
+ * @see {@link https://github.com/y14e/attributes-utils}
359
+ *)
360
+ */
309
361
 
310
362
  module.exports = Accordion;
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Accordion
3
3
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
4
4
  *
5
- * @version 1.2.6
5
+ * @version 1.2.8
6
6
  * @author Yusuke Kamiyamane
7
7
  * @license MIT
8
8
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Accordion
3
3
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
4
4
  *
5
- * @version 1.2.6
5
+ * @version 1.2.8
6
6
  * @author Yusuke Kamiyamane
7
7
  * @license MIT
8
8
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -1,3 +1,41 @@
1
+ // node_modules/@y14e/attributes-utils/dist/index.js
2
+ function addTokenToAttribute(element, attribute, token) {
3
+ const tokens = new Set(
4
+ element.getAttribute(attribute)?.trim().split(/\s+/) ?? []
5
+ );
6
+ tokens.add(token);
7
+ element.setAttribute(attribute, [...tokens].join(" "));
8
+ }
9
+ var snapshots = /* @__PURE__ */ new WeakMap();
10
+ function restoreAttributes(elements) {
11
+ elements.forEach((element) => {
12
+ const snapshot = snapshots.get(element);
13
+ if (!snapshot) {
14
+ return;
15
+ }
16
+ for (const [attribute, value] of snapshot.entries()) {
17
+ if (value === null) {
18
+ element.removeAttribute(attribute);
19
+ } else {
20
+ element.setAttribute(attribute, value);
21
+ }
22
+ }
23
+ snapshots.delete(element);
24
+ });
25
+ }
26
+ function saveAttributes(elements, attributes) {
27
+ elements.forEach((element) => {
28
+ let snapshot = snapshots.get(element);
29
+ if (!snapshot) {
30
+ snapshot = /* @__PURE__ */ new Map();
31
+ snapshots.set(element, snapshot);
32
+ }
33
+ attributes.forEach((attribute) => {
34
+ snapshot.set(attribute, element.getAttribute(attribute));
35
+ });
36
+ });
37
+ }
38
+
1
39
  // src/index.ts
2
40
  var Accordion = class _Accordion {
3
41
  static defaults = {};
@@ -93,6 +131,7 @@ var Accordion = class _Accordion {
93
131
  });
94
132
  this.#animationController?.abort();
95
133
  this.#animationController = null;
134
+ restoreAttributes([...this.#triggerElements, ...this.#contentElements]);
96
135
  this.#triggerElements.length = 0;
97
136
  this.#contentElements.length = 0;
98
137
  this.#rootElement.removeAttribute("data-accordion-initialized");
@@ -100,12 +139,19 @@ var Accordion = class _Accordion {
100
139
  #initialize() {
101
140
  this.#eventController = new AbortController();
102
141
  const { signal } = this.#eventController;
142
+ saveAttributes(this.#triggerElements, [
143
+ "aria-controls",
144
+ "aria-label",
145
+ "id",
146
+ "tabindex"
147
+ ]);
103
148
  this.#triggerElements.forEach((trigger, i) => {
104
149
  const id = Math.random().toString(36).slice(-8);
105
150
  const content = this.#contentElements[i];
106
151
  if (!content) {
107
152
  return;
108
153
  }
154
+ saveAttributes([content], ["aria-labelledby", "id", "role"]);
109
155
  content.id ||= `accordion-content-${id}`;
110
156
  addTokenToAttribute(trigger, "aria-controls", content.id);
111
157
  trigger.setAttribute(
@@ -265,13 +311,6 @@ var Accordion = class _Accordion {
265
311
  await Promise.allSettled(promises);
266
312
  }
267
313
  };
268
- function addTokenToAttribute(element, attribute, token) {
269
- const tokens = new Set(
270
- element.getAttribute(attribute)?.trim().split(/\s+/) ?? []
271
- );
272
- tokens.add(token);
273
- element.setAttribute(attribute, [...tokens].join(" "));
274
- }
275
314
  function createBinding(trigger, content) {
276
315
  return { trigger, content, animation: null };
277
316
  }
@@ -298,11 +337,24 @@ function waitAnimationFinish(animation) {
298
337
  * Accordion
299
338
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
300
339
  *
301
- * @version 1.2.6
340
+ * @version 1.2.8
302
341
  * @author Yusuke Kamiyamane
303
342
  * @license MIT
304
343
  * @copyright Copyright (c) Yusuke Kamiyamane
305
344
  * @see {@link https://github.com/y14e/accordion}
306
345
  */
346
+ /*! Bundled license information:
347
+
348
+ @y14e/attributes-utils/dist/index.js:
349
+ (**
350
+ * Attributes Utils
351
+ *
352
+ * @version 1.0.0
353
+ * @author Yusuke Kamiyamane
354
+ * @license MIT
355
+ * @copyright Copyright (c) Yusuke Kamiyamane
356
+ * @see {@link https://github.com/y14e/attributes-utils}
357
+ *)
358
+ */
307
359
 
308
360
  export { Accordion as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/accordion",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "WAI-ARIA compliant accordion pattern implementation in TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -43,6 +43,7 @@
43
43
  },
44
44
  "homepage": "https://github.com/y14e/accordion#readme",
45
45
  "devDependencies": {
46
+ "@y14e/attributes-utils": "^1.0.0",
46
47
  "bun-types": "latest",
47
48
  "tsup": "^8.0.0",
48
49
  "typescript": "^5.6.0",