@takodotid/circuit 0.19.0 → 0.21.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.
Files changed (54) hide show
  1. package/README.md +2 -2
  2. package/dist/chunks/index-n4zpd25n.js +936 -0
  3. package/dist/chunks/{index-dczpxzzm.js → index-v8zgr7wm.js} +33 -14
  4. package/dist/chunks/{new-7n8qvtjd.js → new-ny89s7y7.js} +4 -6
  5. package/dist/chunks/server-zapfzhv4.js +244 -0
  6. package/dist/cli/index.js +855 -803
  7. package/dist/index.js +20 -21
  8. package/dist/presets/index.js +20 -21
  9. package/dist/types/adapters/devices/derive.d.ts +2 -0
  10. package/dist/types/core/across.d.ts +4 -0
  11. package/dist/types/core/addr.d.ts +10 -0
  12. package/dist/types/core/addresses.d.ts +46 -0
  13. package/dist/types/core/files.d.ts +6 -0
  14. package/dist/types/core/graph.d.ts +31 -1
  15. package/dist/types/core/schema-docs.d.ts +16 -0
  16. package/package.json +7 -7
  17. package/src/adapters/devices/derive.ts +32 -0
  18. package/src/adapters/devices/raisecom-ros/index.ts +23 -3
  19. package/src/adapters/devices/routeros/index.ts +10 -0
  20. package/src/adapters/devices/vrp/index.ts +10 -1
  21. package/src/cli/graph.ts +1 -15
  22. package/src/cli/index.ts +154 -20
  23. package/src/cli/rename.ts +129 -0
  24. package/src/core/across.ts +322 -0
  25. package/src/core/addr.ts +29 -0
  26. package/src/core/addresses.ts +316 -0
  27. package/src/core/files.ts +32 -0
  28. package/src/core/graph.ts +27 -6
  29. package/src/core/schema-docs.ts +166 -0
  30. package/src/core/validate.ts +2 -52
  31. package/src/studio/data.ts +255 -0
  32. package/src/studio/git.ts +119 -0
  33. package/src/studio/public/app.js +165 -0
  34. package/src/studio/public/compare.js +243 -0
  35. package/src/studio/public/diff.js +97 -0
  36. package/src/studio/public/dom.js +108 -0
  37. package/src/studio/public/evaluate.js +648 -0
  38. package/src/studio/public/export.js +122 -0
  39. package/src/studio/public/favicon.svg +12 -0
  40. package/src/studio/public/graph.js +983 -0
  41. package/src/studio/public/index.html +71 -0
  42. package/src/studio/public/net.js +128 -0
  43. package/src/studio/public/special-gothic-latin-ext.woff2 +0 -0
  44. package/src/studio/public/special-gothic-latin.woff2 +0 -0
  45. package/src/studio/public/special-gothic-license.txt +93 -0
  46. package/src/studio/public/style.css +1334 -0
  47. package/src/studio/public/tables.js +1223 -0
  48. package/src/studio/public/tools.js +578 -0
  49. package/src/studio/server.ts +219 -0
  50. package/templates/project/AGENTS.md +2 -0
  51. package/dist/chunks/index-fq57hya4.js +0 -20
  52. package/dist/chunks/studio-femhydvd.js +0 -764
  53. package/src/cli/studio-page.ts +0 -876
  54. package/src/cli/studio.ts +0 -126
