d738e2986e5a791450d29760fa396119dce4a920f3e8b7c1b6d136c5e7cd654220daa8486d0aaccb7f70bb043be8f16c24b306904e2325835f27c17e73e358 798 B

123456789101112131415161718192021222324252627
  1. import { cubicAt, cubicRootAt } from '../core/curve';
  2. import { trim } from '../core/util';
  3. const regexp = /cubic-bezier\(([0-9,\.e ]+)\)/;
  4. export function createCubicEasingFunc(cubicEasingStr: string) {
  5. const cubic = cubicEasingStr && regexp.exec(cubicEasingStr);
  6. if (cubic) {
  7. const points = cubic[1].split(',');
  8. const a = +trim(points[0]);
  9. const b = +trim(points[1]);
  10. const c = +trim(points[2]);
  11. const d = +trim(points[3]);
  12. if (isNaN(a + b + c + d)) {
  13. return;
  14. }
  15. const roots: number[] = [];
  16. return (p: number) => {
  17. return p <= 0
  18. ? 0 : p >= 1
  19. ? 1
  20. : cubicRootAt(0, a, c, 1, p, roots) && cubicAt(0, b, d, 1, roots[0]);
  21. };
  22. }
  23. }