circuit-to-svg 0.0.108 → 0.0.110

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
@@ -220,6 +220,7 @@ function createSvgObjectsFromPcbPlatedHole(hole, transform) {
220
220
  type: "element",
221
221
  attributes: {
222
222
  class: "pcb-hole-outer",
223
+ fill: "rgb(200, 52, 52)",
223
224
  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`
224
225
  },
225
226
  value: "",
@@ -231,6 +232,7 @@ function createSvgObjectsFromPcbPlatedHole(hole, transform) {
231
232
  type: "element",
232
233
  attributes: {
233
234
  class: "pcb-hole-inner",
235
+ fill: "rgb(255, 38, 226)",
234
236
  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`
235
237
  },
236
238
  value: "",
@@ -259,6 +261,7 @@ function createSvgObjectsFromPcbPlatedHole(hole, transform) {
259
261
  type: "element",
260
262
  attributes: {
261
263
  class: "pcb-hole-outer",
264
+ fill: "rgb(200, 52, 52)",
262
265
  cx: x.toString(),
263
266
  cy: y.toString(),
264
267
  r: outerRadius.toString()
@@ -271,6 +274,7 @@ function createSvgObjectsFromPcbPlatedHole(hole, transform) {
271
274
  type: "element",
272
275
  attributes: {
273
276
  class: "pcb-hole-inner",
277
+ fill: "rgb(255, 38, 226)",
274
278
  cx: x.toString(),
275
279
  cy: y.toString(),
276
280
  r: innerRadius.toString()
@@ -333,7 +337,8 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, transform) {
333
337
  text,
334
338
  font_size = 1,
335
339
  layer = "top",
336
- ccw_rotation = 0
340
+ ccw_rotation = 0,
341
+ stroke_width = 0
337
342
  } = pcbSilkscreenText;
338
343
  if (!anchor_position || typeof anchor_position.x !== "number" || typeof anchor_position.y !== "number") {
339
344
  console.error("Invalid anchor_position:", anchor_position);
@@ -344,10 +349,10 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, transform) {
344
349
  anchor_position.y
345
350
  ]);
346
351
  const transformedFontSize = font_size * Math.abs(transform.a);
352
+ const transformedStrokeWidth = stroke_width * Math.abs(transform.a);
347
353
  const textTransform = compose2(
348
354
  translate2(transformedX, transformedY),
349
355
  rotate2(ccw_rotation * Math.PI / 180)
350
- // Convert degrees to radians
351
356
  );
352
357
  const svgObject = {
353
358
  name: "text",
@@ -362,7 +367,9 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, transform) {
362
367
  "dominant-baseline": "central",
363
368
  transform: matrixToString2(textTransform),
364
369
  class: `pcb-silkscreen-text pcb-silkscreen-${layer}`,
365
- "data-pcb-silkscreen-text-id": pcbSilkscreenText.pcb_component_id
370
+ "data-pcb-silkscreen-text-id": pcbSilkscreenText.pcb_component_id,
371
+ stroke: "#f2eda1",
372
+ "stroke-width": transformedStrokeWidth.toString()
366
373
  },
367
374
  children: [
368
375
  {
@@ -388,7 +395,8 @@ function createSvgObjectsFromPcbSilkscreenRect(pcbSilkscreenRect, transform) {
388
395
  width,
389
396
  height,
390
397
  layer = "top",
391
- pcb_silkscreen_rect_id
398
+ pcb_silkscreen_rect_id,
399
+ stroke_width = 1
392
400
  } = pcbSilkscreenRect;
393
401
  if (!center || typeof center.x !== "number" || typeof center.y !== "number" || typeof width !== "number" || typeof height !== "number") {
394
402
  console.error("Invalid rectangle data:", { center, width, height });
@@ -400,6 +408,7 @@ function createSvgObjectsFromPcbSilkscreenRect(pcbSilkscreenRect, transform) {
400
408
  ]);
401
409
  const transformedWidth = width * Math.abs(transform.a);
402
410
  const transformedHeight = height * Math.abs(transform.d);
411
+ const transformedStrokeWidth = stroke_width * Math.abs(transform.a);
403
412
  const svgObject = {
404
413
  name: "rect",
405
414
  type: "element",
@@ -411,7 +420,7 @@ function createSvgObjectsFromPcbSilkscreenRect(pcbSilkscreenRect, transform) {
411
420
  class: `pcb-silkscreen-rect pcb-silkscreen-${layer}`,
412
421
  fill: "none",
413
422
  stroke: "#f2eda1",
414
- "stroke-width": "1",
423
+ "stroke-width": transformedStrokeWidth.toString(),
415
424
  "data-pcb-silkscreen-rect-id": pcb_silkscreen_rect_id
416
425
  },
417
426
  value: "",
@@ -429,7 +438,8 @@ function createSvgObjectsFromPcbSilkscreenCircle(pcbSilkscreenCircle, transform)
429
438
  center,
430
439
  radius,
431
440
  layer = "top",
432
- pcb_silkscreen_circle_id
441
+ pcb_silkscreen_circle_id,
442
+ stroke_width = 1
433
443
  } = pcbSilkscreenCircle;
434
444
  if (!center || typeof center.x !== "number" || typeof center.y !== "number" || typeof radius !== "number") {
435
445
  console.error("Invalid PCB Silkscreen Circle data:", { center, radius });
@@ -440,6 +450,7 @@ function createSvgObjectsFromPcbSilkscreenCircle(pcbSilkscreenCircle, transform)
440
450
  center.y
441
451
  ]);
442
452
  const transformedRadius = radius * Math.abs(transform.a);
453
+ const transformedStrokeWidth = stroke_width * Math.abs(transform.a);
443
454
  const svgObject = {
444
455
  name: "circle",
445
456
  type: "element",
@@ -449,7 +460,7 @@ function createSvgObjectsFromPcbSilkscreenCircle(pcbSilkscreenCircle, transform)
449
460
  r: transformedRadius.toString(),
450
461
  class: `pcb-silkscreen-circle pcb-silkscreen-${layer}`,
451
462
  stroke: "#f2eda1",
452
- "stroke-width": "1",
463
+ "stroke-width": transformedStrokeWidth.toString(),
453
464
  "data-pcb-silkscreen-circle-id": pcb_silkscreen_circle_id
454
465
  },
455
466
  value: "",
@@ -533,7 +544,7 @@ function createSvgObjectsFromPcbTrace(trace, transform) {
533
544
  if (!layer) continue;
534
545
  const layerColor = LAYER_NAME_TO_COLOR[layer] ?? "white";
535
546
  const traceWidth = "width" in start ? start.width : "width" in end ? end.width : null;
536
- svgObjects.push({
547
+ const svgObject = {
537
548
  name: "path",
538
549
  type: "element",
539
550
  value: "",
@@ -541,14 +552,28 @@ function createSvgObjectsFromPcbTrace(trace, transform) {
541
552
  attributes: {
542
553
  class: "pcb-trace",
543
554
  stroke: layerColor,
555
+ fill: "none",
544
556
  d: `M ${startPoint[0]} ${startPoint[1]} L ${endPoint[0]} ${endPoint[1]}`,
545
557
  "stroke-width": traceWidth ? (traceWidth * Math.abs(transform.a)).toString() : "0.3",
546
558
  "stroke-linecap": "round",
547
559
  "stroke-linejoin": "round",
548
- "shape-rendering": "crispEdges"
560
+ "shape-rendering": "crispEdges",
561
+ "data-layer": layer
549
562
  }
550
- });
563
+ };
564
+ svgObjects.push(svgObject);
551
565
  }
566
+ svgObjects.sort((a, b) => {
567
+ const layerA = a.attributes["data-layer"];
568
+ const layerB = b.attributes["data-layer"];
569
+ if (layerA === "bottom" && layerB !== "bottom") {
570
+ return -1;
571
+ }
572
+ if (layerA === "top" && layerB !== "top") {
573
+ return 1;
574
+ }
575
+ return 0;
576
+ });
552
577
  return svgObjects;
553
578
  }
554
579
 
@@ -656,6 +681,7 @@ function createSvgObjectsFromPcbBoard(pcbBoard, transform) {
656
681
  attributes: {
657
682
  class: "pcb-board",
658
683
  d: path,
684
+ fill: "none",
659
685
  stroke: "rgba(255, 255, 255, 0.5)",
660
686
  "stroke-width": (0.1 * Math.abs(transform.a)).toString()
661
687
  }
@@ -682,6 +708,7 @@ function createSvgObjectsFromPcbVia(hole, transform) {
682
708
  type: "element",
683
709
  attributes: {
684
710
  class: "pcb-hole-outer",
711
+ fill: "rgb(200, 52, 52)",
685
712
  cx: x.toString(),
686
713
  cy: y.toString(),
687
714
  r: outerRadius.toString()
@@ -692,6 +719,7 @@ function createSvgObjectsFromPcbVia(hole, transform) {
692
719
  type: "element",
693
720
  attributes: {
694
721
  class: "pcb-hole-inner",
722
+ fill: "rgb(255, 38, 226)",
695
723
  cx: x.toString(),
696
724
  cy: y.toString(),
697
725
  r: innerRadius.toString()
@@ -973,15 +1001,7 @@ function convertCircuitJsonToPcbSvg(soup, options) {
973
1001
  children: [
974
1002
  {
975
1003
  type: "text",
976
- value: `
977
- .boundary { fill: #000; }
978
- .pcb-board { fill: none; }
979
- .pcb-trace { fill: none; }
980
- .pcb-hole-outer { fill: rgb(200, 52, 52); }
981
- .pcb-hole-inner { fill: rgb(255, 38, 226); }
982
- .pcb-pad { }
983
- .pcb-boundary { fill: none; stroke: #fff; stroke-width: 0.3; }
984
- `
1004
+ value: ""
985
1005
  }
986
1006
  ]
987
1007
  },
@@ -992,6 +1012,7 @@ function convertCircuitJsonToPcbSvg(soup, options) {
992
1012
  class: "boundary",
993
1013
  x: "0",
994
1014
  y: "0",
1015
+ fill: "#000",
995
1016
  width: svgWidth.toString(),
996
1017
  height: svgHeight.toString()
997
1018
  }
@@ -1136,6 +1157,9 @@ function createSvgObjectFromPcbBoundary(transform, minX, minY, maxX, maxY) {
1136
1157
  children: [],
1137
1158
  attributes: {
1138
1159
  class: "pcb-boundary",
1160
+ fill: "none",
1161
+ stroke: "#fff",
1162
+ "stroke-width": "0.3",
1139
1163
  x: x.toString(),
1140
1164
  y: y.toString(),
1141
1165
  width: width.toString(),
@@ -1882,7 +1906,7 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
1882
1906
  const portSize = 0.2;
1883
1907
  for (const item of soup) {
1884
1908
  if (item.type === "schematic_component") {
1885
- updateBounds(item.center, item.size, item.rotation || 0);
1909
+ updateBounds(item.center, item.size, 0);
1886
1910
  } else if (item.type === "schematic_port") {
1887
1911
  updateBounds(item.center, { width: portSize, height: portSize }, 0);
1888
1912
  } else if (item.type === "schematic_debug_object") {