@aduh95/viz.js
Advanced tools
Comparing version 3.0.0-beta.4 to 3.0.0-beta.5
@@ -8,4 +8,5 @@ # Changelog | ||
- The library is now compiled to WASM, which shrinks the file size (Viz.js | ||
(2.1.2 full version) brotlified: 409K; @aduh95/viz.js (3.0.0-beta.3) | ||
brotlified: 371K), should improve performances, allows dynamic memory growth. | ||
(2.1.2 full version) brotlified: 409K; @aduh95/viz.js (3.0.0-beta.5 browser | ||
version) brotlified: 368K; 10% decrease), should improve performances and | ||
allows dynamic memory growth. | ||
- The library is able to reset its internal error state, which makes the | ||
@@ -30,5 +31,13 @@ [v2 wiki caveat](https://github.com/mdaines/viz.js/wiki/Caveats#rendering-graphs-with-user-input) | ||
- **BREAKING:** Remove _lite_ version, Viz.js now comes in only one variant. | ||
- **BREAKING:** The `render.js` file (that replaces `full.render.js`) exports a | ||
worker_thread factory. It's available through `@aduh95/viz.js/worker` on | ||
Node.js and bundle tools that support `package.json`#`exports`. | ||
- **BREAKING:** The `full.render.js` script is replaced by the `render.node.mjs` | ||
and `render.browser.js` modules. | ||
- **BREAKING:** The `render.node.js` module (that replaces `full.render.js`) | ||
exports a worker_thread factory when imported from the main thread. It's | ||
available through `@aduh95/viz.js/worker` specifier on Node.js and bundle | ||
tools that support `package.json`#`exports`. | ||
- **BREAKING:** The `render.browser.js` module (that replaces `full.render.js`) | ||
exports a function which takes a Module object as parameter. You should use it | ||
to give the path to `render.wasm` the Emscripten script. You should not import | ||
this module from the main thread. On bundle tools that support | ||
`package.json`#`exports`, you can use the specifier `@aduh95/viz.js/worker`. | ||
- **BREAKING:** Compiles to WebAssembly, which cannot be bundled in the | ||
@@ -35,0 +44,0 @@ `render.js` file like asm.js used to. Depending on your bundling tool, you may |
{ | ||
"name": "@aduh95/viz.js", | ||
"version": "3.0.0-beta.4", | ||
"version": "3.0.0-beta.5", | ||
"description": "A hack to put Graphviz on the web.", | ||
@@ -14,3 +14,7 @@ "main": "./dist/index.cjs", | ||
}, | ||
"./worker": "./dist/render.js" | ||
"./wasm": "./dist/render.wasm", | ||
"./worker": { | ||
"import": "./dist/render.node.mjs", | ||
"browser": "./dist/render.browser.js" | ||
} | ||
}, | ||
@@ -30,4 +34,5 @@ "type": "commonjs", | ||
"files": [ | ||
"worker", | ||
"dist/" | ||
"dist/", | ||
"wasm", | ||
"worker" | ||
], | ||
@@ -47,2 +52,3 @@ "contributors": [ | ||
"puppeteer": "^2.0.0", | ||
"rollup": "^1.31.0", | ||
"terser": "^4.6.3", | ||
@@ -49,0 +55,0 @@ "typescript": "^3.8.0-beta" |
@@ -55,20 +55,54 @@ # Viz.js | ||
You can either use the `worker` or the `workerURL` on the constructor. | ||
You can either use the `worker` or the `workerURL` on the constructor. Note that | ||
when using `workerURL`, `Viz` constructor will try to spawn a webworker using | ||
`type=module`. If you don't want a module worker, you should provide a `worker` | ||
instead. | ||
The Worker module exports a function that takes | ||
[an Emscripten Module object](https://emscripten.org/docs/api_reference/module.html#affecting-execution). | ||
You can use that to tweak the defaults, the only requirement is to define a | ||
`locateFile` method that returns the URL of the WASM file. | ||
```js | ||
import Viz from "/node_modules/@aduh95/viz.js/dist/index.mjs"; | ||
// worker.js | ||
import initWASM from "@aduh95/viz.js/worker"; | ||
// If you are not using a bundler that supports package.json#exports | ||
// use /node_modules/@aduh95/viz.js/dist/render.browser.js instead. | ||
const workerURL = "/node_modules/@aduh95/viz.js/dist/render.js"; | ||
import wasmURL from "file-loader!@aduh95/viz.js/wasm"; | ||
// If you are not using a bundler that supports package.json#exports | ||
// Or doesn't have a file-loader plugin to get URL of the asset, | ||
// use "/node_modules/@aduh95/viz.js/dist/render.wasm" instead. | ||
initWASM({ | ||
locateFile() { | ||
return wasmURL; | ||
}, | ||
}); | ||
``` | ||
N.B.: Emscripten `render.js` expects to find a `render.wasm` on the same | ||
directory as `render.js`. If you are using a building tool that changes file | ||
names and/or file location, the loading would fail. | ||
And give feed that module to the main thread: | ||
If you are using a CDN or loading the files from a different origin, most | ||
browsers will block you from spawning a cross-origin webworker. There is a | ||
workaround: | ||
```js | ||
//main.js | ||
import Viz from "@aduh95/viz.js"; | ||
// If you are not using a bundler that supports package.json#exports | ||
// use /node_modules/@aduh95/viz.js/dist/index.mjs instead. | ||
const workerURL = "/worker.js"; | ||
let viz; | ||
async function dot2svg(dot, options) { | ||
if (viz === undefined) { | ||
viz = new Viz({ workerURL }); | ||
} | ||
return viz.renderString(dot, options); | ||
} | ||
``` | ||
If you are using a CDN and don't want a separate file for the worker module, | ||
there is a workaround: | ||
```js | ||
import Viz from "https://unpkg.com/@aduh95/viz.js@3.0.0-beta.2/dist/index.mjs"; | ||
import Viz from "https://unpkg.com/@aduh95/viz.js@3.0.0-beta.5/dist/index.mjs"; | ||
@@ -78,11 +112,11 @@ const workerURL = URL.createObjectURL( | ||
[ | ||
"self.Module =", | ||
"const Module =", | ||
"{ locateFile: file =>", | ||
'"https://unpkg.com/@aduh95/viz.js@3.0.0-beta.2/dist/"', | ||
'"https://unpkg.com/@aduh95/viz.js@3.0.0-beta.5/dist/"', | ||
"+ file", | ||
"};", // Module.locateFile let the worker resolve the wasm file URL | ||
"importScripts(", // importScripts is not restricted by same-origin policy | ||
"import(", // importScripts is not restricted by same-origin policy | ||
"Module.locateFile(", // We can use it to load the JS file | ||
'"render.js"', | ||
"));", | ||
")).then(i=>i(Module));", | ||
], | ||
@@ -89,0 +123,0 @@ { type: "application/javascript" } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
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
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
1340360
12
693
1
154
1
6
8