circuit-json-to-tscircuit 0.0.78 → 0.0.80
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-35I53U4L.js → chunk-FAZLXH7M.js} +24 -6
- package/dist/cli/main.js +2 -2
- package/dist/lib/index.js +1 -1
- package/lib/generate-board-schematic-tsx/convert-box-components.ts +3 -1
- package/lib/generate-board-schematic-tsx/convert-net-labels.ts +5 -5
- package/lib/generate-board-schematic-tsx/get-net-label-symbol-to-schematic-transform.ts +20 -0
- package/package.json +1 -1
- package/tests/board-power-symbol-anchor.test.ts +73 -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 +353 -353
- package/tests/ti-evms/__snapshots__/ti-lm251772evm-pd-roundtrip-schematic-comparison.snap.svg +2 -2
- package/tests/ti-evms/__snapshots__/ti-lm251772evm-pd-roundtrip.test.tsx.snap +264 -264
- 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 +231 -231
- package/tests/ti-evms/ti-lm251772evm-pd-roundtrip.test.tsx +3 -1
- package/tests/ti-evms/ti-lm5155evm-fly-roundtrip.test.tsx +179 -179
|
@@ -767,6 +767,7 @@ var convertBoxComponent = ({
|
|
|
767
767
|
schematicComponent,
|
|
768
768
|
schematicPort
|
|
769
769
|
});
|
|
770
|
+
const pinLabelFontSize = schematicPort.display_pin_label_font_size ?? DEFAULT_PIN_TEXT_FONT_SIZE;
|
|
770
771
|
if (displayPinLabel)
|
|
771
772
|
primitives.push(
|
|
772
773
|
formatElement("schematictext", {
|
|
@@ -774,7 +775,7 @@ var convertBoxComponent = ({
|
|
|
774
775
|
schX: labelPosition.x,
|
|
775
776
|
schY: labelPosition.y,
|
|
776
777
|
anchor,
|
|
777
|
-
fontSize:
|
|
778
|
+
fontSize: pinLabelFontSize,
|
|
778
779
|
color: DEFAULT_PIN_TEXT_COLOR,
|
|
779
780
|
schRotation: rotation || void 0
|
|
780
781
|
})
|
|
@@ -826,7 +827,24 @@ var convertComponents = (circuitJson) => su3(circuitJson).schematic_component.li
|
|
|
826
827
|
import { su as su4 } from "@tscircuit/soup-util";
|
|
827
828
|
import { schematic_text as schematic_text3 } from "circuit-json";
|
|
828
829
|
import { symbols as symbols2 } from "schematic-symbols";
|
|
829
|
-
|
|
830
|
+
|
|
831
|
+
// lib/generate-board-schematic-tsx/get-net-label-symbol-to-schematic-transform.ts
|
|
832
|
+
import {
|
|
833
|
+
fromOneMovingPoint,
|
|
834
|
+
translate as translate3
|
|
835
|
+
} from "transformation-matrix";
|
|
836
|
+
var getNetLabelSymbolToSchematicTransform = ({
|
|
837
|
+
symbol,
|
|
838
|
+
schematicAnchorPosition
|
|
839
|
+
}) => {
|
|
840
|
+
const symbolPort = symbol.ports[0];
|
|
841
|
+
if (!symbolPort) {
|
|
842
|
+
return translate3(schematicAnchorPosition.x, schematicAnchorPosition.y);
|
|
843
|
+
}
|
|
844
|
+
return fromOneMovingPoint(symbolPort, schematicAnchorPosition);
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
// lib/generate-board-schematic-tsx/convert-net-labels.ts
|
|
830
848
|
function canRenderNativeNetLabel(name) {
|
|
831
849
|
const selector = `net.${name}`;
|
|
832
850
|
if (/net\.[^\s>]*\./.test(selector) || /net\.[^\s>]*[+-]/.test(selector) || /net\.[0-9]/.test(selector)) {
|
|
@@ -842,10 +860,10 @@ var convertNetLabels = (circuitJson) => su4(circuitJson).schematic_net_label.lis
|
|
|
842
860
|
if (symbol)
|
|
843
861
|
return convertSymbolPrimitives({
|
|
844
862
|
symbol,
|
|
845
|
-
symbolToSchematicTransform:
|
|
846
|
-
|
|
847
|
-
anchorPosition
|
|
848
|
-
),
|
|
863
|
+
symbolToSchematicTransform: getNetLabelSymbolToSchematicTransform({
|
|
864
|
+
symbol,
|
|
865
|
+
schematicAnchorPosition: anchorPosition
|
|
866
|
+
}),
|
|
849
867
|
reference: schematicNetLabel.text,
|
|
850
868
|
displayText: schematicNetLabel.text
|
|
851
869
|
});
|
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-FAZLXH7M.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.79",
|
|
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
|
@@ -106,6 +106,8 @@ export const convertBoxComponent = ({
|
|
|
106
106
|
schematicComponent,
|
|
107
107
|
schematicPort,
|
|
108
108
|
})
|
|
109
|
+
const pinLabelFontSize =
|
|
110
|
+
schematicPort.display_pin_label_font_size ?? DEFAULT_PIN_TEXT_FONT_SIZE
|
|
109
111
|
if (displayPinLabel)
|
|
110
112
|
primitives.push(
|
|
111
113
|
formatElement("schematictext", {
|
|
@@ -113,7 +115,7 @@ export const convertBoxComponent = ({
|
|
|
113
115
|
schX: labelPosition.x,
|
|
114
116
|
schY: labelPosition.y,
|
|
115
117
|
anchor,
|
|
116
|
-
fontSize:
|
|
118
|
+
fontSize: pinLabelFontSize,
|
|
117
119
|
color: DEFAULT_PIN_TEXT_COLOR,
|
|
118
120
|
schRotation: rotation || undefined,
|
|
119
121
|
}),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { su } from "@tscircuit/soup-util"
|
|
2
2
|
import { schematic_text } from "circuit-json"
|
|
3
3
|
import { symbols } from "schematic-symbols"
|
|
4
|
-
import { translate } from "transformation-matrix"
|
|
5
4
|
import type { SchematicElementConverter } from "./converter-types"
|
|
6
5
|
import { convertSymbolPrimitives } from "./convert-symbol-primitives"
|
|
7
6
|
import { formatElement } from "./format-attributes"
|
|
7
|
+
import { getNetLabelSymbolToSchematicTransform } from "./get-net-label-symbol-to-schematic-transform"
|
|
8
8
|
|
|
9
9
|
// Match core's preprocessSelector checks for net names. The validator is not
|
|
10
10
|
// exported by @tscircuit/core; runtime regression tests keep these in sync.
|
|
@@ -35,10 +35,10 @@ export const convertNetLabels: SchematicElementConverter = (circuitJson) =>
|
|
|
35
35
|
if (symbol)
|
|
36
36
|
return convertSymbolPrimitives({
|
|
37
37
|
symbol,
|
|
38
|
-
symbolToSchematicTransform:
|
|
39
|
-
|
|
40
|
-
anchorPosition
|
|
41
|
-
),
|
|
38
|
+
symbolToSchematicTransform: getNetLabelSymbolToSchematicTransform({
|
|
39
|
+
symbol,
|
|
40
|
+
schematicAnchorPosition: anchorPosition,
|
|
41
|
+
}),
|
|
42
42
|
reference: schematicNetLabel.text,
|
|
43
43
|
displayText: schematicNetLabel.text,
|
|
44
44
|
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SchSymbol } from "schematic-symbols"
|
|
2
|
+
import {
|
|
3
|
+
fromOneMovingPoint,
|
|
4
|
+
type Matrix,
|
|
5
|
+
translate,
|
|
6
|
+
} from "transformation-matrix"
|
|
7
|
+
|
|
8
|
+
export const getNetLabelSymbolToSchematicTransform = ({
|
|
9
|
+
symbol,
|
|
10
|
+
schematicAnchorPosition,
|
|
11
|
+
}: {
|
|
12
|
+
symbol: SchSymbol
|
|
13
|
+
schematicAnchorPosition: { x: number; y: number }
|
|
14
|
+
}): Matrix => {
|
|
15
|
+
const symbolPort = symbol.ports[0]
|
|
16
|
+
if (!symbolPort) {
|
|
17
|
+
return translate(schematicAnchorPosition.x, schematicAnchorPosition.y)
|
|
18
|
+
}
|
|
19
|
+
return fromOneMovingPoint(symbolPort, schematicAnchorPosition)
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { readFileSync } from "node:fs"
|
|
3
|
+
import { gunzipSync } from "node:zlib"
|
|
4
|
+
import type { CircuitJson, SchematicNetLabel } from "circuit-json"
|
|
5
|
+
import { convertNetLabels } from "lib/generate-board-schematic-tsx/convert-net-labels"
|
|
6
|
+
import { runTscircuitCode } from "tscircuit"
|
|
7
|
+
|
|
8
|
+
const fixtureNames = [
|
|
9
|
+
"drv8307evm",
|
|
10
|
+
"lm251772evm-pd",
|
|
11
|
+
"lm5155evm-fly",
|
|
12
|
+
"lmg342x-bb-evm",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
const sourceCircuitJson = fixtureNames.flatMap((fixtureName) =>
|
|
16
|
+
JSON.parse(
|
|
17
|
+
gunzipSync(
|
|
18
|
+
readFileSync(
|
|
19
|
+
new URL(
|
|
20
|
+
`./fixtures/ti-evms/${fixtureName}.circuit.json.gz`,
|
|
21
|
+
import.meta.url,
|
|
22
|
+
),
|
|
23
|
+
),
|
|
24
|
+
).toString(),
|
|
25
|
+
),
|
|
26
|
+
) as CircuitJson
|
|
27
|
+
|
|
28
|
+
const symbolicNetLabels = sourceCircuitJson.filter(
|
|
29
|
+
(
|
|
30
|
+
element,
|
|
31
|
+
): element is SchematicNetLabel & {
|
|
32
|
+
symbol_name: string
|
|
33
|
+
} => element.type === "schematic_net_label" && Boolean(element.symbol_name),
|
|
34
|
+
)
|
|
35
|
+
const representativeNetLabels = symbolicNetLabels.filter(
|
|
36
|
+
(label, index, labels) =>
|
|
37
|
+
labels.findIndex(
|
|
38
|
+
(candidate) => candidate.symbol_name === label.symbol_name,
|
|
39
|
+
) === index,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
test("TI power symbols connect their library port at the net label anchor", async () => {
|
|
43
|
+
expect(
|
|
44
|
+
representativeNetLabels.map((label) => label.symbol_name).sort(),
|
|
45
|
+
).toEqual([
|
|
46
|
+
"ground_down",
|
|
47
|
+
"ground_left",
|
|
48
|
+
"ground_right",
|
|
49
|
+
"ground_up",
|
|
50
|
+
"vcc_down",
|
|
51
|
+
"vcc_left",
|
|
52
|
+
"vcc_right",
|
|
53
|
+
"vcc_up",
|
|
54
|
+
])
|
|
55
|
+
|
|
56
|
+
for (const label of representativeNetLabels) {
|
|
57
|
+
const generatedElements = convertNetLabels([label])
|
|
58
|
+
const renderedCircuitJson = await runTscircuitCode(
|
|
59
|
+
`export default () => <board><symbol>${generatedElements.join("\n")}</symbol></board>`,
|
|
60
|
+
)
|
|
61
|
+
const renderedPoints = renderedCircuitJson.flatMap((element) =>
|
|
62
|
+
element.type === "schematic_path" ? element.points : [],
|
|
63
|
+
)
|
|
64
|
+
const anchorPosition = label.anchor_position ?? label.center
|
|
65
|
+
expect(
|
|
66
|
+
renderedPoints.some(
|
|
67
|
+
(point) =>
|
|
68
|
+
Math.hypot(point.x - anchorPosition.x, point.y - anchorPosition.y) <
|
|
69
|
+
0.000001,
|
|
70
|
+
),
|
|
71
|
+
).toBe(true)
|
|
72
|
+
}
|
|
73
|
+
})
|