UNPKG

scroll-seamless

Version:

A seamless scroll library for JS, Vue, and React.

3 lines (2 loc) 24.5 kB
class t{constructor(){this.cleanupTasks=[],this.eventListeners=new Map,this.observers=[],this.timers=new Set,this.intervals=new Set,this.rafIds=new Set,this.isDestroyed=!1}addCleanupTask(t){this.isDestroyed||this.cleanupTasks.push(t)}addEventListener(t,e,s,i){if(this.isDestroyed)return;t.addEventListener(e,s,i),this.eventListeners.has(t)||this.eventListeners.set(t,new Map);const n=this.eventListeners.get(t);n.has(e)||n.set(e,[]),n.get(e).push(s)}removeEventListener(t,e,s){t.removeEventListener(e,s);const i=this.eventListeners.get(t);if(i){const t=i.get(e);if(t){const e=t.indexOf(s);e>-1&&t.splice(e,1)}}}createMutationObserver(t,e,s){if(this.isDestroyed)throw new Error("MemoryManager已销毁,无法创建新的Observer");const i=new MutationObserver(t);return i.observe(e,s),this.observers.push(i),i}setTimeout(t,e){if(this.isDestroyed)return-1;const s=window.setTimeout(()=>{this.timers.delete(s),t()},e);return this.timers.add(s),s}setInterval(t,e){if(this.isDestroyed)return-1;const s=window.setInterval(t,e);return this.intervals.add(s),s}clearTimeout(t){window.clearTimeout(t),this.timers.delete(t)}clearInterval(t){window.clearInterval(t),this.intervals.delete(t)}requestAnimationFrame(t){if(this.isDestroyed)return-1;const e=requestAnimationFrame(s=>{this.rafIds.delete(e),t(s)});return this.rafIds.add(e),e}cancelAnimationFrame(t){cancelAnimationFrame(t),this.rafIds.delete(t)}getMemoryStats(){return{cleanupTasks:this.cleanupTasks.length,eventListeners:Array.from(this.eventListeners.values()).reduce((t,e)=>t+Array.from(e.values()).reduce((t,e)=>t+e.length,0),0),observers:this.observers.length,timers:this.timers.size,intervals:this.intervals.size,rafIds:this.rafIds.size,isDestroyed:this.isDestroyed}}destroy(){if(!this.isDestroyed){this.isDestroyed=!0,this.cleanupTasks.forEach(t=>{try{t()}catch(t){console.warn("清理任务执行失败:",t)}}),this.cleanupTasks.length=0;for(const[t,e]of this.eventListeners)for(const[s,i]of e)i.forEach(e=>{try{t.removeEventListener(s,e)}catch(t){console.warn("移除事件监听器失败:",t)}});this.eventListeners.clear(),this.observers.forEach(t=>{try{t.disconnect()}catch(t){console.warn("断开Observer失败:",t)}}),this.observers.length=0,this.timers.forEach(t=>window.clearTimeout(t)),this.timers.clear(),this.intervals.forEach(t=>window.clearInterval(t)),this.intervals.clear(),this.rafIds.forEach(t=>cancelAnimationFrame(t)),this.rafIds.clear()}}}class e{constructor(t,e,s=5,i=50){this.pool=[],this.created=0,this.factory=t,this.reset=e,this.maxSize=i;for(let t=0;t<s;t++)this.pool.push(this.factory()),this.created++}acquire(){return this.pool.length>0?this.pool.pop():(this.created++,this.factory())}release(t){this.pool.length<this.maxSize&&(this.reset(t),this.pool.push(t))}clear(){this.pool.length=0}getStats(){return{poolSize:this.pool.length,totalCreated:this.created,maxSize:this.maxSize}}}class s{constructor(){this.spanPool=new e(()=>document.createElement("span"),t=>{t.className="",t.textContent="",t.removeAttribute("style")}),this.divPool=new e(()=>document.createElement("div"),t=>{t.className="",t.innerHTML="",t.removeAttribute("style")})}acquireSpan(){return this.spanPool.acquire()}releaseSpan(t){this.spanPool.release(t)}acquireDiv(){return this.divPool.acquire()}releaseDiv(t){this.divPool.release(t)}clear(){this.spanPool.clear(),this.divPool.clear()}}class i{constructor(){this.animations=new Map,this.isRunning=!1,this.rafId=null,this.lastTimestamp=0,this.frameCount=0,this.droppedFrames=0,this.fpsHistory=[],this.maxFPSHistory=60,this.frameTimeThreshold=16.67,this.tick=()=>{if(!this.isRunning)return;const t=performance.now(),e=t-this.lastTimestamp;if(this.updateFPS(e),e<.8*this.frameTimeThreshold)return void(this.rafId=requestAnimationFrame(this.tick));const s=Array.from(this.animations.values()).sort((t,e)=>t.priority-e.priority),i=[];let n=0;const o=1.2*this.frameTimeThreshold;for(const e of s){if(e.paused)continue;const s=performance.now();try{e.callback(t)||i.push(e.id),e.lastFrameTime=t}catch(t){console.error(`动画执行错误 (${e.id}):`,t),i.push(e.id)}if(n+=performance.now()-s,n>o){this.droppedFrames++;break}}i.forEach(t=>{this.animations.delete(t)}),this.lastTimestamp=t,this.frameCount++,this.animations.size>0?this.rafId=requestAnimationFrame(this.tick):this.stop()}}static getInstance(){return i.instance||(i.instance=new i),i.instance}schedule(t){t.startTime=performance.now(),this.animations.set(t.id,t),this.isRunning||this.start()}unschedule(t){this.animations.delete(t),0===this.animations.size&&this.stop()}pause(t){const e=this.animations.get(t);e&&(e.paused=!0)}resume(t){const e=this.animations.get(t);e&&(e.paused=!1)}pauseAll(){this.animations.forEach(t=>{t.paused=!0})}resumeAll(){this.animations.forEach(t=>{t.paused=!1})}start(){this.isRunning||(this.isRunning=!0,this.lastTimestamp=performance.now(),this.tick())}stop(){this.isRunning=!1,this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=null)}updateFPS(t){const e=1e3/t;this.fpsHistory.push(e),this.fpsHistory.length>this.maxFPSHistory&&this.fpsHistory.shift()}getPerformanceMetrics(){const t=this.fpsHistory.length>0?this.fpsHistory.reduce((t,e)=>t+e,0)/this.fpsHistory.length:0;return{fps:Math.round(t),frameTime:this.fpsHistory.length>0?1e3/t:0,droppedFrames:this.droppedFrames,activeAnimations:this.animations.size}}getStatus(){return{isRunning:this.isRunning,frameCount:this.frameCount,...this.getPerformanceMetrics()}}resetStats(){this.frameCount=0,this.droppedFrames=0,this.fpsHistory.length=0}destroy(){this.stop(),this.animations.clear(),this.resetStats(),i.instance=null}}i.instance=null;class n{static generateId(t="anim"){return`${t}_${++this.idCounter}_${Date.now()}`}static createTransformAnimation(t,e,s,i,n=t=>t){const o=this.generateId("transform");let r=null;return{id:o,priority:1,callback:o=>{r||(r=o);const a=o-r,l=Math.min(a/i,1),h=n(l),c=e.x+(s.x-e.x)*h,d=e.y+(s.y-e.y)*h;return t.style.transform=`translate(${c}px, ${d}px)`,l<1}}}static createScrollAnimation(t,e,s,i){const n=this.generateId("scroll");let o=0,r=null;return{id:n,priority:1,callback:n=>{r||(r=n);const a=s*(n-r)/16.67;switch(e){case"left":case"up":o+=a,o>=i&&(o=0);break;case"right":case"down":o-=a,o<=-i&&(o=0)}return t.style.transform="left"===e||"right"===e?`translateX(${-o}px)`:`translateY(${-o}px)`,r=n,!0}}}}n.idCounter=0;const o=i.getInstance();class r{constructor(t){this.cache=new Map,this.capacity=t}get(t){if(this.cache.has(t)){const e=this.cache.get(t);return this.cache.delete(t),this.cache.set(t,e),e}}set(t,e){if(this.cache.has(t))this.cache.delete(t);else if(this.cache.size>=this.capacity){const t=this.cache.keys().next().value;void 0!==t&&this.cache.delete(t)}this.cache.set(t,e)}clear(){this.cache.clear()}size(){return this.cache.size}}class a{constructor(t=100){this.resizeObserver=null,this.observedElements=new WeakSet,this.cacheTimeout=5e3,this.measurementCache=new r(t),this.textSizeCache=new r(2*t),"undefined"!=typeof ResizeObserver&&(this.resizeObserver=new ResizeObserver(t=>{t.forEach(t=>{const e=t.target,s=this.getElementKey(e);this.measurementCache.set(s,this.measureElement(e))})}))}getElementKey(t){var e;return`${t.tagName}_${t.className}_${t.id}_${null===(e=t.textContent)||void 0===e?void 0:e.slice(0,50)}`}getTextKey(t,e,s){return`${t}_${e}_${s||""}`}measureElement(t){const e=t.getBoundingClientRect();return{width:e.width,height:e.height,offsetWidth:t.offsetWidth,offsetHeight:t.offsetHeight,scrollWidth:t.scrollWidth,scrollHeight:t.scrollHeight,timestamp:Date.now()}}getElementMeasurement(t,e=!1){const s=this.getElementKey(t);if(!e){const t=this.measurementCache.get(s);if(t&&Date.now()-t.timestamp<this.cacheTimeout)return t}this.resizeObserver&&!this.observedElements.has(t)&&(this.resizeObserver.observe(t),this.observedElements.add(t));const i=this.measureElement(t);return this.measurementCache.set(s,i),i}measureText(t,e="ss-item",s){const i=s?JSON.stringify(s):"",n=this.getTextKey(t,e,i),o=this.textSizeCache.get(n);if(o)return o;const r=document.createElement("span");r.className=e,r.textContent=t,r.style.position="absolute",r.style.visibility="hidden",r.style.whiteSpace="nowrap",s&&Object.assign(r.style,s),document.body.appendChild(r);const a={width:r.offsetWidth,height:r.offsetHeight};return document.body.removeChild(r),this.textSizeCache.set(n,a),a}measureTextBatch(t,e="ss-item",s){const i=[],n=[];if(t.forEach((t,o)=>{const r=s?JSON.stringify(s):"",a=this.getTextKey(t,e,r),l=this.textSizeCache.get(a);l?i[o]=l:n.push({text:t,index:o})}),n.length>0){const t=document.createElement("div");t.style.position="absolute",t.style.visibility="hidden",t.style.whiteSpace="nowrap",document.body.appendChild(t),n.forEach(({text:n,index:o})=>{const r=document.createElement("span");r.className=e,r.textContent=n,s&&Object.assign(r.style,s),t.appendChild(r);const a={width:r.offsetWidth,height:r.offsetHeight};i[o]=a;const l=s?JSON.stringify(s):"",h=this.getTextKey(n,e,l);this.textSizeCache.set(h,a)}),document.body.removeChild(t)}return i}clearExpiredCache(){const t=new r(this.measurementCache.size());this.measurementCache.clear(),this.measurementCache=t}getCacheStats(){return{measurementCacheSize:this.measurementCache.size(),textCacheSize:this.textSizeCache.size(),observedElements:this.observedElements?"WeakSet (无法计数)":0,hasResizeObserver:!!this.resizeObserver}}destroy(){this.measurementCache.clear(),this.textSizeCache.clear(),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}}class l{constructor(t){this.plugins=new Map,this.controller=t}register(t){if(this.plugins.has(t.id))console.warn(`Plugin with id "${t.id}" is already registered. Skipping.`);else try{t.apply(this.controller),this.plugins.set(t.id,t)}catch(e){console.error(`Failed to register plugin "${t.id}":`,e)}}unregister(t){const e=this.plugins.get(t);if(e)try{e.destroy&&e.destroy(),this.plugins.delete(t)}catch(e){console.error(`Failed to unregister plugin "${t}":`,e)}else console.warn(`Plugin with id "${t}" is not registered. Skipping.`)}getPlugin(t){return this.plugins.get(t)||null}getPlugins(){return Array.from(this.plugins.values())}destroyAll(){for(const[t,e]of this.plugins.entries())try{e.destroy&&e.destroy()}catch(e){console.error(`Failed to destroy plugin "${t}":`,e)}this.plugins.clear()}}class h{constructor(s,i){if(this.running=!1,this.rowStates=[],this.colStates=[],this.seamlessData=[],this.seamlessColData=[],!s)throw new Error("ScrollEngine: Container element is required");if(!i.data||!Array.isArray(i.data)||0===i.data.length)throw new Error("ScrollEngine: Data array is required and cannot be empty");this.container=s,this.options=this.mergeOptions(i),this.memoryManager=new t,this.domCache=new a,this.elementPool=new e(()=>document.createElement("span"),t=>{t.className="ss-item",t.textContent="",t.removeAttribute("style")}),this.pluginManager=new l(this),this.options.plugins&&this.options.plugins.length>0&&this.options.plugins.forEach(t=>{this.pluginManager.register(t)}),this.initialize()}mergeOptions(t){return{data:[],direction:"left",minCountToScroll:2,step:1,stepWait:0,delay:0,bezier:[.25,.1,.25,1],hoverStop:!0,wheelEnable:!1,singleLine:!1,rows:1,cols:1,onEvent:()=>{},plugins:[],performance:{enabled:!0},accessibility:{enabled:!0},dataDriven:!1,...t}}initialize(){try{this.setupContainer(),this.createScrollElements(),this.bindEvents(),this.layout(),this.shouldScroll()&&this.start()}catch(t){console.error("ScrollEngine initialization failed:",t),this.handleError(t)}}setupContainer(){this.container.style.overflow="hidden",this.container.style.position="relative"}createScrollElements(){"left"===this.options.direction||"right"===this.options.direction?this.createHorizontalElements():this.createVerticalElements()}createHorizontalElements(){const t=Math.max(1,this.options.rows);for(let e=0;e<t;e++){const s=this.createElement("div","scroll-seamless-row");this.setElementStyle(s,{position:"absolute",left:"0",top:100/t*e+"%",width:"100%",height:100/t+"%",overflow:"hidden",display:"flex",alignItems:"center"});const i=this.createElement("div","ss-content"),n=this.createElement("div","ss-content");this.setContentStyle(i,!0),this.setContentStyle(n,!0),i.style.left="0",s.appendChild(i),s.appendChild(n),this.container.appendChild(s),this.rowStates.push({content1:i,content2:n,position:0,animationId:null})}}createVerticalElements(){const t=Math.max(1,this.options.cols);for(let e=0;e<t;e++){const e=this.createElement("div","scroll-seamless-col");this.setElementStyle(e,{position:"relative",height:"100%",overflow:"hidden",width:100/t+"%",display:"inline-block",textAlign:"center"});const s=this.createElement("div","ss-content"),i=this.createElement("div","ss-content");this.setContentStyle(s,!1),this.setContentStyle(i,!1),s.style.top="0",e.appendChild(s),e.appendChild(i),this.container.appendChild(e),this.colStates.push({content1:s,content2:i,position:0,animationId:null})}}createElement(t,e){const s=document.createElement(t);return s.className=e,s}setElementStyle(t,e){Object.assign(t.style,e)}setContentStyle(t,e){const s={position:"absolute",top:"0",left:"0",boxSizing:"border-box",display:e?"inline-block":"block",whiteSpace:e?"nowrap":"normal"};e||(s.width="100%"),this.setElementStyle(t,s)}bindEvents(){this.options.hoverStop&&(this.memoryManager.addEventListener(this.container,"mouseenter",this.onMouseEnter.bind(this)),this.memoryManager.addEventListener(this.container,"mouseleave",this.onMouseLeave.bind(this))),this.options.wheelEnable&&this.memoryManager.addEventListener(this.container,"wheel",t=>{this.onWheel(t)},{passive:!1})}layout(){"left"===this.options.direction||"right"===this.options.direction?this.layoutHorizontal():this.layoutVertical(),this.renderContent()}layoutHorizontal(){this.seamlessData=[];for(let t=0;t<this.rowStates.length;t++){const e=this.rowStates[t].content1.parentElement;if(!e)continue;const s=this.domCache.getElementMeasurement(e).width,i=this.calculateSeamlessItems(s,!0);this.seamlessData[t]=i}}layoutVertical(){this.seamlessColData=[];for(let t=0;t<this.colStates.length;t++){const e=this.colStates[t].content1.parentElement;if(!e)continue;const s=this.domCache.getElementMeasurement(e).height,i=this.calculateSeamlessItems(s,!1);this.seamlessColData[t]=i}}calculateSeamlessItems(t,e){const s=[];let i=0;const n=3*t+50,o=this.domCache.measureTextBatch(this.options.data,"ss-item"),r=e?5:2;let a=0;for(;i<n&&a<20*this.options.data.length;){const t=a%this.options.data.length,n=this.options.data[t],l=o[t];s.push(n),i+=(e?l.width:l.height)+r,a++}return s}renderContent(){"left"===this.options.direction||"right"===this.options.direction?this.renderHorizontalContent():this.renderVerticalContent()}renderHorizontalContent(){for(let t=0;t<this.rowStates.length;t++){const e=this.rowStates[t],s=this.seamlessData[t]||[];this.renderStateContent(e,s)}}renderVerticalContent(){for(let t=0;t<this.colStates.length;t++){const e=this.colStates[t],s=this.seamlessColData[t]||[];this.renderStateContent(e,s)}}renderStateContent(t,e){t.content1.innerHTML="",t.content2.innerHTML="";const s="left"===this.options.direction||"right"===this.options.direction;e.forEach((e,i)=>{let n,o;if(this.options.renderItem){const s=this.rowStates.indexOf(t)>=0?this.rowStates.indexOf(t):void 0,r=this.colStates.indexOf(t)>=0?this.colStates.indexOf(t):void 0;n=this.options.renderItem(e,i,s,r),o=n.cloneNode(!0)}else n=this.elementPool.acquire(),o=this.elementPool.acquire(),n.textContent=e,o.textContent=e,s?(n.style.marginRight="10px",o.style.marginRight="10px",n.style.display="inline-block",o.style.display="inline-block"):(n.style.marginBottom="5px",o.style.marginBottom="5px",n.style.display="block",o.style.display="block");t.content1.appendChild(n),t.content2.appendChild(o)})}shouldScroll(){return this.options.data.length>=this.options.minCountToScroll}start(){var t,e;if(this.running)return;this.running=!0,null===(e=(t=this.options).onEvent)||void 0===e||e.call(t,"start",{direction:this.options.direction});("left"===this.options.direction||"right"===this.options.direction?this.rowStates:this.colStates).forEach((t,e)=>{void 0===t.position&&(t.position=0);const s=n.generateId("scroll");t.animationId=s;const i=this.createScrollAnimation(t,e);o.schedule(i)})}createScrollAnimation(t,e){const s="left"===this.options.direction||"right"===this.options.direction,i="right"===this.options.direction||"down"===this.options.direction,n=s?t.content1.scrollWidth:t.content1.scrollHeight;return s?t.content2.style.left=`${n}px`:t.content2.style.top=`${n}px`,s?(t.content1.style.transform="translateX(0)",t.content2.style.transform="translateX(0)",t.content2.style.left=`${n}px`):(t.content1.style.transform="translateY(0)",t.content2.style.transform="translateY(0)",t.content2.style.top=`${n}px`),{id:t.animationId,priority:1,callback:e=>{if(!this.running)return!1;const o=this.options.step;return i?(t.position-=o,t.position<=-n&&(t.position=0)):(t.position+=o,t.position>=n&&(t.position=0)),s?(t.content1.style.transform=`translateX(${i?t.position:-t.position}px)`,t.content2.style.transform=`translateX(${i?t.position:-t.position}px)`):(t.content1.style.transform=`translateY(${i?t.position:-t.position}px)`,t.content2.style.transform=`translateY(${i?t.position:-t.position}px)`),!0}}}stop(){var t,e;this.running&&(this.running=!1,null===(e=(t=this.options).onEvent)||void 0===e||e.call(t,"stop",{direction:this.options.direction}),[...this.rowStates,...this.colStates].forEach(t=>{t.animationId&&(o.unschedule(t.animationId),t.animationId=null)}))}pause(){var t,e;this.running&&([...this.rowStates,...this.colStates].forEach(t=>{t.animationId&&o.pause(t.animationId)}),null===(e=(t=this.options).onEvent)||void 0===e||e.call(t,"pause",{direction:this.options.direction}))}resume(){var t,e;this.running&&([...this.rowStates,...this.colStates].forEach(t=>{t.animationId&&o.resume(t.animationId)}),null===(e=(t=this.options).onEvent)||void 0===e||e.call(t,"resume",{direction:this.options.direction}))}destroy(){var t,e;this.stop(),this.pluginManager.destroyAll(),this.memoryManager.destroy(),this.domCache.destroy(),this.elementPool.clear(),this.container.innerHTML="",null===(e=(t=this.options).onEvent)||void 0===e||e.call(t,"destroy",{direction:this.options.direction})}updateData(){const t=this.running;t&&this.stop(),[...this.rowStates,...this.colStates].forEach(t=>{t.position=0,t.content1.style.transform="",t.content2.style.transform=""}),this.layout(),t&&this.shouldScroll()&&setTimeout(()=>this.start(),20)}setOptions(t){const e=this.running;this.stop(),this.options={...this.options,...t},this.layout(),e&&this.shouldScroll()&&this.start()}isRunning(){return this.running}getRenderMatrix(){return"left"===this.options.direction||"right"===this.options.direction?this.seamlessData:this.seamlessColData}getTransforms(){const t="left"===this.options.direction||"right"===this.options.direction;return(t?this.rowStates:this.colStates).map(e=>t?`translateX(${-e.position}px)`:`translateY(${-e.position}px)`)}addPlugin(t){this.pluginManager.register(t)}removePlugin(t){this.pluginManager.unregister(t)}getPosition(){const t="left"===this.options.direction||"right"===this.options.direction?this.rowStates:this.colStates;return 0===t.length?0:t[0].position}setPosition(t){const e="left"===this.options.direction||"right"===this.options.direction;(e?this.rowStates:this.colStates).forEach(s=>{s.position=t;const i=e?s.content1.scrollWidth:s.content1.scrollHeight,n=e?`translateX(${-t}px)`:`translateY(${-t}px)`,o=e?`translateX(${-t+i}px)`:`translateY(${-t+i}px)`;s.content1.style.transform=n,s.content2.style.transform=o})}getPerformance(){const t=this.pluginManager.getPlugin("performance");return t&&"getMetrics"in t?t.getMetrics():{fps:o.getPerformanceMetrics().fps,memory:null,timing:{renderTime:0,animationTime:0},elements:{total:this.container.querySelectorAll("*").length,visible:this.container.querySelectorAll(".ss-item").length}}}onMouseEnter(){this.options.hoverStop&&this.pause()}onMouseLeave(){this.options.hoverStop&&this.shouldScroll()&&this.resume()}onWheel(t){this.options.wheelEnable&&t.preventDefault()}handleError(t){var e,s;console.error("ScrollEngine Error:",t),null===(s=(e=this.options).onEvent)||void 0===s||s.call(e,"error",{type:"error",direction:this.options.direction,error:t.message,stack:t.stack});try{this.stop(),this.rowStates.forEach(t=>{t.position=0,t.content1.style.transform="none",t.content2.style.transform="none"}),this.colStates.forEach(t=>{t.position=0,t.content1.style.transform="none",t.content2.style.transform="none"}),this.options.performance&&this.options.performance.autoRestart&&setTimeout(()=>{this.shouldScroll()&&this.start()},1e3)}catch(t){console.error("ScrollEngine Recovery Failed:",t)}}}class c{constructor(t={}){this.id="performance",this.controller=null,this.monitoringInterval=null,this.options={enabled:!1!==t.enabled,fps:!1!==t.fps,memory:!1!==t.memory,timing:!1!==t.timing,onUpdate:t.onUpdate||(()=>{}),autoRestart:!1!==t.autoRestart},this.metrics={fps:0,memory:null,timing:{renderTime:0,animationTime:0},elements:{total:0,visible:0}}}apply(t){this.controller=t,this.options.enabled&&this.startMonitoring()}destroy(){this.stopMonitoring(),this.controller=null}startMonitoring(){this.monitoringInterval||(this.monitoringInterval=window.setInterval(()=>{this.updateMetrics()},1e3))}stopMonitoring(){this.monitoringInterval&&(clearInterval(this.monitoringInterval),this.monitoringInterval=null)}updateMetrics(){if(this.options.fps){const t=o.getPerformanceMetrics();this.metrics.fps=t.fps}if(this.options.memory&&window.performance&&performance.memory){const t=performance.memory;this.metrics.memory={jsHeapSizeLimit:t.jsHeapSizeLimit,totalJSHeapSize:t.totalJSHeapSize,usedJSHeapSize:t.usedJSHeapSize}}const t=document.querySelector(".scroll-seamless-vue");t&&(this.metrics.elements.total=t.querySelectorAll("*").length,this.metrics.elements.visible=t.querySelectorAll(".ss-item").length),this.options.onUpdate&&this.options.onUpdate(this.metrics)}getMetrics(){return{...this.metrics}}}const d=["left","right","up","down"];function m(t){return d.includes(t)?t:"left"}function p(t,e,s,i){return"left"===t?`translateX(${-e+(i?s:0)}px)`:"right"===t?`translateX(${-e-(i?s:0)}px)`:"up"===t?`translateY(${-e+(i?s:0)}px)`:"down"===t?`translateY(${-e-(i?s:0)}px)`:""}function u(t,e,s,i){return"left"===t||"up"===t?(e+=s)>=i&&(e=0):"right"!==t&&"down"!==t||(e-=s)<=-i&&(e=0),e}function f(t){return"left"===t||"right"===t?{position:"absolute",top:0,left:0,display:"inline-block",whiteSpace:"nowrap",verticalAlign:"top"}:{position:"absolute",top:0,left:0,display:"block",whiteSpace:"normal"}}function g(t,e,s){"function"==typeof t&&t(e,s)}function y(t,e){return"right"===e||"down"===e?t.slice().reverse():t}function v(t,e){let s=null;return function(...i){s&&clearTimeout(s),s=window.setTimeout(()=>{t.apply(this,i),s=null},e)}}function w(t,e){let s=0;return function(...i){const n=Date.now();n-s>=e&&(t.apply(this,i),s=n)}}function S(){return{requestAnimationFrame:"undefined"!=typeof window&&"requestAnimationFrame"in window,intersectionObserver:"undefined"!=typeof window&&"IntersectionObserver"in window,resizeObserver:"undefined"!=typeof window&&"ResizeObserver"in window,passiveEvents:E(),webAnimations:"undefined"!=typeof Element&&"animate"in Element.prototype,transforms:b("transform"),willChange:b("willChange")}}function E(){let t=!1;try{const e=Object.defineProperty({},"passive",{get:function(){return t=!0,!0}});window.addEventListener("testPassive",null,e),window.removeEventListener("testPassive",null,e)}catch(t){}return t}function b(t){return"undefined"!=typeof document&&document.documentElement&&t in document.documentElement.style}function C(t){try{return t()}catch(t){return console.error("DOM操作失败:",t),null}}const x={direction:"left",minCountToScroll:2,step:1,stepWait:0,delay:0,bezier:[.25,.1,.25,1],hoverStop:!0,wheelEnable:!1,singleLine:!1,rows:1,cols:1,onEvent:()=>{},plugins:[],performance:{enabled:!0},accessibility:{enabled:!0},dataDriven:!1};function z(t,e){return new h(t,e)}const I=h;export{n as AnimationHelper,x as DEFAULT_OPTIONS,a as DOMCache,s as DOMElementPool,t as MemoryManager,e as ObjectPool,c as PerformancePlugin,l as PluginManager,i as RAFScheduler,z as createScrollSeamless,v as debounce,I as default,S as detectBrowserFeatures,g as fireEvent,f as getContentStyle,p as getContentTransform,m as getLegalDirection,u as getNextPosition,y as getRenderData,d as legalDirections,o as rafScheduler,C as safeDOM,w as throttle}; //# sourceMappingURL=index.esm.js.map