@modular-circuit/utils 0.0.41 → 0.1.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.
- package/dist/index.d.mts +37 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +241 -0
- package/dist/index.mjs +189 -0
- package/package.json +13 -10
- package/build/constants/index.d.ts +0 -2
- package/build/constants/index.d.ts.map +0 -1
- package/build/constants/index.js +0 -1
- package/build/constants/kicad_file_ext.d.ts +0 -2
- package/build/constants/kicad_file_ext.d.ts.map +0 -1
- package/build/constants/kicad_file_ext.js +0 -1
- package/build/functions/connected_component.d.ts +0 -7
- package/build/functions/connected_component.d.ts.map +0 -1
- package/build/functions/connected_component.js +0 -78
- package/build/functions/get_port_labels.d.ts +0 -4
- package/build/functions/get_port_labels.d.ts.map +0 -1
- package/build/functions/get_port_labels.js +0 -77
- package/build/functions/graph.d.ts +0 -6
- package/build/functions/graph.d.ts.map +0 -1
- package/build/functions/graph.js +0 -92
- package/build/functions/index.d.ts +0 -9
- package/build/functions/index.d.ts.map +0 -1
- package/build/functions/index.js +0 -8
- package/build/functions/label.d.ts +0 -3
- package/build/functions/label.d.ts.map +0 -1
- package/build/functions/label.js +0 -4
- package/build/functions/module_name_parser.d.ts +0 -5
- package/build/functions/module_name_parser.d.ts.map +0 -1
- package/build/functions/module_name_parser.js +0 -30
- package/build/functions/place_module.d.ts +0 -5
- package/build/functions/place_module.d.ts.map +0 -1
- package/build/functions/place_module.js +0 -65
- package/build/functions/utility.d.ts +0 -4
- package/build/functions/utility.d.ts.map +0 -1
- package/build/functions/utility.js +0 -10
- package/build/functions/zip_utils.d.ts +0 -4
- package/build/functions/zip_utils.d.ts.map +0 -1
- package/build/functions/zip_utils.js +0 -117
- package/build/index.d.ts +0 -3
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -2
- package/build/tsconfig.build.tsbuildinfo +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { PortLike, LabelShapes } from '@modular-circuit/electronics-model';
|
|
2
|
+
import { ModuleCircuit, IR_Block, ModuleName, ModuleIndex, LABEL_META } from '@modular-circuit/ir';
|
|
3
|
+
|
|
4
|
+
declare const gen_uuid: () => string;
|
|
5
|
+
declare function deep_copy<T>(obj: T): T;
|
|
6
|
+
declare function replaceAll(str: string, search: string, replacement: string): string;
|
|
7
|
+
|
|
8
|
+
declare function get_circuit_ports(module: ModuleCircuit): Record<number, PortLike>;
|
|
9
|
+
declare function place_module(module: ModuleCircuit): IR_Block;
|
|
10
|
+
|
|
11
|
+
declare function parse_module_name(dep: string): ModuleName;
|
|
12
|
+
declare function fmt_module_name(idx: ModuleName): string;
|
|
13
|
+
declare function stringify_dependency(idx: ModuleIndex): string;
|
|
14
|
+
|
|
15
|
+
declare function gen_passive_label(text: string): LABEL_META;
|
|
16
|
+
|
|
17
|
+
interface GraphVisitor {
|
|
18
|
+
visit_vertex?(v: string): unknown;
|
|
19
|
+
visit_edge?(a: string, b: string): unknown;
|
|
20
|
+
}
|
|
21
|
+
declare function dfs(G: Record<string, Set<string>>, start: string, visited?: Set<string>, visitors?: GraphVisitor[]): string[];
|
|
22
|
+
|
|
23
|
+
interface CC_Visitor extends GraphVisitor {
|
|
24
|
+
start_visit_component?(): unknown;
|
|
25
|
+
end_visit_component?(cc: string[]): unknown;
|
|
26
|
+
}
|
|
27
|
+
declare function test_connected_components(G: Record<string, Set<string>>, visitors: CC_Visitor[]): string[][];
|
|
28
|
+
|
|
29
|
+
declare function unzipFile(file: ArrayBuffer | Blob): Promise<Record<string, string>>;
|
|
30
|
+
declare function zipFiles(files: Record<string, string>): Promise<Blob>;
|
|
31
|
+
declare function remove_filename_path_prefix(name: string): string;
|
|
32
|
+
|
|
33
|
+
declare function get_port_labels(port: PortLike, circuit: ModuleCircuit): Record<string, LabelShapes>;
|
|
34
|
+
|
|
35
|
+
declare const KICAD_SHC_FILE_EXT = ".kicad_sch";
|
|
36
|
+
|
|
37
|
+
export { type CC_Visitor, type GraphVisitor, KICAD_SHC_FILE_EXT, deep_copy, dfs, fmt_module_name, gen_passive_label, gen_uuid, get_circuit_ports, get_port_labels, parse_module_name, place_module, remove_filename_path_prefix, replaceAll, stringify_dependency, test_connected_components, unzipFile, zipFiles };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { PortLike, LabelShapes } from '@modular-circuit/electronics-model';
|
|
2
|
+
import { ModuleCircuit, IR_Block, ModuleName, ModuleIndex, LABEL_META } from '@modular-circuit/ir';
|
|
3
|
+
|
|
4
|
+
declare const gen_uuid: () => string;
|
|
5
|
+
declare function deep_copy<T>(obj: T): T;
|
|
6
|
+
declare function replaceAll(str: string, search: string, replacement: string): string;
|
|
7
|
+
|
|
8
|
+
declare function get_circuit_ports(module: ModuleCircuit): Record<number, PortLike>;
|
|
9
|
+
declare function place_module(module: ModuleCircuit): IR_Block;
|
|
10
|
+
|
|
11
|
+
declare function parse_module_name(dep: string): ModuleName;
|
|
12
|
+
declare function fmt_module_name(idx: ModuleName): string;
|
|
13
|
+
declare function stringify_dependency(idx: ModuleIndex): string;
|
|
14
|
+
|
|
15
|
+
declare function gen_passive_label(text: string): LABEL_META;
|
|
16
|
+
|
|
17
|
+
interface GraphVisitor {
|
|
18
|
+
visit_vertex?(v: string): unknown;
|
|
19
|
+
visit_edge?(a: string, b: string): unknown;
|
|
20
|
+
}
|
|
21
|
+
declare function dfs(G: Record<string, Set<string>>, start: string, visited?: Set<string>, visitors?: GraphVisitor[]): string[];
|
|
22
|
+
|
|
23
|
+
interface CC_Visitor extends GraphVisitor {
|
|
24
|
+
start_visit_component?(): unknown;
|
|
25
|
+
end_visit_component?(cc: string[]): unknown;
|
|
26
|
+
}
|
|
27
|
+
declare function test_connected_components(G: Record<string, Set<string>>, visitors: CC_Visitor[]): string[][];
|
|
28
|
+
|
|
29
|
+
declare function unzipFile(file: ArrayBuffer | Blob): Promise<Record<string, string>>;
|
|
30
|
+
declare function zipFiles(files: Record<string, string>): Promise<Blob>;
|
|
31
|
+
declare function remove_filename_path_prefix(name: string): string;
|
|
32
|
+
|
|
33
|
+
declare function get_port_labels(port: PortLike, circuit: ModuleCircuit): Record<string, LabelShapes>;
|
|
34
|
+
|
|
35
|
+
declare const KICAD_SHC_FILE_EXT = ".kicad_sch";
|
|
36
|
+
|
|
37
|
+
export { type CC_Visitor, type GraphVisitor, KICAD_SHC_FILE_EXT, deep_copy, dfs, fmt_module_name, gen_passive_label, gen_uuid, get_circuit_ports, get_port_labels, parse_module_name, place_module, remove_filename_path_prefix, replaceAll, stringify_dependency, test_connected_components, unzipFile, zipFiles };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
KICAD_SHC_FILE_EXT: () => KICAD_SHC_FILE_EXT,
|
|
34
|
+
deep_copy: () => deep_copy,
|
|
35
|
+
dfs: () => dfs,
|
|
36
|
+
fmt_module_name: () => fmt_module_name,
|
|
37
|
+
gen_passive_label: () => gen_passive_label,
|
|
38
|
+
gen_uuid: () => gen_uuid,
|
|
39
|
+
get_circuit_ports: () => get_circuit_ports,
|
|
40
|
+
get_port_labels: () => get_port_labels,
|
|
41
|
+
parse_module_name: () => parse_module_name,
|
|
42
|
+
place_module: () => place_module,
|
|
43
|
+
remove_filename_path_prefix: () => remove_filename_path_prefix,
|
|
44
|
+
replaceAll: () => replaceAll,
|
|
45
|
+
stringify_dependency: () => stringify_dependency,
|
|
46
|
+
test_connected_components: () => test_connected_components,
|
|
47
|
+
unzipFile: () => unzipFile,
|
|
48
|
+
zipFiles: () => zipFiles
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(index_exports);
|
|
51
|
+
|
|
52
|
+
// src/functions/utility.ts
|
|
53
|
+
var import_lodash = __toESM(require("lodash"));
|
|
54
|
+
var import_uuid = require("uuid");
|
|
55
|
+
var gen_uuid = () => (0, import_uuid.v4)();
|
|
56
|
+
function deep_copy(obj) {
|
|
57
|
+
return import_lodash.default.cloneDeep(obj);
|
|
58
|
+
}
|
|
59
|
+
function replaceAll(str, search, replacement) {
|
|
60
|
+
const regex = new RegExp(search, "g");
|
|
61
|
+
return str.replace(regex, replacement);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/functions/place_module.ts
|
|
65
|
+
var import_electronics_model2 = require("@modular-circuit/electronics-model");
|
|
66
|
+
|
|
67
|
+
// src/functions/get_port_labels.ts
|
|
68
|
+
var import_electronics_model = require("@modular-circuit/electronics-model");
|
|
69
|
+
function get_port_labels(port, circuit) {
|
|
70
|
+
let labels = {};
|
|
71
|
+
for (const [k, v] of Object.entries(port)) {
|
|
72
|
+
if (k === import_electronics_model.LABEL_ASSOCIATED && typeof v === "string") {
|
|
73
|
+
if (circuit.eda_port_annotations[v]) {
|
|
74
|
+
if ("shape" in circuit.eda_port_annotations[v] && circuit.eda_port_annotations[v].shape !== null) {
|
|
75
|
+
labels[v] = circuit.eda_port_annotations[v].shape;
|
|
76
|
+
} else if ("lib_id" in circuit.eda_port_annotations[v] && circuit.eda_port_annotations[v].lib_id !== null) {
|
|
77
|
+
labels[v] = import_electronics_model.LabelShapes.Input;
|
|
78
|
+
} else {
|
|
79
|
+
throw new Error(`Invalid port annotation for port ${v}: ${circuit.eda_port_annotations[v]}`);
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
labels[v] = import_electronics_model.LabelShapes.Output;
|
|
83
|
+
}
|
|
84
|
+
} else if (typeof v === "object" && !Array.isArray(v) && v !== null) {
|
|
85
|
+
labels = { ...labels, ...get_port_labels(v, circuit) };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return labels;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/functions/place_module.ts
|
|
92
|
+
function get_circuit_ports(module2) {
|
|
93
|
+
const port_map = {};
|
|
94
|
+
let index = 0;
|
|
95
|
+
for (const port of module2.ports) {
|
|
96
|
+
port_map[index++] = port;
|
|
97
|
+
}
|
|
98
|
+
return port_map;
|
|
99
|
+
}
|
|
100
|
+
function place_module(module2) {
|
|
101
|
+
const ports = [];
|
|
102
|
+
let index = 0;
|
|
103
|
+
for (const it of module2.ports) {
|
|
104
|
+
ports.push({
|
|
105
|
+
index: index++,
|
|
106
|
+
uuid: gen_uuid(),
|
|
107
|
+
name: it.name,
|
|
108
|
+
shape: (0, import_electronics_model2.merge_port_label_shapes)(get_port_labels(it, module2)),
|
|
109
|
+
type: it.type
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
uuid: gen_uuid(),
|
|
114
|
+
type: {
|
|
115
|
+
author: module2.author,
|
|
116
|
+
name: module2.name
|
|
117
|
+
},
|
|
118
|
+
ports
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/functions/module_name_parser.ts
|
|
123
|
+
function parse_module_name(dep) {
|
|
124
|
+
let [author, name] = dep.split("/");
|
|
125
|
+
author = author.substring(1);
|
|
126
|
+
return {
|
|
127
|
+
author,
|
|
128
|
+
name
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function fmt_module_name(idx) {
|
|
132
|
+
return `@${idx.author}/${idx.name}`;
|
|
133
|
+
}
|
|
134
|
+
function stringify_dependency(idx) {
|
|
135
|
+
return `${fmt_module_name(idx)}@${idx.version}`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/functions/label.ts
|
|
139
|
+
var import_electronics_model3 = require("@modular-circuit/electronics-model");
|
|
140
|
+
function gen_passive_label(text) {
|
|
141
|
+
return { text, shape: import_electronics_model3.LabelShapes.Passive };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/functions/graph.ts
|
|
145
|
+
function dfs(G, start, visited = /* @__PURE__ */ new Set(), visitors) {
|
|
146
|
+
visited.add(start);
|
|
147
|
+
const result = [start];
|
|
148
|
+
for (const neighbor of G[start]) {
|
|
149
|
+
if (!visited.has(neighbor)) {
|
|
150
|
+
if (visitors) {
|
|
151
|
+
for (const visitor of visitors) {
|
|
152
|
+
if (visitor.visit_edge) {
|
|
153
|
+
visitor.visit_edge(start, neighbor);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
result.push(...dfs(G, neighbor, visited, visitors));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (visitors) {
|
|
161
|
+
for (const visitor of visitors) {
|
|
162
|
+
if (visitor.visit_vertex) {
|
|
163
|
+
visitor.visit_vertex(start);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/functions/connected_component.ts
|
|
171
|
+
function test_connected_components(G, visitors) {
|
|
172
|
+
const ccs = [];
|
|
173
|
+
const visited = /* @__PURE__ */ new Set();
|
|
174
|
+
for (const [k] of Object.entries(G)) {
|
|
175
|
+
if (!visited.has(k)) {
|
|
176
|
+
for (const v of visitors) if (v.start_visit_component) v.start_visit_component();
|
|
177
|
+
const cc = dfs(G, k, visited, visitors);
|
|
178
|
+
ccs.push(cc);
|
|
179
|
+
for (const v of visitors) if (v.end_visit_component) v.end_visit_component(cc);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return ccs;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// src/functions/zip_utils.ts
|
|
186
|
+
var import_jszip = __toESM(require("jszip"));
|
|
187
|
+
async function unzipFile(file) {
|
|
188
|
+
const zip = new import_jszip.default();
|
|
189
|
+
try {
|
|
190
|
+
const content = await zip.loadAsync(file);
|
|
191
|
+
const files = {};
|
|
192
|
+
for (const fileName in content.files) {
|
|
193
|
+
if (fileName in content.files) {
|
|
194
|
+
const fileData = content.files[fileName];
|
|
195
|
+
const fileText = await fileData.async("text");
|
|
196
|
+
files[fileName] = fileText;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return files;
|
|
200
|
+
} catch (error) {
|
|
201
|
+
console.error("Error unzipping file:", error);
|
|
202
|
+
throw new Error("Failed to unzip file");
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async function zipFiles(files) {
|
|
206
|
+
const zip = new import_jszip.default();
|
|
207
|
+
for (const filePath in files) zip.file(filePath, files[filePath]);
|
|
208
|
+
try {
|
|
209
|
+
const blob = await zip.generateAsync({ type: "blob" });
|
|
210
|
+
return blob;
|
|
211
|
+
} catch (error) {
|
|
212
|
+
console.error("Error creating zip:", error);
|
|
213
|
+
throw new Error("Failed to create zip file");
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function remove_filename_path_prefix(name) {
|
|
217
|
+
const names = name.split("/");
|
|
218
|
+
return names[names.length - 1];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/constants/kicad_file_ext.ts
|
|
222
|
+
var KICAD_SHC_FILE_EXT = ".kicad_sch";
|
|
223
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
224
|
+
0 && (module.exports = {
|
|
225
|
+
KICAD_SHC_FILE_EXT,
|
|
226
|
+
deep_copy,
|
|
227
|
+
dfs,
|
|
228
|
+
fmt_module_name,
|
|
229
|
+
gen_passive_label,
|
|
230
|
+
gen_uuid,
|
|
231
|
+
get_circuit_ports,
|
|
232
|
+
get_port_labels,
|
|
233
|
+
parse_module_name,
|
|
234
|
+
place_module,
|
|
235
|
+
remove_filename_path_prefix,
|
|
236
|
+
replaceAll,
|
|
237
|
+
stringify_dependency,
|
|
238
|
+
test_connected_components,
|
|
239
|
+
unzipFile,
|
|
240
|
+
zipFiles
|
|
241
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// src/functions/utility.ts
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
import { v4 as uuidv4 } from "uuid";
|
|
4
|
+
var gen_uuid = () => uuidv4();
|
|
5
|
+
function deep_copy(obj) {
|
|
6
|
+
return _.cloneDeep(obj);
|
|
7
|
+
}
|
|
8
|
+
function replaceAll(str, search, replacement) {
|
|
9
|
+
const regex = new RegExp(search, "g");
|
|
10
|
+
return str.replace(regex, replacement);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/functions/place_module.ts
|
|
14
|
+
import { merge_port_label_shapes } from "@modular-circuit/electronics-model";
|
|
15
|
+
|
|
16
|
+
// src/functions/get_port_labels.ts
|
|
17
|
+
import { LABEL_ASSOCIATED, LabelShapes } from "@modular-circuit/electronics-model";
|
|
18
|
+
function get_port_labels(port, circuit) {
|
|
19
|
+
let labels = {};
|
|
20
|
+
for (const [k, v] of Object.entries(port)) {
|
|
21
|
+
if (k === LABEL_ASSOCIATED && typeof v === "string") {
|
|
22
|
+
if (circuit.eda_port_annotations[v]) {
|
|
23
|
+
if ("shape" in circuit.eda_port_annotations[v] && circuit.eda_port_annotations[v].shape !== null) {
|
|
24
|
+
labels[v] = circuit.eda_port_annotations[v].shape;
|
|
25
|
+
} else if ("lib_id" in circuit.eda_port_annotations[v] && circuit.eda_port_annotations[v].lib_id !== null) {
|
|
26
|
+
labels[v] = LabelShapes.Input;
|
|
27
|
+
} else {
|
|
28
|
+
throw new Error(`Invalid port annotation for port ${v}: ${circuit.eda_port_annotations[v]}`);
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
labels[v] = LabelShapes.Output;
|
|
32
|
+
}
|
|
33
|
+
} else if (typeof v === "object" && !Array.isArray(v) && v !== null) {
|
|
34
|
+
labels = { ...labels, ...get_port_labels(v, circuit) };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return labels;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/functions/place_module.ts
|
|
41
|
+
function get_circuit_ports(module) {
|
|
42
|
+
const port_map = {};
|
|
43
|
+
let index = 0;
|
|
44
|
+
for (const port of module.ports) {
|
|
45
|
+
port_map[index++] = port;
|
|
46
|
+
}
|
|
47
|
+
return port_map;
|
|
48
|
+
}
|
|
49
|
+
function place_module(module) {
|
|
50
|
+
const ports = [];
|
|
51
|
+
let index = 0;
|
|
52
|
+
for (const it of module.ports) {
|
|
53
|
+
ports.push({
|
|
54
|
+
index: index++,
|
|
55
|
+
uuid: gen_uuid(),
|
|
56
|
+
name: it.name,
|
|
57
|
+
shape: merge_port_label_shapes(get_port_labels(it, module)),
|
|
58
|
+
type: it.type
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
uuid: gen_uuid(),
|
|
63
|
+
type: {
|
|
64
|
+
author: module.author,
|
|
65
|
+
name: module.name
|
|
66
|
+
},
|
|
67
|
+
ports
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/functions/module_name_parser.ts
|
|
72
|
+
function parse_module_name(dep) {
|
|
73
|
+
let [author, name] = dep.split("/");
|
|
74
|
+
author = author.substring(1);
|
|
75
|
+
return {
|
|
76
|
+
author,
|
|
77
|
+
name
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function fmt_module_name(idx) {
|
|
81
|
+
return `@${idx.author}/${idx.name}`;
|
|
82
|
+
}
|
|
83
|
+
function stringify_dependency(idx) {
|
|
84
|
+
return `${fmt_module_name(idx)}@${idx.version}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/functions/label.ts
|
|
88
|
+
import { LabelShapes as LabelShapes2 } from "@modular-circuit/electronics-model";
|
|
89
|
+
function gen_passive_label(text) {
|
|
90
|
+
return { text, shape: LabelShapes2.Passive };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/functions/graph.ts
|
|
94
|
+
function dfs(G, start, visited = /* @__PURE__ */ new Set(), visitors) {
|
|
95
|
+
visited.add(start);
|
|
96
|
+
const result = [start];
|
|
97
|
+
for (const neighbor of G[start]) {
|
|
98
|
+
if (!visited.has(neighbor)) {
|
|
99
|
+
if (visitors) {
|
|
100
|
+
for (const visitor of visitors) {
|
|
101
|
+
if (visitor.visit_edge) {
|
|
102
|
+
visitor.visit_edge(start, neighbor);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
result.push(...dfs(G, neighbor, visited, visitors));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (visitors) {
|
|
110
|
+
for (const visitor of visitors) {
|
|
111
|
+
if (visitor.visit_vertex) {
|
|
112
|
+
visitor.visit_vertex(start);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/functions/connected_component.ts
|
|
120
|
+
function test_connected_components(G, visitors) {
|
|
121
|
+
const ccs = [];
|
|
122
|
+
const visited = /* @__PURE__ */ new Set();
|
|
123
|
+
for (const [k] of Object.entries(G)) {
|
|
124
|
+
if (!visited.has(k)) {
|
|
125
|
+
for (const v of visitors) if (v.start_visit_component) v.start_visit_component();
|
|
126
|
+
const cc = dfs(G, k, visited, visitors);
|
|
127
|
+
ccs.push(cc);
|
|
128
|
+
for (const v of visitors) if (v.end_visit_component) v.end_visit_component(cc);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return ccs;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/functions/zip_utils.ts
|
|
135
|
+
import JSZip from "jszip";
|
|
136
|
+
async function unzipFile(file) {
|
|
137
|
+
const zip = new JSZip();
|
|
138
|
+
try {
|
|
139
|
+
const content = await zip.loadAsync(file);
|
|
140
|
+
const files = {};
|
|
141
|
+
for (const fileName in content.files) {
|
|
142
|
+
if (fileName in content.files) {
|
|
143
|
+
const fileData = content.files[fileName];
|
|
144
|
+
const fileText = await fileData.async("text");
|
|
145
|
+
files[fileName] = fileText;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return files;
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error("Error unzipping file:", error);
|
|
151
|
+
throw new Error("Failed to unzip file");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async function zipFiles(files) {
|
|
155
|
+
const zip = new JSZip();
|
|
156
|
+
for (const filePath in files) zip.file(filePath, files[filePath]);
|
|
157
|
+
try {
|
|
158
|
+
const blob = await zip.generateAsync({ type: "blob" });
|
|
159
|
+
return blob;
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error("Error creating zip:", error);
|
|
162
|
+
throw new Error("Failed to create zip file");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function remove_filename_path_prefix(name) {
|
|
166
|
+
const names = name.split("/");
|
|
167
|
+
return names[names.length - 1];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/constants/kicad_file_ext.ts
|
|
171
|
+
var KICAD_SHC_FILE_EXT = ".kicad_sch";
|
|
172
|
+
export {
|
|
173
|
+
KICAD_SHC_FILE_EXT,
|
|
174
|
+
deep_copy,
|
|
175
|
+
dfs,
|
|
176
|
+
fmt_module_name,
|
|
177
|
+
gen_passive_label,
|
|
178
|
+
gen_uuid,
|
|
179
|
+
get_circuit_ports,
|
|
180
|
+
get_port_labels,
|
|
181
|
+
parse_module_name,
|
|
182
|
+
place_module,
|
|
183
|
+
remove_filename_path_prefix,
|
|
184
|
+
replaceAll,
|
|
185
|
+
stringify_dependency,
|
|
186
|
+
test_connected_components,
|
|
187
|
+
unzipFile,
|
|
188
|
+
zipFiles
|
|
189
|
+
};
|
package/package.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modular-circuit/utils",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Intermediate representation of the modular circuit",
|
|
5
|
-
"main": "./
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
6
8
|
"exports": {
|
|
7
9
|
".": {
|
|
8
|
-
"import": "./
|
|
9
|
-
"require": "./
|
|
10
|
-
"types": "./
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
11
13
|
}
|
|
12
14
|
},
|
|
13
15
|
"files": [
|
|
14
|
-
"
|
|
16
|
+
"dist"
|
|
15
17
|
],
|
|
16
18
|
"keywords": [],
|
|
17
19
|
"author": "",
|
|
@@ -19,6 +21,7 @@
|
|
|
19
21
|
"devDependencies": {
|
|
20
22
|
"@biomejs/biome": "^1.8.3",
|
|
21
23
|
"@types/lodash": "^4.17.10",
|
|
24
|
+
"@types/node": "20.9.0",
|
|
22
25
|
"@types/uuid": "^10.0.0",
|
|
23
26
|
"esbuild": "^0.20.2",
|
|
24
27
|
"tsup": "^8.3.0",
|
|
@@ -28,13 +31,13 @@
|
|
|
28
31
|
"jszip": "^3.10.1",
|
|
29
32
|
"lodash": "^4.17.21",
|
|
30
33
|
"uuid": "^10.0.0",
|
|
31
|
-
"@modular-circuit/electronics-model": "0.0
|
|
32
|
-
"@modular-circuit/ir": "0.0
|
|
34
|
+
"@modular-circuit/electronics-model": "0.1.0",
|
|
35
|
+
"@modular-circuit/ir": "0.1.0"
|
|
33
36
|
},
|
|
34
37
|
"scripts": {
|
|
35
|
-
"clean": "rimraf
|
|
38
|
+
"clean": "rimraf dist",
|
|
36
39
|
"prebuild": "pnpm clean",
|
|
37
|
-
"build": "
|
|
40
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean --tsconfig tsconfig.build.json",
|
|
38
41
|
"lint:ci": "biome ci",
|
|
39
42
|
"lint": "biome check --fix --unsafe",
|
|
40
43
|
"test:unit": "vitest --workspace ../../vitest.workspace.ts --project unit run"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
|
package/build/constants/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './kicad_file_ext';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kicad_file_ext.d.ts","sourceRoot":"","sources":["../../src/constants/kicad_file_ext.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,eAAe,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export var KICAD_SHC_FILE_EXT = ".kicad_sch";
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,78 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,77 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/build/functions/graph.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/build/functions/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/build/functions/label.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,117 +0,0 @@
|
|
|
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
|
-
}
|
package/build/index.d.ts
DELETED
package/build/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["../src/index.ts","../src/constants/index.ts","../src/constants/kicad_file_ext.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"}
|