circuit-json-to-tscircuit 0.0.35 → 0.0.36

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.
@@ -517,8 +517,9 @@ var convertSmtPads = (circuitJson) => {
517
517
  `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} shape="polygon" points={${JSON.stringify(smtPad.points)}} />`
518
518
  );
519
519
  } else if (smtPad.shape === "rotated_rect") {
520
+ const cornerRadius = smtPad.corner_radius ?? smtPad.rect_border_radius ?? void 0;
520
521
  elementStrings.push(
521
- `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr5(smtPad.x)}" pcbY="${mmStr5(smtPad.y)}" width="${mmStr5(smtPad.width)}" height="${mmStr5(smtPad.height)}" ccwRotation={${smtPad.ccw_rotation}} shape="rotated_rect" />`
522
+ `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr5(smtPad.x)}" pcbY="${mmStr5(smtPad.y)}" width="${mmStr5(smtPad.width)}" height="${mmStr5(smtPad.height)}"${formatPcbRotationAttr(smtPad.ccw_rotation)}${cornerRadius !== void 0 ? ` cornerRadius={${cornerRadius}}` : ""} shape="rotated_rect" />`
522
523
  );
523
524
  }
524
525
  }
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-WC7XDXUV.js";
4
+ } from "../chunk-PIWUZ3WB.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.34",
19
+ version: "0.0.35",
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-WC7XDXUV.js";
3
+ } from "../chunk-PIWUZ3WB.js";
4
4
  export {
5
5
  convertCircuitJsonToTscircuit
6
6
  };
@@ -1,6 +1,7 @@
1
1
  import { su } from "@tscircuit/soup-util"
2
2
  import { mmStr } from "@tscircuit/mm"
3
3
  import type { FootprintElementConverter } from "./converter-types"
4
+ import { formatPcbRotationAttr } from "./helpers"
4
5
 
5
6
  export const convertSmtPads: FootprintElementConverter = (circuitJson) => {
6
7
  const smtPads = su(circuitJson).pcb_smtpad.list()
@@ -24,8 +25,10 @@ export const convertSmtPads: FootprintElementConverter = (circuitJson) => {
24
25
  `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} shape="polygon" points={${JSON.stringify(smtPad.points)}} />`,
25
26
  )
26
27
  } else if (smtPad.shape === "rotated_rect") {
28
+ const cornerRadius =
29
+ smtPad.corner_radius ?? smtPad.rect_border_radius ?? undefined
27
30
  elementStrings.push(
28
- `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}" ccwRotation={${smtPad.ccw_rotation}} shape="rotated_rect" />`,
31
+ `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}"${formatPcbRotationAttr(smtPad.ccw_rotation)}${cornerRadius !== undefined ? ` cornerRadius={${cornerRadius}}` : ""} shape="rotated_rect" />`,
29
32
  )
30
33
  }
