@napi-rs/canvas 0.1.30 → 0.1.32

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%2Fm106-hotpink)
4
+ ![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm110-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
@@ -220,6 +220,7 @@ export class Path2D {
220
220
  moveTo(x: number, y: number): void
221
221
  quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
222
222
  rect(x: number, y: number, w: number, h: number): void
223
+ roundRect(x: number, y: number, w: number, h: number, radii?: number | number[]): void
223
224
 
224
225
  // PathKit methods
225
226
  op(path: Path2D, operation: PathOp): Path2D
@@ -248,8 +249,9 @@ export interface StrokeOptions {
248
249
  export interface SKRSContext2D
249
250
  extends Omit<
250
251
  CanvasRenderingContext2D,
251
- 'drawImage' | 'createPattern' | 'getTransform' | 'drawFocusIfNeeded' | 'scrollPathIntoView'
252
+ 'drawImage' | 'createPattern' | 'getTransform' | 'drawFocusIfNeeded' | 'scrollPathIntoView' | 'canvas'
252
253
  > {
254
+ canvas: Canvas
253
255
  /**
254
256
  * @param startAngle The angle at which to begin the gradient, in radians. Angle measurements start vertically above the centre and move around clockwise.
255
257
  * @param x The x-axis coordinate of the centre of the gradient.
@@ -274,14 +276,7 @@ export interface SKRSContext2D
274
276
  repeat: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' | null,
275
277
  ): CanvasPattern
276
278
  getContextAttributes(): { alpha: boolean; desynchronized: boolean }
277
- getTransform(): {
278
- a: number
279
- b: number
280
- c: number
281
- d: number
282
- e: number
283
- f: number
284
- }
279
+ getTransform(): DOMMatrix
285
280
  }
286
281
 
287
282
  export type ColorSpace = 'srgb' | 'display-p3'
package/index.js CHANGED
@@ -31,20 +31,36 @@ const SvgExportFlag = {
31
31
  // eslint-disable-next-line sonarjs/no-unused-collection
32
32
  const Fonts = []
33
33
 
34
- Object.defineProperty(GlobalFonts, 'families', {
35
- get: function () {
36
- return JSON.parse(GlobalFonts.getFamilies())
37
- },
38
- })
34
+ if (!('families' in GlobalFonts)) {
35
+ Object.defineProperty(GlobalFonts, 'families', {
36
+ get: function () {
37
+ return JSON.parse(GlobalFonts.getFamilies())
38
+ },
39
+ })
40
+ }
41
+
42
+ if (!('has' in GlobalFonts)) {
43
+ Object.defineProperty(GlobalFonts, 'has', {
44
+ value: function has(name) {
45
+ return !!JSON.parse(GlobalFonts.getFamilies()).find(({ family }) => family === name)
46
+ },
47
+ configurable: false,
48
+ enumerable: false,
49
+ writable: false,
50
+ })
51
+ }
39
52
 
40
- Object.defineProperty(GlobalFonts, 'has', {
41
- value: function has(name) {
42
- return !!JSON.parse(GlobalFonts.getFamilies()).find(({ family }) => family === name)
43
- },
44
- configurable: false,
45
- enumerable: false,
46
- writable: false,
47
- })
53
+ const _getTransform = CanvasRenderingContext2D.prototype.getTransform
54
+
55
+ CanvasRenderingContext2D.prototype.getTransform = function getTransform() {
56
+ const transform = _getTransform.apply(this, arguments)
57
+ // monkey patched, skip
58
+ if (transform instanceof DOMMatrix) {
59
+ return transform
60
+ }
61
+ const { a, b, c, d, e, f } = transform
62
+ return new DOMMatrix([a, b, c, d, e, f])
63
+ }
48
64
 
49
65
  function createCanvas(width, height, flag) {
50
66
  const isSvgBackend = typeof flag !== 'undefined'
package/load-image.js CHANGED
@@ -32,7 +32,7 @@ module.exports = async function loadImage(source, options = {}) {
32
32
  // if source is a string or URL instance
33
33
  if (typeof source === 'string' || source instanceof URL) {
34
34
  // if the source exists as a file, construct image from that file
35
- if (fs.existsSync(source)) {
35
+ if (await exists(source)) {
36
36
  return createImage(await fs.promises.readFile(source), options.alt)
37
37
  } else {
38
38
  // the source is a remote url here
@@ -101,3 +101,12 @@ function isBufferLike(src) {
101
101
  src instanceof Object.getPrototypeOf(Uint8Array)
102
102
  )
103
103
  }
104
+
105
+ async function exists(path) {
106
+ try {
107
+ await fs.promises.access(path, fs.constants.F_OK)
108
+ return true
109
+ } catch {
110
+ return false
111
+ }
112
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/canvas",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "Canvas for Node.js with skia backend",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/Brooooooklyn/canvas.git",
@@ -57,44 +57,46 @@
57
57
  "lint": "eslint . -c ./.eslintrc.yml",
58
58
  "prepublishOnly": "pinst --disable && napi prepublish -t npm",
59
59
  "postpublish": "pinst --enable",
60
+ "test:ci": "ava -c 1",
60
61
  "test": "ava",
61
62
  "version": "napi version && conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
62
63
  },
63
64
  "devDependencies": {
64
- "@jimp/core": "^0.16.1",
65
- "@jimp/custom": "^0.16.1",
66
- "@jimp/jpeg": "^0.16.1",
67
- "@jimp/png": "^0.16.1",
68
- "@napi-rs/cli": "^2.11.4",
69
- "@octokit/rest": "^19.0.4",
70
- "@swc-node/register": "^1.5.1",
71
- "@types/lodash": "^4.14.184",
72
- "@types/node": "^18.7.13",
73
- "@typescript-eslint/eslint-plugin": "^5.35.1",
74
- "@typescript-eslint/parser": "^5.35.1",
75
- "ava": "^4.3.3",
65
+ "@jimp/core": "^0.16.2",
66
+ "@jimp/custom": "^0.16.2",
67
+ "@jimp/jpeg": "^0.16.2",
68
+ "@jimp/png": "^0.16.2",
69
+ "@napi-rs/cli": "^2.14.0",
70
+ "@octokit/rest": "^19.0.5",
71
+ "@swc-node/register": "^1.5.4",
72
+ "@swc/core": "^1.3.24",
73
+ "@types/lodash": "^4.14.191",
74
+ "@types/node": "^18.11.18",
75
+ "@typescript-eslint/eslint-plugin": "^5.47.1",
76
+ "@typescript-eslint/parser": "^5.47.1",
77
+ "ava": "^5.1.0",
76
78
  "benny": "^3.7.1",
77
- "canvas": "^2.9.3",
78
- "canvaskit-wasm": "^0.37.0",
79
+ "canvas": "^2.11.0",
80
+ "canvaskit-wasm": "^0.37.2",
79
81
  "colorette": "^2.0.19",
80
82
  "conventional-changelog-cli": "^2.2.2",
81
- "echarts": "^5.3.3",
82
- "eslint": "^8.22.0",
83
+ "echarts": "^5.4.1",
84
+ "eslint": "^8.31.0",
83
85
  "eslint-config-prettier": "^8.5.0",
84
86
  "eslint-plugin-import": "^2.26.0",
85
87
  "eslint-plugin-prettier": "^4.2.1",
86
- "eslint-plugin-sonarjs": "^0.15.0",
87
- "husky": "^8.0.1",
88
- "lint-staged": "^13.0.3",
88
+ "eslint-plugin-sonarjs": "^0.17.0",
89
+ "husky": "^8.0.2",
90
+ "lint-staged": "^13.1.0",
89
91
  "lodash": "^4.17.21",
90
92
  "npm-run-all": "^4.1.5",
91
93
  "pinst": "^3.0.0",
92
94
  "png.js": "^0.2.1",
93
- "prettier": "^2.7.1",
95
+ "prettier": "^2.8.1",
94
96
  "pretty-bytes": "^6.0.0",
95
- "skia-canvas": "^1.0.0",
96
- "table": "^6.8.0",
97
- "typescript": "^4.7.4"
97
+ "skia-canvas": "^1.0.1",
98
+ "table": "^6.8.1",
99
+ "typescript": "^4.9.4"
98
100
  },
99
101
  "lint-staged": {
100
102
  "*.@(js|ts|tsx|yml|yaml|md|json|html)": [
@@ -130,16 +132,16 @@
130
132
  "singleQuote": true,
131
133
  "arrowParens": "always"
132
134
  },
133
- "packageManager": "yarn@3.2.3",
135
+ "packageManager": "yarn@3.3.1",
134
136
  "optionalDependencies": {
135
- "@napi-rs/canvas-win32-x64-msvc": "0.1.30",
136
- "@napi-rs/canvas-darwin-x64": "0.1.30",
137
- "@napi-rs/canvas-linux-x64-gnu": "0.1.30",
138
- "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.30",
139
- "@napi-rs/canvas-linux-x64-musl": "0.1.30",
140
- "@napi-rs/canvas-linux-arm64-gnu": "0.1.30",
141
- "@napi-rs/canvas-linux-arm64-musl": "0.1.30",
142
- "@napi-rs/canvas-darwin-arm64": "0.1.30",
143
- "@napi-rs/canvas-android-arm64": "0.1.30"
137
+ "@napi-rs/canvas-win32-x64-msvc": "0.1.32",
138
+ "@napi-rs/canvas-darwin-x64": "0.1.32",
139
+ "@napi-rs/canvas-linux-x64-gnu": "0.1.32",
140
+ "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.32",
141
+ "@napi-rs/canvas-linux-x64-musl": "0.1.32",
142
+ "@napi-rs/canvas-linux-arm64-gnu": "0.1.32",
143
+ "@napi-rs/canvas-linux-arm64-musl": "0.1.32",
144
+ "@napi-rs/canvas-darwin-arm64": "0.1.32",
145
+ "@napi-rs/canvas-android-arm64": "0.1.32"
144
146
  }
145
147
  }