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/main.cjs
CHANGED
|
@@ -1078,7 +1078,7 @@ var import_promises = __toESM(require("fs/promises"), 1);
|
|
|
1078
1078
|
var package_default = {
|
|
1079
1079
|
name: "easyeda",
|
|
1080
1080
|
type: "module",
|
|
1081
|
-
version: "0.0.
|
|
1081
|
+
version: "0.0.357",
|
|
1082
1082
|
files: [
|
|
1083
1083
|
"dist"
|
|
1084
1084
|
],
|
|
@@ -7250,6 +7250,225 @@ var transformPCBElements = (elms, matrix) => {
|
|
|
7250
7250
|
}
|
|
7251
7251
|
return transformedElms;
|
|
7252
7252
|
};
|
|
7253
|
+
var mergeBounds = (currentBounds, nextBounds) => ({
|
|
7254
|
+
minX: Math.min(currentBounds.minX, nextBounds.minX),
|
|
7255
|
+
minY: Math.min(currentBounds.minY, nextBounds.minY),
|
|
7256
|
+
maxX: Math.max(currentBounds.maxX, nextBounds.maxX),
|
|
7257
|
+
maxY: Math.max(currentBounds.maxY, nextBounds.maxY)
|
|
7258
|
+
});
|
|
7259
|
+
var getCircleBounds = (x, y, diameter) => {
|
|
7260
|
+
const radius = diameter / 2;
|
|
7261
|
+
return {
|
|
7262
|
+
minX: x - radius,
|
|
7263
|
+
minY: y - radius,
|
|
7264
|
+
maxX: x + radius,
|
|
7265
|
+
maxY: y + radius
|
|
7266
|
+
};
|
|
7267
|
+
};
|
|
7268
|
+
var getRotatedRectBounds = (x, y, width, height, rotationDegrees) => {
|
|
7269
|
+
const halfWidth = width / 2;
|
|
7270
|
+
const halfHeight = height / 2;
|
|
7271
|
+
const theta = rotationDegrees * Math.PI / 180;
|
|
7272
|
+
const cosTheta = Math.cos(theta);
|
|
7273
|
+
const sinTheta = Math.sin(theta);
|
|
7274
|
+
const corners = [
|
|
7275
|
+
{ x: -halfWidth, y: -halfHeight },
|
|
7276
|
+
{ x: halfWidth, y: -halfHeight },
|
|
7277
|
+
{ x: halfWidth, y: halfHeight },
|
|
7278
|
+
{ x: -halfWidth, y: halfHeight }
|
|
7279
|
+
].map((corner) => ({
|
|
7280
|
+
x: x + corner.x * cosTheta - corner.y * sinTheta,
|
|
7281
|
+
y: y + corner.x * sinTheta + corner.y * cosTheta
|
|
7282
|
+
}));
|
|
7283
|
+
return {
|
|
7284
|
+
minX: Math.min(...corners.map((corner) => corner.x)),
|
|
7285
|
+
minY: Math.min(...corners.map((corner) => corner.y)),
|
|
7286
|
+
maxX: Math.max(...corners.map((corner) => corner.x)),
|
|
7287
|
+
maxY: Math.max(...corners.map((corner) => corner.y))
|
|
7288
|
+
};
|
|
7289
|
+
};
|
|
7290
|
+
var getRotatedOvalBounds = (x, y, width, height, rotationDegrees) => {
|
|
7291
|
+
const radiusX = width / 2;
|
|
7292
|
+
const radiusY = height / 2;
|
|
7293
|
+
const theta = rotationDegrees * Math.PI / 180;
|
|
7294
|
+
const cosTheta = Math.cos(theta);
|
|
7295
|
+
const sinTheta = Math.sin(theta);
|
|
7296
|
+
const halfWidth = Math.hypot(radiusX * cosTheta, radiusY * sinTheta);
|
|
7297
|
+
const halfHeight = Math.hypot(radiusX * sinTheta, radiusY * cosTheta);
|
|
7298
|
+
return {
|
|
7299
|
+
minX: x - halfWidth,
|
|
7300
|
+
minY: y - halfHeight,
|
|
7301
|
+
maxX: x + halfWidth,
|
|
7302
|
+
maxY: y + halfHeight
|
|
7303
|
+
};
|
|
7304
|
+
};
|
|
7305
|
+
var getRotatedPillBounds = (x, y, width, height, rotationDegrees) => {
|
|
7306
|
+
const radius = Math.min(width, height) / 2;
|
|
7307
|
+
const halfLineLength = Math.max(width, height) / 2 - radius;
|
|
7308
|
+
const theta = rotationDegrees * Math.PI / 180;
|
|
7309
|
+
const axis = width >= height ? { x: halfLineLength, y: 0 } : { x: 0, y: halfLineLength };
|
|
7310
|
+
const rotatedAxis = {
|
|
7311
|
+
x: axis.x * Math.cos(theta) - axis.y * Math.sin(theta),
|
|
7312
|
+
y: axis.x * Math.sin(theta) + axis.y * Math.cos(theta)
|
|
7313
|
+
};
|
|
7314
|
+
const halfWidth = Math.abs(rotatedAxis.x) + radius;
|
|
7315
|
+
const halfHeight = Math.abs(rotatedAxis.y) + radius;
|
|
7316
|
+
return {
|
|
7317
|
+
minX: x - halfWidth,
|
|
7318
|
+
minY: y - halfHeight,
|
|
7319
|
+
maxX: x + halfWidth,
|
|
7320
|
+
maxY: y + halfHeight
|
|
7321
|
+
};
|
|
7322
|
+
};
|
|
7323
|
+
var getBoundsFromPoints2 = (points) => {
|
|
7324
|
+
if (points.length === 0) return null;
|
|
7325
|
+
return {
|
|
7326
|
+
minX: Math.min(...points.map((point2) => point2.x)),
|
|
7327
|
+
minY: Math.min(...points.map((point2) => point2.y)),
|
|
7328
|
+
maxX: Math.max(...points.map((point2) => point2.x)),
|
|
7329
|
+
maxY: Math.max(...points.map((point2) => point2.y))
|
|
7330
|
+
};
|
|
7331
|
+
};
|
|
7332
|
+
var getRoutePoints = (route) => {
|
|
7333
|
+
if (!Array.isArray(route)) return [];
|
|
7334
|
+
return route.flatMap((point2) => {
|
|
7335
|
+
if (!point2 || typeof point2 !== "object") return [];
|
|
7336
|
+
if ("x" in point2 && "y" in point2 && typeof point2.x === "number" && typeof point2.y === "number") {
|
|
7337
|
+
return [{ x: point2.x, y: point2.y }];
|
|
7338
|
+
}
|
|
7339
|
+
if ("start" in point2 && "end" in point2) {
|
|
7340
|
+
const positions = [point2.start, point2.end];
|
|
7341
|
+
return positions.filter(
|
|
7342
|
+
(position2) => Boolean(
|
|
7343
|
+
position2 && typeof position2 === "object" && "x" in position2 && "y" in position2 && typeof position2.x === "number" && typeof position2.y === "number"
|
|
7344
|
+
)
|
|
7345
|
+
);
|
|
7346
|
+
}
|
|
7347
|
+
return [];
|
|
7348
|
+
});
|
|
7349
|
+
};
|
|
7350
|
+
var getPcbElementBounds = (elm) => {
|
|
7351
|
+
if (!elm.type.startsWith("pcb_")) return null;
|
|
7352
|
+
if (elm.type === "pcb_smtpad" && elm.shape === "polygon" && Array.isArray(elm.points)) {
|
|
7353
|
+
return getBoundsFromPoints2(elm.points);
|
|
7354
|
+
}
|
|
7355
|
+
if (elm.type === "pcb_hole" && elm.hole_shape === "circle") {
|
|
7356
|
+
return getCircleBounds(elm.x, elm.y, elm.hole_diameter);
|
|
7357
|
+
}
|
|
7358
|
+
if (elm.type === "pcb_plated_hole") {
|
|
7359
|
+
let platedHoleBounds;
|
|
7360
|
+
if ("outer_diameter" in elm && typeof elm.outer_diameter === "number") {
|
|
7361
|
+
platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.outer_diameter);
|
|
7362
|
+
} else if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
|
|
7363
|
+
platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.hole_diameter);
|
|
7364
|
+
}
|
|
7365
|
+
if ((elm.shape === "oval" || elm.shape === "pill") && typeof elm.outer_width === "number" && typeof elm.outer_height === "number") {
|
|
7366
|
+
const getOuterBounds = elm.shape === "pill" ? getRotatedPillBounds : getRotatedOvalBounds;
|
|
7367
|
+
platedHoleBounds = getOuterBounds(
|
|
7368
|
+
elm.x,
|
|
7369
|
+
elm.y,
|
|
7370
|
+
elm.outer_width,
|
|
7371
|
+
elm.outer_height,
|
|
7372
|
+
elm.ccw_rotation ?? 0
|
|
7373
|
+
);
|
|
7374
|
+
}
|
|
7375
|
+
if ("rect_pad_width" in elm && typeof elm.rect_pad_width === "number" && "rect_pad_height" in elm && typeof elm.rect_pad_height === "number") {
|
|
7376
|
+
const rectBounds = getRotatedRectBounds(
|
|
7377
|
+
elm.x,
|
|
7378
|
+
elm.y,
|
|
7379
|
+
elm.rect_pad_width,
|
|
7380
|
+
elm.rect_pad_height,
|
|
7381
|
+
"rect_ccw_rotation" in elm ? elm.rect_ccw_rotation ?? 0 : 0
|
|
7382
|
+
);
|
|
7383
|
+
platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, rectBounds) : rectBounds;
|
|
7384
|
+
}
|
|
7385
|
+
if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
|
|
7386
|
+
const drillBounds = getCircleBounds(
|
|
7387
|
+
elm.x + ("hole_offset_x" in elm ? elm.hole_offset_x ?? 0 : 0),
|
|
7388
|
+
elm.y + ("hole_offset_y" in elm ? elm.hole_offset_y ?? 0 : 0),
|
|
7389
|
+
elm.hole_diameter
|
|
7390
|
+
);
|
|
7391
|
+
platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, drillBounds) : drillBounds;
|
|
7392
|
+
}
|
|
7393
|
+
if (platedHoleBounds) return platedHoleBounds;
|
|
7394
|
+
}
|
|
7395
|
+
const elementRecord = elm;
|
|
7396
|
+
const routeBounds = getBoundsFromPoints2(getRoutePoints(elementRecord.route));
|
|
7397
|
+
if (routeBounds) return routeBounds;
|
|
7398
|
+
const outlineBounds = getBoundsFromPoints2(
|
|
7399
|
+
getRoutePoints(elementRecord.outline)
|
|
7400
|
+
);
|
|
7401
|
+
if (outlineBounds) return outlineBounds;
|
|
7402
|
+
const pointsBounds = getBoundsFromPoints2(getRoutePoints(elementRecord.points));
|
|
7403
|
+
if (pointsBounds) return pointsBounds;
|
|
7404
|
+
let centerX;
|
|
7405
|
+
let centerY;
|
|
7406
|
+
let width;
|
|
7407
|
+
let height;
|
|
7408
|
+
if ("x" in elm && "y" in elm) {
|
|
7409
|
+
centerX = Number(elm.x);
|
|
7410
|
+
centerY = Number(elm.y);
|
|
7411
|
+
}
|
|
7412
|
+
if ("outer_diameter" in elm) {
|
|
7413
|
+
width = Number(elm.outer_diameter);
|
|
7414
|
+
height = Number(elm.outer_diameter);
|
|
7415
|
+
}
|
|
7416
|
+
if ("width" in elm) {
|
|
7417
|
+
width = Number(elm.width);
|
|
7418
|
+
}
|
|
7419
|
+
if ("height" in elm) {
|
|
7420
|
+
height = Number(elm.height);
|
|
7421
|
+
}
|
|
7422
|
+
if ("center" in elm && elm.center && typeof elm.center === "object" && "x" in elm.center && "y" in elm.center) {
|
|
7423
|
+
centerX = Number(elm.center.x);
|
|
7424
|
+
centerY = Number(elm.center.y);
|
|
7425
|
+
}
|
|
7426
|
+
let rotation2 = 0;
|
|
7427
|
+
if ("rotation" in elm && typeof elm.rotation === "number") {
|
|
7428
|
+
rotation2 = elm.rotation;
|
|
7429
|
+
}
|
|
7430
|
+
if ("ccw_rotation" in elm && typeof elm.ccw_rotation === "number") {
|
|
7431
|
+
rotation2 = elm.ccw_rotation;
|
|
7432
|
+
}
|
|
7433
|
+
if (centerX !== void 0 && centerY !== void 0) {
|
|
7434
|
+
if (width !== void 0 && height !== void 0) {
|
|
7435
|
+
return rotation2 ? getRotatedRectBounds(centerX, centerY, width, height, rotation2) : {
|
|
7436
|
+
minX: centerX - width / 2,
|
|
7437
|
+
minY: centerY - height / 2,
|
|
7438
|
+
maxX: centerX + width / 2,
|
|
7439
|
+
maxY: centerY + height / 2
|
|
7440
|
+
};
|
|
7441
|
+
}
|
|
7442
|
+
if ("radius" in elm && typeof elm.radius === "number") {
|
|
7443
|
+
return getCircleBounds(centerX, centerY, elm.radius * 2);
|
|
7444
|
+
}
|
|
7445
|
+
return { minX: centerX, minY: centerY, maxX: centerX, maxY: centerY };
|
|
7446
|
+
}
|
|
7447
|
+
const anchoredPoint = [elementRecord.anchor_position, elementRecord.position].filter(
|
|
7448
|
+
(position2) => Boolean(
|
|
7449
|
+
position2 && typeof position2 === "object" && "x" in position2 && "y" in position2 && typeof position2.x === "number" && typeof position2.y === "number"
|
|
7450
|
+
)
|
|
7451
|
+
).at(0);
|
|
7452
|
+
return anchoredPoint ? {
|
|
7453
|
+
minX: anchoredPoint.x,
|
|
7454
|
+
minY: anchoredPoint.y,
|
|
7455
|
+
maxX: anchoredPoint.x,
|
|
7456
|
+
maxY: anchoredPoint.y
|
|
7457
|
+
} : null;
|
|
7458
|
+
};
|
|
7459
|
+
var getBoundsOfPcbElements = (elements) => {
|
|
7460
|
+
let bounds = {
|
|
7461
|
+
minX: Number.POSITIVE_INFINITY,
|
|
7462
|
+
minY: Number.POSITIVE_INFINITY,
|
|
7463
|
+
maxX: Number.NEGATIVE_INFINITY,
|
|
7464
|
+
maxY: Number.NEGATIVE_INFINITY
|
|
7465
|
+
};
|
|
7466
|
+
for (const element of elements) {
|
|
7467
|
+
const elementBounds = getPcbElementBounds(element);
|
|
7468
|
+
if (elementBounds) bounds = mergeBounds(bounds, elementBounds);
|
|
7469
|
+
}
|
|
7470
|
+
return bounds;
|
|
7471
|
+
};
|
|
7253
7472
|
function stringHash(str) {
|
|
7254
7473
|
let hash = 0;
|
|
7255
7474
|
if (str.length == 0) return hash;
|
|
@@ -7936,6 +8155,39 @@ var parseCadOffsetsFromSvgNode = (svgNode) => {
|
|
|
7936
8155
|
})()
|
|
7937
8156
|
};
|
|
7938
8157
|
};
|
|
8158
|
+
var getCadModelOutlineBounds = (svgNode) => {
|
|
8159
|
+
const points = [];
|
|
8160
|
+
for (const childNode of svgNode?.svgData.childNodes ?? []) {
|
|
8161
|
+
if (typeof childNode !== "object" || childNode === null) continue;
|
|
8162
|
+
const attrs = childNode.attrs;
|
|
8163
|
+
if (typeof attrs !== "object" || attrs === null) continue;
|
|
8164
|
+
const rawPoints = attrs.points;
|
|
8165
|
+
if (typeof rawPoints !== "string") continue;
|
|
8166
|
+
const coordinates = rawPoints.trim().split(/\s+/).map(Number);
|
|
8167
|
+
for (let index = 0; index + 1 < coordinates.length; index += 2) {
|
|
8168
|
+
const x = coordinates[index];
|
|
8169
|
+
const y = coordinates[index + 1];
|
|
8170
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
|
|
8171
|
+
points.push({ x: milx10(x), y: milx10(y) });
|
|
8172
|
+
}
|
|
8173
|
+
}
|
|
8174
|
+
if (points.length === 0) return void 0;
|
|
8175
|
+
return {
|
|
8176
|
+
minX: Math.min(...points.map((point2) => point2.x)),
|
|
8177
|
+
minY: Math.min(...points.map((point2) => point2.y)),
|
|
8178
|
+
maxX: Math.max(...points.map((point2) => point2.x)),
|
|
8179
|
+
maxY: Math.max(...points.map((point2) => point2.y))
|
|
8180
|
+
};
|
|
8181
|
+
};
|
|
8182
|
+
var unionBounds = (first, second) => {
|
|
8183
|
+
if (!second) return first;
|
|
8184
|
+
return {
|
|
8185
|
+
minX: Math.min(first.minX, second.minX),
|
|
8186
|
+
minY: Math.min(first.minY, second.minY),
|
|
8187
|
+
maxX: Math.max(first.maxX, second.maxX),
|
|
8188
|
+
maxY: Math.max(first.maxY, second.maxY)
|
|
8189
|
+
};
|
|
8190
|
+
};
|
|
7939
8191
|
var readModelHeightMm = (raw) => {
|
|
7940
8192
|
const fallback = 3.5;
|
|
7941
8193
|
if (raw == null) return fallback;
|
|
@@ -8527,17 +8779,29 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
|
|
|
8527
8779
|
);
|
|
8528
8780
|
}
|
|
8529
8781
|
const hasExplicitCourtyard = circuitElements.some(
|
|
8530
|
-
(e) => e.type === "pcb_courtyard_outline"
|
|
8782
|
+
(e) => e.type === "pcb_courtyard_outline" || e.type === "pcb_courtyard_rect"
|
|
8531
8783
|
);
|
|
8532
8784
|
if (!hasExplicitCourtyard) {
|
|
8533
8785
|
const bbox = easyEdaJson.packageDetail.dataStr.BBox;
|
|
8534
|
-
|
|
8786
|
+
const modelOutlineBounds = getCadModelOutlineBounds(svgNode);
|
|
8787
|
+
const packageElements = circuitElements.filter(
|
|
8788
|
+
(element) => element.type === "pcb_smtpad" || element.type === "pcb_plated_hole" || element.type === "pcb_hole" || element.type === "pcb_via"
|
|
8789
|
+
);
|
|
8790
|
+
const packageElementBounds = packageElements.length > 0 ? getBoundsOfPcbElements(packageElements) : void 0;
|
|
8791
|
+
const fallbackBounds = bbox ? {
|
|
8792
|
+
minX: milx10(bbox.x),
|
|
8793
|
+
minY: milx10(bbox.y),
|
|
8794
|
+
maxX: milx10(bbox.x + bbox.width),
|
|
8795
|
+
maxY: milx10(bbox.y + bbox.height)
|
|
8796
|
+
} : void 0;
|
|
8797
|
+
const courtyardBounds = modelOutlineBounds ? unionBounds(modelOutlineBounds, packageElementBounds) : fallbackBounds;
|
|
8798
|
+
if (courtyardBounds) {
|
|
8535
8799
|
const strokeWidth = 0.05;
|
|
8536
8800
|
const margin = 0.25;
|
|
8537
|
-
const x1 =
|
|
8538
|
-
const y1 =
|
|
8539
|
-
const x2 =
|
|
8540
|
-
const y2 =
|
|
8801
|
+
const x1 = courtyardBounds.minX - margin;
|
|
8802
|
+
const y1 = courtyardBounds.minY - margin;
|
|
8803
|
+
const x2 = courtyardBounds.maxX + margin;
|
|
8804
|
+
const y2 = courtyardBounds.maxY + margin;
|
|
8541
8805
|
circuitElements.push(
|
|
8542
8806
|
pcb_courtyard_outline.parse({
|
|
8543
8807
|
type: "pcb_courtyard_outline",
|