@y14e/disclosure-css 1.2.4 → 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/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");
@@ -160,11 +189,24 @@ function isFocusable(element) {
160
189
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
161
190
  * Using the <details> and <summary> element.
162
191
  *
163
- * @version 1.2.4
192
+ * @version 1.2.5
164
193
  * @author Yusuke Kamiyamane
165
194
  * @license MIT
166
195
  * @copyright Copyright (c) Yusuke Kamiyamane
167
196
  * @see {@link https://github.com/y14e/disclosure-css}
168
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
+ */
169
211
 
170
212
  module.exports = Disclosure;
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
4
4
  * Using the <details> and <summary> element.
5
5
  *
6
- * @version 1.2.4
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
@@ -3,7 +3,7 @@
3
3
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
4
4
  * Using the <details> and <summary> element.
5
5
  *
6
- * @version 1.2.4
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");
@@ -158,11 +187,24 @@ function isFocusable(element) {
158
187
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
159
188
  * Using the <details> and <summary> element.
160
189
  *
161
- * @version 1.2.4
190
+ * @version 1.2.5
162
191
  * @author Yusuke Kamiyamane
163
192
  * @license MIT
164
193
  * @copyright Copyright (c) Yusuke Kamiyamane
165
194
  * @see {@link https://github.com/y14e/disclosure-css}
166
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
+ */
167
209
 
168
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.4",
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"