@tscircuit/eval 0.0.359 → 0.0.360

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.
@@ -1,4 +1,4 @@
1
- import { CircuitRunner } from "lib/index"
1
+ import { CircuitRunner, getPlatformConfig } from "lib/index"
2
2
  import { test } from "bun:test"
3
3
  import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
4
4
  import { expect } from "bun:test"
@@ -6,7 +6,21 @@ import { expect } from "bun:test"
6
6
  test(
7
7
  "example20-kicad-direct-import",
8
8
  async () => {
9
- const runner = new CircuitRunner()
9
+ const runner = new CircuitRunner({
10
+ platform: {
11
+ ...getPlatformConfig(),
12
+ footprintFileParserMap: {
13
+ kicad_mod: {
14
+ loadFromUrl: async (url: string) => {
15
+ expect(url).toEqual("/poly.kicad_mod")
16
+ return {
17
+ footprintCircuitJson: [],
18
+ }
19
+ },
20
+ },
21
+ },
22
+ },
23
+ })
10
24
 
11
25
  await runner.executeWithFsMap({
12
26
  entrypoint: "index.tsx",
@@ -23,168 +37,11 @@ test(
23
37
  </board>
24
38
  )
25
39
  `,
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
- `,
40
+ "poly.kicad_mod": "__STATIC_ASSET__",
179
41
  },
180
42
  })
181
43
 
182
44
  await runner.renderUntilSettled()
183
-
184
- const circuitJson = await runner.getCircuitJson()
185
- expect(convertCircuitJsonToPcbSvg(circuitJson)).toMatchSvgSnapshot(
186
- import.meta.path,
187
- )
188
45
  await runner.kill()
189
46
  },
190
47
  20 * 1000,
@@ -40,35 +40,11 @@ export const importLocalFile = async (
40
40
  }
41
41
  } else if (isStaticAssetPath(fsPath)) {
42
42
  const platformConfig = ctx.circuit.platform
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
- }
43
+ // Use projectBaseUrl for static file imports
44
+ const staticUrl = `${platformConfig?.projectBaseUrl ?? ""}/${fsPath.startsWith("./") ? fsPath.slice(2) : fsPath}`
45
+ preSuppliedImports[fsPath] = {
46
+ __esModule: true,
47
+ default: staticUrl,
72
48
  }
73
49
  } else if (fsPath.endsWith(".tsx") || fsPath.endsWith(".ts")) {
74
50
  const importNames = getImportsFromCode(fileContent)
@@ -1 +0,0 @@
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>