circuit-to-svg 0.0.313 → 0.0.315

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
@@ -3405,6 +3405,14 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
3405
3405
  const [x, y] = applyToPoint24(transform, [pad.x, pad.y]);
3406
3406
  const cornerRadiusValue = pad.corner_radius ?? pad.rect_border_radius ?? 0;
3407
3407
  const scaledBorderRadius = cornerRadiusValue * Math.abs(transform.a);
3408
+ const m = {
3409
+ left: (pad.soldermask_margin_left ?? pad.soldermask_margin ?? 0) * Math.abs(transform.a),
3410
+ right: (pad.soldermask_margin_right ?? pad.soldermask_margin ?? 0) * Math.abs(transform.a),
3411
+ top: (pad.soldermask_margin_top ?? pad.soldermask_margin ?? 0) * Math.abs(transform.a),
3412
+ bottom: (pad.soldermask_margin_bottom ?? pad.soldermask_margin ?? 0) * Math.abs(transform.a)
3413
+ };
3414
+ const isNegativeMargin = m.left < 0 || m.right < 0 || m.top < 0 || m.bottom < 0;
3415
+ const isZeroMargin = m.left === 0 && m.right === 0 && m.top === 0 && m.bottom === 0;
3408
3416
  if (pad.shape === "rotated_rect" && pad.ccw_rotation) {
3409
3417
  const padElement2 = {
3410
3418
  name: "rect",
@@ -3430,10 +3438,10 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
3430
3438
  if (!shouldShowSolderMask) {
3431
3439
  return [padElement2];
3432
3440
  }
3433
- const maskWidth2 = width + 2 * soldermaskMargin;
3434
- const maskHeight2 = height + 2 * soldermaskMargin;
3441
+ const maskWidth2 = width + m.left + m.right;
3442
+ const maskHeight2 = height + m.top + m.bottom;
3435
3443
  const maskBorderRadius2 = scaledBorderRadius ? scaledBorderRadius + soldermaskMargin : 0;
3436
- if (soldermaskMargin < 0) {
3444
+ if (isNegativeMargin) {
3437
3445
  const coveredPadElement = {
3438
3446
  name: "rect",
3439
3447
  type: "element",
@@ -3463,8 +3471,8 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
3463
3471
  attributes: {
3464
3472
  class: "pcb-pad-exposed",
3465
3473
  fill: layerNameToColor(pad.layer, colorMap2),
3466
- x: (-maskWidth2 / 2).toString(),
3467
- y: (-maskHeight2 / 2).toString(),
3474
+ x: (-width / 2 - m.left).toString(),
3475
+ y: (-height / 2 - m.top).toString(),
3468
3476
  width: maskWidth2.toString(),
3469
3477
  height: maskHeight2.toString(),
3470
3478
  transform: `translate(${x} ${y}) rotate(${-pad.ccw_rotation})`,
@@ -3478,7 +3486,7 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
3478
3486
  };
3479
3487
  return [coveredPadElement, exposedOpeningElement];
3480
3488
  }
3481
- if (soldermaskMargin === 0) {
3489
+ if (isZeroMargin) {
3482
3490
  const coveredPadElement = {
3483
3491
  name: "rect",
3484
3492
  type: "element",
@@ -3510,8 +3518,8 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
3510
3518
  attributes: {
3511
3519
  class: "pcb-soldermask-cutout",
3512
3520
  fill: colorMap2.substrate,
3513
- x: (-maskWidth2 / 2).toString(),
3514
- y: (-maskHeight2 / 2).toString(),
3521
+ x: (-width / 2 - m.left).toString(),
3522
+ y: (-height / 2 - m.top).toString(),
3515
3523
  width: maskWidth2.toString(),
3516
3524
  height: maskHeight2.toString(),
3517
3525
  transform: `translate(${x} ${y}) rotate(${-pad.ccw_rotation})`,
@@ -3548,10 +3556,10 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
3548
3556
  if (!shouldShowSolderMask) {
3549
3557
  return [padElement];
3550
3558
  }
3551
- const maskWidth = width + 2 * soldermaskMargin;
3552
- const maskHeight = height + 2 * soldermaskMargin;
3559
+ const maskWidth = width + m.left + m.right;
3560
+ const maskHeight = height + m.top + m.bottom;
3553
3561
  const maskBorderRadius = scaledBorderRadius ? scaledBorderRadius + soldermaskMargin : 0;
3554
- if (soldermaskMargin < 0) {
3562
+ if (isNegativeMargin) {
3555
3563
  const coveredPadElement = {
3556
3564
  name: "rect",
3557
3565
  type: "element",
@@ -3580,8 +3588,8 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
3580
3588
  attributes: {
3581
3589
  class: "pcb-pad-exposed",
3582
3590
  fill: layerNameToColor(pad.layer, colorMap2),
3583
- x: (x - maskWidth / 2).toString(),
3584
- y: (y - maskHeight / 2).toString(),
3591
+ x: (x - width / 2 - m.left).toString(),
3592
+ y: (y - height / 2 - m.top).toString(),
3585
3593
  width: maskWidth.toString(),
3586
3594
  height: maskHeight.toString(),
3587
3595
  "data-type": "pcb_soldermask",
@@ -3594,7 +3602,7 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
3594
3602
  };
3595
3603
  return [coveredPadElement, exposedOpeningElement];
3596
3604
  }
3597
- if (soldermaskMargin === 0) {
3605
+ if (isZeroMargin) {
3598
3606
  const coveredPadElement = {
3599
3607
  name: "rect",
3600
3608
  type: "element",
@@ -3625,8 +3633,8 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
3625
3633
  attributes: {
3626
3634
  class: "pcb-soldermask-cutout",
3627
3635
  fill: colorMap2.substrate,
3628
- x: (x - maskWidth / 2).toString(),
3629
- y: (y - maskHeight / 2).toString(),
3636
+ x: (x - width / 2 - m.left).toString(),
3637
+ y: (y - height / 2 - m.top).toString(),
3630
3638
  width: maskWidth.toString(),
3631
3639
  height: maskHeight.toString(),
3632
3640
  ...maskBorderRadius > 0 ? {
@@ -6034,7 +6042,7 @@ function getSoftwareUsedString(circuitJson) {
6034
6042
  var package_default = {
6035
6043
  name: "circuit-to-svg",
6036
6044
  type: "module",
6037
- version: "0.0.312",
6045
+ version: "0.0.314",
6038
6046
  description: "Convert Circuit JSON to SVG",
6039
6047
  main: "dist/index.js",
6040
6048
  files: [
@@ -6057,7 +6065,7 @@ var package_default = {
6057
6065
  "@vitejs/plugin-react": "5.0.0",
6058
6066
  biome: "^0.3.3",
6059
6067
  "bun-match-svg": "^0.0.12",
6060
- "circuit-json": "^0.0.351",
6068
+ "circuit-json": "^0.0.356",
6061
6069
  esbuild: "^0.20.2",
6062
6070
  "performance-now": "^2.1.0",
6063
6071
  react: "19.1.0",
@@ -10487,6 +10495,10 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
10487
10495
  { width: item.radius * 2, height: item.radius * 2 },
10488
10496
  0
10489
10497
  );
10498
+ } else if (item.type === "schematic_path") {
10499
+ for (const point of item.points) {
10500
+ updateBounds(point, { width: 0.02, height: 0.02 }, 0);
10501
+ }
10490
10502
  }
10491
10503
  }
10492
10504
  minX -= padding;
@@ -12683,6 +12695,44 @@ function createSvgObjectsFromSchematicArc({
12683
12695
  ];
12684
12696
  }
12685
12697
 
12698
+ // lib/sch/svg-object-fns/create-svg-objects-from-sch-path.ts
12699
+ import { applyToPoint as applyToPoint75 } from "transformation-matrix";
12700
+ function createSvgObjectsFromSchematicPath({
12701
+ schPath,
12702
+ transform,
12703
+ colorMap: colorMap2
12704
+ }) {
12705
+ if (!schPath.points || schPath.points.length < 2) {
12706
+ return [];
12707
+ }
12708
+ const transformedPoints = schPath.points.map(
12709
+ (p) => applyToPoint75(transform, { x: p.x, y: p.y })
12710
+ );
12711
+ const pathD = transformedPoints.map((p, i) => `${i === 0 ? "M" : "L"} ${p.x} ${p.y}`).join(" ");
12712
+ const strokeColor = colorMap2.schematic.component_outline;
12713
+ const fillColor = schPath.fill_color ?? "none";
12714
+ const strokeWidth = Math.abs(transform.a) * 0.02;
12715
+ return [
12716
+ {
12717
+ name: "path",
12718
+ type: "element",
12719
+ attributes: {
12720
+ d: pathD,
12721
+ stroke: strokeColor,
12722
+ "stroke-width": strokeWidth.toString(),
12723
+ fill: schPath.is_filled ? fillColor : "none",
12724
+ "stroke-linecap": "round",
12725
+ "stroke-linejoin": "round",
12726
+ ...schPath.schematic_component_id && {
12727
+ "data-schematic-component-id": schPath.schematic_component_id
12728
+ }
12729
+ },
12730
+ children: [],
12731
+ value: ""
12732
+ }
12733
+ ];
12734
+ }
12735
+
12686
12736
  // lib/sch/convert-circuit-json-to-schematic-svg.ts
12687
12737
  function buildNetHoverStyles(connectivityKeys) {
12688
12738
  const rules = [];
@@ -12777,6 +12827,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
12777
12827
  const schCircleSvgs = [];
12778
12828
  const schRectSvgs = [];
12779
12829
  const schArcSvgs = [];
12830
+ const schPathSvgs = [];
12780
12831
  for (const elm of circuitJson) {
12781
12832
  if (elm.type === "schematic_debug_object") {
12782
12833
  schDebugObjectSvgs.push(
@@ -12883,6 +12934,14 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
12883
12934
  colorMap: colorMap2
12884
12935
  })
12885
12936
  );
12937
+ } else if (elm.type === "schematic_path") {
12938
+ schPathSvgs.push(
12939
+ ...createSvgObjectsFromSchematicPath({
12940
+ schPath: elm,
12941
+ transform,
12942
+ colorMap: colorMap2
12943
+ })
12944
+ );
12886
12945
  }
12887
12946
  }
12888
12947
  const schTraceBaseSvgs = schTraceSvgs.filter(
@@ -12899,6 +12958,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
12899
12958
  ...schCircleSvgs,
12900
12959
  ...schRectSvgs,
12901
12960
  ...schArcSvgs,
12961
+ ...schPathSvgs,
12902
12962
  ...schComponentSvgs,
12903
12963
  ...schPortHoverSvgs,
12904
12964
  ...schNetLabel,
@@ -13760,18 +13820,18 @@ function formatNumber2(value) {
13760
13820
  import { distance as distance5 } from "circuit-json";
13761
13821
  import { stringify as stringify7 } from "svgson";
13762
13822
  import {
13763
- applyToPoint as applyToPoint77,
13823
+ applyToPoint as applyToPoint78,
13764
13824
  compose as compose16,
13765
13825
  scale as scale9,
13766
13826
  translate as translate16
13767
13827
  } from "transformation-matrix";
13768
13828
 
13769
13829
  // lib/pcb/svg-object-fns/convert-circuit-json-to-solder-paste-mask.ts
13770
- import { applyToPoint as applyToPoint76 } from "transformation-matrix";
13830
+ import { applyToPoint as applyToPoint77 } from "transformation-matrix";
13771
13831
  function createSvgObjectsFromSolderPaste(solderPaste, ctx) {
13772
13832
  const { transform, layer: layerFilter } = ctx;
13773
13833
  if (layerFilter && solderPaste.layer !== layerFilter) return [];
13774
- const [x, y] = applyToPoint76(transform, [solderPaste.x, solderPaste.y]);
13834
+ const [x, y] = applyToPoint77(transform, [solderPaste.x, solderPaste.y]);
13775
13835
  if (solderPaste.shape === "rect" || solderPaste.shape === "rotated_rect") {
13776
13836
  const width = solderPaste.width * Math.abs(transform.a);
13777
13837
  const height = solderPaste.height * Math.abs(transform.d);
@@ -13997,8 +14057,8 @@ function createSvgObjects4({ elm, ctx }) {
13997
14057
  }
13998
14058
  }
13999
14059
  function createSvgObjectFromPcbBoundary2(transform, minX, minY, maxX, maxY) {
14000
- const [x1, y1] = applyToPoint77(transform, [minX, minY]);
14001
- const [x2, y2] = applyToPoint77(transform, [maxX, maxY]);
14060
+ const [x1, y1] = applyToPoint78(transform, [minX, minY]);
14061
+ const [x2, y2] = applyToPoint78(transform, [maxX, maxY]);
14002
14062
  const width = Math.abs(x2 - x1);
14003
14063
  const height = Math.abs(y2 - y1);
14004
14064
  const x = Math.min(x1, x2);