react-spring-carousel 3.0.0-beta-2.0.99 → 3.0.0-beta-2.0.101

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/dist/index.es.js CHANGED
@@ -1334,7 +1334,7 @@ function Ve({
1334
1334
  "data-id": i.id,
1335
1335
  children: typeof i.renderItem == "function" ? i.renderItem({
1336
1336
  useListenToCustomEvent: at,
1337
- index: l,
1337
+ index: { index: l, clonedIndex: l % t.length },
1338
1338
  isClonedItem: !!i.isClonedItem,
1339
1339
  isActiveItem: Lt
1340
1340
  }) : i.renderItem
package/dist/index.umd.js CHANGED
@@ -44,4 +44,4 @@
44
44
  }
45
45
  }
46
46
  `).join(""):""}
47
- `)}}),M.jsx("div",{ref:E,className:"ReactSpringCarouselTrack","data-part":"Track","data-part-internal":`${n}-Track`,onScroll:()=>{k.current=!1,L.current=!1},children:It.map((i,l)=>M.jsx("div",{className:"ReactSpringCarouselItem","data-part":"Item","data-part-internal":`${n}-Item`,"data-id":i.id,children:typeof i.renderItem=="function"?i.renderItem({useListenToCustomEvent:Ie,index:l,isClonedItem:!!i.isClonedItem,isActiveItem:$t}):i.renderItem},`${i.id}-${l}`))})]}),useListenToCustomEvent:Ie,slideToNextItem:()=>se(),slideToPrevItem:()=>ie(),slideToItem:i=>{if(typeof i=="number"){if(!e[i]){console.warn(`The item you're trying to slide doesn't exist. index: ${i}`);return}i>h.current?se(i):ie(i)}if(typeof i=="string"){const l=e.findIndex(_=>_.id===i);if(l<0){console.warn(`The item you're trying to slide doesn't exist. id: ${i}`);return}l>h.current?se(l):ie(l)}}}}function Tt(t){let e=0;const r=getComputedStyle(t).getPropertyValue("gap");return r.includes("px")&&(e=Number(r.replace("px",""))),e}function Se(t){return t.scrollWidth-t.clientWidth}function re(t){const e=t.children[0],r=Tt(t);return e.getBoundingClientRect().width+r}function St({container:t,onReach:e}){const r=m.useRef("start"),n=m.useRef(0),[,s]=J.useSpring(()=>({x:0}));function o(c){s.start({from:{x:t.current.scrollLeft},to:{x:c},onChange({value:f}){t.current&&(t.current.scrollLeft=f.x)}})}function a(c){if(!t.current||c==="next"&&r.current==="end"||c==="prev"&&r.current==="start")return;let f=0;if(c==="next"&&(n.current+=1),c==="prev"&&(n.current-=1),f=n.current*re(t.current),c==="next"){const d=Se(t.current);f>d&&(r.current="end",f=d,e&&e("end"))}c==="prev"&&f<=0&&(r.current="start",n.current=0,f=0,e&&e("start")),o(f)}return m.useEffect(()=>{function c(){var j;const C=re(t.current),P=((j=[...t.current.children].at(0))==null?void 0:j.getBoundingClientRect().width)||0,O=Array(t.current.childElementCount).fill(0).map((v,k)=>({index:k,start:C*k,end:C*(k+1)})),x=t.current.scrollLeft+P,E=O.find(v=>x>=v.start&&x<v.end);n.current=(E==null?void 0:E.index)||0}function f(){s.stop()}function d(C){const P=C.target;P.scrollLeft===0?(n.current=0,r.current="start",e&&e("start")):P.scrollLeft>=Se(P)?(r.current="end",e&&e("end")):r.current!=="idle"&&(r.current="idle",e&&e("idle"))}let u,w=0;function g(){w=t.current.scrollLeft,clearTimeout(u),u=setTimeout(function(){t.current.scrollLeft===w&&c()},200)}if(t.current)return t.current.addEventListener("wheel",f,{passive:!0}),t.current.addEventListener("scroll",d),t.current.addEventListener("scroll",g),()=>{t.current&&(t.current.removeEventListener("scroll",g),t.current.removeEventListener("scroll",d),t.current.removeEventListener("wheel",f))}},[t,e]),m.useEffect(()=>{if(t.current){const c=new ResizeObserver(()=>{o(n.current*re(t.current))});return c.observe(t.current),()=>{c.disconnect()}}},[]),{scrollToNext(){a("next")},scrollToPrev(){a("prev")}}}N.useSpringCarousel=Et,N.useSpringScroll=St,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
47
+ `)}}),M.jsx("div",{ref:E,className:"ReactSpringCarouselTrack","data-part":"Track","data-part-internal":`${n}-Track`,onScroll:()=>{k.current=!1,L.current=!1},children:It.map((i,l)=>M.jsx("div",{className:"ReactSpringCarouselItem","data-part":"Item","data-part-internal":`${n}-Item`,"data-id":i.id,children:typeof i.renderItem=="function"?i.renderItem({useListenToCustomEvent:Ie,index:{index:l,clonedIndex:l%e.length},isClonedItem:!!i.isClonedItem,isActiveItem:$t}):i.renderItem},`${i.id}-${l}`))})]}),useListenToCustomEvent:Ie,slideToNextItem:()=>se(),slideToPrevItem:()=>ie(),slideToItem:i=>{if(typeof i=="number"){if(!e[i]){console.warn(`The item you're trying to slide doesn't exist. index: ${i}`);return}i>h.current?se(i):ie(i)}if(typeof i=="string"){const l=e.findIndex(_=>_.id===i);if(l<0){console.warn(`The item you're trying to slide doesn't exist. id: ${i}`);return}l>h.current?se(l):ie(l)}}}}function Tt(t){let e=0;const r=getComputedStyle(t).getPropertyValue("gap");return r.includes("px")&&(e=Number(r.replace("px",""))),e}function Se(t){return t.scrollWidth-t.clientWidth}function re(t){const e=t.children[0],r=Tt(t);return e.getBoundingClientRect().width+r}function St({container:t,onReach:e}){const r=m.useRef("start"),n=m.useRef(0),[,s]=J.useSpring(()=>({x:0}));function o(c){s.start({from:{x:t.current.scrollLeft},to:{x:c},onChange({value:f}){t.current&&(t.current.scrollLeft=f.x)}})}function a(c){if(!t.current||c==="next"&&r.current==="end"||c==="prev"&&r.current==="start")return;let f=0;if(c==="next"&&(n.current+=1),c==="prev"&&(n.current-=1),f=n.current*re(t.current),c==="next"){const d=Se(t.current);f>d&&(r.current="end",f=d,e&&e("end"))}c==="prev"&&f<=0&&(r.current="start",n.current=0,f=0,e&&e("start")),o(f)}return m.useEffect(()=>{function c(){var j;const C=re(t.current),P=((j=[...t.current.children].at(0))==null?void 0:j.getBoundingClientRect().width)||0,O=Array(t.current.childElementCount).fill(0).map((v,k)=>({index:k,start:C*k,end:C*(k+1)})),x=t.current.scrollLeft+P,E=O.find(v=>x>=v.start&&x<v.end);n.current=(E==null?void 0:E.index)||0}function f(){s.stop()}function d(C){const P=C.target;P.scrollLeft===0?(n.current=0,r.current="start",e&&e("start")):P.scrollLeft>=Se(P)?(r.current="end",e&&e("end")):r.current!=="idle"&&(r.current="idle",e&&e("idle"))}let u,w=0;function g(){w=t.current.scrollLeft,clearTimeout(u),u=setTimeout(function(){t.current.scrollLeft===w&&c()},200)}if(t.current)return t.current.addEventListener("wheel",f,{passive:!0}),t.current.addEventListener("scroll",d),t.current.addEventListener("scroll",g),()=>{t.current&&(t.current.removeEventListener("scroll",g),t.current.removeEventListener("scroll",d),t.current.removeEventListener("wheel",f))}},[t,e]),m.useEffect(()=>{if(t.current){const c=new ResizeObserver(()=>{o(n.current*re(t.current))});return c.observe(t.current),()=>{c.disconnect()}}},[]),{scrollToNext(){a("next")},scrollToPrev(){a("prev")}}}N.useSpringCarousel=Et,N.useSpringScroll=St,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
package/dist/types.d.ts CHANGED
@@ -20,7 +20,10 @@ export type ResponsiveItemsPerSlideItem = {
20
20
  export type Item = {
21
21
  id: string;
22
22
  renderItem: ReactNode | ((props: {
23
- index: number;
23
+ index: {
24
+ index: number;
25
+ clonedIndex: number;
26
+ };
24
27
  isClonedItem: boolean;
25
28
  isActiveItem(id: string | number): boolean;
26
29
  useListenToCustomEvent(eventHandler: SpringCarouselEventsEventHandler): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-spring-carousel",
3
- "version": "3.0.0-beta-2.0.99",
3
+ "version": "3.0.0-beta-2.0.101",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.umd.js",