circuit-json-to-tscircuit 0.0.13 → 0.0.15
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-YX563LGB.js → chunk-GNI7MTM4.js} +49 -1
- package/dist/cli/main.js +2 -2
- package/dist/lib/index.js +1 -1
- package/lib/generate-footprint-tsx.tsx +5 -1
- package/lib/generate-symbol-tsx.ts +55 -1
- package/package.json +1 -1
- package/tests/__snapshots__/test7-support-schematic-elements-comprehensive-schematic-symbol.snap.svg +25 -0
- package/tests/test7-support-schematic-elements.test.tsx +123 -0
- package/tests/test9-support-pill-plated-hole-rotation.test.tsx +64 -0
- package/tests/test7-support-schematic-arc.test.tsx +0 -59
|
@@ -28,8 +28,9 @@ var generateFootprintTsx = (circuitJson) => {
|
|
|
28
28
|
}
|
|
29
29
|
for (const platedHole of platedHoles) {
|
|
30
30
|
if (platedHole.shape === "oval" || platedHole.shape === "pill") {
|
|
31
|
+
const pcbRotation = "ccw_rotation" in platedHole && platedHole.ccw_rotation !== void 0 ? ` pcbRotation="${typeof platedHole.ccw_rotation === "number" ? `${platedHole.ccw_rotation}deg` : platedHole.ccw_rotation}"` : "";
|
|
31
32
|
elementStrings.push(
|
|
32
|
-
`<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" outerHeight="${mmStr(platedHole.outer_height)}" outerWidth="${mmStr(platedHole.outer_width)}" holeHeight="${mmStr(platedHole.hole_height)}" holeWidth="${mmStr(platedHole.hole_width)}" height="${mmStr(platedHole.hole_height)}" shape="${platedHole.shape}" />`
|
|
33
|
+
`<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" outerHeight="${mmStr(platedHole.outer_height)}" outerWidth="${mmStr(platedHole.outer_width)}" holeHeight="${mmStr(platedHole.hole_height)}" holeWidth="${mmStr(platedHole.hole_width)}" height="${mmStr(platedHole.hole_height)}" shape="${platedHole.shape}"${pcbRotation} />`
|
|
33
34
|
);
|
|
34
35
|
} else if (platedHole.shape === "circle") {
|
|
35
36
|
elementStrings.push(
|
|
@@ -249,6 +250,10 @@ import { su as su2 } from "@tscircuit/soup-util";
|
|
|
249
250
|
var generateSymbolTsx = (circuitJson) => {
|
|
250
251
|
const schematicArcs = su2(circuitJson).schematic_arc.list();
|
|
251
252
|
const schematicLines = su2(circuitJson).schematic_line.list();
|
|
253
|
+
const schematicPaths = su2(circuitJson).schematic_path.list();
|
|
254
|
+
const schematicTexts = su2(circuitJson).schematic_text.list();
|
|
255
|
+
const schematicCircles = su2(circuitJson).schematic_circle.list();
|
|
256
|
+
const schematicBoxes = su2(circuitJson).schematic_box.list();
|
|
252
257
|
const elementStrings = [];
|
|
253
258
|
for (const arc of schematicArcs) {
|
|
254
259
|
const center = arc.center ?? { x: 0, y: 0 };
|
|
@@ -284,6 +289,49 @@ var generateSymbolTsx = (circuitJson) => {
|
|
|
284
289
|
`<schematicline x1={${x1}} y1={${y1}} x2={${x2}} y2={${y2}} strokeWidth={${strokeWidth}} color="${color}" isDashed={${isDashed}}/>`
|
|
285
290
|
);
|
|
286
291
|
}
|
|
292
|
+
for (const box of schematicBoxes) {
|
|
293
|
+
const x = box.x ?? 0;
|
|
294
|
+
const y = box.y ?? 0;
|
|
295
|
+
const width = box.width ?? 0;
|
|
296
|
+
const height = box.height ?? 0;
|
|
297
|
+
const isDashed = box.is_dashed ?? false;
|
|
298
|
+
elementStrings.push(
|
|
299
|
+
`<schematicbox center={{ x: ${x}, y: ${y} }} width={${width}} height={${height}} isDashed={${isDashed}}/>`
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
for (const path of schematicPaths) {
|
|
303
|
+
const points = path.points ?? [];
|
|
304
|
+
const fillColor = path.fill_color ?? "red";
|
|
305
|
+
const isFilled = path.is_filled ?? false;
|
|
306
|
+
elementStrings.push(
|
|
307
|
+
`<schematicpath points={${JSON.stringify(points)}} strokeColor="${fillColor}" fillColor="${fillColor}" isFilled={${isFilled}}/>`
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
for (const text of schematicTexts) {
|
|
311
|
+
const x = text.position?.x ?? 0;
|
|
312
|
+
const y = text.position?.y ?? 0;
|
|
313
|
+
const rawText = String(text.text ?? "");
|
|
314
|
+
const escapedText = rawText.replace(/"/g, '\\"');
|
|
315
|
+
const anchorAlignment = text.anchor ?? "center";
|
|
316
|
+
const fontSize = text.font_size ?? 0.1;
|
|
317
|
+
const color = text.color ?? "black";
|
|
318
|
+
const rotation = text.rotation ?? 0;
|
|
319
|
+
elementStrings.push(
|
|
320
|
+
`<schematictext text="${escapedText}" x={${x}} y={${y}} anchorAlignment="${anchorAlignment}" fontSize={${fontSize}} color="${color}" rotation={${rotation}} />`
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
for (const circle of schematicCircles) {
|
|
324
|
+
const x = circle.center?.x ?? 0;
|
|
325
|
+
const y = circle.center?.y ?? 0;
|
|
326
|
+
const radius = circle.radius ?? 0;
|
|
327
|
+
const strokeWidth = circle.stroke_width ?? 0.05;
|
|
328
|
+
const color = circle.color ?? "black";
|
|
329
|
+
const isFilled = circle.is_filled ?? false;
|
|
330
|
+
const isDashed = circle.is_dashed ?? false;
|
|
331
|
+
elementStrings.push(
|
|
332
|
+
`<schematiccircle center={{ x: ${x}, y: ${y} }} radius={${radius}} strokeWidth={${strokeWidth}} color="${color}" isFilled={${isFilled}} isDashed={${isDashed}} />`
|
|
333
|
+
);
|
|
334
|
+
}
|
|
287
335
|
if (elementStrings.length === 0) {
|
|
288
336
|
return null;
|
|
289
337
|
}
|
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-GNI7MTM4.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.14",
|
|
20
20
|
scripts: {
|
|
21
21
|
build: "tsup-node lib/index.ts cli/main.ts --format esm --dts",
|
|
22
22
|
test: "bun test",
|
package/dist/lib/index.js
CHANGED
|
@@ -34,8 +34,12 @@ export const generateFootprintTsx = (
|
|
|
34
34
|
|
|
35
35
|
for (const platedHole of platedHoles) {
|
|
36
36
|
if (platedHole.shape === "oval" || platedHole.shape === "pill") {
|
|
37
|
+
const pcbRotation =
|
|
38
|
+
"ccw_rotation" in platedHole && platedHole.ccw_rotation !== undefined
|
|
39
|
+
? ` pcbRotation="${typeof platedHole.ccw_rotation === "number" ? `${platedHole.ccw_rotation}deg` : platedHole.ccw_rotation}"`
|
|
40
|
+
: ""
|
|
37
41
|
elementStrings.push(
|
|
38
|
-
`<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" outerHeight="${mmStr(platedHole.outer_height)}" outerWidth="${mmStr(platedHole.outer_width)}" holeHeight="${mmStr(platedHole.hole_height)}" holeWidth="${mmStr(platedHole.hole_width)}" height="${mmStr(platedHole.hole_height)}" shape="${platedHole.shape}" />`,
|
|
42
|
+
`<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" outerHeight="${mmStr(platedHole.outer_height)}" outerWidth="${mmStr(platedHole.outer_width)}" holeHeight="${mmStr(platedHole.hole_height)}" holeWidth="${mmStr(platedHole.hole_width)}" height="${mmStr(platedHole.hole_height)}" shape="${platedHole.shape}"${pcbRotation} />`,
|
|
39
43
|
)
|
|
40
44
|
} else if (platedHole.shape === "circle") {
|
|
41
45
|
elementStrings.push(
|
|
@@ -6,7 +6,10 @@ export const generateSymbolTsx = (
|
|
|
6
6
|
): string | null => {
|
|
7
7
|
const schematicArcs = su(circuitJson).schematic_arc.list()
|
|
8
8
|
const schematicLines = su(circuitJson).schematic_line.list()
|
|
9
|
-
|
|
9
|
+
const schematicPaths = su(circuitJson).schematic_path.list()
|
|
10
|
+
const schematicTexts = su(circuitJson).schematic_text.list()
|
|
11
|
+
const schematicCircles = su(circuitJson).schematic_circle.list()
|
|
12
|
+
const schematicBoxes = su(circuitJson).schematic_box.list()
|
|
10
13
|
const elementStrings: string[] = []
|
|
11
14
|
|
|
12
15
|
for (const arc of schematicArcs) {
|
|
@@ -47,6 +50,57 @@ export const generateSymbolTsx = (
|
|
|
47
50
|
)
|
|
48
51
|
}
|
|
49
52
|
|
|
53
|
+
for (const box of schematicBoxes) {
|
|
54
|
+
const x = box.x ?? 0
|
|
55
|
+
const y = box.y ?? 0
|
|
56
|
+
const width = box.width ?? 0
|
|
57
|
+
const height = box.height ?? 0
|
|
58
|
+
const isDashed = box.is_dashed ?? false
|
|
59
|
+
|
|
60
|
+
elementStrings.push(
|
|
61
|
+
`<schematicbox center={{ x: ${x}, y: ${y} }} width={${width}} height={${height}} isDashed={${isDashed}}/>`,
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (const path of schematicPaths) {
|
|
66
|
+
const points = path.points ?? []
|
|
67
|
+
const fillColor = path.fill_color ?? "red"
|
|
68
|
+
const isFilled = path.is_filled ?? false
|
|
69
|
+
|
|
70
|
+
elementStrings.push(
|
|
71
|
+
`<schematicpath points={${JSON.stringify(points)}} strokeColor="${fillColor}" fillColor="${fillColor}" isFilled={${isFilled}}/>`,
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
for (const text of schematicTexts) {
|
|
76
|
+
const x = text.position?.x ?? 0
|
|
77
|
+
const y = text.position?.y ?? 0
|
|
78
|
+
const rawText = String(text.text ?? "")
|
|
79
|
+
const escapedText = rawText.replace(/"/g, '\\"')
|
|
80
|
+
const anchorAlignment = text.anchor ?? "center"
|
|
81
|
+
const fontSize = text.font_size ?? 0.1
|
|
82
|
+
const color = text.color ?? "black"
|
|
83
|
+
const rotation = text.rotation ?? 0
|
|
84
|
+
|
|
85
|
+
elementStrings.push(
|
|
86
|
+
`<schematictext text="${escapedText}" x={${x}} y={${y}} anchorAlignment="${anchorAlignment}" fontSize={${fontSize}} color="${color}" rotation={${rotation}} />`,
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (const circle of schematicCircles) {
|
|
91
|
+
const x = circle.center?.x ?? 0
|
|
92
|
+
const y = circle.center?.y ?? 0
|
|
93
|
+
const radius = circle.radius ?? 0
|
|
94
|
+
const strokeWidth = circle.stroke_width ?? 0.05
|
|
95
|
+
const color = circle.color ?? "black"
|
|
96
|
+
const isFilled = circle.is_filled ?? false
|
|
97
|
+
const isDashed = circle.is_dashed ?? false
|
|
98
|
+
|
|
99
|
+
elementStrings.push(
|
|
100
|
+
`<schematiccircle center={{ x: ${x}, y: ${y} }} radius={${radius}} strokeWidth={${strokeWidth}} color="${color}" isFilled={${isFilled}} isDashed={${isDashed}} />`,
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
50
104
|
if (elementStrings.length === 0) {
|
|
51
105
|
return null
|
|
52
106
|
}
|
package/package.json
CHANGED
package/tests/__snapshots__/test7-support-schematic-elements-comprehensive-schematic-symbol.snap.svg
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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(70.5052878966,0,0,-70.5052878966,493.8895417156,317.9788484136)" data-software-used-string="@tscircuit/core@0.0.1090"><style>
|
|
2
|
+
.boundary { fill: rgb(245, 241, 237); }
|
|
3
|
+
.schematic-boundary { fill: none; stroke: #fff; }
|
|
4
|
+
.component { fill: none; stroke: rgb(132, 0, 0); }
|
|
5
|
+
.chip { fill: rgb(255, 255, 194); stroke: rgb(132, 0, 0); }
|
|
6
|
+
.component-pin { fill: none; stroke: rgb(132, 0, 0); }
|
|
7
|
+
/* Basic per-trace hover fallback */
|
|
8
|
+
.trace:hover {
|
|
9
|
+
filter: invert(1);
|
|
10
|
+
}
|
|
11
|
+
.trace:hover .trace-crossing-outline {
|
|
12
|
+
opacity: 0;
|
|
13
|
+
}
|
|
14
|
+
.trace:hover .trace-junction {
|
|
15
|
+
filter: invert(1);
|
|
16
|
+
}
|
|
17
|
+
/* Net-hover highlighting: when a trace or its overlays are hovered,
|
|
18
|
+
invert color for all traces (base + overlays) sharing the same
|
|
19
|
+
subcircuit connectivity key. Also hide crossing outline during hover. */
|
|
20
|
+
|
|
21
|
+
.text { font-family: sans-serif; fill: rgb(0, 150, 0); }
|
|
22
|
+
.pin-number { fill: rgb(169, 0, 0); }
|
|
23
|
+
.port-label { fill: rgb(0, 100, 100); }
|
|
24
|
+
.component-name { fill: rgb(0, 100, 100); }
|
|
25
|
+
</style><rect class="boundary" x="0" y="0" width="1200" height="600"/><line x1="634.9001175088" y1="317.9788484136" x2="775.910693302" y2="317.9788484136" stroke="black" stroke-width="3.5252643948299998" data-schematic-line-id="schematic_line_0" data-schematic-component-id="schematic_component_0"/><circle cx="705.4054054054" cy="529.4947121033999" r="35.2526439483" fill="green" stroke="green" stroke-width="3.5252643948299998" stroke-dasharray="10.57579318449" data-schematic-circle-id="schematic_circle_0" data-schematic-component-id="schematic_component_0"/><path d="M 564.3948296121999 317.9788484136 A 70.5052878966 70.5052878966 0 0 0 423.384253819 317.9788484136" fill="none" stroke="black" stroke-width="3.5252643948299998" data-schematic-arc-id="schematic_arc_0" data-schematic-component-id="schematic_component_0"/><path d="M 705.4054054054 106.46298472380005 L 775.910693302 35.95769682720004" stroke="blue" stroke-width="1.410105757932" fill="none" stroke-linecap="round" stroke-linejoin="round" data-schematic-component-id="schematic_component_0"/><text x="493.8895417156" y="317.9788484136" fill="red" text-anchor="middle" dominant-baseline="middle" font-family="sans-serif" font-size="14.101057579319999px" transform="rotate(0, 493.8895417156, 317.9788484136)">U1</text><rect class="schematic-box" x="423.384253819" y="247.473560517" width="141.01057579319996" height="141.01057579320002" stroke-width="1.410105757932px" stroke="rgb(132, 0, 0)" fill="transparent"/></svg>
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { test, expect } from "bun:test"
|
|
2
|
+
import { convertCircuitJsonToTscircuit } from "lib/index"
|
|
3
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
4
|
+
import { runTscircuitCode } from "tscircuit"
|
|
5
|
+
import { convertCircuitJsonToSchematicSvg } from "circuit-to-svg"
|
|
6
|
+
|
|
7
|
+
const circuitJson: AnyCircuitElement[] = [
|
|
8
|
+
{
|
|
9
|
+
type: "schematic_arc",
|
|
10
|
+
center: { x: 0, y: 0 },
|
|
11
|
+
schematic_arc_id: "schematic_arc_id_1",
|
|
12
|
+
radius: 1,
|
|
13
|
+
schematic_component_id: "schematic_component_id_1",
|
|
14
|
+
start_angle_degrees: 0,
|
|
15
|
+
end_angle_degrees: 180,
|
|
16
|
+
stroke_width: 0.05,
|
|
17
|
+
color: "black",
|
|
18
|
+
is_dashed: false,
|
|
19
|
+
direction: "counterclockwise",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: "schematic_line",
|
|
23
|
+
x1: 2,
|
|
24
|
+
schematic_line_id: "schematic_line_id_1",
|
|
25
|
+
schematic_component_id: "schematic_component_id_1",
|
|
26
|
+
y1: 0,
|
|
27
|
+
x2: 4,
|
|
28
|
+
y2: 0,
|
|
29
|
+
stroke_width: 0.05,
|
|
30
|
+
color: "black",
|
|
31
|
+
is_dashed: false,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: "schematic_box",
|
|
35
|
+
schematic_component_id: "schematic_component_id_1",
|
|
36
|
+
x: 0,
|
|
37
|
+
y: 3,
|
|
38
|
+
width: 2,
|
|
39
|
+
height: 2,
|
|
40
|
+
is_dashed: true,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: "schematic_path",
|
|
44
|
+
schematic_path_id: "schematic_path_id_1",
|
|
45
|
+
points: [
|
|
46
|
+
{ x: 3, y: 3 },
|
|
47
|
+
{ x: 4, y: 4 },
|
|
48
|
+
],
|
|
49
|
+
fill_color: "blue",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: "schematic_text",
|
|
53
|
+
schematic_text_id: "schematic_text_id_1",
|
|
54
|
+
text: "U1",
|
|
55
|
+
position: { x: 0, y: -3 },
|
|
56
|
+
anchor: "center",
|
|
57
|
+
font_size: 0.2,
|
|
58
|
+
color: "red",
|
|
59
|
+
rotation: 45,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: "schematic_circle",
|
|
63
|
+
center: { x: 3, y: -3 },
|
|
64
|
+
schematic_circle_id: "schematic_circle_id_1",
|
|
65
|
+
radius: 0.5,
|
|
66
|
+
stroke_width: 0.05,
|
|
67
|
+
color: "green",
|
|
68
|
+
is_filled: true,
|
|
69
|
+
is_dashed: true,
|
|
70
|
+
},
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
test("test7 comprehensive schematic symbol support", async () => {
|
|
74
|
+
const tscircuit = convertCircuitJsonToTscircuit(circuitJson, {
|
|
75
|
+
componentName: "U1",
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
expect(tscircuit).toMatchInlineSnapshot(`
|
|
79
|
+
"import { type ChipProps } from "tscircuit"
|
|
80
|
+
export const U1 = (props: ChipProps) => (
|
|
81
|
+
<chip
|
|
82
|
+
symbol={<symbol>
|
|
83
|
+
<schematicarc
|
|
84
|
+
center={{ x: 0, y: 0 }}
|
|
85
|
+
radius={1}
|
|
86
|
+
startAngleDegrees={0}
|
|
87
|
+
endAngleDegrees={180}
|
|
88
|
+
strokeWidth={0.05}
|
|
89
|
+
color="black"
|
|
90
|
+
isDashed={false}
|
|
91
|
+
direction="counterclockwise"
|
|
92
|
+
/>
|
|
93
|
+
<schematicline x1={2} y1={0} x2={4} y2={0} strokeWidth={0.05} color="black" isDashed={false}/>
|
|
94
|
+
<schematicbox center={{ x: 0, y: 3 }} width={2} height={2} isDashed={true}/>
|
|
95
|
+
<schematicpath points={[{"x":3,"y":3},{"x":4,"y":4}]} strokeColor="blue" fillColor="blue" isFilled={false}/>
|
|
96
|
+
<schematictext text="U1" x={0} y={-3} anchorAlignment="center" fontSize={0.2} color="red" rotation={45} />
|
|
97
|
+
<schematiccircle center={{ x: 3, y: -3 }} radius={0.5} strokeWidth={0.05} color="green" isFilled={true} isDashed={true} />
|
|
98
|
+
</symbol>}
|
|
99
|
+
{...props}
|
|
100
|
+
/>
|
|
101
|
+
)"
|
|
102
|
+
`)
|
|
103
|
+
const result = await runTscircuitCode(tscircuit)
|
|
104
|
+
|
|
105
|
+
expect(Array.isArray(result)).toBe(true)
|
|
106
|
+
expect(result).not.toHaveLength(0)
|
|
107
|
+
}, 15000)
|
|
108
|
+
|
|
109
|
+
test("test7 comprehensive schematic symbol support svg", async () => {
|
|
110
|
+
const tscircuit = convertCircuitJsonToTscircuit(circuitJson, {
|
|
111
|
+
componentName: "U1",
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const result = await runTscircuitCode(tscircuit)
|
|
115
|
+
|
|
116
|
+
const schematicSvg = convertCircuitJsonToSchematicSvg(
|
|
117
|
+
result as AnyCircuitElement[],
|
|
118
|
+
)
|
|
119
|
+
await expect(schematicSvg).toMatchSvgSnapshot(
|
|
120
|
+
import.meta.path,
|
|
121
|
+
"comprehensive-schematic-symbol",
|
|
122
|
+
)
|
|
123
|
+
})
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { test, expect } from "bun:test"
|
|
2
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
3
|
+
import { convertCircuitJsonToTscircuit } from "lib/index"
|
|
4
|
+
import { runTscircuitCode } from "tscircuit"
|
|
5
|
+
|
|
6
|
+
declare module "bun:test" {
|
|
7
|
+
interface Matchers<T = unknown> {
|
|
8
|
+
toMatchInlineSnapshot(snapshot?: string | null): Promise<MatcherResult>
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
test("test pill and oval plated hole rotation conversion", async () => {
|
|
13
|
+
const circuitJson: AnyCircuitElement[] = [
|
|
14
|
+
{
|
|
15
|
+
type: "pcb_plated_hole",
|
|
16
|
+
pcb_plated_hole_id: "ph1",
|
|
17
|
+
shape: "pill",
|
|
18
|
+
x: 1.5,
|
|
19
|
+
y: -2.5,
|
|
20
|
+
outer_width: 1.8,
|
|
21
|
+
outer_height: 0.9,
|
|
22
|
+
hole_width: 1.2,
|
|
23
|
+
hole_height: 0.4,
|
|
24
|
+
ccw_rotation: 90,
|
|
25
|
+
layers: ["top", "bottom"],
|
|
26
|
+
port_hints: ["1"],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: "pcb_plated_hole",
|
|
30
|
+
pcb_plated_hole_id: "ph2",
|
|
31
|
+
shape: "oval",
|
|
32
|
+
x: 3.5,
|
|
33
|
+
y: 2.25,
|
|
34
|
+
outer_width: 2.2,
|
|
35
|
+
outer_height: 1.1,
|
|
36
|
+
hole_width: 1.4,
|
|
37
|
+
hole_height: 0.5,
|
|
38
|
+
ccw_rotation: 45,
|
|
39
|
+
layers: ["top", "bottom"],
|
|
40
|
+
port_hints: ["2"],
|
|
41
|
+
},
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
const tscircuit = convertCircuitJsonToTscircuit(circuitJson, {
|
|
45
|
+
componentName: "ComponentWithPillPlatedHoleRotation",
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
expect(tscircuit).toMatchInlineSnapshot(`
|
|
49
|
+
"import { type ChipProps } from "tscircuit"
|
|
50
|
+
export const ComponentWithPillPlatedHoleRotation = (props: ChipProps) => (
|
|
51
|
+
<chip
|
|
52
|
+
footprint={<footprint>
|
|
53
|
+
<platedhole portHints={["1"]} pcbX="1.5mm" pcbY="-2.5mm" outerHeight="0.9mm" outerWidth="1.8mm" holeHeight="0.4mm" holeWidth="1.2mm" height="0.4mm" shape="pill" pcbRotation="90deg" />
|
|
54
|
+
<platedhole portHints={["2"]} pcbX="3.5mm" pcbY="2.25mm" outerHeight="1.1mm" outerWidth="2.2mm" holeHeight="0.5mm" holeWidth="1.4mm" height="0.5mm" shape="oval" pcbRotation="45deg" />
|
|
55
|
+
</footprint>}
|
|
56
|
+
{...props}
|
|
57
|
+
/>
|
|
58
|
+
)"
|
|
59
|
+
`)
|
|
60
|
+
|
|
61
|
+
const result = await runTscircuitCode(tscircuit)
|
|
62
|
+
expect(Array.isArray(result)).toBe(true)
|
|
63
|
+
expect(result).not.toHaveLength(0)
|
|
64
|
+
}, 10000)
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "bun:test"
|
|
2
|
-
import { convertCircuitJsonToTscircuit } from "lib/index"
|
|
3
|
-
import type { AnyCircuitElement } from "circuit-json"
|
|
4
|
-
|
|
5
|
-
test("test7 schematic arc and line inline snapshot", async () => {
|
|
6
|
-
const circuitJson: AnyCircuitElement[] = [
|
|
7
|
-
{
|
|
8
|
-
type: "schematic_arc",
|
|
9
|
-
center: { x: 0, y: 0 },
|
|
10
|
-
radius: 1,
|
|
11
|
-
start_angle_degrees: 0,
|
|
12
|
-
end_angle_degrees: 180,
|
|
13
|
-
stroke_width: 0.05,
|
|
14
|
-
color: "black",
|
|
15
|
-
is_dashed: false,
|
|
16
|
-
schematic_component_id: "schematic_component_id_1",
|
|
17
|
-
direction: "counterclockwise",
|
|
18
|
-
schematic_arc_id: "schematic_arc_id_1",
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
type: "schematic_line",
|
|
22
|
-
x1: -1,
|
|
23
|
-
y1: 0,
|
|
24
|
-
x2: 1,
|
|
25
|
-
y2: 0,
|
|
26
|
-
stroke_width: 0.05,
|
|
27
|
-
schematic_line_id: "schematic_line_id_1",
|
|
28
|
-
schematic_component_id: "schematic_component_id_1",
|
|
29
|
-
color: "black",
|
|
30
|
-
is_dashed: false,
|
|
31
|
-
},
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
const tscircuit = convertCircuitJsonToTscircuit(circuitJson, {
|
|
35
|
-
componentName: "U1",
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
expect(tscircuit).toMatchInlineSnapshot(`
|
|
39
|
-
"import { type ChipProps } from "tscircuit"
|
|
40
|
-
export const U1 = (props: ChipProps) => (
|
|
41
|
-
<chip
|
|
42
|
-
symbol={<symbol>
|
|
43
|
-
<schematicarc
|
|
44
|
-
center={{ x: 0, y: 0 }}
|
|
45
|
-
radius={1}
|
|
46
|
-
startAngleDegrees={0}
|
|
47
|
-
endAngleDegrees={180}
|
|
48
|
-
strokeWidth={0.05}
|
|
49
|
-
color="black"
|
|
50
|
-
isDashed={false}
|
|
51
|
-
direction="counterclockwise"
|
|
52
|
-
/>
|
|
53
|
-
<schematicline x1={-1} y1={0} x2={1} y2={0} strokeWidth={0.05} color="black" isDashed={false}/>
|
|
54
|
-
</symbol>}
|
|
55
|
-
{...props}
|
|
56
|
-
/>
|
|
57
|
-
)"
|
|
58
|
-
`)
|
|
59
|
-
})
|