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

Function applyStrictSelectorScope

third_party/webcomponentsjs/ShadowCSS.js:233–250  ·  view source on GitHub ↗
(selector, scopeSelector)

Source from the content-addressed store, hash-verified

231// return a selector with [name] suffix on each simple selector
232// e.g. .foo.bar > .zot becomes .foo[name].bar[name] > .zot[name]
233export function applyStrictSelectorScope(selector, scopeSelector) {
234 scopeSelector = scopeSelector.replace(/\[is=([^\]]*)\]/g, '$1');
235 var splits = [' ', '>', '+', '~'],
236 scoped = selector,
237 attrName = '[' + scopeSelector + ']';
238 splits.forEach(function(sep) {
239 var parts = scoped.split(sep);
240 scoped = parts.map(function(p) {
241 // remove :host since it should be unnecessary
242 var t = p.trim().replace(polyfillHostRe, '');
243 if (t && (splits.indexOf(t) < 0) && (t.indexOf(attrName) < 0)) {
244 p = t.replace(/([^:]*)(:*)(.*)/, '$1' + attrName + '$2$3');
245 }
246 return p;
247 }).join(sep);
248 });
249 return scoped;
250}
251
252export function propertiesFromRule(rule) {
253 var cssText = rule.style.cssText;

Callers 1

doScopeSelectorFunction · 0.85

Calls 2

replaceMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected