ts-graphviz 1.2.1 → 1.2.2-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/lib/ast/index.cjs +23 -23
- package/lib/ast/index.d.ts +1 -1
- package/lib/ast/index.js +2 -2
- package/lib/common/index.cjs +1 -1
- package/lib/common/index.js +1 -1
- package/lib/core/index.cjs +22 -20
- package/lib/core/index.d.ts +2 -2
- package/lib/core/index.js +2 -2
- package/lib/index.cjs +6 -6
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/package.json +1 -1
- package/test/utils/to-dot.ts +1 -1
package/lib/ast/index.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var index_js = require('../utils/index.js');
|
|
6
|
+
var index_js$1 = require('../common/index.js');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @group Create AST
|
|
@@ -49,7 +49,7 @@ function leftPadWith(left) {
|
|
|
49
49
|
const escape = (value) => value.replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/"/g, '\\"');
|
|
50
50
|
const splitByLine = (value) => value.split(EOL);
|
|
51
51
|
const indent = (style, size, eol) =>
|
|
52
|
-
|
|
52
|
+
index_js.pipe(splitByLine, index_js.map(leftPadWith(style === 'space' ? ' '.repeat(size) : '\n')), joinBy(eol));
|
|
53
53
|
const endOfLine = (eol) => {
|
|
54
54
|
switch (eol) {
|
|
55
55
|
case 'crlf':
|
|
@@ -68,8 +68,8 @@ const AttributeListPrintPlugin = {
|
|
|
68
68
|
return `${ast.kind.toLocaleLowerCase()} [];`;
|
|
69
69
|
}
|
|
70
70
|
const eol = endOfLine(context.endOfLine);
|
|
71
|
-
return
|
|
72
|
-
|
|
71
|
+
return index_js.pipe(
|
|
72
|
+
index_js.map(context.print),
|
|
73
73
|
joinBy(eol),
|
|
74
74
|
indent(context.indentStyle, context.indentSize, eol),
|
|
75
75
|
wrapByPair(`${ast.kind.toLocaleLowerCase()} [${eol}`, `${eol}];`),
|
|
@@ -94,17 +94,17 @@ const CommentPrintPlugin = {
|
|
|
94
94
|
const eol = endOfLine(context.endOfLine);
|
|
95
95
|
switch (ast.kind) {
|
|
96
96
|
case 'Block':
|
|
97
|
-
return
|
|
97
|
+
return index_js.pipe(
|
|
98
98
|
splitByLine,
|
|
99
|
-
|
|
99
|
+
index_js.map(leftPadWith(' * ')),
|
|
100
100
|
joinBy(eol),
|
|
101
101
|
wrapByPair(`/**${eol}`, `${eol} */`),
|
|
102
102
|
)(ast.value);
|
|
103
103
|
case 'Macro':
|
|
104
|
-
return
|
|
104
|
+
return index_js.pipe(splitByLine, index_js.map(leftPadWith('# ')), joinBy(eol))(ast.value);
|
|
105
105
|
case 'Slash':
|
|
106
106
|
default:
|
|
107
|
-
return
|
|
107
|
+
return index_js.pipe(splitByLine, index_js.map(leftPadWith('// ')), joinBy(eol))(ast.value);
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
110
|
};
|
|
@@ -123,13 +123,13 @@ const EdgePrintPlugin = {
|
|
|
123
123
|
return ast.type === 'Edge';
|
|
124
124
|
},
|
|
125
125
|
print(context, ast) {
|
|
126
|
-
const targets =
|
|
126
|
+
const targets = index_js.pipe(index_js.map(context.print), joinBy(context.directed ? ' -> ' : ' -- '))(ast.targets);
|
|
127
127
|
if (ast.children.length === 0) {
|
|
128
128
|
return `${targets};`;
|
|
129
129
|
}
|
|
130
130
|
const eol = endOfLine(context.endOfLine);
|
|
131
|
-
const contents =
|
|
132
|
-
|
|
131
|
+
const contents = index_js.pipe(
|
|
132
|
+
index_js.map(context.print),
|
|
133
133
|
joinBy(eol),
|
|
134
134
|
indent(context.indentStyle, context.indentSize, eol),
|
|
135
135
|
wrapByPair(`[${eol}`, `${eol}];`),
|
|
@@ -156,8 +156,8 @@ const GraphPrintPlugin = {
|
|
|
156
156
|
return `${parts.join(' ')} {}`;
|
|
157
157
|
}
|
|
158
158
|
const eol = endOfLine(context.endOfLine);
|
|
159
|
-
const contents =
|
|
160
|
-
|
|
159
|
+
const contents = index_js.pipe(
|
|
160
|
+
index_js.map(context.print),
|
|
161
161
|
joinBy(eol),
|
|
162
162
|
indent(context.indentStyle, context.indentSize, eol),
|
|
163
163
|
wrapByPair(`{${eol}`, `${eol}}`),
|
|
@@ -166,7 +166,7 @@ const GraphPrintPlugin = {
|
|
|
166
166
|
},
|
|
167
167
|
};
|
|
168
168
|
|
|
169
|
-
const quoteLiteralValue =
|
|
169
|
+
const quoteLiteralValue = index_js.pipe(escape, wrapWith('"'));
|
|
170
170
|
const quoteHTMLLikeLiteralValue = wrapByPair('<', '>');
|
|
171
171
|
const LiteralPrintPlugin = {
|
|
172
172
|
match(ast) {
|
|
@@ -195,8 +195,8 @@ const NodePrintPlugin = {
|
|
|
195
195
|
return `${id};`;
|
|
196
196
|
}
|
|
197
197
|
const eol = endOfLine(context.endOfLine);
|
|
198
|
-
const contents =
|
|
199
|
-
|
|
198
|
+
const contents = index_js.pipe(
|
|
199
|
+
index_js.map(context.print),
|
|
200
200
|
joinBy(eol),
|
|
201
201
|
indent(context.indentStyle, context.indentSize, eol),
|
|
202
202
|
wrapByPair(`[${eol}`, `${eol}];`),
|
|
@@ -210,7 +210,7 @@ const NodeRefGroupPrintPlugin = {
|
|
|
210
210
|
return ast.type === 'NodeRefGroup';
|
|
211
211
|
},
|
|
212
212
|
print(context, ast) {
|
|
213
|
-
return
|
|
213
|
+
return index_js.pipe(index_js.map(context.print), joinBy(' '), wrapByPair('{', '}'))(ast.children);
|
|
214
214
|
},
|
|
215
215
|
};
|
|
216
216
|
|
|
@@ -243,8 +243,8 @@ const SubgraphPrintPlugin = {
|
|
|
243
243
|
return `${parts.join(' ')} {}`;
|
|
244
244
|
}
|
|
245
245
|
const eol = endOfLine(context.endOfLine);
|
|
246
|
-
const contents =
|
|
247
|
-
|
|
246
|
+
const contents = index_js.pipe(
|
|
247
|
+
index_js.map(context.print),
|
|
248
248
|
joinBy(eol),
|
|
249
249
|
indent(context.indentStyle, context.indentSize, eol),
|
|
250
250
|
wrapByPair(`{${eol}`, `${eol}}`),
|
|
@@ -5366,7 +5366,7 @@ const EdgePlugin$1 = {
|
|
|
5366
5366
|
'Edge',
|
|
5367
5367
|
{
|
|
5368
5368
|
targets: model.targets.map((target) => {
|
|
5369
|
-
if (
|
|
5369
|
+
if (index_js$1.isNodeModel(target)) {
|
|
5370
5370
|
return createElement(
|
|
5371
5371
|
'NodeRef',
|
|
5372
5372
|
{
|
|
@@ -5381,7 +5381,7 @@ const EdgePlugin$1 = {
|
|
|
5381
5381
|
},
|
|
5382
5382
|
[],
|
|
5383
5383
|
);
|
|
5384
|
-
} else if (
|
|
5384
|
+
} else if (index_js$1.isForwardRefNode(target)) {
|
|
5385
5385
|
return createElement(
|
|
5386
5386
|
'NodeRef',
|
|
5387
5387
|
{
|
|
@@ -5733,7 +5733,7 @@ class ToModelConverter {
|
|
|
5733
5733
|
convert(ast) {
|
|
5734
5734
|
const plugins = [...this.plugins];
|
|
5735
5735
|
const context = {
|
|
5736
|
-
models:
|
|
5736
|
+
models: index_js$1.createModelsContext(this.options.models ?? {}),
|
|
5737
5737
|
convert(m) {
|
|
5738
5738
|
for (const plugin of plugins) {
|
|
5739
5739
|
if (plugin.match(m)) {
|
package/lib/ast/index.d.ts
CHANGED
package/lib/ast/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { pipe, map } from '
|
|
2
|
-
import { isNodeModel, isForwardRefNode, createModelsContext } from '
|
|
1
|
+
import { pipe, map } from '../utils/index.js';
|
|
2
|
+
import { isNodeModel, isForwardRefNode, createModelsContext } from '../common/index.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @group Create AST
|
package/lib/common/index.cjs
CHANGED
|
@@ -50,7 +50,7 @@ function toNodeRefGroup(targets) {
|
|
|
50
50
|
* @alpha
|
|
51
51
|
*/
|
|
52
52
|
const RootModelsContext = Object.seal({
|
|
53
|
-
// NOTE: RootModelsContext is also initialized after the model class is declared in the '
|
|
53
|
+
// NOTE: RootModelsContext is also initialized after the model class is declared in the 'core/index.js' module.
|
|
54
54
|
Graph: null,
|
|
55
55
|
Digraph: null,
|
|
56
56
|
Subgraph: null,
|
package/lib/common/index.js
CHANGED
|
@@ -46,7 +46,7 @@ function toNodeRefGroup(targets) {
|
|
|
46
46
|
* @alpha
|
|
47
47
|
*/
|
|
48
48
|
const RootModelsContext = Object.seal({
|
|
49
|
-
// NOTE: RootModelsContext is also initialized after the model class is declared in the '
|
|
49
|
+
// NOTE: RootModelsContext is also initialized after the model class is declared in the 'core/index.js' module.
|
|
50
50
|
Graph: null,
|
|
51
51
|
Digraph: null,
|
|
52
52
|
Subgraph: null,
|
package/lib/core/index.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var index_js = require('../common/index.js');
|
|
6
|
+
var index_js$1 = require('../ast/index.js');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @group Attribute
|
|
@@ -81,7 +81,7 @@ class AttributeList extends AttributesBase {
|
|
|
81
81
|
*/
|
|
82
82
|
class GraphBase extends AttributesBase {
|
|
83
83
|
/** @hidden */
|
|
84
|
-
#models =
|
|
84
|
+
#models = index_js.RootModelsContext;
|
|
85
85
|
id;
|
|
86
86
|
comment;
|
|
87
87
|
attributes = Object.freeze({
|
|
@@ -105,7 +105,7 @@ class GraphBase extends AttributesBase {
|
|
|
105
105
|
subgraphs: new Set(),
|
|
106
106
|
};
|
|
107
107
|
with(models) {
|
|
108
|
-
this.#models =
|
|
108
|
+
this.#models = index_js.createModelsContext(models);
|
|
109
109
|
}
|
|
110
110
|
addNode(node) {
|
|
111
111
|
this.#objects.nodes.set(node.id, node);
|
|
@@ -152,7 +152,9 @@ class GraphBase extends AttributesBase {
|
|
|
152
152
|
return this.#objects.nodes.get(id);
|
|
153
153
|
}
|
|
154
154
|
createEdge(targets, attributes) {
|
|
155
|
-
const ts = targets.map((t) =>
|
|
155
|
+
const ts = targets.map((t) =>
|
|
156
|
+
index_js.isNodeRefGroupLike(t) ? index_js.toNodeRefGroup(t) : index_js.toNodeRef(t),
|
|
157
|
+
);
|
|
156
158
|
const edge = new this.#models.Edge(ts, attributes);
|
|
157
159
|
this.addEdge(edge);
|
|
158
160
|
return edge;
|
|
@@ -320,14 +322,14 @@ class Edge extends DotObject {
|
|
|
320
322
|
constructor(targets, attributes) {
|
|
321
323
|
super();
|
|
322
324
|
this.targets = targets;
|
|
323
|
-
if (targets.length < 2 && (
|
|
325
|
+
if (targets.length < 2 && (index_js.isNodeRefLike(targets[0]) && index_js.isNodeRefLike(targets[1])) === false) {
|
|
324
326
|
throw Error('The element of Edge target is missing or not satisfied as Edge target.');
|
|
325
327
|
}
|
|
326
328
|
this.attributes = new AttributesGroup(attributes);
|
|
327
329
|
}
|
|
328
330
|
}
|
|
329
331
|
|
|
330
|
-
Object.assign(
|
|
332
|
+
Object.assign(index_js.RootModelsContext, {
|
|
331
333
|
Graph,
|
|
332
334
|
Digraph,
|
|
333
335
|
Subgraph,
|
|
@@ -350,7 +352,7 @@ function ModelFactoryBuilder(directed, strictMode) {
|
|
|
350
352
|
return g;
|
|
351
353
|
};
|
|
352
354
|
}
|
|
353
|
-
function createModelFactories(strict, context =
|
|
355
|
+
function createModelFactories(strict, context = index_js.RootModelsContext) {
|
|
354
356
|
return Object.freeze({
|
|
355
357
|
digraph: ModelFactoryBuilder.call(context, true, strict),
|
|
356
358
|
graph: ModelFactoryBuilder.call(context, false, strict),
|
|
@@ -377,7 +379,7 @@ const strict = createModelFactories(true);
|
|
|
377
379
|
* @group Model Factory
|
|
378
380
|
*/
|
|
379
381
|
function withContext(models) {
|
|
380
|
-
const context =
|
|
382
|
+
const context = index_js.createModelsContext(models);
|
|
381
383
|
return Object.freeze({
|
|
382
384
|
...createModelFactories(false, context),
|
|
383
385
|
strict: createModelFactories(true, context),
|
|
@@ -394,24 +396,24 @@ function withContext(models) {
|
|
|
394
396
|
* @returns DOT string
|
|
395
397
|
*/
|
|
396
398
|
function toDot(model, options) {
|
|
397
|
-
const ast
|
|
398
|
-
return
|
|
399
|
+
const ast = index_js$1.fromModel(model, options?.convert);
|
|
400
|
+
return index_js$1.stringify(ast, options?.print);
|
|
399
401
|
}
|
|
400
402
|
|
|
401
403
|
function fromDot(dot, options) {
|
|
402
|
-
const ast
|
|
404
|
+
const ast = index_js$1.parse(dot, options?.parse);
|
|
403
405
|
if (
|
|
404
|
-
Array.isArray(ast
|
|
405
|
-
ast
|
|
406
|
-
ast
|
|
407
|
-
ast
|
|
408
|
-
ast
|
|
409
|
-
ast
|
|
410
|
-
ast
|
|
406
|
+
Array.isArray(ast) ||
|
|
407
|
+
ast.type === 'Attribute' ||
|
|
408
|
+
ast.type === 'AttributeList' ||
|
|
409
|
+
ast.type === 'Comment' ||
|
|
410
|
+
ast.type === 'NodeRef' ||
|
|
411
|
+
ast.type === 'NodeRefGroup' ||
|
|
412
|
+
ast.type === 'Literal'
|
|
411
413
|
) {
|
|
412
414
|
throw new Error();
|
|
413
415
|
}
|
|
414
|
-
return
|
|
416
|
+
return index_js$1.toModel(ast, options?.convert);
|
|
415
417
|
}
|
|
416
418
|
|
|
417
419
|
exports.AttributeList = AttributeList;
|
package/lib/core/index.d.ts
CHANGED
|
@@ -28,8 +28,8 @@ import {
|
|
|
28
28
|
SubgraphAttributeKey,
|
|
29
29
|
ClusterSubgraphAttributeKey,
|
|
30
30
|
DotObjectModel,
|
|
31
|
-
} from '
|
|
32
|
-
import { ConvertFromModelOptions, PrintOptions, ParseOptions, ConvertToModelOptions } from '
|
|
31
|
+
} from '../common/index.js';
|
|
32
|
+
import { ConvertFromModelOptions, PrintOptions, ParseOptions, ConvertToModelOptions } from '../ast/index.js';
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* @group Attribute
|
package/lib/core/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
toNodeRefGroup,
|
|
6
6
|
toNodeRef,
|
|
7
7
|
isNodeRefLike,
|
|
8
|
-
} from '
|
|
9
|
-
import { fromModel, stringify, parse, toModel } from '
|
|
8
|
+
} from '../common/index.js';
|
|
9
|
+
import { fromModel, stringify, parse, toModel } from '../ast/index.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @group Attribute
|
package/lib/index.cjs
CHANGED
|
@@ -2,24 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var index_js = require('./common/index.js');
|
|
6
|
+
var index_js$1 = require('./core/index.js');
|
|
7
7
|
|
|
8
|
-
Object.keys(
|
|
8
|
+
Object.keys(index_js).forEach(function (k) {
|
|
9
9
|
if (k !== 'default' && !exports.hasOwnProperty(k))
|
|
10
10
|
Object.defineProperty(exports, k, {
|
|
11
11
|
enumerable: true,
|
|
12
12
|
get: function () {
|
|
13
|
-
return
|
|
13
|
+
return index_js[k];
|
|
14
14
|
},
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
|
-
Object.keys(
|
|
17
|
+
Object.keys(index_js$1).forEach(function (k) {
|
|
18
18
|
if (k !== 'default' && !exports.hasOwnProperty(k))
|
|
19
19
|
Object.defineProperty(exports, k, {
|
|
20
20
|
enumerable: true,
|
|
21
21
|
get: function () {
|
|
22
|
-
return
|
|
22
|
+
return index_js$1[k];
|
|
23
23
|
},
|
|
24
24
|
});
|
|
25
25
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
1
|
+
export * from './common/index.js';
|
|
2
|
+
export * from './core/index.js';
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
1
|
+
export * from './common/index.js';
|
|
2
|
+
export * from './core/index.js';
|
package/package.json
CHANGED
package/test/utils/to-dot.ts
CHANGED