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/index.js
CHANGED
|
@@ -6119,6 +6119,225 @@ var transformPCBElements = (elms, matrix) => {
|
|
|
6119
6119
|
}
|
|
6120
6120
|
return transformedElms;
|
|
6121
6121
|
};
|
|
6122
|
+
var mergeBounds = (currentBounds, nextBounds) => ({
|
|
6123
|
+
minX: Math.min(currentBounds.minX, nextBounds.minX),
|
|
6124
|
+
minY: Math.min(currentBounds.minY, nextBounds.minY),
|
|
6125
|
+
maxX: Math.max(currentBounds.maxX, nextBounds.maxX),
|
|
6126
|
+
maxY: Math.max(currentBounds.maxY, nextBounds.maxY)
|
|
6127
|
+
});
|
|
6128
|
+
var getCircleBounds = (x, y, diameter) => {
|
|
6129
|
+
const radius = diameter / 2;
|
|
6130
|
+
return {
|
|
6131
|
+
minX: x - radius,
|
|
6132
|
+
minY: y - radius,
|
|
6133
|
+
maxX: x + radius,
|
|
6134
|
+
maxY: y + radius
|
|
6135
|
+
};
|
|
6136
|
+
};
|
|
6137
|
+
var getRotatedRectBounds = (x, y, width, height, rotationDegrees) => {
|
|
6138
|
+
const halfWidth = width / 2;
|
|
6139
|
+
const halfHeight = height / 2;
|
|
6140
|
+
const theta = rotationDegrees * Math.PI / 180;
|
|
6141
|
+
const cosTheta = Math.cos(theta);
|
|
6142
|
+
const sinTheta = Math.sin(theta);
|
|
6143
|
+
const corners = [
|
|
6144
|
+
{ x: -halfWidth, y: -halfHeight },
|
|
6145
|
+
{ x: halfWidth, y: -halfHeight },
|
|
6146
|
+
{ x: halfWidth, y: halfHeight },
|
|
6147
|
+
{ x: -halfWidth, y: halfHeight }
|
|
6148
|
+
].map((corner) => ({
|
|
6149
|
+
x: x + corner.x * cosTheta - corner.y * sinTheta,
|
|
6150
|
+
y: y + corner.x * sinTheta + corner.y * cosTheta
|
|
6151
|
+
}));
|
|
6152
|
+
return {
|
|
6153
|
+
minX: Math.min(...corners.map((corner) => corner.x)),
|
|
6154
|
+
minY: Math.min(...corners.map((corner) => corner.y)),
|
|
6155
|
+
maxX: Math.max(...corners.map((corner) => corner.x)),
|
|
6156
|
+
maxY: Math.max(...corners.map((corner) => corner.y))
|
|
6157
|
+
};
|
|
6158
|
+
};
|
|
6159
|
+
var getRotatedOvalBounds = (x, y, width, height, rotationDegrees) => {
|
|
6160
|
+
const radiusX = width / 2;
|
|
6161
|
+
const radiusY = height / 2;
|
|
6162
|
+
const theta = rotationDegrees * Math.PI / 180;
|
|
6163
|
+
const cosTheta = Math.cos(theta);
|
|
6164
|
+
const sinTheta = Math.sin(theta);
|
|
6165
|
+
const halfWidth = Math.hypot(radiusX * cosTheta, radiusY * sinTheta);
|
|
6166
|
+
const halfHeight = Math.hypot(radiusX * sinTheta, radiusY * cosTheta);
|
|
6167
|
+
return {
|
|
6168
|
+
minX: x - halfWidth,
|
|
6169
|
+
minY: y - halfHeight,
|
|
6170
|
+
maxX: x + halfWidth,
|
|
6171
|
+
maxY: y + halfHeight
|
|
6172
|
+
};
|
|
6173
|
+
};
|
|
6174
|
+
var getRotatedPillBounds = (x, y, width, height, rotationDegrees) => {
|
|
6175
|
+
const radius = Math.min(width, height) / 2;
|
|
6176
|
+
const halfLineLength = Math.max(width, height) / 2 - radius;
|
|
6177
|
+
const theta = rotationDegrees * Math.PI / 180;
|
|
6178
|
+
const axis = width >= height ? { x: halfLineLength, y: 0 } : { x: 0, y: halfLineLength };
|
|
6179
|
+
const rotatedAxis = {
|
|
6180
|
+
x: axis.x * Math.cos(theta) - axis.y * Math.sin(theta),
|
|
6181
|
+
y: axis.x * Math.sin(theta) + axis.y * Math.cos(theta)
|
|
6182
|
+
};
|
|
6183
|
+
const halfWidth = Math.abs(rotatedAxis.x) + radius;
|
|
6184
|
+
const halfHeight = Math.abs(rotatedAxis.y) + radius;
|
|
6185
|
+
return {
|
|
6186
|
+
minX: x - halfWidth,
|
|
6187
|
+
minY: y - halfHeight,
|
|
6188
|
+
maxX: x + halfWidth,
|
|
6189
|
+
maxY: y + halfHeight
|
|
6190
|
+
};
|
|
6191
|
+
};
|
|
6192
|
+
var getBoundsFromPoints2 = (points) => {
|
|
6193
|
+
if (points.length === 0) return null;
|
|
6194
|
+
return {
|
|
6195
|
+
minX: Math.min(...points.map((point2) => point2.x)),
|
|
6196
|
+
minY: Math.min(...points.map((point2) => point2.y)),
|
|
6197
|
+
maxX: Math.max(...points.map((point2) => point2.x)),
|
|
6198
|
+
maxY: Math.max(...points.map((point2) => point2.y))
|
|
6199
|
+
};
|
|
6200
|
+
};
|
|
6201
|
+
var getRoutePoints = (route) => {
|
|
6202
|
+
if (!Array.isArray(route)) return [];
|
|
6203
|
+
return route.flatMap((point2) => {
|
|
6204
|
+
if (!point2 || typeof point2 !== "object") return [];
|
|
6205
|
+
if ("x" in point2 && "y" in point2 && typeof point2.x === "number" && typeof point2.y === "number") {
|
|
6206
|
+
return [{ x: point2.x, y: point2.y }];
|
|
6207
|
+
}
|
|
6208
|
+
if ("start" in point2 && "end" in point2) {
|
|
6209
|
+
const positions = [point2.start, point2.end];
|
|
6210
|
+
return positions.filter(
|
|
6211
|
+
(position2) => Boolean(
|
|
6212
|
+
position2 && typeof position2 === "object" && "x" in position2 && "y" in position2 && typeof position2.x === "number" && typeof position2.y === "number"
|
|
6213
|
+
)
|
|
6214
|
+
);
|
|
6215
|
+
}
|
|
6216
|
+
return [];
|
|
6217
|
+
});
|
|
6218
|
+
};
|
|
6219
|
+
var getPcbElementBounds = (elm) => {
|
|
6220
|
+
if (!elm.type.startsWith("pcb_")) return null;
|
|
6221
|
+
if (elm.type === "pcb_smtpad" && elm.shape === "polygon" && Array.isArray(elm.points)) {
|
|
6222
|
+
return getBoundsFromPoints2(elm.points);
|
|
6223
|
+
}
|
|
6224
|
+
if (elm.type === "pcb_hole" && elm.hole_shape === "circle") {
|
|
6225
|
+
return getCircleBounds(elm.x, elm.y, elm.hole_diameter);
|
|
6226
|
+
}
|
|
6227
|
+
if (elm.type === "pcb_plated_hole") {
|
|
6228
|
+
let platedHoleBounds;
|
|
6229
|
+
if ("outer_diameter" in elm && typeof elm.outer_diameter === "number") {
|
|
6230
|
+
platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.outer_diameter);
|
|
6231
|
+
} else if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
|
|
6232
|
+
platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.hole_diameter);
|
|
6233
|
+
}
|
|
6234
|
+
if ((elm.shape === "oval" || elm.shape === "pill") && typeof elm.outer_width === "number" && typeof elm.outer_height === "number") {
|
|
6235
|
+
const getOuterBounds = elm.shape === "pill" ? getRotatedPillBounds : getRotatedOvalBounds;
|
|
6236
|
+
platedHoleBounds = getOuterBounds(
|
|
6237
|
+
elm.x,
|
|
6238
|
+
elm.y,
|
|
6239
|
+
elm.outer_width,
|
|
6240
|
+
elm.outer_height,
|
|
6241
|
+
elm.ccw_rotation ?? 0
|
|
6242
|
+
);
|
|
6243
|
+
}
|
|
6244
|
+
if ("rect_pad_width" in elm && typeof elm.rect_pad_width === "number" && "rect_pad_height" in elm && typeof elm.rect_pad_height === "number") {
|
|
6245
|
+
const rectBounds = getRotatedRectBounds(
|
|
6246
|
+
elm.x,
|
|
6247
|
+
elm.y,
|
|
6248
|
+
elm.rect_pad_width,
|
|
6249
|
+
elm.rect_pad_height,
|
|
6250
|
+
"rect_ccw_rotation" in elm ? elm.rect_ccw_rotation ?? 0 : 0
|
|
6251
|
+
);
|
|
6252
|
+
platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, rectBounds) : rectBounds;
|
|
6253
|
+
}
|
|
6254
|
+
if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
|
|
6255
|
+
const drillBounds = getCircleBounds(
|
|
6256
|
+
elm.x + ("hole_offset_x" in elm ? elm.hole_offset_x ?? 0 : 0),
|
|
6257
|
+
elm.y + ("hole_offset_y" in elm ? elm.hole_offset_y ?? 0 : 0),
|
|
6258
|
+
elm.hole_diameter
|
|
6259
|
+
);
|
|
6260
|
+
platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, drillBounds) : drillBounds;
|
|
6261
|
+
}
|
|
6262
|
+
if (platedHoleBounds) return platedHoleBounds;
|
|
6263
|
+
}
|
|
6264
|
+
const elementRecord = elm;
|
|
6265
|
+
const routeBounds = getBoundsFromPoints2(getRoutePoints(elementRecord.route));
|
|
6266
|
+
if (routeBounds) return routeBounds;
|
|
6267
|
+
const outlineBounds = getBoundsFromPoints2(
|
|
6268
|
+
getRoutePoints(elementRecord.outline)
|
|
6269
|
+
);
|
|
6270
|
+
if (outlineBounds) return outlineBounds;
|
|
6271
|
+
const pointsBounds = getBoundsFromPoints2(getRoutePoints(elementRecord.points));
|
|
6272
|
+
if (pointsBounds) return pointsBounds;
|
|
6273
|
+
let centerX;
|
|
6274
|
+
let centerY;
|
|
6275
|
+
let width;
|
|
6276
|
+
let height;
|
|
6277
|
+
if ("x" in elm && "y" in elm) {
|
|
6278
|
+
centerX = Number(elm.x);
|
|
6279
|
+
centerY = Number(elm.y);
|
|
6280
|
+
}
|
|
6281
|
+
if ("outer_diameter" in elm) {
|
|
6282
|
+
width = Number(elm.outer_diameter);
|
|
6283
|
+
height = Number(elm.outer_diameter);
|
|
6284
|
+
}
|
|
6285
|
+
if ("width" in elm) {
|
|
6286
|
+
width = Number(elm.width);
|
|
6287
|
+
}
|
|
6288
|
+
if ("height" in elm) {
|
|
6289
|
+
height = Number(elm.height);
|
|
6290
|
+
}
|
|
6291
|
+
if ("center" in elm && elm.center && typeof elm.center === "object" && "x" in elm.center && "y" in elm.center) {
|
|
6292
|
+
centerX = Number(elm.center.x);
|
|
6293
|
+
centerY = Number(elm.center.y);
|
|
6294
|
+
}
|
|
6295
|
+
let rotation2 = 0;
|
|
6296
|
+
if ("rotation" in elm && typeof elm.rotation === "number") {
|
|
6297
|
+
rotation2 = elm.rotation;
|
|
6298
|
+
}
|
|
6299
|
+
if ("ccw_rotation" in elm && typeof elm.ccw_rotation === "number") {
|
|
6300
|
+
rotation2 = elm.ccw_rotation;
|
|
6301
|
+
}
|
|
6302
|
+
if (centerX !== void 0 && centerY !== void 0) {
|
|
6303
|
+
if (width !== void 0 && height !== void 0) {
|
|
6304
|
+
return rotation2 ? getRotatedRectBounds(centerX, centerY, width, height, rotation2) : {
|
|
6305
|
+
minX: centerX - width / 2,
|
|
6306
|
+
minY: centerY - height / 2,
|
|
6307
|
+
maxX: centerX + width / 2,
|
|
6308
|
+
maxY: centerY + height / 2
|
|
6309
|
+
};
|
|
6310
|
+
}
|
|
6311
|
+
if ("radius" in elm && typeof elm.radius === "number") {
|
|
6312
|
+
return getCircleBounds(centerX, centerY, elm.radius * 2);
|
|
6313
|
+
}
|
|
6314
|
+
return { minX: centerX, minY: centerY, maxX: centerX, maxY: centerY };
|
|
6315
|
+
}
|
|
6316
|
+
const anchoredPoint = [elementRecord.anchor_position, elementRecord.position].filter(
|
|
6317
|
+
(position2) => Boolean(
|
|
6318
|
+
position2 && typeof position2 === "object" && "x" in position2 && "y" in position2 && typeof position2.x === "number" && typeof position2.y === "number"
|
|
6319
|
+
)
|
|
6320
|
+
).at(0);
|
|
6321
|
+
return anchoredPoint ? {
|
|
6322
|
+
minX: anchoredPoint.x,
|
|
6323
|
+
minY: anchoredPoint.y,
|
|
6324
|
+
maxX: anchoredPoint.x,
|
|
6325
|
+
maxY: anchoredPoint.y
|
|
6326
|
+
} : null;
|
|
6327
|
+
};
|
|
6328
|
+
var getBoundsOfPcbElements = (elements) => {
|
|
6329
|
+
let bounds = {
|
|
6330
|
+
minX: Number.POSITIVE_INFINITY,
|
|
6331
|
+
minY: Number.POSITIVE_INFINITY,
|
|
6332
|
+
maxX: Number.NEGATIVE_INFINITY,
|
|
6333
|
+
maxY: Number.NEGATIVE_INFINITY
|
|
6334
|
+
};
|
|
6335
|
+
for (const element of elements) {
|
|
6336
|
+
const elementBounds = getPcbElementBounds(element);
|
|
6337
|
+
if (elementBounds) bounds = mergeBounds(bounds, elementBounds);
|
|
6338
|
+
}
|
|
6339
|
+
return bounds;
|
|
6340
|
+
};
|
|
6122
6341
|
function stringHash(str) {
|
|
6123
6342
|
let hash = 0;
|
|
6124
6343
|
if (str.length == 0) return hash;
|
|
@@ -6805,6 +7024,39 @@ var parseCadOffsetsFromSvgNode = (svgNode) => {
|
|
|
6805
7024
|
})()
|
|
6806
7025
|
};
|
|
6807
7026
|
};
|
|
7027
|
+
var getCadModelOutlineBounds = (svgNode) => {
|
|
7028
|
+
const points = [];
|
|
7029
|
+
for (const childNode of svgNode?.svgData.childNodes ?? []) {
|
|
7030
|
+
if (typeof childNode !== "object" || childNode === null) continue;
|
|
7031
|
+
const attrs = childNode.attrs;
|
|
7032
|
+
if (typeof attrs !== "object" || attrs === null) continue;
|
|
7033
|
+
const rawPoints = attrs.points;
|
|
7034
|
+
if (typeof rawPoints !== "string") continue;
|
|
7035
|
+
const coordinates = rawPoints.trim().split(/\s+/).map(Number);
|
|
7036
|
+
for (let index = 0; index + 1 < coordinates.length; index += 2) {
|
|
7037
|
+
const x = coordinates[index];
|
|
7038
|
+
const y = coordinates[index + 1];
|
|
7039
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
|
|
7040
|
+
points.push({ x: milx10(x), y: milx10(y) });
|
|
7041
|
+
}
|
|
7042
|
+
}
|
|
7043
|
+
if (points.length === 0) return void 0;
|
|
7044
|
+
return {
|
|
7045
|
+
minX: Math.min(...points.map((point2) => point2.x)),
|
|
7046
|
+
minY: Math.min(...points.map((point2) => point2.y)),
|
|
7047
|
+
maxX: Math.max(...points.map((point2) => point2.x)),
|
|
7048
|
+
maxY: Math.max(...points.map((point2) => point2.y))
|
|
7049
|
+
};
|
|
7050
|
+
};
|
|
7051
|
+
var unionBounds = (first, second) => {
|
|
7052
|
+
if (!second) return first;
|
|
7053
|
+
return {
|
|
7054
|
+
minX: Math.min(first.minX, second.minX),
|
|
7055
|
+
minY: Math.min(first.minY, second.minY),
|
|
7056
|
+
maxX: Math.max(first.maxX, second.maxX),
|
|
7057
|
+
maxY: Math.max(first.maxY, second.maxY)
|
|
7058
|
+
};
|
|
7059
|
+
};
|
|
6808
7060
|
var readModelHeightMm = (raw) => {
|
|
6809
7061
|
const fallback = 3.5;
|
|
6810
7062
|
if (raw == null) return fallback;
|
|
@@ -7396,17 +7648,29 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
|
|
|
7396
7648
|
);
|
|
7397
7649
|
}
|
|
7398
7650
|
const hasExplicitCourtyard = circuitElements.some(
|
|
7399
|
-
(e) => e.type === "pcb_courtyard_outline"
|
|
7651
|
+
(e) => e.type === "pcb_courtyard_outline" || e.type === "pcb_courtyard_rect"
|
|
7400
7652
|
);
|
|
7401
7653
|
if (!hasExplicitCourtyard) {
|
|
7402
7654
|
const bbox = easyEdaJson.packageDetail.dataStr.BBox;
|
|
7403
|
-
|
|
7655
|
+
const modelOutlineBounds = getCadModelOutlineBounds(svgNode);
|
|
7656
|
+
const packageElements = circuitElements.filter(
|
|
7657
|
+
(element) => element.type === "pcb_smtpad" || element.type === "pcb_plated_hole" || element.type === "pcb_hole" || element.type === "pcb_via"
|
|
7658
|
+
);
|
|
7659
|
+
const packageElementBounds = packageElements.length > 0 ? getBoundsOfPcbElements(packageElements) : void 0;
|
|
7660
|
+
const fallbackBounds = bbox ? {
|
|
7661
|
+
minX: milx10(bbox.x),
|
|
7662
|
+
minY: milx10(bbox.y),
|
|
7663
|
+
maxX: milx10(bbox.x + bbox.width),
|
|
7664
|
+
maxY: milx10(bbox.y + bbox.height)
|
|
7665
|
+
} : void 0;
|
|
7666
|
+
const courtyardBounds = modelOutlineBounds ? unionBounds(modelOutlineBounds, packageElementBounds) : fallbackBounds;
|
|
7667
|
+
if (courtyardBounds) {
|
|
7404
7668
|
const strokeWidth = 0.05;
|
|
7405
7669
|
const margin = 0.25;
|
|
7406
|
-
const x1 =
|
|
7407
|
-
const y1 =
|
|
7408
|
-
const x2 =
|
|
7409
|
-
const y2 =
|
|
7670
|
+
const x1 = courtyardBounds.minX - margin;
|
|
7671
|
+
const y1 = courtyardBounds.minY - margin;
|
|
7672
|
+
const x2 = courtyardBounds.maxX + margin;
|
|
7673
|
+
const y2 = courtyardBounds.maxY + margin;
|
|
7410
7674
|
circuitElements.push(
|
|
7411
7675
|
pcb_courtyard_outline.parse({
|
|
7412
7676
|
type: "pcb_courtyard_outline",
|