abstract-document 19.3.0 → 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 +14 -1
- 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 +3 -4
- package/lib/abstract-document-exporters/pdf/render.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.js +12 -12
- 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 +14 -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 +13 -18
- 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,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;
|
|
@@ -33,7 +33,7 @@ function preProcessMarkdownAst(
|
|
|
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
|
|
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":
|
|
@@ -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
|
|
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,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,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 {
|