@napi-rs/canvas 0.1.61 → 0.1.63

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 CHANGED
@@ -131,50 +131,44 @@ See [benchmark](./benchmark) for benchmark code.
131
131
  Hardware info:
132
132
 
133
133
  ```
134
- OS: Windows 10 x86_64
135
- Host: Micro-Star International Co., Ltd. MS-7C35
136
- Kernel: 10.0.19043
137
- Terminal: Windows Terminal
138
- CPU: AMD Ryzen 9 5950X (32) @ 3.400GHz
139
- Memory: 32688MiB
134
+ ,MMMM. Host - xxxxxxxxxxxxxxxxxxxxxxx
135
+ .MMMMMM Machine - Mac15,9
136
+ MMMMM, Kernel - 24.0.0
137
+ .;MMMMM:' MMMMMMMMMM;. OS - macOS 15.0.1 Sequoia
138
+ MMMMMMMMMMMMNWMMMMMMMMMMM: DE - Aqua
139
+ .MMMMMMMMMMMMMMMMMMMMMMMMWM. WM - Quartz Compositor
140
+ MMMMMMMMMMMMMMMMMMMMMMMMM. Packages - 194 (Homebrew), 32 (cargo)
141
+ ;MMMMMMMMMMMMMMMMMMMMMMMM: Shell - zsh
142
+ :MMMMMMMMMMMMMMMMMMMMMMMM: Terminal - warpterminal (Version v0.2024.10.23.14.49.stable_00)
143
+ .MMMMMMMMMMMMMMMMMMMMMMMMM. Resolution - 5120x2880@160fps (as 2560x1440)
144
+ MMMMMMMMMMMMMMMMMMMMMMMMMMM. 2992x1934@120fps (as 1496x967)
145
+ .MMMMMMMMMMMMMMMMMMMMMMMMMM. 2232x1512@60fps (as 1116x756)
146
+ MMMMMMMMMMMMMMMMMMMMMMMM Uptime - 1d 2h 32m
147
+ ;MMMMMMMMMMMMMMMMMMMM. CPU - Apple M3 Max (16)
148
+ .MMMM,. .MMMM,. CPU Load - 16%
149
+ Memory - 50.1 GB / 134.2 GB
150
+ Battery - 78% & Discharging
151
+ Disk Space - 624.0 GB / 994.7 GB
140
152
  ```
141
153
 
142
154
  ```
143
155
  ❯ yarn bench
144
-
145
- > @napi-rs/canvas@0.0.9 bench D:\workspace\skia-rs
146
- > node -r @swc-node/register benchmark/bench.ts
147
-
148
- Running "Draw house" suite...
149
- Progress: 100%
150
-
151
- skia-canvas:
152
- 26 ops/s, ±0.70% | slowest, 29.73% slower
153
-
154
- node-canvas:
155
- 30 ops/s, ±6.95% | 18.92% slower
156
-
157
- @napi-rs/canvas:
158
- 37 ops/s, ±6.30% | fastest
159
-
160
- Finished 3 cases!
161
- Fastest: @napi-rs/canvas
162
- Slowest: skia-canvas
163
- Running "Draw gradient" suite...
164
- Progress: 100%
165
-
166
- skia-canvas:
167
- 36 ops/s, ±6.12% | 14.29% slower
168
-
169
- node-canvas:
170
- 34 ops/s, ±5.60% | slowest, 19.05% slower
171
-
172
- @napi-rs/canvas:
173
- 42 ops/s, ±0.53% | fastest
174
-
175
- Finished 3 cases!
176
- Fastest: @napi-rs/canvas
177
- Slowest: node-canvas
156
+ Draw a House and export to PNG
157
+ ┌─────────┬─────────────────┬───────────────────────┬──────────────────────────┬────────────────────────────┬───────────────────────────┬─────────┐
158
+ │ (index) │ Task name │ Latency average (ns) │ Latency median (ns) │ Throughput average (ops/s) │ Throughput median (ops/s) │ Samples │
159
+ ├─────────┼─────────────────┼───────────────────────┼──────────────────────────┼────────────────────────────┼───────────────────────────┼─────────┤
160
+ │ 0 │ '@napi-rs/skia' │ '14676992.14 ± 0.68%' │ '14602333.00' │ '68 ± 0.59%' │ '68' │ 69 │
161
+ │ 1 │ 'skia-canvas' │ '21167809.17 ± 2.05%' │ '20960021.00 ± 13646.00' │ '47 ± 1.31%' │ '48' │ 64 │
162
+ │ 2 │ 'node-canvas' │ '16552027.42 ± 0.70%' │ '16451291.50 ± 2208.50' │ '60 ± 0.62%' │ '61' │ 64 │
163
+ └─────────┴─────────────────┴───────────────────────┴──────────────────────────┴────────────────────────────┴───────────────────────────┴─────────┘
164
+ Draw Gradient and export to PNG
165
+ ┌─────────┬─────────────────┬───────────────────────┬─────────────────────────┬────────────────────────────┬───────────────────────────┬─────────┐
166
+ │ (index) │ Task name │ Latency average (ns) │ Latency median (ns) │ Throughput average (ops/s) │ Throughput median (ops/s) │ Samples │
167
+ ├─────────┼─────────────────┼───────────────────────┼─────────────────────────┼────────────────────────────┼───────────────────────────┼─────────┤
168
+ │ 0 │ '@napi-rs/skia' │ '15228495.58 ± 0.53%' │ '15146312.50 ± 1187.50' │ '66 ± 0.48%' │ '66' │ 66 │
169
+ │ 1 │ 'skia-canvas' │ '21725564.41 ± 2.20%' │ '21412520.50 ± 2104.50' │ '46 ± 1.39%' │ '47' │ 64 │
170
+ │ 2 │ 'node-canvas' │ '17976022.14 ± 1.53%' │ '17563479.50 ± 5104.50' │ '56 ± 1.38%' │ '57' │ 64 │
171
+ └─────────┴─────────────────┴───────────────────────┴─────────────────────────┴────────────────────────────┴───────────────────────────┴─────────┘
178
172
  ```
