import{__assign as o}from"../../../node_modules/tslib/tslib.es6.js";import{animate as t}from"./index.js";import{velocityPerSecond as e}from"../utils/velocity-per-second.js";import{getFrameData as i}from"../../../../framesync/dist/es/index.js";function n(n){var r,d=n.from,s=void 0===d?0:d,a=n.velocity,l=void 0===a?0:a,v=n.min,f=n.max,m=n.power,p=void 0===m?.8:m,u=n.timeConstant,c=void 0===u?750:u,y=n.bounceStiffness,b=void 0===y?500:y,g=n.bounceDamping,j=void 0===g?10:g,x=n.restDelta,C=void 0===x?1:x,D=n.modifyTarget,U=n.driver,h=n.onUpdate,w=n.onComplete;function M(o){return void 0!==v&&o<v||void 0!==f&&o>f}function T(o){return void 0===v?f:void 0===f||Math.abs(v-o)<Math.abs(f-o)?v:f}function S(e){null==r||r.stop(),r=t(o(o({},e),{driver:U,onUpdate:function(o){var t;null==h||h(o),null===(t=e.onUpdate)||void 0===t||t.call(e,o)},onComplete:w}))}function _(t){S(o({type:"spring",stiffness:b,damping:j,restDelta:C},t))}if(M(s))_({from:s,velocity:l,to:T(s)});else{var k=p*l+s;void 0!==D&&(k=D(k));var q,z,A=T(k),B=A===v?-1:1;S({type:"decay",from:s,velocity:l,timeConstant:c,power:p,restDelta:C,modifyTarget:D,onUpdate:M(k)?function(o){q=z,z=o,l=e(o-q,i().delta),(1===B&&o>A||-1===B&&o<A)&&_({from:o,to:A,velocity:l})}:void 0})}return{stop:function(){return null==r?void 0:r.stop()}}}export{n as inertia};
//# sourceMappingURL=inertia.js.map
