MCPcopy Create free account
hub / github.com/ampproject/amphtml / scopeRules

Function scopeRules

third_party/webcomponentsjs/ShadowCSS.js:130–165  ·  view source on GitHub ↗
(cssRules, scopeSelector, opt_transformer)

Source from the content-addressed store, hash-verified

128
129// change a selector like 'div' to 'name div'
130export function scopeRules(cssRules, scopeSelector, opt_transformer) {
131 var cssText = '';
132 if (cssRules) {
133 Array.prototype.forEach.call(cssRules, function(rule) {
134 if (rule.selectorText && (rule.style && rule.style.cssText !== undefined)) {
135 cssText += doScopeSelector(
136 rule.selectorText, scopeSelector, opt_transformer) + ' {\n\t';
137 cssText += propertiesFromRule(rule) + '\n}\n\n';
138 } else if (rule.type === CSSRule.MEDIA_RULE) {
139 cssText += '@media ' + rule.media.mediaText + ' {\n';
140 cssText += scopeRules(rule.cssRules, scopeSelector);
141 cssText += '\n}\n\n';
142 } else {
143 // KEYFRAMES_RULE in IE throws when we query cssText
144 // when it contains a -webkit- property.
145 // if this happens, we fallback to constructing the rule
146 // from the CSSRuleSet
147 // https://connect.microsoft.com/IE/feedbackdetail/view/955703/accessing-csstext-of-a-keyframe-rule-that-contains-a-webkit-property-via-cssom-generates-exception
148 try {
149 if (rule.cssText) {
150 cssText += rule.cssText + '\n\n';
151 }
152 } catch(x) {
153 if (
154 isIeSupported &&
155 rule.type === CSSRule.KEYFRAMES_RULE &&
156 rule.cssRules
157 ) {
158 cssText += ieSafeCssTextFromKeyFrameRule(rule);
159 }
160 }
161 }
162 });
163 }
164 return cssText;
165}
166
167export function ieSafeCssTextFromKeyFrameRule(rule) {
168 var cssText = '@keyframes ' + rule.name + ' {';

Callers

nothing calls this directly

Calls 3

doScopeSelectorFunction · 0.85
propertiesFromRuleFunction · 0.85

Tested by

no test coverage detected