easyeda 0.0.384 → 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 +187 -17
- package/dist/browser/index.js.map +1 -1
- package/dist/index.js +187 -17
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +188 -18
- package/dist/main.cjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15423,24 +15423,163 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
|
|
|
15423
15423
|
// lib/utils/easyeda-unit-to-mm.ts
|
|
15424
15424
|
var mil10ToMm = (value) => value * 10 * 0.0254;
|
|
15425
15425
|
|
|
15426
|
+
// lib/utils/parse-easyeda-path-commands.ts
|
|
15427
|
+
var argumentCounts = {
|
|
15428
|
+
M: 2,
|
|
15429
|
+
L: 2,
|
|
15430
|
+
H: 1,
|
|
15431
|
+
V: 1,
|
|
15432
|
+
C: 6,
|
|
15433
|
+
S: 4,
|
|
15434
|
+
Q: 4,
|
|
15435
|
+
T: 2,
|
|
15436
|
+
A: 7,
|
|
15437
|
+
Z: 0
|
|
15438
|
+
};
|
|
15439
|
+
var parseEasyEdaPathCommands = (pathData) => {
|
|
15440
|
+
const commands = [];
|
|
15441
|
+
let currentCommand;
|
|
15442
|
+
let lastTokenEnd = 0;
|
|
15443
|
+
for (const token of pathData.matchAll(
|
|
15444
|
+
/([a-df-z])|([-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?)/gi
|
|
15445
|
+
)) {
|
|
15446
|
+
if (!/^[\s,]*$/.test(pathData.slice(lastTokenEnd, token.index))) return null;
|
|
15447
|
+
lastTokenEnd = token.index + token[0].length;
|
|
15448
|
+
if (token[1]) {
|
|
15449
|
+
if (!Object.hasOwn(argumentCounts, token[1].toUpperCase())) return null;
|
|
15450
|
+
currentCommand = { command: token[1], arguments: [] };
|
|
15451
|
+
commands.push(currentCommand);
|
|
15452
|
+
} else {
|
|
15453
|
+
const commandArgument = Number(token[2]);
|
|
15454
|
+
if (!currentCommand || !Number.isFinite(commandArgument)) return null;
|
|
15455
|
+
currentCommand.arguments.push(commandArgument);
|
|
15456
|
+
}
|
|
15457
|
+
}
|
|
15458
|
+
if (!/^[\s,]*$/.test(pathData.slice(lastTokenEnd))) return null;
|
|
15459
|
+
if (commands[0]?.command.toUpperCase() !== "M") return null;
|
|
15460
|
+
for (const pathCommand of commands) {
|
|
15461
|
+
const argumentCount = argumentCounts[pathCommand.command.toUpperCase()];
|
|
15462
|
+
const count = pathCommand.arguments.length;
|
|
15463
|
+
if (argumentCount === 0 ? count !== 0 : count === 0 || count % argumentCount !== 0) {
|
|
15464
|
+
return null;
|
|
15465
|
+
}
|
|
15466
|
+
}
|
|
15467
|
+
return commands;
|
|
15468
|
+
};
|
|
15469
|
+
|
|
15470
|
+
// lib/utils/get-easyeda-npth-pill-hole.ts
|
|
15471
|
+
var PATH_GEOMETRY_TOLERANCE = 1e-9;
|
|
15472
|
+
var isClose = (a, b) => Math.abs(a - b) < PATH_GEOMETRY_TOLERANCE;
|
|
15473
|
+
var getEasyEdaNpthPillHole = (pathData) => {
|
|
15474
|
+
const commands = parseEasyEdaPathCommands(pathData);
|
|
15475
|
+
if (!commands || commands.map((command) => command.command).join("") !== "MLALAZ") {
|
|
15476
|
+
return null;
|
|
15477
|
+
}
|
|
15478
|
+
const coordinates = commands.slice(0, -1).map((command) => command.arguments);
|
|
15479
|
+
if (coordinates.map((command) => command.length).join(",") !== "2,2,7,2,7") {
|
|
15480
|
+
return null;
|
|
15481
|
+
}
|
|
15482
|
+
const [start, firstLineEnd, firstArc, secondLineEnd, secondArc] = coordinates;
|
|
15483
|
+
const firstArcEnd = firstArc.slice(5);
|
|
15484
|
+
const secondArcEnd = secondArc.slice(5);
|
|
15485
|
+
const radius = firstArc[0];
|
|
15486
|
+
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])) {
|
|
15487
|
+
return null;
|
|
15488
|
+
}
|
|
15489
|
+
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);
|
|
15490
|
+
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);
|
|
15491
|
+
if (!horizontal && !vertical) return null;
|
|
15492
|
+
const straightLength = horizontal ? Math.abs(start[0] - firstLineEnd[0]) : Math.abs(start[1] - firstLineEnd[1]);
|
|
15493
|
+
if (straightLength < PATH_GEOMETRY_TOLERANCE) return null;
|
|
15494
|
+
const crossProduct = (firstLineEnd[0] - firstArcEnd[0]) * (firstLineEnd[1] - start[1]) - (firstLineEnd[1] - firstArcEnd[1]) * (firstLineEnd[0] - start[0]);
|
|
15495
|
+
if (firstArc[4] !== Number(crossProduct > 0)) return null;
|
|
15496
|
+
return {
|
|
15497
|
+
hole_shape: "pill",
|
|
15498
|
+
x: mil2mm((start[0] + firstArcEnd[0]) / 2) * 10,
|
|
15499
|
+
y: mil2mm((start[1] + firstArcEnd[1]) / 2) * 10,
|
|
15500
|
+
hole_width: mil2mm(horizontal ? straightLength + radius * 2 : radius * 2) * 10,
|
|
15501
|
+
hole_height: mil2mm(vertical ? straightLength + radius * 2 : radius * 2) * 10
|
|
15502
|
+
};
|
|
15503
|
+
};
|
|
15504
|
+
|
|
15505
|
+
// lib/utils/convert-easyeda-npth-cutouts-to-holes.ts
|
|
15506
|
+
var convertEasyEdaNpthCutoutsToHoles = (circuitJson, npthRegions) => {
|
|
15507
|
+
const npthPillHoles = npthRegions.map((region, index) => ({
|
|
15508
|
+
pcb_cutout_id: `pcb_cutout_npth_${index + 1}`,
|
|
15509
|
+
hole: getEasyEdaNpthPillHole(region.pathData)
|
|
15510
|
+
}));
|
|
15511
|
+
return circuitJson.map((element) => {
|
|
15512
|
+
if (element.type !== "pcb_cutout" || element.shape !== "polygon") {
|
|
15513
|
+
return element;
|
|
15514
|
+
}
|
|
15515
|
+
const npthPillHole = npthPillHoles.find(
|
|
15516
|
+
(candidate) => candidate.pcb_cutout_id === element.pcb_cutout_id
|
|
15517
|
+
);
|
|
15518
|
+
if (!npthPillHole?.hole) return element;
|
|
15519
|
+
const xs = element.points.map((point4) => point4.x);
|
|
15520
|
+
const ys = element.points.map((point4) => point4.y);
|
|
15521
|
+
return pcb_hole.parse({
|
|
15522
|
+
type: "pcb_hole",
|
|
15523
|
+
pcb_hole_id: element.pcb_cutout_id.replace("pcb_cutout_", "pcb_hole_"),
|
|
15524
|
+
pcb_component_id: element.pcb_component_id,
|
|
15525
|
+
...npthPillHole.hole,
|
|
15526
|
+
x: (Math.min(...xs) + Math.max(...xs)) / 2,
|
|
15527
|
+
y: (Math.min(...ys) + Math.max(...ys)) / 2
|
|
15528
|
+
});
|
|
15529
|
+
});
|
|
15530
|
+
};
|
|
15531
|
+
|
|
15426
15532
|
// lib/utils/expand-easyeda-path-data.ts
|
|
15427
15533
|
var expandEasyEdaPathData = (pathData) => {
|
|
15534
|
+
const commands = parseEasyEdaPathCommands(pathData);
|
|
15535
|
+
if (!commands) throw new Error("Invalid EasyEDA SOLIDREGION path");
|
|
15536
|
+
for (const { command } of commands) {
|
|
15537
|
+
if (!/^[MLHVAZ]$/i.test(command)) {
|
|
15538
|
+
throw new Error(
|
|
15539
|
+
`Unsupported EasyEDA SOLIDREGION path command: ${command}`
|
|
15540
|
+
);
|
|
15541
|
+
}
|
|
15542
|
+
}
|
|
15543
|
+
if (commands.slice(1).some(({ command }) => command.toUpperCase() === "M")) {
|
|
15544
|
+
throw new Error("Multiple EasyEDA SOLIDREGION subpaths are not supported");
|
|
15545
|
+
}
|
|
15428
15546
|
const rawRoute = [];
|
|
15429
15547
|
let currentPoint;
|
|
15430
|
-
|
|
15431
|
-
|
|
15432
|
-
|
|
15433
|
-
|
|
15434
|
-
|
|
15435
|
-
|
|
15548
|
+
let subpathStart;
|
|
15549
|
+
let afterClose = false;
|
|
15550
|
+
for (const pathCommand of commands) {
|
|
15551
|
+
const command = pathCommand.command.toUpperCase();
|
|
15552
|
+
const relative = pathCommand.command !== command;
|
|
15553
|
+
const commandArguments = pathCommand.arguments;
|
|
15554
|
+
if (afterClose && command !== "Z" && currentPoint) {
|
|
15555
|
+
const lastPoint = rawRoute.at(-1);
|
|
15556
|
+
if (lastPoint?.x !== currentPoint.x || lastPoint?.y !== currentPoint.y) {
|
|
15436
15557
|
rawRoute.push(currentPoint);
|
|
15437
15558
|
}
|
|
15438
|
-
}
|
|
15439
|
-
|
|
15440
|
-
|
|
15441
|
-
|
|
15442
|
-
|
|
15443
|
-
|
|
15559
|
+
}
|
|
15560
|
+
afterClose = command === "Z";
|
|
15561
|
+
if ((command === "M" || command === "L") && commandArguments.length >= 2) {
|
|
15562
|
+
for (let offset = 0; offset + 1 < commandArguments.length; offset += 2) {
|
|
15563
|
+
currentPoint = {
|
|
15564
|
+
x: commandArguments[offset] + (relative ? currentPoint?.x ?? 0 : 0),
|
|
15565
|
+
y: commandArguments[offset + 1] + (relative ? currentPoint?.y ?? 0 : 0)
|
|
15566
|
+
};
|
|
15567
|
+
rawRoute.push(currentPoint);
|
|
15568
|
+
if (command === "M" && offset === 0) subpathStart = currentPoint;
|
|
15569
|
+
}
|
|
15570
|
+
} else if ((command === "H" || command === "V") && currentPoint) {
|
|
15571
|
+
for (const coordinate of commandArguments) {
|
|
15572
|
+
currentPoint = {
|
|
15573
|
+
x: command === "H" ? coordinate + (relative ? currentPoint.x : 0) : currentPoint.x,
|
|
15574
|
+
y: command === "V" ? coordinate + (relative ? currentPoint.y : 0) : currentPoint.y
|
|
15575
|
+
};
|
|
15576
|
+
rawRoute.push(currentPoint);
|
|
15577
|
+
}
|
|
15578
|
+
} else if (command === "A" && currentPoint && commandArguments.length >= 7) {
|
|
15579
|
+
for (let offset = 0; offset + 6 < commandArguments.length; offset += 7) {
|
|
15580
|
+
const [radiusX, , , largeArcFlag, sweepFlag, endpointX, endpointY] = commandArguments.slice(offset, offset + 7);
|
|
15581
|
+
const endX = endpointX + (relative ? currentPoint.x : 0);
|
|
15582
|
+
const endY = endpointY + (relative ? currentPoint.y : 0);
|
|
15444
15583
|
const generatedArcRoute = generateArcFromSweep(
|
|
15445
15584
|
currentPoint.x,
|
|
15446
15585
|
currentPoint.y,
|
|
@@ -15462,6 +15601,8 @@ var expandEasyEdaPathData = (pathData) => {
|
|
|
15462
15601
|
rawRoute.push(...arcRoute.slice(1));
|
|
15463
15602
|
currentPoint = { x: endX, y: endY };
|
|
15464
15603
|
}
|
|
15604
|
+
} else if (command === "Z" && subpathStart) {
|
|
15605
|
+
currentPoint = subpathStart;
|
|
15465
15606
|
}
|
|
15466
15607
|
}
|
|
15467
15608
|
return rawRoute;
|
|
@@ -16508,9 +16649,10 @@ var convertEasyEdaJsonToCircuitJsonWithPinAttributes = (easyEdaJson, {
|
|
|
16508
16649
|
).forEach((sr, index) => {
|
|
16509
16650
|
circuitElements.push(handleCutout(sr, index));
|
|
16510
16651
|
});
|
|
16511
|
-
easyEdaJson.packageDetail.dataStr.shape.filter(
|
|
16652
|
+
const npthRegions = easyEdaJson.packageDetail.dataStr.shape.filter(
|
|
16512
16653
|
(shape) => shape.type === "SOLIDREGION" && isPcbSolidRegionNpth(shape)
|
|
16513
|
-
)
|
|
16654
|
+
);
|
|
16655
|
+
npthRegions.forEach((sr, index) => {
|
|
16514
16656
|
const geometry = getEasyEdaNpthSlotGeometry(sr);
|
|
16515
16657
|
if (!geometry) return;
|
|
16516
16658
|
circuitElements.push(
|
|
@@ -16805,7 +16947,10 @@ var convertEasyEdaJsonToCircuitJsonWithPinAttributes = (easyEdaJson, {
|
|
|
16805
16947
|
}
|
|
16806
16948
|
pcb_component2.center = { x: 0, y: 0 };
|
|
16807
16949
|
}
|
|
16808
|
-
return {
|
|
16950
|
+
return {
|
|
16951
|
+
circuitJson: convertEasyEdaNpthCutoutsToHoles(circuitElements, npthRegions),
|
|
16952
|
+
resolvedPinAttributes
|
|
16953
|
+
};
|
|
16809
16954
|
};
|
|
16810
16955
|
var convertEasyEdaJsonToCircuitJson = (easyEdaJson, options = {}) => convertEasyEdaJsonToCircuitJsonWithPinAttributes(easyEdaJson, options).circuitJson;
|
|
16811
16956
|
|
|
@@ -18947,13 +19092,36 @@ var isPolarizedCapacitorComponent = (betterEasy) => {
|
|
|
18947
19092
|
return polarizedCapacitorMetadataPattern.test(metadata) || betterEasy.dataStr.shape.some((shape) => shape.type === "ARC");
|
|
18948
19093
|
};
|
|
18949
19094
|
|
|
19095
|
+
// lib/websafe/convert-to-typescript-component/category-value-contains-crystal.ts
|
|
19096
|
+
var categoryValueContainsCrystal = (value) => {
|
|
19097
|
+
if (typeof value === "string") {
|
|
19098
|
+
return /^crystals?$/i.test(value.trim());
|
|
19099
|
+
}
|
|
19100
|
+
if (Array.isArray(value)) {
|
|
19101
|
+
return value.some(categoryValueContainsCrystal);
|
|
19102
|
+
}
|
|
19103
|
+
if (value && typeof value === "object") {
|
|
19104
|
+
return Object.values(value).some(categoryValueContainsCrystal);
|
|
19105
|
+
}
|
|
19106
|
+
return false;
|
|
19107
|
+
};
|
|
19108
|
+
|
|
18950
19109
|
// lib/websafe/convert-to-typescript-component/is-crystal-component.ts
|
|
18951
19110
|
var frequencyPattern = /^\d+(?:\.\d+)?\s*(?:Hz|kHz|MHz|GHz)$/i;
|
|
18952
19111
|
var isCrystalComponent = (betterEasy) => {
|
|
18953
19112
|
const componentParameters = betterEasy.dataStr.head.c_para;
|
|
18954
19113
|
const packageName = componentParameters.package;
|
|
18955
19114
|
const value = componentParameters.Value;
|
|
18956
|
-
|
|
19115
|
+
const hasCrystalCategory = [
|
|
19116
|
+
betterEasy.tags,
|
|
19117
|
+
componentParameters.category,
|
|
19118
|
+
componentParameters.Category,
|
|
19119
|
+
componentParameters["LCSC Category"],
|
|
19120
|
+
componentParameters["JLCPCB Category"],
|
|
19121
|
+
betterEasy.category
|
|
19122
|
+
].some(categoryValueContainsCrystal);
|
|
19123
|
+
const hasCrystalPackageAndPrefix = componentParameters.pre === "X?" && packageName?.toUpperCase().startsWith("CRYSTAL-") === true;
|
|
19124
|
+
return (hasCrystalCategory || hasCrystalPackageAndPrefix) && typeof value === "string" && frequencyPattern.test(value.trim());
|
|
18957
19125
|
};
|
|
18958
19126
|
|
|
18959
19127
|
// lib/websafe/convert-to-typescript-component/is-dip-switch-category-component.ts
|
|
@@ -19118,7 +19286,9 @@ var getGeneratedComponentType = (betterEasy, pinCount) => {
|
|
|
19118
19286
|
if (isCapacitorComponent(betterEasy)) return "capacitor";
|
|
19119
19287
|
if (isResistorComponent(betterEasy) && pinCount === 2) return "resistor";
|
|
19120
19288
|
if (isInductorComponent(betterEasy) && pinCount === 2) return "inductor";
|
|
19121
|
-
if (isCrystalComponent(betterEasy))
|
|
19289
|
+
if (isCrystalComponent(betterEasy) && (pinCount === 2 || pinCount === 4)) {
|
|
19290
|
+
return "crystal";
|
|
19291
|
+
}
|
|
19122
19292
|
if (isMicroUsbConnectorComponent(betterEasy)) return "connector";
|
|
19123
19293
|
return "chip";
|
|
19124
19294
|
};
|