abstract-document 20.0.1 → 20.0.4

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 (194) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +3 -3
  3. package/lib/abstract-document/abstract-doc.d.ts +2 -2
  4. package/lib/abstract-document/abstract-doc.d.ts.map +1 -1
  5. package/lib/abstract-document/atoms/atom.d.ts +7 -7
  6. package/lib/abstract-document/atoms/atom.d.ts.map +1 -1
  7. package/lib/abstract-document/atoms/image.d.ts +1 -1
  8. package/lib/abstract-document/atoms/image.d.ts.map +1 -1
  9. package/lib/abstract-document/atoms/line-break.d.ts +1 -1
  10. package/lib/abstract-document/atoms/line-break.d.ts.map +1 -1
  11. package/lib/abstract-document/atoms/line-break.js +1 -1
  12. package/lib/abstract-document/atoms/line-break.js.map +1 -1
  13. package/lib/abstract-document/atoms/link-target.js +1 -1
  14. package/lib/abstract-document/atoms/text-run.d.ts.map +1 -1
  15. package/lib/abstract-document/atoms/text-run.js +1 -0
  16. package/lib/abstract-document/atoms/text-run.js.map +1 -1
  17. package/lib/abstract-document/default-styles.d.ts +2 -2
  18. package/lib/abstract-document/default-styles.d.ts.map +1 -1
  19. package/lib/abstract-document/markdown/markdown.d.ts +1 -1
  20. package/lib/abstract-document/markdown/markdown.d.ts.map +1 -1
  21. package/lib/abstract-document/markdown/markdown.js +6 -3
  22. package/lib/abstract-document/markdown/markdown.js.map +1 -1
  23. package/lib/abstract-document/markdown/types.d.ts +1 -1
  24. package/lib/abstract-document/markdown/types.d.ts.map +1 -1
  25. package/lib/abstract-document/numberings/numbering-definition.d.ts +1 -1
  26. package/lib/abstract-document/numberings/numbering-definition.d.ts.map +1 -1
  27. package/lib/abstract-document/numberings/numbering-format.d.ts.map +1 -1
  28. package/lib/abstract-document/numberings/numbering-level-definition.d.ts +1 -1
  29. package/lib/abstract-document/numberings/numbering-level-definition.d.ts.map +1 -1
  30. package/lib/abstract-document/page/master-page.d.ts +1 -1
  31. package/lib/abstract-document/page/master-page.d.ts.map +1 -1
  32. package/lib/abstract-document/page/section.d.ts +2 -2
  33. package/lib/abstract-document/page/section.d.ts.map +1 -1
  34. package/lib/abstract-document/primitives/image-resource.d.ts +1 -1
  35. package/lib/abstract-document/primitives/image-resource.d.ts.map +1 -1
  36. package/lib/abstract-document/primitives/layout-foundation-color.js +4 -4
  37. package/lib/abstract-document/primitives/layout-foundation-color.js.map +1 -1
  38. package/lib/abstract-document/primitives/layout-foundation.js +1 -1
  39. package/lib/abstract-document/primitives/point.js +1 -1
  40. package/lib/abstract-document/resources.d.ts +5 -5
  41. package/lib/abstract-document/resources.d.ts.map +1 -1
  42. package/lib/abstract-document/resources.js.map +1 -1
  43. package/lib/abstract-document/section-elements/group.d.ts +2 -2
  44. package/lib/abstract-document/section-elements/group.d.ts.map +1 -1
  45. package/lib/abstract-document/section-elements/page-break.d.ts +1 -1
  46. package/lib/abstract-document/section-elements/page-break.d.ts.map +1 -1
  47. package/lib/abstract-document/section-elements/paragraph.d.ts +3 -3
  48. package/lib/abstract-document/section-elements/paragraph.d.ts.map +1 -1
  49. package/lib/abstract-document/section-elements/paragraph.js +1 -1
  50. package/lib/abstract-document/section-elements/paragraph.js.map +1 -1
  51. package/lib/abstract-document/section-elements/section-element.d.ts +1 -1
  52. package/lib/abstract-document/section-elements/section-element.d.ts.map +1 -1
  53. package/lib/abstract-document/section-elements/table.d.ts +2 -2
  54. package/lib/abstract-document/section-elements/table.d.ts.map +1 -1
  55. package/lib/abstract-document/styles/group-style.d.ts +1 -1
  56. package/lib/abstract-document/styles/group-style.d.ts.map +1 -1
  57. package/lib/abstract-document/styles/paragraph-style.d.ts +1 -1
  58. package/lib/abstract-document/styles/paragraph-style.d.ts.map +1 -1
  59. package/lib/abstract-document/styles/paragraph-style.js +1 -1
  60. package/lib/abstract-document/styles/paragraph-style.js.map +1 -1
  61. package/lib/abstract-document/styles/table-cell-style.d.ts.map +1 -1
  62. package/lib/abstract-document/styles/table-cell-style.js +1 -1
  63. package/lib/abstract-document/styles/table-cell-style.js.map +1 -1
  64. package/lib/abstract-document/styles/table-style.d.ts +1 -1
  65. package/lib/abstract-document/styles/table-style.d.ts.map +1 -1
  66. package/lib/abstract-document/styles/table-style.js +1 -1
  67. package/lib/abstract-document/styles/table-style.js.map +1 -1
  68. package/lib/abstract-document/styles/text-style.js +1 -1
  69. package/lib/abstract-document/styles/text-style.js.map +1 -1
  70. package/lib/abstract-document/table/table-cell.d.ts +1 -1
  71. package/lib/abstract-document/table/table-cell.d.ts.map +1 -1
  72. package/lib/abstract-document/table/table-row.d.ts +1 -1
  73. package/lib/abstract-document/table/table-row.d.ts.map +1 -1
  74. package/lib/abstract-document-exporters/docx/ref-container.d.ts.map +1 -1
  75. package/lib/abstract-document-exporters/docx/string-utils.d.ts.map +1 -1
  76. package/lib/abstract-document-exporters/docx/string-utils.js +1 -3
  77. package/lib/abstract-document-exporters/docx/string-utils.js.map +1 -1
  78. package/lib/abstract-document-exporters/docx/xml-writer.d.ts.map +1 -1
  79. package/lib/abstract-document-exporters/docx/xml-writer.js +1 -0
  80. package/lib/abstract-document-exporters/docx/xml-writer.js.map +1 -1
  81. package/lib/abstract-document-exporters/docx2/render-image.d.ts +4 -4
  82. package/lib/abstract-document-exporters/docx2/render-image.d.ts.map +1 -1
  83. package/lib/abstract-document-exporters/docx2/render-image.js +8 -14
  84. package/lib/abstract-document-exporters/docx2/render-image.js.map +1 -1
  85. package/lib/abstract-document-exporters/docx2/render.d.ts.map +1 -1
  86. package/lib/abstract-document-exporters/docx2/render.js +37 -29
  87. package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
  88. package/lib/abstract-document-exporters/pdf/font.d.ts +2 -2
  89. package/lib/abstract-document-exporters/pdf/font.d.ts.map +1 -1
  90. package/lib/abstract-document-exporters/pdf/font.js +2 -1
  91. package/lib/abstract-document-exporters/pdf/font.js.map +1 -1
  92. package/lib/abstract-document-exporters/pdf/measure.d.ts +1 -1
  93. package/lib/abstract-document-exporters/pdf/measure.d.ts.map +1 -1
  94. package/lib/abstract-document-exporters/pdf/measure.js +3 -2
  95. package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
  96. package/lib/abstract-document-exporters/pdf/paginate.d.ts.map +1 -1
  97. package/lib/abstract-document-exporters/pdf/paginate.js +3 -2
  98. package/lib/abstract-document-exporters/pdf/paginate.js.map +1 -1
  99. package/lib/abstract-document-exporters/pdf/pre-process.d.ts.map +1 -1
  100. package/lib/abstract-document-exporters/pdf/pre-process.js +3 -2
  101. package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
  102. package/lib/abstract-document-exporters/pdf/render-image.js +1 -3
  103. package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
  104. package/lib/abstract-document-exporters/pdf/render.d.ts.map +1 -1
  105. package/lib/abstract-document-exporters/pdf/render.js +1 -0
  106. package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
  107. package/lib/abstract-document-exporters/pdf/std-fonts.js +1 -1
  108. package/lib/abstract-document-exporters/pdf/textRunRow.d.ts.map +1 -1
  109. package/lib/abstract-document-exporters/pdf/textRunRow.js +21 -15
  110. package/lib/abstract-document-exporters/pdf/textRunRow.js.map +1 -1
  111. package/lib/abstract-document-exporters/pdf/update-refs.d.ts +1 -1
  112. package/lib/abstract-document-exporters/pdf/update-refs.d.ts.map +1 -1
  113. package/lib/abstract-document-exporters/shared/get_resources.d.ts +2 -2
  114. package/lib/abstract-document-exporters/shared/get_resources.d.ts.map +1 -1
  115. package/lib/abstract-document-exporters/shared/get_resources.js.map +1 -1
  116. package/lib/abstract-document-jsx/index.d.ts.map +1 -1
  117. package/lib/abstract-document-jsx/index.js.map +1 -1
  118. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts +3 -3
  119. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts.map +1 -1
  120. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js +33 -33
  121. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js.map +1 -1
  122. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.d.ts.map +1 -1
  123. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js +81 -75
  124. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js.map +1 -1
  125. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts +3 -2
  126. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts.map +1 -1
  127. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js +1 -1
  128. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js.map +1 -1
  129. package/lib/abstract-document-xml/xsd-template/custom-elements.d.ts.map +1 -1
  130. package/lib/abstract-document-xml/xsd-template/custom-elements.js +0 -1
  131. package/lib/abstract-document-xml/xsd-template/custom-elements.js.map +1 -1
  132. package/package.json +4 -4
  133. package/src/abstract-document/abstract-doc.ts +7 -7
  134. package/src/abstract-document/atoms/atom.ts +7 -7
  135. package/src/abstract-document/atoms/image.ts +1 -1
  136. package/src/abstract-document/atoms/line-break.ts +1 -1
  137. package/src/abstract-document/atoms/link-target.ts +1 -1
  138. package/src/abstract-document/atoms/text-run.ts +1 -0
  139. package/src/abstract-document/default-styles.ts +2 -2
  140. package/src/abstract-document/markdown/markdown.ts +11 -8
  141. package/src/abstract-document/markdown/types.ts +1 -1
  142. package/src/abstract-document/numberings/numbering-definition.ts +1 -1
  143. package/src/abstract-document/numberings/numbering-format.ts +1 -7
  144. package/src/abstract-document/numberings/numbering-level-definition.ts +1 -1
  145. package/src/abstract-document/page/master-page.ts +1 -1
  146. package/src/abstract-document/page/section.ts +2 -2
  147. package/src/abstract-document/primitives/image-resource.ts +1 -1
  148. package/src/abstract-document/primitives/layout-foundation-color.ts +4 -4
  149. package/src/abstract-document/primitives/layout-foundation.ts +1 -1
  150. package/src/abstract-document/primitives/point.ts +1 -1
  151. package/src/abstract-document/resources.ts +9 -8
  152. package/src/abstract-document/section-elements/group.ts +2 -2
  153. package/src/abstract-document/section-elements/page-break.ts +1 -1
  154. package/src/abstract-document/section-elements/paragraph.ts +4 -4
  155. package/src/abstract-document/section-elements/section-element.ts +1 -1
  156. package/src/abstract-document/section-elements/table.ts +2 -2
  157. package/src/abstract-document/styles/group-style.ts +1 -1
  158. package/src/abstract-document/styles/paragraph-style.ts +2 -2
  159. package/src/abstract-document/styles/table-cell-style.ts +1 -8
  160. package/src/abstract-document/styles/table-style.ts +2 -2
  161. package/src/abstract-document/styles/text-style.ts +20 -20
  162. package/src/abstract-document/table/table-cell.ts +1 -1
  163. package/src/abstract-document/table/table-row.ts +1 -1
  164. package/src/abstract-document-exporters/docx/string-utils.ts +1 -5
  165. package/src/abstract-document-exporters/docx/xml-writer.ts +1 -0
  166. package/src/abstract-document-exporters/docx2/render-image.ts +69 -57
  167. package/src/abstract-document-exporters/docx2/render.ts +104 -77
  168. package/src/abstract-document-exporters/pdf/font.ts +16 -15
  169. package/src/abstract-document-exporters/pdf/measure.ts +6 -3
  170. package/src/abstract-document-exporters/pdf/paginate.ts +11 -6
  171. package/src/abstract-document-exporters/pdf/pre-process.ts +3 -3
  172. package/src/abstract-document-exporters/pdf/render-image.ts +10 -12
  173. package/src/abstract-document-exporters/pdf/render.ts +5 -2
  174. package/src/abstract-document-exporters/pdf/std-fonts.ts +1 -1
  175. package/src/abstract-document-exporters/pdf/textRunRow.ts +108 -74
  176. package/src/abstract-document-exporters/pdf/update-refs.ts +2 -2
  177. package/src/abstract-document-exporters/shared/get_resources.ts +10 -9
  178. package/src/abstract-document-jsx/index.ts +1 -1
  179. package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +47 -46
  180. package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +118 -114
  181. package/src/abstract-document-xml/abstract-doc-of-xml/custom-elements.tsx +4 -13
  182. package/src/abstract-document-xml/xsd-template/custom-elements.ts +0 -1
  183. package/src/abstract-document-xml/xsd-template/styles.ts +1 -1
  184. package/src/custom_typings/pdfkit-standard-fonts/index.d.ts +0 -1
  185. package/lib/abstract-document/table/text-row.d.ts +0 -2
  186. package/lib/abstract-document/table/text-row.d.ts.map +0 -1
  187. package/lib/abstract-document/table/text-row.js +0 -2
  188. package/lib/abstract-document/table/text-row.js.map +0 -1
  189. package/lib/abstract-document-exporters/docx/docx-document-renderer.d.ts +0 -2
  190. package/lib/abstract-document-exporters/docx/docx-document-renderer.d.ts.map +0 -1
  191. package/lib/abstract-document-exporters/docx/docx-document-renderer.js +0 -1085
  192. package/lib/abstract-document-exporters/docx/docx-document-renderer.js.map +0 -1
  193. package/src/abstract-document/table/text-row.ts +0 -0
  194. package/src/abstract-document-exporters/docx/docx-document-renderer.ts +0 -1084
