easyeda 0.0.385 → 0.0.386
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 +160 -15
- package/dist/browser/index.js.map +1 -1
- package/dist/index.js +160 -15
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +161 -16
- package/dist/main.cjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -19220,24 +19220,163 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
|
|
|
19220
19220
|
// lib/utils/easyeda-unit-to-mm.ts
|
|
19221
19221
|
var mil10ToMm = (value) => value * 10 * 0.0254;
|
|
19222
19222
|
|
|
19223
|
+
// lib/utils/parse-easyeda-path-commands.ts
|
|
19224
|
+
var argumentCounts = {
|
|
19225
|
+
M: 2,
|
|
19226
|
+
L: 2,
|
|
19227
|
+
H: 1,
|
|
19228
|
+
V: 1,
|
|
19229
|
+
C: 6,
|
|
19230
|
+
S: 4,
|
|
19231
|
+
Q: 4,
|
|
19232
|
+
T: 2,
|
|
19233
|
+
A: 7,
|
|
19234
|
+
Z: 0
|
|
19235
|
+
};
|
|
19236
|
+
var parseEasyEdaPathCommands = (pathData) => {
|
|
19237
|
+
const commands = [];
|
|
19238
|
+
let currentCommand;
|
|
19239
|
+
let lastTokenEnd = 0;
|
|
19240
|
+
for (const token of pathData.matchAll(
|
|
19241
|
+
/([a-df-z])|([-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?)/gi
|
|
19242
|
+
)) {
|
|
19243
|
+
if (!/^[\s,]*$/.test(pathData.slice(lastTokenEnd, token.index))) return null;
|
|
19244
|
+
lastTokenEnd = token.index + token[0].length;
|
|
19245
|
+
if (token[1]) {
|
|
19246
|
+
if (!Object.hasOwn(argumentCounts, token[1].toUpperCase())) return null;
|
|
19247
|
+
currentCommand = { command: token[1], arguments: [] };
|
|
19248
|
+
commands.push(currentCommand);
|
|
19249
|
+
} else {
|
|
19250
|
+
const commandArgument = Number(token[2]);
|
|
19251
|
+
if (!currentCommand || !Number.isFinite(commandArgument)) return null;
|
|
19252
|
+
currentCommand.arguments.push(commandArgument);
|
|
19253
|
+
}
|
|
19254
|
+
}
|
|
19255
|
+
if (!/^[\s,]*$/.test(pathData.slice(lastTokenEnd))) return null;
|
|
19256
|
+
if (commands[0]?.command.toUpperCase() !== "M") return null;
|
|
19257
|
+
for (const pathCommand of commands) {
|
|
19258
|
+
const argumentCount = argumentCounts[pathCommand.command.toUpperCase()];
|
|
19259
|
+
const count = pathCommand.arguments.length;
|
|
19260
|
+
if (argumentCount === 0 ? count !== 0 : count === 0 || count % argumentCount !== 0) {
|
|
19261
|
+
return null;
|
|
19262
|
+
}
|
|
19263
|
+
}
|
|
19264
|
+
return commands;
|
|
19265
|
+
};
|
|
19266
|
+
|
|
19267
|
+
// lib/utils/get-easyeda-npth-pill-hole.ts
|
|
19268
|
+
var PATH_GEOMETRY_TOLERANCE = 1e-9;
|
|
19269
|
+
var isClose = (a, b) => Math.abs(a - b) < PATH_GEOMETRY_TOLERANCE;
|
|
19270
|
+
var getEasyEdaNpthPillHole = (pathData) => {
|
|
19271
|
+
const commands = parseEasyEdaPathCommands(pathData);
|
|
19272
|
+
if (!commands || commands.map((command) => command.command).join("") !== "MLALAZ") {
|
|
19273
|
+
return null;
|
|
19274
|
+
}
|
|
19275
|
+
const coordinates = commands.slice(0, -1).map((command) => command.arguments);
|
|
19276
|
+
if (coordinates.map((command) => command.length).join(",") !== "2,2,7,2,7") {
|
|
19277
|
+
return null;
|
|
19278
|
+
}
|
|
19279
|
+
const [start, firstLineEnd, firstArc, secondLineEnd, secondArc] = coordinates;
|
|
19280
|
+
const firstArcEnd = firstArc.slice(5);
|
|
19281
|
+
const secondArcEnd = secondArc.slice(5);
|
|
19282
|
+
const radius = firstArc[0];
|
|
19283
|
+
if (radius <= 0 || !isClose(firstArc[1], radius) || !isClose(secondArc[0], radius) || !isClose(secondArc[1], radius) || ![0, 1].includes(firstArc[3]) || ![0, 1].includes(secondArc[3]) || ![0, 1].includes(firstArc[4]) || firstArc[4] !== secondArc[4] || !isClose(start[0], secondArcEnd[0]) || !isClose(start[1], secondArcEnd[1])) {
|
|
19284
|
+
return null;
|
|
19285
|
+
}
|
|
19286
|
+
const horizontal = isClose(start[1], firstLineEnd[1]) && isClose(firstLineEnd[0], firstArcEnd[0]) && isClose(firstArcEnd[1], secondLineEnd[1]) && isClose(secondLineEnd[0], start[0]) && isClose(Math.abs(firstArcEnd[1] - firstLineEnd[1]), radius * 2);
|
|
19287
|
+
const vertical = isClose(start[0], firstLineEnd[0]) && isClose(firstLineEnd[1], firstArcEnd[1]) && isClose(firstArcEnd[0], secondLineEnd[0]) && isClose(secondLineEnd[1], start[1]) && isClose(Math.abs(firstArcEnd[0] - firstLineEnd[0]), radius * 2);
|
|
19288
|
+
if (!horizontal && !vertical) return null;
|
|
19289
|
+
const straightLength = horizontal ? Math.abs(start[0] - firstLineEnd[0]) : Math.abs(start[1] - firstLineEnd[1]);
|
|
19290
|
+
if (straightLength < PATH_GEOMETRY_TOLERANCE) return null;
|
|
19291
|
+
const crossProduct = (firstLineEnd[0] - firstArcEnd[0]) * (firstLineEnd[1] - start[1]) - (firstLineEnd[1] - firstArcEnd[1]) * (firstLineEnd[0] - start[0]);
|
|
19292
|
+
if (firstArc[4] !== Number(crossProduct > 0)) return null;
|
|
19293
|
+
return {
|
|
19294
|
+
hole_shape: "pill",
|
|
19295
|
+
x: mil2mm((start[0] + firstArcEnd[0]) / 2) * 10,
|
|
19296
|
+
y: mil2mm((start[1] + firstArcEnd[1]) / 2) * 10,
|
|
19297
|
+
hole_width: mil2mm(horizontal ? straightLength + radius * 2 : radius * 2) * 10,
|
|
19298
|
+
hole_height: mil2mm(vertical ? straightLength + radius * 2 : radius * 2) * 10
|
|
19299
|
+
};
|
|
19300
|
+
};
|
|
19301
|
+
|
|
19302
|
+
// lib/utils/convert-easyeda-npth-cutouts-to-holes.ts
|
|
19303
|
+
var convertEasyEdaNpthCutoutsToHoles = (circuitJson, npthRegions) => {
|
|
19304
|
+
const npthPillHoles = npthRegions.map((region, index) => ({
|
|
19305
|
+
pcb_cutout_id: `pcb_cutout_npth_${index + 1}`,
|
|
19306
|
+
hole: getEasyEdaNpthPillHole(region.pathData)
|
|
19307
|
+
}));
|
|
19308
|
+
return circuitJson.map((element) => {
|
|
19309
|
+
if (element.type !== "pcb_cutout" || element.shape !== "polygon") {
|
|
19310
|
+
return element;
|
|
19311
|
+
}
|
|
19312
|
+
const npthPillHole = npthPillHoles.find(
|
|
19313
|
+
(candidate) => candidate.pcb_cutout_id === element.pcb_cutout_id
|
|
19314
|
+
);
|
|
19315
|
+
if (!npthPillHole?.hole) return element;
|
|
19316
|
+
const xs = element.points.map((point4) => point4.x);
|
|
19317
|
+
const ys = element.points.map((point4) => point4.y);
|
|
19318
|
+
return pcb_hole.parse({
|
|
19319
|
+
type: "pcb_hole",
|
|
19320
|
+
pcb_hole_id: element.pcb_cutout_id.replace("pcb_cutout_", "pcb_hole_"),
|
|
19321
|
+
pcb_component_id: element.pcb_component_id,
|
|
19322
|
+
...npthPillHole.hole,
|
|
19323
|
+
x: (Math.min(...xs) + Math.max(...xs)) / 2,
|
|
19324
|
+
y: (Math.min(...ys) + Math.max(...ys)) / 2
|
|
19325
|
+
});
|
|
19326
|
+
});
|
|
19327
|
+
};
|
|
19328
|
+
|
|
19223
19329
|
// lib/utils/expand-easyeda-path-data.ts
|
|
19224
19330
|
var expandEasyEdaPathData = (pathData) => {
|
|
19331
|
+
const commands = parseEasyEdaPathCommands(pathData);
|
|
19332
|
+
if (!commands) throw new Error("Invalid EasyEDA SOLIDREGION path");
|
|
19333
|
+
for (const { command } of commands) {
|
|
19334
|
+
if (!/^[MLHVAZ]$/i.test(command)) {
|
|
19335
|
+
throw new Error(
|
|
19336
|
+
`Unsupported EasyEDA SOLIDREGION path command: ${command}`
|
|
19337
|
+
);
|
|
19338
|
+
}
|
|
19339
|
+
}
|
|
19340
|
+
if (commands.slice(1).some(({ command }) => command.toUpperCase() === "M")) {
|
|
19341
|
+
throw new Error("Multiple EasyEDA SOLIDREGION subpaths are not supported");
|
|
19342
|
+
}
|
|
19225
19343
|
const rawRoute = [];
|
|
19226
19344
|
let currentPoint;
|
|
19227
|
-
|
|
19228
|
-
|
|
19229
|
-
|
|
19230
|
-
|
|
19231
|
-
|
|
19232
|
-
|
|
19345
|
+
let subpathStart;
|
|
19346
|
+
let afterClose = false;
|
|
19347
|
+
for (const pathCommand of commands) {
|
|
19348
|
+
const command = pathCommand.command.toUpperCase();
|
|
19349
|
+
const relative = pathCommand.command !== command;
|
|
19350
|
+
const commandArguments = pathCommand.arguments;
|
|
19351
|
+
if (afterClose && command !== "Z" && currentPoint) {
|
|
19352
|
+
const lastPoint = rawRoute.at(-1);
|
|
19353
|
+
if (lastPoint?.x !== currentPoint.x || lastPoint?.y !== currentPoint.y) {
|
|
19233
19354
|
rawRoute.push(currentPoint);
|
|
19234
19355
|
}
|
|
19235
|
-
}
|
|
19236
|
-
|
|
19237
|
-
|
|
19238
|
-
|
|
19239
|
-
|
|
19240
|
-
|
|
19356
|
+
}
|
|
19357
|
+
afterClose = command === "Z";
|
|
19358
|
+
if ((command === "M" || command === "L") && commandArguments.length >= 2) {
|
|
19359
|
+
for (let offset = 0; offset + 1 < commandArguments.length; offset += 2) {
|
|
19360
|
+
currentPoint = {
|
|
19361
|
+
x: commandArguments[offset] + (relative ? currentPoint?.x ?? 0 : 0),
|
|
19362
|
+
y: commandArguments[offset + 1] + (relative ? currentPoint?.y ?? 0 : 0)
|
|
19363
|
+
};
|
|
19364
|
+
rawRoute.push(currentPoint);
|
|
19365
|
+
if (command === "M" && offset === 0) subpathStart = currentPoint;
|
|
19366
|
+
}
|
|
19367
|
+
} else if ((command === "H" || command === "V") && currentPoint) {
|
|
19368
|
+
for (const coordinate of commandArguments) {
|
|
19369
|
+
currentPoint = {
|
|
19370
|
+
x: command === "H" ? coordinate + (relative ? currentPoint.x : 0) : currentPoint.x,
|
|
19371
|
+
y: command === "V" ? coordinate + (relative ? currentPoint.y : 0) : currentPoint.y
|
|
19372
|
+
};
|
|
19373
|
+
rawRoute.push(currentPoint);
|
|
19374
|
+
}
|
|
19375
|
+
} else if (command === "A" && currentPoint && commandArguments.length >= 7) {
|
|
19376
|
+
for (let offset = 0; offset + 6 < commandArguments.length; offset += 7) {
|
|
19377
|
+
const [radiusX, , , largeArcFlag, sweepFlag, endpointX, endpointY] = commandArguments.slice(offset, offset + 7);
|
|
19378
|
+
const endX = endpointX + (relative ? currentPoint.x : 0);
|
|
19379
|
+
const endY = endpointY + (relative ? currentPoint.y : 0);
|
|
19241
19380
|
const generatedArcRoute = generateArcFromSweep(
|
|
19242
19381
|
currentPoint.x,
|
|
19243
19382
|
currentPoint.y,
|
|
@@ -19259,6 +19398,8 @@ var expandEasyEdaPathData = (pathData) => {
|
|
|
19259
19398
|
rawRoute.push(...arcRoute.slice(1));
|
|
19260
19399
|
currentPoint = { x: endX, y: endY };
|
|
19261
19400
|
}
|
|
19401
|
+
} else if (command === "Z" && subpathStart) {
|
|
19402
|
+
currentPoint = subpathStart;
|
|
19262
19403
|
}
|
|
19263
19404
|
}
|
|
19264
19405
|
return rawRoute;
|
|
@@ -20305,9 +20446,10 @@ var convertEasyEdaJsonToCircuitJsonWithPinAttributes = (easyEdaJson, {
|
|
|
20305
20446
|
).forEach((sr, index) => {
|
|
20306
20447
|
circuitElements.push(handleCutout(sr, index));
|
|
20307
20448
|
});
|
|
20308
|
-
easyEdaJson.packageDetail.dataStr.shape.filter(
|
|
20449
|
+
const npthRegions = easyEdaJson.packageDetail.dataStr.shape.filter(
|
|
20309
20450
|
(shape) => shape.type === "SOLIDREGION" && isPcbSolidRegionNpth(shape)
|
|
20310
|
-
)
|
|
20451
|
+
);
|
|
20452
|
+
npthRegions.forEach((sr, index) => {
|
|
20311
20453
|
const geometry = getEasyEdaNpthSlotGeometry(sr);
|
|
20312
20454
|
if (!geometry) return;
|
|
20313
20455
|
circuitElements.push(
|
|
@@ -20602,7 +20744,10 @@ var convertEasyEdaJsonToCircuitJsonWithPinAttributes = (easyEdaJson, {
|
|
|
20602
20744
|
}
|
|
20603
20745
|
pcb_component2.center = { x: 0, y: 0 };
|
|
20604
20746
|
}
|
|
20605
|
-
return {
|
|
20747
|
+
return {
|
|
20748
|
+
circuitJson: convertEasyEdaNpthCutoutsToHoles(circuitElements, npthRegions),
|
|
20749
|
+
resolvedPinAttributes
|
|
20750
|
+
};
|
|
20606
20751
|
};
|
|
20607
20752
|
var convertEasyEdaJsonToCircuitJson = (easyEdaJson, options = {}) => convertEasyEdaJsonToCircuitJsonWithPinAttributes(easyEdaJson, options).circuitJson;
|
|
20608
20753
|
|