najwer23morsels 0.10.6 → 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.
@@ -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 i,useMemo as c}from"react";import{B as s}from"./Button-BdJvyN9u.js";import{s as a}from"./style-inject.es-BnTDb6vU.js";import{u}from"./useWindowSize-CAQRbyxi.js";import{a as d,I as g}from"./IconArrowRight-Bs6HQ5lc.js";import"./Loader-CL-mm0LT.js";import"./TextBox-B47QWA9m.js";var m={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"};a("@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 f=({children:a,className:f,gap:S="5px",isCircular:p=!1})=>{const h=l(null),_=l(null),b=l(null),w=l(!1),v=l(!1),k=l(!1),x=t.toArray(a),C=x.length,L=p?x.map((r,e)=>n(r,{key:`clone-before-${e}`})):[],y=p?x.map((r,e)=>n(r,{key:`clone-after-${e}`})):[],F=l([]),M=p?[...L,...x,...y]:x,[D,j]=o([]),{width:W}=u();i(()=>{if(!h.current)return;const r=F.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))});j(r)},[a,W,S]);const N=c(()=>{const r=[];let e=0;for(const l of D)r.push(e),e+=l;return r},[D]);i(()=>{p&&h.current&&N.length&&(h.current.scrollLeft=(N[C]||0)-2*Number(S.slice(0,-2))),B()},[W,N,C,p]);const B=()=>{if(h.current){if(p)w.current=!0,v.current=!0;else{const r=h.current.scrollLeft,e=h.current.scrollWidth-h.current.clientWidth;w.current=r>0,v.current=r<e-1}X(k.current)}},X=r=>{_.current&&(_.current.disabled=r||!w.current),b.current&&(b.current.disabled=r||!v.current)},E=(r,e,l=300)=>{if(k.current)return;k.current=!0,X(!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):(k.current=!1,X(!1),B())};requestAnimationFrame(i)},T=l({isDown:!1,startX:0,scrollLeft:0,isMove:!1,isDragging:!1}),I=()=>{h.current&&(T.current.isDragging?h.current.classList.add(m.dragging):h.current.classList.remove(m.dragging))};return i(()=>{X(!1)},[]),r("div",{className:["n23mSliderScroll",f].filter(Boolean).join(" "),style:{"--sliderscroll-gap":S,height:"calc(100% - 60px)"},children:[e("div",{className:[m.n23mSliderScrollWrapper,"n23mSliderScrollWrapper"].join(" "),children:e("div",{className:m.n23mSliderScrollTrack,ref:h,onClick:r=>{T.current.isMove&&(r.preventDefault(),r.stopPropagation())},onScroll:()=>{if(h.current){if(p&&N.length&&D.length){const r=h.current.scrollLeft,e=N[N.length-1]+(D[D.length-1]||0),l=N[C]||0,t=N[C+x.length]||e;r<l-D[0]/2?h.current.scrollLeft=r+(N[x.length+C]-l):r>t+D[0]/2&&(h.current.scrollLeft=r-(t-l))}B()}},onMouseDown:r=>{T.current.isDown=!0,T.current.startX=r.pageX-(h.current?.offsetLeft||0),T.current.scrollLeft=h.current?.scrollLeft||0,T.current.isDragging=!0,I()},onMouseLeave:()=>{T.current.isDown&&(T.current.isDown=!1,T.current.isDragging=!1,I())},onMouseUp:()=>{T.current.isDown=!1,T.current.isDragging=!1,I()},onMouseMove:r=>{if(!T.current.isDown)return void(T.current.isMove=!1);r.preventDefault();var e;const l=("pageX"in(e=r)?e.pageX:"touches"in e?e.touches[0].pageX:0)-(h.current?.offsetLeft||0)-T.current.startX;Math.abs(l)>5&&(T.current.isMove=!0),h.current&&(h.current.scrollLeft=T.current.scrollLeft-l,B())},style:{whiteSpace:"nowrap"},children:M.map((r,l)=>e("div",{ref:r=>{F.current[l]=r},style:{display:"inline-block"},children:r},r.key||l))})}),e("div",{className:[m.n23mSliderScrollControls,"n23mSliderScrollControls"].join(" "),children:r("div",{className:[m.n23mSliderScrollControlsButtons,"n23mSliderScrollControlsButtons"].join(" "),children:[e(s,{ref:_,height:"50px",width:"50px",backgroundColor:"#F2F0EF",padding:0,title:"Prev",onClick:()=>{if(!h.current)return;if(!N.length||!D.length)return;const r=h.current,e=r.offsetWidth,l=r.scrollLeft;let t=0;for(let r=0;r<N.length;r++)if(N[r]>l){t=r-1;break}t<0&&(t=0);let n=0,o=0;for(let r=t;r>=0&&(n+=D[r],n<=e);r--)o++;let i=t;p||(i=Math.max(o-1,i));let c=N[i]+D[i]-e;if(c<0&&(c=0),p){c=(N[C]||0)+c-(N[C]||0)+Number(S.slice(0,-2))}E(h.current,c,400)},borderColor:"black",backgroundColorDisabled:"#F2F0EF",children:e(d,{width:24,height:24})}),e(s,{ref:b,height:"50px",width:"50px",backgroundColor:"#F2F0EF",padding:0,title:"Next",onClick:()=>{if(!h.current)return;if(!N.length||!D.length)return;const r=h.current,e=r.offsetWidth,l=r.scrollLeft;let t=N.findIndex((r,e)=>r>l);-1===t?t=N.length-1:t>0&&t--;let n,o=0,i=0;for(let r=t;r<N.length&&(o+=D[r],i++,!(o>=e));r++);const c=t+i-1;n=N[c]+D[c]>l+e+1?c:t+i,p||(n=Math.min(x.length-i,n));let s=N[n]-2*Number(S.slice(0,-2));if(s<0&&(s=0),p){s=(N[C]||0)+s-(N[C]||0)}E(h.current,s,400)},borderColor:"black",backgroundColorDisabled:"#F2F0EF",children:e(g,{width:24,height:24})})]})})]})};f.displayName="SliderScroll";export{f as SliderScroll};
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};
@@ -5,6 +5,8 @@ interface SliderScrollProps extends React.HTMLAttributes<HTMLDivElement> {
5
5
  arrowRightIcon?: ReactNode;
6
6
  gap?: string;
7
7
  isCircular?: boolean;
8
+ autoPlay?: boolean;
9
+ autoPlaySpeed?: number;
8
10
  }
9
11
  export declare const SliderScroll: React.FC<SliderScrollProps>;
10
12
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "najwer23morsels",
3
- "version": "0.10.6",
3
+ "version": "0.10.8",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./lib/index.mjs",
6
6
  "types": "./lib/index.d.ts",