circuit-to-svg 0.0.146 → 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.
Files changed (2) hide show
  1. package/README.md +42 -14
  2. 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
- ![](https://api.tscircuit.com/packages/images/seveibar/keyboard-default60/pcb.svg?fs_sha=md5-e4fc4758380cab0efcc1b3b12bdcf36d)
6
-
7
- ![](https://api.tscircuit.com/packages/images/seveibar/usb-c-flashlight/schematic.svg?fs_sha=)
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 { convertCircuitJsonToSchematicSvg, convertCircuitJsonToPcbSvg } from 'circuit-to-svg';
43
-
44
- // For schematic circuits
45
- const schematicCircuitJson = [...]; // Your schematic circuit description
46
- const schematicSvg = convertCircuitJsonToSchematicSvg(schematicCircuitJson);
47
-
48
- // For PCB layouts
49
- const pcbCircuitJson = [...]; // Your PCB layout description
50
- const pcbSvg = convertCircuitJsonToPcbSvg(pcbCircuitJson);
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
- ### `convertCircuitJsonToSchematicSvg(circuitJson: AnyCircuitElement[]): string`
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
- ### `convertCircuitJsonToPcbSvg(circuitJson: AnyCircuitElement[]): string`
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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-to-svg",
3
3
  "type": "module",
4
- "version": "0.0.146",
4
+ "version": "0.0.147",
5
5
  "description": "Convert Circuit JSON to SVG",
6
6
  "main": "dist/index.js",
7
7
  "files": [