@hpcc-js/wasm-graphviz 1.17.0 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpcc-js/wasm-graphviz",
3
- "version": "1.17.0",
3
+ "version": "1.18.1",
4
4
  "description": "hpcc-js - WASM Graphviz",
5
5
  "type": "module",
6
6
  "exports": {
@@ -26,7 +26,7 @@
26
26
  "build-dev": "run-p gen-types bundle-dev",
27
27
  "build": "run-p gen-types bundle",
28
28
  "lint-skypack": "npx -y @skypack/package-check",
29
- "lint-eslint": "eslint src/**/*.ts tests/**/*.ts",
29
+ "lint-eslint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\"",
30
30
  "lint": "run-p lint-eslint",
31
31
  "test-browser": "vitest run --project browser",
32
32
  "test-node": "vitest run --project node",
@@ -36,7 +36,8 @@
36
36
  "update-major": "npx -y npm-check-updates -u"
37
37
  },
38
38
  "devDependencies": {
39
- "@hpcc-js/esbuild-plugins": "1.7.0"
39
+ "@hpcc-js/esbuild-plugins": "1.7.0",
40
+ "@hpcc-js/wasm-util": "1.0.0"
40
41
  },
41
42
  "keywords": [
42
43
  "graphviz",
@@ -54,5 +55,5 @@
54
55
  },
55
56
  "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
56
57
  "license": "Apache-2.0",
57
- "gitHead": "39b68e046380ff41bd6474242929cd68a6918fef"
58
+ "gitHead": "11395f5acfc865accde71905509bb45d5c79b11b"
58
59
  }
package/src/graphviz.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // @ts-expect-error importing from a wasm file is resolved via a custom esbuild plugin
2
- import load, { reset } from "../../../build/packages/graphviz/src-cpp/graphvizlib.wasm";
2
+ import load, { reset } from "../../../build/packages/graphviz/graphvizlib.wasm";
3
+ import type { MainModule } from "../types/graphvizlib.js";
4
+ import { MainModuleEx } from "@hpcc-js/wasm-util";
3
5
 
4
6
  /**
5
7
  * Various graphic and data formats for end user, web, documents and other applications. See [Output Formats](https://graphviz.gitlab.io/docs/outputs/) for more information.
@@ -70,6 +72,8 @@ function createFiles(graphviz: any, _options?: Options) {
70
72
  [...options.files, ...imagesToFiles(options.images)].forEach(file => graphviz.createFile(file.path, file.data));
71
73
  }
72
74
 
75
+ let g_graphviz: Promise<Graphviz>;
76
+
73
77
  /**
74
78
  * The Graphviz layout algorithms take descriptions of graphs in a simple text language, and make diagrams in useful formats, such as images and SVG for web pages or display in an interactive graph browser.
75
79
  *
@@ -90,9 +94,10 @@ function createFiles(graphviz: any, _options?: Options) {
90
94
  * * https://raw.githack.com/hpcc-systems/hpcc-js-wasm/trunk/index.html
91
95
  * * https://observablehq.com/@gordonsmith/graphviz
92
96
  */
