diff --git a/src/ShadowCSS.js b/src/ShadowCSS.js
index 8851e07..46b8c8d 100644
--- a/src/ShadowCSS.js
+++ b/src/ShadowCSS.js
@@ -89,6 +89,19 @@
becomes:
x-foo [pseudo=x-special] { ... }
+
+ * ::part(): These rules are converted to rules that take advantage of the
+ part attribute. For example, a shadowRoot like this inside an x-foo
+
+
Special
+
+ with a rule like this:
+
+ x-foo::part(special) { ... }
+
+ becomes:
+
+ x-foo [part=special] { ... }
Unaddressed ShadowDOM styling features:
@@ -372,7 +385,9 @@ var ShadowCSS = {
convertScopedStyles: function(styles, name) {
var cssText = stylesToCssText(styles).replace(hostRuleRe, '');
cssText = this.insertPolyfillHostInCssText(cssText);
+ cssText = this.convertColonHost(cssText);
cssText = this.convertPseudos(cssText);
+ cssText = this.convertParts(cssText);
var rules = cssToRules(cssText);
cssText = this.scopeRules(rules, name);
return cssText;
@@ -380,6 +395,18 @@ var ShadowCSS = {
convertPseudos: function(cssText) {
return cssText.replace(cssPseudoRe, ' [pseudo=$1]');
},
+ convertParts: function(cssText) {
+ return cssText.replace(cssPartRe, ' [part=$1]');
+ },
+ convertColonHost: function(cssText) {
+ /*
+ var is = '[is=' + name + ']';
+ var r = name + '$1$2, $1 ' + name + '$2, ' +
+ is + '$1$2, $1' + is + '$2 ';
+ */
+ var r = '$1$2$3, $2 $1$3';
+ return cssText.replace(cssColonHostRe, r);
+ },
// change a selector like 'div' to 'name div'
scopeRules: function(cssRules, name) {
var cssText = '';
@@ -469,6 +496,9 @@ var hostRuleRe = /@host[^{]*{(([^}]*?{[^{]*?}[\s\S]*?)+)}/gim,
cssPolyfillRuleCommentRe = /\/\*\s@polyfill-rule([^*]*\*+([^/*][^*]*\*+)*)\//gim,
cssPolyfillUnscopedRuleCommentRe = /\/\*\s@polyfill-unscoped-rule([^*]*\*+([^/*][^*]*\*+)*)\//gim,
cssPseudoRe = /::(x-[^\s{,(]*)/gim,
+ cssPartRe = /::part\(([^)]*)\)/gim,
+ // note: :host pre-processed to -host.
+ cssColonHostRe = /(-host)(?:\(([^)]*)\))?([^,{]*)/gim,
selectorReSuffix = '([>\\s~+\[.,{:][\\s\\S]*)?$',
hostRe = /@host/gim,
colonHostRe = /\:host/gim,
diff --git a/test/html/styling/colon-host.html b/test/html/styling/colon-host.html
new file mode 100644
index 0000000..e50778f
--- /dev/null
+++ b/test/html/styling/colon-host.html
@@ -0,0 +1,211 @@
+
+
+
+
+
+ Using :host styling
+
+
+
+
+
+
+
+
+
+
background
+
+
+
+
+
white text
+
+
+
+
+
+
orange border & gray background
+
+
+
+
+
background
+
+
+
+
+
+
+
+
+
+
padding: 20px
+
+
+
+
+
padding: 20px
+
+
+
+
+
Expected: red background
+
+
+
Expected: red background
+
+
+
Expected: green background
+
+
+
Expected: black background
+
+
+
Expected: black background
+
+
+
Expected: red background with white text
+
+
+
Expected: red background with white text
+
+
+
Expected: red background with black text and orange border
+
+
+
Expected: red background with black text and orange border and 20px padding