circuit-json-to-tscircuit 0.0.74 → 0.0.75
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-KDQXBFSE.js → chunk-A65QMTEY.js} +5 -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 +1 -4
- package/lib/generate-board-schematic-tsx/get-box-pin-display-label.ts +6 -10
- package/package.json +1 -1
- package/tests/board-schematic-box-pin-text-color.test.tsx +1 -0
- package/tests/board-schematic-component-pin-labels.test.ts +73 -0
- package/tests/board-schematic-hidden-pin-labels.test.ts +37 -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 +0 -4
- 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 +0 -6
- package/tests/ti-evms/ti-lm5155evm-fly-roundtrip.test.tsx +0 -6
|
@@ -672,14 +672,9 @@ var convertBoxPortMarkers = ({
|
|
|
672
672
|
|
|
673
673
|
// lib/generate-board-schematic-tsx/get-box-pin-display-label.ts
|
|
674
674
|
var getBoxPinDisplayLabel = ({
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
}) =>
|
|
678
|
-
if (schematicPort.display_pin_label !== void 0)
|
|
679
|
-
return schematicPort.display_pin_label;
|
|
680
|
-
const sourceName = sourcePort?.name;
|
|
681
|
-
return sourceName && !/^\d+$/.test(sourceName) ? sourceName : void 0;
|
|
682
|
-
};
|
|
675
|
+
schematicComponent,
|
|
676
|
+
schematicPort
|
|
677
|
+
}) => schematicPort.display_pin_label ?? schematicComponent.port_labels?.[String(schematicPort.pin_number)];
|
|
683
678
|
|
|
684
679
|
// lib/generate-board-schematic-tsx/convert-box-components.ts
|
|
685
680
|
var DEFAULT_BOX_BODY_STROKE_WIDTH = 0.02;
|
|
@@ -737,9 +732,6 @@ var convertBoxComponent = ({
|
|
|
737
732
|
})
|
|
738
733
|
);
|
|
739
734
|
primitives.push(...markers);
|
|
740
|
-
const sourcePort = su2(circuitJson).source_port.get(
|
|
741
|
-
schematicPort.source_port_id
|
|
742
|
-
);
|
|
743
735
|
const labelPosition = { ...edge };
|
|
744
736
|
const pinNumberPosition = {
|
|
745
737
|
x: (edge.x + schematicPort.center.x) / 2,
|
|
@@ -772,8 +764,8 @@ var convertBoxComponent = ({
|
|
|
772
764
|
break;
|
|
773
765
|
}
|
|
774
766
|
const displayPinLabel = getBoxPinDisplayLabel({
|
|
775
|
-
|
|
776
|
-
|
|
767
|
+
schematicComponent,
|
|
768
|
+
schematicPort
|
|
777
769
|
});
|
|
778
770
|
if (displayPinLabel)
|
|
779
771
|
primitives.push(
|
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-A65QMTEY.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.74",
|
|
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
|
@@ -71,9 +71,6 @@ export const convertBoxComponent = ({
|
|
|
71
71
|
}),
|
|
72
72
|
)
|
|
73
73
|
primitives.push(...markers)
|
|
74
|
-
const sourcePort = su(circuitJson).source_port.get(
|
|
75
|
-
schematicPort.source_port_id,
|
|
76
|
-
)
|
|
77
74
|
const labelPosition = { ...edge }
|
|
78
75
|
const pinNumberPosition = {
|
|
79
76
|
x: (edge.x + schematicPort.center.x) / 2,
|
|
@@ -106,8 +103,8 @@ export const convertBoxComponent = ({
|
|
|
106
103
|
break
|
|
107
104
|
}
|
|
108
105
|
const displayPinLabel = getBoxPinDisplayLabel({
|
|
106
|
+
schematicComponent,
|
|
109
107
|
schematicPort,
|
|
110
|
-
sourcePort,
|
|
111
108
|
})
|
|
112
109
|
if (displayPinLabel)
|
|
113
110
|
primitives.push(
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SchematicComponent, SchematicPort } from "circuit-json"
|
|
2
2
|
|
|
3
3
|
export const getBoxPinDisplayLabel = ({
|
|
4
|
+
schematicComponent,
|
|
4
5
|
schematicPort,
|
|
5
|
-
sourcePort,
|
|
6
6
|
}: {
|
|
7
|
+
schematicComponent: SchematicComponent
|
|
7
8
|
schematicPort: SchematicPort
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return schematicPort.display_pin_label
|
|
12
|
-
|
|
13
|
-
const sourceName = sourcePort?.name
|
|
14
|
-
return sourceName && !/^\d+$/.test(sourceName) ? sourceName : undefined
|
|
15
|
-
}
|
|
9
|
+
}): string | undefined =>
|
|
10
|
+
schematicPort.display_pin_label ??
|
|
11
|
+
schematicComponent.port_labels?.[String(schematicPort.pin_number)]
|
package/package.json
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
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 component-level pin labels and explicit suppression", 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_component",
|
|
20
|
+
schematic_component_id: "controller",
|
|
21
|
+
center: { x: 0, y: 0 },
|
|
22
|
+
size: { width: 2, height: 1 },
|
|
23
|
+
is_box_with_pins: true,
|
|
24
|
+
port_labels: { "1": "ENABLE", "2": "DISABLED" },
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: "source_port",
|
|
28
|
+
source_port_id: "enable_source",
|
|
29
|
+
name: "ENABLE",
|
|
30
|
+
pin_number: 1,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: "source_port",
|
|
34
|
+
source_port_id: "disabled_source",
|
|
35
|
+
name: "DISABLED",
|
|
36
|
+
pin_number: 2,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: "schematic_port",
|
|
40
|
+
schematic_port_id: "enable_pin",
|
|
41
|
+
source_port_id: "enable_source",
|
|
42
|
+
schematic_component_id: "controller",
|
|
43
|
+
center: { x: -1.4, y: 0.2 },
|
|
44
|
+
distance_from_component_edge: 0.4,
|
|
45
|
+
side_of_component: "left",
|
|
46
|
+
facing_direction: "left",
|
|
47
|
+
pin_number: 1,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: "schematic_port",
|
|
51
|
+
schematic_port_id: "disabled_pin",
|
|
52
|
+
source_port_id: "disabled_source",
|
|
53
|
+
schematic_component_id: "controller",
|
|
54
|
+
center: { x: -1.4, y: -0.2 },
|
|
55
|
+
distance_from_component_edge: 0.4,
|
|
56
|
+
side_of_component: "left",
|
|
57
|
+
facing_direction: "left",
|
|
58
|
+
pin_number: 2,
|
|
59
|
+
display_pin_label: "",
|
|
60
|
+
},
|
|
61
|
+
]
|
|
62
|
+
const renderedCircuitJson = await runTscircuitCode(
|
|
63
|
+
convertCircuitJsonToTscircuit(circuitJson, {
|
|
64
|
+
componentName: "ComponentPinLabelsBoard",
|
|
65
|
+
}),
|
|
66
|
+
)
|
|
67
|
+
const renderedTexts = renderedCircuitJson
|
|
68
|
+
.filter((element) => element.type === "schematic_text")
|
|
69
|
+
.map((element) => element.text)
|
|
70
|
+
|
|
71
|
+
expect(renderedTexts).toContain("ENABLE")
|
|
72
|
+
expect(renderedTexts).not.toContain("DISABLED")
|
|
73
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { readFile } from "node:fs/promises"
|
|
3
|
+
import { join } from "node:path"
|
|
4
|
+
import { gunzipSync } from "node:zlib"
|
|
5
|
+
import type { CircuitJson } from "circuit-json"
|
|
6
|
+
import { convertCircuitJsonToTscircuit } from "lib"
|
|
7
|
+
|
|
8
|
+
test("does not display hidden source port names on the LM5155 U3 symbol", async () => {
|
|
9
|
+
const fixturePath = join(
|
|
10
|
+
import.meta.dir,
|
|
11
|
+
"fixtures/ti-evms/lm5155evm-fly.circuit.json.gz",
|
|
12
|
+
)
|
|
13
|
+
const circuitJson = JSON.parse(
|
|
14
|
+
gunzipSync(await readFile(fixturePath)).toString("utf8"),
|
|
15
|
+
) as CircuitJson
|
|
16
|
+
const refSourcePort = circuitJson.find(
|
|
17
|
+
(element) => element.type === "source_port" && element.name === "REF",
|
|
18
|
+
)
|
|
19
|
+
if (refSourcePort?.type !== "source_port") {
|
|
20
|
+
throw new Error("LM5155 fixture is missing the U3 REF source port")
|
|
21
|
+
}
|
|
22
|
+
const refSchematicPort = circuitJson.find(
|
|
23
|
+
(element) =>
|
|
24
|
+
element.type === "schematic_port" &&
|
|
25
|
+
element.source_port_id === refSourcePort.source_port_id,
|
|
26
|
+
)
|
|
27
|
+
if (refSchematicPort?.type !== "schematic_port") {
|
|
28
|
+
throw new Error("LM5155 fixture is missing the U3 REF schematic port")
|
|
29
|
+
}
|
|
30
|
+
expect(refSchematicPort.display_pin_label).toBeUndefined()
|
|
31
|
+
|
|
32
|
+
const generatedTscircuit = convertCircuitJsonToTscircuit(circuitJson, {
|
|
33
|
+
componentName: "Lm5155EvmFly",
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
expect(generatedTscircuit).not.toContain('<schematictext text={"REF"}')
|
|
37
|
+
})
|