@napi-rs/canvas 0.1.57 → 0.1.59

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/load-image.js +16 -12
  3. package/package.json +13 -13
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # `skr canvas`
2
2
 
3
3
  ![CI](https://github.com/Brooooooklyn/canvas/workflows/CI/badge.svg)
4
- ![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm130-hotpink)
4
+ ![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm131-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/load-image.js CHANGED
@@ -1,7 +1,8 @@
1
1
  const fs = require('fs')
2
- const { Image } = require('./js-binding')
3
2
  const { Readable } = require('stream')
4
3
 
4
+ const { Image } = require('./js-binding')
5
+
5
6
  let http, https
6
7
 
7
8
  const MAX_REDIRECTS = 20
@@ -13,10 +14,13 @@ const REDIRECT_STATUSES = new Set([301, 302])
13
14
  * @param {object} options Options passed to the loader
14
15
  */
15
16
  module.exports = async function loadImage(source, options = {}) {
17
+ // use the same buffer without copying if the source is a buffer
18
+ if (Buffer.isBuffer(source) || source instanceof Uint8Array) return createImage(source, options.alt)
16
19
  // load readable stream as image
17
20
  if (source instanceof Readable) return createImage(await consumeStream(source), options.alt)
18
- // use the same buffer without copying if the source is a buffer
19
- if (Buffer.isBuffer(source)) return createImage(source, options.alt)
21
+ // construct a Uint8Array if the source is ArrayBuffer or SharedArrayBuffer
22
+ if (source instanceof ArrayBuffer || source instanceof SharedArrayBuffer)
23
+ return createImage(new Uint8Array(source), options.alt)
20
24
  // construct a buffer if the source is buffer-like
21
25
  if (isBufferLike(source)) return createImage(Buffer.from(source), options.alt)
22
26
  // if the source is Image instance, copy the image src to new image
@@ -64,11 +68,17 @@ function makeRequest(url, resolve, reject, redirectCount, requestOptions) {
64
68
  try {
65
69
  const shouldRedirect = REDIRECT_STATUSES.has(res.statusCode) && typeof res.headers.location === 'string'
66
70
  if (shouldRedirect && redirectCount > 0)
67
- return makeRequest(new URL(res.headers.location, url.origin), resolve, reject, redirectCount - 1, requestOptions)
71
+ return makeRequest(
72
+ new URL(res.headers.location, url.origin),
73
+ resolve,
74
+ reject,
75
+ redirectCount - 1,
76
+ requestOptions,
77
+ )
68
78
  if (typeof res.statusCode === 'number' && (res.statusCode < 200 || res.statusCode >= 300)) {
69
79
  return reject(new Error(`remote source rejected with status code ${res.statusCode}`))
70
80
  }
71
-
81
+
72
82
  consumeStream(res).then(resolve, reject)
73
83
  } catch (err) {
74
84
  reject(err)
@@ -99,13 +109,7 @@ function createImage(src, alt) {
99
109
  }
100
110
 
101
111
  function isBufferLike(src) {
102
- return (
103
- (src && src.type === 'Buffer') ||
104
- Array.isArray(src) ||
105
- src instanceof ArrayBuffer ||
106
- src instanceof SharedArrayBuffer ||
107
- src instanceof Object.getPrototypeOf(Uint8Array)
108
- )
112
+ return (src && src.type === 'Buffer') || Array.isArray(src)
109
113
  }
110
114
 
111
115
  async function exists(path) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/canvas",
3
- "version": "0.1.57",
3
+ "version": "0.1.59",
4
4
  "description": "Canvas for Node.js with skia backend",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -89,8 +89,8 @@
89
89
  "husky": "^9.0.10",
90
90
  "lint-staged": "^15.2.1",
91
91
  "lodash": "^4.17.21",
92
- "npm-run-all2": "^6.1.2",
93
- "oxlint": "^0.9.0",
92
+ "npm-run-all2": "^7.0.0",
93
+ "oxlint": "^0.10.0",
94
94
  "pinst": "^3.0.0",
95
95
  "png.js": "^0.2.1",
96
96
  "prettier": "^3.2.5",
@@ -135,16 +135,16 @@
135
135
  "singleQuote": true,
136
136
  "arrowParens": "always"
137
137
  },
138
- "packageManager": "yarn@4.5.0",
138
+ "packageManager": "yarn@4.5.1",
139
139
  "optionalDependencies": {
140
- "@napi-rs/canvas-win32-x64-msvc": "0.1.57",
141
- "@napi-rs/canvas-darwin-x64": "0.1.57",
142
- "@napi-rs/canvas-linux-x64-gnu": "0.1.57",
143
- "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.57",
144
- "@napi-rs/canvas-linux-x64-musl": "0.1.57",
145
- "@napi-rs/canvas-linux-arm64-gnu": "0.1.57",
146
- "@napi-rs/canvas-linux-arm64-musl": "0.1.57",
147
- "@napi-rs/canvas-darwin-arm64": "0.1.57",
148
- "@napi-rs/canvas-android-arm64": "0.1.57"
140
+ "@napi-rs/canvas-win32-x64-msvc": "0.1.59",
141
+ "@napi-rs/canvas-darwin-x64": "0.1.59",
142
+ "@napi-rs/canvas-linux-x64-gnu": "0.1.59",
143
+ "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.59",
144
+ "@napi-rs/canvas-linux-x64-musl": "0.1.59",
145
+ "@napi-rs/canvas-linux-arm64-gnu": "0.1.59",
146
+ "@napi-rs/canvas-linux-arm64-musl": "0.1.59",
147
+ "@napi-rs/canvas-darwin-arm64": "0.1.59",
148
+ "@napi-rs/canvas-android-arm64": "0.1.59"
149
149
  }
150
150
  }