UNPKG

3.4 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3 typeof define === 'function' && define.amd ? define(['exports'], factory) :
4 (global = global || self, factory(global.window = global.window || {}));
5}(this, (function (exports) { 'use strict';
6
7 /*!
8 * CSSRulePlugin 3.4.2
9 * https://greensock.com
10 *
11 * @license Copyright 2008-2020, GreenSock. All rights reserved.
12 * Subject to the terms at https://greensock.com/standard-license or for
13 * Club GreenSock members, the agreement issued with that membership.
14 * @author: Jack Doyle, jack@greensock.com
15 */
16 var gsap,
17 _coreInitted,
18 _doc,
19 CSSPlugin,
20 _windowExists = function _windowExists() {
21 return typeof window !== "undefined";
22 },
23 _getGSAP = function _getGSAP() {
24 return gsap || _windowExists() && (gsap = window.gsap) && gsap.registerPlugin && gsap;
25 },
26 _checkRegister = function _checkRegister() {
27 if (!_coreInitted) {
28 _initCore();
29
30 if (!CSSPlugin) {
31 console.warn("Please gsap.registerPlugin(CSSPlugin, CSSRulePlugin)");
32 }
33 }
34
35 return _coreInitted;
36 },
37 _initCore = function _initCore(core) {
38 gsap = core || _getGSAP();
39
40 if (_windowExists()) {
41 _doc = document;
42 }
43
44 if (gsap) {
45 CSSPlugin = gsap.plugins.css;
46
47 if (CSSPlugin) {
48 _coreInitted = 1;
49 }
50 }
51 };
52
53 var CSSRulePlugin = {
54 version: "3.4.2",
55 name: "cssRule",
56 init: function init(target, value, tween, index, targets) {
57 if (!_checkRegister() || typeof target.cssText === "undefined") {
58 return false;
59 }
60
61 var div = target._gsProxy = target._gsProxy || _doc.createElement("div");
62
63 this.ss = target;
64 this.style = div.style;
65 div.style.cssText = target.cssText;
66 CSSPlugin.prototype.init.call(this, div, value, tween, index, targets);
67 },
68 render: function render(ratio, data) {
69 var pt = data._pt,
70 style = data.style,
71 ss = data.ss,
72 i;
73
74 while (pt) {
75 pt.r(ratio, pt.d);
76 pt = pt._next;
77 }
78
79 i = style.length;
80
81 while (--i > -1) {
82 ss[style[i]] = style[style[i]];
83 }
84 },
85 getRule: function getRule(selector) {
86 _checkRegister();
87
88 var ruleProp = _doc.all ? "rules" : "cssRules",
89 styleSheets = _doc.styleSheets,
90 i = styleSheets.length,
91 pseudo = selector.charAt(0) === ":",
92 j,
93 curSS,
94 cs,
95 a;
96 selector = (pseudo ? "" : ",") + selector.split("::").join(":").toLowerCase() + ",";
97
98 if (pseudo) {
99 a = [];
100 }
101
102 while (i--) {
103 try {
104 curSS = styleSheets[i][ruleProp];
105
106 if (!curSS) {
107 continue;
108 }
109
110 j = curSS.length;
111 } catch (e) {
112 console.warn(e);
113 continue;
114 }
115
116 while (--j > -1) {
117 cs = curSS[j];
118
119 if (cs.selectorText && ("," + cs.selectorText.split("::").join(":").toLowerCase() + ",").indexOf(selector) !== -1) {
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
135 exports.CSSRulePlugin = CSSRulePlugin;
136 exports.default = CSSRulePlugin;
137
138 Object.defineProperty(exports, '__esModule', { value: true });
139
140})));