diff --git a/README.md b/README.md
index a05afb6..3b83368 100644
--- a/README.md
+++ b/README.md
@@ -10,37 +10,36 @@ Extract critical CSS path for the current viewport in the current page.
Using modules
```html
-
```
Without using modules
```html
-
-
-
+
+
```
@@ -75,7 +74,8 @@ urls.forEach(async url => critical(url, {
screenshot: true,
secure: false,
// dimensions can be specified as an array of string or object
- dimensions: ['1400x900', '1200x675', '992x558']
+ dimensions: ['1400x900', '1200x675', '992x558'],
+ advanced: true
}).then((results) => {
// print extracted CSS
@@ -111,6 +111,7 @@ urls.forEach(async url => critical(url, {
- output: _string_. change output directory. default _'./output/'_
- fonts: _bool_. generate javascript to load web fonts. default _true_
- json: _bool_. dump result as JSON
+ - advanced: _bool_. remove parts of css selectors that do not match any element. default _false_
> debugging settings
- console: _bool_. log console messages from the pages. default _true_
- verbose: _bool_. enable verbose mode
@@ -161,6 +162,8 @@ Options:
-p, --html Generate an HTML page containing inlined critical css
[boolean]
--json print result in JSON format [boolean] [default: false]
+ -e, --advanced remove parts of css selectors that do not match any elem
+ ent [boolean] [default: false]
-v, --verbose Enable verbose mode [boolean] [default: false]
@@ -185,6 +188,7 @@ $ cat pages/dashboard.html | critical-cli --base=pages/ --secure=no -i -d '1440x
### V1.1.0
- read data from STDIN
+- remove unused selectors
- dump cli result as JSON
### V1.0.1
diff --git a/bin/args.json b/bin/args.json
index 850d36c..0fa8bd9 100644
--- a/bin/args.json
+++ b/bin/args.json
@@ -128,7 +128,14 @@
"description": "print result in JSON format",
"type": "boolean",
"default": false
- } ,
+ },
+ "advanced": {
+ "alias": "e",
+ "demandOption": false,
+ "description": "remove parts of css selectors that do not match any element",
+ "type": "boolean",
+ "default": false
+ },
"verbose": {
"alias": "v",
"demandOption": false,
diff --git a/bin/critical-cli.js b/bin/critical-cli.js
index 3cf3771..3d5027e 100755
--- a/bin/critical-cli.js
+++ b/bin/critical-cli.js
@@ -11,29 +11,39 @@ const aliases = new Map;
aliases.set('h', 'help');
-for (const [name, command] of Object.entries(cliArgs.args)) {
+try {
- if (aliases.has(command.alias)) {
+ for (const [name, command] of Object.entries(cliArgs.args)) {
- throw new Error(`'${name}': Alias ${command.alias} already in use by ${aliases.get(command.alias)}'`);
+ if (aliases.has(command.alias)) {
+
+ throw new Error(`'${name}': Alias ${command.alias} already in use by ${aliases.get(command.alias)}'`);
+ }
+
+ aliases.set(command.alias, name);
+ aliases.set(name.replace(/-([a-z])/g, (all, one) => one.toUpperCase()), name);
+ _yargs.option(name, command);
}
- aliases.set(command.alias, name);
- aliases.set(name.replace(/-([a-z])/g, (all, one) => one.toUpperCase()), name);
- _yargs.option(name, command);
-}
+ for (const name of Object.keys(_yargs.argv)) {
+
+ if (name === '_' || '$0' === name) {
-for (const name of Object.keys(_yargs.argv)) {
+ continue;
+ }
- if (name === '_' || '$0' === name) {
+ if (!aliases.has(name.replace(/-([a-z])/g, (all, one) => one.toUpperCase()))) {
- continue;
+ throw new Error(`'${name}': Unknown argument`);
+ }
}
+}
- if (!aliases.has(name.replace(/-([a-z])/g, (all, one) => one.toUpperCase()))) {
+catch (error) {
- throw new Error(`'${name}': Unknown argument`);
- }
+ _yargs.showHelp();
+ console.error(error.message);
+ process.exit(1);
}
_yargs.help().alias('help', 'h') /*.strict(true) */;
@@ -52,7 +62,6 @@ for (let key of Object.keys(options)) {
}
}
-
// @ts-ignore
delete options._;
// @ts-ignore
@@ -64,7 +73,6 @@ if (urls.length === 0 && process.stdin.isTTY) {
process.exit();
}
-
if (process.stdin.isTTY == null) {
urls.length = 0;
diff --git a/dist/browser-umd.js b/dist/browser-umd.js
index ad94070..a79ef38 100644
--- a/dist/browser-umd.js
+++ b/dist/browser-umd.js
@@ -216,6 +216,8 @@ var critical = (function (exports) {
}
file = files.get(rule.parentStyleSheet).file;
css = rule.cssText;
+ // @ts-ignore
+ console.error({ sel: rule.selectorText, css });
if (file !== 'inline') {
// resolve url()
css = css.replace(/url\(([^)%\s]*?)\)/g, function (all, one) {
diff --git a/dist/browser-umd.js.map b/dist/browser-umd.js.map
index 834078e..68d3fa3 100644
--- a/dist/browser-umd.js.map
+++ b/dist/browser-umd.js.map
@@ -1 +1 @@
-{"version":3,"file":"browser-umd.js","sources":["../src/file/download.ts","../src/file/path.ts","../src/critical/fontscript.ts","../src/critical/extract.ts","../src/browser.ts"],"sourcesContent":["/**\n *\n * @param {string[]} content\n * @param {string} filename\n * @param {string} mimetype\n * @return {Promise}\n */\nexport async function download(content: Array, filename: string, mimetype: string = 'application/octet-stream; charset=utf-8'): Promise> {\n\n //\n const url: string = URL.createObjectURL(new Blob(content, {type: mimetype}));\n //\n const a: HTMLAnchorElement = document.createElement('a');\n document.body.append(a);\n a.style.display = 'none';\n a.download = filename;\n a.href = url;\n\n //\n a.dispatchEvent(new MouseEvent('click'));\n URL.revokeObjectURL(url);\n\n return content;\n}","\nexport function resolve(path: string, from: string): string {\n\n if (path.match(/^['\"]?data:/)) {\n\n return path;\n }\n\n // @ts-ignore\n const baseURL: URL = new URL(from, window.location);\n const pathURL: URL = new URL(path, baseURL);\n\n if (baseURL.protocol != pathURL.protocol ||\n baseURL.host != pathURL.host ||\n pathURL.host != window.location.host ||\n baseURL.port != pathURL.port ||\n pathURL.port != window.location.port ||\n baseURL.port != pathURL.port ||\n pathURL.protocol != window.location.protocol\n ) {\n\n return pathURL.toString();\n }\n\n return pathURL.pathname + pathURL.search + pathURL.hash;\n}","import type {FontObject} from \"../@types\";\n\nexport function fontscript(fonts: FontObject[]): string {\n\n return '/* font preloader script: ' + fonts.length + ' */\\n\"fonts\" in document && ' + JSON.stringify([...fonts], null, 1) + '.forEach(font => new FontFace(font.fontFamily, font.src, font.properties).load().then(font => document.fonts.add(font)))'\n}","import {resolve} from \"../file\";\nimport {fontscript} from \"./fontscript\";\nimport type {\n CriticalExtractOptions,\n CriticalResult,\n FileMapObject,\n FontObject,\n MatchCSSStyleSheet,\n RuleList\n} from \"../@types\";\n\nexport async function extract(options: CriticalExtractOptions = {}) {\n\n const document: Document = window.document;\n const location: Location = window.location;\n const styles: Set = new Set;\n const excluded = ['all', 'print', ''];\n const allStylesheets: MatchCSSStyleSheet[] = [];\n\n // Get a list of all the elements in the view.\n const height = window.innerHeight;\n const walker = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, {acceptNode: () => NodeFilter.SHOW_ELEMENT});\n\n const fonts: Set = new Set;\n const fontFamilies: Set = new Set;\n const files: Map = new Map;\n const weakMap: WeakMap = new WeakMap;\n const nodeMap: Set = new Set;\n let nodeCount: number = 0;\n let k: number;\n let rule: CSSMediaRule | CSSStyleRule;\n let rules;\n\n performance.mark('filterStylesheets');\n\n for (k = 0; k < document.styleSheets.length; k++) {\n\n // @ts-ignore\n rule = document.styleSheets[k];\n\n if (rule.media.mediaText === 'print' || (rule.media.mediaText !== '' && !window.matchMedia(rule.media.mediaText).matches)) {\n\n continue;\n }\n\n try {\n\n\n // @ts-ignore\n rules = (rule).cssRules ?? (rule).rules;\n\n for (let l = 0; l < rules.length; l++) {\n\n allStylesheets.push({rule: rules[l], match: false})\n }\n\n } catch (e) {\n\n // @ts-ignore\n console.error(JSON.stringify({'message': e.message, stylesheet: rule.href}, null, 1));\n }\n }\n\n performance.measure('filter stylesheets', 'filterStylesheets');\n\n if (allStylesheets.length === 0) {\n\n return {styles: [], fonts: [], stats: {}};\n }\n\n let node;\n let rect;\n let allStylesLength = allStylesheets.length;\n\n performance.mark('nodeWalking');\n\n while ((node = walker.nextNode())) {\n\n if (options && options.signal && options.signal.aborted) {\n\n return Promise.reject('Aborted');\n }\n\n if (['SCRIPT', 'LINK', 'HEAD', 'META', 'TITLE', 'NOSCRIPT'].includes(node.tagName)) {\n\n continue;\n }\n\n nodeCount++;\n rect = node.getBoundingClientRect();\n\n if (rect.top < height) {\n\n nodeMap.add(node);\n }\n }\n\n for (k = 0; k < allStylesLength; k++) {\n\n if (allStylesheets[k].match || weakMap.has(allStylesheets[k].rule)) {\n\n continue;\n }\n\n weakMap.set(allStylesheets[k].rule, 1);\n\n if (allStylesheets[k].rule instanceof CSSStyleRule) {\n\n // @ts-ignore\n let selector = allStylesheets[k].rule.selectorText;\n let match;\n\n // detect pseudo selectors\n if (selector.match(/(^|,|\\s)::?((before)|(after))/)) {\n\n match = true\n } else {\n\n if (selector.match(/::?((before)|(after))/)) {\n\n selector = selector.replace(/::?((before)|(after))\\s*((,)|$)/g, '$5');\n }\n\n try {\n\n match = nodeMap.has(document.querySelector(selector));\n } catch (e) {\n\n // @ts-ignore\n match = nodeMap.has(document.querySelector(allStylesheets[k].rule.selectorText));\n }\n }\n\n if (match) {\n\n allStylesheets[k].match = true;\n\n // @ts-ignore\n if (allStylesheets[k].rule.style.getPropertyValue('font-family')) {\n\n // @ts-ignore\n allStylesheets[k].rule.style.getPropertyValue('font-family').split(/\\s*,\\s*/).forEach(fontFamily => fontFamily !== 'inherit' && fontFamilies.add(fontFamily.replace(/(['\"])([^\\1\\s]+)\\1/, '$2')));\n }\n }\n\n } else if (allStylesheets[k].rule instanceof CSSMediaRule || allStylesheets[k].rule instanceof CSSImportRule || allStylesheets[k].rule instanceof CSSConditionRule) {\n\n // @ts-ignore\n if ((allStylesheets[k].rule instanceof CSSMediaRule || allStylesheets[k].rule instanceof CSSImportRule) && (allStylesheets[k].rule.media.mediaText === 'print' || (allStylesheets[k].rule.media.mediaText !== '' && !window.matchMedia(allStylesheets[k].rule.media.mediaText).matches))) {\n continue;\n }\n\n try {\n\n const rule = allStylesheets[k].rule;\n const rules = [];\n // @ts-ignore\n const sheet = rule instanceof CSSImportRule ? rule.styleSheet.cssRules || rule.styleSheet.rules : rule.cssRules || rule.rules;\n\n for (let l = 0; l < sheet.length; l++) {\n\n if (!weakMap.has(sheet[l])) {\n\n rules.push({rule: sheet[l], match: false})\n }\n }\n\n if (rules.length > 0) {\n\n // @ts-ignore\n allStylesheets.splice.apply(allStylesheets, [k + 1, 0].concat(rules))\n allStylesLength = allStylesheets.length\n }\n } catch (e) {\n\n // @ts-ignore\n console.error(JSON.stringify({'message': e.message, stylesheet: rule.href}, null, 1));\n }\n } else if (allStylesheets[k].rule instanceof CSSFontFaceRule) {\n\n // @ts-ignore\n if (allStylesheets[k].rule.style.getPropertyValue('font-family') && allStylesheets[k].rule.style.getPropertyValue('src')) {\n\n // @ts-ignore\n fonts.add(allStylesheets[k].rule);\n }\n }\n }\n\n performance.measure('node walking', 'nodeWalking');\n\n let css;\n let file = '';\n let inlineCount = -1;\n\n performance.mark('rulesExtraction');\n\n loop1:\n for (let k = 0; k < allStylesLength; k++) {\n\n if (!allStylesheets[k].match) {\n\n continue;\n }\n\n // @ts-ignore\n rule = allStylesheets[k].rule;\n let fileUpdate = false;\n\n // @ts-ignore\n if (!files.has(rule.parentStyleSheet)) {\n\n //\n // @ts-ignore\n files.set(rule.parentStyleSheet, {\n\n // @ts-ignore\n base: (rule.parentStyleSheet.href && rule.parentStyleSheet.href.replace(/[?#].*/, '') || location.pathname).replace(/([^/]+)$/, ''),\n // @ts-ignore\n file: rule.parentStyleSheet.href || `inline style #${++inlineCount}`\n });\n\n fileUpdate = true;\n } else { // @ts-ignore\n if (file != null && file !== files.get(rule.parentStyleSheet).file) {\n\n fileUpdate = true;\n }\n }\n\n if (fileUpdate) {\n\n try {\n\n // @ts-ignore\n console.error('analysing ' + files.get(rule.parentStyleSheet).file);\n // @ts-ignore\n styles.add('/* file: ' + files.get(rule.parentStyleSheet).file + ' */');\n } catch (e) {\n\n // @ts-ignore\n console.error(JSON.stringify(e.message, null, 1));\n console.error(JSON.stringify(rule?.parentStyleSheet?.href, null, 1));\n }\n }\n\n file = (files.get(rule.parentStyleSheet)).file;\n css = rule.cssText;\n\n if (file !== 'inline') {\n\n // resolve url()\n css = css.replace(/url\\(([^)%\\s]*?)\\)/g, function (all, one) {\n\n one = one.trim();\n\n if (one.match(/^['\"]?data:/)) {\n\n return all;\n }\n\n one = one.replace(/^(['\"])([^\\1\\s]+)\\1/, '$2');\n\n // @ts-ignore\n return 'url(' + resolve(one, files.get(rule.parentStyleSheet).base) + ')';\n })\n }\n\n while (rule.parentRule) {\n\n /**\n *\n * @type {CSSMediaRule}\n */\n // @ts-ignore\n rule = rule.parentRule;\n\n // @ts-ignore\n if (rule.conditionText == 'print') {\n\n continue loop1;\n }\n\n // @ts-ignore\n if (!excluded.includes(rule.conditionText)) {\n\n // @ts-ignore\n css = '@' + rule.constructor.name.replace(/^CSS(.*?)Rule/, '$1').toLowerCase() + ' ' + rule.conditionText + ' {' + css + '}';\n }\n\n if (!rule.parentRule) {\n\n break;\n }\n }\n\n if (rule.parentStyleSheet) {\n\n let media = rule.parentStyleSheet.media.mediaText;\n\n if (media === 'print') {\n\n continue;\n }\n\n if (media !== '') {\n\n css = '@media ' + media + ' {' + css + '}';\n }\n }\n\n if (styles.has(css)) {\n\n styles.delete(css);\n }\n\n styles.add(css);\n }\n\n performance.measure('rules extraction', 'rulesExtraction');\n\n const usedFonts = new Map;\n\n if (options.fonts) {\n\n let j;\n let name;\n let value;\n let font: CSSFontFaceRule;\n let fontObject;\n let src;\n\n performance.mark('fontsExtraction');\n\n for (font of fonts) {\n\n if (font.style.getPropertyValue('font-family').split(/\\s*,\\s*/).some(token => {\n\n return fontFamilies.has(token.replace(/(['\"])([^\\1\\s]+)\\1/, '$2'));\n })) {\n\n src = font.style.getPropertyValue('src');\n\n if (!src) {\n\n continue;\n }\n\n fontObject = {\n 'fontFamily': font.style.getPropertyValue('font-family').replace(/(['\"])([^\\1\\s]+)\\1/, '$2'),\n src: src.replace(/(^|[,\\s*])local\\([^)]+\\)\\s*,?\\s*?/g, '').replace(/url\\(([^)%\\s]+)\\)([^,]*)(,?)\\s*/g, (all, one, two, three) => {\n\n one = one.replace(/(['\"])([^\\1\\s]+)\\1/, '$2');\n\n // @ts-ignore\n if (!files.has(font.parentStyleSheet)) {\n\n // @ts-ignore\n if (!font.parentStyleSheet.href) {\n\n return all;\n }\n\n // @ts-ignore\n files.set(font.parentStyleSheet, {\n\n // @ts-ignore\n base: font.parentStyleSheet.href.replace(/([^/]+)$/, ''),\n // @ts-ignore\n file: font.parentStyleSheet.href\n })\n }\n\n // @ts-ignore\n return 'url(' + resolve(one, files.get(font.parentStyleSheet).base) + ')' + three;\n }).trim(),\n properties: {}\n }\n\n j = font.style.length;\n\n while (j--) {\n\n name = font.style.item(j);\n value = font.style.getPropertyValue(name);\n\n name !== 'font-family' &&\n name !== 'src' &&\n value !== '' &&\n value !== undefined &&\n // @ts-ignore\n (fontObject.properties[name.replace(/([A-Z])/g, (all, name) => '-' + name.toLowerCase())] = value)\n }\n\n usedFonts.set(JSON.stringify(fontObject), fontObject)\n }\n }\n\n performance.measure('fonts extraction', 'fontsExtraction');\n }\n\n const stats = performance.getEntriesByType(\"measure\").filter(entry => ['filter stylesheets', 'node walking', 'rules extraction', 'fonts extraction'].includes(entry.name)).map(entry => {\n\n return {\n\n name: entry.name,\n\n duration: (entry.duration / 1000).toFixed(3) + 's'\n }\n });\n\n\n const result: CriticalResult = {\n styles: [...styles],\n fonts: [...usedFonts.values()],\n nodeCount,\n stats: {nodeCount, stats}\n };\n\n if (options.html) {\n\n if (!document.querySelector('base')) {\n\n const base: HTMLBaseElement = document.createElement('base');\n\n base.href = options.base ?? (location.protocol + '//' + location.host + location.pathname);\n document.head.insertBefore(base, document.querySelector('meta[charset]')?.nextElementSibling || document.head.firstChild)\n }\n\n if (!document.querySelector('meta[charset]')) {\n\n const meta = document.createElement('meta');\n meta.setAttribute('charset', 'utf-8');\n document.head.insertBefore(meta, document.head.firstChild)\n }\n\n // @ts-ignore\n Array.from(document.querySelectorAll('style,link[rel=stylesheet]')).forEach((node: HTMLLinkElement | HTMLStyleElement) => {\n\n document.body.append(node);\n\n if (node.tagName === 'LINK') {\n\n if (node.media === 'print') {\n\n return\n }\n\n if (node.hasAttribute('media')) {\n\n node.setAttribute('data-media', node.media);\n }\n\n node.media = 'print';\n node.dataset.async = '';\n }\n });\n\n const script: HTMLScriptElement = document.createElement('script');\n\n script.textContent = `\n window.addEventListener('DOMContentLoaded', () => Array.from(document.querySelectorAll('link[data-async]')).forEach(node => {\n\n if(!node.hasAttribute('data-media')) {\n node.removeAttribute('media');\n }\n else {\n node.media=node.dataset.media;\n node.removeAttribute('data-media')\n }\n \n node.removeAttribute('data-async');\n }))`;\n\n document.head.append(script);\n\n // add data-attribute\n const style: HTMLStyleElement = document.createElement('style');\n // @ts-ignore\n style.dataset.critical = true;\n style.textContent = [...usedFonts.values()].map((entry) => {\n\n return '@font-face {' + '\\n ' + Object.entries(entry).map(entry => {\n\n // @ts-ignore\n return typeof entry[1] == 'string' ? `${entry[0] + ': ' + entry[1]}` : Object.entries(entry[1]).map(entry => `${entry[0] + ': ' + entry[1]}`).join(';\\n ') + '\\n}'\n }).join(';\\n')\n }).join('\\n') +\n '\\n' + (result.styles).join('\\n');\n\n if (style.textContent.trim() !== '') {\n\n document.head.insertBefore(style, document.querySelector('base')?.nextElementSibling);\n }\n\n if ((result.fonts).length > 0) {\n\n const script = document.createElement('script');\n script.textContent = fontscript(result.fonts);\n document.head.append(script);\n }\n\n const doctype: DocumentType = document.doctype as DocumentType;\n\n result.html = `` + '\\n' + document.documentElement.outerHTML\n }\n\n return result;\n}","import {extract} from \"./critical/extract\";\nimport {download} from \"./file/download\";\nimport {fontscript} from \"./critical/fontscript\";\nimport {CriticalExtractOptions, CriticalResult} from \"./@types\";\n\nasync function extractAndDownload(filename: string = 'critical.css', options: CriticalExtractOptions = {}): Promise {\n\n return extract(options).\n then(async (content : CriticalResult): Promise => download(content.styles, filename, 'text/css; charset=utf-8').\n then(async () => {\n\n if ((content.fonts).length > 0) {\n\n // @ts-ignore\n return download([fontscript(content.fonts)], filename.replace(/\\.css$/, '.js'), 'text/javascript; charset=utf-8');\n }\n }).\n then(() => content)\n );\n}\n\nexport {extract, fontscript, extractAndDownload as download}"],"names":[],"mappings":";;;IAAA;;;;;;IAMG;IACI,eAAe,QAAQ,CAAC,OAAsB,EAAE,QAAgB,EAAE,QAAA,GAAmB,yCAAyC,EAAA;;IAGjI,IAAA,MAAM,GAAG,GAAW,GAAG,CAAC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,CAAA,CAAA,GAAG,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAA;SACxD;IAED,IAAA,OAAO,MAAM,CAAC;IAClB;;IC5fA,eAAe,kBAAkB,CAAC,WAAmB,cAAc,EAAE,UAAkC,EAAE,EAAA;QAErG,OAAO,OAAO,CAAC,OAAO,CAAC;IACnB,QAAA,IAAI,CAAC,OAAO,OAAwB,KAA8B,QAAQ,CAAW,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,yBAAyB,CAAC;YACrI,IAAI,CAAC,YAAW;YAEZ,IAAe,OAAO,CAAC,KAAM,CAAC,MAAM,GAAG,CAAC,EAAE;;gBAGtC,OAAO,QAAQ,CAAC,CAAC,UAAU,CAAW,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,gCAAgC,CAAC,CAAC;aAC/H;IACT,KAAC,CAAC;IACF,QAAA,IAAI,CAAC,MAAM,OAAO,CAAC,CACtB,CAAC;IACN;;;;;;;;;;;;"}
\ No newline at end of file
+{"version":3,"file":"browser-umd.js","sources":["../src/file/download.ts","../src/file/path.ts","../src/critical/fontscript.ts","../src/critical/extract.ts","../src/browser.ts"],"sourcesContent":["/**\n *\n * @param {string[]} content\n * @param {string} filename\n * @param {string} mimetype\n * @return {Promise}\n */\nexport async function download(content: Array, filename: string, mimetype: string = 'application/octet-stream; charset=utf-8'): Promise> {\n\n //\n const url: string = URL.createObjectURL(new Blob(content, {type: mimetype}));\n //\n const a: HTMLAnchorElement = document.createElement('a');\n document.body.append(a);\n a.style.display = 'none';\n a.download = filename;\n a.href = url;\n\n //\n a.dispatchEvent(new MouseEvent('click'));\n URL.revokeObjectURL(url);\n\n return content;\n}","\nexport function resolve(path: string, from: string): string {\n\n if (path.match(/^['\"]?data:/)) {\n\n return path;\n }\n\n // @ts-ignore\n const baseURL: URL = new URL(from, window.location);\n const pathURL: URL = new URL(path, baseURL);\n\n if (baseURL.protocol != pathURL.protocol ||\n baseURL.host != pathURL.host ||\n pathURL.host != window.location.host ||\n baseURL.port != pathURL.port ||\n pathURL.port != window.location.port ||\n baseURL.port != pathURL.port ||\n pathURL.protocol != window.location.protocol\n ) {\n\n return pathURL.toString();\n }\n\n return pathURL.pathname + pathURL.search + pathURL.hash;\n}","import type {FontObject} from \"../@types\";\n\nexport function fontscript(fonts: FontObject[]): string {\n\n return '/* font preloader script: ' + fonts.length + ' */\\n\"fonts\" in document && ' + JSON.stringify([...fonts], null, 1) + '.forEach(font => new FontFace(font.fontFamily, font.src, font.properties).load().then(font => document.fonts.add(font)))'\n}","import {resolve} from \"../file\";\nimport {fontscript} from \"./fontscript\";\nimport type {\n CriticalExtractOptions,\n CriticalResult,\n FileMapObject,\n FontObject,\n MatchCSSStyleSheet,\n RuleList\n} from \"../@types\";\n\nexport async function extract(options: CriticalExtractOptions = {}) {\n\n const document: Document = window.document;\n const location: Location = window.location;\n const styles: Set = new Set;\n const excluded: string[] = ['all', 'print', ''];\n const allStylesheets: MatchCSSStyleSheet[] = [];\n\n // Get a list of all the elements in the view.\n const height: number = window.innerHeight;\n const walker: NodeIterator = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, {acceptNode: () => NodeFilter.SHOW_ELEMENT});\n\n const fonts: Set = new Set;\n const fontFamilies: Set = new Set;\n const files: Map = new Map;\n const weakMap: WeakMap = new WeakMap;\n const nodeMap: Set = new Set;\n let nodeCount: number = 0;\n let k: number;\n let rule: CSSMediaRule | CSSStyleRule;\n let rules;\n\n performance.mark('filterStylesheets');\n\n for (k = 0; k < document.styleSheets.length; k++) {\n\n // @ts-ignore\n rule = document.styleSheets[k];\n\n if (rule.media.mediaText === 'print' || (rule.media.mediaText !== '' && !window.matchMedia(rule.media.mediaText).matches)) {\n\n continue;\n }\n\n try {\n\n // @ts-ignore\n rules = (rule).cssRules ?? (rule).rules;\n\n for (let l = 0; l < rules.length; l++) {\n\n allStylesheets.push({rule: rules[l], match: false})\n }\n\n } catch (e) {\n\n // @ts-ignore\n console.error(JSON.stringify({'message': e.message, stylesheet: rule.href}, null, 1));\n }\n }\n\n performance.measure('filter stylesheets', 'filterStylesheets');\n\n if (allStylesheets.length === 0) {\n\n return {styles: [], fonts: [], stats: {}};\n }\n\n let node;\n let rect;\n let allStylesLength = allStylesheets.length;\n\n performance.mark('nodeWalking');\n\n while ((node = walker.nextNode())) {\n\n if (options && options.signal && options.signal.aborted) {\n\n return Promise.reject('Aborted');\n }\n\n if (['SCRIPT', 'LINK', 'HEAD', 'META', 'TITLE', 'NOSCRIPT'].includes(node.tagName)) {\n\n continue;\n }\n\n nodeCount++;\n rect = node.getBoundingClientRect();\n\n if (rect.top < height) {\n\n nodeMap.add(node);\n }\n }\n\n for (k = 0; k < allStylesLength; k++) {\n\n if (allStylesheets[k].match || weakMap.has(allStylesheets[k].rule)) {\n\n continue;\n }\n\n weakMap.set(allStylesheets[k].rule, 1);\n\n if (allStylesheets[k].rule instanceof CSSStyleRule) {\n\n // @ts-ignore\n let selector = allStylesheets[k].rule.selectorText;\n let match;\n\n // detect pseudo selectors\n if (selector.match(/(^|,|\\s)::?((before)|(after))/)) {\n\n match = true\n } else {\n\n if (selector.match(/::?((before)|(after))/)) {\n\n selector = selector.replace(/::?((before)|(after))\\s*((,)|$)/g, '$5');\n }\n\n try {\n\n match = nodeMap.has(document.querySelector(selector));\n } catch (e) {\n\n // @ts-ignore\n match = nodeMap.has(document.querySelector(allStylesheets[k].rule.selectorText));\n }\n }\n\n if (match) {\n\n allStylesheets[k].match = true;\n\n // @ts-ignore\n if (allStylesheets[k].rule.style.getPropertyValue('font-family')) {\n\n // @ts-ignore\n allStylesheets[k].rule.style.getPropertyValue('font-family').split(/\\s*,\\s*/).forEach(fontFamily => fontFamily !== 'inherit' && fontFamilies.add(fontFamily.replace(/(['\"])([^\\1\\s]+)\\1/, '$2')));\n }\n }\n\n } else if (allStylesheets[k].rule instanceof CSSMediaRule || allStylesheets[k].rule instanceof CSSImportRule || allStylesheets[k].rule instanceof CSSConditionRule) {\n\n // @ts-ignore\n if ((allStylesheets[k].rule instanceof CSSMediaRule || allStylesheets[k].rule instanceof CSSImportRule) && (allStylesheets[k].rule.media.mediaText === 'print' || (allStylesheets[k].rule.media.mediaText !== '' && !window.matchMedia(allStylesheets[k].rule.media.mediaText).matches))) {\n continue;\n }\n\n try {\n\n const rule = allStylesheets[k].rule;\n const rules = [];\n // @ts-ignore\n const sheet = rule instanceof CSSImportRule ? rule.styleSheet.cssRules || rule.styleSheet.rules : rule.cssRules || rule.rules;\n\n for (let l = 0; l < sheet.length; l++) {\n\n if (!weakMap.has(sheet[l])) {\n\n rules.push({rule: sheet[l], match: false})\n }\n }\n\n if (rules.length > 0) {\n\n // @ts-ignore\n allStylesheets.splice.apply(allStylesheets, [k + 1, 0].concat(rules))\n allStylesLength = allStylesheets.length\n }\n } catch (e) {\n\n // @ts-ignore\n console.error(JSON.stringify({'message': e.message, stylesheet: rule.href}, null, 1));\n }\n } else if (allStylesheets[k].rule instanceof CSSFontFaceRule) {\n\n // @ts-ignore\n if (allStylesheets[k].rule.style.getPropertyValue('font-family') && allStylesheets[k].rule.style.getPropertyValue('src')) {\n\n // @ts-ignore\n fonts.add(allStylesheets[k].rule);\n }\n }\n }\n\n performance.measure('node walking', 'nodeWalking');\n\n let css;\n let file = '';\n let inlineCount = -1;\n\n performance.mark('rulesExtraction');\n\n loop1:\n for (let k = 0; k < allStylesLength; k++) {\n\n if (!allStylesheets[k].match) {\n\n continue;\n }\n\n // @ts-ignore\n rule = allStylesheets[k].rule;\n let fileUpdate: boolean = false;\n\n // @ts-ignore\n if (!files.has(rule.parentStyleSheet)) {\n\n //\n // @ts-ignore\n files.set(rule.parentStyleSheet, {\n\n // @ts-ignore\n base: (rule.parentStyleSheet.href && rule.parentStyleSheet.href.replace(/[?#].*/, '') || location.pathname).replace(/([^/]+)$/, ''),\n // @ts-ignore\n file: rule.parentStyleSheet.href || `inline style #${++inlineCount}`\n });\n\n fileUpdate = true;\n } else { // @ts-ignore\n if (file != null && file !== files.get(rule.parentStyleSheet).file) {\n\n fileUpdate = true;\n }\n }\n\n if (fileUpdate) {\n\n try {\n\n // @ts-ignore\n console.error('analysing ' + files.get(rule.parentStyleSheet).file);\n // @ts-ignore\n styles.add('/* file: ' + files.get(rule.parentStyleSheet).file + ' */');\n } catch (e) {\n\n // @ts-ignore\n console.error(JSON.stringify(e.message, null, 1));\n console.error(JSON.stringify(rule?.parentStyleSheet?.href, null, 1));\n }\n }\n\n file = (files.get(rule.parentStyleSheet)).file;\n css = rule.cssText;\n\n // @ts-ignore\n console.error({sel: rule.selectorText, css});\n\n if (file !== 'inline') {\n\n // resolve url()\n css = css.replace(/url\\(([^)%\\s]*?)\\)/g, function (all, one) {\n\n one = one.trim();\n\n if (one.match(/^['\"]?data:/)) {\n\n return all;\n }\n\n one = one.replace(/^(['\"])([^\\1\\s]+)\\1/, '$2');\n\n // @ts-ignore\n return 'url(' + resolve(one, files.get(rule.parentStyleSheet).base) + ')';\n })\n }\n\n while (rule.parentRule) {\n\n /**\n *\n * @type {CSSMediaRule}\n */\n // @ts-ignore\n rule = rule.parentRule;\n\n // @ts-ignore\n if (rule.conditionText == 'print') {\n\n continue loop1;\n }\n\n // @ts-ignore\n if (!excluded.includes(rule.conditionText)) {\n\n // @ts-ignore\n css = '@' + rule.constructor.name.replace(/^CSS(.*?)Rule/, '$1').toLowerCase() + ' ' + rule.conditionText + ' {' + css + '}';\n }\n\n if (!rule.parentRule) {\n\n break;\n }\n }\n\n if (rule.parentStyleSheet) {\n\n let media: string = rule.parentStyleSheet.media.mediaText;\n\n if (media === 'print') {\n\n continue;\n }\n\n if (media !== '') {\n\n css = '@media ' + media + ' {' + css + '}';\n }\n }\n\n if (styles.has(css)) {\n\n styles.delete(css);\n }\n\n styles.add(css);\n }\n\n performance.measure('rules extraction', 'rulesExtraction');\n\n const usedFonts = new Map;\n\n if (options.fonts) {\n\n let j;\n let name;\n let value;\n let font: CSSFontFaceRule;\n let fontObject;\n let src;\n\n performance.mark('fontsExtraction');\n\n for (font of fonts) {\n\n if (font.style.getPropertyValue('font-family').split(/\\s*,\\s*/).some(token => {\n\n return fontFamilies.has(token.replace(/(['\"])([^\\1\\s]+)\\1/, '$2'));\n })) {\n\n src = font.style.getPropertyValue('src');\n\n if (!src) {\n\n continue;\n }\n\n fontObject = {\n 'fontFamily': font.style.getPropertyValue('font-family').replace(/(['\"])([^\\1\\s]+)\\1/, '$2'),\n src: src.replace(/(^|[,\\s*])local\\([^)]+\\)\\s*,?\\s*?/g, '').replace(/url\\(([^)%\\s]+)\\)([^,]*)(,?)\\s*/g, (all, one, two, three) => {\n\n one = one.replace(/(['\"])([^\\1\\s]+)\\1/, '$2');\n\n // @ts-ignore\n if (!files.has(font.parentStyleSheet)) {\n\n // @ts-ignore\n if (!font.parentStyleSheet.href) {\n\n return all;\n }\n\n // @ts-ignore\n files.set(font.parentStyleSheet, {\n\n // @ts-ignore\n base: font.parentStyleSheet.href.replace(/([^/]+)$/, ''),\n // @ts-ignore\n file: font.parentStyleSheet.href\n })\n }\n\n // @ts-ignore\n return 'url(' + resolve(one, files.get(font.parentStyleSheet).base) + ')' + three;\n }).trim(),\n properties: {}\n }\n\n j = font.style.length;\n\n while (j--) {\n\n name = font.style.item(j);\n value = font.style.getPropertyValue(name);\n\n name !== 'font-family' &&\n name !== 'src' &&\n value !== '' &&\n value !== undefined &&\n // @ts-ignore\n (fontObject.properties[name.replace(/([A-Z])/g, (all, name) => '-' + name.toLowerCase())] = value)\n }\n\n usedFonts.set(JSON.stringify(fontObject), fontObject)\n }\n }\n\n performance.measure('fonts extraction', 'fontsExtraction');\n }\n\n const stats = performance.getEntriesByType(\"measure\").filter(entry => ['filter stylesheets', 'node walking', 'rules extraction', 'fonts extraction'].includes(entry.name)).map(entry => {\n\n return {\n\n name: entry.name,\n duration: (entry.duration / 1000).toFixed(3) + 's'\n }\n });\n\n\n const result: CriticalResult = {\n styles: [...styles],\n fonts: [...usedFonts.values()],\n nodeCount,\n stats: {nodeCount, stats}\n };\n\n if (options.html) {\n\n if (!document.querySelector('base')) {\n\n const base: HTMLBaseElement = document.createElement('base');\n\n base.href = options.base ?? (location.protocol + '//' + location.host + location.pathname);\n document.head.insertBefore(base, document.querySelector('meta[charset]')?.nextElementSibling || document.head.firstChild)\n }\n\n if (!document.querySelector('meta[charset]')) {\n\n const meta = document.createElement('meta');\n meta.setAttribute('charset', 'utf-8');\n document.head.insertBefore(meta, document.head.firstChild)\n }\n\n // @ts-ignore\n Array.from(document.querySelectorAll('style,link[rel=stylesheet]')).forEach((node: HTMLLinkElement | HTMLStyleElement) => {\n\n document.body.append(node);\n\n if (node.tagName === 'LINK') {\n\n if (node.media === 'print') {\n\n return\n }\n\n if (node.hasAttribute('media')) {\n\n node.setAttribute('data-media', node.media);\n }\n\n node.media = 'print';\n node.dataset.async = '';\n }\n });\n\n const script: HTMLScriptElement = document.createElement('script');\n\n script.textContent = `\n window.addEventListener('DOMContentLoaded', () => Array.from(document.querySelectorAll('link[data-async]')).forEach(node => {\n\n if(!node.hasAttribute('data-media')) {\n node.removeAttribute('media');\n }\n else {\n node.media=node.dataset.media;\n node.removeAttribute('data-media')\n }\n \n node.removeAttribute('data-async');\n }))`;\n\n document.head.append(script);\n\n // add data-attribute\n const style: HTMLStyleElement = document.createElement('style');\n // @ts-ignore\n style.dataset.critical = true;\n style.textContent = [...usedFonts.values()].map((entry) => {\n\n return '@font-face {' + '\\n ' + Object.entries(entry).map(entry => {\n\n // @ts-ignore\n return typeof entry[1] == 'string' ? `${entry[0] + ': ' + entry[1]}` : Object.entries(entry[1]).map(entry => `${entry[0] + ': ' + entry[1]}`).join(';\\n ') + '\\n}'\n }).join(';\\n')\n }).join('\\n') +\n '\\n' + (result.styles).join('\\n');\n\n if (style.textContent.trim() !== '') {\n\n document.head.insertBefore(style, document.querySelector('base')?.nextElementSibling);\n }\n\n if ((result.fonts).length > 0) {\n\n const script: HTMLScriptElement = document.createElement('script');\n script.textContent = fontscript(result.fonts);\n document.head.append(script);\n }\n\n const doctype: DocumentType = document.doctype as DocumentType;\n\n result.html = `` + '\\n' + document.documentElement.outerHTML\n }\n\n return result;\n}\n","import {extract} from \"./critical/extract\";\nimport {download} from \"./file/download\";\nimport {fontscript} from \"./critical/fontscript\";\nimport {CriticalExtractOptions, CriticalResult} from \"./@types\";\n\nasync function extractAndDownload(filename: string = 'critical.css', options: CriticalExtractOptions = {}): Promise {\n\n return extract(options).\n then(async (content : CriticalResult): Promise => download(content.styles, filename, 'text/css; charset=utf-8').\n then(async () => {\n\n if ((content.fonts).length > 0) {\n\n // @ts-ignore\n return download([fontscript(content.fonts)], filename.replace(/\\.css$/, '.js'), 'text/javascript; charset=utf-8');\n }\n }).\n then(() => content)\n );\n}\n\nexport {extract, fontscript, extractAndDownload as download}"],"names":[],"mappings":";;;IAAA;;;;;;IAMG;IACI,eAAe,QAAQ,CAAC,OAAsB,EAAE,QAAgB,EAAE,QAAA,GAAmB,yCAAyC,EAAA;;IAGjI,IAAA,MAAM,GAAG,GAAW,GAAG,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC,CAAC,CAAC,CAAC;;QAE7E,MAAM,CAAC,GAAsB,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACzD,IAAA,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACxB,IAAA,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;IACzB,IAAA,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACtB,IAAA,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC;;QAGb,CAAC,CAAC,aAAa,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IACzC,IAAA,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IAEzB,IAAA,OAAO,OAAO,CAAC;IACnB;;ICtBgB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OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,gCAAgC,CAAC,CAAC;aAC/H;IACT,KAAC,CAAC;IACF,QAAA,IAAI,CAAC,MAAM,OAAO,CAAC,CACtB,CAAC;IACN;;;;;;;;;;;;"}
\ No newline at end of file
diff --git a/dist/browser.js b/dist/browser.js
index 185e65b..b1b2c10 100644
--- a/dist/browser.js
+++ b/dist/browser.js
@@ -213,6 +213,8 @@ async function extract(options = {}) {
}
file = files.get(rule.parentStyleSheet).file;
css = rule.cssText;
+ // @ts-ignore
+ console.error({ sel: rule.selectorText, css });
if (file !== 'inline') {
// resolve url()
css = css.replace(/url\(([^)%\s]*?)\)/g, function (all, one) {
diff --git a/dist/browser.js.map b/dist/browser.js.map
index 36986f6..18cc2c4 100644
--- a/dist/browser.js.map
+++ b/dist/browser.js.map
@@ -1 +1 @@
-{"version":3,"file":"browser.js","sources":["../src/file/download.ts","../src/file/path.ts","../src/critical/fontscript.ts","../src/critical/extract.ts","../src/browser.ts"],"sourcesContent":["/**\n *\n * @param {string[]} content\n * @param {string} filename\n * @param {string} mimetype\n * @return {Promise}\n */\nexport async function download(content: Array, filename: string, mimetype: string = 'application/octet-stream; charset=utf-8'): Promise> {\n\n //\n const url: string = URL.createObjectURL(new Blob(content, {type: mimetype}));\n //\n const a: HTMLAnchorElement = document.createElement('a');\n document.body.append(a);\n a.style.display = 'none';\n a.download = filename;\n a.href = url;\n\n //\n a.dispatchEvent(new MouseEvent('click'));\n URL.revokeObjectURL(url);\n\n return content;\n}","\nexport function resolve(path: string, from: string): string {\n\n if (path.match(/^['\"]?data:/)) {\n\n return path;\n }\n\n // @ts-ignore\n const baseURL: URL = new URL(from, window.location);\n const pathURL: URL = new URL(path, baseURL);\n\n if (baseURL.protocol != pathURL.protocol ||\n baseURL.host != pathURL.host ||\n pathURL.host != window.location.host ||\n baseURL.port != pathURL.port ||\n pathURL.port != window.location.port ||\n baseURL.port != pathURL.port ||\n pathURL.protocol != window.location.protocol\n ) {\n\n return pathURL.toString();\n }\n\n return pathURL.pathname + pathURL.search + pathURL.hash;\n}","import type {FontObject} from \"../@types\";\n\nexport function fontscript(fonts: FontObject[]): string {\n\n return '/* font preloader script: ' + fonts.length + ' */\\n\"fonts\" in document && ' + JSON.stringify([...fonts], null, 1) + '.forEach(font => new FontFace(font.fontFamily, font.src, font.properties).load().then(font => document.fonts.add(font)))'\n}","import {resolve} from \"../file\";\nimport {fontscript} from \"./fontscript\";\nimport type {\n CriticalExtractOptions,\n CriticalResult,\n FileMapObject,\n FontObject,\n MatchCSSStyleSheet,\n RuleList\n} from \"../@types\";\n\nexport async function extract(options: CriticalExtractOptions = {}) {\n\n const document: Document = window.document;\n const location: Location = window.location;\n const styles: Set = new Set;\n const excluded = ['all', 'print', ''];\n const allStylesheets: MatchCSSStyleSheet[] = [];\n\n // Get a list of all the elements in the view.\n const height = window.innerHeight;\n const walker = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, {acceptNode: () => NodeFilter.SHOW_ELEMENT});\n\n const fonts: Set = new Set;\n const fontFamilies: Set = new Set;\n const files: Map = new Map;\n const weakMap: WeakMap = new WeakMap;\n const nodeMap: Set = new Set;\n let nodeCount: number = 0;\n let k: number;\n let rule: CSSMediaRule | CSSStyleRule;\n let rules;\n\n performance.mark('filterStylesheets');\n\n for (k = 0; k < document.styleSheets.length; k++) {\n\n // @ts-ignore\n rule = document.styleSheets[k];\n\n if (rule.media.mediaText === 'print' || (rule.media.mediaText !== '' && !window.matchMedia(rule.media.mediaText).matches)) {\n\n continue;\n }\n\n try {\n\n\n // @ts-ignore\n rules = (rule).cssRules ?? (rule).rules;\n\n for (let l = 0; l < rules.length; l++) {\n\n allStylesheets.push({rule: rules[l], match: false})\n }\n\n } catch (e) {\n\n // @ts-ignore\n console.error(JSON.stringify({'message': e.message, stylesheet: rule.href}, null, 1));\n }\n }\n\n performance.measure('filter stylesheets', 'filterStylesheets');\n\n if (allStylesheets.length === 0) {\n\n return {styles: [], fonts: [], stats: {}};\n }\n\n let node;\n let rect;\n let allStylesLength = allStylesheets.length;\n\n performance.mark('nodeWalking');\n\n while ((node = walker.nextNode())) {\n\n if (options && options.signal && options.signal.aborted) {\n\n return Promise.reject('Aborted');\n }\n\n if (['SCRIPT', 'LINK', 'HEAD', 'META', 'TITLE', 'NOSCRIPT'].includes(node.tagName)) {\n\n continue;\n }\n\n nodeCount++;\n rect = node.getBoundingClientRect();\n\n if (rect.top < height) {\n\n nodeMap.add(node);\n }\n }\n\n for (k = 0; k < allStylesLength; k++) {\n\n if (allStylesheets[k].match || weakMap.has(allStylesheets[k].rule)) {\n\n continue;\n }\n\n weakMap.set(allStylesheets[k].rule, 1);\n\n if (allStylesheets[k].rule instanceof CSSStyleRule) {\n\n // @ts-ignore\n let selector = allStylesheets[k].rule.selectorText;\n let match;\n\n // detect pseudo selectors\n if (selector.match(/(^|,|\\s)::?((before)|(after))/)) {\n\n match = true\n } else {\n\n if (selector.match(/::?((before)|(after))/)) {\n\n selector = selector.replace(/::?((before)|(after))\\s*((,)|$)/g, '$5');\n }\n\n try {\n\n match = nodeMap.has(document.querySelector(selector));\n } catch (e) {\n\n // @ts-ignore\n match = nodeMap.has(document.querySelector(allStylesheets[k].rule.selectorText));\n }\n }\n\n if (match) {\n\n allStylesheets[k].match = true;\n\n // @ts-ignore\n if (allStylesheets[k].rule.style.getPropertyValue('font-family')) {\n\n // @ts-ignore\n allStylesheets[k].rule.style.getPropertyValue('font-family').split(/\\s*,\\s*/).forEach(fontFamily => fontFamily !== 'inherit' && fontFamilies.add(fontFamily.replace(/(['\"])([^\\1\\s]+)\\1/, '$2')));\n }\n }\n\n } else if (allStylesheets[k].rule instanceof CSSMediaRule || allStylesheets[k].rule instanceof CSSImportRule || allStylesheets[k].rule instanceof CSSConditionRule) {\n\n // @ts-ignore\n if ((allStylesheets[k].rule instanceof CSSMediaRule || allStylesheets[k].rule instanceof CSSImportRule) && (allStylesheets[k].rule.media.mediaText === 'print' || (allStylesheets[k].rule.media.mediaText !== '' && !window.matchMedia(allStylesheets[k].rule.media.mediaText).matches))) {\n continue;\n }\n\n try {\n\n const rule = allStylesheets[k].rule;\n const rules = [];\n // @ts-ignore\n const sheet = rule instanceof CSSImportRule ? rule.styleSheet.cssRules || rule.styleSheet.rules : rule.cssRules || rule.rules;\n\n for (let l = 0; l < sheet.length; l++) {\n\n if (!weakMap.has(sheet[l])) {\n\n rules.push({rule: sheet[l], match: false})\n }\n }\n\n if (rules.length > 0) {\n\n // @ts-ignore\n allStylesheets.splice.apply(allStylesheets, [k + 1, 0].concat(rules))\n allStylesLength = allStylesheets.length\n }\n } catch (e) {\n\n // @ts-ignore\n console.error(JSON.stringify({'message': e.message, stylesheet: rule.href}, null, 1));\n }\n } else if (allStylesheets[k].rule instanceof CSSFontFaceRule) {\n\n // @ts-ignore\n if (allStylesheets[k].rule.style.getPropertyValue('font-family') && allStylesheets[k].rule.style.getPropertyValue('src')) {\n\n // @ts-ignore\n fonts.add(allStylesheets[k].rule);\n }\n }\n }\n\n performance.measure('node walking', 'nodeWalking');\n\n let css;\n let file = '';\n let inlineCount = -1;\n\n performance.mark('rulesExtraction');\n\n loop1:\n for (let k = 0; k < allStylesLength; k++) {\n\n if (!allStylesheets[k].match) {\n\n continue;\n }\n\n // @ts-ignore\n rule = allStylesheets[k].rule;\n let fileUpdate = false;\n\n // @ts-ignore\n if (!files.has(rule.parentStyleSheet)) {\n\n //\n // @ts-ignore\n files.set(rule.parentStyleSheet, {\n\n // @ts-ignore\n base: (rule.parentStyleSheet.href && rule.parentStyleSheet.href.replace(/[?#].*/, '') || location.pathname).replace(/([^/]+)$/, ''),\n // @ts-ignore\n file: rule.parentStyleSheet.href || `inline style #${++inlineCount}`\n });\n\n fileUpdate = true;\n } else { // @ts-ignore\n if (file != null && file !== files.get(rule.parentStyleSheet).file) {\n\n fileUpdate = true;\n }\n }\n\n if (fileUpdate) {\n\n try {\n\n // @ts-ignore\n console.error('analysing ' + files.get(rule.parentStyleSheet).file);\n // @ts-ignore\n styles.add('/* file: ' + files.get(rule.parentStyleSheet).file + ' */');\n } catch (e) {\n\n // @ts-ignore\n console.error(JSON.stringify(e.message, null, 1));\n console.error(JSON.stringify(rule?.parentStyleSheet?.href, null, 1));\n }\n }\n\n file = (files.get(rule.parentStyleSheet)).file;\n css = rule.cssText;\n\n if (file !== 'inline') {\n\n // resolve url()\n css = css.replace(/url\\(([^)%\\s]*?)\\)/g, function (all, one) {\n\n one = one.trim();\n\n if (one.match(/^['\"]?data:/)) {\n\n return all;\n }\n\n one = one.replace(/^(['\"])([^\\1\\s]+)\\1/, '$2');\n\n // @ts-ignore\n return 'url(' + resolve(one, files.get(rule.parentStyleSheet).base) + ')';\n })\n }\n\n while (rule.parentRule) {\n\n /**\n *\n * @type {CSSMediaRule}\n */\n // @ts-ignore\n rule = rule.parentRule;\n\n // @ts-ignore\n if (rule.conditionText == 'print') {\n\n continue loop1;\n }\n\n // @ts-ignore\n if (!excluded.includes(rule.conditionText)) {\n\n // @ts-ignore\n css = '@' + rule.constructor.name.replace(/^CSS(.*?)Rule/, '$1').toLowerCase() + ' ' + rule.conditionText + ' {' + css + '}';\n }\n\n if (!rule.parentRule) {\n\n break;\n }\n }\n\n if (rule.parentStyleSheet) {\n\n let media = rule.parentStyleSheet.media.mediaText;\n\n if (media === 'print') {\n\n continue;\n }\n\n if (media !== '') {\n\n css = '@media ' + media + ' {' + css + '}';\n }\n }\n\n if (styles.has(css)) {\n\n styles.delete(css);\n }\n\n styles.add(css);\n }\n\n performance.measure('rules extraction', 'rulesExtraction');\n\n const usedFonts = new Map;\n\n if (options.fonts) {\n\n let j;\n let name;\n let value;\n let font: CSSFontFaceRule;\n let fontObject;\n let src;\n\n performance.mark('fontsExtraction');\n\n for (font of fonts) {\n\n if (font.style.getPropertyValue('font-family').split(/\\s*,\\s*/).some(token => {\n\n return fontFamilies.has(token.replace(/(['\"])([^\\1\\s]+)\\1/, '$2'));\n })) {\n\n src = font.style.getPropertyValue('src');\n\n if (!src) {\n\n continue;\n }\n\n fontObject = {\n 'fontFamily': font.style.getPropertyValue('font-family').replace(/(['\"])([^\\1\\s]+)\\1/, '$2'),\n src: src.replace(/(^|[,\\s*])local\\([^)]+\\)\\s*,?\\s*?/g, '').replace(/url\\(([^)%\\s]+)\\)([^,]*)(,?)\\s*/g, (all, one, two, three) => {\n\n one = one.replace(/(['\"])([^\\1\\s]+)\\1/, '$2');\n\n // @ts-ignore\n if (!files.has(font.parentStyleSheet)) {\n\n // @ts-ignore\n if (!font.parentStyleSheet.href) {\n\n return all;\n }\n\n // @ts-ignore\n files.set(font.parentStyleSheet, {\n\n // @ts-ignore\n base: font.parentStyleSheet.href.replace(/([^/]+)$/, ''),\n // @ts-ignore\n file: font.parentStyleSheet.href\n })\n }\n\n // @ts-ignore\n return 'url(' + resolve(one, files.get(font.parentStyleSheet).base) + ')' + three;\n }).trim(),\n properties: {}\n }\n\n j = font.style.length;\n\n while (j--) {\n\n name = font.style.item(j);\n value = font.style.getPropertyValue(name);\n\n name !== 'font-family' &&\n name !== 'src' &&\n value !== '' &&\n value !== undefined &&\n // @ts-ignore\n (fontObject.properties[name.replace(/([A-Z])/g, (all, name) => '-' + name.toLowerCase())] = value)\n }\n\n usedFonts.set(JSON.stringify(fontObject), fontObject)\n }\n }\n\n performance.measure('fonts extraction', 'fontsExtraction');\n }\n\n const stats = performance.getEntriesByType(\"measure\").filter(entry => ['filter stylesheets', 'node walking', 'rules extraction', 'fonts extraction'].includes(entry.name)).map(entry => {\n\n return {\n\n name: entry.name,\n\n duration: (entry.duration / 1000).toFixed(3) + 's'\n }\n });\n\n\n const result: CriticalResult = {\n styles: [...styles],\n fonts: [...usedFonts.values()],\n nodeCount,\n stats: {nodeCount, stats}\n };\n\n if (options.html) {\n\n if (!document.querySelector('base')) {\n\n const base: HTMLBaseElement = document.createElement('base');\n\n base.href = options.base ?? (location.protocol + '//' + location.host + location.pathname);\n document.head.insertBefore(base, document.querySelector('meta[charset]')?.nextElementSibling || document.head.firstChild)\n }\n\n if (!document.querySelector('meta[charset]')) {\n\n const meta = document.createElement('meta');\n meta.setAttribute('charset', 'utf-8');\n document.head.insertBefore(meta, document.head.firstChild)\n }\n\n // @ts-ignore\n Array.from(document.querySelectorAll('style,link[rel=stylesheet]')).forEach((node: HTMLLinkElement | HTMLStyleElement) => {\n\n document.body.append(node);\n\n if (node.tagName === 'LINK') {\n\n if (node.media === 'print') {\n\n return\n }\n\n if (node.hasAttribute('media')) {\n\n node.setAttribute('data-media', node.media);\n }\n\n node.media = 'print';\n node.dataset.async = '';\n }\n });\n\n const script: HTMLScriptElement = document.createElement('script');\n\n script.textContent = `\n window.addEventListener('DOMContentLoaded', () => Array.from(document.querySelectorAll('link[data-async]')).forEach(node => {\n\n if(!node.hasAttribute('data-media')) {\n node.removeAttribute('media');\n }\n else {\n node.media=node.dataset.media;\n node.removeAttribute('data-media')\n }\n \n node.removeAttribute('data-async');\n }))`;\n\n document.head.append(script);\n\n // add data-attribute\n const style: HTMLStyleElement = document.createElement('style');\n // @ts-ignore\n style.dataset.critical = true;\n style.textContent = [...usedFonts.values()].map((entry) => {\n\n return '@font-face {' + '\\n ' + Object.entries(entry).map(entry => {\n\n // @ts-ignore\n return typeof entry[1] == 'string' ? `${entry[0] + ': ' + entry[1]}` : Object.entries(entry[1]).map(entry => `${entry[0] + ': ' + entry[1]}`).join(';\\n ') + '\\n}'\n }).join(';\\n')\n }).join('\\n') +\n '\\n' + (result.styles).join('\\n');\n\n if (style.textContent.trim() !== '') {\n\n document.head.insertBefore(style, document.querySelector('base')?.nextElementSibling);\n }\n\n if ((result.fonts).length > 0) {\n\n const script = document.createElement('script');\n script.textContent = fontscript(result.fonts);\n document.head.append(script);\n }\n\n const doctype: DocumentType = document.doctype as DocumentType;\n\n result.html = `` + '\\n' + document.documentElement.outerHTML\n }\n\n return result;\n}","import {extract} from \"./critical/extract\";\nimport {download} from \"./file/download\";\nimport {fontscript} from \"./critical/fontscript\";\nimport {CriticalExtractOptions, CriticalResult} from \"./@types\";\n\nasync function extractAndDownload(filename: string = 'critical.css', options: CriticalExtractOptions = {}): Promise {\n\n return extract(options).\n then(async (content : CriticalResult): Promise => download(content.styles, filename, 'text/css; charset=utf-8').\n then(async () => {\n\n if ((content.fonts).length > 0) {\n\n // @ts-ignore\n return download([fontscript(content.fonts)], filename.replace(/\\.css$/, '.js'), 'text/javascript; charset=utf-8');\n }\n }).\n then(() => content)\n );\n}\n\nexport {extract, fontscript, extractAndDownload as download}"],"names":[],"mappings":"AAAA;;;;;;AAMG;AACI,eAAe,QAAQ,CAAC,OAAsB,EAAE,QAAgB,EAAE,QAAA,GAAmB,yCAAyC,EAAA;;AAGjI,IAAA,MAAM,GAAG,GAAW,GAAG,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC,CAAC,CAAC,CAAC;;IAE7E,MAAM,CAAC,GAAsB,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;AACzD,IAAA,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACxB,IAAA,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;AACzB,IAAA,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACtB,IAAA,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC;;IAGb,CAAC,CAAC,aAAa,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;AACzC,IAAA,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;AAEzB,IAAA,OAAO,OAAO,CAAC;AACnB;;ACtBgB,SAAA,OAAO,CAAC,IAAY,EAAE,IAAY,EAAA;AAE9C,IAAA,IAAI,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE;AAE3B,QAAA,OAAO,IAAI,CAAC;KACf;;IAGD,MAAM,OAAO,GAAQ,IAAI,G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AC,MAAM,CAAC,CAAC;SAChC;AAED,QAAA,MAAM,OAAO,GAAiB,QAAQ,CAAC,OAAuB,CAAC;AAE/D,QAAA,MAAM,CAAC,IAAI,GAAG,aAAa,OAAO,CAAC,IAAI,CAAE,CAAA;AACnC,eAAC,OAAO,CAAC,QAAQ,GAAG,CAAA,SAAA,EAAY,OAAO,CAAC,QAAQ,CAAG,CAAA,CAAA,GAAG,EAAE,CAAC;eACxD,OAAO,CAAC,QAAQ;AACf,kBAAE,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAA,CAAE,GAAG,SAAS,IAAI,KAAK,OAAO,CAAC,QAAQ,CAAG,CAAA,CAAA;kBAC9D,EAAE,CAAC;cACP,CAAG,CAAA,CAAA,GAAG,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAA;KACxD;AAED,IAAA,OAAO,MAAM,CAAC;AAClB;;AC5fA,eAAe,kBAAkB,CAAC,WAAmB,cAAc,EAAE,UAAkC,EAAE,EAAA;IAErG,OAAO,OAAO,CAAC,OAAO,CAAC;AACnB,QAAA,IAAI,CAAC,OAAO,OAAwB,KAA8B,QAAQ,CAAW,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,yBAAyB,CAAC;QACrI,IAAI,CAAC,YAAW;QAEZ,IAAe,OAAO,CAAC,KAAM,CAAC,MAAM,GAAG,CAAC,EAAE;;YAGtC,OAAO,QAAQ,CAAC,CAAC,UAAU,CAAW,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,gCAAgC,CAAC,CAAC;SAC/H;AACT,KAAC,CAAC;AACF,QAAA,IAAI,CAAC,MAAM,OAAO,CAAC,CACtB,CAAC;AACN;;;;"}
\ No newline at end of file
+{"version":3,"file":"browser.js","sources":["../src/file/download.ts","../src/file/path.ts","../src/critical/fontscript.ts","../src/critical/extract.ts","../src/browser.ts"],"sourcesContent":["/**\n *\n * @param {string[]} content\n * @param {string} filename\n * @param {string} mimetype\n * @return {Promise}\n */\nexport async function download(content: Array, filename: string, mimetype: string = 'application/octet-stream; charset=utf-8'): Promise> {\n\n //\n const url: string = URL.createObjectURL(new Blob(content, {type: mimetype}));\n //\n const a: HTMLAnchorElement = document.createElement('a');\n document.body.append(a);\n a.style.display = 'none';\n a.download = filename;\n a.href = url;\n\n //\n a.dispatchEvent(new MouseEvent('click'));\n URL.revokeObjectURL(url);\n\n return content;\n}","\nexport function resolve(path: string, from: string): string {\n\n if (path.match(/^['\"]?data:/)) {\n\n return path;\n }\n\n // @ts-ignore\n const baseURL: URL = new URL(from, window.location);\n const pathURL: URL = new URL(path, baseURL);\n\n if (baseURL.protocol != pathURL.protocol ||\n baseURL.host != pathURL.host ||\n pathURL.host != window.location.host ||\n baseURL.port != pathURL.port ||\n pathURL.port != window.location.port ||\n baseURL.port != pathURL.port ||\n pathURL.protocol != window.location.protocol\n ) {\n\n return pathURL.toString();\n }\n\n return pathURL.pathname + pathURL.search + pathURL.hash;\n}","import type {FontObject} from \"../@types\";\n\nexport function fontscript(fonts: FontObject[]): string {\n\n return '/* font preloader script: ' + fonts.length + ' */\\n\"fonts\" in document && ' + JSON.stringify([...fonts], null, 1) + '.forEach(font => new FontFace(font.fontFamily, font.src, font.properties).load().then(font => document.fonts.add(font)))'\n}","import {resolve} from \"../file\";\nimport {fontscript} from \"./fontscript\";\nimport type {\n CriticalExtractOptions,\n CriticalResult,\n FileMapObject,\n FontObject,\n MatchCSSStyleSheet,\n RuleList\n} from \"../@types\";\n\nexport async function extract(options: CriticalExtractOptions = {}) {\n\n const document: Document = window.document;\n const location: Location = window.location;\n const styles: Set = new Set;\n const excluded: string[] = ['all', 'print', ''];\n const allStylesheets: MatchCSSStyleSheet[] = [];\n\n // Get a list of all the elements in the view.\n const height: number = window.innerHeight;\n const walker: NodeIterator = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, {acceptNode: () => NodeFilter.SHOW_ELEMENT});\n\n const fonts: Set = new Set;\n const fontFamilies: Set = new Set;\n const files: Map = new Map;\n const weakMap: WeakMap = new WeakMap;\n const nodeMap: Set = new Set;\n let nodeCount: number = 0;\n let k: number;\n let rule: CSSMediaRule | CSSStyleRule;\n let rules;\n\n performance.mark('filterStylesheets');\n\n for (k = 0; k < document.styleSheets.length; k++) {\n\n // @ts-ignore\n rule = document.styleSheets[k];\n\n if (rule.media.mediaText === 'print' || (rule.media.mediaText !== '' && !window.matchMedia(rule.media.mediaText).matches)) {\n\n continue;\n }\n\n try {\n\n // @ts-ignore\n rules = (rule).cssRules ?? (rule).rules;\n\n for (let l = 0; l < rules.length; l++) {\n\n allStylesheets.push({rule: rules[l], match: false})\n }\n\n } catch (e) {\n\n // @ts-ignore\n console.error(JSON.stringify({'message': e.message, stylesheet: rule.href}, null, 1));\n }\n }\n\n performance.measure('filter stylesheets', 'filterStylesheets');\n\n if (allStylesheets.length === 0) {\n\n return {styles: [], fonts: [], stats: {}};\n }\n\n let node;\n let rect;\n let allStylesLength = allStylesheets.length;\n\n performance.mark('nodeWalking');\n\n while ((node = walker.nextNode())) {\n\n if (options && options.signal && options.signal.aborted) {\n\n return Promise.reject('Aborted');\n }\n\n if (['SCRIPT', 'LINK', 'HEAD', 'META', 'TITLE', 'NOSCRIPT'].includes(node.tagName)) {\n\n continue;\n }\n\n nodeCount++;\n rect = node.getBoundingClientRect();\n\n if (rect.top < height) {\n\n nodeMap.add(node);\n }\n }\n\n for (k = 0; k < allStylesLength; k++) {\n\n if (allStylesheets[k].match || weakMap.has(allStylesheets[k].rule)) {\n\n continue;\n }\n\n weakMap.set(allStylesheets[k].rule, 1);\n\n if (allStylesheets[k].rule instanceof CSSStyleRule) {\n\n // @ts-ignore\n let selector = allStylesheets[k].rule.selectorText;\n let match;\n\n // detect pseudo selectors\n if (selector.match(/(^|,|\\s)::?((before)|(after))/)) {\n\n match = true\n } else {\n\n if (selector.match(/::?((before)|(after))/)) {\n\n selector = selector.replace(/::?((before)|(after))\\s*((,)|$)/g, '$5');\n }\n\n try {\n\n match = nodeMap.has(document.querySelector(selector));\n } catch (e) {\n\n // @ts-ignore\n match = nodeMap.has(document.querySelector(allStylesheets[k].rule.selectorText));\n }\n }\n\n if (match) {\n\n allStylesheets[k].match = true;\n\n // @ts-ignore\n if (allStylesheets[k].rule.style.getPropertyValue('font-family')) {\n\n // @ts-ignore\n allStylesheets[k].rule.style.getPropertyValue('font-family').split(/\\s*,\\s*/).forEach(fontFamily => fontFamily !== 'inherit' && fontFamilies.add(fontFamily.replace(/(['\"])([^\\1\\s]+)\\1/, '$2')));\n }\n }\n\n } else if (allStylesheets[k].rule instanceof CSSMediaRule || allStylesheets[k].rule instanceof CSSImportRule || allStylesheets[k].rule instanceof CSSConditionRule) {\n\n // @ts-ignore\n if ((allStylesheets[k].rule instanceof CSSMediaRule || allStylesheets[k].rule instanceof CSSImportRule) && (allStylesheets[k].rule.media.mediaText === 'print' || (allStylesheets[k].rule.media.mediaText !== '' && !window.matchMedia(allStylesheets[k].rule.media.mediaText).matches))) {\n continue;\n }\n\n try {\n\n const rule = allStylesheets[k].rule;\n const rules = [];\n // @ts-ignore\n const sheet = rule instanceof CSSImportRule ? rule.styleSheet.cssRules || rule.styleSheet.rules : rule.cssRules || rule.rules;\n\n for (let l = 0; l < sheet.length; l++) {\n\n if (!weakMap.has(sheet[l])) {\n\n rules.push({rule: sheet[l], match: false})\n }\n }\n\n if (rules.length > 0) {\n\n // @ts-ignore\n allStylesheets.splice.apply(allStylesheets, [k + 1, 0].concat(rules))\n allStylesLength = allStylesheets.length\n }\n } catch (e) {\n\n // @ts-ignore\n console.error(JSON.stringify({'message': e.message, stylesheet: rule.href}, null, 1));\n }\n } else if (allStylesheets[k].rule instanceof CSSFontFaceRule) {\n\n // @ts-ignore\n if (allStylesheets[k].rule.style.getPropertyValue('font-family') && allStylesheets[k].rule.style.getPropertyValue('src')) {\n\n // @ts-ignore\n fonts.add(allStylesheets[k].rule);\n }\n }\n }\n\n performance.measure('node walking', 'nodeWalking');\n\n let css;\n let file = '';\n let inlineCount = -1;\n\n performance.mark('rulesExtraction');\n\n loop1:\n for (let k = 0; k < allStylesLength; k++) {\n\n if (!allStylesheets[k].match) {\n\n continue;\n }\n\n // @ts-ignore\n rule = allStylesheets[k].rule;\n let fileUpdate: boolean = false;\n\n // @ts-ignore\n if (!files.has(rule.parentStyleSheet)) {\n\n //\n // @ts-ignore\n files.set(rule.parentStyleSheet, {\n\n // @ts-ignore\n base: (rule.parentStyleSheet.href && rule.parentStyleSheet.href.replace(/[?#].*/, '') || location.pathname).replace(/([^/]+)$/, ''),\n // @ts-ignore\n file: rule.parentStyleSheet.href || `inline style #${++inlineCount}`\n });\n\n fileUpdate = true;\n } else { // @ts-ignore\n if (file != null && file !== files.get(rule.parentStyleSheet).file) {\n\n fileUpdate = true;\n }\n }\n\n if (fileUpdate) {\n\n try {\n\n // @ts-ignore\n console.error('analysing ' + files.get(rule.parentStyleSheet).file);\n // @ts-ignore\n styles.add('/* file: ' + files.get(rule.parentStyleSheet).file + ' */');\n } catch (e) {\n\n // @ts-ignore\n console.error(JSON.stringify(e.message, null, 1));\n console.error(JSON.stringify(rule?.parentStyleSheet?.href, null, 1));\n }\n }\n\n file = (files.get(rule.parentStyleSheet)).file;\n css = rule.cssText;\n\n // @ts-ignore\n console.error({sel: rule.selectorText, css});\n\n if (file !== 'inline') {\n\n // resolve url()\n css = css.replace(/url\\(([^)%\\s]*?)\\)/g, function (all, one) {\n\n one = one.trim();\n\n if (one.match(/^['\"]?data:/)) {\n\n return all;\n }\n\n one = one.replace(/^(['\"])([^\\1\\s]+)\\1/, '$2');\n\n // @ts-ignore\n return 'url(' + resolve(one, files.get(rule.parentStyleSheet).base) + ')';\n })\n }\n\n while (rule.parentRule) {\n\n /**\n *\n * @type {CSSMediaRule}\n */\n // @ts-ignore\n rule = rule.parentRule;\n\n // @ts-ignore\n if (rule.conditionText == 'print') {\n\n continue loop1;\n }\n\n // @ts-ignore\n if (!excluded.includes(rule.conditionText)) {\n\n // @ts-ignore\n css = '@' + rule.constructor.name.replace(/^CSS(.*?)Rule/, '$1').toLowerCase() + ' ' + rule.conditionText + ' {' + css + '}';\n }\n\n if (!rule.parentRule) {\n\n break;\n }\n }\n\n if (rule.parentStyleSheet) {\n\n let media: string = rule.parentStyleSheet.media.mediaText;\n\n if (media === 'print') {\n\n continue;\n }\n\n if (media !== '') {\n\n css = '@media ' + media + ' {' + css + '}';\n }\n }\n\n if (styles.has(css)) {\n\n styles.delete(css);\n }\n\n styles.add(css);\n }\n\n performance.measure('rules extraction', 'rulesExtraction');\n\n const usedFonts = new Map;\n\n if (options.fonts) {\n\n let j;\n let name;\n let value;\n let font: CSSFontFaceRule;\n let fontObject;\n let src;\n\n performance.mark('fontsExtraction');\n\n for (font of fonts) {\n\n if (font.style.getPropertyValue('font-family').split(/\\s*,\\s*/).some(token => {\n\n return fontFamilies.has(token.replace(/(['\"])([^\\1\\s]+)\\1/, '$2'));\n })) {\n\n src = font.style.getPropertyValue('src');\n\n if (!src) {\n\n continue;\n }\n\n fontObject = {\n 'fontFamily': font.style.getPropertyValue('font-family').replace(/(['\"])([^\\1\\s]+)\\1/, '$2'),\n src: src.replace(/(^|[,\\s*])local\\([^)]+\\)\\s*,?\\s*?/g, '').replace(/url\\(([^)%\\s]+)\\)([^,]*)(,?)\\s*/g, (all, one, two, three) => {\n\n one = one.replace(/(['\"])([^\\1\\s]+)\\1/, '$2');\n\n // @ts-ignore\n if (!files.has(font.parentStyleSheet)) {\n\n // @ts-ignore\n if (!font.parentStyleSheet.href) {\n\n return all;\n }\n\n // @ts-ignore\n files.set(font.parentStyleSheet, {\n\n // @ts-ignore\n base: font.parentStyleSheet.href.replace(/([^/]+)$/, ''),\n // @ts-ignore\n file: font.parentStyleSheet.href\n })\n }\n\n // @ts-ignore\n return 'url(' + resolve(one, files.get(font.parentStyleSheet).base) + ')' + three;\n }).trim(),\n properties: {}\n }\n\n j = font.style.length;\n\n while (j--) {\n\n name = font.style.item(j);\n value = font.style.getPropertyValue(name);\n\n name !== 'font-family' &&\n name !== 'src' &&\n value !== '' &&\n value !== undefined &&\n // @ts-ignore\n (fontObject.properties[name.replace(/([A-Z])/g, (all, name) => '-' + name.toLowerCase())] = value)\n }\n\n usedFonts.set(JSON.stringify(fontObject), fontObject)\n }\n }\n\n performance.measure('fonts extraction', 'fontsExtraction');\n }\n\n const stats = performance.getEntriesByType(\"measure\").filter(entry => ['filter stylesheets', 'node walking', 'rules extraction', 'fonts extraction'].includes(entry.name)).map(entry => {\n\n return {\n\n name: entry.name,\n duration: (entry.duration / 1000).toFixed(3) + 's'\n }\n });\n\n\n const result: CriticalResult = {\n styles: [...styles],\n fonts: [...usedFonts.values()],\n nodeCount,\n stats: {nodeCount, stats}\n };\n\n if (options.html) {\n\n if (!document.querySelector('base')) {\n\n const base: HTMLBaseElement = document.createElement('base');\n\n base.href = options.base ?? (location.protocol + '//' + location.host + location.pathname);\n document.head.insertBefore(base, document.querySelector('meta[charset]')?.nextElementSibling || document.head.firstChild)\n }\n\n if (!document.querySelector('meta[charset]')) {\n\n const meta = document.createElement('meta');\n meta.setAttribute('charset', 'utf-8');\n document.head.insertBefore(meta, document.head.firstChild)\n }\n\n // @ts-ignore\n Array.from(document.querySelectorAll('style,link[rel=stylesheet]')).forEach((node: HTMLLinkElement | HTMLStyleElement) => {\n\n document.body.append(node);\n\n if (node.tagName === 'LINK') {\n\n if (node.media === 'print') {\n\n return\n }\n\n if (node.hasAttribute('media')) {\n\n node.setAttribute('data-media', node.media);\n }\n\n node.media = 'print';\n node.dataset.async = '';\n }\n });\n\n const script: HTMLScriptElement = document.createElement('script');\n\n script.textContent = `\n window.addEventListener('DOMContentLoaded', () => Array.from(document.querySelectorAll('link[data-async]')).forEach(node => {\n\n if(!node.hasAttribute('data-media')) {\n node.removeAttribute('media');\n }\n else {\n node.media=node.dataset.media;\n node.removeAttribute('data-media')\n }\n \n node.removeAttribute('data-async');\n }))`;\n\n document.head.append(script);\n\n // add data-attribute\n const style: HTMLStyleElement = document.createElement('style');\n // @ts-ignore\n style.dataset.critical = true;\n style.textContent = [...usedFonts.values()].map((entry) => {\n\n return '@font-face {' + '\\n ' + Object.entries(entry).map(entry => {\n\n // @ts-ignore\n return typeof entry[1] == 'string' ? `${entry[0] + ': ' + entry[1]}` : Object.entries(entry[1]).map(entry => `${entry[0] + ': ' + entry[1]}`).join(';\\n ') + '\\n}'\n }).join(';\\n')\n }).join('\\n') +\n '\\n' + (result.styles).join('\\n');\n\n if (style.textContent.trim() !== '') {\n\n document.head.insertBefore(style, document.querySelector('base')?.nextElementSibling);\n }\n\n if ((result.fonts).length > 0) {\n\n const script: HTMLScriptElement = document.createElement('script');\n script.textContent = fontscript(result.fonts);\n document.head.append(script);\n }\n\n const doctype: DocumentType = document.doctype as DocumentType;\n\n result.html = `` + '\\n' + document.documentElement.outerHTML\n }\n\n return result;\n}\n","import {extract} from \"./critical/extract\";\nimport {download} from \"./file/download\";\nimport {fontscript} from \"./critical/fontscript\";\nimport {CriticalExtractOptions, CriticalResult} from \"./@types\";\n\nasync function extractAndDownload(filename: string = 'critical.css', options: CriticalExtractOptions = {}): Promise {\n\n return extract(options).\n then(async (content : CriticalResult): Promise => download(content.styles, filename, 'text/css; charset=utf-8').\n then(async () => {\n\n if ((content.fonts).length > 0) {\n\n // @ts-ignore\n return download([fontscript(content.fonts)], filename.replace(/\\.css$/, '.js'), 'text/javascript; charset=utf-8');\n }\n }).\n then(() => content)\n );\n}\n\nexport {extract, fontscript, extractAndDownload as download}"],"names":[],"mappings":"AAAA;;;;;;AAMG;AACI,eAAe,QAAQ,CAAC,OAAsB,EAAE,QAAgB,EAAE,QAAA,GAAmB,yCAAyC,EAAA;;AAGjI,IAAA,MAAM,GAAG,GAAW,GAAG,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC,CAAC,CAAC,CAAC;;IAE7E,MAAM,CAAC,GAAsB,QAAQ,CAAC,aAAa,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OAAO,MAAM,CAAC;AAClB;;AC7fA,eAAe,kBAAkB,CAAC,WAAmB,cAAc,EAAE,UAAkC,EAAE,EAAA;IAErG,OAAO,OAAO,CAAC,OAAO,CAAC;AACnB,QAAA,IAAI,CAAC,OAAO,OAAwB,KAA8B,QAAQ,CAAW,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,yBAAyB,CAAC;QACrI,IAAI,CAAC,YAAW;QAEZ,IAAe,OAAO,CAAC,KAAM,CAAC,MAAM,GAAG,CAAC,EAAE;;YAGtC,OAAO,QAAQ,CAAC,CAAC,UAAU,CAAW,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,gCAAgC,CAAC,CAAC;SAC/H;AACT,KAAC,CAAC;AACF,QAAA,IAAI,CAAC,MAAM,OAAO,CAAC,CACtB,CAAC;AACN;;;;"}
\ No newline at end of file
diff --git a/dist/index.d.ts b/dist/index.d.ts
index d24ebd1..14b4cbc 100644
--- a/dist/index.d.ts
+++ b/dist/index.d.ts
@@ -11,6 +11,7 @@ interface CriticalOptions {
url?: string;
input?: string;
headless?: boolean;
+ advanced?: boolean;
browser?: BrowserOptions;
browserType?: 'mobile' | 'desktop' | 'default';
base?: string;
@@ -66,5 +67,7 @@ interface CriticalCliResult {
declare function critical(options: CriticalOptions): Promise;
declare function critical(url: string, options: CriticalOptions): Promise;
+declare function isWhiteSpace(codepoint: number): boolean;
+declare function splitRule(buffer: string): string[][];
-export { critical };
+export { critical, isWhiteSpace, splitRule };
diff --git a/dist/index.js b/dist/index.js
index b271328..03a2eea 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -5,7 +5,7 @@ import { readFileSync } from 'node:fs';
import { size } from './file/size.js';
import { fontscript } from './critical/fontscript.js';
import chalk from 'chalk';
-import { transform, render } from '@tbela99/css-parser';
+import { parse, expand, walk, EnumToken, render, transform } from '@tbela99/css-parser';
import { createRequire } from 'node:module';
import { mkdtemp, writeFile, rm, mkdir } from 'node:fs/promises';
import { tmpdir } from 'node:os';
@@ -19,6 +19,61 @@ const deviceNames = Object.values(devices);
async function sleep(duration) {
return new Promise(resolve => setTimeout(resolve, duration + Math.ceil(Math.random() * 10)));
}
+async function createBrowser(options, dimension, chromium, browserName) {
+ const launchOptions = {
+ headless: options.headless,
+ bypassCSP: !options.secure,
+ defaultViewport: {
+ isMobile: true,
+ isLandscape: false,
+ },
+ waitForInitialPage: false,
+ args: [],
+ ignoreDefaultArgs: ['--enable-automation']
+ };
+ launchOptions.args = [
+ '--test-type',
+ '--no-startup-window',
+ `--window-size=${dimension.width},${dimension.height}`
+ ];
+ if (!options.secure) {
+ launchOptions.args.push('--disable-web-security', '--allow-running-insecure-content', '--no-default-browser-check', '--ignore-certificate-errors', '--disable-site-isolation-trials');
+ }
+ if (options.container) {
+ launchOptions.args.push("--disable-gpu", "--disable-dev-shm-usage", "--disable-setuid-sandbox", "--no-sandbox");
+ }
+ let contextData = {};
+ if (options.browserType != null || options.randomUserAgent || options.randomBrowser) {
+ contextData = deviceNames.slice().sort(() => [-1, 0, 1][Math.floor(3 * Math.random())]).filter(d => {
+ if (browserName != d.defaultBrowserType) {
+ return false;
+ }
+ if (options.browserType != null) {
+ if (options.browserType == 'mobile') {
+ return d.isMobile;
+ }
+ else {
+ return !d.isMobile;
+ }
+ }
+ return true;
+ })[0];
+ }
+ const browser = await chromium.launch(launchOptions);
+ const context = await browser.newContext({
+ ...contextData,
+ bypassCSP: !options.secure,
+ viewport: dimension
+ });
+ if (options.randomUserAgent) {
+ // antibot evasion
+ await context.addInitScript(() => {
+ Object.defineProperty(navigator, 'webdriver', { get: () => undefined });
+ });
+ }
+ const page = await context.newPage();
+ return { browser, context, page };
+}
async function critical(url, options = {}) {
if (typeof url === 'object') {
options = url;
@@ -59,11 +114,11 @@ async function critical(url, options = {}) {
await writeFile(dir + '/index.html', options.input);
url = 'file://' + dir + '/index.html';
// @ts-ignore
- process.on('exit', async () => await rm(dir, { recursive: true }));
+ process.on('exit', async () => await rm(dir, { recursive: true, force: true }));
// @ts-ignore
- process.on('uncaughtException', async () => await rm(dir, { recursive: true }));
+ process.on('uncaughtException', async () => await rm(dir, { recursive: true, force: true }));
// @ts-ignore
- process.on('unhandledRejection', async () => await rm(dir, { recursive: true }));
+ process.on('unhandledRejection', async () => await rm(dir, { recursive: true, force: true }));
await page.close();
await context.close();
await browser.close();
@@ -135,6 +190,9 @@ async function critical(url, options = {}) {
height: +options.height
}] : ['1920x1080', '1440x900', '1366x768', '1024x768', '768x1024', '320x480'];
}
+ if (dimensions.length == 0) {
+ throw new Error(`No dimensions specified`);
+ }
if (typeof dimensions == 'string') {
dimensions = dimensions.split(/\s/);
}
@@ -154,65 +212,14 @@ async function critical(url, options = {}) {
dimensions.sort(() => [-1, 0, 1][Math.floor(3 * Math.random())]);
// @ts-ignore
for (const dimension of dimensions) {
- const launchOptions = {
- headless: options.headless,
- bypassCSP: !options.secure,
- defaultViewport: {
- isMobile: true,
- isLandscape: false,
- },
- waitForInitialPage: false,
- args: [],
- ignoreDefaultArgs: ['--enable-automation']
- };
- const size = ` (${dimension.width}x${dimension.height})`;
- launchOptions.args = [
- '--test-type',
- '--no-startup-window',
- `--window-size=${dimension.width},${dimension.height}`
- ];
- if (!options.secure) {
- launchOptions.args.push('--disable-web-security', '--allow-running-insecure-content', '--no-default-browser-check', '--ignore-certificate-errors', '--disable-site-isolation-trials');
- }
- if (options.container) {
- launchOptions.args.push("--disable-gpu", "--disable-dev-shm-usage", "--disable-setuid-sandbox", "--no-sandbox");
- }
if (options.verbose || options.console) {
console.error(chalk.blue(`[${shortUrl}]> selected browser `) + chalk.green(chromium.name()));
console.error(chalk.blue(`[${shortUrl}${size}]> set viewport to `) + chalk.green(`${dimension.width}x${dimension.height}`));
}
- let contextData = {};
- if (options.browserType != null || options.randomUserAgent || options.randomBrowser) {
- contextData = deviceNames.slice().sort(() => [-1, 0, 1][Math.floor(3 * Math.random())]).filter(d => {
- if (browserName != d.defaultBrowserType) {
- return false;
- }
- if (options.browserType != null) {
- if (options.browserType == 'mobile') {
- return d.isMobile;
- }
- else {
- return !d.isMobile;
- }
- }
- return true;
- })[0];
- }
- const browser = await chromium.launch(launchOptions);
- const context = await browser.newContext({
- ...contextData,
- bypassCSP: !options.secure,
- viewport: dimension
- });
- if (options.randomUserAgent) {
- // antibot evasion
- await context.addInitScript(() => {
- Object.defineProperty(navigator, 'webdriver', { get: () => undefined });
- });
- }
- await context.addInitScript(script + ';window.critical=critical;');
- const page = await context.newPage();
+ const { browser, context, page } = await createBrowser(options, dimension, chromium, browserName);
try {
+ const size = ` (${dimension.width}x${dimension.height})`;
+ await context.addInitScript(script + ';window.critical=critical;');
await page.emulateMedia({
colorScheme: options.colorScheme,
});
@@ -294,12 +301,56 @@ async function critical(url, options = {}) {
let rawCssFile = undefined;
let nestedCssFile = undefined;
let minNestedCssFile = undefined;
- if (options.filename) {
- const rawCSS = [...styles].join('\n');
- const { code, unminified } = (await transform(rawCSS).then(result => {
- return { code: result.code, unminified: render(result.ast, { minify: false }).code };
+ if (options.filename != null) {
+ let rawCSS = [...styles].join('\n');
+ let css = rawCSS;
+ if (options.advanced) {
+ const { browser, context, page } = await createBrowser(options, dimensions[0], chromium, browserName);
+ await page.emulateMedia({
+ colorScheme: options.colorScheme,
+ });
+ const dimension = dimensions[0];
+ const size = ` (${dimension.width}x${dimension.height})`;
+ console.error(chalk.blue(`[${shortUrl}${size}]> open `) + url);
+ if (options.input != null) {
+ const dir = await mkdtemp(tmpdir() + '/');
+ await writeFile(dir + '/index.html', options.input);
+ url = 'file://' + dir + '/index.html';
+ // @ts-ignore
+ process.on('exit', async () => await rm(dir, { recursive: true }));
+ // @ts-ignore
+ process.on('uncaughtException', async () => await rm(dir, { recursive: true, force: true }));
+ // @ts-ignore
+ process.on('unhandledRejection', async () => await rm(dir, { recursive: true, force: true }));
+ }
+ await page.goto(url, { waitUntil: 'networkidle' });
+ const result = await parse(rawCSS, { minify: false }).then(result => Object.assign(result, { ast: expand(result.ast) }));
+ for (const { node, parent } of walk(result.ast)) {
+ if (node.typ == EnumToken.RuleNodeType) {
+ const filtered = await Promise.all(splitRule(node.sel).map(async (sel) => {
+ const rule = sel.filter(sel => !sel.match(/::?((before)|(after))/));
+ if (rule.length == 0) {
+ return sel;
+ }
+ return await page.evaluate((param) => document.querySelector(param.sel) != null, { sel: rule.join('') }) ? sel : [];
+ })).then((r) => r.filter((r) => r.length > 0));
+ if (filtered.length == 0) {
+ parent.chi.splice(parent.chi.indexOf(node), 1);
+ }
+ else {
+ node.sel = filtered.reduce((acc, curr) => acc + (acc.length == 0 ? '' : ',') + curr.join(''), '');
+ }
+ }
+ }
+ css = render(result.ast, { minify: false, expandNestingRules: true }).code;
+ await page.close();
+ await context.close();
+ await browser.close();
+ }
+ const { code, unminified } = (await transform(css, { expandNestingRules: true }).then(result => {
+ return { code: result.code, unminified: render(result.ast, { minify: false, expandNestingRules: true }).code };
}));
- const { code: nestedCSS, unminified: nestedUnminified } = (await transform(rawCSS, { nestingRules: true }).then(result => {
+ const { code: nestedCSS, unminified: nestedUnminified } = (await transform(css, { nestingRules: true }).then(result => {
return { code: result.code, unminified: render(result.ast, { minify: false }).code };
}));
let cssFile = options.filename;
@@ -324,15 +375,15 @@ async function critical(url, options = {}) {
await writeFile(nestedCssFile, nestedUnminified);
// @ts-ignore
await writeFile(rawCssFile, rawCSS);
- }
- if (options.html != null && html != null && html !== '') {
- const match = html.match(/`);
+ if (options.html != null && html != null && html !== '') {
+ const match = html.match(/`);
+ }
+ htmlFile = options.filename + '.html';
+ // @ts-ignore
+ await writeFile(htmlFile, html);
}
- htmlFile = options.filename + '.html';
- // @ts-ignore
- await writeFile(htmlFile, html);
}
const fontObjects = new Set([...fonts].map((font) => JSON.parse(font)));
if (options.fonts) {
@@ -366,6 +417,111 @@ async function critical(url, options = {}) {
}, fonts: [...fonts], stats, html
};
}
+function isWhiteSpace(codepoint) {
+ return codepoint == 0x9 || codepoint == 0x20 ||
+ // isNewLine
+ codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;
+}
+function splitRule(buffer) {
+ const result = [[]];
+ let str = '';
+ for (let i = 0; i < buffer.length; i++) {
+ let chr = buffer.charAt(i);
+ if (isWhiteSpace(chr.charCodeAt(0))) {
+ let k = i;
+ while (k + 1 < buffer.length) {
+ if (isWhiteSpace(buffer[k + 1].charCodeAt(0))) {
+ k++;
+ continue;
+ }
+ break;
+ }
+ if (str !== '') {
+ // @ts-ignore
+ result.at(-1).push(str);
+ str = '';
+ }
+ // @ts-ignore
+ if (result.at(-1).length > 0) {
+ // @ts-ignore
+ result.at(-1).push(' ');
+ }
+ i = k;
+ continue;
+ }
+ if (chr == ',') {
+ if (str !== '') {
+ // @ts-ignore
+ result.at(-1).push(str);
+ str = '';
+ }
+ result.push([]);
+ continue;
+ }
+ if (chr == ':') {
+ if (str !== '') {
+ // @ts-ignore
+ result.at(-1).push(str);
+ str = '';
+ }
+ if (buffer.charAt(i + 1) == ':') {
+ chr += buffer.charAt(++i);
+ }
+ str += chr;
+ continue;
+ }
+ str += chr;
+ if (chr == '\\') {
+ str += buffer.charAt(++i);
+ continue;
+ }
+ if (chr == '"' || chr == "'") {
+ let k = i;
+ while (++k < buffer.length) {
+ chr = buffer.charAt(k);
+ str += chr;
+ if (chr == '//') {
+ str += buffer.charAt(++k);
+ continue;
+ }
+ if (chr == buffer.charAt(i)) {
+ break;
+ }
+ }
+ continue;
+ }
+ if (chr == '(' || chr == '[') {
+ const open = chr;
+ const close = chr == '(' ? ')' : ']';
+ let inParens = 1;
+ let k = i;
+ while (++k < buffer.length) {
+ chr = buffer.charAt(k);
+ if (chr == '\\') {
+ str += buffer.slice(k, k + 2);
+ k++;
+ continue;
+ }
+ str += chr;
+ if (chr == open) {
+ inParens++;
+ }
+ else if (chr == close) {
+ inParens--;
+ }
+ if (inParens == 0) {
+ break;
+ }
+ }
+ i = k;
+ }
+ }
+ if (str !== '') {
+ // @ts-ignore
+ result.at(-1).push(str);
+ }
+ return result;
+}
-export { critical };
+export { critical, isWhiteSpace, splitRule };
//# sourceMappingURL=index.js.map
diff --git a/dist/index.js.map b/dist/index.js.map
index b3e1e46..201a221 100644
--- a/dist/index.js.map
+++ b/dist/index.js.map
@@ -1 +1 @@
-{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import * as playwright from \"playwright\";\nimport {Browser, BrowserContext, BrowserType, ConsoleMessage, devices, LaunchOptions, Page, Request} from \"playwright\";\nimport {basename, dirname, resolve} from \"node:path\";\nimport {readFileSync} from \"node:fs\";\nimport {fontscript} from \"./critical\";\nimport {size} from \"./file\";\nimport type {\n BrowserOptions,\n CriticalCliResult,\n CriticalCliStats,\n CriticalDimension,\n CriticalExtractOptions,\n CriticalOptions,\n CriticalResult,\n FontObject\n} from \"./@types\";\nimport chalk from \"chalk\";\nimport {render, transform} from \"@tbela99/css-parser\";\nimport {createRequire} from 'node:module';\nimport {mkdir, mkdtemp, rm, writeFile} from 'node:fs/promises';\nimport {tmpdir} from 'node:os';\nimport process from \"node:process\";\n\nconst __dirname: string = dirname(new URL(import.meta.url).pathname);\nconst require = createRequire(import.meta.url);\n\nconst script: string = readFileSync(require.resolve('@tbela99/critical/umd'), {encoding: \"utf-8\"});\n\n// @ts-ignore\nconst deviceNames: Array<{\n userAgent: string;\n viewport: any[];\n screen: any[];\n deviceScaleFactor: number;\n isMobile: boolean;\n hasTouch: boolean;\n defaultBrowserType: string;\n}> = Object.values(devices);\n\nasync function sleep(duration: number) {\n\n return new Promise(resolve => setTimeout(resolve, duration + Math.ceil(Math.random() * 10)));\n}\n\nexport async function critical(options: CriticalOptions): Promise;\nexport async function critical(url: string, options: CriticalOptions): Promise\nexport async function critical(url: string | CriticalOptions, options: CriticalOptions = {}): Promise {\n\n if (typeof url === 'object') {\n\n options = url;\n url = options.url;\n }\n\n let html: string = '';\n let fonts: Set = new Set;\n\n const styles: Set = new Set;\n const stats: CriticalCliStats[] = [];\n const browserName: BrowserOptions = (options.randomBrowser ? ['chromium', 'firefox', 'webkit', 'edge', 'chrome'][Math.floor(Math.random() * 5)] : options.browser ?? 'chromium');\n const chromium: BrowserType = (['chromium', 'firefox', 'webkit', 'edge', 'chrome'].includes(browserName) &&\n // @ts-ignore\n playwright[browserName]) ?? playwright.chromium ?? 'chromium';\n\n if (options.input != null) {\n\n const browser: Browser = await chromium.launch({headless: true});\n const context: BrowserContext = await browser.newContext();\n\n const page: Page = await context.newPage();\n\n await page.goto(options.input.startsWith('data:') ? options.input : 'data:text/html;base64,' + Buffer.from(options.input).toString('base64'), {waitUntil: 'networkidle'});\n\n let base: string = options.base ?? 'file://' + process.cwd();\n\n if (!base.endsWith('/')) {\n\n base += '/';\n }\n\n if (!base.match(/^(([a-zA-Z]+:)?\\/)?\\//)) {\n\n base = 'file://' + process.cwd() + '/' + base;\n }\n\n options.input = await page.evaluate((base: string) => {\n\n const baseElement = (document.querySelector('base') ?? document.head.insertBefore(document.createElement('base'), document.head.firstChild)) as HTMLBaseElement;\n baseElement.href = base;\n\n const doctype = document.doctype as DocumentType;\n return `` + '\\n' + document.documentElement.outerHTML\n }, base) as string;\n\n const dir: string = await mkdtemp(tmpdir() + '/');\n\n await writeFile(dir + '/index.html', options.input);\n url = 'file://' + dir + '/index.html';\n\n // @ts-ignore\n process.on('exit', async () => await rm(dir, {recursive: true}));\n // @ts-ignore\n process.on('uncaughtException', async () => await rm(dir, {recursive: true}));\n // @ts-ignore\n process.on('unhandledRejection', async () => await rm(dir, {recursive: true}));\n\n await page.close();\n await context.close();\n await browser.close();\n }\n\n if (['\"', \"'\"].includes(url.charAt(0))) {\n\n // @ts-ignore\n url = url.replace(/^(['\"])([^\\1\\s]+)\\1$/, '$2');\n }\n\n if (!url.match(/^([a-zA-Z]+:)?\\/\\//)) {\n\n url = 'file://' + (url.charAt(0) == '/' ? url : resolve(__dirname + '/' + url));\n }\n\n options = {\n\n headless: true,\n randomBrowser: false,\n fonts: true,\n screenshot: false,\n console: false,\n secure: false,\n filename: '',\n container: false,\n html: false,\n pause: 30,\n verbose: false,\n colorScheme: 'dark',\n output: 'output/', ...options, browser: browserName\n };\n\n let theUrl: URL = new URL(url);\n let filePath: string = options.output + ((options.output).endsWith('/') ? '' : '/') + browserName + (options.browserType != null ? '-' + options.browserType : '') + ('/' + options.colorScheme);\n let shortUrl: string = theUrl.protocol == 'data:' ? 'data.html' : (theUrl.protocol == 'file:' ? basename(theUrl.pathname) : theUrl.protocol + '//' + theUrl.host + theUrl.pathname);\n let dimensions: string | string[] | Array;\n\n if (filePath.slice(-1) != '/') {\n\n filePath += '/';\n }\n\n if (theUrl.host !== '') {\n\n filePath += theUrl.host.replace(':', '@') + '/';\n } else {\n\n filePath += 'local_files/';\n }\n\n if (theUrl.pathname != '/') {\n\n filePath += basename(theUrl.pathname).replace(/\\.[a-z]{1,4}$/, '').replace(/^[^a-zA-Z0-9_-]+/, '').replace(/[^a-zA-Z0-9_-]+/, '-');\n } else {\n\n filePath += 'index'\n }\n\n // @ts-ignore\n filePath = filePath.replace(/[/]+$/, '');\n\n await mkdir(dirname(filePath), {recursive: true});\n\n options.filename = filePath;\n\n if (options.base != null) {\n\n if (!options.base.match(/^([a-z]+:\\/)?\\//)) {\n\n const parts1: string[] = (filePath.endsWith('/') ? filePath.slice(0, -1) : filePath).split('/');\n const parts2: string[] = (options.base.endsWith('/') ? options.base.slice(0, -1) : options.base).split('/');\n\n const result: string[] = [];\n\n parts1.pop();\n\n while (parts1.shift()) {\n\n result.push('..');\n }\n\n result.push(...parts2);\n\n options.base = result.join('/');\n }\n }\n\n if ('dimensions' in options) {\n\n dimensions = >options.dimensions;\n } else {\n\n dimensions = Number.isInteger(options.width) && Number.isInteger(options.height) ? [{\n width: +options.width,\n height: +options.height\n }] : ['1920x1080', '1440x900', '1366x768', '1024x768', '768x1024', '320x480'];\n }\n\n if (typeof dimensions == 'string') {\n\n dimensions = (dimensions).split(/\\s/)\n } else if (!Array.isArray(dimensions)) {\n\n dimensions = [dimensions];\n }\n\n dimensions = dimensions.map((dimension: string | CriticalDimension): CriticalDimension => {\n\n if (typeof dimension == 'string') {\n\n const parts: string[] = dimension.split(/[xX\"']/g);\n\n return {\n\n width: +parts[0],\n height: +parts[1]\n }\n }\n\n return dimension;\n });\n dimensions.sort(() => [-1, 0, 1][Math.floor(3 * Math.random())]);\n\n // @ts-ignore\n for (const dimension of dimensions) {\n\n const launchOptions: LaunchOptions = {\n headless: options.headless,\n bypassCSP: !options.secure,\n defaultViewport: {\n isMobile: true,\n isLandscape: false,\n },\n waitForInitialPage: false,\n args: [],\n ignoreDefaultArgs: ['--enable-automation']\n };\n\n const size: string = ` (${dimension.width}x${dimension.height})`\n\n launchOptions.args = [\n '--test-type',\n '--no-startup-window',\n `--window-size=${(dimension).width},${(dimension).height}`\n ];\n\n if (!options.secure) {\n\n launchOptions.args.push(\n '--disable-web-security',\n '--allow-running-insecure-content',\n '--no-default-browser-check',\n '--ignore-certificate-errors',\n '--disable-site-isolation-trials'\n )\n }\n\n if (options.container) {\n\n launchOptions.args.push(\n \"--disable-gpu\",\n \"--disable-dev-shm-usage\",\n \"--disable-setuid-sandbox\",\n \"--no-sandbox\"\n )\n }\n\n if (options.verbose || options.console) {\n\n console.error(chalk.blue(`[${shortUrl}]> selected browser `) + chalk.green(chromium.name()));\n console.error(chalk.blue(`[${shortUrl}${size}]> set viewport to `) + chalk.green(`${dimension.width}x${dimension.height}`));\n }\n\n let contextData = {};\n\n if (options.browserType != null || options.randomUserAgent || options.randomBrowser) {\n\n contextData = deviceNames.slice().sort(() => [-1, 0, 1][Math.floor(3 * Math.random())]).filter(d => {\n\n if (browserName != d.defaultBrowserType) {\n\n return false;\n }\n\n if (options.browserType != null) {\n\n if (options.browserType == 'mobile') {\n\n return d.isMobile;\n } else {\n\n return !d.isMobile;\n }\n }\n\n return true;\n })[0];\n }\n\n const browser: Browser = await chromium.launch(launchOptions);\n const context: BrowserContext = await browser.newContext({\n ...contextData,\n bypassCSP: !options.secure,\n viewport: dimension\n });\n\n if (options.randomUserAgent) {\n\n // antibot evasion\n await context.addInitScript(() => {\n\n Object.defineProperty(navigator, 'webdriver', {get: () => undefined});\n });\n }\n\n await context.addInitScript(script + ';window.critical=critical;');\n const page: Page = await context.newPage();\n\n try {\n\n await page.emulateMedia({\n colorScheme: options.colorScheme,\n });\n\n if (options.console) {\n\n page.on('console', (message: ConsoleMessage) =>\n // @ts-ignore\n console.error(chalk.yellow(`[${shortUrl}${size}]> ${message.type().replace(/^([a-z])/, (all: string, one: string) => one.toUpperCase())} ${message.text()}`)))\n // @ts-ignore\n .on('pageerror', ({message}) => console.error(chalk.red(`[${shortUrl}${size}]> ${message}`)))\n .on('requestfailed', (request: Request) => {\n\n const failure = request.failure();\n console.error(chalk.red(`[${shortUrl}${size}]> ${failure && failure.errorText} ${request.url()}`))\n });\n }\n\n console.error(chalk.blue(`[${shortUrl}${size}]> open `) + url);\n\n if (options.input != null) {\n\n const dir: string = await mkdtemp(tmpdir() + '/');\n\n await writeFile(dir + '/index.html', options.input);\n url = 'file://' + dir + '/index.html';\n\n // @ts-ignore\n process.on('exit', async () => await rm(dir, {recursive: true}));\n // @ts-ignore\n process.on('uncaughtException', async () => await rm(dir, {recursive: true}));\n // @ts-ignore\n process.on('unhandledRejection', async () => await rm(dir, {recursive: true}));\n }\n\n await page.goto(url, {waitUntil: 'networkidle'});\n\n if (options.screenshot) {\n\n const screenshot: {\n path: string\n } = typeof options.screenshot == 'object' && Object.assign({}, options.screenshot) || {path: typeof options.screenshot == 'string' && options.screenshot || options.filename + '.png' || 'screenshot.png'}\n\n if (dimensions.length > 1) {\n\n screenshot.path = screenshot.path.replace(/\\.([^.]+)$/, `_${dimension.width}x${dimension.height}.\\$1`)\n }\n\n if (options.verbose) {\n\n console.error(chalk.blue(`[${shortUrl}${size}]> generating screenshot at `) + chalk.green(screenshot.path));\n }\n\n await page.screenshot(screenshot);\n }\n\n if (options.verbose) {\n\n console.error(chalk.blue(`[${shortUrl}${size}]> collect critical data`));\n }\n\n const data = await page.evaluate(async (param: { options: CriticalExtractOptions }) => {\n\n // @ts-ignore\n return await critical.extract(param.options).then((result: CriticalResult) => {\n\n if (Array.isArray(result.fonts)) {\n\n // @ts-ignore\n result.fonts = (result.fonts).map((font: FontObject) => JSON.stringify(font));\n }\n\n // @ts-ignore\n if (param.options.verbose) {\n\n console.error(JSON.stringify({result}, null, 1));\n }\n\n return result;\n });\n }, {options});\n\n if (data.styles != null) {\n\n data.styles.forEach((line: string) => styles.add(line));\n data.fonts.forEach((line: string) => fonts.add(line));\n stats.push({width: dimension.width, height: dimension.height, stats: data.stats});\n\n if (options.html != null && html === '') {\n\n html = data.html ?? '';\n }\n }\n\n } catch (error: any) {\n\n console.error(error);\n } finally {\n\n await page.close();\n await context.close();\n await browser.close();\n }\n\n if (options.pause > 0) {\n\n await sleep(options.pause);\n }\n }\n\n let htmlFile: string | undefined = undefined;\n let fontJS: string | undefined = undefined;\n let minCssFile: string | undefined = undefined;\n let rawCssFile: string | undefined = undefined;\n let nestedCssFile: string | undefined = undefined;\n let minNestedCssFile: string | undefined = undefined;\n\n if (options.filename) {\n\n const rawCSS: string = [...styles].join('\\n');\n const {code, unminified}: { code: string; unminified: string } = (await transform(rawCSS).then(result => {\n\n return {code: result.code, unminified: render(result.ast, {minify: false}).code}\n }));\n const {code: nestedCSS, unminified: nestedUnminified}: {\n code: string;\n unminified: string\n } = (await transform(rawCSS, {nestingRules: true}).then(result => {\n\n return {code: result.code, unminified: render(result.ast, {minify: false}).code}\n }));\n\n let cssFile: string = options.filename;\n\n if (cssFile.slice(-4) != '.css') {\n\n cssFile += '.css';\n }\n\n minCssFile = cssFile.slice(0, -4) + '.min.css' as string;\n rawCssFile = cssFile.slice(0, -4) + '.raw.css' as string;\n\n minNestedCssFile = cssFile.slice(0, -4) + '.nested.min.css' as string;\n nestedCssFile = cssFile.slice(0, -4) + '.nested.css' as string;\n\n console.error(chalk.blue(`[${shortUrl}]> writing css at `) + chalk.green(minCssFile + ' [' + size(code.length) + ']'));\n // @ts-ignore\n await writeFile(minCssFile, code);\n\n console.error(chalk.blue(`[${shortUrl}]> writing css at `) + chalk.green(cssFile + ' [' + size(unminified.length) + ']'));\n\n await writeFile(cssFile, unminified);\n\n // @ts-ignore\n await writeFile(rawCssFile, rawCSS);\n\n console.error(chalk.blue(`[${shortUrl}]> writing css at `) + chalk.green(minNestedCssFile + ' [' + size(nestedCSS.length) + ']'));\n // @ts-ignore\n await writeFile(minNestedCssFile, nestedCSS);\n\n console.error(chalk.blue(`[${shortUrl}]> writing css at `) + chalk.green(nestedCssFile + ' [' + size(nestedUnminified.length) + ']'));\n\n await writeFile(nestedCssFile, nestedUnminified);\n\n // @ts-ignore\n await writeFile(rawCssFile, rawCSS);\n }\n\n if (options.html != null && html != null && html !== '') {\n\n const match: RegExpMatchArray | null = html.match(/`);\n }\n\n htmlFile = options.filename + '.html';\n // @ts-ignore\n await writeFile(htmlFile, html);\n }\n\n const fontObjects: Set = >new Set([...fonts].map((font: string) => JSON.parse(font)));\n\n if (options.fonts) {\n\n let fontJS: string = options.filename;\n let data: string = '/* no font found! */';\n\n if (fontJS.slice(-3) != '.js') {\n\n fontJS += '.js';\n }\n\n if (fontObjects.size == 0) {\n\n console.error(chalk.yellow(`[${shortUrl}]> no preload font found`));\n } else {\n\n data = fontscript([...fontObjects]);\n console.error(chalk.blue(`[${shortUrl}]> writing `) + chalk.green(fontObjects.size.toString()) + chalk.blue(` preload font script at `) +\n chalk.green(`${fontJS} [` + size(data.length) + ']'));\n }\n\n // @ts-ignore\n await writeFile(fontJS, data);\n }\n\n return {\n styles: [...styles],\n files: {\n\n html: htmlFile,\n fonts: fontJS,\n css: {\n\n min: minCssFile,\n raw: rawCssFile,\n nested: nestedCssFile,\n minNested: minNestedCssFile\n }\n\n }, fonts: [...fonts], stats, html\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAuBA,MAAM,SAAS,GAAW,OAAO,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI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,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import * as playwright from \"playwright\";\nimport {Browser, BrowserContext, BrowserType, ConsoleMessage, devices, LaunchOptions, Page, Request} from \"playwright\";\nimport {basename, dirname, resolve} from \"node:path\";\nimport {readFileSync} from \"node:fs\";\nimport {fontscript} from \"./critical\";\nimport {size} from \"./file\";\nimport type {\n BrowserOptions,\n CriticalCliResult,\n CriticalCliStats,\n CriticalDimension,\n CriticalExtractOptions,\n CriticalOptions,\n CriticalResult,\n FontObject\n} from \"./@types\";\nimport chalk from \"chalk\";\nimport {AstRule, EnumToken, expand, parse, render, transform, walk} from \"@tbela99/css-parser\";\nimport {createRequire} from 'node:module';\nimport {mkdir, mkdtemp, rm, writeFile} from 'node:fs/promises';\nimport {tmpdir} from 'node:os';\nimport process from \"node:process\";\n\nconst __dirname: string = dirname(new URL(import.meta.url).pathname);\nconst require = createRequire(import.meta.url);\n\nconst script: string = readFileSync(require.resolve('@tbela99/critical/umd'), {encoding: \"utf-8\"});\n\n// @ts-ignore\nconst deviceNames: Array<{\n userAgent: string;\n viewport: any[];\n screen: any[];\n deviceScaleFactor: number;\n isMobile: boolean;\n hasTouch: boolean;\n defaultBrowserType: string;\n}> = Object.values(devices);\n\nasync function sleep(duration: number) {\n\n return new Promise(resolve => setTimeout(resolve, duration + Math.ceil(Math.random() * 10)));\n}\n\nasync function createBrowser(options: CriticalOptions, dimension: CriticalDimension, chromium: BrowserType, browserName: \"chromium\" | \"firefox\" | \"webkit\" | \"edge\" | \"chrome\"): Promise<{\n\n browser: Browser,\n context: BrowserContext,\n page: Page\n}> {\n const launchOptions: LaunchOptions = {\n headless: options.headless,\n bypassCSP: !options.secure,\n defaultViewport: {\n isMobile: true,\n isLandscape: false,\n },\n waitForInitialPage: false,\n args: [],\n ignoreDefaultArgs: ['--enable-automation']\n };\n\n launchOptions.args = [\n '--test-type',\n '--no-startup-window',\n `--window-size=${(dimension).width},${(dimension).height}`\n ];\n\n if (!options.secure) {\n\n launchOptions.args.push(\n '--disable-web-security',\n '--allow-running-insecure-content',\n '--no-default-browser-check',\n '--ignore-certificate-errors',\n '--disable-site-isolation-trials'\n )\n }\n\n if (options.container) {\n\n launchOptions.args.push(\n \"--disable-gpu\",\n \"--disable-dev-shm-usage\",\n \"--disable-setuid-sandbox\",\n \"--no-sandbox\"\n )\n }\n\n let contextData = {};\n\n if (options.browserType != null || options.randomUserAgent || options.randomBrowser) {\n\n contextData = deviceNames.slice().sort(() => [-1, 0, 1][Math.floor(3 * Math.random())]).filter(d => {\n\n if (browserName != d.defaultBrowserType) {\n\n return false;\n }\n\n if (options.browserType != null) {\n\n if (options.browserType == 'mobile') {\n\n return d.isMobile;\n } else {\n\n return !d.isMobile;\n }\n }\n\n return true;\n })[0];\n }\n\n const browser: Browser = await chromium.launch(launchOptions);\n const context: BrowserContext = await browser.newContext({\n ...contextData,\n bypassCSP: !options.secure,\n viewport: dimension\n });\n\n if (options.randomUserAgent) {\n\n // antibot evasion\n await context.addInitScript(() => {\n\n Object.defineProperty(navigator, 'webdriver', {get: () => undefined});\n });\n }\n\n const page: Page = await context.newPage();\n return {browser, context, page};\n}\n\nexport async function critical(options: CriticalOptions): Promise;\nexport async function critical(url: string, options: CriticalOptions): Promise\n\nexport async function critical(url: string | CriticalOptions, options: CriticalOptions = {}): Promise {\n\n if (typeof url === 'object') {\n\n options = url;\n url = options.url;\n }\n\n let html: string = '';\n let fonts: Set = new Set;\n\n const styles: Set = new Set;\n const stats: CriticalCliStats[] = [];\n const browserName: BrowserOptions = (options.randomBrowser ? ['chromium', 'firefox', 'webkit', 'edge', 'chrome'][Math.floor(Math.random() * 5)] : options.browser ?? 'chromium');\n const chromium: BrowserType = (['chromium', 'firefox', 'webkit', 'edge', 'chrome'].includes(browserName) &&\n // @ts-ignore\n playwright[browserName]) ?? playwright.chromium ?? 'chromium';\n\n if (options.input != null) {\n\n const browser: Browser = await chromium.launch({headless: true});\n const context: BrowserContext = await browser.newContext();\n\n const page: Page = await context.newPage();\n\n await page.goto(options.input.startsWith('data:') ? options.input : 'data:text/html;base64,' + Buffer.from(options.input).toString('base64'), {waitUntil: 'networkidle'});\n\n let base: string = options.base ?? 'file://' + process.cwd();\n\n if (!base.endsWith('/')) {\n\n base += '/';\n }\n\n if (!base.match(/^(([a-zA-Z]+:)?\\/)?\\//)) {\n\n base = 'file://' + process.cwd() + '/' + base;\n }\n\n options.input = await page.evaluate((base: string) => {\n\n const baseElement = (document.querySelector('base') ?? document.head.insertBefore(document.createElement('base'), document.head.firstChild)) as HTMLBaseElement;\n baseElement.href = base;\n\n const doctype = document.doctype as DocumentType;\n return `` + '\\n' + document.documentElement.outerHTML\n }, base) as string;\n\n const dir: string = await mkdtemp(tmpdir() + '/');\n\n await writeFile(dir + '/index.html', options.input);\n url = 'file://' + dir + '/index.html';\n\n // @ts-ignore\n process.on('exit', async () => await rm(dir, {recursive: true, force: true}));\n // @ts-ignore\n process.on('uncaughtException', async () => await rm(dir, {recursive: true, force: true}));\n // @ts-ignore\n process.on('unhandledRejection', async () => await rm(dir, {recursive: true, force: true}));\n\n await page.close();\n await context.close();\n await browser.close();\n }\n\n if (['\"', \"'\"].includes(url.charAt(0))) {\n\n // @ts-ignore\n url = url.replace(/^(['\"])([^\\1\\s]+)\\1$/, '$2');\n }\n\n if (!url.match(/^([a-zA-Z]+:)?\\/\\//)) {\n\n url = 'file://' + (url.charAt(0) == '/' ? url : resolve(__dirname + '/' + url));\n }\n\n options = {\n\n headless: true,\n randomBrowser: false,\n fonts: true,\n screenshot: false,\n console: false,\n secure: false,\n filename: '',\n container: false,\n html: false,\n pause: 30,\n verbose: false,\n colorScheme: 'dark',\n output: 'output/', ...options, browser: browserName\n };\n\n let theUrl: URL = new URL(url);\n let filePath: string = options.output + ((options.output).endsWith('/') ? '' : '/') + browserName + (options.browserType != null ? '-' + options.browserType : '') + ('/' + options.colorScheme);\n let shortUrl: string = theUrl.protocol == 'data:' ? 'data.html' : (theUrl.protocol == 'file:' ? basename(theUrl.pathname) : theUrl.protocol + '//' + theUrl.host + theUrl.pathname);\n let dimensions: string | string[] | Array;\n\n if (filePath.slice(-1) != '/') {\n\n filePath += '/';\n }\n\n if (theUrl.host !== '') {\n\n filePath += theUrl.host.replace(':', '@') + '/';\n } else {\n\n filePath += 'local_files/';\n }\n\n if (theUrl.pathname != '/') {\n\n filePath += basename(theUrl.pathname).replace(/\\.[a-z]{1,4}$/, '').replace(/^[^a-zA-Z0-9_-]+/, '').replace(/[^a-zA-Z0-9_-]+/, '-');\n } else {\n\n filePath += 'index'\n }\n\n // @ts-ignore\n filePath = filePath.replace(/[/]+$/, '');\n\n await mkdir(dirname(filePath), {recursive: true});\n\n options.filename = filePath;\n\n if (options.base != null) {\n\n if (!options.base.match(/^([a-z]+:\\/)?\\//)) {\n\n const parts1: string[] = (filePath.endsWith('/') ? filePath.slice(0, -1) : filePath).split('/');\n const parts2: string[] = (options.base.endsWith('/') ? options.base.slice(0, -1) : options.base).split('/');\n\n const result: string[] = [];\n\n parts1.pop();\n\n while (parts1.shift()) {\n\n result.push('..');\n }\n\n result.push(...parts2);\n\n options.base = result.join('/');\n }\n }\n\n if ('dimensions' in options) {\n\n dimensions = >options.dimensions;\n } else {\n\n dimensions = Number.isInteger(options.width) && Number.isInteger(options.height) ? [{\n width: +options.width,\n height: +options.height\n }] : ['1920x1080', '1440x900', '1366x768', '1024x768', '768x1024', '320x480'];\n }\n\n if (dimensions.length == 0) {\n\n throw new Error(`No dimensions specified`);\n }\n\n if (typeof dimensions == 'string') {\n\n dimensions = (dimensions).split(/\\s/)\n } else if (!Array.isArray(dimensions)) {\n\n dimensions = [dimensions];\n }\n\n dimensions = dimensions.map((dimension: string | CriticalDimension): CriticalDimension => {\n\n if (typeof dimension == 'string') {\n\n const parts: string[] = dimension.split(/[xX\"']/g);\n\n return {\n\n width: +parts[0],\n height: +parts[1]\n }\n }\n\n return dimension;\n });\n dimensions.sort(() => [-1, 0, 1][Math.floor(3 * Math.random())]);\n\n // @ts-ignore\n for (const dimension of dimensions) {\n\n if (options.verbose || options.console) {\n\n console.error(chalk.blue(`[${shortUrl}]> selected browser `) + chalk.green(chromium.name()));\n console.error(chalk.blue(`[${shortUrl}${size}]> set viewport to `) + chalk.green(`${dimension.width}x${dimension.height}`));\n }\n\n const {browser, context, page} = await createBrowser(options, dimension, chromium, browserName);\n\n try {\n\n const size: string = ` (${dimension.width}x${dimension.height})`;\n\n await context.addInitScript(script + ';window.critical=critical;');\n await page.emulateMedia({\n colorScheme: options.colorScheme,\n });\n\n if (options.console) {\n\n page.on('console', (message: ConsoleMessage) =>\n // @ts-ignore\n console.error(chalk.yellow(`[${shortUrl}${size}]> ${message.type().replace(/^([a-z])/, (all: string, one: string) => one.toUpperCase())} ${message.text()}`)))\n // @ts-ignore\n .on('pageerror', ({message}) => console.error(chalk.red(`[${shortUrl}${size}]> ${message}`)))\n .on('requestfailed', (request: Request) => {\n\n const failure = request.failure();\n console.error(chalk.red(`[${shortUrl}${size}]> ${failure && failure.errorText} ${request.url()}`))\n });\n }\n\n console.error(chalk.blue(`[${shortUrl}${size}]> open `) + url);\n\n if (options.input != null) {\n\n const dir: string = await mkdtemp(tmpdir() + '/');\n\n await writeFile(dir + '/index.html', options.input);\n url = 'file://' + dir + '/index.html';\n\n // @ts-ignore\n process.on('exit', async () => await rm(dir, {recursive: true}));\n // @ts-ignore\n process.on('uncaughtException', async () => await rm(dir, {recursive: true}));\n // @ts-ignore\n process.on('unhandledRejection', async () => await rm(dir, {recursive: true}));\n }\n\n await page.goto(url, {waitUntil: 'networkidle'});\n\n if (options.screenshot) {\n\n const screenshot: {\n path: string\n } = typeof options.screenshot == 'object' && Object.assign({}, options.screenshot) || {path: typeof options.screenshot == 'string' && options.screenshot || options.filename + '.png' || 'screenshot.png'}\n\n if (dimensions.length > 1) {\n\n screenshot.path = screenshot.path.replace(/\\.([^.]+)$/, `_${dimension.width}x${dimension.height}.\\$1`)\n }\n\n if (options.verbose) {\n\n console.error(chalk.blue(`[${shortUrl}${size}]> generating screenshot at `) + chalk.green(screenshot.path));\n }\n\n await page.screenshot(screenshot);\n }\n\n if (options.verbose) {\n\n console.error(chalk.blue(`[${shortUrl}${size}]> collect critical data`));\n }\n\n const data = await page.evaluate(async (param: { options: CriticalExtractOptions }) => {\n\n // @ts-ignore\n return await critical.extract(param.options).then((result: CriticalResult) => {\n\n if (Array.isArray(result.fonts)) {\n\n // @ts-ignore\n result.fonts = (result.fonts).map((font: FontObject) => JSON.stringify(font));\n }\n\n // @ts-ignore\n if (param.options.verbose) {\n\n console.error(JSON.stringify({result}, null, 1));\n }\n\n return result;\n });\n }, {options});\n\n if (data.styles != null) {\n\n data.styles.forEach((line: string) => styles.add(line));\n data.fonts.forEach((line: string) => fonts.add(line));\n stats.push({width: dimension.width, height: dimension.height, stats: data.stats});\n\n if (options.html != null && html === '') {\n\n html = data.html ?? '';\n }\n }\n\n } catch (error: any) {\n\n console.error(error);\n } finally {\n\n await page.close();\n await context.close();\n await browser.close();\n }\n\n if (options.pause > 0) {\n\n await sleep(options.pause);\n }\n }\n\n let htmlFile: string | undefined = undefined;\n let fontJS: string | undefined = undefined;\n let minCssFile: string | undefined = undefined;\n let rawCssFile: string | undefined = undefined;\n let nestedCssFile: string | undefined = undefined;\n let minNestedCssFile: string | undefined = undefined;\n\n if (options.filename != null) {\n\n let rawCSS: string = [...styles].join('\\n');\n let css: string = rawCSS;\n\n if (options.advanced) {\n\n const {browser, context, page} = await createBrowser(options, dimensions[0], chromium, browserName);\n\n await page.emulateMedia({\n colorScheme: options.colorScheme,\n });\n\n const dimension = dimensions[0];\n const size: string = ` (${dimension.width}x${dimension.height})`;\n\n console.error(chalk.blue(`[${shortUrl}${size}]> open `) + url);\n\n if (options.input != null) {\n\n const dir: string = await mkdtemp(tmpdir() + '/');\n\n await writeFile(dir + '/index.html', options.input);\n url = 'file://' + dir + '/index.html';\n\n // @ts-ignore\n process.on('exit', async () => await rm(dir, {recursive: true}));\n // @ts-ignore\n process.on('uncaughtException', async () => await rm(dir, {recursive: true, force: true}));\n // @ts-ignore\n process.on('unhandledRejection', async () => await rm(dir, {recursive: true, force: true}));\n }\n\n await page.goto(url, {waitUntil: 'networkidle'});\n\n const result = await parse(rawCSS, {minify: false}).then(result => Object.assign(result, {ast: expand(result.ast)}));\n\n for (const {node, parent} of walk(result.ast)) {\n\n if (node.typ == EnumToken.RuleNodeType) {\n\n const filtered = await Promise.all(splitRule((node as AstRule).sel).map(async sel => {\n\n const rule: string[] = sel.filter(sel => !sel.match(/::?((before)|(after))/));\n\n if (rule.length == 0) {\n return sel;\n }\n\n return await page.evaluate((param: {\n sel: string\n }): boolean => document.querySelector(param.sel) != null, {sel: rule.join('')}) ? sel : [];\n })).then((r: string[][]) => r.filter((r: string[]): boolean => r.length > 0));\n\n if (filtered.length == 0) {\n\n parent!.chi.splice(parent!.chi.indexOf(node), 1);\n } else {\n\n (node as AstRule).sel = filtered.reduce((acc, curr) => acc + (acc.length == 0 ? '' : ',') + curr.join(''), '');\n }\n }\n }\n\n css = render(result.ast, {minify: false, expandNestingRules: true}).code;\n\n await page.close();\n await context.close();\n await browser.close();\n }\n\n const {code, unminified}: {\n code: string;\n unminified: string\n } = (await transform(css, {expandNestingRules: true}).then(result => {\n\n return {code: result.code, unminified: render(result.ast, {minify: false, expandNestingRules: true}).code}\n }));\n\n const {code: nestedCSS, unminified: nestedUnminified}: {\n code: string;\n unminified: string\n } = (await transform(css, {nestingRules: true}).then(result => {\n\n return {code: result.code, unminified: render(result.ast, {minify: false}).code}\n }));\n\n let cssFile: string = options.filename;\n\n if (cssFile.slice(-4) != '.css') {\n\n cssFile += '.css';\n }\n\n minCssFile = cssFile.slice(0, -4) + '.min.css' as string;\n rawCssFile = cssFile.slice(0, -4) + '.raw.css' as string;\n\n minNestedCssFile = cssFile.slice(0, -4) + '.nested.min.css' as string;\n nestedCssFile = cssFile.slice(0, -4) + '.nested.css' as string;\n\n console.error(chalk.blue(`[${shortUrl}]> writing css at `) + chalk.green(minCssFile + ' [' + size(code.length) + ']'));\n\n // @ts-ignore\n await writeFile(minCssFile, code);\n\n console.error(chalk.blue(`[${shortUrl}]> writing css at `) + chalk.green(cssFile + ' [' + size(unminified.length) + ']'));\n\n await writeFile(cssFile, unminified);\n\n // @ts-ignore\n await writeFile(rawCssFile, rawCSS);\n\n console.error(chalk.blue(`[${shortUrl}]> writing css at `) + chalk.green(minNestedCssFile + ' [' + size(nestedCSS.length) + ']'));\n // @ts-ignore\n await writeFile(minNestedCssFile, nestedCSS);\n\n console.error(chalk.blue(`[${shortUrl}]> writing css at `) + chalk.green(nestedCssFile + ' [' + size(nestedUnminified.length) + ']'));\n\n await writeFile(nestedCssFile, nestedUnminified);\n\n // @ts-ignore\n await writeFile(rawCssFile, rawCSS);\n\n if (options.html != null && html != null && html !== '') {\n\n const match: RegExpMatchArray | null = html.match(/`);\n }\n\n htmlFile = options.filename + '.html';\n // @ts-ignore\n await writeFile(htmlFile, html);\n }\n }\n\n const fontObjects: Set = >new Set([...fonts].map((font: string) => JSON.parse(font)));\n\n if (options.fonts) {\n\n let fontJS: string = options.filename;\n let data: string = '/* no font found! */';\n\n if (fontJS.slice(-3) != '.js') {\n\n fontJS += '.js';\n }\n\n if (fontObjects.size == 0) {\n\n console.error(chalk.yellow(`[${shortUrl}]> no preload font found`));\n } else {\n\n data = fontscript([...fontObjects]);\n console.error(chalk.blue(`[${shortUrl}]> writing `) + chalk.green(fontObjects.size.toString()) + chalk.blue(` preload font script at `) +\n chalk.green(`${fontJS} [` + size(data.length) + ']'));\n }\n\n // @ts-ignore\n await writeFile(fontJS, data);\n }\n\n return {\n styles: [...styles],\n files: {\n\n html: htmlFile,\n fonts: fontJS,\n css: {\n\n min: minCssFile,\n raw: rawCssFile,\n nested: nestedCssFile,\n minNested: minNestedCssFile\n }\n\n }, fonts: [...fonts], stats, html\n };\n}\n\nexport function isWhiteSpace(codepoint: number): boolean {\n\n return codepoint == 0x9 || codepoint == 0x20 ||\n // isNewLine\n codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;\n}\n\nexport function splitRule(buffer: string): string[][] {\n\n const result: string[][] = [[]];\n let str: string = '';\n\n for (let i = 0; i < buffer.length; i++) {\n\n let chr: string = buffer.charAt(i);\n\n if (isWhiteSpace(chr.charCodeAt(0))) {\n\n let k: number = i;\n\n while (k + 1 < buffer.length) {\n\n if (isWhiteSpace(buffer[k + 1].charCodeAt(0))) {\n\n k++;\n continue;\n }\n\n break;\n }\n\n if (str !== '') {\n\n // @ts-ignore\n result.at(-1).push(str);\n str = '';\n }\n\n // @ts-ignore\n if (result.at(-1).length > 0) {\n\n // @ts-ignore\n result.at(-1).push(' ');\n }\n\n i = k;\n continue;\n }\n\n if (chr == ',') {\n\n if (str !== '') {\n // @ts-ignore\n result.at(-1).push(str);\n str = '';\n }\n\n result.push([]);\n continue;\n }\n\n if (chr == ':') {\n\n if (str !== '') {\n // @ts-ignore\n result.at(-1).push(str);\n str = '';\n }\n\n if (buffer.charAt(i + 1) == ':') {\n\n chr += buffer.charAt(++i);\n }\n\n str += chr;\n continue;\n }\n\n str += chr;\n if (chr == '\\\\') {\n\n str += buffer.charAt(++i);\n continue;\n }\n\n if (chr == '\"' || chr == \"'\") {\n\n let k = i;\n while (++k < buffer.length) {\n chr = buffer.charAt(k);\n str += chr;\n if (chr == '//') {\n str += buffer.charAt(++k);\n continue;\n }\n if (chr == buffer.charAt(i)) {\n break;\n }\n }\n continue;\n }\n\n if (chr == '(' || chr == '[') {\n const open = chr;\n const close = chr == '(' ? ')' : ']';\n let inParens = 1;\n let k = i;\n while (++k < buffer.length) {\n chr = buffer.charAt(k);\n if (chr == '\\\\') {\n str += buffer.slice(k, k + 2);\n k++;\n continue;\n }\n str += chr;\n if (chr == open) {\n inParens++;\n } else if (chr == close) {\n inParens--;\n }\n if (inParens == 0) {\n break;\n }\n }\n i = k;\n }\n }\n\n if (str !== '') {\n // @ts-ignore\n result.at(-1).push(str);\n }\n\n return result;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAuBA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AAE,EAAE;;QAEZ,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAC3B;AAED,IAAA,OAAO,MAAM,CAAC;AAClB;;;;"}
\ No newline at end of file
diff --git a/src/@types/index.d.ts b/src/@types/index.d.ts
index 535f06b..5fa55a5 100644
--- a/src/@types/index.d.ts
+++ b/src/@types/index.d.ts
@@ -18,6 +18,7 @@ export interface CriticalOptions {
url?: string;
input?: string;
headless?: boolean;
+ advanced?: boolean;
browser?: BrowserOptions;
browserType?: 'mobile' | 'desktop' | 'default';
base?: string;
@@ -44,6 +45,7 @@ export interface CriticalExtractOptions {
html?: boolean;
base?: string;
fonts?: boolean;
+ advanced?: boolean;
signal?: AbortSignal;
}
diff --git a/src/critical/extract.ts b/src/critical/extract.ts
index be57bd7..6f602eb 100644
--- a/src/critical/extract.ts
+++ b/src/critical/extract.ts
@@ -14,12 +14,12 @@ export async function extract(options: CriticalExtractOptions = {}) {
const document: Document = window.document;
const location: Location = window.location;
const styles: Set = new Set;
- const excluded = ['all', 'print', ''];
+ const excluded: string[] = ['all', 'print', ''];
const allStylesheets: MatchCSSStyleSheet[] = [];
// Get a list of all the elements in the view.
- const height = window.innerHeight;
- const walker = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, {acceptNode: () => NodeFilter.SHOW_ELEMENT});
+ const height: number = window.innerHeight;
+ const walker: NodeIterator = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, {acceptNode: () => NodeFilter.SHOW_ELEMENT});
const fonts: Set = new Set;
const fontFamilies: Set = new Set;
@@ -45,7 +45,6 @@ export async function extract(options: CriticalExtractOptions = {}) {
try {
-
// @ts-ignore
rules = (rule).cssRules ?? (rule).rules;
@@ -205,7 +204,7 @@ export async function extract(options: CriticalExtractOptions = {}) {
// @ts-ignore
rule = allStylesheets[k].rule;
- let fileUpdate = false;
+ let fileUpdate: boolean = false;
// @ts-ignore
if (!files.has(rule.parentStyleSheet)) {
@@ -247,6 +246,9 @@ export async function extract(options: CriticalExtractOptions = {}) {
file = (files.get(rule.parentStyleSheet)).file;
css = rule.cssText;
+ // @ts-ignore
+ console.error({sel: rule.selectorText, css});
+
if (file !== 'inline') {
// resolve url()
@@ -296,7 +298,7 @@ export async function extract(options: CriticalExtractOptions = {}) {
if (rule.parentStyleSheet) {
- let media = rule.parentStyleSheet.media.mediaText;
+ let media: string = rule.parentStyleSheet.media.mediaText;
if (media === 'print') {
@@ -404,7 +406,6 @@ export async function extract(options: CriticalExtractOptions = {}) {
return {
name: entry.name,
-
duration: (entry.duration / 1000).toFixed(3) + 's'
}
});
@@ -495,7 +496,7 @@ export async function extract(options: CriticalExtractOptions = {}) {
if ((result.fonts).length > 0) {
- const script = document.createElement('script');
+ const script: HTMLScriptElement = document.createElement('script');
script.textContent = fontscript(result.fonts);
document.head.append(script);
}
@@ -511,4 +512,4 @@ export async function extract(options: CriticalExtractOptions = {}) {
}
return result;
-}
\ No newline at end of file
+}
diff --git a/src/index.ts b/src/index.ts
index fbd5ece..931cef8 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -15,7 +15,7 @@ import type {
FontObject
} from "./@types";
import chalk from "chalk";
-import {render, transform} from "@tbela99/css-parser";
+import {AstRule, EnumToken, expand, parse, render, transform, walk} from "@tbela99/css-parser";
import {createRequire} from 'node:module';
import {mkdir, mkdtemp, rm, writeFile} from 'node:fs/promises';
import {tmpdir} from 'node:os';
@@ -42,8 +42,100 @@ async function sleep(duration: number) {
return new Promise(resolve => setTimeout(resolve, duration + Math.ceil(Math.random() * 10)));
}
+async function createBrowser(options: CriticalOptions, dimension: CriticalDimension, chromium: BrowserType, browserName: "chromium" | "firefox" | "webkit" | "edge" | "chrome"): Promise<{
+
+ browser: Browser,
+ context: BrowserContext,
+ page: Page
+}> {
+ const launchOptions: LaunchOptions = {
+ headless: options.headless,
+ bypassCSP: !options.secure,
+ defaultViewport: {
+ isMobile: true,
+ isLandscape: false,
+ },
+ waitForInitialPage: false,
+ args: [],
+ ignoreDefaultArgs: ['--enable-automation']
+ };
+
+ launchOptions.args = [
+ '--test-type',
+ '--no-startup-window',
+ `--window-size=${(dimension).width},${(dimension).height}`
+ ];
+
+ if (!options.secure) {
+
+ launchOptions.args.push(
+ '--disable-web-security',
+ '--allow-running-insecure-content',
+ '--no-default-browser-check',
+ '--ignore-certificate-errors',
+ '--disable-site-isolation-trials'
+ )
+ }
+
+ if (options.container) {
+
+ launchOptions.args.push(
+ "--disable-gpu",
+ "--disable-dev-shm-usage",
+ "--disable-setuid-sandbox",
+ "--no-sandbox"
+ )
+ }
+
+ let contextData = {};
+
+ if (options.browserType != null || options.randomUserAgent || options.randomBrowser) {
+
+ contextData = deviceNames.slice().sort(() => [-1, 0, 1][Math.floor(3 * Math.random())]).filter(d => {
+
+ if (browserName != d.defaultBrowserType) {
+
+ return false;
+ }
+
+ if (options.browserType != null) {
+
+ if (options.browserType == 'mobile') {
+
+ return d.isMobile;
+ } else {
+
+ return !d.isMobile;
+ }
+ }
+
+ return true;
+ })[0];
+ }
+
+ const browser: Browser = await chromium.launch(launchOptions);
+ const context: BrowserContext = await browser.newContext({
+ ...contextData,
+ bypassCSP: !options.secure,
+ viewport: dimension
+ });
+
+ if (options.randomUserAgent) {
+
+ // antibot evasion
+ await context.addInitScript(() => {
+
+ Object.defineProperty(navigator, 'webdriver', {get: () => undefined});
+ });
+ }
+
+ const page: Page = await context.newPage();
+ return {browser, context, page};
+}
+
export async function critical(options: CriticalOptions): Promise;
export async function critical(url: string, options: CriticalOptions): Promise
+
export async function critical(url: string | CriticalOptions, options: CriticalOptions = {}): Promise {
if (typeof url === 'object') {
@@ -103,11 +195,11 @@ export async function critical(url: string | CriticalOptions, options: CriticalO
url = 'file://' + dir + '/index.html';
// @ts-ignore
- process.on('exit', async () => await rm(dir, {recursive: true}));
+ process.on('exit', async () => await rm(dir, {recursive: true, force: true}));
// @ts-ignore
- process.on('uncaughtException', async () => await rm(dir, {recursive: true}));
+ process.on('uncaughtException', async () => await rm(dir, {recursive: true, force: true}));
// @ts-ignore
- process.on('unhandledRejection', async () => await rm(dir, {recursive: true}));
+ process.on('unhandledRejection', async () => await rm(dir, {recursive: true, force: true}));
await page.close();
await context.close();
@@ -208,6 +300,11 @@ export async function critical(url: string | CriticalOptions, options: CriticalO
}] : ['1920x1080', '1440x900', '1366x768', '1024x768', '768x1024', '320x480'];
}
+ if (dimensions.length == 0) {
+
+ throw new Error(`No dimensions specified`);
+ }
+
if (typeof dimensions == 'string') {
dimensions = (dimensions).split(/\s/)
@@ -236,100 +333,19 @@ export async function critical(url: string | CriticalOptions, options: CriticalO
// @ts-ignore
for (const dimension of dimensions) {
- const launchOptions: LaunchOptions = {
- headless: options.headless,
- bypassCSP: !options.secure,
- defaultViewport: {
- isMobile: true,
- isLandscape: false,
- },
- waitForInitialPage: false,
- args: [],
- ignoreDefaultArgs: ['--enable-automation']
- };
-
- const size: string = ` (${dimension.width}x${dimension.height})`
-
- launchOptions.args = [
- '--test-type',
- '--no-startup-window',
- `--window-size=${(dimension).width},${(dimension).height}`
- ];
-
- if (!options.secure) {
-
- launchOptions.args.push(
- '--disable-web-security',
- '--allow-running-insecure-content',
- '--no-default-browser-check',
- '--ignore-certificate-errors',
- '--disable-site-isolation-trials'
- )
- }
-
- if (options.container) {
-
- launchOptions.args.push(
- "--disable-gpu",
- "--disable-dev-shm-usage",
- "--disable-setuid-sandbox",
- "--no-sandbox"
- )
- }
-
if (options.verbose || options.console) {
console.error(chalk.blue(`[${shortUrl}]> selected browser `) + chalk.green(chromium.name()));
console.error(chalk.blue(`[${shortUrl}${size}]> set viewport to `) + chalk.green(`${dimension.width}x${dimension.height}`));
}
- let contextData = {};
-
- if (options.browserType != null || options.randomUserAgent || options.randomBrowser) {
-
- contextData = deviceNames.slice().sort(() => [-1, 0, 1][Math.floor(3 * Math.random())]).filter(d => {
-
- if (browserName != d.defaultBrowserType) {
-
- return false;
- }
-
- if (options.browserType != null) {
-
- if (options.browserType == 'mobile') {
-
- return d.isMobile;
- } else {
-
- return !d.isMobile;
- }
- }
-
- return true;
- })[0];
- }
-
- const browser: Browser = await chromium.launch(launchOptions);
- const context: BrowserContext = await browser.newContext({
- ...contextData,
- bypassCSP: !options.secure,
- viewport: dimension
- });
-
- if (options.randomUserAgent) {
-
- // antibot evasion
- await context.addInitScript(() => {
-
- Object.defineProperty(navigator, 'webdriver', {get: () => undefined});
- });
- }
-
- await context.addInitScript(script + ';window.critical=critical;');
- const page: Page = await context.newPage();
+ const {browser, context, page} = await createBrowser(options, dimension, chromium, browserName);
try {
+ const size: string = ` (${dimension.width}x${dimension.height})`;
+
+ await context.addInitScript(script + ';window.critical=critical;');
await page.emulateMedia({
colorScheme: options.colorScheme,
});
@@ -447,17 +463,89 @@ export async function critical(url: string | CriticalOptions, options: CriticalO
let nestedCssFile: string | undefined = undefined;
let minNestedCssFile: string | undefined = undefined;
- if (options.filename) {
+ if (options.filename != null) {
- const rawCSS: string = [...styles].join('\n');
- const {code, unminified}: { code: string; unminified: string } = (await transform(rawCSS).then(result => {
+ let rawCSS: string = [...styles].join('\n');
+ let css: string = rawCSS;
- return {code: result.code, unminified: render(result.ast, {minify: false}).code}
+ if (options.advanced) {
+
+ const {browser, context, page} = await createBrowser(options, dimensions[0], chromium, browserName);
+
+ await page.emulateMedia({
+ colorScheme: options.colorScheme,
+ });
+
+ const dimension = dimensions[0];
+ const size: string = ` (${dimension.width}x${dimension.height})`;
+
+ console.error(chalk.blue(`[${shortUrl}${size}]> open `) + url);
+
+ if (options.input != null) {
+
+ const dir: string = await mkdtemp(tmpdir() + '/');
+
+ await writeFile(dir + '/index.html', options.input);
+ url = 'file://' + dir + '/index.html';
+
+ // @ts-ignore
+ process.on('exit', async () => await rm(dir, {recursive: true}));
+ // @ts-ignore
+ process.on('uncaughtException', async () => await rm(dir, {recursive: true, force: true}));
+ // @ts-ignore
+ process.on('unhandledRejection', async () => await rm(dir, {recursive: true, force: true}));
+ }
+
+ await page.goto(url, {waitUntil: 'networkidle'});
+
+ const result = await parse(rawCSS, {minify: false}).then(result => Object.assign(result, {ast: expand(result.ast)}));
+
+ for (const {node, parent} of walk(result.ast)) {
+
+ if (node.typ == EnumToken.RuleNodeType) {
+
+ const filtered = await Promise.all(splitRule((node as AstRule).sel).map(async sel => {
+
+ const rule: string[] = sel.filter(sel => !sel.match(/::?((before)|(after))/));
+
+ if (rule.length == 0) {
+ return sel;
+ }
+
+ return await page.evaluate((param: {
+ sel: string
+ }): boolean => document.querySelector(param.sel) != null, {sel: rule.join('')}) ? sel : [];
+ })).then((r: string[][]) => r.filter((r: string[]): boolean => r.length > 0));
+
+ if (filtered.length == 0) {
+
+ parent!.chi.splice(parent!.chi.indexOf(node), 1);
+ } else {
+
+ (node as AstRule).sel = filtered.reduce((acc, curr) => acc + (acc.length == 0 ? '' : ',') + curr.join(''), '');
+ }
+ }
+ }
+
+ css = render(result.ast, {minify: false, expandNestingRules: true}).code;
+
+ await page.close();
+ await context.close();
+ await browser.close();
+ }
+
+ const {code, unminified}: {
+ code: string;
+ unminified: string
+ } = (await transform(css, {expandNestingRules: true}).then(result => {
+
+ return {code: result.code, unminified: render(result.ast, {minify: false, expandNestingRules: true}).code}
}));
+
const {code: nestedCSS, unminified: nestedUnminified}: {
code: string;
unminified: string
- } = (await transform(rawCSS, {nestingRules: true}).then(result => {
+ } = (await transform(css, {nestingRules: true}).then(result => {
return {code: result.code, unminified: render(result.ast, {minify: false}).code}
}));
@@ -476,6 +564,7 @@ export async function critical(url: string | CriticalOptions, options: CriticalO
nestedCssFile = cssFile.slice(0, -4) + '.nested.css' as string;
console.error(chalk.blue(`[${shortUrl}]> writing css at `) + chalk.green(minCssFile + ' [' + size(code.length) + ']'));
+
// @ts-ignore
await writeFile(minCssFile, code);
@@ -496,20 +585,20 @@ export async function critical(url: string | CriticalOptions, options: CriticalO
// @ts-ignore
await writeFile(rawCssFile, rawCSS);
- }
- if (options.html != null && html != null && html !== '') {
+ if (options.html != null && html != null && html !== '') {
- const match: RegExpMatchArray | null = html.match(/`);
- }
+ html = html.replace(match[0], ``);
+ }
- htmlFile = options.filename + '.html';
- // @ts-ignore
- await writeFile(htmlFile, html);
+ htmlFile = options.filename + '.html';
+ // @ts-ignore
+ await writeFile(htmlFile, html);
+ }
}
const fontObjects: Set = >new Set([...fonts].map((font: string) => JSON.parse(font)));
@@ -555,3 +644,139 @@ export async function critical(url: string | CriticalOptions, options: CriticalO
}, fonts: [...fonts], stats, html
};
}
+
+export function isWhiteSpace(codepoint: number): boolean {
+
+ return codepoint == 0x9 || codepoint == 0x20 ||
+ // isNewLine
+ codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;
+}
+
+export function splitRule(buffer: string): string[][] {
+
+ const result: string[][] = [[]];
+ let str: string = '';
+
+ for (let i = 0; i < buffer.length; i++) {
+
+ let chr: string = buffer.charAt(i);
+
+ if (isWhiteSpace(chr.charCodeAt(0))) {
+
+ let k: number = i;
+
+ while (k + 1 < buffer.length) {
+
+ if (isWhiteSpace(buffer[k + 1].charCodeAt(0))) {
+
+ k++;
+ continue;
+ }
+
+ break;
+ }
+
+ if (str !== '') {
+
+ // @ts-ignore
+ result.at(-1).push(str);
+ str = '';
+ }
+
+ // @ts-ignore
+ if (result.at(-1).length > 0) {
+
+ // @ts-ignore
+ result.at(-1).push(' ');
+ }
+
+ i = k;
+ continue;
+ }
+
+ if (chr == ',') {
+
+ if (str !== '') {
+ // @ts-ignore
+ result.at(-1).push(str);
+ str = '';
+ }
+
+ result.push([]);
+ continue;
+ }
+
+ if (chr == ':') {
+
+ if (str !== '') {
+ // @ts-ignore
+ result.at(-1).push(str);
+ str = '';
+ }
+
+ if (buffer.charAt(i + 1) == ':') {
+
+ chr += buffer.charAt(++i);
+ }
+
+ str += chr;
+ continue;
+ }
+
+ str += chr;
+ if (chr == '\\') {
+
+ str += buffer.charAt(++i);
+ continue;
+ }
+
+ if (chr == '"' || chr == "'") {
+
+ let k = i;
+ while (++k < buffer.length) {
+ chr = buffer.charAt(k);
+ str += chr;
+ if (chr == '//') {
+ str += buffer.charAt(++k);
+ continue;
+ }
+ if (chr == buffer.charAt(i)) {
+ break;
+ }
+ }
+ continue;
+ }
+
+ if (chr == '(' || chr == '[') {
+ const open = chr;
+ const close = chr == '(' ? ')' : ']';
+ let inParens = 1;
+ let k = i;
+ while (++k < buffer.length) {
+ chr = buffer.charAt(k);
+ if (chr == '\\') {
+ str += buffer.slice(k, k + 2);
+ k++;
+ continue;
+ }
+ str += chr;
+ if (chr == open) {
+ inParens++;
+ } else if (chr == close) {
+ inParens--;
+ }
+ if (inParens == 0) {
+ break;
+ }
+ }
+ i = k;
+ }
+ }
+
+ if (str !== '') {
+ // @ts-ignore
+ result.at(-1).push(str);
+ }
+
+ return result;
+}