markstream-vue
Version:
Vue 3 Markdown renderer optimized for large docs: progressive Mermaid, streaming diff code blocks, and fast real-time preview.
118 lines (117 loc) • 3.75 kB
JavaScript
var v = (d, o, r) => new Promise((f, l) => {
var c = (e) => {
try {
s(r.next(e));
} catch (t) {
l(t);
}
}, m = (e) => {
try {
s(r.throw(e));
} catch (t) {
l(t);
}
}, s = (e) => e.done ? f(e.value) : Promise.resolve(e.value).then(c, m);
s((r = r.apply(d, o)).next());
});
import { defineComponent as k, ref as g, watch as I, onMounted as O, onBeforeUnmount as y, createElementBlock as C, openBlock as R, withDirectives as B, createBlock as M, createCommentVNode as x, createElementVNode as p, vShow as W, Transition as K, withCtx as b, renderSlot as L } from "vue";
import { a as N, r as V, e as S, f as U, W as A, d as D } from "./exports-BreegGo9.js";
const F = {
class: "math-inline__loading",
role: "status",
"aria-live": "polite"
}, X = /* @__PURE__ */ k({
__name: "MathInlineNode",
props: {
node: {}
},
setup(d) {
const o = d;
let r = null;
const f = g(null), l = g(null);
let c = !1, m = 0, s = !1, e = null;
const t = g(!0), T = N();
let a = null;
function E() {
return v(this, null, function* () {
if (!o.node.content || !l.value || s)
return;
e && (e.abort(), e = null);
const i = ++m, u = new AbortController();
if (e = u, !c)
try {
!a && f.value && (a = T(f.value)), yield a == null ? void 0 : a.whenVisible;
} catch (n) {
}
V(o.node.content, !1, {
// Inline math should not wait on worker slots; fallback to sync render immediately
timeout: 1500,
waitTimeout: 0,
maxRetries: 0,
signal: u.signal
}).then((n) => {
s || i !== m || l.value && (l.value.innerHTML = n, t.value = !1, c = !0);
}).catch((n) => v(null, null, function* () {
if (s || i !== m || !l.value)
return;
const h = (n == null ? void 0 : n.code) || (n == null ? void 0 : n.name);
if ((h === "WORKER_INIT_ERROR" || (n == null ? void 0 : n.fallbackToRenderer) || (h === A || h === "WORKER_TIMEOUT")) && (r || (r = yield S()), r)) {
try {
const _ = r.renderToString(o.node.content, { throwOnError: o.node.loading, displayMode: !1 });
t.value = !1, l.value.innerHTML = _, c = !0, U(o.node.content, !1, _);
} catch (_) {
}
return;
}
c || (t.value = !0), o.node.loading || (t.value = !1, l.value.textContent = o.node.raw);
}));
});
}
return I(
() => o.node.content,
() => {
E();
}
), O(() => {
E();
}), y(() => {
var i;
s = !0, e && (e.abort(), e = null), (i = a == null ? void 0 : a.destroy) == null || i.call(a), a = null;
}), (i, u) => (R(), C("span", {
ref_key: "containerEl",
ref: f,
class: "math-inline-wrapper"
}, [
B(p("span", {
ref_key: "mathElement",
ref: l,
class: "math-inline"
}, null, 512), [
[W, !t.value]
]),
t.value ? (R(), M(K, {
key: 0,
name: "table-node-fade"
}, {
default: b(() => [
p("span", F, [
L(i.$slots, "loading", { isLoading: t.value }, () => [
u[0] || (u[0] = p("span", {
class: "math-inline__spinner animate-spin",
"aria-hidden": "true"
}, null, -1)),
u[1] || (u[1] = p("span", { class: "sr-only" }, "Loading", -1))
], !0)
])
]),
_: 3
})) : x("", !0)
], 512));
}
}), w = /* @__PURE__ */ D(X, [["__scopeId", "data-v-6b23009e"]]);
w.install = (d) => {
d.component(w.__name, w);
};
export {
w as default
};