react-spring-carousel 3.0.0-beta-2.1.1 → 3.0.0-beta-2.1.3
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 +555 -526
- package/dist/index.umd.js +10 -10
- package/dist/types.d.ts +12 -0
- package/dist/useSpringCarousel.d.ts +1 -1
- package/package.json +1 -1
- package/dist/utils.d.ts +0 -6
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(P,O){typeof exports=="object"&&typeof module<"u"?O(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"],O):(P=typeof globalThis<"u"?globalThis:P||self,O(P["react-spring-carousel"]={},P["react/jsx-runtime"],P["@react-spring/web"],P.React))})(this,function(P,O,Z,h){"use strict";function Re(r,e,t){return Math.max(e,Math.min(r,t))}const w={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 ue(r,e,t){return e===0||Math.abs(e)===1/0?Math.pow(r,t*5):r*e*t/(e+t*r)}function le(r,e,t,n=.15){return n===0?Re(r,e,t):r<e?-ue(e-r,t-e,n)+e:r>t?+ue(r-t,t-e,n)+t:r}function je(r,[e,t],[n,s]){const[[a,o],[l,c]]=r;return[le(e,a,o,n),le(t,l,c,s)]}function Be(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 Ue(r){var e=Be(r,"string");return typeof e=="symbol"?e:String(e)}function E(r,e,t){return e=Ue(e),e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function fe(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?fe(Object(t),!0).forEach(function(n){E(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):fe(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}const de={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 he(r){return r?r[0].toUpperCase()+r.slice(1):""}const Ke=["enter","leave"];function ze(r=!1,e){return r&&!Ke.includes(e)}function Ge(r,e="",t=!1){const n=de[r],s=n&&n[e]||e;return"on"+he(r)+he(s)+(ze(t,s)?"Capture":"")}const Fe=["gotpointercapture","lostpointercapture"];function We(r){let e=r.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const n=Fe.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(n);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:t}}function Ye(r,e=""){const t=de[r],n=t&&t[e]||e;return r+n}function H(r){return"touches"in r}function pe(r){return H(r)?"touch":"pointerType"in r?r.pointerType:"mouse"}function He(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 Xe(r){return r.type==="touchend"||r.type==="touchcancel"?r.changedTouches:r.targetTouches}function ge(r){return H(r)?Xe(r)[0]:r}function qe(r){return He(r).map(e=>e.identifier)}function ee(r){const e=ge(r);return H(r)?e.identifier:e.pointerId}function me(r){const e=ge(r);return[e.clientX,e.clientY]}function Je(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 X(r,...e){return typeof r=="function"?r(...e):r}function Qe(){}function Ze(...r){return r.length===0?Qe:r.length===1?r[0]:function(){let e;for(const t of r)e=t.apply(this,arguments)||e;return e}}function ve(r,e){return Object.assign({},e,r||{})}const et=32;class tt{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?X(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,Je(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 T=t._delta.map(Math.abs);w.addTo(t._distance,T)}this.axisIntent&&this.axisIntent(e);const[o,l]=t._movement,[c,p]=n.threshold,{_step:f,values:b}=t;if(n.hasCustomTransform?(f[0]===!1&&(f[0]=Math.abs(o)>=c&&b[0]),f[1]===!1&&(f[1]=Math.abs(l)>=p&&b[1])):(f[0]===!1&&(f[0]=Math.abs(o)>=c&&Math.sign(o)*c),f[1]===!1&&(f[1]=Math.abs(l)>=p&&Math.sign(l)*p)),t.intentional=f[0]!==!1||f[1]!==!1,!t.intentional)return;const g=[0,0];if(n.hasCustomTransform){const[T,Y]=b;g[0]=f[0]!==!1?T-f[0]:0,g[1]=f[1]!==!1?Y-f[1]:0}else g[0]=f[0]!==!1?o-f[0]:0,g[1]=f[1]!==!1?l-f[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(g);const x=t.offset,S=t._active&&!t._blocked||t.active;S&&(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=X(n.bounds,t)),this.setup&&this.setup()),t.movement=g,this.computeOffset()));const[V,D]=t.offset,[[$,C],[R,A]]=t._bounds;t.overflow=[V<$?-1:V>C?1:0,D<R?-1:D>A?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 N=t._active?n.rubberband||[0,0]:[0,0];if(t.offset=je(t._bounds,t.offset,N),t.delta=w.sub(t.offset,x),this.computeMovement(),S&&(!t.last||a>et)){t.delta=w.sub(t.offset,x);const T=t.delta.map(Math.abs);w.addTo(t.distance,T),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&a>0&&(t.velocity=[T[0]/a,T[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 rt([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 nt extends tt{constructor(...e){super(...e),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=w.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=w.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[pe(e)]:n.axisThreshold;t.axis=rt(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 ye=r=>r,be=.15,te={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[be,be];case!1:return[0,0];default:return w.toVector(r)}},from(r){if(typeof r=="function")return r;if(r!=null)return w.toVector(r)},transform(r,e,t){const n=r||t.shared.transform;if(this.hasCustomTransform=!!n,process.env.NODE_ENV==="development"){const s=n||ye;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||ye},threshold(r){return w.toVector(r,0)}};process.env.NODE_ENV==="development"&&Object.assign(te,{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 st=0,F=y(y({},te),{},{axis(r,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(r=st){return r},bounds(r={}){if(typeof r=="function")return a=>F.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]]}}),_e={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 it extends nt{constructor(...e){super(...e),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=F.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=ee(e),n._pointerActive=!0,this.computeValues(me(e)),this.computeInitial(),t.preventScrollAxis&&pe(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=ee(e);if(t._pointerId!==void 0&&s!==t._pointerId)return;const a=me(e);if(document.pointerLockElement===e.target?t._delta=[e.movementX,e.movementY]:(t._delta=w.sub(a,t._values),this.computeValues(a)),w.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=ee(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[l,c]=t._delta,[p,f]=t._movement,[b,g]=n.swipe.velocity,[x,S]=n.swipe.distance,V=n.swipe.duration;if(t.elapsedTime<V){const D=Math.abs(l/t.timeDelta),$=Math.abs(c/t.timeDelta);D>b&&Math.abs(p)>x&&(t.swipe[0]=Math.sign(l)),$>g&&Math.abs(f)>S&&(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,ot(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=_e[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,w.addTo(n._movement,n._delta),this.compute(e),this.emit()}}keyUp(e){e.key in _e&&(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 ot(r){"persist"in r&&typeof r.persist=="function"&&r.persist()}const W=typeof window<"u"&&window.document&&window.document.createElement;function we(){return W&&"ontouchstart"in window}function at(){return we()||W&&window.navigator.maxTouchPoints>1}function ct(){return W&&"onpointerdown"in window}function ut(){return W&&"exitPointerLock"in window.document}function lt(){try{return"constructor"in GestureEvent}catch{return!1}}const k={isBrowser:W,gesture:lt(),touch:we(),touchscreen:at(),pointer:ct(),pointerLock:ut()},ft=250,dt=180,ht=.5,pt=50,gt=250,mt=10,xe={mouse:0,touch:0,pen:8},Te=y(y({},F),{},{device(r,e,{pointer:{touch:t=!1,lock:n=!1,mouse:s=!1}={}}){return this.pointerLock=n&&k.pointerLock,k.touch&&t?"touch":this.pointerLock?"mouse":k.pointer&&!s?"pointer":k.touch?"touch":"mouse"},preventScrollAxis(r,e,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&r?ft:void 0,!(!k.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=w.toVector(r,t?n:s?1:0);return this.filterTaps=t,this.tapsThreshold=n,a},swipe({velocity:r=ht,distance:e=pt,duration:t=gt}={}){return{velocity:this.transform(w.toVector(r)),distance:this.transform(w.toVector(e)),duration:t}},delay(r=0){switch(r){case!0:return dt;case!1:return 0;default:return r}},axisThreshold(r){return r?y(y({},xe),r):xe},keyboardDisplacement(r=mt){return r}});process.env.NODE_ENV==="development"&&Object.assign(Te,{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({},te),{},{device(r,e,{shared:t,pointer:{touch:n=!1}={}}){if(t.target&&!k.touch&&k.gesture)return"gesture";if(k.touch&&n)return"touch";if(k.touchscreen){if(k.pointer)return"pointer";if(k.touch)return"touch"}},bounds(r,e,{scaleBounds:t={},angleBounds:n={}}){const s=o=>{const l=ve(X(t,o),{min:-1/0,max:1/0});return[l.min,l.max]},a=o=>{const l=ve(X(n,o),{min:-1/0,max:1/0});return[l.min,l.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",w.toVector(r,this.lockDirection?[.1,3]:0)},modifierKey(r){return r===void 0?"ctrlKey":r},pinchOnWheel(r=!0){return r}}),y(y({},F),{},{mouseOnly:(r=!0)=>r}),y(y({},F),{},{mouseOnly:(r=!0)=>r});const Ie=new Map,re=new Map;function vt(r){Ie.set(r.key,r.engine),re.set(r.key,r.resolver)}const yt={key:"drag",engine:it,resolver:Te};function bt(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 _t(r,e){if(r==null)return{};var t=bt(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 wt={target(r){if(r)return()=>"current"in r?r.current:r},enabled(r=!0){return r},window(r=k.isBrowser?window:void 0){return r},eventOptions({passive:r=!0,capture:e=!1}={}){return{passive:r,capture:e}},transform(r){return r}},xt=["target","eventOptions","window","enabled","transform"];function q(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]=q(r[n],s);break;case"boolean":s&&(t[n]=r[n]);break}return t}function Tt(r,e,t={}){const n=r,{target:s,eventOptions:a,window:o,enabled:l,transform:c}=n,p=_t(n,xt);if(t.shared=q({target:s,eventOptions:a,window:o,enabled:l,transform:c},wt),e){const f=re.get(e);t[e]=q(y({shared:t.shared},p),f)}else for(const f in p){const b=re.get(f);if(b)t[f]=q(y({shared:t.shared},p[f]),b);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 Ee{constructor(e,t){E(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,n,s,a){const o=this._listeners,l=Ye(t,n),c=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},p=y(y({},c),a);e.addEventListener(l,s,p);const f=()=>{e.removeEventListener(l,s,p),o.delete(f)};return o.add(f),f}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class It{constructor(){E(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 Et{constructor(e){E(this,"gestures",new Set),E(this,"_targetEventStore",new Ee(this)),E(this,"gestureEventStores",{}),E(this,"gestureTimeoutStores",{}),E(this,"handlers",{}),E(this,"config",{}),E(this,"pointerIds",new Set),E(this,"touchIds",new Set),E(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),St(this,e)}setEventIds(e){if(H(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=Tt(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 l=this.config[o],c=Se(n,l.eventOptions,!!s);if(l.enabled){const p=Ie.get(o);new p(this,e,o).bind(c)}}const a=Se(n,t.eventOptions,!!s);for(const o in this.nativeHandlers)a(o,"",l=>this.nativeHandlers[o](y(y({},this.state.shared),{},{event:l,args:e})),void 0,!0)}for(const a in n)n[a]=Ze(...n[a]);if(!s)return n;for(const a in n){const{device:o,capture:l,passive:c}=We(a);this._targetEventStore.add(s,o,"",n[a],{capture:l,passive:c})}}}}function U(r,e){r.gestures.add(e),r.gestureEventStores[e]=new Ee(r,e),r.gestureTimeoutStores[e]=new It}function St(r,e){e.drag&&U(r,"drag"),e.wheel&&U(r,"wheel"),e.scroll&&U(r,"scroll"),e.move&&U(r,"move"),e.pinch&&U(r,"pinch"),e.hover&&U(r,"hover")}const Se=(r,e,t)=>(n,s,a,o={},l=!1)=>{var c,p;const f=(c=o.capture)!==null&&c!==void 0?c:e.capture,b=(p=o.passive)!==null&&p!==void 0?p:e.passive;let g=l?n:Ge(n,s,f);t&&b&&(g+="Passive"),r[g]=r[g]||[],r[g].push(a)};function kt(r,e={},t,n){const s=h.useMemo(()=>new Et(r),[]);if(s.applyHandlers(r,n),s.applyConfig(e,t),h.useEffect(s.effect.bind(s)),h.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function Dt(r,e){return vt(yt),kt({drag:r},e||{},"drag")}function Ct(r){const{type:e,actionType:t,toIndex:n,itemsLength:s,withLoop:a,scrollAmount:o,totalAvailable:l}=r;let c=r.currentActive,p=r.fromValueRaw,f=!1,b=!1;e==="next"&&(c+=1),e==="prev"&&(c=c===0?s-1:c-1),n!==void 0&&(c=n);let g=0;e==="next"&&(g=-(c*o),a&&c===s&&(c=0,p=p+o*s,g=0),!a&&(Math.abs(g)>=l||c===s-1)&&(b=!0,g=-l)),e==="prev"&&(g=-(c*o),c===s-1&&(p=p-s*o),!a&&g>=0&&(f=!0,g=0)),t==="resize"&&(g=-(c*o));const x=a?c%s:c,S=a?s+c%s:c;return{newActive:c,fromValue:p,toValue:g,startReached:f,endReached:b,logicalIndex:x,realTrackIndex:S}}function J(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 At(){const r=h.useRef(null);r.current===null&&(r.current=new Set);const e=h.useRef(null);return e.current===null&&(e.current={useListenToCustomEvent(t){h.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 $t(r){let e=r.replace(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm,"");return e=e.replace(/[\n\t]+/g," "),e=e.replace(/\s*([{}:;,])\s*/g,"$1"),e=e.replace(/\s+}/g,"}"),e=e.replace(/{\s+/g,"{"),e=e.replace(/\s+/g," "),e.trim()}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:l="start",enableGestures:c=!0,slideWhenDragThresholdIsReached:p=!0,slideType:f="item",initialActiveItem:b=0,renderWindow:g}){const[x,S]=h.useState(!1),[,V]=h.useState(0),D=h.useRef(r),$=h.useRef(null),C=h.useRef(null),R=h.useRef(0),A=h.useRef(0),N=h.useRef(!t),T=h.useRef(!1),Y=h.useRef(0),_=h.useRef(0),De=h.useRef(e);De.current=e;const Ce=h.useRef(t);Ce.current=t;const Ae=h.useRef(!1),B=h.useRef(null),M=h.useRef(null);function $e(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 u=e.findIndex(v=>v.id===i);return u<0?(console.warn(`initialActiveItem: item with id "${i}" doesn't exist.`),0):u}const Q=Z.useSpringRef(),se=Z.useSpring({value:0,ref:Q,onChange({value:i}){C.current.style.transform=J(i.value,o,n)}}),Mt=t?e.length*3:e.length,{useListenToCustomEvent:Pe,emitEvent:K}=At();function Oe(i){if(!i||i.length===0)return null;let u=null,v=-1/0;for(const m of i)(m.media?window.matchMedia(m.media).matches:window.innerWidth>=m.breakpoint)&&m.breakpoint>=v&&(u=m,v=m.breakpoint);return u}function Ne(){const{totalGutterCssVar:i}=Me();return i}function Lt(){const i=Oe(a);return(i==null?void 0:i.itemsPerSlide)||1}function ie(i){D.current&&(T.current||z({type:"next",toIndex:i,actionType:"click"}))}function oe(i){D.current&&(N.current||z({type:"prev",toIndex:i,actionType:"click"}))}function z({type:i,shouldAnimate:u=!0,toIndex:v,actionType:m}){var L,j;const I=!u;N.current=!1,T.current=!1;const d=Ct({type:i,actionType:m,toIndex:v,currentActive:_.current,itemsLength:e.length,withLoop:t,scrollAmount:A.current,totalAvailable:i==="next"?ae(t?A.current*(e.length*2):0):0,fromValueRaw:se.value.get()});_.current=d.newActive,N.current=d.startReached,T.current=d.endReached,R.current=d.toValue,g!==void 0&&V(G=>G+1),K(m==="resize"?{eventName:"onResize",sliceActionType:m,slideDirection:i,currentItem:{id:((L=e.at(d.logicalIndex))==null?void 0:L.id)??"",index:d.logicalIndex,trackIndex:d.realTrackIndex,startReached:N.current,endReached:T.current}}:{eventName:"onSlideStartChange",sliceActionType:m,slideDirection:i,nextItem:{index:d.logicalIndex,id:((j=e.at(d.logicalIndex))==null?void 0:j.id)??"",trackIndex:d.realTrackIndex,startReached:N.current,endReached:T.current}}),Q.start({immediate:I,from:{value:d.fromValue},to:{value:d.toValue},onChange({value:G}){C.current.style.transform=J(G.value,o,n)},onRest({finished:G}){var Le;if(G){const Ve=t?_.current%e.length:_.current,Ft=t?e.length+_.current%e.length:_.current;K({eventName:"onSlideChangeComplete",sliceActionType:m,slideDirection:i,currentItem:{index:Ve,id:((Le=e.at(Ve))==null?void 0:Le.id)??"",trackIndex:Ft,startReached:N.current,endReached:T.current}})}}})}function Vt(){const i=C.current;let u=0;return f==="item"?u=i.children[0].getBoundingClientRect()[o==="x"?"width":"height"]+Ne():u=i.getBoundingClientRect()[o==="x"?"width":"height"]+Ne(),u}function ae(i){const u=C.current;return u[o==="x"?"scrollWidth":"scrollHeight"]-u.getBoundingClientRect()[o==="x"?"width":"height"]-i}function Me(){const i=Oe(s);return{totalGutterCssVar:(i==null?void 0:i.gutter)||0,totalStartEndGutterCssVar:((i==null?void 0:i.startEndGutter)||0)*2}}h.useEffect(()=>{function i(I){const d=Lt();switch(I){case"start":return 0;case"middle-start":return Math.floor((d-1)*.25);case"center":return Math.floor((d-1)*.5);case"middle-end":return Math.floor((d-1)*.75);case"end":return d-1;default:return 0}}function u(){A.current=Vt(),Y.current=A.current/4;const{totalStartEndGutterCssVar:I}=Me();let d=0;t&&(d=A.current*e.length),d-=A.current*i(l),d-=I/2,$.current.style.setProperty(`--${n}-offset-modifier`,`${-d}px`)}function v(I){if($.current&&(u(),S(!0),I)){const d=$e(b),L=t?e.length+d%e.length:d;K({eventName:"onInit",index:d,trackIndex:L})}}function m(){v(),z({type:"resize",toIndex:_.current,shouldAnimate:!1,actionType:"resize"})}if(r)return D.current=!0,Ae.current?m():(v(!0),Ae.current=!0),window.addEventListener("resize",m),()=>{window.removeEventListener("resize",m)}},[r,n,o,t]),h.useEffect(()=>{const i=$e(b);r&&i!==_.current&&z({type:"next",toIndex:i,actionType:"resize",shouldAnimate:!1})},[r,b]);const ce=c;function Rt(){if(M.current!==null&&(cancelAnimationFrame(M.current),M.current=null),B.current){const i=B.current;B.current=null,K(i)}}function jt(i){B.current=i,M.current===null&&(M.current=requestAnimationFrame(()=>{M.current=null;const u=B.current;B.current=null,u&&K(u)}))}h.useEffect(()=>()=>{M.current!==null&&(cancelAnimationFrame(M.current),M.current=null),B.current=null},[]);const Bt=Dt(i=>{if(!D.current)return;const u=i.dragging,v=i.offset[o==="x"?0:1],m=i.movement[o==="x"?0:1],I=m>Y.current,d=m<-Y.current,L=i.velocity;u&&(jt({...i,eventName:"onDrag",slideActionType:"drag"}),Q.start({value:v,immediate:!0,config:{velocity:L},onChange({value:j}){C.current.style.transform=J(j.value,o,n)}}),p&&(I||d)&&i.cancel()),i.last&&(Rt(),I?(z({actionType:"drag",type:"prev"}),i.cancel()):d?(z({actionType:"drag",type:"next"}),i.cancel()):(Q.start({value:R.current,config:{velocity:L},onChange({value:j}){C.current.style.transform=J(j.value,o,n)}}),i.cancel()))},{enabled:ce,axis:o,rubberband:!t,...t?{}:{bounds:()=>({right:0,left:-ae(0),top:-ae(0),bottom:0})},from:()=>[se.value.get(),se.value.get()]}),Ut=h.useCallback(i=>{var d;const u=De.current,m=Ce.current?u.length+_.current%u.length:_.current;if(typeof i=="number")return m===i;const I=_.current%u.length;return i===((d=u[I])==null?void 0:d.id)},[]),Kt=h.useMemo(()=>Array.from({length:e.length},(i,u)=>()=>{const v=t?_.current%e.length:_.current;return t?u===(v+1)%e.length:v+1>=e.length?!1:u===v+1}),[e.length,t]),zt=h.useMemo(()=>Array.from({length:e.length},(i,u)=>()=>{const v=t?_.current%e.length:_.current;return t?u===(v-1+e.length)%e.length:v-1<0?!1:u===v-1}),[e.length,t]),Gt=h.useMemo(()=>$t(`
|
|
1
|
+
(function(P,M){typeof exports=="object"&&typeof module<"u"?M(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"],M):(P=typeof globalThis<"u"?globalThis:P||self,M(P["react-spring-carousel"]={},P["react/jsx-runtime"],P["@react-spring/web"],P.React))})(this,function(P,M,te,d){"use strict";function Ue(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 de(r,e,t){return e===0||Math.abs(e)===1/0?Math.pow(r,t*5):r*e*t/(e+t*r)}function he(r,e,t,n=.15){return n===0?Ue(r,e,t):r<e?-de(e-r,t-e,n)+e:r>t?+de(r-t,t-e,n)+t:r}function Ke(r,[e,t],[n,s]){const[[o,a],[u,c]]=r;return[he(e,o,a,n),he(t,u,c,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 Fe(r){var e=ze(r,"string");return typeof e=="symbol"?e:String(e)}function k(r,e,t){return e=Fe(e),e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function pe(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?pe(Object(t),!0).forEach(function(n){k(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):pe(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}const ge={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 me(r){return r?r[0].toUpperCase()+r.slice(1):""}const Ge=["enter","leave"];function We(r=!1,e){return r&&!Ge.includes(e)}function Ye(r,e="",t=!1){const n=ge[r],s=n&&n[e]||e;return"on"+me(r)+me(s)+(We(t,s)?"Capture":"")}const He=["gotpointercapture","lostpointercapture"];function qe(r){let e=r.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const n=He.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(n);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:t}}function Xe(r,e=""){const t=ge[r],n=t&&t[e]||e;return r+n}function X(r){return"touches"in r}function ve(r){return X(r)?"touch":"pointerType"in r?r.pointerType:"mouse"}function Je(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 Qe(r){return r.type==="touchend"||r.type==="touchcancel"?r.changedTouches:r.targetTouches}function ye(r){return X(r)?Qe(r)[0]:r}function Ze(r){return Je(r).map(e=>e.identifier)}function re(r){const e=ye(r);return X(r)?e.identifier:e.pointerId}function be(r){const e=ye(r);return[e.clientX,e.clientY]}function et(r){const e={};if("buttons"in r&&(e.buttons=r.buttons),"shiftKey"in r){const{shiftKey:t,altKey:n,metaKey:s,ctrlKey:o}=r;Object.assign(e,{shiftKey:t,altKey:n,metaKey:s,ctrlKey:o})}return e}function J(r,...e){return typeof r=="function"?r(...e):r}function tt(){}function rt(...r){return r.length===0?tt:r.length===1?r[0]:function(){let e;for(const t of r)e=t.apply(this,arguments)||e;return e}}function _e(r,e){return Object.assign({},e,r||{})}const nt=32;class st{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?J(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 o=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,et(e)),s.down=s.pressed=s.buttons%2===1||s.touches>0,o=e.timeStamp-t.timeStamp,t.timeStamp=e.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const S=t._delta.map(Math.abs);T.addTo(t._distance,S)}this.axisIntent&&this.axisIntent(e);const[a,u]=t._movement,[c,p]=n.threshold,{_step:f,values:_}=t;if(n.hasCustomTransform?(f[0]===!1&&(f[0]=Math.abs(a)>=c&&_[0]),f[1]===!1&&(f[1]=Math.abs(u)>=p&&_[1])):(f[0]===!1&&(f[0]=Math.abs(a)>=c&&Math.sign(a)*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[S,L]=_;h[0]=f[0]!==!1?S-f[0]:0,h[1]=f[1]!==!1?L-f[1]:0}else h[0]=f[0]!==!1?a-f[0]:0,h[1]=f[1]!==!1?u-f[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(h);const E=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=J(n.bounds,t)),this.setup&&this.setup()),t.movement=h,this.computeOffset()));const[j,N]=t.offset,[[$,O],[D,B]]=t._bounds;t.overflow=[j<$?-1:j>O?1:0,N<D?-1:N>B?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=Ke(t._bounds,t.offset,U),t.delta=T.sub(t.offset,E),this.computeMovement(),I&&(!t.last||o>nt)){t.delta=T.sub(t.offset,E);const S=t.delta.map(Math.abs);T.addTo(t.distance,S),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&o>0&&(t.velocity=[S[0]/o,S[1]/o],t.timeDelta=o)}}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 it([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 ot extends st{constructor(...e){super(...e),k(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[ve(e)]:n.axisThreshold;t.axis=it(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 we=r=>r,xe=.15,ne={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[xe,xe];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||we;return o=>{const a=s(o);return(!isFinite(a[0])||!isFinite(a[1]))&&console.warn(`[@use-gesture]: config.transform() must produce a valid result, but it was: [${a[0]},${[1]}]`),a}}return n||we},threshold(r){return T.toVector(r,0)}};process.env.NODE_ENV==="development"&&Object.assign(ne,{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 at=0,Y=y(y({},ne),{},{axis(r,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(r=at){return r},bounds(r={}){if(typeof r=="function")return o=>Y.bounds(r(o));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]]}}),Te={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 ct extends ot{constructor(...e){super(...e),k(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=Y.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=re(e),n._pointerActive=!0,this.computeValues(be(e)),this.computeInitial(),t.preventScrollAxis&&ve(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=re(e);if(t._pointerId!==void 0&&s!==t._pointerId)return;const o=be(e);if(document.pointerLockElement===e.target?t._delta=[e.movementX,e.movementY]:(t._delta=T.sub(o,t._values),this.computeValues(o)),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=re(e);if(t._pointerId!==void 0&&s!==t._pointerId)return;this.state._pointerActive=!1,this.setActive(),this.compute(e);const[o,a]=t._distance;if(t.tap=o<=n.tapsThreshold&&a<=n.tapsThreshold,t.tap&&n.filterTaps)t._force=!0;else{const[u,c]=t._delta,[p,f]=t._movement,[_,h]=n.swipe.velocity,[E,I]=n.swipe.distance,j=n.swipe.duration;if(t.elapsedTime<j){const N=Math.abs(u/t.timeDelta),$=Math.abs(c/t.timeDelta);N>_&&Math.abs(p)>E&&(t.swipe[0]=Math.sign(u)),$>h&&Math.abs(f)>I&&(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,ut(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=Te[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 Te&&(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 ut(r){"persist"in r&&typeof r.persist=="function"&&r.persist()}const H=typeof window<"u"&&window.document&&window.document.createElement;function Ee(){return H&&"ontouchstart"in window}function lt(){return Ee()||H&&window.navigator.maxTouchPoints>1}function ft(){return H&&"onpointerdown"in window}function dt(){return H&&"exitPointerLock"in window.document}function ht(){try{return"constructor"in GestureEvent}catch{return!1}}const A={isBrowser:H,gesture:ht(),touch:Ee(),touchscreen:lt(),pointer:ft(),pointerLock:dt()},pt=250,gt=180,mt=.5,vt=50,yt=250,bt=10,Ie={mouse:0,touch:0,pen:8},Se=y(y({},Y),{},{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?pt: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 o=T.toVector(r,t?n:s?1:0);return this.filterTaps=t,this.tapsThreshold=n,o},swipe({velocity:r=mt,distance:e=vt,duration:t=yt}={}){return{velocity:this.transform(T.toVector(r)),distance:this.transform(T.toVector(e)),duration:t}},delay(r=0){switch(r){case!0:return gt;case!1:return 0;default:return r}},axisThreshold(r){return r?y(y({},Ie),r):Ie},keyboardDisplacement(r=bt){return r}});process.env.NODE_ENV==="development"&&Object.assign(Se,{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({},ne),{},{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=a=>{const u=_e(J(t,a),{min:-1/0,max:1/0});return[u.min,u.max]},o=a=>{const u=_e(J(n,a),{min:-1/0,max:1/0});return[u.min,u.max]};return typeof t!="function"&&typeof n!="function"?[s(),o()]:a=>[s(a),o(a)]},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({},Y),{},{mouseOnly:(r=!0)=>r}),y(y({},Y),{},{mouseOnly:(r=!0)=>r});const ke=new Map,se=new Map;function _t(r){ke.set(r.key,r.engine),se.set(r.key,r.resolver)}const wt={key:"drag",engine:ct,resolver:Se};function xt(r,e){if(r==null)return{};var t={},n=Object.keys(r),s,o;for(o=0;o<n.length;o++)s=n[o],!(e.indexOf(s)>=0)&&(t[s]=r[s]);return t}function Tt(r,e){if(r==null)return{};var t=xt(r,e),n,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(r);for(s=0;s<o.length;s++)n=o[s],!(e.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(r,n)&&(t[n]=r[n])}return t}const Et={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}},It=["target","eventOptions","window","enabled","transform"];function Q(r={},e){const t={};for(const[n,s]of Object.entries(e))switch(typeof s){case"function":if(process.env.NODE_ENV==="development"){const o=s.call(t,r[n],n,r);Number.isNaN(o)||(t[n]=o)}else t[n]=s.call(t,r[n],n,r);break;case"object":t[n]=Q(r[n],s);break;case"boolean":s&&(t[n]=r[n]);break}return t}function St(r,e,t={}){const n=r,{target:s,eventOptions:o,window:a,enabled:u,transform:c}=n,p=Tt(n,It);if(t.shared=Q({target:s,eventOptions:o,window:a,enabled:u,transform:c},Et),e){const f=se.get(e);t[e]=Q(y({shared:t.shared},p),f)}else for(const f in p){const _=se.get(f);if(_)t[f]=Q(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 Ce{constructor(e,t){k(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,n,s,o){const a=this._listeners,u=Xe(t,n),c=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},p=y(y({},c),o);e.addEventListener(u,s,p);const f=()=>{e.removeEventListener(u,s,p),a.delete(f)};return a.add(f),f}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class kt{constructor(){k(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 Ct{constructor(e){k(this,"gestures",new Set),k(this,"_targetEventStore",new Ce(this)),k(this,"gestureEventStores",{}),k(this,"gestureTimeoutStores",{}),k(this,"handlers",{}),k(this,"config",{}),k(this,"pointerIds",new Set),k(this,"touchIds",new Set),k(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),Dt(this,e)}setEventIds(e){if(X(e))return this.touchIds=new Set(Ze(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=St(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 a of this.gestures){const u=this.config[a],c=De(n,u.eventOptions,!!s);if(u.enabled){const p=ke.get(a);new p(this,e,a).bind(c)}}const o=De(n,t.eventOptions,!!s);for(const a in this.nativeHandlers)o(a,"",u=>this.nativeHandlers[a](y(y({},this.state.shared),{},{event:u,args:e})),void 0,!0)}for(const o in n)n[o]=rt(...n[o]);if(!s)return n;for(const o in n){const{device:a,capture:u,passive:c}=qe(o);this._targetEventStore.add(s,a,"",n[o],{capture:u,passive:c})}}}}function z(r,e){r.gestures.add(e),r.gestureEventStores[e]=new Ce(r,e),r.gestureTimeoutStores[e]=new kt}function Dt(r,e){e.drag&&z(r,"drag"),e.wheel&&z(r,"wheel"),e.scroll&&z(r,"scroll"),e.move&&z(r,"move"),e.pinch&&z(r,"pinch"),e.hover&&z(r,"hover")}const De=(r,e,t)=>(n,s,o,a={},u=!1)=>{var c,p;const f=(c=a.capture)!==null&&c!==void 0?c:e.capture,_=(p=a.passive)!==null&&p!==void 0?p:e.passive;let h=u?n:Ye(n,s,f);t&&_&&(h+="Passive"),r[h]=r[h]||[],r[h].push(o)};function At(r,e={},t,n){const s=d.useMemo(()=>new Ct(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 $t(r,e){return _t(wt),At({drag:r},e||{},"drag")}function Ot(r){const{type:e,actionType:t,toIndex:n,itemsLength:s,withLoop:o,scrollAmount:a,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*a),o&&c===s&&(c=0,p=p+a*s,h=0),!o&&(Math.abs(h)>=u||c===s-1)&&(_=!0,h=-u)),e==="prev"&&(h=-(c*a),c===s-1&&(p=p-s*a),!o&&h>=0&&(f=!0,h=0)),t==="resize"&&(h=-(c*a),o||(c===0&&(f=!0),(c===s-1||Math.abs(h)>=u)&&(_=!0,Math.abs(h)>=u&&u>0&&(h=-u))));const E=o?c%s:c,I=o?s+c%s:c;return{newActive:c,fromValue:p,toValue:h,startReached:f,endReached:_,logicalIndex:E,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 Pt(){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 Mt({init:r=!0,items:e,withLoop:t=!1,id:n,gutter:s=[{breakpoint:0,gutter:0,startEndGutter:0}],itemsPerSlide:o=[{breakpoint:0,itemsPerSlide:1}],carouselAxis:a="x",startingPosition:u="start",enableGestures:c=!0,slideWhenDragThresholdIsReached:p=!0,slideType:f="item",initialActiveItem:_=0,renderWindow:h,renderPlaceholder:E}){const[I,j]=d.useState(!1),[,N]=d.useState(0),$=d.useRef(r),O=d.useRef(null),D=d.useRef(null),B=d.useRef(0),U=d.useRef(0),S=d.useRef(!t),L=d.useRef(!1),oe=d.useRef(0),w=d.useRef(0),$e=d.useRef(e);$e.current=e;const Oe=d.useRef(t);Oe.current=t;const Pe=d.useRef(!1),K=d.useRef(null),V=d.useRef(null),F=d.useRef(null),q=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 l=e.findIndex(v=>v.id===i);return l<0?(console.warn(`initialActiveItem: item with id "${i}" doesn't exist.`),0):l}const ee=te.useSpringRef(),ae=te.useSpring({value:0,ref:ee,onChange({value:i}){D.current.style.transform=Z(i.value,a,n)}}),Vt=t?e.length*3:e.length,{useListenToCustomEvent:Ne,emitEvent:G}=Pt();function Le(i){if(!i||i.length===0)return null;let l=null,v=-1/0;for(const g of i)(g.media?window.matchMedia(g.media).matches:window.innerWidth>=g.breakpoint)&&g.breakpoint>=v&&(l=g,v=g.breakpoint);return l}function Ve(){const{totalGutterCssVar:i}=Re();return i}function Rt(){const i=Le(o);return(i==null?void 0:i.itemsPerSlide)||1}function ce(i){$.current&&(L.current||W({type:"next",toIndex:i,actionType:"click"}))}function ue(i){$.current&&(S.current||W({type:"prev",toIndex:i,actionType:"click"}))}function W({type:i,shouldAnimate:l=!0,toIndex:v,actionType:g}){var x,m;const C=!l;S.current=!1,L.current=!1;const b=Ot({type:i,actionType:g,toIndex:v,currentActive:w.current,itemsLength:e.length,withLoop:t,scrollAmount:U.current,totalAvailable:i==="next"||g==="resize"?le(t?U.current*(e.length*2):0):0,fromValueRaw:ae.value.get()});w.current=b.newActive,S.current=b.startReached,L.current=b.endReached,B.current=b.toValue,h!==void 0&&N(R=>R+1),G(g==="resize"?{eventName:"onResize",sliceActionType:g,slideDirection:i,currentItem:{id:((x=e.at(b.logicalIndex))==null?void 0:x.id)??"",index:b.logicalIndex,trackIndex:b.realTrackIndex,startReached:S.current,endReached:L.current}}:{eventName:"onSlideStartChange",sliceActionType:g,slideDirection:i,nextItem:{index:b.logicalIndex,id:((m=e.at(b.logicalIndex))==null?void 0:m.id)??"",trackIndex:b.realTrackIndex,startReached:S.current,endReached:L.current}}),ee.start({immediate:C,from:{value:b.fromValue},to:{value:b.toValue},onChange({value:R}){D.current.style.transform=Z(R.value,a,n)},onRest({finished:R}){var je;if(R){const Be=t?w.current%e.length:w.current,Yt=t?e.length+w.current%e.length:w.current;G({eventName:"onSlideChangeComplete",sliceActionType:g,slideDirection:i,currentItem:{index:Be,id:((je=e.at(Be))==null?void 0:je.id)??"",trackIndex:Yt,startReached:S.current,endReached:L.current}})}}})}function jt(){const i=D.current;let l=0;return f==="item"?l=i.children[0].getBoundingClientRect()[a==="x"?"width":"height"]+Ve():l=i.getBoundingClientRect()[a==="x"?"width":"height"]+Ve(),l}function le(i){const l=D.current;return l[a==="x"?"scrollWidth":"scrollHeight"]-l.getBoundingClientRect()[a==="x"?"width":"height"]-i}function Re(){const i=Le(s);return{totalGutterCssVar:(i==null?void 0:i.gutter)||0,totalStartEndGutterCssVar:((i==null?void 0:i.startEndGutter)||0)*2}}d.useEffect(()=>{function i(x){const m=Rt();switch(x){case"start":return 0;case"middle-start":return Math.floor((m-1)*.25);case"center":return Math.floor((m-1)*.5);case"middle-end":return Math.floor((m-1)*.75);case"end":return m-1;default:return 0}}function l(){U.current=jt(),oe.current=U.current/4;const{totalStartEndGutterCssVar:x}=Re();let m=0;t&&(m=U.current*e.length),m-=U.current*i(u),m-=x/2,O.current.style.setProperty(`--${n}-offset-modifier`,`${-m}px`)}function v(x){if(O.current&&(l(),j(!0),x)){const m=Me(_),R=t?e.length+m%e.length:m;G({eventName:"onInit",index:m,trackIndex:R})}}function g(){v(),W({type:"resize",toIndex:w.current,shouldAnimate:!1,actionType:"resize"})}function C(){F.current===null&&(F.current=requestAnimationFrame(()=>{F.current=null;const x=O.current;if(!x)return;const m=x.getBoundingClientRect();(m.width!==q.current.width||m.height!==q.current.height)&&(q.current={width:m.width,height:m.height},g())}))}function b(){setTimeout(()=>{q.current={width:0,height:0},C()},250)}if(r){if($.current=!0,Pe.current)g();else if(v(!0),Pe.current=!0,O.current){const m=O.current.getBoundingClientRect();q.current={width:m.width,height:m.height}}const x=window.visualViewport??window;return x.addEventListener("resize",C),window.addEventListener("orientationchange",b),()=>{x.removeEventListener("resize",C),window.removeEventListener("orientationchange",b),F.current!==null&&(cancelAnimationFrame(F.current),F.current=null)}}},[r,n,a,t]),d.useEffect(()=>{const i=Me(_);r&&i!==w.current&&W({type:"next",toIndex:i,actionType:"resize",shouldAnimate:!1})},[r,_]);const fe=c;function Bt(){if(V.current!==null&&(cancelAnimationFrame(V.current),V.current=null),K.current){const i=K.current;K.current=null,G(i)}}function Ut(i){K.current=i,V.current===null&&(V.current=requestAnimationFrame(()=>{V.current=null;const l=K.current;K.current=null,l&&G(l)}))}d.useEffect(()=>()=>{V.current!==null&&(cancelAnimationFrame(V.current),V.current=null),K.current=null},[]);const Kt=$t(i=>{if(!$.current)return;const l=i.dragging,v=i.offset[a==="x"?0:1],g=i.movement[a==="x"?0:1],C=g>oe.current,b=g<-oe.current,x=i.velocity;l&&(Ut({...i,eventName:"onDrag",slideActionType:"drag"}),ee.start({value:v,immediate:!0,config:{velocity:x},onChange({value:m}){D.current.style.transform=Z(m.value,a,n)}}),p&&(C||b)&&i.cancel()),i.last&&(Bt(),C?(W({actionType:"drag",type:"prev"}),i.cancel()):b?(W({actionType:"drag",type:"next"}),i.cancel()):(ee.start({value:B.current,config:{velocity:x},onChange({value:m}){D.current.style.transform=Z(m.value,a,n)}}),i.cancel()))},{enabled:fe,axis:a,rubberband:!t,...t?{}:{bounds:()=>({right:0,left:-le(0),top:-le(0),bottom:0})},from:()=>[ae.value.get(),ae.value.get()]}),zt=d.useCallback(i=>{var b;const l=$e.current,g=Oe.current?l.length+w.current%l.length:w.current;if(typeof i=="number")return g===i;const C=w.current%l.length;return i===((b=l[C])==null?void 0:b.id)},[]),Ft=d.useMemo(()=>Array.from({length:e.length},(i,l)=>()=>{const v=t?w.current%e.length:w.current;return t?l===(v+1)%e.length:v+1>=e.length?!1:l===v+1}),[e.length,t]),Gt=d.useMemo(()=>Array.from({length:e.length},(i,l)=>()=>{const v=t?w.current%e.length:w.current;return t?l===(v-1+e.length)%e.length:v-1<0?!1:l===v-1}),[e.length,t]),Wt=d.useMemo(()=>`
|
|
2
2
|
[data-part-internal="${n}-Container"] {
|
|
3
3
|
display: flex;
|
|
4
4
|
width: 100%;
|
|
@@ -7,19 +7,19 @@
|
|
|
7
7
|
--${n}-items-per-slide: 1;
|
|
8
8
|
--${n}-offset-position: 0px;
|
|
9
9
|
--${n}-offset-modifier: 0px;
|
|
10
|
-
--${n}-scroll-x-value: ${
|
|
11
|
-
--${n}-scroll-y-value: ${
|
|
10
|
+
--${n}-scroll-x-value: ${a==="x"?`calc(var(--${n}-offset-position) + var(--${n}-offset-modifier))`:"0px"};
|
|
11
|
+
--${n}-scroll-y-value: ${a==="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: ${fe?a==="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&&
|
|
21
|
-
top: ${t&&
|
|
22
|
-
flex-direction: ${
|
|
20
|
+
left: ${t&&a==="x"&&!I?"var(--initial-offset-modifier)":"0px"};
|
|
21
|
+
top: ${t&&a==="y"&&!I?"var(--initial-offset-modifier)":"0px"};
|
|
22
|
+
flex-direction: ${a==="x"?"row":"column"};
|
|
23
23
|
width: 100%;
|
|
24
24
|
height: 100%;
|
|
25
25
|
gap: var(--${n}-gutter);
|
|
@@ -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
|
-
${
|
|
40
|
+
${o&&o.length>0?o.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
|
-
|
|
47
|
+
`,[n,a,fe,e.length,t,I,s,o]);return{carouselFragment:M.jsxs("div",{ref:O,className:"ReactSpringCarouselContainer","data-part":"Container","data-part-internal":`${n}-Container`,...Kt(),children:[M.jsx("style",{dangerouslySetInnerHTML:{__html:Wt}}),M.jsx("div",{ref:D,className:"ReactSpringCarouselTrack","data-part":"Track","data-part-internal":`${n}-Track`,onScroll:()=>{S.current=!1,L.current=!1},children:Array.from({length:Vt},(i,l)=>{const v=t?l%e.length:l,g=e[v],C=t&&(l<e.length||l>=e.length*2);if(h!==void 0){const m=t?e.length+w.current%e.length:w.current;if(Math.abs(l-m)>h)return M.jsx("div",{className:"ReactSpringCarouselItem","data-part":"Item","data-part-internal":`${n}-Item`,"data-id":g.id,"aria-hidden":"true",children:E==null?void 0:E({item:g,index:l,isClonedItem:C})},`${g.id}-${l}`)}const b=Ft[v],x=Gt[v];return M.jsx("div",{className:"ReactSpringCarouselItem","data-part":"Item","data-part-internal":`${n}-Item`,"data-id":g.id,children:typeof g.renderItem=="function"?g.renderItem({useListenToCustomEvent:Ne,index:l,isClonedItem:C,isActiveItem:zt,isNextItem:b,isPrevItem:x}):g.renderItem},`${g.id}-${l}`)})})]}),useListenToCustomEvent:Ne,slideToNextItem:()=>ce(),slideToPrevItem:()=>ue(),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?ce(i):ue(i)}if(typeof i=="string"){const l=e.findIndex(v=>v.id===i);if(l<0){console.warn(`The item you're trying to slide doesn't exist. id: ${i}`);return}l>w.current?ce(l):ue(l)}}}}function Nt(r){let e=0;const t=getComputedStyle(r).getPropertyValue("gap");return t.includes("px")&&(e=Number(t.replace("px",""))),e}function Ae(r){return r.scrollWidth-r.clientWidth}function ie(r){const e=r.children[0],t=Nt(r);return e.getBoundingClientRect().width+t}function Lt({container:r,onReach:e}){const t=d.useRef("start"),n=d.useRef(0),[,s]=te.useSpring(()=>({x:0}));function o(u){s.start({from:{x:r.current.scrollLeft},to:{x:u},onChange({value:c}){r.current&&(r.current.scrollLeft=c.x)}})}function a(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*ie(r.current),u==="next"){const p=Ae(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")),o(c)}return d.useEffect(()=>{function u(){var O;const E=ie(r.current),I=((O=[...r.current.children].at(0))==null?void 0:O.getBoundingClientRect().width)||0,j=Array(r.current.childElementCount).fill(0).map((D,B)=>({index:B,start:E*B,end:E*(B+1)})),N=r.current.scrollLeft+I,$=j.find(D=>N>=D.start&&N<D.end);n.current=($==null?void 0:$.index)||0}function c(){s.stop()}function p(E){const I=E.target;I.scrollLeft===0?(n.current=0,t.current="start",e&&e("start")):I.scrollLeft>=Ae(I)?(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(()=>{o(n.current*ie(r.current))});return u.observe(r.current),()=>{u.disconnect()}}},[]),{scrollToNext(){a("next")},scrollToPrev(){a("prev")}}}P.useSpringCarousel=Mt,P.useSpringScroll=Lt,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
CHANGED
|
@@ -50,6 +50,18 @@ type BaseProps = {
|
|
|
50
50
|
* Recommended minimum: 1 (active + immediate neighbors).
|
|
51
51
|
*/
|
|
52
52
|
renderWindow?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Optional render function called for items OUTSIDE the `renderWindow`.
|
|
55
|
+
* Receives the original `item`, its track `index`, and `isClonedItem`.
|
|
56
|
+
* Use it to render lightweight content (skeletons, posters) in place of
|
|
57
|
+
* the heavy `renderItem` for off-window slots. Has no effect when
|
|
58
|
+
* `renderWindow` is undefined.
|
|
59
|
+
*/
|
|
60
|
+
renderPlaceholder?: (props: {
|
|
61
|
+
item: Item;
|
|
62
|
+
index: number;
|
|
63
|
+
isClonedItem: boolean;
|
|
64
|
+
}) => ReactNode;
|
|
53
65
|
};
|
|
54
66
|
export type Props = BaseProps & LayoutProps;
|
|
55
67
|
export type SlideActionType = "drag" | "click" | "resize";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Props } from './types';
|
|
2
|
-
export declare function useSpringCarousel({ init, items, withLoop, id, gutter, itemsPerSlide, carouselAxis, startingPosition, enableGestures, slideWhenDragThresholdIsReached, slideType, initialActiveItem, renderWindow, }: Props): {
|
|
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
4
|
useListenToCustomEvent: (eventHandler: import('./types').SpringCarouselEventsEventHandler) => void;
|
|
5
5
|
slideToNextItem: () => void;
|
package/package.json
CHANGED