@y14e/accordion 1.4.15 → 1.4.17

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
@@ -65,7 +65,7 @@ var Accordion = class _Accordion {
65
65
  if (!content2) {
66
66
  return;
67
67
  }
68
- const binding = createBinding(trigger2, content2);
68
+ const binding = this.#createBinding(trigger2, content2);
69
69
  this.#bindings.set(trigger2, binding);
70
70
  this.#bindings.set(content2, binding);
71
71
  });
@@ -97,7 +97,7 @@ var Accordion = class _Accordion {
97
97
  !force && await this.#waitAnimationsFinish();
98
98
  this.#contentElements.forEach((content) => {
99
99
  force && this.#bindings.get(content)?.animation?.finish();
100
- this.#onAnimationFinish(content);
100
+ this.#onContentAnimationFinish(content);
101
101
  });
102
102
  this.#animationController?.abort();
103
103
  this.#animationController = null;
@@ -140,7 +140,7 @@ var Accordion = class _Accordion {
140
140
  String(trigger2.ariaExpanded === "true")
141
141
  );
142
142
  trigger2.id ||= `accordion-trigger-${id}`;
143
- if (!isFocusable(trigger2)) {
143
+ if (!this.#isFocusable(trigger2)) {
144
144
  trigger2.setAttribute("aria-disabled", "true");
145
145
  trigger2.setAttribute("tabindex", "-1");
146
146
  trigger2.style.setProperty("pointer-events", "none");
@@ -170,6 +170,16 @@ var Accordion = class _Accordion {
170
170
  }
171
171
  this.#toggle(trigger, trigger.ariaExpanded === "false");
172
172
  };
173
+ #onContentAnimationFinish(content) {
174
+ const trigger = this.#bindings.get(content)?.trigger;
175
+ if (!trigger) {
176
+ return;
177
+ }
178
+ trigger.ariaExpanded === "false" && content.setAttribute("hidden", "until-found");
179
+ ["block-size", "overflow"].forEach((name) => {
180
+ content.style.removeProperty(name);
181
+ });
182
+ }
173
183
  #onContentBeforeMatch = (event) => {
174
184
  const content = event.currentTarget;
175
185
  if (!(content instanceof HTMLElement)) {
@@ -187,10 +197,10 @@ var Accordion = class _Accordion {
187
197
  }
188
198
  const name = trigger.getAttribute("data-accordion-name");
189
199
  if (name && isOpen) {
190
- const opened = this.#triggerElements.find(
200
+ const open = this.#triggerElements.find(
191
201
  (t) => t !== trigger && t.getAttribute("data-accordion-name") === name && t.ariaExpanded === "true"
192
202
  );
193
- opened && this.#toggle(opened, false, isMatch);
203
+ open && this.#toggle(open, false, isMatch);
194
204
  }
195
205
  trigger.setAttribute(
196
206
  "aria-label",
@@ -229,31 +239,25 @@ var Accordion = class _Accordion {
229
239
  "finish",
230
240
  () => {
231
241
  if (binding?.animation === animation) {
232
- this.#onAnimationFinish(content);
242
+ this.#onContentAnimationFinish(content);
233
243
  cleanup();
234
244
  }
235
245
  },
236
246
  { once: true, signal }
237
247
  );
238
248
  }
249
+ #createBinding(trigger, content) {
250
+ return { trigger, content, animation: null };
251
+ }
252
+ #isFocusable(element) {
253
+ return !element.hasAttribute("disabled") && element.tabIndex >= 0;
254
+ }
239
255
  #mergeOptions(target, source) {
240
256
  return {
241
257
  animation: { ...target.animation, ...source.animation ?? {} },
242
258
  selector: { ...target.selector, ...source.selector ?? {} }
243
259
  };
244
260
  }
245
- #onAnimationFinish(content) {
246
- const trigger = this.#bindings.get(content)?.trigger;
247
- if (!trigger) {
248
- return;
249
- }
250
- if (trigger.ariaExpanded === "false") {
251
- content.setAttribute("hidden", "until-found");
252
- }
253
- ["block-size", "overflow"].forEach((name) => {
254
- content.style.removeProperty(name);
255
- });
256
- }
257
261
  async #waitAnimationsFinish() {
258
262
  const promises = [];
259
263
  this.#contentElements.forEach((content) => {
@@ -263,26 +267,16 @@ var Accordion = class _Accordion {
263
267
  await Promise.allSettled(promises);
264
268
  }
265
269
  };
