@forevka/wordcanvas 0.7.1 → 0.7.3

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.
Files changed (64) hide show
  1. package/dist-lib/assets/{worker-D8rUOKfg.js → worker-CqU4Popa.js} +10903 -10736
  2. package/dist-lib/assets/worker-Cw5cYW5z.js +2418 -0
  3. package/dist-lib/blockFactory-DDCRWDnA.js +91 -0
  4. package/dist-lib/browser-BUrsjziD.js +612 -0
  5. package/dist-lib/builder.js +13 -13
  6. package/dist-lib/editorApp-CB_ZArIF.js +9566 -0
  7. package/dist-lib/export.js +4507 -4456
  8. package/dist-lib/generate-toc.js +7 -7
  9. package/dist-lib/import.js +2 -2
  10. package/dist-lib/lists-DpmgbDyt.js +110 -0
  11. package/dist-lib/measure.js +2 -2
  12. package/dist-lib/{measureHost-CMiJKdlk.js → measureHost-BlukHGwx.js} +1 -1
  13. package/dist-lib/metrics-bvGO8KDK.js +96 -0
  14. package/dist-lib/paintStyle-vT6jtWbH.js +74 -0
  15. package/dist-lib/pipeline-UryP-u7Z.js +1850 -0
  16. package/dist-lib/recalc-docx.js +2 -2
  17. package/dist-lib/recalcToc-BfXlXZik.js +3985 -0
  18. package/dist-lib/styleProps-DhqDEfvc.js +149 -0
  19. package/dist-lib/stylesheet-LTBEGkvG.js +146 -0
  20. package/dist-lib/toc-D09f4PrI.js +939 -0
  21. package/dist-lib/{webmcp-6WxRNKCc.js → webmcp-K6UZgQJ0.js} +60 -68
  22. package/dist-lib/wordcanvas-DBx2ana_.js +734 -0
  23. package/dist-lib/wordcanvas.js +4 -2
  24. package/dist-node/{chunk-CDN6WU2P.js → chunk-373K2XRY.js} +40 -22
  25. package/dist-node/chunk-373K2XRY.js.map +7 -0
  26. package/dist-node/{chunk-22JHAERT.js → chunk-3PUV3BG6.js} +235 -39
  27. package/dist-node/chunk-3PUV3BG6.js.map +7 -0
  28. package/dist-node/{chunk-4ICCHZX4.js → chunk-5RX3IHWE.js} +39 -3
  29. package/dist-node/chunk-5RX3IHWE.js.map +7 -0
  30. package/dist-node/{chunk-4PDVRJF6.js → chunk-EMY2P524.js} +32 -2
  31. package/dist-node/chunk-EMY2P524.js.map +7 -0
  32. package/dist-node/{chunk-BRAPV465.js → chunk-HWQKGDS2.js} +2 -2
  33. package/dist-node/{chunk-6AJJMHKY.js → chunk-KJV7GJ3H.js} +1 -1
  34. package/dist-node/chunk-KJV7GJ3H.js.map +7 -0
  35. package/dist-node/{chunk-RNB336F3.js → chunk-ZLLSXOO2.js} +92 -14
  36. package/dist-node/{chunk-RNB336F3.js.map → chunk-ZLLSXOO2.js.map} +2 -2
  37. package/dist-node/{engine-5FGDJD2H.js → engine-LLA6PCS5.js} +4 -4
  38. package/dist-node/export.js +89 -24
  39. package/dist-node/export.js.map +2 -2
  40. package/dist-node/generate-toc.js +6 -6
  41. package/dist-node/import.js +3 -3
  42. package/dist-node/measure.js +2 -2
  43. package/dist-node/recalc-docx.js +4 -4
  44. package/package.json +1 -1
  45. package/types/model.d.ts +46 -0
  46. package/types/wordcanvas.d.ts +493 -1
  47. package/dist-lib/assets/worker-wXuuyshQ.js +0 -2258
  48. package/dist-lib/blockFactory-CUI4Rqiq.js +0 -186
  49. package/dist-lib/browser-DkKxreJM.js +0 -1305
  50. package/dist-lib/editorApp-DLXMmtu5.js +0 -8023
  51. package/dist-lib/lists-Sc5I40JO.js +0 -110
  52. package/dist-lib/metrics-CkAo4zh8.js +0 -143
  53. package/dist-lib/pipeline-CbxmCE84.js +0 -1705
  54. package/dist-lib/recalcToc-g1hFKSNs.js +0 -3935
  55. package/dist-lib/styleProps-Db5pEkG8.js +0 -127
  56. package/dist-lib/toc-B6VpkJge.js +0 -213
  57. package/dist-lib/wordcanvas-CFqpDK0k.js +0 -125
  58. package/dist-node/chunk-22JHAERT.js.map +0 -7
  59. package/dist-node/chunk-4ICCHZX4.js.map +0 -7
  60. package/dist-node/chunk-4PDVRJF6.js.map +0 -7
  61. package/dist-node/chunk-6AJJMHKY.js.map +0 -7
  62. package/dist-node/chunk-CDN6WU2P.js.map +0 -7
  63. /package/dist-node/{chunk-BRAPV465.js.map → chunk-HWQKGDS2.js.map} +0 -0
  64. /package/dist-node/{engine-5FGDJD2H.js.map → engine-LLA6PCS5.js.map} +0 -0
