@y14e/accordion 1.2.7 → 1.2.9
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 +35 -18
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +35 -18
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,29 +1,41 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// node_modules/@y14e/attributes-utils/dist/index.js
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
var defaultParser = (value) => value.split(/\s+/);
|
|
5
|
+
var defaultSerializer = (tokens) => tokens.join(" ");
|
|
6
|
+
function addTokenToAttribute(element, attribute, token, options = {}) {
|
|
7
|
+
const {
|
|
8
|
+
caseInsensitive = false,
|
|
9
|
+
parse = defaultParser,
|
|
10
|
+
serialize = defaultSerializer
|
|
11
|
+
} = options;
|
|
12
|
+
const value = element.getAttribute(attribute)?.trim();
|
|
13
|
+
const tokens = value ? parse(value).filter(Boolean) : [];
|
|
14
|
+
if (caseInsensitive) {
|
|
15
|
+
const lower = token.toLowerCase();
|
|
16
|
+
if (tokens.some((token2) => token2.toLowerCase() === lower)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
tokens.push(token);
|
|
20
|
+
element.setAttribute(attribute, serialize(tokens));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const set = new Set(tokens);
|
|
24
|
+
set.add(token);
|
|
25
|
+
element.setAttribute(attribute, serialize([...set]));
|
|
10
26
|
}
|
|
11
27
|
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
12
28
|
function restoreAttributes(elements) {
|
|
13
|
-
|
|
29
|
+
for (const element of elements) {
|
|
14
30
|
const snapshot = snapshots.get(element);
|
|
15
31
|
if (!snapshot) {
|
|
16
|
-
|
|
32
|
+
continue;
|
|
17
33
|
}
|
|
18
34
|
for (const [attribute, value] of snapshot.entries()) {
|
|
19
|
-
|
|
20
|
-
element.removeAttribute(attribute);
|
|
21
|
-
} else {
|
|
22
|
-
element.setAttribute(attribute, value);
|
|
23
|
-
}
|
|
35
|
+
value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
|
|
24
36
|
}
|
|
25
37
|
snapshots.delete(element);
|
|
26
|
-
}
|
|
38
|
+
}
|
|
27
39
|
}
|
|
28
40
|
function saveAttributes(elements, attributes) {
|
|
29
41
|
elements.forEach((element) => {
|
|
@@ -141,7 +153,12 @@ var Accordion = class _Accordion {
|
|
|
141
153
|
#initialize() {
|
|
142
154
|
this.#eventController = new AbortController();
|
|
143
155
|
const { signal } = this.#eventController;
|
|
144
|
-
saveAttributes(this.#triggerElements, [
|
|
156
|
+
saveAttributes(this.#triggerElements, [
|
|
157
|
+
"aria-controls",
|
|
158
|
+
"aria-label",
|
|
159
|
+
"id",
|
|
160
|
+
"tabindex"
|
|
161
|
+
]);
|
|
145
162
|
this.#triggerElements.forEach((trigger, i) => {
|
|
146
163
|
const id = Math.random().toString(36).slice(-8);
|
|
147
164
|
const content = this.#contentElements[i];
|
|
@@ -224,7 +241,7 @@ var Accordion = class _Accordion {
|
|
|
224
241
|
if (!binding) {
|
|
225
242
|
return;
|
|
226
243
|
}
|
|
227
|
-
binding.trigger.ariaExpanded
|
|
244
|
+
binding.trigger.ariaExpanded === "false" && this.#toggle(binding.trigger, true, true);
|
|
228
245
|
};
|
|
229
246
|
#toggle(trigger, isOpen, isMatch = false) {
|
|
230
247
|
if (trigger.ariaExpanded === String(isOpen)) {
|
|
@@ -334,7 +351,7 @@ function waitAnimationFinish(animation) {
|
|
|
334
351
|
* Accordion
|
|
335
352
|
* WAI-ARIA compliant accordion pattern implementation in TypeScript.
|
|
336
353
|
*
|
|
337
|
-
* @version 1.2.
|
|
354
|
+
* @version 1.2.9
|
|
338
355
|
* @author Yusuke Kamiyamane
|
|
339
356
|
* @license MIT
|
|
340
357
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -346,7 +363,7 @@ function waitAnimationFinish(animation) {
|
|
|
346
363
|
(**
|
|
347
364
|
* Attributes Utils
|
|
348
365
|
*
|
|
349
|
-
* @version 1.0.
|
|
366
|
+
* @version 1.0.5
|
|
350
367
|
* @author Yusuke Kamiyamane
|
|
351
368
|
* @license MIT
|
|
352
369
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,27 +1,39 @@
|
|
|
1
1
|
// node_modules/@y14e/attributes-utils/dist/index.js
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
var defaultParser = (value) => value.split(/\s+/);
|
|
3
|
+
var defaultSerializer = (tokens) => tokens.join(" ");
|
|
4
|
+
function addTokenToAttribute(element, attribute, token, options = {}) {
|
|
5
|
+
const {
|
|
6
|
+
caseInsensitive = false,
|
|
7
|
+
parse = defaultParser,
|
|
8
|
+
serialize = defaultSerializer
|
|
9
|
+
} = options;
|
|
10
|
+
const value = element.getAttribute(attribute)?.trim();
|
|
11
|
+
const tokens = value ? parse(value).filter(Boolean) : [];
|
|
12
|
+
if (caseInsensitive) {
|
|
13
|
+
const lower = token.toLowerCase();
|
|
14
|
+
if (tokens.some((token2) => token2.toLowerCase() === lower)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
tokens.push(token);
|
|
18
|
+
element.setAttribute(attribute, serialize(tokens));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const set = new Set(tokens);
|
|
22
|
+
set.add(token);
|
|
23
|
+
element.setAttribute(attribute, serialize([...set]));
|
|
8
24
|
}
|
|
9
25
|
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
10
26
|
function restoreAttributes(elements) {
|
|
11
|
-
|
|
27
|
+
for (const element of elements) {
|
|
12
28
|
const snapshot = snapshots.get(element);
|
|
13
29
|
if (!snapshot) {
|
|
14
|
-
|
|
30
|
+
continue;
|
|
15
31
|
}
|
|
16
32
|
for (const [attribute, value] of snapshot.entries()) {
|
|
17
|
-
|
|
18
|
-
element.removeAttribute(attribute);
|
|
19
|
-
} else {
|
|
20
|
-
element.setAttribute(attribute, value);
|
|
21
|
-
}
|
|
33
|
+
value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
|
|
22
34
|
}
|
|
23
35
|
snapshots.delete(element);
|
|
24
|
-
}
|
|
36
|
+
}
|
|
25
37
|
}
|
|
26
38
|
function saveAttributes(elements, attributes) {
|
|
27
39
|
elements.forEach((element) => {
|
|
@@ -139,7 +151,12 @@ var Accordion = class _Accordion {
|
|
|
139
151
|
#initialize() {
|
|
140
152
|
this.#eventController = new AbortController();
|
|
141
153
|
const { signal } = this.#eventController;
|
|
142
|
-
saveAttributes(this.#triggerElements, [
|
|
154
|
+
saveAttributes(this.#triggerElements, [
|
|
155
|
+
"aria-controls",
|
|
156
|
+
"aria-label",
|
|
157
|
+
"id",
|
|
158
|
+
"tabindex"
|
|
159
|
+
]);
|
|
143
160
|
this.#triggerElements.forEach((trigger, i) => {
|
|
144
161
|
const id = Math.random().toString(36).slice(-8);
|
|
145
162
|
const content = this.#contentElements[i];
|
|
@@ -222,7 +239,7 @@ var Accordion = class _Accordion {
|
|
|
222
239
|
if (!binding) {
|
|
223
240
|
return;
|
|
224
241
|
}
|
|
225
|
-
binding.trigger.ariaExpanded
|
|
242
|
+
binding.trigger.ariaExpanded === "false" && this.#toggle(binding.trigger, true, true);
|
|
226
243
|
};
|
|
227
244
|
#toggle(trigger, isOpen, isMatch = false) {
|
|
228
245
|
if (trigger.ariaExpanded === String(isOpen)) {
|
|
@@ -332,7 +349,7 @@ function waitAnimationFinish(animation) {
|
|
|
332
349
|
* Accordion
|
|
333
350
|
* WAI-ARIA compliant accordion pattern implementation in TypeScript.
|
|
334
351
|
*
|
|
335
|
-
* @version 1.2.
|
|
352
|
+
* @version 1.2.9
|
|
336
353
|
* @author Yusuke Kamiyamane
|
|
337
354
|
* @license MIT
|
|
338
355
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -344,7 +361,7 @@ function waitAnimationFinish(animation) {
|
|
|
344
361
|
(**
|
|
345
362
|
* Attributes Utils
|
|
346
363
|
*
|
|
347
|
-
* @version 1.0.
|
|
364
|
+
* @version 1.0.5
|
|
348
365
|
* @author Yusuke Kamiyamane
|
|
349
366
|
* @license MIT
|
|
350
367
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/accordion",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
4
4
|
"description": "WAI-ARIA compliant accordion pattern implementation in TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"homepage": "https://github.com/y14e/accordion#readme",
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@y14e/attributes-utils": "^1.0.
|
|
46
|
+
"@y14e/attributes-utils": "^1.0.5",
|
|
47
47
|
"bun-types": "latest",
|
|
48
48
|
"tsup": "^8.0.0",
|
|
49
49
|
"typescript": "^5.6.0",
|