reamkit 0.1.0-alpha.0 → 1.0.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.
- package/README.md +106 -30
- package/dist/esm/{bidi → core/bidi}/algorithm.js +1 -1
- package/dist/esm/{bidi → core/bidi}/char-types.js +1 -1
- package/dist/esm/{bidi → core/bidi}/index.js +1 -1
- package/dist/esm/core/bytes.d.ts +1 -0
- package/dist/esm/core/bytes.js +11 -0
- package/dist/esm/core/converter/facade.d.ts +45 -0
- package/dist/esm/core/converter/facade.js +89 -0
- package/dist/esm/core/converter/index.d.ts +4 -0
- package/dist/esm/core/converter/project.d.ts +4 -0
- package/dist/esm/core/converter/project.js +16 -0
- package/dist/esm/core/converter/ream.d.ts +35 -0
- package/dist/esm/core/converter/ream.js +100 -0
- package/dist/esm/{crypto → core/crypto}/asn1.js +1 -1
- package/dist/esm/{crypto → core/crypto}/cms.js +1 -1
- package/dist/esm/core/document-model/index.d.ts +1 -0
- package/dist/esm/{document-model → core/document-model}/types.d.ts +57 -41
- package/dist/esm/{ooxml → core}/drawingml/chart-parser.d.ts +1 -1
- package/dist/esm/{ooxml → core}/drawingml/chart-parser.js +6 -29
- package/dist/esm/{ooxml → core}/drawingml/colors.d.ts +3 -0
- package/dist/esm/{ooxml → core}/drawingml/colors.js +32 -2
- package/dist/esm/{ooxml → core}/drawingml/theme-parser.js +2 -2
- package/dist/esm/{font → core/font}/arabic-joining.js +1 -1
- package/dist/esm/{font → core/font}/binary-reader.js +1 -1
- package/dist/esm/{font → core/font}/font-registry.d.ts +1 -0
- package/dist/esm/{font → core/font}/font-registry.js +17 -16
- package/dist/esm/{font → core/font}/index.d.ts +1 -0
- package/dist/esm/{font → core/font}/opentype-layout.js +1 -1
- package/dist/esm/{font → core/font}/ttf-parser.js +1 -1
- package/dist/esm/{font → core/font}/ttf-subset.js +1 -1
- package/dist/esm/core/fonts/provider.d.ts +60 -0
- package/dist/esm/core/fonts/provider.js +163 -0
- package/dist/esm/{fonts → core/fonts}/remote-fonts.js +1 -1
- package/dist/esm/{hyphenation → core/hyphenation}/index.js +1 -1
- package/dist/esm/{hyphenation → core/hyphenation}/liang.js +1 -1
- package/dist/esm/{hyphenation → core/hyphenation}/patterns-en-us.js +1 -1
- package/dist/esm/{hyphenation → core/hyphenation}/patterns-ru.js +1 -1
- package/dist/esm/core/ir/adapters.d.ts +37 -0
- package/dist/esm/core/ir/features.d.ts +25 -0
- package/dist/esm/core/ir/features.js +24 -0
- package/dist/esm/core/ir/flow.d.ts +24 -0
- package/dist/esm/core/ir/index.d.ts +11 -0
- package/dist/esm/core/ir/loss.d.ts +22 -0
- package/dist/esm/core/ir/loss.js +15 -0
- package/dist/esm/core/ir/resources.d.ts +16 -0
- package/dist/esm/core/ir/resources.js +50 -0
- package/dist/esm/core/ir/units.d.ts +16 -0
- package/dist/esm/core/ir/units.js +41 -0
- package/dist/esm/core/line-breaker/index.d.ts +2 -0
- package/dist/esm/{line-breaker → core/line-breaker}/knuth-plass.js +1 -1
- package/dist/esm/{numbering → core/numbering}/state.js +1 -1
- package/dist/esm/{opc → core/opc}/core-properties.js +1 -1
- package/dist/esm/{opc → core/opc}/package.js +1 -1
- package/dist/esm/{opc → core/opc}/relationship-types.js +1 -1
- package/dist/esm/{opc → core/opc}/relationships.js +1 -1
- package/dist/esm/{ooxml/wordproc → core}/po-helpers.js +1 -1
- package/dist/esm/{style-cascade → core/style-cascade}/index.d.ts +2 -2
- package/dist/esm/core/style-cascade/index.js +2 -0
- package/dist/esm/{style-cascade → core/style-cascade}/resolver.d.ts +1 -0
- package/dist/esm/{style-cascade → core/style-cascade}/resolver.js +14 -9
- package/dist/esm/{style-cascade → core/style-cascade}/types.d.ts +8 -7
- package/dist/esm/{style-cascade → core/style-cascade}/types.js +9 -8
- package/dist/esm/{ooxml/spreadsheet → excel}/cell-reference.js +1 -1
- package/dist/esm/{ooxml/spreadsheet → excel}/defined-name-ref.js +1 -1
- package/dist/esm/{ooxml/spreadsheet → excel}/index.d.ts +1 -1
- package/dist/esm/{ooxml/spreadsheet → excel}/number-format.js +1 -1
- package/dist/esm/excel/print-model.d.ts +18 -0
- package/dist/esm/{converter/xlsx-to-pdf.js → excel/print-model.js} +39 -148
- package/dist/esm/{ooxml/spreadsheet → excel}/shared-strings-parser.js +1 -1
- package/dist/esm/{ooxml/spreadsheet → excel}/styles-parser.js +1 -1
- package/dist/esm/{ooxml/spreadsheet → excel}/workbook-parser.js +1 -1
- package/dist/esm/{ooxml/spreadsheet → excel}/worksheet-parser.js +1 -1
- package/dist/esm/excel/xlsx-reader.d.ts +4 -0
- package/dist/esm/excel/xlsx-reader.js +91 -0
- package/dist/esm/{converter → excel}/xlsx-to-pdf.d.ts +13 -2
- package/dist/esm/excel/xlsx-to-pdf.js +69 -0
- package/dist/esm/index.d.ts +23 -8
- package/dist/esm/index.js +18 -11
- package/dist/esm/pdf/chart-geometry.d.ts +1 -1
- package/dist/esm/pdf/cid-font.d.ts +7 -1
- package/dist/esm/pdf/cid-font.js +33 -22
- package/dist/esm/pdf/image-xobject.d.ts +13 -0
- package/dist/esm/pdf/image-xobject.js +55 -54
- package/dist/esm/pdf/index.d.ts +2 -2
- package/dist/esm/pdf/math-layout.d.ts +1 -1
- package/dist/esm/pdf/preset-geometry.d.ts +1 -1
- package/dist/esm/pdf/signature.js +4 -4
- package/dist/esm/pdf/styled-page-emitter.d.ts +5 -0
- package/dist/esm/pdf/styled-page-emitter.js +542 -0
- package/dist/esm/pdf/styled-page-renderer.d.ts +189 -14
- package/dist/esm/pdf/styled-page-renderer.js +168 -654
- package/dist/esm/pdf/text-page-renderer.d.ts +1 -1
- package/dist/esm/svg/svg-writer.d.ts +8 -0
- package/dist/esm/svg/svg-writer.js +138 -0
- package/dist/esm/word/document-parser.d.ts +16 -0
- package/dist/esm/{ooxml/wordproc → word}/document-parser.js +55 -47
- package/dist/esm/word/docx-reader.d.ts +4 -0
- package/dist/esm/word/docx-reader.js +190 -0
- package/dist/esm/word/docx-to-pdf.d.ts +34 -0
- package/dist/esm/word/docx-to-pdf.js +112 -0
- package/dist/esm/{ooxml/wordproc → word}/drawing-parser.d.ts +10 -9
- package/dist/esm/{ooxml/wordproc → word}/drawing-parser.js +15 -42
- package/dist/esm/{ooxml/wordproc → word}/font-table.d.ts +2 -2
- package/dist/esm/{ooxml/wordproc → word}/font-table.js +2 -2
- package/dist/esm/{ooxml/wordproc → word}/index.d.ts +3 -2
- package/dist/esm/{ooxml/wordproc → word}/numbering-parser.d.ts +1 -1
- package/dist/esm/{ooxml/wordproc → word}/numbering-parser.js +1 -1
- package/dist/esm/{ooxml/math → word}/omml-parser.d.ts +2 -2
- package/dist/esm/{ooxml/math → word}/omml-parser.js +2 -2
- package/dist/esm/{ooxml/wordproc → word}/paragraph-properties.d.ts +1 -1
- package/dist/esm/{ooxml/wordproc → word}/paragraph-properties.js +9 -8
- package/dist/esm/{ooxml/wordproc → word}/po-to-flat.d.ts +1 -1
- package/dist/esm/{ooxml/wordproc → word}/po-to-flat.js +2 -2
- package/dist/esm/{ooxml/wordproc → word}/run-properties.d.ts +1 -1
- package/dist/esm/{ooxml/wordproc → word}/run-properties.js +3 -2
- package/dist/esm/{ooxml/wordproc → word}/settings-parser.js +2 -2
- package/dist/esm/word/styles-parser.d.ts +2 -0
- package/dist/esm/{ooxml/wordproc → word}/styles-parser.js +4 -7
- package/dist/esm/word/table-parser.d.ts +4 -0
- package/dist/esm/{ooxml/wordproc → word}/table-parser.js +80 -26
- package/dist/esm/{ooxml/wordproc → word}/xml-helpers.js +1 -1
- package/package.json +5 -6
- package/dist/esm/converter/docx-to-pdf.d.ts +0 -15
- package/dist/esm/converter/docx-to-pdf.js +0 -227
- package/dist/esm/converter/index.d.ts +0 -4
- package/dist/esm/converter/index.js +0 -2
- package/dist/esm/document-model/index.d.ts +0 -1
- package/dist/esm/line-breaker/index.d.ts +0 -2
- package/dist/esm/ooxml/index.d.ts +0 -1
- package/dist/esm/ooxml/wordproc/document-parser.d.ts +0 -9
- package/dist/esm/ooxml/wordproc/styles-parser.d.ts +0 -3
- package/dist/esm/ooxml/wordproc/table-parser.d.ts +0 -3
- /package/dist/esm/{bidi → core/bidi}/algorithm.d.ts +0 -0
- /package/dist/esm/{bidi → core/bidi}/char-types.d.ts +0 -0
- /package/dist/esm/{bidi → core/bidi}/index.d.ts +0 -0
- /package/dist/esm/{crypto → core/crypto}/asn1.d.ts +0 -0
- /package/dist/esm/{crypto → core/crypto}/cms.d.ts +0 -0
- /package/dist/esm/{crypto → core/crypto}/index.d.ts +0 -0
- /package/dist/esm/{crypto → core/crypto}/index.js +0 -0
- /package/dist/esm/{document-model → core/document-model}/index.js +0 -0
- /package/dist/esm/{ooxml → core}/drawingml/theme-parser.d.ts +0 -0
- /package/dist/esm/{font → core/font}/arabic-joining.d.ts +0 -0
- /package/dist/esm/{font → core/font}/binary-reader.d.ts +0 -0
- /package/dist/esm/{font → core/font}/opentype-layout.d.ts +0 -0
- /package/dist/esm/{font → core/font}/ttf-parser.d.ts +0 -0
- /package/dist/esm/{font → core/font}/ttf-subset.d.ts +0 -0
- /package/dist/esm/{fonts → core/fonts}/index.d.ts +0 -0
- /package/dist/esm/{fonts → core/fonts}/remote-fonts.d.ts +0 -0
- /package/dist/esm/{hyphenation → core/hyphenation}/index.d.ts +0 -0
- /package/dist/esm/{hyphenation → core/hyphenation}/liang.d.ts +0 -0
- /package/dist/esm/{hyphenation → core/hyphenation}/patterns-en-us.d.ts +0 -0
- /package/dist/esm/{hyphenation → core/hyphenation}/patterns-ru.d.ts +0 -0
- /package/dist/esm/{line-breaker → core/line-breaker}/knuth-plass.d.ts +0 -0
- /package/dist/esm/{numbering → core/numbering}/index.d.ts +0 -0
- /package/dist/esm/{numbering → core/numbering}/state.d.ts +0 -0
- /package/dist/esm/{opc → core/opc}/core-properties.d.ts +0 -0
- /package/dist/esm/{opc → core/opc}/index.d.ts +0 -0
- /package/dist/esm/{opc → core/opc}/index.js +0 -0
- /package/dist/esm/{opc → core/opc}/package.d.ts +0 -0
- /package/dist/esm/{opc → core/opc}/relationship-types.d.ts +0 -0
- /package/dist/esm/{opc → core/opc}/relationships.d.ts +0 -0
- /package/dist/esm/{ooxml/wordproc → core}/po-helpers.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/cell-reference.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/defined-name-ref.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/index.js +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/number-format.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/shared-strings-parser.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/styles-parser.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/workbook-parser.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/worksheet-parser.d.ts +0 -0
- /package/dist/esm/{ooxml/wordproc → word}/index.js +0 -0
- /package/dist/esm/{ooxml/wordproc → word}/settings-parser.d.ts +0 -0
- /package/dist/esm/{ooxml/wordproc → word}/text-extractor.d.ts +0 -0
- /package/dist/esm/{ooxml/wordproc → word}/text-extractor.js +0 -0
- /package/dist/esm/{ooxml/wordproc → word}/xml-helpers.d.ts +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { fetchFontSet, resolveFamilyKey } from "../core/fonts/remote-fonts.js";
|
|
2
|
+
import { FontRegistry } from "../core/font/font-registry.js";
|
|
3
|
+
import { signPdf } from "../pdf/signature.js";
|
|
4
|
+
import { renderStyledPdf } from "../pdf/styled-page-renderer.js";
|
|
5
|
+
import "../pdf/index.js";
|
|
6
|
+
import { OpcPackage } from "../core/opc/package.js";
|
|
7
|
+
import "../core/opc/index.js";
|
|
8
|
+
import { readDocx } from "./docx-reader.js";
|
|
9
|
+
import { flowRenderOptions } from "../core/converter/project.js";
|
|
10
|
+
//#region src/word/docx-to-pdf.ts
|
|
11
|
+
var STYLES_PART = "word/styles.xml";
|
|
12
|
+
var MAIN_DOCUMENT_PART = "word/document.xml";
|
|
13
|
+
/**
|
|
14
|
+
* Synchronous one-shot conversion (requires `fonts`/`fontBytes`, no network).
|
|
15
|
+
*
|
|
16
|
+
* Internal since 1.0 — see the async variant above.
|
|
17
|
+
*/
|
|
18
|
+
function convertDocxToPdfSync(docx, options) {
|
|
19
|
+
const fonts = options.fonts ?? (options.fontBytes ? { regular: options.fontBytes } : void 0);
|
|
20
|
+
if (!fonts) throw new Error("convertDocxToPdfSync requires options.fonts or options.fontBytes");
|
|
21
|
+
const registry = FontRegistry.fromBytes(fonts);
|
|
22
|
+
const { doc: flow } = readDocx(docx);
|
|
23
|
+
const { fontBytes: _ignoreA, fonts: _ignoreB, info: callerInfo, embedSource, attachments: callerAttachments, signature: _ignoreSig, ...renderOptions } = options;
|
|
24
|
+
const info = flow.info || callerInfo ? {
|
|
25
|
+
...flow.info,
|
|
26
|
+
...callerInfo
|
|
27
|
+
} : void 0;
|
|
28
|
+
const attachments = [...callerAttachments ?? []];
|
|
29
|
+
if (embedSource && options.pdfA?.startsWith("PDF/A-3")) attachments.push({
|
|
30
|
+
name: "source.docx",
|
|
31
|
+
bytes: docx,
|
|
32
|
+
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
33
|
+
relationship: "Source",
|
|
34
|
+
description: "Source Word document"
|
|
35
|
+
});
|
|
36
|
+
return renderStyledPdf(flow.body, {
|
|
37
|
+
registry,
|
|
38
|
+
...flowRenderOptions(flow),
|
|
39
|
+
...info ? { info } : {},
|
|
40
|
+
...attachments.length > 0 ? { attachments } : {},
|
|
41
|
+
...renderOptions
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function detectDocxFamilyKeys(docx) {
|
|
45
|
+
const keys = new Set(["roboto"]);
|
|
46
|
+
let pkg;
|
|
47
|
+
try {
|
|
48
|
+
pkg = OpcPackage.open(docx);
|
|
49
|
+
} catch {
|
|
50
|
+
return keys;
|
|
51
|
+
}
|
|
52
|
+
const decoder = new TextDecoder("utf-8");
|
|
53
|
+
const re = /<w:rFonts[^>]*\bw:ascii="([^"]+)"/g;
|
|
54
|
+
for (const part of [STYLES_PART, MAIN_DOCUMENT_PART]) {
|
|
55
|
+
const data = pkg.getPart(part);
|
|
56
|
+
if (!data) continue;
|
|
57
|
+
const xml = decoder.decode(data);
|
|
58
|
+
let m;
|
|
59
|
+
while ((m = re.exec(xml)) !== null) keys.add(resolveFamilyKey(m[1]));
|
|
60
|
+
}
|
|
61
|
+
return keys;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* One-shot .docx → PDF (auto-downloads a substitute font set when the caller
|
|
65
|
+
* supplies none; zero network with `fonts`/`fontBytes`).
|
|
66
|
+
*
|
|
67
|
+
* Internal since 1.0 — the public entry is `Ream.parse(bytes).convert('pdf')`;
|
|
68
|
+
* the createConverter facade and the test suite drive this directly.
|
|
69
|
+
*/
|
|
70
|
+
async function convertDocxToPdf(docx, options = {}) {
|
|
71
|
+
const { signature } = options;
|
|
72
|
+
const pdf = await buildUnsignedDocxPdf(docx, signature ? {
|
|
73
|
+
...options,
|
|
74
|
+
signaturePlaceholder: signature
|
|
75
|
+
} : options);
|
|
76
|
+
return signature ? signPdf(pdf, signature) : pdf;
|
|
77
|
+
}
|
|
78
|
+
async function buildUnsignedDocxPdf(docx, options) {
|
|
79
|
+
if (options.fonts ?? options.fontBytes) return convertDocxToPdfSync(docx, options);
|
|
80
|
+
const auto = await resolveDocxAutoFonts(docx, options);
|
|
81
|
+
return convertDocxToPdfSync(docx, {
|
|
82
|
+
...options,
|
|
83
|
+
...auto
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async function resolveDocxAutoFonts(docx, options = {}) {
|
|
87
|
+
const fetchOpt = options.fontFetch ? { fetch: options.fontFetch } : {};
|
|
88
|
+
const keys = options.fontFamily ? new Set([resolveFamilyKey(options.fontFamily)]) : detectDocxFamilyKeys(docx);
|
|
89
|
+
if (keys.size <= 1) {
|
|
90
|
+
const family = keys.values().next().value;
|
|
91
|
+
return { fonts: await fetchFontSet({
|
|
92
|
+
...family ? { family } : {},
|
|
93
|
+
...fetchOpt
|
|
94
|
+
}) };
|
|
95
|
+
}
|
|
96
|
+
const registriesByFamily = /* @__PURE__ */ new Map();
|
|
97
|
+
let baseBytes;
|
|
98
|
+
for (const key of keys) {
|
|
99
|
+
const bytes = await fetchFontSet({
|
|
100
|
+
family: key,
|
|
101
|
+
...fetchOpt
|
|
102
|
+
});
|
|
103
|
+
registriesByFamily.set(key, FontRegistry.fromBytes(bytes));
|
|
104
|
+
if (key === "roboto" || !baseBytes) baseBytes = bytes;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
fonts: baseBytes,
|
|
108
|
+
registriesByFamily
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { convertDocxToPdf, resolveDocxAutoFonts };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { BodyElement, ShapeFill, ShapeGeometry, ShapeLine, ShapeTextBody, ShapeTransform } from '
|
|
2
|
-
import { ColorResolver } from '../drawingml/colors.js';
|
|
3
|
-
import { PoNode } from '
|
|
1
|
+
import { BodyElement, ShapeFill, ShapeGeometry, ShapeLine, ShapeTextBody, ShapeTransform } from '../core/document-model/index.js';
|
|
2
|
+
import { ColorResolver } from '../core/drawingml/colors.js';
|
|
3
|
+
import { PoNode } from '../core/po-helpers.js';
|
|
4
|
+
import { Pt } from '../core/ir/index.js';
|
|
4
5
|
export interface ShapeData {
|
|
5
|
-
readonly
|
|
6
|
-
readonly
|
|
6
|
+
readonly width: Pt;
|
|
7
|
+
readonly height: Pt;
|
|
7
8
|
readonly geometry: ShapeGeometry;
|
|
8
9
|
readonly fill: ShapeFill;
|
|
9
10
|
readonly line?: ShapeLine;
|
|
@@ -14,8 +15,8 @@ export type ParseBody = (children: ReadonlyArray<PoNode>) => Array<BodyElement>;
|
|
|
14
15
|
export type DrawingContent = {
|
|
15
16
|
readonly kind: 'image';
|
|
16
17
|
readonly imageId: string;
|
|
17
|
-
readonly
|
|
18
|
-
readonly
|
|
18
|
+
readonly width: Pt;
|
|
19
|
+
readonly height: Pt;
|
|
19
20
|
readonly altText?: string;
|
|
20
21
|
} | {
|
|
21
22
|
readonly kind: 'shape';
|
|
@@ -24,8 +25,8 @@ export type DrawingContent = {
|
|
|
24
25
|
} | {
|
|
25
26
|
readonly kind: 'chart';
|
|
26
27
|
readonly chartRelId: string;
|
|
27
|
-
readonly
|
|
28
|
-
readonly
|
|
28
|
+
readonly width: Pt;
|
|
29
|
+
readonly height: Pt;
|
|
29
30
|
readonly altText?: string;
|
|
30
31
|
};
|
|
31
32
|
export declare function resolveMc(altContent: PoNode): ReadonlyArray<PoNode>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { emuToPt } from "../core/ir/units.js";
|
|
2
|
+
import { poAttr, poChildren, poFindDescendant, poIntAttr, poIs, poTag } from "../core/po-helpers.js";
|
|
3
|
+
import { resolveColorNode } from "../core/drawingml/colors.js";
|
|
4
|
+
//#region src/word/drawing-parser.ts
|
|
3
5
|
var WPS_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
|
|
4
6
|
var CHART_URI = "http://schemas.openxmlformats.org/drawingml/2006/chart";
|
|
5
7
|
var UNDERSTOOD_NS = new Set(["wps"]);
|
|
@@ -45,8 +47,8 @@ function parseDrawing(drawing, resolveColor, parseBody) {
|
|
|
45
47
|
if (chartRelId && extentCx !== void 0 && extentCy !== void 0) return {
|
|
46
48
|
kind: "chart",
|
|
47
49
|
chartRelId,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
width: emuToPt(extentCx),
|
|
51
|
+
height: emuToPt(extentCy),
|
|
50
52
|
...alt
|
|
51
53
|
};
|
|
52
54
|
return null;
|
|
@@ -56,8 +58,8 @@ function parseDrawing(drawing, resolveColor, parseBody) {
|
|
|
56
58
|
if (extentCx !== void 0 && extentCy !== void 0 && rId) return {
|
|
57
59
|
kind: "image",
|
|
58
60
|
imageId: rId,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
width: emuToPt(extentCx),
|
|
62
|
+
height: emuToPt(extentCy),
|
|
61
63
|
...alt
|
|
62
64
|
};
|
|
63
65
|
return null;
|
|
@@ -98,8 +100,8 @@ function parseWsp(graphicData, extentCx, extentCy, resolveColor, parseBody) {
|
|
|
98
100
|
const text = parseBody ? parseTextBox(wsp, parseBody) : void 0;
|
|
99
101
|
if (widthEmu === void 0 || heightEmu === void 0) return null;
|
|
100
102
|
return {
|
|
101
|
-
widthEmu,
|
|
102
|
-
heightEmu,
|
|
103
|
+
width: emuToPt(widthEmu),
|
|
104
|
+
height: emuToPt(heightEmu),
|
|
103
105
|
geometry,
|
|
104
106
|
fill,
|
|
105
107
|
...line ? { line } : {},
|
|
@@ -123,10 +125,10 @@ function parseTextBox(wsp, parseBody) {
|
|
|
123
125
|
const anchor = a === "ctr" ? "ctr" : a === "b" ? "b" : a === "t" ? "t" : void 0;
|
|
124
126
|
return {
|
|
125
127
|
content,
|
|
126
|
-
...lIns !== void 0 ? {
|
|
127
|
-
...tIns !== void 0 ? {
|
|
128
|
-
...rIns !== void 0 ? {
|
|
129
|
-
...bIns !== void 0 ? {
|
|
128
|
+
...lIns !== void 0 ? { insetLeft: emuToPt(lIns) } : {},
|
|
129
|
+
...tIns !== void 0 ? { insetTop: emuToPt(tIns) } : {},
|
|
130
|
+
...rIns !== void 0 ? { insetRight: emuToPt(rIns) } : {},
|
|
131
|
+
...bIns !== void 0 ? { insetBottom: emuToPt(bIns) } : {},
|
|
130
132
|
...anchor ? { anchor } : {}
|
|
131
133
|
};
|
|
132
134
|
}
|
|
@@ -287,7 +289,7 @@ function parseLine(spPr, resolveColor) {
|
|
|
287
289
|
else if (poIs(c, "a:solidFill")) colorHex = colorFromContainer(c, resolveColor);
|
|
288
290
|
else if (poIs(c, "a:prstDash")) dash = normalizeDash(poAttr(c, "val"));
|
|
289
291
|
return {
|
|
290
|
-
...widthEmu !== void 0 ? { widthEmu } : {},
|
|
292
|
+
...widthEmu !== void 0 ? { width: emuToPt(widthEmu) } : {},
|
|
291
293
|
...colorHex ? { colorHex } : {},
|
|
292
294
|
...dash ? { dash } : {},
|
|
293
295
|
...cap ? { cap } : {},
|
|
@@ -310,35 +312,6 @@ function normalizeDash(v) {
|
|
|
310
312
|
if (v === "lgDashDotDot") return "lgDashDot";
|
|
311
313
|
if (v === "sysDashDot" || v === "sysDashDotDot") return "sysDash";
|
|
312
314
|
}
|
|
313
|
-
function readColorMods(colorNode) {
|
|
314
|
-
const mods = [];
|
|
315
|
-
for (const c of poChildren(colorNode)) for (const kind of [
|
|
316
|
-
"lumMod",
|
|
317
|
-
"lumOff",
|
|
318
|
-
"shade",
|
|
319
|
-
"tint",
|
|
320
|
-
"alpha"
|
|
321
|
-
]) if (poIs(c, `a:${kind}`)) {
|
|
322
|
-
const v = poIntAttr(c, "val");
|
|
323
|
-
if (v !== void 0) mods.push({
|
|
324
|
-
kind,
|
|
325
|
-
val: v / 1e5
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
return mods;
|
|
329
|
-
}
|
|
330
|
-
function resolveColorNode(c, resolveColor) {
|
|
331
|
-
const isSrgb = poIs(c, "a:srgbClr");
|
|
332
|
-
if (!isSrgb && !poIs(c, "a:schemeClr")) return void 0;
|
|
333
|
-
const v = poAttr(c, "val");
|
|
334
|
-
if (!v) return void 0;
|
|
335
|
-
const mods = readColorMods(c);
|
|
336
|
-
const raw = isSrgb ? { srgb: v } : { scheme: v };
|
|
337
|
-
return resolveColor(mods.length > 0 ? {
|
|
338
|
-
...raw,
|
|
339
|
-
mods
|
|
340
|
-
} : raw);
|
|
341
|
-
}
|
|
342
315
|
function colorFromContainer(parent, resolveColor) {
|
|
343
316
|
for (const c of poChildren(parent)) {
|
|
344
317
|
const hex = resolveColorNode(c, resolveColor);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OpcPackage } from '
|
|
2
|
-
import { FontRegistry } from '
|
|
1
|
+
import { OpcPackage } from '../core/opc/index.js';
|
|
2
|
+
import { FontRegistry } from '../core/font/index.js';
|
|
3
3
|
type EmbedVariant = 'regular' | 'bold' | 'italic' | 'boldItalic';
|
|
4
4
|
interface EmbedRef {
|
|
5
5
|
readonly rId: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FontRegistry } from "
|
|
2
|
-
//#region src/
|
|
1
|
+
import { FontRegistry } from "../core/font/font-registry.js";
|
|
2
|
+
//#region src/word/font-table.ts
|
|
3
3
|
var FONT_TABLE_PART = "word/fontTable.xml";
|
|
4
4
|
var REL_FONT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/font";
|
|
5
5
|
var VARIANT_BY_TAG = {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
export type { ImageResolver, ParseContext } from './document-parser.js';
|
|
1
2
|
export { extractParagraphs } from './text-extractor.js';
|
|
2
3
|
export { parseDocument, parseBodyElements, parseSection, parseSections, parseHeaderFooter, EMPTY_SECTION, } from './document-parser.js';
|
|
3
4
|
export { parseRunProperties } from './run-properties.js';
|
|
4
5
|
export { parseParagraphProperties } from './paragraph-properties.js';
|
|
5
|
-
export { parseStyles
|
|
6
|
+
export { parseStyles } from './styles-parser.js';
|
|
6
7
|
export { parseTable } from './table-parser.js';
|
|
7
|
-
export { loadEmbeddedFonts, deobfuscateEmbeddedFont, parseFontTable
|
|
8
|
+
export { loadEmbeddedFonts, deobfuscateEmbeddedFont, parseFontTable } from './font-table.js';
|
|
8
9
|
export { parseNumbering, EMPTY_NUMBERING } from './numbering-parser.js';
|
|
9
10
|
export { parseSettings, EMPTY_SETTINGS } from './settings-parser.js';
|
|
10
11
|
export type { DocumentSettings } from './settings-parser.js';
|
|
@@ -2,7 +2,7 @@ import { asArray, asElement, getAttr } from "./xml-helpers.js";
|
|
|
2
2
|
import { parseRunProperties } from "./run-properties.js";
|
|
3
3
|
import { parseParagraphProperties } from "./paragraph-properties.js";
|
|
4
4
|
import { XMLParser } from "fast-xml-parser";
|
|
5
|
-
//#region src/
|
|
5
|
+
//#region src/word/numbering-parser.ts
|
|
6
6
|
var decoder = new TextDecoder("utf-8");
|
|
7
7
|
var parser = new XMLParser({
|
|
8
8
|
ignoreAttributes: false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MathNode } from '
|
|
2
|
-
import { PoNode } from '../
|
|
1
|
+
import { MathNode } from '../core/document-model/index.js';
|
|
2
|
+
import { PoNode } from '../core/po-helpers.js';
|
|
3
3
|
export declare function parseOMath(oMath: PoNode): MathNode;
|
|
4
4
|
export declare function childRow(parent: PoNode, tag: string): MathNode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { poChildren, poChildrenWith, poIs, poTag, poText, poToggle, poVal } from "../
|
|
2
|
-
//#region src/
|
|
1
|
+
import { poChildren, poChildrenWith, poIs, poTag, poText, poToggle, poVal } from "../core/po-helpers.js";
|
|
2
|
+
//#region src/word/omml-parser.ts
|
|
3
3
|
function parseOMath(oMath) {
|
|
4
4
|
return {
|
|
5
5
|
type: "row",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ParagraphProperties } from '
|
|
1
|
+
import { ParagraphProperties } from '../core/document-model/index.js';
|
|
2
2
|
export declare function parseParagraphProperties(pPr: unknown): ParagraphProperties;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { twipsToPt } from "../core/ir/units.js";
|
|
1
2
|
import { asElement, getAttr, getVal, parseIntAttr, parseToggle } from "./xml-helpers.js";
|
|
2
3
|
import { parseRunProperties } from "./run-properties.js";
|
|
3
|
-
//#region src/
|
|
4
|
+
//#region src/word/paragraph-properties.ts
|
|
4
5
|
var ALIGNMENTS = new Set([
|
|
5
6
|
"left",
|
|
6
7
|
"right",
|
|
@@ -31,9 +32,9 @@ function parseParagraphProperties(pPr) {
|
|
|
31
32
|
const after = parseIntAttr(node, "after");
|
|
32
33
|
const line = parseIntAttr(node, "line");
|
|
33
34
|
const lineRule = getAttr(node, "lineRule");
|
|
34
|
-
if (before !== void 0) out.
|
|
35
|
-
if (after !== void 0) out.
|
|
36
|
-
if (line !== void 0) out.
|
|
35
|
+
if (before !== void 0) out.spacingBefore = twipsToPt(before);
|
|
36
|
+
if (after !== void 0) out.spacingAfter = twipsToPt(after);
|
|
37
|
+
if (line !== void 0) out.spacingLine = twipsToPt(line);
|
|
37
38
|
if (lineRule && LINE_RULES.has(lineRule)) out.spacingLineRule = lineRule;
|
|
38
39
|
}
|
|
39
40
|
if ("w:ind" in el) {
|
|
@@ -42,10 +43,10 @@ function parseParagraphProperties(pPr) {
|
|
|
42
43
|
const right = parseIntAttr(node, "right");
|
|
43
44
|
const firstLine = parseIntAttr(node, "firstLine");
|
|
44
45
|
const hanging = parseIntAttr(node, "hanging");
|
|
45
|
-
if (left !== void 0) out.
|
|
46
|
-
if (right !== void 0) out.
|
|
47
|
-
if (firstLine !== void 0) out.
|
|
48
|
-
else if (hanging !== void 0) out.
|
|
46
|
+
if (left !== void 0) out.indentLeft = twipsToPt(left);
|
|
47
|
+
if (right !== void 0) out.indentRight = twipsToPt(right);
|
|
48
|
+
if (firstLine !== void 0) out.indentFirstLine = twipsToPt(firstLine);
|
|
49
|
+
else if (hanging !== void 0) out.indentFirstLine = twipsToPt(-hanging);
|
|
49
50
|
}
|
|
50
51
|
if ("w:pageBreakBefore" in el) {
|
|
51
52
|
const v = parseToggle(el["w:pageBreakBefore"]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PoNode } from '
|
|
1
|
+
import { PoNode } from '../core/po-helpers.js';
|
|
2
2
|
export declare function poElementToFlat(node: PoNode | undefined): Record<string, unknown>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { poChildren, poTag } from "
|
|
2
|
-
//#region src/
|
|
1
|
+
import { poChildren, poTag } from "../core/po-helpers.js";
|
|
2
|
+
//#region src/word/po-to-flat.ts
|
|
3
3
|
var ATTRS_KEY = ":@";
|
|
4
4
|
var TEXT_KEY = "#text";
|
|
5
5
|
function poElementToFlat(node) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RunProperties } from '
|
|
1
|
+
import { RunProperties } from '../core/document-model/index.js';
|
|
2
2
|
export declare function parseRunProperties(rPr: unknown): RunProperties;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { halfPtToPt } from "../core/ir/units.js";
|
|
1
2
|
import { asElement, getAttr, getVal, parseIntAttr, parseToggle } from "./xml-helpers.js";
|
|
2
|
-
//#region src/
|
|
3
|
+
//#region src/word/run-properties.ts
|
|
3
4
|
var UNDERLINE_STYLES = new Set([
|
|
4
5
|
"none",
|
|
5
6
|
"single",
|
|
@@ -42,7 +43,7 @@ function parseRunProperties(rPr) {
|
|
|
42
43
|
}
|
|
43
44
|
if ("w:sz" in el) {
|
|
44
45
|
const v = parseIntAttr(el["w:sz"], "val");
|
|
45
|
-
if (v !== void 0) out.
|
|
46
|
+
if (v !== void 0) out.fontSizePt = halfPtToPt(v);
|
|
46
47
|
}
|
|
47
48
|
if ("w:color" in el) {
|
|
48
49
|
const v = getVal(el["w:color"]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { poAttr, poChildren, poFindByPath, poIs } from "
|
|
1
|
+
import { poAttr, poChildren, poFindByPath, poIs } from "../core/po-helpers.js";
|
|
2
2
|
import { XMLParser } from "fast-xml-parser";
|
|
3
|
-
//#region src/
|
|
3
|
+
//#region src/word/settings-parser.ts
|
|
4
4
|
var decoder = new TextDecoder("utf-8");
|
|
5
5
|
var parser = new XMLParser({
|
|
6
6
|
ignoreAttributes: false,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { EMPTY_STYLE_SHEET } from "../core/style-cascade/resolver.js";
|
|
2
|
+
import "../core/style-cascade/index.js";
|
|
1
3
|
import { asArray, asElement, getAttr, getVal } from "./xml-helpers.js";
|
|
2
4
|
import { parseRunProperties } from "./run-properties.js";
|
|
3
5
|
import { parseParagraphProperties } from "./paragraph-properties.js";
|
|
4
6
|
import { XMLParser } from "fast-xml-parser";
|
|
5
|
-
//#region src/
|
|
7
|
+
//#region src/word/styles-parser.ts
|
|
6
8
|
var decoder = new TextDecoder("utf-8");
|
|
7
9
|
var parser = new XMLParser({
|
|
8
10
|
ignoreAttributes: false,
|
|
@@ -18,11 +20,6 @@ var STYLE_TYPES = new Set([
|
|
|
18
20
|
"table",
|
|
19
21
|
"numbering"
|
|
20
22
|
]);
|
|
21
|
-
var EMPTY_STYLE_SHEET = {
|
|
22
|
-
defaultRunProperties: {},
|
|
23
|
-
defaultParagraphProperties: {},
|
|
24
|
-
styles: /* @__PURE__ */ new Map()
|
|
25
|
-
};
|
|
26
23
|
function parseStyles(stylesXml) {
|
|
27
24
|
const xml = decoder.decode(stylesXml);
|
|
28
25
|
const root = asElement(parser.parse(xml)["w:styles"]);
|
|
@@ -64,4 +61,4 @@ function parseStyles(stylesXml) {
|
|
|
64
61
|
};
|
|
65
62
|
}
|
|
66
63
|
//#endregion
|
|
67
|
-
export {
|
|
64
|
+
export { parseStyles };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { eighthPtToPt, twipsToPt } from "../core/ir/units.js";
|
|
2
|
+
import { poAttr, poChildren, poChildrenWith, poFirstChild, poIntAttr, poToggle, poVal } from "../core/po-helpers.js";
|
|
3
|
+
import { DEFAULT_PARSE_CONTEXT, parseBodyElements } from "./document-parser.js";
|
|
4
|
+
//#region src/word/table-parser.ts
|
|
4
5
|
var BORDER_STYLES = new Set([
|
|
5
6
|
"none",
|
|
6
7
|
"single",
|
|
@@ -20,17 +21,62 @@ var HEIGHT_RULES = new Set([
|
|
|
20
21
|
"atLeast",
|
|
21
22
|
"exact"
|
|
22
23
|
]);
|
|
23
|
-
function parseTable(tbl) {
|
|
24
|
+
function parseTable(tbl, ctx = DEFAULT_PARSE_CONTEXT) {
|
|
24
25
|
const properties = parseTableProperties(poFirstChild(tbl, "w:tblPr"));
|
|
25
26
|
const grid = parseTableGrid(poFirstChild(tbl, "w:tblGrid"));
|
|
26
|
-
const
|
|
27
|
-
for (const tr of poChildrenWith(tbl, "w:tr"))
|
|
27
|
+
const draftRows = [];
|
|
28
|
+
for (const tr of poChildrenWith(tbl, "w:tr")) draftRows.push(parseTableRow(tr, ctx));
|
|
29
|
+
const roles = resolveMergeRoles(draftRows.map((r) => r.cells));
|
|
28
30
|
return {
|
|
29
31
|
properties,
|
|
30
32
|
grid,
|
|
31
|
-
rows
|
|
33
|
+
rows: draftRows.map((draft, rowIdx) => ({
|
|
34
|
+
properties: draft.properties,
|
|
35
|
+
cells: draft.cells.map((d, cellIdx) => {
|
|
36
|
+
const merge = roles[rowIdx][cellIdx];
|
|
37
|
+
return merge ? {
|
|
38
|
+
...d.cell,
|
|
39
|
+
properties: {
|
|
40
|
+
...d.cell.properties,
|
|
41
|
+
merge
|
|
42
|
+
}
|
|
43
|
+
} : d.cell;
|
|
44
|
+
})
|
|
45
|
+
}))
|
|
32
46
|
};
|
|
33
47
|
}
|
|
48
|
+
function resolveMergeRoles(rows) {
|
|
49
|
+
const out = rows.map((r) => new Array(r.length).fill(void 0));
|
|
50
|
+
const colSlots = /* @__PURE__ */ new Map();
|
|
51
|
+
for (let rowIdx = 0; rowIdx < rows.length; rowIdx++) {
|
|
52
|
+
const row = rows[rowIdx];
|
|
53
|
+
let colIdx = 0;
|
|
54
|
+
for (let cellIdx = 0; cellIdx < row.length; cellIdx++) {
|
|
55
|
+
const d = row[cellIdx];
|
|
56
|
+
let arr = colSlots.get(colIdx);
|
|
57
|
+
if (!arr) {
|
|
58
|
+
arr = [];
|
|
59
|
+
colSlots.set(colIdx, arr);
|
|
60
|
+
}
|
|
61
|
+
arr.push({
|
|
62
|
+
rowIdx,
|
|
63
|
+
cellIdx,
|
|
64
|
+
vMerge: d.vMerge
|
|
65
|
+
});
|
|
66
|
+
colIdx += Math.max(1, d.cell.properties.colSpan ?? 1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const slots of colSlots.values()) for (let i = 0; i < slots.length; i++) {
|
|
70
|
+
const cur = slots[i];
|
|
71
|
+
const next = slots[i + 1];
|
|
72
|
+
const nextIsContinue = !!next && next.vMerge === "continue";
|
|
73
|
+
let role;
|
|
74
|
+
if (cur.vMerge === "restart") role = nextIsContinue ? "start" : void 0;
|
|
75
|
+
else if (cur.vMerge === "continue") role = nextIsContinue ? "middle" : "end";
|
|
76
|
+
out[cur.rowIdx][cur.cellIdx] = role;
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
34
80
|
function parseTableProperties(tblPr) {
|
|
35
81
|
if (!tblPr) return {};
|
|
36
82
|
const out = {};
|
|
@@ -38,7 +84,8 @@ function parseTableProperties(tblPr) {
|
|
|
38
84
|
if (tblW) {
|
|
39
85
|
const w = poIntAttr(tblW, "w");
|
|
40
86
|
const type = poAttr(tblW, "type");
|
|
41
|
-
if (w !== void 0) out.
|
|
87
|
+
if (w !== void 0 && type === "pct") out.widthFraction = w / 5e3;
|
|
88
|
+
else if (w !== void 0) out.widthPt = twipsToPt(w);
|
|
42
89
|
if (type && WIDTH_TYPES.has(type)) out.widthType = type;
|
|
43
90
|
}
|
|
44
91
|
const tblLayout = poFirstChild(tblPr, "w:tblLayout");
|
|
@@ -57,14 +104,14 @@ function parseTableGrid(tblGrid) {
|
|
|
57
104
|
const cols = [];
|
|
58
105
|
for (const gridCol of poChildrenWith(tblGrid, "w:gridCol")) {
|
|
59
106
|
const w = poIntAttr(gridCol, "w");
|
|
60
|
-
cols.push(w ?? 0);
|
|
107
|
+
cols.push(twipsToPt(w ?? 0));
|
|
61
108
|
}
|
|
62
109
|
return cols;
|
|
63
110
|
}
|
|
64
|
-
function parseTableRow(tr) {
|
|
111
|
+
function parseTableRow(tr, ctx) {
|
|
65
112
|
const properties = parseRowProperties(poFirstChild(tr, "w:trPr"));
|
|
66
113
|
const cells = [];
|
|
67
|
-
for (const tc of poChildrenWith(tr, "w:tc")) cells.push(parseTableCell(tc));
|
|
114
|
+
for (const tc of poChildrenWith(tr, "w:tc")) cells.push(parseTableCell(tc, ctx));
|
|
68
115
|
return {
|
|
69
116
|
properties,
|
|
70
117
|
cells
|
|
@@ -77,35 +124,39 @@ function parseRowProperties(trPr) {
|
|
|
77
124
|
if (trHeight) {
|
|
78
125
|
const val = poIntAttr(trHeight, "val");
|
|
79
126
|
const rule = poAttr(trHeight, "hRule");
|
|
80
|
-
if (val !== void 0) out.
|
|
127
|
+
if (val !== void 0) out.height = twipsToPt(val);
|
|
81
128
|
if (rule && HEIGHT_RULES.has(rule)) out.heightRule = rule;
|
|
82
129
|
}
|
|
83
130
|
if (poFirstChild(trPr, "w:cantSplit")) out.cantSplit = poToggle(poFirstChild(trPr, "w:cantSplit")) ?? true;
|
|
84
131
|
if (poFirstChild(trPr, "w:tblHeader")) out.isHeader = poToggle(poFirstChild(trPr, "w:tblHeader")) ?? true;
|
|
85
132
|
return out;
|
|
86
133
|
}
|
|
87
|
-
function parseTableCell(tc) {
|
|
134
|
+
function parseTableCell(tc, ctx) {
|
|
135
|
+
const { properties, vMerge } = parseCellProperties(poFirstChild(tc, "w:tcPr"));
|
|
88
136
|
return {
|
|
89
|
-
|
|
90
|
-
|
|
137
|
+
cell: {
|
|
138
|
+
properties,
|
|
139
|
+
content: parseBodyElements(poChildren(tc), ctx)
|
|
140
|
+
},
|
|
141
|
+
...vMerge ? { vMerge } : {}
|
|
91
142
|
};
|
|
92
143
|
}
|
|
93
144
|
function parseCellProperties(tcPr) {
|
|
94
|
-
if (!tcPr) return {};
|
|
145
|
+
if (!tcPr) return { properties: {} };
|
|
95
146
|
const out = {};
|
|
147
|
+
let rawVMerge;
|
|
96
148
|
const tcW = poFirstChild(tcPr, "w:tcW");
|
|
97
149
|
if (tcW) {
|
|
98
150
|
const w = poIntAttr(tcW, "w");
|
|
99
|
-
if (w !== void 0) out.
|
|
151
|
+
if (w !== void 0) out.width = twipsToPt(w);
|
|
100
152
|
}
|
|
101
153
|
const gridSpan = poFirstChild(tcPr, "w:gridSpan");
|
|
102
154
|
if (gridSpan) {
|
|
103
155
|
const v = poIntAttr(gridSpan, "val");
|
|
104
|
-
if (v !== void 0) out.
|
|
156
|
+
if (v !== void 0) out.colSpan = v;
|
|
105
157
|
}
|
|
106
158
|
const vMerge = poFirstChild(tcPr, "w:vMerge");
|
|
107
|
-
if (vMerge)
|
|
108
|
-
else out.vMerge = "continue";
|
|
159
|
+
if (vMerge) rawVMerge = poVal(vMerge) === "restart" ? "restart" : "continue";
|
|
109
160
|
const borders = parseBorders(poFirstChild(tcPr, "w:tcBorders"));
|
|
110
161
|
if (borders) out.borders = borders;
|
|
111
162
|
const margins = parseCellMargins(poFirstChild(tcPr, "w:tcMar"));
|
|
@@ -115,7 +166,10 @@ function parseCellProperties(tcPr) {
|
|
|
115
166
|
const fill = poAttr(shd, "fill");
|
|
116
167
|
if (fill && fill !== "auto" && /^[0-9A-Fa-f]{6}$/.test(fill)) out.shading = { colorHex: fill.toUpperCase() };
|
|
117
168
|
}
|
|
118
|
-
return
|
|
169
|
+
return {
|
|
170
|
+
properties: out,
|
|
171
|
+
...rawVMerge ? { vMerge: rawVMerge } : {}
|
|
172
|
+
};
|
|
119
173
|
}
|
|
120
174
|
function parseBorders(node) {
|
|
121
175
|
if (!node) return void 0;
|
|
@@ -141,7 +195,7 @@ function parseBorder(node) {
|
|
|
141
195
|
const sz = poIntAttr(node, "sz");
|
|
142
196
|
const color = poAttr(node, "color");
|
|
143
197
|
const out = { style: val };
|
|
144
|
-
if (sz !== void 0) out.
|
|
198
|
+
if (sz !== void 0) out.width = eighthPtToPt(sz);
|
|
145
199
|
if (color && color !== "auto" && /^[0-9A-Fa-f]{6}$/.test(color)) out.colorHex = color.toUpperCase();
|
|
146
200
|
return out;
|
|
147
201
|
}
|
|
@@ -152,10 +206,10 @@ function parseCellMargins(node) {
|
|
|
152
206
|
const bottom = poIntAttr(poFirstChild(node, "w:bottom"), "w");
|
|
153
207
|
const left = poIntAttr(poFirstChild(node, "w:left") ?? poFirstChild(node, "w:start"), "w");
|
|
154
208
|
const right = poIntAttr(poFirstChild(node, "w:right") ?? poFirstChild(node, "w:end"), "w");
|
|
155
|
-
if (top !== void 0) out.
|
|
156
|
-
if (bottom !== void 0) out.
|
|
157
|
-
if (left !== void 0) out.
|
|
158
|
-
if (right !== void 0) out.
|
|
209
|
+
if (top !== void 0) out.top = twipsToPt(top);
|
|
210
|
+
if (bottom !== void 0) out.bottom = twipsToPt(bottom);
|
|
211
|
+
if (left !== void 0) out.left = twipsToPt(left);
|
|
212
|
+
if (right !== void 0) out.right = twipsToPt(right);
|
|
159
213
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
160
214
|
}
|
|
161
215
|
//#endregion
|