@ts-graphviz/core 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 +13 -0
- package/LICENSE +22 -0
- package/README.md +47 -0
- package/lib/core.cjs +397 -0
- package/lib/core.d.ts +323 -0
- package/lib/core.js +397 -0
- package/package.json +37 -0
- package/src/attribute.ts +18 -0
- package/src/core.ts +5 -0
- package/src/from-dot.ts +73 -0
- package/src/model-factory/index.ts +2 -0
- package/src/model-factory/model-factory-builder.test.ts +79 -0
- package/src/model-factory/model-factory-builder.ts +55 -0
- package/src/model-factory/model-factory.test.ts +61 -0
- package/src/model-factory/model-factory.ts +40 -0
- package/src/model-factory/types.ts +46 -0
- package/src/models/AttributeList.spec.ts +58 -0
- package/src/models/AttributeList.ts +32 -0
- package/src/models/AttributesBase.spec.ts +79 -0
- package/src/models/AttributesBase.ts +62 -0
- package/src/models/AttributesGroup.spec.ts +18 -0
- package/src/models/AttributesGroup.ts +13 -0
- package/src/models/Digraph.spec.ts +17 -0
- package/src/models/Digraph.ts +11 -0
- package/src/models/DotObject.ts +5 -0
- package/src/models/Edge.spec.ts +48 -0
- package/src/models/Edge.ts +40 -0
- package/src/models/Graph.spec.ts +18 -0
- package/src/models/Graph.ts +11 -0
- package/src/models/GraphBase.spec.ts +364 -0
- package/src/models/GraphBase.ts +263 -0
- package/src/models/Node.spec.ts +25 -0
- package/src/models/Node.ts +37 -0
- package/src/models/RootGraph.spec.ts +69 -0
- package/src/models/RootGraph.ts +48 -0
- package/src/models/Subgraph.spec.ts +196 -0
- package/src/models/Subgraph.ts +44 -0
- package/src/models/index.ts +15 -0
- package/src/models/registerModelContext.ts +14 -0
- package/src/to-dot.ts +36 -0
- package/tsconfig.json +8 -0
- package/typedoc.json +4 -0
- package/vite.config.ts +22 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @ts-graphviz/core
|
|
2
|
+
|
|
3
|
+
## 0.0.0-pr956-20240225073457
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [`6b2f0e8`](https://github.com/ts-graphviz/ts-graphviz/commit/6b2f0e8349605b4fe0dd950147ba3a8285b24b24) Thanks [@kamiazya](https://github.com/kamiazya)! - Release v2.0.0
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`6b2f0e8`](https://github.com/ts-graphviz/ts-graphviz/commit/6b2f0e8349605b4fe0dd950147ba3a8285b24b24)]:
|
|
12
|
+
- @ts-graphviz/common@0.0.0-pr956-20240225073457
|
|
13
|
+
- @ts-graphviz/ast@0.0.0-pr956-20240225073457
|
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2019-2024 Yuki Yamazaki
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @ts-graphviz/core
|
|
2
|
+
|
|
3
|
+
This package contains the core implementation of models and functions provided to users for the ts-graphviz library.
|
|
4
|
+
|
|
5
|
+
It is part of the ts-graphviz library, which is split into modular packages to improve maintainability, flexibility, and ease of use.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Graph, Node, and Edge model implementations
|
|
10
|
+
- High-level APIs for creating and manipulating DOT language elements
|
|
11
|
+
- Extensible design for custom implementations
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Import the necessary classes and functions from the @ts-graphviz/core package:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Graph, Node, Edge } from '@ts-graphviz/core';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Use the imported items in your project to create and manipulate DOT language elements:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const graph = new Graph('G');
|
|
25
|
+
const nodeA = new Node('A', { label: 'Node A' });
|
|
26
|
+
const nodeB = new Node('B', { label: 'Node B' });
|
|
27
|
+
const edge = new Edge([nodeA, nodeB], { label: 'A -> B' });
|
|
28
|
+
|
|
29
|
+
graph.addNode(nodeA);
|
|
30
|
+
graph.addNode(nodeB);
|
|
31
|
+
graph.addEdge(edge);
|
|
32
|
+
|
|
33
|
+
console.log(graph.toDot());
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For more examples and usage details, please refer to the ts-graphviz documentation.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Contributing
|
|
40
|
+
|
|
41
|
+
Contributions to the ts-graphviz project are welcome.
|
|
42
|
+
|
|
43
|
+
Please refer to the main ts-graphviz repository for guidelines on how to contribute.
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
This package is released under the MIT License.
|
package/lib/core.cjs
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
var __accessCheck = (obj, member, msg) => {
|
|
9
|
+
if (!member.has(obj))
|
|
10
|
+
throw TypeError("Cannot " + msg);
|
|
11
|
+
};
|
|
12
|
+
var __privateGet = (obj, member, getter) => {
|
|
13
|
+
__accessCheck(obj, member, "read from private field");
|
|
14
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
15
|
+
};
|
|
16
|
+
var __privateAdd = (obj, member, value) => {
|
|
17
|
+
if (member.has(obj))
|
|
18
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
19
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
20
|
+
};
|
|
21
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
22
|
+
__accessCheck(obj, member, "write to private field");
|
|
23
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
var _attrs, _models, _objects;
|
|
27
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
28
|
+
const common = require("@ts-graphviz/common");
|
|
29
|
+
const ast = require("@ts-graphviz/ast");
|
|
30
|
+
const attribute = new Proxy(
|
|
31
|
+
Object.freeze({}),
|
|
32
|
+
{
|
|
33
|
+
get: (_, key) => key
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
class DotObject {
|
|
37
|
+
}
|
|
38
|
+
class AttributesBase extends DotObject {
|
|
39
|
+
constructor(attributes) {
|
|
40
|
+
super();
|
|
41
|
+
/** @hidden */
|
|
42
|
+
__privateAdd(this, _attrs, /* @__PURE__ */ new Map());
|
|
43
|
+
if (attributes !== void 0) {
|
|
44
|
+
this.apply(attributes);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
get values() {
|
|
48
|
+
return Array.from(__privateGet(this, _attrs).entries());
|
|
49
|
+
}
|
|
50
|
+
get size() {
|
|
51
|
+
return __privateGet(this, _attrs).size;
|
|
52
|
+
}
|
|
53
|
+
get(key) {
|
|
54
|
+
return __privateGet(this, _attrs).get(key);
|
|
55
|
+
}
|
|
56
|
+
set(key, value) {
|
|
57
|
+
if (value !== null && value !== void 0) {
|
|
58
|
+
__privateGet(this, _attrs).set(key, value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
delete(key) {
|
|
62
|
+
__privateGet(this, _attrs).delete(key);
|
|
63
|
+
}
|
|
64
|
+
apply(attributes) {
|
|
65
|
+
const entries = Array.isArray(attributes) ? attributes : Object.entries(attributes);
|
|
66
|
+
for (const [key, value] of entries) {
|
|
67
|
+
this.set(key, value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
clear() {
|
|
71
|
+
__privateGet(this, _attrs).clear();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
_attrs = new WeakMap();
|
|
75
|
+
class AttributeList extends AttributesBase {
|
|
76
|
+
constructor($$kind, attributes) {
|
|
77
|
+
super(attributes);
|
|
78
|
+
__publicField(this, "comment");
|
|
79
|
+
this.$$kind = $$kind;
|
|
80
|
+
}
|
|
81
|
+
get $$type() {
|
|
82
|
+
return "AttributeList";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
class GraphBase extends AttributesBase {
|
|
86
|
+
constructor() {
|
|
87
|
+
super(...arguments);
|
|
88
|
+
/** @hidden */
|
|
89
|
+
__privateAdd(this, _models, common.RootModelsContext);
|
|
90
|
+
__publicField(this, "id");
|
|
91
|
+
__publicField(this, "comment");
|
|
92
|
+
__publicField(this, "attributes", Object.freeze({
|
|
93
|
+
graph: new AttributeList("Graph"),
|
|
94
|
+
edge: new AttributeList("Edge"),
|
|
95
|
+
node: new AttributeList("Node")
|
|
96
|
+
}));
|
|
97
|
+
/** @hidden */
|
|
98
|
+
__privateAdd(this, _objects, {
|
|
99
|
+
nodes: /* @__PURE__ */ new Map(),
|
|
100
|
+
edges: /* @__PURE__ */ new Set(),
|
|
101
|
+
subgraphs: /* @__PURE__ */ new Set()
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
get nodes() {
|
|
105
|
+
return Array.from(__privateGet(this, _objects).nodes.values());
|
|
106
|
+
}
|
|
107
|
+
get edges() {
|
|
108
|
+
return Array.from(__privateGet(this, _objects).edges.values());
|
|
109
|
+
}
|
|
110
|
+
get subgraphs() {
|
|
111
|
+
return Array.from(__privateGet(this, _objects).subgraphs.values());
|
|
112
|
+
}
|
|
113
|
+
with(models) {
|
|
114
|
+
__privateSet(this, _models, common.createModelsContext(models));
|
|
115
|
+
}
|
|
116
|
+
addNode(node) {
|
|
117
|
+
__privateGet(this, _objects).nodes.set(node.id, node);
|
|
118
|
+
}
|
|
119
|
+
addEdge(edge) {
|
|
120
|
+
__privateGet(this, _objects).edges.add(edge);
|
|
121
|
+
}
|
|
122
|
+
addSubgraph(subgraph) {
|
|
123
|
+
__privateGet(this, _objects).subgraphs.add(subgraph);
|
|
124
|
+
}
|
|
125
|
+
existNode(nodeId) {
|
|
126
|
+
return __privateGet(this, _objects).nodes.has(nodeId);
|
|
127
|
+
}
|
|
128
|
+
existEdge(edge) {
|
|
129
|
+
return __privateGet(this, _objects).edges.has(edge);
|
|
130
|
+
}
|
|
131
|
+
existSubgraph(subgraph) {
|
|
132
|
+
return __privateGet(this, _objects).subgraphs.has(subgraph);
|
|
133
|
+
}
|
|
134
|
+
createSubgraph(...args) {
|
|
135
|
+
const subgraph = new (__privateGet(this, _models)).Subgraph(...args);
|
|
136
|
+
subgraph.with(__privateGet(this, _models));
|
|
137
|
+
this.addSubgraph(subgraph);
|
|
138
|
+
return subgraph;
|
|
139
|
+
}
|
|
140
|
+
removeNode(node) {
|
|
141
|
+
__privateGet(this, _objects).nodes.delete(typeof node === "string" ? node : node.id);
|
|
142
|
+
}
|
|
143
|
+
removeEdge(edge) {
|
|
144
|
+
__privateGet(this, _objects).edges.delete(edge);
|
|
145
|
+
}
|
|
146
|
+
removeSubgraph(subgraph) {
|
|
147
|
+
__privateGet(this, _objects).subgraphs.delete(subgraph);
|
|
148
|
+
}
|
|
149
|
+
createNode(id, attributes) {
|
|
150
|
+
const node = new (__privateGet(this, _models)).Node(id, attributes);
|
|
151
|
+
this.addNode(node);
|
|
152
|
+
return node;
|
|
153
|
+
}
|
|
154
|
+
getSubgraph(id) {
|
|
155
|
+
return Array.from(__privateGet(this, _objects).subgraphs.values()).find(
|
|
156
|
+
(subgraph) => subgraph.id === id
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
getNode(id) {
|
|
160
|
+
return __privateGet(this, _objects).nodes.get(id);
|
|
161
|
+
}
|
|
162
|
+
createEdge(targets, attributes) {
|
|
163
|
+
const ts = targets.map(
|
|
164
|
+
(t) => common.isNodeRefGroupLike(t) ? common.toNodeRefGroup(t) : common.toNodeRef(t)
|
|
165
|
+
);
|
|
166
|
+
const edge = new (__privateGet(this, _models)).Edge(ts, attributes);
|
|
167
|
+
this.addEdge(edge);
|
|
168
|
+
return edge;
|
|
169
|
+
}
|
|
170
|
+
subgraph(...args) {
|
|
171
|
+
const id = args.find(
|
|
172
|
+
(arg) => typeof arg === "string"
|
|
173
|
+
);
|
|
174
|
+
const attributes = args.find(
|
|
175
|
+
(arg) => typeof arg === "object" && arg !== null
|
|
176
|
+
);
|
|
177
|
+
const callback = args.find(
|
|
178
|
+
(arg) => typeof arg === "function"
|
|
179
|
+
);
|
|
180
|
+
const subgraph = id ? this.getSubgraph(id) ?? this.createSubgraph(id) : this.createSubgraph();
|
|
181
|
+
if (attributes !== void 0) {
|
|
182
|
+
subgraph.apply(attributes);
|
|
183
|
+
}
|
|
184
|
+
if (callback !== void 0) {
|
|
185
|
+
callback(subgraph);
|
|
186
|
+
}
|
|
187
|
+
return subgraph;
|
|
188
|
+
}
|
|
189
|
+
node(firstArg, ...args) {
|
|
190
|
+
if (typeof firstArg === "string") {
|
|
191
|
+
const id = firstArg;
|
|
192
|
+
const attributes = args.find(
|
|
193
|
+
(arg) => typeof arg === "object" && arg !== null
|
|
194
|
+
);
|
|
195
|
+
const callback = args.find(
|
|
196
|
+
(arg) => typeof arg === "function"
|
|
197
|
+
);
|
|
198
|
+
const node = this.getNode(id) ?? this.createNode(id);
|
|
199
|
+
if (attributes !== void 0) {
|
|
200
|
+
node.attributes.apply(attributes);
|
|
201
|
+
}
|
|
202
|
+
if (callback !== void 0) {
|
|
203
|
+
callback(node);
|
|
204
|
+
}
|
|
205
|
+
return node;
|
|
206
|
+
}
|
|
207
|
+
if (typeof firstArg === "object" && firstArg !== null) {
|
|
208
|
+
this.attributes.node.apply(firstArg);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
edge(firstArg, ...args) {
|
|
212
|
+
if (Array.isArray(firstArg)) {
|
|
213
|
+
const targets = firstArg;
|
|
214
|
+
const attributes = args.find(
|
|
215
|
+
(arg) => typeof arg === "object"
|
|
216
|
+
);
|
|
217
|
+
const callback = args.find(
|
|
218
|
+
(arg) => typeof arg === "function"
|
|
219
|
+
);
|
|
220
|
+
const edge = this.createEdge(targets, attributes);
|
|
221
|
+
if (callback !== void 0) {
|
|
222
|
+
callback(edge);
|
|
223
|
+
}
|
|
224
|
+
return edge;
|
|
225
|
+
}
|
|
226
|
+
if (typeof firstArg === "object" && firstArg !== null) {
|
|
227
|
+
this.attributes.edge.apply(firstArg);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
graph(attributes) {
|
|
231
|
+
this.attributes.graph.apply(attributes);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
_models = new WeakMap();
|
|
235
|
+
_objects = new WeakMap();
|
|
236
|
+
class RootGraph extends GraphBase {
|
|
237
|
+
constructor(...args) {
|
|
238
|
+
super();
|
|
239
|
+
__publicField(this, "id");
|
|
240
|
+
__publicField(this, "strict");
|
|
241
|
+
this.id = args.find((arg) => typeof arg === "string");
|
|
242
|
+
this.strict = args.find((arg) => typeof arg === "boolean") ?? false;
|
|
243
|
+
const attributes = args.find(
|
|
244
|
+
(arg) => typeof arg === "object" && arg !== null
|
|
245
|
+
);
|
|
246
|
+
if (attributes !== void 0) {
|
|
247
|
+
this.apply(attributes);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
get $$type() {
|
|
251
|
+
return "Graph";
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
class Digraph extends RootGraph {
|
|
255
|
+
get directed() {
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
class AttributesGroup extends AttributesBase {
|
|
260
|
+
constructor() {
|
|
261
|
+
super(...arguments);
|
|
262
|
+
__publicField(this, "comment");
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
class Edge extends DotObject {
|
|
266
|
+
constructor(targets, attributes) {
|
|
267
|
+
super();
|
|
268
|
+
__publicField(this, "comment");
|
|
269
|
+
__publicField(this, "attributes");
|
|
270
|
+
this.targets = targets;
|
|
271
|
+
if (targets.length < 2 && (common.isNodeRefLike(targets[0]) && common.isNodeRefLike(targets[1])) === false) {
|
|
272
|
+
throw Error(
|
|
273
|
+
"The element of Edge target is missing or not satisfied as Edge target."
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
this.attributes = new AttributesGroup(attributes);
|
|
277
|
+
}
|
|
278
|
+
get $$type() {
|
|
279
|
+
return "Edge";
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
class Graph extends RootGraph {
|
|
283
|
+
get directed() {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
class Node extends DotObject {
|
|
288
|
+
constructor(id, attributes) {
|
|
289
|
+
super();
|
|
290
|
+
__publicField(this, "comment");
|
|
291
|
+
__publicField(this, "attributes");
|
|
292
|
+
this.id = id;
|
|
293
|
+
this.attributes = new AttributesGroup(attributes);
|
|
294
|
+
}
|
|
295
|
+
get $$type() {
|
|
296
|
+
return "Node";
|
|
297
|
+
}
|
|
298
|
+
port(port) {
|
|
299
|
+
if (typeof port === "string") {
|
|
300
|
+
return { id: this.id, port };
|
|
301
|
+
}
|
|
302
|
+
return { id: this.id, ...port };
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
class Subgraph extends GraphBase {
|
|
306
|
+
constructor(...args) {
|
|
307
|
+
super();
|
|
308
|
+
__publicField(this, "id");
|
|
309
|
+
this.id = args.find((arg) => typeof arg === "string");
|
|
310
|
+
const attributes = args.find(
|
|
311
|
+
(arg) => typeof arg === "object" && arg !== null
|
|
312
|
+
);
|
|
313
|
+
if (attributes !== void 0) {
|
|
314
|
+
this.apply(attributes);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
get $$type() {
|
|
318
|
+
return "Subgraph";
|
|
319
|
+
}
|
|
320
|
+
isSubgraphCluster() {
|
|
321
|
+
if (typeof this.id === "string") {
|
|
322
|
+
return this.id.startsWith("cluster");
|
|
323
|
+
}
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
Object.assign(common.RootModelsContext, {
|
|
328
|
+
Graph,
|
|
329
|
+
Digraph,
|
|
330
|
+
Subgraph,
|
|
331
|
+
Node,
|
|
332
|
+
Edge
|
|
333
|
+
});
|
|
334
|
+
function ModelFactoryBuilder(directed, strictMode) {
|
|
335
|
+
return (...args) => {
|
|
336
|
+
const G = directed ? this.Digraph : this.Graph;
|
|
337
|
+
const id = args.find((arg) => typeof arg === "string");
|
|
338
|
+
const attributes = args.find(
|
|
339
|
+
(arg) => typeof arg === "object"
|
|
340
|
+
);
|
|
341
|
+
const callback = args.find(
|
|
342
|
+
(arg) => typeof arg === "function"
|
|
343
|
+
);
|
|
344
|
+
const g = new G(id, strictMode, attributes);
|
|
345
|
+
g.with(this);
|
|
346
|
+
if (typeof callback === "function") {
|
|
347
|
+
callback(g);
|
|
348
|
+
}
|
|
349
|
+
return g;
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function createModelFactories(strict2, context = common.RootModelsContext) {
|
|
353
|
+
return Object.freeze({
|
|
354
|
+
digraph: ModelFactoryBuilder.call(context, true, strict2),
|
|
355
|
+
graph: ModelFactoryBuilder.call(context, false, strict2)
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
const noStrict = createModelFactories(false);
|
|
359
|
+
const digraph = noStrict.digraph;
|
|
360
|
+
const graph = noStrict.graph;
|
|
361
|
+
const strict = createModelFactories(true);
|
|
362
|
+
function withContext(models) {
|
|
363
|
+
const context = common.createModelsContext(models);
|
|
364
|
+
return Object.freeze({
|
|
365
|
+
...createModelFactories(false, context),
|
|
366
|
+
strict: createModelFactories(true, context)
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
function toDot(model, options) {
|
|
370
|
+
const ast$1 = ast.fromModel(model, options == null ? void 0 : options.convert);
|
|
371
|
+
return ast.stringify(ast$1, options == null ? void 0 : options.print);
|
|
372
|
+
}
|
|
373
|
+
function fromDot(dot, options) {
|
|
374
|
+
const ast$1 = ast.parse(dot, options == null ? void 0 : options.parse);
|
|
375
|
+
if (Array.isArray(ast$1) || ast$1.type === "Attribute" || ast$1.type === "AttributeList" || ast$1.type === "Comment" || ast$1.type === "NodeRef" || ast$1.type === "NodeRefGroup" || ast$1.type === "Literal") {
|
|
376
|
+
throw new Error();
|
|
377
|
+
}
|
|
378
|
+
return ast.toModel(ast$1, options == null ? void 0 : options.convert);
|
|
379
|
+
}
|
|
380
|
+
exports.AttributeList = AttributeList;
|
|
381
|
+
exports.AttributesBase = AttributesBase;
|
|
382
|
+
exports.AttributesGroup = AttributesGroup;
|
|
383
|
+
exports.Digraph = Digraph;
|
|
384
|
+
exports.DotObject = DotObject;
|
|
385
|
+
exports.Edge = Edge;
|
|
386
|
+
exports.Graph = Graph;
|
|
387
|
+
exports.GraphBase = GraphBase;
|
|
388
|
+
exports.Node = Node;
|
|
389
|
+
exports.RootGraph = RootGraph;
|
|
390
|
+
exports.Subgraph = Subgraph;
|
|
391
|
+
exports.attribute = attribute;
|
|
392
|
+
exports.digraph = digraph;
|
|
393
|
+
exports.fromDot = fromDot;
|
|
394
|
+
exports.graph = graph;
|
|
395
|
+
exports.strict = strict;
|
|
396
|
+
exports.toDot = toDot;
|
|
397
|
+
exports.withContext = withContext;
|