/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/html-webpack-plugin@5.6.4/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";const promisify=require("util").promisify,vm=require("vm"),fs=require("fs"),_uniq=require("lodash/uniq"),path=require("path"),{CachedChildCompilation:CachedChildCompilation}=require("./lib/cached-child-compiler"),{createHtmlTagObject:createHtmlTagObject,htmlTagObjectToString:htmlTagObjectToString,HtmlTagArray:HtmlTagArray}=require("./lib/html-tags"),prettyError=require("./lib/errors.js"),chunkSorter=require("./lib/chunksorter.js"),{AsyncSeriesWaterfallHook:AsyncSeriesWaterfallHook}=require("tapable"),compilationHooksMap=new WeakMap;class HtmlWebpackPlugin{static getCompilationHooks(e){let t=compilationHooksMap.get(e);return t||(t={beforeAssetTagGeneration:new AsyncSeriesWaterfallHook(["pluginArgs"]),alterAssetTags:new AsyncSeriesWaterfallHook(["pluginArgs"]),alterAssetTagGroups:new AsyncSeriesWaterfallHook(["pluginArgs"]),afterTemplateExecution:new AsyncSeriesWaterfallHook(["pluginArgs"]),beforeEmit:new AsyncSeriesWaterfallHook(["pluginArgs"]),afterEmit:new AsyncSeriesWaterfallHook(["pluginArgs"])},compilationHooksMap.set(e,t)),t}constructor(e){this.userOptions=e||{},this.version=HtmlWebpackPlugin.version;const t={template:"auto",templateContent:!1,templateParameters:templateParametersGenerator,filename:"index.html",publicPath:void 0===this.userOptions.publicPath?"auto":this.userOptions.publicPath,hash:!1,inject:"blocking"===this.userOptions.scriptLoading?"body":"head",scriptLoading:"defer",compile:!0,favicon:!1,minify:"auto",cache:!0,showErrors:!0,chunks:"all",excludeChunks:[],chunksSortMode:"auto",meta:{},base:!1,title:"Webpack App",xhtml:!1};this.options=Object.assign(t,this.userOptions)}apply(e){this.logger=e.getInfrastructureLogger("HtmlWebpackPlugin");const t=this.options;t.template=this.getTemplatePath(this.options.template,e.context),"defer"!==t.scriptLoading&&"blocking"!==t.scriptLoading&&"module"!==t.scriptLoading&&"systemjs-module"!==t.scriptLoading&&this.logger.error('The "scriptLoading" option need to be set to "defer", "blocking" or "module" or "systemjs-module"'),!0!==t.inject&&!1!==t.inject&&"head"!==t.inject&&"body"!==t.inject&&this.logger.error('The `inject` option needs to be set to true, false, "head" or "body'),!1!==this.options.templateParameters&&"function"!=typeof this.options.templateParameters&&"object"!=typeof this.options.templateParameters&&this.logger.error("The `templateParameters` has to be either a function or an object or false"),!this.userOptions.template&&!1===t.templateContent&&t.meta&&(t.meta=Object.assign({},t.meta,{viewport:"width=device-width, initial-scale=1"},this.userOptions.meta));const o=this.userOptions.filename||this.options.filename,a="function"==typeof o?o:e=>o.replace(/\[name\]/g,e),r=Object.keys(e.options.entry);new Set((r.length?r:["main"]).map(a)).forEach((t=>{const o={value:void 0},a=[],r=new CachedChildCompilation(e);this.options.templateContent||r.addEntry(this.options.template);let s=t;if(path.resolve(s)===path.normalize(s)){const t=e.options.output.path;s=path.relative(t,s)}e.hooks.thisCompilation.tap("HtmlWebpackPlugin",(t=>{t.hooks.processAssets.tapAsync({name:"HtmlWebpackPlugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE},((n,i)=>{this.generateHTML(e,t,s,r,a,o,i)}))}))}))}getTemplatePath(e,t){return"auto"===e&&(e=path.resolve(t,"src/index.ejs"),fs.existsSync(e)||(e=path.join(__dirname,"default_index.ejs"))),-1===e.indexOf("!")&&(e=require.resolve("./lib/loader.js")+"!"+path.resolve(t,e)),e.replace(/([!])([^/\\][^!?]+|[^/\\!?])($|\?[^!?\n]+$)/,((e,t,o,a)=>t+path.resolve(o)+a))}filterEntryChunks(e,t,o){return e.filter((e=>(!Array.isArray(t)||-1!==t.indexOf(e))&&(!Array.isArray(o)||-1===o.indexOf(e))))}sortEntryChunks(e,t,o){if("function"==typeof t)return e.sort(t);if(void 0!==chunkSorter[t])return chunkSorter[t](e,o,this.options);throw new Error('"'+t+'" is not a valid chunk sort mode')}urlencodePath(e){const t=e.indexOf("?"),o=-1===t?e:e.substr(0,t),a=e.substr(o.length);return o.split("/").map(encodeURIComponent).join("/")+a}appendHash(e,t){return e?e+(-1===e.indexOf("?")?"?":"&")+t:e}getPublicPath(e,t,o){const a=e.getAssetPath(e.outputOptions.publicPath,{hash:e.hash});let r="auto"!==o?o:"auto"!==a?a:path.relative(path.resolve(e.options.output.path,path.dirname(t)),e.options.output.path).split(path.sep).join("/");return r.length&&"/"!==r.substr(-1,1)&&(r+="/"),r}getAssetsInformationByGroups(e,t,o){const a=this.getPublicPath(e,t,this.options.publicPath),r={publicPath:a,js:[],css:[],manifest:Object.keys(e.assets).find((e=>".appcache"===path.extname(e))),favicon:void 0};this.options.hash&&r.manifest&&(r.manifest=this.appendHash(r.manifest,e.hash));const s={},n=/\.(css|js|mjs)(\?|$)/;for(let t=0;t<o.length;t++){const i=o[t];e.entrypoints.get(i).getFiles().filter((t=>{const o=e.getAsset(t);if(!o)return!0;const a=o.info||{};return!(a.hotModuleReplacement||a.development)})).map((t=>{const o=a+this.urlencodePath(t);return this.options.hash?this.appendHash(o,e.hash):o})).forEach((e=>{const t=n.exec(e);if(!t)return;if(s[e])return;s[e]=!0;const o="mjs"===t[1]?"js":t[1];r[o].push(e)}))}return r}evaluateCompilationResult(e,t,o){if(!e)return Promise.reject(new Error("The child compilation didn't provide a result"));e.indexOf("HTML_WEBPACK_PLUGIN_RESULT")>=0&&(e+=";\nHTML_WEBPACK_PLUGIN_RESULT");const a=o.replace(/^.+!/,"").replace(/\?.+$/,""),r=vm.createContext({...global,HTML_WEBPACK_PLUGIN:!0,require:require,htmlWebpackPluginPublicPath:t,__filename:a,__dirname:path.dirname(a),AbortController:global.AbortController,AbortSignal:global.AbortSignal,Blob:global.Blob,Buffer:global.Buffer,ByteLengthQueuingStrategy:global.ByteLengthQueuingStrategy,BroadcastChannel:global.BroadcastChannel,CompressionStream:global.CompressionStream,CountQueuingStrategy:global.CountQueuingStrategy,Crypto:global.Crypto,CryptoKey:global.CryptoKey,CustomEvent:global.CustomEvent,DecompressionStream:global.DecompressionStream,Event:global.Event,EventTarget:global.EventTarget,File:global.File,FormData:global.FormData,Headers:global.Headers,MessageChannel:global.MessageChannel,MessageEvent:global.MessageEvent,MessagePort:global.MessagePort,PerformanceEntry:global.PerformanceEntry,PerformanceMark:global.PerformanceMark,PerformanceMeasure:global.PerformanceMeasure,PerformanceObserver:global.PerformanceObserver,PerformanceObserverEntryList:global.PerformanceObserverEntryList,PerformanceResourceTiming:global.PerformanceResourceTiming,ReadableByteStreamController:global.ReadableByteStreamController,ReadableStream:global.ReadableStream,ReadableStreamBYOBReader:global.ReadableStreamBYOBReader,ReadableStreamBYOBRequest:global.ReadableStreamBYOBRequest,ReadableStreamDefaultController:global.ReadableStreamDefaultController,ReadableStreamDefaultReader:global.ReadableStreamDefaultReader,Response:global.Response,Request:global.Request,SubtleCrypto:global.SubtleCrypto,DOMException:global.DOMException,TextDecoder:global.TextDecoder,TextDecoderStream:global.TextDecoderStream,TextEncoder:global.TextEncoder,TextEncoderStream:global.TextEncoderStream,TransformStream:global.TransformStream,TransformStreamDefaultController:global.TransformStreamDefaultController,URL:global.URL,URLSearchParams:global.URLSearchParams,WebAssembly:global.WebAssembly,WritableStream:global.WritableStream,WritableStreamDefaultController:global.WritableStreamDefaultController,WritableStreamDefaultWriter:global.WritableStreamDefaultWriter}),s=new vm.Script(e,{filename:a});let n;try{n=s.runInContext(r)}catch(e){return Promise.reject(e)}return"object"==typeof n&&n.__esModule&&void 0!==n.default&&(n=n.default),"string"==typeof n||"function"==typeof n?Promise.resolve(n):Promise.reject(new Error('The loader "'+a+"\" didn't return html."))}prepareAssetTagGroupForRendering(e){const t=this.options.xhtml;return HtmlTagArray.from(e.map((e=>{const o=Object.assign({},e);return o.toString=function(){return htmlTagObjectToString(this,t)},o})))}getTemplateParameters(e,t,o){const a=this.options.templateParameters;if(!1===a)return Promise.resolve({});if("function"!=typeof a&&"object"!=typeof a)throw new Error("templateParameters has to be either a function or an object");const r="function"==typeof a?a:(e,t,o,r)=>Object.assign({},templateParametersGenerator(e,t,o,r),a),s={headTags:this.prepareAssetTagGroupForRendering(o.headTags),bodyTags:this.prepareAssetTagGroupForRendering(o.bodyTags)};return Promise.resolve().then((()=>r(e,t,s,this.options)))}executeTemplate(e,t,o,a){return this.getTemplateParameters(a,t,o).then((t=>{try{return e(t)}catch(e){return a.errors.push(new Error("Template execution failed: "+e)),Promise.reject(e)}}))}postProcessHtml(e,t,o,a){let r=t;if("string"!=typeof r)return Promise.reject(new Error("Expected html to be a string but got "+JSON.stringify(r)));if(this.options.inject){const e=/(<html[^>]*>)/i,t=/(<\/head\s*>)/i,s=/(<\/body\s*>)/i,n=/<meta[^>]+name=["']viewport["'][^>]*>/i,i=a.bodyTags.map((e=>htmlTagObjectToString(e,this.options.xhtml))),l=a.headTags.filter((e=>"meta"!==e.tagName||!e.attributes||"viewport"!==e.attributes.name||!n.test(r))).map((e=>htmlTagObjectToString(e,this.options.xhtml)));i.length&&(s.test(r)?r=r.replace(s,(e=>i.join("")+e)):r+=i.join("")),l.length&&(t.test(r)||(r=e.test(r)?r.replace(e,(e=>e+"<head></head>")):"<head></head>"+r),r=r.replace(t,(e=>l.join("")+e))),o.manifest&&(r=r.replace(/(<html[^>]*)(>)/i,((e,t,a)=>/\smanifest\s*=/.test(e)?e:t+' manifest="'+o.manifest+'"'+a)))}const s="production"===e.options.mode||!e.options.mode;if(!(!0===this.options.minify||"object"==typeof this.options.minify||"auto"===this.options.minify&&s))return Promise.resolve(r);const n="object"==typeof this.options.minify?this.options.minify:{collapseWhitespace:!0,keepClosingSlash:!0,removeComments:!0,removeRedundantAttributes:!0,removeScriptTypeAttributes:!0,removeStyleLinkTypeAttributes:!0,useShortDoctype:!0};try{r=require("html-minifier-terser").minify(r,n)}catch(e){return 0===String(e.message).indexOf("Parse Error")&&(e.message="html-webpack-plugin could not minify the generated output.\nIn production mode the html minification is enabled by default.\nIf you are not generating a valid html output please disable it manually.\nYou can do so by adding the following setting to your HtmlWebpackPlugin config:\n|\n|    minify: false\n|\nSee https://github.com/jantimon/html-webpack-plugin#options for details.\n\nFor parser dedicated bugs please create an issue here:\nhttps://danielruf.github.io/html-minifier-terser/\n"+e.message),Promise.reject(e)}return Promise.resolve(r)}getAssetFiles(e){const t=_uniq(Object.keys(e).filter((t=>"chunks"!==t&&e[t])).reduce(((t,o)=>t.concat(e[o])),[]));return t.sort(),t}generateFavicon(e,t,o,a,r){if(!t)return Promise.resolve(void 0);const s=path.resolve(o.compiler.context,t);return promisify(o.inputFileSystem.readFile)(s).then((t=>{const n=new e.webpack.sources.RawSource(t,!1),i=path.basename(s);o.fileDependencies.add(s),o.emitAsset(i,n),r.push({name:i,source:n});const l=a+i;return this.options.hash?this.appendHash(l,o.hash):l})).catch((()=>Promise.reject(new Error("HtmlWebpackPlugin: could not load file "+s))))}generatedScriptTags(e){return e.map((e=>{const t={};return"defer"===this.options.scriptLoading?t.defer=!0:"module"===this.options.scriptLoading?t.type="module":"systemjs-module"===this.options.scriptLoading&&(t.type="systemjs-module"),t.src=e,{tagName:"script",voidTag:!1,meta:{plugin:"html-webpack-plugin"},attributes:t}}))}generateStyleTags(e){return e.map((e=>({tagName:"link",voidTag:!0,meta:{plugin:"html-webpack-plugin"},attributes:{href:e,rel:"stylesheet"}})))}generateBaseTag(e){return[{tagName:"base",voidTag:!0,meta:{plugin:"html-webpack-plugin"},attributes:"string"==typeof e?{href:e}:e}]}generatedMetaTags(e){if(!1===e)return[];return Object.keys(e).map((t=>{const o=e[t];return"string"==typeof o?{name:t,content:o}:o})).filter((e=>!1!==e)).map((e=>{if(!1===e)throw new Error("Invalid meta tag");return{tagName:"meta",voidTag:!0,meta:{plugin:"html-webpack-plugin"},attributes:e}}))}generateFaviconTag(e){return[{tagName:"link",voidTag:!0,meta:{plugin:"html-webpack-plugin"},attributes:{rel:"icon",href:e}}]}groupAssetsByElements(e,t){const o={headTags:[...e.meta,...e.styles],bodyTags:[]};if("body"===t)o.bodyTags.push(...e.scripts);else{const t="blocking"===this.options.scriptLoading?o.headTags.length:e.meta.length;o.headTags.splice(t,0,...e.scripts)}return o}replacePlaceholdersInFilename(e,t,o,a){if(!1===/\[\\*([\w:]+)\\*\]/i.test(t))return{path:t,info:{}};const r=e.webpack.util.createHash(a.outputOptions.hashFunction);r.update(o),a.outputOptions.hashSalt&&r.update(a.outputOptions.hashSalt);const s=r.digest(a.outputOptions.hashDigest).slice(0,a.outputOptions.hashDigestLength);return a.getPathWithInfo(t,{contentHash:s,chunk:{hash:s,contentHash:s}})}generateHTML(e,t,o,a,r,s,n){const i=Array.from(t.entrypoints.keys()),l=this.filterEntryChunks(i,this.options.chunks,this.options.excludeChunks),p=this.sortEntryChunks(l,this.options.chunksSortMode,t),h=this.options.templateContent?{mainCompilationHash:t.hash}:a.getCompilationEntryResult(this.options.template);"error"in h&&t.errors.push(new Error(prettyError(h.error,e.context).toString()));const c=h.mainCompilationHash!==t.hash,m=this.getAssetsInformationByGroups(t,o,p),u=JSON.stringify(this.getAssetFiles(m));if(c&&this.options.cache&&s.value===u)return r.forEach((({name:e,source:o,info:a})=>{t.emitAsset(e,o,a)})),n();r.length=0,s.value=u;const g=this.generateFavicon(e,this.options.favicon,t,m.publicPath,r).then((e=>(m.favicon=e,HtmlWebpackPlugin.getCompilationHooks(t).beforeAssetTagGeneration.promise({assets:m,outputName:o,plugin:this})))),b=g.then((({assets:e})=>HtmlWebpackPlugin.getCompilationHooks(t).alterAssetTags.promise({assetTags:{scripts:this.generatedScriptTags(e.js),styles:this.generateStyleTags(e.css),meta:[...!1!==this.options.base?this.generateBaseTag(this.options.base):[],...this.generatedMetaTags(this.options.meta),...e.favicon?this.generateFaviconTag(e.favicon):[]]},outputName:o,publicPath:m.publicPath,plugin:this}))).then((({assetTags:e})=>{const a="head"===this.options.inject||"body"!==this.options.inject&&"blocking"!==this.options.scriptLoading?"head":"body",r=this.groupAssetsByElements(e,a);return HtmlWebpackPlugin.getCompilationHooks(t).alterAssetTagGroups.promise({headTags:r.headTags,bodyTags:r.bodyTags,outputName:o,publicPath:m.publicPath,plugin:this})})),d=Promise.resolve().then((()=>{if("error"in h)return this.options.showErrors?prettyError(h.error,e.context).toHtml():"ERROR";if(!1!==this.options.templateContent)return this.options.templateContent;if("compiledEntry"in h){const e=h.compiledEntry,t=e.assets;for(const e in t)r.push({name:e,source:t[e].source,info:t[e].info});return this.evaluateCompilationResult(e.content,m.publicPath,this.options.template)}return Promise.reject(new Error("Child compilation contained no compiledEntry"))})),f=Promise.all([g,b,d]).then((([e,o,a])=>"function"!=typeof a?a:this.executeTemplate(a,e.assets,{headTags:o.headTags,bodyTags:o.bodyTags},t)));Promise.all([b,f]).then((([e,a])=>{const r={html:a,headTags:e.headTags,bodyTags:e.bodyTags,plugin:this,outputName:o};return HtmlWebpackPlugin.getCompilationHooks(t).afterTemplateExecution.promise(r)})).then((({html:t,headTags:o,bodyTags:a})=>this.postProcessHtml(e,t,m,{headTags:o,bodyTags:a}))).then((e=>{const a={html:e,plugin:this,outputName:o};return HtmlWebpackPlugin.getCompilationHooks(t).beforeEmit.promise(a).then((e=>e.html))})).catch((o=>(t.errors.push(new Error(prettyError(o,e.context).toString())),this.options.showErrors?prettyError(o,e.context).toHtml():"ERROR"))).then((a=>{const s=o.replace(/\[templatehash([^\]]*)\]/g,require("util").deprecate(((e,t)=>`[contenthash${t}]`),"[templatehash] is now [contenthash]")),n=this.replacePlaceholdersInFilename(e,s,a,t),i=new e.webpack.sources.RawSource(a,!1);return t.emitAsset(n.path,i,n.info),r.push({name:n.path,source:i}),n.path})).then((e=>HtmlWebpackPlugin.getCompilationHooks(t).afterEmit.promise({outputName:e,plugin:this}).catch((e=>(this.logger.error(e),null))).then((()=>null)))).then((()=>{n()}))}}function templateParametersGenerator(e,t,o,a){return{compilation:e,webpackConfig:e.options,htmlWebpackPlugin:{tags:o,files:t,options:a}}}HtmlWebpackPlugin.version=5,HtmlWebpackPlugin.getHooks=HtmlWebpackPlugin.getCompilationHooks,HtmlWebpackPlugin.createHtmlTagObject=createHtmlTagObject,module.exports=HtmlWebpackPlugin;
//# sourceMappingURL=/sm/9a853baa52054b6173e62b2f063d038ba954ec541fbb678e0d080cafd94c2847.map