{"version":3,"sources":["../../src/prerender/static.ts","../../src/frameworks/webpack.ts"],"names":["glob"],"mappings":";;;;;;;;;;AAAA,uBAAiB;AAEjB,OAAO,QAAQ;AACf,SAAS,gBAAgB;AACzB,OAAO,UAAU;AAejB,eAAsB,gBAAgB,SAAgC;AACrE,QAAM,EAAE,OAAO,IAAI;AACnB,QAAM,YAAY,UAAM,iBAAAA,SAAK,KAAK,KAAK,QAAQ,MAAM,QAAQ,CAAC;AAE9D,QAAM,QAAQ;AAAA,IACb,UAAU,IAAI,OAAO,SAAS;AAC7B,YAAM,UAAU,MAAM,SAAS,MAAM,MAAM;AAE3C,YAAM,CAAC,OAAO,IAAI,oCAAK,MAAM,OAAO;AACpC,YAAM,CAAC,OAAO,IAAI,SAAS,QAAQ,OAAO;AAC1C,YAAM,CAAC,IAAI,IAAI,SAAS,QAAQ,OAAO;AAEvC,YAAM,WAAW,MAAM,SAAS,MAAM,OAAO;AAG7C,UAAI,UAAU;AAMb,cAAM,kBAAkB;AAAA,EAAoB,oCAAK,UAAU,CAAC,OAAO,CAAC;AACpE,cAAM,GAAG,SAAS,UAAU,MAAM,eAAe;AAAA,MAClD;AAAA,IACD,CAAC;AAAA,EACF;AACD;;;ACjCA,IAAqB,6BAArB,MAAgD;AAAA,EAC9B;AAAA,EAMjB,YAAY,SAA6C;AACxD,SAAK,YAAY,WAAW,CAAC;AAAA,EAC9B;AAAA,EAEA,MAAM,UAAoB;AAEzB,aAAS,MAAM,KAAK,SAAS,MAAa,OAAO,WAAkB;AAClE,YAAM,gBAAgB;AAAA,QACrB,GAAG,KAAK;AAAA,QACR,QAAQ,SAAS,QAAQ,OAAO,QAAQ;AAAA,MACzC,CAAC;AAAA,IACF,CAAC;AAAA,EACF;AACD;AAMA,OAAO,UAAU;AACjB,OAAO,QAAQ,UAAU","sourcesContent":["import glob from \"fast-glob\";\nimport HTML from \"html-parse-stringify\";\nimport fs from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { findTags } from \"../ast-helpers\";\nimport type { PrerenderOptions } from \"./util\";\nimport { traverse } from \"./util\";\n\ninterface PrerenderBuildOptions extends PrerenderOptions {}\n\n/**\n * Prerendering for static builds - operates on entire HTML files.\n *\n * It globs the output directory for `.html` files and will rewrite their\n * contents if icons were prerendered\n *\n * @param options\n */\nexport async function prerenderStatic(options: PrerenderBuildOptions) {\n\tconst { outDir } = options;\n\tconst htmlFiles = await glob(path.join(outDir, \"**\", \"*.html\"));\n\n\tawait Promise.all(\n\t\thtmlFiles.map(async (file) => {\n\t\t\tconst content = await readFile(file, \"utf8\");\n\n\t\t\tconst [doctype] = HTML.parse(content);\n\t\t\tconst [htmlTag] = findTags(\"html\", doctype);\n\t\t\tconst [body] = findTags(\"body\", htmlTag);\n\n\t\t\tconst replaced = await traverse(body, options);\n\n\t\t\t// Avoids unnecessary file writes\n\t\t\tif (replaced) {\n\t\t\t\t/**\n\t\t\t\t * Can't use the `doctype` AST node since it contains { attrs: { html: '' } }\n\t\t\t\t * which is stringified into <!DOCTYPE html=\"\"> (instead of\n\t\t\t\t * <!DOCTYPE html>) which is invalid HTML.\n\t\t\t\t */\n\t\t\t\tconst replacedContent = `<!DOCTYPE html>\\n${HTML.stringify([htmlTag])}`;\n\t\t\t\tawait fs.promises.writeFile(file, replacedContent);\n\t\t\t}\n\t\t})\n\t);\n}\n","/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable unicorn/prefer-module */\n/* eslint-disable import/no-import-module-exports */\nimport { prerenderStatic } from \"@/prerender/static\";\nimport type { IconPrerenderPluginOptions } from \"@/types\";\nimport { PLUGIN_NAME } from \"@/types\";\nimport type { Compiler, Stats } from \"webpack\";\n\n// TODO: Make it work during development\ninterface IconPrerenderPluginWebpackOptions\n\textends IconPrerenderPluginOptions {}\n\nexport default class IconPrerenderWebpackPlugin {\n\tprivate readonly __options: IconPrerenderPluginWebpackOptions;\n\n\t/**\n\t * Return a new instance of the plugin with user-set configuration options\n\t * @param options\n\t */\n\tconstructor(options?: IconPrerenderPluginWebpackOptions) {\n\t\tthis.__options = options ?? {};\n\t}\n\n\tapply(compiler: Compiler) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\tcompiler.hooks.done.tapAsync(PLUGIN_NAME, async (_stats: Stats) => {\n\t\t\tawait prerenderStatic({\n\t\t\t\t...this.__options,\n\t\t\t\toutDir: compiler.options.output.path ?? \"dist\",\n\t\t\t});\n\t\t});\n\t}\n}\n\n/**\n * Workaround so ES Build allows require() without require().default in consumer\n * See https://github.com/ajv-validator/ajv/issues/1381#issuecomment-798884865\n */\nmodule.exports = IconPrerenderWebpackPlugin;\nmodule.exports.default = IconPrerenderWebpackPlugin;\n"]}