circuit-json-to-tscircuit 0.0.78 → 0.0.79

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.
@@ -826,7 +826,24 @@ var convertComponents = (circuitJson) => su3(circuitJson).schematic_component.li
826
826
  import { su as su4 } from "@tscircuit/soup-util";
827
827
  import { schematic_text as schematic_text3 } from "circuit-json";
828
828
  import { symbols as symbols2 } from "schematic-symbols";
829
- import { translate as translate3 } from "transformation-matrix";
829
+
830
+ // lib/generate-board-schematic-tsx/get-net-label-symbol-to-schematic-transform.ts
831
+ import {
832
+ fromOneMovingPoint,
833
+ translate as translate3
834
+ } from "transformation-matrix";
835
+ var getNetLabelSymbolToSchematicTransform = ({
836
+ symbol,
837
+ schematicAnchorPosition
838
+ }) => {
839
+ const symbolPort = symbol.ports[0];
840
+ if (!symbolPort) {
841
+ return translate3(schematicAnchorPosition.x, schematicAnchorPosition.y);
842
+ }
843
+ return fromOneMovingPoint(symbolPort, schematicAnchorPosition);
844
+ };
845
+
846
+ // lib/generate-board-schematic-tsx/convert-net-labels.ts
830
847
  function canRenderNativeNetLabel(name) {
831
848
  const selector = `net.${name}`;
832
849
  if (/net\.[^\s>]*\./.test(selector) || /net\.[^\s>]*[+-]/.test(selector) || /net\.[0-9]/.test(selector)) {
@@ -842,10 +859,10 @@ var convertNetLabels = (circuitJson) => su4(circuitJson).schematic_net_label.lis
842
859
  if (symbol)
843
860
  return convertSymbolPrimitives({
844
861
  symbol,
845
- symbolToSchematicTransform: translate3(
846
- anchorPosition.x,
847
- anchorPosition.y
848
- ),
862
+ symbolToSchematicTransform: getNetLabelSymbolToSchematicTransform({
863
+ symbol,
864
+ schematicAnchorPosition: anchorPosition
865
+ }),
849
866
  reference: schematicNetLabel.text,
850
867
  displayText: schematicNetLabel.text
851
868
  });
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-35I53U4L.js";
4
+ } from "../chunk-43HJS53G.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.77",
19
+ version: "0.0.78",
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,6 +1,6 @@
1
1
  import {
2
2
  convertCircuitJsonToTscircuit
3
- } from "../chunk-35I53U4L.js";
3
+ } from "../chunk-43HJS53G.js";
4
4
  export {
5
5
  convertCircuitJsonToTscircuit
6
6
  };
@@ -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: translate(
39
- anchorPosition.x,
40
- anchorPosition.y,
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
@@ -6,7 +6,7 @@
6
6
  "./cli": "./dist/cli/main.js"
7
7
  },
8
8
  "type": "module",
9
- "version": "0.0.78",
9
+ "version": "0.0.79",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/tscircuit/circuit-json-to-tscircuit.git"
@@ -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
+ })