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/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.384",
1081
+ version: "0.0.386",
1082
1082
  files: [
1083
1083
  "dist"
1084
1084
  ],
@@ -16517,10 +16517,25 @@ var mil2mm = (mil) => {
16517
16517
  // lib/constants.ts
16518
16518
  var DEFAULT_PCB_THICKNESS_MM = 1.6;
16519
16519
 
16520
+ // lib/utils/easyeda-path-limits.ts
16521
+ var MAX_EASYEDA_PATH_POINTS = 8192;
16522
+ var EASYEDA_PATH_LIMIT_MESSAGE = "EasyEDA SOLIDREGION path exceeds the vertex limit";
16523
+ var INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE = "Invalid EasyEDA SOLIDREGION path geometry";
16524
+
16520
16525
  // lib/math/arc-utils.ts
16521
- function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag, sweepFlag) {
16522
- const start = { x: startX, y: startY };
16523
- const end = { x: endX, y: endY };
16526
+ function generateArcFromSweep({
16527
+ start,
16528
+ end,
16529
+ radius,
16530
+ largeArcFlag,
16531
+ sweepFlag,
16532
+ maxSegments = MAX_EASYEDA_PATH_POINTS - 1
16533
+ }) {
16534
+ const { x: startX, y: startY } = start;
16535
+ const { x: endX, y: endY } = end;
16536
+ if (![startX, startY, endX, endY, radius].every(Number.isFinite) || !Number.isInteger(maxSegments) || maxSegments < 1) {
16537
+ throw new Error(INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE);
16538
+ }
16524
16539
  const midX = (startX + endX) / 2;
16525
16540
  const midY = (startY + endY) / 2;
16526
16541
  const dx = endX - startX;
@@ -16546,12 +16561,26 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
16546
16561
  const minNumPoints = Math.max(2, Math.ceil(arcAngle * radius));
16547
16562
  const isSemicircle = Math.abs(arcAngle - Math.PI) < 1e-6;
16548
16563
  const numPoints = isSemicircle ? minNumPoints + minNumPoints % 2 : minNumPoints;
16564
+ if (![centerX, centerY, startAngle, endAngle, numPoints].every(Number.isFinite)) {
16565
+ throw new Error(INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE);
16566
+ }
16567
+ const sampledSegments = Math.min(
16568
+ numPoints,
16569
+ maxSegments,
16570
+ MAX_EASYEDA_PATH_POINTS - 1
16571
+ );
16549
16572
  const path = [];
16550
- for (let i = 0; i <= numPoints; i++) {
16551
- const t = i / numPoints;
16573
+ for (let i = 0; i <= sampledSegments; i++) {
16574
+ const pointIndex = sampledSegments === numPoints ? i : Math.round(
16575
+ numPoints <= Number.MAX_SAFE_INTEGER / sampledSegments ? i * numPoints / sampledSegments : i / sampledSegments * numPoints
16576
+ );
16577
+ const t = pointIndex / numPoints;
16552
16578
  const angle2 = startAngle + t * (endAngle - startAngle);
16553
16579
  const x = centerX + radius * Math.cos(angle2);
16554
16580
  const y = centerY + radius * Math.sin(angle2);
16581
+ if (!Number.isFinite(x) || !Number.isFinite(y)) {
16582
+ throw new Error(INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE);
16583
+ }
16555
16584
  path.push({ x, y });
16556
16585
  }
16557
16586
  return path;
@@ -16560,48 +16589,123 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
16560
16589
  // lib/utils/easyeda-unit-to-mm.ts
16561
16590
  var mil10ToMm = (value) => value * 10 * 0.0254;
16562
16591
 
16563
- // lib/utils/expand-easyeda-path-data.ts
16564
- var expandEasyEdaPathData = (pathData) => {
16565
- const rawRoute = [];
16566
- let currentPoint;
16567
- for (const commandMatch of pathData.matchAll(/([MLAZ])([^MLAZ]*)/gi)) {
16568
- const command = commandMatch[1]?.toUpperCase();
16569
- const values = commandMatch[2]?.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
16570
- if ((command === "M" || command === "L") && values.length >= 2) {
16571
- for (let offset = 0; offset + 1 < values.length; offset += 2) {
16572
- currentPoint = { x: values[offset], y: values[offset + 1] };
16573
- rawRoute.push(currentPoint);
16574
- }
16575
- } else if (command === "A" && currentPoint && values.length >= 7) {
16576
- for (let offset = 0; offset + 6 < values.length; offset += 7) {
16577
- const [radiusX, , , largeArcFlag, sweepFlag, endX, endY] = values.slice(
16578
- offset,
16579
- offset + 7
16580
- );
16581
- const generatedArcRoute = generateArcFromSweep(
16582
- currentPoint.x,
16583
- currentPoint.y,
16584
- endX,
16585
- endY,
16586
- radiusX,
16587
- largeArcFlag === 1,
16588
- sweepFlag === 1
16589
- );
16590
- const maxArcSegments = 16;
16591
- const arcRoute = generatedArcRoute.length <= maxArcSegments + 1 ? generatedArcRoute : Array.from(
16592
- { length: maxArcSegments + 1 },
16593
- (_, pointIndex) => generatedArcRoute.at(
16594
- Math.round(
16595
- pointIndex * (generatedArcRoute.length - 1) / maxArcSegments
16596
- )
16597
- )
16598
- ).filter((point4) => !!point4);
16599
- rawRoute.push(...arcRoute.slice(1));
16600
- currentPoint = { x: endX, y: endY };
16601
- }
16592
+ // lib/utils/parse-easyeda-path-commands.ts
16593
+ var argumentCounts = {
16594
+ M: 2,
16595
+ L: 2,
16596
+ H: 1,
16597
+ V: 1,
16598
+ C: 6,
16599
+ S: 4,
16600
+ Q: 4,
16601
+ T: 2,
16602
+ A: 7,
16603
+ Z: 0
16604
+ };
16605
+ var parseEasyEdaPathCommands = (pathData) => {
16606
+ const commands = [];
16607
+ let currentCommand;
16608
+ let lastTokenEnd = 0;
16609
+ for (const token of pathData.matchAll(
16610
+ /([a-df-z])|([-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?)/gi
16611
+ )) {
16612
+ if (!/^[\s,]*$/.test(pathData.slice(lastTokenEnd, token.index))) return null;
16613
+ lastTokenEnd = token.index + token[0].length;
16614
+ if (token[1]) {
16615
+ if (!Object.hasOwn(argumentCounts, token[1].toUpperCase())) return null;
16616
+ currentCommand = { command: token[1], arguments: [] };
16617
+ commands.push(currentCommand);
16618
+ } else {
16619
+ const commandArgument = Number(token[2]);
16620
+ if (!currentCommand || !Number.isFinite(commandArgument)) return null;
16621
+ currentCommand.arguments.push(commandArgument);
16602
16622
  }
16603
16623
  }
16604
- return rawRoute;
16624
+ if (!/^[\s,]*$/.test(pathData.slice(lastTokenEnd))) return null;
16625
+ if (commands[0]?.command.toUpperCase() !== "M") return null;
16626
+ for (const pathCommand of commands) {
16627
+ const argumentCount = argumentCounts[pathCommand.command.toUpperCase()];
16628
+ const count = pathCommand.arguments.length;
16629
+ if (argumentCount === 0 ? count !== 0 : count === 0 || count % argumentCount !== 0) {
16630
+ return null;
16631
+ }
16632
+ }
16633
+ return commands;
16634
+ };
16635
+
16636
+ // lib/utils/get-easyeda-npth-pill-hole.ts
16637
+ var PATH_GEOMETRY_TOLERANCE = 1e-9;
16638
+ var isClose = (a, b) => Math.abs(a - b) < PATH_GEOMETRY_TOLERANCE;
16639
+ var getEasyEdaNpthPillHole = (pathData) => {
16640
+ const commands = parseEasyEdaPathCommands(pathData);
16641
+ if (!commands || commands.map((command) => command.command).join("") !== "MLALAZ") {
16642
+ return null;
16643
+ }
16644
+ const coordinates = commands.slice(0, -1).map((command) => command.arguments);
16645
+ if (coordinates.map((command) => command.length).join(",") !== "2,2,7,2,7") {
16646
+ return null;
16647
+ }
16648
+ const [start, firstLineEnd, firstArc, secondLineEnd, secondArc] = coordinates;
16649
+ const firstArcEnd = firstArc.slice(5);
16650
+ const secondArcEnd = secondArc.slice(5);
16651
+ const radius = firstArc[0];
16652
+ 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])) {
16653
+ return null;
16654
+ }
16655
+ 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);
16656
+ 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);
16657
+ if (!horizontal && !vertical) return null;
16658
+ const straightLength = horizontal ? Math.abs(start[0] - firstLineEnd[0]) : Math.abs(start[1] - firstLineEnd[1]);
16659
+ if (straightLength < PATH_GEOMETRY_TOLERANCE) return null;
16660
+ const crossProduct = (firstLineEnd[0] - firstArcEnd[0]) * (firstLineEnd[1] - start[1]) - (firstLineEnd[1] - firstArcEnd[1]) * (firstLineEnd[0] - start[0]);
16661
+ if (firstArc[4] !== Number(crossProduct > 0)) return null;
16662
+ return {
16663
+ hole_shape: "pill",
16664
+ x: mil2mm((start[0] + firstArcEnd[0]) / 2) * 10,
16665
+ y: mil2mm((start[1] + firstArcEnd[1]) / 2) * 10,
16666
+ hole_width: mil2mm(horizontal ? straightLength + radius * 2 : radius * 2) * 10,
16667
+ hole_height: mil2mm(vertical ? straightLength + radius * 2 : radius * 2) * 10
16668
+ };
16669
+ };
16670
+
16671
+ // lib/utils/convert-easyeda-npth-cutouts-to-holes.ts
16672
+ var convertEasyEdaNpthCutoutsToHoles = (circuitJson, npthRegions) => {
16673
+ const npthPillHoles = npthRegions.map((region, index) => ({
16674
+ pcb_cutout_id: `pcb_cutout_npth_${index + 1}`,
16675
+ hole: getEasyEdaNpthPillHole(region.pathData)
16676
+ }));
16677
+ return circuitJson.map((element) => {
16678
+ if (element.type !== "pcb_cutout" || element.shape !== "polygon") {
16679
+ return element;
16680
+ }
16681
+ const npthPillHole = npthPillHoles.find(
16682
+ (candidate) => candidate.pcb_cutout_id === element.pcb_cutout_id
16683
+ );
16684
+ if (!npthPillHole?.hole) return element;
16685
+ const xs = element.points.map((point4) => point4.x);
16686
+ const ys = element.points.map((point4) => point4.y);
16687
+ return pcb_hole.parse({
16688
+ type: "pcb_hole",
16689
+ pcb_hole_id: element.pcb_cutout_id.replace("pcb_cutout_", "pcb_hole_"),
16690
+ pcb_component_id: element.pcb_component_id,
16691
+ ...npthPillHole.hole,
16692
+ x: (Math.min(...xs) + Math.max(...xs)) / 2,
16693
+ y: (Math.min(...ys) + Math.max(...ys)) / 2
16694
+ });
16695
+ });
16696
+ };
16697
+
16698
+ // lib/utils/append-easyeda-path-point.ts
16699
+ var appendEasyEdaPathPoint = (route, point4) => {
16700
+ if (!Number.isFinite(point4.x) || !Number.isFinite(point4.y)) {
16701
+ throw new Error(INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE);
16702
+ }
16703
+ const firstPoint = route[0] ?? point4;
16704
+ const needsClosingPoint = firstPoint.x !== point4.x || firstPoint.y !== point4.y;
16705
+ if (route.length + 1 + Number(needsClosingPoint) > MAX_EASYEDA_PATH_POINTS) {
16706
+ throw new Error(EASYEDA_PATH_LIMIT_MESSAGE);
16707
+ }
16708
+ route.push(point4);
16605
16709
  };
16606
16710
 
16607
16711
  // node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
@@ -16610,6 +16714,17 @@ function orientation(p, q, r) {
16610
16714
  if (val === 0) return 0;
16611
16715
  return val > 0 ? 1 : 2;
16612
16716
  }
16717
+ function pointToSegmentDistance(p, v, w) {
16718
+ const l2 = (w.x - v.x) ** 2 + (w.y - v.y) ** 2;
16719
+ if (l2 === 0) return distance2(p, v);
16720
+ let t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
16721
+ t = Math.max(0, Math.min(1, t));
16722
+ const projection = {
16723
+ x: v.x + t * (w.x - v.x),
16724
+ y: v.y + t * (w.y - v.y)
16725
+ };
16726
+ return distance2(p, projection);
16727
+ }
16613
16728
  function distance2(p1, p2) {
16614
16729
  const dx = p1.x - p2.x;
16615
16730
  const dy = p1.y - p2.y;
@@ -16630,6 +16745,14 @@ var getUnitVectorFromDirection = (direction) => {
16630
16745
  }
16631
16746
  };
16632
16747
 
16748
+ // node_modules/@tscircuit/math-utils/dist/chunk-5J3PCV4D.js
16749
+ function midpoint(p1, p2) {
16750
+ return {
16751
+ x: (p1.x + p2.x) / 2,
16752
+ y: (p1.y + p2.y) / 2
16753
+ };
16754
+ }
16755
+
16633
16756
  // node_modules/@tscircuit/math-utils/dist/chunk-3WCUPG5S.js
16634
16757
  var getBoundsCenter = (bounds) => ({
16635
16758
  x: (bounds.minX + bounds.maxX) / 2,
@@ -16655,6 +16778,194 @@ var getBoundsFromPoints2 = (points) => {
16655
16778
  return { minX, minY, maxX, maxY };
16656
16779
  };
16657
16780
 
16781
+ // lib/utils/flatten-bezier-curve.ts
16782
+ var MAX_SUBDIVISION_DEPTH = 20;
16783
+ var BEZIER_SUBDIVISION_LIMIT_MESSAGE = "Bezier curve exceeds the subdivision limit";
16784
+ var INVALID_BEZIER_GEOMETRY_MESSAGE = "Invalid Bezier curve geometry";
16785
+ var flattenBezierCurve = ({
16786
+ controlPoints,
16787
+ tolerance,
16788
+ maxPoints = MAX_EASYEDA_PATH_POINTS
16789
+ }) => {
16790
+ if (![3, 4].includes(controlPoints.length) || !Number.isFinite(tolerance) || tolerance <= 0 || controlPoints.some(
16791
+ (point4) => !Number.isFinite(point4.x) || !Number.isFinite(point4.y)
16792
+ )) {
16793
+ throw new Error(INVALID_BEZIER_GEOMETRY_MESSAGE);
16794
+ }
16795
+ if (!Number.isInteger(maxPoints) || maxPoints < 2) {
16796
+ throw new Error(EASYEDA_PATH_LIMIT_MESSAGE);
16797
+ }
16798
+ const pointLimit = Math.min(maxPoints, MAX_EASYEDA_PATH_POINTS);
16799
+ const route = [controlPoints[0]];
16800
+ const pending = [{ points: controlPoints, depth: 0 }];
16801
+ while (pending.length) {
16802
+ const { points, depth } = pending.pop();
16803
+ const start = points[0];
16804
+ const end = points.at(-1);
16805
+ if (points.slice(1, -1).every(
16806
+ (point4) => pointToSegmentDistance(point4, start, end) <= tolerance
16807
+ )) {
16808
+ route.push(end);
16809
+ continue;
16810
+ }
16811
+ if (depth >= MAX_SUBDIVISION_DEPTH) {
16812
+ throw new Error(BEZIER_SUBDIVISION_LIMIT_MESSAGE);
16813
+ }
16814
+ if (route.length + pending.length + 2 > pointLimit) {
16815
+ throw new Error(EASYEDA_PATH_LIMIT_MESSAGE);
16816
+ }
16817
+ let level = points;
16818
+ const left = [start];
16819
+ const right = [end];
16820
+ while (level.length > 1) {
16821
+ level = level.slice(1).map((point4, index) => midpoint(level[index], point4));
16822
+ left.push(level[0]);
16823
+ right.unshift(level.at(-1));
16824
+ }
16825
+ pending.push(
16826
+ { points: right, depth: depth + 1 },
16827
+ { points: left, depth: depth + 1 }
16828
+ );
16829
+ }
16830
+ return route;
16831
+ };
16832
+
16833
+ // lib/utils/expand-easyeda-bezier-command.ts
16834
+ var BEZIER_TOLERANCE = 1e-3 / mil10ToMm(1);
16835
+ var expandEasyEdaBezierCommand = (pathCommand, ctx) => {
16836
+ const command = pathCommand.command.toUpperCase();
16837
+ const relative = command !== pathCommand.command;
16838
+ const groupSize = command === "C" ? 6 : command === "T" ? 2 : 4;
16839
+ const route = [];
16840
+ let { currentPoint, cubicControl, quadraticControl } = ctx;
16841
+ for (let offset = 0; offset < pathCommand.arguments.length; offset += groupSize) {
16842
+ if (route.length >= ctx.remainingPoints) {
16843
+ throw new Error(EASYEDA_PATH_LIMIT_MESSAGE);
16844
+ }
16845
+ const coordinates = [];
16846
+ for (let index = offset; index < offset + groupSize; index += 2) {
16847
+ coordinates.push({
16848
+ x: pathCommand.arguments[index] + (relative ? currentPoint.x : 0),
16849
+ y: pathCommand.arguments[index + 1] + (relative ? currentPoint.y : 0)
16850
+ });
16851
+ }
16852
+ const end = coordinates.at(-1);
16853
+ let controlPoints;
16854
+ if (command === "C" || command === "S") {
16855
+ const firstControl = command === "C" ? coordinates[0] : cubicControl ? {
16856
+ x: 2 * currentPoint.x - cubicControl.x,
16857
+ y: 2 * currentPoint.y - cubicControl.y
16858
+ } : currentPoint;
16859
+ cubicControl = coordinates.at(-2);
16860
+ quadraticControl = void 0;
16861
+ controlPoints = [currentPoint, firstControl, cubicControl, end];
16862
+ } else {
16863
+ quadraticControl = command === "Q" ? coordinates[0] : quadraticControl ? {
16864
+ x: 2 * currentPoint.x - quadraticControl.x,
16865
+ y: 2 * currentPoint.y - quadraticControl.y
16866
+ } : currentPoint;
16867
+ cubicControl = void 0;
16868
+ controlPoints = [currentPoint, quadraticControl, end];
16869
+ }
16870
+ const points = flattenBezierCurve({
16871
+ controlPoints,
16872
+ tolerance: BEZIER_TOLERANCE,
16873
+ maxPoints: ctx.remainingPoints - route.length + 1
16874
+ });
16875
+ for (let index = 1; index < points.length; index++) {
16876
+ route.push(points[index]);
16877
+ }
16878
+ currentPoint = end;
16879
+ }
16880
+ return { route, currentPoint, cubicControl, quadraticControl };
16881
+ };
16882
+
16883
+ // lib/utils/expand-easyeda-path-data.ts
16884
+ var expandEasyEdaPathData = (pathData) => {
16885
+ const commands = parseEasyEdaPathCommands(pathData);
16886
+ if (!commands) throw new Error("Invalid EasyEDA SOLIDREGION path");
16887
+ for (const { command } of commands) {
16888
+ if (!/^[MLHVAZCSQT]$/i.test(command)) {
16889
+ throw new Error(
16890
+ `Unsupported EasyEDA SOLIDREGION path command: ${command}`
16891
+ );
16892
+ }
16893
+ }
16894
+ if (commands.slice(1).some(({ command }) => command.toUpperCase() === "M")) {
16895
+ throw new Error("Multiple EasyEDA SOLIDREGION subpaths are not supported");
16896
+ }
16897
+ const rawRoute = [];
16898
+ let currentPoint;
16899
+ let subpathStart;
16900
+ let afterClose = false;
16901
+ let cubicControl;
16902
+ let quadraticControl;
16903
+ for (const pathCommand of commands) {
16904
+ const command = pathCommand.command.toUpperCase();
16905
+ const relative = pathCommand.command !== command;
16906
+ const commandArguments = pathCommand.arguments;
16907
+ if (command !== "C" && command !== "S") cubicControl = void 0;
16908
+ if (command !== "Q" && command !== "T") quadraticControl = void 0;
16909
+ if (afterClose && command !== "Z" && currentPoint) {
16910
+ const lastPoint = rawRoute.at(-1);
16911
+ if (lastPoint?.x !== currentPoint.x || lastPoint?.y !== currentPoint.y) {
16912
+ appendEasyEdaPathPoint(rawRoute, currentPoint);
16913
+ }
16914
+ }
16915
+ afterClose = command === "Z";
16916
+ if ((command === "M" || command === "L") && commandArguments.length >= 2) {
16917
+ for (let offset = 0; offset + 1 < commandArguments.length; offset += 2) {
16918
+ currentPoint = {
16919
+ x: commandArguments[offset] + (relative ? currentPoint?.x ?? 0 : 0),
16920
+ y: commandArguments[offset + 1] + (relative ? currentPoint?.y ?? 0 : 0)
16921
+ };
16922
+ appendEasyEdaPathPoint(rawRoute, currentPoint);
16923
+ if (command === "M" && offset === 0) subpathStart = currentPoint;
16924
+ }
16925
+ } else if ((command === "H" || command === "V") && currentPoint) {
16926
+ for (const coordinate of commandArguments) {
16927
+ currentPoint = {
16928
+ x: command === "H" ? coordinate + (relative ? currentPoint.x : 0) : currentPoint.x,
16929
+ y: command === "V" ? coordinate + (relative ? currentPoint.y : 0) : currentPoint.y
16930
+ };
16931
+ appendEasyEdaPathPoint(rawRoute, currentPoint);
16932
+ }
16933
+ } else if (/^[CSQT]$/.test(command) && currentPoint) {
16934
+ const curve = expandEasyEdaBezierCommand(pathCommand, {
16935
+ currentPoint,
16936
+ cubicControl,
16937
+ quadraticControl,
16938
+ remainingPoints: MAX_EASYEDA_PATH_POINTS - rawRoute.length
16939
+ });
16940
+ for (const point4 of curve.route) appendEasyEdaPathPoint(rawRoute, point4);
16941
+ currentPoint = curve.currentPoint;
16942
+ cubicControl = curve.cubicControl;
16943
+ quadraticControl = curve.quadraticControl;
16944
+ } else if (command === "A" && currentPoint && commandArguments.length >= 7) {
16945
+ for (let offset = 0; offset + 6 < commandArguments.length; offset += 7) {
16946
+ const [radiusX, , , largeArcFlag, sweepFlag, endpointX, endpointY] = commandArguments.slice(offset, offset + 7);
16947
+ const endX = endpointX + (relative ? currentPoint.x : 0);
16948
+ const endY = endpointY + (relative ? currentPoint.y : 0);
16949
+ const arcRoute = generateArcFromSweep({
16950
+ start: currentPoint,
16951
+ end: { x: endX, y: endY },
16952
+ radius: radiusX,
16953
+ largeArcFlag: largeArcFlag === 1,
16954
+ sweepFlag: sweepFlag === 1,
16955
+ maxSegments: 16
16956
+ });
16957
+ for (let index = 1; index < arcRoute.length; index++) {
16958
+ appendEasyEdaPathPoint(rawRoute, arcRoute[index]);
16959
+ }
16960
+ currentPoint = { x: endX, y: endY };
16961
+ }
16962
+ } else if (command === "Z" && subpathStart) {
16963
+ currentPoint = subpathStart;
16964
+ }
16965
+ }
16966
+ return rawRoute;
16967
+ };
16968
+
16658
16969
  // lib/utils/get-board-outline-polygons.ts
16659
16970
  var same = (a, b) => distance2(a, b) < 1e-4;
16660
16971
  var getBoardOutlinePolygons = (tracks) => {
@@ -16972,20 +17283,20 @@ var distanceFromRouteMidpoint = (route, point4) => {
16972
17283
  return Math.hypot(midpoint2.x - point4.x, midpoint2.y - point4.y);
16973
17284
  };
16974
17285
  var getSilkscreenArcPath = (arc2, footprintCenter, silkscreenTracks) => {
16975
- const generateArcPath = (sweepFlag2) => generateArcFromSweep(
16976
- arc2.start.x,
16977
- arc2.start.y,
16978
- arc2.end.x,
16979
- arc2.end.y,
16980
- arc2.radiusX,
16981
- arc2.largeArc,
16982
- sweepFlag2
16983
- );
17286
+ const arcOptions = {
17287
+ start: arc2.start,
17288
+ end: arc2.end,
17289
+ radius: arc2.radiusX,
17290
+ largeArcFlag: arc2.largeArc
17291
+ };
16984
17292
  const sweepFlag = arc2.sweepDirection === "CW";
16985
- const arcPath = generateArcPath(sweepFlag);
17293
+ const arcPath = generateArcFromSweep({ ...arcOptions, sweepFlag });
16986
17294
  const semicircleRole = classifySemicircle(arc2, silkscreenTracks);
16987
17295
  if (!semicircleRole) return arcPath;
16988
- const oppositeArcPath = generateArcPath(!sweepFlag);
17296
+ const oppositeArcPath = generateArcFromSweep({
17297
+ ...arcOptions,
17298
+ sweepFlag: !sweepFlag
17299
+ });
16989
17300
  const arcDistance = distanceFromRouteMidpoint(arcPath, footprintCenter);
16990
17301
  const oppositeDistance = distanceFromRouteMidpoint(
16991
17302
  oppositeArcPath,
@@ -17323,7 +17634,31 @@ var handleFabricationNotePath = (track, index) => pcb_fabrication_note_path.pars
17323
17634
  stroke_width: mil10ToMm(track.width)
17324
17635
  });
17325
17636
  var handleFabricationNoteSolidRegion = (solidRegion, index) => {
17326
- const rawRoute = expandEasyEdaPathData(solidRegion.pathData);
17637
+ const commands = parseEasyEdaPathCommands(solidRegion.pathData);
17638
+ const pathWarning = !commands ? "Invalid EasyEDA SOLIDREGION path" : commands.slice(1).some(({ command }) => command.toUpperCase() === "M") ? "Multiple EasyEDA SOLIDREGION subpaths are not supported" : void 0;
17639
+ if (pathWarning) {
17640
+ console.warn(
17641
+ `Skipping EasyEDA fabrication note ${solidRegion.id ?? index + 1}: ${pathWarning}`
17642
+ );
17643
+ return null;
17644
+ }
17645
+ let rawRoute;
17646
+ try {
17647
+ rawRoute = expandEasyEdaPathData(solidRegion.pathData);
17648
+ } catch (error) {
17649
+ if (!(error instanceof Error) || ![
17650
+ BEZIER_SUBDIVISION_LIMIT_MESSAGE,
17651
+ EASYEDA_PATH_LIMIT_MESSAGE,
17652
+ INVALID_BEZIER_GEOMETRY_MESSAGE,
17653
+ INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE
17654
+ ].includes(error.message)) {
17655
+ throw error;
17656
+ }
17657
+ console.warn(
17658
+ `Skipping EasyEDA fabrication note ${solidRegion.id ?? index + 1}: ${error.message}`
17659
+ );
17660
+ return null;
17661
+ }
17327
17662
  const route = rawRoute.map((point4) => ({
17328
17663
  x: mil10ToMm(point4.x),
17329
17664
  y: mil10ToMm(point4.y)
@@ -17645,9 +17980,10 @@ var convertEasyEdaJsonToCircuitJsonWithPinAttributes = (easyEdaJson, {
17645
17980
  ).forEach((sr, index) => {
17646
17981
  circuitElements.push(handleCutout(sr, index));
17647
17982
  });
17648
- easyEdaJson.packageDetail.dataStr.shape.filter(
17983
+ const npthRegions = easyEdaJson.packageDetail.dataStr.shape.filter(
17649
17984
  (shape) => shape.type === "SOLIDREGION" && isPcbSolidRegionNpth(shape)
17650
- ).forEach((sr, index) => {
17985
+ );
17986
+ npthRegions.forEach((sr, index) => {
17651
17987
  const geometry = getEasyEdaNpthSlotGeometry(sr);
17652
17988
  if (!geometry) return;
17653
17989
  circuitElements.push(
@@ -17942,7 +18278,10 @@ var convertEasyEdaJsonToCircuitJsonWithPinAttributes = (easyEdaJson, {
17942
18278
  }
17943
18279
  pcb_component2.center = { x: 0, y: 0 };
17944
18280
  }
17945
- return { circuitJson: circuitElements, resolvedPinAttributes };
18281
+ return {
18282
+ circuitJson: convertEasyEdaNpthCutoutsToHoles(circuitElements, npthRegions),
18283
+ resolvedPinAttributes
18284
+ };
17946
18285
  };
17947
18286
  var convertEasyEdaJsonToCircuitJson = (easyEdaJson, options = {}) => convertEasyEdaJsonToCircuitJsonWithPinAttributes(easyEdaJson, options).circuitJson;
17948
18287