circuit-json-to-tscircuit 0.0.46 → 0.0.48
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-E24YLRWU.js → chunk-YHGRHULT.js} +8 -3
- package/dist/cli/main.js +2 -2
- package/dist/lib/index.js +1 -1
- package/lib/generate-footprint-tsx/convert-silkscreen.ts +10 -3
- package/package.json +1 -1
- package/tests/cli/cli-circuit-json-to-tsx.test.tsx +2 -2
- package/tests/test1-basic-circuit.test.tsx +4 -4
- package/tests/test2-get-component-template.test.tsx +3 -3
- package/tests/test21-silkscreen-path-props-tsx.test.tsx +57 -0
- package/tests/test22-silkscreen-path-props-roundtrip.test.tsx +74 -0
- package/tests/test3-kicad-mod-circuit-json-example.test.tsx +9 -9
|
@@ -445,9 +445,14 @@ var convertSilkscreen = (circuitJson) => {
|
|
|
445
445
|
const silkscreenCircles = su9(circuitJson).pcb_silkscreen_circle.list();
|
|
446
446
|
const elementStrings = [];
|
|
447
447
|
for (const silkscreenPath of silkscreenPaths) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
448
|
+
const attrs = [`route={${JSON.stringify(silkscreenPath.route)}}`];
|
|
449
|
+
if (silkscreenPath.stroke_width !== void 0) {
|
|
450
|
+
attrs.push(`strokeWidth={${silkscreenPath.stroke_width}}`);
|
|
451
|
+
}
|
|
452
|
+
if (silkscreenPath.layer === "bottom") {
|
|
453
|
+
attrs.push(`layer="bottom"`);
|
|
454
|
+
}
|
|
455
|
+
elementStrings.push(`<silkscreenpath ${attrs.join(" ")} />`);
|
|
451
456
|
}
|
|
452
457
|
for (const silkscreenRect of silkscreenRects) {
|
|
453
458
|
const center = silkscreenRect.center ?? { x: 0, y: 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-YHGRHULT.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.47",
|
|
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
|
@@ -9,9 +9,16 @@ export const convertSilkscreen: FootprintElementConverter = (circuitJson) => {
|
|
|
9
9
|
const elementStrings: string[] = []
|
|
10
10
|
|
|
11
11
|
for (const silkscreenPath of silkscreenPaths) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
12
|
+
const attrs = [`route={${JSON.stringify(silkscreenPath.route)}}`]
|
|
13
|
+
|
|
14
|
+
if (silkscreenPath.stroke_width !== undefined) {
|
|
15
|
+
attrs.push(`strokeWidth={${silkscreenPath.stroke_width}}`)
|
|
16
|
+
}
|
|
17
|
+
if (silkscreenPath.layer === "bottom") {
|
|
18
|
+
attrs.push(`layer="bottom"`)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
elementStrings.push(`<silkscreenpath ${attrs.join(" ")} />`)
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
for (const silkscreenRect of silkscreenRects) {
|
package/package.json
CHANGED
|
@@ -24,8 +24,8 @@ test("should convert sample circuit.json to TSX", async () => {
|
|
|
24
24
|
footprint={<footprint>
|
|
25
25
|
<smtpad portHints={["pin2"]} pcbX="0.753364mm" pcbY="0mm" layer="top" coveredWithSolderMask={false} width="0.8064754mm" height="0.8640064mm" shape="rect" />
|
|
26
26
|
<smtpad portHints={["pin1"]} pcbX="-0.753364mm" pcbY="0mm" layer="top" coveredWithSolderMask={false} width="0.8064754mm" height="0.8640064mm" shape="rect" />
|
|
27
|
-
<silkscreenpath route={[{"x":0.42621199999996406,"y":-0.6606031999999686},{"x":1.3850873999999749,"y":-0.6606031999999686},{"x":1.3850873999999749,"y":0.6606031999999686},{"x":0.42621199999996406,"y":0.6606031999999686}]} />
|
|
28
|
-
<silkscreenpath route={[{"x":-0.42621200000007775,"y":-0.6606031999999686},{"x":-1.3850874000000886,"y":-0.6606031999999686},{"x":-1.3850874000000886,"y":0.6606031999999686},{"x":-0.42621200000007775,"y":0.6606031999999686}]} />
|
|
27
|
+
<silkscreenpath route={[{"x":0.42621199999996406,"y":-0.6606031999999686},{"x":1.3850873999999749,"y":-0.6606031999999686},{"x":1.3850873999999749,"y":0.6606031999999686},{"x":0.42621199999996406,"y":0.6606031999999686}]} strokeWidth={0.1} />
|
|
28
|
+
<silkscreenpath route={[{"x":-0.42621200000007775,"y":-0.6606031999999686},{"x":-1.3850874000000886,"y":-0.6606031999999686},{"x":-1.3850874000000886,"y":0.6606031999999686},{"x":-0.42621200000007775,"y":0.6606031999999686}]} strokeWidth={0.1} />
|
|
29
29
|
<silkscreentext pcbX={-0.0127} pcbY={1.6604} anchorAlignment="center" fontSize={1} font="tscircuit2024" pcbRotation="0deg" layer="top" text="unnamed_chip1" />
|
|
30
30
|
<courtyardoutline outline={[{"x":-1.647000000000162,"y":0.9103999999999814},{"x":1.6216000000000577,"y":0.9103999999999814},{"x":1.6216000000000577,"y":-0.9103999999998678},{"x":-1.647000000000162,"y":-0.9103999999998678},{"x":-1.647000000000162,"y":0.9103999999999814}]} layer="top" />
|
|
31
31
|
</footprint>}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { convertCircuitJsonToTscircuit } from "lib/index"
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
3
2
|
import { readFile } from "node:fs/promises"
|
|
4
3
|
import { join } from "node:path"
|
|
4
|
+
import { convertCircuitJsonToTscircuit } from "lib/index"
|
|
5
5
|
|
|
6
6
|
declare module "bun:test" {
|
|
7
7
|
interface Matchers<T = unknown> {
|
|
@@ -30,8 +30,8 @@ test("test1 basic circuit", async () => {
|
|
|
30
30
|
footprint={<footprint>
|
|
31
31
|
<smtpad portHints={["pin2"]} pcbX="0.753364mm" pcbY="0mm" layer="top" coveredWithSolderMask={false} width="0.8064754mm" height="0.8640064mm" shape="rect" />
|
|
32
32
|
<smtpad portHints={["pin1"]} pcbX="-0.753364mm" pcbY="0mm" layer="top" coveredWithSolderMask={false} width="0.8064754mm" height="0.8640064mm" shape="rect" />
|
|
33
|
-
<silkscreenpath route={[{"x":0.42621199999996406,"y":-0.6606031999999686},{"x":1.3850873999999749,"y":-0.6606031999999686},{"x":1.3850873999999749,"y":0.6606031999999686},{"x":0.42621199999996406,"y":0.6606031999999686}]} />
|
|
34
|
-
<silkscreenpath route={[{"x":-0.42621200000007775,"y":-0.6606031999999686},{"x":-1.3850874000000886,"y":-0.6606031999999686},{"x":-1.3850874000000886,"y":0.6606031999999686},{"x":-0.42621200000007775,"y":0.6606031999999686}]} />
|
|
33
|
+
<silkscreenpath route={[{"x":0.42621199999996406,"y":-0.6606031999999686},{"x":1.3850873999999749,"y":-0.6606031999999686},{"x":1.3850873999999749,"y":0.6606031999999686},{"x":0.42621199999996406,"y":0.6606031999999686}]} strokeWidth={0.1} />
|
|
34
|
+
<silkscreenpath route={[{"x":-0.42621200000007775,"y":-0.6606031999999686},{"x":-1.3850874000000886,"y":-0.6606031999999686},{"x":-1.3850874000000886,"y":0.6606031999999686},{"x":-0.42621200000007775,"y":0.6606031999999686}]} strokeWidth={0.1} />
|
|
35
35
|
<silkscreentext pcbX={-0.0127} pcbY={1.6604} anchorAlignment="center" fontSize={1} font="tscircuit2024" pcbRotation="0deg" layer="top" text="unnamed_chip1" />
|
|
36
36
|
<courtyardoutline outline={[{"x":-1.647000000000162,"y":0.9103999999999814},{"x":1.6216000000000577,"y":0.9103999999999814},{"x":1.6216000000000577,"y":-0.9103999999998678},{"x":-1.647000000000162,"y":-0.9103999999998678},{"x":-1.647000000000162,"y":0.9103999999999814}]} layer="top" />
|
|
37
37
|
</footprint>}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
2
|
import { readFile } from "node:fs/promises"
|
|
3
3
|
import { join } from "node:path"
|
|
4
4
|
import { getComponentUsingTemplate } from "lib/get-component-using-template"
|
|
@@ -38,8 +38,8 @@ test("test2 getComponentUsingTemplate", async () => {
|
|
|
38
38
|
footprint={<footprint>
|
|
39
39
|
<smtpad portHints={["pin2"]} pcbX="0.753364mm" pcbY="0mm" layer="top" coveredWithSolderMask={false} width="0.8064754mm" height="0.8640064mm" shape="rect" />
|
|
40
40
|
<smtpad portHints={["pin1"]} pcbX="-0.753364mm" pcbY="0mm" layer="top" coveredWithSolderMask={false} width="0.8064754mm" height="0.8640064mm" shape="rect" />
|
|
41
|
-
<silkscreenpath route={[{"x":0.42621199999996406,"y":-0.6606031999999686},{"x":1.3850873999999749,"y":-0.6606031999999686},{"x":1.3850873999999749,"y":0.6606031999999686},{"x":0.42621199999996406,"y":0.6606031999999686}]} />
|
|
42
|
-
<silkscreenpath route={[{"x":-0.42621200000007775,"y":-0.6606031999999686},{"x":-1.3850874000000886,"y":-0.6606031999999686},{"x":-1.3850874000000886,"y":0.6606031999999686},{"x":-0.42621200000007775,"y":0.6606031999999686}]} />
|
|
41
|
+
<silkscreenpath route={[{"x":0.42621199999996406,"y":-0.6606031999999686},{"x":1.3850873999999749,"y":-0.6606031999999686},{"x":1.3850873999999749,"y":0.6606031999999686},{"x":0.42621199999996406,"y":0.6606031999999686}]} strokeWidth={0.1} />
|
|
42
|
+
<silkscreenpath route={[{"x":-0.42621200000007775,"y":-0.6606031999999686},{"x":-1.3850874000000886,"y":-0.6606031999999686},{"x":-1.3850874000000886,"y":0.6606031999999686},{"x":-0.42621200000007775,"y":0.6606031999999686}]} strokeWidth={0.1} />
|
|
43
43
|
<silkscreentext pcbX={-0.0127} pcbY={1.6604} anchorAlignment="center" fontSize={1} font="tscircuit2024" pcbRotation="0deg" layer="top" text="unnamed_chip1" />
|
|
44
44
|
<courtyardoutline outline={[{"x":-1.647000000000162,"y":0.9103999999999814},{"x":1.6216000000000577,"y":0.9103999999999814},{"x":1.6216000000000577,"y":-0.9103999999998678},{"x":-1.647000000000162,"y":-0.9103999999998678},{"x":-1.647000000000162,"y":0.9103999999999814}]} layer="top" />
|
|
45
45
|
</footprint>}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { convertCircuitJsonToTscircuit } from "lib"
|
|
3
|
+
|
|
4
|
+
test("test21 silkscreen path props tsx", async () => {
|
|
5
|
+
const tscircuit = convertCircuitJsonToTscircuit(circuitJson, {
|
|
6
|
+
componentName: "Test21Component",
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
expect(tscircuit).toContain('layer="bottom"')
|
|
10
|
+
expect(tscircuit).toContain("strokeWidth={0.2}")
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const circuitJson: any = [
|
|
14
|
+
{
|
|
15
|
+
type: "source_component",
|
|
16
|
+
source_component_id: "generic_0",
|
|
17
|
+
supplier_part_numbers: {},
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
type: "schematic_component",
|
|
21
|
+
schematic_component_id: "schematic_generic_component_0",
|
|
22
|
+
source_component_id: "generic_0",
|
|
23
|
+
center: {
|
|
24
|
+
x: 0,
|
|
25
|
+
y: 0,
|
|
26
|
+
},
|
|
27
|
+
rotation: 0,
|
|
28
|
+
size: {
|
|
29
|
+
width: 0,
|
|
30
|
+
height: 0,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: "pcb_component",
|
|
35
|
+
source_component_id: "generic_0",
|
|
36
|
+
pcb_component_id: "pcb_generic_component_0",
|
|
37
|
+
layer: "top",
|
|
38
|
+
center: {
|
|
39
|
+
x: 0,
|
|
40
|
+
y: 0,
|
|
41
|
+
},
|
|
42
|
+
rotation: 0,
|
|
43
|
+
width: 2,
|
|
44
|
+
height: 1,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: "pcb_silkscreen_path",
|
|
48
|
+
pcb_silkscreen_path_id: "pcb_silkscreen_path_0",
|
|
49
|
+
pcb_component_id: "pcb_generic_component_0",
|
|
50
|
+
layer: "bottom",
|
|
51
|
+
route: [
|
|
52
|
+
{ x: -1, y: 1.8 },
|
|
53
|
+
{ x: 1, y: 1.8 },
|
|
54
|
+
],
|
|
55
|
+
stroke_width: 0.2,
|
|
56
|
+
},
|
|
57
|
+
]
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
3
|
+
import { convertCircuitJsonToTscircuit } from "lib"
|
|
4
|
+
import { runTscircuitCode } from "tscircuit"
|
|
5
|
+
|
|
6
|
+
test("test22 silkscreen path props roundtrip", async () => {
|
|
7
|
+
const tscircuit = convertCircuitJsonToTscircuit(circuitJson, {
|
|
8
|
+
componentName: "Test22Component",
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const renderedCircuitJson = (await runTscircuitCode(`
|
|
12
|
+
${tscircuit}
|
|
13
|
+
|
|
14
|
+
circuit.add(
|
|
15
|
+
<board width="20mm" height="20mm">
|
|
16
|
+
<Test22Component />
|
|
17
|
+
</board>,
|
|
18
|
+
)
|
|
19
|
+
`)) as AnyCircuitElement[]
|
|
20
|
+
|
|
21
|
+
const silkscreenPath = renderedCircuitJson.find(
|
|
22
|
+
(el) => el.type === "pcb_silkscreen_path",
|
|
23
|
+
) as any
|
|
24
|
+
|
|
25
|
+
expect(silkscreenPath).toBeDefined()
|
|
26
|
+
expect(silkscreenPath.layer).toBe("bottom")
|
|
27
|
+
expect(silkscreenPath.stroke_width).toBe(0.2)
|
|
28
|
+
}, 15000)
|
|
29
|
+
|
|
30
|
+
const circuitJson: any = [
|
|
31
|
+
{
|
|
32
|
+
type: "source_component",
|
|
33
|
+
source_component_id: "generic_0",
|
|
34
|
+
supplier_part_numbers: {},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: "schematic_component",
|
|
38
|
+
schematic_component_id: "schematic_generic_component_0",
|
|
39
|
+
source_component_id: "generic_0",
|
|
40
|
+
center: {
|
|
41
|
+
x: 0,
|
|
42
|
+
y: 0,
|
|
43
|
+
},
|
|
44
|
+
rotation: 0,
|
|
45
|
+
size: {
|
|
46
|
+
width: 0,
|
|
47
|
+
height: 0,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: "pcb_component",
|
|
52
|
+
source_component_id: "generic_0",
|
|
53
|
+
pcb_component_id: "pcb_generic_component_0",
|
|
54
|
+
layer: "top",
|
|
55
|
+
center: {
|
|
56
|
+
x: 0,
|
|
57
|
+
y: 0,
|
|
58
|
+
},
|
|
59
|
+
rotation: 0,
|
|
60
|
+
width: 2,
|
|
61
|
+
height: 1,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: "pcb_silkscreen_path",
|
|
65
|
+
pcb_silkscreen_path_id: "pcb_silkscreen_path_0",
|
|
66
|
+
pcb_component_id: "pcb_generic_component_0",
|
|
67
|
+
layer: "bottom",
|
|
68
|
+
route: [
|
|
69
|
+
{ x: -1, y: 1.8 },
|
|
70
|
+
{ x: 1, y: 1.8 },
|
|
71
|
+
],
|
|
72
|
+
stroke_width: 0.2,
|
|
73
|
+
},
|
|
74
|
+
]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
2
|
import { convertCircuitJsonToTscircuit } from "lib"
|
|
3
3
|
|
|
4
4
|
test("test3 kicad mod circuit json example", async () => {
|
|
@@ -66,14 +66,14 @@ test("test3 kicad mod circuit json example", async () => {
|
|
|
66
66
|
<smtpad portHints={["13"]} pcbX="8.337mm" pcbY="5.08mm" layer="top" width="1.626mm" height="1.208mm" shape="rect" />
|
|
67
67
|
<smtpad portHints={["14"]} pcbX="8.278mm" pcbY="7.62mm" layer="top" width="1.626mm" height="1.325mm" shape="rect" />
|
|
68
68
|
<smtpad portHints={["14"]} pcbX="8.278mm" pcbY="7.62mm" layer="top" width="1.626mm" height="1.325mm" shape="rect" />
|
|
69
|
-
<silkscreenpath route={[{"x":-8.89,"y":-8.509},{"x":-8.89,"y":8.636}]} />
|
|
70
|
-
<silkscreenpath route={[{"x":-6.985,"y":-10.414},{"x":6.985,"y":-10.414}]} />
|
|
71
|
-
<silkscreenpath route={[{"x":6.985,"y":10.541},{"x":-6.985,"y":10.541}]} />
|
|
72
|
-
<silkscreenpath route={[{"x":8.89,"y":-8.509},{"x":8.89,"y":8.636}]} />
|
|
73
|
-
<silkscreenpath route={[{"x":-8.89,"y":8.636},{"x":-8.634777964987212,"y":9.588499698293818},{"x":-7.937499698293819,"y":10.285777964987211},{"x":-6.985,"y":10.541}]} />
|
|
74
|
-
<silkscreenpath route={[{"x":-6.985,"y":-10.414},{"x":-7.937499698293818,"y":-10.158777964987209},{"x":-8.63477796498721,"y":-9.461499698293817},{"x":-8.89,"y":-8.509}]} />
|
|
75
|
-
<silkscreenpath route={[{"x":6.985,"y":10.541},{"x":7.937499698293818,"y":10.285777964987211},{"x":8.63477796498721,"y":9.588499698293818},{"x":8.889999999999999,"y":8.636}]} />
|
|
76
|
-
<silkscreenpath route={[{"x":8.89,"y":-8.509},{"x":8.63477796498721,"y":-9.461499698293817},{"x":7.937499698293818,"y":-10.158777964987209},{"x":6.985,"y":-10.413999999999998}]} />
|
|
69
|
+
<silkscreenpath route={[{"x":-8.89,"y":-8.509},{"x":-8.89,"y":8.636}]} strokeWidth={0.1} />
|
|
70
|
+
<silkscreenpath route={[{"x":-6.985,"y":-10.414},{"x":6.985,"y":-10.414}]} strokeWidth={0.1} />
|
|
71
|
+
<silkscreenpath route={[{"x":6.985,"y":10.541},{"x":-6.985,"y":10.541}]} strokeWidth={0.1} />
|
|
72
|
+
<silkscreenpath route={[{"x":8.89,"y":-8.509},{"x":8.89,"y":8.636}]} strokeWidth={0.1} />
|
|
73
|
+
<silkscreenpath route={[{"x":-8.89,"y":8.636},{"x":-8.634777964987212,"y":9.588499698293818},{"x":-7.937499698293819,"y":10.285777964987211},{"x":-6.985,"y":10.541}]} strokeWidth={0.1} />
|
|
74
|
+
<silkscreenpath route={[{"x":-6.985,"y":-10.414},{"x":-7.937499698293818,"y":-10.158777964987209},{"x":-8.63477796498721,"y":-9.461499698293817},{"x":-8.89,"y":-8.509}]} strokeWidth={0.1} />
|
|
75
|
+
<silkscreenpath route={[{"x":6.985,"y":10.541},{"x":7.937499698293818,"y":10.285777964987211},{"x":8.63477796498721,"y":9.588499698293818},{"x":8.889999999999999,"y":8.636}]} strokeWidth={0.1} />
|
|
76
|
+
<silkscreenpath route={[{"x":8.89,"y":-8.509},{"x":8.63477796498721,"y":-9.461499698293817},{"x":7.937499698293818,"y":-10.158777964987209},{"x":6.985,"y":-10.413999999999998}]} strokeWidth={0.1} />
|
|
77
77
|
<fabricationnotetext pcbX={-8} pcbY={11.5} anchorAlignment="center" text="REF**" font="tscircuit2024" fontSize={1.27} />
|
|
78
78
|
<fabricationnotetext pcbX={0} pcbY={0} anchorAlignment="center" text="XIAO-Add-On" font="tscircuit2024" fontSize={1.27} />
|
|
79
79
|
</footprint>}
|