@napi-rs/canvas 0.1.98 → 0.1.100
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/load-image.js +11 -0
- package/package.json +22 -14
package/load-image.js
CHANGED
|
@@ -31,6 +31,10 @@ module.exports = async function loadImage(source, options = {}) {
|
|
|
31
31
|
const commaIdx = source.indexOf(',')
|
|
32
32
|
const encoding = source.lastIndexOf('base64', commaIdx) < 0 ? 'utf-8' : 'base64'
|
|
33
33
|
const data = Buffer.from(source.slice(commaIdx + 1), encoding)
|
|
34
|
+
// Empty payload would silently complete on Image (HTML spec) and the loadImage
|
|
35
|
+
// promise would never settle; reject upfront instead.
|
|
36
|
+
// See https://github.com/Brooooooklyn/canvas/issues/1255
|
|
37
|
+
if (data.length === 0) throw new Error(`Invalid data URI: empty payload in ${source.slice(0, 64)}`)
|
|
34
38
|
return createImage(data, options.alt)
|
|
35
39
|
}
|
|
36
40
|
// if source is a string or URL instance
|
|
@@ -118,6 +122,13 @@ function consumeStream(res) {
|
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
async function createImage(src, alt) {
|
|
125
|
+
// Empty Buffer / Uint8Array: Image follows the HTML spec (silent completion,
|
|
126
|
+
// no events) so the promise below would hang. Reject upfront.
|
|
127
|
+
// See https://github.com/Brooooooklyn/canvas/issues/1255
|
|
128
|
+
if ((Buffer.isBuffer(src) || src instanceof Uint8Array) && src.length === 0) {
|
|
129
|
+
throw new Error('loadImage: empty image data')
|
|
130
|
+
}
|
|
131
|
+
|
|
121
132
|
const image = new Image()
|
|
122
133
|
if (typeof alt === 'string') image.alt = alt
|
|
123
134
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/canvas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.100",
|
|
4
4
|
"description": "Canvas for Node.js with skia backend",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"lodash": "^4.17.21",
|
|
102
102
|
"npm-run-all2": "^8.0.4",
|
|
103
103
|
"oxlint": "^1.34.0",
|
|
104
|
-
"oxlint-tsgolint": "^0.
|
|
104
|
+
"oxlint-tsgolint": "^0.22.0",
|
|
105
105
|
"pinst": "^3.0.0",
|
|
106
106
|
"png.js": "^0.2.1",
|
|
107
107
|
"prettier": "^3.7.4",
|
|
@@ -151,18 +151,26 @@
|
|
|
151
151
|
"type": "github",
|
|
152
152
|
"url": "https://github.com/sponsors/Brooooooklyn"
|
|
153
153
|
},
|
|
154
|
-
"packageManager": "yarn@4.
|
|
154
|
+
"packageManager": "yarn@4.14.1",
|
|
155
|
+
"dependenciesMeta": {
|
|
156
|
+
"canvas": {
|
|
157
|
+
"built": true
|
|
158
|
+
},
|
|
159
|
+
"skia-canvas": {
|
|
160
|
+
"built": true
|
|
161
|
+
}
|
|
162
|
+
},
|
|
155
163
|
"optionalDependencies": {
|
|
156
|
-
"@napi-rs/canvas-linux-x64-gnu": "0.1.
|
|
157
|
-
"@napi-rs/canvas-darwin-x64": "0.1.
|
|
158
|
-
"@napi-rs/canvas-win32-x64-msvc": "0.1.
|
|
159
|
-
"@napi-rs/canvas-win32-arm64-msvc": "0.1.
|
|
160
|
-
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.
|
|
161
|
-
"@napi-rs/canvas-linux-x64-musl": "0.1.
|
|
162
|
-
"@napi-rs/canvas-linux-arm64-gnu": "0.1.
|
|
163
|
-
"@napi-rs/canvas-linux-arm64-musl": "0.1.
|
|
164
|
-
"@napi-rs/canvas-darwin-arm64": "0.1.
|
|
165
|
-
"@napi-rs/canvas-android-arm64": "0.1.
|
|
166
|
-
"@napi-rs/canvas-linux-riscv64-gnu": "0.1.
|
|
164
|
+
"@napi-rs/canvas-linux-x64-gnu": "0.1.100",
|
|
165
|
+
"@napi-rs/canvas-darwin-x64": "0.1.100",
|
|
166
|
+
"@napi-rs/canvas-win32-x64-msvc": "0.1.100",
|
|
167
|
+
"@napi-rs/canvas-win32-arm64-msvc": "0.1.100",
|
|
168
|
+
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.100",
|
|
169
|
+
"@napi-rs/canvas-linux-x64-musl": "0.1.100",
|
|
170
|
+
"@napi-rs/canvas-linux-arm64-gnu": "0.1.100",
|
|
171
|
+
"@napi-rs/canvas-linux-arm64-musl": "0.1.100",
|
|
172
|
+
"@napi-rs/canvas-darwin-arm64": "0.1.100",
|
|
173
|
+
"@napi-rs/canvas-android-arm64": "0.1.100",
|
|
174
|
+
"@napi-rs/canvas-linux-riscv64-gnu": "0.1.100"
|
|
167
175
|
}
|
|
168
176
|
}
|