-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSSRulePlugin.js
134 lines (114 loc) · 3.47 KB
/
CSSRulePlugin.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
/*!
* CSSRulePlugin 3.12.2
* https://greensock.com
*
* @license Copyright 2008-2023, 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 */
var gsap,
_coreInitted,
_win,
_doc,
CSSPlugin,
_windowExists = function _windowExists() {
return typeof window !== "undefined";
},
_getGSAP = function _getGSAP() {
return gsap || _windowExists() && (gsap = window.gsap) && gsap.registerPlugin && gsap;
},
_checkRegister = function _checkRegister() {
if (!_coreInitted) {
_initCore();
if (!CSSPlugin) {
console.warn("Please gsap.registerPlugin(CSSPlugin, CSSRulePlugin)");
}
}
return _coreInitted;
},
_initCore = function _initCore(core) {
gsap = core || _getGSAP();
if (_windowExists()) {
_win = window;
_doc = document;
}
if (gsap) {
CSSPlugin = gsap.plugins.css;
if (CSSPlugin) {
_coreInitted = 1;
}
}
};
export var CSSRulePlugin = {
version: "3.12.2",
name: "cssRule",
init: function init(target, value, tween, index, targets) {
if (!_checkRegister() || typeof target.cssText === "undefined") {
return false;
}
var div = target._gsProxy = target._gsProxy || _doc.createElement("div");
this.ss = target;
this.style = div.style;
div.style.cssText = target.cssText;
CSSPlugin.prototype.init.call(this, div, value, tween, index, targets); //we just offload all the work to the regular CSSPlugin and then copy the cssText back over to the rule in the render() method. This allows us to have all of the updates to CSSPlugin automatically flow through to CSSRulePlugin instead of having to maintain both
},
render: function render(ratio, data) {
var pt = data._pt,
style = data.style,
ss = data.ss,
i;
while (pt) {
pt.r(ratio, pt.d);
pt = pt._next;
}
i = style.length;
while (--i > -1) {
ss[style[i]] = style[style[i]];
}
},
getRule: function getRule(selector) {
_checkRegister();
var ruleProp = _doc.all ? "rules" : "cssRules",
styleSheets = _doc.styleSheets,
i = styleSheets.length,
pseudo = selector.charAt(0) === ":",
j,
curSS,
cs,
a;
selector = (pseudo ? "" : ",") + selector.split("::").join(":").toLowerCase() + ","; //note: old versions of IE report tag name selectors as upper case, so we just change everything to lowercase.
if (pseudo) {
a = [];
}
while (i--) {
//Firefox may throw insecure operation errors when css is loaded from other domains, so try/catch.
try {
curSS = styleSheets[i][ruleProp];
if (!curSS) {
continue;
}
j = curSS.length;
} catch (e) {
console.warn(e);
continue;
}
while (--j > -1) {
cs = curSS[j];
if (cs.selectorText && ("," + cs.selectorText.split("::").join(":").toLowerCase() + ",").indexOf(selector) !== -1) {
//note: IE adds an extra ":" to pseudo selectors, so .myClass:after becomes .myClass::after, so we need to strip the extra one out.
if (pseudo) {
a.push(cs.style);
} else {
return cs.style;
}
}
}
}
return a;
},
register: _initCore
};
_getGSAP() && gsap.registerPlugin(CSSRulePlugin);
export { CSSRulePlugin as default };