@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.
- package/dist-lib/assets/{worker-D8rUOKfg.js → worker-CqU4Popa.js} +10903 -10736
- package/dist-lib/assets/worker-Cw5cYW5z.js +2418 -0
- package/dist-lib/blockFactory-DDCRWDnA.js +91 -0
- package/dist-lib/browser-BUrsjziD.js +612 -0
- package/dist-lib/builder.js +13 -13
- package/dist-lib/editorApp-CB_ZArIF.js +9566 -0
- package/dist-lib/export.js +4507 -4456
- package/dist-lib/generate-toc.js +7 -7
- package/dist-lib/import.js +2 -2
- package/dist-lib/lists-DpmgbDyt.js +110 -0
- package/dist-lib/measure.js +2 -2
- package/dist-lib/{measureHost-CMiJKdlk.js → measureHost-BlukHGwx.js} +1 -1
- package/dist-lib/metrics-bvGO8KDK.js +96 -0
- package/dist-lib/paintStyle-vT6jtWbH.js +74 -0
- package/dist-lib/pipeline-UryP-u7Z.js +1850 -0
- package/dist-lib/recalc-docx.js +2 -2
- package/dist-lib/recalcToc-BfXlXZik.js +3985 -0
- package/dist-lib/styleProps-DhqDEfvc.js +149 -0
- package/dist-lib/stylesheet-LTBEGkvG.js +146 -0
- package/dist-lib/toc-D09f4PrI.js +939 -0
- package/dist-lib/{webmcp-6WxRNKCc.js → webmcp-K6UZgQJ0.js} +60 -68
- package/dist-lib/wordcanvas-DBx2ana_.js +734 -0
- package/dist-lib/wordcanvas.js +4 -2
- package/dist-node/{chunk-CDN6WU2P.js → chunk-373K2XRY.js} +40 -22
- package/dist-node/chunk-373K2XRY.js.map +7 -0
- package/dist-node/{chunk-22JHAERT.js → chunk-3PUV3BG6.js} +235 -39
- package/dist-node/chunk-3PUV3BG6.js.map +7 -0
- package/dist-node/{chunk-4ICCHZX4.js → chunk-5RX3IHWE.js} +39 -3
- package/dist-node/chunk-5RX3IHWE.js.map +7 -0
- package/dist-node/{chunk-4PDVRJF6.js → chunk-EMY2P524.js} +32 -2
- package/dist-node/chunk-EMY2P524.js.map +7 -0
- package/dist-node/{chunk-BRAPV465.js → chunk-HWQKGDS2.js} +2 -2
- package/dist-node/{chunk-6AJJMHKY.js → chunk-KJV7GJ3H.js} +1 -1
- package/dist-node/chunk-KJV7GJ3H.js.map +7 -0
- package/dist-node/{chunk-RNB336F3.js → chunk-ZLLSXOO2.js} +92 -14
- package/dist-node/{chunk-RNB336F3.js.map → chunk-ZLLSXOO2.js.map} +2 -2
- package/dist-node/{engine-5FGDJD2H.js → engine-LLA6PCS5.js} +4 -4
- package/dist-node/export.js +89 -24
- package/dist-node/export.js.map +2 -2
- package/dist-node/generate-toc.js +6 -6
- package/dist-node/import.js +3 -3
- package/dist-node/measure.js +2 -2
- package/dist-node/recalc-docx.js +4 -4
- package/package.json +1 -1
- package/types/model.d.ts +46 -0
- package/types/wordcanvas.d.ts +493 -1
- package/dist-lib/assets/worker-wXuuyshQ.js +0 -2258
- package/dist-lib/blockFactory-CUI4Rqiq.js +0 -186
- package/dist-lib/browser-DkKxreJM.js +0 -1305
- package/dist-lib/editorApp-DLXMmtu5.js +0 -8023
- package/dist-lib/lists-Sc5I40JO.js +0 -110
- package/dist-lib/metrics-CkAo4zh8.js +0 -143
- package/dist-lib/pipeline-CbxmCE84.js +0 -1705
- package/dist-lib/recalcToc-g1hFKSNs.js +0 -3935
- package/dist-lib/styleProps-Db5pEkG8.js +0 -127
- package/dist-lib/toc-B6VpkJge.js +0 -213
- package/dist-lib/wordcanvas-CFqpDK0k.js +0 -125
- package/dist-node/chunk-22JHAERT.js.map +0 -7
- package/dist-node/chunk-4ICCHZX4.js.map +0 -7
- package/dist-node/chunk-4PDVRJF6.js.map +0 -7
- package/dist-node/chunk-6AJJMHKY.js.map +0 -7
- package/dist-node/chunk-CDN6WU2P.js.map +0 -7
- /package/dist-node/{chunk-BRAPV465.js.map → chunk-HWQKGDS2.js.map} +0 -0
- /package/dist-node/{engine-5FGDJD2H.js.map → engine-LLA6PCS5.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as j, j as _, z as F, t as k, J as L } from "./toc-D09f4PrI.js";
|
|
2
2
|
const s = (e) => Math.round(e * 100) / 100;
|
|
3
|
-
function
|
|
3
|
+
function A(e) {
|
|
4
4
|
const o = { font: e.fontFamily, sizePx: e.fontSizePx };
|
|
5
5
|
return e.bold && (o.bold = !0), e.italic && (o.italic = !0), e.underline && (o.underline = !0), e.strikethrough && (o.strike = !0), e.color && e.color !== "#000000" && (o.color = e.color), e.verticalAlign && (o.verticalAlign = e.verticalAlign), e.highlightColor && (o.highlight = e.highlightColor), e.link && (o.link = e.link), e.hidden && (o.hidden = !0), o;
|
|
6
6
|
}
|
|
@@ -10,30 +10,30 @@ function B(e, o) {
|
|
|
10
10
|
width: s(e.width),
|
|
11
11
|
startOffset: e.startOffset,
|
|
12
12
|
endOffset: e.endOffset,
|
|
13
|
-
style:
|
|
13
|
+
style: A(e.style)
|
|
14
14
|
};
|
|
15
15
|
return o && (r.text = e.text), e.wordSpacingPx !== void 0 && (r.wordSpacingPx = s(e.wordSpacingPx)), e.offsetMap && (r.whitespaceCollapsed = !0), r;
|
|
16
16
|
}
|
|
17
17
|
function W(e, o, r) {
|
|
18
|
-
const
|
|
18
|
+
const l = e.fragments.slice(0, r).map((p) => B(p, o)), c = {
|
|
19
19
|
y: s(e.y),
|
|
20
20
|
height: s(e.height),
|
|
21
21
|
ascent: s(e.ascent),
|
|
22
|
-
fragments:
|
|
22
|
+
fragments: l
|
|
23
23
|
};
|
|
24
24
|
return e.fragments.length > r && (c.fragmentsTruncated = e.fragments.length - r), e.emptyOffset !== void 0 && (c.emptyOffset = e.emptyOffset), e.leaders && e.leaders.length > 0 && (c.leaderCount = e.leaders.length), c;
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function M(e, o, r) {
|
|
27
27
|
return {
|
|
28
28
|
x: s(e.x),
|
|
29
29
|
y: s(e.y),
|
|
30
30
|
width: s(e.width),
|
|
31
31
|
height: s(e.height),
|
|
32
32
|
colWidths: e.colWidths.map(s),
|
|
33
|
-
rows: e.rows.map((
|
|
34
|
-
y: s(
|
|
35
|
-
height: s(
|
|
36
|
-
cells:
|
|
33
|
+
rows: e.rows.map((l) => ({
|
|
34
|
+
y: s(l.y),
|
|
35
|
+
height: s(l.height),
|
|
36
|
+
cells: l.cells.map((c) => ({
|
|
37
37
|
x: s(c.x),
|
|
38
38
|
y: s(c.y),
|
|
39
39
|
width: s(c.width),
|
|
@@ -45,9 +45,9 @@ function A(e, o, r) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
function q(e, o, r) {
|
|
48
|
-
const
|
|
48
|
+
const l = e.image ? "image" : e.table ? "table" : "paragraph", c = {
|
|
49
49
|
blockId: e.blockId,
|
|
50
|
-
kind:
|
|
50
|
+
kind: l,
|
|
51
51
|
x: s(e.x),
|
|
52
52
|
y: s(e.y),
|
|
53
53
|
firstLineIndex: e.firstLineIndex
|
|
@@ -59,19 +59,19 @@ function q(e, o, r) {
|
|
|
59
59
|
srcKind: e.image.src.slice(0, e.image.src.indexOf(":") + 1) || "unknown",
|
|
60
60
|
srcLength: e.image.src.length,
|
|
61
61
|
...e.image.clip ? { clipped: !0 } : {}
|
|
62
|
-
} : e.table ? c.table =
|
|
62
|
+
} : e.table ? c.table = M(e.table, o, r) : c.lines = e.lines.map((p) => W(p, o, r)), c;
|
|
63
63
|
}
|
|
64
64
|
function R(e, o) {
|
|
65
65
|
if (e.blockId === o) return !0;
|
|
66
66
|
if (e.table) {
|
|
67
67
|
for (const r of e.table.rows)
|
|
68
|
-
for (const
|
|
68
|
+
for (const l of r.cells) for (const c of l.blocks) if (R(c, o)) return !0;
|
|
69
69
|
}
|
|
70
70
|
return !1;
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function $(e, o) {
|
|
73
73
|
let r = e.blocks;
|
|
74
|
-
return o.blockId && (r = r.filter((
|
|
74
|
+
return o.blockId && (r = r.filter((l) => R(l, o.blockId))), {
|
|
75
75
|
index: e.index,
|
|
76
76
|
number: e.number,
|
|
77
77
|
widthPx: s(e.widthPx),
|
|
@@ -88,50 +88,42 @@ function M(e, o) {
|
|
|
88
88
|
blockCount: e.blocks.length,
|
|
89
89
|
headerBlocks: e.header?.length ?? 0,
|
|
90
90
|
footerBlocks: e.footer?.length ?? 0,
|
|
91
|
-
blocks: r.map((
|
|
91
|
+
blocks: r.map((l) => q(l, o.includeText, o.maxFragmentsPerLine))
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
function
|
|
95
|
-
const r = o.includeText ?? !0,
|
|
94
|
+
function D(e, o = {}) {
|
|
95
|
+
const r = o.includeText ?? !0, l = o.maxFragmentsPerLine ?? 200;
|
|
96
96
|
let c = e.pages;
|
|
97
97
|
o.page !== void 0 && (c = c.filter((h) => h.index === o.page));
|
|
98
98
|
const p = {
|
|
99
99
|
includeText: r,
|
|
100
|
-
maxFragmentsPerLine:
|
|
100
|
+
maxFragmentsPerLine: l,
|
|
101
101
|
...o.blockId !== void 0 ? { blockId: o.blockId } : {}
|
|
102
102
|
};
|
|
103
103
|
return {
|
|
104
104
|
pageCount: e.pages.length,
|
|
105
105
|
defaultPageWidthPx: s(e.pageWidthPx),
|
|
106
106
|
defaultPageHeightPx: s(e.pageHeightPx),
|
|
107
|
-
pages: c.map((h) =>
|
|
107
|
+
pages: c.map((h) => $(h, p))
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
|
-
const
|
|
111
|
-
fontFamily: "Georgia, serif",
|
|
112
|
-
fontSizePx: 16,
|
|
113
|
-
bold: !1,
|
|
114
|
-
italic: !1,
|
|
115
|
-
underline: !1,
|
|
116
|
-
strikethrough: !1,
|
|
117
|
-
color: "#202124"
|
|
118
|
-
}, g = (e) => ({ content: [{ type: "text", text: e }] }), x = (e) => g(JSON.stringify(e, null, 2)), f = (e) => ({ content: [{ type: "text", text: e }], isError: !0 }), u = (e) => typeof e == "string" ? e : void 0, y = (e) => typeof e == "boolean" ? e : void 0, v = (e) => typeof e == "number" && Number.isFinite(e) ? e : void 0;
|
|
119
|
-
function O(e) {
|
|
120
|
-
return [{ text: e, style: D }];
|
|
121
|
-
}
|
|
110
|
+
const E = L, g = (e) => ({ content: [{ type: "text", text: e }] }), x = (e) => g(JSON.stringify(e, null, 2)), f = (e) => ({ content: [{ type: "text", text: e }], isError: !0 }), u = (e) => typeof e == "string" ? e : void 0, y = (e) => typeof e == "boolean" ? e : void 0, v = (e) => typeof e == "number" && Number.isFinite(e) ? e : void 0;
|
|
122
111
|
function T(e) {
|
|
112
|
+
return [{ text: e, style: E }];
|
|
113
|
+
}
|
|
114
|
+
function O(e) {
|
|
123
115
|
const o = {}, r = y(e.matchCase);
|
|
124
116
|
r !== void 0 && (o.matchCase = r);
|
|
125
|
-
const
|
|
126
|
-
return
|
|
117
|
+
const l = y(e.wholeWord);
|
|
118
|
+
return l !== void 0 && (o.wholeWord = l), o;
|
|
127
119
|
}
|
|
128
120
|
function z(e) {
|
|
129
121
|
return j(e).map((o) => k(o.runs)).join(`
|
|
130
122
|
`);
|
|
131
123
|
}
|
|
132
|
-
function
|
|
133
|
-
const r = j(e),
|
|
134
|
-
let c = o.anchor, p = o.focus, h =
|
|
124
|
+
function J(e, o) {
|
|
125
|
+
const r = j(e), l = (t) => r.findIndex((i) => i.id === t);
|
|
126
|
+
let c = o.anchor, p = o.focus, h = l(c.blockId), a = l(p.blockId);
|
|
135
127
|
if ((h > a || h === a && c.offset > p.offset) && ([c, p] = [p, c], [h, a] = [a, h]), h < 0 || a < 0) {
|
|
136
128
|
if (o.anchor.blockId === o.focus.blockId) {
|
|
137
129
|
const t = r.find((i) => i.id === o.anchor.blockId);
|
|
@@ -150,9 +142,9 @@ function N() {
|
|
|
150
142
|
const e = globalThis;
|
|
151
143
|
return e.document?.modelContext ?? e.navigator?.modelContext ?? null;
|
|
152
144
|
}
|
|
153
|
-
function
|
|
154
|
-
const
|
|
155
|
-
if (!
|
|
145
|
+
function H(e, o = {}, r = {}) {
|
|
146
|
+
const l = r.modelContext ?? N();
|
|
147
|
+
if (!l)
|
|
156
148
|
return console.warn("[wordcanvas] agentTools enabled but no navigator.modelContext is available; tools not registered."), () => {
|
|
157
149
|
};
|
|
158
150
|
const c = new Set(r.capabilities ?? ["read", "suggest", "edit"]), p = r.name ? `${r.name}_` : "", h = new AbortController(), a = (n) => {
|
|
@@ -162,12 +154,12 @@ function Y(e, o = {}, r = {}) {
|
|
|
162
154
|
execute: async (i) => {
|
|
163
155
|
try {
|
|
164
156
|
return await n.execute(i ?? {});
|
|
165
|
-
} catch (
|
|
166
|
-
return f(`${n.name} failed: ${
|
|
157
|
+
} catch (d) {
|
|
158
|
+
return f(`${n.name} failed: ${d instanceof Error ? d.message : String(d)}`);
|
|
167
159
|
}
|
|
168
160
|
}
|
|
169
161
|
};
|
|
170
|
-
|
|
162
|
+
l.registerTool(t, { signal: h.signal });
|
|
171
163
|
};
|
|
172
164
|
return a({
|
|
173
165
|
name: "get_document",
|
|
@@ -183,7 +175,7 @@ function Y(e, o = {}, r = {}) {
|
|
|
183
175
|
inputSchema: { type: "object", properties: {} },
|
|
184
176
|
execute: () => {
|
|
185
177
|
const n = e.getSelection();
|
|
186
|
-
return x(n ? { selection: n, text:
|
|
178
|
+
return x(n ? { selection: n, text: J(e.getDocument(), n) } : { selection: null });
|
|
187
179
|
}
|
|
188
180
|
}), a({
|
|
189
181
|
name: "search_document",
|
|
@@ -200,7 +192,7 @@ function Y(e, o = {}, r = {}) {
|
|
|
200
192
|
execute: (n) => {
|
|
201
193
|
const t = u(n.query);
|
|
202
194
|
if (!t) return f("query is required");
|
|
203
|
-
const i = e.search(t,
|
|
195
|
+
const i = e.search(t, O(n));
|
|
204
196
|
return x({ total: i.total, current: i.index });
|
|
205
197
|
}
|
|
206
198
|
}), a({
|
|
@@ -218,12 +210,12 @@ function Y(e, o = {}, r = {}) {
|
|
|
218
210
|
execute: (n) => {
|
|
219
211
|
const t = {}, i = v(n.page);
|
|
220
212
|
i !== void 0 && (t.page = i);
|
|
221
|
-
const
|
|
222
|
-
|
|
213
|
+
const d = u(n.blockId);
|
|
214
|
+
d && (t.blockId = d);
|
|
223
215
|
const m = y(n.includeText);
|
|
224
216
|
m !== void 0 && (t.includeText = m);
|
|
225
217
|
const b = v(n.maxFragmentsPerLine);
|
|
226
|
-
return b !== void 0 && (t.maxFragmentsPerLine = b), x(
|
|
218
|
+
return b !== void 0 && (t.maxFragmentsPerLine = b), x(D(e.getLayoutTree(), t));
|
|
227
219
|
}
|
|
228
220
|
}), a({
|
|
229
221
|
name: "get_document_stats",
|
|
@@ -271,8 +263,8 @@ function Y(e, o = {}, r = {}) {
|
|
|
271
263
|
if (i && e.search(i).total === 0)
|
|
272
264
|
return f(`text not found: ${i}`);
|
|
273
265
|
if (!e.getSelection()) return f("no selection to anchor the comment (pass 'find' or select first)");
|
|
274
|
-
const
|
|
275
|
-
return i && e.searchClear(),
|
|
266
|
+
const d = e.addComment(T(t));
|
|
267
|
+
return i && e.searchClear(), d ? x({ threadId: d }) : f("could not add comment (view mode or empty selection)");
|
|
276
268
|
}
|
|
277
269
|
}), a({
|
|
278
270
|
name: "reply_to_comment",
|
|
@@ -280,7 +272,7 @@ function Y(e, o = {}, r = {}) {
|
|
|
280
272
|
inputSchema: { type: "object", properties: { threadId: { type: "string" }, body: { type: "string" } }, required: ["threadId", "body"] },
|
|
281
273
|
execute: (n) => {
|
|
282
274
|
const t = u(n.threadId), i = u(n.body);
|
|
283
|
-
return !t || !i ? f("threadId and body are required") : (e.replyToComment(t,
|
|
275
|
+
return !t || !i ? f("threadId and body are required") : (e.replyToComment(t, T(i)), g("replied"));
|
|
284
276
|
}
|
|
285
277
|
}), a({
|
|
286
278
|
name: "resolve_thread",
|
|
@@ -323,7 +315,7 @@ function Y(e, o = {}, r = {}) {
|
|
|
323
315
|
execute: (n) => {
|
|
324
316
|
const t = u(n.find), i = u(n.replaceWith);
|
|
325
317
|
if (t === void 0 || i === void 0) return f("find and replaceWith are required");
|
|
326
|
-
if (e.search(t,
|
|
318
|
+
if (e.search(t, O(n)).total === 0)
|
|
327
319
|
return e.searchClear(), f(`text not found: ${t}`);
|
|
328
320
|
let m;
|
|
329
321
|
return y(n.all) ? m = e.searchReplaceAll(i) : (e.searchReplaceCurrent(i), m = 1), e.searchClear(), x({ replaced: m });
|
|
@@ -339,8 +331,8 @@ function Y(e, o = {}, r = {}) {
|
|
|
339
331
|
if (i && e.search(i).total === 0)
|
|
340
332
|
return e.searchClear(), f(`text not found: ${i}`);
|
|
341
333
|
if (!e.getSelection()) return f("no selection (pass 'find' or select_range first)");
|
|
342
|
-
const { insertText:
|
|
343
|
-
return e.dispatch(
|
|
334
|
+
const { insertText: d } = await import("./editorApp-CB_ZArIF.js").then((m) => m.c);
|
|
335
|
+
return e.dispatch(d(t)), i && e.searchClear(), g("inserted");
|
|
344
336
|
}
|
|
345
337
|
}), a({
|
|
346
338
|
name: "format_text",
|
|
@@ -370,8 +362,8 @@ function Y(e, o = {}, r = {}) {
|
|
|
370
362
|
i = { bold: !1, italic: !1, underline: !1, strikethrough: !1, highlightColor: void 0 };
|
|
371
363
|
else {
|
|
372
364
|
i = {};
|
|
373
|
-
const
|
|
374
|
-
|
|
365
|
+
const d = y(n.bold);
|
|
366
|
+
d !== void 0 && (i.bold = d);
|
|
375
367
|
const m = y(n.italic);
|
|
376
368
|
m !== void 0 && (i.italic = m);
|
|
377
369
|
const b = y(n.underline);
|
|
@@ -382,10 +374,10 @@ function Y(e, o = {}, r = {}) {
|
|
|
382
374
|
w && (i.color = w);
|
|
383
375
|
const I = u(n.fontFamily);
|
|
384
376
|
I && (i.fontFamily = I);
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
|
|
377
|
+
const C = v(n.fontSizePx);
|
|
378
|
+
C !== void 0 && (i.fontSizePx = C);
|
|
379
|
+
const P = u(n.highlightColor);
|
|
380
|
+
P && (i.highlightColor = P);
|
|
389
381
|
}
|
|
390
382
|
return e.setCharStyle(i), t && e.searchClear(), g("formatted");
|
|
391
383
|
}
|
|
@@ -411,13 +403,13 @@ function Y(e, o = {}, r = {}) {
|
|
|
411
403
|
required: ["anchorBlockId", "anchorOffset", "focusBlockId", "focusOffset"]
|
|
412
404
|
},
|
|
413
405
|
execute: (n) => {
|
|
414
|
-
const t = u(n.anchorBlockId), i = v(n.anchorOffset),
|
|
415
|
-
if (t === void 0 || i === void 0 ||
|
|
406
|
+
const t = u(n.anchorBlockId), i = v(n.anchorOffset), d = u(n.focusBlockId), m = v(n.focusOffset);
|
|
407
|
+
if (t === void 0 || i === void 0 || d === void 0 || m === void 0) return f("anchor/focus block id + offset are required");
|
|
416
408
|
const b = e.getDocument();
|
|
417
409
|
if (!_(b, t)) return f(`anchor block '${t}' not found`);
|
|
418
|
-
if (!_(b,
|
|
410
|
+
if (!_(b, d)) return f(`focus block '${d}' not found`);
|
|
419
411
|
const S = (w, I) => Math.max(0, Math.min(w, F(b, I).length));
|
|
420
|
-
return e.setSelection({ anchor: { blockId: t, offset: S(i, t) }, focus: { blockId:
|
|
412
|
+
return e.setSelection({ anchor: { blockId: t, offset: S(i, t) }, focus: { blockId: d, offset: S(m, d) } }), g("selection set");
|
|
421
413
|
}
|
|
422
414
|
}), a({
|
|
423
415
|
name: "undo",
|
|
@@ -439,13 +431,13 @@ function Y(e, o = {}, r = {}) {
|
|
|
439
431
|
let i;
|
|
440
432
|
try {
|
|
441
433
|
i = JSON.parse(t);
|
|
442
|
-
} catch (
|
|
443
|
-
return f(`invalid JSON: ${
|
|
434
|
+
} catch (d) {
|
|
435
|
+
return f(`invalid JSON: ${d instanceof Error ? d.message : String(d)}`);
|
|
444
436
|
}
|
|
445
437
|
return o.setDocument(i), g("document replaced");
|
|
446
438
|
}
|
|
447
439
|
})), () => h.abort();
|
|
448
440
|
}
|
|
449
441
|
export {
|
|
450
|
-
|
|
442
|
+
H as registerAgentTools
|
|
451
443
|
};
|