|
36 | 36 |
|
37 | 37 | * ::shadow, /deep/: processed simimlar to ::content
|
38 | 38 |
|
39 |
| - * :host-context(...): NOT SUPPORTED |
| 39 | + * :host-context(...): scopeName..., ... scopeName |
40 | 40 |
|
41 | 41 | */
|
42 | 42 | var api = {
|
|
156 | 156 |
|
157 | 157 | _transformComplexSelector: function(selector, scope, hostScope) {
|
158 | 158 | var stop = false;
|
| 159 | + var hostContext = false; |
159 | 160 | var self = this;
|
160 | 161 | selector = selector.replace(SIMPLE_SELECTOR_SEP, function(m, c, s) {
|
161 | 162 | if (!stop) {
|
162 | 163 | var o = self._transformCompoundSelector(s, c, scope, hostScope);
|
163 |
| - if (o.stop) { |
164 |
| - stop = true; |
165 |
| - } |
| 164 | + stop = stop || o.stop; |
| 165 | + hostContext = hostContext || o.hostContext; |
166 | 166 | c = o.combinator;
|
167 | 167 | s = o.value;
|
168 | 168 | } else {
|
169 | 169 | s = s.replace(SCOPE_JUMP, ' ');
|
170 | 170 | }
|
171 | 171 | return c + s;
|
172 | 172 | });
|
| 173 | + if (hostContext) { |
| 174 | + selector = selector.replace(CONTEXT_MARKER_MATCH, |
| 175 | + function(m, pre, paren, post) { |
| 176 | + return pre + paren + ' ' + hostScope + post + |
| 177 | + COMPLEX_SELECTOR_SEP + ' ' + pre + hostScope + paren + post; |
| 178 | + }); |
| 179 | + } |
173 | 180 | return selector;
|
174 | 181 | },
|
175 | 182 |
|
176 | 183 | _transformCompoundSelector: function(selector, combinator, scope, hostScope) {
|
177 | 184 | // replace :host with host scoping class
|
178 | 185 | var jumpIndex = selector.search(SCOPE_JUMP);
|
179 |
| - if (selector.indexOf(HOST) >=0) { |
180 |
| - // :host(...) |
| 186 | + var hostContext = false; |
| 187 | + if (selector.indexOf(HOST_CONTEXT) >=0) { |
| 188 | + // :host-context(...) -> ##...## |
| 189 | + selector = selector.replace(HOST_CONTEXT_PAREN, function(m, host, paren) { |
| 190 | + hostContext = true; |
| 191 | + return CONTEXT_MARKER + paren + CONTEXT_MARKER; |
| 192 | + }); |
| 193 | + } else if (selector.indexOf(HOST) >=0) { |
| 194 | + // :host(...) -> scopeName... |
181 | 195 | selector = selector.replace(HOST_PAREN, function(m, host, paren) {
|
182 | 196 | return hostScope + paren;
|
183 | 197 | });
|
|
199 | 213 | selector = selector.replace(SCOPE_JUMP, ' ');
|
200 | 214 | stop = true;
|
201 | 215 | }
|
202 |
| - return {value: selector, combinator: combinator, stop: stop}; |
| 216 | + return {value: selector, combinator: combinator, stop: stop, |
| 217 | + hostContext: hostContext}; |
203 | 218 | },
|
204 | 219 |
|
205 | 220 | _transformSimpleSelector: function(selector, scope) {
|
|
243 | 258 | // :host(:not([selected]), more general support requires
|
244 | 259 | // parsing which seems like overkill
|
245 | 260 | var HOST_PAREN = /(\:host)(?:\(((?:\([^)(]*\)|[^)(]*)+?)\))/g;
|
| 261 | + var HOST_CONTEXT = ':host-context'; |
| 262 | + var HOST_CONTEXT_PAREN = /(\:host-context)(?:\(((?:\([^)(]*\)|[^)(]*)+?)\))/g; |
| 263 | + var CONTEXT_MARKER = '##'; |
| 264 | + var CONTEXT_MARKER_MATCH = /(.*)##(.*)##(.*)/; |
246 | 265 | var CONTENT = '::content';
|
247 | 266 | var SCOPE_JUMP = /\:\:content|\:\:shadow|\/deep\//;
|
248 | 267 | var CSS_CLASS_PREFIX = '.';
|
|
0 commit comments