circuit-json-to-tscircuit 0.0.61 → 0.0.63

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.
Files changed (21) hide show
  1. package/dist/{chunk-S5BLPDEH.js → chunk-MVPNWU4R.js} +45 -34
  2. package/dist/cli/main.js +2 -2
  3. package/dist/lib/index.js +1 -1
  4. package/lib/generate-board-schematic-tsx/convert-box-components.ts +13 -3
  5. package/lib/generate-footprint-tsx/convert-fabrication-note-dimension.ts +37 -0
  6. package/lib/generate-footprint-tsx/convert-fabrication.ts +2 -35
  7. package/package.json +1 -1
  8. package/tests/__snapshots__/fabrication-dimension-offset-comparison.snap.svg +8 -0
  9. package/tests/__snapshots__/test22-preserve-board-schematic-schematic.snap.svg +2 -2
  10. package/tests/fabrication-dimension-offset.test.tsx +74 -0
  11. package/tests/ti-evms/__snapshots__/ti-drv8307evm-roundtrip-schematic-comparison.snap.svg +2 -2
  12. package/tests/ti-evms/__snapshots__/ti-drv8307evm-roundtrip.test.tsx.snap +13 -13
  13. package/tests/ti-evms/__snapshots__/ti-lm251772evm-pd-roundtrip-pcb-comparison.snap.svg +3 -3
  14. package/tests/ti-evms/__snapshots__/ti-lm251772evm-pd-roundtrip-schematic-comparison.snap.svg +2 -2
  15. package/tests/ti-evms/__snapshots__/ti-lm251772evm-pd-roundtrip.test.tsx.snap +11 -11
  16. package/tests/ti-evms/__snapshots__/ti-lm5155evm-fly-roundtrip-pcb-comparison.snap.svg +1 -1
  17. package/tests/ti-evms/__snapshots__/ti-lm5155evm-fly-roundtrip-schematic-comparison.snap.svg +2 -2
  18. package/tests/ti-evms/__snapshots__/ti-lmg342x-bb-evm-roundtrip-pcb-comparison.snap.svg +1 -1
  19. package/tests/ti-evms/__snapshots__/ti-lmg342x-bb-evm-roundtrip-schematic-comparison.snap.svg +2 -2
  20. package/tests/ti-evms/__snapshots__/ti-lmg342x-bb-evm-roundtrip.test.tsx.snap +47 -47
  21. package/tests/ti-evms/ti-lm5155evm-fly-roundtrip.test.tsx +40 -9
@@ -571,16 +571,22 @@ import { su as su2 } from "@tscircuit/soup-util";
571
571
  import {
572
572
  schematic_text as schematic_text3
573
573
  } from "circuit-json";
