Skip to content

Commit d90a5d3

Browse files
authored
add support for @starting-style (#1)
* add support for starting style * Create three-bears-kick.md
1 parent 87e6cd0 commit d90a5d3

File tree

7 files changed

+91
-1
lines changed

7 files changed

+91
-1
lines changed

.changeset/three-bears-kick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"rrweb-cssom": minor
3+
---
4+
5+
add support for @starting-style

lib/CSSRule.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ CSSOM.CSSRule.DOCUMENT_RULE = 13;
3030
CSSOM.CSSRule.FONT_FEATURE_VALUES_RULE = 14;
3131
CSSOM.CSSRule.VIEWPORT_RULE = 15;
3232
CSSOM.CSSRule.REGION_STYLE_RULE = 16;
33+
CSSOM.CSSRule.STARTING_STYLE_RULE = 1002;
3334

3435

3536
CSSOM.CSSRule.prototype = {

lib/CSSStartingStyleRule.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//.CommonJS
2+
var CSSOM = {
3+
CSSRule: require("./CSSRule").CSSRule
4+
};
5+
///CommonJS
6+
7+
8+
/**
9+
* @constructor
10+
* @see http://www.w3.org/TR/shadow-dom/#host-at-rule
11+
*/
12+
CSSOM.CSSStartingStyleRule = function CSSStartingStyleRule() {
13+
CSSOM.CSSRule.call(this);
14+
this.cssRules = [];
15+
};
16+
17+
CSSOM.CSSStartingStyleRule.prototype = new CSSOM.CSSRule();
18+
CSSOM.CSSStartingStyleRule.prototype.constructor = CSSOM.CSSStartingStyleRule;
19+
CSSOM.CSSStartingStyleRule.prototype.type = 1002;
20+
//FIXME
21+
//CSSOM.CSSStartingStyleRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
22+
//CSSOM.CSSStartingStyleRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
23+
24+
Object.defineProperty(CSSOM.CSSStartingStyleRule.prototype, "cssText", {
25+
get: function() {
26+
var cssTexts = [];
27+
for (var i=0, length=this.cssRules.length; i < length; i++) {
28+
cssTexts.push(this.cssRules[i].cssText);
29+
}
30+
return "@starting-style {" + cssTexts.join("") + "}";
31+
}
32+
});
33+
34+
35+
//.CommonJS
36+
exports.CSSStartingStyleRule = CSSOM.CSSStartingStyleRule;
37+
///CommonJS

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ exports.CSSSupportsRule = require('./CSSSupportsRule').CSSSupportsRule;
1111
exports.CSSImportRule = require('./CSSImportRule').CSSImportRule;
1212
exports.CSSFontFaceRule = require('./CSSFontFaceRule').CSSFontFaceRule;
1313
exports.CSSHostRule = require('./CSSHostRule').CSSHostRule;
14+
exports.CSSStartingStyleRule = require('./CSSStartingStyleRule').CSSStartingStyleRule;
1415
exports.StyleSheet = require('./StyleSheet').StyleSheet;
1516
exports.CSSStyleSheet = require('./CSSStyleSheet').CSSStyleSheet;
1617
exports.CSSKeyframesRule = require('./CSSKeyframesRule').CSSKeyframesRule;

lib/parse.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ CSSOM.parse = function parse(token) {
5151
var hasAncestors = false;
5252
var prevScope;
5353

54-
var name, priority="", styleRule, mediaRule, supportsRule, importRule, fontFaceRule, keyframesRule, documentRule, hostRule;
54+
var name, priority="", styleRule, mediaRule, supportsRule, importRule, fontFaceRule, keyframesRule, documentRule, hostRule, startingStyleRule;
5555

5656
var atKeyframesRegExp = /@(-(?:\w+-)+)?keyframes/g;
5757

@@ -171,6 +171,13 @@ CSSOM.parse = function parse(token) {
171171
hostRule.__starts = i;
172172
buffer = "";
173173
break;
174+
} else if (token.indexOf("@starting-style", i) === i) {
175+
state = "startingStyleRule-begin";
176+
i += "startingStyle".length;
177+
startingStyleRule = new CSSOM.CSSStartingStyleRule();
178+
startingStyleRule.__starts = i;
179+
buffer = "";
180+
break;
174181
} else if (token.indexOf("@import", i) === i) {
175182
state = "importRule-begin";
176183
i += "import".length;
@@ -238,6 +245,16 @@ CSSOM.parse = function parse(token) {
238245
hostRule.parentStyleSheet = styleSheet;
239246
buffer = "";
240247
state = "before-selector";
248+
} else if (state === "startingStyleRule-begin") {
249+
if (parentRule) {
250+
ancestorRules.push(parentRule);
251+
}
252+
253+
currentScope = parentRule = startingStyleRule;
254+
startingStyleRule.parentStyleSheet = styleSheet;
255+
buffer = "";
256+
state = "before-selector";
257+
241258
} else if (state === "fontFaceRule-begin") {
242259
if (parentRule) {
243260
fontFaceRule.parentRule = parentRule;
@@ -457,6 +474,7 @@ CSSOM.CSSConditionRule = require("./CSSConditionRule").CSSConditionRule;
457474
CSSOM.CSSSupportsRule = require("./CSSSupportsRule").CSSSupportsRule;
458475
CSSOM.CSSFontFaceRule = require("./CSSFontFaceRule").CSSFontFaceRule;
459476
CSSOM.CSSHostRule = require("./CSSHostRule").CSSHostRule;
477+
CSSOM.CSSStartingStyleRule = require("./CSSStartingStyleRule").CSSStartingStyleRule;
460478
CSSOM.CSSStyleDeclaration = require('./CSSStyleDeclaration').CSSStyleDeclaration;
461479
CSSOM.CSSKeyframeRule = require('./CSSKeyframeRule').CSSKeyframeRule;
462480
CSSOM.CSSKeyframesRule = require('./CSSKeyframesRule').CSSKeyframesRule;

spec/parse.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,33 @@ var TESTS = [
972972
return result;
973973
})()
974974
},
975+
{
976+
input: "@starting-style { body { background: red; } }",
977+
result: (function() {
978+
var result = {
979+
cssRules: [
980+
{
981+
cssRules: {
982+
0: {
983+
selectorText: "body",
984+
style: {
985+
0: "background",
986+
length: 1,
987+
parentRule: "..",
988+
background: "red"
989+
}
990+
}
991+
},
992+
parentRule: null
993+
}
994+
],
995+
parentStyleSheet: null
996+
};
997+
result.cssRules[0].parentStyleSheet = result.cssRules[0].cssRules[0].parentStyleSheet = result;
998+
result.cssRules[0].cssRules[0].parentRule = result.cssRules[0];
999+
return result;
1000+
})()
1001+
},
9751002
{
9761003
// Non-vendor prefixed @keyframes rule, from Twitter Bootstrap (progress-bars):
9771004
input: '@keyframes progress-bar-stripes {\n from { background-position: 0 0; }\n to { background-position: 40px 0; }\n}',

src/files.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ exports.files = [
1010
"CSSImportRule",
1111
"CSSFontFaceRule",
1212
"CSSHostRule",
13+
"CSSStartingStyleRule",
1314
"StyleSheet",
1415
"CSSStyleSheet",
1516
"CSSKeyframesRule",

0 commit comments

Comments
 (0)