179
173
 
180
174
  # Features
package/index.d.ts CHANGED
@@ -195,7 +195,9 @@ export class Image {
195
195
  readonly naturalHeight: number
196
196
  readonly complete: boolean
197
197
  alt: string
198
- src: Buffer
198
+ // the src can be a Uint8Array or a string
199
+ // if it's a string, it can be a file path, a data URL, a remote URL, or a SVG string
200
+ src: Uint8Array | string
199
201
  onload?(): void
200
202
  onerror?(err: Error): void
201
203
  }
package/js-binding.js CHANGED
@@ -203,6 +203,18 @@ switch (platform) {
203
203
  loadError = e
204
204
  }
205
205
  break
206
+ case 'riscv64':
207
+ localFileExisted = existsSync(join(__dirname, 'skia.linux-riscv64-gnu.node'))
208
+ try {
209
+ if (localFileExisted) {
210
+ nativeBinding = require('./skia.linux-riscv64-gnu.node')
211
+ } else {
212
+ nativeBinding = require('@napi-rs/canvas-linux-riscv64-gnu')
213
+ }
214
+ } catch (e) {
215
+ loadError = e
216
+ }
217
+ break
206
218
  default:
207
219
  throw new Error(`Unsupported architecture on Linux: ${arch}`)
208
220
  }
package/load-image.js CHANGED
@@ -36,7 +36,7 @@ module.exports = async function loadImage(source, options = {}) {
36
36
  if (typeof source === 'string' || source instanceof URL) {
37
37
  // if the source exists as a file, construct image from that file
38
38
  if (await exists(source)) {
39
- return createImage(await fs.promises.readFile(source), options.alt)
39
+ return createImage(source, options.alt)
40
40
  } else {
41
41
  // the source is a remote url here
42
42
  source = !(source instanceof URL) ? new URL(source) : source
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/canvas",
3
- "version": "0.1.61",
3
+ "version": "0.1.63",
4
4
  "description": "Canvas for Node.js with skia backend",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -38,7 +38,8 @@
38
38
  "aarch64-unknown-linux-gnu",
39
39
  "aarch64-unknown-linux-musl",
40
40
  "aarch64-apple-darwin",
41
- "aarch64-linux-android"
41
+ "aarch64-linux-android",
42
+ "riscv64-unknown-linux-gnu"
42
43
  ]
43
44
  }
44
45
  },
@@ -79,7 +80,6 @@
79
80
  "@types/node": "^20.11.16",
80
81
  "@types/semver": "^7",
81
82
  "ava": "^6.1.1",
82
- "benny": "^3.7.1",
83
83
  "canvas": "^2.11.2",
84
84
  "canvaskit-wasm": "^0.39.1",
85
85
  "colorette": "^2.0.20",
@@ -90,7 +90,7 @@
90
90
  "lint-staged": "^15.2.1",
91
91
  "lodash": "^4.17.21",
92
92
  "npm-run-all2": "^7.0.0",
93
- "oxlint": "^0.11.0",
93
+ "oxlint": "^0.13.0",
94
94
  "pinst": "^3.0.0",
95
95
  "png.js": "^0.2.1",
96
96
  "prettier": "^3.2.5",
@@ -98,6 +98,7 @@
98
98
  "semver": "^7.5.4",
99
99
  "skia-canvas": "^1.0.1",
100
100
  "table": "^6.8.1",
101
+ "tinybench": "^3.0.6",
101
102
  "typescript": "^5.3.3"
102
103
  },
103
104
  "lint-staged": {
@@ -135,16 +136,17 @@
135
136
  "singleQuote": true,
136
137
  "arrowParens": "always"
137
138
  },
138
- "packageManager": "yarn@4.5.1",
139
+ "packageManager": "yarn@4.5.2",
139
140
  "optionalDependencies": {
140
- "@napi-rs/canvas-win32-x64-msvc": "0.1.61",
141
- "@napi-rs/canvas-darwin-x64": "0.1.61",
142
- "@napi-rs/canvas-linux-x64-gnu": "0.1.61",
143
- "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.61",
144
- "@napi-rs/canvas-linux-x64-musl": "0.1.61",
145
- "@napi-rs/canvas-linux-arm64-gnu": "0.1.61",
146
- "@napi-rs/canvas-linux-arm64-musl": "0.1.61",
147
- "@napi-rs/canvas-darwin-arm64": "0.1.61",
148
- "@napi-rs/canvas-android-arm64": "0.1.61"
141
+ "@napi-rs/canvas-win32-x64-msvc": "0.1.63",
142
+ "@napi-rs/canvas-darwin-x64": "0.1.63",
143
+ "@napi-rs/canvas-linux-x64-gnu": "0.1.63",
144
+ "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.63",
145
+ "@napi-rs/canvas-linux-x64-musl": "0.1.63",
146
+ "@napi-rs/canvas-linux-arm64-gnu": "0.1.63",
147
+ "@napi-rs/canvas-linux-arm64-musl": "0.1.63",
148
+ "@napi-rs/canvas-darwin-arm64": "0.1.63",
149
+ "@napi-rs/canvas-android-arm64": "0.1.63",
150
+ "@napi-rs/canvas-linux-riscv64-gnu": "0.1.63"
149
151
  }
150
152
  }