{"version":3,"file":"html.mjs","names":["basename","dirname","join","pathJoin","mkdir","writeFile","Bundle","ProjectorHtml","htmlEncode","trimExtension","BundleHtml","constructor","path","flat","projector","_createProjector","extension","a","split","ext","length","pop","Error","subdir","index","getLauncher","lang","title","url","map","encodeURIComponent","hAttr","s","replace","repeat","_close","_writeLauncher","_getProjectorPathNested","_getProjectorPath","recursive"],"sources":["../../src/bundle/html.ts"],"sourcesContent":["import {basename, dirname, join as pathJoin} from 'node:path';\nimport {mkdir, writeFile} from 'node:fs/promises';\n\nimport {Bundle} from '../bundle.ts';\nimport {ProjectorHtml} from '../projector/html.ts';\nimport {htmlEncode, trimExtension} from '../util.ts';\n\n/**\n * BundleHtml object.\n */\nexport class BundleHtml extends Bundle {\n\t/**\n\t * ProjectorHtml instance.\n\t */\n\tpublic readonly projector: ProjectorHtml;\n\n\t/**\n\t * BundleHtml constructor.\n\t *\n\t * @param path Output path.\n\t * @param flat Flat bundle.\n\t */\n\tconstructor(path: string, flat = false) {\n\t\tsuper(path, flat);\n\n\t\tthis.projector = this._createProjector();\n\t}\n\n\t/**\n\t * Main application file extension.\n\t *\n\t * @returns File extension.\n\t */\n\tpublic get extension() {\n\t\tconst a = basename(this.path).split('.');\n\t\tconst ext = a.length > 1 ? a.pop() : '';\n\t\tif (!ext) {\n\t\t\tthrow new Error('Failed to extract extension');\n\t\t}\n\t\treturn `.${ext}`;\n\t}\n\n\t/**\n\t * Get the nested subdirectory.\n\t *\n\t * @returns Directory name.\n\t */\n\tpublic get subdir() {\n\t\treturn trimExtension(basename(this.path), this.extension);\n\t}\n\n\t/**\n\t * Get the nested index.\n\t *\n\t * @returns File name.\n\t */\n\tpublic get index() {\n\t\treturn `index${this.extension}`;\n\t}\n\n\t/**\n\t * Get launcher HTML code.\n\t *\n\t * @returns HTML code.\n\t */\n\tpublic getLauncher() {\n\t\tconst {projector, subdir, index} = this;\n\t\tconst {lang, title} = projector;\n\t\tconst path = `${subdir}/${index}`;\n\t\tconst url = path.split(/[/\\\\]/).map(encodeURIComponent).join('/');\n\t\tconst hAttr = lang === null ? '' : ` lang=\"${htmlEncode(lang, true)}\"`;\n\n\t\treturn [\n\t\t\t'<!DOCTYPE html>',\n\t\t\t`<html${hAttr}>`,\n\t\t\t' <head>',\n\t\t\t'  <meta charset=\"UTF-8\">',\n\t\t\t'  <meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge\">',\n\t\t\t`  <meta http-equiv=\"refresh\" content=\"0; url=${htmlEncode(\n\t\t\t\turl,\n\t\t\t\ttrue\n\t\t\t)}\">`,\n\t\t\t...(title === null\n\t\t\t\t? []\n\t\t\t\t: [`  <title>${htmlEncode(title)}</title>`]),\n\t\t\t' </head>',\n\t\t\t' <body></body>',\n\t\t\t'</html>',\n\t\t\t''\n\t\t]\n\t\t\t.map(s => s.replace(/^\\s+/, s => '\\t'.repeat(s.length)))\n\t\t\t.join('\\n');\n\t}\n\n\t/**\n\t * @inheritdoc\n\t */\n\tprotected async _close(): Promise<void> {\n\t\tif (!this.flat) {\n\t\t\tawait this._writeLauncher();\n\t\t}\n\t\tawait super._close();\n\t}\n\n\t/**\n\t * @inheritdoc\n\t */\n\tprotected _getProjectorPathNested(): string {\n\t\treturn pathJoin(dirname(this.path), this.subdir, this.index);\n\t}\n\n\t/**\n\t * Create projector instance for the bundle.\n\t *\n\t * @returns Projector instance.\n\t */\n\tprotected _createProjector() {\n\t\treturn new ProjectorHtml(this._getProjectorPath());\n\t}\n\n\t/**\n\t * Write the launcher file.\n\t */\n\tprotected async _writeLauncher() {\n\t\tconst {path} = this;\n\t\tawait mkdir(dirname(path), {recursive: true});\n\t\tawait writeFile(path, this.getLauncher());\n\t}\n}\n"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,EAAEC,IAAI,IAAIC,QAAQ,QAAO,WAAW;AAC7D,SAAQC,KAAK,EAAEC,SAAS,QAAO,kBAAkB;AAEjD,SAAQC,MAAM,QAAO,eAAc;AACnC,SAAQC,aAAa,QAAO,uBAA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