@data-slot/accordion 0.2.167 → 1.0.1

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 CHANGED
@@ -40,7 +40,9 @@ npm install @data-slot/accordion
40
40
 
41
41
  ## API
42
42
 
43
- ### `create(scope?)`
43
+ ### Initialization
44
+
45
+ #### `create(scope?)`
44
46
 
45
47
  Auto-discover and bind all accordion instances in a scope (defaults to `document`).
46
48
 
@@ -50,7 +52,7 @@ import { create } from "@data-slot/accordion";
50
52
  const controllers = create(); // Returns AccordionController[]
51
53
  ```
52
54
 
53
- ### `createAccordion(root, options?)`
55
+ #### `createAccordion(root, options?)`
54
56
 
55
57
  Create a controller for a specific element.
56
58
 
@@ -67,28 +69,34 @@ const accordion = createAccordion(element, {
67
69
  });
68
70
  ```
69
71
 
70
- ### Options
72
+ ### Slots
71
73
 
72
- | Option | Type | Default | Description |
73
- | --- | --- | --- | --- |
74
- | `multiple` | `boolean` | `false` | Allow multiple items open at once |
75
- | `defaultValue` | `string \| string[]` | `undefined` | Initially expanded item(s) |
76
- | `disabled` | `boolean` | `false` | Disable all user interaction for the accordion |
77
- | `orientation` | `"horizontal" \| "vertical"` | `"vertical"` | Controls roving-focus arrow keys |
78
- | `loopFocus` | `boolean` | `true` | Wrap roving focus at the ends |
79
- | `hiddenUntilFound` | `boolean` | `false` | Use `hidden="until-found"` on closed panels |
80
- | `onValueChange` | `(value: string[]) => void` | `undefined` | Callback when expanded items change |
81
- | `collapsible` | `boolean` | `true` | Deprecated single-mode alias for “can close the last open item” |
74
+ #### Runtime Slots
82
75
 
83
- ### Deprecated Option
76
+ - `accordion` - Root element that manages expanded items and keyboard navigation.
77
+ - `accordion-item` - Container for one section. Set a unique `data-value` to identify it; at least one item is required.
78
+ - `accordion-trigger` - Button inside an item that toggles its content and receives `aria-expanded`.
79
+ - `accordion-content` - Panel inside an item, linked to its trigger and shown when the item is expanded.
84
80
 
85
- The following option is deprecated and will be removed in the next major release:
81
+ #### Style-only Slots
86
82
 
87
- ```typescript
88
- createAccordion(element, {
89
- // Deprecated: use the default Base UI-style collapsible behavior instead.
90
- collapsible: false,
91
- });
83
+ - `accordion-trigger-icon` - Optional icon inside the trigger, useful for rotating with the open state.
84
+ - `accordion-content-inner` - Optional wrapper for content padding inside the animated panel.
85
+
86
+ #### Markup
87
+
88
+ ```html
89
+ <div data-slot="accordion">
90
+ <div data-slot="accordion-item" data-value="unique-id">
91
+ <button data-slot="accordion-trigger">
92
+ <span>Trigger</span>
93
+ <span data-slot="accordion-trigger-icon">+</span>
94
+ </button>
95
+ <div data-slot="accordion-content">
96
+ <div data-slot="accordion-content-inner">Content</div>
97
+ </div>
98
+ </div>
99
+ </div>
92
100
  ```
93
101
 
94
102
  ### Data Attributes
@@ -130,6 +138,30 @@ For multiple default items in HTML, encode the value as JSON:
130
138
  </div>
131
139
  ```
132
140
 
141
+ ### Options
142
+
143
+ | Option | Type | Default | Description |
144
+ | --- | --- | --- | --- |
145
+ | `multiple` | `boolean` | `false` | Allow multiple items open at once |
146
+ | `defaultValue` | `string \| string[]` | `undefined` | Initially expanded item(s) |
147
+ | `disabled` | `boolean` | `false` | Disable all user interaction for the accordion |
148
+ | `orientation` | `"horizontal" \| "vertical"` | `"vertical"` | Controls roving-focus arrow keys |
149
+ | `loopFocus` | `boolean` | `true` | Wrap roving focus at the ends |
150
+ | `hiddenUntilFound` | `boolean` | `false` | Use `hidden="until-found"` on closed panels |
151
+ | `onValueChange` | `(value: string[]) => void` | `undefined` | Callback when expanded items change |
152
+ | `collapsible` | `boolean` | `true` | Deprecated single-mode alias for “can close the last open item” |
153
+
154
+ #### Deprecated Option
155
+
156
+ The following option is deprecated and will be removed in the next major release:
157
+
158
+ ```typescript
159
+ createAccordion(element, {
160
+ // Deprecated: use the default Base UI-style collapsible behavior instead.
161
+ collapsible: false,
162
+ });
163
+ ```
164
+
133
165
  ### Controller
134
166
 
135
167
  | Method/Property | Description |
@@ -140,27 +172,41 @@ For multiple default items in HTML, encode the value as JSON:
140
172
  | `value` | Currently expanded values (readonly `string[]`) |
141
173
  | `destroy()` | Cleanup all event listeners |
142
174
 
143
- ## Markup Structure
175
+ ### Events
144
176
 
145
- ```html
146
- <div data-slot="accordion">
147
- <div data-slot="accordion-item" data-value="unique-id">
148
- <button data-slot="accordion-trigger">
149
- <span>Trigger</span>
150
- <span data-slot="accordion-trigger-icon">+</span>
151
- </button>
152
- <div data-slot="accordion-content">
153
- <div data-slot="accordion-content-inner">Content</div>
154
- </div>
155
- </div>
156
- </div>
177
+ #### Outbound Events
178
+
179
+ Listen for changes via custom events:
180
+
181
+ ```javascript
182
+ element.addEventListener("accordion:change", (e) => {
183
+ console.log("Expanded items:", e.detail.value);
184
+ });
185
+ ```
186
+
187
+ #### Inbound Events
188
+
189
+ Control the accordion via events:
190
+
191
+ | Event | Detail | Description |
192
+ | --- | --- | --- |
193
+ | `accordion:set` | `{ value: string \| string[] }` | Set expanded items programmatically |
194
+
195
+ ```javascript
196
+ element.dispatchEvent(
197
+ new CustomEvent("accordion:set", { detail: { value: "one" } })
198
+ );
199
+
200
+ element.dispatchEvent(
201
+ new CustomEvent("accordion:set", { detail: { value: ["one", "two"] } })
202
+ );
157
203
  ```
158
204
 
159
- `data-slot="accordion-trigger-icon"` and `data-slot="accordion-content-inner"` are optional styling hooks.
205
+ `accordion:set` and controller methods still work when the accordion is disabled. User-triggered click and keyboard interaction do not.
160
206
 
161
- ## Styling
207
+ ### Styling
162
208
 
163
- ### State Hooks
209
+ #### State Hooks
164
210
 
165
211
  The accordion exposes these useful styling hooks:
166
212
 
@@ -171,7 +217,7 @@ The accordion exposes these useful styling hooks:
171
217
  | trigger | `data-state`, `data-panel-open`, `data-disabled`, `aria-expanded` |
172
218
  | content | `data-state`, `data-open`, `data-closed`, `data-index`, `data-disabled`, `data-orientation`, `data-starting-style`, `data-ending-style` |
173
219
 
174
- ### CSS Variables
220
+ #### CSS Variables
175
221
 
176
222
  The content element exposes size variables for height or width transitions:
177
223
 
@@ -182,7 +228,7 @@ The content element exposes size variables for height or width transitions:
182
228
  | `--radix-accordion-content-height` | Compatibility alias for Tailwind/Radix accordion keyframes |
183
229
  | `--radix-accordion-content-width` | Compatibility alias for width-based integrations |
184
230
 
185
- ### CSS Example
231
+ #### CSS Example
186
232
 
187
233
  ```css
188
234
  [data-slot="accordion-item"] {
@@ -227,10 +273,10 @@ The content element exposes size variables for height or width transitions:
227
273
  }
228
274
  ```
229
275
 
230
- ### Tailwind Example
276
+ #### Tailwind Example
231
277
 
232
278
  ```html
233
- <div data-slot="accordion" class="overflow-hidden rounded-2xl border">
279
+ <div data-slot="accordion" class="overflow-hidden border">
234
280
  <div
235
281
  data-slot="accordion-item"
236
282
  data-value="one"
@@ -264,7 +310,7 @@ The content element exposes size variables for height or width transitions:
264
310
  </div>
