abstract-document 14.0.11 → 14.0.12
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/lib/abstract-document/index.d.ts +44 -45
- package/lib/abstract-document/index.d.ts.map +1 -1
- package/lib/abstract-document/index.js +45 -89
- package/lib/abstract-document/index.js.map +1 -1
- package/lib/abstract-document/resources.js +5 -38
- package/lib/abstract-document/resources.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.d.ts +4 -3
- package/lib/abstract-document-exporters/docx2/render-image.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.js +2 -35
- package/lib/abstract-document-exporters/docx2/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx2/render.js +51 -56
- package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
- package/lib/abstract-document-exporters/index.d.ts +2 -3
- package/lib/abstract-document-exporters/index.d.ts.map +1 -1
- package/lib/abstract-document-exporters/index.js +2 -4
- package/lib/abstract-document-exporters/index.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.js +3 -3
- package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/shared/get_resources.d.ts +3 -2
- package/lib/abstract-document-exporters/shared/get_resources.d.ts.map +1 -1
- package/lib/abstract-document-exporters/shared/get_resources.js +10 -43
- package/lib/abstract-document-exporters/shared/get_resources.js.map +1 -1
- package/lib/abstract-document-jsx/index.d.ts +1 -1
- package/lib/abstract-document-jsx/index.d.ts.map +1 -1
- package/lib/abstract-document-xml/mustache-xml/parse-mustache-xml.d.ts +2 -2
- package/lib/abstract-document-xml/mustache-xml/parse-mustache-xml.d.ts.map +1 -1
- package/lib/abstract-document-xml/mustache-xml/parse-mustache-xml.js +4 -37
- package/lib/abstract-document-xml/mustache-xml/parse-mustache-xml.js.map +1 -1
- package/lib/abstract-document-xml/mustache-xml/validate-mustache-xml.js +2 -35
- package/lib/abstract-document-xml/mustache-xml/validate-mustache-xml.js.map +1 -1
- package/lib/index.d.ts +4 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -8
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/abstract-document/index.ts +44 -91
- package/src/abstract-document/resources.ts +5 -5
- package/src/abstract-document-exporters/docx2/render-image.ts +7 -6
- package/src/abstract-document-exporters/docx2/render.ts +111 -87
- package/src/abstract-document-exporters/index.ts +2 -5
- package/src/abstract-document-exporters/pdf/render-image.ts +3 -3
- package/src/abstract-document-exporters/shared/get_resources.ts +27 -19
- package/src/abstract-document-jsx/index.ts +1 -1
- package/src/abstract-document-xml/mustache-xml/parse-mustache-xml.ts +5 -5
- package/src/abstract-document-xml/mustache-xml/validate-mustache-xml.ts +3 -3
- package/src/index.ts +4 -6
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
import * as AD from "../../abstract-document/index.js";
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
Packer,
|
|
4
|
+
Document,
|
|
5
|
+
ISectionOptions,
|
|
6
|
+
Paragraph,
|
|
7
|
+
Table,
|
|
8
|
+
Bookmark,
|
|
9
|
+
PageOrientation,
|
|
10
|
+
Header,
|
|
11
|
+
Footer,
|
|
12
|
+
InternalHyperlink,
|
|
13
|
+
ExternalHyperlink,
|
|
14
|
+
TextRun,
|
|
15
|
+
UnderlineType,
|
|
16
|
+
AlignmentType,
|
|
17
|
+
WidthType,
|
|
18
|
+
BorderStyle,
|
|
19
|
+
TableRow,
|
|
20
|
+
TableCell,
|
|
21
|
+
VerticalAlign,
|
|
22
|
+
ImageRun,
|
|
23
|
+
SymbolRun,
|
|
24
|
+
PageBreak,
|
|
25
|
+
SequentialIdentifier,
|
|
26
|
+
FootnoteReferenceRun,
|
|
27
|
+
InsertedTextRun,
|
|
28
|
+
DeletedTextRun,
|
|
29
|
+
Math as MathDocX,
|
|
30
|
+
PageNumber,
|
|
31
|
+
} from "docx";
|
|
3
32
|
import { renderImage } from "./render-image.js";
|
|
4
33
|
import { Readable } from "stream";
|
|
5
34
|
|
|
@@ -9,7 +38,7 @@ const abstractDocPixelToDocxDXARatio = 20;
|
|
|
9
38
|
export function exportToHTML5Blob(doc: AD.AbstractDoc.AbstractDoc): Promise<Blob> {
|
|
10
39
|
return new Promise((resolve) => {
|
|
11
40
|
const docx = createDocument(doc);
|
|
12
|
-
|
|
41
|
+
Packer.toBlob(docx).then((blob) => {
|
|
13
42
|
resolve(blob);
|
|
14
43
|
});
|
|
15
44
|
});
|
|
@@ -18,7 +47,7 @@ export function exportToHTML5Blob(doc: AD.AbstractDoc.AbstractDoc): Promise<Blob
|
|
|
18
47
|
export function exportToStream(blobStream: NodeJS.WritableStream, doc: AD.AbstractDoc.AbstractDoc): void {
|
|
19
48
|
const docx = createDocument(doc);
|
|
20
49
|
|
|
21
|
-
|
|
50
|
+
Packer.toBuffer(docx).then((buffer) => {
|
|
22
51
|
const readableStream = new Readable();
|
|
23
52
|
readableStream.push(buffer);
|
|
24
53
|
readableStream.push(null);
|
|
@@ -33,14 +62,14 @@ export function exportToStream(blobStream: NodeJS.WritableStream, doc: AD.Abstra
|
|
|
33
62
|
* @param doc
|
|
34
63
|
*/
|
|
35
64
|
|
|
36
|
-
function createDocument(doc: AD.AbstractDoc.AbstractDoc):
|
|
37
|
-
const docx = new
|
|
65
|
+
function createDocument(doc: AD.AbstractDoc.AbstractDoc): Document {
|
|
66
|
+
const docx = new Document({
|
|
38
67
|
sections: doc.children.map((s) => renderSection(s, doc)),
|
|
39
68
|
});
|
|
40
69
|
return docx;
|
|
41
70
|
}
|
|
42
71
|
|
|
43
|
-
function renderSection(section: AD.Section.Section, parentResources: AD.Resources.Resources):
|
|
72
|
+
function renderSection(section: AD.Section.Section, parentResources: AD.Resources.Resources): ISectionOptions {
|
|
44
73
|
const pageWidth = AD.PageStyle.getWidth(section.page.style);
|
|
45
74
|
const pageHeight = AD.PageStyle.getHeight(section.page.style);
|
|
46
75
|
|
|
@@ -52,20 +81,20 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
52
81
|
const headerChildren = section.page.header.reduce((sofar, c) => {
|
|
53
82
|
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
54
83
|
return sofar;
|
|
55
|
-
}, [] as Array<
|
|
84
|
+
}, [] as Array<Paragraph | Table>);
|
|
56
85
|
|
|
57
86
|
const footerChildren = [
|
|
58
87
|
...section.page.footer.reduce((sofar, c) => {
|
|
59
88
|
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
60
89
|
return sofar;
|
|
61
|
-
}, [] as Array<
|
|
90
|
+
}, [] as Array<Paragraph | Table>),
|
|
62
91
|
];
|
|
63
92
|
|
|
64
93
|
const contentChildren = [
|
|
65
|
-
new
|
|
94
|
+
new Paragraph({
|
|
66
95
|
spacing: { before: 0, after: 0, line: 1 },
|
|
67
96
|
children: [
|
|
68
|
-
new
|
|
97
|
+
new Bookmark({
|
|
69
98
|
id: section.id,
|
|
70
99
|
children: [],
|
|
71
100
|
}),
|
|
@@ -74,7 +103,7 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
74
103
|
...section.children.reduce((sofar, c) => {
|
|
75
104
|
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
76
105
|
return sofar;
|
|
77
|
-
}, [] as Array<
|
|
106
|
+
}, [] as Array<Paragraph | Table>),
|
|
78
107
|
];
|
|
79
108
|
|
|
80
109
|
return {
|
|
@@ -85,9 +114,7 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
85
114
|
width: AD.PageStyle.getPaperWidth(section.page.style.paperSize) * abstractDocPixelToDocxDXARatio,
|
|
86
115
|
height: AD.PageStyle.getPaperHeight(section.page.style.paperSize) * abstractDocPixelToDocxDXARatio,
|
|
87
116
|
orientation:
|
|
88
|
-
section.page.style.orientation === "Landscape"
|
|
89
|
-
? DOCXJS.PageOrientation.LANDSCAPE
|
|
90
|
-
: DOCXJS.PageOrientation.PORTRAIT,
|
|
117
|
+
section.page.style.orientation === "Landscape" ? PageOrientation.LANDSCAPE : PageOrientation.PORTRAIT,
|
|
91
118
|
},
|
|
92
119
|
margin: {
|
|
93
120
|
bottom: section.page.style.contentMargins.bottom * abstractDocPixelToDocxDXARatio,
|
|
@@ -100,12 +127,12 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
100
127
|
},
|
|
101
128
|
},
|
|
102
129
|
headers: {
|
|
103
|
-
default: new
|
|
130
|
+
default: new Header({
|
|
104
131
|
children: headerChildren,
|
|
105
132
|
}),
|
|
106
133
|
},
|
|
107
134
|
footers: {
|
|
108
|
-
default: new
|
|
135
|
+
default: new Footer({
|
|
109
136
|
children: footerChildren,
|
|
110
137
|
}),
|
|
111
138
|
},
|
|
@@ -116,9 +143,9 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
116
143
|
function renderHyperLink(
|
|
117
144
|
hyperLink: AD.HyperLink.HyperLink,
|
|
118
145
|
style: AD.TextStyle.TextStyle
|
|
119
|
-
):
|
|
146
|
+
): InternalHyperlink | ExternalHyperlink {
|
|
120
147
|
const fontSize = AD.TextStyle.calculateFontSize(style, 10) * 2;
|
|
121
|
-
const textRun = new
|
|
148
|
+
const textRun = new TextRun({
|
|
122
149
|
text: hyperLink.text,
|
|
123
150
|
font: style.fontFamily || "Arial",
|
|
124
151
|
size: fontSize,
|
|
@@ -127,18 +154,18 @@ function renderHyperLink(
|
|
|
127
154
|
underline: style.underline
|
|
128
155
|
? {
|
|
129
156
|
color: style.color || "blue",
|
|
130
|
-
type:
|
|
157
|
+
type: UnderlineType.SINGLE,
|
|
131
158
|
}
|
|
132
159
|
: undefined,
|
|
133
160
|
});
|
|
134
161
|
|
|
135
162
|
if (hyperLink.target.startsWith("#") && !hyperLink.target.startsWith("#page=")) {
|
|
136
|
-
return new
|
|
163
|
+
return new InternalHyperlink({
|
|
137
164
|
anchor: hyperLink.target,
|
|
138
165
|
child: textRun,
|
|
139
166
|
});
|
|
140
167
|
} else {
|
|
141
|
-
return new
|
|
168
|
+
return new ExternalHyperlink({
|
|
142
169
|
link: hyperLink.target,
|
|
143
170
|
child: textRun,
|
|
144
171
|
});
|
|
@@ -150,7 +177,7 @@ function renderSectionElement(
|
|
|
150
177
|
parentResources: AD.Resources.Resources,
|
|
151
178
|
contentAvailableWidth: number,
|
|
152
179
|
keepNext: boolean = false
|
|
153
|
-
): ReadonlyArray<
|
|
180
|
+
): ReadonlyArray<Paragraph | Table> /*| DOCXJS.TableOfContents | DOCXJS.HyperlinkRef */ {
|
|
154
181
|
const resources = AD.Resources.mergeResources([parentResources, element]);
|
|
155
182
|
switch (element.type) {
|
|
156
183
|
case "Paragraph":
|
|
@@ -160,19 +187,16 @@ function renderSectionElement(
|
|
|
160
187
|
case "Table":
|
|
161
188
|
const table = renderTable(element, resources, contentAvailableWidth, keepNext);
|
|
162
189
|
return table
|
|
163
|
-
? [
|
|
164
|
-
table,
|
|
165
|
-
new DOCXJS.Paragraph({ keepNext: keepNext, children: [new DOCXJS.TextRun({ text: ".", size: 0.000001 })] }),
|
|
166
|
-
]
|
|
190
|
+
? [table, new Paragraph({ keepNext: keepNext, children: [new TextRun({ text: ".", size: 0.000001 })] })]
|
|
167
191
|
: [];
|
|
168
192
|
case "PageBreak":
|
|
169
193
|
return [
|
|
170
|
-
new
|
|
194
|
+
new Paragraph({
|
|
171
195
|
pageBreakBefore: true,
|
|
172
196
|
}),
|
|
173
197
|
];
|
|
174
198
|
default:
|
|
175
|
-
return [new
|
|
199
|
+
return [new Paragraph({})];
|
|
176
200
|
}
|
|
177
201
|
}
|
|
178
202
|
|
|
@@ -181,7 +205,7 @@ function renderTable(
|
|
|
181
205
|
resources: AD.Resources.Resources,
|
|
182
206
|
contentAvailableWidth: number,
|
|
183
207
|
keepNext: boolean
|
|
184
|
-
):
|
|
208
|
+
): Table | undefined {
|
|
185
209
|
const style = AD.Resources.getStyle(
|
|
186
210
|
undefined,
|
|
187
211
|
table.style,
|
|
@@ -204,13 +228,13 @@ function renderTable(
|
|
|
204
228
|
Number.isFinite(w) ? w * abstractDocPixelToDocxDXARatio : infinityCellWidth * abstractDocPixelToDocxDXARatio
|
|
205
229
|
);
|
|
206
230
|
|
|
207
|
-
return new
|
|
231
|
+
return new Table({
|
|
208
232
|
alignment:
|
|
209
233
|
style.alignment === "Left"
|
|
210
|
-
?
|
|
234
|
+
? AlignmentType.LEFT
|
|
211
235
|
: style.alignment === "Right"
|
|
212
|
-
?
|
|
213
|
-
:
|
|
236
|
+
? AlignmentType.RIGHT
|
|
237
|
+
: AlignmentType.CENTER,
|
|
214
238
|
margins: {
|
|
215
239
|
top: style.margins.top * abstractDocPixelToDocxDXARatio,
|
|
216
240
|
bottom: style.margins.bottom * abstractDocPixelToDocxDXARatio,
|
|
@@ -218,39 +242,39 @@ function renderTable(
|
|
|
218
242
|
right: style.margins.right * abstractDocPixelToDocxDXARatio,
|
|
219
243
|
},
|
|
220
244
|
width: {
|
|
221
|
-
type:
|
|
245
|
+
type: WidthType.DXA,
|
|
222
246
|
size: columnWidths.reduce((a, b) => a + b),
|
|
223
247
|
},
|
|
224
248
|
borders: {
|
|
225
249
|
top: {
|
|
226
250
|
color: style.cellStyle.borderColor ?? "",
|
|
227
251
|
size: 0,
|
|
228
|
-
style:
|
|
252
|
+
style: BorderStyle.NONE,
|
|
229
253
|
},
|
|
230
254
|
right: {
|
|
231
255
|
color: style.cellStyle.borderColor ?? "",
|
|
232
256
|
size: 0,
|
|
233
|
-
style:
|
|
257
|
+
style: BorderStyle.NONE,
|
|
234
258
|
},
|
|
235
259
|
bottom: {
|
|
236
260
|
color: style.cellStyle.borderColor ?? "",
|
|
237
261
|
size: 0,
|
|
238
|
-
style:
|
|
262
|
+
style: BorderStyle.NONE,
|
|
239
263
|
},
|
|
240
264
|
left: {
|
|
241
265
|
color: style.cellStyle.borderColor ?? "",
|
|
242
266
|
size: 0,
|
|
243
|
-
style:
|
|
267
|
+
style: BorderStyle.NONE,
|
|
244
268
|
},
|
|
245
269
|
insideHorizontal: {
|
|
246
270
|
color: style.cellStyle.borderColor ?? "",
|
|
247
271
|
size: 0,
|
|
248
|
-
style:
|
|
272
|
+
style: BorderStyle.NONE,
|
|
249
273
|
},
|
|
250
274
|
insideVertical: {
|
|
251
275
|
color: style.cellStyle.borderColor ?? "",
|
|
252
276
|
size: 0,
|
|
253
|
-
style:
|
|
277
|
+
style: BorderStyle.NONE,
|
|
254
278
|
},
|
|
255
279
|
},
|
|
256
280
|
rows: table.children.map((c) => renderRow(c, resources, style.cellStyle, columnWidths, keepNext)),
|
|
@@ -263,8 +287,8 @@ function renderRow(
|
|
|
263
287
|
tableCellStyle: AD.TableCellStyle.TableCellStyle,
|
|
264
288
|
columnWidths: ReadonlyArray<number>,
|
|
265
289
|
keepNext: boolean
|
|
266
|
-
):
|
|
267
|
-
return new
|
|
290
|
+
): TableRow {
|
|
291
|
+
return new TableRow({
|
|
268
292
|
cantSplit: true,
|
|
269
293
|
children: row.children.map((c, ix) => renderCell(c, resources, tableCellStyle, columnWidths[ix], keepNext)),
|
|
270
294
|
});
|
|
@@ -276,7 +300,7 @@ function renderCell(
|
|
|
276
300
|
tableCellStyle: AD.TableCellStyle.TableCellStyle,
|
|
277
301
|
width: number,
|
|
278
302
|
keepNext: boolean
|
|
279
|
-
):
|
|
303
|
+
): TableCell {
|
|
280
304
|
const style = AD.Resources.getStyle(
|
|
281
305
|
tableCellStyle,
|
|
282
306
|
cell.style,
|
|
@@ -285,20 +309,20 @@ function renderCell(
|
|
|
285
309
|
resources
|
|
286
310
|
) as AD.TableCellStyle.TableCellStyle;
|
|
287
311
|
|
|
288
|
-
return new
|
|
312
|
+
return new TableCell({
|
|
289
313
|
verticalAlign:
|
|
290
314
|
(style.verticalAlignment && style.verticalAlignment === "Top"
|
|
291
|
-
?
|
|
315
|
+
? VerticalAlign.TOP
|
|
292
316
|
: style.verticalAlignment === "Bottom"
|
|
293
|
-
?
|
|
294
|
-
:
|
|
317
|
+
? VerticalAlign.BOTTOM
|
|
318
|
+
: VerticalAlign.CENTER) || undefined,
|
|
295
319
|
shading: {
|
|
296
320
|
fill: style.background ? style.background : undefined,
|
|
297
321
|
},
|
|
298
322
|
columnSpan: cell.columnSpan,
|
|
299
323
|
rowSpan: cell.rowSpan,
|
|
300
324
|
width: {
|
|
301
|
-
type:
|
|
325
|
+
type: WidthType.DXA,
|
|
302
326
|
size: width,
|
|
303
327
|
},
|
|
304
328
|
margins: {
|
|
@@ -311,29 +335,29 @@ function renderCell(
|
|
|
311
335
|
top: {
|
|
312
336
|
color: style.borderColor ?? "",
|
|
313
337
|
size: style.borders.top,
|
|
314
|
-
style: style.borders.top ?
|
|
338
|
+
style: style.borders.top ? BorderStyle.SINGLE : BorderStyle.NONE,
|
|
315
339
|
},
|
|
316
340
|
right: {
|
|
317
341
|
color: style.borderColor ?? "",
|
|
318
342
|
size: style.borders.right,
|
|
319
|
-
style: style.borders.right ?
|
|
343
|
+
style: style.borders.right ? BorderStyle.SINGLE : BorderStyle.NONE,
|
|
320
344
|
},
|
|
321
345
|
bottom: {
|
|
322
346
|
color: style.borderColor ?? "",
|
|
323
347
|
size: style.borders.bottom,
|
|
324
|
-
style: style.borders.bottom ?
|
|
348
|
+
style: style.borders.bottom ? BorderStyle.SINGLE : BorderStyle.NONE,
|
|
325
349
|
},
|
|
326
350
|
left: {
|
|
327
351
|
color: style.borderColor ?? "",
|
|
328
352
|
size: style.borders.left,
|
|
329
|
-
style: style.borders.left ?
|
|
353
|
+
style: style.borders.left ? BorderStyle.SINGLE : BorderStyle.NONE,
|
|
330
354
|
},
|
|
331
355
|
},
|
|
332
356
|
|
|
333
357
|
children: cell.children.reduce((sofar, c) => {
|
|
334
358
|
sofar.push(...renderSectionElement(c, resources, width, keepNext));
|
|
335
359
|
return sofar;
|
|
336
|
-
}, [] as Array<
|
|
360
|
+
}, [] as Array<Paragraph | Table>),
|
|
337
361
|
});
|
|
338
362
|
}
|
|
339
363
|
|
|
@@ -342,18 +366,18 @@ function renderAtom(
|
|
|
342
366
|
textStyle: AD.TextStyle.TextStyle,
|
|
343
367
|
atom: AD.Atom.Atom
|
|
344
368
|
):
|
|
345
|
-
|
|
|
346
|
-
|
|
|
347
|
-
|
|
|
348
|
-
|
|
|
349
|
-
|
|
|
350
|
-
|
|
|
351
|
-
|
|
|
352
|
-
|
|
|
353
|
-
|
|
|
354
|
-
|
|
|
355
|
-
|
|
|
356
|
-
|
|
|
369
|
+
| TextRun
|
|
370
|
+
| ImageRun
|
|
371
|
+
| SymbolRun
|
|
372
|
+
| Bookmark
|
|
373
|
+
| PageBreak
|
|
374
|
+
| SequentialIdentifier
|
|
375
|
+
| FootnoteReferenceRun
|
|
376
|
+
| InsertedTextRun
|
|
377
|
+
| DeletedTextRun
|
|
378
|
+
| InternalHyperlink
|
|
379
|
+
| ExternalHyperlink
|
|
380
|
+
| MathDocX {
|
|
357
381
|
switch (atom.type) {
|
|
358
382
|
case "TextField":
|
|
359
383
|
return renderTextField(resources, textStyle, atom);
|
|
@@ -364,9 +388,9 @@ function renderAtom(
|
|
|
364
388
|
case "HyperLink":
|
|
365
389
|
return renderHyperLink(atom, textStyle);
|
|
366
390
|
case "TocSeparator":
|
|
367
|
-
return new
|
|
391
|
+
return new TextRun({ text: "..." });
|
|
368
392
|
default:
|
|
369
|
-
return new
|
|
393
|
+
return new TextRun({ text: "missed" }); // TODO
|
|
370
394
|
}
|
|
371
395
|
}
|
|
372
396
|
|
|
@@ -374,7 +398,7 @@ function renderTextField(
|
|
|
374
398
|
resources: AD.Resources.Resources,
|
|
375
399
|
textStyle: AD.TextStyle.TextStyle,
|
|
376
400
|
textField: AD.TextField.TextField
|
|
377
|
-
):
|
|
401
|
+
): TextRun {
|
|
378
402
|
const style = AD.Resources.getStyle(
|
|
379
403
|
textStyle,
|
|
380
404
|
textField.style,
|
|
@@ -398,7 +422,7 @@ function renderTextRun(
|
|
|
398
422
|
resources: AD.Resources.Resources,
|
|
399
423
|
textStyle: AD.TextStyle.TextStyle,
|
|
400
424
|
textRun: AD.TextRun.TextRun
|
|
401
|
-
):
|
|
425
|
+
): TextRun {
|
|
402
426
|
const style = AD.Resources.getNestedStyle(
|
|
403
427
|
textStyle,
|
|
404
428
|
textRun.style,
|
|
@@ -411,9 +435,9 @@ function renderTextRun(
|
|
|
411
435
|
return renderText(style, textRun.text);
|
|
412
436
|
}
|
|
413
437
|
|
|
414
|
-
function renderPageNumber(style: AD.TextStyle.TextStyle):
|
|
438
|
+
function renderPageNumber(style: AD.TextStyle.TextStyle): TextRun {
|
|
415
439
|
const fontSize = AD.TextStyle.calculateFontSize(style, 10) * abstractDocToDocxFontRatio;
|
|
416
|
-
return new
|
|
440
|
+
return new TextRun({
|
|
417
441
|
font: style.fontFamily || "Arial",
|
|
418
442
|
size: fontSize,
|
|
419
443
|
color: style.color || "black",
|
|
@@ -421,16 +445,16 @@ function renderPageNumber(style: AD.TextStyle.TextStyle): DOCXJS.TextRun {
|
|
|
421
445
|
underline: style.underline
|
|
422
446
|
? {
|
|
423
447
|
color: style.color,
|
|
424
|
-
type:
|
|
448
|
+
type: UnderlineType.SINGLE,
|
|
425
449
|
}
|
|
426
450
|
: undefined,
|
|
427
|
-
children: [
|
|
451
|
+
children: [PageNumber.CURRENT],
|
|
428
452
|
});
|
|
429
453
|
}
|
|
430
454
|
|
|
431
|
-
function renderTotalPages(style: AD.TextStyle.TextStyle):
|
|
455
|
+
function renderTotalPages(style: AD.TextStyle.TextStyle): TextRun {
|
|
432
456
|
const fontSize = AD.TextStyle.calculateFontSize(style, 10) * abstractDocToDocxFontRatio;
|
|
433
|
-
return new
|
|
457
|
+
return new TextRun({
|
|
434
458
|
font: style.fontFamily || "Arial",
|
|
435
459
|
size: fontSize,
|
|
436
460
|
color: style.color || "black",
|
|
@@ -438,17 +462,17 @@ function renderTotalPages(style: AD.TextStyle.TextStyle): DOCXJS.TextRun {
|
|
|
438
462
|
underline: style.underline
|
|
439
463
|
? {
|
|
440
464
|
color: style.color,
|
|
441
|
-
type:
|
|
465
|
+
type: UnderlineType.SINGLE,
|
|
442
466
|
}
|
|
443
467
|
: undefined,
|
|
444
|
-
children: [
|
|
468
|
+
children: [PageNumber.TOTAL_PAGES],
|
|
445
469
|
});
|
|
446
470
|
}
|
|
447
471
|
|
|
448
|
-
function renderText(style: AD.TextStyle.TextStyle, text: string):
|
|
472
|
+
function renderText(style: AD.TextStyle.TextStyle, text: string): TextRun {
|
|
449
473
|
const fontSize = AD.TextStyle.calculateFontSize(style, 10) * abstractDocToDocxFontRatio;
|
|
450
474
|
|
|
451
|
-
return new
|
|
475
|
+
return new TextRun({
|
|
452
476
|
text: text,
|
|
453
477
|
font: style.fontFamily || "Arial",
|
|
454
478
|
size: fontSize,
|
|
@@ -457,7 +481,7 @@ function renderText(style: AD.TextStyle.TextStyle, text: string): DOCXJS.TextRun
|
|
|
457
481
|
underline: style.underline
|
|
458
482
|
? {
|
|
459
483
|
color: style.color,
|
|
460
|
-
type:
|
|
484
|
+
type: UnderlineType.SINGLE,
|
|
461
485
|
}
|
|
462
486
|
: undefined,
|
|
463
487
|
});
|
|
@@ -467,8 +491,8 @@ function renderGroup(
|
|
|
467
491
|
group: AD.Group.Group,
|
|
468
492
|
resources: AD.Resources.Resources,
|
|
469
493
|
availabelWidth: number
|
|
470
|
-
): Array<
|
|
471
|
-
let sofar = Array<
|
|
494
|
+
): Array<Paragraph | Table> {
|
|
495
|
+
let sofar = Array<Paragraph | Table>();
|
|
472
496
|
let keepNext = true;
|
|
473
497
|
for (let index = 0; index < group.children.length; index++) {
|
|
474
498
|
if (index == group.children.length - 1) {
|
|
@@ -483,7 +507,7 @@ function renderParagraph(
|
|
|
483
507
|
paragraph: AD.Paragraph.Paragraph,
|
|
484
508
|
resources: AD.Resources.Resources,
|
|
485
509
|
keepNext: boolean
|
|
486
|
-
):
|
|
510
|
+
): Paragraph {
|
|
487
511
|
const style = AD.Resources.getStyle(
|
|
488
512
|
undefined,
|
|
489
513
|
paragraph.style,
|
|
@@ -492,15 +516,15 @@ function renderParagraph(
|
|
|
492
516
|
resources
|
|
493
517
|
) as AD.ParagraphStyle.ParagraphStyle;
|
|
494
518
|
|
|
495
|
-
return new
|
|
519
|
+
return new Paragraph({
|
|
496
520
|
keepNext: keepNext,
|
|
497
521
|
alignment:
|
|
498
522
|
(style.alignment &&
|
|
499
523
|
(style.alignment === "Center"
|
|
500
|
-
?
|
|
524
|
+
? AlignmentType.CENTER
|
|
501
525
|
: style.alignment === "End"
|
|
502
|
-
?
|
|
503
|
-
:
|
|
526
|
+
? AlignmentType.END
|
|
527
|
+
: AlignmentType.START)) ||
|
|
504
528
|
undefined,
|
|
505
529
|
|
|
506
530
|
spacing: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as AbstractImage from "abstract-image";
|
|
2
|
-
import
|
|
2
|
+
import { fromByteArray } from "base64-js";
|
|
3
3
|
import svgToPdfKit from "svg-to-pdfkit";
|
|
4
4
|
import * as AD from "../../abstract-document/index.js";
|
|
5
5
|
import { getFontNameStyle, getFontName, isFontAvailable } from "./font.js";
|
|
@@ -41,12 +41,12 @@ function abstractComponentToPdf(
|
|
|
41
41
|
fit: [imageWidth, imageHeight],
|
|
42
42
|
});
|
|
43
43
|
} else if (format === "png") {
|
|
44
|
-
const data = "data:image/png;base64," +
|
|
44
|
+
const data = "data:image/png;base64," + fromByteArray(component.data.bytes);
|
|
45
45
|
pdf.image(data, component.topLeft.x, component.topLeft.y, {
|
|
46
46
|
fit: [imageWidth, imageHeight],
|
|
47
47
|
});
|
|
48
48
|
} else if (format === "jpg") {
|
|
49
|
-
const data = "data:image/jpeg;base64," +
|
|
49
|
+
const data = "data:image/jpeg;base64," + fromByteArray(component.data.bytes);
|
|
50
50
|
pdf.image(data, component.topLeft.x, component.topLeft.y, {
|
|
51
51
|
fit: [imageWidth, imageHeight],
|
|
52
52
|
});
|
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
import * as AD from "../../abstract-document/index.js";
|
|
2
1
|
import { exhaustiveCheck } from "ts-exhaustive-check";
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { AbstractDoc } from "../../abstract-document/abstract-doc.js";
|
|
3
|
+
import { Resources, mergeResources } from "../../abstract-document/resources.js";
|
|
4
|
+
import { Group } from "../../abstract-document/section-elements/group.js";
|
|
5
|
+
import { Table } from "../../abstract-document/section-elements/table.js";
|
|
6
|
+
import { SectionElement } from "../../abstract-document/section-elements/section-element.js";
|
|
7
|
+
import { Paragraph } from "../../abstract-document/section-elements/paragraph.js";
|
|
8
|
+
import { Section } from "../../abstract-document/page/section.js";
|
|
9
|
+
import { TableRow } from "../../abstract-document/table/table-row.js";
|
|
10
|
+
import { TableCell } from "../../abstract-document/table/table-cell.js";
|
|
11
|
+
|
|
12
|
+
export function getResources(doc: AbstractDoc): Resources {
|
|
5
13
|
const resources = doc.children.map((s) => getResourcesSection(s));
|
|
6
|
-
return
|
|
14
|
+
return mergeResources([...resources, doc]);
|
|
7
15
|
}
|
|
8
16
|
|
|
9
|
-
function getResourcesSection(s:
|
|
10
|
-
const header =
|
|
11
|
-
const footer =
|
|
12
|
-
const children =
|
|
13
|
-
return
|
|
17
|
+
function getResourcesSection(s: Section): Resources {
|
|
18
|
+
const header = mergeResources(s.page.header.map((e) => getResourcesSectionElement(e)));
|
|
19
|
+
const footer = mergeResources(s.page.footer.map((e) => getResourcesSectionElement(e)));
|
|
20
|
+
const children = mergeResources(s.children.map((e) => getResourcesSectionElement(e)));
|
|
21
|
+
return mergeResources([header, footer, children]);
|
|
14
22
|
}
|
|
15
23
|
|
|
16
|
-
function getResourcesSectionElement(e:
|
|
24
|
+
function getResourcesSectionElement(e: SectionElement): Resources {
|
|
17
25
|
switch (e.type) {
|
|
18
26
|
case "Paragraph":
|
|
19
27
|
return getResourcesParagraph(e);
|
|
@@ -28,22 +36,22 @@ function getResourcesSectionElement(e: AD.SectionElement.SectionElement): AD.Res
|
|
|
28
36
|
}
|
|
29
37
|
}
|
|
30
38
|
|
|
31
|
-
function getResourcesParagraph(paragraph:
|
|
39
|
+
function getResourcesParagraph(paragraph: Paragraph): Resources {
|
|
32
40
|
return paragraph;
|
|
33
41
|
}
|
|
34
42
|
|
|
35
|
-
function getResourcesTable(table:
|
|
36
|
-
return
|
|
43
|
+
function getResourcesTable(table: Table): Resources {
|
|
44
|
+
return mergeResources(table.children.map((r) => getResourcesTableRow(r)));
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
function getResourcesTableRow(r:
|
|
40
|
-
return
|
|
47
|
+
function getResourcesTableRow(r: TableRow): Resources {
|
|
48
|
+
return mergeResources(r.children.map((c) => getResourcesTableCell(c)));
|
|
41
49
|
}
|
|
42
50
|
|
|
43
|
-
function getResourcesTableCell(c:
|
|
44
|
-
return
|
|
51
|
+
function getResourcesTableCell(c: TableCell): Resources {
|
|
52
|
+
return mergeResources(c.children.map((e) => getResourcesSectionElement(e)));
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
function getResourcesGroup(group:
|
|
48
|
-
return
|
|
55
|
+
function getResourcesGroup(group: Group): Resources {
|
|
56
|
+
return mergeResources(group.children.map((e) => getResourcesSectionElement(e)));
|
|
49
57
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { X2jOptions, XMLParser } from "fast-xml-parser";
|
|
2
2
|
import Mustache from "mustache";
|
|
3
3
|
|
|
4
4
|
export type XmlElement = {
|
|
@@ -16,8 +16,8 @@ export const parseMustacheXml = (
|
|
|
16
16
|
|
|
17
17
|
export const render = Mustache.render;
|
|
18
18
|
|
|
19
|
-
export function parseXmlCustom(text: string, options: Partial<
|
|
20
|
-
const parser = new
|
|
19
|
+
export function parseXmlCustom(text: string, options: Partial<X2jOptions>): ReadonlyArray<XmlElement> {
|
|
20
|
+
const parser = new XMLParser(options);
|
|
21
21
|
parser.addEntity("#x2F", "/");
|
|
22
22
|
parser.addEntity("#x3D", "=");
|
|
23
23
|
return transformFXP(parser.parse(text));
|
|
@@ -104,7 +104,7 @@ function shouldSkipLevel(tag: XmlElement): boolean {
|
|
|
104
104
|
);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
const xmlParser = new
|
|
107
|
+
const xmlParser = new XMLParser({
|
|
108
108
|
preserveOrder: true,
|
|
109
109
|
ignoreAttributes: false,
|
|
110
110
|
attributeNamePrefix: "",
|
|
@@ -127,7 +127,7 @@ const xmlParser = new FXmlP.XMLParser({
|
|
|
127
127
|
xmlParser.addEntity("#x2F", "/");
|
|
128
128
|
xmlParser.addEntity("#x3D", "=");
|
|
129
129
|
|
|
130
|
-
const xsdParser = new
|
|
130
|
+
const xsdParser = new XMLParser({
|
|
131
131
|
preserveOrder: true,
|
|
132
132
|
ignoreAttributes: false,
|
|
133
133
|
attributeNamePrefix: "",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { XMLValidator, ValidationError } from "fast-xml-parser";
|
|
2
2
|
import { XmlElement, parseXml, findElement } from "./parse-mustache-xml.js";
|
|
3
3
|
|
|
4
4
|
enum ErrorType {
|
|
@@ -56,7 +56,7 @@ export function validateXml(fullXml: string, xsdSchema: ReadonlyArray<XmlElement
|
|
|
56
56
|
|
|
57
57
|
if (xml) {
|
|
58
58
|
try {
|
|
59
|
-
const result =
|
|
59
|
+
const result = XMLValidator.validate(xml, {
|
|
60
60
|
allowBooleanAttributes: true,
|
|
61
61
|
});
|
|
62
62
|
|
|
@@ -191,7 +191,7 @@ function getDecorationsFromError(error: XmlError): ErrorObject {
|
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
function getErrorFromException(result:
|
|
194
|
+
function getErrorFromException(result: ValidationError, xml: string): XmlError {
|
|
195
195
|
const { col, line, msg } = result.err;
|
|
196
196
|
const startLine = line - 1;
|
|
197
197
|
const lines = xml.split("\n");
|