easyeda 0.0.380 → 0.0.382
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 +117 -91
- package/dist/browser/index.js.map +1 -1
- package/dist/index.js +117 -91
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +118 -92
- package/dist/main.cjs.map +1 -1
- package/package.json +1 -1
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.
|
|
1081
|
+
version: "0.0.381",
|
|
1082
1082
|
files: [
|
|
1083
1083
|
"dist"
|
|
1084
1084
|
],
|
|
@@ -13136,8 +13136,10 @@ var Polygon$1 = class Polygon {
|
|
|
13136
13136
|
return edge;
|
|
13137
13137
|
}
|
|
13138
13138
|
/**
|
|
13139
|
-
* Split polygon into array of
|
|
13140
|
-
*
|
|
13139
|
+
* Split polygon into an array of islands with their contained holes.
|
|
13140
|
+
* The largest face defines the outer orientation; opposite-oriented faces represent voids.
|
|
13141
|
+
* Holes not contained in any island are omitted from the result, without changing
|
|
13142
|
+
* their orientation or the input polygon. This method does not clip overlapping faces.
|
|
13141
13143
|
* @returns {Flatten.Polygon[]}
|
|
13142
13144
|
*/
|
|
13143
13145
|
splitToIslands() {
|
|
@@ -13182,7 +13184,7 @@ var Polygon$1 = class Polygon {
|
|
|
13182
13184
|
}
|
|
13183
13185
|
/**
|
|
13184
13186
|
* Helper method to check if face is outer face of the polygon
|
|
13185
|
-
* @param face
|
|
13187
|
+
* @param {Flatten.Face} face - face to check
|
|
13186
13188
|
* @returns {boolean}
|
|
13187
13189
|
*/
|
|
13188
13190
|
isOuter(face) {
|
|
@@ -13967,14 +13969,41 @@ var Distance = class _Distance {
|
|
|
13967
13969
|
};
|
|
13968
13970
|
Flatten.Distance = Distance;
|
|
13969
13971
|
var { Multiline: Multiline2, Point: Point2, Segment: Segment2, Polygon: Polygon2 } = Flatten;
|
|
13972
|
+
function splitComponents(str) {
|
|
13973
|
+
const components = [];
|
|
13974
|
+
let depth = 0;
|
|
13975
|
+
let start = 0;
|
|
13976
|
+
for (let i = 0; i < str.length; i++) {
|
|
13977
|
+
if (str[i] === "(") depth++;
|
|
13978
|
+
if (str[i] === ")") depth--;
|
|
13979
|
+
if (depth < 0) throw Flatten.Errors.ILLEGAL_PARAMETERS;
|
|
13980
|
+
if (str[i] === "," && depth === 0) {
|
|
13981
|
+
components.push(str.slice(start, i).trim());
|
|
13982
|
+
start = i + 1;
|
|
13983
|
+
}
|
|
13984
|
+
}
|
|
13985
|
+
if (depth !== 0) throw Flatten.Errors.ILLEGAL_PARAMETERS;
|
|
13986
|
+
components.push(str.slice(start).trim());
|
|
13987
|
+
return components;
|
|
13988
|
+
}
|
|
13989
|
+
function unwrap(str) {
|
|
13990
|
+
str = str.trim();
|
|
13991
|
+
if (str === "EMPTY") throw new Error("Empty geometry not supported");
|
|
13992
|
+
if (!str.startsWith("(") || !str.endsWith(")")) {
|
|
13993
|
+
throw Flatten.Errors.ILLEGAL_PARAMETERS;
|
|
13994
|
+
}
|
|
13995
|
+
return str.slice(1, -1).trim();
|
|
13996
|
+
}
|
|
13970
13997
|
function parseSinglePoint(pointStr) {
|
|
13971
|
-
|
|
13998
|
+
pointStr = pointStr.trim();
|
|
13999
|
+
if (pointStr === "EMPTY") throw new Error("Empty geometry not supported");
|
|
14000
|
+
return new Point2(pointStr.split(/\s+/).map(Number));
|
|
13972
14001
|
}
|
|
13973
14002
|
function parseMultiPoint(multipointStr) {
|
|
13974
|
-
return multipointStr.
|
|
14003
|
+
return splitComponents(multipointStr).map((str) => parseSinglePoint(str.startsWith("(") ? unwrap(str) : str));
|
|
13975
14004
|
}
|
|
13976
14005
|
function parseLineString(lineStr) {
|
|
13977
|
-
const points =
|
|
14006
|
+
const points = splitComponents(lineStr).map(parseSinglePoint);
|
|
13978
14007
|
let segments = [];
|
|
13979
14008
|
for (let i = 0; i < points.length - 1; i++) {
|
|
13980
14009
|
segments.push(new Segment2(points[i], points[i + 1]));
|
|
@@ -13982,45 +14011,31 @@ function parseLineString(lineStr) {
|
|
|
13982
14011
|
return new Multiline2(segments);
|
|
13983
14012
|
}
|
|
13984
14013
|
function parseMultiLineString(multilineStr) {
|
|
13985
|
-
|
|
13986
|
-
return lineStrings.map(parseLineString);
|
|
14014
|
+
return splitComponents(multilineStr).map((str) => parseLineString(unwrap(str)));
|
|
13987
14015
|
}
|
|
13988
14016
|
function parseSinglePolygon(polygonStr) {
|
|
13989
|
-
const facesStr = polygonStr.replace(/\(\(/, "").replace(/\)\)$/, "").split("), (");
|
|
13990
14017
|
const polygon2 = new Polygon2();
|
|
14018
|
+
if (polygonStr.trim() === "EMPTY") return polygon2;
|
|
14019
|
+
const facesStr = splitComponents(unwrap(polygonStr));
|
|
13991
14020
|
let orientation2;
|
|
13992
|
-
facesStr.forEach((
|
|
13993
|
-
|
|
13994
|
-
return new Point2(coordStr.split(" ").map(Number));
|
|
13995
|
-
});
|
|
14021
|
+
facesStr.forEach((faceStr, idx) => {
|
|
14022
|
+
const points = splitComponents(unwrap(faceStr)).map(parseSinglePoint);
|
|
13996
14023
|
const face = polygon2.addFace(points);
|
|
13997
14024
|
if (idx === 0) {
|
|
13998
14025
|
orientation2 = face.orientation();
|
|
13999
|
-
} else {
|
|
14000
|
-
|
|
14001
|
-
face.reverse();
|
|
14002
|
-
}
|
|
14026
|
+
} else if (face.orientation() === orientation2) {
|
|
14027
|
+
face.reverse();
|
|
14003
14028
|
}
|
|
14004
14029
|
});
|
|
14005
14030
|
return polygon2;
|
|
14006
14031
|
}
|
|
14007
|
-
function
|
|
14008
|
-
const polygonStrings = multiPolygonString.split(/\)\), \(\(/).map((polygon3) => "((" + polygon3 + "))");
|
|
14009
|
-
const polygons = polygonStrings.map(parseSinglePolygon);
|
|
14032
|
+
function parseMultiPolygon(multiPolygonStr) {
|
|
14010
14033
|
const polygon2 = new Polygon2();
|
|
14011
|
-
|
|
14012
|
-
|
|
14034
|
+
splitComponents(multiPolygonStr).map(parseSinglePolygon).forEach((part) => {
|
|
14035
|
+
part.faces.forEach((face) => polygon2.addFace([...face.shapes]));
|
|
14036
|
+
});
|
|
14013
14037
|
return polygon2;
|
|
14014
14038
|
}
|
|
14015
|
-
function parsePolygon(wkt) {
|
|
14016
|
-
if (wkt.startsWith("POLYGON")) {
|
|
14017
|
-
const polygonStr = wkt.replace(/^POLYGON /, "");
|
|
14018
|
-
return parseSinglePolygon(polygonStr);
|
|
14019
|
-
} else {
|
|
14020
|
-
const multiPolygonString = wkt.replace(/^MULTIPOLYGON \(\(\((.*)\)\)\)$/, "$1");
|
|
14021
|
-
return parseMutliPolygon(multiPolygonString);
|
|
14022
|
-
}
|
|
14023
|
-
}
|
|
14024
14039
|
function parseArrayOfPoints(str) {
|
|
14025
14040
|
const arr = str.split("\n").map((x) => x.match(/\(([^)]+)\)/)[1]);
|
|
14026
14041
|
return arr.map(parseSinglePoint);
|
|
@@ -14030,28 +14045,39 @@ function parseArrayOfLineStrings(str) {
|
|
|
14030
14045
|
return arr.map(parseLineString).reduce((acc, x) => [...acc, ...x], []);
|
|
14031
14046
|
}
|
|
14032
14047
|
function parseWKT(str) {
|
|
14033
|
-
|
|
14034
|
-
|
|
14035
|
-
|
|
14036
|
-
|
|
14037
|
-
|
|
14038
|
-
|
|
14039
|
-
|
|
14040
|
-
|
|
14041
|
-
|
|
14042
|
-
|
|
14043
|
-
|
|
14044
|
-
|
|
14045
|
-
|
|
14046
|
-
|
|
14047
|
-
|
|
14048
|
-
|
|
14049
|
-
const
|
|
14050
|
-
|
|
14051
|
-
|
|
14052
|
-
|
|
14053
|
-
|
|
14054
|
-
|
|
14048
|
+
const records = str.trim().split("\n");
|
|
14049
|
+
if (records.length > 1) {
|
|
14050
|
+
if (records.every((record) => /^\s*POINT\s*\([^()]*\)\s*$/.test(record))) {
|
|
14051
|
+
return parseArrayOfPoints(str.trim());
|
|
14052
|
+
}
|
|
14053
|
+
if (records.every((record) => /^\s*LINESTRING\s*\([^()]*\)\s*$/.test(record))) {
|
|
14054
|
+
return parseArrayOfLineStrings(str.trim());
|
|
14055
|
+
}
|
|
14056
|
+
}
|
|
14057
|
+
const geometry = str.trim().match(/^(POINT|MULTIPOINT|LINESTRING|MULTILINESTRING|POLYGON|MULTIPOLYGON|GEOMETRYCOLLECTION)\s*(EMPTY|\([\s\S]*\))$/);
|
|
14058
|
+
if (geometry) {
|
|
14059
|
+
const [, type, body] = geometry;
|
|
14060
|
+
if (body === "EMPTY") {
|
|
14061
|
+
if (type === "POLYGON") return new Polygon2();
|
|
14062
|
+
throw new Error("Empty geometry not supported");
|
|
14063
|
+
}
|
|
14064
|
+
const content = unwrap(body);
|
|
14065
|
+
switch (type) {
|
|
14066
|
+
case "POINT":
|
|
14067
|
+
return parseSinglePoint(content);
|
|
14068
|
+
case "MULTIPOINT":
|
|
14069
|
+
return parseMultiPoint(content);
|
|
14070
|
+
case "LINESTRING":
|
|
14071
|
+
return parseLineString(content);
|
|
14072
|
+
case "MULTILINESTRING":
|
|
14073
|
+
return parseMultiLineString(content);
|
|
14074
|
+
case "POLYGON":
|
|
14075
|
+
return parseSinglePolygon(body);
|
|
14076
|
+
case "MULTIPOLYGON":
|
|
14077
|
+
return parseMultiPolygon(content);
|
|
14078
|
+
case "GEOMETRYCOLLECTION":
|
|
14079
|
+
return splitComponents(content).map(parseWKT).reduce((acc, shapes) => acc.concat(shapes), []);
|
|
14080
|
+
}
|
|
14055
14081
|
} else if (isArrayOfPoints(str)) {
|
|
14056
14082
|
return parseArrayOfPoints(str);
|
|
14057
14083
|
} else if (isArrayOfLines(str)) {
|
|
@@ -15585,22 +15611,15 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
|
|
|
15585
15611
|
const centerY = midY - h * Math.cos(angle) * centerDirection;
|
|
15586
15612
|
const startAngle = Math.atan2(startY - centerY, startX - centerX);
|
|
15587
15613
|
let endAngle = Math.atan2(endY - centerY, endX - centerX);
|
|
15588
|
-
if (sweepFlag && endAngle
|
|
15589
|
-
endAngle -= 2 * Math.PI;
|
|
15590
|
-
} else if (!sweepFlag && endAngle < startAngle) {
|
|
15614
|
+
if (sweepFlag && endAngle < startAngle) {
|
|
15591
15615
|
endAngle += 2 * Math.PI;
|
|
15616
|
+
} else if (!sweepFlag && endAngle > startAngle) {
|
|
15617
|
+
endAngle -= 2 * Math.PI;
|
|
15592
15618
|
}
|
|
15593
|
-
|
|
15594
|
-
|
|
15595
|
-
|
|
15596
|
-
|
|
15597
|
-
endAngle += 2 * Math.PI;
|
|
15598
|
-
}
|
|
15599
|
-
}
|
|
15600
|
-
const numPoints = Math.max(
|
|
15601
|
-
2,
|
|
15602
|
-
Math.ceil(Math.abs(endAngle - startAngle) * radius)
|
|
15603
|
-
);
|
|
15619
|
+
const arcAngle = Math.abs(endAngle - startAngle);
|
|
15620
|
+
const minNumPoints = Math.max(2, Math.ceil(arcAngle * radius));
|
|
15621
|
+
const isSemicircle = Math.abs(arcAngle - Math.PI) < 1e-6;
|
|
15622
|
+
const numPoints = isSemicircle ? minNumPoints + minNumPoints % 2 : minNumPoints;
|
|
15604
15623
|
const path = [];
|
|
15605
15624
|
for (let i = 0; i <= numPoints; i++) {
|
|
15606
15625
|
const t = i / numPoints;
|
|
@@ -15623,30 +15642,37 @@ var expandEasyEdaPathData = (pathData) => {
|
|
|
15623
15642
|
const command = commandMatch[1]?.toUpperCase();
|
|
15624
15643
|
const values = commandMatch[2]?.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
|
|
15625
15644
|
if ((command === "M" || command === "L") && values.length >= 2) {
|
|
15626
|
-
|
|
15627
|
-
|
|
15645
|
+
for (let offset = 0; offset + 1 < values.length; offset += 2) {
|
|
15646
|
+
currentPoint = { x: values[offset], y: values[offset + 1] };
|
|
15647
|
+
rawRoute.push(currentPoint);
|
|
15648
|
+
}
|
|
15628
15649
|
} else if (command === "A" && currentPoint && values.length >= 7) {
|
|
15629
|
-
|
|
15630
|
-
|
|
15631
|
-
|
|
15632
|
-
|
|
15633
|
-
|
|
15634
|
-
|
|
15635
|
-
|
|
15636
|
-
|
|
15637
|
-
|
|
15638
|
-
|
|
15639
|
-
|
|
15640
|
-
|
|
15641
|
-
|
|
15642
|
-
|
|
15643
|
-
|
|
15644
|
-
|
|
15650
|
+
for (let offset = 0; offset + 6 < values.length; offset += 7) {
|
|
15651
|
+
const [radiusX, , , largeArcFlag, sweepFlag, endX, endY] = values.slice(
|
|
15652
|
+
offset,
|
|
15653
|
+
offset + 7
|
|
15654
|
+
);
|
|
15655
|
+
const generatedArcRoute = generateArcFromSweep(
|
|
15656
|
+
currentPoint.x,
|
|
15657
|
+
currentPoint.y,
|
|
15658
|
+
endX,
|
|
15659
|
+
endY,
|
|
15660
|
+
radiusX,
|
|
15661
|
+
largeArcFlag === 1,
|
|
15662
|
+
sweepFlag === 1
|
|
15663
|
+
);
|
|
15664
|
+
const maxArcSegments = 16;
|
|
15665
|
+
const arcRoute = generatedArcRoute.length <= maxArcSegments + 1 ? generatedArcRoute : Array.from(
|
|
15666
|
+
{ length: maxArcSegments + 1 },
|
|
15667
|
+
(_, pointIndex) => generatedArcRoute.at(
|
|
15668
|
+
Math.round(
|
|
15669
|
+
pointIndex * (generatedArcRoute.length - 1) / maxArcSegments
|
|
15670
|
+
)
|
|
15645
15671
|
)
|
|
15646
|
-
)
|
|
15647
|
-
|
|
15648
|
-
|
|
15649
|
-
|
|
15672
|
+
).filter((point4) => !!point4);
|
|
15673
|
+
rawRoute.push(...arcRoute.slice(1));
|
|
15674
|
+
currentPoint = { x: endX, y: endY };
|
|
15675
|
+
}
|
|
15650
15676
|
}
|
|
15651
15677
|
}
|
|
15652
15678
|
return rawRoute;
|
|
@@ -17498,7 +17524,7 @@ var PolygonShapeOutputSchema = import_zod223.z.object({
|
|
|
17498
17524
|
lineColor: import_zod223.z.string(),
|
|
17499
17525
|
id: import_zod223.z.string()
|
|
17500
17526
|
});
|
|
17501
|
-
var
|
|
17527
|
+
var parsePolygon = (str) => {
|
|
17502
17528
|
const [, ...rest] = str.split("~");
|
|
17503
17529
|
const [pointsStr, lineColor, lineWidth, , fillColor, id] = rest;
|
|
17504
17530
|
return {
|
|
@@ -17510,7 +17536,7 @@ var parsePolygon2 = (str) => {
|
|
|
17510
17536
|
id
|
|
17511
17537
|
};
|
|
17512
17538
|
};
|
|
17513
|
-
var PolygonShapeSchema = import_zod223.z.string().startsWith("PG~").transform(
|
|
17539
|
+
var PolygonShapeSchema = import_zod223.z.string().startsWith("PG~").transform(parsePolygon).pipe(PolygonShapeOutputSchema);
|
|
17514
17540
|
var PathShapeOutputSchema = import_zod223.z.object({
|
|
17515
17541
|
type: import_zod223.z.literal("PATH"),
|
|
17516
17542
|
pathData: import_zod223.z.string(),
|