Skip to content

Commit 6f87aa7

Browse files
authored
Merge branch 'master' into feature/add-container-ruler
2 parents 4e9e3a8 + d90a5d3 commit 6f87aa7

File tree

7 files changed

+92
-1
lines changed

7 files changed

+92
-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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ CSSOM.CSSRule.FONT_FEATURE_VALUES_RULE = 14;
3131
CSSOM.CSSRule.VIEWPORT_RULE = 15;
3232
CSSOM.CSSRule.REGION_STYLE_RULE = 16;
3333
CSSOM.CSSRule.CONTAINER_RULE = 17;
34+
CSSOM.CSSRule.STARTING_STYLE_RULE = 1002;
35+
3436

3537
CSSOM.CSSRule.prototype = {
3638
constructor: CSSOM.CSSRule

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
@@ -12,6 +12,7 @@ exports.CSSSupportsRule = require('./CSSSupportsRule').CSSSupportsRule;
1212
exports.CSSImportRule = require('./CSSImportRule').CSSImportRule;
1313
exports.CSSFontFaceRule = require('./CSSFontFaceRule').CSSFontFaceRule;
1414
exports.CSSHostRule = require('./CSSHostRule').CSSHostRule;
15+
exports.CSSStartingStyleRule = require('./CSSStartingStyleRule').CSSStartingStyleRule;
1516
exports.StyleSheet = require('./StyleSheet').StyleSheet;
1617
exports.CSSStyleSheet = require('./CSSStyleSheet').CSSStyleSheet;
1718
exports.CSSKeyframesRule = require('./CSSKeyframesRule').CSSKeyframesRule;

lib/parse.js

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

55-
var name, priority="", styleRule, mediaRule, containerRule, supportsRule, importRule, fontFaceRule, keyframesRule, documentRule, hostRule;
55+
var name, priority="", styleRule, mediaRule, containerRule, supportsRule, importRule, fontFaceRule, keyframesRule, documentRule, hostRule, startingStyleRule;
5656

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

@@ -179,6 +179,13 @@ CSSOM.parse = function parse(token) {
179179
hostRule.__starts = i;
180180
buffer = "";
181181
break;
182+
} else if (token.indexOf("@starting-style", i) === i) {
183+
state = "startingStyleRule-begin";
184+
i += "startingStyle".length;
185+
startingStyleRule = new CSSOM.CSSStartingStyleRule();
186+
startingStyleRule.__starts = i;
187+
buffer = "";
188+
break;
182189
} else if (token.indexOf("@import", i) === i) {
183190
state = "importRule-begin";
184191
i += "import".length;
@@ -256,6 +263,16 @@ CSSOM.parse = function parse(token) {
256263
hostRule.parentStyleSheet = styleSheet;
257264
buffer = "";
258265
state = "before-selector";
266+
} else if (state === "startingStyleRule-begin") {
267+
if (parentRule) {
268+
ancestorRules.push(parentRule);
269+
}
270+
271+
currentScope = parentRule = startingStyleRule;
272+
startingStyleRule.parentStyleSheet = styleSheet;
273+
buffer = "";
274+
state = "before-selector";
275+
259276
} else if (state === "fontFaceRule-begin") {
260277
if (parentRule) {
261278
fontFaceRule.parentRule = parentRule;
@@ -477,6 +494,7 @@ CSSOM.CSSConditionRule = require("./CSSConditionRule").CSSConditionRule;
477494
CSSOM.CSSSupportsRule = require("./CSSSupportsRule").CSSSupportsRule;
478495
CSSOM.CSSFontFaceRule = require("./CSSFontFaceRule").CSSFontFaceRule;
479496
CSSOM.CSSHostRule = require("./CSSHostRule").CSSHostRule;
497+
CSSOM.CSSStartingStyleRule = require("./CSSStartingStyleRule").CSSStartingStyleRule;
480498
CSSOM.CSSStyleDeclaration = require('./CSSStyleDeclaration').CSSStyleDeclaration;
481499
CSSOM.CSSKeyframeRule = require('./CSSKeyframeRule').CSSKeyframeRule;
482500
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
@@ -11,6 +11,7 @@ exports.files = [
1111
"CSSImportRule",
1212
"CSSFontFaceRule",
1313
"CSSHostRule",
14+
"CSSStartingStyleRule",
1415
"StyleSheet",
1516
"CSSStyleSheet",
1617
"CSSKeyframesRule",

0 commit comments

Comments
 (0)