@ts-graphviz/adapter 0.0.0-pr956-20240225073457
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/CHANGELOG.md +12 -0
- package/LICENSE +22 -0
- package/README.md +37 -0
- package/lib/browser.cjs +14 -0
- package/lib/browser.d.ts +12 -0
- package/lib/browser.js +9 -0
- package/lib/create-command-and-args.cjs +87 -0
- package/lib/create-command-and-args.d.ts +8 -0
- package/lib/create-command-and-args.js +83 -0
- package/lib/create-command-args.d.ts +18 -0
- package/lib/deno.d.ts +12 -0
- package/lib/deno.js +31 -0
- package/lib/node.cjs +55 -0
- package/lib/node.d.ts +6 -0
- package/lib/node.js +50 -0
- package/lib/to-file.node.d.ts +5 -0
- package/lib/to-stream.node.d.ts +6 -0
- package/lib/types.d.ts +127 -0
- package/package.json +56 -0
- package/src/browser.ts +19 -0
- package/src/create-command-and-args.test.ts +63 -0
- package/src/create-command-and-args.ts +14 -0
- package/src/create-command-args.test.ts +100 -0
- package/src/create-command-args.ts +90 -0
- package/src/deno.ts +49 -0
- package/src/node.ts +6 -0
- package/src/to-file.node.ts +16 -0
- package/src/to-stream.node.ts +50 -0
- package/src/types.ts +166 -0
- package/tsconfig.browser.json +13 -0
- package/tsconfig.deno.json +13 -0
- package/tsconfig.node.json +13 -0
- package/typedoc.json +4 -0
- package/types/deno.d.ts +20 -0
- package/vite.config.ts +39 -0
package/src/browser.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @ts-graphviz/adapter
|
|
3
|
+
*/
|
|
4
|
+
export type Options = any;
|
|
5
|
+
|
|
6
|
+
const ERROR_MESSAGE = 'This module cannot be run in a browser.';
|
|
7
|
+
/**
|
|
8
|
+
* Execute the Graphviz dot command and make a Stream of the results.
|
|
9
|
+
*/
|
|
10
|
+
export function toStream(dot: string, options?: Options): never {
|
|
11
|
+
throw new Error(ERROR_MESSAGE);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Execute the Graphviz dot command and output the results to a file.
|
|
16
|
+
*/
|
|
17
|
+
export function toFile(dot: string, path: string, options?: Options): never {
|
|
18
|
+
throw new Error(ERROR_MESSAGE);
|
|
19
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createCommandAndArgs } from './create-command-and-args.js';
|
|
3
|
+
import { Options } from './types.js';
|
|
4
|
+
|
|
5
|
+
describe('createCommandAndArgs', () => {
|
|
6
|
+
it('should return the correct command and args', () => {
|
|
7
|
+
const options: Options = {
|
|
8
|
+
dotCommand: 'mydot',
|
|
9
|
+
suppressWarnings: true,
|
|
10
|
+
format: 'svg',
|
|
11
|
+
attributes: {
|
|
12
|
+
graph: <any>{
|
|
13
|
+
a: 'foo',
|
|
14
|
+
b: 'bar',
|
|
15
|
+
},
|
|
16
|
+
node: <any>{
|
|
17
|
+
c: 'baz',
|
|
18
|
+
d: 'qux',
|
|
19
|
+
},
|
|
20
|
+
edge: <any>{
|
|
21
|
+
e: 'quux',
|
|
22
|
+
f: 'corge',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
library: ['lib1', 'lib2'],
|
|
26
|
+
y: true,
|
|
27
|
+
scale: 5,
|
|
28
|
+
layout: 'neato',
|
|
29
|
+
reduce: true,
|
|
30
|
+
noop: 3,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const [command, args] = createCommandAndArgs(options);
|
|
34
|
+
expect(command).toBe('mydot');
|
|
35
|
+
expect(args).toMatchInlineSnapshot(`
|
|
36
|
+
[
|
|
37
|
+
"-q",
|
|
38
|
+
"-Tsvg",
|
|
39
|
+
"-Ga=foo",
|
|
40
|
+
"-Gb=bar",
|
|
41
|
+
"-Nc=baz",
|
|
42
|
+
"-Nd=qux",
|
|
43
|
+
"-Ee=quux",
|
|
44
|
+
"-Ef=corge",
|
|
45
|
+
"-s5",
|
|
46
|
+
"-llib1",
|
|
47
|
+
"-llib2",
|
|
48
|
+
"-y",
|
|
49
|
+
"-Kneato",
|
|
50
|
+
"-x",
|
|
51
|
+
"-n3",
|
|
52
|
+
]
|
|
53
|
+
`);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should return user customized command', () => {
|
|
57
|
+
const options: Options = {
|
|
58
|
+
dotCommand: 'mydot',
|
|
59
|
+
};
|
|
60
|
+
const [command] = createCommandAndArgs(options);
|
|
61
|
+
expect(command).toBe('mydot');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCommandArgs } from './create-command-args.js';
|
|
2
|
+
import { Layout, Options } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* createCommandAndArgs creates a command and an array of arguments, based on the given {@link Options}.
|
|
6
|
+
*
|
|
7
|
+
* @param options Options to create the command and args from.
|
|
8
|
+
* @returns A tuple containing the command and an array of arguments.
|
|
9
|
+
*/
|
|
10
|
+
export function createCommandAndArgs<T extends Layout>(
|
|
11
|
+
options: Options<T>,
|
|
12
|
+
): [command: string, args: string[]] {
|
|
13
|
+
return [options.dotCommand ?? 'dot', Array.from(createCommandArgs(options))];
|
|
14
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createCommandArgs, escapeValue } from './create-command-args.js';
|
|
3
|
+
import { Options } from './types.js';
|
|
4
|
+
|
|
5
|
+
describe('createCommandArgs', () => {
|
|
6
|
+
it('should generate correct args for neato layout', () => {
|
|
7
|
+
const options: Options = {
|
|
8
|
+
suppressWarnings: true,
|
|
9
|
+
format: 'svg',
|
|
10
|
+
attributes: {
|
|
11
|
+
graph: <any>{
|
|
12
|
+
foo: 'bar',
|
|
13
|
+
},
|
|
14
|
+
node: <any>{
|
|
15
|
+
baz: 'qux',
|
|
16
|
+
},
|
|
17
|
+
edge: <any>{
|
|
18
|
+
quux: 'quuz',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
library: ['lib1', 'lib2'],
|
|
22
|
+
y: true,
|
|
23
|
+
scale: 1.5,
|
|
24
|
+
layout: 'neato',
|
|
25
|
+
reduce: true,
|
|
26
|
+
noop: 10,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
expect(Array.from(createCommandArgs(options))).toMatchInlineSnapshot(`
|
|
30
|
+
[
|
|
31
|
+
"-q",
|
|
32
|
+
"-Tsvg",
|
|
33
|
+
"-Gfoo=bar",
|
|
34
|
+
"-Nbaz=qux",
|
|
35
|
+
"-Equux=quuz",
|
|
36
|
+
"-s1.5",
|
|
37
|
+
"-llib1",
|
|
38
|
+
"-llib2",
|
|
39
|
+
"-y",
|
|
40
|
+
"-Kneato",
|
|
41
|
+
"-x",
|
|
42
|
+
"-n10",
|
|
43
|
+
]
|
|
44
|
+
`);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should generate correct args for fdp layout', () => {
|
|
48
|
+
const options: Options = {
|
|
49
|
+
suppressWarnings: false,
|
|
50
|
+
format: 'png',
|
|
51
|
+
attributes: {
|
|
52
|
+
graph: <any>{
|
|
53
|
+
foo: 'bar',
|
|
54
|
+
},
|
|
55
|
+
node: <any>{
|
|
56
|
+
baz: 'qux',
|
|
57
|
+
},
|
|
58
|
+
edge: <any>{
|
|
59
|
+
quux: 'quuz',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
library: ['lib1'],
|
|
63
|
+
y: false,
|
|
64
|
+
scale: 2,
|
|
65
|
+
layout: 'fdp',
|
|
66
|
+
grid: true,
|
|
67
|
+
oldAttractive: true,
|
|
68
|
+
iterations: 5,
|
|
69
|
+
unscaledFactor: 0.5,
|
|
70
|
+
overlapExpansionFactor: 10,
|
|
71
|
+
temperature: 3,
|
|
72
|
+
};
|
|
73
|
+
expect(Array.from(createCommandArgs(options))).toMatchInlineSnapshot(`
|
|
74
|
+
[
|
|
75
|
+
"-Tpng",
|
|
76
|
+
"-Gfoo=bar",
|
|
77
|
+
"-Nbaz=qux",
|
|
78
|
+
"-Equux=quuz",
|
|
79
|
+
"-s2",
|
|
80
|
+
"-llib1",
|
|
81
|
+
"-Kfdp",
|
|
82
|
+
"-LO",
|
|
83
|
+
"-Ln5",
|
|
84
|
+
"-LU0.5",
|
|
85
|
+
"-LC10",
|
|
86
|
+
"-LT3",
|
|
87
|
+
]
|
|
88
|
+
`);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('escapeValue', () => {
|
|
93
|
+
it('should escape values correctly', () => {
|
|
94
|
+
expect(escapeValue('foo bar')).toEqual('="foo bar"');
|
|
95
|
+
expect(escapeValue('foo')).toEqual('=foo');
|
|
96
|
+
expect(escapeValue(true)).toEqual('');
|
|
97
|
+
expect(escapeValue(false)).toEqual('=false');
|
|
98
|
+
expect(escapeValue(10)).toEqual('=10');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Attribute, AttributeKey } from '@ts-graphviz/common';
|
|
2
|
+
import { Layout, Options } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* escapeValue is a function that escapes a given Attribute value of a given AttributeKey.
|
|
6
|
+
* It checks the type of the value and adds quotes if the value is of type string and contains whitespace.
|
|
7
|
+
*
|
|
8
|
+
* @param value The value of an Attribute of type T that extends AttributeKey
|
|
9
|
+
* @returns The escaped Attribute value
|
|
10
|
+
*/
|
|
11
|
+
export function escapeValue<T extends AttributeKey>(value: Attribute<T>) {
|
|
12
|
+
if (value !== true) {
|
|
13
|
+
if (typeof value === 'string' && /\s/g.test(value)) {
|
|
14
|
+
return `="${value}"`;
|
|
15
|
+
}
|
|
16
|
+
return `=${value}`;
|
|
17
|
+
}
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* createCommandArgs is a function that creates command arguments from a given Options object.
|
|
23
|
+
* It reads the properties of the Options object and creates corresponding command line arguments accordingly.
|
|
24
|
+
*
|
|
25
|
+
* @param options The Options object used to create command arguments
|
|
26
|
+
* @returns A generator that yields strings for command arguments
|
|
27
|
+
*/
|
|
28
|
+
export function* createCommandArgs<T extends Layout>(
|
|
29
|
+
options: Options<T>,
|
|
30
|
+
): Generator<string> {
|
|
31
|
+
const {
|
|
32
|
+
suppressWarnings = true,
|
|
33
|
+
format = 'svg',
|
|
34
|
+
attributes = {},
|
|
35
|
+
library = [],
|
|
36
|
+
y = false,
|
|
37
|
+
scale,
|
|
38
|
+
} = options;
|
|
39
|
+
if (suppressWarnings) yield '-q';
|
|
40
|
+
yield `-T${format}`;
|
|
41
|
+
if (attributes.graph) {
|
|
42
|
+
for (const [key, value] of Object.entries(attributes.graph)) {
|
|
43
|
+
yield `-G${key}${escapeValue(value)}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (attributes.node) {
|
|
47
|
+
for (const [key, value] of Object.entries(attributes.node)) {
|
|
48
|
+
yield `-N${key}${escapeValue(value)}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (attributes.edge) {
|
|
52
|
+
for (const [key, value] of Object.entries(attributes.edge)) {
|
|
53
|
+
yield `-E${key}${escapeValue(value)}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (typeof scale === 'number' && !Number.isNaN(scale)) yield `-s${scale}`;
|
|
57
|
+
if (Array.isArray(library)) for (const lib of library) yield `-l${lib}`;
|
|
58
|
+
if (y === true) yield '-y';
|
|
59
|
+
|
|
60
|
+
if (typeof options.layout === 'string') {
|
|
61
|
+
yield `-K${options.layout}`;
|
|
62
|
+
switch (options.layout) {
|
|
63
|
+
case 'neato': {
|
|
64
|
+
const { reduce, noop } = options;
|
|
65
|
+
if (reduce === true) yield '-x';
|
|
66
|
+
if (typeof noop === 'number') yield `-n${noop}`;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case 'fdp': {
|
|
70
|
+
const {
|
|
71
|
+
grid,
|
|
72
|
+
oldAttractive,
|
|
73
|
+
iterations,
|
|
74
|
+
unscaledFactor,
|
|
75
|
+
overlapExpansionFactor,
|
|
76
|
+
temperature,
|
|
77
|
+
} = options;
|
|
78
|
+
yield ['-L', grid ? '' : 'g', oldAttractive ? 'O' : ''].join('');
|
|
79
|
+
if (typeof iterations === 'number') yield `-Ln${iterations}`;
|
|
80
|
+
if (typeof unscaledFactor === 'number') yield `-LU${unscaledFactor}`;
|
|
81
|
+
if (typeof overlapExpansionFactor === 'number')
|
|
82
|
+
yield `-LC${overlapExpansionFactor}`;
|
|
83
|
+
if (typeof temperature === 'number') yield `-LT${temperature}`;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
default:
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/deno.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createCommandAndArgs } from './create-command-and-args.js';
|
|
2
|
+
/**
|
|
3
|
+
* @module @ts-graphviz/adapter
|
|
4
|
+
*/
|
|
5
|
+
/// <reference types="../types/deno.d.ts" />
|
|
6
|
+
import { Layout, Options } from './types.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Execute the Graphviz dot command and make a Stream of the results.
|
|
10
|
+
*/
|
|
11
|
+
export async function toStream<T extends Layout>(
|
|
12
|
+
dot: string,
|
|
13
|
+
options?: Options<T>,
|
|
14
|
+
): Promise<ReadableStream<Uint8Array>> {
|
|
15
|
+
const [command, args] = createCommandAndArgs(options ?? {});
|
|
16
|
+
const cp = new Deno.Command(command, {
|
|
17
|
+
args: args,
|
|
18
|
+
stdin: 'piped',
|
|
19
|
+
stdout: 'piped',
|
|
20
|
+
}).spawn();
|
|
21
|
+
const stdin = cp.stdin.getWriter();
|
|
22
|
+
await stdin.write(new TextEncoder().encode(dot));
|
|
23
|
+
await stdin.close();
|
|
24
|
+
return cp.stdout;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function open(path: string) {
|
|
28
|
+
try {
|
|
29
|
+
return Deno.open(path, { write: true });
|
|
30
|
+
} catch (e) {
|
|
31
|
+
if (e instanceof Deno.errors.NotFound) {
|
|
32
|
+
return Deno.open(path, { createNew: true, write: true });
|
|
33
|
+
}
|
|
34
|
+
throw e;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Execute the Graphviz dot command and output the results to a file.
|
|
40
|
+
*/
|
|
41
|
+
export async function toFile<T extends Layout>(
|
|
42
|
+
dot: string,
|
|
43
|
+
path: string,
|
|
44
|
+
options?: Options<T>,
|
|
45
|
+
): Promise<void> {
|
|
46
|
+
const output = await open(path);
|
|
47
|
+
const stream = await toStream(dot, options);
|
|
48
|
+
await stream.pipeTo(output.writable);
|
|
49
|
+
}
|
package/src/node.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createWriteStream } from 'node:fs';
|
|
2
|
+
import { pipeline } from 'node:stream/promises';
|
|
3
|
+
import { toStream } from './to-stream.node.js';
|
|
4
|
+
import { Layout, Options } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Execute the Graphviz dot command and output the results to a file.
|
|
8
|
+
*/
|
|
9
|
+
export async function toFile<T extends Layout>(
|
|
10
|
+
dot: string,
|
|
11
|
+
path: string,
|
|
12
|
+
options?: Options<T>,
|
|
13
|
+
): Promise<void> {
|
|
14
|
+
const stream = await toStream(dot, options);
|
|
15
|
+
await pipeline(stream, createWriteStream(path));
|
|
16
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { PassThrough, Readable } from 'node:stream';
|
|
3
|
+
import { pipeline } from 'node:stream/promises';
|
|
4
|
+
import { createCommandAndArgs } from './create-command-and-args.js';
|
|
5
|
+
import { Layout, Options } from './types.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Execute the Graphviz dot command and make a Stream of the results.
|
|
9
|
+
*/
|
|
10
|
+
export async function toStream<T extends Layout>(
|
|
11
|
+
dot: string,
|
|
12
|
+
options?: Options<T>,
|
|
13
|
+
): Promise<NodeJS.ReadableStream> {
|
|
14
|
+
const [command, args] = createCommandAndArgs(options ?? {});
|
|
15
|
+
return new Promise(function toStreamInternal(resolve, reject) {
|
|
16
|
+
const p = spawn(command, args, { stdio: 'pipe' });
|
|
17
|
+
|
|
18
|
+
// error handling
|
|
19
|
+
p.on('error', (e) => {
|
|
20
|
+
reject(
|
|
21
|
+
new Error(`Command "${command}" failed.\nMESSAGE:${e.message}`, {
|
|
22
|
+
cause: e,
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const stderrChunks: Uint8Array[] = [];
|
|
28
|
+
p.stdout.on('pause', () => p.stdout.resume());
|
|
29
|
+
p.stderr.on('data', (chunk) => stderrChunks.push(chunk));
|
|
30
|
+
p.stderr.on('pause', () => p.stderr.resume());
|
|
31
|
+
|
|
32
|
+
const dist = p.stdout.pipe(new PassThrough());
|
|
33
|
+
p.on('close', async (code, signal) => {
|
|
34
|
+
if (code === 0) {
|
|
35
|
+
resolve(dist);
|
|
36
|
+
} else {
|
|
37
|
+
const message = Buffer.concat(
|
|
38
|
+
stderrChunks as ReadonlyArray<Uint8Array>,
|
|
39
|
+
).toString();
|
|
40
|
+
reject(
|
|
41
|
+
new Error(
|
|
42
|
+
`Command "${command}" failed.\nCODE: ${code}\nSIGNAL: ${signal}\nMESSAGE: ${message}`,
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
pipeline(Readable.from([dot]), p.stdin);
|
|
49
|
+
});
|
|
50
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import {
|
|
2
|
+
$keywords,
|
|
3
|
+
$keywordsValidation,
|
|
4
|
+
EdgeAttributesObject,
|
|
5
|
+
GraphAttributesObject,
|
|
6
|
+
NodeAttributesObject,
|
|
7
|
+
SubgraphAttributesObject,
|
|
8
|
+
} from '@ts-graphviz/common';
|
|
9
|
+
|
|
10
|
+
export type Format = Format.values;
|
|
11
|
+
export namespace Format {
|
|
12
|
+
export type values = Exclude<keyof $values, keyof $exclude | symbol | number>;
|
|
13
|
+
export interface $values
|
|
14
|
+
extends $keywords<
|
|
15
|
+
| 'png'
|
|
16
|
+
| 'svg'
|
|
17
|
+
| 'json'
|
|
18
|
+
| 'jpg'
|
|
19
|
+
| 'pdf'
|
|
20
|
+
| 'xdot'
|
|
21
|
+
| 'dot'
|
|
22
|
+
| 'plain'
|
|
23
|
+
| 'dot_json'
|
|
24
|
+
> {}
|
|
25
|
+
export interface $exclude extends $keywordsValidation {}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type Layout = Layout.values;
|
|
29
|
+
export namespace Layout {
|
|
30
|
+
export type values = Exclude<keyof $values, keyof $exclude | symbol | number>;
|
|
31
|
+
export interface $values
|
|
32
|
+
extends $keywords<
|
|
33
|
+
| 'dot'
|
|
34
|
+
| 'neato'
|
|
35
|
+
| 'fdp'
|
|
36
|
+
| 'sfdp'
|
|
37
|
+
| 'circo'
|
|
38
|
+
| 'twopi'
|
|
39
|
+
| 'nop'
|
|
40
|
+
| 'nop2'
|
|
41
|
+
| 'osage'
|
|
42
|
+
| 'patchwork'
|
|
43
|
+
> {}
|
|
44
|
+
export interface $exclude extends $keywordsValidation {}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* NeatoOptions interface provides options for the neato layout.
|
|
49
|
+
*/
|
|
50
|
+
export interface NeatoOptions {
|
|
51
|
+
layout: 'neato';
|
|
52
|
+
/**
|
|
53
|
+
* Sets no-op flag in neato.
|
|
54
|
+
*/
|
|
55
|
+
noop?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Reduce graph.
|
|
58
|
+
*/
|
|
59
|
+
reduce?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* FdpOptions interface provides options for the fdp layout.
|
|
64
|
+
*/
|
|
65
|
+
export interface FdpOptions {
|
|
66
|
+
layout: 'fdp';
|
|
67
|
+
/**
|
|
68
|
+
* Use grid.
|
|
69
|
+
*
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
72
|
+
grid?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Use old attractive force
|
|
75
|
+
*
|
|
76
|
+
* @default true
|
|
77
|
+
*/
|
|
78
|
+
oldAttractive?: boolean;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Set number of iterations.
|
|
82
|
+
*/
|
|
83
|
+
iterations?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Set unscaled factor
|
|
86
|
+
*/
|
|
87
|
+
unscaledFactor?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Set overlap expansion factor.
|
|
90
|
+
*/
|
|
91
|
+
overlapExpansionFactor?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Set temperature.
|
|
94
|
+
*/
|
|
95
|
+
temperature?: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @description
|
|
100
|
+
* This interface describes an optional parameter called "layout" which is used to set a layout engine.
|
|
101
|
+
* The default value for this parameter is 'dot', and it must be an option of the Layout type,
|
|
102
|
+
* excluding 'neato' and 'fdp'.
|
|
103
|
+
*/
|
|
104
|
+
export interface OtherOptions {
|
|
105
|
+
/**
|
|
106
|
+
* Set layout engine.
|
|
107
|
+
*
|
|
108
|
+
* @default 'dot'
|
|
109
|
+
*/
|
|
110
|
+
layout?: Exclude<Layout, 'neato' | 'fdp'>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* This interface represents the CommonOptions for setting output format.
|
|
115
|
+
*/
|
|
116
|
+
export interface CommonOptions {
|
|
117
|
+
/**
|
|
118
|
+
* Set output format.
|
|
119
|
+
*
|
|
120
|
+
* @default 'svg'
|
|
121
|
+
*/
|
|
122
|
+
format?: Format;
|
|
123
|
+
/**
|
|
124
|
+
* If true, set level of message suppression (=1).
|
|
125
|
+
*
|
|
126
|
+
* @default true
|
|
127
|
+
*/
|
|
128
|
+
suppressWarnings?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Path of graphviz dot command.
|
|
131
|
+
*/
|
|
132
|
+
dotCommand?: string;
|
|
133
|
+
attributes?: {
|
|
134
|
+
/**
|
|
135
|
+
* Set edge attribute.
|
|
136
|
+
*/
|
|
137
|
+
edge?: EdgeAttributesObject;
|
|
138
|
+
/**
|
|
139
|
+
* Set node attribute.
|
|
140
|
+
*/
|
|
141
|
+
node?: NodeAttributesObject;
|
|
142
|
+
/**
|
|
143
|
+
* Set graph attribute.
|
|
144
|
+
*/
|
|
145
|
+
graph?: GraphAttributesObject & SubgraphAttributesObject;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Scale input
|
|
149
|
+
*/
|
|
150
|
+
scale?: number;
|
|
151
|
+
/**
|
|
152
|
+
* Use external library.
|
|
153
|
+
*/
|
|
154
|
+
library?: string[];
|
|
155
|
+
/**
|
|
156
|
+
* Invert y coordinate in output.
|
|
157
|
+
*/
|
|
158
|
+
y?: boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export type Options<T extends Layout = Layout> = CommonOptions &
|
|
162
|
+
(T extends 'neato'
|
|
163
|
+
? NeatoOptions
|
|
164
|
+
: T extends 'fdp'
|
|
165
|
+
? FdpOptions
|
|
166
|
+
: OtherOptions);
|
package/typedoc.json
ADDED
package/types/deno.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare global {
|
|
2
|
+
declare namespace Deno {
|
|
3
|
+
// biome-ignore lint/style/noVar: <explanation>
|
|
4
|
+
declare var open: typeof import('@deno/shim-deno').Deno.open;
|
|
5
|
+
// biome-ignore lint/style/noVar: <explanation>
|
|
6
|
+
declare var errors: typeof import('@deno/shim-deno').Deno.errors;
|
|
7
|
+
|
|
8
|
+
declare class Command {
|
|
9
|
+
constructor(
|
|
10
|
+
command: string,
|
|
11
|
+
options: {
|
|
12
|
+
args: string[];
|
|
13
|
+
stdin: 'piped';
|
|
14
|
+
stdout: 'piped';
|
|
15
|
+
},
|
|
16
|
+
);
|
|
17
|
+
spawn(): Deno.Process;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import dts from 'vite-plugin-dts';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
build: {
|
|
6
|
+
target: 'esnext',
|
|
7
|
+
outDir: './lib',
|
|
8
|
+
minify: false,
|
|
9
|
+
lib: {
|
|
10
|
+
entry: {
|
|
11
|
+
'create-command-and-args': './src/create-command-and-args.ts',
|
|
12
|
+
deno: './src/deno.ts',
|
|
13
|
+
browser: './src/browser.ts',
|
|
14
|
+
node: './src/node.ts',
|
|
15
|
+
},
|
|
16
|
+
formats: ['es', 'cjs'],
|
|
17
|
+
},
|
|
18
|
+
rollupOptions: {
|
|
19
|
+
external: [
|
|
20
|
+
'@ts-graphviz/common',
|
|
21
|
+
'node:stream',
|
|
22
|
+
'node:stream/promises',
|
|
23
|
+
'node:child_process',
|
|
24
|
+
'node:fs',
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
plugins: [
|
|
29
|
+
dts({
|
|
30
|
+
tsconfigPath: './tsconfig.browser.json',
|
|
31
|
+
}),
|
|
32
|
+
dts({
|
|
33
|
+
tsconfigPath: './tsconfig.node.json',
|
|
34
|
+
}),
|
|
35
|
+
dts({
|
|
36
|
+
tsconfigPath: './tsconfig.deno.json',
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
});
|