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