circuit-to-svg 0.0.145 → 0.0.147
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 +51 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
# circuit-to-svg
|
|
2
2
|
|
|
3
|
-
A TypeScript library for converting
|
|
3
|
+
A TypeScript library for converting Circuit JSON to Schematic, PCB and Assembly SVG representations.
|
|
4
|
+
|
|
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>
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm add circuit-to-svg
|
|
12
|
+
# or...
|
|
13
|
+
bun add circuit-to-svg
|
|
14
|
+
```
|
|
4
15
|
|
|
5
16
|
## Overview
|
|
6
17
|
|
|
7
|
-
This library provides functionality to convert
|
|
18
|
+
This library provides functionality to convert Circuit JSON into SVG (Scalable Vector Graphics) representations. It supports both schematic and PCB (Printed Circuit Board), and Assembly layouts.
|
|
8
19
|
|
|
9
20
|
## Features
|
|
10
21
|
|
|
@@ -29,24 +40,41 @@ npm install circuit-to-svg
|
|
|
29
40
|
## Usage
|
|
30
41
|
|
|
31
42
|
```typescript
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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)
|
|
41
65
|
```
|
|
42
66
|
|
|
43
67
|
## API
|
|
44
68
|
|
|
45
|
-
###
|
|
69
|
+
### convertCircuitJsonToSchematicSvg
|
|
70
|
+
|
|
71
|
+
`convertCircuitJsonToSchematicSvg(circuitJson: AnyCircuitElement[], options?): string`
|
|
46
72
|
|
|
47
73
|
Converts a schematic circuit description to an SVG string.
|
|
48
74
|
|
|
49
|
-
###
|
|
75
|
+
### convertCircuitJsonToPcbSvg
|
|
76
|
+
|
|
77
|
+
`convertCircuitJsonToPcbSvg(circuitJson: AnyCircuitElement[], options?): string`
|
|
50
78
|
|
|
51
79
|
Converts a PCB layout description to an SVG string.
|
|
52
80
|
|
|
@@ -60,6 +88,16 @@ Converts a PCB layout description to an SVG string.
|
|
|
60
88
|
- `drawPaddingOutsideBoard` – if `false`, omit the board outline and extra
|
|
61
89
|
padding around it. Defaults to `true`.
|
|
62
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
|
+
|
|
63
101
|
## Contributing
|
|
64
102
|
|
|
65
103
|
Contributions are welcome! Please feel free to submit a Pull Request.
|