/** * @collapsed/core v5.0.0 * * Copyright (c) 2019-2024, Rogin Farrer * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ "use strict";var y=Object.create;var r=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var C=(t,e)=>{for(var n in e)r(t,n,{get:e[n],enumerable:!0})},p=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of b(e))!v.call(t,o)&&o!==n&&r(t,o,{get:()=>e[o],enumerable:!(i=f(e,o))||i.enumerable});return t};var F=(t,e,n)=>(n=t!=null?y(x(t)):{},p(e||!t||!t.__esModule?r(n,"default",{value:t,enumerable:!0}):n,t)),S=t=>p(r({},"__esModule",{value:!0}),t);var I={};C(I,{Collapse:()=>l,prefersReducedMotion:()=>d});module.exports=S(I);var m=F(require("tiny-warning"),1);function h(t){if(!t)return 0;let e=t/36;return Math.round((4+15*e**.25+e/5)*10)}function u(t){if(process.env.NODE_ENV!=="production"&&window&&"getComputedStyle"in window){let{paddingTop:e,paddingBottom:n}=window.getComputedStyle(t);(0,m.default)(!(e&&e!=="0px"||n&&n!=="0px"),"Collapse: Padding applied to the collapse element will cause the animation to break and not perform as expected. To fix, apply equivalent padding to the direct descendent of the collapse element.")}}function c(t,e){let n=performance.now(),i={};function o(){i.id=requestAnimationFrame(g=>{g-n>e?t():o()})}return o(),i}function s(t){t.id&&cancelAnimationFrame(t.id)}var a=new Map;function T(t){return a.has(t)||a.set(t,h(t)),a.get(t)}var l=class{#e;frameId;endFrameId;constructor(e){this.#e={easing:"cubic-bezier(0.4, 0, 0.2, 1)",duration:"auto",collapsedHeight:0,onExpandedChange(){},onTransitionStateChange(){},...e}}setOptions(e){this.#e={...this.#e,...e}}#t(){return this.#e.getDisclosureElement()}#n(e){return this.#e.duration==="auto"?T(e):this.#e.duration}#i=(e,n)=>{let i=()=>{let o=this.#t();o.style.removeProperty("transition"),e==="close"?(this.setCollapsedStyles(),this.frameId=requestAnimationFrame(()=>{this.#e.onTransitionStateChange("collapseEnd")})):(o.style.removeProperty("height"),o.style.removeProperty("overflow"),o.style.removeProperty("display"),this.frameId=requestAnimationFrame(()=>{this.#e.onTransitionStateChange("expandEnd")}))};this.endFrameId&&s(this.endFrameId),this.endFrameId=c(i,n)};getCollapsedStyles(){return{height:`${this.#e.collapsedHeight}px`,overflow:"hidden",display:this.#e.collapsedHeight===0?"none":"block"}}setCollapsedStyles(){let e=this.#t();for(let[n,i]of Object.entries(this.getCollapsedStyles()))e.style.setProperty(n,i)}unsetCollapsedStyles(){let e=this.#t();for(let n of Object.keys(this.getCollapsedStyles()))e.style.removeProperty(n)}open(){let e=this.#t();if(this.#e.onExpandedChange(!0),this.frameId&&cancelAnimationFrame(this.frameId),this.endFrameId&&s(this.endFrameId),d()){e.style.removeProperty("display"),e.style.removeProperty("height"),e.style.removeProperty("overflow");return}u(e),this.frameId=requestAnimationFrame(()=>{this.#e.onTransitionStateChange("expandStart"),e.style.setProperty("display","block"),e.style.setProperty("overflow","hidden"),e.style.setProperty("height",`${this.#e.collapsedHeight}px`),this.frameId=requestAnimationFrame(()=>{this.#e.onTransitionStateChange("expanding");let n=e.scrollHeight,i=this.#n(n);this.#i("open",i),e.style.transition=`height ${i}ms ${this.#e.easing}`,e.style.height=`${n}px`})})}close(){if(this.#e.onExpandedChange(!1),this.frameId&&cancelAnimationFrame(this.frameId),this.endFrameId&&s(this.endFrameId),d()){this.setCollapsedStyles();return}this.#e.onTransitionStateChange("collapseStart"),this.frameId=requestAnimationFrame(()=>{let e=this.#t(),n=e.scrollHeight,i=this.#n(n);this.#i("close",i),e.style.transition=`height ${i}ms ${this.#e.easing}`,e.style.height=`${n}px`,this.frameId=requestAnimationFrame(()=>{this.#e.onTransitionStateChange("collapsing"),e.style.overflow="hidden",e.style.height=`${this.#e.collapsedHeight}px`})})}};function d(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}0&&(module.exports={Collapse,prefersReducedMotion});