@napi-rs/canvas 0.1.25 → 0.1.26

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/workflows/CI/badge.svg)
4
- ![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm104-hotpink)
4
+ ![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm105-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/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /// <reference lib="dom" />
2
+
1
3
  export interface DOMMatrix2DInit {
2
4
  a: number
3
5
  b: number
@@ -354,7 +356,7 @@ interface IGlobalFonts {
354
356
 
355
357
  export const GlobalFonts: IGlobalFonts
356
358
 
357
- export const enum PathOp {
359
+ export enum PathOp {
358
360
  Difference = 0, // subtract the op path from the first path
359
361
  Intersect = 1, // intersect the two paths
360
362
  Union = 2, // union (inclusive-or) the two paths
@@ -362,26 +364,26 @@ export const enum PathOp {
362
364
  ReverseDifference = 4, // subtract the first path from the op path
363
365
  }
364
366
 
365
- export const enum FillType {
367
+ export enum FillType {
366
368
  Winding = 0,
367
369
  EvenOdd = 1,
368
370
  InverseWinding = 2,
369
371
  InverseEvenOdd = 3,
370
372
  }
371
373
 
372
- export const enum StrokeJoin {
374
+ export enum StrokeJoin {
373
375
  Miter = 0,
374
376
  Round = 1,
375
377
  Bevel = 2,
376
378
  }
377
379
 
378
- export const enum StrokeCap {
380
+ export enum StrokeCap {
379
381
  Butt = 0,
380
382
  Round = 1,
381
383
  Square = 2,
382
384
  }
383
385
 
384
- export const enum SvgExportFlag {
386
+ export enum SvgExportFlag {
385
387
  ConvertTextToPaths = 0x01,
386
388
  NoPrettyXML = 0x02,
387
389
  RelativePathEncoding = 0x04,
@@ -390,9 +392,9 @@ export const enum SvgExportFlag {
390
392
  export function convertSVGTextToPath(svg: Buffer | string): Buffer
391
393
 
392
394
  export interface LoadImageOptions {
393
- alt?: string,
394
- maxRedirects?: number,
395
- requestOptions?: import('http').RequestOptions,
395
+ alt?: string
396
+ maxRedirects?: number
397
+ requestOptions?: import('http').RequestOptions
396
398
  }
397
399
 
398
400
  export function loadImage(
package/index.js CHANGED
@@ -213,87 +213,37 @@ function createCanvas(width, height, flag) {
213
213
  toDataURLAsync: canvasToDataURLAsync,
214
214
  } = Object.getPrototypeOf(canvasElement)
215
215
 
216
- // See also: https://github.com/kornelski/cavif-rs#usage
217
- const avifDefaultQuality = 80
218
- const avifConfig = {
219
- // Quality from 1 (worst) to 100 (best), the default value is 80. The numbers have different meaning than JPEG's quality scale. Beware when comparing codecs. There is no lossless compression support.
220
- quality: avifDefaultQuality,
221
-
222
- // Calculate alphaQuality, this is consistent with cavif.
223
- // https://github.com/kornelski/cavif-rs/blob/37847b95bb81d4cf90e36b7fab2c7fbbcf95abe2/src/main.rs#L97
224
- alphaQuality: Math.min((avifDefaultQuality + 100) / 2, avifDefaultQuality + avifDefaultQuality / 4 + 2),
225
- threads: 0,
226
-
227
- // Encoding speed between 1 (best, but slowest) and 10 (fastest, but a blurry mess), the default value is 4. Speeds 1 and 2 are unbelievably slow, but make files ~3-5% smaller. Speeds 7 and above degrade compression significantly, and are not recommended.
228
- speed: 4,
229
- }
230
-
231
- canvasElement.encode = function encode(type, qualityOrConfig) {
216
+ canvasElement.encode = function encode(type, qualityOrConfig = {}) {
232
217
  if (type === 'avif') {
233
- return canvasEncode.call(
234
- this,
235
- type,
236
- JSON.stringify({
237
- ...avifConfig,
238
- ...(qualityOrConfig || {}),
239
- }),
240
- )
218
+ return canvasEncode.call(this, type, JSON.stringify(qualityOrConfig))
241
219
  }
242
220
  return canvasEncode.call(this, type, qualityOrConfig)
243
221
  }
244
222
 
245
- canvasElement.encodeSync = function encodeSync(type, qualityOrConfig) {
223
+ canvasElement.encodeSync = function encodeSync(type, qualityOrConfig = {}) {
246
224
  if (type === 'avif') {
247
- return canvasEncodeSync.call(
248
- this,
249
- type,
250
- JSON.stringify({
251
- ...avifConfig,
252
- ...(qualityOrConfig || {}),
253
- }),
254
- )
225
+ return canvasEncodeSync.call(this, type, JSON.stringify(qualityOrConfig))
255
226
  }
256
227
  return canvasEncodeSync.call(this, type, qualityOrConfig)
257
228
  }
258
229
 
259
- canvasElement.toBuffer = function toBuffer(type = 'image/png', qualityOrConfig) {
230
+ canvasElement.toBuffer = function toBuffer(type = 'image/png', qualityOrConfig = {}) {
260
231
  if (type === 'avif') {
261
- return canvasToBuffer.call(
262
- this,
263
- type,
264
- JSON.stringify({
265
- ...avifConfig,
266
- ...(qualityOrConfig || {}),
267
- }),
268
- )
232
+ return canvasToBuffer.call(this, type, JSON.stringify(qualityOrConfig))
269
233
  }
270
234
  return canvasToBuffer.call(this, type, qualityOrConfig)
271
235
  }
272
236
 
273
- canvasElement.toDataURL = function toDataURL(type = 'image/png', qualityOrConfig) {
237
+ canvasElement.toDataURL = function toDataURL(type = 'image/png', qualityOrConfig = {}) {
274
238
  if (type === 'avif') {
275
- return canvasToDataURL.call(
276
- this,
277
- type,
278
- JSON.stringify({
279
- ...avifConfig,
280
- ...(qualityOrConfig || {}),
281
- }),
282
- )
239
+ return canvasToDataURL.call(this, type, JSON.stringify(qualityOrConfig))
283
240
  }
284
241
  return canvasToDataURL.call(this, type, qualityOrConfig)
285
242
  }
286
243
 
287
- canvasElement.toDataURLAsync = function toDataURLAsync(type = 'image/png', qualityOrConfig) {
244
+ canvasElement.toDataURLAsync = function toDataURLAsync(type = 'image/png', qualityOrConfig = {}) {
288
245
  if (type === 'avif') {
289
- return canvasToDataURLAsync.call(
290
- this,
291
- type,
292
- JSON.stringify({
293
- ...avifConfig,
294
- ...(qualityOrConfig || {}),
295
- }),
296
- )
246
+ return canvasToDataURLAsync.call(this, type, JSON.stringify(qualityOrConfig))
297
247
  }
298
248
  return canvasToDataURLAsync.call(this, type, qualityOrConfig)
299
249
  }
package/load-image.js CHANGED
@@ -57,7 +57,7 @@ function makeRequest(url, resolve, reject, redirectCount, requestOptions) {
57
57
  lib.get(url, requestOptions ?? {}, (res) => {
58
58
  const shouldRedirect = REDIRECT_STATUSES.has(res.statusCode) && typeof res.headers.location === 'string'
59
59
  if (shouldRedirect && redirectCount > 0)
60
- return makeRequest(res.headers.location, resolve, reject, redirectCount - 1, requestOptions)
60
+ return makeRequest(new URL(res.headers.location), resolve, reject, redirectCount - 1, requestOptions)
61
61
  if (typeof res.statusCode === 'number' && (res.statusCode < 200 || res.statusCode >= 300)) {
62
62
  return reject(new Error(`remote source rejected with status code ${res.statusCode}`))
63
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/canvas",
3
- "version": "0.1.25",
3
+ "version": "0.1.26",
4
4
  "description": "Canvas for Node.js with skia backend",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/Brooooooklyn/canvas.git",
@@ -66,7 +66,7 @@
66
66
  "@jimp/jpeg": "^0.16.1",
67
67
  "@jimp/png": "^0.16.1",
68
68
  "@napi-rs/cli": "^2.9.0",
69
- "@octokit/rest": "^18.12.0",
69
+ "@octokit/rest": "^19.0.0",
70
70
  "@swc-node/register": "^1.5.1",
71
71
  "@types/lodash": "^4.14.182",
72
72
  "@types/node": "^17.0.35",
@@ -75,7 +75,7 @@
75
75
  "ava": "^4.2.0",
76
76
  "benny": "^3.7.1",
77
77
  "canvas": "^2.9.1",
78
- "canvaskit-wasm": "^0.34.0",
78
+ "canvaskit-wasm": "^0.35.0",
79
79
  "colorette": "^2.0.16",
80
80
  "conventional-changelog-cli": "^2.2.2",
81
81
  "echarts": "^5.3.2",
@@ -83,7 +83,7 @@
83
83
  "eslint-config-prettier": "^8.5.0",
84
84
  "eslint-plugin-import": "^2.26.0",
85
85
  "eslint-plugin-prettier": "^4.0.0",
86
- "eslint-plugin-sonarjs": "^0.13.0",
86
+ "eslint-plugin-sonarjs": "^0.14.0",
87
87
  "husky": "^8.0.1",
88
88
  "lint-staged": "^13.0.0",
89
89
  "lodash": "^4.17.21",
@@ -91,7 +91,7 @@
91
91
  "pinst": "^3.0.0",
92
92
  "png.js": "^0.2.1",
93
93
  "prettier": "^2.6.2",
94
- "skia-canvas": "^0.9.29",
94
+ "skia-canvas": "^1.0.0",
95
95
  "typescript": "^4.7.2"
96
96
  },
97
97
  "lint-staged": {
@@ -109,6 +109,10 @@
109
109
  "extensions": [
110
110
  "ts"
111
111
  ],
112
+ "files": [
113
+ "__test__/**/*.spec.ts",
114
+ "scripts/__test__/**/*.spec.ts"
115
+ ],
112
116
  "workerThreads": false,
113
117
  "cache": false,
114
118
  "timeout": "3m",
@@ -124,16 +128,16 @@
124
128
  "singleQuote": true,
125
129
  "arrowParens": "always"
126
130
  },
127
- "packageManager": "yarn@3.2.1",
131
+ "packageManager": "yarn@3.2.2",
128
132
  "optionalDependencies": {
129
- "@napi-rs/canvas-win32-x64-msvc": "0.1.25",
130
- "@napi-rs/canvas-darwin-x64": "0.1.25",
131
- "@napi-rs/canvas-linux-x64-gnu": "0.1.25",
132
- "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.25",
133
- "@napi-rs/canvas-linux-x64-musl": "0.1.25",
134
- "@napi-rs/canvas-linux-arm64-gnu": "0.1.25",
135
- "@napi-rs/canvas-linux-arm64-musl": "0.1.25",
136
- "@napi-rs/canvas-darwin-arm64": "0.1.25",
137
- "@napi-rs/canvas-android-arm64": "0.1.25"
133
+ "@napi-rs/canvas-win32-x64-msvc": "0.1.26",
134
+ "@napi-rs/canvas-darwin-x64": "0.1.26",
135
+ "@napi-rs/canvas-linux-x64-gnu": "0.1.26",
136
+ "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.26",
137
+ "@napi-rs/canvas-linux-x64-musl": "0.1.26",
138
+ "@napi-rs/canvas-linux-arm64-gnu": "0.1.26",
139
+ "@napi-rs/canvas-linux-arm64-musl": "0.1.26",
140
+ "@napi-rs/canvas-darwin-arm64": "0.1.26",
141
+ "@napi-rs/canvas-android-arm64": "0.1.26"
138
142
  }
139
143
  }