var xt = Object.defineProperty;
var s = (t, e) => xt(t, "name", { value: e, configurable: !0 });

// src/channels/index.ts
import { global as Mo } from "@storybook/global";

// ../node_modules/ts-dedent/esm/index.js
function j(t) {
  for (var e = [], r = 1; r < arguments.length; r++)
    e[r - 1] = arguments[r];
  var n = Array.from(typeof t == "string" ? [t] : t);
  n[n.length - 1] = n[n.length - 1].replace(/\r?\n([\t ]*)$/, "");
  var o = n.reduce(function(c, i) {
    var l = i.match(/\n([\t ]+|(?!\s).)/g);
    return l ? c.concat(l.map(function(d) {
      var u, y;
      return (y = (u = d.match(/[\t ]/g)) === null || u === void 0 ? void 0 : u.length) !== null && y !== void 0 ? y : 0;
    })) : c;
  }, []);
  if (o.length) {
    var p = new RegExp(`
[	 ]{` + Math.min.apply(Math, o) + "}", "g");
    n = n.map(function(c) {
      return c.replace(p, `
`);
    });
  }
  n[0] = n[0].replace(/^\r?\n/, "");
  var a = n[0];
  return e.forEach(function(c, i) {
    var l = a.match(/(?:^|\n)( *)$/), d = l ? l[1] : "", u = c;
    typeof c == "string" && c.includes(`
`) && (u = String(c).split(`
`).map(function(y, g) {
      return g === 0 ? y : "" + d + y;
    }).join(`
`)), a += u + n[i + 1];
  }), a;
}
s(j, "dedent");

// src/shared/universal-store/instances.ts
var he = /* @__PURE__ */ new Map();

// src/shared/universal-store/index.ts
var wt = "UNIVERSAL_STORE:", x = {
  PENDING: "PENDING",
  RESOLVED: "RESOLVED",
  REJECTED: "REJECTED"
}, M = class t {
  constructor(e, r) {
    /** Enable debug logs for this store */
    this.debugging = !1;
    // TODO: narrow type of listeners based on event type
    this.listeners = /* @__PURE__ */ new Map([["*", /* @__PURE__ */ new Set()]]);
    /** Gets the current state */
    this.getState = /* @__PURE__ */ s(() => (this.debug("getState", { state: this.state }), this.state), "getState");
    /**
     * Subscribes to store events
     *
     * @returns A function to unsubscribe
     */
    this.subscribe = /* @__PURE__ */ s((e, r) => {
      let n = typeof e == "function", o = n ? "*" : e, p = n ? e : r;
      if (this.debug("subscribe", { eventType: o, listener: p }), !p)
        throw new TypeError(
          `Missing first subscribe argument, or second if first is the event type, when subscribing to a UniversalStore with id '${this.id}'`
        );
      return this.listeners.has(o) || this.listeners.set(o, /* @__PURE__ */ new Set()), this.listeners.get(o).add(p), () => {
        this.debug("unsubscribe", { eventType: o, listener: p }), this.listeners.has(o) && (this.listeners.get(o).delete(p), this.listeners.get(o)?.size === 0 && this.listeners.delete(o));
      };
    }, "subscribe");
    /** Sends a custom event to the other stores */
    this.send = /* @__PURE__ */ s((e) => {
      if (this.debug("send", { event: e }), this.status !== t.Status.READY)
        throw new TypeError(
          j`Cannot send event before store is ready. You can get the current status with store.status,
        or await store.readyPromise to wait for the store to be ready before sending events.
        ${JSON.stringify(
            {
              event: e,
              id: this.id,
              actor: this.actor,
              environment: this.environment
            },
            null,
            2
          )}`
        );
      this.emitToListeners(e, { actor: this.actor }), this.emitToChannel(e, { actor: this.actor });
    }, "send");
    if (this.debugging = e.debug ?? !1, !t.isInternalConstructing)
      throw new TypeError(
        "UniversalStore is not constructable - use UniversalStore.create() instead"
      );
    if (t.isInternalConstructing = !1, this.id = e.id, this.actorId = Date.now().toString(36) + Math.random().toString(36).substring(2), this.actorType = e.leader ? t.ActorType.LEADER : t.ActorType.FOLLOWER, this.state = e.initialState, this.channelEventName = `${wt}${this.id}`, this.debug("constructor", {
      options: e,
      environmentOverrides: r,
      channelEventName: this.channelEventName
    }), this.actor.type === t.ActorType.LEADER)
      this.syncing = {
        state: x.RESOLVED,
        promise: Promise.resolve()
      };
    else {
      let n, o, p = new Promise((a, c) => {
        n = /* @__PURE__ */ s(() => {
          this.syncing.state === x.PENDING && (this.syncing.state = x.RESOLVED, a());
        }, "syncingResolve"), o = /* @__PURE__ */ s((i) => {
          this.syncing.state === x.PENDING && (this.syncing.state = x.REJECTED, c(i));
        }, "syncingReject");
      });
      this.syncing = {
        state: x.PENDING,
        promise: p,
        resolve: n,
        reject: o
      };
    }
    this.getState = this.getState.bind(this), this.setState = this.setState.bind(this), this.subscribe = this.subscribe.bind(this), this.onStateChange = this.onStateChange.bind(this), this.send = this.send.bind(this), this.emitToChannel = this.emitToChannel.bind(this), this.prepareThis = this.prepareThis.bind(this), this.emitToListeners = this.emitToListeners.bind(this), this.handleChannelEvents = this.handleChannelEvents.bind(this), this.debug = this.debug.bind(this), this.channel = r?.channel ?? t.preparation.channel, this.environment = r?.environment ?? t.preparation.environment, this.channel && this.environment ? (t.preparation.resolve({ channel: this.channel, environment: this.environment }), this.prepareThis({ channel: this.channel, environment: this.environment })) : t.preparation.promise.then(this.prepareThis);
  }
  static {
    s(this, "UniversalStore");
  }
  static {
    /**
     * Defines the possible actor types in the store system
     *
     * @readonly
     */
    this.ActorType = {
      LEADER: "LEADER",
      FOLLOWER: "FOLLOWER"
    };
  }
  static {
    /**
     * Defines the possible environments the store can run in
     *
     * @readonly
     */
    this.Environment = {
      SERVER: "SERVER",
      MANAGER: "MANAGER",
      PREVIEW: "PREVIEW",
      UNKNOWN: "UNKNOWN",
      MOCK: "MOCK"
    };
  }
  static {
    /**
     * Internal event types used for store synchronization
     *
     * @readonly
     */
    this.InternalEventType = {
      EXISTING_STATE_REQUEST: "__EXISTING_STATE_REQUEST",
      EXISTING_STATE_RESPONSE: "__EXISTING_STATE_RESPONSE",
      SET_STATE: "__SET_STATE",
      LEADER_CREATED: "__LEADER_CREATED",
      FOLLOWER_CREATED: "__FOLLOWER_CREATED"
    };
  }
  static {
    this.Status = {
      UNPREPARED: "UNPREPARED",
      SYNCING: "SYNCING",
      READY: "READY",
      ERROR: "ERROR"
    };
  }
  static {
    // This is used to check if constructor was called from the static factory create()
    this.isInternalConstructing = !1;
  }
  static {
    t.setupPreparationPromise();
  }
  static setupPreparationPromise() {
    let e, r, n = new Promise(
      (o, p) => {
        e = /* @__PURE__ */ s((a) => {
          o(a);
        }, "resolveRef"), r = /* @__PURE__ */ s((...a) => {
          p(a);
        }, "rejectRef");
      }
    );
    t.preparation = {
      resolve: e,
      reject: r,
      promise: n
    };
  }
  /** The actor object representing the store instance with a unique ID and a type */
  get actor() {
    return Object.freeze({
      id: this.actorId,
      type: this.actorType,
      environment: this.environment ?? t.Environment.UNKNOWN
    });
  }
  /**
   * The current state of the store, that signals both if the store is prepared by Storybook and
   * also - in the case of a follower - if the state has been synced with the leader's state.
   */
  get status() {
    if (!this.channel || !this.environment)
      return t.Status.UNPREPARED;
    switch (this.syncing?.state) {
      case x.PENDING:
      case void 0:
        return t.Status.SYNCING;
      case x.REJECTED:
        return t.Status.ERROR;
      case x.RESOLVED:
      default:
        return t.Status.READY;
    }
  }
  /**
   * A promise that resolves when the store is fully ready. A leader will be ready when the store
   * has been prepared by Storybook, which is almost instantly.
   *
   * A follower will be ready when the state has been synced with the leader's state, within a few
   * hundred milliseconds.
   */
  untilReady() {
    return Promise.all([t.preparation.promise, this.syncing?.promise]);
  }
  /** Creates a new instance of UniversalStore */
  static create(e) {
    if (!e || typeof e?.id != "string")
      throw new TypeError("id is required and must be a string, when creating a UniversalStore");
    e.debug && console.debug(
      j`[UniversalStore]
        create`,
      { options: e }
    );
    let r = he.get(e.id);
    if (r)
      return console.warn(j`UniversalStore with id "${e.id}" already exists in this environment, re-using existing.
        You should reuse the existing instance instead of trying to create a new one.`), r;
    t.isInternalConstructing = !0;
    let n = new t(e);
    return he.set(e.id, n), n;
  }
  /**
   * Used by Storybook to set the channel for all instances of UniversalStore in the given
   * environment.
   *
   * @internal
   */
  static __prepare(e, r) {
    t.preparation.channel = e, t.preparation.environment = r, t.preparation.resolve({ channel: e, environment: r });
  }
  /**
   * Updates the store's state
   *
   * Either a new state or a state updater function can be passed to the method.
   */
  setState(e) {
    let r = this.state, n = typeof e == "function" ? e(r) : e;
    if (this.debug("setState", { newState: n, previousState: r, updater: e }), this.status !== t.Status.READY)
      throw new TypeError(
        j`Cannot set state before store is ready. You can get the current status with store.status,
        or await store.readyPromise to wait for the store to be ready before sending events.
        ${JSON.stringify(
          {
            newState: n,
            id: this.id,
            actor: this.actor,
            environment: this.environment
          },
          null,
          2
        )}`
      );
    this.state = n;
    let o = {
      type: t.InternalEventType.SET_STATE,
      payload: {
        state: n,
        previousState: r
      }
    };
    this.emitToChannel(o, { actor: this.actor }), this.emitToListeners(o, { actor: this.actor });
  }
  /**
   * Subscribes to state changes
   *
   * @returns Unsubscribe function
   */
  onStateChange(e) {
    return this.debug("onStateChange", { listener: e }), this.subscribe(
      t.InternalEventType.SET_STATE,
      ({ payload: r }, n) => {
        e(r.state, r.previousState, n);
      }
    );
  }
  emitToChannel(e, r) {
    this.debug("emitToChannel", { event: e, eventInfo: r, channel: !!this.channel }), this.channel?.emit(this.channelEventName, {
      event: e,
      eventInfo: r
    });
  }
  prepareThis({
    channel: e,
    environment: r
  }) {
    this.channel = e, this.environment = r, this.debug("prepared", { channel: !!e, environment: r }), this.channel.on(this.channelEventName, this.handleChannelEvents), this.actor.type === t.ActorType.LEADER ? this.emitToChannel(
      { type: t.InternalEventType.LEADER_CREATED },
      { actor: this.actor }
    ) : (this.emitToChannel(
      { type: t.InternalEventType.FOLLOWER_CREATED },
      { actor: this.actor }
    ), this.emitToChannel(
      { type: t.InternalEventType.EXISTING_STATE_REQUEST },
      { actor: this.actor }
    ), setTimeout(() => {
      this.syncing.reject(
        new TypeError(
          `No existing state found for follower with id: '${this.id}'. Make sure a leader with the same id exists before creating a follower.`
        )
      );
    }, 1e3));
  }
  emitToListeners(e, r) {
    let n = this.listeners.get(e.type), o = this.listeners.get("*");
    this.debug("emitToListeners", {
      event: e,
      eventInfo: r,
      eventTypeListeners: n,
      everythingListeners: o
    }), [...n ?? [], ...o ?? []].forEach(
      (p) => p(e, r)
    );
  }
  handleChannelEvents(e) {
    let { event: r, eventInfo: n } = e;
    if ([n.actor.id, n.forwardingActor?.id].includes(this.actor.id)) {
      this.debug("handleChannelEvents: Ignoring event from self", { channelEvent: e });
      return;
    } else if (this.syncing?.state === x.PENDING && r.type !== t.InternalEventType.EXISTING_STATE_RESPONSE) {
      this.debug("handleChannelEvents: Ignoring event while syncing", { channelEvent: e });
      return;
    }
    if (this.debug("handleChannelEvents", { channelEvent: e }), this.actor.type === t.ActorType.LEADER) {
      let o = !0;
      switch (r.type) {
        case t.InternalEventType.EXISTING_STATE_REQUEST:
          o = !1;
          let p = {
            type: t.InternalEventType.EXISTING_STATE_RESPONSE,
            payload: this.state
          };
          this.debug("handleChannelEvents: responding to existing state request", {
            responseEvent: p
          }), this.emitToChannel(p, { actor: this.actor }), this.emitToListeners(p, { actor: this.actor });
          break;
        case t.InternalEventType.LEADER_CREATED:
          o = !1, this.syncing.state = x.REJECTED, this.debug("handleChannelEvents: erroring due to second leader being created", {
            event: r
          }), console.error(
            j`Detected multiple UniversalStore leaders created with the same id "${this.id}".
            Only one leader can exists at a time, your stores are now in an invalid state.
            Leaders detected:
            this: ${JSON.stringify(this.actor, null, 2)}
            other: ${JSON.stringify(n.actor, null, 2)}`
          );
          break;
      }
      o && (this.debug("handleChannelEvents: forwarding event", { channelEvent: e }), this.emitToChannel(r, { actor: n.actor, forwardingActor: this.actor }));
    }
    if (this.actor.type === t.ActorType.FOLLOWER)
      switch (r.type) {
        case t.InternalEventType.EXISTING_STATE_RESPONSE:
          if (this.debug("handleChannelEvents: Setting state from leader's existing state response", {
            event: r
          }), this.syncing?.state !== x.PENDING)
            break;
          this.syncing.resolve?.();
          let o = {
            type: t.InternalEventType.SET_STATE,
            payload: {
              state: r.payload,
              previousState: this.state
            }
          };
          this.state = r.payload, this.emitToListeners(o, n);
          break;
      }
    switch (r.type) {
      case t.InternalEventType.SET_STATE:
        this.debug("handleChannelEvents: Setting state", { event: r }), this.state = r.payload.state;
        break;
    }
    this.emitToListeners(r, { actor: n.actor });
  }
  debug(e, r) {
    this.debugging && console.debug(
      j`[UniversalStore::${this.id}::${this.environment ?? t.Environment.UNKNOWN}]
        ${e}`,
      JSON.stringify(
        {
          data: r,
          actor: this.actor,
          state: this.state,
          status: this.status
        },
        null,
        2
      )
    );
  }
  /**
   * Used to reset the static fields of the UniversalStore class when cleaning up tests
   *
   * @internal
   */
  static __reset() {
    t.preparation.reject(new Error("reset")), t.setupPreparationPromise(), t.isInternalConstructing = !1;
  }
};

