easyeda 0.0.385 → 0.0.387

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/index.js CHANGED
@@ -15380,10 +15380,25 @@ var mil2mm = (mil) => {
15380
15380
  // lib/constants.ts
15381
15381
  var DEFAULT_PCB_THICKNESS_MM = 1.6;
15382
15382
 
15383
+ // lib/utils/easyeda-path-limits.ts
15384
+ var MAX_EASYEDA_PATH_POINTS = 8192;
15385
+ var EASYEDA_PATH_LIMIT_MESSAGE = "EasyEDA SOLIDREGION path exceeds the vertex limit";
15386
+ var INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE = "Invalid EasyEDA SOLIDREGION path geometry";
15387
+
15383
15388
  // lib/math/arc-utils.ts
15384
- function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag, sweepFlag) {
15385
- const start = { x: startX, y: startY };
15386
- const end = { x: endX, y: endY };
15389
+ function generateArcFromSweep({
15390
+ start,
15391
+ end,
15392
+ radius,
15393
+ largeArcFlag,
15394
+ sweepFlag,
15395
+ maxSegments = MAX_EASYEDA_PATH_POINTS - 1
15396
+ }) {
15397
+ const { x: startX, y: startY } = start;
15398
+ const { x: endX, y: endY } = end;
15399
+ if (![startX, startY, endX, endY, radius].every(Number.isFinite) || !Number.isInteger(maxSegments) || maxSegments < 1) {
15400
+ throw new Error(INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE);
15401
+ }
15387
15402
  const midX = (startX + endX) / 2;
15388
15403
  const midY = (startY + endY) / 2;
15389
15404
  const dx = endX - startX;
@@ -15409,12 +15424,26 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
15409
15424
  const minNumPoints = Math.max(2, Math.ceil(arcAngle * radius));
15410
15425
  const isSemicircle = Math.abs(arcAngle - Math.PI) < 1e-6;
15411
15426
  const numPoints = isSemicircle ? minNumPoints + minNumPoints % 2 : minNumPoints;
15427
+ if (![centerX, centerY, startAngle, endAngle, numPoints].every(Number.isFinite)) {
15428
+ throw new Error(INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE);
15429
+ }
15430
+ const sampledSegments = Math.min(
15431
+ numPoints,
15432
+ maxSegments,
15433
+ MAX_EASYEDA_PATH_POINTS - 1
15434
+ );
15412
15435
  const path = [];
15413
- for (let i = 0; i <= numPoints; i++) {
15414
- const t = i / numPoints;
15436
+ for (let i = 0; i <= sampledSegments; i++) {
15437
+ const pointIndex = sampledSegments === numPoints ? i : Math.round(
15438
+ numPoints <= Number.MAX_SAFE_INTEGER / sampledSegments ? i * numPoints / sampledSegments : i / sampledSegments * numPoints
15439
+ );
15440
+ const t = pointIndex / numPoints;
15415
15441
  const angle2 = startAngle + t * (endAngle - startAngle);
15416
15442
  const x = centerX + radius * Math.cos(angle2);
15417
15443
  const y = centerY + radius * Math.sin(angle2);
15444
+ if (!Number.isFinite(x) || !Number.isFinite(y)) {
15445
+ throw new Error(INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE);
15446
+ }
15418
15447
  path.push({ x, y });
15419
15448
  }
15420
15449
  return path;
@@ -15423,48 +15452,123 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
15423
15452
  // lib/utils/easyeda-unit-to-mm.ts
15424
15453
  var mil10ToMm = (value) => value * 10 * 0.0254;
15425
15454
 
15426
- // lib/utils/expand-easyeda-path-data.ts
15427
- var expandEasyEdaPathData = (pathData) => {
15428
- const rawRoute = [];
15429
- let currentPoint;
15430
- for (const commandMatch of pathData.matchAll(/([MLAZ])([^MLAZ]*)/gi)) {
15431
- const command = commandMatch[1]?.toUpperCase();
15432
- const values = commandMatch[2]?.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
15433
- if ((command === "M" || command === "L") && values.length >= 2) {
15434
- for (let offset = 0; offset + 1 < values.length; offset += 2) {
15435
- currentPoint = { x: values[offset], y: values[offset + 1] };
15436
- rawRoute.push(currentPoint);
15437
- }
15438
- } else if (command === "A" && currentPoint && values.length >= 7) {
15439
- for (let offset = 0; offset + 6 < values.length; offset += 7) {
15440
- const [radiusX, , , largeArcFlag, sweepFlag, endX, endY] = values.slice(
15441
- offset,
15442
- offset + 7
15443
- );
15444
- const generatedArcRoute = generateArcFromSweep(
15445
- currentPoint.x,
15446
- currentPoint.y,
15447
- endX,
15448
- endY,
15449
- radiusX,
15450
- largeArcFlag === 1,
15451
- sweepFlag === 1
15452
- );
15453
- const maxArcSegments = 16;
15454
- const arcRoute = generatedArcRoute.length <= maxArcSegments + 1 ? generatedArcRoute : Array.from(
15455
- { length: maxArcSegments + 1 },
15456
- (_, pointIndex) => generatedArcRoute.at(
15457
- Math.round(
15458
- pointIndex * (generatedArcRoute.length - 1) / maxArcSegments
15459
- )
15460
- )
15461
- ).filter((point4) => !!point4);
15462
- rawRoute.push(...arcRoute.slice(1));
15463
- currentPoint = { x: endX, y: endY };
15464
- }
15455
+ // lib/utils/parse-easyeda-path-commands.ts
15456
+ var argumentCounts = {
15457
+ M: 2,
15458
+ L: 2,
15459
+ H: 1,
15460
+ V: 1,
15461
+ C: 6,
15462
+ S: 4,
15463
+ Q: 4,
15464
+ T: 2,
15465
+ A: 7,
15466
+ Z: 0
15467
+ };
15468
+ var parseEasyEdaPathCommands = (pathData) => {
15469
+ const commands = [];
15470
+ let currentCommand;
15471
+ let lastTokenEnd = 0;
15472
+ for (const token of pathData.matchAll(
15473
+ /([a-df-z])|([-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?)/gi
15474
+ )) {
15475
+ if (!/^[\s,]*$/.test(pathData.slice(lastTokenEnd, token.index))) return null;
15476
+ lastTokenEnd = token.index + token[0].length;
15477
+ if (token[1]) {
15478
+ if (!Object.hasOwn(argumentCounts, token[1].toUpperCase())) return null;
15479
+ currentCommand = { command: token[1], arguments: [] };
15480
+ commands.push(currentCommand);
15481
+ } else {
15482
+ const commandArgument = Number(token[2]);
15483
+ if (!currentCommand || !Number.isFinite(commandArgument)) return null;
15484
+ currentCommand.arguments.push(commandArgument);
15465
15485
  }
15466
15486
  }
15467
- return rawRoute;
15487
+ if (!/^[\s,]*$/.test(pathData.slice(lastTokenEnd))) return null;
15488
+ if (commands[0]?.command.toUpperCase() !== "M") return null;
15489
+ for (const pathCommand of commands) {
15490
+ const argumentCount = argumentCounts[pathCommand.command.toUpperCase()];
15491
+ const count = pathCommand.arguments.length;
15492
+ if (argumentCount === 0 ? count !== 0 : count === 0 || count % argumentCount !== 0) {
15493
+ return null;
15494
+ }
15495
+ }
15496
+ return commands;
15497
+ };
15498
+
15499
+ // lib/utils/get-easyeda-npth-pill-hole.ts
15500
+ var PATH_GEOMETRY_TOLERANCE = 1e-9;
15501
+ var isClose = (a, b) => Math.abs(a - b) < PATH_GEOMETRY_TOLERANCE;
15502
+ var getEasyEdaNpthPillHole = (pathData) => {
15503
+ const commands = parseEasyEdaPathCommands(pathData);
15504
+ if (!commands || commands.map((command) => command.command).join("") !== "MLALAZ") {
15505
+ return null;
15506
+ }
15507
+ const coordinates = commands.slice(0, -1).map((command) => command.arguments);
15508
+ if (coordinates.map((command) => command.length).join(",") !== "2,2,7,2,7") {
15509
+ return null;
15510
+ }
15511
+ const [start, firstLineEnd, firstArc, secondLineEnd, secondArc] = coordinates;
15512
+ const firstArcEnd = firstArc.slice(5);
15513
+ const secondArcEnd = secondArc.slice(5);
15514
+ const radius = firstArc[0];
15515
+ 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])) {
15516
+ return null;
15517
+ }
15518
+ 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);
15519
+ 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);
15520
+ if (!horizontal && !vertical) return null;
15521
+ const straightLength = horizontal ? Math.abs(start[0] - firstLineEnd[0]) : Math.abs(start[1] - firstLineEnd[1]);
15522
+ if (straightLength < PATH_GEOMETRY_TOLERANCE) return null;
15523
+ const crossProduct = (firstLineEnd[0] - firstArcEnd[0]) * (firstLineEnd[1] - start[1]) - (firstLineEnd[1] - firstArcEnd[1]) * (firstLineEnd[0] - start[0]);
15524
+ if (firstArc[4] !== Number(crossProduct > 0)) return null;
15525
+ return {
15526
+ hole_shape: "pill",
15527
+ x: mil2mm((start[0] + firstArcEnd[0]) / 2) * 10,
15528
+ y: mil2mm((start[1] + firstArcEnd[1]) / 2) * 10,
15529
+ hole_width: mil2mm(horizontal ? straightLength + radius * 2 : radius * 2) * 10,
15530
+ hole_height: mil2mm(vertical ? straightLength + radius * 2 : radius * 2) * 10
15531
+ };
15532
+ };
15533
+
15534
+ // lib/utils/convert-easyeda-npth-cutouts-to-holes.ts
15535
+ var convertEasyEdaNpthCutoutsToHoles = (circuitJson, npthRegions) => {
15536
+ const npthPillHoles = npthRegions.map((region, index) => ({
15537
+ pcb_cutout_id: `pcb_cutout_npth_${index + 1}`,
15538
+ hole: getEasyEdaNpthPillHole(region.pathData)
15539
+ }));
15540
+ return circuitJson.map((element) => {
15541
+ if (element.type !== "pcb_cutout" || element.shape !== "polygon") {
15542
+ return element;
15543
+ }
15544
+ const npthPillHole = npthPillHoles.find(
15545
+ (candidate) => candidate.pcb_cutout_id === element.pcb_cutout_id
15546
+ );
15547
+ if (!npthPillHole?.hole) return element;
15548
+ const xs = element.points.map((point4) => point4.x);
15549
+ const ys = element.points.map((point4) => point4.y);
15550
+ return pcb_hole.parse({
15551
+ type: "pcb_hole",
15552
+ pcb_hole_id: element.pcb_cutout_id.replace("pcb_cutout_", "pcb_hole_"),
15553
+ pcb_component_id: element.pcb_component_id,
15554
+ ...npthPillHole.hole,
15555
+ x: (Math.min(...xs) + Math.max(...xs)) / 2,
15556
+ y: (Math.min(...ys) + Math.max(...ys)) / 2
15557
+ });
15558
+ });
15559
+ };
15560
+
15561
+ // lib/utils/append-easyeda-path-point.ts
15562
+ var appendEasyEdaPathPoint = (route, point4) => {
15563
+ if (!Number.isFinite(point4.x) || !Number.isFinite(point4.y)) {
15564
+ throw new Error(INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE);
15565
+ }
15566
+ const firstPoint = route[0] ?? point4;
15567
+ const needsClosingPoint = firstPoint.x !== point4.x || firstPoint.y !== point4.y;
15568
+ if (route.length + 1 + Number(needsClosingPoint) > MAX_EASYEDA_PATH_POINTS) {
15569
+ throw new Error(EASYEDA_PATH_LIMIT_MESSAGE);
15570
+ }
15571
+ route.push(point4);
15468
15572
  };
15469
15573
 
15470
15574
  // node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
@@ -15473,6 +15577,17 @@ function orientation(p, q, r) {
15473
15577
  if (val === 0) return 0;
15474
15578
  return val > 0 ? 1 : 2;
15475
15579
  }
15580
+ function pointToSegmentDistance(p, v, w) {
15581
+ const l2 = (w.x - v.x) ** 2 + (w.y - v.y) ** 2;
15582
+ if (l2 === 0) return distance2(p, v);
15583
+ let t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
15584
+ t = Math.max(0, Math.min(1, t));
15585
+ const projection = {
15586
+ x: v.x + t * (w.x - v.x),
15587
+ y: v.y + t * (w.y - v.y)
15588
+ };
15589
+ return distance2(p, projection);
15590
+ }
15476
15591
  function distance2(p1, p2) {
15477
15592
  const dx = p1.x - p2.x;
15478
15593
  const dy = p1.y - p2.y;
@@ -15493,6 +15608,14 @@ var getUnitVectorFromDirection = (direction) => {
15493
15608
  }
15494
15609
  };
15495
15610
 
15611
+ // node_modules/@tscircuit/math-utils/dist/chunk-5J3PCV4D.js
15612
+ function midpoint(p1, p2) {
15613
+ return {
15614
+ x: (p1.x + p2.x) / 2,
15615
+ y: (p1.y + p2.y) / 2
15616
+ };
15617
+ }
15618
+
15496
15619
  // node_modules/@tscircuit/math-utils/dist/chunk-3WCUPG5S.js
15497
15620
  var getBoundsCenter = (bounds) => ({
15498
15621
  x: (bounds.minX + bounds.maxX) / 2,
@@ -15518,6 +15641,194 @@ var getBoundsFromPoints2 = (points) => {
15518
15641
  return { minX, minY, maxX, maxY };
15519
15642
  };
15520
15643
 
15644
+ // lib/utils/flatten-bezier-curve.ts
15645
+ var MAX_SUBDIVISION_DEPTH = 20;
15646
+ var BEZIER_SUBDIVISION_LIMIT_MESSAGE = "Bezier curve exceeds the subdivision limit";
15647
+ var INVALID_BEZIER_GEOMETRY_MESSAGE = "Invalid Bezier curve geometry";
15648
+ var flattenBezierCurve = ({
15649
+ controlPoints,
15650
+ tolerance,
15651
+ maxPoints = MAX_EASYEDA_PATH_POINTS
15652
+ }) => {
15653
+ if (![3, 4].includes(controlPoints.length) || !Number.isFinite(tolerance) || tolerance <= 0 || controlPoints.some(
15654
+ (point4) => !Number.isFinite(point4.x) || !Number.isFinite(point4.y)
15655
+ )) {
15656
+ throw new Error(INVALID_BEZIER_GEOMETRY_MESSAGE);
15657
+ }
15658
+ if (!Number.isInteger(maxPoints) || maxPoints < 2) {
15659
+ throw new Error(EASYEDA_PATH_LIMIT_MESSAGE);
15660
+ }
15661
+ const pointLimit = Math.min(maxPoints, MAX_EASYEDA_PATH_POINTS);
15662
+ const route = [controlPoints[0]];
15663
+ const pending = [{ points: controlPoints, depth: 0 }];
15664
+ while (pending.length) {
15665
+ const { points, depth } = pending.pop();
15666
+ const start = points[0];
15667
+ const end = points.at(-1);
15668
+ if (points.slice(1, -1).every(
15669
+ (point4) => pointToSegmentDistance(point4, start, end) <= tolerance
15670
+ )) {
15671
+ route.push(end);
15672
+ continue;
15673
+ }
15674
+ if (depth >= MAX_SUBDIVISION_DEPTH) {
15675
+ throw new Error(BEZIER_SUBDIVISION_LIMIT_MESSAGE);
15676
+ }
15677
+ if (route.length + pending.length + 2 > pointLimit) {
15678
+ throw new Error(EASYEDA_PATH_LIMIT_MESSAGE);
15679
+ }
15680
+ let level = points;
15681
+ const left = [start];
15682
+ const right = [end];
15683
+ while (level.length > 1) {
15684
+ level = level.slice(1).map((point4, index) => midpoint(level[index], point4));
15685
+ left.push(level[0]);
15686
+ right.unshift(level.at(-1));
15687
+ }
15688
+ pending.push(
15689
+ { points: right, depth: depth + 1 },
15690
+ { points: left, depth: depth + 1 }
15691
+ );
15692
+ }
15693
+ return route;
15694
+ };
15695
+
15696
+ // lib/utils/expand-easyeda-bezier-command.ts
15697
+ var BEZIER_TOLERANCE = 1e-3 / mil10ToMm(1);
15698
+ var expandEasyEdaBezierCommand = (pathCommand, ctx) => {
15699
+ const command = pathCommand.command.toUpperCase();
15700
+ const relative = command !== pathCommand.command;
15701
+ const groupSize = command === "C" ? 6 : command === "T" ? 2 : 4;
15702
+ const route = [];
15703
+ let { currentPoint, cubicControl, quadraticControl } = ctx;
15704
+ for (let offset = 0; offset < pathCommand.arguments.length; offset += groupSize) {
15705
+ if (route.length >= ctx.remainingPoints) {
15706
+ throw new Error(EASYEDA_PATH_LIMIT_MESSAGE);
15707
+ }
15708
+ const coordinates = [];
15709
+ for (let index = offset; index < offset + groupSize; index += 2) {
15710
+ coordinates.push({
15711
+ x: pathCommand.arguments[index] + (relative ? currentPoint.x : 0),
15712
+ y: pathCommand.arguments[index + 1] + (relative ? currentPoint.y : 0)
15713
+ });
15714
+ }
15715
+ const end = coordinates.at(-1);
15716
+ let controlPoints;
15717
+ if (command === "C" || command === "S") {
15718
+ const firstControl = command === "C" ? coordinates[0] : cubicControl ? {
15719
+ x: 2 * currentPoint.x - cubicControl.x,
15720
+ y: 2 * currentPoint.y - cubicControl.y
15721
+ } : currentPoint;
15722
+ cubicControl = coordinates.at(-2);
15723
+ quadraticControl = void 0;
15724
+ controlPoints = [currentPoint, firstControl, cubicControl, end];
15725
+ } else {
15726
+ quadraticControl = command === "Q" ? coordinates[0] : quadraticControl ? {
15727
+ x: 2 * currentPoint.x - quadraticControl.x,
15728
+ y: 2 * currentPoint.y - quadraticControl.y
15729
+ } : currentPoint;
15730
+ cubicControl = void 0;
15731
+ controlPoints = [currentPoint, quadraticControl, end];
15732
+ }
15733
+ const points = flattenBezierCurve({
15734
+ controlPoints,
15735
+ tolerance: BEZIER_TOLERANCE,
15736
+ maxPoints: ctx.remainingPoints - route.length + 1
15737
+ });
15738
+ for (let index = 1; index < points.length; index++) {
15739
+ route.push(points[index]);
15740
+ }
15741
+ currentPoint = end;
15742
+ }
15743
+ return { route, currentPoint, cubicControl, quadraticControl };
15744
+ };
15745
+
15746
+ // lib/utils/expand-easyeda-path-data.ts
15747
+ var expandEasyEdaPathData = (pathData) => {
15748
+ const commands = parseEasyEdaPathCommands(pathData);
15749
+ if (!commands) throw new Error("Invalid EasyEDA SOLIDREGION path");
15750
+ for (const { command } of commands) {
15751
+ if (!/^[MLHVAZCSQT]$/i.test(command)) {
15752
+ throw new Error(
15753
+ `Unsupported EasyEDA SOLIDREGION path command: ${command}`
15754
+ );
15755
+ }
15756
+ }
15757
+ if (commands.slice(1).some(({ command }) => command.toUpperCase() === "M")) {
15758
+ throw new Error("Multiple EasyEDA SOLIDREGION subpaths are not supported");
15759
+ }
15760
+ const rawRoute = [];
15761
+ let currentPoint;
15762
+ let subpathStart;
15763
+ let afterClose = false;
15764
+ let cubicControl;
15765
+ let quadraticControl;
15766
+ for (const pathCommand of commands) {
15767
+ const command = pathCommand.command.toUpperCase();
15768
+ const relative = pathCommand.command !== command;
15769
+ const commandArguments = pathCommand.arguments;
15770
+ if (command !== "C" && command !== "S") cubicControl = void 0;
15771
+ if (command !== "Q" && command !== "T") quadraticControl = void 0;
15772
+ if (afterClose && command !== "Z" && currentPoint) {
15773
+ const lastPoint = rawRoute.at(-1);
15774
+ if (lastPoint?.x !== currentPoint.x || lastPoint?.y !== currentPoint.y) {
15775
+ appendEasyEdaPathPoint(rawRoute, currentPoint);
15776
+ }
15777
+ }
15778
+ afterClose = command === "Z";
15779
+ if ((command === "M" || command === "L") && commandArguments.length >= 2) {
15780
+ for (let offset = 0; offset + 1 < commandArguments.length; offset += 2) {
15781
+ currentPoint = {
15782
+ x: commandArguments[offset] + (relative ? currentPoint?.x ?? 0 : 0),
15783
+ y: commandArguments[offset + 1] + (relative ? currentPoint?.y ?? 0 : 0)
15784
+ };
15785
+ appendEasyEdaPathPoint(rawRoute, currentPoint);
15786
+ if (command === "M" && offset === 0) subpathStart = currentPoint;
15787
+ }
15788
+ } else if ((command === "H" || command === "V") && currentPoint) {
15789
+ for (const coordinate of commandArguments) {
15790
+ currentPoint = {
15791
+ x: command === "H" ? coordinate + (relative ? currentPoint.x : 0) : currentPoint.x,
15792
+ y: command === "V" ? coordinate + (relative ? currentPoint.y : 0) : currentPoint.y
15793
+ };
15794
+ appendEasyEdaPathPoint(rawRoute, currentPoint);
15795
+ }
15796
+ } else if (/^[CSQT]$/.test(command) && currentPoint) {
15797
+ const curve = expandEasyEdaBezierCommand(pathCommand, {
15798
+ currentPoint,
15799
+ cubicControl,
15800
+ quadraticControl,
15801
+ remainingPoints: MAX_EASYEDA_PATH_POINTS - rawRoute.length
15802
+ });
15803
+ for (const point4 of curve.route) appendEasyEdaPathPoint(rawRoute, point4);
15804
+ currentPoint = curve.currentPoint;
15805
+ cubicControl = curve.cubicControl;
15806
+ quadraticControl = curve.quadraticControl;
15807
+ } else if (command === "A" && currentPoint && commandArguments.length >= 7) {
15808
+ for (let offset = 0; offset + 6 < commandArguments.length; offset += 7) {
15809
+ const [radiusX, , , largeArcFlag, sweepFlag, endpointX, endpointY] = commandArguments.slice(offset, offset + 7);
15810
+ const endX = endpointX + (relative ? currentPoint.x : 0);
15811
+ const endY = endpointY + (relative ? currentPoint.y : 0);
15812
+ const arcRoute = generateArcFromSweep({
15813
+ start: currentPoint,
15814
+ end: { x: endX, y: endY },
15815
+ radius: radiusX,
15816
+ largeArcFlag: largeArcFlag === 1,
15817
+ sweepFlag: sweepFlag === 1,
15818
+ maxSegments: 16
15819
+ });
15820
+ for (let index = 1; index < arcRoute.length; index++) {
15821
+ appendEasyEdaPathPoint(rawRoute, arcRoute[index]);
15822
+ }
15823
+ currentPoint = { x: endX, y: endY };
15824
+ }
15825
+ } else if (command === "Z" && subpathStart) {
15826
+ currentPoint = subpathStart;
15827
+ }
15828
+ }
15829
+ return rawRoute;
15830
+ };
15831
+
15521
15832
  // lib/utils/get-board-outline-polygons.ts
15522
15833
  var same = (a, b) => distance2(a, b) < 1e-4;
15523
15834
  var getBoardOutlinePolygons = (tracks) => {
@@ -15835,20 +16146,20 @@ var distanceFromRouteMidpoint = (route, point4) => {
15835
16146
  return Math.hypot(midpoint2.x - point4.x, midpoint2.y - point4.y);
15836
16147
  };
15837
16148
  var getSilkscreenArcPath = (arc2, footprintCenter, silkscreenTracks) => {
15838
- const generateArcPath = (sweepFlag2) => generateArcFromSweep(
15839
- arc2.start.x,
15840
- arc2.start.y,
15841
- arc2.end.x,
15842
- arc2.end.y,
15843
- arc2.radiusX,
15844
- arc2.largeArc,
15845
- sweepFlag2
15846
- );
16149
+ const arcOptions = {
16150
+ start: arc2.start,
16151
+ end: arc2.end,
16152
+ radius: arc2.radiusX,
16153
+ largeArcFlag: arc2.largeArc
16154
+ };
15847
16155
  const sweepFlag = arc2.sweepDirection === "CW";
15848
- const arcPath = generateArcPath(sweepFlag);
16156
+ const arcPath = generateArcFromSweep({ ...arcOptions, sweepFlag });
15849
16157
  const semicircleRole = classifySemicircle(arc2, silkscreenTracks);
15850
16158
  if (!semicircleRole) return arcPath;
15851
- const oppositeArcPath = generateArcPath(!sweepFlag);
16159
+ const oppositeArcPath = generateArcFromSweep({
16160
+ ...arcOptions,
16161
+ sweepFlag: !sweepFlag
16162
+ });
15852
16163
  const arcDistance = distanceFromRouteMidpoint(arcPath, footprintCenter);
15853
16164
  const oppositeDistance = distanceFromRouteMidpoint(
15854
16165
  oppositeArcPath,
@@ -16186,7 +16497,31 @@ var handleFabricationNotePath = (track, index) => pcb_fabrication_note_path.pars
16186
16497
  stroke_width: mil10ToMm(track.width)
16187
16498
  });
16188
16499
  var handleFabricationNoteSolidRegion = (solidRegion, index) => {
16189
- const rawRoute = expandEasyEdaPathData(solidRegion.pathData);
16500
+ const commands = parseEasyEdaPathCommands(solidRegion.pathData);
16501
+ const pathWarning = !commands ? "Invalid EasyEDA SOLIDREGION path" : commands.slice(1).some(({ command }) => command.toUpperCase() === "M") ? "Multiple EasyEDA SOLIDREGION subpaths are not supported" : void 0;
16502
+ if (pathWarning) {
16503
+ console.warn(
16504
+ `Skipping EasyEDA fabrication note ${solidRegion.id ?? index + 1}: ${pathWarning}`
16505
+ );
16506
+ return null;
16507
+ }
16508
+ let rawRoute;
16509
+ try {
16510
+ rawRoute = expandEasyEdaPathData(solidRegion.pathData);
16511
+ } catch (error) {
16512
+ if (!(error instanceof Error) || ![
16513
+ BEZIER_SUBDIVISION_LIMIT_MESSAGE,
16514
+ EASYEDA_PATH_LIMIT_MESSAGE,
16515
+ INVALID_BEZIER_GEOMETRY_MESSAGE,
16516
+ INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE
16517
+ ].includes(error.message)) {
16518
+ throw error;
16519
+ }
16520
+ console.warn(
16521
+ `Skipping EasyEDA fabrication note ${solidRegion.id ?? index + 1}: ${error.message}`
16522
+ );
16523
+ return null;
16524
+ }
16190
16525
  const route = rawRoute.map((point4) => ({
16191
16526
  x: mil10ToMm(point4.x),
16192
16527
  y: mil10ToMm(point4.y)
@@ -16508,9 +16843,10 @@ var convertEasyEdaJsonToCircuitJsonWithPinAttributes = (easyEdaJson, {
16508
16843
  ).forEach((sr, index) => {
16509
16844
  circuitElements.push(handleCutout(sr, index));
16510
16845
  });
16511
- easyEdaJson.packageDetail.dataStr.shape.filter(
16846
+ const npthRegions = easyEdaJson.packageDetail.dataStr.shape.filter(
16512
16847
  (shape) => shape.type === "SOLIDREGION" && isPcbSolidRegionNpth(shape)
16513
- ).forEach((sr, index) => {
16848
+ );
16849
+ npthRegions.forEach((sr, index) => {
16514
16850
  const geometry = getEasyEdaNpthSlotGeometry(sr);
16515
16851
  if (!geometry) return;
16516
16852
  circuitElements.push(
@@ -16805,7 +17141,10 @@ var convertEasyEdaJsonToCircuitJsonWithPinAttributes = (easyEdaJson, {
16805
17141
  }
16806
17142
  pcb_component2.center = { x: 0, y: 0 };
16807
17143
  }
16808
- return { circuitJson: circuitElements, resolvedPinAttributes };
17144
+ return {
17145
+ circuitJson: convertEasyEdaNpthCutoutsToHoles(circuitElements, npthRegions),
17146
+ resolvedPinAttributes
17147
+ };
16809
17148
  };
16810
17149
  var convertEasyEdaJsonToCircuitJson = (easyEdaJson, options = {}) => convertEasyEdaJsonToCircuitJsonWithPinAttributes(easyEdaJson, options).circuitJson;
16811
17150