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AS,EAAG,KAAG,CAAC;AACnD;AAAA,AAzIA,KAAK,eAAe,AAAC,kCACb,EAAC,GAAE,CAAG,UAAS,AAAD,CAAG;AAAC,YAD1B,eAAc,KAAO,UAC4B;EAAC,CAAC,CAAC,CAAC;AA2IrD,OAAS,iBAAe,CAAE,GAAE,AAAQ,CAAG,CAAA,KAAI,AAAQ,CAAW;AAC5D,OAAO,CAAA,CAAC,OAAM,AAAC,CAAC,KAAI,CAAC,CAAC,EAAI,IAAE,IAAI,SAAS,EAAC,MAAI,EAAC,OAAM,EAAC,IAAE,EAAC,MAAI,CAAA,CAAC;AAChE;AAAA,AA9IA,KAAK,eAAe,AAAC,gCACb,EAAC,GAAE,CAAG,UAAS,AAAD,CAAG;AAAC,YAD1B,eAAc,KAAO,WAArB,eAAc,KAAO,UAC4B;EAAC,CAAC,CAAC,CAAC;AA+IrD,AAAI,EAAA,CAAA,SAAQ,EAAI,CAAA,aAAY,OAAO,AAAC,CAAC,qBAAoB,CAAC,CAAC;AAC3D,AAAI,EAAA,CAAA,MAAK,EAAI,CAAA,aAAY,OAAO,AAAC,CAC/B,oCAAmC,EACnC,uBAAqB,CACvB,CAAC;AACD,AAAI,EAAA,CAAA,aAAY,EAAI,CAAA,aAAY,OAAO,AAAC,CAAC,mCAAkC,CAAC,CAAC;AAC7E","file":"angular2/src/render/dom/shadow_dom/style_inliner.js","sourcesContent":["import {Injectable} from 'angular2/src/di/annotations_impl';\nimport {XHR} from 'angular2/src/services/xhr';\nimport {ListWrapper} from 'angular2/src/facade/collection';\n\nimport {UrlResolver} from 'angular2/src/services/url_resolver';\nimport {StyleUrlResolver} from './style_url_resolver';\n\nimport {\n  isBlank,\n  isPresent,\n  RegExp,\n  RegExpWrapper,\n  StringWrapper,\n  normalizeBlank,\n} from 'angular2/src/facade/lang';\nimport {\n  Promise,\n  PromiseWrapper,\n} from 'angular2/src/facade/async';\n\n/**\n * Inline @import rules in the given CSS.\n *\n * When an @import rules is inlined, it's url are rewritten.\n */\n@Injectable()\nexport class StyleInliner {\n  _xhr: XHR;\n  _urlResolver: UrlResolver;\n  _styleUrlResolver: StyleUrlResolver;\n\n  constructor(xhr: XHR, styleUrlResolver: StyleUrlResolver, urlResolver: UrlResolver) {\n    this._xhr = xhr;\n    this._urlResolver = urlResolver;\n    this._styleUrlResolver = styleUrlResolver;\n  }\n\n  /**\n   * Inline the @imports rules in the given CSS text.\n   *\n   * The baseUrl is required to rewrite URLs in the inlined content.\n   *\n   * @param {string} cssText\n   * @param {string} baseUrl\n   * @returns {*} a Promise<string> when @import rules are present, a string otherwise\n   */\n  // TODO(vicb): Union types: returns either a Promise<string> or a string\n  // TODO(vicb): commented out @import rules should not be inlined\n  inlineImports(cssText: string, baseUrl: string) {\n    return this._inlineImports(cssText, baseUrl, []);\n  }\n\n  _inlineImports(cssText: string, baseUrl: string, inlinedUrls: List<string>) {\n    var partIndex = 0;\n    var parts = StringWrapper.split(cssText, _importRe);\n\n    if (parts.length === 1) {\n      // no @import rule found, return the original css\n      return cssText;\n    }\n\n    var promises = [];\n\n    while (partIndex < parts.length - 1) {\n      // prefix is the content before the @import rule\n      var prefix = parts[partIndex];\n      // rule is the parameter of the @import rule\n      var rule = parts[partIndex + 1];\n      var url = _extractUrl(rule);\n      if (isPresent(url)) {\n        url = this._urlResolver.resolve(baseUrl, url);\n      }\n      var mediaQuery = _extractMediaQuery(rule);\n      var promise;\n\n      if (isBlank(url)) {\n        promise = PromiseWrapper.resolve(`/* Invalid import rule: \"@import ${rule};\" */`);\n      } else if (ListWrapper.contains(inlinedUrls, url)) {\n        // The current import rule has already been inlined, return the prefix only\n        // Importing again might cause a circular dependency\n        promise = PromiseWrapper.resolve(prefix);\n      } else {\n        ListWrapper.push(inlinedUrls, url);\n        promise = PromiseWrapper.then(\n          this._xhr.get(url),\n          (css) => {\n            // resolve nested @import rules\n            css = this._inlineImports(css, url, inlinedUrls);\n            if (PromiseWrapper.isPromise(css)) {\n              // wait until nested @import are inlined\n              return css.then((css) => {\n                return prefix + this._transformImportedCss(css, mediaQuery, url) + '\\n'\n              }) ;\n            } else {\n              // there are no nested @import, return the css\n              return prefix + this._transformImportedCss(css, mediaQuery, url) + '\\n';\n            }\n          },\n          (error) => `/* failed to import ${url} */\\n`\n        );\n      }\n      ListWrapper.push(promises, promise);\n      partIndex += 2;\n    }\n\n    return PromiseWrapper.all(promises).then(function (cssParts) {\n      var cssText = cssParts.join('');\n      if (partIndex < parts.length) {\n        // append then content located after the last @import rule\n        cssText += parts[partIndex];\n      }\n      return cssText;\n    });\n  }\n\n  _transformImportedCss(css: string, mediaQuery: string, url: string): string {\n    css = this._styleUrlResolver.resolveUrls(css, url);\n    return _wrapInMediaRule(css, mediaQuery);\n  }\n}\n\n// Extracts the url from an import rule, supported formats:\n// - 'url' / \"url\",\n// - url(url) / url('url') / url(\"url\")\nfunction _extractUrl(importRule: string): string {\n  var match = RegExpWrapper.firstMatch(_urlRe, importRule);\n  if (isBlank(match)) return null;\n  return isPresent(match[1]) ? match[1] : match[2];\n}\n\n// Extracts the media query from an import rule.\n// Returns null when there is no media query.\nfunction _extractMediaQuery(importRule: string): string {\n  var match = RegExpWrapper.firstMatch(_mediaQueryRe, importRule);\n  if (isBlank(match)) return null;\n  var mediaQuery = match[1].trim();\n  return (mediaQuery.length > 0) ? mediaQuery: null;\n}\n\n// Wraps the css in a media rule when the media query is not null\nfunction _wrapInMediaRule(css: string, query: string): string {\n  return (isBlank(query)) ? css : `@media ${query} {\\n${css}\\n}`;\n}\n\nvar _importRe = RegExpWrapper.create('@import\\\\s+([^;]+);');\nvar _urlRe = RegExpWrapper.create(\n  'url\\\\(\\\\s*?[\\'\"]?([^\\'\")]+)[\\'\"]?|' + // url(url) or url('url') or url(\"url\")\n  '[\\'\"]([^\\'\")]+)[\\'\"]'                 // \"url\" or 'url'\n);\nvar _mediaQueryRe = RegExpWrapper.create('[\\'\"][^\\'\"]+[\\'\"]\\\\s*\\\\)?\\\\s*(.*)');\n"]}