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 | var _doc,
|
8 | _win,
|
9 | _docElement,
|
10 | _body,
|
11 | _divContainer,
|
12 | _svgContainer,
|
13 | _identityMatrix,
|
14 | _gEl,
|
15 | _transformProp = "transform",
|
16 | _transformOriginProp = _transformProp + "Origin",
|
17 | _hasOffsetBug,
|
18 | _setDoc = function _setDoc(element) {
|
19 | var doc = element.ownerDocument || element;
|
20 |
|
21 | if (!(_transformProp in element.style) && "msTransform" in element.style) {
|
22 | _transformProp = "msTransform";
|
23 | _transformOriginProp = _transformProp + "Origin";
|
24 | }
|
25 |
|
26 | while (doc.parentNode && (doc = doc.parentNode)) {}
|
27 |
|
28 | _win = window;
|
29 | _identityMatrix = new Matrix2D();
|
30 |
|
31 | if (doc) {
|
32 | _doc = doc;
|
33 | _docElement = doc.documentElement;
|
34 | _body = doc.body;
|
35 | _gEl = _doc.createElementNS("http://www.w3.org/2000/svg", "g");
|
36 | _gEl.style.transform = "none";
|
37 | var d1 = doc.createElement("div"),
|
38 | d2 = doc.createElement("div");
|
39 |
|
40 | _body.appendChild(d1);
|
41 |
|
42 | d1.appendChild(d2);
|
43 | d1.style.position = "static";
|
44 | d1.style[_transformProp] = "translate3d(0,0,1px)";
|
45 | _hasOffsetBug = d2.offsetParent !== d1;
|
46 |
|
47 | _body.removeChild(d1);
|
48 | }
|
49 |
|
50 | return doc;
|
51 | },
|
52 | _forceNonZeroScale = function _forceNonZeroScale(e) {
|
53 | var a, cache;
|
54 |
|
55 | while (e && e !== _body) {
|
56 | cache = e._gsap;
|
57 | cache && cache.uncache && cache.get(e, "x");
|
58 |
|
59 | if (cache && !cache.scaleX && !cache.scaleY && cache.renderTransform) {
|
60 | cache.scaleX = cache.scaleY = 1e-4;
|
61 | cache.renderTransform(1, cache);
|
62 | a ? a.push(cache) : a = [cache];
|
63 | }
|
64 |
|
65 | e = e.parentNode;
|
66 | }
|
67 |
|
68 | return a;
|
69 | },
|
70 | _svgTemps = [],
|
71 | _divTemps = [],
|
72 | _getDocScrollTop = function _getDocScrollTop() {
|
73 | return _win.pageYOffset || _doc.scrollTop || _docElement.scrollTop || _body.scrollTop || 0;
|
74 | },
|
75 | _getDocScrollLeft = function _getDocScrollLeft() {
|
76 | return _win.pageXOffset || _doc.scrollLeft || _docElement.scrollLeft || _body.scrollLeft || 0;
|
77 | },
|
78 | _svgOwner = function _svgOwner(element) {
|
79 | return element.ownerSVGElement || ((element.tagName + "").toLowerCase() === "svg" ? element : null);
|
80 | },
|
81 | _isFixed = function _isFixed(element) {
|
82 | if (_win.getComputedStyle(element).position === "fixed") {
|
83 | return true;
|
84 | }
|
85 |
|
86 | element = element.parentNode;
|
87 |
|
88 | if (element && element.nodeType === 1) {
|
89 | return _isFixed(element);
|
90 | }
|
91 | },
|
92 | _createSibling = function _createSibling(element, i) {
|
93 | if (element.parentNode && (_doc || _setDoc(element))) {
|
94 | var svg = _svgOwner(element),
|
95 | ns = svg ? svg.getAttribute("xmlns") || "http://www.w3.org/2000/svg" : "http://www.w3.org/1999/xhtml",
|
96 | type = svg ? i ? "rect" : "g" : "div",
|
97 | x = i !== 2 ? 0 : 100,
|
98 | y = i === 3 ? 100 : 0,
|
99 | css = "position:absolute;display:block;pointer-events:none;margin:0;padding:0;",
|
100 | e = _doc.createElementNS ? _doc.createElementNS(ns.replace(/^https/, "http"), type) : _doc.createElement(type);
|
101 |
|
102 | if (i) {
|
103 | if (!svg) {
|
104 | if (!_divContainer) {
|
105 | _divContainer = _createSibling(element);
|
106 | _divContainer.style.cssText = css;
|
107 | }
|
108 |
|
109 | e.style.cssText = css + "width:0.1px;height:0.1px;top:" + y + "px;left:" + x + "px";
|
110 |
|
111 | _divContainer.appendChild(e);
|
112 | } else {
|
113 | _svgContainer || (_svgContainer = _createSibling(element));
|
114 | e.setAttribute("width", 0.01);
|
115 | e.setAttribute("height", 0.01);
|
116 | e.setAttribute("transform", "translate(" + x + "," + y + ")");
|
117 |
|
118 | _svgContainer.appendChild(e);
|
119 | }
|
120 | }
|
121 |
|
122 | return e;
|
123 | }
|
124 |
|
125 | throw "Need document and parent.";
|
126 | },
|
127 | _consolidate = function _consolidate(m) {
|
128 | var c = new Matrix2D(),
|
129 | i = 0;
|
130 |
|
131 | for (; i < m.numberOfItems; i++) {
|
132 | c.multiply(m.getItem(i).matrix);
|
133 | }
|
134 |
|
135 | return c;
|
136 | },
|
137 | _getCTM = function _getCTM(svg) {
|
138 | var m = svg.getCTM(),
|
139 | transform;
|
140 |
|
141 | if (!m) {
|
142 | transform = svg.style[_transformProp];
|
143 | svg.style[_transformProp] = "none";
|
144 | svg.appendChild(_gEl);
|
145 | m = _gEl.getCTM();
|
146 | svg.removeChild(_gEl);
|
147 | transform ? svg.style[_transformProp] = transform : svg.style.removeProperty(_transformProp.replace(/([A-Z])/g, "-$1").toLowerCase());
|
148 | }
|
149 |
|
150 | return m || _identityMatrix.clone();
|
151 | },
|
152 | _placeSiblings = function _placeSiblings(element, adjustGOffset) {
|
153 | var svg = _svgOwner(element),
|
154 | isRootSVG = element === svg,
|
155 | siblings = svg ? _svgTemps : _divTemps,
|
156 | parent = element.parentNode,
|
157 | container,
|
158 | m,
|
159 | b,
|
160 | x,
|
161 | y,
|
162 | cs;
|
163 |
|
164 | if (element === _win) {
|
165 | return element;
|
166 | }
|
167 |
|
168 | siblings.length || siblings.push(_createSibling(element, 1), _createSibling(element, 2), _createSibling(element, 3));
|
169 | container = svg ? _svgContainer : _divContainer;
|
170 |
|
171 | if (svg) {
|
172 | if (isRootSVG) {
|
173 | b = _getCTM(element);
|
174 | x = -b.e / b.a;
|
175 | y = -b.f / b.d;
|
176 | m = _identityMatrix;
|
177 | } else if (element.getBBox) {
|
178 | b = element.getBBox();
|
179 | m = element.transform ? element.transform.baseVal : {};
|
180 | m = !m.numberOfItems ? _identityMatrix : m.numberOfItems > 1 ? _consolidate(m) : m.getItem(0).matrix;
|
181 | x = m.a * b.x + m.c * b.y;
|
182 | y = m.b * b.x + m.d * b.y;
|
183 | } else {
|
184 | m = new Matrix2D();
|
185 | x = y = 0;
|
186 | }
|
187 |
|
188 | if (adjustGOffset && element.tagName.toLowerCase() === "g") {
|
189 | x = y = 0;
|
190 | }
|
191 |
|
192 | (isRootSVG ? svg : parent).appendChild(container);
|
193 | container.setAttribute("transform", "matrix(" + m.a + "," + m.b + "," + m.c + "," + m.d + "," + (m.e + x) + "," + (m.f + y) + ")");
|
194 | } else {
|
195 | x = y = 0;
|
196 |
|
197 | if (_hasOffsetBug) {
|
198 | m = element.offsetParent;
|
199 | b = element;
|
200 |
|
201 | while (b && (b = b.parentNode) && b !== m && b.parentNode) {
|
202 | if ((_win.getComputedStyle(b)[_transformProp] + "").length > 4) {
|
203 | x = b.offsetLeft;
|
204 | y = b.offsetTop;
|
205 | b = 0;
|
206 | }
|
207 | }
|
208 | }
|
209 |
|
210 | cs = _win.getComputedStyle(element);
|
211 |
|
212 | if (cs.position !== "absolute" && cs.position !== "fixed") {
|
213 | m = element.offsetParent;
|
214 |
|
215 | while (parent && parent !== m) {
|
216 | x += parent.scrollLeft || 0;
|
217 | y += parent.scrollTop || 0;
|
218 | parent = parent.parentNode;
|
219 | }
|
220 | }
|
221 |
|
222 | b = container.style;
|
223 | b.top = element.offsetTop - y + "px";
|
224 | b.left = element.offsetLeft - x + "px";
|
225 | b[_transformProp] = cs[_transformProp];
|
226 | b[_transformOriginProp] = cs[_transformOriginProp];
|
227 | b.position = cs.position === "fixed" ? "fixed" : "absolute";
|
228 | element.parentNode.appendChild(container);
|
229 | }
|
230 |
|
231 | return container;
|
232 | },
|
233 | _setMatrix = function _setMatrix(m, a, b, c, d, e, f) {
|
234 | m.a = a;
|
235 | m.b = b;
|
236 | m.c = c;
|
237 | m.d = d;
|
238 | m.e = e;
|
239 | m.f = f;
|
240 | return m;
|
241 | };
|
242 |
|
243 | var Matrix2D = function () {
|
244 | function Matrix2D(a, b, c, d, e, f) {
|
245 | if (a === void 0) {
|
246 | a = 1;
|
247 | }
|
248 |
|
249 | if (b === void 0) {
|
250 | b = 0;
|
251 | }
|
252 |
|
253 | if (c === void 0) {
|
254 | c = 0;
|
255 | }
|
256 |
|
257 | if (d === void 0) {
|
258 | d = 1;
|
259 | }
|
260 |
|
261 | if (e === void 0) {
|
262 | e = 0;
|
263 | }
|
264 |
|
265 | if (f === void 0) {
|
266 | f = 0;
|
267 | }
|
268 |
|
269 | _setMatrix(this, a, b, c, d, e, f);
|
270 | }
|
271 |
|
272 | var _proto = Matrix2D.prototype;
|
273 |
|
274 | _proto.inverse = function inverse() {
|
275 | var a = this.a,
|
276 | b = this.b,
|
277 | c = this.c,
|
278 | d = this.d,
|
279 | e = this.e,
|
280 | f = this.f,
|
281 | determinant = a * d - b * c || 1e-10;
|
282 | return _setMatrix(this, d / determinant, -b / determinant, -c / determinant, a / determinant, (c * f - d * e) / determinant, -(a * f - b * e) / determinant);
|
283 | };
|
284 |
|
285 | _proto.multiply = function multiply(matrix) {
|
286 | var a = this.a,
|
287 | b = this.b,
|
288 | c = this.c,
|
289 | d = this.d,
|
290 | e = this.e,
|
291 | f = this.f,
|
292 | a2 = matrix.a,
|
293 | b2 = matrix.c,
|
294 | c2 = matrix.b,
|
295 | d2 = matrix.d,
|
296 | e2 = matrix.e,
|
297 | f2 = matrix.f;
|
298 | return _setMatrix(this, a2 * a + c2 * c, a2 * b + c2 * d, b2 * a + d2 * c, b2 * b + d2 * d, e + e2 * a + f2 * c, f + e2 * b + f2 * d);
|
299 | };
|
300 |
|
301 | _proto.clone = function clone() {
|
302 | return new Matrix2D(this.a, this.b, this.c, this.d, this.e, this.f);
|
303 | };
|
304 |
|
305 | _proto.equals = function equals(matrix) {
|
306 | var a = this.a,
|
307 | b = this.b,
|
308 | c = this.c,
|
309 | d = this.d,
|
310 | e = this.e,
|
311 | f = this.f;
|
312 | return a === matrix.a && b === matrix.b && c === matrix.c && d === matrix.d && e === matrix.e && f === matrix.f;
|
313 | };
|
314 |
|
315 | _proto.apply = function apply(point, decoratee) {
|
316 | if (decoratee === void 0) {
|
317 | decoratee = {};
|
318 | }
|
319 |
|
320 | var x = point.x,
|
321 | y = point.y,
|
322 | a = this.a,
|
323 | b = this.b,
|
324 | c = this.c,
|
325 | d = this.d,
|
326 | e = this.e,
|
327 | f = this.f;
|
328 | decoratee.x = x * a + y * c + e || 0;
|
329 | decoratee.y = x * b + y * d + f || 0;
|
330 | return decoratee;
|
331 | };
|
332 |
|
333 | return Matrix2D;
|
334 | }();
|
335 | function getGlobalMatrix(element, inverse, adjustGOffset, includeScrollInFixed) {
|
336 | if (!element || !element.parentNode || (_doc || _setDoc(element)).documentElement === element) {
|
337 | return new Matrix2D();
|
338 | }
|
339 |
|
340 | var zeroScales = _forceNonZeroScale(element),
|
341 | svg = _svgOwner(element),
|
342 | temps = svg ? _svgTemps : _divTemps,
|
343 | container = _placeSiblings(element, adjustGOffset),
|
344 | b1 = temps[0].getBoundingClientRect(),
|
345 | b2 = temps[1].getBoundingClientRect(),
|
346 | b3 = temps[2].getBoundingClientRect(),
|
347 | parent = container.parentNode,
|
348 | isFixed = !includeScrollInFixed && _isFixed(element),
|
349 | m = new Matrix2D((b2.left - b1.left) / 100, (b2.top - b1.top) / 100, (b3.left - b1.left) / 100, (b3.top - b1.top) / 100, b1.left + (isFixed ? 0 : _getDocScrollLeft()), b1.top + (isFixed ? 0 : _getDocScrollTop()));
|
350 |
|
351 | parent.removeChild(container);
|
352 |
|
353 | if (zeroScales) {
|
354 | b1 = zeroScales.length;
|
355 |
|
356 | while (b1--) {
|
357 | b2 = zeroScales[b1];
|
358 | b2.scaleX = b2.scaleY = 0;
|
359 | b2.renderTransform(1, b2);
|
360 | }
|
361 | }
|
362 |
|
363 | return inverse ? m.inverse() : m;
|
364 | }
|
365 |
|
366 | |
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 | var _id = 1,
|
377 | _toArray,
|
378 | gsap,
|
379 | _batch,
|
380 | _batchAction,
|
381 | _body$1,
|
382 | _closestTenth,
|
383 | _forEachBatch = function _forEachBatch(batch, name) {
|
384 | return batch.actions.forEach(function (a) {
|
385 | return a.vars[name] && a.vars[name](a);
|
386 | });
|
387 | },
|
388 | _batchLookup = {},
|
389 | _RAD2DEG = 180 / Math.PI,
|
390 | _DEG2RAD = Math.PI / 180,
|
391 | _emptyObj = {},
|
392 | _dashedNameLookup = {},
|
393 | _memoizedRemoveProps = {},
|
394 | _listToArray = function _listToArray(list) {
|
395 | return typeof list === "string" ? list.split(" ").join("").split(",") : list;
|
396 | },
|
397 | _callbacks = _listToArray("onStart,onUpdate,onComplete,onReverseComplete,onInterrupt"),
|
398 | _removeProps = _listToArray("transform,transformOrigin,width,height,position,top,left,opacity,zIndex,maxWidth,maxHeight,minWidth,minHeight"),
|
399 | _getEl = function _getEl(target) {
|
400 | return _toArray(target)[0] || console.warn("Element not found:", target);
|
401 | },
|
402 | _round = function _round(value) {
|
403 | return Math.round(value * 10000) / 10000 || 0;
|
404 | },
|
405 | _toggleClass = function _toggleClass(targets, className, action) {
|
406 | return targets.forEach(function (el) {
|
407 | return el.classList[action](className);
|
408 | });
|
409 | },
|
410 | _reserved = {
|
411 | zIndex: 1,
|
412 | kill: 1,
|
413 | simple: 1,
|
414 | spin: 1,
|
415 | clearProps: 1,
|
416 | targets: 1,
|
417 | toggleClass: 1,
|
418 | onComplete: 1,
|
419 | onUpdate: 1,
|
420 | onInterrupt: 1,
|
421 | onStart: 1,
|
422 | delay: 1,
|
423 | repeat: 1,
|
424 | repeatDelay: 1,
|
425 | yoyo: 1,
|
426 | scale: 1,
|
427 | fade: 1,
|
428 | absolute: 1,
|
429 | props: 1,
|
430 | onEnter: 1,
|
431 | onLeave: 1,
|
432 | custom: 1,
|
433 | paused: 1,
|
434 | nested: 1,
|
435 | prune: 1,
|
436 | absoluteOnLeave: 1
|
437 | },
|
438 | _fitReserved = {
|
439 | zIndex: 1,
|
440 | simple: 1,
|
441 | clearProps: 1,
|
442 | scale: 1,
|
443 | absolute: 1,
|
444 | fitChild: 1,
|
445 | getVars: 1,
|
446 | props: 1
|
447 | },
|
448 | _camelToDashed = function _camelToDashed(p) {
|
449 | return p.replace(/([A-Z])/g, "-$1").toLowerCase();
|
450 | },
|
451 | _copy = function _copy(obj, exclude) {
|
452 | var result = {},
|
453 | p;
|
454 |
|
455 | for (p in obj) {
|
456 | exclude[p] || (result[p] = obj[p]);
|
457 | }
|
458 |
|
459 | return result;
|
460 | },
|
461 | _memoizedProps = {},
|
462 | _memoizeProps = function _memoizeProps(props) {
|
463 | var p = _memoizedProps[props] = _listToArray(props);
|
464 |
|
465 | _memoizedRemoveProps[props] = p.concat(_removeProps);
|
466 | return p;
|
467 | },
|
468 | _getInverseGlobalMatrix = function _getInverseGlobalMatrix(el) {
|
469 | var cache = el._gsap || gsap.core.getCache(el);
|
470 |
|
471 | if (cache.gmCache === gsap.ticker.frame) {
|
472 | return cache.gMatrix;
|
473 | }
|
474 |
|
475 | cache.gmCache = gsap.ticker.frame;
|
476 | return cache.gMatrix = getGlobalMatrix(el, true, false, true);
|
477 | },
|
478 | _getDOMDepth = function _getDOMDepth(el, invert, level) {
|
479 | if (level === void 0) {
|
480 | level = 0;
|
481 | }
|
482 |
|
483 | var parent = el.parentNode,
|
484 | inc = 1000 * Math.pow(10, level) * (invert ? -1 : 1),
|
485 | l = invert ? -inc * 900 : 0;
|
486 |
|
487 | while (el) {
|
488 | l += inc;
|
489 | el = el.previousSibling;
|
490 | }
|
491 |
|
492 | return parent ? l + _getDOMDepth(parent, invert, level + 1) : l;
|
493 | },
|
494 | _orderByDOMDepth = function _orderByDOMDepth(comps, invert, isElStates) {
|
495 | comps.forEach(function (comp) {
|
496 | return comp.d = _getDOMDepth(isElStates ? comp.element : comp.t, invert);
|
497 | });
|
498 | comps.sort(function (c1, c2) {
|
499 | return c1.d - c2.d;
|
500 | });
|
501 | return comps;
|
502 | },
|
503 | _recordInlineStyles = function _recordInlineStyles(elState, props) {
|
504 | var style = elState.element.style,
|
505 | a = elState.css = elState.css || [],
|
506 | i = props.length,
|
507 | p,
|
508 | v;
|
509 |
|
510 | while (i--) {
|
511 | p = props[i];
|
512 | v = style[p] || style.getPropertyValue(p);
|
513 | a.push(v ? p : _dashedNameLookup[p] || (_dashedNameLookup[p] = _camelToDashed(p)), v);
|
514 | }
|
515 |
|
516 | return style;
|
517 | },
|
518 | _applyInlineStyles = function _applyInlineStyles(state) {
|
519 | var css = state.css,
|
520 | style = state.element.style,
|
521 | i = 0;
|
522 | state.cache.uncache = 1;
|
523 |
|
524 | for (; i < css.length; i += 2) {
|
525 | css[i + 1] ? style[css[i]] = css[i + 1] : style.removeProperty(css[i]);
|
526 | }
|
527 | },
|
528 | _setFinalStates = function _setFinalStates(comps, onlyTransforms) {
|
529 | comps.forEach(function (c) {
|
530 | return c.a.cache.uncache = 1;
|
531 | });
|
532 | onlyTransforms || comps.finalStates.forEach(_applyInlineStyles);
|
533 | },
|
534 | _absoluteProps = "paddingTop,paddingRight,paddingBottom,paddingLeft,gridArea,transition".split(","),
|
535 | _makeAbsolute = function _makeAbsolute(elState, fallbackNode, ignoreBatch) {
|
536 | var element = elState.element,
|
537 | width = elState.width,
|
538 | height = elState.height,
|
539 | uncache = elState.uncache,
|
540 | getProp = elState.getProp,
|
541 | style = element.style,
|
542 | i = 4,
|
543 | result,
|
544 | displayIsNone,
|
545 | cs;
|
546 | typeof fallbackNode !== "object" && (fallbackNode = elState);
|
547 |
|
548 | if (_batch && ignoreBatch !== 1) {
|
549 | _batch._abs.push({
|
550 | t: element,
|
551 | b: elState,
|
552 | a: elState,
|
553 | sd: 0
|
554 | });
|
555 |
|
556 | _batch._final.push(function () {
|
557 | return (elState.cache.uncache = 1) && _applyInlineStyles(elState);
|
558 | });
|
559 |
|
560 | return element;
|
561 | }
|
562 |
|
563 | displayIsNone = getProp("display") === "none";
|
564 |
|
565 | if (!elState.isVisible || displayIsNone) {
|
566 | displayIsNone && (_recordInlineStyles(elState, ["display"]).display = fallbackNode.display);
|
567 | elState.matrix = fallbackNode.matrix;
|
568 | elState.width = width = elState.width || fallbackNode.width;
|
569 | elState.height = height = elState.height || fallbackNode.height;
|
570 | }
|
571 |
|
572 | _recordInlineStyles(elState, _absoluteProps);
|
573 |
|
574 | cs = window.getComputedStyle(element);
|
575 |
|
576 | while (i--) {
|
577 | style[_absoluteProps[i]] = cs[_absoluteProps[i]];
|
578 | }
|
579 |
|
580 | style.gridArea = "1 / 1 / 1 / 1";
|
581 | style.transition = "none";
|
582 | style.position = "absolute";
|
583 | style.width = width + "px";
|
584 | style.height = height + "px";
|
585 | style.top || (style.top = "0px");
|
586 | style.left || (style.left = "0px");
|
587 |
|
588 | if (uncache) {
|
589 | result = new ElementState(element);
|
590 | } else {
|
591 | result = _copy(elState, _emptyObj);
|
592 | result.position = "absolute";
|
593 |
|
594 | if (elState.simple) {
|
595 | var bounds = element.getBoundingClientRect();
|
596 | result.matrix = new Matrix2D(1, 0, 0, 1, bounds.left + _getDocScrollLeft(), bounds.top + _getDocScrollTop());
|
597 | } else {
|
598 | result.matrix = getGlobalMatrix(element, false, false, true);
|
599 | }
|
600 | }
|
601 |
|
602 | result = _fit(result, elState, true);
|
603 | elState.x = _closestTenth(result.x, 0.01);
|
604 | elState.y = _closestTenth(result.y, 0.01);
|
605 | return element;
|
606 | },
|
607 | _filterComps = function _filterComps(comps, targets) {
|
608 | if (targets !== true) {
|
609 | targets = _toArray(targets);
|
610 | comps = comps.filter(function (c) {
|
611 | if (targets.indexOf((c.sd < 0 ? c.b : c.a).element) !== -1) {
|
612 | return true;
|
613 | } else {
|
614 | c.t._gsap.renderTransform(1);
|
615 |
|
616 | c.t.style.width = c.b.width + "px";
|
617 | c.t.style.height = c.b.height + "px";
|
618 | }
|
619 | });
|
620 | }
|
621 |
|
622 | return comps;
|
623 | },
|
624 | _makeCompsAbsolute = function _makeCompsAbsolute(comps) {
|
625 | return _orderByDOMDepth(comps, true).forEach(function (c) {
|
626 | return (c.a.isVisible || c.b.isVisible) && _makeAbsolute(c.sd < 0 ? c.b : c.a, c.b, 1);
|
627 | });
|
628 | },
|
629 | _findElStateInState = function _findElStateInState(state, other) {
|
630 | return other && state.idLookup[_parseElementState(other).id] || state.elementStates[0];
|
631 | },
|
632 | _parseElementState = function _parseElementState(elOrNode, props, simple, other) {
|
633 | return elOrNode instanceof ElementState ? elOrNode : elOrNode instanceof FlipState ? _findElStateInState(elOrNode, other) : new ElementState(typeof elOrNode === "string" ? _getEl(elOrNode) || console.warn(elOrNode + " not found") : elOrNode, props, simple);
|
634 | },
|
635 | _recordProps = function _recordProps(elState, props) {
|
636 | var getProp = gsap.getProperty(elState.element, null, "native"),
|
637 | obj = elState.props = {},
|
638 | i = props.length;
|
639 |
|
640 | while (i--) {
|
641 | obj[props[i]] = (getProp(props[i]) + "").trim();
|
642 | }
|
643 |
|
644 | obj.zIndex && (obj.zIndex = parseFloat(obj.zIndex) || 0);
|
645 | return elState;
|
646 | },
|
647 | _applyProps = function _applyProps(element, props) {
|
648 | var style = element.style || element,
|
649 | p;
|
650 |
|
651 | for (p in props) {
|
652 | style[p] = props[p];
|
653 | }
|
654 | },
|
655 | _getID = function _getID(el) {
|
656 | var id = el.getAttribute("data-flip-id");
|
657 | id || el.setAttribute("data-flip-id", id = "auto-" + _id++);
|
658 | return id;
|
659 | },
|
660 | _elementsFromElementStates = function _elementsFromElementStates(elStates) {
|
661 | return elStates.map(function (elState) {
|
662 | return elState.element;
|
663 | });
|
664 | },
|
665 | _handleCallback = function _handleCallback(callback, elStates, tl) {
|
666 | return callback && elStates.length && tl.add(callback(_elementsFromElementStates(elStates), tl, new FlipState(elStates, 0, true)), 0);
|
667 | },
|
668 | _fit = function _fit(fromState, toState, scale, applyProps, fitChild, vars) {
|
669 | var element = fromState.element,
|
670 | cache = fromState.cache,
|
671 | parent = fromState.parent,
|
672 | x = fromState.x,
|
673 | y = fromState.y,
|
674 | width = toState.width,
|
675 | height = toState.height,
|
676 | scaleX = toState.scaleX,
|
677 | scaleY = toState.scaleY,
|
678 | rotation = toState.rotation,
|
679 | bounds = toState.bounds,
|
680 | cssText = vars && element.style.cssText,
|
681 | transform = vars && element.getBBox && element.getAttribute("transform"),
|
682 | dimensionState = fromState,
|
683 | _toState$matrix = toState.matrix,
|
684 | e = _toState$matrix.e,
|
685 | f = _toState$matrix.f,
|
686 | deep = fromState.bounds.width !== bounds.width || fromState.bounds.height !== bounds.height || fromState.scaleX !== scaleX || fromState.scaleY !== scaleY || fromState.rotation !== rotation,
|
687 | simple = !deep && fromState.simple && toState.simple && !fitChild,
|
688 | skewX,
|
689 | fromPoint,
|
690 | toPoint,
|
691 | getProp,
|
692 | parentMatrix,
|
693 | matrix,
|
694 | bbox;
|
695 |
|
696 | if (simple || !parent) {
|
697 | scaleX = scaleY = 1;
|
698 | rotation = skewX = 0;
|
699 | } else {
|
700 | parentMatrix = _getInverseGlobalMatrix(parent);
|
701 | matrix = parentMatrix.clone().multiply(toState.ctm ? toState.matrix.clone().multiply(toState.ctm) : toState.matrix);
|
702 | rotation = _round(Math.atan2(matrix.b, matrix.a) * _RAD2DEG);
|
703 | skewX = _round(Math.atan2(matrix.c, matrix.d) * _RAD2DEG + rotation) % 360;
|
704 | scaleX = Math.sqrt(Math.pow(matrix.a, 2) + Math.pow(matrix.b, 2));
|
705 | scaleY = Math.sqrt(Math.pow(matrix.c, 2) + Math.pow(matrix.d, 2)) * Math.cos(skewX * _DEG2RAD);
|
706 |
|
707 | if (fitChild) {
|
708 | fitChild = _toArray(fitChild)[0];
|
709 | getProp = gsap.getProperty(fitChild);
|
710 | bbox = fitChild.getBBox && typeof fitChild.getBBox === "function" && fitChild.getBBox();
|
711 | dimensionState = {
|
712 | scaleX: getProp("scaleX"),
|
713 | scaleY: getProp("scaleY"),
|
714 | width: bbox ? bbox.width : Math.ceil(parseFloat(getProp("width", "px"))),
|
715 | height: bbox ? bbox.height : parseFloat(getProp("height", "px"))
|
716 | };
|
717 | }
|
718 |
|
719 | cache.rotation = rotation + "deg";
|
720 | cache.skewX = skewX + "deg";
|
721 | }
|
722 |
|
723 | if (scale) {
|
724 | scaleX *= width === dimensionState.width || !dimensionState.width ? 1 : width / dimensionState.width;
|
725 | scaleY *= height === dimensionState.height || !dimensionState.height ? 1 : height / dimensionState.height;
|
726 | cache.scaleX = scaleX;
|
727 | cache.scaleY = scaleY;
|
728 | } else {
|
729 | width = _closestTenth(width * scaleX / dimensionState.scaleX, 0);
|
730 | height = _closestTenth(height * scaleY / dimensionState.scaleY, 0);
|
731 | element.style.width = width + "px";
|
732 | element.style.height = height + "px";
|
733 | }
|
734 |
|
735 | applyProps && _applyProps(element, toState.props);
|
736 |
|
737 | if (simple || !parent) {
|
738 | x += e - fromState.matrix.e;
|
739 | y += f - fromState.matrix.f;
|
740 | } else if (deep || parent !== toState.parent) {
|
741 | cache.renderTransform(1, cache);
|
742 | matrix = getGlobalMatrix(fitChild || element, false, false, true);
|
743 | fromPoint = parentMatrix.apply({
|
744 | x: matrix.e,
|
745 | y: matrix.f
|
746 | });
|
747 | toPoint = parentMatrix.apply({
|
748 | x: e,
|
749 | y: f
|
750 | });
|
751 | x += toPoint.x - fromPoint.x;
|
752 | y += toPoint.y - fromPoint.y;
|
753 | } else {
|
754 | parentMatrix.e = parentMatrix.f = 0;
|
755 | toPoint = parentMatrix.apply({
|
756 | x: e - fromState.matrix.e,
|
757 | y: f - fromState.matrix.f
|
758 | });
|
759 | x += toPoint.x;
|
760 | y += toPoint.y;
|
761 | }
|
762 |
|
763 | x = _closestTenth(x, 0.02);
|
764 | y = _closestTenth(y, 0.02);
|
765 |
|
766 | if (vars && !(vars instanceof ElementState)) {
|
767 | element.style.cssText = cssText;
|
768 | element.getBBox && element.setAttribute("transform", transform || "");
|
769 | cache.uncache = 1;
|
770 | } else {
|
771 | cache.x = x + "px";
|
772 | cache.y = y + "px";
|
773 | cache.renderTransform(1, cache);
|
774 | }
|
775 |
|
776 | if (vars) {
|
777 | vars.x = x;
|
778 | vars.y = y;
|
779 | vars.rotation = rotation;
|
780 | vars.skewX = skewX;
|
781 |
|
782 | if (scale) {
|
783 | vars.scaleX = scaleX;
|
784 | vars.scaleY = scaleY;
|
785 | } else {
|
786 | vars.width = width;
|
787 | vars.height = height;
|
788 | }
|
789 | }
|
790 |
|
791 | return vars || cache;
|
792 | },
|
793 | _parseState = function _parseState(targetsOrState, vars) {
|
794 | return targetsOrState instanceof FlipState ? targetsOrState : new FlipState(targetsOrState, vars);
|
795 | },
|
796 | _getChangingElState = function _getChangingElState(toState, fromState, id) {
|
797 | var to1 = toState.idLookup[id],
|
798 | to2 = toState.alt[id];
|
799 | return to2.isVisible && (!(fromState.getElementState(to2.element) || to2).isVisible || !to1.isVisible) ? to2 : to1;
|
800 | },
|
801 | _bodyMetrics = [],
|
802 | _bodyProps = "width,height,overflowX,overflowY".split(","),
|
803 | _bodyLocked,
|
804 | _lockBodyScroll = function _lockBodyScroll(lock) {
|
805 | if (lock !== _bodyLocked) {
|
806 | var s = _body$1.style,
|
807 | w = _body$1.clientWidth === window.outerWidth,
|
808 | h = _body$1.clientHeight === window.outerHeight,
|
809 | i = 4;
|
810 |
|
811 | if (lock && (w || h)) {
|
812 | while (i--) {
|
813 | _bodyMetrics[i] = s[_bodyProps[i]];
|
814 | }
|
815 |
|
816 | if (w) {
|
817 | s.width = _body$1.clientWidth + "px";
|
818 | s.overflowY = "hidden";
|
819 | }
|
820 |
|
821 | if (h) {
|
822 | s.height = _body$1.clientHeight + "px";
|
823 | s.overflowX = "hidden";
|
824 | }
|
825 |
|
826 | _bodyLocked = lock;
|
827 | } else if (_bodyLocked) {
|
828 | while (i--) {
|
829 | _bodyMetrics[i] ? s[_bodyProps[i]] = _bodyMetrics[i] : s.removeProperty(_camelToDashed(_bodyProps[i]));
|
830 | }
|
831 |
|
832 | _bodyLocked = lock;
|
833 | }
|
834 | }
|
835 | },
|
836 | _fromTo = function _fromTo(fromState, toState, vars, relative) {
|
837 | fromState instanceof FlipState && toState instanceof FlipState || console.warn("Not a valid state object.");
|
838 | vars = vars || {};
|
839 |
|
840 | var _vars = vars,
|
841 | clearProps = _vars.clearProps,
|
842 | onEnter = _vars.onEnter,
|
843 | onLeave = _vars.onLeave,
|
844 | absolute = _vars.absolute,
|
845 | absoluteOnLeave = _vars.absoluteOnLeave,
|
846 | custom = _vars.custom,
|
847 | delay = _vars.delay,
|
848 | paused = _vars.paused,
|
849 | repeat = _vars.repeat,
|
850 | repeatDelay = _vars.repeatDelay,
|
851 | yoyo = _vars.yoyo,
|
852 | toggleClass = _vars.toggleClass,
|
853 | nested = _vars.nested,
|
854 | _zIndex = _vars.zIndex,
|
855 | scale = _vars.scale,
|
856 | fade = _vars.fade,
|
857 | stagger = _vars.stagger,
|
858 | spin = _vars.spin,
|
859 | prune = _vars.prune,
|
860 | props = ("props" in vars ? vars : fromState).props,
|
861 | tweenVars = _copy(vars, _reserved),
|
862 | animation = gsap.timeline({
|
863 | delay: delay,
|
864 | paused: paused,
|
865 | repeat: repeat,
|
866 | repeatDelay: repeatDelay,
|
867 | yoyo: yoyo
|
868 | }),
|
869 | remainingProps = tweenVars,
|
870 | entering = [],
|
871 | leaving = [],
|
872 | comps = [],
|
873 | swapOutTargets = [],
|
874 | spinNum = spin === true ? 1 : spin || 0,
|
875 | spinFunc = typeof spin === "function" ? spin : function () {
|
876 | return spinNum;
|
877 | },
|
878 | interrupted = fromState.interrupted || toState.interrupted,
|
879 | addFunc = animation[relative !== 1 ? "to" : "from"],
|
880 | v,
|
881 | p,
|
882 | endTime,
|
883 | i,
|
884 | el,
|
885 | comp,
|
886 | state,
|
887 | targets,
|
888 | finalStates,
|
889 | fromNode,
|
890 | toNode,
|
891 | run,
|
892 | a,
|
893 | b;
|
894 |
|
895 | for (p in toState.idLookup) {
|
896 | toNode = !toState.alt[p] ? toState.idLookup[p] : _getChangingElState(toState, fromState, p);
|
897 | el = toNode.element;
|
898 | fromNode = fromState.idLookup[p];
|
899 | fromState.alt[p] && el === fromNode.element && (fromState.alt[p].isVisible || !toNode.isVisible) && (fromNode = fromState.alt[p]);
|
900 |
|
901 | if (fromNode) {
|
902 | comp = {
|
903 | t: el,
|
904 | b: fromNode,
|
905 | a: toNode,
|
906 | sd: fromNode.element === el ? 0 : toNode.isVisible ? 1 : -1
|
907 | };
|
908 | comps.push(comp);
|
909 |
|
910 | if (comp.sd) {
|
911 | if (comp.sd < 0) {
|
912 | comp.b = toNode;
|
913 | comp.a = fromNode;
|
914 | }
|
915 |
|
916 | interrupted && _recordInlineStyles(comp.b, props ? _memoizedRemoveProps[props] : _removeProps);
|
917 | fade && comps.push(comp.swap = {
|
918 | t: fromNode.element,
|
919 | b: comp.b,
|
920 | a: comp.a,
|
921 | sd: -comp.sd,
|
922 | swap: comp
|
923 | });
|
924 | }
|
925 |
|
926 | el._flip = fromNode.element._flip = _batch ? _batch.timeline : animation;
|
927 | } else if (toNode.isVisible) {
|
928 | comps.push({
|
929 | t: el,
|
930 | b: _copy(toNode, {
|
931 | isVisible: 1
|
932 | }),
|
933 | a: toNode,
|
934 | sd: 0,
|
935 | entering: 1
|
936 | });
|
937 | el._flip = _batch ? _batch.timeline : animation;
|
938 | }
|
939 | }
|
940 |
|
941 | props && (_memoizedProps[props] || _memoizeProps(props)).forEach(function (p) {
|
942 | return tweenVars[p] = function (i) {
|
943 | return comps[i].a.props[p];
|
944 | };
|
945 | });
|
946 | comps.finalStates = finalStates = [];
|
947 |
|
948 | run = function run() {
|
949 | _orderByDOMDepth(comps);
|
950 |
|
951 | _lockBodyScroll(true);
|
952 |
|
953 | for (i = 0; i < comps.length; i++) {
|
954 | comp = comps[i];
|
955 | a = comp.a;
|
956 | b = comp.b;
|
957 |
|
958 | if (prune && !a.isDifferent(b) && !comp.entering) {
|
959 | comps.splice(i--, 1);
|
960 | } else {
|
961 | el = comp.t;
|
962 | nested && !(comp.sd < 0) && i && (a.matrix = getGlobalMatrix(el, false, false, true));
|
963 |
|
964 | if (comp.sd || b.isVisible && a.isVisible) {
|
965 | if (comp.sd < 0) {
|
966 | state = new ElementState(el, props, fromState.simple);
|
967 |
|
968 | _fit(state, a, scale, 0, 0, state);
|
969 |
|
970 | state.matrix = getGlobalMatrix(el, false, false, true);
|
971 | state.css = comp.b.css;
|
972 | comp.a = a = state;
|
973 | fade && (el.style.opacity = interrupted ? b.opacity : a.opacity);
|
974 | stagger && swapOutTargets.push(el);
|
975 | } else if (comp.sd > 0 && fade) {
|
976 | el.style.opacity = interrupted ? a.opacity - b.opacity : "0";
|
977 | }
|
978 |
|
979 | _fit(a, b, scale, props);
|
980 | } else if (b.isVisible !== a.isVisible) {
|
981 | if (!b.isVisible) {
|
982 | a.isVisible && entering.push(a);
|
983 | comps.splice(i--, 1);
|
984 | } else if (!a.isVisible) {
|
985 | b.css = a.css;
|
986 | leaving.push(b);
|
987 | comps.splice(i--, 1);
|
988 | absolute && nested && _fit(a, b, scale, props);
|
989 | }
|
990 | }
|
991 |
|
992 | if (!scale) {
|
993 | el.style.maxWidth = Math.max(a.width, b.width) + "px";
|
994 | el.style.maxHeight = Math.max(a.height, b.height) + "px";
|
995 | el.style.minWidth = Math.min(a.width, b.width) + "px";
|
996 | el.style.minHeight = Math.min(a.height, b.height) + "px";
|
997 | }
|
998 |
|
999 | nested && toggleClass && el.classList.add(toggleClass);
|
1000 | }
|
1001 |
|
1002 | finalStates.push(a);
|
1003 | }
|
1004 |
|
1005 | var classTargets;
|
1006 |
|
1007 | if (toggleClass) {
|
1008 | classTargets = finalStates.map(function (s) {
|
1009 | return s.element;
|
1010 | });
|
1011 | nested && classTargets.forEach(function (e) {
|
1012 | return e.classList.remove(toggleClass);
|
1013 | });
|
1014 | }
|
1015 |
|
1016 | _lockBodyScroll(false);
|
1017 |
|
1018 | if (scale) {
|
1019 | tweenVars.scaleX = function (i) {
|
1020 | return comps[i].a.scaleX;
|
1021 | };
|
1022 |
|
1023 | tweenVars.scaleY = function (i) {
|
1024 | return comps[i].a.scaleY;
|
1025 | };
|
1026 | } else {
|
1027 | tweenVars.width = function (i) {
|
1028 | return comps[i].a.width + "px";
|
1029 | };
|
1030 |
|
1031 | tweenVars.height = function (i) {
|
1032 | return comps[i].a.height + "px";
|
1033 | };
|
1034 |
|
1035 | tweenVars.autoRound = vars.autoRound || false;
|
1036 | }
|
1037 |
|
1038 | tweenVars.x = function (i) {
|
1039 | return comps[i].a.x + "px";
|
1040 | };
|
1041 |
|
1042 | tweenVars.y = function (i) {
|
1043 | return comps[i].a.y + "px";
|
1044 | };
|
1045 |
|
1046 | tweenVars.rotation = function (i) {
|
1047 | return comps[i].a.rotation + (spin ? spinFunc(i, targets[i], targets) * 360 : 0);
|
1048 | };
|
1049 |
|
1050 | tweenVars.skewX = function (i) {
|
1051 | return comps[i].a.skewX;
|
1052 | };
|
1053 |
|
1054 | targets = comps.map(function (c) {
|
1055 | return c.t;
|
1056 | });
|
1057 |
|
1058 | if (_zIndex || _zIndex === 0) {
|
1059 | tweenVars.modifiers = {
|
1060 | zIndex: function zIndex() {
|
1061 | return _zIndex;
|
1062 | }
|
1063 | };
|
1064 | tweenVars.zIndex = _zIndex;
|
1065 | tweenVars.immediateRender = vars.immediateRender !== false;
|
1066 | }
|
1067 |
|
1068 | fade && (tweenVars.opacity = function (i) {
|
1069 | return comps[i].sd < 0 ? 0 : comps[i].sd > 0 ? comps[i].a.opacity : "+=0";
|
1070 | });
|
1071 |
|
1072 | if (swapOutTargets.length) {
|
1073 | stagger = gsap.utils.distribute(stagger);
|
1074 | var dummyArray = targets.slice(swapOutTargets.length);
|
1075 |
|
1076 | tweenVars.stagger = function (i, el) {
|
1077 | return stagger(~swapOutTargets.indexOf(el) ? targets.indexOf(comps[i].swap.t) : i, el, dummyArray);
|
1078 | };
|
1079 | }
|
1080 |
|
1081 | _callbacks.forEach(function (name) {
|
1082 | return vars[name] && animation.eventCallback(name, vars[name], vars[name + "Params"]);
|
1083 | });
|
1084 |
|
1085 | if (custom && targets.length) {
|
1086 | remainingProps = _copy(tweenVars, _reserved);
|
1087 |
|
1088 | if ("scale" in custom) {
|
1089 | custom.scaleX = custom.scaleY = custom.scale;
|
1090 | delete custom.scale;
|
1091 | }
|
1092 |
|
1093 | for (p in custom) {
|
1094 | v = _copy(custom[p], _fitReserved);
|
1095 | v[p] = tweenVars[p];
|
1096 | !("duration" in v) && "duration" in tweenVars && (v.duration = tweenVars.duration);
|
1097 | v.stagger = tweenVars.stagger;
|
1098 | addFunc.call(animation, targets, v, 0);
|
1099 | delete remainingProps[p];
|
1100 | }
|
1101 | }
|
1102 |
|
1103 | if (targets.length || leaving.length || entering.length) {
|
1104 | toggleClass && animation.add(function () {
|
1105 | return _toggleClass(classTargets, toggleClass, animation._zTime < 0 ? "remove" : "add");
|
1106 | }, 0) && !paused && _toggleClass(classTargets, toggleClass, "add");
|
1107 | targets.length && addFunc.call(animation, targets, remainingProps, 0);
|
1108 | }
|
1109 |
|
1110 | _handleCallback(onEnter, entering, animation);
|
1111 |
|
1112 | _handleCallback(onLeave, leaving, animation);
|
1113 |
|
1114 | var batchTl = _batch && _batch.timeline;
|
1115 |
|
1116 | if (batchTl) {
|
1117 | batchTl.add(animation, 0);
|
1118 |
|
1119 | _batch._final.push(function () {
|
1120 | return _setFinalStates(comps, !clearProps);
|
1121 | });
|
1122 | }
|
1123 |
|
1124 | endTime = animation.duration();
|
1125 | animation.call(function () {
|
1126 | var forward = animation.time() >= endTime;
|
1127 | forward && !batchTl && _setFinalStates(comps, !clearProps);
|
1128 | toggleClass && _toggleClass(classTargets, toggleClass, forward ? "remove" : "add");
|
1129 | });
|
1130 | };
|
1131 |
|
1132 | absoluteOnLeave && (absolute = comps.filter(function (comp) {
|
1133 | return !comp.sd && !comp.a.isVisible && comp.b.isVisible;
|
1134 | }).map(function (comp) {
|
1135 | return comp.a.element;
|
1136 | }));
|
1137 |
|
1138 | if (_batch) {
|
1139 | var _batch$_abs;
|
1140 |
|
1141 | absolute && (_batch$_abs = _batch._abs).push.apply(_batch$_abs, _filterComps(comps, absolute));
|
1142 |
|
1143 | _batch._run.push(run);
|
1144 | } else {
|
1145 | absolute && _makeCompsAbsolute(_filterComps(comps, absolute));
|
1146 | run();
|
1147 | }
|
1148 |
|
1149 | return _batch ? _batch.timeline : animation;
|
1150 | },
|
1151 | _interrupt = function _interrupt(tl) {
|
1152 | tl.vars.onInterrupt && tl.vars.onInterrupt.apply(tl, tl.vars.onInterruptParams || []);
|
1153 | tl.getChildren(true, false, true).forEach(_interrupt);
|
1154 | },
|
1155 | _killFlip = function _killFlip(tl, action) {
|
1156 | if (tl && tl.progress() < 1 && !tl.paused()) {
|
1157 | if (action) {
|
1158 | _interrupt(tl);
|
1159 |
|
1160 | action < 2 && tl.progress(1);
|
1161 | tl.kill();
|
1162 | }
|
1163 |
|
1164 | return true;
|
1165 | }
|
1166 | },
|
1167 | _createLookup = function _createLookup(state) {
|
1168 | var lookup = state.idLookup = {},
|
1169 | alt = state.alt = {},
|
1170 | elStates = state.elementStates,
|
1171 | i = elStates.length,
|
1172 | elState;
|
1173 |
|
1174 | while (i--) {
|
1175 | elState = elStates[i];
|
1176 | lookup[elState.id] ? alt[elState.id] = elState : lookup[elState.id] = elState;
|
1177 | }
|
1178 | };
|
1179 |
|
1180 | var FlipState = function () {
|
1181 | function FlipState(targets, vars, targetsAreElementStates) {
|
1182 | this.props = vars && vars.props;
|
1183 | this.simple = !!(vars && vars.simple);
|
1184 |
|
1185 | if (targetsAreElementStates) {
|
1186 | this.targets = _elementsFromElementStates(targets);
|
1187 | this.elementStates = targets;
|
1188 |
|
1189 | _createLookup(this);
|
1190 | } else {
|
1191 | this.targets = _toArray(targets);
|
1192 | var soft = vars && (vars.kill === false || vars.batch && !vars.kill);
|
1193 | _batch && !soft && _batch._kill.push(this);
|
1194 | this.update(soft || !!_batch);
|
1195 | }
|
1196 | }
|
1197 |
|
1198 | var _proto = FlipState.prototype;
|
1199 |
|
1200 | _proto.update = function update(soft) {
|
1201 | var _this = this;
|
1202 |
|
1203 | this.elementStates = this.targets.map(function (el) {
|
1204 | return new ElementState(el, _this.props, _this.simple);
|
1205 | });
|
1206 |
|
1207 | _createLookup(this);
|
1208 |
|
1209 | this.interrupt(soft);
|
1210 | this.recordInlineStyles();
|
1211 | return this;
|
1212 | };
|
1213 |
|
1214 | _proto.clear = function clear() {
|
1215 | this.targets.length = this.elementStates.length = 0;
|
1216 |
|
1217 | _createLookup(this);
|
1218 |
|
1219 | return this;
|
1220 | };
|
1221 |
|
1222 | _proto.fit = function fit(state, scale, nested) {
|
1223 | var elStatesInOrder = _orderByDOMDepth(this.elementStates.slice(0), false, true),
|
1224 | toElStates = (state || this).idLookup,
|
1225 | i = 0,
|
1226 | fromNode,
|
1227 | toNode;
|
1228 |
|
1229 | for (; i < elStatesInOrder.length; i++) {
|
1230 | fromNode = elStatesInOrder[i];
|
1231 | nested && (fromNode.matrix = getGlobalMatrix(fromNode.element, false, false, true));
|
1232 | toNode = toElStates[fromNode.id];
|
1233 | toNode && _fit(fromNode, toNode, scale, true, 0, fromNode);
|
1234 | fromNode.matrix = getGlobalMatrix(fromNode.element, false, false, true);
|
1235 | }
|
1236 |
|
1237 | return this;
|
1238 | };
|
1239 |
|
1240 | _proto.getProperty = function getProperty(element, property) {
|
1241 | var es = this.getElementState(element) || _emptyObj;
|
1242 |
|
1243 | return (property in es ? es : es.props || _emptyObj)[property];
|
1244 | };
|
1245 |
|
1246 | _proto.add = function add(state) {
|
1247 | var i = state.targets.length,
|
1248 | lookup = this.idLookup,
|
1249 | alt = this.alt,
|
1250 | index,
|
1251 | es,
|
1252 | es2;
|
1253 |
|
1254 | while (i--) {
|
1255 | es = state.elementStates[i];
|
1256 | es2 = lookup[es.id];
|
1257 |
|
1258 | if (es2 && (es.element === es2.element || alt[es.id] && alt[es.id].element === es.element)) {
|
1259 | index = this.elementStates.indexOf(es.element === es2.element ? es2 : alt[es.id]);
|
1260 | this.targets.splice(index, 1, state.targets[i]);
|
1261 | this.elementStates.splice(index, 1, es);
|
1262 | } else {
|
1263 | this.targets.push(state.targets[i]);
|
1264 | this.elementStates.push(es);
|
1265 | }
|
1266 | }
|
1267 |
|
1268 | state.interrupted && (this.interrupted = true);
|
1269 | state.simple || (this.simple = false);
|
1270 |
|
1271 | _createLookup(this);
|
1272 |
|
1273 | return this;
|
1274 | };
|
1275 |
|
1276 | _proto.compare = function compare(state) {
|
1277 | var l1 = state.idLookup,
|
1278 | l2 = this.idLookup,
|
1279 | unchanged = [],
|
1280 | changed = [],
|
1281 | enter = [],
|
1282 | leave = [],
|
1283 | targets = [],
|
1284 | a1 = state.alt,
|
1285 | a2 = this.alt,
|
1286 | place = function place(s1, s2, el) {
|
1287 | return (s1.isVisible !== s2.isVisible ? s1.isVisible ? enter : leave : s1.isVisible ? changed : unchanged).push(el) && targets.push(el);
|
1288 | },
|
1289 | placeIfDoesNotExist = function placeIfDoesNotExist(s1, s2, el) {
|
1290 | return targets.indexOf(el) < 0 && place(s1, s2, el);
|
1291 | },
|
1292 | s1,
|
1293 | s2,
|
1294 | p,
|
1295 | el,
|
1296 | s1Alt,
|
1297 | s2Alt,
|
1298 | c1,
|
1299 | c2;
|
1300 |
|
1301 | for (p in l1) {
|
1302 | s1Alt = a1[p];
|
1303 | s2Alt = a2[p];
|
1304 | s1 = !s1Alt ? l1[p] : _getChangingElState(state, this, p);
|
1305 | el = s1.element;
|
1306 | s2 = l2[p];
|
1307 |
|
1308 | if (s2Alt) {
|
1309 | c2 = s2.isVisible || !s2Alt.isVisible && el === s2.element ? s2 : s2Alt;
|
1310 | c1 = s1Alt && !s1.isVisible && !s1Alt.isVisible && c2.element === s1Alt.element ? s1Alt : s1;
|
1311 |
|
1312 | if (c1.isVisible && c2.isVisible && c1.element !== c2.element) {
|
1313 | (c1.isDifferent(c2) ? changed : unchanged).push(c1.element, c2.element);
|
1314 | targets.push(c1.element, c2.element);
|
1315 | } else {
|
1316 | place(c1, c2, c1.element);
|
1317 | }
|
1318 |
|
1319 | s1Alt && c1.element === s1Alt.element && (s1Alt = l1[p]);
|
1320 | placeIfDoesNotExist(c1.element !== s2.element && s1Alt ? s1Alt : c1, s2, s2.element);
|
1321 | placeIfDoesNotExist(s1Alt && s1Alt.element === s2Alt.element ? s1Alt : c1, s2Alt, s2Alt.element);
|
1322 | s1Alt && placeIfDoesNotExist(s1Alt, s2Alt.element === s1Alt.element ? s2Alt : s2, s1Alt.element);
|
1323 | } else {
|
1324 | !s2 ? enter.push(el) : !s2.isDifferent(s1) ? unchanged.push(el) : place(s1, s2, el);
|
1325 | s1Alt && placeIfDoesNotExist(s1Alt, s2, s1Alt.element);
|
1326 | }
|
1327 | }
|
1328 |
|
1329 | for (p in l2) {
|
1330 | if (!l1[p]) {
|
1331 | leave.push(l2[p].element);
|
1332 | a2[p] && leave.push(a2[p].element);
|
1333 | }
|
1334 | }
|
1335 |
|
1336 | return {
|
1337 | changed: changed,
|
1338 | unchanged: unchanged,
|
1339 | enter: enter,
|
1340 | leave: leave
|
1341 | };
|
1342 | };
|
1343 |
|
1344 | _proto.recordInlineStyles = function recordInlineStyles() {
|
1345 | var props = _memoizedRemoveProps[this.props] || _removeProps,
|
1346 | i = this.elementStates.length;
|
1347 |
|
1348 | while (i--) {
|
1349 | _recordInlineStyles(this.elementStates[i], props);
|
1350 | }
|
1351 | };
|
1352 |
|
1353 | _proto.interrupt = function interrupt(soft) {
|
1354 | var _this2 = this;
|
1355 |
|
1356 | var timelines = [];
|
1357 | this.targets.forEach(function (t) {
|
1358 | var tl = t._flip,
|
1359 | foundInProgress = _killFlip(tl, soft ? 0 : 1);
|
1360 |
|
1361 | soft && foundInProgress && timelines.indexOf(tl) < 0 && tl.add(function () {
|
1362 | return _this2.updateVisibility();
|
1363 | });
|
1364 | foundInProgress && timelines.push(tl);
|
1365 | });
|
1366 | !soft && timelines.length && this.updateVisibility();
|
1367 | this.interrupted || (this.interrupted = !!timelines.length);
|
1368 | };
|
1369 |
|
1370 | _proto.updateVisibility = function updateVisibility() {
|
1371 | this.elementStates.forEach(function (es) {
|
1372 | var b = es.element.getBoundingClientRect();
|
1373 | es.isVisible = !!(b.width || b.height || b.top || b.left);
|
1374 | es.uncache = 1;
|
1375 | });
|
1376 | };
|
1377 |
|
1378 | _proto.getElementState = function getElementState(element) {
|
1379 | return this.elementStates[this.targets.indexOf(_getEl(element))];
|
1380 | };
|
1381 |
|
1382 | _proto.makeAbsolute = function makeAbsolute() {
|
1383 | return _orderByDOMDepth(this.elementStates.slice(0), true, true).map(_makeAbsolute);
|
1384 | };
|
1385 |
|
1386 | return FlipState;
|
1387 | }();
|
1388 |
|
1389 | var ElementState = function () {
|
1390 | function ElementState(element, props, simple) {
|
1391 | this.element = element;
|
1392 | this.update(props, simple);
|
1393 | }
|
1394 |
|
1395 | var _proto2 = ElementState.prototype;
|
1396 |
|
1397 | _proto2.isDifferent = function isDifferent(state) {
|
1398 | var b1 = this.bounds,
|
1399 | b2 = state.bounds;
|
1400 | return b1.top !== b2.top || b1.left !== b2.left || b1.width !== b2.width || b1.height !== b2.height || !this.matrix.equals(state.matrix) || this.opacity !== state.opacity || this.props && state.props && JSON.stringify(this.props) !== JSON.stringify(state.props);
|
1401 | };
|
1402 |
|
1403 | _proto2.update = function update(props, simple) {
|
1404 | var self = this,
|
1405 | element = self.element,
|
1406 | getProp = gsap.getProperty(element),
|
1407 | cache = gsap.core.getCache(element),
|
1408 | bounds = element.getBoundingClientRect(),
|
1409 | bbox = element.getBBox && typeof element.getBBox === "function" && element.nodeName.toLowerCase() !== "svg" && element.getBBox(),
|
1410 | m = simple ? new Matrix2D(1, 0, 0, 1, bounds.left + _getDocScrollLeft(), bounds.top + _getDocScrollTop()) : getGlobalMatrix(element, false, false, true);
|
1411 | self.getProp = getProp;
|
1412 | self.element = element;
|
1413 | self.id = _getID(element);
|
1414 | self.matrix = m;
|
1415 | self.cache = cache;
|
1416 | self.bounds = bounds;
|
1417 | self.isVisible = !!(bounds.width || bounds.height || bounds.left || bounds.top);
|
1418 | self.display = getProp("display");
|
1419 | self.position = getProp("position");
|
1420 | self.parent = element.parentNode;
|
1421 | self.x = getProp("x");
|
1422 | self.y = getProp("y");
|
1423 | self.scaleX = cache.scaleX;
|
1424 | self.scaleY = cache.scaleY;
|
1425 | self.rotation = getProp("rotation");
|
1426 | self.skewX = getProp("skewX");
|
1427 | self.opacity = getProp("opacity");
|
1428 | self.width = bbox ? bbox.width : _closestTenth(getProp("width", "px"), 0.04);
|
1429 | self.height = bbox ? bbox.height : _closestTenth(getProp("height", "px"), 0.04);
|
1430 | props && _recordProps(self, _memoizedProps[props] || _memoizeProps(props));
|
1431 | self.ctm = element.getCTM && element.nodeName.toLowerCase() === "svg" && _getCTM(element).inverse();
|
1432 | self.simple = simple || _round(m.a) === 1 && !_round(m.b) && !_round(m.c) && _round(m.d) === 1;
|
1433 | self.uncache = 0;
|
1434 | };
|
1435 |
|
1436 | return ElementState;
|
1437 | }();
|
1438 |
|
1439 | var FlipAction = function () {
|
1440 | function FlipAction(vars, batch) {
|
1441 | this.vars = vars;
|
1442 | this.batch = batch;
|
1443 | this.states = [];
|
1444 | this.timeline = batch.timeline;
|
1445 | }
|
1446 |
|
1447 | var _proto3 = FlipAction.prototype;
|
1448 |
|
1449 | _proto3.getStateById = function getStateById(id) {
|
1450 | var i = this.states.length;
|
1451 |
|
1452 | while (i--) {
|
1453 | if (this.states[i].idLookup[id]) {
|
1454 | return this.states[i];
|
1455 | }
|
1456 | }
|
1457 | };
|
1458 |
|
1459 | _proto3.kill = function kill() {
|
1460 | this.batch.remove(this);
|
1461 | };
|
1462 |
|
1463 | return FlipAction;
|
1464 | }();
|
1465 |
|
1466 | var FlipBatch = function () {
|
1467 | function FlipBatch(id) {
|
1468 | this.id = id;
|
1469 | this.actions = [];
|
1470 | this._kill = [];
|
1471 | this._final = [];
|
1472 | this._abs = [];
|
1473 | this._run = [];
|
1474 | this.data = {};
|
1475 | this.state = new FlipState();
|
1476 | this.timeline = gsap.timeline();
|
1477 | }
|
1478 |
|
1479 | var _proto4 = FlipBatch.prototype;
|
1480 |
|
1481 | _proto4.add = function add(config) {
|
1482 | var result = this.actions.filter(function (action) {
|
1483 | return action.vars === config;
|
1484 | });
|
1485 |
|
1486 | if (result.length) {
|
1487 | return result[0];
|
1488 | }
|
1489 |
|
1490 | result = new FlipAction(typeof config === "function" ? {
|
1491 | animate: config
|
1492 | } : config, this);
|
1493 | this.actions.push(result);
|
1494 | return result;
|
1495 | };
|
1496 |
|
1497 | _proto4.remove = function remove(action) {
|
1498 | var i = this.actions.indexOf(action);
|
1499 | i >= 0 && this.actions.splice(i, 1);
|
1500 | return this;
|
1501 | };
|
1502 |
|
1503 | _proto4.getState = function getState(merge) {
|
1504 | var _this3 = this;
|
1505 |
|
1506 | var prevBatch = _batch,
|
1507 | prevAction = _batchAction;
|
1508 | _batch = this;
|
1509 | this.state.clear();
|
1510 | this._kill.length = 0;
|
1511 | this.actions.forEach(function (action) {
|
1512 | if (action.vars.getState) {
|
1513 | action.states.length = 0;
|
1514 | _batchAction = action;
|
1515 | action.state = action.vars.getState(action);
|
1516 | }
|
1517 |
|
1518 | merge && action.states.forEach(function (s) {
|
1519 | return _this3.state.add(s);
|
1520 | });
|
1521 | });
|
1522 | _batchAction = prevAction;
|
1523 | _batch = prevBatch;
|
1524 | this.killConflicts();
|
1525 | return this;
|
1526 | };
|
1527 |
|
1528 | _proto4.animate = function animate() {
|
1529 | var _this4 = this;
|
1530 |
|
1531 | var prevBatch = _batch,
|
1532 | tl = this.timeline,
|
1533 | i = this.actions.length,
|
1534 | finalStates,
|
1535 | endTime;
|
1536 | _batch = this;
|
1537 | tl.clear();
|
1538 | this._abs.length = this._final.length = this._run.length = 0;
|
1539 | this.actions.forEach(function (a) {
|
1540 | a.vars.animate && a.vars.animate(a);
|
1541 | var onEnter = a.vars.onEnter,
|
1542 | onLeave = a.vars.onLeave,
|
1543 | targets = a.targets,
|
1544 | s,
|
1545 | result;
|
1546 |
|
1547 | if (targets && targets.length && (onEnter || onLeave)) {
|
1548 | s = new FlipState();
|
1549 | a.states.forEach(function (state) {
|
1550 | return s.add(state);
|
1551 | });
|
1552 | result = s.compare(Flip.getState(targets));
|
1553 | result.enter.length && onEnter && onEnter(result.enter);
|
1554 | result.leave.length && onLeave && onLeave(result.leave);
|
1555 | }
|
1556 | });
|
1557 |
|
1558 | _makeCompsAbsolute(this._abs);
|
1559 |
|
1560 | this._run.forEach(function (f) {
|
1561 | return f();
|
1562 | });
|
1563 |
|
1564 | endTime = tl.duration();
|
1565 | finalStates = this._final.slice(0);
|
1566 | tl.add(function () {
|
1567 | if (endTime <= tl.time()) {
|
1568 | finalStates.forEach(function (f) {
|
1569 | return f();
|
1570 | });
|
1571 |
|
1572 | _forEachBatch(_this4, "onComplete");
|
1573 | }
|
1574 | });
|
1575 | _batch = prevBatch;
|
1576 |
|
1577 | while (i--) {
|
1578 | this.actions[i].vars.once && this.actions[i].kill();
|
1579 | }
|
1580 |
|
1581 | _forEachBatch(this, "onStart");
|
1582 |
|
1583 | tl.restart();
|
1584 | return this;
|
1585 | };
|
1586 |
|
1587 | _proto4.loadState = function loadState(done) {
|
1588 | done || (done = function done() {
|
1589 | return 0;
|
1590 | });
|
1591 | var queue = [];
|
1592 | this.actions.forEach(function (c) {
|
1593 | if (c.vars.loadState) {
|
1594 | var i,
|
1595 | f = function f(targets) {
|
1596 | targets && (c.targets = targets);
|
1597 | i = queue.indexOf(f);
|
1598 |
|
1599 | if (~i) {
|
1600 | queue.splice(i, 1);
|
1601 | queue.length || done();
|
1602 | }
|
1603 | };
|
1604 |
|
1605 | queue.push(f);
|
1606 | c.vars.loadState(f);
|
1607 | }
|
1608 | });
|
1609 | queue.length || done();
|
1610 | return this;
|
1611 | };
|
1612 |
|
1613 | _proto4.setState = function setState() {
|
1614 | this.actions.forEach(function (c) {
|
1615 | return c.targets = c.vars.setState && c.vars.setState(c);
|
1616 | });
|
1617 | return this;
|
1618 | };
|
1619 |
|
1620 | _proto4.killConflicts = function killConflicts(soft) {
|
1621 | this.state.interrupt(soft);
|
1622 |
|
1623 | this._kill.forEach(function (state) {
|
1624 | return state.interrupt(soft);
|
1625 | });
|
1626 |
|
1627 | return this;
|
1628 | };
|
1629 |
|
1630 | _proto4.run = function run(skipGetState, merge) {
|
1631 | var _this5 = this;
|
1632 |
|
1633 | if (this !== _batch) {
|
1634 | skipGetState || this.getState(merge);
|
1635 | this.loadState(function () {
|
1636 | if (!_this5._killed) {
|
1637 | _this5.setState();
|
1638 |
|
1639 | _this5.animate();
|
1640 | }
|
1641 | });
|
1642 | }
|
1643 |
|
1644 | return this;
|
1645 | };
|
1646 |
|
1647 | _proto4.clear = function clear(stateOnly) {
|
1648 | this.state.clear();
|
1649 | stateOnly || (this.actions.length = 0);
|
1650 | };
|
1651 |
|
1652 | _proto4.getStateById = function getStateById(id) {
|
1653 | var i = this.actions.length,
|
1654 | s;
|
1655 |
|
1656 | while (i--) {
|
1657 | s = this.actions[i].getStateById(id);
|
1658 |
|
1659 | if (s) {
|
1660 | return s;
|
1661 | }
|
1662 | }
|
1663 |
|
1664 | return this.state.idLookup[id] && this.state;
|
1665 | };
|
1666 |
|
1667 | _proto4.kill = function kill() {
|
1668 | this._killed = 1;
|
1669 | this.clear();
|
1670 | delete _batchLookup[this.id];
|
1671 | };
|
1672 |
|
1673 | return FlipBatch;
|
1674 | }();
|
1675 |
|
1676 | var Flip = function () {
|
1677 | function Flip() {}
|
1678 |
|
1679 | Flip.getState = function getState(targets, vars) {
|
1680 | var state = _parseState(targets, vars);
|
1681 |
|
1682 | _batchAction && _batchAction.states.push(state);
|
1683 | vars && vars.batch && Flip.batch(vars.batch).state.add(state);
|
1684 | return state;
|
1685 | };
|
1686 |
|
1687 | Flip.from = function from(state, vars) {
|
1688 | vars = vars || {};
|
1689 | "clearProps" in vars || (vars.clearProps = true);
|
1690 | return _fromTo(state, _parseState(vars.targets || state.targets, {
|
1691 | props: vars.props || state.props,
|
1692 | simple: vars.simple,
|
1693 | kill: !!vars.kill
|
1694 | }), vars, -1);
|
1695 | };
|
1696 |
|
1697 | Flip.to = function to(state, vars) {
|
1698 | return _fromTo(state, _parseState(vars.targets || state.targets, {
|
1699 | props: vars.props || state.props,
|
1700 | simple: vars.simple,
|
1701 | kill: !!vars.kill
|
1702 | }), vars, 1);
|
1703 | };
|
1704 |
|
1705 | Flip.fromTo = function fromTo(fromState, toState, vars) {
|
1706 | return _fromTo(fromState, toState, vars);
|
1707 | };
|
1708 |
|
1709 | Flip.fit = function fit(fromEl, toEl, vars) {
|
1710 | var v = vars ? _copy(vars, _fitReserved) : {},
|
1711 | _ref = vars || v,
|
1712 | absolute = _ref.absolute,
|
1713 | scale = _ref.scale,
|
1714 | getVars = _ref.getVars,
|
1715 | props = _ref.props,
|
1716 | runBackwards = _ref.runBackwards,
|
1717 | onComplete = _ref.onComplete,
|
1718 | simple = _ref.simple,
|
1719 | fitChild = vars && vars.fitChild && _getEl(vars.fitChild),
|
1720 | before = _parseElementState(toEl, props, simple, fromEl),
|
1721 | after = _parseElementState(fromEl, 0, simple, before),
|
1722 | inlineProps = props ? _memoizedRemoveProps[props] : _removeProps;
|
1723 |
|
1724 | props && _applyProps(v, before.props);
|
1725 |
|
1726 | if (runBackwards) {
|
1727 | _recordInlineStyles(after, inlineProps);
|
1728 |
|
1729 | "immediateRender" in v || (v.immediateRender = true);
|
1730 |
|
1731 | v.onComplete = function () {
|
1732 | _applyInlineStyles(after);
|
1733 |
|
1734 | onComplete && onComplete.apply(this, arguments);
|
1735 | };
|
1736 | }
|
1737 |
|
1738 | absolute && _makeAbsolute(after, before);
|
1739 | v = _fit(after, before, scale || fitChild, props, fitChild, v.duration || getVars ? v : 0);
|
1740 | return getVars ? v : v.duration ? gsap.to(after.element, v) : null;
|
1741 | };
|
1742 |
|
1743 | Flip.makeAbsolute = function makeAbsolute(targetsOrStates, vars) {
|
1744 | return (targetsOrStates instanceof FlipState ? targetsOrStates : new FlipState(targetsOrStates, vars)).makeAbsolute();
|
1745 | };
|
1746 |
|
1747 | Flip.batch = function batch(id) {
|
1748 | id || (id = "default");
|
1749 | return _batchLookup[id] || (_batchLookup[id] = new FlipBatch(id));
|
1750 | };
|
1751 |
|
1752 | Flip.killFlipsOf = function killFlipsOf(targets, complete) {
|
1753 | (targets instanceof FlipState ? targets.targets : _toArray(targets)).forEach(function (t) {
|
1754 | return t && _killFlip(t._flip, complete !== false ? 1 : 2);
|
1755 | });
|
1756 | };
|
1757 |
|
1758 | Flip.isFlipping = function isFlipping(target) {
|
1759 | var f = Flip.getByTarget(target);
|
1760 | return !!f && f.isActive();
|
1761 | };
|
1762 |
|
1763 | Flip.getByTarget = function getByTarget(target) {
|
1764 | return (_getEl(target) || _emptyObj)._flip;
|
1765 | };
|
1766 |
|
1767 | Flip.getElementState = function getElementState(target, props) {
|
1768 | return new ElementState(_getEl(target), props);
|
1769 | };
|
1770 |
|
1771 | Flip.convertCoordinates = function convertCoordinates(fromElement, toElement, point) {
|
1772 | var m = getGlobalMatrix(toElement, true, true).multiply(getGlobalMatrix(fromElement));
|
1773 | return point ? m.apply(point) : m;
|
1774 | };
|
1775 |
|
1776 | Flip.register = function register(core) {
|
1777 | _body$1 = typeof document !== "undefined" && document.body;
|
1778 |
|
1779 | if (_body$1) {
|
1780 | gsap = core;
|
1781 |
|
1782 | _setDoc(_body$1);
|
1783 |
|
1784 | _toArray = gsap.utils.toArray;
|
1785 | var snap = gsap.utils.snap(0.1);
|
1786 |
|
1787 | _closestTenth = function _closestTenth(value, add) {
|
1788 | return snap(parseFloat(value) + add);
|
1789 | };
|
1790 | }
|
1791 | };
|
1792 |
|
1793 | return Flip;
|
1794 | }();
|
1795 | Flip.version = "3.10.3";
|
1796 | typeof window !== "undefined" && window.gsap && window.gsap.registerPlugin(Flip);
|
1797 |
|
1798 | exports.Flip = Flip;
|
1799 | exports.default = Flip;
|
1800 |
|
1801 | Object.defineProperty(exports, '__esModule', { value: true });
|
1802 |
|
1803 | })));
|