@napi-rs/canvas 0.1.64 → 0.1.66
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/README.md +2 -2
- package/index.d.ts +4 -1
- package/load-image.js +22 -3
- package/package.json +29 -29
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# `skr canvas`
|
|
2
2
|
|
|
3
|
-

|
|
4
|
-
](https://github.com/Brooooooklyn/canvas/actions/workflows/CI.yaml)
|
|
4
|
+

|
|
5
5
|
[](https://packagephobia.com/result?p=@napi-rs/canvas)
|
|
6
6
|
[](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true)
|
|
7
7
|
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ReadableStream } from 'node:stream/web'
|
|
2
|
+
|
|
1
3
|
// Clear all type of caches in Skia
|
|
2
4
|
export function clearAllCache(): void
|
|
3
5
|
|
|
@@ -368,7 +370,8 @@ export class Canvas {
|
|
|
368
370
|
encode(format: 'webp' | 'jpeg', quality?: number): Promise<Buffer>
|
|
369
371
|
encode(format: 'png'): Promise<Buffer>
|
|
370
372
|
encode(format: 'avif', cfg?: AvifConfig): Promise<Buffer>
|
|
371
|
-
|
|
373
|
+
encodeStream(format: 'webp' | 'jpeg', quality?: number): ReadableStream<Buffer>
|
|
374
|
+
encodeStream(format: 'png'): ReadableStream<Buffer>
|
|
372
375
|
toBuffer(mime: 'image/png'): Buffer
|
|
373
376
|
toBuffer(mime: 'image/jpeg' | 'image/webp', quality?: number): Buffer
|
|
374
377
|
toBuffer(mime: 'image/avif', cfg?: AvifConfig): Buffer
|
package/load-image.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const { Readable } = require('stream')
|
|
3
|
+
const { URL } = require('url')
|
|
3
4
|
|
|
4
5
|
const { Image } = require('./js-binding')
|
|
5
6
|
|
|
@@ -33,13 +34,13 @@ module.exports = async function loadImage(source, options = {}) {
|
|
|
33
34
|
return createImage(data, options.alt)
|
|
34
35
|
}
|
|
35
36
|
// if source is a string or URL instance
|
|
36
|
-
if (typeof source === 'string'
|
|
37
|
+
if (typeof source === 'string') {
|
|
37
38
|
// if the source exists as a file, construct image from that file
|
|
38
|
-
if (await exists(source)) {
|
|
39
|
+
if ((!source.startsWith('http') && !source.startsWith('https')) && await exists(source)) {
|
|
39
40
|
return createImage(source, options.alt)
|
|
40
41
|
} else {
|
|
41
42
|
// the source is a remote url here
|
|
42
|
-
source =
|
|
43
|
+
source = new URL(source)
|
|
43
44
|
// attempt to download the remote source and construct image
|
|
44
45
|
const data = await new Promise((resolve, reject) =>
|
|
45
46
|
makeRequest(
|
|
@@ -54,6 +55,24 @@ module.exports = async function loadImage(source, options = {}) {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
if (source instanceof URL) {
|
|
59
|
+
if (source.protocol === 'file:') {
|
|
60
|
+
// remove the leading slash on windows
|
|
61
|
+
return createImage(process.platform === 'win32' ? source.pathname.substring(1) : source.pathname, options.alt)
|
|
62
|
+
} else {
|
|
63
|
+
const data = await new Promise((resolve, reject) =>
|
|
64
|
+
makeRequest(
|
|
65
|
+
source,
|
|
66
|
+
resolve,
|
|
67
|
+
reject,
|
|
68
|
+
typeof options.maxRedirects === 'number' && options.maxRedirects >= 0 ? options.maxRedirects : MAX_REDIRECTS,
|
|
69
|
+
options.requestOptions,
|
|
70
|
+
),
|
|
71
|
+
)
|
|
72
|
+
return createImage(data, options.alt)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
57
76
|
// throw error as don't support that source
|
|
58
77
|
throw new TypeError('unsupported image source')
|
|
59
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/canvas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.66",
|
|
4
4
|
"description": "Canvas for Node.js with skia backend",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -29,19 +29,19 @@
|
|
|
29
29
|
"load-image.js"
|
|
30
30
|
],
|
|
31
31
|
"napi": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
"binaryName": "skia",
|
|
33
|
+
"targets": [
|
|
34
|
+
"x86_64-unknown-linux-gnu",
|
|
35
|
+
"x86_64-apple-darwin",
|
|
36
|
+
"x86_64-pc-windows-msvc",
|
|
37
|
+
"armv7-unknown-linux-gnueabihf",
|
|
38
|
+
"x86_64-unknown-linux-musl",
|
|
39
|
+
"aarch64-unknown-linux-gnu",
|
|
40
|
+
"aarch64-unknown-linux-musl",
|
|
41
|
+
"aarch64-apple-darwin",
|
|
42
|
+
"aarch64-linux-android",
|
|
43
|
+
"riscv64-unknown-linux-gnu"
|
|
44
|
+
]
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">= 10"
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@jimp/custom": "^0.22.10",
|
|
72
72
|
"@jimp/jpeg": "^0.22.10",
|
|
73
73
|
"@jimp/png": "^0.22.10",
|
|
74
|
-
"@napi-rs/cli": "^
|
|
74
|
+
"@napi-rs/cli": "^3.0.0-alpha.70",
|
|
75
75
|
"@octokit/rest": "^21.0.0",
|
|
76
76
|
"@swc-node/register": "^1.8.0",
|
|
77
77
|
"@swc/core": "^1.4.0",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"@types/node": "^20.11.16",
|
|
81
81
|
"@types/semver": "^7",
|
|
82
82
|
"ava": "^6.1.1",
|
|
83
|
-
"canvas": "^
|
|
83
|
+
"canvas": "^3.0.0",
|
|
84
84
|
"canvaskit-wasm": "^0.39.1",
|
|
85
85
|
"colorette": "^2.0.20",
|
|
86
86
|
"conventional-changelog-cli": "^5.0.0",
|
|
@@ -90,13 +90,13 @@
|
|
|
90
90
|
"lint-staged": "^15.2.1",
|
|
91
91
|
"lodash": "^4.17.21",
|
|
92
92
|
"npm-run-all2": "^7.0.0",
|
|
93
|
-
"oxlint": "^0.
|
|
93
|
+
"oxlint": "^0.15.0",
|
|
94
94
|
"pinst": "^3.0.0",
|
|
95
95
|
"png.js": "^0.2.1",
|
|
96
96
|
"prettier": "^3.2.5",
|
|
97
97
|
"pretty-bytes": "^6.1.1",
|
|
98
98
|
"semver": "^7.5.4",
|
|
99
|
-
"skia-canvas": "^
|
|
99
|
+
"skia-canvas": "^2.0.0",
|
|
100
100
|
"table": "^6.8.1",
|
|
101
101
|
"tinybench": "^3.0.6",
|
|
102
102
|
"typescript": "^5.3.3"
|
|
@@ -136,17 +136,17 @@
|
|
|
136
136
|
"singleQuote": true,
|
|
137
137
|
"arrowParens": "always"
|
|
138
138
|
},
|
|
139
|
-
"packageManager": "yarn@4.
|
|
139
|
+
"packageManager": "yarn@4.6.0",
|
|
140
140
|
"optionalDependencies": {
|
|
141
|
-
"@napi-rs/canvas-
|
|
142
|
-
"@napi-rs/canvas-darwin-x64": "0.1.
|
|
143
|
-
"@napi-rs/canvas-
|
|
144
|
-
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.
|
|
145
|
-
"@napi-rs/canvas-linux-x64-musl": "0.1.
|
|
146
|
-
"@napi-rs/canvas-linux-arm64-gnu": "0.1.
|
|
147
|
-
"@napi-rs/canvas-linux-arm64-musl": "0.1.
|
|
148
|
-
"@napi-rs/canvas-darwin-arm64": "0.1.
|
|
149
|
-
"@napi-rs/canvas-android-arm64": "0.1.
|
|
150
|
-
"@napi-rs/canvas-linux-riscv64-gnu": "0.1.
|
|
141
|
+
"@napi-rs/canvas-linux-x64-gnu": "0.1.66",
|
|
142
|
+
"@napi-rs/canvas-darwin-x64": "0.1.66",
|
|
143
|
+
"@napi-rs/canvas-win32-x64-msvc": "0.1.66",
|
|
144
|
+
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.66",
|
|
145
|
+
"@napi-rs/canvas-linux-x64-musl": "0.1.66",
|
|
146
|
+
"@napi-rs/canvas-linux-arm64-gnu": "0.1.66",
|
|
147
|
+
"@napi-rs/canvas-linux-arm64-musl": "0.1.66",
|
|
148
|
+
"@napi-rs/canvas-darwin-arm64": "0.1.66",
|
|
149
|
+
"@napi-rs/canvas-android-arm64": "0.1.66",
|
|
150
|
+
"@napi-rs/canvas-linux-riscv64-gnu": "0.1.66"
|
|
151
151
|
}
|
|
152
152
|
}
|