function inlineStylesheet(analyzer, document, cssLink, docBundle, excludes, rewriteUrlsInTemplates) {
    return __awaiter(this, void 0, void 0, function* () {
        const stylesheetUrl = dom5.getAttribute(cssLink, 'href');
        const importUrl = urlLib.resolve(document.url, stylesheetUrl);
        if (!analyzer.canResolveUrl(importUrl)) {
            return;
        }
        const resolvedImportUrl = analyzer.resolveUrl(importUrl);
        if (excludes &&
            excludes.some((e) => resolvedImportUrl === e ||
                resolvedImportUrl.startsWith(urlUtils.ensureTrailingSlash(e)))) {
            return;
        }
        const stylesheetImport = findInSet(document.getFeatures({ kind: 'html-style', imported: true, externalPackages: true }), (i) => i.document && i.document.url === resolvedImportUrl) ||
            findInSet(document.getFeatures({ kind: 'css-import', imported: true, externalPackages: true }), (i) => i.document && i.document.url === resolvedImportUrl);
        if (!stylesheetImport) {
            docBundle.bundle.missingImports.add(resolvedImportUrl);
            return;
        }
        const stylesheetContent = stylesheetImport.document.parsedDocument.contents;
        const media = dom5.getAttribute(cssLink, 'media');
        let newBaseUrl = document.url;
        // If the css link we are about to inline is inside of a dom-module, the new
        // base url must be calculated using the assetpath of the dom-module if
        // present, since Polymer will honor assetpath when resolving urls in
        // `<style>` tags, even inside of `<template>` tags.
        const parentDomModule = findAncestor(cssLink, dom5.predicates.hasTagName('dom-module'));
        if (!rewriteUrlsInTemplates && parentDomModule &&
            dom5.hasAttribute(parentDomModule, 'assetpath')) {
            const assetPath = dom5.getAttribute(parentDomModule, 'assetpath') || '';
            if (assetPath) {
                newBaseUrl = urlLib.resolve(newBaseUrl, assetPath);
            }
        }
        const resolvedStylesheetContent = rewriteCssTextBaseUrl(stylesheetContent, resolvedImportUrl, newBaseUrl);
        const styleNode = dom5.constructors.element('style');
        if (media) {
            dom5.setAttribute(styleNode, 'media', media);
        }
        dom5.replace(cssLink, styleNode);
        dom5.setTextContent(styleNode, resolvedStylesheetContent);
        // Record that the inlining took place.
        docBundle.bundle.inlinedStyles.add(resolvedImportUrl);
        return styleNode;
    });
}
/**
 * Inlines the contents of the stylesheet returned by the link tag's href url
 * into a style tag and removes the link tag.
 */
