@acemir/cssom 0.9.23 → 0.9.24
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 +714 -111
- package/lib/CSSContainerRule.js +11 -4
- package/lib/CSSDocumentRule.js +1 -0
- package/lib/CSSHostRule.js +13 -4
- package/lib/CSSKeyframesRule.js +12 -5
- package/lib/CSSLayerBlockRule.js +11 -4
- package/lib/CSSMediaRule.js +11 -4
- package/lib/CSSPageRule.js +8 -3
- package/lib/CSSScopeRule.js +11 -4
- package/lib/CSSStartingStyleRule.js +11 -4
- package/lib/CSSStyleRule.js +8 -3
- package/lib/CSSStyleSheet.js +79 -0
- package/lib/CSSSupportsRule.js +11 -6
- package/lib/MediaList.js +3 -1
- package/lib/errorUtils.js +15 -3
- package/lib/parse.js +509 -66
- package/package.json +1 -1
package/lib/CSSContainerRule.js
CHANGED
|
@@ -24,11 +24,18 @@ CSSOM.CSSContainerRule.prototype.type = 17;
|
|
|
24
24
|
Object.defineProperties(CSSOM.CSSContainerRule.prototype, {
|
|
25
25
|
"cssText": {
|
|
26
26
|
get: function() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
var values = "";
|
|
28
|
+
var valuesArr = [" {"];
|
|
29
|
+
if (this.cssRules.length) {
|
|
30
|
+
valuesArr.push(this.cssRules.reduce(function(acc, rule){
|
|
31
|
+
if (rule.cssText !== "") {
|
|
32
|
+
acc.push(rule.cssText);
|
|
33
|
+
}
|
|
34
|
+
return acc;
|
|
35
|
+
}, []).join("\n "));
|
|
30
36
|
}
|
|
31
|
-
|
|
37
|
+
values = valuesArr.join("\n ") + "\n}";
|
|
38
|
+
return "@container " + this.conditionText + values;
|
|
32
39
|
},
|
|
33
40
|
configurable: true,
|
|
34
41
|
enumerable: true
|
package/lib/CSSDocumentRule.js
CHANGED
|
@@ -10,6 +10,7 @@ var CSSOM = {
|
|
|
10
10
|
/**
|
|
11
11
|
* @constructor
|
|
12
12
|
* @see https://developer.mozilla.org/en/CSS/@-moz-document
|
|
13
|
+
* @deprecated This rule is a non-standard Mozilla-specific extension and is not part of any official CSS specification.
|
|
13
14
|
*/
|
|
14
15
|
CSSOM.CSSDocumentRule = function CSSDocumentRule() {
|
|
15
16
|
CSSOM.CSSRule.call(this);
|
package/lib/CSSHostRule.js
CHANGED
|
@@ -9,6 +9,8 @@ var CSSOM = {
|
|
|
9
9
|
/**
|
|
10
10
|
* @constructor
|
|
11
11
|
* @see http://www.w3.org/TR/shadow-dom/#host-at-rule
|
|
12
|
+
* @see http://html5index.org/Shadow%20DOM%20-%20CSSHostRule.html
|
|
13
|
+
* @deprecated This rule was part of early Shadow DOM drafts but was removed in favor of the more flexible :host and :host-context() pseudo-classes in modern CSS for Web Components.
|
|
12
14
|
*/
|
|
13
15
|
CSSOM.CSSHostRule = function CSSHostRule() {
|
|
14
16
|
CSSOM.CSSRule.call(this);
|
|
@@ -24,11 +26,18 @@ CSSOM.CSSHostRule.prototype.type = 1001;
|
|
|
24
26
|
|
|
25
27
|
Object.defineProperty(CSSOM.CSSHostRule.prototype, "cssText", {
|
|
26
28
|
get: function() {
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
var values = "";
|
|
30
|
+
var valuesArr = [" {"];
|
|
31
|
+
if (this.cssRules.length) {
|
|
32
|
+
valuesArr.push(this.cssRules.reduce(function(acc, rule){
|
|
33
|
+
if (rule.cssText !== "") {
|
|
34
|
+
acc.push(rule.cssText);
|
|
35
|
+
}
|
|
36
|
+
return acc;
|
|
37
|
+
}, []).join("\n "));
|
|
30
38
|
}
|
|
31
|
-
|
|
39
|
+
values = valuesArr.join("\n ") + "\n}";
|
|
40
|
+
return "@host" + values;
|
|
32
41
|
}
|
|
33
42
|
});
|
|
34
43
|
|
package/lib/CSSKeyframesRule.js
CHANGED
|
@@ -56,13 +56,20 @@ CSSOM.CSSKeyframesRule.prototype.type = 7;
|
|
|
56
56
|
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSKeyframesRule.cpp
|
|
57
57
|
Object.defineProperty(CSSOM.CSSKeyframesRule.prototype, "cssText", {
|
|
58
58
|
get: function() {
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
var values = "";
|
|
60
|
+
var valuesArr = [" {"];
|
|
61
|
+
if (this.cssRules.length) {
|
|
62
|
+
valuesArr.push(this.cssRules.reduce(function(acc, rule){
|
|
63
|
+
if (rule.cssText !== "") {
|
|
64
|
+
acc.push(rule.cssText);
|
|
65
|
+
}
|
|
66
|
+
return acc;
|
|
67
|
+
}, []).join("\n "));
|
|
68
|
+
}
|
|
69
|
+
values = valuesArr.join("\n ") + "\n}";
|
|
63
70
|
var cssWideKeywords = ['initial', 'inherit', 'revert', 'revert-layer', 'unset', 'none'];
|
|
64
71
|
var processedName = cssWideKeywords.includes(this.name) ? '"' + this.name + '"' : this.name;
|
|
65
|
-
return "@" + (this._vendorPrefix || '') + "keyframes " + processedName +
|
|
72
|
+
return "@" + (this._vendorPrefix || '') + "keyframes " + processedName + values;
|
|
66
73
|
}
|
|
67
74
|
});
|
|
68
75
|
|
package/lib/CSSLayerBlockRule.js
CHANGED
|
@@ -22,11 +22,18 @@ CSSOM.CSSLayerBlockRule.prototype.type = 18;
|
|
|
22
22
|
Object.defineProperties(CSSOM.CSSLayerBlockRule.prototype, {
|
|
23
23
|
cssText: {
|
|
24
24
|
get: function () {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
var values = "";
|
|
26
|
+
var valuesArr = [" {"];
|
|
27
|
+
if (this.cssRules.length) {
|
|
28
|
+
valuesArr.push(this.cssRules.reduce(function(acc, rule){
|
|
29
|
+
if (rule.cssText !== "") {
|
|
30
|
+
acc.push(rule.cssText);
|
|
31
|
+
}
|
|
32
|
+
return acc;
|
|
33
|
+
}, []).join("\n "));
|
|
28
34
|
}
|
|
29
|
-
|
|
35
|
+
values = valuesArr.join("\n ") + "\n}";
|
|
36
|
+
return "@layer" + (this.name ? " " + this.name : "") + values;
|
|
30
37
|
},
|
|
31
38
|
configurable: true,
|
|
32
39
|
enumerable: true,
|
package/lib/CSSMediaRule.js
CHANGED
|
@@ -45,11 +45,18 @@ Object.defineProperties(CSSOM.CSSMediaRule.prototype, {
|
|
|
45
45
|
},
|
|
46
46
|
"cssText": {
|
|
47
47
|
get: function() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
var values = "";
|
|
49
|
+
var valuesArr = [" {"];
|
|
50
|
+
if (this.cssRules.length) {
|
|
51
|
+
valuesArr.push(this.cssRules.reduce(function(acc, rule){
|
|
52
|
+
if (rule.cssText !== "") {
|
|
53
|
+
acc.push(rule.cssText);
|
|
54
|
+
}
|
|
55
|
+
return acc;
|
|
56
|
+
}, []).join("\n "));
|
|
51
57
|
}
|
|
52
|
-
|
|
58
|
+
values = valuesArr.join("\n ") + "\n}";
|
|
59
|
+
return "@media " + this.media.mediaText + values;
|
|
53
60
|
},
|
|
54
61
|
configurable: true,
|
|
55
62
|
enumerable: true
|
package/lib/CSSPageRule.js
CHANGED
|
@@ -106,12 +106,17 @@ Object.defineProperty(CSSOM.CSSPageRule.prototype, "style", {
|
|
|
106
106
|
|
|
107
107
|
Object.defineProperty(CSSOM.CSSPageRule.prototype, "cssText", {
|
|
108
108
|
get: function() {
|
|
109
|
-
var values = ""
|
|
109
|
+
var values = "";
|
|
110
110
|
if (this.cssRules.length) {
|
|
111
111
|
var valuesArr = [" {"];
|
|
112
112
|
this.style.cssText && valuesArr.push(this.style.cssText);
|
|
113
|
-
valuesArr.push(this.cssRules.
|
|
114
|
-
|
|
113
|
+
valuesArr.push(this.cssRules.reduce(function(acc, rule){
|
|
114
|
+
if (rule.cssText !== "") {
|
|
115
|
+
acc.push(rule.cssText);
|
|
116
|
+
}
|
|
117
|
+
return acc;
|
|
118
|
+
}, []).join("\n "));
|
|
119
|
+
values = valuesArr.join("\n ") + "\n}";
|
|
115
120
|
} else {
|
|
116
121
|
values = " {" + (this.style.cssText ? " " + this.style.cssText : "") + " }";
|
|
117
122
|
}
|
package/lib/CSSScopeRule.js
CHANGED
|
@@ -27,11 +27,18 @@ Object.defineProperties(CSSOM.CSSScopeRule.prototype, {
|
|
|
27
27
|
},
|
|
28
28
|
cssText: {
|
|
29
29
|
get: function () {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
var values = "";
|
|
31
|
+
var valuesArr = [" {"];
|
|
32
|
+
if (this.cssRules.length) {
|
|
33
|
+
valuesArr.push(this.cssRules.reduce(function(acc, rule){
|
|
34
|
+
if (rule.cssText !== "") {
|
|
35
|
+
acc.push(rule.cssText);
|
|
36
|
+
}
|
|
37
|
+
return acc;
|
|
38
|
+
}, []).join("\n "));
|
|
33
39
|
}
|
|
34
|
-
|
|
40
|
+
values = valuesArr.join("\n ") + "\n}";
|
|
41
|
+
return "@scope" + (this.start ? " (" + this.start + ")" : "") + (this.end ? " to (" + this.end + ")" : "") + values;
|
|
35
42
|
},
|
|
36
43
|
configurable: true,
|
|
37
44
|
enumerable: true,
|
|
@@ -24,11 +24,18 @@ CSSOM.CSSStartingStyleRule.prototype.type = 1002;
|
|
|
24
24
|
|
|
25
25
|
Object.defineProperty(CSSOM.CSSStartingStyleRule.prototype, "cssText", {
|
|
26
26
|
get: function() {
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
var values = "";
|
|
28
|
+
var valuesArr = [" {"];
|
|
29
|
+
if (this.cssRules.length) {
|
|
30
|
+
valuesArr.push(this.cssRules.reduce(function(acc, rule){
|
|
31
|
+
if (rule.cssText !== "") {
|
|
32
|
+
acc.push(rule.cssText);
|
|
33
|
+
}
|
|
34
|
+
return acc;
|
|
35
|
+
}, []).join("\n "));
|
|
30
36
|
}
|
|
31
|
-
|
|
37
|
+
values = valuesArr.join("\n ") + "\n}";
|
|
38
|
+
return "@starting-style" + values;
|
|
32
39
|
}
|
|
33
40
|
});
|
|
34
41
|
|
package/lib/CSSStyleRule.js
CHANGED
|
@@ -73,12 +73,17 @@ Object.defineProperty(CSSOM.CSSStyleRule.prototype, "cssText", {
|
|
|
73
73
|
get: function() {
|
|
74
74
|
var text;
|
|
75
75
|
if (this.selectorText) {
|
|
76
|
-
var values = ""
|
|
76
|
+
var values = "";
|
|
77
77
|
if (this.cssRules.length) {
|
|
78
78
|
var valuesArr = [" {"];
|
|
79
79
|
this.style.cssText && valuesArr.push(this.style.cssText);
|
|
80
|
-
valuesArr.push(this.cssRules.
|
|
81
|
-
|
|
80
|
+
valuesArr.push(this.cssRules.reduce(function(acc, rule){
|
|
81
|
+
if (rule.cssText !== "") {
|
|
82
|
+
acc.push(rule.cssText);
|
|
83
|
+
}
|
|
84
|
+
return acc;
|
|
85
|
+
}, []).join("\n "));
|
|
86
|
+
values = valuesArr.join("\n ") + "\n}";
|
|
82
87
|
} else {
|
|
83
88
|
values = " {" + (this.style.cssText ? " " + this.style.cssText : "") + " }";
|
|
84
89
|
}
|
package/lib/CSSStyleSheet.js
CHANGED
|
@@ -15,6 +15,7 @@ var errorUtils = require("./errorUtils").errorUtils;
|
|
|
15
15
|
*/
|
|
16
16
|
CSSOM.CSSStyleSheet = function CSSStyleSheet() {
|
|
17
17
|
CSSOM.StyleSheet.call(this);
|
|
18
|
+
this.__constructed = true;
|
|
18
19
|
this.cssRules = new CSSOM.CSSRuleList();
|
|
19
20
|
};
|
|
20
21
|
|
|
@@ -227,6 +228,84 @@ CSSOM.CSSStyleSheet.prototype.removeRule = function(index) {
|
|
|
227
228
|
this.deleteRule(index);
|
|
228
229
|
};
|
|
229
230
|
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Replaces the rules of a {@link CSSStyleSheet}
|
|
234
|
+
*
|
|
235
|
+
* @returns a promise
|
|
236
|
+
* @see https://www.w3.org/TR/cssom-1/#dom-cssstylesheet-replace
|
|
237
|
+
*/
|
|
238
|
+
CSSOM.CSSStyleSheet.prototype.replace = function(text) {
|
|
239
|
+
var _Promise;
|
|
240
|
+
if (this.__globalObject) {
|
|
241
|
+
_Promise = this.__globalObject['Promise'];
|
|
242
|
+
} else {
|
|
243
|
+
_Promise = Promise;
|
|
244
|
+
}
|
|
245
|
+
var sheet = this;
|
|
246
|
+
return new _Promise(function (resolve, reject) {
|
|
247
|
+
// If the constructed flag is not set, or the disallow modification flag is set, throw a NotAllowedError DOMException.
|
|
248
|
+
if (!sheet.__constructed || sheet.__disallowModification) {
|
|
249
|
+
reject(errorUtils.createError(sheet, 'DOMException',
|
|
250
|
+
"Failed to execute 'replaceSync' on '" + sheet.constructor.name + "': Not allowed.",
|
|
251
|
+
'NotAllowedError'));
|
|
252
|
+
}
|
|
253
|
+
// Set the disallow modification flag.
|
|
254
|
+
sheet.__disallowModification = true;
|
|
255
|
+
|
|
256
|
+
// In parallel, do these steps:
|
|
257
|
+
setTimeout(function() {
|
|
258
|
+
// Let rules be the result of running parse a stylesheet's contents from text.
|
|
259
|
+
var rules = new CSSOM.CSSRuleList();
|
|
260
|
+
CSSOM.parse(text, { styleSheet: sheet, cssRules: rules });
|
|
261
|
+
// If rules contains one or more @import rules, remove those rules from rules.
|
|
262
|
+
var i = 0;
|
|
263
|
+
while (i < rules.length) {
|
|
264
|
+
if (rules[i].constructor.name === 'CSSImportRule') {
|
|
265
|
+
rules.splice(i, 1);
|
|
266
|
+
} else {
|
|
267
|
+
i++;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
// Set sheet's CSS rules to rules.
|
|
271
|
+
sheet.cssRules = rules;
|
|
272
|
+
// Unset sheet’s disallow modification flag.
|
|
273
|
+
delete sheet.__disallowModification;
|
|
274
|
+
// Resolve promise with sheet.
|
|
275
|
+
resolve(sheet);
|
|
276
|
+
})
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Synchronously replaces the rules of a {@link CSSStyleSheet}
|
|
282
|
+
*
|
|
283
|
+
* @see https://www.w3.org/TR/cssom-1/#dom-cssstylesheet-replacesync
|
|
284
|
+
*/
|
|
285
|
+
CSSOM.CSSStyleSheet.prototype.replaceSync = function(text) {
|
|
286
|
+
var sheet = this;
|
|
287
|
+
// If the constructed flag is not set, or the disallow modification flag is set, throw a NotAllowedError DOMException.
|
|
288
|
+
if (!sheet.__constructed || sheet.__disallowModification) {
|
|
289
|
+
errorUtils.throwError(sheet, 'DOMException',
|
|
290
|
+
"Failed to execute 'replaceSync' on '" + sheet.constructor.name + "': Not allowed.",
|
|
291
|
+
'NotAllowedError');
|
|
292
|
+
}
|
|
293
|
+
// Let rules be the result of running parse a stylesheet's contents from text.
|
|
294
|
+
var rules = new CSSOM.CSSRuleList();
|
|
295
|
+
CSSOM.parse(text, { styleSheet: sheet, cssRules: rules });
|
|
296
|
+
// If rules contains one or more @import rules, remove those rules from rules.
|
|
297
|
+
var i = 0;
|
|
298
|
+
while (i < rules.length) {
|
|
299
|
+
if (rules[i].constructor.name === 'CSSImportRule') {
|
|
300
|
+
rules.splice(i, 1);
|
|
301
|
+
} else {
|
|
302
|
+
i++;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Set sheet's CSS rules to rules.
|
|
306
|
+
sheet.cssRules = rules;
|
|
307
|
+
}
|
|
308
|
+
|
|
230
309
|
/**
|
|
231
310
|
* NON-STANDARD
|
|
232
311
|
* @return {string} serialize stylesheet
|
package/lib/CSSSupportsRule.js
CHANGED
|
@@ -22,13 +22,18 @@ CSSOM.CSSSupportsRule.prototype.type = 12;
|
|
|
22
22
|
|
|
23
23
|
Object.defineProperty(CSSOM.CSSSupportsRule.prototype, "cssText", {
|
|
24
24
|
get: function() {
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
var values = "";
|
|
26
|
+
var valuesArr = [" {"];
|
|
27
|
+
if (this.cssRules.length) {
|
|
28
|
+
valuesArr.push(this.cssRules.reduce(function(acc, rule){
|
|
29
|
+
if (rule.cssText !== "") {
|
|
30
|
+
acc.push(rule.cssText);
|
|
31
|
+
}
|
|
32
|
+
return acc;
|
|
33
|
+
}, []).join("\n "));
|
|
29
34
|
}
|
|
30
|
-
|
|
31
|
-
return "@supports " + this.conditionText +
|
|
35
|
+
values = valuesArr.join("\n ") + "\n}";
|
|
36
|
+
return "@supports " + this.conditionText + values;
|
|
32
37
|
}
|
|
33
38
|
});
|
|
34
39
|
|
package/lib/MediaList.js
CHANGED
|
@@ -26,7 +26,9 @@ CSSOM.MediaList.prototype = {
|
|
|
26
26
|
* @param {string} value
|
|
27
27
|
*/
|
|
28
28
|
set mediaText(value) {
|
|
29
|
-
var values = value.split(",")
|
|
29
|
+
var values = value.split(",").filter(function(text){
|
|
30
|
+
return !!text;
|
|
31
|
+
});
|
|
30
32
|
var length = this.length = values.length;
|
|
31
33
|
for (var i=0; i<length; i++) {
|
|
32
34
|
this[i] = values[i].trim();
|
package/lib/errorUtils.js
CHANGED
|
@@ -31,6 +31,19 @@ function getErrorConstructor(context, errorType) {
|
|
|
31
31
|
eval(errorType);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Creates an appropriate error with context-aware constructor.
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} context - The CSSOM object (rule, stylesheet, etc.)
|
|
38
|
+
* @param {string} errorType - The error type ('TypeError', 'RangeError', 'DOMException', etc.)
|
|
39
|
+
* @param {string} message - The error message
|
|
40
|
+
* @param {string} [name] - Optional name for DOMException
|
|
41
|
+
*/
|
|
42
|
+
function createError(context, errorType, message, name) {
|
|
43
|
+
var ErrorConstructor = getErrorConstructor(context, errorType);
|
|
44
|
+
return new ErrorConstructor(message, name);
|
|
45
|
+
}
|
|
46
|
+
|
|
34
47
|
/**
|
|
35
48
|
* Creates and throws an appropriate error with context-aware constructor.
|
|
36
49
|
*
|
|
@@ -40,9 +53,7 @@ function getErrorConstructor(context, errorType) {
|
|
|
40
53
|
* @param {string} [name] - Optional name for DOMException
|
|
41
54
|
*/
|
|
42
55
|
function throwError(context, errorType, message, name) {
|
|
43
|
-
|
|
44
|
-
var error = new ErrorConstructor(message, name);
|
|
45
|
-
throw error;
|
|
56
|
+
throw createError(context, errorType, message, name);
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
/**
|
|
@@ -95,6 +106,7 @@ function throwIndexError(context, methodName, objectName, index, maxIndex, name)
|
|
|
95
106
|
}
|
|
96
107
|
|
|
97
108
|
var errorUtils = {
|
|
109
|
+
createError: createError,
|
|
98
110
|
getErrorConstructor: getErrorConstructor,
|
|
99
111
|
throwError: throwError,
|
|
100
112
|
throwMissingArguments: throwMissingArguments,
|