@pi-outpost/embed 0.28.2 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { r as e } from "./rolldown-runtime-DArdT4gl.js";
2
- import { h as t, l as n, m as r, n as i, r as a, t as o } from "./lib-BV1VyBDK.js";
3
- import { a as s, n as c, o as l } from "./workspacePath-CfDl0V4n.js";
2
+ import { _ as t, h as n, i as r, n as i, t as a, u as o } from "./lib-BgQYQRfw.js";
3
+ import { i as s, n as c, t as l } from "./loadReferencedImage-CUSqS4eN.js";
4
4
  //#region ../node_modules/docx/dist/index.mjs
5
5
  var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescriptor, p = Object.getOwnPropertyNames, m = Object.getPrototypeOf, h = Object.prototype.hasOwnProperty, g = (e, t) => () => (e && (t = e(e = 0)), t), _ = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), v = (e, t, n, r) => {
6
6
  if (t && typeof t == "object" || typeof t == "function") for (var i = p(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !h.call(e, s) && s !== n && d(e, s, {
@@ -35436,42 +35436,116 @@ var jg = function(e, t) {
35436
35436
  LineNode: Rd
35437
35437
  }
35438
35438
  }, Ig = class extends Error {
35439
+ constructor(e) {
35440
+ super(e), this.name = "MathMarkupError";
35441
+ }
35442
+ }, Lg = {
35443
+ amp: "&",
35444
+ lt: "<",
35445
+ gt: ">",
35446
+ quot: "\"",
35447
+ apos: "'"
35448
+ };
35449
+ function Rg(e) {
35450
+ return e.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-zA-Z]+);/g, (e, t) => t.startsWith("#x") ? String.fromCodePoint(Number.parseInt(t.slice(2), 16)) : t.startsWith("#") ? String.fromCodePoint(Number.parseInt(t.slice(1), 10)) : Lg[t] ?? e);
35451
+ }
35452
+ function zg(e) {
35453
+ let t = e.children.map(zg);
35454
+ return {
35455
+ tagName: e.tagName,
35456
+ attributes: e.attributes,
35457
+ children: t,
35458
+ get textContent() {
35459
+ return e.text.join("");
35460
+ }
35461
+ };
35462
+ }
35463
+ var Bg = /<(\/?)([A-Za-z][\w:.-]*)((?:\s+[\w:.-]+\s*=\s*(?:"[^"]*"|'[^']*'))*)\s*(\/?)>/y, Vg = /([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
35464
+ function Hg(e) {
35465
+ let t = {
35466
+ tagName: "#root",
35467
+ attributes: /* @__PURE__ */ new Map(),
35468
+ children: [],
35469
+ text: []
35470
+ }, n = [t], r = 0;
35471
+ for (; r < e.length;) {
35472
+ let i = e.indexOf("<", r), a = i === -1 ? e.length : i;
35473
+ if (a > r) {
35474
+ let t = Rg(e.slice(r, a));
35475
+ for (let e of n) e.text.push(t);
35476
+ }
35477
+ if (i === -1) break;
35478
+ Bg.lastIndex = i;
35479
+ let o = Bg.exec(e);
35480
+ if (o === null) throw new Ig(`unreadable markup at ${i}`);
35481
+ let [, s, c, l, u] = o;
35482
+ if (r = Bg.lastIndex, s === "/") {
35483
+ let e = n.pop();
35484
+ if (e === void 0 || e === t || e.tagName !== c) throw new Ig(`unexpected </${c}>`);
35485
+ continue;
35486
+ }
35487
+ let d = /* @__PURE__ */ new Map();
35488
+ for (let e of l.matchAll(Vg)) d.set(e[1], Rg(e[2] ?? e[3] ?? ""));
35489
+ let f = {
35490
+ tagName: c,
35491
+ attributes: d,
35492
+ children: [],
35493
+ text: []
35494
+ };
35495
+ n[n.length - 1].children.push(f), u !== "/" && n.push(f);
35496
+ }
35497
+ if (n.length !== 1) throw new Ig(`unclosed <${n[n.length - 1].tagName}>`);
35498
+ return t.children.map(zg);
35499
+ }
35500
+ function Ug(e, t) {
35501
+ for (let n of e) {
35502
+ if (t(n)) return n;
35503
+ let e = Ug(n.children, t);
35504
+ if (e !== void 0) return e;
35505
+ }
35506
+ }
35507
+ function Wg(e, t) {
35508
+ return (e.attributes.get("class") ?? "").split(/\s+/).includes(t);
35509
+ }
35510
+ //#endregion
35511
+ //#region ../shared/src/docx/mathmlToOmml.ts
35512
+ var Gg = class extends Error {
35439
35513
  element;
35440
35514
  constructor(e) {
35441
35515
  super(`no OMML mapping for MathML element <${e}>`), this.name = "UnsupportedMathError", this.element = e;
35442
35516
  }
35443
- }, Lg = /* @__PURE__ */ new Set(["∑"]), Rg = /* @__PURE__ */ new Set([
35517
+ }, Kg = /* @__PURE__ */ new Set(["∑"]), qg = /* @__PURE__ */ new Set([
35444
35518
  "∫",
35445
35519
  "∬",
35446
35520
  "∭",
35447
35521
  "∮"
35448
- ]), zg = /* @__PURE__ */ new Set(["(", "("]), Bg = /* @__PURE__ */ new Set([")", ")"]);
35449
- function Vg(e, t) {
35450
- let n = Fg.renderToString(e, {
35522
+ ]), Jg = /* @__PURE__ */ new Set(["(", "("]), Yg = /* @__PURE__ */ new Set([")", ")"]);
35523
+ function Xg(e, t) {
35524
+ let n = Ug(Hg(Fg.renderToString(e, {
35451
35525
  output: "mathml",
35452
35526
  displayMode: t,
35453
35527
  throwOnError: !1
35454
- }), r = new DOMParser().parseFromString(n, "text/html").querySelector("math");
35455
- if (r === null) throw new Ig("math");
35456
- return r;
35528
+ })), (e) => e.tagName.toLowerCase() === "math");
35529
+ if (n === void 0) throw new Gg("math");
35530
+ return n;
35457
35531
  }
35458
- function Hg(e) {
35532
+ function Zg(e) {
35459
35533
  return [...e.children];
35460
35534
  }
35461
- function Ug(e) {
35535
+ function Qg(e) {
35462
35536
  return (e.textContent ?? "").replace(/[\u2061-\u2064]/g, "").trim();
35463
35537
  }
35464
- function Wg(e) {
35465
- return e.flatMap(Gg);
35538
+ function $g(e) {
35539
+ return e.flatMap(e_);
35466
35540
  }
35467
- function Gg(e) {
35541
+ function e_(e) {
35468
35542
  let t = e.tagName.toLowerCase().replace(/^m:/, "");
35469
35543
  switch (t) {
35470
35544
  case "math":
35471
35545
  case "semantics":
35472
35546
  case "mrow":
35473
35547
  case "mstyle":
35474
- case "mpadded": return Yg(Hg(e));
35548
+ case "mpadded": return i_(Zg(e));
35475
35549
  case "annotation":
35476
35550
  case "annotation-xml":
35477
35551
  case "mphantom": return [];
@@ -35480,58 +35554,58 @@ function Gg(e) {
35480
35554
  case "mn":
35481
35555
  case "mo":
35482
35556
  case "mtext": {
35483
- let t = Ug(e);
35557
+ let t = Qg(e);
35484
35558
  return t === "" ? [] : [new qa(t)];
35485
35559
  }
35486
35560
  case "mfrac": {
35487
- let [t, n] = Hg(e);
35488
- if (t === void 0 || n === void 0) throw new Ig("mfrac");
35561
+ let [t, n] = Zg(e);
35562
+ if (t === void 0 || n === void 0) throw new Gg("mfrac");
35489
35563
  return [new Xa({
35490
- numerator: Gg(t),
35491
- denominator: Gg(n)
35564
+ numerator: e_(t),
35565
+ denominator: e_(n)
35492
35566
  })];
35493
35567
  }
35494
- case "msqrt": return [new vo({ children: Wg(Hg(e)) })];
35568
+ case "msqrt": return [new vo({ children: $g(Zg(e)) })];
35495
35569
  case "mroot": {
35496
- let [t, n] = Hg(e);
35497
- if (t === void 0 || n === void 0) throw new Ig("mroot");
35570
+ let [t, n] = Zg(e);
35571
+ if (t === void 0 || n === void 0) throw new Gg("mroot");
35498
35572
  return [new vo({
35499
- children: Gg(t),
35500
- degree: Gg(n)
35573
+ children: e_(t),
35574
+ degree: e_(n)
35501
35575
  })];
35502
35576
  }
35503
35577
  case "msub":
35504
35578
  case "munder": {
35505
- let [n, r] = Hg(e);
35506
- if (n === void 0 || r === void 0) throw new Ig(t);
35579
+ let [n, r] = Zg(e);
35580
+ if (n === void 0 || r === void 0) throw new Gg(t);
35507
35581
  return [new uo({
35508
- children: Gg(n),
35509
- subScript: Gg(r)
35582
+ children: e_(n),
35583
+ subScript: e_(r)
35510
35584
  })];
35511
35585
  }
35512
35586
  case "msup":
35513
35587
  case "mover": {
35514
- let [n, r] = Hg(e);
35515
- if (n === void 0 || r === void 0) throw new Ig(t);
35588
+ let [n, r] = Zg(e);
35589
+ if (n === void 0 || r === void 0) throw new Gg(t);
35516
35590
  return [new co({
35517
- children: Gg(n),
35518
- superScript: Gg(r)
35591
+ children: e_(n),
35592
+ superScript: e_(r)
35519
35593
  })];
35520
35594
  }
35521
35595
  case "msubsup":
35522
35596
  case "munderover": {
35523
- let [n, r, i] = Hg(e);
35524
- if (n === void 0 || r === void 0 || i === void 0) throw new Ig(t);
35597
+ let [n, r, i] = Zg(e);
35598
+ if (n === void 0 || r === void 0 || i === void 0) throw new Gg(t);
35525
35599
  return [new po({
35526
- children: Gg(n),
35527
- subScript: Gg(r),
35528
- superScript: Gg(i)
35600
+ children: e_(n),
35601
+ subScript: e_(r),
35602
+ superScript: e_(i)
35529
35603
  })];
35530
35604
  }
35531
- default: throw new Ig(t);
35605
+ default: throw new Gg(t);
35532
35606
  }
35533
35607
  }
35534
- var Kg = /* @__PURE__ */ new Set([
35608
+ var t_ = /* @__PURE__ */ new Set([
35535
35609
  "msub",
35536
35610
  "msup",
35537
35611
  "msubsup",
@@ -35539,361 +35613,93 @@ var Kg = /* @__PURE__ */ new Set([
35539
35613
  "mover",
35540
35614
  "munderover"
35541
35615
  ]);
35542
- function qg(e, t) {
35543
- if (!Kg.has(e.tagName.toLowerCase())) return;
35544
- let [n, r, i] = Hg(e);
35616
+ function n_(e, t) {
35617
+ if (!t_.has(e.tagName.toLowerCase())) return;
35618
+ let [n, r, i] = Zg(e);
35545
35619
  if (n === void 0) return;
35546
- let a = Ug(n), o = Lg.has(a), s = Rg.has(a);
35620
+ let a = Qg(n), o = Kg.has(a), s = qg.has(a);
35547
35621
  if (!o && !s) return;
35548
35622
  let c = e.tagName.toLowerCase(), l = c === "msub" || c === "munder" || c === "msubsup" || c === "munderover" ? r : void 0, u = c === "msup" || c === "mover" ? r : c === "msubsup" || c === "munderover" ? i : void 0, d = {
35549
- children: Wg(t),
35550
- ...l === void 0 ? {} : { subScript: Gg(l) },
35551
- ...u === void 0 ? {} : { superScript: Gg(u) }
35623
+ children: $g(t),
35624
+ ...l === void 0 ? {} : { subScript: e_(l) },
35625
+ ...u === void 0 ? {} : { superScript: e_(u) }
35552
35626
  };
35553
35627
  return [o ? new ao(d) : new oo(d)];
35554
35628
  }
35555
- function Jg(e) {
35629
+ function r_(e) {
35556
35630
  let t = e[0], n = e[e.length - 1];
35557
- return e.length >= 2 && t !== void 0 && n !== void 0 && t.tagName.toLowerCase() === "mo" && n.tagName.toLowerCase() === "mo" && zg.has(Ug(t)) && Bg.has(Ug(n)) ? [new So({ children: Yg(e.slice(1, -1)) })] : Yg(e);
35631
+ return e.length >= 2 && t !== void 0 && n !== void 0 && t.tagName.toLowerCase() === "mo" && n.tagName.toLowerCase() === "mo" && Jg.has(Qg(t)) && Yg.has(Qg(n)) ? [new So({ children: i_(e.slice(1, -1)) })] : i_(e);
35558
35632
  }
35559
- function Yg(e) {
35633
+ function i_(e) {
35560
35634
  let t = [];
35561
35635
  for (let n = 0; n < e.length; n++) {
35562
- let r = qg(e[n], e.slice(n + 1));
35636
+ let r = n_(e[n], e.slice(n + 1));
35563
35637
  if (r !== void 0) return t.push(...r), t;
35564
- t.push(...Gg(e[n]));
35638
+ t.push(...e_(e[n]));
35565
35639
  }
35566
35640
  return t;
35567
35641
  }
35568
- function Xg(e, t) {
35569
- let n = Vg(e, t);
35570
- if (n.querySelector(".katex-error") !== null) throw new Ig("katex-error");
35571
- let r = n.querySelector("semantics"), i = Hg(r === null ? n : r), a = Jg((i.length === 1 && i[0].tagName.toLowerCase() === "mrow" ? Hg(i[0]) : i).filter((e) => e.tagName.toLowerCase() !== "annotation"));
35572
- if (a.length === 0) throw new Ig("empty");
35642
+ function a_(e, t) {
35643
+ let n = Xg(e, t);
35644
+ if (Ug([n], (e) => Wg(e, "katex-error")) !== void 0) throw new Gg("katex-error");
35645
+ let r = Ug(n.children, (e) => e.tagName.toLowerCase() === "semantics"), i = Zg(r === void 0 ? n : r), a = r_((i.length === 1 && i[0].tagName.toLowerCase() === "mrow" ? Zg(i[0]) : i).filter((e) => e.tagName.toLowerCase() !== "annotation"));
35646
+ if (a.length === 0) throw new Gg("empty");
35573
35647
  return a;
35574
35648
  }
35575
35649
  //#endregion
35576
- //#region ../ui/src/export/xmlText.ts
35577
- var Zg = "�", Qg = /[- -￾￿]/g, $g = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
35578
- function e_(e) {
35579
- return e.replace(Qg, Zg).replace($g, Zg);
35650
+ //#region ../shared/src/docx/xmlText.ts
35651
+ var o_ = "�", s_ = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]/g, c_ = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
35652
+ function l_(e) {
35653
+ return e.replace(s_, o_).replace(c_, o_);
35580
35654
  }
35581
35655
  //#endregion
35582
- //#region ../ui/src/export/mermaidToImage.ts
35583
- var t_ = class extends Error {
35584
- constructor(e) {
35585
- super(e), this.name = "DiagramError";
35586
- }
35587
- };
35588
- function n_(e) {
35589
- let t = /viewBox="\s*[\d.-]+[\s,]+[\d.-]+[\s,]+([\d.]+)[\s,]+([\d.]+)/.exec(e), n = t ? Number(t[1]) : NaN, r = t ? Number(t[2]) : NaN;
35590
- if (!Number.isFinite(n) || !Number.isFinite(r) || n <= 0 || r <= 0) throw new t_("diagram has no usable viewBox");
35591
- return {
35592
- width: n,
35593
- height: r
35594
- };
35595
- }
35596
- function r_(e, t, n) {
35597
- let r = /^[\s\S]*?<svg\b[^>]*>/.exec(e);
35598
- return r === null ? e : r[0].replace(/\swidth="[^"]*"/, "").replace(/\sheight="[^"]*"/, "").replace(/\sstyle="[^"]*"/, (e) => {
35599
- let t = e.replace(/max-width:[^;"]*;?/, "");
35600
- return /style="\s*"/.test(t) ? "" : t;
35601
- }).replace(/>$/, ` width="${t}" height="${n}">`) + e.slice(r[0].length);
35602
- }
35603
- var i_ = [
35604
- "fill",
35605
- "fill-opacity",
35606
- "stroke",
35607
- "stroke-width",
35608
- "stroke-opacity",
35609
- "stroke-dasharray",
35610
- "stroke-linecap",
35611
- "stroke-linejoin",
35612
- "opacity",
35613
- "font-family",
35614
- "font-size",
35615
- "font-weight",
35616
- "font-style",
35617
- "text-anchor",
35618
- "dominant-baseline"
35619
- ];
35620
- function a_(e) {
35621
- let t = document.createElement("div");
35622
- t.setAttribute("style", "position:absolute;left:-10000px;top:0;width:0;height:0;overflow:hidden"), t.innerHTML = e;
35623
- let n = t.querySelector("svg");
35624
- if (n === null) return e;
35625
- document.body.append(t);
35626
- try {
35627
- let e = [n, ...n.querySelectorAll("*")].filter((e) => e.tagName.toLowerCase() !== "style").map((e) => {
35628
- let t = window.getComputedStyle(e), n = [];
35629
- for (let e of i_) {
35630
- let r = t.getPropertyValue(e);
35631
- r !== "" && n.push([e, r]);
35632
- }
35633
- return {
35634
- element: e,
35635
- painted: n
35636
- };
35637
- });
35638
- for (let { element: t, painted: n } of e) {
35639
- for (let [e, r] of n) t.setAttribute(e, r);
35640
- t.removeAttribute("style"), t.removeAttribute("class");
35641
- }
35642
- for (let e of [...n.querySelectorAll("style")]) e.remove();
35643
- return n.outerHTML;
35644
- } finally {
35645
- t.remove();
35646
- }
35647
- }
35648
- var o_ = Promise.resolve();
35649
- async function s_(e) {
35650
- let t = o_.then(e, e);
35651
- return o_ = t.then(() => void 0, () => void 0), t;
35652
- }
35653
- async function c_(e, t) {
35654
- return s_(async () => {
35655
- let n = (await import("./mermaid.core-DI1iFk6G.js").then((e) => e.t)).default, r;
35656
- try {
35657
- n.initialize({
35658
- startOnLoad: !1,
35659
- theme: "default",
35660
- securityLevel: "strict",
35661
- suppressErrorRendering: !0,
35662
- flowchart: { htmlLabels: !1 },
35663
- htmlLabels: !1
35664
- }), {svg: r} = await n.render(t, e);
35665
- } catch (e) {
35666
- throw new t_(`mermaid could not render the diagram: ${String(e)}`);
35667
- } finally {
35668
- n.initialize({
35669
- startOnLoad: !1,
35670
- securityLevel: "strict",
35671
- suppressErrorRendering: !0
35672
- });
35673
- }
35674
- let { width: i, height: a } = n_(r), o = r_(r, i, a), s = await u_(o, i, a);
35675
- return {
35676
- svg: a_(o),
35677
- png: s,
35678
- width: i,
35679
- height: a
35680
- };
35681
- });
35682
- }
35683
- var l_ = 2;
35684
- async function u_(e, t, n) {
35685
- let r = document.createElement("canvas");
35686
- r.width = Math.max(1, Math.round(t * l_)), r.height = Math.max(1, Math.round(n * l_));
35687
- let i = r.getContext("2d");
35688
- if (i === null) throw new t_("no 2d canvas context for the fallback image");
35689
- let a = URL.createObjectURL(new Blob([e], { type: "image/svg+xml;charset=utf-8" }));
35690
- try {
35691
- let e = await d_(a);
35692
- return i.fillStyle = "#ffffff", i.fillRect(0, 0, r.width, r.height), i.drawImage(e, 0, 0, r.width, r.height), await f_(r);
35693
- } finally {
35694
- URL.revokeObjectURL(a);
35695
- }
35696
- }
35697
- function d_(e) {
35698
- return new Promise((t, n) => {
35699
- let r = new Image();
35700
- r.onload = () => t(r), r.onerror = () => n(new t_("the browser would not draw the diagram")), r.src = e;
35701
- });
35702
- }
35703
- async function f_(e) {
35704
- let t = await new Promise((t) => e.toBlob(t, "image/png"));
35705
- if (t === null) throw new t_("the canvas produced no image");
35706
- return new Uint8Array(await t.arrayBuffer());
35707
- }
35708
- //#endregion
35709
- //#region ../ui/src/export/loadReferencedImage.ts
35656
+ //#region ../shared/src/docx/markdownToDocx.ts
35657
+ var u_ = "Consolas, Courier New, monospace", d_ = 360, f_ = "md-ordered";
35710
35658
  function p_(e) {
35711
- return e !== "" && !c(e);
35712
- }
35713
- function m_(e, t, n, r) {
35714
- if (p_(t)) return s(n, l(e, t), r);
35715
- }
35716
- async function h_(e, t, n, r) {
35717
- let i = m_(e, t, n, r);
35718
- if (i !== void 0) try {
35719
- let e = await fetch(i);
35720
- return e.ok ? await g_(new Uint8Array(await e.arrayBuffer())) : void 0;
35721
- } catch {
35722
- return;
35723
- }
35724
- }
35725
- async function g_(e) {
35726
- if (__(e)) return v_(new TextDecoder().decode(e));
35727
- let t = x_(e);
35728
- return t === void 0 ? void 0 : {
35729
- kind: "raster",
35730
- ...t,
35731
- bytes: e
35732
- };
35733
- }
35734
- function __(e) {
35735
- return new TextDecoder().decode(e.subarray(0, 512)).toLowerCase().includes("<svg");
35736
- }
35737
- async function v_(e) {
35738
- try {
35739
- let { width: t, height: n } = y_(e), r = r_(e, t, n), i = await u_(r, t, n);
35740
- return {
35741
- kind: "vector",
35742
- image: {
35743
- svg: a_(r),
35744
- png: i,
35745
- width: t,
35746
- height: n
35747
- }
35748
- };
35749
- } catch {
35750
- return;
35751
- }
35752
- }
35753
- function y_(e) {
35754
- try {
35755
- return n_(e);
35756
- } catch {
35757
- let t = /<svg\b[^>]*>/.exec(e), n = b_(t?.[0] ?? "", "width"), r = b_(t?.[0] ?? "", "height");
35758
- if (n === void 0 || r === void 0) throw new t_("the referenced svg states no size");
35759
- return {
35760
- width: n,
35761
- height: r
35762
- };
35763
- }
35764
- }
35765
- function b_(e, t) {
35766
- let n = RegExp(`\\s${t}="([^"]*)"`).exec(e)?.[1];
35767
- if (n === void 0) return;
35768
- let r = Number.parseFloat(n.replace(/px$/i, ""));
35769
- return Number.isFinite(r) && r > 0 && !n.includes("%") ? r : void 0;
35659
+ return r().use(o).use(i).use(a).parse(t(e));
35770
35660
  }
35771
- function x_(e) {
35772
- return E_(e) ?? D_(e) ?? O_(e) ?? A_(e);
35773
- }
35774
- function S_(e, t) {
35775
- return (e[t] << 24 | e[t + 1] << 16 | e[t + 2] << 8 | e[t + 3]) >>> 0;
35776
- }
35777
- function C_(e, t) {
35778
- return e[t] | e[t + 1] << 8;
35779
- }
35780
- function w_(e, t) {
35781
- return e[t] | e[t + 1] << 8 | e[t + 2] << 16 | e[t + 3] << 24 | 0;
35782
- }
35783
- var T_ = [
35784
- 137,
35785
- 80,
35786
- 78,
35787
- 71,
35788
- 13,
35789
- 10,
35790
- 26,
35791
- 10
35792
- ];
35793
- function E_(e) {
35794
- if (!(e.length < 24) && T_.every((t, n) => e[n] === t)) return j_("png", S_(e, 16), S_(e, 20));
35795
- }
35796
- function D_(e) {
35797
- if (e.length < 10) return;
35798
- let t = String.fromCharCode(...e.subarray(0, 6));
35799
- if (t === "GIF87a" || t === "GIF89a") return j_("gif", C_(e, 6), C_(e, 8));
35800
- }
35801
- function O_(e) {
35802
- if (!(e.length < 26 || e[0] !== 66 || e[1] !== 77)) return j_("bmp", Math.abs(w_(e, 18)), Math.abs(w_(e, 22)));
35803
- }
35804
- var k_ = /* @__PURE__ */ new Set([
35805
- 192,
35806
- 193,
35807
- 194,
35808
- 195,
35809
- 197,
35810
- 198,
35811
- 199,
35812
- 201,
35813
- 202,
35814
- 203,
35815
- 205,
35816
- 206,
35817
- 207
35818
- ]);
35819
- function A_(e) {
35820
- if (e.length < 4 || e[0] !== 255 || e[1] !== 216) return;
35821
- let t = 2;
35822
- for (; t + 9 < e.length;) {
35823
- if (e[t] !== 255) {
35824
- t += 1;
35825
- continue;
35826
- }
35827
- let n = e[t + 1];
35828
- if (n === 255) {
35829
- t += 1;
35830
- continue;
35831
- }
35832
- if (n === 216 || n === 1 || n >= 208 && n <= 215) {
35833
- t += 2;
35834
- continue;
35835
- }
35836
- if (k_.has(n)) return j_("jpg", e[t + 7] << 8 | e[t + 8], e[t + 5] << 8 | e[t + 6]);
35837
- let r = e[t + 2] << 8 | e[t + 3];
35838
- if (r < 2) return;
35839
- t += 2 + r;
35840
- }
35841
- }
35842
- function j_(e, t, n) {
35843
- return t > 0 && n > 0 ? {
35844
- type: e,
35845
- width: t,
35846
- height: n
35847
- } : void 0;
35848
- }
35849
- //#endregion
35850
- //#region ../ui/src/export/markdownToDocx.ts
35851
- var M_ = "Consolas, Courier New, monospace", N_ = 360, P_ = "md-ordered";
35852
- function F_(e) {
35853
- return a().use(n).use(i).use(o).parse(t(e));
35854
- }
35855
- function I_(e, t) {
35661
+ function m_(e, t) {
35856
35662
  return new cr({
35857
- text: e_(e),
35663
+ text: l_(e),
35858
35664
  bold: t.bold,
35859
35665
  italics: t.italics,
35860
35666
  strike: t.strike,
35861
- ...t.code === !0 ? { font: M_ } : {}
35667
+ ...t.code === !0 ? { font: u_ } : {}
35862
35668
  });
35863
35669
  }
35864
- function L_(e, t, n = {}) {
35670
+ function h_(e, t, n = {}) {
35865
35671
  let r = [];
35866
35672
  for (let i of e) switch (i.type) {
35867
35673
  case "text":
35868
- r.push(I_(i.value, n));
35674
+ r.push(m_(i.value, n));
35869
35675
  break;
35870
35676
  case "strong":
35871
- r.push(...L_(i.children, t, {
35677
+ r.push(...h_(i.children, t, {
35872
35678
  ...n,
35873
35679
  bold: !0
35874
35680
  }));
35875
35681
  break;
35876
35682
  case "emphasis":
35877
- r.push(...L_(i.children, t, {
35683
+ r.push(...h_(i.children, t, {
35878
35684
  ...n,
35879
35685
  italics: !0
35880
35686
  }));
35881
35687
  break;
35882
35688
  case "delete":
35883
- r.push(...L_(i.children, t, {
35689
+ r.push(...h_(i.children, t, {
35884
35690
  ...n,
35885
35691
  strike: !0
35886
35692
  }));
35887
35693
  break;
35888
35694
  case "inlineCode":
35889
- r.push(I_(i.value, {
35695
+ r.push(m_(i.value, {
35890
35696
  ...n,
35891
35697
  code: !0
35892
35698
  }));
35893
35699
  break;
35894
35700
  case "link":
35895
35701
  r.push(new Oa({
35896
- children: L_(i.children, t, n),
35702
+ children: h_(i.children, t, n),
35897
35703
  link: i.url
35898
35704
  }));
35899
35705
  break;
@@ -35905,31 +35711,31 @@ function L_(e, t, n = {}) {
35905
35711
  break;
35906
35712
  case "image": {
35907
35713
  let e = t.get(i);
35908
- e === void 0 ? r.push(I_(i.alt ?? i.url, n)) : r.push(X_(e));
35714
+ e === void 0 ? r.push(m_(i.alt ?? i.url, n)) : r.push(O_(e, i.alt));
35909
35715
  break;
35910
35716
  }
35911
35717
  case "inlineMath":
35912
- r.push(...R_(i.value, !1, n));
35718
+ r.push(...g_(i.value, !1, n));
35913
35719
  break;
35914
- default: r.push(...L_(z_(i), t, n));
35720
+ default: r.push(...h_(__(i), t, n));
35915
35721
  }
35916
35722
  return r;
35917
35723
  }
35918
- function R_(e, t, n) {
35724
+ function g_(e, t, n) {
35919
35725
  try {
35920
- return [new Ga({ children: Xg(e, t) })];
35726
+ return [new Ga({ children: a_(e, t) })];
35921
35727
  } catch {
35922
- return [I_(e, {
35728
+ return [m_(e, {
35923
35729
  ...n,
35924
35730
  code: !0
35925
35731
  })];
35926
35732
  }
35927
35733
  }
35928
- function z_(e) {
35734
+ function __(e) {
35929
35735
  let t = e.children;
35930
35736
  return Array.isArray(t) ? t : [];
35931
35737
  }
35932
- var B_ = [
35738
+ var v_ = [
35933
35739
  _a.HEADING_1,
35934
35740
  _a.HEADING_2,
35935
35741
  _a.HEADING_3,
@@ -35937,17 +35743,17 @@ var B_ = [
35937
35743
  _a.HEADING_5,
35938
35744
  _a.HEADING_6
35939
35745
  ];
35940
- function V_(e, t) {
35746
+ function y_(e, t) {
35941
35747
  return new Wa({
35942
- heading: B_[Math.min(e.depth, 6) - 1],
35943
- children: L_(e.children, t)
35748
+ heading: v_[Math.min(e.depth, 6) - 1],
35749
+ children: h_(e.children, t)
35944
35750
  });
35945
35751
  }
35946
- function H_(e) {
35752
+ function b_(e) {
35947
35753
  return e.value.split("\n").map((e) => new Wa({
35948
35754
  children: [new cr({
35949
- text: e_(e === "" ? " " : e),
35950
- font: M_
35755
+ text: l_(e === "" ? " " : e),
35756
+ font: u_
35951
35757
  })],
35952
35758
  spacing: {
35953
35759
  before: 0,
@@ -35955,48 +35761,51 @@ function H_(e) {
35955
35761
  }
35956
35762
  }));
35957
35763
  }
35958
- var U_ = 624;
35959
- function W_(e, t) {
35960
- return e <= U_ ? {
35764
+ var x_ = 624;
35765
+ function S_(e, t) {
35766
+ return e <= x_ ? {
35961
35767
  width: Math.round(e),
35962
35768
  height: Math.round(t)
35963
35769
  } : {
35964
- width: U_,
35965
- height: Math.round(t * U_ / e)
35770
+ width: x_,
35771
+ height: Math.round(t * x_ / e)
35966
35772
  };
35967
35773
  }
35968
- function G_(e) {
35774
+ function C_(e) {
35969
35775
  return (e.lang ?? "").toLowerCase() === "mermaid";
35970
35776
  }
35971
- async function K_(e) {
35972
- let t = [], n = (e) => {
35973
- e.type === "code" && G_(e) && t.push(e);
35974
- for (let t of e.children ?? []) n(t);
35777
+ async function w_(e, t) {
35778
+ let n = /* @__PURE__ */ new Map();
35779
+ if (t === void 0) return n;
35780
+ let r = [], i = (e) => {
35781
+ e.type === "code" && C_(e) && r.push(e);
35782
+ for (let t of e.children ?? []) i(t);
35975
35783
  };
35976
- n(e);
35977
- let r = /* @__PURE__ */ new Map();
35978
- for (let [e, n] of t.entries()) try {
35979
- r.set(n, await c_(n.value, `docx-export-${e}`));
35784
+ i(e);
35785
+ for (let [e, i] of r.entries()) try {
35786
+ n.set(i, await t(i.value, `docx-export-${e}`));
35980
35787
  } catch {}
35981
- return r;
35788
+ return n;
35982
35789
  }
35983
- async function q_(e, t, n, r) {
35984
- let i = [], a = (e) => {
35985
- e.type === "image" && i.push(e);
35986
- for (let t of e.children ?? []) a(t);
35790
+ async function T_(e, t) {
35791
+ let n = /* @__PURE__ */ new Map(), { imageKey: r, loadImage: i } = t;
35792
+ if (r === void 0 || i === void 0) return n;
35793
+ let a = [], o = (e) => {
35794
+ e.type === "image" && a.push(e);
35795
+ for (let t of e.children ?? []) o(t);
35987
35796
  };
35988
- a(e);
35989
- let o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
35990
- for (let e of i) {
35991
- let i = m_(t, e.url, n, r);
35992
- if (i === void 0) continue;
35993
- s.has(i) || s.set(i, await h_(t, e.url, n, r));
35994
- let a = s.get(i);
35995
- a !== void 0 && o.set(e, a);
35996
- }
35997
- return o;
35797
+ o(e);
35798
+ let s = /* @__PURE__ */ new Map();
35799
+ for (let e of a) {
35800
+ let t = r(e.url);
35801
+ if (t === void 0) continue;
35802
+ s.has(t) || s.set(t, await i(e.url));
35803
+ let a = s.get(t);
35804
+ a !== void 0 && n.set(e, a);
35805
+ }
35806
+ return n;
35998
35807
  }
35999
- function J_(e) {
35808
+ function E_(e) {
36000
35809
  return new $i({
36001
35810
  type: "svg",
36002
35811
  data: new TextEncoder().encode(e.svg),
@@ -36004,25 +35813,33 @@ function J_(e) {
36004
35813
  type: "png",
36005
35814
  data: e.png
36006
35815
  },
36007
- transformation: W_(e.width, e.height)
35816
+ transformation: S_(e.width, e.height)
36008
35817
  });
36009
35818
  }
36010
- function Y_(e) {
35819
+ function D_(e) {
36011
35820
  return new Wa({
36012
35821
  alignment: bn.CENTER,
36013
- children: [J_(e)]
35822
+ children: [E_(e)]
36014
35823
  });
36015
35824
  }
36016
- function X_(e) {
36017
- return e.kind === "vector" ? J_(e.image) : new $i({
35825
+ function O_(e, t) {
35826
+ return e.kind === "vector" ? E_(e.image) : new $i({
36018
35827
  type: e.type,
36019
35828
  data: e.bytes,
36020
- transformation: W_(e.width, e.height)
35829
+ transformation: S_(e.width, e.height),
35830
+ ...k_(t)
36021
35831
  });
36022
35832
  }
36023
- function Z_(e) {
35833
+ function k_(e) {
35834
+ let t = e?.trim() ?? "";
35835
+ return t === "" ? {} : { altText: {
35836
+ name: "Picture",
35837
+ description: t
35838
+ } };
35839
+ }
35840
+ function A_(e) {
36024
35841
  return e === 0 ? {} : {
36025
- indent: { left: N_ * e },
35842
+ indent: { left: d_ * e },
36026
35843
  border: { left: {
36027
35844
  style: Cn.SINGLE,
36028
35845
  size: 12,
@@ -36031,36 +35848,36 @@ function Z_(e) {
36031
35848
  } }
36032
35849
  };
36033
35850
  }
36034
- function Q_(e, t, n = 0) {
35851
+ function j_(e, t, n = 0) {
36035
35852
  let r = e.ordered === !0, i = r ? t.instance++ : 0, a = [];
36036
35853
  for (let o of e.children) {
36037
35854
  let e = !0;
36038
35855
  for (let s of o.children) {
36039
35856
  if (s.type === "list") {
36040
- a.push(...Q_(s, t, n + 1));
35857
+ a.push(...j_(s, t, n + 1));
36041
35858
  continue;
36042
35859
  }
36043
35860
  if (s.type === "paragraph") {
36044
35861
  a.push(new Wa({
36045
- children: L_(s.children, t.images),
35862
+ children: h_(s.children, t.images),
36046
35863
  ...e ? r ? { numbering: {
36047
- reference: P_,
35864
+ reference: f_,
36048
35865
  level: n,
36049
35866
  instance: i
36050
- } } : { bullet: { level: n } } : { indent: { left: N_ * (n + 1) } }
35867
+ } } : { bullet: { level: n } } : { indent: { left: d_ * (n + 1) } }
36051
35868
  })), e = !1;
36052
35869
  continue;
36053
35870
  }
36054
- a.push(...tv([s], t));
35871
+ a.push(...P_([s], t));
36055
35872
  }
36056
35873
  }
36057
35874
  return a;
36058
35875
  }
36059
- function $_(e, t) {
35876
+ function M_(e, t) {
36060
35877
  return new ss({
36061
35878
  rows: e.children.map((e, n) => new ds({
36062
35879
  tableHeader: n === 0,
36063
- children: e.children.map((e) => new Yo({ children: [new Wa({ children: L_(e.children, t) })] }))
35880
+ children: e.children.map((e) => new Yo({ children: [new Wa({ children: h_(e.children, t) })] }))
36064
35881
  })),
36065
35882
  width: {
36066
35883
  size: 100,
@@ -36068,7 +35885,7 @@ function $_(e, t) {
36068
35885
  }
36069
35886
  });
36070
35887
  }
36071
- function ev() {
35888
+ function N_() {
36072
35889
  return new Wa({
36073
35890
  children: [],
36074
35891
  border: { bottom: {
@@ -36079,55 +35896,55 @@ function ev() {
36079
35896
  } }
36080
35897
  });
36081
35898
  }
36082
- function tv(e, t) {
35899
+ function P_(e, t) {
36083
35900
  let n = [];
36084
35901
  for (let r of e) switch (r.type) {
36085
35902
  case "heading":
36086
- n.push(V_(r, t.images));
35903
+ n.push(y_(r, t.images));
36087
35904
  break;
36088
35905
  case "paragraph":
36089
35906
  n.push(new Wa({
36090
- children: L_(r.children, t.images),
36091
- ...Z_(t.quoteDepth)
35907
+ children: h_(r.children, t.images),
35908
+ ...A_(t.quoteDepth)
36092
35909
  }));
36093
35910
  break;
36094
35911
  case "list":
36095
- n.push(...Q_(r, t));
35912
+ n.push(...j_(r, t));
36096
35913
  break;
36097
35914
  case "table":
36098
- n.push($_(r, t.images));
35915
+ n.push(M_(r, t.images));
36099
35916
  break;
36100
35917
  case "code": {
36101
35918
  let e = t.diagrams.get(r);
36102
- e === void 0 ? n.push(...H_(r)) : n.push(Y_(e));
35919
+ e === void 0 ? n.push(...b_(r)) : n.push(D_(e));
36103
35920
  break;
36104
35921
  }
36105
35922
  case "blockquote":
36106
- n.push(...tv(r.children, {
35923
+ n.push(...P_(r.children, {
36107
35924
  ...t,
36108
35925
  quoteDepth: t.quoteDepth + 1
36109
35926
  }));
36110
35927
  break;
36111
35928
  case "thematicBreak":
36112
- n.push(ev());
35929
+ n.push(N_());
36113
35930
  break;
36114
35931
  case "math":
36115
35932
  n.push(new Wa({
36116
- children: R_(r.value, !0, {}),
35933
+ children: g_(r.value, !0, {}),
36117
35934
  alignment: bn.CENTER
36118
35935
  }));
36119
35936
  break;
36120
35937
  default: {
36121
- let e = L_(z_(r), t.images);
35938
+ let e = h_(__(r), t.images);
36122
35939
  e.length > 0 && n.push(new Wa({ children: e }));
36123
35940
  break;
36124
35941
  }
36125
35942
  }
36126
35943
  return n;
36127
35944
  }
36128
- async function nv(e, t) {
36129
- let n = F_(e), r = await K_(n), i = await q_(n, t?.path ?? "", t?.serverUrl ?? "", t?.token ?? null);
36130
- return tv(n.children, {
35945
+ async function F_(e, t = {}) {
35946
+ let n = p_(e), r = await w_(n, t.renderDiagram), i = await T_(n, t);
35947
+ return P_(n.children, {
36131
35948
  instance: 0,
36132
35949
  quoteDepth: 0,
36133
35950
  diagrams: r,
@@ -36135,39 +35952,28 @@ async function nv(e, t) {
36135
35952
  });
36136
35953
  }
36137
35954
  //#endregion
36138
- //#region ../ui/src/export/plainTextToDocx.ts
36139
- var rv = "Consolas, Courier New, monospace";
36140
- function iv(e) {
36141
- return e.replace(/\r\n/g, "\n").replace(/\n$/, "").split("\n").map((e) => new Wa({
36142
- children: [new cr({
36143
- text: e_(e === "" ? " " : e),
36144
- font: rv
36145
- })],
36146
- spacing: {
36147
- before: 0,
36148
- after: 0
36149
- }
36150
- }));
36151
- }
36152
- //#endregion
36153
- //#region ../ui/src/export/docxExport.ts
36154
- function av(e) {
36155
- let t = e.split(/[/\\]/).pop() ?? "document", n = t.lastIndexOf(".");
36156
- return `${n > 0 ? t.slice(0, n) : t}.docx`;
36157
- }
36158
- function ov(e) {
36159
- return /\.(md|markdown)$/i.test(e);
36160
- }
36161
- async function sv(e, t, n) {
36162
- let r = new wl({
36163
- numbering: { config: [cv()] },
36164
- sections: [{ children: await lv(e, t, n) }]
35955
+ //#region ../shared/src/docx/document.ts
35956
+ function I_(e) {
35957
+ return new wl({
35958
+ styles: { default: L_() },
35959
+ numbering: { config: [R_()] },
35960
+ sections: [{ children: e }]
36165
35961
  });
36166
- return Ul.toBlob(r);
36167
35962
  }
36168
- function cv() {
35963
+ function L_() {
35964
+ let e = (e) => ({ paragraph: { outlineLevel: e } });
36169
35965
  return {
36170
- reference: P_,
35966
+ heading1: e(0),
35967
+ heading2: e(1),
35968
+ heading3: e(2),
35969
+ heading4: e(3),
35970
+ heading5: e(4),
35971
+ heading6: e(5)
35972
+ };
35973
+ }
35974
+ function R_() {
35975
+ return {
35976
+ reference: f_,
36171
35977
  levels: [
36172
35978
  wc.DECIMAL,
36173
35979
  wc.LOWER_LETTER,
@@ -36186,14 +35992,69 @@ function cv() {
36186
35992
  }))
36187
35993
  };
36188
35994
  }
36189
- async function lv(e, t, n) {
36190
- return ov(t) ? nv(e, {
35995
+ //#endregion
35996
+ //#region ../ui/src/export/markdownToDocx.ts
35997
+ async function z_(e, t) {
35998
+ let n = t?.path ?? "", r = t?.serverUrl ?? "", i = t?.token ?? null;
35999
+ return F_(e, {
36000
+ imageKey: (e) => c(n, e, r, i),
36001
+ loadImage: (e) => l(n, e, r, i),
36002
+ renderDiagram: s
36003
+ });
36004
+ }
36005
+ //#endregion
36006
+ //#region ../ui/src/export/plainTextToDocx.ts
36007
+ var B_ = "Consolas, Courier New, monospace";
36008
+ function V_(e) {
36009
+ return e.replace(/\r\n/g, "\n").replace(/\n$/, "").split("\n").map((e) => new Wa({
36010
+ children: [new cr({
36011
+ text: l_(e === "" ? " " : e),
36012
+ font: B_
36013
+ })],
36014
+ spacing: {
36015
+ before: 0,
36016
+ after: 0
36017
+ }
36018
+ }));
36019
+ }
36020
+ //#endregion
36021
+ //#region ../ui/src/export/docxExport.ts
36022
+ function H_(e) {
36023
+ let t = e.split(/[/\\]/).pop() ?? "document", n = t.lastIndexOf(".");
36024
+ return `${n > 0 ? t.slice(0, n) : t}.docx`;
36025
+ }
36026
+ function U_(e) {
36027
+ return /\.(md|markdown)$/i.test(e);
36028
+ }
36029
+ async function W_(e, t, n) {
36030
+ return Ul.toBlob(I_(await G_(e, t, n)));
36031
+ }
36032
+ async function G_(e, t, n) {
36033
+ return U_(t) ? z_(e, {
36191
36034
  ...n,
36192
36035
  path: t
36193
- }) : iv(e);
36036
+ }) : V_(e);
36037
+ }
36038
+ async function K_(e, t, r) {
36039
+ n(await W_(e, t, r), H_(t));
36040
+ }
36041
+ var q_ = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
36042
+ async function J_(e, t, n) {
36043
+ let r = await W_(e, t, n), i = { "Content-Type": q_ };
36044
+ n?.token && (i.Authorization = `Bearer ${n.token}`);
36045
+ let a = await fetch(`${n?.serverUrl ?? ""}/files/docx-template`, {
36046
+ method: "POST",
36047
+ headers: i,
36048
+ body: r
36049
+ });
36050
+ if (!a.ok) {
36051
+ let e = await a.json().catch(() => null);
36052
+ throw Error(e?.message ?? `the server answered ${a.status}`);
36053
+ }
36054
+ return a.blob();
36194
36055
  }
36195
- async function uv(e, t, n) {
36196
- r(await sv(e, t, n), av(t));
36056
+ async function Y_(e, t, r) {
36057
+ n(await J_(e, t, r), H_(t));
36197
36058
  }
36198
36059
  //#endregion
36199
- export { uv as downloadDocx };
36060
+ export { K_ as downloadDocx, Y_ as downloadDocxInTemplate };