abstract-image 13.0.9 → 13.0.12
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/lib/dynamic-image/dynamic-image.d.ts +11 -1
- package/lib/dynamic-image/dynamic-image.d.ts.map +1 -1
- package/lib/dynamic-image/dynamic-image.js +31 -12
- package/lib/dynamic-image/dynamic-image.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/package.json +5 -4
- package/src/dynamic-image/dynamic-image.ts +42 -13
- package/src/index.ts +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PropertySchema } from "jsxpression";
|
|
1
2
|
import { AbstractImage } from "../model/abstract-image.js";
|
|
2
3
|
export type DynamicImageResult = {
|
|
3
4
|
readonly type: "Ok";
|
|
@@ -12,5 +13,14 @@ export type DynamicImageError = {
|
|
|
12
13
|
message: string;
|
|
13
14
|
cause?: unknown;
|
|
14
15
|
};
|
|
15
|
-
export declare function dynamicImage(source: string, data: Record<string, unknown>): DynamicImageResult;
|
|
16
|
+
export declare function dynamicImage(source: string, data: Record<string, unknown>, dataSchema?: Record<string, PropertySchema>): DynamicImageResult;
|
|
17
|
+
export type CompileDynamicImageResult = {
|
|
18
|
+
readonly type: "Ok";
|
|
19
|
+
value: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly type: "Err";
|
|
22
|
+
readonly error: DynamicImageError;
|
|
23
|
+
};
|
|
24
|
+
export declare function compileDynamicImage(source: string, dataSchema?: Record<string, PropertySchema>): CompileDynamicImageResult;
|
|
25
|
+
export declare function renderDynamicImage(jsString: string, data: Record<string, unknown>): DynamicImageResult;
|
|
16
26
|
//# sourceMappingURL=dynamic-image.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-image.d.ts","sourceRoot":"","sources":["../../src/dynamic-image/dynamic-image.ts"],"names":[],"mappings":"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AAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,kBAAkB,CActG"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { render } from "jsxpression";
|
|
2
|
-
import { generateDataSchema } from "./utils.js";
|
|
1
|
+
import { render, compile, evaluate } from "jsxpression";
|
|
3
2
|
import { createComponents } from "./components.js";
|
|
4
3
|
import { baseSchema } from "./schema.js";
|
|
5
|
-
export function dynamicImage(source, data) {
|
|
4
|
+
export function dynamicImage(source, data, dataSchema) {
|
|
6
5
|
try {
|
|
7
6
|
const imageUrls = Array();
|
|
8
|
-
const schema = {
|
|
9
|
-
...baseSchema,
|
|
10
|
-
data: generateDataSchema(data),
|
|
11
|
-
};
|
|
7
|
+
const schema = dataSchema ? { ...baseSchema, data: dataSchema } : baseSchema;
|
|
12
8
|
const image = render(source, schema, {
|
|
13
9
|
data,
|
|
14
10
|
components: createComponents(imageUrls),
|
|
@@ -18,11 +14,34 @@ export function dynamicImage(source, data) {
|
|
|
18
14
|
catch (error) {
|
|
19
15
|
return {
|
|
20
16
|
type: "Err",
|
|
21
|
-
error: {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
error: { type: "RENDER_ERROR", message: error instanceof Error ? error.message : String(error), cause: error },
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function compileDynamicImage(source, dataSchema) {
|
|
22
|
+
try {
|
|
23
|
+
return { type: "Ok", value: compile(source, dataSchema ? { ...baseSchema, data: dataSchema } : baseSchema) };
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return {
|
|
27
|
+
type: "Err",
|
|
28
|
+
error: { type: "RENDER_ERROR", message: error instanceof Error ? error.message : String(error), cause: error },
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function renderDynamicImage(jsString, data) {
|
|
33
|
+
const imageUrls = Array();
|
|
34
|
+
try {
|
|
35
|
+
return {
|
|
36
|
+
type: "Ok",
|
|
37
|
+
image: evaluate(jsString, baseSchema, { data, components: createComponents(imageUrls) }),
|
|
38
|
+
imageUrls,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
return {
|
|
43
|
+
type: "Err",
|
|
44
|
+
error: { type: "RENDER_ERROR", message: error instanceof Error ? error.message : String(error), cause: error },
|
|
26
45
|
};
|
|
27
46
|
}
|
|
28
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-image.js","sourceRoot":"","sources":["../../src/dynamic-image/dynamic-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,
|
|
1
|
+
{"version":3,"file":"dynamic-image.js","sourceRoot":"","sources":["../../src/dynamic-image/dynamic-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,OAAO,EAAE,QAAQ,EAAkB,MAAM,aAAa,CAAC;AAGhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAYzC,MAAM,UAAU,YAAY,CAC1B,MAAc,EACd,IAA6B,EAC7B,UAA2C;IAE3C,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,KAAK,EAAU,CAAC;QAClC,MAAM,MAAM,GAAW,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;QAErF,MAAM,KAAK,GAAG,MAAM,CAAgB,MAAM,EAAE,MAAM,EAAE;YAClD,IAAI;YACJ,UAAU,EAAE,gBAAgB,CAAC,SAAS,CAAC;SACxC,CAAC,CAAC;QAEH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,IAAI,EAAE,KAAK;YACX,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C,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE;SAC/G,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,5 @@ export * from "./exporters/png-export-image.js";
|
|
|
9
9
|
export * from "./exporters/dxf2d-export-image.js";
|
|
10
10
|
export * from "./exporters/react-svg-export-image.js";
|
|
11
11
|
export * from "./exporters/eps-export-image.js";
|
|
12
|
-
export * from "./dynamic-image/index.js";
|
|
13
12
|
export * as AbstractImageJsx from "./abstract-image-jsx/index.js";
|
|
14
13
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,uCAAuC,CAAC;AACtD,cAAc,iCAAiC,CAAC;AAChD,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,uCAAuC,CAAC;AACtD,cAAc,iCAAiC,CAAC;AAChD,OAAO,KAAK,gBAAgB,MAAM,+BAA+B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,5 @@ export * from "./exporters/png-export-image.js";
|
|
|
9
9
|
export * from "./exporters/dxf2d-export-image.js";
|
|
10
10
|
export * from "./exporters/react-svg-export-image.js";
|
|
11
11
|
export * from "./exporters/eps-export-image.js";
|
|
12
|
-
export * from "./dynamic-image/index.js";
|
|
13
12
|
export * as AbstractImageJsx from "./abstract-image-jsx/index.js";
|
|
14
13
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,uCAAuC,CAAC;AACtD,cAAc,iCAAiC,CAAC;AAChD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,uCAAuC,CAAC;AACtD,cAAc,iCAAiC,CAAC;AAChD,OAAO,KAAK,gBAAgB,MAAM,+BAA+B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "abstract-image",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.12",
|
|
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",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"type": "module",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"exports": {
|
|
12
|
-
".": "./lib/index.js"
|
|
12
|
+
".": "./lib/index.js",
|
|
13
|
+
"./dynamic-image": "./lib/dynamic-image/index.js"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
16
|
"/lib",
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"handlebars": "4.7.8",
|
|
27
28
|
"handlebars-xml": "^0.4.3",
|
|
28
29
|
"iconv-lite": "^0.7.2",
|
|
29
|
-
"jsxpression": "^0.1.
|
|
30
|
+
"jsxpression": "^0.1.15"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
33
|
"react": ">=17.0.0 <20.0.0"
|
|
@@ -38,5 +39,5 @@
|
|
|
38
39
|
"vite": "^6.0.1",
|
|
39
40
|
"vitest": "^2.1.6"
|
|
40
41
|
},
|
|
41
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "4bcc2cca436aa2b5e54d25acec0c744635fa434b"
|
|
42
43
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { render, Schema } from "jsxpression";
|
|
1
|
+
import { render, Schema, compile, evaluate, PropertySchema } from "jsxpression";
|
|
2
2
|
import { AbstractImage } from "../model/abstract-image.js";
|
|
3
|
-
|
|
4
3
|
import { generateDataSchema } from "./utils.js";
|
|
5
4
|
import { createComponents } from "./components.js";
|
|
6
5
|
import { baseSchema } from "./schema.js";
|
|
@@ -15,14 +14,14 @@ export type DynamicImageError = {
|
|
|
15
14
|
cause?: unknown;
|
|
16
15
|
};
|
|
17
16
|
|
|
18
|
-
export function dynamicImage(
|
|
17
|
+
export function dynamicImage(
|
|
18
|
+
source: string,
|
|
19
|
+
data: Record<string, unknown>,
|
|
20
|
+
dataSchema?: Record<string, PropertySchema>
|
|
21
|
+
): DynamicImageResult {
|
|
19
22
|
try {
|
|
20
23
|
const imageUrls = Array<string>();
|
|
21
|
-
|
|
22
|
-
const schema: Schema = {
|
|
23
|
-
...baseSchema,
|
|
24
|
-
data: generateDataSchema(data),
|
|
25
|
-
};
|
|
24
|
+
const schema: Schema = dataSchema ? { ...baseSchema, data: dataSchema } : baseSchema;
|
|
26
25
|
|
|
27
26
|
const image = render<AbstractImage>(source, schema, {
|
|
28
27
|
data,
|
|
@@ -33,11 +32,41 @@ export function dynamicImage(source: string, data: Record<string, unknown>): Dyn
|
|
|
33
32
|
} catch (error) {
|
|
34
33
|
return {
|
|
35
34
|
type: "Err",
|
|
36
|
-
error: {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
error: { type: "RENDER_ERROR", message: error instanceof Error ? error.message : String(error), cause: error },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type CompileDynamicImageResult =
|
|
41
|
+
| { readonly type: "Ok"; value: string }
|
|
42
|
+
| { readonly type: "Err"; readonly error: DynamicImageError };
|
|
43
|
+
|
|
44
|
+
export function compileDynamicImage(
|
|
45
|
+
source: string,
|
|
46
|
+
dataSchema?: Record<string, PropertySchema>
|
|
47
|
+
): CompileDynamicImageResult {
|
|
48
|
+
try {
|
|
49
|
+
return { type: "Ok", value: compile(source, dataSchema ? { ...baseSchema, data: dataSchema } : baseSchema) };
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return {
|
|
52
|
+
type: "Err",
|
|
53
|
+
error: { type: "RENDER_ERROR", message: error instanceof Error ? error.message : String(error), cause: error },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function renderDynamicImage(jsString: string, data: Record<string, unknown>): DynamicImageResult {
|
|
59
|
+
const imageUrls = Array<string>();
|
|
60
|
+
try {
|
|
61
|
+
return {
|
|
62
|
+
type: "Ok",
|
|
63
|
+
image: evaluate(jsString, baseSchema, { data, components: createComponents(imageUrls) }) as AbstractImage,
|
|
64
|
+
imageUrls,
|
|
65
|
+
};
|
|
66
|
+
} catch (error) {
|
|
67
|
+
return {
|
|
68
|
+
type: "Err",
|
|
69
|
+
error: { type: "RENDER_ERROR", message: error instanceof Error ? error.message : String(error), cause: error },
|
|
41
70
|
};
|
|
42
71
|
}
|
|
43
72
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,5 +9,4 @@ export * from "./exporters/png-export-image.js";
|
|
|
9
9
|
export * from "./exporters/dxf2d-export-image.js";
|
|
10
10
|
export * from "./exporters/react-svg-export-image.js";
|
|
11
11
|
export * from "./exporters/eps-export-image.js";
|
|
12
|
-
export * from "./dynamic-image/index.js";
|
|
13
12
|
export * as AbstractImageJsx from "./abstract-image-jsx/index.js";
|