abstract-image 11.2.13 → 11.2.17

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 (32) hide show
  1. package/lib/dynamic-image/components.d.ts +2 -0
  2. package/lib/dynamic-image/components.d.ts.map +1 -0
  3. package/lib/dynamic-image/components.js +88 -0
  4. package/lib/dynamic-image/components.js.map +1 -0
  5. package/lib/dynamic-image/dynamic-image.d.ts +2 -12
  6. package/lib/dynamic-image/dynamic-image.d.ts.map +1 -1
  7. package/lib/dynamic-image/dynamic-image.js +17 -172
  8. package/lib/dynamic-image/dynamic-image.js.map +1 -1
  9. package/lib/dynamic-image/index.d.ts +1 -0
  10. package/lib/dynamic-image/index.d.ts.map +1 -1
  11. package/lib/dynamic-image/index.js +3 -0
  12. package/lib/dynamic-image/index.js.map +1 -1
  13. package/lib/dynamic-image/schema.d.ts +236 -0
  14. package/lib/dynamic-image/schema.d.ts.map +1 -0
  15. package/lib/dynamic-image/schema.js +239 -0
  16. package/lib/dynamic-image/schema.js.map +1 -0
  17. package/lib/dynamic-image/utils.d.ts +2 -0
  18. package/lib/dynamic-image/utils.d.ts.map +1 -0
  19. package/lib/dynamic-image/utils.js +56 -0
  20. package/lib/dynamic-image/utils.js.map +1 -0
  21. package/package.json +5 -3
  22. package/src/dynamic-image/components.ts +163 -0
  23. package/src/dynamic-image/dynamic-image.ts +25 -201
  24. package/src/dynamic-image/index.ts +1 -0
  25. package/src/dynamic-image/schema.ts +245 -0
  26. package/src/dynamic-image/utils.ts +62 -0
  27. package/lib/dynamic-image/dynamic-image-xsd.d.ts +0 -2
  28. package/lib/dynamic-image/dynamic-image-xsd.d.ts.map +0 -1
  29. package/lib/dynamic-image/dynamic-image-xsd.js +0 -188
  30. package/lib/dynamic-image/dynamic-image-xsd.js.map +0 -1
  31. package/src/dynamic-image/dynamic-image-xsd.ts +0 -184
  32. package/src/dynamic-image/dynamic-image-xsd.xml +0 -183
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.baseSchema = void 0;
4
+ exports.baseSchema = {
5
+ elements: {
6
+ AbstractImage: {
7
+ description: "Root container — defines the image canvas and its coordinate system.",
8
+ props: {
9
+ width: {
10
+ type: "number",
11
+ required: true,
12
+ description: "Total width of the image canvas (in px).",
13
+ },
14
+ height: {
15
+ type: "number",
16
+ required: true,
17
+ description: "Total height of the image canvas (in px).",
18
+ },
19
+ },
20
+ allowedChildren: ["Image", "Text", "Rectangle", "Ellipse", "Line", "Polyline", "Polygon", "Group"],
21
+ },
22
+ Group: {
23
+ description: "Groups elements together.",
24
+ props: {},
25
+ allowedChildren: ["Image", "Text", "Rectangle", "Ellipse", "Line", "Polyline", "Polygon", "Group"],
26
+ },
27
+ Image: {
28
+ description: "Displays a raster image.",
29
+ props: {
30
+ src: {
31
+ type: "string",
32
+ required: true,
33
+ description: "Source of the image (URL or asset ID).",
34
+ },
35
+ x: {
36
+ type: "number",
37
+ description: "X position in pixels.",
38
+ },
39
+ y: {
40
+ type: "number",
41
+ description: "Y position in pixels.",
42
+ },
43
+ width: {
44
+ type: "number",
45
+ description: "Display width in pixels.",
46
+ },
47
+ height: {
48
+ type: "number",
49
+ description: "Display height in pixels.",
50
+ },
51
+ },
52
+ allowedChildren: [],
53
+ },
54
+ Ellipse: {
55
+ description: "Draws an ellipse using x, y, width, and height.",
56
+ props: {
57
+ x: {
58
+ type: "number",
59
+ description: "X coordinate of the top-left of the ellipse box.",
60
+ },
61
+ y: {
62
+ type: "number",
63
+ description: "Y coordinate of the top-left of the ellipse box.",
64
+ },
65
+ width: {
66
+ type: "number",
67
+ description: "Box width.",
68
+ },
69
+ height: {
70
+ type: "number",
71
+ description: "Box height.",
72
+ },
73
+ stroke: {
74
+ type: "string",
75
+ format: "color",
76
+ description: "Stroke color (CSS color string).",
77
+ },
78
+ strokeWidth: {
79
+ type: "number",
80
+ description: "Stroke width in pixels.",
81
+ },
82
+ fill: {
83
+ type: "string",
84
+ format: "color",
85
+ description: "Fill color (inside the ellipse).",
86
+ },
87
+ },
88
+ allowedChildren: [],
89
+ },
90
+ Line: {
91
+ description: "Draws a straight line between two points.",
92
+ props: {
93
+ x1: {
94
+ type: "number",
95
+ description: "X coordinate of the start point.",
96
+ },
97
+ y1: {
98
+ type: "number",
99
+ description: "Y coordinate of the start point.",
100
+ },
101
+ x2: {
102
+ type: "number",
103
+ description: "X coordinate of the end point.",
104
+ },
105
+ y2: {
106
+ type: "number",
107
+ description: "Y coordinate of the end point.",
108
+ },
109
+ stroke: {
110
+ type: "string",
111
+ format: "color",
112
+ description: "Stroke color of the line.",
113
+ },
114
+ strokeWidth: {
115
+ type: "number",
116
+ description: "Width of the stroke in px.",
117
+ },
118
+ },
119
+ allowedChildren: [],
120
+ },
121
+ Polyline: {
122
+ description: "A connected set of line segments (open shape).",
123
+ props: {
124
+ points: {
125
+ type: "string",
126
+ required: true,
127
+ description: "List of points: 'x0,y0 x1,y1 x2,y2'.",
128
+ },
129
+ stroke: {
130
+ type: "string",
131
+ format: "color",
132
+ description: "Stroke color.",
133
+ },
134
+ strokeWidth: {
135
+ type: "number",
136
+ description: "Stroke width in px.",
137
+ },
138
+ },
139
+ allowedChildren: [],
140
+ },
141
+ Polygon: {
142
+ description: "A closed polygon shape.",
143
+ props: {
144
+ points: {
145
+ type: "string",
146
+ required: true,
147
+ description: "List of vertex points: 'x0,y0 x1,y1 ...'.",
148
+ },
149
+ stroke: {
150
+ type: "string",
151
+ format: "color",
152
+ description: "Stroke color.",
153
+ },
154
+ strokeWidth: {
155
+ type: "number",
156
+ description: "Stroke width in px.",
157
+ },
158
+ fill: {
159
+ type: "string",
160
+ format: "color",
161
+ description: "Fill color of the polygon.",
162
+ },
163
+ },
164
+ allowedChildren: [],
165
+ },
166
+ Rectangle: {
167
+ description: "Draws a rectangle, optionally with rounded corners.",
168
+ props: {
169
+ x: {
170
+ type: "number",
171
+ description: "X position of the rectangle (top-left).",
172
+ },
173
+ y: {
174
+ type: "number",
175
+ description: "Y position of the rectangle (top-left).",
176
+ },
177
+ width: {
178
+ type: "number",
179
+ description: "Rectangle width in px.",
180
+ },
181
+ height: {
182
+ type: "number",
183
+ description: "Rectangle height in px.",
184
+ },
185
+ stroke: {
186
+ type: "string",
187
+ format: "color",
188
+ description: "Stroke color.",
189
+ },
190
+ strokeWidth: {
191
+ type: "number",
192
+ description: "Stroke width in px.",
193
+ },
194
+ fill: {
195
+ type: "string",
196
+ format: "color",
197
+ description: "Fill color of the rectangle.",
198
+ },
199
+ radius: {
200
+ type: "number",
201
+ description: "Corner radius in px (uniform).",
202
+ },
203
+ },
204
+ allowedChildren: [],
205
+ },
206
+ Text: {
207
+ description: "Renders a text element.",
208
+ props: {
209
+ x: {
210
+ type: "number",
211
+ description: "X position of the text anchor.",
212
+ },
213
+ y: {
214
+ type: "number",
215
+ description: "Y position of the text baseline.",
216
+ },
217
+ fontFamily: {
218
+ type: "string",
219
+ description: "Font family, e.g. 'Inter, system-ui'.",
220
+ },
221
+ fontSize: {
222
+ type: "number",
223
+ description: "Font size in pixels.",
224
+ },
225
+ fontWeight: {
226
+ type: "string",
227
+ description: "Font weight, e.g. 'bold', '700'.",
228
+ },
229
+ fill: {
230
+ type: "string",
231
+ format: "color",
232
+ description: "Fill color (text color).",
233
+ },
234
+ },
235
+ allowedChildren: [],
236
+ },
237
+ },
238
+ };
239
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/dynamic-image/schema.ts"],"names":[],"mappings":";;;AAEa,QAAA,UAAU,GAAG;IACxB,QAAQ,EAAE;QACR,aAAa,EAAE;YACb,WAAW,EAAE,sEAAsE;YACnF,KAAK,EAAE;gBACL,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,0CAA0C;iBACxD;gBACD,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,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AW,EAAE,gCAAgC;iBAC9C;aACF;YACD,eAAe,EAAE,EAAE;SACpB;QAED,IAAI,EAAE;YACJ,WAAW,EAAE,yBAAyB;YACtC,KAAK,EAAE;gBACL,CAAC,EAAE;oBACD,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,gCAAgC;iBAC9C;gBACD,CAAC,EAAE;oBACD,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,kCAAkC;iBAChD;gBACD,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,uCAAuC;iBACrD;gBACD,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,sBAAsB;iBACpC;gBACD,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,kCAAkC;iBAChD;gBACD,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,MAAM,EAAE,OAAO;oBACf,WAAW,EAAE,0BAA0B;iBACxC;aACF;YACD,eAAe,EAAE,EAAE;SACpB;KACF;CACwB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function generateDataSchema(data: Record<string, unknown>): Record<string, any>;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/dynamic-image/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAQrF"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateDataSchema = generateDataSchema;
4
+ function generateDataSchema(data) {
5
+ const schema = {};
6
+ for (const [key, value] of Object.entries(data)) {
7
+ schema[key] = inferPropertySchema(value);
8
+ }
9
+ return schema;
10
+ }
11
+ function inferPropertySchema(value) {
12
+ if (value === null || value === undefined) {
13
+ return {
14
+ type: "string",
15
+ };
16
+ }
17
+ if (typeof value === "string") {
18
+ return {
19
+ type: "string",
20
+ };
21
+ }
22
+ if (typeof value === "number") {
23
+ return {
24
+ type: "number",
25
+ };
26
+ }
27
+ if (typeof value === "boolean") {
28
+ return {
29
+ type: "boolean",
30
+ };
31
+ }
32
+ if (typeof value === "function") {
33
+ return {
34
+ type: "function",
35
+ };
36
+ }
37
+ if (Array.isArray(value)) {
38
+ const itemSchema = value.length > 0 ? inferPropertySchema(value[0]) : { type: "string" };
39
+ return {
40
+ type: "array",
41
+ shape: itemSchema,
42
+ };
43
+ }
44
+ if (typeof value === "object") {
45
+ const shape = {};
46
+ for (const [k, v] of Object.entries(value)) {
47
+ shape[k] = inferPropertySchema(v);
48
+ }
49
+ return {
50
+ type: "object",
51
+ shape,
52
+ };
53
+ }
54
+ return { type: "string" };
55
+ }
56
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/dynamic-image/utils.ts"],"names":[],"mappings":";;AAAA,gDAQC;AARD,SAAgB,kBAAkB,CAAC,IAA6B;IAC9D,MAAM,MAAM,GAAwB,EAAE,CAAC;IAEvC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,MAAM,CAAC,GAAG,CAAC,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAc;IACzC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO;YACL,IAAI,EAAE,QAAQ;SACf,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO;YACL,IAAI,EAAE,QAAQ;SACf,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO;YACL,IAAI,EAAE,QAAQ;SACf,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO;YACL,IAAI,EAAE,SAAS;SAChB,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,OAAO;YACL,IAAI,EAAE,UAAU;SACjB,CAAC;IACJ,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QACzF,OAAO;YACL,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,UAAU;SAClB,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAwB,EAAE,CAAC;QACtC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3C,KAAK,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;QACpC,CAAC;QACD,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,KAAK;SACN,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC5B,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "abstract-image",
3
- "version": "11.2.13",
3
+ "version": "11.2.17",
4
4
  "description": "Dynamically create images using code or JSX and render to any format",
