@thi.ng/dot 2.1.76 → 2.1.78
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 +7 -1
- package/README.md +1 -1
- package/package.json +8 -8
- package/serialize.js +25 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-29T09:28:36Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [2.1.77](https://github.com/thi-ng/umbrella/tree/@thi.ng/dot@2.1.77) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
17
|
+
|
|
12
18
|
### [2.1.69](https://github.com/thi-ng/umbrella/tree/@thi.ng/dot@2.1.69) (2024-03-18)
|
|
13
19
|
|
|
14
20
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 189 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/dot",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.78",
|
|
4
4
|
"description": "Graphviz document abstraction & serialization to DOT format",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/dot",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
40
|
-
"@thi.ng/checks": "^3.6.
|
|
39
|
+
"@thi.ng/api": "^8.11.4",
|
|
40
|
+
"@thi.ng/checks": "^3.6.6"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@microsoft/api-extractor": "^7.
|
|
44
|
-
"esbuild": "^0.21.
|
|
43
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
44
|
+
"esbuild": "^0.21.5",
|
|
45
45
|
"typedoc": "^0.25.13",
|
|
46
|
-
"typescript": "^5.
|
|
46
|
+
"typescript": "^5.5.2"
|
|
47
47
|
},
|
|
48
48
|
"keywords": [
|
|
49
49
|
"2d",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"status": "beta",
|
|
85
85
|
"year": 2018
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\n"
|
|
88
88
|
}
|
package/serialize.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isArray } from "@thi.ng/checks/is-array";
|
|
2
|
-
let
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
2
|
+
let __nextID = 0;
|
|
3
|
+
const __nextSubgraphID = () => "cluster" + __nextID++;
|
|
4
|
+
const __wrapQ = (x) => `"${x}"`;
|
|
5
|
+
const __escape = (x) => String(x).replace(/"/g, `\\"`).replace(/\n/g, "\\n");
|
|
6
|
+
const __formatGraphAttribs = (attribs, acc) => {
|
|
7
7
|
for (let a in attribs) {
|
|
8
8
|
let v = attribs[a];
|
|
9
9
|
switch (a) {
|
|
@@ -14,19 +14,19 @@ const formatGraphAttribs = (attribs, acc) => {
|
|
|
14
14
|
isArray(v) && (v = v.join(","));
|
|
15
15
|
break;
|
|
16
16
|
case "edge":
|
|
17
|
-
acc.push(`edge[${
|
|
17
|
+
acc.push(`edge[${__formatAttribs(v)}];`);
|
|
18
18
|
continue;
|
|
19
19
|
case "node":
|
|
20
|
-
acc.push(`node[${
|
|
20
|
+
acc.push(`node[${__formatAttribs(v)}];`);
|
|
21
21
|
continue;
|
|
22
22
|
default:
|
|
23
23
|
break;
|
|
24
24
|
}
|
|
25
|
-
acc.push(`${a}="${
|
|
25
|
+
acc.push(`${a}="${__escape(v)}";`);
|
|
26
26
|
}
|
|
27
27
|
return acc;
|
|
28
28
|
};
|
|
29
|
-
const
|
|
29
|
+
const __formatAttribs = (attribs) => {
|
|
30
30
|
const acc = [];
|
|
31
31
|
for (let a in attribs) {
|
|
32
32
|
let v = attribs[a];
|
|
@@ -38,7 +38,7 @@ const formatAttribs = (attribs) => {
|
|
|
38
38
|
break;
|
|
39
39
|
case "label":
|
|
40
40
|
if (attribs.ins || attribs.outs) {
|
|
41
|
-
v =
|
|
41
|
+
v = __formatPortLabel(attribs, v);
|
|
42
42
|
}
|
|
43
43
|
break;
|
|
44
44
|
case "url":
|
|
@@ -53,47 +53,47 @@ const formatAttribs = (attribs) => {
|
|
|
53
53
|
continue;
|
|
54
54
|
default:
|
|
55
55
|
}
|
|
56
|
-
acc.push(`${a}="${
|
|
56
|
+
acc.push(`${a}="${__escape(v)}"`);
|
|
57
57
|
}
|
|
58
58
|
return acc.join(", ");
|
|
59
59
|
};
|
|
60
|
-
const
|
|
60
|
+
const __formatPorts = (ports) => {
|
|
61
61
|
const acc = [];
|
|
62
62
|
for (let i in ports) {
|
|
63
|
-
acc.push(`<${i}> ${
|
|
63
|
+
acc.push(`<${i}> ${__escape(ports[i])}`);
|
|
64
64
|
}
|
|
65
65
|
return `{ ${acc.join(" | ")} }`;
|
|
66
66
|
};
|
|
67
|
-
const
|
|
67
|
+
const __formatPortLabel = (node, label) => {
|
|
68
68
|
const acc = [];
|
|
69
|
-
node.ins && acc.push(
|
|
70
|
-
acc.push(
|
|
71
|
-
node.outs && acc.push(
|
|
69
|
+
node.ins && acc.push(__formatPorts(node.ins));
|
|
70
|
+
acc.push(__escape(label));
|
|
71
|
+
node.outs && acc.push(__formatPorts(node.outs));
|
|
72
72
|
return acc.join(" | ");
|
|
73
73
|
};
|
|
74
74
|
const serializeNode = (id, n) => {
|
|
75
|
-
const attribs =
|
|
75
|
+
const attribs = __formatAttribs(n);
|
|
76
76
|
return attribs.length ? `"${id}"[${attribs}];` : `"${id}";`;
|
|
77
77
|
};
|
|
78
78
|
const serializeEdge = (e, directed = true) => {
|
|
79
|
-
const acc = [
|
|
80
|
-
e.srcPort != null && acc.push(":",
|
|
79
|
+
const acc = [__wrapQ(e.src)];
|
|
80
|
+
e.srcPort != null && acc.push(":", __wrapQ(e.srcPort));
|
|
81
81
|
acc.push(directed ? " -> " : " -- ");
|
|
82
|
-
acc.push(
|
|
83
|
-
e.destPort != null && acc.push(":",
|
|
84
|
-
const attribs =
|
|
82
|
+
acc.push(__wrapQ(e.dest));
|
|
83
|
+
e.destPort != null && acc.push(":", __wrapQ(e.destPort));
|
|
84
|
+
const attribs = __formatAttribs(e);
|
|
85
85
|
attribs.length && acc.push("[", attribs, "]");
|
|
86
86
|
acc.push(";");
|
|
87
87
|
return acc.join("");
|
|
88
88
|
};
|
|
89
89
|
const serializeGraph = (graph, isSub = false) => {
|
|
90
90
|
const directed = graph.directed !== false;
|
|
91
|
-
const acc = isSub ? [`subgraph ${graph.id ||
|
|
91
|
+
const acc = isSub ? [`subgraph ${graph.id || __nextSubgraphID()} {`] : [`${directed ? "di" : ""}graph ${graph.id || "g"} {`];
|
|
92
92
|
if (graph.include) {
|
|
93
93
|
acc.push(graph.include);
|
|
94
94
|
}
|
|
95
95
|
if (graph.attribs) {
|
|
96
|
-
|
|
96
|
+
__formatGraphAttribs(graph.attribs, acc);
|
|
97
97
|
}
|
|
98
98
|
for (let id in graph.nodes) {
|
|
99
99
|
acc.push(serializeNode(id, graph.nodes[id]));
|