{"version":3,"file":"easing.mjs","sources":["../../../../src/util/animation/easing.ts"],"sourcesContent":["/**\n * Easing functions\n * @see {@link http://gizma.com/easing/ Easing Equations by Robert Penner}\n */\n\nimport { twoMathPi, halfPI } from '../../constants';\nimport type { TEasingFunction } from './types';\n\nconst normalize = (a: number, c: number, p: number, s: number) => {\n  if (a < Math.abs(c)) {\n    a = c;\n    s = p / 4;\n  } else {\n    //handle the 0/0 case:\n    if (c === 0 && a === 0) {\n      s = (p / twoMathPi) * Math.asin(1);\n    } else {\n      s = (p / twoMathPi) * Math.asin(c / a);\n    }\n  }\n  return { a, c, p, s };\n};\n\nconst elastic = (\n  a: number,\n  s: number,\n  p: number,\n  t: number,\n  d: number,\n): number =>\n  a * Math.pow(2, 10 * (t -= 1)) * Math.sin(((t * d - s) * twoMathPi) / p);\n\n/**\n * Default sinusoidal easing\n */\nexport const defaultEasing: TEasingFunction = (t, b, c, d) =>\n  -c * Math.cos((t / d) * halfPI) + c + b;\n\n/**\n * Cubic easing in\n */\nexport const easeInCubic: TEasingFunction = (t, b, c, d) =>\n  c * (t / d) ** 3 + b;\n\n/**\n * Cubic easing out\n */\nexport const easeOutCubic: TEasingFunction = (t, b, c, d) =>\n  c * ((t / d - 1) ** 3 + 1) + b;\n\n/**\n * Cubic easing in and out\n */\nexport const easeInOutCubic: TEasingFunction = (t, b, c, d) => {\n  t /= d / 2;\n  if (t < 1) {\n    return (c / 2) * t ** 3 + b;\n  }\n  return (c / 2) * ((t - 2) ** 3 + 2) + b;\n};\n\n/**\n * Quartic easing in\n */\nexport const easeInQuart: TEasingFunction = (t, b, c, d) =>\n  c * (t /= d) * t ** 3 + b;\n\n/**\n * Quartic easing out\n */\nexport const easeOutQuart: TEasingFunction = (t, b, c, d) =>\n  -c * ((t = t / d - 1) * t ** 3 - 1) + b;\n\n/**\n * Quartic easing in and out\n */\nexport const easeInOutQuart: TEasingFunction = (t, b, c, d) => {\n  t /= d / 2;\n  if (t < 1) {\n    return (c / 2) * t ** 4 + b;\n  }\n  return (-c / 2) * ((t -= 2) * t ** 3 - 2) + b;\n};\n\n/**\n * Quintic easing in\n */\nexport const easeInQuint: TEasingFunction = (t, b, c, d) =>\n  c * (t / d) ** 5 + b;\n\n/**\n * Quintic easing out\n */\nexport const easeOutQuint: TEasingFunction = (t, b, c, d) =>\n  c * ((t / d - 1) ** 5 + 1) + b;\n\n/**\n * Quintic easing in and out\n */\nexport const easeInOutQuint: TEasingFunction = (t, b, c, d) => {\n  t /= d / 2;\n  if (t < 1) {\n    return (c / 2) * t ** 5 + b;\n  }\n  return (c / 2) * ((t - 2) ** 5 + 2) + b;\n};\n\n/**\n * Sinusoidal easing in\n */\nexport const easeInSine: TEasingFunction = (t, b, c, d) =>\n  -c * Math.cos((t / d) * halfPI) + c + b;\n\n/**\n * Sinusoidal easing out\n */\nexport const easeOutSine: TEasingFunction = (t, b, c, d) =>\n  c * Math.sin((t / d) * halfPI) + b;\n\n/**\n * Sinusoidal easing in and out\n */\nexport const easeInOutSine: TEasingFunction = (t, b, c, d) =>\n  (-c / 2) * (Math.cos((Math.PI * t) / d) - 1) + b;\n\n/**\n * Exponential easing in\n */\nexport const easeInExpo: TEasingFunction = (t, b, c, d) =>\n  t === 0 ? b : c * 2 ** (10 * (t / d - 1)) + b;\n\n/**\n * Exponential easing out\n */\nexport const easeOutExpo: TEasingFunction = (t, b, c, d) =>\n  t === d ? b + c : c * -(2 ** ((-10 * t) / d) + 1) + b;\n\n/**\n * Exponential easing in and out\n */\nexport const easeInOutExpo: TEasingFunction = (t, b, c, d) => {\n  if (t === 0) {\n    return b;\n  }\n  if (t === d) {\n    return b + c;\n  }\n  t /= d / 2;\n  if (t < 1) {\n    return (c / 2) * 2 ** (10 * (t - 1)) + b;\n  }\n  return (c / 2) * -(2 ** (-10 * --t) + 2) + b;\n};\n\n/**\n * Circular easing in\n */\nexport const easeInCirc: TEasingFunction = (t, b, c, d) =>\n  -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;\n\n/**\n * Circular easing out\n */\nexport const easeOutCirc: TEasingFunction = (t, b, c, d) =>\n  c * Math.sqrt(1 - (t = t / d - 1) * t) + b;\n\n/**\n * Circular easing in and out\n */\nexport const easeInOutCirc: TEasingFunction = (t, b, c, d) => {\n  t /= d / 2;\n  if (t < 1) {\n    return (-c / 2) * (Math.sqrt(1 - t ** 2) - 1) + b;\n  }\n  return (c / 2) * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;\n};\n\n/**\n * Elastic easing in\n */\nexport const easeInElastic: TEasingFunction = (t, b, c, d) => {\n  const s = 1.70158,\n    a = c;\n  let p = 0;\n  if (t === 0) {\n    return b;\n  }\n  t /= d;\n  if (t === 1) {\n    return b + c;\n  }\n  if (!p) {\n    p = d * 0.3;\n  }\n  const { a: normA, s: normS, p: normP } = normalize(a, c, p, s);\n  return -elastic(normA, normS, normP, t, d) + b;\n};\n\n/**\n * Elastic easing out\n */\nexport const easeOutElastic: TEasingFunction = (t, b, c, d) => {\n  const s = 1.70158,\n    a = c;\n  let p = 0;\n  if (t === 0) {\n    return b;\n  }\n  t /= d;\n  if (t === 1) {\n    return b + c;\n  }\n  if (!p) {\n    p = d * 0.3;\n  }\n  const { a: normA, s: normS, p: normP, c: normC } = normalize(a, c, p, s);\n  return (\n    normA * 2 ** (-10 * t) * Math.sin(((t * d - normS) * twoMathPi) / normP) +\n    normC +\n    b\n  );\n};\n\n/**\n * Elastic easing in and out\n */\nexport const easeInOutElastic: TEasingFunction = (t, b, c, d) => {\n  const s = 1.70158,\n    a = c;\n  let p = 0;\n  if (t === 0) {\n    return b;\n  }\n  t /= d / 2;\n  if (t === 2) {\n    return b + c;\n  }\n  if (!p) {\n    p = d * (0.3 * 1.5);\n  }\n  const { a: normA, s: normS, p: normP, c: normC } = normalize(a, c, p, s);\n  if (t < 1) {\n    return -0.5 * elastic(normA, normS, normP, t, d) + b;\n  }\n  return (\n    normA *\n      Math.pow(2, -10 * (t -= 1)) *\n      Math.sin(((t * d - normS) * twoMathPi) / normP) *\n      0.5 +\n    normC +\n    b\n  );\n};\n\n/**\n * Backwards easing in\n */\nexport const easeInBack: TEasingFunction = (t, b, c, d, s = 1.70158) =>\n  c * (t /= d) * t * ((s + 1) * t - s) + b;\n\n/**\n * Backwards easing out\n */\nexport const easeOutBack: TEasingFunction = (t, b, c, d, s = 1.70158) =>\n  c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;\n\n/**\n * Backwards easing in and out\n */\nexport const easeInOutBack: TEasingFunction = (t, b, c, d, s = 1.70158) => {\n  t /= d / 2;\n  if (t < 1) {\n    return (c / 2) * (t * t * (((s *= 1.525) + 1) * t - s)) + b;\n  }\n  return (c / 2) * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;\n};\n\n/**\n * Bouncing easing out\n */\nexport const easeOutBounce: TEasingFunction = (t, b, c, d) => {\n  if ((t /= d) < 1 / 2.75) {\n    return c * (7.5625 * t * t) + b;\n  } else if (t < 2 / 2.75) {\n    return c * (7.5625 * (t -= 1.5 / 2.75) * t + 0.75) + b;\n  } else if (t < 2.5 / 2.75) {\n    return c * (7.5625 * (t -= 2.25 / 2.75) * t + 0.9375) + b;\n  } else {\n    return c * (7.5625 * (t -= 2.625 / 2.75) * t + 0.984375) + b;\n  }\n};\n\n/**\n * Bouncing easing in\n */\nexport const easeInBounce: TEasingFunction = (t, b, c, d) =>\n  c - easeOutBounce(d - t, 0, c, d) + b;\n\n/**\n * Bouncing easing in and out\n */\nexport const easeInOutBounce: TEasingFunction = (t, b, c, d) =>\n  t < d / 2\n    ? easeInBounce(t * 2, 0, c, d) * 0.5 + b\n    : easeOutBounce(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;\n\n/**\n * Quadratic easing in\n */\nexport const easeInQuad: TEasingFunction = (t, b, c, d) => c * (t /= d) * t + b;\n\n/**\n * Quadratic easing out\n */\nexport const easeOutQuad: TEasingFunction = (t, b, c, d) =>\n  -c * (t /= d) * (t - 2) + b;\n\n/**\n * Quadratic easing in and out\n */\nexport const easeInOutQuad: TEasingFunction = (t, b, c, d) => {\n  t /= d / 2;\n  if (t < 1) {\n    return (c / 2) * t ** 2 + b;\n  }\n  return (-c / 2) * (--t * (t - 2) - 1) + b;\n};\n"],"names":["defaultEasing","t","b","c","d","Math","cos","halfPI"],"mappings":";;AAAA;AACA;AACA;AACA;;;AA6BA;AACA;AACA;AACaA,MAAAA,aAA8B,GAAGA,CAACC,CAAC,EAAEC,CAAC,EAAEC,CAAC,EAAEC,CAAC,KACvD,CAACD,CAAC,GAAGE,IAAI,CAACC,GAAG,CAAEL,CAAC,GAAGG,CAAC,GAAIG,MAAM,CAAC,GAAGJ,CAAC,GAAGD;;;;"}