likec4 1.48.0 → 1.50.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.md +11 -1
- package/__app__/src/likec4.js +5941 -4496
- package/__app__/src/routes/index.js +3 -153
- package/__app__/src/routes/projects.js +21 -1087
- package/__app__/src/routes/single.js +1228 -16
- package/__app__/src/style.css +1 -1
- package/__app__/src/vendors.js +4649 -1897
- package/__app__/src/webcomponent.js +1 -1
- package/config/schema.json +169 -141
- package/dist/THIRD-PARTY-LICENSES.md +1769 -0
- package/dist/_chunks/LikeC4.mjs +1154 -202
- package/dist/_chunks/binary.mjs +72 -0
- package/dist/_chunks/index.d.mts +234 -140
- package/dist/_chunks/index2.d.mts +2043 -1828
- package/dist/_chunks/libs/@chevrotain/cst-dts-gen.mjs +30 -0
- package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +9 -785
- package/dist/_chunks/libs/@chevrotain/utils.mjs +1 -37
- package/dist/_chunks/libs/@hono/mcp.mjs +34 -0
- package/dist/_chunks/libs/@hono/node-server.mjs +1 -436
- package/dist/_chunks/libs/@logtape/logtape.d.mts +741 -0
- package/dist/_chunks/libs/@logtape/logtape.mjs +6 -1354
- package/dist/_chunks/libs/@lume/kiwi.mjs +1 -1355
- package/dist/_chunks/libs/@modelcontextprotocol/sdk.d.mts +114 -14
- package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +12 -25105
- package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -1503
- package/dist/_chunks/libs/@nanostores/react.d.mts +61 -1
- package/dist/_chunks/libs/@nanostores/react.mjs +1 -30
- package/dist/_chunks/libs/@smithy/is-array-buffer.mjs +1 -10
- package/dist/_chunks/libs/@smithy/util-base64.mjs +1 -100
- package/dist/_chunks/libs/ajv.mjs +1 -777
- package/dist/_chunks/libs/atomically.mjs +1 -362
- package/dist/_chunks/libs/birpc.mjs +1 -201
- package/dist/_chunks/libs/chevrotain-allstar.mjs +2 -850
- package/dist/_chunks/libs/chevrotain.mjs +55 -6229
- package/dist/_chunks/libs/conf.mjs +1 -2258
- package/dist/_chunks/libs/defu.mjs +1 -42
- package/dist/_chunks/libs/esm-env.mjs +1 -5
- package/dist/_chunks/libs/eventemitter3.mjs +1 -243
- package/dist/_chunks/libs/fast-equals.mjs +1 -446
- package/dist/_chunks/libs/find-up-simple.mjs +1 -24
- package/dist/_chunks/libs/get-port.mjs +1 -107
- package/dist/_chunks/libs/is-docker.mjs +1 -26
- package/dist/_chunks/libs/is-error-instance.mjs +1 -26
- package/dist/_chunks/libs/is-inside-container.mjs +1 -20
- package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
- package/dist/_chunks/libs/isexe.mjs +1 -127
- package/dist/_chunks/libs/json5.mjs +14 -959
- package/dist/_chunks/libs/khroma.mjs +1 -605
- package/dist/_chunks/libs/ky.mjs +2 -807
- package/dist/_chunks/libs/langium.d.mts +2913 -2876
- package/dist/_chunks/libs/langium.mjs +33 -20351
- package/dist/_chunks/libs/merge-error-cause.mjs +2 -746
- package/dist/_chunks/libs/p-limit.mjs +1 -120
- package/dist/_chunks/libs/p-queue.mjs +1 -449
- package/dist/_chunks/libs/package-manager-detector.mjs +1 -559
- package/dist/_chunks/libs/package-up.mjs +1 -10
- package/dist/_chunks/libs/pako.mjs +1 -0
- package/dist/_chunks/libs/parse-ms.mjs +1 -36
- package/dist/_chunks/libs/pathe.mjs +1 -0
- package/dist/_chunks/libs/picomatch.mjs +1 -1673
- package/dist/_chunks/libs/pretty-ms.mjs +1 -80
- package/dist/_chunks/libs/remeda.mjs +2 -690
- package/dist/_chunks/libs/safe-stringify.mjs +1 -21
- package/dist/_chunks/libs/strip-indent.mjs +1 -15
- package/dist/_chunks/libs/tinyrainbow.mjs +1 -88
- package/dist/_chunks/libs/ts-graphviz.mjs +4 -725
- package/dist/_chunks/libs/ufo.mjs +1 -240
- package/dist/_chunks/libs/which.mjs +1 -84
- package/dist/_chunks/libs/word-wrap.mjs +12 -43
- package/dist/_chunks/rolldown-runtime.mjs +1 -48
- package/dist/_chunks/sequence.mjs +1 -0
- package/dist/_chunks/src.mjs +15 -0
- package/dist/_chunks/src2.mjs +499 -0
- package/dist/cli/index.mjs +77 -1952
- package/dist/config/index.d.mts +2 -2
- package/dist/config/index.mjs +1 -6
- package/dist/index.d.mts +150 -7
- package/dist/index.mjs +1 -21
- package/dist/model/builder.mjs +1 -3
- package/dist/model/index.d.mts +57 -3
- package/dist/model/index.mjs +1 -5
- package/dist/vite-plugin/index.d.mts +7 -3
- package/dist/vite-plugin/index.mjs +1 -22
- package/dist/vite-plugin/internal.d.mts +6 -7
- package/dist/vite-plugin/internal.mjs +1 -68
- package/package.json +64 -45
- package/react/{index.d.ts → index.d.mts} +114 -72
- package/react/{index.js → index.mjs} +21320 -22041
- package/react/package.json +2 -5
- package/vite-plugin-modules.d.ts +10 -5
- package/dist/_chunks/LikeC4.d.mts +0 -121
- package/dist/_chunks/config-app.prod.d.mts +0 -18
- package/dist/_chunks/config-app.prod.mjs +0 -188
- package/dist/_chunks/config-webcomponent.prod.mjs +0 -71
- package/dist/_chunks/define-config.mjs +0 -409
- package/dist/_chunks/index3.d.mts +0 -60
- package/dist/_chunks/libs/@chevrotain/gast.mjs +0 -3969
- package/dist/_chunks/libs/hono.mjs +0 -1829
- package/dist/_chunks/libs/nanoid.mjs +0 -29
- package/dist/_chunks/libs/nanostores.d.mts +0 -63
- package/dist/_chunks/libs/nanostores.mjs +0 -198
- package/dist/_chunks/model.mjs +0 -12
- package/dist/_chunks/module.d.mts +0 -71
- package/dist/_chunks/module.mjs +0 -18657
- package/dist/_chunks/plugin.mjs +0 -996
- package/dist/_chunks/sequence-view.mjs +0 -575
- package/dist/_chunks/vite-build.mjs +0 -69
- package/dist/_chunks/vite-dev.mjs +0 -79
- package/dist/_chunks/vite-preview.mjs +0 -27
- package/dist/language/module.d.mts +0 -5
- package/dist/language/module.mjs +0 -20
- package/dist/vite/vite-build.d.mts +0 -26
- package/dist/vite/vite-build.mjs +0 -27
- package/dist/vite/vite-dev.d.mts +0 -34
- package/dist/vite/vite-dev.mjs +0 -29
- package/dist/vite/vite-preview.d.mts +0 -20
- package/dist/vite/vite-preview.mjs +0 -26
- /package/dist/_chunks/{index4.d.mts → libs/@chevrotain/types.d.mts} +0 -0
|
@@ -1,725 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
function isNodeModel(object) {
|
|
6
|
-
return typeof object === "object" && object !== null && object.$$type === "Node" && typeof object.id === "string";
|
|
7
|
-
}
|
|
8
|
-
function isNodeRef(node) {
|
|
9
|
-
return isNodeModel(node) || isForwardRefNode(node);
|
|
10
|
-
}
|
|
11
|
-
function isNodeRefLike(node) {
|
|
12
|
-
return typeof node === "string" || isNodeRef(node);
|
|
13
|
-
}
|
|
14
|
-
function isNodeRefGroupLike(target) {
|
|
15
|
-
return Array.isArray(target) && target.every(isNodeRefLike);
|
|
16
|
-
}
|
|
17
|
-
function isCompass(c) {
|
|
18
|
-
return [
|
|
19
|
-
"n",
|
|
20
|
-
"ne",
|
|
21
|
-
"e",
|
|
22
|
-
"se",
|
|
23
|
-
"s",
|
|
24
|
-
"sw",
|
|
25
|
-
"w",
|
|
26
|
-
"nw",
|
|
27
|
-
"c"
|
|
28
|
-
].includes(c);
|
|
29
|
-
}
|
|
30
|
-
function toNodeRef(target) {
|
|
31
|
-
if (isNodeRef(target)) return target;
|
|
32
|
-
const [id, port, compass] = target.split(":");
|
|
33
|
-
if (isCompass(compass)) return {
|
|
34
|
-
id,
|
|
35
|
-
port,
|
|
36
|
-
compass
|
|
37
|
-
};
|
|
38
|
-
return {
|
|
39
|
-
id,
|
|
40
|
-
port
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function toNodeRefGroup(targets) {
|
|
44
|
-
if (targets.length < 2 && (isNodeRefLike(targets[0]) && isNodeRefLike(targets[1])) === false) throw Error("EdgeTargets must have at least 2 elements.");
|
|
45
|
-
return targets.map((t) => toNodeRef(t));
|
|
46
|
-
}
|
|
47
|
-
const RootModelsContext = Object.seal({
|
|
48
|
-
Graph: null,
|
|
49
|
-
Digraph: null,
|
|
50
|
-
Subgraph: null,
|
|
51
|
-
Node: null,
|
|
52
|
-
Edge: null
|
|
53
|
-
});
|
|
54
|
-
function createModelsContext(models) {
|
|
55
|
-
return Object.assign(Object.seal(Object.assign({}, RootModelsContext)), models);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region ../../node_modules/.pnpm/ts-graphviz@1.8.2/node_modules/ts-graphviz/lib/utils/index.js
|
|
60
|
-
function _pipe(...args) {
|
|
61
|
-
const [o1, ...operations] = args;
|
|
62
|
-
return (...t) => operations.reduce((acc, f) => f(acc), o1(...t));
|
|
63
|
-
}
|
|
64
|
-
function pipe(o1, ...operations) {
|
|
65
|
-
return _pipe(o1, ...operations);
|
|
66
|
-
}
|
|
67
|
-
const defer = (fn) => (...args) => (src) => fn(src, ...args);
|
|
68
|
-
const toIterable = (f) => ({ [Symbol.iterator]: f });
|
|
69
|
-
const map = defer((src, selector) => Array.from(toIterable(function* () {
|
|
70
|
-
for (const v of src) yield selector(v);
|
|
71
|
-
})));
|
|
72
|
-
const filter = defer((src, pred) => Array.from(toIterable(function* () {
|
|
73
|
-
for (const x of src) if (pred(x)) yield x;
|
|
74
|
-
})));
|
|
75
|
-
|
|
76
|
-
//#endregion
|
|
77
|
-
//#region ../../node_modules/.pnpm/ts-graphviz@1.8.2/node_modules/ts-graphviz/lib/ast/index.js
|
|
78
|
-
var Builder = class {
|
|
79
|
-
options;
|
|
80
|
-
getLocation() {
|
|
81
|
-
return this.options?.locationFunction?.() ?? null;
|
|
82
|
-
}
|
|
83
|
-
constructor(options) {
|
|
84
|
-
this.options = options;
|
|
85
|
-
}
|
|
86
|
-
createElement(type, props, children = []) {
|
|
87
|
-
return {
|
|
88
|
-
location: this.getLocation(),
|
|
89
|
-
...props,
|
|
90
|
-
type,
|
|
91
|
-
children
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const createElement = Builder.prototype.createElement.bind(new Builder());
|
|
96
|
-
const EOL = /\r?\n/;
|
|
97
|
-
function joinBy(sep) {
|
|
98
|
-
return (value) => value.join(sep);
|
|
99
|
-
}
|
|
100
|
-
function wrapWith(wrapper) {
|
|
101
|
-
return (value) => wrapper + value + wrapper;
|
|
102
|
-
}
|
|
103
|
-
function wrapByPair(l, r) {
|
|
104
|
-
return (value) => l + value + r;
|
|
105
|
-
}
|
|
106
|
-
function leftPadWith(left) {
|
|
107
|
-
return (value) => left + value;
|
|
108
|
-
}
|
|
109
|
-
const escape = (value) => value.replace(/\r/g, "\\r").replace(/\n/g, "\\n").replace(/"/g, "\\\"");
|
|
110
|
-
const splitByLine = (value) => value.split(EOL);
|
|
111
|
-
const indent = (style, size, eol) => pipe(splitByLine, map(leftPadWith(style === "space" ? " ".repeat(size) : "\n")), joinBy(eol));
|
|
112
|
-
const endOfLine = (eol) => {
|
|
113
|
-
switch (eol) {
|
|
114
|
-
case "crlf": return "\r\n";
|
|
115
|
-
case "lf": return "\n";
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
const AttributeListPrintPlugin = {
|
|
119
|
-
match(ast) {
|
|
120
|
-
return ast.type === "AttributeList";
|
|
121
|
-
},
|
|
122
|
-
print(context, ast) {
|
|
123
|
-
if (ast.children.length === 0) return `${ast.kind.toLocaleLowerCase()} [];`;
|
|
124
|
-
const eol = endOfLine(context.endOfLine);
|
|
125
|
-
return pipe(map(context.print), joinBy(eol), indent(context.indentStyle, context.indentSize, eol), wrapByPair(`${ast.kind.toLocaleLowerCase()} [${eol}`, `${eol}];`))(ast.children);
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
const AttributePrintPlugin = {
|
|
129
|
-
match(ast) {
|
|
130
|
-
return ast.type === "Attribute";
|
|
131
|
-
},
|
|
132
|
-
print(context, ast) {
|
|
133
|
-
return `${context.print(ast.key)} = ${context.print(ast.value)};`;
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
const CommentPrintPlugin = {
|
|
137
|
-
match(ast) {
|
|
138
|
-
return ast.type === "Comment";
|
|
139
|
-
},
|
|
140
|
-
print(context, ast) {
|
|
141
|
-
const eol = endOfLine(context.endOfLine);
|
|
142
|
-
switch (ast.kind) {
|
|
143
|
-
case "Block": return pipe(splitByLine, map(leftPadWith(" * ")), joinBy(eol), wrapByPair(`/**${eol}`, `${eol} */`))(ast.value);
|
|
144
|
-
case "Macro": return pipe(splitByLine, map(leftPadWith("# ")), joinBy(eol))(ast.value);
|
|
145
|
-
default: return pipe(splitByLine, map(leftPadWith("// ")), joinBy(eol))(ast.value);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
const DotPrintPlugin = {
|
|
150
|
-
match(ast) {
|
|
151
|
-
return ast.type === "Dot";
|
|
152
|
-
},
|
|
153
|
-
print(context, ast) {
|
|
154
|
-
return ast.children.map(context.print).join(endOfLine(context.endOfLine));
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const EdgePrintPlugin = {
|
|
158
|
-
match(ast) {
|
|
159
|
-
return ast.type === "Edge";
|
|
160
|
-
},
|
|
161
|
-
print(context, ast) {
|
|
162
|
-
const targets = pipe(map(context.print), joinBy(context.directed ? " -> " : " -- "))(ast.targets);
|
|
163
|
-
if (ast.children.length === 0) return `${targets};`;
|
|
164
|
-
const eol = endOfLine(context.endOfLine);
|
|
165
|
-
return `${targets} ${pipe(map(context.print), joinBy(eol), indent(context.indentStyle, context.indentSize, eol), wrapByPair(`[${eol}`, `${eol}];`))(ast.children)}`;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
const GraphPrintPlugin = {
|
|
169
|
-
match(ast) {
|
|
170
|
-
return ast.type === "Graph";
|
|
171
|
-
},
|
|
172
|
-
print(context, ast) {
|
|
173
|
-
context.directed = ast.directed;
|
|
174
|
-
const parts = [];
|
|
175
|
-
if (ast.strict) parts.push("strict");
|
|
176
|
-
parts.push(ast.directed ? "digraph" : "graph");
|
|
177
|
-
if (ast.id) parts.push(context.print(ast.id));
|
|
178
|
-
if (ast.children.length === 0) return `${parts.join(" ")} {}`;
|
|
179
|
-
const eol = endOfLine(context.endOfLine);
|
|
180
|
-
const contents = pipe(map(context.print), joinBy(eol), indent(context.indentStyle, context.indentSize, eol), wrapByPair(`{${eol}`, `${eol}}`))(ast.children);
|
|
181
|
-
return `${parts.join(" ")} ${contents}`;
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
const quoteLiteralValue = pipe(escape, wrapWith("\""));
|
|
185
|
-
const quoteHTMLLikeLiteralValue = wrapByPair("<", ">");
|
|
186
|
-
const defaultPlugins$2 = [
|
|
187
|
-
AttributeListPrintPlugin,
|
|
188
|
-
AttributePrintPlugin,
|
|
189
|
-
CommentPrintPlugin,
|
|
190
|
-
DotPrintPlugin,
|
|
191
|
-
EdgePrintPlugin,
|
|
192
|
-
GraphPrintPlugin,
|
|
193
|
-
{
|
|
194
|
-
match(ast) {
|
|
195
|
-
return ast.type === "Literal";
|
|
196
|
-
},
|
|
197
|
-
print(context, ast) {
|
|
198
|
-
switch (ast.quoted) {
|
|
199
|
-
case "html": return quoteHTMLLikeLiteralValue(ast.value);
|
|
200
|
-
case true: return quoteLiteralValue(ast.value);
|
|
201
|
-
default: return escape(ast.value);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
match(ast) {
|
|
207
|
-
return ast.type === "Node";
|
|
208
|
-
},
|
|
209
|
-
print(context, ast) {
|
|
210
|
-
const id = context.print(ast.id);
|
|
211
|
-
if (ast.children.length === 0) return `${id};`;
|
|
212
|
-
const eol = endOfLine(context.endOfLine);
|
|
213
|
-
return `${id} ${pipe(map(context.print), joinBy(eol), indent(context.indentStyle, context.indentSize, eol), wrapByPair(`[${eol}`, `${eol}];`))(ast.children)}`;
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
match(ast) {
|
|
218
|
-
return ast.type === "NodeRefGroup";
|
|
219
|
-
},
|
|
220
|
-
print(context, ast) {
|
|
221
|
-
return pipe(map(context.print), joinBy(" "), wrapByPair("{", "}"))(ast.children);
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
match(ast) {
|
|
226
|
-
return ast.type === "NodeRef";
|
|
227
|
-
},
|
|
228
|
-
print(context, ast) {
|
|
229
|
-
const parts = [context.print(ast.id)];
|
|
230
|
-
if (ast.port) parts.push(context.print(ast.port));
|
|
231
|
-
if (ast.compass) parts.push(context.print(ast.compass));
|
|
232
|
-
return parts.join(":");
|
|
233
|
-
}
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
match(ast) {
|
|
237
|
-
return ast.type === "Subgraph";
|
|
238
|
-
},
|
|
239
|
-
print(context, ast) {
|
|
240
|
-
const parts = ["subgraph"];
|
|
241
|
-
if (ast.id) parts.push(context.print(ast.id));
|
|
242
|
-
if (ast.children.length === 0) return `${parts.join(" ")} {}`;
|
|
243
|
-
const eol = endOfLine(context.endOfLine);
|
|
244
|
-
const contents = pipe(map(context.print), joinBy(eol), indent(context.indentStyle, context.indentSize, eol), wrapByPair(`{${eol}`, `${eol}}`))(ast.children);
|
|
245
|
-
return `${parts.join(" ")} ${contents}`;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
];
|
|
249
|
-
var Printer = class {
|
|
250
|
-
options;
|
|
251
|
-
#plugins = [...defaultPlugins$2];
|
|
252
|
-
constructor(options = {}) {
|
|
253
|
-
this.options = options;
|
|
254
|
-
}
|
|
255
|
-
print(ast) {
|
|
256
|
-
const plugins = [...this.#plugins];
|
|
257
|
-
const { indentSize = 2, indentStyle = "space", endOfLine = "lf" } = this.options;
|
|
258
|
-
const context = {
|
|
259
|
-
directed: true,
|
|
260
|
-
indentSize,
|
|
261
|
-
indentStyle,
|
|
262
|
-
endOfLine,
|
|
263
|
-
print(a) {
|
|
264
|
-
for (const plugin of plugins) if (plugin.match(a)) return plugin.print(context, a);
|
|
265
|
-
throw Error();
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
return context.print(ast);
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
function stringify(ast, options) {
|
|
272
|
-
const result = new Printer(options).print(ast);
|
|
273
|
-
if (!result) throw new Error();
|
|
274
|
-
return result;
|
|
275
|
-
}
|
|
276
|
-
function convertAttribute(key, value) {
|
|
277
|
-
if (typeof value === "string") {
|
|
278
|
-
const trimmed = value.trim();
|
|
279
|
-
if (/^<.+>$/ms.test(trimmed)) return createElement("Attribute", {
|
|
280
|
-
key: createElement("Literal", {
|
|
281
|
-
value: key,
|
|
282
|
-
quoted: false
|
|
283
|
-
}, []),
|
|
284
|
-
value: createElement("Literal", {
|
|
285
|
-
value: trimmed.slice(1, trimmed.length - 1),
|
|
286
|
-
quoted: "html"
|
|
287
|
-
}, [])
|
|
288
|
-
}, []);
|
|
289
|
-
else return createElement("Attribute", {
|
|
290
|
-
key: createElement("Literal", {
|
|
291
|
-
value: key,
|
|
292
|
-
quoted: false
|
|
293
|
-
}, []),
|
|
294
|
-
value: createElement("Literal", {
|
|
295
|
-
value,
|
|
296
|
-
quoted: true
|
|
297
|
-
}, [])
|
|
298
|
-
}, []);
|
|
299
|
-
}
|
|
300
|
-
return createElement("Attribute", {
|
|
301
|
-
key: createElement("Literal", {
|
|
302
|
-
value: key,
|
|
303
|
-
quoted: false
|
|
304
|
-
}, []),
|
|
305
|
-
value: createElement("Literal", {
|
|
306
|
-
value: String(value),
|
|
307
|
-
quoted: false
|
|
308
|
-
}, [])
|
|
309
|
-
}, []);
|
|
310
|
-
}
|
|
311
|
-
function convertComment(value, kind) {
|
|
312
|
-
return createElement("Comment", {
|
|
313
|
-
kind,
|
|
314
|
-
value
|
|
315
|
-
}, []);
|
|
316
|
-
}
|
|
317
|
-
function convertClusterChildren(context, model) {
|
|
318
|
-
return Array.from((function* () {
|
|
319
|
-
for (const [key, value] of model.values) yield convertAttribute(key, value);
|
|
320
|
-
for (const attrs of Object.values(model.attributes)) if (attrs.size > 0) {
|
|
321
|
-
if (attrs.comment) yield convertComment(attrs.comment, context.commentKind);
|
|
322
|
-
yield context.convert(attrs);
|
|
323
|
-
}
|
|
324
|
-
for (const node of model.nodes) {
|
|
325
|
-
if (node.comment) yield convertComment(node.comment, context.commentKind);
|
|
326
|
-
yield context.convert(node);
|
|
327
|
-
}
|
|
328
|
-
for (const subgraph of model.subgraphs) {
|
|
329
|
-
if (subgraph.comment) yield convertComment(subgraph.comment, context.commentKind);
|
|
330
|
-
yield context.convert(subgraph);
|
|
331
|
-
}
|
|
332
|
-
for (const edge of model.edges) {
|
|
333
|
-
if (edge.comment) yield convertComment(edge.comment, context.commentKind);
|
|
334
|
-
yield context.convert(edge);
|
|
335
|
-
}
|
|
336
|
-
})());
|
|
337
|
-
}
|
|
338
|
-
const defaultPlugins$1 = [
|
|
339
|
-
{
|
|
340
|
-
match(model) {
|
|
341
|
-
return model.$$type === "AttributeList";
|
|
342
|
-
},
|
|
343
|
-
convert(context, model) {
|
|
344
|
-
return createElement("AttributeList", { kind: model.$$kind }, model.values.map(([key, value]) => convertAttribute(key, value)));
|
|
345
|
-
}
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
match(model) {
|
|
349
|
-
return model.$$type === "Edge";
|
|
350
|
-
},
|
|
351
|
-
convert(context, model) {
|
|
352
|
-
return createElement("Edge", { targets: model.targets.map((target) => {
|
|
353
|
-
if (isNodeModel(target)) return createElement("NodeRef", { id: createElement("Literal", {
|
|
354
|
-
value: target.id,
|
|
355
|
-
quoted: true
|
|
356
|
-
}, []) }, []);
|
|
357
|
-
else if (isForwardRefNode(target)) return createElement("NodeRef", {
|
|
358
|
-
id: createElement("Literal", {
|
|
359
|
-
value: target.id,
|
|
360
|
-
quoted: true
|
|
361
|
-
}, []),
|
|
362
|
-
port: target.port ? createElement("Literal", {
|
|
363
|
-
value: target.port,
|
|
364
|
-
quoted: true
|
|
365
|
-
}, []) : void 0,
|
|
366
|
-
compass: target.compass ? createElement("Literal", {
|
|
367
|
-
value: target.compass,
|
|
368
|
-
quoted: true
|
|
369
|
-
}, []) : void 0
|
|
370
|
-
}, []);
|
|
371
|
-
else return createElement("NodeRefGroup", {}, target.map((n) => {
|
|
372
|
-
if (isNodeModel(n)) return createElement("NodeRef", { id: createElement("Literal", {
|
|
373
|
-
value: n.id,
|
|
374
|
-
quoted: true
|
|
375
|
-
}, []) }, []);
|
|
376
|
-
return createElement("NodeRef", {
|
|
377
|
-
id: createElement("Literal", {
|
|
378
|
-
value: n.id,
|
|
379
|
-
quoted: true
|
|
380
|
-
}, []),
|
|
381
|
-
port: n.port ? createElement("Literal", {
|
|
382
|
-
value: n.port,
|
|
383
|
-
quoted: true
|
|
384
|
-
}, []) : void 0,
|
|
385
|
-
compass: n.compass ? createElement("Literal", {
|
|
386
|
-
value: n.compass,
|
|
387
|
-
quoted: true
|
|
388
|
-
}, []) : void 0
|
|
389
|
-
}, []);
|
|
390
|
-
}));
|
|
391
|
-
}) }, [...model.attributes.comment ? [convertComment(model.attributes.comment, context.commentKind)] : [], ...model.attributes.values.map(([key, value]) => convertAttribute(key, value))]);
|
|
392
|
-
}
|
|
393
|
-
},
|
|
394
|
-
{
|
|
395
|
-
match(model) {
|
|
396
|
-
return model.$$type === "Node";
|
|
397
|
-
},
|
|
398
|
-
convert(context, model) {
|
|
399
|
-
return createElement("Node", { id: createElement("Literal", {
|
|
400
|
-
value: model.id,
|
|
401
|
-
quoted: true
|
|
402
|
-
}, []) }, [...model.attributes.comment ? [convertComment(model.attributes.comment, context.commentKind)] : [], ...model.attributes.values.map(([key, value]) => convertAttribute(key, value))]);
|
|
403
|
-
}
|
|
404
|
-
},
|
|
405
|
-
{
|
|
406
|
-
match(model) {
|
|
407
|
-
return model.$$type === "Graph";
|
|
408
|
-
},
|
|
409
|
-
convert(context, model) {
|
|
410
|
-
return createElement("Dot", {}, [...model.comment ? [convertComment(model.comment, context.commentKind)] : [], createElement("Graph", {
|
|
411
|
-
directed: model.directed,
|
|
412
|
-
strict: model.strict,
|
|
413
|
-
id: model.id ? createElement("Literal", {
|
|
414
|
-
value: model.id,
|
|
415
|
-
quoted: true
|
|
416
|
-
}, []) : void 0
|
|
417
|
-
}, convertClusterChildren(context, model))]);
|
|
418
|
-
}
|
|
419
|
-
},
|
|
420
|
-
{
|
|
421
|
-
match(model) {
|
|
422
|
-
return model.$$type === "Subgraph";
|
|
423
|
-
},
|
|
424
|
-
convert(context, model) {
|
|
425
|
-
return createElement("Subgraph", { id: model.id ? createElement("Literal", {
|
|
426
|
-
value: model.id,
|
|
427
|
-
quoted: true
|
|
428
|
-
}, []) : void 0 }, convertClusterChildren(context, model));
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
];
|
|
432
|
-
var FromModelConverter = class {
|
|
433
|
-
options;
|
|
434
|
-
#plugins = [...defaultPlugins$1];
|
|
435
|
-
constructor(options = {}) {
|
|
436
|
-
this.options = options;
|
|
437
|
-
}
|
|
438
|
-
convert(model) {
|
|
439
|
-
const plugins = [...this.#plugins];
|
|
440
|
-
const { commentKind = "Slash" } = this.options;
|
|
441
|
-
const context = {
|
|
442
|
-
commentKind,
|
|
443
|
-
convert(m) {
|
|
444
|
-
for (const plugin of plugins) if (plugin.match(m)) return plugin.convert(context, m);
|
|
445
|
-
throw Error();
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
return context.convert(model);
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
function fromModel(model, options) {
|
|
452
|
-
return new FromModelConverter(options).convert(model);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
//#endregion
|
|
456
|
-
//#region ../../node_modules/.pnpm/ts-graphviz@1.8.2/node_modules/ts-graphviz/lib/core/index.js
|
|
457
|
-
const attribute = new Proxy(Object.freeze({}), { get: (_, key) => key });
|
|
458
|
-
var DotObject = class {};
|
|
459
|
-
var AttributesBase = class extends DotObject {
|
|
460
|
-
#attrs = /* @__PURE__ */ new Map();
|
|
461
|
-
constructor(attributes) {
|
|
462
|
-
super();
|
|
463
|
-
if (attributes !== void 0) this.apply(attributes);
|
|
464
|
-
}
|
|
465
|
-
get values() {
|
|
466
|
-
return Array.from(this.#attrs.entries());
|
|
467
|
-
}
|
|
468
|
-
get size() {
|
|
469
|
-
return this.#attrs.size;
|
|
470
|
-
}
|
|
471
|
-
get(key) {
|
|
472
|
-
return this.#attrs.get(key);
|
|
473
|
-
}
|
|
474
|
-
set(key, value) {
|
|
475
|
-
if (value !== null && value !== void 0) this.#attrs.set(key, value);
|
|
476
|
-
}
|
|
477
|
-
delete(key) {
|
|
478
|
-
this.#attrs.delete(key);
|
|
479
|
-
}
|
|
480
|
-
apply(attributes) {
|
|
481
|
-
const entries = Array.isArray(attributes) ? attributes : Object.entries(attributes);
|
|
482
|
-
for (const [key, value] of entries) this.set(key, value);
|
|
483
|
-
}
|
|
484
|
-
clear() {
|
|
485
|
-
this.#attrs.clear();
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
var AttributeList = class extends AttributesBase {
|
|
489
|
-
$$kind;
|
|
490
|
-
get $$type() {
|
|
491
|
-
return "AttributeList";
|
|
492
|
-
}
|
|
493
|
-
comment;
|
|
494
|
-
constructor($$kind, attributes) {
|
|
495
|
-
super(attributes);
|
|
496
|
-
this.$$kind = $$kind;
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
var GraphBase = class extends AttributesBase {
|
|
500
|
-
#models = RootModelsContext;
|
|
501
|
-
id;
|
|
502
|
-
comment;
|
|
503
|
-
attributes = Object.freeze({
|
|
504
|
-
graph: new AttributeList("Graph"),
|
|
505
|
-
edge: new AttributeList("Edge"),
|
|
506
|
-
node: new AttributeList("Node")
|
|
507
|
-
});
|
|
508
|
-
get nodes() {
|
|
509
|
-
return Array.from(this.#objects.nodes.values());
|
|
510
|
-
}
|
|
511
|
-
get edges() {
|
|
512
|
-
return Array.from(this.#objects.edges.values());
|
|
513
|
-
}
|
|
514
|
-
get subgraphs() {
|
|
515
|
-
return Array.from(this.#objects.subgraphs.values());
|
|
516
|
-
}
|
|
517
|
-
#objects = {
|
|
518
|
-
nodes: /* @__PURE__ */ new Map(),
|
|
519
|
-
edges: /* @__PURE__ */ new Set(),
|
|
520
|
-
subgraphs: /* @__PURE__ */ new Set()
|
|
521
|
-
};
|
|
522
|
-
with(models) {
|
|
523
|
-
this.#models = createModelsContext(models);
|
|
524
|
-
}
|
|
525
|
-
addNode(node) {
|
|
526
|
-
this.#objects.nodes.set(node.id, node);
|
|
527
|
-
}
|
|
528
|
-
addEdge(edge) {
|
|
529
|
-
this.#objects.edges.add(edge);
|
|
530
|
-
}
|
|
531
|
-
addSubgraph(subgraph) {
|
|
532
|
-
this.#objects.subgraphs.add(subgraph);
|
|
533
|
-
}
|
|
534
|
-
existNode(nodeId) {
|
|
535
|
-
return this.#objects.nodes.has(nodeId);
|
|
536
|
-
}
|
|
537
|
-
existEdge(edge) {
|
|
538
|
-
return this.#objects.edges.has(edge);
|
|
539
|
-
}
|
|
540
|
-
existSubgraph(subgraph) {
|
|
541
|
-
return this.#objects.subgraphs.has(subgraph);
|
|
542
|
-
}
|
|
543
|
-
createSubgraph(...args) {
|
|
544
|
-
const subgraph = new this.#models.Subgraph(...args);
|
|
545
|
-
subgraph.with(this.#models);
|
|
546
|
-
this.addSubgraph(subgraph);
|
|
547
|
-
return subgraph;
|
|
548
|
-
}
|
|
549
|
-
removeNode(node) {
|
|
550
|
-
this.#objects.nodes.delete(typeof node === "string" ? node : node.id);
|
|
551
|
-
}
|
|
552
|
-
removeEdge(edge) {
|
|
553
|
-
this.#objects.edges.delete(edge);
|
|
554
|
-
}
|
|
555
|
-
removeSubgraph(subgraph) {
|
|
556
|
-
this.#objects.subgraphs.delete(subgraph);
|
|
557
|
-
}
|
|
558
|
-
createNode(id, attributes) {
|
|
559
|
-
const node = new this.#models.Node(id, attributes);
|
|
560
|
-
this.addNode(node);
|
|
561
|
-
return node;
|
|
562
|
-
}
|
|
563
|
-
getSubgraph(id) {
|
|
564
|
-
return Array.from(this.#objects.subgraphs.values()).find((subgraph) => subgraph.id === id);
|
|
565
|
-
}
|
|
566
|
-
getNode(id) {
|
|
567
|
-
return this.#objects.nodes.get(id);
|
|
568
|
-
}
|
|
569
|
-
createEdge(targets, attributes) {
|
|
570
|
-
const ts = targets.map((t) => isNodeRefGroupLike(t) ? toNodeRefGroup(t) : toNodeRef(t));
|
|
571
|
-
const edge = new this.#models.Edge(ts, attributes);
|
|
572
|
-
this.addEdge(edge);
|
|
573
|
-
return edge;
|
|
574
|
-
}
|
|
575
|
-
subgraph(...args) {
|
|
576
|
-
const id = args.find((arg) => typeof arg === "string");
|
|
577
|
-
const attributes = args.find((arg) => typeof arg === "object" && arg !== null);
|
|
578
|
-
const callback = args.find((arg) => typeof arg === "function");
|
|
579
|
-
const subgraph = id ? this.getSubgraph(id) ?? this.createSubgraph(id) : this.createSubgraph();
|
|
580
|
-
if (attributes !== void 0) subgraph.apply(attributes);
|
|
581
|
-
if (callback !== void 0) callback(subgraph);
|
|
582
|
-
return subgraph;
|
|
583
|
-
}
|
|
584
|
-
node(firstArg, ...args) {
|
|
585
|
-
if (typeof firstArg === "string") {
|
|
586
|
-
const id = firstArg;
|
|
587
|
-
const attributes = args.find((arg) => typeof arg === "object" && arg !== null);
|
|
588
|
-
const callback = args.find((arg) => typeof arg === "function");
|
|
589
|
-
const node = this.getNode(id) ?? this.createNode(id);
|
|
590
|
-
if (attributes !== void 0) node.attributes.apply(attributes);
|
|
591
|
-
if (callback !== void 0) callback(node);
|
|
592
|
-
return node;
|
|
593
|
-
}
|
|
594
|
-
if (typeof firstArg === "object" && firstArg !== null) this.attributes.node.apply(firstArg);
|
|
595
|
-
}
|
|
596
|
-
edge(firstArg, ...args) {
|
|
597
|
-
if (Array.isArray(firstArg)) {
|
|
598
|
-
const targets = firstArg;
|
|
599
|
-
const attributes = args.find((arg) => typeof arg === "object");
|
|
600
|
-
const callback = args.find((arg) => typeof arg === "function");
|
|
601
|
-
const edge = this.createEdge(targets, attributes);
|
|
602
|
-
if (callback !== void 0) callback(edge);
|
|
603
|
-
return edge;
|
|
604
|
-
}
|
|
605
|
-
if (typeof firstArg === "object" && firstArg !== null) this.attributes.edge.apply(firstArg);
|
|
606
|
-
}
|
|
607
|
-
graph(attributes) {
|
|
608
|
-
this.attributes.graph.apply(attributes);
|
|
609
|
-
}
|
|
610
|
-
};
|
|
611
|
-
var RootGraph = class extends GraphBase {
|
|
612
|
-
get $$type() {
|
|
613
|
-
return "Graph";
|
|
614
|
-
}
|
|
615
|
-
id;
|
|
616
|
-
strict;
|
|
617
|
-
constructor(...args) {
|
|
618
|
-
super();
|
|
619
|
-
this.id = args.find((arg) => typeof arg === "string");
|
|
620
|
-
this.strict = args.find((arg) => typeof arg === "boolean") ?? false;
|
|
621
|
-
const attributes = args.find((arg) => typeof arg === "object" && arg !== null);
|
|
622
|
-
if (attributes !== void 0) this.apply(attributes);
|
|
623
|
-
}
|
|
624
|
-
};
|
|
625
|
-
var Digraph = class extends RootGraph {
|
|
626
|
-
get directed() {
|
|
627
|
-
return true;
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
var Graph = class extends RootGraph {
|
|
631
|
-
get directed() {
|
|
632
|
-
return false;
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
var Subgraph = class extends GraphBase {
|
|
636
|
-
get $$type() {
|
|
637
|
-
return "Subgraph";
|
|
638
|
-
}
|
|
639
|
-
id;
|
|
640
|
-
constructor(...args) {
|
|
641
|
-
super();
|
|
642
|
-
this.id = args.find((arg) => typeof arg === "string");
|
|
643
|
-
const attributes = args.find((arg) => typeof arg === "object" && arg !== null);
|
|
644
|
-
if (attributes !== void 0) this.apply(attributes);
|
|
645
|
-
}
|
|
646
|
-
isSubgraphCluster() {
|
|
647
|
-
if (typeof this.id === "string") return this.id.startsWith("cluster");
|
|
648
|
-
return false;
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
|
-
var AttributesGroup = class extends AttributesBase {
|
|
652
|
-
comment;
|
|
653
|
-
};
|
|
654
|
-
var Node = class extends DotObject {
|
|
655
|
-
id;
|
|
656
|
-
get $$type() {
|
|
657
|
-
return "Node";
|
|
658
|
-
}
|
|
659
|
-
comment;
|
|
660
|
-
attributes;
|
|
661
|
-
constructor(id, attributes) {
|
|
662
|
-
super();
|
|
663
|
-
this.id = id;
|
|
664
|
-
this.attributes = new AttributesGroup(attributes);
|
|
665
|
-
}
|
|
666
|
-
port(port) {
|
|
667
|
-
if (typeof port === "string") return {
|
|
668
|
-
id: this.id,
|
|
669
|
-
port
|
|
670
|
-
};
|
|
671
|
-
return {
|
|
672
|
-
id: this.id,
|
|
673
|
-
...port
|
|
674
|
-
};
|
|
675
|
-
}
|
|
676
|
-
};
|
|
677
|
-
var Edge = class extends DotObject {
|
|
678
|
-
targets;
|
|
679
|
-
get $$type() {
|
|
680
|
-
return "Edge";
|
|
681
|
-
}
|
|
682
|
-
comment;
|
|
683
|
-
attributes;
|
|
684
|
-
constructor(targets, attributes) {
|
|
685
|
-
super();
|
|
686
|
-
this.targets = targets;
|
|
687
|
-
if (targets.length < 2 && (isNodeRefLike(targets[0]) && isNodeRefLike(targets[1])) === false) throw Error("The element of Edge target is missing or not satisfied as Edge target.");
|
|
688
|
-
this.attributes = new AttributesGroup(attributes);
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
Object.assign(RootModelsContext, {
|
|
692
|
-
Graph,
|
|
693
|
-
Digraph,
|
|
694
|
-
Subgraph,
|
|
695
|
-
Node,
|
|
696
|
-
Edge
|
|
697
|
-
});
|
|
698
|
-
function ModelFactoryBuilder(directed, strictMode) {
|
|
699
|
-
return (...args) => {
|
|
700
|
-
const G = directed ? this.Digraph : this.Graph;
|
|
701
|
-
const id = args.find((arg) => typeof arg === "string");
|
|
702
|
-
const attributes = args.find((arg) => typeof arg === "object");
|
|
703
|
-
const callback = args.find((arg) => typeof arg === "function");
|
|
704
|
-
const g = new G(id, strictMode, attributes);
|
|
705
|
-
g.with(this);
|
|
706
|
-
if (typeof callback === "function") callback(g);
|
|
707
|
-
return g;
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
function createModelFactories(strict, context = RootModelsContext) {
|
|
711
|
-
return Object.freeze({
|
|
712
|
-
digraph: ModelFactoryBuilder.call(context, true, strict),
|
|
713
|
-
graph: ModelFactoryBuilder.call(context, false, strict)
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
const noStrict = createModelFactories(false);
|
|
717
|
-
const digraph = noStrict.digraph;
|
|
718
|
-
const graph = noStrict.graph;
|
|
719
|
-
const strict = createModelFactories(true);
|
|
720
|
-
function toDot(model, options) {
|
|
721
|
-
return stringify(fromModel(model, options?.convert), options?.print);
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
//#endregion
|
|
725
|
-
export { digraph as n, toDot as r, attribute as t };
|
|
1
|
+
function e(e){return typeof e==`object`&&!!e&&typeof e.id==`string`}function t(e){return typeof e==`object`&&!!e&&e.$$type===`Node`&&typeof e.id==`string`}function n(n){return t(n)||e(n)}function r(e){return typeof e==`string`||n(e)}function i(e){return Array.isArray(e)&&e.every(r)}function a(e){return[`n`,`ne`,`e`,`se`,`s`,`sw`,`w`,`nw`,`c`].includes(e)}function o(e){if(n(e))return e;let[t,r,i]=e.split(`:`);return a(i)?{id:t,port:r,compass:i}:{id:t,port:r}}function s(e){if(e.length<2&&(r(e[0])&&r(e[1]))===!1)throw Error(`EdgeTargets must have at least 2 elements.`);return e.map(e=>o(e))}const c=Object.seal({Graph:null,Digraph:null,Subgraph:null,Node:null,Edge:null});function l(e){return Object.assign(Object.seal(Object.assign({},c)),e)}function u(...e){let[t,...n]=e;return(...e)=>n.reduce((e,t)=>t(e),t(...e))}function d(e,...t){return u(e,...t)}const f=e=>(...t)=>n=>e(n,...t),p=e=>({[Symbol.iterator]:e}),m=f((e,t)=>Array.from(p(function*(){for(let n of e)yield t(n)})));var h=class{options;getLocation(){return this.options?.locationFunction?.()??null}constructor(e){this.options=e}createElement(e,t,n=[]){return{location:this.getLocation(),...t,type:e,children:n}}};const g=h.prototype.createElement.bind(new h),_=/\r?\n/;function v(e){return t=>t.join(e)}function y(e){return t=>e+t+e}function b(e,t){return n=>e+n+t}function x(e){return t=>e+t}const S=e=>e.replace(/\r/g,`\\r`).replace(/\n/g,`\\n`).replace(/"/g,`\\"`),C=e=>e.split(_),w=(e,t,n)=>d(C,m(x(e===`space`?` `.repeat(t):`
|
|
2
|
+
`)),v(n)),T=e=>{switch(e){case`crlf`:return`\r
|
|
3
|
+
`;case`lf`:return`
|
|
4
|
+
`}},E={match(e){return e.type===`AttributeList`},print(e,t){if(t.children.length===0)return`${t.kind.toLocaleLowerCase()} [];`;let n=T(e.endOfLine);return d(m(e.print),v(n),w(e.indentStyle,e.indentSize,n),b(`${t.kind.toLocaleLowerCase()} [${n}`,`${n}];`))(t.children)}},D={match(e){return e.type===`Attribute`},print(e,t){return`${e.print(t.key)} = ${e.print(t.value)};`}},O={match(e){return e.type===`Comment`},print(e,t){let n=T(e.endOfLine);switch(t.kind){case`Block`:return d(C,m(x(` * `)),v(n),b(`/**${n}`,`${n} */`))(t.value);case`Macro`:return d(C,m(x(`# `)),v(n))(t.value);default:return d(C,m(x(`// `)),v(n))(t.value)}}},k={match(e){return e.type===`Dot`},print(e,t){return t.children.map(e.print).join(T(e.endOfLine))}},ee={match(e){return e.type===`Edge`},print(e,t){let n=d(m(e.print),v(e.directed?` -> `:` -- `))(t.targets);if(t.children.length===0)return`${n};`;let r=T(e.endOfLine);return`${n} ${d(m(e.print),v(r),w(e.indentStyle,e.indentSize,r),b(`[${r}`,`${r}];`))(t.children)}`}},te={match(e){return e.type===`Graph`},print(e,t){e.directed=t.directed;let n=[];if(t.strict&&n.push(`strict`),n.push(t.directed?`digraph`:`graph`),t.id&&n.push(e.print(t.id)),t.children.length===0)return`${n.join(` `)} {}`;let r=T(e.endOfLine),i=d(m(e.print),v(r),w(e.indentStyle,e.indentSize,r),b(`{${r}`,`${r}}`))(t.children);return`${n.join(` `)} ${i}`}},ne=d(S,y(`"`)),A=b(`<`,`>`),j=[E,D,O,k,ee,te,{match(e){return e.type===`Literal`},print(e,t){switch(t.quoted){case`html`:return A(t.value);case!0:return ne(t.value);default:return S(t.value)}}},{match(e){return e.type===`Node`},print(e,t){let n=e.print(t.id);if(t.children.length===0)return`${n};`;let r=T(e.endOfLine);return`${n} ${d(m(e.print),v(r),w(e.indentStyle,e.indentSize,r),b(`[${r}`,`${r}];`))(t.children)}`}},{match(e){return e.type===`NodeRefGroup`},print(e,t){return d(m(e.print),v(` `),b(`{`,`}`))(t.children)}},{match(e){return e.type===`NodeRef`},print(e,t){let n=[e.print(t.id)];return t.port&&n.push(e.print(t.port)),t.compass&&n.push(e.print(t.compass)),n.join(`:`)}},{match(e){return e.type===`Subgraph`},print(e,t){let n=[`subgraph`];if(t.id&&n.push(e.print(t.id)),t.children.length===0)return`${n.join(` `)} {}`;let r=T(e.endOfLine),i=d(m(e.print),v(r),w(e.indentStyle,e.indentSize,r),b(`{${r}`,`${r}}`))(t.children);return`${n.join(` `)} ${i}`}}];var M=class{options;#e=[...j];constructor(e={}){this.options=e}print(e){let t=[...this.#e],{indentSize:n=2,indentStyle:r=`space`,endOfLine:i=`lf`}=this.options,a={directed:!0,indentSize:n,indentStyle:r,endOfLine:i,print(e){for(let n of t)if(n.match(e))return n.print(a,e);throw Error()}};return a.print(e)}};function N(e,t){let n=new M(t).print(e);if(!n)throw Error();return n}function P(e,t){if(typeof t==`string`){let n=t.trim();return/^<.+>$/ms.test(n)?g(`Attribute`,{key:g(`Literal`,{value:e,quoted:!1},[]),value:g(`Literal`,{value:n.slice(1,n.length-1),quoted:`html`},[])},[]):g(`Attribute`,{key:g(`Literal`,{value:e,quoted:!1},[]),value:g(`Literal`,{value:t,quoted:!0},[])},[])}return g(`Attribute`,{key:g(`Literal`,{value:e,quoted:!1},[]),value:g(`Literal`,{value:String(t),quoted:!1},[])},[])}function F(e,t){return g(`Comment`,{kind:t,value:e},[])}function I(e,t){return Array.from((function*(){for(let[e,n]of t.values)yield P(e,n);for(let n of Object.values(t.attributes))n.size>0&&(n.comment&&(yield F(n.comment,e.commentKind)),yield e.convert(n));for(let n of t.nodes)n.comment&&(yield F(n.comment,e.commentKind)),yield e.convert(n);for(let n of t.subgraphs)n.comment&&(yield F(n.comment,e.commentKind)),yield e.convert(n);for(let n of t.edges)n.comment&&(yield F(n.comment,e.commentKind)),yield e.convert(n)})())}const L=[{match(e){return e.$$type===`AttributeList`},convert(e,t){return g(`AttributeList`,{kind:t.$$kind},t.values.map(([e,t])=>P(e,t)))}},{match(e){return e.$$type===`Edge`},convert(n,r){return g(`Edge`,{targets:r.targets.map(n=>t(n)?g(`NodeRef`,{id:g(`Literal`,{value:n.id,quoted:!0},[])},[]):e(n)?g(`NodeRef`,{id:g(`Literal`,{value:n.id,quoted:!0},[]),port:n.port?g(`Literal`,{value:n.port,quoted:!0},[]):void 0,compass:n.compass?g(`Literal`,{value:n.compass,quoted:!0},[]):void 0},[]):g(`NodeRefGroup`,{},n.map(e=>t(e)?g(`NodeRef`,{id:g(`Literal`,{value:e.id,quoted:!0},[])},[]):g(`NodeRef`,{id:g(`Literal`,{value:e.id,quoted:!0},[]),port:e.port?g(`Literal`,{value:e.port,quoted:!0},[]):void 0,compass:e.compass?g(`Literal`,{value:e.compass,quoted:!0},[]):void 0},[]))))},[...r.attributes.comment?[F(r.attributes.comment,n.commentKind)]:[],...r.attributes.values.map(([e,t])=>P(e,t))])}},{match(e){return e.$$type===`Node`},convert(e,t){return g(`Node`,{id:g(`Literal`,{value:t.id,quoted:!0},[])},[...t.attributes.comment?[F(t.attributes.comment,e.commentKind)]:[],...t.attributes.values.map(([e,t])=>P(e,t))])}},{match(e){return e.$$type===`Graph`},convert(e,t){return g(`Dot`,{},[...t.comment?[F(t.comment,e.commentKind)]:[],g(`Graph`,{directed:t.directed,strict:t.strict,id:t.id?g(`Literal`,{value:t.id,quoted:!0},[]):void 0},I(e,t))])}},{match(e){return e.$$type===`Subgraph`},convert(e,t){return g(`Subgraph`,{id:t.id?g(`Literal`,{value:t.id,quoted:!0},[]):void 0},I(e,t))}}];var R=class{options;#e=[...L];constructor(e={}){this.options=e}convert(e){let t=[...this.#e],{commentKind:n=`Slash`}=this.options,r={commentKind:n,convert(e){for(let n of t)if(n.match(e))return n.convert(r,e);throw Error()}};return r.convert(e)}};function z(e,t){return new R(t).convert(e)}const B=new Proxy(Object.freeze({}),{get:(e,t)=>t});var V=class{},H=class extends V{#e=new Map;constructor(e){super(),e!==void 0&&this.apply(e)}get values(){return Array.from(this.#e.entries())}get size(){return this.#e.size}get(e){return this.#e.get(e)}set(e,t){t!=null&&this.#e.set(e,t)}delete(e){this.#e.delete(e)}apply(e){let t=Array.isArray(e)?e:Object.entries(e);for(let[e,n]of t)this.set(e,n)}clear(){this.#e.clear()}},U=class extends H{$$kind;get $$type(){return`AttributeList`}comment;constructor(e,t){super(t),this.$$kind=e}},W=class extends H{#e=c;id;comment;attributes=Object.freeze({graph:new U(`Graph`),edge:new U(`Edge`),node:new U(`Node`)});get nodes(){return Array.from(this.#t.nodes.values())}get edges(){return Array.from(this.#t.edges.values())}get subgraphs(){return Array.from(this.#t.subgraphs.values())}#t={nodes:new Map,edges:new Set,subgraphs:new Set};with(e){this.#e=l(e)}addNode(e){this.#t.nodes.set(e.id,e)}addEdge(e){this.#t.edges.add(e)}addSubgraph(e){this.#t.subgraphs.add(e)}existNode(e){return this.#t.nodes.has(e)}existEdge(e){return this.#t.edges.has(e)}existSubgraph(e){return this.#t.subgraphs.has(e)}createSubgraph(...e){let t=new this.#e.Subgraph(...e);return t.with(this.#e),this.addSubgraph(t),t}removeNode(e){this.#t.nodes.delete(typeof e==`string`?e:e.id)}removeEdge(e){this.#t.edges.delete(e)}removeSubgraph(e){this.#t.subgraphs.delete(e)}createNode(e,t){let n=new this.#e.Node(e,t);return this.addNode(n),n}getSubgraph(e){return Array.from(this.#t.subgraphs.values()).find(t=>t.id===e)}getNode(e){return this.#t.nodes.get(e)}createEdge(e,t){let n=e.map(e=>i(e)?s(e):o(e)),r=new this.#e.Edge(n,t);return this.addEdge(r),r}subgraph(...e){let t=e.find(e=>typeof e==`string`),n=e.find(e=>typeof e==`object`&&!!e),r=e.find(e=>typeof e==`function`),i=t?this.getSubgraph(t)??this.createSubgraph(t):this.createSubgraph();return n!==void 0&&i.apply(n),r!==void 0&&r(i),i}node(e,...t){if(typeof e==`string`){let n=e,r=t.find(e=>typeof e==`object`&&!!e),i=t.find(e=>typeof e==`function`),a=this.getNode(n)??this.createNode(n);return r!==void 0&&a.attributes.apply(r),i!==void 0&&i(a),a}typeof e==`object`&&e&&this.attributes.node.apply(e)}edge(e,...t){if(Array.isArray(e)){let n=e,r=t.find(e=>typeof e==`object`),i=t.find(e=>typeof e==`function`),a=this.createEdge(n,r);return i!==void 0&&i(a),a}typeof e==`object`&&e&&this.attributes.edge.apply(e)}graph(e){this.attributes.graph.apply(e)}},G=class extends W{get $$type(){return`Graph`}id;strict;constructor(...e){super(),this.id=e.find(e=>typeof e==`string`),this.strict=e.find(e=>typeof e==`boolean`)??!1;let t=e.find(e=>typeof e==`object`&&!!e);t!==void 0&&this.apply(t)}},K=class extends G{get directed(){return!0}},q=class extends G{get directed(){return!1}},J=class extends W{get $$type(){return`Subgraph`}id;constructor(...e){super(),this.id=e.find(e=>typeof e==`string`);let t=e.find(e=>typeof e==`object`&&!!e);t!==void 0&&this.apply(t)}isSubgraphCluster(){return typeof this.id==`string`?this.id.startsWith(`cluster`):!1}},Y=class extends H{comment},X=class extends V{id;get $$type(){return`Node`}comment;attributes;constructor(e,t){super(),this.id=e,this.attributes=new Y(t)}port(e){return typeof e==`string`?{id:this.id,port:e}:{id:this.id,...e}}},re=class extends V{targets;get $$type(){return`Edge`}comment;attributes;constructor(e,t){if(super(),this.targets=e,e.length<2&&(r(e[0])&&r(e[1]))===!1)throw Error(`The element of Edge target is missing or not satisfied as Edge target.`);this.attributes=new Y(t)}};Object.assign(c,{Graph:q,Digraph:K,Subgraph:J,Node:X,Edge:re});function Z(e,t){return(...n)=>{let r=e?this.Digraph:this.Graph,i=n.find(e=>typeof e==`string`),a=n.find(e=>typeof e==`object`),o=n.find(e=>typeof e==`function`),s=new r(i,t,a);return s.with(this),typeof o==`function`&&o(s),s}}function Q(e,t=c){return Object.freeze({digraph:Z.call(t,!0,e),graph:Z.call(t,!1,e)})}const $=Q(!1),ie=$.digraph;$.graph,Q(!0);function ae(e,t){return N(z(e,t?.convert),t?.print)}export{ie as n,ae as r,B as t};
|