@napi-rs/canvas 0.1.14 → 0.1.19

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/CHANGELOG.md CHANGED
@@ -1,18 +1,48 @@
1
- ## [0.1.14](https://github.com/Brooooooklyn/canvas/compare/v0.1.13...v0.1.14) (2021-10-26)
1
+ ## [0.1.19](https://github.com/Brooooooklyn/canvas/compare/v0.1.18...v0.1.19) (2021-12-31)
2
+
3
+ ### Bug Fixes
2
4
 
5
+ - text align and font fallback ([d80ac6b](https://github.com/Brooooooklyn/canvas/commit/d80ac6befc8861ebebc5855c1a5714b7f55e1d55))
6
+
7
+ ## [0.1.18](https://github.com/Brooooooklyn/canvas/compare/v0.1.17...v0.1.18) (2021-12-30)
3
8
 
4
9
  ### Bug Fixes
5
10
 
6
- * Now generating avif images is 10x+ faster. ([407d1d1](https://github.com/Brooooooklyn/canvas/commit/407d1d1f09dce622426b71ee800480534c8e0888))
7
- * Use different quality for WebP and JPEG formats, which is more in line with the browser's default values. ([fdefa5d](https://github.com/Brooooooklyn/canvas/commit/fdefa5dd278fcc911cb74524388ec7960d9cd1f6))
11
+ - reduce install size for linux glibc/musl ([8e6c7e8](https://github.com/Brooooooklyn/canvas/commit/8e6c7e8f2aeceb2598c24f8b37faa39a961739f9))
12
+
13
+ ### Features
14
+
15
+ - upgrade skia to chrome/m98 ([99e3635](https://github.com/Brooooooklyn/canvas/commit/99e363540db1572a832d65e1593721ad3b051493))
16
+
17
+ ## [0.1.17](https://github.com/Brooooooklyn/canvas/compare/v0.1.16...v0.1.17) (2021-12-12)
18
+
19
+ ## [0.1.16](https://github.com/Brooooooklyn/canvas/compare/v0.1.15...v0.1.16) (2021-12-12)
20
+
21
+ ### Bug Fixes
8
22
 
23
+ - make methods on ctx configurable & writable ([affe82d](https://github.com/Brooooooklyn/canvas/commit/affe82d0b8880441737497403d790f4d39a217c3))
9
24
 
10
25
  ### Features
11
26
 
12
- * The option to generate avif removes alphaQuality and calculates it internally. ([8de6e95](https://github.com/Brooooooklyn/canvas/commit/8de6e95d23383897870c66e59698a71cd0e73631))
13
- * Add a new SVG generation avif example. ([04d401a](https://github.com/Brooooooklyn/canvas/commit/04d401aaf3d35d13223e32af9e13b829f13170fc))
27
+ - chrome/m97 ([66c900f](https://github.com/Brooooooklyn/canvas/commit/66c900f4307f8204b55912659874a83513220460))
14
28
 
29
+ ## [0.1.15](https://github.com/Brooooooklyn/canvas/compare/v0.1.14...v0.1.15) (2021-11-11)
30
+
31
+ ### Bug Fixes
32
+
33
+ - `vercel/nft` and `webpack` compatible issue ([f2e23f5](https://github.com/Brooooooklyn/canvas/commit/f2e23f5d763795c1e499e1eda5b70078a6de501a))
34
+
35
+ ## [0.1.14](https://github.com/Brooooooklyn/canvas/compare/v0.1.13...v0.1.14) (2021-10-26)
36
+
37
+ ### Bug Fixes
38
+
39
+ - Now generating avif images is 10x+ faster. ([407d1d1](https://github.com/Brooooooklyn/canvas/commit/407d1d1f09dce622426b71ee800480534c8e0888))
40
+ - Use different quality for WebP and JPEG formats, which is more in line with the browser's default values. ([fdefa5d](https://github.com/Brooooooklyn/canvas/commit/fdefa5dd278fcc911cb74524388ec7960d9cd1f6))
41
+
42
+ ### Features
15
43
 
44
+ - The option to generate avif removes alphaQuality and calculates it internally. ([8de6e95](https://github.com/Brooooooklyn/canvas/commit/8de6e95d23383897870c66e59698a71cd0e73631))
45
+ - Add a new SVG generation avif example. ([04d401a](https://github.com/Brooooooklyn/canvas/commit/04d401aaf3d35d13223e32af9e13b829f13170fc))
16
46
 
17
47
  ## [0.1.13](https://github.com/Brooooooklyn/canvas/compare/v0.1.12...v0.1.13) (2021-10-20)
18
48
 
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%2Fm96-hotpink)
4
+ ![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm98-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
 
@@ -300,7 +300,6 @@ path.simplify().toSVGString()
300
300
 
301
301
  <img width="500" src="example/tiger.png">
302
302
 
303
-
304
303
  ```shell
305
304
  node example/anime-girl.js
306
305
  ```
@@ -309,7 +308,6 @@ node example/anime-girl.js
309
308
  | ---------------------------------------------- | ---------------------------------------------- |
310
309
  | <img width="500" src="example/anime-girl.svg"> | <img width="500" src="example/anime-girl.png"> |
311
310
 
312
-
313
311
  # Building
314
312
 
315
313
  ## Build skia from source
package/index.js CHANGED
@@ -1,16 +1,6 @@
1
1
  const { platform, homedir } = require('os')
2
2
  const { join } = require('path')
3
3
 
4
- const { loadBinding } = require('@node-rs/helper')
5
-
6
- /**
7
- * __dirname means load native addon from current dir
8
- * 'skia' means native addon name is `skia`
9
- * the first arguments was decided by `napi.name` field in `package.json`
10
- * the second arguments was decided by `name` field in `package.json`
11
- * loadBinding helper will load `skia.[PLATFORM].node` from `__dirname` first
12
- * If failed to load addon, it will fallback to load from `@napi-rs/skia-[PLATFORM]`
13
- */
14
4
  const {
15
5
  CanvasRenderingContext2D,
16
6
  CanvasElement,
@@ -22,9 +12,9 @@ const {
22
12
  CanvasPattern,
23
13
  GlobalFonts,
24
14
  convertSVGTextToPath: _convertSVGTextToPath,
25
- } = loadBinding(__dirname, 'skia', '@napi-rs/canvas')
15
+ } = require('./js-binding')
26
16
 
27
- const Geometry = require('./geometry')
17
+ const { DOMPoint, DOMMatrix, DOMRect } = require('./geometry')
28
18
 
29
19
  const StrokeJoin = {
30
20
  Miter: 0,
@@ -197,9 +187,9 @@ function createCanvas(width, height, flag) {
197
187
  }
198
188
  return new ImageData(widthOrImage, height, { colorSpace: 'srgb', ...attrs })
199
189
  },
200
- configurable: false,
190
+ configurable: true,
201
191
  enumerable: false,
202
- writable: false,
192
+ writable: true,
203
193
  })
204
194
 
205
195
  Object.defineProperty(canvasElement, 'ctx', {
@@ -335,7 +325,7 @@ if (!process.env.DISABLE_SYSTEM_FONTS_LOAD) {
335
325
  }
336
326
 
337
327
  function convertSVGTextToPath(input) {
338
- return _convertSVGTextToPath(Buffer.from(input), GlobalFontsSingleton)
328
+ return _convertSVGTextToPath(Buffer.isBuffer(input) ? input : Buffer.from(input), GlobalFontsSingleton)
339
329
  }
340
330
 
341
331
  module.exports = {
@@ -349,7 +339,9 @@ module.exports = {
349
339
  StrokeCap,
350
340
  StrokeJoin,
351
341
  SvgExportFlag,
352
- ...Geometry,
353
342
  GlobalFonts: GlobalFontsSingleton,
354
343
  convertSVGTextToPath,
344
+ DOMPoint,
345
+ DOMMatrix,
346
+ DOMRect,
355
347
  }
package/js-binding.js ADDED
@@ -0,0 +1,220 @@
1
+ const { existsSync, readFileSync } = require('fs')
2
+ const { join } = require('path')
3
+
4
+ const { platform, arch } = process
5
+
6
+ let nativeBinding = null
7
+ let localFileExisted = false
8
+ let isMusl = false
9
+ let loadError = null
10
+
11
+ switch (platform) {
12
+ case 'android':
13
+ if (arch !== 'arm64') {
14
+ throw new Error(`Unsupported architecture on Android ${arch}`)
15
+ }
16
+ localFileExisted = existsSync(join(__dirname, 'skia.android-arm64.node'))
17
+ try {
18
+ if (localFileExisted) {
19
+ nativeBinding = require('./skia.android-arm64.node')
20
+ } else {
21
+ nativeBinding = require('@napi-rs/canvas-android-arm64')
22
+ }
23
+ } catch (e) {
24
+ loadError = e
25
+ }
26
+ break
27
+ case 'win32':
28
+ // eslint-disable-next-line sonarjs/no-nested-switch
29
+ switch (arch) {
30
+ case 'x64':
31
+ localFileExisted = existsSync(join(__dirname, 'skia.win32-x64-msvc.node'))
32
+ try {
33
+ if (localFileExisted) {
34
+ nativeBinding = require('./skia.win32-x64-msvc.node')
35
+ } else {
36
+ nativeBinding = require('@napi-rs/canvas-win32-x64-msvc')
37
+ }
38
+ } catch (e) {
39
+ loadError = e
40
+ }
41
+ break
42
+ case 'ia32':
43
+ localFileExisted = existsSync(join(__dirname, 'skia.win32-ia32-msvc.node'))
44
+ try {
45
+ if (localFileExisted) {
46
+ nativeBinding = require('./skia.win32-ia32-msvc.node')
47
+ } else {
48
+ nativeBinding = require('@napi-rs/canvas-win32-ia32-msvc')
49
+ }
50
+ } catch (e) {
51
+ loadError = e
52
+ }
53
+ break
54
+ case 'arm64':
55
+ localFileExisted = existsSync(join(__dirname, 'skia.win32-arm64-msvc.node'))
56
+ try {
57
+ if (localFileExisted) {
58
+ nativeBinding = require('./skia.win32-arm64-msvc.node')
59
+ } else {
60
+ nativeBinding = require('@napi-rs/canvas-win32-arm64-msvc')
61
+ }
62
+ } catch (e) {
63
+ loadError = e
64
+ }
65
+ break
66
+ default:
67
+ throw new Error(`Unsupported architecture on Windows: ${arch}`)
68
+ }
69
+ break
70
+ case 'darwin':
71
+ // eslint-disable-next-line sonarjs/no-nested-switch
72
+ switch (arch) {
73
+ case 'x64':
74
+ localFileExisted = existsSync(join(__dirname, 'skia.darwin-x64.node'))
75
+ try {
76
+ if (localFileExisted) {
77
+ nativeBinding = require('./skia.darwin-x64.node')
78
+ } else {
79
+ nativeBinding = require('@napi-rs/canvas-darwin-x64')
80
+ }
81
+ } catch (e) {
82
+ loadError = e
83
+ }
84
+ break
85
+ case 'arm64':
86
+ localFileExisted = existsSync(join(__dirname, 'skia.darwin-arm64.node'))
87
+ try {
88
+ if (localFileExisted) {
89
+ nativeBinding = require('./skia.darwin-arm64.node')
90
+ } else {
91
+ nativeBinding = require('@napi-rs/canvas-darwin-arm64')
92
+ }
93
+ } catch (e) {
94
+ loadError = e
95
+ }
96
+ break
97
+ default:
98
+ throw new Error(`Unsupported architecture on macOS: ${arch}`)
99
+ }
100
+ break
101
+ case 'freebsd':
102
+ if (arch !== 'x64') {
103
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
104
+ }
105
+ localFileExisted = existsSync(join(__dirname, 'skia.freebsd-x64.node'))
106
+ try {
107
+ if (localFileExisted) {
108
+ nativeBinding = require('./skia.freebsd-x64.node')
109
+ } else {
110
+ nativeBinding = require('@napi-rs/canvas-freebsd-x64')
111
+ }
112
+ } catch (e) {
113
+ loadError = e
114
+ }
115
+ break
116
+ case 'linux':
117
+ // eslint-disable-next-line sonarjs/no-nested-switch
118
+ switch (arch) {
119
+ case 'x64':
120
+ isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
121
+ if (isMusl) {
122
+ localFileExisted = existsSync(join(__dirname, 'skia.linux-x64-musl.node'))
123
+ try {
124
+ if (localFileExisted) {
125
+ nativeBinding = require('./skia.linux-x64-musl.node')
126
+ } else {
127
+ nativeBinding = require('@napi-rs/canvas-linux-x64-musl')
128
+ }
129
+ } catch (e) {
130
+ loadError = e
131
+ }
132
+ } else {
133
+ localFileExisted = existsSync(join(__dirname, 'skia.linux-x64-gnu.node'))
134
+ try {
135
+ if (localFileExisted) {
136
+ nativeBinding = require('./skia.linux-x64-gnu.node')
137
+ } else {
138
+ nativeBinding = require('@napi-rs/canvas-linux-x64-gnu')
139
+ }
140
+ } catch (e) {
141
+ loadError = e
142
+ }
143
+ }
144
+ break
145
+ case 'arm64':
146
+ isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
147
+ if (isMusl) {
148
+ localFileExisted = existsSync(join(__dirname, 'skia.linux-arm64-musl.node'))
149
+ try {
150
+ if (localFileExisted) {
151
+ nativeBinding = require('./skia.linux-arm64-musl.node')
152
+ } else {
153
+ nativeBinding = require('@napi-rs/canvas-linux-arm64-musl')
154
+ }
155
+ } catch (e) {
156
+ loadError = e
157
+ }
158
+ } else {
159
+ localFileExisted = existsSync(join(__dirname, 'skia.linux-arm64-gnu.node'))
160
+ try {
161
+ if (localFileExisted) {
162
+ nativeBinding = require('./skia.linux-arm64-gnu.node')
163
+ } else {
164
+ nativeBinding = require('@napi-rs/canvas-linux-arm64-gnu')
165
+ }
166
+ } catch (e) {
167
+ loadError = e
168
+ }
169
+ }
170
+ break
171
+ case 'arm':
172
+ localFileExisted = existsSync(join(__dirname, 'skia.linux-arm-gnueabihf.node'))
173
+ try {
174
+ if (localFileExisted) {
175
+ nativeBinding = require('./skia.linux-arm-gnueabihf.node')
176
+ } else {
177
+ nativeBinding = require('@napi-rs/canvas-linux-arm-gnueabihf')
178
+ }
179
+ } catch (e) {
180
+ loadError = e
181
+ }
182
+ break
183
+ default:
184
+ throw new Error(`Unsupported architecture on Linux: ${arch}`)
185
+ }
186
+ break
187
+ default:
188
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
189
+ }
190
+
191
+ if (!nativeBinding) {
192
+ if (loadError) {
193
+ throw loadError
194
+ }
195
+ throw new Error(`Failed to load native binding`)
196
+ }
197
+
198
+ const {
199
+ CanvasRenderingContext2D,
200
+ CanvasElement,
201
+ createContext,
202
+ SVGCanvas,
203
+ Path2D,
204
+ ImageData,
205
+ Image,
206
+ CanvasPattern,
207
+ GlobalFonts,
208
+ convertSVGTextToPath,
209
+ } = nativeBinding
210
+
211
+ module.exports.CanvasRenderingContext2D = CanvasRenderingContext2D
212
+ module.exports.CanvasElement = CanvasElement
213
+ module.exports.createContext = createContext
214
+ module.exports.SVGCanvas = SVGCanvas
215
+ module.exports.Path2D = Path2D
216
+ module.exports.ImageData = ImageData
217
+ module.exports.Image = Image
218
+ module.exports.CanvasPattern = CanvasPattern
219
+ module.exports.GlobalFonts = GlobalFonts
220
+ module.exports.convertSVGTextToPath = convertSVGTextToPath
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/canvas",
3
- "version": "0.1.14",
3
+ "version": "0.1.19",
4
4
  "description": "Canvas for Node.js with skia backend",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/Brooooooklyn/canvas.git",
@@ -21,7 +21,8 @@
21
21
  "files": [
22
22
  "index.d.ts",
23
23
  "index.js",
24
- "geometry.js"
24
+ "geometry.js",
25
+ "js-binding.js"
25
26
  ],
26
27
  "napi": {
27
28
  "name": "skia",
@@ -49,12 +50,9 @@
49
50
  "bench": "node -r @swc-node/register benchmark/bench.ts",
50
51
  "build": "napi build --platform --release",
51
52
  "build:debug": "napi build --platform",
52
- "format": "run-p format:md format:json format:yaml format:source format:rs",
53
- "format:md": "prettier --parser markdown --write ./**/*.md",
54
- "format:json": "prettier --parser json --write ./**/*.json",
53
+ "format": "run-p format:source format:rs",
55
54
  "format:rs": "cargo fmt",
56
- "format:source": "prettier --config ./package.json --write ./**/*.{js,ts}",
57
- "format:yaml": "prettier --parser yaml --write ./**/*.{yml,yaml}",
55
+ "format:source": "prettier . -w",
58
56
  "lint": "eslint . -c ./.eslintrc.yml",
59
57
  "prepublishOnly": "pinst --disable && napi prepublish -t npm",
60
58
  "postpublish": "pinst --enable",
@@ -66,50 +64,41 @@
66
64
  "@jimp/custom": "^0.16.1",
67
65
  "@jimp/jpeg": "^0.16.1",
68
66
  "@jimp/png": "^0.16.1",
69
- "@napi-rs/cli": "^1.3.3",
67
+ "@napi-rs/cli": "^1.3.5",
70
68
  "@octokit/rest": "^18.12.0",
71
- "@swc-node/register": "^1.3.6",
72
- "@types/lodash": "^4.14.175",
73
- "@typescript-eslint/eslint-plugin": "^5.0.0",
74
- "@typescript-eslint/parser": "^5.0.0",
69
+ "@swc-node/register": "^1.4.0",
70
+ "@types/lodash": "^4.14.178",
71
+ "@typescript-eslint/eslint-plugin": "^5.6.0",
72
+ "@typescript-eslint/parser": "^5.6.0",
75
73
  "ava": "^3.15.0",
76
- "benny": "^3.7.0",
74
+ "benny": "^3.7.1",
77
75
  "canvas": "^2.8.0",
78
- "canvaskit-wasm": "^0.30.0",
79
- "chalk": "^4.1.2",
76
+ "canvaskit-wasm": "^0.32.0",
77
+ "chalk": "4",
80
78
  "conventional-changelog-cli": "^2.1.1",
81
- "eslint": "^8.0.1",
79
+ "echarts": "^5.2.2",
80
+ "eslint": "^8.4.1",
82
81
  "eslint-config-prettier": "^8.3.0",
83
- "eslint-plugin-import": "^2.25.2",
82
+ "eslint-plugin-import": "^2.25.3",
84
83
  "eslint-plugin-prettier": "^4.0.0",
85
- "eslint-plugin-sonarjs": "^0.10.0",
86
- "husky": "^7.0.2",
87
- "lint-staged": "^11.2.3",
84
+ "eslint-plugin-sonarjs": "^0.11.0",
85
+ "husky": "^7.0.4",
86
+ "lint-staged": "^12.1.2",
88
87
  "lodash": "^4.17.21",
89
88
  "npm-run-all": "^4.1.5",
90
89
  "pinst": "^2.1.6",
91
90
  "png.js": "^0.2.1",
92
- "prettier": "^2.4.1",
91
+ "prettier": "^2.5.1",
93
92
  "putasset": "^5.0.3",
94
- "skia-canvas": "^0.9.25",
95
- "typescript": "^4.4.4"
96
- },
97
- "dependencies": {
98
- "@node-rs/helper": "^1.2.1"
93
+ "skia-canvas": "^0.9.27",
94
+ "typescript": "^4.5.3"
99
95
  },
100
96
  "lint-staged": {
97
+ "*.@(js|ts|tsx|yml|yaml|md|json)": [
98
+ "prettier --write"
99
+ ],
101
100
  "*.@(js|ts|tsx)": [
102
- "prettier --write",
103
101
  "eslint -c .eslintrc.yml --fix"
104
- ],
105
- "*.@(yml|yaml)": [
106
- "prettier --parser yaml --write"
107
- ],
108
- "*.md": [
109
- "prettier --parser markdown --write"
110
- ],
111
- "*.json": [
112
- "prettier --parser json --write"
113
102
  ]
114
103
  },
115
104
  "ava": {
@@ -130,18 +119,17 @@
130
119
  "semi": false,
131
120
  "trailingComma": "all",
132
121
  "singleQuote": true,
133
- "arrowParens": "always",
134
- "parser": "typescript"
122
+ "arrowParens": "always"
135
123
  },
136
124
  "optionalDependencies": {
137
- "@napi-rs/canvas-win32-x64-msvc": "0.1.14",
138
- "@napi-rs/canvas-darwin-x64": "0.1.14",
139
- "@napi-rs/canvas-linux-x64-gnu": "0.1.14",
140
- "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.14",
141
- "@napi-rs/canvas-linux-x64-musl": "0.1.14",
142
- "@napi-rs/canvas-linux-arm64-gnu": "0.1.14",
143
- "@napi-rs/canvas-linux-arm64-musl": "0.1.14",
144
- "@napi-rs/canvas-darwin-arm64": "0.1.14",
145
- "@napi-rs/canvas-android-arm64": "0.1.14"
125
+ "@napi-rs/canvas-win32-x64-msvc": "0.1.19",
126
+ "@napi-rs/canvas-darwin-x64": "0.1.19",
127
+ "@napi-rs/canvas-linux-x64-gnu": "0.1.19",
128
+ "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.19",
129
+ "@napi-rs/canvas-linux-x64-musl": "0.1.19",
130
+ "@napi-rs/canvas-linux-arm64-gnu": "0.1.19",
131
+ "@napi-rs/canvas-linux-arm64-musl": "0.1.19",
132
+ "@napi-rs/canvas-darwin-arm64": "0.1.19",
133
+ "@napi-rs/canvas-android-arm64": "0.1.19"
146
134
  }
147
135
  }