abstract-document 6.9.5 → 6.10.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 +12 -1
- package/README.md +2 -2
- package/lib/abstract-document/table/text-row.d.ts +1 -0
- package/lib/abstract-document/table/text-row.d.ts.map +1 -0
- package/lib/abstract-document/table/text-row.js +1 -0
- package/lib/abstract-document/table/text-row.js.map +1 -0
- package/lib/abstract-document-xml/__tests__/export-test-def.d.ts +13 -0
- package/lib/abstract-document-xml/__tests__/export-test-def.d.ts.map +1 -0
- package/lib/abstract-document-xml/__tests__/export-test-def.js +3 -0
- package/lib/abstract-document-xml/__tests__/export-test-def.js.map +1 -0
- package/lib/abstract-document-xml/__tests__/export.test.d.ts +3 -0
- package/lib/abstract-document-xml/__tests__/export.test.d.ts.map +1 -0
- package/lib/abstract-document-xml/__tests__/export.test.js +41 -0
- package/lib/abstract-document-xml/__tests__/export.test.js.map +1 -0
- package/lib/abstract-document-xml/__tests__/layer/export-test-def.d.ts +13 -0
- package/lib/abstract-document-xml/__tests__/layer/export-test-def.d.ts.map +1 -0
- package/lib/abstract-document-xml/__tests__/layer/export-test-def.js +3 -0
- package/lib/abstract-document-xml/__tests__/layer/export-test-def.js.map +1 -0
- package/lib/abstract-document-xml/__tests__/layer/export.test.d.ts +3 -0
- package/lib/abstract-document-xml/__tests__/layer/export.test.d.ts.map +1 -0
- package/lib/abstract-document-xml/__tests__/layer/export.test.js +41 -0
- package/lib/abstract-document-xml/__tests__/layer/export.test.js.map +1 -0
- package/lib/abstract-document-xml/__tests__/layer/test-defs/simple-document.d.ts +3 -0
- package/lib/abstract-document-xml/__tests__/layer/test-defs/simple-document.d.ts.map +1 -0
- package/lib/abstract-document-xml/__tests__/layer/test-defs/simple-document.js +361 -0
- package/lib/abstract-document-xml/__tests__/layer/test-defs/simple-document.js.map +1 -0
- package/lib/abstract-document-xml/__tests__/test-defs/simple-document.d.ts +3 -0
- package/lib/abstract-document-xml/__tests__/test-defs/simple-document.d.ts.map +1 -0
- package/lib/abstract-document-xml/__tests__/test-defs/simple-document.js +198 -0
- package/lib/abstract-document-xml/__tests__/test-defs/simple-document.js.map +1 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts +5 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts.map +1 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js +94 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js.map +1 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.d.ts +14 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.d.ts.map +1 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js +218 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js.map +1 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts +38 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts.map +1 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js +59 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js.map +1 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/index.d.ts +3 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/index.d.ts.map +1 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/index.js +17 -0
- package/lib/abstract-document-xml/abstract-doc-of-xml/index.js.map +1 -0
- package/lib/abstract-document-xml/index.d.ts +4 -0
- package/lib/abstract-document-xml/index.d.ts.map +1 -0
- package/lib/abstract-document-xml/index.js +16 -0
- package/lib/abstract-document-xml/index.js.map +1 -0
- package/lib/abstract-document-xml/parse-xml/index.d.ts +3 -0
- package/lib/abstract-document-xml/parse-xml/index.d.ts.map +1 -0
- package/lib/abstract-document-xml/parse-xml/index.js +15 -0
- package/lib/abstract-document-xml/parse-xml/index.js.map +1 -0
- package/lib/abstract-document-xml/parse-xml/parse-xml.d.ts +12 -0
- package/lib/abstract-document-xml/parse-xml/parse-xml.d.ts.map +1 -0
- package/lib/abstract-document-xml/parse-xml/parse-xml.js +83 -0
- package/lib/abstract-document-xml/parse-xml/parse-xml.js.map +1 -0
- package/lib/abstract-document-xml/parse-xml/validation.d.ts +21 -0
- package/lib/abstract-document-xml/parse-xml/validation.d.ts.map +1 -0
- package/lib/abstract-document-xml/parse-xml/validation.js +205 -0
- package/lib/abstract-document-xml/parse-xml/validation.js.map +1 -0
- package/lib/abstract-document-xml/xsd-template/custom-elements.d.ts +7 -0
- package/lib/abstract-document-xml/xsd-template/custom-elements.d.ts.map +1 -0
- package/lib/abstract-document-xml/xsd-template/custom-elements.js +57 -0
- package/lib/abstract-document-xml/xsd-template/custom-elements.js.map +1 -0
- package/lib/abstract-document-xml/xsd-template/elements.d.ts +19 -0
- package/lib/abstract-document-xml/xsd-template/elements.d.ts.map +1 -0
- package/lib/abstract-document-xml/xsd-template/elements.js +187 -0
- package/lib/abstract-document-xml/xsd-template/elements.js.map +1 -0
- package/lib/abstract-document-xml/xsd-template/index.d.ts +2 -0
- package/lib/abstract-document-xml/xsd-template/index.d.ts.map +1 -0
- package/lib/abstract-document-xml/xsd-template/index.js +14 -0
- package/lib/abstract-document-xml/xsd-template/index.js.map +1 -0
- package/lib/abstract-document-xml/xsd-template/styles.d.ts +11 -0
- package/lib/abstract-document-xml/xsd-template/styles.d.ts.map +1 -0
- package/lib/abstract-document-xml/xsd-template/styles.js +279 -0
- package/lib/abstract-document-xml/xsd-template/styles.js.map +1 -0
- package/lib/abstract-document-xml/xsd-template/xsd-template.d.ts +3 -0
- package/lib/abstract-document-xml/xsd-template/xsd-template.d.ts.map +1 -0
- package/lib/abstract-document-xml/xsd-template/xsd-template.js +71 -0
- package/lib/abstract-document-xml/xsd-template/xsd-template.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/package.json +4 -3
- package/src/abstract-document/table/text-row.ts +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Group.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Header and footer.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Header → footer.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed hyperlink and textrun.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed hyperlink → textrun.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed textrun and images.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed textrun → images.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple images.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple tables.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Center alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with End alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Start alignment that linebreaks.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Start alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Page numbering.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table colSpan and rowSpan.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table colSpan → rowSpan.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table without rows.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single hyperlink.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single image.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Center alignment that linebreaks.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Center alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with End alignment that linebreaks.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with End alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Start alignment that linebreaks.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Start alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/hello with Arial font.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/hello.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/letter-dimensions.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/page-orientation-landscape.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/page-orientation-portrait.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/tocSeparator.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/world.docx +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position group.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position header and footer.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position paragraph.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position section in group.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position section in table.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position table.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group Paragraphs.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group Tables.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group no keeptogether.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group too big for one page.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Header and footer.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Hyperlink internal linktarget.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Hyperlink internal.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun no underline.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun with underline.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed textrun and images.pdf and b/package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed textrun → images.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple images overflow.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple images.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Center alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with End alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Start alignment that linebreaks.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Start alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Page numbering.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table row that doesnt fit page.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table single row.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with group.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with header 2.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with header.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin bottom.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin top single table.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin top.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with rowSpan multipages.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with rowSpan.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table all auto.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table all fix.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table background.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table cell padding of image.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table cell padding of text.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table center alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table colSpan and rowSpan.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table minimal row height.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table mix auto fix.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table padding.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table right alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table row alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table text alignment in cell with wrapping.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table text alignment in cell.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with default colored borders.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with header.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with multi colored borders.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with single colored borders.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single date.pdf +14 -14
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single figure.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink centered.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink no underline.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink right aligned.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image from URL.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color hex.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color name.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color url.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg dasharray.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline alphabetic.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline bottom.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline hanging.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline middle.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline top.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Center alignment that linebreaks.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Center alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with End alignment that linebreaks.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with End alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Justify alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Start alignment that linebreaks.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Start alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with super and subscripts.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Table of content separator.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/hello with roman font.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/hello.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/pagebreak.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/world.pdf +2 -2
- package/src/abstract-document-xml/__tests__/export-test-def.ts +12 -0
- package/src/abstract-document-xml/__tests__/export.test.tsx +43 -0
- package/src/abstract-document-xml/__tests__/test-defs/simple-document.tsx +196 -0
- package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +96 -0
- package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +267 -0
- package/src/abstract-document-xml/abstract-doc-of-xml/custom-elements.tsx +110 -0
- package/src/abstract-document-xml/abstract-doc-of-xml/index.ts +2 -0
- package/src/abstract-document-xml/index.ts +3 -0
- package/src/abstract-document-xml/parse-xml/index.ts +2 -0
- package/src/abstract-document-xml/parse-xml/parse-xml.ts +95 -0
- package/src/abstract-document-xml/parse-xml/validation.ts +280 -0
- package/src/abstract-document-xml/xsd-template/custom-elements.ts +56 -0
- package/src/abstract-document-xml/xsd-template/elements.ts +201 -0
- package/src/abstract-document-xml/xsd-template/index.ts +1 -0
- package/src/abstract-document-xml/xsd-template/styles.ts +284 -0
- package/src/abstract-document-xml/xsd-template/xsd-template.ts +51 -0
- package/src/index.ts +2 -1
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Table of content separator.docx +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Empty Paragraph.pdf +0 -91
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group.pdf +0 -123
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Named destination.pdf +0 -1761
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin.pdf +0 -404
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Paragraph numbering.pdf +0 -143
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table.pdf +0 -133
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with default alignment.pdf +0 -113
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { ExportTestDef } from "../export-test-def";
|
|
2
|
+
|
|
3
|
+
export const test: ExportTestDef = {
|
|
4
|
+
name: "Simple document",
|
|
5
|
+
images: {},
|
|
6
|
+
fonts: {},
|
|
7
|
+
abstractDocXML: `<AbstractDoc>
|
|
8
|
+
<StyleNames>
|
|
9
|
+
<StyleName name="footerResultText" type="TextStyle" fontSize="8" color="#353535" bold="true"/>
|
|
10
|
+
<StyleName name="footerResultCell" type="TableCellStyle" padding="4 4 3 0" borders="1 0 0 0" borderColor="#123151" verticalAlignment="Bottom"/>
|
|
11
|
+
</StyleNames>
|
|
12
|
+
<Section>
|
|
13
|
+
<Table columnWidths="375,70,60">
|
|
14
|
+
<style margins="150 0 0 0"/>
|
|
15
|
+
<TableRow>
|
|
16
|
+
<TableCell styleName="footerResultCell"/>
|
|
17
|
+
<TextCell text="Cost €" styleNames="footerResultText, footerResultCell"/>
|
|
18
|
+
<TextCell text="Price €" styleNames="footerResultText, footerResultCell"/>
|
|
19
|
+
</TableRow>
|
|
20
|
+
</Table>
|
|
21
|
+
</Section>
|
|
22
|
+
</AbstractDoc>`,
|
|
23
|
+
expectedPdfJson: {
|
|
24
|
+
children: [
|
|
25
|
+
{
|
|
26
|
+
page: {
|
|
27
|
+
style: {
|
|
28
|
+
headerMargins: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
29
|
+
footerMargins: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
30
|
+
contentMargins: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
31
|
+
orientation: "Portrait",
|
|
32
|
+
paperSize: "A4",
|
|
33
|
+
noTopBottomMargin: false,
|
|
34
|
+
},
|
|
35
|
+
header: [],
|
|
36
|
+
footer: [],
|
|
37
|
+
},
|
|
38
|
+
id: "",
|
|
39
|
+
children: [
|
|
40
|
+
{
|
|
41
|
+
type: "Table",
|
|
42
|
+
columnWidths: [375, 70, 60],
|
|
43
|
+
styleName: "",
|
|
44
|
+
style: {
|
|
45
|
+
margins: { top: 150, right: 0, bottom: 0, left: 0 },
|
|
46
|
+
type: "TableStyle",
|
|
47
|
+
},
|
|
48
|
+
headerRows: [],
|
|
49
|
+
children: [
|
|
50
|
+
{
|
|
51
|
+
children: [
|
|
52
|
+
{
|
|
53
|
+
styleName: "footerResultCell",
|
|
54
|
+
columnSpan: 1,
|
|
55
|
+
rowSpan: 1,
|
|
56
|
+
style: {
|
|
57
|
+
type: "TableCellStyle",
|
|
58
|
+
borders: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
59
|
+
borderColors: { top: "", bottom: "", left: "", right: "" },
|
|
60
|
+
padding: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
61
|
+
},
|
|
62
|
+
dummy: false,
|
|
63
|
+
children: [],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
styleName: "footerResultCell",
|
|
67
|
+
columnSpan: 1,
|
|
68
|
+
rowSpan: 1,
|
|
69
|
+
style: {
|
|
70
|
+
type: "TableCellStyle",
|
|
71
|
+
borders: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
72
|
+
borderColors: { top: "", bottom: "", left: "", right: "" },
|
|
73
|
+
padding: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
74
|
+
},
|
|
75
|
+
dummy: false,
|
|
76
|
+
children: [
|
|
77
|
+
{
|
|
78
|
+
type: "Paragraph",
|
|
79
|
+
styleName: "",
|
|
80
|
+
style: {
|
|
81
|
+
type: "ParagraphStyle",
|
|
82
|
+
margins: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
83
|
+
position: "relative",
|
|
84
|
+
textStyle: { type: "TextStyle" },
|
|
85
|
+
},
|
|
86
|
+
children: [
|
|
87
|
+
{
|
|
88
|
+
type: "TextRun",
|
|
89
|
+
styleName: "footerResultText",
|
|
90
|
+
text: "Cost €",
|
|
91
|
+
style: { type: "TextStyle" },
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
styleName: "footerResultCell",
|
|
99
|
+
columnSpan: 1,
|
|
100
|
+
rowSpan: 1,
|
|
101
|
+
style: {
|
|
102
|
+
type: "TableCellStyle",
|
|
103
|
+
borders: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
104
|
+
borderColors: { top: "", bottom: "", left: "", right: "" },
|
|
105
|
+
padding: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
106
|
+
},
|
|
107
|
+
dummy: false,
|
|
108
|
+
children: [
|
|
109
|
+
{
|
|
110
|
+
type: "Paragraph",
|
|
111
|
+
styleName: "",
|
|
112
|
+
style: {
|
|
113
|
+
type: "ParagraphStyle",
|
|
114
|
+
margins: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
115
|
+
position: "relative",
|
|
116
|
+
textStyle: { type: "TextStyle" },
|
|
117
|
+
},
|
|
118
|
+
children: [
|
|
119
|
+
{
|
|
120
|
+
type: "TextRun",
|
|
121
|
+
styleName: "footerResultText",
|
|
122
|
+
text: "Price €",
|
|
123
|
+
style: { type: "TextStyle" },
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
styles: {
|
|
137
|
+
TextStyle_footerResultText: {
|
|
138
|
+
name: "footerResultText",
|
|
139
|
+
type: "TextStyle",
|
|
140
|
+
fontSize: 8,
|
|
141
|
+
color: "#353535",
|
|
142
|
+
bold: "true",
|
|
143
|
+
style: { type: "TextStyle" },
|
|
144
|
+
},
|
|
145
|
+
TableCellStyle_footerResultCell: {
|
|
146
|
+
name: "footerResultCell",
|
|
147
|
+
type: "TableCellStyle",
|
|
148
|
+
padding: { top: 4, right: 4, bottom: 3, left: 0 },
|
|
149
|
+
borders: { top: 1, right: 0, bottom: 0, left: 0 },
|
|
150
|
+
borderColor: "#123151",
|
|
151
|
+
verticalAlignment: "Bottom",
|
|
152
|
+
},
|
|
153
|
+
ParagraphStyle_H1: {
|
|
154
|
+
type: "ParagraphStyle",
|
|
155
|
+
margins: { top: 8, bottom: 2, left: 0, right: 0 },
|
|
156
|
+
position: "relative",
|
|
157
|
+
textStyle: { type: "TextStyle", bold: true, fontSize: 32 },
|
|
158
|
+
},
|
|
159
|
+
ParagraphStyle_H2: {
|
|
160
|
+
type: "ParagraphStyle",
|
|
161
|
+
margins: { top: 6, bottom: 1.5, left: 0, right: 0 },
|
|
162
|
+
position: "relative",
|
|
163
|
+
textStyle: { type: "TextStyle", bold: true, fontSize: 24 },
|
|
164
|
+
},
|
|
165
|
+
ParagraphStyle_H3: {
|
|
166
|
+
type: "ParagraphStyle",
|
|
167
|
+
margins: { top: 4.5, bottom: 1.125, left: 0, right: 0 },
|
|
168
|
+
position: "relative",
|
|
169
|
+
textStyle: { type: "TextStyle", bold: true, fontSize: 18 },
|
|
170
|
+
},
|
|
171
|
+
ParagraphStyle_H4: {
|
|
172
|
+
type: "ParagraphStyle",
|
|
173
|
+
margins: { top: 3.75, bottom: 0.9375, left: 0, right: 0 },
|
|
174
|
+
position: "relative",
|
|
175
|
+
textStyle: { type: "TextStyle", bold: true, fontSize: 15 },
|
|
176
|
+
},
|
|
177
|
+
ParagraphStyle_H5: {
|
|
178
|
+
type: "ParagraphStyle",
|
|
179
|
+
margins: { top: 3.25, bottom: 0.8125, left: 0, right: 0 },
|
|
180
|
+
position: "relative",
|
|
181
|
+
textStyle: { type: "TextStyle", bold: true, fontSize: 13 },
|
|
182
|
+
},
|
|
183
|
+
ParagraphStyle_H6: {
|
|
184
|
+
type: "ParagraphStyle",
|
|
185
|
+
margins: { top: 2.5, bottom: 0.625, left: 0, right: 0 },
|
|
186
|
+
position: "relative",
|
|
187
|
+
textStyle: { type: "TextStyle", bold: true, fontSize: 10 },
|
|
188
|
+
},
|
|
189
|
+
TextStyle_Emphasis: { type: "TextStyle", italic: true },
|
|
190
|
+
TextStyle_Strong: { type: "TextStyle", bold: true },
|
|
191
|
+
TextStyle_Subscript: { type: "TextStyle", subScript: true, fontSize: 6 },
|
|
192
|
+
TextStyle_Superscript: { type: "TextStyle", superScript: true, fontSize: 6 },
|
|
193
|
+
},
|
|
194
|
+
fonts: {},
|
|
195
|
+
},
|
|
196
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { XmlElement } from "../parse-xml";
|
|
2
|
+
import { ADCreatorFn, propsCreators } from "./creator";
|
|
3
|
+
|
|
4
|
+
export function abstractDocOfXml(
|
|
5
|
+
creators: Record<string, ADCreatorFn>,
|
|
6
|
+
xmlElement: XmlElement,
|
|
7
|
+
onlyChildren: boolean = false
|
|
8
|
+
): unknown {
|
|
9
|
+
const children = [];
|
|
10
|
+
const props: Record<string, unknown> = {};
|
|
11
|
+
for (const childElement of xmlElement.children ?? []) {
|
|
12
|
+
const childName = childElement.tagName;
|
|
13
|
+
if (childName !== undefined) {
|
|
14
|
+
if (childName === "StyleNames") {
|
|
15
|
+
props.styles = abstractDocOfXml(creators, childElement);
|
|
16
|
+
} else if (childName === "StyleName" && childElement.attributes && childElement.attributes.name) {
|
|
17
|
+
const styleName = childElement.attributes.name;
|
|
18
|
+
const style = abstractDocOfXml(creators, childElement);
|
|
19
|
+
props[styleName] = style;
|
|
20
|
+
} else if (childName.startsWith(childName.charAt(0).toUpperCase())) {
|
|
21
|
+
// For uppercase elements we add them to the children key
|
|
22
|
+
children.push(abstractDocOfXml(creators, childElement));
|
|
23
|
+
} else {
|
|
24
|
+
// For lowercase elements we add them as keys using their name
|
|
25
|
+
// Some special keys should directly have an array of children as value instead of an object with children key
|
|
26
|
+
const childrenOnly = childName === "header" || childName === "footer" || childName === "headerRows";
|
|
27
|
+
props[childName] = abstractDocOfXml(creators, childElement, childrenOnly);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (onlyChildren) {
|
|
32
|
+
return children;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Create the abstract doc object to return
|
|
36
|
+
const allProps = { ...xmlElement.attributes, ...props };
|
|
37
|
+
const creator = xmlElement.tagName && creators[xmlElement.tagName] ? creators[xmlElement.tagName] : () => allProps;
|
|
38
|
+
if (creator === undefined) {
|
|
39
|
+
throw new Error(`Could not find creator for element with name ${xmlElement.tagName}`);
|
|
40
|
+
}
|
|
41
|
+
//
|
|
42
|
+
const theObj = creator(allProps, children) as { [k: string]: unknown };
|
|
43
|
+
|
|
44
|
+
for (const propName of Object.keys(allProps)) {
|
|
45
|
+
const propsCreator = allProps[propName] && propsCreators[propName] ? propsCreators[propName] : undefined;
|
|
46
|
+
if (propsCreator) {
|
|
47
|
+
theObj[propsCreator.name] = propsCreator(allProps, children);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Elements styling needs to have style: {type= "StyleName" }. Occures when having a <style></style> element.
|
|
52
|
+
if (theObj.type && (theObj.type as string) === "Table") {
|
|
53
|
+
theObj.style = { ...(theObj.style as Object), type: "TableStyle" };
|
|
54
|
+
}
|
|
55
|
+
if (theObj.type && (theObj.type as string).startsWith("Text")) {
|
|
56
|
+
theObj.style = { ...(theObj.style as Object), type: "TextStyle" };
|
|
57
|
+
}
|
|
58
|
+
if (theObj.type && (theObj.type as string) === "Paragraph") {
|
|
59
|
+
theObj.style = {
|
|
60
|
+
...(theObj.style as Object),
|
|
61
|
+
type: "ParagraphStyle",
|
|
62
|
+
textStyle: { type: "TextStyle" },
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (theObj.columnSpan) {
|
|
66
|
+
theObj.style = { ...(theObj.style as Object), type: "TableCellStyle" };
|
|
67
|
+
}
|
|
68
|
+
// let theObj["columnWidths"] = propsCreator(allProps, children);
|
|
69
|
+
if (children.length > 0) {
|
|
70
|
+
(theObj as { children: Array<unknown> }).children = children;
|
|
71
|
+
}
|
|
72
|
+
return theObj;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function extractImageFontsStyleNames(
|
|
76
|
+
xmlElement: ReadonlyArray<XmlElement>
|
|
77
|
+
): readonly [images: ReadonlyArray<string>, fonts: ReadonlyArray<string>, styleNames: Record<string, string>] {
|
|
78
|
+
const images = Array<string>();
|
|
79
|
+
const fonts = Array<string>();
|
|
80
|
+
let styleNames: Record<string, string> = {};
|
|
81
|
+
xmlElement.forEach((item) => {
|
|
82
|
+
if (item.tagName === "Image" && item.attributes?.src) {
|
|
83
|
+
images.push(item.attributes.src as string);
|
|
84
|
+
} else if (item.attributes?.fontFamily) {
|
|
85
|
+
fonts.push(item.attributes.fontFamily as string);
|
|
86
|
+
} else if (item.tagName === "StyleName" && item.attributes.name && item.attributes.type) {
|
|
87
|
+
styleNames[item.attributes.name as string] = item.attributes.type;
|
|
88
|
+
} else {
|
|
89
|
+
const [newImages, newFonts, newStyleNames] = extractImageFontsStyleNames(item.children);
|
|
90
|
+
images.push(...newImages);
|
|
91
|
+
fonts.push(...newFonts);
|
|
92
|
+
styleNames = { ...styleNames, ...newStyleNames };
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return [images, fonts, styleNames];
|
|
96
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AbstractDoc,
|
|
3
|
+
Atom,
|
|
4
|
+
DefaultStyles,
|
|
5
|
+
Font,
|
|
6
|
+
Group,
|
|
7
|
+
Image,
|
|
8
|
+
Markdown,
|
|
9
|
+
PageBreak,
|
|
10
|
+
Paragraph,
|
|
11
|
+
Section,
|
|
12
|
+
SectionElement,
|
|
13
|
+
Table,
|
|
14
|
+
TableCell,
|
|
15
|
+
TableRow,
|
|
16
|
+
TextField,
|
|
17
|
+
TextRun,
|
|
18
|
+
TocSeparator,
|
|
19
|
+
Types,
|
|
20
|
+
ImageResource as ADImageResource,
|
|
21
|
+
TextStyle,
|
|
22
|
+
} from "../../abstract-document/index";
|
|
23
|
+
import {
|
|
24
|
+
TextRowProps,
|
|
25
|
+
TextRow,
|
|
26
|
+
TextCellProps,
|
|
27
|
+
TextCell,
|
|
28
|
+
TextParagraphProps,
|
|
29
|
+
TextParagraph,
|
|
30
|
+
ImageCellProps,
|
|
31
|
+
ImageCell,
|
|
32
|
+
} from "./custom-elements";
|
|
33
|
+
|
|
34
|
+
export type ADCreatorFn = (props?: Record<string, unknown>, children?: ReadonlyArray<unknown>) => unknown;
|
|
35
|
+
|
|
36
|
+
export type ImageResource = ADImageResource.ImageResource & { readonly width?: number; readonly height?: number };
|
|
37
|
+
|
|
38
|
+
export type TextRunProps = {
|
|
39
|
+
readonly text: string;
|
|
40
|
+
readonly styleName?: string;
|
|
41
|
+
readonly style?: TextStyle.TextStyle;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const creators: (
|
|
45
|
+
images: Record<string, ImageResource>,
|
|
46
|
+
fonts: Types.Indexer<Font.Font>,
|
|
47
|
+
styleNames: Record<string, string>
|
|
48
|
+
) => Record<string, ADCreatorFn> = (images, fonts, styleNames) => {
|
|
49
|
+
return {
|
|
50
|
+
AbstractDoc: (props, children: ReadonlyArray<Section.Section>) => {
|
|
51
|
+
if (props) {
|
|
52
|
+
props.fonts = fonts ?? undefined;
|
|
53
|
+
}
|
|
54
|
+
return AbstractDoc.create(props, children);
|
|
55
|
+
},
|
|
56
|
+
Paragraph: (props, children: ReadonlyArray<Atom.Atom>) => Paragraph.create(props, children),
|
|
57
|
+
Section: (props, children: ReadonlyArray<SectionElement.SectionElement>) => Section.create(props, children),
|
|
58
|
+
TextRun: (props) => TextRun.create(props as unknown as TextRun.TextRunProps),
|
|
59
|
+
TextRow: (props: TextRowProps) => TextRow(props, styleNames),
|
|
60
|
+
TextCell: (props: TextCellProps) => TextCell(props, styleNames),
|
|
61
|
+
TextParagraph: (props: TextParagraphProps) => TextParagraph(props, styleNames),
|
|
62
|
+
ImageCell: (props: ImageCellProps) => ImageCell(props, styleNames),
|
|
63
|
+
Table: (props, children: ReadonlyArray<TableRow.TableRow>) =>
|
|
64
|
+
Table.create(props as unknown as Table.TableProps, children),
|
|
65
|
+
TableRow: (props, children: ReadonlyArray<TableCell.TableCell>) => TableRow.create(props, children),
|
|
66
|
+
TableCell: (props, children: ReadonlyArray<SectionElement.SectionElement>) => TableCell.create(props, children),
|
|
67
|
+
TextField: (props) => TextField.create(props as unknown as TextField.TextFieldProps),
|
|
68
|
+
Image: (props: Record<string, unknown>) => {
|
|
69
|
+
const image = images[(props.src as string) ?? ""];
|
|
70
|
+
if (image) {
|
|
71
|
+
if (image.width && image.height) {
|
|
72
|
+
props.width = image.width;
|
|
73
|
+
props.height = image.height;
|
|
74
|
+
} else {
|
|
75
|
+
const scaleX = (props.width as number) / image.abstractImage.size.width;
|
|
76
|
+
const scaleY = (props.height as number) / image.abstractImage.size.height;
|
|
77
|
+
if (scaleX < scaleY) {
|
|
78
|
+
props.height = (props.height as number) * (scaleX / scaleY);
|
|
79
|
+
} else {
|
|
80
|
+
props.width = (props.width as number) * (scaleY / scaleX);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
props.imageResource = images[props.src as string];
|
|
85
|
+
}
|
|
86
|
+
return Image.create(props as unknown as Image.ImageProps);
|
|
87
|
+
},
|
|
88
|
+
Group: (props, children) => Group.create(props, children as ReadonlyArray<Group.Group>),
|
|
89
|
+
PageBreak: () => PageBreak.create(),
|
|
90
|
+
Markdown: (props) => Markdown.create(props as unknown as Markdown.MarkdownProps),
|
|
91
|
+
TocSeparator: (props) => TocSeparator.create(props as TocSeparator.TocSeparatorProps),
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const propsCreators: Record<string, ADCreatorFn> = {
|
|
96
|
+
styles: (props: {
|
|
97
|
+
readonly styles: Record<string, Record<string, string | number> & { readonly type: string }>;
|
|
98
|
+
}): unknown => {
|
|
99
|
+
const fixedStyles: Record<string, Record<string, string | number>> = {};
|
|
100
|
+
if (props.styles) {
|
|
101
|
+
Object.keys(props.styles).forEach((key: string) => {
|
|
102
|
+
const styleObj = props.styles[key];
|
|
103
|
+
fixedStyles[((styleObj ? styleObj.type : "") + "_" + key) as string] = { ...props.styles[key] };
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return { ...fixedStyles, ...DefaultStyles.createStandardStyles() };
|
|
108
|
+
},
|
|
109
|
+
columnWidths: (props: { readonly columnWidths: string; readonly columnMultiplier: string }): unknown => {
|
|
110
|
+
const columnWidths = props.columnWidths
|
|
111
|
+
.toString()
|
|
112
|
+
.split(",")
|
|
113
|
+
.map((item: string) => {
|
|
114
|
+
const number = Number(item);
|
|
115
|
+
return number === 0 || Number.isNaN(number) ? Infinity : number;
|
|
116
|
+
});
|
|
117
|
+
if (props.columnMultiplier) {
|
|
118
|
+
return columnWidths.map((l) => l * Number(props.columnMultiplier));
|
|
119
|
+
}
|
|
120
|
+
return columnWidths;
|
|
121
|
+
},
|
|
122
|
+
borders: (props: { readonly borders: string }): unknown => {
|
|
123
|
+
const borders: { [k: string]: number } = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
124
|
+
const propBorders = props.borders.toString().split(" ");
|
|
125
|
+
if (!propBorders) {
|
|
126
|
+
return borders;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (propBorders.length === 1) {
|
|
130
|
+
borders.top = Number(propBorders[0]);
|
|
131
|
+
borders.right = Number(propBorders[0]);
|
|
132
|
+
borders.bottom = Number(propBorders[0]);
|
|
133
|
+
borders.left = Number(propBorders[0]);
|
|
134
|
+
return borders;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
propBorders.forEach((item: string, index) => {
|
|
138
|
+
switch (index) {
|
|
139
|
+
case 1:
|
|
140
|
+
borders.top = Number(propBorders[0]);
|
|
141
|
+
borders.right = Number(item);
|
|
142
|
+
borders.bottom = Number(propBorders[0]);
|
|
143
|
+
borders.left = Number(item);
|
|
144
|
+
break;
|
|
145
|
+
case 2:
|
|
146
|
+
borders.top = Number(propBorders[0]);
|
|
147
|
+
borders.right = Number(propBorders[1]);
|
|
148
|
+
borders.bottom = Number(item);
|
|
149
|
+
borders.left = Number(propBorders[1]);
|
|
150
|
+
break;
|
|
151
|
+
case 3:
|
|
152
|
+
borders.top = Number(propBorders[0]);
|
|
153
|
+
borders.right = Number(propBorders[1]);
|
|
154
|
+
borders.bottom = Number(propBorders[2]);
|
|
155
|
+
borders.left = Number(item);
|
|
156
|
+
break;
|
|
157
|
+
default:
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
return borders;
|
|
162
|
+
},
|
|
163
|
+
padding: (props: { readonly padding: string }): unknown => {
|
|
164
|
+
const padding: { [k: string]: number } = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
165
|
+
|
|
166
|
+
const paddings = props.padding.toString().split(" ");
|
|
167
|
+
if (!paddings) {
|
|
168
|
+
return padding;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (paddings.length === 1) {
|
|
172
|
+
padding.top = Number(paddings[0]);
|
|
173
|
+
padding.right = Number(paddings[0]);
|
|
174
|
+
padding.bottom = Number(paddings[0]);
|
|
175
|
+
padding.left = Number(paddings[0]);
|
|
176
|
+
return padding;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
paddings.forEach((item: string, index) => {
|
|
180
|
+
switch (index) {
|
|
181
|
+
case 1:
|
|
182
|
+
padding.top = Number(paddings[0]);
|
|
183
|
+
padding.right = Number(item);
|
|
184
|
+
padding.bottom = Number(paddings[0]);
|
|
185
|
+
padding.left = Number(item);
|
|
186
|
+
break;
|
|
187
|
+
case 2:
|
|
188
|
+
padding.top = Number(paddings[0]);
|
|
189
|
+
padding.right = Number(paddings[1]);
|
|
190
|
+
padding.bottom = Number(item);
|
|
191
|
+
padding.left = Number(paddings[1]);
|
|
192
|
+
break;
|
|
193
|
+
case 3:
|
|
194
|
+
padding.top = Number(paddings[0]);
|
|
195
|
+
padding.right = Number(paddings[1]);
|
|
196
|
+
padding.bottom = Number(paddings[2]);
|
|
197
|
+
padding.left = Number(item);
|
|
198
|
+
break;
|
|
199
|
+
default:
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
return padding;
|
|
204
|
+
},
|
|
205
|
+
margins: (props: { readonly margins: string }): unknown => {
|
|
206
|
+
const margins: { [k: string]: number } = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
207
|
+
const propMargins = props.margins.toString().split(" ");
|
|
208
|
+
if (!propMargins) {
|
|
209
|
+
return margins;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (propMargins.length === 1) {
|
|
213
|
+
margins.top = Number(propMargins[0]);
|
|
214
|
+
margins.right = Number(propMargins[0]);
|
|
215
|
+
margins.bottom = Number(propMargins[0]);
|
|
216
|
+
margins.left = Number(propMargins[0]);
|
|
217
|
+
return margins;
|
|
218
|
+
}
|
|
219
|
+
propMargins.forEach((item: string, index) => {
|
|
220
|
+
switch (index) {
|
|
221
|
+
case 1:
|
|
222
|
+
margins.top = Number(propMargins[0]);
|
|
223
|
+
margins.right = Number(item);
|
|
224
|
+
margins.bottom = Number(propMargins[0]);
|
|
225
|
+
margins.left = Number(item);
|
|
226
|
+
break;
|
|
227
|
+
case 2:
|
|
228
|
+
margins.top = Number(propMargins[0]);
|
|
229
|
+
margins.right = Number(propMargins[1]);
|
|
230
|
+
margins.bottom = Number(item);
|
|
231
|
+
margins.left = Number(propMargins[1]);
|
|
232
|
+
break;
|
|
233
|
+
case 3:
|
|
234
|
+
margins.top = Number(propMargins[0]);
|
|
235
|
+
margins.right = Number(propMargins[1]);
|
|
236
|
+
margins.bottom = Number(propMargins[2]);
|
|
237
|
+
margins.left = Number(item);
|
|
238
|
+
break;
|
|
239
|
+
default:
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
return margins;
|
|
244
|
+
},
|
|
245
|
+
borderColors: (props: { readonly borderColors: string }): unknown => {
|
|
246
|
+
const borderColors: { [k: string]: string } = { top: "", right: "", bottom: "", left: "" };
|
|
247
|
+
props.borderColors.split(" ").forEach((item: string, index) => {
|
|
248
|
+
switch (index) {
|
|
249
|
+
case 0:
|
|
250
|
+
borderColors.top = item;
|
|
251
|
+
break;
|
|
252
|
+
case 1:
|
|
253
|
+
borderColors.right = item;
|
|
254
|
+
break;
|
|
255
|
+
case 2:
|
|
256
|
+
borderColors.bottom = item;
|
|
257
|
+
break;
|
|
258
|
+
case 3:
|
|
259
|
+
borderColors.left = item;
|
|
260
|
+
break;
|
|
261
|
+
default:
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return borderColors;
|
|
266
|
+
},
|
|
267
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TextStyle,
|
|
3
|
+
ParagraphStyle,
|
|
4
|
+
TableCellStyle,
|
|
5
|
+
ImageResource,
|
|
6
|
+
TextRun,
|
|
7
|
+
Paragraph,
|
|
8
|
+
TableCell,
|
|
9
|
+
TableRow,
|
|
10
|
+
Image,
|
|
11
|
+
} from "../../abstract-document/index";
|
|
12
|
+
|
|
13
|
+
type StyleProps = {
|
|
14
|
+
readonly ParagraphStyle: string;
|
|
15
|
+
readonly TextStyle: string;
|
|
16
|
+
readonly TableCellStyle: string;
|
|
17
|
+
readonly TableStyle: string;
|
|
18
|
+
readonly GroupStyle: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const stylePropsKeys: Record<string, boolean> = {
|
|
22
|
+
ParagraphStyle: true,
|
|
23
|
+
TextStyle: true,
|
|
24
|
+
TableCellStyle: true,
|
|
25
|
+
TableStyle: true,
|
|
26
|
+
GroupStyle: true,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function extractStyleNames(
|
|
30
|
+
styleNames: string | undefined,
|
|
31
|
+
styleNameTypes: Record<string, string>
|
|
32
|
+
): Partial<StyleProps> {
|
|
33
|
+
const names = (styleNames || "").split(",");
|
|
34
|
+
|
|
35
|
+
let styleNameProps = {};
|
|
36
|
+
|
|
37
|
+
for (const name of names) {
|
|
38
|
+
const trimmed = name.trim();
|
|
39
|
+
const type = styleNameTypes[trimmed];
|
|
40
|
+
if (type && stylePropsKeys[type]) {
|
|
41
|
+
styleNameProps = { ...styleNameProps, [type]: trimmed };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return styleNameProps;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type TextParagraphProps = {
|
|
48
|
+
readonly text: string;
|
|
49
|
+
readonly textStyle?: TextStyle.TextStyle;
|
|
50
|
+
readonly paragraphStyle?: ParagraphStyle.ParagraphStyle;
|
|
51
|
+
readonly styleNames?: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export function TextParagraph(props: TextParagraphProps, styleNameTypes: Record<string, string>): Paragraph.Paragraph {
|
|
55
|
+
const { text, textStyle, paragraphStyle } = props;
|
|
56
|
+
const styleNames = extractStyleNames(props.styleNames, styleNameTypes);
|
|
57
|
+
const textRun = TextRun.create({ text, style: textStyle, styleName: styleNames.TextStyle });
|
|
58
|
+
return Paragraph.create({ style: paragraphStyle, styleName: styleNames.ParagraphStyle }, [textRun]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type TextCellProps = TextParagraphProps & {
|
|
62
|
+
readonly columnSpan?: number;
|
|
63
|
+
readonly rowSpan?: number;
|
|
64
|
+
readonly cellStyle?: TableCellStyle.TableCellStyle;
|
|
65
|
+
readonly styleNames?: string;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export function TextCell(props: TextCellProps, styleNameTypes: Record<string, string>): TableCell.TableCell {
|
|
69
|
+
const { text, textStyle, paragraphStyle, cellStyle, columnSpan, rowSpan } = props;
|
|
70
|
+
const styleNames = extractStyleNames(props.styleNames, styleNameTypes);
|
|
71
|
+
const textRun = TextRun.create({ text, style: textStyle, styleName: styleNames.TextStyle });
|
|
72
|
+
const paragraph = Paragraph.create({ style: paragraphStyle, styleName: styleNames.ParagraphStyle }, [textRun]);
|
|
73
|
+
return TableCell.create({ columnSpan, rowSpan, style: cellStyle, styleName: styleNames.TableCellStyle }, [paragraph]);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type TextRowProps = TextCellProps & {};
|
|
77
|
+
|
|
78
|
+
export function TextRow(props: TextRowProps, styleNameTypes: Record<string, string>): TableRow.TableRow {
|
|
79
|
+
const { text, textStyle, paragraphStyle, cellStyle, columnSpan, rowSpan } = props;
|
|
80
|
+
const styleNames = extractStyleNames(props.styleNames, styleNameTypes);
|
|
81
|
+
const textRun = TextRun.create({ text, style: textStyle, styleName: styleNames.TextStyle });
|
|
82
|
+
const paragraph = Paragraph.create({ style: paragraphStyle, styleName: styleNames.ParagraphStyle }, [textRun]);
|
|
83
|
+
const tableCell = TableCell.create({ columnSpan, rowSpan, style: cellStyle, styleName: styleNames.TableCellStyle }, [
|
|
84
|
+
paragraph,
|
|
85
|
+
]);
|
|
86
|
+
return TableRow.create({}, [tableCell]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type ImageCellProps = {
|
|
90
|
+
readonly image: ImageResource.ImageResource | undefined;
|
|
91
|
+
readonly width: number;
|
|
92
|
+
readonly height: number;
|
|
93
|
+
readonly paragraphStyle?: ParagraphStyle.ParagraphStyle;
|
|
94
|
+
readonly cellStyle?: TableCellStyle.TableCellStyle;
|
|
95
|
+
readonly columnSpan?: number;
|
|
96
|
+
readonly rowSpan?: number;
|
|
97
|
+
readonly styleNames?: string;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export function ImageCell(props: ImageCellProps, styleNameTypes: Record<string, string>): TableCell.TableCell {
|
|
101
|
+
const { image, width, height, paragraphStyle, cellStyle, columnSpan, rowSpan } = props;
|
|
102
|
+
const styleNames = extractStyleNames(props.styleNames, styleNameTypes);
|
|
103
|
+
const imageElement = image && Image.create({ imageResource: image, width, height });
|
|
104
|
+
const paragraph =
|
|
105
|
+
imageElement && Paragraph.create({ style: paragraphStyle, styleName: styleNames.ParagraphStyle }, [imageElement]);
|
|
106
|
+
return TableCell.create(
|
|
107
|
+
{ columnSpan, rowSpan, style: cellStyle, styleName: styleNames.TableCellStyle },
|
|
108
|
+
paragraph && [paragraph]
|
|
109
|
+
);
|
|
110
|
+
}
|