easyeda 0.0.357 → 0.0.358
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/browser/index.js +272 -8
- package/dist/browser/index.js.map +1 -1
- package/dist/index.js +270 -6
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +271 -7
- package/dist/main.cjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -9847,6 +9847,225 @@ var transformPCBElements = (elms, matrix) => {
|
|
|
9847
9847
|
}
|
|
9848
9848
|
return transformedElms;
|
|
9849
9849
|
};
|
|
9850
|
+
var mergeBounds = (currentBounds, nextBounds) => ({
|
|
9851
|
+
minX: Math.min(currentBounds.minX, nextBounds.minX),
|
|
9852
|
+
minY: Math.min(currentBounds.minY, nextBounds.minY),
|
|
9853
|
+
maxX: Math.max(currentBounds.maxX, nextBounds.maxX),
|
|
9854
|
+
maxY: Math.max(currentBounds.maxY, nextBounds.maxY)
|
|
9855
|
+
});
|
|
9856
|
+
var getCircleBounds = (x, y, diameter) => {
|
|
9857
|
+
const radius = diameter / 2;
|
|
9858
|
+
return {
|
|
9859
|
+
minX: x - radius,
|
|
9860
|
+
minY: y - radius,
|
|
9861
|
+
maxX: x + radius,
|
|
9862
|
+
maxY: y + radius
|
|
9863
|
+
};
|
|
9864
|
+
};
|
|
9865
|
+
var getRotatedRectBounds = (x, y, width, height, rotationDegrees) => {
|
|
9866
|
+
const halfWidth = width / 2;
|
|
9867
|
+
const halfHeight = height / 2;
|
|
9868
|
+
const theta = rotationDegrees * Math.PI / 180;
|
|
9869
|
+
const cosTheta = Math.cos(theta);
|
|
9870
|
+
const sinTheta = Math.sin(theta);
|
|
9871
|
+
const corners = [
|
|
9872
|
+
{ x: -halfWidth, y: -halfHeight },
|
|
9873
|
+
{ x: halfWidth, y: -halfHeight },
|
|
9874
|
+
{ x: halfWidth, y: halfHeight },
|
|
9875
|
+
{ x: -halfWidth, y: halfHeight }
|
|
9876
|
+
].map((corner) => ({
|
|
9877
|
+
x: x + corner.x * cosTheta - corner.y * sinTheta,
|
|
9878
|
+
y: y + corner.x * sinTheta + corner.y * cosTheta
|
|
9879
|
+
}));
|
|
9880
|
+
return {
|
|
9881
|
+
minX: Math.min(...corners.map((corner) => corner.x)),
|
|
9882
|
+
minY: Math.min(...corners.map((corner) => corner.y)),
|
|
9883
|
+
maxX: Math.max(...corners.map((corner) => corner.x)),
|
|
9884
|
+
maxY: Math.max(...corners.map((corner) => corner.y))
|
|
9885
|
+
};
|
|
9886
|
+
};
|
|
9887
|
+
var getRotatedOvalBounds = (x, y, width, height, rotationDegrees) => {
|
|
9888
|
+
const radiusX = width / 2;
|
|
9889
|
+
const radiusY = height / 2;
|
|
9890
|
+
const theta = rotationDegrees * Math.PI / 180;
|
|
9891
|
+
const cosTheta = Math.cos(theta);
|
|
9892
|
+
const sinTheta = Math.sin(theta);
|
|
9893
|
+
const halfWidth = Math.hypot(radiusX * cosTheta, radiusY * sinTheta);
|
|
9894
|
+
const halfHeight = Math.hypot(radiusX * sinTheta, radiusY * cosTheta);
|
|
9895
|
+
return {
|
|
9896
|
+
minX: x - halfWidth,
|
|
9897
|
+
minY: y - halfHeight,
|
|
9898
|
+
maxX: x + halfWidth,
|
|
9899
|
+
maxY: y + halfHeight
|
|
9900
|
+
};
|
|
9901
|
+
};
|
|
9902
|
+
var getRotatedPillBounds = (x, y, width, height, rotationDegrees) => {
|
|
9903
|
+
const radius = Math.min(width, height) / 2;
|
|
9904
|
+
const halfLineLength = Math.max(width, height) / 2 - radius;
|
|
9905
|
+
const theta = rotationDegrees * Math.PI / 180;
|
|
9906
|
+
const axis = width >= height ? { x: halfLineLength, y: 0 } : { x: 0, y: halfLineLength };
|
|
9907
|
+
const rotatedAxis = {
|
|
9908
|
+
x: axis.x * Math.cos(theta) - axis.y * Math.sin(theta),
|
|
9909
|
+
y: axis.x * Math.sin(theta) + axis.y * Math.cos(theta)
|
|
9910
|
+
};
|
|
9911
|
+
const halfWidth = Math.abs(rotatedAxis.x) + radius;
|
|
9912
|
+
const halfHeight = Math.abs(rotatedAxis.y) + radius;
|
|
9913
|
+
return {
|
|
9914
|
+
minX: x - halfWidth,
|
|
9915
|
+
minY: y - halfHeight,
|
|
9916
|
+
maxX: x + halfWidth,
|
|
9917
|
+
maxY: y + halfHeight
|
|
9918
|
+
};
|
|
9919
|
+
};
|
|
9920
|
+
var getBoundsFromPoints = (points) => {
|
|
9921
|
+
if (points.length === 0) return null;
|
|
9922
|
+
return {
|
|
9923
|
+
minX: Math.min(...points.map((point2) => point2.x)),
|
|
9924
|
+
minY: Math.min(...points.map((point2) => point2.y)),
|
|
9925
|
+
maxX: Math.max(...points.map((point2) => point2.x)),
|
|
9926
|
+
maxY: Math.max(...points.map((point2) => point2.y))
|
|
9927
|
+
};
|
|
9928
|
+
};
|
|
9929
|
+
var getRoutePoints = (route) => {
|
|
9930
|
+
if (!Array.isArray(route)) return [];
|
|
9931
|
+
return route.flatMap((point2) => {
|
|
9932
|
+
if (!point2 || typeof point2 !== "object") return [];
|
|
9933
|
+
if ("x" in point2 && "y" in point2 && typeof point2.x === "number" && typeof point2.y === "number") {
|
|
9934
|
+
return [{ x: point2.x, y: point2.y }];
|
|
9935
|
+
}
|
|
9936
|
+
if ("start" in point2 && "end" in point2) {
|
|
9937
|
+
const positions = [point2.start, point2.end];
|
|
9938
|
+
return positions.filter(
|
|
9939
|
+
(position2) => Boolean(
|
|
9940
|
+
position2 && typeof position2 === "object" && "x" in position2 && "y" in position2 && typeof position2.x === "number" && typeof position2.y === "number"
|
|
9941
|
+
)
|
|
9942
|
+
);
|
|
9943
|
+
}
|
|
9944
|
+
return [];
|
|
9945
|
+
});
|
|
9946
|
+
};
|
|
9947
|
+
var getPcbElementBounds = (elm) => {
|
|
9948
|
+
if (!elm.type.startsWith("pcb_")) return null;
|
|
9949
|
+
if (elm.type === "pcb_smtpad" && elm.shape === "polygon" && Array.isArray(elm.points)) {
|
|
9950
|
+
return getBoundsFromPoints(elm.points);
|
|
9951
|
+
}
|
|
9952
|
+
if (elm.type === "pcb_hole" && elm.hole_shape === "circle") {
|
|
9953
|
+
return getCircleBounds(elm.x, elm.y, elm.hole_diameter);
|
|
9954
|
+
}
|
|
9955
|
+
if (elm.type === "pcb_plated_hole") {
|
|
9956
|
+
let platedHoleBounds;
|
|
9957
|
+
if ("outer_diameter" in elm && typeof elm.outer_diameter === "number") {
|
|
9958
|
+
platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.outer_diameter);
|
|
9959
|
+
} else if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
|
|
9960
|
+
platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.hole_diameter);
|
|
9961
|
+
}
|
|
9962
|
+
if ((elm.shape === "oval" || elm.shape === "pill") && typeof elm.outer_width === "number" && typeof elm.outer_height === "number") {
|
|
9963
|
+
const getOuterBounds = elm.shape === "pill" ? getRotatedPillBounds : getRotatedOvalBounds;
|
|
9964
|
+
platedHoleBounds = getOuterBounds(
|
|
9965
|
+
elm.x,
|
|
9966
|
+
elm.y,
|
|
9967
|
+
elm.outer_width,
|
|
9968
|
+
elm.outer_height,
|
|
9969
|
+
elm.ccw_rotation ?? 0
|
|
9970
|
+
);
|
|
9971
|
+
}
|
|
9972
|
+
if ("rect_pad_width" in elm && typeof elm.rect_pad_width === "number" && "rect_pad_height" in elm && typeof elm.rect_pad_height === "number") {
|
|
9973
|
+
const rectBounds = getRotatedRectBounds(
|
|
9974
|
+
elm.x,
|
|
9975
|
+
elm.y,
|
|
9976
|
+
elm.rect_pad_width,
|
|
9977
|
+
elm.rect_pad_height,
|
|
9978
|
+
"rect_ccw_rotation" in elm ? elm.rect_ccw_rotation ?? 0 : 0
|
|
9979
|
+
);
|
|
9980
|
+
platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, rectBounds) : rectBounds;
|
|
9981
|
+
}
|
|
9982
|
+
if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
|
|
9983
|
+
const drillBounds = getCircleBounds(
|
|
9984
|
+
elm.x + ("hole_offset_x" in elm ? elm.hole_offset_x ?? 0 : 0),
|
|
9985
|
+
elm.y + ("hole_offset_y" in elm ? elm.hole_offset_y ?? 0 : 0),
|
|
9986
|
+
elm.hole_diameter
|
|
9987
|
+
);
|
|
9988
|
+
platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, drillBounds) : drillBounds;
|
|
9989
|
+
}
|
|
9990
|
+
if (platedHoleBounds) return platedHoleBounds;
|
|
9991
|
+
}
|
|
9992
|
+
const elementRecord = elm;
|
|
9993
|
+
const routeBounds = getBoundsFromPoints(getRoutePoints(elementRecord.route));
|
|
9994
|
+
if (routeBounds) return routeBounds;
|
|
9995
|
+
const outlineBounds = getBoundsFromPoints(
|
|
9996
|
+
getRoutePoints(elementRecord.outline)
|
|
9997
|
+
);
|
|
9998
|
+
if (outlineBounds) return outlineBounds;
|
|
9999
|
+
const pointsBounds = getBoundsFromPoints(getRoutePoints(elementRecord.points));
|
|
10000
|
+
if (pointsBounds) return pointsBounds;
|
|
10001
|
+
let centerX;
|
|
10002
|
+
let centerY;
|
|
10003
|
+
let width;
|
|
10004
|
+
let height;
|
|
10005
|
+
if ("x" in elm && "y" in elm) {
|
|
10006
|
+
centerX = Number(elm.x);
|
|
10007
|
+
centerY = Number(elm.y);
|
|
10008
|
+
}
|
|
10009
|
+
if ("outer_diameter" in elm) {
|
|
10010
|
+
width = Number(elm.outer_diameter);
|
|
10011
|
+
height = Number(elm.outer_diameter);
|
|
10012
|
+
}
|
|
10013
|
+
if ("width" in elm) {
|
|
10014
|
+
width = Number(elm.width);
|
|
10015
|
+
}
|
|
10016
|
+
if ("height" in elm) {
|
|
10017
|
+
height = Number(elm.height);
|
|
10018
|
+
}
|
|
10019
|
+
if ("center" in elm && elm.center && typeof elm.center === "object" && "x" in elm.center && "y" in elm.center) {
|
|
10020
|
+
centerX = Number(elm.center.x);
|
|
10021
|
+
centerY = Number(elm.center.y);
|
|
10022
|
+
}
|
|
10023
|
+
let rotation2 = 0;
|
|
10024
|
+
if ("rotation" in elm && typeof elm.rotation === "number") {
|
|
10025
|
+
rotation2 = elm.rotation;
|
|
10026
|
+
}
|
|
10027
|
+
if ("ccw_rotation" in elm && typeof elm.ccw_rotation === "number") {
|
|
10028
|
+
rotation2 = elm.ccw_rotation;
|
|
10029
|
+
}
|
|
10030
|
+
if (centerX !== void 0 && centerY !== void 0) {
|
|
10031
|
+
if (width !== void 0 && height !== void 0) {
|
|
10032
|
+
return rotation2 ? getRotatedRectBounds(centerX, centerY, width, height, rotation2) : {
|
|
10033
|
+
minX: centerX - width / 2,
|
|
10034
|
+
minY: centerY - height / 2,
|
|
10035
|
+
maxX: centerX + width / 2,
|
|
10036
|
+
maxY: centerY + height / 2
|
|
10037
|
+
};
|
|
10038
|
+
}
|
|
10039
|
+
if ("radius" in elm && typeof elm.radius === "number") {
|
|
10040
|
+
return getCircleBounds(centerX, centerY, elm.radius * 2);
|
|
10041
|
+
}
|
|
10042
|
+
return { minX: centerX, minY: centerY, maxX: centerX, maxY: centerY };
|
|
10043
|
+
}
|
|
10044
|
+
const anchoredPoint = [elementRecord.anchor_position, elementRecord.position].filter(
|
|
10045
|
+
(position2) => Boolean(
|
|
10046
|
+
position2 && typeof position2 === "object" && "x" in position2 && "y" in position2 && typeof position2.x === "number" && typeof position2.y === "number"
|
|
10047
|
+
)
|
|
10048
|
+
).at(0);
|
|
10049
|
+
return anchoredPoint ? {
|
|
10050
|
+
minX: anchoredPoint.x,
|
|
10051
|
+
minY: anchoredPoint.y,
|
|
10052
|
+
maxX: anchoredPoint.x,
|
|
10053
|
+
maxY: anchoredPoint.y
|
|
10054
|
+
} : null;
|
|
10055
|
+
};
|
|
10056
|
+
var getBoundsOfPcbElements = (elements) => {
|
|
10057
|
+
let bounds = {
|
|
10058
|
+
minX: Number.POSITIVE_INFINITY,
|
|
10059
|
+
minY: Number.POSITIVE_INFINITY,
|
|
10060
|
+
maxX: Number.NEGATIVE_INFINITY,
|
|
10061
|
+
maxY: Number.NEGATIVE_INFINITY
|
|
10062
|
+
};
|
|
10063
|
+
for (const element of elements) {
|
|
10064
|
+
const elementBounds = getPcbElementBounds(element);
|
|
10065
|
+
if (elementBounds) bounds = mergeBounds(bounds, elementBounds);
|
|
10066
|
+
}
|
|
10067
|
+
return bounds;
|
|
10068
|
+
};
|
|
9850
10069
|
function stringHash(str) {
|
|
9851
10070
|
let hash = 0;
|
|
9852
10071
|
if (str.length == 0) return hash;
|
|
@@ -10096,7 +10315,7 @@ var getBoundsCenter = (bounds) => ({
|
|
|
10096
10315
|
});
|
|
10097
10316
|
|
|
10098
10317
|
// node_modules/@tscircuit/math-utils/dist/chunk-5N7UJNVK.js
|
|
10099
|
-
var
|
|
10318
|
+
var getBoundsFromPoints2 = (points) => {
|
|
10100
10319
|
if (points.length === 0) {
|
|
10101
10320
|
return null;
|
|
10102
10321
|
}
|
|
@@ -10557,7 +10776,7 @@ var getEasyEdaModelOriginOnBoardMm = ({
|
|
|
10557
10776
|
}
|
|
10558
10777
|
let modelOriginMm = null;
|
|
10559
10778
|
if (points.length > 0) {
|
|
10560
|
-
const bounds =
|
|
10779
|
+
const bounds = getBoundsFromPoints2(points);
|
|
10561
10780
|
modelOriginMm = bounds ? getBoundsCenter(bounds) : null;
|
|
10562
10781
|
} else {
|
|
10563
10782
|
const [originX, originY] = String(svgNode.svgData.attrs?.c_origin ?? "0,0").split(",").map((value) => Number(value.trim()));
|
|
@@ -10648,6 +10867,39 @@ var parseCadOffsetsFromSvgNode = (svgNode) => {
|
|
|
10648
10867
|
})()
|
|
10649
10868
|
};
|
|
10650
10869
|
};
|
|
10870
|
+
var getCadModelOutlineBounds = (svgNode) => {
|
|
10871
|
+
const points = [];
|
|
10872
|
+
for (const childNode of svgNode?.svgData.childNodes ?? []) {
|
|
10873
|
+
if (typeof childNode !== "object" || childNode === null) continue;
|
|
10874
|
+
const attrs = childNode.attrs;
|
|
10875
|
+
if (typeof attrs !== "object" || attrs === null) continue;
|
|
10876
|
+
const rawPoints = attrs.points;
|
|
10877
|
+
if (typeof rawPoints !== "string") continue;
|
|
10878
|
+
const coordinates = rawPoints.trim().split(/\s+/).map(Number);
|
|
10879
|
+
for (let index = 0; index + 1 < coordinates.length; index += 2) {
|
|
10880
|
+
const x = coordinates[index];
|
|
10881
|
+
const y = coordinates[index + 1];
|
|
10882
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
|
|
10883
|
+
points.push({ x: milx10(x), y: milx10(y) });
|
|
10884
|
+
}
|
|
10885
|
+
}
|
|
10886
|
+
if (points.length === 0) return void 0;
|
|
10887
|
+
return {
|
|
10888
|
+
minX: Math.min(...points.map((point2) => point2.x)),
|
|
10889
|
+
minY: Math.min(...points.map((point2) => point2.y)),
|
|
10890
|
+
maxX: Math.max(...points.map((point2) => point2.x)),
|
|
10891
|
+
maxY: Math.max(...points.map((point2) => point2.y))
|
|
10892
|
+
};
|
|
10893
|
+
};
|
|
10894
|
+
var unionBounds = (first, second) => {
|
|
10895
|
+
if (!second) return first;
|
|
10896
|
+
return {
|
|
10897
|
+
minX: Math.min(first.minX, second.minX),
|
|
10898
|
+
minY: Math.min(first.minY, second.minY),
|
|
10899
|
+
maxX: Math.max(first.maxX, second.maxX),
|
|
10900
|
+
maxY: Math.max(first.maxY, second.maxY)
|
|
10901
|
+
};
|
|
10902
|
+
};
|
|
10651
10903
|
var readModelHeightMm = (raw) => {
|
|
10652
10904
|
const fallback = 3.5;
|
|
10653
10905
|
if (raw == null) return fallback;
|
|
@@ -11239,17 +11491,29 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
|
|
|
11239
11491
|
);
|
|
11240
11492
|
}
|
|
11241
11493
|
const hasExplicitCourtyard = circuitElements.some(
|
|
11242
|
-
(e) => e.type === "pcb_courtyard_outline"
|
|
11494
|
+
(e) => e.type === "pcb_courtyard_outline" || e.type === "pcb_courtyard_rect"
|
|
11243
11495
|
);
|
|
11244
11496
|
if (!hasExplicitCourtyard) {
|
|
11245
11497
|
const bbox = easyEdaJson.packageDetail.dataStr.BBox;
|
|
11246
|
-
|
|
11498
|
+
const modelOutlineBounds = getCadModelOutlineBounds(svgNode);
|
|
11499
|
+
const packageElements = circuitElements.filter(
|
|
11500
|
+
(element) => element.type === "pcb_smtpad" || element.type === "pcb_plated_hole" || element.type === "pcb_hole" || element.type === "pcb_via"
|
|
11501
|
+
);
|
|
11502
|
+
const packageElementBounds = packageElements.length > 0 ? getBoundsOfPcbElements(packageElements) : void 0;
|
|
11503
|
+
const fallbackBounds = bbox ? {
|
|
11504
|
+
minX: milx10(bbox.x),
|
|
11505
|
+
minY: milx10(bbox.y),
|
|
11506
|
+
maxX: milx10(bbox.x + bbox.width),
|
|
11507
|
+
maxY: milx10(bbox.y + bbox.height)
|
|
11508
|
+
} : void 0;
|
|
11509
|
+
const courtyardBounds = modelOutlineBounds ? unionBounds(modelOutlineBounds, packageElementBounds) : fallbackBounds;
|
|
11510
|
+
if (courtyardBounds) {
|
|
11247
11511
|
const strokeWidth = 0.05;
|
|
11248
11512
|
const margin = 0.25;
|
|
11249
|
-
const x1 =
|
|
11250
|
-
const y1 =
|
|
11251
|
-
const x2 =
|
|
11252
|
-
const y2 =
|
|
11513
|
+
const x1 = courtyardBounds.minX - margin;
|
|
11514
|
+
const y1 = courtyardBounds.minY - margin;
|
|
11515
|
+
const x2 = courtyardBounds.maxX + margin;
|
|
11516
|
+
const y2 = courtyardBounds.maxY + margin;
|
|
11253
11517
|
circuitElements.push(
|
|
11254
11518
|
pcb_courtyard_outline.parse({
|
|
11255
11519
|
type: "pcb_courtyard_outline",
|