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.
Files changed (130) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/lib/abstract-document/abstract-doc.d.ts +2 -2
  3. package/lib/abstract-document/abstract-doc.d.ts.map +1 -1
  4. package/lib/abstract-document/atoms/atom.d.ts +7 -7
  5. package/lib/abstract-document/atoms/atom.d.ts.map +1 -1
  6. package/lib/abstract-document/atoms/image.d.ts +1 -1
  7. package/lib/abstract-document/atoms/image.d.ts.map +1 -1
  8. package/lib/abstract-document/default-styles.d.ts +2 -2
  9. package/lib/abstract-document/default-styles.d.ts.map +1 -1
  10. package/lib/abstract-document/markdown/markdown.d.ts +1 -1
  11. package/lib/abstract-document/markdown/markdown.d.ts.map +1 -1
  12. package/lib/abstract-document/markdown/markdown.js +5 -2
  13. package/lib/abstract-document/markdown/markdown.js.map +1 -1
  14. package/lib/abstract-document/markdown/types.d.ts +1 -1
  15. package/lib/abstract-document/markdown/types.d.ts.map +1 -1
  16. package/lib/abstract-document/numberings/numbering-definition.d.ts +1 -1
  17. package/lib/abstract-document/numberings/numbering-definition.d.ts.map +1 -1
  18. package/lib/abstract-document/numberings/numbering-level-definition.d.ts +1 -1
  19. package/lib/abstract-document/numberings/numbering-level-definition.d.ts.map +1 -1
  20. package/lib/abstract-document/page/master-page.d.ts +1 -1
  21. package/lib/abstract-document/page/master-page.d.ts.map +1 -1
  22. package/lib/abstract-document/page/section.d.ts +2 -2
  23. package/lib/abstract-document/page/section.d.ts.map +1 -1
  24. package/lib/abstract-document/primitives/image-resource.d.ts +1 -1
  25. package/lib/abstract-document/primitives/image-resource.d.ts.map +1 -1
  26. package/lib/abstract-document/resources.d.ts +5 -5
  27. package/lib/abstract-document/resources.d.ts.map +1 -1
  28. package/lib/abstract-document/resources.js.map +1 -1
  29. package/lib/abstract-document/section-elements/group.d.ts +2 -2
  30. package/lib/abstract-document/section-elements/group.d.ts.map +1 -1
  31. package/lib/abstract-document/section-elements/page-break.d.ts +1 -1
  32. package/lib/abstract-document/section-elements/page-break.d.ts.map +1 -1
  33. package/lib/abstract-document/section-elements/paragraph.d.ts +3 -3
  34. package/lib/abstract-document/section-elements/paragraph.d.ts.map +1 -1
  35. package/lib/abstract-document/section-elements/section-element.d.ts +1 -1
  36. package/lib/abstract-document/section-elements/section-element.d.ts.map +1 -1
  37. package/lib/abstract-document/section-elements/table.d.ts +2 -2
  38. package/lib/abstract-document/section-elements/table.d.ts.map +1 -1
  39. package/lib/abstract-document/styles/group-style.d.ts +1 -1
  40. package/lib/abstract-document/styles/group-style.d.ts.map +1 -1
  41. package/lib/abstract-document/styles/paragraph-style.d.ts +1 -1
  42. package/lib/abstract-document/styles/paragraph-style.d.ts.map +1 -1
  43. package/lib/abstract-document/styles/table-style.d.ts +1 -1
  44. package/lib/abstract-document/styles/table-style.d.ts.map +1 -1
  45. package/lib/abstract-document/table/table-cell.d.ts +1 -1
  46. package/lib/abstract-document/table/table-cell.d.ts.map +1 -1
  47. package/lib/abstract-document/table/table-row.d.ts +1 -1
  48. package/lib/abstract-document/table/table-row.d.ts.map +1 -1
  49. package/lib/abstract-document-exporters/docx/ref-container.d.ts.map +1 -1
  50. package/lib/abstract-document-exporters/docx/xml-writer.d.ts.map +1 -1
  51. package/lib/abstract-document-exporters/docx/xml-writer.js.map +1 -1
  52. package/lib/abstract-document-exporters/docx2/render-image.d.ts +4 -4
  53. package/lib/abstract-document-exporters/docx2/render-image.d.ts.map +1 -1
  54. package/lib/abstract-document-exporters/docx2/render-image.js +7 -13
  55. package/lib/abstract-document-exporters/docx2/render-image.js.map +1 -1
  56. package/lib/abstract-document-exporters/docx2/render.d.ts.map +1 -1
  57. package/lib/abstract-document-exporters/docx2/render.js +28 -24
  58. package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
  59. package/lib/abstract-document-exporters/pdf/font.d.ts +2 -2
  60. package/lib/abstract-document-exporters/pdf/font.d.ts.map +1 -1
  61. package/lib/abstract-document-exporters/pdf/font.js +1 -1
  62. package/lib/abstract-document-exporters/pdf/font.js.map +1 -1
  63. package/lib/abstract-document-exporters/pdf/measure.d.ts +1 -1
  64. package/lib/abstract-document-exporters/pdf/measure.d.ts.map +1 -1
  65. package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
  66. package/lib/abstract-document-exporters/pdf/paginate.js.map +1 -1
  67. package/lib/abstract-document-exporters/pdf/pre-process.d.ts.map +1 -1
  68. package/lib/abstract-document-exporters/pdf/pre-process.js +1 -1
  69. package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
  70. package/lib/abstract-document-exporters/pdf/render-image.js +0 -2
  71. package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
  72. package/lib/abstract-document-exporters/pdf/render.d.ts.map +1 -1
  73. package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
  74. package/lib/abstract-document-exporters/pdf/update-refs.d.ts +1 -1
  75. package/lib/abstract-document-exporters/pdf/update-refs.d.ts.map +1 -1
  76. package/lib/abstract-document-exporters/shared/get_resources.d.ts +2 -2
  77. package/lib/abstract-document-exporters/shared/get_resources.d.ts.map +1 -1
  78. package/lib/abstract-document-exporters/shared/get_resources.js.map +1 -1
  79. package/lib/abstract-document-jsx/index.d.ts.map +1 -1
  80. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts +3 -3
  81. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts.map +1 -1
  82. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js +32 -32
  83. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js.map +1 -1
  84. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.d.ts.map +1 -1
  85. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js +74 -74
  86. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js.map +1 -1
  87. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts +3 -2
  88. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts.map +1 -1
  89. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js +1 -1
  90. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js.map +1 -1
  91. package/lib/abstract-document-xml/xsd-template/custom-elements.d.ts.map +1 -1
  92. package/lib/abstract-document-xml/xsd-template/custom-elements.js +0 -1
  93. package/lib/abstract-document-xml/xsd-template/custom-elements.js.map +1 -1
  94. package/package.json +4 -4
  95. package/src/abstract-document/abstract-doc.ts +7 -7
  96. package/src/abstract-document/atoms/atom.ts +7 -7
  97. package/src/abstract-document/atoms/image.ts +1 -1
  98. package/src/abstract-document/default-styles.ts +2 -2
  99. package/src/abstract-document/markdown/markdown.ts +9 -6
  100. package/src/abstract-document/markdown/types.ts +1 -1
  101. package/src/abstract-document/numberings/numbering-definition.ts +1 -1
  102. package/src/abstract-document/numberings/numbering-level-definition.ts +1 -1
  103. package/src/abstract-document/page/master-page.ts +1 -1
  104. package/src/abstract-document/page/section.ts +2 -2
  105. package/src/abstract-document/primitives/image-resource.ts +1 -1
  106. package/src/abstract-document/resources.ts +9 -8
  107. package/src/abstract-document/section-elements/group.ts +2 -2
  108. package/src/abstract-document/section-elements/page-break.ts +1 -1
  109. package/src/abstract-document/section-elements/paragraph.ts +3 -3
  110. package/src/abstract-document/section-elements/section-element.ts +1 -1
  111. package/src/abstract-document/section-elements/table.ts +2 -2
  112. package/src/abstract-document/styles/group-style.ts +1 -1
  113. package/src/abstract-document/styles/paragraph-style.ts +1 -1
  114. package/src/abstract-document/styles/table-style.ts +1 -1
  115. package/src/abstract-document/table/table-cell.ts +1 -1
  116. package/src/abstract-document/table/table-row.ts +1 -1
  117. package/src/abstract-document-exporters/docx2/render-image.ts +63 -51
  118. package/src/abstract-document-exporters/docx2/render.ts +62 -57
  119. package/src/abstract-document-exporters/pdf/font.ts +5 -5
  120. package/src/abstract-document-exporters/pdf/measure.ts +2 -1
  121. package/src/abstract-document-exporters/pdf/pre-process.ts +1 -2
  122. package/src/abstract-document-exporters/pdf/render-image.ts +1 -3
  123. package/src/abstract-document-exporters/pdf/render.ts +4 -2
  124. package/src/abstract-document-exporters/pdf/update-refs.ts +2 -2
  125. package/src/abstract-document-exporters/shared/get_resources.ts +10 -9
  126. package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +43 -42
  127. package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +111 -113
  128. package/src/abstract-document-xml/abstract-doc-of-xml/custom-elements.tsx +4 -13
  129. package/src/abstract-document-xml/xsd-template/custom-elements.ts +0 -1
  130. 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,4 +1,4 @@