5
5
  "repository": "https://github.com/dividab/abstract-visuals/tree/master/packages/abstract-image",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index",
8
+ "sideEffects": false,
8
9
  "license": "MIT",
9
10
  "exports": {
10
11
  ".": "./lib/index.js"
@@ -22,7 +23,8 @@
22
23
  "base64-js": "^1.5.1",
23
24
  "fast-xml-parser": "^4.5.0",
24
25
  "handlebars": "4.7.8",
25
- "handlebars-xml": "^0.1.3"
26
+ "handlebars-xml": "^0.1.6",
27
+ "jsxpression": "^0.1.11"
26
28
  },
27
29
  "peerDependencies": {
28
30
  "react": ">=17.0.0 <20.0.0"
@@ -34,5 +36,5 @@
34
36
  "vite": "^6.0.1",
35
37
  "vitest": "^2.1.6"
36
38
  },
37
- "gitHead": "db19d1efd6eeec69dcacb3a82f51da3fa14f69ef"
39
+ "gitHead": "07369c92f3faed8f1adfc92b37ff7f8a040cf5e9"
38
40
  }
@@ -0,0 +1,163 @@
1
+ import {
2
+ AbstractFontWeight,
3
+ AbstractImage,
4
+ BinaryImage,
5
+ black,
6
+ createBinaryImage,
7
+ createEllipse,
8
+ createGroup,
9
+ createLine,
10
+ createPolygon,
11
+ createPolyLine,
12
+ createRectangle,
13
+ createText,
14
+ Ellipse,
15
+ fromString2,
16
+ Group,
17
+ Line,
18
+ Point,
19
+ Polygon,
20
+ PolyLine,
21
+ Rectangle,
22
+ solidLine,
23
+ Text,
24
+ transparent,
25
+ white,
26
+ } from "../model";
27
+
28
+ export const createComponents = (mutableImageUrls: Array<string>): Record<string, (...args: any[]) => any> => ({
29
+ AbstractImage: (props): AbstractImage => ({
30
+ topLeft: { x: 0, y: 0 },
31
+ size: { width: props.width ?? 800, height: props.height ?? 600 },
32
+ backgroundColor: transparent,
33
+ components: (props.children ?? []).flat().filter(Boolean),
34
+ }),
35
+ Group: (props): Group => {
36
+ return createGroup("", (props.children ?? []).flat().filter(Boolean));
37
+ },
38
+ Image: (props): BinaryImage => {
39
+ mutableImageUrls.push(props.src);
40
+ const x = props.x ?? 0;
41
+ const y = props.y ?? 0;
42
+ const width = props.width ?? 100;
43
+ const height = props.height ?? 100;
44
+ return createBinaryImage(
45
+ { x, y },
46
+ { x: x + width, y: y + height },
47
+ "png",
48
+ { type: "url", url: props.src },
49
+ undefined
50
+ );
51
+ },
52
+ Rectangle: (props): Rectangle => {
53
+ const x = props.x ?? 0;
54
+ const y = props.y ?? 0;
55
+ const width = props.width ?? 100;
56
+ const height = props.height ?? 100;
57
+ return createRectangle(
58
+ { x, y },
59
+ { x: x + width, y: y + height },
60
+ fromString2(props.stroke ?? "#000", black),
61
+ props.strokeWidth ?? 1,
62
+ fromString2(props.fill ?? "#fff", white),
63
+ undefined,
64
+ solidLine,
65
+ props.radius ? { x: props.radius, y: props.radius } : undefined
66
+ );
67
+ },
68
+ Ellipse: (props): Ellipse => {
69
+ const x = props.x ?? 0;
70
+ const y = props.y ?? 0;
71
+ const width = props.width ?? 100;
72
+ const height = props.height ?? 100;
73
+ return createEllipse(
74
+ { x, y },
75
+ { x: x + width, y: y + height },
76
+ fromString2(props.stroke ?? "#000", black),
77
+ props.strokeWidth ?? 1,
78
+ fromString2(props.fill ?? "#fff", white),
79
+ undefined,
80
+ solidLine
81
+ );
82
+ },
83
+ Line: (props): Line => {
84
+ return createLine(
85
+ { x: props.x1 ?? 0, y: props.y1 ?? 0 },
86
+ { x: props.x2 ?? 100, y: props.y2 ?? 0 },
87
+ fromString2(props.stroke ?? "#000", black),
88
+ props.strokeWidth ?? 1,
89
+ undefined,
90
+ solidLine
91
+ );
92
+ },
93
+ Polyline: (props): PolyLine => {
94
+ return createPolyLine(
95
+ parsePointsString(props.points),
96
+ fromString2(props.stroke ?? "#000", black),
97
+ props.strokeWidth ?? 1,
98
+ undefined,
99
+ solidLine
100
+ );
101
+ },
102
+ Polygon: (props): Polygon => {
103
+ return createPolygon(
104
+ parsePointsString(props.points),
105
+ fromString2(props.stroke ?? "#000", black),
106
+ props.strokeWidth ?? 1,
107
+ fromString2(props.fill ?? "#fff", white),
108
+ undefined,
109
+ solidLine
110
+ );
111
+ },
112
+ Text: (props): Text => {
113
+ const fontWeight = mapFontWeight(props.fontWeight);
114
+ const children = props.children ?? [];
115
+ const filteredChildren = Array.isArray(children)
116
+ ? children.flat().filter((c: any) => c !== null && c !== undefined)
117
+ : [];
118
+ const text = filteredChildren.length > 0 ? String(filteredChildren[0]) : "";
119
+ return createText(
120
+ { x: props.x ?? 0, y: props.y ?? 0 },
121
+ text,
122
+ props.fontFamily ?? "",
123
+ props.fontSize ?? 12,
124
+ fromString2(props.fill ?? "#000", black),
125
+ fontWeight,
126
+ 0, // clockwiseRotationDegrees
127
+ "left", // textAlignment
128
+ "right", // horizontalGrowthDirection
129
+ "down", // verticalGrowthDirection
130
+ 0, // strokeThickness
131
+ transparent, // strokeColor
132
+ false, // italic
133
+ undefined // id
134
+ );
135
+ },
136
+ });
137
+
138
+ function mapFontWeight(weight?: string | number): AbstractFontWeight {
139
+ if (weight === undefined) {
140
+ return "normal";
141
+ }
142
+
143
+ if (typeof weight === "string") {
144
+ switch (weight.toLowerCase()) {
145
+ case "bold":
146
+ case "bolder":
147
+ return "bold";
148
+ case "lighter":
149
+ case "normal":
150
+ default:
151
+ return "normal";
152
+ }
153
+ }
154
+
155
+ return weight >= 600 ? "bold" : "normal";
156
+ }
157
+
158
+ function parsePointsString(pointsString: string): Array<Point> {
159
+ return pointsString.split(" ").map((tuple): Point => {
160
+ const [xString, yString] = tuple.split(",");
161
+ return { x: Number(xString ?? 0), y: Number(yString ?? 0) };
162
+ });
163
+ }