"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("../waapi/utils/linear.mjs.js"),s=require("./utils/calc-duration.mjs.js"),e=require("./utils/create-generator-easing.mjs.js"),n=require("../../../../../motion-utils/dist/es/time-conversion.mjs.js"),a=require("../../../../../motion-utils/dist/es/clamp.mjs.js"),o=require("../../../../../motion-utils/dist/es/errors.mjs.js");const i={stiffness:100,damping:10,mass:1,velocity:0,duration:800,bounce:.3,visualDuration:.3,restSpeed:{granular:.01,default:2},restDelta:{granular:.005,default:.5},minDuration:.01,maxDuration:10,minDamping:.05,maxDamping:1};function r(t,s){return t*Math.sqrt(1-s*s)}const u=12;const l=.001;function c(t){let s,e,{duration:c=i.duration,bounce:d=i.bounce,velocity:m=i.velocity,mass:p=i.mass}=t;o.warning(c<=n.secondsToMilliseconds(i.maxDuration),"Spring duration must be 10 seconds or less","spring-duration-limit");let h=1-d;h=a.clamp(i.minDamping,i.maxDamping,h),c=a.clamp(i.minDuration,i.maxDuration,n.millisecondsToSeconds(c)),h<1?(s=t=>{const s=t*h,e=s*c,n=s-m,a=r(t,h),o=Math.exp(-e);return l-n/a*o},e=t=>{const e=t*h*c,n=e*m+m,a=Math.pow(h,2)*Math.pow(t,2)*c,o=Math.exp(-e),i=r(Math.pow(t,2),h);return(-s(t)+l>0?-1:1)*((n-a)*o)/i}):(s=t=>Math.exp(-t*c)*((t-m)*c+1)-l,e=t=>Math.exp(-t*c)*(c*c*(m-t)));const M=function(t,s,e){let n=e;for(let e=1;e<u;e++)n-=t(n)/s(n);return n}(s,e,5/c);if(c=n.secondsToMilliseconds(c),isNaN(M))return{stiffness:i.stiffness,damping:i.damping,duration:c};{const t=Math.pow(M,2)*p;return{stiffness:t,damping:2*h*Math.sqrt(p*t),duration:c}}}const d=["duration","bounce"],m=["stiffness","damping","mass"];function p(t,s){return s.some((s=>void 0!==t[s]))}function h(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:i.visualDuration,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i.bounce;const u="object"!=typeof e?{visualDuration:e,keyframes:[0,1],bounce:o}:e;let{restSpeed:l,restDelta:h}=u;const M=u.keyframes[0],f=u.keyframes[u.keyframes.length-1],g={done:!1,value:M},{stiffness:v,damping:D,mass:x,duration:y,velocity:b,isResolvedFromDuration:j}=function(t){let s={velocity:i.velocity,stiffness:i.stiffness,damping:i.damping,mass:i.mass,isResolvedFromDuration:!1,...t};if(!p(t,m)&&p(t,d))if(s.velocity=0,t.visualDuration){const e=t.visualDuration,n=2*Math.PI/(1.2*e),o=n*n,r=2*a.clamp(.05,1,1-(t.bounce||0))*Math.sqrt(o);s={...s,mass:i.mass,stiffness:o,damping:r}}else{const e=c({...t,velocity:0});s={...s,...e,mass:i.mass},s.isResolvedFromDuration=!0}return s}({...u,velocity:-n.millisecondsToSeconds(u.velocity||0)}),q=b||0,T=D/(2*Math.sqrt(v*x)),S=f-M,w=n.millisecondsToSeconds(Math.sqrt(v/x)),k=Math.abs(S)<5;let F,G,R,E,N,O;if(l||(l=k?i.restSpeed.granular:i.restSpeed.default),h||(h=k?i.restDelta.granular:i.restDelta.default),T<1)R=r(w,T),E=(q+T*w*S)/R,F=t=>{const s=Math.exp(-T*w*t);return f-s*(E*Math.sin(R*t)+S*Math.cos(R*t))},N=T*w*E+S*R,O=T*w*S-E*R,G=t=>Math.exp(-T*w*t)*(N*Math.sin(R*t)+O*Math.cos(R*t));else if(1===T){F=t=>f-Math.exp(-w*t)*(S+(q+w*S)*t);const t=q+w*S;G=s=>Math.exp(-w*s)*(w*t*s-q)}else{const t=w*Math.sqrt(T*T-1);F=s=>{const e=Math.exp(-T*w*s),n=Math.min(t*s,300);return f-e*((q+T*w*S)*Math.sinh(n)+t*S*Math.cosh(n))/t};const s=(q+T*w*S)/t,e=T*w*s-S*t,n=T*w*S-s*t;G=s=>{const a=Math.exp(-T*w*s),o=Math.min(t*s,300);return a*(e*Math.sinh(o)+n*Math.cosh(o))}}const P={calculatedDuration:j&&y||null,velocity:t=>n.secondsToMilliseconds(G(t)),next:t=>{if(!j&&T<1){const s=Math.exp(-T*w*t),e=Math.sin(R*t),a=Math.cos(R*t),o=f-s*(E*e+S*a),i=n.secondsToMilliseconds(s*(N*e+O*a));return g.done=Math.abs(i)<=l&&Math.abs(f-o)<=h,g.value=g.done?f:o,g}const s=F(t);if(j)g.done=t>=y;else{const e=n.secondsToMilliseconds(G(t));g.done=Math.abs(e)<=l&&Math.abs(f-s)<=h}return g.value=g.done?f:s,g},toString:()=>{const e=Math.min(s.calcGeneratorDuration(P),s.maxGeneratorDuration),n=t.generateLinearEasing((t=>P.next(e*t).value),e,30);return e+"ms "+n},toTransition:()=>{}};return P}h.applyToOptions=t=>{const s=e.createGeneratorEasing(t,100,h);return t.ease=s.ease,t.duration=n.secondsToMilliseconds(s.duration),t.type="keyframes",t},exports.spring=h;
//# sourceMappingURL=spring.mjs.js.map