Inlines the contents of the stylesheet returned by the link tag's href url
into a style tag and removes the link tag.
Inlines the contents of the stylesheet returned by the link tag ' s href url into a style tag and removes the link tag .
function inlineStylesheet(analyzer, document, cssLink, docBundle, excludes, rewriteUrlsInTemplates) {
    return __awaiter(this, void 0, void 0, function* () {
        const stylesheetUrl = dom5.getAttribute(cssLink, 'href');
        const importUrl = urlLib.resolve(document.url, stylesheetUrl);
        if (!analyzer.canResolveUrl(importUrl)) {
            return;
        }
        const resolvedImportUrl = analyzer.resolveUrl(importUrl);
        if (excludes &&
            excludes.some((e) => resolvedImportUrl === e ||
                resolvedImportUrl.startsWith(urlUtils.ensureTrailingSlash(e)))) {
            return;
        }
        const stylesheetImport = findInSet(document.getFeatures({ kind: 'html-style', imported: true, externalPackages: true }), (i) => i.document && i.document.url === resolvedImportUrl) ||
            findInSet(document.getFeatures({ kind: 'css-import', imported: true, externalPackages: true }), (i) => i.document && i.document.url === resolvedImportUrl);
        if (!stylesheetImport) {
            docBundle.bundle.missingImports.add(resolvedImportUrl);
            return;
        }
        const stylesheetContent = stylesheetImport.document.parsedDocument.contents;
        const media = dom5.getAttribute(cssLink, 'media');
        let newBaseUrl = document.url;
        const parentDomModule = findAncestor(cssLink, dom5.predicates.hasTagName('dom-module'));
        if (!rewriteUrlsInTemplates && parentDomModule &&
            dom5.hasAttribute(parentDomModule, 'assetpath')) {
            const assetPath = dom5.getAttribute(parentDomModule, 'assetpath') || '';
            if (assetPath) {
                newBaseUrl = urlLib.resolve(newBaseUrl, assetPath);
            }
        }
        const resolvedStylesheetContent = rewriteCssTextBaseUrl(stylesheetContent, resolvedImportUrl, newBaseUrl);
        const styleNode = dom5.constructors.element('style');
        if (media) {
            dom5.setAttribute(styleNode, 'media', media);
        }
        dom5.replace(cssLink, styleNode);
        dom5.setTextContent(styleNode, resolvedStylesheetContent);
        docBundle.bundle.inlinedStyles.add(resolvedImportUrl);
        return styleNode;
    });
}
function inlineStylesheet ( analyzer , document , cssLink , docBundle , excludes , rewriteUrlsInTemplates ) { return __awaiter ( this , void 0 , void 0 , function * ( ) { const stylesheetUrl = dom5 . getAttribute ( cssLink , 'href' ) ; const importUrl = urlLib . resolve ( document . url , stylesheetUrl ) ; if ( ! analyzer . canResolveUrl ( importUrl ) ) { return ; } const resolvedImportUrl = analyzer . resolveUrl ( importUrl ) ; if ( excludes && excludes . some ( ( e ) => resolvedImportUrl === e || resolvedImportUrl . startsWith ( urlUtils . ensureTrailingSlash ( e ) ) ) ) { return ; } const stylesheetImport = findInSet ( document . getFeatures ( { kind : 'html-style' , imported : true , externalPackages : true } ) , ( i ) => i . document && i . document . url === resolvedImportUrl ) || findInSet ( document . getFeatures ( { kind : 'css-import' , imported : true , externalPackages : true } ) , ( i ) => i . document && i . document . url === resolvedImportUrl ) ; if ( ! stylesheetImport ) { docBundle . bundle . missingImports . add ( resolvedImportUrl ) ; return ; } const stylesheetContent = stylesheetImport . document . parsedDocument . contents ; const media = dom5 . getAttribute ( cssLink , 'media' ) ; let newBaseUrl = document . url ; const parentDomModule = findAncestor ( cssLink , dom5 . predicates . hasTagName ( 'dom-module' ) ) ; if ( ! rewriteUrlsInTemplates && parentDomModule && dom5 . hasAttribute ( parentDomModule , 'assetpath' ) ) { const assetPath = dom5 . getAttribute ( parentDomModule , 'assetpath' ) || '' ; if ( assetPath ) { newBaseUrl = urlLib . resolve ( newBaseUrl , assetPath ) ; } } const resolvedStylesheetContent = rewriteCssTextBaseUrl ( stylesheetContent , resolvedImportUrl , newBaseUrl ) ; const styleNode = dom5 . constructors . element ( 'style' ) ; if ( media ) { dom5 . setAttribute ( styleNode , 'media' , media ) ; } dom5 . replace ( cssLink , styleNode ) ; dom5 . setTextContent ( styleNode , resolvedStylesheetContent ) ; docBundle . bundle . inlinedStyles . add ( resolvedImportUrl ) ; return styleNode ; } ) ; }
Inlines the contents of the stylesheet returned by the link tag's href url
 into a style tag and removes the link tag.
Inlines the contents of the stylesheet returned by the link tag ' s href url into a style tag and removes the link tag .
// If the css link we are about to inline is inside of a dom-module, the new // base url must be calculated using the assetpath of the dom-module if // present, since Polymer will honor assetpath when resolving urls in // `<style>` tags, even inside of `<template>` tags. // Record that the inlining took place.