reamkit 0.1.0-alpha.0 → 1.0.1
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 +107 -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.d.ts +2 -0
- package/dist/esm/{bidi → core/bidi}/index.js +2 -1
- package/dist/esm/core/bidi/segments.d.ts +6 -0
- package/dist/esm/core/bidi/segments.js +41 -0
- 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 +17 -0
- package/dist/esm/core/converter/ream.d.ts +35 -0
- package/dist/esm/core/converter/ream.js +101 -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 +3 -0
- package/dist/esm/core/font/measure.d.ts +7 -0
- package/dist/esm/core/font/measure.js +30 -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/images.d.ts +17 -0
- package/dist/esm/core/images.js +308 -0
- 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.d.ts +1 -0
- package/dist/esm/{line-breaker → core/line-breaker}/knuth-plass.js +3 -3
- package/dist/esm/core/numbering/apply.d.ts +3 -0
- package/dist/esm/core/numbering/apply.js +62 -0
- package/dist/esm/core/numbering/index.d.ts +2 -0
- 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.d.ts +2 -1
- package/dist/esm/{opc → core/opc}/package.js +7 -3
- 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/core/style-cascade/index.d.ts +3 -0
- package/dist/esm/core/style-cascade/index.js +2 -0
- package/dist/esm/core/style-cascade/resolver.d.ts +7 -0
- package/dist/esm/{style-cascade → core/style-cascade}/resolver.js +82 -10
- package/dist/esm/{style-cascade → core/style-cascade}/types.d.ts +10 -8
- package/dist/esm/{style-cascade → core/style-cascade}/types.js +9 -8
- package/dist/esm/core/vector.d.ts +45 -0
- package/dist/esm/core/vector.js +48 -0
- 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 -10
- package/dist/esm/{pdf → layout}/arc-to-bezier.d.ts +1 -1
- package/dist/esm/{pdf → layout}/arc-to-bezier.js +2 -2
- package/dist/esm/{pdf → layout}/chart-geometry.d.ts +1 -1
- package/dist/esm/{pdf → layout}/math-layout.d.ts +2 -2
- package/dist/esm/{pdf → layout}/math-layout.js +1 -1
- package/dist/esm/layout/page-doc.d.ts +133 -0
- package/dist/esm/layout/page-doc.js +38 -0
- package/dist/esm/{pdf → layout}/preset-geometry.d.ts +2 -2
- package/dist/esm/{pdf → layout}/preset-geometry.js +2 -2
- package/dist/esm/layout/styled-layout.d.ts +84 -0
- package/dist/esm/layout/styled-layout.js +1729 -0
- package/dist/esm/pdf/cid-font.d.ts +1 -1
- package/dist/esm/pdf/cid-font.js +6 -21
- package/dist/esm/pdf/image-xobject.d.ts +4 -5
- package/dist/esm/pdf/image-xobject.js +21 -324
- package/dist/esm/pdf/index.d.ts +2 -2
- package/dist/esm/pdf/index.js +1 -0
- package/dist/esm/pdf/signature.js +4 -4
- package/dist/esm/pdf/styled-page-emitter.d.ts +11 -0
- package/dist/esm/pdf/styled-page-emitter.js +557 -0
- package/dist/esm/pdf/styled-page-renderer.d.ts +4 -42
- package/dist/esm/pdf/styled-page-renderer.js +4 -2311
- package/dist/esm/pdf/text-page-renderer.d.ts +1 -1
- package/dist/esm/pdf/vector-graphics.d.ts +3 -45
- package/dist/esm/pdf/vector-graphics.js +2 -46
- package/dist/esm/svg/svg-writer.d.ts +8 -0
- package/dist/esm/svg/svg-writer.js +137 -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 +191 -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/numbering/index.d.ts +0 -1
- 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/style-cascade/index.d.ts +0 -3
- package/dist/esm/style-cascade/resolver.d.ts +0 -4
- /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/{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/{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}/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/{pdf → layout}/chart-geometry.js +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,191 @@
|
|
|
1
|
+
import { ResourceStore } from "../core/ir/resources.js";
|
|
2
|
+
import { FEATURES } from "../core/ir/features.js";
|
|
3
|
+
import { applyNumbering, applyNumberingToHeadersFooters } from "../core/numbering/apply.js";
|
|
4
|
+
import { EMPTY_STYLE_SHEET, resolveBodyStyles, resolveHeadersFootersStyles } from "../core/style-cascade/resolver.js";
|
|
5
|
+
import "../core/style-cascade/index.js";
|
|
6
|
+
import { bytesInclude } from "../core/bytes.js";
|
|
7
|
+
import { DEFAULT_THEME_PALETTE, makeColorResolver } from "../core/drawingml/colors.js";
|
|
8
|
+
import { parseChart } from "../core/drawingml/chart-parser.js";
|
|
9
|
+
import { parseTheme } from "../core/drawingml/theme-parser.js";
|
|
10
|
+
import { OpcPackage } from "../core/opc/package.js";
|
|
11
|
+
import { parseCoreProperties } from "../core/opc/core-properties.js";
|
|
12
|
+
import "../core/opc/index.js";
|
|
13
|
+
import { EMPTY_SECTION, parseDocument, parseHeaderFooter, parseSections } from "./document-parser.js";
|
|
14
|
+
import { parseStyles } from "./styles-parser.js";
|
|
15
|
+
import { loadEmbeddedFonts } from "./font-table.js";
|
|
16
|
+
import { EMPTY_NUMBERING, parseNumbering } from "./numbering-parser.js";
|
|
17
|
+
import { EMPTY_SETTINGS, parseSettings } from "./settings-parser.js";
|
|
18
|
+
import "./index.js";
|
|
19
|
+
//#region src/word/docx-reader.ts
|
|
20
|
+
var STYLES_PART = "word/styles.xml";
|
|
21
|
+
var NUMBERING_PART = "word/numbering.xml";
|
|
22
|
+
var SETTINGS_PART = "word/settings.xml";
|
|
23
|
+
var CORE_PROPS_PART = "docProps/core.xml";
|
|
24
|
+
var MAIN_DOCUMENT_PART = "word/document.xml";
|
|
25
|
+
var REL_IMAGE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
|
|
26
|
+
var REL_CHART = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart";
|
|
27
|
+
var REL_THEME = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
|
|
28
|
+
var REL_HEADER = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
|
|
29
|
+
var REL_FOOTER = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer";
|
|
30
|
+
var THEME_PART = "word/theme/theme1.xml";
|
|
31
|
+
function readDocx(docx) {
|
|
32
|
+
const pkg = OpcPackage.open(docx);
|
|
33
|
+
const main = pkg.getMainDocument();
|
|
34
|
+
const resolveColor = buildColorResolver(pkg);
|
|
35
|
+
const resources = new ResourceStore();
|
|
36
|
+
const ctx = {
|
|
37
|
+
resolveColor,
|
|
38
|
+
resolveImage: makeImageResolver(pkg, resources)
|
|
39
|
+
};
|
|
40
|
+
const body = parseDocument(main.data, ctx);
|
|
41
|
+
const rawSections = parseSections(main.data);
|
|
42
|
+
const stylesData = pkg.getPart(STYLES_PART);
|
|
43
|
+
const styles = stylesData ? parseStyles(stylesData) : EMPTY_STYLE_SHEET;
|
|
44
|
+
const numberingData = pkg.getPart(NUMBERING_PART);
|
|
45
|
+
const numbering = numberingData ? parseNumbering(numberingData) : EMPTY_NUMBERING;
|
|
46
|
+
const settingsData = pkg.getPart(SETTINGS_PART);
|
|
47
|
+
const settings = settingsData ? parseSettings(settingsData) : EMPTY_SETTINGS;
|
|
48
|
+
const sections = rawSections.length > 0 ? rawSections.map((s) => ({
|
|
49
|
+
...s,
|
|
50
|
+
properties: settings.evenAndOddHeaders ? {
|
|
51
|
+
...s.properties,
|
|
52
|
+
evenAndOddHeaders: true
|
|
53
|
+
} : s.properties
|
|
54
|
+
})) : [{
|
|
55
|
+
properties: settings.evenAndOddHeaders ? {
|
|
56
|
+
...EMPTY_SECTION,
|
|
57
|
+
evenAndOddHeaders: true
|
|
58
|
+
} : EMPTY_SECTION,
|
|
59
|
+
endIndex: body.length
|
|
60
|
+
}];
|
|
61
|
+
const headersFooters = loadHeadersFootersForSections(pkg, sections, ctx, resources);
|
|
62
|
+
const charts = loadCharts(pkg, resolveColor);
|
|
63
|
+
const embeddedFonts = loadEmbeddedFonts(pkg);
|
|
64
|
+
const coreData = pkg.getPart(CORE_PROPS_PART);
|
|
65
|
+
const info = infoFromCore(coreData ? parseCoreProperties(coreData) : void 0);
|
|
66
|
+
const language = detectDocxLanguage(stylesData, main.data);
|
|
67
|
+
return {
|
|
68
|
+
doc: {
|
|
69
|
+
kind: "flow",
|
|
70
|
+
body: resolveBodyStyles(applyNumbering(body, numbering), styles),
|
|
71
|
+
sections,
|
|
72
|
+
styles,
|
|
73
|
+
numbering,
|
|
74
|
+
headersFooters: resolveHeadersFootersStyles(applyNumberingToHeadersFooters(headersFooters, numbering), styles),
|
|
75
|
+
charts,
|
|
76
|
+
resources,
|
|
77
|
+
...embeddedFonts.size > 0 ? { embeddedFonts } : {},
|
|
78
|
+
...info ? { info } : {},
|
|
79
|
+
...language ? { language } : {}
|
|
80
|
+
},
|
|
81
|
+
losses: []
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
var docxReader = {
|
|
85
|
+
id: "docx",
|
|
86
|
+
produces: "flow",
|
|
87
|
+
supports: new Set([
|
|
88
|
+
FEATURES.text,
|
|
89
|
+
FEATURES.tables,
|
|
90
|
+
FEATURES.tablesNested,
|
|
91
|
+
FEATURES.lists,
|
|
92
|
+
FEATURES.sections,
|
|
93
|
+
FEATURES.headersFooters,
|
|
94
|
+
FEATURES.images,
|
|
95
|
+
FEATURES.shapes,
|
|
96
|
+
FEATURES.charts,
|
|
97
|
+
FEATURES.math,
|
|
98
|
+
FEATURES.rtl,
|
|
99
|
+
FEATURES.trackedChanges,
|
|
100
|
+
FEATURES.fontsEmbedding
|
|
101
|
+
]),
|
|
102
|
+
sniff: (bytes) => bytes[0] === 80 && bytes[1] === 75 && bytesInclude(bytes, "word/document.xml"),
|
|
103
|
+
read: (bytes) => readDocx(bytes)
|
|
104
|
+
};
|
|
105
|
+
function infoFromCore(core) {
|
|
106
|
+
if (!core) return void 0;
|
|
107
|
+
return {
|
|
108
|
+
...core.title ? { title: core.title } : {},
|
|
109
|
+
...core.creator ? { author: core.creator } : {},
|
|
110
|
+
...core.subject ? { subject: core.subject } : {},
|
|
111
|
+
...core.keywords ? { keywords: core.keywords } : {},
|
|
112
|
+
...core.created ? { creationDate: core.created } : {},
|
|
113
|
+
...core.modified ? { modificationDate: core.modified } : {}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function makeImageResolver(pkg, store, partName = MAIN_DOCUMENT_PART) {
|
|
117
|
+
const byRelId = /* @__PURE__ */ new Map();
|
|
118
|
+
for (const rel of pkg.getPartRelationships(partName)) {
|
|
119
|
+
if (rel.type !== REL_IMAGE) continue;
|
|
120
|
+
const resolved = pkg.resolveRelatedPart(partName, rel);
|
|
121
|
+
if (resolved) byRelId.set(rel.id, resolved.data);
|
|
122
|
+
}
|
|
123
|
+
const cache = /* @__PURE__ */ new Map();
|
|
124
|
+
return (relId) => {
|
|
125
|
+
if (cache.has(relId)) return cache.get(relId);
|
|
126
|
+
const bytes = byRelId.get(relId);
|
|
127
|
+
const id = bytes ? store.put(bytes) : void 0;
|
|
128
|
+
cache.set(relId, id);
|
|
129
|
+
return id;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function loadCharts(pkg, resolveColor) {
|
|
133
|
+
const out = /* @__PURE__ */ new Map();
|
|
134
|
+
for (const rel of pkg.getPartRelationships(MAIN_DOCUMENT_PART)) {
|
|
135
|
+
if (rel.type !== REL_CHART) continue;
|
|
136
|
+
const resolved = pkg.resolveRelatedPart(MAIN_DOCUMENT_PART, rel);
|
|
137
|
+
if (!resolved) continue;
|
|
138
|
+
const chart = parseChart(resolved.data, resolveColor);
|
|
139
|
+
if (chart) out.set(rel.id, chart);
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
function buildColorResolver(pkg) {
|
|
144
|
+
const themeData = loadTheme(pkg);
|
|
145
|
+
if (!themeData) return makeColorResolver(DEFAULT_THEME_PALETTE);
|
|
146
|
+
const palette = new Map(DEFAULT_THEME_PALETTE);
|
|
147
|
+
for (const [slot, hex] of parseTheme(themeData)) palette.set(slot, hex);
|
|
148
|
+
return makeColorResolver(palette);
|
|
149
|
+
}
|
|
150
|
+
function loadTheme(pkg) {
|
|
151
|
+
for (const rel of pkg.getPartRelationships(MAIN_DOCUMENT_PART)) {
|
|
152
|
+
if (rel.type !== REL_THEME) continue;
|
|
153
|
+
const resolved = pkg.resolveRelatedPart(MAIN_DOCUMENT_PART, rel);
|
|
154
|
+
if (resolved) return resolved.data;
|
|
155
|
+
}
|
|
156
|
+
return pkg.getPart(THEME_PART);
|
|
157
|
+
}
|
|
158
|
+
function loadHeadersFootersForSections(pkg, sections, ctx, store) {
|
|
159
|
+
const wanted = /* @__PURE__ */ new Set();
|
|
160
|
+
for (const s of sections) {
|
|
161
|
+
for (const h of s.properties.headers) wanted.add(h.relationshipId);
|
|
162
|
+
for (const f of s.properties.footers) wanted.add(f.relationshipId);
|
|
163
|
+
}
|
|
164
|
+
if (wanted.size === 0) return /* @__PURE__ */ new Map();
|
|
165
|
+
const rels = pkg.getPartRelationships(MAIN_DOCUMENT_PART);
|
|
166
|
+
if (rels.length === 0) return /* @__PURE__ */ new Map();
|
|
167
|
+
const out = /* @__PURE__ */ new Map();
|
|
168
|
+
for (const rel of rels) {
|
|
169
|
+
if (!wanted.has(rel.id)) continue;
|
|
170
|
+
if (rel.type !== REL_HEADER && rel.type !== REL_FOOTER) continue;
|
|
171
|
+
const resolved = pkg.resolveRelatedPart(MAIN_DOCUMENT_PART, rel);
|
|
172
|
+
if (!resolved) continue;
|
|
173
|
+
const hfCtx = {
|
|
174
|
+
resolveColor: ctx.resolveColor,
|
|
175
|
+
resolveImage: makeImageResolver(pkg, store, resolved.path)
|
|
176
|
+
};
|
|
177
|
+
out.set(rel.id, parseHeaderFooter(resolved.data, hfCtx));
|
|
178
|
+
}
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
function detectDocxLanguage(stylesData, documentData) {
|
|
182
|
+
const re = /<w:lang\b[^>]*\bw:val="([^"]+)"/;
|
|
183
|
+
const decoder = new TextDecoder();
|
|
184
|
+
for (const data of [stylesData, documentData]) {
|
|
185
|
+
if (!data) continue;
|
|
186
|
+
const m = re.exec(decoder.decode(data));
|
|
187
|
+
if (m?.[1]) return m[1];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
export { docxReader, readDocx };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { FontBytesByVariant, FontRegistry } from '../core/font/index.js';
|
|
2
|
+
import { FamilyKey, FetchLike } from '../core/fonts/index.js';
|
|
3
|
+
import { SignatureOptions, StyledRenderOptions } from '../pdf/index.js';
|
|
4
|
+
export interface ConvertDocxOptions extends Omit<StyledRenderOptions, 'registry' | 'styles'> {
|
|
5
|
+
readonly fontBytes?: Uint8Array;
|
|
6
|
+
readonly fonts?: FontBytesByVariant;
|
|
7
|
+
readonly fontFamily?: string;
|
|
8
|
+
readonly fontFetch?: FetchLike;
|
|
9
|
+
readonly embedSource?: boolean;
|
|
10
|
+
readonly signature?: SignatureOptions;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Synchronous one-shot conversion (requires `fonts`/`fontBytes`, no network).
|
|
14
|
+
*
|
|
15
|
+
* Internal since 1.0 — see the async variant above.
|
|
16
|
+
*/
|
|
17
|
+
export declare function convertDocxToPdfSync(docx: Uint8Array, options: ConvertDocxOptions): Uint8Array;
|
|
18
|
+
export declare function detectDocxFamilyKeys(docx: Uint8Array): Set<FamilyKey>;
|
|
19
|
+
/**
|
|
20
|
+
* One-shot .docx → PDF (auto-downloads a substitute font set when the caller
|
|
21
|
+
* supplies none; zero network with `fonts`/`fontBytes`).
|
|
22
|
+
*
|
|
23
|
+
* Internal since 1.0 — the public entry is `Ream.parse(bytes).convert('pdf')`;
|
|
24
|
+
* the createConverter facade and the test suite drive this directly.
|
|
25
|
+
*/
|
|
26
|
+
export declare function convertDocxToPdf(docx: Uint8Array, options?: ConvertDocxOptions): Promise<Uint8Array>;
|
|
27
|
+
export declare function resolveDocxAutoFonts(docx: Uint8Array, options?: {
|
|
28
|
+
readonly fontFamily?: string;
|
|
29
|
+
readonly fontFetch?: FetchLike;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
fonts: FontBytesByVariant;
|
|
32
|
+
registriesByFamily?: Map<FamilyKey, FontRegistry>;
|
|
33
|
+
}>;
|
|
34
|
+
export declare function detectDocxFontFamily(docx: Uint8Array): string | undefined;
|
|
@@ -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,
|