@aduh95/viz.js
Advanced tools
Comparing version 3.0.0-beta.5 to 3.0.0-beta.6
{ | ||
"name": "@aduh95/viz.js", | ||
"version": "3.0.0-beta.5", | ||
"version": "3.0.0-beta.6", | ||
"description": "A hack to put Graphviz on the web.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs", |
@@ -106,16 +106,15 @@ # Viz.js | ||
```js | ||
import Viz from "https://unpkg.com/@aduh95/viz.js@3.0.0-beta.5/dist/index.mjs"; | ||
import Viz from "https://unpkg.com/@aduh95/viz.js@3.0.0-beta.6"; | ||
const vizDistFolder = "https://unpkg.com/@aduh95/viz.js@3.0.0-beta.6/dist"; | ||
const workerURL = URL.createObjectURL( | ||
new Blob( | ||
[ | ||
"const Module =", | ||
"{ locateFile: file =>", | ||
'"https://unpkg.com/@aduh95/viz.js@3.0.0-beta.5/dist/"', | ||
"+ file", | ||
"};", // Module.locateFile let the worker resolve the wasm file URL | ||
"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));", | ||
`import init from "${vizDistFolder}/render.browser.js";`, | ||
"init({", | ||
"locateFile(fileName) {", | ||
// allows the worker to resolve the wasm file URL | ||
`return \`${vizDistFolder}/\${fileName}\`;`, | ||
"}", | ||
"});", | ||
], | ||
@@ -133,2 +132,58 @@ { type: "application/javascript" } | ||
If you want to support browsers that do not support loading webworker as module, | ||
or want a custom message handling, you can use dynamic imports to help you: | ||
```js | ||
// worker.js | ||
/** | ||
* Lazy-loads Viz.js message handler | ||
* @returns {(event: MessageEvent) => Promise<any>} | ||
*/ | ||
function getVizMessageHandler() { | ||
if (this._messageHandler === undefined) { | ||
const vizDistFolder = "https://unpkg.com/@aduh95/viz.js@3.0.0-beta.6/dist"; | ||
const Module = { | ||
// locateFile is used by render module to locate WASM file. | ||
locateFile: fileName => `${vizDistFolder}/${fileName}`, | ||
}; | ||
this._messageHandler = import(Module.locateFile("render.browser.js")).then( | ||
({ default: init, onmessage }) => { | ||
// to avoid conflicts, disable viz.js message handler | ||
self.removeEventListener("message", onmessage); | ||
return init(Module).then(() => onmessage); | ||
} | ||
); | ||
} | ||
return this._messageHandler; | ||
} | ||
self.addEventListener("message", event => { | ||
if (event.data.id) { | ||
// handling event sent by viz.js | ||
getVizMessageHandler() | ||
.then(onmessage => onmessage(event)) | ||
.catch(error => { | ||
// handle dynamic import error here | ||
console.error(error); | ||
// Note: If an error is emitted by Viz.js internals (dot syntax error, | ||
// WASM file initialization error, etc.), the error is catch and sent | ||
// directly through postMessage. | ||
// If you think this behavior is not ideal, please open an issue. | ||
}); | ||
} else { | ||
// handle other messages | ||
} | ||
}); | ||
``` | ||
### Deno | ||
_The support is experimental. You would probably need to monkey-patch the | ||
unimplemented web APIs. Please check the test folder for an example of | ||
implementation._ | ||
As Deno aims to expose all the web API, you can use the browser implementation. | ||
## Building From Source | ||
@@ -135,0 +190,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
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
1341523
209
7
690