1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
3 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
4 | (global = global || self, factory(global.window = global.window || {}));
|
5 | }(this, (function (exports) { 'use strict';
|
6 |
|
7 | |
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | var gsap,
|
17 | _registerEase,
|
18 | _getGSAP = function _getGSAP() {
|
19 | return gsap || typeof window !== "undefined" && (gsap = window.gsap) && gsap.registerPlugin && gsap;
|
20 | },
|
21 | _boolean = function _boolean(value, defaultValue) {
|
22 | return !!(typeof value === "undefined" ? defaultValue : value && !~(value + "").indexOf("false"));
|
23 | },
|
24 | _initCore = function _initCore(core) {
|
25 | gsap = core || _getGSAP();
|
26 |
|
27 | if (gsap) {
|
28 | _registerEase = gsap.registerEase;
|
29 |
|
30 | var eases = gsap.parseEase(),
|
31 | createConfig = function createConfig(ease) {
|
32 | return function (ratio) {
|
33 | var y = 0.5 + ratio / 2;
|
34 |
|
35 | ease.config = function (p) {
|
36 | return ease(2 * (1 - p) * p * y + p * p);
|
37 | };
|
38 | };
|
39 | },
|
40 | p;
|
41 |
|
42 | for (p in eases) {
|
43 | if (!eases[p].config) {
|
44 | createConfig(eases[p]);
|
45 | }
|
46 | }
|
47 |
|
48 | _registerEase("slow", SlowMo);
|
49 |
|
50 | _registerEase("expoScale", ExpoScaleEase);
|
51 |
|
52 | _registerEase("rough", RoughEase);
|
53 |
|
54 | for (p in EasePack) {
|
55 | p !== "version" && gsap.core.globals(p, EasePack[p]);
|
56 | }
|
57 | }
|
58 | },
|
59 | _createSlowMo = function _createSlowMo(linearRatio, power, yoyoMode) {
|
60 | linearRatio = Math.min(1, linearRatio || 0.7);
|
61 |
|
62 | var pow = linearRatio < 1 ? power || power === 0 ? power : 0.7 : 0,
|
63 | p1 = (1 - linearRatio) / 2,
|
64 | p3 = p1 + linearRatio,
|
65 | calcEnd = _boolean(yoyoMode);
|
66 |
|
67 | return function (p) {
|
68 | var r = p + (0.5 - p) * pow;
|
69 | 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;
|
70 | };
|
71 | },
|
72 | _createExpoScale = function _createExpoScale(start, end, ease) {
|
73 | var p1 = Math.log(end / start),
|
74 | p2 = end - start;
|
75 | ease && (ease = gsap.parseEase(ease));
|
76 | return function (p) {
|
77 | return (start * Math.exp(p1 * (ease ? ease(p) : p)) - start) / p2;
|
78 | };
|
79 | },
|
80 | EasePoint = function EasePoint(time, value, next) {
|
81 | this.t = time;
|
82 | this.v = value;
|
83 |
|
84 | if (next) {
|
85 | this.next = next;
|
86 | next.prev = this;
|
87 | this.c = next.v - value;
|
88 | this.gap = next.t - time;
|
89 | }
|
90 | },
|
91 | _createRoughEase = function _createRoughEase(vars) {
|
92 | if (typeof vars !== "object") {
|
93 | vars = {
|
94 | points: +vars || 20
|
95 | };
|
96 | }
|
97 |
|
98 | var taper = vars.taper || "none",
|
99 | a = [],
|
100 | cnt = 0,
|
101 | points = (+vars.points || 20) | 0,
|
102 | i = points,
|
103 | randomize = _boolean(vars.randomize, true),
|
104 | clamp = _boolean(vars.clamp),
|
105 | template = gsap ? gsap.parseEase(vars.template) : 0,
|
106 | strength = (+vars.strength || 1) * 0.4,
|
107 | x,
|
108 | y,
|
109 | bump,
|
110 | invX,
|
111 | obj,
|
112 | pnt,
|
113 | recent;
|
114 |
|
115 | while (--i > -1) {
|
116 | x = randomize ? Math.random() : 1 / points * i;
|
117 | y = template ? template(x) : x;
|
118 |
|
119 | if (taper === "none") {
|
120 | bump = strength;
|
121 | } else if (taper === "out") {
|
122 | invX = 1 - x;
|
123 | bump = invX * invX * strength;
|
124 | } else if (taper === "in") {
|
125 | bump = x * x * strength;
|
126 | } else if (x < 0.5) {
|
127 | invX = x * 2;
|
128 | bump = invX * invX * 0.5 * strength;
|
129 | } else {
|
130 | invX = (1 - x) * 2;
|
131 | bump = invX * invX * 0.5 * strength;
|
132 | }
|
133 |
|
134 | if (randomize) {
|
135 | y += Math.random() * bump - bump * 0.5;
|
136 | } else if (i % 2) {
|
137 | y += bump * 0.5;
|
138 | } else {
|
139 | y -= bump * 0.5;
|
140 | }
|
141 |
|
142 | if (clamp) {
|
143 | if (y > 1) {
|
144 | y = 1;
|
145 | } else if (y < 0) {
|
146 | y = 0;
|
147 | }
|
148 | }
|
149 |
|
150 | a[cnt++] = {
|
151 | x: x,
|
152 | y: y
|
153 | };
|
154 | }
|
155 |
|
156 | a.sort(function (a, b) {
|
157 | return a.x - b.x;
|
158 | });
|
159 | pnt = new EasePoint(1, 1, null);
|
160 | i = points;
|
161 |
|
162 | while (i--) {
|
163 | obj = a[i];
|
164 | pnt = new EasePoint(obj.x, obj.y, pnt);
|
165 | }
|
166 |
|
167 | recent = new EasePoint(0, 0, pnt.t ? pnt : pnt.next);
|
168 | return function (p) {
|
169 | var pnt = recent;
|
170 |
|
171 | if (p > pnt.t) {
|
172 | while (pnt.next && p >= pnt.t) {
|
173 | pnt = pnt.next;
|
174 | }
|
175 |
|
176 | pnt = pnt.prev;
|
177 | } else {
|
178 | while (pnt.prev && p <= pnt.t) {
|
179 | pnt = pnt.prev;
|
180 | }
|
181 | }
|
182 |
|
183 | recent = pnt;
|
184 | return pnt.v + (p - pnt.t) / pnt.gap * pnt.c;
|
185 | };
|
186 | };
|
187 |
|
188 | var SlowMo = _createSlowMo(0.7);
|
189 | SlowMo.ease = SlowMo;
|
190 | SlowMo.config = _createSlowMo;
|
191 | var ExpoScaleEase = _createExpoScale(1, 2);
|
192 | ExpoScaleEase.config = _createExpoScale;
|
193 | var RoughEase = _createRoughEase();
|
194 | RoughEase.ease = RoughEase;
|
195 | RoughEase.config = _createRoughEase;
|
196 | var EasePack = {
|
197 | SlowMo: SlowMo,
|
198 | RoughEase: RoughEase,
|
199 | ExpoScaleEase: ExpoScaleEase
|
200 | };
|
201 |
|
202 | for (var p in EasePack) {
|
203 | EasePack[p].register = _initCore;
|
204 | EasePack[p].version = "3.5.1";
|
205 | }
|
206 |
|
207 | _getGSAP() && gsap.registerPlugin(SlowMo);
|
208 |
|
209 | exports.EasePack = EasePack;
|
210 | exports.ExpoScaleEase = ExpoScaleEase;
|
211 | exports.RoughEase = RoughEase;
|
212 | exports.SlowMo = SlowMo;
|
213 | exports.default = EasePack;
|
214 |
|
215 | Object.defineProperty(exports, '__esModule', { value: true });
|
216 |
|
217 | })));
|