Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-spring/core

Package Overview
Dependencies
Maintainers
1
Versions
134
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-spring/core - npm Package Compare versions

Comparing version 0.0.1-alpha.0 to 0.0.1-alpha.1

2

index.cjs.js

@@ -1,2 +0,2 @@

"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React),_extends=_interopDefault(require("@babel/runtime/helpers/extends")),shared=require("@react-spring/shared"),useMemoOne=require("use-memo-one"),tslib_1=require("tslib"),globals=require("@react-spring/shared/globals"),animated=require("@react-spring/animated"),_objectWithoutPropertiesLoose=_interopDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));function useChain(e,t,n){void 0===n&&(n=1e3),React.useEffect(function(){if(t){var r=0;e.forEach(function(e,i){if(e.current){var s=e.current.controllers;if(s.length){var a=n*t[i];isNaN(a)?a=r:r=a,s.forEach(function(e){e.queue.forEach(function(e){return e.delay+=a}),e.start()})}}})}else{var i=Promise.resolve();e.forEach(function(e){var t=e.current||{},n=t.controllers,r=t.start;if(n&&n.length){var s=n.map(function(e){var t=e.queue;return e.queue=[],t});i=i.then(function(){return n.forEach(function(e,t){var n;return(n=e.queue).push.apply(n,s[t])}),r()})}else console.warn("useChain ref has no animations:",e)})}})}function withDefault(e,t){return null==e?t:e}function toArray(e){return shared.is.und(e)?[]:Array.isArray(e)?e:[e]}function callProp(e,...t){return shared.is.fun(e)?e(...t):e}function getForwardProps(e){return tslib_1.__rest(e,["children","config","from","to","ref","reset","cancel","reverse","immediate","delay","lazy","items","trail","unique","initial","enter","leave","update","onStart","onRest","onFrame","onDestroyed","timestamp","attach"])}function interpolateTo(e){const t=getForwardProps(e);return e=Object.entries(e).reduce((e,[n,r])=>(n in t||(e[n]=r),e),{}),Object.assign({to:t},e)}function freeze(e){return"undefined"!=typeof process&&"development"===process.env.NODE_ENV?Object.freeze(e):e}const linear=e=>e,emptyObj=Object.freeze({});let nextId=1;class Controller{constructor(e){this.id=nextId++,this.idle=!0,this.runCount=0,this.destroyed=!1,this.props={},this.queue=[],this.timestamps={},this.values={},this.merged={},this.animated={},this.animations={},this.configs=[],this.children=[],this.onEndQueue=[],this.cancelledAt=0,e&&this.update(e).start()}update(e){if(!e||this.destroyed)return this;const t=interpolateTo(e);if(this._ensureAnimated(t.from,!0),this._ensureAnimated(t.to),t.timestamp=globals.now(),shared.is.fun(t.delay)&&shared.is.obj(t.to)){const e=t.from||emptyObj;for(const n in t.to)this.queue.push(Object.assign({},t,{to:{[n]:t.to[n]},from:n in e?{[n]:e[n]}:void 0,delay:Math.max(0,Math.round(t.delay(n)))}))}else t.delay=shared.is.num(t.delay)?Math.max(0,Math.round(t.delay)):0,t.to||(t.to=void 0),t.from||(t.from=void 0),this.queue.push(t);return this}start(e){return this.queue.length?this._flush(e):this._start(e),this}stop(...e){let t=!1;if(shared.is.boo(e[0])&&([t,...e]=e),e.length)for(const t of e){const e=this.configs.findIndex(e=>t===e.key);this._stopAnimation(t),this.configs[e]=this.animations[t]}else this.runCount&&(this.cancelledAt=globals.now(),this.configs.forEach(e=>this._stopAnimation(e.key)),this.configs=Object.values(this.animations),this._stop(t));return this}reset(){return this.stop(),this.destroyed=!1,this.props={},this.queue=[],this.timestamps={},this.values={},this.merged={},this.animated={},this.animations={},this.configs=[],this}destroy(){this.destroyed||(this.stop(),this.destroyed=!0)}onFrame([e,t]){if(t&&t.length){for(const[e,n]of t)this.values[e]=n;this.props.onFrame(Object.assign({},this.values))}e||this._stop(!0)}setProp(e,t){return this.props[e]=t,this.timestamps[e]=globals.now(),this}_ensureAnimated(e,t=!1){if(shared.is.obj(e))for(const n in e){const r=e[n];let i=this.animated[n];i&&t&&this.animations[n].isNew&&(i.setValue?i.setValue(r):i=null),i||((i=createAnimated(r))?(this.animated[n]&&moveChildren(this.animated[n],i),this.animated[n]=i,this._stopAnimation(n,!0)):console.warn("Given value not animatable:",r))}}_onEnd(e){this.runCount?this.onEndQueue.push(e):e(!0)}_start(e){e&&this._onEnd(e),this.idle&&this.runCount&&(this.idle=!1,globals.frameLoop.start(this))}_attach(e){this.children.forEach(t=>{const n=e.filter(e=>{const n=getPayload(t,e);if(n)return n.forEach(e=>e.done&&e.reset(!0)),!0});n.length&&(t._attach(n),t._start())})}_stop(e){this.idle=!0,globals.frameLoop.stop(this);const{onEndQueue:t}=this;t.length&&(this.onEndQueue=[],t.forEach(t=>t(e)))}_flush(e){const t=this.queue.reduce(reduceDelays,[]);this.queue.length=0;let n=Object.keys(t).length;this.runCount+=n;const r=t=>{if(this.runCount--,!--n&&(e&&e(t),!this.runCount&&t)){const{onRest:e}=this.props;e&&e(this.merged)}};t.forEach((e,t)=>{t?setTimeout(()=>{e.timestamp<this.cancelledAt||this._run(e,r)},t):this._run(e,r)})}_run(e,t){shared.is.arr(e.to)||shared.is.fun(e.to)?this._runAsync(e,t):this._diff(e)?this._animate(e)._start(t):this._onEnd(t)}_runAsync(e,t){var{to:n}=e,r=tslib_1.__rest(e,["to"]);if(this._diff(r)&&this._animate(r),!0===r.cancel)return this.props.asyncTo=void 0,t(!1);const{timestamp:i}=r;if(!this._diff({asyncTo:n,timestamp:i}))return t(!1);const s=()=>i<this.cancelledAt||shared.is.fun(n)&&n!==this.props.asyncTo;let a;const o=e=>{if(s())throw this;return(a=new Promise(t=>{this.update(e).start(t)})).then(()=>{if(s())throw this})};let u=Promise.resolve();shared.is.arr(n)?n.forEach(e=>u=u.then(()=>o(e))):shared.is.fun(n)&&(u=u.then(()=>n(o,this.stop.bind(this)).then(()=>a))),u.catch(e=>e!==this&&console.error(e)).then(()=>t(!s()))}_diff(e){var{timestamp:t,delay:n,config:r,immediate:i,reverse:s,attach:a}=e,o=tslib_1.__rest(e,["timestamp","delay","config","immediate","reverse","attach"]);let u=!1;const c=e=>{const n=this.timestamps[e];return!!(shared.is.und(n)||t>=n)&&(this.timestamps[e]=t,!0)},l=(e,t,n)=>{if(shared.is.und(t))return;const r=e[e.length-1];if(shared.is.obj(t)){shared.is.obj(n[r])||(n[r]={});for(const i in t)l(e.concat(i),t[i],n[r])}else if(c(e.join("."))){isEqual(t,n[r])||(u=!0,n[r]=t)}};if(s){const{to:e}=o;o.to=o.from,o.from=shared.is.obj(e)?e:void 0}a&&(o.parent=a(this));const{parent:h}=o;if(h&&!(h instanceof Controller))throw Error('The "parent" prop must be a Controller object or falsy');const d=this.props.parent;null!=h&&h!==d&&(d&&d.children.splice(d.children.indexOf(this),1),h&&h.children.push(this));for(const e in o)l([e],o[e],this.props);return"reset"in o&&(this.props.reset=!1),"cancel"in o&&(this.props.cancel=void 0),u}_isModified(e,t){return this.timestamps[t]===e.timestamp}_animate(e){const{from:t=emptyObj,to:n=emptyObj,parent:r,onStart:i}=this.props;let s=e=>!1;if(e.cancel&&this._isModified(e,"cancel")){if(!0===e.cancel)return this.stop(),this.cancelledAt=e.timestamp,this;const t=toArray(e.cancel);shared.is.arr(t)&&t.length&&(s=e=>t.indexOf(e)>=0,this.stop(...t))}this.merged=freeze(Object.assign({},t,n));let a=!1;const o=[],u=r&&this._isModified(e,"parent");for(const n in this.merged){if(s(n))continue;const i=this.animations[n];if(!i){console.warn(`Failed to animate key: "${n}"\n`+`Did you forget to define "from.${n}" for an async animation?`);continue}let{animated:c,animatedValues:l}=i;const h=this.merged[n],d=computeGoalValue(h),f=c.getValue();if(e.reset||u||!isEqual(d,f)){if(e.reset||u||!isEqual(d,i.isNew?f:i.goalValue)){let{immediate:i}=shared.is.und(e.immediate)?this.props:e;i=!!callProp(i,n);const s=l.some(e=>!e.done),u=shared.is.und(t[n])?d:computeGoalValue(t[n]),f=isAnimatableString(h);if(f){const t=[e.reset?u:c.getValue(),d];let n=l[0];n?(n.setValue(0,!1),n.reset(s)):n=new animated.AnimatedValue(0);try{moveChildren(c,c=n.interpolate({output:t}))}catch(e){console.warn('Failed to interpolate string from "%s" to "%s"',t[0],t[1]),console.error(e);continue}i&&n.setValue(1,!1)}else{if(shared.is.arr(h))if(c instanceof animated.AnimatedValueArray)e.reset&&c.setValue(u,!1),l.forEach(e=>e.reset(s));else{moveChildren(c,c=createAnimated(u))}else if(c instanceof animated.AnimatedValue)e.reset&&c.setValue(u,!1),c.reset(s);else{moveChildren(c,c=new animated.AnimatedValue(u))}i&&c.setValue(d,!1)}const p=callProp(e.config,n)||callProp(this.props.config,n)||emptyObj;i||o.push(n);const m=l.map(e=>e.getValue()),g=r&&getPayload(r,n)||toArray(f?1:d);a=!0,l=toArray(c.getPayload()),this.animations[n]={key:n,idle:!1,goalValue:d,toValues:g,fromValues:m,animated:c,animatedValues:l,immediate:i,duration:p.duration,easing:withDefault(p.easing,linear),decay:p.decay,mass:withDefault(p.mass,1),tension:withDefault(p.tension,170),friction:withDefault(p.friction,26),initialVelocity:withDefault(p.velocity,0),clamp:withDefault(p.clamp,!1),precision:withDefault(p.precision,.005),config:p}}}else i.idle||(a=!0,this._stopAnimation(n))}if(a){o.length&&(this._attach(o),i&&o.forEach(e=>{i(this.animations[e])}));const e=Object.keys(this.animations);this.configs.length=e.length,e.forEach((e,t)=>{const n=this.animations[e];this.configs[t]=n,this.values[e]=n.animated.getValue(),this.animated[e]=n.animated})}return this}_stopAnimation(e,t){const n=this.animated[e];if(!n)return console.warn(`Cannot stop an animation for a key that isn't animated: "${e}"`);this.timestamps["to."+e]=globals.now();const r=this.animations[e]||emptyObj;if(r.idle&&n===r.animated)return;shared.is.und(t)&&(t=!!r.isNew);const i=toArray(n.getPayload());i.forEach(e=>e.done=!0);const s=n.getValue();this.props.to&&(this.props.to[e]=s),this.animations[e]={key:e,idle:!0,isNew:t,goalValue:s,animated:n,animatedValues:i}}}function createAnimated(e){return shared.is.arr(e)?new animated.AnimatedValueArray(e.map(e=>{const t=createAnimated(e),n=t.getPayload();return t instanceof animated.AnimatedInterpolation?n[0]:n})):isAnimatableString(e)?new animated.AnimatedValue(0).interpolate({output:[e,e]}):new animated.AnimatedValue(e)}function moveChildren(e,t){e.getChildren().slice().forEach(n=>{e.removeChild(n),t.addChild(n);const r=n.getPayload();if(shared.is.arr(r)){const i=r.indexOf(e);if(i>=0){const e=[...r];e[i]=t,n.payload=e}}else if(shared.is.obj(r)){const i=Object.entries(r).find(t=>t[1]===e);i&&(n.payload=Object.assign({},r,{[i[0]]:t}))}})}function reduceDelays(e,t){const n=e[t.delay];return n?(t.to=merge(n.to,t.to),t.from=merge(n.from,t.from),Object.assign(n,t)):e[t.delay]=t,e}function merge(e,t){return shared.is.obj(e)&&shared.is.obj(t)?Object.assign({},e,t):t||e}function isAnimatableString(e){return!!shared.is.str(e)&&(e.startsWith("#")||/\d/.test(e)||!!globals.colorNames[e])}function computeGoalValue(e){return shared.is.arr(e)?e.map(computeGoalValue):isAnimatableString(e)?globals.createStringInterpolator({range:[0,1],output:[e,e]})(1):e}function isEqual(e,t){if(shared.is.arr(e)){if(!shared.is.arr(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}return e===t}function getPayload(e,t){const n=e.animations[t];return n&&n.animatedValues}var useSprings=function(e,t,n){var r=e!==shared.usePrev(e),i=shared.is.fun(t),s=React.useRef({springs:[],ref:null}).current,a=i?[]:t,o=useMemoOne.useMemoOne(function(){return shared.fillArray(e,function(e){var n=new Controller,r=a[e]||(a[e]=shared.callProp(t,e,n));return n.update(r)})},[e]),u=React.useMemo(function(){return{start:function(){return Promise.all(s.springs.map(function(e){return new Promise(function(t){return e.start(t)})}))},update:function(e){var t=shared.is.fun(e),n=shared.is.arr(e);s.springs.forEach(function(r,i){r.update(t?shared.callProp(e,i,r):n?e[i]:e),s.ref||r.start()})},stop:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return s.springs.forEach(function(e){return e.stop.apply(e,t)})}}},[]),c=u.start,l=u.update,h=u.stop,d=a[0]?a[0].ref:i?s.ref:null;React.useImperativeHandle(d,function(){return{start:c,stop:h,get controllers(){return s.springs}}}),React.useEffect(function(){i&&!r||a.forEach(function(e,t){o[t].setProp("config",e.config),o[t].setProp("immediate",e.immediate)}),r?(s.springs.forEach(function(e){return e.destroy()}),s.springs=o,s.ref=d,d||o.forEach(function(e){return e.start()})):i||l(a)},n),shared.useOnce(function(){return function(){s.springs.forEach(function(e){return e.destroy()})}});var f=o.map(function(e){return _extends({},e.animated)});return i?[f,l,h]:f},useSpring=function(e,t){var n=shared.is.fun(e),r=useSprings(1,n?e:[e],t),i=r[0],s=r[1],a=r[2];return n?[i[0],s,a]:i},useTrail=function(e,t){var n=e!==shared.usePrev(e),r=shared.is.fun(t),i=r?null:t,s=React.useRef([]),a=s.current;n&&(a.length=e);var o=useSprings(e,function(e,n){return r&&!i&&(i=shared.callProp(t,n)||{}),a[e]=n,_extends({},i,e>0&&{attach:function(){return a[e-1]},onStart:withArgument(i.onStart,e),onFrame:withArgument(i.onFrame,e),onRest:withArgument(i.onRest,e)},{config:shared.callProp(i.config,e)})}),u=o[0],c=o[1],l=o[2],h=useMemoOne.useCallbackOne(function(e){return c(function(t,n){var r=shared.callProp(e,t,n)||{},i=s.current[r.reverse?t+1:t-1];return _extends({},r,!!i&&{attach:function(){return i}},{config:shared.callProp(r.config,t)})})},[]);return React.useEffect(function(){r||n||h(t)}),r?[u,h,l]:u};function withArgument(e,t){return shared.is.fun(e)?function(){for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];return e.apply(void 0,r.concat([t]))}:e}var guid=0,INITIAL="initial",ENTER="enter",UPDATE="update",LEAVE="leave",makeKeys=function(e,t){return("function"==typeof t?e.map(t):shared.toArray(t)).map(String)},makeConfig=function(e){var t=e.items,n=e.keys,r=_objectWithoutPropertiesLoose(e,["items","keys"]);return t=shared.toArray(shared.is.und(t)?null:t),_extends({items:t,keys:makeKeys(t,n)},r)};function useTransition(e,t,n){var r=n=makeConfig(_extends({},n,{items:e,keys:t||function(e){return e}})),i=r.lazy,s=void 0!==i&&i,a=(r.unique,r.from,r.enter,r.leave,r.update,r.onDestroyed),o=(r.keys,r.items,r.onFrame),u=r.onRest,c=r.onStart,l=r.ref,h=_objectWithoutPropertiesLoose(r,["lazy","unique","from","enter","leave","update","onDestroyed","keys","items","onFrame","onRest","onStart","ref"]),d=shared.useForceUpdate(),f=React.useRef(!1),p=React.useRef({mounted:!1,first:!0,deleted:[],current:{},transitions:[],prevProps:{},paused:!!n.ref,instances:!f.current&&new Map,forceUpdate:d});return React.useImperativeHandle(n.ref,function(){return{start:function(){return Promise.all(Array.from(p.current.instances).map(function(e){var t=e[1];return new Promise(function(e){return t.start(e)})}))},stop:function(e){return Array.from(p.current.instances).forEach(function(t){return t[1].stop(e)})},get controllers(){return Array.from(p.current.instances).map(function(e){return e[1]})}}}),p.current=diffItems(p.current,n),p.current.changed&&p.current.transitions.forEach(function(e){var t=e.phase,n=e.key,r=e.item,i=e.props;p.current.instances.has(n)||p.current.instances.set(n,new Controller);var d=!1,f=p.current.instances.get(n),m=_extends({},h,i,{ref:l,onRest:function(i){p.current.mounted&&(e.destroyed&&(l||s||cleanUp(p,n),a&&a(r)),!Array.from(p.current.instances).some(function(e){return!e[1].idle})&&(l||s)&&p.current.deleted.length>0&&cleanUp(p),u&&u(r,t,i))},onFrame:o&&function(e){return o(r,t,e)},onStart:c&&function(e){return d||(c(r,t,e),d=!0)}});f.update(m),p.current.paused||f.start()}),React.useOnce(function(){return p.current.mounted=f.current=!0,function(){p.current.mounted=f.current=!1,Array.from(p.current.instances).map(function(e){return e[1].destroy()}),p.current.instances.clear()}}),p.current.transitions.map(function(e){var t=e.item,n=e.phase,r=e.key;return{item:t,key:r,phase:n,props:_extends({},p.current.instances.get(r).animated)}})}function cleanUp(e,t){var n=e.current,r=function(){if(s){if(a>=i.length)return"break";o=i[a++]}else{if((a=i.next()).done)return"break";o=a.value}var e=o.key,r=function(t){return t.key!==e};(shared.is.und(t)||t===e)&&(n.instances.delete(e),n.transitions=n.transitions.filter(r),n.deleted=n.deleted.filter(r))},i=n.deleted,s=Array.isArray(i),a=0;for(i=s?i:i[Symbol.iterator]();;){var o;if("break"===r())break}n.forceUpdate()}function diffItems(e,t){var n=e.first,r=e.current,i=e.deleted,s=e.prevProps,a=_objectWithoutPropertiesLoose(e,["first","current","deleted","prevProps"]),o=t.items,u=t.keys,c=t.initial,l=t.from,h=t.enter,d=t.leave,f=t.update,p=t.trail,m=void 0===p?0:p,g=t.unique,y=t.config,v=t.order,b=void 0===v?[ENTER,LEAVE,UPDATE]:v,_=makeConfig(s),A=_.keys,E=_.items;t.reset&&(r={},a.transitions=[]);for(var P=Object.keys(r),V=new Set(P),w=new Set(u),x=u.filter(function(e){return!V.has(e)}),j=f?u.filter(function(e){return V.has(e)}):[],O=a.transitions.filter(function(e){return!e.destroyed&&!w.has(e.originalKey)}).map(function(e){return e.originalKey}),S=-m,k=function(){var e=b.shift();e===ENTER?(n&&!shared.is.und(c)&&(e=INITIAL,l=c),x.forEach(function(t){g&&i.find(function(e){return e.originalKey===t})&&(i=i.filter(function(e){return e.originalKey!==t}));var n=u.indexOf(t),s=o[n],a=shared.callProp(h,s,n);r[t]={phase:e,originalKey:t,key:g?String(t):guid++,item:s,props:_extends({delay:S+=m,config:shared.callProp(y,s,e),from:shared.callProp(l,s),to:a},shared.is.obj(a)&&shared.interpolateTo(a))}})):e===LEAVE?O.forEach(function(t){var n=A.indexOf(t),s=E[n],a=shared.callProp(d,s,n);i.push(_extends({},r[t],{phase:e,destroyed:!0,left:A[n-1],right:A[n+1],props:_extends({delay:S+=m,config:shared.callProp(y,s,e),to:a},shared.is.obj(a)&&shared.interpolateTo(a))})),delete r[t]}):e===UPDATE&&j.forEach(function(t){var n=u.indexOf(t),i=o[n],s=shared.callProp(f,i,n);r[t]=_extends({},r[t],{phase:e,props:_extends({delay:S+=m,config:shared.callProp(y,i,e),to:s},shared.is.obj(s)&&shared.interpolateTo(s))})})};b.length;)k();var T=u.map(function(e){return r[e]});return T=shared.reconcileDeleted(i,T),_extends({},a,{first:n&&!x.length,changed:!!(x.length||O.length||j.length),transitions:T,current:r,deleted:i,prevProps:t})}function Spring(e){var t=e.children,n=_objectWithoutPropertiesLoose(e,["children"]);return t(useSpring(n))}function Trail(e){var t=e.items,n=e.children,r=_objectWithoutPropertiesLoose(e,["items","children"]),i=useTrail(t.length,r);return t.map(function(e,t){var r=n(e,t);return shared.is.fun(r)?r(i[t]):r})}function Transition(e){var t=e.items,n=e.keys,r=void 0===n?null:n,i=e.children;return useTransition(t,r,_objectWithoutPropertiesLoose(e,["items","keys","children"])).map(function(e,t){var n=e.item,r=e.key,s=e.props,a=e.phase,o=i(n,a,t),u=shared.is.fun(o)?o(s):o;return u&&React__default.createElement(u.type,_extends({key:r},u.props))})}class FrameLoop{constructor({update:e,onFrame:t,requestFrame:n}={}){this.controllers=[],this.isActive=!1,this.requestFrame=n||globals.requestAnimationFrame,this.onFrame=t&&t.bind(this)||(e=>{e.forEach((e,t)=>{this.controllers[t].onFrame(e)})}),this.update=e&&e.bind(this)||(()=>{if(!this.isActive)return!1;const e=[];for(const t of this.controllers){let n=!1;const r=t.props.onFrame?[]:void 0;for(const e of t.configs)this.advance(e)&&(n=!0,r&&r.push([e.key,e.animated.getValue()]));e.push([n,r])}return this.onFrame(e),this.controllers.length?(this.requestFrame(this.update),!0):this.isActive=!1})}start(e){this.controllers.includes(e)||this.controllers.push(e),this.isActive||(this.isActive=!0,this.requestFrame(this.update))}stop(e){const t=this.controllers.indexOf(e);t>=0&&this.controllers.splice(t,1)}advance(e){const t=globals.now();let n=!1,r=!1;for(let i=0;i<e.animatedValues.length;i++){const s=e.animatedValues[i];if(s.done)continue;let a=e.toValues[i];const o=a instanceof animated.Animated;if(o&&(a=a.getValue()),e.immediate){s.setValue(a),s.done=!0;continue}const u=e.fromValues[i];if("string"==typeof u||"string"==typeof a){s.setValue(a),s.done=!0;continue}let c=s.lastPosition,l=Array.isArray(e.initialVelocity)?e.initialVelocity[i]:e.initialVelocity;if(void 0!==e.duration)c=u+e.easing((t-s.startTime)/e.duration)*(a-u),r=t>=s.startTime+e.duration;else if(e.decay){const n=!0===e.decay?.998:e.decay;c=u+l/(1-n)*(1-Math.exp(-(1-n)*(t-s.startTime))),(r=Math.abs(s.lastPosition-c)<.1)&&(a=c)}else{let n=void 0!==s.lastTime?s.lastTime:t;void 0!==s.lastVelocity&&(l=s.lastVelocity),t>n+64&&(n=t);const i=Math.floor(t-n);for(let t=0;t<i;++t){c+=1*(l+=1*((-e.tension*(c-a)+-e.friction*l)/e.mass)/1e3)/1e3}s.lastTime=t,s.lastVelocity=l;const o=!(!e.clamp||0===e.tension)&&(u<a?c>a:c<a),h=Math.abs(l)<=e.precision,d=0===e.tension||Math.abs(a-c)<=e.precision;r=o||h&&d}o&&!e.toValues[i].done&&(r=!1),r?(s.value!==a&&(c=a),s.done=!0):n=!0,s.setValue(c),s.lastPosition=c}return n}}const stringShapeRegex=/[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,createStringInterpolator=e=>{const t=e.output,n=t[0].match(stringShapeRegex).map(()=>[]);t.forEach(e=>{e.match(stringShapeRegex).forEach((e,t)=>n[t].push(+e))});const r=t[0].match(stringShapeRegex).map((t,r)=>shared.createInterpolator(Object.assign({},e,{output:n[r]})));return e=>{let n=0;return t[0].replace(stringShapeRegex,()=>r[n++](e))}};shared.Globals.assign({frameLoop:new FrameLoop,createStringInterpolator:createStringInterpolator,applyAnimatedValues:()=>!1,createAnimatedStyle:e=>new animated.AnimatedStyle(e),createAnimatedInterpolation:(e,...t)=>new animated.AnimatedInterpolation(e,t)});const update=()=>shared.Globals.frameLoop.update(),config={default:{tension:170,friction:26},gentle:{tension:120,friction:14},wobbly:{tension:180,friction:12},stiff:{tension:210,friction:20},slow:{tension:280,friction:60},molasses:{tension:280,friction:120}};Object.defineProperty(exports,"Globals",{enumerable:!0,get:function(){return shared.Globals}}),Object.defineProperty(exports,"createInterpolator",{enumerable:!0,get:function(){return shared.createInterpolator}}),Object.defineProperty(exports,"interpolate",{enumerable:!0,get:function(){return animated.interpolate}}),exports.Controller=Controller,exports.FrameLoop=FrameLoop,exports.Spring=Spring,exports.Trail=Trail,exports.Transition=Transition,exports.config=config,exports.update=update,exports.useChain=useChain,exports.useSpring=useSpring,exports.useSprings=useSprings,exports.useTrail=useTrail,exports.useTransition=useTransition;
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React),_extends=_interopDefault(require("@babel/runtime/helpers/extends")),shared=require("@react-spring/shared"),tslib_1=require("tslib"),useMemoOne=require("use-memo-one"),globals=require("@react-spring/shared/globals"),animated=require("@react-spring/animated"),_objectWithoutPropertiesLoose=_interopDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));function useChain(e,t,n){void 0===n&&(n=1e3),React.useEffect(function(){if(t){var r=0;e.forEach(function(e,i){if(e.current){var s=e.current.controllers;if(s.length){var a=n*t[i];isNaN(a)?a=r:r=a,s.forEach(function(e){e.queue.forEach(function(e){return e.delay+=a}),e.start()})}}})}else{var i=Promise.resolve();e.forEach(function(e){var t=e.current||{},n=t.controllers,r=t.start;if(n&&n.length){var s=n.map(function(e){var t=e.queue;return e.queue=[],t});i=i.then(function(){return n.forEach(function(e,t){var n;return(n=e.queue).push.apply(n,s[t])}),r()})}else console.warn("useChain ref has no animations:",e)})}})}function fillArray(e,t){const n=[];for(let r=0;r<e;r++)n.push(t(r));return n}function withDefault(e,t){return null==e?t:e}function toArray(e){return shared.is.und(e)?[]:Array.isArray(e)?e:[e]}function callProp(e,...t){return shared.is.fun(e)?e(...t):e}function getForwardProps(e){return tslib_1.__rest(e,["children","config","from","to","ref","reset","cancel","reverse","immediate","delay","lazy","items","trail","unique","initial","enter","leave","update","onStart","onRest","onFrame","onDestroyed","timestamp","attach"])}function interpolateTo(e){const t=getForwardProps(e);return e=Object.entries(e).reduce((e,[n,r])=>(n in t||(e[n]=r),e),{}),Object.assign({to:t},e)}function reconcileDeleted(e,t){e=[...e],t=[...t];let n=0,r=0,i=e.length;for(let s=0;s<e.length;s++){if(s===i){if(r+n===i){for(let n=s;n<e.length;n++){const r=e[n],i=tslib_1.__rest(r,["left","right"]);t.push(i)}break}r=i,i=e.length,n=0}let a=-1;const o=e[s],{left:u,right:c}=o,l=tslib_1.__rest(o,["left","right"]);for(let e=t.length;--e>=0;){const{originalKey:n}=t[e];if(n===c){a=e;break}if(n===u){a=e+1;break}}a<0?(n++,e.push(e[s])):t.splice(a,0,l)}return t}function freeze(e){return"undefined"!=typeof process&&"development"===process.env.NODE_ENV?Object.freeze(e):e}const linear=e=>e,emptyObj=Object.freeze({});let nextId=1;class Controller{constructor(e){this.id=nextId++,this.idle=!0,this.runCount=0,this.destroyed=!1,this.props={},this.queue=[],this.timestamps={},this.values={},this.merged={},this.animated={},this.animations={},this.configs=[],this.children=[],this.onEndQueue=[],this.cancelledAt=0,e&&this.update(e).start()}update(e){if(!e||this.destroyed)return this;const t=interpolateTo(e);if(this._ensureAnimated(t.from,!0),this._ensureAnimated(t.to),t.timestamp=globals.now(),shared.is.fun(t.delay)&&shared.is.obj(t.to)){const e=t.from||emptyObj;for(const n in t.to)this.queue.push(Object.assign({},t,{to:{[n]:t.to[n]},from:n in e?{[n]:e[n]}:void 0,delay:Math.max(0,Math.round(t.delay(n)))}))}else t.delay=shared.is.num(t.delay)?Math.max(0,Math.round(t.delay)):0,t.to||(t.to=void 0),t.from||(t.from=void 0),this.queue.push(t);return this}start(e){return this.queue.length?this._flush(e):this._start(e),this}stop(...e){let t=!1;if(shared.is.boo(e[0])&&([t,...e]=e),e.length)for(const t of e){const e=this.configs.findIndex(e=>t===e.key);this._stopAnimation(t),this.configs[e]=this.animations[t]}else this.runCount&&(this.cancelledAt=globals.now(),this.configs.forEach(e=>this._stopAnimation(e.key)),this.configs=Object.values(this.animations),this._stop(t));return this}reset(){return this.stop(),this.destroyed=!1,this.props={},this.queue=[],this.timestamps={},this.values={},this.merged={},this.animated={},this.animations={},this.configs=[],this}destroy(){this.destroyed||(this.stop(),this.destroyed=!0)}onFrame([e,t,n]){if(e===this.id){if(n&&n.length){for(const[e,t]of n)this.values[e]=t;this.props.onFrame(Object.assign({},this.values))}t||this._stop(!0)}}setProp(e,t){return this.props[e]=t,this.timestamps[e]=globals.now(),this}_ensureAnimated(e,t=!1){if(shared.is.obj(e))for(const n in e){const r=e[n];let i=this.animated[n];i&&t&&this.animations[n].isNew&&(i.setValue?i.setValue(r):i=null),i||((i=createAnimated(r))?(this.animated[n]&&moveChildren(this.animated[n],i),this.animated[n]=i,this._stopAnimation(n,!0)):console.warn("Given value not animatable:",r))}}_onEnd(e){this.runCount?this.onEndQueue.push(e):e(!0)}_start(e){e&&this._onEnd(e),this.idle&&this.runCount&&(this.idle=!1,globals.frameLoop.start(this))}_attach(e,t={}){this.children.forEach(n=>{if(t[this.id])return;t[this.id]=!0;const r=e.filter(e=>{const t=getPayload(n,e);if(t)return t.forEach(e=>e.done&&e.reset(!0)),!0});r.length&&(n._attach(r,t),n._start())})}_stop(e){this.idle=!0,globals.frameLoop.stop(this);const{onEndQueue:t}=this;t.length&&(this.onEndQueue=[],t.forEach(t=>t(e)))}_flush(e){const t=this.queue.reduce(reduceDelays,[]);this.queue.length=0;let n=Object.keys(t).length;this.runCount+=n;const r=t=>{if(this.runCount--,!--n&&(e&&e(t),!this.runCount&&t)){const{onRest:e}=this.props;e&&e(this.merged)}};t.forEach((e,t)=>{t?setTimeout(()=>{e.timestamp<this.cancelledAt||this._run(e,r)},t):this._run(e,r)})}_run(e,t){shared.is.arr(e.to)||shared.is.fun(e.to)?this._runAsync(e,t):this._diff(e)?this._animate(e)._start(t):this._onEnd(t)}_runAsync(e,t){var{to:n}=e,r=tslib_1.__rest(e,["to"]);if(this._diff(r)&&this._animate(r),!0===r.cancel)return this.props.asyncTo=void 0,t(!1);const{timestamp:i}=r;if(!this._diff({asyncTo:n,timestamp:i}))return t(!1);const s=()=>i<this.cancelledAt||shared.is.fun(n)&&n!==this.props.asyncTo;let a;const o=e=>{if(s())throw this;return(a=new Promise(t=>{this.update(e).start(t)})).then(()=>{if(s())throw this})};let u=Promise.resolve();shared.is.arr(n)?n.forEach(e=>u=u.then(()=>o(e))):shared.is.fun(n)&&(u=u.then(()=>n(o,this.stop.bind(this)).then(()=>a))),u.catch(e=>e!==this&&console.error(e)).then(()=>t(!s()))}_diff(e){var{timestamp:t,delay:n,config:r,immediate:i,reverse:s,attach:a}=e,o=tslib_1.__rest(e,["timestamp","delay","config","immediate","reverse","attach"]);let u=!1;const c=(e,n,r)=>{if(shared.is.und(n))return;const i=e[e.length-1];if(shared.is.obj(n)){shared.is.obj(r[i])||(r[i]={});for(const t in n)c(e.concat(t),n[t],r[i])}else{const s=e.join("."),a=this.timestamps[s];if(shared.is.und(a)||t>=a){this.timestamps[s]=t,isEqual(n,r[i])||(u=!0,r[i]=n)}}};if(s){const{to:e}=o;o.to=o.from,o.from=shared.is.obj(e)?e:void 0}o.parent=(a?a(this):o.parent)||null;const l=this.props.parent||null;o.parent!==l&&(l&&l.children.splice(l.children.indexOf(this),1),o.parent&&o.parent.children.push(this));for(const e in o)c([e],o[e],this.props);return"reset"in o&&(this.props.reset=!1),"cancel"in o&&(this.props.cancel=void 0),u}_isModified(e,t){return this.timestamps[t]===e.timestamp}_animate(e){const{from:t=emptyObj,to:n=emptyObj,parent:r,onStart:i}=this.props;let s=e=>!1;if(e.cancel&&this._isModified(e,"cancel")){if(!0===e.cancel)return this.stop(),this.cancelledAt=e.timestamp,this;const t=toArray(e.cancel);shared.is.arr(t)&&t.length&&(s=e=>t.indexOf(e)>=0,this.stop(...t))}this.merged=freeze(Object.assign({},t,n));let a=!1;const o=[],u=r&&this._isModified(e,"parent");for(const n in this.merged){if(s(n))continue;const i=this.animations[n];if(!i){console.warn(`Failed to animate key: "${n}"\n`+`Did you forget to define "from.${n}" for an async animation?`);continue}let{animated:c,animatedValues:l}=i;const h=this.merged[n],d=computeGoalValue(h),f=c.getValue();if(e.reset||u||!isEqual(d,f)){if(e.reset||u||!isEqual(d,i.isNew?f:i.goalValue)){let{immediate:i}=shared.is.und(e.immediate)?this.props:e;i=!!callProp(i,n);const s=l.some(e=>!e.done),u=shared.is.und(t[n])?d:computeGoalValue(t[n]),f=isAnimatableString(h);if(f){const t=[e.reset?u:c.getValue(),d];let n=l[0];n?(n.setValue(0,!1),n.reset(s)):n=new animated.AnimatedValue(0);try{moveChildren(c,c=n.interpolate({output:t}))}catch(e){console.warn('Failed to interpolate string from "%s" to "%s"',t[0],t[1]),console.error(e);continue}i&&n.setValue(1,!1)}else{if(shared.is.arr(h))if(c instanceof animated.AnimatedValueArray)e.reset&&c.setValue(u,!1),l.forEach(e=>e.reset(s));else{moveChildren(c,c=createAnimated(u))}else if(c instanceof animated.AnimatedValue)e.reset&&c.setValue(u,!1),c.reset(s);else{moveChildren(c,c=new animated.AnimatedValue(u))}i&&c.setValue(d,!1)}const p=callProp(e.config,n)||callProp(this.props.config,n)||emptyObj;i||o.push(n);const m=l.map(e=>e.getValue()),g=r&&getPayload(r,n)||toArray(f?1:d);a=!0,l=toArray(c.getPayload()),this.animations[n]={key:n,idle:!1,goalValue:d,toValues:g,fromValues:m,animated:c,animatedValues:l,immediate:i,duration:p.duration,easing:withDefault(p.easing,linear),decay:p.decay,mass:withDefault(p.mass,1),tension:withDefault(p.tension,170),friction:withDefault(p.friction,26),initialVelocity:withDefault(p.velocity,0),clamp:withDefault(p.clamp,!1),precision:withDefault(p.precision,.005),config:p}}}else i.idle||(a=!0,this._stopAnimation(n))}if(a){o.length&&(this._attach(o),i&&o.forEach(e=>{i(this.animations[e])}));const e=Object.keys(this.animations);this.configs.length=e.length,e.forEach((e,t)=>{const n=this.animations[e];this.configs[t]=n,this.values[e]=n.animated.getValue(),this.animated[e]=n.animated})}return this}_stopAnimation(e,t){const n=this.animated[e];if(!n)return console.warn(`Cannot stop an animation for a key that isn't animated: "${e}"`);this.timestamps["to."+e]=globals.now();const r=this.animations[e]||emptyObj;if(r.idle&&n===r.animated)return;shared.is.und(t)&&(t=!!r.isNew);const i=toArray(n.getPayload());i.forEach(e=>e.done=!0);const s=n.getValue();this.props.to&&(this.props.to[e]=s),this.animations[e]={key:e,idle:!0,isNew:t,goalValue:s,animated:n,animatedValues:i}}}function createAnimated(e){return shared.is.arr(e)?new animated.AnimatedValueArray(e.map(e=>{const t=createAnimated(e),n=t.getPayload();return t instanceof animated.AnimatedInterpolation?n[0]:n})):isAnimatableString(e)?new animated.AnimatedValue(0).interpolate({output:[e,e]}):new animated.AnimatedValue(e)}function moveChildren(e,t){e.getChildren().slice().forEach(n=>{e.removeChild(n),t.addChild(n);const r=n.getPayload();if(shared.is.arr(r)){const i=r.indexOf(e);if(i>=0){const e=[...r];e[i]=t,n.payload=e}}else if(shared.is.obj(r)){const i=Object.entries(r).find(t=>t[1]===e);i&&(n.payload=Object.assign({},r,{[i[0]]:t}))}})}function reduceDelays(e,t){const n=e[t.delay];return n?(t.to=merge(n.to,t.to),t.from=merge(n.from,t.from),Object.assign(n,t)):e[t.delay]=t,e}function merge(e,t){return shared.is.obj(e)&&shared.is.obj(t)?Object.assign({},e,t):t||e}function isAnimatableString(e){return!!shared.is.str(e)&&(e.startsWith("#")||/\d/.test(e)||!!globals.colorNames[e])}function computeGoalValue(e){return shared.is.arr(e)?e.map(computeGoalValue):isAnimatableString(e)?globals.createStringInterpolator({range:[0,1],output:[e,e]})(1):e}function isEqual(e,t){if(shared.is.arr(e)){if(!shared.is.arr(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}return e===t}function getPayload(e,t){const n=e.animations[t];return n&&n.animatedValues}var useSprings=function(e,t,n){var r=e!==shared.usePrev(e),i=shared.is.fun(t),s=React.useRef({springs:[],ref:null}).current,a=i?[]:t,o=useMemoOne.useMemoOne(function(){return fillArray(e,function(e){var n=new Controller,r=a[e]||(a[e]=callProp(t,e,n));return n.update(r)})},[e]),u=React.useMemo(function(){return{start:function(){return Promise.all(s.springs.map(function(e){return new Promise(function(t){return e.start(t)})}))},update:function(e){var t=shared.is.fun(e),n=shared.is.arr(e);s.springs.forEach(function(r,i){r.update(t?callProp(e,i,r):n?e[i]:e),s.ref||r.start()})},stop:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return s.springs.forEach(function(e){return e.stop.apply(e,t)})}}},[]),c=u.start,l=u.update,h=u.stop,d=a[0]?a[0].ref:i?s.ref:null;React.useImperativeHandle(d,function(){return{start:c,stop:h,get controllers(){return s.springs}}}),React.useEffect(function(){i&&!r||a.forEach(function(e,t){o[t].setProp("config",e.config),o[t].setProp("immediate",e.immediate)}),r?(s.springs.forEach(function(e){return e.destroy()}),s.springs=o,s.ref=d,d||o.forEach(function(e){return e.start()})):i||l(a)},n),shared.useOnce(function(){return function(){s.springs.forEach(function(e){return e.destroy()})}});var f=o.map(function(e){return _extends({},e.animated)});return i?[f,l,h]:f},useSpring=function(e,t){var n=shared.is.fun(e),r=useSprings(1,n?e:[e],t),i=r[0],s=r[1],a=r[2];return n?[i[0],s,a]:i},useTrail=function(e,t){var n=e!==shared.usePrev(e),r=shared.is.fun(t),i=r?null:t,s=React.useRef([]),a=s.current;n&&(a.length=e);var o=useSprings(e,function(e,n){return r&&!i&&(i=callProp(t,n)||{}),a[e]=n,_extends({},i,e>0&&{attach:function(){return a[e-1]},onStart:withArgument(i.onStart,e),onFrame:withArgument(i.onFrame,e),onRest:withArgument(i.onRest,e)},{config:callProp(i.config,e)})}),u=o[0],c=o[1],l=o[2],h=useMemoOne.useCallbackOne(function(e){return c(function(t,n){var r=callProp(e,t,n)||{},i=s.current[r.reverse?t+1:t-1];return _extends({},r,{attach:function(){return i},config:callProp(r.config,t)})})},[]);return React.useEffect(function(){r||n||h(t)}),r?[u,h,l]:u};function withArgument(e,t){return shared.is.fun(e)?function(){for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];return e.apply(void 0,r.concat([t]))}:e}var guid=0,INITIAL="initial",ENTER="enter",UPDATE="update",LEAVE="leave",makeKeys=function(e,t){return("function"==typeof t?e.map(t):toArray(t)).map(String)},makeConfig=function(e){var t=e.items,n=e.keys,r=_objectWithoutPropertiesLoose(e,["items","keys"]);return t=toArray(shared.is.und(t)?null:t),_extends({items:t,keys:makeKeys(t,n)},r)};function useTransition(e,t,n){var r=n=makeConfig(_extends({},n,{items:e,keys:t||function(e){return e}})),i=r.lazy,s=void 0!==i&&i,a=(r.unique,r.from,r.enter,r.leave,r.update,r.onDestroyed),o=(r.keys,r.items,r.onFrame),u=r.onRest,c=r.onStart,l=r.ref,h=_objectWithoutPropertiesLoose(r,["lazy","unique","from","enter","leave","update","onDestroyed","keys","items","onFrame","onRest","onStart","ref"]),d=shared.useForceUpdate(),f=React.useRef(!1),p=React.useRef({mounted:!1,first:!0,deleted:[],current:{},transitions:[],prevProps:{},paused:!!n.ref,instances:!f.current&&new Map,forceUpdate:d});return React.useImperativeHandle(n.ref,function(){return{start:function(){return Promise.all(Array.from(p.current.instances).map(function(e){var t=e[1];return new Promise(function(e){return t.start(e)})}))},stop:function(e){return Array.from(p.current.instances).forEach(function(t){return t[1].stop(e)})},get controllers(){return Array.from(p.current.instances).map(function(e){return e[1]})}}}),p.current=diffItems(p.current,n),p.current.changed&&p.current.transitions.forEach(function(e){var t=e.phase,n=e.key,r=e.item,i=e.props;p.current.instances.has(n)||p.current.instances.set(n,new Controller);var d=!1,f=p.current.instances.get(n),m=_extends({},h,i,{ref:l,onRest:function(i){p.current.mounted&&(e.destroyed&&(l||s||cleanUp(p,n),a&&a(r)),!Array.from(p.current.instances).some(function(e){return!e[1].idle})&&(l||s)&&p.current.deleted.length>0&&cleanUp(p),u&&u(r,t,i))},onFrame:o&&function(e){return o(r,t,e)},onStart:c&&function(e){return d||(c(r,t,e),d=!0)}});f.update(m),p.current.paused||f.start()}),shared.useOnce(function(){return p.current.mounted=f.current=!0,function(){p.current.mounted=f.current=!1,Array.from(p.current.instances).map(function(e){return e[1].destroy()}),p.current.instances.clear()}}),p.current.transitions.map(function(e){var t=e.item,n=e.phase,r=e.key;return{item:t,key:r,phase:n,props:_extends({},p.current.instances.get(r).animated)}})}function cleanUp(e,t){var n=e.current,r=function(){if(s){if(a>=i.length)return"break";o=i[a++]}else{if((a=i.next()).done)return"break";o=a.value}var e=o.key,r=function(t){return t.key!==e};(shared.is.und(t)||t===e)&&(n.instances.delete(e),n.transitions=n.transitions.filter(r),n.deleted=n.deleted.filter(r))},i=n.deleted,s=Array.isArray(i),a=0;for(i=s?i:i[Symbol.iterator]();;){var o;if("break"===r())break}n.forceUpdate()}function diffItems(e,t){var n=e.first,r=e.current,i=e.deleted,s=e.prevProps,a=_objectWithoutPropertiesLoose(e,["first","current","deleted","prevProps"]),o=t.items,u=t.keys,c=t.initial,l=t.from,h=t.enter,d=t.leave,f=t.update,p=t.trail,m=void 0===p?0:p,g=t.unique,y=t.config,v=t.order,b=void 0===v?[ENTER,LEAVE,UPDATE]:v,_=makeConfig(s),A=_.keys,E=_.items;t.reset&&(r={},a.transitions=[]);for(var P=Object.keys(r),V=new Set(P),w=new Set(u),x=u.filter(function(e){return!V.has(e)}),j=f?u.filter(function(e){return V.has(e)}):[],k=a.transitions.filter(function(e){return!e.destroyed&&!w.has(e.originalKey)}).map(function(e){return e.originalKey}),O=-m,S=function(){var e=b.shift();e===ENTER?(n&&!shared.is.und(c)&&(e=INITIAL,l=c),x.forEach(function(t){g&&i.find(function(e){return e.originalKey===t})&&(i=i.filter(function(e){return e.originalKey!==t}));var n=u.indexOf(t),s=o[n],a=callProp(h,s,n);r[t]={phase:e,originalKey:t,key:g?String(t):guid++,item:s,props:_extends({delay:O+=m,config:callProp(y,s,e),from:callProp(l,s),to:a},shared.is.obj(a)&&interpolateTo(a))}})):e===LEAVE?k.forEach(function(t){var n=A.indexOf(t),s=E[n],a=callProp(d,s,n);i.push(_extends({},r[t],{phase:e,destroyed:!0,left:A[n-1],right:A[n+1],props:_extends({delay:O+=m,config:callProp(y,s,e),to:a},shared.is.obj(a)&&interpolateTo(a))})),delete r[t]}):e===UPDATE&&j.forEach(function(t){var n=u.indexOf(t),i=o[n],s=callProp(f,i,n);r[t]=_extends({},r[t],{phase:e,props:_extends({delay:O+=m,config:callProp(y,i,e),to:s},shared.is.obj(s)&&interpolateTo(s))})})};b.length;)S();var T=u.map(function(e){return r[e]});return T=reconcileDeleted(i,T),_extends({},a,{first:n&&!x.length,changed:!!(x.length||k.length||j.length),transitions:T,current:r,deleted:i,prevProps:t})}function Spring(e){var t=e.children,n=_objectWithoutPropertiesLoose(e,["children"]);return t(useSpring(n))}function Trail(e){var t=e.items,n=e.children,r=_objectWithoutPropertiesLoose(e,["items","children"]),i=useTrail(t.length,r);return t.map(function(e,t){var r=n(e,t);return shared.is.fun(r)?r(i[t]):r})}function Transition(e){var t=e.items,n=e.keys,r=void 0===n?null:n,i=e.children;return useTransition(t,r,_objectWithoutPropertiesLoose(e,["items","keys","children"])).map(function(e,t){var n=e.item,r=e.key,s=e.props,a=e.phase,o=i(n,a,t),u=shared.is.fun(o)?o(s):o;return u&&React__default.createElement(u.type,_extends({key:r},u.props))})}class FrameLoop{constructor({update:e,onFrame:t,requestFrame:n}={}){this.controllers=new Map,this.isActive=!1,this.requestFrame=n||(e=>globals.requestAnimationFrame(e)),this.onFrame=t&&t.bind(this)||(e=>{e.forEach(e=>{const t=this.controllers.get(e[0]);t&&t.onFrame(e)})}),this.update=e&&e.bind(this)||(()=>{if(!this.isActive)return!1;const e=[];for(const t of Array.from(this.controllers.keys())){let n=!1;const r=this.controllers.get(t),i=r.props.onFrame&&[];for(const e of r.configs)e.idle||this.advance(e)&&(n=!0,i&&i.push([e.key,e.animated.getValue()]));e.push([t,n,i])}return this.onFrame(e),this.controllers.size?(this.requestFrame(this.update),!0):this.isActive=!1})}start(e){this.controllers.set(e.id,e),this.isActive||(this.isActive=!0,this.requestFrame(this.update))}stop(e){this.controllers.delete(e.id)}advance(e){const t=globals.now();let n=!1,r=!1;for(let i=0;i<e.animatedValues.length;i++){const s=e.animatedValues[i];if(s.done)continue;let a=e.toValues[i];const o=a instanceof animated.Animated?a:null;if(o&&(a=o.getValue()),e.immediate){s.setValue(a),s.done=!0;continue}const u=e.fromValues[i],c=s.startTime;if("string"==typeof u||"string"==typeof a){s.setValue(a),s.done=!0;continue}let l=s.lastPosition,h=Array.isArray(e.initialVelocity)?e.initialVelocity[i]:e.initialVelocity;if(void 0!==e.duration)l=u+e.easing((t-c)/e.duration)*(a-u),r=t>=c+e.duration;else if(e.decay){const n=!0===e.decay?.998:e.decay;l=u+h/(1-n)*(1-Math.exp(-(1-n)*(t-c))),(r=Math.abs(s.lastPosition-l)<.1)&&(a=l)}else{let n=void 0!==s.lastTime?s.lastTime:t;void 0!==s.lastVelocity&&(h=s.lastVelocity),t>n+64&&(n=t);const i=Math.floor(t-n);for(let t=0;t<i;++t){l+=1*(h+=1*((-e.tension*(l-a)+-e.friction*h)/e.mass)/1e3)/1e3}s.lastTime=t,s.lastVelocity=h;const o=!(!e.clamp||0===e.tension)&&(u<a?l>a:l<a),c=Math.abs(h)<=e.precision,d=0===e.tension||Math.abs(a-l)<=e.precision;r=o||c&&d}o&&!o.done&&(r=!1),r?(s.value!==a&&(l=a),s.done=!0):n=!0,s.setValue(l),s.lastPosition=l}return n}}const stringShapeRegex=/[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,createStringInterpolator=e=>{const t=e.output,n=t[0].match(stringShapeRegex).map(()=>[]);t.forEach(e=>{e.match(stringShapeRegex).forEach((e,t)=>n[t].push(+e))});const r=t[0].match(stringShapeRegex).map((t,r)=>shared.createInterpolator(Object.assign({},e,{output:n[r]})));return e=>{let n=0;return t[0].replace(stringShapeRegex,()=>r[n++](e))}};shared.Globals.assign({frameLoop:new FrameLoop,createStringInterpolator:createStringInterpolator,applyAnimatedValues:()=>!1,createAnimatedStyle:e=>new animated.AnimatedStyle(e),createAnimatedInterpolation:(e,...t)=>new animated.AnimatedInterpolation(e,t)});const update=()=>shared.Globals.frameLoop.update(),config={default:{tension:170,friction:26},gentle:{tension:120,friction:14},wobbly:{tension:180,friction:12},stiff:{tension:210,friction:20},slow:{tension:280,friction:60},molasses:{tension:280,friction:120}};Object.defineProperty(exports,"Globals",{enumerable:!0,get:function(){return shared.Globals}}),Object.defineProperty(exports,"createInterpolator",{enumerable:!0,get:function(){return shared.createInterpolator}}),Object.defineProperty(exports,"interpolate",{enumerable:!0,get:function(){return animated.interpolate}}),exports.Controller=Controller,exports.FrameLoop=FrameLoop,exports.Spring=Spring,exports.Trail=Trail,exports.Transition=Transition,exports.config=config,exports.update=update,exports.useChain=useChain,exports.useSpring=useSpring,exports.useSprings=useSprings,exports.useTrail=useTrail,exports.useTransition=useTransition;
//# sourceMappingURL=index.cjs.js.map

@@ -1,5 +0,1 @@

// FILE GENERATED BY `rollup-plugin-dts@0.15.1`
// https://github.com/Swatinem/rollup-plugin-dts
import { RefObject, ReactNode } from 'react';

@@ -11,5 +7,3 @@ import { Remap, EasingFunction, SpringValue } from '@react-spring/shared';

import { Merge, OneOrMore, Remap as Remap$1, Arrify, Solve, Indexable, OnEnd, Falsy } from '@react-spring/shared/types/common';
export * from '@react-spring/shared/types/animated';
export * from '@react-spring/shared/types/interpolation';
import { requestAnimationFrame } from '@react-spring/shared/globals';
import { FrameRequestCallback } from '@react-spring/shared/types';

@@ -512,4 +506,12 @@ /** Extract string keys from an object type */

/** `[isActive, [key, value][]]` */
declare type FrameUpdate<State extends object = any> = [boolean, [keyof State, State[keyof State]][] | undefined];
/**
* A tuple containing:
*
* [0] `controllerID`: The controller being updated
*
* [1] `isActive`: False when all animations have finished
*
* [2] `changes`: An array of `[key, value]` tuples
*/
declare type FrameUpdate<State extends object = any> = [number, boolean, [keyof State, State[keyof State]][] | undefined];
/** Controller props in pending updates */

@@ -519,4 +521,4 @@ declare type PendingProps<State extends object> = Merge<AnimationProps<State>, {

from?: Partial<State>;
parent?: Controller;
attach?: (ctrl: Controller) => Controller;
parent?: Controller | null;
attach?: (ctrl: Controller) => Controller | null;
timestamp?: number;

@@ -566,3 +568,3 @@ }>;

/** @internal Called by the frameloop */
onFrame([isActive, entries]: FrameUpdate<State>): void;
onFrame([id, isActive, entries]: FrameUpdate<State>): void;
/**

@@ -598,10 +600,8 @@ * Set a prop for the next animations where the prop is undefined. The given

declare type FrameListener = (this: FrameLoop, updates: FrameUpdate[]) => void;
declare type RequestFrameFn = (cb: FrameRequestCallback) => number | void;
declare class FrameLoop {
/**
* On each frame, these controllers are searched for values to animate.
*
* To avoid calling `requestAnimationFrame`, you can add controllers directly
* to this.
*/
controllers: Controller[];
controllers: Map<number, Controller<any>>;
/**

@@ -630,7 +630,7 @@ * True when at least one value is animating.

*/
requestFrame: typeof requestAnimationFrame;
requestFrame: RequestFrameFn;
constructor({ update, onFrame, requestFrame, }?: {
update?: FrameUpdater;
onFrame?: FrameListener;
requestFrame?: typeof requestAnimationFrame;
requestFrame?: RequestFrameFn;
});

@@ -640,5 +640,5 @@ start(ctrl: Controller): void;

/** Advance an animation forward one frame. */
advance(config: any): boolean;
advance(config: ActiveAnimation): boolean;
}
export { AnimationEvents, AnimationProps, Controller, ForwardProps, FrameLoop, FrameUpdate, ItemKeys, ItemTransition, ItemsProp, ReservedProps, Spring, SpringAsyncFn, SpringConfig, SpringHandle, SpringProps, SpringStopFn, SpringUpdate, SpringUpdateFn, Trail, Transition, TransitionPhase, UnknownProps, UseSpringProps, UseTransitionProps, config, update, useChain, useSpring, useSprings, useTrail, useTransition };

