@forevka/wordcanvas 0.7.1 → 0.7.2
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-4HYrkNrG.js} +10873 -10730
- package/dist-lib/assets/worker-CJpwUzKh.js +2403 -0
- package/dist-lib/blockFactory-B_CLnkUh.js +106 -0
- package/dist-lib/browser-p_rkUcqE.js +1339 -0
- package/dist-lib/builder.js +14 -13
- package/dist-lib/editorApp-mTD0YNv-.js +9863 -0
- package/dist-lib/export.js +4507 -4456
- package/dist-lib/generate-toc.js +5 -5
- package/dist-lib/import.js +2 -2
- package/dist-lib/measure.js +2 -2
- package/dist-lib/{measureHost-CMiJKdlk.js → measureHost-B2aKX7lF.js} +1 -1
- package/dist-lib/metrics-BUMIC9Mv.js +164 -0
- package/dist-lib/pipeline-DD0nxAYM.js +1850 -0
- package/dist-lib/recalc-docx.js +2 -2
- package/dist-lib/recalcToc-CFCGCgij.js +3985 -0
- package/dist-lib/styleProps-DhqDEfvc.js +149 -0
- package/dist-lib/stylesheet-B6oczA-L.js +141 -0
- package/dist-lib/{toc-B6VpkJge.js → toc-Dj57zdz-.js} +5 -5
- package/dist-lib/{webmcp-6WxRNKCc.js → webmcp-CXghUon_.js} +2 -2
- package/dist-lib/{wordcanvas-CFqpDK0k.js → wordcanvas-D5DI9ZR1.js} +49 -23
- package/dist-lib/wordcanvas.js +1 -1
- package/dist-node/{chunk-22JHAERT.js → chunk-57L5XMCL.js} +235 -39
- package/dist-node/chunk-57L5XMCL.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-6AJJMHKY.js → chunk-KJV7GJ3H.js} +1 -1
- package/dist-node/chunk-KJV7GJ3H.js.map +7 -0
- package/dist-node/{chunk-CDN6WU2P.js → chunk-PIMVQULL.js} +7 -1
- package/dist-node/chunk-PIMVQULL.js.map +7 -0
- package/dist-node/{chunk-BRAPV465.js → chunk-SA26UVIJ.js} +2 -2
- package/dist-node/{chunk-RNB336F3.js → chunk-T3253N22.js} +92 -14
- package/dist-node/{chunk-RNB336F3.js.map → chunk-T3253N22.js.map} +2 -2
- package/dist-node/{chunk-4ICCHZX4.js → chunk-U27EBKBG.js} +37 -1
- package/dist-node/chunk-U27EBKBG.js.map +7 -0
- package/dist-node/{engine-5FGDJD2H.js → engine-5F7DUU4W.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 +212 -157
- 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/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-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-SA26UVIJ.js.map} +0 -0
- /package/dist-node/{engine-5FGDJD2H.js.map → engine-5F7DUU4W.js.map} +0 -0
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
formatListNumber,
|
|
10
10
|
isHiddenParagraph,
|
|
11
11
|
markerText
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-PIMVQULL.js";
|
|
13
13
|
import {
|
|
14
14
|
charStyleToFont,
|
|
15
15
|
fontMetrics,
|
|
16
16
|
measureTextWidth
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-U27EBKBG.js";
|
|
18
18
|
|
|
19
19
|
// ../node_modules/@chenglou/pretext/dist/generated/bidi-data.js
|
|
20
20
|
var latin1BidiTypes = [
|
|
@@ -4068,6 +4068,7 @@ function layoutTabbedSegment(p, segRuns, segStart, contentWidth, firstIndent) {
|
|
|
4068
4068
|
const out = [];
|
|
4069
4069
|
let curFrags = [];
|
|
4070
4070
|
let curLeaders = [];
|
|
4071
|
+
let curArrows = [];
|
|
4071
4072
|
let curX = firstIndent;
|
|
4072
4073
|
let maxH = 0;
|
|
4073
4074
|
let maxA = 0;
|
|
@@ -4089,10 +4090,12 @@ function layoutTabbedSegment(p, segRuns, segStart, contentWidth, firstIndent) {
|
|
|
4089
4090
|
// A tab-positioned line stays ragged (its manual x must not be re-justified);
|
|
4090
4091
|
// pure wrapped continuation lines justify normally when the paragraph does.
|
|
4091
4092
|
lastOfSegment: isLast || hasTab,
|
|
4092
|
-
...curLeaders.length > 0 ? { leaders: curLeaders } : {}
|
|
4093
|
+
...curLeaders.length > 0 ? { leaders: curLeaders } : {},
|
|
4094
|
+
...curArrows.length > 0 ? { tabArrows: curArrows } : {}
|
|
4093
4095
|
});
|
|
4094
4096
|
curFrags = [];
|
|
4095
4097
|
curLeaders = [];
|
|
4098
|
+
curArrows = [];
|
|
4096
4099
|
curX = 0;
|
|
4097
4100
|
maxH = 0;
|
|
4098
4101
|
maxA = 0;
|
|
@@ -4112,6 +4115,7 @@ function layoutTabbedSegment(p, segRuns, segStart, contentWidth, firstIndent) {
|
|
|
4112
4115
|
if ((stop.leader ?? "none") !== "none" && targetX > curX + 1 && baseStyle) {
|
|
4113
4116
|
curLeaders.push({ x1: curX, x2: targetX, kind: stop.leader ?? "none", color: baseStyle.color, fontSizePx: baseStyle.fontSizePx });
|
|
4114
4117
|
}
|
|
4118
|
+
curArrows.push({ x1: curX, x2: Math.max(targetX, curX) });
|
|
4115
4119
|
curX = targetX;
|
|
4116
4120
|
hasTab = true;
|
|
4117
4121
|
}
|
|
@@ -4164,10 +4168,13 @@ function paragraphLines(p, contentWidth, cache) {
|
|
|
4164
4168
|
const lines = [];
|
|
4165
4169
|
const raw = [];
|
|
4166
4170
|
let first = true;
|
|
4167
|
-
|
|
4171
|
+
const segLastLine = [];
|
|
4172
|
+
for (let si = 0; si < segments.length; si++) {
|
|
4173
|
+
const seg = segments[si];
|
|
4168
4174
|
if (seg.runs.some((r) => r.text.includes(" "))) {
|
|
4169
4175
|
raw.push(...layoutTabbedSegment(p, seg.runs, seg.startOffset, contentWidth, first ? p.style.indentFirstLinePx : 0));
|
|
4170
4176
|
first = false;
|
|
4177
|
+
segLastLine[si] = raw.length - 1;
|
|
4171
4178
|
continue;
|
|
4172
4179
|
}
|
|
4173
4180
|
const runStarts = segRunOffsets(seg.runs, seg.startOffset);
|
|
@@ -4208,6 +4215,13 @@ function paragraphLines(p, contentWidth, cache) {
|
|
|
4208
4215
|
} else {
|
|
4209
4216
|
raw[raw.length - 1].lastOfSegment = true;
|
|
4210
4217
|
}
|
|
4218
|
+
segLastLine[si] = raw.length - 1;
|
|
4219
|
+
}
|
|
4220
|
+
for (let si = 0; si < segLastLine.length; si++) {
|
|
4221
|
+
const idx = segLastLine[si];
|
|
4222
|
+
if (idx === void 0) continue;
|
|
4223
|
+
if (si === segments.length - 1) raw[idx].paragraphEnd = true;
|
|
4224
|
+
else raw[idx].lineBreak = true;
|
|
4211
4225
|
}
|
|
4212
4226
|
let y = 0;
|
|
4213
4227
|
for (const rl of raw) {
|
|
@@ -4222,6 +4236,11 @@ function paragraphLines(p, contentWidth, cache) {
|
|
|
4222
4236
|
if (rl.leaders && rl.leaders.length > 0) {
|
|
4223
4237
|
box.leaders = rl.leaders.map((l) => ({ ...l, x1: l.x1 + startX, x2: l.x2 + startX }));
|
|
4224
4238
|
}
|
|
4239
|
+
if (rl.tabArrows && rl.tabArrows.length > 0) {
|
|
4240
|
+
box.tabArrows = rl.tabArrows.map((a) => ({ x1: a.x1 + startX, x2: a.x2 + startX }));
|
|
4241
|
+
}
|
|
4242
|
+
if (rl.paragraphEnd) box.paragraphEnd = true;
|
|
4243
|
+
if (rl.lineBreak) box.lineBreak = true;
|
|
4225
4244
|
lines.push(box);
|
|
4226
4245
|
y += rl.height;
|
|
4227
4246
|
}
|
|
@@ -4244,6 +4263,10 @@ function effectiveSection(base, patch) {
|
|
|
4244
4263
|
if (headerDist !== void 0) out.headerDistancePx = headerDist;
|
|
4245
4264
|
const footerDist = patch.footerDistancePx ?? base.footerDistancePx;
|
|
4246
4265
|
if (footerDist !== void 0) out.footerDistancePx = footerDist;
|
|
4266
|
+
const pageColorHex = patch.pageColorHex ?? base.pageColorHex;
|
|
4267
|
+
if (pageColorHex !== void 0) out.pageColorHex = pageColorHex;
|
|
4268
|
+
const pageBorders = patch.pageBorders ?? base.pageBorders;
|
|
4269
|
+
if (pageBorders !== void 0) out.pageBorders = pageBorders;
|
|
4247
4270
|
for (const key of BAND_KEYS) {
|
|
4248
4271
|
const blocks = patch[key] ?? base[key];
|
|
4249
4272
|
if (blocks) out[key] = blocks;
|
|
@@ -4321,8 +4344,9 @@ function layoutDocument(doc, getLines, getPrepared, rawBand) {
|
|
|
4321
4344
|
let contentBottom = 0;
|
|
4322
4345
|
let contentWidth = 0;
|
|
4323
4346
|
let colCount = 1;
|
|
4324
|
-
let colGap = 0;
|
|
4325
4347
|
let colWidth = 0;
|
|
4348
|
+
let colBoxes = [];
|
|
4349
|
+
let colSeparatorsX = [];
|
|
4326
4350
|
const applySection = (props) => {
|
|
4327
4351
|
sec = props;
|
|
4328
4352
|
const box = contentBoxOf(sec);
|
|
@@ -4331,8 +4355,27 @@ function layoutDocument(doc, getLines, getPrepared, rawBand) {
|
|
|
4331
4355
|
contentBottom = box.bottom;
|
|
4332
4356
|
contentWidth = sec.pageWidthPx - sec.marginPx.left - sec.marginPx.right;
|
|
4333
4357
|
colCount = Math.max(1, sec.columns?.count ?? 1);
|
|
4334
|
-
|
|
4335
|
-
|
|
4358
|
+
const gap = sec.columns?.gapPx ?? 24;
|
|
4359
|
+
const cols = sec.columns?.cols;
|
|
4360
|
+
if (colCount > 1 && cols && cols.length === colCount) {
|
|
4361
|
+
let x = contentX;
|
|
4362
|
+
colBoxes = cols.map((c, i) => {
|
|
4363
|
+
const b = { x, width: c.widthPx };
|
|
4364
|
+
x += c.widthPx + (i < colCount - 1 ? c.spaceAfterPx : 0);
|
|
4365
|
+
return b;
|
|
4366
|
+
});
|
|
4367
|
+
colWidth = Math.min(...cols.map((c) => c.widthPx));
|
|
4368
|
+
} else if (colCount > 1) {
|
|
4369
|
+
colWidth = (contentWidth - (colCount - 1) * gap) / colCount;
|
|
4370
|
+
colBoxes = Array.from({ length: colCount }, (_, i) => ({
|
|
4371
|
+
x: contentX + i * (colWidth + gap),
|
|
4372
|
+
width: colWidth
|
|
4373
|
+
}));
|
|
4374
|
+
} else {
|
|
4375
|
+
colWidth = contentWidth;
|
|
4376
|
+
colBoxes = [{ x: contentX, width: contentWidth }];
|
|
4377
|
+
}
|
|
4378
|
+
colSeparatorsX = sec.columns?.sep ? colBoxes.slice(0, -1).map((b, i) => (b.x + b.width + colBoxes[i + 1].x) / 2) : [];
|
|
4336
4379
|
};
|
|
4337
4380
|
applySection(sec);
|
|
4338
4381
|
const lists = doc.lists ?? {};
|
|
@@ -4400,7 +4443,7 @@ function layoutDocument(doc, getLines, getPrepared, rawBand) {
|
|
|
4400
4443
|
const pageSections = [];
|
|
4401
4444
|
const mkPage = () => {
|
|
4402
4445
|
pageSections.push(sec);
|
|
4403
|
-
|
|
4446
|
+
const p = {
|
|
4404
4447
|
index: pageSections.length - 1,
|
|
4405
4448
|
number: pageSections.length,
|
|
4406
4449
|
// provisional; the post-pass sets the real value
|
|
@@ -4411,6 +4454,10 @@ function layoutDocument(doc, getLines, getPrepared, rawBand) {
|
|
|
4411
4454
|
contentTopPx: contentTop,
|
|
4412
4455
|
contentBottomPx: contentBottom
|
|
4413
4456
|
};
|
|
4457
|
+
if (sec.pageColorHex !== void 0) p.pageColorHex = sec.pageColorHex;
|
|
4458
|
+
if (sec.pageBorders !== void 0) p.pageBorders = sec.pageBorders;
|
|
4459
|
+
if (colSeparatorsX.length) p.columnSeparatorsX = colSeparatorsX.slice();
|
|
4460
|
+
return p;
|
|
4414
4461
|
};
|
|
4415
4462
|
const pages = [mkPage()];
|
|
4416
4463
|
let page = pages[0];
|
|
@@ -4450,7 +4497,7 @@ function layoutDocument(doc, getLines, getPrepared, rawBand) {
|
|
|
4450
4497
|
};
|
|
4451
4498
|
let colIdx = 0;
|
|
4452
4499
|
let colStartCount = 0;
|
|
4453
|
-
const colX = () =>
|
|
4500
|
+
const colX = () => colBoxes[colIdx]?.x ?? contentX;
|
|
4454
4501
|
const colHasContent = () => page.blocks.length > colStartCount;
|
|
4455
4502
|
const hardPage = () => {
|
|
4456
4503
|
colIdx = 0;
|
|
@@ -4480,6 +4527,12 @@ function layoutDocument(doc, getLines, getPrepared, rawBand) {
|
|
|
4480
4527
|
page.marginPx = sec.marginPx;
|
|
4481
4528
|
page.contentTopPx = contentTop;
|
|
4482
4529
|
page.contentBottomPx = contentBottom;
|
|
4530
|
+
if (sec.pageColorHex !== void 0) page.pageColorHex = sec.pageColorHex;
|
|
4531
|
+
else delete page.pageColorHex;
|
|
4532
|
+
if (sec.pageBorders !== void 0) page.pageBorders = sec.pageBorders;
|
|
4533
|
+
else delete page.pageBorders;
|
|
4534
|
+
if (colSeparatorsX.length) page.columnSeparatorsX = colSeparatorsX.slice();
|
|
4535
|
+
else delete page.columnSeparatorsX;
|
|
4483
4536
|
pageSections[page.index] = sec;
|
|
4484
4537
|
colIdx = 0;
|
|
4485
4538
|
colStartCount = 0;
|
|
@@ -4929,10 +4982,13 @@ function layoutDocument(doc, getLines, getPrepared, rawBand) {
|
|
|
4929
4982
|
}
|
|
4930
4983
|
}
|
|
4931
4984
|
}
|
|
4932
|
-
|
|
4933
|
-
|
|
4985
|
+
const reorderAnchoredLayers = (blocks) => {
|
|
4986
|
+
for (const b of blocks) {
|
|
4987
|
+
if (b.table) for (const row of b.table.rows) for (const cell of row.cells) cell.blocks = reorderAnchoredLayers(cell.blocks);
|
|
4988
|
+
}
|
|
4989
|
+
if (!blocks.some((b) => b.image?.behind || b.image?.front)) return blocks;
|
|
4934
4990
|
const layer = (b) => b.image?.behind ? 0 : b.image?.front ? 2 : 1;
|
|
4935
|
-
|
|
4991
|
+
return blocks.map((b, i) => ({ b, i })).sort((p, q) => {
|
|
4936
4992
|
const dl = layer(p.b) - layer(q.b);
|
|
4937
4993
|
if (dl !== 0) return dl;
|
|
4938
4994
|
if (layer(p.b) !== 1) {
|
|
@@ -4941,7 +4997,8 @@ function layoutDocument(doc, getLines, getPrepared, rawBand) {
|
|
|
4941
4997
|
}
|
|
4942
4998
|
return p.i - q.i;
|
|
4943
4999
|
}).map((x) => x.b);
|
|
4944
|
-
}
|
|
5000
|
+
};
|
|
5001
|
+
for (const pg of pages) pg.blocks = reorderAnchoredLayers(pg.blocks);
|
|
4945
5002
|
const pageNumbers = [];
|
|
4946
5003
|
{
|
|
4947
5004
|
let n = 0;
|
|
@@ -5173,6 +5230,7 @@ function measureTable(t, contentWidth, getLines, listCtx) {
|
|
|
5173
5230
|
return { kind: "para", block: b, lines };
|
|
5174
5231
|
}
|
|
5175
5232
|
if (b.kind === "image") {
|
|
5233
|
+
if (b.anchor) return { kind: "image", block: b, width: b.widthPx, height: b.heightPx };
|
|
5176
5234
|
const scale = Math.min(1, innerWidth / Math.max(1, b.widthPx));
|
|
5177
5235
|
const w = b.widthPx * scale;
|
|
5178
5236
|
const ih = b.heightPx * scale;
|
|
@@ -5243,6 +5301,26 @@ function placeTable(t, rows, colWidths, x, y, width, firstRowIndex, listCtx) {
|
|
|
5243
5301
|
blocks.push(placedPara);
|
|
5244
5302
|
py += totalLinesHeight(it.lines) + it.block.style.spaceAfterPx;
|
|
5245
5303
|
} else if (it.kind === "image") {
|
|
5304
|
+
const anchor = it.block.anchor;
|
|
5305
|
+
if (anchor) {
|
|
5306
|
+
const placedImage = {
|
|
5307
|
+
src: it.block.src,
|
|
5308
|
+
width: it.block.widthPx,
|
|
5309
|
+
height: it.block.heightPx,
|
|
5310
|
+
z: anchor.z ?? 0
|
|
5311
|
+
};
|
|
5312
|
+
if (anchor.behind) placedImage.behind = true;
|
|
5313
|
+
else placedImage.front = true;
|
|
5314
|
+
blocks.push({
|
|
5315
|
+
blockId: it.block.id,
|
|
5316
|
+
x: cx + mgn.left + anchor.offsetXPx,
|
|
5317
|
+
y: ry + mgn.top + anchor.offsetYPx,
|
|
5318
|
+
firstLineIndex: 0,
|
|
5319
|
+
lines: [],
|
|
5320
|
+
image: placedImage
|
|
5321
|
+
});
|
|
5322
|
+
continue;
|
|
5323
|
+
}
|
|
5246
5324
|
const innerH = cellHeight - mgn.top - mgn.bottom;
|
|
5247
5325
|
if (mc.items.length === 1 && innerH > it.height + 8) {
|
|
5248
5326
|
const scale = Math.max(innerWidth / it.block.widthPx, innerH / it.block.heightPx);
|
|
@@ -5311,4 +5389,4 @@ export {
|
|
|
5311
5389
|
effectiveSection,
|
|
5312
5390
|
resolveSections
|
|
5313
5391
|
};
|
|
5314
|
-
//# sourceMappingURL=chunk-
|
|
5392
|
+
//# sourceMappingURL=chunk-T3253N22.js.map
|