// @bun
var __create = Object.create;
var __getProtoOf = Object.getPrototypeOf;
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __hasOwnProp = Object.prototype.hasOwnProperty;
function __accessProp(key) {
  return this[key];
}
var __toESMCache_node;
var __toESMCache_esm;
var __toESM = (mod, isNodeMode, target) => {
  var canCache = mod != null && typeof mod === "object";
  if (canCache) {
    var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
    var cached = cache.get(mod);
    if (cached)
      return cached;
  }
  target = mod != null ? __create(__getProtoOf(mod)) : {};
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
  for (let key of __getOwnPropNames(mod))
    if (!__hasOwnProp.call(to, key))
      __defProp(to, key, {
        get: __accessProp.bind(mod, key),
        enumerable: true
      });
  if (canCache)
    cache.set(mod, to);
  return to;
};
var __toCommonJS = (from) => {
  var entry = (__moduleCache ??= new WeakMap).get(from), desc;
  if (entry)
    return entry;
  entry = __defProp({}, "__esModule", { value: true });
  if (from && typeof from === "object" || typeof from === "function") {
    for (var key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(entry, key))
        __defProp(entry, key, {
          get: __accessProp.bind(from, key),
          enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
        });
  }
  __moduleCache.set(from, entry);
  return entry;
};
var __moduleCache;
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
var __returnValue = (v) => v;
function __exportSetter(name, newValue) {
  this[name] = __returnValue.bind(null, newValue);
}
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, {
      get: all[name],
      enumerable: true,
      configurable: true,
      set: __exportSetter.bind(all, name)
    });
};
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
    r = Reflect.decorate(decorators, target, key, desc);
  else
    for (var i = decorators.length - 1;i >= 0; i--)
      if (d = decorators[i])
        r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __legacyMetadataTS = (k, v) => {
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
    return Reflect.metadata(k, v);
};
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
var __require = import.meta.require;

// src/core/streamingSlotRegistrar.ts
var STREAMING_SLOT_REGISTRAR_KEY = Symbol.for("absolutejs.streamingSlotRegistrar");
var getRegistrarGlobal = () => globalThis;
var setStreamingSlotRegistrar = (nextRegistrar) => {
  getRegistrarGlobal()[STREAMING_SLOT_REGISTRAR_KEY] = nextRegistrar;
};
var registerStreamingSlot = (slot) => {
  getRegistrarGlobal()[STREAMING_SLOT_REGISTRAR_KEY]?.(slot);
};

// src/core/streamingSlotRegistry.ts
var STREAMING_SLOT_STORAGE_KEY = Symbol.for("absolutejs.streamingSlotAsyncLocalStorage");
var getStorageGlobal = () => globalThis;
var isServerRuntime = () => typeof process !== "undefined" && typeof process.versions?.node === "string";
var ensureAsyncLocalStorage = async () => {
  const storageGlobal = getStorageGlobal();
  if (typeof storageGlobal[STREAMING_SLOT_STORAGE_KEY] !== "undefined") {
    return storageGlobal[STREAMING_SLOT_STORAGE_KEY];
  }
  if (!isServerRuntime()) {
    storageGlobal[STREAMING_SLOT_STORAGE_KEY] = null;
    return storageGlobal[STREAMING_SLOT_STORAGE_KEY];
  }
  const mod = await import("async_hooks");
  storageGlobal[STREAMING_SLOT_STORAGE_KEY] = new mod.AsyncLocalStorage;
  return storageGlobal[STREAMING_SLOT_STORAGE_KEY];
};
var registerStreamingSlot2 = (slot) => {
  const storage = getStorageGlobal()[STREAMING_SLOT_STORAGE_KEY];
  if (!storage)
    return;
  const store = storage.getStore();
  if (!store)
    return;
  store.set(slot.id, slot);
};
setStreamingSlotRegistrar(registerStreamingSlot2);
var runWithStreamingSlotRegistry = async (task) => {
  const storage = await ensureAsyncLocalStorage();
  if (!storage) {
    return {
      result: await task(),
      slots: []
    };
  }
  return storage.run(new Map, async () => {
    const result = await task();
    const store = storage.getStore();
    return {
      result,
      slots: store ? [...store.values()] : []
    };
  });
};
export {
  runWithStreamingSlotRegistry
};

//# debugId=3B93EBA78951E67B64756E2164756E21
//# sourceMappingURL=streamingSlotRegistry.js.map
