Socket
Socket
Sign inDemoInstall

@resvg/resvg-js

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@resvg/resvg-js - npm Package Compare versions

Comparing version 1.4.0 to 2.0.0-alpha.0

12

index.js
const { render: _render, renderAsync: _renderAsync } = require('./js-binding')
module.exports.render = function render(svgString, options) {
module.exports.render = function render(svg, options) {
if (options) {
return _render(svgString, JSON.stringify(options))
return _render(svg, JSON.stringify(options))
}
return _render(svgString)
return _render(svg)
}
module.exports.renderAsync = function renderAsync(svgString, options, signal) {
module.exports.renderAsync = function renderAsync(svg, options, signal) {
if (options) {
return _renderAsync(svgString, JSON.stringify(options), signal)
return _renderAsync(svg, JSON.stringify(options), signal)
}
return _renderAsync(svgString, null, signal)
return _renderAsync(svg, null, signal)
}

@@ -6,10 +6,4 @@ /* tslint:disable */

export class ExternalObject<T> {
readonly '': {
readonly '': unique symbol
[K: symbol]: T
}
}
/** Renders an SVG */
export function render(svg: string | Buffer, options?: string | undefined | null): Buffer
export function renderAsync(svg: string | Buffer, options?: string | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
{
"name": "@resvg/resvg-js",
"version": "1.4.0",
"version": "2.0.0-alpha.0",
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",

@@ -52,4 +52,11 @@ "main": "index.js",

"bench": "node -r @swc-node/register benchmark/bench.ts",
"bundle": "run-p bundle:*",
"bundle:js": "node bundle.js",
"bundle:dts": "dts-bundle-generator --external-types -o wasm/index.d.ts wasm-binding.ts",
"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",
"build:wasm": "run-s build:wasm-web copy-wasm playground bundle",
"build:wasm-web": "wasm-pack build --target web --out-name index --out-dir wasm/dist --release",
"copy-wasm": "copyfiles -f wasm/dist/index_bg.wasm ./wasm",
"playground": "copyfiles -f playground/index.html ./wasm",
"format": "run-p format:md format:json format:yaml format:source format:rs",

@@ -65,3 +72,4 @@ "format:md": "prettier --parser markdown --write './**/*.md'",

"prepublishOnly": "napi prepublish -t npm && esbuild js-binding.js --minify --allow-overwrite --outfile=js-binding.js",
"test": "ava",
"test": "ava __test__/**/index*.*",
"test:wasm": "ava __test__/**/wasm*.*",
"version": "napi version"

@@ -71,3 +79,3 @@ },

"@napi-rs/canvas": "^0.1.19",
"@napi-rs/cli": "^2.4.2",
"@napi-rs/cli": "^2.4.4",
"@swc-node/register": "^1.4.2",

@@ -81,4 +89,6 @@ "@types/node": "^17.0.1",

"chalk": "^4.1.2",
"esbuild": "^0.14.11",
"eslint": "^8.6.0",
"copyfiles": "^2.4.1",
"dts-bundle-generator": "^6.5.0",
"esbuild": "^0.14.21",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.3.0",

@@ -92,5 +102,5 @@ "eslint-plugin-import": "^2.25.3",

"npm-run-all": "^4.1.5",
"oslllo-svg2": "^0.3.1",
"oslllo-svg2": "0.3.1",
"prettier": "^2.5.1",
"sharp": "^0.29.3",
"sharp": "^0.30.0",
"svg2img": "^0.9.4",

@@ -138,15 +148,15 @@ "typescript": "^4.5.4"

"optionalDependencies": {
"@resvg/resvg-js-win32-x64-msvc": "1.4.0",
"@resvg/resvg-js-darwin-x64": "1.4.0",
"@resvg/resvg-js-linux-x64-gnu": "1.4.0",
"@resvg/resvg-js-linux-x64-musl": "1.4.0",
"@resvg/resvg-js-linux-arm64-gnu": "1.4.0",
"@resvg/resvg-js-win32-ia32-msvc": "1.4.0",
"@resvg/resvg-js-linux-arm-gnueabihf": "1.4.0",
"@resvg/resvg-js-darwin-arm64": "1.4.0",
"@resvg/resvg-js-android-arm64": "1.4.0",
"@resvg/resvg-js-android-arm-eabi": "1.4.0",
"@resvg/resvg-js-linux-arm64-musl": "1.4.0",
"@resvg/resvg-js-win32-arm64-msvc": "1.4.0"
"@resvg/resvg-js-win32-x64-msvc": "2.0.0-alpha.0",
"@resvg/resvg-js-darwin-x64": "2.0.0-alpha.0",
"@resvg/resvg-js-linux-x64-gnu": "2.0.0-alpha.0",
"@resvg/resvg-js-linux-x64-musl": "2.0.0-alpha.0",
"@resvg/resvg-js-linux-arm64-gnu": "2.0.0-alpha.0",
"@resvg/resvg-js-win32-ia32-msvc": "2.0.0-alpha.0",
"@resvg/resvg-js-linux-arm-gnueabihf": "2.0.0-alpha.0",
"@resvg/resvg-js-darwin-arm64": "2.0.0-alpha.0",
"@resvg/resvg-js-android-arm64": "2.0.0-alpha.0",
"@resvg/resvg-js-android-arm-eabi": "2.0.0-alpha.0",
"@resvg/resvg-js-linux-arm64-musl": "2.0.0-alpha.0",
"@resvg/resvg-js-win32-arm64-msvc": "2.0.0-alpha.0"
}
}

@@ -12,2 +12,3 @@ # resvg-js

- Support system fonts and custom fonts in SVG text.
- Support WebAssembly.

@@ -39,2 +40,64 @@ ## Installation

## Usage
### Node.js
```js
const { promises } = require('fs')
const { join } = require('path')
const { performance } = require('perf_hooks')
const { render } = require('@resvg/resvg-js')
async function main() {
const svg = await promises.readFile(join(__dirname, './text.svg'))
const t = performance.now()
const pngData = render(svg, {
background: 'rgba(238, 235, 230, .9)',
fitTo: {
mode: 'width',
value: 1200,
},
font: {
fontFiles: ['./example/SourceHanSerifCN-Light-subset.ttf'], // Load custom fonts.
loadSystemFonts: false, // It will be faster to disable loading system fonts.
defaultFontFamily: 'Source Han Serif CN Light',
},
logLevel: 'debug',
})
console.info('✨ Done in', performance.now() - t, 'ms')
await promises.writeFile(join(__dirname, './text-out.png'), pngData)
}
main()
```
### WebAssembly
Although we support the use of WASM packages in Node.js, this is not recommended. The native addon performs better.
#### Browser(ES Modules)
```js
import { render, initWasm } from '@resvg/resvg-js-wasm'
;(async function () {
// The wasm must be initialized first
await initWasm(fetch('./index_bg.wasm'))
const opts = {
fitTo: {
mode: 'width',
value: 800,
},
}
const svg = '<svg> ... </svg>' // input svg, String or Uint8Array
const png = render(svg, opts) // PNG data, Uint8Array
const svgUrl = URL.createObjectURL(new Blob([png], { type: 'image/png' }))
document.getElementById('output').src = svgUrl
})()
```
See [playground](playground/index.html).
## Benchmark

@@ -86,15 +149,29 @@

## Test in local
## Test or Contributing
- Install latest `Rust`
- Install `Node.js@10+` which fully supported `Node-API`
- install `wasm-pack`
```bash
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
```
### Build Node.js bindings
```bash
npm i
npm build
npm run build
npm test
```
## Roadmap & Contributing
### Build WebAssembly bindings
```bash
npm i
npm run build:wasm
npm run test:wasm
```
## Roadmap
I will consider implementing the following features, if you happen to be interested,

@@ -105,6 +182,6 @@ please feel free to discuss with me or submit a PR.

- [x] Upgrade to napi-rs v2
- [x] Support WebAssembly(.wasm)
- [ ] 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)

@@ -115,3 +192,3 @@ ## Release package

```
```bash
# 1.0.0 => 1.0.1

@@ -122,4 +199,2 @@ npm version patch

npm version minor
git push --follow-tags
```

@@ -130,1 +205,3 @@

[MPLv2.0](https://www.mozilla.org/en-US/MPL/)
Copyright (c) 2021-present, yisibl(一丝)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc