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.
Files changed (2) hide show
  1. package/README.md +51 -13
  2. 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 circuit descriptions (soup) to SVG representations.
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 circuit descriptions, referred to as "soup", into SVG (Scalable Vector Graphics) representations. It supports both schematic and PCB (Printed Circuit Board) layouts.
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 { convertCircuitJsonToSchematicSvg, convertCircuitJsonToPcbSvg } from 'circuit-to-svg';
33
-
34
- // For schematic circuits
35
- const schematicCircuitJson = [...]; // Your schematic circuit description
36
- const schematicSvg = convertCircuitJsonToSchematicSvg(schematicCircuitJson);
37
-
38
- // For PCB layouts
39
- const pcbCircuitJson = [...]; // Your PCB layout description
40
- 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)
41
65
  ```
42
66
 
43
67
  ## API
44
68
 
45
- ### `convertCircuitJsonToSchematicSvg(circuitJson: AnyCircuitElement[]): string`
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
- ### `convertCircuitJsonToPcbSvg(circuitJson: AnyCircuitElement[]): string`
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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-to-svg",
3
3
  "type": "module",
4
- "version": "0.0.145",
4
+ "version": "0.0.147",
5
5
  "description": "Convert Circuit JSON to SVG",
6
6
  "main": "dist/index.js",
7
7
  "files": [