circuit-json-to-tscircuit 0.0.21 → 0.0.22

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.
@@ -5,6 +5,7 @@ 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();
9
10
  const fabricationNotePaths = su(circuitJson).pcb_fabrication_note_path.list();
10
11
  const fabricationNoteTexts = su(circuitJson).pcb_fabrication_note_text.list();
@@ -59,6 +60,21 @@ var generateFootprintTsx = (circuitJson) => {
59
60
  `<silkscreenpath route={${JSON.stringify(silkscreenPath.route)}} />`
60
61
  );
61
62
  }
63
+ for (const silkscreenLine of silkscreenLines) {
64
+ const attrs = [
65
+ `x1={${silkscreenLine.x1 ?? 0}}`,
66
+ `y1={${silkscreenLine.y1 ?? 0}}`,
67
+ `x2={${silkscreenLine.x2 ?? 0}}`,
68
+ `y2={${silkscreenLine.y2 ?? 0}}`
69
+ ];
70
+ if (silkscreenLine.stroke_width !== void 0) {
71
+ attrs.push(`strokeWidth={${silkscreenLine.stroke_width}}`);
72
+ }
73
+ if (silkscreenLine.layer === "bottom") {
74
+ attrs.push(`layer="bottom"`);
75
+ }
76
+ elementStrings.push(`<silkscreenline ${attrs.join(" ")} />`);
77
+ }
62
78
  for (const fabPath of fabricationNotePaths) {
63
79
  const attrs = [`route={${JSON.stringify(fabPath.route)}}`];
64
80
  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-3AWPESWI.js";
4
+ } from "../chunk-HOCTWOZW.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.20",
19
+ version: "0.0.21",
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-3AWPESWI.js";
3
+ } from "../chunk-HOCTWOZW.js";
4
4
  export {
5
5
  convertCircuitJsonToTscircuit
6
6
  };
@@ -8,6 +8,7 @@ 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()
12
13
  const fabricationNotePaths = su(circuitJson).pcb_fabrication_note_path.list()
13
14
  const fabricationNoteTexts = su(circuitJson).pcb_fabrication_note_text.list()
@@ -72,6 +73,25 @@ export const generateFootprintTsx = (
72
73
  )
73
74
  }
74
75
 
76
+ for (const silkscreenLine of silkscreenLines) {
77
+ const attrs = [
78
+ `x1={${silkscreenLine.x1 ?? 0}}`,
79
+ `y1={${silkscreenLine.y1 ?? 0}}`,
80
+ `x2={${silkscreenLine.x2 ?? 0}}`,
81
+ `y2={${silkscreenLine.y2 ?? 0}}`,
82
+ ]
83
+
84
+ if (silkscreenLine.stroke_width !== undefined) {
85
+ attrs.push(`strokeWidth={${silkscreenLine.stroke_width}}`)
86
+ }
87
+
88
+ if (silkscreenLine.layer === "bottom") {
89
+ attrs.push(`layer="bottom"`)
90
+ }
91
+
92
+ elementStrings.push(`<silkscreenline ${attrs.join(" ")} />`)
93
+ }
94
+
75
95
  for (const fabPath of fabricationNotePaths) {
76
96
  const attrs = [`route={${JSON.stringify(fabPath.route)}}`]
77
97
 
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.21",
9
+ "version": "0.0.22",
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 @@
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,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
+ ]