abstract-image 11.2.2 → 11.2.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/lib/index.d.ts +0 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -2
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +0 -2
- package/src/replace-extract-urls.ts +0 -53
- package/src/stringify-parse.ts +0 -98
package/lib/index.d.ts
CHANGED
|
@@ -10,6 +10,4 @@ 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
12
|
export * from "./dynamic-image/index.js";
|
|
13
|
-
export * from "./stringify-parse.js";
|
|
14
|
-
export * from "./replace-extract-urls.js";
|
|
15
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,cAAc,0BAA0B,CAAC
|
|
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,cAAc,0BAA0B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -26,6 +26,4 @@ __exportStar(require("./exporters/dxf2d-export-image.js"), exports);
|
|
|
26
26
|
__exportStar(require("./exporters/react-svg-export-image.js"), exports);
|
|
27
27
|
__exportStar(require("./exporters/eps-export-image.js"), exports);
|
|
28
28
|
__exportStar(require("./dynamic-image/index.js"), exports);
|
|
29
|
-
__exportStar(require("./stringify-parse.js"), exports);
|
|
30
|
-
__exportStar(require("./replace-extract-urls.js"), exports);
|
|
31
29
|
//# 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,4DAA0C;AAC1C,mDAAiC;AACjC,uDAAqC;AACrC,mDAAiC;AACjC,kDAAgC;AAChC,wDAAsC;AACtC,kEAAgD;AAChD,kEAAgD;AAChD,oEAAkD;AAClD,wEAAsD;AACtD,kEAAgD;AAChD,2DAAyC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,mDAAiC;AACjC,uDAAqC;AACrC,mDAAiC;AACjC,kDAAgC;AAChC,wDAAsC;AACtC,kEAAgD;AAChD,kEAAgD;AAChD,oEAAkD;AAClD,wEAAsD;AACtD,kEAAgD;AAChD,2DAAyC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "abstract-image",
|
|
3
|
-
"version": "11.2.
|
|
3
|
+
"version": "11.2.3",
|
|
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",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"vite": "^6.0.1",
|
|
35
35
|
"vitest": "^2.1.6"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "dc840ebd0418fc2c9f80d3731304f8caa125a546"
|
|
38
38
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,5 +10,3 @@ 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
12
|
export * from "./dynamic-image/index.js";
|
|
13
|
-
export * from "./stringify-parse.js";
|
|
14
|
-
export * from "./replace-extract-urls.js";
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { AbstractImage, Component } from "./model";
|
|
2
|
-
|
|
3
|
-
export function replaceUrls(abstractImage: AbstractImage, blobs: Record<string, Uint8Array>): AbstractImage {
|
|
4
|
-
return { ...abstractImage, components: abstractImage.components.map((c) => componentReplaceUrl(c, blobs)) };
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function componentReplaceUrl(c: Component, blobs: Record<string, Uint8Array>): any {
|
|
8
|
-
switch (c.type) {
|
|
9
|
-
case "binaryimage": {
|
|
10
|
-
const bytes = c.data.type === "url" ? blobs[c.data.url] : undefined;
|
|
11
|
-
if (bytes) {
|
|
12
|
-
return { ...c, data: { type: "bytes", bytes } };
|
|
13
|
-
}
|
|
14
|
-
return c;
|
|
15
|
-
}
|
|
16
|
-
case "group":
|
|
17
|
-
return { ...c, children: c.children.map((child) => componentReplaceUrl(child, blobs)) };
|
|
18
|
-
case "subimage":
|
|
19
|
-
return { ...c, image: componentReplaceUrl(c.image, blobs) };
|
|
20
|
-
default:
|
|
21
|
-
return c;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function extractUrls(abstractImage: AbstractImage): ReadonlyArray<string> {
|
|
26
|
-
const urls = Array<string>();
|
|
27
|
-
const stack = abstractImage.components.slice();
|
|
28
|
-
|
|
29
|
-
while (stack.length > 0) {
|
|
30
|
-
const c = stack.pop()!;
|
|
31
|
-
switch (c.type) {
|
|
32
|
-
case "binaryimage": {
|
|
33
|
-
if (c.data.type === "url") {
|
|
34
|
-
urls.push(c.data.url);
|
|
35
|
-
}
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
case "group": {
|
|
39
|
-
for (const child of c.children) {
|
|
40
|
-
stack.push(child);
|
|
41
|
-
}
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
case "subimage":
|
|
45
|
-
stack.push(c.image);
|
|
46
|
-
break;
|
|
47
|
-
default:
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return urls;
|
|
53
|
-
}
|
package/src/stringify-parse.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { AbstractImage } from "./model/abstract-image";
|
|
2
|
-
import { BinaryImage, Component, Group, SubImage } from "./model/component";
|
|
3
|
-
|
|
4
|
-
export function stringifyBase64(abstractImage: AbstractImage): string {
|
|
5
|
-
const safe = { ...abstractImage, components: abstractImage.components.map(componentToJsonSafe) };
|
|
6
|
-
return JSON.stringify(safe);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function encodeBase64(abstractImage: AbstractImage): AbstractImage {
|
|
10
|
-
return { ...abstractImage, components: abstractImage.components.map(componentToJsonSafe) };
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function parseBase64(stringifiedImage: string): AbstractImage {
|
|
14
|
-
const obj = JSON.parse(stringifiedImage);
|
|
15
|
-
return { ...obj, components: (obj.components ?? []).map(componentFromJsonSafe) } as AbstractImage;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function decodeBase64(safeAbstractImage: AbstractImage): AbstractImage {
|
|
19
|
-
return {
|
|
20
|
-
...safeAbstractImage,
|
|
21
|
-
components: (safeAbstractImage.components ?? []).map(componentFromJsonSafe),
|
|
22
|
-
} as AbstractImage;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function componentToJsonSafe(c: Component): any {
|
|
26
|
-
switch (c.type) {
|
|
27
|
-
case "binaryimage": {
|
|
28
|
-
if (c.data.type === "bytes") {
|
|
29
|
-
return { ...c, data: { type: "bytes", bytes: toBase64(c.data.bytes) } };
|
|
30
|
-
}
|
|
31
|
-
return c;
|
|
32
|
-
}
|
|
33
|
-
case "group":
|
|
34
|
-
return { ...c, children: c.children.map(componentToJsonSafe) };
|
|
35
|
-
case "subimage":
|
|
36
|
-
return { ...c, image: componentToJsonSafe(c.image) };
|
|
37
|
-
default:
|
|
38
|
-
return c;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type BufferFromUint8ArrayStringified = { data: Uint8Array; type: "Buffer" };
|
|
43
|
-
|
|
44
|
-
function componentFromJsonSafe(c: any): Component {
|
|
45
|
-
if (c?.type === "binaryimage") {
|
|
46
|
-
if (c.data?.type === "bytes") {
|
|
47
|
-
if (typeof c.data.bytes === "string") {
|
|
48
|
-
return { ...c, data: { type: "bytes", bytes: fromBase64(c.data.bytes) } } as BinaryImage;
|
|
49
|
-
}
|
|
50
|
-
// legacy fallback, will remove
|
|
51
|
-
if ((c.data.bytes as unknown as BufferFromUint8ArrayStringified)?.data) {
|
|
52
|
-
return {
|
|
53
|
-
...c,
|
|
54
|
-
data: { ...c.data, bytes: new Uint8Array((c.data.bytes as unknown as BufferFromUint8ArrayStringified).data) },
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
if (!Array.isArray(c.data?.bytes)) {
|
|
58
|
-
return { ...c, data: { ...c.data, bytes: new Uint8Array(Object.values(c.data.bytes)) } }; // Somtimes Uint8Array is an object instead of an array
|
|
59
|
-
}
|
|
60
|
-
return { ...c, data: { ...c.data, bytes: new Uint8Array(c.data.bytes) } };
|
|
61
|
-
}
|
|
62
|
-
return c as BinaryImage;
|
|
63
|
-
}
|
|
64
|
-
if (c?.type === "group") {
|
|
65
|
-
return { ...c, children: Array.isArray(c.children) ? c.children.map(componentFromJsonSafe) : [] } as Group;
|
|
66
|
-
}
|
|
67
|
-
if (c?.type === "subimage") {
|
|
68
|
-
return { ...c, image: componentFromJsonSafe(c.image) } as SubImage;
|
|
69
|
-
}
|
|
70
|
-
return c as Component;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function toBase64(u8: Uint8Array): string {
|
|
74
|
-
// Node
|
|
75
|
-
if (typeof Buffer !== "undefined") {
|
|
76
|
-
return Buffer.from(u8).toString("base64");
|
|
77
|
-
}
|
|
78
|
-
// Browser
|
|
79
|
-
let bin = "";
|
|
80
|
-
for (const e of u8) {
|
|
81
|
-
bin += String.fromCharCode(e);
|
|
82
|
-
}
|
|
83
|
-
return btoa(bin);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function fromBase64(b64: string): Uint8Array {
|
|
87
|
-
// Node
|
|
88
|
-
if (typeof Buffer !== "undefined") {
|
|
89
|
-
return new Uint8Array(Buffer.from(b64, "base64"));
|
|
90
|
-
}
|
|
91
|
-
// Browser
|
|
92
|
-
const bin = atob(b64);
|
|
93
|
-
const out = new Uint8Array(bin.length);
|
|
94
|
-
for (let i = 0; i < bin.length; i++) {
|
|
95
|
-
out[i] = bin.charCodeAt(i);
|
|
96
|
-
}
|
|
97
|
-
return out;
|
|
98
|
-
}
|