@resvg/resvg-js
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -12,2 +12,31 @@ # Change Log | ||
## [1.1.0] - 2021-11-11 | ||
### Added | ||
- feat: implement `renderAsync()` function. By @Brooooooklyn | ||
We have made a major upgrade to napi-rs, from v1 to 2.x alpha. This allows better support for asynchronous binding and automatic generation of TypeScript definitions. Now you can enjoy `async/await`. | ||
```js | ||
const { renderAsync } = require('@resvg/resvg-js') | ||
async function main() { | ||
const pngData = await renderAsync(/* SVG string or buffer */) | ||
} | ||
``` | ||
- feat: The input to the `render()` and `renderAsync()` functions supports buffer. | ||
- feat: improved webpack support, no more need `@node-rs/helper` dependency. | ||
The `@node-rs/helper` is convenient to load native binary cross platform and cpu arch. But it's not friendly to [`webpack`](https://github.com/webpack/webpack), [`vercel/nft`](https://github.com/vercel/nft) and [`vercel/ncc`](https://github.com/vercel/ncc) because the logic is too dynamic. | ||
- feat: add `example/compare.js`. | ||
### Changed | ||
- fix: the default font no longer throws an error if it is not found, it changes to a warning. | ||
- chore: benchmark adds tests for svg icons and other improvements. | ||
- chore: upgrade Rust Edition to 2021. | ||
## [1.0.4] - 2021-10-19 | ||
@@ -90,3 +119,4 @@ | ||
[unreleased]: https://github.com/yisibl/resvg-js/compare/v1.0.4...HEAD | ||
[unreleased]: https://github.com/yisibl/resvg-js/compare/v1.1.0...HEAD | ||
[1.1.0]: https://github.com/yisibl/resvg-js/compare/v1.0.4...v1.1.0 | ||
[1.0.4]: https://github.com/yisibl/resvg-js/compare/v1.0.3...v1.0.4 | ||
@@ -93,0 +123,0 @@ [1.0.3]: https://github.com/yisibl/resvg-js/compare/v1.0.2...v1.0.3 |
@@ -44,2 +44,7 @@ /// <reference types="node" /> | ||
export function render(svg: string, options?: ResvgRenderOptions): Buffer | ||
export function render(svg: string | Buffer, options?: ResvgRenderOptions | null): Buffer | ||
export function renderAsync( | ||
svg: string | Buffer, | ||
options?: ResvgRenderOptions | null, | ||
signal?: AbortSignal | null, | ||
): Promise<Buffer> |
24
index.js
@@ -1,11 +0,15 @@ | ||
const { loadBinding } = require('@node-rs/helper') | ||
const { render: _render, renderAsync: _renderAsync } = require('./js-binding') | ||
/** | ||
* __dirname means load native addon from current dir | ||
* 'resvg' means native addon name is `resvg` | ||
* the first arguments was decided by `napi.name` field in `package.json` | ||
* the second arguments was decided by `name` field in `package.json` | ||
* loadBinding helper will load `resvg.[PLATFORM].node` from `__dirname` first | ||
* If failed to load addon, it will fallback to load from `@resvg/resvgjs-[PLATFORM]` | ||
*/ | ||
module.exports = loadBinding(__dirname, 'resvgjs', '@resvg/resvg-js') | ||
module.exports.render = function render(svgString, options) { | ||
if (options) { | ||
return _render(svgString, JSON.stringify(options)) | ||
} | ||
return _render(svgString) | ||
} | ||
module.exports.renderAsync = function renderAsync(svgString, options, signal) { | ||
if (options) { | ||
return _renderAsync(svgString, JSON.stringify(options), signal) | ||
} | ||
return _renderAsync(svgString, null, signal) | ||
} |
{ | ||
"name": "@resvg/resvg-js", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs", | ||
@@ -21,3 +21,5 @@ "main": "index.js", | ||
"index.d.ts", | ||
"index.js" | ||
"index.js", | ||
"js-binding.js", | ||
"js-binding.d.ts" | ||
], | ||
@@ -50,13 +52,14 @@ "napi": { | ||
"bench": "node -r @swc-node/register benchmark/bench.ts", | ||
"build": "napi build --platform --release", | ||
"build:debug": "napi build --platform", | ||
"build": "napi build --platform --release --js js-binding.js --dts js-binding.d.ts", | ||
"build:debug": "napi build --platform --js js-binding.js --dts js-binding.d.ts", | ||
"format": "run-p format:md format:json format:yaml format:source format:rs", | ||
"format:md": "prettier --parser markdown --write './**/*.md'", | ||
"format:json": "prettier --parser json --write './**/*.json'", | ||
"format:svg": "prettier --parser html --write './**/*.svg'", | ||
"format:rs": "cargo fmt", | ||
"format:source": "prettier --config ./package.json --write './**/*.{js,ts}'", | ||
"format:source": "prettier --config ./package.json --write './**/*.{js,ts,mjs}'", | ||
"format:yaml": "prettier --parser yaml --write './**/*.{yml,yaml}'", | ||
"lint": "eslint . -c ./.eslintrc.yml './**/*.{ts,tsx,js}'", | ||
"lint:fix": "eslint . -c ./.eslintrc.yml './**/*.{ts,tsx,js}' --fix", | ||
"prepublishOnly": "napi prepublish -t npm", | ||
"prepublishOnly": "napi prepublish -t npm && esbuild js-binding.js --minify --allow-overwrite --outfile=js-binding.js", | ||
"test": "ava", | ||
@@ -66,25 +69,27 @@ "version": "napi version" | ||
"devDependencies": { | ||
"@napi-rs/cli": "^1.3.3", | ||
"@swc-node/register": "^1.3.5", | ||
"@types/node": "^14.17.22", | ||
"@typescript-eslint/eslint-plugin": "^4.33.0", | ||
"@typescript-eslint/parser": "^4.33.0", | ||
"@napi-rs/canvas": "^0.1.14", | ||
"@napi-rs/cli": "^2.0.0-alpha.3", | ||
"@swc-node/register": "^1.4.0", | ||
"@types/node": "^16.11.7", | ||
"@types/sharp": "^0.29.3", | ||
"@typescript-eslint/eslint-plugin": "^5.3.1", | ||
"@typescript-eslint/parser": "^5.3.1", | ||
"ava": "^3.15.0", | ||
"benny": "^3.7.0", | ||
"benny": "^3.7.1", | ||
"chalk": "^4.1.2", | ||
"eslint": "^7.32.0", | ||
"esbuild": "^0.13.13", | ||
"eslint": "^8.2.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.24.2", | ||
"eslint-plugin-import": "^2.25.3", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-sonarjs": "^0.10.0", | ||
"husky": "^7.0.2", | ||
"husky": "^7.0.4", | ||
"jimp": "^0.16.1", | ||
"lint-staged": "^11.2.0", | ||
"lint-staged": "^11.2.6", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.4.1", | ||
"typescript": "^4.4.3" | ||
"sharp": "^0.29.2", | ||
"svg2img": "^0.9.4", | ||
"typescript": "^4.4.4" | ||
}, | ||
"dependencies": { | ||
"@node-rs/helper": "^1.2.1" | ||
}, | ||
"lint-staged": { | ||
@@ -103,2 +108,5 @@ "*.@(js|ts|tsx)": [ | ||
"prettier --parser json --write" | ||
], | ||
"*.svg": [ | ||
"prettier --parser html --write" | ||
] | ||
@@ -127,14 +135,14 @@ }, | ||
"optionalDependencies": { | ||
"@resvg/resvg-js-win32-x64-msvc": "1.0.4", | ||
"@resvg/resvg-js-darwin-x64": "1.0.4", | ||
"@resvg/resvg-js-linux-x64-gnu": "1.0.4", | ||
"@resvg/resvg-js-linux-x64-musl": "1.0.4", | ||
"@resvg/resvg-js-linux-arm64-gnu": "1.0.4", | ||
"@resvg/resvg-js-win32-ia32-msvc": "1.0.4", | ||
"@resvg/resvg-js-linux-arm-gnueabihf": "1.0.4", | ||
"@resvg/resvg-js-darwin-arm64": "1.0.4", | ||
"@resvg/resvg-js-android-arm64": "1.0.4", | ||
"@resvg/resvg-js-linux-arm64-musl": "1.0.4", | ||
"@resvg/resvg-js-win32-arm64-msvc": "1.0.4" | ||
"@resvg/resvg-js-win32-x64-msvc": "1.1.0", | ||
"@resvg/resvg-js-darwin-x64": "1.1.0", | ||
"@resvg/resvg-js-linux-x64-gnu": "1.1.0", | ||
"@resvg/resvg-js-linux-x64-musl": "1.1.0", | ||
"@resvg/resvg-js-linux-arm64-gnu": "1.1.0", | ||
"@resvg/resvg-js-win32-ia32-msvc": "1.1.0", | ||
"@resvg/resvg-js-linux-arm-gnueabihf": "1.1.0", | ||
"@resvg/resvg-js-darwin-arm64": "1.1.0", | ||
"@resvg/resvg-js-android-arm64": "1.1.0", | ||
"@resvg/resvg-js-linux-arm64-musl": "1.1.0", | ||
"@resvg/resvg-js-win32-arm64-msvc": "1.1.0" | ||
} | ||
} |
@@ -6,7 +6,7 @@ # resvg-js | ||
> A high-performance SVG renderer, powered by Rust based [resvg](https://github.com/RazrFalcon/resvg/) and [napi-rs](https://github.com/napi-rs/napi-rs). | ||
> resvg-js is a high-performance SVG renderer, powered by Rust based [resvg](https://github.com/RazrFalcon/resvg/) and [napi-rs](https://github.com/napi-rs/napi-rs). | ||
- Fast, safe and zero dependencies! | ||
- No need for node-gyp and postinstall, the `.node` file has been compiled for you. | ||
- Cross-platform support, including [Apple M1](https://www.apple.com/newsroom/2020/11/apple-unleashes-m1/). | ||
- No need for node-gyp and postinstall, the `.node` file has been compiled for you. | ||
- Support system fonts and custom fonts in SVG text. | ||
@@ -34,6 +34,24 @@ | ||
| SVG | PNG | | ||
| ---------------------------------------- | -------------------------------------------- | | ||
| <img width="390" src="example/text.svg"> | <img width="390" src="example/text-out.png"> | | ||
| SVG | PNG | | ||
| ------------------------------------------------------------------- | ----------------------------------------------------------------------- | | ||
| <img width="500" src="example/anime_girl.svg" alt="Anime girl SVG"> | <img width="500" src="example/out-resvg-js.png" alt="Anime girl png" /> | | ||
| <img width="500" src="example/text.svg"> | <img width="500" src="example/text-out.png"> | | ||
## Benchmark | ||
```shell | ||
Running "resize width" suite... | ||
resvg-js(Rust): | ||
12 ops/s, ±22.66% | fastest 🚀 | ||
sharp: | ||
9 ops/s, ±64.52% | 25% slower | ||
skr-canvas(Rust): | ||
7 ops/s, ±3.72% | 41.67% slower | ||
svg2img(canvg and node-canvas): | ||
6 ops/s, ±16.94% | slowest, 50% slower | ||
``` | ||
## Support matrix | ||
@@ -66,33 +84,25 @@ | ||
## Build | ||
## Test in local | ||
You can set the name of the generated `.node` file in `napi.name` of package.json. | ||
After `npm run build` command, you can see `resvgjs.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs). | ||
## Develop requirements | ||
- Install latest `Rust` | ||
- Install `Node.js@10+` which fully supported `Node-API` | ||
- Install `yarn@1.x` | ||
## Test in local | ||
```bash | ||
npm i | ||
npm build | ||
npm test | ||
``` | ||
- yarn | ||
- yarn build | ||
- yarn test | ||
## Roadmap & Contributing | ||
And you will see: | ||
I will consider implementing the following features, if you happen to be interested, | ||
please feel free to discuss with me or submit a PR. | ||
```bash | ||
$ ava --verbose | ||
- [x] Support async API | ||
- [x] Upgrade to napi-rs v2 | ||
- [ ] Support for getting SVG Bounding box | ||
- [ ] Output usvg-simplified SVG string | ||
- [ ] Support for generating more lossless bitmap formats, e.g. avif, webp, JPEG XL | ||
- [ ] Support WebAssembly(.wasm) | ||
✔ sync function from native code | ||
✔ sleep function from native code (201ms) | ||
─ | ||
2 tests passed | ||
✨ Done in 1.12s. | ||
``` | ||
## Release package | ||
@@ -99,0 +109,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36882
11
8
78
122
24
2
2
+ Added@resvg/resvg-js-android-arm64@1.1.0(transitive)
+ Added@resvg/resvg-js-darwin-arm64@1.1.0(transitive)
+ Added@resvg/resvg-js-darwin-x64@1.1.0(transitive)
+ Added@resvg/resvg-js-linux-arm-gnueabihf@1.1.0(transitive)
+ Added@resvg/resvg-js-linux-arm64-gnu@1.1.0(transitive)
+ Added@resvg/resvg-js-linux-arm64-musl@1.1.0(transitive)
+ Added@resvg/resvg-js-linux-x64-gnu@1.1.0(transitive)
+ Added@resvg/resvg-js-linux-x64-musl@1.1.0(transitive)
+ Added@resvg/resvg-js-win32-arm64-msvc@1.1.0(transitive)
+ Added@resvg/resvg-js-win32-ia32-msvc@1.1.0(transitive)
+ Added@resvg/resvg-js-win32-x64-msvc@1.1.0(transitive)
- Removed@node-rs/helper@^1.2.1
- Removed@napi-rs/triples@1.2.0(transitive)
- Removed@node-rs/helper@1.6.0(transitive)
- Removed@resvg/resvg-js-android-arm64@1.0.4(transitive)
- Removed@resvg/resvg-js-darwin-arm64@1.0.4(transitive)
- Removed@resvg/resvg-js-darwin-x64@1.0.4(transitive)
- Removed@resvg/resvg-js-linux-arm-gnueabihf@1.0.4(transitive)
- Removed@resvg/resvg-js-linux-arm64-gnu@1.0.4(transitive)
- Removed@resvg/resvg-js-linux-arm64-musl@1.0.4(transitive)
- Removed@resvg/resvg-js-linux-x64-gnu@1.0.4(transitive)
- Removed@resvg/resvg-js-linux-x64-musl@1.0.4(transitive)
- Removed@resvg/resvg-js-win32-arm64-msvc@1.0.4(transitive)
- Removed@resvg/resvg-js-win32-ia32-msvc@1.0.4(transitive)
- Removed@resvg/resvg-js-win32-x64-msvc@1.0.4(transitive)