documents.js 1.62.0 → 1.64.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 +150 -24
- package/dist/convert/convert.cjs +72 -20
- package/dist/convert/convert.d.cts +6 -2
- package/dist/convert/convert.d.ts +6 -2
- package/dist/convert/convert.js +73 -21
- package/dist/convert/local.cjs +15 -2
- package/dist/convert/local.js +15 -2
- package/dist/convert/port.d.cts +8 -4
- package/dist/convert/port.d.ts +8 -4
- package/dist/edit/docx/content.d.cts +1 -1
- package/dist/edit/docx/content.d.ts +1 -1
- package/dist/edit/docx/paragraph.d.cts +3 -3
- package/dist/edit/docx/paragraph.d.ts +3 -3
- package/dist/edit/ods/address.cjs +42 -24
- package/dist/edit/ods/address.d.cts +12 -2
- package/dist/edit/ods/address.d.ts +12 -2
- package/dist/edit/ods/address.js +39 -25
- package/dist/edit/ods/column-row.cjs +68 -6
- package/dist/edit/ods/column-row.d.cts +5 -1
- package/dist/edit/ods/column-row.d.ts +5 -1
- package/dist/edit/ods/column-row.js +68 -10
- package/dist/edit/ods/content.cjs +10 -2
- package/dist/edit/ods/content.js +10 -2
- package/dist/edit/ods/floating.cjs +90 -0
- package/dist/edit/ods/floating.d.cts +7 -0
- package/dist/edit/ods/floating.d.ts +7 -0
- package/dist/edit/ods/floating.js +88 -0
- package/dist/edit/ods/print-settings.cjs +158 -2
- package/dist/edit/ods/print-settings.js +159 -3
- package/dist/edit/ods/sheet.cjs +13 -0
- package/dist/edit/ods/sheet.d.cts +5 -1
- package/dist/edit/ods/sheet.d.ts +5 -1
- package/dist/edit/ods/sheet.js +14 -1
- package/dist/edit/odt/content.cjs +8 -4
- package/dist/edit/odt/content.js +8 -4
- package/dist/edit/odt/editor.cjs +7 -0
- package/dist/edit/odt/editor.d.cts +3 -0
- package/dist/edit/odt/editor.d.ts +3 -0
- package/dist/edit/odt/editor.js +7 -0
- package/dist/edit/odt/formula.cjs +19 -0
- package/dist/edit/odt/formula.d.cts +8 -0
- package/dist/edit/odt/formula.d.ts +8 -0
- package/dist/edit/odt/formula.js +17 -0
- package/dist/evaluate-BU5N1Jk1.d.ts +11 -0
- package/dist/evaluate-BhMXY6DM.d.cts +11 -0
- package/dist/firebird/backup.d.cts +1 -1
- package/dist/firebird/backup.d.ts +1 -1
- package/dist/firebird/data.cjs +30 -16
- package/dist/firebird/data.d.cts +3 -2
- package/dist/firebird/data.d.ts +3 -2
- package/dist/firebird/data.js +30 -17
- package/dist/fonts/obfuscation.cjs +50 -0
- package/dist/fonts/obfuscation.d.cts +9 -0
- package/dist/fonts/obfuscation.d.ts +9 -0
- package/dist/fonts/obfuscation.js +46 -0
- package/dist/fonts/odf.cjs +86 -0
- package/dist/fonts/odf.d.cts +9 -0
- package/dist/fonts/odf.d.ts +9 -0
- package/dist/fonts/odf.js +84 -0
- package/dist/fonts/ooxml.cjs +129 -0
- package/dist/fonts/ooxml.d.cts +9 -0
- package/dist/fonts/ooxml.d.ts +9 -0
- package/dist/fonts/ooxml.js +127 -0
- package/dist/fonts/registry.cjs +18 -0
- package/dist/fonts/registry.d.cts +2 -0
- package/dist/fonts/registry.d.ts +2 -0
- package/dist/fonts/registry.js +16 -0
- package/dist/formula-CgydMiTt.d.ts +10 -0
- package/dist/formula-CiwPw8nY.d.cts +10 -0
- package/dist/hsqldb/binary-script.d.cts +1 -1
- package/dist/hsqldb/binary-script.d.ts +1 -1
- package/dist/hsqldb/cache.d.cts +1 -1
- package/dist/hsqldb/cache.d.ts +1 -1
- package/dist/hsqldb/rowformat.cjs +22 -13
- package/dist/hsqldb/rowformat.js +22 -13
- package/dist/hsqldb/script.d.cts +1 -18
- package/dist/hsqldb/script.d.ts +1 -18
- package/dist/index.cjs +88 -0
- package/dist/index.d.cts +27 -9
- package/dist/index.d.ts +27 -9
- package/dist/index.js +20 -3
- package/dist/layout/sheets.cjs +30 -24
- package/dist/layout/sheets.js +31 -25
- package/dist/layout/slides.cjs +6 -4
- package/dist/layout/slides.js +7 -5
- package/dist/lexer-DGPWx_f2.d.cts +42 -0
- package/dist/lexer-DGPWx_f2.d.ts +42 -0
- package/dist/mathml/layout.d.cts +1 -1
- package/dist/mathml/layout.d.ts +1 -1
- package/dist/mathml/variant.d.cts +1 -6
- package/dist/mathml/variant.d.ts +1 -6
- package/dist/odb/csv.d.cts +1 -1
- package/dist/odb/csv.d.ts +1 -1
- package/dist/odb/formula/definition.cjs +49 -0
- package/dist/odb/formula/definition.d.cts +8 -0
- package/dist/odb/formula/definition.d.ts +8 -0
- package/dist/odb/formula/definition.js +46 -0
- package/dist/odb/formula/errors.cjs +47 -0
- package/dist/odb/formula/errors.d.cts +21 -0
- package/dist/odb/formula/errors.d.ts +21 -0
- package/dist/odb/formula/errors.js +43 -0
- package/dist/odb/formula/evaluate.cjs +283 -0
- package/dist/odb/formula/evaluate.d.cts +43 -0
- package/dist/odb/formula/evaluate.d.ts +43 -0
- package/dist/odb/formula/evaluate.js +281 -0
- package/dist/odb/formula/parser.cjs +198 -0
- package/dist/odb/formula/parser.d.cts +29 -0
- package/dist/odb/formula/parser.d.ts +29 -0
- package/dist/odb/formula/parser.js +197 -0
- package/dist/odb/read.d.cts +1 -1
- package/dist/odb/read.d.ts +1 -1
- package/dist/odb/report/content.cjs +27 -0
- package/dist/odb/report/content.d.cts +14 -0
- package/dist/odb/report/content.d.ts +14 -0
- package/dist/odb/report/content.js +25 -0
- package/dist/odb/report/render.cjs +106 -0
- package/dist/odb/report/render.d.cts +7 -0
- package/dist/odb/report/render.d.ts +7 -0
- package/dist/odb/report/render.js +106 -0
- package/dist/odb/report/source.cjs +45 -0
- package/dist/odb/report/source.d.cts +14 -0
- package/dist/odb/report/source.d.ts +14 -0
- package/dist/odb/report/source.js +42 -0
- package/dist/odb/spreadsheet.d.cts +1 -1
- package/dist/odb/spreadsheet.d.ts +1 -1
- package/dist/odb/sql/errors.cjs +38 -0
- package/dist/odb/sql/errors.d.cts +17 -0
- package/dist/odb/sql/errors.d.ts +17 -0
- package/dist/odb/sql/errors.js +35 -0
- package/dist/odb/sql/evaluate.cjs +312 -0
- package/dist/odb/sql/evaluate.d.cts +2 -0
- package/dist/odb/sql/evaluate.d.ts +2 -0
- package/dist/odb/sql/evaluate.js +311 -0
- package/dist/odb/sql/lexer.cjs +282 -0
- package/dist/odb/sql/lexer.d.cts +2 -0
- package/dist/odb/sql/lexer.d.ts +2 -0
- package/dist/odb/sql/lexer.js +281 -0
- package/dist/odb/sql/parser.cjs +479 -0
- package/dist/odb/sql/parser.d.cts +2 -0
- package/dist/odb/sql/parser.d.ts +2 -0
- package/dist/odb/sql/parser.js +478 -0
- package/dist/odb/values.cjs +75 -0
- package/dist/odb/values.d.cts +2 -0
- package/dist/odb/values.d.ts +2 -0
- package/dist/odb/values.js +69 -0
- package/dist/odf/odt/read.cjs +43 -21
- package/dist/odf/odt/read.js +43 -21
- package/dist/odf-package/formula.cjs +59 -0
- package/dist/odf-package/formula.d.cts +11 -0
- package/dist/odf-package/formula.d.ts +11 -0
- package/dist/odf-package/formula.js +58 -0
- package/dist/odf-package/manifest.cjs +29 -0
- package/dist/odf-package/manifest.d.cts +5 -2
- package/dist/odf-package/manifest.d.ts +5 -2
- package/dist/odf-package/manifest.js +30 -2
- package/dist/odf-package/media.cjs +2 -1
- package/dist/odf-package/media.js +2 -2
- package/dist/omml/read.cjs +265 -0
- package/dist/omml/read.d.cts +12 -0
- package/dist/omml/read.d.ts +12 -0
- package/dist/omml/read.js +263 -0
- package/dist/omml/shared.cjs +67 -0
- package/dist/omml/shared.d.cts +2 -0
- package/dist/omml/shared.d.ts +2 -0
- package/dist/omml/shared.js +64 -0
- package/dist/omml/write.cjs +3 -51
- package/dist/omml/write.d.cts +2 -2
- package/dist/omml/write.d.ts +2 -2
- package/dist/omml/write.js +1 -49
- package/dist/ooxml/docx/extras.cjs +15 -0
- package/dist/ooxml/docx/extras.d.cts +12 -0
- package/dist/ooxml/docx/extras.d.ts +12 -0
- package/dist/ooxml/docx/extras.js +14 -0
- package/dist/ooxml/docx/formula.cjs +109 -0
- package/dist/ooxml/docx/formula.d.cts +2 -0
- package/dist/ooxml/docx/formula.d.ts +2 -0
- package/dist/ooxml/docx/formula.js +108 -0
- package/dist/ooxml/docx/read.cjs +10 -2
- package/dist/ooxml/docx/read.d.cts +6 -2
- package/dist/ooxml/docx/read.d.ts +6 -2
- package/dist/ooxml/docx/read.js +11 -3
- package/dist/parser-B9vC1T6T.d.cts +101 -0
- package/dist/parser-DQSgYJzQ.d.ts +101 -0
- package/dist/registry-CrSqLIcn.d.ts +19 -0
- package/dist/registry-lqJej0Jr.d.cts +19 -0
- package/dist/script-DsGGIzGU.d.cts +19 -0
- package/dist/script-DsGGIzGU.d.ts +19 -0
- package/dist/shared-DLZ3IQUl.d.cts +15 -0
- package/dist/shared-DUOzjwcL.d.ts +15 -0
- package/dist/values-BetetbaH.d.cts +23 -0
- package/dist/values-BetetbaH.d.ts +23 -0
- package/dist/variant-BMrebjMw.d.cts +7 -0
- package/dist/variant-BMrebjMw.d.ts +7 -0
- package/dist/{write-DuyfnbL_.d.cts → write-BQ6SK8r8.d.cts} +2 -6
- package/dist/{write-Zqwx6pka.d.ts → write-THs7ipBq.d.ts} +2 -6
- package/package.json +1 -1
package/dist/convert/convert.cjs
CHANGED
|
@@ -8,6 +8,7 @@ const require_edit_odt_content = require("../edit/odt/content.cjs");
|
|
|
8
8
|
const require_edit_odp_content = require("../edit/odp/content.cjs");
|
|
9
9
|
const require_edit_ods_content = require("../edit/ods/content.cjs");
|
|
10
10
|
const require_edit_odg_content = require("../edit/odg/content.cjs");
|
|
11
|
+
const require_fonts_registry = require("../fonts/registry.cjs");
|
|
11
12
|
const require_mathml_layout = require("../mathml/layout.cjs");
|
|
12
13
|
const require_ooxml_docx_read = require("../ooxml/docx/read.cjs");
|
|
13
14
|
const require_ooxml_pptx_read = require("../ooxml/pptx/read.cjs");
|
|
@@ -35,9 +36,13 @@ let pdf_codec = require("pdf-codec");
|
|
|
35
36
|
//#region src/convert/convert.ts
|
|
36
37
|
function docxToPdf(bytes, options) {
|
|
37
38
|
const pkg = require_edit_docx_editor.openDocx(bytes).toPackage();
|
|
38
|
-
const content = require_ooxml_docx_read.readDocxContent(pkg);
|
|
39
|
+
const content = require_ooxml_docx_read.readDocxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic });
|
|
39
40
|
if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
|
|
40
|
-
const
|
|
41
|
+
const fonts = require_fonts_registry.createDocumentFontRegistry({
|
|
42
|
+
kind: "docx",
|
|
43
|
+
package: pkg
|
|
44
|
+
}, options);
|
|
45
|
+
const { document: layout, formulas } = require_layout_engine.convertWordprocessingToLayout(content, { measurer: (0, pdf_codec.createFontMeasurer)(fonts) });
|
|
41
46
|
options?.onDocument?.({
|
|
42
47
|
formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
43
48
|
content,
|
|
@@ -46,14 +51,19 @@ function docxToPdf(bytes, options) {
|
|
|
46
51
|
return (0, pdf_codec.writePdf)(layout, {
|
|
47
52
|
signal: options?.signal,
|
|
48
53
|
onSubstitution: options?.onSubstitution,
|
|
49
|
-
formulas
|
|
54
|
+
formulas,
|
|
55
|
+
fonts
|
|
50
56
|
});
|
|
51
57
|
}
|
|
52
58
|
function odtToPdf(bytes, options) {
|
|
53
59
|
const pkg = (0, odf_js.decodePackage)(bytes);
|
|
54
60
|
const content = require_odf_odt_read.readOdtContent(pkg);
|
|
55
61
|
if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
|
|
56
|
-
const
|
|
62
|
+
const fonts = require_fonts_registry.createDocumentFontRegistry({
|
|
63
|
+
kind: "odf",
|
|
64
|
+
package: pkg
|
|
65
|
+
}, options);
|
|
66
|
+
const { document: layout, formulas } = require_layout_engine.convertWordprocessingToLayout(content, { measurer: (0, pdf_codec.createFontMeasurer)(fonts) });
|
|
57
67
|
options?.onDocument?.({
|
|
58
68
|
formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
59
69
|
content,
|
|
@@ -62,14 +72,19 @@ function odtToPdf(bytes, options) {
|
|
|
62
72
|
return (0, pdf_codec.writePdf)(layout, {
|
|
63
73
|
signal: options?.signal,
|
|
64
74
|
onSubstitution: options?.onSubstitution,
|
|
65
|
-
formulas
|
|
75
|
+
formulas,
|
|
76
|
+
fonts
|
|
66
77
|
});
|
|
67
78
|
}
|
|
68
79
|
function pptxToPdf(bytes, options) {
|
|
69
80
|
const pkg = require_edit_pptx_editor.openPptx(bytes).toPackage();
|
|
70
81
|
const content = require_ooxml_pptx_read.readPptxContent(pkg);
|
|
71
82
|
if (content.kind !== "presentation") throw new Error("readPptxContent returned a non-presentation ContentDocument");
|
|
72
|
-
const
|
|
83
|
+
const fonts = require_fonts_registry.createDocumentFontRegistry({
|
|
84
|
+
kind: "pptx",
|
|
85
|
+
package: pkg
|
|
86
|
+
}, options);
|
|
87
|
+
const { document: layout, formulas } = require_layout_slides.convertPresentationToLayout(content, { measurer: (0, pdf_codec.createFontMeasurer)(fonts) });
|
|
73
88
|
options?.onDocument?.({
|
|
74
89
|
formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
75
90
|
content,
|
|
@@ -78,14 +93,19 @@ function pptxToPdf(bytes, options) {
|
|
|
78
93
|
return (0, pdf_codec.writePdf)(layout, {
|
|
79
94
|
signal: options?.signal,
|
|
80
95
|
onSubstitution: options?.onSubstitution,
|
|
81
|
-
formulas
|
|
96
|
+
formulas,
|
|
97
|
+
fonts
|
|
82
98
|
});
|
|
83
99
|
}
|
|
84
100
|
function odpToPdf(bytes, options) {
|
|
85
101
|
const pkg = (0, odf_js.decodePackage)(bytes);
|
|
86
102
|
const content = require_odf_odp_read.readOdpContent(pkg);
|
|
87
103
|
if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
|
|
88
|
-
const
|
|
104
|
+
const fonts = require_fonts_registry.createDocumentFontRegistry({
|
|
105
|
+
kind: "odf",
|
|
106
|
+
package: pkg
|
|
107
|
+
}, options);
|
|
108
|
+
const { document: layout, formulas } = require_layout_slides.convertPresentationToLayout(content, { measurer: (0, pdf_codec.createFontMeasurer)(fonts) });
|
|
89
109
|
options?.onDocument?.({
|
|
90
110
|
formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
91
111
|
content,
|
|
@@ -94,15 +114,20 @@ function odpToPdf(bytes, options) {
|
|
|
94
114
|
return (0, pdf_codec.writePdf)(layout, {
|
|
95
115
|
signal: options?.signal,
|
|
96
116
|
onSubstitution: options?.onSubstitution,
|
|
97
|
-
formulas
|
|
117
|
+
formulas,
|
|
118
|
+
fonts
|
|
98
119
|
});
|
|
99
120
|
}
|
|
100
121
|
function odsToPdf(bytes, options) {
|
|
101
122
|
const pkg = (0, odf_js.decodePackage)(bytes);
|
|
102
123
|
const content = require_odf_ods_read.readOdsContent(pkg);
|
|
103
124
|
if (content.kind !== "spreadsheet") throw new Error("readOdsContent returned a non-spreadsheet ContentDocument");
|
|
125
|
+
const fonts = require_fonts_registry.createDocumentFontRegistry({
|
|
126
|
+
kind: "odf",
|
|
127
|
+
package: pkg
|
|
128
|
+
}, options);
|
|
104
129
|
const layout = require_layout_sheets.convertSpreadsheetToLayout(content, {
|
|
105
|
-
measurer: (0, pdf_codec.
|
|
130
|
+
measurer: (0, pdf_codec.createFontMeasurer)(fonts),
|
|
106
131
|
signal: options?.signal
|
|
107
132
|
});
|
|
108
133
|
options?.onDocument?.({
|
|
@@ -112,14 +137,19 @@ function odsToPdf(bytes, options) {
|
|
|
112
137
|
});
|
|
113
138
|
return (0, pdf_codec.writePdf)(layout, {
|
|
114
139
|
signal: options?.signal,
|
|
115
|
-
onSubstitution: options?.onSubstitution
|
|
140
|
+
onSubstitution: options?.onSubstitution,
|
|
141
|
+
fonts
|
|
116
142
|
});
|
|
117
143
|
}
|
|
118
144
|
function odgToPdf(bytes, options) {
|
|
119
145
|
const pkg = (0, odf_js.decodePackage)(bytes);
|
|
120
146
|
const content = require_odf_odg_read.readOdgContent(pkg);
|
|
121
147
|
if (content.kind !== "drawing") throw new Error("readOdgContent returned a non-drawing ContentDocument");
|
|
122
|
-
const
|
|
148
|
+
const fonts = require_fonts_registry.createDocumentFontRegistry({
|
|
149
|
+
kind: "odf",
|
|
150
|
+
package: pkg
|
|
151
|
+
}, options);
|
|
152
|
+
const layout = require_layout_drawing.convertDrawingToLayout(content, { measurer: (0, pdf_codec.createFontMeasurer)(fonts) });
|
|
123
153
|
options?.onDocument?.({
|
|
124
154
|
formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
125
155
|
content,
|
|
@@ -127,7 +157,8 @@ function odgToPdf(bytes, options) {
|
|
|
127
157
|
});
|
|
128
158
|
return (0, pdf_codec.writePdf)(layout, {
|
|
129
159
|
signal: options?.signal,
|
|
130
|
-
onSubstitution: options?.onSubstitution
|
|
160
|
+
onSubstitution: options?.onSubstitution,
|
|
161
|
+
fonts
|
|
131
162
|
});
|
|
132
163
|
}
|
|
133
164
|
function markdownToPdf(bytes, options) {
|
|
@@ -135,7 +166,11 @@ function markdownToPdf(bytes, options) {
|
|
|
135
166
|
const text = require_markdown_text.decodeMarkdownText(bytes);
|
|
136
167
|
const content = require_markdown_read.readMarkdownContent(text, { signal: options?.signal });
|
|
137
168
|
if (content.kind !== "wordprocessing") throw new Error("readMarkdownContent returned a non-wordprocessing ContentDocument");
|
|
138
|
-
const
|
|
169
|
+
const fonts = (0, pdf_codec.createFontRegistry)({
|
|
170
|
+
fonts: options?.fonts,
|
|
171
|
+
onSubstitution: options?.onFontSubstitution
|
|
172
|
+
});
|
|
173
|
+
const { document: layout, formulas } = require_layout_engine.convertWordprocessingToLayout(content, { measurer: (0, pdf_codec.createFontMeasurer)(fonts) });
|
|
139
174
|
options?.onDocument?.({
|
|
140
175
|
formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
141
176
|
content,
|
|
@@ -144,7 +179,8 @@ function markdownToPdf(bytes, options) {
|
|
|
144
179
|
return (0, pdf_codec.writePdf)(layout, {
|
|
145
180
|
signal: options?.signal,
|
|
146
181
|
onSubstitution: options?.onSubstitution,
|
|
147
|
-
formulas
|
|
182
|
+
formulas,
|
|
183
|
+
fonts
|
|
148
184
|
});
|
|
149
185
|
}
|
|
150
186
|
const STANDALONE_FORMULA_SIZE_PT = 18;
|
|
@@ -299,7 +335,7 @@ function odtToDocx(bytes, options) {
|
|
|
299
335
|
function docxToOdt(bytes, options) {
|
|
300
336
|
require_ports_abort.throwIfAborted(options?.signal);
|
|
301
337
|
const pkg = (0, ooxml_js.decodePackage)(bytes);
|
|
302
|
-
const content = require_ooxml_docx_read.readDocxContent(pkg);
|
|
338
|
+
const content = require_ooxml_docx_read.readDocxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic });
|
|
303
339
|
if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
|
|
304
340
|
require_ports_abort.throwIfAborted(options?.signal);
|
|
305
341
|
options?.onDocument?.({
|
|
@@ -371,7 +407,7 @@ function markdownToDocx(bytes, options) {
|
|
|
371
407
|
function docxToMarkdown(bytes, options) {
|
|
372
408
|
require_ports_abort.throwIfAborted(options?.signal);
|
|
373
409
|
const pkg = (0, ooxml_js.decodePackage)(bytes);
|
|
374
|
-
const content = require_ooxml_docx_read.readDocxContent(pkg);
|
|
410
|
+
const content = require_ooxml_docx_read.readDocxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic });
|
|
375
411
|
if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
|
|
376
412
|
require_ports_abort.throwIfAborted(options?.signal);
|
|
377
413
|
options?.onDocument?.({
|
|
@@ -413,7 +449,9 @@ function xlsxToPdf(bytes, options) {
|
|
|
413
449
|
return odsToPdf(odsBytes, {
|
|
414
450
|
signal: options?.signal,
|
|
415
451
|
onSubstitution: options?.onSubstitution,
|
|
416
|
-
onDocument: options?.onDocument
|
|
452
|
+
onDocument: options?.onDocument,
|
|
453
|
+
fonts: options?.fonts,
|
|
454
|
+
onFontSubstitution: options?.onFontSubstitution
|
|
417
455
|
});
|
|
418
456
|
}
|
|
419
457
|
function pdfToXlsx(bytes, options) {
|
|
@@ -469,6 +507,10 @@ function odmToPdf(bytes, options) {
|
|
|
469
507
|
const odm = (0, odf_js.readOdm)(pkg);
|
|
470
508
|
const unresolvedHrefs = [];
|
|
471
509
|
const chapterSections = [];
|
|
510
|
+
const sourceFonts = require_fonts_registry.extractSourceFonts({
|
|
511
|
+
kind: "odf",
|
|
512
|
+
package: pkg
|
|
513
|
+
});
|
|
472
514
|
for (const section of odm.sections) {
|
|
473
515
|
require_ports_abort.throwIfAborted(options?.signal);
|
|
474
516
|
if (section.inlineContent !== void 0) {
|
|
@@ -481,6 +523,10 @@ function odmToPdf(bytes, options) {
|
|
|
481
523
|
continue;
|
|
482
524
|
}
|
|
483
525
|
const chapterPkg = (0, odf_js.decodePackage)(chapterBytes);
|
|
526
|
+
sourceFonts.push(...require_fonts_registry.extractSourceFonts({
|
|
527
|
+
kind: "odf",
|
|
528
|
+
package: chapterPkg
|
|
529
|
+
}));
|
|
484
530
|
const chapterContent = require_odf_odt_read.readOdtContent(chapterPkg);
|
|
485
531
|
if (chapterContent.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
|
|
486
532
|
chapterSections.push(chapterContent.sections);
|
|
@@ -501,11 +547,17 @@ function odmToPdf(bytes, options) {
|
|
|
501
547
|
metadata: (0, odf_js.readOdfMetadata)(pkg),
|
|
502
548
|
sections: combinedSections
|
|
503
549
|
};
|
|
504
|
-
const
|
|
550
|
+
const fonts = (0, pdf_codec.createFontRegistry)({
|
|
551
|
+
sourceFonts,
|
|
552
|
+
fonts: options?.fonts,
|
|
553
|
+
onSubstitution: options?.onFontSubstitution
|
|
554
|
+
});
|
|
555
|
+
const { document: layout, formulas } = require_layout_engine.convertWordprocessingToLayout(content, { measurer: (0, pdf_codec.createFontMeasurer)(fonts) });
|
|
505
556
|
return (0, pdf_codec.writePdf)(layout, {
|
|
506
557
|
signal: options?.signal,
|
|
507
558
|
onSubstitution: options?.onSubstitution,
|
|
508
|
-
formulas
|
|
559
|
+
formulas,
|
|
560
|
+
fonts
|
|
509
561
|
});
|
|
510
562
|
}
|
|
511
563
|
function odbToXlsx(bytes, options) {
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { n as HsqldbDecodeOptions } from "../rowformat-Cl2exlEh.cjs";
|
|
2
|
-
import { t as OmmlDiagnostic } from "../
|
|
2
|
+
import { t as OmmlDiagnostic } from "../shared-DLZ3IQUl.cjs";
|
|
3
|
+
import { t as DocumentFontRegistryOptions } from "../registry-lqJej0Jr.cjs";
|
|
3
4
|
import { ContentSection, DocumentPackage } from "document-schema.js";
|
|
4
5
|
import { OdmSection, Package } from "odf.js";
|
|
5
6
|
import { PdfDiagnosticSink, WinAnsiSubstitution } from "pdf-codec";
|
|
6
7
|
//#region src/convert/convert.d.ts
|
|
7
|
-
interface DocumentToPdfOptions {
|
|
8
|
+
interface DocumentToPdfOptions extends DocumentFontRegistryOptions {
|
|
8
9
|
readonly signal?: AbortSignal;
|
|
9
10
|
readonly onSubstitution?: (substitution: WinAnsiSubstitution, context: {
|
|
10
11
|
readonly pageIndex: number;
|
|
11
12
|
}) => void;
|
|
12
13
|
readonly onDocument?: (pkg: DocumentPackage) => void;
|
|
14
|
+
readonly onMathDiagnostic?: (diagnostic: OmmlDiagnostic, context: {
|
|
15
|
+
readonly sourcePath?: string;
|
|
16
|
+
}) => void;
|
|
13
17
|
}
|
|
14
18
|
declare function docxToPdf(bytes: Uint8Array<ArrayBuffer>, options?: DocumentToPdfOptions): Uint8Array<ArrayBuffer>;
|
|
15
19
|
declare function odtToPdf(bytes: Uint8Array<ArrayBuffer>, options?: DocumentToPdfOptions): Uint8Array<ArrayBuffer>;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { n as HsqldbDecodeOptions } from "../rowformat-Cl2exlEh.js";
|
|
2
|
-
import { t as OmmlDiagnostic } from "../
|
|
2
|
+
import { t as OmmlDiagnostic } from "../shared-DUOzjwcL.js";
|
|
3
|
+
import { t as DocumentFontRegistryOptions } from "../registry-CrSqLIcn.js";
|
|
3
4
|
import { ContentSection, DocumentPackage } from "document-schema.js";
|
|
4
5
|
import { OdmSection, Package } from "odf.js";
|
|
5
6
|
import { PdfDiagnosticSink, WinAnsiSubstitution } from "pdf-codec";
|
|
6
7
|
//#region src/convert/convert.d.ts
|
|
7
|
-
interface DocumentToPdfOptions {
|
|
8
|
+
interface DocumentToPdfOptions extends DocumentFontRegistryOptions {
|
|
8
9
|
readonly signal?: AbortSignal;
|
|
9
10
|
readonly onSubstitution?: (substitution: WinAnsiSubstitution, context: {
|
|
10
11
|
readonly pageIndex: number;
|
|
11
12
|
}) => void;
|
|
12
13
|
readonly onDocument?: (pkg: DocumentPackage) => void;
|
|
14
|
+
readonly onMathDiagnostic?: (diagnostic: OmmlDiagnostic, context: {
|
|
15
|
+
readonly sourcePath?: string;
|
|
16
|
+
}) => void;
|
|
13
17
|
}
|
|
14
18
|
declare function docxToPdf(bytes: Uint8Array<ArrayBuffer>, options?: DocumentToPdfOptions): Uint8Array<ArrayBuffer>;
|
|
15
19
|
declare function odtToPdf(bytes: Uint8Array<ArrayBuffer>, options?: DocumentToPdfOptions): Uint8Array<ArrayBuffer>;
|
package/dist/convert/convert.js
CHANGED
|
@@ -7,6 +7,7 @@ import { buildOdtPackage } from "../edit/odt/content.js";
|
|
|
7
7
|
import { buildOdpPackage } from "../edit/odp/content.js";
|
|
8
8
|
import { buildOdsPackage } from "../edit/ods/content.js";
|
|
9
9
|
import { buildOdgPackage } from "../edit/odg/content.js";
|
|
10
|
+
import { createDocumentFontRegistry, extractSourceFonts } from "../fonts/registry.js";
|
|
10
11
|
import { layoutFormula } from "../mathml/layout.js";
|
|
11
12
|
import { readDocxContent } from "../ooxml/docx/read.js";
|
|
12
13
|
import { readPptxContent } from "../ooxml/pptx/read.js";
|
|
@@ -30,13 +31,17 @@ import { odbTablesToSpreadsheetDocument } from "../odb/spreadsheet.js";
|
|
|
30
31
|
import { buildXlsxPackage, decodePackage, encodePackage, readXlsxContent } from "ooxml.js";
|
|
31
32
|
import { COLOR_BLACK, CONTENT_FORMAT_VERSION, DOCUMENT_PACKAGE_FORMAT_VERSION, LAYOUT_FORMAT_VERSION } from "document-schema.js";
|
|
32
33
|
import { decodePackage as decodePackage$1, encodePackage as encodePackage$1, readOdfMetadata, readOdfParagraph, readOdfTable, readOdm } from "odf.js";
|
|
33
|
-
import {
|
|
34
|
+
import { createFontMeasurer, createFontRegistry, loadMathFont, readPdf, writePdf } from "pdf-codec";
|
|
34
35
|
//#region src/convert/convert.ts
|
|
35
36
|
function docxToPdf(bytes, options) {
|
|
36
37
|
const pkg = openDocx(bytes).toPackage();
|
|
37
|
-
const content = readDocxContent(pkg);
|
|
38
|
+
const content = readDocxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic });
|
|
38
39
|
if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
|
|
39
|
-
const
|
|
40
|
+
const fonts = createDocumentFontRegistry({
|
|
41
|
+
kind: "docx",
|
|
42
|
+
package: pkg
|
|
43
|
+
}, options);
|
|
44
|
+
const { document: layout, formulas } = convertWordprocessingToLayout(content, { measurer: createFontMeasurer(fonts) });
|
|
40
45
|
options?.onDocument?.({
|
|
41
46
|
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
42
47
|
content,
|
|
@@ -45,14 +50,19 @@ function docxToPdf(bytes, options) {
|
|
|
45
50
|
return writePdf(layout, {
|
|
46
51
|
signal: options?.signal,
|
|
47
52
|
onSubstitution: options?.onSubstitution,
|
|
48
|
-
formulas
|
|
53
|
+
formulas,
|
|
54
|
+
fonts
|
|
49
55
|
});
|
|
50
56
|
}
|
|
51
57
|
function odtToPdf(bytes, options) {
|
|
52
58
|
const pkg = decodePackage$1(bytes);
|
|
53
59
|
const content = readOdtContent(pkg);
|
|
54
60
|
if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
|
|
55
|
-
const
|
|
61
|
+
const fonts = createDocumentFontRegistry({
|
|
62
|
+
kind: "odf",
|
|
63
|
+
package: pkg
|
|
64
|
+
}, options);
|
|
65
|
+
const { document: layout, formulas } = convertWordprocessingToLayout(content, { measurer: createFontMeasurer(fonts) });
|
|
56
66
|
options?.onDocument?.({
|
|
57
67
|
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
58
68
|
content,
|
|
@@ -61,14 +71,19 @@ function odtToPdf(bytes, options) {
|
|
|
61
71
|
return writePdf(layout, {
|
|
62
72
|
signal: options?.signal,
|
|
63
73
|
onSubstitution: options?.onSubstitution,
|
|
64
|
-
formulas
|
|
74
|
+
formulas,
|
|
75
|
+
fonts
|
|
65
76
|
});
|
|
66
77
|
}
|
|
67
78
|
function pptxToPdf(bytes, options) {
|
|
68
79
|
const pkg = openPptx(bytes).toPackage();
|
|
69
80
|
const content = readPptxContent(pkg);
|
|
70
81
|
if (content.kind !== "presentation") throw new Error("readPptxContent returned a non-presentation ContentDocument");
|
|
71
|
-
const
|
|
82
|
+
const fonts = createDocumentFontRegistry({
|
|
83
|
+
kind: "pptx",
|
|
84
|
+
package: pkg
|
|
85
|
+
}, options);
|
|
86
|
+
const { document: layout, formulas } = convertPresentationToLayout(content, { measurer: createFontMeasurer(fonts) });
|
|
72
87
|
options?.onDocument?.({
|
|
73
88
|
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
74
89
|
content,
|
|
@@ -77,14 +92,19 @@ function pptxToPdf(bytes, options) {
|
|
|
77
92
|
return writePdf(layout, {
|
|
78
93
|
signal: options?.signal,
|
|
79
94
|
onSubstitution: options?.onSubstitution,
|
|
80
|
-
formulas
|
|
95
|
+
formulas,
|
|
96
|
+
fonts
|
|
81
97
|
});
|
|
82
98
|
}
|
|
83
99
|
function odpToPdf(bytes, options) {
|
|
84
100
|
const pkg = decodePackage$1(bytes);
|
|
85
101
|
const content = readOdpContent(pkg);
|
|
86
102
|
if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
|
|
87
|
-
const
|
|
103
|
+
const fonts = createDocumentFontRegistry({
|
|
104
|
+
kind: "odf",
|
|
105
|
+
package: pkg
|
|
106
|
+
}, options);
|
|
107
|
+
const { document: layout, formulas } = convertPresentationToLayout(content, { measurer: createFontMeasurer(fonts) });
|
|
88
108
|
options?.onDocument?.({
|
|
89
109
|
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
90
110
|
content,
|
|
@@ -93,15 +113,20 @@ function odpToPdf(bytes, options) {
|
|
|
93
113
|
return writePdf(layout, {
|
|
94
114
|
signal: options?.signal,
|
|
95
115
|
onSubstitution: options?.onSubstitution,
|
|
96
|
-
formulas
|
|
116
|
+
formulas,
|
|
117
|
+
fonts
|
|
97
118
|
});
|
|
98
119
|
}
|
|
99
120
|
function odsToPdf(bytes, options) {
|
|
100
121
|
const pkg = decodePackage$1(bytes);
|
|
101
122
|
const content = readOdsContent(pkg);
|
|
102
123
|
if (content.kind !== "spreadsheet") throw new Error("readOdsContent returned a non-spreadsheet ContentDocument");
|
|
124
|
+
const fonts = createDocumentFontRegistry({
|
|
125
|
+
kind: "odf",
|
|
126
|
+
package: pkg
|
|
127
|
+
}, options);
|
|
103
128
|
const layout = convertSpreadsheetToLayout(content, {
|
|
104
|
-
measurer:
|
|
129
|
+
measurer: createFontMeasurer(fonts),
|
|
105
130
|
signal: options?.signal
|
|
106
131
|
});
|
|
107
132
|
options?.onDocument?.({
|
|
@@ -111,14 +136,19 @@ function odsToPdf(bytes, options) {
|
|
|
111
136
|
});
|
|
112
137
|
return writePdf(layout, {
|
|
113
138
|
signal: options?.signal,
|
|
114
|
-
onSubstitution: options?.onSubstitution
|
|
139
|
+
onSubstitution: options?.onSubstitution,
|
|
140
|
+
fonts
|
|
115
141
|
});
|
|
116
142
|
}
|
|
117
143
|
function odgToPdf(bytes, options) {
|
|
118
144
|
const pkg = decodePackage$1(bytes);
|
|
119
145
|
const content = readOdgContent(pkg);
|
|
120
146
|
if (content.kind !== "drawing") throw new Error("readOdgContent returned a non-drawing ContentDocument");
|
|
121
|
-
const
|
|
147
|
+
const fonts = createDocumentFontRegistry({
|
|
148
|
+
kind: "odf",
|
|
149
|
+
package: pkg
|
|
150
|
+
}, options);
|
|
151
|
+
const layout = convertDrawingToLayout(content, { measurer: createFontMeasurer(fonts) });
|
|
122
152
|
options?.onDocument?.({
|
|
123
153
|
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
124
154
|
content,
|
|
@@ -126,7 +156,8 @@ function odgToPdf(bytes, options) {
|
|
|
126
156
|
});
|
|
127
157
|
return writePdf(layout, {
|
|
128
158
|
signal: options?.signal,
|
|
129
|
-
onSubstitution: options?.onSubstitution
|
|
159
|
+
onSubstitution: options?.onSubstitution,
|
|
160
|
+
fonts
|
|
130
161
|
});
|
|
131
162
|
}
|
|
132
163
|
function markdownToPdf(bytes, options) {
|
|
@@ -134,7 +165,11 @@ function markdownToPdf(bytes, options) {
|
|
|
134
165
|
const text = decodeMarkdownText(bytes);
|
|
135
166
|
const content = readMarkdownContent(text, { signal: options?.signal });
|
|
136
167
|
if (content.kind !== "wordprocessing") throw new Error("readMarkdownContent returned a non-wordprocessing ContentDocument");
|
|
137
|
-
const
|
|
168
|
+
const fonts = createFontRegistry({
|
|
169
|
+
fonts: options?.fonts,
|
|
170
|
+
onSubstitution: options?.onFontSubstitution
|
|
171
|
+
});
|
|
172
|
+
const { document: layout, formulas } = convertWordprocessingToLayout(content, { measurer: createFontMeasurer(fonts) });
|
|
138
173
|
options?.onDocument?.({
|
|
139
174
|
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
140
175
|
content,
|
|
@@ -143,7 +178,8 @@ function markdownToPdf(bytes, options) {
|
|
|
143
178
|
return writePdf(layout, {
|
|
144
179
|
signal: options?.signal,
|
|
145
180
|
onSubstitution: options?.onSubstitution,
|
|
146
|
-
formulas
|
|
181
|
+
formulas,
|
|
182
|
+
fonts
|
|
147
183
|
});
|
|
148
184
|
}
|
|
149
185
|
const STANDALONE_FORMULA_SIZE_PT = 18;
|
|
@@ -298,7 +334,7 @@ function odtToDocx(bytes, options) {
|
|
|
298
334
|
function docxToOdt(bytes, options) {
|
|
299
335
|
throwIfAborted(options?.signal);
|
|
300
336
|
const pkg = decodePackage(bytes);
|
|
301
|
-
const content = readDocxContent(pkg);
|
|
337
|
+
const content = readDocxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic });
|
|
302
338
|
if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
|
|
303
339
|
throwIfAborted(options?.signal);
|
|
304
340
|
options?.onDocument?.({
|
|
@@ -370,7 +406,7 @@ function markdownToDocx(bytes, options) {
|
|
|
370
406
|
function docxToMarkdown(bytes, options) {
|
|
371
407
|
throwIfAborted(options?.signal);
|
|
372
408
|
const pkg = decodePackage(bytes);
|
|
373
|
-
const content = readDocxContent(pkg);
|
|
409
|
+
const content = readDocxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic });
|
|
374
410
|
if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
|
|
375
411
|
throwIfAborted(options?.signal);
|
|
376
412
|
options?.onDocument?.({
|
|
@@ -412,7 +448,9 @@ function xlsxToPdf(bytes, options) {
|
|
|
412
448
|
return odsToPdf(odsBytes, {
|
|
413
449
|
signal: options?.signal,
|
|
414
450
|
onSubstitution: options?.onSubstitution,
|
|
415
|
-
onDocument: options?.onDocument
|
|
451
|
+
onDocument: options?.onDocument,
|
|
452
|
+
fonts: options?.fonts,
|
|
453
|
+
onFontSubstitution: options?.onFontSubstitution
|
|
416
454
|
});
|
|
417
455
|
}
|
|
418
456
|
function pdfToXlsx(bytes, options) {
|
|
@@ -468,6 +506,10 @@ function odmToPdf(bytes, options) {
|
|
|
468
506
|
const odm = readOdm(pkg);
|
|
469
507
|
const unresolvedHrefs = [];
|
|
470
508
|
const chapterSections = [];
|
|
509
|
+
const sourceFonts = extractSourceFonts({
|
|
510
|
+
kind: "odf",
|
|
511
|
+
package: pkg
|
|
512
|
+
});
|
|
471
513
|
for (const section of odm.sections) {
|
|
472
514
|
throwIfAborted(options?.signal);
|
|
473
515
|
if (section.inlineContent !== void 0) {
|
|
@@ -480,6 +522,10 @@ function odmToPdf(bytes, options) {
|
|
|
480
522
|
continue;
|
|
481
523
|
}
|
|
482
524
|
const chapterPkg = decodePackage$1(chapterBytes);
|
|
525
|
+
sourceFonts.push(...extractSourceFonts({
|
|
526
|
+
kind: "odf",
|
|
527
|
+
package: chapterPkg
|
|
528
|
+
}));
|
|
483
529
|
const chapterContent = readOdtContent(chapterPkg);
|
|
484
530
|
if (chapterContent.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
|
|
485
531
|
chapterSections.push(chapterContent.sections);
|
|
@@ -500,11 +546,17 @@ function odmToPdf(bytes, options) {
|
|
|
500
546
|
metadata: readOdfMetadata(pkg),
|
|
501
547
|
sections: combinedSections
|
|
502
548
|
};
|
|
503
|
-
const
|
|
549
|
+
const fonts = createFontRegistry({
|
|
550
|
+
sourceFonts,
|
|
551
|
+
fonts: options?.fonts,
|
|
552
|
+
onSubstitution: options?.onFontSubstitution
|
|
553
|
+
});
|
|
554
|
+
const { document: layout, formulas } = convertWordprocessingToLayout(content, { measurer: createFontMeasurer(fonts) });
|
|
504
555
|
return writePdf(layout, {
|
|
505
556
|
signal: options?.signal,
|
|
506
557
|
onSubstitution: options?.onSubstitution,
|
|
507
|
-
formulas
|
|
558
|
+
formulas,
|
|
559
|
+
fonts
|
|
508
560
|
});
|
|
509
561
|
}
|
|
510
562
|
function odbToXlsx(bytes, options) {
|
package/dist/convert/local.cjs
CHANGED
|
@@ -13,6 +13,13 @@ function substitutionDiagnostic(substitution, context) {
|
|
|
13
13
|
pageIndex: context.pageIndex
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
+
function fontSubstitutionDiagnostic(substitution) {
|
|
17
|
+
return {
|
|
18
|
+
severity: "info",
|
|
19
|
+
code: "font/substituted",
|
|
20
|
+
message: `"${`${substitution.requestedFamily}${substitution.requestedBold ? " bold" : ""}${substitution.requestedItalic ? " italic" : ""}`}" is not available; ${substitution.reason === "vendored-substitute" ? `substituted the metric-compatible "${substitution.resolvedFamily}"` : `substituted another face of "${substitution.resolvedFamily}"`}`
|
|
21
|
+
};
|
|
22
|
+
}
|
|
16
23
|
function fromPdfDiagnostic(diagnostic) {
|
|
17
24
|
return {
|
|
18
25
|
severity: diagnostic.severity,
|
|
@@ -23,7 +30,7 @@ function fromPdfDiagnostic(diagnostic) {
|
|
|
23
30
|
}
|
|
24
31
|
function createLocalDocumentConverter() {
|
|
25
32
|
return {
|
|
26
|
-
contractVersion:
|
|
33
|
+
contractVersion: 3,
|
|
27
34
|
conversions: SUPPORTED_CONVERSIONS,
|
|
28
35
|
convert(request, options) {
|
|
29
36
|
const { source, targetFormat } = request;
|
|
@@ -32,6 +39,10 @@ function createLocalDocumentConverter() {
|
|
|
32
39
|
const onDocument = (pkg) => {
|
|
33
40
|
documentPackage = pkg;
|
|
34
41
|
};
|
|
42
|
+
const onFontSubstitution = (substitution) => {
|
|
43
|
+
diagnostics.push(fontSubstitutionDiagnostic(substitution));
|
|
44
|
+
options.onFontSubstitution?.(substitution);
|
|
45
|
+
};
|
|
35
46
|
const strategy = require_convert_capability.resolveConversionPath(source.format, targetFormat);
|
|
36
47
|
if (strategy?.kind !== "direct") return Promise.reject(/* @__PURE__ */ new Error(`unsupported conversion: ${source.format} -> ${targetFormat}`));
|
|
37
48
|
const edge = strategy.edge;
|
|
@@ -39,7 +50,9 @@ function createLocalDocumentConverter() {
|
|
|
39
50
|
const bytes = edge.convert(source.bytes, {
|
|
40
51
|
signal: options.signal,
|
|
41
52
|
onSubstitution: (s, c) => diagnostics.push(substitutionDiagnostic(s, c)),
|
|
42
|
-
onDocument
|
|
53
|
+
onDocument,
|
|
54
|
+
fonts: options.fonts,
|
|
55
|
+
onFontSubstitution
|
|
43
56
|
});
|
|
44
57
|
return Promise.resolve({
|
|
45
58
|
document: {
|
package/dist/convert/local.js
CHANGED
|
@@ -12,6 +12,13 @@ function substitutionDiagnostic(substitution, context) {
|
|
|
12
12
|
pageIndex: context.pageIndex
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
+
function fontSubstitutionDiagnostic(substitution) {
|
|
16
|
+
return {
|
|
17
|
+
severity: "info",
|
|
18
|
+
code: "font/substituted",
|
|
19
|
+
message: `"${`${substitution.requestedFamily}${substitution.requestedBold ? " bold" : ""}${substitution.requestedItalic ? " italic" : ""}`}" is not available; ${substitution.reason === "vendored-substitute" ? `substituted the metric-compatible "${substitution.resolvedFamily}"` : `substituted another face of "${substitution.resolvedFamily}"`}`
|
|
20
|
+
};
|
|
21
|
+
}
|
|
15
22
|
function fromPdfDiagnostic(diagnostic) {
|
|
16
23
|
return {
|
|
17
24
|
severity: diagnostic.severity,
|
|
@@ -22,7 +29,7 @@ function fromPdfDiagnostic(diagnostic) {
|
|
|
22
29
|
}
|
|
23
30
|
function createLocalDocumentConverter() {
|
|
24
31
|
return {
|
|
25
|
-
contractVersion:
|
|
32
|
+
contractVersion: 3,
|
|
26
33
|
conversions: SUPPORTED_CONVERSIONS,
|
|
27
34
|
convert(request, options) {
|
|
28
35
|
const { source, targetFormat } = request;
|
|
@@ -31,6 +38,10 @@ function createLocalDocumentConverter() {
|
|
|
31
38
|
const onDocument = (pkg) => {
|
|
32
39
|
documentPackage = pkg;
|
|
33
40
|
};
|
|
41
|
+
const onFontSubstitution = (substitution) => {
|
|
42
|
+
diagnostics.push(fontSubstitutionDiagnostic(substitution));
|
|
43
|
+
options.onFontSubstitution?.(substitution);
|
|
44
|
+
};
|
|
34
45
|
const strategy = resolveConversionPath(source.format, targetFormat);
|
|
35
46
|
if (strategy?.kind !== "direct") return Promise.reject(/* @__PURE__ */ new Error(`unsupported conversion: ${source.format} -> ${targetFormat}`));
|
|
36
47
|
const edge = strategy.edge;
|
|
@@ -38,7 +49,9 @@ function createLocalDocumentConverter() {
|
|
|
38
49
|
const bytes = edge.convert(source.bytes, {
|
|
39
50
|
signal: options.signal,
|
|
40
51
|
onSubstitution: (s, c) => diagnostics.push(substitutionDiagnostic(s, c)),
|
|
41
|
-
onDocument
|
|
52
|
+
onDocument,
|
|
53
|
+
fonts: options.fonts,
|
|
54
|
+
onFontSubstitution
|
|
42
55
|
});
|
|
43
56
|
return Promise.resolve({
|
|
44
57
|
document: {
|
package/dist/convert/port.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DocumentPackage } from "document-schema.js";
|
|
2
|
+
import { FontSubstitution, ProvidedFont } from "pdf-codec";
|
|
2
3
|
//#region src/convert/port.d.ts
|
|
3
4
|
type DocumentFormat = 'docx' | 'pptx' | 'xlsx' | 'odt' | 'odp' | 'ods' | 'odg' | 'odf' | 'markdown' | 'pdf';
|
|
4
5
|
interface DocumentPayload {
|
|
@@ -20,15 +21,18 @@ interface ConversionResult {
|
|
|
20
21
|
readonly diagnostics: readonly Diagnostic[];
|
|
21
22
|
readonly package?: DocumentPackage;
|
|
22
23
|
}
|
|
24
|
+
interface ConversionOptions {
|
|
25
|
+
readonly signal: AbortSignal;
|
|
26
|
+
readonly fonts?: readonly ProvidedFont[];
|
|
27
|
+
readonly onFontSubstitution?: (substitution: FontSubstitution) => void;
|
|
28
|
+
}
|
|
23
29
|
interface DocumentConverter {
|
|
24
30
|
readonly contractVersion: number;
|
|
25
31
|
readonly conversions: readonly {
|
|
26
32
|
readonly source: DocumentFormat;
|
|
27
33
|
readonly target: DocumentFormat;
|
|
28
34
|
}[];
|
|
29
|
-
convert(request: ConversionRequest, options:
|
|
30
|
-
readonly signal: AbortSignal;
|
|
31
|
-
}): Promise<ConversionResult>;
|
|
35
|
+
convert(request: ConversionRequest, options: ConversionOptions): Promise<ConversionResult>;
|
|
32
36
|
}
|
|
33
37
|
//#endregion
|
|
34
|
-
export { ConversionRequest, ConversionResult, Diagnostic, DocumentConverter, DocumentFormat, DocumentPayload };
|
|
38
|
+
export { ConversionOptions, ConversionRequest, ConversionResult, Diagnostic, DocumentConverter, DocumentFormat, DocumentPayload };
|
package/dist/convert/port.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DocumentPackage } from "document-schema.js";
|
|
2
|
+
import { FontSubstitution, ProvidedFont } from "pdf-codec";
|
|
2
3
|
//#region src/convert/port.d.ts
|
|
3
4
|
type DocumentFormat = 'docx' | 'pptx' | 'xlsx' | 'odt' | 'odp' | 'ods' | 'odg' | 'odf' | 'markdown' | 'pdf';
|
|
4
5
|
interface DocumentPayload {
|
|
@@ -20,15 +21,18 @@ interface ConversionResult {
|
|
|
20
21
|
readonly diagnostics: readonly Diagnostic[];
|
|
21
22
|
readonly package?: DocumentPackage;
|
|
22
23
|
}
|
|
24
|
+
interface ConversionOptions {
|
|
25
|
+
readonly signal: AbortSignal;
|
|
26
|
+
readonly fonts?: readonly ProvidedFont[];
|
|
27
|
+
readonly onFontSubstitution?: (substitution: FontSubstitution) => void;
|
|
28
|
+
}
|
|
23
29
|
interface DocumentConverter {
|
|
24
30
|
readonly contractVersion: number;
|
|
25
31
|
readonly conversions: readonly {
|
|
26
32
|
readonly source: DocumentFormat;
|
|
27
33
|
readonly target: DocumentFormat;
|
|
28
34
|
}[];
|
|
29
|
-
convert(request: ConversionRequest, options:
|
|
30
|
-
readonly signal: AbortSignal;
|
|
31
|
-
}): Promise<ConversionResult>;
|
|
35
|
+
convert(request: ConversionRequest, options: ConversionOptions): Promise<ConversionResult>;
|
|
32
36
|
}
|
|
33
37
|
//#endregion
|
|
34
|
-
export { ConversionRequest, ConversionResult, Diagnostic, DocumentConverter, DocumentFormat, DocumentPayload };
|
|
38
|
+
export { ConversionOptions, ConversionRequest, ConversionResult, Diagnostic, DocumentConverter, DocumentFormat, DocumentPayload };
|