1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var gsap,
|
13 | _coreInitted,
|
14 | _win,
|
15 | _doc,
|
16 | CSSPlugin,
|
17 | _windowExists = function _windowExists() {
|
18 | return typeof window !== "undefined";
|
19 | },
|
20 | _getGSAP = function _getGSAP() {
|
21 | return gsap || _windowExists() && (gsap = window.gsap) && gsap.registerPlugin && gsap;
|
22 | },
|
23 | _checkRegister = function _checkRegister() {
|
24 | if (!_coreInitted) {
|
25 | _initCore();
|
26 |
|
27 | if (!CSSPlugin) {
|
28 | console.warn("Please gsap.registerPlugin(CSSPlugin, CSSRulePlugin)");
|
29 | }
|
30 | }
|
31 |
|
32 | return _coreInitted;
|
33 | },
|
34 | _initCore = function _initCore(core) {
|
35 | gsap = core || _getGSAP();
|
36 |
|
37 | if (_windowExists()) {
|
38 | _win = window;
|
39 | _doc = document;
|
40 | }
|
41 |
|
42 | if (gsap) {
|
43 | CSSPlugin = gsap.plugins.css;
|
44 |
|
45 | if (CSSPlugin) {
|
46 | _coreInitted = 1;
|
47 | }
|
48 | }
|
49 | };
|
50 |
|
51 | export var CSSRulePlugin = {
|
52 | version: "3.10.3",
|
53 | name: "cssRule",
|
54 | init: function init(target, value, tween, index, targets) {
|
55 | if (!_checkRegister() || typeof target.cssText === "undefined") {
|
56 | return false;
|
57 | }
|
58 |
|
59 | var div = target._gsProxy = target._gsProxy || _doc.createElement("div");
|
60 |
|
61 | this.ss = target;
|
62 | this.style = div.style;
|
63 | div.style.cssText = target.cssText;
|
64 | CSSPlugin.prototype.init.call(this, div, value, tween, index, targets);
|
65 | },
|
66 | render: function render(ratio, data) {
|
67 | var pt = data._pt,
|
68 | style = data.style,
|
69 | ss = data.ss,
|
70 | i;
|
71 |
|
72 | while (pt) {
|
73 | pt.r(ratio, pt.d);
|
74 | pt = pt._next;
|
75 | }
|
76 |
|
77 | i = style.length;
|
78 |
|
79 | while (--i > -1) {
|
80 | ss[style[i]] = style[style[i]];
|
81 | }
|
82 | },
|
83 | getRule: function getRule(selector) {
|
84 | _checkRegister();
|
85 |
|
86 | var ruleProp = _doc.all ? "rules" : "cssRules",
|
87 | styleSheets = _doc.styleSheets,
|
88 | i = styleSheets.length,
|
89 | pseudo = selector.charAt(0) === ":",
|
90 | j,
|
91 | curSS,
|
92 | cs,
|
93 | a;
|
94 | selector = (pseudo ? "" : ",") + selector.split("::").join(":").toLowerCase() + ",";
|
95 |
|
96 | if (pseudo) {
|
97 | a = [];
|
98 | }
|
99 |
|
100 | while (i--) {
|
101 |
|
102 | try {
|
103 | curSS = styleSheets[i][ruleProp];
|
104 |
|
105 | if (!curSS) {
|
106 | continue;
|
107 | }
|
108 |
|
109 | j = curSS.length;
|
110 | } catch (e) {
|
111 | console.warn(e);
|
112 | continue;
|
113 | }
|
114 |
|
115 | while (--j > -1) {
|
116 | cs = curSS[j];
|
117 |
|
118 | if (cs.selectorText && ("," + cs.selectorText.split("::").join(":").toLowerCase() + ",").indexOf(selector) !== -1) {
|
119 |
|
120 | if (pseudo) {
|
121 | a.push(cs.style);
|
122 | } else {
|
123 | return cs.style;
|
124 | }
|
125 | }
|
126 | }
|
127 | }
|
128 |
|
129 | return a;
|
130 | },
|
131 | register: _initCore
|
132 | };
|
133 | _getGSAP() && gsap.registerPlugin(CSSRulePlugin);
|
134 | export { CSSRulePlugin as default }; |
\ | No newline at end of file |