circuit-to-svg 0.0.140 → 0.0.142

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
@@ -1,7 +1,27 @@
1
1
  import { AnyCircuitElement } from 'circuit-json';
2
2
  import { Matrix } from 'transformation-matrix';
3
3
 
4
+ interface PcbColorMap {
5
+ copper: {
6
+ top: string;
7
+ bottom: string;
8
+ };
9
+ drill: string;
10
+ silkscreen: {
11
+ top: string;
12
+ bottom: string;
13
+ };
14
+ boardOutline: string;
15
+ }
16
+ interface PcbColorOverrides {
17
+ copper?: Partial<PcbColorMap["copper"]>;
18
+ drill?: string;
19
+ silkscreen?: Partial<PcbColorMap["silkscreen"]>;
20
+ boardOutline?: string;
21
+ }
22
+
4
23
  interface Options$3 {
24
+ colorOverrides?: PcbColorOverrides;
5
25
  width?: number;
6
26
  height?: number;
7
27
  shouldDrawErrors?: boolean;
@@ -9,11 +29,14 @@ interface Options$3 {
9
29
  layer?: "top" | "bottom";
10
30
  matchBoardAspectRatio?: boolean;
11
31
  backgroundColor?: string;
32
+ drawPaddingOutsideBoard?: boolean;
12
33
  }
13
34
  interface PcbContext {
14
35
  transform: Matrix;
15
36
  layer?: "top" | "bottom";
16
37
  shouldDrawErrors?: boolean;
38
+ drawPaddingOutsideBoard?: boolean;
39
+ colorMap: PcbColorMap;
17
40
  }
18
41
  declare function convertCircuitJsonToPcbSvg(circuitJson: AnyCircuitElement[], options?: Options$3): string;
19
42
  /**
@@ -217,4 +240,4 @@ interface Options {
217
240
  }
218
241
  declare function convertCircuitJsonToSolderPasteMask(circuitJson: AnyCircuitElement[], options: Options): string;
219
242
 
220
- export { type ColorMap, type ColorOverrides, type PcbContext, circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToAssemblySvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToSchematicSvg, convertCircuitJsonToSolderPasteMask };
243
+ export { type ColorMap, type ColorOverrides, type PcbColorMap, type PcbColorOverrides, type PcbContext, circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToAssemblySvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToSchematicSvg, convertCircuitJsonToSolderPasteMask };
package/dist/index.js CHANGED
@@ -333,7 +333,7 @@ function createSvgObjectsFromPcbFabricationNoteText(pcbFabNoteText, ctx) {
333
333
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-plated-hole.ts
334
334
  import { applyToPoint as applyToPoint4 } from "transformation-matrix";
335
335
  function createSvgObjectsFromPcbPlatedHole(hole, ctx) {
336
- const { transform } = ctx;
336
+ const { transform, colorMap: colorMap2 } = ctx;
337
337
  const [x, y] = applyToPoint4(transform, [hole.x, hole.y]);
338
338
  if (hole.shape === "pill") {
339
339
  const scaledOuterWidth = hole.outer_width * Math.abs(transform.a);
@@ -356,7 +356,7 @@ function createSvgObjectsFromPcbPlatedHole(hole, ctx) {
356
356
  type: "element",
357
357
  attributes: {
358
358
  class: "pcb-hole-outer",
359
- fill: "rgb(200, 52, 52)",
359
+ fill: colorMap2.copper.top,
360
360
  d: `M${x - outerRadiusX},${y - straightLength / 2} v${straightLength} a${outerRadiusX},${outerRadiusX} 0 0 0 ${scaledOuterWidth},0 v-${straightLength} a${outerRadiusX},${outerRadiusX} 0 0 0 -${scaledOuterWidth},0 z`
361
361
  },
362
362
  value: "",
@@ -368,7 +368,7 @@ function createSvgObjectsFromPcbPlatedHole(hole, ctx) {
368
368
  type: "element",
369
369
  attributes: {
370
370
  class: "pcb-hole-inner",
371
- fill: "rgb(255, 38, 226)",
371
+ fill: colorMap2.drill,
372
372
  d: `M${x - innerRadiusX},${y - (scaledHoleHeight - scaledHoleWidth) / 2} v${scaledHoleHeight - scaledHoleWidth} a${innerRadiusX},${innerRadiusX} 0 0 0 ${scaledHoleWidth},0 v-${scaledHoleHeight - scaledHoleWidth} a${innerRadiusX},${innerRadiusX} 0 0 0 -${scaledHoleWidth},0 z`
373
373
  },
374
374
  value: "",
@@ -397,7 +397,7 @@ function createSvgObjectsFromPcbPlatedHole(hole, ctx) {
397
397
  type: "element",
398
398
  attributes: {
399
399
  class: "pcb-hole-outer",
400
- fill: "rgb(200, 52, 52)",
400
+ fill: colorMap2.copper.top,
401
401
  cx: x.toString(),
402
402
  cy: y.toString(),
403
403
  r: outerRadius.toString()
@@ -410,7 +410,7 @@ function createSvgObjectsFromPcbPlatedHole(hole, ctx) {
410
410
  type: "element",
411
411
  attributes: {
412
412
  class: "pcb-hole-inner",
413
- fill: "rgb(255, 38, 226)",
413
+ fill: colorMap2.drill,
414
414
  cx: x.toString(),
415
415
  cy: y.toString(),
416
416
  r: innerRadius.toString()
@@ -440,7 +440,7 @@ function createSvgObjectsFromPcbPlatedHole(hole, ctx) {
440
440
  type: "element",
441
441
  attributes: {
442
442
  class: "pcb-hole-outer-pad",
443
- fill: "rgb(200, 52, 52)",
443
+ fill: colorMap2.copper.top,
444
444
  x: (x - scaledRectPadWidth / 2).toString(),
445
445
  y: (y - scaledRectPadHeight / 2).toString(),
446
446
  width: scaledRectPadWidth.toString(),
@@ -455,7 +455,7 @@ function createSvgObjectsFromPcbPlatedHole(hole, ctx) {
455
455
  type: "element",
456
456
  attributes: {
457
457
  class: "pcb-hole-inner",
458
- fill: "rgb(255, 38, 226)",
458
+ fill: colorMap2.drill,
459
459
  cx: x.toString(),
460
460
  cy: y.toString(),
461
461
  r: holeRadius.toString()
@@ -486,7 +486,7 @@ function createSvgObjectsFromPcbPlatedHole(hole, ctx) {
486
486
  type: "element",
487
487
  attributes: {
488
488
  class: "pcb-hole-outer-pad",
489
- fill: "rgb(200, 52, 52)",
489
+ fill: colorMap2.copper.top,
490
490
  x: (x - scaledRectPadWidth / 2).toString(),
491
491
  y: (y - scaledRectPadHeight / 2).toString(),
492
492
  width: scaledRectPadWidth.toString(),
@@ -501,7 +501,7 @@ function createSvgObjectsFromPcbPlatedHole(hole, ctx) {
501
501
  type: "element",
502
502
  attributes: {
503
503
  class: "pcb-hole-inner",
504
- fill: "rgb(255, 38, 226)",
504
+ fill: colorMap2.drill,
505
505
  x: (x - scaledHoleWidth / 2).toString(),
506
506
  y: (y - scaledHoleHeight / 2).toString(),
507
507
  width: scaledHoleWidth.toString(),
@@ -523,15 +523,8 @@ function createSvgObjectsFromPcbPlatedHole(hole, ctx) {
523
523
 
524
524
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-silkscreen-path.ts
525
525
  import { applyToPoint as applyToPoint5 } from "transformation-matrix";
526
-
527
- // lib/pcb/colors.ts
528
- var HOLE_COLOR = "#FF26E2";
529
- var SILKSCREEN_TOP_COLOR = "#f2eda1";
530
- var SILKSCREEN_BOTTOM_COLOR = "#5da9e9";
531
-
532
- // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-silkscreen-path.ts
533
526
  function createSvgObjectsFromPcbSilkscreenPath(silkscreenPath, ctx) {
534
- const { transform, layer: layerFilter } = ctx;
527
+ const { transform, layer: layerFilter, colorMap: colorMap2 } = ctx;
535
528
  if (!silkscreenPath.route || !Array.isArray(silkscreenPath.route)) return [];
536
529
  let path = silkscreenPath.route.map((point, index) => {
537
530
  const [x, y] = applyToPoint5(transform, [point.x, point.y]);
@@ -544,7 +537,7 @@ function createSvgObjectsFromPcbSilkscreenPath(silkscreenPath, ctx) {
544
537
  }
545
538
  const layer = silkscreenPath.layer || "top";
546
539
  if (layerFilter && layer !== layerFilter) return [];
547
- const color = layer === "bottom" ? SILKSCREEN_BOTTOM_COLOR : SILKSCREEN_TOP_COLOR;
540
+ const color = layer === "bottom" ? colorMap2.silkscreen.bottom : colorMap2.silkscreen.top;
548
541
  return [
549
542
  {
550
543
  name: "path",
@@ -576,7 +569,7 @@ import {
576
569
  toString as matrixToString2
577
570
  } from "transformation-matrix";
578
571
  function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, ctx) {
579
- const { transform, layer: layerFilter } = ctx;
572
+ const { transform, layer: layerFilter, colorMap: colorMap2 } = ctx;
580
573
  const {
581
574
  anchor_position,
582
575
  text,
@@ -643,7 +636,7 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, ctx) {
643
636
  rotate2(ccw_rotation * Math.PI / 180),
644
637
  ...layer === "bottom" ? [scale(-1, 1)] : []
645
638
  );
646
- const color = layer === "bottom" ? SILKSCREEN_BOTTOM_COLOR : SILKSCREEN_TOP_COLOR;
639
+ const color = layer === "bottom" ? colorMap2.silkscreen.bottom : colorMap2.silkscreen.top;
647
640
  const svgObject = {
648
641
  name: "text",
649
642
  type: "element",
@@ -679,7 +672,7 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, ctx) {
679
672
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-silkscreen-rect.ts
680
673
  import { applyToPoint as applyToPoint7 } from "transformation-matrix";
681
674
  function createSvgObjectsFromPcbSilkscreenRect(pcbSilkscreenRect, ctx) {
682
- const { transform, layer: layerFilter } = ctx;
675
+ const { transform, layer: layerFilter, colorMap: colorMap2 } = ctx;
683
676
  const {
684
677
  center,
685
678
  width,
@@ -703,7 +696,7 @@ function createSvgObjectsFromPcbSilkscreenRect(pcbSilkscreenRect, ctx) {
703
696
  const transformedWidth = width * Math.abs(transform.a);
704
697
  const transformedHeight = height * Math.abs(transform.d);
705
698
  const transformedStrokeWidth = stroke_width * Math.abs(transform.a);
706
- const color = layer === "bottom" ? SILKSCREEN_BOTTOM_COLOR : SILKSCREEN_TOP_COLOR;
699
+ const color = layer === "bottom" ? colorMap2.silkscreen.bottom : colorMap2.silkscreen.top;
707
700
  const attributes = {
708
701
  x: (transformedX - transformedWidth / 2).toString(),
709
702
  y: (transformedY - transformedHeight / 2).toString(),
@@ -743,7 +736,7 @@ function createSvgObjectsFromPcbSilkscreenRect(pcbSilkscreenRect, ctx) {
743
736
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-silkscreen-circle.ts
744
737
  import { applyToPoint as applyToPoint8 } from "transformation-matrix";
745
738
  function createSvgObjectsFromPcbSilkscreenCircle(pcbSilkscreenCircle, ctx) {
746
- const { transform, layer: layerFilter } = ctx;
739
+ const { transform, layer: layerFilter, colorMap: colorMap2 } = ctx;
747
740
  const {
748
741
  center,
749
742
  radius,
@@ -762,7 +755,7 @@ function createSvgObjectsFromPcbSilkscreenCircle(pcbSilkscreenCircle, ctx) {
762
755
  ]);
763
756
  const transformedRadius = radius * Math.abs(transform.a);
764
757
  const transformedStrokeWidth = stroke_width * Math.abs(transform.a);
765
- const color = layer === "bottom" ? SILKSCREEN_BOTTOM_COLOR : SILKSCREEN_TOP_COLOR;
758
+ const color = layer === "bottom" ? colorMap2.silkscreen.bottom : colorMap2.silkscreen.top;
766
759
  const svgObject = {
767
760
  name: "circle",
768
761
  type: "element",
@@ -784,7 +777,7 @@ function createSvgObjectsFromPcbSilkscreenCircle(pcbSilkscreenCircle, ctx) {
784
777
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-silkscreen-line.ts
785
778
  import { applyToPoint as applyToPoint9 } from "transformation-matrix";
786
779
  function createSvgObjectsFromPcbSilkscreenLine(pcbSilkscreenLine, ctx) {
787
- const { transform, layer: layerFilter } = ctx;
780
+ const { transform, layer: layerFilter, colorMap: colorMap2 } = ctx;
788
781
  const {
789
782
  x1,
790
783
  y1,
@@ -802,7 +795,7 @@ function createSvgObjectsFromPcbSilkscreenLine(pcbSilkscreenLine, ctx) {
802
795
  const [transformedX1, transformedY1] = applyToPoint9(transform, [x1, y1]);
803
796
  const [transformedX2, transformedY2] = applyToPoint9(transform, [x2, y2]);
804
797
  const transformedStrokeWidth = stroke_width * Math.abs(transform.a);
805
- const color = layer === "bottom" ? SILKSCREEN_BOTTOM_COLOR : SILKSCREEN_TOP_COLOR;
798
+ const color = layer === "bottom" ? colorMap2.silkscreen.bottom : colorMap2.silkscreen.top;
806
799
  return [
807
800
  {
808
801
  name: "line",
@@ -835,13 +828,30 @@ function pairs(arr) {
835
828
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-trace.ts
836
829
  import { applyToPoint as applyToPoint10 } from "transformation-matrix";
837
830
 
831
+ // lib/pcb/colors.ts
832
+ var DEFAULT_PCB_COLOR_MAP = {
833
+ copper: {
834
+ top: "rgb(200, 52, 52)",
835
+ bottom: "rgb(77, 127, 196)"
836
+ },
837
+ drill: "#FF26E2",
838
+ silkscreen: {
839
+ top: "#f2eda1",
840
+ bottom: "#5da9e9"
841
+ },
842
+ boardOutline: "rgba(255, 255, 255, 0.5)"
843
+ };
844
+ var HOLE_COLOR = DEFAULT_PCB_COLOR_MAP.drill;
845
+ var SILKSCREEN_TOP_COLOR = DEFAULT_PCB_COLOR_MAP.silkscreen.top;
846
+ var SILKSCREEN_BOTTOM_COLOR = DEFAULT_PCB_COLOR_MAP.silkscreen.bottom;
847
+
838
848
  // lib/pcb/layer-name-to-color.ts
839
849
  var LAYER_NAME_TO_COLOR = {
840
- top: "rgb(200, 52, 52)",
841
- bottom: "rgb(77, 127, 196)"
850
+ top: DEFAULT_PCB_COLOR_MAP.copper.top,
851
+ bottom: DEFAULT_PCB_COLOR_MAP.copper.bottom
842
852
  };
843
- function layerNameToColor(layerName) {
844
- return LAYER_NAME_TO_COLOR[layerName] ?? "white";
853
+ function layerNameToColor(layerName, colorMap2 = DEFAULT_PCB_COLOR_MAP) {
854
+ return colorMap2.copper[layerName] ?? "white";
845
855
  }
846
856
  var SOLDER_PASTE_LAYER_NAME_TO_COLOR = {
847
857
  bottom: "rgb(105, 105, 105)",
@@ -853,7 +863,7 @@ function solderPasteLayerNameToColor(layerName) {
853
863
 
854
864
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-trace.ts
855
865
  function createSvgObjectsFromPcbTrace(trace, ctx) {
856
- const { transform, layer: layerFilter } = ctx;
866
+ const { transform, layer: layerFilter, colorMap: colorMap2 } = ctx;
857
867
  if (!trace.route || !Array.isArray(trace.route) || trace.route.length < 2)
858
868
  return [];
859
869
  const segments = pairs(trace.route);
@@ -864,7 +874,7 @@ function createSvgObjectsFromPcbTrace(trace, ctx) {
864
874
  const layer = "layer" in start ? start.layer : "layer" in end ? end.layer : null;
865
875
  if (!layer) continue;
866
876
  if (layerFilter && layer !== layerFilter) continue;
867
- const layerColor = LAYER_NAME_TO_COLOR[layer] ?? "white";
877
+ const layerColor = layerNameToColor(layer, colorMap2);
868
878
  const traceWidth = "width" in start ? start.width : "width" in end ? end.width : null;
869
879
  const svgObject = {
870
880
  name: "path",
@@ -902,7 +912,7 @@ function createSvgObjectsFromPcbTrace(trace, ctx) {
902
912
  // lib/pcb/svg-object-fns/create-svg-objects-from-smt-pads.ts
903
913
  import { applyToPoint as applyToPoint11 } from "transformation-matrix";
904
914
  function createSvgObjectsFromSmtPad(pad, ctx) {
905
- const { transform, layer: layerFilter } = ctx;
915
+ const { transform, layer: layerFilter, colorMap: colorMap2 } = ctx;
906
916
  const [x, y] = applyToPoint11(transform, [pad.x, pad.y]);
907
917
  if (layerFilter && pad.layer !== layerFilter) return [];
908
918
  if (pad.shape === "rect" || pad.shape === "rotated_rect") {
@@ -915,7 +925,7 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
915
925
  type: "element",
916
926
  attributes: {
917
927
  class: "pcb-pad",
918
- fill: layerNameToColor(pad.layer),
928
+ fill: layerNameToColor(pad.layer, colorMap2),
919
929
  x: (-width / 2).toString(),
920
930
  y: (-height / 2).toString(),
921
931
  width: width.toString(),
@@ -931,7 +941,7 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
931
941
  type: "element",
932
942
  attributes: {
933
943
  class: "pcb-pad",
934
- fill: layerNameToColor(pad.layer),
944
+ fill: layerNameToColor(pad.layer, colorMap2),
935
945
  x: (x - width / 2).toString(),
936
946
  y: (y - height / 2).toString(),
937
947
  width: width.toString(),
@@ -950,7 +960,7 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
950
960
  type: "element",
951
961
  attributes: {
952
962
  class: "pcb-pad",
953
- fill: layerNameToColor(pad.layer),
963
+ fill: layerNameToColor(pad.layer, colorMap2),
954
964
  x: (x - width / 2).toString(),
955
965
  y: (y - height / 2).toString(),
956
966
  width: width.toString(),
@@ -967,7 +977,7 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
967
977
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-board.ts
968
978
  import { applyToPoint as applyToPoint12 } from "transformation-matrix";
969
979
  function createSvgObjectsFromPcbBoard(pcbBoard, ctx) {
970
- const { transform } = ctx;
980
+ const { transform, colorMap: colorMap2 } = ctx;
971
981
  const { width, height, center, outline } = pcbBoard;
972
982
  let path;
973
983
  if (outline && Array.isArray(outline) && outline.length >= 3) {
@@ -1007,7 +1017,7 @@ function createSvgObjectsFromPcbBoard(pcbBoard, ctx) {
1007
1017
  class: "pcb-board",
1008
1018
  d: path,
1009
1019
  fill: "none",
1010
- stroke: "rgba(255, 255, 255, 0.5)",
1020
+ stroke: colorMap2.boardOutline,
1011
1021
  "stroke-width": (0.1 * Math.abs(transform.a)).toString()
1012
1022
  }
1013
1023
  }
@@ -1017,7 +1027,7 @@ function createSvgObjectsFromPcbBoard(pcbBoard, ctx) {
1017
1027
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-via.ts
1018
1028
  import { applyToPoint as applyToPoint13 } from "transformation-matrix";
1019
1029
  function createSvgObjectsFromPcbVia(hole, ctx) {
1020
- const { transform } = ctx;
1030
+ const { transform, colorMap: colorMap2 } = ctx;
1021
1031
  const [x, y] = applyToPoint13(transform, [hole.x, hole.y]);
1022
1032
  const scaledOuterWidth = hole.outer_diameter * Math.abs(transform.a);
1023
1033
  const scaledOuterHeight = hole.outer_diameter * Math.abs(transform.a);
@@ -1034,7 +1044,7 @@ function createSvgObjectsFromPcbVia(hole, ctx) {
1034
1044
  type: "element",
1035
1045
  attributes: {
1036
1046
  class: "pcb-hole-outer",
1037
- fill: "rgb(200, 52, 52)",
1047
+ fill: colorMap2.copper.top,
1038
1048
  cx: x.toString(),
1039
1049
  cy: y.toString(),
1040
1050
  r: outerRadius.toString()
@@ -1045,7 +1055,7 @@ function createSvgObjectsFromPcbVia(hole, ctx) {
1045
1055
  type: "element",
1046
1056
  attributes: {
1047
1057
  class: "pcb-hole-inner",
1048
- fill: "rgb(255, 38, 226)",
1058
+ fill: colorMap2.drill,
1049
1059
  cx: x.toString(),
1050
1060
  cy: y.toString(),
1051
1061
  r: innerRadius.toString()
@@ -1058,7 +1068,7 @@ function createSvgObjectsFromPcbVia(hole, ctx) {
1058
1068
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-hole.ts
1059
1069
  import { applyToPoint as applyToPoint14 } from "transformation-matrix";
1060
1070
  function createSvgObjectsFromPcbHole(hole, ctx) {
1061
- const { transform } = ctx;
1071
+ const { transform, colorMap: colorMap2 } = ctx;
1062
1072
  const [x, y] = applyToPoint14(transform, [hole.x, hole.y]);
1063
1073
  if (hole.hole_shape === "circle" || hole.hole_shape === "square") {
1064
1074
  const scaledDiameter = hole.hole_diameter * Math.abs(transform.a);
@@ -1073,7 +1083,7 @@ function createSvgObjectsFromPcbHole(hole, ctx) {
1073
1083
  cx: x.toString(),
1074
1084
  cy: y.toString(),
1075
1085
  r: radius.toString(),
1076
- fill: HOLE_COLOR
1086
+ fill: colorMap2.drill
1077
1087
  },
1078
1088
  children: [],
1079
1089
  value: ""
@@ -1090,7 +1100,7 @@ function createSvgObjectsFromPcbHole(hole, ctx) {
1090
1100
  y: (y - radius).toString(),
1091
1101
  width: scaledDiameter.toString(),
1092
1102
  height: scaledDiameter.toString(),
1093
- fill: HOLE_COLOR
1103
+ fill: colorMap2.drill
1094
1104
  },
1095
1105
  children: [],
1096
1106
  value: ""
@@ -1112,7 +1122,7 @@ function createSvgObjectsFromPcbHole(hole, ctx) {
1112
1122
  cy: y.toString(),
1113
1123
  rx: rx.toString(),
1114
1124
  ry: ry.toString(),
1115
- fill: HOLE_COLOR
1125
+ fill: colorMap2.drill
1116
1126
  },
1117
1127
  children: [],
1118
1128
  value: ""
@@ -1244,7 +1254,7 @@ import {
1244
1254
  toString as matrixToString6
1245
1255
  } from "transformation-matrix";
1246
1256
  function createSvgObjectsFromPcbCutout(cutout, ctx) {
1247
- const { transform } = ctx;
1257
+ const { transform, colorMap: colorMap2 } = ctx;
1248
1258
  if (cutout.shape === "rect") {
1249
1259
  const rectCutout = cutout;
1250
1260
  const [cx, cy] = applyToPoint16(transform, [
@@ -1264,7 +1274,7 @@ function createSvgObjectsFromPcbCutout(cutout, ctx) {
1264
1274
  y: (-scaledHeight / 2).toString(),
1265
1275
  width: scaledWidth.toString(),
1266
1276
  height: scaledHeight.toString(),
1267
- fill: HOLE_COLOR,
1277
+ fill: colorMap2.drill,
1268
1278
  transform: matrixToString6(
1269
1279
  compose3(translate3(cx, cy), rotate3(svgRotation * Math.PI / 180))
1270
1280
  )
@@ -1290,7 +1300,7 @@ function createSvgObjectsFromPcbCutout(cutout, ctx) {
1290
1300
  cx: cx.toString(),
1291
1301
  cy: cy.toString(),
1292
1302
  r: scaledRadius.toString(),
1293
- fill: HOLE_COLOR
1303
+ fill: colorMap2.drill
1294
1304
  },
1295
1305
  children: [],
1296
1306
  value: ""
@@ -1311,7 +1321,7 @@ function createSvgObjectsFromPcbCutout(cutout, ctx) {
1311
1321
  attributes: {
1312
1322
  class: "pcb-cutout pcb-cutout-polygon",
1313
1323
  points: pointsString,
1314
- fill: HOLE_COLOR
1324
+ fill: colorMap2.drill
1315
1325
  },
1316
1326
  children: [],
1317
1327
  value: ""
@@ -1337,7 +1347,21 @@ var OBJECT_ORDER = [
1337
1347
  "pcb_board"
1338
1348
  ];
1339
1349
  function convertCircuitJsonToPcbSvg(circuitJson, options) {
1350
+ const drawPaddingOutsideBoard = options?.drawPaddingOutsideBoard ?? true;
1340
1351
  const layer = options?.layer;
1352
+ const colorOverrides = options?.colorOverrides;
1353
+ const colorMap2 = {
1354
+ copper: {
1355
+ top: colorOverrides?.copper?.top ?? DEFAULT_PCB_COLOR_MAP.copper.top,
1356
+ bottom: colorOverrides?.copper?.bottom ?? DEFAULT_PCB_COLOR_MAP.copper.bottom
1357
+ },
1358
+ drill: colorOverrides?.drill ?? DEFAULT_PCB_COLOR_MAP.drill,
1359
+ silkscreen: {
1360
+ top: colorOverrides?.silkscreen?.top ?? DEFAULT_PCB_COLOR_MAP.silkscreen.top,
1361
+ bottom: colorOverrides?.silkscreen?.bottom ?? DEFAULT_PCB_COLOR_MAP.silkscreen.bottom
1362
+ },
1363
+ boardOutline: colorOverrides?.boardOutline ?? DEFAULT_PCB_COLOR_MAP.boardOutline
1364
+ };
1341
1365
  let minX = Number.POSITIVE_INFINITY;
1342
1366
  let minY = Number.POSITIVE_INFINITY;
1343
1367
  let maxX = Number.NEGATIVE_INFINITY;
@@ -1371,7 +1395,7 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
1371
1395
  updateSilkscreenBounds(circuitJsonElm);
1372
1396
  }
1373
1397
  }
1374
- const padding = 1;
1398
+ const padding = drawPaddingOutsideBoard ? 1 : 0;
1375
1399
  const circuitWidth = maxX - minX + 2 * padding;
1376
1400
  const circuitHeight = maxY - minY + 2 * padding;
1377
1401
  let svgWidth = options?.width ?? 800;
@@ -1412,7 +1436,9 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
1412
1436
  const ctx = {
1413
1437
  transform,
1414
1438
  layer,
1415
- shouldDrawErrors: options?.shouldDrawErrors
1439
+ shouldDrawErrors: options?.shouldDrawErrors,
1440
+ drawPaddingOutsideBoard,
1441
+ colorMap: colorMap2
1416
1442
  };
1417
1443
  let svgObjects = circuitJson.sort(
1418
1444
  (a, b) => (OBJECT_ORDER.indexOf(b.type) ?? 9999) - (OBJECT_ORDER.indexOf(a.type) ?? 9999)
@@ -1428,6 +1454,43 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
1428
1454
  const ratsNestObjects = createSvgObjectsForRatsNest(circuitJson, ctx);
1429
1455
  svgObjects = svgObjects.concat(ratsNestObjects);
1430
1456
  }
1457
+ const children = [
1458
+ {
1459
+ name: "style",
1460
+ type: "element",
1461
+ value: "",
1462
+ attributes: {},
1463
+ children: [
1464
+ {
1465
+ type: "text",
1466
+ value: "",
1467
+ name: "",
1468
+ attributes: {},
1469
+ children: []
1470
+ }
1471
+ ]
1472
+ },
1473
+ {
1474
+ name: "rect",
1475
+ type: "element",
1476
+ value: "",
1477
+ attributes: {
1478
+ class: "boundary",
1479
+ x: "0",
1480
+ y: "0",
1481
+ fill: options?.backgroundColor ?? "#000",
1482
+ width: svgWidth.toString(),
1483
+ height: svgHeight.toString()
1484
+ },
1485
+ children: []
1486
+ }
1487
+ ];
1488
+ if (drawPaddingOutsideBoard) {
1489
+ children.push(
1490
+ createSvgObjectFromPcbBoundary(transform, minX, minY, maxX, maxY)
1491
+ );
1492
+ }
1493
+ children.push(...svgObjects);
1431
1494
  const svgObject = {
1432
1495
  name: "svg",
1433
1496
  type: "element",
@@ -1437,32 +1500,7 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
1437
1500
  height: svgHeight.toString()
1438
1501
  },
1439
1502
  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)
1503
+ children: children.filter((child) => child !== null)
1466
1504
  };
1467
1505
  try {
1468
1506
  return stringify(svgObject);
@@ -1570,7 +1608,7 @@ function createSvgObjects({
1570
1608
  case "pcb_silkscreen_path":
1571
1609
  return createSvgObjectsFromPcbSilkscreenPath(elm, ctx);
1572
1610
  case "pcb_board":
1573
- return createSvgObjectsFromPcbBoard(elm, ctx);
1611
+ return ctx.drawPaddingOutsideBoard ? createSvgObjectsFromPcbBoard(elm, ctx) : [];
1574
1612
  case "pcb_via":
1575
1613
  return createSvgObjectsFromPcbVia(elm, ctx);
1576
1614
  case "pcb_cutout":
@@ -5125,7 +5163,8 @@ function convertCircuitJsonToSolderPasteMask(circuitJson, options) {
5125
5163
  );
5126
5164
  const ctx = {
5127
5165
  transform,
5128
- layer: options.layer
5166
+ layer: options.layer,
5167
+ colorMap: DEFAULT_PCB_COLOR_MAP
5129
5168
  };
5130
5169
  const svgObjects = filteredCircuitJson.sort(
5131
5170
  (a, b) => (OBJECT_ORDER3.indexOf(b.type) ?? 9999) - (OBJECT_ORDER3.indexOf(a.type) ?? 9999)