circuit-json-to-tscircuit 0.0.8 → 0.0.9

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.
@@ -6,6 +6,8 @@ var generateFootprintTsx = (circuitJson) => {
6
6
  const platedHoles = su(circuitJson).pcb_plated_hole.list();
7
7
  const smtPads = su(circuitJson).pcb_smtpad.list();
8
8
  const silkscreenPaths = su(circuitJson).pcb_silkscreen_path.list();
9
+ const fabricationNotePaths = su(circuitJson).pcb_fabrication_note_path.list();
10
+ const silkscreenTexts = su(circuitJson).pcb_silkscreen_text.list();
9
11
  const elementStrings = [];
10
12
  for (const hole of holes) {
11
13
  if (hole.hole_shape === "circle") {
@@ -43,6 +45,22 @@ var generateFootprintTsx = (circuitJson) => {
43
45
  `<silkscreenpath route={${JSON.stringify(silkscreenPath.route)}} />`
44
46
  );
45
47
  }
48
+ for (const fabPath of fabricationNotePaths) {
49
+ elementStrings.push(
50
+ `<silkscreenpath route={${JSON.stringify(fabPath.route)}} />`
51
+ );
52
+ }
53
+ for (const stext of silkscreenTexts) {
54
+ const pcbX = stext.anchor_position?.x ?? 0;
55
+ const pcbY = stext.anchor_position?.y ?? 0;
56
+ const anchorAlignment = stext.anchor_alignment;
57
+ const fontSize = stext.font_size;
58
+ const rawText = String(stext.text ?? "");
59
+ const escapedText = rawText.replace(/"/g, '\\"');
60
+ elementStrings.push(
61
+ `<silkscreentext pcbX={${pcbX}} pcbY={${pcbY}} anchorAlignment="${anchorAlignment}" fontSize={${fontSize}} text="${escapedText}" />`
62
+ );
63
+ }
46
64
  return `
47
65
  <footprint>
48
66
  ${elementStrings.join("\n")}
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-X7PFGT53.js";
4
+ } from "../chunk-EX2F3BMQ.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.7",
19
+ version: "0.0.8",
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
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  convertCircuitJsonToTscircuit
3
- } from "../chunk-X7PFGT53.js";
3
+ } from "../chunk-EX2F3BMQ.js";
4
4
  export {
5
5
  convertCircuitJsonToTscircuit
6
6
  };
@@ -9,6 +9,8 @@ export const generateFootprintTsx = (
9
9
  const platedHoles = su(circuitJson).pcb_plated_hole.list()
10
10
  const smtPads = su(circuitJson).pcb_smtpad.list()
11
11
  const silkscreenPaths = su(circuitJson).pcb_silkscreen_path.list()
12
+ const fabricationNotePaths = su(circuitJson).pcb_fabrication_note_path.list()
13
+ const silkscreenTexts = su(circuitJson).pcb_silkscreen_text.list()
12
14
 
13
15
  const elementStrings: string[] = []
14
16
 
@@ -52,6 +54,28 @@ export const generateFootprintTsx = (
52
54
  )
53
55
  }
54
56
 
57
+ // Map fabrication note paths to silkscreen paths in footprints
58
+ for (const fabPath of fabricationNotePaths) {
59
+ elementStrings.push(
60
+ `<silkscreenpath route={${JSON.stringify(fabPath.route)}} />`,
61
+ )
62
+ }
63
+
64
+ // Add silkscreen text elements (use pcbX/pcbY instead of anchorPosition)
65
+ for (const stext of silkscreenTexts) {
66
+ const pcbX = stext.anchor_position?.x ?? 0
67
+ const pcbY = stext.anchor_position?.y ?? 0
68
+ const anchorAlignment = stext.anchor_alignment
69
+ const fontSize = stext.font_size
70
+ // Escape quotes in text content for JSX attribute
71
+ const rawText = String(stext.text ?? "")
72
+ const escapedText = rawText.replace(/"/g, '\\"')
73
+
74
+ elementStrings.push(
75
+ `<silkscreentext pcbX={${pcbX}} pcbY={${pcbY}} anchorAlignment="${anchorAlignment}" fontSize={${fontSize}} text="${escapedText}" />`,
76
+ )
77
+ }
78
+
55
79
  return `
56
80
  <footprint>
57
81
  ${elementStrings.join("\n")}
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "./cli": "./dist/cli/main.js"
7
7
  },
8
8
  "type": "module",
9
- "version": "0.0.8",
9
+ "version": "0.0.9",
10
10
  "scripts": {
11
11
  "build": "tsup-node lib/index.ts cli/main.ts --format esm --dts",
12
12
  "test": "bun test",
@@ -0,0 +1,198 @@
1
+ import { test, expect } from "bun:test"
2
+ import { convertCircuitJsonToTscircuit } from "lib"
3
+
4
+ test("test4 support silkscreen", async () => {
5
+ const tscircuit = convertCircuitJsonToTscircuit(circuitJson, {
6
+ componentName: "Test4Component",
7
+ })
8
+
9
+ expect(tscircuit).toMatchInlineSnapshot(`
10
+ "import { type ChipProps } from "tscircuit"
11
+ export const Test4Component = (props: ChipProps) => (
12
+ <chip
13
+ footprint={<footprint>
14
+ <smtpad portHints={["1"]} pcbX="-0.32mm" pcbY="0mm" width="0.46mm" height="0.4mm" shape="rect" />
15
+ <smtpad portHints={["2"]} pcbX="0.32mm" pcbY="0mm" width="0.46mm" height="0.4mm" shape="rect" />
16
+ <silkscreenpath route={[{"x":-0.3,"y":0.15},{"x":0.3,"y":0.15}]} />
17
+ <silkscreenpath route={[{"x":-0.3,"y":-0.15},{"x":-0.3,"y":0.15}]} />
18
+ <silkscreenpath route={[{"x":0.3,"y":0.15},{"x":0.3,"y":-0.15}]} />
19
+ <silkscreenpath route={[{"x":0.3,"y":-0.15},{"x":-0.3,"y":-0.15}]} />
20
+ <silkscreentext pcbX={0} pcbY={0.68} anchorAlignment="center" fontSize={0.25} text="\${REFERENCE}" />
21
+ <silkscreentext pcbX={0} pcbY={1.05} anchorAlignment="center" fontSize={1.27} text="REF**" />
22
+ <silkscreentext pcbX={0} pcbY={-1.05} anchorAlignment="center" fontSize={1.27} text="R_0201_0603Metric" />
23
+ </footprint>}
24
+ {...props}
25
+ />
26
+ )"
27
+ `)
28
+ })
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: 1.1,
61
+ height: 0.4,
62
+ },
63
+ {
64
+ type: "pcb_smtpad",
65
+ pcb_smtpad_id: "pcb_smtpad_0",
66
+ shape: "rect",
67
+ x: -0.32,
68
+ y: 0,
69
+ width: 0.46,
70
+ height: 0.4,
71
+ layer: "top",
72
+ pcb_component_id: "pcb_generic_component_0",
73
+ port_hints: ["1"],
74
+ },
75
+ {
76
+ type: "pcb_smtpad",
77
+ pcb_smtpad_id: "pcb_smtpad_1",
78
+ shape: "rect",
79
+ x: 0.32,
80
+ y: 0,
81
+ width: 0.46,
82
+ height: 0.4,
83
+ layer: "top",
84
+ pcb_component_id: "pcb_generic_component_0",
85
+ port_hints: ["2"],
86
+ },
87
+ {
88
+ type: "pcb_fabrication_note_path",
89
+ fabrication_note_path_id: "fabrication_note_path_0",
90
+ pcb_component_id: "pcb_generic_component_0",
91
+ layer: "top",
92
+ route: [
93
+ {
94
+ x: -0.3,
95
+ y: 0.15,
96
+ },
97
+ {
98
+ x: 0.3,
99
+ y: 0.15,
100
+ },
101
+ ],
102
+ stroke_width: 0.1,
103
+ port_hints: [],
104
+ },
105
+ {
106
+ type: "pcb_fabrication_note_path",
107
+ fabrication_note_path_id: "fabrication_note_path_1",
108
+ pcb_component_id: "pcb_generic_component_0",
109
+ layer: "top",
110
+ route: [
111
+ {
112
+ x: -0.3,
113
+ y: -0.15,
114
+ },
115
+ {
116
+ x: -0.3,
117
+ y: 0.15,
118
+ },
119
+ ],
120
+ stroke_width: 0.1,
121
+ port_hints: [],
122
+ },
123
+ {
124
+ type: "pcb_fabrication_note_path",
125
+ fabrication_note_path_id: "fabrication_note_path_2",
126
+ pcb_component_id: "pcb_generic_component_0",
127
+ layer: "top",
128
+ route: [
129
+ {
130
+ x: 0.3,
131
+ y: 0.15,
132
+ },
133
+ {
134
+ x: 0.3,
135
+ y: -0.15,
136
+ },
137
+ ],
138
+ stroke_width: 0.1,
139
+ port_hints: [],
140
+ },
141
+ {
142
+ type: "pcb_fabrication_note_path",
143
+ fabrication_note_path_id: "fabrication_note_path_3",
144
+ pcb_component_id: "pcb_generic_component_0",
145
+ layer: "top",
146
+ route: [
147
+ {
148
+ x: 0.3,
149
+ y: -0.15,
150
+ },
151
+ {
152
+ x: -0.3,
153
+ y: -0.15,
154
+ },
155
+ ],
156
+ stroke_width: 0.1,
157
+ port_hints: [],
158
+ },
159
+ {
160
+ type: "pcb_silkscreen_text",
161
+ layer: "top",
162
+ font: "tscircuit2024",
163
+ font_size: 0.25,
164
+ pcb_component_id: "pcb_generic_component_0",
165
+ anchor_position: {
166
+ x: 0,
167
+ y: 0.68,
168
+ },
169
+ anchor_alignment: "center",
170
+ text: "${REFERENCE}",
171
+ },
172
+ {
173
+ type: "pcb_silkscreen_text",
174
+ layer: "top",
175
+ font: "tscircuit2024",
176
+ font_size: 1.27,
177
+ pcb_component_id: "pcb_generic_component_0",
178
+ anchor_position: {
179
+ x: 0,
180
+ y: 1.05,
181
+ },
182
+ anchor_alignment: "center",
183
+ text: "REF**",
184
+ },
185
+ {
186
+ type: "pcb_silkscreen_text",
187
+ layer: "top",
188
+ font: "tscircuit2024",
189
+ font_size: 1.27,
190
+ pcb_component_id: "pcb_generic_component_0",
191
+ anchor_position: {
192
+ x: 0,
193
+ y: -1.05,
194
+ },
195
+ anchor_alignment: "center",
196
+ text: "R_0201_0603Metric",
197
+ },
198
+ ]