reamkit 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +95 -0
- package/dist/esm/bidi/algorithm.d.ts +9 -0
- package/dist/esm/bidi/algorithm.js +458 -0
- package/dist/esm/bidi/char-types.d.ts +2 -0
- package/dist/esm/bidi/char-types.js +439 -0
- package/dist/esm/bidi/index.d.ts +14 -0
- package/dist/esm/bidi/index.js +25 -0
- package/dist/esm/converter/docx-to-pdf.d.ts +15 -0
- package/dist/esm/converter/docx-to-pdf.js +227 -0
- package/dist/esm/converter/index.d.ts +4 -0
- package/dist/esm/converter/index.js +2 -0
- package/dist/esm/converter/xlsx-to-pdf.d.ts +13 -0
- package/dist/esm/converter/xlsx-to-pdf.js +515 -0
- package/dist/esm/crypto/asn1.d.ts +23 -0
- package/dist/esm/crypto/asn1.js +123 -0
- package/dist/esm/crypto/cms.d.ts +9 -0
- package/dist/esm/crypto/cms.js +34 -0
- package/dist/esm/crypto/index.d.ts +2 -0
- package/dist/esm/crypto/index.js +1 -0
- package/dist/esm/document-model/index.d.ts +1 -0
- package/dist/esm/document-model/index.js +0 -0
- package/dist/esm/document-model/types.d.ts +403 -0
- package/dist/esm/font/arabic-joining.d.ts +4 -0
- package/dist/esm/font/arabic-joining.js +97 -0
- package/dist/esm/font/binary-reader.d.ts +13 -0
- package/dist/esm/font/binary-reader.js +44 -0
- package/dist/esm/font/font-registry.d.ts +19 -0
- package/dist/esm/font/font-registry.js +39 -0
- package/dist/esm/font/index.d.ts +7 -0
- package/dist/esm/font/opentype-layout.d.ts +21 -0
- package/dist/esm/font/opentype-layout.js +329 -0
- package/dist/esm/font/ttf-parser.d.ts +29 -0
- package/dist/esm/font/ttf-parser.js +290 -0
- package/dist/esm/font/ttf-subset.d.ts +3 -0
- package/dist/esm/font/ttf-subset.js +201 -0
- package/dist/esm/fonts/index.d.ts +2 -0
- package/dist/esm/fonts/remote-fonts.d.ts +13 -0
- package/dist/esm/fonts/remote-fonts.js +94 -0
- package/dist/esm/hyphenation/index.d.ts +10 -0
- package/dist/esm/hyphenation/index.js +38 -0
- package/dist/esm/hyphenation/liang.d.ts +10 -0
- package/dist/esm/hyphenation/liang.js +79 -0
- package/dist/esm/hyphenation/patterns-en-us.d.ts +2 -0
- package/dist/esm/hyphenation/patterns-en-us.js +5 -0
- package/dist/esm/hyphenation/patterns-ru.d.ts +2 -0
- package/dist/esm/hyphenation/patterns-ru.js +5 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/line-breaker/index.d.ts +2 -0
- package/dist/esm/line-breaker/knuth-plass.d.ts +30 -0
- package/dist/esm/line-breaker/knuth-plass.js +172 -0
- package/dist/esm/numbering/index.d.ts +1 -0
- package/dist/esm/numbering/state.d.ts +6 -0
- package/dist/esm/numbering/state.js +83 -0
- package/dist/esm/ooxml/drawingml/chart-parser.d.ts +3 -0
- package/dist/esm/ooxml/drawingml/chart-parser.js +218 -0
- package/dist/esm/ooxml/drawingml/colors.d.ts +17 -0
- package/dist/esm/ooxml/drawingml/colors.js +125 -0
- package/dist/esm/ooxml/drawingml/theme-parser.d.ts +1 -0
- package/dist/esm/ooxml/drawingml/theme-parser.js +55 -0
- package/dist/esm/ooxml/index.d.ts +1 -0
- package/dist/esm/ooxml/math/omml-parser.d.ts +4 -0
- package/dist/esm/ooxml/math/omml-parser.js +217 -0
- package/dist/esm/ooxml/spreadsheet/cell-reference.d.ts +6 -0
- package/dist/esm/ooxml/spreadsheet/cell-reference.js +26 -0
- package/dist/esm/ooxml/spreadsheet/defined-name-ref.d.ts +11 -0
- package/dist/esm/ooxml/spreadsheet/defined-name-ref.js +64 -0
- package/dist/esm/ooxml/spreadsheet/index.d.ts +12 -0
- package/dist/esm/ooxml/spreadsheet/index.js +7 -0
- package/dist/esm/ooxml/spreadsheet/number-format.d.ts +1 -0
- package/dist/esm/ooxml/spreadsheet/number-format.js +438 -0
- package/dist/esm/ooxml/spreadsheet/shared-strings-parser.d.ts +1 -0
- package/dist/esm/ooxml/spreadsheet/shared-strings-parser.js +47 -0
- package/dist/esm/ooxml/spreadsheet/styles-parser.d.ts +52 -0
- package/dist/esm/ooxml/spreadsheet/styles-parser.js +225 -0
- package/dist/esm/ooxml/spreadsheet/workbook-parser.d.ts +16 -0
- package/dist/esm/ooxml/spreadsheet/workbook-parser.js +90 -0
- package/dist/esm/ooxml/spreadsheet/worksheet-parser.d.ts +60 -0
- package/dist/esm/ooxml/spreadsheet/worksheet-parser.js +311 -0
- package/dist/esm/ooxml/wordproc/document-parser.d.ts +9 -0
- package/dist/esm/ooxml/wordproc/document-parser.js +274 -0
- package/dist/esm/ooxml/wordproc/drawing-parser.d.ts +33 -0
- package/dist/esm/ooxml/wordproc/drawing-parser.js +374 -0
- package/dist/esm/ooxml/wordproc/font-table.d.ts +15 -0
- package/dist/esm/ooxml/wordproc/font-table.js +82 -0
- package/dist/esm/ooxml/wordproc/index.d.ts +10 -0
- package/dist/esm/ooxml/wordproc/index.js +9 -0
- package/dist/esm/ooxml/wordproc/numbering-parser.d.ts +3 -0
- package/dist/esm/ooxml/wordproc/numbering-parser.js +89 -0
- package/dist/esm/ooxml/wordproc/paragraph-properties.d.ts +2 -0
- package/dist/esm/ooxml/wordproc/paragraph-properties.js +85 -0
- package/dist/esm/ooxml/wordproc/po-helpers.d.ts +14 -0
- package/dist/esm/ooxml/wordproc/po-helpers.js +76 -0
- package/dist/esm/ooxml/wordproc/po-to-flat.d.ts +2 -0
- package/dist/esm/ooxml/wordproc/po-to-flat.js +28 -0
- package/dist/esm/ooxml/wordproc/run-properties.d.ts +2 -0
- package/dist/esm/ooxml/wordproc/run-properties.js +82 -0
- package/dist/esm/ooxml/wordproc/settings-parser.d.ts +5 -0
- package/dist/esm/ooxml/wordproc/settings-parser.js +26 -0
- package/dist/esm/ooxml/wordproc/styles-parser.d.ts +3 -0
- package/dist/esm/ooxml/wordproc/styles-parser.js +67 -0
- package/dist/esm/ooxml/wordproc/table-parser.d.ts +3 -0
- package/dist/esm/ooxml/wordproc/table-parser.js +162 -0
- package/dist/esm/ooxml/wordproc/text-extractor.d.ts +1 -0
- package/dist/esm/ooxml/wordproc/text-extractor.js +1 -0
- package/dist/esm/ooxml/wordproc/xml-helpers.d.ts +9 -0
- package/dist/esm/ooxml/wordproc/xml-helpers.js +36 -0
- package/dist/esm/opc/core-properties.d.ts +11 -0
- package/dist/esm/opc/core-properties.js +51 -0
- package/dist/esm/opc/index.d.ts +5 -0
- package/dist/esm/opc/index.js +3 -0
- package/dist/esm/opc/package.d.ts +26 -0
- package/dist/esm/opc/package.js +113 -0
- package/dist/esm/opc/relationship-types.d.ts +3 -0
- package/dist/esm/opc/relationship-types.js +4 -0
- package/dist/esm/opc/relationships.d.ts +7 -0
- package/dist/esm/opc/relationships.js +28 -0
- package/dist/esm/pdf/arc-to-bezier.d.ts +5 -0
- package/dist/esm/pdf/arc-to-bezier.js +58 -0
- package/dist/esm/pdf/builtin-fonts.d.ts +2 -0
- package/dist/esm/pdf/chart-geometry.d.ts +64 -0
- package/dist/esm/pdf/chart-geometry.js +674 -0
- package/dist/esm/pdf/cid-font.d.ts +15 -0
- package/dist/esm/pdf/cid-font.js +174 -0
- package/dist/esm/pdf/embedded-file.d.ts +11 -0
- package/dist/esm/pdf/embedded-file.js +23 -0
- package/dist/esm/pdf/icc-profile.d.ts +1 -0
- package/dist/esm/pdf/icc-profile.js +166 -0
- package/dist/esm/pdf/image-xobject.d.ts +13 -0
- package/dist/esm/pdf/image-xobject.js +335 -0
- package/dist/esm/pdf/index.d.ts +11 -0
- package/dist/esm/pdf/index.js +5 -0
- package/dist/esm/pdf/math-layout.d.ts +45 -0
- package/dist/esm/pdf/math-layout.js +1138 -0
- package/dist/esm/pdf/objects.d.ts +32 -0
- package/dist/esm/pdf/objects.js +54 -0
- package/dist/esm/pdf/preset-geometry.d.ts +6 -0
- package/dist/esm/pdf/preset-geometry.js +199 -0
- package/dist/esm/pdf/serialize.d.ts +3 -0
- package/dist/esm/pdf/serialize.js +54 -0
- package/dist/esm/pdf/signature.d.ts +25 -0
- package/dist/esm/pdf/signature.js +126 -0
- package/dist/esm/pdf/struct-tree.d.ts +31 -0
- package/dist/esm/pdf/struct-tree.js +109 -0
- package/dist/esm/pdf/styled-page-renderer.d.ts +43 -0
- package/dist/esm/pdf/styled-page-renderer.js +2317 -0
- package/dist/esm/pdf/text-encoding.d.ts +2 -0
- package/dist/esm/pdf/text-page-renderer.d.ts +16 -0
- package/dist/esm/pdf/text-page-renderer.js +4 -0
- package/dist/esm/pdf/vector-graphics.d.ts +46 -0
- package/dist/esm/pdf/vector-graphics.js +103 -0
- package/dist/esm/pdf/writer.d.ts +10 -0
- package/dist/esm/pdf/writer.js +81 -0
- package/dist/esm/pdf/xmp.d.ts +13 -0
- package/dist/esm/pdf/xmp.js +38 -0
- package/dist/esm/style-cascade/index.d.ts +3 -0
- package/dist/esm/style-cascade/resolver.d.ts +4 -0
- package/dist/esm/style-cascade/resolver.js +96 -0
- package/dist/esm/style-cascade/types.d.ts +29 -0
- package/dist/esm/style-cascade/types.js +26 -0
- package/package.json +90 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BodyElement, Section, SectionProperties } from '../../document-model/index.js';
|
|
2
|
+
import { ColorResolver } from '../drawingml/colors.js';
|
|
3
|
+
import { PoNode } from './po-helpers.js';
|
|
4
|
+
export declare function parseDocument(documentXml: Uint8Array, resolveColor?: ColorResolver): Array<BodyElement>;
|
|
5
|
+
export declare const EMPTY_SECTION: SectionProperties;
|
|
6
|
+
export declare function parseSection(documentXml: Uint8Array): SectionProperties;
|
|
7
|
+
export declare function parseSections(documentXml: Uint8Array): Array<Section>;
|
|
8
|
+
export declare function parseHeaderFooter(xml: Uint8Array, resolveColor?: ColorResolver): Array<BodyElement>;
|
|
9
|
+
export declare function parseBodyElements(children: ReadonlyArray<PoNode>, resolveColor?: ColorResolver): Array<BodyElement>;
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { poAttr, poChildren, poFindByPath, poIntAttr, poIs, poText } from "./po-helpers.js";
|
|
2
|
+
import { defaultColorResolver } from "../drawingml/colors.js";
|
|
3
|
+
import { parseOMath } from "../math/omml-parser.js";
|
|
4
|
+
import { expandMcChildren, parseDrawing } from "./drawing-parser.js";
|
|
5
|
+
import { parseRunProperties } from "./run-properties.js";
|
|
6
|
+
import { parseParagraphProperties } from "./paragraph-properties.js";
|
|
7
|
+
import { poElementToFlat } from "./po-to-flat.js";
|
|
8
|
+
import { parseTable } from "./table-parser.js";
|
|
9
|
+
import { XMLParser } from "fast-xml-parser";
|
|
10
|
+
//#region src/ooxml/wordproc/document-parser.ts
|
|
11
|
+
var decoder = new TextDecoder("utf-8");
|
|
12
|
+
var parser = new XMLParser({
|
|
13
|
+
ignoreAttributes: false,
|
|
14
|
+
attributeNamePrefix: "@_",
|
|
15
|
+
preserveOrder: true,
|
|
16
|
+
parseAttributeValue: false,
|
|
17
|
+
parseTagValue: false,
|
|
18
|
+
trimValues: false
|
|
19
|
+
});
|
|
20
|
+
var RUN_CONTAINER_TAGS = new Set([
|
|
21
|
+
"w:hyperlink",
|
|
22
|
+
"w:sdt",
|
|
23
|
+
"w:sdtContent",
|
|
24
|
+
"w:smartTag",
|
|
25
|
+
"w:fldSimple",
|
|
26
|
+
"w:ins",
|
|
27
|
+
"w:moveTo"
|
|
28
|
+
]);
|
|
29
|
+
function parseDocument(documentXml, resolveColor = defaultColorResolver) {
|
|
30
|
+
const xml = decoder.decode(documentXml);
|
|
31
|
+
const body = poFindByPath(parser.parse(xml), ["w:document", "w:body"]);
|
|
32
|
+
if (!body) return [];
|
|
33
|
+
return parseBodyElements(poChildren(body), resolveColor);
|
|
34
|
+
}
|
|
35
|
+
var HF_TYPES = new Set([
|
|
36
|
+
"default",
|
|
37
|
+
"first",
|
|
38
|
+
"even"
|
|
39
|
+
]);
|
|
40
|
+
var EMPTY_SECTION = {
|
|
41
|
+
headers: [],
|
|
42
|
+
footers: []
|
|
43
|
+
};
|
|
44
|
+
function parseSections(documentXml) {
|
|
45
|
+
const xml = decoder.decode(documentXml);
|
|
46
|
+
const body = poFindByPath(parser.parse(xml), ["w:document", "w:body"]);
|
|
47
|
+
if (!body) return [];
|
|
48
|
+
const children = poChildren(body);
|
|
49
|
+
const sections = [];
|
|
50
|
+
let bodyIdx = 0;
|
|
51
|
+
for (const child of children) {
|
|
52
|
+
if (poIs(child, "w:sectPr")) {
|
|
53
|
+
sections.push({
|
|
54
|
+
properties: parseSectPrNode(child),
|
|
55
|
+
endIndex: bodyIdx
|
|
56
|
+
});
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (poIs(child, "w:p")) {
|
|
60
|
+
const pPrNode = poChildren(child).find((c) => poIs(c, "w:pPr"));
|
|
61
|
+
const sectPrInPPr = pPrNode ? poChildren(pPrNode).find((c) => poIs(c, "w:sectPr")) : void 0;
|
|
62
|
+
bodyIdx++;
|
|
63
|
+
if (sectPrInPPr) sections.push({
|
|
64
|
+
properties: parseSectPrNode(sectPrInPPr),
|
|
65
|
+
endIndex: bodyIdx
|
|
66
|
+
});
|
|
67
|
+
} else if (poIs(child, "w:tbl")) bodyIdx++;
|
|
68
|
+
}
|
|
69
|
+
if (sections.length === 0 || sections[sections.length - 1].endIndex < bodyIdx) sections.push({
|
|
70
|
+
properties: EMPTY_SECTION,
|
|
71
|
+
endIndex: bodyIdx
|
|
72
|
+
});
|
|
73
|
+
return sections;
|
|
74
|
+
}
|
|
75
|
+
function parseSectPrNode(sectPr) {
|
|
76
|
+
let pageSize;
|
|
77
|
+
let margins;
|
|
78
|
+
let titlePg = false;
|
|
79
|
+
const headers = [];
|
|
80
|
+
const footers = [];
|
|
81
|
+
for (const child of poChildren(sectPr)) if (poIs(child, "w:pgSz")) {
|
|
82
|
+
const w = poIntAttr(child, "w");
|
|
83
|
+
const h = poIntAttr(child, "h");
|
|
84
|
+
const orientRaw = poAttr(child, "orient");
|
|
85
|
+
if (w !== void 0 && h !== void 0) pageSize = {
|
|
86
|
+
widthTwips: w,
|
|
87
|
+
heightTwips: h,
|
|
88
|
+
...orientRaw === "portrait" || orientRaw === "landscape" ? { orientation: orientRaw } : {}
|
|
89
|
+
};
|
|
90
|
+
} else if (poIs(child, "w:pgMar")) {
|
|
91
|
+
const top = poIntAttr(child, "top");
|
|
92
|
+
const right = poIntAttr(child, "right");
|
|
93
|
+
const bottom = poIntAttr(child, "bottom");
|
|
94
|
+
const left = poIntAttr(child, "left");
|
|
95
|
+
const header = poIntAttr(child, "header");
|
|
96
|
+
const footer = poIntAttr(child, "footer");
|
|
97
|
+
margins = {
|
|
98
|
+
topTwips: top ?? 1440,
|
|
99
|
+
rightTwips: right ?? 1440,
|
|
100
|
+
bottomTwips: bottom ?? 1440,
|
|
101
|
+
leftTwips: left ?? 1440,
|
|
102
|
+
...header !== void 0 ? { headerTwips: header } : {},
|
|
103
|
+
...footer !== void 0 ? { footerTwips: footer } : {}
|
|
104
|
+
};
|
|
105
|
+
} else if (poIs(child, "w:headerReference")) pushHeaderFooter(child, headers);
|
|
106
|
+
else if (poIs(child, "w:footerReference")) pushHeaderFooter(child, footers);
|
|
107
|
+
else if (poIs(child, "w:titlePg")) {
|
|
108
|
+
const val = poAttr(child, "val");
|
|
109
|
+
titlePg = val === void 0 || val === "" || val !== "0" && val !== "false";
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
...pageSize ? { pageSize } : {},
|
|
113
|
+
...margins ? { margins } : {},
|
|
114
|
+
headers,
|
|
115
|
+
footers,
|
|
116
|
+
...titlePg ? { titlePg: true } : {}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function pushHeaderFooter(node, list) {
|
|
120
|
+
const rId = poAttr(node, "id");
|
|
121
|
+
if (!rId) return;
|
|
122
|
+
const typeRaw = poAttr(node, "type") ?? "default";
|
|
123
|
+
const type = HF_TYPES.has(typeRaw) ? typeRaw : "default";
|
|
124
|
+
list.push({
|
|
125
|
+
type,
|
|
126
|
+
relationshipId: rId
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function parseHeaderFooter(xml, resolveColor = defaultColorResolver) {
|
|
130
|
+
const root = parser.parse(decoder.decode(xml)).find((n) => poIs(n, "w:hdr") || poIs(n, "w:ftr"));
|
|
131
|
+
if (!root) return [];
|
|
132
|
+
return parseBodyElements(poChildren(root), resolveColor);
|
|
133
|
+
}
|
|
134
|
+
function parseBodyElements(children, resolveColor = defaultColorResolver) {
|
|
135
|
+
const out = [];
|
|
136
|
+
for (const child of children) if (poIs(child, "w:p")) {
|
|
137
|
+
const drawing = tryExtractDrawingFromParagraph(child, resolveColor);
|
|
138
|
+
out.push(drawing ?? {
|
|
139
|
+
kind: "paragraph",
|
|
140
|
+
paragraph: parseParagraph(child)
|
|
141
|
+
});
|
|
142
|
+
} else if (poIs(child, "w:tbl")) out.push({
|
|
143
|
+
kind: "table",
|
|
144
|
+
table: parseTable(child)
|
|
145
|
+
});
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
function tryExtractDrawingFromParagraph(p, resolveColor) {
|
|
149
|
+
let drawing;
|
|
150
|
+
let hasText = false;
|
|
151
|
+
for (const child of poChildren(p)) {
|
|
152
|
+
if (!poIs(child, "w:r")) continue;
|
|
153
|
+
for (const runChild of expandMcChildren(poChildren(child))) if (poIs(runChild, "w:drawing")) {
|
|
154
|
+
if (!drawing) drawing = runChild;
|
|
155
|
+
} else if (poIs(runChild, "w:t") && poText(runChild).length > 0) hasText = true;
|
|
156
|
+
else if (poIs(runChild, "w:tab") || poIs(runChild, "w:br") || poIs(runChild, "w:noBreakHyphen")) hasText = true;
|
|
157
|
+
}
|
|
158
|
+
if (!drawing || hasText) return null;
|
|
159
|
+
const parseBody = (children) => parseBodyElements(children, resolveColor);
|
|
160
|
+
const content = parseDrawing(drawing, resolveColor, parseBody);
|
|
161
|
+
if (!content) return null;
|
|
162
|
+
const pPrNode = poChildren(p).find((c) => poIs(c, "w:pPr"));
|
|
163
|
+
const paragraphProperties = pPrNode ? parseParagraphProperties(poElementToFlat(pPrNode)) : {};
|
|
164
|
+
if (content.kind === "image") return {
|
|
165
|
+
kind: "image",
|
|
166
|
+
image: {
|
|
167
|
+
imageId: content.imageId,
|
|
168
|
+
widthEmu: content.widthEmu,
|
|
169
|
+
heightEmu: content.heightEmu,
|
|
170
|
+
paragraphProperties,
|
|
171
|
+
...content.altText ? { altText: content.altText } : {}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
if (content.kind === "chart") return {
|
|
175
|
+
kind: "chart",
|
|
176
|
+
chart: {
|
|
177
|
+
chartRelId: content.chartRelId,
|
|
178
|
+
widthEmu: content.widthEmu,
|
|
179
|
+
heightEmu: content.heightEmu,
|
|
180
|
+
paragraphProperties,
|
|
181
|
+
...content.altText ? { altText: content.altText } : {}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
kind: "shape",
|
|
186
|
+
shape: {
|
|
187
|
+
...content.data,
|
|
188
|
+
paragraphProperties,
|
|
189
|
+
...content.altText ? { altText: content.altText } : {}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function parseParagraph(p) {
|
|
194
|
+
const pPr = poChildren(p).find((c) => poIs(c, "w:pPr"));
|
|
195
|
+
let properties = parseParagraphProperties(pPr ? poElementToFlat(pPr) : void 0);
|
|
196
|
+
const mathPara = poChildren(p).find((c) => poIs(c, "m:oMathPara"));
|
|
197
|
+
if (mathPara && properties.alignment === void 0) {
|
|
198
|
+
const paraPr = poChildren(mathPara).find((c) => poIs(c, "m:oMathParaPr"));
|
|
199
|
+
const jcVal = poAttr(paraPr ? poChildren(paraPr).find((c) => poIs(c, "m:jc")) : void 0, "val");
|
|
200
|
+
const alignment = jcVal === "left" ? "left" : jcVal === "right" ? "right" : "center";
|
|
201
|
+
properties = {
|
|
202
|
+
...properties,
|
|
203
|
+
alignment
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const runs = [];
|
|
207
|
+
collectRuns(p, runs);
|
|
208
|
+
return {
|
|
209
|
+
properties,
|
|
210
|
+
runs
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function collectRuns(container, out) {
|
|
214
|
+
for (const child of poChildren(container)) {
|
|
215
|
+
if (poIs(child, "w:pPr")) continue;
|
|
216
|
+
if (poIs(child, "w:r")) {
|
|
217
|
+
out.push(parseRun(child));
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (poIs(child, "m:oMath")) {
|
|
221
|
+
out.push({
|
|
222
|
+
text: "",
|
|
223
|
+
properties: {},
|
|
224
|
+
math: parseOMath(child)
|
|
225
|
+
});
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (poIs(child, "m:oMathPara")) {
|
|
229
|
+
for (const om of poChildren(child)) if (poIs(om, "m:oMath")) out.push({
|
|
230
|
+
text: "",
|
|
231
|
+
properties: {},
|
|
232
|
+
math: parseOMath(om)
|
|
233
|
+
});
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
const tag = elementTag(child);
|
|
237
|
+
if (tag && RUN_CONTAINER_TAGS.has(tag)) collectRuns(child, out);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function parseRun(r) {
|
|
241
|
+
const rPr = poChildren(r).find((c) => poIs(c, "w:rPr"));
|
|
242
|
+
const properties = parseRunProperties(rPr ? poElementToFlat(rPr) : void 0);
|
|
243
|
+
let text = "";
|
|
244
|
+
let pageBreak = false;
|
|
245
|
+
let inlineImage;
|
|
246
|
+
for (const child of expandMcChildren(poChildren(r))) {
|
|
247
|
+
if (poIs(child, "w:rPr")) continue;
|
|
248
|
+
if (poIs(child, "w:t")) text += poText(child);
|
|
249
|
+
else if (poIs(child, "w:tab")) text += " ";
|
|
250
|
+
else if (poIs(child, "w:br")) if (poAttr(child, "type") === "page") pageBreak = true;
|
|
251
|
+
else text += "\n";
|
|
252
|
+
else if (poIs(child, "w:noBreakHyphen")) text += "‑";
|
|
253
|
+
else if (poIs(child, "w:softHyphen")) text += "";
|
|
254
|
+
else if (poIs(child, "w:drawing")) {
|
|
255
|
+
const content = parseDrawing(child, defaultColorResolver);
|
|
256
|
+
if (content && content.kind === "image") inlineImage = {
|
|
257
|
+
imageId: content.imageId,
|
|
258
|
+
widthEmu: content.widthEmu,
|
|
259
|
+
heightEmu: content.heightEmu
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
text,
|
|
265
|
+
properties,
|
|
266
|
+
...inlineImage ? { inlineImage } : {},
|
|
267
|
+
...pageBreak ? { pageBreak: true } : {}
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
function elementTag(node) {
|
|
271
|
+
for (const key of Object.keys(node)) if (key !== ":@" && key !== "#text") return key;
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
export { EMPTY_SECTION, parseBodyElements, parseDocument, parseHeaderFooter, parseSections };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BodyElement, ShapeFill, ShapeGeometry, ShapeLine, ShapeTextBody, ShapeTransform } from '../../document-model/index.js';
|
|
2
|
+
import { ColorResolver } from '../drawingml/colors.js';
|
|
3
|
+
import { PoNode } from './po-helpers.js';
|
|
4
|
+
export interface ShapeData {
|
|
5
|
+
readonly widthEmu: number;
|
|
6
|
+
readonly heightEmu: number;
|
|
7
|
+
readonly geometry: ShapeGeometry;
|
|
8
|
+
readonly fill: ShapeFill;
|
|
9
|
+
readonly line?: ShapeLine;
|
|
10
|
+
readonly transform?: ShapeTransform;
|
|
11
|
+
readonly text?: ShapeTextBody;
|
|
12
|
+
}
|
|
13
|
+
export type ParseBody = (children: ReadonlyArray<PoNode>) => Array<BodyElement>;
|
|
14
|
+
export type DrawingContent = {
|
|
15
|
+
readonly kind: 'image';
|
|
16
|
+
readonly imageId: string;
|
|
17
|
+
readonly widthEmu: number;
|
|
18
|
+
readonly heightEmu: number;
|
|
19
|
+
readonly altText?: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'shape';
|
|
22
|
+
readonly data: ShapeData;
|
|
23
|
+
readonly altText?: string;
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: 'chart';
|
|
26
|
+
readonly chartRelId: string;
|
|
27
|
+
readonly widthEmu: number;
|
|
28
|
+
readonly heightEmu: number;
|
|
29
|
+
readonly altText?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function resolveMc(altContent: PoNode): ReadonlyArray<PoNode>;
|
|
32
|
+
export declare function expandMcChildren(children: ReadonlyArray<PoNode>): Array<PoNode>;
|
|
33
|
+
export declare function parseDrawing(drawing: PoNode, resolveColor: ColorResolver, parseBody?: ParseBody): DrawingContent | null;
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { poAttr, poChildren, poFindDescendant, poIntAttr, poIs, poTag } from "./po-helpers.js";
|
|
2
|
+
//#region src/ooxml/wordproc/drawing-parser.ts
|
|
3
|
+
var WPS_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
|
|
4
|
+
var CHART_URI = "http://schemas.openxmlformats.org/drawingml/2006/chart";
|
|
5
|
+
var UNDERSTOOD_NS = new Set(["wps"]);
|
|
6
|
+
function resolveMc(altContent) {
|
|
7
|
+
for (const choice of poChildren(altContent)) {
|
|
8
|
+
if (!poIs(choice, "mc:Choice")) continue;
|
|
9
|
+
const requires = (poAttr(choice, "Requires") ?? "").split(/\s+/).filter(Boolean);
|
|
10
|
+
if (requires.length > 0 && requires.every((r) => UNDERSTOOD_NS.has(r))) return poChildren(choice);
|
|
11
|
+
}
|
|
12
|
+
const fallback = poChildren(altContent).find((c) => poIs(c, "mc:Fallback"));
|
|
13
|
+
return fallback ? poChildren(fallback) : [];
|
|
14
|
+
}
|
|
15
|
+
function expandMcChildren(children) {
|
|
16
|
+
const out = [];
|
|
17
|
+
for (const c of children) if (poIs(c, "mc:AlternateContent")) out.push(...resolveMc(c));
|
|
18
|
+
else out.push(c);
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
function parseDrawing(drawing, resolveColor, parseBody) {
|
|
22
|
+
const anchor = poChildren(drawing).find((c) => poIs(c, "wp:inline")) ?? poChildren(drawing).find((c) => poIs(c, "wp:anchor"));
|
|
23
|
+
if (!anchor) return null;
|
|
24
|
+
const extent = poFindDescendant(anchor, "wp:extent");
|
|
25
|
+
const extentCx = extent ? poIntAttr(extent, "cx") : void 0;
|
|
26
|
+
const extentCy = extent ? poIntAttr(extent, "cy") : void 0;
|
|
27
|
+
const docPr = poChildren(anchor).find((c) => poIs(c, "wp:docPr"));
|
|
28
|
+
const descr = docPr ? poAttr(docPr, "descr") : void 0;
|
|
29
|
+
const title = docPr ? poAttr(docPr, "title") : void 0;
|
|
30
|
+
const altText = (descr ?? title)?.trim() || void 0;
|
|
31
|
+
const alt = altText ? { altText } : {};
|
|
32
|
+
const graphicData = poFindDescendant(anchor, "a:graphicData");
|
|
33
|
+
const uri = graphicData ? poAttr(graphicData, "uri") : void 0;
|
|
34
|
+
if (graphicData && uri === WPS_URI) {
|
|
35
|
+
const data = parseWsp(graphicData, extentCx, extentCy, resolveColor, parseBody);
|
|
36
|
+
return data ? {
|
|
37
|
+
kind: "shape",
|
|
38
|
+
data,
|
|
39
|
+
...alt
|
|
40
|
+
} : null;
|
|
41
|
+
}
|
|
42
|
+
if (graphicData && uri === CHART_URI) {
|
|
43
|
+
const cChart = poFindDescendant(graphicData, "c:chart");
|
|
44
|
+
const chartRelId = cChart ? poAttr(cChart, "id") : void 0;
|
|
45
|
+
if (chartRelId && extentCx !== void 0 && extentCy !== void 0) return {
|
|
46
|
+
kind: "chart",
|
|
47
|
+
chartRelId,
|
|
48
|
+
widthEmu: extentCx,
|
|
49
|
+
heightEmu: extentCy,
|
|
50
|
+
...alt
|
|
51
|
+
};
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const blip = poFindDescendant(anchor, "a:blip");
|
|
55
|
+
const rId = blip ? poAttr(blip, "embed") : void 0;
|
|
56
|
+
if (extentCx !== void 0 && extentCy !== void 0 && rId) return {
|
|
57
|
+
kind: "image",
|
|
58
|
+
imageId: rId,
|
|
59
|
+
widthEmu: extentCx,
|
|
60
|
+
heightEmu: extentCy,
|
|
61
|
+
...alt
|
|
62
|
+
};
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
function parseWsp(graphicData, extentCx, extentCy, resolveColor, parseBody) {
|
|
66
|
+
const wsp = expandMcChildren(poChildren(graphicData)).find((c) => poIs(c, "wps:wsp"));
|
|
67
|
+
if (!wsp) return null;
|
|
68
|
+
const spPr = poChildren(wsp).find((c) => poIs(c, "wps:spPr"));
|
|
69
|
+
let geometry = {
|
|
70
|
+
kind: "preset",
|
|
71
|
+
preset: "rect",
|
|
72
|
+
adjust: /* @__PURE__ */ new Map()
|
|
73
|
+
};
|
|
74
|
+
let fill = { kind: "none" };
|
|
75
|
+
let line;
|
|
76
|
+
let transform;
|
|
77
|
+
let widthEmu = extentCx;
|
|
78
|
+
let heightEmu = extentCy;
|
|
79
|
+
if (spPr) {
|
|
80
|
+
const xfrm = poChildren(spPr).find((c) => poIs(c, "a:xfrm"));
|
|
81
|
+
if (xfrm) {
|
|
82
|
+
transform = parseXfrm(xfrm);
|
|
83
|
+
if (widthEmu === void 0 || heightEmu === void 0) {
|
|
84
|
+
const ext = poChildren(xfrm).find((c) => poIs(c, "a:ext"));
|
|
85
|
+
if (ext) {
|
|
86
|
+
widthEmu = widthEmu ?? poIntAttr(ext, "cx");
|
|
87
|
+
heightEmu = heightEmu ?? poIntAttr(ext, "cy");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const prst = poChildren(spPr).find((c) => poIs(c, "a:prstGeom"));
|
|
92
|
+
const cust = poChildren(spPr).find((c) => poIs(c, "a:custGeom"));
|
|
93
|
+
if (prst) geometry = parsePrstGeom(prst);
|
|
94
|
+
else if (cust) geometry = parseCustGeom(cust);
|
|
95
|
+
fill = parseFill(spPr, resolveColor);
|
|
96
|
+
line = parseLine(spPr, resolveColor);
|
|
97
|
+
}
|
|
98
|
+
const text = parseBody ? parseTextBox(wsp, parseBody) : void 0;
|
|
99
|
+
if (widthEmu === void 0 || heightEmu === void 0) return null;
|
|
100
|
+
return {
|
|
101
|
+
widthEmu,
|
|
102
|
+
heightEmu,
|
|
103
|
+
geometry,
|
|
104
|
+
fill,
|
|
105
|
+
...line ? { line } : {},
|
|
106
|
+
...transform ? { transform } : {},
|
|
107
|
+
...text ? { text } : {}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function parseTextBox(wsp, parseBody) {
|
|
111
|
+
const txbx = poChildren(wsp).find((c) => poIs(c, "wps:txbx"));
|
|
112
|
+
if (!txbx) return void 0;
|
|
113
|
+
const txContent = poChildren(txbx).find((c) => poIs(c, "w:txbxContent"));
|
|
114
|
+
if (!txContent) return void 0;
|
|
115
|
+
const content = parseBody(poChildren(txContent));
|
|
116
|
+
if (content.length === 0) return void 0;
|
|
117
|
+
const bodyPr = poChildren(wsp).find((c) => poIs(c, "wps:bodyPr"));
|
|
118
|
+
const lIns = bodyPr ? poIntAttr(bodyPr, "lIns") : void 0;
|
|
119
|
+
const tIns = bodyPr ? poIntAttr(bodyPr, "tIns") : void 0;
|
|
120
|
+
const rIns = bodyPr ? poIntAttr(bodyPr, "rIns") : void 0;
|
|
121
|
+
const bIns = bodyPr ? poIntAttr(bodyPr, "bIns") : void 0;
|
|
122
|
+
const a = bodyPr ? poAttr(bodyPr, "anchor") : void 0;
|
|
123
|
+
const anchor = a === "ctr" ? "ctr" : a === "b" ? "b" : a === "t" ? "t" : void 0;
|
|
124
|
+
return {
|
|
125
|
+
content,
|
|
126
|
+
...lIns !== void 0 ? { insetLeftEmu: lIns } : {},
|
|
127
|
+
...tIns !== void 0 ? { insetTopEmu: tIns } : {},
|
|
128
|
+
...rIns !== void 0 ? { insetRightEmu: rIns } : {},
|
|
129
|
+
...bIns !== void 0 ? { insetBottomEmu: bIns } : {},
|
|
130
|
+
...anchor ? { anchor } : {}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
var isTrue = (v) => v === "1" || v === "true" || v === "on";
|
|
134
|
+
function parseXfrm(xfrm) {
|
|
135
|
+
const rot = poIntAttr(xfrm, "rot");
|
|
136
|
+
const flipH = isTrue(poAttr(xfrm, "flipH"));
|
|
137
|
+
const flipV = isTrue(poAttr(xfrm, "flipV"));
|
|
138
|
+
return {
|
|
139
|
+
...rot !== void 0 ? { rotation60k: rot } : {},
|
|
140
|
+
...flipH ? { flipH: true } : {},
|
|
141
|
+
...flipV ? { flipV: true } : {}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function parsePrstGeom(prst) {
|
|
145
|
+
const preset = poAttr(prst, "prst") ?? "rect";
|
|
146
|
+
const adjust = /* @__PURE__ */ new Map();
|
|
147
|
+
const avLst = poChildren(prst).find((c) => poIs(c, "a:avLst"));
|
|
148
|
+
if (avLst) for (const gd of poChildren(avLst)) {
|
|
149
|
+
if (!poIs(gd, "a:gd")) continue;
|
|
150
|
+
const nm = poAttr(gd, "name");
|
|
151
|
+
const fmla = poAttr(gd, "fmla");
|
|
152
|
+
if (!nm || !fmla) continue;
|
|
153
|
+
const m = /^val\s+(-?\d+)/.exec(fmla);
|
|
154
|
+
if (m) adjust.set(nm, Number(m[1]));
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
kind: "preset",
|
|
158
|
+
preset,
|
|
159
|
+
adjust
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function parseCustGeom(cust) {
|
|
163
|
+
const pathLst = poChildren(cust).find((c) => poIs(c, "a:pathLst"));
|
|
164
|
+
const path = pathLst ? poChildren(pathLst).find((c) => poIs(c, "a:path")) : void 0;
|
|
165
|
+
if (!path) return {
|
|
166
|
+
kind: "preset",
|
|
167
|
+
preset: "rect",
|
|
168
|
+
adjust: /* @__PURE__ */ new Map()
|
|
169
|
+
};
|
|
170
|
+
const pathWidth = poIntAttr(path, "w") ?? 0;
|
|
171
|
+
const pathHeight = poIntAttr(path, "h") ?? 0;
|
|
172
|
+
const commands = [];
|
|
173
|
+
for (const node of poChildren(path)) switch (poTag(node)) {
|
|
174
|
+
case "a:moveTo": {
|
|
175
|
+
const p = firstPt(node);
|
|
176
|
+
if (p) commands.push({
|
|
177
|
+
cmd: "move",
|
|
178
|
+
x: p.x,
|
|
179
|
+
y: p.y
|
|
180
|
+
});
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
case "a:lnTo": {
|
|
184
|
+
const p = firstPt(node);
|
|
185
|
+
if (p) commands.push({
|
|
186
|
+
cmd: "line",
|
|
187
|
+
x: p.x,
|
|
188
|
+
y: p.y
|
|
189
|
+
});
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case "a:cubicBezTo": {
|
|
193
|
+
const p = pts(node);
|
|
194
|
+
if (p.length >= 3) commands.push({
|
|
195
|
+
cmd: "cubic",
|
|
196
|
+
x1: p[0].x,
|
|
197
|
+
y1: p[0].y,
|
|
198
|
+
x2: p[1].x,
|
|
199
|
+
y2: p[1].y,
|
|
200
|
+
x: p[2].x,
|
|
201
|
+
y: p[2].y
|
|
202
|
+
});
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case "a:quadBezTo": {
|
|
206
|
+
const p = pts(node);
|
|
207
|
+
if (p.length >= 2) commands.push({
|
|
208
|
+
cmd: "quad",
|
|
209
|
+
x1: p[0].x,
|
|
210
|
+
y1: p[0].y,
|
|
211
|
+
x: p[1].x,
|
|
212
|
+
y: p[1].y
|
|
213
|
+
});
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
case "a:arcTo":
|
|
217
|
+
commands.push({
|
|
218
|
+
cmd: "arc",
|
|
219
|
+
wR: poIntAttr(node, "wR") ?? 0,
|
|
220
|
+
hR: poIntAttr(node, "hR") ?? 0,
|
|
221
|
+
stAng: poIntAttr(node, "stAng") ?? 0,
|
|
222
|
+
swAng: poIntAttr(node, "swAng") ?? 0
|
|
223
|
+
});
|
|
224
|
+
break;
|
|
225
|
+
case "a:close":
|
|
226
|
+
commands.push({ cmd: "close" });
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
if (pathWidth <= 0 || pathHeight <= 0 || commands.length === 0) return {
|
|
230
|
+
kind: "preset",
|
|
231
|
+
preset: "rect",
|
|
232
|
+
adjust: /* @__PURE__ */ new Map()
|
|
233
|
+
};
|
|
234
|
+
return {
|
|
235
|
+
kind: "custom",
|
|
236
|
+
custom: {
|
|
237
|
+
pathWidth,
|
|
238
|
+
pathHeight,
|
|
239
|
+
commands
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function pts(node) {
|
|
244
|
+
const out = [];
|
|
245
|
+
for (const c of poChildren(node)) {
|
|
246
|
+
if (!poIs(c, "a:pt")) continue;
|
|
247
|
+
const x = poIntAttr(c, "x");
|
|
248
|
+
const y = poIntAttr(c, "y");
|
|
249
|
+
if (x !== void 0 && y !== void 0) out.push({
|
|
250
|
+
x,
|
|
251
|
+
y
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
256
|
+
var firstPt = (node) => pts(node)[0];
|
|
257
|
+
function parseFill(spPr, resolveColor) {
|
|
258
|
+
for (const child of poChildren(spPr)) {
|
|
259
|
+
if (poIs(child, "a:noFill")) return { kind: "none" };
|
|
260
|
+
if (poIs(child, "a:solidFill")) {
|
|
261
|
+
const hex = colorFromContainer(child, resolveColor);
|
|
262
|
+
return hex ? {
|
|
263
|
+
kind: "solid",
|
|
264
|
+
colorHex: hex
|
|
265
|
+
} : { kind: "none" };
|
|
266
|
+
}
|
|
267
|
+
if (poIs(child, "a:gradFill")) {
|
|
268
|
+
const hex = colorFromGradient(child, resolveColor);
|
|
269
|
+
return hex ? {
|
|
270
|
+
kind: "solid",
|
|
271
|
+
colorHex: hex
|
|
272
|
+
} : { kind: "none" };
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return { kind: "none" };
|
|
276
|
+
}
|
|
277
|
+
function parseLine(spPr, resolveColor) {
|
|
278
|
+
const ln = poChildren(spPr).find((c) => poIs(c, "a:ln"));
|
|
279
|
+
if (!ln) return void 0;
|
|
280
|
+
const widthEmu = poIntAttr(ln, "w");
|
|
281
|
+
const capRaw = poAttr(ln, "cap");
|
|
282
|
+
const cap = capRaw === "rnd" ? "round" : capRaw === "sq" ? "square" : capRaw === "flat" ? "flat" : void 0;
|
|
283
|
+
let noFill = false;
|
|
284
|
+
let colorHex;
|
|
285
|
+
let dash;
|
|
286
|
+
for (const c of poChildren(ln)) if (poIs(c, "a:noFill")) noFill = true;
|
|
287
|
+
else if (poIs(c, "a:solidFill")) colorHex = colorFromContainer(c, resolveColor);
|
|
288
|
+
else if (poIs(c, "a:prstDash")) dash = normalizeDash(poAttr(c, "val"));
|
|
289
|
+
return {
|
|
290
|
+
...widthEmu !== void 0 ? { widthEmu } : {},
|
|
291
|
+
...colorHex ? { colorHex } : {},
|
|
292
|
+
...dash ? { dash } : {},
|
|
293
|
+
...cap ? { cap } : {},
|
|
294
|
+
...noFill ? { fill: "none" } : {}
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
var DASH_VALUES = new Set([
|
|
298
|
+
"solid",
|
|
299
|
+
"dot",
|
|
300
|
+
"dash",
|
|
301
|
+
"dashDot",
|
|
302
|
+
"lgDash",
|
|
303
|
+
"lgDashDot",
|
|
304
|
+
"sysDash",
|
|
305
|
+
"sysDot"
|
|
306
|
+
]);
|
|
307
|
+
function normalizeDash(v) {
|
|
308
|
+
if (!v) return void 0;
|
|
309
|
+
if (DASH_VALUES.has(v)) return v;
|
|
310
|
+
if (v === "lgDashDotDot") return "lgDashDot";
|
|
311
|
+
if (v === "sysDashDot" || v === "sysDashDotDot") return "sysDash";
|
|
312
|
+
}
|
|
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
|
+
function colorFromContainer(parent, resolveColor) {
|
|
343
|
+
for (const c of poChildren(parent)) {
|
|
344
|
+
const hex = resolveColorNode(c, resolveColor);
|
|
345
|
+
if (hex) return hex;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function colorFromGradient(grad, resolveColor) {
|
|
349
|
+
const gsLst = poChildren(grad).find((c) => poIs(c, "a:gsLst"));
|
|
350
|
+
if (!gsLst) return void 0;
|
|
351
|
+
let r = 0;
|
|
352
|
+
let g = 0;
|
|
353
|
+
let b = 0;
|
|
354
|
+
let n = 0;
|
|
355
|
+
for (const gs of poChildren(gsLst)) {
|
|
356
|
+
if (!poIs(gs, "a:gs")) continue;
|
|
357
|
+
let hex;
|
|
358
|
+
for (const c of poChildren(gs)) {
|
|
359
|
+
hex = resolveColorNode(c, resolveColor);
|
|
360
|
+
if (hex) break;
|
|
361
|
+
}
|
|
362
|
+
if (!hex) continue;
|
|
363
|
+
const num = parseInt(hex, 16);
|
|
364
|
+
r += num >> 16 & 255;
|
|
365
|
+
g += num >> 8 & 255;
|
|
366
|
+
b += num & 255;
|
|
367
|
+
n++;
|
|
368
|
+
}
|
|
369
|
+
if (n === 0) return void 0;
|
|
370
|
+
const toHex = (x) => Math.round(x / n).toString(16).padStart(2, "0");
|
|
371
|
+
return (toHex(r) + toHex(g) + toHex(b)).toUpperCase();
|
|
372
|
+
}
|
|
373
|
+
//#endregion
|
|
374
|
+
export { expandMcChildren, parseDrawing };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OpcPackage } from '../../opc/index.js';
|
|
2
|
+
import { FontRegistry } from '../../font/index.js';
|
|
3
|
+
type EmbedVariant = 'regular' | 'bold' | 'italic' | 'boldItalic';
|
|
4
|
+
interface EmbedRef {
|
|
5
|
+
readonly rId: string;
|
|
6
|
+
readonly fontKey: string;
|
|
7
|
+
}
|
|
8
|
+
interface FontTableEntry {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly embeds: Partial<Record<EmbedVariant, EmbedRef>>;
|
|
11
|
+
}
|
|
12
|
+
export declare function deobfuscateEmbeddedFont(data: Uint8Array, fontKey: string): Uint8Array;
|
|
13
|
+
export declare function parseFontTable(data: Uint8Array): Array<FontTableEntry>;
|
|
14
|
+
export declare function loadEmbeddedFonts(pkg: OpcPackage): Map<string, FontRegistry>;
|
|
15
|
+
export {};
|