1
- import { AbstractImage } from "abstract-image";
1
+ import type { AbstractImage } from "abstract-image";
2
2
 
3
3
  export type Guid = string;
4
4
 
@@ -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, overrideWith } from "./styles/style.js";
6
- import { Font } from "./primitives/font.js";
7
- import { Indexer } from "./types.js";
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
- (sofar, name) => overrideWith(sofar, resources.styles && resources.styles[create(type, name)]),
73
- namedStyle
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,4 +1,4 @@
1
- import { Resources } from "../resources.js";
1
+ import type { Resources } from "../resources.js";
2
2
 
3
3
  export type PageBreak = Resources & {
4
4
  readonly type: "PageBreak";
@@ -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,5 +1,5 @@
1
1
  import * as LayoutFoundation from "../primitives/layout-foundation.js";
2
- import * as Position from "./position.js";
2
+ import type * as Position from "./position.js";
3
3
 
4
4
  export interface GroupStyle {
5
5
  readonly type: "GroupStyle";
@@ -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,4 +1,4 @@
1
- import * as SectionElement from "../section-elements/section-element.js";
1
+ import type * as SectionElement from "../section-elements/section-element.js";
2
2
  import * as TableCellStyle from "../styles/table-cell-style.js";
3
3
 
4
4
  export interface TableCell {
@@ -1,4 +1,4 @@
1
- import { TableCell } from "./table-cell.js";
1
+ import type { TableCell } from "./table-cell.js";
2
2
 
3
3
  export interface TableRow {
4
4
  readonly children: ReadonlyArray<TableCell>;
@@ -1,35 +1,26 @@
1
- import * as AbstractImage from "abstract-image";
2
- import { ImageRun, IMediaTransformation } from "docx";
3
- import { TextStyle } from "../../abstract-document/styles/text-style.js";
4
- import { Image } from "../../abstract-document/atoms/image.js";
5
- import { Resources } from "../../abstract-document/index.js";
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
- const fallbackImage = {
15
- type: "png" as const,
16
- data: fromBase64(emptyPNG),
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 = { width: drawnW * abstractDocPointsToDocxPxRatio, height: drawnH * abstractDocPointsToDocxPxRatio};
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="${component.end.y}" ${strokeAttrs(component.strokeColor, component.strokeThickness, component.strokeDashStyle)} />`;
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(component.strokeColor, component.strokeThickness, component.strokeDashStyle)} />`;
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(component.fillColor)} ${strokeAttrs(component.strokeColor, component.strokeThickness, component.strokeDashStyle)} />`;
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="${component.topLeft.y}" width="${width}" height="${height}" ${fillAttrs(component.fillColor)} ${strokeAttrs(component.strokeColor, component.strokeThickness, component.strokeDashStyle)} />`;
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(component.fillColor)} ${strokeAttrs(component.strokeColor, component.strokeThickness, component.strokeDashStyle)} />`;
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="${component.topLeft.y}" width="${width}" height="${height}" href="${escapeXml(component.data.url)}" />`;
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(component.fontFamily)}" font-size="${component.fontSize}" font-weight="${component.fontWeight}" font-style="${component.italic ? "italic" : "normal"}" fill="${colorToCss(component.textColor)}" text-anchor="${anchor}" dominant-baseline="${dominantBaseline}"${rotation}>${escapeXml(component.text)}</text>`;
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="${dashStyle.offset}"`
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(color)}" stroke-width="${thickness}"${dashArray}`;
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, "&amp;")
341
- .replace(/"/g, "&quot;")
342
- .replace(/</g, "&lt;")
343
- .replace(/>/g, "&gt;");
355
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
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 pageHeight = AD.PageStyle.getHeight(section.page.style);
76
- const pageHeaderMargins = AD.LayoutFoundation.orDefault(section.page.style.headerMargins)
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 ? section.page.frontHeader.reduce((sofar, c) => {
94
- sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
95
- return sofar;
96
- }, [] as Array<Paragraph | Table>) : [];
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 ? section.page.frontFooter.reduce((sofar, c) => {
104
- sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
105
- return sofar;
106
- }, [] as Array<Paragraph | Table>) : [];
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 ? new Header({
150
- children: firstpageHeaderChildren
151
- }) : undefined
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 ? new Footer({
158
- children: firstPageFooterChildren
159
- }) : undefined
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
- color: style.color || "#0000ff",
180
- type: UnderlineType.SINGLE,
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
- ? AlignmentType.RIGHT
262
- : AlignmentType.CENTER,
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.concat(table.children).map((c) => renderRow(c, resources, style.cellStyle, columnWidths, keepNext)),
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
- ? VerticalAlign.BOTTOM
367
- : VerticalAlign.CENTER) || undefined,
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
- color: style.color,
498
- type: UnderlineType.SINGLE,
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
- color: style.color,
516
- type: UnderlineType.SINGLE,
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
- color: style.color,
536
- type: UnderlineType.SINGLE,
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
- ? AlignmentType.END
580
- : AlignmentType.START)) ||
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.italic}`;
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 { getHeaderAndFooter, Page } from "./paginate.js";
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