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W,EAAK,IAElB,KAAK,eAAe,EAAG,SAAS,UAAU,GAAK,GAAM,IAIzD,EAAW,SAAS,IAClB,MAAM,EAAO,KAAK,eAAe,GAEjC,UADY,SAAS,MAAM,GACb,IAGhB,EAAW,SAAS,IAClB,IAAI,EAAO,KAAK,eAAe,GAC/B,MAAM,EAAM,SAAS,MAAM,GACvB,EAAiB,KAEnB,UAAU,YAAY,GAAM,IACtB,GAAW,EAAQ,mBACrB,iBAAiB,aAAa,GAE9B,iBAAiB,sBAAsB,EACzC,IAGF,YAAY,EAAG,IAEjB,UAAU,GACN,GACF,aAAa,EAAK,GACK,IAAnB,GACF,iBAAiB,KAGnB,UAAU,EAAK,EAAG,GACK,IAAnB,GACF,iBAAiB,EAAK,SAAS,IAAI,KAGvC,EAAO,SAAS,UAAU,GAAK,GAC/B,KAAK,eAAe,EAAG,EAAK,IAG9B,IAAK,MAAM,KAAkB,EAC3B,qBAAqB,GAEvB,OAAO,EAAM,KAAK,IAChB,MAAM,EAAM,YAAY,EAAU,EAAE,KACpC,MAAO,CACL,IAAK,EAAE,IACP,QAAS,EAAI,YACd,GAEL,CAEA,QAAQ,gBAAkB","file":"/npm/polymer-css-build@0.7.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/polymer-css-build@0.7.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n@license\nCopyright (c) 2016 The Polymer Project Authors. All rights reserved.\nThis code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\nThe complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\nThe complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\nCode distributed by Google as part of the polymer project is also\nsubject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n*/\n\n'use strict';\nconst dom5 = require('dom5');\n\nconst pathResolver = require('./lib/pathresolver.js');\n\nlet ApplyShim, CssParse, StyleTransformer, StyleUtil, ShadyUnscopedAttribute;\nconst loadShadyCSS = require('./lib/shadycss-entrypoint.js');\n\nconst {Analyzer, InMemoryOverlayUrlLoader} = require('polymer-analyzer');\n\n// Use types from polymer-analyzer\n/* eslint-disable no-unused-vars */\nconst {Analysis} = require('polymer-analyzer/lib/model/model.js');\nconst {ParsedHtmlDocument} = require('polymer-analyzer');\n/* eslint-enable */\n\nconst {traverse} = require('polymer-analyzer/lib/javascript/estraverse-shim.js');\n\nconst {dirShadowTransform, slottedToContent, shadyReplaceContent, fixBadVars} = require('./lib/polymer-1-transforms.js');\n\nconst {polymer2DirShadowTransform} = require('./lib/polymer-2-dir-transform.js');\n\nconst {createScannerMap, createParserMap} = require('./lib/slim-analyzer-options.js');\n\nconst {IdentifierIsDocumentVariable} = require('./lib/closure-html-template-scanner.js');\n\nconst pred = dom5.predicates;\n\n/**\n * Map of dom-module id to <dom-module> element in the HTML AST\n * @type {!Map<string, !Object>}\n */\nconst domModuleMap = Object.create(null);\n\n// TODO: upstream to dom5\nconst styleMatch = pred.AND(\n  pred.hasTagName('style'),\n  pred.OR(\n    pred.NOT(\n      pred.hasAttr('type')\n    ),\n    pred.hasAttrValue('type', 'text/css')\n  )\n);\n\nconst notStyleMatch = pred.NOT(styleMatch);\n\nconst customStyleMatchV1 = pred.AND(\n  styleMatch,\n  pred.hasAttrValue('is', 'custom-style')\n);\n\nconst customStyleMatchV2 = pred.AND(\n  styleMatch,\n  pred.parentMatches(\n    pred.hasTagName('custom-style')\n  )\n);\n\nconst styleIncludeMatch = pred.AND(styleMatch, pred.hasAttr('include'));\n\n/**\n * Map of <style> ast node to element name that defines it\n * @type {!WeakMap<!Object, string>}\n */\nconst scopeMap = new WeakMap();\n\n/**\n * Map of <style> ast node to inline HTML documents from analyzer\n * @type {!WeakMap<!Object, !ParsedHtmlDocument>}\n */\nconst inlineHTMLDocumentMap = new WeakMap();\n\nfunction prepend(parent, node) {\n  if (parent.childNodes.length > 0) {\n    dom5.insertBefore(parent, parent.childNodes[0], node);\n  } else {\n    dom5.append(parent, node);\n  }\n}\n\n/*\n * Collect styles from dom-module\n * In addition, make sure those styles are inside a template\n */\nfunction getAndFixDomModuleStyles(domModule) {\n  // TODO: support `.styleModules = ['module-id', ...]` ?\n  const styles = getStyles(domModule);\n  if (!styles.length) {\n    return [];\n  }\n  let template = dom5.query(domModule, pred.hasTagName('template'));\n  if (!template) {\n    template = dom5.constructors.element('template');\n    const content = dom5.constructors.fragment();\n    styles.forEach(s => dom5.append(content, s));\n    dom5.append(template, content);\n    dom5.append(domModule, template);\n  } else {\n    styles.forEach((s) => {\n      let templateContent = template.content;\n      // ensure element styles are inside the template element\n      const parent = dom5.nodeWalkAncestors(s, (n) =>\n        n === templateContent || n === domModule\n      );\n      if (parent !== templateContent) {\n        prepend(templateContent, s);\n      }\n    })\n  }\n  return styles;\n}\n\nfunction getStyles(astNode) {\n  return dom5.queryAll(astNode, styleMatch, undefined, dom5.childNodesIncludeTemplate)\n}\n\n// TODO: consider upstreaming to dom5\nfunction getAttributeArray(node, attribute) {\n  const attr = dom5.getAttribute(node, attribute);\n  let array;\n  if (!attr) {\n    array = [];\n  } else {\n    array = attr.split(' ');\n  }\n  return array;\n}\n\nfunction isUnscopedStyle(style) {\n  return dom5.hasAttribute(style, ShadyUnscopedAttribute);\n}\n\nfunction inlineStyleIncludes(style, useNativeShadow) {\n  if (!styleIncludeMatch(style)) {\n    return;\n  }\n  const styleText = [];\n  const includes = getAttributeArray(style, 'include');\n  const leftover = [];\n  const baseDocument = style.__ownerDocument;\n  includes.forEach((id) => {\n    const domModule = domModuleMap[id];\n    if (!domModule) {\n      // we missed this one, put it back on later\n      leftover.push(id);\n      return;\n    }\n    const includedStyles = getAndFixDomModuleStyles(domModule);\n    // gather included styles\n    includedStyles.forEach((ism) => {\n      // do not inline styles that need to be unscoped in ShadyDOM\n      if (!useNativeShadow && isUnscopedStyle(ism)) {\n        leftover.push(id);\n        return;\n      }\n      // this style may also have includes\n      inlineStyleIncludes(ism);\n      const inlineDocument = domModule.__ownerDocument;\n      let includeText = dom5.getTextContent(ism);\n      // adjust paths\n      includeText = pathResolver.rewriteURL(inlineDocument, baseDocument, includeText);\n      styleText.push(includeText);\n    });\n  });\n  // remove inlined includes\n  if (leftover.length) {\n    dom5.setAttribute(style, 'include', leftover.join(' '));\n  } else {\n    dom5.removeAttribute(style, 'include');\n  }\n  // prepend included styles\n  if (styleText.length) {\n    let text = dom5.getTextContent(style);\n    text = styleText.join('') + text;\n    dom5.setTextContent(style, text);\n  }\n}\n\nfunction applyShim(ast) {\n  /*\n   * `transform` expects an array of decorated <style> elements\n   *\n   * Decorated <style> elements are ones with `__cssRules` property\n   * with a value of the CSS ast\n   */\n  StyleUtil.forEachRule(ast, (rule) => ApplyShim.transformRule(rule));\n}\n\nfunction getModuleDefinition(moduleName, elementDescriptors) {\n  for (let ed of elementDescriptors) {\n    if (ed.tagName && ed.tagName.toLowerCase() === moduleName) {\n      return ed;\n    }\n  }\n  return null;\n}\n\nfunction shadyShim(ast, style, analysis) {\n  const scope = scopeMap.get(style);\n  const moduleDefinition = getModuleDefinition(scope, analysis.getFeatures({kind: 'element'}));\n  // only shim if module is a full polymer element, not just a style module\n  if (!scope || !moduleDefinition) {\n    return;\n  }\n  const ext = moduleDefinition.extends;\n  StyleTransformer.css(ast, scope, ext);\n}\n\nfunction addClass(node, className) {\n  const classList = getAttributeArray(node, 'class');\n  if (classList.indexOf('style-scope') === -1) {\n    classList.push('style-scope');\n  }\n  if (classList.indexOf(className) === -1) {\n    classList.push(className);\n  }\n  dom5.setAttribute(node, 'class', classList.join(' '));\n}\n\nfunction markElement(element, useNativeShadow) {\n  dom5.setAttribute(element, 'css-build', useNativeShadow ? 'shadow' : 'shady');\n}\n\nfunction markDomModule(domModule, scope, useNativeShadow, markTemplate = true) {\n  // apply scoping to dom-module\n  markElement(domModule, useNativeShadow);\n  // apply scoping to template\n  const template = dom5.query(domModule, pred.hasTagName('template'));\n  if (template) {\n    if (markTemplate) {\n      markElement(template, useNativeShadow);\n    }\n    // mark elements' subtree under shady build\n    if (!useNativeShadow && scope) {\n      shadyScopeElementsInTemplate(template, scope);\n    }\n  }\n}\n\nfunction shadyScopeElementsInTemplate(template, scope) {\n  const elements = dom5.queryAll(template, notStyleMatch, undefined, dom5.childNodesIncludeTemplate);\n  elements.forEach((el) => addClass(el, scope));\n}\n\n// For forward compatibility with ShadowDOM v1 and Polymer 2.x,\n// replace ::slotted(${inner}) with ::content > ${inner}\nfunction slottedTransform(ast) {\n  StyleUtil.forEachRule(ast, (rule) => {\n    rule.selector = slottedToContent(rule.selector);\n  });\n}\n\nfunction dirTransform(ast, polymerVersion) {\n  StyleUtil.forEachRule(ast, (rule) => {\n    if (polymerVersion === 1) {\n      rule.selector = dirShadowTransform(rule.selector);\n    } else {\n      rule.selector = polymer2DirShadowTransform(rule.selector);\n    }\n  });\n}\n\nfunction contentTransform(ast, scope) {\n  StyleUtil.forEachRule(ast, (rule) => {\n    rule.selector = shadyReplaceContent(rule.selector, scope);\n  });\n}\n\nfunction setUpLibraries(useNativeShadow) {\n  ({\n    ApplyShim,\n    CssParse,\n    StyleTransformer,\n    StyleUtil,\n    ShadyUnscopedAttribute\n  } = loadShadyCSS(useNativeShadow));\n}\n\nfunction setNodeFileLocation(node, analysisKind) {\n  if (!node.__ownerDocument) {\n    node.__ownerDocument = analysisKind.sourceRange.file;\n  }\n}\n\n/**\n *\n * @param {Analysis} analysis\n * @param {Function} query\n * @param {Function=} queryOptions\n * @return {Array}\n */\nfunction nodeWalkAllDocuments(analysis, query, queryOptions = undefined) {\n  const results = [];\n  for (const document of analysis.getFeatures({kind: 'html-document'})) {\n    const matches = dom5.nodeWalkAll(document.parsedDocument.ast, query, undefined, queryOptions);\n    matches.forEach((match) => {\n      setNodeFileLocation(match, document);\n      results.push(match)\n    });\n  }\n  return results;\n}\n\n/**\n * Handle the difference between analyzer 2 and 3 Analyzer::getDocument\n * @param {!Analysis} analysis\n * @param {string} url\n * @return {!Document}\n */\nfunction getDocument(analysis, url) {\n  const res = analysis.getDocument(url);\n  if (res.error) {\n    throw res.error;\n  }\n  return res.value;\n}\n\nfunction getAstNode(feature) {\n  let astNode = feature.astNode;\n  if (astNode.node) {\n    return astNode.node;\n  } else {\n    return astNode;\n  }\n}\n\nfunction getContainingDocument(feature, analysis) {\n  return feature.astNode.containingDocument ||\n    analysis.getDocumentContaining(feature.sourceRange).parsedDocument;\n}\n\nfunction getOrderedPolymerElements(analysis) {\n  const polymerElements = new Set();\n  for (const document of analysis.getFeatures({kind: 'document'})) {\n    for (const element of document.getFeatures({kind: 'polymer-element'})) {\n      polymerElements.add(element);\n    }\n  }\n  return Array.from(polymerElements);\n}\n\nfunction updateInlineDocument(inlineDocument) {\n  if (!inlineDocument || !inlineDocument.isInline) {\n    return;\n  }\n  // this is a hack and bad\n  // get the containing JavascriptDocument for the inline document\n  const jsNode = getAstNode(inlineDocument);\n  let node = jsNode;\n  /* eslint-disable no-fallthrough */\n  switch(jsNode.type) {\n    case 'TaggedTemplateExpression':\n      // Get the to the node representing the inside of the TemplateLiteral\n      node = node.quasi;\n    case 'TemplateLiteral':\n      // set the value of the TemplateLiteral interior to the stringified document\n      // the AST has both \"cooked\" and \"raw\" versions of the string, but they should be the same in practice\n      node = node.quasis[0];\n      node.value = {\n        cooked: inlineDocument.stringify(),\n        raw: inlineDocument.stringify()\n      };\n      break;\n    case 'ArrayExpression':\n      // get to the node representing the closurified output of html``\n      node = node.elements[0];\n    case 'StringLiteral':\n      // set the value of the array element to the stringified document\n      node.value = inlineDocument.stringify();\n      break;\n  }\n  /* eslint-enable */\n}\n\nfunction searchAst(polymerElement, templateDocument, analysis) {\n  const polymerElementNode = getAstNode(polymerElement, analysis);\n  const templateNode = getAstNode(templateDocument, analysis);\n  let match = false;\n  // Note: in visitor, return 'skip' to skip subtree, and 'break' to exit early\n  const visitor = {\n    enterCallExpression(current) {\n      const args = current.arguments;\n      if (args.length !== 1) {\n        return 'skip';\n      }\n      const [arg, ] = args;\n      if (arg.type !== 'Identifier') {\n        return 'skip';\n      }\n      if (IdentifierIsDocumentVariable(arg, templateNode)) {\n        match = templateNode;\n        return 'break';\n      }\n    },\n    enterObjectProperty(current, _parent, path) {\n      if (path.parentPath.parent !== polymerElementNode) {\n        return 'skip';\n      }\n      // this is a Polymer({}) call with `_template`\n      const keyName = current.key.name;\n      if (keyName === '_template' || keyName === 'template') {\n        match = current.value === templateNode;\n        if (match) {\n          return 'break';\n        }\n      }\n    },\n    enterClassMethod(current) {\n      // this is a class element with `static get template() {}`\n      if (!current.static || current.kind !== 'get' || current.key.name !== 'template') {\n        return 'skip';\n      }\n    },\n    enterTaggedTemplateExpression(current) {\n      match = current === templateNode;\n      if (match) {\n        return 'break';\n      }\n    }\n  };\n  // walk the AST from the `Polymer({})` or `class {}` definition\n  traverse(polymerElementNode, visitor);\n  return match;\n}\n\nfunction getInlinedTemplateDocument(polymerElement, analysis) {\n  // lookup from cache\n  if (inlineHTMLDocumentMap.has(polymerElement)) {\n    return inlineHTMLDocumentMap.get(polymerElement);\n  }\n  // find InlinedHTMLDocuments inside of the \"parsed\" js document containing this PolymerElement\n  const jsDocument = getContainingDocument(polymerElement, analysis);\n  const parsedJsDocument = getDocument(analysis, jsDocument.url);\n  const inlineHTMLDocumentSet = parsedJsDocument.getFeatures({kind: 'html-document'});\n  let inlinedDocument = null;\n  // search all inlined html-documents in this js document for the one that is\n  // inside the class definition for this polymer element scanning the AST\n  for (const htmlDocument of inlineHTMLDocumentSet) {\n    if (searchAst(polymerElement, htmlDocument, analysis)) {\n      inlinedDocument = htmlDocument;\n      break;\n    }\n  }\n  if (!inlinedDocument) {\n    return null;\n  }\n  // cache template lookup\n  inlineHTMLDocumentMap.set(polymerElement, inlinedDocument.parsedDocument);\n  return inlinedDocument.parsedDocument;\n}\n\nfunction getInlinedStyles(polymerElement, analysis) {\n  const document = getInlinedTemplateDocument(polymerElement, analysis);\n  if (!document) {\n    return [];\n  }\n  return getStyles(document.ast);\n}\n\nfunction findDisconnectedDomModule(polymerElement, analysis) {\n  // search analysis for a dom-module with the same id as the polymerElement's\n  const [domModuleFeature, ] = analysis.getFeatures({kind: 'dom-module', id: polymerElement.tagName});\n  if (domModuleFeature) {\n    // polymerElement.domModule is assumed to the the HTML node\n    const domModuleNode = getAstNode(domModuleFeature);\n    polymerElement.domModule = domModuleNode;\n  }\n}\n\nfunction markPolymerElement(polymerElement, useNativeShadow, analysis) {\n  const document = getInlinedTemplateDocument(polymerElement, analysis);\n  if (!document) {\n    return;\n  }\n  const template = document.ast;\n  // add a comment of the form `<!--css-build:shadow-->` to the template as the first child\n  const buildComment = dom5.constructors.comment(`css-build:${useNativeShadow ? 'shadow' : 'shady'}`);\n  prepend(template, buildComment);\n  if (!useNativeShadow) {\n    shadyScopeElementsInTemplate(template, polymerElement.tagName);\n  }\n}\n\nfunction buildInlineDocumentSet(analysis) {\n  const inlineHTMLDocumentSet = new Set();\n\n  for (const doc of analysis.getFeatures({kind: 'html-document', externalPackages: true})) {\n    if (doc.isInline) {\n      inlineHTMLDocumentSet.add(doc);\n    }\n  }\n\n  return inlineHTMLDocumentSet;\n}\n\nasync function polymerCssBuild(paths, options = {}) {\n  const nativeShadow = options ? !options['build-for-shady'] : true;\n  const polymerVersion = options['polymer-version'] || 2;\n  const customStyleMatch = polymerVersion === 2 ? customStyleMatchV2 : customStyleMatchV1;\n  setUpLibraries(nativeShadow);\n  // build analyzer loader\n  const loader = new InMemoryOverlayUrlLoader();\n  const analyzer = new Analyzer({\n    urlLoader: loader,\n    parsers: createParserMap(),\n    scanners: createScannerMap(polymerVersion === 2)\n  });\n  // load given files as strings\n  paths.forEach((p) => {\n    loader.urlContentsMap.set(analyzer.resolveUrl(p.url), p.content);\n  });\n  // run analyzer on all given files\n  /** @type {Analysis} */\n  const analysis = await analyzer.analyze(paths.map((p) => p.url));\n  // populate the dom module map\n  const domModuleSet = analysis.getFeatures({kind: 'dom-module'})\n  for (const domModule of domModuleSet) {\n    const scope = domModule.id.toLowerCase();\n    const astNode = getAstNode(domModule);\n    domModuleMap[scope] = astNode;\n    setNodeFileLocation(astNode, domModule);\n  }\n  // grap a set of all inline html documents to update at the end\n  const inlineHTMLDocumentSet = buildInlineDocumentSet(analysis);\n  // map polymer elements to styles\n  const moduleStyles = [];\n  for (const polymerElement of getOrderedPolymerElements(analysis)) {\n    const scope = polymerElement.tagName;\n    let styles = [];\n    if (!polymerElement.domModule) {\n      // there can be cases where a polymerElement is defined in a way that\n      // analyzer can't get associate it with the <dom-module>, so try to find\n      // it before assuming the polymerElement has an inline template\n      findDisconnectedDomModule(polymerElement, analysis);\n    }\n    if (polymerElement.domModule) {\n      const domModule = polymerElement.domModule;\n      markDomModule(domModule, scope, nativeShadow, polymerVersion > 1);\n      styles = getAndFixDomModuleStyles(domModule);\n    } else {\n      markPolymerElement(polymerElement, nativeShadow, analysis);\n      styles = getInlinedStyles(polymerElement, analysis);\n    }\n    styles.forEach((s) => {\n      scopeMap.set(s, scope);\n      setNodeFileLocation(s, polymerElement);\n    });\n    moduleStyles.push(styles);\n  }\n  // also process dom modules used only for style sharing\n  for (const domModule of domModuleSet) {\n    const {id} = domModule;\n    const domModuleIsElementTemplate = analysis.getFeatures({kind: 'polymer-element', id}).size > 0;\n    if (!domModuleIsElementTemplate) {\n      const styles = getAndFixDomModuleStyles(domModuleMap[id]);\n      styles.forEach((s) => {\n        scopeMap.set(s, id);\n        setNodeFileLocation(s, domModule);\n      });\n      moduleStyles.push(styles);\n    }\n  }\n  // inline and flatten styles into a single list\n  const flatStyles = [];\n  moduleStyles.forEach((styles) => {\n    if (!styles.length) {\n      return;\n    }\n    // do style includes\n    if (options ? !options['no-inline-includes'] : true) {\n      styles.forEach((s) => inlineStyleIncludes(s, nativeShadow));\n    }\n    // reduce styles to one\n    const finalStyle = styles[styles.length - 1];\n    dom5.setAttribute(finalStyle, 'scope', scopeMap.get(finalStyle));\n    if (styles.length > 1) {\n      const consumed = styles.slice(0, -1);\n      const text = styles.map((s) => dom5.getTextContent(s));\n      const includes = styles.map((s) => getAttributeArray(s, 'include')).reduce((acc, inc) => acc.concat(inc));\n      consumed.forEach((c) => dom5.remove(c));\n      dom5.setTextContent(finalStyle, text.join(''));\n      const oldInclude = getAttributeArray(finalStyle, 'include');\n      const newInclude = Array.from(new Set(oldInclude.concat(includes))).join(' ');\n      if (newInclude) {\n        dom5.setAttribute(finalStyle, 'include', newInclude);\n      }\n    }\n    flatStyles.push(finalStyle);\n  });\n  // find custom styles\n  const customStyles = nodeWalkAllDocuments(analysis, customStyleMatch);\n  // inline custom styles with includes\n  if (options ? !options['no-inline-includes'] : true) {\n    customStyles.forEach((s) => inlineStyleIncludes(s, nativeShadow));\n  }\n  // add custom styles to the front\n  // custom styles may define mixins for the whole tree\n  flatStyles.unshift(...customStyles);\n  // fix old `var(--a, --b)` syntax in polymer v1 builds\n  if (polymerVersion === 1) {\n    flatStyles.forEach((s) => {\n      const text = dom5.getTextContent(s);\n      const ast = CssParse.parse(text);\n      StyleUtil.forEachRule(ast, (rule) => {\n        fixBadVars(rule);\n      });\n      dom5.setTextContent(s, CssParse.stringify(ast, true));\n    });\n  }\n  // populate mixin map\n  flatStyles.forEach((s) => {\n    const text = dom5.getTextContent(s);\n    const ast = CssParse.parse(text);\n    applyShim(ast);\n  });\n  // parse, transform, emit\n  flatStyles.forEach((s) => {\n    let text = dom5.getTextContent(s);\n    const ast = CssParse.parse(text);\n    if (customStyleMatch(s)) {\n      // custom-style `:root` selectors need to be processed to `html`\n      StyleUtil.forEachRule(ast, (rule) => {\n        if (options && options['build-for-shady']) {\n          StyleTransformer.documentRule(rule);\n        } else {\n          StyleTransformer.normalizeRootSelector(rule);\n        }\n      });\n      // mark the style as built\n      markElement(s, nativeShadow);\n    }\n    applyShim(ast);\n    if (nativeShadow) {\n      dirTransform(ast, polymerVersion);\n      if (polymerVersion === 1) {\n        slottedTransform(ast);\n      }\n    } else {\n      shadyShim(ast, s, analysis);\n      if (polymerVersion === 1) {\n        contentTransform(ast, scopeMap.get(s));\n      }\n    }\n    text = CssParse.stringify(ast, true);\n    dom5.setTextContent(s, text);\n  });\n  // update inline HTML documents\n  for (const inlineDocument of inlineHTMLDocumentSet) {\n    updateInlineDocument(inlineDocument);\n  }\n  return paths.map((p) => {\n    const doc = getDocument(analysis, p.url);\n    return {\n      url: p.url,\n      content: doc.stringify()\n    };\n  });\n}\n\nexports.polymerCssBuild = polymerCssBuild;\n"]}