ts-graphviz 1.0.0 → 1.1.0
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/README.ja.md +15 -8
- package/README.md +15 -8
- package/lib/ast/index.cjs +543 -527
- package/lib/ast/index.d.ts +215 -49
- package/lib/ast/index.js +543 -527
- package/lib/common/index.cjs +32 -0
- package/lib/common/index.d.ts +267 -9
- package/lib/common/index.js +32 -0
- package/lib/core/index.cjs +149 -178
- package/lib/core/index.d.ts +148 -402
- package/lib/core/index.js +157 -179
- package/media/ts-graphviz.svg +1 -1
- package/package.json +3 -3
- package/test/__snapshots__/class-base.test.ts.snap +18 -0
- package/test/__snapshots__/create-root-graph.spec.ts.snap +200 -0
- package/test/__snapshots__/to-dot.test.ts.snap +229 -0
- package/test/class-base.test.ts +23 -0
- package/test/create-root-graph.spec.ts +292 -0
- package/test/to-dot.test.ts +112 -0
- package/test/utils/index.ts +1 -0
- package/test/utils/to-dot.ts +5 -0
package/lib/common/index.cjs
CHANGED
|
@@ -2,24 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
require('#lib/core');
|
|
6
|
+
|
|
7
|
+
/** @hidden */
|
|
5
8
|
function isForwardRefNode(object) {
|
|
6
9
|
return typeof object === 'object' && object !== null && typeof object.id === 'string';
|
|
7
10
|
}
|
|
11
|
+
/** @hidden */
|
|
8
12
|
function isNodeModel(object) {
|
|
9
13
|
return typeof object === 'object' && object !== null && object.$$type === 'Node' && typeof object.id === 'string';
|
|
10
14
|
}
|
|
15
|
+
/** @hidden */
|
|
11
16
|
function isNodeRef(node) {
|
|
12
17
|
return isNodeModel(node) || isForwardRefNode(node);
|
|
13
18
|
}
|
|
19
|
+
/** @hidden */
|
|
14
20
|
function isNodeRefLike(node) {
|
|
15
21
|
return typeof node === 'string' || isNodeRef(node);
|
|
16
22
|
}
|
|
23
|
+
/** @hidden */
|
|
17
24
|
function isNodeRefGroupLike(target) {
|
|
18
25
|
return Array.isArray(target) && target.every(isNodeRefLike);
|
|
19
26
|
}
|
|
27
|
+
/** @hidden */
|
|
20
28
|
function isCompass(c) {
|
|
21
29
|
return ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'c'].includes(c);
|
|
22
30
|
}
|
|
31
|
+
/** @hidden */
|
|
23
32
|
function toNodeRef(target) {
|
|
24
33
|
if (isNodeRef(target)) {
|
|
25
34
|
return target;
|
|
@@ -30,6 +39,7 @@ function toNodeRef(target) {
|
|
|
30
39
|
}
|
|
31
40
|
return { id, port };
|
|
32
41
|
}
|
|
42
|
+
/** @hidden */
|
|
33
43
|
function toNodeRefGroup(targets) {
|
|
34
44
|
if (targets.length < 2 && (isNodeRefLike(targets[0]) && isNodeRefLike(targets[1])) === false) {
|
|
35
45
|
throw Error('EdgeTargets must have at least 2 elements.');
|
|
@@ -37,6 +47,28 @@ function toNodeRefGroup(targets) {
|
|
|
37
47
|
return targets.map((t) => toNodeRef(t));
|
|
38
48
|
}
|
|
39
49
|
|
|
50
|
+
/**
|
|
51
|
+
* @group Models Context
|
|
52
|
+
* @alpha
|
|
53
|
+
*/
|
|
54
|
+
const RootModelsContext = Object.seal({
|
|
55
|
+
// NOTE: RootModelsContext is also initialized after the model class is declared in the '#lib/core' module.
|
|
56
|
+
Graph: null,
|
|
57
|
+
Digraph: null,
|
|
58
|
+
Subgraph: null,
|
|
59
|
+
Node: null,
|
|
60
|
+
Edge: null,
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* @group Models Context
|
|
64
|
+
* @alpha
|
|
65
|
+
*/
|
|
66
|
+
function createModelsContext(models) {
|
|
67
|
+
return Object.assign(Object.seal(Object.assign({}, RootModelsContext)), models);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
exports.RootModelsContext = RootModelsContext;
|
|
71
|
+
exports.createModelsContext = createModelsContext;
|
|
40
72
|
exports.isCompass = isCompass;
|
|
41
73
|
exports.isForwardRefNode = isForwardRefNode;
|
|
42
74
|
exports.isNodeModel = isNodeModel;
|