265
311
  ```
266
312
 
267
- ## Keyboard Navigation
313
+ ### Keyboard Navigation
268
314
 
269
315
  | Key | Action |
270
316
  | --- | --- |
@@ -276,38 +322,6 @@ The content element exposes size variables for height or width transitions:
276
322
 
277
323
  Disabled items are skipped during roving focus.
278
324
 
279
- ## Events
280
-
281
- ### Outbound Events
282
-
283
- Listen for changes via custom events:
284
-
285
- ```javascript
286
- element.addEventListener("accordion:change", (e) => {
287
- console.log("Expanded items:", e.detail.value);
288
- });
289
- ```
290
-
291
- ### Inbound Events
292
-
293
- Control the accordion via events:
294
-
295
- | Event | Detail | Description |
296
- | --- | --- | --- |
297
- | `accordion:set` | `{ value: string \| string[] }` | Set expanded items programmatically |
298
-
299
- ```javascript
300
- element.dispatchEvent(
301
- new CustomEvent("accordion:set", { detail: { value: "one" } })
302
- );
303
-
304
- element.dispatchEvent(
305
- new CustomEvent("accordion:set", { detail: { value: ["one", "two"] } })
306
- );
307
- ```
308
-
309
- `accordion:set` and controller methods still work when the accordion is disabled. User-triggered click and keyboard interaction do not.
310
-
311
325
  ## License
312
326
 
313
327
  MIT
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=[`horizontal`,`vertical`],n=new Set([`all`,`height`,`width`,`block-size`,`inline-size`]),r=new Set([`Enter`,` `]),i=e=>!!e&&(e.hasAttribute(`disabled`)||e.hasAttribute(`data-disabled`)||e.getAttribute(`aria-disabled`)===`true`),a=(e,t,n)=>{n?e.setAttribute(t,``):e.removeAttribute(t)},o=(e,t)=>{e.setAttribute(`data-state`,t?`open`:`closed`),t?(e.setAttribute(`data-open`,``),e.removeAttribute(`data-closed`)):(e.setAttribute(`data-closed`,``),e.removeAttribute(`data-open`))},s=e=>{let t=e.trim();return t?t.endsWith(`ms`)?Number.parseFloat(t.slice(0,-2))||0:t.endsWith(`s`)?(Number.parseFloat(t.slice(0,-1))||0)*1e3:Number.parseFloat(t)||0:0},c=(e,t)=>{let n=e.split(`,`),r=t.split(`,`),i=Math.max(n.length,r.length),a=0;for(let e=0;e<i;e+=1){let t=s(n[e]??n[n.length-1]??`0`),i=s(r[e]??r[r.length-1]??`0`);a=Math.max(a,t+i)}return a},l=e=>{let t=getComputedStyle(e),n=c(t.transitionDuration,t.transitionDelay),r=c(t.animationDuration,t.animationDelay);return Math.max(n,r)},u=e=>c(e.animationDuration,e.animationDelay)<=0?!1:e.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`),d=(e,t)=>{let n=getComputedStyle(e),r=n.transitionProperty.split(`,`).map(e=>e.trim()),i=n.transitionDuration.split(`,`),a=n.transitionDelay.split(`,`),o=Math.max(r.length,i.length,a.length),c=0;for(let e=0;e<o;e+=1){if(!t(r[e]??r[r.length-1]??`all`))continue;let n=s(i[e]??i[i.length-1]??`0`),o=s(a[e]??a[a.length-1]??`0`);c=Math.max(c,n+o)}return c},f=e=>d(e,e=>n.has(e)),p=e=>{if(e===void 0)return;let t=e.trim();if(!t.startsWith(`[`)||!t.endsWith(`]`))return e;try{let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>typeof e==`string`):e}catch{return e}},m=`@data-slot/accordion`;function h(s,c={}){let d=(0,e.reuseRootBinding)(s,m,`[@data-slot/accordion] createAccordion() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(d)return d;let h=s,g=(0,e.getParts)(s,`accordion-item`);if(g.length===0)throw Error(`Accordion requires at least one accordion-item`);let _=s.ownerDocument?.defaultView??window,v=c.multiple??(0,e.getDataBool)(s,`multiple`)??!1,ee=c.onValueChange,y=c.disabled??(0,e.getDataBool)(s,`disabled`)??i(s),b=c.orientation??(0,e.getDataEnum)(s,`orientation`,t)??`vertical`,x=c.loopFocus??(0,e.getDataBool)(s,`loopFocus`)??!0,S=c.hiddenUntilFound??(0,e.getDataBool)(s,`hiddenUntilFound`)??!1,C=c.collapsible??(0,e.getDataBool)(s,`collapsible`)??!0,w=[],T=[],E=(e,t,n)=>{e.content.style.setProperty(`--accordion-panel-height`,t),e.content.style.setProperty(`--accordion-panel-width`,n),e.content.style.setProperty(`--radix-accordion-content-height`,t),e.content.style.setProperty(`--radix-accordion-content-width`,n)},D=(e,t,n)=>{E(e,`${t}px`,`${n}px`)},O=e=>{E(e,`auto`,`auto`)},k=e=>{D(e,0,0)},A=(e,{resetVarsToAuto:t=!1}={})=>{t&&O(e),D(e,e.content.scrollHeight,e.content.scrollWidth)},j=e=>{let t=e.content.style.getPropertyValue(`--accordion-panel-height`).trim(),n=e.content.style.getPropertyValue(`--accordion-panel-width`).trim();return t===`auto`&&n===`auto`},M=e=>{e.suppressClick=!1,e.suppressClickTimeoutId!==null&&(_.clearTimeout(e.suppressClickTimeoutId),e.suppressClickTimeoutId=null)},N=e=>{e.openSettleRafId!==null&&(_.cancelAnimationFrame(e.openSettleRafId),e.openSettleRafId=null),e.openSettleTimeoutId!==null&&(_.clearTimeout(e.openSettleTimeoutId),e.openSettleTimeoutId=null),e.openSettleCleanups.forEach(e=>e()),e.openSettleCleanups=[]},P=e=>{e.closeZeroRafId!==null&&(_.cancelAnimationFrame(e.closeZeroRafId),e.closeZeroRafId=null)},F=e=>{N(e),P(e)},I=e=>{let t=getComputedStyle(e.content),n=f(e.content)>0,r=u(t);return r&&!n?`css-animation`:n?`css-transition`:r?`css-animation`:`none`},L=(e,t)=>{let n=e.content.style.getPropertyValue(`animation-name`);e.content.style.setProperty(`animation-name`,`none`);try{t()}finally{n?e.content.style.setProperty(`animation-name`,n):e.content.style.removeProperty(`animation-name`)}},R=e=>{e.idleAnimationSuppressed||(e.idleAnimationName=e.content.style.getPropertyValue(`animation-name`)||null,e.idleAnimationSuppressed=!0,e.content.style.setProperty(`animation-name`,`none`))},z=e=>{e.idleAnimationSuppressed&&=(e.idleAnimationName?e.content.style.setProperty(`animation-name`,e.idleAnimationName):e.content.style.removeProperty(`animation-name`),e.idleAnimationName=null,!1)},B=e=>{e.content.removeAttribute(`hidden`)},V=e=>{S?e.content.setAttribute(`hidden`,`until-found`):e.content.hidden=!0,k(e)},H=new Set,U=(e,t)=>{N(e),!(!H.has(e.value)||e.presence.isExiting)&&(O(e),t===`css-animation`&&R(e))},W=(e,t)=>{N(e);let r=l(e.content),i=f(e.content),a=i||r;if(a>0){let r=typeof _.performance?.now==`function`?_.performance.now():Date.now(),o=e=>(typeof _.performance?.now==`function`?_.performance.now():Date.now())-r>=Math.max(0,e-5),s=r=>{if(r.target!==e.content)return;let s=`propertyName`in r?String(r.propertyName):``;if(i>0){if(!n.has(s)||!o(i))return}else if(!o(a))return;U(e,t)},c=n=>{n.target===e.content&&(i>0||o(a)&&U(e,t))};e.content.addEventListener(`transitionend`,s),e.content.addEventListener(`animationend`,c),e.openSettleCleanups.push(()=>e.content.removeEventListener(`transitionend`,s)),e.openSettleCleanups.push(()=>e.content.removeEventListener(`animationend`,c)),e.openSettleTimeoutId=_.setTimeout(()=>{e.openSettleTimeoutId=null,U(e,t)},Math.ceil(a)+50);return}e.openSettleRafId=_.requestAnimationFrame(()=>{e.openSettleRafId=null,U(e,t)})},G=e=>{P(e),e.closeZeroRafId=_.requestAnimationFrame(()=>{e.closeZeroRafId=null,!H.has(e.value)&&e.presence.isExiting&&k(e)})},K=e=>{e.el.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-orientation`,b),a(e.el,`data-disabled`,e.disabled),a(e.trigger,`data-disabled`,e.disabled),a(e.content,`data-disabled`,e.disabled),e.disabled?(e.trigger.setAttribute(`aria-disabled`,`true`),e.trigger instanceof HTMLButtonElement&&(e.trigger.disabled=!0)):(e.trigger.removeAttribute(`aria-disabled`),e.trigger instanceof HTMLButtonElement&&(e.trigger.disabled=!1))},q=(e,t)=>{e.trigger.setAttribute(`data-state`,t?`open`:`closed`),a(e.trigger,`data-panel-open`,t)},te=t=>{let n=H.has(t.value);K(t),(0,e.setAria)(t.trigger,`expanded`,n),o(t.el,n),o(t.content,n),q(t,n),t.content.removeAttribute(`data-starting-style`),t.content.removeAttribute(`data-ending-style`);let r=I(t);n?(B(t),r===`css-animation`?L(t,()=>{A(t,{resetVarsToAuto:!0})}):A(t),W(t,r)):V(t)},ne=t=>{let n=H.has(t.value),r=t.trigger.getAttribute(`aria-expanded`)===`true`;K(t),(0,e.setAria)(t.trigger,`expanded`,n),o(t.el,n),o(t.content,n),q(t,n);let i=I(t);if(n){if(P(t),B(t),r&&!t.presence.isExiting&&j(t))return;i===`css-animation`?L(t,()=>{A(t,{resetVarsToAuto:!0}),r||t.presence.enter()}):(A(t),r||t.presence.enter()),W(t,i);return}if(r){N(t),i===`css-animation`?L(t,()=>{A(t,{resetVarsToAuto:!0}),t.presence.exit()}):(A(t),t.presence.exit(),G(t));return}F(t),t.content.removeAttribute(`data-starting-style`),t.content.removeAttribute(`data-ending-style`),V(t)},J=e=>{let t=[],n=new Set;for(let r of e)if(!(n.has(r)||!g.some(e=>e.dataset.value===r))&&(n.add(r),t.push(r),!v&&t.length===1))break;return t},re=e=>e.size===H.size?[...e].some(e=>!H.has(e)):!0,ie=()=>{T.forEach(ne)},ae=()=>{let t=[...H];(0,e.emit)(s,`accordion:change`,{value:t}),ee?.(t)},Y=e=>{let t=J(e);if(!v&&!C&&t.length===0&&H.size>0)return!1;let n=new Set(t);return re(n)?(T.forEach(e=>{H.has(e.value)!==n.has(e.value)&&z(e)}),H=n,ie(),ae(),!0):!1},X=e=>(e.getAttribute(`dir`)??h.getAttribute(`dir`))===`rtl`||(getComputedStyle(e).direction||getComputedStyle(h).direction||s.ownerDocument?.documentElement.getAttribute(`dir`)||``)===`rtl`?`rtl`:`ltr`;h.setAttribute(`data-orientation`,b),a(h,`data-disabled`,!!y),g.forEach((t,n)=>{let a=t.dataset.value;if(!a)return;let o=(0,e.getOwnedElements)(s,t,`[data-slot="accordion-trigger"]`)[0]??null,c=(0,e.getOwnedElements)(s,t,`[data-slot="accordion-content"]`)[0]??null;if(!o||!c)return;let l=(0,e.ensureId)(c,`accordion-content`),u=(0,e.ensureId)(o,`accordion-trigger`);o.setAttribute(`aria-controls`,l),c.setAttribute(`aria-labelledby`,u),c.setAttribute(`role`,`region`);let d=!!y||i(t)||i(o),f;f={el:t,value:a,index:n,disabled:d,trigger:o,content:c,presence:(0,e.createPresenceLifecycle)({element:c,onExitComplete:()=>{P(f),V(f)}}),sizeObserver:null,idleAnimationName:null,idleAnimationSuppressed:!1,openSettleRafId:null,openSettleTimeoutId:null,closeZeroRafId:null,openSettleCleanups:[],suppressClick:!1,suppressClickTimeoutId:null},typeof ResizeObserver<`u`&&(f.sizeObserver=new ResizeObserver(()=>{!H.has(f.value)||f.presence.isExiting||j(f)||A(f)}),f.sizeObserver.observe(c)),w.push((0,e.on)(o,`click`,()=>{if(f.suppressClick){M(f);return}f.disabled||(H.has(f.value)?Y([...H].filter(e=>e!==f.value)):Y(v?[...H,f.value]:[f.value]))})),w.push((0,e.on)(o,`keydown`,e=>{if(r.has(e.key)){if(f.disabled){e.preventDefault();return}e.preventDefault(),M(f),f.suppressClick=!0,f.suppressClickTimeoutId=_.setTimeout(()=>{f.suppressClick=!1,f.suppressClickTimeoutId=null},0),H.has(f.value)?Y([...H].filter(e=>e!==f.value)):Y(v?[...H,f.value]:[f.value])}})),S&&w.push((0,e.on)(c,`beforematch`,()=>{Y(v?[...H,f.value]:[f.value])})),T.push(f)});let Z=new Set(T.map(e=>e.value)),Q=c.defaultValue??p((0,e.getDataString)(s,`defaultValue`)),oe=J((Q?Array.isArray(Q)?Q:[Q]:[]).filter(e=>Z.has(e)));H=new Set(oe),T.forEach(te),w.push((0,e.on)(h,`keydown`,e=>{let t=e.target;if(!t)return;let n=T.find(e=>e.trigger===t);if(!n)return;let r=T.filter(e=>!e.disabled),i=r.findIndex(e=>e.trigger===t);if(i===-1)return;let a=r.length-1,o=-1,s=()=>{o=x?i+1>a?0:i+1:Math.min(i+1,a)},c=()=>{o=x?i===0?a:i-1:Math.max(i-1,0)};switch(e.key){case`ArrowDown`:b===`vertical`&&s();break;case`ArrowUp`:b===`vertical`&&c();break;case`ArrowRight`:b===`horizontal`&&(X(n.trigger)===`rtl`?c():s());break;case`ArrowLeft`:b===`horizontal`&&(X(n.trigger)===`rtl`?s():c());break;case`Home`:o=0;break;case`End`:o=a;break;default:return}o<0||(e.preventDefault(),r[o]?.trigger.focus())})),w.push((0,e.onRoot)(s,`accordion:set`,e=>{let t=e.detail?.value;t!==void 0&&Y(Array.isArray(t)?t:[t])}));let $={expand:e=>{!Z.has(e)||H.has(e)||Y(v?[...H,e]:[e])},collapse:e=>{!Z.has(e)||!H.has(e)||Y([...H].filter(t=>t!==e))},toggle:e=>{Z.has(e)&&(H.has(e)?$.collapse(e):$.expand(e))},get value(){return[...H]},destroy:()=>{T.forEach(e=>{M(e),e.presence.cleanup(),F(e),e.sizeObserver?.disconnect(),e.sizeObserver=null}),w.forEach(e=>e()),w.length=0,(0,e.clearRootBinding)(s,m,$)}};return(0,e.setRootBinding)(s,m,$),$}function g(t=document){let n=[];for(let r of(0,e.getRoots)(t,`accordion`))(0,e.hasRootBinding)(r,m)||n.push(h(r));return n}exports.create=g,exports.createAccordion=h;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=[`horizontal`,`vertical`],n=new Set([`all`,`height`,`width`,`block-size`,`inline-size`]),r=new Set([`Enter`,` `]),i=e=>!!e&&(e.hasAttribute(`disabled`)||e.hasAttribute(`data-disabled`)||e.getAttribute(`aria-disabled`)===`true`),a=(e,t,n)=>{n?e.setAttribute(t,``):e.removeAttribute(t)},o=(e,t)=>{e.setAttribute(`data-state`,t?`open`:`closed`),t?(e.setAttribute(`data-open`,``),e.removeAttribute(`data-closed`)):(e.setAttribute(`data-closed`,``),e.removeAttribute(`data-open`))},s=e=>{let t=e.trim();return t?t.endsWith(`ms`)?Number.parseFloat(t.slice(0,-2))||0:t.endsWith(`s`)?(Number.parseFloat(t.slice(0,-1))||0)*1e3:Number.parseFloat(t)||0:0},c=(e,t)=>{let n=e.split(`,`),r=t.split(`,`),i=Math.max(n.length,r.length),a=0;for(let e=0;e<i;e+=1){let t=s(n[e]??n[n.length-1]??`0`),i=s(r[e]??r[r.length-1]??`0`);a=Math.max(a,t+i)}return a},l=e=>{let t=c(e.transitionDuration,e.transitionDelay),n=c(e.animationDuration,e.animationDelay);return Math.max(t,n)},u=e=>c(e.animationDuration,e.animationDelay)<=0?!1:e.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`),d=(e,t)=>{let n=e.transitionProperty.split(`,`).map(e=>e.trim()),r=e.transitionDuration.split(`,`),i=e.transitionDelay.split(`,`),a=Math.max(n.length,r.length,i.length),o=0;for(let e=0;e<a;e+=1){if(!t(n[e]??n[n.length-1]??`all`))continue;let a=s(r[e]??r[r.length-1]??`0`),c=s(i[e]??i[i.length-1]??`0`);o=Math.max(o,a+c)}return o},f=e=>d(e,e=>n.has(e)),p=e=>{if(e===void 0)return;let t=e.trim();if(!t.startsWith(`[`)||!t.endsWith(`]`))return e;try{let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>typeof e==`string`):e}catch{return e}},m=`@data-slot/accordion`;function h(s,c={}){let d=(0,e.reuseRootBinding)(s,m,`[@data-slot/accordion] createAccordion() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(d)return d;let h=s,g=(0,e.getParts)(s,`accordion-item`);if(g.length===0)throw Error(`Accordion requires at least one accordion-item`);let _=s.ownerDocument?.defaultView??window,v=c.multiple??(0,e.getDataBool)(s,`multiple`)??!1,ee=c.onValueChange,y=c.disabled??(0,e.getDataBool)(s,`disabled`)??i(s),b=c.orientation??(0,e.getDataEnum)(s,`orientation`,t)??`vertical`,x=c.loopFocus??(0,e.getDataBool)(s,`loopFocus`)??!0,S=c.hiddenUntilFound??(0,e.getDataBool)(s,`hiddenUntilFound`)??!1,C=c.collapsible??(0,e.getDataBool)(s,`collapsible`)??!0,w=[],T=[],E=(e,t,n)=>{e.content.style.setProperty(`--accordion-panel-height`,t),e.content.style.setProperty(`--accordion-panel-width`,n),e.content.style.setProperty(`--radix-accordion-content-height`,t),e.content.style.setProperty(`--radix-accordion-content-width`,n)},D=(e,t,n)=>{E(e,`${t}px`,`${n}px`)},O=e=>{E(e,`auto`,`auto`)},k=e=>{D(e,0,0)},A=e=>{D(e,e.content.scrollHeight,e.content.scrollWidth)},j=e=>{let t=e.content.style.getPropertyValue(`--accordion-panel-height`).trim(),n=e.content.style.getPropertyValue(`--accordion-panel-width`).trim();return t===`auto`&&n===`auto`},M=e=>{e.suppressClick=!1,e.suppressClickTimeoutId!==null&&(_.clearTimeout(e.suppressClickTimeoutId),e.suppressClickTimeoutId=null)},N=e=>{e.openSettleRafId!==null&&(_.cancelAnimationFrame(e.openSettleRafId),e.openSettleRafId=null),e.openSettleTimeoutId!==null&&(_.clearTimeout(e.openSettleTimeoutId),e.openSettleTimeoutId=null),e.openSettleCleanups.forEach(e=>e()),e.openSettleCleanups=[]},P=e=>{e.closeZeroRafId!==null&&(_.cancelAnimationFrame(e.closeZeroRafId),e.closeZeroRafId=null)},F=e=>{N(e),P(e)},I=e=>f(e)>0?`css-transition`:u(e)?`css-animation`:`none`,L=(e,t)=>{let n=e.content.style.getPropertyValue(`animation-name`);e.content.style.setProperty(`animation-name`,`none`);try{O(e),A(e),t?.()}finally{n?e.content.style.setProperty(`animation-name`,n):e.content.style.removeProperty(`animation-name`)}},R=e=>{e.idleAnimationSuppressed||(e.idleAnimationName=e.content.style.getPropertyValue(`animation-name`)||null,e.idleAnimationSuppressed=!0,e.content.style.setProperty(`animation-name`,`none`))},z=e=>{e.idleAnimationSuppressed&&=(e.idleAnimationName?e.content.style.setProperty(`animation-name`,e.idleAnimationName):e.content.style.removeProperty(`animation-name`),e.idleAnimationName=null,!1)},B=e=>{e.content.removeAttribute(`hidden`)},V=e=>{S?e.content.setAttribute(`hidden`,`until-found`):e.content.hidden=!0,k(e)},H=new Set,U=(e,t)=>{N(e),!(!H.has(e.value)||e.presence.isExiting)&&(O(e),t===`css-animation`&&R(e))},W=(e,t,r)=>{N(e);let i=l(r),a=f(r),o=a||i;if(o>0){let r=typeof _.performance?.now==`function`?_.performance.now():Date.now(),i=e=>(typeof _.performance?.now==`function`?_.performance.now():Date.now())-r>=Math.max(0,e-5),s=r=>{if(r.target!==e.content)return;let s=`propertyName`in r?String(r.propertyName):``;if(a>0){if(!n.has(s)||!i(a))return}else if(!i(o))return;U(e,t)},c=n=>{n.target===e.content&&(a>0||i(o)&&U(e,t))};e.content.addEventListener(`transitionend`,s),e.content.addEventListener(`animationend`,c),e.openSettleCleanups.push(()=>e.content.removeEventListener(`transitionend`,s)),e.openSettleCleanups.push(()=>e.content.removeEventListener(`animationend`,c)),e.openSettleTimeoutId=_.setTimeout(()=>{e.openSettleTimeoutId=null,U(e,t)},Math.ceil(o)+50);return}e.openSettleRafId=_.requestAnimationFrame(()=>{e.openSettleRafId=null,U(e,t)})},G=e=>{P(e),e.closeZeroRafId=_.requestAnimationFrame(()=>{e.closeZeroRafId=null,!H.has(e.value)&&e.presence.isExiting&&k(e)})},K=e=>{e.el.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-orientation`,b),a(e.el,`data-disabled`,e.disabled),a(e.trigger,`data-disabled`,e.disabled),a(e.content,`data-disabled`,e.disabled),e.disabled?(e.trigger.setAttribute(`aria-disabled`,`true`),e.trigger instanceof HTMLButtonElement&&(e.trigger.disabled=!0)):(e.trigger.removeAttribute(`aria-disabled`),e.trigger instanceof HTMLButtonElement&&(e.trigger.disabled=!1))},q=(e,t)=>{e.trigger.setAttribute(`data-state`,t?`open`:`closed`),a(e.trigger,`data-panel-open`,t)},te=t=>{let n=H.has(t.value);if(K(t),(0,e.setAria)(t.trigger,`expanded`,n),o(t.el,n),o(t.content,n),q(t,n),t.content.removeAttribute(`data-starting-style`),t.content.removeAttribute(`data-ending-style`),n){B(t);let e=getComputedStyle(t.content),n=I(e);n===`css-animation`?L(t):A(t),W(t,n,e)}else V(t)},ne=(t,n)=>{let r=H.has(t.value),i=t.trigger.getAttribute(`aria-expanded`)===`true`;if(!(r===i&&(r?j(t):!t.presence.isExiting))){if((0,e.setAria)(t.trigger,`expanded`,r),o(t.el,r),o(t.content,r),q(t,r),r){P(t),B(t);let e=getComputedStyle(t.content),n=I(e);n===`css-animation`?L(t,()=>{i||t.presence.enter()}):(A(t),i||t.presence.enter()),W(t,n,e);return}if(i){N(t),I(getComputedStyle(t.content))===`css-animation`?L(t,()=>t.presence.exit()):(D(t,...n),t.presence.exit(),G(t));return}F(t),t.content.removeAttribute(`data-starting-style`),t.content.removeAttribute(`data-ending-style`),V(t)}},J=e=>{let t=[],n=new Set;for(let r of e)if(!(n.has(r)||!g.some(e=>e.dataset.value===r))&&(n.add(r),t.push(r),!v&&t.length===1))break;return t},re=e=>e.size===H.size?[...e].some(e=>!H.has(e)):!0,ie=()=>{let t=[...H];(0,e.emit)(s,`accordion:change`,{value:t}),ee?.(t)},Y=e=>{let t=J(e);if(!v&&!C&&t.length===0&&H.size>0)return!1;let n=new Set(t);if(!re(n))return!1;let r=T.filter(e=>H.has(e.value)!==n.has(e.value)),i=new Map;for(let e of r)H.has(e.value)&&i.set(e,[e.content.scrollHeight,e.content.scrollWidth]);return r.forEach(z),H=n,T.forEach(e=>ne(e,i.get(e))),ie(),!0},X=e=>(e.getAttribute(`dir`)??h.getAttribute(`dir`))===`rtl`||(getComputedStyle(e).direction||getComputedStyle(h).direction||s.ownerDocument?.documentElement.getAttribute(`dir`)||``)===`rtl`?`rtl`:`ltr`;h.setAttribute(`data-orientation`,b),a(h,`data-disabled`,!!y),g.forEach((t,n)=>{let a=t.dataset.value;if(!a)return;let o=(0,e.getOwnedElements)(s,t,`[data-slot="accordion-trigger"]`)[0]??null,c=(0,e.getOwnedElements)(s,t,`[data-slot="accordion-content"]`)[0]??null;if(!o||!c)return;let l=(0,e.ensureId)(c,`accordion-content`),u=(0,e.ensureId)(o,`accordion-trigger`);o.setAttribute(`aria-controls`,l),c.setAttribute(`aria-labelledby`,u),c.setAttribute(`role`,`region`);let d=!!y||i(t)||i(o),f;f={el:t,value:a,index:n,disabled:d,trigger:o,content:c,presence:(0,e.createPresenceLifecycle)({element:c,onExitComplete:()=>{P(f),V(f)}}),sizeObserver:null,idleAnimationName:null,idleAnimationSuppressed:!1,openSettleRafId:null,openSettleTimeoutId:null,closeZeroRafId:null,openSettleCleanups:[],suppressClick:!1,suppressClickTimeoutId:null},typeof ResizeObserver<`u`&&(f.sizeObserver=new ResizeObserver(()=>{!H.has(f.value)||f.presence.isExiting||j(f)||A(f)}),f.sizeObserver.observe(c)),w.push((0,e.on)(o,`click`,()=>{if(f.suppressClick){M(f);return}f.disabled||(H.has(f.value)?Y([...H].filter(e=>e!==f.value)):Y(v?[...H,f.value]:[f.value]))})),w.push((0,e.on)(o,`keydown`,e=>{if(r.has(e.key)){if(f.disabled){e.preventDefault();return}e.preventDefault(),M(f),f.suppressClick=!0,f.suppressClickTimeoutId=_.setTimeout(()=>{f.suppressClick=!1,f.suppressClickTimeoutId=null},0),H.has(f.value)?Y([...H].filter(e=>e!==f.value)):Y(v?[...H,f.value]:[f.value])}})),S&&w.push((0,e.on)(c,`beforematch`,()=>{Y(v?[...H,f.value]:[f.value])})),T.push(f)});let Z=new Set(T.map(e=>e.value)),Q=c.defaultValue??p((0,e.getDataString)(s,`defaultValue`)),ae=J((Q?Array.isArray(Q)?Q:[Q]:[]).filter(e=>Z.has(e)));H=new Set(ae),T.forEach(te),w.push((0,e.on)(h,`keydown`,e=>{let t=e.target;if(!t)return;let n=T.find(e=>e.trigger===t);if(!n)return;let r=T.filter(e=>!e.disabled),i=r.findIndex(e=>e.trigger===t);if(i===-1)return;let a=r.length-1,o=-1,s=()=>{o=x?i+1>a?0:i+1:Math.min(i+1,a)},c=()=>{o=x?i===0?a:i-1:Math.max(i-1,0)};switch(e.key){case`ArrowDown`:b===`vertical`&&s();break;case`ArrowUp`:b===`vertical`&&c();break;case`ArrowRight`:b===`horizontal`&&(X(n.trigger)===`rtl`?c():s());break;case`ArrowLeft`:b===`horizontal`&&(X(n.trigger)===`rtl`?s():c());break;case`Home`:o=0;break;case`End`:o=a;break;default:return}o<0||(e.preventDefault(),r[o]?.trigger.focus())})),w.push((0,e.onRoot)(s,`accordion:set`,e=>{let t=e.detail?.value;t!==void 0&&Y(Array.isArray(t)?t:[t])}));let $={expand:e=>{!Z.has(e)||H.has(e)||Y(v?[...H,e]:[e])},collapse:e=>{!Z.has(e)||!H.has(e)||Y([...H].filter(t=>t!==e))},toggle:e=>{Z.has(e)&&(H.has(e)?$.collapse(e):$.expand(e))},get value(){return[...H]},destroy:()=>{T.forEach(e=>{M(e),e.presence.cleanup(),F(e),e.sizeObserver?.disconnect(),e.sizeObserver=null}),w.forEach(e=>e()),w.length=0,(0,e.clearRootBinding)(s,m,$)}};return(0,e.setRootBinding)(s,m,$),$}function g(t=document){let n=[];for(let r of(0,e.getRoots)(t,`accordion`))(0,e.hasRootBinding)(r,m)||n.push(h(r));return n}exports.create=g,exports.createAccordion=h;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{clearRootBinding as e,createPresenceLifecycle as t,emit as n,ensureId as r,getDataBool as i,getDataEnum as a,getDataString as o,getOwnedElements as s,getParts as c,getRoots as l,hasRootBinding as u,on as d,onRoot as f,reuseRootBinding as p,setAria as m,setRootBinding as ee}from"@data-slot/core";const te=[`horizontal`,`vertical`],ne=new Set([`all`,`height`,`width`,`block-size`,`inline-size`]),re=new Set([`Enter`,` `]),h=e=>!!e&&(e.hasAttribute(`disabled`)||e.hasAttribute(`data-disabled`)||e.getAttribute(`aria-disabled`)===`true`),g=(e,t,n)=>{n?e.setAttribute(t,``):e.removeAttribute(t)},_=(e,t)=>{e.setAttribute(`data-state`,t?`open`:`closed`),t?(e.setAttribute(`data-open`,``),e.removeAttribute(`data-closed`)):(e.setAttribute(`data-closed`,``),e.removeAttribute(`data-open`))},v=e=>{let t=e.trim();return t?t.endsWith(`ms`)?Number.parseFloat(t.slice(0,-2))||0:t.endsWith(`s`)?(Number.parseFloat(t.slice(0,-1))||0)*1e3:Number.parseFloat(t)||0:0},y=(e,t)=>{let n=e.split(`,`),r=t.split(`,`),i=Math.max(n.length,r.length),a=0;for(let e=0;e<i;e+=1){let t=v(n[e]??n[n.length-1]??`0`),i=v(r[e]??r[r.length-1]??`0`);a=Math.max(a,t+i)}return a},ie=e=>{let t=getComputedStyle(e),n=y(t.transitionDuration,t.transitionDelay),r=y(t.animationDuration,t.animationDelay);return Math.max(n,r)},ae=e=>y(e.animationDuration,e.animationDelay)<=0?!1:e.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`),b=(e,t)=>{let n=getComputedStyle(e),r=n.transitionProperty.split(`,`).map(e=>e.trim()),i=n.transitionDuration.split(`,`),a=n.transitionDelay.split(`,`),o=Math.max(r.length,i.length,a.length),s=0;for(let e=0;e<o;e+=1){if(!t(r[e]??r[r.length-1]??`all`))continue;let n=v(i[e]??i[i.length-1]??`0`),o=v(a[e]??a[a.length-1]??`0`);s=Math.max(s,n+o)}return s},x=e=>b(e,e=>ne.has(e)),oe=e=>{if(e===void 0)return;let t=e.trim();if(!t.startsWith(`[`)||!t.endsWith(`]`))return e;try{let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>typeof e==`string`):e}catch{return e}},S=`@data-slot/accordion`;function C(l,u={}){let v=p(l,S,`[@data-slot/accordion] createAccordion() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(v)return v;let y=l,b=c(l,`accordion-item`);if(b.length===0)throw Error(`Accordion requires at least one accordion-item`);let C=l.ownerDocument?.defaultView??window,w=u.multiple??i(l,`multiple`)??!1,se=u.onValueChange,T=u.disabled??i(l,`disabled`)??h(l),E=u.orientation??a(l,`orientation`,te)??`vertical`,ce=u.loopFocus??i(l,`loopFocus`)??!0,D=u.hiddenUntilFound??i(l,`hiddenUntilFound`)??!1,le=u.collapsible??i(l,`collapsible`)??!0,O=[],k=[],A=(e,t,n)=>{e.content.style.setProperty(`--accordion-panel-height`,t),e.content.style.setProperty(`--accordion-panel-width`,n),e.content.style.setProperty(`--radix-accordion-content-height`,t),e.content.style.setProperty(`--radix-accordion-content-width`,n)},j=(e,t,n)=>{A(e,`${t}px`,`${n}px`)},M=e=>{A(e,`auto`,`auto`)},N=e=>{j(e,0,0)},P=(e,{resetVarsToAuto:t=!1}={})=>{t&&M(e),j(e,e.content.scrollHeight,e.content.scrollWidth)},F=e=>{let t=e.content.style.getPropertyValue(`--accordion-panel-height`).trim(),n=e.content.style.getPropertyValue(`--accordion-panel-width`).trim();return t===`auto`&&n===`auto`},I=e=>{e.suppressClick=!1,e.suppressClickTimeoutId!==null&&(C.clearTimeout(e.suppressClickTimeoutId),e.suppressClickTimeoutId=null)},L=e=>{e.openSettleRafId!==null&&(C.cancelAnimationFrame(e.openSettleRafId),e.openSettleRafId=null),e.openSettleTimeoutId!==null&&(C.clearTimeout(e.openSettleTimeoutId),e.openSettleTimeoutId=null),e.openSettleCleanups.forEach(e=>e()),e.openSettleCleanups=[]},R=e=>{e.closeZeroRafId!==null&&(C.cancelAnimationFrame(e.closeZeroRafId),e.closeZeroRafId=null)},z=e=>{L(e),R(e)},B=e=>{let t=getComputedStyle(e.content),n=x(e.content)>0,r=ae(t);return r&&!n?`css-animation`:n?`css-transition`:r?`css-animation`:`none`},V=(e,t)=>{let n=e.content.style.getPropertyValue(`animation-name`);e.content.style.setProperty(`animation-name`,`none`);try{t()}finally{n?e.content.style.setProperty(`animation-name`,n):e.content.style.removeProperty(`animation-name`)}},ue=e=>{e.idleAnimationSuppressed||(e.idleAnimationName=e.content.style.getPropertyValue(`animation-name`)||null,e.idleAnimationSuppressed=!0,e.content.style.setProperty(`animation-name`,`none`))},de=e=>{e.idleAnimationSuppressed&&=(e.idleAnimationName?e.content.style.setProperty(`animation-name`,e.idleAnimationName):e.content.style.removeProperty(`animation-name`),e.idleAnimationName=null,!1)},H=e=>{e.content.removeAttribute(`hidden`)},U=e=>{D?e.content.setAttribute(`hidden`,`until-found`):e.content.hidden=!0,N(e)},W=new Set,G=(e,t)=>{L(e),!(!W.has(e.value)||e.presence.isExiting)&&(M(e),t===`css-animation`&&ue(e))},K=(e,t)=>{L(e);let n=ie(e.content),r=x(e.content),i=r||n;if(i>0){let n=typeof C.performance?.now==`function`?C.performance.now():Date.now(),a=e=>(typeof C.performance?.now==`function`?C.performance.now():Date.now())-n>=Math.max(0,e-5),o=n=>{if(n.target!==e.content)return;let o=`propertyName`in n?String(n.propertyName):``;if(r>0){if(!ne.has(o)||!a(r))return}else if(!a(i))return;G(e,t)},s=n=>{n.target===e.content&&(r>0||a(i)&&G(e,t))};e.content.addEventListener(`transitionend`,o),e.content.addEventListener(`animationend`,s),e.openSettleCleanups.push(()=>e.content.removeEventListener(`transitionend`,o)),e.openSettleCleanups.push(()=>e.content.removeEventListener(`animationend`,s)),e.openSettleTimeoutId=C.setTimeout(()=>{e.openSettleTimeoutId=null,G(e,t)},Math.ceil(i)+50);return}e.openSettleRafId=C.requestAnimationFrame(()=>{e.openSettleRafId=null,G(e,t)})},fe=e=>{R(e),e.closeZeroRafId=C.requestAnimationFrame(()=>{e.closeZeroRafId=null,!W.has(e.value)&&e.presence.isExiting&&N(e)})},q=e=>{e.el.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-orientation`,E),g(e.el,`data-disabled`,e.disabled),g(e.trigger,`data-disabled`,e.disabled),g(e.content,`data-disabled`,e.disabled),e.disabled?(e.trigger.setAttribute(`aria-disabled`,`true`),e.trigger instanceof HTMLButtonElement&&(e.trigger.disabled=!0)):(e.trigger.removeAttribute(`aria-disabled`),e.trigger instanceof HTMLButtonElement&&(e.trigger.disabled=!1))},J=(e,t)=>{e.trigger.setAttribute(`data-state`,t?`open`:`closed`),g(e.trigger,`data-panel-open`,t)},pe=e=>{let t=W.has(e.value);q(e),m(e.trigger,`expanded`,t),_(e.el,t),_(e.content,t),J(e,t),e.content.removeAttribute(`data-starting-style`),e.content.removeAttribute(`data-ending-style`);let n=B(e);t?(H(e),n===`css-animation`?V(e,()=>{P(e,{resetVarsToAuto:!0})}):P(e),K(e,n)):U(e)},me=e=>{let t=W.has(e.value),n=e.trigger.getAttribute(`aria-expanded`)===`true`;q(e),m(e.trigger,`expanded`,t),_(e.el,t),_(e.content,t),J(e,t);let r=B(e);if(t){if(R(e),H(e),n&&!e.presence.isExiting&&F(e))return;r===`css-animation`?V(e,()=>{P(e,{resetVarsToAuto:!0}),n||e.presence.enter()}):(P(e),n||e.presence.enter()),K(e,r);return}if(n){L(e),r===`css-animation`?V(e,()=>{P(e,{resetVarsToAuto:!0}),e.presence.exit()}):(P(e),e.presence.exit(),fe(e));return}z(e),e.content.removeAttribute(`data-starting-style`),e.content.removeAttribute(`data-ending-style`),U(e)},Y=e=>{let t=[],n=new Set;for(let r of e)if(!(n.has(r)||!b.some(e=>e.dataset.value===r))&&(n.add(r),t.push(r),!w&&t.length===1))break;return t},he=e=>e.size===W.size?[...e].some(e=>!W.has(e)):!0,ge=()=>{k.forEach(me)},_e=()=>{let e=[...W];n(l,`accordion:change`,{value:e}),se?.(e)},X=e=>{let t=Y(e);if(!w&&!le&&t.length===0&&W.size>0)return!1;let n=new Set(t);return he(n)?(k.forEach(e=>{W.has(e.value)!==n.has(e.value)&&de(e)}),W=n,ge(),_e(),!0):!1},ve=e=>(e.getAttribute(`dir`)??y.getAttribute(`dir`))===`rtl`||(getComputedStyle(e).direction||getComputedStyle(y).direction||l.ownerDocument?.documentElement.getAttribute(`dir`)||``)===`rtl`?`rtl`:`ltr`;y.setAttribute(`data-orientation`,E),g(y,`data-disabled`,!!T),b.forEach((e,n)=>{let i=e.dataset.value;if(!i)return;let a=s(l,e,`[data-slot="accordion-trigger"]`)[0]??null,o=s(l,e,`[data-slot="accordion-content"]`)[0]??null;if(!a||!o)return;let c=r(o,`accordion-content`),u=r(a,`accordion-trigger`);a.setAttribute(`aria-controls`,c),o.setAttribute(`aria-labelledby`,u),o.setAttribute(`role`,`region`);let f=!!T||h(e)||h(a),p;p={el:e,value:i,index:n,disabled:f,trigger:a,content:o,presence:t({element:o,onExitComplete:()=>{R(p),U(p)}}),sizeObserver:null,idleAnimationName:null,idleAnimationSuppressed:!1,openSettleRafId:null,openSettleTimeoutId:null,closeZeroRafId:null,openSettleCleanups:[],suppressClick:!1,suppressClickTimeoutId:null},typeof ResizeObserver<`u`&&(p.sizeObserver=new ResizeObserver(()=>{!W.has(p.value)||p.presence.isExiting||F(p)||P(p)}),p.sizeObserver.observe(o)),O.push(d(a,`click`,()=>{if(p.suppressClick){I(p);return}p.disabled||(W.has(p.value)?X([...W].filter(e=>e!==p.value)):X(w?[...W,p.value]:[p.value]))})),O.push(d(a,`keydown`,e=>{if(re.has(e.key)){if(p.disabled){e.preventDefault();return}e.preventDefault(),I(p),p.suppressClick=!0,p.suppressClickTimeoutId=C.setTimeout(()=>{p.suppressClick=!1,p.suppressClickTimeoutId=null},0),W.has(p.value)?X([...W].filter(e=>e!==p.value)):X(w?[...W,p.value]:[p.value])}})),D&&O.push(d(o,`beforematch`,()=>{X(w?[...W,p.value]:[p.value])})),k.push(p)});let Z=new Set(k.map(e=>e.value)),Q=u.defaultValue??oe(o(l,`defaultValue`)),ye=Y((Q?Array.isArray(Q)?Q:[Q]:[]).filter(e=>Z.has(e)));W=new Set(ye),k.forEach(pe),O.push(d(y,`keydown`,e=>{let t=e.target;if(!t)return;let n=k.find(e=>e.trigger===t);if(!n)return;let r=k.filter(e=>!e.disabled),i=r.findIndex(e=>e.trigger===t);if(i===-1)return;let a=r.length-1,o=-1,s=()=>{o=ce?i+1>a?0:i+1:Math.min(i+1,a)},c=()=>{o=ce?i===0?a:i-1:Math.max(i-1,0)};switch(e.key){case`ArrowDown`:E===`vertical`&&s();break;case`ArrowUp`:E===`vertical`&&c();break;case`ArrowRight`:E===`horizontal`&&(ve(n.trigger)===`rtl`?c():s());break;case`ArrowLeft`:E===`horizontal`&&(ve(n.trigger)===`rtl`?s():c());break;case`Home`:o=0;break;case`End`:o=a;break;default:return}o<0||(e.preventDefault(),r[o]?.trigger.focus())})),O.push(f(l,`accordion:set`,e=>{let t=e.detail?.value;t!==void 0&&X(Array.isArray(t)?t:[t])}));let $={expand:e=>{!Z.has(e)||W.has(e)||X(w?[...W,e]:[e])},collapse:e=>{!Z.has(e)||!W.has(e)||X([...W].filter(t=>t!==e))},toggle:e=>{Z.has(e)&&(W.has(e)?$.collapse(e):$.expand(e))},get value(){return[...W]},destroy:()=>{k.forEach(e=>{I(e),e.presence.cleanup(),z(e),e.sizeObserver?.disconnect(),e.sizeObserver=null}),O.forEach(e=>e()),O.length=0,e(l,S,$)}};return ee(l,S,$),$}function w(e=document){let t=[];for(let n of l(e,`accordion`))u(n,S)||t.push(C(n));return t}export{w as create,C as createAccordion};
1
+ import{clearRootBinding as e,createPresenceLifecycle as t,emit as n,ensureId as r,getDataBool as i,getDataEnum as a,getDataString as o,getOwnedElements as s,getParts as c,getRoots as l,hasRootBinding as u,on as d,onRoot as f,reuseRootBinding as p,setAria as m,setRootBinding as ee}from"@data-slot/core";const te=[`horizontal`,`vertical`],h=new Set([`all`,`height`,`width`,`block-size`,`inline-size`]),ne=new Set([`Enter`,` `]),g=e=>!!e&&(e.hasAttribute(`disabled`)||e.hasAttribute(`data-disabled`)||e.getAttribute(`aria-disabled`)===`true`),_=(e,t,n)=>{n?e.setAttribute(t,``):e.removeAttribute(t)},v=(e,t)=>{e.setAttribute(`data-state`,t?`open`:`closed`),t?(e.setAttribute(`data-open`,``),e.removeAttribute(`data-closed`)):(e.setAttribute(`data-closed`,``),e.removeAttribute(`data-open`))},y=e=>{let t=e.trim();return t?t.endsWith(`ms`)?Number.parseFloat(t.slice(0,-2))||0:t.endsWith(`s`)?(Number.parseFloat(t.slice(0,-1))||0)*1e3:Number.parseFloat(t)||0:0},b=(e,t)=>{let n=e.split(`,`),r=t.split(`,`),i=Math.max(n.length,r.length),a=0;for(let e=0;e<i;e+=1){let t=y(n[e]??n[n.length-1]??`0`),i=y(r[e]??r[r.length-1]??`0`);a=Math.max(a,t+i)}return a},re=e=>{let t=b(e.transitionDuration,e.transitionDelay),n=b(e.animationDuration,e.animationDelay);return Math.max(t,n)},ie=e=>b(e.animationDuration,e.animationDelay)<=0?!1:e.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`),x=(e,t)=>{let n=e.transitionProperty.split(`,`).map(e=>e.trim()),r=e.transitionDuration.split(`,`),i=e.transitionDelay.split(`,`),a=Math.max(n.length,r.length,i.length),o=0;for(let e=0;e<a;e+=1){if(!t(n[e]??n[n.length-1]??`all`))continue;let a=y(r[e]??r[r.length-1]??`0`),s=y(i[e]??i[i.length-1]??`0`);o=Math.max(o,a+s)}return o},S=e=>x(e,e=>h.has(e)),ae=e=>{if(e===void 0)return;let t=e.trim();if(!t.startsWith(`[`)||!t.endsWith(`]`))return e;try{let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>typeof e==`string`):e}catch{return e}},C=`@data-slot/accordion`;function w(l,u={}){let y=p(l,C,`[@data-slot/accordion] createAccordion() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(y)return y;let b=l,x=c(l,`accordion-item`);if(x.length===0)throw Error(`Accordion requires at least one accordion-item`);let w=l.ownerDocument?.defaultView??window,T=u.multiple??i(l,`multiple`)??!1,oe=u.onValueChange,E=u.disabled??i(l,`disabled`)??g(l),D=u.orientation??a(l,`orientation`,te)??`vertical`,O=u.loopFocus??i(l,`loopFocus`)??!0,k=u.hiddenUntilFound??i(l,`hiddenUntilFound`)??!1,se=u.collapsible??i(l,`collapsible`)??!0,A=[],j=[],M=(e,t,n)=>{e.content.style.setProperty(`--accordion-panel-height`,t),e.content.style.setProperty(`--accordion-panel-width`,n),e.content.style.setProperty(`--radix-accordion-content-height`,t),e.content.style.setProperty(`--radix-accordion-content-width`,n)},N=(e,t,n)=>{M(e,`${t}px`,`${n}px`)},P=e=>{M(e,`auto`,`auto`)},F=e=>{N(e,0,0)},I=e=>{N(e,e.content.scrollHeight,e.content.scrollWidth)},L=e=>{let t=e.content.style.getPropertyValue(`--accordion-panel-height`).trim(),n=e.content.style.getPropertyValue(`--accordion-panel-width`).trim();return t===`auto`&&n===`auto`},R=e=>{e.suppressClick=!1,e.suppressClickTimeoutId!==null&&(w.clearTimeout(e.suppressClickTimeoutId),e.suppressClickTimeoutId=null)},z=e=>{e.openSettleRafId!==null&&(w.cancelAnimationFrame(e.openSettleRafId),e.openSettleRafId=null),e.openSettleTimeoutId!==null&&(w.clearTimeout(e.openSettleTimeoutId),e.openSettleTimeoutId=null),e.openSettleCleanups.forEach(e=>e()),e.openSettleCleanups=[]},B=e=>{e.closeZeroRafId!==null&&(w.cancelAnimationFrame(e.closeZeroRafId),e.closeZeroRafId=null)},V=e=>{z(e),B(e)},H=e=>S(e)>0?`css-transition`:ie(e)?`css-animation`:`none`,U=(e,t)=>{let n=e.content.style.getPropertyValue(`animation-name`);e.content.style.setProperty(`animation-name`,`none`);try{P(e),I(e),t?.()}finally{n?e.content.style.setProperty(`animation-name`,n):e.content.style.removeProperty(`animation-name`)}},ce=e=>{e.idleAnimationSuppressed||(e.idleAnimationName=e.content.style.getPropertyValue(`animation-name`)||null,e.idleAnimationSuppressed=!0,e.content.style.setProperty(`animation-name`,`none`))},le=e=>{e.idleAnimationSuppressed&&=(e.idleAnimationName?e.content.style.setProperty(`animation-name`,e.idleAnimationName):e.content.style.removeProperty(`animation-name`),e.idleAnimationName=null,!1)},W=e=>{e.content.removeAttribute(`hidden`)},G=e=>{k?e.content.setAttribute(`hidden`,`until-found`):e.content.hidden=!0,F(e)},K=new Set,q=(e,t)=>{z(e),!(!K.has(e.value)||e.presence.isExiting)&&(P(e),t===`css-animation`&&ce(e))},J=(e,t,n)=>{z(e);let r=re(n),i=S(n),a=i||r;if(a>0){let n=typeof w.performance?.now==`function`?w.performance.now():Date.now(),r=e=>(typeof w.performance?.now==`function`?w.performance.now():Date.now())-n>=Math.max(0,e-5),o=n=>{if(n.target!==e.content)return;let o=`propertyName`in n?String(n.propertyName):``;if(i>0){if(!h.has(o)||!r(i))return}else if(!r(a))return;q(e,t)},s=n=>{n.target===e.content&&(i>0||r(a)&&q(e,t))};e.content.addEventListener(`transitionend`,o),e.content.addEventListener(`animationend`,s),e.openSettleCleanups.push(()=>e.content.removeEventListener(`transitionend`,o)),e.openSettleCleanups.push(()=>e.content.removeEventListener(`animationend`,s)),e.openSettleTimeoutId=w.setTimeout(()=>{e.openSettleTimeoutId=null,q(e,t)},Math.ceil(a)+50);return}e.openSettleRafId=w.requestAnimationFrame(()=>{e.openSettleRafId=null,q(e,t)})},ue=e=>{B(e),e.closeZeroRafId=w.requestAnimationFrame(()=>{e.closeZeroRafId=null,!K.has(e.value)&&e.presence.isExiting&&F(e)})},de=e=>{e.el.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-orientation`,D),_(e.el,`data-disabled`,e.disabled),_(e.trigger,`data-disabled`,e.disabled),_(e.content,`data-disabled`,e.disabled),e.disabled?(e.trigger.setAttribute(`aria-disabled`,`true`),e.trigger instanceof HTMLButtonElement&&(e.trigger.disabled=!0)):(e.trigger.removeAttribute(`aria-disabled`),e.trigger instanceof HTMLButtonElement&&(e.trigger.disabled=!1))},Y=(e,t)=>{e.trigger.setAttribute(`data-state`,t?`open`:`closed`),_(e.trigger,`data-panel-open`,t)},fe=e=>{let t=K.has(e.value);if(de(e),m(e.trigger,`expanded`,t),v(e.el,t),v(e.content,t),Y(e,t),e.content.removeAttribute(`data-starting-style`),e.content.removeAttribute(`data-ending-style`),t){W(e);let t=getComputedStyle(e.content),n=H(t);n===`css-animation`?U(e):I(e),J(e,n,t)}else G(e)},pe=(e,t)=>{let n=K.has(e.value),r=e.trigger.getAttribute(`aria-expanded`)===`true`;if(!(n===r&&(n?L(e):!e.presence.isExiting))){if(m(e.trigger,`expanded`,n),v(e.el,n),v(e.content,n),Y(e,n),n){B(e),W(e);let t=getComputedStyle(e.content),n=H(t);n===`css-animation`?U(e,()=>{r||e.presence.enter()}):(I(e),r||e.presence.enter()),J(e,n,t);return}if(r){z(e),H(getComputedStyle(e.content))===`css-animation`?U(e,()=>e.presence.exit()):(N(e,...t),e.presence.exit(),ue(e));return}V(e),e.content.removeAttribute(`data-starting-style`),e.content.removeAttribute(`data-ending-style`),G(e)}},me=e=>{let t=[],n=new Set;for(let r of e)if(!(n.has(r)||!x.some(e=>e.dataset.value===r))&&(n.add(r),t.push(r),!T&&t.length===1))break;return t},he=e=>e.size===K.size?[...e].some(e=>!K.has(e)):!0,ge=()=>{let e=[...K];n(l,`accordion:change`,{value:e}),oe?.(e)},X=e=>{let t=me(e);if(!T&&!se&&t.length===0&&K.size>0)return!1;let n=new Set(t);if(!he(n))return!1;let r=j.filter(e=>K.has(e.value)!==n.has(e.value)),i=new Map;for(let e of r)K.has(e.value)&&i.set(e,[e.content.scrollHeight,e.content.scrollWidth]);return r.forEach(le),K=n,j.forEach(e=>pe(e,i.get(e))),ge(),!0},_e=e=>(e.getAttribute(`dir`)??b.getAttribute(`dir`))===`rtl`||(getComputedStyle(e).direction||getComputedStyle(b).direction||l.ownerDocument?.documentElement.getAttribute(`dir`)||``)===`rtl`?`rtl`:`ltr`;b.setAttribute(`data-orientation`,D),_(b,`data-disabled`,!!E),x.forEach((e,n)=>{let i=e.dataset.value;if(!i)return;let a=s(l,e,`[data-slot="accordion-trigger"]`)[0]??null,o=s(l,e,`[data-slot="accordion-content"]`)[0]??null;if(!a||!o)return;let c=r(o,`accordion-content`),u=r(a,`accordion-trigger`);a.setAttribute(`aria-controls`,c),o.setAttribute(`aria-labelledby`,u),o.setAttribute(`role`,`region`);let f=!!E||g(e)||g(a),p;p={el:e,value:i,index:n,disabled:f,trigger:a,content:o,presence:t({element:o,onExitComplete:()=>{B(p),G(p)}}),sizeObserver:null,idleAnimationName:null,idleAnimationSuppressed:!1,openSettleRafId:null,openSettleTimeoutId:null,closeZeroRafId:null,openSettleCleanups:[],suppressClick:!1,suppressClickTimeoutId:null},typeof ResizeObserver<`u`&&(p.sizeObserver=new ResizeObserver(()=>{!K.has(p.value)||p.presence.isExiting||L(p)||I(p)}),p.sizeObserver.observe(o)),A.push(d(a,`click`,()=>{if(p.suppressClick){R(p);return}p.disabled||(K.has(p.value)?X([...K].filter(e=>e!==p.value)):X(T?[...K,p.value]:[p.value]))})),A.push(d(a,`keydown`,e=>{if(ne.has(e.key)){if(p.disabled){e.preventDefault();return}e.preventDefault(),R(p),p.suppressClick=!0,p.suppressClickTimeoutId=w.setTimeout(()=>{p.suppressClick=!1,p.suppressClickTimeoutId=null},0),K.has(p.value)?X([...K].filter(e=>e!==p.value)):X(T?[...K,p.value]:[p.value])}})),k&&A.push(d(o,`beforematch`,()=>{X(T?[...K,p.value]:[p.value])})),j.push(p)});let Z=new Set(j.map(e=>e.value)),Q=u.defaultValue??ae(o(l,`defaultValue`)),ve=me((Q?Array.isArray(Q)?Q:[Q]:[]).filter(e=>Z.has(e)));K=new Set(ve),j.forEach(fe),A.push(d(b,`keydown`,e=>{let t=e.target;if(!t)return;let n=j.find(e=>e.trigger===t);if(!n)return;let r=j.filter(e=>!e.disabled),i=r.findIndex(e=>e.trigger===t);if(i===-1)return;let a=r.length-1,o=-1,s=()=>{o=O?i+1>a?0:i+1:Math.min(i+1,a)},c=()=>{o=O?i===0?a:i-1:Math.max(i-1,0)};switch(e.key){case`ArrowDown`:D===`vertical`&&s();break;case`ArrowUp`:D===`vertical`&&c();break;case`ArrowRight`:D===`horizontal`&&(_e(n.trigger)===`rtl`?c():s());break;case`ArrowLeft`:D===`horizontal`&&(_e(n.trigger)===`rtl`?s():c());break;case`Home`:o=0;break;case`End`:o=a;break;default:return}o<0||(e.preventDefault(),r[o]?.trigger.focus())})),A.push(f(l,`accordion:set`,e=>{let t=e.detail?.value;t!==void 0&&X(Array.isArray(t)?t:[t])}));let $={expand:e=>{!Z.has(e)||K.has(e)||X(T?[...K,e]:[e])},collapse:e=>{!Z.has(e)||!K.has(e)||X([...K].filter(t=>t!==e))},toggle:e=>{Z.has(e)&&(K.has(e)?$.collapse(e):$.expand(e))},get value(){return[...K]},destroy:()=>{j.forEach(e=>{R(e),e.presence.cleanup(),V(e),e.sizeObserver?.disconnect(),e.sizeObserver=null}),A.forEach(e=>e()),A.length=0,e(l,C,$)}};return ee(l,C,$),$}function T(e=document){let t=[];for(let n of l(e,`accordion`))u(n,C)||t.push(w(n));return t}export{T as create,w as createAccordion};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-slot/accordion",
3
- "version": "0.2.167",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.cjs",
@@ -34,6 +34,6 @@
34
34
  ],
35
35
  "license": "MIT",
36
36
  "dependencies": {
37
- "@data-slot/core": "0.2.167"
37
+ "@data-slot/core": "1.0.1"
38
38
  }
39
39
  }