@napi-rs/canvas 0.1.51 → 0.1.53
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/load-image.js +10 -8
- package/package.json +15 -20
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# `skr canvas`
|
|
2
2
|
|
|
3
3
|

|
|
4
|
-

|
|
5
5
|
[](https://packagephobia.com/result?p=@napi-rs/canvas)
|
|
6
6
|
[](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true)
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
Google Skia binding to Node.js via [Node-API](https://napi.rs), **0 System dependencies!**
|
|
11
11
|
|
|
12
|
-
⚠️ This project is in pre-release stage. And there may some bugs
|
|
12
|
+
⚠️ This project is in pre-release stage. And there may be some bugs.<br/>
|
|
13
13
|
For details on planned features and future direction please refer to the [Roadmap](https://github.com/Brooooooklyn/canvas/issues/113).
|
|
14
14
|
|
|
15
15
|
[中文文档](./README-zh.md)
|
package/load-image.js
CHANGED
|
@@ -4,9 +4,8 @@ const { Readable } = require('stream')
|
|
|
4
4
|
|
|
5
5
|
let http, https
|
|
6
6
|
|
|
7
|
-
const MAX_REDIRECTS = 20
|
|
8
|
-
|
|
9
|
-
DATA_URI = /^\s*data:/
|
|
7
|
+
const MAX_REDIRECTS = 20
|
|
8
|
+
const REDIRECT_STATUSES = new Set([301, 302])
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Loads the given source into canvas Image
|
|
@@ -23,7 +22,7 @@ module.exports = async function loadImage(source, options = {}) {
|
|
|
23
22
|
// if the source is Image instance, copy the image src to new image
|
|
24
23
|
if (source instanceof Image) return createImage(source.src, options.alt)
|
|
25
24
|
// if source is string and in data uri format, construct image using data uri
|
|
26
|
-
if (typeof source === 'string' &&
|
|
25
|
+
if (typeof source === 'string' && source.trimStart().startsWith('data:')) {
|
|
27
26
|
const commaIdx = source.indexOf(',')
|
|
28
27
|
const encoding = source.lastIndexOf('base64', commaIdx) < 0 ? 'utf-8' : 'base64'
|
|
29
28
|
const data = Buffer.from(source.slice(commaIdx + 1), encoding)
|
|
@@ -86,10 +85,13 @@ function consumeStream(res) {
|
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
function createImage(src, alt) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
const image = new Image()
|
|
90
|
+
if (typeof alt === 'string') image.alt = alt
|
|
91
|
+
image.onload = () => resolve(image)
|
|
92
|
+
image.onerror = (e) => reject(e)
|
|
93
|
+
image.src = src
|
|
94
|
+
})
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
function isBufferLike(src) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/canvas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.53",
|
|
4
4
|
"description": "Canvas for Node.js with skia backend",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"format:rs": "cargo fmt",
|
|
59
59
|
"format:source": "prettier . -w",
|
|
60
60
|
"format:toml": "taplo format",
|
|
61
|
-
"lint": "
|
|
61
|
+
"lint": "oxlint",
|
|
62
62
|
"prepublishOnly": "pinst --disable && napi prepublish -t npm",
|
|
63
63
|
"postpublish": "pinst --enable",
|
|
64
64
|
"test:ci": "ava -c 1",
|
|
@@ -78,23 +78,18 @@
|
|
|
78
78
|
"@types/lodash": "^4.14.202",
|
|
79
79
|
"@types/node": "^20.11.16",
|
|
80
80
|
"@types/semver": "^7",
|
|
81
|
-
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
82
|
-
"@typescript-eslint/parser": "^7.0.0",
|
|
83
81
|
"ava": "^6.1.1",
|
|
84
82
|
"benny": "^3.7.1",
|
|
85
83
|
"canvas": "^2.11.2",
|
|
86
84
|
"canvaskit-wasm": "^0.39.1",
|
|
87
85
|
"colorette": "^2.0.20",
|
|
88
|
-
"conventional-changelog-cli": "^
|
|
86
|
+
"conventional-changelog-cli": "^5.0.0",
|
|
89
87
|
"echarts": "^5.4.3",
|
|
90
|
-
"eslint": "^8.56.0",
|
|
91
|
-
"eslint-config-prettier": "^9.1.0",
|
|
92
|
-
"eslint-plugin-import": "^2.29.1",
|
|
93
|
-
"eslint-plugin-sonarjs": "^0.24.0",
|
|
94
88
|
"husky": "^9.0.10",
|
|
95
89
|
"lint-staged": "^15.2.1",
|
|
96
90
|
"lodash": "^4.17.21",
|
|
97
91
|
"npm-run-all2": "^6.1.2",
|
|
92
|
+
"oxlint": "^0.4.0",
|
|
98
93
|
"pinst": "^3.0.0",
|
|
99
94
|
"png.js": "^0.2.1",
|
|
100
95
|
"prettier": "^3.2.5",
|
|
@@ -109,7 +104,7 @@
|
|
|
109
104
|
"prettier --write"
|
|
110
105
|
],
|
|
111
106
|
"*.@(js|ts|tsx)": [
|
|
112
|
-
"
|
|
107
|
+
"oxlint --fix"
|
|
113
108
|
]
|
|
114
109
|
},
|
|
115
110
|
"ava": {
|
|
@@ -138,16 +133,16 @@
|
|
|
138
133
|
"singleQuote": true,
|
|
139
134
|
"arrowParens": "always"
|
|
140
135
|
},
|
|
141
|
-
"packageManager": "yarn@4.
|
|
136
|
+
"packageManager": "yarn@4.2.2",
|
|
142
137
|
"optionalDependencies": {
|
|
143
|
-
"@napi-rs/canvas-win32-x64-msvc": "0.1.
|
|
144
|
-
"@napi-rs/canvas-darwin-x64": "0.1.
|
|
145
|
-
"@napi-rs/canvas-linux-x64-gnu": "0.1.
|
|
146
|
-
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.
|
|
147
|
-
"@napi-rs/canvas-linux-x64-musl": "0.1.
|
|
148
|
-
"@napi-rs/canvas-linux-arm64-gnu": "0.1.
|
|
149
|
-
"@napi-rs/canvas-linux-arm64-musl": "0.1.
|
|
150
|
-
"@napi-rs/canvas-darwin-arm64": "0.1.
|
|
151
|
-
"@napi-rs/canvas-android-arm64": "0.1.
|
|
138
|
+
"@napi-rs/canvas-win32-x64-msvc": "0.1.53",
|
|
139
|
+
"@napi-rs/canvas-darwin-x64": "0.1.53",
|
|
140
|
+
"@napi-rs/canvas-linux-x64-gnu": "0.1.53",
|
|
141
|
+
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.53",
|
|
142
|
+
"@napi-rs/canvas-linux-x64-musl": "0.1.53",
|
|
143
|
+
"@napi-rs/canvas-linux-arm64-gnu": "0.1.53",
|
|
144
|
+
"@napi-rs/canvas-linux-arm64-musl": "0.1.53",
|
|
145
|
+
"@napi-rs/canvas-darwin-arm64": "0.1.53",
|
|
146
|
+
"@napi-rs/canvas-android-arm64": "0.1.53"
|
|
152
147
|
}
|
|
153
148
|
}
|