UNPKG

4.8 kBJavaScriptView Raw
1/*!
2 * EasePack 3.10.3
3 * https://greensock.com
4 *
5 * @license Copyright 2008-2022, GreenSock. All rights reserved.
6 * Subject to the terms at https://greensock.com/standard-license or for
7 * Club GreenSock members, the agreement issued with that membership.
8 * @author: Jack Doyle, jack@greensock.com
9*/
10/* eslint-disable */
11
12let gsap, _coreInitted, _registerEase,
13 _getGSAP = () => gsap || (typeof(window) !== "undefined" && (gsap = window.gsap) && gsap.registerPlugin && gsap),
14 _boolean = (value, defaultValue) => !!(typeof(value) === "undefined" ? defaultValue : value && !~((value + "").indexOf("false"))),
15 _initCore = core => {
16 gsap = core || _getGSAP();
17 if (gsap) {
18 _registerEase = gsap.registerEase;
19 //add weighted ease capabilities to standard eases so users can do "power2.inOut(0.8)" for example to push everything toward the "out", or (-0.8) to push it toward the "in" (0 is neutral)
20 let eases = gsap.parseEase(),
21 createConfig = ease => ratio => {
22 let y = 0.5 + ratio / 2;
23 ease.config = p => ease(2 * (1 - p) * p * y + p * p);
24 },
25 p;
26 for (p in eases) {
27 if (!eases[p].config) {
28 createConfig(eases[p]);
29 }
30 }
31 _registerEase("slow", SlowMo);
32 _registerEase("expoScale", ExpoScaleEase);
33 _registerEase("rough", RoughEase);
34 for (p in EasePack) {
35 p !== "version" && gsap.core.globals(p, EasePack[p]);
36 }
37 _coreInitted = 1;
38 }
39 },
40 _createSlowMo = (linearRatio, power, yoyoMode) => {
41 linearRatio = Math.min(1, linearRatio || 0.7);
42 let pow = linearRatio < 1 ? ((power || power === 0) ? power : 0.7) : 0,
43 p1 = (1 - linearRatio) / 2,
44 p3 = p1 + linearRatio,
45 calcEnd = _boolean(yoyoMode);
46 return p => {
47 let r = p + (0.5 - p) * pow;
48 return (p < p1) ? (calcEnd ? 1 - ((p = 1 - (p / p1)) * p) : r - ((p = 1 - (p / p1)) * p * p * p * r)) : (p > p3) ? (calcEnd ? (p === 1 ? 0 : 1 - (p = (p - p3) / p1) * p) : r + ((p - r) * (p = (p - p3) / p1) * p * p * p)) : (calcEnd ? 1 : r);
49 }
50 },
51 _createExpoScale = (start, end, ease) => {
52 let p1 = Math.log(end / start),
53 p2 = end - start;
54 ease && (ease = gsap.parseEase(ease));
55 return p => (start * Math.exp(p1 * (ease ? ease(p) : p)) - start) / p2;
56 },
57 EasePoint = function(time, value, next) {
58 this.t = time;
59 this.v = value;
60 if (next) {
61 this.next = next;
62 next.prev = this;
63 this.c = next.v - value;
64 this.gap = next.t - time;
65 }
66 },
67 _createRoughEase = vars => {
68 if (typeof(vars) !== "object") { //users may pass in via a string, like "rough(30)"
69 vars = {points: +vars || 20};
70 }
71 let taper = vars.taper || "none",
72 a = [],
73 cnt = 0,
74 points = (+vars.points || 20) | 0,
75 i = points,
76 randomize = _boolean(vars.randomize, true),
77 clamp = _boolean(vars.clamp),
78 template = gsap ? gsap.parseEase(vars.template) : 0,
79 strength = (+vars.strength || 1) * 0.4,
80 x, y, bump, invX, obj, pnt, recent;
81 while (--i > -1) {
82 x = randomize ? Math.random() : (1 / points) * i;
83 y = template ? template(x) : x;
84 if (taper === "none") {
85 bump = strength;
86 } else if (taper === "out") {
87 invX = 1 - x;
88 bump = invX * invX * strength;
89 } else if (taper === "in") {
90 bump = x * x * strength;
91 } else if (x < 0.5) { //"both" (start)
92 invX = x * 2;
93 bump = invX * invX * 0.5 * strength;
94 } else { //"both" (end)
95 invX = (1 - x) * 2;
96 bump = invX * invX * 0.5 * strength;
97 }
98 if (randomize) {
99 y += (Math.random() * bump) - (bump * 0.5);
100 } else if (i % 2) {
101 y += bump * 0.5;
102 } else {
103 y -= bump * 0.5;
104 }
105 if (clamp) {
106 if (y > 1) {
107 y = 1;
108 } else if (y < 0) {
109 y = 0;
110 }
111 }
112 a[cnt++] = {x:x, y:y};
113 }
114 a.sort((a, b) => a.x - b.x);
115 pnt = new EasePoint(1, 1, null);
116 i = points;
117 while (i--) {
118 obj = a[i];
119 pnt = new EasePoint(obj.x, obj.y, pnt);
120 }
121 recent = new EasePoint(0, 0, pnt.t ? pnt : pnt.next);
122 return p => {
123 let pnt = recent;
124 if (p > pnt.t) {
125 while (pnt.next && p >= pnt.t) {
126 pnt = pnt.next;
127 }
128 pnt = pnt.prev;
129 } else {
130 while (pnt.prev && p <= pnt.t) {
131 pnt = pnt.prev;
132 }
133 }
134 recent = pnt;
135 return pnt.v + ((p - pnt.t) / pnt.gap) * pnt.c;
136 };
137 };
138
139export const SlowMo = _createSlowMo(0.7);
140SlowMo.ease = SlowMo; //for backward compatibility
141SlowMo.config = _createSlowMo;
142
143export const ExpoScaleEase = _createExpoScale(1, 2);
144ExpoScaleEase.config = _createExpoScale;
145
146export const RoughEase = _createRoughEase();
147RoughEase.ease = RoughEase; //for backward compatibility
148RoughEase.config = _createRoughEase;
149
150export const EasePack = {
151 SlowMo: SlowMo,
152 RoughEase: RoughEase,
153 ExpoScaleEase: ExpoScaleEase
154};
155
156for (let p in EasePack) {
157 EasePack[p].register = _initCore;
158 EasePack[p].version = "3.10.3";
159}
160
161_getGSAP() && gsap.registerPlugin(SlowMo);
162
163export { EasePack as default };
\No newline at end of file