@tscircuit/circuit-json-util 0.0.131 → 0.0.133
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.ts +3 -61
- package/dist/index.js +24 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as circuit_json from 'circuit-json';
|
|
2
|
-
import { AnyCircuitElementInput, AnyCircuitElement, InsertionDirection, PcbSolderPasteRect, PcbSolderPasteRotatedRect, PcbBoard, SchematicComponent, SchematicNetLabel, SchematicTrace, SourceGroup, SourceComponentBase, PcbRenderLayer, PcbVia, PcbPin1Location, Point as Point$2, PcbPlatedHole, PcbCopperPour, PcbSmtPad } from 'circuit-json';
|
|
2
|
+
import { AnyCircuitElementInput, AnyCircuitElement, InsertionDirection, PcbSolderPasteRect, PcbSolderPasteRotatedRect, PcbSolderPastePill, PcbSolderPasteRotatedPill, PcbBoard, SchematicComponent, SchematicNetLabel, SchematicTrace, SourceGroup, SourceComponentBase, PcbRenderLayer, PcbVia, PcbPin1Location, Point as Point$2, PcbPlatedHole, PcbCopperPour, PcbSmtPad } from 'circuit-json';
|
|
3
3
|
import * as zod from 'zod';
|
|
4
4
|
import { Matrix } from 'transformation-matrix';
|
|
5
5
|
import * as parsel from 'parsel-js';
|
|
@@ -13231,35 +13231,6 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
|
|
|
13231
13231
|
subcircuit_id?: string | undefined;
|
|
13232
13232
|
pcb_group_id?: string | undefined;
|
|
13233
13233
|
pcb_smtpad_id?: string | undefined;
|
|
13234
|
-
} | {
|
|
13235
|
-
type: "pcb_solder_paste";
|
|
13236
|
-
x: number;
|
|
13237
|
-
y: number;
|
|
13238
|
-
width: number;
|
|
13239
|
-
height: number;
|
|
13240
|
-
shape: "pill";
|
|
13241
|
-
radius: number;
|
|
13242
|
-
layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
|
|
13243
|
-
pcb_solder_paste_id: string;
|
|
13244
|
-
pcb_component_id?: string | undefined;
|
|
13245
|
-
subcircuit_id?: string | undefined;
|
|
13246
|
-
pcb_group_id?: string | undefined;
|
|
13247
|
-
pcb_smtpad_id?: string | undefined;
|
|
13248
|
-
} | {
|
|
13249
|
-
type: "pcb_solder_paste";
|
|
13250
|
-
x: number;
|
|
13251
|
-
y: number;
|
|
13252
|
-
width: number;
|
|
13253
|
-
height: number;
|
|
13254
|
-
shape: "rotated_pill";
|
|
13255
|
-
radius: number;
|
|
13256
|
-
ccw_rotation: number;
|
|
13257
|
-
layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
|
|
13258
|
-
pcb_solder_paste_id: string;
|
|
13259
|
-
pcb_component_id?: string | undefined;
|
|
13260
|
-
subcircuit_id?: string | undefined;
|
|
13261
|
-
pcb_group_id?: string | undefined;
|
|
13262
|
-
pcb_smtpad_id?: string | undefined;
|
|
13263
13234
|
} | {
|
|
13264
13235
|
type: "pcb_solder_paste";
|
|
13265
13236
|
x: number;
|
|
@@ -16810,7 +16781,7 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
|
|
|
16810
16781
|
simulation_spice_subcircuit_id: string;
|
|
16811
16782
|
spice_pin_to_source_port_map: Record<string, string>;
|
|
16812
16783
|
subcircuit_source: string;
|
|
16813
|
-
} | PcbSolderPasteRect | PcbSolderPasteRotatedRect | circuit_json.PcbSoldermaskOpeningCircle | circuit_json.PcbSoldermaskOpeningRect | circuit_json.PcbSoldermaskOpeningRotatedRect | circuit_json.PcbSoldermaskOpeningPolygon;
|
|
16784
|
+
} | PcbSolderPasteRect | PcbSolderPasteRotatedRect | PcbSolderPastePill | PcbSolderPasteRotatedPill | circuit_json.PcbSoldermaskOpeningCircle | circuit_json.PcbSoldermaskOpeningRect | circuit_json.PcbSoldermaskOpeningRotatedRect | circuit_json.PcbSoldermaskOpeningPolygon;
|
|
16814
16785
|
declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix) => ({
|
|
16815
16786
|
message: string;
|
|
16816
16787
|
type: "source_runtime_error";
|
|
@@ -18517,35 +18488,6 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
|
|
|
18517
18488
|
subcircuit_id?: string | undefined;
|
|
18518
18489
|
pcb_group_id?: string | undefined;
|
|
18519
18490
|
pcb_smtpad_id?: string | undefined;
|
|
18520
|
-
} | {
|
|
18521
|
-
type: "pcb_solder_paste";
|
|
18522
|
-
x: number;
|
|
18523
|
-
y: number;
|
|
18524
|
-
width: number;
|
|
18525
|
-
height: number;
|
|
18526
|
-
shape: "pill";
|
|
18527
|
-
radius: number;
|
|
18528
|
-
layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
|
|
18529
|
-
pcb_solder_paste_id: string;
|
|
18530
|
-
pcb_component_id?: string | undefined;
|
|
18531
|
-
subcircuit_id?: string | undefined;
|
|
18532
|
-
pcb_group_id?: string | undefined;
|
|
18533
|
-
pcb_smtpad_id?: string | undefined;
|
|
18534
|
-
} | {
|
|
18535
|
-
type: "pcb_solder_paste";
|
|
18536
|
-
x: number;
|
|
18537
|
-
y: number;
|
|
18538
|
-
width: number;
|
|
18539
|
-
height: number;
|
|
18540
|
-
shape: "rotated_pill";
|
|
18541
|
-
radius: number;
|
|
18542
|
-
ccw_rotation: number;
|
|
18543
|
-
layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
|
|
18544
|
-
pcb_solder_paste_id: string;
|
|
18545
|
-
pcb_component_id?: string | undefined;
|
|
18546
|
-
subcircuit_id?: string | undefined;
|
|
18547
|
-
pcb_group_id?: string | undefined;
|
|
18548
|
-
pcb_smtpad_id?: string | undefined;
|
|
18549
18491
|
} | {
|
|
18550
18492
|
type: "pcb_solder_paste";
|
|
18551
18493
|
x: number;
|
|
@@ -22096,7 +22038,7 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
|
|
|
22096
22038
|
simulation_spice_subcircuit_id: string;
|
|
22097
22039
|
spice_pin_to_source_port_map: Record<string, string>;
|
|
22098
22040
|
subcircuit_source: string;
|
|
22099
|
-
} | PcbSolderPasteRect | PcbSolderPasteRotatedRect | circuit_json.PcbSoldermaskOpeningCircle | circuit_json.PcbSoldermaskOpeningRect | circuit_json.PcbSoldermaskOpeningRotatedRect | circuit_json.PcbSoldermaskOpeningPolygon)[];
|
|
22041
|
+
} | PcbSolderPasteRect | PcbSolderPasteRotatedRect | PcbSolderPastePill | PcbSolderPasteRotatedPill | circuit_json.PcbSoldermaskOpeningCircle | circuit_json.PcbSoldermaskOpeningRect | circuit_json.PcbSoldermaskOpeningRotatedRect | circuit_json.PcbSoldermaskOpeningPolygon)[];
|
|
22100
22042
|
|
|
22101
22043
|
declare const directionToVec: (direction: "up" | "down" | "left" | "right") => {
|
|
22102
22044
|
x: number;
|
package/dist/index.js
CHANGED
|
@@ -192,7 +192,7 @@ var cju = ((circuitJsonInput, options = {}) => {
|
|
|
192
192
|
return {
|
|
193
193
|
get: (id) => circuitJson.find(
|
|
194
194
|
(e) => e.type === component_type && e[`${component_type}_id`] === id
|
|
195
|
-
),
|
|
195
|
+
) ?? null,
|
|
196
196
|
getUsing: (using) => {
|
|
197
197
|
const keys = Object.keys(using);
|
|
198
198
|
if (keys.length !== 1) {
|
|
@@ -208,13 +208,13 @@ var cju = ((circuitJsonInput, options = {}) => {
|
|
|
208
208
|
if (!joiner) return null;
|
|
209
209
|
return circuitJson.find(
|
|
210
210
|
(e) => e.type === component_type && e[`${component_type}_id`] === joiner[`${component_type}_id`]
|
|
211
|
-
);
|
|
211
|
+
) ?? null;
|
|
212
212
|
},
|
|
213
213
|
getWhere: (where) => {
|
|
214
214
|
const keys = Object.keys(where);
|
|
215
215
|
return circuitJson.find(
|
|
216
216
|
(e) => e.type === component_type && keys.every((key) => e[key] === where[key])
|
|
217
|
-
);
|
|
217
|
+
) ?? null;
|
|
218
218
|
},
|
|
219
219
|
list: (where) => {
|
|
220
220
|
const keys = !where ? [] : Object.keys(where);
|
|
@@ -260,7 +260,7 @@ var cju = ((circuitJsonInput, options = {}) => {
|
|
|
260
260
|
if (component_type === "source_component") {
|
|
261
261
|
return circuitJson.find(
|
|
262
262
|
(e) => e.type === "source_component" && e.name === selector.replace(/\./g, "")
|
|
263
|
-
);
|
|
263
|
+
) ?? null;
|
|
264
264
|
} else if (component_type === "pcb_port" || component_type === "source_port" || component_type === "schematic_port") {
|
|
265
265
|
const [component_name, port_selector] = selector.replace(/\./g, "").split(/[\s\>]+/);
|
|
266
266
|
const source_component = circuitJson.find(
|
|
@@ -275,13 +275,14 @@ var cju = ((circuitJsonInput, options = {}) => {
|
|
|
275
275
|
if (component_type === "pcb_port") {
|
|
276
276
|
return circuitJson.find(
|
|
277
277
|
(e) => e.type === "pcb_port" && e.source_port_id === source_port.source_port_id
|
|
278
|
-
);
|
|
278
|
+
) ?? null;
|
|
279
279
|
} else if (component_type === "schematic_port") {
|
|
280
280
|
return circuitJson.find(
|
|
281
281
|
(e) => e.type === "schematic_port" && e.source_port_id === source_port.source_port_id
|
|
282
|
-
);
|
|
282
|
+
) ?? null;
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
|
+
return null;
|
|
285
286
|
}
|
|
286
287
|
};
|
|
287
288
|
}
|
|
@@ -1025,12 +1026,13 @@ var getTransformedRectRotation = (rotation, matrix) => {
|
|
|
1025
1026
|
const isReflected = matrix.a * matrix.d - matrix.b * matrix.c < 0;
|
|
1026
1027
|
return decomposeTSR(compose(matrix, rotateDEG(rotation)), false, isReflected).rotation.angle * 180 / Math.PI;
|
|
1027
1028
|
};
|
|
1028
|
-
var
|
|
1029
|
+
var transformPcbSolderPasteRectOrPill = (paste, matrix) => {
|
|
1029
1030
|
const center = applyToPoint2(matrix, { x: paste.x, y: paste.y });
|
|
1030
1031
|
paste.x = center.x;
|
|
1031
1032
|
paste.y = center.y;
|
|
1033
|
+
const isPill = paste.shape === "pill" || paste.shape === "rotated_pill";
|
|
1032
1034
|
const rotation = getTransformedRectRotation(
|
|
1033
|
-
|
|
1035
|
+
"ccw_rotation" in paste ? paste.ccw_rotation : 0,
|
|
1034
1036
|
matrix
|
|
1035
1037
|
);
|
|
1036
1038
|
const quarterTurns = Math.round(rotation / 90);
|
|
@@ -1039,10 +1041,13 @@ var transformPcbSolderPasteRectangle = (paste, matrix) => {
|
|
|
1039
1041
|
;
|
|
1040
1042
|
[paste.width, paste.height] = [paste.height, paste.width];
|
|
1041
1043
|
}
|
|
1042
|
-
Object.assign(paste, { shape: "rect" });
|
|
1044
|
+
Object.assign(paste, { shape: isPill ? "pill" : "rect" });
|
|
1043
1045
|
Reflect.deleteProperty(paste, "ccw_rotation");
|
|
1044
1046
|
} else {
|
|
1045
|
-
Object.assign(paste, {
|
|
1047
|
+
Object.assign(paste, {
|
|
1048
|
+
shape: isPill ? "rotated_pill" : "rotated_rect",
|
|
1049
|
+
ccw_rotation: rotation
|
|
1050
|
+
});
|
|
1046
1051
|
}
|
|
1047
1052
|
return paste;
|
|
1048
1053
|
};
|
|
@@ -1089,8 +1094,8 @@ var transformPCBElement = (elm, matrix) => {
|
|
|
1089
1094
|
if (elm.type === "pcb_soldermask_opening") {
|
|
1090
1095
|
return transformPcbSoldermaskOpening(elm, matrix);
|
|
1091
1096
|
}
|
|
1092
|
-
if (elm.type === "pcb_solder_paste" && (elm.shape === "rect" || elm.shape === "rotated_rect")) {
|
|
1093
|
-
return
|
|
1097
|
+
if (elm.type === "pcb_solder_paste" && (elm.shape === "rect" || elm.shape === "rotated_rect" || elm.shape === "pill" || elm.shape === "rotated_pill")) {
|
|
1098
|
+
return transformPcbSolderPasteRectOrPill(elm, matrix);
|
|
1094
1099
|
}
|
|
1095
1100
|
if ((elm.type === "pcb_smtpad" || elm.type === "pcb_solder_paste") && elm.shape === "polygon") {
|
|
1096
1101
|
elm.points = elm.points.map((point) => applyToPoint2(matrix, point));
|
|
@@ -1112,8 +1117,11 @@ var transformPCBElement = (elm, matrix) => {
|
|
|
1112
1117
|
});
|
|
1113
1118
|
elm.x = x;
|
|
1114
1119
|
elm.y = y;
|
|
1115
|
-
if (elm.type === "pcb_smtpad" && (elm.shape === "rotated_rect" || elm.shape === "rotated_pill")) {
|
|
1116
|
-
elm.ccw_rotation = getTransformedRectRotation(
|
|
1120
|
+
if (elm.type === "pcb_smtpad" && (elm.shape === "rotated_rect" || elm.shape === "rotated_pill") || elm.type === "pcb_plated_hole" && (elm.shape === "pill" || elm.shape === "oval")) {
|
|
1121
|
+
elm.ccw_rotation = getTransformedRectRotation(
|
|
1122
|
+
elm.ccw_rotation ?? 0,
|
|
1123
|
+
matrix
|
|
1124
|
+
);
|
|
1117
1125
|
}
|
|
1118
1126
|
} else if (elm.type === "pcb_keepout" && elm.shape === "outline") {
|
|
1119
1127
|
elm.outline = elm.outline.map((point) => applyToPoint2(matrix, point));
|
|
@@ -1121,7 +1129,7 @@ var transformPCBElement = (elm, matrix) => {
|
|
|
1121
1129
|
elm.center = applyToPoint2(matrix, elm.center);
|
|
1122
1130
|
} else if (elm.type === "pcb_silkscreen_text" || elm.type === "pcb_fabrication_note_text" || elm.type === "pcb_note_text") {
|
|
1123
1131
|
elm.anchor_position = applyToPoint2(matrix, elm.anchor_position);
|
|
1124
|
-
if (elm.type === "pcb_silkscreen_text") {
|
|
1132
|
+
if (elm.type === "pcb_silkscreen_text" || elm.type === "pcb_fabrication_note_text") {
|
|
1125
1133
|
const textTransform = compose(matrix, rotateDEG(elm.ccw_rotation ?? 0));
|
|
1126
1134
|
elm.ccw_rotation = Math.atan2(textTransform.b, textTransform.a) * 180 / Math.PI;
|
|
1127
1135
|
}
|
|
@@ -1217,7 +1225,7 @@ var transformPCBElements = (elms, matrix) => {
|
|
|
1217
1225
|
let transformedElms = elms.map((elm) => transformPCBElement(elm, matrix));
|
|
1218
1226
|
if (flipPadWidthHeight) {
|
|
1219
1227
|
transformedElms = transformedElms.map((elm) => {
|
|
1220
|
-
if (elm.type === "pcb_smtpad" && (elm.shape === "rect" || elm.shape === "pill")
|
|
1228
|
+
if (elm.type === "pcb_smtpad" && (elm.shape === "rect" || elm.shape === "pill")) {
|
|
1221
1229
|
;
|
|
1222
1230
|
[elm.width, elm.height] = [elm.height, elm.width];
|
|
1223
1231
|
}
|