abstract-document 20.0.3 → 20.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +3 -3
- package/lib/abstract-document/abstract-doc.d.ts.map +1 -1
- package/lib/abstract-document/abstract-doc.js +2 -2
- package/lib/abstract-document/atoms/atom.d.ts +3 -3
- package/lib/abstract-document/atoms/atom.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.map +1 -1
- package/lib/abstract-document/default-styles.js.map +1 -1
- package/lib/abstract-document/markdown/markdown.d.ts.map +1 -1
- package/lib/abstract-document/markdown/markdown.js +5 -5
- package/lib/abstract-document/markdown/markdown.js.map +1 -1
- package/lib/abstract-document/numberings/numbering-definition.d.ts +2 -2
- 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.js +2 -2
- 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/master-page.js +1 -1
- package/lib/abstract-document/page/master-page.js.map +1 -1
- package/lib/abstract-document/page/section.d.ts +1 -1
- package/lib/abstract-document/page/section.d.ts.map +1 -1
- package/lib/abstract-document/page/section.js +2 -2
- package/lib/abstract-document/page/section.js.map +1 -1
- package/lib/abstract-document/primitives/font.d.ts +1 -1
- package/lib/abstract-document/primitives/font.d.ts.map +1 -1
- package/lib/abstract-document/primitives/font.js +1 -1
- package/lib/abstract-document/primitives/font.js.map +1 -1
- package/lib/abstract-document/primitives/layout-foundation-color.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.d.ts.map +1 -1
- package/lib/abstract-document/primitives/layout-foundation.js +1 -1
- package/lib/abstract-document/primitives/layout-foundation.js.map +1 -1
- package/lib/abstract-document/primitives/point.js +1 -1
- package/lib/abstract-document/resources.d.ts +4 -3
- package/lib/abstract-document/resources.d.ts.map +1 -1
- package/lib/abstract-document/resources.js +4 -4
- package/lib/abstract-document/resources.js.map +1 -1
- package/lib/abstract-document/section-elements/group.d.ts +1 -1
- package/lib/abstract-document/section-elements/group.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/group.js +2 -2
- package/lib/abstract-document/section-elements/group.js.map +1 -1
- package/lib/abstract-document/section-elements/page-break.d.ts +2 -2
- package/lib/abstract-document/section-elements/page-break.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/page-break.js +1 -2
- package/lib/abstract-document/section-elements/page-break.js.map +1 -1
- package/lib/abstract-document/section-elements/paragraph.d.ts +2 -2
- package/lib/abstract-document/section-elements/paragraph.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/paragraph.js +2 -2
- 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/section-element.js.map +1 -1
- package/lib/abstract-document/section-elements/table.d.ts +1 -1
- package/lib/abstract-document/section-elements/table.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/table.js +2 -2
- package/lib/abstract-document/section-elements/table.js.map +1 -1
- package/lib/abstract-document/styles/group-style.js +3 -3
- package/lib/abstract-document/styles/page-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/page-style.js +3 -7
- package/lib/abstract-document/styles/page-style.js.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 +5 -5
- package/lib/abstract-document/styles/paragraph-style.js.map +1 -1
- package/lib/abstract-document/styles/style.d.ts.map +1 -1
- package/lib/abstract-document/styles/style.js.map +1 -1
- package/lib/abstract-document/styles/table-cell-style.d.ts +1 -1
- package/lib/abstract-document/styles/table-cell-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/table-cell-style.js +7 -7
- 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 +2 -2
- package/lib/abstract-document/styles/table-style.js.map +1 -1
- package/lib/abstract-document/styles/text-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/text-style.js +17 -22
- package/lib/abstract-document/styles/text-style.js.map +1 -1
- package/lib/abstract-document/table/table-cell.js +2 -2
- package/lib/abstract-document/table/table-row.d.ts +2 -3
- package/lib/abstract-document/table/table-row.d.ts.map +1 -1
- package/lib/abstract-document/table/table-row.js +2 -3
- package/lib/abstract-document/table/table-row.js.map +1 -1
- package/lib/abstract-document/types.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/document-container.d.ts +5 -5
- package/lib/abstract-document-exporters/docx/document-container.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/document-container.js +14 -13
- package/lib/abstract-document-exporters/docx/document-container.js.map +1 -1
- package/lib/abstract-document-exporters/docx/docx-constants.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/docx-constants.js +1 -4
- package/lib/abstract-document-exporters/docx/docx-constants.js.map +1 -1
- package/lib/abstract-document-exporters/docx/ref-container.d.ts +8 -10
- package/lib/abstract-document-exporters/docx/ref-container.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/ref-container.js +34 -35
- package/lib/abstract-document-exporters/docx/ref-container.js.map +1 -1
- package/lib/abstract-document-exporters/docx/string-utils.d.ts +2 -1
- package/lib/abstract-document-exporters/docx/string-utils.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/string-utils.js +6 -6
- package/lib/abstract-document-exporters/docx/string-utils.js.map +1 -1
- package/lib/abstract-document-exporters/docx/xml-writer.d.ts +12 -33
- package/lib/abstract-document-exporters/docx/xml-writer.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/xml-writer.js +243 -248
- package/lib/abstract-document-exporters/docx/xml-writer.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.d.ts +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.js +5 -17
- 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 -43
- package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.js +14 -14
- package/lib/abstract-document-exporters/pdf/font.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/header-footer.d.ts +8 -0
- package/lib/abstract-document-exporters/pdf/header-footer.d.ts.map +1 -0
- package/lib/abstract-document-exporters/pdf/header-footer.js +31 -0
- package/lib/abstract-document-exporters/pdf/header-footer.js.map +1 -0
- package/lib/abstract-document-exporters/pdf/measure.d.ts +4 -4
- package/lib/abstract-document-exporters/pdf/measure.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.js +31 -32
- package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/page.d.ts +15 -0
- package/lib/abstract-document-exporters/pdf/page.d.ts.map +1 -0
- package/lib/abstract-document-exporters/pdf/page.js +2 -0
- package/lib/abstract-document-exporters/pdf/page.js.map +1 -0
- package/lib/abstract-document-exporters/pdf/paginate.d.ts +2 -20
- package/lib/abstract-document-exporters/pdf/paginate.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.js +8 -44
- 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 +10 -36
- package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.js +25 -35
- package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.d.ts +4 -3
- package/lib/abstract-document-exporters/pdf/render.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.js +60 -49
- package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/std-fonts.js +2 -2
- package/lib/abstract-document-exporters/pdf/std-fonts.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/textRunRow.d.ts +3 -3
- package/lib/abstract-document-exporters/pdf/textRunRow.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/textRunRow.js +26 -20
- 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/pdf/update-refs.js +3 -2
- package/lib/abstract-document-exporters/pdf/update-refs.js.map +1 -1
- 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 +2 -3
- package/lib/abstract-document-jsx/index.d.ts.map +1 -1
- package/lib/abstract-document-jsx/index.js +10 -6
- 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 -7
- 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 +6 -4
- 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 +8 -4
- 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.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js +4 -8
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js.map +1 -1
- package/lib/abstract-document-xml/xsd-template/xsd-template.js +2 -2
- package/lib/abstract-document-xml/xsd-template/xsd-template.js.map +1 -1
- package/package.json +21 -21
- package/src/abstract-document/abstract-doc.ts +6 -6
- package/src/abstract-document/atoms/atom.ts +3 -3
- 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 +1 -1
- package/src/abstract-document/markdown/markdown.ts +7 -7
- package/src/abstract-document/numberings/numbering-definition.ts +2 -2
- package/src/abstract-document/numberings/numbering-format.ts +1 -7
- package/src/abstract-document/numberings/numbering-level-definition.ts +2 -2
- package/src/abstract-document/page/master-page.ts +2 -2
- package/src/abstract-document/page/section.ts +3 -3
- package/src/abstract-document/primitives/font.ts +1 -12
- package/src/abstract-document/primitives/layout-foundation-color.ts +5 -8
- package/src/abstract-document/primitives/layout-foundation.ts +2 -5
- package/src/abstract-document/primitives/point.ts +1 -1
- package/src/abstract-document/resources.ts +9 -14
- package/src/abstract-document/section-elements/group.ts +3 -3
- package/src/abstract-document/section-elements/page-break.ts +2 -3
- 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 +3 -3
- package/src/abstract-document/styles/group-style.ts +3 -3
- package/src/abstract-document/styles/page-style.ts +3 -7
- package/src/abstract-document/styles/paragraph-style.ts +6 -14
- package/src/abstract-document/styles/style.ts +1 -5
- package/src/abstract-document/styles/table-cell-style.ts +8 -18
- package/src/abstract-document/styles/table-style.ts +3 -8
- package/src/abstract-document/styles/text-style.ts +31 -36
- package/src/abstract-document/table/table-cell.ts +2 -2
- package/src/abstract-document/table/table-row.ts +3 -4
- package/src/abstract-document/types.ts +0 -1
- package/src/abstract-document-exporters/docx/document-container.ts +24 -13
- package/src/abstract-document-exporters/docx/docx-constants.ts +2 -6
- package/src/abstract-document-exporters/docx/ref-container.ts +48 -41
- package/src/abstract-document-exporters/docx/string-utils.ts +6 -10
- package/src/abstract-document-exporters/docx/xml-writer.ts +261 -265
- package/src/abstract-document-exporters/docx2/render-image.ts +16 -50
- package/src/abstract-document-exporters/docx2/render.ts +68 -121
- package/src/abstract-document-exporters/pdf/font.ts +27 -32
- package/src/abstract-document-exporters/pdf/header-footer.ts +43 -0
- package/src/abstract-document-exporters/pdf/measure.ts +52 -103
- package/src/abstract-document-exporters/pdf/page.ts +16 -0
- package/src/abstract-document-exporters/pdf/paginate.ts +29 -120
- package/src/abstract-document-exporters/pdf/pre-process.ts +13 -48
- package/src/abstract-document-exporters/pdf/render-image.ts +30 -47
- package/src/abstract-document-exporters/pdf/render.ts +84 -128
- package/src/abstract-document-exporters/pdf/std-fonts.ts +2 -2
- package/src/abstract-document-exporters/pdf/textRunRow.ts +100 -77
- package/src/abstract-document-exporters/pdf/update-refs.ts +10 -33
- package/src/abstract-document-exporters/shared/get_resources.ts +4 -4
- package/src/abstract-document-jsx/index.ts +38 -26
- package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +23 -35
- package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +17 -29
- package/src/abstract-document-xml/abstract-doc-of-xml/custom-elements.tsx +8 -30
- package/src/abstract-document-xml/xsd-template/styles.ts +1 -1
- package/src/abstract-document-xml/xsd-template/xsd-template.ts +2 -2
- 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
|
@@ -8,17 +8,25 @@ type LongWordSplit = {
|
|
|
8
8
|
readonly width: number;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export function rowsSplit(
|
|
11
|
+
export function rowsSplit(
|
|
12
|
+
rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>,
|
|
13
|
+
availableWidth: number,
|
|
14
|
+
desiredSizes: Map<object, AD.Size.Size>,
|
|
15
|
+
alignment: PdfKitAlignment,
|
|
16
|
+
pdf: PDFKit.PDFDocument,
|
|
17
|
+
resources: AD.Resources.Resources,
|
|
18
|
+
defaultStyle: AD.TextStyle.TextStyle
|
|
19
|
+
): ReadonlyArray<ReadonlyArray<AD.Atom.Atom>> {
|
|
12
20
|
const newRows: Array<ReadonlyArray<AD.Atom.Atom>> = [];
|
|
13
21
|
|
|
14
|
-
for(const row of rows) {
|
|
15
|
-
if(row.length < 1) {
|
|
22
|
+
for (const row of rows) {
|
|
23
|
+
if (row.length < 1) {
|
|
16
24
|
newRows.push(row);
|
|
17
25
|
continue;
|
|
18
26
|
}
|
|
19
|
-
|
|
27
|
+
|
|
20
28
|
const width = row.reduce((a, b) => a + getDesiredSize(b, desiredSizes).width, 0);
|
|
21
|
-
if(width < availableWidth) {
|
|
29
|
+
if (width < availableWidth) {
|
|
22
30
|
newRows.push(row);
|
|
23
31
|
continue;
|
|
24
32
|
}
|
|
@@ -28,45 +36,41 @@ export function rowsSplit(rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>, avai
|
|
|
28
36
|
let currentWidth = 0;
|
|
29
37
|
let lastWasSpace = false;
|
|
30
38
|
|
|
31
|
-
for(let i = 0; i < row.length; i++) {
|
|
39
|
+
for (let i = 0; i < row.length; i++) {
|
|
32
40
|
const atom = row[i];
|
|
33
41
|
const size = getDesiredSize(atom, desiredSizes);
|
|
34
42
|
const width = size.width;
|
|
35
43
|
const height = size.height;
|
|
36
44
|
|
|
37
|
-
if(atom.type !== "TextRun") {
|
|
45
|
+
if (atom.type !== "TextRun") {
|
|
38
46
|
currentRow.push(atom);
|
|
39
47
|
currentWidth += width;
|
|
40
48
|
continue;
|
|
41
49
|
}
|
|
42
50
|
|
|
43
|
-
|
|
44
|
-
const isSpace = atom.text.replaceAll(/[\p{Zs}]/ug, "").length === 0;
|
|
51
|
+
const isSpace = atom.text.replaceAll(/[\p{Zs}]/gu, "").length === 0;
|
|
45
52
|
const lastSpace = lastWasSpace;
|
|
46
53
|
lastWasSpace = isSpace;
|
|
47
54
|
|
|
48
55
|
//if the next atom is a space, we need to split this row early if it doesnt fit
|
|
49
56
|
const nextAtom = row[i + 1];
|
|
50
|
-
const nextWidthIfSpace =
|
|
51
|
-
!isSpace
|
|
52
|
-
&& nextAtom
|
|
53
|
-
&& nextAtom.type === "TextRun"
|
|
54
|
-
&& nextAtom.text.replaceAll(/[\p{Zs}]/ug, "").length === 0
|
|
57
|
+
const nextWidthIfSpace =
|
|
58
|
+
!isSpace && nextAtom?.type === "TextRun" && nextAtom.text.replaceAll(/[\p{Zs}]/gu, "").length === 0
|
|
55
59
|
? getDesiredSize(nextAtom, desiredSizes).width
|
|
56
60
|
: 0;
|
|
57
61
|
|
|
58
|
-
if(isSpace && currentWidth === 0 && i !== 0 && (alignment === "left" || alignment === "justify")) {
|
|
62
|
+
if (isSpace && currentWidth === 0 && i !== 0 && (alignment === "left" || alignment === "justify")) {
|
|
59
63
|
continue;
|
|
60
64
|
}
|
|
61
|
-
|
|
62
|
-
if(
|
|
65
|
+
|
|
66
|
+
if (currentWidth + width + nextWidthIfSpace < availableWidth) {
|
|
63
67
|
currentRow.push(atom);
|
|
64
68
|
currentWidth += width;
|
|
65
69
|
continue;
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
//was it a space??
|
|
69
|
-
if(isSpace) {
|
|
73
|
+
if (isSpace) {
|
|
70
74
|
newRows.push(currentRow);
|
|
71
75
|
currentRow = [];
|
|
72
76
|
currentWidth = 0;
|
|
@@ -76,10 +80,10 @@ export function rowsSplit(rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>, avai
|
|
|
76
80
|
//it is now longer than the remaning size
|
|
77
81
|
const remSize = availableWidth - (currentWidth + nextWidthIfSpace);
|
|
78
82
|
const splittedWord = splitWord(atom, remSize, availableWidth, pdf, resources, defaultStyle);
|
|
79
|
-
if(splittedWord.length > 0) {
|
|
83
|
+
if (splittedWord.length > 0) {
|
|
80
84
|
const heightPerRow = height / splittedWord.length;
|
|
81
85
|
const [first, ...rest] = splittedWord;
|
|
82
|
-
if(!first && !rest) {
|
|
86
|
+
if (!first && !rest) {
|
|
83
87
|
continue;
|
|
84
88
|
}
|
|
85
89
|
//add the first to the current row
|
|
@@ -88,7 +92,7 @@ export function rowsSplit(rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>, avai
|
|
|
88
92
|
currentRow.push(newFirstRowAtom);
|
|
89
93
|
|
|
90
94
|
//then add new rows
|
|
91
|
-
for(const part of rest ?? []) {
|
|
95
|
+
for (const part of rest ?? []) {
|
|
92
96
|
newRows.push(currentRow);
|
|
93
97
|
const newAtom = { ...atom, text: part.text };
|
|
94
98
|
desiredSizes.set(newAtom, { width: part.width, height: heightPerRow });
|
|
@@ -98,11 +102,11 @@ export function rowsSplit(rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>, avai
|
|
|
98
102
|
continue;
|
|
99
103
|
}
|
|
100
104
|
|
|
101
|
-
newRows.push(
|
|
105
|
+
newRows.push(lastSpace && (alignment === "right" || alignment === "justify") ? currentRow.slice(0, -1) : currentRow);
|
|
102
106
|
currentRow = [atom];
|
|
103
107
|
currentWidth = width;
|
|
104
108
|
}
|
|
105
|
-
newRows.push(
|
|
109
|
+
newRows.push(lastWasSpace && (alignment === "right" || alignment === "justify") ? currentRow.slice(0, -1) : currentRow);
|
|
106
110
|
}
|
|
107
111
|
return newRows;
|
|
108
112
|
}
|
|
@@ -110,27 +114,34 @@ export function rowsSplit(rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>, avai
|
|
|
110
114
|
/*
|
|
111
115
|
the first entry fits inside the current row
|
|
112
116
|
*/
|
|
113
|
-
function splitWord(
|
|
117
|
+
function splitWord(
|
|
118
|
+
word: AD.TextRun.TextRun,
|
|
119
|
+
firstRowRemainingWidth: number,
|
|
120
|
+
rowWidth: number,
|
|
121
|
+
pdf: PDFKit.PDFDocument,
|
|
122
|
+
resources: AD.Resources.Resources,
|
|
123
|
+
defaultStyle: AD.TextStyle.TextStyle
|
|
124
|
+
): ReadonlyArray<LongWordSplit> {
|
|
114
125
|
const strings: Array<LongWordSplit> = [];
|
|
115
126
|
const totalWidth = stringWidth(word, pdf, word.text, resources, defaultStyle);
|
|
116
|
-
if(totalWidth < rowWidth) {
|
|
127
|
+
if (totalWidth < rowWidth) {
|
|
117
128
|
return [];
|
|
118
129
|
}
|
|
119
130
|
|
|
120
131
|
let currentString = "";
|
|
121
132
|
let atFirstRow = true;
|
|
122
|
-
for(const char of word.text) {
|
|
133
|
+
for (const char of word.text) {
|
|
123
134
|
const remWidth = atFirstRow ? firstRowRemainingWidth : rowWidth;
|
|
124
135
|
const newString = currentString + char;
|
|
125
136
|
const newWidth = stringWidth(word, pdf, newString, resources, defaultStyle);
|
|
126
|
-
if(newWidth < remWidth) {
|
|
137
|
+
if (newWidth < remWidth) {
|
|
127
138
|
currentString = newString;
|
|
128
139
|
continue;
|
|
129
140
|
}
|
|
130
141
|
|
|
131
142
|
strings.push({
|
|
132
143
|
text: currentString,
|
|
133
|
-
width: newWidth
|
|
144
|
+
width: newWidth,
|
|
134
145
|
});
|
|
135
146
|
|
|
136
147
|
//reset
|
|
@@ -139,19 +150,26 @@ function splitWord(word: AD.TextRun.TextRun, firstRowRemainingWidth: number, row
|
|
|
139
150
|
}
|
|
140
151
|
|
|
141
152
|
//add any remainder
|
|
142
|
-
if(currentString !== "") {
|
|
153
|
+
if (currentString !== "") {
|
|
143
154
|
const newWidth = stringWidth(word, pdf, currentString, resources, defaultStyle);
|
|
144
155
|
strings.push({
|
|
145
156
|
text: currentString,
|
|
146
|
-
width: newWidth
|
|
157
|
+
width: newWidth,
|
|
147
158
|
});
|
|
148
159
|
}
|
|
149
160
|
|
|
150
161
|
return strings;
|
|
151
162
|
}
|
|
152
163
|
|
|
153
|
-
export function rowsCombineTextRuns(
|
|
154
|
-
|
|
164
|
+
export function rowsCombineTextRuns(
|
|
165
|
+
resources: AD.Resources.Resources,
|
|
166
|
+
pdf: PDFKit.PDFDocument,
|
|
167
|
+
rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>,
|
|
168
|
+
desiredSizes: Map<object, AD.Size.Size>,
|
|
169
|
+
alignment: PdfKitAlignment,
|
|
170
|
+
defaultStyle: AD.TextStyle.TextStyle
|
|
171
|
+
): { newDesiredSizes: Map<object, AD.Size.Size>; combinedRows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>> } {
|
|
172
|
+
if (alignment === "justify") {
|
|
155
173
|
return { combinedRows: rows, newDesiredSizes: desiredSizes };
|
|
156
174
|
}
|
|
157
175
|
|
|
@@ -161,31 +179,34 @@ export function rowsCombineTextRuns(resources: AD.Resources.Resources, pdf: PDFK
|
|
|
161
179
|
let currentStyle: string = "";
|
|
162
180
|
|
|
163
181
|
const newRows: Array<ReadonlyArray<AD.Atom.Atom>> = [];
|
|
164
|
-
for(const row of rows) {
|
|
182
|
+
for (const row of rows) {
|
|
165
183
|
const newRow: Array<AD.Atom.Atom> = [];
|
|
166
184
|
let isFirst = true;
|
|
167
185
|
|
|
168
|
-
for(let i = 0; i < row.length; i++) {
|
|
186
|
+
for (let i = 0; i < row.length; i++) {
|
|
169
187
|
const atom = row[i];
|
|
170
188
|
const isLast = i === row.length - 1;
|
|
171
189
|
const measurement = getDesiredSize(atom, desiredSizes);
|
|
172
190
|
|
|
173
|
-
if(atom.type !== "TextRun") {
|
|
174
|
-
if(current !== undefined) {
|
|
191
|
+
if (atom.type !== "TextRun") {
|
|
192
|
+
if (current !== undefined) {
|
|
175
193
|
const newTextRun = {
|
|
176
194
|
...current,
|
|
177
|
-
text: currentString
|
|
195
|
+
text: currentString,
|
|
178
196
|
};
|
|
179
|
-
if(isFirst && alignment === "left") {
|
|
180
|
-
while(currentString.startsWith(" ")) {
|
|
197
|
+
if (isFirst && alignment === "left") {
|
|
198
|
+
while (currentString.startsWith(" ")) {
|
|
181
199
|
currentString = currentString.slice(1);
|
|
182
200
|
}
|
|
183
201
|
isFirst = false;
|
|
184
|
-
} else if(isFirst) {
|
|
202
|
+
} else if (isFirst) {
|
|
185
203
|
isFirst = false;
|
|
186
204
|
}
|
|
187
205
|
newRow.push(newTextRun);
|
|
188
|
-
desiredSizes.set(newTextRun, {
|
|
206
|
+
desiredSizes.set(newTextRun, {
|
|
207
|
+
width: stringWidth(current, pdf, currentString, resources, defaultStyle),
|
|
208
|
+
height: currentHeight,
|
|
209
|
+
});
|
|
189
210
|
currentString = "";
|
|
190
211
|
currentStyle = "";
|
|
191
212
|
currentHeight = 0;
|
|
@@ -195,35 +216,33 @@ export function rowsCombineTextRuns(resources: AD.Resources.Resources, pdf: PDFK
|
|
|
195
216
|
continue;
|
|
196
217
|
}
|
|
197
218
|
|
|
198
|
-
const style = JSON.stringify(
|
|
199
|
-
defaultStyle,
|
|
200
|
-
|
|
201
|
-
"TextStyle",
|
|
202
|
-
atom.styleName,
|
|
203
|
-
resources,
|
|
204
|
-
atom.nestedStyleNames || []
|
|
205
|
-
));
|
|
219
|
+
const style = JSON.stringify(
|
|
220
|
+
AD.Resources.getNestedStyle(defaultStyle, atom.style, "TextStyle", atom.styleName, resources, atom.nestedStyleNames ?? [])
|
|
221
|
+
);
|
|
206
222
|
|
|
207
|
-
if(current === undefined) {
|
|
223
|
+
if (current === undefined) {
|
|
208
224
|
currentString = atom.text;
|
|
209
225
|
current = atom;
|
|
210
226
|
currentHeight = Math.max(measurement.height, currentHeight);
|
|
211
227
|
currentStyle = style;
|
|
212
|
-
} else if(style !== currentStyle) {
|
|
228
|
+
} else if (style !== currentStyle) {
|
|
213
229
|
const newTextRun = {
|
|
214
230
|
...current,
|
|
215
|
-
text: currentString
|
|
231
|
+
text: currentString,
|
|
216
232
|
};
|
|
217
|
-
if(isFirst && alignment === "left") {
|
|
218
|
-
while(currentString.startsWith(" ")) {
|
|
233
|
+
if (isFirst && alignment === "left") {
|
|
234
|
+
while (currentString.startsWith(" ")) {
|
|
219
235
|
currentString = currentString.slice(1);
|
|
220
236
|
}
|
|
221
237
|
isFirst = false;
|
|
222
|
-
} else if(isFirst) {
|
|
238
|
+
} else if (isFirst) {
|
|
223
239
|
isFirst = false;
|
|
224
240
|
}
|
|
225
241
|
newRow.push(newTextRun);
|
|
226
|
-
desiredSizes.set(newTextRun, {
|
|
242
|
+
desiredSizes.set(newTextRun, {
|
|
243
|
+
width: stringWidth(current, pdf, currentString, resources, defaultStyle),
|
|
244
|
+
height: currentHeight,
|
|
245
|
+
});
|
|
227
246
|
currentString = atom.text;
|
|
228
247
|
currentHeight = Math.max(measurement.height, currentHeight);
|
|
229
248
|
current = atom;
|
|
@@ -233,16 +252,16 @@ export function rowsCombineTextRuns(resources: AD.Resources.Resources, pdf: PDFK
|
|
|
233
252
|
currentHeight = Math.max(measurement.height, currentHeight);
|
|
234
253
|
}
|
|
235
254
|
|
|
236
|
-
if(isLast) {
|
|
237
|
-
if(current) {
|
|
255
|
+
if (isLast) {
|
|
256
|
+
if (current) {
|
|
238
257
|
//does the last contain spaces at the end?
|
|
239
|
-
if(alignment === "right") {
|
|
240
|
-
while(currentString.endsWith(" ")) {
|
|
258
|
+
if (alignment === "right") {
|
|
259
|
+
while (currentString.endsWith(" ")) {
|
|
241
260
|
currentString = currentString.slice(0, -1);
|
|
242
261
|
}
|
|
243
262
|
}
|
|
244
|
-
if(isFirst && alignment === "left") {
|
|
245
|
-
while(currentString.startsWith(" ")) {
|
|
263
|
+
if (isFirst && alignment === "left") {
|
|
264
|
+
while (currentString.startsWith(" ")) {
|
|
246
265
|
currentString = currentString.slice(1);
|
|
247
266
|
}
|
|
248
267
|
isFirst = false;
|
|
@@ -251,9 +270,12 @@ export function rowsCombineTextRuns(resources: AD.Resources.Resources, pdf: PDFK
|
|
|
251
270
|
const newTextRun: AD.Atom.Atom = {
|
|
252
271
|
...current,
|
|
253
272
|
text: currentString,
|
|
254
|
-
}
|
|
273
|
+
};
|
|
255
274
|
newRow.push(newTextRun);
|
|
256
|
-
desiredSizes.set(newTextRun, {
|
|
275
|
+
desiredSizes.set(newTextRun, {
|
|
276
|
+
width: stringWidth(current, pdf, currentString, resources, defaultStyle),
|
|
277
|
+
height: currentHeight,
|
|
278
|
+
});
|
|
257
279
|
}
|
|
258
280
|
}
|
|
259
281
|
}
|
|
@@ -273,25 +295,26 @@ function stringWidth(
|
|
|
273
295
|
resources: AD.Resources.Resources,
|
|
274
296
|
defaultStyle: AD.TextStyle.TextStyle
|
|
275
297
|
): number {
|
|
276
|
-
const style =
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
298
|
+
const style =
|
|
299
|
+
(AD.Resources.getNestedStyle(
|
|
300
|
+
defaultStyle,
|
|
301
|
+
textRun.style,
|
|
302
|
+
"TextStyle",
|
|
303
|
+
textRun.styleName,
|
|
304
|
+
resources,
|
|
305
|
+
textRun.nestedStyleNames ?? []
|
|
306
|
+
) as AD.TextStyle.TextStyle) ?? defaultStyle;
|
|
284
307
|
|
|
285
308
|
const font = getFontNameStyle(style);
|
|
286
309
|
const fontSize = AD.TextStyle.calculateFontSize(style, 10);
|
|
287
310
|
pdf
|
|
288
311
|
.font(font)
|
|
289
312
|
.fontSize(fontSize)
|
|
290
|
-
.fillColor(style.color
|
|
313
|
+
.fillColor(style.color ?? "black");
|
|
291
314
|
|
|
292
315
|
const textOptions = {
|
|
293
|
-
underline: style.underline
|
|
294
|
-
indent: style.indent
|
|
316
|
+
underline: style.underline ?? false,
|
|
317
|
+
indent: style.indent ?? 0,
|
|
295
318
|
lineBreak: false,
|
|
296
319
|
...(style.characterSpacing !== undefined ? { characterSpacing: style.characterSpacing } : {}),
|
|
297
320
|
...(style.lineGap !== undefined ? { lineGap: style.lineGap } : {}),
|
|
@@ -299,10 +322,10 @@ function stringWidth(
|
|
|
299
322
|
return pdf.widthOfString(text, textOptions);
|
|
300
323
|
}
|
|
301
324
|
|
|
302
|
-
function getDesiredSize(element:
|
|
325
|
+
function getDesiredSize(element: object, desiredSizes: Map<object, AD.Size.Size>): AD.Size.Size {
|
|
303
326
|
const size = desiredSizes.get(element);
|
|
304
327
|
if (size) {
|
|
305
328
|
return size;
|
|
306
329
|
}
|
|
307
330
|
throw new Error("Could not find size for element!");
|
|
308
|
-
}
|
|
331
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as AD from "../../abstract-document/index.js";
|
|
2
|
-
import type { Page } from "./
|
|
2
|
+
import type { Page } from "./page.js";
|
|
3
3
|
|
|
4
4
|
export function updatePageRefs(pages: ReadonlyArray<Page>): Array<Page> {
|
|
5
5
|
return pages.map((page) => updateRefsOnPage(page, pages));
|
|
@@ -23,18 +23,14 @@ function updateRefsInElements(
|
|
|
23
23
|
pages: ReadonlyArray<Page>
|
|
24
24
|
): ReadonlyArray<AD.SectionElement.SectionElement> {
|
|
25
25
|
const updatedElements = new Array<AD.SectionElement.SectionElement>();
|
|
26
|
-
for (
|
|
26
|
+
for (const element of elements) {
|
|
27
27
|
const updatedElement = updateRefsInElement(element, page, pages);
|
|
28
28
|
updatedElements.push(updatedElement);
|
|
29
29
|
}
|
|
30
30
|
return updatedElements;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function updateRefsInElement(
|
|
34
|
-
element: AD.SectionElement.SectionElement,
|
|
35
|
-
page: Page,
|
|
36
|
-
pages: ReadonlyArray<Page>
|
|
37
|
-
): AD.SectionElement.SectionElement {
|
|
33
|
+
function updateRefsInElement(element: AD.SectionElement.SectionElement, page: Page, pages: ReadonlyArray<Page>): AD.SectionElement.SectionElement {
|
|
38
34
|
switch (element.type) {
|
|
39
35
|
case "Paragraph":
|
|
40
36
|
return updateRefsInParagraph(element, page, pages);
|
|
@@ -47,11 +43,7 @@ function updateRefsInElement(
|
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
function updateRefsInParagraph(
|
|
51
|
-
paragraph: AD.Paragraph.Paragraph,
|
|
52
|
-
page: Page,
|
|
53
|
-
pages: ReadonlyArray<Page>
|
|
54
|
-
): AD.SectionElement.SectionElement {
|
|
46
|
+
function updateRefsInParagraph(paragraph: AD.Paragraph.Paragraph, page: Page, pages: ReadonlyArray<Page>): AD.SectionElement.SectionElement {
|
|
55
47
|
const updatedChildren = paragraph.children.map((atom) => updateRefInAtom(atom, page, pages));
|
|
56
48
|
return {
|
|
57
49
|
...paragraph,
|
|
@@ -59,11 +51,7 @@ function updateRefsInParagraph(
|
|
|
59
51
|
};
|
|
60
52
|
}
|
|
61
53
|
|
|
62
|
-
function updateRefsInTable(
|
|
63
|
-
table: AD.Table.Table,
|
|
64
|
-
page: Page,
|
|
65
|
-
pages: ReadonlyArray<Page>
|
|
66
|
-
): AD.SectionElement.SectionElement {
|
|
54
|
+
function updateRefsInTable(table: AD.Table.Table, page: Page, pages: ReadonlyArray<Page>): AD.SectionElement.SectionElement {
|
|
67
55
|
const updatedChildren = table.children.map((row) => updateRefsInTableRow(row, page, pages));
|
|
68
56
|
return {
|
|
69
57
|
...table,
|
|
@@ -79,11 +67,7 @@ function updateRefsInTableRow(row: AD.TableRow.TableRow, page: Page, pages: Read
|
|
|
79
67
|
};
|
|
80
68
|
}
|
|
81
69
|
|
|
82
|
-
function updateRefsInTableCell(
|
|
83
|
-
cell: AD.TableCell.TableCell,
|
|
84
|
-
page: Page,
|
|
85
|
-
pages: ReadonlyArray<Page>
|
|
86
|
-
): AD.TableCell.TableCell {
|
|
70
|
+
function updateRefsInTableCell(cell: AD.TableCell.TableCell, page: Page, pages: ReadonlyArray<Page>): AD.TableCell.TableCell {
|
|
87
71
|
const updatedChildren = cell.children.map((element) => updateRefsInElement(element, page, pages));
|
|
88
72
|
return {
|
|
89
73
|
...cell,
|
|
@@ -91,11 +75,7 @@ function updateRefsInTableCell(
|
|
|
91
75
|
};
|
|
92
76
|
}
|
|
93
77
|
|
|
94
|
-
function updateRefsInGroup(
|
|
95
|
-
group: AD.Group.Group,
|
|
96
|
-
page: Page,
|
|
97
|
-
pages: ReadonlyArray<Page>
|
|
98
|
-
): AD.SectionElement.SectionElement {
|
|
78
|
+
function updateRefsInGroup(group: AD.Group.Group, page: Page, pages: ReadonlyArray<Page>): AD.SectionElement.SectionElement {
|
|
99
79
|
const updatedChildren = group.children.map((element) => updateRefsInElement(element, page, pages));
|
|
100
80
|
return {
|
|
101
81
|
...group,
|
|
@@ -111,11 +91,7 @@ function updateRefInAtom(atom: AD.Atom.Atom, page: Page, pages: ReadonlyArray<Pa
|
|
|
111
91
|
}
|
|
112
92
|
}
|
|
113
93
|
|
|
114
|
-
function updateRefInTextField(
|
|
115
|
-
textField: AD.TextField.TextField,
|
|
116
|
-
page: Page,
|
|
117
|
-
pages: ReadonlyArray<Page>
|
|
118
|
-
): AD.TextField.TextField {
|
|
94
|
+
function updateRefInTextField(textField: AD.TextField.TextField, page: Page, pages: ReadonlyArray<Page>): AD.TextField.TextField {
|
|
119
95
|
switch (textField.fieldType) {
|
|
120
96
|
case "PageNumber":
|
|
121
97
|
return {
|
|
@@ -127,7 +103,7 @@ function updateRefInTextField(
|
|
|
127
103
|
...textField,
|
|
128
104
|
text: pages.length.toString(),
|
|
129
105
|
};
|
|
130
|
-
case "PageNumberOf":
|
|
106
|
+
case "PageNumberOf": {
|
|
131
107
|
const targetPage = pages.find((p) => p.namedDestionations.some((dest) => dest === textField.target));
|
|
132
108
|
if (targetPage) {
|
|
133
109
|
return {
|
|
@@ -137,6 +113,7 @@ function updateRefInTextField(
|
|
|
137
113
|
} else {
|
|
138
114
|
return textField;
|
|
139
115
|
}
|
|
116
|
+
}
|
|
140
117
|
default:
|
|
141
118
|
return textField;
|
|
142
119
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { exhaustiveCheck } from "ts-exhaustive-check";
|
|
2
2
|
import type { AbstractDoc } from "../../abstract-document/abstract-doc.js";
|
|
3
|
+
import type { Section } from "../../abstract-document/page/section.js";
|
|
3
4
|
import type { Resources } from "../../abstract-document/resources.js";
|
|
4
5
|
import { mergeResources } from "../../abstract-document/resources.js";
|
|
5
6
|
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
7
|
import type { Paragraph } from "../../abstract-document/section-elements/paragraph.js";
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
8
|
+
import type { SectionElement } from "../../abstract-document/section-elements/section-element.js";
|
|
9
|
+
import type { Table } from "../../abstract-document/section-elements/table.js";
|
|
11
10
|
import type { TableCell } from "../../abstract-document/table/table-cell.js";
|
|
11
|
+
import type { TableRow } from "../../abstract-document/table/table-row.js";
|
|
12
12
|
|
|
13
13
|
export function getResources(doc: AbstractDoc): Resources {
|
|
14
14
|
const resources = doc.children.map((s) => getResourcesSection(s));
|
|
@@ -17,52 +17,64 @@ import {
|
|
|
17
17
|
PageBreak as PageBreak1,
|
|
18
18
|
LineBreak as LineBreak1,
|
|
19
19
|
} from "../abstract-document/index.js";
|
|
20
|
+
import type { SectionElement as SectionElement1, Atom as Atom1 } from "../abstract-document/index.js";
|
|
20
21
|
|
|
21
22
|
export interface ChildrenProp {
|
|
22
23
|
readonly children?: Child;
|
|
23
24
|
}
|
|
24
25
|
export type Child = React.JSX.Element | Children;
|
|
25
|
-
export
|
|
26
|
+
export type Children = ReadonlyArray<Child>;
|
|
26
27
|
|
|
28
|
+
// These factories build a real AD tree, structurally incompatible with React.JSX.Element (the fake
|
|
29
|
+
// type this JSX pragma requires). Every cast below just bridges the two via `unknown`; there's no real type fix.
|
|
27
30
|
export const AbstractDoc = (props?: AbstractDoc1.AbstractDocProps & ChildrenProp): React.JSX.Element =>
|
|
28
|
-
AbstractDoc1.create(props, props && (props.children as
|
|
31
|
+
AbstractDoc1.create(props, props && (props.children as unknown as ReadonlyArray<Section1.Section>)) as unknown as React.JSX.Element;
|
|
29
32
|
export const Section = (props?: Section1.SectionProps & ChildrenProp): React.JSX.Element =>
|
|
30
|
-
Section1.create(props, props && (props.children as
|
|
33
|
+
Section1.create(props, props && (props.children as unknown as ReadonlyArray<SectionElement1.SectionElement>)) as unknown as React.JSX.Element;
|
|
31
34
|
export const Group = (props: Group1.GroupProps & ChildrenProp): React.JSX.Element =>
|
|
32
|
-
Group1.create(props, props && (props.children as
|
|
35
|
+
Group1.create(props, props && (props.children as unknown as ReadonlyArray<SectionElement1.SectionElement>)) as unknown as React.JSX.Element;
|
|
33
36
|
export const Paragraph = (props: Paragraph1.ParagraphProps & ChildrenProp): React.JSX.Element =>
|
|
34
|
-
Paragraph1.create(props, props && (props.children as
|
|
37
|
+
Paragraph1.create(props, props && (props.children as unknown as ReadonlyArray<Atom1.Atom>)) as unknown as React.JSX.Element;
|
|
35
38
|
export const Table = (props: Table1.TableProps & ChildrenProp): React.JSX.Element =>
|
|
36
|
-
Table1.create(props, props && (props.children as
|
|
39
|
+
Table1.create(props, props && (props.children as unknown as ReadonlyArray<TableRow1.TableRow>)) as unknown as React.JSX.Element;
|
|
37
40
|
export const TableRow = (props: TableRow1.TableRowProps & ChildrenProp): React.JSX.Element =>
|
|
38
|
-
TableRow1.create(props, props && (props.children as
|
|
41
|
+
TableRow1.create(props, props && (props.children as unknown as ReadonlyArray<TableCell1.TableCell>)) as unknown as React.JSX.Element;
|
|
39
42
|
export const TableCell = (props: TableCell1.TableCellProps & ChildrenProp): React.JSX.Element =>
|
|
40
|
-
TableCell1.create(props, props && (props.children as
|
|
41
|
-
export const HyperLink = (props: HyperLink1.HyperLinkProps): React.JSX.Element => HyperLink1.create(props) as
|
|
42
|
-
export const LinkTarget = (props: LinkTarget1.LinkTargetProps): React.JSX.Element => LinkTarget1.create(props) as
|
|
43
|
-
export const Image = (props: Image1.ImageProps): React.JSX.Element => Image1.create(props) as
|
|
43
|
+
TableCell1.create(props, props && (props.children as unknown as ReadonlyArray<SectionElement1.SectionElement>)) as unknown as React.JSX.Element;
|
|
44
|
+
export const HyperLink = (props: HyperLink1.HyperLinkProps): React.JSX.Element => HyperLink1.create(props) as unknown as React.JSX.Element;
|
|
45
|
+
export const LinkTarget = (props: LinkTarget1.LinkTargetProps): React.JSX.Element => LinkTarget1.create(props) as unknown as React.JSX.Element;
|
|
46
|
+
export const Image = (props: Image1.ImageProps): React.JSX.Element => Image1.create(props) as unknown as React.JSX.Element;
|
|
44
47
|
export const TocSeparator = (props: TocSeparator1.TocSeparatorProps): React.JSX.Element =>
|
|
45
|
-
TocSeparator1.create(props) as
|
|
46
|
-
export const Markdown = (props: Markdown1.MarkdownProps): React.JSX.Element => Markdown1.create(props) as
|
|
47
|
-
export const TextField = (props: TextField1.TextFieldProps): React.JSX.Element => TextField1.create(props) as
|
|
48
|
-
export const TextRun = (props: TextRun1.TextRunProps): React.JSX.Element => TextRun1.create(props) as
|
|
49
|
-
export const PageBreak = (props: PageBreak1.PageBreakProps): React.JSX.Element => PageBreak1.create(props) as
|
|
50
|
-
export const LineBreak = (props: LineBreak1.LineBreakProps): React.JSX.Element => LineBreak1.create(props) as
|
|
48
|
+
TocSeparator1.create(props) as unknown as React.JSX.Element;
|
|
49
|
+
export const Markdown = (props: Markdown1.MarkdownProps): React.JSX.Element => Markdown1.create(props) as unknown as React.JSX.Element;
|
|
50
|
+
export const TextField = (props: TextField1.TextFieldProps): React.JSX.Element => TextField1.create(props) as unknown as React.JSX.Element;
|
|
51
|
+
export const TextRun = (props: TextRun1.TextRunProps): React.JSX.Element => TextRun1.create(props) as unknown as React.JSX.Element;
|
|
52
|
+
export const PageBreak = (props: PageBreak1.PageBreakProps): React.JSX.Element => PageBreak1.create(props) as unknown as React.JSX.Element;
|
|
53
|
+
export const LineBreak = (props: LineBreak1.LineBreakProps): React.JSX.Element => LineBreak1.create(props) as unknown as React.JSX.Element;
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
// Shape actually accessed when walking the fake element tree at runtime; `type`'s props param and
|
|
56
|
+
// `props` itself are a genuinely arbitrary bag of component props, not a fixed structural type.
|
|
57
|
+
interface FakeElement {
|
|
58
|
+
readonly type: string | ((props: Record<string, unknown>) => unknown);
|
|
59
|
+
readonly props?: { readonly children?: unknown; readonly [key: string]: unknown };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// oxlint-disable-next-line typescript/no-explicit-any -- callers assign the result to whichever AD model type they expect at that call site; narrowing this would break every caller
|
|
63
|
+
export function render(element: unknown): any {
|
|
64
|
+
const el = element as FakeElement;
|
|
65
|
+
if (typeof el.type !== "function") {
|
|
66
|
+
return el;
|
|
55
67
|
}
|
|
56
|
-
const props =
|
|
57
|
-
const children = renderChildren(
|
|
58
|
-
return
|
|
68
|
+
const props = el.props ?? {};
|
|
69
|
+
const children = renderChildren(el);
|
|
70
|
+
return el.type({ ...props, children });
|
|
59
71
|
}
|
|
60
72
|
|
|
61
|
-
function renderChildren(element:
|
|
62
|
-
if (!element.props
|
|
73
|
+
function renderChildren(element: FakeElement): Array<unknown> {
|
|
74
|
+
if (!element.props?.children) {
|
|
63
75
|
return [];
|
|
64
76
|
} else if (Array.isArray(element.props.children)) {
|
|
65
|
-
return element.props.children.flatMap((c:
|
|
77
|
+
return element.props.children.flatMap((c: unknown) => {
|
|
66
78
|
if (!c) {
|
|
67
79
|
return [];
|
|
68
80
|
}
|