import {
  oo
} from "./chunk-chunk-DUODS2QA.mjs";
import {
  __name,
  init_define_process
} from "./chunk-chunk-5RXWZEI4.mjs";

// src/importMapReplace.ts
init_define_process();
self.impTest = (code) => console.log(importMapReplace(code));
function importMapReplace(code) {
  const topLevelImportPattern = /(import\s*(?:[\w{},*\s]+|[\w{} as,*\s]+|\w+)\s*from\s*)(['"`][^'`"]+['"`])/g;
  const topLevelExportPattern = /(export\s*(?:[\w{},*\s]+|[\w{} as,*\s]+|\w+)\s*from\s*)(['"`][^'`"]+['"`])/g;
  const dynamicImportPattern = /(import\()(['"`][^'`"]+['"`]\))/g;
  const replacer = /* @__PURE__ */ __name((match, p1, p2) => {
    const packageName = p2.slice(1, -1);
    if (packageName.startsWith(".") || packageName.startsWith("http")) {
      return match;
    }
    if (packageName.startsWith("/")) {
      return `${p1}'origin${packageName}'`;
    }
    return `${p1}'origin/*${packageName}?bundle'`;
  }, "replacer");
  code = code.replace(topLevelImportPattern, replacer).replace(topLevelExportPattern, replacer).replace(dynamicImportPattern, replacer);
  Object.keys(oo).forEach((pkg) => {
    code = code.split(`origin/*${pkg}?bundle`).join(oo[pkg]);
  });
  return code;
}
__name(importMapReplace, "importMapReplace");

export {
  importMapReplace
};