// src/channels/main.ts
var Pt = /* @__PURE__ */ s((t) => t.transports !== void 0, "isMulti"), Ot = /* @__PURE__ */ s(() => Math.random().toString(16).slice(2), "generateRandomId"), J = class {
  constructor(e = {}) {
    this.sender = Ot();
    this.events = {};
    this.data = {};
    this.transports = [];
    this.isAsync = e.async || !1, Pt(e) ? (this.transports = e.transports || [], this.transports.forEach((r) => {
      r.setHandler((n) => this.handleEvent(n));
    })) : this.transports = e.transport ? [e.transport] : [], this.transports.forEach((r) => {
      r.setHandler((n) => this.handleEvent(n));
    });
  }
  static {
    s(this, "Channel");
  }
  get hasTransport() {
    return this.transports.length > 0;
  }
  addListener(e, r) {
    this.events[e] = this.events[e] || [], this.events[e].push(r);
  }
  emit(e, ...r) {
    let n = { type: e, args: r, from: this.sender }, o = {};
    r.length >= 1 && r[0] && r[0].options && (o = r[0].options);
    let p = /* @__PURE__ */ s(() => {
      this.transports.forEach((a) => {
        a.send(n, o);
      }), this.handleEvent(n);
    }, "handler");
    this.isAsync ? setImmediate(p) : p();
  }
  last(e) {
    return this.data[e];
  }
  eventNames() {
    return Object.keys(this.events);
  }
  listenerCount(e) {
    let r = this.listeners(e);
    return r ? r.length : 0;
  }
  listeners(e) {
    return this.events[e] || void 0;
  }
  once(e, r) {
    let n = this.onceListener(e, r);
    this.addListener(e, n);
  }
  removeAllListeners(e) {
    e ? this.events[e] && delete this.events[e] : this.events = {};
  }
  removeListener(e, r) {
    let n = this.listeners(e);
    n && (this.events[e] = n.filter((o) => o !== r));
  }
  on(e, r) {
    this.addListener(e, r);
  }
  off(e, r) {
    this.removeListener(e, r);
  }
  handleEvent(e) {
    let r = this.listeners(e.type);
    r && r.length && r.forEach((n) => {
      n.apply(e, e.args);
    }), this.data[e.type] = e.args;
  }
  onceListener(e, r) {
    let n = /* @__PURE__ */ s((...o) => (this.removeListener(e, n), r(...o)), "onceListener");
    return n;
  }
};

// src/channels/postmessage/index.ts
import { logger as st, pretty as it } from "storybook/internal/client-logger";
import * as Do from "storybook/internal/core-events";
import { global as b } from "@storybook/global";

// ../node_modules/telejson/dist/chunk-EAFQLD22.mjs
var Ct = Object.create, je = Object.defineProperty, Nt = Object.getOwnPropertyDescriptor, Le = Object.getOwnPropertyNames, It = Object.getPrototypeOf, Rt = Object.prototype.hasOwnProperty, f = /* @__PURE__ */ s((t, e) => /* @__PURE__ */ s(function() {
  return e || (0, t[Le(t)[0]])((e = { exports: {} }).exports, e), e.exports;
}, "__require"), "__commonJS"), jt = /* @__PURE__ */ s((t, e, r, n) => {
  if (e && typeof e == "object" || typeof e == "function")
    for (let o of Le(e))
      !Rt.call(t, o) && o !== r && je(t, o, { get: /* @__PURE__ */ s(() => e[o], "get"), enumerable: !(n = Nt(e, o)) || n.enumerable });
  return t;
}, "__copyProps"), ae = /* @__PURE__ */ s((t, e, r) => (r = t != null ? Ct(It(t)) : {}, jt(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  e || !t || !t.__esModule ? je(r, "default", { value: t, enumerable: !0 }) : r,
  t
)), "__toESM"), Lt = [
  "bubbles",
  "cancelBubble",
  "cancelable",
  "composed",
  "currentTarget",
  "defaultPrevented",
  "eventPhase",
  "isTrusted",
  "returnValue",
  "srcElement",
  "target",
  "timeStamp",
  "type"
], Dt = ["detail"];
function De(t) {
  let e = Lt.filter((r) => t[r] !== void 0).reduce((r, n) => (r[n] = t[n], r), {});
  if (t instanceof CustomEvent)
    for (let r of Dt.filter(
      (n) => t[n] !== void 0
    ))
      e[r] = t[r];
  return e;
}
s(De, "extractEventHiddenProperties");