574
+ var DEFAULT_BOX_BODY_STROKE_WIDTH = 0.02;
575
+ var DEFAULT_BOX_BODY_STROKE_COLOR = "#840000";
576
+ var DEFAULT_BOX_BODY_FILL_COLOR = "#ffffc2";
574
577
  var convertBoxComponent = ({
575
578
  circuitJson,
576
579
  schematicComponent
577
580
  }) => {
578
581
  const primitives = [
579
- formatElement("schematicrect", {
580
- schX: schematicComponent.center.x,
581
- schY: schematicComponent.center.y,
582
+ convertRect({
583
+ center: schematicComponent.center,
582
584
  width: schematicComponent.size.width,
583
- height: schematicComponent.size.height
585
+ height: schematicComponent.size.height,
586
+ strokeWidth: DEFAULT_BOX_BODY_STROKE_WIDTH,
587
+ color: DEFAULT_BOX_BODY_STROKE_COLOR,
588
+ fillColor: DEFAULT_BOX_BODY_FILL_COLOR,
589
+ isFilled: true
584
590
  })
585
591
  ];
586
592
  for (const schematicPort of su2(circuitJson).schematic_port.list({
@@ -1062,6 +1068,40 @@ var convertCutouts = (circuitJson) => {
1062
1068
 
1063
1069
  // lib/generate-footprint-tsx/convert-fabrication.ts
1064
1070
  import { su as su10 } from "@tscircuit/soup-util";
1071
+
1072
+ // lib/generate-footprint-tsx/convert-fabrication-note-dimension.ts
1073
+ var convertFabricationNoteDimension = (dimension) => {
1074
+ const from = dimension.from ?? { x: 0, y: 0 };
1075
+ const to = dimension.to ?? { x: 0, y: 0 };
1076
+ const offsetDistance = dimension.offset_distance ?? dimension.offset;
1077
+ const attrs = [
1078
+ `from={{ x: ${from.x}, y: ${from.y} }}`,
1079
+ `to={{ x: ${to.x}, y: ${to.y} }}`
1080
+ ];
1081
+ if (dimension.text !== void 0) {
1082
+ attrs.push(`text="${escapeJsxText2(dimension.text)}"`);
1083
+ }
1084
+ if (dimension.font !== void 0) attrs.push(`font="${dimension.font}"`);
1085
+ if (dimension.font_size !== void 0) {
1086
+ attrs.push(`fontSize={${dimension.font_size}}`);
1087
+ }
1088
+ if (dimension.color !== void 0) attrs.push(`color="${dimension.color}"`);
1089
+ if (dimension.arrow_size !== void 0) {
1090
+ attrs.push(`arrowSize={${dimension.arrow_size}}`);
1091
+ }
1092
+ if (offsetDistance !== void 0) {
1093
+ attrs.push(`offset={${offsetDistance}}`);
1094
+ }
1095
+ if (dimension.offset_direction !== void 0) {
1096
+ attrs.push(
1097
+ `offsetDirection={${JSON.stringify(dimension.offset_direction)}}`
1098
+ );
1099
+ }
1100
+ if (dimension.layer === "bottom") attrs.push(`layer="bottom"`);
1101
+ return [`<fabricationnotedimension ${attrs.join(" ")} />`];
1102
+ };
1103
+
1104
+ // lib/generate-footprint-tsx/convert-fabrication.ts
1065
1105
  var convertFabrication = (circuitJson) => {
1066
1106
  const fabricationNotePaths = su10(circuitJson).pcb_fabrication_note_path.list();
1067
1107
  const fabricationNoteTexts = su10(circuitJson).pcb_fabrication_note_text.list();
@@ -1137,36 +1177,7 @@ var convertFabrication = (circuitJson) => {
1137
1177
  elementStrings.push(`<fabricationnoterect ${attrs.join(" ")} />`);
1138
1178
  }
1139
1179
  for (const fabDimension of fabricationNoteDimensions) {
1140
- const fromPoint = fabDimension.from ?? { x: 0, y: 0 };
1141
- const toPoint2 = fabDimension.to ?? { x: 0, y: 0 };
1142
- const attrs = [
1143
- `from={{ x: ${fromPoint.x}, y: ${fromPoint.y} }}`,
1144
- `to={{ x: ${toPoint2.x}, y: ${toPoint2.y} }}`
1145
- ];
1146
- if (fabDimension.text !== void 0) {
1147
- attrs.push(`text="${escapeJsxText2(fabDimension.text)}"`);
1148
- }
1149
- if (fabDimension.font !== void 0) {
1150
- attrs.push(`font="${fabDimension.font}"`);
1151
- }
1152
- if (fabDimension.font_size !== void 0) {
1153
- attrs.push(`fontSize={${fabDimension.font_size}}`);
1154
- }
1155
- if (fabDimension.color !== void 0) {
1156
- attrs.push(`color="${fabDimension.color}"`);
1157
- }
1158
- if (fabDimension.arrow_size !== void 0) {
1159
- attrs.push(`arrowSize={${fabDimension.arrow_size}}`);
1160
- }
1161
- if (fabDimension.offset !== void 0) {
1162
- attrs.push(`offset={${fabDimension.offset}}`);
1163
- } else if ("offset_distance" in fabDimension && fabDimension.offset_distance !== void 0) {
1164
- attrs.push(`offset={${fabDimension.offset_distance}}`);
1165
- }
1166
- if (fabDimension.layer === "bottom") {
1167
- attrs.push(`layer="bottom"`);
1168
- }
1169
- elementStrings.push(`<fabricationnotedimension ${attrs.join(" ")} />`);
1180
+ elementStrings.push(...convertFabricationNoteDimension(fabDimension));
1170
1181
  }
1171
1182
  return elementStrings;
1172
1183
  };
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-S5BLPDEH.js";
4
+ } from "../chunk-MVPNWU4R.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.60",
19
+ version: "0.0.62",
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-S5BLPDEH.js";
3
+ } from "../chunk-MVPNWU4R.js";
4
4
  export {
5
5
  convertCircuitJsonToTscircuit
6
6
  };
@@ -4,8 +4,15 @@ import {
4
4
  type AnyCircuitElement,
5
5
  type SchematicComponent,
6
6
  } from "circuit-json"
7
+ import { convertRect } from "./convert-rect"
7
8
  import { formatElement } from "./format-attributes"
8
9
 
10
+ // Circuit JSON does not encode box body styling. These values mirror the
11
+ // circuit-to-svg defaults so reconstructed boxes keep the compiled view.
12
+ const DEFAULT_BOX_BODY_STROKE_WIDTH = 0.02
13
+ const DEFAULT_BOX_BODY_STROKE_COLOR = "#840000"
14
+ const DEFAULT_BOX_BODY_FILL_COLOR = "#ffffc2"
15
+
9
16
  export const convertBoxComponent = ({
10
17
  circuitJson,
11
18
  schematicComponent,
@@ -14,11 +21,14 @@ export const convertBoxComponent = ({
14
21
  schematicComponent: SchematicComponent
15
22
  }): string[] => {
16
23
  const primitives = [
17
- formatElement("schematicrect", {
18
- schX: schematicComponent.center.x,
19
- schY: schematicComponent.center.y,
24
+ convertRect({
25
+ center: schematicComponent.center,
20
26
  width: schematicComponent.size.width,
21
27
  height: schematicComponent.size.height,
28
+ strokeWidth: DEFAULT_BOX_BODY_STROKE_WIDTH,
29
+ color: DEFAULT_BOX_BODY_STROKE_COLOR,
30
+ fillColor: DEFAULT_BOX_BODY_FILL_COLOR,
31
+ isFilled: true,
22
32
  }),
23
33
  ]
24
34
  for (const schematicPort of su(circuitJson).schematic_port.list({
@@ -0,0 +1,37 @@
1
+ import type { PcbFabricationNoteDimension } from "circuit-json"
2
+ import { escapeJsxText } from "./footprint-tsx-attribute-formatters/escape-jsx-text"
3
+
4
+ export const convertFabricationNoteDimension = (
5
+ dimension: PcbFabricationNoteDimension,
6
+ ): string[] => {
7
+ const from = dimension.from ?? { x: 0, y: 0 }
8
+ const to = dimension.to ?? { x: 0, y: 0 }
9
+ const offsetDistance = dimension.offset_distance ?? dimension.offset
10
+ const attrs = [
11
+ `from={{ x: ${from.x}, y: ${from.y} }}`,
12
+ `to={{ x: ${to.x}, y: ${to.y} }}`,
13
+ ]
14
+
15
+ if (dimension.text !== undefined) {
16
+ attrs.push(`text="${escapeJsxText(dimension.text)}"`)
17
+ }
18
+ if (dimension.font !== undefined) attrs.push(`font="${dimension.font}"`)
19
+ if (dimension.font_size !== undefined) {
20
+ attrs.push(`fontSize={${dimension.font_size}}`)
21
+ }
22
+ if (dimension.color !== undefined) attrs.push(`color="${dimension.color}"`)
23
+ if (dimension.arrow_size !== undefined) {
24
+ attrs.push(`arrowSize={${dimension.arrow_size}}`)
25
+ }
26
+ if (offsetDistance !== undefined) {
27
+ attrs.push(`offset={${offsetDistance}}`)
28
+ }
29
+ if (dimension.offset_direction !== undefined) {
30
+ attrs.push(
31
+ `offsetDirection={${JSON.stringify(dimension.offset_direction)}}`,
32
+ )
33
+ }
34
+ if (dimension.layer === "bottom") attrs.push(`layer="bottom"`)
35
+
36
+ return [`<fabricationnotedimension ${attrs.join(" ")} />`]
37
+ }
@@ -2,6 +2,7 @@ import { su } from "@tscircuit/soup-util"
2
2
  import { formatPcbRotationAttr } from "./footprint-tsx-attribute-formatters/format-pcb-rotation-attr"
3
3
  import type { FootprintElementConverter } from "./converter-types"
4
4
  import { escapeJsxText } from "./footprint-tsx-attribute-formatters/escape-jsx-text"
5
+ import { convertFabricationNoteDimension } from "./convert-fabrication-note-dimension"
5
6
 
6
7
  export const convertFabrication: FootprintElementConverter = (circuitJson) => {
7
8
  const fabricationNotePaths = su(circuitJson).pcb_fabrication_note_path.list()
@@ -89,41 +90,7 @@ export const convertFabrication: FootprintElementConverter = (circuitJson) => {
89
90
  }
90
91
 
91
92
  for (const fabDimension of fabricationNoteDimensions) {
92
- const fromPoint = fabDimension.from ?? { x: 0, y: 0 }
93
- const toPoint = fabDimension.to ?? { x: 0, y: 0 }
94
- const attrs = [
95
- `from={{ x: ${fromPoint.x}, y: ${fromPoint.y} }}`,
96
- `to={{ x: ${toPoint.x}, y: ${toPoint.y} }}`,
97
- ]
98
-
99
- if (fabDimension.text !== undefined) {
100
- attrs.push(`text="${escapeJsxText(fabDimension.text)}"`)
101
- }
102
- if (fabDimension.font !== undefined) {
103
- attrs.push(`font="${fabDimension.font}"`)
104
- }
105
- if (fabDimension.font_size !== undefined) {
106
- attrs.push(`fontSize={${fabDimension.font_size}}`)
107
- }
108
- if (fabDimension.color !== undefined) {
109
- attrs.push(`color="${fabDimension.color}"`)
110
- }
111
- if (fabDimension.arrow_size !== undefined) {
112
- attrs.push(`arrowSize={${fabDimension.arrow_size}}`)
113
- }
114
- if (fabDimension.offset !== undefined) {
115
- attrs.push(`offset={${fabDimension.offset}}`)
116
- } else if (
117
- "offset_distance" in fabDimension &&
118
- fabDimension.offset_distance !== undefined
119
- ) {
120
- attrs.push(`offset={${fabDimension.offset_distance}}`)
121
- }
122
- if (fabDimension.layer === "bottom") {
123
- attrs.push(`layer="bottom"`)
124
- }
125
-
126
- elementStrings.push(`<fabricationnotedimension ${attrs.join(" ")} />`)
93
+ elementStrings.push(...convertFabricationNoteDimension(fabDimension))
127
94
  }
128
95
 
129
96
  return elementStrings
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.61",
9
+ "version": "0.0.63",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/tscircuit/circuit-json-to-tscircuit.git"
@@ -0,0 +1,8 @@
1
+ <svg width="1624" height="600" viewBox="0 0 1624 600" xmlns="http://www.w3.org/2000/svg" aria-label="fabrication dimension source on left, generated tscircuit render on right" role="img">
2
+ <g transform="translate(0, 0)">
3
+ <style></style><rect class="boundary" x="0" y="0" fill="#000" width="800" height="600" data-type="pcb_background" data-pcb-layer="global"/><rect class="pcb-boundary" fill="none" stroke="#fff" stroke-width="0.3" x="100" y="50" width="600" height="500" data-type="pcb_boundary" data-pcb-layer="global"/><path class="pcb-board" d="M 100 550 L 700 550 L 700 50 L 100 50 Z" fill="none" stroke="rgba(255, 255, 255, 0.5)" stroke-width="5" data-type="pcb_board" data-pcb-layer="board"/><g class="pcb-fabrication-note-dimension" data-type="pcb_fabrication_note_dimension" data-pcb-fabrication-note-dimension-id="pcb_fabrication_note_dimension_0" data-pcb-layer="top" data-pcb-component-id="pcb_component_0"><path d="M 250 300 L 276.5165042944955 326.5165042944955" stroke="#ec4899" fill="none" stroke-width="5" stroke-linecap="round" class="pcb-fabrication-note-dimension-extension"/><path d="M 550 300 L 576.5165042944955 326.5165042944955" stroke="#ec4899" fill="none" stroke-width="5" stroke-linecap="round" class="pcb-fabrication-note-dimension-extension"/><path d="M 283.83883476483186 308.83883476483186 L 533.8388347648319 308.83883476483186" stroke="#ec4899" fill="none" stroke-width="5" stroke-linecap="round" class="pcb-fabrication-note-dimension-line"/><path d="M 258.83883476483186 308.83883476483186 L 283.83883476483186 296.33883476483186 L 283.83883476483186 321.33883476483186 Z" fill="#ec4899" class="pcb-fabrication-note-dimension-arrow"/><path d="M 558.8388347648319 308.83883476483186 L 533.8388347648319 296.33883476483186 L 533.8388347648319 321.33883476483186 Z" fill="#ec4899" class="pcb-fabrication-note-dimension-arrow"/><text x="408.83883476483186" y="271.33883476483186" fill="#ec4899" font-size="40" font-family="Arial, sans-serif" text-anchor="middle" dominant-baseline="central" class="pcb-fabrication-note-dimension-text" transform="rotate(0 408.83883476483186 271.33883476483186)">6 mm</text></g>
4
+ </g>
5
+ <g transform="translate(824, 0)">
6
+ <style></style><rect class="boundary" x="0" y="0" fill="#000" width="800" height="600" data-type="pcb_background" data-pcb-layer="global"/><rect class="pcb-boundary" fill="none" stroke="#fff" stroke-width="0.3" x="100" y="50" width="600" height="500" data-type="pcb_boundary" data-pcb-layer="global"/><path class="pcb-board" d="M 100 550 L 700 550 L 700 50 L 100 50 Z" fill="none" stroke="rgba(255, 255, 255, 0.5)" stroke-width="5" data-type="pcb_board" data-pcb-layer="board"/><g class="pcb-fabrication-note-dimension" data-type="pcb_fabrication_note_dimension" data-pcb-fabrication-note-dimension-id="pcb_fabrication_note_dimension_0__stack1" data-pcb-layer="top" data-pcb-component-id="pcb_component_0__stack1"><path d="M 250 300 L 276.5165042944955 326.5165042944955" stroke="#ec4899" fill="none" stroke-width="5" stroke-linecap="round" class="pcb-fabrication-note-dimension-extension"/><path d="M 550 300 L 576.5165042944955 326.5165042944955" stroke="#ec4899" fill="none" stroke-width="5" stroke-linecap="round" class="pcb-fabrication-note-dimension-extension"/><path d="M 283.83883476483186 308.83883476483186 L 533.8388347648319 308.83883476483186" stroke="#ec4899" fill="none" stroke-width="5" stroke-linecap="round" class="pcb-fabrication-note-dimension-line"/><path d="M 258.83883476483186 308.83883476483186 L 283.83883476483186 296.33883476483186 L 283.83883476483186 321.33883476483186 Z" fill="#ec4899" class="pcb-fabrication-note-dimension-arrow"/><path d="M 558.8388347648319 308.83883476483186 L 533.8388347648319 296.33883476483186 L 533.8388347648319 321.33883476483186 Z" fill="#ec4899" class="pcb-fabrication-note-dimension-arrow"/><text x="408.83883476483186" y="271.33883476483186" fill="#ec4899" font-size="40" font-family="Arial, sans-serif" text-anchor="middle" dominant-baseline="central" class="pcb-fabrication-note-dimension-text" transform="rotate(0 408.83883476483186 271.33883476483186)">6 mm</text></g>
7
+ </g>
8
+ </svg>
@@ -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>
@@ -0,0 +1,74 @@
1
+ import { expect, test } from "bun:test"
2
+ import type { CircuitJson } from "circuit-json"
3
+ import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
4
+ import { convertCircuitJsonToTscircuit } from "lib"
5
+ import { stackSvgsHorizontally } from "stack-svgs"
6
+ import { runTscircuitCode } from "tscircuit"
7
+
8
+ test("preserves fabrication dimension offset direction", async () => {
9
+ const generatedTscircuit = convertCircuitJsonToTscircuit(sourceCircuitJson, {
10
+ componentName: "FabricationDimensionBoard",
11
+ })
12
+ const renderedCircuitJson = (await runTscircuitCode(
13
+ generatedTscircuit,
14
+ )) as CircuitJson
15
+ const renderedDimension = renderedCircuitJson.find(
16
+ (element) => element.type === "pcb_fabrication_note_dimension",
17
+ )
18
+ expect(renderedDimension).toMatchObject({
19
+ from: { x: -3, y: 0 },
20
+ to: { x: 3, y: 0 },
21
+ offset_distance: 0.25,
22
+ offset_direction: { x: 1, y: -1 },
23
+ })
24
+ expect(
25
+ renderedCircuitJson.filter(
26
+ (element) => element.type === "pcb_fabrication_note_path",
27
+ ),
28
+ ).toHaveLength(0)
29
+
30
+ const comparisonSvg = stackSvgsHorizontally(
31
+ [
32
+ convertCircuitJsonToPcbSvg(sourceCircuitJson),
33
+ convertCircuitJsonToPcbSvg(renderedCircuitJson),
34
+ ],
35
+ {
36
+ gap: 24,
37
+ targetSize: 800,
38
+ rootAttributes: {
39
+ "aria-label":
40
+ "fabrication dimension source on left, generated tscircuit render on right",
41
+ role: "img",
42
+ },
43
+ },
44
+ )
45
+ await expect(comparisonSvg).toMatchSvgSnapshot(import.meta.path, "comparison")
46
+ })
47
+
48
+ const sourceCircuitJson: CircuitJson = [
49
+ {
50
+ type: "pcb_board",
51
+ pcb_board_id: "pcb_board_0",
52
+ center: { x: 0, y: 0 },
53
+ width: 12,
54
+ height: 10,
55
+ thickness: 1.6,
56
+ num_layers: 2,
57
+ material: "fr4",
58
+ },
59
+ {
60
+ type: "pcb_fabrication_note_dimension",
61
+ pcb_fabrication_note_dimension_id: "pcb_fabrication_note_dimension_0",
62
+ pcb_component_id: "pcb_component_0",
63
+ layer: "top",
64
+ from: { x: -3, y: 0 },
65
+ to: { x: 3, y: 0 },
66
+ text: "6 mm",
67
+ font: "tscircuit2024",
68
+ font_size: 0.8,
69
+ color: "#ec4899",
70
+ arrow_size: 0.5,
71
+ offset_distance: 0.25,
72
+ offset_direction: { x: 1, y: -1 },
73
+ },
74
+ ]