circuit-to-svg 0.0.146 → 0.0.148
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/README.md +42 -14
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
A TypeScript library for converting Circuit JSON to Schematic, PCB and Assembly SVG representations.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
<div align="center">
|
|
6
|
+
<img src="https://api.tscircuit.com/packages/images/seveibar/keyboard-default60/pcb.svg?fs_sha=md5-e4fc4758380cab0efcc1b3b12bdcf36d" alt="Keyboard PCB" height="200" />
|
|
7
|
+
<img src="https://api.tscircuit.com/packages/images/seveibar/usb-c-flashlight/schematic.svg?fs_sha=" alt="Flashlight schematic" height="200" />
|
|
8
|
+
</div>
|
|
8
9
|
|
|
9
10
|
```bash
|
|
10
11
|
npm add circuit-to-svg
|
|
@@ -39,24 +40,41 @@ npm install circuit-to-svg
|
|
|
39
40
|
## Usage
|
|
40
41
|
|
|
41
42
|
```typescript
|
|
42
|
-
import {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
import { readFileSync, writeFileSync } from 'fs'
|
|
44
|
+
import {
|
|
45
|
+
convertCircuitJsonToSchematicSvg,
|
|
46
|
+
convertCircuitJsonToPcbSvg,
|
|
47
|
+
} from 'circuit-to-svg'
|
|
48
|
+
|
|
49
|
+
const circuitJson = JSON.parse(readFileSync('circuit.json', 'utf8'))
|
|
50
|
+
|
|
51
|
+
// Generate a schematic with a grid
|
|
52
|
+
const schematicSvg = convertCircuitJsonToSchematicSvg(circuitJson, {
|
|
53
|
+
width: 1000,
|
|
54
|
+
height: 600,
|
|
55
|
+
grid: true,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// Generate a PCB image using the board's aspect ratio
|
|
59
|
+
const pcbSvg = convertCircuitJsonToPcbSvg(circuitJson, {
|
|
60
|
+
matchBoardAspectRatio: true,
|
|
61
|
+
backgroundColor: '#1e1e1e',
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
writeFileSync('board.svg', pcbSvg)
|
|
51
65
|
```
|
|
52
66
|
|
|
53
67
|
## API
|
|
54
68
|
|
|
55
|
-
###
|
|
69
|
+
### convertCircuitJsonToSchematicSvg
|
|
70
|
+
|
|
71
|
+
`convertCircuitJsonToSchematicSvg(circuitJson: AnyCircuitElement[], options?): string`
|
|
56
72
|
|
|
57
73
|
Converts a schematic circuit description to an SVG string.
|
|
58
74
|
|
|
59
|
-
###
|
|
75
|
+
### convertCircuitJsonToPcbSvg
|
|
76
|
+
|
|
77
|
+
`convertCircuitJsonToPcbSvg(circuitJson: AnyCircuitElement[], options?): string`
|
|
60
78
|
|
|
61
79
|
Converts a PCB layout description to an SVG string.
|
|
62
80
|
|
|
@@ -70,6 +88,16 @@ Converts a PCB layout description to an SVG string.
|
|
|
70
88
|
- `drawPaddingOutsideBoard` – if `false`, omit the board outline and extra
|
|
71
89
|
padding around it. Defaults to `true`.
|
|
72
90
|
|
|
91
|
+
### convertCircuitJsonToAssemblySvg
|
|
92
|
+
|
|
93
|
+
`convertCircuitJsonToAssemblySvg(circuitJson: AnyCircuitElement[], options?): string`
|
|
94
|
+
|
|
95
|
+
Converts circuit JSON into an assembly view of the board and components.
|
|
96
|
+
|
|
97
|
+
#### Options
|
|
98
|
+
|
|
99
|
+
- `width` and `height` – dimensions of the output SVG. Defaults to `800x600`.
|
|
100
|
+
|
|
73
101
|
## Contributing
|
|
74
102
|
|
|
75
103
|
Contributions are welcome! Please feel free to submit a Pull Request.
|
package/dist/index.js
CHANGED
|
@@ -882,7 +882,7 @@ function createSvgObjectsFromPcbTrace(trace, ctx) {
|
|
|
882
882
|
const layer = "layer" in start ? start.layer : "layer" in end ? end.layer : null;
|
|
883
883
|
if (!layer) continue;
|
|
884
884
|
if (layerFilter && layer !== layerFilter) continue;
|
|
885
|
-
const layerColor = layerNameToColor(layer, colorMap2);
|
|
885
|
+
const layerColor = colorMap2.soldermask[layer] ?? layerNameToColor(layer, colorMap2);
|
|
886
886
|
const traceWidth = "width" in start ? start.width : "width" in end ? end.width : null;
|
|
887
887
|
const svgObject = {
|
|
888
888
|
name: "path",
|