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.6 to 3.0.0-beta.7

dist/renderFunction.d.ts

27

CHANGELOG.md

@@ -8,4 +8,4 @@ # 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.5 browser
version) brotlified: 368K; 10% decrease), should improve performances and
(2.1.2 full version) brotlified: 409K; @aduh95/viz.js (3.0.0-beta.7 browser
version) brotlified: 337K; 18% decrease), should improve performances and
allows dynamic memory growth.

@@ -15,6 +15,7 @@ - The library is able to reset its internal error state, which makes the

unnecessary.
- Rendering from main thread is no longer supported, you must use a worker
(webworker or worker_thread).
- Rendering from main thread is no longer supported on the default async API,
you must use a worker (webworker or worker_thread).
- The JS code is now transpiled from TypeScript, and typings are packed within
the npm package. You can find the API documentation there!
- There is a synchronous version available for legacy Node.js support.

@@ -24,3 +25,3 @@ ##### Breaking changes and deprecations

- **BREAKING:** Bump required version of Node.js to v12 LTS (might work on v10
LTS using CLI flags).
LTS using CLI flags or the synchronous API).
- **BREAKING:** Remove `Viz.prototype.renderSVGElement`. You can use

@@ -46,3 +47,5 @@ `renderString` and `DOMParser` to achieve the same result.

`render.js` file like asm.js used to. Depending on your bundling tool, you may
need some extra config to make everything work.
need some extra config to make everything work. You might also use the
synchronous API, which bundles the asm.js code, although its usage should be
strictly limited to Node.js or webworker use.
- **BREAKING:** Remove ES5 and CJS dist files, all modern browsers now support

@@ -59,3 +62,3 @@ ES2015 modules. If you want to support an older browser, you would need to

- Add support for Node.js `worker_threads`.
- Refactor JS files to Typescript.
- Refactor JS files to TypeScript.
- Refactor `viz.c` to C++ to use

