image-js 1.4.0 → 1.5.0
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/dist/image-js.esm.js +11 -2
- package/dist/image-js.esm.js.map +1 -1
- package/dist/image-js.esm.min.js +2 -2
- package/dist/image-js.esm.min.js.map +1 -1
- package/dist/image-js.umd.js +11 -2
- package/dist/image-js.umd.js.map +1 -1
- package/dist/image-js.umd.min.js +2 -2
- package/dist/image-js.umd.min.js.map +1 -1
- package/lib/utils/cross_platform.d.ts +1 -0
- package/lib/utils/cross_platform.d.ts.map +1 -1
- package/lib/utils/cross_platform.js +9 -1
- package/lib/utils/cross_platform.js.map +1 -1
- package/package.json +4 -2
- package/src/utils/cross_platform.ts +11 -1
|
@@ -11,6 +11,7 @@ export declare function getNodeApiOrThrow(methodName: string): {
|
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
13
|
* Returns a 2D canvas context for rendering on the browser or Node.js.
|
|
14
|
+
* On Node.js this requires the optional `skia-canvas` package to be installed.
|
|
14
15
|
* @param width - Width of the canvas.
|
|
15
16
|
* @param height - Height of the canvas.
|
|
16
17
|
* @returns The initialised canvas context.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross_platform.d.ts","sourceRoot":"","sources":["../../src/utils/cross_platform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,wBAAwB,IAAI,4BAA4B,EACzD,MAAM,aAAa,CAAC;AAErB;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM;;;;EASnD;AAKD
|
|
1
|
+
{"version":3,"file":"cross_platform.d.ts","sourceRoot":"","sources":["../../src/utils/cross_platform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,wBAAwB,IAAI,4BAA4B,EACzD,MAAM,aAAa,CAAC;AAErB;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM;;;;EASnD;AAKD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,iCAAiC,GAAG,4BAA4B,CAqBlE"}
|
|
@@ -17,13 +17,21 @@ let CanvasCtorBrowser;
|
|
|
17
17
|
let CanvasCtorNode;
|
|
18
18
|
/**
|
|
19
19
|
* Returns a 2D canvas context for rendering on the browser or Node.js.
|
|
20
|
+
* On Node.js this requires the optional `skia-canvas` package to be installed.
|
|
20
21
|
* @param width - Width of the canvas.
|
|
21
22
|
* @param height - Height of the canvas.
|
|
22
23
|
* @returns The initialised canvas context.
|
|
23
24
|
*/
|
|
24
25
|
export function getCanvasContext(width, height) {
|
|
25
26
|
if (isNode()) {
|
|
26
|
-
|
|
27
|
+
if (!CanvasCtorNode) {
|
|
28
|
+
try {
|
|
29
|
+
CanvasCtorNode = getRequireFn()('skia-canvas').Canvas;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new Error('drawText on Node.js requires the optional "skia-canvas" package. Install it with: npm install skia-canvas', { cause: error });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
27
35
|
return new CanvasCtorNode(width, height).getContext('2d');
|
|
28
36
|
}
|
|
29
37
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross_platform.js","sourceRoot":"","sources":["../../src/utils/cross_platform.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,kCAAkC,CAAC,CAAC;IACnE,CAAC;IACD,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC;QACvC,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC;QAC3C,GAAG,EAAE,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC;KAC1C,CAAC;AACJ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OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAED,SAAS,MAAM;IACb,OAAO,CACL,OAAO,OAAO,KAAK,WAAW;QAC9B,OAAO,OAAO,CAAC,gBAAgB,KAAK,UAAU,CAC/C,CAAC;AACJ,CAAC;AAED,IAAI,SAAyB,CAAC;AAC9B,SAAS,YAAY;IACnB,SAAS,KAAK,OAAO;SAClB,gBAAgB,CAAC,aAAa,CAAC;SAC/B,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "image-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Image processing and manipulation in JavaScript",
|
|
6
6
|
"author": "Michaël Zasso",
|
|
@@ -55,12 +55,14 @@
|
|
|
55
55
|
"ml-regression-polynomial-2d": "^1.0.0",
|
|
56
56
|
"ml-spectra-processing": "^14.18.2",
|
|
57
57
|
"robust-point-in-polygon": "^1.0.3",
|
|
58
|
-
"skia-canvas": "^3.0.8",
|
|
59
58
|
"ssim.js": "^3.5.0",
|
|
60
59
|
"tiff": "^7.1.3",
|
|
61
60
|
"ts-pattern": "^5.9.0",
|
|
62
61
|
"uint8-base64": "^1.0.0"
|
|
63
62
|
},
|
|
63
|
+
"optionalDependencies": {
|
|
64
|
+
"skia-canvas": "^3.0.8"
|
|
65
|
+
},
|
|
64
66
|
"lavamoat": {
|
|
65
67
|
"allowScripts": {
|
|
66
68
|
"@lavamoat/preinstall-always-fail": false,
|
|
@@ -24,6 +24,7 @@ let CanvasCtorNode: typeof SkiaCanvas;
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Returns a 2D canvas context for rendering on the browser or Node.js.
|
|
27
|
+
* On Node.js this requires the optional `skia-canvas` package to be installed.
|
|
27
28
|
* @param width - Width of the canvas.
|
|
28
29
|
* @param height - Height of the canvas.
|
|
29
30
|
* @returns The initialised canvas context.
|
|
@@ -33,7 +34,16 @@ export function getCanvasContext(
|
|
|
33
34
|
height: number,
|
|
34
35
|
): OffscreenCanvasRenderingContext2D | SkiaCanvasRenderingContext2D {
|
|
35
36
|
if (isNode()) {
|
|
36
|
-
|
|
37
|
+
if (!CanvasCtorNode) {
|
|
38
|
+
try {
|
|
39
|
+
CanvasCtorNode = getRequireFn()('skia-canvas').Canvas;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
'drawText on Node.js requires the optional "skia-canvas" package. Install it with: npm install skia-canvas',
|
|
43
|
+
{ cause: error },
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
37
47
|
return new CanvasCtorNode(width, height).getContext('2d');
|
|
38
48
|
} else {
|
|
39
49
|
CanvasCtorBrowser ??= globalThis.OffscreenCanvas;
|