@acemir/cssom 0.9.15 → 0.9.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/CSSOM.js +562 -88
- package/lib/CSSFontFaceRule.js +21 -2
- package/lib/CSSGroupingRule.js +5 -4
- package/lib/CSSKeyframeRule.js +22 -3
- package/lib/CSSKeyframesRule.js +199 -5
- package/lib/CSSNestedDeclarations.js +23 -2
- package/lib/CSSRule.js +39 -26
- package/lib/CSSStyleRule.js +38 -6
- package/lib/CSSStyleSheet.js +8 -7
- package/lib/StyleSheet.js +8 -1
- package/lib/clone.js +6 -0
- package/lib/cssstyleTryCatchBlock.js +5 -0
- package/lib/errorUtils.js +118 -0
- package/lib/index.js +5 -0
- package/lib/parse.js +36 -30
- package/package.json +1 -1
package/lib/CSSFontFaceRule.js
CHANGED
|
@@ -3,6 +3,12 @@ var CSSOM = {
|
|
|
3
3
|
CSSStyleDeclaration: require("./CSSStyleDeclaration").CSSStyleDeclaration,
|
|
4
4
|
CSSRule: require("./CSSRule").CSSRule
|
|
5
5
|
};
|
|
6
|
+
// Use cssstyle if available
|
|
7
|
+
try {
|
|
8
|
+
CSSOM.CSSStyleDeclaration = require("cssstyle").CSSStyleDeclaration;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
// ignore
|
|
11
|
+
}
|
|
6
12
|
///CommonJS
|
|
7
13
|
|
|
8
14
|
|
|
@@ -12,8 +18,8 @@ var CSSOM = {
|
|
|
12
18
|
*/
|
|
13
19
|
CSSOM.CSSFontFaceRule = function CSSFontFaceRule() {
|
|
14
20
|
CSSOM.CSSRule.call(this);
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
21
|
+
this.__style = new CSSOM.CSSStyleDeclaration();
|
|
22
|
+
this.__style.parentRule = this;
|
|
17
23
|
};
|
|
18
24
|
|
|
19
25
|
CSSOM.CSSFontFaceRule.prototype = new CSSOM.CSSRule();
|
|
@@ -23,6 +29,19 @@ CSSOM.CSSFontFaceRule.prototype.type = 5;
|
|
|
23
29
|
//CSSOM.CSSFontFaceRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
|
|
24
30
|
//CSSOM.CSSFontFaceRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
|
|
25
31
|
|
|
32
|
+
Object.defineProperty(CSSOM.CSSFontFaceRule.prototype, "style", {
|
|
33
|
+
get: function() {
|
|
34
|
+
return this.__style;
|
|
35
|
+
},
|
|
36
|
+
set: function(value) {
|
|
37
|
+
if (typeof value === "string") {
|
|
38
|
+
this.__style.cssText = value;
|
|
39
|
+
} else {
|
|
40
|
+
this.__style = value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
26
45
|
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSFontFaceRule.cpp
|
|
27
46
|
Object.defineProperty(CSSOM.CSSFontFaceRule.prototype, "cssText", {
|
|
28
47
|
get: function() {
|
package/lib/CSSGroupingRule.js
CHANGED
|
@@ -3,6 +3,7 @@ var CSSOM = {
|
|
|
3
3
|
CSSRule: require("./CSSRule").CSSRule,
|
|
4
4
|
parse: require('./parse').parse
|
|
5
5
|
};
|
|
6
|
+
var errorUtils = require("./errorUtils").errorUtils;
|
|
6
7
|
///CommonJS
|
|
7
8
|
|
|
8
9
|
|
|
@@ -37,10 +38,10 @@ CSSOM.CSSGroupingRule.prototype.constructor = CSSOM.CSSGroupingRule;
|
|
|
37
38
|
*/
|
|
38
39
|
CSSOM.CSSGroupingRule.prototype.insertRule = function insertRule(rule, index) {
|
|
39
40
|
if (index < 0 || index > this.cssRules.length) {
|
|
40
|
-
|
|
41
|
+
errorUtils.throwIndexSizeError(this);
|
|
41
42
|
}
|
|
42
43
|
var cssRule = CSSOM.parse(rule).cssRules[0];
|
|
43
|
-
cssRule.
|
|
44
|
+
cssRule.__parentRule = this;
|
|
44
45
|
this.cssRules.splice(index, 0, cssRule);
|
|
45
46
|
return index;
|
|
46
47
|
};
|
|
@@ -59,9 +60,9 @@ CSSOM.CSSGroupingRule.prototype.constructor = CSSOM.CSSGroupingRule;
|
|
|
59
60
|
*/
|
|
60
61
|
CSSOM.CSSGroupingRule.prototype.deleteRule = function deleteRule(index) {
|
|
61
62
|
if (index < 0 || index >= this.cssRules.length) {
|
|
62
|
-
|
|
63
|
+
errorUtils.throwIndexSizeError(this);
|
|
63
64
|
}
|
|
64
|
-
this.cssRules.splice(index, 1)[0].
|
|
65
|
+
this.cssRules.splice(index, 1)[0].__parentRule = null;
|
|
65
66
|
};
|
|
66
67
|
|
|
67
68
|
//.CommonJS
|
package/lib/CSSKeyframeRule.js
CHANGED
|
@@ -3,6 +3,12 @@ var CSSOM = {
|
|
|
3
3
|
CSSRule: require("./CSSRule").CSSRule,
|
|
4
4
|
CSSStyleDeclaration: require('./CSSStyleDeclaration').CSSStyleDeclaration
|
|
5
5
|
};
|
|
6
|
+
// Use cssstyle if available
|
|
7
|
+
try {
|
|
8
|
+
CSSOM.CSSStyleDeclaration = require("cssstyle").CSSStyleDeclaration;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
// ignore
|
|
11
|
+
}
|
|
6
12
|
///CommonJS
|
|
7
13
|
|
|
8
14
|
|
|
@@ -13,8 +19,8 @@ var CSSOM = {
|
|
|
13
19
|
CSSOM.CSSKeyframeRule = function CSSKeyframeRule() {
|
|
14
20
|
CSSOM.CSSRule.call(this);
|
|
15
21
|
this.keyText = '';
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
22
|
+
this.__style = new CSSOM.CSSStyleDeclaration();
|
|
23
|
+
this.__style.parentRule = this;
|
|
18
24
|
};
|
|
19
25
|
|
|
20
26
|
CSSOM.CSSKeyframeRule.prototype = new CSSOM.CSSRule();
|
|
@@ -24,10 +30,23 @@ CSSOM.CSSKeyframeRule.prototype.type = 8;
|
|
|
24
30
|
//CSSOM.CSSKeyframeRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
|
|
25
31
|
//CSSOM.CSSKeyframeRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
|
|
26
32
|
|
|
33
|
+
Object.defineProperty(CSSOM.CSSKeyframeRule.prototype, "style", {
|
|
34
|
+
get: function() {
|
|
35
|
+
return this.__style;
|
|
36
|
+
},
|
|
37
|
+
set: function(value) {
|
|
38
|
+
if (typeof value === "string") {
|
|
39
|
+
this.__style.cssText = value;
|
|
40
|
+
} else {
|
|
41
|
+
this.__style = value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
27
46
|
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSKeyframeRule.cpp
|
|
28
47
|
Object.defineProperty(CSSOM.CSSKeyframeRule.prototype, "cssText", {
|
|
29
48
|
get: function() {
|
|
30
|
-
return this.keyText + " { " + this.style.cssText + " }
|
|
49
|
+
return this.keyText + " { " + this.style.cssText + " }";
|
|
31
50
|
}
|
|
32
51
|
});
|
|
33
52
|
|
package/lib/CSSKeyframesRule.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
//.CommonJS
|
|
2
2
|
var CSSOM = {
|
|
3
|
-
CSSRule: require("./CSSRule").CSSRule
|
|
3
|
+
CSSRule: require("./CSSRule").CSSRule,
|
|
4
|
+
parse: require("./parse").parse
|
|
4
5
|
};
|
|
6
|
+
var errorUtils = require("./errorUtils").errorUtils;
|
|
5
7
|
///CommonJS
|
|
6
8
|
|
|
7
9
|
|
|
@@ -13,14 +15,42 @@ CSSOM.CSSKeyframesRule = function CSSKeyframesRule() {
|
|
|
13
15
|
CSSOM.CSSRule.call(this);
|
|
14
16
|
this.name = '';
|
|
15
17
|
this.cssRules = [];
|
|
18
|
+
|
|
19
|
+
// Set up initial indexed access
|
|
20
|
+
this._setupIndexedAccess();
|
|
21
|
+
|
|
22
|
+
// Override cssRules methods after initial setup, store references as non-enumerable properties
|
|
23
|
+
var self = this;
|
|
24
|
+
var originalPush = this.cssRules.push;
|
|
25
|
+
var originalSplice = this.cssRules.splice;
|
|
26
|
+
|
|
27
|
+
// Create non-enumerable method overrides
|
|
28
|
+
Object.defineProperty(this.cssRules, 'push', {
|
|
29
|
+
value: function() {
|
|
30
|
+
var result = originalPush.apply(this, arguments);
|
|
31
|
+
self._setupIndexedAccess();
|
|
32
|
+
return result;
|
|
33
|
+
},
|
|
34
|
+
writable: true,
|
|
35
|
+
enumerable: false,
|
|
36
|
+
configurable: true
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
Object.defineProperty(this.cssRules, 'splice', {
|
|
40
|
+
value: function() {
|
|
41
|
+
var result = originalSplice.apply(this, arguments);
|
|
42
|
+
self._setupIndexedAccess();
|
|
43
|
+
return result;
|
|
44
|
+
},
|
|
45
|
+
writable: true,
|
|
46
|
+
enumerable: false,
|
|
47
|
+
configurable: true
|
|
48
|
+
});
|
|
16
49
|
};
|
|
17
50
|
|
|
18
51
|
CSSOM.CSSKeyframesRule.prototype = new CSSOM.CSSRule();
|
|
19
52
|
CSSOM.CSSKeyframesRule.prototype.constructor = CSSOM.CSSKeyframesRule;
|
|
20
53
|
CSSOM.CSSKeyframesRule.prototype.type = 7;
|
|
21
|
-
//FIXME
|
|
22
|
-
//CSSOM.CSSKeyframesRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
|
|
23
|
-
//CSSOM.CSSKeyframesRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
|
|
24
54
|
|
|
25
55
|
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSKeyframesRule.cpp
|
|
26
56
|
Object.defineProperty(CSSOM.CSSKeyframesRule.prototype, "cssText", {
|
|
@@ -29,10 +59,174 @@ Object.defineProperty(CSSOM.CSSKeyframesRule.prototype, "cssText", {
|
|
|
29
59
|
for (var i=0, length=this.cssRules.length; i < length; i++) {
|
|
30
60
|
cssTexts.push(this.cssRules[i].cssText);
|
|
31
61
|
}
|
|
32
|
-
|
|
62
|
+
var cssWideKeywords = ['initial', 'inherit', 'revert', 'revert-layer', 'unset', 'none'];
|
|
63
|
+
var processedName = cssWideKeywords.includes(this.name) ? '"' + this.name + '"' : this.name;
|
|
64
|
+
return "@" + (this._vendorPrefix || '') + "keyframes " + processedName + (processedName && " ") + "{" + (cssTexts.length ? "\n " + cssTexts.join("\n ") : "") + "\n}";
|
|
33
65
|
}
|
|
34
66
|
});
|
|
35
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Appends a new keyframe rule to the list of keyframes.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} rule - The keyframe rule string to append (e.g., "50% { opacity: 0.5; }")
|
|
72
|
+
* @see https://www.w3.org/TR/css-animations-1/#dom-csskeyframesrule-appendrule
|
|
73
|
+
*/
|
|
74
|
+
CSSOM.CSSKeyframesRule.prototype.appendRule = function appendRule(rule) {
|
|
75
|
+
if (arguments.length === 0) {
|
|
76
|
+
errorUtils.throwMissingArguments(this, 'appendRule', 'CSSKeyframesRule');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var parsedRule;
|
|
80
|
+
try {
|
|
81
|
+
// Parse the rule string as a keyframe rule
|
|
82
|
+
var tempStyleSheet = CSSOM.parse("@keyframes temp { " + rule + " }");
|
|
83
|
+
if (tempStyleSheet.cssRules.length > 0 && tempStyleSheet.cssRules[0].cssRules.length > 0) {
|
|
84
|
+
parsedRule = tempStyleSheet.cssRules[0].cssRules[0];
|
|
85
|
+
} else {
|
|
86
|
+
throw new Error("Failed to parse keyframe rule");
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
errorUtils.throwParseError(this, 'appendRule', 'CSSKeyframesRule', rule);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
parsedRule.__parentRule = this;
|
|
93
|
+
this.cssRules.push(parsedRule);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Deletes a keyframe rule that matches the specified key.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} select - The keyframe selector to delete (e.g., "50%", "from", "to")
|
|
100
|
+
* @see https://www.w3.org/TR/css-animations-1/#dom-csskeyframesrule-deleterule
|
|
101
|
+
*/
|
|
102
|
+
CSSOM.CSSKeyframesRule.prototype.deleteRule = function deleteRule(select) {
|
|
103
|
+
if (arguments.length === 0) {
|
|
104
|
+
errorUtils.throwMissingArguments(this, 'deleteRule', 'CSSKeyframesRule');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
var normalizedSelect = this._normalizeKeyText(select);
|
|
108
|
+
|
|
109
|
+
for (var i = 0; i < this.cssRules.length; i++) {
|
|
110
|
+
var rule = this.cssRules[i];
|
|
111
|
+
if (this._normalizeKeyText(rule.keyText) === normalizedSelect) {
|
|
112
|
+
rule.__parentRule = null;
|
|
113
|
+
this.cssRules.splice(i, 1);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Finds and returns the keyframe rule that matches the specified key.
|
|
121
|
+
* When multiple rules have the same key, returns the last one.
|
|
122
|
+
*
|
|
123
|
+
* @param {string} select - The keyframe selector to find (e.g., "50%", "from", "to")
|
|
124
|
+
* @return {CSSKeyframeRule|null} The matching keyframe rule, or null if not found
|
|
125
|
+
* @see https://www.w3.org/TR/css-animations-1/#dom-csskeyframesrule-findrule
|
|
126
|
+
*/
|
|
127
|
+
CSSOM.CSSKeyframesRule.prototype.findRule = function findRule(select) {
|
|
128
|
+
if (arguments.length === 0) {
|
|
129
|
+
errorUtils.throwMissingArguments(this, 'findRule', 'CSSKeyframesRule');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
var normalizedSelect = this._normalizeKeyText(select);
|
|
133
|
+
|
|
134
|
+
// Iterate backwards to find the last matching rule
|
|
135
|
+
for (var i = this.cssRules.length - 1; i >= 0; i--) {
|
|
136
|
+
var rule = this.cssRules[i];
|
|
137
|
+
if (this._normalizeKeyText(rule.keyText) === normalizedSelect) {
|
|
138
|
+
return rule;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return null;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Normalizes keyframe selector text for comparison.
|
|
147
|
+
* Handles "from" -> "0%" and "to" -> "100%" conversions and trims whitespace.
|
|
148
|
+
*
|
|
149
|
+
* @private
|
|
150
|
+
* @param {string} keyText - The keyframe selector text to normalize
|
|
151
|
+
* @return {string} The normalized keyframe selector text
|
|
152
|
+
*/
|
|
153
|
+
CSSOM.CSSKeyframesRule.prototype._normalizeKeyText = function _normalizeKeyText(keyText) {
|
|
154
|
+
if (!keyText) return '';
|
|
155
|
+
|
|
156
|
+
var normalized = keyText.toString().trim().toLowerCase();
|
|
157
|
+
|
|
158
|
+
// Convert keywords to percentages for comparison
|
|
159
|
+
if (normalized === 'from') {
|
|
160
|
+
return '0%';
|
|
161
|
+
} else if (normalized === 'to') {
|
|
162
|
+
return '100%';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return normalized;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Makes CSSKeyframesRule iterable over its cssRules.
|
|
170
|
+
* Allows for...of loops and other iterable methods.
|
|
171
|
+
*/
|
|
172
|
+
if (typeof Symbol !== 'undefined' && Symbol.iterator) {
|
|
173
|
+
CSSOM.CSSKeyframesRule.prototype[Symbol.iterator] = function() {
|
|
174
|
+
var index = 0;
|
|
175
|
+
var cssRules = this.cssRules;
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
next: function() {
|
|
179
|
+
if (index < cssRules.length) {
|
|
180
|
+
return { value: cssRules[index++], done: false };
|
|
181
|
+
} else {
|
|
182
|
+
return { done: true };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Adds indexed getters for direct access to cssRules by index.
|
|
191
|
+
* This enables rule[0], rule[1], etc. access patterns.
|
|
192
|
+
* Works in environments where Proxy is not available (like jsdom).
|
|
193
|
+
*/
|
|
194
|
+
CSSOM.CSSKeyframesRule.prototype._setupIndexedAccess = function() {
|
|
195
|
+
// Remove any existing indexed properties
|
|
196
|
+
for (var i = 0; i < 1000; i++) { // reasonable upper limit
|
|
197
|
+
if (this.hasOwnProperty(i)) {
|
|
198
|
+
delete this[i];
|
|
199
|
+
} else {
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Add indexed getters for current cssRules
|
|
205
|
+
for (var i = 0; i < this.cssRules.length; i++) {
|
|
206
|
+
(function(index) {
|
|
207
|
+
Object.defineProperty(this, index, {
|
|
208
|
+
get: function() {
|
|
209
|
+
return this.cssRules[index];
|
|
210
|
+
},
|
|
211
|
+
enumerable: false,
|
|
212
|
+
configurable: true
|
|
213
|
+
});
|
|
214
|
+
}.call(this, i));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Update length property
|
|
218
|
+
Object.defineProperty(this, 'length', {
|
|
219
|
+
get: function() {
|
|
220
|
+
return this.cssRules.length;
|
|
221
|
+
},
|
|
222
|
+
enumerable: false,
|
|
223
|
+
configurable: true
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
36
230
|
|
|
37
231
|
//.CommonJS
|
|
38
232
|
exports.CSSKeyframesRule = CSSOM.CSSKeyframesRule;
|
|
@@ -1,23 +1,44 @@
|
|
|
1
1
|
//.CommonJS
|
|
2
2
|
var CSSOM = {
|
|
3
3
|
CSSRule: require("./CSSRule").CSSRule,
|
|
4
|
+
CSSStyleDeclaration: require('./CSSStyleDeclaration').CSSStyleDeclaration
|
|
4
5
|
};
|
|
6
|
+
// Use cssstyle if available
|
|
7
|
+
try {
|
|
8
|
+
CSSOM.CSSStyleDeclaration = require("cssstyle").CSSStyleDeclaration;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
// ignore
|
|
11
|
+
}
|
|
5
12
|
///CommonJS
|
|
6
13
|
|
|
14
|
+
|
|
7
15
|
/**
|
|
8
16
|
* @constructor
|
|
9
17
|
* @see https://drafts.csswg.org/css-nesting-1/
|
|
10
18
|
*/
|
|
11
19
|
CSSOM.CSSNestedDeclarations = function CSSNestedDeclarations() {
|
|
12
20
|
CSSOM.CSSRule.call(this);
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
21
|
+
this.__style = new CSSOM.CSSStyleDeclaration();
|
|
22
|
+
this.__style.parentRule = this;
|
|
15
23
|
};
|
|
16
24
|
|
|
17
25
|
CSSOM.CSSNestedDeclarations.prototype = new CSSOM.CSSRule();
|
|
18
26
|
CSSOM.CSSNestedDeclarations.prototype.constructor = CSSOM.CSSNestedDeclarations;
|
|
19
27
|
CSSOM.CSSNestedDeclarations.prototype.type = 0;
|
|
20
28
|
|
|
29
|
+
Object.defineProperty(CSSOM.CSSNestedDeclarations.prototype, "style", {
|
|
30
|
+
get: function() {
|
|
31
|
+
return this.__style;
|
|
32
|
+
},
|
|
33
|
+
set: function(value) {
|
|
34
|
+
if (typeof value === "string") {
|
|
35
|
+
this.__style.cssText = value;
|
|
36
|
+
} else {
|
|
37
|
+
this.__style = value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
21
42
|
Object.defineProperty(CSSOM.CSSNestedDeclarations.prototype, "cssText", {
|
|
22
43
|
get: function () {
|
|
23
44
|
return this.style.cssText;
|
package/lib/CSSRule.js
CHANGED
|
@@ -8,35 +8,48 @@ var CSSOM = {};
|
|
|
8
8
|
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSRule
|
|
9
9
|
*/
|
|
10
10
|
CSSOM.CSSRule = function CSSRule() {
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
11
|
+
this.__parentRule = null;
|
|
12
|
+
this.__parentStyleSheet = null;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
CSSOM.CSSRule.
|
|
16
|
-
CSSOM.CSSRule.STYLE_RULE = 1;
|
|
17
|
-
CSSOM.CSSRule.CHARSET_RULE = 2; // obsolete
|
|
18
|
-
CSSOM.CSSRule.IMPORT_RULE = 3;
|
|
19
|
-
CSSOM.CSSRule.MEDIA_RULE = 4;
|
|
20
|
-
CSSOM.CSSRule.FONT_FACE_RULE = 5;
|
|
21
|
-
CSSOM.CSSRule.PAGE_RULE = 6;
|
|
22
|
-
CSSOM.CSSRule.KEYFRAMES_RULE = 7;
|
|
23
|
-
CSSOM.CSSRule.KEYFRAME_RULE = 8;
|
|
24
|
-
CSSOM.CSSRule.MARGIN_RULE = 9;
|
|
25
|
-
CSSOM.CSSRule.NAMESPACE_RULE = 10;
|
|
26
|
-
CSSOM.CSSRule.COUNTER_STYLE_RULE = 11;
|
|
27
|
-
CSSOM.CSSRule.SUPPORTS_RULE = 12;
|
|
28
|
-
CSSOM.CSSRule.DOCUMENT_RULE = 13;
|
|
29
|
-
CSSOM.CSSRule.FONT_FEATURE_VALUES_RULE = 14;
|
|
30
|
-
CSSOM.CSSRule.VIEWPORT_RULE = 15;
|
|
31
|
-
CSSOM.CSSRule.REGION_STYLE_RULE = 16;
|
|
32
|
-
CSSOM.CSSRule.CONTAINER_RULE = 17;
|
|
33
|
-
CSSOM.CSSRule.LAYER_BLOCK_RULE = 18;
|
|
34
|
-
CSSOM.CSSRule.STARTING_STYLE_RULE = 1002;
|
|
15
|
+
Object.defineProperties(CSSOM.CSSRule.prototype, {
|
|
35
16
|
|
|
36
|
-
CSSOM.CSSRule
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
17
|
+
constructor: { value: CSSOM.CSSRule },
|
|
18
|
+
|
|
19
|
+
parentRule: {
|
|
20
|
+
get: function() {
|
|
21
|
+
return this.__parentRule
|
|
22
|
+
}
|
|
23
|
+
},
|
|
40
24
|
|
|
25
|
+
parentStyleSheet: {
|
|
26
|
+
get: function() {
|
|
27
|
+
return this.__parentStyleSheet
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
UNKNOWN_RULE: { value: 0, enumerable: true }, // obsolet
|
|
32
|
+
STYLE_RULE: { value: 1, enumerable: true },
|
|
33
|
+
CHARSET_RULE: { value: 2, enumerable: true }, // obsolet
|
|
34
|
+
IMPORT_RULE: { value: 3, enumerable: true },
|
|
35
|
+
MEDIA_RULE: { value: 4, enumerable: true },
|
|
36
|
+
FONT_FACE_RULE: { value: 5, enumerable: true },
|
|
37
|
+
PAGE_RULE: { value: 6, enumerable: true },
|
|
38
|
+
KEYFRAMES_RULE: { value: 7, enumerable: true },
|
|
39
|
+
KEYFRAME_RULE: { value: 8, enumerable: true },
|
|
40
|
+
MARGIN_RULE: { value: 9, enumerable: true },
|
|
41
|
+
NAMESPACE_RULE: { value: 10, enumerable: true },
|
|
42
|
+
COUNTER_STYLE_RULE: { value: 11, enumerable: true },
|
|
43
|
+
SUPPORTS_RULE: { value: 12, enumerable: true },
|
|
44
|
+
DOCUMENT_RULE: { value: 13, enumerable: true },
|
|
45
|
+
FONT_FEATURE_VALUES_RULE: { value: 14, enumerable: true },
|
|
46
|
+
VIEWPORT_RULE: { value: 15, enumerable: true },
|
|
47
|
+
REGION_STYLE_RULE: { value: 16, enumerable: true },
|
|
48
|
+
CONTAINER_RULE: { value: 17, enumerable: true },
|
|
49
|
+
LAYER_BLOCK_RULE: { value: 18, enumerable: true },
|
|
50
|
+
STARTING_STYLE_RULE: { value: 1002, enumerable: true },
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
//.CommonJS
|
|
41
54
|
exports.CSSRule = CSSOM.CSSRule;
|
|
42
55
|
///CommonJS
|
package/lib/CSSStyleRule.js
CHANGED
|
@@ -4,6 +4,12 @@ var CSSOM = {
|
|
|
4
4
|
CSSGroupingRule: require("./CSSGroupingRule").CSSGroupingRule,
|
|
5
5
|
CSSRule: require("./CSSRule").CSSRule
|
|
6
6
|
};
|
|
7
|
+
// Use cssstyle if available
|
|
8
|
+
try {
|
|
9
|
+
CSSOM.CSSStyleDeclaration = require("cssstyle").CSSStyleDeclaration;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
// ignore
|
|
12
|
+
}
|
|
7
13
|
///CommonJS
|
|
8
14
|
|
|
9
15
|
|
|
@@ -14,14 +20,40 @@ var CSSOM = {
|
|
|
14
20
|
*/
|
|
15
21
|
CSSOM.CSSStyleRule = function CSSStyleRule() {
|
|
16
22
|
CSSOM.CSSGroupingRule.call(this);
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
23
|
+
this.__selectorText = "";
|
|
24
|
+
this.__style = new CSSOM.CSSStyleDeclaration();
|
|
25
|
+
this.__style.parentRule = this;
|
|
20
26
|
};
|
|
21
27
|
|
|
22
28
|
CSSOM.CSSStyleRule.prototype = new CSSOM.CSSGroupingRule();
|
|
23
29
|
CSSOM.CSSStyleRule.prototype.constructor = CSSOM.CSSStyleRule;
|
|
24
|
-
|
|
30
|
+
|
|
31
|
+
Object.defineProperty(CSSOM.CSSStyleRule.prototype, "type", {
|
|
32
|
+
value: 1,
|
|
33
|
+
writable: false
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
Object.defineProperty(CSSOM.CSSStyleRule.prototype, "selectorText", {
|
|
37
|
+
get: function() {
|
|
38
|
+
return this.__selectorText;
|
|
39
|
+
},
|
|
40
|
+
set: function(value) {
|
|
41
|
+
this.__selectorText = value;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
Object.defineProperty(CSSOM.CSSStyleRule.prototype, "style", {
|
|
46
|
+
get: function() {
|
|
47
|
+
return this.__style;
|
|
48
|
+
},
|
|
49
|
+
set: function(value) {
|
|
50
|
+
if (typeof value === "string") {
|
|
51
|
+
this.__style.cssText = value;
|
|
52
|
+
} else {
|
|
53
|
+
this.__style = value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
25
57
|
|
|
26
58
|
Object.defineProperty(CSSOM.CSSStyleRule.prototype, "cssText", {
|
|
27
59
|
get: function() {
|
|
@@ -44,8 +76,8 @@ Object.defineProperty(CSSOM.CSSStyleRule.prototype, "cssText", {
|
|
|
44
76
|
},
|
|
45
77
|
set: function(cssText) {
|
|
46
78
|
var rule = CSSOM.CSSStyleRule.parse(cssText);
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
79
|
+
this.__style = rule.style;
|
|
80
|
+
this.__selectorText = rule.selectorText;
|
|
49
81
|
}
|
|
50
82
|
});
|
|
51
83
|
|
package/lib/CSSStyleSheet.js
CHANGED
|
@@ -3,6 +3,7 @@ var CSSOM = {
|
|
|
3
3
|
StyleSheet: require("./StyleSheet").StyleSheet,
|
|
4
4
|
CSSStyleRule: require("./CSSStyleRule").CSSStyleRule
|
|
5
5
|
};
|
|
6
|
+
var errorUtils = require("./errorUtils").errorUtils;
|
|
6
7
|
///CommonJS
|
|
7
8
|
|
|
8
9
|
|
|
@@ -38,13 +39,13 @@ CSSOM.CSSStyleSheet.prototype.constructor = CSSOM.CSSStyleSheet;
|
|
|
38
39
|
*/
|
|
39
40
|
CSSOM.CSSStyleSheet.prototype.insertRule = function(rule, index) {
|
|
40
41
|
if (rule === undefined && index === undefined) {
|
|
41
|
-
|
|
42
|
+
errorUtils.throwMissingArguments(this, 'insertRule', 'CSSStyleSheet');
|
|
42
43
|
}
|
|
43
44
|
if (index === void 0) {
|
|
44
45
|
index = 0;
|
|
45
46
|
}
|
|
46
47
|
if (index < 0 || index > this.cssRules.length) {
|
|
47
|
-
|
|
48
|
+
errorUtils.throwIndexSizeError(this);
|
|
48
49
|
}
|
|
49
50
|
var ruleToParse = String(rule);
|
|
50
51
|
var parsedSheet = CSSOM.parse(ruleToParse);
|
|
@@ -53,10 +54,10 @@ CSSOM.CSSStyleSheet.prototype.insertRule = function(rule, index) {
|
|
|
53
54
|
if (ruleToParse.trimStart().startsWith('@namespace')) {
|
|
54
55
|
domExceptionName = "InvalidStateError";
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
+
errorUtils.throwParseError(this, 'insertRule', 'CSSStyleSheet', ruleToParse, domExceptionName);
|
|
57
58
|
}
|
|
58
59
|
var cssRule = parsedSheet.cssRules[0];
|
|
59
|
-
cssRule.
|
|
60
|
+
cssRule.__parentStyleSheet = this;
|
|
60
61
|
this.cssRules.splice(index, 0, cssRule);
|
|
61
62
|
return index;
|
|
62
63
|
};
|
|
@@ -77,21 +78,21 @@ CSSOM.CSSStyleSheet.prototype.insertRule = function(rule, index) {
|
|
|
77
78
|
*/
|
|
78
79
|
CSSOM.CSSStyleSheet.prototype.deleteRule = function(index) {
|
|
79
80
|
if (index === undefined) {
|
|
80
|
-
|
|
81
|
+
errorUtils.throwMissingArguments(this, 'deleteRule', 'CSSStyleSheet');
|
|
81
82
|
}
|
|
82
83
|
index = Number(index);
|
|
83
84
|
if (index < 0) {
|
|
84
85
|
index = 4294967296 + index;
|
|
85
86
|
}
|
|
86
87
|
if (index >= this.cssRules.length) {
|
|
87
|
-
|
|
88
|
+
errorUtils.throwIndexError(this, 'deleteRule', 'CSSStyleSheet', index, this.cssRules.length);
|
|
88
89
|
}
|
|
89
90
|
if (this.cssRules[index] && this.cssRules[index].constructor.name == "CSSNamespaceRule") {
|
|
90
91
|
var shouldContinue = this.cssRules.every(function (rule) {
|
|
91
92
|
return ['CSSImportRule','CSSLayerStatementRule','CSSNamespaceRule'].indexOf(rule.constructor.name) !== -1
|
|
92
93
|
});
|
|
93
94
|
if (!shouldContinue) {
|
|
94
|
-
|
|
95
|
+
errorUtils.throwError(this, 'DOMException', "Failed to execute 'deleteRule' on 'CSSStyleSheet': Deleting a CSSNamespaceRule is not allowed when there is rules other than @import, @layer statement, or @namespace.", "InvalidStateError");
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
this.cssRules.splice(index, 1);
|
package/lib/StyleSheet.js
CHANGED
|
@@ -8,9 +8,16 @@ var CSSOM = {};
|
|
|
8
8
|
* @see http://dev.w3.org/csswg/cssom/#the-stylesheet-interface
|
|
9
9
|
*/
|
|
10
10
|
CSSOM.StyleSheet = function StyleSheet() {
|
|
11
|
-
this.
|
|
11
|
+
this.__parentStyleSheet = null;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
Object.defineProperties(CSSOM.StyleSheet.prototype, {
|
|
15
|
+
parentStyleSheet: {
|
|
16
|
+
get: function() {
|
|
17
|
+
return this.__parentStyleSheet;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
14
21
|
|
|
15
22
|
//.CommonJS
|
|
16
23
|
exports.StyleSheet = CSSOM.StyleSheet;
|
package/lib/clone.js
CHANGED
|
@@ -15,6 +15,12 @@ var CSSOM = {
|
|
|
15
15
|
CSSLayerBlockRule: require('./CSSLayerBlockRule').CSSLayerBlockRule,
|
|
16
16
|
CSSLayerStatementRule: require('./CSSLayerStatementRule').CSSLayerStatementRule
|
|
17
17
|
};
|
|
18
|
+
// Use cssstyle if available
|
|
19
|
+
try {
|
|
20
|
+
CSSOM.CSSStyleDeclaration = require("cssstyle").CSSStyleDeclaration;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
// ignore
|
|
23
|
+
}
|
|
18
24
|
///CommonJS
|
|
19
25
|
|
|
20
26
|
|