UNPKG

3.56 kBJavaScriptView Raw
1/*!
2 * CSSRulePlugin 3.10.3
3 * https://greensock.com
4 *
5 * @license Copyright 2008-2022, GreenSock. All rights reserved.
6 * Subject to the terms at https://greensock.com/standard-license or for
7 * Club GreenSock members, the agreement issued with that membership.
8 * @author: Jack Doyle, jack@greensock.com
9*/
10
11/* eslint-disable */
12var 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
51export 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); //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
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() + ","; //note: old versions of IE report tag name selectors as upper case, so we just change everything to lowercase.
95
96 if (pseudo) {
97 a = [];
98 }
99
100 while (i--) {
101 //Firefox may throw insecure operation errors when css is loaded from other domains, so try/catch.
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 //note: IE adds an extra ":" to pseudo selectors, so .myClass:after becomes .myClass::after, so we need to strip the extra one out.
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);
134export { CSSRulePlugin as default };
\No newline at end of file