najwer23morsels 0.10.7 → 0.10.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Sliderscroll.js +1 -1
- package/package.json +1 -1
package/lib/Sliderscroll.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as r,jsx as e}from"react/jsx-runtime";import{useRef as l,Children as t,cloneElement as n,useState as o,useEffect as
|
|
1
|
+
import{jsxs as r,jsx as e}from"react/jsx-runtime";import{useRef as l,Children as t,cloneElement as n,useState as o,useEffect as i,useMemo as c,useCallback as s}from"react";import{B as a}from"./Button-BdJvyN9u.js";import{s as u}from"./style-inject.es-BnTDb6vU.js";import{u as d}from"./useWindowSize-CAQRbyxi.js";import{a as g,I as m}from"./IconArrowRight-Bs6HQ5lc.js";import"./Loader-CL-mm0LT.js";import"./TextBox-B47QWA9m.js";var f={n23mSliderScrollWrapper:"SliderScroll-module_n23mSliderScrollWrapper__MqXIk",n23mSliderScrollTrack:"SliderScroll-module_n23mSliderScrollTrack__FcsTl",dragging:"SliderScroll-module_dragging__iE4mo",n23mSliderScrollControls:"SliderScroll-module_n23mSliderScrollControls__i64nM",n23mSliderScrollControlsButtons:"SliderScroll-module_n23mSliderScrollControlsButtons__W-5rb"};u("@layer n23mSliderScroll{.SliderScroll-module_n23mSliderScrollWrapper__MqXIk{display:grid;position:relative}.SliderScroll-module_n23mSliderScrollTrack__FcsTl{-ms-overflow-style:none;-webkit-overflow-scrolling:touch;display:flex;flex-wrap:nowrap;gap:var(--sliderscroll-gap);overflow-x:scroll;scrollbar-width:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;will-change:scroll-position;&::-webkit-scrollbar{display:none}&>*{flex-shrink:0}&.SliderScroll-module_dragging__iE4mo,&.SliderScroll-module_dragging__iE4mo a{cursor:grabbing}}.SliderScroll-module_n23mSliderScrollControls__i64nM{align-items:center;display:flex;justify-content:flex-end;margin-left:20px;margin-right:20px}.SliderScroll-module_n23mSliderScrollControlsButtons__W-5rb{display:flex;gap:10px;margin-top:10px}}");const h=({children:u,className:h,gap:S="5px",isCircular:p=!1,autoPlay:w=!1,autoPlaySpeed:b=.5})=>{const F={carousel:l(null),buttonLeft:l(null),buttonRight:l(null),showArrowLeft:l(!1),showArrowRight:l(!1),isSliding:l(!1),animationFrameId:l(null),isHovered:l(!1),drag:l({isDown:!1,startX:0,scrollLeft:0,isMove:!1,isDragging:!1}),childRefs:l([])},_=t.toArray(u),v=_.length,L=p?_.map((r,e)=>n(r,{key:`cb-${e}`})):[],k=p?_.map((r,e)=>n(r,{key:`ca-${e}`})):[],x=p?[...L,..._,...k]:_,[y,C]=o([]),{width:M}=d();i(()=>{if(!F.carousel.current)return;const r=F.childRefs.current.map(r=>{if(!r)return 0;const e=getComputedStyle(r),l=parseFloat(e.marginLeft)||0,t=parseFloat(e.marginRight)||0;return r.offsetWidth+l+t+Number(S.slice(0,-2))});C(r)},[u,M,S]);const A=c(()=>{const r=[];let e=0;for(const l of y)r.push(e),e+=l;return r},[y]);i(()=>{p&&F.carousel.current&&A.length&&(F.carousel.current.scrollLeft=(A[v]||0)-2*Number(S.slice(0,-2))),D()},[M,A,v,p]),i(()=>{I(!1)},[]),i(()=>{if(!p)return;if(!w)return void(F.animationFrameId.current&&(cancelAnimationFrame(F.animationFrameId.current),F.animationFrameId.current=null));let r;const e=()=>{if(!F.carousel.current)return;if(F.isSliding.current||F.isHovered.current)return void(F.animationFrameId.current=requestAnimationFrame(e));const r=F.carousel.current;let l=r.scrollLeft+b;if(p&&A.length&&y.length){const r=A[A.length-1]+(y[y.length-1]||0),e=A[v]||0,t=A[v+_.length]||r;l>t+y[0]/2&&(l-=t-e)}r.scrollLeft=l,D(),F.animationFrameId.current=requestAnimationFrame(e)};return r=setTimeout(()=>{F.animationFrameId.current=requestAnimationFrame(e)},500),()=>{r&&clearTimeout(r),F.animationFrameId.current&&(cancelAnimationFrame(F.animationFrameId.current),F.animationFrameId.current=null)}},[w,b,p,A,y,v,_.length]);const D=()=>{if(F.carousel.current){if(p)F.showArrowLeft.current=!0,F.showArrowRight.current=!0;else{const r=F.carousel.current.scrollLeft,e=F.carousel.current.scrollWidth-F.carousel.current.clientWidth;F.showArrowLeft.current=r>0,F.showArrowRight.current=r<e-1}I(F.isSliding.current)}},I=r=>{F.buttonLeft.current&&(F.buttonLeft.current.disabled=r||!F.showArrowLeft.current),F.buttonRight.current&&(F.buttonRight.current.disabled=r||!F.showArrowRight.current)},j=(r,e,l=300)=>{if(F.isSliding.current)return;F.isSliding.current=!0,I(!0);const t=r.scrollLeft,n=e-t,o=performance.now(),i=e=>{const c=e-o,s=Math.min(c/l,1);var a;r.scrollLeft=t+n*((a=s)<.5?4*a*a*a:1-Math.pow(-2*a+2,3)/2),s<1?requestAnimationFrame(i):(F.isSliding.current=!1,I(!1),D())};requestAnimationFrame(i)},R=s(()=>{if(!F.carousel.current)return;if(!A.length||!y.length)return;const r=F.carousel.current,e=r.offsetWidth,l=r.scrollLeft;let t=A.findIndex((r,e)=>r>l);-1===t?t=A.length-1:t>0&&t--;let n,o=0,i=0;for(let r=t;r<A.length&&(o+=y[r],i++,!(o>=e));r++);const c=t+i-1;n=A[c]+y[c]>l+e+1?c:t+i;let s=A[n]-2*Number(S.slice(0,-2));if(s<0&&(s=0),p){s=(A[v]||0)+s-(A[v]||0)}j(F.carousel.current,s,400)},[A,y,S,v,p,_.length]),W=s(()=>{if(!F.carousel.current)return;if(!A.length||!y.length)return;const r=F.carousel.current,e=r.offsetWidth,l=r.scrollLeft;let t=0;for(let r=0;r<A.length;r++)if(A[r]>l){t=r-1;break}t<0&&(t=0);let n=0,o=0;for(let r=t;r>=0&&(n+=y[r],n<=e);r--)o++;let i=t;p||(i=Math.max(o-1,i));let c=A[i]+y[i]-e;if(c<0&&(c=0),p){c=(A[v]||0)+c-(A[v]||0)+Number(S.slice(0,-2))}j(F.carousel.current,c,400)},[A,y,S,v,p]),N=()=>{F.carousel.current&&(F.drag.current.isDragging?F.carousel.current.classList.add(f.dragging):F.carousel.current.classList.remove(f.dragging))};return r("div",{className:["n23mSliderScroll",h].filter(Boolean).join(" "),style:{"--sliderscroll-gap":S,height:"calc(100% - 60px)"},onMouseEnter:()=>{F.isHovered.current=!0},onMouseLeave:()=>{F.isHovered.current=!1},children:[e("div",{className:[f.n23mSliderScrollWrapper,"n23mSliderScrollWrapper"].join(" "),children:e("div",{className:f.n23mSliderScrollTrack,ref:F.carousel,onClick:r=>{F.drag.current.isMove&&(r.preventDefault(),r.stopPropagation())},onScroll:()=>{if(F.carousel.current){if(p&&A.length&&y.length){const r=F.carousel.current.scrollLeft,e=A[A.length-1]+(y[y.length-1]||0),l=A[v]||0,t=A[v+_.length]||e;r<l-y[0]/2?F.carousel.current.scrollLeft=r+(A[_.length+v]-l):r>t+y[0]/2&&(F.carousel.current.scrollLeft=r-(t-l))}D()}},onMouseDown:r=>{F.drag.current.isDown=!0,F.drag.current.startX=r.pageX-(F.carousel.current?.offsetLeft||0),F.drag.current.scrollLeft=F.carousel.current?.scrollLeft||0,F.drag.current.isDragging=!0,N()},onMouseLeave:()=>{F.drag.current.isDown&&(F.drag.current.isDown=!1,F.drag.current.isDragging=!1,N())},onMouseUp:()=>{F.drag.current.isDown=!1,F.drag.current.isDragging=!1,N()},onMouseMove:r=>{if(!F.drag.current.isDown)return void(F.drag.current.isMove=!1);r.preventDefault();var e;const l=("pageX"in(e=r)?e.pageX:"touches"in e?e.touches[0].pageX:0)-(F.carousel.current?.offsetLeft||0)-F.drag.current.startX;Math.abs(l)>5&&(F.drag.current.isMove=!0),F.carousel.current&&(F.carousel.current.scrollLeft=F.drag.current.scrollLeft-l,D())},style:{whiteSpace:"nowrap"},children:x.map((r,l)=>e("div",{ref:r=>{F.childRefs.current[l]=r},style:{display:"inline-block"},children:r},r.key||l))})}),e("div",{className:[f.n23mSliderScrollControls,"n23mSliderScrollControls"].join(" "),children:r("div",{className:[f.n23mSliderScrollControlsButtons,"n23mSliderScrollControlsButtons"].join(" "),children:[e(a,{ref:F.buttonLeft,height:"50px",width:"50px",backgroundColor:"#F2F0EF",padding:0,title:"Prev",onClick:W,borderColor:"black",backgroundColorDisabled:"#F2F0EF",children:e(g,{width:24,height:24})}),e(a,{ref:F.buttonRight,height:"50px",width:"50px",backgroundColor:"#F2F0EF",padding:0,title:"Next",onClick:R,borderColor:"black",backgroundColorDisabled:"#F2F0EF",children:e(m,{width:24,height:24})})]})})]})};h.displayName="SliderScroll";export{h as SliderScroll};
|