import { createRequire as $createRequire } from "node:module";

const require = $createRequire(import.meta.url);

import { parentPort } from 'node:worker_threads';
import { version } from 'vue';
import { build } from 'esbuild';
import { e as export_vuePlugin } from './vue3-DtTC1eal.mjs';
import path from 'node:path/posix';
import { t as tsconfigPath } from './tsconfig-path-bG7G_cK8.mjs';
import 'node:crypto';
import 'vue/compiler-sfc';
import 'node:url';

const pluginName = "virtual-entry";
function virtualEntryPlugin(entries) {
  function haveEntry(key) {
    return Boolean(entries[key]);
  }
  function getEntry(key) {
    return entries[key];
  }
  return {
    name: pluginName,
    setup(build) {
      build.onResolve({ filter: /.*/ }, (args) => {
        if (args.kind === "entry-point" && haveEntry(args.path)) {
          return {
            path: args.path,
            namespace: pluginName
          };
        } else {
          return void 0;
        }
      });
      build.onLoad({ filter: /.*/, namespace: pluginName }, (args) => {
        const [, resolveFrom] = args.path.split(":");
        const contents = getEntry(args.path);
        return {
          contents,
          loader: "ts",
          resolveDir: path.dirname(resolveFrom)
        };
      });
    }
  };
}

const vueMajor = parseInt(version.split(".", 2)[0], 10);
function stripExtension(filename) {
  return filename.replace(".js", "");
}
function VuePlugin() {
  switch (vueMajor) {
    case 2:
      throw new Error(
        "Vue 2 is no longer supported, upgrade to Vue 3 or downgrade docs-generator"
      );
    case 3:
      return export_vuePlugin();
  }
}
function virtualEntryPoint(task) {
  return `virtual:${task.sourceFile}:${task.outputFile}`;
}
async function compileExample(options, task) {
  const { outputFolder: outdir, external } = options;
  const entryPoints = [
    { in: virtualEntryPoint(task), out: stripExtension(task.outputFile) }
  ];
  const virtualEntries = { [virtualEntryPoint(task)]: task.sourcecode };
  const iconLib = process.env.DOCS_ICON_LIB ?? "@fkui/icon-lib-default";
  await build({
    entryPoints,
    outdir,
    bundle: true,
    format: "esm",
    platform: "browser",
    external,
    tsconfig: tsconfigPath,
    define: {
      "process.env.NODE_ENV": JSON.stringify("development"),
      "process.env.DOCS_ICON_LIB": JSON.stringify(iconLib)
    },
    plugins: [virtualEntryPlugin(virtualEntries), VuePlugin()]
  });
  return { ...task };
}
async function compileExampleMultiple(options, tasks) {
  return Promise.all(tasks.map((task) => compileExample(options, task)));
}
const queue = [];
const port = parentPort;
if (port) {
  let runner = true;
  port.on("message", async (message) => {
    const { tasks } = message;
    queue.push(async () => {
      const results = await compileExampleMultiple(message, tasks);
      const response = {
        ref: message.ref,
        results
      };
      port.postMessage(response);
    });
    if (!runner) {
      return;
    }
    runner = false;
    try {
      while (queue.length > 0) {
        const next = queue.pop();
        if (next) {
          await next();
        }
      }
    } finally {
      runner = true;
    }
  });
}
//# sourceMappingURL=worker-DUs54YZx.mjs.map
