"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 doesChunkBelongToHtml_exports = {};
__export(doesChunkBelongToHtml_exports, {
  doesChunkBelongToHtml: () => doesChunkBelongToHtml
});
module.exports = __toCommonJS(doesChunkBelongToHtml_exports);
var import_lodash = require("lodash");
/**
 * @license
 * Copyright 2018 Google Inc.
 * https://github.com/vuejs/preload-webpack-plugin/blob/master/src/lib/does-chunk-belong-to-html.js
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function recursiveChunkGroup(chunkGroup) {
  const parents = chunkGroup.getParents();
  if (!parents.length) {
    return [chunkGroup.name];
  }
  return parents.flatMap((chunkParent) => recursiveChunkGroup(chunkParent));
}
function recursiveChunkEntryNames(chunk) {
  const isChunkName = (name) => Boolean(name);
  const [...chunkGroups] = chunk.groupsIterable;
  return (0, import_lodash.uniq)(
    chunkGroups.flatMap((chunkGroup) => recursiveChunkGroup(chunkGroup)).filter(isChunkName)
  );
}
function isChunksFiltered(chunkName, includeChunks, excludeChunks) {
  if (Array.isArray(includeChunks) && includeChunks.indexOf(chunkName) === -1) {
    return false;
  }
  if (Array.isArray(excludeChunks) && excludeChunks.indexOf(chunkName) !== -1) {
    return false;
  }
  return true;
}
function doesChunkBelongToHtml({
  chunk,
  htmlPluginData
}) {
  const { options } = htmlPluginData.plugin;
  const chunkNames = recursiveChunkEntryNames(chunk);
  return chunkNames.some(
    (chunkName) => isChunksFiltered(chunkName, options == null ? void 0 : options.chunks, options == null ? void 0 : options.excludeChunks)
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  doesChunkBelongToHtml
});
