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.
@@ -19177,10 +19177,25 @@ var mil2mm = (mil) => {
19177
19177
  // lib/constants.ts
19178
19178
  var DEFAULT_PCB_THICKNESS_MM = 1.6;
19179
19179
 
19180
+ // lib/utils/easyeda-path-limits.ts
19181
+ var MAX_EASYEDA_PATH_POINTS = 8192;
19182
+ var EASYEDA_PATH_LIMIT_MESSAGE = "EasyEDA SOLIDREGION path exceeds the vertex limit";
19183
+ var INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE = "Invalid EasyEDA SOLIDREGION path geometry";
19184
+
19180
19185
  // lib/math/arc-utils.ts
19181
- function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag, sweepFlag) {
19182
- const start = { x: startX, y: startY };
19183
- const end = { x: endX, y: endY };
19186
+ function generateArcFromSweep({
19187
+ start,
19188
+ end,
19189
+ radius,
19190
+ largeArcFlag,
19191
+ sweepFlag,
19192
+ maxSegments = MAX_EASYEDA_PATH_POINTS - 1
19193
+ }) {
19194
+ const { x: startX, y: startY } = start;
19195
+ const { x: endX, y: endY } = end;
19196
+ if (![startX, startY, endX, endY, radius].every(Number.isFinite) || !Number.isInteger(maxSegments) || maxSegments < 1) {
19197
+ throw new Error(INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE);
19198
+ }
19184
19199
  const midX = (startX + endX) / 2;
19185
19200
  const midY = (startY + endY) / 2;
19186
19201
  const dx = endX - startX;
@@ -19206,12 +19221,26 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
19206
19221
  const minNumPoints = Math.max(2, Math.ceil(arcAngle * radius));
19207
19222
  const isSemicircle = Math.abs(arcAngle - Math.PI) < 1e-6;
19208
19223
  const numPoints = isSemicircle ? minNumPoints + minNumPoints % 2 : minNumPoints;
19224
+ if (![centerX, centerY, startAngle, endAngle, numPoints].every(Number.isFinite)) {
19225
+ throw new Error(INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE);
19226
+ }
19227
+ const sampledSegments = Math.min(
19228
+ numPoints,
19229
+ maxSegments,
19230
+ MAX_EASYEDA_PATH_POINTS - 1
19231
+ );
19209
19232
  const path = [];
19210
- for (let i = 0; i <= numPoints; i++) {
19211
- const t = i / numPoints;
19233
+ for (let i = 0; i <= sampledSegments; i++) {
19234
+ const pointIndex = sampledSegments === numPoints ? i : Math.round(
19235
+ numPoints <= Number.MAX_SAFE_INTEGER / sampledSegments ? i * numPoints / sampledSegments : i / sampledSegments * numPoints
19236
+ );
19237
+ const t = pointIndex / numPoints;
19212
19238
  const angle2 = startAngle + t * (endAngle - startAngle);
19213
19239
  const x = centerX + radius * Math.cos(angle2);
19214
19240
  const y = centerY + radius * Math.sin(angle2);
19241
+ if (!Number.isFinite(x) || !Number.isFinite(y)) {
19242
+ throw new Error(INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE);
19243
+ }
19215
19244
  path.push({ x, y });
19216
19245
  }
19217
19246
  return path;
@@ -19220,48 +19249,123 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
19220
19249
  // lib/utils/easyeda-unit-to-mm.ts
19221
19250
  var mil10ToMm = (value) => value * 10 * 0.0254;
19222
19251
 
19223
- // lib/utils/expand-easyeda-path-data.ts
19224
- var expandEasyEdaPathData = (pathData) => {
19225
- const rawRoute = [];
19226
- let currentPoint;
19227
- for (const commandMatch of pathData.matchAll(/([MLAZ])([^MLAZ]*)/gi)) {
19228
- const command = commandMatch[1]?.toUpperCase();
19229
- const values = commandMatch[2]?.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
19230
- if ((command === "M" || command === "L") && values.length >= 2) {
19231
- for (let offset = 0; offset + 1 < values.length; offset += 2) {
19232
- currentPoint = { x: values[offset], y: values[offset + 1] };
19233
- rawRoute.push(currentPoint);
19234
- }
19235
- } else if (command === "A" && currentPoint && values.length >= 7) {
19236
- for (let offset = 0; offset + 6 < values.length; offset += 7) {
19237
- const [radiusX, , , largeArcFlag, sweepFlag, endX, endY] = values.slice(
19238
- offset,
19239
- offset + 7
19240
- );
19241
- const generatedArcRoute = generateArcFromSweep(
19242
- currentPoint.x,
19243
- currentPoint.y,
19244
- endX,
19245
- endY,
19246
- radiusX,
19247
- largeArcFlag === 1,
19248
- sweepFlag === 1
19249
- );
19250
- const maxArcSegments = 16;
19251
- const arcRoute = generatedArcRoute.length <= maxArcSegments + 1 ? generatedArcRoute : Array.from(
19252
- { length: maxArcSegments + 1 },
19253
- (_, pointIndex) => generatedArcRoute.at(
19254
- Math.round(
19255
- pointIndex * (generatedArcRoute.length - 1) / maxArcSegments
19256
- )
19257
- )
19258
- ).filter((point4) => !!point4);
19259
- rawRoute.push(...arcRoute.slice(1));
19260
- currentPoint = { x: endX, y: endY };
19261
- }
19252
+ // lib/utils/parse-easyeda-path-commands.ts
19253
+ var argumentCounts = {
19254
+ M: 2,
19255
+ L: 2,
19256
+ H: 1,
19257
+ V: 1,
19258
+ C: 6,
19259
+ S: 4,
19260
+ Q: 4,
19261
+ T: 2,
19262
+ A: 7,
19263
+ Z: 0
19264
+ };
19265
+ var parseEasyEdaPathCommands = (pathData) => {
19266
+ const commands = [];
19267
+ let currentCommand;
19268
+ let lastTokenEnd = 0;
19269
+ for (const token of pathData.matchAll(
19270
+ /([a-df-z])|([-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?)/gi
19271
+ )) {
19272
+ if (!/^[\s,]*$/.test(pathData.slice(lastTokenEnd, token.index))) return null;
19273
+ lastTokenEnd = token.index + token[0].length;
19274
+ if (token[1]) {
19275
+ if (!Object.hasOwn(argumentCounts, token[1].toUpperCase())) return null;
19276
+ currentCommand = { command: token[1], arguments: [] };
19277
+ commands.push(currentCommand);
19278
+ } else {
19279
+ const commandArgument = Number(token[2]);
19280
+ if (!currentCommand || !Number.isFinite(commandArgument)) return null;
19281
+ currentCommand.arguments.push(commandArgument);
19262
19282
  }
19263
19283
  }
19264
- return rawRoute;
19284
+ if (!/^[\s,]*$/.test(pathData.slice(lastTokenEnd))) return null;
19285
+ if (commands[0]?.command.toUpperCase() !== "M") return null;
19286
+ for (const pathCommand of commands) {
19287
+ const argumentCount = argumentCounts[pathCommand.command.toUpperCase()];
19288
+ const count = pathCommand.arguments.length;
19289
+ if (argumentCount === 0 ? count !== 0 : count === 0 || count % argumentCount !== 0) {
19290
+ return null;
19291
+ }
19292
+ }
19293
+ return commands;
19294
+ };
19295
+
19296
+ // lib/utils/get-easyeda-npth-pill-hole.ts
19297
+ var PATH_GEOMETRY_TOLERANCE = 1e-9;
19298
+ var isClose = (a, b) => Math.abs(a - b) < PATH_GEOMETRY_TOLERANCE;
19299
+ var getEasyEdaNpthPillHole = (pathData) => {
19300
+ const commands = parseEasyEdaPathCommands(pathData);
19301
+ if (!commands || commands.map((command) => command.command).join("") !== "MLALAZ") {
19302
+ return null;
19303
+ }
19304
+ const coordinates = commands.slice(0, -1).map((command) => command.arguments);
19305
+ if (coordinates.map((command) => command.length).join(",") !== "2,2,7,2,7") {
19306
+ return null;
19307
+ }
19308
+ const [start, firstLineEnd, firstArc, secondLineEnd, secondArc] = coordinates;
19309
+ const firstArcEnd = firstArc.slice(5);
19310
+ const secondArcEnd = secondArc.slice(5);
19311
+ const radius = firstArc[0];
19312
+ 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])) {
19313
+ return null;
19314
+ }
19315
+ 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);
19316
+ 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);
19317
+ if (!horizontal && !vertical) return null;
19318
+ const straightLength = horizontal ? Math.abs(start[0] - firstLineEnd[0]) : Math.abs(start[1] - firstLineEnd[1]);
19319
+ if (straightLength < PATH_GEOMETRY_TOLERANCE) return null;
19320
+ const crossProduct = (firstLineEnd[0] - firstArcEnd[0]) * (firstLineEnd[1] - start[1]) - (firstLineEnd[1] - firstArcEnd[1]) * (firstLineEnd[0] - start[0]);
19321
+ if (firstArc[4] !== Number(crossProduct > 0)) return null;
19322
+ return {
19323
+ hole_shape: "pill",
19324
+ x: mil2mm((start[0] + firstArcEnd[0]) / 2) * 10,
19325
+ y: mil2mm((start[1] + firstArcEnd[1]) / 2) * 10,
19326
+ hole_width: mil2mm(horizontal ? straightLength + radius * 2 : radius * 2) * 10,
19327
+ hole_height: mil2mm(vertical ? straightLength + radius * 2 : radius * 2) * 10
19328
+ };
19329
+ };
19330
+
19331
+ // lib/utils/convert-easyeda-npth-cutouts-to-holes.ts
19332
+ var convertEasyEdaNpthCutoutsToHoles = (circuitJson, npthRegions) => {
19333
+ const npthPillHoles = npthRegions.map((region, index) => ({
19334
+ pcb_cutout_id: `pcb_cutout_npth_${index + 1}`,
19335
+ hole: getEasyEdaNpthPillHole(region.pathData)
19336
+ }));
19337
+ return circuitJson.map((element) => {
19338
+ if (element.type !== "pcb_cutout" || element.shape !== "polygon") {
19339
+ return element;
19340
+ }
19341
+ const npthPillHole = npthPillHoles.find(
19342
+ (candidate) => candidate.pcb_cutout_id === element.pcb_cutout_id
19343
+ );
19344
+ if (!npthPillHole?.hole) return element;
19345
+ const xs = element.points.map((point4) => point4.x);
19346
+ const ys = element.points.map((point4) => point4.y);
19347
+ return pcb_hole.parse({
19348
+ type: "pcb_hole",
19349
+ pcb_hole_id: element.pcb_cutout_id.replace("pcb_cutout_", "pcb_hole_"),
19350
+ pcb_component_id: element.pcb_component_id,
19351
+ ...npthPillHole.hole,
19352
+ x: (Math.min(...xs) + Math.max(...xs)) / 2,
19353
+ y: (Math.min(...ys) + Math.max(...ys)) / 2
19354
+ });
19355
+ });
19356
+ };
19357
+
19358
+ // lib/utils/append-easyeda-path-point.ts
19359
+ var appendEasyEdaPathPoint = (route, point4) => {
19360
+ if (!Number.isFinite(point4.x) || !Number.isFinite(point4.y)) {
19361
+ throw new Error(INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE);
19362
+ }
19363
+ const firstPoint = route[0] ?? point4;
19364
+ const needsClosingPoint = firstPoint.x !== point4.x || firstPoint.y !== point4.y;
19365
+ if (route.length + 1 + Number(needsClosingPoint) > MAX_EASYEDA_PATH_POINTS) {
19366
+ throw new Error(EASYEDA_PATH_LIMIT_MESSAGE);
19367
+ }
19368
+ route.push(point4);
19265
19369
  };
19266
19370
 
19267
19371
  // node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
@@ -19270,6 +19374,17 @@ function orientation(p, q, r) {
19270
19374
  if (val === 0) return 0;
19271
19375
  return val > 0 ? 1 : 2;
19272
19376
  }
19377
+ function pointToSegmentDistance(p, v, w) {
19378
+ const l2 = (w.x - v.x) ** 2 + (w.y - v.y) ** 2;
19379
+ if (l2 === 0) return distance2(p, v);
19380
+ let t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
19381
+ t = Math.max(0, Math.min(1, t));
19382
+ const projection = {
19383
+ x: v.x + t * (w.x - v.x),
19384
+ y: v.y + t * (w.y - v.y)
19385
+ };
19386
+ return distance2(p, projection);
19387
+ }
19273
19388
  function distance2(p1, p2) {
19274
19389
  const dx = p1.x - p2.x;
19275
19390
  const dy = p1.y - p2.y;
@@ -19290,6 +19405,14 @@ var getUnitVectorFromDirection = (direction) => {
19290
19405
  }
19291
19406
  };
19292
19407
 
19408
+ // node_modules/@tscircuit/math-utils/dist/chunk-5J3PCV4D.js
19409
+ function midpoint(p1, p2) {
19410
+ return {
19411
+ x: (p1.x + p2.x) / 2,
19412
+ y: (p1.y + p2.y) / 2
19413
+ };
19414
+ }
19415
+
19293
19416
  // node_modules/@tscircuit/math-utils/dist/chunk-3WCUPG5S.js
19294
19417
  var getBoundsCenter = (bounds) => ({
19295
19418
  x: (bounds.minX + bounds.maxX) / 2,
@@ -19315,6 +19438,194 @@ var getBoundsFromPoints2 = (points) => {
19315
19438
  return { minX, minY, maxX, maxY };
19316
19439
  };
19317
19440
 
19441
+ // lib/utils/flatten-bezier-curve.ts
19442
+ var MAX_SUBDIVISION_DEPTH = 20;
19443
+ var BEZIER_SUBDIVISION_LIMIT_MESSAGE = "Bezier curve exceeds the subdivision limit";
19444
+ var INVALID_BEZIER_GEOMETRY_MESSAGE = "Invalid Bezier curve geometry";
19445
+ var flattenBezierCurve = ({
19446
+ controlPoints,
19447
+ tolerance,
19448
+ maxPoints = MAX_EASYEDA_PATH_POINTS
19449
+ }) => {
19450
+ if (![3, 4].includes(controlPoints.length) || !Number.isFinite(tolerance) || tolerance <= 0 || controlPoints.some(
19451
+ (point4) => !Number.isFinite(point4.x) || !Number.isFinite(point4.y)
19452
+ )) {
19453
+ throw new Error(INVALID_BEZIER_GEOMETRY_MESSAGE);
19454
+ }
19455
+ if (!Number.isInteger(maxPoints) || maxPoints < 2) {
19456
+ throw new Error(EASYEDA_PATH_LIMIT_MESSAGE);
19457
+ }
19458
+ const pointLimit = Math.min(maxPoints, MAX_EASYEDA_PATH_POINTS);
19459
+ const route = [controlPoints[0]];
19460
+ const pending = [{ points: controlPoints, depth: 0 }];
19461
+ while (pending.length) {
19462
+ const { points, depth } = pending.pop();
19463
+ const start = points[0];
19464
+ const end = points.at(-1);
19465
+ if (points.slice(1, -1).every(
19466
+ (point4) => pointToSegmentDistance(point4, start, end) <= tolerance
19467
+ )) {
19468
+ route.push(end);
19469
+ continue;
19470
+ }
19471
+ if (depth >= MAX_SUBDIVISION_DEPTH) {
19472
+ throw new Error(BEZIER_SUBDIVISION_LIMIT_MESSAGE);
19473
+ }
19474
+ if (route.length + pending.length + 2 > pointLimit) {
19475
+ throw new Error(EASYEDA_PATH_LIMIT_MESSAGE);
19476
+ }
19477
+ let level = points;
19478
+ const left = [start];
19479
+ const right = [end];
19480
+ while (level.length > 1) {
19481
+ level = level.slice(1).map((point4, index) => midpoint(level[index], point4));
19482
+ left.push(level[0]);
19483
+ right.unshift(level.at(-1));
19484
+ }
19485
+ pending.push(
19486
+ { points: right, depth: depth + 1 },
19487
+ { points: left, depth: depth + 1 }
19488
+ );
19489
+ }
19490
+ return route;
19491
+ };
19492
+
19493
+ // lib/utils/expand-easyeda-bezier-command.ts
19494
+ var BEZIER_TOLERANCE = 1e-3 / mil10ToMm(1);
19495
+ var expandEasyEdaBezierCommand = (pathCommand, ctx) => {
19496
+ const command = pathCommand.command.toUpperCase();
19497
+ const relative = command !== pathCommand.command;
19498
+ const groupSize = command === "C" ? 6 : command === "T" ? 2 : 4;
19499
+ const route = [];
19500
+ let { currentPoint, cubicControl, quadraticControl } = ctx;
19501
+ for (let offset = 0; offset < pathCommand.arguments.length; offset += groupSize) {
19502
+ if (route.length >= ctx.remainingPoints) {
19503
+ throw new Error(EASYEDA_PATH_LIMIT_MESSAGE);
19504
+ }
19505
+ const coordinates = [];
19506
+ for (let index = offset; index < offset + groupSize; index += 2) {
19507
+ coordinates.push({
19508
+ x: pathCommand.arguments[index] + (relative ? currentPoint.x : 0),
19509
+ y: pathCommand.arguments[index + 1] + (relative ? currentPoint.y : 0)
19510
+ });
19511
+ }
19512
+ const end = coordinates.at(-1);
19513
+ let controlPoints;
19514
+ if (command === "C" || command === "S") {
19515
+ const firstControl = command === "C" ? coordinates[0] : cubicControl ? {
19516
+ x: 2 * currentPoint.x - cubicControl.x,
19517
+ y: 2 * currentPoint.y - cubicControl.y
19518
+ } : currentPoint;
19519
+ cubicControl = coordinates.at(-2);
19520
+ quadraticControl = void 0;
19521
+ controlPoints = [currentPoint, firstControl, cubicControl, end];
19522
+ } else {
19523
+ quadraticControl = command === "Q" ? coordinates[0] : quadraticControl ? {
19524
+ x: 2 * currentPoint.x - quadraticControl.x,
19525
+ y: 2 * currentPoint.y - quadraticControl.y
19526
+ } : currentPoint;
19527
+ cubicControl = void 0;
19528
+ controlPoints = [currentPoint, quadraticControl, end];
19529
+ }
19530
+ const points = flattenBezierCurve({
19531
+ controlPoints,
19532
+ tolerance: BEZIER_TOLERANCE,
19533
+ maxPoints: ctx.remainingPoints - route.length + 1
19534
+ });
19535
+ for (let index = 1; index < points.length; index++) {
19536
+ route.push(points[index]);
19537
+ }
19538
+ currentPoint = end;
19539
+ }
19540
+ return { route, currentPoint, cubicControl, quadraticControl };
19541
+ };
19542
+
19543
+ // lib/utils/expand-easyeda-path-data.ts
19544
+ var expandEasyEdaPathData = (pathData) => {
19545
+ const commands = parseEasyEdaPathCommands(pathData);
19546
+ if (!commands) throw new Error("Invalid EasyEDA SOLIDREGION path");
19547
+ for (const { command } of commands) {
19548
+ if (!/^[MLHVAZCSQT]$/i.test(command)) {
19549
+ throw new Error(
19550
+ `Unsupported EasyEDA SOLIDREGION path command: ${command}`
19551
+ );
19552
+ }
19553
+ }
19554
+ if (commands.slice(1).some(({ command }) => command.toUpperCase() === "M")) {
19555
+ throw new Error("Multiple EasyEDA SOLIDREGION subpaths are not supported");
19556
+ }
19557
+ const rawRoute = [];
19558
+ let currentPoint;
19559
+ let subpathStart;
19560
+ let afterClose = false;
19561
+ let cubicControl;
19562
+ let quadraticControl;
19563
+ for (const pathCommand of commands) {
19564
+ const command = pathCommand.command.toUpperCase();
19565
+ const relative = pathCommand.command !== command;
19566
+ const commandArguments = pathCommand.arguments;
19567
+ if (command !== "C" && command !== "S") cubicControl = void 0;
19568
+ if (command !== "Q" && command !== "T") quadraticControl = void 0;
19569
+ if (afterClose && command !== "Z" && currentPoint) {
19570
+ const lastPoint = rawRoute.at(-1);
19571
+ if (lastPoint?.x !== currentPoint.x || lastPoint?.y !== currentPoint.y) {
19572
+ appendEasyEdaPathPoint(rawRoute, currentPoint);
19573
+ }
19574
+ }
19575
+ afterClose = command === "Z";
19576
+ if ((command === "M" || command === "L") && commandArguments.length >= 2) {
19577
+ for (let offset = 0; offset + 1 < commandArguments.length; offset += 2) {
19578
+ currentPoint = {
19579
+ x: commandArguments[offset] + (relative ? currentPoint?.x ?? 0 : 0),
19580
+ y: commandArguments[offset + 1] + (relative ? currentPoint?.y ?? 0 : 0)
19581
+ };
19582
+ appendEasyEdaPathPoint(rawRoute, currentPoint);
19583
+ if (command === "M" && offset === 0) subpathStart = currentPoint;
19584
+ }
19585
+ } else if ((command === "H" || command === "V") && currentPoint) {
19586
+ for (const coordinate of commandArguments) {
19587
+ currentPoint = {
19588
+ x: command === "H" ? coordinate + (relative ? currentPoint.x : 0) : currentPoint.x,
19589
+ y: command === "V" ? coordinate + (relative ? currentPoint.y : 0) : currentPoint.y
19590
+ };
19591
+ appendEasyEdaPathPoint(rawRoute, currentPoint);
19592
+ }
19593
+ } else if (/^[CSQT]$/.test(command) && currentPoint) {
19594
+ const curve = expandEasyEdaBezierCommand(pathCommand, {
19595
+ currentPoint,
19596
+ cubicControl,
19597
+ quadraticControl,
19598
+ remainingPoints: MAX_EASYEDA_PATH_POINTS - rawRoute.length
19599
+ });
19600
+ for (const point4 of curve.route) appendEasyEdaPathPoint(rawRoute, point4);
19601
+ currentPoint = curve.currentPoint;
19602
+ cubicControl = curve.cubicControl;
19603
+ quadraticControl = curve.quadraticControl;
19604
+ } else if (command === "A" && currentPoint && commandArguments.length >= 7) {
19605
+ for (let offset = 0; offset + 6 < commandArguments.length; offset += 7) {
19606
+ const [radiusX, , , largeArcFlag, sweepFlag, endpointX, endpointY] = commandArguments.slice(offset, offset + 7);
19607
+ const endX = endpointX + (relative ? currentPoint.x : 0);
19608
+ const endY = endpointY + (relative ? currentPoint.y : 0);
19609
+ const arcRoute = generateArcFromSweep({
19610
+ start: currentPoint,
19611
+ end: { x: endX, y: endY },
19612
+ radius: radiusX,
19613
+ largeArcFlag: largeArcFlag === 1,
19614
+ sweepFlag: sweepFlag === 1,
19615
+ maxSegments: 16
19616
+ });
19617
+ for (let index = 1; index < arcRoute.length; index++) {
19618
+ appendEasyEdaPathPoint(rawRoute, arcRoute[index]);
19619
+ }
19620
+ currentPoint = { x: endX, y: endY };
19621
+ }
19622
+ } else if (command === "Z" && subpathStart) {
19623
+ currentPoint = subpathStart;
19624
+ }
19625
+ }
19626
+ return rawRoute;
19627
+ };
19628
+
19318
19629
  // lib/utils/get-board-outline-polygons.ts
19319
19630
  var same = (a, b) => distance2(a, b) < 1e-4;
19320
19631
  var getBoardOutlinePolygons = (tracks) => {
@@ -19632,20 +19943,20 @@ var distanceFromRouteMidpoint = (route, point4) => {
19632
19943
  return Math.hypot(midpoint2.x - point4.x, midpoint2.y - point4.y);
19633
19944
  };
19634
19945
  var getSilkscreenArcPath = (arc2, footprintCenter, silkscreenTracks) => {
19635
- const generateArcPath = (sweepFlag2) => generateArcFromSweep(
19636
- arc2.start.x,
19637
- arc2.start.y,
19638
- arc2.end.x,
19639
- arc2.end.y,
19640
- arc2.radiusX,
19641
- arc2.largeArc,
19642
- sweepFlag2
19643
- );
19946
+ const arcOptions = {
19947
+ start: arc2.start,
19948
+ end: arc2.end,
19949
+ radius: arc2.radiusX,
19950
+ largeArcFlag: arc2.largeArc
19951
+ };
19644
19952
  const sweepFlag = arc2.sweepDirection === "CW";
19645
- const arcPath = generateArcPath(sweepFlag);
19953
+ const arcPath = generateArcFromSweep({ ...arcOptions, sweepFlag });
19646
19954
  const semicircleRole = classifySemicircle(arc2, silkscreenTracks);
19647
19955
  if (!semicircleRole) return arcPath;
19648
- const oppositeArcPath = generateArcPath(!sweepFlag);
19956
+ const oppositeArcPath = generateArcFromSweep({
19957
+ ...arcOptions,
19958
+ sweepFlag: !sweepFlag
19959
+ });
19649
19960
  const arcDistance = distanceFromRouteMidpoint(arcPath, footprintCenter);
19650
19961
  const oppositeDistance = distanceFromRouteMidpoint(
19651
19962
  oppositeArcPath,
@@ -19983,7 +20294,31 @@ var handleFabricationNotePath = (track, index) => pcb_fabrication_note_path.pars
19983
20294
  stroke_width: mil10ToMm(track.width)
19984
20295
  });
19985
20296
  var handleFabricationNoteSolidRegion = (solidRegion, index) => {
19986
- const rawRoute = expandEasyEdaPathData(solidRegion.pathData);
20297
+ const commands = parseEasyEdaPathCommands(solidRegion.pathData);
20298
+ const pathWarning = !commands ? "Invalid EasyEDA SOLIDREGION path" : commands.slice(1).some(({ command }) => command.toUpperCase() === "M") ? "Multiple EasyEDA SOLIDREGION subpaths are not supported" : void 0;
20299
+ if (pathWarning) {
20300
+ console.warn(
20301
+ `Skipping EasyEDA fabrication note ${solidRegion.id ?? index + 1}: ${pathWarning}`
20302
+ );
20303
+ return null;
20304
+ }
20305
+ let rawRoute;
20306
+ try {
20307
+ rawRoute = expandEasyEdaPathData(solidRegion.pathData);
20308
+ } catch (error) {
20309
+ if (!(error instanceof Error) || ![
20310
+ BEZIER_SUBDIVISION_LIMIT_MESSAGE,
20311
+ EASYEDA_PATH_LIMIT_MESSAGE,
20312
+ INVALID_BEZIER_GEOMETRY_MESSAGE,
20313
+ INVALID_EASYEDA_PATH_GEOMETRY_MESSAGE
20314
+ ].includes(error.message)) {
20315
+ throw error;
20316
+ }
20317
+ console.warn(
20318
+ `Skipping EasyEDA fabrication note ${solidRegion.id ?? index + 1}: ${error.message}`
20319
+ );
20320
+ return null;
20321
+ }
19987
20322
  const route = rawRoute.map((point4) => ({
19988
20323
  x: mil10ToMm(point4.x),
19989
20324
  y: mil10ToMm(point4.y)
@@ -20305,9 +20640,10 @@ var convertEasyEdaJsonToCircuitJsonWithPinAttributes = (easyEdaJson, {
20305
20640
  ).forEach((sr, index) => {
20306
20641
  circuitElements.push(handleCutout(sr, index));
20307
20642
  });
20308
- easyEdaJson.packageDetail.dataStr.shape.filter(
20643
+ const npthRegions = easyEdaJson.packageDetail.dataStr.shape.filter(
20309
20644
  (shape) => shape.type === "SOLIDREGION" && isPcbSolidRegionNpth(shape)
20310
- ).forEach((sr, index) => {
20645
+ );
20646
+ npthRegions.forEach((sr, index) => {
20311
20647
  const geometry = getEasyEdaNpthSlotGeometry(sr);
20312
20648
  if (!geometry) return;
20313
20649
  circuitElements.push(
@@ -20602,7 +20938,10 @@ var convertEasyEdaJsonToCircuitJsonWithPinAttributes = (easyEdaJson, {
20602
20938
  }
20603
20939
  pcb_component2.center = { x: 0, y: 0 };
20604
20940
  }
20605
- return { circuitJson: circuitElements, resolvedPinAttributes };
20941
+ return {
20942
+ circuitJson: convertEasyEdaNpthCutoutsToHoles(circuitElements, npthRegions),
20943
+ resolvedPinAttributes
20944
+ };
20606
20945
  };
20607
20946
  var convertEasyEdaJsonToCircuitJson = (easyEdaJson, options = {}) => convertEasyEdaJsonToCircuitJsonWithPinAttributes(easyEdaJson, options).circuitJson;
20608
20947