@ts-graphviz/core 0.0.0-pr956-20240225091623 → 0.0.0-pr956-20240225160253

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/core.js CHANGED
@@ -1,380 +1,14 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
- var __accessCheck = (obj, member, msg) => {
8
- if (!member.has(obj))
9
- throw TypeError("Cannot " + msg);
10
- };
11
- var __privateGet = (obj, member, getter) => {
12
- __accessCheck(obj, member, "read from private field");
13
- return getter ? getter.call(obj) : member.get(obj);
14
- };
15
- var __privateAdd = (obj, member, value) => {
16
- if (member.has(obj))
17
- throw TypeError("Cannot add the same private member more than once");
18
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
19
- };
20
- var __privateSet = (obj, member, value, setter) => {
21
- __accessCheck(obj, member, "write to private field");
22
- setter ? setter.call(obj, value) : member.set(obj, value);
23
- return value;
24
- };
25
- var _attrs, _models, _objects;
26
- import { RootModelsContext, createModelsContext, isNodeRefGroupLike, toNodeRefGroup, toNodeRef, isNodeRefLike } from "@ts-graphviz/common";
27
- import { fromModel, stringify, parse, toModel } from "@ts-graphviz/ast";
28
- const attribute = new Proxy(
29
- Object.freeze({}),
30
- {
31
- get: (_, key) => key
32
- }
33
- );
34
- class DotObject {
35
- }
36
- class AttributesBase extends DotObject {
37
- constructor(attributes) {
38
- super();
39
- /** @hidden */
40
- __privateAdd(this, _attrs, /* @__PURE__ */ new Map());
41
- if (attributes !== void 0) {
42
- this.apply(attributes);
43
- }
44
- }
45
- get values() {
46
- return Array.from(__privateGet(this, _attrs).entries());
47
- }
48
- get size() {
49
- return __privateGet(this, _attrs).size;
50
- }
51
- get(key) {
52
- return __privateGet(this, _attrs).get(key);
53
- }
54
- set(key, value) {
55
- if (value !== null && value !== void 0) {
56
- __privateGet(this, _attrs).set(key, value);
57
- }
58
- }
59
- delete(key) {
60
- __privateGet(this, _attrs).delete(key);
61
- }
62
- apply(attributes) {
63
- const entries = Array.isArray(attributes) ? attributes : Object.entries(attributes);
64
- for (const [key, value] of entries) {
65
- this.set(key, value);
66
- }
67
- }
68
- clear() {
69
- __privateGet(this, _attrs).clear();
70
- }
71
- }
72
- _attrs = new WeakMap();
73
- class AttributeList extends AttributesBase {
74
- constructor($$kind, attributes) {
75
- super(attributes);
76
- __publicField(this, "comment");
77
- this.$$kind = $$kind;
78
- }
79
- get $$type() {
80
- return "AttributeList";
81
- }
82
- }
83
- class GraphBase extends AttributesBase {
84
- constructor() {
85
- super(...arguments);
86
- /** @hidden */
87
- __privateAdd(this, _models, RootModelsContext);
88
- __publicField(this, "id");
89
- __publicField(this, "comment");
90
- __publicField(this, "attributes", Object.freeze({
91
- graph: new AttributeList("Graph"),
92
- edge: new AttributeList("Edge"),
93
- node: new AttributeList("Node")
94
- }));
95
- /** @hidden */
96
- __privateAdd(this, _objects, {
97
- nodes: /* @__PURE__ */ new Map(),
98
- edges: /* @__PURE__ */ new Set(),
99
- subgraphs: /* @__PURE__ */ new Set()
100
- });
101
- }
102
- get nodes() {
103
- return Array.from(__privateGet(this, _objects).nodes.values());
104
- }
105
- get edges() {
106
- return Array.from(__privateGet(this, _objects).edges.values());
107
- }
108
- get subgraphs() {
109
- return Array.from(__privateGet(this, _objects).subgraphs.values());
110
- }
111
- with(models) {
112
- __privateSet(this, _models, createModelsContext(models));
113
- }
114
- addNode(node) {
115
- __privateGet(this, _objects).nodes.set(node.id, node);
116
- }
117
- addEdge(edge) {
118
- __privateGet(this, _objects).edges.add(edge);
119
- }
120
- addSubgraph(subgraph) {
121
- __privateGet(this, _objects).subgraphs.add(subgraph);
122
- }
123
- existNode(nodeId) {
124
- return __privateGet(this, _objects).nodes.has(nodeId);
125
- }
126
- existEdge(edge) {
127
- return __privateGet(this, _objects).edges.has(edge);
128
- }
129
- existSubgraph(subgraph) {
130
- return __privateGet(this, _objects).subgraphs.has(subgraph);
131
- }
132
- createSubgraph(...args) {
133
- const subgraph = new (__privateGet(this, _models)).Subgraph(...args);
134
- subgraph.with(__privateGet(this, _models));
135
- this.addSubgraph(subgraph);
136
- return subgraph;
137
- }
138
- removeNode(node) {
139
- __privateGet(this, _objects).nodes.delete(typeof node === "string" ? node : node.id);
140
- }
141
- removeEdge(edge) {
142
- __privateGet(this, _objects).edges.delete(edge);
143
- }
144
- removeSubgraph(subgraph) {
145
- __privateGet(this, _objects).subgraphs.delete(subgraph);
146
- }
147
- createNode(id, attributes) {
148
- const node = new (__privateGet(this, _models)).Node(id, attributes);
149
- this.addNode(node);
150
- return node;
151
- }
152
- getSubgraph(id) {
153
- return Array.from(__privateGet(this, _objects).subgraphs.values()).find(
154
- (subgraph) => subgraph.id === id
155
- );
156
- }
157
- getNode(id) {
158
- return __privateGet(this, _objects).nodes.get(id);
159
- }
160
- createEdge(targets, attributes) {
161
- const ts = targets.map(
162
- (t) => isNodeRefGroupLike(t) ? toNodeRefGroup(t) : toNodeRef(t)
163
- );
164
- const edge = new (__privateGet(this, _models)).Edge(ts, attributes);
165
- this.addEdge(edge);
166
- return edge;
167
- }
168
- subgraph(...args) {
169
- const id = args.find(
170
- (arg) => typeof arg === "string"
171
- );
172
- const attributes = args.find(
173
- (arg) => typeof arg === "object" && arg !== null
174
- );
175
- const callback = args.find(
176
- (arg) => typeof arg === "function"
177
- );
178
- const subgraph = id ? this.getSubgraph(id) ?? this.createSubgraph(id) : this.createSubgraph();
179
- if (attributes !== void 0) {
180
- subgraph.apply(attributes);
181
- }
182
- if (callback !== void 0) {
183
- callback(subgraph);
184
- }
185
- return subgraph;
186
- }
187
- node(firstArg, ...args) {
188
- if (typeof firstArg === "string") {
189
- const id = firstArg;
190
- const attributes = args.find(
191
- (arg) => typeof arg === "object" && arg !== null
192
- );
193
- const callback = args.find(
194
- (arg) => typeof arg === "function"
195
- );
196
- const node = this.getNode(id) ?? this.createNode(id);
197
- if (attributes !== void 0) {
198
- node.attributes.apply(attributes);
199
- }
200
- if (callback !== void 0) {
201
- callback(node);
202
- }
203
- return node;
204
- }
205
- if (typeof firstArg === "object" && firstArg !== null) {
206
- this.attributes.node.apply(firstArg);
207
- }
208
- }
209
- edge(firstArg, ...args) {
210
- if (Array.isArray(firstArg)) {
211
- const targets = firstArg;
212
- const attributes = args.find(
213
- (arg) => typeof arg === "object"
214
- );
215
- const callback = args.find(
216
- (arg) => typeof arg === "function"
217
- );
218
- const edge = this.createEdge(targets, attributes);
219
- if (callback !== void 0) {
220
- callback(edge);
221
- }
222
- return edge;
223
- }
224
- if (typeof firstArg === "object" && firstArg !== null) {
225
- this.attributes.edge.apply(firstArg);
226
- }
227
- }
228
- graph(attributes) {
229
- this.attributes.graph.apply(attributes);
230
- }
231
- }
232
- _models = new WeakMap();
233
- _objects = new WeakMap();
234
- class RootGraph extends GraphBase {
235
- constructor(...args) {
236
- super();
237
- __publicField(this, "id");
238
- __publicField(this, "strict");
239
- this.id = args.find((arg) => typeof arg === "string");
240
- this.strict = args.find((arg) => typeof arg === "boolean") ?? false;
241
- const attributes = args.find(
242
- (arg) => typeof arg === "object" && arg !== null
243
- );
244
- if (attributes !== void 0) {
245
- this.apply(attributes);
246
- }
247
- }
248
- get $$type() {
249
- return "Graph";
250
- }
251
- }
252
- class Digraph extends RootGraph {
253
- get directed() {
254
- return true;
255
- }
256
- }
257
- class AttributesGroup extends AttributesBase {
258
- constructor() {
259
- super(...arguments);
260
- __publicField(this, "comment");
261
- }
262
- }
263
- class Edge extends DotObject {
264
- constructor(targets, attributes) {
265
- super();
266
- __publicField(this, "comment");
267
- __publicField(this, "attributes");
268
- this.targets = targets;
269
- if (targets.length < 2 && (isNodeRefLike(targets[0]) && isNodeRefLike(targets[1])) === false) {
270
- throw Error(
271
- "The element of Edge target is missing or not satisfied as Edge target."
272
- );
273
- }
274
- this.attributes = new AttributesGroup(attributes);
275
- }
276
- get $$type() {
277
- return "Edge";
278
- }
279
- }
280
- class Graph extends RootGraph {
281
- get directed() {
282
- return false;
283
- }
284
- }
285
- class Node extends DotObject {
286
- constructor(id, attributes) {
287
- super();
288
- __publicField(this, "comment");
289
- __publicField(this, "attributes");
290
- this.id = id;
291
- this.attributes = new AttributesGroup(attributes);
292
- }
293
- get $$type() {
294
- return "Node";
295
- }
296
- port(port) {
297
- if (typeof port === "string") {
298
- return { id: this.id, port };
299
- }
300
- return { id: this.id, ...port };
301
- }
302
- }
303
- class Subgraph extends GraphBase {
304
- constructor(...args) {
305
- super();
306
- __publicField(this, "id");
307
- this.id = args.find((arg) => typeof arg === "string");
308
- const attributes = args.find(
309
- (arg) => typeof arg === "object" && arg !== null
310
- );
311
- if (attributes !== void 0) {
312
- this.apply(attributes);
313
- }
314
- }
315
- get $$type() {
316
- return "Subgraph";
317
- }
318
- isSubgraphCluster() {
319
- if (typeof this.id === "string") {
320
- return this.id.startsWith("cluster");
321
- }
322
- return false;
323
- }
324
- }
325
- Object.assign(RootModelsContext, {
326
- Graph,
327
- Digraph,
328
- Subgraph,
329
- Node,
330
- Edge
331
- });
332
- function ModelFactoryBuilder(directed, strictMode) {
333
- return (...args) => {
334
- const G = directed ? this.Digraph : this.Graph;
335
- const id = args.find((arg) => typeof arg === "string");
336
- const attributes = args.find(
337
- (arg) => typeof arg === "object"
338
- );
339
- const callback = args.find(
340
- (arg) => typeof arg === "function"
341
- );
342
- const g = new G(id, strictMode, attributes);
343
- g.with(this);
344
- if (typeof callback === "function") {
345
- callback(g);
346
- }
347
- return g;
348
- };
349
- }
350
- function createModelFactories(strict2, context = RootModelsContext) {
351
- return Object.freeze({
352
- digraph: ModelFactoryBuilder.call(context, true, strict2),
353
- graph: ModelFactoryBuilder.call(context, false, strict2)
354
- });
355
- }
356
- const noStrict = createModelFactories(false);
357
- const digraph = noStrict.digraph;
358
- const graph = noStrict.graph;
359
- const strict = createModelFactories(true);
360
- function withContext(models) {
361
- const context = createModelsContext(models);
362
- return Object.freeze({
363
- ...createModelFactories(false, context),
364
- strict: createModelFactories(true, context)
365
- });
366
- }
367
- function toDot(model, options) {
368
- const ast = fromModel(model, options == null ? void 0 : options.convert);
369
- return stringify(ast, options == null ? void 0 : options.print);
370
- }
371
- function fromDot(dot, options) {
372
- const ast = parse(dot, options == null ? void 0 : options.parse);
373
- if (Array.isArray(ast) || ast.type === "Attribute" || ast.type === "AttributeList" || ast.type === "Comment" || ast.type === "NodeRef" || ast.type === "NodeRefGroup" || ast.type === "Literal") {
374
- throw new Error();
375
- }
376
- return toModel(ast, options == null ? void 0 : options.convert);
377
- }
1
+ import { AttributeList } from "./AttributeList.js";
2
+ import { AttributesBase } from "./AttributesBase.js";
3
+ import { AttributesGroup } from "./AttributesGroup.js";
4
+ import { Digraph } from "./Digraph.js";
5
+ import { DotObject } from "./DotObject.js";
6
+ import { Edge } from "./Edge.js";
7
+ import { Graph } from "./Graph.js";
8
+ import { GraphBase } from "./GraphBase.js";
9
+ import { Node } from "./Node.js";
10
+ import { RootGraph } from "./RootGraph.js";
11
+ import { Subgraph } from "./Subgraph.js";
378
12
  export {
379
13
  AttributeList,
380
14
  AttributesBase,
@@ -386,12 +20,5 @@ export {
386
20
  GraphBase,
387
21
  Node,
388
22
  RootGraph,
389
- Subgraph,
390
- attribute,
391
- digraph,
392
- fromDot,
393
- graph,
394
- strict,
395
- toDot,
396
- withContext
23
+ Subgraph
397
24
  };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ const common = require("@ts-graphviz/common");
3
+ const Digraph = require("./Digraph.cjs");
4
+ const Edge = require("./Edge.cjs");
5
+ const Graph = require("./Graph.cjs");
6
+ const Node = require("./Node.cjs");
7
+ const Subgraph = require("./Subgraph.cjs");
8
+ Object.assign(common.RootModelsContext, {
9
+ Graph: Graph.Graph,
10
+ Digraph: Digraph.Digraph,
11
+ Subgraph: Subgraph.Subgraph,
12
+ Node: Node.Node,
13
+ Edge: Edge.Edge
14
+ });
@@ -0,0 +1 @@
1
+ export { }
@@ -0,0 +1,13 @@
1
+ import { RootModelsContext } from "@ts-graphviz/common";
2
+ import { Digraph } from "./Digraph.js";
3
+ import { Edge } from "./Edge.js";
4
+ import { Graph } from "./Graph.js";
5
+ import { Node } from "./Node.js";
6
+ import { Subgraph } from "./Subgraph.js";
7
+ Object.assign(RootModelsContext, {
8
+ Graph,
9
+ Digraph,
10
+ Subgraph,
11
+ Node,
12
+ Edge
13
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ts-graphviz/core",
3
- "version": "0.0.0-pr956-20240225091623",
4
- "description": "",
3
+ "version": "0.0.0-pr956-20240225160253",
4
+ "description": "Graphviz Models for Object-Oriented Programming",
5
5
  "keywords": [
6
6
  "graphviz",
7
7
  "dot"
@@ -27,8 +27,27 @@
27
27
  ],
28
28
  "license": "MIT",
29
29
  "author": "Yuki Yamazaki <yuki@kamiazya.tech>",
30
- "sideEffects": true,
30
+ "sideEffects": [
31
+ "./lib/register-default.*"
32
+ ],
31
33
  "type": "module",
34
+ "exports": {
35
+ ".": {
36
+ "require": {
37
+ "types": "./lib/core.d.ts",
38
+ "default": "./lib/core.cjs"
39
+ },
40
+ "import": {
41
+ "types": "./lib/core.d.ts",
42
+ "default": "./lib/core.js"
43
+ }
44
+ },
45
+ "./register-default": {
46
+ "require": "./lib/register-default.cjs",
47
+ "default": "./lib/register-default.js"
48
+ },
49
+ "./package.json": "./package.json"
50
+ },
32
51
  "main": "lib/core.cjs",
33
52
  "module": "lib/core.js",
34
53
  "types": "lib/core.d.ts",
@@ -39,8 +58,8 @@
39
58
  "LICENSE"
40
59
  ],
41
60
  "dependencies": {
42
- "@ts-graphviz/ast": "^0.0.0-pr956-20240225091623",
43
- "@ts-graphviz/common": "^0.0.0-pr956-20240225091623"
61
+ "@ts-graphviz/ast": "^0.0.0-pr956-20240225160253",
62
+ "@ts-graphviz/common": "^0.0.0-pr956-20240225160253"
44
63
  },
45
64
  "devDependencies": {
46
65
  "typescript": "^5.3.3",