import { isDefined as b, isJsonString as r } from "@scalar/oas-utils/helpers";
import { useEventBus as p } from "@vueuse/core";
import { toJson as w, normalize as a, toYaml as f } from "@scalar/openapi-parser";
const v = Symbol("download"), L = p(v);
function E(e, n) {
  return n && !r(e) ? w(a(e)) : !n && r(e) ? f(a(e)) : e;
}
function y() {
  try {
    return new MouseEvent("click", {
      bubbles: !0,
      cancelable: !0,
      view: window
    });
  } catch {
    return new MouseEvent("click", {
      bubbles: !0,
      cancelable: !0
    });
  }
}
function R(e, n, c) {
  const t = c === "json" || !b(c) && r(e), l = E(e, t), i = t ? ".json" : ".yaml", u = t ? "application/json" : "application/x-yaml", m = n ? n + i : "openapi" + i, d = new Blob([l], { type: u }), s = URL.createObjectURL(d), o = document.createElement("a");
  o.href = s, o.download = m, o.dispatchEvent(y()), setTimeout(() => {
    window.URL.revokeObjectURL(s), o.remove();
  }, 100);
}
export {
  R as downloadDocument,
  L as downloadEventBus
};