// ../node_modules/telejson/dist/index.mjs
var ke = f({
  "node_modules/.pnpm/es-object-atoms@1.1.1/node_modules/es-object-atoms/index.js"(t, e) {
    "use strict";
    e.exports = Object;
  }
}), $t = f({
  "node_modules/.pnpm/es-errors@1.3.0/node_modules/es-errors/index.js"(t, e) {
    "use strict";
    e.exports = Error;
  }
}), Ft = f({
  "node_modules/.pnpm/es-errors@1.3.0/node_modules/es-errors/eval.js"(t, e) {
    "use strict";
    e.exports = EvalError;
  }
}), Mt = f({
  "node_modules/.pnpm/es-errors@1.3.0/node_modules/es-errors/range.js"(t, e) {
    "use strict";
    e.exports = RangeError;
  }
}), Ut = f({
  "node_modules/.pnpm/es-errors@1.3.0/node_modules/es-errors/ref.js"(t, e) {
    "use strict";
    e.exports = ReferenceError;
  }
}), Gt = f({
  "node_modules/.pnpm/es-errors@1.3.0/node_modules/es-errors/syntax.js"(t, e) {
    "use strict";
    e.exports = SyntaxError;
  }
}), me = f({
  "node_modules/.pnpm/es-errors@1.3.0/node_modules/es-errors/type.js"(t, e) {
    "use strict";
    e.exports = TypeError;
  }
}), kt = f({
  "node_modules/.pnpm/es-errors@1.3.0/node_modules/es-errors/uri.js"(t, e) {
    "use strict";
    e.exports = URIError;
  }
}), Wt = f({
  "node_modules/.pnpm/math-intrinsics@1.1.0/node_modules/math-intrinsics/abs.js"(t, e) {
    "use strict";
    e.exports = Math.abs;
  }
}), qt = f({
  "node_modules/.pnpm/math-intrinsics@1.1.0/node_modules/math-intrinsics/floor.js"(t, e) {
    "use strict";
    e.exports = Math.floor;
  }
}), Bt = f({
  "node_modules/.pnpm/math-intrinsics@1.1.0/node_modules/math-intrinsics/max.js"(t, e) {
    "use strict";
    e.exports = Math.max;
  }
}), Ht = f({
  "node_modules/.pnpm/math-intrinsics@1.1.0/node_modules/math-intrinsics/min.js"(t, e) {
    "use strict";
    e.exports = Math.min;
  }
}), Vt = f({
  "node_modules/.pnpm/math-intrinsics@1.1.0/node_modules/math-intrinsics/pow.js"(t, e) {
    "use strict";
    e.exports = Math.pow;
  }
}), Jt = f({
  "node_modules/.pnpm/math-intrinsics@1.1.0/node_modules/math-intrinsics/round.js"(t, e) {
    "use strict";
    e.exports = Math.round;
  }
}), zt = f({
  "node_modules/.pnpm/math-intrinsics@1.1.0/node_modules/math-intrinsics/isNaN.js"(t, e) {
    "use strict";
    e.exports = Number.isNaN || /* @__PURE__ */ s(function(n) {
      return n !== n;
    }, "isNaN2");
  }
}), Yt = f({
  "node_modules/.pnpm/math-intrinsics@1.1.0/node_modules/math-intrinsics/sign.js"(t, e) {
    "use strict";
    var r = zt();
    e.exports = /* @__PURE__ */ s(function(o) {
      return r(o) || o === 0 ? o : o < 0 ? -1 : 1;
    }, "sign");
  }
}), Kt = f({
  "node_modules/.pnpm/gopd@1.2.0/node_modules/gopd/gOPD.js"(t, e) {
    "use strict";
    e.exports = Object.getOwnPropertyDescriptor;
  }
}), ve = f({
  "node_modules/.pnpm/gopd@1.2.0/node_modules/gopd/index.js"(t, e) {
    "use strict";
    var r = Kt();
    if (r)
      try {
        r([], "length");
      } catch {
        r = null;
      }
    e.exports = r;
  }
}), Xt = f({
  "node_modules/.pnpm/es-define-property@1.0.1/node_modules/es-define-property/index.js"(t, e) {
    "use strict";
    var r = Object.defineProperty || !1;
    if (r)
      try {
        r({}, "a", { value: 1 });
      } catch {
        r = !1;
      }
    e.exports = r;
  }
}), We = f({
  "node_modules/.pnpm/has-symbols@1.1.0/node_modules/has-symbols/shams.js"(t, e) {
    "use strict";
    e.exports = /* @__PURE__ */ s(function() {
      if (typeof Symbol != "function" || typeof Object.getOwnPropertySymbols != "function")
        return !1;
      if (typeof Symbol.iterator == "symbol")
        return !0;
      var n = {}, o = Symbol("test"), p = Object(o);
      if (typeof o == "string" || Object.prototype.toString.call(o) !== "[object Symbol]" || Object.prototype.toString.call(p) !== "[object Symbol]")
        return !1;
      var a = 42;
      n[o] = a;
      for (var c in n)
        return !1;
      if (typeof Object.keys == "function" && Object.keys(n).length !== 0 || typeof Object.getOwnPropertyNames == "function" && Object.getOwnPropertyNames(n).length !== 0)
        return !1;
      var i = Object.getOwnPropertySymbols(n);
      if (i.length !== 1 || i[0] !== o || !Object.prototype.propertyIsEnumerable.call(n, o))
        return !1;
      if (typeof Object.getOwnPropertyDescriptor == "function") {
        var l = (
          /** @type {PropertyDescriptor} */
          Object.getOwnPropertyDescriptor(n, o)
        );
        if (l.value !== a || l.enumerable !== !0)
          return !1;
      }
      return !0;
    }, "hasSymbols");
  }
}), qe = f({
  "node_modules/.pnpm/has-symbols@1.1.0/node_modules/has-symbols/index.js"(t, e) {
    "use strict";
    var r = typeof Symbol < "u" && Symbol, n = We();
    e.exports = /* @__PURE__ */ s(function() {
      return typeof r != "function" || typeof Symbol != "function" || typeof r("foo") != "symbol" || typeof Symbol("bar") != "symbol" ? !1 : n();
    }, "hasNativeSymbols");
  }
}), Be = f({
  "node_modules/.pnpm/get-proto@1.0.1/node_modules/get-proto/Reflect.getPrototypeOf.js"(t, e) {
    "use strict";
    e.exports = typeof Reflect < "u" && Reflect.getPrototypeOf || null;
  }
}), He = f({
  "node_modules/.pnpm/get-proto@1.0.1/node_modules/get-proto/Object.getPrototypeOf.js"(t, e) {
    "use strict";
    var r = ke();
    e.exports = r.getPrototypeOf || null;
  }
}), Qt = f({
  "node_modules/.pnpm/function-bind@1.1.2/node_modules/function-bind/implementation.js"(t, e) {
    "use strict";
    var r = "Function.prototype.bind called on incompatible ", n = Object.prototype.toString, o = Math.max, p = "[object Function]", a = /* @__PURE__ */ s(function(d, u) {
      for (var y = [], g = 0; g < d.length; g += 1)
        y[g] = d[g];
      for (var h = 0; h < u.length; h += 1)
        y[h + d.length] = u[h];
      return y;
    }, "concatty2"), c = /* @__PURE__ */ s(function(d, u) {
      for (var y = [], g = u || 0, h = 0; g < d.length; g += 1, h += 1)
        y[h] = d[g];
      return y;
    }, "slicy2"), i = /* @__PURE__ */ s(function(l, d) {
      for (var u = "", y = 0; y < l.length; y += 1)
        u += l[y], y + 1 < l.length && (u += d);
      return u;
    }, "joiny");
    e.exports = /* @__PURE__ */ s(function(d) {
      var u = this;
      if (typeof u != "function" || n.apply(u) !== p)
        throw new TypeError(r + u);
      for (var y = c(arguments, 1), g, h = /* @__PURE__ */ s(function() {
        if (this instanceof g) {
          var I = u.apply(
            this,
            a(y, arguments)
          );
          return Object(I) === I ? I : this;
        }
        return u.apply(
          d,
          a(y, arguments)
        );
      }, "binder"), C = o(0, u.length - y.length), w = [], A = 0; A < C; A++)
        w[A] = "$" + A;
      if (g = Function("binder", "return function (" + i(w, ",") + "){ return binder.apply(this,arguments); }")(h), u.prototype) {
        var L = /* @__PURE__ */ s(function() {
        }, "Empty2");
        L.prototype = u.prototype, g.prototype = new L(), L.prototype = null;
      }
      return g;
    }, "bind");
  }
}), pe = f({
  "node_modules/.pnpm/function-bind@1.1.2/node_modules/function-bind/index.js"(t, e) {
    "use strict";
    var r = Qt();
    e.exports = Function.prototype.bind || r;
  }
}), Ee = f({
  "node_modules/.pnpm/call-bind-apply-helpers@1.0.2/node_modules/call-bind-apply-helpers/functionCall.js"(t, e) {
    "use strict";
    e.exports = Function.prototype.call;
  }
}), Ve = f({
  "node_modules/.pnpm/call-bind-apply-helpers@1.0.2/node_modules/call-bind-apply-helpers/functionApply.js"(t, e) {
    "use strict";
    e.exports = Function.prototype.apply;
  }
}), Zt = f({
  "node_modules/.pnpm/call-bind-apply-helpers@1.0.2/node_modules/call-bind-apply-helpers/reflectApply.js"(t, e) {
    "use strict";
    e.exports = typeof Reflect < "u" && Reflect && Reflect.apply;
  }
}), er = f({
  "node_modules/.pnpm/call-bind-apply-helpers@1.0.2/node_modules/call-bind-apply-helpers/actualApply.js"(t, e) {
    "use strict";
    var r = pe(), n = Ve(), o = Ee(), p = Zt();
    e.exports = p || r.call(o, n);
  }
}), Je = f({
  "node_modules/.pnpm/call-bind-apply-helpers@1.0.2/node_modules/call-bind-apply-helpers/index.js"(t, e) {
    "use strict";
    var r = pe(), n = me(), o = Ee(), p = er();
    e.exports = /* @__PURE__ */ s(function(c) {
      if (c.length < 1 || typeof c[0] != "function")
        throw new n("a function is required");
      return p(r, o, c);
    }, "callBindBasic");
  }
}), tr = f({
  "node_modules/.pnpm/dunder-proto@1.0.1/node_modules/dunder-proto/get.js"(t, e) {
    "use strict";
    var r = Je(), n = ve(), o;
    try {
      o = /** @type {{ __proto__?: typeof Array.prototype }} */
      [].__proto__ === Array.prototype;
    } catch (i) {
      if (!i || typeof i != "object" || !("code" in i) || i.code !== "ERR_PROTO_ACCESS")
        throw i;
    }
    var p = !!o && n && n(
      Object.prototype,
      /** @type {keyof typeof Object.prototype} */
      "__proto__"
    ), a = Object, c = a.getPrototypeOf;
    e.exports = p && typeof p.get == "function" ? r([p.get]) : typeof c == "function" ? (
      /** @type {import('./get')} */
      /* @__PURE__ */ s(function(l) {
        return c(l == null ? l : a(l));
      }, "getDunder")
    ) : !1;
  }
}), rr = f({
  "node_modules/.pnpm/get-proto@1.0.1/node_modules/get-proto/index.js"(t, e) {
    "use strict";
    var r = Be(), n = He(), o = tr();
    e.exports = r ? /* @__PURE__ */ s(function(a) {
      return r(a);
    }, "getProto") : n ? /* @__PURE__ */ s(function(a) {
      if (!a || typeof a != "object" && typeof a != "function")
        throw new TypeError("getProto: not an object");
      return n(a);
    }, "getProto") : o ? /* @__PURE__ */ s(function(a) {
      return o(a);
    }, "getProto") : null;
  }
}), ze = f({
  "node_modules/.pnpm/hasown@2.0.2/node_modules/hasown/index.js"(t, e) {
    "use strict";
    var r = Function.prototype.call, n = Object.prototype.hasOwnProperty, o = pe();
    e.exports = o.call(r, n);
  }
}), nr = f({
  "node_modules/.pnpm/get-intrinsic@1.3.0/node_modules/get-intrinsic/index.js"(t, e) {
    "use strict";
    var r, n = ke(), o = $t(), p = Ft(), a = Mt(), c = Ut(), i = Gt(), l = me(), d = kt(), u = Wt(), y = qt(), g = Bt(), h = Ht(), C = Vt(), w = Jt(), A = Yt(), L = Function, I = /* @__PURE__ */ s(function(P) {
      try {
        return L('"use strict"; return (' + P + ").constructor;")();
      } catch {
      }
    }, "getEvalledConstructor"), q = ve(), ft = Xt(), de = /* @__PURE__ */ s(function() {
      throw new l();
    }, "throwTypeError"), dt = q ? function() {
      try {
        return arguments.callee, de;
      } catch {
        try {
          return q(arguments, "callee").get;
        } catch {
          return de;
        }
      }
    }() : de, D = qe()(), E = rr(), yt = He(), ht = Be(), Ce = Ve(), B = Ee(), $ = {}, gt = typeof Uint8Array > "u" || !E ? r : E(Uint8Array), R = {
      __proto__: null,
      "%AggregateError%": typeof AggregateError > "u" ? r : AggregateError,
      "%Array%": Array,
      "%ArrayBuffer%": typeof ArrayBuffer > "u" ? r : ArrayBuffer,
      "%ArrayIteratorPrototype%": D && E ? E([][Symbol.iterator]()) : r,
      "%AsyncFromSyncIteratorPrototype%": r,
      "%AsyncFunction%": $,
      "%AsyncGenerator%": $,
      "%AsyncGeneratorFunction%": $,
      "%AsyncIteratorPrototype%": $,
      "%Atomics%": typeof Atomics > "u" ? r : Atomics,
      "%BigInt%": typeof BigInt > "u" ? r : BigInt,
      "%BigInt64Array%": typeof BigInt64Array > "u" ? r : BigInt64Array,
      "%BigUint64Array%": typeof BigUint64Array > "u" ? r : BigUint64Array,
      "%Boolean%": Boolean,
      "%DataView%": typeof DataView > "u" ? r : DataView,
      "%Date%": Date,
      "%decodeURI%": decodeURI,
      "%decodeURIComponent%": decodeURIComponent,
      "%encodeURI%": encodeURI,
      "%encodeURIComponent%": encodeURIComponent,
      "%Error%": o,
      "%eval%": eval,
      // eslint-disable-line no-eval
      "%EvalError%": p,
      "%Float16Array%": typeof Float16Array > "u" ? r : Float16Array,
      "%Float32Array%": typeof Float32Array > "u" ? r : Float32Array,
      "%Float64Array%": typeof Float64Array > "u" ? r : Float64Array,
      "%FinalizationRegistry%": typeof FinalizationRegistry > "u" ? r : FinalizationRegistry,
      "%Function%": L,
      "%GeneratorFunction%": $,
      "%Int8Array%": typeof Int8Array > "u" ? r : Int8Array,
      "%Int16Array%": typeof Int16Array > "u" ? r : Int16Array,
      "%Int32Array%": typeof Int32Array > "u" ? r : Int32Array,
      "%isFinite%": isFinite,
      "%isNaN%": isNaN,
      "%IteratorPrototype%": D && E ? E(E([][Symbol.iterator]())) : r,
      "%JSON%": typeof JSON == "object" ? JSON : r,
      "%Map%": typeof Map > "u" ? r : Map,
      "%MapIteratorPrototype%": typeof Map > "u" || !D || !E ? r : E((/* @__PURE__ */ new Map())[Symbol.iterator]()),
      "%Math%": Math,
      "%Number%": Number,
      "%Object%": n,
      "%Object.getOwnPropertyDescriptor%": q,
      "%parseFloat%": parseFloat,
      "%parseInt%": parseInt,
      "%Promise%": typeof Promise > "u" ? r : Promise,
      "%Proxy%": typeof Proxy > "u" ? r : Proxy,
      "%RangeError%": a,
      "%ReferenceError%": c,
      "%Reflect%": typeof Reflect > "u" ? r : Reflect,
      "%RegExp%": RegExp,
      "%Set%": typeof Set > "u" ? r : Set,
      "%SetIteratorPrototype%": typeof Set > "u" || !D || !E ? r : E((/* @__PURE__ */ new Set())[Symbol.iterator]()),
      "%SharedArrayBuffer%": typeof SharedArrayBuffer > "u" ? r : SharedArrayBuffer,
      "%String%": String,
      "%StringIteratorPrototype%": D && E ? E(""[Symbol.iterator]()) : r,
      "%Symbol%": D ? Symbol : r,
      "%SyntaxError%": i,
      "%ThrowTypeError%": dt,
      "%TypedArray%": gt,
      "%TypeError%": l,
      "%Uint8Array%": typeof Uint8Array > "u" ? r : Uint8Array,
      "%Uint8ClampedArray%": typeof Uint8ClampedArray > "u" ? r : Uint8ClampedArray,
      "%Uint16Array%": typeof Uint16Array > "u" ? r : Uint16Array,
      "%Uint32Array%": typeof Uint32Array > "u" ? r : Uint32Array,
      "%URIError%": d,
      "%WeakMap%": typeof WeakMap > "u" ? r : WeakMap,
      "%WeakRef%": typeof WeakRef > "u" ? r : WeakRef,
      "%WeakSet%": typeof WeakSet > "u" ? r : WeakSet,
      "%Function.prototype.call%": B,
      "%Function.prototype.apply%": Ce,
      "%Object.defineProperty%": ft,
      "%Object.getPrototypeOf%": yt,
      "%Math.abs%": u,
      "%Math.floor%": y,
      "%Math.max%": g,
      "%Math.min%": h,
      "%Math.pow%": C,
      "%Math.round%": w,
      "%Math.sign%": A,
      "%Reflect.getPrototypeOf%": ht
    };
    if (E)
      try {
        null.error;
      } catch (P) {
        Ne = E(E(P)), R["%Error.prototype%"] = Ne;
      }
    var Ne, mt = /* @__PURE__ */ s(function P(m) {
      var _;
      if (m === "%AsyncFunction%")
        _ = I("async function () {}");
      else if (m === "%GeneratorFunction%")
        _ = I("function* () {}");
      else if (m === "%AsyncGeneratorFunction%")
        _ = I("async function* () {}");
      else if (m === "%AsyncGenerator%") {
        var v = P("%AsyncGeneratorFunction%");
        v && (_ = v.prototype);
      } else if (m === "%AsyncIteratorPrototype%") {
        var S = P("%AsyncGenerator%");
        S && E && (_ = E(S.prototype));
      }
      return R[m] = _, _;
    }, "doEval2"), Ie = {
      __proto__: null,
      "%ArrayBufferPrototype%": ["ArrayBuffer", "prototype"],
      "%ArrayPrototype%": ["Array", "prototype"],
      "%ArrayProto_entries%": ["Array", "prototype", "entries"],
      "%ArrayProto_forEach%": ["Array", "prototype", "forEach"],
      "%ArrayProto_keys%": ["Array", "prototype", "keys"],
      "%ArrayProto_values%": ["Array", "prototype", "values"],
      "%AsyncFunctionPrototype%": ["AsyncFunction", "prototype"],
      "%AsyncGenerator%": ["AsyncGeneratorFunction", "prototype"],
      "%AsyncGeneratorPrototype%": ["AsyncGeneratorFunction", "prototype", "prototype"],
      "%BooleanPrototype%": ["Boolean", "prototype"],
      "%DataViewPrototype%": ["DataView", "prototype"],
      "%DatePrototype%": ["Date", "prototype"],
      "%ErrorPrototype%": ["Error", "prototype"],
      "%EvalErrorPrototype%": ["EvalError", "prototype"],
      "%Float32ArrayPrototype%": ["Float32Array", "prototype"],
      "%Float64ArrayPrototype%": ["Float64Array", "prototype"],
      "%FunctionPrototype%": ["Function", "prototype"],
      "%Generator%": ["GeneratorFunction", "prototype"],
      "%GeneratorPrototype%": ["GeneratorFunction", "prototype", "prototype"],
      "%Int8ArrayPrototype%": ["Int8Array", "prototype"],
      "%Int16ArrayPrototype%": ["Int16Array", "prototype"],
      "%Int32ArrayPrototype%": ["Int32Array", "prototype"],
      "%JSONParse%": ["JSON", "parse"],
      "%JSONStringify%": ["JSON", "stringify"],
      "%MapPrototype%": ["Map", "prototype"],
      "%NumberPrototype%": ["Number", "prototype"],
      "%ObjectPrototype%": ["Object", "prototype"],
      "%ObjProto_toString%": ["Object", "prototype", "toString"],
      "%ObjProto_valueOf%": ["Object", "prototype", "valueOf"],
      "%PromisePrototype%": ["Promise", "prototype"],
      "%PromiseProto_then%": ["Promise", "prototype", "then"],
      "%Promise_all%": ["Promise", "all"],
      "%Promise_reject%": ["Promise", "reject"],
      "%Promise_resolve%": ["Promise", "resolve"],
      "%RangeErrorPrototype%": ["RangeError", "prototype"],
      "%ReferenceErrorPrototype%": ["ReferenceError", "prototype"],
      "%RegExpPrototype%": ["RegExp", "prototype"],
      "%SetPrototype%": ["Set", "prototype"],
      "%SharedArrayBufferPrototype%": ["SharedArrayBuffer", "prototype"],
      "%StringPrototype%": ["String", "prototype"],
      "%SymbolPrototype%": ["Symbol", "prototype"],
      "%SyntaxErrorPrototype%": ["SyntaxError", "prototype"],
      "%TypedArrayPrototype%": ["TypedArray", "prototype"],
      "%TypeErrorPrototype%": ["TypeError", "prototype"],
      "%Uint8ArrayPrototype%": ["Uint8Array", "prototype"],
      "%Uint8ClampedArrayPrototype%": ["Uint8ClampedArray", "prototype"],
      "%Uint16ArrayPrototype%": ["Uint16Array", "prototype"],
      "%Uint32ArrayPrototype%": ["Uint32Array", "prototype"],
      "%URIErrorPrototype%": ["URIError", "prototype"],
      "%WeakMapPrototype%": ["WeakMap", "prototype"],
      "%WeakSetPrototype%": ["WeakSet", "prototype"]
    }, H = pe(), ee = ze(), vt = H.call(B, Array.prototype.concat), Et = H.call(Ce, Array.prototype.splice), Re = H.call(B, String.prototype.replace), te = H.call(B, String.prototype.slice), _t = H.call(B, RegExp.prototype.exec), bt = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g, St = /\\(\\)?/g, Tt = /* @__PURE__ */ s(function(m) {
      var _ = te(m, 0, 1), v = te(m, -1);
      if (_ === "%" && v !== "%")
        throw new i("invalid intrinsic syntax, expected closing `%`");
      if (v === "%" && _ !== "%")
        throw new i("invalid intrinsic syntax, expected opening `%`");
      var S = [];
      return Re(m, bt, function(O, F, T, re) {
        S[S.length] = T ? Re(re, St, "$1") : F || O;
      }), S;
    }, "stringToPath3"), At = /* @__PURE__ */ s(function(m, _) {
      var v = m, S;
      if (ee(Ie, v) && (S = Ie[v], v = "%" + S[0] + "%"), ee(R, v)) {
        var O = R[v];
        if (O === $ && (O = mt(v)), typeof O > "u" && !_)
          throw new l("intrinsic " + m + " exists, but is not available. Please file an issue!");
        return {
          alias: S,
          name: v,
          value: O
        };
      }
      throw new i("intrinsic " + m + " does not exist!");
    }, "getBaseIntrinsic2");
    e.exports = /* @__PURE__ */ s(function(m, _) {
      if (typeof m != "string" || m.length === 0)
        throw new l("intrinsic name must be a non-empty string");
      if (arguments.length > 1 && typeof _ != "boolean")
        throw new l('"allowMissing" argument must be a boolean');
      if (_t(/^%?[^%]*%?$/, m) === null)
        throw new i("`%` may not be present anywhere but at the beginning and end of the intrinsic name");
      var v = Tt(m), S = v.length > 0 ? v[0] : "", O = At("%" + S + "%", _), F = O.name, T = O.value, re = !1, ye = O.alias;
      ye && (S = ye[0], Et(v, vt([0, 1], ye)));
      for (var ne = 1, V = !0; ne < v.length; ne += 1) {
        var N = v[ne], oe = te(N, 0, 1), se = te(N, -1);
        if ((oe === '"' || oe === "'" || oe === "`" || se === '"' || se === "'" || se === "`") && oe !== se)
          throw new i("property names with quotes must have matching quotes");
        if ((N === "constructor" || !V) && (re = !0), S += "." + N, F = "%" + S + "%", ee(R, F))
          T = R[F];
        else if (T != null) {
          if (!(N in T)) {
            if (!_)
              throw new l("base intrinsic for " + m + " exists, but the property is not available.");
            return;
          }
          if (q && ne + 1 >= v.length) {
            var ie = q(T, N);
            V = !!ie, V && "get" in ie && !("originalValue" in ie.get) ? T = ie.get : T = T[N];
          } else
            V = ee(T, N), T = T[N];
          V && !re && (R[F] = T);
        }
      }
      return T;
    }, "GetIntrinsic");
  }
}), _e = f({
  "node_modules/.pnpm/call-bound@1.0.4/node_modules/call-bound/index.js"(t, e) {
    "use strict";
    var r = nr(), n = Je(), o = n([r("%String.prototype.indexOf%")]);
    e.exports = /* @__PURE__ */ s(function(a, c) {
      var i = (
        /** @type {(this: unknown, ...args: unknown[]) => unknown} */
        r(a, !!c)
      );
      return typeof i == "function" && o(a, ".prototype.") > -1 ? n(
        /** @type {const} */
        [i]
      ) : i;
    }, "callBoundIntrinsic");
  }
}), or = f({
  "node_modules/.pnpm/has-tostringtag@1.0.2/node_modules/has-tostringtag/shams.js"(t, e) {
    "use strict";
    var r = We();
    e.exports = /* @__PURE__ */ s(function() {
      return r() && !!Symbol.toStringTag;
    }, "hasToStringTagShams");
  }
}), Ye = f({
  "node_modules/.pnpm/is-regex@1.2.1/node_modules/is-regex/index.js"(t, e) {
    "use strict";
    var r = _e(), n = or()(), o = ze(), p = ve(), a;
    n ? (c = r("RegExp.prototype.exec"), i = {}, l = /* @__PURE__ */ s(function() {
      throw i;
    }, "throwRegexMarker"), d = {
      toString: l,
      valueOf: l
    }, typeof Symbol.toPrimitive == "symbol" && (d[Symbol.toPrimitive] = l), a = /* @__PURE__ */ s(function(h) {
      if (!h || typeof h != "object")
        return !1;
      var C = (
        /** @type {NonNullable<typeof gOPD>} */
        p(
          /** @type {{ lastIndex?: unknown }} */
          h,
          "lastIndex"
        )
      ), w = C && o(C, "value");
      if (!w)
        return !1;
      try {
        c(
          h,
          /** @type {string} */
          /** @type {unknown} */
          d
        );
      } catch (A) {
        return A === i;
      }
    }, "isRegex")) : (u = r("Object.prototype.toString"), y = "[object RegExp]", a = /* @__PURE__ */ s(function(h) {
      return !h || typeof h != "object" && typeof h != "function" ? !1 : u(h) === y;
    }, "isRegex"));
    var c, i, l, d, u, y;
    e.exports = a;
  }
}), sr = f({
  "node_modules/.pnpm/is-function@1.0.2/node_modules/is-function/index.js"(t, e) {
    e.exports = n;
    var r = Object.prototype.toString;
    function n(o) {
      if (!o)
        return !1;
      var p = r.call(o);
      return p === "[object Function]" || typeof o == "function" && p !== "[object RegExp]" || typeof window < "u" && // IE8 and below
      (o === window.setTimeout || o === window.alert || o === window.confirm || o === window.prompt);
    }
    s(n, "isFunction3");
  }
}), ir = f({
  "node_modules/.pnpm/safe-regex-test@1.1.0/node_modules/safe-regex-test/index.js"(t, e) {
    "use strict";
    var r = _e(), n = Ye(), o = r("RegExp.prototype.exec"), p = me();
    e.exports = /* @__PURE__ */ s(function(c) {
      if (!n(c))
        throw new p("`regex` must be a RegExp");
      return /* @__PURE__ */ s(function(l) {
        return o(c, l) !== null;
      }, "test");
    }, "regexTester");
  }
}), ar = f({
  "node_modules/.pnpm/is-symbol@1.1.1/node_modules/is-symbol/index.js"(t, e) {
    "use strict";
    var r = _e(), n = r("Object.prototype.toString"), o = qe()(), p = ir();
    o ? (a = r("Symbol.prototype.toString"), c = p(/^Symbol\(.*\)$/), i = /* @__PURE__ */ s(function(d) {
      return typeof d.valueOf() != "symbol" ? !1 : c(a(d));
    }, "isRealSymbolObject"), e.exports = /* @__PURE__ */ s(function(d) {
      if (typeof d == "symbol")
        return !0;
      if (!d || typeof d != "object" || n(d) !== "[object Symbol]")
        return !1;
      try {
        return i(d);
      } catch {
        return !1;
      }
    }, "isSymbol3")) : e.exports = /* @__PURE__ */ s(function(d) {
      return !1;
    }, "isSymbol3");
    var a, c, i;
  }
}), pr = ae(Ye()), cr = ae(sr()), lr = ae(ar());
function ur(t) {
  return t != null && typeof t == "object" && Array.isArray(t) === !1;
}
s(ur, "isObject");
var fr = typeof global == "object" && global && global.Object === Object && global, dr = fr, yr = typeof self == "object" && self && self.Object === Object && self, hr = dr || yr || Function("return this")(), be = hr, gr = be.Symbol, U = gr, Ke = Object.prototype, mr = Ke.hasOwnProperty, vr = Ke.toString, z = U ? U.toStringTag : void 0;
function Er(t) {
  var e = mr.call(t, z), r = t[z];
  try {
    t[z] = void 0;
    var n = !0;
  } catch {
  }
  var o = vr.call(t);
  return n && (e ? t[z] = r : delete t[z]), o;
}
s(Er, "getRawTag");
var _r = Er, br = Object.prototype, Sr = br.toString;
function Tr(t) {
  return Sr.call(t);
}
s(Tr, "objectToString");
var Ar = Tr, xr = "[object Null]", wr = "[object Undefined]", $e = U ? U.toStringTag : void 0;
function Pr(t) {
  return t == null ? t === void 0 ? wr : xr : $e && $e in Object(t) ? _r(t) : Ar(t);
}
s(Pr, "baseGetTag");
var Xe = Pr;
function Or(t) {
  return t != null && typeof t == "object";
}
s(Or, "isObjectLike");
var Cr = Or, Nr = "[object Symbol]";
function Ir(t) {
  return typeof t == "symbol" || Cr(t) && Xe(t) == Nr;
}
s(Ir, "isSymbol");
var Se = Ir;
function Rr(t, e) {
  for (var r = -1, n = t == null ? 0 : t.length, o = Array(n); ++r < n; )
    o[r] = e(t[r], r, t);
  return o;
}
s(Rr, "arrayMap");
var jr = Rr, Lr = Array.isArray, Te = Lr, Dr = 1 / 0, Fe = U ? U.prototype : void 0, Me = Fe ? Fe.toString : void 0;
function Qe(t) {
  if (typeof t == "string")
    return t;
  if (Te(t))
    return jr(t, Qe) + "";
  if (Se(t))
    return Me ? Me.call(t) : "";
  var e = t + "";
  return e == "0" && 1 / t == -Dr ? "-0" : e;
}
s(Qe, "baseToString");
var $r = Qe;
function Fr(t) {
  var e = typeof t;
  return t != null && (e == "object" || e == "function");
}
s(Fr, "isObject2");
var Ze = Fr, Mr = "[object AsyncFunction]", Ur = "[object Function]", Gr = "[object GeneratorFunction]", kr = "[object Proxy]";
function Wr(t) {
  if (!Ze(t))
    return !1;
  var e = Xe(t);
  return e == Ur || e == Gr || e == Mr || e == kr;
}
s(Wr, "isFunction");
var qr = Wr, Br = be["__core-js_shared__"], ge = Br, Ue = function() {
  var t = /[^.]+$/.exec(ge && ge.keys && ge.keys.IE_PROTO || "");
  return t ? "Symbol(src)_1." + t : "";
}();
function Hr(t) {
  return !!Ue && Ue in t;
}
s(Hr, "isMasked");
var Vr = Hr, Jr = Function.prototype, zr = Jr.toString;
function Yr(t) {
  if (t != null) {
    try {
      return zr.call(t);
    } catch {
    }
    try {
      return t + "";
    } catch {
    }
  }
  return "";
}
s(Yr, "toSource");
var Kr = Yr, Xr = /[\\^$.*+?()[\]{}|]/g, Qr = /^\[object .+?Constructor\]$/, Zr = Function.prototype, en = Object.prototype, tn = Zr.toString, rn = en.hasOwnProperty, nn = RegExp(
  "^" + tn.call(rn).replace(Xr, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
);
function on(t) {
  if (!Ze(t) || Vr(t))
    return !1;
  var e = qr(t) ? nn : Qr;
  return e.test(Kr(t));
}
s(on, "baseIsNative");
var sn = on;
function an(t, e) {
  return t?.[e];
}
s(an, "getValue");
var pn = an;
function cn(t, e) {
  var r = pn(t, e);
  return sn(r) ? r : void 0;
}
s(cn, "getNative");
var et = cn;
function ln(t, e) {
  return t === e || t !== t && e !== e;
}
s(ln, "eq");
var un = ln, fn = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, dn = /^\w*$/;
function yn(t, e) {
  if (Te(t))
    return !1;
  var r = typeof t;
  return r == "number" || r == "symbol" || r == "boolean" || t == null || Se(t) ? !0 : dn.test(t) || !fn.test(t) || e != null && t in Object(e);
}
s(yn, "isKey");
var hn = yn, gn = et(Object, "create"), Y = gn;
function mn() {
  this.__data__ = Y ? Y(null) : {}, this.size = 0;
}
s(mn, "hashClear");
var vn = mn;
function En(t) {
  var e = this.has(t) && delete this.__data__[t];
  return this.size -= e ? 1 : 0, e;
}
s(En, "hashDelete");
var _n = En, bn = "__lodash_hash_undefined__", Sn = Object.prototype, Tn = Sn.hasOwnProperty;
function An(t) {
  var e = this.__data__;
  if (Y) {
    var r = e[t];
    return r === bn ? void 0 : r;
  }
  return Tn.call(e, t) ? e[t] : void 0;
}
s(An, "hashGet");
var xn = An, wn = Object.prototype, Pn = wn.hasOwnProperty;
function On(t) {
  var e = this.__data__;
  return Y ? e[t] !== void 0 : Pn.call(e, t);
}
s(On, "hashHas");
var Cn = On, Nn = "__lodash_hash_undefined__";
function In(t, e) {
  var r = this.__data__;
  return this.size += this.has(t) ? 0 : 1, r[t] = Y && e === void 0 ? Nn : e, this;
}
s(In, "hashSet");
var Rn = In;
function G(t) {
  var e = -1, r = t == null ? 0 : t.length;
  for (this.clear(); ++e < r; ) {
    var n = t[e];
    this.set(n[0], n[1]);
  }
}
s(G, "Hash");
G.prototype.clear = vn;
G.prototype.delete = _n;
G.prototype.get = xn;
G.prototype.has = Cn;
G.prototype.set = Rn;
var Ge = G;
function jn() {
  this.__data__ = [], this.size = 0;
}
s(jn, "listCacheClear");
var Ln = jn;
function Dn(t, e) {
  for (var r = t.length; r--; )
    if (un(t[r][0], e))
      return r;
  return -1;
}
s(Dn, "assocIndexOf");
var ce = Dn, $n = Array.prototype, Fn = $n.splice;
function Mn(t) {
  var e = this.__data__, r = ce(e, t);
  if (r < 0)
    return !1;
  var n = e.length - 1;
  return r == n ? e.pop() : Fn.call(e, r, 1), --this.size, !0;
}
s(Mn, "listCacheDelete");
var Un = Mn;
function Gn(t) {
  var e = this.__data__, r = ce(e, t);
  return r < 0 ? void 0 : e[r][1];
}
s(Gn, "listCacheGet");
var kn = Gn;
function Wn(t) {
  return ce(this.__data__, t) > -1;
}
s(Wn, "listCacheHas");
var qn = Wn;
function Bn(t, e) {
  var r = this.__data__, n = ce(r, t);
  return n < 0 ? (++this.size, r.push([t, e])) : r[n][1] = e, this;
}
s(Bn, "listCacheSet");
var Hn = Bn;
function k(t) {
  var e = -1, r = t == null ? 0 : t.length;
  for (this.clear(); ++e < r; ) {
    var n = t[e];
    this.set(n[0], n[1]);
  }
}
s(k, "ListCache");
k.prototype.clear = Ln;
k.prototype.delete = Un;
k.prototype.get = kn;
k.prototype.has = qn;
k.prototype.set = Hn;
var Vn = k, Jn = et(be, "Map"), zn = Jn;
function Yn() {
  this.size = 0, this.__data__ = {
    hash: new Ge(),
    map: new (zn || Vn)(),
    string: new Ge()
  };
}
s(Yn, "mapCacheClear");
var Kn = Yn;
function Xn(t) {
  var e = typeof t;
  return e == "string" || e == "number" || e == "symbol" || e == "boolean" ? t !== "__proto__" : t === null;
}
s(Xn, "isKeyable");
var Qn = Xn;
function Zn(t, e) {
  var r = t.__data__;
  return Qn(e) ? r[typeof e == "string" ? "string" : "hash"] : r.map;
}
s(Zn, "getMapData");
var le = Zn;
function eo(t) {
  var e = le(this, t).delete(t);
  return this.size -= e ? 1 : 0, e;
}
s(eo, "mapCacheDelete");
var to = eo;
function ro(t) {
  return le(this, t).get(t);
}
s(ro, "mapCacheGet");
var no = ro;
function oo(t) {
  return le(this, t).has(t);
}
s(oo, "mapCacheHas");
var so = oo;
function io(t, e) {
  var r = le(this, t), n = r.size;
  return r.set(t, e), this.size += r.size == n ? 0 : 1, this;
}
s(io, "mapCacheSet");
var ao = io;
function W(t) {
  var e = -1, r = t == null ? 0 : t.length;
  for (this.clear(); ++e < r; ) {
    var n = t[e];
    this.set(n[0], n[1]);
  }
}
s(W, "MapCache");
W.prototype.clear = Kn;
W.prototype.delete = to;
W.prototype.get = no;
W.prototype.has = so;
W.prototype.set = ao;
var tt = W, po = "Expected a function";
function Ae(t, e) {
  if (typeof t != "function" || e != null && typeof e != "function")
    throw new TypeError(po);
  var r = /* @__PURE__ */ s(function() {
    var n = arguments, o = e ? e.apply(this, n) : n[0], p = r.cache;
    if (p.has(o))
      return p.get(o);
    var a = t.apply(this, n);
    return r.cache = p.set(o, a) || p, a;
  }, "memoized");
  return r.cache = new (Ae.Cache || tt)(), r;
}
s(Ae, "memoize");
Ae.Cache = tt;
var co = Ae, lo = 500;
function uo(t) {
  var e = co(t, function(n) {
    return r.size === lo && r.clear(), n;
  }), r = e.cache;
  return e;
}
s(uo, "memoizeCapped");
var fo = uo, yo = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g, ho = /\\(\\)?/g, go = fo(function(t) {
  var e = [];
  return t.charCodeAt(0) === 46 && e.push(""), t.replace(yo, function(r, n, o, p) {
    e.push(o ? p.replace(ho, "$1") : n || r);
  }), e;
}), mo = go;
function vo(t) {
  return t == null ? "" : $r(t);
}
s(vo, "toString");
var Eo = vo;
function _o(t, e) {
  return Te(t) ? t : hn(t, e) ? [t] : mo(Eo(t));
}
s(_o, "castPath");
var bo = _o, So = 1 / 0;
function To(t) {
  if (typeof t == "string" || Se(t))
    return t;
  var e = t + "";
  return e == "0" && 1 / t == -So ? "-0" : e;
}
s(To, "toKey");
var Ao = To;
function xo(t, e) {
  e = bo(e, t);
  for (var r = 0, n = e.length; t != null && r < n; )
    t = t[Ao(e[r++])];
  return r && r == n ? t : void 0;
}
s(xo, "baseGet");
var wo = xo;
function Po(t, e, r) {
  var n = t == null ? void 0 : wo(t, e);
  return n === void 0 ? r : n;
}
s(Po, "get");
var Oo = Po, xe = ur, Co = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/, K = /* @__PURE__ */ s((t) => t.match(/^[\[\{\"\}].*[\]\}\"]$/), "isJSON");
function rt(t) {
  if (!xe(t))
    return t;
  let e = t, r = !1;
  return typeof Event < "u" && t instanceof Event && (e = De(e), r = !0), e = Object.keys(e).reduce((n, o) => {
    try {
      e[o] && e[o].toJSON, n[o] = e[o];
    } catch {
      r = !0;
    }
    return n;
  }, {}), r ? e : t;
}
s(rt, "convertUnconventionalData");
var No = /* @__PURE__ */ s(function(e) {
  let r, n, o, p;
  return /* @__PURE__ */ s(function(c, i) {
    try {
      if (c === "")
        return p = [], r = /* @__PURE__ */ new Map([[i, "[]"]]), n = /* @__PURE__ */ new Map(), o = [], i;
      let l = n.get(this) || this;
      for (; o.length && l !== o[0]; )
        o.shift(), p.pop();
      if (typeof i == "boolean")
        return i;
      if (i === void 0)
        return e.allowUndefined ? "_undefined_" : void 0;
      if (i === null)
        return null;
      if (typeof i == "number")
        return i === Number.NEGATIVE_INFINITY ? "_-Infinity_" : i === Number.POSITIVE_INFINITY ? "_Infinity_" : Number.isNaN(i) ? "_NaN_" : i;
      if (typeof i == "bigint")
        return `_bigint_${i.toString()}`;
      if (typeof i == "string")
        return Co.test(i) ? e.allowDate ? `_date_${i}` : void 0 : i;
      if ((0, pr.default)(i))
        return e.allowRegExp ? `_regexp_${i.flags}|${i.source}` : void 0;
      if ((0, cr.default)(i))
        return;
      if ((0, lr.default)(i)) {
        if (!e.allowSymbol)
          return;
        let u = Symbol.keyFor(i);
        return u !== void 0 ? `_gsymbol_${u}` : `_symbol_${i.toString().slice(7, -1)}`;
      }
      if (o.length >= e.maxDepth)
        return Array.isArray(i) ? `[Array(${i.length})]` : "[Object]";
      if (i === this)
        return `_duplicate_${JSON.stringify(p)}`;
      if (i instanceof Error && e.allowError)
        return {
          __isConvertedError__: !0,
          errorProperties: {
            // @ts-expect-error cause is not defined in the current tsconfig target(es2020)
            ...i.cause ? { cause: i.cause } : {},
            ...i,
            name: i.name,
            message: i.message,
            stack: i.stack,
            "_constructor-name_": i.constructor.name
          }
        };
      if (i?.constructor?.name && i.constructor.name !== "Object" && !Array.isArray(i)) {
        let u = r.get(i);
        if (!u) {
          let y = {
            __isClassInstance__: !0,
            __className__: i.constructor.name,
            ...Object.getOwnPropertyNames(i).reduce(
              (g, h) => {
                try {
                  g[h] = i[h];
                } catch {
                }
                return g;
              },
              {}
            )
          };
          return p.push(c), o.unshift(y), r.set(i, JSON.stringify(p)), i !== y && n.set(i, y), y;
        }
        return `_duplicate_${u}`;
      }
      let d = r.get(i);
      if (!d) {
        let u = Array.isArray(i) ? i : rt(i);
        return p.push(c), o.unshift(u), r.set(i, JSON.stringify(p)), i !== u && n.set(i, u), u;
      }
      return `_duplicate_${d}`;
    } catch {
      return;
    }
  }, "replace");
}, "replacer2"), Io = /* @__PURE__ */ s(function(e) {
  let r = [], n;
  return /* @__PURE__ */ s(function(p, a) {
    if (p === "" && (n = a, r.forEach(({ target: c, container: i, replacement: l }) => {
      let d = K(l) ? JSON.parse(l) : l.split(".");
      d.length === 0 ? i[c] = n : i[c] = Oo(n, d);
    })), p === "_constructor-name_")
      return a;
    if (xe(a) && a.__isConvertedError__) {
      let { message: c, ...i } = a.errorProperties, l = new Error(c);
      return Object.assign(l, i), l;
    }
    if (typeof a == "string" && a.startsWith("_regexp_") && e.allowRegExp) {
      let [, c, i] = a.match(/_regexp_([^|]*)\|(.*)/) || [];
      return new RegExp(i, c);
    }
    return typeof a == "string" && a.startsWith("_date_") && e.allowDate ? new Date(a.replace("_date_", "")) : typeof a == "string" && a.startsWith("_duplicate_") ? (r.push({ target: p, container: this, replacement: a.replace(/^_duplicate_/, "") }), null) : typeof a == "string" && a.startsWith("_symbol_") && e.allowSymbol ? Symbol(a.replace("_symbol_", "")) : typeof a == "string" && a.startsWith("_gsymbol_") && e.allowSymbol ? Symbol.for(a.replace("_gsymbol_", "")) : typeof a == "string" && a === "_-Infinity_" ? Number.NEGATIVE_INFINITY : typeof a == "string" && a === "_Infinity_" ? Number.POSITIVE_INFINITY : typeof a == "string" && a === "_NaN_" ? Number.NaN : typeof a == "string" && a.startsWith("_bigint_") && typeof BigInt == "function" ? BigInt(a.replace("_bigint_", "")) : a;
  }, "revive");
}, "reviver2"), nt = {
  maxDepth: 10,
  space: void 0,
  allowRegExp: !0,
  allowDate: !0,
  allowError: !0,
  allowUndefined: !0,
  allowSymbol: !0
}, ue = /* @__PURE__ */ s((t, e = {}) => {
  let r = { ...nt, ...e };
  return JSON.stringify(rt(t), No(r), e.space);
}, "stringify"), Ro = /* @__PURE__ */ s(() => {
  let t = /* @__PURE__ */ new Map();
  return /* @__PURE__ */ s(function e(r) {
    xe(r) && Object.entries(r).forEach(([n, o]) => {
      o === "_undefined_" ? r[n] = void 0 : t.get(o) || (t.set(o, !0), e(o));
    }), Array.isArray(r) && r.forEach((n, o) => {
      n === "_undefined_" ? (t.set(n, !0), r[o] = void 0) : t.get(n) || (t.set(n, !0), e(n));
    });
  }, "mutateUndefined");
}, "mutator"), fe = /* @__PURE__ */ s((t, e = {}) => {
  let r = { ...nt, ...e }, n = JSON.parse(t, Io(r));
  return Ro()(n), n;
}, "parse");

// ../node_modules/tiny-invariant/dist/esm/tiny-invariant.js
var jo = !1, we = "Invariant failed";
function X(t, e) {
  if (!t) {
    if (jo)
      throw new Error(we);
    var r = typeof e == "function" ? e() : e, n = r ? "".concat(we, ": ").concat(r) : we;
    throw new Error(n);
  }
}
s(X, "invariant");

// src/channels/postmessage/getEventSourceUrl.ts
import { logger as Lo } from "storybook/internal/client-logger";
var ot = /* @__PURE__ */ s((t) => {
  let e = Array.from(
    document.querySelectorAll("iframe[data-is-storybook]")
  ), [r, ...n] = e.filter((p) => {
    try {
      return p.contentWindow?.location.origin === t.source.location.origin && p.contentWindow?.location.pathname === t.source.location.pathname;
    } catch {
    }
    try {
      return p.contentWindow === t.source;
    } catch {
    }
    let a = p.getAttribute("src"), c;
    try {
      if (!a)
        return !1;
      ({ origin: c } = new URL(a, document.location.toString()));
    } catch {
      return !1;
    }
    return c === t.origin;
  }), o = r?.getAttribute("src");
  if (o && n.length === 0) {
    let { protocol: p, host: a, pathname: c } = new URL(o, document.location.toString());
    return `${p}//${a}${c}`;
  }
  return n.length > 0 && Lo.error("found multiple candidates for event source"), null;
}, "getEventSourceUrl");

// src/channels/postmessage/index.ts
var { document: Pe, location: Oe } = b, at = "storybook-channel", $o = { maxDepth: 25 }, Q = class {
  constructor(e) {
    this.config = e;
    this.connected = !1;
    if (this.buffer = [], typeof b?.addEventListener == "function" && b.addEventListener("message", this.handleEvent.bind(this), !1), e.page !== "manager" && e.page !== "preview")
      throw new Error(`postmsg-channel: "config.page" cannot be "${e.page}"`);
  }
  static {
    s(this, "PostMessageTransport");
  }
  setHandler(e) {
    this.handler = (...r) => {
      e.apply(this, r), !this.connected && this.getLocalFrame().length && (this.flush(), this.connected = !0);
    };
  }
  /**
   * Sends `event` to the associated window. If the window does not yet exist the event will be
   * stored in a buffer and sent when the window exists.
   *
   * @param event
   */
  send(e, r) {
    let {
      target: n,
      // telejson options
      allowRegExp: o,
      allowSymbol: p,
      allowDate: a,
      allowError: c,
      allowUndefined: i,
      maxDepth: l,
      space: d
    } = r || {}, u = Object.fromEntries(
      Object.entries({
        allowRegExp: o,
        allowSymbol: p,
        allowDate: a,
        allowError: c,
        allowUndefined: i,
        maxDepth: l,
        space: d
      }).filter(([w, A]) => typeof A < "u")
    ), y = {
      ...$o,
      ...b.CHANNEL_OPTIONS || {},
      ...u
    }, g = this.getFrames(n), h = new URLSearchParams(Oe?.search || ""), C = ue(
      {
        key: at,
        event: e,
        refId: h.get("refId")
      },
      y
    );
    return g.length ? (this.buffer.length && this.flush(), g.forEach((w) => {
      try {
        w.postMessage(C, "*");
      } catch {
        st.error("sending over postmessage fail");
      }
    }), Promise.resolve(null)) : new Promise((w, A) => {
      this.buffer.push({ event: e, resolve: w, reject: A });
    });
  }
  flush() {
    let { buffer: e } = this;
    this.buffer = [], e.forEach((r) => {
      this.send(r.event).then(r.resolve).catch(r.reject);
    });
  }
  getFrames(e) {
    if (this.config.page === "manager") {
      let n = Array.from(
        Pe.querySelectorAll("iframe[data-is-storybook][data-is-loaded]")
      ).flatMap((o) => {
        try {
          return o.contentWindow && o.dataset.isStorybook !== void 0 && o.id === e ? [o.contentWindow] : [];
        } catch {
          return [];
        }
      });
      return n?.length ? n : this.getCurrentFrames();
    }
    return b && b.parent && b.parent !== b.self ? [b.parent] : [];
  }
  getCurrentFrames() {
    return this.config.page === "manager" ? Array.from(
      Pe.querySelectorAll('[data-is-storybook="true"]')
    ).flatMap((r) => r.contentWindow ? [r.contentWindow] : []) : b && b.parent ? [b.parent] : [];
  }
  getLocalFrame() {
    return this.config.page === "manager" ? Array.from(
      Pe.querySelectorAll("#storybook-preview-iframe")
    ).flatMap((r) => r.contentWindow ? [r.contentWindow] : []) : b && b.parent ? [b.parent] : [];
  }
  handleEvent(e) {
    try {
      let { data: r } = e, { key: n, event: o, refId: p } = typeof r == "string" && K(r) ? fe(r, b.CHANNEL_OPTIONS || {}) : r;
      if (n === at) {
        let a = this.config.page === "manager" ? '<span style="color: #37D5D3; background: black"> manager </span>' : '<span style="color: #1EA7FD; background: black"> preview </span>', c = Object.values(Do).includes(o.type) ? `<span style="color: #FF4785">${o.type}</span>` : `<span style="color: #FFAE00">${o.type}</span>`;
        if (p && (o.refId = p), o.source = this.config.page === "preview" ? e.origin : ot(e), !o.source) {
          it.error(
            `${a} received ${c} but was unable to determine the source of the event`
          );
          return;
        }
        let i = `${a} received ${c} (${r.length})`;
        it.debug(
          Oe.origin !== o.source ? i : `${i} <span style="color: gray">(on ${Oe.origin} from ${o.source})</span>`,
          ...o.args
        ), X(this.handler, "ChannelHandler should be set"), this.handler(o);
      }
    } catch (r) {
      st.error(r);
    }
  }
};

// src/channels/websocket/index.ts
import * as pt from "storybook/internal/core-events";
import { global as ct } from "@storybook/global";
var { WebSocket: Fo } = ct, lt = 15e3, ut = 5e3, Z = class {
  constructor({ url: e, onError: r, page: n }) {
    this.buffer = [];
    this.isReady = !1;
    this.isClosed = !1;
    this.pingTimeout = 0;
    this.socket = new Fo(e), this.socket.onopen = () => {
      this.isReady = !0, this.heartbeat(), this.flush();
    }, this.socket.onmessage = ({ data: o }) => {
      let p = typeof o == "string" && K(o) ? fe(o) : o;
      X(this.handler, "WebsocketTransport handler should be set"), this.handler(p), p.type === "ping" && (this.heartbeat(), this.send({ type: "pong" }));
    }, this.socket.onerror = (o) => {
      r && r(o);
    }, this.socket.onclose = (o) => {
      X(this.handler, "WebsocketTransport handler should be set"), this.handler({
        type: pt.CHANNEL_WS_DISCONNECT,
        args: [{ reason: o.reason, code: o.code }],
        from: n || "preview"
      }), this.isClosed = !0, clearTimeout(this.pingTimeout);
    };
  }
  static {
    s(this, "WebsocketTransport");
  }
  heartbeat() {
    clearTimeout(this.pingTimeout), this.pingTimeout = setTimeout(() => {
      this.socket.close(3008, "timeout");
    }, lt + ut);
  }
  setHandler(e) {
    this.handler = e;
  }
  send(e) {
    this.isClosed || (this.isReady ? this.sendNow(e) : this.sendLater(e));
  }
  sendLater(e) {
    this.buffer.push(e);
  }
  sendNow(e) {
    let r = ue(e, {
      maxDepth: 15,
      ...ct.CHANNEL_OPTIONS
    });
    this.socket.send(r);
  }
  flush() {
    let { buffer: e } = this;
    this.buffer = [], e.forEach((r) => this.send(r));
  }
};

// src/channels/index.ts
var { CONFIG_TYPE: Uo } = Mo, Ts = J;
function As({ page: t, extraTransports: e = [] }) {
  let r = [new Q({ page: t }), ...e];
  if (Uo === "DEVELOPMENT") {
    let o = window.location.protocol === "http:" ? "ws" : "wss", { hostname: p, port: a } = window.location, c = `${o}://${p}:${a}/storybook-server-channel`;
    r.push(new Z({ url: c, onError: /* @__PURE__ */ s(() => {
    }, "onError"), page: t }));
  }
  let n = new J({ transports: r });
  return M.__prepare(
    n,
    t === "manager" ? M.Environment.MANAGER : M.Environment.PREVIEW
  ), n;
}
s(As, "createBrowserChannel");
export {
  J as Channel,
  lt as HEARTBEAT_INTERVAL,
  ut as HEARTBEAT_MAX_LATENCY,
  Q as PostMessageTransport,
  Z as WebsocketTransport,
  As as createBrowserChannel,
  Ts as default
};
/*! Bundled license information:

telejson/dist/index.mjs:
  (*! Bundled license information:
  
  isobject/index.js:
    (*!
     * isobject <https://github.com/jonschlinkert/isobject>
     *
     * Copyright (c) 2014-2017, Jon Schlinkert.
     * Released under the MIT License.
     *)
  
  lodash-es/lodash.js:
    (**
     * @license
     * Lodash (Custom Build) <https://lodash.com/>
     * Build: `lodash modularize exports="es" -o ./`
     * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
     * Released under MIT license <https://lodash.com/license>
     * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
     * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
     *)
  *)
*/
