@napi-rs/canvas 0.1.28 → 0.1.29
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 +6 -2
- package/index.js +1 -77
- package/js-binding.js +0 -2
- package/load-image.js +9 -2
- package/package.json +26 -26
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# `skr canvas`
|
|
2
2
|
|
|
3
3
|

|
|
4
|
-

|
|
5
5
|
[](https://packagephobia.com/result?p=@napi-rs/canvas)
|
|
6
6
|
[](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true)
|
|
7
7
|
|
|
@@ -41,12 +41,16 @@ npm install @napi-rs/canvas
|
|
|
41
41
|
|
|
42
42
|
[**_cortex-a57_**](https://en.wikipedia.org/wiki/ARM_Cortex-A57) or newer CPU architecture on **Linux**.
|
|
43
43
|
|
|
44
|
-
All
|
|
44
|
+
All Apple M chips on **macOS**.
|
|
45
45
|
|
|
46
46
|
### `armv7`
|
|
47
47
|
|
|
48
48
|
[**_cortex-a7_**](https://en.wikipedia.org/wiki/ARM_Cortex-A7) or newer CPU architecture.
|
|
49
49
|
|
|
50
|
+
### glibc
|
|
51
|
+
|
|
52
|
+
Since Skia relies on the [glibc](https://www.gnu.org/software/libc/) 2.18 API, you need to have at least glibc version >= 2.18 on your system.
|
|
53
|
+
|
|
50
54
|
# Usage
|
|
51
55
|
|
|
52
56
|
```js
|
package/index.js
CHANGED
|
@@ -5,7 +5,6 @@ const {
|
|
|
5
5
|
clearAllCache,
|
|
6
6
|
CanvasRenderingContext2D,
|
|
7
7
|
CanvasElement,
|
|
8
|
-
createContext,
|
|
9
8
|
SVGCanvas,
|
|
10
9
|
Path2D,
|
|
11
10
|
ImageData,
|
|
@@ -47,84 +46,9 @@ Object.defineProperty(GlobalFonts, 'has', {
|
|
|
47
46
|
writable: false,
|
|
48
47
|
})
|
|
49
48
|
|
|
50
|
-
CanvasRenderingContext2D.prototype.createPattern = function createPattern(image, repetition) {
|
|
51
|
-
if (image instanceof ImageData) {
|
|
52
|
-
const pattern = new CanvasPattern(image, repetition, 0)
|
|
53
|
-
Object.defineProperty(pattern, '_imageData', {
|
|
54
|
-
writable: true,
|
|
55
|
-
configurable: false,
|
|
56
|
-
enumerable: false,
|
|
57
|
-
value: null,
|
|
58
|
-
})
|
|
59
|
-
return pattern
|
|
60
|
-
} else if (image instanceof Image) {
|
|
61
|
-
return new CanvasPattern(image, repetition, 1)
|
|
62
|
-
} else if (image instanceof CanvasElement || image instanceof SVGCanvas) {
|
|
63
|
-
return new CanvasPattern(image, repetition, 2)
|
|
64
|
-
}
|
|
65
|
-
throw TypeError('Image should be instance of ImageData or Image')
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
CanvasRenderingContext2D.prototype.getImageData = function getImageData(x, y, w, h) {
|
|
69
|
-
const data = this._getImageData(x, y, w, h)
|
|
70
|
-
return new ImageData(data, w, h)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
49
|
function createCanvas(width, height, flag) {
|
|
74
50
|
const isSvgBackend = typeof flag !== 'undefined'
|
|
75
|
-
const canvasElement = isSvgBackend ? new SVGCanvas(width, height) : new CanvasElement(width, height)
|
|
76
|
-
|
|
77
|
-
let ctx
|
|
78
|
-
canvasElement.getContext = function getContext(type, attr = {}) {
|
|
79
|
-
if (type !== '2d') {
|
|
80
|
-
throw new Error('Unsupported type')
|
|
81
|
-
}
|
|
82
|
-
const attrs = { alpha: true, colorSpace: 'srgb', ...attr }
|
|
83
|
-
ctx = ctx
|
|
84
|
-
? ctx
|
|
85
|
-
: isSvgBackend
|
|
86
|
-
? new CanvasRenderingContext2D(this.width, this.height, attrs.colorSpace, flag)
|
|
87
|
-
: new CanvasRenderingContext2D(this.width, this.height, attrs.colorSpace)
|
|
88
|
-
createContext(ctx, this.width, this.height, attrs)
|
|
89
|
-
|
|
90
|
-
// napi can not define writable: true but enumerable: false property
|
|
91
|
-
Object.defineProperty(ctx, '_fillStyle', {
|
|
92
|
-
value: '#000',
|
|
93
|
-
configurable: false,
|
|
94
|
-
enumerable: false,
|
|
95
|
-
writable: true,
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
Object.defineProperty(ctx, '_strokeStyle', {
|
|
99
|
-
value: '#000',
|
|
100
|
-
configurable: false,
|
|
101
|
-
enumerable: false,
|
|
102
|
-
writable: true,
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
Object.defineProperty(ctx, 'createImageData', {
|
|
106
|
-
value: function createImageData(widthOrImage, height, attrs = {}) {
|
|
107
|
-
if (widthOrImage instanceof ImageData) {
|
|
108
|
-
return new ImageData(widthOrImage.data, widthOrImage.width, widthOrImage.height)
|
|
109
|
-
}
|
|
110
|
-
return new ImageData(widthOrImage, height, { colorSpace: 'srgb', ...attrs })
|
|
111
|
-
},
|
|
112
|
-
configurable: true,
|
|
113
|
-
enumerable: false,
|
|
114
|
-
writable: true,
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
Object.defineProperty(canvasElement, 'ctx', {
|
|
118
|
-
value: ctx,
|
|
119
|
-
enumerable: false,
|
|
120
|
-
configurable: false,
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
ctx.canvas = canvasElement
|
|
124
|
-
|
|
125
|
-
return ctx
|
|
126
|
-
}
|
|
127
|
-
|
|
51
|
+
const canvasElement = isSvgBackend ? new SVGCanvas(width, height, flag) : new CanvasElement(width, height)
|
|
128
52
|
const {
|
|
129
53
|
encode: canvasEncode,
|
|
130
54
|
encodeSync: canvasEncodeSync,
|
package/js-binding.js
CHANGED
|
@@ -199,7 +199,6 @@ const {
|
|
|
199
199
|
clearAllCache,
|
|
200
200
|
CanvasRenderingContext2D,
|
|
201
201
|
CanvasElement,
|
|
202
|
-
createContext,
|
|
203
202
|
SVGCanvas,
|
|
204
203
|
Path,
|
|
205
204
|
ImageData,
|
|
@@ -216,7 +215,6 @@ const {
|
|
|
216
215
|
module.exports.clearAllCache = clearAllCache
|
|
217
216
|
module.exports.CanvasRenderingContext2D = CanvasRenderingContext2D
|
|
218
217
|
module.exports.CanvasElement = CanvasElement
|
|
219
|
-
module.exports.createContext = createContext
|
|
220
218
|
module.exports.SVGCanvas = SVGCanvas
|
|
221
219
|
module.exports.Path2D = Path
|
|
222
220
|
module.exports.ImageData = ImageData
|
package/load-image.js
CHANGED
|
@@ -39,7 +39,13 @@ module.exports = async function loadImage(source, options = {}) {
|
|
|
39
39
|
source = !(source instanceof URL) ? new URL(source) : source
|
|
40
40
|
// attempt to download the remote source and construct image
|
|
41
41
|
const data = await new Promise((resolve, reject) =>
|
|
42
|
-
makeRequest(
|
|
42
|
+
makeRequest(
|
|
43
|
+
source,
|
|
44
|
+
resolve,
|
|
45
|
+
reject,
|
|
46
|
+
typeof options.maxRedirects === 'number' && options.maxRedirects >= 0 ? options.maxRedirects : MAX_REDIRECTS,
|
|
47
|
+
options.requestOptions,
|
|
48
|
+
),
|
|
43
49
|
)
|
|
44
50
|
return createImage(data, options.alt)
|
|
45
51
|
}
|
|
@@ -54,7 +60,7 @@ function makeRequest(url, resolve, reject, redirectCount, requestOptions) {
|
|
|
54
60
|
// lazy load the lib
|
|
55
61
|
const lib = isHttps ? (!https ? (https = require('https')) : https) : !http ? (http = require('http')) : http
|
|
56
62
|
|
|
57
|
-
lib.get(url, requestOptions
|
|
63
|
+
lib.get(url, requestOptions || {}, (res) => {
|
|
58
64
|
const shouldRedirect = REDIRECT_STATUSES.has(res.statusCode) && typeof res.headers.location === 'string'
|
|
59
65
|
if (shouldRedirect && redirectCount > 0)
|
|
60
66
|
return makeRequest(new URL(res.headers.location), resolve, reject, redirectCount - 1, requestOptions)
|
|
@@ -86,6 +92,7 @@ function createImage(src, alt) {
|
|
|
86
92
|
|
|
87
93
|
function isBufferLike(src) {
|
|
88
94
|
return (
|
|
95
|
+
(src && src.type === 'Buffer') ||
|
|
89
96
|
Array.isArray(src) ||
|
|
90
97
|
src instanceof ArrayBuffer ||
|
|
91
98
|
src instanceof SharedArrayBuffer ||
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/canvas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "Canvas for Node.js with skia backend",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "https://github.com/Brooooooklyn/canvas.git",
|
|
@@ -65,36 +65,36 @@
|
|
|
65
65
|
"@jimp/custom": "^0.16.1",
|
|
66
66
|
"@jimp/jpeg": "^0.16.1",
|
|
67
67
|
"@jimp/png": "^0.16.1",
|
|
68
|
-
"@napi-rs/cli": "^2.
|
|
69
|
-
"@octokit/rest": "^19.0.
|
|
68
|
+
"@napi-rs/cli": "^2.11.4",
|
|
69
|
+
"@octokit/rest": "^19.0.4",
|
|
70
70
|
"@swc-node/register": "^1.5.1",
|
|
71
|
-
"@types/lodash": "^4.14.
|
|
72
|
-
"@types/node": "^
|
|
73
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
74
|
-
"@typescript-eslint/parser": "^5.
|
|
75
|
-
"ava": "^4.
|
|
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",
|
|
76
76
|
"benny": "^3.7.1",
|
|
77
|
-
"canvas": "^2.9.
|
|
78
|
-
"canvaskit-wasm": "^0.
|
|
77
|
+
"canvas": "^2.9.3",
|
|
78
|
+
"canvaskit-wasm": "^0.36.1",
|
|
79
79
|
"colorette": "^2.0.19",
|
|
80
80
|
"conventional-changelog-cli": "^2.2.2",
|
|
81
|
-
"echarts": "^5.3.
|
|
82
|
-
"eslint": "^8.
|
|
81
|
+
"echarts": "^5.3.3",
|
|
82
|
+
"eslint": "^8.22.0",
|
|
83
83
|
"eslint-config-prettier": "^8.5.0",
|
|
84
84
|
"eslint-plugin-import": "^2.26.0",
|
|
85
|
-
"eslint-plugin-prettier": "^4.
|
|
85
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
86
86
|
"eslint-plugin-sonarjs": "^0.15.0",
|
|
87
87
|
"husky": "^8.0.1",
|
|
88
|
-
"lint-staged": "^13.0.
|
|
88
|
+
"lint-staged": "^13.0.3",
|
|
89
89
|
"lodash": "^4.17.21",
|
|
90
90
|
"npm-run-all": "^4.1.5",
|
|
91
91
|
"pinst": "^3.0.0",
|
|
92
92
|
"png.js": "^0.2.1",
|
|
93
|
-
"prettier": "^2.
|
|
93
|
+
"prettier": "^2.7.1",
|
|
94
94
|
"pretty-bytes": "^6.0.0",
|
|
95
95
|
"skia-canvas": "^1.0.0",
|
|
96
96
|
"table": "^6.8.0",
|
|
97
|
-
"typescript": "^4.7.
|
|
97
|
+
"typescript": "^4.7.4"
|
|
98
98
|
},
|
|
99
99
|
"lint-staged": {
|
|
100
100
|
"*.@(js|ts|tsx|yml|yaml|md|json|html)": [
|
|
@@ -130,16 +130,16 @@
|
|
|
130
130
|
"singleQuote": true,
|
|
131
131
|
"arrowParens": "always"
|
|
132
132
|
},
|
|
133
|
-
"packageManager": "yarn@3.2.
|
|
133
|
+
"packageManager": "yarn@3.2.3",
|
|
134
134
|
"optionalDependencies": {
|
|
135
|
-
"@napi-rs/canvas-win32-x64-msvc": "0.1.
|
|
136
|
-
"@napi-rs/canvas-darwin-x64": "0.1.
|
|
137
|
-
"@napi-rs/canvas-linux-x64-gnu": "0.1.
|
|
138
|
-
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.
|
|
139
|
-
"@napi-rs/canvas-linux-x64-musl": "0.1.
|
|
140
|
-
"@napi-rs/canvas-linux-arm64-gnu": "0.1.
|
|
141
|
-
"@napi-rs/canvas-linux-arm64-musl": "0.1.
|
|
142
|
-
"@napi-rs/canvas-darwin-arm64": "0.1.
|
|
143
|
-
"@napi-rs/canvas-android-arm64": "0.1.
|
|
135
|
+
"@napi-rs/canvas-win32-x64-msvc": "0.1.29",
|
|
136
|
+
"@napi-rs/canvas-darwin-x64": "0.1.29",
|
|
137
|
+
"@napi-rs/canvas-linux-x64-gnu": "0.1.29",
|
|
138
|
+
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.29",
|
|
139
|
+
"@napi-rs/canvas-linux-x64-musl": "0.1.29",
|
|
140
|
+
"@napi-rs/canvas-linux-arm64-gnu": "0.1.29",
|
|
141
|
+
"@napi-rs/canvas-linux-arm64-musl": "0.1.29",
|
|
142
|
+
"@napi-rs/canvas-darwin-arm64": "0.1.29",
|
|
143
|
+
"@napi-rs/canvas-android-arm64": "0.1.29"
|
|
144
144
|
}
|
|
145
145
|
}
|