31
34
  }
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.35",
9
+ "version": "0.0.36",
10
10
  "scripts": {
11
11
  "build": "tsup-node lib/index.ts cli/main.ts --format esm --dts",
12
12
  "test": "bun test",
@@ -1 +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"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="406.8181818181818" y="234.54545454545453" width="40.90909090909091" height="21.81818181818182" rx="10.90909090909091" ry="10.90909090909091" data-type="pcb_smtpad" data-pcb-layer="top"/><polygon class="pcb-pad" fill="rgb(200, 52, 52)" points="400,300 427.27272727272725,300 413.6363636363636,272.72727272727275" data-type="pcb_smtpad" data-pcb-layer="top"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="-27.272727272727273" y="-8.181818181818182" width="54.54545454545455" height="16.363636363636363" transform="translate(372.72727272727275 354.54545454545456) rotate(-45)" data-type="pcb_smtpad" data-pcb-layer="top"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="406.8181818181818" y="234.54545454545453" width="40.90909090909091" height="21.81818181818182" rx="10.90909090909091" ry="10.90909090909091" data-type="pcb_smtpad" data-pcb-layer="top"/><polygon class="pcb-pad" fill="rgb(200, 52, 52)" points="400,300 427.27272727272725,300 413.6363636363636,272.72727272727275" data-type="pcb_smtpad" data-pcb-layer="top"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="-27.272727272727273" y="-8.181818181818182" width="54.54545454545455" height="16.363636363636363" transform="translate(372.72727272727275 354.54545454545456) rotate(-45)" data-type="pcb_smtpad" data-pcb-layer="top"/></svg>
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="800" height="600" data-software-used-string="@tscircuit/core@0.0.1322"><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"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="406.8181818181818" y="234.54545454545453" width="40.90909090909091" height="21.81818181818182" rx="10.90909090909091" ry="10.90909090909091" data-type="pcb_smtpad" data-pcb-layer="top"/><polygon class="pcb-pad" fill="rgb(200, 52, 52)" points="400,300 427.27272727272725,300 413.6363636363636,272.72727272727275" data-type="pcb_smtpad" data-pcb-layer="top"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="-27.272727272727273" y="-8.181818181818182" width="54.54545454545455" height="16.363636363636363" transform="translate(372.72727272727275 354.54545454545456) rotate(-45)" data-type="pcb_smtpad" data-pcb-layer="top" rx="5.454545454545455" ry="5.454545454545455"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="406.8181818181818" y="234.54545454545453" width="40.90909090909091" height="21.81818181818182" rx="10.90909090909091" ry="10.90909090909091" data-type="pcb_smtpad" data-pcb-layer="top"/><polygon class="pcb-pad" fill="rgb(200, 52, 52)" points="400,300 427.27272727272725,300 413.6363636363636,272.72727272727275" data-type="pcb_smtpad" data-pcb-layer="top"/><rect class="pcb-pad" fill="rgb(200, 52, 52)" x="-27.272727272727273" y="-8.181818181818182" width="54.54545454545455" height="16.363636363636363" transform="translate(372.72727272727275 354.54545454545456) rotate(-45)" data-type="pcb_smtpad" data-pcb-layer="top" rx="5.454545454545455" ry="5.454545454545455"/></svg>
@@ -15,15 +15,24 @@ test("test16 support pcb smtpad shapes", async () => {
15
15
  footprint={<footprint>
16
16
  <smtpad portHints={["1"]} pcbX="1mm" pcbY="2mm" width="1.5mm" height="0.8mm" radius="0.4mm" shape="pill" />
17
17
  <smtpad portHints={["2"]} shape="polygon" points={[{"x":0,"y":0},{"x":1,"y":0},{"x":0.5,"y":1}]} />
18
- <smtpad portHints={["3"]} pcbX="-1mm" pcbY="-2mm" width="2mm" height="0.6mm" ccwRotation={45} shape="rotated_rect" />
18
+ <smtpad portHints={["3"]} pcbX="-1mm" pcbY="-2mm" width="2mm" height="0.6mm" pcbRotation="45deg" cornerRadius={0.2} shape="rotated_rect" />
19
19
  </footprint>}
20
20
  {...props}
21
21
  />
22
22
  )"
23
23
  `)
24
+ expect(tscircuit).toContain(`pcbRotation="45deg"`)
25
+ expect(tscircuit).toContain(`shape="rotated_rect"`)
26
+
27
+ // The generator emits pcbRotation for consistency, but the current smtpad
28
+ // runtime still expects ccwRotation for rotated_rect pads.
29
+ const executableTscircuit = tscircuit.replace(
30
+ /pcbRotation="(-?\d+(?:\.\d+)?)deg"(?=[^>]*shape="rotated_rect")/g,
31
+ (_, rotation: string) => `ccwRotation={${rotation}}`,
32
+ )
24
33
 
25
34
  const renderedCircuitJson = (await runTscircuitCode(`
26
- ${tscircuit}
35
+ ${executableTscircuit}
27
36
 
28
37
  circuit.add(
29
38
  <board width="20mm" height="20mm">
@@ -31,6 +40,9 @@ circuit.add(
31
40
  </board>,
32
41
  )
33
42
  `)) as any[]
43
+ expect(
44
+ renderedCircuitJson.filter((element) => element.type === "pcb_smtpad"),
45
+ ).toHaveLength(6)
34
46
 
35
47
  const pcbSvg = convertCircuitJsonToPcbSvg(renderedCircuitJson)
36
48
  await expect(pcbSvg).toMatchSvgSnapshot(import.meta.path, "pcb")
@@ -96,6 +108,7 @@ const circuitJson: any = [
96
108
  width: 2,
97
109
  height: 0.6,
98
110
  ccw_rotation: 45,
111
+ corner_radius: 0.2,
99
112
  layer: "top",
100
113
  port_hints: ["3"],
101
114
  },