circuit-json-to-tscircuit 0.0.62 → 0.0.64

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.
@@ -568,19 +568,26 @@ 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";
572
+ var DEFAULT_BOX_BODY_STROKE_WIDTH = 0.02;
573
+ var DEFAULT_BOX_BODY_STROKE_COLOR = "#840000";
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;
574
578
  var convertBoxComponent = ({
575
579
  circuitJson,
576
580
  schematicComponent
577
581
  }) => {
578
582
  const primitives = [
579
- formatElement("schematicrect", {
580
- schX: schematicComponent.center.x,
581
- schY: schematicComponent.center.y,
583
+ convertRect({
584
+ center: schematicComponent.center,
582
585
  width: schematicComponent.size.width,
583
- height: schematicComponent.size.height
586
+ height: schematicComponent.size.height,
587
+ strokeWidth: DEFAULT_BOX_BODY_STROKE_WIDTH,
588
+ color: DEFAULT_BOX_BODY_STROKE_COLOR,
589
+ fillColor: DEFAULT_BOX_BODY_FILL_COLOR,
590
+ isFilled: true
584
591
  })
585
592
  ];
586
593
  for (const schematicPort of su2(circuitJson).schematic_port.list({
@@ -612,25 +619,57 @@ var convertBoxComponent = ({
612
619
  const sourcePort = su2(circuitJson).source_port.get(
613
620
  schematicPort.source_port_id
614
621
  );
615
- const anchor = schematicPort.side_of_component === "left" ? "center_left" : schematicPort.side_of_component === "right" ? "center_right" : "center";
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
+ }
616
653
  if (sourcePort?.name)
617
654
  primitives.push(
618
655
  formatElement("schematictext", {
619
656
  text: sourcePort.name,
620
- schX: edge.x,
621
- schY: edge.y,
657
+ schX: labelPosition.x,
658
+ schY: labelPosition.y,
622
659
  anchor,
623
- fontSize: schematic_text3.shape.font_size.parse(void 0)
660
+ fontSize: DEFAULT_PIN_TEXT_FONT_SIZE,
661
+ schRotation: rotation || void 0
624
662
  })
625
663
  );
626
664
  if (schematicPort.pin_number !== void 0)
627
665
  primitives.push(
628
666
  formatElement("schematictext", {
629
667
  text: String(schematicPort.pin_number),
630
- schX: (edge.x + schematicPort.center.x) / 2,
631
- schY: (edge.y + schematicPort.center.y) / 2,
668
+ schX: pinNumberPosition.x,
669
+ schY: pinNumberPosition.y,
632
670
  anchor: "bottom_center",
633
- fontSize: schematic_text3.shape.font_size.parse(void 0)
671
+ fontSize: DEFAULT_PIN_TEXT_FONT_SIZE,
672
+ schRotation: rotation || void 0
634
673
  })
635
674
  );
636
675
  }
@@ -666,7 +705,7 @@ var convertComponents = (circuitJson) => su3(circuitJson).schematic_component.li
666
705
 
667
706
  // lib/generate-board-schematic-tsx/convert-net-labels.ts
668
707
  import { su as su4 } from "@tscircuit/soup-util";
669
- import { schematic_text as schematic_text4 } from "circuit-json";
708
+ import { schematic_text as schematic_text3 } from "circuit-json";
670
709
  import { symbols as symbols2 } from "schematic-symbols";
671
710
  import { translate as translate3 } from "transformation-matrix";
672
711
  var convertNetLabels = (circuitJson) => su4(circuitJson).schematic_net_label.list().flatMap((schematicNetLabel) => {
@@ -690,7 +729,7 @@ var convertNetLabels = (circuitJson) => su4(circuitJson).schematic_net_label.lis
690
729
  text: schematicNetLabel.text,
691
730
  schX: anchorPosition.x,
692
731
  schY: anchorPosition.y,
693
- fontSize: schematic_text4.shape.font_size.parse(void 0)
732
+ fontSize: schematic_text3.shape.font_size.parse(void 0)
694
733
  })
695
734
  ];
696
735
  });
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-7OQRDC2Y.js";
4
+ } from "../chunk-KBH5O2WR.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.61",
19
+ version: "0.0.63",
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-7OQRDC2Y.js";
3
+ } from "../chunk-KBH5O2WR.js";
4
4
  export {
5
5
  convertCircuitJsonToTscircuit
6
6
  };
@@ -1,11 +1,20 @@
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"
3
+ import { convertRect } from "./convert-rect"
7
4
  import { formatElement } from "./format-attributes"
8
5
 
6
+ // Circuit JSON does not encode box body styling. These values mirror the
7
+ // circuit-to-svg defaults so reconstructed boxes keep the compiled view.
8
+ const DEFAULT_BOX_BODY_STROKE_WIDTH = 0.02
9
+ const DEFAULT_BOX_BODY_STROKE_COLOR = "#840000"
10
+ const DEFAULT_BOX_BODY_FILL_COLOR = "#ffffc2"
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
+
9
18
  export const convertBoxComponent = ({
10
19
  circuitJson,
11
20
  schematicComponent,
@@ -14,11 +23,14 @@ export const convertBoxComponent = ({
14
23
  schematicComponent: SchematicComponent
15
24
  }): string[] => {
16
25
  const primitives = [
17
- formatElement("schematicrect", {
18
- schX: schematicComponent.center.x,
19
- schY: schematicComponent.center.y,
26
+ convertRect({
27
+ center: schematicComponent.center,
20
28
  width: schematicComponent.size.width,
21
29
  height: schematicComponent.size.height,
30
+ strokeWidth: DEFAULT_BOX_BODY_STROKE_WIDTH,
31
+ color: DEFAULT_BOX_BODY_STROKE_COLOR,
32
+ fillColor: DEFAULT_BOX_BODY_FILL_COLOR,
33
+ isFilled: true,
22
34
  }),
23
35
  ]
24
36
  for (const schematicPort of su(circuitJson).schematic_port.list({
@@ -52,30 +64,57 @@ export const convertBoxComponent = ({
52
64
  const sourcePort = su(circuitJson).source_port.get(
53
65
  schematicPort.source_port_id,
54
66
  )
55
- const anchor =
56
- schematicPort.side_of_component === "left"
57
- ? "center_left"
58
- : schematicPort.side_of_component === "right"
59
- ? "center_right"
60
- : "center"
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
+ }
61
98
  if (sourcePort?.name)
62
99
  primitives.push(
63
100
  formatElement("schematictext", {
64
101
  text: sourcePort.name,
65
- schX: edge.x,
66
- schY: edge.y,
102
+ schX: labelPosition.x,
103
+ schY: labelPosition.y,
67
104
  anchor,
68
- fontSize: schematic_text.shape.font_size.parse(undefined),
105
+ fontSize: DEFAULT_PIN_TEXT_FONT_SIZE,
106
+ schRotation: rotation || undefined,
69
107
  }),
70
108
  )
71
109
  if (schematicPort.pin_number !== undefined)
72
110
  primitives.push(
73
111
  formatElement("schematictext", {
74
112
  text: String(schematicPort.pin_number),
75
- schX: (edge.x + schematicPort.center.x) / 2,
76
- schY: (edge.y + schematicPort.center.y) / 2,
113
+ schX: pinNumberPosition.x,
114
+ schY: pinNumberPosition.y,
77
115
  anchor: "bottom_center",
78
- fontSize: schematic_text.shape.font_size.parse(undefined),
116
+ fontSize: DEFAULT_PIN_TEXT_FONT_SIZE,
117
+ schRotation: rotation || undefined,
79
118
  }),
80
119
  )
81
120
  }
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.62",
9
+ "version": "0.0.64",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/tscircuit/circuit-json-to-tscircuit.git"
@@ -1,4 +1,4 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="1200" height="600" style="background-color: rgb(245, 241, 237)" data-real-to-screen-transform="matrix(64.5869731593,0,0,-64.5869731593,568.0294482861,502.4736705294)" data-software-used-string="@tscircuit/core@0.0.2025"><style>
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="1200" height="600" style="background-color: rgb(245, 241, 237)" data-real-to-screen-transform="matrix(64.5869731593,0,0,-64.5869731593,567.7065134203,502.4736705294)" data-software-used-string="@tscircuit/core@0.0.2038"><style>
2
2
  .boundary { fill: rgb(245, 241, 237); }
3
3
  .schematic-boundary { fill: none; stroke: #fff; }
4
4
  .component { fill: none; stroke: rgb(132, 0, 0); }
@@ -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="568.0294482861" cy="373.29972421080004" r="1.937609194779" fill="#008800" stroke="#008800" stroke-width="7.750436779116" data-schematic-circle-id="schematic_circle_0"/><rect x="632.6164214454" y="211.83229131254998" width="129.1739463186" height="193.76091947790002" fill="none" stroke="rgba(132, 0, 0)" stroke-width="7.750436779116" data-schematic-rect-id="schematic_rect_0"/><path d="M 438.8555019675 373.29972421080004 L 568.0294482861 373.29972421080004" stroke="rgb(132, 0, 0)" stroke-width="1.291739463186" fill="none" stroke-linecap="round" stroke-linejoin="round"/><path d="M 568.0294482861 373.29972421080004 L 568.0294482861 567.0606436887" stroke="rgb(132, 0, 0)" stroke-width="1.291739463186" fill="none" stroke-linecap="round" stroke-linejoin="round"/><text x="632.6164214454" y="179.53880473290002" fill="#000000" text-anchor="start" dominant-baseline="ideographic" font-family="sans-serif" font-size="12.91739463186px" transform="rotate(90, 632.6164214454, 179.53880473290002)">U1 "controller" {flyback}</text></svg>
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="rgb(132, 0, 0)" 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="rgb(132, 0, 0)" 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>