@modular-circuit/utils 0.0.29

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 (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/build/constants/index.d.ts +2 -0
  4. package/build/constants/index.d.ts.map +1 -0
  5. package/build/constants/index.js +1 -0
  6. package/build/functions/connected_component.d.ts +7 -0
  7. package/build/functions/connected_component.d.ts.map +1 -0
  8. package/build/functions/connected_component.js +78 -0
  9. package/build/functions/get_port_labels.d.ts +4 -0
  10. package/build/functions/get_port_labels.d.ts.map +1 -0
  11. package/build/functions/get_port_labels.js +77 -0
  12. package/build/functions/graph.d.ts +6 -0
  13. package/build/functions/graph.d.ts.map +1 -0
  14. package/build/functions/graph.js +92 -0
  15. package/build/functions/index.d.ts +9 -0
  16. package/build/functions/index.d.ts.map +1 -0
  17. package/build/functions/index.js +8 -0
  18. package/build/functions/label.d.ts +3 -0
  19. package/build/functions/label.d.ts.map +1 -0
  20. package/build/functions/label.js +4 -0
  21. package/build/functions/module_name_parser.d.ts +5 -0
  22. package/build/functions/module_name_parser.d.ts.map +1 -0
  23. package/build/functions/module_name_parser.js +30 -0
  24. package/build/functions/place_module.d.ts +5 -0
  25. package/build/functions/place_module.d.ts.map +1 -0
  26. package/build/functions/place_module.js +65 -0
  27. package/build/functions/utility.d.ts +4 -0
  28. package/build/functions/utility.d.ts.map +1 -0
  29. package/build/functions/utility.js +10 -0
  30. package/build/functions/zip_utils.d.ts +4 -0
  31. package/build/functions/zip_utils.d.ts.map +1 -0
  32. package/build/functions/zip_utils.js +117 -0
  33. package/build/index.d.ts +3 -0
  34. package/build/index.d.ts.map +1 -0
  35. package/build/index.js +2 -0
  36. package/build/tsconfig.build.tsbuildinfo +1 -0
  37. package/package.json +42 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-current Alberto Schiabel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Modular Circuit Runtime
2
+
3
+ Runtime for Modular Circuit
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type GraphVisitor } from './graph';
2
+ export interface CC_Visitor extends GraphVisitor {
3
+ start_visit_component?(): unknown;
4
+ end_visit_component?(cc: string[]): unknown;
5
+ }
6
+ export declare function test_connected_components(G: Record<string, Set<string>>, visitors: CC_Visitor[]): string[][];
7
+ //# sourceMappingURL=connected_component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connected_component.d.ts","sourceRoot":"","sources":["../../src/functions/connected_component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAO,MAAM,SAAS,CAAA;AAEhD,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C,qBAAqB,CAAC,IAAI,OAAO,CAAA;IACjC,mBAAmB,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;CAC5C;AAED,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,cAa/F"}
@@ -0,0 +1,78 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
12
+ var __read = (this && this.__read) || function (o, n) {
13
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
14
+ if (!m) return o;
15
+ var i = m.call(o), r, ar = [], e;
16
+ try {
17
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
+ }
19
+ catch (error) { e = { error: error }; }
20
+ finally {
21
+ try {
22
+ if (r && !r.done && (m = i["return"])) m.call(i);
23
+ }
24
+ finally { if (e) throw e.error; }
25
+ }
26
+ return ar;
27
+ };
28
+ import { dfs } from './graph';
29
+ export function test_connected_components(G, visitors) {
30
+ var e_1, _a, e_2, _b, e_3, _c;
31
+ var ccs = [];
32
+ var visited = new Set();
33
+ try {
34
+ for (var _d = __values(Object.entries(G)), _e = _d.next(); !_e.done; _e = _d.next()) {
35
+ var _f = __read(_e.value, 1), k = _f[0];
36
+ if (!visited.has(k)) {
37
+ try {
38
+ for (var visitors_1 = (e_2 = void 0, __values(visitors)), visitors_1_1 = visitors_1.next(); !visitors_1_1.done; visitors_1_1 = visitors_1.next()) {
39
+ var v = visitors_1_1.value;
40
+ if (v.start_visit_component)
41
+ v.start_visit_component();
42
+ }
43
+ }
44
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
45
+ finally {
46
+ try {
47
+ if (visitors_1_1 && !visitors_1_1.done && (_b = visitors_1.return)) _b.call(visitors_1);
48
+ }
49
+ finally { if (e_2) throw e_2.error; }
50
+ }
51
+ var cc = dfs(G, k, visited, visitors);
52
+ ccs.push(cc);
53
+ try {
54
+ for (var visitors_2 = (e_3 = void 0, __values(visitors)), visitors_2_1 = visitors_2.next(); !visitors_2_1.done; visitors_2_1 = visitors_2.next()) {
55
+ var v = visitors_2_1.value;
56
+ if (v.end_visit_component)
57
+ v.end_visit_component(cc);
58
+ }
59
+ }
60
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
61
+ finally {
62
+ try {
63
+ if (visitors_2_1 && !visitors_2_1.done && (_c = visitors_2.return)) _c.call(visitors_2);
64
+ }
65
+ finally { if (e_3) throw e_3.error; }
66
+ }
67
+ }
68
+ }
69
+ }
70
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
71
+ finally {
72
+ try {
73
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
74
+ }
75
+ finally { if (e_1) throw e_1.error; }
76
+ }
77
+ return ccs;
78
+ }
@@ -0,0 +1,4 @@
1
+ import { LabelShapes, type PortLike } from '@modular-circuit/electronics-model';
2
+ import type { ModuleCircuit } from '@modular-circuit/ir';
3
+ export declare function get_port_labels(port: PortLike, circuit: ModuleCircuit): Record<string, LabelShapes>;
4
+ //# sourceMappingURL=get_port_labels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get_port_labels.d.ts","sourceRoot":"","sources":["../../src/functions/get_port_labels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,oCAAoC,CAAA;AACjG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,+BAuBrE"}
@@ -0,0 +1,77 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __values = (this && this.__values) || function(o) {
13
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
14
+ if (m) return m.call(o);
15
+ if (o && typeof o.length === "number") return {
16
+ next: function () {
17
+ if (o && i >= o.length) o = void 0;
18
+ return { value: o && o[i++], done: !o };
19
+ }
20
+ };
21
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
22
+ };
23
+ var __read = (this && this.__read) || function (o, n) {
24
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
25
+ if (!m) return o;
26
+ var i = m.call(o), r, ar = [], e;
27
+ try {
28
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
29
+ }
30
+ catch (error) { e = { error: error }; }
31
+ finally {
32
+ try {
33
+ if (r && !r.done && (m = i["return"])) m.call(i);
34
+ }
35
+ finally { if (e) throw e.error; }
36
+ }
37
+ return ar;
38
+ };
39
+ import { LABEL_ASSOCIATED, LabelShapes } from '@modular-circuit/electronics-model';
40
+ export function get_port_labels(port, circuit) {
41
+ var e_1, _a;
42
+ var labels = {};
43
+ try {
44
+ for (var _b = __values(Object.entries(port)), _c = _b.next(); !_c.done; _c = _b.next()) {
45
+ var _d = __read(_c.value, 2), k = _d[0], v = _d[1];
46
+ if (k === LABEL_ASSOCIATED && typeof v === 'string') {
47
+ if (circuit.eda_port_annotations[v]) {
48
+ if ('shape' in circuit.eda_port_annotations[v] && circuit.eda_port_annotations[v].shape !== null) {
49
+ labels[v] = circuit.eda_port_annotations[v].shape;
50
+ }
51
+ else if ('lib_id' in circuit.eda_port_annotations[v] && circuit.eda_port_annotations[v].lib_id !== null) {
52
+ labels[v] = LabelShapes.Input;
53
+ }
54
+ else {
55
+ throw new Error("Invalid port annotation for port ".concat(v, ": ").concat(circuit.eda_port_annotations[v]));
56
+ }
57
+ }
58
+ else {
59
+ // TODO : handel GND and VCC
60
+ // NOTE: Currently only GND and VCC will come here
61
+ labels[v] = LabelShapes.Output;
62
+ }
63
+ }
64
+ else if (typeof v === 'object' && !Array.isArray(v) && v !== null) {
65
+ labels = __assign(__assign({}, labels), get_port_labels(v, circuit));
66
+ }
67
+ }
68
+ }
69
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
70
+ finally {
71
+ try {
72
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
73
+ }
74
+ finally { if (e_1) throw e_1.error; }
75
+ }
76
+ return labels;
77
+ }
@@ -0,0 +1,6 @@
1
+ export interface GraphVisitor {
2
+ visit_vertex?(v: string): unknown;
3
+ visit_edge?(a: string, b: string): unknown;
4
+ }
5
+ export declare function dfs(G: Record<string, Set<string>>, start: string, visited?: Set<string>, visitors?: GraphVisitor[]): string[];
6
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/functions/graph.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACjC,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAC3C;AACD,wBAAgB,GAAG,CACjB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,EAC9B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,GAAG,CAAC,MAAM,CAAa,EAChC,QAAQ,CAAC,EAAE,YAAY,EAAE,GACxB,MAAM,EAAE,CAyBV"}
@@ -0,0 +1,92 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
12
+ var __read = (this && this.__read) || function (o, n) {
13
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
14
+ if (!m) return o;
15
+ var i = m.call(o), r, ar = [], e;
16
+ try {
17
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
+ }
19
+ catch (error) { e = { error: error }; }
20
+ finally {
21
+ try {
22
+ if (r && !r.done && (m = i["return"])) m.call(i);
23
+ }
24
+ finally { if (e) throw e.error; }
25
+ }
26
+ return ar;
27
+ };
28
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
29
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
+ if (ar || !(i in from)) {
31
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
+ ar[i] = from[i];
33
+ }
34
+ }
35
+ return to.concat(ar || Array.prototype.slice.call(from));
36
+ };
37
+ export function dfs(G, start, visited, visitors) {
38
+ var e_1, _a, e_2, _b, e_3, _c;
39
+ if (visited === void 0) { visited = new Set(); }
40
+ visited.add(start);
41
+ var result = [start];
42
+ try {
43
+ for (var _d = __values(G[start]), _e = _d.next(); !_e.done; _e = _d.next()) {
44
+ var neighbor = _e.value;
45
+ if (!visited.has(neighbor)) {
46
+ if (visitors) {
47
+ try {
48
+ for (var visitors_1 = (e_2 = void 0, __values(visitors)), visitors_1_1 = visitors_1.next(); !visitors_1_1.done; visitors_1_1 = visitors_1.next()) {
49
+ var visitor = visitors_1_1.value;
50
+ if (visitor.visit_edge) {
51
+ visitor.visit_edge(start, neighbor);
52
+ }
53
+ }
54
+ }
55
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
56
+ finally {
57
+ try {
58
+ if (visitors_1_1 && !visitors_1_1.done && (_b = visitors_1.return)) _b.call(visitors_1);
59
+ }
60
+ finally { if (e_2) throw e_2.error; }
61
+ }
62
+ }
63
+ result.push.apply(result, __spreadArray([], __read(dfs(G, neighbor, visited, visitors)), false));
64
+ }
65
+ }
66
+ }
67
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
68
+ finally {
69
+ try {
70
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
71
+ }
72
+ finally { if (e_1) throw e_1.error; }
73
+ }
74
+ if (visitors) {
75
+ try {
76
+ for (var visitors_2 = __values(visitors), visitors_2_1 = visitors_2.next(); !visitors_2_1.done; visitors_2_1 = visitors_2.next()) {
77
+ var visitor = visitors_2_1.value;
78
+ if (visitor.visit_vertex) {
79
+ visitor.visit_vertex(start);
80
+ }
81
+ }
82
+ }
83
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
84
+ finally {
85
+ try {
86
+ if (visitors_2_1 && !visitors_2_1.done && (_c = visitors_2.return)) _c.call(visitors_2);
87
+ }
88
+ finally { if (e_3) throw e_3.error; }
89
+ }
90
+ }
91
+ return result;
92
+ }
@@ -0,0 +1,9 @@
1
+ export * from './utility';
2
+ export * from './place_module';
3
+ export * from './module_name_parser';
4
+ export * from './label';
5
+ export * from './graph';
6
+ export * from './connected_component';
7
+ export * from './zip_utils';
8
+ export * from './get_port_labels';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,uBAAuB,CAAA;AACrC,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,8 @@
1
+ export * from './utility';
2
+ export * from './place_module';
3
+ export * from './module_name_parser';
4
+ export * from './label';
5
+ export * from './graph';
6
+ export * from './connected_component';
7
+ export * from './zip_utils';
8
+ export * from './get_port_labels';
@@ -0,0 +1,3 @@
1
+ import type { LABEL_META } from '@modular-circuit/ir';
2
+ export declare function gen_passive_label(text: string): LABEL_META;
3
+ //# sourceMappingURL=label.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"label.d.ts","sourceRoot":"","sources":["../../src/functions/label.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAErD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAE1D"}
@@ -0,0 +1,4 @@
1
+ import { LabelShapes } from '@modular-circuit/electronics-model';
2
+ export function gen_passive_label(text) {
3
+ return { text: text, shape: LabelShapes.Passive };
4
+ }
@@ -0,0 +1,5 @@
1
+ import type { ModuleIndex, ModuleName } from '@modular-circuit/ir';
2
+ export declare function parse_module_name(dep: string): ModuleName;
3
+ export declare function fmt_module_name(idx: ModuleName): string;
4
+ export declare function stringify_dependency(idx: ModuleIndex): string;
5
+ //# sourceMappingURL=module_name_parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module_name_parser.d.ts","sourceRoot":"","sources":["../../src/functions/module_name_parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAElE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAOzD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CAEvD;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,CAE7D"}
@@ -0,0 +1,30 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
17
+ export function parse_module_name(dep) {
18
+ var _a = __read(dep.split('/'), 2), author = _a[0], name = _a[1];
19
+ author = author.substring(1);
20
+ return {
21
+ author: author,
22
+ name: name,
23
+ };
24
+ }
25
+ export function fmt_module_name(idx) {
26
+ return "@".concat(idx.author, "/").concat(idx.name);
27
+ }
28
+ export function stringify_dependency(idx) {
29
+ return "".concat(fmt_module_name(idx), "@").concat(idx.version);
30
+ }
@@ -0,0 +1,5 @@
1
+ import { type PortLike } from '@modular-circuit/electronics-model';
2
+ import type { IR_Block, ModuleCircuit } from '@modular-circuit/ir';
3
+ export declare function get_circuit_ports(module: ModuleCircuit): Record<number, PortLike>;
4
+ export declare function place_module(module: ModuleCircuit): IR_Block;
5
+ //# sourceMappingURL=place_module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"place_module.d.ts","sourceRoot":"","sources":["../../src/functions/place_module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAA2B,MAAM,oCAAoC,CAAA;AAC3F,OAAO,KAAK,EAAE,QAAQ,EAAW,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAI3E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CASjF;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,QAAQ,CAsB5D"}
@@ -0,0 +1,65 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
12
+ import { merge_port_label_shapes } from '@modular-circuit/electronics-model';
13
+ import { get_port_labels } from './get_port_labels';
14
+ import { gen_uuid } from './utility';
15
+ export function get_circuit_ports(module) {
16
+ var e_1, _a;
17
+ var port_map = {};
18
+ var index = 0;
19
+ try {
20
+ for (var _b = __values(module.ports), _c = _b.next(); !_c.done; _c = _b.next()) {
21
+ var port = _c.value;
22
+ port_map[index++] = port;
23
+ }
24
+ }
25
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
26
+ finally {
27
+ try {
28
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
29
+ }
30
+ finally { if (e_1) throw e_1.error; }
31
+ }
32
+ return port_map;
33
+ }
34
+ export function place_module(module) {
35
+ var e_2, _a;
36
+ var ports = [];
37
+ var index = 0;
38
+ try {
39
+ for (var _b = __values(module.ports), _c = _b.next(); !_c.done; _c = _b.next()) {
40
+ var it_1 = _c.value;
41
+ ports.push({
42
+ index: index++,
43
+ uuid: gen_uuid(),
44
+ name: it_1.name,
45
+ shape: merge_port_label_shapes(get_port_labels(it_1, module)),
46
+ type: it_1.type,
47
+ });
48
+ }
49
+ }
50
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
51
+ finally {
52
+ try {
53
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
54
+ }
55
+ finally { if (e_2) throw e_2.error; }
56
+ }
57
+ return {
58
+ uuid: gen_uuid(),
59
+ type: {
60
+ author: module.author,
61
+ name: module.name,
62
+ },
63
+ ports: ports,
64
+ };
65
+ }
@@ -0,0 +1,4 @@
1
+ export declare const gen_uuid: () => string;
2
+ export declare function deep_copy<T>(obj: T): T;
3
+ export declare function replaceAll(str: string, search: string, replacement: string): string;
4
+ //# sourceMappingURL=utility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["../../src/functions/utility.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,cAAiB,CAAA;AAEtC,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAEtC;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,UAG1E"}
@@ -0,0 +1,10 @@
1
+ import _ from 'lodash';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ export var gen_uuid = function () { return uuidv4(); };
4
+ export function deep_copy(obj) {
5
+ return _.cloneDeep(obj);
6
+ }
7
+ export function replaceAll(str, search, replacement) {
8
+ var regex = new RegExp(search, 'g');
9
+ return str.replace(regex, replacement);
10
+ }
@@ -0,0 +1,4 @@
1
+ export declare function unzipFile(file: ArrayBuffer | Blob): Promise<Record<string, string>>;
2
+ export declare function zipFiles(files: Record<string, string>): Promise<Blob>;
3
+ export declare function remove_filename_path_prefix(name: string): string;
4
+ //# sourceMappingURL=zip_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip_utils.d.ts","sourceRoot":"","sources":["../../src/functions/zip_utils.ts"],"names":[],"mappings":"AAEA,wBAAsB,SAAS,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,mCA2BvD;AAED,wBAAsB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,iBAc3D;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,UAGvD"}
@@ -0,0 +1,117 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import JSZip from 'jszip';
38
+ export function unzipFile(file) {
39
+ return __awaiter(this, void 0, void 0, function () {
40
+ var zip, content, files, _a, _b, _c, _i, fileName, fileData, fileText, error_1;
41
+ return __generator(this, function (_d) {
42
+ switch (_d.label) {
43
+ case 0:
44
+ zip = new JSZip();
45
+ _d.label = 1;
46
+ case 1:
47
+ _d.trys.push([1, 7, , 8]);
48
+ return [4 /*yield*/, zip.loadAsync(file)
49
+ // Prepare an object to store the extracted file content
50
+ ];
51
+ case 2:
52
+ content = _d.sent();
53
+ files = {};
54
+ _a = content.files;
55
+ _b = [];
56
+ for (_c in _a)
57
+ _b.push(_c);
58
+ _i = 0;
59
+ _d.label = 3;
60
+ case 3:
61
+ if (!(_i < _b.length)) return [3 /*break*/, 6];
62
+ _c = _b[_i];
63
+ if (!(_c in _a)) return [3 /*break*/, 5];
64
+ fileName = _c;
65
+ if (!(fileName in content.files)) return [3 /*break*/, 5];
66
+ fileData = content.files[fileName];
67
+ return [4 /*yield*/, fileData.async('text')
68
+ // Store the extracted content in the files object
69
+ ];
70
+ case 4:
71
+ fileText = _d.sent();
72
+ // Store the extracted content in the files object
73
+ files[fileName] = fileText;
74
+ _d.label = 5;
75
+ case 5:
76
+ _i++;
77
+ return [3 /*break*/, 3];
78
+ case 6: return [2 /*return*/, files];
79
+ case 7:
80
+ error_1 = _d.sent();
81
+ console.error('Error unzipping file:', error_1);
82
+ throw new Error('Failed to unzip file');
83
+ case 8: return [2 /*return*/];
84
+ }
85
+ });
86
+ });
87
+ }
88
+ export function zipFiles(files) {
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ var zip, filePath, blob, error_2;
91
+ return __generator(this, function (_a) {
92
+ switch (_a.label) {
93
+ case 0:
94
+ zip = new JSZip();
95
+ // Add files to the zip archive
96
+ for (filePath in files)
97
+ zip.file(filePath, files[filePath]); // Add file content to the zip
98
+ _a.label = 1;
99
+ case 1:
100
+ _a.trys.push([1, 3, , 4]);
101
+ return [4 /*yield*/, zip.generateAsync({ type: 'blob' })];
102
+ case 2:
103
+ blob = _a.sent();
104
+ return [2 /*return*/, blob];
105
+ case 3:
106
+ error_2 = _a.sent();
107
+ console.error('Error creating zip:', error_2);
108
+ throw new Error('Failed to create zip file');
109
+ case 4: return [2 /*return*/];
110
+ }
111
+ });
112
+ });
113
+ }
114
+ export function remove_filename_path_prefix(name) {
115
+ var names = name.split('/');
116
+ return names[names.length - 1];
117
+ }
@@ -0,0 +1,3 @@
1
+ export * from './functions';
2
+ export * from './constants';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
package/build/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './functions';
2
+ export * from './constants';
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts","../src/constants/index.ts","../src/functions/connected_component.ts","../src/functions/get_port_labels.ts","../src/functions/graph.ts","../src/functions/index.ts","../src/functions/label.ts","../src/functions/module_name_parser.ts","../src/functions/place_module.ts","../src/functions/utility.ts","../src/functions/zip_utils.ts"],"version":"5.8.3"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@modular-circuit/utils",
3
+ "version": "0.0.29",
4
+ "description": "Intermediate representation of the modular circuit",
5
+ "main": "./build/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./build/index.js",
9
+ "require": "./build/index.js",
10
+ "types": "./build/index.d.ts"
11
+ }
12
+ },
13
+ "files": [
14
+ "build"
15
+ ],
16
+ "keywords": [],
17
+ "author": "",
18
+ "license": "ISC",
19
+ "devDependencies": {
20
+ "@biomejs/biome": "^1.8.3",
21
+ "@types/lodash": "^4.17.10",
22
+ "@types/uuid": "^10.0.0",
23
+ "esbuild": "^0.20.2",
24
+ "tsup": "^8.3.0",
25
+ "typescript": "^5.4.5"
26
+ },
27
+ "dependencies": {
28
+ "jszip": "^3.10.1",
29
+ "lodash": "^4.17.21",
30
+ "uuid": "^10.0.0",
31
+ "@modular-circuit/ir": "0.0.51",
32
+ "@modular-circuit/electronics-model": "0.0.43"
33
+ },
34
+ "scripts": {
35
+ "clean": "rimraf build",
36
+ "prebuild": "pnpm clean",
37
+ "build": "tsc --build tsconfig.build.json",
38
+ "lint:ci": "biome ci",
39
+ "lint": "biome check --fix --unsafe",
40
+ "test:unit": "vitest --workspace ../../vitest.workspace.ts --project unit run"
41
+ }
42
+ }