abstract-image 3.3.2 → 3.3.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 +44 -38
- package/LICENSE +21 -21
- package/README.md +73 -73
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-ellipse.js +379 -379
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-group.js +123 -123
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-line.js +55 -55
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-polygon.js +89 -89
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-polyline.js +79 -79
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-rectangle.js +99 -99
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-text-growth-directions.js +135 -135
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-text.js +63 -63
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-ellipse.js +24 -24
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-empty-text.js +26 -26
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-group.js +31 -31
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-line.js +20 -20
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-polygon.js +34 -34
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-polyline.js +26 -26
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-rectangle.js +20 -20
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-text-growth-directions.js +59 -59
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-text.js +26 -26
- package/package.json +4 -2
- package/src/__stories__/react-svg-export/example-1.stories.tsx +54 -54
- package/src/__stories__/svg-export/example-1.stories.tsx +42 -42
- package/src/exporters/__tests__/dxf2d-export-image/export-test-def.ts +11 -11
- package/src/exporters/__tests__/dxf2d-export-image/export.test.tsx +13 -13
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-ellipse.ts +405 -405
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-group.ts +166 -166
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-line.ts +80 -80
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-polygon.ts +114 -114
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-polyline.ts +103 -103
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-rectangle.ts +125 -125
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-text-growth-directions.ts +214 -214
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-text.ts +97 -97
- package/src/exporters/__tests__/eps-export-image/export-test-def.ts +11 -11
- package/src/exporters/__tests__/eps-export-image/export.test.tsx +13 -13
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-ellipse.ts +50 -50
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-empty-text.ts +60 -60
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-group.ts +74 -74
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-line.ts +45 -45
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-polygon.ts +65 -65
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-polyline.ts +58 -58
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-rectangle.ts +46 -46
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-text-growth-directions.ts +138 -138
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-text.ts +60 -60
- package/src/exporters/__tests__/exception/png-unsupported.test.tsx +25 -25
- package/src/exporters/__tests__/exception/react-svg-direction-exception.test.tsx +65 -65
- package/src/exporters/__tests__/exception/svg-direction-exception.test.tsx +65 -65
- package/src/exporters/__tests__/png-export-image/export-test-def.ts +11 -11
- package/src/exporters/__tests__/png-export-image/export.test.tsx +13 -13
- package/src/exporters/__tests__/png-export-image/test-defs/png-createPNG.tsx +26 -26
- package/src/exporters/__tests__/react-svg-export-image/export-test-def.tsx +13 -13
- package/src/exporters/__tests__/react-svg-export-image/export.test.tsx +13 -13
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-binary-png.tsx +26 -26
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-binary-url.tsx +26 -26
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-binary.tsx +25 -25
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-callback.tsx +60 -60
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-ellipse.tsx +28 -28
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-empty-text.tsx +35 -35
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-group.tsx +44 -44
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-line.tsx +26 -26
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-polygon.tsx +32 -32
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-polyline.tsx +33 -33
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-rectangle.tsx +27 -27
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-subimage.tsx +36 -36
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-text-bold.tsx +50 -50
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-text-growth-directions.tsx +80 -80
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-text-italic.tsx +65 -65
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-text-sub.tsx +35 -35
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-text.tsx +35 -35
- package/src/exporters/__tests__/svg-export-image/export-test-def.ts +11 -11
- package/src/exporters/__tests__/svg-export-image/export.test.tsx +13 -13
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-binary.tsx +25 -25
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-ellipse.ts +27 -27
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-empty-text.ts +34 -34
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-group.ts +44 -44
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-line.ts +26 -26
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-polygon.ts +32 -32
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-polyline.ts +33 -33
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-rectangle.ts +27 -27
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-text-bold.ts +50 -50
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-text-growth-directions.ts +80 -80
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-text-italic.ts +65 -65
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-text.ts +35 -35
- package/src/exporters/dxf2d-export-image.ts +218 -218
- package/src/exporters/eps-export-image.ts +154 -154
- package/src/exporters/index.ts +3 -3
- package/src/exporters/png-export-image.ts +12 -12
- package/src/exporters/react-svg-export-image.tsx +315 -315
- package/src/exporters/svg-export-image.ts +309 -309
- package/src/index.ts +11 -11
- package/src/model/__tests__/color/export-test-def.ts +13 -13
- package/src/model/__tests__/color/export.test.tsx +14 -14
- package/src/model/__tests__/color/test-defs/color-from-string.ts +46 -46
- package/src/model/__tests__/color/test-defs/color-to-string.ts +35 -35
- package/src/model/__tests__/color/test-defs/color-undefined-2.ts +8 -8
- package/src/model/__tests__/color/test-defs/color-undefined.ts +8 -8
- package/src/model/abstract-image.ts +25 -25
- package/src/model/color.ts +52 -52
- package/src/model/component.ts +279 -279
- package/src/model/index.ts +5 -5
- package/src/model/point.ts +11 -11
- package/src/model/size.ts +11 -11
- package/lib/exporters/__tests__/svg-export-image.test.d.ts +0 -2
- package/lib/exporters/__tests__/svg-export-image.test.d.ts.map +0 -1
- package/lib/exporters/__tests__/svg-export-image.test.js +0 -35
- package/lib/exporters/__tests__/svg-export-image.test.js.map +0 -1
package/src/model/component.ts
CHANGED
|
@@ -1,279 +1,279 @@
|
|
|
1
|
-
import * as Point from "./point";
|
|
2
|
-
import * as Color from "./color";
|
|
3
|
-
import * as AbstractImage from "./abstract-image";
|
|
4
|
-
|
|
5
|
-
export type Component = BinaryImage | Ellipse | Line | PolyLine | Polygon | Rectangle | Text | SubImage | Group;
|
|
6
|
-
|
|
7
|
-
export interface Group {
|
|
8
|
-
readonly type: "group";
|
|
9
|
-
readonly name: string;
|
|
10
|
-
readonly children: Array<Component>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function createGroup(name: string, children: Array<Component>): Group {
|
|
14
|
-
return {
|
|
15
|
-
type: "group",
|
|
16
|
-
name: name,
|
|
17
|
-
children: children,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Embed a foreign binary image in any suported format.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
export type BinaryFormat = "svg" | "png";
|
|
26
|
-
|
|
27
|
-
export interface BinaryImage {
|
|
28
|
-
readonly type: "binaryimage";
|
|
29
|
-
readonly topLeft: Point.Point;
|
|
30
|
-
readonly bottomRight: Point.Point;
|
|
31
|
-
readonly format: BinaryFormat;
|
|
32
|
-
readonly data: ImageData;
|
|
33
|
-
readonly id: string | undefined;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type ImageData = ImageBytes | ImageUrl;
|
|
37
|
-
|
|
38
|
-
export interface ImageBytes {
|
|
39
|
-
readonly type: "bytes";
|
|
40
|
-
readonly bytes: Uint8Array;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface ImageUrl {
|
|
44
|
-
readonly type: "url";
|
|
45
|
-
readonly url: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function createBinaryImage(
|
|
49
|
-
topLeft: Point.Point,
|
|
50
|
-
bottomRight: Point.Point,
|
|
51
|
-
format: BinaryFormat,
|
|
52
|
-
data: ImageData,
|
|
53
|
-
id?: string
|
|
54
|
-
): BinaryImage {
|
|
55
|
-
return {
|
|
56
|
-
type: "binaryimage",
|
|
57
|
-
topLeft: topLeft,
|
|
58
|
-
bottomRight: bottomRight,
|
|
59
|
-
format: format,
|
|
60
|
-
data: data,
|
|
61
|
-
id: id,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface Ellipse {
|
|
66
|
-
readonly type: "ellipse";
|
|
67
|
-
readonly topLeft: Point.Point;
|
|
68
|
-
readonly bottomRight: Point.Point;
|
|
69
|
-
readonly strokeColor: Color.Color;
|
|
70
|
-
readonly strokeThickness: number;
|
|
71
|
-
readonly fillColor: Color.Color;
|
|
72
|
-
readonly id: string | undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function createEllipse(
|
|
76
|
-
topLeft: Point.Point,
|
|
77
|
-
bottomRight: Point.Point,
|
|
78
|
-
strokeColor: Color.Color,
|
|
79
|
-
strokeThickness: number,
|
|
80
|
-
fillColor: Color.Color,
|
|
81
|
-
id?: string
|
|
82
|
-
): Ellipse {
|
|
83
|
-
return {
|
|
84
|
-
type: "ellipse",
|
|
85
|
-
topLeft: topLeft,
|
|
86
|
-
bottomRight: bottomRight,
|
|
87
|
-
strokeColor: strokeColor,
|
|
88
|
-
strokeThickness: strokeThickness,
|
|
89
|
-
fillColor: fillColor,
|
|
90
|
-
id: id,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface Line {
|
|
95
|
-
readonly type: "line";
|
|
96
|
-
readonly start: Point.Point;
|
|
97
|
-
readonly end: Point.Point;
|
|
98
|
-
readonly strokeColor: Color.Color;
|
|
99
|
-
readonly strokeThickness: number;
|
|
100
|
-
readonly id: string | undefined;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function createLine(
|
|
104
|
-
start: Point.Point,
|
|
105
|
-
end: Point.Point,
|
|
106
|
-
strokeColor: Color.Color,
|
|
107
|
-
strokeThickness: number,
|
|
108
|
-
id?: string
|
|
109
|
-
): Line {
|
|
110
|
-
return {
|
|
111
|
-
type: "line",
|
|
112
|
-
start: start,
|
|
113
|
-
end: end,
|
|
114
|
-
strokeColor: strokeColor,
|
|
115
|
-
strokeThickness: strokeThickness,
|
|
116
|
-
id: id,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface PolyLine {
|
|
121
|
-
readonly type: "polyline";
|
|
122
|
-
readonly points: Array<Point.Point>;
|
|
123
|
-
readonly strokeColor: Color.Color;
|
|
124
|
-
readonly strokeThickness: number;
|
|
125
|
-
readonly id: string | undefined;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function createPolyLine(
|
|
129
|
-
points: Array<Point.Point>,
|
|
130
|
-
strokeColor: Color.Color,
|
|
131
|
-
strokeThickness: number,
|
|
132
|
-
id?: string
|
|
133
|
-
): PolyLine {
|
|
134
|
-
return {
|
|
135
|
-
type: "polyline",
|
|
136
|
-
points: points,
|
|
137
|
-
strokeColor: strokeColor,
|
|
138
|
-
strokeThickness: strokeThickness,
|
|
139
|
-
id: id,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export interface Polygon {
|
|
144
|
-
readonly type: "polygon";
|
|
145
|
-
readonly points: Array<Point.Point>;
|
|
146
|
-
readonly strokeColor: Color.Color;
|
|
147
|
-
readonly strokeThickness: number;
|
|
148
|
-
readonly fillColor: Color.Color;
|
|
149
|
-
readonly id: string | undefined;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function createPolygon(
|
|
153
|
-
points: Array<Point.Point>,
|
|
154
|
-
strokeColor: Color.Color,
|
|
155
|
-
strokeThickness: number,
|
|
156
|
-
fillColor: Color.Color,
|
|
157
|
-
id?: string
|
|
158
|
-
): Polygon {
|
|
159
|
-
return {
|
|
160
|
-
type: "polygon",
|
|
161
|
-
points: points,
|
|
162
|
-
strokeColor: strokeColor,
|
|
163
|
-
strokeThickness: strokeThickness,
|
|
164
|
-
fillColor: fillColor,
|
|
165
|
-
id: id,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export interface Rectangle {
|
|
170
|
-
readonly type: "rectangle";
|
|
171
|
-
readonly topLeft: Point.Point;
|
|
172
|
-
readonly bottomRight: Point.Point;
|
|
173
|
-
readonly strokeColor: Color.Color;
|
|
174
|
-
readonly strokeThickness: number;
|
|
175
|
-
readonly fillColor: Color.Color;
|
|
176
|
-
readonly id: string | undefined;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export function createRectangle(
|
|
180
|
-
topLeft: Point.Point,
|
|
181
|
-
bottomRight: Point.Point,
|
|
182
|
-
strokeColor: Color.Color,
|
|
183
|
-
strokeThickness: number,
|
|
184
|
-
fillColor: Color.Color,
|
|
185
|
-
id?: string
|
|
186
|
-
): Rectangle {
|
|
187
|
-
return {
|
|
188
|
-
type: "rectangle",
|
|
189
|
-
topLeft: topLeft,
|
|
190
|
-
bottomRight: bottomRight,
|
|
191
|
-
strokeColor: strokeColor,
|
|
192
|
-
strokeThickness: strokeThickness,
|
|
193
|
-
fillColor: fillColor,
|
|
194
|
-
id: id,
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export function corners(rectangle: Rectangle): Array<Point.Point> {
|
|
199
|
-
return [
|
|
200
|
-
rectangle.topLeft,
|
|
201
|
-
Point.createPoint(rectangle.bottomRight.x, rectangle.topLeft.y),
|
|
202
|
-
rectangle.bottomRight,
|
|
203
|
-
Point.createPoint(rectangle.topLeft.x, rectangle.bottomRight.y),
|
|
204
|
-
];
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export type AbstractFontWeight = "normal" | "mediumBold" | "bold";
|
|
208
|
-
|
|
209
|
-
export type TextAlignment = "left" | "center" | "right";
|
|
210
|
-
|
|
211
|
-
export type GrowthDirection = "up" | "down" | "uniform" | "left" | "right";
|
|
212
|
-
|
|
213
|
-
export interface Text {
|
|
214
|
-
readonly type: "text";
|
|
215
|
-
readonly position: Point.Point;
|
|
216
|
-
readonly text: string;
|
|
217
|
-
readonly fontFamily: string;
|
|
218
|
-
readonly fontSize: number;
|
|
219
|
-
readonly textColor: Color.Color;
|
|
220
|
-
readonly fontWeight: AbstractFontWeight;
|
|
221
|
-
readonly clockwiseRotationDegrees: number;
|
|
222
|
-
readonly textAlignment: TextAlignment;
|
|
223
|
-
readonly horizontalGrowthDirection: GrowthDirection;
|
|
224
|
-
readonly verticalGrowthDirection: GrowthDirection;
|
|
225
|
-
readonly strokeThickness: number;
|
|
226
|
-
readonly strokeColor: Color.Color;
|
|
227
|
-
readonly italic: boolean;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export function createText(
|
|
231
|
-
position: Point.Point,
|
|
232
|
-
text: string,
|
|
233
|
-
fontFamily: string,
|
|
234
|
-
fontSize: number,
|
|
235
|
-
textColor: Color.Color,
|
|
236
|
-
fontWeight: AbstractFontWeight,
|
|
237
|
-
clockwiseRotationDegrees: number,
|
|
238
|
-
textAlignment: TextAlignment,
|
|
239
|
-
horizontalGrowthDirection: GrowthDirection,
|
|
240
|
-
verticalGrowthDirection: GrowthDirection,
|
|
241
|
-
strokeThickness: number,
|
|
242
|
-
strokeColor: Color.Color,
|
|
243
|
-
italic: boolean
|
|
244
|
-
): Text {
|
|
245
|
-
return {
|
|
246
|
-
type: "text",
|
|
247
|
-
position: position,
|
|
248
|
-
text: text,
|
|
249
|
-
fontFamily: fontFamily,
|
|
250
|
-
fontSize: fontSize,
|
|
251
|
-
textColor: textColor,
|
|
252
|
-
fontWeight: fontWeight,
|
|
253
|
-
clockwiseRotationDegrees: clockwiseRotationDegrees,
|
|
254
|
-
textAlignment: textAlignment,
|
|
255
|
-
horizontalGrowthDirection: horizontalGrowthDirection,
|
|
256
|
-
verticalGrowthDirection: verticalGrowthDirection,
|
|
257
|
-
strokeThickness: strokeThickness,
|
|
258
|
-
strokeColor: strokeColor,
|
|
259
|
-
italic: italic,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export interface SubImage {
|
|
264
|
-
readonly type: "subimage";
|
|
265
|
-
readonly topLeft: Point.Point;
|
|
266
|
-
readonly image: Component;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export function createSubImage(topLeft: Point.Point, image: Component): SubImage {
|
|
270
|
-
return {
|
|
271
|
-
type: "subimage",
|
|
272
|
-
topLeft: topLeft,
|
|
273
|
-
image: image,
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
export function embedAbstractImage(topLeft: Point.Point, name: string, image: AbstractImage.AbstractImage): Component {
|
|
278
|
-
return createSubImage(topLeft, createGroup(name, image.components));
|
|
279
|
-
}
|
|
1
|
+
import * as Point from "./point";
|
|
2
|
+
import * as Color from "./color";
|
|
3
|
+
import * as AbstractImage from "./abstract-image";
|
|
4
|
+
|
|
5
|
+
export type Component = BinaryImage | Ellipse | Line | PolyLine | Polygon | Rectangle | Text | SubImage | Group;
|
|
6
|
+
|
|
7
|
+
export interface Group {
|
|
8
|
+
readonly type: "group";
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly children: Array<Component>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createGroup(name: string, children: Array<Component>): Group {
|
|
14
|
+
return {
|
|
15
|
+
type: "group",
|
|
16
|
+
name: name,
|
|
17
|
+
children: children,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Embed a foreign binary image in any suported format.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export type BinaryFormat = "svg" | "png";
|
|
26
|
+
|
|
27
|
+
export interface BinaryImage {
|
|
28
|
+
readonly type: "binaryimage";
|
|
29
|
+
readonly topLeft: Point.Point;
|
|
30
|
+
readonly bottomRight: Point.Point;
|
|
31
|
+
readonly format: BinaryFormat;
|
|
32
|
+
readonly data: ImageData;
|
|
33
|
+
readonly id: string | undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type ImageData = ImageBytes | ImageUrl;
|
|
37
|
+
|
|
38
|
+
export interface ImageBytes {
|
|
39
|
+
readonly type: "bytes";
|
|
40
|
+
readonly bytes: Uint8Array;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ImageUrl {
|
|
44
|
+
readonly type: "url";
|
|
45
|
+
readonly url: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createBinaryImage(
|
|
49
|
+
topLeft: Point.Point,
|
|
50
|
+
bottomRight: Point.Point,
|
|
51
|
+
format: BinaryFormat,
|
|
52
|
+
data: ImageData,
|
|
53
|
+
id?: string
|
|
54
|
+
): BinaryImage {
|
|
55
|
+
return {
|
|
56
|
+
type: "binaryimage",
|
|
57
|
+
topLeft: topLeft,
|
|
58
|
+
bottomRight: bottomRight,
|
|
59
|
+
format: format,
|
|
60
|
+
data: data,
|
|
61
|
+
id: id,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface Ellipse {
|
|
66
|
+
readonly type: "ellipse";
|
|
67
|
+
readonly topLeft: Point.Point;
|
|
68
|
+
readonly bottomRight: Point.Point;
|
|
69
|
+
readonly strokeColor: Color.Color;
|
|
70
|
+
readonly strokeThickness: number;
|
|
71
|
+
readonly fillColor: Color.Color;
|
|
72
|
+
readonly id: string | undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function createEllipse(
|
|
76
|
+
topLeft: Point.Point,
|
|
77
|
+
bottomRight: Point.Point,
|
|
78
|
+
strokeColor: Color.Color,
|
|
79
|
+
strokeThickness: number,
|
|
80
|
+
fillColor: Color.Color,
|
|
81
|
+
id?: string
|
|
82
|
+
): Ellipse {
|
|
83
|
+
return {
|
|
84
|
+
type: "ellipse",
|
|
85
|
+
topLeft: topLeft,
|
|
86
|
+
bottomRight: bottomRight,
|
|
87
|
+
strokeColor: strokeColor,
|
|
88
|
+
strokeThickness: strokeThickness,
|
|
89
|
+
fillColor: fillColor,
|
|
90
|
+
id: id,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface Line {
|
|
95
|
+
readonly type: "line";
|
|
96
|
+
readonly start: Point.Point;
|
|
97
|
+
readonly end: Point.Point;
|
|
98
|
+
readonly strokeColor: Color.Color;
|
|
99
|
+
readonly strokeThickness: number;
|
|
100
|
+
readonly id: string | undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function createLine(
|
|
104
|
+
start: Point.Point,
|
|
105
|
+
end: Point.Point,
|
|
106
|
+
strokeColor: Color.Color,
|
|
107
|
+
strokeThickness: number,
|
|
108
|
+
id?: string
|
|
109
|
+
): Line {
|
|
110
|
+
return {
|
|
111
|
+
type: "line",
|
|
112
|
+
start: start,
|
|
113
|
+
end: end,
|
|
114
|
+
strokeColor: strokeColor,
|
|
115
|
+
strokeThickness: strokeThickness,
|
|
116
|
+
id: id,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface PolyLine {
|
|
121
|
+
readonly type: "polyline";
|
|
122
|
+
readonly points: Array<Point.Point>;
|
|
123
|
+
readonly strokeColor: Color.Color;
|
|
124
|
+
readonly strokeThickness: number;
|
|
125
|
+
readonly id: string | undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function createPolyLine(
|
|
129
|
+
points: Array<Point.Point>,
|
|
130
|
+
strokeColor: Color.Color,
|
|
131
|
+
strokeThickness: number,
|
|
132
|
+
id?: string
|
|
133
|
+
): PolyLine {
|
|
134
|
+
return {
|
|
135
|
+
type: "polyline",
|
|
136
|
+
points: points,
|
|
137
|
+
strokeColor: strokeColor,
|
|
138
|
+
strokeThickness: strokeThickness,
|
|
139
|
+
id: id,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface Polygon {
|
|
144
|
+
readonly type: "polygon";
|
|
145
|
+
readonly points: Array<Point.Point>;
|
|
146
|
+
readonly strokeColor: Color.Color;
|
|
147
|
+
readonly strokeThickness: number;
|
|
148
|
+
readonly fillColor: Color.Color;
|
|
149
|
+
readonly id: string | undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function createPolygon(
|
|
153
|
+
points: Array<Point.Point>,
|
|
154
|
+
strokeColor: Color.Color,
|
|
155
|
+
strokeThickness: number,
|
|
156
|
+
fillColor: Color.Color,
|
|
157
|
+
id?: string
|
|
158
|
+
): Polygon {
|
|
159
|
+
return {
|
|
160
|
+
type: "polygon",
|
|
161
|
+
points: points,
|
|
162
|
+
strokeColor: strokeColor,
|
|
163
|
+
strokeThickness: strokeThickness,
|
|
164
|
+
fillColor: fillColor,
|
|
165
|
+
id: id,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface Rectangle {
|
|
170
|
+
readonly type: "rectangle";
|
|
171
|
+
readonly topLeft: Point.Point;
|
|
172
|
+
readonly bottomRight: Point.Point;
|
|
173
|
+
readonly strokeColor: Color.Color;
|
|
174
|
+
readonly strokeThickness: number;
|
|
175
|
+
readonly fillColor: Color.Color;
|
|
176
|
+
readonly id: string | undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function createRectangle(
|
|
180
|
+
topLeft: Point.Point,
|
|
181
|
+
bottomRight: Point.Point,
|
|
182
|
+
strokeColor: Color.Color,
|
|
183
|
+
strokeThickness: number,
|
|
184
|
+
fillColor: Color.Color,
|
|
185
|
+
id?: string
|
|
186
|
+
): Rectangle {
|
|
187
|
+
return {
|
|
188
|
+
type: "rectangle",
|
|
189
|
+
topLeft: topLeft,
|
|
190
|
+
bottomRight: bottomRight,
|
|
191
|
+
strokeColor: strokeColor,
|
|
192
|
+
strokeThickness: strokeThickness,
|
|
193
|
+
fillColor: fillColor,
|
|
194
|
+
id: id,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function corners(rectangle: Rectangle): Array<Point.Point> {
|
|
199
|
+
return [
|
|
200
|
+
rectangle.topLeft,
|
|
201
|
+
Point.createPoint(rectangle.bottomRight.x, rectangle.topLeft.y),
|
|
202
|
+
rectangle.bottomRight,
|
|
203
|
+
Point.createPoint(rectangle.topLeft.x, rectangle.bottomRight.y),
|
|
204
|
+
];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export type AbstractFontWeight = "normal" | "mediumBold" | "bold";
|
|
208
|
+
|
|
209
|
+
export type TextAlignment = "left" | "center" | "right";
|
|
210
|
+
|
|
211
|
+
export type GrowthDirection = "up" | "down" | "uniform" | "left" | "right";
|
|
212
|
+
|
|
213
|
+
export interface Text {
|
|
214
|
+
readonly type: "text";
|
|
215
|
+
readonly position: Point.Point;
|
|
216
|
+
readonly text: string;
|
|
217
|
+
readonly fontFamily: string;
|
|
218
|
+
readonly fontSize: number;
|
|
219
|
+
readonly textColor: Color.Color;
|
|
220
|
+
readonly fontWeight: AbstractFontWeight;
|
|
221
|
+
readonly clockwiseRotationDegrees: number;
|
|
222
|
+
readonly textAlignment: TextAlignment;
|
|
223
|
+
readonly horizontalGrowthDirection: GrowthDirection;
|
|
224
|
+
readonly verticalGrowthDirection: GrowthDirection;
|
|
225
|
+
readonly strokeThickness: number;
|
|
226
|
+
readonly strokeColor: Color.Color;
|
|
227
|
+
readonly italic: boolean;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function createText(
|
|
231
|
+
position: Point.Point,
|
|
232
|
+
text: string,
|
|
233
|
+
fontFamily: string,
|
|
234
|
+
fontSize: number,
|
|
235
|
+
textColor: Color.Color,
|
|
236
|
+
fontWeight: AbstractFontWeight,
|
|
237
|
+
clockwiseRotationDegrees: number,
|
|
238
|
+
textAlignment: TextAlignment,
|
|
239
|
+
horizontalGrowthDirection: GrowthDirection,
|
|
240
|
+
verticalGrowthDirection: GrowthDirection,
|
|
241
|
+
strokeThickness: number,
|
|
242
|
+
strokeColor: Color.Color,
|
|
243
|
+
italic: boolean
|
|
244
|
+
): Text {
|
|
245
|
+
return {
|
|
246
|
+
type: "text",
|
|
247
|
+
position: position,
|
|
248
|
+
text: text,
|
|
249
|
+
fontFamily: fontFamily,
|
|
250
|
+
fontSize: fontSize,
|
|
251
|
+
textColor: textColor,
|
|
252
|
+
fontWeight: fontWeight,
|
|
253
|
+
clockwiseRotationDegrees: clockwiseRotationDegrees,
|
|
254
|
+
textAlignment: textAlignment,
|
|
255
|
+
horizontalGrowthDirection: horizontalGrowthDirection,
|
|
256
|
+
verticalGrowthDirection: verticalGrowthDirection,
|
|
257
|
+
strokeThickness: strokeThickness,
|
|
258
|
+
strokeColor: strokeColor,
|
|
259
|
+
italic: italic,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface SubImage {
|
|
264
|
+
readonly type: "subimage";
|
|
265
|
+
readonly topLeft: Point.Point;
|
|
266
|
+
readonly image: Component;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function createSubImage(topLeft: Point.Point, image: Component): SubImage {
|
|
270
|
+
return {
|
|
271
|
+
type: "subimage",
|
|
272
|
+
topLeft: topLeft,
|
|
273
|
+
image: image,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function embedAbstractImage(topLeft: Point.Point, name: string, image: AbstractImage.AbstractImage): Component {
|
|
278
|
+
return createSubImage(topLeft, createGroup(name, image.components));
|
|
279
|
+
}
|
package/src/model/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from "./abstract-image";
|
|
2
|
-
export * from "./color";
|
|
3
|
-
export * from "./component";
|
|
4
|
-
export * from "./point";
|
|
5
|
-
export * from "./size";
|
|
1
|
+
export * from "./abstract-image";
|
|
2
|
+
export * from "./color";
|
|
3
|
+
export * from "./component";
|
|
4
|
+
export * from "./point";
|
|
5
|
+
export * from "./size";
|
package/src/model/point.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export interface Point {
|
|
2
|
-
readonly x: number;
|
|
3
|
-
readonly y: number;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function createPoint(x: number, y: number): Point {
|
|
7
|
-
return {
|
|
8
|
-
x: x,
|
|
9
|
-
y: y
|
|
10
|
-
};
|
|
11
|
-
}
|
|
1
|
+
export interface Point {
|
|
2
|
+
readonly x: number;
|
|
3
|
+
readonly y: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function createPoint(x: number, y: number): Point {
|
|
7
|
+
return {
|
|
8
|
+
x: x,
|
|
9
|
+
y: y
|
|
10
|
+
};
|
|
11
|
+
}
|
package/src/model/size.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export interface Size {
|
|
2
|
-
readonly width: number;
|
|
3
|
-
readonly height: number;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function createSize(width: number, height: number): Size {
|
|
7
|
-
return {
|
|
8
|
-
width: width,
|
|
9
|
-
height: height
|
|
10
|
-
};
|
|
11
|
-
}
|
|
1
|
+
export interface Size {
|
|
2
|
+
readonly width: number;
|
|
3
|
+
readonly height: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function createSize(width: number, height: number): Size {
|
|
7
|
+
return {
|
|
8
|
+
width: width,
|
|
9
|
+
height: height
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svg-export-image.test.d.ts","sourceRoot":"","sources":["../../../src/exporters/__tests__/svg-export-image.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
const AbstractImage = __importStar(require("../../../src/index"));
|
|
23
|
-
describe("svg export", () => {
|
|
24
|
-
it("doesnt throw exception and produces output", () => {
|
|
25
|
-
const components = [
|
|
26
|
-
AbstractImage.createLine(AbstractImage.createPoint(25, 25), AbstractImage.createPoint(80, 60), AbstractImage.black, 2),
|
|
27
|
-
AbstractImage.createRectangle(AbstractImage.createPoint(10, 50), AbstractImage.createPoint(50, 60), AbstractImage.blue, 2, AbstractImage.red),
|
|
28
|
-
];
|
|
29
|
-
const image = AbstractImage.createAbstractImage(AbstractImage.createPoint(0, 0), AbstractImage.createSize(400, 400), AbstractImage.white, components);
|
|
30
|
-
const svg = AbstractImage.createSVG(image);
|
|
31
|
-
// console.log(svg);
|
|
32
|
-
expect(svg !== "").toEqual(true);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
//# sourceMappingURL=svg-export-image.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svg-export-image.test.js","sourceRoot":"","sources":["../../../src/exporters/__tests__/svg-export-image.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,kEAAoD;AAEpD,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,UAAU,GAAG;YACjB,aAAa,CAAC,UAAU,CACtB,aAAa,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,EACjC,aAAa,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,EACjC,aAAa,CAAC,KAAK,EACnB,CAAC,CACF;YACD,aAAa,CAAC,eAAe,CAC3B,aAAa,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,EACjC,aAAa,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,EACjC,aAAa,CAAC,IAAI,EAClB,CAAC,EACD,aAAa,CAAC,GAAG,CAClB;SACF,CAAC;QACF,MAAM,KAAK,GAAG,aAAa,CAAC,mBAAmB,CAC7C,aAAa,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAC/B,aAAa,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,EAClC,aAAa,CAAC,KAAK,EACnB,UAAU,CACX,CAAC;QACF,MAAM,GAAG,GAAG,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC3C,oBAAoB;QACpB,MAAM,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|