circuit-to-svg 0.0.209 → 0.0.211

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
@@ -19,20 +19,6 @@ bun add circuit-to-svg
19
19
 
20
20
  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.
21
21
 
22
- ## Features
23
-
24
- - Convert schematic circuit descriptions to SVG
25
- - Convert PCB layouts to SVG
26
- - Support for various circuit elements:
27
- - Components
28
- - Traces
29
- - Text labels
30
- - Net labels
31
- - PCB boards
32
- - PCB components
33
- - PCB traces
34
- - PCB holes and pads
35
-
36
22
  ## Installation
37
23
 
38
24
  ```bash
@@ -43,28 +29,25 @@ npm install circuit-to-svg
43
29
 
44
30
  ```typescript
45
31
  import { readFileSync, writeFileSync } from 'fs'
46
- import {
47
- convertCircuitJsonToSchematicSvg,
48
- convertCircuitJsonToPcbSvg,
49
- } from 'circuit-to-svg'
32
+ import { convertCircuitJsonToSchematicSvg } from 'circuit-to-svg'
50
33
 
51
34
  const circuitJson = JSON.parse(readFileSync('circuit.json', 'utf8'))
35
+ const schematicSvg = convertCircuitJsonToSchematicSvg(circuitJson)
52
36
 
53
- // Generate a schematic with a grid
54
- const schematicSvg = convertCircuitJsonToSchematicSvg(circuitJson, {
55
- width: 1000,
56
- height: 600,
57
- grid: true,
58
- })
37
+ writeFileSync('schematic.svg', schematicSvg)
38
+ ```
59
39
 
60
- // Generate a PCB image using the board's aspect ratio
61
- const pcbSvg = convertCircuitJsonToPcbSvg(circuitJson, {
62
- matchBoardAspectRatio: true,
63
- backgroundColor: '#1e1e1e',
64
- })
40
+ Explore the API sections below to render PCB, assembly, pinout, simulation, and solder paste views.
65
41
 
66
- writeFileSync('board.svg', pcbSvg)
67
- ```
42
+ | Function | Description |
43
+ | --- | --- |
44
+ | [`convertCircuitJsonToSchematicSvg`](#convertcircuitjsontoschematicsvg) | Generate schematic SVG output from Circuit JSON. |
45
+ | [`convertCircuitJsonToSchematicSimulationSvg`](#convertcircuitjsontoschematicsimulationsvg) | Overlay simulation data on schematic diagrams. |
46
+ | [`convertCircuitJsonToPcbSvg`](#convertcircuitjsontopcbsvg) | Render PCB layouts as SVG graphics. |
47
+ | [`convertCircuitJsonToSolderPasteMask`](#convertcircuitjsontosolderpastemask) | Create solder paste mask layers for fabrication. |
48
+ | [`convertCircuitJsonToAssemblySvg`](#convertcircuitjsontoassemblysvg) | Produce assembly view SVGs for board visualization. |
49
+ | [`convertCircuitJsonToPinoutSvg`](#convertcircuitjsontopinoutsvg) | Build annotated pinout diagrams for boards and modules. |
50
+ | [`convertCircuitJsonToSimulationGraphSvg`](#convertcircuitjsontosimulationgraphsvg) | Plot simulation experiment results as SVG graphs. |
68
51
 
69
52
  ## API
70
53
 
@@ -74,8 +57,22 @@ writeFileSync('board.svg', pcbSvg)
74
57
 
75
58
  Converts a schematic circuit description to an SVG string.
76
59
 
60
+ ```typescript
61
+ import { convertCircuitJsonToSchematicSvg } from 'circuit-to-svg'
62
+
63
+ const schematicSvg = convertCircuitJsonToSchematicSvg(circuitJson, {
64
+ includeVersion: true,
65
+ })
66
+ ```
67
+
68
+ See the [schematic grid snapshot](tests/sch/__snapshots__/grid-and-points.snap.svg).
69
+
77
70
  #### Options
78
71
 
72
+ - `width` and `height` – dimensions of the output SVG. Defaults to `1200x600`.
73
+ - `grid` – enable a schematic grid (`true`) or configure cell size and labels.
74
+ - `labeledPoints` – annotate specific coordinates with helper labels.
75
+ - `colorOverrides` – override portions of the schematic color palette.
79
76
  - `includeVersion` – if `true`, add a `data-circuit-to-svg-version` attribute to
80
77
  the root `<svg>`.
81
78
 
@@ -85,6 +82,17 @@ Converts a schematic circuit description to an SVG string.
85
82
 
86
83
  Converts a PCB layout description to an SVG string.
87
84
 
85
+ ```typescript
86
+ import { convertCircuitJsonToPcbSvg } from 'circuit-to-svg'
87
+
88
+ const pcbSvg = convertCircuitJsonToPcbSvg(circuitJson, {
89
+ matchBoardAspectRatio: true,
90
+ backgroundColor: '#1e1e1e',
91
+ })
92
+ ```
93
+
94
+ See the [PCB default snapshot](tests/pcb/__snapshots__/default.snap.svg).
95
+
88
96
  #### Options
89
97
 
90
98
  - `width` and `height` – dimensions of the output SVG. Defaults to `800x600`.
@@ -103,16 +111,129 @@ Converts a PCB layout description to an SVG string.
103
111
 
104
112
  Converts circuit JSON into an assembly view of the board and components.
105
113
 
114
+ ```typescript
115
+ import { convertCircuitJsonToAssemblySvg } from 'circuit-to-svg'
116
+
117
+ const assemblySvg = convertCircuitJsonToAssemblySvg(circuitJson, {
118
+ includeVersion: false,
119
+ })
120
+ ```
121
+
122
+ See the [assembly board snapshot](tests/assembly/__snapshots__/first-assembly-test.snap.svg).
123
+
106
124
  #### Options
107
125
 
108
126
  - `width` and `height` – dimensions of the output SVG. Defaults to `800x600`.
109
127
  - `includeVersion` – if `true`, add a `data-circuit-to-svg-version` attribute to
110
128
  the root `<svg>`.
111
129
 
112
- ## Contributing
130
+ ### convertCircuitJsonToPinoutSvg
131
+
132
+ `convertCircuitJsonToPinoutSvg(circuitJson: AnyCircuitElement[], options?): string`
133
+
134
+ Generates pinout diagrams that call out ports, pads, and holes for boards or modules.
113
135
 
114
- Contributions are welcome! Please feel free to submit a Pull Request.
136
+ ```typescript
137
+ import { convertCircuitJsonToPinoutSvg } from 'circuit-to-svg'
138
+
139
+ const pinoutSvg = convertCircuitJsonToPinoutSvg(circuitJson)
140
+ ```
141
+
142
+ See the [pinout snapshot](tests/pinout/__snapshots__/pinout-basic.snap.svg).
143
+
144
+ #### Options
145
+
146
+ - `width` and `height` – dimensions of the output SVG. Defaults to `800x600`.
147
+ - `includeVersion` – if `true`, add a `data-circuit-to-svg-version` attribute to
148
+ the root `<svg>`.
115
149
 
116
- ## License
150
+ ### convertCircuitJsonToSchematicSimulationSvg
151
+
152
+ `convertCircuitJsonToSchematicSimulationSvg({
153
+ circuitJson,
154
+ simulation_experiment_id,
155
+ simulation_transient_voltage_graph_ids?,
156
+ width?,
157
+ height?,
158
+ schematicHeightRatio?,
159
+ schematicOptions?,
160
+ includeVersion?,
161
+ }): string`
162
+
163
+ Overlays simulation results directly on the rendered schematic for easy debugging.
164
+
165
+ ```typescript
166
+ import { convertCircuitJsonToSchematicSimulationSvg } from 'circuit-to-svg'
167
+
168
+ const schematicSimulationSvg = convertCircuitJsonToSchematicSimulationSvg({
169
+ circuitJson,
170
+ simulation_experiment_id: 'simulation-experiment-id',
171
+ simulation_transient_voltage_graph_ids: ['transient-graph-id'],
172
+ schematicHeightRatio: 0.6,
173
+ })
174
+ ```
175
+
176
+ See the [schematic simulation snapshot](tests/sim/__snapshots__/schematic-simulation-combined.snap.svg).
177
+
178
+ #### Options
179
+
180
+ - `width` and `height` – overall SVG dimensions. Defaults to `1200x1200`.
181
+ - `schematicHeightRatio` – ratio of the SVG dedicated to the schematic view. Defaults to `0.55`.
182
+ - `schematicOptions` – forward additional schematic rendering options (except `width`, `height`, and `includeVersion`).
183
+ - `includeVersion` – if `true`, add a `data-circuit-to-svg-version` attribute to
184
+ the root `<svg>`.
185
+
186
+ ### convertCircuitJsonToSimulationGraphSvg
187
+
188
+ `convertCircuitJsonToSimulationGraphSvg({
189
+ circuitJson,
190
+ simulation_experiment_id,
191
+ simulation_transient_voltage_graph_ids?,
192
+ width?,
193
+ height?,
194
+ includeVersion?,
195
+ }): string`
196
+
197
+ Creates standalone graphs for circuit simulation experiments.
198
+
199
+ ```typescript
200
+ import { convertCircuitJsonToSimulationGraphSvg } from 'circuit-to-svg'
201
+
202
+ const simulationGraphSvg = convertCircuitJsonToSimulationGraphSvg({
203
+ circuitJson,
204
+ simulation_experiment_id: 'simulation-experiment-id',
205
+ simulation_transient_voltage_graph_ids: ['transient-graph-id'],
206
+ })
207
+ ```
208
+
209
+ See the [simulation graph snapshot](tests/sim/__snapshots__/simulation-graph.snap.svg).
210
+
211
+ #### Options
212
+
213
+ - `width` and `height` – SVG dimensions for the graph. Defaults to `1200x600`.
214
+ - `includeVersion` – if `true`, add a `data-circuit-to-svg-version` attribute to
215
+ the root `<svg>`.
216
+
217
+ ### convertCircuitJsonToSolderPasteMask
218
+
219
+ `convertCircuitJsonToSolderPasteMask(circuitJson: AnyCircuitElement[], options: { layer: 'top' | 'bottom'; width?; height?; includeVersion? }): string`
220
+
221
+ Produces top and bottom solder paste mask renderings suitable for stencil generation.
222
+
223
+ ```typescript
224
+ import { convertCircuitJsonToSolderPasteMask } from 'circuit-to-svg'
225
+
226
+ const solderPasteMaskSvg = convertCircuitJsonToSolderPasteMask(circuitJson, {
227
+ layer: 'top',
228
+ })
229
+ ```
230
+
231
+ See the [solder paste snapshot](tests/pcb/__snapshots__/solder-paste.test.tsx.top.snap.svg).
232
+
233
+ #### Options
234
+
235
+ - `layer` – `'top' | 'bottom'`, chooses which solder paste layer to render. Defaults to `'top'`.
236
+ - `width` and `height` – dimensions of the output SVG. Defaults to `800x600`.
237
+ - `includeVersion` – if `true`, add a `data-circuit-to-svg-version` attribute to
238
+ the root `<svg>`.
117
239
 
118
- This project is licensed under the MIT License.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyCircuitElement, SchematicComponent } from 'circuit-json';
1
+ import { AnyCircuitElement, PcbPort, SchematicComponent } from 'circuit-json';
2
2
  import { Matrix } from 'transformation-matrix';
3
3
  import { INode } from 'svgson';
4
4
 
@@ -87,6 +87,11 @@ interface Options$2 {
87
87
  height?: number;
88
88
  includeVersion?: boolean;
89
89
  }
90
+ interface PinoutLabel {
91
+ pcb_port: PcbPort;
92
+ aliases: string[];
93
+ edge: "left" | "right" | "top" | "bottom";
94
+ }
90
95
  interface PinoutSvgContext {
91
96
  transform: Matrix;
92
97
  soup: AnyCircuitElement[];
@@ -347,4 +352,4 @@ declare const createSvgObjectsForSchComponentPortHovers: ({ component, transform
347
352
  circuitJson: AnyCircuitElement[];
348
353
  }) => INode[];
349
354
 
350
- export { type AssemblySvgContext, CIRCUIT_TO_SVG_VERSION, type ColorMap, type ColorOverrides, type PcbColorMap, type PcbColorOverrides, type PcbContext, type PinoutSvgContext, circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToAssemblySvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToPinoutSvg, convertCircuitJsonToSchematicSimulationSvg, convertCircuitJsonToSchematicSvg, convertCircuitJsonToSimulationGraphSvg, convertCircuitJsonToSolderPasteMask, createSvgObjectsForSchComponentPortHovers, getSoftwareUsedString };
355
+ export { type AssemblySvgContext, CIRCUIT_TO_SVG_VERSION, type ColorMap, type ColorOverrides, type PcbColorMap, type PcbColorOverrides, type PcbContext, type PinoutLabel, type PinoutSvgContext, circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToAssemblySvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToPinoutSvg, convertCircuitJsonToSchematicSimulationSvg, convertCircuitJsonToSchematicSvg, convertCircuitJsonToSimulationGraphSvg, convertCircuitJsonToSolderPasteMask, createSvgObjectsForSchComponentPortHovers, getSoftwareUsedString };