@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
|
@@ -8,13 +8,13 @@ import {
|
|
|
8
8
|
createLayoutEngine,
|
|
9
9
|
effectiveSection,
|
|
10
10
|
resolveSections
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-ZLLSXOO2.js";
|
|
12
|
+
import "./chunk-373K2XRY.js";
|
|
13
|
+
import "./chunk-5RX3IHWE.js";
|
|
14
14
|
import "./chunk-XSRSBST2.js";
|
|
15
15
|
export {
|
|
16
16
|
createLayoutEngine,
|
|
17
17
|
effectiveSection,
|
|
18
18
|
resolveSections
|
|
19
19
|
};
|
|
20
|
-
//# sourceMappingURL=engine-
|
|
20
|
+
//# sourceMappingURL=engine-LLA6PCS5.js.map
|
package/dist-node/export.js
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
require_unicode_trie,
|
|
17
17
|
resolveFont,
|
|
18
18
|
tslib_es6_exports
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-HWQKGDS2.js";
|
|
20
20
|
import {
|
|
21
21
|
WML_NS,
|
|
22
22
|
XML_DECL,
|
|
@@ -30,8 +30,9 @@ import {
|
|
|
30
30
|
pxToEmu,
|
|
31
31
|
pxToTwips,
|
|
32
32
|
runPropsXml,
|
|
33
|
+
tableStyleXml,
|
|
33
34
|
textEl
|
|
34
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-EMY2P524.js";
|
|
35
36
|
import {
|
|
36
37
|
pageOfBlockMap
|
|
37
38
|
} from "./chunk-EGSAVPCC.js";
|
|
@@ -41,14 +42,16 @@ import {
|
|
|
41
42
|
} from "./chunk-5PUCGN47.js";
|
|
42
43
|
import {
|
|
43
44
|
createLayoutEngine
|
|
44
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-ZLLSXOO2.js";
|
|
45
46
|
import {
|
|
46
47
|
detectTocHeadings,
|
|
47
48
|
inRange,
|
|
48
49
|
parseTocInstruction,
|
|
50
|
+
styleType,
|
|
49
51
|
textOfRuns
|
|
50
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-373K2XRY.js";
|
|
51
53
|
import {
|
|
54
|
+
COLUMN_SEPARATOR_COLOR,
|
|
52
55
|
DEFAULT_GRID_COLOR,
|
|
53
56
|
FOOTNOTE_RULE_COLOR,
|
|
54
57
|
FOOTNOTE_RULE_WIDTH_FRACTION,
|
|
@@ -65,10 +68,11 @@ import {
|
|
|
65
68
|
leaderDash,
|
|
66
69
|
leaderWidth,
|
|
67
70
|
normalizeLinkBlue,
|
|
71
|
+
pageBorderSegments,
|
|
68
72
|
runPaint,
|
|
69
73
|
strikeOffset,
|
|
70
74
|
verticalShift
|
|
71
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-5RX3IHWE.js";
|
|
72
76
|
import {
|
|
73
77
|
__commonJS,
|
|
74
78
|
__require,
|
|
@@ -24545,7 +24549,7 @@ function toBuffer(bytes) {
|
|
|
24545
24549
|
var PT = 72 / 96;
|
|
24546
24550
|
async function renderPdf(doc, opts = {}) {
|
|
24547
24551
|
await installMeasureHost();
|
|
24548
|
-
const { createLayoutEngine: createLayoutEngine2 } = await import("./engine-
|
|
24552
|
+
const { createLayoutEngine: createLayoutEngine2 } = await import("./engine-LLA6PCS5.js");
|
|
24549
24553
|
const tree = createLayoutEngine2().layout(doc);
|
|
24550
24554
|
const warnings = new WarningSink();
|
|
24551
24555
|
const images = opts.images ?? {};
|
|
@@ -24600,8 +24604,23 @@ async function renderPdf(doc, opts = {}) {
|
|
|
24600
24604
|
}
|
|
24601
24605
|
pdf.save();
|
|
24602
24606
|
pdf.scale(PT);
|
|
24603
|
-
pdf.rect(0, 0, page.widthPx, page.heightPx).fill("#ffffff");
|
|
24607
|
+
pdf.rect(0, 0, page.widthPx, page.heightPx).fill(page.pageColorHex ?? "#ffffff");
|
|
24608
|
+
if (page.pageBorders) {
|
|
24609
|
+
for (const s of pageBorderSegments(page.pageBorders, page.widthPx, page.heightPx, page.marginPx)) {
|
|
24610
|
+
pdf.lineWidth(s.widthPx).strokeColor(s.color);
|
|
24611
|
+
if (s.dash.length) pdf.dash(s.dash[0], { space: s.dash[1] ?? s.dash[0] });
|
|
24612
|
+
else pdf.undash();
|
|
24613
|
+
pdf.moveTo(s.x1, s.y1).lineTo(s.x2, s.y2).stroke();
|
|
24614
|
+
}
|
|
24615
|
+
pdf.undash();
|
|
24616
|
+
}
|
|
24604
24617
|
for (const block of page.blocks) paintBlock(ctx, block);
|
|
24618
|
+
if (page.columnSeparatorsX) {
|
|
24619
|
+
pdf.undash().lineWidth(1).strokeColor(COLUMN_SEPARATOR_COLOR);
|
|
24620
|
+
for (const x of page.columnSeparatorsX) {
|
|
24621
|
+
pdf.moveTo(x + 0.5, page.contentTopPx).lineTo(x + 0.5, page.contentBottomPx).stroke();
|
|
24622
|
+
}
|
|
24623
|
+
}
|
|
24605
24624
|
if (page.footnoteRuleY !== void 0) {
|
|
24606
24625
|
const cw = page.widthPx - page.marginPx.left - page.marginPx.right;
|
|
24607
24626
|
pdf.undash().lineWidth(1).strokeColor(FOOTNOTE_RULE_COLOR);
|
|
@@ -24944,13 +24963,25 @@ function tableXml(table, ctx) {
|
|
|
24944
24963
|
col = emitContinues(col, out);
|
|
24945
24964
|
rowsXml.push(el("w:tr", void 0, out.join("")));
|
|
24946
24965
|
}
|
|
24966
|
+
const styleRef = table.styleId ? el("w:tblStyle", { "w:val": table.styleId }) : "";
|
|
24967
|
+
const look = table.styleId && table.condOverrides ? tblLookXml(table.condOverrides) : "";
|
|
24947
24968
|
const tblPr = el(
|
|
24948
24969
|
"w:tblPr",
|
|
24949
24970
|
void 0,
|
|
24950
|
-
el("w:tblW", { "w:w": 0, "w:type": "auto" }) + el("w:tblLayout", { "w:type": "fixed" })
|
|
24971
|
+
styleRef + el("w:tblW", { "w:w": 0, "w:type": "auto" }) + el("w:tblLayout", { "w:type": "fixed" }) + look
|
|
24951
24972
|
);
|
|
24952
24973
|
return el("w:tbl", void 0, tblPr + el("w:tblGrid", void 0, grid) + rowsXml.join(""));
|
|
24953
24974
|
}
|
|
24975
|
+
function tblLookXml(o) {
|
|
24976
|
+
return el("w:tblLook", {
|
|
24977
|
+
"w:firstRow": o.firstRow ? "1" : "0",
|
|
24978
|
+
"w:lastRow": o.lastRow ? "1" : "0",
|
|
24979
|
+
"w:firstColumn": o.firstCol ? "1" : "0",
|
|
24980
|
+
"w:lastColumn": o.lastCol ? "1" : "0",
|
|
24981
|
+
"w:noHBand": o.bandRows ? "0" : "1",
|
|
24982
|
+
"w:noVBand": o.bandCols ? "0" : "1"
|
|
24983
|
+
});
|
|
24984
|
+
}
|
|
24954
24985
|
function blockXml(block, ctx) {
|
|
24955
24986
|
if (block.kind === "paragraph") return paragraphXml(block, ctx);
|
|
24956
24987
|
if (block.kind === "table") return tableXml(block, ctx);
|
|
@@ -25077,6 +25108,20 @@ function imageParagraphXml(img, ctx) {
|
|
|
25077
25108
|
const align = img.align === "center" ? "center" : img.align === "right" ? "right" : "left";
|
|
25078
25109
|
return el("w:p", void 0, el("w:pPr", void 0, el("w:jc", { "w:val": align })) + el("w:r", void 0, drawing));
|
|
25079
25110
|
}
|
|
25111
|
+
function pgBordersXml(b) {
|
|
25112
|
+
const edge = (name, e) => {
|
|
25113
|
+
if (!e || e.style === "none") return "";
|
|
25114
|
+
const spacePt = Math.min(31, Math.max(0, Math.round((e.spacePx ?? 0) * (72 / 96))));
|
|
25115
|
+
return el("w:" + name, {
|
|
25116
|
+
"w:val": e.style,
|
|
25117
|
+
"w:sz": pxToEighthPoints(e.widthPx),
|
|
25118
|
+
"w:space": spacePt,
|
|
25119
|
+
"w:color": e.color === "auto" ? "auto" : hexColor(e.color)
|
|
25120
|
+
});
|
|
25121
|
+
};
|
|
25122
|
+
const inner = edge("top", b.top) + edge("left", b.left) + edge("bottom", b.bottom) + edge("right", b.right);
|
|
25123
|
+
return el("w:pgBorders", { "w:offsetFrom": b.offsetFrom ?? "page" }, inner);
|
|
25124
|
+
}
|
|
25080
25125
|
function sectPrXml(s, ctx, addBand, isBody) {
|
|
25081
25126
|
const c = [];
|
|
25082
25127
|
const band = (blocks, kind, type) => {
|
|
@@ -25092,7 +25137,12 @@ function sectPrXml(s, ctx, addBand, isBody) {
|
|
|
25092
25137
|
band(s.footerEven, "footer", "even");
|
|
25093
25138
|
if (s.headerFirst || s.footerFirst) c.push(el("w:titlePg"));
|
|
25094
25139
|
if (s.pageWidthPx !== void 0 && s.pageHeightPx !== void 0) {
|
|
25095
|
-
|
|
25140
|
+
const pgSz = {
|
|
25141
|
+
"w:w": pxToTwips(s.pageWidthPx),
|
|
25142
|
+
"w:h": pxToTwips(s.pageHeightPx)
|
|
25143
|
+
};
|
|
25144
|
+
if (s.pageWidthPx > s.pageHeightPx) pgSz["w:orient"] = "landscape";
|
|
25145
|
+
c.push(el("w:pgSz", pgSz));
|
|
25096
25146
|
}
|
|
25097
25147
|
if (s.marginPx) {
|
|
25098
25148
|
const m = s.marginPx;
|
|
@@ -25101,13 +25151,23 @@ function sectPrXml(s, ctx, addBand, isBody) {
|
|
|
25101
25151
|
"w:right": pxToTwips(m.right),
|
|
25102
25152
|
"w:bottom": pxToTwips(m.bottom),
|
|
25103
25153
|
"w:left": pxToTwips(m.left),
|
|
25104
|
-
"w:header": 720,
|
|
25105
|
-
"w:footer": 720
|
|
25154
|
+
"w:header": s.headerDistancePx !== void 0 ? pxToTwips(s.headerDistancePx) : 720,
|
|
25155
|
+
"w:footer": s.footerDistancePx !== void 0 ? pxToTwips(s.footerDistancePx) : 720
|
|
25106
25156
|
}));
|
|
25107
25157
|
}
|
|
25108
25158
|
if (s.columns && s.columns.count > 1) {
|
|
25109
|
-
|
|
25159
|
+
const cols = s.columns;
|
|
25160
|
+
const attrs = { "w:num": cols.count, "w:space": pxToTwips(cols.gapPx) };
|
|
25161
|
+
if (cols.sep) attrs["w:sep"] = "1";
|
|
25162
|
+
if (cols.cols && cols.cols.length === cols.count) {
|
|
25163
|
+
attrs["w:equalWidth"] = "0";
|
|
25164
|
+
const inner = cols.cols.map((col) => el("w:col", { "w:w": pxToTwips(col.widthPx), "w:space": pxToTwips(col.spaceAfterPx) })).join("");
|
|
25165
|
+
c.push(el("w:cols", attrs, inner));
|
|
25166
|
+
} else {
|
|
25167
|
+
c.push(el("w:cols", attrs));
|
|
25168
|
+
}
|
|
25110
25169
|
}
|
|
25170
|
+
if (s.pageBorders) c.push(pgBordersXml(s.pageBorders));
|
|
25111
25171
|
if (s.pageNumberStart !== void 0) c.push(el("w:pgNumType", { "w:start": s.pageNumberStart }));
|
|
25112
25172
|
if (!isBody) c.push(el("w:type", { "w:val": "nextPage" }));
|
|
25113
25173
|
return el("w:sectPr", void 0, c.join(""));
|
|
@@ -25132,7 +25192,8 @@ function buildDocumentXml(blocks, section, ctx, addBand) {
|
|
|
25132
25192
|
}
|
|
25133
25193
|
}
|
|
25134
25194
|
const body = parts.join("") + sectPrXml(section, ctx, addBand, true);
|
|
25135
|
-
|
|
25195
|
+
const background = section.pageColorHex !== void 0 ? el("w:background", { "w:color": hexColor(section.pageColorHex) }) : "";
|
|
25196
|
+
return XML_DECL + el("w:document", WML_NS, background + el("w:body", void 0, body));
|
|
25136
25197
|
}
|
|
25137
25198
|
|
|
25138
25199
|
// src/export/docx/contentTypes.ts
|
|
@@ -25240,20 +25301,22 @@ function numberingXml(lists, listIdMap) {
|
|
|
25240
25301
|
}
|
|
25241
25302
|
|
|
25242
25303
|
// src/export/docx/settingsXml.ts
|
|
25243
|
-
function settingsXml(evenAndOdd) {
|
|
25244
|
-
const body = evenAndOdd ? el("w:evenAndOddHeadersAndFooters") : "";
|
|
25304
|
+
function settingsXml(evenAndOdd, displayBackgroundShape = false) {
|
|
25305
|
+
const body = (displayBackgroundShape ? el("w:displayBackgroundShape") : "") + (evenAndOdd ? el("w:evenAndOddHeadersAndFooters") : "");
|
|
25245
25306
|
return XML_DECL + el("w:settings", WML_NS, body);
|
|
25246
25307
|
}
|
|
25247
25308
|
|
|
25248
25309
|
// src/export/docx/stylesXml.ts
|
|
25249
|
-
function stylesXml(sheet) {
|
|
25250
|
-
const
|
|
25251
|
-
const
|
|
25252
|
-
|
|
25253
|
-
|
|
25310
|
+
function stylesXml(sheet, tableStyles) {
|
|
25311
|
+
const named = (sheet?.styles ?? []).map((s) => {
|
|
25312
|
+
const isChar = styleType(s) === "character";
|
|
25313
|
+
const attrs = { "w:type": isChar ? "character" : "paragraph", "w:styleId": s.id };
|
|
25314
|
+
if (!isChar && sheet && s.id === sheet.defaultStyleId) attrs["w:default"] = "1";
|
|
25315
|
+
const body = el("w:name", { "w:val": s.name }) + (s.basedOn ? el("w:basedOn", { "w:val": s.basedOn }) : "") + (isChar ? "" : partialPPrXml(s.para)) + partialRPrXml(s.char);
|
|
25254
25316
|
return el("w:style", attrs, body);
|
|
25255
25317
|
}).join("");
|
|
25256
|
-
|
|
25318
|
+
const tables = Object.values(tableStyles ?? {}).map(tableStyleXml).join("");
|
|
25319
|
+
return XML_DECL + el("w:styles", WML_NS, named + tables);
|
|
25257
25320
|
}
|
|
25258
25321
|
|
|
25259
25322
|
// src/export/docx/writeDocx.ts
|
|
@@ -25343,8 +25406,10 @@ function writeDocx(doc, images = {}, tocPages) {
|
|
|
25343
25406
|
return bodyRels.add(kind === "header" ? REL.header : REL.footer, file);
|
|
25344
25407
|
};
|
|
25345
25408
|
parts["word/document.xml"] = buildDocumentXml(doc.blocks, doc.section, bodyCtx, addBand);
|
|
25346
|
-
|
|
25347
|
-
|
|
25409
|
+
const hasNamed = !!doc.stylesheet && doc.stylesheet.styles.length > 0;
|
|
25410
|
+
const hasTableStyles = !!doc.tableStyles && Object.keys(doc.tableStyles).length > 0;
|
|
25411
|
+
if (hasNamed || hasTableStyles) {
|
|
25412
|
+
parts["word/styles.xml"] = stylesXml(doc.stylesheet, doc.tableStyles);
|
|
25348
25413
|
overrides.push(["/word/styles.xml", CT.styles]);
|
|
25349
25414
|
bodyRels.add(REL.styles, "styles.xml");
|
|
25350
25415
|
}
|
|
@@ -25359,7 +25424,7 @@ function writeDocx(doc, images = {}, tocPages) {
|
|
|
25359
25424
|
bodyRels.add(REL.footnotes, "footnotes.xml");
|
|
25360
25425
|
}
|
|
25361
25426
|
const evenAndOdd = sectionsHaveEvenBands(doc);
|
|
25362
|
-
parts["word/settings.xml"] = settingsXml(evenAndOdd);
|
|
25427
|
+
parts["word/settings.xml"] = settingsXml(evenAndOdd, doc.section.pageColorHex !== void 0);
|
|
25363
25428
|
overrides.push(["/word/settings.xml", CT.settings]);
|
|
25364
25429
|
bodyRels.add(REL.settings, "settings.xml");
|
|
25365
25430
|
for (const [path, bytes2] of bodyMedia.parts()) parts[`word/${path}`] = bytes2;
|