najwer23morsels 0.3.0 → 0.3.1

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.
Files changed (2) hide show
  1. package/lib/Slider.js +1 -1
  2. package/package.json +1 -1
package/lib/Slider.js CHANGED
@@ -1 +1 @@
1
- import{jsxs as e,jsx as t}from"react/jsx-runtime";import r,{useState as n,useRef as l,useEffect as i,useCallback as s}from"react";import{s as o}from"./style-inject.es-BnTDb6vU.js";var a="Slider-module_sliderContainer__o7YCe",d="Slider-module_slideWrapper__Jll6Y",c="Slider-module_slide__G9U2-",m="Slider-module_sliderBtnControl__dtMGL",f="Slider-module_btn__FGB-r";o("@layer najwer23morselsSlider{.Slider-module_sliderContainer__o7YCe{display:flex;flex-direction:column;gap:10px;height:100%;position:relative;user-select:none;width:100%}.Slider-module_slideWrapper__Jll6Y{height:100%;overflow:hidden;position:relative;width:100%;will-change:transform}.Slider-module_slide__G9U2-{height:calc(100% - 2px);overflow:hidden;position:absolute;top:0;width:calc(100% - 100px);will-change:transform;&>*{height:100%;width:100%}}.Slider-module_sliderBtnControl__dtMGL{align-items:center;display:flex;font-size:20px;height:100%;justify-content:space-between;left:0;padding:0 20px;pointer-events:none;position:absolute;right:0;z-index:100}.Slider-module_btn__FGB-r{background-color:#1f487e;border:1px solid #fff;border-radius:5px;color:#fff;cursor:pointer;left:50%;padding:10px 30px;pointer-events:auto;user-select:none}}");const p=(e,t,n=!1)=>(n?e.slice(0,t):e.slice(-t)).map((e,t)=>r.cloneElement(e,{key:`${n?"clone-first":"clone-last"}-${t}`,className:e.props.className})),h=({isCircular:o=!1,children:h})=>{const u=r.Children.toArray(h).filter(r.isValidElement),[_,g]=n(o&&u.length>=2?2:0),[y,x]=n(!1),[v,w]=n(0),[b,N]=n(0),S=l(null),C=l([]),E=o&&u.length>=2?[...p(u,2,!1),...u.map((e,t)=>r.cloneElement(e,{key:e.key??t,className:e.props.className})),...p(u,2,!0)]:u.map((e,t)=>r.cloneElement(e,{key:e.key??t,className:e.props.className}));C.current.length!==E.length&&(C.current=Array(E.length).fill(null)),i(()=>{g(o&&u.length>=2?2:0)},[o,u.length]);const k=s(()=>{const e=S.current;if(!e)return;const t=C.current[0];if(!t)return;const r=window.getComputedStyle(t);w(t.offsetWidth+parseFloat(r.marginLeft)+parseFloat(r.marginRight)),N(e.offsetWidth)},[]);i(()=>(k(),window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)),[k]),i(()=>{const e=v+10;C.current.forEach((t,r)=>{if(t)if(o){const n=(r-_)*e+(b-v)/2;t.style.transition=y?"transform 0.4s cubic-bezier(.4,0,.2,1)":"none",t.style.transform=`translateX(${n}px)`,t.style.left=""}else{const n=e*(r-_)+(b-v)/2;if(y){const e=parseFloat(t.style.left||"0");t.animate([{left:`${e}px`},{left:`${n}px`}],{duration:400,easing:"ease-out",fill:"forwards"}).finished.then(()=>{t.style.left=`${n}px`,x(!1)})}else t.style.left=`${n}px`;t.style.transition="none",t.style.transform=""}})},[_,v,b,y,E.length,o]),i(()=>{if(!o||!y)return;const e=C.current.length,t=C.current[e-1];if(!t)return;const r=()=>{let n=_;1===_?n=e-3:_===e-2&&(n=2),n!==_&&g(n),x(!1),t.removeEventListener("transitionend",r)};return t.addEventListener("transitionend",r),()=>t.removeEventListener("transitionend",r)},[_,o,y]);return e("div",{className:a,children:[e("div",{className:m,children:[t("button",{className:f,onClick:()=>{y||(x(!0),g(o?e=>e-1:e=>Math.max(e-1,0)))},disabled:y,children:"Prev"}),t("button",{className:f,onClick:()=>{y||(x(!0),g(o?e=>e+1:e=>Math.min(e+1,E.length-1)))},disabled:y,children:"Next"})]}),t("div",{className:d,ref:S,children:E.map((e,r)=>t("div",{ref:e=>{C.current[r]=e},className:`${c}`,"aria-hidden":_!==r,children:e},e.key??r))})]})};h.displayName="Slider";export{h as Slider};
1
+ import{jsxs as e,jsx as t}from"react/jsx-runtime";import l,{useState as r,useRef as n,useEffect as i,useCallback as s}from"react";import{s as o}from"./style-inject.es-BnTDb6vU.js";var a="Slider-module_sliderContainer__o7YCe",d="Slider-module_slideWrapper__Jll6Y",c="Slider-module_slide__G9U2-",h="Slider-module_sliderBtnControl__dtMGL",m="Slider-module_btn__FGB-r";o("@layer najwer23morselsSlider{.Slider-module_sliderContainer__o7YCe{display:flex;flex-direction:column;gap:10px;height:100%;position:relative;user-select:none;width:100%}.Slider-module_slideWrapper__Jll6Y{height:100%;overflow:hidden;position:relative;width:100%;will-change:transform}.Slider-module_slide__G9U2-{height:calc(100% - 2px);overflow:hidden;position:absolute;top:0;width:calc(100% - 100px);will-change:transform;&>*{height:100%;width:100%}}.Slider-module_sliderBtnControl__dtMGL{align-items:center;display:flex;height:100%;justify-content:space-between;left:0;padding:0 25px;pointer-events:none;position:absolute;right:0;z-index:100}.Slider-module_btn__FGB-r{background-color:#1f487e;border:1px solid #fff;border-radius:50%;color:#fff;cursor:pointer;display:flex;left:50%;padding:10px;pointer-events:auto;user-select:none}}");const f=(e,t,r=!1)=>(r?e.slice(0,t):e.slice(-t)).map((e,t)=>l.cloneElement(e,{key:`${r?"clone-first":"clone-last"}-${t}`,className:e.props.className})),p=({isCircular:o=!1,children:p})=>{const u=l.Children.toArray(p).filter(l.isValidElement),[g,_]=r(o&&u.length>=2?2:0),[w,v]=r(!1),[y,x]=r(0),[b,C]=r(0),N=n(null),S=n([]),E=o&&u.length>=2?[...f(u,2,!1),...u.map((e,t)=>l.cloneElement(e,{key:e.key??t,className:e.props.className})),...f(u,2,!0)]:u.map((e,t)=>l.cloneElement(e,{key:e.key??t,className:e.props.className}));S.current.length!==E.length&&(S.current=Array(E.length).fill(null)),i(()=>{_(o&&u.length>=2?2:0)},[o,u.length]);const L=s(()=>{const e=N.current;if(!e)return;const t=S.current[0];if(!t)return;const l=window.getComputedStyle(t);x(t.offsetWidth+parseFloat(l.marginLeft)+parseFloat(l.marginRight)),C(e.offsetWidth)},[]);i(()=>(L(),window.addEventListener("resize",L),()=>window.removeEventListener("resize",L)),[L]),i(()=>{const e=y+10;S.current.forEach((t,l)=>{if(t)if(o){const r=(l-g)*e+(b-y)/2;t.style.transition=w?"transform 0.4s cubic-bezier(.4,0,.2,1)":"none",t.style.transform=`translateX(${r}px)`,t.style.left=""}else{const r=e*(l-g)+(b-y)/2;if(w){const e=parseFloat(t.style.left||"0");t.animate([{left:`${e}px`},{left:`${r}px`}],{duration:400,easing:"ease-out",fill:"forwards"}).finished.then(()=>{t.style.left=`${r}px`,v(!1)})}else t.style.left=`${r}px`;t.style.transition="none",t.style.transform=""}})},[g,y,b,w,E.length,o]),i(()=>{if(!o||!w)return;const e=S.current.length,t=S.current[e-1];if(!t)return;const l=()=>{let r=g;1===g?r=e-3:g===e-2&&(r=2),r!==g&&_(r),v(!1),t.removeEventListener("transitionend",l)};return t.addEventListener("transitionend",l),()=>t.removeEventListener("transitionend",l)},[g,o,w]);return e("div",{className:a,children:[e("div",{className:h,children:[t("button",{className:m,onClick:()=>{w||(v(!0),_(o?e=>e-1:e=>Math.max(e-1,0)))},disabled:w,children:t("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 320 512",width:"24",height:"24",fill:"currentColor",children:t("path",{d:"M41.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 256 246.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z"})})}),t("button",{className:m,onClick:()=>{w||(v(!0),_(o?e=>e+1:e=>Math.min(e+1,E.length-1)))},disabled:w,children:t("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 320 512",width:"24",height:"24",fill:"currentColor",children:t("path",{d:"M278.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-160 160c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L210.7 256 73.4 118.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l160 160z"})})})]}),t("div",{className:d,ref:N,children:E.map((e,l)=>t("div",{ref:e=>{S.current[l]=e},className:`${c}`,"aria-hidden":g!==l,children:e},e.key??l))})]})};p.displayName="Slider";export{p as Slider};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "najwer23morsels",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./lib/index.mjs",
6
6
  "types": "./lib/index.d.ts",