circuit-json-to-tscircuit 0.0.71 → 0.0.73

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.
@@ -571,6 +571,19 @@ var convertSymbolPrimitives = ({
571
571
  // lib/generate-board-schematic-tsx/convert-box-components.ts
572
572
  import { su as su2 } from "@tscircuit/soup-util";
573
573
  import "circuit-json";
574
+
575
+ // lib/generate-board-schematic-tsx/get-box-pin-display-label.ts
576
+ var getBoxPinDisplayLabel = ({
577
+ schematicPort,
578
+ sourcePort
579
+ }) => {
580
+ if (schematicPort.display_pin_label !== void 0)
581
+ return schematicPort.display_pin_label;
582
+ const sourceName = sourcePort?.name;
583
+ return sourceName && !/^\d+$/.test(sourceName) ? sourceName : void 0;
584
+ };
585
+
586
+ // lib/generate-board-schematic-tsx/convert-box-components.ts
574
587
  var DEFAULT_BOX_BODY_STROKE_WIDTH = 0.02;
575
588
  var DEFAULT_BOX_BODY_STROKE_COLOR = "#840000";
576
589
  var DEFAULT_BOX_BODY_FILL_COLOR = "#ffffc2";
@@ -655,7 +668,10 @@ var convertBoxComponent = ({
655
668
  rotation = -90;
656
669
  break;
657
670
  }
658
- const displayPinLabel = schematicPort.display_pin_label ?? sourcePort?.name;
671
+ const displayPinLabel = getBoxPinDisplayLabel({
672
+ schematicPort,
673
+ sourcePort
674
+ });
659
675
  if (displayPinLabel)
660
676
  primitives.push(
661
677
  formatElement("schematictext", {
@@ -728,7 +744,7 @@ var convertNetLabels = (circuitJson) => su4(circuitJson).schematic_net_label.lis
728
744
  anchorPosition.x,
729
745
  anchorPosition.y
730
746
  ),
731
- reference: "",
747
+ reference: schematicNetLabel.text,
732
748
  displayText: schematicNetLabel.text
733
749
  });
734
750
  }
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-3CHC36FN.js";
4
+ } from "../chunk-5YQBNWPZ.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.70",
19
+ version: "0.0.72",
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-3CHC36FN.js";
3
+ } from "../chunk-5YQBNWPZ.js";
4
4
  export {
5
5
  convertCircuitJsonToTscircuit
6
6
  };
@@ -2,6 +2,7 @@ import { su } from "@tscircuit/soup-util"
2
2
  import { type AnyCircuitElement, type SchematicComponent } from "circuit-json"
3
3
  import { convertRect } from "./convert-rect"
4
4
  import { formatElement } from "./format-attributes"
5
+ import { getBoxPinDisplayLabel } from "./get-box-pin-display-label"
5
6
 
6
7
  // Circuit JSON does not encode box body styling. These values mirror the
7
8
  // circuit-to-svg defaults so reconstructed boxes keep the compiled view.
@@ -98,7 +99,10 @@ export const convertBoxComponent = ({
98
99
  rotation = -90
99
100
  break
100
101
  }
101
- const displayPinLabel = schematicPort.display_pin_label ?? sourcePort?.name
102
+ const displayPinLabel = getBoxPinDisplayLabel({
103
+ schematicPort,
104
+ sourcePort,
105
+ })
102
106
  if (displayPinLabel)
103
107
  primitives.push(
104
108
  formatElement("schematictext", {
@@ -22,7 +22,7 @@ export const convertNetLabels: SchematicElementConverter = (circuitJson) =>
22
22
  anchorPosition.x,
23
23
  anchorPosition.y,
24
24
  ),
25
- reference: "",
25
+ reference: schematicNetLabel.text,
26
26
  displayText: schematicNetLabel.text,
27
27
  })
28
28
  }
@@ -0,0 +1,15 @@
1
+ import type { SchematicPort, SourcePort } from "circuit-json"
2
+
3
+ export const getBoxPinDisplayLabel = ({
4
+ schematicPort,
5
+ sourcePort,
6
+ }: {
7
+ schematicPort: SchematicPort
8
+ sourcePort: SourcePort | null
9
+ }): string | undefined => {
10
+ if (schematicPort.display_pin_label !== undefined)
11
+ return schematicPort.display_pin_label
12
+
13
+ const sourceName = sourcePort?.name
14
+ return sourceName && !/^\d+$/.test(sourceName) ? sourceName : undefined
15
+ }
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.71",
9
+ "version": "0.0.73",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/tscircuit/circuit-json-to-tscircuit.git"
@@ -0,0 +1,47 @@
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 text for imported symbolic net labels", 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: "source_net",
20
+ source_net_id: "power_good_net",
21
+ name: "PGOOD",
22
+ member_source_group_ids: [],
23
+ },
24
+ {
25
+ type: "schematic_net_label",
26
+ schematic_net_label_id: "power_good_label",
27
+ source_net_id: "power_good_net",
28
+ text: "PGOOD",
29
+ center: { x: 1, y: 2 },
30
+ anchor_position: { x: 1, y: 2 },
31
+ anchor_side: "left",
32
+ symbol_name: "vcc_right",
33
+ },
34
+ ]
35
+ const renderedCircuitJson = await runTscircuitCode(
36
+ convertCircuitJsonToTscircuit(circuitJson, {
37
+ componentName: "NetLabelBoard",
38
+ }),
39
+ )
40
+
41
+ expect(
42
+ renderedCircuitJson.some(
43
+ (element) =>
44
+ element.type === "schematic_text" && element.text === "PGOOD",
45
+ ),
46
+ ).toBe(true)
47
+ })
@@ -0,0 +1,72 @@
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("does not duplicate numeric box pin names", 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: "net_tie",
21
+ center: { x: 0, y: 0 },
22
+ size: { width: 0.4, height: 0.4 },
23
+ is_box_with_pins: true,
24
+ },
25
+ {
26
+ type: "source_port",
27
+ source_port_id: "net_tie_left_source",
28
+ name: "1",
29
+ pin_number: 1,
30
+ },
31
+ {
32
+ type: "source_port",
33
+ source_port_id: "net_tie_right_source",
34
+ name: "2",
35
+ pin_number: 2,
36
+ },
37
+ {
38
+ type: "schematic_port",
39
+ schematic_port_id: "net_tie_left",
40
+ source_port_id: "net_tie_left_source",
41
+ schematic_component_id: "net_tie",
42
+ center: { x: -0.4, y: 0 },
43
+ side_of_component: "left",
44
+ facing_direction: "left",
45
+ pin_number: 1,
46
+ },
47
+ {
48
+ type: "schematic_port",
49
+ schematic_port_id: "net_tie_right",
50
+ source_port_id: "net_tie_right_source",
51
+ schematic_component_id: "net_tie",
52
+ center: { x: 0.4, y: 0 },
53
+ side_of_component: "right",
54
+ facing_direction: "right",
55
+ pin_number: 2,
56
+ },
57
+ ]
58
+ const renderedCircuitJson = await runTscircuitCode(
59
+ convertCircuitJsonToTscircuit(circuitJson, {
60
+ componentName: "NetTieBoard",
61
+ }),
62
+ )
63
+ const numericTexts = renderedCircuitJson
64
+ .flatMap((element) =>
65
+ element.type === "schematic_text" && /^[12]$/.test(element.text)
66
+ ? [element.text]
67
+ : [],
68
+ )
69
+ .sort()
70
+
71
+ expect(numericTexts).toEqual(["1", "2"])
72
+ })