circuit-to-svg 0.0.140 → 0.0.141

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
@@ -57,6 +57,8 @@ Converts a PCB layout description to an SVG string.
57
57
  resulting aspect ratio matches the `pcb_board` found in the circuit JSON.
58
58
  - `backgroundColor` – fill color for the SVG background rectangle. Defaults to
59
59
  `"#000"`.
60
+ - `drawPaddingOutsideBoard` – if `false`, omit the board outline and extra
61
+ padding around it. Defaults to `true`.
60
62
 
61
63
  ## Contributing
62
64
 
package/dist/index.d.ts CHANGED
@@ -9,11 +9,13 @@ interface Options$3 {
9
9
  layer?: "top" | "bottom";
10
10
  matchBoardAspectRatio?: boolean;
11
11
  backgroundColor?: string;
12
+ drawPaddingOutsideBoard?: boolean;
12
13
  }
13
14
  interface PcbContext {
14
15
  transform: Matrix;
15
16
  layer?: "top" | "bottom";
16
17
  shouldDrawErrors?: boolean;
18
+ drawPaddingOutsideBoard?: boolean;
17
19
  }
18
20
  declare function convertCircuitJsonToPcbSvg(circuitJson: AnyCircuitElement[], options?: Options$3): string;
19
21
  /**
package/dist/index.js CHANGED
@@ -1337,6 +1337,7 @@ var OBJECT_ORDER = [
1337
1337
  "pcb_board"
1338
1338
  ];
1339
1339
  function convertCircuitJsonToPcbSvg(circuitJson, options) {
1340
+ const drawPaddingOutsideBoard = options?.drawPaddingOutsideBoard ?? true;
1340
1341
  const layer = options?.layer;
1341
1342
  let minX = Number.POSITIVE_INFINITY;
1342
1343
  let minY = Number.POSITIVE_INFINITY;
@@ -1371,7 +1372,7 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
1371
1372
  updateSilkscreenBounds(circuitJsonElm);
1372
1373
  }
1373
1374
  }
1374
- const padding = 1;
1375
+ const padding = drawPaddingOutsideBoard ? 1 : 0;
1375
1376
  const circuitWidth = maxX - minX + 2 * padding;
1376
1377
  const circuitHeight = maxY - minY + 2 * padding;
1377
1378
  let svgWidth = options?.width ?? 800;
@@ -1412,7 +1413,8 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
1412
1413
  const ctx = {
1413
1414
  transform,
1414
1415
  layer,
1415
- shouldDrawErrors: options?.shouldDrawErrors
1416
+ shouldDrawErrors: options?.shouldDrawErrors,
1417
+ drawPaddingOutsideBoard
1416
1418
  };
1417
1419
  let svgObjects = circuitJson.sort(
1418
1420
  (a, b) => (OBJECT_ORDER.indexOf(b.type) ?? 9999) - (OBJECT_ORDER.indexOf(a.type) ?? 9999)
@@ -1428,6 +1430,43 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
1428
1430
  const ratsNestObjects = createSvgObjectsForRatsNest(circuitJson, ctx);
1429
1431
  svgObjects = svgObjects.concat(ratsNestObjects);
1430
1432
  }
1433
+ const children = [
1434
+ {
1435
+ name: "style",
1436
+ type: "element",
1437
+ value: "",
1438
+ attributes: {},
1439
+ children: [
1440
+ {
1441
+ type: "text",
1442
+ value: "",
1443
+ name: "",
1444
+ attributes: {},
1445
+ children: []
1446
+ }
1447
+ ]
1448
+ },
1449
+ {
1450
+ name: "rect",
1451
+ type: "element",
1452
+ value: "",
1453
+ attributes: {
1454
+ class: "boundary",
1455
+ x: "0",
1456
+ y: "0",
1457
+ fill: options?.backgroundColor ?? "#000",
1458
+ width: svgWidth.toString(),
1459
+ height: svgHeight.toString()
1460
+ },
1461
+ children: []
1462
+ }
1463
+ ];
1464
+ if (drawPaddingOutsideBoard) {
1465
+ children.push(
1466
+ createSvgObjectFromPcbBoundary(transform, minX, minY, maxX, maxY)
1467
+ );
1468
+ }
1469
+ children.push(...svgObjects);
1431
1470
  const svgObject = {
1432
1471
  name: "svg",
1433
1472
  type: "element",
@@ -1437,32 +1476,7 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
1437
1476
  height: svgHeight.toString()
1438
1477
  },
1439
1478
  value: "",
1440
- children: [
1441
- {
1442
- name: "style",
1443
- type: "element",
1444
- children: [
1445
- {
1446
- type: "text",
1447
- value: ""
1448
- }
1449
- ]
1450
- },
1451
- {
1452
- name: "rect",
1453
- type: "element",
1454
- attributes: {
1455
- class: "boundary",
1456
- x: "0",
1457
- y: "0",
1458
- fill: options?.backgroundColor ?? "#000",
1459
- width: svgWidth.toString(),
1460
- height: svgHeight.toString()
1461
- }
1462
- },
1463
- createSvgObjectFromPcbBoundary(transform, minX, minY, maxX, maxY),
1464
- ...svgObjects
1465
- ].filter((child) => child !== null)
1479
+ children: children.filter((child) => child !== null)
1466
1480
  };
1467
1481
  try {
1468
1482
  return stringify(svgObject);
@@ -1570,7 +1584,7 @@ function createSvgObjects({
1570
1584
  case "pcb_silkscreen_path":
1571
1585
  return createSvgObjectsFromPcbSilkscreenPath(elm, ctx);
1572
1586
  case "pcb_board":
1573
- return createSvgObjectsFromPcbBoard(elm, ctx);
1587
+ return ctx.drawPaddingOutsideBoard ? createSvgObjectsFromPcbBoard(elm, ctx) : [];
1574
1588
  case "pcb_via":
1575
1589
  return createSvgObjectsFromPcbVia(elm, ctx);
1576
1590
  case "pcb_cutout":