abstract-document 19.3.0 → 20.0.3
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/CHANGELOG.md +14 -1
- package/lib/abstract-document/abstract-doc.d.ts +2 -2
- package/lib/abstract-document/abstract-doc.d.ts.map +1 -1
- package/lib/abstract-document/atoms/atom.d.ts +7 -7
- package/lib/abstract-document/atoms/atom.d.ts.map +1 -1
- package/lib/abstract-document/atoms/image.d.ts +1 -1
- package/lib/abstract-document/atoms/image.d.ts.map +1 -1
- package/lib/abstract-document/default-styles.d.ts +2 -2
- package/lib/abstract-document/default-styles.d.ts.map +1 -1
- package/lib/abstract-document/markdown/markdown.d.ts +1 -1
- package/lib/abstract-document/markdown/markdown.d.ts.map +1 -1
- package/lib/abstract-document/markdown/markdown.js +5 -2
- package/lib/abstract-document/markdown/markdown.js.map +1 -1
- package/lib/abstract-document/markdown/types.d.ts +1 -1
- package/lib/abstract-document/markdown/types.d.ts.map +1 -1
- package/lib/abstract-document/numberings/numbering-definition.d.ts +1 -1
- package/lib/abstract-document/numberings/numbering-definition.d.ts.map +1 -1
- package/lib/abstract-document/numberings/numbering-level-definition.d.ts +1 -1
- package/lib/abstract-document/numberings/numbering-level-definition.d.ts.map +1 -1
- package/lib/abstract-document/page/master-page.d.ts +1 -1
- package/lib/abstract-document/page/master-page.d.ts.map +1 -1
- package/lib/abstract-document/page/section.d.ts +2 -2
- package/lib/abstract-document/page/section.d.ts.map +1 -1
- package/lib/abstract-document/primitives/image-resource.d.ts +1 -1
- package/lib/abstract-document/primitives/image-resource.d.ts.map +1 -1
- package/lib/abstract-document/resources.d.ts +5 -5
- package/lib/abstract-document/resources.d.ts.map +1 -1
- package/lib/abstract-document/resources.js.map +1 -1
- package/lib/abstract-document/section-elements/group.d.ts +2 -2
- package/lib/abstract-document/section-elements/group.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/page-break.d.ts +1 -1
- package/lib/abstract-document/section-elements/page-break.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/paragraph.d.ts +3 -3
- package/lib/abstract-document/section-elements/paragraph.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/section-element.d.ts +1 -1
- package/lib/abstract-document/section-elements/section-element.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/table.d.ts +2 -2
- package/lib/abstract-document/section-elements/table.d.ts.map +1 -1
- package/lib/abstract-document/styles/group-style.d.ts +1 -1
- package/lib/abstract-document/styles/group-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/paragraph-style.d.ts +1 -1
- package/lib/abstract-document/styles/paragraph-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/table-style.d.ts +1 -1
- package/lib/abstract-document/styles/table-style.d.ts.map +1 -1
- package/lib/abstract-document/table/table-cell.d.ts +1 -1
- package/lib/abstract-document/table/table-cell.d.ts.map +1 -1
- package/lib/abstract-document/table/table-row.d.ts +1 -1
- package/lib/abstract-document/table/table-row.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/ref-container.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/xml-writer.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/xml-writer.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.d.ts +4 -4
- package/lib/abstract-document-exporters/docx2/render-image.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.js +7 -13
- 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 +28 -24
- package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.d.ts +2 -2
- package/lib/abstract-document-exporters/pdf/font.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.js +1 -1
- package/lib/abstract-document-exporters/pdf/font.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.d.ts +1 -1
- package/lib/abstract-document-exporters/pdf/measure.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.js +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.js +0 -2
- package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.d.ts +3 -4
- package/lib/abstract-document-exporters/pdf/render.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.js +12 -12
- package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/update-refs.d.ts +1 -1
- package/lib/abstract-document-exporters/pdf/update-refs.d.ts.map +1 -1
- package/lib/abstract-document-exporters/shared/get_resources.d.ts +2 -2
- package/lib/abstract-document-exporters/shared/get_resources.d.ts.map +1 -1
- package/lib/abstract-document-exporters/shared/get_resources.js.map +1 -1
- package/lib/abstract-document-jsx/index.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts +3 -3
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js +32 -32
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js +74 -74
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts +3 -2
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js.map +1 -1
- package/lib/abstract-document-xml/xsd-template/custom-elements.d.ts.map +1 -1
- package/lib/abstract-document-xml/xsd-template/custom-elements.js +0 -1
- package/lib/abstract-document-xml/xsd-template/custom-elements.js.map +1 -1
- package/package.json +14 -4
- package/src/abstract-document/abstract-doc.ts +7 -7
- package/src/abstract-document/atoms/atom.ts +7 -7
- package/src/abstract-document/atoms/image.ts +1 -1
- package/src/abstract-document/default-styles.ts +2 -2
- package/src/abstract-document/markdown/markdown.ts +9 -6
- package/src/abstract-document/markdown/types.ts +1 -1
- package/src/abstract-document/numberings/numbering-definition.ts +1 -1
- package/src/abstract-document/numberings/numbering-level-definition.ts +1 -1
- package/src/abstract-document/page/master-page.ts +1 -1
- package/src/abstract-document/page/section.ts +2 -2
- package/src/abstract-document/primitives/image-resource.ts +1 -1
- package/src/abstract-document/resources.ts +9 -8
- package/src/abstract-document/section-elements/group.ts +2 -2
- package/src/abstract-document/section-elements/page-break.ts +1 -1
- package/src/abstract-document/section-elements/paragraph.ts +3 -3
- package/src/abstract-document/section-elements/section-element.ts +1 -1
- package/src/abstract-document/section-elements/table.ts +2 -2
- package/src/abstract-document/styles/group-style.ts +1 -1
- package/src/abstract-document/styles/paragraph-style.ts +1 -1
- package/src/abstract-document/styles/table-style.ts +1 -1
- package/src/abstract-document/table/table-cell.ts +1 -1
- package/src/abstract-document/table/table-row.ts +1 -1
- package/src/abstract-document-exporters/docx2/render-image.ts +63 -51
- package/src/abstract-document-exporters/docx2/render.ts +62 -57
- package/src/abstract-document-exporters/pdf/font.ts +5 -5
- package/src/abstract-document-exporters/pdf/measure.ts +2 -1
- package/src/abstract-document-exporters/pdf/pre-process.ts +1 -2
- package/src/abstract-document-exporters/pdf/render-image.ts +1 -3
- package/src/abstract-document-exporters/pdf/render.ts +13 -18
- package/src/abstract-document-exporters/pdf/update-refs.ts +2 -2
- package/src/abstract-document-exporters/shared/get_resources.ts +10 -9
- package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +43 -42
- package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +111 -113
- package/src/abstract-document-xml/abstract-doc-of-xml/custom-elements.tsx +4 -13
- package/src/abstract-document-xml/xsd-template/custom-elements.ts +0 -1
- package/src/custom_typings/pdfkit-standard-fonts/index.d.ts +0 -1
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import * as AD from "../../abstract-document/index.js";
|
|
2
|
+
import type {
|
|
3
|
+
ISectionOptions,
|
|
4
|
+
ImageRun,
|
|
5
|
+
SymbolRun,
|
|
6
|
+
PageBreak,
|
|
7
|
+
SequentialIdentifier,
|
|
8
|
+
FootnoteReferenceRun,
|
|
9
|
+
InsertedTextRun,
|
|
10
|
+
DeletedTextRun,
|
|
11
|
+
Math as MathDocX,
|
|
12
|
+
} from "docx";
|
|
2
13
|
import {
|
|
3
14
|
Packer,
|
|
4
15
|
Document,
|
|
5
|
-
ISectionOptions,
|
|
6
16
|
Paragraph,
|
|
7
17
|
Table,
|
|
8
18
|
Bookmark,
|
|
@@ -19,14 +29,6 @@ import {
|
|
|
19
29
|
TableRow,
|
|
20
30
|
TableCell,
|
|
21
31
|
VerticalAlign,
|
|
22
|
-
ImageRun,
|
|
23
|
-
SymbolRun,
|
|
24
|
-
PageBreak,
|
|
25
|
-
SequentialIdentifier,
|
|
26
|
-
FootnoteReferenceRun,
|
|
27
|
-
InsertedTextRun,
|
|
28
|
-
DeletedTextRun,
|
|
29
|
-
Math as MathDocX,
|
|
30
32
|
PageNumber,
|
|
31
33
|
} from "docx";
|
|
32
34
|
import { renderImage } from "./render-image.js";
|
|
@@ -72,16 +74,14 @@ function createDocument(doc: AD.AbstractDoc.AbstractDoc): Document {
|
|
|
72
74
|
|
|
73
75
|
function renderSection(section: AD.Section.Section, parentResources: AD.Resources.Resources): ISectionOptions {
|
|
74
76
|
const pageWidth = AD.PageStyle.getWidth(section.page.style);
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const pageFooterMargins = AD.LayoutFoundation.orDefault(section.page.style.footerMargins)
|
|
77
|
+
const pageHeaderMargins = AD.LayoutFoundation.orDefault(section.page.style.headerMargins);
|
|
78
|
+
const pageFooterMargins = AD.LayoutFoundation.orDefault(section.page.style.footerMargins);
|
|
78
79
|
const pageContentMargins = AD.LayoutFoundation.orDefault(section.page.style.contentMargins);
|
|
79
80
|
|
|
80
81
|
const hasFrontHeader = section.page.frontHeader !== undefined && section.page.frontHeader.length !== 0;
|
|
81
82
|
const hasFrontFooter = section.page.frontFooter !== undefined && section.page.frontFooter.length !== 0;
|
|
82
|
-
|
|
83
|
-
const contentAvailableWidth =
|
|
84
|
-
pageWidth - (pageContentMargins.left + pageContentMargins.right);
|
|
83
|
+
|
|
84
|
+
const contentAvailableWidth = pageWidth - (pageContentMargins.left + pageContentMargins.right);
|
|
85
85
|
|
|
86
86
|
const resources = AD.Resources.mergeResources([parentResources, section]);
|
|
87
87
|
|
|
@@ -90,20 +90,24 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
90
90
|
return sofar;
|
|
91
91
|
}, [] as Array<Paragraph | Table>);
|
|
92
92
|
|
|
93
|
-
const firstpageHeaderChildren = hasFrontHeader
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
const firstpageHeaderChildren = hasFrontHeader
|
|
94
|
+
? section.page.frontHeader.reduce((sofar, c) => {
|
|
95
|
+
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
96
|
+
return sofar;
|
|
97
|
+
}, [] as Array<Paragraph | Table>)
|
|
98
|
+
: [];
|
|
97
99
|
|
|
98
100
|
const footerChildren = section.page.footer.reduce((sofar, c) => {
|
|
99
101
|
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
100
102
|
return sofar;
|
|
101
103
|
}, [] as Array<Paragraph | Table>);
|
|
102
104
|
|
|
103
|
-
const firstPageFooterChildren = hasFrontFooter
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
const firstPageFooterChildren = hasFrontFooter
|
|
106
|
+
? section.page.frontFooter.reduce((sofar, c) => {
|
|
107
|
+
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
108
|
+
return sofar;
|
|
109
|
+
}, [] as Array<Paragraph | Table>)
|
|
110
|
+
: [];
|
|
107
111
|
|
|
108
112
|
const contentChildren = [
|
|
109
113
|
new Paragraph({
|
|
@@ -146,17 +150,21 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
146
150
|
default: new Header({
|
|
147
151
|
children: headerChildren,
|
|
148
152
|
}),
|
|
149
|
-
first: hasFrontHeader
|
|
150
|
-
|
|
151
|
-
|
|
153
|
+
first: hasFrontHeader
|
|
154
|
+
? new Header({
|
|
155
|
+
children: firstpageHeaderChildren,
|
|
156
|
+
})
|
|
157
|
+
: undefined,
|
|
152
158
|
},
|
|
153
159
|
footers: {
|
|
154
160
|
default: new Footer({
|
|
155
|
-
children: footerChildren
|
|
161
|
+
children: footerChildren,
|
|
156
162
|
}),
|
|
157
|
-
first: hasFrontFooter
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
first: hasFrontFooter
|
|
164
|
+
? new Footer({
|
|
165
|
+
children: firstPageFooterChildren,
|
|
166
|
+
})
|
|
167
|
+
: undefined,
|
|
160
168
|
},
|
|
161
169
|
children: contentChildren,
|
|
162
170
|
};
|
|
@@ -176,9 +184,9 @@ function renderHyperLink(
|
|
|
176
184
|
characterSpacing: style.characterSpacing,
|
|
177
185
|
underline: style.underline
|
|
178
186
|
? {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
187
|
+
color: style.color || "#0000ff",
|
|
188
|
+
type: UnderlineType.SINGLE,
|
|
189
|
+
}
|
|
182
190
|
: undefined,
|
|
183
191
|
});
|
|
184
192
|
|
|
@@ -258,8 +266,8 @@ function renderTable(
|
|
|
258
266
|
style.alignment === "Left"
|
|
259
267
|
? AlignmentType.LEFT
|
|
260
268
|
: style.alignment === "Right"
|
|
261
|
-
|
|
262
|
-
|
|
269
|
+
? AlignmentType.RIGHT
|
|
270
|
+
: AlignmentType.CENTER,
|
|
263
271
|
margins: {
|
|
264
272
|
top: styleMargins.top * abstractDocPixelToDocxDXARatio,
|
|
265
273
|
bottom: styleMargins.bottom * abstractDocPixelToDocxDXARatio,
|
|
@@ -302,7 +310,9 @@ function renderTable(
|
|
|
302
310
|
style: BorderStyle.NONE,
|
|
303
311
|
},
|
|
304
312
|
},
|
|
305
|
-
rows: table.headerRows
|
|
313
|
+
rows: table.headerRows
|
|
314
|
+
.concat(table.children)
|
|
315
|
+
.map((c) => renderRow(c, resources, style.cellStyle, columnWidths, keepNext)),
|
|
306
316
|
});
|
|
307
317
|
}
|
|
308
318
|
|
|
@@ -317,16 +327,11 @@ function renderRow(
|
|
|
317
327
|
(acc, cell) => {
|
|
318
328
|
const span = cell.columnSpan ?? 1;
|
|
319
329
|
|
|
320
|
-
const width = columnWidths
|
|
321
|
-
.slice(acc.columnIndex, acc.columnIndex + span)
|
|
322
|
-
.reduce((a, b) => a + b, 0);
|
|
330
|
+
const width = columnWidths.slice(acc.columnIndex, acc.columnIndex + span).reduce((a, b) => a + b, 0);
|
|
323
331
|
|
|
324
332
|
return {
|
|
325
333
|
columnIndex: acc.columnIndex + span,
|
|
326
|
-
children: [
|
|
327
|
-
...acc.children,
|
|
328
|
-
renderCell(cell, resources, tableCellStyle, width, keepNext),
|
|
329
|
-
],
|
|
334
|
+
children: [...acc.children, renderCell(cell, resources, tableCellStyle, width, keepNext)],
|
|
330
335
|
};
|
|
331
336
|
},
|
|
332
337
|
{ columnIndex: 0, children: [] as TableCell[] }
|
|
@@ -346,7 +351,7 @@ function renderCell(
|
|
|
346
351
|
keepNext: boolean
|
|
347
352
|
): TableCell {
|
|
348
353
|
const abstractDocPxCellWidth = width / abstractDocPixelToDocxDXARatio;
|
|
349
|
-
|
|
354
|
+
|
|
350
355
|
const style = AD.Resources.getStyle(
|
|
351
356
|
tableCellStyle,
|
|
352
357
|
cell.style,
|
|
@@ -363,8 +368,8 @@ function renderCell(
|
|
|
363
368
|
(style.verticalAlignment && style.verticalAlignment === "Top"
|
|
364
369
|
? VerticalAlign.TOP
|
|
365
370
|
: style.verticalAlignment === "Bottom"
|
|
366
|
-
|
|
367
|
-
|
|
371
|
+
? VerticalAlign.BOTTOM
|
|
372
|
+
: VerticalAlign.CENTER) || undefined,
|
|
368
373
|
shading: {
|
|
369
374
|
fill: style.background ? style.background : undefined,
|
|
370
375
|
},
|
|
@@ -494,9 +499,9 @@ function renderPageNumber(style: AD.TextStyle.TextStyle): TextRun {
|
|
|
494
499
|
characterSpacing: style.characterSpacing,
|
|
495
500
|
underline: style.underline
|
|
496
501
|
? {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
502
|
+
color: style.color,
|
|
503
|
+
type: UnderlineType.SINGLE,
|
|
504
|
+
}
|
|
500
505
|
: undefined,
|
|
501
506
|
children: [PageNumber.CURRENT],
|
|
502
507
|
});
|
|
@@ -512,9 +517,9 @@ function renderTotalPages(style: AD.TextStyle.TextStyle): TextRun {
|
|
|
512
517
|
characterSpacing: style.characterSpacing,
|
|
513
518
|
underline: style.underline
|
|
514
519
|
? {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
520
|
+
color: style.color,
|
|
521
|
+
type: UnderlineType.SINGLE,
|
|
522
|
+
}
|
|
518
523
|
: undefined,
|
|
519
524
|
children: [PageNumber.TOTAL_PAGES],
|
|
520
525
|
});
|
|
@@ -532,9 +537,9 @@ function renderText(style: AD.TextStyle.TextStyle, text: string): TextRun {
|
|
|
532
537
|
characterSpacing: style.characterSpacing,
|
|
533
538
|
underline: style.underline
|
|
534
539
|
? {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
540
|
+
color: style.color,
|
|
541
|
+
type: UnderlineType.SINGLE,
|
|
542
|
+
}
|
|
538
543
|
: undefined,
|
|
539
544
|
});
|
|
540
545
|
}
|
|
@@ -576,8 +581,8 @@ function renderParagraph(
|
|
|
576
581
|
(style.alignment === "Center"
|
|
577
582
|
? AlignmentType.CENTER
|
|
578
583
|
: style.alignment === "End"
|
|
579
|
-
|
|
580
|
-
|
|
584
|
+
? AlignmentType.END
|
|
585
|
+
: AlignmentType.START)) ||
|
|
581
586
|
undefined,
|
|
582
587
|
|
|
583
588
|
spacing: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as AD from "../../abstract-document/index.js";
|
|
2
|
-
import { Font } from "../../abstract-document/primitives/font.js";
|
|
3
|
-
import { TextFontWeight } from "../../abstract-document/styles/text-style.js";
|
|
2
|
+
import type { Font } from "../../abstract-document/primitives/font.js";
|
|
3
|
+
import type { TextFontWeight } from "../../abstract-document/styles/text-style.js";
|
|
4
4
|
import { getResources } from "../shared/get_resources.js";
|
|
5
5
|
|
|
6
6
|
export function registerFonts(
|
|
@@ -57,12 +57,12 @@ export function getFontNameStyle(textStyle: AD.TextStyle.TextStyle): string {
|
|
|
57
57
|
|
|
58
58
|
export function getFontStyleName(attributes: Record<string, string>): keyof Font {
|
|
59
59
|
const fontWeight = getFontWeightFromAttributes(attributes);
|
|
60
|
-
const stringifiedItalic = `${attributes
|
|
60
|
+
const stringifiedItalic = `${attributes["italic"]}`;
|
|
61
61
|
const italic = stringifiedItalic === "true" || stringifiedItalic === "1";
|
|
62
|
-
if(fontWeight === "normal") {
|
|
62
|
+
if (fontWeight === "normal") {
|
|
63
63
|
return italic ? "italic" : fontWeight;
|
|
64
64
|
}
|
|
65
|
-
return `${fontWeight === "mediumBold" ? "medium" : fontWeight}${italic ? "Italic": ""}`;
|
|
65
|
+
return `${fontWeight === "mediumBold" ? "medium" : fontWeight}${italic ? "Italic" : ""}`;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export function getFontName(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as AD from "../../abstract-document/index.js";
|
|
2
2
|
import { exhaustiveCheck } from "ts-exhaustive-check";
|
|
3
|
-
import {
|
|
3
|
+
import type { Page } from "./paginate.js";
|
|
4
|
+
import { getHeaderAndFooter } from "./paginate.js";
|
|
4
5
|
import { registerFonts, getFontNameStyle } from "./font.js";
|
|
5
6
|
|
|
6
7
|
//tslint:disable:no-any variable-name
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { exhaustiveCheck } from "ts-exhaustive-check";
|
|
2
2
|
import * as AD from "../../abstract-document/index.js";
|
|
3
3
|
import * as TextStyle from "../../abstract-document/styles/text-style.js";
|
|
4
|
-
import { checkServerIdentity } from "node:tls";
|
|
5
4
|
|
|
6
5
|
const alphabet = [
|
|
7
6
|
"a",
|
|
@@ -201,7 +200,7 @@ function adjustParagraph(paragraph: AD.Paragraph.Paragraph): Array<AD.SectionEle
|
|
|
201
200
|
type: "LineBreak",
|
|
202
201
|
style: child.style,
|
|
203
202
|
nestedStyleNames: child.nestedStyleNames,
|
|
204
|
-
styleName: child.styleName
|
|
203
|
+
styleName: child.styleName,
|
|
205
204
|
};
|
|
206
205
|
newChildren.push(lineBreak);
|
|
207
206
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as AbstractImage from "abstract-image";
|
|
1
|
+
import type * as AbstractImage from "abstract-image";
|
|
2
2
|
import svgToPdfKit from "svg-to-pdfkit";
|
|
3
3
|
import * as AD from "../../abstract-document/index.js";
|
|
4
4
|
import { getFontNameStyle, getFontName, isFontAvailable } from "./font.js";
|
|
@@ -230,7 +230,6 @@ function addWithSvgToPdfKit(
|
|
|
230
230
|
let svgUpdated = svg;
|
|
231
231
|
["fill=", "stroke=", "color="].forEach((t) => {
|
|
232
232
|
let index = 0;
|
|
233
|
-
// eslint-disable-next-line no-constant-condition
|
|
234
233
|
while (true) {
|
|
235
234
|
index = svgUpdated.indexOf(t, index);
|
|
236
235
|
if (index === -1) break;
|
|
@@ -247,7 +246,6 @@ function addWithSvgToPdfKit(
|
|
|
247
246
|
|
|
248
247
|
["stroke-dasharray="].forEach((t) => {
|
|
249
248
|
let index = 0;
|
|
250
|
-
// eslint-disable-next-line no-constant-condition
|
|
251
249
|
while (true) {
|
|
252
250
|
index = svgUpdated.indexOf(t, index);
|
|
253
251
|
if (index === -1) break;
|
|
@@ -1,68 +1,63 @@
|
|
|
1
1
|
import * as AD from "../../abstract-document/index.js";
|
|
2
2
|
import { preProcess } from "./pre-process.js";
|
|
3
3
|
import { measure, measurePages } from "./measure.js";
|
|
4
|
-
import {
|
|
4
|
+
import type { Page } from "./paginate.js";
|
|
5
|
+
import { paginate, getHeaderAndFooter } from "./paginate.js";
|
|
5
6
|
import { updatePageRefs } from "./update-refs.js";
|
|
6
7
|
import { renderImage } from "./render-image.js";
|
|
7
8
|
import { registerFonts, getFontNameStyle } from "./font.js";
|
|
8
9
|
import { registerDefaultStdFonts } from "./std-fonts.js";
|
|
9
10
|
import { toBlob, toBytes } from "pdfkit/output";
|
|
10
|
-
import
|
|
11
|
+
import PDFDocument from "pdfkit";
|
|
12
|
+
import type { PdfKitAlignment } from "./textRunRow.js";
|
|
13
|
+
import { rowsCombineTextRuns, rowsSplit } from "./textRunRow.js";
|
|
11
14
|
|
|
12
15
|
export type PdfExportOptions = {
|
|
13
16
|
compress: boolean;
|
|
14
17
|
};
|
|
15
18
|
|
|
16
19
|
export function exportToHTML5Blob(
|
|
17
|
-
pdfKit: PDFKit.PDFDocument,
|
|
18
20
|
doc: AD.AbstractDoc.AbstractDoc,
|
|
19
21
|
options: PdfExportOptions = { compress: false }
|
|
20
22
|
): Promise<Blob> {
|
|
21
|
-
const pdf = createDocument(
|
|
23
|
+
const pdf = createDocument(options, doc);
|
|
22
24
|
return toBlob(pdf);
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export function exportToBytes(
|
|
26
|
-
pdfKit: PDFKit.PDFDocument,
|
|
27
28
|
doc: AD.AbstractDoc.AbstractDoc,
|
|
28
29
|
options: PdfExportOptions = { compress: false }
|
|
29
30
|
): Promise<Uint8Array> {
|
|
30
|
-
const pdf = createDocument(
|
|
31
|
+
const pdf = createDocument(options, doc);
|
|
31
32
|
return toBytes(pdf);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* On the client side the stream can be a BlobStream from the blob-stream package.
|
|
36
37
|
* On the server-side the stream can be a file stream from the fs package.
|
|
37
|
-
* @param pdfKit
|
|
38
38
|
* @param blobStream
|
|
39
39
|
* @param doc
|
|
40
40
|
* @param options
|
|
41
41
|
*/
|
|
42
42
|
export function exportToStream(
|
|
43
|
-
pdfKit: PDFKit.PDFDocument,
|
|
44
43
|
blobStream: any,
|
|
45
44
|
doc: AD.AbstractDoc.AbstractDoc,
|
|
46
45
|
options: PdfExportOptions = { compress: false }
|
|
47
46
|
): void {
|
|
48
|
-
let pdf = createDocument(
|
|
47
|
+
let pdf = createDocument(options, doc);
|
|
49
48
|
pdf.pipe(blobStream);
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
function createDocument(
|
|
53
|
-
pdfKit: PDFKit.PDFDocument,
|
|
54
|
-
options: PdfExportOptions,
|
|
55
|
-
ad: AD.AbstractDoc.AbstractDoc
|
|
56
|
-
): PDFKit.PDFDocument {
|
|
51
|
+
function createDocument(options: PdfExportOptions, ad: AD.AbstractDoc.AbstractDoc): PDFKit.PDFDocument {
|
|
57
52
|
registerDefaultStdFonts();
|
|
58
|
-
const pdf = new
|
|
53
|
+
const pdf = new PDFDocument({ ...options, autoFirstPage: false, bufferPages: true });
|
|
59
54
|
|
|
60
55
|
const document = preProcess(ad);
|
|
61
56
|
registerFonts((fontName: string, fontSource: AD.Font.FontSource) => pdf.registerFont(fontName, fontSource), document);
|
|
62
|
-
const desiredSizes = measure(
|
|
63
|
-
const pages = paginate(
|
|
57
|
+
const desiredSizes = measure(PDFDocument, document);
|
|
58
|
+
const pages = paginate(PDFDocument, document, desiredSizes);
|
|
64
59
|
const updatedPages = updatePageRefs(pages);
|
|
65
|
-
const pageDesiredSizes = measurePages(
|
|
60
|
+
const pageDesiredSizes = measurePages(PDFDocument, document, updatedPages);
|
|
66
61
|
|
|
67
62
|
for (let page of updatedPages) {
|
|
68
63
|
renderPage(document, pdf, pageDesiredSizes, page);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as AD from "../../abstract-document/index.js";
|
|
2
|
-
import { Page } from "./paginate.js";
|
|
1
|
+
import type * as AD from "../../abstract-document/index.js";
|
|
2
|
+
import type { Page } from "./paginate.js";
|
|
3
3
|
|
|
4
4
|
export function updatePageRefs(pages: ReadonlyArray<Page>): Array<Page> {
|
|
5
5
|
return pages.map((page) => updateRefsOnPage(page, pages));
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { exhaustiveCheck } from "ts-exhaustive-check";
|
|
2
|
-
import { AbstractDoc } from "../../abstract-document/abstract-doc.js";
|
|
3
|
-
import { Resources
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
2
|
+
import type { AbstractDoc } from "../../abstract-document/abstract-doc.js";
|
|
3
|
+
import type { Resources } from "../../abstract-document/resources.js";
|
|
4
|
+
import { mergeResources } from "../../abstract-document/resources.js";
|
|
5
|
+
import type { Group } from "../../abstract-document/section-elements/group.js";
|
|
6
|
+
import type { Table } from "../../abstract-document/section-elements/table.js";
|
|
7
|
+
import type { SectionElement } from "../../abstract-document/section-elements/section-element.js";
|
|
8
|
+
import type { Paragraph } from "../../abstract-document/section-elements/paragraph.js";
|
|
9
|
+
import type { Section } from "../../abstract-document/page/section.js";
|
|
10
|
+
import type { TableRow } from "../../abstract-document/table/table-row.js";
|
|
11
|
+
import type { TableCell } from "../../abstract-document/table/table-cell.js";
|
|
11
12
|
|
|
12
13
|
export function getResources(doc: AbstractDoc): Resources {
|
|
13
14
|
const resources = doc.children.map((s) => getResourcesSection(s));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { addResources, merge } from "../../abstract-document/abstract-doc.js";
|
|
2
|
-
import { AbstractDoc } from "../../abstract-document/index.js";
|
|
2
|
+
import type { AbstractDoc } from "../../abstract-document/index.js";
|
|
3
3
|
import * as StyleKey from "../../abstract-document/styles/style-key.js";
|
|
4
|
-
import { Resources } from "../../abstract-document/resources.js";
|
|
5
|
-
import { ADCreatorFn
|
|
4
|
+
import type { Resources } from "../../abstract-document/resources.js";
|
|
5
|
+
import type { ADCreatorFn } from "./creator.js";
|
|
6
|
+
import { creators, propsCreators } from "./creator.js";
|
|
6
7
|
import { parseHandlebarsXml, type XmlElement } from "handlebars-xml";
|
|
7
8
|
import { getFontStyleName } from "../../abstract-document-exporters/pdf/font.js";
|
|
8
|
-
import { Font } from "../../abstract-document/primitives/font.js";
|
|
9
|
+
import type { Font } from "../../abstract-document/primitives/font.js";
|
|
9
10
|
|
|
10
11
|
export type TemplateInput = {
|
|
11
12
|
readonly template: string;
|
|
@@ -72,9 +73,9 @@ function abstractDocXmlRecursive(
|
|
|
72
73
|
const childName = childElement.tagName;
|
|
73
74
|
if (childName !== undefined) {
|
|
74
75
|
if (childName === "StyleNames") {
|
|
75
|
-
props
|
|
76
|
-
} else if (childName === "StyleName" && childElement.attributes && childElement.attributes
|
|
77
|
-
const styleName = StyleKey.create(childElement.attributes
|
|
76
|
+
props["styles"] = abstractDocXmlRecursive(creators, childElement);
|
|
77
|
+
} else if (childName === "StyleName" && childElement.attributes && childElement.attributes["name"]) {
|
|
78
|
+
const styleName = StyleKey.create(childElement.attributes["type"], childElement.attributes["name"]);
|
|
78
79
|
const style = abstractDocXmlRecursive(creators, childElement);
|
|
79
80
|
props[styleName] = style;
|
|
80
81
|
} else if (childName.startsWith(childName.charAt(0).toUpperCase())) {
|
|
@@ -85,11 +86,11 @@ function abstractDocXmlRecursive(
|
|
|
85
86
|
// Some special keys should directly have an array of children as value instead of an object with children key
|
|
86
87
|
const arrayedElements = ["header", "footer", "headerRows"];
|
|
87
88
|
const childrenOnly = arrayedElements.findIndex((e) => e === childName) !== -1;
|
|
88
|
-
const differentFirstPage = childElement.attributes
|
|
89
|
+
const differentFirstPage = childElement.attributes["differentFirstPage"];
|
|
89
90
|
if (differentFirstPage === "true" && childName === "header") {
|
|
90
|
-
props
|
|
91
|
+
props["frontHeader"] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
|
|
91
92
|
} else if (differentFirstPage === "true" && childName === "footer") {
|
|
92
|
-
props
|
|
93
|
+
props["frontFooter"] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
|
|
93
94
|
} else {
|
|
94
95
|
props[childName] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
|
|
95
96
|
}
|
|
@@ -119,19 +120,19 @@ function abstractDocXmlRecursive(
|
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
// Elements styling needs to have style: {type= "StyleName" }. Occures when having a <style></style> element.
|
|
122
|
-
if (typeof obj
|
|
123
|
-
if (obj
|
|
124
|
-
obj
|
|
123
|
+
if (typeof obj["style"] === "object") {
|
|
124
|
+
if (obj["columnSpan"]) {
|
|
125
|
+
obj["style"] = { ...obj["style"], type: "TableCellStyle" };
|
|
125
126
|
} else {
|
|
126
|
-
switch (obj
|
|
127
|
+
switch (obj["type"]) {
|
|
127
128
|
case "page":
|
|
128
|
-
obj
|
|
129
|
+
obj["style"] = { ...obj["style"], type: "MasterPageStyle" };
|
|
129
130
|
break;
|
|
130
131
|
case "Group":
|
|
131
|
-
obj
|
|
132
|
+
obj["style"] = { ...obj["style"], type: "GroupStyle" };
|
|
132
133
|
break;
|
|
133
134
|
case "Table":
|
|
134
|
-
obj
|
|
135
|
+
obj["style"] = { ...obj["style"], type: "TableStyle" };
|
|
135
136
|
break;
|
|
136
137
|
// Cell is missing type in abstract doc?!?!?!
|
|
137
138
|
// case "TableCell":
|
|
@@ -142,12 +143,12 @@ function abstractDocXmlRecursive(
|
|
|
142
143
|
case "TextParagraph":
|
|
143
144
|
case "ImageParagraph":
|
|
144
145
|
case "Paragraph":
|
|
145
|
-
obj
|
|
146
|
+
obj["style"] = { ...obj["style"], type: "ParagraphStyle" };
|
|
146
147
|
break;
|
|
147
148
|
case "TextField":
|
|
148
149
|
case "HyperLink":
|
|
149
150
|
case "TextRun":
|
|
150
|
-
obj
|
|
151
|
+
obj["style"] = { ...obj["style"], type: "TextStyle" };
|
|
151
152
|
break;
|
|
152
153
|
default:
|
|
153
154
|
break;
|
|
@@ -156,7 +157,7 @@ function abstractDocXmlRecursive(
|
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
if (children.length > 0) {
|
|
159
|
-
obj
|
|
160
|
+
obj["children"] = children;
|
|
160
161
|
}
|
|
161
162
|
return obj;
|
|
162
163
|
}
|
|
@@ -188,7 +189,7 @@ function extractImageFontsStyleNames(
|
|
|
188
189
|
styleNames: Record<string, string> = {},
|
|
189
190
|
images: Record<string, true> = {},
|
|
190
191
|
fonts: Record<string, Partial<Record<keyof Font, boolean>>> = {},
|
|
191
|
-
currentFontFamily: string | undefined = undefined
|
|
192
|
+
currentFontFamily: string | undefined = undefined
|
|
192
193
|
): readonly [
|
|
193
194
|
imageUrls: Record<string, true>,
|
|
194
195
|
fontFamilies: Record<string, Partial<Record<keyof Font, boolean>>>,
|
|
@@ -196,41 +197,41 @@ function extractImageFontsStyleNames(
|
|
|
196
197
|
] {
|
|
197
198
|
let crFntFam = currentFontFamily;
|
|
198
199
|
xmlElement.forEach((item) => {
|
|
199
|
-
if (item.tagName.startsWith("Image") && item.attributes?.src) {
|
|
200
|
-
images[item.attributes
|
|
200
|
+
if (item.tagName.startsWith("Image") && item.attributes?.["src"]) {
|
|
201
|
+
images[item.attributes["src"] as string] = true;
|
|
201
202
|
} else if (item.tagName === "style") {
|
|
202
|
-
const fontFamily = crFntFam ?? styleFamilies
|
|
203
|
-
if(fontFamily) {
|
|
203
|
+
const fontFamily = crFntFam ?? styleFamilies["Default"];
|
|
204
|
+
if (fontFamily) {
|
|
204
205
|
const styleName = getFontStyleName(item.attributes);
|
|
205
206
|
(fonts[fontFamily] ??= {})[styleName] = true;
|
|
206
207
|
}
|
|
207
|
-
} else if(item.attributes
|
|
208
|
-
crFntFam = styleFamilies[item.attributes
|
|
209
|
-
} else if (item.attributes
|
|
210
|
-
const style = item.attributes
|
|
211
|
-
if(style) {
|
|
208
|
+
} else if (item.attributes["styleName"] !== undefined) {
|
|
209
|
+
crFntFam = styleFamilies[item.attributes["styleName"]] ?? crFntFam;
|
|
210
|
+
} else if (item.attributes["styleNames"] !== undefined) {
|
|
211
|
+
const style = item.attributes["styleNames"].split(",").find((style) => styleFamilies[style]);
|
|
212
|
+
if (style) {
|
|
212
213
|
const fontFamily = styleFamilies[style];
|
|
213
|
-
if(fontFamily) {
|
|
214
|
+
if (fontFamily) {
|
|
214
215
|
crFntFam = fontFamily;
|
|
215
216
|
}
|
|
216
217
|
}
|
|
217
|
-
} else if (item.attributes?.fontFamily) {
|
|
218
|
+
} else if (item.attributes?.["fontFamily"]) {
|
|
218
219
|
const styleName = getFontStyleName(item.attributes);
|
|
219
|
-
(fonts[item.attributes
|
|
220
|
-
if (item.tagName === "StyleName" && item.attributes
|
|
221
|
-
styleNames[item.attributes
|
|
220
|
+
(fonts[item.attributes["fontFamily"] as string] ??= {})[styleName] = true;
|
|
221
|
+
if (item.tagName === "StyleName" && item.attributes["name"] && item.attributes["type"]) {
|
|
222
|
+
styleNames[item.attributes["name"] as string] = item.attributes["type"];
|
|
222
223
|
}
|
|
223
|
-
} else if (item.tagName === "StyleName" && item.attributes
|
|
224
|
-
styleNames[item.attributes
|
|
225
|
-
if(item.attributes
|
|
224
|
+
} else if (item.tagName === "StyleName" && item.attributes["name"] && item.attributes["type"]) {
|
|
225
|
+
styleNames[item.attributes["name"] as string] = item.attributes["type"];
|
|
226
|
+
if (item.attributes["type"] === "TextStyle" && item.attributes["fontFamily"]) {
|
|
226
227
|
const styleName = getFontStyleName(item.attributes);
|
|
227
|
-
styleFamilies[item.attributes
|
|
228
|
-
(fonts[item.attributes
|
|
228
|
+
styleFamilies[item.attributes["name"] as string] = item.attributes["fontFamily"];
|
|
229
|
+
(fonts[item.attributes["fontFamily"]] ??= {})[styleName] = true;
|
|
229
230
|
}
|
|
230
231
|
}
|
|
231
|
-
if(item.children.length > 0) {
|
|
232
|
+
if (item.children.length > 0) {
|
|
232
233
|
extractImageFontsStyleNames(item.children, styleFamilies, styleNames, images, fonts, crFntFam);
|
|
233
234
|
}
|
|
234
235
|
});
|
|
235
236
|
return [images, fonts, styleNames];
|
|
236
|
-
}
|
|
237
|
+
}
|