import{rast,easi,wass,fase,h,Hasr,casn}from"./p-38dcedc4.js";import{caso}from"./p-5a5a5c96.js";consta=(t,i)=>{consts=l(t,i);returns&&t.ownerDocument?t.ownerDocument.importNode(s.content,!0).children[0]:null},l=(t,i)=>{switch(i){case"item":returnt.querySelector("template:not([name])");case"header":returnt.querySelector("template[name=header]");case"footer":returnt.querySelector("template[name=footer]")}},c=(t,i,s,e,h,r,n,o,a,l,c,u)=>{constd=[],m=u+c;for(letu=c;u<m;u++){constc=t[u];if(h){consti=h(c,u,t);null!=i&&d.push({i:l++,type:"header",value:i,index:u,height:s?s(i,u):n,reads:s?0:2,visible:!!s})}if(d.push({i:l++,type:"item",value:c,index:u,height:i?i(c,u):a,reads:i?0:2,visible:!!i}),r){consti=r(c,u,t);null!=i&&d.push({i:l++,type:"footer",value:i,index:u,height:e?e(i,u):o,reads:e?0:2,visible:!!e})}}returnd},u=class{constructor(i){t(this,i),this.range={offset:0,length:0},this.viewportHeight=0,this.cells=[],this.virtualDom=[],this.isEnabled=!1,this.viewportOffset=0,this.currentScrollTop=0,this.indexDirty=0,this.lastItemLen=0,this.totalHeight=0,this.approxItemHeight=45,this.approxHeaderHeight=30,this.approxFooterHeight=30,this.onScroll=()=>{this.updateVirtualScroll()}}itemsChanged(){this.calcCells(),this.updateVirtualScroll()}asyncconnectedCallback(){constt=this.el.closest("ion-content");t?(this.scrollEl=awaitt.getScrollElement(),this.contentEl=t,this.calcCells(),this.updateState()):console.error("<ion-virtual-scroll> must be used inside an <ion-content>")}componentDidUpdate(){this.updateState()}disconnectedCallback(){this.scrollEl=void0}onResize(){this.calcCells(),this.updateVirtualScroll()}positionForItem(t){returnPromise.resolve(((t,i,s)=>{conste=i.find((i=>"item"===i.type&&i.index===t));returne?s[e.i]:-1})(t,this.cells,this.getHeightIndex()))}asynccheckRange(t,i=-1){if(!this.items)return;consts=-1===i?this.items.length-t:i,e=((t,i)=>0===i?0:i===(t.length>0?t[t.length-1].index:0)+1?t.length:t.findIndex((t=>t.index===i)))(this.cells,t),h=c(this.items,this.itemHeight,this.headerHeight,this.footerHeight,this.headerFn,this.footerFn,this.approxHeaderHeight,this.approxFooterHeight,this.approxItemHeight,e,t,s);this.cells=((t,i,s)=>{if(0===s&&i.length>=t.length)returni;for(lete=0;e<i.length;e++)t[e+s]=i[e];returnt})(this.cells,h,e),this.lastItemLen=this.items.length,this.indexDirty=Math.max(t-1,0),this.scheduleUpdate()}asynccheckEnd(){this.items&&this.checkRange(this.lastItemLen)}updateVirtualScroll(){this.isEnabled&&this.scrollEl&&(this.timerUpdate&&(clearTimeout(this.timerUpdate),this.timerUpdate=void0),i(this.readVS.bind(this)),s(this.writeVS.bind(this)))}readVS(){const{contentEl:t,scrollEl:i,el:s}=this;lete=0,h=s;for(;h&&h!==t;)e+=h.offsetTop,h=h.offsetParent;this.viewportOffset=e,i&&(this.viewportHeight=i.offsetHeight,this.currentScrollTop=i.scrollTop)}writeVS(){constt=this.indexDirty,i=(r=this.currentScrollTop-this.viewportOffset,n=this.viewportHeight,{top:Math.max(r-100,0),bottom:r+n+100}),s=this.getHeightIndex(),h=((t,i)=>{consts=i.top,e=i.bottom;leth=0;for(;h<t.length&&!(t[h]>s);h++);constr=Math.max(h-2-1,0);for(;h<t.length&&!(t[h]>=e);h++);return{offset:r,length:Math.min(h+2,t.length)-r}})(s,i);varr,n;((t,i,s)=>t<=s.offset+s.length||i.offset!==s.offset||i.length!==s.length)(t,this.range,h)&&(this.range=h,((t,i,s,e)=>{for(constioft)i.change=0,i.d=!0;consth=[],r=e.offset+e.length;for(letn=e.offset;n<r;n++){conste=s[n],r=t.find((t=>t.d&&t.cell===e));if(r){constt=i[n];t!==r.top&&(r.top=t,r.change=1),r.d=!1}elseh.push(e)}constn=t.filter((t=>t.d));for(constsofh){conste=n.find((t=>t.d&&t.cell.type===s.type)),h=s.i;e?(e.d=!1,e.change=2,e.cell=s,e.top=i[h]):t.push({d:!1,cell:s,visible:!0,change:2,top:i[h]})}t.filter((t=>t.d&&-9999!==t.top)).forEach((t=>{t.change=1,t.top=-9999}))})(this.virtualDom,s,this.cells,h),this.nodeRender?((t,i,s,e)=>{consth=Array.from(t.children).filter((t=>"TEMPLATE"!==t.tagName)),r=h.length;letn;for(leto=0;o<s.length;o++){constl=s[o],c=l.cell;if(2===l.change){if(o<r)n=h[o],i(n,c,o);else{consts=a(t,c.type);n=i(s,c,o)||s,n.classList.add("virtual-item"),t.appendChild(n)}n.$ionCell=c}elsen=h[o];0!==l.change&&(n.style.transform=`translate3d(0,${l.top}px,0)`);constu=c.visible;l.visible!==u&&(u?n.classList.remove("virtual-loading"):n.classList.add("virtual-loading"),l.visible=u),c.reads>0&&(e(c,n),c.reads--)}})(this.el,this.nodeRender,this.virtualDom,this.updateCellHeight.bind(this)):this.domRender?this.domRender(this.virtualDom):this.renderItem&&e(this))}updateCellHeight(t,i){consts=()=>{if(i.$ionCell===t){consts=window.getComputedStyle(i),e=i.offsetHeight+parseFloat(s.getPropertyValue("margin-bottom"));this.setCellHeight(t,e)}};i?o(i,s):s()}setCellHeight(t,i){consts=t.i;t===this.cells[s]&&(t.height===i&&!0===t.visible||(t.visible=!0,t.height=i,this.indexDirty=Math.min(this.indexDirty,s),this.scheduleUpdate()))}scheduleUpdate(){clearTimeout(this.timerUpdate),this.timerUpdate=setTimeout((()=>this.updateVirtualScroll()),100)}updateState(){constt=!(!this.scrollEl||!this.cells);t!==this.isEnabled&&(this.enableScrollEvents(t),t&&this.updateVirtualScroll())}calcCells(){this.items&&(this.lastItemLen=this.items.length,this.cells=c(this.items,this.itemHeight,this.headerHeight,this.footerHeight,this.headerFn,this.footerFn,this.approxHeaderHeight,this.approxFooterHeight,this.approxItemHeight,0,0,this.lastItemLen),this.indexDirty=0)}getHeightIndex(){returnthis.indexDirty!==1/0&&this.calcHeightIndex(this.indexDirty),this.heightIndex}calcHeightIndex(t=0){this.heightIndex=((t,i)=>{if(!t)returnnewUint32Array(i);if(t.length===i)returnt;if(i>t.length){consts=newUint32Array(i);returns.set(t),s}returnt.subarray(0,i)})(this.heightIndex,this.cells.length),this.totalHeight=((t,i,s)=>{lete=t[s];for(leth=s;h<t.length;h++)t[h]=e,e+=i[h].height;returne})(this.heightIndex,this.cells,t),this.indexDirty=1/0}enableScrollEvents(t){this.rmEvent&&(this.rmEvent(),this.rmEvent=void0);consti=this.scrollEl;i&&(this.isEnabled=t,i.addEventListener("scroll",this.onScroll),this.rmEvent=()=>{i.removeEventListener("scroll",this.onScroll)})}renderVirtualNode(t){const{type:i,value:s,index:e}=t.cell;switch(i){case"item":returnthis.renderItem(s,e);case"header":returnthis.renderHeader(s,e);case"footer":returnthis.renderFooter(s,e)}}render(){returnh(r,{style:{height:`${this.totalHeight}px`}},this.renderItem&&h(d,{dom:this.virtualDom},this.virtualDom.map((t=>this.renderVirtualNode(t)))))}getel(){returnn(this)}staticgetwatchers(){return{itemHeight:["itemsChanged"],headerHeight:["itemsChanged"],footerHeight:["itemsChanged"],items:["itemsChanged"]}}},d=({dom:t},i,s)=>s.map(i,((i,s)=>{conste=t[s],h=i.vattrs||{};letr=h.class||"";returnr+="virtual-item ",e.visible||(r+="virtual-loading"),Object.assign(Object.assign({},i),{vattrs:Object.assign(Object.assign({},h),{class:r,style:Object.assign(Object.assign({},h.style),{transform:`translate3d(0,${e.top}px,0)`})})})}));u.style="ion-virtual-scroll{display:block;position:relative;width:100%;contain:strict;user-select:none}ion-virtual-scroll>.virtual-loading{opacity:0}ion-virtual-scroll>.virtual-item{position:absolute !important;top:0 !important;right:0 !important;left:0 !important;transition-duration:0ms;will-change:transform}";export{uasion_virtual_scroll}