d3-ease.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // https://d3js.org/d3-ease/ v1.0.7 Copyright 2020 Mike Bostock
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = global || self, factory(global.d3 = global.d3 || {}));
  6. }(this, function (exports) { 'use strict';
  7. function linear(t) {
  8. return +t;
  9. }
  10. function quadIn(t) {
  11. return t * t;
  12. }
  13. function quadOut(t) {
  14. return t * (2 - t);
  15. }
  16. function quadInOut(t) {
  17. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  18. }
  19. function cubicIn(t) {
  20. return t * t * t;
  21. }
  22. function cubicOut(t) {
  23. return --t * t * t + 1;
  24. }
  25. function cubicInOut(t) {
  26. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  27. }
  28. var exponent = 3;
  29. var polyIn = (function custom(e) {
  30. e = +e;
  31. function polyIn(t) {
  32. return Math.pow(t, e);
  33. }
  34. polyIn.exponent = custom;
  35. return polyIn;
  36. })(exponent);
  37. var polyOut = (function custom(e) {
  38. e = +e;
  39. function polyOut(t) {
  40. return 1 - Math.pow(1 - t, e);
  41. }
  42. polyOut.exponent = custom;
  43. return polyOut;
  44. })(exponent);
  45. var polyInOut = (function custom(e) {
  46. e = +e;
  47. function polyInOut(t) {
  48. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  49. }
  50. polyInOut.exponent = custom;
  51. return polyInOut;
  52. })(exponent);
  53. var pi = Math.PI,
  54. halfPi = pi / 2;
  55. function sinIn(t) {
  56. return (+t === 1) ? 1 : 1 - Math.cos(t * halfPi);
  57. }
  58. function sinOut(t) {
  59. return Math.sin(t * halfPi);
  60. }
  61. function sinInOut(t) {
  62. return (1 - Math.cos(pi * t)) / 2;
  63. }
  64. // tpmt is two power minus ten times t scaled to [0,1]
  65. function tpmt(x) {
  66. return (Math.pow(2, -10 * x) - 0.0009765625) * 1.0009775171065494;
  67. }
  68. function expIn(t) {
  69. return tpmt(1 - +t);
  70. }
  71. function expOut(t) {
  72. return 1 - tpmt(t);
  73. }
  74. function expInOut(t) {
  75. return ((t *= 2) <= 1 ? tpmt(1 - t) : 2 - tpmt(t - 1)) / 2;
  76. }
  77. function circleIn(t) {
  78. return 1 - Math.sqrt(1 - t * t);
  79. }
  80. function circleOut(t) {
  81. return Math.sqrt(1 - --t * t);
  82. }
  83. function circleInOut(t) {
  84. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  85. }
  86. var b1 = 4 / 11,
  87. b2 = 6 / 11,
  88. b3 = 8 / 11,
  89. b4 = 3 / 4,
  90. b5 = 9 / 11,
  91. b6 = 10 / 11,
  92. b7 = 15 / 16,
  93. b8 = 21 / 22,
  94. b9 = 63 / 64,
  95. b0 = 1 / b1 / b1;
  96. function bounceIn(t) {
  97. return 1 - bounceOut(1 - t);
  98. }
  99. function bounceOut(t) {
  100. return (t = +t) < b1 ? b0 * t * t : t < b3 ? b0 * (t -= b2) * t + b4 : t < b6 ? b0 * (t -= b5) * t + b7 : b0 * (t -= b8) * t + b9;
  101. }
  102. function bounceInOut(t) {
  103. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  104. }
  105. var overshoot = 1.70158;
  106. var backIn = (function custom(s) {
  107. s = +s;
  108. function backIn(t) {
  109. return (t = +t) * t * (s * (t - 1) + t);
  110. }
  111. backIn.overshoot = custom;
  112. return backIn;
  113. })(overshoot);
  114. var backOut = (function custom(s) {
  115. s = +s;
  116. function backOut(t) {
  117. return --t * t * ((t + 1) * s + t) + 1;
  118. }
  119. backOut.overshoot = custom;
  120. return backOut;
  121. })(overshoot);
  122. var backInOut = (function custom(s) {
  123. s = +s;
  124. function backInOut(t) {
  125. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  126. }
  127. backInOut.overshoot = custom;
  128. return backInOut;
  129. })(overshoot);
  130. var tau = 2 * Math.PI,
  131. amplitude = 1,
  132. period = 0.3;
  133. var elasticIn = (function custom(a, p) {
  134. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  135. function elasticIn(t) {
  136. return a * tpmt(-(--t)) * Math.sin((s - t) / p);
  137. }
  138. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  139. elasticIn.period = function(p) { return custom(a, p); };
  140. return elasticIn;
  141. })(amplitude, period);
  142. var elasticOut = (function custom(a, p) {
  143. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  144. function elasticOut(t) {
  145. return 1 - a * tpmt(t = +t) * Math.sin((t + s) / p);
  146. }
  147. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  148. elasticOut.period = function(p) { return custom(a, p); };
  149. return elasticOut;
  150. })(amplitude, period);
  151. var elasticInOut = (function custom(a, p) {
  152. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  153. function elasticInOut(t) {
  154. return ((t = t * 2 - 1) < 0
  155. ? a * tpmt(-t) * Math.sin((s - t) / p)
  156. : 2 - a * tpmt(t) * Math.sin((s + t) / p)) / 2;
  157. }
  158. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  159. elasticInOut.period = function(p) { return custom(a, p); };
  160. return elasticInOut;
  161. })(amplitude, period);
  162. exports.easeBack = backInOut;
  163. exports.easeBackIn = backIn;
  164. exports.easeBackInOut = backInOut;
  165. exports.easeBackOut = backOut;
  166. exports.easeBounce = bounceOut;
  167. exports.easeBounceIn = bounceIn;
  168. exports.easeBounceInOut = bounceInOut;
  169. exports.easeBounceOut = bounceOut;
  170. exports.easeCircle = circleInOut;
  171. exports.easeCircleIn = circleIn;
  172. exports.easeCircleInOut = circleInOut;
  173. exports.easeCircleOut = circleOut;
  174. exports.easeCubic = cubicInOut;
  175. exports.easeCubicIn = cubicIn;
  176. exports.easeCubicInOut = cubicInOut;
  177. exports.easeCubicOut = cubicOut;
  178. exports.easeElastic = elasticOut;
  179. exports.easeElasticIn = elasticIn;
  180. exports.easeElasticInOut = elasticInOut;
  181. exports.easeElasticOut = elasticOut;
  182. exports.easeExp = expInOut;
  183. exports.easeExpIn = expIn;
  184. exports.easeExpInOut = expInOut;
  185. exports.easeExpOut = expOut;
  186. exports.easeLinear = linear;
  187. exports.easePoly = polyInOut;
  188. exports.easePolyIn = polyIn;
  189. exports.easePolyInOut = polyInOut;
  190. exports.easePolyOut = polyOut;
  191. exports.easeQuad = quadInOut;
  192. exports.easeQuadIn = quadIn;
  193. exports.easeQuadInOut = quadInOut;
  194. exports.easeQuadOut = quadOut;
  195. exports.easeSin = sinInOut;
  196. exports.easeSinIn = sinIn;
  197. exports.easeSinInOut = sinInOut;
  198. exports.easeSinOut = sinOut;
  199. Object.defineProperty(exports, '__esModule', { value: true });
  200. }));