var css_ensureScopedStyles;

(function(){
	css_ensureScopedStyles = function (str, node, el) {
		var attr = node.attr;
		if (attr.scoped == null) {
			return str;
		}
		attr.scoped = null;


		var str_;
		var id = getScopeIdentity(node, el);
		str_ = transformScopedStyles(str, id);
		str_ = transformHostCss(str_, id);
		return str_;
	};

	var rgx_selector = /^([\s]*)([^\{\}]+)\{/gm;
	var rgx_host = /^([\s]*):host\s*(\(([^)]+)\))?\s*\{/gm;

	function transformScopedStyles (css, id){
		return css.replace(rgx_selector, function(full, pref, selector){
			if (selector.indexOf(':host') !== -1)
				return full;

			var arr = selector.split(','),
				imax = arr.length,
				i = 0;
			for(; i < imax; i++) {
				arr[i] = id + ' ' + arr[i];
			}
			selector = arr.join(',');
			return pref + selector + '{';
		});
	}

	function transformHostCss (css, id) {
		return css.replace(rgx_host, function(full, pref, ext, expr){
			return pref
				+ id
				+ (expr || '')
				+ '{';
		});
	}

	function getScopeIdentity(node, el) {
		var identity = 'scoped__css__' + node.id;
		if (el.id) {
			el.className += ' ' + identity;
			return '.' + identity;
		}
		el.setAttribute('id', identity);
		return '#' + identity;
	}
}());
@@ -21,17 +21,16 @@
 Styles;%0A
-%0A
 (functio
@@ -131,16 +131,37 @@
 coped ==
+ null && attr%5BKEY%5D ==
  null) %7B
@@ -180,16 +180,136 @@
 tr;%0A%09%09%7D%0A
+%09%09// Remove %60scoped%60 attribute to exclude supported browsers.%0A%09%09// Redefine custom attribute to use same template later%0A
 %09%09attr.s
@@ -326,20 +326,23 @@
 ll;%0A
-%0A%0A%09%09var str_
+%09%09attr%5BKEY%5D = 1
 ;%0A%09%09
@@ -378,16 +378,34 @@
 e, el);%0A
+%09%09var str_ = str;%0A
 %09%09str_ =
@@ -430,16 +430,17 @@
 yles(str
+_
 , id);%0A%09
@@ -495,16 +495,39 @@
 _;%0A%09%7D;%0A%0A
+%09var KEY = 'x-scoped';%0A
 %09var rgx

fix (ScopedCss) Preserve scoped property in MaskAst