@@ -1,2 +0,2 @@

import t,{useEffect as e,useRef as n,useMemo as s,useImperativeHandle as i,useOnce as r}from"react";import o from"@babel/runtime/helpers/esm/extends";import{is as a,usePrev as c,fillArray as l,callProp as u,useOnce as h,toArray as f,useForceUpdate as d,interpolateTo as m,reconcileDeleted as p,Globals as g,createInterpolator as y}from"@react-spring/shared";export{Globals,createInterpolator}from"@react-spring/shared";import{useMemoOne as v,useCallbackOne as b}from"use-memo-one";import{__rest as E}from"tslib";import{now as V,frameLoop as _,createStringInterpolator as A,colorNames as w,requestAnimationFrame as j}from"@react-spring/shared/globals";import{AnimatedValueArray as k,AnimatedInterpolation as O,AnimatedValue as P,Animated as q,AnimatedStyle as F}from"@react-spring/animated";export{interpolate}from"@react-spring/animated";import x from"@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";function S(t,n,s){void 0===s&&(s=1e3),e(()=>{if(n){let e=0;t.forEach((t,i)=>{if(!t.current)return;const r=t.current.controllers;if(r.length){let t=s*n[i];isNaN(t)?t=e:e=t,r.forEach(e=>{e.queue.forEach(e=>e.delay+=t),e.start()})}})}else{let e=Promise.resolve();t.forEach(t=>{const n=t.current||{},s=n.controllers,i=n.start;if(s&&s.length){const t=s.map(t=>{const e=t.queue;return t.queue=[],e});e=e.then(()=>(s.forEach((e,n)=>e.queue.push(...t[n])),i()))}else console.warn("useChain ref has no animations:",t)})}})}function C(t,e){return null==t?e:t}function M(t){return a.und(t)?[]:Array.isArray(t)?t:[t]}function T(t,...e){return a.fun(t)?t(...e):t}function N(t){const e=function(t){return E(t,["children","config","from","to","ref","reset","cancel","reverse","immediate","delay","lazy","items","trail","unique","initial","enter","leave","update","onStart","onRest","onFrame","onDestroyed","timestamp","attach"])}(t);return t=Object.entries(t).reduce((t,[n,s])=>(n in e||(t[n]=s),t),{}),Object.assign({to:e},t)}const R=t=>t,z=Object.freeze({});let D=1;class I{constructor(t){this.id=D++,this.idle=!0,this.runCount=0,this.destroyed=!1,this.props={},this.queue=[],this.timestamps={},this.values={},this.merged={},this.animated={},this.animations={},this.configs=[],this.children=[],this.onEndQueue=[],this.cancelledAt=0,t&&this.update(t).start()}update(t){if(!t||this.destroyed)return this;const e=N(t);if(this._ensureAnimated(e.from,!0),this._ensureAnimated(e.to),e.timestamp=V(),a.fun(e.delay)&&a.obj(e.to)){const t=e.from||z;for(const n in e.to)this.queue.push(Object.assign({},e,{to:{[n]:e.to[n]},from:n in t?{[n]:t[n]}:void 0,delay:Math.max(0,Math.round(e.delay(n)))}))}else e.delay=a.num(e.delay)?Math.max(0,Math.round(e.delay)):0,e.to||(e.to=void 0),e.from||(e.from=void 0),this.queue.push(e);return this}start(t){return this.queue.length?this._flush(t):this._start(t),this}stop(...t){let e=!1;if(a.boo(t[0])&&([e,...t]=t),t.length)for(const e of t){const t=this.configs.findIndex(t=>e===t.key);this._stopAnimation(e),this.configs[t]=this.animations[e]}else this.runCount&&(this.cancelledAt=V(),this.configs.forEach(t=>this._stopAnimation(t.key)),this.configs=Object.values(this.animations),this._stop(e));return this}reset(){return this.stop(),this.destroyed=!1,this.props={},this.queue=[],this.timestamps={},this.values={},this.merged={},this.animated={},this.animations={},this.configs=[],this}destroy(){this.destroyed||(this.stop(),this.destroyed=!0)}onFrame([t,e]){if(e&&e.length){for(const[t,n]of e)this.values[t]=n;this.props.onFrame(Object.assign({},this.values))}t||this._stop(!0)}setProp(t,e){return this.props[t]=e,this.timestamps[t]=V(),this}_ensureAnimated(t,e=!1){if(a.obj(t))for(const n in t){const s=t[n];let i=this.animated[n];i&&e&&this.animations[n].isNew&&(i.setValue?i.setValue(s):i=null),i||((i=K(s))?(this.animated[n]&&Q(this.animated[n],i),this.animated[n]=i,this._stopAnimation(n,!0)):console.warn("Given value not animatable:",s))}}_onEnd(t){this.runCount?this.onEndQueue.push(t):t(!0)}_start(t){t&&this._onEnd(t),this.idle&&this.runCount&&(this.idle=!1,_.start(this))}_attach(t){this.children.forEach(e=>{const n=t.filter(t=>{const n=B(e,t);if(n)return n.forEach(t=>t.done&&t.reset(!0)),!0});n.length&&(e._attach(n),e._start())})}_stop(t){this.idle=!0,_.stop(this);const{onEndQueue:e}=this;e.length&&(this.onEndQueue=[],e.forEach(e=>e(t)))}_flush(t){const e=this.queue.reduce(L,[]);this.queue.length=0;let n=Object.keys(e).length;this.runCount+=n;const s=e=>{if(this.runCount--,!--n&&(t&&t(e),!this.runCount&&e)){const{onRest:t}=this.props;t&&t(this.merged)}};e.forEach((t,e)=>{e?setTimeout(()=>{t.timestamp<this.cancelledAt||this._run(t,s)},e):this._run(t,s)})}_run(t,e){a.arr(t.to)||a.fun(t.to)?this._runAsync(t,e):this._diff(t)?this._animate(t)._start(e):this._onEnd(e)}_runAsync(t,e){var{to:n}=t,s=E(t,["to"]);if(this._diff(s)&&this._animate(s),!0===s.cancel)return this.props.asyncTo=void 0,e(!1);const{timestamp:i}=s;if(!this._diff({asyncTo:n,timestamp:i}))return e(!1);const r=()=>i<this.cancelledAt||a.fun(n)&&n!==this.props.asyncTo;let o;const c=t=>{if(r())throw this;return(o=new Promise(e=>{this.update(t).start(e)})).then(()=>{if(r())throw this})};let l=Promise.resolve();a.arr(n)?n.forEach(t=>l=l.then(()=>c(t))):a.fun(n)&&(l=l.then(()=>n(c,this.stop.bind(this)).then(()=>o))),l.catch(t=>t!==this&&console.error(t)).then(()=>e(!r()))}_diff(t){var{timestamp:e,delay:n,config:s,immediate:i,reverse:r,attach:o}=t,c=E(t,["timestamp","delay","config","immediate","reverse","attach"]);let l=!1;const u=t=>{const n=this.timestamps[t];return!!(a.und(n)||e>=n)&&(this.timestamps[t]=e,!0)},h=(t,e,n)=>{if(a.und(e))return;const s=t[t.length-1];if(a.obj(e)){a.obj(n[s])||(n[s]={});for(const i in e)h(t.concat(i),e[i],n[s])}else if(u(t.join("."))){W(e,n[s])||(l=!0,n[s]=e)}};if(r){const{to:t}=c;c.to=c.from,c.from=a.obj(t)?t:void 0}o&&(c.parent=o(this));const{parent:f}=c;if(f&&!(f instanceof I))throw Error('The "parent" prop must be a Controller object or falsy');const d=this.props.parent;null!=f&&f!==d&&(d&&d.children.splice(d.children.indexOf(this),1),f&&f.children.push(this));for(const t in c)h([t],c[t],this.props);return"reset"in c&&(this.props.reset=!1),"cancel"in c&&(this.props.cancel=void 0),l}_isModified(t,e){return this.timestamps[e]===t.timestamp}_animate(t){const{from:e=z,to:n=z,parent:s,onStart:i}=this.props;let r=t=>!1;if(t.cancel&&this._isModified(t,"cancel")){if(!0===t.cancel)return this.stop(),this.cancelledAt=t.timestamp,this;const e=M(t.cancel);a.arr(e)&&e.length&&(r=t=>e.indexOf(t)>=0,this.stop(...e))}var o;this.merged=(o=Object.assign({},e,n),"undefined"!=typeof process&&"development"===process.env.NODE_ENV?Object.freeze(o):o);let c=!1;const l=[],u=s&&this._isModified(t,"parent");for(const n in this.merged){if(r(n))continue;const i=this.animations[n];if(!i){console.warn(`Failed to animate key: "${n}"\n`+`Did you forget to define "from.${n}" for an async animation?`);continue}let{animated:o,animatedValues:h}=i;const f=this.merged[n],d=U(f),m=o.getValue();if(t.reset||u||!W(d,m)){if(t.reset||u||!W(d,i.isNew?m:i.goalValue)){let{immediate:i}=a.und(t.immediate)?this.props:t;i=!!T(i,n);const r=h.some(t=>!t.done),u=a.und(e[n])?d:U(e[n]),m=G(f);if(m){const e=[t.reset?u:o.getValue(),d];let n=h[0];n?(n.setValue(0,!1),n.reset(r)):n=new P(0);try{Q(o,o=n.interpolate({output:e}))}catch(t){console.warn('Failed to interpolate string from "%s" to "%s"',e[0],e[1]),console.error(t);continue}i&&n.setValue(1,!1)}else{if(a.arr(f))if(o instanceof k)t.reset&&o.setValue(u,!1),h.forEach(t=>t.reset(r));else{Q(o,o=K(u))}else if(o instanceof P)t.reset&&o.setValue(u,!1),o.reset(r);else{Q(o,o=new P(u))}i&&o.setValue(d,!1)}const p=T(t.config,n)||T(this.props.config,n)||z;i||l.push(n);const g=h.map(t=>t.getValue()),y=s&&B(s,n)||M(m?1:d);c=!0,h=M(o.getPayload()),this.animations[n]={key:n,idle:!1,goalValue:d,toValues:y,fromValues:g,animated:o,animatedValues:h,immediate:i,duration:p.duration,easing:C(p.easing,R),decay:p.decay,mass:C(p.mass,1),tension:C(p.tension,170),friction:C(p.friction,26),initialVelocity:C(p.velocity,0),clamp:C(p.clamp,!1),precision:C(p.precision,.005),config:p}}}else i.idle||(c=!0,this._stopAnimation(n))}if(c){l.length&&(this._attach(l),i&&l.forEach(t=>{i(this.animations[t])}));const t=Object.keys(this.animations);this.configs.length=t.length,t.forEach((t,e)=>{const n=this.animations[t];this.configs[e]=n,this.values[t]=n.animated.getValue(),this.animated[t]=n.animated})}return this}_stopAnimation(t,e){const n=this.animated[t];if(!n)return console.warn(`Cannot stop an animation for a key that isn't animated: "${t}"`);this.timestamps["to."+t]=V();const s=this.animations[t]||z;if(s.idle&&n===s.animated)return;a.und(e)&&(e=!!s.isNew);const i=M(n.getPayload());i.forEach(t=>t.done=!0);const r=n.getValue();this.props.to&&(this.props.to[t]=r),this.animations[t]={key:t,idle:!0,isNew:e,goalValue:r,animated:n,animatedValues:i}}}function K(t){return a.arr(t)?new k(t.map(t=>{const e=K(t),n=e.getPayload();return e instanceof O?n[0]:n})):G(t)?new P(0).interpolate({output:[t,t]}):new P(t)}function Q(t,e){t.getChildren().slice().forEach(n=>{t.removeChild(n),e.addChild(n);const s=n.getPayload();if(a.arr(s)){const i=s.indexOf(t);if(i>=0){const t=[...s];t[i]=e,n.payload=t}}else if(a.obj(s)){const i=Object.entries(s).find(e=>e[1]===t);i&&(n.payload=Object.assign({},s,{[i[0]]:e}))}})}function L(t,e){const n=t[e.delay];return n?(e.to=$(n.to,e.to),e.from=$(n.from,e.from),Object.assign(n,e)):t[e.delay]=e,t}function $(t,e){return a.obj(t)&&a.obj(e)?Object.assign({},t,e):e||t}function G(t){return!!a.str(t)&&(t.startsWith("#")||/\d/.test(t)||!!w[t])}function U(t){return a.arr(t)?t.map(U):G(t)?A({range:[0,1],output:[t,t]})(1):t}function W(t,e){if(a.arr(t)){if(!a.arr(e)||t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}return t===e}function B(t,e){const n=t.animations[e];return n&&n.animatedValues}const H=(t,r,f)=>{const d=t!==c(t),m=a.fun(r),p=n({springs:[],ref:null}).current,g=m?[]:r,y=v(()=>l(t,t=>{const e=new I,n=g[t]||(g[t]=u(r,t,e));return e.update(n)}),[t]),b=s(()=>({start:()=>Promise.all(p.springs.map(t=>new Promise(e=>t.start(e)))),update:t=>{const e=a.fun(t),n=a.arr(t);p.springs.forEach((s,i)=>{s.update(e?u(t,i,s):n?t[i]:t),p.ref||s.start()})},stop:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return p.springs.forEach(t=>t.stop(...e))}}),[]),E=b.start,V=b.update,_=b.stop,A=g[0]?g[0].ref:m?p.ref:null;i(A,()=>({start:E,stop:_,get controllers(){return p.springs}})),e(()=>{m&&!d||g.forEach((t,e)=>{y[e].setProp("config",t.config),y[e].setProp("immediate",t.immediate)}),d?(p.springs.forEach(t=>t.destroy()),p.springs=y,p.ref=A,A||y.forEach(t=>t.start())):m||V(g)},f),h(()=>()=>{p.springs.forEach(t=>t.destroy())});const w=y.map(t=>o({},t.animated));return m?[w,V,_]:w},J=(t,e)=>{const n=a.fun(t),s=H(1,n?t:[t],e),i=s[0],r=s[1],o=s[2];return n?[i[0],r,o]:i},X=(t,s)=>{const i=t!==c(t),r=a.fun(s);let l=r?null:s;const h=n([]),f=h.current;i&&(f.length=t);const d=H(t,(t,e)=>(r&&!l&&(l=u(s,e)||{}),f[t]=e,o({},l,t>0&&{attach:()=>f[t-1],onStart:Y(l.onStart,t),onFrame:Y(l.onFrame,t),onRest:Y(l.onRest,t)},{config:u(l.config,t)}))),m=d[0],p=d[1],g=d[2],y=b(t=>p((e,n)=>{const s=u(t,e,n)||{},i=h.current[s.reverse?e+1:e-1];return o({},s,!!i&&{attach:()=>i},{config:u(s.config,e)})}),[]);return e(()=>{r||i||y(s)}),r?[m,y,g]:m};function Y(t,e){return a.fun(t)?function(){for(var n=arguments.length,s=new Array(n),i=0;i<n;i++)s[i]=arguments[i];return t(...s,e)}:t}let Z=0;const tt="initial",et="enter",nt="update",st="leave",it=(t,e)=>("function"==typeof e?t.map(e):f(e)).map(String),rt=t=>{let e=t.items,n=t.keys,s=x(t,["items","keys"]);return e=f(a.und(e)?null:e),o({items:e,keys:it(e,n)},s)};function ot(t,e,s){const c=s=rt(o({},s,{items:t,keys:e||(t=>t)})),l=c.lazy,h=void 0!==l&&l,f=(c.unique,c.from,c.enter,c.leave,c.update,c.onDestroyed),g=(c.keys,c.items,c.onFrame),y=c.onRest,v=c.onStart,b=c.ref,E=x(c,["lazy","unique","from","enter","leave","update","onDestroyed","keys","items","onFrame","onRest","onStart","ref"]),V=d(),_=n(!1),A=n({mounted:!1,first:!0,deleted:[],current:{},transitions:[],prevProps:{},paused:!!s.ref,instances:!_.current&&new Map,forceUpdate:V});return i(s.ref,()=>({start:()=>Promise.all(Array.from(A.current.instances).map(t=>{let e=t[1];return new Promise(t=>e.start(t))})),stop:t=>Array.from(A.current.instances).forEach(e=>{return e[1].stop(t)}),get controllers(){return Array.from(A.current.instances).map(t=>{return t[1]})}})),A.current=function(t,e){let n=t.first,s=t.current,i=t.deleted,r=t.prevProps,c=x(t,["first","current","deleted","prevProps"]),l=e.items,h=e.keys,f=e.initial,d=e.from,g=e.enter,y=e.leave,v=e.update,b=e.trail,E=void 0===b?0:b,V=e.unique,_=e.config,A=e.order,w=void 0===A?[et,st,nt]:A,j=rt(r),k=j.keys,O=j.items;e.reset&&(s={},c.transitions=[]);const P=Object.keys(s),q=new Set(P),F=new Set(h),S=h.filter(t=>!q.has(t)),C=v?h.filter(t=>q.has(t)):[],M=c.transitions.filter(t=>!t.destroyed&&!F.has(t.originalKey)).map(t=>t.originalKey);let T=-E;for(;w.length;){let t=w.shift();t===et?(n&&!a.und(f)&&(t=tt,d=f),S.forEach(e=>{V&&i.find(t=>t.originalKey===e)&&(i=i.filter(t=>t.originalKey!==e));const n=h.indexOf(e),r=l[n],c=u(g,r,n);s[e]={phase:t,originalKey:e,key:V?String(e):Z++,item:r,props:o({delay:T+=E,config:u(_,r,t),from:u(d,r),to:c},a.obj(c)&&m(c))}})):t===st?M.forEach(e=>{const n=k.indexOf(e),r=O[n],c=u(y,r,n);i.push(o({},s[e],{phase:t,destroyed:!0,left:k[n-1],right:k[n+1],props:o({delay:T+=E,config:u(_,r,t),to:c},a.obj(c)&&m(c))})),delete s[e]}):t===nt&&C.forEach(e=>{const n=h.indexOf(e),i=l[n],r=u(v,i,n);s[e]=o({},s[e],{phase:t,props:o({delay:T+=E,config:u(_,i,t),to:r},a.obj(r)&&m(r))})})}let N=h.map(t=>s[t]);return N=p(i,N),o({},c,{first:n&&!S.length,changed:!!(S.length||M.length||C.length),transitions:N,current:s,deleted:i,prevProps:e})}(A.current,s),A.current.changed&&A.current.transitions.forEach(t=>{const e=t.phase,n=t.key,s=t.item,i=t.props;A.current.instances.has(n)||A.current.instances.set(n,new I);let r=!1;const a=A.current.instances.get(n),c=o({},E,i,{ref:b,onRest:i=>{if(A.current.mounted){t.destroyed&&(b||h||at(A,n),f&&f(s)),!Array.from(A.current.instances).some(t=>{return!t[1].idle})&&(b||h)&&A.current.deleted.length>0&&at(A),y&&y(s,e,i)}},onFrame:g&&(t=>g(s,e,t)),onStart:v&&(t=>r||(v(s,e,t),r=!0))});a.update(c),A.current.paused||a.start()}),r(()=>(A.current.mounted=_.current=!0,()=>{A.current.mounted=_.current=!1,Array.from(A.current.instances).map(t=>{return t[1].destroy()}),A.current.instances.clear()})),A.current.transitions.map(t=>{let e=t.item,n=t.phase,s=t.key;return{item:e,key:s,phase:n,props:o({},A.current.instances.get(s).animated)}})}function at(t,e){let n=t.current;const s=n.deleted;for(let t of s){let s=t.key;const i=t=>t.key!==s;(a.und(e)||e===s)&&(n.instances.delete(s),n.transitions=n.transitions.filter(i),n.deleted=n.deleted.filter(i))}n.forceUpdate()}function ct(t){let e=t.children,n=x(t,["children"]);return e(J(n))}function lt(t){let e=t.items,n=t.children,s=x(t,["items","children"]);const i=X(e.length,s);return e.map((t,e)=>{const s=n(t,e);return a.fun(s)?s(i[e]):s})}function ut(e){let n=e.items,s=e.keys,i=void 0===s?null:s,r=e.children;return ot(n,i,x(e,["items","keys","children"])).map((e,n)=>{let s=e.item,i=e.key,c=e.props,l=e.phase;const u=r(s,l,n),h=a.fun(u)?u(c):u;return h&&t.createElement(h.type,o({key:i},h.props))})}class ht{constructor({update:t,onFrame:e,requestFrame:n}={}){this.controllers=[],this.isActive=!1,this.requestFrame=n||j,this.onFrame=e&&e.bind(this)||(t=>{t.forEach((t,e)=>{this.controllers[e].onFrame(t)})}),this.update=t&&t.bind(this)||(()=>{if(!this.isActive)return!1;const t=[];for(const e of this.controllers){let n=!1;const s=e.props.onFrame?[]:void 0;for(const t of e.configs)this.advance(t)&&(n=!0,s&&s.push([t.key,t.animated.getValue()]));t.push([n,s])}return this.onFrame(t),this.controllers.length?(this.requestFrame(this.update),!0):this.isActive=!1})}start(t){this.controllers.includes(t)||this.controllers.push(t),this.isActive||(this.isActive=!0,this.requestFrame(this.update))}stop(t){const e=this.controllers.indexOf(t);e>=0&&this.controllers.splice(e,1)}advance(t){const e=V();let n=!1,s=!1;for(let i=0;i<t.animatedValues.length;i++){const r=t.animatedValues[i];if(r.done)continue;let o=t.toValues[i];const a=o instanceof q;if(a&&(o=o.getValue()),t.immediate){r.setValue(o),r.done=!0;continue}const c=t.fromValues[i];if("string"==typeof c||"string"==typeof o){r.setValue(o),r.done=!0;continue}let l=r.lastPosition,u=Array.isArray(t.initialVelocity)?t.initialVelocity[i]:t.initialVelocity;if(void 0!==t.duration)l=c+t.easing((e-r.startTime)/t.duration)*(o-c),s=e>=r.startTime+t.duration;else if(t.decay){const n=!0===t.decay?.998:t.decay;l=c+u/(1-n)*(1-Math.exp(-(1-n)*(e-r.startTime))),(s=Math.abs(r.lastPosition-l)<.1)&&(o=l)}else{let n=void 0!==r.lastTime?r.lastTime:e;void 0!==r.lastVelocity&&(u=r.lastVelocity),e>n+64&&(n=e);const i=Math.floor(e-n);for(let e=0;e<i;++e){l+=1*(u+=1*((-t.tension*(l-o)+-t.friction*u)/t.mass)/1e3)/1e3}r.lastTime=e,r.lastVelocity=u;const a=!(!t.clamp||0===t.tension)&&(c<o?l>o:l<o),h=Math.abs(u)<=t.precision,f=0===t.tension||Math.abs(o-l)<=t.precision;s=a||h&&f}a&&!t.toValues[i].done&&(s=!1),s?(r.value!==o&&(l=o),r.done=!0):n=!0,r.setValue(l),r.lastPosition=l}return n}}const ft=/[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;g.assign({frameLoop:new ht,createStringInterpolator:t=>{const e=t.output,n=e[0].match(ft).map(()=>[]);e.forEach(t=>{t.match(ft).forEach((t,e)=>n[e].push(+t))});const s=e[0].match(ft).map((e,s)=>y(Object.assign({},t,{output:n[s]})));return t=>{let n=0;return e[0].replace(ft,()=>s[n++](t))}},applyAnimatedValues:()=>!1,createAnimatedStyle:t=>new F(t),createAnimatedInterpolation:(t,...e)=>new O(t,e)});const dt=()=>g.frameLoop.update(),mt={default:{tension:170,friction:26},gentle:{tension:120,friction:14},wobbly:{tension:180,friction:12},stiff:{tension:210,friction:20},slow:{tension:280,friction:60},molasses:{tension:280,friction:120}};export{I as Controller,ht as FrameLoop,ct as Spring,lt as Trail,ut as Transition,mt as config,dt as update,S as useChain,J as useSpring,H as useSprings,X as useTrail,ot as useTransition};
import t,{useEffect as e,useRef as n,useMemo as s,useImperativeHandle as i}from"react";import r from"@babel/runtime/helpers/esm/extends";import{is as o,usePrev as a,useOnce as c,useForceUpdate as l,Globals as u,createInterpolator as h}from"@react-spring/shared";export{Globals,createInterpolator}from"@react-spring/shared";import{__rest as f}from"tslib";import{useMemoOne as d,useCallbackOne as m}from"use-memo-one";import{now as p,frameLoop as g,createStringInterpolator as y,colorNames as v,requestAnimationFrame as b}from"@react-spring/shared/globals";import{AnimatedValueArray as E,AnimatedInterpolation as V,AnimatedValue as _,Animated as A,AnimatedStyle as k}from"@react-spring/animated";export{interpolate}from"@react-spring/animated";import w from"@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";function j(t,n,s){void 0===s&&(s=1e3),e(()=>{if(n){let e=0;t.forEach((t,i)=>{if(!t.current)return;const r=t.current.controllers;if(r.length){let t=s*n[i];isNaN(t)?t=e:e=t,r.forEach(e=>{e.queue.forEach(e=>e.delay+=t),e.start()})}})}else{let e=Promise.resolve();t.forEach(t=>{const n=t.current||{},s=n.controllers,i=n.start;if(s&&s.length){const t=s.map(t=>{const e=t.queue;return t.queue=[],e});e=e.then(()=>(s.forEach((e,n)=>e.queue.push(...t[n])),i()))}else console.warn("useChain ref has no animations:",t)})}})}function O(t,e){return null==t?e:t}function P(t){return o.und(t)?[]:Array.isArray(t)?t:[t]}function q(t,...e){return o.fun(t)?t(...e):t}function F(t){const e=function(t){return f(t,["children","config","from","to","ref","reset","cancel","reverse","immediate","delay","lazy","items","trail","unique","initial","enter","leave","update","onStart","onRest","onFrame","onDestroyed","timestamp","attach"])}(t);return t=Object.entries(t).reduce((t,[n,s])=>(n in e||(t[n]=s),t),{}),Object.assign({to:e},t)}const x=t=>t,M=Object.freeze({});let S=1;class C{constructor(t){this.id=S++,this.idle=!0,this.runCount=0,this.destroyed=!1,this.props={},this.queue=[],this.timestamps={},this.values={},this.merged={},this.animated={},this.animations={},this.configs=[],this.children=[],this.onEndQueue=[],this.cancelledAt=0,t&&this.update(t).start()}update(t){if(!t||this.destroyed)return this;const e=F(t);if(this._ensureAnimated(e.from,!0),this._ensureAnimated(e.to),e.timestamp=p(),o.fun(e.delay)&&o.obj(e.to)){const t=e.from||M;for(const n in e.to)this.queue.push(Object.assign({},e,{to:{[n]:e.to[n]},from:n in t?{[n]:t[n]}:void 0,delay:Math.max(0,Math.round(e.delay(n)))}))}else e.delay=o.num(e.delay)?Math.max(0,Math.round(e.delay)):0,e.to||(e.to=void 0),e.from||(e.from=void 0),this.queue.push(e);return this}start(t){return this.queue.length?this._flush(t):this._start(t),this}stop(...t){let e=!1;if(o.boo(t[0])&&([e,...t]=t),t.length)for(const e of t){const t=this.configs.findIndex(t=>e===t.key);this._stopAnimation(e),this.configs[t]=this.animations[e]}else this.runCount&&(this.cancelledAt=p(),this.configs.forEach(t=>this._stopAnimation(t.key)),this.configs=Object.values(this.animations),this._stop(e));return this}reset(){return this.stop(),this.destroyed=!1,this.props={},this.queue=[],this.timestamps={},this.values={},this.merged={},this.animated={},this.animations={},this.configs=[],this}destroy(){this.destroyed||(this.stop(),this.destroyed=!0)}onFrame([t,e,n]){if(t===this.id){if(n&&n.length){for(const[t,e]of n)this.values[t]=e;this.props.onFrame(Object.assign({},this.values))}e||this._stop(!0)}}setProp(t,e){return this.props[t]=e,this.timestamps[t]=p(),this}_ensureAnimated(t,e=!1){if(o.obj(t))for(const n in t){const s=t[n];let i=this.animated[n];i&&e&&this.animations[n].isNew&&(i.setValue?i.setValue(s):i=null),i||((i=N(s))?(this.animated[n]&&T(this.animated[n],i),this.animated[n]=i,this._stopAnimation(n,!0)):console.warn("Given value not animatable:",s))}}_onEnd(t){this.runCount?this.onEndQueue.push(t):t(!0)}_start(t){t&&this._onEnd(t),this.idle&&this.runCount&&(this.idle=!1,g.start(this))}_attach(t,e={}){this.children.forEach(n=>{if(e[this.id])return;e[this.id]=!0;const s=t.filter(t=>{const e=Q(n,t);if(e)return e.forEach(t=>t.done&&t.reset(!0)),!0});s.length&&(n._attach(s,e),n._start())})}_stop(t){this.idle=!0,g.stop(this);const{onEndQueue:e}=this;e.length&&(this.onEndQueue=[],e.forEach(e=>e(t)))}_flush(t){const e=this.queue.reduce(R,[]);this.queue.length=0;let n=Object.keys(e).length;this.runCount+=n;const s=e=>{if(this.runCount--,!--n&&(t&&t(e),!this.runCount&&e)){const{onRest:t}=this.props;t&&t(this.merged)}};e.forEach((t,e)=>{e?setTimeout(()=>{t.timestamp<this.cancelledAt||this._run(t,s)},e):this._run(t,s)})}_run(t,e){o.arr(t.to)||o.fun(t.to)?this._runAsync(t,e):this._diff(t)?this._animate(t)._start(e):this._onEnd(e)}_runAsync(t,e){var{to:n}=t,s=f(t,["to"]);if(this._diff(s)&&this._animate(s),!0===s.cancel)return this.props.asyncTo=void 0,e(!1);const{timestamp:i}=s;if(!this._diff({asyncTo:n,timestamp:i}))return e(!1);const r=()=>i<this.cancelledAt||o.fun(n)&&n!==this.props.asyncTo;let a;const c=t=>{if(r())throw this;return(a=new Promise(e=>{this.update(t).start(e)})).then(()=>{if(r())throw this})};let l=Promise.resolve();o.arr(n)?n.forEach(t=>l=l.then(()=>c(t))):o.fun(n)&&(l=l.then(()=>n(c,this.stop.bind(this)).then(()=>a))),l.catch(t=>t!==this&&console.error(t)).then(()=>e(!r()))}_diff(t){var{timestamp:e,delay:n,config:s,immediate:i,reverse:r,attach:a}=t,c=f(t,["timestamp","delay","config","immediate","reverse","attach"]);let l=!1;const u=(t,n,s)=>{if(o.und(n))return;const i=t[t.length-1];if(o.obj(n)){o.obj(s[i])||(s[i]={});for(const e in n)u(t.concat(e),n[e],s[i])}else{const r=t.join("."),a=this.timestamps[r];if(o.und(a)||e>=a){this.timestamps[r]=e,I(n,s[i])||(l=!0,s[i]=n)}}};if(r){const{to:t}=c;c.to=c.from,c.from=o.obj(t)?t:void 0}c.parent=(a?a(this):c.parent)||null;const h=this.props.parent||null;c.parent!==h&&(h&&h.children.splice(h.children.indexOf(this),1),c.parent&&c.parent.children.push(this));for(const t in c)u([t],c[t],this.props);return"reset"in c&&(this.props.reset=!1),"cancel"in c&&(this.props.cancel=void 0),l}_isModified(t,e){return this.timestamps[e]===t.timestamp}_animate(t){const{from:e=M,to:n=M,parent:s,onStart:i}=this.props;let r=t=>!1;if(t.cancel&&this._isModified(t,"cancel")){if(!0===t.cancel)return this.stop(),this.cancelledAt=t.timestamp,this;const e=P(t.cancel);o.arr(e)&&e.length&&(r=t=>e.indexOf(t)>=0,this.stop(...e))}var a;this.merged=(a=Object.assign({},e,n),"undefined"!=typeof process&&"development"===process.env.NODE_ENV?Object.freeze(a):a);let c=!1;const l=[],u=s&&this._isModified(t,"parent");for(const n in this.merged){if(r(n))continue;const i=this.animations[n];if(!i){console.warn(`Failed to animate key: "${n}"\n`+`Did you forget to define "from.${n}" for an async animation?`);continue}let{animated:a,animatedValues:h}=i;const f=this.merged[n],d=D(f),m=a.getValue();if(t.reset||u||!I(d,m)){if(t.reset||u||!I(d,i.isNew?m:i.goalValue)){let{immediate:i}=o.und(t.immediate)?this.props:t;i=!!q(i,n);const r=h.some(t=>!t.done),u=o.und(e[n])?d:D(e[n]),m=K(f);if(m){const e=[t.reset?u:a.getValue(),d];let n=h[0];n?(n.setValue(0,!1),n.reset(r)):n=new _(0);try{T(a,a=n.interpolate({output:e}))}catch(t){console.warn('Failed to interpolate string from "%s" to "%s"',e[0],e[1]),console.error(t);continue}i&&n.setValue(1,!1)}else{if(o.arr(f))if(a instanceof E)t.reset&&a.setValue(u,!1),h.forEach(t=>t.reset(r));else{T(a,a=N(u))}else if(a instanceof _)t.reset&&a.setValue(u,!1),a.reset(r);else{T(a,a=new _(u))}i&&a.setValue(d,!1)}const p=q(t.config,n)||q(this.props.config,n)||M;i||l.push(n);const g=h.map(t=>t.getValue()),y=s&&Q(s,n)||P(m?1:d);c=!0,h=P(a.getPayload()),this.animations[n]={key:n,idle:!1,goalValue:d,toValues:y,fromValues:g,animated:a,animatedValues:h,immediate:i,duration:p.duration,easing:O(p.easing,x),decay:p.decay,mass:O(p.mass,1),tension:O(p.tension,170),friction:O(p.friction,26),initialVelocity:O(p.velocity,0),clamp:O(p.clamp,!1),precision:O(p.precision,.005),config:p}}}else i.idle||(c=!0,this._stopAnimation(n))}if(c){l.length&&(this._attach(l),i&&l.forEach(t=>{i(this.animations[t])}));const t=Object.keys(this.animations);this.configs.length=t.length,t.forEach((t,e)=>{const n=this.animations[t];this.configs[e]=n,this.values[t]=n.animated.getValue(),this.animated[t]=n.animated})}return this}_stopAnimation(t,e){const n=this.animated[t];if(!n)return console.warn(`Cannot stop an animation for a key that isn't animated: "${t}"`);this.timestamps["to."+t]=p();const s=this.animations[t]||M;if(s.idle&&n===s.animated)return;o.und(e)&&(e=!!s.isNew);const i=P(n.getPayload());i.forEach(t=>t.done=!0);const r=n.getValue();this.props.to&&(this.props.to[t]=r),this.animations[t]={key:t,idle:!0,isNew:e,goalValue:r,animated:n,animatedValues:i}}}function N(t){return o.arr(t)?new E(t.map(t=>{const e=N(t),n=e.getPayload();return e instanceof V?n[0]:n})):K(t)?new _(0).interpolate({output:[t,t]}):new _(t)}function T(t,e){t.getChildren().slice().forEach(n=>{t.removeChild(n),e.addChild(n);const s=n.getPayload();if(o.arr(s)){const i=s.indexOf(t);if(i>=0){const t=[...s];t[i]=e,n.payload=t}}else if(o.obj(s)){const i=Object.entries(s).find(e=>e[1]===t);i&&(n.payload=Object.assign({},s,{[i[0]]:e}))}})}function R(t,e){const n=t[e.delay];return n?(e.to=z(n.to,e.to),e.from=z(n.from,e.from),Object.assign(n,e)):t[e.delay]=e,t}function z(t,e){return o.obj(t)&&o.obj(e)?Object.assign({},t,e):e||t}function K(t){return!!o.str(t)&&(t.startsWith("#")||/\d/.test(t)||!!v[t])}function D(t){return o.arr(t)?t.map(D):K(t)?y({range:[0,1],output:[t,t]})(1):t}function I(t,e){if(o.arr(t)){if(!o.arr(e)||t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}return t===e}function Q(t,e){const n=t.animations[e];return n&&n.animatedValues}const L=(t,l,u)=>{const h=t!==a(t),f=o.fun(l),m=n({springs:[],ref:null}).current,p=f?[]:l,g=d(()=>(function(t,e){const n=[];for(let s=0;s<t;s++)n.push(e(s));return n})(t,t=>{const e=new C,n=p[t]||(p[t]=q(l,t,e));return e.update(n)}),[t]),y=s(()=>({start:()=>Promise.all(m.springs.map(t=>new Promise(e=>t.start(e)))),update:t=>{const e=o.fun(t),n=o.arr(t);m.springs.forEach((s,i)=>{s.update(e?q(t,i,s):n?t[i]:t),m.ref||s.start()})},stop:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return m.springs.forEach(t=>t.stop(...e))}}),[]),v=y.start,b=y.update,E=y.stop,V=p[0]?p[0].ref:f?m.ref:null;i(V,()=>({start:v,stop:E,get controllers(){return m.springs}})),e(()=>{f&&!h||p.forEach((t,e)=>{g[e].setProp("config",t.config),g[e].setProp("immediate",t.immediate)}),h?(m.springs.forEach(t=>t.destroy()),m.springs=g,m.ref=V,V||g.forEach(t=>t.start())):f||b(p)},u),c(()=>()=>{m.springs.forEach(t=>t.destroy())});const _=g.map(t=>r({},t.animated));return f?[_,b,E]:_},$=(t,e)=>{const n=o.fun(t),s=L(1,n?t:[t],e),i=s[0],r=s[1],a=s[2];return n?[i[0],r,a]:i},G=(t,s)=>{const i=t!==a(t),c=o.fun(s);let l=c?null:s;const u=n([]),h=u.current;i&&(h.length=t);const f=L(t,(t,e)=>(c&&!l&&(l=q(s,e)||{}),h[t]=e,r({},l,t>0&&{attach:()=>h[t-1],onStart:U(l.onStart,t),onFrame:U(l.onFrame,t),onRest:U(l.onRest,t)},{config:q(l.config,t)}))),d=f[0],p=f[1],g=f[2],y=m(t=>p((e,n)=>{const s=q(t,e,n)||{},i=u.current[s.reverse?e+1:e-1];return r({},s,{attach:()=>i,config:q(s.config,e)})}),[]);return e(()=>{c||i||y(s)}),c?[d,y,g]:d};function U(t,e){return o.fun(t)?function(){for(var n=arguments.length,s=new Array(n),i=0;i<n;i++)s[i]=arguments[i];return t(...s,e)}:t}let W=0;const B="initial",H="enter",J="update",X="leave",Y=(t,e)=>("function"==typeof e?t.map(e):P(e)).map(String),Z=t=>{let e=t.items,n=t.keys,s=w(t,["items","keys"]);return e=P(o.und(e)?null:e),r({items:e,keys:Y(e,n)},s)};function tt(t,e,s){const a=s=Z(r({},s,{items:t,keys:e||(t=>t)})),u=a.lazy,h=void 0!==u&&u,d=(a.unique,a.from,a.enter,a.leave,a.update,a.onDestroyed),m=(a.keys,a.items,a.onFrame),p=a.onRest,g=a.onStart,y=a.ref,v=w(a,["lazy","unique","from","enter","leave","update","onDestroyed","keys","items","onFrame","onRest","onStart","ref"]),b=l(),E=n(!1),V=n({mounted:!1,first:!0,deleted:[],current:{},transitions:[],prevProps:{},paused:!!s.ref,instances:!E.current&&new Map,forceUpdate:b});return i(s.ref,()=>({start:()=>Promise.all(Array.from(V.current.instances).map(t=>{let e=t[1];return new Promise(t=>e.start(t))})),stop:t=>Array.from(V.current.instances).forEach(e=>{return e[1].stop(t)}),get controllers(){return Array.from(V.current.instances).map(t=>{return t[1]})}})),V.current=function(t,e){let n=t.first,s=t.current,i=t.deleted,a=t.prevProps,c=w(t,["first","current","deleted","prevProps"]),l=e.items,u=e.keys,h=e.initial,d=e.from,m=e.enter,p=e.leave,g=e.update,y=e.trail,v=void 0===y?0:y,b=e.unique,E=e.config,V=e.order,_=void 0===V?[H,X,J]:V,A=Z(a),k=A.keys,j=A.items;e.reset&&(s={},c.transitions=[]);const O=Object.keys(s),P=new Set(O),x=new Set(u),M=u.filter(t=>!P.has(t)),S=g?u.filter(t=>P.has(t)):[],C=c.transitions.filter(t=>!t.destroyed&&!x.has(t.originalKey)).map(t=>t.originalKey);let N=-v;for(;_.length;){let t=_.shift();t===H?(n&&!o.und(h)&&(t=B,d=h),M.forEach(e=>{b&&i.find(t=>t.originalKey===e)&&(i=i.filter(t=>t.originalKey!==e));const n=u.indexOf(e),a=l[n],c=q(m,a,n);s[e]={phase:t,originalKey:e,key:b?String(e):W++,item:a,props:r({delay:N+=v,config:q(E,a,t),from:q(d,a),to:c},o.obj(c)&&F(c))}})):t===X?C.forEach(e=>{const n=k.indexOf(e),a=j[n],c=q(p,a,n);i.push(r({},s[e],{phase:t,destroyed:!0,left:k[n-1],right:k[n+1],props:r({delay:N+=v,config:q(E,a,t),to:c},o.obj(c)&&F(c))})),delete s[e]}):t===J&&S.forEach(e=>{const n=u.indexOf(e),i=l[n],a=q(g,i,n);s[e]=r({},s[e],{phase:t,props:r({delay:N+=v,config:q(E,i,t),to:a},o.obj(a)&&F(a))})})}let T=u.map(t=>s[t]);return T=function(t,e){t=[...t],e=[...e];let n=0,s=0,i=t.length;for(let r=0;r<t.length;r++){if(r===i){if(s+n===i){for(let n=r;n<t.length;n++){const s=t[n],i=f(s,["left","right"]);e.push(i)}break}s=i,i=t.length,n=0}let o=-1;const a=t[r],{left:c,right:l}=a,u=f(a,["left","right"]);for(let t=e.length;--t>=0;){const{originalKey:n}=e[t];if(n===l){o=t;break}if(n===c){o=t+1;break}}o<0?(n++,t.push(t[r])):e.splice(o,0,u)}return e}(i,T),r({},c,{first:n&&!M.length,changed:!!(M.length||C.length||S.length),transitions:T,current:s,deleted:i,prevProps:e})}(V.current,s),V.current.changed&&V.current.transitions.forEach(t=>{const e=t.phase,n=t.key,s=t.item,i=t.props;V.current.instances.has(n)||V.current.instances.set(n,new C);let o=!1;const a=V.current.instances.get(n),c=r({},v,i,{ref:y,onRest:i=>{if(V.current.mounted){t.destroyed&&(y||h||et(V,n),d&&d(s)),!Array.from(V.current.instances).some(t=>{return!t[1].idle})&&(y||h)&&V.current.deleted.length>0&&et(V),p&&p(s,e,i)}},onFrame:m&&(t=>m(s,e,t)),onStart:g&&(t=>o||(g(s,e,t),o=!0))});a.update(c),V.current.paused||a.start()}),c(()=>(V.current.mounted=E.current=!0,()=>{V.current.mounted=E.current=!1,Array.from(V.current.instances).map(t=>{return t[1].destroy()}),V.current.instances.clear()})),V.current.transitions.map(t=>{let e=t.item,n=t.phase,s=t.key;return{item:e,key:s,phase:n,props:r({},V.current.instances.get(s).animated)}})}function et(t,e){let n=t.current;const s=n.deleted;for(let t of s){let s=t.key;const i=t=>t.key!==s;(o.und(e)||e===s)&&(n.instances.delete(s),n.transitions=n.transitions.filter(i),n.deleted=n.deleted.filter(i))}n.forceUpdate()}function nt(t){let e=t.children,n=w(t,["children"]);return e($(n))}function st(t){let e=t.items,n=t.children,s=w(t,["items","children"]);const i=G(e.length,s);return e.map((t,e)=>{const s=n(t,e);return o.fun(s)?s(i[e]):s})}function it(e){let n=e.items,s=e.keys,i=void 0===s?null:s,a=e.children;return tt(n,i,w(e,["items","keys","children"])).map((e,n)=>{let s=e.item,i=e.key,c=e.props,l=e.phase;const u=a(s,l,n),h=o.fun(u)?u(c):u;return h&&t.createElement(h.type,r({key:i},h.props))})}class rt{constructor({update:t,onFrame:e,requestFrame:n}={}){this.controllers=new Map,this.isActive=!1,this.requestFrame=n||(t=>b(t)),this.onFrame=e&&e.bind(this)||(t=>{t.forEach(t=>{const e=this.controllers.get(t[0]);e&&e.onFrame(t)})}),this.update=t&&t.bind(this)||(()=>{if(!this.isActive)return!1;const t=[];for(const e of Array.from(this.controllers.keys())){let n=!1;const s=this.controllers.get(e),i=s.props.onFrame&&[];for(const t of s.configs)t.idle||this.advance(t)&&(n=!0,i&&i.push([t.key,t.animated.getValue()]));t.push([e,n,i])}return this.onFrame(t),this.controllers.size?(this.requestFrame(this.update),!0):this.isActive=!1})}start(t){this.controllers.set(t.id,t),this.isActive||(this.isActive=!0,this.requestFrame(this.update))}stop(t){this.controllers.delete(t.id)}advance(t){const e=p();let n=!1,s=!1;for(let i=0;i<t.animatedValues.length;i++){const r=t.animatedValues[i];if(r.done)continue;let o=t.toValues[i];const a=o instanceof A?o:null;if(a&&(o=a.getValue()),t.immediate){r.setValue(o),r.done=!0;continue}const c=t.fromValues[i],l=r.startTime;if("string"==typeof c||"string"==typeof o){r.setValue(o),r.done=!0;continue}let u=r.lastPosition,h=Array.isArray(t.initialVelocity)?t.initialVelocity[i]:t.initialVelocity;if(void 0!==t.duration)u=c+t.easing((e-l)/t.duration)*(o-c),s=e>=l+t.duration;else if(t.decay){const n=!0===t.decay?.998:t.decay;u=c+h/(1-n)*(1-Math.exp(-(1-n)*(e-l))),(s=Math.abs(r.lastPosition-u)<.1)&&(o=u)}else{let n=void 0!==r.lastTime?r.lastTime:e;void 0!==r.lastVelocity&&(h=r.lastVelocity),e>n+64&&(n=e);const i=Math.floor(e-n);for(let e=0;e<i;++e){u+=1*(h+=1*((-t.tension*(u-o)+-t.friction*h)/t.mass)/1e3)/1e3}r.lastTime=e,r.lastVelocity=h;const a=!(!t.clamp||0===t.tension)&&(c<o?u>o:u<o),l=Math.abs(h)<=t.precision,f=0===t.tension||Math.abs(o-u)<=t.precision;s=a||l&&f}a&&!a.done&&(s=!1),s?(r.value!==o&&(u=o),r.done=!0):n=!0,r.setValue(u),r.lastPosition=u}return n}}const ot=/[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;u.assign({frameLoop:new rt,createStringInterpolator:t=>{const e=t.output,n=e[0].match(ot).map(()=>[]);e.forEach(t=>{t.match(ot).forEach((t,e)=>n[e].push(+t))});const s=e[0].match(ot).map((e,s)=>h(Object.assign({},t,{output:n[s]})));return t=>{let n=0;return e[0].replace(ot,()=>s[n++](t))}},applyAnimatedValues:()=>!1,createAnimatedStyle:t=>new k(t),createAnimatedInterpolation:(t,...e)=>new V(t,e)});const at=()=>u.frameLoop.update(),ct={default:{tension:170,friction:26},gentle:{tension:120,friction:14},wobbly:{tension:180,friction:12},stiff:{tension:210,friction:20},slow:{tension:280,friction:60},molasses:{tension:280,friction:120}};export{C as Controller,rt as FrameLoop,nt as Spring,st as Trail,it as Transition,ct as config,at as update,j as useChain,$ as useSpring,L as useSprings,G as useTrail,tt as useTransition};
//# sourceMappingURL=index.js.map
{
"name": "@react-spring/core",
"version": "0.0.1-alpha.0",
"version": "0.0.1-alpha.1",
"description": "Cross-platform animation engine",

@@ -16,3 +16,3 @@ "keywords": [

],
"homepage": "https://github.com/react-spring/react-spring/packages/core#readme",
"homepage": "https://github.com/react-spring/react-spring/tree/master/packages/core#readme",
"bugs": {

@@ -31,4 +31,4 @@ "url": "https://github.com/react-spring/react-spring/issues"

"@babel/runtime": "^7.3.1",
"@react-spring/animated": "^0.0.1-alpha.0",
"@react-spring/shared": "^0.0.1-alpha.0",
"@react-spring/animated": "^0.0.1-alpha.1",
"@react-spring/shared": "^0.0.1-alpha.1",
"tslib": "^1.9.3",

@@ -35,0 +35,0 @@ "use-memo-one": "^1.1.0"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc