import{av as c,aw as u,l as S}from"./index-DDsA4eVb.js";/*!
 * Built by Revolist OU ❤️
 */const h={contentSize:0,clientSize:0,virtualSize:0,maxSize:0},n=-1;function m(r,t,i=0){return i>r?0:r+(i?t-i:0)}class f{constructor(t){this.cfg=t,this.preventArtificialScroll={rgRow:null,rgCol:null},this.previousScroll={rgRow:n,rgCol:n},this.params={rgRow:Object.assign({},h),rgCol:Object.assign({},h)}}setParams(t,i){const l=m(t.contentSize,t.clientSize,t.virtualSize);this.params[i]=Object.assign(Object.assign({},t),{maxSize:l-t.clientSize,virtualContentSize:l})}async setScroll(t){this.cancelScroll(t.dimension);const i=new Promise((l,e)=>{if(this.cfg.skipAnimationFrame)return l();const a=window.requestAnimationFrame(()=>{l()});this.preventArtificialScroll[t.dimension]=e.bind(null,a)});try{await i;const l=this.getParams(t.dimension);t.coordinate=Math.ceil(t.coordinate),this.previousScroll[t.dimension]=this.wrapCoordinate(t.coordinate,l),this.preventArtificialScroll[t.dimension]=null,this.cfg.applyScroll(Object.assign(Object.assign({},t),{coordinate:l.virtualSize?this.convert(t.coordinate,l,!1):t.coordinate}))}catch(l){window.cancelAnimationFrame(l)}}scroll(t,i,l=!1,e,a=!1){if(this.cancelScroll(i),!l&&this.previousScroll[i]===t){this.previousScroll[i]=n;return}const o=this.getParams(i);this.cfg.runScroll({dimension:i,coordinate:o.virtualSize?this.convert(t,o):t,delta:e,outside:a})}getParams(t){return this.params[t]}wrapCoordinate(t,i){return t<0?n:typeof i.maxSize=="number"&&t>i.maxSize?i.maxSize:t}cancelScroll(t){var i,l;(l=(i=this.preventArtificialScroll)[t])===null||l===void 0||l.call(i),this.preventArtificialScroll[t]=null}convert(t,i,l=!0){var e;const a=i.clientSize,o=[0,((e=i.virtualContentSize)!==null&&e!==void 0?e:a)-a],s=[0,i.contentSize-i.virtualSize];return l?c(t,o,s):c(t,s,o)}}class v{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,l;clearTimeout((l=(i=this.lastScrollUpdateCallbacks[t])===null||i===void 0?void 0:i.timeout)!==null&&l!==void 0?l:0),delete this.lastScrollUpdateCallbacks[t]}throttleLastScrollUpdate(t,i,l){if(this.scrollThrottling){this.clearLastScrollUpdate(t);const e=this.lastScrollUpdateCallbacks[t]={callback:l,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)}}}var g="Expected a function";function C(r,t,i){var l=!0,e=!0;if(typeof r!="function")throw new TypeError(g);return u(i)&&(l="leading"in i?!!i.leading:l,e="trailing"in i?!!i.trailing:e),S(r,t,{leading:l,maxWait:t,trailing:e})}export{v as L,f as a,m as g,C as t};
