circuit-to-svg 0.0.285 → 0.0.287

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
@@ -2750,6 +2750,7 @@ import { lineAlphabet } from "@tscircuit/alphabet";
2750
2750
  var CHAR_WIDTH = 1;
2751
2751
  var CHAR_SPACING = 0.2;
2752
2752
  var LINE_HEIGHT = 1.4;
2753
+ var FONT_SCALE = 0.53;
2753
2754
  function linesToPathData(lines, offsetX, offsetY, charScale) {
2754
2755
  return lines.map((line) => {
2755
2756
  const x1 = offsetX + line.x1 * charScale;
@@ -2841,15 +2842,16 @@ function createSvgObjectsFromPcbCopperText(pcbCopperText, ctx) {
2841
2842
  const isBottom = layerName === "bottom";
2842
2843
  const applyMirror = isBottom ? true : is_mirrored === true;
2843
2844
  if (is_knockout) {
2845
+ const scaledFontSize2 = fontSizeNum * FONT_SCALE;
2844
2846
  const { pathData: pathData2, width: width2, height: height2 } = textToCenteredAlphabetPaths(
2845
2847
  text,
2846
- fontSizeNum
2848
+ scaledFontSize2
2847
2849
  );
2848
- const padX = knockout_padding?.left ?? fontSizeNum * 0.5;
2849
- const padY = knockout_padding?.top ?? fontSizeNum * 0.3;
2850
+ const padX = knockout_padding?.left ?? scaledFontSize2 * 0.5;
2851
+ const padY = knockout_padding?.top ?? scaledFontSize2 * 0.3;
2850
2852
  const rectW = width2 + padX * 2;
2851
2853
  const rectH = height2 + padY * 2;
2852
- const strokeWidth2 = fontSizeNum * 0.15;
2854
+ const strokeWidth2 = scaledFontSize2 * 0.15;
2853
2855
  const knockoutTransform = matrixToString4(
2854
2856
  compose3(
2855
2857
  translate3(ax, ay),
@@ -2927,9 +2929,10 @@ function createSvgObjectsFromPcbCopperText(pcbCopperText, ctx) {
2927
2929
  }
2928
2930
  ];
2929
2931
  }
2932
+ const scaledFontSize = fontSizeNum * FONT_SCALE;
2930
2933
  const { pathData, width, height } = textToCenteredAlphabetPaths(
2931
2934
  text,
2932
- fontSizeNum
2935
+ scaledFontSize
2933
2936
  );
2934
2937
  let offsetX = 0;
2935
2938
  let offsetY = 0;
@@ -2972,7 +2975,7 @@ function createSvgObjectsFromPcbCopperText(pcbCopperText, ctx) {
2972
2975
  scale2(scaleFactor, scaleFactor)
2973
2976
  )
2974
2977
  );
2975
- const strokeWidth = fontSizeNum * 0.15;
2978
+ const strokeWidth = scaledFontSize * 0.15;
2976
2979
  return [
2977
2980
  {
2978
2981
  name: "path",
@@ -3788,7 +3791,9 @@ function createAnchorOffsetIndicators(params) {
3788
3791
  componentPosition,
3789
3792
  transform,
3790
3793
  componentWidth = 0,
3791
- componentHeight = 0
3794
+ componentHeight = 0,
3795
+ displayXOffset,
3796
+ displayYOffset
3792
3797
  } = params;
3793
3798
  const objects = [];
3794
3799
  const [screenGroupAnchorX, screenGroupAnchorY] = applyToPoint22(transform, [
@@ -3854,7 +3859,8 @@ function createAnchorOffsetIndicators(params) {
3854
3859
  endX: screenComponentX,
3855
3860
  y: horizontalLineY,
3856
3861
  offsetMm: offsetX,
3857
- offsetY
3862
+ offsetY,
3863
+ displayOffset: displayXOffset
3858
3864
  })
3859
3865
  );
3860
3866
  }
@@ -3865,7 +3871,8 @@ function createAnchorOffsetIndicators(params) {
3865
3871
  startY: screenGroupAnchorY,
3866
3872
  endY: screenComponentY,
3867
3873
  offsetMm: offsetY,
3868
- offsetX
3874
+ offsetX,
3875
+ displayOffset: displayYOffset
3869
3876
  })
3870
3877
  );
3871
3878
  }
@@ -3919,7 +3926,8 @@ function createHorizontalDimension({
3919
3926
  endX,
3920
3927
  y,
3921
3928
  offsetMm,
3922
- offsetY
3929
+ offsetY,
3930
+ displayOffset
3923
3931
  }) {
3924
3932
  const objects = [];
3925
3933
  objects.push({
@@ -3983,7 +3991,7 @@ function createHorizontalDimension({
3983
3991
  children: [
3984
3992
  {
3985
3993
  type: "text",
3986
- value: `X: ${offsetMm.toFixed(2)}mm`,
3994
+ value: formatOffsetLabel("X", offsetMm, displayOffset),
3987
3995
  name: "",
3988
3996
  attributes: {},
3989
3997
  children: []
@@ -3998,7 +4006,8 @@ function createVerticalDimension({
3998
4006
  startY,
3999
4007
  endY,
4000
4008
  offsetMm,
4001
- offsetX
4009
+ offsetX,
4010
+ displayOffset
4002
4011
  }) {
4003
4012
  const objects = [];
4004
4013
  objects.push({
@@ -4062,7 +4071,7 @@ function createVerticalDimension({
4062
4071
  children: [
4063
4072
  {
4064
4073
  type: "text",
4065
- value: `Y: ${offsetMm.toFixed(2)}mm`,
4074
+ value: formatOffsetLabel("Y", offsetMm, displayOffset),
4066
4075
  name: "",
4067
4076
  attributes: {},
4068
4077
  children: []
@@ -4072,6 +4081,13 @@ function createVerticalDimension({
4072
4081
  });
4073
4082
  return objects;
4074
4083
  }
4084
+ function formatOffsetLabel(axis, offsetMm, displayOffset) {
4085
+ const baseValue = displayOffset ?? offsetMm.toFixed(2);
4086
+ const valueStr = typeof baseValue === "number" ? baseValue.toString() : baseValue;
4087
+ const hasUnit = typeof valueStr === "string" && valueStr.trim().endsWith("mm");
4088
+ const unitSuffix = hasUnit ? "" : "mm";
4089
+ return `${axis}: ${valueStr}${unitSuffix}`;
4090
+ }
4075
4091
 
4076
4092
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-board.ts
4077
4093
  function createSvgObjectsFromPcbBoard(pcbBoard, ctx) {
@@ -5360,18 +5376,18 @@ function createSvgObjectsFromPcbComponent(component, ctx) {
5360
5376
  const scaledHeight = height * Math.abs(transform.d);
5361
5377
  const transformStr = `translate(${x}, ${y}) rotate(${-rotation}) scale(1, -1)`;
5362
5378
  const svgObjects = [];
5363
- if (ctx.showAnchorOffsets && component.positioned_relative_to_pcb_group_id && component.position_mode === "relative" && circuitJson) {
5364
- const pcbGroup = circuitJson.find(
5365
- (elm) => elm.type === "pcb_group" && elm.pcb_group_id === component.positioned_relative_to_pcb_group_id
5366
- );
5367
- if (pcbGroup?.center) {
5379
+ if (ctx.showAnchorOffsets && component.position_mode === "relative" && circuitJson) {
5380
+ const anchorPosition = getAnchorPosition(component, circuitJson);
5381
+ if (anchorPosition) {
5368
5382
  svgObjects.push(
5369
5383
  ...createAnchorOffsetIndicators({
5370
- groupAnchorPosition: pcbGroup.center,
5384
+ groupAnchorPosition: anchorPosition,
5371
5385
  componentPosition: center,
5372
5386
  transform,
5373
5387
  componentWidth: width,
5374
- componentHeight: height
5388
+ componentHeight: height,
5389
+ displayXOffset: component.display_x_offset,
5390
+ displayYOffset: component.display_y_offset
5375
5391
  })
5376
5392
  );
5377
5393
  }
@@ -5408,6 +5424,21 @@ function createSvgObjectsFromPcbComponent(component, ctx) {
5408
5424
  });
5409
5425
  return svgObjects;
5410
5426
  }
5427
+ function getAnchorPosition(component, circuitJson) {
5428
+ if (component.positioned_relative_to_pcb_group_id) {
5429
+ const pcbGroup = circuitJson.find(
5430
+ (elm) => elm.type === "pcb_group" && elm.pcb_group_id === component.positioned_relative_to_pcb_group_id
5431
+ );
5432
+ if (pcbGroup?.center) return pcbGroup.center;
5433
+ }
5434
+ if (component.positioned_relative_to_pcb_board_id) {
5435
+ const pcbBoard = circuitJson.find(
5436
+ (elm) => elm.type === "pcb_board" && elm.pcb_board_id === component.positioned_relative_to_pcb_board_id
5437
+ );
5438
+ if (pcbBoard?.center) return pcbBoard.center;
5439
+ }
5440
+ return void 0;
5441
+ }
5411
5442
 
5412
5443
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-group.ts
5413
5444
  import { applyToPoint as applyToPoint32 } from "transformation-matrix";
@@ -5499,7 +5530,7 @@ function getSoftwareUsedString(circuitJson) {
5499
5530
  var package_default = {
5500
5531
  name: "circuit-to-svg",
5501
5532
  type: "module",
5502
- version: "0.0.284",
5533
+ version: "0.0.286",
5503
5534
  description: "Convert Circuit JSON to SVG",
5504
5535
  main: "dist/index.js",
5505
5536
  files: [
@@ -5522,7 +5553,7 @@ var package_default = {
5522
5553
  "@vitejs/plugin-react": "5.0.0",
5523
5554
  biome: "^0.3.3",
5524
5555
  "bun-match-svg": "^0.0.12",
5525
- "circuit-json": "^0.0.327",
5556
+ "circuit-json": "^0.0.331",
5526
5557
  esbuild: "^0.20.2",
5527
5558
  "performance-now": "^2.1.0",
5528
5559
  react: "19.1.0",