@@ -1,127 +0,0 @@
1
- const l = (i) => Number.isFinite(i) ? i : 0, s = (i) => Math.round(l(i) * 15), f = (i) => Math.round(l(i) * 1.5), x = (i) => Math.round(l(i) * 9525), P = (i) => Math.max(2, Math.round(l(i) * 6)), h = (i) => Math.round(l(i) * 240), w = {
2
- "#ffff00": "yellow",
3
- "#00ff00": "green",
4
- "#00ffff": "cyan",
5
- "#ff00ff": "magenta",
6
- "#0000ff": "blue",
7
- "#ff0000": "red",
8
- "#000080": "darkBlue",
9
- "#008080": "darkCyan",
10
- "#008000": "darkGreen",
11
- "#800080": "darkMagenta",
12
- "#800000": "darkRed",
13
- "#808000": "darkYellow",
14
- "#808080": "darkGray",
15
- "#c0c0c0": "lightGray",
16
- "#000000": "black",
17
- "#ffffff": "white"
18
- }, c = { left: "left", center: "center", right: "right", justify: "both" }, p = { left: "left", center: "center", right: "right", decimal: "decimal" }, u = { dot: "dot", dash: "hyphen", underscore: "underscore" }, d = (i) => i.replace(/^#/, "").toLowerCase();
19
- function g(i) {
20
- return i.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
21
- }
22
- function m(i) {
23
- return g(i).replace(/"/g, "&quot;");
24
- }
25
- function v(i) {
26
- if (!i) return "";
27
- let n = "";
28
- for (const [e, o] of Object.entries(i))
29
- o === void 0 || o === !1 || (n += ` ${e}="${m(String(o))}"`);
30
- return n;
31
- }
32
- function t(i, n, e) {
33
- const o = v(n);
34
- return e === void 0 || e === "" ? `<${i}${o}/>` : `<${i}${o}>${e}</${i}>`;
35
- }
36
- function b(i) {
37
- const n = /^\s|\s$|\s\s/.test(i) || i.includes(" ");
38
- return t("w:t", n ? { "xml:space": "preserve" } : void 0, g(i));
39
- }
40
- const L = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
41
- `, k = {
42
- "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
43
- "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
44
- "xmlns:wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
45
- "xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
46
- "xmlns:pic": "http://schemas.openxmlformats.org/drawingml/2006/picture",
47
- "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
48
- "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006"
49
- };
50
- function A(i) {
51
- const n = (i.fontFamily.split(",")[0] ?? "").trim(), e = [];
52
- if (n && e.push(t("w:rFonts", { "w:ascii": n, "w:hAnsi": n, "w:cs": n })), e.push(t("w:b", { "w:val": i.bold ? "1" : "0" })), e.push(t("w:i", { "w:val": i.italic ? "1" : "0" })), i.strikethrough && e.push(t("w:strike", { "w:val": "1" })), i.hidden && e.push(t("w:vanish", { "w:val": "1" })), e.push(t("w:color", { "w:val": d(i.color) })), e.push(t("w:sz", { "w:val": f(i.fontSizePx) })), e.push(t("w:szCs", { "w:val": f(i.fontSizePx) })), e.push(t("w:u", { "w:val": i.underline ? "single" : "none" })), i.letterSpacingPx !== void 0 && e.push(t("w:spacing", { "w:val": s(i.letterSpacingPx) })), i.highlightColor) {
53
- const o = w[i.highlightColor.toLowerCase()];
54
- o && e.push(t("w:highlight", { "w:val": o }));
55
- }
56
- return i.verticalAlign && e.push(t("w:vertAlign", { "w:val": i.verticalAlign === "super" ? "superscript" : "subscript" })), t("w:rPr", void 0, e.join(""));
57
- }
58
- function F(i) {
59
- const n = [];
60
- n.push(t("w:spacing", {
61
- "w:before": s(i.spaceBeforePx),
62
- "w:after": s(i.spaceAfterPx),
63
- "w:line": h(i.lineHeight),
64
- "w:lineRule": "auto"
65
- }));
66
- const e = {};
67
- if (i.indentLeftPx && (e["w:left"] = s(i.indentLeftPx)), i.indentRightPx && (e["w:right"] = s(i.indentRightPx)), i.indentFirstLinePx > 0 ? e["w:firstLine"] = s(i.indentFirstLinePx) : i.indentFirstLinePx < 0 && (e["w:hanging"] = s(-i.indentFirstLinePx)), Object.keys(e).length > 0 && n.push(t("w:ind", e)), n.push(t("w:jc", { "w:val": c[i.align] })), i.tabStops && i.tabStops.length > 0) {
68
- const o = i.tabStops.map(
69
- (r) => t("w:tab", {
70
- "w:val": r.align ? p[r.align] ?? "left" : "left",
71
- "w:pos": s(r.posPx),
72
- "w:leader": r.leader && r.leader !== "none" ? u[r.leader] : void 0
73
- })
74
- ).join("");
75
- n.push(t("w:tabs", void 0, o));
76
- }
77
- return n.join("");
78
- }
79
- function C(i) {
80
- const n = [];
81
- if (i.fontFamily) {
82
- const e = (i.fontFamily.split(",")[0] ?? "").trim();
83
- e && n.push(t("w:rFonts", { "w:ascii": e, "w:hAnsi": e, "w:cs": e }));
84
- }
85
- if (i.bold !== void 0 && n.push(t("w:b", { "w:val": i.bold ? "1" : "0" })), i.italic !== void 0 && n.push(t("w:i", { "w:val": i.italic ? "1" : "0" })), i.strikethrough !== void 0 && n.push(t("w:strike", { "w:val": i.strikethrough ? "1" : "0" })), i.color && n.push(t("w:color", { "w:val": d(i.color) })), i.fontSizePx !== void 0) {
86
- const e = Math.round(i.fontSizePx * 1.5);
87
- n.push(t("w:sz", { "w:val": e })), n.push(t("w:szCs", { "w:val": e }));
88
- }
89
- if (i.underline !== void 0 && n.push(t("w:u", { "w:val": i.underline ? "single" : "none" })), i.highlightColor) {
90
- const e = w[i.highlightColor.toLowerCase()];
91
- e && n.push(t("w:highlight", { "w:val": e }));
92
- }
93
- return i.verticalAlign && n.push(t("w:vertAlign", { "w:val": i.verticalAlign === "super" ? "superscript" : "subscript" })), n.length > 0 ? t("w:rPr", void 0, n.join("")) : "";
94
- }
95
- function S(i) {
96
- const n = [];
97
- i.align && n.push(t("w:jc", { "w:val": c[i.align] ?? "left" }));
98
- const e = {};
99
- i.spaceBeforePx !== void 0 && (e["w:before"] = s(i.spaceBeforePx)), i.spaceAfterPx !== void 0 && (e["w:after"] = s(i.spaceAfterPx)), i.lineHeight !== void 0 && (e["w:line"] = h(i.lineHeight), e["w:lineRule"] = "auto"), Object.keys(e).length > 0 && n.push(t("w:spacing", e));
100
- const o = {};
101
- if (i.indentLeftPx !== void 0 && (o["w:left"] = s(i.indentLeftPx)), i.indentRightPx !== void 0 && (o["w:right"] = s(i.indentRightPx)), i.indentFirstLinePx !== void 0 && (i.indentFirstLinePx >= 0 ? o["w:firstLine"] = s(i.indentFirstLinePx) : o["w:hanging"] = s(-i.indentFirstLinePx)), Object.keys(o).length > 0 && n.push(t("w:ind", o)), i.keepWithNext && n.push(t("w:keepNext")), i.keepLinesTogether && n.push(t("w:keepLines")), i.tabStops && i.tabStops.length > 0) {
102
- const r = i.tabStops.map(
103
- (a) => t("w:tab", {
104
- "w:val": a.align ? p[a.align] ?? "left" : "left",
105
- "w:pos": s(a.posPx),
106
- "w:leader": a.leader && a.leader !== "none" ? u[a.leader] : void 0
107
- })
108
- ).join("");
109
- n.push(t("w:tabs", void 0, r));
110
- }
111
- return n.length > 0 ? t("w:pPr", void 0, n.join("")) : "";
112
- }
113
- export {
114
- k as W,
115
- L as X,
116
- g as a,
117
- F as b,
118
- x as c,
119
- P as d,
120
- t as e,
121
- C as f,
122
- S as g,
123
- d as h,
124
- s as p,
125
- A as r,
126
- b as t
127
- };
@@ -1,213 +0,0 @@
1
- import { t as b, v as k, y as v } from "./browser-DkKxreJM.js";
2
- function y(t, e = 0) {
3
- let i = e;
4
- return {
5
- siteId: t,
6
- next: () => `${t}-${(i++).toString(36)}`,
7
- count: () => i
8
- };
9
- }
10
- let h = y("local");
11
- function E(t, e = 0) {
12
- h = y(t, e);
13
- }
14
- function g() {
15
- return h.next();
16
- }
17
- function A() {
18
- return h.siteId;
19
- }
20
- const m = (t) => {
21
- if (!t) return;
22
- const e = t.match(/^(\d+)\s*-\s*(\d+)$/);
23
- if (e) return { from: Number(e[1]), to: Number(e[2]) };
24
- const i = t.match(/^\d+$/) ? Number(t) : NaN;
25
- return Number.isNaN(i) ? void 0 : { from: i, to: i };
26
- };
27
- function S(t) {
28
- const e = {
29
- useOutlineLevels: /\\u\b/.test(t),
30
- hyperlinks: /\\h\b/.test(t),
31
- hideInWeb: /\\z\b/.test(t)
32
- }, i = m(t.match(/\\o\s+"([^"]+)"/)?.[1]);
33
- i && (e.outlineRange = i);
34
- const n = m(t.match(/\\n\s+"?([0-9-]+)"?/)?.[1]);
35
- n && (e.hidePageNumberRange = n);
36
- const a = t.match(/\\p\s+"([^"]*)"/)?.[1];
37
- a !== void 0 && (e.separator = a);
38
- const s = t.match(/\\t\s+"([^"]+)"/)?.[1];
39
- if (s) {
40
- const r = s.split(","), o = {};
41
- for (let l = 0; l + 1 < r.length; l += 2) {
42
- const c = r[l].trim(), u = Number(r[l + 1].trim());
43
- c && u >= 1 && (o[c] = u);
44
- }
45
- Object.keys(o).length > 0 && (e.customStyles = o);
46
- }
47
- return e;
48
- }
49
- function B(t) {
50
- const e = ["TOC"];
51
- if (t.outlineRange && e.push(`\\o "${t.outlineRange.from}-${t.outlineRange.to}"`), t.useOutlineLevels && e.push("\\u"), t.customStyles && Object.keys(t.customStyles).length > 0) {
52
- const i = Object.entries(t.customStyles).map(([n, a]) => `${n},${a}`).join(",");
53
- e.push(`\\t "${i}"`);
54
- }
55
- return t.hyperlinks && e.push("\\h"), t.hidePageNumberRange && e.push(`\\n "${t.hidePageNumberRange.from}-${t.hidePageNumberRange.to}"`), t.separator !== void 0 && e.push(`\\p "${t.separator}"`), t.hideInWeb && e.push("\\z"), ` ${e.join(" ")} `;
56
- }
57
- const C = (t, e) => !!t && e >= t.from && e <= t.to;
58
- function p(t, e) {
59
- if (!e || !t.stylesheet) return;
60
- const i = new Map(t.stylesheet.styles.map((s) => [s.id, s]));
61
- let n = i.get(e);
62
- const a = /* @__PURE__ */ new Set();
63
- for (; n && !a.has(n.id); ) {
64
- if (n.name && /(?:^|\s)heading\s*\d/i.test(n.name)) return n.name;
65
- a.add(n.id), n = n.basedOn ? i.get(n.basedOn) : void 0;
66
- }
67
- return i.get(e)?.name;
68
- }
69
- function I(t, e, i) {
70
- const n = t.style.namedStyle;
71
- if (i?.customStyles && n) {
72
- const r = i.customStyles[n] ?? i.customStyles[p(e, n) ?? ""];
73
- if (r) return r;
74
- }
75
- if (t.style.outlineLevel !== void 0) return t.style.outlineLevel + 1;
76
- const a = n?.match(/^heading\s*(\d)$/i);
77
- if (a) return Number(a[1]);
78
- const s = p(e, n)?.match(/(?:^|\s)heading\s*(\d)/i);
79
- return s ? Number(s[1]) : null;
80
- }
81
- function R(t, e, i = 3) {
82
- const n = e?.outlineRange?.to ?? i, a = [];
83
- for (const s of v(t)) {
84
- const r = I(s, t, e);
85
- r === null || r < 1 || r > n || e?.outlineRange && (r < e.outlineRange.from || r > e.outlineRange.to) || a.push({ block: s, level: r });
86
- }
87
- return a;
88
- }
89
- function H(t, e = 20) {
90
- if (!t.bookmarks) return 0;
91
- const i = t.section.pageWidthPx - t.section.marginPx.left - t.section.marginPx.right;
92
- let n = 0;
93
- for (const a of t.blocks) {
94
- if (a.kind !== "paragraph" || a.style.tocEntry) continue;
95
- const s = a.runs.find((u) => u.style.link?.startsWith("#"))?.style.link?.slice(1);
96
- if (!s) continue;
97
- const r = t.bookmarks[s]?.start.blockId;
98
- if (!r) continue;
99
- const o = b(a.runs), l = o.match(/\t\d+\s*$/);
100
- if (!l) continue;
101
- a.runs = k(a.runs, 0, o.length - l[0].length), a.runs.length === 0 && (a.runs = [{ text: "", style: { ...f } }]);
102
- const c = Math.min(9, Math.max(1, Math.round((a.style.indentLeftPx || 0) / e) + 1));
103
- a.style.tocEntry = { targetId: r, level: c }, !a.style.tabStops?.length && i > 0 && (a.style.tabStops = [{ posPx: i, align: "right", leader: "dot" }]), a.revision++, n++;
104
- }
105
- return n;
106
- }
107
- const f = {
108
- fontFamily: "Georgia, serif",
109
- fontSizePx: 13,
110
- bold: !1,
111
- italic: !1,
112
- underline: !1,
113
- strikethrough: !1,
114
- color: "#202124"
115
- };
116
- function L(t, e, i, n) {
117
- const a = t.indentStepPx ?? 20, s = t.leader ?? "dot";
118
- let r, o;
119
- if (n && (n.char || n.para)) {
120
- r = { ...f, ...n.char, ...t.baseChar, ...t.levels?.[e]?.char };
121
- const l = n.para?.indentLeftPx ?? 0;
122
- o = {
123
- align: "left",
124
- lineHeight: 1.5,
125
- spaceBeforePx: 0,
126
- spaceAfterPx: 2,
127
- indentFirstLinePx: 0,
128
- ...n.para,
129
- indentLeftPx: l + (e - 1) * a,
130
- ...t.levels?.[e]?.para
131
- };
132
- } else
133
- r = { ...{ ...f, ...t.baseChar }, fontSizePx: e === 1 ? 14 : 13, bold: e === 1, ...t.levels?.[e]?.char }, o = {
134
- align: "left",
135
- lineHeight: 1.5,
136
- spaceBeforePx: 0,
137
- spaceAfterPx: 2,
138
- indentFirstLinePx: 0,
139
- indentLeftPx: (e - 1) * a,
140
- ...t.levels?.[e]?.para
141
- };
142
- return s !== "none" && i > 0 ? o.tabStops = [{ posPx: i, align: "right", leader: s }] : delete o.tabStops, { char: r, para: o };
143
- }
144
- function N(t) {
145
- if (t.title === null) return null;
146
- const e = t.title ?? {}, i = { ...f, ...t.baseChar };
147
- return {
148
- text: e.text ?? "Table of Contents",
149
- char: { ...i, fontSizePx: 20, bold: !0, ...e.char },
150
- para: {
151
- align: "left",
152
- lineHeight: 1.4,
153
- spaceBeforePx: 8,
154
- spaceAfterPx: 12,
155
- indentFirstLinePx: 0,
156
- indentLeftPx: 0,
157
- namedStyle: e.namedStyle ?? "tocTitle",
158
- ...e.para
159
- }
160
- };
161
- }
162
- const $ = 3;
163
- function T(t, e = {}) {
164
- const i = t.tocInstruction ? S(t.tocInstruction) : void 0, n = e.maxLevel ?? i?.outlineRange?.to ?? $, a = t.section.pageWidthPx - t.section.marginPx.left - t.section.marginPx.right, s = t.tocAnchorBlockId ? t.blocks.find((c) => c.kind === "paragraph" && c.id === t.tocAnchorBlockId) : void 0, r = s ? { char: s.runs[0]?.style, para: s.style } : void 0, o = [];
165
- if (e.title !== void 0 ? e.title !== null : s === void 0) {
166
- const c = N(e);
167
- c && o.push({
168
- kind: "paragraph",
169
- id: g(),
170
- revision: 0,
171
- runs: [{ text: c.text, style: c.char }],
172
- style: c.para
173
- });
174
- }
175
- for (const { block: c, level: u } of R(t, i, n)) {
176
- const d = b(c.runs).replace(/\v/g, " ").trim();
177
- if (d.length === 0) continue;
178
- const { char: x, para: P } = L(e, u, a, r);
179
- o.push({
180
- kind: "paragraph",
181
- id: g(),
182
- revision: 0,
183
- runs: [{ text: d, style: x }],
184
- style: { ...P, tocEntry: { targetId: c.id, level: u } }
185
- });
186
- }
187
- return o;
188
- }
189
- function W(t, e = {}) {
190
- if (t.blocks.some((r) => r.kind === "paragraph" && r.style.tocEntry))
191
- return { doc: t, generated: 0, headings: 0 };
192
- if (t.tocAnchorBlockId === void 0) return { doc: t, generated: 0, headings: 0 };
193
- const i = t.blocks.findIndex((r) => r.id === t.tocAnchorBlockId);
194
- if (i < 0) return { doc: t, generated: 0, headings: 0 };
195
- const n = T(t, e), a = n.reduce((r, o) => r + (o.style.tocEntry ? 1 : 0), 0);
196
- if (a === 0) return { doc: t, generated: 0, headings: 0 };
197
- const s = [...t.blocks];
198
- return s.splice(i, 1, ...n), { doc: { ...t, blocks: s }, generated: a, headings: a };
199
- }
200
- export {
201
- T as a,
202
- B as b,
203
- A as c,
204
- R as d,
205
- E as e,
206
- g as f,
207
- W as g,
208
- y as h,
209
- C as i,
210
- H as m,
211
- S as p,
212
- L as t
213
- };
@@ -1,125 +0,0 @@
1
- function r(s, e) {
2
- const a = e > 0 ? s / e : 1;
3
- return { phase: "fonts", loaded: s, total: e, percent: 0.15 + (1 - 0.15) * a };
4
- }
5
- class o {
6
- handle = null;
7
- ready;
8
- handlers = /* @__PURE__ */ new Map();
9
- constructor(e) {
10
- this.ready = new Promise((a) => {
11
- const t = {
12
- container: e.container,
13
- backendUrl: e.backendUrl,
14
- // `docId` is the canonical name; fall back to the deprecated `collabId`.
15
- collabId: e.docId ?? e.collabId,
16
- user: e.user,
17
- onShareLink: e.onShareLink,
18
- readonly: e.readonly,
19
- mode: e.mode,
20
- allowedModes: e.allowedModes,
21
- knownUsers: e.knownUsers,
22
- resolveField: e.resolveField,
23
- agentTools: e.agentTools,
24
- onLoadProgress: e.onLoadProgress,
25
- onReady: (n) => {
26
- this.handle = n, a(n);
27
- },
28
- onEvent: (n) => this.emit(n)
29
- };
30
- e.onLoadProgress?.({ phase: "bundle", percent: 0, loaded: 0, total: 0 }), import("./editorApp-DLXMmtu5.js").then((n) => n.e).then((n) => (e.onLoadProgress?.({ phase: "bundle", percent: 0.15, loaded: 0, total: 0 }), n.mountEditorApp(t)));
31
- });
32
- }
33
- /** Subscribe to a collaboration event. Returns an unsubscribe function. */
34
- on(e, a) {
35
- let t = this.handlers.get(e);
36
- return t || this.handlers.set(e, t = /* @__PURE__ */ new Set()), t.add(a), () => this.off(e, a);
37
- }
38
- /** Unsubscribe a handler previously passed to on(). */
39
- off(e, a) {
40
- this.handlers.get(e)?.delete(a);
41
- }
42
- emit(e) {
43
- const { type: a, ...t } = e;
44
- for (const n of this.handlers.get(a) ?? []) n(t);
45
- }
46
- /** Resolves once the editor is mounted and ready. */
47
- whenReady() {
48
- return this.ready;
49
- }
50
- /** Open a .docx. When online, auto-publishes it and surfaces a share link. */
51
- async openDocx(e) {
52
- return (await this.ready).openDocx(e);
53
- }
54
- /** Replace the open document with a programmatically-built one (e.g. a
55
- * DocumentBuilder result). The input is cloned. Like openDocx, this starts
56
- * a NEW document: undo history and any live collab session are dropped
57
- * (the next share() forks). Zoom and scroll position are preserved, so
58
- * calling this on every data change gives a stable live preview. */
59
- async setDocument(e) {
60
- (await this.ready).setDocument(e);
61
- }
62
- /** Publish the current document and resolve its shareable link (online only). */
63
- async share() {
64
- return (await this.ready).share();
65
- }
66
- // ---- review layer (track changes + comments) ----------------------------
67
- /** Current editor mode. Returns null before the editor is ready. */
68
- getMode() {
69
- return this.handle?.getMode() ?? null;
70
- }
71
- /** Switch mode. Resolves to false if the mode isn't allowed (or not ready). */
72
- async setMode(e) {
73
- return (await this.ready).setMode(e);
74
- }
75
- /** Snapshot of the review overlay (suggestions + comment threads). */
76
- async getReview() {
77
- return (await this.ready).getReview();
78
- }
79
- /** The effective @-mentionable roster: the configured base PLUS whoever is
80
- * live-editing the document right now (auto-merged from presence). */
81
- async getKnownUsers() {
82
- return (await this.ready).getKnownUsers();
83
- }
84
- /** Replace the configured base roster (live editors are still merged on top). */
85
- async setKnownUsers(e) {
86
- (await this.ready).setKnownUsers(e);
87
- }
88
- async acceptSuggestion(e) {
89
- (await this.ready).acceptSuggestion(e);
90
- }
91
- async rejectSuggestion(e) {
92
- (await this.ready).rejectSuggestion(e);
93
- }
94
- async acceptAllSuggestions() {
95
- (await this.ready).acceptAllSuggestions();
96
- }
97
- async rejectAllSuggestions() {
98
- (await this.ready).rejectAllSuggestions();
99
- }
100
- /** Add a comment thread anchored to the current selection (a rich-text body;
101
- * `mentions` are @-tagged users). Resolves to the thread id, or null if
102
- * there's no selection. */
103
- async addComment(e, a) {
104
- return (await this.ready).addComment(e, a);
105
- }
106
- async replyToComment(e, a, t) {
107
- (await this.ready).replyToComment(e, a, t);
108
- }
109
- async resolveThread(e, a = !0) {
110
- (await this.ready).resolveThread(e, a);
111
- }
112
- getDocId() {
113
- return this.handle?.getDocId() ?? null;
114
- }
115
- getShareLink() {
116
- return this.handle?.getShareLink() ?? null;
117
- }
118
- destroy() {
119
- this.handle?.destroy(), this.handle = null, this.handlers.clear();
120
- }
121
- }
122
- export {
123
- o as W,
124
- r as f
125
- };