UNPKG

scroll-seamless

Version:

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

3 lines (2 loc) 22.3 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("vue");class e{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 s{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 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()}}const h=class{constructor(t,i){if(this.running=!1,this.rowStates=[],this.colStates=[],this.seamlessData=[],this.seamlessColData=[],!t)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=t,this.options=this.mergeOptions(i),this.memoryManager=new e,this.domCache=new a,this.elementPool=new s(()=>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)=>{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`,t.position=0,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)}))}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.stop()}onMouseLeave(){this.options.hoverStop&&this.shouldScroll()&&this.start()}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)}}},c=t.defineComponent({name:"ScrollSeamlessVue",props:{data:{type:Array,default:()=>[]},direction:{type:String,default:"left"},minCountToScroll:{type:Number,default:2},step:{type:Number,default:1},stepWait:{type:Number,default:0},delay:{type:Number,default:0},bezier:{type:Array,default:()=>[.25,.1,.25,1]},hoverStop:{type:Boolean,default:!0},wheelEnable:{type:Boolean,default:!1},singleLine:{type:Boolean,default:!1},class:{type:[String,Object,Array],default:""},style:{type:[String,Object,Array],default:""},contentClass:{type:[String,Object,Array],default:""},itemClass:{type:[String,Object,Array],default:""},rows:{type:Number,default:1},cols:{type:Number,default:1},modelValue:{type:Boolean,default:void 0}},emits:[],setup(e,{slots:s,expose:i}){const n=t.ref(null);let o=null;const r=(e,i,n,o)=>{if(!s.default){const t=document.createElement("div");return t.textContent=e,t.style.padding="10px 15px",t.style.margin="0 10px",t.style.backgroundColor="#f0f0f0",t.style.borderRadius="4px",t.style.display="inline-block",t}const r=s.default({item:e,index:i,rowIndex:n,colIndex:o}),a=document.createElement("div");a.className="ss-slot-wrapper",a.style.display="inline-block";const l=document.createElement("div"),h=t.h("div",{},r);try{const{render:t}=require("vue");t(h,l),l.firstChild?a.appendChild(l.firstChild):a.textContent=String(e)}catch(t){a.textContent=String(e)}return a},a=()=>{if(!n.value)return;const t={direction:["left","right","up","down"].includes(e.direction)?e.direction:"left",step:Number(e.step),minCountToScroll:e.minCountToScroll,stepWait:e.stepWait,delay:e.delay,bezier:e.bezier,hoverStop:e.hoverStop,wheelEnable:e.wheelEnable,singleLine:e.singleLine,rows:e.rows,cols:e.cols,data:e.data,dataDriven:!0,renderItem:r};o&&(o.destroy(),o=null),o=new h(n.value,t),!1===e.modelValue&&o.stop()};return i({start:()=>{o&&o.start()},stop:()=>{o&&o.stop()},destroy:()=>{o&&o.destroy()},updateData:()=>{o&&o.updateData()},setOptions:t=>{o&&o.setOptions(t)},isRunning:()=>o?o.isRunning():void 0}),t.onMounted(()=>{a()}),t.onBeforeUnmount(()=>{o&&(o.destroy(),o=null)}),t.watch(()=>e.modelValue,t=>{o&&(t?o.start():o.stop())}),t.watch(()=>e.data,()=>{a()},{deep:!0}),t.watch(()=>e.step,t=>{o&&o.setOptions({step:Number(t)})}),()=>t.h("div",{ref:n,class:["scroll-seamless-vue",e.class],style:[{width:"100%",height:"100%",overflow:"hidden",position:"relative"},e.style]})}});exports.default=c; //# sourceMappingURL=index.cjs.js.map