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 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/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",