93
- export class Graphviz {
97
+ export class Graphviz extends MainModuleEx<MainModule> {
94
98
 
95
- private constructor(protected _module: any) {
99
+ private constructor(_module: MainModule) {
100
+ super(_module);
96
101
  }
97
102
 
98
103
  /**
@@ -105,9 +110,10 @@ export class Graphviz {
105
110
  * @returns A promise to an instance of the Graphviz class.
106
111
  */
107
112
  static load(): Promise<Graphviz> {
108
- return load().then((module: any) => {
109
- return new Graphviz(module);
110
- });
113
+ if (!g_graphviz) {
114
+ g_graphviz = (load() as Promise<MainModule>).then((module) => new Graphviz(module));
115
+ }
116
+ return g_graphviz;
111
117
  }
112
118
 
113
119
  /**
@@ -121,7 +127,7 @@ export class Graphviz {
121
127
  * @returns The Graphviz c++ version
122
128
  */
123
129
  version(): string {
124
- return this._module.Graphviz.prototype.version();
130
+ return this._module.CGraphviz.version();
125
131
  }
126
132
 
127
133
  /**
@@ -135,7 +141,7 @@ export class Graphviz {
135
141
  */
136
142
  layout(dotSource: string, outputFormat: Format = "svg", layoutEngine: Engine = "dot", options?: Options): string {
137
143
  if (!dotSource) return "";
138
- const graphViz = new this._module.Graphviz(options?.yInvert ? 1 : 0, options?.nop ? options?.nop : 0);
144
+ const graphViz = new this._module.CGraphviz(options?.yInvert ? 1 : 0, options?.nop ? options?.nop : 0);
139
145
  let retVal = "";
140
146
  let errorMsg = "";
141
147
  try {
@@ -145,9 +151,9 @@ export class Graphviz {
145
151
  } catch (e: any) {
146
152
  errorMsg = e.message;
147
153
  };
148
- errorMsg = graphViz.lastError() || errorMsg;
154
+ errorMsg = this._module.CGraphviz.lastError() || errorMsg;
149
155
  } finally {
150
- this._module.destroy(graphViz);
156
+ graphViz.delete();
151
157
  }
152
158
  if (!retVal && errorMsg) {
153
159
  Graphviz.unload();
@@ -166,7 +172,7 @@ export class Graphviz {
166
172
  */
167
173
  acyclic(dotSource: string, doWrite: boolean = false, verbose: boolean = false): { acyclic: boolean, num_rev: number, outFile: string } {
168
174
  if (!dotSource) return { acyclic: false, num_rev: 0, outFile: "" };
169
- const graphViz = new this._module.Graphviz();
175
+ const graphViz = new this._module.CGraphviz();
170
176
  let acyclic: boolean = false;
171
177
  let num_rev: number = 0;
172
178
  let outFile: string = "";
@@ -179,9 +185,9 @@ export class Graphviz {
179
185
  } catch (e: any) {
180
186
  errorMsg = e.message;
181
187
  };
182
- errorMsg = graphViz.lastError() || errorMsg;
188
+ errorMsg = this._module.CGraphviz.lastError() || errorMsg;
183
189
  } finally {
184
- this._module.destroy(graphViz);
190
+ graphViz.delete();
185
191
  }
186
192
  if (errorMsg) {
187
193
  Graphviz.unload();
@@ -200,7 +206,7 @@ export class Graphviz {
200
206
  */
201
207
  tred(dotSource: string, verbose: boolean = false, printRemovedEdges: boolean = false): { out: string, err: string } {
202
208
  if (!dotSource) return { out: "", err: "" };
203
- const graphViz = new this._module.Graphviz();
209
+ const graphViz = new this._module.CGraphviz();
204
210
  let out: string = "";
205
211
  let err: string = "";
206
212
  let errorMsg = "";
@@ -212,9 +218,9 @@ export class Graphviz {
212
218
  } catch (e: any) {
213
219
  errorMsg = e.message;
214
220
  };
215
- errorMsg = graphViz.lastError() || errorMsg;
221
+ errorMsg = this._module.CGraphviz.lastError() || errorMsg;
216
222
  } finally {
217
- this._module.destroy(graphViz);
223
+ graphViz.delete();
218
224
  }
219
225
  if (!out && errorMsg) {
220
226
  Graphviz.unload();
@@ -234,7 +240,7 @@ export class Graphviz {
234
240
  */
235
241
  unflatten(dotSource: string, maxMinlen: number = 0, do_fans: boolean = false, chainLimit: number = 0): string {
236
242
  if (!dotSource) return "";
237
- const graphViz = new this._module.Graphviz();
243
+ const graphViz = new this._module.CGraphviz();
238
244
  let retVal = "";
239
245
  let errorMsg = "";
240
246
  try {
@@ -243,9 +249,9 @@ export class Graphviz {
243
249
  } catch (e: any) {
244
250
  errorMsg = e.message;
245
251
  };
246
- errorMsg = graphViz.lastError() || errorMsg;
252
+ errorMsg = this._module.CGraphviz.lastError() || errorMsg;
247
253
  } finally {
248
- this._module.destroy(graphViz);
254
+ graphViz.delete();
249
255
  }
250
256
  if (!retVal && errorMsg) {
251
257
  Graphviz.unload();
@@ -1,3 +1,5 @@
1
+ import type { MainModule } from "../types/graphvizlib.js";
2
+ import { MainModuleEx } from "@hpcc-js/wasm-util";
1
3
  /**
2
4
  * Various graphic and data formats for end user, web, documents and other applications. See [Output Formats](https://graphviz.gitlab.io/docs/outputs/) for more information.
3
5
  */
@@ -60,8 +62,7 @@ export interface Options {
60
62
  * * https://raw.githack.com/hpcc-systems/hpcc-js-wasm/trunk/index.html
61
63
  * * https://observablehq.com/@gordonsmith/graphviz
62
64
  */
63
- export declare class Graphviz {
64
- protected _module: any;
65
+ export declare class Graphviz extends MainModuleEx<MainModule> {
65
66
  private constructor();
66
67
  /**
67
68
  * Compiles and instantiates the raw wasm.
@@ -0,0 +1,65 @@
1
+ // TypeScript bindings for emscripten-generated code. Automatically generated at compile time.
2
+ declare namespace RuntimeExports {
3
+ /**
4
+ * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
5
+ * emscripten HEAP, returns a copy of that string as a Javascript String object.
6
+ *
7
+ * @param {number} ptr
8
+ * @param {number=} maxBytesToRead - An optional length that specifies the
9
+ * maximum number of bytes to read. You can omit this parameter to scan the
10
+ * string until the first 0 byte. If maxBytesToRead is passed, and the string
11
+ * at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
12
+ * string will cut short at that byte index.
13
+ * @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.
14
+ * @return {string}
15
+ */
16
+ function UTF8ToString(ptr: number, maxBytesToRead?: number | undefined, ignoreNul?: boolean | undefined): string;
17
+ function lengthBytesUTF8(str: any): number;
18
+ function stringToUTF8(str: any, outPtr: any, maxBytesToWrite: any): any;
19
+ let HEAPU8: any;
20
+ }
21
+ interface WasmModule {
22
+ _malloc(_0: number): number;
23
+ _free(_0: number): void;
24
+ }
25
+
26
+ type EmbindString = ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string;
27
+ export interface ClassHandle {
28
+ isAliasOf(other: ClassHandle): boolean;
29
+ delete(): void;
30
+ deleteLater(): this;
31
+ isDeleted(): boolean;
32
+ // @ts-ignore - If targeting lower than ESNext, this symbol might not exist.
33
+ [Symbol.dispose](): void;
34
+ clone(): this;
35
+ }
36
+ export interface CGraphviz extends ClassHandle {
37
+ acyclic_num_rev: number;
38
+ get layout_result(): string;
39
+ set layout_result(value: EmbindString);
40
+ get acyclic_outFile(): string;
41
+ set acyclic_outFile(value: EmbindString);
42
+ get tred_out(): string;
43
+ set tred_out(value: EmbindString);
44
+ get tred_err(): string;
45
+ set tred_err(value: EmbindString);
46
+ get unflatten_out(): string;
47
+ set unflatten_out(value: EmbindString);
48
+ createFile(_0: EmbindString, _1: EmbindString): void;
49
+ layout(_0: EmbindString, _1: EmbindString, _2: EmbindString): string;
50
+ acyclic(_0: EmbindString, _1: boolean, _2: boolean): boolean;
51
+ tred(_0: EmbindString, _1: boolean, _2: boolean): void;
52
+ unflatten(_0: EmbindString, _1: number, _2: boolean, _3: number): string;
53
+ }
54
+
55
+ interface EmbindModule {
56
+ CGraphviz: {
57
+ new(): CGraphviz;
58
+ new(_0: number, _1: number): CGraphviz;
59
+ version(): string;
60
+ lastError(): string;
61
+ };
62
+ }
63
+
64
+ export type MainModule = WasmModule & typeof RuntimeExports & EmbindModule;
65
+ export default function MainModuleFactory (options?: unknown): Promise<MainModule>;