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
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type * as AbstractImage from "abstract-image";
|
|
2
2
|
import type { IMediaTransformation } from "docx";
|
|
3
3
|
import { ImageRun } from "docx";
|
|
4
|
-
import type { TextStyle } from "../../abstract-document/styles/text-style.js";
|
|
5
4
|
import type { Image } from "../../abstract-document/atoms/image.js";
|
|
6
|
-
import { fromBase64, rawSvgPrefix } from "../shared/base-64.js";
|
|
7
5
|
import type * as AD from "../../abstract-document/index.js";
|
|
6
|
+
import type { TextStyle } from "../../abstract-document/styles/text-style.js";
|
|
7
|
+
import { fromBase64, rawSvgPrefix } from "../shared/base-64.js";
|
|
8
8
|
|
|
9
9
|
const abstractDocPointsToDocxPxRatio = 1; // Set to 1 for now to minimize impact. Can be adjusted to better match PDF image dimensions
|
|
10
10
|
|
|
@@ -21,7 +21,7 @@ export function renderImage(image: Image, textStyle: TextStyle, resources: AD.Re
|
|
|
21
21
|
const firstComp = aImage.components[0];
|
|
22
22
|
const resource =
|
|
23
23
|
!aImage.size.width && !aImage.size.height && firstComp?.type === "binaryimage" && firstComp.data.type === "url"
|
|
24
|
-
? resources.imageResources?.[firstComp.data.url] ?? image.imageResource
|
|
24
|
+
? (resources.imageResources?.[firstComp.data.url] ?? image.imageResource)
|
|
25
25
|
: image.imageResource;
|
|
26
26
|
|
|
27
27
|
const rect = resourceRect(resource, {
|
|
@@ -87,13 +87,9 @@ function binaryImageToImageRun(
|
|
|
87
87
|
if (format === "png" || format === "jpg" || format === "jpeg") {
|
|
88
88
|
return new ImageRun({
|
|
89
89
|
type: format === "png" ? "png" : "jpg",
|
|
90
|
-
data: Buffer.from(
|
|
91
|
-
component.data.bytes.buffer,
|
|
92
|
-
component.data.bytes.byteOffset,
|
|
93
|
-
component.data.bytes.byteLength
|
|
94
|
-
),
|
|
90
|
+
data: Buffer.from(component.data.bytes.buffer, component.data.bytes.byteOffset, component.data.bytes.byteLength),
|
|
95
91
|
transformation,
|
|
96
|
-
}
|
|
92
|
+
});
|
|
97
93
|
}
|
|
98
94
|
|
|
99
95
|
if (format === "svg") {
|
|
@@ -131,11 +127,11 @@ function binaryImageToImageRun(
|
|
|
131
127
|
const data = fromBase64(match[2]);
|
|
132
128
|
|
|
133
129
|
if (mimeType.includes("png")) {
|
|
134
|
-
return new ImageRun({ data, transformation, type: "png" }
|
|
130
|
+
return new ImageRun({ data, transformation, type: "png" });
|
|
135
131
|
}
|
|
136
132
|
|
|
137
133
|
if (mimeType.includes("jpeg") || mimeType.includes("jpg")) {
|
|
138
|
-
return new ImageRun({ data, transformation, type: "jpg" }
|
|
134
|
+
return new ImageRun({ data, transformation, type: "jpg" });
|
|
139
135
|
}
|
|
140
136
|
|
|
141
137
|
if (mimeType.includes("svg")) {
|
|
@@ -147,11 +143,7 @@ function binaryImageToImageRun(
|
|
|
147
143
|
return undefined;
|
|
148
144
|
}
|
|
149
145
|
|
|
150
|
-
function abstractImageToSvg(
|
|
151
|
-
image: AbstractImage.AbstractImage,
|
|
152
|
-
resources: AD.Resources.Resources,
|
|
153
|
-
textStyle: TextStyle
|
|
154
|
-
): string {
|
|
146
|
+
function abstractImageToSvg(image: AbstractImage.AbstractImage, resources: AD.Resources.Resources, textStyle: TextStyle): string {
|
|
155
147
|
const width = image.size.width || 1;
|
|
156
148
|
const height = image.size.height || 1;
|
|
157
149
|
|
|
@@ -163,12 +155,7 @@ function abstractImageToSvg(
|
|
|
163
155
|
return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">${children}</svg>`;
|
|
164
156
|
}
|
|
165
157
|
|
|
166
|
-
function componentToSvg(
|
|
167
|
-
component: AbstractImage.Component,
|
|
168
|
-
resources: AD.Resources.Resources,
|
|
169
|
-
textStyle: TextStyle,
|
|
170
|
-
circuitBreaker: number
|
|
171
|
-
): string {
|
|
158
|
+
function componentToSvg(component: AbstractImage.Component, resources: AD.Resources.Resources, textStyle: TextStyle, circuitBreaker: number): string {
|
|
172
159
|
if (++circuitBreaker > 20) {
|
|
173
160
|
return "";
|
|
174
161
|
}
|
|
@@ -182,9 +169,7 @@ function componentToSvg(
|
|
|
182
169
|
const scaleY = component.size.height / (component.image.size.height || 1);
|
|
183
170
|
const scale = Math.min(scaleX, scaleY);
|
|
184
171
|
|
|
185
|
-
const children = component.image.components
|
|
186
|
-
.map((child) => componentToSvg(child, resources, textStyle, circuitBreaker))
|
|
187
|
-
.join("");
|
|
172
|
+
const children = component.image.components.map((child) => componentToSvg(child, resources, textStyle, circuitBreaker)).join("");
|
|
188
173
|
|
|
189
174
|
return `<g transform="translate(${component.topLeft.x} ${component.topLeft.y}) scale(${scale})">${children}</g>`;
|
|
190
175
|
}
|
|
@@ -259,9 +244,7 @@ function binaryImageToSvg(
|
|
|
259
244
|
const scaleY = height / (imageResource.abstractImage.size.height || 1);
|
|
260
245
|
const scale = Math.min(scaleX, scaleY);
|
|
261
246
|
|
|
262
|
-
const children = imageResource.abstractImage.components
|
|
263
|
-
.map((child) => componentToSvg(child, resources, textStyle, circuitBreaker))
|
|
264
|
-
.join("");
|
|
247
|
+
const children = imageResource.abstractImage.components.map((child) => componentToSvg(child, resources, textStyle, circuitBreaker)).join("");
|
|
265
248
|
|
|
266
249
|
return `<g transform="translate(${component.topLeft.x} ${component.topLeft.y}) scale(${scale})">${children}</g>`;
|
|
267
250
|
}
|
|
@@ -279,11 +262,7 @@ function binaryImageToSvg(
|
|
|
279
262
|
if (component.data.type === "bytes") {
|
|
280
263
|
if (format === "png" || format === "jpg" || format === "jpeg") {
|
|
281
264
|
const mime = format === "png" ? "image/png" : "image/jpeg";
|
|
282
|
-
const base64 = Buffer.from(
|
|
283
|
-
component.data.bytes.buffer,
|
|
284
|
-
component.data.bytes.byteOffset,
|
|
285
|
-
component.data.bytes.byteLength
|
|
286
|
-
).toString("base64");
|
|
265
|
+
const base64 = Buffer.from(component.data.bytes.buffer, component.data.bytes.byteOffset, component.data.bytes.byteLength).toString("base64");
|
|
287
266
|
|
|
288
267
|
return `<image x="${component.topLeft.x}" y="${component.topLeft.y}" width="${width}" height="${height}" href="data:${mime};base64,${base64}" />`;
|
|
289
268
|
}
|
|
@@ -303,19 +282,10 @@ function textComponentToSvg(component: AbstractImage.Text): string {
|
|
|
303
282
|
? ` transform="rotate(${component.clockwiseRotationDegrees} ${component.position.x} ${component.position.y})"`
|
|
304
283
|
: "";
|
|
305
284
|
|
|
306
|
-
const anchor =
|
|
307
|
-
component.horizontalGrowthDirection === "left"
|
|
308
|
-
? "end"
|
|
309
|
-
: component.horizontalGrowthDirection === "uniform"
|
|
310
|
-
? "middle"
|
|
311
|
-
: "start";
|
|
285
|
+
const anchor = component.horizontalGrowthDirection === "left" ? "end" : component.horizontalGrowthDirection === "uniform" ? "middle" : "start";
|
|
312
286
|
|
|
313
287
|
const dominantBaseline =
|
|
314
|
-
component.verticalGrowthDirection === "up"
|
|
315
|
-
? "text-after-edge"
|
|
316
|
-
: component.verticalGrowthDirection === "uniform"
|
|
317
|
-
? "middle"
|
|
318
|
-
: "text-before-edge";
|
|
288
|
+
component.verticalGrowthDirection === "up" ? "text-after-edge" : component.verticalGrowthDirection === "uniform" ? "middle" : "text-before-edge";
|
|
319
289
|
|
|
320
290
|
return `<text x="${component.position.x}" y="${component.position.y}" font-family="${escapeXml(
|
|
321
291
|
component.fontFamily
|
|
@@ -333,14 +303,10 @@ function fillAttrs(color: AbstractImage.Color): string {
|
|
|
333
303
|
function strokeAttrs(color: AbstractImage.Color, thickness: number, dashStyle: AbstractImage.DashStyle): string {
|
|
334
304
|
const dashArray =
|
|
335
305
|
dashStyle.dashes.length > 0
|
|
336
|
-
? ` stroke-dasharray="${dashStyle.dashes.filter((dash) => dash !== 0).join(" ")}" stroke-dashoffset="${
|
|
337
|
-
dashStyle.offset
|
|
338
|
-
}"`
|
|
306
|
+
? ` stroke-dasharray="${dashStyle.dashes.filter((dash) => dash !== 0).join(" ")}" stroke-dashoffset="${dashStyle.offset}"`
|
|
339
307
|
: "";
|
|
340
308
|
|
|
341
|
-
return `stroke="${colorToCss(color)}" stroke-opacity="${colorToOpacity(
|
|
342
|
-
color
|
|
343
|
-
)}" stroke-width="${thickness}"${dashArray}`;
|
|
309
|
+
return `stroke="${colorToCss(color)}" stroke-opacity="${colorToOpacity(color)}" stroke-width="${thickness}"${dashArray}`;
|
|
344
310
|
}
|
|
345
311
|
|
|
346
312
|
function colorToOpacity(color: AbstractImage.Color): number {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Readable } from "stream";
|
|
2
2
|
import type {
|
|
3
3
|
ISectionOptions,
|
|
4
4
|
ImageRun,
|
|
@@ -31,36 +31,41 @@ import {
|
|
|
31
31
|
VerticalAlign,
|
|
32
32
|
PageNumber,
|
|
33
33
|
} from "docx";
|
|
34
|
+
import * as AD from "../../abstract-document/index.js";
|
|
34
35
|
import { renderImage } from "./render-image.js";
|
|
35
|
-
import { Readable } from "stream";
|
|
36
36
|
|
|
37
37
|
const abstractDocToDocxFontRatio = 2;
|
|
38
38
|
const abstractDocPixelToDocxDXARatio = 20;
|
|
39
39
|
const abstractDocBorderToDocxBorderSizeRatio = 8;
|
|
40
40
|
|
|
41
41
|
export function exportToHTML5Blob(doc: AD.AbstractDoc.AbstractDoc): Promise<Blob> {
|
|
42
|
-
return new Promise((resolve) => {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
43
|
const docx = createDocument(doc);
|
|
44
|
-
Packer.toBlob(docx)
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
Packer.toBlob(docx)
|
|
45
|
+
.then((blob) => {
|
|
46
|
+
resolve(blob);
|
|
47
|
+
})
|
|
48
|
+
.catch(reject);
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
export function exportToStream(blobStream: NodeJS.WritableStream, doc: AD.AbstractDoc.AbstractDoc): void {
|
|
51
53
|
const docx = createDocument(doc);
|
|
52
54
|
|
|
53
|
-
Packer.toBuffer(docx)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
Packer.toBuffer(docx)
|
|
56
|
+
.then((buffer) => {
|
|
57
|
+
const readableStream = new Readable();
|
|
58
|
+
readableStream.push(buffer);
|
|
59
|
+
readableStream.push(null);
|
|
60
|
+
readableStream.pipe(blobStream);
|
|
61
|
+
})
|
|
62
|
+
.catch((err: unknown) => blobStream.emit("error", err instanceof Error ? err : new Error(String(err))));
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
/**
|
|
62
|
-
* On the client side the stream can be a BlobStream from the blob-stream package.
|
|
63
|
-
*
|
|
66
|
+
* On the client side the stream can be a BlobStream from the blob-stream package. On the server-side the stream can be a file stream from the fs
|
|
67
|
+
* package.
|
|
68
|
+
*
|
|
64
69
|
* @param blobStream
|
|
65
70
|
* @param doc
|
|
66
71
|
*/
|
|
@@ -85,28 +90,28 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
85
90
|
|
|
86
91
|
const resources = AD.Resources.mergeResources([parentResources, section]);
|
|
87
92
|
|
|
88
|
-
const headerChildren = section.page.header.reduce((sofar, c) => {
|
|
93
|
+
const headerChildren = section.page.header.reduce<Array<Paragraph | Table>>((sofar, c) => {
|
|
89
94
|
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
90
95
|
return sofar;
|
|
91
|
-
}, []
|
|
96
|
+
}, []);
|
|
92
97
|
|
|
93
98
|
const firstpageHeaderChildren = hasFrontHeader
|
|
94
|
-
? section.page.frontHeader.reduce((sofar, c) => {
|
|
99
|
+
? section.page.frontHeader.reduce<Array<Paragraph | Table>>((sofar, c) => {
|
|
95
100
|
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
96
101
|
return sofar;
|
|
97
|
-
}, []
|
|
102
|
+
}, [])
|
|
98
103
|
: [];
|
|
99
104
|
|
|
100
|
-
const footerChildren = section.page.footer.reduce((sofar, c) => {
|
|
105
|
+
const footerChildren = section.page.footer.reduce<Array<Paragraph | Table>>((sofar, c) => {
|
|
101
106
|
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
102
107
|
return sofar;
|
|
103
|
-
}, []
|
|
108
|
+
}, []);
|
|
104
109
|
|
|
105
110
|
const firstPageFooterChildren = hasFrontFooter
|
|
106
|
-
? section.page.frontFooter.reduce((sofar, c) => {
|
|
111
|
+
? section.page.frontFooter.reduce<Array<Paragraph | Table>>((sofar, c) => {
|
|
107
112
|
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
108
113
|
return sofar;
|
|
109
|
-
}, []
|
|
114
|
+
}, [])
|
|
110
115
|
: [];
|
|
111
116
|
|
|
112
117
|
const contentChildren = [
|
|
@@ -119,10 +124,10 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
119
124
|
}),
|
|
120
125
|
],
|
|
121
126
|
}),
|
|
122
|
-
...section.children.reduce((sofar, c) => {
|
|
127
|
+
...section.children.reduce<Array<Paragraph | Table>>((sofar, c) => {
|
|
123
128
|
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
124
129
|
return sofar;
|
|
125
|
-
}, []
|
|
130
|
+
}, []),
|
|
126
131
|
];
|
|
127
132
|
|
|
128
133
|
return {
|
|
@@ -133,8 +138,7 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
133
138
|
//DOC JS does the orientation after the width and height are set
|
|
134
139
|
width: AD.PageStyle.getPaperWidth(section.page.style.paperSize) * abstractDocPixelToDocxDXARatio,
|
|
135
140
|
height: AD.PageStyle.getPaperHeight(section.page.style.paperSize) * abstractDocPixelToDocxDXARatio,
|
|
136
|
-
orientation:
|
|
137
|
-
section.page.style.orientation === "Landscape" ? PageOrientation.LANDSCAPE : PageOrientation.PORTRAIT,
|
|
141
|
+
orientation: section.page.style.orientation === "Landscape" ? PageOrientation.LANDSCAPE : PageOrientation.PORTRAIT,
|
|
138
142
|
},
|
|
139
143
|
margin: {
|
|
140
144
|
bottom: pageContentMargins.bottom * abstractDocPixelToDocxDXARatio,
|
|
@@ -170,21 +174,18 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
170
174
|
};
|
|
171
175
|
}
|
|
172
176
|
|
|
173
|
-
function renderHyperLink(
|
|
174
|
-
hyperLink: AD.HyperLink.HyperLink,
|
|
175
|
-
style: AD.TextStyle.TextStyle
|
|
176
|
-
): InternalHyperlink | ExternalHyperlink {
|
|
177
|
+
function renderHyperLink(hyperLink: AD.HyperLink.HyperLink, style: AD.TextStyle.TextStyle): InternalHyperlink | ExternalHyperlink {
|
|
177
178
|
const fontSize = AD.TextStyle.calculateFontSize(style, 10) * 2;
|
|
178
179
|
const textRun = new TextRun({
|
|
179
180
|
text: hyperLink.text,
|
|
180
|
-
font: style.fontFamily
|
|
181
|
+
font: style.fontFamily ?? "Helvetica",
|
|
181
182
|
size: fontSize,
|
|
182
|
-
color: style.color
|
|
183
|
-
bold: style.bold
|
|
183
|
+
color: style.color ?? "#0000ff",
|
|
184
|
+
bold: style.bold ?? style.fontWeight === "bold",
|
|
184
185
|
characterSpacing: style.characterSpacing,
|
|
185
186
|
underline: style.underline
|
|
186
187
|
? {
|
|
187
|
-
color: style.color
|
|
188
|
+
color: style.color ?? "#0000ff",
|
|
188
189
|
type: UnderlineType.SINGLE,
|
|
189
190
|
}
|
|
190
191
|
: undefined,
|
|
@@ -215,11 +216,10 @@ function renderSectionElement(
|
|
|
215
216
|
return [renderParagraph(element, resources, keepNext)];
|
|
216
217
|
case "Group":
|
|
217
218
|
return [...renderGroup(element, parentResources, contentAvailableWidth)];
|
|
218
|
-
case "Table":
|
|
219
|
+
case "Table": {
|
|
219
220
|
const table = renderTable(element, resources, contentAvailableWidth, keepNext);
|
|
220
|
-
return table
|
|
221
|
-
|
|
222
|
-
: [];
|
|
221
|
+
return table ? [table, new Paragraph({ keepNext: keepNext, children: [new TextRun({ text: ".", size: 0.000001 })] })] : [];
|
|
222
|
+
}
|
|
223
223
|
case "PageBreak":
|
|
224
224
|
return [
|
|
225
225
|
new Paragraph({
|
|
@@ -231,29 +231,15 @@ function renderSectionElement(
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
function renderTable(
|
|
235
|
-
table
|
|
236
|
-
resources: AD.Resources.Resources,
|
|
237
|
-
contentAvailableWidth: number,
|
|
238
|
-
keepNext: boolean
|
|
239
|
-
): Table | undefined {
|
|
240
|
-
const style = AD.Resources.getStyle(
|
|
241
|
-
undefined,
|
|
242
|
-
table.style,
|
|
243
|
-
"TableStyle",
|
|
244
|
-
table.styleName,
|
|
245
|
-
resources
|
|
246
|
-
) as AD.TableStyle.TableStyle;
|
|
234
|
+
function renderTable(table: AD.Table.Table, resources: AD.Resources.Resources, contentAvailableWidth: number, keepNext: boolean): Table | undefined {
|
|
235
|
+
const style = AD.Resources.getStyle(undefined, table.style, "TableStyle", table.styleName, resources) as AD.TableStyle.TableStyle;
|
|
247
236
|
const styleMargins = AD.LayoutFoundation.orDefault(style.margins);
|
|
248
237
|
|
|
249
238
|
if (table.children.length === 0) {
|
|
250
239
|
return undefined;
|
|
251
240
|
}
|
|
252
241
|
|
|
253
|
-
const tableWidthWithoutInfinity = table.columnWidths.reduce(
|
|
254
|
-
(sofar, c) => (Number.isFinite(c) ? sofar + c : sofar),
|
|
255
|
-
0
|
|
256
|
-
);
|
|
242
|
+
const tableWidthWithoutInfinity = table.columnWidths.reduce((sofar, c) => (Number.isFinite(c) ? sofar + c : sofar), 0);
|
|
257
243
|
const amountOfInfinity = table.columnWidths.reduce((sofar, c) => (!Number.isFinite(c) ? sofar + 1 : sofar), 0);
|
|
258
244
|
const infinityCellWidth = (contentAvailableWidth - tableWidthWithoutInfinity) / amountOfInfinity;
|
|
259
245
|
const columnWidths = table.columnWidths.map((w) =>
|
|
@@ -262,12 +248,7 @@ function renderTable(
|
|
|
262
248
|
|
|
263
249
|
return new Table({
|
|
264
250
|
layout: "fixed",
|
|
265
|
-
alignment:
|
|
266
|
-
style.alignment === "Left"
|
|
267
|
-
? AlignmentType.LEFT
|
|
268
|
-
: style.alignment === "Right"
|
|
269
|
-
? AlignmentType.RIGHT
|
|
270
|
-
: AlignmentType.CENTER,
|
|
251
|
+
alignment: style.alignment === "Left" ? AlignmentType.LEFT : style.alignment === "Right" ? AlignmentType.RIGHT : AlignmentType.CENTER,
|
|
271
252
|
margins: {
|
|
272
253
|
top: styleMargins.top * abstractDocPixelToDocxDXARatio,
|
|
273
254
|
bottom: styleMargins.bottom * abstractDocPixelToDocxDXARatio,
|
|
@@ -310,9 +291,7 @@ function renderTable(
|
|
|
310
291
|
style: BorderStyle.NONE,
|
|
311
292
|
},
|
|
312
293
|
},
|
|
313
|
-
rows: table.headerRows
|
|
314
|
-
.concat(table.children)
|
|
315
|
-
.map((c) => renderRow(c, resources, style.cellStyle, columnWidths, keepNext)),
|
|
294
|
+
rows: table.headerRows.concat(table.children).map((c) => renderRow(c, resources, style.cellStyle, columnWidths, keepNext)),
|
|
316
295
|
});
|
|
317
296
|
}
|
|
318
297
|
|
|
@@ -334,7 +313,7 @@ function renderRow(
|
|
|
334
313
|
children: [...acc.children, renderCell(cell, resources, tableCellStyle, width, keepNext)],
|
|
335
314
|
};
|
|
336
315
|
},
|
|
337
|
-
{ columnIndex: 0, children: [] as TableCell
|
|
316
|
+
{ columnIndex: 0, children: [] as Array<TableCell> }
|
|
338
317
|
).children;
|
|
339
318
|
|
|
340
319
|
return new TableRow({
|
|
@@ -352,13 +331,7 @@ function renderCell(
|
|
|
352
331
|
): TableCell {
|
|
353
332
|
const abstractDocPxCellWidth = width / abstractDocPixelToDocxDXARatio;
|
|
354
333
|
|
|
355
|
-
const style = AD.Resources.getStyle(
|
|
356
|
-
tableCellStyle,
|
|
357
|
-
cell.style,
|
|
358
|
-
"TableCellStyle",
|
|
359
|
-
cell.styleName,
|
|
360
|
-
resources
|
|
361
|
-
) as AD.TableCellStyle.TableCellStyle;
|
|
334
|
+
const style = AD.Resources.getStyle(tableCellStyle, cell.style, "TableCellStyle", cell.styleName, resources) as AD.TableCellStyle.TableCellStyle;
|
|
362
335
|
|
|
363
336
|
const stylePadding = AD.LayoutFoundation.orDefault(style.padding);
|
|
364
337
|
const styleBorders = AD.LayoutFoundation.orDefault(style.borders);
|
|
@@ -368,10 +341,10 @@ function renderCell(
|
|
|
368
341
|
(style.verticalAlignment && style.verticalAlignment === "Top"
|
|
369
342
|
? VerticalAlign.TOP
|
|
370
343
|
: style.verticalAlignment === "Bottom"
|
|
371
|
-
|
|
372
|
-
|
|
344
|
+
? VerticalAlign.BOTTOM
|
|
345
|
+
: VerticalAlign.CENTER) || undefined,
|
|
373
346
|
shading: {
|
|
374
|
-
fill: style.background
|
|
347
|
+
fill: style.background ?? undefined,
|
|
375
348
|
},
|
|
376
349
|
columnSpan: cell.columnSpan,
|
|
377
350
|
rowSpan: cell.rowSpan,
|
|
@@ -408,10 +381,10 @@ function renderCell(
|
|
|
408
381
|
},
|
|
409
382
|
},
|
|
410
383
|
|
|
411
|
-
children: cell.children.reduce((sofar, c) => {
|
|
384
|
+
children: cell.children.reduce<Array<Paragraph | Table>>((sofar, c) => {
|
|
412
385
|
sofar.push(...renderSectionElement(c, resources, abstractDocPxCellWidth, keepNext));
|
|
413
386
|
return sofar;
|
|
414
|
-
}, []
|
|
387
|
+
}, []),
|
|
415
388
|
});
|
|
416
389
|
}
|
|
417
390
|
|
|
@@ -448,18 +421,8 @@ function renderAtom(
|
|
|
448
421
|
}
|
|
449
422
|
}
|
|
450
423
|
|
|
451
|
-
function renderTextField(
|
|
452
|
-
|
|
453
|
-
textStyle: AD.TextStyle.TextStyle,
|
|
454
|
-
textField: AD.TextField.TextField
|
|
455
|
-
): TextRun {
|
|
456
|
-
const style = AD.Resources.getStyle(
|
|
457
|
-
textStyle,
|
|
458
|
-
textField.style,
|
|
459
|
-
"TextStyle",
|
|
460
|
-
textField.styleName,
|
|
461
|
-
resources
|
|
462
|
-
) as AD.TextStyle.TextStyle;
|
|
424
|
+
function renderTextField(resources: AD.Resources.Resources, textStyle: AD.TextStyle.TextStyle, textField: AD.TextField.TextField): TextRun {
|
|
425
|
+
const style = AD.Resources.getStyle(textStyle, textField.style, "TextStyle", textField.styleName, resources) as AD.TextStyle.TextStyle;
|
|
463
426
|
switch (textField.fieldType) {
|
|
464
427
|
case "Date":
|
|
465
428
|
return renderText(style, new Date(Date.now()).toDateString());
|
|
@@ -472,18 +435,14 @@ function renderTextField(
|
|
|
472
435
|
}
|
|
473
436
|
}
|
|
474
437
|
|
|
475
|
-
function renderTextRun(
|
|
476
|
-
resources: AD.Resources.Resources,
|
|
477
|
-
textStyle: AD.TextStyle.TextStyle,
|
|
478
|
-
textRun: AD.TextRun.TextRun
|
|
479
|
-
): TextRun {
|
|
438
|
+
function renderTextRun(resources: AD.Resources.Resources, textStyle: AD.TextStyle.TextStyle, textRun: AD.TextRun.TextRun): TextRun {
|
|
480
439
|
const style = AD.Resources.getNestedStyle(
|
|
481
440
|
textStyle,
|
|
482
441
|
textRun.style,
|
|
483
442
|
"TextStyle",
|
|
484
443
|
textRun.styleName,
|
|
485
444
|
resources,
|
|
486
|
-
textRun.nestedStyleNames
|
|
445
|
+
textRun.nestedStyleNames ?? []
|
|
487
446
|
) as AD.TextStyle.TextStyle;
|
|
488
447
|
|
|
489
448
|
return renderText(style, textRun.text);
|
|
@@ -492,10 +451,10 @@ function renderTextRun(
|
|
|
492
451
|
function renderPageNumber(style: AD.TextStyle.TextStyle): TextRun {
|
|
493
452
|
const fontSize = AD.TextStyle.calculateFontSize(style, 10) * abstractDocToDocxFontRatio;
|
|
494
453
|
return new TextRun({
|
|
495
|
-
font: style.fontFamily
|
|
454
|
+
font: style.fontFamily ?? "Helvetica",
|
|
496
455
|
size: fontSize,
|
|
497
|
-
color: style.color
|
|
498
|
-
bold: style.bold
|
|
456
|
+
color: style.color ?? "#000000",
|
|
457
|
+
bold: style.bold ?? style.fontWeight === "bold",
|
|
499
458
|
characterSpacing: style.characterSpacing,
|
|
500
459
|
underline: style.underline
|
|
501
460
|
? {
|
|
@@ -510,10 +469,10 @@ function renderPageNumber(style: AD.TextStyle.TextStyle): TextRun {
|
|
|
510
469
|
function renderTotalPages(style: AD.TextStyle.TextStyle): TextRun {
|
|
511
470
|
const fontSize = AD.TextStyle.calculateFontSize(style, 10) * abstractDocToDocxFontRatio;
|
|
512
471
|
return new TextRun({
|
|
513
|
-
font: style.fontFamily
|
|
472
|
+
font: style.fontFamily ?? "Helvetica",
|
|
514
473
|
size: fontSize,
|
|
515
|
-
color: style.color
|
|
516
|
-
bold: style.bold
|
|
474
|
+
color: style.color ?? "#000000",
|
|
475
|
+
bold: style.bold ?? style.fontWeight === "bold",
|
|
517
476
|
characterSpacing: style.characterSpacing,
|
|
518
477
|
underline: style.underline
|
|
519
478
|
? {
|
|
@@ -530,10 +489,10 @@ function renderText(style: AD.TextStyle.TextStyle, text: string): TextRun {
|
|
|
530
489
|
|
|
531
490
|
return new TextRun({
|
|
532
491
|
text: text,
|
|
533
|
-
font: style.fontFamily
|
|
492
|
+
font: style.fontFamily ?? "Helvetica",
|
|
534
493
|
size: fontSize,
|
|
535
|
-
color: style.color
|
|
536
|
-
bold: style.bold
|
|
494
|
+
color: style.color ?? "#000000",
|
|
495
|
+
bold: style.bold ?? style.fontWeight === "bold",
|
|
537
496
|
characterSpacing: style.characterSpacing,
|
|
538
497
|
underline: style.underline
|
|
539
498
|
? {
|
|
@@ -544,15 +503,11 @@ function renderText(style: AD.TextStyle.TextStyle, text: string): TextRun {
|
|
|
544
503
|
});
|
|
545
504
|
}
|
|
546
505
|
|
|
547
|
-
function renderGroup(
|
|
548
|
-
|
|
549
|
-
resources: AD.Resources.Resources,
|
|
550
|
-
availabelWidth: number
|
|
551
|
-
): Array<Paragraph | Table> {
|
|
552
|
-
let sofar = Array<Paragraph | Table>();
|
|
506
|
+
function renderGroup(group: AD.Group.Group, resources: AD.Resources.Resources, availabelWidth: number): Array<Paragraph | Table> {
|
|
507
|
+
const sofar = Array<Paragraph | Table>();
|
|
553
508
|
let keepNext = true;
|
|
554
509
|
for (let index = 0; index < group.children.length; index++) {
|
|
555
|
-
if (index
|
|
510
|
+
if (index === group.children.length - 1) {
|
|
556
511
|
keepNext = false;
|
|
557
512
|
}
|
|
558
513
|
sofar.push(...renderSectionElement(group.children[index], resources, availabelWidth, keepNext));
|
|
@@ -560,11 +515,7 @@ function renderGroup(
|
|
|
560
515
|
return sofar;
|
|
561
516
|
}
|
|
562
517
|
|
|
563
|
-
function renderParagraph(
|
|
564
|
-
paragraph: AD.Paragraph.Paragraph,
|
|
565
|
-
resources: AD.Resources.Resources,
|
|
566
|
-
keepNext: boolean
|
|
567
|
-
): Paragraph {
|
|
518
|
+
function renderParagraph(paragraph: AD.Paragraph.Paragraph, resources: AD.Resources.Resources, keepNext: boolean): Paragraph {
|
|
568
519
|
const style = AD.Resources.getStyle(
|
|
569
520
|
undefined,
|
|
570
521
|
paragraph.style,
|
|
@@ -578,11 +529,7 @@ function renderParagraph(
|
|
|
578
529
|
keepNext: keepNext,
|
|
579
530
|
alignment:
|
|
580
531
|
(style.alignment &&
|
|
581
|
-
(style.alignment === "Center"
|
|
582
|
-
? AlignmentType.CENTER
|
|
583
|
-
: style.alignment === "End"
|
|
584
|
-
? AlignmentType.END
|
|
585
|
-
: AlignmentType.START)) ||
|
|
532
|
+
(style.alignment === "Center" ? AlignmentType.CENTER : style.alignment === "End" ? AlignmentType.END : AlignmentType.START)) ??
|
|
586
533
|
undefined,
|
|
587
534
|
|
|
588
535
|
spacing: {
|
|
@@ -3,10 +3,7 @@ import type { Font } from "../../abstract-document/primitives/font.js";
|
|
|
3
3
|
import type { TextFontWeight } from "../../abstract-document/styles/text-style.js";
|
|
4
4
|
import { getResources } from "../shared/get_resources.js";
|
|
5
5
|
|
|
6
|
-
export function registerFonts(
|
|
7
|
-
registerFont: (fontName: string, fontSource: AD.Font.FontSource) => void,
|
|
8
|
-
document: AD.AbstractDoc.AbstractDoc
|
|
9
|
-
): void {
|
|
6
|
+
export function registerFonts(registerFont: (fontName: string, fontSource: AD.Font.FontSource) => void, document: AD.AbstractDoc.AbstractDoc): void {
|
|
10
7
|
const resources = getResources(document);
|
|
11
8
|
for (const [fontName, font] of Object.entries(resources.fonts ?? {})) {
|
|
12
9
|
// Required
|
|
@@ -17,32 +14,33 @@ export function registerFonts(
|
|
|
17
14
|
registerFont(fontName + "-BoldOblique", font.boldItalic);
|
|
18
15
|
registerFont(fontName + "-BoldItalic", font.boldItalic);
|
|
19
16
|
// Optional
|
|
20
|
-
registerFont(fontName + "-Light", font.light
|
|
21
|
-
registerFont(fontName + "-Medium", font.medium
|
|
22
|
-
registerFont(fontName + "-ExtraBold", font.extraBold
|
|
23
|
-
registerFont(fontName + "-LightOblique", font.lightItalic
|
|
24
|
-
registerFont(fontName + "-LightItalic", font.lightItalic
|
|
25
|
-
registerFont(fontName + "-MediumOblique", font.mediumItalic
|
|
26
|
-
registerFont(fontName + "-MediumItalic", font.mediumItalic
|
|
27
|
-
registerFont(fontName + "-ExtraBoldItalic", font.extraBoldItalic
|
|
28
|
-
registerFont(fontName + "-ExtraBoldOblique", font.extraBoldItalic
|
|
17
|
+
registerFont(fontName + "-Light", font.light ?? font.normal);
|
|
18
|
+
registerFont(fontName + "-Medium", font.medium ?? font.normal);
|
|
19
|
+
registerFont(fontName + "-ExtraBold", font.extraBold ?? font.bold);
|
|
20
|
+
registerFont(fontName + "-LightOblique", font.lightItalic ?? font.normal);
|
|
21
|
+
registerFont(fontName + "-LightItalic", font.lightItalic ?? font.normal);
|
|
22
|
+
registerFont(fontName + "-MediumOblique", font.mediumItalic ?? font.italic);
|
|
23
|
+
registerFont(fontName + "-MediumItalic", font.mediumItalic ?? font.italic);
|
|
24
|
+
registerFont(fontName + "-ExtraBoldItalic", font.extraBoldItalic ?? font.boldItalic);
|
|
25
|
+
registerFont(fontName + "-ExtraBoldOblique", font.extraBoldItalic ?? font.boldItalic);
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
function getFontWeightFromStyle(textStyle: AD.TextStyle.TextStyle): TextFontWeight {
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
return (
|
|
31
|
+
textStyle.fontWeight ??
|
|
32
|
+
(textStyle.light
|
|
33
|
+
? "light"
|
|
34
|
+
: textStyle.normal
|
|
35
|
+
? "normal"
|
|
36
|
+
: textStyle.bold
|
|
37
|
+
? "bold"
|
|
38
|
+
: textStyle.mediumBold
|
|
39
|
+
? "mediumBold"
|
|
40
|
+
: textStyle.extraBold
|
|
41
|
+
? "extraBold"
|
|
42
|
+
: "normal")
|
|
43
|
+
);
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
function getFontWeightFromAttributes(attribs: Record<string, string>): TextFontWeight {
|
|
@@ -57,6 +55,7 @@ export function getFontNameStyle(textStyle: AD.TextStyle.TextStyle): string {
|
|
|
57
55
|
|
|
58
56
|
export function getFontStyleName(attributes: Record<string, string>): keyof Font {
|
|
59
57
|
const fontWeight = getFontWeightFromAttributes(attributes);
|
|
58
|
+
// oxlint-disable-next-line typescript/no-unnecessary-template-expression
|
|
60
59
|
const stringifiedItalic = `${attributes["italic"]}`;
|
|
61
60
|
const italic = stringifiedItalic === "true" || stringifiedItalic === "1";
|
|
62
61
|
if (fontWeight === "normal") {
|
|
@@ -65,12 +64,8 @@ export function getFontStyleName(attributes: Record<string, string>): keyof Font
|
|
|
65
64
|
return `${fontWeight === "mediumBold" ? "medium" : fontWeight}${italic ? "Italic" : ""}`;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
export function getFontName(
|
|
69
|
-
fontFamily
|
|
70
|
-
fontWeight: TextFontWeight,
|
|
71
|
-
italic: boolean | undefined
|
|
72
|
-
): string {
|
|
73
|
-
const name = fontFamily || "Helvetica";
|
|
67
|
+
export function getFontName(fontFamily: string | undefined, fontWeight: TextFontWeight, italic: boolean | undefined): string {
|
|
68
|
+
const name = fontFamily ?? "Helvetica";
|
|
74
69
|
if (fontWeight === "light" && italic) {
|
|
75
70
|
return name + "-LightOblique";
|
|
76
71
|
} else if (fontWeight === "bold" && italic) {
|