najwer23morsels 0.10.6 → 0.10.7

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 c,useMemo as i,useCallback as s}from"react";import{B as u}from"./Button-BdJvyN9u.js";import{s as a}from"./style-inject.es-BnTDb6vU.js";import{u as d}from"./useWindowSize-CAQRbyxi.js";import{a as m,I as g}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"};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 S=({children:a,className:S,gap:p="5px",isCircular:h=!1,autoPlay:_=!1,autoPlaySpeed:b=.5})=>{const v=l(null),w=l(null),k=l(null),x=l(!1),L=l(!1),F=l(!1),y=l(null),C=l(!1),M=t.toArray(a),D=M.length,j=h?M.map((r,e)=>n(r,{key:`cb-${e}`})):[],W=h?M.map((r,e)=>n(r,{key:`ca-${e}`})):[],N=l([]),A=h?[...j,...M,...W]:M,[B,X]=o([]),{width:E}=d();c(()=>{if(!v.current)return;const r=N.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(p.slice(0,-2))});X(r)},[a,E,p]);const q=i(()=>{const r=[];let e=0;for(const l of B)r.push(e),e+=l;return r},[B]);c(()=>{h&&v.current&&q.length&&(v.current.scrollLeft=(q[D]||0)-2*Number(p.slice(0,-2))),T()},[E,q,D,h]);const T=()=>{if(v.current){if(h)x.current=!0,L.current=!0;else{const r=v.current.scrollLeft,e=v.current.scrollWidth-v.current.clientWidth;x.current=r>0,L.current=r<e-1}I(F.current)}},I=r=>{w.current&&(w.current.disabled=r||!x.current),k.current&&(k.current.disabled=r||!L.current)},P=(r,e,l=300)=>{if(F.current)return;F.current=!0,I(!0);const t=r.scrollLeft,n=e-t,o=performance.now(),c=e=>{const i=e-o,s=Math.min(i/l,1);var u;r.scrollLeft=t+n*((u=s)<.5?4*u*u*u:1-Math.pow(-2*u+2,3)/2),s<1?requestAnimationFrame(c):(F.current=!1,I(!1),T())};requestAnimationFrame(c)},z=s(()=>{if(!v.current)return;if(!q.length||!B.length)return;const r=v.current,e=r.offsetWidth,l=r.scrollLeft;let t=q.findIndex((r,e)=>r>l);-1===t?t=q.length-1:t>0&&t--;let n,o=0,c=0;for(let r=t;r<q.length&&(o+=B[r],c++,!(o>=e));r++);const i=t+c-1;n=q[i]+B[i]>l+e+1?i:t+c;let s=q[n]-2*Number(p.slice(0,-2));if(s<0&&(s=0),h){s=(q[D]||0)+s-(q[D]||0)}P(v.current,s,400)},[q,B,p,D,h,M.length]),R=s(()=>{if(!v.current)return;if(!q.length||!B.length)return;const r=v.current,e=r.offsetWidth,l=r.scrollLeft;let t=0;for(let r=0;r<q.length;r++)if(q[r]>l){t=r-1;break}t<0&&(t=0);let n=0,o=0;for(let r=t;r>=0&&(n+=B[r],n<=e);r--)o++;let c=t;h||(c=Math.max(o-1,c));let i=q[c]+B[c]-e;if(i<0&&(i=0),h){i=(q[D]||0)+i-(q[D]||0)+Number(p.slice(0,-2))}P(v.current,i,400)},[q,B,p,D,h]),$=l({isDown:!1,startX:0,scrollLeft:0,isMove:!1,isDragging:!1}),U=()=>{v.current&&($.current.isDragging?v.current.classList.add(f.dragging):v.current.classList.remove(f.dragging))};c(()=>{I(!1)},[]);return c(()=>{if(!h)return;if(!_)return void(y.current&&(cancelAnimationFrame(y.current),y.current=null));const r=()=>{if(!v.current)return;if(F.current||C.current)return void(y.current=requestAnimationFrame(r));const e=v.current;let l=e.scrollLeft+b;if(h&&q.length&&B.length){const r=q[q.length-1]+(B[B.length-1]||0),e=q[D]||0,t=q[D+M.length]||r;l>t+B[0]/2&&(l-=t-e)}e.scrollLeft=l,T(),y.current=requestAnimationFrame(r)};return y.current=requestAnimationFrame(r),()=>{y.current&&(cancelAnimationFrame(y.current),y.current=null)}},[_,b,h,q,B,D,M.length]),r("div",{className:["n23mSliderScroll",S].filter(Boolean).join(" "),style:{"--sliderscroll-gap":p,height:"calc(100% - 60px)"},onMouseEnter:()=>{C.current=!0},onMouseLeave:()=>{C.current=!1},children:[e("div",{className:[f.n23mSliderScrollWrapper,"n23mSliderScrollWrapper"].join(" "),children:e("div",{className:f.n23mSliderScrollTrack,ref:v,onClick:r=>{$.current.isMove&&(r.preventDefault(),r.stopPropagation())},onScroll:()=>{if(v.current){if(h&&q.length&&B.length){const r=v.current.scrollLeft,e=q[q.length-1]+(B[B.length-1]||0),l=q[D]||0,t=q[D+M.length]||e;r<l-B[0]/2?v.current.scrollLeft=r+(q[M.length+D]-l):r>t+B[0]/2&&(v.current.scrollLeft=r-(t-l))}T()}},onMouseDown:r=>{$.current.isDown=!0,$.current.startX=r.pageX-(v.current?.offsetLeft||0),$.current.scrollLeft=v.current?.scrollLeft||0,$.current.isDragging=!0,U()},onMouseLeave:()=>{$.current.isDown&&($.current.isDown=!1,$.current.isDragging=!1,U())},onMouseUp:()=>{$.current.isDown=!1,$.current.isDragging=!1,U()},onMouseMove:r=>{if(!$.current.isDown)return void($.current.isMove=!1);r.preventDefault();var e;const l=("pageX"in(e=r)?e.pageX:"touches"in e?e.touches[0].pageX:0)-(v.current?.offsetLeft||0)-$.current.startX;Math.abs(l)>5&&($.current.isMove=!0),v.current&&(v.current.scrollLeft=$.current.scrollLeft-l,T())},style:{whiteSpace:"nowrap"},children:A.map((r,l)=>e("div",{ref:r=>{N.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(u,{ref:w,height:"50px",width:"50px",backgroundColor:"#F2F0EF",padding:0,title:"Prev",onClick:R,borderColor:"black",backgroundColorDisabled:"#F2F0EF",children:e(m,{width:24,height:24})}),e(u,{ref:k,height:"50px",width:"50px",backgroundColor:"#F2F0EF",padding:0,title:"Next",onClick:z,borderColor:"black",backgroundColorDisabled:"#F2F0EF",children:e(g,{width:24,height:24})})]})})]})};S.displayName="SliderScroll";export{S 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.7",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./lib/index.mjs",
6
6
  "types": "./lib/index.d.ts",