@@ -1,12 +1,12 @@
1
1
  import unified from "unified";
2
2
  import remarkParse from "remark-parse";
3
3
  import remarkSubSuper from "remark-sub-super";
4
- import { SectionElement } from "../section-elements/section-element.js";
4
+ import type { SectionElement } from "../section-elements/section-element.js";
5
5
  import * as Paragraph from "../section-elements/paragraph.js";
6
- import * as Atom from "../atoms/atom.js";
7
- import * as TextRun from "../atoms/text-run.js";
6
+ import type * as Atom from "../atoms/atom.js";
7
+ import type * as TextRun from "../atoms/text-run.js";
8
8
  import * as Group from "../section-elements/group.js";
9
- import { AstElements, MarkDownProcessData, AstRoot } from "./types.js";
9
+ import type { AstElements, MarkDownProcessData, AstRoot } from "./types.js";
10
10
 
11
11
  export interface MarkdownProps {
12
12
  readonly text: string;
@@ -26,14 +26,14 @@ function preProcessMarkdownAst(
26
26
  atoms: Array<Atom.Atom>,
27
27
  paragraphs: Array<Paragraph.Paragraph>,
28
28
  d: number,
29
- listItemParams: ListItemParams | undefined = undefined
29
+ listItemParams?: ListItemParams
30
30
  ): MarkDownProcessData {
31
31
  if (ast.type === "text" || ast.type === "break") {
32
32
  return { atoms, paragraphs };
33
33
  } // Need to convice TS that we never go below this line with a Str element.
34
34
 
35
35
  if (ast.children) {
36
- ast.children.forEach((child, i) => {
36
+ ast.children.forEach((child) => {
37
37
  let style = styles.slice(); // create a new copy of styles
38
38
  switch (ast.type) {
39
39
  case "heading":
@@ -103,7 +103,7 @@ function preProcessMarkdownAst(
103
103
  styleName: style[style.length - 1],
104
104
  nestedStyleNames: style,
105
105
  textProperties: {},
106
- } as TextRun.TextRun)
106
+ }) as TextRun.TextRun
107
107
  )
108
108
  );
109
109
  }
@@ -115,7 +115,10 @@ function preProcessMarkdownAst(
115
115
 
116
116
  export function create({ text, keepTogetherSections }: MarkdownProps): SectionElement {
117
117
  //markdown require newlines to have two spaces before them (this fixex alignment issues when using linebreaks for rows with single text runs)
118
- const newlineReplacedText = text.replaceAll(/ \n/g, "\n").replaceAll(/ {2}\n/g, "\n").replaceAll(/\n/g, " \n\r");
118
+ const newlineReplacedText = text
119
+ .replaceAll(/ \n/g, "\n")
120
+ .replaceAll(/ {2}\n/g, "\n")
121
+ .replaceAll(/\n/g, " \n\r");
119
122
 
120
123
  const ast = unified().use(remarkParse, { commonmark: true }).use(remarkSubSuper).parse(newlineReplacedText);
121
124
  const { paragraphs } = preProcessMarkdownAst(ast as AstRoot, [], [], [], 0);
@@ -1,4 +1,4 @@
1
- import * as AD from "../../abstract-document/index.js";
1
+ import type * as AD from "../../abstract-document/index.js";
2
2
 
3
3
  export type AstChildElements =
4
4
  | AstHeading
@@ -1,4 +1,4 @@
1
- import { NumberingLevelDefinition } from "./numbering-level-definition.js";
1
+ import type { NumberingLevelDefinition } from "./numbering-level-definition.js";
2
2
 
3
3
  export interface NumberingDefinition {
4
4
  readonly levels: NumberingLevelDefinition[];
@@ -1,7 +1 @@
1
- export type NumberingFormat =
2
- | "Decimal"
3
- | "DecimalZero"
4
- | "LowerLetter"
5
- | "UpperLetter"
6
- | "LowerRoman"
7
- | "UpperRoman";
1
+ export type NumberingFormat = "Decimal" | "DecimalZero" | "LowerLetter" | "UpperLetter" | "LowerRoman" | "UpperRoman";
@@ -1,5 +1,5 @@
1
1
  import * as TextStyle from "../styles/text-style.js";
2
- import { NumberingFormat } from "./numbering-format.js";
2
+ import type { NumberingFormat } from "./numbering-format.js";
3
3
 
4
4
  export interface NumberingLevelDefinition {
5
5
  readonly level: number;
@@ -1,5 +1,5 @@
1
1
  import * as PageStyle from "../styles/page-style.js";
2
- import * as SectionElement from "../section-elements/section-element.js";
2
+ import type * as SectionElement from "../section-elements/section-element.js";
3
3
 
4
4
  export interface MasterPage {
5
5
  readonly style: PageStyle.PageStyle;
@@ -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
 
@@ -30,9 +30,9 @@ export function overrideWith(
30
30
  const a = overrider;
31
31
  const b = toOverride;
32
32
  return create({
33
- top: (a?.top ?? b?.top),
34
- bottom: (a?.bottom ?? b?.bottom),
35
- left: (a?.left ?? b?.left),
36
- right: (a?.right ?? b?.right),
33
+ top: a?.top ?? b?.top,
34
+ bottom: a?.bottom ?? b?.bottom,
35
+ left: a?.left ?? b?.left,
36
+ right: a?.right ?? b?.right,
37
37
  });
38
38
  }
@@ -10,7 +10,7 @@ export function create(props?: LayoutFoundation): LayoutFoundation {
10
10
  top: props?.top,
11
11
  bottom: props?.bottom,
12
12
  left: props?.left,
13
- right: props?.right
13
+ right: props?.right,
14
14
  };
15
15
  }
16
16
 
@@ -6,6 +6,6 @@ export interface Point {
6
6
  export function create(x: number, y: number): Point {
7
7
  return {
8
8
  x: x,
9
- y: y
9
+ y: y,
10
10
  };
11
11
  }
@@ -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";
@@ -20,7 +20,7 @@ export type ParagraphProps = Resources & {
20
20
  };
21
21
 
22
22
  export function create(props?: ParagraphProps, children?: ReadonlyArray<Atom>): Paragraph {
23
- const { styleName = "", style = ParagraphStyle.create(), numbering = undefined, ...rest } = props || {};
23
+ const { styleName = "", style = ParagraphStyle.create(), numbering, ...rest } = props || {};
24
24
  return {
25
25
  type: sectionType,
26
26
  styleName,
@@ -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
 
@@ -21,7 +21,7 @@ export interface ParagraphStyleProps {
21
21
 
22
22
  export function create(props?: ParagraphStyleProps): ParagraphStyle {
23
23
  const {
24
- alignment = undefined,
24
+ alignment,
25
25
  margins = LayoutFoundation.create(),
26
26
  position = "relative",
27
27
  textStyle = TextStyle.create(),
@@ -23,14 +23,7 @@ export interface TableCellStyleProps {
23
23
  }
24
24
 
25
25
  export function create(props?: TableCellStyleProps): TableCellStyle {
26
- const {
27
- background = undefined,
28
- borders = undefined,
29
- borderColor = undefined,
30
- borderColors = undefined,
31
- padding = undefined,
32
- verticalAlignment = undefined,
33
- } = props || {};
26
+ const { background, borders, borderColor, borderColors, padding, verticalAlignment } = props || {};
34
27
  return {
35
28
  type: "TableCellStyle",
36
29
  background,
@@ -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
 
@@ -22,7 +22,7 @@ export interface TableStyleProps {
22
22
  export function create(props?: TableStyleProps): TableStyle {
23
23
  const {
24
24
  margins = LayoutFoundation.create(),
25
- alignment = undefined,
25
+ alignment,
26
26
  position = "relative",
27
27
  cellStyle = TableCellStyle.create(),
28
28
  } = props || {};
@@ -55,34 +55,34 @@ export interface TextStyleProps {
55
55
  export function create(props?: TextStyleProps): TextStyle {
56
56
  return {
57
57
  type: "TextStyle",
58
- ...(props || {}),
58
+ ...props,
59
59
  };
60
60
  }
61
61
 
62
62
  export function overrideWith(overrider: TextStyle | undefined, toOverride: TextStyle | undefined): TextStyle {
63
63
  const overriddenFontWeight: Partial<TextStyle> =
64
64
  overrider?.light ||
65
- overrider?.normal ||
66
- overrider?.mediumBold ||
67
- overrider?.bold ||
68
- overrider?.extraBold ||
69
- overrider?.fontWeight
65
+ overrider?.normal ||
66
+ overrider?.mediumBold ||
67
+ overrider?.bold ||
68
+ overrider?.extraBold ||
69
+ overrider?.fontWeight
70
70
  ? {
71
- light: overrider?.light,
72
- normal: overrider?.normal,
73
- mediumBold: overrider?.mediumBold,
74
- bold: overrider?.bold,
75
- extraBold: overrider?.extraBold,
76
- fontWeight: overrider?.fontWeight,
77
- }
71
+ light: overrider?.light,
72
+ normal: overrider?.normal,
73
+ mediumBold: overrider?.mediumBold,
74
+ bold: overrider?.bold,
75
+ extraBold: overrider?.extraBold,
76
+ fontWeight: overrider?.fontWeight,
77
+ }
78
78
  : {
79
- light: toOverride?.light,
80
- normal: toOverride?.normal,
81
- mediumBold: toOverride?.mediumBold,
82
- bold: toOverride?.bold,
83
- extraBold: toOverride?.extraBold,
84
- fontWeight: toOverride?.fontWeight,
85
- };
79
+ light: toOverride?.light,
80
+ normal: toOverride?.normal,
81
+ mediumBold: toOverride?.mediumBold,
82
+ bold: toOverride?.bold,
83
+ extraBold: toOverride?.extraBold,
84
+ fontWeight: toOverride?.fontWeight,
85
+ };
86
86
  const a: TextStyleProps = overrider || {};
87
87
  const b: TextStyleProps = toOverride || {};
88
88
  return create({
@@ -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>;
@@ -18,11 +18,7 @@ export function stringToUtf8ByteArray(str: string): Uint8Array {
18
18
  } else if (c < 2048) {
19
19
  out[p++] = (c >> 6) | 192;
20
20
  out[p++] = (c & 63) | 128;
21
- } else if (
22
- (c & 0xfc00) == 0xd800 &&
23
- i + 1 < str.length &&
24
- (str.charCodeAt(i + 1) & 0xfc00) == 0xdc00
25
- ) {
21
+ } else if ((c & 0xfc00) == 0xd800 && i + 1 < str.length && (str.charCodeAt(i + 1) & 0xfc00) == 0xdc00) {
26
22
  // Surrogate Pair
27
23
  c = 0x10000 + ((c & 0x03ff) << 10) + (str.charCodeAt(++i) & 0x03ff);
28
24
  out[p++] = (c >> 18) | 240;
@@ -327,6 +327,7 @@ export class XmlWriter {
327
327
  if (prefix) {
328
328
  return `${prefix}:${localName}`;
329
329
  } else {
330
+ // oxlint-disable-next-line typescript/no-unnecessary-template-expression
330
331
  return `${localName}`;
331
332
  }
332
333
  }
@@ -1,36 +1,27 @@
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"
33
- ? resources.imageResources?.[firstComp.data.url] ?? image.imageResource
23
+ !aImage.size.width && !aImage.size.height && firstComp?.type === "binaryimage" && firstComp.data.type === "url"
24
+ ? (resources.imageResources?.[firstComp.data.url] ?? image.imageResource)
34
25
  : image.imageResource;
35
26
 
36
27
  const rect = resourceRect(resource, {
@@ -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") {
@@ -297,34 +307,40 @@ function textComponentToSvg(component: AbstractImage.Text): string {
297
307
  component.horizontalGrowthDirection === "left"
298
308
  ? "end"
299
309
  : component.horizontalGrowthDirection === "uniform"
300
- ? "middle"
301
- : "start";
310
+ ? "middle"
311
+ : "start";
302
312
 
303
313
  const dominantBaseline =
304
314
  component.verticalGrowthDirection === "up"
305
315
  ? "text-after-edge"
306
316
  : component.verticalGrowthDirection === "uniform"
307
- ? "middle"
308
- : "text-before-edge";
309
-
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>`;
317
+ ? "middle"
318
+ : "text-before-edge";
319
+
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 {