circuit-to-svg 0.0.305 → 0.0.306

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
@@ -1,5 +1,5 @@
1
1
  // lib/pcb/convert-circuit-json-to-pcb-svg.ts
2
- import { distance as distance2 } from "circuit-json";
2
+ import "circuit-json";
3
3
  import { stringify } from "svgson";
4
4
  import {
5
5
  applyToPoint as applyToPoint37,
@@ -3834,10 +3834,10 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
3834
3834
  maskPoints = points.map(([px, py]) => {
3835
3835
  const dx = px - centroidX;
3836
3836
  const dy = py - centroidY;
3837
- const distance4 = Math.sqrt(dx * dx + dy * dy);
3838
- if (distance4 === 0) return [px, py];
3839
- const normalizedDx = dx / distance4;
3840
- const normalizedDy = dy / distance4;
3837
+ const distance5 = Math.sqrt(dx * dx + dy * dy);
3838
+ if (distance5 === 0) return [px, py];
3839
+ const normalizedDx = dx / distance5;
3840
+ const normalizedDy = dy / distance5;
3841
3841
  return [
3842
3842
  px + normalizedDx * soldermaskMargin,
3843
3843
  py + normalizedDy * soldermaskMargin
@@ -4043,11 +4043,11 @@ function createAnchorOffsetIndicators(params) {
4043
4043
  function getTrimmedConnectorLine(x1, y1, x2, y2) {
4044
4044
  const dx = x2 - x1;
4045
4045
  const dy = y2 - y1;
4046
- const distance4 = Math.hypot(dx, dy);
4046
+ const distance5 = Math.hypot(dx, dy);
4047
4047
  const totalTrim = CONNECTOR_GROUP_GAP_PX + CONNECTOR_COMPONENT_GAP_PX;
4048
- if (!(distance4 > totalTrim)) return { x1, y1, x2, y2 };
4049
- const ux = dx / distance4;
4050
- const uy = dy / distance4;
4048
+ if (!(distance5 > totalTrim)) return { x1, y1, x2, y2 };
4049
+ const ux = dx / distance5;
4050
+ const uy = dy / distance5;
4051
4051
  return {
4052
4052
  x1: x1 + ux * CONNECTOR_GROUP_GAP_PX,
4053
4053
  y1: y1 + uy * CONNECTOR_GROUP_GAP_PX,
@@ -5004,9 +5004,9 @@ var findNearestPointInNet = (sourcePoint, netId, connectivity, circuitJson) => {
5004
5004
  if (pos) {
5005
5005
  const dx = sourcePoint.x - pos.x;
5006
5006
  const dy = sourcePoint.y - pos.y;
5007
- const distance4 = Math.sqrt(dx * dx + dy * dy);
5008
- if (distance4 > 0 && distance4 < minDistance) {
5009
- minDistance = distance4;
5007
+ const distance5 = Math.sqrt(dx * dx + dy * dy);
5008
+ if (distance5 > 0 && distance5 < minDistance) {
5009
+ minDistance = distance5;
5010
5010
  nearestPoint = pos;
5011
5011
  }
5012
5012
  }
@@ -5884,7 +5884,7 @@ function getSoftwareUsedString(circuitJson) {
5884
5884
  var package_default = {
5885
5885
  name: "circuit-to-svg",
5886
5886
  type: "module",
5887
- version: "0.0.304",
5887
+ version: "0.0.305",
5888
5888
  description: "Convert Circuit JSON to SVG",
5889
5889
  main: "dist/index.js",
5890
5890
  files: [
@@ -6066,49 +6066,9 @@ function createErrorTextOverlay(circuitJson, dataType = "error_text_overlay") {
6066
6066
  return textBlock;
6067
6067
  }
6068
6068
 
6069
- // lib/pcb/convert-circuit-json-to-pcb-svg.ts
6070
- function convertCircuitJsonToPcbSvg(circuitJson, options) {
6071
- const drawPaddingOutsideBoard = options?.drawPaddingOutsideBoard ?? true;
6072
- const layer = options?.layer;
6073
- const colorOverrides = options?.colorOverrides;
6074
- const copperColors = {
6075
- ...DEFAULT_PCB_COLOR_MAP.copper
6076
- };
6077
- if (colorOverrides?.copper) {
6078
- for (const [layerName, color] of Object.entries(colorOverrides.copper)) {
6079
- if (color !== void 0) {
6080
- copperColors[layerName] = color;
6081
- }
6082
- }
6083
- }
6084
- const colorMap2 = {
6085
- copper: copperColors,
6086
- drill: colorOverrides?.drill ?? DEFAULT_PCB_COLOR_MAP.drill,
6087
- silkscreen: {
6088
- top: colorOverrides?.silkscreen?.top ?? DEFAULT_PCB_COLOR_MAP.silkscreen.top,
6089
- bottom: colorOverrides?.silkscreen?.bottom ?? DEFAULT_PCB_COLOR_MAP.silkscreen.bottom
6090
- },
6091
- boardOutline: colorOverrides?.boardOutline ?? DEFAULT_PCB_COLOR_MAP.boardOutline,
6092
- soldermask: {
6093
- top: colorOverrides?.soldermask?.top ?? DEFAULT_PCB_COLOR_MAP.soldermask.top,
6094
- bottom: colorOverrides?.soldermask?.bottom ?? DEFAULT_PCB_COLOR_MAP.soldermask.bottom
6095
- },
6096
- soldermaskOverCopper: {
6097
- top: colorOverrides?.soldermaskOverCopper?.top ?? DEFAULT_PCB_COLOR_MAP.soldermaskOverCopper.top,
6098
- bottom: colorOverrides?.soldermaskOverCopper?.bottom ?? DEFAULT_PCB_COLOR_MAP.soldermaskOverCopper.bottom
6099
- },
6100
- soldermaskWithCopperUnderneath: {
6101
- top: colorOverrides?.soldermaskWithCopperUnderneath?.top ?? DEFAULT_PCB_COLOR_MAP.soldermaskWithCopperUnderneath.top,
6102
- bottom: colorOverrides?.soldermaskWithCopperUnderneath?.bottom ?? DEFAULT_PCB_COLOR_MAP.soldermaskWithCopperUnderneath.bottom
6103
- },
6104
- substrate: colorOverrides?.substrate ?? DEFAULT_PCB_COLOR_MAP.substrate,
6105
- courtyard: colorOverrides?.courtyard ?? DEFAULT_PCB_COLOR_MAP.courtyard,
6106
- keepout: colorOverrides?.keepout ?? DEFAULT_PCB_COLOR_MAP.keepout,
6107
- debugComponent: {
6108
- fill: colorOverrides?.debugComponent?.fill ?? DEFAULT_PCB_COLOR_MAP.debugComponent.fill,
6109
- stroke: colorOverrides?.debugComponent?.stroke ?? DEFAULT_PCB_COLOR_MAP.debugComponent.stroke
6110
- }
6111
- };
6069
+ // lib/pcb/get-pcb-bounds-from-circuit-json.ts
6070
+ import { distance as distance2 } from "circuit-json";
6071
+ function getPcbBoundsFromCircuitJson(circuitJson) {
6112
6072
  let minX = Number.POSITIVE_INFINITY;
6113
6073
  let minY = Number.POSITIVE_INFINITY;
6114
6074
  let maxX = Number.NEGATIVE_INFINITY;
@@ -6128,53 +6088,73 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
6128
6088
  continue;
6129
6089
  }
6130
6090
  const center = panel.center ?? { x: width / 2, y: height / 2 };
6131
- updateBounds(center, width, height);
6091
+ updateBounds({ center, width, height });
6132
6092
  } else if (circuitJsonElm.type === "pcb_board") {
6133
6093
  if (circuitJsonElm.outline && Array.isArray(circuitJsonElm.outline) && circuitJsonElm.outline.length >= 3) {
6134
6094
  updateBoundsToIncludeOutline(circuitJsonElm.outline);
6135
6095
  updateBoardBoundsToIncludeOutline(circuitJsonElm.outline);
6136
6096
  } else if ("center" in circuitJsonElm && "width" in circuitJsonElm && "height" in circuitJsonElm) {
6137
- updateBounds(
6138
- circuitJsonElm.center,
6139
- circuitJsonElm.width,
6140
- circuitJsonElm.height
6141
- );
6142
- updateBoardBounds(
6143
- circuitJsonElm.center,
6144
- circuitJsonElm.width,
6145
- circuitJsonElm.height
6146
- );
6097
+ updateBounds({
6098
+ center: circuitJsonElm.center,
6099
+ width: circuitJsonElm.width,
6100
+ height: circuitJsonElm.height
6101
+ });
6102
+ updateBoardBounds({
6103
+ center: circuitJsonElm.center,
6104
+ width: circuitJsonElm.width,
6105
+ height: circuitJsonElm.height
6106
+ });
6147
6107
  }
6148
6108
  } else if (circuitJsonElm.type === "pcb_smtpad") {
6149
6109
  const pad = circuitJsonElm;
6150
6110
  if (pad.shape === "rect" || pad.shape === "rotated_rect" || pad.shape === "pill") {
6151
- updateBounds({ x: pad.x, y: pad.y }, pad.width, pad.height);
6111
+ updateBounds({
6112
+ center: { x: pad.x, y: pad.y },
6113
+ width: pad.width,
6114
+ height: pad.height
6115
+ });
6152
6116
  } else if (pad.shape === "circle") {
6153
6117
  const radius = distance2.parse(pad.radius);
6154
6118
  if (radius !== void 0) {
6155
- updateBounds({ x: pad.x, y: pad.y }, radius * 2, radius * 2);
6119
+ updateBounds({
6120
+ center: { x: pad.x, y: pad.y },
6121
+ width: radius * 2,
6122
+ height: radius * 2
6123
+ });
6156
6124
  }
6157
6125
  } else if (pad.shape === "polygon") {
6158
6126
  updateTraceBounds(pad.points);
6159
6127
  }
6160
6128
  } else if ("x" in circuitJsonElm && "y" in circuitJsonElm) {
6161
- updateBounds({ x: circuitJsonElm.x, y: circuitJsonElm.y }, 0, 0);
6129
+ updateBounds({
6130
+ center: { x: circuitJsonElm.x, y: circuitJsonElm.y },
6131
+ width: 0,
6132
+ height: 0
6133
+ });
6162
6134
  } else if ("route" in circuitJsonElm) {
6163
6135
  updateTraceBounds(circuitJsonElm.route);
6164
6136
  } else if (circuitJsonElm.type === "pcb_note_rect" || circuitJsonElm.type === "pcb_fabrication_note_rect") {
6165
- updateBounds(
6166
- circuitJsonElm.center,
6167
- circuitJsonElm.width,
6168
- circuitJsonElm.height
6169
- );
6137
+ updateBounds({
6138
+ center: circuitJsonElm.center,
6139
+ width: circuitJsonElm.width,
6140
+ height: circuitJsonElm.height
6141
+ });
6170
6142
  } else if (circuitJsonElm.type === "pcb_cutout") {
6171
6143
  const cutout = circuitJsonElm;
6172
6144
  if (cutout.shape === "rect") {
6173
- updateBounds(cutout.center, cutout.width, cutout.height);
6145
+ updateBounds({
6146
+ center: cutout.center,
6147
+ width: cutout.width,
6148
+ height: cutout.height
6149
+ });
6174
6150
  } else if (cutout.shape === "circle") {
6175
6151
  const radius = distance2.parse(cutout.radius);
6176
6152
  if (radius !== void 0) {
6177
- updateBounds(cutout.center, radius * 2, radius * 2);
6153
+ updateBounds({
6154
+ center: cutout.center,
6155
+ width: radius * 2,
6156
+ height: radius * 2
6157
+ });
6178
6158
  }
6179
6159
  } else if (cutout.shape === "polygon") {
6180
6160
  updateTraceBounds(cutout.points);
@@ -6187,34 +6167,262 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
6187
6167
  } else if (circuitJsonElm.type === "pcb_keepout") {
6188
6168
  const keepout = circuitJsonElm;
6189
6169
  if (keepout.shape === "rect") {
6190
- updateBounds(keepout.center, keepout.width, keepout.height);
6170
+ updateBounds({
6171
+ center: keepout.center,
6172
+ width: keepout.width,
6173
+ height: keepout.height
6174
+ });
6191
6175
  } else if (keepout.shape === "circle") {
6192
6176
  const radius = typeof keepout.radius === "number" ? keepout.radius : distance2.parse(keepout.radius) ?? 0;
6193
6177
  if (radius > 0) {
6194
- updateBounds(keepout.center, radius * 2, radius * 2);
6178
+ updateBounds({
6179
+ center: keepout.center,
6180
+ width: radius * 2,
6181
+ height: radius * 2
6182
+ });
6195
6183
  }
6196
6184
  }
6197
6185
  } else if (circuitJsonElm.type === "pcb_silkscreen_text" || circuitJsonElm.type === "pcb_silkscreen_rect" || circuitJsonElm.type === "pcb_silkscreen_circle" || circuitJsonElm.type === "pcb_silkscreen_line" || circuitJsonElm.type === "pcb_silkscreen_oval") {
6198
6186
  updateSilkscreenBounds(circuitJsonElm);
6199
6187
  } else if (circuitJsonElm.type === "pcb_copper_text") {
6200
- updateBounds(circuitJsonElm.anchor_position, 0, 0);
6188
+ updateBounds({
6189
+ center: circuitJsonElm.anchor_position,
6190
+ width: 0,
6191
+ height: 0
6192
+ });
6201
6193
  } else if (circuitJsonElm.type === "pcb_copper_pour") {
6202
6194
  if (circuitJsonElm.shape === "rect") {
6203
- updateBounds(
6204
- circuitJsonElm.center,
6205
- circuitJsonElm.width,
6206
- circuitJsonElm.height
6207
- );
6195
+ updateBounds({
6196
+ center: circuitJsonElm.center,
6197
+ width: circuitJsonElm.width,
6198
+ height: circuitJsonElm.height
6199
+ });
6208
6200
  } else if (circuitJsonElm.shape === "polygon") {
6209
6201
  updateTraceBounds(circuitJsonElm.points);
6210
6202
  }
6211
6203
  }
6212
6204
  }
6205
+ return {
6206
+ minX,
6207
+ minY,
6208
+ maxX,
6209
+ maxY,
6210
+ boardMinX,
6211
+ boardMinY,
6212
+ boardMaxX,
6213
+ boardMaxY,
6214
+ hasBounds,
6215
+ hasBoardBounds
6216
+ };
6217
+ function updateBounds({
6218
+ center,
6219
+ width,
6220
+ height
6221
+ }) {
6222
+ if (!center) return;
6223
+ const centerX = distance2.parse(center.x);
6224
+ const centerY = distance2.parse(center.y);
6225
+ if (centerX === void 0 || centerY === void 0) return;
6226
+ const numericWidth = distance2.parse(width) ?? 0;
6227
+ const numericHeight = distance2.parse(height) ?? 0;
6228
+ const halfWidth = numericWidth / 2;
6229
+ const halfHeight = numericHeight / 2;
6230
+ minX = Math.min(minX, centerX - halfWidth);
6231
+ minY = Math.min(minY, centerY - halfHeight);
6232
+ maxX = Math.max(maxX, centerX + halfWidth);
6233
+ maxY = Math.max(maxY, centerY + halfHeight);
6234
+ hasBounds = true;
6235
+ }
6236
+ function updateBoardBounds({
6237
+ center,
6238
+ width,
6239
+ height
6240
+ }) {
6241
+ if (!center) return;
6242
+ const centerX = distance2.parse(center.x);
6243
+ const centerY = distance2.parse(center.y);
6244
+ if (centerX === void 0 || centerY === void 0) return;
6245
+ const numericWidth = distance2.parse(width) ?? 0;
6246
+ const numericHeight = distance2.parse(height) ?? 0;
6247
+ const halfWidth = numericWidth / 2;
6248
+ const halfHeight = numericHeight / 2;
6249
+ boardMinX = Math.min(boardMinX, centerX - halfWidth);
6250
+ boardMinY = Math.min(boardMinY, centerY - halfHeight);
6251
+ boardMaxX = Math.max(boardMaxX, centerX + halfWidth);
6252
+ boardMaxY = Math.max(boardMaxY, centerY + halfHeight);
6253
+ hasBounds = true;
6254
+ hasBoardBounds = true;
6255
+ }
6256
+ function updateBoundsToIncludeOutline(outline) {
6257
+ let updated = false;
6258
+ for (const point of outline) {
6259
+ const x = distance2.parse(point.x);
6260
+ const y = distance2.parse(point.y);
6261
+ if (x === void 0 || y === void 0) continue;
6262
+ minX = Math.min(minX, x);
6263
+ minY = Math.min(minY, y);
6264
+ maxX = Math.max(maxX, x);
6265
+ maxY = Math.max(maxY, y);
6266
+ updated = true;
6267
+ }
6268
+ if (updated) {
6269
+ hasBounds = true;
6270
+ }
6271
+ }
6272
+ function updateBoardBoundsToIncludeOutline(outline) {
6273
+ let updated = false;
6274
+ for (const point of outline) {
6275
+ const x = distance2.parse(point.x);
6276
+ const y = distance2.parse(point.y);
6277
+ if (x === void 0 || y === void 0) continue;
6278
+ boardMinX = Math.min(boardMinX, x);
6279
+ boardMinY = Math.min(boardMinY, y);
6280
+ boardMaxX = Math.max(boardMaxX, x);
6281
+ boardMaxY = Math.max(boardMaxY, y);
6282
+ updated = true;
6283
+ }
6284
+ if (updated) {
6285
+ hasBounds = true;
6286
+ hasBoardBounds = true;
6287
+ }
6288
+ }
6289
+ function updateTraceBounds(route) {
6290
+ let updated = false;
6291
+ for (const point of route) {
6292
+ const x = distance2.parse(point?.x);
6293
+ const y = distance2.parse(point?.y);
6294
+ if (x === void 0 || y === void 0) continue;
6295
+ minX = Math.min(minX, x);
6296
+ minY = Math.min(minY, y);
6297
+ maxX = Math.max(maxX, x);
6298
+ maxY = Math.max(maxY, y);
6299
+ updated = true;
6300
+ }
6301
+ if (updated) {
6302
+ hasBounds = true;
6303
+ }
6304
+ }
6305
+ function updateSilkscreenBounds(item) {
6306
+ if (item.type === "pcb_silkscreen_text") {
6307
+ updateBounds({ center: item.anchor_position, width: 0, height: 0 });
6308
+ } else if (item.type === "pcb_silkscreen_path") {
6309
+ updateTraceBounds(item.route);
6310
+ } else if (item.type === "pcb_silkscreen_rect") {
6311
+ updateBounds({
6312
+ center: item.center,
6313
+ width: item.width,
6314
+ height: item.height
6315
+ });
6316
+ } else if (item.type === "pcb_silkscreen_circle") {
6317
+ const radius = distance2.parse(item.radius);
6318
+ if (radius !== void 0) {
6319
+ updateBounds({
6320
+ center: item.center,
6321
+ width: radius * 2,
6322
+ height: radius * 2
6323
+ });
6324
+ }
6325
+ } else if (item.type === "pcb_silkscreen_line") {
6326
+ updateBounds({ center: { x: item.x1, y: item.y1 }, width: 0, height: 0 });
6327
+ updateBounds({ center: { x: item.x2, y: item.y2 }, width: 0, height: 0 });
6328
+ } else if (item.type === "pcb_silkscreen_oval") {
6329
+ const radiusX = distance2.parse(item.radius_x);
6330
+ const radiusY = distance2.parse(item.radius_y);
6331
+ if (radiusX !== void 0 && radiusY !== void 0) {
6332
+ updateBounds({
6333
+ center: item.center,
6334
+ width: radiusX * 2,
6335
+ height: radiusY * 2
6336
+ });
6337
+ }
6338
+ } else if (item.type === "pcb_cutout") {
6339
+ const cutout = item;
6340
+ if (cutout.shape === "rect") {
6341
+ updateBounds({
6342
+ center: cutout.center,
6343
+ width: cutout.width,
6344
+ height: cutout.height
6345
+ });
6346
+ } else if (cutout.shape === "circle") {
6347
+ const radius = distance2.parse(cutout.radius);
6348
+ if (radius !== void 0) {
6349
+ updateBounds({
6350
+ center: cutout.center,
6351
+ width: radius * 2,
6352
+ height: radius * 2
6353
+ });
6354
+ }
6355
+ } else if (cutout.shape === "polygon") {
6356
+ updateTraceBounds(cutout.points);
6357
+ } else if (cutout.shape === "path") {
6358
+ const cutoutPath = cutout;
6359
+ if (cutoutPath.route && Array.isArray(cutoutPath.route)) {
6360
+ updateTraceBounds(cutoutPath.route);
6361
+ }
6362
+ }
6363
+ }
6364
+ }
6365
+ }
6366
+
6367
+ // lib/pcb/convert-circuit-json-to-pcb-svg.ts
6368
+ function convertCircuitJsonToPcbSvg(circuitJson, options) {
6369
+ const drawPaddingOutsideBoard = options?.drawPaddingOutsideBoard ?? true;
6370
+ const layer = options?.layer;
6371
+ const colorOverrides = options?.colorOverrides;
6372
+ const copperColors = {
6373
+ ...DEFAULT_PCB_COLOR_MAP.copper
6374
+ };
6375
+ if (colorOverrides?.copper) {
6376
+ for (const [layerName, color] of Object.entries(colorOverrides.copper)) {
6377
+ if (color !== void 0) {
6378
+ copperColors[layerName] = color;
6379
+ }
6380
+ }
6381
+ }
6382
+ const colorMap2 = {
6383
+ copper: copperColors,
6384
+ drill: colorOverrides?.drill ?? DEFAULT_PCB_COLOR_MAP.drill,
6385
+ silkscreen: {
6386
+ top: colorOverrides?.silkscreen?.top ?? DEFAULT_PCB_COLOR_MAP.silkscreen.top,
6387
+ bottom: colorOverrides?.silkscreen?.bottom ?? DEFAULT_PCB_COLOR_MAP.silkscreen.bottom
6388
+ },
6389
+ boardOutline: colorOverrides?.boardOutline ?? DEFAULT_PCB_COLOR_MAP.boardOutline,
6390
+ soldermask: {
6391
+ top: colorOverrides?.soldermask?.top ?? DEFAULT_PCB_COLOR_MAP.soldermask.top,
6392
+ bottom: colorOverrides?.soldermask?.bottom ?? DEFAULT_PCB_COLOR_MAP.soldermask.bottom
6393
+ },
6394
+ soldermaskOverCopper: {
6395
+ top: colorOverrides?.soldermaskOverCopper?.top ?? DEFAULT_PCB_COLOR_MAP.soldermaskOverCopper.top,
6396
+ bottom: colorOverrides?.soldermaskOverCopper?.bottom ?? DEFAULT_PCB_COLOR_MAP.soldermaskOverCopper.bottom
6397
+ },
6398
+ soldermaskWithCopperUnderneath: {
6399
+ top: colorOverrides?.soldermaskWithCopperUnderneath?.top ?? DEFAULT_PCB_COLOR_MAP.soldermaskWithCopperUnderneath.top,
6400
+ bottom: colorOverrides?.soldermaskWithCopperUnderneath?.bottom ?? DEFAULT_PCB_COLOR_MAP.soldermaskWithCopperUnderneath.bottom
6401
+ },
6402
+ substrate: colorOverrides?.substrate ?? DEFAULT_PCB_COLOR_MAP.substrate,
6403
+ courtyard: colorOverrides?.courtyard ?? DEFAULT_PCB_COLOR_MAP.courtyard,
6404
+ keepout: colorOverrides?.keepout ?? DEFAULT_PCB_COLOR_MAP.keepout,
6405
+ debugComponent: {
6406
+ fill: colorOverrides?.debugComponent?.fill ?? DEFAULT_PCB_COLOR_MAP.debugComponent.fill,
6407
+ stroke: colorOverrides?.debugComponent?.stroke ?? DEFAULT_PCB_COLOR_MAP.debugComponent.stroke
6408
+ }
6409
+ };
6410
+ const {
6411
+ minX,
6412
+ minY,
6413
+ maxX,
6414
+ maxY,
6415
+ boardMinX,
6416
+ boardMinY,
6417
+ boardMaxX,
6418
+ boardMaxY,
6419
+ hasBoardBounds
6420
+ } = getPcbBoundsFromCircuitJson(circuitJson);
6213
6421
  const padding = drawPaddingOutsideBoard ? 1 : 0;
6214
- const boundsMinX = drawPaddingOutsideBoard || !Number.isFinite(boardMinX) ? minX : boardMinX;
6215
- const boundsMinY = drawPaddingOutsideBoard || !Number.isFinite(boardMinY) ? minY : boardMinY;
6216
- const boundsMaxX = drawPaddingOutsideBoard || !Number.isFinite(boardMaxX) ? maxX : boardMaxX;
6217
- const boundsMaxY = drawPaddingOutsideBoard || !Number.isFinite(boardMaxY) ? maxY : boardMaxY;
6422
+ const boundsMinX = drawPaddingOutsideBoard || !hasBoardBounds ? minX : boardMinX;
6423
+ const boundsMinY = drawPaddingOutsideBoard || !hasBoardBounds ? minY : boardMinY;
6424
+ const boundsMaxX = drawPaddingOutsideBoard || !hasBoardBounds ? maxX : boardMaxX;
6425
+ const boundsMaxY = drawPaddingOutsideBoard || !hasBoardBounds ? maxY : boardMaxY;
6218
6426
  const circuitWidth = boundsMaxX - boundsMinX + 2 * padding;
6219
6427
  const circuitHeight = boundsMaxY - boundsMinY + 2 * padding;
6220
6428
  let svgWidth = options?.width ?? 800;
@@ -6363,126 +6571,6 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
6363
6571
  console.error("Error stringifying SVG object:", error);
6364
6572
  throw error;
6365
6573
  }
6366
- function updateBounds(center, width, height) {
6367
- if (!center) return;
6368
- const centerX = distance2.parse(center.x);
6369
- const centerY = distance2.parse(center.y);
6370
- if (centerX === void 0 || centerY === void 0) return;
6371
- const numericWidth = distance2.parse(width) ?? 0;
6372
- const numericHeight = distance2.parse(height) ?? 0;
6373
- const halfWidth = numericWidth / 2;
6374
- const halfHeight = numericHeight / 2;
6375
- minX = Math.min(minX, centerX - halfWidth);
6376
- minY = Math.min(minY, centerY - halfHeight);
6377
- maxX = Math.max(maxX, centerX + halfWidth);
6378
- maxY = Math.max(maxY, centerY + halfHeight);
6379
- hasBounds = true;
6380
- }
6381
- function updateBoardBounds(center, width, height) {
6382
- if (!center) return;
6383
- const centerX = distance2.parse(center.x);
6384
- const centerY = distance2.parse(center.y);
6385
- if (centerX === void 0 || centerY === void 0) return;
6386
- const numericWidth = distance2.parse(width) ?? 0;
6387
- const numericHeight = distance2.parse(height) ?? 0;
6388
- const halfWidth = numericWidth / 2;
6389
- const halfHeight = numericHeight / 2;
6390
- boardMinX = Math.min(boardMinX, centerX - halfWidth);
6391
- boardMinY = Math.min(boardMinY, centerY - halfHeight);
6392
- boardMaxX = Math.max(boardMaxX, centerX + halfWidth);
6393
- boardMaxY = Math.max(boardMaxY, centerY + halfHeight);
6394
- hasBounds = true;
6395
- hasBoardBounds = true;
6396
- }
6397
- function updateBoundsToIncludeOutline(outline) {
6398
- let updated = false;
6399
- for (const point of outline) {
6400
- const x = distance2.parse(point.x);
6401
- const y = distance2.parse(point.y);
6402
- if (x === void 0 || y === void 0) continue;
6403
- minX = Math.min(minX, x);
6404
- minY = Math.min(minY, y);
6405
- maxX = Math.max(maxX, x);
6406
- maxY = Math.max(maxY, y);
6407
- updated = true;
6408
- }
6409
- if (updated) {
6410
- hasBounds = true;
6411
- }
6412
- }
6413
- function updateBoardBoundsToIncludeOutline(outline) {
6414
- let updated = false;
6415
- for (const point of outline) {
6416
- const x = distance2.parse(point.x);
6417
- const y = distance2.parse(point.y);
6418
- if (x === void 0 || y === void 0) continue;
6419
- boardMinX = Math.min(boardMinX, x);
6420
- boardMinY = Math.min(boardMinY, y);
6421
- boardMaxX = Math.max(boardMaxX, x);
6422
- boardMaxY = Math.max(boardMaxY, y);
6423
- updated = true;
6424
- }
6425
- if (updated) {
6426
- hasBounds = true;
6427
- hasBoardBounds = true;
6428
- }
6429
- }
6430
- function updateTraceBounds(route) {
6431
- let updated = false;
6432
- for (const point of route) {
6433
- const x = distance2.parse(point?.x);
6434
- const y = distance2.parse(point?.y);
6435
- if (x === void 0 || y === void 0) continue;
6436
- minX = Math.min(minX, x);
6437
- minY = Math.min(minY, y);
6438
- maxX = Math.max(maxX, x);
6439
- maxY = Math.max(maxY, y);
6440
- updated = true;
6441
- }
6442
- if (updated) {
6443
- hasBounds = true;
6444
- }
6445
- }
6446
- function updateSilkscreenBounds(item) {
6447
- if (item.type === "pcb_silkscreen_text") {
6448
- updateBounds(item.anchor_position, 0, 0);
6449
- } else if (item.type === "pcb_silkscreen_path") {
6450
- updateTraceBounds(item.route);
6451
- } else if (item.type === "pcb_silkscreen_rect") {
6452
- updateBounds(item.center, item.width, item.height);
6453
- } else if (item.type === "pcb_silkscreen_circle") {
6454
- const radius = distance2.parse(item.radius);
6455
- if (radius !== void 0) {
6456
- updateBounds(item.center, radius * 2, radius * 2);
6457
- }
6458
- } else if (item.type === "pcb_silkscreen_line") {
6459
- updateBounds({ x: item.x1, y: item.y1 }, 0, 0);
6460
- updateBounds({ x: item.x2, y: item.y2 }, 0, 0);
6461
- } else if (item.type === "pcb_silkscreen_oval") {
6462
- const radiusX = distance2.parse(item.radius_x);
6463
- const radiusY = distance2.parse(item.radius_y);
6464
- if (radiusX !== void 0 && radiusY !== void 0) {
6465
- updateBounds(item.center, radiusX * 2, radiusY * 2);
6466
- }
6467
- } else if (item.type === "pcb_cutout") {
6468
- const cutout = item;
6469
- if (cutout.shape === "rect") {
6470
- updateBounds(cutout.center, cutout.width, cutout.height);
6471
- } else if (cutout.shape === "circle") {
6472
- const radius = distance2.parse(cutout.radius);
6473
- if (radius !== void 0) {
6474
- updateBounds(cutout.center, radius * 2, radius * 2);
6475
- }
6476
- } else if (cutout.shape === "polygon") {
6477
- updateTraceBounds(cutout.points);
6478
- } else if (cutout.shape === "path") {
6479
- const cutoutPath = cutout;
6480
- if (cutoutPath.route && Array.isArray(cutoutPath.route)) {
6481
- updateTraceBounds(cutoutPath.route);
6482
- }
6483
- }
6484
- }
6485
- }
6486
6574
  }
6487
6575
  function createSvgObjects({
6488
6576
  elm,
@@ -13278,7 +13366,7 @@ function formatNumber2(value) {
13278
13366
  }
13279
13367
 
13280
13368
  // lib/pcb/convert-circuit-json-to-solder-paste-mask.ts
13281
- import { distance as distance3 } from "circuit-json";
13369
+ import { distance as distance4 } from "circuit-json";
13282
13370
  import { stringify as stringify7 } from "svgson";
13283
13371
  import {
13284
13372
  applyToPoint as applyToPoint76,
@@ -13396,8 +13484,8 @@ function convertCircuitJsonToSolderPasteMask(circuitJson, options) {
13396
13484
  }
13397
13485
  } else if (item.type === "pcb_panel") {
13398
13486
  const panel = item;
13399
- const width = distance3.parse(panel.width);
13400
- const height = distance3.parse(panel.height);
13487
+ const width = distance4.parse(panel.width);
13488
+ const height = distance4.parse(panel.height);
13401
13489
  if (width !== void 0 && height !== void 0) {
13402
13490
  const center = panel.center ?? { x: width / 2, y: height / 2 };
13403
13491
  updateBounds(center, width, height);