circuit-to-svg 0.0.208 → 0.0.210
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 +156 -35
- package/dist/index.d.ts +21 -9
- package/dist/index.js +360 -243
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
54
|
-
|
|
55
|
-
width: 1000,
|
|
56
|
-
height: 600,
|
|
57
|
-
grid: true,
|
|
58
|
-
})
|
|
37
|
+
writeFileSync('schematic.svg', schematicSvg)
|
|
38
|
+
```
|
|
59
39
|
|
|
60
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
@@ -285,14 +285,6 @@ declare function convertCircuitJsonToSchematicSvg(circuitJson: AnyCircuitElement
|
|
|
285
285
|
*/
|
|
286
286
|
declare const circuitJsonToSchematicSvg: typeof convertCircuitJsonToSchematicSvg;
|
|
287
287
|
|
|
288
|
-
interface Options {
|
|
289
|
-
layer: "top" | "bottom";
|
|
290
|
-
width?: number;
|
|
291
|
-
height?: number;
|
|
292
|
-
includeVersion?: boolean;
|
|
293
|
-
}
|
|
294
|
-
declare function convertCircuitJsonToSolderPasteMask(circuitJson: AnyCircuitElement[], options: Options): string;
|
|
295
|
-
|
|
296
288
|
type ExperimentType = string;
|
|
297
289
|
interface SimulationExperimentElement {
|
|
298
290
|
type: "simulation_experiment";
|
|
@@ -315,6 +307,26 @@ interface SimulationTransientVoltageGraphElement {
|
|
|
315
307
|
}
|
|
316
308
|
type CircuitJsonWithSimulation = AnyCircuitElement | SimulationExperimentElement | SimulationTransientVoltageGraphElement;
|
|
317
309
|
|
|
310
|
+
interface ConvertSchematicSimulationParams {
|
|
311
|
+
circuitJson: CircuitJsonWithSimulation[];
|
|
312
|
+
simulation_experiment_id: string;
|
|
313
|
+
simulation_transient_voltage_graph_ids?: string[];
|
|
314
|
+
width?: number;
|
|
315
|
+
height?: number;
|
|
316
|
+
schematicHeightRatio?: number;
|
|
317
|
+
schematicOptions?: Omit<Parameters<typeof convertCircuitJsonToSchematicSvg>[1], "width" | "height" | "includeVersion">;
|
|
318
|
+
includeVersion?: boolean;
|
|
319
|
+
}
|
|
320
|
+
declare function convertCircuitJsonToSchematicSimulationSvg({ circuitJson, simulation_experiment_id, simulation_transient_voltage_graph_ids, width, height, schematicHeightRatio, schematicOptions, includeVersion, }: ConvertSchematicSimulationParams): string;
|
|
321
|
+
|
|
322
|
+
interface Options {
|
|
323
|
+
layer: "top" | "bottom";
|
|
324
|
+
width?: number;
|
|
325
|
+
height?: number;
|
|
326
|
+
includeVersion?: boolean;
|
|
327
|
+
}
|
|
328
|
+
declare function convertCircuitJsonToSolderPasteMask(circuitJson: AnyCircuitElement[], options: Options): string;
|
|
329
|
+
|
|
318
330
|
interface ConvertSimulationGraphParams {
|
|
319
331
|
circuitJson: CircuitJsonWithSimulation[];
|
|
320
332
|
simulation_experiment_id: string;
|
|
@@ -335,4 +347,4 @@ declare const createSvgObjectsForSchComponentPortHovers: ({ component, transform
|
|
|
335
347
|
circuitJson: AnyCircuitElement[];
|
|
336
348
|
}) => INode[];
|
|
337
349
|
|
|
338
|
-
export { type AssemblySvgContext, CIRCUIT_TO_SVG_VERSION, type ColorMap, type ColorOverrides, type PcbColorMap, type PcbColorOverrides, type PcbContext, type PinoutSvgContext, circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToAssemblySvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToPinoutSvg, convertCircuitJsonToSchematicSvg, convertCircuitJsonToSimulationGraphSvg, convertCircuitJsonToSolderPasteMask, createSvgObjectsForSchComponentPortHovers, getSoftwareUsedString };
|
|
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 };
|