@napi-rs/canvas 0.1.70 → 0.1.72

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
@@ -1,7 +1,7 @@
1
1
  # `skr canvas`
2
2
 
3
3
  [![CI](https://github.com/Brooooooklyn/canvas/actions/workflows/CI.yaml/badge.svg)](https://github.com/Brooooooklyn/canvas/actions/workflows/CI.yaml)
4
- ![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm136-hotpink)
4
+ ![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm138-hotpink)
5
5
  [![install size](https://packagephobia.com/badge?p=@napi-rs/canvas)](https://packagephobia.com/result?p=@napi-rs/canvas)
6
6
  [![Downloads](https://img.shields.io/npm/dm/@napi-rs/canvas.svg?sanitize=true)](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true)
7
7
 
package/geometry.js CHANGED
@@ -473,7 +473,7 @@ class DOMMatrix {
473
473
  console.info([mat.slice(0, 4), mat.slice(4, 8), mat.slice(8, 12), mat.slice(12, 16)])
474
474
  }
475
475
 
476
- [inspect.custom](depth, options) {
476
+ [inspect.custom](depth) {
477
477
  if (depth < 0) return '[DOMMatrix]'
478
478
 
479
479
  const { a, b, c, d, e, f, is2D, isIdentity } = this
package/index.js CHANGED
@@ -59,6 +59,37 @@ CanvasRenderingContext2D.prototype.getTransform = function getTransform() {
59
59
  return new DOMMatrix([a, b, c, d, e, f])
60
60
  }
61
61
 
62
+ // Workaround for webpack bundling issue with drawImage
63
+ // Store the original drawImage method
64
+ const _drawImage = CanvasRenderingContext2D.prototype.drawImage
65
+
66
+ // Override drawImage to ensure proper type recognition in bundled environments
67
+ CanvasRenderingContext2D.prototype.drawImage = function drawImage(image, ...args) {
68
+ // If the image is a Canvas-like object but not recognized due to bundling,
69
+ // we need to ensure it's properly identified
70
+ if (image && typeof image === 'object') {
71
+ // First check if it's a wrapped canvas object
72
+ if (image.canvas instanceof CanvasElement || image.canvas instanceof SVGCanvas) {
73
+ image = image.canvas
74
+ } else if (image._canvas instanceof CanvasElement || image._canvas instanceof SVGCanvas) {
75
+ image = image._canvas
76
+ }
77
+ // Then check if it's a Canvas-like object by checking for getContext method
78
+ else if (typeof image.getContext === 'function' && image.width && image.height) {
79
+ // If it has canvas properties but isn't recognized as CanvasElement or SVGCanvas,
80
+ // try to correct the prototype chain
81
+ if (!(image instanceof CanvasElement) && !(image instanceof SVGCanvas)) {
82
+ // Try to create a proper CanvasElement from the canvas-like object
83
+ // This helps when webpack has transformed the prototype chain
84
+ Object.setPrototypeOf(image, CanvasElement.prototype)
85
+ }
86
+ }
87
+ }
88
+
89
+ // Call the original drawImage with the potentially corrected image
90
+ return _drawImage.apply(this, [image, ...args])
91
+ }
92
+
62
93
  function createCanvas(width, height, flag) {
63
94
  const isSvgBackend = typeof flag !== 'undefined'
64
95
  return isSvgBackend ? new SVGCanvas(width, height, flag) : new CanvasElement(width, height)
@@ -111,4 +142,7 @@ module.exports = {
111
142
  DOMRect,
112
143
  loadImage,
113
144
  FontKey,
145
+ // Export these for better webpack compatibility
146
+ CanvasElement,
147
+ SVGCanvas,
114
148
  }
package/js-binding.js CHANGED
@@ -59,9 +59,9 @@ const isMuslFromChildProcess = () => {
59
59
  function requireNative() {
60
60
  if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
61
61
  try {
62
- nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
62
+ nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
63
63
  } catch (err) {
64
- loadErrors.push(err);
64
+ loadErrors.push(err)
65
65
  }
66
66
  } else if (process.platform === 'android') {
67
67
  if (process.arch === 'arm64') {
@@ -75,7 +75,6 @@ function requireNative() {
75
75
  } catch (e) {
76
76
  loadErrors.push(e)
77
77
  }
78
-
79
78
  } else if (process.arch === 'arm') {
80
79
  try {
81
80
  return require('./skia.android-arm-eabi.node')
@@ -87,7 +86,6 @@ function requireNative() {
87
86
  } catch (e) {
88
87
  loadErrors.push(e)
89
88
  }
90
-
91
89
  } else {
92
90
  loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
93
91
  }
@@ -103,7 +101,6 @@ function requireNative() {
103
101
  } catch (e) {
104
102
  loadErrors.push(e)
105
103
  }
106
-
107
104
  } else if (process.arch === 'ia32') {
108
105
  try {
109
106
  return require('./skia.win32-ia32-msvc.node')
@@ -115,7 +112,6 @@ function requireNative() {
115
112
  } catch (e) {
116
113
  loadErrors.push(e)
117
114
  }
118
-
119
115
  } else if (process.arch === 'arm64') {
120
116
  try {
121
117
  return require('./skia.win32-arm64-msvc.node')
@@ -127,21 +123,20 @@ function requireNative() {
127
123
  } catch (e) {
128
124
  loadErrors.push(e)
129
125
  }
130
-
131
126
  } else {
132
127
  loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
133
128
  }
134
129
  } else if (process.platform === 'darwin') {
135
130
  try {
136
- return require('./skia.darwin-universal.node')
137
- } catch (e) {
138
- loadErrors.push(e)
139
- }
140
- try {
141
- return require('@napi-rs/canvas-darwin-universal')
142
- } catch (e) {
143
- loadErrors.push(e)
144
- }
131
+ return require('./skia.darwin-universal.node')
132
+ } catch (e) {
133
+ loadErrors.push(e)
134
+ }
135
+ try {
136
+ return require('@napi-rs/canvas-darwin-universal')
137
+ } catch (e) {
138
+ loadErrors.push(e)
139
+ }
145
140
 
146
141
  if (process.arch === 'x64') {
147
142
  try {
@@ -154,7 +149,6 @@ function requireNative() {
154
149
  } catch (e) {
155
150
  loadErrors.push(e)
156
151
  }
157
-
158
152
  } else if (process.arch === 'arm64') {
159
153
  try {
160
154
  return require('./skia.darwin-arm64.node')
@@ -166,7 +160,6 @@ function requireNative() {
166
160
  } catch (e) {
167
161
  loadErrors.push(e)
168
162
  }
169
-
170
163
  } else {
171
164
  loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
172
165
  }
@@ -182,7 +175,6 @@ function requireNative() {
182
175
  } catch (e) {
183
176
  loadErrors.push(e)
184
177
  }
185
-
186
178
  } else if (process.arch === 'arm64') {
187
179
  try {
188
180
  return require('./skia.freebsd-arm64.node')
@@ -194,7 +186,6 @@ function requireNative() {
194
186
  } catch (e) {
195
187
  loadErrors.push(e)
196
188
  }
197
-
198
189
  } else {
199
190
  loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
200
191
  }
@@ -202,106 +193,98 @@ function requireNative() {
202
193
  if (process.arch === 'x64') {
203
194
  if (isMusl()) {
204
195
  try {
205
- return require('./skia.linux-x64-musl.node')
206
- } catch (e) {
207
- loadErrors.push(e)
208
- }
209
- try {
210
- return require('@napi-rs/canvas-linux-x64-musl')
211
- } catch (e) {
212
- loadErrors.push(e)
213
- }
214
-
196
+ return require('./skia.linux-x64-musl.node')
197
+ } catch (e) {
198
+ loadErrors.push(e)
199
+ }
200
+ try {
201
+ return require('@napi-rs/canvas-linux-x64-musl')
202
+ } catch (e) {
203
+ loadErrors.push(e)
204
+ }
215
205
  } else {
216
206
  try {
217
- return require('./skia.linux-x64-gnu.node')
218
- } catch (e) {
219
- loadErrors.push(e)
220
- }
221
- try {
222
- return require('@napi-rs/canvas-linux-x64-gnu')
223
- } catch (e) {
224
- loadErrors.push(e)
225
- }
226
-
207
+ return require('./skia.linux-x64-gnu.node')
208
+ } catch (e) {
209
+ loadErrors.push(e)
210
+ }
211
+ try {
212
+ return require('@napi-rs/canvas-linux-x64-gnu')
213
+ } catch (e) {
214
+ loadErrors.push(e)
215
+ }
227
216
  }
228
217
  } else if (process.arch === 'arm64') {
229
218
  if (isMusl()) {
230
219
  try {
231
- return require('./skia.linux-arm64-musl.node')
232
- } catch (e) {
233
- loadErrors.push(e)
234
- }
235
- try {
236
- return require('@napi-rs/canvas-linux-arm64-musl')
237
- } catch (e) {
238
- loadErrors.push(e)
239
- }
240
-
220
+ return require('./skia.linux-arm64-musl.node')
221
+ } catch (e) {
222
+ loadErrors.push(e)
223
+ }
224
+ try {
225
+ return require('@napi-rs/canvas-linux-arm64-musl')
226
+ } catch (e) {
227
+ loadErrors.push(e)
228
+ }
241
229
  } else {
242
230
  try {
243
- return require('./skia.linux-arm64-gnu.node')
244
- } catch (e) {
245
- loadErrors.push(e)
246
- }
247
- try {
248
- return require('@napi-rs/canvas-linux-arm64-gnu')
249
- } catch (e) {
250
- loadErrors.push(e)
251
- }
252
-
231
+ return require('./skia.linux-arm64-gnu.node')
232
+ } catch (e) {
233
+ loadErrors.push(e)
234
+ }
235
+ try {
236
+ return require('@napi-rs/canvas-linux-arm64-gnu')
237
+ } catch (e) {
238
+ loadErrors.push(e)
239
+ }
253
240
  }
254
241
  } else if (process.arch === 'arm') {
255
242
  if (isMusl()) {
256
243
  try {
257
- return require('./skia.linux-arm-musleabihf.node')
258
- } catch (e) {
259
- loadErrors.push(e)
260
- }
261
- try {
262
- return require('@napi-rs/canvas-linux-arm-musleabihf')
263
- } catch (e) {
264
- loadErrors.push(e)
265
- }
266
-
244
+ return require('./skia.linux-arm-musleabihf.node')
245
+ } catch (e) {
246
+ loadErrors.push(e)
247
+ }
248
+ try {
249
+ return require('@napi-rs/canvas-linux-arm-musleabihf')
250
+ } catch (e) {
251
+ loadErrors.push(e)
252
+ }
267
253
  } else {
268
254
  try {
269
- return require('./skia.linux-arm-gnueabihf.node')
270
- } catch (e) {
271
- loadErrors.push(e)
272
- }
273
- try {
274
- return require('@napi-rs/canvas-linux-arm-gnueabihf')
275
- } catch (e) {
276
- loadErrors.push(e)
277
- }
278
-
255
+ return require('./skia.linux-arm-gnueabihf.node')
256
+ } catch (e) {
257
+ loadErrors.push(e)
258
+ }
259
+ try {
260
+ return require('@napi-rs/canvas-linux-arm-gnueabihf')
261
+ } catch (e) {
262
+ loadErrors.push(e)
263
+ }
279
264
  }
280
265
  } else if (process.arch === 'riscv64') {
281
266
  if (isMusl()) {
282
267
  try {
283
- return require('./skia.linux-riscv64-musl.node')
284
- } catch (e) {
285
- loadErrors.push(e)
286
- }
287
- try {
288
- return require('@napi-rs/canvas-linux-riscv64-musl')
289
- } catch (e) {
290
- loadErrors.push(e)
291
- }
292
-
268
+ return require('./skia.linux-riscv64-musl.node')
269
+ } catch (e) {
270
+ loadErrors.push(e)
271
+ }
272
+ try {
273
+ return require('@napi-rs/canvas-linux-riscv64-musl')
274
+ } catch (e) {
275
+ loadErrors.push(e)
276
+ }
293
277
  } else {
294
278
  try {
295
- return require('./skia.linux-riscv64-gnu.node')
296
- } catch (e) {
297
- loadErrors.push(e)
298
- }
299
- try {
300
- return require('@napi-rs/canvas-linux-riscv64-gnu')
301
- } catch (e) {
302
- loadErrors.push(e)
303
- }
304
-
279
+ return require('./skia.linux-riscv64-gnu.node')
280
+ } catch (e) {
281
+ loadErrors.push(e)
282
+ }
283
+ try {
284
+ return require('@napi-rs/canvas-linux-riscv64-gnu')
285
+ } catch (e) {
286
+ loadErrors.push(e)
287
+ }
305
288
  }
306
289
  } else if (process.arch === 'ppc64') {
307
290
  try {
@@ -314,7 +297,6 @@ function requireNative() {
314
297
  } catch (e) {
315
298
  loadErrors.push(e)
316
299
  }
317
-
318
300
  } else if (process.arch === 's390x') {
319
301
  try {
320
302
  return require('./skia.linux-s390x-gnu.node')
@@ -326,7 +308,6 @@ function requireNative() {
326
308
  } catch (e) {
327
309
  loadErrors.push(e)
328
310
  }
329
-
330
311
  } else {
331
312
  loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
332
313
  }
package/load-image.js CHANGED
@@ -36,7 +36,7 @@ module.exports = async function loadImage(source, options = {}) {
36
36
  // if source is a string or URL instance
37
37
  if (typeof source === 'string') {
38
38
  // if the source exists as a file, construct image from that file
39
- if ((!source.startsWith('http') && !source.startsWith('https')) && await exists(source)) {
39
+ if (!source.startsWith('http') && !source.startsWith('https') && (await exists(source))) {
40
40
  return createImage(source, options.alt)
41
41
  } else {
42
42
  // the source is a remote url here
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@napi-rs/canvas",
3
- "version": "0.1.70",
3
+ "version": "0.1.72",
4
4
  "description": "Canvas for Node.js with skia backend",
5
5
  "main": "index.js",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/Brooooooklyn/canvas.git"
9
9
  },
10
+ "workspaces": [
11
+ "e2e/*"
12
+ ],
10
13
  "license": "MIT",
11
14
  "keywords": [
12
15
  "napi-rs",
@@ -64,42 +67,43 @@
64
67
  "postpublish": "pinst --enable",
65
68
  "test:ci": "ava -c 1",
66
69
  "test": "ava",
70
+ "e2e": "yarn workspace @napi-rs/canvas-e2e-webpack test",
67
71
  "version": "napi version && conventional-changelog -p angular -i CHANGELOG.md -s && git add ."
68
72
  },
69
73
  "devDependencies": {
70
- "@jimp/core": "^1.0.0",
71
- "@jimp/custom": "^0.22.10",
72
- "@jimp/jpeg": "^0.22.10",
73
- "@jimp/png": "^0.22.10",
74
- "@napi-rs/cli": "^3.0.0-alpha.70",
75
- "@octokit/rest": "^21.0.0",
76
- "@swc-node/register": "^1.8.0",
77
- "@swc/core": "^1.4.0",
74
+ "@jimp/core": "^1.6.0",
75
+ "@jimp/custom": "^0.22.12",
76
+ "@jimp/jpeg": "^0.22.12",
77
+ "@jimp/png": "^0.22.12",
78
+ "@napi-rs/cli": "^3.0.0-alpha.91",
79
+ "@octokit/rest": "^22.0.0",
80
+ "@swc-node/register": "^1.10.10",
81
+ "@swc/core": "^1.11.31",
78
82
  "@taplo/cli": "^0.7.0",
79
- "@types/lodash": "^4.14.202",
80
- "@types/node": "^20.11.16",
83
+ "@types/lodash": "^4.17.17",
84
+ "@types/node": "^22.15.30",
81
85
  "@types/semver": "^7",
82
- "ava": "^6.1.1",
83
- "canvas": "^3.0.0",
86
+ "ava": "^6.3.0",
87
+ "canvas": "^3.1.0",
84
88
  "canvaskit-wasm": "^0.40.0",
85
89
  "colorette": "^2.0.20",
86
90
  "conventional-changelog-cli": "^5.0.0",
87
- "core-js": "^3.38.0",
88
- "echarts": "^5.4.3",
89
- "husky": "^9.0.10",
90
- "lint-staged": "^15.2.1",
91
+ "core-js": "^3.42.0",
92
+ "echarts": "^5.6.0",
93
+ "husky": "^9.1.7",
94
+ "lint-staged": "^16.1.0",
91
95
  "lodash": "^4.17.21",
92
- "npm-run-all2": "^7.0.0",
93
- "oxlint": "^0.16.0",
96
+ "npm-run-all2": "^8.0.4",
97
+ "oxlint": "^1.0.0",
94
98
  "pinst": "^3.0.0",
95
99
  "png.js": "^0.2.1",
96
- "prettier": "^3.2.5",
100
+ "prettier": "^3.5.3",
97
101
  "pretty-bytes": "^7.0.0",
98
- "semver": "^7.5.4",
99
- "skia-canvas": "^2.0.0",
100
- "table": "^6.8.1",
101
- "tinybench": "^4.0.0",
102
- "typescript": "^5.3.3"
102
+ "semver": "^7.7.2",
103
+ "skia-canvas": "^2.0.2",
104
+ "table": "^6.9.0",
105
+ "tinybench": "^4.0.1",
106
+ "typescript": "^5.8.3"
103
107
  },
104
108
  "lint-staged": {
105
109
  "*.@(js|ts|tsx|yml|yaml|md|json|html)": [
@@ -136,17 +140,17 @@
136
140
  "singleQuote": true,
137
141
  "arrowParens": "always"
138
142
  },
139
- "packageManager": "yarn@4.9.1",
143
+ "packageManager": "yarn@4.9.2",
140
144
  "optionalDependencies": {
141
- "@napi-rs/canvas-linux-x64-gnu": "0.1.70",
142
- "@napi-rs/canvas-darwin-x64": "0.1.70",
143
- "@napi-rs/canvas-win32-x64-msvc": "0.1.70",
144
- "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.70",
145
- "@napi-rs/canvas-linux-x64-musl": "0.1.70",
146
- "@napi-rs/canvas-linux-arm64-gnu": "0.1.70",
147
- "@napi-rs/canvas-linux-arm64-musl": "0.1.70",
148
- "@napi-rs/canvas-darwin-arm64": "0.1.70",
149
- "@napi-rs/canvas-android-arm64": "0.1.70",
150
- "@napi-rs/canvas-linux-riscv64-gnu": "0.1.70"
145
+ "@napi-rs/canvas-linux-x64-gnu": "0.1.72",
146
+ "@napi-rs/canvas-darwin-x64": "0.1.72",
147
+ "@napi-rs/canvas-win32-x64-msvc": "0.1.72",
148
+ "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.72",
149
+ "@napi-rs/canvas-linux-x64-musl": "0.1.72",
150
+ "@napi-rs/canvas-linux-arm64-gnu": "0.1.72",
151
+ "@napi-rs/canvas-linux-arm64-musl": "0.1.72",
152
+ "@napi-rs/canvas-darwin-arm64": "0.1.72",
153
+ "@napi-rs/canvas-android-arm64": "0.1.72",
154
+ "@napi-rs/canvas-linux-riscv64-gnu": "0.1.72"
151
155
  }
152
156
  }