@data-slot/accordion 0.2.151 → 0.2.152

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
@@ -98,7 +98,7 @@ Options can also be set via data attributes on the root element. JS options take
98
98
  | Attribute | Type | Default | Description |
99
99
  | --- | --- | --- | --- |
100
100
  | `data-multiple` | `boolean` | `false` | Allow multiple items open at once |
101
- | `data-default-value` | `string` | none | Initially expanded item |
101
+ | `data-default-value` | `string` | none | Initially expanded item, or a JSON array string for multiple defaults |
102
102
  | `data-disabled` | `boolean` | `false` | Disable the entire accordion |
103
103
  | `data-orientation` | `"horizontal" \| "vertical"` | `"vertical"` | Controls roving-focus arrow keys |
104
104
  | `data-loop-focus` | `boolean` | `true` | Wrap roving focus at the ends |
@@ -118,6 +118,18 @@ Boolean attributes: present or `"true"` = true, `"false"` = false, absent = defa
118
118
  </div>
119
119
  ```
120
120
 
121
+ For multiple default items in HTML, encode the value as JSON:
122
+
123
+ ```html
124
+ <div
125
+ data-slot="accordion"
126
+ data-multiple
127
+ data-default-value='["one","two"]'
128
+ >
129
+ ...
130
+ </div>
131
+ ```
132
+
121
133
  ### Controller
122
134
 
123
135
  | Method/Property | Description |
@@ -167,6 +179,8 @@ The content element exposes size variables for height or width transitions:
167
179
  | --- | --- |
168
180
  | `--accordion-panel-height` | Panel height (`auto` at rest, measured px during transitions, `0px` when closed) |
169
181
  | `--accordion-panel-width` | Panel width (`auto` at rest, measured px during transitions, `0px` when closed) |
182
+ | `--radix-accordion-content-height` | Compatibility alias for Tailwind/Radix accordion keyframes |
183
+ | `--radix-accordion-content-width` | Compatibility alias for width-based integrations |
170
184
 
171
185
  ### CSS Example
172
186
 
@@ -237,9 +251,12 @@ The content element exposes size variables for height or width transitions:
237
251
  </button>
238
252
  <div
239
253
  data-slot="accordion-content"
240
- class="h-[var(--accordion-panel-height)] overflow-hidden text-sm transition-[height] ease-out data-[starting-style]:h-0"
254
+ class="overflow-hidden text-sm data-open:animate-accordion-down data-closed:animate-accordion-up"
241
255
  >
242
- <div data-slot="accordion-content-inner" class="px-4 pb-4 pt-0">
256
+ <div
257
+ data-slot="accordion-content-inner"
258
+ class="h-(--accordion-panel-height) px-4 pb-4 pt-0 data-ending-style:h-0 data-starting-style:h-0"
259
+ >
243
260
  Content
244
261
  </div>
245
262
  </div>
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,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},d=e=>u(e,e=>n.has(e)),f=`@data-slot/accordion`;function p(s,c={}){let u=(0,e.reuseRootBinding)(s,f,`[@data-slot/accordion] createAccordion() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(u)return u;let p=s,m=(0,e.getParts)(s,`accordion-item`);if(m.length===0)throw Error(`Accordion requires at least one accordion-item`);let h=s.ownerDocument?.defaultView??window,g=c.multiple??(0,e.getDataBool)(s,`multiple`)??!1,_=c.onValueChange,v=c.disabled??(0,e.getDataBool)(s,`disabled`)??i(s),y=c.orientation??(0,e.getDataEnum)(s,`orientation`,t)??`vertical`,b=c.loopFocus??(0,e.getDataBool)(s,`loopFocus`)??!0,x=c.hiddenUntilFound??(0,e.getDataBool)(s,`hiddenUntilFound`)??!1,S=c.collapsible??(0,e.getDataBool)(s,`collapsible`)??!0,C=[],w=[],T=(e,t,n)=>{e.content.style.setProperty(`--accordion-panel-height`,t),e.content.style.setProperty(`--accordion-panel-width`,n)},E=(e,t,n)=>{T(e,`${t}px`,`${n}px`)},D=e=>{T(e,`auto`,`auto`)},O=e=>{E(e,0,0)},k=e=>{E(e,e.content.scrollHeight,e.content.scrollWidth)},A=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`},j=e=>{e.suppressClick=!1,e.suppressClickTimeoutId!==null&&(h.clearTimeout(e.suppressClickTimeoutId),e.suppressClickTimeoutId=null)},M=e=>{e.openSettleRafId!==null&&(h.cancelAnimationFrame(e.openSettleRafId),e.openSettleRafId=null),e.openSettleTimeoutId!==null&&(h.clearTimeout(e.openSettleTimeoutId),e.openSettleTimeoutId=null),e.openSettleCleanups.forEach(e=>e()),e.openSettleCleanups=[]},N=e=>{e.closeZeroRafId!==null&&(h.cancelAnimationFrame(e.closeZeroRafId),e.closeZeroRafId=null)},P=e=>{M(e),N(e)},F=e=>{e.content.removeAttribute(`hidden`)},I=e=>{x?e.content.setAttribute(`hidden`,`until-found`):e.content.hidden=!0,O(e)},L=new Set,R=e=>{M(e),!(!L.has(e.value)||e.presence.isExiting)&&D(e)},z=e=>{M(e);let t=l(e.content),r=d(e.content),i=r||t;if(i>0){let t=typeof h.performance?.now==`function`?h.performance.now():Date.now(),a=e=>(typeof h.performance?.now==`function`?h.performance.now():Date.now())-t>=Math.max(0,e-5),o=t=>{if(t.target!==e.content)return;let o=`propertyName`in t?String(t.propertyName):``;if(r>0){if(!n.has(o)||!a(r))return}else if(!a(i))return;R(e)},s=t=>{t.target===e.content&&(r>0||a(i)&&R(e))};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=h.setTimeout(()=>{e.openSettleTimeoutId=null,R(e)},Math.ceil(i)+50);return}e.openSettleRafId=h.requestAnimationFrame(()=>{e.openSettleRafId=null,R(e)})},B=e=>{N(e),e.closeZeroRafId=h.requestAnimationFrame(()=>{e.closeZeroRafId=null,!L.has(e.value)&&e.presence.isExiting&&O(e)})},V=e=>{e.el.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-orientation`,y),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))},H=(e,t)=>{e.trigger.setAttribute(`data-state`,t?`open`:`closed`),a(e.trigger,`data-panel-open`,t)},U=t=>{let n=L.has(t.value);V(t),(0,e.setAria)(t.trigger,`expanded`,n),o(t.el,n),o(t.content,n),H(t,n),t.content.removeAttribute(`data-starting-style`),t.content.removeAttribute(`data-ending-style`),n?(F(t),k(t),z(t)):I(t)},W=t=>{let n=L.has(t.value),r=t.trigger.getAttribute(`aria-expanded`)===`true`;if(V(t),(0,e.setAria)(t.trigger,`expanded`,n),o(t.el,n),o(t.content,n),H(t,n),n){N(t),F(t),k(t),r||t.presence.enter(),z(t);return}if(r){M(t),k(t),t.presence.exit(),B(t);return}P(t),t.content.removeAttribute(`data-starting-style`),t.content.removeAttribute(`data-ending-style`),I(t)},G=e=>{let t=[],n=new Set;for(let r of e)if(!(n.has(r)||!m.some(e=>e.dataset.value===r))&&(n.add(r),t.push(r),!g&&t.length===1))break;return t},K=e=>e.size===L.size?[...e].some(e=>!L.has(e)):!0,q=()=>{w.forEach(W)},J=()=>{let t=[...L];(0,e.emit)(s,`accordion:change`,{value:t}),_?.(t)},Y=e=>{let t=G(e);if(!g&&!S&&t.length===0&&L.size>0)return!1;let n=new Set(t);return K(n)?(L=n,q(),J(),!0):!1},X=e=>(e.getAttribute(`dir`)??p.getAttribute(`dir`))===`rtl`||(getComputedStyle(e).direction||getComputedStyle(p).direction||s.ownerDocument?.documentElement.getAttribute(`dir`)||``)===`rtl`?`rtl`:`ltr`;p.setAttribute(`data-orientation`,y),a(p,`data-disabled`,!!v),m.forEach((t,n)=>{let a=t.dataset.value;if(!a)return;let o=(0,e.getPart)(t,`accordion-trigger`),s=(0,e.getPart)(t,`accordion-content`);if(!o||!s)return;let c=(0,e.ensureId)(s,`accordion-content`),l=(0,e.ensureId)(o,`accordion-trigger`);o.setAttribute(`aria-controls`,c),s.setAttribute(`aria-labelledby`,l),s.setAttribute(`role`,`region`);let u=!!v||i(t)||i(o),d;d={el:t,value:a,index:n,disabled:u,trigger:o,content:s,presence:(0,e.createPresenceLifecycle)({element:s,onExitComplete:()=>{N(d),I(d)}}),sizeObserver:null,openSettleRafId:null,openSettleTimeoutId:null,closeZeroRafId:null,openSettleCleanups:[],suppressClick:!1,suppressClickTimeoutId:null},typeof ResizeObserver<`u`&&(d.sizeObserver=new ResizeObserver(()=>{!L.has(d.value)||d.presence.isExiting||A(d)||k(d)}),d.sizeObserver.observe(s)),C.push((0,e.on)(o,`click`,()=>{if(d.suppressClick){j(d);return}d.disabled||(L.has(d.value)?Y([...L].filter(e=>e!==d.value)):Y(g?[...L,d.value]:[d.value]))})),C.push((0,e.on)(o,`keydown`,e=>{if(r.has(e.key)){if(d.disabled){e.preventDefault();return}e.preventDefault(),j(d),d.suppressClick=!0,d.suppressClickTimeoutId=h.setTimeout(()=>{d.suppressClick=!1,d.suppressClickTimeoutId=null},0),L.has(d.value)?Y([...L].filter(e=>e!==d.value)):Y(g?[...L,d.value]:[d.value])}})),x&&C.push((0,e.on)(s,`beforematch`,()=>{Y(g?[...L,d.value]:[d.value])})),w.push(d)});let Z=new Set(w.map(e=>e.value)),Q=c.defaultValue??(0,e.getDataString)(s,`defaultValue`),ee=G((Q?Array.isArray(Q)?Q:[Q]:[]).filter(e=>Z.has(e)));L=new Set(ee),w.forEach(U),C.push((0,e.on)(p,`keydown`,e=>{let t=e.target;if(!t)return;let n=w.find(e=>e.trigger===t);if(!n)return;let r=w.filter(e=>!e.disabled),i=r.findIndex(e=>e.trigger===t);if(i===-1)return;let a=r.length-1,o=-1,s=()=>{o=b?i+1>a?0:i+1:Math.min(i+1,a)},c=()=>{o=b?i===0?a:i-1:Math.max(i-1,0)};switch(e.key){case`ArrowDown`:y===`vertical`&&s();break;case`ArrowUp`:y===`vertical`&&c();break;case`ArrowRight`:y===`horizontal`&&(X(n.trigger)===`rtl`?c():s());break;case`ArrowLeft`:y===`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())})),C.push((0,e.on)(s,`accordion:set`,e=>{let t=e.detail?.value;t!==void 0&&Y(Array.isArray(t)?t:[t])}));let $={expand:e=>{!Z.has(e)||L.has(e)||Y(g?[...L,e]:[e])},collapse:e=>{!Z.has(e)||!L.has(e)||Y([...L].filter(t=>t!==e))},toggle:e=>{Z.has(e)&&(L.has(e)?$.collapse(e):$.expand(e))},get value(){return[...L]},destroy:()=>{w.forEach(e=>{j(e),e.presence.cleanup(),P(e),e.sizeObserver?.disconnect(),e.sizeObserver=null}),C.forEach(e=>e()),C.length=0,(0,e.clearRootBinding)(s,f,$)}};return(0,e.setRootBinding)(s,f,$),$}function m(t=document){let n=[];for(let r of(0,e.getRoots)(t,`accordion`))(0,e.hasRootBinding)(r,f)||n.push(p(r));return n}exports.create=m,exports.createAccordion=p;
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)),ee=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}},p=`@data-slot/accordion`;function m(s,c={}){let d=(0,e.reuseRootBinding)(s,p,`[@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 m=s,h=(0,e.getParts)(s,`accordion-item`);if(h.length===0)throw Error(`Accordion requires at least one accordion-item`);let g=s.ownerDocument?.defaultView??window,_=c.multiple??(0,e.getDataBool)(s,`multiple`)??!1,v=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&&(g.clearTimeout(e.suppressClickTimeoutId),e.suppressClickTimeoutId=null)},N=e=>{e.openSettleRafId!==null&&(g.cancelAnimationFrame(e.openSettleRafId),e.openSettleRafId=null),e.openSettleTimeoutId!==null&&(g.clearTimeout(e.openSettleTimeoutId),e.openSettleTimeoutId=null),e.openSettleCleanups.forEach(e=>e()),e.openSettleCleanups=[]},P=e=>{e.closeZeroRafId!==null&&(g.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.content.removeAttribute(`hidden`)},z=e=>{S?e.content.setAttribute(`hidden`,`until-found`):e.content.hidden=!0,k(e)},B=new Set,V=e=>{N(e),!(!B.has(e.value)||e.presence.isExiting)&&O(e)},H=e=>{N(e);let t=l(e.content),r=f(e.content),i=r||t;if(i>0){let t=typeof g.performance?.now==`function`?g.performance.now():Date.now(),a=e=>(typeof g.performance?.now==`function`?g.performance.now():Date.now())-t>=Math.max(0,e-5),o=t=>{if(t.target!==e.content)return;let o=`propertyName`in t?String(t.propertyName):``;if(r>0){if(!n.has(o)||!a(r))return}else if(!a(i))return;V(e)},s=t=>{t.target===e.content&&(r>0||a(i)&&V(e))};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=g.setTimeout(()=>{e.openSettleTimeoutId=null,V(e)},Math.ceil(i)+50);return}e.openSettleRafId=g.requestAnimationFrame(()=>{e.openSettleRafId=null,V(e)})},U=e=>{P(e),e.closeZeroRafId=g.requestAnimationFrame(()=>{e.closeZeroRafId=null,!B.has(e.value)&&e.presence.isExiting&&k(e)})},W=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))},G=(e,t)=>{e.trigger.setAttribute(`data-state`,t?`open`:`closed`),a(e.trigger,`data-panel-open`,t)},K=t=>{let n=B.has(t.value);W(t),(0,e.setAria)(t.trigger,`expanded`,n),o(t.el,n),o(t.content,n),G(t,n),t.content.removeAttribute(`data-starting-style`),t.content.removeAttribute(`data-ending-style`);let r=I(t);n?(R(t),r===`css-animation`?L(t,()=>{A(t,{resetVarsToAuto:!0})}):A(t),H(t)):z(t)},q=t=>{let n=B.has(t.value),r=t.trigger.getAttribute(`aria-expanded`)===`true`;W(t),(0,e.setAria)(t.trigger,`expanded`,n),o(t.el,n),o(t.content,n),G(t,n);let i=I(t);if(n){if(P(t),R(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()),H(t);return}if(r){N(t),i===`css-animation`?L(t,()=>{A(t,{resetVarsToAuto:!0}),t.presence.exit()}):(A(t),t.presence.exit(),U(t));return}F(t),t.content.removeAttribute(`data-starting-style`),t.content.removeAttribute(`data-ending-style`),z(t)},J=e=>{let t=[],n=new Set;for(let r of e)if(!(n.has(r)||!h.some(e=>e.dataset.value===r))&&(n.add(r),t.push(r),!_&&t.length===1))break;return t},te=e=>e.size===B.size?[...e].some(e=>!B.has(e)):!0,ne=()=>{T.forEach(q)},re=()=>{let t=[...B];(0,e.emit)(s,`accordion:change`,{value:t}),v?.(t)},Y=e=>{let t=J(e);if(!_&&!C&&t.length===0&&B.size>0)return!1;let n=new Set(t);return te(n)?(B=n,ne(),re(),!0):!1},X=e=>(e.getAttribute(`dir`)??m.getAttribute(`dir`))===`rtl`||(getComputedStyle(e).direction||getComputedStyle(m).direction||s.ownerDocument?.documentElement.getAttribute(`dir`)||``)===`rtl`?`rtl`:`ltr`;m.setAttribute(`data-orientation`,b),a(m,`data-disabled`,!!y),h.forEach((t,n)=>{let a=t.dataset.value;if(!a)return;let o=(0,e.getPart)(t,`accordion-trigger`),s=(0,e.getPart)(t,`accordion-content`);if(!o||!s)return;let c=(0,e.ensureId)(s,`accordion-content`),l=(0,e.ensureId)(o,`accordion-trigger`);o.setAttribute(`aria-controls`,c),s.setAttribute(`aria-labelledby`,l),s.setAttribute(`role`,`region`);let u=!!y||i(t)||i(o),d;d={el:t,value:a,index:n,disabled:u,trigger:o,content:s,presence:(0,e.createPresenceLifecycle)({element:s,onExitComplete:()=>{P(d),z(d)}}),sizeObserver:null,openSettleRafId:null,openSettleTimeoutId:null,closeZeroRafId:null,openSettleCleanups:[],suppressClick:!1,suppressClickTimeoutId:null},typeof ResizeObserver<`u`&&(d.sizeObserver=new ResizeObserver(()=>{!B.has(d.value)||d.presence.isExiting||j(d)||A(d)}),d.sizeObserver.observe(s)),w.push((0,e.on)(o,`click`,()=>{if(d.suppressClick){M(d);return}d.disabled||(B.has(d.value)?Y([...B].filter(e=>e!==d.value)):Y(_?[...B,d.value]:[d.value]))})),w.push((0,e.on)(o,`keydown`,e=>{if(r.has(e.key)){if(d.disabled){e.preventDefault();return}e.preventDefault(),M(d),d.suppressClick=!0,d.suppressClickTimeoutId=g.setTimeout(()=>{d.suppressClick=!1,d.suppressClickTimeoutId=null},0),B.has(d.value)?Y([...B].filter(e=>e!==d.value)):Y(_?[...B,d.value]:[d.value])}})),S&&w.push((0,e.on)(s,`beforematch`,()=>{Y(_?[...B,d.value]:[d.value])})),T.push(d)});let Z=new Set(T.map(e=>e.value)),Q=c.defaultValue??ee((0,e.getDataString)(s,`defaultValue`)),ie=J((Q?Array.isArray(Q)?Q:[Q]:[]).filter(e=>Z.has(e)));B=new Set(ie),T.forEach(K),w.push((0,e.on)(m,`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.on)(s,`accordion:set`,e=>{let t=e.detail?.value;t!==void 0&&Y(Array.isArray(t)?t:[t])}));let $={expand:e=>{!Z.has(e)||B.has(e)||Y(_?[...B,e]:[e])},collapse:e=>{!Z.has(e)||!B.has(e)||Y([...B].filter(t=>t!==e))},toggle:e=>{Z.has(e)&&(B.has(e)?$.collapse(e):$.expand(e))},get value(){return[...B]},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,p,$)}};return(0,e.setRootBinding)(s,p,$),$}function h(t=document){let n=[];for(let r of(0,e.getRoots)(t,`accordion`))(0,e.hasRootBinding)(r,p)||n.push(m(r));return n}exports.create=h,exports.createAccordion=m;
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,getPart as s,getParts as c,getRoots as l,hasRootBinding as u,on as d,reuseRootBinding as f,setAria as p,setRootBinding as m}from"@data-slot/core";const ee=[`horizontal`,`vertical`],h=new Set([`all`,`height`,`width`,`block-size`,`inline-size`]),te=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},ne=e=>{let t=getComputedStyle(e),n=b(t.transitionDuration,t.transitionDelay),r=b(t.animationDuration,t.animationDelay);return Math.max(n,r)},x=(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=y(i[e]??i[i.length-1]??`0`),o=y(a[e]??a[a.length-1]??`0`);s=Math.max(s,n+o)}return s},re=e=>x(e,e=>h.has(e)),S=`@data-slot/accordion`;function C(l,u={}){let y=f(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(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 C=l.ownerDocument?.defaultView??window,w=u.multiple??i(l,`multiple`)??!1,ie=u.onValueChange,T=u.disabled??i(l,`disabled`)??g(l),E=u.orientation??a(l,`orientation`,ee)??`vertical`,D=u.loopFocus??i(l,`loopFocus`)??!0,O=u.hiddenUntilFound??i(l,`hiddenUntilFound`)??!1,ae=u.collapsible??i(l,`collapsible`)??!0,k=[],A=[],j=(e,t,n)=>{e.content.style.setProperty(`--accordion-panel-height`,t),e.content.style.setProperty(`--accordion-panel-width`,n)},M=(e,t,n)=>{j(e,`${t}px`,`${n}px`)},N=e=>{j(e,`auto`,`auto`)},P=e=>{M(e,0,0)},F=e=>{M(e,e.content.scrollHeight,e.content.scrollWidth)},I=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`},L=e=>{e.suppressClick=!1,e.suppressClickTimeoutId!==null&&(C.clearTimeout(e.suppressClickTimeoutId),e.suppressClickTimeoutId=null)},R=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=[]},z=e=>{e.closeZeroRafId!==null&&(C.cancelAnimationFrame(e.closeZeroRafId),e.closeZeroRafId=null)},B=e=>{R(e),z(e)},V=e=>{e.content.removeAttribute(`hidden`)},H=e=>{O?e.content.setAttribute(`hidden`,`until-found`):e.content.hidden=!0,P(e)},U=new Set,W=e=>{R(e),!(!U.has(e.value)||e.presence.isExiting)&&N(e)},G=e=>{R(e);let t=ne(e.content),n=re(e.content),r=n||t;if(r>0){let t=typeof C.performance?.now==`function`?C.performance.now():Date.now(),i=e=>(typeof C.performance?.now==`function`?C.performance.now():Date.now())-t>=Math.max(0,e-5),a=t=>{if(t.target!==e.content)return;let a=`propertyName`in t?String(t.propertyName):``;if(n>0){if(!h.has(a)||!i(n))return}else if(!i(r))return;W(e)},o=t=>{t.target===e.content&&(n>0||i(r)&&W(e))};e.content.addEventListener(`transitionend`,a),e.content.addEventListener(`animationend`,o),e.openSettleCleanups.push(()=>e.content.removeEventListener(`transitionend`,a)),e.openSettleCleanups.push(()=>e.content.removeEventListener(`animationend`,o)),e.openSettleTimeoutId=C.setTimeout(()=>{e.openSettleTimeoutId=null,W(e)},Math.ceil(r)+50);return}e.openSettleRafId=C.requestAnimationFrame(()=>{e.openSettleRafId=null,W(e)})},oe=e=>{z(e),e.closeZeroRafId=C.requestAnimationFrame(()=>{e.closeZeroRafId=null,!U.has(e.value)&&e.presence.isExiting&&P(e)})},K=e=>{e.el.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-orientation`,E),_(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))},q=(e,t)=>{e.trigger.setAttribute(`data-state`,t?`open`:`closed`),_(e.trigger,`data-panel-open`,t)},se=e=>{let t=U.has(e.value);K(e),p(e.trigger,`expanded`,t),v(e.el,t),v(e.content,t),q(e,t),e.content.removeAttribute(`data-starting-style`),e.content.removeAttribute(`data-ending-style`),t?(V(e),F(e),G(e)):H(e)},ce=e=>{let t=U.has(e.value),n=e.trigger.getAttribute(`aria-expanded`)===`true`;if(K(e),p(e.trigger,`expanded`,t),v(e.el,t),v(e.content,t),q(e,t),t){z(e),V(e),F(e),n||e.presence.enter(),G(e);return}if(n){R(e),F(e),e.presence.exit(),oe(e);return}B(e),e.content.removeAttribute(`data-starting-style`),e.content.removeAttribute(`data-ending-style`),H(e)},J=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),!w&&t.length===1))break;return t},le=e=>e.size===U.size?[...e].some(e=>!U.has(e)):!0,ue=()=>{A.forEach(ce)},de=()=>{let e=[...U];n(l,`accordion:change`,{value:e}),ie?.(e)},Y=e=>{let t=J(e);if(!w&&!ae&&t.length===0&&U.size>0)return!1;let n=new Set(t);return le(n)?(U=n,ue(),de(),!0):!1},X=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`,E),_(b,`data-disabled`,!!T),x.forEach((e,n)=>{let i=e.dataset.value;if(!i)return;let a=s(e,`accordion-trigger`),o=s(e,`accordion-content`);if(!a||!o)return;let c=r(o,`accordion-content`),l=r(a,`accordion-trigger`);a.setAttribute(`aria-controls`,c),o.setAttribute(`aria-labelledby`,l),o.setAttribute(`role`,`region`);let u=!!T||g(e)||g(a),f;f={el:e,value:i,index:n,disabled:u,trigger:a,content:o,presence:t({element:o,onExitComplete:()=>{z(f),H(f)}}),sizeObserver:null,openSettleRafId:null,openSettleTimeoutId:null,closeZeroRafId:null,openSettleCleanups:[],suppressClick:!1,suppressClickTimeoutId:null},typeof ResizeObserver<`u`&&(f.sizeObserver=new ResizeObserver(()=>{!U.has(f.value)||f.presence.isExiting||I(f)||F(f)}),f.sizeObserver.observe(o)),k.push(d(a,`click`,()=>{if(f.suppressClick){L(f);return}f.disabled||(U.has(f.value)?Y([...U].filter(e=>e!==f.value)):Y(w?[...U,f.value]:[f.value]))})),k.push(d(a,`keydown`,e=>{if(te.has(e.key)){if(f.disabled){e.preventDefault();return}e.preventDefault(),L(f),f.suppressClick=!0,f.suppressClickTimeoutId=C.setTimeout(()=>{f.suppressClick=!1,f.suppressClickTimeoutId=null},0),U.has(f.value)?Y([...U].filter(e=>e!==f.value)):Y(w?[...U,f.value]:[f.value])}})),O&&k.push(d(o,`beforematch`,()=>{Y(w?[...U,f.value]:[f.value])})),A.push(f)});let Z=new Set(A.map(e=>e.value)),Q=u.defaultValue??o(l,`defaultValue`),fe=J((Q?Array.isArray(Q)?Q:[Q]:[]).filter(e=>Z.has(e)));U=new Set(fe),A.forEach(se),k.push(d(b,`keydown`,e=>{let t=e.target;if(!t)return;let n=A.find(e=>e.trigger===t);if(!n)return;let r=A.filter(e=>!e.disabled),i=r.findIndex(e=>e.trigger===t);if(i===-1)return;let a=r.length-1,o=-1,s=()=>{o=D?i+1>a?0:i+1:Math.min(i+1,a)},c=()=>{o=D?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`&&(X(n.trigger)===`rtl`?c():s());break;case`ArrowLeft`:E===`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())})),k.push(d(l,`accordion:set`,e=>{let t=e.detail?.value;t!==void 0&&Y(Array.isArray(t)?t:[t])}));let $={expand:e=>{!Z.has(e)||U.has(e)||Y(w?[...U,e]:[e])},collapse:e=>{!Z.has(e)||!U.has(e)||Y([...U].filter(t=>t!==e))},toggle:e=>{Z.has(e)&&(U.has(e)?$.collapse(e):$.expand(e))},get value(){return[...U]},destroy:()=>{A.forEach(e=>{L(e),e.presence.cleanup(),B(e),e.sizeObserver?.disconnect(),e.sizeObserver=null}),k.forEach(e=>e()),k.length=0,e(l,S,$)}};return m(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,getPart as s,getParts as c,getRoots as l,hasRootBinding as u,on as d,reuseRootBinding as f,setAria as ee,setRootBinding as te}from"@data-slot/core";const ne=[`horizontal`,`vertical`],p=new Set([`all`,`height`,`width`,`block-size`,`inline-size`]),re=new Set([`Enter`,` `]),m=e=>!!e&&(e.hasAttribute(`disabled`)||e.hasAttribute(`data-disabled`)||e.getAttribute(`aria-disabled`)===`true`),h=(e,t,n)=>{n?e.setAttribute(t,``):e.removeAttribute(t)},g=(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`))},_=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},v=(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=_(n[e]??n[n.length-1]??`0`),i=_(r[e]??r[r.length-1]??`0`);a=Math.max(a,t+i)}return a},ie=e=>{let t=getComputedStyle(e),n=v(t.transitionDuration,t.transitionDelay),r=v(t.animationDuration,t.animationDelay);return Math.max(n,r)},ae=e=>v(e.animationDuration,e.animationDelay)<=0?!1:e.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`),y=(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=_(i[e]??i[i.length-1]??`0`),o=_(a[e]??a[a.length-1]??`0`);s=Math.max(s,n+o)}return s},b=e=>y(e,e=>p.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}},x=`@data-slot/accordion`;function S(l,u={}){let _=f(l,x,`[@data-slot/accordion] createAccordion() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(_)return _;let v=l,y=c(l,`accordion-item`);if(y.length===0)throw Error(`Accordion requires at least one accordion-item`);let S=l.ownerDocument?.defaultView??window,C=u.multiple??i(l,`multiple`)??!1,se=u.onValueChange,w=u.disabled??i(l,`disabled`)??m(l),T=u.orientation??a(l,`orientation`,ne)??`vertical`,E=u.loopFocus??i(l,`loopFocus`)??!0,ce=u.hiddenUntilFound??i(l,`hiddenUntilFound`)??!1,le=u.collapsible??i(l,`collapsible`)??!0,D=[],O=[],k=(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)},A=(e,t,n)=>{k(e,`${t}px`,`${n}px`)},j=e=>{k(e,`auto`,`auto`)},M=e=>{A(e,0,0)},N=(e,{resetVarsToAuto:t=!1}={})=>{t&&j(e),A(e,e.content.scrollHeight,e.content.scrollWidth)},P=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`},F=e=>{e.suppressClick=!1,e.suppressClickTimeoutId!==null&&(S.clearTimeout(e.suppressClickTimeoutId),e.suppressClickTimeoutId=null)},I=e=>{e.openSettleRafId!==null&&(S.cancelAnimationFrame(e.openSettleRafId),e.openSettleRafId=null),e.openSettleTimeoutId!==null&&(S.clearTimeout(e.openSettleTimeoutId),e.openSettleTimeoutId=null),e.openSettleCleanups.forEach(e=>e()),e.openSettleCleanups=[]},L=e=>{e.closeZeroRafId!==null&&(S.cancelAnimationFrame(e.closeZeroRafId),e.closeZeroRafId=null)},R=e=>{I(e),L(e)},z=e=>{let t=getComputedStyle(e.content),n=b(e.content)>0,r=ae(t);return r&&!n?`css-animation`:n?`css-transition`:r?`css-animation`:`none`},B=(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`)}},V=e=>{e.content.removeAttribute(`hidden`)},H=e=>{ce?e.content.setAttribute(`hidden`,`until-found`):e.content.hidden=!0,M(e)},U=new Set,W=e=>{I(e),!(!U.has(e.value)||e.presence.isExiting)&&j(e)},G=e=>{I(e);let t=ie(e.content),n=b(e.content),r=n||t;if(r>0){let t=typeof S.performance?.now==`function`?S.performance.now():Date.now(),i=e=>(typeof S.performance?.now==`function`?S.performance.now():Date.now())-t>=Math.max(0,e-5),a=t=>{if(t.target!==e.content)return;let a=`propertyName`in t?String(t.propertyName):``;if(n>0){if(!p.has(a)||!i(n))return}else if(!i(r))return;W(e)},o=t=>{t.target===e.content&&(n>0||i(r)&&W(e))};e.content.addEventListener(`transitionend`,a),e.content.addEventListener(`animationend`,o),e.openSettleCleanups.push(()=>e.content.removeEventListener(`transitionend`,a)),e.openSettleCleanups.push(()=>e.content.removeEventListener(`animationend`,o)),e.openSettleTimeoutId=S.setTimeout(()=>{e.openSettleTimeoutId=null,W(e)},Math.ceil(r)+50);return}e.openSettleRafId=S.requestAnimationFrame(()=>{e.openSettleRafId=null,W(e)})},ue=e=>{L(e),e.closeZeroRafId=S.requestAnimationFrame(()=>{e.closeZeroRafId=null,!U.has(e.value)&&e.presence.isExiting&&M(e)})},K=e=>{e.el.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-orientation`,T),h(e.el,`data-disabled`,e.disabled),h(e.trigger,`data-disabled`,e.disabled),h(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`),h(e.trigger,`data-panel-open`,t)},de=e=>{let t=U.has(e.value);K(e),ee(e.trigger,`expanded`,t),g(e.el,t),g(e.content,t),q(e,t),e.content.removeAttribute(`data-starting-style`),e.content.removeAttribute(`data-ending-style`);let n=z(e);t?(V(e),n===`css-animation`?B(e,()=>{N(e,{resetVarsToAuto:!0})}):N(e),G(e)):H(e)},fe=e=>{let t=U.has(e.value),n=e.trigger.getAttribute(`aria-expanded`)===`true`;K(e),ee(e.trigger,`expanded`,t),g(e.el,t),g(e.content,t),q(e,t);let r=z(e);if(t){if(L(e),V(e),n&&!e.presence.isExiting&&P(e))return;r===`css-animation`?B(e,()=>{N(e,{resetVarsToAuto:!0}),n||e.presence.enter()}):(N(e),n||e.presence.enter()),G(e);return}if(n){I(e),r===`css-animation`?B(e,()=>{N(e,{resetVarsToAuto:!0}),e.presence.exit()}):(N(e),e.presence.exit(),ue(e));return}R(e),e.content.removeAttribute(`data-starting-style`),e.content.removeAttribute(`data-ending-style`),H(e)},J=e=>{let t=[],n=new Set;for(let r of e)if(!(n.has(r)||!y.some(e=>e.dataset.value===r))&&(n.add(r),t.push(r),!C&&t.length===1))break;return t},pe=e=>e.size===U.size?[...e].some(e=>!U.has(e)):!0,me=()=>{O.forEach(fe)},he=()=>{let e=[...U];n(l,`accordion:change`,{value:e}),se?.(e)},Y=e=>{let t=J(e);if(!C&&!le&&t.length===0&&U.size>0)return!1;let n=new Set(t);return pe(n)?(U=n,me(),he(),!0):!1},X=e=>(e.getAttribute(`dir`)??v.getAttribute(`dir`))===`rtl`||(getComputedStyle(e).direction||getComputedStyle(v).direction||l.ownerDocument?.documentElement.getAttribute(`dir`)||``)===`rtl`?`rtl`:`ltr`;v.setAttribute(`data-orientation`,T),h(v,`data-disabled`,!!w),y.forEach((e,n)=>{let i=e.dataset.value;if(!i)return;let a=s(e,`accordion-trigger`),o=s(e,`accordion-content`);if(!a||!o)return;let c=r(o,`accordion-content`),l=r(a,`accordion-trigger`);a.setAttribute(`aria-controls`,c),o.setAttribute(`aria-labelledby`,l),o.setAttribute(`role`,`region`);let u=!!w||m(e)||m(a),f;f={el:e,value:i,index:n,disabled:u,trigger:a,content:o,presence:t({element:o,onExitComplete:()=>{L(f),H(f)}}),sizeObserver:null,openSettleRafId:null,openSettleTimeoutId:null,closeZeroRafId:null,openSettleCleanups:[],suppressClick:!1,suppressClickTimeoutId:null},typeof ResizeObserver<`u`&&(f.sizeObserver=new ResizeObserver(()=>{!U.has(f.value)||f.presence.isExiting||P(f)||N(f)}),f.sizeObserver.observe(o)),D.push(d(a,`click`,()=>{if(f.suppressClick){F(f);return}f.disabled||(U.has(f.value)?Y([...U].filter(e=>e!==f.value)):Y(C?[...U,f.value]:[f.value]))})),D.push(d(a,`keydown`,e=>{if(re.has(e.key)){if(f.disabled){e.preventDefault();return}e.preventDefault(),F(f),f.suppressClick=!0,f.suppressClickTimeoutId=S.setTimeout(()=>{f.suppressClick=!1,f.suppressClickTimeoutId=null},0),U.has(f.value)?Y([...U].filter(e=>e!==f.value)):Y(C?[...U,f.value]:[f.value])}})),ce&&D.push(d(o,`beforematch`,()=>{Y(C?[...U,f.value]:[f.value])})),O.push(f)});let Z=new Set(O.map(e=>e.value)),Q=u.defaultValue??oe(o(l,`defaultValue`)),ge=J((Q?Array.isArray(Q)?Q:[Q]:[]).filter(e=>Z.has(e)));U=new Set(ge),O.forEach(de),D.push(d(v,`keydown`,e=>{let t=e.target;if(!t)return;let n=O.find(e=>e.trigger===t);if(!n)return;let r=O.filter(e=>!e.disabled),i=r.findIndex(e=>e.trigger===t);if(i===-1)return;let a=r.length-1,o=-1,s=()=>{o=E?i+1>a?0:i+1:Math.min(i+1,a)},c=()=>{o=E?i===0?a:i-1:Math.max(i-1,0)};switch(e.key){case`ArrowDown`:T===`vertical`&&s();break;case`ArrowUp`:T===`vertical`&&c();break;case`ArrowRight`:T===`horizontal`&&(X(n.trigger)===`rtl`?c():s());break;case`ArrowLeft`:T===`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())})),D.push(d(l,`accordion:set`,e=>{let t=e.detail?.value;t!==void 0&&Y(Array.isArray(t)?t:[t])}));let $={expand:e=>{!Z.has(e)||U.has(e)||Y(C?[...U,e]:[e])},collapse:e=>{!Z.has(e)||!U.has(e)||Y([...U].filter(t=>t!==e))},toggle:e=>{Z.has(e)&&(U.has(e)?$.collapse(e):$.expand(e))},get value(){return[...U]},destroy:()=>{O.forEach(e=>{F(e),e.presence.cleanup(),R(e),e.sizeObserver?.disconnect(),e.sizeObserver=null}),D.forEach(e=>e()),D.length=0,e(l,x,$)}};return te(l,x,$),$}function C(e=document){let t=[];for(let n of l(e,`accordion`))u(n,x)||t.push(S(n));return t}export{C as create,S as createAccordion};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-slot/accordion",
3
- "version": "0.2.151",
3
+ "version": "0.2.152",
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.151"
37
+ "@data-slot/core": "0.2.152"
38
38
  }
39
39
  }