import{forwardRef as e,useRef as t,useState as r,useEffect as n,useImperativeHandle as l}from"react";import{throttle as o}from"throttle-debounce";import{jsx as i,jsxs as c,Fragment as u}from"react/jsx-runtime";const s=e((e,s)=>{const{value:a=!0,list:d=[],step:f=1,limitScrollNum:m=3,hover:h=!0,direction:p="up",singleHeight:y=0,singleWidth:g=0,singleWaitTime:w=1e3,isRemUnit:b=!1,isWatch:v=!0,delay:$=0,ease:x="ease-in",count:M=-1,copyNum:T=1,wheel:N=!1,singleLine:S=!1,children:W,className:A}=e,k=t(null),E=t(null),F=t(null),H=t(null),L=t(null),q=t(!1),[z,Y]=r(0),[j,C]=r(0),[I,R]=r(0),[U,B]=r(0),[D,G]=r(0),J=d.length>=m,K={width:z?`${z}px`:"auto",transform:`translate(${I}px,${U}px)`,transition:`all ${"string"==typeof x?x:`cubic-bezier(${x.x1}, ${x.y1}, ${x.x2}, ${x.y2})`} ${$}ms`,overflow:"hidden",display:S?"flex":"block"},O="left"===p||"right"===p,P=O?{float:"left",overflow:"hidden",display:S?"flex":"block",flexShrink:S?0:1}:{overflow:"hidden"},Q=b?Number.parseInt(window.getComputedStyle(document.documentElement,null).fontSize):1,V=g*Q,X=y*Q;n(()=>{X>0&&X%f>0&&console.error("如果设置了单步滚动，step 需是单步大小的约数，否则无法保证单步滚动结束的位置是否准确。~~~~~")},[X,f]);const Z=()=>{H.current&&(cancelAnimationFrame(H.current),H.current=null)},_=(e,t,r)=>{H.current=requestAnimationFrame(()=>{const n=j/2,l=z/2;if(("up"===e||"down"===e)&&n<=0)return;if(("left"===e||"right"===e)&&l<=0)return;let o=U,i=I;"up"===e?B(e=>Math.abs(e)>=n?(G(e=>e+1),o=-t,-t):(o=e-t,e-t)):"down"===e?B(e=>e>=0?(G(e=>e+1),o=-1*n+t,-1*n+t):(o=e+t,e+t)):"left"===e?R(e=>Math.abs(e)>=l?(G(e=>e+1),i=-t,-t):(i=e-t,e-t)):"right"===e&&R(e=>e>=0?(G(e=>e+1),i=-1*l+t,-1*l+t):(i=e+t,e+t)),r||(L.current&&clearTimeout(L.current),X?Math.abs(o)%X<t?L.current=window.setTimeout(()=>{ee()},w):ee():V&&Math.abs(i)%V<t?L.current=window.setTimeout(()=>{ee()},w):ee())})},ee=()=>{Z(),!q.current&&J&&D!==M?_(p,f,!1):G(0)},te=()=>{if(d&&"boolean"!=typeof d&&d.length>100&&console.warn(`数据达到了${d.length}条有点多哦~,可能会造成部分老旧浏览器卡顿。`),O){let e=E.current?.offsetWidth||0;e=2*e+1,Y(e)}J?requestAnimationFrame(()=>{const e=F.current?.offsetHeight||0;e>0?C(e):setTimeout(()=>{const e=F.current?.offsetHeight||0;e>0&&C(e)},100)}):(Z(),R(0),B(0))},re=()=>{q.current=!1,ee()},ne=()=>{q.current=!0,L.current&&clearTimeout(L.current),Z()},le=h&&a&&J,oe=()=>{Z(),te()},ie=o(30,e=>{Z();const t=X||15;e.deltaY<0&&_("down",t,!0),e.deltaY>0&&_("up",t,!0)});l(s,()=>({reset:oe})),n(()=>{J&&te()},[J]),n(()=>{J&&a&&(j>0||z>0)&&!q.current&&ee()},[j,z]),n(()=>{a?re():ne()},[a]),n(()=>{0!==M&&re()},[M]),n(()=>{v&&oe()},[d,v]),n(()=>()=>{Z(),L.current&&clearTimeout(L.current)},[]);const ce=()=>c(u,{children:[i("div",{ref:E,style:P,children:W&&"function"==typeof W?W():W}),J?Array.from({length:T}).map((e,t)=>i("div",{style:P,children:W&&"function"==typeof W?W():W},`copy-${t}`)):null]});return i("div",{ref:k,className:A,children:i("div",N&&h?{ref:F,style:K,onMouseEnter:()=>{le&&ne()},onMouseLeave:()=>{le&&re()},onWheel:e=>{le&&ie(e)},children:ce()}:{ref:F,style:K,onMouseEnter:()=>{le&&ne()},onMouseLeave:()=>{le&&re()},children:ce()})})});s.displayName="SeamlessScroll";export{s as default};
