UNPKG

mnstr

Version:

Ultra fast large list rendering.

2 lines (1 loc) 21.1 kB
class MNSTR{constructor(t){(this.context=this).parentNode=void 0,this.getData=void 0,this.getElementChildren=void 0,this.getCellRenderer=void 0,this.virtualEnvironment=!1,this.needUpdateVirtualDOM=void 0,this.renderOnInitialize=!0,this.initialScrollToElement=void 0,this.initialScrollToOptions=void 0,this.observeCellBounds=!1,this.rememberChildrenExpands=!0,this.thresholdRatio=.5,this.useTransform=!0,this.className="mnstr",this.didRenderFirstElement=void 0,this.didRenderLastElement=void 0,this.firstInBoundsElementChanged=void 0,this.lastInBoundsElementChanged=void 0,this._data=[],this._scrollNode=void 0,this._listNode=void 0,this._events={},this._lowestCellHeigh=Number.MAX_VALUE,this._averageCellHeight=1,this._currentMaxIndex=0,this._initialScrollToElement=void 0,this._cachedScrollToElement=void 0,this._cachedScrollToOptions=void 0,this._firstInBoundsElement=void 0,this._lastInBoundsElement=void 0,this._frameRequests={},this._cellsSorted=[],this._vElements=[],this._expandInformations=[],this._updatingCells=!1,t=t||{},Object.keys(t).forEach(e=>{"_"===e.charAt(0)&&delete t[e]}),Object.assign(this,t),this._initialScrollToElement=this.initialScrollToElement,this._cachedScrollToElement=this._initialScrollToElement,this._cachedScrollToOptions=this.initialScrollToOptions,this.renderOnInitialize&&this.render()}destroy(){console.error("wheeee.")}async reset(){if(this._data=[],this._lowestCellHeight=Number.MAX_VALUE,this._averageCellHeight=1,this._currentMaxIndex=0,this._cachedScrollToElement=void 0,this._cachedScrollToOptions=void 0,this._frameRequests={},this._cellsSorted=[],this._expandInformations=[],this._vElements=[],this.virtualEnvironment)await this.updateVirtualDOM();else for(;this._listNode.firstChild;)this._listNode.removeChild(this._listNode.firstChild);this.needUpdate(),this.setScrollPosition(0),this.rUpdateCells()}exportRestoreState(){var e=this.getCellsSorted()[0];return{scrollTop:this.getScrollPosition(),index:e?e.__index:0,position:e?this.getNodeTop(e):0,height:this.getNodeHeight(this._listNode)}}render(e){return this.needUpdate(),this.renderScrollNode(e),this.renderListNode(),this.initScrollListener(),this.rAF(async()=>{await this.updateCells(!0),this.renderListResizeObserver()},"render"),this}renderScrollNode(e){return this._scrollNode&&this._scrollNode.parentNode&&this._scrollNode.parentNode.removeChild(this._scrollNode),this._scrollNode=document.createElement("div"),this._scrollNode.classList.add(this.className),this._scrollNode.setAttribute("style","overflow-y: auto; -webkit-overflow-scrolling: touch; overflow-scrolling: touch; position: relative; will-change: transform;"),this.parentNode=e||this.parentNode||document.body,this.parentNode.appendChild(this._scrollNode),this._scrollNode}renderListNode(){return this._listNode=document.createElement("ul"),this._listNode.classList.add(this.className+"-list"),this._listNode.setAttribute("style","position: relative; overflow: hidden; list-style-type: none; margin: 0; padding: 0;"),this._scrollNode.appendChild(this._listNode),this._listNode}renderIFrame(e,t){var i=document.createElement("iframe");return i.setAttribute("style","position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 0; border: none; opacity: 0; pointer-events: none; touch-action: none; z-index: -1000;"),i.onload=e=>{e.target.contentWindow.onresize=t.bind(this)},e.appendChild(i),i}renderListResizeObserver(){this._scrollNode.__frameNode=this.renderIFrame(this._scrollNode,this.onResizeScrollNode)}renderCell(){var e=document.createElement("li"),t=(e.classList.add(this.className+"-cell"),e.setAttribute("style","position: absolute; width: 100%; top: 0; left: 0;"),e.__frameNode=this.observeCellBounds?this.renderIFrame(e,this.onResizeCell):void 0,document.createElement("div"));return t.classList.add(this.className+"-content"),t.setAttribute("style","width: 100%; margin: 0; border: 0;"),e.appendChild(t),e.__contentNode=t,this._listNode.appendChild(e),e}updateVirtualDOM(){return new Promise(e=>{this.needUpdateVirtualDOM.call(this.context,[].concat(this._vElements),()=>e())})}addVirtualElement(e,t,i,s){this._vElements&&this._vElements.push(this.createVirtualElement(e,t,i,s))}removeVirtualElementForCell(t){var e;return this._vElements&&-1<(e=this._vElements.findIndex(e=>e.element===t.__element))?(this._vElements.splice(e,1),!0):void 0}sortVirtualElements(){this._vElements&&this._vElements.sort((e,t)=>e.index<t.index?-1:1)}replaceVirtualElementForCell(e,t,i,s,l){this._vElements&&this._vElements.splice([].slice.call(this.getCells()).indexOf(t),1,this.createVirtualElement(e,i,s,l))}createVirtualElement(e,t,i,s){return{element:e,index:t,isExpanded:i,level:s}}async syncVDOMToInternalState(){var e=this._vElements.slice(0).sort((e,t)=>e.index-t.index);if(e.length){const s=e[0].index,l=this.getCellsSorted().find(e=>e.__index===s);if(l){var e=this.getNodeTop(l),t=(await this.updateVirtualDOM(),this.getCells());for(let e=0;e<t.length;e++){const l=t[e];var i=this._vElements[e];l.__index=i.index,l.__element=i.element,l.__level=i.level,l.dataset.level=i.level}this.updateCellsSorted().reduce((e,t)=>(this.setNodeTop(t,e),this.setNodeHeight(t),e+this.getNodeHeight(t)),e)}}else await this.updateVirtualDOM(),this.updateCellsSorted()}getNodeHeight(e,t){return e?t||!e.__nodeHeight?this.setNodeHeight(e,t):e.__nodeHeight||0:0}setNodeHeight(e,t,i,s){return i=Math.max(i,0),s&&(e.style.height=i+"px"),e.__nodeHeight=i||t?e.getBoundingClientRect().height:e.offsetHeight,e.__nodeHeight}getNodeTop(e){return e&&e.__nodeTop||0}setNodeTop(e,t){return t=Math.max(t,0),this.useTransform?e.style.transform="translateY("+t+"px)":e.style.top=t+"px",e.__nodeTop=t,e.__nodeTop}getNodeBottom(e){return e?this.getNodeTop(e)+this.getNodeHeight(e):0}getMinimumListNodeHeight(){var e=this.getNodeHeight(this._scrollNode,!0);return e+e*(2*this.thresholdRatio)}updateListBounds(e){var t,i,s,l,n;this._cellsSorted&&this._cellsSorted.length&&(t=this._cellsSorted[this._cellsSorted.length-1],i=this.getNodeBottom(t),s=this.getNodeHeight(this._listNode),l=Math.floor(this._scrollNode.scrollHeight-this.getScrollPosition())-Math.ceil(this.getNodeHeight(this._scrollNode))<=1,n=t.__index===this._currentMaxIndex&&i-s!=0,e||l||n||!s)&&this.setNodeHeight(this._listNode,!1,i+(this._currentMaxIndex-t.__index)*this._averageCellHeight,!0)}getTopRenderThreshold(){return-this.getNodeHeight(this._scrollNode)*this.thresholdRatio}getBottomRenderThreshold(){var e=this.getNodeHeight(this._scrollNode);return e*this.thresholdRatio+e}getCells(){return this._listNode?this._listNode.children:void 0}getCellsSorted(){return this._cellsSorted||this.updateCellsSorted()}updateCellsSorted(){var e=this.getCells();if(e)return this._cellsSorted=[].slice.call(e),this._cellsSorted.sort((e,t)=>e.__index-t.__index),this._cellsSorted}addEventListener(e,t){return this._events[e]=this._events[e]||[],this._events[e].push(t),this}removeEventListener(e,t){this._events[e]&&-1<(t=this._events[e].indexOf(t))&&this._events[e].splice(t,1)}emitEvent(e){var t=this._events[e];const i=[].slice.call(arguments,1);t&&0<t.length&&t.forEach(e=>e.apply(this,i)),this[e]&&this[e].apply(this.context,i)}emitElementEvents(e,t){0===t&&this.emitEvent("didRenderFirstElement",e,this),t===this._currentMaxIndex&&this.emitEvent("didRenderLastElement",e,this)}getScrollPosition(){return this._scrollNode?this._scrollNode.scrollTop:void 0}setScrollPosition(e){this._scrollNode&&(this._scrollNode.scrollTop=e)}initScrollListener(){this._scrollNode&&this._scrollNode.addEventListener("scroll",e=>this.rUpdateCells())}async scrollToFirstElement(){var e=this.getElementAndLevelAtIndex(0);await this.scrollToElement(e.element)}async scrollToLastElement(){var e=this.getElementAndLevelAtIndex(this._currentMaxIndex);await this.scrollToElement(e.element)}async scrollToElement(t,e){var i,e=Object.assign({smooth:!1,nearest:!1,bottom:!1,force:!1,offset:0},e),s=this._cellsSorted.find(e=>e.__element===t);s||await this.updateCells(),s?(i=this.getNodeTop(s)>this.getScrollPosition()&&this.getNodeBottom(s)<this.getScrollPosition()+this.getNodeHeight(this._scrollNode),!e.force&&i||(i=e.bottom||e.nearest&&this.getNodeTop(s)>this.getScrollPosition()+this.getNodeHeight(this._scrollNode)/2?this.getNodeTop(s)-this.getNodeHeight(this._scrollNode)+this.getNodeHeight(s)+e.offset:this.getNodeTop(s)+e.offset,this.setScrollPosition(i)),delete this._cachedScrollToElement,delete this._cachedScrollToOptions,delete this._initialScrollToElement):(s=this.getIndexForElement(t))<0||(this._cachedScrollToElement=t,this._cachedScrollToOptions=e,0!==this._cellsSorted.length&&this.setScrollPosition(s*this._averageCellHeight))}async scrollToCachedScrollElement(){this._cachedScrollToElement&&await this.scrollToElement(this._cachedScrollToElement,this._cachedScrollToOptions)}needUpdate(){return this._data=this.getData?this.getData.call(this.context,this):[],this.updateCurrentMaxIndex(),this.invalidateExpandInformations(),this}update(e,t){return this.needUpdate(),this.rUpdateCells(!0,e,t),this}async restoreState(e,t){this.needUpdate(),this._scrollNode||(this.renderScrollNode(t||this.parentNode),this.renderListNode(),this.initScrollListener()),-1!==this._currentMaxIndex&&(await this.addCell(e.index,e.position)&&(this.setNodeHeight(this._listNode,!1,e.height,!0),this.setScrollPosition(e.scrollTop)),delete this._initialScrollToElement,delete this._cachedScrollToElement,this.updateCellsAverages(),this.updateCells())}getElementAndLevelAtIndex(t){if(!this.canHasChildren())return this.createElementAndLevelInformation(this._data[t],0);let i=0;for(let e=this._expandInformations.length-1;0<=e;e--){var s,l=this._expandInformations[e];if(l.active&&!(l.index>=t))if(i+=l.elementChildren.length,!(l.index+i<t))return s=t-(l.index+i-l.elementChildren.length)-1,this.createElementAndLevelInformation(l.elementChildren[s],l.level)}return this.createElementAndLevelInformation(this._data[t-i],0)}createElementAndLevelInformation(e,t){return{element:e,level:t}}updateCurrentMaxIndex(){var e=this._expandInformations.reduce((e,t)=>e+(t.active?t.elementChildren.length:0),0);this._currentMaxIndex=this._data.length-1+e}canHasChildren(){return void 0!==this.getElementChildren}getChildrenForElement(e){return this.canHasChildren()?this.getElementChildren.call(this.context,e,this):void 0}getIndexForElement(i){let s=this._data.indexOf(i);return-1<s?this._expandInformations.reduce((e,t)=>{return t.elementParent||this._data.indexOf(t.element)<s&&(e+=t.totalLength),e},s):this._expandInformations.reduce((e,t)=>{if(!(-1<e)){const s=t.elementChildren.indexOf(i);-1<s&&(e=s+t.index+1+t.elementChildren.reduce((e,t,i)=>{return i>=s||(i=this._expandInformations.find(e=>e.element===t))&&(e+=i.totalLength),e},0))}return e},-1)}async maintainCellCount(){var e=this.getScrollPosition(),t=e+this.getTopRenderThreshold(),e=e+this.getBottomRenderThreshold(),i=this.getCellsSorted(),s=i[0],l=i[i.length-1],i=this.getNodeBottom(l)-this.getNodeTop(s),n=this.getMinimumListNodeHeight(),o=i<n;let r=!1;switch(!0){case!s&&-1<this._currentMaxIndex:var d=this._initialScrollToElement?this.getIndexForElement(this._initialScrollToElement):0,h=await this.addCell(d,0);h&&(this.setNodeTop(h,this.getNodeHeight(h)*d),r=!0);break;case l&&l.__index<this._currentMaxIndex&&(o||this.getNodeBottom(l)<e):r=!!await this.addCell(l.__index+1,this.getNodeBottom(l));break;case s&&0<s.__index&&(o||this.getNodeTop(s)>t):r=!!await this.addCell(s.__index-1,this.getNodeTop(s),!0);break;case s&&(s.__index<0||this.getNodeBottom(s)<t&&i-this.getNodeHeight(s)>n):r=!!await this.removeCell(s);break;case l&&(l.__index>this._currentMaxIndex||this.getNodeTop(l)>e&&i-this.getNodeHeight(l)>n):r=!!await this.removeCell(l)}r&&(this.updateCellsSorted(),this.updateCellsAverages(),this.updateListBounds(),this._initialScrollToElement&&await this.scrollToCachedScrollElement(),await this.updateCells(),await this.maintainCellCount())}async addCell(e,t,i=!1){if(!(e<0||e>this._currentMaxIndex)){e=this.virtualEnvironment?await this.updateCell(void 0,e):await this.updateCell(this.renderCell(),e);if(e)return e.__frameNode=this.virtualEnvironment&&this.observeCellBounds?this.renderIFrame(e,this.onResizeCell):e.__frameNode,this.setNodeHeight(e),this.setNodeTop(e,t-(i?this.getNodeHeight(e):0)),e}}async removeCell(e){var t;return this.virtualEnvironment?(t=this.removeVirtualElementForCell(e),await this.syncVDOMToInternalState(),t):(this._listNode.removeChild(e),!0)}rUpdateCells(e,t,i){this.rAF(this.updateCells,"updatecells",e,t,i)}async updateCells(i,s,e){if(!this._updatingCells){this._updatingCells=!0;var l,n=this.getScrollPosition(),o=n+this.getTopRenderThreshold(),r=n+this.getBottomRenderThreshold(),d=this.getCellsSorted().slice(0),h=i,a={};let t=!1;i&&(a.index=0,a.pos=0,e?(l=(e=this.findCellIndexDeviation())*this._averageCellHeight,a.index=Math.max(0,d&&d.length?d[0].__index+e:0),a.pos=Math.max(0,this.getNodeTop(d[0])+l),this.updateListBounds(!0),this.setScrollPosition(n+l)):this.setScrollPosition(0)),d&&d.length&&(this.getNodeTop(d[0])>r||this.getNodeBottom(d[d.length-1])<o)&&(i=!0,a.index=Math.min(Math.round(Math.max(o,0)/this._averageCellHeight),this._currentMaxIndex-d.length+1),a.pos=Math.max(0,a.index*this._averageCellHeight+this.getTopRenderThreshold()));for(let e=0;e<d.length;e++){var m=d[0],_=d[d.length-1],c=d[e];if(i){var g=0===c.__index&&0<a.index?this.getNodeHeight(c):0;await this.updateCell(c,a.index,s),this.setNodeHeight(c),a.pos+=g?g-this.getNodeHeight(c):0,this.setNodeTop(c,a.pos),a.index+=1,a.pos+=this.getNodeHeight(c),t=!0}else if(_.__index<this._currentMaxIndex&&this.getNodeBottom(c)<o&&this.getNodeBottom(_)<r)await this.updateCell(c,_.__index+1,s),this.setNodeHeight(c),this.setNodeTop(c,this.getNodeBottom(_)),d.push(d.shift()),t=!0;else if(e===d.length-1&&0<m.__index&&this.getNodeTop(c)>r&&this.getNodeTop(m)>o)switch(await this.updateCell(c,m.__index-1,s),this.setNodeHeight(c),this.setNodeTop(c,this.getNodeTop(m)-this.getNodeHeight(c)),d.unshift(d.pop()),t=!0){case 0===c.__index&&0<this.getNodeTop(c):var p=this.getNodeTop(c);i=!0,a.index=c.__index,a.pos=0,this.setScrollPosition(n-p),e=-1;break;case 0===this.getNodeTop(c):p=this._averageCellHeight*c.__index;i=!0,a.index=c.__index,this.setScrollPosition(n+(a.pos=p)),e=-1;break;default:e--}}d&&d.length&&!t||(this.updateCellsSorted(),await this.maintainCellCount(),this.updateCellsAverages(),this.emitEvent("cellsUpdated",this.getCellsSorted(),this)),this.updateListBounds(h),this.scrollToCachedScrollElement(),this.updateFirstAndLastCellInViewport(),this._updatingCells=!1}}async updateCell(e,t,i){var s=this.getElementAndLevelAtIndex(t);if(s){var l,n=s.element,s=s.level;if(n&&(!e||n!==e.__element||i))return i=this.canHasChildren()?this.getExpandInformationForElement(n):void 0,e&&this.disableNodeResizeObserving(e),this.virtualEnvironment?(e?this.replaceVirtualElementForCell(n,e,t,void 0!==i,s):this.addVirtualElement(n,t,void 0!==i,s),await this.updateVirtualDOM(),e||(e=(l=this.getCells())[l.length-1])):"string"==typeof(l=this.getCellRenderer?this.getCellRenderer.call(this.context,n,t,void 0!==i,this):"")||l instanceof String?e.__contentNode.innerHTML=l:(e.__contentNode.innerHTML="",e.__contentNode.appendChild(l)),this.observeCellBounds&&this.rAF(this.enableNodeResizeObserving,!1,e),i?e.classList.add("expanded"):e.classList.remove("expanded"),e.dataset.level=s,e.__element=n,e.__index=t,e.__level=s,this.emitElementEvents(n,t),e;e&&n===e.__element&&(e.__index=t,e.__level=s,e.dataset.level=s)}}findCellIndexDeviation(){for(let e=0;e<this._cellsSorted.length;e++){var t=this._cellsSorted[e],i=this.getIndexForElement(t.__element);if(-1!==i)return i===t.__index?0:i-t.__index}return 0}updateCellsAverages(){var t=this.getCells();let i=0;this._lowestCellHeight=Number.MAX_VALUE;for(let e=0;e<t.length;e++){var s=this.getNodeHeight(t[e]);i+=s,this._lowestCellHeight=0===this._lowestCellHeight?s:Math.min(this._lowestCellHeight,s)}this._averageCellHeight=i/t.length}cellBoundsUpdated(){this.rUpdateCells(!0,!1,!0)}updateFirstAndLastCellInViewport(){var e,t=this.getScrollPosition(),i=this.getNodeHeight(this._scrollNode),s=this.getCellsSorted(),l=t+i,n=Math.max(1,Math.round(s.length/5));let o=-1,r=-1;for(let e=0;e<s.length;e+=n){var d=s[e];if(this.getNodeTop(d)>t){o=Math.max(0,e-n);break}}if(-1<o){for(;;){var h=s[o];if(this.getNodeTop(h)>=t)break;o++}for(r=o;;){var a=s[r];if(!a||this.getNodeTop(a)+this.getNodeHeight(a)>=l){r--;break}r++}o<0||r<0||(i=s[o].__element,e=s[r].__element,i!==this._firstInBoundsElement&&(this._firstInBoundsElement=i,this.emitEvent("firstInBoundsElementChanged",this._firstInBoundsElement,this)),e!==this._lastInBoundsElement&&(this._lastInBoundsElement=e,this.emitEvent("lastInBoundsElementChanged",this._lastInBoundsElement,this)))}}onResizeScrollNode(e){this.disableAllCellsResizeObserving(),this.rAF(async()=>{await this.updateCells(!0,!1,!0),this.setNodeHeight(this._scrollNode),this.enableAllCellsResizeObserving()},"resizelist")}onResizeCell(e){this.cellBoundsUpdated()}disableNodeResizeObserving(e){e.__frameNode&&e.__frameNode.contentWindow&&e.__frameNode.contentWindow.onresize&&(e.__frameNode.contentWindow.__onresize=e.__frameNode.contentWindow.onresize,e.__frameNode.contentWindow.onresize=void 0)}enableNodeResizeObserving(e){this.observeCellBounds&&e.__frameNode&&e.__frameNode.contentWindow&&e.__frameNode.contentWindow.__onresize&&(e.__frameNode.contentWindow.onresize=e.__frameNode.contentWindow.__onresize,e.__frameNode.contentWindow.__onresize=void 0)}disableAllCellsResizeObserving(){this.observeCellBounds&&this.getCellsSorted().forEach(e=>this.disableNodeResizeObserving(e))}enableAllCellsResizeObserving(){this.observeCellBounds&&this.getCellsSorted().forEach(e=>this.enableNodeResizeObserving(e))}isElementExpanded(e){return void 0!==this.getExpandInformationForElement(e)}expandElement(e){this.addExpandInformationForElement(e),this.updateCells(!0,!1,!0)}collapseElement(e){this.removeExpandInformationForElement(e),this.updateCells(!0,!1,!0)}toggleExpandElement(e){this.isElementExpanded(e)?this.collapseElement(e):this.expandElement(e)}getExpandInformationForElement(t){return this._expandInformations.find(e=>e.element===t)}getExpandInformationForElementParent(t){return this._expandInformations.find(e=>-1<e.elementChildren.indexOf(t))}createExpandInformation(e){var t=this.getExpandInformationForElementParent(e);return{active:!0,element:e,elementIndex:(t?t.elementChildren:this._data).indexOf(e),elementChildren:this.getChildrenForElement(e),elementParent:t?t.element:void 0,index:this.getIndexForElement(e),level:t?t.level+1:1,totalLength:0}}addExpandInformationForElement(t){t=this.createExpandInformation(t);if(this._expandInformations.push(t),this.invalidateExpandInformations(),this.rememberChildrenExpands)for(let e=this._expandInformations.indexOf(t)+1;e<this._expandInformations.length;e++){var i=this._expandInformations[e],s=this._expandInformations[e-1];s.active&&s.element===i.elementParent&&(i.active=!0)}this.invalidateExpandInformations()}removeExpandInformationForElement(e){var t=this.getExpandInformationForElement(e),i=[t];for(let e=this._expandInformations.indexOf(t)+1;e<this._expandInformations.length;e++){var s=this._expandInformations[e];if(s.level<=t.level)break;i.push(s)}for(let e=0;e<i.length;e++){var l=i[e];l!==t&&this.rememberChildrenExpands?l.active=!1:this.removeElementFromArray(this._expandInformations,l)}this.invalidateExpandInformations()}invalidateExpandInformations(){this._expandInformations.sort((e,t)=>e.index-t.index);var i=[];for(let e=0;e<this._expandInformations.length;e++){var s=this._expandInformations[e],l=s.elementParent?this.getChildrenForElement(s.elementParent):this._data;let t=!1;for(let e=0;e<i.length;e++)t=i[e].element===s.elementParent||t;t||-1===l.indexOf(s.element)?(s.elementChildren=[],i.push(s)):s.elementChildren=this.getChildrenForElement(s.element)}for(let e=0;e<i.length;e++)this.removeElementFromArray(this._expandInformations,i[e]);this.calculateExpandInformationIndexes()}calculateExpandInformationIndexes(){let t=[],i=void 0,s=0;for(let e=0;e<this._expandInformations.length;e++){var l=this._expandInformations[e];if(l.active){i&&(l.level>i.level&&t.push(i),l.level<i.level)&&(t=t.slice(0,t.length-(i.level-l.level))),l.totalLength=l.elementChildren.length;for(let e=0;e<t.length;e++)t[e].totalLength+=l.totalLength;var n=0<t.length?t[t.length-1]:void 0,o=n?n.index:void 0,r=n?n.totalLength-l.totalLength:0,n=n?n.elementChildren.length:0,d=(t&&0<t.length?t[t.length-1].elementChildren:this._data).indexOf(l.element),r=r-n+d+(void 0!==o?o+1:0)+(1===l.level?s:0);l.elementIndex=d,l.index=r,i=l,s+=l.elementChildren.length}}this.updateCurrentMaxIndex()}rAF(e,t){const i=[].slice.call(arguments,2);this.virtualEnvironment?e.apply(this,i):t?(this._frameRequests[t]&&window.cancelAnimationFrame(this._frameRequests[t]),this._frameRequests[t]=window.requestAnimationFrame(()=>{e.apply(this,i),delete this._frameRequests[t]})):window.requestAnimationFrame(()=>e.apply(this,i))}removeElementFromArray(e,t){t=e?e.indexOf(t):-1;return-1<t?e.splice(t,1):void 0}}export{MNSTR as default};