circuit-to-svg 0.0.138 → 0.0.140
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 +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -55,6 +55,8 @@ Converts a PCB layout description to an SVG string.
|
|
|
55
55
|
- `width` and `height` – dimensions of the output SVG. Defaults to `800x600`.
|
|
56
56
|
- `matchBoardAspectRatio` – if `true`, adjust the SVG dimensions so the
|
|
57
57
|
resulting aspect ratio matches the `pcb_board` found in the circuit JSON.
|
|
58
|
+
- `backgroundColor` – fill color for the SVG background rectangle. Defaults to
|
|
59
|
+
`"#000"`.
|
|
58
60
|
|
|
59
61
|
## Contributing
|
|
60
62
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -686,7 +686,10 @@ function createSvgObjectsFromPcbSilkscreenRect(pcbSilkscreenRect, ctx) {
|
|
|
686
686
|
height,
|
|
687
687
|
layer = "top",
|
|
688
688
|
pcb_silkscreen_rect_id,
|
|
689
|
-
stroke_width
|
|
689
|
+
stroke_width,
|
|
690
|
+
is_filled,
|
|
691
|
+
has_stroke,
|
|
692
|
+
is_stroke_dashed
|
|
690
693
|
} = pcbSilkscreenRect;
|
|
691
694
|
if (layerFilter && layer !== layerFilter) return [];
|
|
692
695
|
if (!center || typeof center.x !== "number" || typeof center.y !== "number" || typeof width !== "number" || typeof height !== "number") {
|
|
@@ -701,20 +704,36 @@ function createSvgObjectsFromPcbSilkscreenRect(pcbSilkscreenRect, ctx) {
|
|
|
701
704
|
const transformedHeight = height * Math.abs(transform.d);
|
|
702
705
|
const transformedStrokeWidth = stroke_width * Math.abs(transform.a);
|
|
703
706
|
const color = layer === "bottom" ? SILKSCREEN_BOTTOM_COLOR : SILKSCREEN_TOP_COLOR;
|
|
707
|
+
const attributes = {
|
|
708
|
+
x: (transformedX - transformedWidth / 2).toString(),
|
|
709
|
+
y: (transformedY - transformedHeight / 2).toString(),
|
|
710
|
+
width: transformedWidth.toString(),
|
|
711
|
+
height: transformedHeight.toString(),
|
|
712
|
+
class: `pcb-silkscreen-rect pcb-silkscreen-${layer}`,
|
|
713
|
+
"data-pcb-silkscreen-rect-id": pcb_silkscreen_rect_id
|
|
714
|
+
};
|
|
715
|
+
attributes.fill = is_filled ? color : "none";
|
|
716
|
+
let actualHasStroke;
|
|
717
|
+
if (has_stroke === void 0) {
|
|
718
|
+
actualHasStroke = transformedStrokeWidth > 0;
|
|
719
|
+
} else {
|
|
720
|
+
actualHasStroke = has_stroke;
|
|
721
|
+
}
|
|
722
|
+
if (actualHasStroke) {
|
|
723
|
+
attributes.stroke = color;
|
|
724
|
+
attributes["stroke-width"] = transformedStrokeWidth.toString();
|
|
725
|
+
if (is_stroke_dashed) {
|
|
726
|
+
const dashLength = 0.1 * Math.abs(transform.a);
|
|
727
|
+
const gapLength = 0.05 * Math.abs(transform.a);
|
|
728
|
+
attributes["stroke-dasharray"] = `${dashLength} ${gapLength}`;
|
|
729
|
+
}
|
|
730
|
+
} else {
|
|
731
|
+
attributes.stroke = "none";
|
|
732
|
+
}
|
|
704
733
|
const svgObject = {
|
|
705
734
|
name: "rect",
|
|
706
735
|
type: "element",
|
|
707
|
-
attributes
|
|
708
|
-
x: (transformedX - transformedWidth / 2).toString(),
|
|
709
|
-
y: (transformedY - transformedHeight / 2).toString(),
|
|
710
|
-
width: transformedWidth.toString(),
|
|
711
|
-
height: transformedHeight.toString(),
|
|
712
|
-
class: `pcb-silkscreen-rect pcb-silkscreen-${layer}`,
|
|
713
|
-
fill: "none",
|
|
714
|
-
stroke: color,
|
|
715
|
-
"stroke-width": transformedStrokeWidth.toString(),
|
|
716
|
-
"data-pcb-silkscreen-rect-id": pcb_silkscreen_rect_id
|
|
717
|
-
},
|
|
736
|
+
attributes,
|
|
718
737
|
value: "",
|
|
719
738
|
children: []
|
|
720
739
|
};
|
|
@@ -1436,7 +1455,7 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
1436
1455
|
class: "boundary",
|
|
1437
1456
|
x: "0",
|
|
1438
1457
|
y: "0",
|
|
1439
|
-
fill: "#000",
|
|
1458
|
+
fill: options?.backgroundColor ?? "#000",
|
|
1440
1459
|
width: svgWidth.toString(),
|
|
1441
1460
|
height: svgHeight.toString()
|
|
1442
1461
|
}
|