@modular-circuit/utils 0.0.34 → 0.0.35

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,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,21 +1,78 @@
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);
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 };
18
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; }
19
76
  }
20
77
  return ccs;
21
78
  }
@@ -1,31 +1,77 @@
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;
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
+ }
15
57
  }
16
58
  else {
17
- throw new Error(`Invalid port annotation for port ${v}: ${circuit.eda_port_annotations[v]}`);
59
+ // TODO : handel GND and VCC
60
+ // NOTE: Currently only GND and VCC will come here
61
+ labels[v] = LabelShapes.Output;
18
62
  }
19
63
  }
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;
64
+ else if (typeof v === 'object' && !Array.isArray(v) && v !== null) {
65
+ labels = __assign(__assign({}, labels), get_port_labels(v, circuit));
24
66
  }
25
67
  }
26
- else if (typeof v === 'object' && !Array.isArray(v) && v !== null) {
27
- labels = { ...labels, ...get_port_labels(v, circuit) };
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);
28
73
  }
74
+ finally { if (e_1) throw e_1.error; }
29
75
  }
30
76
  return labels;
31
77
  }
@@ -1,26 +1,91 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dfs = dfs;
4
- function dfs(G, start, visited = new Set(), visitors) {
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(); }
5
40
  visited.add(start);
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);
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; }
13
61
  }
14
62
  }
63
+ result.push.apply(result, __spreadArray([], __read(dfs(G, neighbor, visited, visitors)), false));
15
64
  }
16
- result.push(...dfs(G, neighbor, visited, visitors));
17
65
  }
18
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
+ }
19
74
  if (visitors) {
20
- for (const visitor of visitors) {
21
- if (visitor.visit_vertex) {
22
- visitor.visit_vertex(start);
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);
23
87
  }
88
+ finally { if (e_3) throw e_3.error; }
24
89
  }
25
90
  }
26
91
  return result;
@@ -1,24 +1,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);
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';
@@ -1,7 +1,4 @@
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 };
1
+ import { LabelShapes } from '@modular-circuit/electronics-model';
2
+ export function gen_passive_label(text) {
3
+ return { text: text, shape: LabelShapes.Passive };
7
4
  }
@@ -1,19 +1,30 @@
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('/');
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];
8
19
  author = author.substring(1);
9
20
  return {
10
- author,
11
- name,
21
+ author: author,
22
+ name: name,
12
23
  };
13
24
  }
14
- function fmt_module_name(idx) {
15
- return `@${idx.author}/${idx.name}`;
25
+ export function fmt_module_name(idx) {
26
+ return "@".concat(idx.author, "/").concat(idx.name);
16
27
  }
17
- function stringify_dependency(idx) {
18
- return `${fmt_module_name(idx)}@${idx.version}`;
28
+ export function stringify_dependency(idx) {
29
+ return "".concat(fmt_module_name(idx), "@").concat(idx.version);
19
30
  }
@@ -1,36 +1,65 @@
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;
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; }
13
31
  }
14
32
  return port_map;
15
33
  }
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
- });
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; }
27
56
  }
28
57
  return {
29
- uuid: (0, utility_1.gen_uuid)(),
58
+ uuid: gen_uuid(),
30
59
  type: {
31
60
  author: module.author,
32
61
  name: module.name,
33
62
  },
34
- ports,
63
+ ports: ports,
35
64
  };
36
65
  }
@@ -1,19 +1,10 @@
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);
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);
15
6
  }
16
- function replaceAll(str, search, replacement) {
17
- const regex = new RegExp(search, 'g');
7
+ export function replaceAll(str, search, replacement) {
8
+ var regex = new RegExp(search, 'g');
18
9
  return str.replace(regex, replacement);
19
10
  }
@@ -1,52 +1,117 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
+ });
4
9
  };
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;
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;
25
31
  }
26
- }
27
- return files;
28
- }
29
- catch (error) {
30
- console.error('Error unzipping file:', error);
31
- throw new Error('Failed to unzip file');
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 };
32
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
+ });
33
87
  }
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
- }
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
+ });
48
113
  }
49
- function remove_filename_path_prefix(name) {
50
- const names = name.split('/');
114
+ export function remove_filename_path_prefix(name) {
115
+ var names = name.split('/');
51
116
  return names[names.length - 1];
52
117
  }
package/build/index.js CHANGED
@@ -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);
1
+ export * from './functions';
2
+ export * from './constants';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modular-circuit/utils",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
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/ir": "0.0.56",
32
- "@modular-circuit/electronics-model": "0.0.48"
31
+ "@modular-circuit/electronics-model": "0.0.49",
32
+ "@modular-circuit/ir": "0.0.57"
33
33
  },
34
34
  "scripts": {
35
35
  "clean": "rimraf build",