/*!
 * Built by Revolist OU ❤️
 */
import{s as t}from"./index2.js";const i={contentSize:0,clientSize:0,virtualSize:0,maxSize:0};function s(t,i,s=0){return s>t?0:t+(s?i-s:0)}class e{constructor(t){this.cfg=t,this.preventArtificialScroll={rgRow:null,rgCol:null},this.previousScroll={rgRow:-1,rgCol:-1},this.params={rgRow:Object.assign({},i),rgCol:Object.assign({},i)}}setParams(t,i){const e=s(t.contentSize,t.clientSize,t.virtualSize);this.params[i]=Object.assign(Object.assign({},t),{maxSize:e-t.clientSize,virtualContentSize:e})}async setScroll(t){this.cancelScroll(t.dimension);const i=new Promise(((i,s)=>{if(this.cfg.skipAnimationFrame)return i();const e=window.requestAnimationFrame((()=>{i()}));this.preventArtificialScroll[t.dimension]=s.bind(null,e)}));try{await i;const s=this.getParams(t.dimension);t.coordinate=Math.ceil(t.coordinate),this.previousScroll[t.dimension]=this.wrapCoordinate(t.coordinate,s),this.preventArtificialScroll[t.dimension]=null,this.cfg.applyScroll(Object.assign(Object.assign({},t),{coordinate:s.virtualSize?this.convert(t.coordinate,s,!1):t.coordinate}))}catch(t){window.cancelAnimationFrame(t)}}scroll(t,i,s=!1,e,o=!1){if(this.cancelScroll(i),!s&&this.previousScroll[i]===t)return void(this.previousScroll[i]=-1);const r=this.getParams(i);this.cfg.runScroll({dimension:i,coordinate:r.virtualSize?this.convert(t,r):t,delta:e,outside:o})}getParams(t){return this.params[t]}wrapCoordinate(t,i){return t<0?-1:"number"==typeof i.maxSize&&t>i.maxSize?i.maxSize:t}cancelScroll(t){var i,s;null===(s=(i=this.preventArtificialScroll)[t])||void 0===s||s.call(i),this.preventArtificialScroll[t]=null}convert(i,s,e=!0){var o;const r=s.clientSize,n=[0,(null!==(o=s.virtualContentSize)&&void 0!==o?o:r)-r],l=[0,s.contentSize-s.virtualSize];return e?t(i,n,l):t(i,l,n)}}class o{constructor(t=10){this.scrollThrottling=t,this.mouseWheelScrollTimestamp={rgCol:0,rgRow:0},this.lastKnownScrollCoordinate={rgCol:0,rgRow:0},this.lastScrollUpdateCallbacks={}}setCoordinate(t){this.lastKnownScrollCoordinate[t.dimension]=t.coordinate}latestScrollUpdate(t){this.mouseWheelScrollTimestamp[t]=(new Date).getTime()}isReady(t,i){return this.lastScrollUpdateCallbacks[t]&&this.clearLastScrollUpdate(t),this.verifyChange(t,i)}verifyChange(t,i){return(new Date).getTime()-this.mouseWheelScrollTimestamp[t]>this.scrollThrottling&&i!==this.lastKnownScrollCoordinate[t]}clearLastScrollUpdate(t){var i,s;clearTimeout(null!==(s=null===(i=this.lastScrollUpdateCallbacks[t])||void 0===i?void 0:i.timeout)&&void 0!==s?s:0),delete this.lastScrollUpdateCallbacks[t]}throttleLastScrollUpdate(t,i,s){if(this.scrollThrottling){this.clearLastScrollUpdate(t);const e=this.lastScrollUpdateCallbacks[t]={callback:s,timestamp:(new Date).getTime(),coordinate:i,timeout:0};e.timeout=setTimeout((()=>{this.clearLastScrollUpdate(t),this.mouseWheelScrollTimestamp[t]<e.timestamp&&this.verifyChange(t,e.coordinate)&&e.callback()}),this.scrollThrottling+50)}}}export{o as L,e as a,s as g}