266
- function createBinding(trigger, content) {
267
- return { trigger, content, animation: null };
268
- }
269
- function isFocusable(element) {
270
- return !element.hasAttribute("disabled") && element.tabIndex >= 0;
271
- }
272
270
  function waitAnimationFinish(animation) {
273
- if (["idle", "finished"].includes(animation.playState)) {
274
- return Promise.resolve();
275
- } else {
276
- return new Promise(
277
- (resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
278
- );
279
- }
271
+ return ["idle", "finished"].includes(animation.playState) ? Promise.resolve() : new Promise(
272
+ (resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
273
+ );
280
274
  }
281
275
  /**
282
276
  * Accordion
283
277
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
284
278
  *
285
- * @version 1.4.15
279
+ * @version 1.4.17
286
280
  * @author Yusuke Kamiyamane
287
281
  * @license MIT
288
282
  * @copyright Copyright (c) Yusuke Kamiyamane
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.4.15
5
+ * @version 1.4.17
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.4.15
5
+ * @version 1.4.17
6
6
  * @author Yusuke Kamiyamane
7
7
  * @license MIT
8
8
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -59,7 +59,7 @@ var Accordion = class _Accordion {
59
59
  if (!content2) {
60
60
  return;
61
61
  }
62
- const binding = createBinding(trigger2, content2);
62
+ const binding = this.#createBinding(trigger2, content2);
63
63
  this.#bindings.set(trigger2, binding);
64
64
  this.#bindings.set(content2, binding);
65
65
  });
@@ -91,7 +91,7 @@ var Accordion = class _Accordion {
91
91
  !force && await this.#waitAnimationsFinish();
92
92
  this.#contentElements.forEach((content) => {
93
93
  force && this.#bindings.get(content)?.animation?.finish();
94
- this.#onAnimationFinish(content);
94
+ this.#onContentAnimationFinish(content);
95
95
  });
96
96
  this.#animationController?.abort();
97
97
  this.#animationController = null;
@@ -134,7 +134,7 @@ var Accordion = class _Accordion {
134
134
  String(trigger2.ariaExpanded === "true")
135
135
  );
136
136
  trigger2.id ||= `accordion-trigger-${id}`;
137
- if (!isFocusable(trigger2)) {
137
+ if (!this.#isFocusable(trigger2)) {
138
138
  trigger2.setAttribute("aria-disabled", "true");
139
139
  trigger2.setAttribute("tabindex", "-1");
140
140
  trigger2.style.setProperty("pointer-events", "none");
@@ -164,6 +164,16 @@ var Accordion = class _Accordion {
164
164
  }
165
165
  this.#toggle(trigger, trigger.ariaExpanded === "false");
166
166
  };
167
+ #onContentAnimationFinish(content) {
168
+ const trigger = this.#bindings.get(content)?.trigger;
169
+ if (!trigger) {
170
+ return;
171
+ }
172
+ trigger.ariaExpanded === "false" && content.setAttribute("hidden", "until-found");
173
+ ["block-size", "overflow"].forEach((name) => {
174
+ content.style.removeProperty(name);
175
+ });
176
+ }
167
177
  #onContentBeforeMatch = (event) => {
168
178
  const content = event.currentTarget;
169
179
  if (!(content instanceof HTMLElement)) {
@@ -181,10 +191,10 @@ var Accordion = class _Accordion {
181
191
  }
182
192
  const name = trigger.getAttribute("data-accordion-name");
183
193
  if (name && isOpen) {
184
- const opened = this.#triggerElements.find(
194
+ const open = this.#triggerElements.find(
185
195
  (t) => t !== trigger && t.getAttribute("data-accordion-name") === name && t.ariaExpanded === "true"
186
196
  );
187
- opened && this.#toggle(opened, false, isMatch);
197
+ open && this.#toggle(open, false, isMatch);
188
198
  }
189
199
  trigger.setAttribute(
190
200
  "aria-label",
@@ -223,31 +233,25 @@ var Accordion = class _Accordion {
223
233
  "finish",
224
234
  () => {
225
235
  if (binding?.animation === animation) {
226
- this.#onAnimationFinish(content);
236
+ this.#onContentAnimationFinish(content);
227
237
  cleanup();
228
238
  }
229
239
  },
230
240
  { once: true, signal }
231
241
  );
232
242
  }
243
+ #createBinding(trigger, content) {
244
+ return { trigger, content, animation: null };
245
+ }
246
+ #isFocusable(element) {
247
+ return !element.hasAttribute("disabled") && element.tabIndex >= 0;
248
+ }
233
249
  #mergeOptions(target, source) {
234
250
  return {
235
251
  animation: { ...target.animation, ...source.animation ?? {} },
236
252
  selector: { ...target.selector, ...source.selector ?? {} }
237
253
  };
238
254
  }
239
- #onAnimationFinish(content) {
240
- const trigger = this.#bindings.get(content)?.trigger;
241
- if (!trigger) {
242
- return;
243
- }
244
- if (trigger.ariaExpanded === "false") {
245
- content.setAttribute("hidden", "until-found");
246
- }
247
- ["block-size", "overflow"].forEach((name) => {
248
- content.style.removeProperty(name);
249
- });
250
- }
251
255
  async #waitAnimationsFinish() {
252
256
  const promises = [];
253
257
  this.#contentElements.forEach((content) => {
@@ -257,26 +261,16 @@ var Accordion = class _Accordion {
257
261
  await Promise.allSettled(promises);
258
262
  }
259
263
  };
260
- function createBinding(trigger, content) {
261
- return { trigger, content, animation: null };
262
- }
263
- function isFocusable(element) {
264
- return !element.hasAttribute("disabled") && element.tabIndex >= 0;
265
- }
266
264
  function waitAnimationFinish(animation) {
267
- if (["idle", "finished"].includes(animation.playState)) {
268
- return Promise.resolve();
269
- } else {
270
- return new Promise(
271
- (resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
272
- );
273
- }
265
+ return ["idle", "finished"].includes(animation.playState) ? Promise.resolve() : new Promise(
266
+ (resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
267
+ );
274
268
  }
275
269
  /**
276
270
  * Accordion
277
271
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
278
272
  *
279
- * @version 1.4.15
273
+ * @version 1.4.17
280
274
  * @author Yusuke Kamiyamane
281
275
  * @license MIT
282
276
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/accordion",
3
- "version": "1.4.15",
3
+ "version": "1.4.17",
4
4
  "description": "WAI-ARIA compliant accordion pattern implementation in TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@y14e/attributes-utils": "^1.1.2",
56
- "@y14e/button": "^1.0.5",
57
- "@y14e/roving-tabindex": "^3.0.11"
56
+ "@y14e/button": "^1.0.6",
57
+ "@y14e/roving-tabindex": "^3.1.2"
58
58
  }
59
59
  }