"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var HtmlNetworkPerformancePlugin_exports = {};
__export(HtmlNetworkPerformancePlugin_exports, {
  HtmlNetworkPerformancePlugin: () => HtmlNetworkPerformancePlugin
});
module.exports = __toCommonJS(HtmlNetworkPerformancePlugin_exports);
var import_lodash = require("lodash");
function generateLinks(options, type) {
  return options.map((option) => ({
    tagName: "link",
    attributes: {
      rel: (0, import_lodash.kebabCase)(type),
      ...option
    },
    voidTag: false,
    meta: {}
  }));
}
class HtmlNetworkPerformancePlugin {
  constructor(options, type, HtmlPlugin) {
    this.options = options;
    this.type = type;
    this.HtmlPlugin = HtmlPlugin;
  }
  apply(compiler) {
    compiler.hooks.compilation.tap(
      `HTML${this.type}Plugin`,
      (compilation) => {
        this.HtmlPlugin.getHooks(compilation).alterAssetTagGroups.tap(
          `HTML${(0, import_lodash.upperFirst)(this.type)}Plugin`,
          (htmlPluginData) => {
            const { headTags } = htmlPluginData;
            const options = this.options.map(
              (option) => typeof option === "string" ? {
                href: option
              } : option
            );
            if (options.length) {
              headTags.unshift(...generateLinks(options, this.type));
            }
            return htmlPluginData;
          }
        );
      }
    );
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  HtmlNetworkPerformancePlugin
});
