import{r as t,h as s,H as i,a as e}from"./p-DBTJNfo7.js";const o=class{constructor(s){t(this,s),this.ordered=!1,this.containerHeight=0,this.hasRendered=!1,this.pendingLayoutFrame=null}onOrderedChange(){this.scheduleLayout()}componentDidLoad(){this.setupObservers(),this.layoutItems(),this.hasRendered=!0}connectedCallback(){this.hasRendered&&(this.setupObservers(),this.scheduleLayout())}disconnectedCallback(){var t,s,i;null===(t=this.resizeObserver)||void 0===t||t.disconnect(),null===(s=this.mutationObserver)||void 0===s||s.disconnect(),null===(i=this.itemResizeObserver)||void 0===i||i.disconnect(),null!==this.pendingLayoutFrame&&cancelAnimationFrame(this.pendingLayoutFrame)}render(){return s(i,{key:"e41aecdf81962515dabef9b872cac4a44facf45d",style:{height:`${this.containerHeight}rem`},class:{"is-laid-out":this.hasRendered}},s("slot",{key:"94e9603630597a47bef3861a076fca9a8e90dd3c"}))}setupObservers(){this.resizeObserver=new ResizeObserver((()=>{this.scheduleLayout()})),this.resizeObserver.observe(this.host),this.itemResizeObserver=new ResizeObserver((()=>{this.scheduleLayout()})),this.mutationObserver=new MutationObserver((()=>{this.observeItemSizes(),this.scheduleLayout()})),this.mutationObserver.observe(this.host,{childList:!0}),this.observeItemSizes()}observeItemSizes(){var t;null===(t=this.itemResizeObserver)||void 0===t||t.disconnect();const s=this.getItems();for(const t of s)this.itemResizeObserver.observe(t)}getItems(){return[...this.host.children].filter((t=>t instanceof HTMLElement))}getRootFontSize(){return Number.parseFloat(getComputedStyle(document.documentElement).fontSize)}pxToRem(t,s){return t/s}getCssPropertyInPx(t,s,i){const e=getComputedStyle(this.host).getPropertyValue(t).trim()||s,o=Number.parseFloat(e);return e.endsWith("px")?o:o*i}scheduleLayout(){null!==this.pendingLayoutFrame&&cancelAnimationFrame(this.pendingLayoutFrame),this.pendingLayoutFrame=requestAnimationFrame((()=>{this.pendingLayoutFrame=null,this.layoutItems()}))}layoutItems(){const t=this.getItems();if(0===t.length)return void(this.containerHeight=0);const s=this.host.offsetWidth;if(!s)return;const i=this.getRootFontSize(),e=this.getCssPropertyInPx("--masonry-layout-gap","1rem",i),{columnCount:o,columnWidth:n}=this.calculateColumns(s,e,i),r=this.positionItems(t,o,n,e,i),h=this.pxToRem(Math.max(...r)-e,i);Math.abs(h-this.containerHeight)>.1&&(this.containerHeight=h)}calculateColumns(t,s,i){const e=this.getCssPropertyInPx("--masonry-layout-min-column-width","12rem",i),o=Math.max(1,Math.floor((t+s)/(e+s)));return{columnCount:o,columnWidth:(t-(o-1)*s)/o}}positionItems(t,s,i,e,o){const n=Array.from({length:s},(()=>0));let r=0;for(const h of t){const t=this.ordered?r%s:n.indexOf(Math.min(...n)),a=t*(i+e),l=n[t];h.style.position="absolute",h.style.left=`${this.pxToRem(a,o)}rem`,h.style.top=`${this.pxToRem(l,o)}rem`,h.style.width=`${this.pxToRem(i,o)}rem`,this.hasRendered||this.staggerFadeIn(h,r),n[t]+=h.offsetHeight+e,r++}return n}staggerFadeIn(t,s){if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;t.style.transition="opacity 0.2s cubic-bezier(0.2, 0, 0.2, 1)",t.style.transitionDelay=20*s+"ms";const i=s=>{s.target===t&&"opacity"===s.propertyName&&(t.style.transition="",t.style.transitionDelay="",t.removeEventListener("transitionend",i))};t.addEventListener("transitionend",i)}get host(){return e(this)}static get watchers(){return{ordered:[{onOrderedChange:0}]}}};o.style=":host(limel-masonry-layout){display:block;position:relative;box-sizing:border-box;visibility:hidden}:host(limel-masonry-layout) ::slotted(*){opacity:0;box-sizing:border-box}:host(limel-masonry-layout.is-laid-out){visibility:visible}:host(limel-masonry-layout.is-laid-out) ::slotted(*){opacity:1}";export{o as limel_masonry_layout}