circuit-to-svg 0.0.137 → 0.0.139

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/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 = 1
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
  };
@@ -2454,7 +2473,10 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
2454
2473
  updateBounds(item.position, { width: 0.2, height: 0.4 }, 0);
2455
2474
  } else if (item.type === "schematic_box") {
2456
2475
  updateBounds(
2457
- { x: item.x, y: item.y },
2476
+ {
2477
+ x: item.x + item.width / 2,
2478
+ y: item.y + item.height / 2
2479
+ },
2458
2480
  { width: item.width, height: item.height },
2459
2481
  0
2460
2482
  );
@@ -4729,6 +4751,49 @@ var createSvgObjectsForSchNetLabel = ({
4729
4751
  return svgObjects;
4730
4752
  };
4731
4753
 
4754
+ // lib/sch/svg-object-fns/create-svg-objects-from-sch-box.ts
4755
+ import { applyToPoint as applyToPoint37 } from "transformation-matrix";
4756
+ var createSvgObjectsFromSchematicBox = ({
4757
+ schematicBox,
4758
+ transform,
4759
+ colorMap: colorMap2
4760
+ }) => {
4761
+ const topLeft = applyToPoint37(transform, {
4762
+ x: schematicBox.x,
4763
+ y: schematicBox.y
4764
+ });
4765
+ const bottomRight = applyToPoint37(transform, {
4766
+ x: schematicBox.x + schematicBox.width,
4767
+ y: schematicBox.y + schematicBox.height
4768
+ });
4769
+ const yTop = Math.min(topLeft.y, bottomRight.y);
4770
+ const yBottom = Math.max(topLeft.y, bottomRight.y);
4771
+ const xLeft = Math.min(topLeft.x, bottomRight.x);
4772
+ const xRight = Math.max(topLeft.x, bottomRight.x);
4773
+ const attributes = {
4774
+ class: "schematic-box",
4775
+ x: xLeft.toString(),
4776
+ y: yTop.toString(),
4777
+ width: (xRight - xLeft).toString(),
4778
+ height: (yBottom - yTop).toString(),
4779
+ "stroke-width": "2px",
4780
+ stroke: colorMap2.schematic.component_outline || "black",
4781
+ fill: "transparent"
4782
+ };
4783
+ if (schematicBox.is_dashed) {
4784
+ attributes["stroke-dasharray"] = "20 8";
4785
+ }
4786
+ return [
4787
+ {
4788
+ name: "rect",
4789
+ type: "element",
4790
+ value: "",
4791
+ attributes,
4792
+ children: []
4793
+ }
4794
+ ];
4795
+ };
4796
+
4732
4797
  // lib/sch/convert-circuit-json-to-schematic-svg.ts
4733
4798
  function convertCircuitJsonToSchematicSvg(circuitJson, options) {
4734
4799
  const realBounds = getSchematicBoundsFromCircuitJson(circuitJson);
@@ -4798,6 +4863,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
4798
4863
  const schNetLabel = [];
4799
4864
  const schText = [];
4800
4865
  const voltageProbeSvgs = [];
4866
+ const schBoxSvgs = [];
4801
4867
  for (const elm of circuitJson) {
4802
4868
  if (elm.type === "schematic_debug_object") {
4803
4869
  schDebugObjectSvgs.push(
@@ -4815,6 +4881,14 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
4815
4881
  colorMap: colorMap2
4816
4882
  })
4817
4883
  );
4884
+ } else if (elm.type === "schematic_box") {
4885
+ schBoxSvgs.push(
4886
+ ...createSvgObjectsFromSchematicBox({
4887
+ schematicBox: elm,
4888
+ transform,
4889
+ colorMap: colorMap2
4890
+ })
4891
+ );
4818
4892
  } else if (elm.type === "schematic_trace") {
4819
4893
  schTraceSvgs.push(
4820
4894
  ...createSchematicTrace({
@@ -4855,6 +4929,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
4855
4929
  ...schTraceSvgs,
4856
4930
  ...schNetLabel,
4857
4931
  ...schText,
4932
+ ...schBoxSvgs,
4858
4933
  ...voltageProbeSvgs
4859
4934
  );
4860
4935
  if (options?.labeledPoints) {
@@ -4921,18 +4996,18 @@ var circuitJsonToSchematicSvg = convertCircuitJsonToSchematicSvg;
4921
4996
  // lib/pcb/convert-circuit-json-to-solder-paste-mask.ts
4922
4997
  import { stringify as stringify4 } from "svgson";
4923
4998
  import {
4924
- applyToPoint as applyToPoint39,
4999
+ applyToPoint as applyToPoint40,
4925
5000
  compose as compose11,
4926
5001
  scale as scale8,
4927
5002
  translate as translate11
4928
5003
  } from "transformation-matrix";
4929
5004
 
4930
5005
  // lib/pcb/svg-object-fns/convert-circuit-json-to-solder-paste-mask.ts
4931
- import { applyToPoint as applyToPoint38 } from "transformation-matrix";
5006
+ import { applyToPoint as applyToPoint39 } from "transformation-matrix";
4932
5007
  function createSvgObjectsFromSolderPaste(solderPaste, ctx) {
4933
5008
  const { transform, layer: layerFilter } = ctx;
4934
5009
  if (layerFilter && solderPaste.layer !== layerFilter) return [];
4935
- const [x, y] = applyToPoint38(transform, [solderPaste.x, solderPaste.y]);
5010
+ const [x, y] = applyToPoint39(transform, [solderPaste.x, solderPaste.y]);
4936
5011
  if (solderPaste.shape === "rect" || solderPaste.shape === "rotated_rect") {
4937
5012
  const width = solderPaste.width * Math.abs(transform.a);
4938
5013
  const height = solderPaste.height * Math.abs(transform.d);
@@ -5126,8 +5201,8 @@ function createSvgObjects3({ elm, ctx }) {
5126
5201
  }
5127
5202
  }
5128
5203
  function createSvgObjectFromPcbBoundary2(transform, minX, minY, maxX, maxY) {
5129
- const [x1, y1] = applyToPoint39(transform, [minX, minY]);
5130
- const [x2, y2] = applyToPoint39(transform, [maxX, maxY]);
5204
+ const [x1, y1] = applyToPoint40(transform, [minX, minY]);
5205
+ const [x2, y2] = applyToPoint40(transform, [maxX, maxY]);
5131
5206
  const width = Math.abs(x2 - x1);
5132
5207
  const height = Math.abs(y2 - y1);
5133
5208
  const x = Math.min(x1, x2);