@scalar/api-reference
Version:
Generate beautiful API references from OpenAPI documents
55 lines (54 loc) • 1.89 kB
JavaScript
import { createHead as c } from "@unhead/vue";
import { reactive as f, createApp as d, h as i } from "vue";
import u from "../../components/ApiReference.vue.js";
const g = (a, s) => {
const r = "scalar-refs", t = f({
// Either the configuration will be the second arugment or it MUST be the first (configuration only)
configuration: s ?? a ?? {}
});
let n = d(() => i(u, t));
if (n.use(c()), n.config.idPrefix = r, s) {
const e = typeof a == "string" ? document.querySelector(a) : a;
e ? n.mount(e) : console.error("Could not find a mount point for API References:", a);
}
document.addEventListener(
"scalar:reload-references",
() => {
if (console.warn(
"scalar:reload-references event has been deprecated, please use the scalarInstance.app.mount method instead."
), !t.configuration)
return;
const e = typeof a == "string" ? document.querySelector(a) : a;
e && (e && !document.body.contains(e) && document.body.appendChild(e), n.unmount(), n = d(() => i(u, t)), n.use(c()), n.config.idPrefix = r, n.mount(e));
},
!1
);
const o = () => {
delete t.configuration, n.unmount();
};
return document.addEventListener(
"scalar:destroy-references",
() => {
console.warn("scalar:destroy-references event has been deprecated, please use scalarInstance.destroy instead."), o();
},
!1
), document.addEventListener(
"scalar:update-references-config",
(e) => {
console.warn(
"scalar:update-references-config event has been deprecated, please use scalarInstance.updateConfiguration instead."
), "detail" in e && Object.assign(t, e.detail);
},
!1
), {
app: n,
getConfiguration: () => t.configuration ?? {},
updateConfiguration: (e) => {
t.configuration = e;
},
destroy: o
};
};
export {
g as createApiReference
};