circuit-json-to-tscircuit 0.0.21 → 0.0.23
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-3AWPESWI.js → chunk-KF5NKSNK.js} +37 -0
- package/dist/cli/main.js +2 -2
- package/dist/lib/index.js +1 -1
- package/lib/generate-footprint-tsx.tsx +44 -0
- package/package.json +1 -1
- package/tests/__snapshots__/test12-support-silkscreen-line-pcb.snap.svg +1 -0
- package/tests/__snapshots__/test13-support-silkscreen-rect-pcb.snap.svg +1 -0
- package/tests/test12-support-silkscreen-line.test.tsx +94 -0
- package/tests/test13-support-silkscreen-rect.test.tsx +85 -0
|
@@ -5,7 +5,9 @@ var generateFootprintTsx = (circuitJson) => {
|
|
|
5
5
|
const holes = su(circuitJson).pcb_hole.list();
|
|
6
6
|
const platedHoles = su(circuitJson).pcb_plated_hole.list();
|
|
7
7
|
const smtPads = su(circuitJson).pcb_smtpad.list();
|
|
8
|
+
const silkscreenLines = su(circuitJson).pcb_silkscreen_line.list();
|
|
8
9
|
const silkscreenPaths = su(circuitJson).pcb_silkscreen_path.list();
|
|
10
|
+
const silkscreenRects = su(circuitJson).pcb_silkscreen_rect.list();
|
|
9
11
|
const fabricationNotePaths = su(circuitJson).pcb_fabrication_note_path.list();
|
|
10
12
|
const fabricationNoteTexts = su(circuitJson).pcb_fabrication_note_text.list();
|
|
11
13
|
const fabricationNoteRects = su(circuitJson).pcb_fabrication_note_rect.list();
|
|
@@ -59,6 +61,41 @@ var generateFootprintTsx = (circuitJson) => {
|
|
|
59
61
|
`<silkscreenpath route={${JSON.stringify(silkscreenPath.route)}} />`
|
|
60
62
|
);
|
|
61
63
|
}
|
|
64
|
+
for (const silkscreenRect of silkscreenRects) {
|
|
65
|
+
const center = silkscreenRect.center ?? { x: 0, y: 0 };
|
|
66
|
+
const attrs = [
|
|
67
|
+
`pcbX={${center.x}}`,
|
|
68
|
+
`pcbY={${center.y}}`,
|
|
69
|
+
`width={${silkscreenRect.width ?? 0}}`,
|
|
70
|
+
`height={${silkscreenRect.height ?? 0}}`,
|
|
71
|
+
`layer="${silkscreenRect.layer}"`
|
|
72
|
+
];
|
|
73
|
+
if (silkscreenRect.stroke_width !== void 0) {
|
|
74
|
+
attrs.push(`strokeWidth={${silkscreenRect.stroke_width}}`);
|
|
75
|
+
}
|
|
76
|
+
if (silkscreenRect.is_filled !== void 0) {
|
|
77
|
+
attrs.push(`filled={${silkscreenRect.is_filled}}`);
|
|
78
|
+
}
|
|
79
|
+
if (silkscreenRect.corner_radius !== void 0) {
|
|
80
|
+
attrs.push(`cornerRadius={${silkscreenRect.corner_radius}}`);
|
|
81
|
+
}
|
|
82
|
+
elementStrings.push(`<silkscreenrect ${attrs.join(" ")} />`);
|
|
83
|
+
}
|
|
84
|
+
for (const silkscreenLine of silkscreenLines) {
|
|
85
|
+
const attrs = [
|
|
86
|
+
`x1={${silkscreenLine.x1 ?? 0}}`,
|
|
87
|
+
`y1={${silkscreenLine.y1 ?? 0}}`,
|
|
88
|
+
`x2={${silkscreenLine.x2 ?? 0}}`,
|
|
89
|
+
`y2={${silkscreenLine.y2 ?? 0}}`
|
|
90
|
+
];
|
|
91
|
+
if (silkscreenLine.stroke_width !== void 0) {
|
|
92
|
+
attrs.push(`strokeWidth={${silkscreenLine.stroke_width}}`);
|
|
93
|
+
}
|
|
94
|
+
if (silkscreenLine.layer === "bottom") {
|
|
95
|
+
attrs.push(`layer="bottom"`);
|
|
96
|
+
}
|
|
97
|
+
elementStrings.push(`<silkscreenline ${attrs.join(" ")} />`);
|
|
98
|
+
}
|
|
62
99
|
for (const fabPath of fabricationNotePaths) {
|
|
63
100
|
const attrs = [`route={${JSON.stringify(fabPath.route)}}`];
|
|
64
101
|
if ("stroke_width" in fabPath && fabPath.stroke_width !== void 0) {
|
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-KF5NKSNK.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.22",
|
|
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
|
@@ -8,7 +8,9 @@ export const generateFootprintTsx = (
|
|
|
8
8
|
const holes = su(circuitJson).pcb_hole.list()
|
|
9
9
|
const platedHoles = su(circuitJson).pcb_plated_hole.list()
|
|
10
10
|
const smtPads = su(circuitJson).pcb_smtpad.list()
|
|
11
|
+
const silkscreenLines = su(circuitJson).pcb_silkscreen_line.list()
|
|
11
12
|
const silkscreenPaths = su(circuitJson).pcb_silkscreen_path.list()
|
|
13
|
+
const silkscreenRects = su(circuitJson).pcb_silkscreen_rect.list()
|
|
12
14
|
const fabricationNotePaths = su(circuitJson).pcb_fabrication_note_path.list()
|
|
13
15
|
const fabricationNoteTexts = su(circuitJson).pcb_fabrication_note_text.list()
|
|
14
16
|
const fabricationNoteRects = su(circuitJson).pcb_fabrication_note_rect.list()
|
|
@@ -72,6 +74,48 @@ export const generateFootprintTsx = (
|
|
|
72
74
|
)
|
|
73
75
|
}
|
|
74
76
|
|
|
77
|
+
for (const silkscreenRect of silkscreenRects) {
|
|
78
|
+
const center = silkscreenRect.center ?? { x: 0, y: 0 }
|
|
79
|
+
const attrs = [
|
|
80
|
+
`pcbX={${center.x}}`,
|
|
81
|
+
`pcbY={${center.y}}`,
|
|
82
|
+
`width={${silkscreenRect.width ?? 0}}`,
|
|
83
|
+
`height={${silkscreenRect.height ?? 0}}`,
|
|
84
|
+
`layer="${silkscreenRect.layer}"`,
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
if (silkscreenRect.stroke_width !== undefined) {
|
|
88
|
+
attrs.push(`strokeWidth={${silkscreenRect.stroke_width}}`)
|
|
89
|
+
}
|
|
90
|
+
if (silkscreenRect.is_filled !== undefined) {
|
|
91
|
+
attrs.push(`filled={${silkscreenRect.is_filled}}`)
|
|
92
|
+
}
|
|
93
|
+
if (silkscreenRect.corner_radius !== undefined) {
|
|
94
|
+
attrs.push(`cornerRadius={${silkscreenRect.corner_radius}}`)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
elementStrings.push(`<silkscreenrect ${attrs.join(" ")} />`)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
for (const silkscreenLine of silkscreenLines) {
|
|
101
|
+
const attrs = [
|
|
102
|
+
`x1={${silkscreenLine.x1 ?? 0}}`,
|
|
103
|
+
`y1={${silkscreenLine.y1 ?? 0}}`,
|
|
104
|
+
`x2={${silkscreenLine.x2 ?? 0}}`,
|
|
105
|
+
`y2={${silkscreenLine.y2 ?? 0}}`,
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
if (silkscreenLine.stroke_width !== undefined) {
|
|
109
|
+
attrs.push(`strokeWidth={${silkscreenLine.stroke_width}}`)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (silkscreenLine.layer === "bottom") {
|
|
113
|
+
attrs.push(`layer="bottom"`)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
elementStrings.push(`<silkscreenline ${attrs.join(" ")} />`)
|
|
117
|
+
}
|
|
118
|
+
|
|
75
119
|
for (const fabPath of fabricationNotePaths) {
|
|
76
120
|
const attrs = [`route={${JSON.stringify(fabPath.route)}}`]
|
|
77
121
|
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="800" height="600" data-software-used-string="@tscircuit/core@0.0.1090"><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="127.27272727272725" y="27.272727272727252" width="545.4545454545455" height="545.4545454545455" data-type="pcb_boundary" data-pcb-layer="global"/><path class="pcb-board" d="M 127.27272727272725 572.7272727272727 L 672.7272727272727 572.7272727272727 L 672.7272727272727 27.272727272727252 L 127.27272727272725 27.272727272727252 Z" fill="none" stroke="rgba(255, 255, 255, 0.5)" stroke-width="2.7272727272727275" data-type="pcb_board" data-pcb-layer="board"/><line x1="372.72727272727275" y1="349.0909090909091" x2="427.27272727272725" y2="349.0909090909091" stroke="#5da9e9" stroke-width="3.2727272727272725" class="pcb-silkscreen-line pcb-silkscreen-bottom" data-pcb-silkscreen-line-id="pcb_silkscreen_line_1" data-type="pcb_silkscreen_line" data-pcb-layer="bottom"/><line x1="372.72727272727275" y1="349.0909090909091" x2="427.27272727272725" y2="349.0909090909091" stroke="#5da9e9" stroke-width="3.2727272727272725" class="pcb-silkscreen-line pcb-silkscreen-bottom" data-pcb-silkscreen-line-id="pcb_silkscreen_line_3" data-type="pcb_silkscreen_line" data-pcb-layer="bottom"/><line x1="372.72727272727275" y1="250.9090909090909" x2="427.27272727272725" y2="250.9090909090909" stroke="#f2eda1" stroke-width="3.2727272727272725" class="pcb-silkscreen-line pcb-silkscreen-top" data-pcb-silkscreen-line-id="pcb_silkscreen_line_0" data-type="pcb_silkscreen_line" data-pcb-layer="top"/><line x1="372.72727272727275" y1="250.9090909090909" x2="427.27272727272725" y2="250.9090909090909" stroke="#f2eda1" stroke-width="3.2727272727272725" class="pcb-silkscreen-line pcb-silkscreen-top" data-pcb-silkscreen-line-id="pcb_silkscreen_line_2" data-type="pcb_silkscreen_line" data-pcb-layer="top"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="800" height="600" data-software-used-string="@tscircuit/core@0.0.1090"><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="127.27272727272725" y="27.272727272727252" width="545.4545454545455" height="545.4545454545455" data-type="pcb_boundary" data-pcb-layer="global"/><path class="pcb-board" d="M 127.27272727272725 572.7272727272727 L 672.7272727272727 572.7272727272727 L 672.7272727272727 27.272727272727252 L 127.27272727272725 27.272727272727252 Z" fill="none" stroke="rgba(255, 255, 255, 0.5)" stroke-width="2.7272727272727275" data-type="pcb_board" data-pcb-layer="board"/><rect x="380.90909090909093" y="286.3636363636363" width="38.18181818181818" height="21.81818181818182" class="pcb-silkscreen-rect pcb-silkscreen-top" data-pcb-silkscreen-rect-id="pcb_silkscreen_rect_0" data-type="pcb_silkscreen_rect" data-pcb-layer="top" rx="2.181818181818182" ry="2.181818181818182" fill="#f2eda1" stroke="#f2eda1" stroke-width="3.2727272727272725"/><rect x="380.90909090909093" y="286.3636363636363" width="38.18181818181818" height="21.81818181818182" class="pcb-silkscreen-rect pcb-silkscreen-top" data-pcb-silkscreen-rect-id="pcb_silkscreen_rect_1" data-type="pcb_silkscreen_rect" data-pcb-layer="top" rx="2.181818181818182" ry="2.181818181818182" fill="#f2eda1" stroke="#f2eda1" stroke-width="3.2727272727272725"/></svg>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
|
|
3
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
4
|
+
import { convertCircuitJsonToTscircuit } from "lib"
|
|
5
|
+
import { runTscircuitCode } from "tscircuit"
|
|
6
|
+
|
|
7
|
+
test("test12 support silkscreen line", async () => {
|
|
8
|
+
const tscircuit = convertCircuitJsonToTscircuit(circuitJson, {
|
|
9
|
+
componentName: "Test12Component",
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
expect(tscircuit).toMatchInlineSnapshot(`
|
|
13
|
+
"import { type ChipProps } from "tscircuit"
|
|
14
|
+
export const Test12Component = (props: ChipProps) => (
|
|
15
|
+
<chip
|
|
16
|
+
footprint={<footprint>
|
|
17
|
+
<silkscreenline x1={-1} y1={1.8} x2={1} y2={1.8} strokeWidth={0.12} />
|
|
18
|
+
<silkscreenline x1={-1} y1={-1.8} x2={1} y2={-1.8} strokeWidth={0.12} layer="bottom" />
|
|
19
|
+
</footprint>}
|
|
20
|
+
{...props}
|
|
21
|
+
/>
|
|
22
|
+
)"
|
|
23
|
+
`)
|
|
24
|
+
|
|
25
|
+
const renderedCircuitJson = (await runTscircuitCode(`
|
|
26
|
+
${tscircuit}
|
|
27
|
+
|
|
28
|
+
circuit.add(
|
|
29
|
+
<board width="20mm" height="20mm">
|
|
30
|
+
<Test12Component />
|
|
31
|
+
</board>,
|
|
32
|
+
)
|
|
33
|
+
`)) as AnyCircuitElement[]
|
|
34
|
+
|
|
35
|
+
const pcbSvg = convertCircuitJsonToPcbSvg(renderedCircuitJson)
|
|
36
|
+
await expect(pcbSvg).toMatchSvgSnapshot(import.meta.path, "pcb")
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const circuitJson: any = [
|
|
40
|
+
{
|
|
41
|
+
type: "source_component",
|
|
42
|
+
source_component_id: "generic_0",
|
|
43
|
+
supplier_part_numbers: {},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "schematic_component",
|
|
47
|
+
schematic_component_id: "schematic_generic_component_0",
|
|
48
|
+
source_component_id: "generic_0",
|
|
49
|
+
center: {
|
|
50
|
+
x: 0,
|
|
51
|
+
y: 0,
|
|
52
|
+
},
|
|
53
|
+
rotation: 0,
|
|
54
|
+
size: {
|
|
55
|
+
width: 0,
|
|
56
|
+
height: 0,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: "pcb_component",
|
|
61
|
+
source_component_id: "generic_0",
|
|
62
|
+
pcb_component_id: "pcb_generic_component_0",
|
|
63
|
+
layer: "top",
|
|
64
|
+
center: {
|
|
65
|
+
x: 0,
|
|
66
|
+
y: 0,
|
|
67
|
+
},
|
|
68
|
+
rotation: 0,
|
|
69
|
+
width: 2,
|
|
70
|
+
height: 1,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: "pcb_silkscreen_line",
|
|
74
|
+
pcb_silkscreen_line_id: "pcb_silkscreen_line_0",
|
|
75
|
+
pcb_component_id: "pcb_generic_component_0",
|
|
76
|
+
layer: "top",
|
|
77
|
+
x1: -1,
|
|
78
|
+
y1: 1.8,
|
|
79
|
+
x2: 1,
|
|
80
|
+
y2: 1.8,
|
|
81
|
+
stroke_width: 0.12,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: "pcb_silkscreen_line",
|
|
85
|
+
pcb_silkscreen_line_id: "pcb_silkscreen_line_1",
|
|
86
|
+
pcb_component_id: "pcb_generic_component_0",
|
|
87
|
+
layer: "bottom",
|
|
88
|
+
x1: -1,
|
|
89
|
+
y1: -1.8,
|
|
90
|
+
x2: 1,
|
|
91
|
+
y2: -1.8,
|
|
92
|
+
stroke_width: 0.12,
|
|
93
|
+
},
|
|
94
|
+
]
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
|
|
3
|
+
import { convertCircuitJsonToTscircuit } from "lib"
|
|
4
|
+
import { runTscircuitCode } from "tscircuit"
|
|
5
|
+
|
|
6
|
+
test("test13 support silkscreen rect", async () => {
|
|
7
|
+
const tscircuit = convertCircuitJsonToTscircuit(circuitJson, {
|
|
8
|
+
componentName: "Test13Component",
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
expect(tscircuit).toMatchInlineSnapshot(`
|
|
12
|
+
"import { type ChipProps } from "tscircuit"
|
|
13
|
+
export const Test13Component = (props: ChipProps) => (
|
|
14
|
+
<chip
|
|
15
|
+
footprint={<footprint>
|
|
16
|
+
<silkscreenrect pcbX={0} pcbY={0.1} width={1.4} height={0.8} layer="top" strokeWidth={0.12} filled={true} cornerRadius={0.08} />
|
|
17
|
+
</footprint>}
|
|
18
|
+
{...props}
|
|
19
|
+
/>
|
|
20
|
+
)"
|
|
21
|
+
`)
|
|
22
|
+
|
|
23
|
+
const renderedCircuitJson = (await runTscircuitCode(`
|
|
24
|
+
${tscircuit}
|
|
25
|
+
|
|
26
|
+
circuit.add(
|
|
27
|
+
<board width="20mm" height="20mm">
|
|
28
|
+
<Test13Component />
|
|
29
|
+
</board>,
|
|
30
|
+
)
|
|
31
|
+
`)) as any[]
|
|
32
|
+
|
|
33
|
+
const pcbSvg = convertCircuitJsonToPcbSvg(renderedCircuitJson)
|
|
34
|
+
await expect(pcbSvg).toMatchSvgSnapshot(import.meta.path, "pcb")
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const circuitJson: any = [
|
|
38
|
+
{
|
|
39
|
+
type: "source_component",
|
|
40
|
+
source_component_id: "generic_0",
|
|
41
|
+
supplier_part_numbers: {},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: "schematic_component",
|
|
45
|
+
schematic_component_id: "schematic_generic_component_0",
|
|
46
|
+
source_component_id: "generic_0",
|
|
47
|
+
center: {
|
|
48
|
+
x: 0,
|
|
49
|
+
y: 0,
|
|
50
|
+
},
|
|
51
|
+
rotation: 0,
|
|
52
|
+
size: {
|
|
53
|
+
width: 0,
|
|
54
|
+
height: 0,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: "pcb_component",
|
|
59
|
+
source_component_id: "generic_0",
|
|
60
|
+
pcb_component_id: "pcb_generic_component_0",
|
|
61
|
+
layer: "top",
|
|
62
|
+
center: {
|
|
63
|
+
x: 0,
|
|
64
|
+
y: 0,
|
|
65
|
+
},
|
|
66
|
+
rotation: 0,
|
|
67
|
+
width: 1.1,
|
|
68
|
+
height: 0.4,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: "pcb_silkscreen_rect",
|
|
72
|
+
pcb_silkscreen_rect_id: "pcb_silkscreen_rect_0",
|
|
73
|
+
pcb_component_id: "pcb_generic_component_0",
|
|
74
|
+
layer: "top",
|
|
75
|
+
center: {
|
|
76
|
+
x: 0,
|
|
77
|
+
y: 0.1,
|
|
78
|
+
},
|
|
79
|
+
width: 1.4,
|
|
80
|
+
height: 0.8,
|
|
81
|
+
stroke_width: 0.12,
|
|
82
|
+
is_filled: true,
|
|
83
|
+
corner_radius: 0.08,
|
|
84
|
+
},
|
|
85
|
+
]
|