@y14e/accordion 1.2.6 → 1.2.7

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,14 @@ var Accordion = class _Accordion {
102
141
  #initialize() {
103
142
  this.#eventController = new AbortController();
104
143
  const { signal } = this.#eventController;
144
+ saveAttributes(this.#triggerElements, ["aria-controls", "id", "tabindex"]);
105
145
  this.#triggerElements.forEach((trigger, i) => {
106
146
  const id = Math.random().toString(36).slice(-8);
107
147
  const content = this.#contentElements[i];
108
148
  if (!content) {
109
149
  return;
110
150
  }
151
+ saveAttributes([content], ["aria-labelledby", "id", "role"]);
111
152
  content.id ||= `accordion-content-${id}`;
112
153
  addTokenToAttribute(trigger, "aria-controls", content.id);
113
154
  trigger.setAttribute(
@@ -267,13 +308,6 @@ var Accordion = class _Accordion {
267
308
  await Promise.allSettled(promises);
268
309
  }
269
310
  };
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
311
  function createBinding(trigger, content) {
278
312
  return { trigger, content, animation: null };
279
313
  }
@@ -300,11 +334,24 @@ function waitAnimationFinish(animation) {
300
334
  * Accordion
301
335
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
302
336
  *
303
- * @version 1.2.6
337
+ * @version 1.2.7
304
338
  * @author Yusuke Kamiyamane
305
339
  * @license MIT
306
340
  * @copyright Copyright (c) Yusuke Kamiyamane
307
341
  * @see {@link https://github.com/y14e/accordion}
308
342
  */
343
+ /*! Bundled license information:
344
+
345
+ @y14e/attributes-utils/dist/index.js:
346
+ (**
347
+ * Attributes Utils
348
+ *
349
+ * @version 1.0.0
350
+ * @author Yusuke Kamiyamane
351
+ * @license MIT
352
+ * @copyright Copyright (c) Yusuke Kamiyamane
353
+ * @see {@link https://github.com/y14e/attributes-utils}
354
+ *)
355
+ */
309
356
 
310
357
  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.7
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.7
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,14 @@ var Accordion = class _Accordion {
100
139
  #initialize() {
101
140
  this.#eventController = new AbortController();
102
141
  const { signal } = this.#eventController;
142
+ saveAttributes(this.#triggerElements, ["aria-controls", "id", "tabindex"]);
103
143
  this.#triggerElements.forEach((trigger, i) => {
104
144
  const id = Math.random().toString(36).slice(-8);
105
145
  const content = this.#contentElements[i];
106
146
  if (!content) {
107
147
  return;
108
148
  }
149
+ saveAttributes([content], ["aria-labelledby", "id", "role"]);
109
150
  content.id ||= `accordion-content-${id}`;
110
151
  addTokenToAttribute(trigger, "aria-controls", content.id);
111
152
  trigger.setAttribute(
@@ -265,13 +306,6 @@ var Accordion = class _Accordion {
265
306
  await Promise.allSettled(promises);
266
307
  }
267
308
  };
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
309
  function createBinding(trigger, content) {
276
310
  return { trigger, content, animation: null };
277
311
  }
@@ -298,11 +332,24 @@ function waitAnimationFinish(animation) {
298
332
  * Accordion
299
333
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
300
334
  *
301
- * @version 1.2.6
335
+ * @version 1.2.7
302
336
  * @author Yusuke Kamiyamane
303
337
  * @license MIT
304
338
  * @copyright Copyright (c) Yusuke Kamiyamane
305
339
  * @see {@link https://github.com/y14e/accordion}
306
340
  */
341
+ /*! Bundled license information:
342
+
343
+ @y14e/attributes-utils/dist/index.js:
344
+ (**
345
+ * Attributes Utils
346
+ *
347
+ * @version 1.0.0
348
+ * @author Yusuke Kamiyamane
349
+ * @license MIT
350
+ * @copyright Copyright (c) Yusuke Kamiyamane
351
+ * @see {@link https://github.com/y14e/attributes-utils}
352
+ *)
353
+ */
307
354
 
308
355
  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.7",
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",