easyeda 0.0.357 → 0.0.359
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.d.ts +10 -10
- package/dist/browser/index.js +397 -111
- package/dist/browser/index.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.js +395 -109
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +396 -110
- 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.358",
|
|
1082
1082
|
files: [
|
|
1083
1083
|
"dist"
|
|
1084
1084
|
],
|
|
@@ -1135,6 +1135,112 @@ var package_default = {
|
|
|
1135
1135
|
types: "./dist/index.d.ts"
|
|
1136
1136
|
};
|
|
1137
1137
|
|
|
1138
|
+
// lib/utils/normalize-pin-labels.ts
|
|
1139
|
+
var normalizeActiveLowPinLabel = (label) => {
|
|
1140
|
+
const hasActiveLowMarker = label.startsWith("#") || label.endsWith("#");
|
|
1141
|
+
if (!hasActiveLowMarker) return label;
|
|
1142
|
+
const activeLowLabel = label.replace(/^#/, "").replace(/#$/, "");
|
|
1143
|
+
if (activeLowLabel.length === 0) return label;
|
|
1144
|
+
if (activeLowLabel.startsWith("N_")) return activeLowLabel;
|
|
1145
|
+
return `N_${activeLowLabel}`;
|
|
1146
|
+
};
|
|
1147
|
+
var normalizePinLabels = (inputPinLabels) => {
|
|
1148
|
+
const normalizedInputPinLabels = inputPinLabels.map(
|
|
1149
|
+
(labels) => labels.map(normalizeActiveLowPinLabel)
|
|
1150
|
+
);
|
|
1151
|
+
const uniqueInputPinLabels = normalizedInputPinLabels.map((labels) => [
|
|
1152
|
+
...new Set(labels)
|
|
1153
|
+
]);
|
|
1154
|
+
const result = uniqueInputPinLabels.map(() => []);
|
|
1155
|
+
const desiredNumbers = uniqueInputPinLabels.map(() => null);
|
|
1156
|
+
for (let i = 0; i < uniqueInputPinLabels.length; i++) {
|
|
1157
|
+
for (const label of uniqueInputPinLabels[i]) {
|
|
1158
|
+
if (/^\d+$/.test(label)) {
|
|
1159
|
+
desiredNumbers[i] = Number.parseInt(label);
|
|
1160
|
+
break;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
let highestPinNumber = 0;
|
|
1165
|
+
const acceptedDesiredNumbers = /* @__PURE__ */ new Set();
|
|
1166
|
+
for (let i = 0; i < desiredNumbers.length; i++) {
|
|
1167
|
+
const desiredNumber = desiredNumbers[i];
|
|
1168
|
+
if (desiredNumber === null || desiredNumber < 1) continue;
|
|
1169
|
+
if (!acceptedDesiredNumbers.has(desiredNumber)) {
|
|
1170
|
+
acceptedDesiredNumbers.add(desiredNumber);
|
|
1171
|
+
result[i].push(`pin${desiredNumber}`);
|
|
1172
|
+
highestPinNumber = Math.max(highestPinNumber, desiredNumber);
|
|
1173
|
+
continue;
|
|
1174
|
+
}
|
|
1175
|
+
let existingAltCount = 0;
|
|
1176
|
+
for (const label of result[i]) {
|
|
1177
|
+
if (label.startsWith(`pin${desiredNumber}_alt`)) {
|
|
1178
|
+
existingAltCount += 1;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
result[i].push(`pin${desiredNumber}_alt${existingAltCount + 1}`);
|
|
1182
|
+
}
|
|
1183
|
+
for (let i = 0; i < result.length; i++) {
|
|
1184
|
+
const firstLabel = result[i][0];
|
|
1185
|
+
if (firstLabel?.includes("_alt")) {
|
|
1186
|
+
highestPinNumber += 1;
|
|
1187
|
+
result[i].unshift(`pin${highestPinNumber}`);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
for (let i = 0; i < result.length; i++) {
|
|
1191
|
+
if (result[i].length === 0) {
|
|
1192
|
+
highestPinNumber += 1;
|
|
1193
|
+
result[i].push(`pin${highestPinNumber}`);
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
const totalLabelCounts = {};
|
|
1197
|
+
for (const inputLabels of uniqueInputPinLabels) {
|
|
1198
|
+
for (const label of inputLabels) {
|
|
1199
|
+
if (/^\d+$/.test(label)) continue;
|
|
1200
|
+
totalLabelCounts[label] = (totalLabelCounts[label] ?? 0) + 1;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
const incrementalLabelCounts = {};
|
|
1204
|
+
for (let i = 0; i < uniqueInputPinLabels.length; i++) {
|
|
1205
|
+
for (const label of uniqueInputPinLabels[i]) {
|
|
1206
|
+
if (/^\d+$/.test(label)) continue;
|
|
1207
|
+
if (totalLabelCounts[label] === 1) {
|
|
1208
|
+
result[i].push(label);
|
|
1209
|
+
} else {
|
|
1210
|
+
incrementalLabelCounts[label] = (incrementalLabelCounts[label] ?? 0) + 1;
|
|
1211
|
+
result[i].push(`${label}${incrementalLabelCounts[label]}`);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
return result;
|
|
1216
|
+
};
|
|
1217
|
+
|
|
1218
|
+
// lib/utils/normalize-easyeda-pin-label.ts
|
|
1219
|
+
var normalizeEasyEdaPinLabel = (label) => {
|
|
1220
|
+
if (label.endsWith("+")) label = `${label.slice(0, -1)}_POS`;
|
|
1221
|
+
if (/[-–−]$/.test(label)) label = `${label.slice(0, -1)}_NEG`;
|
|
1222
|
+
label = normalizeActiveLowPinLabel(label);
|
|
1223
|
+
if (/^\+\d+(?:\.\d+)?V$/i.test(label)) label = `V${label.slice(1, -1)}`;
|
|
1224
|
+
if (label.startsWith("+")) label = `${label.slice(1)}_POS`;
|
|
1225
|
+
if (/^[-–−]/.test(label)) label = `${label.slice(1)}_NEG`;
|
|
1226
|
+
return label;
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
// lib/utils/get-easyeda-pin-aliases.ts
|
|
1230
|
+
var getEasyEdaPinAliases = (label) => {
|
|
1231
|
+
label = label.replace(/&#(x[0-9a-f]+|[0-9]+);/gi, (entity, code) => {
|
|
1232
|
+
let codePoint = Number(code);
|
|
1233
|
+
if (/^x/i.test(code)) codePoint = Number.parseInt(code.slice(1), 16);
|
|
1234
|
+
const maximumUnicodeCodePoint = 1114111;
|
|
1235
|
+
if (codePoint > maximumUnicodeCodePoint) return entity;
|
|
1236
|
+
return String.fromCodePoint(codePoint);
|
|
1237
|
+
});
|
|
1238
|
+
if (label.includes("/") && !/[a-zA-Z0-9]/.test(label)) return [];
|
|
1239
|
+
return label.split("/").map(
|
|
1240
|
+
(alias) => normalizeEasyEdaPinLabel(alias.trim()).replace(/[`′]/g, "_PRIME").replace(/^[()]+|[()]+$/g, "").replace(/[^a-zA-Z0-9_]/g, "_")
|
|
1241
|
+
).filter((alias) => /[a-zA-Z0-9]/.test(alias));
|
|
1242
|
+
};
|
|
1243
|
+
|
|
1138
1244
|
// node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
|
|
1139
1245
|
function orientation(p, q, r) {
|
|
1140
1246
|
const val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
|
@@ -7250,6 +7356,225 @@ var transformPCBElements = (elms, matrix) => {
|
|
|
7250
7356
|
}
|
|
7251
7357
|
return transformedElms;
|
|
7252
7358
|
};
|
|
7359
|
+
var mergeBounds = (currentBounds, nextBounds) => ({
|
|
7360
|
+
minX: Math.min(currentBounds.minX, nextBounds.minX),
|
|
7361
|
+
minY: Math.min(currentBounds.minY, nextBounds.minY),
|
|
7362
|
+
maxX: Math.max(currentBounds.maxX, nextBounds.maxX),
|
|
7363
|
+
maxY: Math.max(currentBounds.maxY, nextBounds.maxY)
|
|
7364
|
+
});
|
|
7365
|
+
var getCircleBounds = (x, y, diameter) => {
|
|
7366
|
+
const radius = diameter / 2;
|
|
7367
|
+
return {
|
|
7368
|
+
minX: x - radius,
|
|
7369
|
+
minY: y - radius,
|
|
7370
|
+
maxX: x + radius,
|
|
7371
|
+
maxY: y + radius
|
|
7372
|
+
};
|
|
7373
|
+
};
|
|
7374
|
+
var getRotatedRectBounds = (x, y, width, height, rotationDegrees) => {
|
|
7375
|
+
const halfWidth = width / 2;
|
|
7376
|
+
const halfHeight = height / 2;
|
|
7377
|
+
const theta = rotationDegrees * Math.PI / 180;
|
|
7378
|
+
const cosTheta = Math.cos(theta);
|
|
7379
|
+
const sinTheta = Math.sin(theta);
|
|
7380
|
+
const corners = [
|
|
7381
|
+
{ x: -halfWidth, y: -halfHeight },
|
|
7382
|
+
{ x: halfWidth, y: -halfHeight },
|
|
7383
|
+
{ x: halfWidth, y: halfHeight },
|
|
7384
|
+
{ x: -halfWidth, y: halfHeight }
|
|
7385
|
+
].map((corner) => ({
|
|
7386
|
+
x: x + corner.x * cosTheta - corner.y * sinTheta,
|
|
7387
|
+
y: y + corner.x * sinTheta + corner.y * cosTheta
|
|
7388
|
+
}));
|
|
7389
|
+
return {
|
|
7390
|
+
minX: Math.min(...corners.map((corner) => corner.x)),
|
|
7391
|
+
minY: Math.min(...corners.map((corner) => corner.y)),
|
|
7392
|
+
maxX: Math.max(...corners.map((corner) => corner.x)),
|
|
7393
|
+
maxY: Math.max(...corners.map((corner) => corner.y))
|
|
7394
|
+
};
|
|
7395
|
+
};
|
|
7396
|
+
var getRotatedOvalBounds = (x, y, width, height, rotationDegrees) => {
|
|
7397
|
+
const radiusX = width / 2;
|
|
7398
|
+
const radiusY = height / 2;
|
|
7399
|
+
const theta = rotationDegrees * Math.PI / 180;
|
|
7400
|
+
const cosTheta = Math.cos(theta);
|
|
7401
|
+
const sinTheta = Math.sin(theta);
|
|
7402
|
+
const halfWidth = Math.hypot(radiusX * cosTheta, radiusY * sinTheta);
|
|
7403
|
+
const halfHeight = Math.hypot(radiusX * sinTheta, radiusY * cosTheta);
|
|
7404
|
+
return {
|
|
7405
|
+
minX: x - halfWidth,
|
|
7406
|
+
minY: y - halfHeight,
|
|
7407
|
+
maxX: x + halfWidth,
|
|
7408
|
+
maxY: y + halfHeight
|
|
7409
|
+
};
|
|
7410
|
+
};
|
|
7411
|
+
var getRotatedPillBounds = (x, y, width, height, rotationDegrees) => {
|
|
7412
|
+
const radius = Math.min(width, height) / 2;
|
|
7413
|
+
const halfLineLength = Math.max(width, height) / 2 - radius;
|
|
7414
|
+
const theta = rotationDegrees * Math.PI / 180;
|
|
7415
|
+
const axis = width >= height ? { x: halfLineLength, y: 0 } : { x: 0, y: halfLineLength };
|
|
7416
|
+
const rotatedAxis = {
|
|
7417
|
+
x: axis.x * Math.cos(theta) - axis.y * Math.sin(theta),
|
|
7418
|
+
y: axis.x * Math.sin(theta) + axis.y * Math.cos(theta)
|
|
7419
|
+
};
|
|
7420
|
+
const halfWidth = Math.abs(rotatedAxis.x) + radius;
|
|
7421
|
+
const halfHeight = Math.abs(rotatedAxis.y) + radius;
|
|
7422
|
+
return {
|
|
7423
|
+
minX: x - halfWidth,
|
|
7424
|
+
minY: y - halfHeight,
|
|
7425
|
+
maxX: x + halfWidth,
|
|
7426
|
+
maxY: y + halfHeight
|
|
7427
|
+
};
|
|
7428
|
+
};
|
|
7429
|
+
var getBoundsFromPoints2 = (points) => {
|
|
7430
|
+
if (points.length === 0) return null;
|
|
7431
|
+
return {
|
|
7432
|
+
minX: Math.min(...points.map((point2) => point2.x)),
|
|
7433
|
+
minY: Math.min(...points.map((point2) => point2.y)),
|
|
7434
|
+
maxX: Math.max(...points.map((point2) => point2.x)),
|
|
7435
|
+
maxY: Math.max(...points.map((point2) => point2.y))
|
|
7436
|
+
};
|
|
7437
|
+
};
|
|
7438
|
+
var getRoutePoints = (route) => {
|
|
7439
|
+
if (!Array.isArray(route)) return [];
|
|
7440
|
+
return route.flatMap((point2) => {
|
|
7441
|
+
if (!point2 || typeof point2 !== "object") return [];
|
|
7442
|
+
if ("x" in point2 && "y" in point2 && typeof point2.x === "number" && typeof point2.y === "number") {
|
|
7443
|
+
return [{ x: point2.x, y: point2.y }];
|
|
7444
|
+
}
|
|
7445
|
+
if ("start" in point2 && "end" in point2) {
|
|
7446
|
+
const positions = [point2.start, point2.end];
|
|
7447
|
+
return positions.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
|
+
);
|
|
7452
|
+
}
|
|
7453
|
+
return [];
|
|
7454
|
+
});
|
|
7455
|
+
};
|
|
7456
|
+
var getPcbElementBounds = (elm) => {
|
|
7457
|
+
if (!elm.type.startsWith("pcb_")) return null;
|
|
7458
|
+
if (elm.type === "pcb_smtpad" && elm.shape === "polygon" && Array.isArray(elm.points)) {
|
|
7459
|
+
return getBoundsFromPoints2(elm.points);
|
|
7460
|
+
}
|
|
7461
|
+
if (elm.type === "pcb_hole" && elm.hole_shape === "circle") {
|
|
7462
|
+
return getCircleBounds(elm.x, elm.y, elm.hole_diameter);
|
|
7463
|
+
}
|
|
7464
|
+
if (elm.type === "pcb_plated_hole") {
|
|
7465
|
+
let platedHoleBounds;
|
|
7466
|
+
if ("outer_diameter" in elm && typeof elm.outer_diameter === "number") {
|
|
7467
|
+
platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.outer_diameter);
|
|
7468
|
+
} else if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
|
|
7469
|
+
platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.hole_diameter);
|
|
7470
|
+
}
|
|
7471
|
+
if ((elm.shape === "oval" || elm.shape === "pill") && typeof elm.outer_width === "number" && typeof elm.outer_height === "number") {
|
|
7472
|
+
const getOuterBounds = elm.shape === "pill" ? getRotatedPillBounds : getRotatedOvalBounds;
|
|
7473
|
+
platedHoleBounds = getOuterBounds(
|
|
7474
|
+
elm.x,
|
|
7475
|
+
elm.y,
|
|
7476
|
+
elm.outer_width,
|
|
7477
|
+
elm.outer_height,
|
|
7478
|
+
elm.ccw_rotation ?? 0
|
|
7479
|
+
);
|
|
7480
|
+
}
|
|
7481
|
+
if ("rect_pad_width" in elm && typeof elm.rect_pad_width === "number" && "rect_pad_height" in elm && typeof elm.rect_pad_height === "number") {
|
|
7482
|
+
const rectBounds = getRotatedRectBounds(
|
|
7483
|
+
elm.x,
|
|
7484
|
+
elm.y,
|
|
7485
|
+
elm.rect_pad_width,
|
|
7486
|
+
elm.rect_pad_height,
|
|
7487
|
+
"rect_ccw_rotation" in elm ? elm.rect_ccw_rotation ?? 0 : 0
|
|
7488
|
+
);
|
|
7489
|
+
platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, rectBounds) : rectBounds;
|
|
7490
|
+
}
|
|
7491
|
+
if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
|
|
7492
|
+
const drillBounds = getCircleBounds(
|
|
7493
|
+
elm.x + ("hole_offset_x" in elm ? elm.hole_offset_x ?? 0 : 0),
|
|
7494
|
+
elm.y + ("hole_offset_y" in elm ? elm.hole_offset_y ?? 0 : 0),
|
|
7495
|
+
elm.hole_diameter
|
|
7496
|
+
);
|
|
7497
|
+
platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, drillBounds) : drillBounds;
|
|
7498
|
+
}
|
|
7499
|
+
if (platedHoleBounds) return platedHoleBounds;
|
|
7500
|
+
}
|
|
7501
|
+
const elementRecord = elm;
|
|
7502
|
+
const routeBounds = getBoundsFromPoints2(getRoutePoints(elementRecord.route));
|
|
7503
|
+
if (routeBounds) return routeBounds;
|
|
7504
|
+
const outlineBounds = getBoundsFromPoints2(
|
|
7505
|
+
getRoutePoints(elementRecord.outline)
|
|
7506
|
+
);
|
|
7507
|
+
if (outlineBounds) return outlineBounds;
|
|
7508
|
+
const pointsBounds = getBoundsFromPoints2(getRoutePoints(elementRecord.points));
|
|
7509
|
+
if (pointsBounds) return pointsBounds;
|
|
7510
|
+
let centerX;
|
|
7511
|
+
let centerY;
|
|
7512
|
+
let width;
|
|
7513
|
+
let height;
|
|
7514
|
+
if ("x" in elm && "y" in elm) {
|
|
7515
|
+
centerX = Number(elm.x);
|
|
7516
|
+
centerY = Number(elm.y);
|
|
7517
|
+
}
|
|
7518
|
+
if ("outer_diameter" in elm) {
|
|
7519
|
+
width = Number(elm.outer_diameter);
|
|
7520
|
+
height = Number(elm.outer_diameter);
|
|
7521
|
+
}
|
|
7522
|
+
if ("width" in elm) {
|
|
7523
|
+
width = Number(elm.width);
|
|
7524
|
+
}
|
|
7525
|
+
if ("height" in elm) {
|
|
7526
|
+
height = Number(elm.height);
|
|
7527
|
+
}
|
|
7528
|
+
if ("center" in elm && elm.center && typeof elm.center === "object" && "x" in elm.center && "y" in elm.center) {
|
|
7529
|
+
centerX = Number(elm.center.x);
|
|
7530
|
+
centerY = Number(elm.center.y);
|
|
7531
|
+
}
|
|
7532
|
+
let rotation2 = 0;
|
|
7533
|
+
if ("rotation" in elm && typeof elm.rotation === "number") {
|
|
7534
|
+
rotation2 = elm.rotation;
|
|
7535
|
+
}
|
|
7536
|
+
if ("ccw_rotation" in elm && typeof elm.ccw_rotation === "number") {
|
|
7537
|
+
rotation2 = elm.ccw_rotation;
|
|
7538
|
+
}
|
|
7539
|
+
if (centerX !== void 0 && centerY !== void 0) {
|
|
7540
|
+
if (width !== void 0 && height !== void 0) {
|
|
7541
|
+
return rotation2 ? getRotatedRectBounds(centerX, centerY, width, height, rotation2) : {
|
|
7542
|
+
minX: centerX - width / 2,
|
|
7543
|
+
minY: centerY - height / 2,
|
|
7544
|
+
maxX: centerX + width / 2,
|
|
7545
|
+
maxY: centerY + height / 2
|
|
7546
|
+
};
|
|
7547
|
+
}
|
|
7548
|
+
if ("radius" in elm && typeof elm.radius === "number") {
|
|
7549
|
+
return getCircleBounds(centerX, centerY, elm.radius * 2);
|
|
7550
|
+
}
|
|
7551
|
+
return { minX: centerX, minY: centerY, maxX: centerX, maxY: centerY };
|
|
7552
|
+
}
|
|
7553
|
+
const anchoredPoint = [elementRecord.anchor_position, elementRecord.position].filter(
|
|
7554
|
+
(position2) => Boolean(
|
|
7555
|
+
position2 && typeof position2 === "object" && "x" in position2 && "y" in position2 && typeof position2.x === "number" && typeof position2.y === "number"
|
|
7556
|
+
)
|
|
7557
|
+
).at(0);
|
|
7558
|
+
return anchoredPoint ? {
|
|
7559
|
+
minX: anchoredPoint.x,
|
|
7560
|
+
minY: anchoredPoint.y,
|
|
7561
|
+
maxX: anchoredPoint.x,
|
|
7562
|
+
maxY: anchoredPoint.y
|
|
7563
|
+
} : null;
|
|
7564
|
+
};
|
|
7565
|
+
var getBoundsOfPcbElements = (elements) => {
|
|
7566
|
+
let bounds = {
|
|
7567
|
+
minX: Number.POSITIVE_INFINITY,
|
|
7568
|
+
minY: Number.POSITIVE_INFINITY,
|
|
7569
|
+
maxX: Number.NEGATIVE_INFINITY,
|
|
7570
|
+
maxY: Number.NEGATIVE_INFINITY
|
|
7571
|
+
};
|
|
7572
|
+
for (const element of elements) {
|
|
7573
|
+
const elementBounds = getPcbElementBounds(element);
|
|
7574
|
+
if (elementBounds) bounds = mergeBounds(bounds, elementBounds);
|
|
7575
|
+
}
|
|
7576
|
+
return bounds;
|
|
7577
|
+
};
|
|
7253
7578
|
function stringHash(str) {
|
|
7254
7579
|
let hash = 0;
|
|
7255
7580
|
if (str.length == 0) return hash;
|
|
@@ -7656,94 +7981,6 @@ var getPolarizedPinMetadata = (pinLabels) => {
|
|
|
7656
7981
|
};
|
|
7657
7982
|
};
|
|
7658
7983
|
|
|
7659
|
-
// lib/utils/normalize-pin-labels.ts
|
|
7660
|
-
var normalizeActiveLowPinLabel = (label) => {
|
|
7661
|
-
const hasActiveLowMarker = label.startsWith("#") || label.endsWith("#");
|
|
7662
|
-
if (!hasActiveLowMarker) return label;
|
|
7663
|
-
const activeLowLabel = label.replace(/^#/, "").replace(/#$/, "");
|
|
7664
|
-
if (activeLowLabel.length === 0) return label;
|
|
7665
|
-
if (activeLowLabel.startsWith("N_")) return activeLowLabel;
|
|
7666
|
-
return `N_${activeLowLabel}`;
|
|
7667
|
-
};
|
|
7668
|
-
var normalizePinLabels = (inputPinLabels) => {
|
|
7669
|
-
const normalizedInputPinLabels = inputPinLabels.map(
|
|
7670
|
-
(labels) => labels.map(normalizeActiveLowPinLabel)
|
|
7671
|
-
);
|
|
7672
|
-
const uniqueInputPinLabels = normalizedInputPinLabels.map((labels) => [
|
|
7673
|
-
...new Set(labels)
|
|
7674
|
-
]);
|
|
7675
|
-
const result = uniqueInputPinLabels.map(() => []);
|
|
7676
|
-
const desiredNumbers = uniqueInputPinLabels.map(() => null);
|
|
7677
|
-
for (let i = 0; i < uniqueInputPinLabels.length; i++) {
|
|
7678
|
-
for (const label of uniqueInputPinLabels[i]) {
|
|
7679
|
-
if (/^\d+$/.test(label)) {
|
|
7680
|
-
desiredNumbers[i] = Number.parseInt(label);
|
|
7681
|
-
break;
|
|
7682
|
-
}
|
|
7683
|
-
}
|
|
7684
|
-
}
|
|
7685
|
-
let highestPinNumber = 0;
|
|
7686
|
-
const acceptedDesiredNumbers = /* @__PURE__ */ new Set();
|
|
7687
|
-
for (let i = 0; i < desiredNumbers.length; i++) {
|
|
7688
|
-
const desiredNumber = desiredNumbers[i];
|
|
7689
|
-
if (desiredNumber === null || desiredNumber < 1) continue;
|
|
7690
|
-
if (!acceptedDesiredNumbers.has(desiredNumber)) {
|
|
7691
|
-
acceptedDesiredNumbers.add(desiredNumber);
|
|
7692
|
-
result[i].push(`pin${desiredNumber}`);
|
|
7693
|
-
highestPinNumber = Math.max(highestPinNumber, desiredNumber);
|
|
7694
|
-
continue;
|
|
7695
|
-
}
|
|
7696
|
-
let existingAltCount = 0;
|
|
7697
|
-
for (const label of result[i]) {
|
|
7698
|
-
if (label.startsWith(`pin${desiredNumber}_alt`)) {
|
|
7699
|
-
existingAltCount += 1;
|
|
7700
|
-
}
|
|
7701
|
-
}
|
|
7702
|
-
result[i].push(`pin${desiredNumber}_alt${existingAltCount + 1}`);
|
|
7703
|
-
}
|
|
7704
|
-
for (let i = 0; i < result.length; i++) {
|
|
7705
|
-
const firstLabel = result[i][0];
|
|
7706
|
-
if (firstLabel?.includes("_alt")) {
|
|
7707
|
-
highestPinNumber += 1;
|
|
7708
|
-
result[i].unshift(`pin${highestPinNumber}`);
|
|
7709
|
-
}
|
|
7710
|
-
}
|
|
7711
|
-
for (let i = 0; i < result.length; i++) {
|
|
7712
|
-
if (result[i].length === 0) {
|
|
7713
|
-
highestPinNumber += 1;
|
|
7714
|
-
result[i].push(`pin${highestPinNumber}`);
|
|
7715
|
-
}
|
|
7716
|
-
}
|
|
7717
|
-
const totalLabelCounts = {};
|
|
7718
|
-
for (const inputLabels of uniqueInputPinLabels) {
|
|
7719
|
-
for (const label of inputLabels) {
|
|
7720
|
-
if (/^\d+$/.test(label)) continue;
|
|
7721
|
-
totalLabelCounts[label] = (totalLabelCounts[label] ?? 0) + 1;
|
|
7722
|
-
}
|
|
7723
|
-
}
|
|
7724
|
-
const incrementalLabelCounts = {};
|
|
7725
|
-
for (let i = 0; i < uniqueInputPinLabels.length; i++) {
|
|
7726
|
-
for (const label of uniqueInputPinLabels[i]) {
|
|
7727
|
-
if (/^\d+$/.test(label)) continue;
|
|
7728
|
-
if (totalLabelCounts[label] === 1) {
|
|
7729
|
-
result[i].push(label);
|
|
7730
|
-
} else {
|
|
7731
|
-
incrementalLabelCounts[label] = (incrementalLabelCounts[label] ?? 0) + 1;
|
|
7732
|
-
result[i].push(`${label}${incrementalLabelCounts[label]}`);
|
|
7733
|
-
}
|
|
7734
|
-
}
|
|
7735
|
-
}
|
|
7736
|
-
return result;
|
|
7737
|
-
};
|
|
7738
|
-
|
|
7739
|
-
// lib/utils/normalize-symbol-name.ts
|
|
7740
|
-
var normalizeSymbolName = (name) => {
|
|
7741
|
-
const trimmedName = name.trim();
|
|
7742
|
-
if (trimmedName === "+") return "_POS";
|
|
7743
|
-
if (trimmedName === "-") return "_NEG";
|
|
7744
|
-
return trimmedName.replace(/(?<=[A-Za-z0-9])-(?=[A-Za-z0-9])/g, "_");
|
|
7745
|
-
};
|
|
7746
|
-
|
|
7747
7984
|
// lib/websafe/convert-to-typescript-component/category-value-contains-diode.ts
|
|
7748
7985
|
var categoryValueContainsDiode = (value) => {
|
|
7749
7986
|
if (typeof value === "string") {
|
|
@@ -7936,6 +8173,39 @@ var parseCadOffsetsFromSvgNode = (svgNode) => {
|
|
|
7936
8173
|
})()
|
|
7937
8174
|
};
|
|
7938
8175
|
};
|
|
8176
|
+
var getCadModelOutlineBounds = (svgNode) => {
|
|
8177
|
+
const points = [];
|
|
8178
|
+
for (const childNode of svgNode?.svgData.childNodes ?? []) {
|
|
8179
|
+
if (typeof childNode !== "object" || childNode === null) continue;
|
|
8180
|
+
const attrs = childNode.attrs;
|
|
8181
|
+
if (typeof attrs !== "object" || attrs === null) continue;
|
|
8182
|
+
const rawPoints = attrs.points;
|
|
8183
|
+
if (typeof rawPoints !== "string") continue;
|
|
8184
|
+
const coordinates = rawPoints.trim().split(/\s+/).map(Number);
|
|
8185
|
+
for (let index = 0; index + 1 < coordinates.length; index += 2) {
|
|
8186
|
+
const x = coordinates[index];
|
|
8187
|
+
const y = coordinates[index + 1];
|
|
8188
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
|
|
8189
|
+
points.push({ x: milx10(x), y: milx10(y) });
|
|
8190
|
+
}
|
|
8191
|
+
}
|
|
8192
|
+
if (points.length === 0) return void 0;
|
|
8193
|
+
return {
|
|
8194
|
+
minX: Math.min(...points.map((point2) => point2.x)),
|
|
8195
|
+
minY: Math.min(...points.map((point2) => point2.y)),
|
|
8196
|
+
maxX: Math.max(...points.map((point2) => point2.x)),
|
|
8197
|
+
maxY: Math.max(...points.map((point2) => point2.y))
|
|
8198
|
+
};
|
|
8199
|
+
};
|
|
8200
|
+
var unionBounds = (first, second) => {
|
|
8201
|
+
if (!second) return first;
|
|
8202
|
+
return {
|
|
8203
|
+
minX: Math.min(first.minX, second.minX),
|
|
8204
|
+
minY: Math.min(first.minY, second.minY),
|
|
8205
|
+
maxX: Math.max(first.maxX, second.maxX),
|
|
8206
|
+
maxY: Math.max(first.maxY, second.maxY)
|
|
8207
|
+
};
|
|
8208
|
+
};
|
|
7939
8209
|
var readModelHeightMm = (raw) => {
|
|
7940
8210
|
const fallback = 3.5;
|
|
7941
8211
|
if (raw == null) return fallback;
|
|
@@ -8194,9 +8464,9 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
|
|
|
8194
8464
|
const pins = easyEdaJson.dataStr.shape.filter((shape) => shape.type === "PIN");
|
|
8195
8465
|
const pinLabelSets = pads.map((pad) => {
|
|
8196
8466
|
const labels = [];
|
|
8197
|
-
if (pad.number) labels.push(pad.number.toString());
|
|
8467
|
+
if (pad.number) labels.push(...getEasyEdaPinAliases(pad.number.toString()));
|
|
8198
8468
|
const pin = pins.find((p) => p.pinNumber === pad.number);
|
|
8199
|
-
if (pin) labels.push(
|
|
8469
|
+
if (pin) labels.push(...getEasyEdaPinAliases(pin.label));
|
|
8200
8470
|
return labels;
|
|
8201
8471
|
});
|
|
8202
8472
|
const padNumberKeys = pads.map((pad, index) => {
|
|
@@ -8527,17 +8797,29 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
|
|
|
8527
8797
|
);
|
|
8528
8798
|
}
|
|
8529
8799
|
const hasExplicitCourtyard = circuitElements.some(
|
|
8530
|
-
(e) => e.type === "pcb_courtyard_outline"
|
|
8800
|
+
(e) => e.type === "pcb_courtyard_outline" || e.type === "pcb_courtyard_rect"
|
|
8531
8801
|
);
|
|
8532
8802
|
if (!hasExplicitCourtyard) {
|
|
8533
8803
|
const bbox = easyEdaJson.packageDetail.dataStr.BBox;
|
|
8534
|
-
|
|
8804
|
+
const modelOutlineBounds = getCadModelOutlineBounds(svgNode);
|
|
8805
|
+
const packageElements = circuitElements.filter(
|
|
8806
|
+
(element) => element.type === "pcb_smtpad" || element.type === "pcb_plated_hole" || element.type === "pcb_hole" || element.type === "pcb_via"
|
|
8807
|
+
);
|
|
8808
|
+
const packageElementBounds = packageElements.length > 0 ? getBoundsOfPcbElements(packageElements) : void 0;
|
|
8809
|
+
const fallbackBounds = bbox ? {
|
|
8810
|
+
minX: milx10(bbox.x),
|
|
8811
|
+
minY: milx10(bbox.y),
|
|
8812
|
+
maxX: milx10(bbox.x + bbox.width),
|
|
8813
|
+
maxY: milx10(bbox.y + bbox.height)
|
|
8814
|
+
} : void 0;
|
|
8815
|
+
const courtyardBounds = modelOutlineBounds ? unionBounds(modelOutlineBounds, packageElementBounds) : fallbackBounds;
|
|
8816
|
+
if (courtyardBounds) {
|
|
8535
8817
|
const strokeWidth = 0.05;
|
|
8536
8818
|
const margin = 0.25;
|
|
8537
|
-
const x1 =
|
|
8538
|
-
const y1 =
|
|
8539
|
-
const x2 =
|
|
8540
|
-
const y2 =
|
|
8819
|
+
const x1 = courtyardBounds.minX - margin;
|
|
8820
|
+
const y1 = courtyardBounds.minY - margin;
|
|
8821
|
+
const x2 = courtyardBounds.maxX + margin;
|
|
8822
|
+
const y2 = courtyardBounds.maxY + margin;
|
|
8541
8823
|
circuitElements.push(
|
|
8542
8824
|
pcb_courtyard_outline.parse({
|
|
8543
8825
|
type: "pcb_courtyard_outline",
|
|
@@ -9104,14 +9386,9 @@ var PinShapeOutputSchema = import_zod201.z.object({
|
|
|
9104
9386
|
var parsePin = (pinString) => {
|
|
9105
9387
|
const parts = pinString.split("~");
|
|
9106
9388
|
const [, visibility, , pinNumber, x, y, rotation2, id] = parts;
|
|
9107
|
-
const
|
|
9108
|
-
let label =
|
|
9109
|
-
if (label.
|
|
9110
|
-
if (label.endsWith("-")) label = `${label.slice(0, -1)}_NEG`;
|
|
9111
|
-
label = normalizeActiveLowPinLabel(label);
|
|
9112
|
-
if (/^\+\d+(?:\.\d+)?V$/i.test(label)) label = `V${label.slice(1, -1)}`;
|
|
9113
|
-
if (label.startsWith("+")) label = `${label.slice(1)}_POS`;
|
|
9114
|
-
if (label.startsWith("-")) label = `${label.slice(1)}_NEG`;
|
|
9389
|
+
const pinNameSection = pinString.split("^^")[3];
|
|
9390
|
+
let label = pinNameSection?.split("~")[4] ?? "";
|
|
9391
|
+
if (!label.includes("/")) label = normalizeEasyEdaPinLabel(label);
|
|
9115
9392
|
const colorMatch = pinString.match(/#[0-9A-F]{6}/);
|
|
9116
9393
|
const labelColor = colorMatch ? colorMatch[0] : "";
|
|
9117
9394
|
const path = pinString.split("^^")[2]?.split("~")[0] ?? "";
|
|
@@ -9590,6 +9867,14 @@ var getEasyEdaCadModelPlacement = async (easyEdaJson, { fetch: fetch2 = globalTh
|
|
|
9590
9867
|
return placementPromise;
|
|
9591
9868
|
};
|
|
9592
9869
|
|
|
9870
|
+
// lib/utils/normalize-symbol-name.ts
|
|
9871
|
+
var normalizeSymbolName = (name) => {
|
|
9872
|
+
const trimmedName = name.trim();
|
|
9873
|
+
if (trimmedName === "+") return "_POS";
|
|
9874
|
+
if (trimmedName === "-") return "_NEG";
|
|
9875
|
+
return trimmedName.replace(/(?<=[A-Za-z0-9])-(?=[A-Za-z0-9])/g, "_");
|
|
9876
|
+
};
|
|
9877
|
+
|
|
9593
9878
|
// lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
|
|
9594
9879
|
var round = (value) => Number(value.toFixed(6));
|
|
9595
9880
|
var EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT = 0.02;
|
|
@@ -9816,14 +10101,15 @@ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
|
|
|
9816
10101
|
portName ??= `pin${pinIndex + 1}`;
|
|
9817
10102
|
usedPortNames.add(portName);
|
|
9818
10103
|
const sourcePort = sourcePorts.find((port) => port.name === portName);
|
|
10104
|
+
let aliases = getEasyEdaPinAliases(pin.label);
|
|
10105
|
+
if (sourcePort?.port_hints?.length) {
|
|
10106
|
+
aliases = sourcePort.port_hints;
|
|
10107
|
+
}
|
|
9819
10108
|
metadataByShapeId.set(pin.id, {
|
|
9820
10109
|
name: portName,
|
|
9821
10110
|
pinNumber: sourcePort?.pin_number,
|
|
9822
|
-
aliases:
|
|
9823
|
-
|
|
9824
|
-
...pin.label ? [normalizeSymbolName(pin.label)] : []
|
|
9825
|
-
].filter(
|
|
9826
|
-
(alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
|
|
10111
|
+
aliases: aliases.filter(
|
|
10112
|
+
(alias, index, aliases2) => alias !== portName && aliases2.indexOf(alias) === index
|
|
9827
10113
|
)
|
|
9828
10114
|
});
|
|
9829
10115
|
});
|