markstream-vue
Version:
Vue 3 Markdown renderer optimized for large docs: progressive Mermaid, streaming diff code blocks, and fast real-time preview.
109 lines (108 loc) • 3.4 kB
JavaScript
var v = (i, o, r) => new Promise((d, a) => {
var s = (e) => {
try {
l(r.next(e));
} catch (m) {
a(m);
}
}, f = (e) => {
try {
l(r.throw(e));
} catch (m) {
a(m);
}
}, l = (e) => e.done ? d(e.value) : Promise.resolve(e.value).then(s, f);
l((r = r.apply(i, o)).next());
});
import { defineComponent as x, ref as k, watch as B, onMounted as C, onBeforeUnmount as O, createElementBlock as T, openBlock as g, createVNode as y, createElementVNode as w, Transition as I, withCtx as M, createCommentVNode as W, normalizeClass as K } from "vue";
import { a as N, r as V, e as b, f as U, W as L, d as A } from "./exports-BreegGo9.js";
const F = {
key: 0,
class: "math-loading-overlay"
}, S = /* @__PURE__ */ x({
__name: "MathBlockNode",
props: {
node: {}
},
setup(i) {
const o = i;
let r = null;
const d = k(null), a = k(null);
let s = !1, f = 0, l = !1, e = null;
const m = N();
let n = null;
const u = k(!0);
function R() {
return v(this, null, function* () {
if (!o.node.content || !a.value || l)
return;
if (!s)
try {
!n && d.value && (n = m(d.value)), yield n == null ? void 0 : n.whenVisible;
} catch (t) {
}
e && (e.abort(), e = null);
const c = ++f, h = new AbortController();
e = h, V(o.node.content, !0, {
timeout: 3e3,
waitTimeout: 2e3,
maxRetries: 1,
signal: h.signal
}).then((t) => {
l || c !== f || a.value && (a.value.innerHTML = t, s = !0, u.value = !1);
}).catch((t) => v(null, null, function* () {
if (l || c !== f || !a.value)
return;
const _ = (t == null ? void 0 : t.code) || (t == null ? void 0 : t.name);
if ((_ === "WORKER_INIT_ERROR" || (t == null ? void 0 : t.fallbackToRenderer) || (_ === L || _ === "WORKER_TIMEOUT")) && (r || (r = yield b()), r)) {
try {
const p = r.renderToString(o.node.content, {
throwOnError: o.node.loading,
displayMode: !0
});
a.value.innerHTML = p, s = !0, u.value = !1, U(o.node.content, !0, p);
} catch (p) {
}
return;
}
s || (u.value = !0), o.node.loading || (u.value = !1, a.value.textContent = o.node.raw);
}));
});
}
return B(
() => o.node.content,
() => {
R();
}
), C(() => {
R();
}), O(() => {
var c;
l = !0, e && (e.abort(), e = null), (c = n == null ? void 0 : n.destroy) == null || c.call(n), n = null;
}), (c, h) => (g(), T("div", {
ref_key: "containerEl",
ref: d,
class: "math-block text-center overflow-x-auto relative min-h-[40px]"
}, [
y(I, { name: "math-fade" }, {
default: M(() => [
u.value ? (g(), T("div", F, [...h[0] || (h[0] = [
w("div", { class: "math-loading-spinner" }, null, -1)
])])) : W("", !0)
]),
_: 1
}),
w("div", {
ref_key: "mathBlockElement",
ref: a,
class: K({ "math-rendering": u.value })
}, null, 2)
], 512));
}
}), E = /* @__PURE__ */ A(S, [["__scopeId", "data-v-2e076ab9"]]);
E.install = (i) => {
i.component(E.__name, E);
};
export {
E as default
};