@modular-circuit/transpiler 0.0.82 → 0.0.83
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.
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { VECTOR2 } from '@modular-circuit/electronics-model';
|
|
2
|
-
export declare const calc_boxes_pos: (boxes:
|
|
3
|
-
[id: string]: VECTOR2;
|
|
4
|
-
}) => Promise<Record<string, VECTOR2>>;
|
|
2
|
+
export declare const calc_boxes_pos: (boxes: Record<string, VECTOR2>) => Promise<Record<string, VECTOR2>>;
|
|
5
3
|
//# sourceMappingURL=calc_boxes_pos.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calc_boxes_pos.d.ts","sourceRoot":"","sources":["../../../src/converter/netlist_to_kicad/calc_boxes_pos.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAA;
|
|
1
|
+
{"version":3,"file":"calc_boxes_pos.d.ts","sourceRoot":"","sources":["../../../src/converter/netlist_to_kicad/calc_boxes_pos.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAA;AAGjE,eAAO,MAAM,cAAc,GACzB,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAqDjC,CAAA"}
|
|
@@ -34,84 +34,49 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
var __values = (this && this.__values) || function(o) {
|
|
38
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
39
|
-
if (m) return m.call(o);
|
|
40
|
-
if (o && typeof o.length === "number") return {
|
|
41
|
-
next: function () {
|
|
42
|
-
if (o && i >= o.length) o = void 0;
|
|
43
|
-
return { value: o && o[i++], done: !o };
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
47
|
-
};
|
|
48
|
-
// @ts-expect-error
|
|
49
|
-
import { loadYoga } from 'yoga-layout/load';
|
|
50
|
-
import { DEFAULT_PAPER_SIZE } from '../../utils';
|
|
51
37
|
import { GRID_SIZE } from './layout';
|
|
52
38
|
export var calc_boxes_pos = function (boxes) { return __awaiter(void 0, void 0, void 0, function () {
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
for (idList_2 = __values(idList), idList_2_1 = idList_2.next(); !idList_2_1.done; idList_2_1 = idList_2.next()) {
|
|
97
|
-
id = idList_2_1.value;
|
|
98
|
-
child = children_map[id];
|
|
99
|
-
result[id] = {
|
|
100
|
-
x: child.getComputedLeft() * GRID_SIZE,
|
|
101
|
-
y: child.getComputedTop() * GRID_SIZE,
|
|
102
|
-
};
|
|
103
|
-
child.free();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
107
|
-
finally {
|
|
108
|
-
try {
|
|
109
|
-
if (idList_2_1 && !idList_2_1.done && (_b = idList_2.return)) _b.call(idList_2);
|
|
110
|
-
}
|
|
111
|
-
finally { if (e_2) throw e_2.error; }
|
|
112
|
-
}
|
|
113
|
-
node.free();
|
|
114
|
-
return [2 /*return*/, result];
|
|
115
|
-
}
|
|
39
|
+
var idList, sizes, cols, rows, colWidths, rowHeights, margin, result;
|
|
40
|
+
return __generator(this, function (_a) {
|
|
41
|
+
idList = Object.keys(boxes);
|
|
42
|
+
if (idList.length === 0)
|
|
43
|
+
return [2 /*return*/, {}
|
|
44
|
+
// Convert sizes to logical units (grid space)
|
|
45
|
+
];
|
|
46
|
+
sizes = idList.map(function (id) {
|
|
47
|
+
var box = boxes[id];
|
|
48
|
+
return {
|
|
49
|
+
id: id,
|
|
50
|
+
w: box.x / GRID_SIZE,
|
|
51
|
+
h: box.y / GRID_SIZE,
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
cols = Math.ceil(Math.sqrt(idList.length));
|
|
55
|
+
rows = Math.ceil(idList.length / cols);
|
|
56
|
+
colWidths = Array(cols).fill(0);
|
|
57
|
+
rowHeights = Array(rows).fill(0);
|
|
58
|
+
sizes.forEach(function (s, i) {
|
|
59
|
+
var row = Math.floor(i / cols);
|
|
60
|
+
var col = i % cols;
|
|
61
|
+
colWidths[col] = Math.max(colWidths[col], s.w);
|
|
62
|
+
rowHeights[row] = Math.max(rowHeights[row], s.h);
|
|
63
|
+
});
|
|
64
|
+
margin = 1 // in grid units
|
|
65
|
+
;
|
|
66
|
+
result = {};
|
|
67
|
+
sizes.forEach(function (s, i) {
|
|
68
|
+
var row = Math.floor(i / cols);
|
|
69
|
+
var col = i % cols;
|
|
70
|
+
var prevColsWidth = colWidths.slice(0, col).reduce(function (a, b) { return a + b; }, 0);
|
|
71
|
+
var prevRowsHeight = rowHeights.slice(0, row).reduce(function (a, b) { return a + b; }, 0);
|
|
72
|
+
// Cell top-left position
|
|
73
|
+
var cellLeft = prevColsWidth + col * margin;
|
|
74
|
+
var cellTop = prevRowsHeight + row * margin;
|
|
75
|
+
// Center box inside cell
|
|
76
|
+
var x = (cellLeft + (colWidths[col] - s.w) / 2) * GRID_SIZE;
|
|
77
|
+
var y = (cellTop + (rowHeights[row] - s.h) / 2) * GRID_SIZE;
|
|
78
|
+
result[s.id] = { x: x, y: y };
|
|
79
|
+
});
|
|
80
|
+
return [2 /*return*/, result];
|
|
116
81
|
});
|
|
117
82
|
}); };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modular-circuit/transpiler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.83",
|
|
4
4
|
"description": "Intermediate representation of the modular circuit",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"files": [
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"js-base64": "^3.7.7",
|
|
28
28
|
"jszip": "^3.10.1",
|
|
29
29
|
"yoga-layout": "^3.2.1",
|
|
30
|
-
"@modular-circuit/electronics-model": "0.0.54",
|
|
31
|
-
"@modular-circuit/perc": "0.0.61",
|
|
32
30
|
"@modular-circuit/ir": "0.0.61",
|
|
33
|
-
"@modular-circuit/
|
|
31
|
+
"@modular-circuit/electronics-model": "0.0.54",
|
|
32
|
+
"@modular-circuit/utils": "0.0.40",
|
|
33
|
+
"@modular-circuit/perc": "0.0.61"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"clean": "rimraf build",
|