circuit-json-to-tscircuit 0.0.63 → 0.0.65
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/{chunk-MVPNWU4R.js → chunk-BEFEQ6FB.js} +50 -13
- package/dist/cli/main.js +2 -2
- package/dist/lib/index.js +1 -1
- package/lib/generate-board-schematic-tsx/convert-box-components.ts +46 -17
- package/lib/generate-board-schematic-tsx/convert-traces.ts +6 -1
- package/package.json +1 -1
- package/tests/__snapshots__/test22-preserve-board-schematic-schematic.snap.svg +1 -1
- package/tests/board-schematic-trace-color.test.tsx +36 -0
- package/tests/ti-evms/__snapshots__/ti-drv8307evm-roundtrip-schematic-comparison.snap.svg +1 -1
- package/tests/ti-evms/__snapshots__/ti-drv8307evm-roundtrip.test.tsx.snap +828 -828
- package/tests/ti-evms/__snapshots__/ti-lm251772evm-pd-roundtrip-schematic-comparison.snap.svg +1 -1
- package/tests/ti-evms/__snapshots__/ti-lm251772evm-pd-roundtrip.test.tsx.snap +877 -877
- package/tests/ti-evms/__snapshots__/ti-lm5155evm-fly-roundtrip-schematic-comparison.snap.svg +1 -1
- package/tests/ti-evms/__snapshots__/ti-lmg342x-bb-evm-roundtrip-schematic-comparison.snap.svg +1 -1
- package/tests/ti-evms/__snapshots__/ti-lmg342x-bb-evm-roundtrip.test.tsx.snap +575 -575
- package/tests/ti-evms/ti-lm251772evm-pd-roundtrip.test.tsx +37 -0
- package/tests/ti-evms/ti-lm5155evm-fly-roundtrip.test.tsx +495 -495
|
@@ -568,12 +568,13 @@ var convertSymbolPrimitives = ({
|
|
|
568
568
|
|
|
569
569
|
// lib/generate-board-schematic-tsx/convert-box-components.ts
|
|
570
570
|
import { su as su2 } from "@tscircuit/soup-util";
|
|
571
|
-
import
|
|
572
|
-
schematic_text as schematic_text3
|
|
573
|
-
} from "circuit-json";
|
|
571
|
+
import "circuit-json";
|
|
574
572
|
var DEFAULT_BOX_BODY_STROKE_WIDTH = 0.02;
|
|
575
573
|
var DEFAULT_BOX_BODY_STROKE_COLOR = "#840000";
|
|
576
574
|
var DEFAULT_BOX_BODY_FILL_COLOR = "#ffffc2";
|
|
575
|
+
var DEFAULT_PIN_TEXT_FONT_SIZE = 0.15;
|
|
576
|
+
var DEFAULT_PIN_LABEL_DISTANCE_FROM_EDGE = 0.1;
|
|
577
|
+
var DEFAULT_PIN_NUMBER_BASELINE_OFFSET = 0.02;
|
|
577
578
|
var convertBoxComponent = ({
|
|
578
579
|
circuitJson,
|
|
579
580
|
schematicComponent
|
|
@@ -618,25 +619,57 @@ var convertBoxComponent = ({
|
|
|
618
619
|
const sourcePort = su2(circuitJson).source_port.get(
|
|
619
620
|
schematicPort.source_port_id
|
|
620
621
|
);
|
|
621
|
-
const
|
|
622
|
+
const labelPosition = { ...edge };
|
|
623
|
+
const pinNumberPosition = {
|
|
624
|
+
x: (edge.x + schematicPort.center.x) / 2,
|
|
625
|
+
y: (edge.y + schematicPort.center.y) / 2
|
|
626
|
+
};
|
|
627
|
+
let anchor = "center";
|
|
628
|
+
let rotation = 0;
|
|
629
|
+
switch (schematicPort.side_of_component) {
|
|
630
|
+
case "left":
|
|
631
|
+
labelPosition.x += DEFAULT_PIN_LABEL_DISTANCE_FROM_EDGE;
|
|
632
|
+
pinNumberPosition.y += DEFAULT_PIN_NUMBER_BASELINE_OFFSET;
|
|
633
|
+
anchor = "center_left";
|
|
634
|
+
break;
|
|
635
|
+
case "right":
|
|
636
|
+
labelPosition.x -= DEFAULT_PIN_LABEL_DISTANCE_FROM_EDGE;
|
|
637
|
+
pinNumberPosition.y += DEFAULT_PIN_NUMBER_BASELINE_OFFSET;
|
|
638
|
+
anchor = "center_right";
|
|
639
|
+
break;
|
|
640
|
+
case "top":
|
|
641
|
+
labelPosition.y -= DEFAULT_PIN_LABEL_DISTANCE_FROM_EDGE;
|
|
642
|
+
pinNumberPosition.x -= DEFAULT_PIN_NUMBER_BASELINE_OFFSET;
|
|
643
|
+
anchor = "center_right";
|
|
644
|
+
rotation = -90;
|
|
645
|
+
break;
|
|
646
|
+
case "bottom":
|
|
647
|
+
labelPosition.y += DEFAULT_PIN_LABEL_DISTANCE_FROM_EDGE;
|
|
648
|
+
pinNumberPosition.x -= DEFAULT_PIN_NUMBER_BASELINE_OFFSET;
|
|
649
|
+
anchor = "center_left";
|
|
650
|
+
rotation = -90;
|
|
651
|
+
break;
|
|
652
|
+
}
|
|
622
653
|
if (sourcePort?.name)
|
|
623
654
|
primitives.push(
|
|
624
655
|
formatElement("schematictext", {
|
|
625
656
|
text: sourcePort.name,
|
|
626
|
-
schX:
|
|
627
|
-
schY:
|
|
657
|
+
schX: labelPosition.x,
|
|
658
|
+
schY: labelPosition.y,
|
|
628
659
|
anchor,
|
|
629
|
-
fontSize:
|
|
660
|
+
fontSize: DEFAULT_PIN_TEXT_FONT_SIZE,
|
|
661
|
+
schRotation: rotation || void 0
|
|
630
662
|
})
|
|
631
663
|
);
|
|
632
664
|
if (schematicPort.pin_number !== void 0)
|
|
633
665
|
primitives.push(
|
|
634
666
|
formatElement("schematictext", {
|
|
635
667
|
text: String(schematicPort.pin_number),
|
|
636
|
-
schX:
|
|
637
|
-
schY:
|
|
668
|
+
schX: pinNumberPosition.x,
|
|
669
|
+
schY: pinNumberPosition.y,
|
|
638
670
|
anchor: "bottom_center",
|
|
639
|
-
fontSize:
|
|
671
|
+
fontSize: DEFAULT_PIN_TEXT_FONT_SIZE,
|
|
672
|
+
schRotation: rotation || void 0
|
|
640
673
|
})
|
|
641
674
|
);
|
|
642
675
|
}
|
|
@@ -672,7 +705,7 @@ var convertComponents = (circuitJson) => su3(circuitJson).schematic_component.li
|
|
|
672
705
|
|
|
673
706
|
// lib/generate-board-schematic-tsx/convert-net-labels.ts
|
|
674
707
|
import { su as su4 } from "@tscircuit/soup-util";
|
|
675
|
-
import { schematic_text as
|
|
708
|
+
import { schematic_text as schematic_text3 } from "circuit-json";
|
|
676
709
|
import { symbols as symbols2 } from "schematic-symbols";
|
|
677
710
|
import { translate as translate3 } from "transformation-matrix";
|
|
678
711
|
var convertNetLabels = (circuitJson) => su4(circuitJson).schematic_net_label.list().flatMap((schematicNetLabel) => {
|
|
@@ -696,16 +729,20 @@ var convertNetLabels = (circuitJson) => su4(circuitJson).schematic_net_label.lis
|
|
|
696
729
|
text: schematicNetLabel.text,
|
|
697
730
|
schX: anchorPosition.x,
|
|
698
731
|
schY: anchorPosition.y,
|
|
699
|
-
fontSize:
|
|
732
|
+
fontSize: schematic_text3.shape.font_size.parse(void 0)
|
|
700
733
|
})
|
|
701
734
|
];
|
|
702
735
|
});
|
|
703
736
|
|
|
704
737
|
// lib/generate-board-schematic-tsx/convert-traces.ts
|
|
705
738
|
import { su as su5 } from "@tscircuit/soup-util";
|
|
739
|
+
var SCHEMATIC_WIRE_COLOR = "#009600";
|
|
706
740
|
var convertTraces = (circuitJson) => su5(circuitJson).schematic_trace.list().flatMap((schematicTrace) => [
|
|
707
741
|
...schematicTrace.edges.map(
|
|
708
|
-
(edge) => formatElement("schematicpath", {
|
|
742
|
+
(edge) => formatElement("schematicpath", {
|
|
743
|
+
points: [edge.from, edge.to],
|
|
744
|
+
strokeColor: SCHEMATIC_WIRE_COLOR
|
|
745
|
+
})
|
|
709
746
|
),
|
|
710
747
|
...schematicTrace.junctions.map(
|
|
711
748
|
(center) => formatElement("schematiccircle", {
|
package/dist/cli/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
convertCircuitJsonToTscircuit
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-BEFEQ6FB.js";
|
|
5
5
|
|
|
6
6
|
// cli/main.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -16,7 +16,7 @@ var package_default = {
|
|
|
16
16
|
"./cli": "./dist/cli/main.js"
|
|
17
17
|
},
|
|
18
18
|
type: "module",
|
|
19
|
-
version: "0.0.
|
|
19
|
+
version: "0.0.64",
|
|
20
20
|
repository: {
|
|
21
21
|
type: "git",
|
|
22
22
|
url: "https://github.com/tscircuit/circuit-json-to-tscircuit.git"
|
package/dist/lib/index.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { su } from "@tscircuit/soup-util"
|
|
2
|
-
import {
|
|
3
|
-
schematic_text,
|
|
4
|
-
type AnyCircuitElement,
|
|
5
|
-
type SchematicComponent,
|
|
6
|
-
} from "circuit-json"
|
|
2
|
+
import { type AnyCircuitElement, type SchematicComponent } from "circuit-json"
|
|
7
3
|
import { convertRect } from "./convert-rect"
|
|
8
4
|
import { formatElement } from "./format-attributes"
|
|
9
5
|
|
|
@@ -13,6 +9,12 @@ const DEFAULT_BOX_BODY_STROKE_WIDTH = 0.02
|
|
|
13
9
|
const DEFAULT_BOX_BODY_STROKE_COLOR = "#840000"
|
|
14
10
|
const DEFAULT_BOX_BODY_FILL_COLOR = "#ffffc2"
|
|
15
11
|
|
|
12
|
+
// Circuit JSON does not encode these presentation values. They mirror the
|
|
13
|
+
// circuit-to-svg defaults so reconstructed box pins keep the compiled view.
|
|
14
|
+
const DEFAULT_PIN_TEXT_FONT_SIZE = 0.15
|
|
15
|
+
const DEFAULT_PIN_LABEL_DISTANCE_FROM_EDGE = 0.1
|
|
16
|
+
const DEFAULT_PIN_NUMBER_BASELINE_OFFSET = 0.02
|
|
17
|
+
|
|
16
18
|
export const convertBoxComponent = ({
|
|
17
19
|
circuitJson,
|
|
18
20
|
schematicComponent,
|
|
@@ -62,30 +64,57 @@ export const convertBoxComponent = ({
|
|
|
62
64
|
const sourcePort = su(circuitJson).source_port.get(
|
|
63
65
|
schematicPort.source_port_id,
|
|
64
66
|
)
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
const labelPosition = { ...edge }
|
|
68
|
+
const pinNumberPosition = {
|
|
69
|
+
x: (edge.x + schematicPort.center.x) / 2,
|
|
70
|
+
y: (edge.y + schematicPort.center.y) / 2,
|
|
71
|
+
}
|
|
72
|
+
let anchor = "center"
|
|
73
|
+
let rotation = 0
|
|
74
|
+
switch (schematicPort.side_of_component) {
|
|
75
|
+
case "left":
|
|
76
|
+
labelPosition.x += DEFAULT_PIN_LABEL_DISTANCE_FROM_EDGE
|
|
77
|
+
pinNumberPosition.y += DEFAULT_PIN_NUMBER_BASELINE_OFFSET
|
|
78
|
+
anchor = "center_left"
|
|
79
|
+
break
|
|
80
|
+
case "right":
|
|
81
|
+
labelPosition.x -= DEFAULT_PIN_LABEL_DISTANCE_FROM_EDGE
|
|
82
|
+
pinNumberPosition.y += DEFAULT_PIN_NUMBER_BASELINE_OFFSET
|
|
83
|
+
anchor = "center_right"
|
|
84
|
+
break
|
|
85
|
+
case "top":
|
|
86
|
+
labelPosition.y -= DEFAULT_PIN_LABEL_DISTANCE_FROM_EDGE
|
|
87
|
+
pinNumberPosition.x -= DEFAULT_PIN_NUMBER_BASELINE_OFFSET
|
|
88
|
+
anchor = "center_right"
|
|
89
|
+
rotation = -90
|
|
90
|
+
break
|
|
91
|
+
case "bottom":
|
|
92
|
+
labelPosition.y += DEFAULT_PIN_LABEL_DISTANCE_FROM_EDGE
|
|
93
|
+
pinNumberPosition.x -= DEFAULT_PIN_NUMBER_BASELINE_OFFSET
|
|
94
|
+
anchor = "center_left"
|
|
95
|
+
rotation = -90
|
|
96
|
+
break
|
|
97
|
+
}
|
|
71
98
|
if (sourcePort?.name)
|
|
72
99
|
primitives.push(
|
|
73
100
|
formatElement("schematictext", {
|
|
74
101
|
text: sourcePort.name,
|
|
75
|
-
schX:
|
|
76
|
-
schY:
|
|
102
|
+
schX: labelPosition.x,
|
|
103
|
+
schY: labelPosition.y,
|
|
77
104
|
anchor,
|
|
78
|
-
fontSize:
|
|
105
|
+
fontSize: DEFAULT_PIN_TEXT_FONT_SIZE,
|
|
106
|
+
schRotation: rotation || undefined,
|
|
79
107
|
}),
|
|
80
108
|
)
|
|
81
109
|
if (schematicPort.pin_number !== undefined)
|
|
82
110
|
primitives.push(
|
|
83
111
|
formatElement("schematictext", {
|
|
84
112
|
text: String(schematicPort.pin_number),
|
|
85
|
-
schX:
|
|
86
|
-
schY:
|
|
113
|
+
schX: pinNumberPosition.x,
|
|
114
|
+
schY: pinNumberPosition.y,
|
|
87
115
|
anchor: "bottom_center",
|
|
88
|
-
fontSize:
|
|
116
|
+
fontSize: DEFAULT_PIN_TEXT_FONT_SIZE,
|
|
117
|
+
schRotation: rotation || undefined,
|
|
89
118
|
}),
|
|
90
119
|
)
|
|
91
120
|
}
|
|
@@ -2,12 +2,17 @@ import { su } from "@tscircuit/soup-util"
|
|
|
2
2
|
import type { SchematicElementConverter } from "./converter-types"
|
|
3
3
|
import { formatElement } from "./format-attributes"
|
|
4
4
|
|
|
5
|
+
const SCHEMATIC_WIRE_COLOR = "#009600"
|
|
6
|
+
|
|
5
7
|
export const convertTraces: SchematicElementConverter = (circuitJson) =>
|
|
6
8
|
su(circuitJson)
|
|
7
9
|
.schematic_trace.list()
|
|
8
10
|
.flatMap((schematicTrace) => [
|
|
9
11
|
...schematicTrace.edges.map((edge) =>
|
|
10
|
-
formatElement("schematicpath", {
|
|
12
|
+
formatElement("schematicpath", {
|
|
13
|
+
points: [edge.from, edge.to],
|
|
14
|
+
strokeColor: SCHEMATIC_WIRE_COLOR,
|
|
15
|
+
}),
|
|
11
16
|
),
|
|
12
17
|
...schematicTrace.junctions.map((center) =>
|
|
13
18
|
formatElement("schematiccircle", {
|
package/package.json
CHANGED
|
@@ -22,4 +22,4 @@
|
|
|
22
22
|
.pin-number { fill: rgb(169, 0, 0); }
|
|
23
23
|
.port-label { fill: rgb(0, 100, 100); }
|
|
24
24
|
.component-name { fill: rgb(0, 100, 100); }
|
|
25
|
-
</style><rect class="boundary" x="0" y="0" width="1200" height="600"/><circle cx="567.7065134203" cy="373.29972421080004" r="1.937609194779" fill="#008800" stroke="#008800" stroke-width="7.750436779116" data-schematic-circle-id="schematic_circle_0"/><path d="M 632.2934865796 405.59321079045003 L 761.4674328982001 405.59321079045003 L 761.4674328982001 211.83229131255 L 632.2934865796 211.83229131255 L 632.2934865796 405.59321079045003" stroke="#840000" stroke-width="1.291739463186" fill="#ffffc2" stroke-linecap="round" stroke-linejoin="round"/><path d="M 438.5325671017 373.29972421080004 L 567.7065134203 373.29972421080004" stroke="
|
|
25
|
+
</style><rect class="boundary" x="0" y="0" width="1200" height="600"/><circle cx="567.7065134203" cy="373.29972421080004" r="1.937609194779" fill="#008800" stroke="#008800" stroke-width="7.750436779116" data-schematic-circle-id="schematic_circle_0"/><path d="M 632.2934865796 405.59321079045003 L 761.4674328982001 405.59321079045003 L 761.4674328982001 211.83229131255 L 632.2934865796 211.83229131255 L 632.2934865796 405.59321079045003" stroke="#840000" stroke-width="1.291739463186" fill="#ffffc2" stroke-linecap="round" stroke-linejoin="round"/><path d="M 438.5325671017 373.29972421080004 L 567.7065134203 373.29972421080004" stroke="#009600" stroke-width="1.291739463186" fill="none" stroke-linecap="round" stroke-linejoin="round"/><path d="M 567.7065134203 373.29972421080004 L 567.7065134203 567.0606436887" stroke="#009600" stroke-width="1.291739463186" fill="none" stroke-linecap="round" stroke-linejoin="round"/><text x="632.2934865796" y="179.53880473290002" fill="#000000" text-anchor="start" dominant-baseline="ideographic" font-family="sans-serif" font-size="12.91739463186px" transform="rotate(90, 632.2934865796, 179.53880473290002)">U1 "controller" {flyback}</text></svg>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import type { CircuitJson } from "circuit-json"
|
|
3
|
+
import { convertCircuitJsonToTscircuit } from "lib"
|
|
4
|
+
import { runTscircuitCode } from "tscircuit"
|
|
5
|
+
|
|
6
|
+
test("preserves the compiled schematic wire color", async () => {
|
|
7
|
+
const circuitJson: CircuitJson = [
|
|
8
|
+
{
|
|
9
|
+
type: "pcb_board",
|
|
10
|
+
pcb_board_id: "board",
|
|
11
|
+
center: { x: 0, y: 0 },
|
|
12
|
+
width: 10,
|
|
13
|
+
height: 10,
|
|
14
|
+
num_layers: 2,
|
|
15
|
+
thickness: 1.6,
|
|
16
|
+
material: "fr4",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
type: "schematic_trace",
|
|
20
|
+
schematic_trace_id: "wire",
|
|
21
|
+
source_trace_id: "trace",
|
|
22
|
+
edges: [{ from: { x: -1, y: 0 }, to: { x: 1, y: 0 } }],
|
|
23
|
+
junctions: [],
|
|
24
|
+
},
|
|
25
|
+
]
|
|
26
|
+
const renderedCircuitJson = await runTscircuitCode(
|
|
27
|
+
convertCircuitJsonToTscircuit(circuitJson, {
|
|
28
|
+
componentName: "WireColorBoard",
|
|
29
|
+
}),
|
|
30
|
+
)
|
|
31
|
+
const path = renderedCircuitJson.find(
|
|
32
|
+
(element) => element.type === "schematic_path",
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
expect(path).toMatchObject({ stroke_color: "#009600" })
|
|
36
|
+
})
|