@@ -0,0 +1,122 @@
1
+ // @ts-check
2
+ /// <reference lib="dom" />
3
+ // Saving what Studio shows: a table as CSV, and the graph as SVG or PNG, drawn the way it looks on screen.
4
+
5
+ /** The properties that make the drawing look as it does, copied onto each element, since a saved SVG has no stylesheet. */
6
+ const DRAWN = [
7
+ "fill",
8
+ "stroke",
9
+ "stroke-width",
10
+ "stroke-dasharray",
11
+ "stroke-linejoin",
12
+ "paint-order",
13
+ "opacity",
14
+ "font-family",
15
+ "font-size",
16
+ "font-weight",
17
+ "text-anchor",
18
+ "dominant-baseline",
19
+ "display",
20
+ ];
21
+
22
+ /**
23
+ * Hand the browser a file to save.
24
+ *
25
+ * @param {string} name
26
+ * @param {Blob} blob
27
+ */
28
+ export function save(name, blob) {
29
+ const url = URL.createObjectURL(blob);
30
+ const anchor = document.createElement("a");
31
+ anchor.href = url;
32
+ anchor.download = name;
33
+ anchor.click();
34
+ setTimeout(() => URL.revokeObjectURL(url), 1000);
35
+ }
36
+
37
+ /**
38
+ * A table as CSV: its header, then each row, every cell as the text it shows.
39
+ *
40
+ * @param {HTMLTableElement} table
41
+ */
42
+ export function csvOf(table) {
43
+ /** @param {string} text */
44
+ const field = (text) => (/[",\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text);
45
+ const rows = [...table.querySelectorAll(":scope > thead > tr, :scope > tbody > tr")];
46
+
47
+ return rows.map((row) => [...row.children].map((cell) => field(cell.textContent?.trim() ?? "")).join(",")).join("\n") + "\n";
48
+ }
49
+
50
+ /**
51
+ * The drawing as an SVG file of its own: the drawn parts, framed around what is drawn, with each element's look written onto it.
52
+ *
53
+ * @param {SVGElement} svg
54
+ * @param {SVGGraphicsElement} viewport
55
+ * @returns {{ text: string, width: number, height: number }}
56
+ */
57
+ export function svgOf(svg, viewport) {
58
+ const box = viewport.getBBox();
59
+ const margin = 24;
60
+ const width = Math.ceil(box.width + margin * 2);
61
+ const height = Math.ceil(box.height + margin * 2);
62
+
63
+ const copy = /** @type {SVGElement} */ (svg.cloneNode(true));
64
+ const originals = [svg, ...svg.querySelectorAll("*")];
65
+ const copies = [copy, ...copy.querySelectorAll("*")];
66
+
67
+ for (const [index, original] of originals.entries()) {
68
+ const target = copies[index];
69
+ if (!(target instanceof SVGElement)) continue;
70
+
71
+ const look = getComputedStyle(original);
72
+ target.setAttribute("style", DRAWN.map((name) => `${name}:${look.getPropertyValue(name)}`).join(";"));
73
+ target.removeAttribute("class");
74
+ }
75
+
76
+ // The drawing's own place on screen is left out: the file is framed around what is drawn.
77
+ copy.querySelector("#viewport")?.removeAttribute("transform");
78
+ copy.setAttribute("xmlns", "http://www.w3.org/2000/svg");
79
+ copy.setAttribute("viewBox", `${box.x - margin} ${box.y - margin} ${width} ${height}`);
80
+ copy.setAttribute("width", String(width));
81
+ copy.setAttribute("height", String(height));
82
+
83
+ const background = document.createElementNS("http://www.w3.org/2000/svg", "rect");
84
+ background.setAttribute("x", String(box.x - margin));
85
+ background.setAttribute("y", String(box.y - margin));
86
+ background.setAttribute("width", String(width));
87
+ background.setAttribute("height", String(height));
88
+ background.setAttribute("fill", getComputedStyle(document.body).backgroundColor);
89
+ copy.prepend(background);
90
+
91
+ return { text: new XMLSerializer().serializeToString(copy), width, height };
92
+ }
93
+
94
+ /**
95
+ * An SVG drawn into a PNG, at twice its size so it stays sharp.
96
+ *
97
+ * @param {{ text: string, width: number, height: number }} drawing
98
+ * @returns {Promise<Blob>}
99
+ */
100
+ export function pngOf(drawing) {
101
+ const scale = 2;
102
+ const image = new Image();
103
+ const url = URL.createObjectURL(new Blob([drawing.text], { type: "image/svg+xml" }));
104
+
105
+ return new Promise((done, fail) => {
106
+ image.addEventListener("load", () => {
107
+ const canvas = document.createElement("canvas");
108
+ canvas.width = drawing.width * scale;
109
+ canvas.height = drawing.height * scale;
110
+
111
+ const context = canvas.getContext("2d");
112
+ if (!context) return fail(new Error("this browser cannot draw a PNG"));
113
+
114
+ context.scale(scale, scale);
115
+ context.drawImage(image, 0, 0);
116
+ URL.revokeObjectURL(url);
117
+ canvas.toBlob((blob) => (blob ? done(blob) : fail(new Error("the PNG could not be made"))), "image/png");
118
+ });
119
+ image.addEventListener("error", () => fail(new Error("the drawing could not be read back")));
120
+ image.src = url;
121
+ });
122
+ }
@@ -0,0 +1,12 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
2
+ <rect width="32" height="32" rx="6" fill="#f8e347" />
3
+ <rect x="4" y="8" width="24" height="16" rx="3" fill="#0a47b8" />
4
+ <g fill="#ffffff">
5
+ <rect x="7.5" y="11.5" width="4" height="3.5" rx="0.6" />
6
+ <rect x="14" y="11.5" width="4" height="3.5" rx="0.6" />
7
+ <rect x="20.5" y="11.5" width="4" height="3.5" rx="0.6" />
8
+ <rect x="7.5" y="17" width="4" height="3.5" rx="0.6" />
9
+ <rect x="14" y="17" width="4" height="3.5" rx="0.6" />
10
+ </g>
11
+ <rect x="20.5" y="17" width="4" height="3.5" rx="0.6" fill="#f8e347" />
12
+ </svg>