// @bun
import {
  createRuntimePlugin
} from "./index-q0cfnm5n.js";

// src/runtime-plugin-support-configure.ts
var {plugin: registerBunPlugin } = globalThis.Bun;
var runtimePluginSupportInstalledKey = "__opentuiCoreRuntimePluginSupportInstalled__";
function normalizeRewriteKey(rewrite) {
  return `${rewrite?.nodeModulesRuntimeSpecifiers ?? true}:${rewrite?.nodeModulesBareSpecifiers ?? false}`;
}
function assertCompatibleInstall(install, options) {
  for (const specifier of Object.keys(options.additional ?? {})) {
    if (!install.additionalSpecifiers.has(specifier)) {
      throw new Error(`OpenTUI Core runtime plugin support is already installed without ${specifier}. Call ensureRuntimePluginSupport({ additional }) from @opentui/core/runtime-plugin-support/configure before importing @opentui/core/runtime-plugin-support.`);
    }
  }
  if (options.core && options.core !== install.core) {
    throw new Error("OpenTUI Core runtime plugin support is already installed with a different core runtime module.");
  }
  if (options.rewrite && normalizeRewriteKey(options.rewrite) !== install.rewriteKey) {
    throw new Error("OpenTUI Core runtime plugin support is already installed with different rewrite options.");
  }
}
function ensureRuntimePluginSupport(options = {}) {
  const state = globalThis;
  const install = state[runtimePluginSupportInstalledKey];
  if (install) {
    assertCompatibleInstall(install, options);
    return false;
  }
  registerBunPlugin(createRuntimePlugin(options));
  state[runtimePluginSupportInstalledKey] = {
    additionalSpecifiers: new Set(Object.keys(options.additional ?? {})),
    core: options.core,
    rewriteKey: normalizeRewriteKey(options.rewrite)
  };
  return true;
}

export { ensureRuntimePluginSupport };

//# debugId=09C0597CB92E654F64756E2164756E21
//# sourceMappingURL=index-abcme1yw.js.map
