@@ -38,14 +38,23 @@ String shimCssText(String css, String tag) =>
38
38
* * `:host(.x)`
39
39
*
40
40
* When the shim is not powerful enough, you can fall back on the polyfill-next-selector
41
- * directive .
41
+ * and the polyfill-unscoped-next-selector directives .
42
42
*
43
43
* polyfill-next-selector {content: 'x > y'}
44
44
* z {}
45
45
*
46
46
* Becomes:
47
47
*
48
- * x[tag] > y[tag]
48
+ * x[tag] > y[tag] {}
49
+ *
50
+ * And:
51
+ *
52
+ * polyfill-unscoped-next-selector {content: 'x > y'}
53
+ * z {}
54
+ *
55
+ * Becomes:
56
+ *
57
+ * x > y {}
49
58
*
50
59
* See http://www.polymer-project.org/docs/polymer/styling.html#at-polyfill
51
60
*
@@ -64,6 +73,16 @@ class _CssShim {
64
73
caseSensitive: false ,
65
74
multiLine: true
66
75
);
76
+ static final RegExp POLYFILL_UNSCOPED_NEXT_SELECTOR_DIRECTIVE = new RegExp (
77
+ r"polyfill-unscoped-next-selector"
78
+ r"[^}]*"
79
+ r"content\:[\s]*"
80
+ r"'([^']*)'"
81
+ r"[^}]*}"
82
+ r"([^{]*)" ,
83
+ caseSensitive: false ,
84
+ multiLine: true
85
+ );
67
86
static final int NEXT_SELECTOR_CONTENT = 1 ;
68
87
69
88
static final String HOST_TOKEN = '-host-element' ;
@@ -79,6 +98,8 @@ class _CssShim {
79
98
static final RegExp COLON_HOST = new RegExp ('($HOST_TOKEN $PAREN_SUFFIX ' ,
80
99
caseSensitive: false , multiLine: true );
81
100
101
+ static final List <String > DO_NOT_SCOPE = ['polyfill-unscoped-next-selector' ];
102
+
82
103
final String tag;
83
104
final String attr;
84
105
@@ -88,12 +109,16 @@ class _CssShim {
88
109
String shimCssText (String css) {
89
110
final preprocessed = convertColonHost (applyPolyfillNextSelectorDirective (css));
90
111
final rules = cssToRules (preprocessed);
91
- return scopeRules (rules);
112
+ final scoped = scopeRules (rules);
113
+ return applyPolyfillUnscopedNextSelectorDirective (scoped);
92
114
}
93
115
94
116
String applyPolyfillNextSelectorDirective (String css) =>
95
117
css.replaceAllMapped (POLYFILL_NEXT_SELECTOR_DIRECTIVE , (m) => m[NEXT_SELECTOR_CONTENT ]);
96
118
119
+ String applyPolyfillUnscopedNextSelectorDirective (String css) =>
120
+ css.replaceAllMapped (POLYFILL_UNSCOPED_NEXT_SELECTOR_DIRECTIVE , (m) => m[NEXT_SELECTOR_CONTENT ]);
121
+
97
122
String convertColonHost (String css) {
98
123
css = css.replaceAll (":host" , HOST_TOKEN );
99
124
@@ -174,7 +199,10 @@ class _CssShim {
174
199
}
175
200
176
201
String insertAttrSuffixIntoSelectorPart (String p) {
177
- final shouldInsert = p.isNotEmpty && ! SELECTOR_SPLITS .contains (p) && ! p.contains (attr);
202
+ final shouldInsert = p.isNotEmpty &&
203
+ ! SELECTOR_SPLITS .contains (p) &&
204
+ ! p.contains (attr) &&
205
+ ! DO_NOT_SCOPE .contains (p);
178
206
return shouldInsert ? insertAttr (p) : p;
179
207
}
180
208
0 commit comments