abstract-document 20.0.1 → 20.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/lib/abstract-document/abstract-doc.d.ts +2 -2
- package/lib/abstract-document/abstract-doc.d.ts.map +1 -1
- package/lib/abstract-document/atoms/atom.d.ts +7 -7
- package/lib/abstract-document/atoms/atom.d.ts.map +1 -1
- package/lib/abstract-document/atoms/image.d.ts +1 -1
- package/lib/abstract-document/atoms/image.d.ts.map +1 -1
- package/lib/abstract-document/default-styles.d.ts +2 -2
- package/lib/abstract-document/default-styles.d.ts.map +1 -1
- package/lib/abstract-document/markdown/markdown.d.ts +1 -1
- package/lib/abstract-document/markdown/markdown.d.ts.map +1 -1
- package/lib/abstract-document/markdown/markdown.js +5 -2
- package/lib/abstract-document/markdown/markdown.js.map +1 -1
- package/lib/abstract-document/markdown/types.d.ts +1 -1
- package/lib/abstract-document/markdown/types.d.ts.map +1 -1
- package/lib/abstract-document/numberings/numbering-definition.d.ts +1 -1
- package/lib/abstract-document/numberings/numbering-definition.d.ts.map +1 -1
- package/lib/abstract-document/numberings/numbering-level-definition.d.ts +1 -1
- package/lib/abstract-document/numberings/numbering-level-definition.d.ts.map +1 -1
- package/lib/abstract-document/page/master-page.d.ts +1 -1
- package/lib/abstract-document/page/master-page.d.ts.map +1 -1
- package/lib/abstract-document/page/section.d.ts +2 -2
- package/lib/abstract-document/page/section.d.ts.map +1 -1
- package/lib/abstract-document/primitives/image-resource.d.ts +1 -1
- package/lib/abstract-document/primitives/image-resource.d.ts.map +1 -1
- package/lib/abstract-document/resources.d.ts +5 -5
- package/lib/abstract-document/resources.d.ts.map +1 -1
- package/lib/abstract-document/resources.js.map +1 -1
- package/lib/abstract-document/section-elements/group.d.ts +2 -2
- package/lib/abstract-document/section-elements/group.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/page-break.d.ts +1 -1
- package/lib/abstract-document/section-elements/page-break.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/paragraph.d.ts +3 -3
- package/lib/abstract-document/section-elements/paragraph.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/section-element.d.ts +1 -1
- package/lib/abstract-document/section-elements/section-element.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/table.d.ts +2 -2
- package/lib/abstract-document/section-elements/table.d.ts.map +1 -1
- package/lib/abstract-document/styles/group-style.d.ts +1 -1
- package/lib/abstract-document/styles/group-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/paragraph-style.d.ts +1 -1
- package/lib/abstract-document/styles/paragraph-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/table-style.d.ts +1 -1
- package/lib/abstract-document/styles/table-style.d.ts.map +1 -1
- package/lib/abstract-document/table/table-cell.d.ts +1 -1
- package/lib/abstract-document/table/table-cell.d.ts.map +1 -1
- package/lib/abstract-document/table/table-row.d.ts +1 -1
- package/lib/abstract-document/table/table-row.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/ref-container.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/xml-writer.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/xml-writer.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.d.ts +4 -4
- package/lib/abstract-document-exporters/docx2/render-image.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.js +7 -13
- package/lib/abstract-document-exporters/docx2/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx2/render.js +28 -24
- package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.d.ts +2 -2
- package/lib/abstract-document-exporters/pdf/font.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.js +1 -1
- package/lib/abstract-document-exporters/pdf/font.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.d.ts +1 -1
- package/lib/abstract-document-exporters/pdf/measure.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.js +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.js +0 -2
- package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/update-refs.d.ts +1 -1
- package/lib/abstract-document-exporters/pdf/update-refs.d.ts.map +1 -1
- package/lib/abstract-document-exporters/shared/get_resources.d.ts +2 -2
- package/lib/abstract-document-exporters/shared/get_resources.d.ts.map +1 -1
- package/lib/abstract-document-exporters/shared/get_resources.js.map +1 -1
- package/lib/abstract-document-jsx/index.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts +3 -3
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js +32 -32
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js +74 -74
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts +3 -2
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js.map +1 -1
- package/lib/abstract-document-xml/xsd-template/custom-elements.d.ts.map +1 -1
- package/lib/abstract-document-xml/xsd-template/custom-elements.js +0 -1
- package/lib/abstract-document-xml/xsd-template/custom-elements.js.map +1 -1
- package/package.json +4 -4
- package/src/abstract-document/abstract-doc.ts +7 -7
- package/src/abstract-document/atoms/atom.ts +7 -7
- package/src/abstract-document/atoms/image.ts +1 -1
- package/src/abstract-document/default-styles.ts +2 -2
- package/src/abstract-document/markdown/markdown.ts +9 -6
- package/src/abstract-document/markdown/types.ts +1 -1
- package/src/abstract-document/numberings/numbering-definition.ts +1 -1
- package/src/abstract-document/numberings/numbering-level-definition.ts +1 -1
- package/src/abstract-document/page/master-page.ts +1 -1
- package/src/abstract-document/page/section.ts +2 -2
- package/src/abstract-document/primitives/image-resource.ts +1 -1
- package/src/abstract-document/resources.ts +9 -8
- package/src/abstract-document/section-elements/group.ts +2 -2
- package/src/abstract-document/section-elements/page-break.ts +1 -1
- package/src/abstract-document/section-elements/paragraph.ts +3 -3
- package/src/abstract-document/section-elements/section-element.ts +1 -1
- package/src/abstract-document/section-elements/table.ts +2 -2
- package/src/abstract-document/styles/group-style.ts +1 -1
- package/src/abstract-document/styles/paragraph-style.ts +1 -1
- package/src/abstract-document/styles/table-style.ts +1 -1
- package/src/abstract-document/table/table-cell.ts +1 -1
- package/src/abstract-document/table/table-row.ts +1 -1
- package/src/abstract-document-exporters/docx2/render-image.ts +63 -51
- package/src/abstract-document-exporters/docx2/render.ts +62 -57
- package/src/abstract-document-exporters/pdf/font.ts +5 -5
- package/src/abstract-document-exporters/pdf/measure.ts +2 -1
- package/src/abstract-document-exporters/pdf/pre-process.ts +1 -2
- package/src/abstract-document-exporters/pdf/render-image.ts +1 -3
- package/src/abstract-document-exporters/pdf/render.ts +4 -2
- package/src/abstract-document-exporters/pdf/update-refs.ts +2 -2
- package/src/abstract-document-exporters/shared/get_resources.ts +10 -9
- package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +43 -42
- package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +111 -113
- package/src/abstract-document-xml/abstract-doc-of-xml/custom-elements.tsx +4 -13
- package/src/abstract-document-xml/xsd-template/custom-elements.ts +0 -1
- package/src/custom_typings/pdfkit-standard-fonts/index.d.ts +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Resources } from "../resources.js";
|
|
1
|
+
import type { Resources } from "../resources.js";
|
|
2
2
|
import * as MasterPage from "./master-page.js";
|
|
3
|
-
import { SectionElement } from "../section-elements/section-element.js";
|
|
3
|
+
import type { SectionElement } from "../section-elements/section-element.js";
|
|
4
4
|
|
|
5
5
|
export type Section = Resources & {
|
|
6
6
|
readonly page: MasterPage.MasterPage;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// import { ImageResource } from "./primitives/image-resource.js";
|
|
2
2
|
// import { Numbering } from "./numberings/numbering.js";
|
|
3
|
-
import { NumberingDefinition } from "./numberings/numbering-definition.js";
|
|
3
|
+
import type { NumberingDefinition } from "./numberings/numbering-definition.js";
|
|
4
4
|
import { create } from "./styles/style-key.js";
|
|
5
|
-
import { Style
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import type { Style } from "./styles/style.js";
|
|
6
|
+
import { overrideWith } from "./styles/style.js";
|
|
7
|
+
import type { Font } from "./primitives/font.js";
|
|
8
|
+
import type { Indexer } from "./types.js";
|
|
8
9
|
import { defaultAndStandardStyles } from "./default-styles.js";
|
|
9
|
-
import { ImageResource } from "./primitives/image-resource.js";
|
|
10
|
+
import type { ImageResource } from "./primitives/image-resource.js";
|
|
10
11
|
|
|
11
12
|
export interface Resources {
|
|
12
13
|
readonly fonts?: Indexer<Font>;
|
|
@@ -69,9 +70,9 @@ export function getNestedStyle(
|
|
|
69
70
|
const namedStyle = resources.styles && resources.styles[create(type, name)];
|
|
70
71
|
const nestedStyle = nestedStyleNames
|
|
71
72
|
? nestedStyleNames.reduce(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
(sofar, name) => overrideWith(sofar, resources.styles && resources.styles[create(type, name)]),
|
|
74
|
+
namedStyle
|
|
75
|
+
)
|
|
75
76
|
: namedStyle;
|
|
76
77
|
return overrideWith(
|
|
77
78
|
elementStyle,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Resources } from "../resources.js";
|
|
2
|
-
import { SectionElement } from "./section-element.js";
|
|
1
|
+
import type { Resources } from "../resources.js";
|
|
2
|
+
import type { SectionElement } from "./section-element.js";
|
|
3
3
|
import * as GroupStyle from "../styles/group-style.js";
|
|
4
4
|
|
|
5
5
|
export const sectionType = "Group";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Resources } from "../resources.js";
|
|
2
|
-
import { Atom } from "../atoms/atom.js";
|
|
3
|
-
import { ParagraphNumbering } from "./paragraph-numbering.js";
|
|
1
|
+
import type { Resources } from "../resources.js";
|
|
2
|
+
import type { Atom } from "../atoms/atom.js";
|
|
3
|
+
import type { ParagraphNumbering } from "./paragraph-numbering.js";
|
|
4
4
|
import * as ParagraphStyle from "../styles/paragraph-style.js";
|
|
5
5
|
|
|
6
6
|
export const sectionType = "Paragraph";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Group from "./group.js";
|
|
2
2
|
import * as Paragraph from "./paragraph.js";
|
|
3
3
|
import * as Table from "./table.js";
|
|
4
|
-
import * as PageBreak from "./page-break.js";
|
|
4
|
+
import type * as PageBreak from "./page-break.js";
|
|
5
5
|
|
|
6
6
|
export type SectionElement = Group.Group | Paragraph.Paragraph | Table.Table | PageBreak.PageBreak;
|
|
7
7
|
export type SectionElementNoPageBreak = Exclude<SectionElement, PageBreak.PageBreak>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Resources } from "../resources.js";
|
|
2
|
-
import * as TableRow from "../table/table-row.js";
|
|
1
|
+
import type { Resources } from "../resources.js";
|
|
2
|
+
import type * as TableRow from "../table/table-row.js";
|
|
3
3
|
import * as TableStyle from "../styles/table-style.js";
|
|
4
4
|
|
|
5
5
|
export const sectionType = "Table";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as TextStyle from "./text-style.js";
|
|
2
2
|
import * as LayoutFoundation from "../primitives/layout-foundation.js";
|
|
3
|
-
import * as Position from "./position.js";
|
|
3
|
+
import type * as Position from "./position.js";
|
|
4
4
|
|
|
5
5
|
export type TextAlignment = "Start" | "Center" | "End" | "Justify";
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as LayoutFoundation from "../primitives/layout-foundation.js";
|
|
2
2
|
import * as TableCellStyle from "./table-cell-style.js";
|
|
3
|
-
import * as Position from "./position.js";
|
|
3
|
+
import type * as Position from "./position.js";
|
|
4
4
|
|
|
5
5
|
export type TableAlignment = "Left" | "Center" | "Right";
|
|
6
6
|
|
|
@@ -1,35 +1,26 @@
|
|
|
1
|
-
import * as AbstractImage from "abstract-image";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import type * as AbstractImage from "abstract-image";
|
|
2
|
+
import type { IMediaTransformation } from "docx";
|
|
3
|
+
import { ImageRun } from "docx";
|
|
4
|
+
import type { TextStyle } from "../../abstract-document/styles/text-style.js";
|
|
5
|
+
import type { Image } from "../../abstract-document/atoms/image.js";
|
|
6
6
|
import { fromBase64, rawSvgPrefix } from "../shared/base-64.js";
|
|
7
|
-
import * as AD from "../../abstract-document/index.js";
|
|
7
|
+
import type * as AD from "../../abstract-document/index.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
|
|
|
11
|
-
const emptyPNG =
|
|
12
|
-
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO6pH7sAAAAASUVORK5CYII=";
|
|
11
|
+
const emptyPNG = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO6pH7sAAAAASUVORK5CYII=";
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export function renderImage(
|
|
20
|
-
image: Image,
|
|
21
|
-
textStyle: TextStyle,
|
|
22
|
-
resources: Resources.Resources
|
|
23
|
-
): ImageRun {
|
|
13
|
+
const fallbackImage = {
|
|
14
|
+
type: "png" as const,
|
|
15
|
+
data: fromBase64(emptyPNG),
|
|
16
|
+
};
|
|
24
17
|
|
|
18
|
+
export function renderImage(image: Image, textStyle: TextStyle, resources: AD.Resources.Resources): ImageRun {
|
|
25
19
|
const aImage = image.imageResource.abstractImage;
|
|
26
20
|
|
|
27
21
|
const firstComp = aImage.components[0];
|
|
28
22
|
const resource =
|
|
29
|
-
!aImage.size.width &&
|
|
30
|
-
!aImage.size.height &&
|
|
31
|
-
firstComp?.type === "binaryimage" &&
|
|
32
|
-
firstComp.data.type === "url"
|
|
23
|
+
!aImage.size.width && !aImage.size.height && firstComp?.type === "binaryimage" && firstComp.data.type === "url"
|
|
33
24
|
? resources.imageResources?.[firstComp.data.url] ?? image.imageResource
|
|
34
25
|
: image.imageResource;
|
|
35
26
|
|
|
@@ -48,7 +39,10 @@ export function renderImage(
|
|
|
48
39
|
const drawnW = imgW * scale;
|
|
49
40
|
const drawnH = imgH * scale;
|
|
50
41
|
|
|
51
|
-
const transformation: IMediaTransformation = {
|
|
42
|
+
const transformation: IMediaTransformation = {
|
|
43
|
+
width: drawnW * abstractDocPointsToDocxPxRatio,
|
|
44
|
+
height: drawnH * abstractDocPointsToDocxPxRatio,
|
|
45
|
+
};
|
|
52
46
|
|
|
53
47
|
const directImage = tryCreateDirectImageRun(resource, transformation, resources);
|
|
54
48
|
if (directImage) {
|
|
@@ -68,7 +62,7 @@ export function renderImage(
|
|
|
68
62
|
function tryCreateDirectImageRun(
|
|
69
63
|
resource: AD.ImageResource.ImageResource,
|
|
70
64
|
transformation: IMediaTransformation,
|
|
71
|
-
resources: Resources.Resources
|
|
65
|
+
resources: AD.Resources.Resources
|
|
72
66
|
): ImageRun | undefined {
|
|
73
67
|
if (resource.abstractImage.components.length !== 1) {
|
|
74
68
|
return undefined;
|
|
@@ -85,7 +79,7 @@ function tryCreateDirectImageRun(
|
|
|
85
79
|
function binaryImageToImageRun(
|
|
86
80
|
component: AbstractImage.BinaryImage,
|
|
87
81
|
transformation: IMediaTransformation,
|
|
88
|
-
resources: Resources.Resources
|
|
82
|
+
resources: AD.Resources.Resources
|
|
89
83
|
): ImageRun | undefined {
|
|
90
84
|
const format = component.format.toLowerCase();
|
|
91
85
|
|
|
@@ -145,7 +139,7 @@ function binaryImageToImageRun(
|
|
|
145
139
|
}
|
|
146
140
|
|
|
147
141
|
if (mimeType.includes("svg")) {
|
|
148
|
-
return new ImageRun({ type: "svg", data, transformation, fallback: fallbackImage});
|
|
142
|
+
return new ImageRun({ type: "svg", data, transformation, fallback: fallbackImage });
|
|
149
143
|
}
|
|
150
144
|
}
|
|
151
145
|
}
|
|
@@ -155,7 +149,7 @@ function binaryImageToImageRun(
|
|
|
155
149
|
|
|
156
150
|
function abstractImageToSvg(
|
|
157
151
|
image: AbstractImage.AbstractImage,
|
|
158
|
-
resources: Resources.Resources,
|
|
152
|
+
resources: AD.Resources.Resources,
|
|
159
153
|
textStyle: TextStyle
|
|
160
154
|
): string {
|
|
161
155
|
const width = image.size.width || 1;
|
|
@@ -171,7 +165,7 @@ function abstractImageToSvg(
|
|
|
171
165
|
|
|
172
166
|
function componentToSvg(
|
|
173
167
|
component: AbstractImage.Component,
|
|
174
|
-
resources: Resources.Resources,
|
|
168
|
+
resources: AD.Resources.Resources,
|
|
175
169
|
textStyle: TextStyle,
|
|
176
170
|
circuitBreaker: number
|
|
177
171
|
): string {
|
|
@@ -181,9 +175,7 @@ function componentToSvg(
|
|
|
181
175
|
|
|
182
176
|
switch (component.type) {
|
|
183
177
|
case "group":
|
|
184
|
-
return component.children
|
|
185
|
-
.map((child) => componentToSvg(child, resources, textStyle, circuitBreaker))
|
|
186
|
-
.join("");
|
|
178
|
+
return component.children.map((child) => componentToSvg(child, resources, textStyle, circuitBreaker)).join("");
|
|
187
179
|
|
|
188
180
|
case "subimage": {
|
|
189
181
|
const scaleX = component.size.width / (component.image.size.width || 1);
|
|
@@ -201,19 +193,33 @@ function componentToSvg(
|
|
|
201
193
|
return binaryImageToSvg(component, resources, textStyle, circuitBreaker);
|
|
202
194
|
|
|
203
195
|
case "line":
|
|
204
|
-
return `<line x1="${component.start.x}" y1="${component.start.y}" x2="${component.end.x}" y2="${
|
|
196
|
+
return `<line x1="${component.start.x}" y1="${component.start.y}" x2="${component.end.x}" y2="${
|
|
197
|
+
component.end.y
|
|
198
|
+
}" ${strokeAttrs(component.strokeColor, component.strokeThickness, component.strokeDashStyle)} />`;
|
|
205
199
|
|
|
206
200
|
case "polyline":
|
|
207
|
-
return `<polyline points="${component.points.map((p) => `${p.x},${p.y}`).join(" ")}" fill="none" ${strokeAttrs(
|
|
201
|
+
return `<polyline points="${component.points.map((p) => `${p.x},${p.y}`).join(" ")}" fill="none" ${strokeAttrs(
|
|
202
|
+
component.strokeColor,
|
|
203
|
+
component.strokeThickness,
|
|
204
|
+
component.strokeDashStyle
|
|
205
|
+
)} />`;
|
|
208
206
|
|
|
209
207
|
case "polygon":
|
|
210
|
-
return `<polygon points="${component.points.map((p) => `${p.x},${p.y}`).join(" ")}" ${fillAttrs(
|
|
208
|
+
return `<polygon points="${component.points.map((p) => `${p.x},${p.y}`).join(" ")}" ${fillAttrs(
|
|
209
|
+
component.fillColor
|
|
210
|
+
)} ${strokeAttrs(component.strokeColor, component.strokeThickness, component.strokeDashStyle)} />`;
|
|
211
211
|
|
|
212
212
|
case "rectangle": {
|
|
213
213
|
const width = component.bottomRight.x - component.topLeft.x;
|
|
214
214
|
const height = component.bottomRight.y - component.topLeft.y;
|
|
215
215
|
|
|
216
|
-
return `<rect x="${component.topLeft.x}" y="${
|
|
216
|
+
return `<rect x="${component.topLeft.x}" y="${
|
|
217
|
+
component.topLeft.y
|
|
218
|
+
}" width="${width}" height="${height}" ${fillAttrs(component.fillColor)} ${strokeAttrs(
|
|
219
|
+
component.strokeColor,
|
|
220
|
+
component.strokeThickness,
|
|
221
|
+
component.strokeDashStyle
|
|
222
|
+
)} />`;
|
|
217
223
|
}
|
|
218
224
|
|
|
219
225
|
case "ellipse": {
|
|
@@ -222,7 +228,9 @@ function componentToSvg(
|
|
|
222
228
|
const cx = component.topLeft.x + width * 0.5;
|
|
223
229
|
const cy = component.topLeft.y + height * 0.5;
|
|
224
230
|
|
|
225
|
-
return `<ellipse cx="${cx}" cy="${cy}" rx="${width * 0.5}" ry="${height * 0.5}" ${fillAttrs(
|
|
231
|
+
return `<ellipse cx="${cx}" cy="${cy}" rx="${width * 0.5}" ry="${height * 0.5}" ${fillAttrs(
|
|
232
|
+
component.fillColor
|
|
233
|
+
)} ${strokeAttrs(component.strokeColor, component.strokeThickness, component.strokeDashStyle)} />`;
|
|
226
234
|
}
|
|
227
235
|
|
|
228
236
|
case "text":
|
|
@@ -235,7 +243,7 @@ function componentToSvg(
|
|
|
235
243
|
|
|
236
244
|
function binaryImageToSvg(
|
|
237
245
|
component: AbstractImage.BinaryImage,
|
|
238
|
-
resources: Resources.Resources,
|
|
246
|
+
resources: AD.Resources.Resources,
|
|
239
247
|
textStyle: TextStyle,
|
|
240
248
|
circuitBreaker: number
|
|
241
249
|
): string {
|
|
@@ -263,7 +271,9 @@ function binaryImageToSvg(
|
|
|
263
271
|
return `<g transform="translate(${component.topLeft.x} ${component.topLeft.y})">${svg}</g>`;
|
|
264
272
|
}
|
|
265
273
|
|
|
266
|
-
return `<image x="${component.topLeft.x}" y="${
|
|
274
|
+
return `<image x="${component.topLeft.x}" y="${
|
|
275
|
+
component.topLeft.y
|
|
276
|
+
}" width="${width}" height="${height}" href="${escapeXml(component.data.url)}" />`;
|
|
267
277
|
}
|
|
268
278
|
|
|
269
279
|
if (component.data.type === "bytes") {
|
|
@@ -307,24 +317,30 @@ function textComponentToSvg(component: AbstractImage.Text): string {
|
|
|
307
317
|
? "middle"
|
|
308
318
|
: "text-before-edge";
|
|
309
319
|
|
|
310
|
-
return `<text x="${component.position.x}" y="${component.position.y}" font-family="${escapeXml(
|
|
320
|
+
return `<text x="${component.position.x}" y="${component.position.y}" font-family="${escapeXml(
|
|
321
|
+
component.fontFamily
|
|
322
|
+
)}" font-size="${component.fontSize}" font-weight="${component.fontWeight}" font-style="${
|
|
323
|
+
component.italic ? "italic" : "normal"
|
|
324
|
+
}" fill="${colorToCss(
|
|
325
|
+
component.textColor
|
|
326
|
+
)}" text-anchor="${anchor}" dominant-baseline="${dominantBaseline}"${rotation}>${escapeXml(component.text)}</text>`;
|
|
311
327
|
}
|
|
312
328
|
|
|
313
329
|
function fillAttrs(color: AbstractImage.Color): string {
|
|
314
330
|
return `fill="${colorToCss(color)}" fill-opacity="${colorToOpacity(color)}"`;
|
|
315
331
|
}
|
|
316
332
|
|
|
317
|
-
function strokeAttrs(
|
|
318
|
-
color: AbstractImage.Color,
|
|
319
|
-
thickness: number,
|
|
320
|
-
dashStyle: AbstractImage.DashStyle
|
|
321
|
-
): string {
|
|
333
|
+
function strokeAttrs(color: AbstractImage.Color, thickness: number, dashStyle: AbstractImage.DashStyle): string {
|
|
322
334
|
const dashArray =
|
|
323
335
|
dashStyle.dashes.length > 0
|
|
324
|
-
? ` stroke-dasharray="${dashStyle.dashes.filter((dash) => dash !== 0).join(" ")}" stroke-dashoffset="${
|
|
336
|
+
? ` stroke-dasharray="${dashStyle.dashes.filter((dash) => dash !== 0).join(" ")}" stroke-dashoffset="${
|
|
337
|
+
dashStyle.offset
|
|
338
|
+
}"`
|
|
325
339
|
: "";
|
|
326
340
|
|
|
327
|
-
return `stroke="${colorToCss(color)}" stroke-opacity="${colorToOpacity(
|
|
341
|
+
return `stroke="${colorToCss(color)}" stroke-opacity="${colorToOpacity(
|
|
342
|
+
color
|
|
343
|
+
)}" stroke-width="${thickness}"${dashArray}`;
|
|
328
344
|
}
|
|
329
345
|
|
|
330
346
|
function colorToOpacity(color: AbstractImage.Color): number {
|
|
@@ -336,11 +352,7 @@ function colorToCss(color: AbstractImage.Color): string {
|
|
|
336
352
|
}
|
|
337
353
|
|
|
338
354
|
function escapeXml(value: string): string {
|
|
339
|
-
return value
|
|
340
|
-
.replace(/&/g, "&")
|
|
341
|
-
.replace(/"/g, """)
|
|
342
|
-
.replace(/</g, "<")
|
|
343
|
-
.replace(/>/g, ">");
|
|
355
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
344
356
|
}
|
|
345
357
|
|
|
346
358
|
function resourceRect(resource: AD.ImageResource.ImageResource, rect: AbstractImage.Size): AbstractImage.Size {
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import * as AD from "../../abstract-document/index.js";
|
|
2
|
+
import type {
|
|
3
|
+
ISectionOptions,
|
|
4
|
+
ImageRun,
|
|
5
|
+
SymbolRun,
|
|
6
|
+
PageBreak,
|
|
7
|
+
SequentialIdentifier,
|
|
8
|
+
FootnoteReferenceRun,
|
|
9
|
+
InsertedTextRun,
|
|
10
|
+
DeletedTextRun,
|
|
11
|
+
Math as MathDocX,
|
|
12
|
+
} from "docx";
|
|
2
13
|
import {
|
|
3
14
|
Packer,
|
|
4
15
|
Document,
|
|
5
|
-
ISectionOptions,
|
|
6
16
|
Paragraph,
|
|
7
17
|
Table,
|
|
8
18
|
Bookmark,
|
|
@@ -19,14 +29,6 @@ import {
|
|
|
19
29
|
TableRow,
|
|
20
30
|
TableCell,
|
|
21
31
|
VerticalAlign,
|
|
22
|
-
ImageRun,
|
|
23
|
-
SymbolRun,
|
|
24
|
-
PageBreak,
|
|
25
|
-
SequentialIdentifier,
|
|
26
|
-
FootnoteReferenceRun,
|
|
27
|
-
InsertedTextRun,
|
|
28
|
-
DeletedTextRun,
|
|
29
|
-
Math as MathDocX,
|
|
30
32
|
PageNumber,
|
|
31
33
|
} from "docx";
|
|
32
34
|
import { renderImage } from "./render-image.js";
|
|
@@ -72,16 +74,14 @@ function createDocument(doc: AD.AbstractDoc.AbstractDoc): Document {
|
|
|
72
74
|
|
|
73
75
|
function renderSection(section: AD.Section.Section, parentResources: AD.Resources.Resources): ISectionOptions {
|
|
74
76
|
const pageWidth = AD.PageStyle.getWidth(section.page.style);
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const pageFooterMargins = AD.LayoutFoundation.orDefault(section.page.style.footerMargins)
|
|
77
|
+
const pageHeaderMargins = AD.LayoutFoundation.orDefault(section.page.style.headerMargins);
|
|
78
|
+
const pageFooterMargins = AD.LayoutFoundation.orDefault(section.page.style.footerMargins);
|
|
78
79
|
const pageContentMargins = AD.LayoutFoundation.orDefault(section.page.style.contentMargins);
|
|
79
80
|
|
|
80
81
|
const hasFrontHeader = section.page.frontHeader !== undefined && section.page.frontHeader.length !== 0;
|
|
81
82
|
const hasFrontFooter = section.page.frontFooter !== undefined && section.page.frontFooter.length !== 0;
|
|
82
|
-
|
|
83
|
-
const contentAvailableWidth =
|
|
84
|
-
pageWidth - (pageContentMargins.left + pageContentMargins.right);
|
|
83
|
+
|
|
84
|
+
const contentAvailableWidth = pageWidth - (pageContentMargins.left + pageContentMargins.right);
|
|
85
85
|
|
|
86
86
|
const resources = AD.Resources.mergeResources([parentResources, section]);
|
|
87
87
|
|
|
@@ -90,20 +90,24 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
90
90
|
return sofar;
|
|
91
91
|
}, [] as Array<Paragraph | Table>);
|
|
92
92
|
|
|
93
|
-
const firstpageHeaderChildren = hasFrontHeader
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
const firstpageHeaderChildren = hasFrontHeader
|
|
94
|
+
? section.page.frontHeader.reduce((sofar, c) => {
|
|
95
|
+
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
96
|
+
return sofar;
|
|
97
|
+
}, [] as Array<Paragraph | Table>)
|
|
98
|
+
: [];
|
|
97
99
|
|
|
98
100
|
const footerChildren = section.page.footer.reduce((sofar, c) => {
|
|
99
101
|
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
100
102
|
return sofar;
|
|
101
103
|
}, [] as Array<Paragraph | Table>);
|
|
102
104
|
|
|
103
|
-
const firstPageFooterChildren = hasFrontFooter
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
const firstPageFooterChildren = hasFrontFooter
|
|
106
|
+
? section.page.frontFooter.reduce((sofar, c) => {
|
|
107
|
+
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
108
|
+
return sofar;
|
|
109
|
+
}, [] as Array<Paragraph | Table>)
|
|
110
|
+
: [];
|
|
107
111
|
|
|
108
112
|
const contentChildren = [
|
|
109
113
|
new Paragraph({
|
|
@@ -146,17 +150,21 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
146
150
|
default: new Header({
|
|
147
151
|
children: headerChildren,
|
|
148
152
|
}),
|
|
149
|
-
first: hasFrontHeader
|
|
150
|
-
|
|
151
|
-
|
|
153
|
+
first: hasFrontHeader
|
|
154
|
+
? new Header({
|
|
155
|
+
children: firstpageHeaderChildren,
|
|
156
|
+
})
|
|
157
|
+
: undefined,
|
|
152
158
|
},
|
|
153
159
|
footers: {
|
|
154
160
|
default: new Footer({
|
|
155
|
-
children: footerChildren
|
|
161
|
+
children: footerChildren,
|
|
156
162
|
}),
|
|
157
|
-
first: hasFrontFooter
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
first: hasFrontFooter
|
|
164
|
+
? new Footer({
|
|
165
|
+
children: firstPageFooterChildren,
|
|
166
|
+
})
|
|
167
|
+
: undefined,
|
|
160
168
|
},
|
|
161
169
|
children: contentChildren,
|
|
162
170
|
};
|
|
@@ -176,9 +184,9 @@ function renderHyperLink(
|
|
|
176
184
|
characterSpacing: style.characterSpacing,
|
|
177
185
|
underline: style.underline
|
|
178
186
|
? {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
187
|
+
color: style.color || "#0000ff",
|
|
188
|
+
type: UnderlineType.SINGLE,
|
|
189
|
+
}
|
|
182
190
|
: undefined,
|
|
183
191
|
});
|
|
184
192
|
|
|
@@ -258,8 +266,8 @@ function renderTable(
|
|
|
258
266
|
style.alignment === "Left"
|
|
259
267
|
? AlignmentType.LEFT
|
|
260
268
|
: style.alignment === "Right"
|
|
261
|
-
|
|
262
|
-
|
|
269
|
+
? AlignmentType.RIGHT
|
|
270
|
+
: AlignmentType.CENTER,
|
|
263
271
|
margins: {
|
|
264
272
|
top: styleMargins.top * abstractDocPixelToDocxDXARatio,
|
|
265
273
|
bottom: styleMargins.bottom * abstractDocPixelToDocxDXARatio,
|
|
@@ -302,7 +310,9 @@ function renderTable(
|
|
|
302
310
|
style: BorderStyle.NONE,
|
|
303
311
|
},
|
|
304
312
|
},
|
|
305
|
-
rows: table.headerRows
|
|
313
|
+
rows: table.headerRows
|
|
314
|
+
.concat(table.children)
|
|
315
|
+
.map((c) => renderRow(c, resources, style.cellStyle, columnWidths, keepNext)),
|
|
306
316
|
});
|
|
307
317
|
}
|
|
308
318
|
|
|
@@ -317,16 +327,11 @@ function renderRow(
|
|
|
317
327
|
(acc, cell) => {
|
|
318
328
|
const span = cell.columnSpan ?? 1;
|
|
319
329
|
|
|
320
|
-
const width = columnWidths
|
|
321
|
-
.slice(acc.columnIndex, acc.columnIndex + span)
|
|
322
|
-
.reduce((a, b) => a + b, 0);
|
|
330
|
+
const width = columnWidths.slice(acc.columnIndex, acc.columnIndex + span).reduce((a, b) => a + b, 0);
|
|
323
331
|
|
|
324
332
|
return {
|
|
325
333
|
columnIndex: acc.columnIndex + span,
|
|
326
|
-
children: [
|
|
327
|
-
...acc.children,
|
|
328
|
-
renderCell(cell, resources, tableCellStyle, width, keepNext),
|
|
329
|
-
],
|
|
334
|
+
children: [...acc.children, renderCell(cell, resources, tableCellStyle, width, keepNext)],
|
|
330
335
|
};
|
|
331
336
|
},
|
|
332
337
|
{ columnIndex: 0, children: [] as TableCell[] }
|
|
@@ -346,7 +351,7 @@ function renderCell(
|
|
|
346
351
|
keepNext: boolean
|
|
347
352
|
): TableCell {
|
|
348
353
|
const abstractDocPxCellWidth = width / abstractDocPixelToDocxDXARatio;
|
|
349
|
-
|
|
354
|
+
|
|
350
355
|
const style = AD.Resources.getStyle(
|
|
351
356
|
tableCellStyle,
|
|
352
357
|
cell.style,
|
|
@@ -363,8 +368,8 @@ function renderCell(
|
|
|
363
368
|
(style.verticalAlignment && style.verticalAlignment === "Top"
|
|
364
369
|
? VerticalAlign.TOP
|
|
365
370
|
: style.verticalAlignment === "Bottom"
|
|
366
|
-
|
|
367
|
-
|
|
371
|
+
? VerticalAlign.BOTTOM
|
|
372
|
+
: VerticalAlign.CENTER) || undefined,
|
|
368
373
|
shading: {
|
|
369
374
|
fill: style.background ? style.background : undefined,
|
|
370
375
|
},
|
|
@@ -494,9 +499,9 @@ function renderPageNumber(style: AD.TextStyle.TextStyle): TextRun {
|
|
|
494
499
|
characterSpacing: style.characterSpacing,
|
|
495
500
|
underline: style.underline
|
|
496
501
|
? {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
502
|
+
color: style.color,
|
|
503
|
+
type: UnderlineType.SINGLE,
|
|
504
|
+
}
|
|
500
505
|
: undefined,
|
|
501
506
|
children: [PageNumber.CURRENT],
|
|
502
507
|
});
|
|
@@ -512,9 +517,9 @@ function renderTotalPages(style: AD.TextStyle.TextStyle): TextRun {
|
|
|
512
517
|
characterSpacing: style.characterSpacing,
|
|
513
518
|
underline: style.underline
|
|
514
519
|
? {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
520
|
+
color: style.color,
|
|
521
|
+
type: UnderlineType.SINGLE,
|
|
522
|
+
}
|
|
518
523
|
: undefined,
|
|
519
524
|
children: [PageNumber.TOTAL_PAGES],
|
|
520
525
|
});
|
|
@@ -532,9 +537,9 @@ function renderText(style: AD.TextStyle.TextStyle, text: string): TextRun {
|
|
|
532
537
|
characterSpacing: style.characterSpacing,
|
|
533
538
|
underline: style.underline
|
|
534
539
|
? {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
540
|
+
color: style.color,
|
|
541
|
+
type: UnderlineType.SINGLE,
|
|
542
|
+
}
|
|
538
543
|
: undefined,
|
|
539
544
|
});
|
|
540
545
|
}
|
|
@@ -576,8 +581,8 @@ function renderParagraph(
|
|
|
576
581
|
(style.alignment === "Center"
|
|
577
582
|
? AlignmentType.CENTER
|
|
578
583
|
: style.alignment === "End"
|
|
579
|
-
|
|
580
|
-
|
|
584
|
+
? AlignmentType.END
|
|
585
|
+
: AlignmentType.START)) ||
|
|
581
586
|
undefined,
|
|
582
587
|
|
|
583
588
|
spacing: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as AD from "../../abstract-document/index.js";
|
|
2
|
-
import { Font } from "../../abstract-document/primitives/font.js";
|
|
3
|
-
import { TextFontWeight } from "../../abstract-document/styles/text-style.js";
|
|
2
|
+
import type { Font } from "../../abstract-document/primitives/font.js";
|
|
3
|
+
import type { TextFontWeight } from "../../abstract-document/styles/text-style.js";
|
|
4
4
|
import { getResources } from "../shared/get_resources.js";
|
|
5
5
|
|
|
6
6
|
export function registerFonts(
|
|
@@ -57,12 +57,12 @@ export function getFontNameStyle(textStyle: AD.TextStyle.TextStyle): string {
|
|
|
57
57
|
|
|
58
58
|
export function getFontStyleName(attributes: Record<string, string>): keyof Font {
|
|
59
59
|
const fontWeight = getFontWeightFromAttributes(attributes);
|
|
60
|
-
const stringifiedItalic = `${attributes
|
|
60
|
+
const stringifiedItalic = `${attributes["italic"]}`;
|
|
61
61
|
const italic = stringifiedItalic === "true" || stringifiedItalic === "1";
|
|
62
|
-
if(fontWeight === "normal") {
|
|
62
|
+
if (fontWeight === "normal") {
|
|
63
63
|
return italic ? "italic" : fontWeight;
|
|
64
64
|
}
|
|
65
|
-
return `${fontWeight === "mediumBold" ? "medium" : fontWeight}${italic ? "Italic": ""}`;
|
|
65
|
+
return `${fontWeight === "mediumBold" ? "medium" : fontWeight}${italic ? "Italic" : ""}`;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export function getFontName(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as AD from "../../abstract-document/index.js";
|
|
2
2
|
import { exhaustiveCheck } from "ts-exhaustive-check";
|
|
3
|
-
import {
|
|
3
|
+
import type { Page } from "./paginate.js";
|
|
4
|
+
import { getHeaderAndFooter } from "./paginate.js";
|
|
4
5
|
import { registerFonts, getFontNameStyle } from "./font.js";
|
|
5
6
|
|
|
6
7
|
//tslint:disable:no-any variable-name
|