import CJS_COMPAT_NODE_URL_qfbekemo7ri from 'node:url';
import CJS_COMPAT_NODE_PATH_qfbekemo7ri from 'node:path';
import CJS_COMPAT_NODE_MODULE_qfbekemo7ri from "node:module";

var __filename = CJS_COMPAT_NODE_URL_qfbekemo7ri.fileURLToPath(import.meta.url);
var __dirname = CJS_COMPAT_NODE_PATH_qfbekemo7ri.dirname(__filename);
var require = CJS_COMPAT_NODE_MODULE_qfbekemo7ri.createRequire(import.meta.url);

// ------------------------------------------------------------
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
// ------------------------------------------------------------
import {
  dirname,
  join
} from "./chunk-6A2WP6N7.js";
import {
  __name
} from "./chunk-PTT3CRNJ.js";

// src/shared/utils/module.ts
import { statSync } from "node:fs";
import { createRequire, register } from "node:module";
import { win32 } from "node:path/win32";
import { fileURLToPath, pathToFileURL } from "node:url";
var importMetaResolve = /* @__PURE__ */ __name((...args) => {
  if (typeof import.meta.resolve !== "function" && process.env.VITEST === "true") {
    console.warn(
      "importMetaResolve from within Storybook is being used in a Vitest test, but it shouldn't be. Please report this at https://github.com/storybookjs/storybook/issues/new?template=bug_report.yml"
    );
    return pathToFileURL(args[0]).href;
  }
  return import.meta.resolve(...args);
}, "importMetaResolve");
var resolvePackageDir = /* @__PURE__ */ __name((pkg, parent) => {
  return dirname(fileURLToPath(importMetaResolve(join(pkg, "package.json"), parent)));
}, "resolvePackageDir");
var isTypescriptLoaderRegistered = false;
async function importModule(path) {
  if (!isTypescriptLoaderRegistered) {
    const typescriptLoaderUrl = importMetaResolve("storybook/internal/bin/loader");
    register(typescriptLoaderUrl, import.meta.url);
    isTypescriptLoaderRegistered = true;
  }
  let mod;
  try {
    const resolvedPath = win32.isAbsolute(path) ? pathToFileURL(path).href : path;
    mod = await import(resolvedPath);
  } catch (importError) {
    try {
      const require2 = createRequire(import.meta.url);
      mod = require2(path);
    } catch (requireError) {
      throw importError;
    }
  }
  return mod.default ?? mod;
}
__name(importModule, "importModule");
var safeResolveModule = /* @__PURE__ */ __name(({
  specifier,
  parent,
  extensions = [".mjs", ".js", ".cjs"]
}) => {
  for (const extension of [""].concat(extensions)) {
    try {
      const resolvedPath = fileURLToPath(importMetaResolve(specifier + extension, parent));
      if (statSync(resolvedPath).isFile()) {
        return resolvedPath;
      }
    } catch (e) {
    }
  }
}, "safeResolveModule");

export {
  importMetaResolve,
  resolvePackageDir,
  importModule,
  safeResolveModule
};
