@tscircuit/eval 0.0.338 → 0.0.340
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/.github/workflows/bun-pver-release.yml +2 -0
- package/dist/blob-url.js +1 -1
- package/dist/eval/index.js +39 -6
- package/dist/lib/index.js +39 -6
- package/dist/webworker/entrypoint.js +132 -128
- package/lib/getPlatformConfig.ts +15 -1
- package/package.json +4 -3
- package/tests/examples/__snapshots__/example20-kicad-import.snap.svg +1 -0
- package/tests/examples/example20-kicad-import.test.tsx +191 -0
- package/webworker/import-local-file.ts +29 -5
package/lib/getPlatformConfig.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PlatformConfig } from "@tscircuit/props"
|
|
2
2
|
import { jlcPartsEngine } from "@tscircuit/parts-engine"
|
|
3
|
-
|
|
3
|
+
import { parseKicadModToCircuitJson } from "kicad-component-converter"
|
|
4
4
|
const KICAD_FOOTPRINT_CACHE_URL = "https://kicad-mod-cache.tscircuit.com"
|
|
5
5
|
|
|
6
6
|
export const getPlatformConfig = (): PlatformConfig => ({
|
|
@@ -25,4 +25,18 @@ export const getPlatformConfig = (): PlatformConfig => ({
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
},
|
|
28
|
+
footprintFileParserMap: {
|
|
29
|
+
kicad_mod: {
|
|
30
|
+
loadFromUrl: async (url: string) => {
|
|
31
|
+
const kicadJson = await parseKicadModToCircuitJson(
|
|
32
|
+
atob(url.replace("data:text/plain;base64,", "")),
|
|
33
|
+
)
|
|
34
|
+
return {
|
|
35
|
+
footprintCircuitJson: Array.isArray(kicadJson)
|
|
36
|
+
? kicadJson
|
|
37
|
+
: [kicadJson],
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
28
42
|
})
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/eval",
|
|
3
3
|
"main": "dist/lib/index.js",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.340",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "bun run build:lib && bun run build:webworker && bun run build:blob-url && bun run build:runner && bun run build:worker-wrapper",
|
|
@@ -66,12 +66,11 @@
|
|
|
66
66
|
"@tscircuit/math-utils": "^0.0.21",
|
|
67
67
|
"@tscircuit/miniflex": "^0.0.4",
|
|
68
68
|
"@tscircuit/parts-engine": "^0.0.11",
|
|
69
|
-
"@tscircuit/props": "0.0.
|
|
69
|
+
"@tscircuit/props": "^0.0.337",
|
|
70
70
|
"@tscircuit/schematic-autolayout": "^0.0.6",
|
|
71
71
|
"@tscircuit/schematic-match-adapt": "^0.0.16",
|
|
72
72
|
"@tscircuit/schematic-trace-solver": "^0.0.38",
|
|
73
73
|
"@tscircuit/simple-3d-svg": "^0.0.41",
|
|
74
|
-
"sucrase": "^3.35.0",
|
|
75
74
|
"@types/bun": "^1.2.16",
|
|
76
75
|
"@types/debug": "^4.1.12",
|
|
77
76
|
"@types/react": "^19.1.8",
|
|
@@ -93,6 +92,7 @@
|
|
|
93
92
|
"flatbush": "^4.5.0",
|
|
94
93
|
"graphics-debug": "^0.0.60",
|
|
95
94
|
"howfat": "^0.3.8",
|
|
95
|
+
"kicad-component-converter": "^0.1.19",
|
|
96
96
|
"live-server": "^1.2.2",
|
|
97
97
|
"looks-same": "^9.0.1",
|
|
98
98
|
"minicssgrid": "^0.0.9",
|
|
@@ -100,6 +100,7 @@
|
|
|
100
100
|
"react": "^19.1.0",
|
|
101
101
|
"react-dom": "^19.1.0",
|
|
102
102
|
"schematic-symbols": "^0.0.202",
|
|
103
|
+
"sucrase": "^3.35.0",
|
|
103
104
|
"ts-expect": "^1.3.0",
|
|
104
105
|
"tsup": "^8.2.4"
|
|
105
106
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="800" height="600" data-software-used-string="@tscircuit/core@0.0.747"><style></style><rect class="boundary" x="0" y="0" fill="#000" width="800" height="600"/><rect class="pcb-boundary" fill="none" stroke="#fff" stroke-width="0.3" x="150" y="50" width="500" height="500"/><path class="pcb-board" d="M 150 550 L 650 550 L 650 50 L 150 50 Z" fill="none" stroke="rgba(255, 255, 255, 0.5)" stroke-width="5"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="361" y="284" width="27" height="32" data-layer="top"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="412" y="284" width="27" height="32" data-layer="top"/><path class="pcb-silkscreen pcb-silkscreen-top" d="M 392.31795 281 L 407.68205 281" fill="none" stroke="#f2eda1" stroke-width="6" stroke-linecap="round" stroke-linejoin="round" data-pcb-component-id="pcb_component_0" data-pcb-silkscreen-path-id="pcb_silkscreen_path_0"/><path class="pcb-silkscreen pcb-silkscreen-top" d="M 392.31795 319 L 407.68205 319" fill="none" stroke="#f2eda1" stroke-width="6" stroke-linecap="round" stroke-linejoin="round" data-pcb-component-id="pcb_component_0" data-pcb-silkscreen-path-id="pcb_silkscreen_path_1"/><text x="0" y="0" dx="0" dy="0" fill="#f2eda1" font-family="Arial, sans-serif" font-size="73.5" text-anchor="middle" dominant-baseline="central" transform="matrix(1,0,0,1,400,241.5)" class="pcb-silkscreen-text pcb-silkscreen-top" data-pcb-silkscreen-text-id="pcb_component_0" stroke="none">U1</text><text x="0" y="0" dx="0" dy="0" fill="#f2eda1" font-family="Arial, sans-serif" font-size="73.5" text-anchor="middle" dominant-baseline="central" transform="matrix(1,0,0,1,400,358.5)" class="pcb-silkscreen-text pcb-silkscreen-top" data-pcb-silkscreen-text-id="pcb_component_0" stroke="none">U1</text></svg>
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { CircuitRunner } from "lib/index"
|
|
2
|
+
import { test } from "bun:test"
|
|
3
|
+
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
|
|
4
|
+
import { expect } from "bun:test"
|
|
5
|
+
|
|
6
|
+
test(
|
|
7
|
+
"example20-kicad-direct-import",
|
|
8
|
+
async () => {
|
|
9
|
+
const runner = new CircuitRunner()
|
|
10
|
+
|
|
11
|
+
await runner.executeWithFsMap({
|
|
12
|
+
entrypoint: "index.tsx",
|
|
13
|
+
fsMap: {
|
|
14
|
+
"index.tsx": `
|
|
15
|
+
import kicadMod from "./poly.kicad_mod"
|
|
16
|
+
|
|
17
|
+
circuit.add(
|
|
18
|
+
<board width="10mm" height="10mm">
|
|
19
|
+
<chip
|
|
20
|
+
name="U1"
|
|
21
|
+
footprint={kicadMod}
|
|
22
|
+
/>
|
|
23
|
+
</board>
|
|
24
|
+
)
|
|
25
|
+
`,
|
|
26
|
+
"poly.kicad_mod": `(footprint "R_0402_1005Metric"
|
|
27
|
+
(version 20241229)
|
|
28
|
+
(generator "kicad-footprint-generator")
|
|
29
|
+
(layer "F.Cu")
|
|
30
|
+
(descr "Resistor SMD 0402 (1005 Metric), square (rectangular) end terminal, IPC-7351 nominal, (Body size source: IPC-SM-782 page 72, https://www.pcb-3d.com/wordpress/wp-content/uploads/ipc-sm-782a_amendment_1_and_2.pdf), generated with kicad-footprint-generator")
|
|
31
|
+
(tags "resistor")
|
|
32
|
+
(property "Reference" "REF**"
|
|
33
|
+
(at 0 -1.17 0)
|
|
34
|
+
(layer "F.SilkS")
|
|
35
|
+
(effects
|
|
36
|
+
(font
|
|
37
|
+
(size 1 1)
|
|
38
|
+
(thickness 0.15)
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
(property "Value" "R_0402_1005Metric"
|
|
43
|
+
(at 0 1.17 0)
|
|
44
|
+
(layer "F.Fab")
|
|
45
|
+
(effects
|
|
46
|
+
(font
|
|
47
|
+
(size 1 1)
|
|
48
|
+
(thickness 0.15)
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
(attr smd)
|
|
53
|
+
(fp_line
|
|
54
|
+
(start -0.153641 -0.38)
|
|
55
|
+
(end 0.153641 -0.38)
|
|
56
|
+
(stroke
|
|
57
|
+
(width 0.12)
|
|
58
|
+
(type solid)
|
|
59
|
+
)
|
|
60
|
+
(layer "F.SilkS")
|
|
61
|
+
)
|
|
62
|
+
(fp_line
|
|
63
|
+
(start -0.153641 0.38)
|
|
64
|
+
(end 0.153641 0.38)
|
|
65
|
+
(stroke
|
|
66
|
+
(width 0.12)
|
|
67
|
+
(type solid)
|
|
68
|
+
)
|
|
69
|
+
(layer "F.SilkS")
|
|
70
|
+
)
|
|
71
|
+
(fp_line
|
|
72
|
+
(start -0.93 -0.47)
|
|
73
|
+
(end 0.93 -0.47)
|
|
74
|
+
(stroke
|
|
75
|
+
(width 0.05)
|
|
76
|
+
(type solid)
|
|
77
|
+
)
|
|
78
|
+
(layer "F.CrtYd")
|
|
79
|
+
)
|
|
80
|
+
(fp_line
|
|
81
|
+
(start -0.93 0.47)
|
|
82
|
+
(end -0.93 -0.47)
|
|
83
|
+
(stroke
|
|
84
|
+
(width 0.05)
|
|
85
|
+
(type solid)
|
|
86
|
+
)
|
|
87
|
+
(layer "F.CrtYd")
|
|
88
|
+
)
|
|
89
|
+
(fp_line
|
|
90
|
+
(start 0.93 -0.47)
|
|
91
|
+
(end 0.93 0.47)
|
|
92
|
+
(stroke
|
|
93
|
+
(width 0.05)
|
|
94
|
+
(type solid)
|
|
95
|
+
)
|
|
96
|
+
(layer "F.CrtYd")
|
|
97
|
+
)
|
|
98
|
+
(fp_line
|
|
99
|
+
(start 0.93 0.47)
|
|
100
|
+
(end -0.93 0.47)
|
|
101
|
+
(stroke
|
|
102
|
+
(width 0.05)
|
|
103
|
+
(type solid)
|
|
104
|
+
)
|
|
105
|
+
(layer "F.CrtYd")
|
|
106
|
+
)
|
|
107
|
+
(fp_line
|
|
108
|
+
(start -0.525 -0.27)
|
|
109
|
+
(end 0.525 -0.27)
|
|
110
|
+
(stroke
|
|
111
|
+
(width 0.1)
|
|
112
|
+
(type solid)
|
|
113
|
+
)
|
|
114
|
+
(layer "F.Fab")
|
|
115
|
+
)
|
|
116
|
+
(fp_line
|
|
117
|
+
(start -0.525 0.27)
|
|
118
|
+
(end -0.525 -0.27)
|
|
119
|
+
(stroke
|
|
120
|
+
(width 0.1)
|
|
121
|
+
(type solid)
|
|
122
|
+
)
|
|
123
|
+
(layer "F.Fab")
|
|
124
|
+
)
|
|
125
|
+
(fp_line
|
|
126
|
+
(start 0.525 -0.27)
|
|
127
|
+
(end 0.525 0.27)
|
|
128
|
+
(stroke
|
|
129
|
+
(width 0.1)
|
|
130
|
+
(type solid)
|
|
131
|
+
)
|
|
132
|
+
(layer "F.Fab")
|
|
133
|
+
)
|
|
134
|
+
(fp_line
|
|
135
|
+
(start 0.525 0.27)
|
|
136
|
+
(end -0.525 0.27)
|
|
137
|
+
(stroke
|
|
138
|
+
(width 0.1)
|
|
139
|
+
(type solid)
|
|
140
|
+
)
|
|
141
|
+
(layer "F.Fab")
|
|
142
|
+
)
|
|
143
|
+
(fp_text user "\${REFERENCE}"
|
|
144
|
+
(at 0 0 0)
|
|
145
|
+
(layer "F.Fab")
|
|
146
|
+
(effects
|
|
147
|
+
(font
|
|
148
|
+
(size 0.26 0.26)
|
|
149
|
+
(thickness 0.04)
|
|
150
|
+
)
|
|
151
|
+
)
|
|
152
|
+
)
|
|
153
|
+
(pad "1" smd roundrect
|
|
154
|
+
(at -0.51 0)
|
|
155
|
+
(size 0.54 0.64)
|
|
156
|
+
(layers "F.Cu" "F.Mask" "F.Paste")
|
|
157
|
+
(roundrect_rratio 0.25)
|
|
158
|
+
)
|
|
159
|
+
(pad "2" smd roundrect
|
|
160
|
+
(at 0.51 0)
|
|
161
|
+
(size 0.54 0.64)
|
|
162
|
+
(layers "F.Cu" "F.Mask" "F.Paste")
|
|
163
|
+
(roundrect_rratio 0.25)
|
|
164
|
+
)
|
|
165
|
+
(embedded_fonts no)
|
|
166
|
+
(model "\${KICAD9_3DMODEL_DIR}/Resistor_SMD.3dshapes/R_0402_1005Metric.step"
|
|
167
|
+
(offset
|
|
168
|
+
(xyz 0 0 0)
|
|
169
|
+
)
|
|
170
|
+
(scale
|
|
171
|
+
(xyz 1 1 1)
|
|
172
|
+
)
|
|
173
|
+
(rotate
|
|
174
|
+
(xyz 0 0 0)
|
|
175
|
+
)
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
`,
|
|
179
|
+
},
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
await runner.renderUntilSettled()
|
|
183
|
+
|
|
184
|
+
const circuitJson = await runner.getCircuitJson()
|
|
185
|
+
expect(convertCircuitJsonToPcbSvg(circuitJson)).toMatchSvgSnapshot(
|
|
186
|
+
import.meta.path,
|
|
187
|
+
)
|
|
188
|
+
await runner.kill()
|
|
189
|
+
},
|
|
190
|
+
20 * 1000,
|
|
191
|
+
)
|
|
@@ -40,11 +40,35 @@ export const importLocalFile = async (
|
|
|
40
40
|
}
|
|
41
41
|
} else if (isStaticAssetPath(fsPath)) {
|
|
42
42
|
const platformConfig = ctx.circuit.platform
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
const fileExtension = fsPath.split(".").pop()
|
|
44
|
+
const footprintParser =
|
|
45
|
+
platformConfig?.footprintFileParserMap?.[fileExtension!]
|
|
46
|
+
if (
|
|
47
|
+
fileExtension == "kicad_mod" &&
|
|
48
|
+
footprintParser &&
|
|
49
|
+
footprintParser.loadFromUrl
|
|
50
|
+
) {
|
|
51
|
+
try {
|
|
52
|
+
const contentUrl = `data:text/plain;base64,${btoa(fileContent)}`
|
|
53
|
+
const result = await footprintParser.loadFromUrl(contentUrl)
|
|
54
|
+
preSuppliedImports[fsPath] = {
|
|
55
|
+
__esModule: true,
|
|
56
|
+
default: result.footprintCircuitJson,
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.log("here", error)
|
|
60
|
+
const staticUrl = `${platformConfig?.projectBaseUrl ?? ""}/${fsPath.startsWith("./") ? fsPath.slice(2) : fsPath}`
|
|
61
|
+
preSuppliedImports[fsPath] = {
|
|
62
|
+
__esModule: true,
|
|
63
|
+
default: staticUrl,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
const staticUrl = `${platformConfig?.projectBaseUrl ?? ""}/${fsPath.startsWith("./") ? fsPath.slice(2) : fsPath}`
|
|
68
|
+
preSuppliedImports[fsPath] = {
|
|
69
|
+
__esModule: true,
|
|
70
|
+
default: staticUrl,
|
|
71
|
+
}
|
|
48
72
|
}
|
|
49
73
|
} else if (fsPath.endsWith(".tsx") || fsPath.endsWith(".ts")) {
|
|
50
74
|
const importNames = getImportsFromCode(fileContent)
|