|
64 | 64 | // a string of scoped css where each selector is transformed to include
|
65 | 65 | // a class created from the scope. ShadowDOM selectors are also transformed
|
66 | 66 | // (e.g. :host) to use the scoping selector.
|
67 |
| - function transformCss(rules, scope, callback) { |
| 67 | + function transformCss(rules, scope, ext, callback) { |
| 68 | + var hostScope = calcHostScope(scope, ext); |
68 | 69 | return Polymer.StyleUtil.toCssText(rules, function(rule) {
|
69 |
| - transformRule(rule, scope); |
| 70 | + transformRule(rule, scope, hostScope); |
70 | 71 | if (callback) {
|
71 |
| - callback(rule, scope); |
| 72 | + callback(rule, scope, hostScope); |
72 | 73 | }
|
73 | 74 | });
|
74 | 75 | }
|
75 | 76 |
|
| 77 | + function calcHostScope(scope, ext) { |
| 78 | + return ext ? '[is=' + scope + ']' : scope; |
| 79 | + } |
| 80 | + |
76 | 81 | // transforms a css rule to a scoped rule.
|
77 |
| - function transformRule(rule, scope) { |
| 82 | + function transformRule(rule, scope, hostScope) { |
78 | 83 | var p$ = rule.selector.split(COMPLEX_SELECTOR_SEP);
|
79 | 84 | for (var i=0, l=p$.length, p; (i<l) && (p=p$[i]); i++) {
|
80 |
| - p$[i] = transformComplexSelector(p, scope); |
| 85 | + p$[i] = transformComplexSelector(p, scope, hostScope); |
81 | 86 | }
|
82 | 87 | rule.selector = p$.join(COMPLEX_SELECTOR_SEP);
|
83 | 88 | }
|
84 | 89 |
|
85 |
| - function transformComplexSelector(selector, scope) { |
| 90 | + function transformComplexSelector(selector, scope, hostScope) { |
86 | 91 | var stop = false;
|
87 | 92 | selector = selector.replace(SIMPLE_SELECTOR_SEP, function(s) {
|
88 | 93 | if (!stop) {
|
89 |
| - var o = transformCompoundSelector(s, scope); |
| 94 | + var o = transformCompoundSelector(s, scope, hostScope); |
90 | 95 | if (o.stop) {
|
91 | 96 | stop = true;
|
92 | 97 | }
|
|
100 | 105 | return selector;
|
101 | 106 | }
|
102 | 107 |
|
103 |
| - function transformCompoundSelector(selector, scope) { |
| 108 | + function transformCompoundSelector(selector, scope, hostScope) { |
104 | 109 | // replace :host with host scoping class
|
105 | 110 | var jumpIndex = selector.search(SCOPE_JUMP);
|
106 | 111 | if (selector.indexOf(HOST) >=0) {
|
107 |
| - var r = scope; |
108 | 112 | // :host(...)
|
109 | 113 | selector = selector.replace(HOST_PAREN, function(m, host, paren) {
|
110 |
| - return r + paren; |
| 114 | + return hostScope + paren; |
111 | 115 | });
|
112 | 116 | // now normal :host
|
113 |
| - selector = selector.replace(HOST, r); |
| 117 | + selector = selector.replace(HOST, hostScope); |
114 | 118 | // replace other selectors with scoping class
|
115 | 119 | } else if (jumpIndex !== 0) {
|
116 | 120 | selector = transformSimpleSelector(selector, scope);
|
|
0 commit comments