-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsap-css-plugin.js
1416 lines (1210 loc) · 54.8 KB
/
gsap-css-plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* CSSPlugin 3.6.1
* https://greensock.com
*
* Copyright 2008-2021, GreenSock. All rights reserved.
* Subject to the terms at https://greensock.com/standard-license or for
* Club GreenSock members, the agreement issued with that membership.
* @author: Jack Doyle, [email protected]
*/
/* eslint-disable */
import { gsap, _getProperty, _numExp, _numWithUnitExp, getUnit, _isString, _isUndefined, _renderComplexString, _relExp, _forEachName, _sortPropTweensByPriority, _colorStringFilter, _checkPlugin, _replaceRandom, _plugins, GSCache, PropTween, _config, _ticker, _round, _missingPlugin, _getSetter, _getCache, _colorExp, _setDefaults, _removeLinkedListItem //for the commented-out className feature.
} from "./gsap-core.js";
var _win,
_doc,
_docElement,
_pluginInitted,
_tempDiv,
_tempDivStyler,
_recentSetterPlugin,
_windowExists = function _windowExists() {
return typeof window !== "undefined";
},
_transformProps = {},
_RAD2DEG = 180 / Math.PI,
_DEG2RAD = Math.PI / 180,
_atan2 = Math.atan2,
_bigNum = 1e8,
_capsExp = /([A-Z])/g,
_horizontalExp = /(?:left|right|width|margin|padding|x)/i,
_complexExp = /[\s,\(]\S/,
_propertyAliases = {
autoAlpha: "opacity,visibility",
scale: "scaleX,scaleY",
alpha: "opacity"
},
_renderCSSProp = function _renderCSSProp(ratio, data) {
return data.set(data.t, data.p, Math.round((data.s + data.c * ratio) * 10000) / 10000 + data.u, data);
},
_renderPropWithEnd = function _renderPropWithEnd(ratio, data) {
return data.set(data.t, data.p, ratio === 1 ? data.e : Math.round((data.s + data.c * ratio) * 10000) / 10000 + data.u, data);
},
_renderCSSPropWithBeginning = function _renderCSSPropWithBeginning(ratio, data) {
return data.set(data.t, data.p, ratio ? Math.round((data.s + data.c * ratio) * 10000) / 10000 + data.u : data.b, data);
},
//if units change, we need a way to render the original unit/value when the tween goes all the way back to the beginning (ratio:0)
_renderRoundedCSSProp = function _renderRoundedCSSProp(ratio, data) {
var value = data.s + data.c * ratio;
data.set(data.t, data.p, ~~(value + (value < 0 ? -.5 : .5)) + data.u, data);
},
_renderNonTweeningValue = function _renderNonTweeningValue(ratio, data) {
return data.set(data.t, data.p, ratio ? data.e : data.b, data);
},
_renderNonTweeningValueOnlyAtEnd = function _renderNonTweeningValueOnlyAtEnd(ratio, data) {
return data.set(data.t, data.p, ratio !== 1 ? data.b : data.e, data);
},
_setterCSSStyle = function _setterCSSStyle(target, property, value) {
return target.style[property] = value;
},
_setterCSSProp = function _setterCSSProp(target, property, value) {
return target.style.setProperty(property, value);
},
_setterTransform = function _setterTransform(target, property, value) {
return target._gsap[property] = value;
},
_setterScale = function _setterScale(target, property, value) {
return target._gsap.scaleX = target._gsap.scaleY = value;
},
_setterScaleWithRender = function _setterScaleWithRender(target, property, value, data, ratio) {
var cache = target._gsap;
cache.scaleX = cache.scaleY = value;
cache.renderTransform(ratio, cache);
},
_setterTransformWithRender = function _setterTransformWithRender(target, property, value, data, ratio) {
var cache = target._gsap;
cache[property] = value;
cache.renderTransform(ratio, cache);
},
_transformProp = "transform",
_transformOriginProp = _transformProp + "Origin",
_supports3D,
_createElement = function _createElement(type, ns) {
var e = _doc.createElementNS ? _doc.createElementNS((ns || "http://www.w3.org/1999/xhtml").replace(/^https/, "http"), type) : _doc.createElement(type); //some servers swap in https for http in the namespace which can break things, making "style" inaccessible.
return e.style ? e : _doc.createElement(type); //some environments won't allow access to the element's style when created with a namespace in which case we default to the standard createElement() to work around the issue. Also note that when GSAP is embedded directly inside an SVG file, createElement() won't allow access to the style object in Firefox (see https://greensock.com/forums/topic/20215-problem-using-tweenmax-in-standalone-self-containing-svg-file-err-cannot-set-property-csstext-of-undefined/).
},
_getComputedProperty = function _getComputedProperty(target, property, skipPrefixFallback) {
var cs = getComputedStyle(target);
return cs[property] || cs.getPropertyValue(property.replace(_capsExp, "-$1").toLowerCase()) || cs.getPropertyValue(property) || !skipPrefixFallback && _getComputedProperty(target, _checkPropPrefix(property) || property, 1) || ""; //css variables may not need caps swapped out for dashes and lowercase.
},
_prefixes = "O,Moz,ms,Ms,Webkit".split(","),
_checkPropPrefix = function _checkPropPrefix(property, element, preferPrefix) {
var e = element || _tempDiv,
s = e.style,
i = 5;
if (property in s && !preferPrefix) {
return property;
}
property = property.charAt(0).toUpperCase() + property.substr(1);
while (i-- && !(_prefixes[i] + property in s)) {}
return i < 0 ? null : (i === 3 ? "ms" : i >= 0 ? _prefixes[i] : "") + property;
},
_initCore = function _initCore() {
if (_windowExists() && window.document) {
_win = window;
_doc = _win.document;
_docElement = _doc.documentElement;
_tempDiv = _createElement("div") || {
style: {}
};
_tempDivStyler = _createElement("div");
_transformProp = _checkPropPrefix(_transformProp);
_transformOriginProp = _transformProp + "Origin";
_tempDiv.style.cssText = "border-width:0;line-height:0;position:absolute;padding:0"; //make sure to override certain properties that may contaminate measurements, in case the user has overreaching style sheets.
_supports3D = !!_checkPropPrefix("perspective");
_pluginInitted = 1;
}
},
_getBBoxHack = function _getBBoxHack(swapIfPossible) {
//works around issues in some browsers (like Firefox) that don't correctly report getBBox() on SVG elements inside a <defs> element and/or <mask>. We try creating an SVG, adding it to the documentElement and toss the element in there so that it's definitely part of the rendering tree, then grab the bbox and if it works, we actually swap out the original getBBox() method for our own that does these extra steps whenever getBBox is needed. This helps ensure that performance is optimal (only do all these extra steps when absolutely necessary...most elements don't need it).
var svg = _createElement("svg", this.ownerSVGElement && this.ownerSVGElement.getAttribute("xmlns") || "http://www.w3.org/2000/svg"),
oldParent = this.parentNode,
oldSibling = this.nextSibling,
oldCSS = this.style.cssText,
bbox;
_docElement.appendChild(svg);
svg.appendChild(this);
this.style.display = "block";
if (swapIfPossible) {
try {
bbox = this.getBBox();
this._gsapBBox = this.getBBox; //store the original
this.getBBox = _getBBoxHack;
} catch (e) {}
} else if (this._gsapBBox) {
bbox = this._gsapBBox();
}
if (oldParent) {
if (oldSibling) {
oldParent.insertBefore(this, oldSibling);
} else {
oldParent.appendChild(this);
}
}
_docElement.removeChild(svg);
this.style.cssText = oldCSS;
return bbox;
},
_getAttributeFallbacks = function _getAttributeFallbacks(target, attributesArray) {
var i = attributesArray.length;
while (i--) {
if (target.hasAttribute(attributesArray[i])) {
return target.getAttribute(attributesArray[i]);
}
}
},
_getBBox = function _getBBox(target) {
var bounds;
try {
bounds = target.getBBox(); //Firefox throws errors if you try calling getBBox() on an SVG element that's not rendered (like in a <symbol> or <defs>). https://bugzilla.mozilla.org/show_bug.cgi?id=612118
} catch (error) {
bounds = _getBBoxHack.call(target, true);
}
bounds && (bounds.width || bounds.height) || target.getBBox === _getBBoxHack || (bounds = _getBBoxHack.call(target, true)); //some browsers (like Firefox) misreport the bounds if the element has zero width and height (it just assumes it's at x:0, y:0), thus we need to manually grab the position in that case.
return bounds && !bounds.width && !bounds.x && !bounds.y ? {
x: +_getAttributeFallbacks(target, ["x", "cx", "x1"]) || 0,
y: +_getAttributeFallbacks(target, ["y", "cy", "y1"]) || 0,
width: 0,
height: 0
} : bounds;
},
_isSVG = function _isSVG(e) {
return !!(e.getCTM && (!e.parentNode || e.ownerSVGElement) && _getBBox(e));
},
//reports if the element is an SVG on which getBBox() actually works
_removeProperty = function _removeProperty(target, property) {
if (property) {
var style = target.style;
if (property in _transformProps && property !== _transformOriginProp) {
property = _transformProp;
}
if (style.removeProperty) {
if (property.substr(0, 2) === "ms" || property.substr(0, 6) === "webkit") {
//Microsoft and some Webkit browsers don't conform to the standard of capitalizing the first prefix character, so we adjust so that when we prefix the caps with a dash, it's correct (otherwise it'd be "ms-transform" instead of "-ms-transform" for IE9, for example)
property = "-" + property;
}
style.removeProperty(property.replace(_capsExp, "-$1").toLowerCase());
} else {
//note: old versions of IE use "removeAttribute()" instead of "removeProperty()"
style.removeAttribute(property);
}
}
},
_addNonTweeningPT = function _addNonTweeningPT(plugin, target, property, beginning, end, onlySetAtEnd) {
var pt = new PropTween(plugin._pt, target, property, 0, 1, onlySetAtEnd ? _renderNonTweeningValueOnlyAtEnd : _renderNonTweeningValue);
plugin._pt = pt;
pt.b = beginning;
pt.e = end;
plugin._props.push(property);
return pt;
},
_nonConvertibleUnits = {
deg: 1,
rad: 1,
turn: 1
},
//takes a single value like 20px and converts it to the unit specified, like "%", returning only the numeric amount.
_convertToUnit = function _convertToUnit(target, property, value, unit) {
var curValue = parseFloat(value) || 0,
curUnit = (value + "").trim().substr((curValue + "").length) || "px",
// some browsers leave extra whitespace at the beginning of CSS variables, hence the need to trim()
style = _tempDiv.style,
horizontal = _horizontalExp.test(property),
isRootSVG = target.tagName.toLowerCase() === "svg",
measureProperty = (isRootSVG ? "client" : "offset") + (horizontal ? "Width" : "Height"),
amount = 100,
toPixels = unit === "px",
toPercent = unit === "%",
px,
parent,
cache,
isSVG;
if (unit === curUnit || !curValue || _nonConvertibleUnits[unit] || _nonConvertibleUnits[curUnit]) {
return curValue;
}
curUnit !== "px" && !toPixels && (curValue = _convertToUnit(target, property, value, "px"));
isSVG = target.getCTM && _isSVG(target);
if ((toPercent || curUnit === "%") && (_transformProps[property] || ~property.indexOf("adius"))) {
px = isSVG ? target.getBBox()[horizontal ? "width" : "height"] : target[measureProperty];
return _round(toPercent ? curValue / px * amount : curValue / 100 * px);
}
style[horizontal ? "width" : "height"] = amount + (toPixels ? curUnit : unit);
parent = ~property.indexOf("adius") || unit === "em" && target.appendChild && !isRootSVG ? target : target.parentNode;
if (isSVG) {
parent = (target.ownerSVGElement || {}).parentNode;
}
if (!parent || parent === _doc || !parent.appendChild) {
parent = _doc.body;
}
cache = parent._gsap;
if (cache && toPercent && cache.width && horizontal && cache.time === _ticker.time) {
return _round(curValue / cache.width * amount);
} else {
(toPercent || curUnit === "%") && (style.position = _getComputedProperty(target, "position"));
parent === target && (style.position = "static"); // like for borderRadius, if it's a % we must have it relative to the target itself but that may not have position: relative or position: absolute in which case it'd go up the chain until it finds its offsetParent (bad). position: static protects against that.
parent.appendChild(_tempDiv);
px = _tempDiv[measureProperty];
parent.removeChild(_tempDiv);
style.position = "absolute";
if (horizontal && toPercent) {
cache = _getCache(parent);
cache.time = _ticker.time;
cache.width = parent[measureProperty];
}
}
return _round(toPixels ? px * curValue / amount : px && curValue ? amount / px * curValue : 0);
},
_get = function _get(target, property, unit, uncache) {
var value;
_pluginInitted || _initCore();
if (property in _propertyAliases && property !== "transform") {
property = _propertyAliases[property];
if (~property.indexOf(",")) {
property = property.split(",")[0];
}
}
if (_transformProps[property] && property !== "transform") {
value = _parseTransform(target, uncache);
value = property !== "transformOrigin" ? value[property] : _firstTwoOnly(_getComputedProperty(target, _transformOriginProp)) + " " + value.zOrigin + "px";
} else {
value = target.style[property];
if (!value || value === "auto" || uncache || ~(value + "").indexOf("calc(")) {
value = _specialProps[property] && _specialProps[property](target, property, unit) || _getComputedProperty(target, property) || _getProperty(target, property) || (property === "opacity" ? 1 : 0); // note: some browsers, like Firefox, don't report borderRadius correctly! Instead, it only reports every corner like borderTopLeftRadius
}
}
return unit && !~(value + "").trim().indexOf(" ") ? _convertToUnit(target, property, value, unit) + unit : value;
},
_tweenComplexCSSString = function _tweenComplexCSSString(target, prop, start, end) {
//note: we call _tweenComplexCSSString.call(pluginInstance...) to ensure that it's scoped properly. We may call it from within a plugin too, thus "this" would refer to the plugin.
if (!start || start === "none") {
// some browsers like Safari actually PREFER the prefixed property and mis-report the unprefixed value like clipPath (BUG). In other words, even though clipPath exists in the style ("clipPath" in target.style) and it's set in the CSS properly (along with -webkit-clip-path), Safari reports clipPath as "none" whereas WebkitClipPath reports accurately like "ellipse(100% 0% at 50% 0%)", so in this case we must SWITCH to using the prefixed property instead. See https://greensock.com/forums/topic/18310-clippath-doesnt-work-on-ios/
var p = _checkPropPrefix(prop, target, 1),
s = p && _getComputedProperty(target, p, 1);
if (s && s !== start) {
prop = p;
start = s;
} else if (prop === "borderColor") {
start = _getComputedProperty(target, "borderTopColor"); // Firefox bug: always reports "borderColor" as "", so we must fall back to borderTopColor. See https://greensock.com/forums/topic/24583-how-to-return-colors-that-i-had-after-reverse/
}
}
var pt = new PropTween(this._pt, target.style, prop, 0, 1, _renderComplexString),
index = 0,
matchIndex = 0,
a,
result,
startValues,
startNum,
color,
startValue,
endValue,
endNum,
chunk,
endUnit,
startUnit,
relative,
endValues;
pt.b = start;
pt.e = end;
start += ""; //ensure values are strings
end += "";
if (end === "auto") {
target.style[prop] = end;
end = _getComputedProperty(target, prop) || end;
target.style[prop] = start;
}
a = [start, end];
_colorStringFilter(a); //pass an array with the starting and ending values and let the filter do whatever it needs to the values. If colors are found, it returns true and then we must match where the color shows up order-wise because for things like boxShadow, sometimes the browser provides the computed values with the color FIRST, but the user provides it with the color LAST, so flip them if necessary. Same for drop-shadow().
start = a[0];
end = a[1];
startValues = start.match(_numWithUnitExp) || [];
endValues = end.match(_numWithUnitExp) || [];
if (endValues.length) {
while (result = _numWithUnitExp.exec(end)) {
endValue = result[0];
chunk = end.substring(index, result.index);
if (color) {
color = (color + 1) % 5;
} else if (chunk.substr(-5) === "rgba(" || chunk.substr(-5) === "hsla(") {
color = 1;
}
if (endValue !== (startValue = startValues[matchIndex++] || "")) {
startNum = parseFloat(startValue) || 0;
startUnit = startValue.substr((startNum + "").length);
relative = endValue.charAt(1) === "=" ? +(endValue.charAt(0) + "1") : 0;
if (relative) {
endValue = endValue.substr(2);
}
endNum = parseFloat(endValue);
endUnit = endValue.substr((endNum + "").length);
index = _numWithUnitExp.lastIndex - endUnit.length;
if (!endUnit) {
//if something like "perspective:300" is passed in and we must add a unit to the end
endUnit = endUnit || _config.units[prop] || startUnit;
if (index === end.length) {
end += endUnit;
pt.e += endUnit;
}
}
if (startUnit !== endUnit) {
startNum = _convertToUnit(target, prop, startValue, endUnit) || 0;
} //these nested PropTweens are handled in a special way - we'll never actually call a render or setter method on them. We'll just loop through them in the parent complex string PropTween's render method.
pt._pt = {
_next: pt._pt,
p: chunk || matchIndex === 1 ? chunk : ",",
//note: SVG spec allows omission of comma/space when a negative sign is wedged between two numbers, like 2.5-5.3 instead of 2.5,-5.3 but when tweening, the negative value may switch to positive, so we insert the comma just in case.
s: startNum,
c: relative ? relative * endNum : endNum - startNum,
m: color && color < 4 || prop === "zIndex" ? Math.round : 0
};
}
}
pt.c = index < end.length ? end.substring(index, end.length) : ""; //we use the "c" of the PropTween to store the final part of the string (after the last number)
} else {
pt.r = prop === "display" && end === "none" ? _renderNonTweeningValueOnlyAtEnd : _renderNonTweeningValue;
}
_relExp.test(end) && (pt.e = 0); //if the end string contains relative values or dynamic random(...) values, delete the end it so that on the final render we don't actually set it to the string with += or -= characters (forces it to use the calculated value).
this._pt = pt; //start the linked list with this new PropTween. Remember, we call _tweenComplexCSSString.call(pluginInstance...) to ensure that it's scoped properly. We may call it from within another plugin too, thus "this" would refer to the plugin.
return pt;
},
_keywordToPercent = {
top: "0%",
bottom: "100%",
left: "0%",
right: "100%",
center: "50%"
},
_convertKeywordsToPercentages = function _convertKeywordsToPercentages(value) {
var split = value.split(" "),
x = split[0],
y = split[1] || "50%";
if (x === "top" || x === "bottom" || y === "left" || y === "right") {
//the user provided them in the wrong order, so flip them
value = x;
x = y;
y = value;
}
split[0] = _keywordToPercent[x] || x;
split[1] = _keywordToPercent[y] || y;
return split.join(" ");
},
_renderClearProps = function _renderClearProps(ratio, data) {
if (data.tween && data.tween._time === data.tween._dur) {
var target = data.t,
style = target.style,
props = data.u,
cache = target._gsap,
prop,
clearTransforms,
i;
if (props === "all" || props === true) {
style.cssText = "";
clearTransforms = 1;
} else {
props = props.split(",");
i = props.length;
while (--i > -1) {
prop = props[i];
if (_transformProps[prop]) {
clearTransforms = 1;
prop = prop === "transformOrigin" ? _transformOriginProp : _transformProp;
}
_removeProperty(target, prop);
}
}
if (clearTransforms) {
_removeProperty(target, _transformProp);
if (cache) {
cache.svg && target.removeAttribute("transform");
_parseTransform(target, 1); // force all the cached values back to "normal"/identity, otherwise if there's another tween that's already set to render transforms on this element, it could display the wrong values.
cache.uncache = 1;
}
}
}
},
// note: specialProps should return 1 if (and only if) they have a non-zero priority. It indicates we need to sort the linked list.
_specialProps = {
clearProps: function clearProps(plugin, target, property, endValue, tween) {
if (tween.data !== "isFromStart") {
var pt = plugin._pt = new PropTween(plugin._pt, target, property, 0, 0, _renderClearProps);
pt.u = endValue;
pt.pr = -10;
pt.tween = tween;
plugin._props.push(property);
return 1;
}
}
/* className feature (about 0.4kb gzipped).
, className(plugin, target, property, endValue, tween) {
let _renderClassName = (ratio, data) => {
data.css.render(ratio, data.css);
if (!ratio || ratio === 1) {
let inline = data.rmv,
target = data.t,
p;
target.setAttribute("class", ratio ? data.e : data.b);
for (p in inline) {
_removeProperty(target, p);
}
}
},
_getAllStyles = (target) => {
let styles = {},
computed = getComputedStyle(target),
p;
for (p in computed) {
if (isNaN(p) && p !== "cssText" && p !== "length") {
styles[p] = computed[p];
}
}
_setDefaults(styles, _parseTransform(target, 1));
return styles;
},
startClassList = target.getAttribute("class"),
style = target.style,
cssText = style.cssText,
cache = target._gsap,
classPT = cache.classPT,
inlineToRemoveAtEnd = {},
data = {t:target, plugin:plugin, rmv:inlineToRemoveAtEnd, b:startClassList, e:(endValue.charAt(1) !== "=") ? endValue : startClassList.replace(new RegExp("(?:\\s|^)" + endValue.substr(2) + "(?![\\w-])"), "") + ((endValue.charAt(0) === "+") ? " " + endValue.substr(2) : "")},
changingVars = {},
startVars = _getAllStyles(target),
transformRelated = /(transform|perspective)/i,
endVars, p;
if (classPT) {
classPT.r(1, classPT.d);
_removeLinkedListItem(classPT.d.plugin, classPT, "_pt");
}
target.setAttribute("class", data.e);
endVars = _getAllStyles(target, true);
target.setAttribute("class", startClassList);
for (p in endVars) {
if (endVars[p] !== startVars[p] && !transformRelated.test(p)) {
changingVars[p] = endVars[p];
if (!style[p] && style[p] !== "0") {
inlineToRemoveAtEnd[p] = 1;
}
}
}
cache.classPT = plugin._pt = new PropTween(plugin._pt, target, "className", 0, 0, _renderClassName, data, 0, -11);
if (style.cssText !== cssText) { //only apply if things change. Otherwise, in cases like a background-image that's pulled dynamically, it could cause a refresh. See https://greensock.com/forums/topic/20368-possible-gsap-bug-switching-classnames-in-chrome/.
style.cssText = cssText; //we recorded cssText before we swapped classes and ran _getAllStyles() because in cases when a className tween is overwritten, we remove all the related tweening properties from that class change (otherwise class-specific stuff can't override properties we've directly set on the target's style object due to specificity).
}
_parseTransform(target, true); //to clear the caching of transforms
data.css = new gsap.plugins.css();
data.css.init(target, changingVars, tween);
plugin._props.push(...data.css._props);
return 1;
}
*/
},
/*
* --------------------------------------------------------------------------------------
* TRANSFORMS
* --------------------------------------------------------------------------------------
*/
_identity2DMatrix = [1, 0, 0, 1, 0, 0],
_rotationalProperties = {},
_isNullTransform = function _isNullTransform(value) {
return value === "matrix(1, 0, 0, 1, 0, 0)" || value === "none" || !value;
},
_getComputedTransformMatrixAsArray = function _getComputedTransformMatrixAsArray(target) {
var matrixString = _getComputedProperty(target, _transformProp);
return _isNullTransform(matrixString) ? _identity2DMatrix : matrixString.substr(7).match(_numExp).map(_round);
},
_getMatrix = function _getMatrix(target, force2D) {
var cache = target._gsap || _getCache(target),
style = target.style,
matrix = _getComputedTransformMatrixAsArray(target),
parent,
nextSibling,
temp,
addedToDOM;
if (cache.svg && target.getAttribute("transform")) {
temp = target.transform.baseVal.consolidate().matrix; //ensures that even complex values like "translate(50,60) rotate(135,0,0)" are parsed because it mashes it into a matrix.
matrix = [temp.a, temp.b, temp.c, temp.d, temp.e, temp.f];
return matrix.join(",") === "1,0,0,1,0,0" ? _identity2DMatrix : matrix;
} else if (matrix === _identity2DMatrix && !target.offsetParent && target !== _docElement && !cache.svg) {
//note: if offsetParent is null, that means the element isn't in the normal document flow, like if it has display:none or one of its ancestors has display:none). Firefox returns null for getComputedStyle() if the element is in an iframe that has display:none. https://bugzilla.mozilla.org/show_bug.cgi?id=548397
//browsers don't report transforms accurately unless the element is in the DOM and has a display value that's not "none". Firefox and Microsoft browsers have a partial bug where they'll report transforms even if display:none BUT not any percentage-based values like translate(-50%, 8px) will be reported as if it's translate(0, 8px).
temp = style.display;
style.display = "block";
parent = target.parentNode;
if (!parent || !target.offsetParent) {
// note: in 3.3.0 we switched target.offsetParent to _doc.body.contains(target) to avoid [sometimes unnecessary] MutationObserver calls but that wasn't adequate because there are edge cases where nested position: fixed elements need to get reparented to accurately sense transforms. See https://github.com/greensock/GSAP/issues/388 and https://github.com/greensock/GSAP/issues/375
addedToDOM = 1; //flag
nextSibling = target.nextSibling;
_docElement.appendChild(target); //we must add it to the DOM in order to get values properly
}
matrix = _getComputedTransformMatrixAsArray(target);
temp ? style.display = temp : _removeProperty(target, "display");
if (addedToDOM) {
nextSibling ? parent.insertBefore(target, nextSibling) : parent ? parent.appendChild(target) : _docElement.removeChild(target);
}
}
return force2D && matrix.length > 6 ? [matrix[0], matrix[1], matrix[4], matrix[5], matrix[12], matrix[13]] : matrix;
},
_applySVGOrigin = function _applySVGOrigin(target, origin, originIsAbsolute, smooth, matrixArray, pluginToAddPropTweensTo) {
var cache = target._gsap,
matrix = matrixArray || _getMatrix(target, true),
xOriginOld = cache.xOrigin || 0,
yOriginOld = cache.yOrigin || 0,
xOffsetOld = cache.xOffset || 0,
yOffsetOld = cache.yOffset || 0,
a = matrix[0],
b = matrix[1],
c = matrix[2],
d = matrix[3],
tx = matrix[4],
ty = matrix[5],
originSplit = origin.split(" "),
xOrigin = parseFloat(originSplit[0]) || 0,
yOrigin = parseFloat(originSplit[1]) || 0,
bounds,
determinant,
x,
y;
if (!originIsAbsolute) {
bounds = _getBBox(target);
xOrigin = bounds.x + (~originSplit[0].indexOf("%") ? xOrigin / 100 * bounds.width : xOrigin);
yOrigin = bounds.y + (~(originSplit[1] || originSplit[0]).indexOf("%") ? yOrigin / 100 * bounds.height : yOrigin);
} else if (matrix !== _identity2DMatrix && (determinant = a * d - b * c)) {
//if it's zero (like if scaleX and scaleY are zero), skip it to avoid errors with dividing by zero.
x = xOrigin * (d / determinant) + yOrigin * (-c / determinant) + (c * ty - d * tx) / determinant;
y = xOrigin * (-b / determinant) + yOrigin * (a / determinant) - (a * ty - b * tx) / determinant;
xOrigin = x;
yOrigin = y;
}
if (smooth || smooth !== false && cache.smooth) {
tx = xOrigin - xOriginOld;
ty = yOrigin - yOriginOld;
cache.xOffset = xOffsetOld + (tx * a + ty * c) - tx;
cache.yOffset = yOffsetOld + (tx * b + ty * d) - ty;
} else {
cache.xOffset = cache.yOffset = 0;
}
cache.xOrigin = xOrigin;
cache.yOrigin = yOrigin;
cache.smooth = !!smooth;
cache.origin = origin;
cache.originIsAbsolute = !!originIsAbsolute;
target.style[_transformOriginProp] = "0px 0px"; //otherwise, if someone sets an origin via CSS, it will likely interfere with the SVG transform attribute ones (because remember, we're baking the origin into the matrix() value).
if (pluginToAddPropTweensTo) {
_addNonTweeningPT(pluginToAddPropTweensTo, cache, "xOrigin", xOriginOld, xOrigin);
_addNonTweeningPT(pluginToAddPropTweensTo, cache, "yOrigin", yOriginOld, yOrigin);
_addNonTweeningPT(pluginToAddPropTweensTo, cache, "xOffset", xOffsetOld, cache.xOffset);
_addNonTweeningPT(pluginToAddPropTweensTo, cache, "yOffset", yOffsetOld, cache.yOffset);
}
target.setAttribute("data-svg-origin", xOrigin + " " + yOrigin);
},
_parseTransform = function _parseTransform(target, uncache) {
var cache = target._gsap || new GSCache(target);
if ("x" in cache && !uncache && !cache.uncache) {
return cache;
}
var style = target.style,
invertedScaleX = cache.scaleX < 0,
px = "px",
deg = "deg",
origin = _getComputedProperty(target, _transformOriginProp) || "0",
x,
y,
z,
scaleX,
scaleY,
rotation,
rotationX,
rotationY,
skewX,
skewY,
perspective,
xOrigin,
yOrigin,
matrix,
angle,
cos,
sin,
a,
b,
c,
d,
a12,
a22,
t1,
t2,
t3,
a13,
a23,
a33,
a42,
a43,
a32;
x = y = z = rotation = rotationX = rotationY = skewX = skewY = perspective = 0;
scaleX = scaleY = 1;
cache.svg = !!(target.getCTM && _isSVG(target));
matrix = _getMatrix(target, cache.svg);
if (cache.svg) {
t1 = !cache.uncache && !uncache && target.getAttribute("data-svg-origin");
_applySVGOrigin(target, t1 || origin, !!t1 || cache.originIsAbsolute, cache.smooth !== false, matrix);
}
xOrigin = cache.xOrigin || 0;
yOrigin = cache.yOrigin || 0;
if (matrix !== _identity2DMatrix) {
a = matrix[0]; //a11
b = matrix[1]; //a21
c = matrix[2]; //a31
d = matrix[3]; //a41
x = a12 = matrix[4];
y = a22 = matrix[5]; //2D matrix
if (matrix.length === 6) {
scaleX = Math.sqrt(a * a + b * b);
scaleY = Math.sqrt(d * d + c * c);
rotation = a || b ? _atan2(b, a) * _RAD2DEG : 0; //note: if scaleX is 0, we cannot accurately measure rotation. Same for skewX with a scaleY of 0. Therefore, we default to the previously recorded value (or zero if that doesn't exist).
skewX = c || d ? _atan2(c, d) * _RAD2DEG + rotation : 0;
skewX && (scaleY *= Math.abs(Math.cos(skewX * _DEG2RAD)));
if (cache.svg) {
x -= xOrigin - (xOrigin * a + yOrigin * c);
y -= yOrigin - (xOrigin * b + yOrigin * d);
} //3D matrix
} else {
a32 = matrix[6];
a42 = matrix[7];
a13 = matrix[8];
a23 = matrix[9];
a33 = matrix[10];
a43 = matrix[11];
x = matrix[12];
y = matrix[13];
z = matrix[14];
angle = _atan2(a32, a33);
rotationX = angle * _RAD2DEG; //rotationX
if (angle) {
cos = Math.cos(-angle);
sin = Math.sin(-angle);
t1 = a12 * cos + a13 * sin;
t2 = a22 * cos + a23 * sin;
t3 = a32 * cos + a33 * sin;
a13 = a12 * -sin + a13 * cos;
a23 = a22 * -sin + a23 * cos;
a33 = a32 * -sin + a33 * cos;
a43 = a42 * -sin + a43 * cos;
a12 = t1;
a22 = t2;
a32 = t3;
} //rotationY
angle = _atan2(-c, a33);
rotationY = angle * _RAD2DEG;
if (angle) {
cos = Math.cos(-angle);
sin = Math.sin(-angle);
t1 = a * cos - a13 * sin;
t2 = b * cos - a23 * sin;
t3 = c * cos - a33 * sin;
a43 = d * sin + a43 * cos;
a = t1;
b = t2;
c = t3;
} //rotationZ
angle = _atan2(b, a);
rotation = angle * _RAD2DEG;
if (angle) {
cos = Math.cos(angle);
sin = Math.sin(angle);
t1 = a * cos + b * sin;
t2 = a12 * cos + a22 * sin;
b = b * cos - a * sin;
a22 = a22 * cos - a12 * sin;
a = t1;
a12 = t2;
}
if (rotationX && Math.abs(rotationX) + Math.abs(rotation) > 359.9) {
//when rotationY is set, it will often be parsed as 180 degrees different than it should be, and rotationX and rotation both being 180 (it looks the same), so we adjust for that here.
rotationX = rotation = 0;
rotationY = 180 - rotationY;
}
scaleX = _round(Math.sqrt(a * a + b * b + c * c));
scaleY = _round(Math.sqrt(a22 * a22 + a32 * a32));
angle = _atan2(a12, a22);
skewX = Math.abs(angle) > 0.0002 ? angle * _RAD2DEG : 0;
perspective = a43 ? 1 / (a43 < 0 ? -a43 : a43) : 0;
}
if (cache.svg) {
//sense if there are CSS transforms applied on an SVG element in which case we must overwrite them when rendering. The transform attribute is more reliable cross-browser, but we can't just remove the CSS ones because they may be applied in a CSS rule somewhere (not just inline).
t1 = target.getAttribute("transform");
cache.forceCSS = target.setAttribute("transform", "") || !_isNullTransform(_getComputedProperty(target, _transformProp));
t1 && target.setAttribute("transform", t1);
}
}
if (Math.abs(skewX) > 90 && Math.abs(skewX) < 270) {
if (invertedScaleX) {
scaleX *= -1;
skewX += rotation <= 0 ? 180 : -180;
rotation += rotation <= 0 ? 180 : -180;
} else {
scaleY *= -1;
skewX += skewX <= 0 ? 180 : -180;
}
}
cache.x = x - ((cache.xPercent = x && (cache.xPercent || (Math.round(target.offsetWidth / 2) === Math.round(-x) ? -50 : 0))) ? target.offsetWidth * cache.xPercent / 100 : 0) + px;
cache.y = y - ((cache.yPercent = y && (cache.yPercent || (Math.round(target.offsetHeight / 2) === Math.round(-y) ? -50 : 0))) ? target.offsetHeight * cache.yPercent / 100 : 0) + px;
cache.z = z + px;
cache.scaleX = _round(scaleX);
cache.scaleY = _round(scaleY);
cache.rotation = _round(rotation) + deg;
cache.rotationX = _round(rotationX) + deg;
cache.rotationY = _round(rotationY) + deg;
cache.skewX = skewX + deg;
cache.skewY = skewY + deg;
cache.transformPerspective = perspective + px;
if (cache.zOrigin = parseFloat(origin.split(" ")[2]) || 0) {
style[_transformOriginProp] = _firstTwoOnly(origin);
}
cache.xOffset = cache.yOffset = 0;
cache.force3D = _config.force3D;
cache.renderTransform = cache.svg ? _renderSVGTransforms : _supports3D ? _renderCSSTransforms : _renderNon3DTransforms;
cache.uncache = 0;
return cache;
},
_firstTwoOnly = function _firstTwoOnly(value) {
return (value = value.split(" "))[0] + " " + value[1];
},
//for handling transformOrigin values, stripping out the 3rd dimension
_addPxTranslate = function _addPxTranslate(target, start, value) {
var unit = getUnit(start);
return _round(parseFloat(start) + parseFloat(_convertToUnit(target, "x", value + "px", unit))) + unit;
},
_renderNon3DTransforms = function _renderNon3DTransforms(ratio, cache) {
cache.z = "0px";
cache.rotationY = cache.rotationX = "0deg";
cache.force3D = 0;
_renderCSSTransforms(ratio, cache);
},
_zeroDeg = "0deg",
_zeroPx = "0px",
_endParenthesis = ") ",
_renderCSSTransforms = function _renderCSSTransforms(ratio, cache) {
var _ref = cache || this,
xPercent = _ref.xPercent,
yPercent = _ref.yPercent,
x = _ref.x,
y = _ref.y,
z = _ref.z,
rotation = _ref.rotation,
rotationY = _ref.rotationY,
rotationX = _ref.rotationX,
skewX = _ref.skewX,
skewY = _ref.skewY,
scaleX = _ref.scaleX,
scaleY = _ref.scaleY,
transformPerspective = _ref.transformPerspective,
force3D = _ref.force3D,
target = _ref.target,
zOrigin = _ref.zOrigin,
transforms = "",
use3D = force3D === "auto" && ratio && ratio !== 1 || force3D === true; // Safari has a bug that causes it not to render 3D transform-origin values properly, so we force the z origin to 0, record it in the cache, and then do the math here to offset the translate values accordingly (basically do the 3D transform-origin part manually)
if (zOrigin && (rotationX !== _zeroDeg || rotationY !== _zeroDeg)) {
var angle = parseFloat(rotationY) * _DEG2RAD,
a13 = Math.sin(angle),
a33 = Math.cos(angle),
cos;
angle = parseFloat(rotationX) * _DEG2RAD;
cos = Math.cos(angle);
x = _addPxTranslate(target, x, a13 * cos * -zOrigin);
y = _addPxTranslate(target, y, -Math.sin(angle) * -zOrigin);
z = _addPxTranslate(target, z, a33 * cos * -zOrigin + zOrigin);
}
if (transformPerspective !== _zeroPx) {
transforms += "perspective(" + transformPerspective + _endParenthesis;
}
if (xPercent || yPercent) {
transforms += "translate(" + xPercent + "%, " + yPercent + "%) ";
}
if (use3D || x !== _zeroPx || y !== _zeroPx || z !== _zeroPx) {
transforms += z !== _zeroPx || use3D ? "translate3d(" + x + ", " + y + ", " + z + ") " : "translate(" + x + ", " + y + _endParenthesis;
}
if (rotation !== _zeroDeg) {
transforms += "rotate(" + rotation + _endParenthesis;
}
if (rotationY !== _zeroDeg) {
transforms += "rotateY(" + rotationY + _endParenthesis;
}
if (rotationX !== _zeroDeg) {
transforms += "rotateX(" + rotationX + _endParenthesis;
}
if (skewX !== _zeroDeg || skewY !== _zeroDeg) {
transforms += "skew(" + skewX + ", " + skewY + _endParenthesis;
}
if (scaleX !== 1 || scaleY !== 1) {
transforms += "scale(" + scaleX + ", " + scaleY + _endParenthesis;
}
target.style[_transformProp] = transforms || "translate(0, 0)";
},
_renderSVGTransforms = function _renderSVGTransforms(ratio, cache) {
var _ref2 = cache || this,
xPercent = _ref2.xPercent,
yPercent = _ref2.yPercent,
x = _ref2.x,
y = _ref2.y,
rotation = _ref2.rotation,
skewX = _ref2.skewX,
skewY = _ref2.skewY,
scaleX = _ref2.scaleX,
scaleY = _ref2.scaleY,
target = _ref2.target,
xOrigin = _ref2.xOrigin,
yOrigin = _ref2.yOrigin,
xOffset = _ref2.xOffset,
yOffset = _ref2.yOffset,
forceCSS = _ref2.forceCSS,
tx = parseFloat(x),
ty = parseFloat(y),
a11,
a21,
a12,
a22,
temp;