@@ -69,7 +72,11 @@ [Emscripten's Embind](https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html).

- Switch to Mocha and Puppeteer for browser testing.
- Add synchronous API using asm.js.
- Upgrade deps:
- Upgrade Emscripten to 1.38.44
- Upgrade Graphviz to 2.43.x (unstable)
- Upgrade Emscripten to 1.39.12
- Upgrade Graphviz to 2.44.0
- Upgrade Expat to 2.2.9
- Upgrade Mocha to 7.0.1
- Upgrade Rollup to 2.x
- Change test chain:
- Upgrade Mocha to 7.1.1
- Use Puppeteer instead of Selenium

@@ -76,0 +83,0 @@ ### Viz.js v2.1.2 (2018-12-08)

/// <reference types="node" />
import type { Worker as NodeJSWorker } from "worker_threads";
import type { RenderOptions, GraphvizJSONOutput } from "./types";
declare type VizConstructorOptionsWorkerURL = {

@@ -10,27 +11,2 @@ workerURL: string;

export declare type VizConstructorOptions = VizConstructorOptionsWorkerURL | VizConstructorOptionsWorker;
declare type Image = {
path: string;
height: string | number;
width: string | number;
};
declare type File = {
path: string;
data: string;
};
export declare type RenderOptions = {
engine?: "circo" | "dot" | "fdp" | "neato" | "osage" | "twopi";
format?: "svg" | "dot" | "xdot" | "plain" | "plain-ext" | "ps" | "ps2" | "json" | "json0";
yInvert?: boolean;
images?: Image[];
files?: File[];
nop: number;
};
export declare type GraphvizJSONOutput = {
name: string;
directed: boolean;
strict: boolean;
_subgraph_cnt: number;
objects?: GraphvizJSONOutput[];
[key: string]: any;
};
declare class Viz {

@@ -55,3 +31,8 @@ private _wrapper;

renderJSONObject(src: string, options?: RenderOptions): Promise<GraphvizJSONOutput>;
/**
* Terminates the worker, clearing all on-going work.
*/
terminateWorker(): Promise<number> | void;
}
export default Viz;
export { RenderOptions, GraphvizJSONOutput };
{
"name": "@aduh95/viz.js",
"version": "3.0.0-beta.6",
"version": "3.0.0-beta.7",
"description": "A hack to put Graphviz on the web.",

@@ -14,2 +14,3 @@ "main": "./dist/index.cjs",

},
"./sync": "./dist/renderSync.js",
"./wasm": "./dist/render.wasm",

@@ -35,2 +36,3 @@ "./worker": {

"dist/",
"sync/",
"wasm",

@@ -50,8 +52,14 @@ "worker"

"@types/node": "^13.5.3",
"@typescript-eslint/eslint-plugin": "^2.28.0",
"@typescript-eslint/parser": "^2.28.0",
"eslint": "next",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.3",
"mocha": "^7.0.0",
"puppeteer": "^2.0.0",
"rollup": "^1.31.0",
"prettier": "^2.0.4",
"puppeteer": "^3.0.0",
"rollup": "^2.4.0",
"terser": "^4.6.3",
"typescript": "^3.8.0-beta"
"typescript": "^3.9.0-beta"
}
}
}
# Viz.js
[![Build Status](https://travis-ci.org/mdaines/viz.js.svg?branch=master)](https://travis-ci.org/mdaines/viz.js)
[![CI](https://github.com/aduh95/viz.js/workflows/CI/badge.svg)](https://github.com/aduh95/viz.js/actions)

@@ -26,6 +26,6 @@ This project builds [Graphviz](http://www.graphviz.org) with

.renderString("digraph{1 -> 2 }")
.then(svgString => {
.then((svgString) => {
console.log(svgString);
})
.catch(error => {
.catch((error) => {
console.error(error);

@@ -44,4 +44,6 @@ })

async function dot2svg(dot, options = {}) {
const Viz = await import("@aduh95/viz.js").then(m => m.default);
const getWorker = await import("@aduh95/viz.js/worker").then(m => m.default);
const Viz = await import("@aduh95/viz.js").then((m) => m.default);
const getWorker = await import("@aduh95/viz.js/worker").then(
(m) => m.default
);

@@ -55,2 +57,25 @@ const worker = getWorker();

#### Synchronous API
There is a synchronous version of `renderString` method available:
```js
const vizRenderStringSync = require("@aduh95/viz.js/sync");
console.log(vizRenderStringSync("digraph{1 -> 2 }"));
```
Key differences with async API:
- It compiles Graphviz to JavaScript instead of `WebAssembly`, this should come
with a performance hit and a bigger bundled file size (brotli size is 27%
bigger).
- It is a CommonJS module, while the rest of the API is written as standard
ECMAScript modules. The upside is this syntax is supported on a wider Node.js
version array.
> Note: Using the sync API on the browser main thread is not recommended, it
> might degrade the overall user experience of the web page. It is strongly
> recommended to use web workers – with the sync or the async API.
### Browsers

@@ -111,20 +136,34 @@

const vizDistFolder = "https://unpkg.com/@aduh95/viz.js@3.0.0-beta.6/dist";
const workerURL = URL.createObjectURL(
new Blob(
[
`import init from "${vizDistFolder}/render.browser.js";`,
"init({",
"locateFile(fileName) {",
// allows the worker to resolve the wasm file URL
`return \`${vizDistFolder}/\${fileName}\`;`,
"}",
"});",
],
{ type: "application/javascript" }
)
);
const locateFile = (fileName) =>
"https://unpkg.com/@aduh95/viz.js@3.0.0-beta.6/dist/" + fileName;
const onmessage = async function (event) {
if (this.messageHandler === undefined) {
// Lazy loading actual handler
const { default: init, onmessage } = await import(
Module.locateFile("render.browser.js")
);
// Removing default MessageEvent handler
removeEventListener("message", onmessage);
await init(Module);
this.messageHandler = onmessage;
}
return this.messageHandler(event);
};
const vizOptions = {
workerURL: URL.createObjectURL(
new Blob(
[
"const Module = { locateFile:",
locateFile.toString(),
"};",
"onmessage=",
onmessage.toString(),
],
{ type: "application/javascript" }
)
),
};
async function dot2svg(dot, options) {
const viz = new Viz({ workerURL });
const viz = new Viz(vizOptions);

@@ -149,3 +188,3 @@ return viz.renderString(dot, options);

// locateFile is used by render module to locate WASM file.
locateFile: fileName => `${vizDistFolder}/${fileName}`,
locateFile: (fileName) => `${vizDistFolder}/${fileName}`,
};

@@ -164,8 +203,8 @@ this._messageHandler = import(Module.locateFile("render.browser.js")).then(

self.addEventListener("message", event => {
self.addEventListener("message", (event) => {
if (event.data.id) {
// handling event sent by viz.js
getVizMessageHandler()
.then(onmessage => onmessage(event))
.catch(error => {
.then((onmessage) => onmessage(event))
.catch((error) => {
// handle dynamic import error here

@@ -196,12 +235,16 @@ console.error(error);

To build from source, first
[install the Emscripten SDK](http://kripken.github.io/emscripten-site/docs/getting_started/index.html).
[install the Emscripten SDK](https://emscripten.org/docs/getting_started/index.html).
You'll also need [Node.js 13+](https://nodejs.org/) and
[Yarn 2+](https://yarnpkg.com).
[Deno](https://deno.land/) to run the tests.
On macOS:
Using Homebrew (macOS or GNU/Linux):
```shell
brew install yarn binaryen emscripten automake libtool pkg-config qt
brew install node automake libtool pkg-config
```
> Note: Emscripten version number is pinned in the Makefile. If you are willing
> to use a different version, you'd need to change the Makefile variable to
> match the version you are using.
You will certainly need to tweak config files to make sure your system knows

@@ -208,0 +251,0 @@ where it should find each binary.

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

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