Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aduh95/viz.js

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aduh95/viz.js - npm Package Compare versions

Comparing version 3.0.0-beta.5 to 3.0.0-beta.6

2

package.json
{
"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

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