react-spring-carousel 3.0.0-beta-2.1.6 → 3.0.0-beta-2.2.0
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 +547 -588
- package/dist/index.umd.js +7 -7
- package/dist/useSpringCarousel.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(M,L){typeof exports=="object"&&typeof module<"u"?L(exports,require("react/jsx-runtime"),require("@react-spring/web"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@react-spring/web","react"],L):(M=typeof globalThis<"u"?globalThis:M||self,L(M["react-spring-carousel"]={},M["react/jsx-runtime"],M["@react-spring/web"],M.React))})(this,function(M,L,se,d){"use strict";function Be(r,e,t){return Math.max(e,Math.min(r,t))}const S={toVector(r,e){return r===void 0&&(r=e),Array.isArray(r)?r:[r,r]},add(r,e){return[r[0]+e[0],r[1]+e[1]]},sub(r,e){return[r[0]-e[0],r[1]-e[1]]},addTo(r,e){r[0]+=e[0],r[1]+=e[1]},subTo(r,e){r[0]-=e[0],r[1]-=e[1]}};function ge(r,e,t){return e===0||Math.abs(e)===1/0?Math.pow(r,t*5):r*e*t/(e+t*r)}function me(r,e,t,n=.15){return n===0?Be(r,e,t):r<e?-ge(e-r,t-e,n)+e:r>t?+ge(r-t,t-e,n)+t:r}function Ue(r,[e,t],[n,s]){const[[a,o],[c,u]]=r;return[me(e,a,o,n),me(t,c,u,s)]}function ze(r,e){if(typeof r!="object"||r===null)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var n=t.call(r,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function Ke(r){var e=ze(r,"string");return typeof e=="symbol"?e:String(e)}function $(r,e,t){return e=Ke(e),e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function ve(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(s){return Object.getOwnPropertyDescriptor(r,s).enumerable})),t.push.apply(t,n)}return t}function _(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?ve(Object(t),!0).forEach(function(n){$(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):ve(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}const ye={pointer:{start:"down",change:"move",end:"up"},mouse:{start:"down",change:"move",end:"up"},touch:{start:"start",change:"move",end:"end"},gesture:{start:"start",change:"change",end:"end"}};function be(r){return r?r[0].toUpperCase()+r.slice(1):""}const Fe=["enter","leave"];function Ge(r=!1,e){return r&&!Fe.includes(e)}function We(r,e="",t=!1){const n=ye[r],s=n&&n[e]||e;return"on"+be(r)+be(s)+(Ge(t,s)?"Capture":"")}const Ye=["gotpointercapture","lostpointercapture"];function He(r){let e=r.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const n=Ye.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(n);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:t}}function qe(r,e=""){const t=ye[r],n=t&&t[e]||e;return r+n}function ee(r){return"touches"in r}function _e(r){return ee(r)?"touch":"pointerType"in r?r.pointerType:"mouse"}function Xe(r){return Array.from(r.touches).filter(e=>{var t,n;return e.target===r.currentTarget||((t=r.currentTarget)===null||t===void 0||(n=t.contains)===null||n===void 0?void 0:n.call(t,e.target))})}function Je(r){return r.type==="touchend"||r.type==="touchcancel"?r.changedTouches:r.targetTouches}function we(r){return ee(r)?Je(r)[0]:r}function Qe(r){return Xe(r).map(e=>e.identifier)}function ie(r){const e=we(r);return ee(r)?e.identifier:e.pointerId}function xe(r){const e=we(r);return[e.clientX,e.clientY]}function Ze(r){const e={};if("buttons"in r&&(e.buttons=r.buttons),"shiftKey"in r){const{shiftKey:t,altKey:n,metaKey:s,ctrlKey:a}=r;Object.assign(e,{shiftKey:t,altKey:n,metaKey:s,ctrlKey:a})}return e}function te(r,...e){return typeof r=="function"?r(...e):r}function et(){}function tt(...r){return r.length===0?et:r.length===1?r[0]:function(){let e;for(const t of r)e=t.apply(this,arguments)||e;return e}}function Te(r,e){return Object.assign({},e,r||{})}const rt=32;class nt{constructor(e,t,n){this.ctrl=e,this.args=t,this.key=n,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(e){this.ctrl.state[this.key]=e}get shared(){return this.ctrl.state.shared}get eventStore(){return this.ctrl.gestureEventStores[this.key]}get timeoutStore(){return this.ctrl.gestureTimeoutStores[this.key]}get config(){return this.ctrl.config[this.key]}get sharedConfig(){return this.ctrl.config.shared}get handler(){return this.ctrl.handlers[this.key]}reset(){const{state:e,shared:t,ingKey:n,args:s}=this;t[n]=e._active=e.active=e._blocked=e._force=!1,e._step=[!1,!1],e.intentional=!1,e._movement=[0,0],e._distance=[0,0],e._direction=[0,0],e._delta=[0,0],e._bounds=[[-1/0,1/0],[-1/0,1/0]],e.args=s,e.axis=void 0,e.memo=void 0,e.elapsedTime=e.timeDelta=0,e.direction=[0,0],e.distance=[0,0],e.overflow=[0,0],e._movementBound=[!1,!1],e.velocity=[0,0],e.movement=[0,0],e.delta=[0,0],e.timeStamp=0}start(e){const t=this.state,n=this.config;t._active||(this.reset(),this.computeInitial(),t._active=!0,t.target=e.target,t.currentTarget=e.currentTarget,t.lastOffset=n.from?te(n.from,t):t.offset,t.offset=t.lastOffset,t.startTime=t.timeStamp=e.timeStamp)}computeValues(e){const t=this.state;t._values=e,t.values=this.config.transform(e)}computeInitial(){const e=this.state;e._initial=e._values,e.initial=e.values}compute(e){const{state:t,config:n,shared:s}=this;t.args=this.args;let a=0;if(e&&(t.event=e,n.preventDefault&&e.cancelable&&t.event.preventDefault(),t.type=e.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,Ze(e)),s.down=s.pressed=s.buttons%2===1||s.touches>0,a=e.timeStamp-t.timeStamp,t.timeStamp=e.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const g=t._delta.map(Math.abs);S.addTo(t._distance,g)}this.axisIntent&&this.axisIntent(e);const[o,c]=t._movement,[u,h]=n.threshold,{_step:l,values:v}=t;if(n.hasCustomTransform?(l[0]===!1&&(l[0]=Math.abs(o)>=u&&v[0]),l[1]===!1&&(l[1]=Math.abs(c)>=h&&v[1])):(l[0]===!1&&(l[0]=Math.abs(o)>=u&&Math.sign(o)*u),l[1]===!1&&(l[1]=Math.abs(c)>=h&&Math.sign(c)*h)),t.intentional=l[0]!==!1||l[1]!==!1,!t.intentional)return;const p=[0,0];if(n.hasCustomTransform){const[g,G]=v;p[0]=l[0]!==!1?g-l[0]:0,p[1]=l[1]!==!1?G-l[1]:0}else p[0]=l[0]!==!1?o-l[0]:0,p[1]=l[1]!==!1?c-l[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(p);const k=t.offset,I=t._active&&!t._blocked||t.active;I&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=s[this.ingKey]=t._active,e&&(t.first&&("bounds"in n&&(t._bounds=te(n.bounds,t)),this.setup&&this.setup()),t.movement=p,this.computeOffset()));const[D,m]=t.offset,[[E,A],[w,C]]=t._bounds;t.overflow=[D<E?-1:D>A?1:0,m<w?-1:m>C?1:0],t._movementBound[0]=t.overflow[0]?t._movementBound[0]===!1?t._movement[0]:t._movementBound[0]:!1,t._movementBound[1]=t.overflow[1]?t._movementBound[1]===!1?t._movement[1]:t._movementBound[1]:!1;const U=t._active?n.rubberband||[0,0]:[0,0];if(t.offset=Ue(t._bounds,t.offset,U),t.delta=S.sub(t.offset,k),this.computeMovement(),I&&(!t.last||a>rt)){t.delta=S.sub(t.offset,k);const g=t.delta.map(Math.abs);S.addTo(t.distance,g),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&a>0&&(t.velocity=[g[0]/a,g[1]/a],t.timeDelta=a)}}emit(){const e=this.state,t=this.shared,n=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!n.triggerAllEvents)return;const s=this.handler(_(_(_({},t),e),{},{[this.aliasKey]:e.values}));s!==void 0&&(e.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function st([r,e],t){const n=Math.abs(r),s=Math.abs(e);if(n>s&&n>t)return"x";if(s>n&&s>t)return"y"}class it extends nt{constructor(...e){super(...e),$(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=S.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=S.sub(this.state.offset,this.state.lastOffset)}axisIntent(e){const t=this.state,n=this.config;if(!t.axis&&e){const s=typeof n.axisThreshold=="object"?n.axisThreshold[_e(e)]:n.axisThreshold;t.axis=st(t._movement,s)}t._blocked=(n.lockDirection||!!n.axis)&&!t.axis||!!n.axis&&n.axis!==t.axis}restrictToAxis(e){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":e[1]=0;break;case"y":e[0]=0;break}}}const Ee=r=>r,Ie=.15,oe={enabled(r=!0){return r},eventOptions(r,e,t){return _(_({},t.shared.eventOptions),r)},preventDefault(r=!1){return r},triggerAllEvents(r=!1){return r},rubberband(r=0){switch(r){case!0:return[Ie,Ie];case!1:return[0,0];default:return S.toVector(r)}},from(r){if(typeof r=="function")return r;if(r!=null)return S.toVector(r)},transform(r,e,t){const n=r||t.shared.transform;if(this.hasCustomTransform=!!n,process.env.NODE_ENV==="development"){const s=n||Ee;return a=>{const o=s(a);return(!isFinite(o[0])||!isFinite(o[1]))&&console.warn(`[@use-gesture]: config.transform() must produce a valid result, but it was: [${o[0]},${[1]}]`),o}}return n||Ee},threshold(r){return S.toVector(r,0)}};process.env.NODE_ENV==="development"&&Object.assign(oe,{domTarget(r){if(r!==void 0)throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");return NaN},lockDirection(r){if(r!==void 0)throw Error("[@use-gesture]: `lockDirection` option has been merged with `axis`. Use it as in `{ axis: 'lock' }`");return NaN},initial(r){if(r!==void 0)throw Error("[@use-gesture]: `initial` option has been renamed to `from`.");return NaN}});const ot=0,J=_(_({},oe),{},{axis(r,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(r=ot){return r},bounds(r={}){if(typeof r=="function")return a=>J.bounds(r(a));if("current"in r)return()=>r.current;if(typeof HTMLElement=="function"&&r instanceof HTMLElement)return r;const{left:e=-1/0,right:t=1/0,top:n=-1/0,bottom:s=1/0}=r;return[[e,t],[n,s]]}}),Se={ArrowRight:(r,e=1)=>[r*e,0],ArrowLeft:(r,e=1)=>[-1*r*e,0],ArrowUp:(r,e=1)=>[0,-1*r*e],ArrowDown:(r,e=1)=>[0,r*e]};class at extends it{constructor(...e){super(...e),$(this,"ingKey","dragging")}reset(){super.reset();const e=this.state;e._pointerId=void 0,e._pointerActive=!1,e._keyboardActive=!1,e._preventScroll=!1,e._delayed=!1,e.swipe=[0,0],e.tap=!1,e.canceled=!1,e.cancel=this.cancel.bind(this)}setup(){const e=this.state;if(e._bounds instanceof HTMLElement){const t=e._bounds.getBoundingClientRect(),n=e.currentTarget.getBoundingClientRect(),s={left:t.left-n.left+e.offset[0],right:t.right-n.right+e.offset[0],top:t.top-n.top+e.offset[1],bottom:t.bottom-n.bottom+e.offset[1]};e._bounds=J.bounds(s)}}cancel(){const e=this.state;e.canceled||(e.canceled=!0,e._active=!1,setTimeout(()=>{this.compute(),this.emit()},0))}setActive(){this.state._active=this.state._pointerActive||this.state._keyboardActive}clean(){this.pointerClean(),this.state._pointerActive=!1,this.state._keyboardActive=!1,super.clean()}pointerDown(e){const t=this.config,n=this.state;if(e.buttons!=null&&(Array.isArray(t.pointerButtons)?!t.pointerButtons.includes(e.buttons):t.pointerButtons!==-1&&t.pointerButtons!==e.buttons))return;const s=this.ctrl.setEventIds(e);t.pointerCapture&&e.target.setPointerCapture(e.pointerId),!(s&&s.size>1&&n._pointerActive)&&(this.start(e),this.setupPointer(e),n._pointerId=ie(e),n._pointerActive=!0,this.computeValues(xe(e)),this.computeInitial(),t.preventScrollAxis&&_e(e)!=="mouse"?(n._active=!1,this.setupScrollPrevention(e)):t.delay>0?(this.setupDelayTrigger(e),t.triggerAllEvents&&(this.compute(e),this.emit())):this.startPointerDrag(e))}startPointerDrag(e){const t=this.state;t._active=!0,t._preventScroll=!0,t._delayed=!1,this.compute(e),this.emit()}pointerMove(e){const t=this.state,n=this.config;if(!t._pointerActive)return;const s=ie(e);if(t._pointerId!==void 0&&s!==t._pointerId)return;const a=xe(e);if(document.pointerLockElement===e.target?t._delta=[e.movementX,e.movementY]:(t._delta=S.sub(a,t._values),this.computeValues(a)),S.addTo(t._movement,t._delta),this.compute(e),t._delayed&&t.intentional){this.timeoutStore.remove("dragDelay"),t.active=!1,this.startPointerDrag(e);return}if(n.preventScrollAxis&&!t._preventScroll)if(t.axis)if(t.axis===n.preventScrollAxis||n.preventScrollAxis==="xy"){t._active=!1,this.clean();return}else{this.timeoutStore.remove("startPointerDrag"),this.startPointerDrag(e);return}else return;this.emit()}pointerUp(e){this.ctrl.setEventIds(e);try{this.config.pointerCapture&&e.target.hasPointerCapture(e.pointerId)&&e.target.releasePointerCapture(e.pointerId)}catch{process.env.NODE_ENV==="development"&&console.warn("[@use-gesture]: If you see this message, it's likely that you're using an outdated version of `@react-three/fiber`. \n\nPlease upgrade to the latest version.")}const t=this.state,n=this.config;if(!t._active||!t._pointerActive)return;const s=ie(e);if(t._pointerId!==void 0&&s!==t._pointerId)return;this.state._pointerActive=!1,this.setActive(),this.compute(e);const[a,o]=t._distance;if(t.tap=a<=n.tapsThreshold&&o<=n.tapsThreshold,t.tap&&n.filterTaps)t._force=!0;else{const[c,u]=t._delta,[h,l]=t._movement,[v,p]=n.swipe.velocity,[k,I]=n.swipe.distance,D=n.swipe.duration;if(t.elapsedTime<D){const m=Math.abs(c/t.timeDelta),E=Math.abs(u/t.timeDelta);m>v&&Math.abs(h)>k&&(t.swipe[0]=Math.sign(c)),E>p&&Math.abs(l)>I&&(t.swipe[1]=Math.sign(u))}}this.emit()}pointerClick(e){!this.state.tap&&e.detail>0&&(e.preventDefault(),e.stopPropagation())}setupPointer(e){const t=this.config,n=t.device;if(process.env.NODE_ENV==="development")try{if(n==="pointer"&&t.preventScrollDelay===void 0){const s="uv"in e?e.sourceEvent.currentTarget:e.currentTarget;window.getComputedStyle(s).touchAction==="auto"&&console.warn("[@use-gesture]: The drag target has its `touch-action` style property set to `auto`. It is recommended to add `touch-action: 'none'` so that the drag gesture behaves correctly on touch-enabled devices. For more information read this: https://use-gesture.netlify.app/docs/extras/#touch-action.\n\nThis message will only show in development mode. It won't appear in production. If this is intended, you can ignore it.",s)}}catch{}t.pointerLock&&e.currentTarget.requestPointerLock(),t.pointerCapture||(this.eventStore.add(this.sharedConfig.window,n,"change",this.pointerMove.bind(this)),this.eventStore.add(this.sharedConfig.window,n,"end",this.pointerUp.bind(this)),this.eventStore.add(this.sharedConfig.window,n,"cancel",this.pointerUp.bind(this)))}pointerClean(){this.config.pointerLock&&document.pointerLockElement===this.state.currentTarget&&document.exitPointerLock()}preventScroll(e){this.state._preventScroll&&e.cancelable&&e.preventDefault()}setupScrollPrevention(e){this.state._preventScroll=!1,ct(e);const t=this.eventStore.add(this.sharedConfig.window,"touch","change",this.preventScroll.bind(this),{passive:!1});this.eventStore.add(this.sharedConfig.window,"touch","end",t),this.eventStore.add(this.sharedConfig.window,"touch","cancel",t),this.timeoutStore.add("startPointerDrag",this.startPointerDrag.bind(this),this.config.preventScrollDelay,e)}setupDelayTrigger(e){this.state._delayed=!0,this.timeoutStore.add("dragDelay",()=>{this.state._step=[0,0],this.startPointerDrag(e)},this.config.delay)}keyDown(e){const t=Se[e.key];if(t){const n=this.state,s=e.shiftKey?10:e.altKey?.1:1;this.start(e),n._delta=t(this.config.keyboardDisplacement,s),n._keyboardActive=!0,S.addTo(n._movement,n._delta),this.compute(e),this.emit()}}keyUp(e){e.key in Se&&(this.state._keyboardActive=!1,this.setActive(),this.compute(e),this.emit())}bind(e){const t=this.config.device;e(t,"start",this.pointerDown.bind(this)),this.config.pointerCapture&&(e(t,"change",this.pointerMove.bind(this)),e(t,"end",this.pointerUp.bind(this)),e(t,"cancel",this.pointerUp.bind(this)),e("lostPointerCapture","",this.pointerUp.bind(this))),this.config.keys&&(e("key","down",this.keyDown.bind(this)),e("key","up",this.keyUp.bind(this))),this.config.filterTaps&&e("click","",this.pointerClick.bind(this),{capture:!0,passive:!1})}}function ct(r){"persist"in r&&typeof r.persist=="function"&&r.persist()}const Q=typeof window<"u"&&window.document&&window.document.createElement;function ke(){return Q&&"ontouchstart"in window}function ut(){return ke()||Q&&window.navigator.maxTouchPoints>1}function lt(){return Q&&"onpointerdown"in window}function ft(){return Q&&"exitPointerLock"in window.document}function dt(){try{return"constructor"in GestureEvent}catch{return!1}}const N={isBrowser:Q,gesture:dt(),touch:ke(),touchscreen:ut(),pointer:lt(),pointerLock:ft()},ht=250,pt=180,gt=.5,mt=50,vt=250,yt=10,Ce={mouse:0,touch:0,pen:8},De=_(_({},J),{},{device(r,e,{pointer:{touch:t=!1,lock:n=!1,mouse:s=!1}={}}){return this.pointerLock=n&&N.pointerLock,N.touch&&t?"touch":this.pointerLock?"mouse":N.pointer&&!s?"pointer":N.touch?"touch":"mouse"},preventScrollAxis(r,e,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&r?ht:void 0,!(!N.touchscreen||t===!1))return r||(t!==void 0?"y":void 0)},pointerCapture(r,e,{pointer:{capture:t=!0,buttons:n=1,keys:s=!0}={}}){return this.pointerButtons=n,this.keys=s,!this.pointerLock&&this.device==="pointer"&&t},threshold(r,e,{filterTaps:t=!1,tapsThreshold:n=3,axis:s=void 0}){const a=S.toVector(r,t?n:s?1:0);return this.filterTaps=t,this.tapsThreshold=n,a},swipe({velocity:r=gt,distance:e=mt,duration:t=vt}={}){return{velocity:this.transform(S.toVector(r)),distance:this.transform(S.toVector(e)),duration:t}},delay(r=0){switch(r){case!0:return pt;case!1:return 0;default:return r}},axisThreshold(r){return r?_(_({},Ce),r):Ce},keyboardDisplacement(r=yt){return r}});process.env.NODE_ENV==="development"&&Object.assign(De,{useTouch(r){if(r!==void 0)throw Error("[@use-gesture]: `useTouch` option has been renamed to `pointer.touch`. Use it as in `{ pointer: { touch: true } }`.");return NaN},experimental_preventWindowScrollY(r){if(r!==void 0)throw Error("[@use-gesture]: `experimental_preventWindowScrollY` option has been renamed to `preventScroll`.");return NaN},swipeVelocity(r){if(r!==void 0)throw Error("[@use-gesture]: `swipeVelocity` option has been renamed to `swipe.velocity`. Use it as in `{ swipe: { velocity: 0.5 } }`.");return NaN},swipeDistance(r){if(r!==void 0)throw Error("[@use-gesture]: `swipeDistance` option has been renamed to `swipe.distance`. Use it as in `{ swipe: { distance: 50 } }`.");return NaN},swipeDuration(r){if(r!==void 0)throw Error("[@use-gesture]: `swipeDuration` option has been renamed to `swipe.duration`. Use it as in `{ swipe: { duration: 250 } }`.");return NaN}}),_(_({},oe),{},{device(r,e,{shared:t,pointer:{touch:n=!1}={}}){if(t.target&&!N.touch&&N.gesture)return"gesture";if(N.touch&&n)return"touch";if(N.touchscreen){if(N.pointer)return"pointer";if(N.touch)return"touch"}},bounds(r,e,{scaleBounds:t={},angleBounds:n={}}){const s=o=>{const c=Te(te(t,o),{min:-1/0,max:1/0});return[c.min,c.max]},a=o=>{const c=Te(te(n,o),{min:-1/0,max:1/0});return[c.min,c.max]};return typeof t!="function"&&typeof n!="function"?[s(),a()]:o=>[s(o),a(o)]},threshold(r,e,t){return this.lockDirection=t.axis==="lock",S.toVector(r,this.lockDirection?[.1,3]:0)},modifierKey(r){return r===void 0?"ctrlKey":r},pinchOnWheel(r=!0){return r}}),_(_({},J),{},{mouseOnly:(r=!0)=>r}),_(_({},J),{},{mouseOnly:(r=!0)=>r});const Ae=new Map,ae=new Map;function bt(r){Ae.set(r.key,r.engine),ae.set(r.key,r.resolver)}const _t={key:"drag",engine:at,resolver:De};function wt(r,e){if(r==null)return{};var t={},n=Object.keys(r),s,a;for(a=0;a<n.length;a++)s=n[a],!(e.indexOf(s)>=0)&&(t[s]=r[s]);return t}function xt(r,e){if(r==null)return{};var t=wt(r,e),n,s;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(r);for(s=0;s<a.length;s++)n=a[s],!(e.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(r,n)&&(t[n]=r[n])}return t}const Tt={target(r){if(r)return()=>"current"in r?r.current:r},enabled(r=!0){return r},window(r=N.isBrowser?window:void 0){return r},eventOptions({passive:r=!0,capture:e=!1}={}){return{passive:r,capture:e}},transform(r){return r}},Et=["target","eventOptions","window","enabled","transform"];function re(r={},e){const t={};for(const[n,s]of Object.entries(e))switch(typeof s){case"function":if(process.env.NODE_ENV==="development"){const a=s.call(t,r[n],n,r);Number.isNaN(a)||(t[n]=a)}else t[n]=s.call(t,r[n],n,r);break;case"object":t[n]=re(r[n],s);break;case"boolean":s&&(t[n]=r[n]);break}return t}function It(r,e,t={}){const n=r,{target:s,eventOptions:a,window:o,enabled:c,transform:u}=n,h=xt(n,Et);if(t.shared=re({target:s,eventOptions:a,window:o,enabled:c,transform:u},Tt),e){const l=ae.get(e);t[e]=re(_({shared:t.shared},h),l)}else for(const l in h){const v=ae.get(l);if(v)t[l]=re(_({shared:t.shared},h[l]),v);else if(process.env.NODE_ENV==="development"&&!["drag","pinch","scroll","wheel","move","hover"].includes(l)){if(l==="domTarget")throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");console.warn(`[@use-gesture]: Unknown config key \`${l}\` was used. Please read the documentation for further information.`)}}return t}class $e{constructor(e,t){$(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,n,s,a){const o=this._listeners,c=qe(t,n),u=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},h=_(_({},u),a);e.addEventListener(c,s,h);const l=()=>{e.removeEventListener(c,s,h),o.delete(l)};return o.add(l),l}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class St{constructor(){$(this,"_timeouts",new Map)}add(e,t,n=140,...s){this.remove(e),this._timeouts.set(e,window.setTimeout(t,n,...s))}remove(e){const t=this._timeouts.get(e);t&&window.clearTimeout(t)}clean(){this._timeouts.forEach(e=>void window.clearTimeout(e)),this._timeouts.clear()}}class kt{constructor(e){$(this,"gestures",new Set),$(this,"_targetEventStore",new $e(this)),$(this,"gestureEventStores",{}),$(this,"gestureTimeoutStores",{}),$(this,"handlers",{}),$(this,"config",{}),$(this,"pointerIds",new Set),$(this,"touchIds",new Set),$(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),Ct(this,e)}setEventIds(e){if(ee(e))return this.touchIds=new Set(Qe(e)),this.touchIds;if("pointerId"in e)return e.type==="pointerup"||e.type==="pointercancel"?this.pointerIds.delete(e.pointerId):e.type==="pointerdown"&&this.pointerIds.add(e.pointerId),this.pointerIds}applyHandlers(e,t){this.handlers=e,this.nativeHandlers=t}applyConfig(e,t){this.config=It(e,t,this.config)}clean(){this._targetEventStore.clean();for(const e of this.gestures)this.gestureEventStores[e].clean(),this.gestureTimeoutStores[e].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...e){const t=this.config.shared,n={};let s;if(!(t.target&&(s=t.target(),!s))){if(t.enabled){for(const o of this.gestures){const c=this.config[o],u=Oe(n,c.eventOptions,!!s);if(c.enabled){const h=Ae.get(o);new h(this,e,o).bind(u)}}const a=Oe(n,t.eventOptions,!!s);for(const o in this.nativeHandlers)a(o,"",c=>this.nativeHandlers[o](_(_({},this.state.shared),{},{event:c,args:e})),void 0,!0)}for(const a in n)n[a]=tt(...n[a]);if(!s)return n;for(const a in n){const{device:o,capture:c,passive:u}=He(a);this._targetEventStore.add(s,o,"",n[a],{capture:c,passive:u})}}}}function F(r,e){r.gestures.add(e),r.gestureEventStores[e]=new $e(r,e),r.gestureTimeoutStores[e]=new St}function Ct(r,e){e.drag&&F(r,"drag"),e.wheel&&F(r,"wheel"),e.scroll&&F(r,"scroll"),e.move&&F(r,"move"),e.pinch&&F(r,"pinch"),e.hover&&F(r,"hover")}const Oe=(r,e,t)=>(n,s,a,o={},c=!1)=>{var u,h;const l=(u=o.capture)!==null&&u!==void 0?u:e.capture,v=(h=o.passive)!==null&&h!==void 0?h:e.passive;let p=c?n:We(n,s,l);t&&v&&(p+="Passive"),r[p]=r[p]||[],r[p].push(a)};function Dt(r,e={},t,n){const s=d.useMemo(()=>new kt(r),[]);if(s.applyHandlers(r,n),s.applyConfig(e,t),d.useEffect(s.effect.bind(s)),d.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function At(r,e){return bt(_t),Dt({drag:r},e||{},"drag")}function $t(r){const{type:e,actionType:t,toIndex:n,itemsLength:s,withLoop:a,scrollAmount:o,totalAvailable:c}=r;let u=r.currentActive,h=r.fromValueRaw,l=!1,v=!1;e==="next"&&(u+=1),e==="prev"&&(u=u===0?s-1:u-1),n!==void 0&&(u=n);let p=0;e==="next"&&(p=-(u*o),a&&u===s&&(u=0,h=h+o*s,p=0),!a&&(Math.abs(p)>=c||u===s-1)&&(v=!0,p=-c)),e==="prev"&&(p=-(u*o),u===s-1&&(h=h-s*o),!a&&p>=0&&(l=!0,p=0)),t==="resize"&&(p=-(u*o),a||(u===0&&(l=!0),(u===s-1||Math.abs(p)>=c)&&(v=!0,Math.abs(p)>=c&&c>0&&(p=-c))));const k=a?u%s:u,I=a?s+u%s:u;return{newActive:u,fromValue:h,toValue:p,startReached:l,endReached:v,logicalIndex:k,realTrackIndex:I}}function Z(r,e,t){return e==="x"?`translate3d(calc(${r}px + var(--${t}-offset-modifier)), 0px, 0px)`:`translate3d(0px, calc(${r}px + var(--${t}-offset-modifier)), 0px)`}function Ot(){const r=d.useRef(null);r.current===null&&(r.current=new Set);const e=d.useRef(null);return e.current===null&&(e.current={useListenToCustomEvent(t){d.useEffect(()=>{const n=r.current;return n.add(t),()=>{n.delete(t)}},[t])},emitEvent(t){const n=r.current;!n||n.size===0||n.forEach(s=>s(t))}}),e.current}function Pt({init:r=!0,items:e,withLoop:t=!1,id:n,gutter:s=[{breakpoint:0,gutter:0,startEndGutter:0}],itemsPerSlide:a=[{breakpoint:0,itemsPerSlide:1}],carouselAxis:o="x",startingPosition:c="start",enableGestures:u=!0,slideWhenDragThresholdIsReached:h=!0,slideType:l="item",initialActiveItem:v=0,renderWindow:p,renderPlaceholder:k}){const I=d.useRef(r),D=d.useRef(null),m=d.useRef(null),E=d.useRef(0),A=d.useRef(0),w=d.useRef(!t),C=d.useRef(!1),U=d.useRef(0),g=d.useRef(0),G=d.useRef(e);G.current=e;const ue=d.useRef(t);ue.current=t;const Ne=d.useRef(!1),z=d.useRef(null),R=d.useRef(null),K=d.useRef(null),W=d.useRef(null),Y=d.useRef({width:0,height:0});function Me(i){if(i===void 0)return 0;if(typeof i=="number")return e[i]?i:(console.warn(`initialActiveItem: item at index ${i} doesn't exist.`),0);const f=e.findIndex(y=>y.id===i);return f<0?(console.warn(`initialActiveItem: item with id "${i}" doesn't exist.`),0):f}const ne=se.useSpringRef(),le=se.useSpring({value:0,ref:ne,onChange({value:i}){m.current.style.transform=Z(i.value,o,n)}}),Rt=t?e.length*3:e.length,{useListenToCustomEvent:Le,emitEvent:H}=Ot();function Re(i){if(!i||i.length===0)return null;let f=null,y=-1/0;for(const T of i)(T.media?window.matchMedia(T.media).matches:window.innerWidth>=T.breakpoint)&&T.breakpoint>=y&&(f=T,y=T.breakpoint);return f}function Ve(){const{totalGutterCssVar:i}=je();return i}function Vt(){const i=Re(a);return(i==null?void 0:i.itemsPerSlide)||1}function fe(i){I.current&&(C.current||q({type:"next",toIndex:i,actionType:"click"}))}function de(i){I.current&&(w.current||q({type:"prev",toIndex:i,actionType:"click"}))}function q({type:i,shouldAnimate:f=!0,toIndex:y,actionType:T}){var j,V;const O=!f;w.current=!1,C.current=!1;const b=$t({type:i,actionType:T,toIndex:y,currentActive:g.current,itemsLength:e.length,withLoop:t,scrollAmount:A.current,totalAvailable:i==="next"||T==="resize"?he(t?A.current*(e.length*2):0):0,fromValueRaw:le.value.get()});g.current=b.newActive,w.current=b.startReached,C.current=b.endReached,E.current=b.toValue,H(T==="resize"?{eventName:"onResize",sliceActionType:T,slideDirection:i,currentItem:{id:((j=e.at(b.logicalIndex))==null?void 0:j.id)??"",index:b.logicalIndex,trackIndex:b.realTrackIndex,startReached:w.current,endReached:C.current}}:{eventName:"onSlideStartChange",sliceActionType:T,slideDirection:i,nextItem:{index:b.logicalIndex,id:((V=e.at(b.logicalIndex))==null?void 0:V.id)??"",trackIndex:b.realTrackIndex,startReached:w.current,endReached:C.current}}),O&&m.current&&(m.current.style.transform=Z(b.toValue,o,n)),ne.start({immediate:O,from:{value:b.fromValue},to:{value:b.toValue},onChange({value:X}){m.current.style.transform=Z(X.value,o,n)},onRest({finished:X}){var P;if(X){const x=t?g.current%e.length:g.current,B=t?e.length+g.current%e.length:g.current;H({eventName:"onSlideChangeComplete",sliceActionType:T,slideDirection:i,currentItem:{index:x,id:((P=e.at(x))==null?void 0:P.id)??"",trackIndex:B,startReached:w.current,endReached:C.current}})}}})}function jt(){const i=m.current;let f=0;return l==="item"?f=i.children[0].getBoundingClientRect()[o==="x"?"width":"height"]+Ve():f=i.getBoundingClientRect()[o==="x"?"width":"height"]+Ve(),f}function he(i){const f=m.current;return f[o==="x"?"scrollWidth":"scrollHeight"]-f.getBoundingClientRect()[o==="x"?"width":"height"]-i}function je(){const i=Re(s);return{totalGutterCssVar:(i==null?void 0:i.gutter)||0,totalStartEndGutterCssVar:((i==null?void 0:i.startEndGutter)||0)*2}}d.useEffect(()=>{function i(P){const x=Vt();switch(P){case"start":return 0;case"middle-start":return Math.floor((x-1)*.25);case"center":return Math.floor((x-1)*.5);case"middle-end":return Math.floor((x-1)*.75);case"end":return x-1;default:return 0}}function f(){A.current=jt(),U.current=A.current/4;const{totalStartEndGutterCssVar:P}=je();let x=0;t&&(x=A.current*e.length),x-=A.current*i(c),x-=P/2,D.current.style.setProperty(`--${n}-offset-modifier`,`${-x}px`),t&&m.current&&(o==="x"?m.current.style.left="0px":m.current.style.top="0px")}function y(P){if(D.current&&(f(),P)){const x=Me(v),B=t?e.length+x%e.length:x;H({eventName:"onInit",index:x,trackIndex:B})}}function T(){y(),q({type:"resize",toIndex:g.current,shouldAnimate:!1,actionType:"resize"})}function O(){K.current!==null&&(clearTimeout(K.current),K.current=null),W.current!==null&&(cancelAnimationFrame(W.current),W.current=null)}function b(P){W.current===null&&(W.current=requestAnimationFrame(()=>{W.current=null;const x=D.current;if(!x)return;const B=x.getBoundingClientRect();(B.width!==Y.current.width||B.height!==Y.current.height)&&(Y.current={width:B.width,height:B.height},T()),P&&(K.current=window.setTimeout(()=>{K.current=null,b(!1)},400))}))}function j(){O(),b(!0)}function V(){O(),K.current=window.setTimeout(()=>{K.current=null,Y.current={width:0,height:0},b(!0)},250)}function X(){document.visibilityState==="visible"&&(O(),Y.current={width:0,height:0},b(!0))}if(r){if(I.current=!0,Ne.current)T();else if(y(!0),Ne.current=!0,D.current){const x=D.current.getBoundingClientRect();Y.current={width:x.width,height:x.height}}const P=window.visualViewport??window;return P.addEventListener("resize",j),window.addEventListener("orientationchange",V),document.addEventListener("visibilitychange",X),()=>{P.removeEventListener("resize",j),window.removeEventListener("orientationchange",V),document.removeEventListener("visibilitychange",X),O()}}},[r,n,o,t]),d.useEffect(()=>{const i=Me(v);r&&i!==g.current&&q({type:"next",toIndex:i,actionType:"resize",shouldAnimate:!1})},[r,v]);const pe=u;function Bt(){if(R.current!==null&&(cancelAnimationFrame(R.current),R.current=null),z.current){const i=z.current;z.current=null,H(i)}}function Ut(i){z.current=i,R.current===null&&(R.current=requestAnimationFrame(()=>{R.current=null;const f=z.current;z.current=null,f&&H(f)}))}d.useEffect(()=>()=>{R.current!==null&&(cancelAnimationFrame(R.current),R.current=null),z.current=null},[]);const zt=At(i=>{if(!I.current)return;const f=i.dragging,y=i.offset[o==="x"?0:1],T=i.movement[o==="x"?0:1],O=T>U.current,b=T<-U.current,j=i.velocity;f&&(Ut({...i,eventName:"onDrag",slideActionType:"drag"}),ne.start({value:y,immediate:!0,config:{velocity:j},onChange({value:V}){m.current.style.transform=Z(V.value,o,n)}}),h&&(O||b)&&i.cancel()),i.last&&(Bt(),O?(q({actionType:"drag",type:"prev"}),i.cancel()):b?(q({actionType:"drag",type:"next"}),i.cancel()):(ne.start({value:E.current,config:{velocity:j},onChange({value:V}){m.current.style.transform=Z(V.value,o,n)}}),i.cancel()))},{enabled:pe,axis:o,rubberband:!t,...t?{}:{bounds:()=>({right:0,left:-he(0),top:-he(0),bottom:0})},from:()=>[le.value.get(),le.value.get()]}),Kt=d.useCallback(i=>{var b;const f=G.current,T=ue.current?f.length+g.current%f.length:g.current;if(typeof i=="number")return T===i;const O=g.current%f.length;return i===((b=f[O])==null?void 0:b.id)},[]),Ft=d.useMemo(()=>Array.from({length:e.length},(i,f)=>()=>{const y=t?g.current%e.length:g.current;return t?f===(y+1)%e.length:y+1>=e.length?!1:f===y+1}),[e.length,t]),Gt=d.useMemo(()=>Array.from({length:e.length},(i,f)=>()=>{const y=t?g.current%e.length:g.current;return t?f===(y-1+e.length)%e.length:y-1<0?!1:f===y-1}),[e.length,t]),Wt=d.useMemo(()=>`
|
|
1
|
+
(function(M,N){typeof exports=="object"&&typeof module<"u"?N(exports,require("react/jsx-runtime"),require("@react-spring/web"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@react-spring/web","react"],N):(M=typeof globalThis<"u"?globalThis:M||self,N(M["react-spring-carousel"]={},M["react/jsx-runtime"],M["@react-spring/web"],M.React))})(this,function(M,N,ie,d){"use strict";function Fe(r,e,t){return Math.max(e,Math.min(r,t))}const T={toVector(r,e){return r===void 0&&(r=e),Array.isArray(r)?r:[r,r]},add(r,e){return[r[0]+e[0],r[1]+e[1]]},sub(r,e){return[r[0]-e[0],r[1]-e[1]]},addTo(r,e){r[0]+=e[0],r[1]+=e[1]},subTo(r,e){r[0]-=e[0],r[1]-=e[1]}};function me(r,e,t){return e===0||Math.abs(e)===1/0?Math.pow(r,t*5):r*e*t/(e+t*r)}function ve(r,e,t,n=.15){return n===0?Fe(r,e,t):r<e?-me(e-r,t-e,n)+e:r>t?+me(r-t,t-e,n)+t:r}function Ge(r,[e,t],[n,s]){const[[a,o],[u,c]]=r;return[ve(e,a,o,n),ve(t,u,c,s)]}function We(r,e){if(typeof r!="object"||r===null)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var n=t.call(r,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function Ye(r){var e=We(r,"string");return typeof e=="symbol"?e:String(e)}function D(r,e,t){return e=Ye(e),e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function ye(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(s){return Object.getOwnPropertyDescriptor(r,s).enumerable})),t.push.apply(t,n)}return t}function y(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?ye(Object(t),!0).forEach(function(n){D(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):ye(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}const be={pointer:{start:"down",change:"move",end:"up"},mouse:{start:"down",change:"move",end:"up"},touch:{start:"start",change:"move",end:"end"},gesture:{start:"start",change:"change",end:"end"}};function _e(r){return r?r[0].toUpperCase()+r.slice(1):""}const He=["enter","leave"];function qe(r=!1,e){return r&&!He.includes(e)}function Xe(r,e="",t=!1){const n=be[r],s=n&&n[e]||e;return"on"+_e(r)+_e(s)+(qe(t,s)?"Capture":"")}const Je=["gotpointercapture","lostpointercapture"];function Qe(r){let e=r.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const n=Je.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(n);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:t}}function Ze(r,e=""){const t=be[r],n=t&&t[e]||e;return r+n}function te(r){return"touches"in r}function we(r){return te(r)?"touch":"pointerType"in r?r.pointerType:"mouse"}function et(r){return Array.from(r.touches).filter(e=>{var t,n;return e.target===r.currentTarget||((t=r.currentTarget)===null||t===void 0||(n=t.contains)===null||n===void 0?void 0:n.call(t,e.target))})}function tt(r){return r.type==="touchend"||r.type==="touchcancel"?r.changedTouches:r.targetTouches}function Te(r){return te(r)?tt(r)[0]:r}function rt(r){return et(r).map(e=>e.identifier)}function oe(r){const e=Te(r);return te(r)?e.identifier:e.pointerId}function xe(r){const e=Te(r);return[e.clientX,e.clientY]}function nt(r){const e={};if("buttons"in r&&(e.buttons=r.buttons),"shiftKey"in r){const{shiftKey:t,altKey:n,metaKey:s,ctrlKey:a}=r;Object.assign(e,{shiftKey:t,altKey:n,metaKey:s,ctrlKey:a})}return e}function re(r,...e){return typeof r=="function"?r(...e):r}function st(){}function it(...r){return r.length===0?st:r.length===1?r[0]:function(){let e;for(const t of r)e=t.apply(this,arguments)||e;return e}}function Ee(r,e){return Object.assign({},e,r||{})}const ot=32;class at{constructor(e,t,n){this.ctrl=e,this.args=t,this.key=n,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(e){this.ctrl.state[this.key]=e}get shared(){return this.ctrl.state.shared}get eventStore(){return this.ctrl.gestureEventStores[this.key]}get timeoutStore(){return this.ctrl.gestureTimeoutStores[this.key]}get config(){return this.ctrl.config[this.key]}get sharedConfig(){return this.ctrl.config.shared}get handler(){return this.ctrl.handlers[this.key]}reset(){const{state:e,shared:t,ingKey:n,args:s}=this;t[n]=e._active=e.active=e._blocked=e._force=!1,e._step=[!1,!1],e.intentional=!1,e._movement=[0,0],e._distance=[0,0],e._direction=[0,0],e._delta=[0,0],e._bounds=[[-1/0,1/0],[-1/0,1/0]],e.args=s,e.axis=void 0,e.memo=void 0,e.elapsedTime=e.timeDelta=0,e.direction=[0,0],e.distance=[0,0],e.overflow=[0,0],e._movementBound=[!1,!1],e.velocity=[0,0],e.movement=[0,0],e.delta=[0,0],e.timeStamp=0}start(e){const t=this.state,n=this.config;t._active||(this.reset(),this.computeInitial(),t._active=!0,t.target=e.target,t.currentTarget=e.currentTarget,t.lastOffset=n.from?re(n.from,t):t.offset,t.offset=t.lastOffset,t.startTime=t.timeStamp=e.timeStamp)}computeValues(e){const t=this.state;t._values=e,t.values=this.config.transform(e)}computeInitial(){const e=this.state;e._initial=e._values,e.initial=e.values}compute(e){const{state:t,config:n,shared:s}=this;t.args=this.args;let a=0;if(e&&(t.event=e,n.preventDefault&&e.cancelable&&t.event.preventDefault(),t.type=e.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,nt(e)),s.down=s.pressed=s.buttons%2===1||s.touches>0,a=e.timeStamp-t.timeStamp,t.timeStamp=e.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const C=t._delta.map(Math.abs);T.addTo(t._distance,C)}this.axisIntent&&this.axisIntent(e);const[o,u]=t._movement,[c,p]=n.threshold,{_step:f,values:_}=t;if(n.hasCustomTransform?(f[0]===!1&&(f[0]=Math.abs(o)>=c&&_[0]),f[1]===!1&&(f[1]=Math.abs(u)>=p&&_[1])):(f[0]===!1&&(f[0]=Math.abs(o)>=c&&Math.sign(o)*c),f[1]===!1&&(f[1]=Math.abs(u)>=p&&Math.sign(u)*p)),t.intentional=f[0]!==!1||f[1]!==!1,!t.intentional)return;const h=[0,0];if(n.hasCustomTransform){const[C,V]=_;h[0]=f[0]!==!1?C-f[0]:0,h[1]=f[1]!==!1?V-f[1]:0}else h[0]=f[0]!==!1?o-f[0]:0,h[1]=f[1]!==!1?u-f[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(h);const x=t.offset,E=t._active&&!t._blocked||t.active;E&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=s[this.ingKey]=t._active,e&&(t.first&&("bounds"in n&&(t._bounds=re(n.bounds,t)),this.setup&&this.setup()),t.movement=h,this.computeOffset()));const[z,L]=t.offset,[[$,O],[k,U]]=t._bounds;t.overflow=[z<$?-1:z>O?1:0,L<k?-1:L>U?1:0],t._movementBound[0]=t.overflow[0]?t._movementBound[0]===!1?t._movement[0]:t._movementBound[0]:!1,t._movementBound[1]=t.overflow[1]?t._movementBound[1]===!1?t._movement[1]:t._movementBound[1]:!1;const K=t._active?n.rubberband||[0,0]:[0,0];if(t.offset=Ge(t._bounds,t.offset,K),t.delta=T.sub(t.offset,x),this.computeMovement(),E&&(!t.last||a>ot)){t.delta=T.sub(t.offset,x);const C=t.delta.map(Math.abs);T.addTo(t.distance,C),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&a>0&&(t.velocity=[C[0]/a,C[1]/a],t.timeDelta=a)}}emit(){const e=this.state,t=this.shared,n=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!n.triggerAllEvents)return;const s=this.handler(y(y(y({},t),e),{},{[this.aliasKey]:e.values}));s!==void 0&&(e.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function ct([r,e],t){const n=Math.abs(r),s=Math.abs(e);if(n>s&&n>t)return"x";if(s>n&&s>t)return"y"}class ut extends at{constructor(...e){super(...e),D(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=T.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=T.sub(this.state.offset,this.state.lastOffset)}axisIntent(e){const t=this.state,n=this.config;if(!t.axis&&e){const s=typeof n.axisThreshold=="object"?n.axisThreshold[we(e)]:n.axisThreshold;t.axis=ct(t._movement,s)}t._blocked=(n.lockDirection||!!n.axis)&&!t.axis||!!n.axis&&n.axis!==t.axis}restrictToAxis(e){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":e[1]=0;break;case"y":e[0]=0;break}}}const Ie=r=>r,Se=.15,ae={enabled(r=!0){return r},eventOptions(r,e,t){return y(y({},t.shared.eventOptions),r)},preventDefault(r=!1){return r},triggerAllEvents(r=!1){return r},rubberband(r=0){switch(r){case!0:return[Se,Se];case!1:return[0,0];default:return T.toVector(r)}},from(r){if(typeof r=="function")return r;if(r!=null)return T.toVector(r)},transform(r,e,t){const n=r||t.shared.transform;if(this.hasCustomTransform=!!n,process.env.NODE_ENV==="development"){const s=n||Ie;return a=>{const o=s(a);return(!isFinite(o[0])||!isFinite(o[1]))&&console.warn(`[@use-gesture]: config.transform() must produce a valid result, but it was: [${o[0]},${[1]}]`),o}}return n||Ie},threshold(r){return T.toVector(r,0)}};process.env.NODE_ENV==="development"&&Object.assign(ae,{domTarget(r){if(r!==void 0)throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");return NaN},lockDirection(r){if(r!==void 0)throw Error("[@use-gesture]: `lockDirection` option has been merged with `axis`. Use it as in `{ axis: 'lock' }`");return NaN},initial(r){if(r!==void 0)throw Error("[@use-gesture]: `initial` option has been renamed to `from`.");return NaN}});const lt=0,Q=y(y({},ae),{},{axis(r,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(r=lt){return r},bounds(r={}){if(typeof r=="function")return a=>Q.bounds(r(a));if("current"in r)return()=>r.current;if(typeof HTMLElement=="function"&&r instanceof HTMLElement)return r;const{left:e=-1/0,right:t=1/0,top:n=-1/0,bottom:s=1/0}=r;return[[e,t],[n,s]]}}),ke={ArrowRight:(r,e=1)=>[r*e,0],ArrowLeft:(r,e=1)=>[-1*r*e,0],ArrowUp:(r,e=1)=>[0,-1*r*e],ArrowDown:(r,e=1)=>[0,r*e]};class ft extends ut{constructor(...e){super(...e),D(this,"ingKey","dragging")}reset(){super.reset();const e=this.state;e._pointerId=void 0,e._pointerActive=!1,e._keyboardActive=!1,e._preventScroll=!1,e._delayed=!1,e.swipe=[0,0],e.tap=!1,e.canceled=!1,e.cancel=this.cancel.bind(this)}setup(){const e=this.state;if(e._bounds instanceof HTMLElement){const t=e._bounds.getBoundingClientRect(),n=e.currentTarget.getBoundingClientRect(),s={left:t.left-n.left+e.offset[0],right:t.right-n.right+e.offset[0],top:t.top-n.top+e.offset[1],bottom:t.bottom-n.bottom+e.offset[1]};e._bounds=Q.bounds(s)}}cancel(){const e=this.state;e.canceled||(e.canceled=!0,e._active=!1,setTimeout(()=>{this.compute(),this.emit()},0))}setActive(){this.state._active=this.state._pointerActive||this.state._keyboardActive}clean(){this.pointerClean(),this.state._pointerActive=!1,this.state._keyboardActive=!1,super.clean()}pointerDown(e){const t=this.config,n=this.state;if(e.buttons!=null&&(Array.isArray(t.pointerButtons)?!t.pointerButtons.includes(e.buttons):t.pointerButtons!==-1&&t.pointerButtons!==e.buttons))return;const s=this.ctrl.setEventIds(e);t.pointerCapture&&e.target.setPointerCapture(e.pointerId),!(s&&s.size>1&&n._pointerActive)&&(this.start(e),this.setupPointer(e),n._pointerId=oe(e),n._pointerActive=!0,this.computeValues(xe(e)),this.computeInitial(),t.preventScrollAxis&&we(e)!=="mouse"?(n._active=!1,this.setupScrollPrevention(e)):t.delay>0?(this.setupDelayTrigger(e),t.triggerAllEvents&&(this.compute(e),this.emit())):this.startPointerDrag(e))}startPointerDrag(e){const t=this.state;t._active=!0,t._preventScroll=!0,t._delayed=!1,this.compute(e),this.emit()}pointerMove(e){const t=this.state,n=this.config;if(!t._pointerActive)return;const s=oe(e);if(t._pointerId!==void 0&&s!==t._pointerId)return;const a=xe(e);if(document.pointerLockElement===e.target?t._delta=[e.movementX,e.movementY]:(t._delta=T.sub(a,t._values),this.computeValues(a)),T.addTo(t._movement,t._delta),this.compute(e),t._delayed&&t.intentional){this.timeoutStore.remove("dragDelay"),t.active=!1,this.startPointerDrag(e);return}if(n.preventScrollAxis&&!t._preventScroll)if(t.axis)if(t.axis===n.preventScrollAxis||n.preventScrollAxis==="xy"){t._active=!1,this.clean();return}else{this.timeoutStore.remove("startPointerDrag"),this.startPointerDrag(e);return}else return;this.emit()}pointerUp(e){this.ctrl.setEventIds(e);try{this.config.pointerCapture&&e.target.hasPointerCapture(e.pointerId)&&e.target.releasePointerCapture(e.pointerId)}catch{process.env.NODE_ENV==="development"&&console.warn("[@use-gesture]: If you see this message, it's likely that you're using an outdated version of `@react-three/fiber`. \n\nPlease upgrade to the latest version.")}const t=this.state,n=this.config;if(!t._active||!t._pointerActive)return;const s=oe(e);if(t._pointerId!==void 0&&s!==t._pointerId)return;this.state._pointerActive=!1,this.setActive(),this.compute(e);const[a,o]=t._distance;if(t.tap=a<=n.tapsThreshold&&o<=n.tapsThreshold,t.tap&&n.filterTaps)t._force=!0;else{const[u,c]=t._delta,[p,f]=t._movement,[_,h]=n.swipe.velocity,[x,E]=n.swipe.distance,z=n.swipe.duration;if(t.elapsedTime<z){const L=Math.abs(u/t.timeDelta),$=Math.abs(c/t.timeDelta);L>_&&Math.abs(p)>x&&(t.swipe[0]=Math.sign(u)),$>h&&Math.abs(f)>E&&(t.swipe[1]=Math.sign(c))}}this.emit()}pointerClick(e){!this.state.tap&&e.detail>0&&(e.preventDefault(),e.stopPropagation())}setupPointer(e){const t=this.config,n=t.device;if(process.env.NODE_ENV==="development")try{if(n==="pointer"&&t.preventScrollDelay===void 0){const s="uv"in e?e.sourceEvent.currentTarget:e.currentTarget;window.getComputedStyle(s).touchAction==="auto"&&console.warn("[@use-gesture]: The drag target has its `touch-action` style property set to `auto`. It is recommended to add `touch-action: 'none'` so that the drag gesture behaves correctly on touch-enabled devices. For more information read this: https://use-gesture.netlify.app/docs/extras/#touch-action.\n\nThis message will only show in development mode. It won't appear in production. If this is intended, you can ignore it.",s)}}catch{}t.pointerLock&&e.currentTarget.requestPointerLock(),t.pointerCapture||(this.eventStore.add(this.sharedConfig.window,n,"change",this.pointerMove.bind(this)),this.eventStore.add(this.sharedConfig.window,n,"end",this.pointerUp.bind(this)),this.eventStore.add(this.sharedConfig.window,n,"cancel",this.pointerUp.bind(this)))}pointerClean(){this.config.pointerLock&&document.pointerLockElement===this.state.currentTarget&&document.exitPointerLock()}preventScroll(e){this.state._preventScroll&&e.cancelable&&e.preventDefault()}setupScrollPrevention(e){this.state._preventScroll=!1,dt(e);const t=this.eventStore.add(this.sharedConfig.window,"touch","change",this.preventScroll.bind(this),{passive:!1});this.eventStore.add(this.sharedConfig.window,"touch","end",t),this.eventStore.add(this.sharedConfig.window,"touch","cancel",t),this.timeoutStore.add("startPointerDrag",this.startPointerDrag.bind(this),this.config.preventScrollDelay,e)}setupDelayTrigger(e){this.state._delayed=!0,this.timeoutStore.add("dragDelay",()=>{this.state._step=[0,0],this.startPointerDrag(e)},this.config.delay)}keyDown(e){const t=ke[e.key];if(t){const n=this.state,s=e.shiftKey?10:e.altKey?.1:1;this.start(e),n._delta=t(this.config.keyboardDisplacement,s),n._keyboardActive=!0,T.addTo(n._movement,n._delta),this.compute(e),this.emit()}}keyUp(e){e.key in ke&&(this.state._keyboardActive=!1,this.setActive(),this.compute(e),this.emit())}bind(e){const t=this.config.device;e(t,"start",this.pointerDown.bind(this)),this.config.pointerCapture&&(e(t,"change",this.pointerMove.bind(this)),e(t,"end",this.pointerUp.bind(this)),e(t,"cancel",this.pointerUp.bind(this)),e("lostPointerCapture","",this.pointerUp.bind(this))),this.config.keys&&(e("key","down",this.keyDown.bind(this)),e("key","up",this.keyUp.bind(this))),this.config.filterTaps&&e("click","",this.pointerClick.bind(this),{capture:!0,passive:!1})}}function dt(r){"persist"in r&&typeof r.persist=="function"&&r.persist()}const Z=typeof window<"u"&&window.document&&window.document.createElement;function Ce(){return Z&&"ontouchstart"in window}function ht(){return Ce()||Z&&window.navigator.maxTouchPoints>1}function pt(){return Z&&"onpointerdown"in window}function gt(){return Z&&"exitPointerLock"in window.document}function mt(){try{return"constructor"in GestureEvent}catch{return!1}}const A={isBrowser:Z,gesture:mt(),touch:Ce(),touchscreen:ht(),pointer:pt(),pointerLock:gt()},vt=250,yt=180,bt=.5,_t=50,wt=250,Tt=10,De={mouse:0,touch:0,pen:8},Ae=y(y({},Q),{},{device(r,e,{pointer:{touch:t=!1,lock:n=!1,mouse:s=!1}={}}){return this.pointerLock=n&&A.pointerLock,A.touch&&t?"touch":this.pointerLock?"mouse":A.pointer&&!s?"pointer":A.touch?"touch":"mouse"},preventScrollAxis(r,e,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&r?vt:void 0,!(!A.touchscreen||t===!1))return r||(t!==void 0?"y":void 0)},pointerCapture(r,e,{pointer:{capture:t=!0,buttons:n=1,keys:s=!0}={}}){return this.pointerButtons=n,this.keys=s,!this.pointerLock&&this.device==="pointer"&&t},threshold(r,e,{filterTaps:t=!1,tapsThreshold:n=3,axis:s=void 0}){const a=T.toVector(r,t?n:s?1:0);return this.filterTaps=t,this.tapsThreshold=n,a},swipe({velocity:r=bt,distance:e=_t,duration:t=wt}={}){return{velocity:this.transform(T.toVector(r)),distance:this.transform(T.toVector(e)),duration:t}},delay(r=0){switch(r){case!0:return yt;case!1:return 0;default:return r}},axisThreshold(r){return r?y(y({},De),r):De},keyboardDisplacement(r=Tt){return r}});process.env.NODE_ENV==="development"&&Object.assign(Ae,{useTouch(r){if(r!==void 0)throw Error("[@use-gesture]: `useTouch` option has been renamed to `pointer.touch`. Use it as in `{ pointer: { touch: true } }`.");return NaN},experimental_preventWindowScrollY(r){if(r!==void 0)throw Error("[@use-gesture]: `experimental_preventWindowScrollY` option has been renamed to `preventScroll`.");return NaN},swipeVelocity(r){if(r!==void 0)throw Error("[@use-gesture]: `swipeVelocity` option has been renamed to `swipe.velocity`. Use it as in `{ swipe: { velocity: 0.5 } }`.");return NaN},swipeDistance(r){if(r!==void 0)throw Error("[@use-gesture]: `swipeDistance` option has been renamed to `swipe.distance`. Use it as in `{ swipe: { distance: 50 } }`.");return NaN},swipeDuration(r){if(r!==void 0)throw Error("[@use-gesture]: `swipeDuration` option has been renamed to `swipe.duration`. Use it as in `{ swipe: { duration: 250 } }`.");return NaN}}),y(y({},ae),{},{device(r,e,{shared:t,pointer:{touch:n=!1}={}}){if(t.target&&!A.touch&&A.gesture)return"gesture";if(A.touch&&n)return"touch";if(A.touchscreen){if(A.pointer)return"pointer";if(A.touch)return"touch"}},bounds(r,e,{scaleBounds:t={},angleBounds:n={}}){const s=o=>{const u=Ee(re(t,o),{min:-1/0,max:1/0});return[u.min,u.max]},a=o=>{const u=Ee(re(n,o),{min:-1/0,max:1/0});return[u.min,u.max]};return typeof t!="function"&&typeof n!="function"?[s(),a()]:o=>[s(o),a(o)]},threshold(r,e,t){return this.lockDirection=t.axis==="lock",T.toVector(r,this.lockDirection?[.1,3]:0)},modifierKey(r){return r===void 0?"ctrlKey":r},pinchOnWheel(r=!0){return r}}),y(y({},Q),{},{mouseOnly:(r=!0)=>r}),y(y({},Q),{},{mouseOnly:(r=!0)=>r});const $e=new Map,ce=new Map;function xt(r){$e.set(r.key,r.engine),ce.set(r.key,r.resolver)}const Et={key:"drag",engine:ft,resolver:Ae};function It(r,e){if(r==null)return{};var t={},n=Object.keys(r),s,a;for(a=0;a<n.length;a++)s=n[a],!(e.indexOf(s)>=0)&&(t[s]=r[s]);return t}function St(r,e){if(r==null)return{};var t=It(r,e),n,s;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(r);for(s=0;s<a.length;s++)n=a[s],!(e.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(r,n)&&(t[n]=r[n])}return t}const kt={target(r){if(r)return()=>"current"in r?r.current:r},enabled(r=!0){return r},window(r=A.isBrowser?window:void 0){return r},eventOptions({passive:r=!0,capture:e=!1}={}){return{passive:r,capture:e}},transform(r){return r}},Ct=["target","eventOptions","window","enabled","transform"];function ne(r={},e){const t={};for(const[n,s]of Object.entries(e))switch(typeof s){case"function":if(process.env.NODE_ENV==="development"){const a=s.call(t,r[n],n,r);Number.isNaN(a)||(t[n]=a)}else t[n]=s.call(t,r[n],n,r);break;case"object":t[n]=ne(r[n],s);break;case"boolean":s&&(t[n]=r[n]);break}return t}function Dt(r,e,t={}){const n=r,{target:s,eventOptions:a,window:o,enabled:u,transform:c}=n,p=St(n,Ct);if(t.shared=ne({target:s,eventOptions:a,window:o,enabled:u,transform:c},kt),e){const f=ce.get(e);t[e]=ne(y({shared:t.shared},p),f)}else for(const f in p){const _=ce.get(f);if(_)t[f]=ne(y({shared:t.shared},p[f]),_);else if(process.env.NODE_ENV==="development"&&!["drag","pinch","scroll","wheel","move","hover"].includes(f)){if(f==="domTarget")throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");console.warn(`[@use-gesture]: Unknown config key \`${f}\` was used. Please read the documentation for further information.`)}}return t}class Oe{constructor(e,t){D(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,n,s,a){const o=this._listeners,u=Ze(t,n),c=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},p=y(y({},c),a);e.addEventListener(u,s,p);const f=()=>{e.removeEventListener(u,s,p),o.delete(f)};return o.add(f),f}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class At{constructor(){D(this,"_timeouts",new Map)}add(e,t,n=140,...s){this.remove(e),this._timeouts.set(e,window.setTimeout(t,n,...s))}remove(e){const t=this._timeouts.get(e);t&&window.clearTimeout(t)}clean(){this._timeouts.forEach(e=>void window.clearTimeout(e)),this._timeouts.clear()}}class $t{constructor(e){D(this,"gestures",new Set),D(this,"_targetEventStore",new Oe(this)),D(this,"gestureEventStores",{}),D(this,"gestureTimeoutStores",{}),D(this,"handlers",{}),D(this,"config",{}),D(this,"pointerIds",new Set),D(this,"touchIds",new Set),D(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),Ot(this,e)}setEventIds(e){if(te(e))return this.touchIds=new Set(rt(e)),this.touchIds;if("pointerId"in e)return e.type==="pointerup"||e.type==="pointercancel"?this.pointerIds.delete(e.pointerId):e.type==="pointerdown"&&this.pointerIds.add(e.pointerId),this.pointerIds}applyHandlers(e,t){this.handlers=e,this.nativeHandlers=t}applyConfig(e,t){this.config=Dt(e,t,this.config)}clean(){this._targetEventStore.clean();for(const e of this.gestures)this.gestureEventStores[e].clean(),this.gestureTimeoutStores[e].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...e){const t=this.config.shared,n={};let s;if(!(t.target&&(s=t.target(),!s))){if(t.enabled){for(const o of this.gestures){const u=this.config[o],c=Pe(n,u.eventOptions,!!s);if(u.enabled){const p=$e.get(o);new p(this,e,o).bind(c)}}const a=Pe(n,t.eventOptions,!!s);for(const o in this.nativeHandlers)a(o,"",u=>this.nativeHandlers[o](y(y({},this.state.shared),{},{event:u,args:e})),void 0,!0)}for(const a in n)n[a]=it(...n[a]);if(!s)return n;for(const a in n){const{device:o,capture:u,passive:c}=Qe(a);this._targetEventStore.add(s,o,"",n[a],{capture:u,passive:c})}}}}function W(r,e){r.gestures.add(e),r.gestureEventStores[e]=new Oe(r,e),r.gestureTimeoutStores[e]=new At}function Ot(r,e){e.drag&&W(r,"drag"),e.wheel&&W(r,"wheel"),e.scroll&&W(r,"scroll"),e.move&&W(r,"move"),e.pinch&&W(r,"pinch"),e.hover&&W(r,"hover")}const Pe=(r,e,t)=>(n,s,a,o={},u=!1)=>{var c,p;const f=(c=o.capture)!==null&&c!==void 0?c:e.capture,_=(p=o.passive)!==null&&p!==void 0?p:e.passive;let h=u?n:Xe(n,s,f);t&&_&&(h+="Passive"),r[h]=r[h]||[],r[h].push(a)};function Pt(r,e={},t,n){const s=d.useMemo(()=>new $t(r),[]);if(s.applyHandlers(r,n),s.applyConfig(e,t),d.useEffect(s.effect.bind(s)),d.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function Mt(r,e){return xt(Et),Pt({drag:r},e||{},"drag")}function Nt(r){const{type:e,actionType:t,toIndex:n,itemsLength:s,withLoop:a,scrollAmount:o,totalAvailable:u}=r;let c=r.currentActive,p=r.fromValueRaw,f=!1,_=!1;e==="next"&&(c+=1),e==="prev"&&(c=c===0?s-1:c-1),n!==void 0&&(c=n);let h=0;e==="next"&&(h=-(c*o),a&&c===s&&(c=0,p=p+o*s,h=0),!a&&(Math.abs(h)>=u||c===s-1)&&(_=!0,h=-u)),e==="prev"&&(h=-(c*o),c===s-1&&(p=p-s*o),!a&&h>=0&&(f=!0,h=0)),t==="resize"&&(h=-(c*o),a||(c===0&&(f=!0),(c===s-1||Math.abs(h)>=u)&&(_=!0,Math.abs(h)>=u&&u>0&&(h=-u))));const x=a?c%s:c,E=a?s+c%s:c;return{newActive:c,fromValue:p,toValue:h,startReached:f,endReached:_,logicalIndex:x,realTrackIndex:E}}function ee(r,e,t){return e==="x"?`translate3d(calc(${r}px + var(--${t}-offset-modifier)), 0px, 0px)`:`translate3d(0px, calc(${r}px + var(--${t}-offset-modifier)), 0px)`}function Lt(){const r=d.useRef(null);r.current===null&&(r.current=new Set);const e=d.useRef(null);return e.current===null&&(e.current={useListenToCustomEvent(t){d.useEffect(()=>{const n=r.current;return n.add(t),()=>{n.delete(t)}},[t])},emitEvent(t){const n=r.current;!n||n.size===0||n.forEach(s=>s(t))}}),e.current}function Vt({init:r=!0,items:e,withLoop:t=!1,id:n,gutter:s=[{breakpoint:0,gutter:0,startEndGutter:0}],itemsPerSlide:a=[{breakpoint:0,itemsPerSlide:1}],carouselAxis:o="x",startingPosition:u="start",enableGestures:c=!0,slideWhenDragThresholdIsReached:p=!0,slideType:f="item",initialActiveItem:_=0,renderWindow:h,renderPlaceholder:x}){const[E,z]=d.useState(!1),[,L]=d.useState(0),$=d.useRef(r),O=d.useRef(null),k=d.useRef(null),U=d.useRef(0),K=d.useRef(0),C=d.useRef(!t),V=d.useRef(!1),le=d.useRef(0),w=d.useRef(0),Ne=d.useRef(e);Ne.current=e;const Le=d.useRef(t);Le.current=t;const Ve=d.useRef(!1),F=d.useRef(null),R=d.useRef(null),G=d.useRef(null),Y=d.useRef(null),H=d.useRef({width:0,height:0});function Re(i){if(i===void 0)return 0;if(typeof i=="number")return e[i]?i:(console.warn(`initialActiveItem: item at index ${i} doesn't exist.`),0);const l=e.findIndex(m=>m.id===i);return l<0?(console.warn(`initialActiveItem: item with id "${i}" doesn't exist.`),0):l}const se=ie.useSpringRef(),fe=ie.useSpring({value:0,ref:se,onChange({value:i}){k.current.style.transform=ee(i.value,o,n)}}),Bt=t?e.length*3:e.length,{useListenToCustomEvent:je,emitEvent:q}=Lt();function Be(i){if(!i||i.length===0)return null;let l=null,m=-1/0;for(const g of i)(g.media?window.matchMedia(g.media).matches:window.innerWidth>=g.breakpoint)&&g.breakpoint>=m&&(l=g,m=g.breakpoint);return l}function ze(){const{totalGutterCssVar:i}=Ue();return i}function zt(){const i=Be(a);return(i==null?void 0:i.itemsPerSlide)||1}function de(i){$.current&&(V.current||X({type:"next",toIndex:i,actionType:"click"}))}function he(i){$.current&&(C.current||X({type:"prev",toIndex:i,actionType:"click"}))}function X({type:i,shouldAnimate:l=!0,toIndex:m,actionType:g}){var P,J;const I=!l;C.current=!1,V.current=!1;const v=Nt({type:i,actionType:g,toIndex:m,currentActive:w.current,itemsLength:e.length,withLoop:t,scrollAmount:K.current,totalAvailable:i==="next"||g==="resize"?pe(t?K.current*(e.length*2):0):0,fromValueRaw:fe.value.get()}),j=w.current;w.current=v.newActive,C.current=v.startReached,V.current=v.endReached,U.current=v.toValue,h!==void 0&&j!==v.newActive&&L(S=>S+1),q(g==="resize"?{eventName:"onResize",sliceActionType:g,slideDirection:i,currentItem:{id:((P=e.at(v.logicalIndex))==null?void 0:P.id)??"",index:v.logicalIndex,trackIndex:v.realTrackIndex,startReached:C.current,endReached:V.current}}:{eventName:"onSlideStartChange",sliceActionType:g,slideDirection:i,nextItem:{index:v.logicalIndex,id:((J=e.at(v.logicalIndex))==null?void 0:J.id)??"",trackIndex:v.realTrackIndex,startReached:C.current,endReached:V.current}}),I&&k.current&&(k.current.style.transform=ee(v.toValue,o,n)),se.start({immediate:I,from:{value:v.fromValue},to:{value:v.toValue},onChange({value:S}){k.current.style.transform=ee(S.value,o,n)},onRest({finished:S}){var b;if(S){const B=t?w.current%e.length:w.current,Ke=t?e.length+w.current%e.length:w.current;q({eventName:"onSlideChangeComplete",sliceActionType:g,slideDirection:i,currentItem:{index:B,id:((b=e.at(B))==null?void 0:b.id)??"",trackIndex:Ke,startReached:C.current,endReached:V.current}})}}})}function Ut(){const i=k.current;let l=0;return f==="item"?l=i.children[0].getBoundingClientRect()[o==="x"?"width":"height"]+ze():l=i.getBoundingClientRect()[o==="x"?"width":"height"]+ze(),l}function pe(i){const l=k.current;return l[o==="x"?"scrollWidth":"scrollHeight"]-l.getBoundingClientRect()[o==="x"?"width":"height"]-i}function Ue(){const i=Be(s);return{totalGutterCssVar:(i==null?void 0:i.gutter)||0,totalStartEndGutterCssVar:((i==null?void 0:i.startEndGutter)||0)*2}}d.useEffect(()=>{function i(S){const b=zt();switch(S){case"start":return 0;case"middle-start":return Math.floor((b-1)*.25);case"center":return Math.floor((b-1)*.5);case"middle-end":return Math.floor((b-1)*.75);case"end":return b-1;default:return 0}}function l(){K.current=Ut(),le.current=K.current/4;const{totalStartEndGutterCssVar:S}=Ue();let b=0;t&&(b=K.current*e.length),b-=K.current*i(u),b-=S/2,O.current.style.setProperty(`--${n}-offset-modifier`,`${-b}px`)}function m(S){if(O.current&&(l(),z(!0),S)){const b=Re(_),B=t?e.length+b%e.length:b;q({eventName:"onInit",index:b,trackIndex:B})}}function g(){m(),X({type:"resize",toIndex:w.current,shouldAnimate:!1,actionType:"resize"})}function I(){G.current!==null&&(clearTimeout(G.current),G.current=null),Y.current!==null&&(cancelAnimationFrame(Y.current),Y.current=null)}function v(S){Y.current===null&&(Y.current=requestAnimationFrame(()=>{Y.current=null;const b=O.current;if(!b)return;const B=b.getBoundingClientRect();(B.width!==H.current.width||B.height!==H.current.height)&&(H.current={width:B.width,height:B.height},g()),S&&(G.current=window.setTimeout(()=>{G.current=null,v(!1)},400))}))}function j(){I(),v(!0)}function P(){I(),G.current=window.setTimeout(()=>{G.current=null,H.current={width:0,height:0},v(!0)},250)}function J(){document.visibilityState==="visible"&&(I(),H.current={width:0,height:0},v(!0))}if(r){if($.current=!0,Ve.current)g();else if(m(!0),Ve.current=!0,O.current){const b=O.current.getBoundingClientRect();H.current={width:b.width,height:b.height}}const S=window.visualViewport??window;return S.addEventListener("resize",j),window.addEventListener("orientationchange",P),document.addEventListener("visibilitychange",J),()=>{S.removeEventListener("resize",j),window.removeEventListener("orientationchange",P),document.removeEventListener("visibilitychange",J),I()}}},[r,n,o,t]),d.useEffect(()=>{const i=Re(_);r&&i!==w.current&&X({type:"next",toIndex:i,actionType:"resize",shouldAnimate:!1})},[r,_]);const ge=c;function Kt(){if(R.current!==null&&(cancelAnimationFrame(R.current),R.current=null),F.current){const i=F.current;F.current=null,q(i)}}function Ft(i){F.current=i,R.current===null&&(R.current=requestAnimationFrame(()=>{R.current=null;const l=F.current;F.current=null,l&&q(l)}))}d.useEffect(()=>()=>{R.current!==null&&(cancelAnimationFrame(R.current),R.current=null),F.current=null},[]);const Gt=Mt(i=>{if(!$.current)return;const l=i.dragging,m=i.offset[o==="x"?0:1],g=i.movement[o==="x"?0:1],I=g>le.current,v=g<-le.current,j=i.velocity;l&&(Ft({...i,eventName:"onDrag",slideActionType:"drag"}),se.start({value:m,immediate:!0,config:{velocity:j},onChange({value:P}){k.current.style.transform=ee(P.value,o,n)}}),p&&(I||v)&&i.cancel()),i.last&&(Kt(),I?(X({actionType:"drag",type:"prev"}),i.cancel()):v?(X({actionType:"drag",type:"next"}),i.cancel()):(se.start({value:U.current,config:{velocity:j},onChange({value:P}){k.current.style.transform=ee(P.value,o,n)}}),i.cancel()))},{enabled:ge,axis:o,rubberband:!t,...t?{}:{bounds:()=>({right:0,left:-pe(0),top:-pe(0),bottom:0})},from:()=>[fe.value.get(),fe.value.get()]}),Wt=d.useCallback(i=>{var v;const l=Ne.current,g=Le.current?l.length+w.current%l.length:w.current;if(typeof i=="number")return g===i;const I=w.current%l.length;return i===((v=l[I])==null?void 0:v.id)},[]),Yt=d.useMemo(()=>Array.from({length:e.length},(i,l)=>()=>{const m=t?w.current%e.length:w.current;return t?l===(m+1)%e.length:m+1>=e.length?!1:l===m+1}),[e.length,t]),Ht=d.useMemo(()=>Array.from({length:e.length},(i,l)=>()=>{const m=t?w.current%e.length:w.current;return t?l===(m-1+e.length)%e.length:m-1<0?!1:l===m-1}),[e.length,t]),qt=d.useMemo(()=>`
|
|
2
2
|
[data-part-internal="${n}-Container"] {
|
|
3
3
|
display: flex;
|
|
4
4
|
width: 100%;
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
--${n}-scroll-y-value: ${o==="y"?`calc(var(--${n}-offset-position) + var(--${n}-offset-modifier))`:"0px"};
|
|
12
12
|
--${n}-gutter: 0px;
|
|
13
13
|
--${n}-start-end-gutter: 0px;
|
|
14
|
-
touch-action: ${
|
|
14
|
+
touch-action: ${ge?o==="x"?"pan-y":"pan-x":"auto"};
|
|
15
15
|
}
|
|
16
16
|
[data-part-internal="${n}-Track"] {
|
|
17
17
|
display: flex;
|
|
18
18
|
position: relative;
|
|
19
19
|
--initial-offset-modifier: calc(calc(-100% - var(--${n}-gutter) + calc(var(--${n}-start-end-gutter) / 2 / ${e.length} * var(--${n}-items-per-slide)) + var(--${n}-start-end-gutter)) * ${e.length} / var(--${n}-items-per-slide));
|
|
20
|
-
left: ${t&&o==="x"?"var(--initial-offset-modifier)":"0px"};
|
|
21
|
-
top: ${t&&o==="y"?"var(--initial-offset-modifier)":"0px"};
|
|
20
|
+
left: ${t&&o==="x"&&!E?"var(--initial-offset-modifier)":"0px"};
|
|
21
|
+
top: ${t&&o==="y"&&!E?"var(--initial-offset-modifier)":"0px"};
|
|
22
22
|
flex-direction: ${o==="x"?"row":"column"};
|
|
23
23
|
width: 100%;
|
|
24
24
|
height: 100%;
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
display: flex;
|
|
30
30
|
flex: 1 0 calc(100% / var(--${n}-items-per-slide) - calc(var(--${n}-gutter) * (var(--${n}-items-per-slide) - 1)) / var(--${n}-items-per-slide) - calc(var(--${n}-start-end-gutter) / var(--${n}-items-per-slide)));
|
|
31
31
|
}
|
|
32
|
-
${s&&s.length>0?s.slice().sort((i,
|
|
32
|
+
${s&&s.length>0?s.slice().sort((i,l)=>i.breakpoint-l.breakpoint).map(i=>`
|
|
33
33
|
@media ${i.media||`(min-width: ${i.breakpoint}px)`} {
|
|
34
34
|
[data-part-internal="${n}-Container"] {
|
|
35
35
|
--${n}-gutter: ${i.gutter||0}px;
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
`).join(""):""}
|
|
40
|
-
${a&&a.length>0?a.slice().sort((i,
|
|
40
|
+
${a&&a.length>0?a.slice().sort((i,l)=>i.breakpoint-l.breakpoint).map(i=>`
|
|
41
41
|
@media ${i.media||`(min-width: ${i.breakpoint}px)`} {
|
|
42
42
|
[data-part-internal="${n}-Container"] {
|
|
43
43
|
--${n}-items-per-slide: ${i.itemsPerSlide||1};
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
`).join(""):""}
|
|
47
|
-
`,[n,o,
|
|
47
|
+
`,[n,o,ge,e.length,t,E,s,a]);return{carouselFragment:N.jsxs("div",{ref:O,className:"ReactSpringCarouselContainer","data-part":"Container","data-part-internal":`${n}-Container`,...Gt(),children:[N.jsx("style",{dangerouslySetInnerHTML:{__html:qt}}),N.jsx("div",{ref:k,className:"ReactSpringCarouselTrack","data-part":"Track","data-part-internal":`${n}-Track`,onScroll:()=>{C.current=!1,V.current=!1},children:Array.from({length:Bt},(i,l)=>{const m=t?l%e.length:l,g=e[m],I=t&&(l<e.length||l>=e.length*2);if(h!==void 0){const P=t?e.length+w.current%e.length:w.current;if(Math.abs(l-P)>h)return N.jsx("div",{className:"ReactSpringCarouselItem","data-part":"Item","data-part-internal":`${n}-Item`,"data-id":g.id,"aria-hidden":"true",children:x==null?void 0:x({item:g,index:l,isClonedItem:I})},`${g.id}-${l}`)}const v=Yt[m],j=Ht[m];return N.jsx("div",{className:"ReactSpringCarouselItem","data-part":"Item","data-part-internal":`${n}-Item`,"data-id":g.id,children:typeof g.renderItem=="function"?g.renderItem({useListenToCustomEvent:je,index:l,isClonedItem:I,isActiveItem:Wt,isNextItem:v,isPrevItem:j}):g.renderItem},`${g.id}-${l}`)})})]}),useListenToCustomEvent:je,slideToNextItem:()=>de(),slideToPrevItem:()=>he(),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>w.current?de(i):he(i)}if(typeof i=="string"){const l=e.findIndex(m=>m.id===i);if(l<0){console.warn(`The item you're trying to slide doesn't exist. id: ${i}`);return}l>w.current?de(l):he(l)}}}}function Rt(r){let e=0;const t=getComputedStyle(r).getPropertyValue("gap");return t.includes("px")&&(e=Number(t.replace("px",""))),e}function Me(r){return r.scrollWidth-r.clientWidth}function ue(r){const e=r.children[0],t=Rt(r);return e.getBoundingClientRect().width+t}function jt({container:r,onReach:e}){const t=d.useRef("start"),n=d.useRef(0),[,s]=ie.useSpring(()=>({x:0}));function a(u){s.start({from:{x:r.current.scrollLeft},to:{x:u},onChange({value:c}){r.current&&(r.current.scrollLeft=c.x)}})}function o(u){if(!r.current||u==="next"&&t.current==="end"||u==="prev"&&t.current==="start")return;let c=0;if(u==="next"&&(n.current+=1),u==="prev"&&(n.current-=1),c=n.current*ue(r.current),u==="next"){const p=Me(r.current);c>p&&(t.current="end",c=p,e&&e("end"))}u==="prev"&&c<=0&&(t.current="start",n.current=0,c=0,e&&e("start")),a(c)}return d.useEffect(()=>{function u(){var O;const x=ue(r.current),E=((O=[...r.current.children].at(0))==null?void 0:O.getBoundingClientRect().width)||0,z=Array(r.current.childElementCount).fill(0).map((k,U)=>({index:U,start:x*U,end:x*(U+1)})),L=r.current.scrollLeft+E,$=z.find(k=>L>=k.start&&L<k.end);n.current=($==null?void 0:$.index)||0}function c(){s.stop()}function p(x){const E=x.target;E.scrollLeft===0?(n.current=0,t.current="start",e&&e("start")):E.scrollLeft>=Me(E)?(t.current="end",e&&e("end")):t.current!=="idle"&&(t.current="idle",e&&e("idle"))}let f,_=0;function h(){_=r.current.scrollLeft,clearTimeout(f),f=setTimeout(function(){r.current.scrollLeft===_&&u()},200)}if(r.current)return r.current.addEventListener("wheel",c,{passive:!0}),r.current.addEventListener("scroll",p),r.current.addEventListener("scroll",h),()=>{r.current&&(r.current.removeEventListener("scroll",h),r.current.removeEventListener("scroll",p),r.current.removeEventListener("wheel",c))}},[r,e]),d.useEffect(()=>{if(r.current){const u=new ResizeObserver(()=>{a(n.current*ue(r.current))});return u.observe(r.current),()=>{u.disconnect()}}},[]),{scrollToNext(){o("next")},scrollToPrev(){o("prev")}}}M.useSpringCarousel=Vt,M.useSpringScroll=jt,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Props
|
|
1
|
+
import { Props } from './types';
|
|
2
2
|
export declare function useSpringCarousel({ init, items, withLoop, id, gutter, itemsPerSlide, carouselAxis, startingPosition, enableGestures, slideWhenDragThresholdIsReached, slideType, initialActiveItem, renderWindow, renderPlaceholder, }: Props): {
|
|
3
3
|
carouselFragment: import("react/jsx-runtime").JSX.Element;
|
|
4
|
-
useListenToCustomEvent: (eventHandler: SpringCarouselEventsEventHandler) => void;
|
|
4
|
+
useListenToCustomEvent: (eventHandler: import('./types').SpringCarouselEventsEventHandler) => void;
|
|
5
5
|
slideToNextItem: () => void;
|
|
6
6
|
slideToPrevItem: () => void;
|
|
7
7
|
slideToItem: (id: string | number) => void;
|