circuit-to-svg 0.0.311 → 0.0.312
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.d.ts +10 -0
- package/dist/index.js +160 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -72,6 +72,16 @@ interface Options$4 {
|
|
|
72
72
|
showSolderMask?: boolean;
|
|
73
73
|
grid?: PcbGridOptions;
|
|
74
74
|
showAnchorOffsets?: boolean;
|
|
75
|
+
viewport?: {
|
|
76
|
+
minX: number;
|
|
77
|
+
minY: number;
|
|
78
|
+
maxX: number;
|
|
79
|
+
maxY: number;
|
|
80
|
+
};
|
|
81
|
+
viewportTarget?: {
|
|
82
|
+
pcb_panel_id?: string;
|
|
83
|
+
pcb_board_id?: string;
|
|
84
|
+
};
|
|
75
85
|
}
|
|
76
86
|
interface PcbContext {
|
|
77
87
|
transform: Matrix;
|
package/dist/index.js
CHANGED
|
@@ -3877,10 +3877,10 @@ function createSvgObjectsFromSmtPad(pad, ctx) {
|
|
|
3877
3877
|
maskPoints = points.map(([px, py]) => {
|
|
3878
3878
|
const dx = px - centroidX;
|
|
3879
3879
|
const dy = py - centroidY;
|
|
3880
|
-
const
|
|
3881
|
-
if (
|
|
3882
|
-
const normalizedDx = dx /
|
|
3883
|
-
const normalizedDy = dy /
|
|
3880
|
+
const distance6 = Math.sqrt(dx * dx + dy * dy);
|
|
3881
|
+
if (distance6 === 0) return [px, py];
|
|
3882
|
+
const normalizedDx = dx / distance6;
|
|
3883
|
+
const normalizedDy = dy / distance6;
|
|
3884
3884
|
return [
|
|
3885
3885
|
px + normalizedDx * soldermaskMargin,
|
|
3886
3886
|
py + normalizedDy * soldermaskMargin
|
|
@@ -4086,11 +4086,11 @@ function createAnchorOffsetIndicators(params) {
|
|
|
4086
4086
|
function getTrimmedConnectorLine(x1, y1, x2, y2) {
|
|
4087
4087
|
const dx = x2 - x1;
|
|
4088
4088
|
const dy = y2 - y1;
|
|
4089
|
-
const
|
|
4089
|
+
const distance6 = Math.hypot(dx, dy);
|
|
4090
4090
|
const totalTrim = CONNECTOR_GROUP_GAP_PX + CONNECTOR_COMPONENT_GAP_PX;
|
|
4091
|
-
if (!(
|
|
4092
|
-
const ux = dx /
|
|
4093
|
-
const uy = dy /
|
|
4091
|
+
if (!(distance6 > totalTrim)) return { x1, y1, x2, y2 };
|
|
4092
|
+
const ux = dx / distance6;
|
|
4093
|
+
const uy = dy / distance6;
|
|
4094
4094
|
return {
|
|
4095
4095
|
x1: x1 + ux * CONNECTOR_GROUP_GAP_PX,
|
|
4096
4096
|
y1: y1 + uy * CONNECTOR_GROUP_GAP_PX,
|
|
@@ -5047,9 +5047,9 @@ var findNearestPointInNet = (sourcePoint, netId, connectivity, circuitJson) => {
|
|
|
5047
5047
|
if (pos) {
|
|
5048
5048
|
const dx = sourcePoint.x - pos.x;
|
|
5049
5049
|
const dy = sourcePoint.y - pos.y;
|
|
5050
|
-
const
|
|
5051
|
-
if (
|
|
5052
|
-
minDistance =
|
|
5050
|
+
const distance6 = Math.sqrt(dx * dx + dy * dy);
|
|
5051
|
+
if (distance6 > 0 && distance6 < minDistance) {
|
|
5052
|
+
minDistance = distance6;
|
|
5053
5053
|
nearestPoint = pos;
|
|
5054
5054
|
}
|
|
5055
5055
|
}
|
|
@@ -5927,7 +5927,7 @@ function getSoftwareUsedString(circuitJson) {
|
|
|
5927
5927
|
var package_default = {
|
|
5928
5928
|
name: "circuit-to-svg",
|
|
5929
5929
|
type: "module",
|
|
5930
|
-
version: "0.0.
|
|
5930
|
+
version: "0.0.311",
|
|
5931
5931
|
description: "Convert Circuit JSON to SVG",
|
|
5932
5932
|
main: "dist/index.js",
|
|
5933
5933
|
files: [
|
|
@@ -6501,6 +6501,128 @@ function getPcbBoundsFromCircuitJson(circuitJson) {
|
|
|
6501
6501
|
}
|
|
6502
6502
|
}
|
|
6503
6503
|
|
|
6504
|
+
// lib/utils/get-viewport-bounds.ts
|
|
6505
|
+
import { distance as distance3 } from "circuit-json";
|
|
6506
|
+
var getViewportBounds = ({
|
|
6507
|
+
circuitJson,
|
|
6508
|
+
drawPaddingOutsideBoard,
|
|
6509
|
+
baseBounds,
|
|
6510
|
+
viewportOptions
|
|
6511
|
+
}) => {
|
|
6512
|
+
let padding = drawPaddingOutsideBoard ? 1 : 0;
|
|
6513
|
+
let boundsMinX = drawPaddingOutsideBoard || !baseBounds.hasBoardBounds ? baseBounds.minX : baseBounds.boardMinX;
|
|
6514
|
+
let boundsMinY = drawPaddingOutsideBoard || !baseBounds.hasBoardBounds ? baseBounds.minY : baseBounds.boardMinY;
|
|
6515
|
+
let boundsMaxX = drawPaddingOutsideBoard || !baseBounds.hasBoardBounds ? baseBounds.maxX : baseBounds.boardMaxX;
|
|
6516
|
+
let boundsMaxY = drawPaddingOutsideBoard || !baseBounds.hasBoardBounds ? baseBounds.maxY : baseBounds.boardMaxY;
|
|
6517
|
+
let hasPanelBounds = false;
|
|
6518
|
+
let panelMinX = Number.POSITIVE_INFINITY;
|
|
6519
|
+
let panelMinY = Number.POSITIVE_INFINITY;
|
|
6520
|
+
let panelMaxX = Number.NEGATIVE_INFINITY;
|
|
6521
|
+
let panelMaxY = Number.NEGATIVE_INFINITY;
|
|
6522
|
+
const panelBoundsById = /* @__PURE__ */ new Map();
|
|
6523
|
+
const boardBoundsById = /* @__PURE__ */ new Map();
|
|
6524
|
+
for (const elm of circuitJson) {
|
|
6525
|
+
if (elm.type === "pcb_panel") {
|
|
6526
|
+
const panel = elm;
|
|
6527
|
+
const panelBounds = rectBounds(panel.center, panel.width, panel.height);
|
|
6528
|
+
if (!panelBounds) continue;
|
|
6529
|
+
panelMinX = Math.min(panelMinX, panelBounds.minX);
|
|
6530
|
+
panelMinY = Math.min(panelMinY, panelBounds.minY);
|
|
6531
|
+
panelMaxX = Math.max(panelMaxX, panelBounds.maxX);
|
|
6532
|
+
panelMaxY = Math.max(panelMaxY, panelBounds.maxY);
|
|
6533
|
+
hasPanelBounds = true;
|
|
6534
|
+
if (panel.pcb_panel_id) {
|
|
6535
|
+
panelBoundsById.set(panel.pcb_panel_id, panelBounds);
|
|
6536
|
+
}
|
|
6537
|
+
} else if (elm.type === "pcb_board") {
|
|
6538
|
+
const board = elm;
|
|
6539
|
+
const outlineBounds = getOutlineBounds(board.outline);
|
|
6540
|
+
const boardBounds = outlineBounds ?? rectBounds(board.center, board.width, board.height);
|
|
6541
|
+
if (boardBounds && board.pcb_board_id) {
|
|
6542
|
+
boardBoundsById.set(board.pcb_board_id, boardBounds);
|
|
6543
|
+
}
|
|
6544
|
+
}
|
|
6545
|
+
}
|
|
6546
|
+
if (viewportOptions?.viewport) {
|
|
6547
|
+
const { minX, minY, maxX, maxY } = viewportOptions.viewport;
|
|
6548
|
+
boundsMinX = minX;
|
|
6549
|
+
boundsMinY = minY;
|
|
6550
|
+
boundsMaxX = maxX;
|
|
6551
|
+
boundsMaxY = maxY;
|
|
6552
|
+
padding = 0;
|
|
6553
|
+
} else if (viewportOptions?.viewportTarget?.pcb_panel_id) {
|
|
6554
|
+
const panelBounds = panelBoundsById.get(
|
|
6555
|
+
viewportOptions.viewportTarget.pcb_panel_id
|
|
6556
|
+
);
|
|
6557
|
+
if (!panelBounds) {
|
|
6558
|
+
throw new Error(
|
|
6559
|
+
`Viewport target panel '${viewportOptions.viewportTarget.pcb_panel_id}' not found`
|
|
6560
|
+
);
|
|
6561
|
+
}
|
|
6562
|
+
boundsMinX = panelBounds.minX;
|
|
6563
|
+
boundsMinY = panelBounds.minY;
|
|
6564
|
+
boundsMaxX = panelBounds.maxX;
|
|
6565
|
+
boundsMaxY = panelBounds.maxY;
|
|
6566
|
+
padding = 0;
|
|
6567
|
+
} else if (viewportOptions?.viewportTarget?.pcb_board_id) {
|
|
6568
|
+
const boardBounds = boardBoundsById.get(
|
|
6569
|
+
viewportOptions.viewportTarget.pcb_board_id
|
|
6570
|
+
);
|
|
6571
|
+
if (!boardBounds) {
|
|
6572
|
+
throw new Error(
|
|
6573
|
+
`Viewport target board '${viewportOptions.viewportTarget.pcb_board_id}' not found`
|
|
6574
|
+
);
|
|
6575
|
+
}
|
|
6576
|
+
boundsMinX = boardBounds.minX;
|
|
6577
|
+
boundsMinY = boardBounds.minY;
|
|
6578
|
+
boundsMaxX = boardBounds.maxX;
|
|
6579
|
+
boundsMaxY = boardBounds.maxY;
|
|
6580
|
+
padding = 0;
|
|
6581
|
+
} else if (hasPanelBounds) {
|
|
6582
|
+
boundsMinX = panelMinX;
|
|
6583
|
+
boundsMinY = panelMinY;
|
|
6584
|
+
boundsMaxX = panelMaxX;
|
|
6585
|
+
boundsMaxY = panelMaxY;
|
|
6586
|
+
}
|
|
6587
|
+
return { boundsMinX, boundsMinY, boundsMaxX, boundsMaxY, padding };
|
|
6588
|
+
};
|
|
6589
|
+
function rectBounds(center, width, height) {
|
|
6590
|
+
if (!center || width === void 0 || height === void 0) return;
|
|
6591
|
+
const cx = distance3.parse(center.x);
|
|
6592
|
+
const cy = distance3.parse(center.y);
|
|
6593
|
+
if (cx === void 0 || cy === void 0) return;
|
|
6594
|
+
const numericWidth = distance3.parse(width);
|
|
6595
|
+
const numericHeight = distance3.parse(height);
|
|
6596
|
+
if (numericWidth === void 0 || numericHeight === void 0) return;
|
|
6597
|
+
const halfW = numericWidth / 2;
|
|
6598
|
+
const halfH = numericHeight / 2;
|
|
6599
|
+
return {
|
|
6600
|
+
minX: cx - halfW,
|
|
6601
|
+
minY: cy - halfH,
|
|
6602
|
+
maxX: cx + halfW,
|
|
6603
|
+
maxY: cy + halfH
|
|
6604
|
+
};
|
|
6605
|
+
}
|
|
6606
|
+
function getOutlineBounds(outline) {
|
|
6607
|
+
if (!outline || outline.length < 3) return;
|
|
6608
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
6609
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
6610
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
6611
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
6612
|
+
for (const pt of outline) {
|
|
6613
|
+
const x = distance3.parse(pt.x);
|
|
6614
|
+
const y = distance3.parse(pt.y);
|
|
6615
|
+
if (x === void 0 || y === void 0) continue;
|
|
6616
|
+
minX = Math.min(minX, x);
|
|
6617
|
+
minY = Math.min(minY, y);
|
|
6618
|
+
maxX = Math.max(maxX, x);
|
|
6619
|
+
maxY = Math.max(maxY, y);
|
|
6620
|
+
}
|
|
6621
|
+
if (!Number.isFinite(minX) || !Number.isFinite(minY)) return;
|
|
6622
|
+
if (!Number.isFinite(maxX) || !Number.isFinite(maxY)) return;
|
|
6623
|
+
return { minX, minY, maxX, maxY };
|
|
6624
|
+
}
|
|
6625
|
+
|
|
6504
6626
|
// lib/pcb/convert-circuit-json-to-pcb-svg.ts
|
|
6505
6627
|
function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
6506
6628
|
const drawPaddingOutsideBoard = options?.drawPaddingOutsideBoard ?? true;
|
|
@@ -6555,20 +6677,34 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
6555
6677
|
boardMaxY,
|
|
6556
6678
|
hasBoardBounds
|
|
6557
6679
|
} = getPcbBoundsFromCircuitJson(circuitJson);
|
|
6558
|
-
const
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6680
|
+
const { boundsMinX, boundsMinY, boundsMaxX, boundsMaxY, padding } = getViewportBounds({
|
|
6681
|
+
circuitJson,
|
|
6682
|
+
drawPaddingOutsideBoard,
|
|
6683
|
+
baseBounds: {
|
|
6684
|
+
minX,
|
|
6685
|
+
minY,
|
|
6686
|
+
maxX,
|
|
6687
|
+
maxY,
|
|
6688
|
+
boardMinX,
|
|
6689
|
+
boardMinY,
|
|
6690
|
+
boardMaxX,
|
|
6691
|
+
boardMaxY,
|
|
6692
|
+
hasBoardBounds
|
|
6693
|
+
},
|
|
6694
|
+
viewportOptions: {
|
|
6695
|
+
viewport: options?.viewport,
|
|
6696
|
+
viewportTarget: options?.viewportTarget
|
|
6697
|
+
}
|
|
6698
|
+
});
|
|
6563
6699
|
const circuitWidth = boundsMaxX - boundsMinX + 2 * padding;
|
|
6564
6700
|
const circuitHeight = boundsMaxY - boundsMinY + 2 * padding;
|
|
6565
6701
|
let svgWidth = options?.width ?? 800;
|
|
6566
6702
|
let svgHeight = options?.height ?? 600;
|
|
6567
6703
|
if (options?.matchBoardAspectRatio) {
|
|
6568
|
-
const
|
|
6569
|
-
const
|
|
6570
|
-
if (
|
|
6571
|
-
const aspect =
|
|
6704
|
+
const viewportWidth = boundsMaxX - boundsMinX;
|
|
6705
|
+
const viewportHeight = boundsMaxY - boundsMinY;
|
|
6706
|
+
if (viewportWidth > 0 && viewportHeight > 0) {
|
|
6707
|
+
const aspect = viewportWidth / viewportHeight;
|
|
6572
6708
|
if (options?.width && !options?.height) {
|
|
6573
6709
|
svgHeight = options.width / aspect;
|
|
6574
6710
|
} else if (options?.height && !options?.width) {
|
|
@@ -13506,7 +13642,7 @@ function formatNumber2(value) {
|
|
|
13506
13642
|
}
|
|
13507
13643
|
|
|
13508
13644
|
// lib/pcb/convert-circuit-json-to-solder-paste-mask.ts
|
|
13509
|
-
import { distance as
|
|
13645
|
+
import { distance as distance5 } from "circuit-json";
|
|
13510
13646
|
import { stringify as stringify7 } from "svgson";
|
|
13511
13647
|
import {
|
|
13512
13648
|
applyToPoint as applyToPoint77,
|
|
@@ -13624,8 +13760,8 @@ function convertCircuitJsonToSolderPasteMask(circuitJson, options) {
|
|
|
13624
13760
|
}
|
|
13625
13761
|
} else if (item.type === "pcb_panel") {
|
|
13626
13762
|
const panel = item;
|
|
13627
|
-
const width =
|
|
13628
|
-
const height =
|
|
13763
|
+
const width = distance5.parse(panel.width);
|
|
13764
|
+
const height = distance5.parse(panel.height);
|
|
13629
13765
|
if (width !== void 0 && height !== void 0) {
|
|
13630
13766
|
const center = panel.center ?? { x: width / 2, y: height / 2 };
|
|
13631
13767
|
updateBounds(center, width, height);
|