UNPKG

9.43 kBJavaScriptView Raw
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 * EaselPlugin 3.10.3
9 * https://greensock.com
10 *
11 * @license Copyright 2008-2022, GreenSock. All rights reserved.
12 * Subject to the terms at https://greensock.com/standard-license or for
13 * Club GreenSock members, the agreement issued with that membership.
14 * @author: Jack Doyle, jack@greensock.com
15 */
16 var gsap,
17 _coreInitted,
18 _win,
19 _createJS,
20 _ColorFilter,
21 _ColorMatrixFilter,
22 _colorProps = "redMultiplier,greenMultiplier,blueMultiplier,alphaMultiplier,redOffset,greenOffset,blueOffset,alphaOffset".split(","),
23 _windowExists = function _windowExists() {
24 return typeof window !== "undefined";
25 },
26 _getGSAP = function _getGSAP() {
27 return gsap || _windowExists() && (gsap = window.gsap) && gsap.registerPlugin && gsap;
28 },
29 _getCreateJS = function _getCreateJS() {
30 return _createJS || _win && _win.createjs || _win || {};
31 },
32 _warn = function _warn(message) {
33 return console.warn(message);
34 },
35 _cache = function _cache(target) {
36 var b = target.getBounds && target.getBounds();
37
38 if (!b) {
39 b = target.nominalBounds || {
40 x: 0,
41 y: 0,
42 width: 100,
43 height: 100
44 };
45 target.setBounds && target.setBounds(b.x, b.y, b.width, b.height);
46 }
47
48 target.cache && target.cache(b.x, b.y, b.width, b.height);
49
50 _warn("EaselPlugin: for filters to display in EaselJS, you must call the object's cache() method first. GSAP attempted to use the target's getBounds() for the cache but that may not be completely accurate. " + target);
51 },
52 _parseColorFilter = function _parseColorFilter(target, v, plugin) {
53 if (!_ColorFilter) {
54 _ColorFilter = _getCreateJS().ColorFilter;
55
56 if (!_ColorFilter) {
57 _warn("EaselPlugin error: The EaselJS ColorFilter JavaScript file wasn't loaded.");
58 }
59 }
60
61 var filters = target.filters || [],
62 i = filters.length,
63 c,
64 s,
65 e,
66 a,
67 p,
68 pt;
69
70 while (i--) {
71 if (filters[i] instanceof _ColorFilter) {
72 s = filters[i];
73 break;
74 }
75 }
76
77 if (!s) {
78 s = new _ColorFilter();
79 filters.push(s);
80 target.filters = filters;
81 }
82
83 e = s.clone();
84
85 if (v.tint != null) {
86 c = gsap.utils.splitColor(v.tint);
87 a = v.tintAmount != null ? +v.tintAmount : 1;
88 e.redOffset = +c[0] * a;
89 e.greenOffset = +c[1] * a;
90 e.blueOffset = +c[2] * a;
91 e.redMultiplier = e.greenMultiplier = e.blueMultiplier = 1 - a;
92 } else {
93 for (p in v) {
94 if (p !== "exposure") if (p !== "brightness") {
95 e[p] = +v[p];
96 }
97 }
98 }
99
100 if (v.exposure != null) {
101 e.redOffset = e.greenOffset = e.blueOffset = 255 * (+v.exposure - 1);
102 e.redMultiplier = e.greenMultiplier = e.blueMultiplier = 1;
103 } else if (v.brightness != null) {
104 a = +v.brightness - 1;
105 e.redOffset = e.greenOffset = e.blueOffset = a > 0 ? a * 255 : 0;
106 e.redMultiplier = e.greenMultiplier = e.blueMultiplier = 1 - Math.abs(a);
107 }
108
109 i = 8;
110
111 while (i--) {
112 p = _colorProps[i];
113
114 if (s[p] !== e[p]) {
115 pt = plugin.add(s, p, s[p], e[p]);
116
117 if (pt) {
118 pt.op = "easel_colorFilter";
119 }
120 }
121 }
122
123 plugin._props.push("easel_colorFilter");
124
125 if (!target.cacheID) {
126 _cache(target);
127 }
128 },
129 _idMatrix = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0],
130 _lumR = 0.212671,
131 _lumG = 0.715160,
132 _lumB = 0.072169,
133 _applyMatrix = function _applyMatrix(m, m2) {
134 if (!(m instanceof Array) || !(m2 instanceof Array)) {
135 return m2;
136 }
137
138 var temp = [],
139 i = 0,
140 z = 0,
141 y,
142 x;
143
144 for (y = 0; y < 4; y++) {
145 for (x = 0; x < 5; x++) {
146 z = x === 4 ? m[i + 4] : 0;
147 temp[i + x] = m[i] * m2[x] + m[i + 1] * m2[x + 5] + m[i + 2] * m2[x + 10] + m[i + 3] * m2[x + 15] + z;
148 }
149
150 i += 5;
151 }
152
153 return temp;
154 },
155 _setSaturation = function _setSaturation(m, n) {
156 if (isNaN(n)) {
157 return m;
158 }
159
160 var inv = 1 - n,
161 r = inv * _lumR,
162 g = inv * _lumG,
163 b = inv * _lumB;
164 return _applyMatrix([r + n, g, b, 0, 0, r, g + n, b, 0, 0, r, g, b + n, 0, 0, 0, 0, 0, 1, 0], m);
165 },
166 _colorize = function _colorize(m, color, amount) {
167 if (isNaN(amount)) {
168 amount = 1;
169 }
170
171 var c = gsap.utils.splitColor(color),
172 r = c[0] / 255,
173 g = c[1] / 255,
174 b = c[2] / 255,
175 inv = 1 - amount;
176 return _applyMatrix([inv + amount * r * _lumR, amount * r * _lumG, amount * r * _lumB, 0, 0, amount * g * _lumR, inv + amount * g * _lumG, amount * g * _lumB, 0, 0, amount * b * _lumR, amount * b * _lumG, inv + amount * b * _lumB, 0, 0, 0, 0, 0, 1, 0], m);
177 },
178 _setHue = function _setHue(m, n) {
179 if (isNaN(n)) {
180 return m;
181 }
182
183 n *= Math.PI / 180;
184 var c = Math.cos(n),
185 s = Math.sin(n);
186 return _applyMatrix([_lumR + c * (1 - _lumR) + s * -_lumR, _lumG + c * -_lumG + s * -_lumG, _lumB + c * -_lumB + s * (1 - _lumB), 0, 0, _lumR + c * -_lumR + s * 0.143, _lumG + c * (1 - _lumG) + s * 0.14, _lumB + c * -_lumB + s * -0.283, 0, 0, _lumR + c * -_lumR + s * -(1 - _lumR), _lumG + c * -_lumG + s * _lumG, _lumB + c * (1 - _lumB) + s * _lumB, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1], m);
187 },
188 _setContrast = function _setContrast(m, n) {
189 if (isNaN(n)) {
190 return m;
191 }
192
193 n += 0.01;
194 return _applyMatrix([n, 0, 0, 0, 128 * (1 - n), 0, n, 0, 0, 128 * (1 - n), 0, 0, n, 0, 128 * (1 - n), 0, 0, 0, 1, 0], m);
195 },
196 _parseColorMatrixFilter = function _parseColorMatrixFilter(target, v, plugin) {
197 if (!_ColorMatrixFilter) {
198 _ColorMatrixFilter = _getCreateJS().ColorMatrixFilter;
199
200 if (!_ColorMatrixFilter) {
201 _warn("EaselPlugin: The EaselJS ColorMatrixFilter JavaScript file wasn't loaded.");
202 }
203 }
204
205 var filters = target.filters || [],
206 i = filters.length,
207 matrix,
208 startMatrix,
209 s,
210 pg;
211
212 while (--i > -1) {
213 if (filters[i] instanceof _ColorMatrixFilter) {
214 s = filters[i];
215 break;
216 }
217 }
218
219 if (!s) {
220 s = new _ColorMatrixFilter(_idMatrix.slice());
221 filters.push(s);
222 target.filters = filters;
223 }
224
225 startMatrix = s.matrix;
226 matrix = _idMatrix.slice();
227
228 if (v.colorize != null) {
229 matrix = _colorize(matrix, v.colorize, Number(v.colorizeAmount));
230 }
231
232 if (v.contrast != null) {
233 matrix = _setContrast(matrix, Number(v.contrast));
234 }
235
236 if (v.hue != null) {
237 matrix = _setHue(matrix, Number(v.hue));
238 }
239
240 if (v.saturation != null) {
241 matrix = _setSaturation(matrix, Number(v.saturation));
242 }
243
244 i = matrix.length;
245
246 while (--i > -1) {
247 if (matrix[i] !== startMatrix[i]) {
248 pg = plugin.add(startMatrix, i, startMatrix[i], matrix[i]);
249
250 if (pg) {
251 pg.op = "easel_colorMatrixFilter";
252 }
253 }
254 }
255
256 plugin._props.push("easel_colorMatrixFilter");
257
258 if (!target.cacheID) {
259 _cache();
260 }
261
262 plugin._matrix = startMatrix;
263 },
264 _initCore = function _initCore(core) {
265 gsap = core || _getGSAP();
266
267 if (_windowExists()) {
268 _win = window;
269 }
270
271 if (gsap) {
272 _coreInitted = 1;
273 }
274 };
275
276 var EaselPlugin = {
277 version: "3.10.3",
278 name: "easel",
279 init: function init(target, value, tween, index, targets) {
280 if (!_coreInitted) {
281 _initCore();
282
283 if (!gsap) {
284 _warn("Please gsap.registerPlugin(EaselPlugin)");
285 }
286 }
287
288 this.target = target;
289 var p, pt, tint, colorMatrix, end, labels, i;
290
291 for (p in value) {
292 end = value[p];
293
294 if (p === "colorFilter" || p === "tint" || p === "tintAmount" || p === "exposure" || p === "brightness") {
295 if (!tint) {
296 _parseColorFilter(target, value.colorFilter || value, this);
297
298 tint = true;
299 }
300 } else if (p === "saturation" || p === "contrast" || p === "hue" || p === "colorize" || p === "colorizeAmount") {
301 if (!colorMatrix) {
302 _parseColorMatrixFilter(target, value.colorMatrixFilter || value, this);
303
304 colorMatrix = true;
305 }
306 } else if (p === "frame") {
307 if (typeof end === "string" && end.charAt(1) !== "=" && (labels = target.labels)) {
308 for (i = 0; i < labels.length; i++) {
309 if (labels[i].label === end) {
310 end = labels[i].position;
311 }
312 }
313 }
314
315 pt = this.add(target, "gotoAndStop", target.currentFrame, end, index, targets, Math.round);
316
317 if (pt) {
318 pt.op = p;
319 }
320 } else if (target[p] != null) {
321 this.add(target, p, "get", end);
322 }
323 }
324 },
325 render: function render(ratio, data) {
326 var pt = data._pt;
327
328 while (pt) {
329 pt.r(ratio, pt.d);
330 pt = pt._next;
331 }
332
333 if (data.target.cacheID) {
334 data.target.updateCache();
335 }
336 },
337 register: _initCore
338 };
339
340 EaselPlugin.registerCreateJS = function (createjs) {
341 _createJS = createjs;
342 };
343
344 _getGSAP() && gsap.registerPlugin(EaselPlugin);
345
346 exports.EaselPlugin = EaselPlugin;
347 exports.default = EaselPlugin;
348
349 Object.defineProperty(exports, '__esModule', { value: true });
350
351})));