function shadyShim(ast, style, elements) {
  const scope = scopeMap.get(style);
  const element = getModuleElement(scope, elements);
  // only shim if module is a full polymer element, not just a style module
  if (!scope || !element) {
    return;
  }
  const ext = getTypeExtends(element);
  Polymer.StyleTransformer.css(ast, scope, ext);
  const module = domModuleCache[scope];
  const head = findHead(module);
  dom5.setAttribute(style, 'scope', scope);
  const insertionPoint = afterLastInsertion();
  dom5.insertBefore(head, insertionPoint || head.childNodes[0], style);
  // leave comment breadcrumb for css property shim to insert new styles
  const comment = dom5.constructors.comment();
  dom5.setTextContent(comment, ` Shady DOM styles for ${scope} `)
  dom5.insertBefore(head, style, comment);
  lastShadyInsertionPoint = style;
  const template = dom5.query(module, pred.hasTagName('template'));
  // apply scoping to template
  if (template) {
    const elements = dom5.queryAll(template, notStyleMatch);
    elements.forEach(el => addClass(el, scope));
  }
}
Example #2
0
function markPolymerElement(polymerElement, useNativeShadow, analysis) {
  const document = getInlinedTemplateDocument(polymerElement, analysis);
  if (!document) {
    return;
  }
  const template = document.ast;
  // add a comment of the form `<!--css-build:shadow-->` to the template as the first child
  const buildComment = dom5.constructors.comment(`css-build:${useNativeShadow ? 'shadow' : 'shady'}`);
  prepend(template, buildComment);
  if (!useNativeShadow) {
    shadyScopeElementsInTemplate(template, polymerElement.tagName);
  }
}