@acemir/cssom 0.9.6 → 0.9.8
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 +41 -2
- package/lib/CSSCounterStyleRule.js +23 -0
- package/lib/index.js +1 -0
- package/lib/parse.js +28 -2
- package/package.json +1 -1
package/build/CSSOM.js
CHANGED
|
@@ -298,6 +298,20 @@ CSSOM.CSSGroupingRule.prototype.constructor = CSSOM.CSSGroupingRule;
|
|
|
298
298
|
};
|
|
299
299
|
|
|
300
300
|
|
|
301
|
+
/**
|
|
302
|
+
* @constructor
|
|
303
|
+
* @see https://drafts.csswg.org/css-counter-styles/#the-csscounterstylerule-interface
|
|
304
|
+
*/
|
|
305
|
+
CSSOM.CSSCounterStyleRule = function CSSCounterStyleRule() {
|
|
306
|
+
CSSOM.CSSRule.call(this);
|
|
307
|
+
this.name = "";
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
CSSOM.CSSCounterStyleRule.prototype = new CSSOM.CSSRule();
|
|
311
|
+
CSSOM.CSSCounterStyleRule.prototype.constructor = CSSOM.CSSCounterStyleRule;
|
|
312
|
+
CSSOM.CSSCounterStyleRule.prototype.type = 11;
|
|
313
|
+
|
|
314
|
+
|
|
301
315
|
/**
|
|
302
316
|
* @constructor
|
|
303
317
|
* @see https://www.w3.org/TR/css-conditional-3/#the-cssconditionrule-interface
|
|
@@ -1607,6 +1621,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
1607
1621
|
"atBlock": true,
|
|
1608
1622
|
"containerBlock": true,
|
|
1609
1623
|
"conditionBlock": true,
|
|
1624
|
+
"counterStyleBlock": true,
|
|
1610
1625
|
'documentRule-begin': true,
|
|
1611
1626
|
"layerBlock": true
|
|
1612
1627
|
};
|
|
@@ -1622,7 +1637,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
1622
1637
|
var ancestorRules = [];
|
|
1623
1638
|
var prevScope;
|
|
1624
1639
|
|
|
1625
|
-
var name, priority="", styleRule, mediaRule, containerRule, supportsRule, importRule, fontFaceRule, keyframesRule, documentRule, hostRule, startingStyleRule, layerBlockRule, layerStatementRule, nestedSelectorRule;
|
|
1640
|
+
var name, priority="", styleRule, mediaRule, containerRule, counterStyleRule, supportsRule, importRule, fontFaceRule, keyframesRule, documentRule, hostRule, startingStyleRule, layerBlockRule, layerStatementRule, nestedSelectorRule;
|
|
1626
1641
|
|
|
1627
1642
|
var atKeyframesRegExp = /@(-(?:\w+-)+)?keyframes/g; // Match @keyframes and vendor-prefixed @keyframes
|
|
1628
1643
|
// Regex above is not ES5 compliant
|
|
@@ -2154,6 +2169,15 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2154
2169
|
});
|
|
2155
2170
|
buffer = "";
|
|
2156
2171
|
break;
|
|
2172
|
+
} else if (token.indexOf("@counter-style", i) === i) {
|
|
2173
|
+
validateAtRule("@counter-style", function(){
|
|
2174
|
+
state = "counterStyleBlock"
|
|
2175
|
+
counterStyleRule = new CSSOM.CSSCounterStyleRule();
|
|
2176
|
+
counterStyleRule.__starts = i;
|
|
2177
|
+
i += "counter-style".length;
|
|
2178
|
+
}, true);
|
|
2179
|
+
buffer = "";
|
|
2180
|
+
break;
|
|
2157
2181
|
} else if (token.indexOf("@layer", i) === i) {
|
|
2158
2182
|
validateAtRule("@layer", function(){
|
|
2159
2183
|
state = "layerBlock"
|
|
@@ -2163,7 +2187,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2163
2187
|
});
|
|
2164
2188
|
buffer = "";
|
|
2165
2189
|
break;
|
|
2166
|
-
}
|
|
2190
|
+
} else if (token.indexOf("@supports", i) === i) {
|
|
2167
2191
|
validateAtRule("@supports", function(){
|
|
2168
2192
|
state = "conditionBlock";
|
|
2169
2193
|
supportsRule = new CSSOM.CSSSupportsRule();
|
|
@@ -2280,6 +2304,12 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2280
2304
|
containerRule.parentStyleSheet = styleSheet;
|
|
2281
2305
|
buffer = "";
|
|
2282
2306
|
state = "before-selector";
|
|
2307
|
+
} else if (state === "counterStyleBlock") {
|
|
2308
|
+
// TODO: Validate counter-style name. At least that it cannot be empty nor multiple
|
|
2309
|
+
counterStyleRule.name = buffer.trim().replace(/\n/g, "");
|
|
2310
|
+
currentScope = parentRule = counterStyleRule;
|
|
2311
|
+
counterStyleRule.parentStyleSheet = styleSheet;
|
|
2312
|
+
buffer = "";
|
|
2283
2313
|
} else if (state === "conditionBlock") {
|
|
2284
2314
|
supportsRule.conditionText = buffer.trim();
|
|
2285
2315
|
|
|
@@ -2514,6 +2544,15 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2514
2544
|
break;
|
|
2515
2545
|
|
|
2516
2546
|
case "}":
|
|
2547
|
+
if (state === "counterStyleBlock") {
|
|
2548
|
+
// FIXME : Implement cssText get setter that parses the real implementation
|
|
2549
|
+
counterStyleRule.cssText = "@counter-style " + counterStyleRule.name + " { " + buffer.trim().replace(/\n/g, " ").replace(/(['"])(?:\\.|[^\\])*?\1|(\s{2,})/g, function(match, quote, spaces) {
|
|
2550
|
+
return quote ? match : ' ';
|
|
2551
|
+
}) + " }";
|
|
2552
|
+
buffer = "";
|
|
2553
|
+
state = "before-selector";
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2517
2556
|
switch (state) {
|
|
2518
2557
|
case "value":
|
|
2519
2558
|
styleRule.style.setProperty(name, buffer.trim(), priority, parseError);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//.CommonJS
|
|
2
|
+
var CSSOM = {
|
|
3
|
+
CSSRule: require("./CSSRule").CSSRule
|
|
4
|
+
};
|
|
5
|
+
///CommonJS
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @constructor
|
|
10
|
+
* @see https://drafts.csswg.org/css-counter-styles/#the-csscounterstylerule-interface
|
|
11
|
+
*/
|
|
12
|
+
CSSOM.CSSCounterStyleRule = function CSSCounterStyleRule() {
|
|
13
|
+
CSSOM.CSSRule.call(this);
|
|
14
|
+
this.name = "";
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
CSSOM.CSSCounterStyleRule.prototype = new CSSOM.CSSRule();
|
|
18
|
+
CSSOM.CSSCounterStyleRule.prototype.constructor = CSSOM.CSSCounterStyleRule;
|
|
19
|
+
CSSOM.CSSCounterStyleRule.prototype.type = 11;
|
|
20
|
+
|
|
21
|
+
//.CommonJS
|
|
22
|
+
exports.CSSCounterStyleRule = CSSOM.CSSCounterStyleRule;
|
|
23
|
+
///CommonJS
|
package/lib/index.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.CSSStyleDeclaration = require('./CSSStyleDeclaration').CSSStyleDeclarati
|
|
|
4
4
|
exports.CSSRule = require('./CSSRule').CSSRule;
|
|
5
5
|
exports.CSSNestedDeclarations = require('./CSSNestedDeclarations').CSSNestedDeclarations;
|
|
6
6
|
exports.CSSGroupingRule = require('./CSSGroupingRule').CSSGroupingRule;
|
|
7
|
+
exports.CSSCounterStyleRule = require('./CSSCounterStyleRule').CSSCounterStyleRule;
|
|
7
8
|
exports.CSSConditionRule = require('./CSSConditionRule').CSSConditionRule;
|
|
8
9
|
exports.CSSStyleRule = require('./CSSStyleRule').CSSStyleRule;
|
|
9
10
|
exports.MediaList = require('./MediaList').MediaList;
|
package/lib/parse.js
CHANGED
|
@@ -40,6 +40,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
40
40
|
"atBlock": true,
|
|
41
41
|
"containerBlock": true,
|
|
42
42
|
"conditionBlock": true,
|
|
43
|
+
"counterStyleBlock": true,
|
|
43
44
|
'documentRule-begin': true,
|
|
44
45
|
"layerBlock": true
|
|
45
46
|
};
|
|
@@ -55,7 +56,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
55
56
|
var ancestorRules = [];
|
|
56
57
|
var prevScope;
|
|
57
58
|
|
|
58
|
-
var name, priority="", styleRule, mediaRule, containerRule, supportsRule, importRule, fontFaceRule, keyframesRule, documentRule, hostRule, startingStyleRule, layerBlockRule, layerStatementRule, nestedSelectorRule;
|
|
59
|
+
var name, priority="", styleRule, mediaRule, containerRule, counterStyleRule, supportsRule, importRule, fontFaceRule, keyframesRule, documentRule, hostRule, startingStyleRule, layerBlockRule, layerStatementRule, nestedSelectorRule;
|
|
59
60
|
|
|
60
61
|
var atKeyframesRegExp = /@(-(?:\w+-)+)?keyframes/g; // Match @keyframes and vendor-prefixed @keyframes
|
|
61
62
|
// Regex above is not ES5 compliant
|
|
@@ -587,6 +588,15 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
587
588
|
});
|
|
588
589
|
buffer = "";
|
|
589
590
|
break;
|
|
591
|
+
} else if (token.indexOf("@counter-style", i) === i) {
|
|
592
|
+
validateAtRule("@counter-style", function(){
|
|
593
|
+
state = "counterStyleBlock"
|
|
594
|
+
counterStyleRule = new CSSOM.CSSCounterStyleRule();
|
|
595
|
+
counterStyleRule.__starts = i;
|
|
596
|
+
i += "counter-style".length;
|
|
597
|
+
}, true);
|
|
598
|
+
buffer = "";
|
|
599
|
+
break;
|
|
590
600
|
} else if (token.indexOf("@layer", i) === i) {
|
|
591
601
|
validateAtRule("@layer", function(){
|
|
592
602
|
state = "layerBlock"
|
|
@@ -596,7 +606,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
596
606
|
});
|
|
597
607
|
buffer = "";
|
|
598
608
|
break;
|
|
599
|
-
}
|
|
609
|
+
} else if (token.indexOf("@supports", i) === i) {
|
|
600
610
|
validateAtRule("@supports", function(){
|
|
601
611
|
state = "conditionBlock";
|
|
602
612
|
supportsRule = new CSSOM.CSSSupportsRule();
|
|
@@ -713,6 +723,12 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
713
723
|
containerRule.parentStyleSheet = styleSheet;
|
|
714
724
|
buffer = "";
|
|
715
725
|
state = "before-selector";
|
|
726
|
+
} else if (state === "counterStyleBlock") {
|
|
727
|
+
// TODO: Validate counter-style name. At least that it cannot be empty nor multiple
|
|
728
|
+
counterStyleRule.name = buffer.trim().replace(/\n/g, "");
|
|
729
|
+
currentScope = parentRule = counterStyleRule;
|
|
730
|
+
counterStyleRule.parentStyleSheet = styleSheet;
|
|
731
|
+
buffer = "";
|
|
716
732
|
} else if (state === "conditionBlock") {
|
|
717
733
|
supportsRule.conditionText = buffer.trim();
|
|
718
734
|
|
|
@@ -947,6 +963,15 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
947
963
|
break;
|
|
948
964
|
|
|
949
965
|
case "}":
|
|
966
|
+
if (state === "counterStyleBlock") {
|
|
967
|
+
// FIXME : Implement cssText get setter that parses the real implementation
|
|
968
|
+
counterStyleRule.cssText = "@counter-style " + counterStyleRule.name + " { " + buffer.trim().replace(/\n/g, " ").replace(/(['"])(?:\\.|[^\\])*?\1|(\s{2,})/g, function(match, quote, spaces) {
|
|
969
|
+
return quote ? match : ' ';
|
|
970
|
+
}) + " }";
|
|
971
|
+
buffer = "";
|
|
972
|
+
state = "before-selector";
|
|
973
|
+
}
|
|
974
|
+
|
|
950
975
|
switch (state) {
|
|
951
976
|
case "value":
|
|
952
977
|
styleRule.style.setProperty(name, buffer.trim(), priority, parseError);
|
|
@@ -1152,6 +1177,7 @@ CSSOM.CSSNestedDeclarations = require("./CSSNestedDeclarations").CSSNestedDeclar
|
|
|
1152
1177
|
CSSOM.CSSImportRule = require("./CSSImportRule").CSSImportRule;
|
|
1153
1178
|
CSSOM.CSSGroupingRule = require("./CSSGroupingRule").CSSGroupingRule;
|
|
1154
1179
|
CSSOM.CSSMediaRule = require("./CSSMediaRule").CSSMediaRule;
|
|
1180
|
+
CSSOM.CSSCounterStyleRule = require("./CSSCounterStyleRule").CSSCounterStyleRule;
|
|
1155
1181
|
CSSOM.CSSContainerRule = require("./CSSContainerRule").CSSContainerRule;
|
|
1156
1182
|
CSSOM.CSSConditionRule = require("./CSSConditionRule").CSSConditionRule;
|
|
1157
1183
|
CSSOM.CSSSupportsRule = require("./CSSSupportsRule").CSSSupportsRule;
|