diff --git a/src/lib/style-properties.html b/src/lib/style-properties.html index 8f0fd3a8..7daadf66 100644 --- a/src/lib/style-properties.html +++ b/src/lib/style-properties.html @@ -82,23 +82,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN // returns cssText of properties that consume variables/mixins collectCssText: function(rule) { - var customCssText = ''; var cssText = rule.parsedCssText; // NOTE: we support consumption inside mixin assignment // but not production, so strip out {...} cssText = cssText.replace(this.rx.BRACKETED, '') .replace(this.rx.VAR_ASSIGN, ''); - var parts = cssText.split(';'); - for (var i=0, p; i .x-foo-42 .a.x-foo - // host selector: x-foo.wide -> x-foo.x-foo-42.wide + // host selector: x-foo.wide -> .x-foo-42.wide + // note: we use only the scope class (.x-foo-42) and not the hostSelector + // (x-foo) to scope :host rules; this helps make property host rules + // have low specificity. They are overrideable by class selectors but, + // unfortunately, not by type selectors (e.g. overriding via + // `.special` is ok, but not by `x-foo`). _scopeSelector: function(rule, hostRx, hostSelector, viaAttr, scopeId) { rule.transformedSelector = rule.transformedSelector || rule.selector; var selector = rule.transformedSelector; @@ -370,7 +364,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN var parts = selector.split(','); for (var i=0, l=parts.length, p; (i+~]+)([^\s>+~]+)/g; + var SIMPLE_SELECTOR_SEP = /(^|[\s>+~]+)((?:\[.+?\]|[^\s>+~=\[])+)/g; var HOST = ':host'; var ROOT = ':root'; // NOTE: this supports 1 nested () pair for things like diff --git a/src/standard/styling.html b/src/standard/styling.html index 134d6362..edf1144b 100644 --- a/src/standard/styling.html +++ b/src/standard/styling.html @@ -42,8 +42,19 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN } if (this._template) { this._styles = this._collectStyles(); + // calculate shimmed styles (we must always do this as it + // stores shimmed style data in the css rules for later use) var cssText = styleTransformer.elementStyles(this); - if (cssText) { + // do we really need to output shimmed styles + var needsStatic = this._needsStaticStyles(this._styles); + // under shady dom we always output a shimmed style (which may be + // empty) so that other dynamic stylesheets can always be placed + // after the element's main stylesheet. + // This helps ensure element styles are always in registration order. + if (needsStatic || !nativeShadow) { + // NOTE: IE has css style ordering issues unless there's at least a + // space in the stylesheet. + cssText = needsStatic ? cssText : ' '; var style = styleUtil.applyCss(cssText, this.is, nativeShadow ? this._template.content : null); // keep track of style when in document scope (polyfill) so we can diff --git a/src/standard/x-styling.html b/src/standard/x-styling.html index 0f355b9c..49219da2 100644 --- a/src/standard/x-styling.html +++ b/src/standard/x-styling.html @@ -18,6 +18,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN var serializeValueToAttribute = Polymer.Base.serializeValueToAttribute; var propertyUtils = Polymer.StyleProperties; + var styleUtil = Polymer.StyleUtil; var styleTransformer = Polymer.StyleTransformer; var styleDefaults = Polymer.StyleDefaults; @@ -25,6 +26,22 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN Polymer.Base._addFeature({ + // Skip applying CSS if there are some mixins or variables used + // since styles with mixins and variables will be added on later stages anyway, + // and will include styles applied here, no need to do this twice + _needsStaticStyles: function(styles) { + var needsStatic; + for (var i=0, l=styles.length, css; i < l; i++) { + css = styleUtil.parser._clean(styles[i].textContent); + needsStatic = needsStatic || Boolean(css); + if (css.match(propertyUtils.rx.MIXIN_MATCH) || + css.match(propertyUtils.rx.VAR_MATCH)) { + return false; + } + } + return needsStatic; + }, + _prepStyleProperties: function() { // note: an element should produce an x-scope stylesheet // if it has any _stylePropertyNames diff --git a/test/unit/styling-cross-scope-var.html b/test/unit/styling-cross-scope-var.html index 371345ac..f4b8b506 100644 --- a/test/unit/styling-cross-scope-var.html +++ b/test/unit/styling-cross-scope-var.html @@ -14,6 +14,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN + @@ -533,12 +538,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN - - + + + + + + + + + + + + +