@data-slot/accordion 0.2.152 → 0.2.153

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +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)),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;
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,y=c.onValueChange,b=c.disabled??(0,e.getDataBool)(s,`disabled`)??i(s),x=c.orientation??(0,e.getDataEnum)(s,`orientation`,t)??`vertical`,S=c.loopFocus??(0,e.getDataBool)(s,`loopFocus`)??!0,C=c.hiddenUntilFound??(0,e.getDataBool)(s,`hiddenUntilFound`)??!1,w=c.collapsible??(0,e.getDataBool)(s,`collapsible`)??!0,T=[],E=[],D=(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)},O=(e,t,n)=>{D(e,`${t}px`,`${n}px`)},k=e=>{D(e,`auto`,`auto`)},A=e=>{O(e,0,0)},j=(e,{resetVarsToAuto:t=!1}={})=>{t&&k(e),O(e,e.content.scrollHeight,e.content.scrollWidth)},M=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`},N=e=>{e.suppressClick=!1,e.suppressClickTimeoutId!==null&&(_.clearTimeout(e.suppressClickTimeoutId),e.suppressClickTimeoutId=null)},P=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=[]},F=e=>{e.closeZeroRafId!==null&&(_.cancelAnimationFrame(e.closeZeroRafId),e.closeZeroRafId=null)},I=e=>{P(e),F(e)},L=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`},R=(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`)}},z=e=>{e.idleAnimationSuppressed||(e.idleAnimationName=e.content.style.getPropertyValue(`animation-name`)||null,e.idleAnimationSuppressed=!0,e.content.style.setProperty(`animation-name`,`none`))},B=e=>{e.idleAnimationSuppressed&&=(e.idleAnimationName?e.content.style.setProperty(`animation-name`,e.idleAnimationName):e.content.style.removeProperty(`animation-name`),e.idleAnimationName=null,!1)},V=e=>{e.content.removeAttribute(`hidden`)},H=e=>{C?e.content.setAttribute(`hidden`,`until-found`):e.content.hidden=!0,A(e)},U=new Set,W=(e,t)=>{P(e),!(!U.has(e.value)||e.presence.isExiting)&&(k(e),t===`css-animation`&&z(e))},G=(e,t)=>{P(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;W(e,t)},c=n=>{n.target===e.content&&(i>0||o(a)&&W(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,W(e,t)},Math.ceil(a)+50);return}e.openSettleRafId=_.requestAnimationFrame(()=>{e.openSettleRafId=null,W(e,t)})},ee=e=>{F(e),e.closeZeroRafId=_.requestAnimationFrame(()=>{e.closeZeroRafId=null,!U.has(e.value)&&e.presence.isExiting&&A(e)})},K=e=>{e.el.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-index`,String(e.index)),e.content.setAttribute(`data-orientation`,x),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=U.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=L(t);n?(V(t),r===`css-animation`?R(t,()=>{j(t,{resetVarsToAuto:!0})}):j(t),G(t,r)):H(t)},ne=t=>{let n=U.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=L(t);if(n){if(F(t),V(t),r&&!t.presence.isExiting&&M(t))return;i===`css-animation`?R(t,()=>{j(t,{resetVarsToAuto:!0}),r||t.presence.enter()}):(j(t),r||t.presence.enter()),G(t,i);return}if(r){P(t),i===`css-animation`?R(t,()=>{j(t,{resetVarsToAuto:!0}),t.presence.exit()}):(j(t),t.presence.exit(),ee(t));return}I(t),t.content.removeAttribute(`data-starting-style`),t.content.removeAttribute(`data-ending-style`),H(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===U.size?[...e].some(e=>!U.has(e)):!0,ie=()=>{E.forEach(ne)},ae=()=>{let t=[...U];(0,e.emit)(s,`accordion:change`,{value:t}),y?.(t)},Y=e=>{let t=J(e);if(!v&&!w&&t.length===0&&U.size>0)return!1;let n=new Set(t);return re(n)?(E.forEach(e=>{U.has(e.value)!==n.has(e.value)&&B(e)}),U=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`,x),a(h,`data-disabled`,!!b),g.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=!!b||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:()=>{F(d),H(d)}}),sizeObserver:null,idleAnimationName:null,idleAnimationSuppressed:!1,openSettleRafId:null,openSettleTimeoutId:null,closeZeroRafId:null,openSettleCleanups:[],suppressClick:!1,suppressClickTimeoutId:null},typeof ResizeObserver<`u`&&(d.sizeObserver=new ResizeObserver(()=>{!U.has(d.value)||d.presence.isExiting||M(d)||j(d)}),d.sizeObserver.observe(s)),T.push((0,e.on)(o,`click`,()=>{if(d.suppressClick){N(d);return}d.disabled||(U.has(d.value)?Y([...U].filter(e=>e!==d.value)):Y(v?[...U,d.value]:[d.value]))})),T.push((0,e.on)(o,`keydown`,e=>{if(r.has(e.key)){if(d.disabled){e.preventDefault();return}e.preventDefault(),N(d),d.suppressClick=!0,d.suppressClickTimeoutId=_.setTimeout(()=>{d.suppressClick=!1,d.suppressClickTimeoutId=null},0),U.has(d.value)?Y([...U].filter(e=>e!==d.value)):Y(v?[...U,d.value]:[d.value])}})),C&&T.push((0,e.on)(s,`beforematch`,()=>{Y(v?[...U,d.value]:[d.value])})),E.push(d)});let Z=new Set(E.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)));U=new Set(oe),E.forEach(te),T.push((0,e.on)(h,`keydown`,e=>{let t=e.target;if(!t)return;let n=E.find(e=>e.trigger===t);if(!n)return;let r=E.filter(e=>!e.disabled),i=r.findIndex(e=>e.trigger===t);if(i===-1)return;let a=r.length-1,o=-1,s=()=>{o=S?i+1>a?0:i+1:Math.min(i+1,a)},c=()=>{o=S?i===0?a:i-1:Math.max(i-1,0)};switch(e.key){case`ArrowDown`:x===`vertical`&&s();break;case`ArrowUp`:x===`vertical`&&c();break;case`ArrowRight`:x===`horizontal`&&(X(n.trigger)===`rtl`?c():s());break;case`ArrowLeft`:x===`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())})),T.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)||U.has(e)||Y(v?[...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:()=>{E.forEach(e=>{N(e),e.presence.cleanup(),I(e),e.sizeObserver?.disconnect(),e.sizeObserver=null}),T.forEach(e=>e()),T.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,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};
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,D=u.hiddenUntilFound??i(l,`hiddenUntilFound`)??!1,ce=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&&(S.clearTimeout(e.suppressClickTimeoutId),e.suppressClickTimeoutId=null)},L=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=[]},R=e=>{e.closeZeroRafId!==null&&(S.cancelAnimationFrame(e.closeZeroRafId),e.closeZeroRafId=null)},z=e=>{L(e),R(e)},B=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`},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`)}},le=e=>{e.idleAnimationSuppressed||(e.idleAnimationName=e.content.style.getPropertyValue(`animation-name`)||null,e.idleAnimationSuppressed=!0,e.content.style.setProperty(`animation-name`,`none`))},ue=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`&&le(e))},K=(e,t)=>{L(e);let n=ie(e.content),r=b(e.content),i=r||n;if(i>0){let n=typeof S.performance?.now==`function`?S.performance.now():Date.now(),a=e=>(typeof S.performance?.now==`function`?S.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(!p.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=S.setTimeout(()=>{e.openSettleTimeoutId=null,G(e,t)},Math.ceil(i)+50);return}e.openSettleRafId=S.requestAnimationFrame(()=>{e.openSettleRafId=null,G(e,t)})},de=e=>{R(e),e.closeZeroRafId=S.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`,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))},J=(e,t)=>{e.trigger.setAttribute(`data-state`,t?`open`:`closed`),h(e.trigger,`data-panel-open`,t)},fe=e=>{let t=W.has(e.value);q(e),ee(e.trigger,`expanded`,t),g(e.el,t),g(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)},pe=e=>{let t=W.has(e.value),n=e.trigger.getAttribute(`aria-expanded`)===`true`;q(e),ee(e.trigger,`expanded`,t),g(e.el,t),g(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(),de(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)||!y.some(e=>e.dataset.value===r))&&(n.add(r),t.push(r),!C&&t.length===1))break;return t},me=e=>e.size===W.size?[...e].some(e=>!W.has(e)):!0,he=()=>{k.forEach(pe)},ge=()=>{let e=[...W];n(l,`accordion:change`,{value:e}),se?.(e)},X=e=>{let t=Y(e);if(!C&&!ce&&t.length===0&&W.size>0)return!1;let n=new Set(t);return me(n)?(k.forEach(e=>{W.has(e.value)!==n.has(e.value)&&ue(e)}),W=n,he(),ge(),!0):!1},_e=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:()=>{R(f),U(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(()=>{!W.has(f.value)||f.presence.isExiting||F(f)||P(f)}),f.sizeObserver.observe(o)),O.push(d(a,`click`,()=>{if(f.suppressClick){I(f);return}f.disabled||(W.has(f.value)?X([...W].filter(e=>e!==f.value)):X(C?[...W,f.value]:[f.value]))})),O.push(d(a,`keydown`,e=>{if(re.has(e.key)){if(f.disabled){e.preventDefault();return}e.preventDefault(),I(f),f.suppressClick=!0,f.suppressClickTimeoutId=S.setTimeout(()=>{f.suppressClick=!1,f.suppressClickTimeoutId=null},0),W.has(f.value)?X([...W].filter(e=>e!==f.value)):X(C?[...W,f.value]:[f.value])}})),D&&O.push(d(o,`beforematch`,()=>{X(C?[...W,f.value]:[f.value])})),k.push(f)});let Z=new Set(k.map(e=>e.value)),Q=u.defaultValue??oe(o(l,`defaultValue`)),ve=Y((Q?Array.isArray(Q)?Q:[Q]:[]).filter(e=>Z.has(e)));W=new Set(ve),k.forEach(fe),O.push(d(v,`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=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`&&(_e(n.trigger)===`rtl`?c():s());break;case`ArrowLeft`:T===`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())})),O.push(d(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(C?[...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,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.152",
3
+ "version": "0.2.153",
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.152"
37
+ "@data-slot/core": "0.2.153"
38
38
  }
39
39
  }