circuit-to-svg 0.0.144 → 0.0.146

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
@@ -1,10 +1,20 @@
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
+ ![](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=)
8
+
9
+ ```bash
10
+ npm add circuit-to-svg
11
+ # or...
12
+ bun add circuit-to-svg
13
+ ```
4
14
 
5
15
  ## Overview
6
16
 
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.
17
+ 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
18
 
9
19
  ## Features
10
20
 
package/dist/index.js CHANGED
@@ -1466,8 +1466,12 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
1466
1466
  }
1467
1467
  }
1468
1468
  const padding = drawPaddingOutsideBoard ? 1 : 0;
1469
- const circuitWidth = maxX - minX + 2 * padding;
1470
- const circuitHeight = maxY - minY + 2 * padding;
1469
+ const boundsMinX = drawPaddingOutsideBoard || !isFinite(boardMinX) ? minX : boardMinX;
1470
+ const boundsMinY = drawPaddingOutsideBoard || !isFinite(boardMinY) ? minY : boardMinY;
1471
+ const boundsMaxX = drawPaddingOutsideBoard || !isFinite(boardMaxX) ? maxX : boardMaxX;
1472
+ const boundsMaxY = drawPaddingOutsideBoard || !isFinite(boardMaxY) ? maxY : boardMaxY;
1473
+ const circuitWidth = boundsMaxX - boundsMinX + 2 * padding;
1474
+ const circuitHeight = boundsMaxY - boundsMinY + 2 * padding;
1471
1475
  let svgWidth = options?.width ?? 800;
1472
1476
  let svgHeight = options?.height ?? 600;
1473
1477
  if (options?.matchBoardAspectRatio) {
@@ -1497,8 +1501,8 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
1497
1501
  const offsetY = (svgHeight - circuitHeight * scaleFactor) / 2;
1498
1502
  const transform = compose4(
1499
1503
  translate4(
1500
- offsetX - minX * scaleFactor + padding * scaleFactor,
1501
- svgHeight - offsetY + minY * scaleFactor - padding * scaleFactor
1504
+ offsetX - boundsMinX * scaleFactor + padding * scaleFactor,
1505
+ svgHeight - offsetY + boundsMinY * scaleFactor - padding * scaleFactor
1502
1506
  ),
1503
1507
  scale2(scaleFactor, -scaleFactor)
1504
1508
  // Flip in y-direction