@napi-rs/canvas
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -0,1 +1,7 @@ | ||
## [0.0.9](https://github.com/Brooooooklyn/canvas/compare/v0.0.8...v0.0.9) (2021-07-11) | ||
### Features | ||
- upgrade skia to chrome/m92 latest ([584a02a](https://github.com/Brooooooklyn/canvas/commit/584a02aef28516dd18d675a8f90c1f25dceae129)) | ||
## [0.0.8](https://github.com/Brooooooklyn/canvas/compare/v0.0.7...v0.0.8) (2021-06-23) | ||
@@ -2,0 +8,0 @@ |
@@ -276,8 +276,7 @@ export interface DOMMatrix2DInit { | ||
export interface Canvas | ||
extends Omit< | ||
HTMLCanvasElement, | ||
'getContext' | 'transferControlToOffscreen' | 'addEventListener' | 'removeEventListener' | ||
> { | ||
export interface Canvas { | ||
width: number | ||
height: number | ||
getContext(contextType: '2d', contextAttributes?: { alpha: boolean }): SKRSContext2D | ||
toBuffer(): Buffer | ||
encode(format: 'webp' | 'jpeg', quality: number): Promise<Buffer> | ||
@@ -291,3 +290,6 @@ encode(format: 'png'): Promise<Buffer> | ||
readonly families: string[] | ||
register(path: string): void | ||
// return true if succeeded | ||
register(font: Buffer): boolean | ||
// absolute path | ||
registerFromPath(path: string): boolean | ||
has(name: string): boolean | ||
@@ -294,0 +296,0 @@ } |
14
index.js
@@ -51,4 +51,5 @@ const { loadBinding } = require('@node-rs/helper') | ||
value: function register(path) { | ||
GlobalFontsSingleton._register(path) | ||
const result = GlobalFontsSingleton._register(path) | ||
FamilyNamesMap = GlobalFontsSingleton._families | ||
return result | ||
}, | ||
@@ -60,2 +61,13 @@ configurable: false, | ||
Object.defineProperty(GlobalFontsSingleton, 'registerFromPath', { | ||
value: function register(path) { | ||
const result = GlobalFontsSingleton._registerFromPath(path) | ||
FamilyNamesMap = GlobalFontsSingleton._families | ||
return result | ||
}, | ||
configurable: false, | ||
enumerable: false, | ||
writable: false, | ||
}) | ||
Object.defineProperty(GlobalFontsSingleton, 'families', { | ||
@@ -62,0 +74,0 @@ get: function () { |
{ | ||
"name": "@napi-rs/canvas", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Canvas for Node.js with skia backend", | ||
@@ -34,2 +34,3 @@ "main": "index.js", | ||
"aarch64-unknown-linux-gnu", | ||
"aarch64-unknown-linux-musl", | ||
"aarch64-apple-darwin", | ||
@@ -70,6 +71,6 @@ "aarch64-linux-android" | ||
"@napi-rs/cli": "^1.1.0", | ||
"@octokit/rest": "^18.6.0", | ||
"@octokit/rest": "^18.6.1", | ||
"@swc-node/register": "^1.3.2", | ||
"@typescript-eslint/eslint-plugin": "^4.27.0", | ||
"@typescript-eslint/parser": "^4.27.0", | ||
"@typescript-eslint/eslint-plugin": "^4.28.0", | ||
"@typescript-eslint/parser": "^4.28.0", | ||
"ava": "^3.15.0", | ||
@@ -84,4 +85,4 @@ "benny": "^3.6.15", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"eslint-plugin-sonarjs": "^0.7.0", | ||
"husky": "^6.0.0", | ||
"eslint-plugin-sonarjs": "^0.9.0", | ||
"husky": "^7.0.0", | ||
"lint-staged": "^11.0.0", | ||
@@ -93,2 +94,3 @@ "npm-run-all": "^4.1.5", | ||
"putasset": "^5.0.3", | ||
"skia-canvas": "^0.9.22", | ||
"typescript": "^4.3.4" | ||
@@ -136,11 +138,12 @@ }, | ||
"optionalDependencies": { | ||
"@napi-rs/canvas-win32-x64-msvc": "^0.0.8", | ||
"@napi-rs/canvas-darwin-x64": "^0.0.8", | ||
"@napi-rs/canvas-linux-x64-gnu": "^0.0.8", | ||
"@napi-rs/canvas-linux-arm-gnueabihf": "^0.0.8", | ||
"@napi-rs/canvas-linux-x64-musl": "^0.0.8", | ||
"@napi-rs/canvas-linux-arm64-gnu": "^0.0.8", | ||
"@napi-rs/canvas-darwin-arm64": "^0.0.8", | ||
"@napi-rs/canvas-android-arm64": "^0.0.8" | ||
"@napi-rs/canvas-win32-x64-msvc": "^0.0.9", | ||
"@napi-rs/canvas-darwin-x64": "^0.0.9", | ||
"@napi-rs/canvas-linux-x64-gnu": "^0.0.9", | ||
"@napi-rs/canvas-linux-arm-gnueabihf": "^0.0.9", | ||
"@napi-rs/canvas-linux-x64-musl": "^0.0.9", | ||
"@napi-rs/canvas-linux-arm64-gnu": "^0.0.9", | ||
"@napi-rs/canvas-linux-arm64-musl": "^0.0.9", | ||
"@napi-rs/canvas-darwin-arm64": "^0.0.9", | ||
"@napi-rs/canvas-android-arm64": "^0.0.9" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# `@napi-rs/canvas` | ||
# `skr canvas` | ||
@@ -7,9 +7,16 @@ ![CI](https://github.com/Brooooooklyn/canvas/workflows/CI/badge.svg) | ||
Google Skia binding to Node.js via `N-API`. | ||
Google Skia binding to Node.js via [Node-API](https://napi.rs), **0 System dependencies!** | ||
> β οΈ This project is in very early stage.<br/> | ||
> For details on planned features and future direction please refer to the [Roadmap](https://github.com/Brooooooklyn/canvas/issues/113). | ||
β οΈ This project is in very early stage.<br/> | ||
For details on planned features and future direction please refer to the [Roadmap](https://github.com/Brooooooklyn/canvas/issues/113). | ||
[δΈζζζ‘£](./README-zh.md) | ||
# Install | ||
```bash | ||
yarn add @napi-rs/canvas | ||
npm install @napi-rs/canvas | ||
``` | ||
# Support matrix | ||
@@ -25,2 +32,3 @@ | ||
| Linux aarch64 gnu | β | β | β | β | | ||
| Linux aarch64 musl | β | β | β | β | | ||
| Linux arm gnueabihf | β | β | β | β | | ||
@@ -70,2 +78,55 @@ | Linux aarch64 android | β | β | β | β | | ||
# Performance | ||
See [benchmark](./benchmark) for benchmark code. | ||
Hardware info: | ||
``` | ||
OS: Windows 10 x86_64 | ||
Host: Micro-Star International Co., Ltd. MS-7C35 | ||
Kernel: 10.0.19043 | ||
Terminal: Windows Terminal | ||
CPU: AMD Ryzen 9 5950X (32) @ 3.400GHz | ||
Memory: 32688MiB | ||
``` | ||
``` | ||
β― pnpm bench | ||
> @napi-rs/canvas@0.0.9 bench D:\workspace\skia-rs | ||
> node -r @swc-node/register benchmark/bench.ts | ||
Running "Draw house" suite... | ||
Progress: 100% | ||
skia-canvas: | ||
26 ops/s, Β±0.70% | slowest, 29.73% slower | ||
node-canvas: | ||
30 ops/s, Β±6.95% | 18.92% slower | ||
@napi-rs/skia: | ||
37 ops/s, Β±6.30% | fastest | ||
Finished 3 cases! | ||
Fastest: @napi-rs/skia | ||
Slowest: skia-canvas | ||
Running "Draw gradient" suite... | ||
Progress: 100% | ||
skia-canvas: | ||
36 ops/s, Β±6.12% | 14.29% slower | ||
node-canvas: | ||
34 ops/s, Β±5.60% | slowest, 19.05% slower | ||
@napi-rs/skia: | ||
42 ops/s, Β±0.53% | fastest | ||
Finished 3 cases! | ||
Fastest: @napi-rs/skia | ||
Slowest: node-canvas | ||
``` | ||
# Features | ||
@@ -216,7 +277,7 @@ | ||
# Install NPM packages, build the Node.js addon: | ||
$ yarn install --ignore-scripts | ||
$ yarn build | ||
$ pnpm install --ignore-scripts | ||
$ pnpm build | ||
# All done! Run test cases or examples now: | ||
$ yarn test | ||
$ pnpm test | ||
$ node example/tiger.js | ||
@@ -239,8 +300,8 @@ ``` | ||
# Install NPM packages, build the Node.js addon: | ||
$ yarn install --ignore-scripts | ||
$ yarn build | ||
$ pnpm install --ignore-scripts | ||
$ pnpm build | ||
# All done! Run test cases or examples now: | ||
$ yarn test | ||
$ pnpm test | ||
$ node example/tiger.js | ||
``` |
56413
1184
303
10
28