@modular-circuit/utils 0.0.29 → 0.0.32
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/build/constants/index.js +2 -1
- package/build/functions/connected_component.js +17 -74
- package/build/functions/get_port_labels.js +21 -67
- package/build/functions/graph.js +15 -80
- package/build/functions/index.js +24 -8
- package/build/functions/label.js +6 -3
- package/build/functions/module_name_parser.js +13 -24
- package/build/functions/place_module.js +25 -54
- package/build/functions/utility.js +16 -7
- package/build/functions/zip_utils.js +45 -110
- package/build/index.js +18 -2
- package/package.json +3 -3
package/build/constants/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,78 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.test_connected_components = test_connected_components;
|
|
4
|
+
const graph_1 = require("./graph");
|
|
5
|
+
function test_connected_components(G, visitors) {
|
|
6
|
+
const ccs = [];
|
|
7
|
+
const visited = new Set();
|
|
8
|
+
for (const [k] of Object.entries(G)) {
|
|
9
|
+
if (!visited.has(k)) {
|
|
10
|
+
for (const v of visitors)
|
|
11
|
+
if (v.start_visit_component)
|
|
12
|
+
v.start_visit_component();
|
|
13
|
+
const cc = (0, graph_1.dfs)(G, k, visited, visitors);
|
|
14
|
+
ccs.push(cc);
|
|
15
|
+
for (const v of visitors)
|
|
16
|
+
if (v.end_visit_component)
|
|
17
|
+
v.end_visit_component(cc);
|
|
8
18
|
}
|
|
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
19
|
}
|
|
77
20
|
return ccs;
|
|
78
21
|
}
|
|
@@ -1,77 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.get_port_labels = get_port_labels;
|
|
4
|
+
const electronics_model_1 = require("@modular-circuit/electronics-model");
|
|
5
|
+
function get_port_labels(port, circuit) {
|
|
6
|
+
let labels = {};
|
|
7
|
+
for (const [k, v] of Object.entries(port)) {
|
|
8
|
+
if (k === electronics_model_1.LABEL_ASSOCIATED && typeof v === 'string') {
|
|
9
|
+
if (circuit.eda_port_annotations[v]) {
|
|
10
|
+
if ('shape' in circuit.eda_port_annotations[v] && circuit.eda_port_annotations[v].shape !== null) {
|
|
11
|
+
labels[v] = circuit.eda_port_annotations[v].shape;
|
|
12
|
+
}
|
|
13
|
+
else if ('lib_id' in circuit.eda_port_annotations[v] && circuit.eda_port_annotations[v].lib_id !== null) {
|
|
14
|
+
labels[v] = electronics_model_1.LabelShapes.Input;
|
|
57
15
|
}
|
|
58
16
|
else {
|
|
59
|
-
|
|
60
|
-
// NOTE: Currently only GND and VCC will come here
|
|
61
|
-
labels[v] = LabelShapes.Output;
|
|
17
|
+
throw new Error(`Invalid port annotation for port ${v}: ${circuit.eda_port_annotations[v]}`);
|
|
62
18
|
}
|
|
63
19
|
}
|
|
64
|
-
else
|
|
65
|
-
|
|
20
|
+
else {
|
|
21
|
+
// TODO : handel GND and VCC
|
|
22
|
+
// NOTE: Currently only GND and VCC will come here
|
|
23
|
+
labels[v] = electronics_model_1.LabelShapes.Output;
|
|
66
24
|
}
|
|
67
25
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
finally {
|
|
71
|
-
try {
|
|
72
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
26
|
+
else if (typeof v === 'object' && !Array.isArray(v) && v !== null) {
|
|
27
|
+
labels = { ...labels, ...get_port_labels(v, circuit) };
|
|
73
28
|
}
|
|
74
|
-
finally { if (e_1) throw e_1.error; }
|
|
75
29
|
}
|
|
76
30
|
return labels;
|
|
77
31
|
}
|
package/build/functions/graph.js
CHANGED
|
@@ -1,91 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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(); }
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dfs = dfs;
|
|
4
|
+
function dfs(G, start, visited = new Set(), visitors) {
|
|
40
5
|
visited.add(start);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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; }
|
|
6
|
+
const result = [start];
|
|
7
|
+
for (const neighbor of G[start]) {
|
|
8
|
+
if (!visited.has(neighbor)) {
|
|
9
|
+
if (visitors) {
|
|
10
|
+
for (const visitor of visitors) {
|
|
11
|
+
if (visitor.visit_edge) {
|
|
12
|
+
visitor.visit_edge(start, neighbor);
|
|
61
13
|
}
|
|
62
14
|
}
|
|
63
|
-
result.push.apply(result, __spreadArray([], __read(dfs(G, neighbor, visited, visitors)), false));
|
|
64
15
|
}
|
|
16
|
+
result.push(...dfs(G, neighbor, visited, visitors));
|
|
65
17
|
}
|
|
66
18
|
}
|
|
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
19
|
if (visitors) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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);
|
|
20
|
+
for (const visitor of visitors) {
|
|
21
|
+
if (visitor.visit_vertex) {
|
|
22
|
+
visitor.visit_vertex(start);
|
|
87
23
|
}
|
|
88
|
-
finally { if (e_3) throw e_3.error; }
|
|
89
24
|
}
|
|
90
25
|
}
|
|
91
26
|
return result;
|
package/build/functions/index.js
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./utility"), exports);
|
|
18
|
+
__exportStar(require("./place_module"), exports);
|
|
19
|
+
__exportStar(require("./module_name_parser"), exports);
|
|
20
|
+
__exportStar(require("./label"), exports);
|
|
21
|
+
__exportStar(require("./graph"), exports);
|
|
22
|
+
__exportStar(require("./connected_component"), exports);
|
|
23
|
+
__exportStar(require("./zip_utils"), exports);
|
|
24
|
+
__exportStar(require("./get_port_labels"), exports);
|
package/build/functions/label.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gen_passive_label = gen_passive_label;
|
|
4
|
+
const electronics_model_1 = require("@modular-circuit/electronics-model");
|
|
5
|
+
function gen_passive_label(text) {
|
|
6
|
+
return { text, shape: electronics_model_1.LabelShapes.Passive };
|
|
4
7
|
}
|
|
@@ -1,30 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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];
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse_module_name = parse_module_name;
|
|
4
|
+
exports.fmt_module_name = fmt_module_name;
|
|
5
|
+
exports.stringify_dependency = stringify_dependency;
|
|
6
|
+
function parse_module_name(dep) {
|
|
7
|
+
let [author, name] = dep.split('/');
|
|
19
8
|
author = author.substring(1);
|
|
20
9
|
return {
|
|
21
|
-
author
|
|
22
|
-
name
|
|
10
|
+
author,
|
|
11
|
+
name,
|
|
23
12
|
};
|
|
24
13
|
}
|
|
25
|
-
|
|
26
|
-
return
|
|
14
|
+
function fmt_module_name(idx) {
|
|
15
|
+
return `@${idx.author}/${idx.name}`;
|
|
27
16
|
}
|
|
28
|
-
|
|
29
|
-
return
|
|
17
|
+
function stringify_dependency(idx) {
|
|
18
|
+
return `${fmt_module_name(idx)}@${idx.version}`;
|
|
30
19
|
}
|
|
@@ -1,65 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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; }
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.get_circuit_ports = get_circuit_ports;
|
|
4
|
+
exports.place_module = place_module;
|
|
5
|
+
const electronics_model_1 = require("@modular-circuit/electronics-model");
|
|
6
|
+
const get_port_labels_1 = require("./get_port_labels");
|
|
7
|
+
const utility_1 = require("./utility");
|
|
8
|
+
function get_circuit_ports(module) {
|
|
9
|
+
const port_map = {};
|
|
10
|
+
let index = 0;
|
|
11
|
+
for (const port of module.ports) {
|
|
12
|
+
port_map[index++] = port;
|
|
31
13
|
}
|
|
32
14
|
return port_map;
|
|
33
15
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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; }
|
|
16
|
+
function place_module(module) {
|
|
17
|
+
const ports = [];
|
|
18
|
+
let index = 0;
|
|
19
|
+
for (const it of module.ports) {
|
|
20
|
+
ports.push({
|
|
21
|
+
index: index++,
|
|
22
|
+
uuid: (0, utility_1.gen_uuid)(),
|
|
23
|
+
name: it.name,
|
|
24
|
+
shape: (0, electronics_model_1.merge_port_label_shapes)((0, get_port_labels_1.get_port_labels)(it, module)),
|
|
25
|
+
type: it.type,
|
|
26
|
+
});
|
|
56
27
|
}
|
|
57
28
|
return {
|
|
58
|
-
uuid: gen_uuid(),
|
|
29
|
+
uuid: (0, utility_1.gen_uuid)(),
|
|
59
30
|
type: {
|
|
60
31
|
author: module.author,
|
|
61
32
|
name: module.name,
|
|
62
33
|
},
|
|
63
|
-
ports
|
|
34
|
+
ports,
|
|
64
35
|
};
|
|
65
36
|
}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.gen_uuid = void 0;
|
|
7
|
+
exports.deep_copy = deep_copy;
|
|
8
|
+
exports.replaceAll = replaceAll;
|
|
9
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
+
const uuid_1 = require("uuid");
|
|
11
|
+
const gen_uuid = () => (0, uuid_1.v4)();
|
|
12
|
+
exports.gen_uuid = gen_uuid;
|
|
13
|
+
function deep_copy(obj) {
|
|
14
|
+
return lodash_1.default.cloneDeep(obj);
|
|
6
15
|
}
|
|
7
|
-
|
|
8
|
-
|
|
16
|
+
function replaceAll(str, search, replacement) {
|
|
17
|
+
const regex = new RegExp(search, 'g');
|
|
9
18
|
return str.replace(regex, replacement);
|
|
10
19
|
}
|
|
@@ -1,117 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return
|
|
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
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
4
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
_.trys.pop(); continue;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.unzipFile = unzipFile;
|
|
7
|
+
exports.zipFiles = zipFiles;
|
|
8
|
+
exports.remove_filename_path_prefix = remove_filename_path_prefix;
|
|
9
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
10
|
+
async function unzipFile(file) {
|
|
11
|
+
const zip = new jszip_1.default();
|
|
12
|
+
try {
|
|
13
|
+
// Load the zip file from the Blob
|
|
14
|
+
const content = await zip.loadAsync(file);
|
|
15
|
+
// Prepare an object to store the extracted file content
|
|
16
|
+
const files = {};
|
|
17
|
+
// Iterate through each file in the zip archive
|
|
18
|
+
for (const fileName in content.files) {
|
|
19
|
+
if (fileName in content.files) {
|
|
20
|
+
const fileData = content.files[fileName];
|
|
21
|
+
// Extract the file content as text (you can modify this to other formats like Blob or Uint8Array as needed)
|
|
22
|
+
const fileText = await fileData.async('text');
|
|
23
|
+
// Store the extracted content in the files object
|
|
24
|
+
files[fileName] = fileText;
|
|
31
25
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
}
|
|
27
|
+
return files;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error('Error unzipping file:', error);
|
|
31
|
+
throw new Error('Failed to unzip file');
|
|
35
32
|
}
|
|
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
33
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
});
|
|
34
|
+
async function zipFiles(files) {
|
|
35
|
+
const zip = new jszip_1.default();
|
|
36
|
+
// Add files to the zip archive
|
|
37
|
+
for (const filePath in files)
|
|
38
|
+
zip.file(filePath, files[filePath]); // Add file content to the zip
|
|
39
|
+
// Generate the zip file as a Blob
|
|
40
|
+
try {
|
|
41
|
+
const blob = await zip.generateAsync({ type: 'blob' });
|
|
42
|
+
return blob;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error('Error creating zip:', error);
|
|
46
|
+
throw new Error('Failed to create zip file');
|
|
47
|
+
}
|
|
113
48
|
}
|
|
114
|
-
|
|
115
|
-
|
|
49
|
+
function remove_filename_path_prefix(name) {
|
|
50
|
+
const names = name.split('/');
|
|
116
51
|
return names[names.length - 1];
|
|
117
52
|
}
|
package/build/index.js
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./functions"), exports);
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modular-circuit/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "Intermediate representation of the modular circuit",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"jszip": "^3.10.1",
|
|
29
29
|
"lodash": "^4.17.21",
|
|
30
30
|
"uuid": "^10.0.0",
|
|
31
|
-
"@modular-circuit/
|
|
32
|
-
"@modular-circuit/
|
|
31
|
+
"@modular-circuit/electronics-model": "0.0.46",
|
|
32
|
+
"@modular-circuit/ir": "0.0.54"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"clean": "rimraf build",
|