@y14e/disclosure-css 1.2.3 → 1.2.5
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/README.md +1 -1
- package/dist/index.cjs +45 -4
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +45 -4
- package/package.json +2 -1
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// node_modules/@y14e/attributes-utils/dist/index.js
|
|
4
|
+
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
function restoreAttributes(elements) {
|
|
6
|
+
for (const element of elements) {
|
|
7
|
+
const snapshot = snapshots.get(element);
|
|
8
|
+
if (!snapshot) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
for (const [attribute, value] of snapshot.entries()) {
|
|
12
|
+
value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
|
|
13
|
+
}
|
|
14
|
+
snapshots.delete(element);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function saveAttributes(elements, attributes) {
|
|
18
|
+
elements.forEach((element) => {
|
|
19
|
+
let snapshot = snapshots.get(element);
|
|
20
|
+
if (!snapshot) {
|
|
21
|
+
snapshot = /* @__PURE__ */ new Map();
|
|
22
|
+
snapshots.set(element, snapshot);
|
|
23
|
+
}
|
|
24
|
+
attributes.forEach((attribute) => {
|
|
25
|
+
snapshot.set(attribute, element.getAttribute(attribute));
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
3
30
|
// src/index.ts
|
|
4
31
|
var Disclosure = class {
|
|
5
32
|
#rootElement;
|
|
@@ -87,6 +114,7 @@ var Disclosure = class {
|
|
|
87
114
|
this.#controller?.abort();
|
|
88
115
|
this.#controller = null;
|
|
89
116
|
this.#detailsElements.length = 0;
|
|
117
|
+
restoreAttributes(this.#summaryElements);
|
|
90
118
|
this.#summaryElements.length = 0;
|
|
91
119
|
this.#contentElements.length = 0;
|
|
92
120
|
this.#rootElement.removeAttribute("data-disclosure-initialized");
|
|
@@ -99,6 +127,7 @@ var Disclosure = class {
|
|
|
99
127
|
return;
|
|
100
128
|
}
|
|
101
129
|
if (!isFocusable(summary)) {
|
|
130
|
+
saveAttributes([summary], ["aria-disabled", "style", "tabindex"]);
|
|
102
131
|
summary.setAttribute("aria-disabled", "true");
|
|
103
132
|
summary.setAttribute("tabindex", "-1");
|
|
104
133
|
summary.style.setProperty("pointer-events", "none");
|
|
@@ -112,13 +141,12 @@ var Disclosure = class {
|
|
|
112
141
|
if (!["End", "Home", "ArrowUp", "ArrowDown"].includes(key)) {
|
|
113
142
|
return;
|
|
114
143
|
}
|
|
115
|
-
event.preventDefault();
|
|
116
|
-
event.stopPropagation();
|
|
117
144
|
const focusables = this.#summaryElements.filter(isFocusable);
|
|
118
145
|
const active = getActiveElement();
|
|
119
146
|
if (!(active instanceof HTMLElement)) {
|
|
120
147
|
return;
|
|
121
148
|
}
|
|
149
|
+
event.preventDefault();
|
|
122
150
|
const currentIndex = focusables.indexOf(active);
|
|
123
151
|
let newIndex = currentIndex;
|
|
124
152
|
switch (key) {
|
|
@@ -157,15 +185,28 @@ function isFocusable(element) {
|
|
|
157
185
|
return element.tabIndex >= 0;
|
|
158
186
|
}
|
|
159
187
|
/**
|
|
160
|
-
* Disclosure (CSS)
|
|
188
|
+
* Disclosure (CSS Animation)
|
|
161
189
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
162
190
|
* Using the <details> and <summary> element.
|
|
163
191
|
*
|
|
164
|
-
* @version 1.2.
|
|
192
|
+
* @version 1.2.5
|
|
165
193
|
* @author Yusuke Kamiyamane
|
|
166
194
|
* @license MIT
|
|
167
195
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
168
196
|
* @see {@link https://github.com/y14e/disclosure-css}
|
|
169
197
|
*/
|
|
198
|
+
/*! Bundled license information:
|
|
199
|
+
|
|
200
|
+
@y14e/attributes-utils/dist/index.js:
|
|
201
|
+
(**
|
|
202
|
+
* Attributes Utils
|
|
203
|
+
*
|
|
204
|
+
* @version 1.0.5
|
|
205
|
+
* @author Yusuke Kamiyamane
|
|
206
|
+
* @license MIT
|
|
207
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
208
|
+
* @see {@link https://github.com/y14e/attributes-utils}
|
|
209
|
+
*)
|
|
210
|
+
*/
|
|
170
211
|
|
|
171
212
|
module.exports = Disclosure;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Disclosure (CSS)
|
|
2
|
+
* Disclosure (CSS Animation)
|
|
3
3
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
4
4
|
* Using the <details> and <summary> element.
|
|
5
5
|
*
|
|
6
|
-
* @version 1.2.
|
|
6
|
+
* @version 1.2.5
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Disclosure (CSS)
|
|
2
|
+
* Disclosure (CSS Animation)
|
|
3
3
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
4
4
|
* Using the <details> and <summary> element.
|
|
5
5
|
*
|
|
6
|
-
* @version 1.2.
|
|
6
|
+
* @version 1.2.5
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
// node_modules/@y14e/attributes-utils/dist/index.js
|
|
2
|
+
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function restoreAttributes(elements) {
|
|
4
|
+
for (const element of elements) {
|
|
5
|
+
const snapshot = snapshots.get(element);
|
|
6
|
+
if (!snapshot) {
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
for (const [attribute, value] of snapshot.entries()) {
|
|
10
|
+
value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
|
|
11
|
+
}
|
|
12
|
+
snapshots.delete(element);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function saveAttributes(elements, attributes) {
|
|
16
|
+
elements.forEach((element) => {
|
|
17
|
+
let snapshot = snapshots.get(element);
|
|
18
|
+
if (!snapshot) {
|
|
19
|
+
snapshot = /* @__PURE__ */ new Map();
|
|
20
|
+
snapshots.set(element, snapshot);
|
|
21
|
+
}
|
|
22
|
+
attributes.forEach((attribute) => {
|
|
23
|
+
snapshot.set(attribute, element.getAttribute(attribute));
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
1
28
|
// src/index.ts
|
|
2
29
|
var Disclosure = class {
|
|
3
30
|
#rootElement;
|
|
@@ -85,6 +112,7 @@ var Disclosure = class {
|
|
|
85
112
|
this.#controller?.abort();
|
|
86
113
|
this.#controller = null;
|
|
87
114
|
this.#detailsElements.length = 0;
|
|
115
|
+
restoreAttributes(this.#summaryElements);
|
|
88
116
|
this.#summaryElements.length = 0;
|
|
89
117
|
this.#contentElements.length = 0;
|
|
90
118
|
this.#rootElement.removeAttribute("data-disclosure-initialized");
|
|
@@ -97,6 +125,7 @@ var Disclosure = class {
|
|
|
97
125
|
return;
|
|
98
126
|
}
|
|
99
127
|
if (!isFocusable(summary)) {
|
|
128
|
+
saveAttributes([summary], ["aria-disabled", "style", "tabindex"]);
|
|
100
129
|
summary.setAttribute("aria-disabled", "true");
|
|
101
130
|
summary.setAttribute("tabindex", "-1");
|
|
102
131
|
summary.style.setProperty("pointer-events", "none");
|
|
@@ -110,13 +139,12 @@ var Disclosure = class {
|
|
|
110
139
|
if (!["End", "Home", "ArrowUp", "ArrowDown"].includes(key)) {
|
|
111
140
|
return;
|
|
112
141
|
}
|
|
113
|
-
event.preventDefault();
|
|
114
|
-
event.stopPropagation();
|
|
115
142
|
const focusables = this.#summaryElements.filter(isFocusable);
|
|
116
143
|
const active = getActiveElement();
|
|
117
144
|
if (!(active instanceof HTMLElement)) {
|
|
118
145
|
return;
|
|
119
146
|
}
|
|
147
|
+
event.preventDefault();
|
|
120
148
|
const currentIndex = focusables.indexOf(active);
|
|
121
149
|
let newIndex = currentIndex;
|
|
122
150
|
switch (key) {
|
|
@@ -155,15 +183,28 @@ function isFocusable(element) {
|
|
|
155
183
|
return element.tabIndex >= 0;
|
|
156
184
|
}
|
|
157
185
|
/**
|
|
158
|
-
* Disclosure (CSS)
|
|
186
|
+
* Disclosure (CSS Animation)
|
|
159
187
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
160
188
|
* Using the <details> and <summary> element.
|
|
161
189
|
*
|
|
162
|
-
* @version 1.2.
|
|
190
|
+
* @version 1.2.5
|
|
163
191
|
* @author Yusuke Kamiyamane
|
|
164
192
|
* @license MIT
|
|
165
193
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
166
194
|
* @see {@link https://github.com/y14e/disclosure-css}
|
|
167
195
|
*/
|
|
196
|
+
/*! Bundled license information:
|
|
197
|
+
|
|
198
|
+
@y14e/attributes-utils/dist/index.js:
|
|
199
|
+
(**
|
|
200
|
+
* Attributes Utils
|
|
201
|
+
*
|
|
202
|
+
* @version 1.0.5
|
|
203
|
+
* @author Yusuke Kamiyamane
|
|
204
|
+
* @license MIT
|
|
205
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
206
|
+
* @see {@link https://github.com/y14e/attributes-utils}
|
|
207
|
+
*)
|
|
208
|
+
*/
|
|
168
209
|
|
|
169
210
|
export { Disclosure as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/disclosure-css",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "WAI-ARIA compliant disclosure 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/disclosure-css#readme",
|
|
45
45
|
"devDependencies": {
|
|
46
|
+
"@y14e/attributes-utils": "^1.0.5",
|
|
46
47
|
"bun-types": "latest",
|
|
47
48
|
"tsup": "^8.0.0",
|
|
48
49
|
"typescript": "^5.6.0"
|