abstract-document 20.0.1 → 20.0.4
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 +4 -0
- package/README.md +3 -3
- 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/atoms/line-break.d.ts +1 -1
- package/lib/abstract-document/atoms/line-break.d.ts.map +1 -1
- package/lib/abstract-document/atoms/line-break.js +1 -1
- package/lib/abstract-document/atoms/line-break.js.map +1 -1
- package/lib/abstract-document/atoms/link-target.js +1 -1
- package/lib/abstract-document/atoms/text-run.d.ts.map +1 -1
- package/lib/abstract-document/atoms/text-run.js +1 -0
- package/lib/abstract-document/atoms/text-run.js.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 +6 -3
- 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-format.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/primitives/layout-foundation-color.js +4 -4
- package/lib/abstract-document/primitives/layout-foundation-color.js.map +1 -1
- package/lib/abstract-document/primitives/layout-foundation.js +1 -1
- package/lib/abstract-document/primitives/point.js +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/paragraph.js +1 -1
- package/lib/abstract-document/section-elements/paragraph.js.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/paragraph-style.js +1 -1
- package/lib/abstract-document/styles/paragraph-style.js.map +1 -1
- package/lib/abstract-document/styles/table-cell-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/table-cell-style.js +1 -1
- package/lib/abstract-document/styles/table-cell-style.js.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/styles/table-style.js +1 -1
- package/lib/abstract-document/styles/table-style.js.map +1 -1
- package/lib/abstract-document/styles/text-style.js +1 -1
- package/lib/abstract-document/styles/text-style.js.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/string-utils.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/string-utils.js +1 -3
- package/lib/abstract-document-exporters/docx/string-utils.js.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 +1 -0
- 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 +8 -14
- 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 +37 -29
- 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 +2 -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 +3 -2
- package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.js +3 -2
- 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 +3 -2
- package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.js +1 -3
- package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.js +1 -0
- package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/std-fonts.js +1 -1
- package/lib/abstract-document-exporters/pdf/textRunRow.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/textRunRow.js +21 -15
- package/lib/abstract-document-exporters/pdf/textRunRow.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-jsx/index.js.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 +33 -33
- 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 +81 -75
- 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 +4 -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/atoms/line-break.ts +1 -1
- package/src/abstract-document/atoms/link-target.ts +1 -1
- package/src/abstract-document/atoms/text-run.ts +1 -0
- package/src/abstract-document/default-styles.ts +2 -2
- package/src/abstract-document/markdown/markdown.ts +11 -8
- 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-format.ts +1 -7
- 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/primitives/layout-foundation-color.ts +4 -4
- package/src/abstract-document/primitives/layout-foundation.ts +1 -1
- package/src/abstract-document/primitives/point.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 +4 -4
- 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 +2 -2
- package/src/abstract-document/styles/table-cell-style.ts +1 -8
- package/src/abstract-document/styles/table-style.ts +2 -2
- package/src/abstract-document/styles/text-style.ts +20 -20
- 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/docx/string-utils.ts +1 -5
- package/src/abstract-document-exporters/docx/xml-writer.ts +1 -0
- package/src/abstract-document-exporters/docx2/render-image.ts +69 -57
- package/src/abstract-document-exporters/docx2/render.ts +104 -77
- package/src/abstract-document-exporters/pdf/font.ts +16 -15
- package/src/abstract-document-exporters/pdf/measure.ts +6 -3
- package/src/abstract-document-exporters/pdf/paginate.ts +11 -6
- package/src/abstract-document-exporters/pdf/pre-process.ts +3 -3
- package/src/abstract-document-exporters/pdf/render-image.ts +10 -12
- package/src/abstract-document-exporters/pdf/render.ts +5 -2
- package/src/abstract-document-exporters/pdf/std-fonts.ts +1 -1
- package/src/abstract-document-exporters/pdf/textRunRow.ts +108 -74
- 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-jsx/index.ts +1 -1
- package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +47 -46
- package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +118 -114
- 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/abstract-document-xml/xsd-template/styles.ts +1 -1
- package/src/custom_typings/pdfkit-standard-fonts/index.d.ts +0 -1
- package/lib/abstract-document/table/text-row.d.ts +0 -2
- package/lib/abstract-document/table/text-row.d.ts.map +0 -1
- package/lib/abstract-document/table/text-row.js +0 -2
- package/lib/abstract-document/table/text-row.js.map +0 -1
- package/lib/abstract-document-exporters/docx/docx-document-renderer.d.ts +0 -2
- package/lib/abstract-document-exporters/docx/docx-document-renderer.d.ts.map +0 -1
- package/lib/abstract-document-exporters/docx/docx-document-renderer.js +0 -1085
- package/lib/abstract-document-exporters/docx/docx-document-renderer.js.map +0 -1
- package/src/abstract-document/table/text-row.ts +0 -0
- package/src/abstract-document-exporters/docx/docx-document-renderer.ts +0 -1084
|
@@ -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";
|
|
@@ -37,23 +39,27 @@ const abstractDocPixelToDocxDXARatio = 20;
|
|
|
37
39
|
const abstractDocBorderToDocxBorderSizeRatio = 8;
|
|
38
40
|
|
|
39
41
|
export function exportToHTML5Blob(doc: AD.AbstractDoc.AbstractDoc): Promise<Blob> {
|
|
40
|
-
return new Promise((resolve) => {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
41
43
|
const docx = createDocument(doc);
|
|
42
|
-
Packer.toBlob(docx)
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
Packer.toBlob(docx)
|
|
45
|
+
.then((blob) => {
|
|
46
|
+
resolve(blob);
|
|
47
|
+
})
|
|
48
|
+
.catch(reject);
|
|
45
49
|
});
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
export function exportToStream(blobStream: NodeJS.WritableStream, doc: AD.AbstractDoc.AbstractDoc): void {
|
|
49
53
|
const docx = createDocument(doc);
|
|
50
54
|
|
|
51
|
-
Packer.toBuffer(docx)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
Packer.toBuffer(docx)
|
|
56
|
+
.then((buffer) => {
|
|
57
|
+
const readableStream = new Readable();
|
|
58
|
+
readableStream.push(buffer);
|
|
59
|
+
readableStream.push(null);
|
|
60
|
+
readableStream.pipe(blobStream);
|
|
61
|
+
})
|
|
62
|
+
.catch((err: unknown) => blobStream.emit("error", err instanceof Error ? err : new Error(String(err))));
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
/**
|
|
@@ -72,38 +78,52 @@ function createDocument(doc: AD.AbstractDoc.AbstractDoc): Document {
|
|
|
72
78
|
|
|
73
79
|
function renderSection(section: AD.Section.Section, parentResources: AD.Resources.Resources): ISectionOptions {
|
|
74
80
|
const pageWidth = AD.PageStyle.getWidth(section.page.style);
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const pageFooterMargins = AD.LayoutFoundation.orDefault(section.page.style.footerMargins)
|
|
81
|
+
const pageHeaderMargins = AD.LayoutFoundation.orDefault(section.page.style.headerMargins);
|
|
82
|
+
const pageFooterMargins = AD.LayoutFoundation.orDefault(section.page.style.footerMargins);
|
|
78
83
|
const pageContentMargins = AD.LayoutFoundation.orDefault(section.page.style.contentMargins);
|
|
79
84
|
|
|
80
85
|
const hasFrontHeader = section.page.frontHeader !== undefined && section.page.frontHeader.length !== 0;
|
|
81
86
|
const hasFrontFooter = section.page.frontFooter !== undefined && section.page.frontFooter.length !== 0;
|
|
82
|
-
|
|
83
|
-
const contentAvailableWidth =
|
|
84
|
-
pageWidth - (pageContentMargins.left + pageContentMargins.right);
|
|
87
|
+
|
|
88
|
+
const contentAvailableWidth = pageWidth - (pageContentMargins.left + pageContentMargins.right);
|
|
85
89
|
|
|
86
90
|
const resources = AD.Resources.mergeResources([parentResources, section]);
|
|
87
91
|
|
|
88
|
-
const headerChildren = section.page.header.reduce(
|
|
89
|
-
sofar
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
const headerChildren = section.page.header.reduce(
|
|
93
|
+
(sofar, c) => {
|
|
94
|
+
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
95
|
+
return sofar;
|
|
96
|
+
},
|
|
97
|
+
[] as Array<Paragraph | Table>
|
|
98
|
+
);
|
|
92
99
|
|
|
93
|
-
const firstpageHeaderChildren = hasFrontHeader
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
const firstpageHeaderChildren = hasFrontHeader
|
|
101
|
+
? section.page.frontHeader.reduce(
|
|
102
|
+
(sofar, c) => {
|
|
103
|
+
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
104
|
+
return sofar;
|
|
105
|
+
},
|
|
106
|
+
[] as Array<Paragraph | Table>
|
|
107
|
+
)
|
|
108
|
+
: [];
|
|
97
109
|
|
|
98
|
-
const footerChildren = section.page.footer.reduce(
|
|
99
|
-
sofar
|
|
100
|
-
|
|
101
|
-
|
|
110
|
+
const footerChildren = section.page.footer.reduce(
|
|
111
|
+
(sofar, c) => {
|
|
112
|
+
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
113
|
+
return sofar;
|
|
114
|
+
},
|
|
115
|
+
[] as Array<Paragraph | Table>
|
|
116
|
+
);
|
|
102
117
|
|
|
103
|
-
const firstPageFooterChildren = hasFrontFooter
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
118
|
+
const firstPageFooterChildren = hasFrontFooter
|
|
119
|
+
? section.page.frontFooter.reduce(
|
|
120
|
+
(sofar, c) => {
|
|
121
|
+
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
122
|
+
return sofar;
|
|
123
|
+
},
|
|
124
|
+
[] as Array<Paragraph | Table>
|
|
125
|
+
)
|
|
126
|
+
: [];
|
|
107
127
|
|
|
108
128
|
const contentChildren = [
|
|
109
129
|
new Paragraph({
|
|
@@ -115,10 +135,13 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
115
135
|
}),
|
|
116
136
|
],
|
|
117
137
|
}),
|
|
118
|
-
...section.children.reduce(
|
|
119
|
-
sofar
|
|
120
|
-
|
|
121
|
-
|
|
138
|
+
...section.children.reduce(
|
|
139
|
+
(sofar, c) => {
|
|
140
|
+
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
141
|
+
return sofar;
|
|
142
|
+
},
|
|
143
|
+
[] as Array<Paragraph | Table>
|
|
144
|
+
),
|
|
122
145
|
];
|
|
123
146
|
|
|
124
147
|
return {
|
|
@@ -146,17 +169,21 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
146
169
|
default: new Header({
|
|
147
170
|
children: headerChildren,
|
|
148
171
|
}),
|
|
149
|
-
first: hasFrontHeader
|
|
150
|
-
|
|
151
|
-
|
|
172
|
+
first: hasFrontHeader
|
|
173
|
+
? new Header({
|
|
174
|
+
children: firstpageHeaderChildren,
|
|
175
|
+
})
|
|
176
|
+
: undefined,
|
|
152
177
|
},
|
|
153
178
|
footers: {
|
|
154
179
|
default: new Footer({
|
|
155
|
-
children: footerChildren
|
|
180
|
+
children: footerChildren,
|
|
156
181
|
}),
|
|
157
|
-
first: hasFrontFooter
|
|
158
|
-
|
|
159
|
-
|
|
182
|
+
first: hasFrontFooter
|
|
183
|
+
? new Footer({
|
|
184
|
+
children: firstPageFooterChildren,
|
|
185
|
+
})
|
|
186
|
+
: undefined,
|
|
160
187
|
},
|
|
161
188
|
children: contentChildren,
|
|
162
189
|
};
|
|
@@ -176,9 +203,9 @@ function renderHyperLink(
|
|
|
176
203
|
characterSpacing: style.characterSpacing,
|
|
177
204
|
underline: style.underline
|
|
178
205
|
? {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
206
|
+
color: style.color || "#0000ff",
|
|
207
|
+
type: UnderlineType.SINGLE,
|
|
208
|
+
}
|
|
182
209
|
: undefined,
|
|
183
210
|
});
|
|
184
211
|
|
|
@@ -302,7 +329,9 @@ function renderTable(
|
|
|
302
329
|
style: BorderStyle.NONE,
|
|
303
330
|
},
|
|
304
331
|
},
|
|
305
|
-
rows: table.headerRows
|
|
332
|
+
rows: table.headerRows
|
|
333
|
+
.concat(table.children)
|
|
334
|
+
.map((c) => renderRow(c, resources, style.cellStyle, columnWidths, keepNext)),
|
|
306
335
|
});
|
|
307
336
|
}
|
|
308
337
|
|
|
@@ -317,16 +346,11 @@ function renderRow(
|
|
|
317
346
|
(acc, cell) => {
|
|
318
347
|
const span = cell.columnSpan ?? 1;
|
|
319
348
|
|
|
320
|
-
const width = columnWidths
|
|
321
|
-
.slice(acc.columnIndex, acc.columnIndex + span)
|
|
322
|
-
.reduce((a, b) => a + b, 0);
|
|
349
|
+
const width = columnWidths.slice(acc.columnIndex, acc.columnIndex + span).reduce((a, b) => a + b, 0);
|
|
323
350
|
|
|
324
351
|
return {
|
|
325
352
|
columnIndex: acc.columnIndex + span,
|
|
326
|
-
children: [
|
|
327
|
-
...acc.children,
|
|
328
|
-
renderCell(cell, resources, tableCellStyle, width, keepNext),
|
|
329
|
-
],
|
|
353
|
+
children: [...acc.children, renderCell(cell, resources, tableCellStyle, width, keepNext)],
|
|
330
354
|
};
|
|
331
355
|
},
|
|
332
356
|
{ columnIndex: 0, children: [] as TableCell[] }
|
|
@@ -346,7 +370,7 @@ function renderCell(
|
|
|
346
370
|
keepNext: boolean
|
|
347
371
|
): TableCell {
|
|
348
372
|
const abstractDocPxCellWidth = width / abstractDocPixelToDocxDXARatio;
|
|
349
|
-
|
|
373
|
+
|
|
350
374
|
const style = AD.Resources.getStyle(
|
|
351
375
|
tableCellStyle,
|
|
352
376
|
cell.style,
|
|
@@ -403,10 +427,13 @@ function renderCell(
|
|
|
403
427
|
},
|
|
404
428
|
},
|
|
405
429
|
|
|
406
|
-
children: cell.children.reduce(
|
|
407
|
-
sofar
|
|
408
|
-
|
|
409
|
-
|
|
430
|
+
children: cell.children.reduce(
|
|
431
|
+
(sofar, c) => {
|
|
432
|
+
sofar.push(...renderSectionElement(c, resources, abstractDocPxCellWidth, keepNext));
|
|
433
|
+
return sofar;
|
|
434
|
+
},
|
|
435
|
+
[] as Array<Paragraph | Table>
|
|
436
|
+
),
|
|
410
437
|
});
|
|
411
438
|
}
|
|
412
439
|
|
|
@@ -494,9 +521,9 @@ function renderPageNumber(style: AD.TextStyle.TextStyle): TextRun {
|
|
|
494
521
|
characterSpacing: style.characterSpacing,
|
|
495
522
|
underline: style.underline
|
|
496
523
|
? {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
524
|
+
color: style.color,
|
|
525
|
+
type: UnderlineType.SINGLE,
|
|
526
|
+
}
|
|
500
527
|
: undefined,
|
|
501
528
|
children: [PageNumber.CURRENT],
|
|
502
529
|
});
|
|
@@ -512,9 +539,9 @@ function renderTotalPages(style: AD.TextStyle.TextStyle): TextRun {
|
|
|
512
539
|
characterSpacing: style.characterSpacing,
|
|
513
540
|
underline: style.underline
|
|
514
541
|
? {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
542
|
+
color: style.color,
|
|
543
|
+
type: UnderlineType.SINGLE,
|
|
544
|
+
}
|
|
518
545
|
: undefined,
|
|
519
546
|
children: [PageNumber.TOTAL_PAGES],
|
|
520
547
|
});
|
|
@@ -532,9 +559,9 @@ function renderText(style: AD.TextStyle.TextStyle, text: string): TextRun {
|
|
|
532
559
|
characterSpacing: style.characterSpacing,
|
|
533
560
|
underline: style.underline
|
|
534
561
|
? {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
562
|
+
color: style.color,
|
|
563
|
+
type: UnderlineType.SINGLE,
|
|
564
|
+
}
|
|
538
565
|
: undefined,
|
|
539
566
|
});
|
|
540
567
|
}
|
|
@@ -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(
|
|
@@ -33,16 +33,16 @@ function getFontWeightFromStyle(textStyle: AD.TextStyle.TextStyle): TextFontWeig
|
|
|
33
33
|
return textStyle.fontWeight
|
|
34
34
|
? textStyle.fontWeight
|
|
35
35
|
: textStyle.light
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
? "light"
|
|
37
|
+
: textStyle.normal
|
|
38
|
+
? "normal"
|
|
39
|
+
: textStyle.bold
|
|
40
|
+
? "bold"
|
|
41
|
+
: textStyle.mediumBold
|
|
42
|
+
? "mediumBold"
|
|
43
|
+
: textStyle.extraBold
|
|
44
|
+
? "extraBold"
|
|
45
|
+
: "normal";
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function getFontWeightFromAttributes(attribs: Record<string, string>): TextFontWeight {
|
|
@@ -57,12 +57,13 @@ 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
|
-
|
|
60
|
+
// oxlint-disable-next-line typescript/no-unnecessary-template-expression
|
|
61
|
+
const stringifiedItalic = `${attributes["italic"]}`;
|
|
61
62
|
const italic = stringifiedItalic === "true" || stringifiedItalic === "1";
|
|
62
|
-
if(fontWeight === "normal") {
|
|
63
|
+
if (fontWeight === "normal") {
|
|
63
64
|
return italic ? "italic" : fontWeight;
|
|
64
65
|
}
|
|
65
|
-
return `${fontWeight === "mediumBold" ? "medium" : fontWeight}${italic ? "Italic": ""}`;
|
|
66
|
+
return `${fontWeight === "mediumBold" ? "medium" : fontWeight}${italic ? "Italic" : ""}`;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
export function getFontName(
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import * as AD from "../../abstract-document/index.js";
|
|
2
2
|
import { exhaustiveCheck } from "ts-exhaustive-check";
|
|
3
|
-
import
|
|
3
|
+
// oxlint-disable-next-line import/no-cycle -- type-only, erased at compile time
|
|
4
|
+
import type { Page } from "./paginate.js";
|
|
5
|
+
// oxlint-disable-next-line import/no-cycle -- both sides only call each other from function bodies
|
|
6
|
+
import { getHeaderAndFooter } from "./paginate.js";
|
|
4
7
|
import { registerFonts, getFontNameStyle } from "./font.js";
|
|
5
8
|
|
|
6
9
|
//tslint:disable:no-any variable-name
|
|
@@ -302,7 +305,7 @@ export function measureTable(
|
|
|
302
305
|
return a.child.rowSpan - b.child.rowSpan;
|
|
303
306
|
}
|
|
304
307
|
});
|
|
305
|
-
const minRowHeights =
|
|
308
|
+
const minRowHeights = Array.from({ length: rows.length }, () => 0);
|
|
306
309
|
for (const { child, rowIndex } of cells) {
|
|
307
310
|
const rowSpan = child.rowSpan || 1;
|
|
308
311
|
let currentHeight = 0;
|
|
@@ -487,7 +490,7 @@ function measureImage(
|
|
|
487
490
|
const firstComp = ai.components[0];
|
|
488
491
|
const resource =
|
|
489
492
|
!ai.size.width && !ai.size.height && firstComp?.type === "binaryimage" && firstComp.data.type === "url"
|
|
490
|
-
? resources.imageResources?.[firstComp.data.url] ?? image.imageResource
|
|
493
|
+
? (resources.imageResources?.[firstComp.data.url] ?? image.imageResource)
|
|
491
494
|
: image.imageResource;
|
|
492
495
|
|
|
493
496
|
let desiredWidth = availableSize.width;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as AD from "../../abstract-document/index.js";
|
|
2
2
|
import { getResources } from "../shared/get_resources.js";
|
|
3
3
|
import { registerFonts } from "./font.js";
|
|
4
|
+
// oxlint-disable-next-line import/no-cycle -- both sides only call each other from function bodies
|
|
4
5
|
import { measureTable } from "./measure.js";
|
|
5
6
|
|
|
6
7
|
export interface PageColumn {
|
|
@@ -280,12 +281,16 @@ export function getHeaderAndFooter(
|
|
|
280
281
|
return {
|
|
281
282
|
footer: normalFooter ? section.page.footer : section.page.frontFooter,
|
|
282
283
|
header: normalHeader ? section.page.header : section.page.frontHeader,
|
|
283
|
-
headerMargins: AD.LayoutFoundation.orDefault(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
284
|
+
headerMargins: AD.LayoutFoundation.orDefault(
|
|
285
|
+
normalHeader
|
|
286
|
+
? section.page.style.headerMargins
|
|
287
|
+
: (section.page.style.firstPageHeaderMargins ?? section.page.style.headerMargins)
|
|
288
|
+
),
|
|
289
|
+
footerMargins: AD.LayoutFoundation.orDefault(
|
|
290
|
+
normalFooter
|
|
291
|
+
? section.page.style.footerMargins
|
|
292
|
+
: (section.page.style.firstPageFooterMargins ?? section.page.style.footerMargins)
|
|
293
|
+
),
|
|
289
294
|
};
|
|
290
295
|
}
|
|
291
296
|
case pageNo === 0:
|
|
@@ -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",
|
|
@@ -184,7 +183,8 @@ function adjustParagraph(paragraph: AD.Paragraph.Paragraph): Array<AD.SectionEle
|
|
|
184
183
|
if (child.type === "TextRun") {
|
|
185
184
|
// Pdfkit will automatically split texts on "\n", which would not match with out measuring.
|
|
186
185
|
// Fix this by replacing "\n" with a LineBreak
|
|
187
|
-
|
|
186
|
+
// oxlint-disable-next-line typescript/no-unnecessary-type-conversion -- text isn't always a string at runtime
|
|
187
|
+
const text = String(child.text);
|
|
188
188
|
const lines = text.split("\n");
|
|
189
189
|
|
|
190
190
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -201,7 +201,7 @@ function adjustParagraph(paragraph: AD.Paragraph.Paragraph): Array<AD.SectionEle
|
|
|
201
201
|
type: "LineBreak",
|
|
202
202
|
style: child.style,
|
|
203
203
|
nestedStyleNames: child.nestedStyleNames,
|
|
204
|
-
styleName: child.styleName
|
|
204
|
+
styleName: child.styleName,
|
|
205
205
|
};
|
|
206
206
|
newChildren.push(lineBreak);
|
|
207
207
|
}
|
|
@@ -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";
|
|
@@ -17,7 +17,7 @@ export function renderImage(
|
|
|
17
17
|
const firstComp = ai.components[0];
|
|
18
18
|
const resource =
|
|
19
19
|
!ai.size.width && !ai.size.height && firstComp?.type === "binaryimage" && firstComp.data.type === "url"
|
|
20
|
-
? resources.imageResources?.[firstComp.data.url] ?? image.imageResource
|
|
20
|
+
? (resources.imageResources?.[firstComp.data.url] ?? image.imageResource)
|
|
21
21
|
: image.imageResource;
|
|
22
22
|
|
|
23
23
|
const position = AD.Point.create(finalRect.x, finalRect.y);
|
|
@@ -37,15 +37,15 @@ export function renderImage(
|
|
|
37
37
|
image.horizontalAlignment === "Center"
|
|
38
38
|
? (rect.width - drawnW) / 2
|
|
39
39
|
: image.horizontalAlignment === "Right"
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
? rect.width - drawnW
|
|
41
|
+
: 0;
|
|
42
42
|
|
|
43
43
|
const offsetY =
|
|
44
44
|
image.verticalAlignment === "Center"
|
|
45
45
|
? (rect.height - drawnH) / 2
|
|
46
46
|
: image.verticalAlignment === "Bottom"
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
? rect.height - drawnH
|
|
48
|
+
: 0;
|
|
49
49
|
|
|
50
50
|
pdf.save();
|
|
51
51
|
pdf.translate(position.x + offsetX, position.y + offsetY).scale(scale);
|
|
@@ -162,14 +162,14 @@ function abstractComponentToPdf(
|
|
|
162
162
|
component.horizontalGrowthDirection === "left"
|
|
163
163
|
? -stringWidth
|
|
164
164
|
: component.horizontalGrowthDirection === "uniform"
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
? -stringWidth * 0.5
|
|
166
|
+
: 0;
|
|
167
167
|
const dy =
|
|
168
168
|
component.verticalGrowthDirection === "up"
|
|
169
169
|
? -stringHeight
|
|
170
170
|
: component.verticalGrowthDirection === "uniform"
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
? -stringHeight * 0.5
|
|
172
|
+
: 0;
|
|
173
173
|
pdf
|
|
174
174
|
.font(font)
|
|
175
175
|
.fontSize(component.fontSize)
|
|
@@ -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,14 +1,17 @@
|
|
|
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";
|
|
11
|
+
// oxlint-disable-next-line import/no-named-as-default -- standard pdfkit import idiom
|
|
10
12
|
import PDFDocument from "pdfkit";
|
|
11
|
-
import { PdfKitAlignment
|
|
13
|
+
import type { PdfKitAlignment } from "./textRunRow.js";
|
|
14
|
+
import { rowsCombineTextRuns, rowsSplit } from "./textRunRow.js";
|
|
12
15
|
|
|
13
16
|
export type PdfExportOptions = {
|
|
14
17
|
compress: boolean;
|
|
@@ -14,7 +14,7 @@ const pdfkitExports = PdfkitModule as unknown as {
|
|
|
14
14
|
registerStdFonts?: (...fonts: ReadonlyArray<unknown>) => void;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
//
|
|
17
|
+
// oxlint-disable-next-line functional/no-let
|
|
18
18
|
let registered = false;
|
|
19
19
|
|
|
20
20
|
export function registerDefaultStdFonts(): void {
|