easyeda 0.0.381 → 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 +110 -77
- package/dist/browser/index.js.map +1 -1
- package/dist/index.js +110 -77
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +111 -78
- package/dist/main.cjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11999,8 +11999,10 @@ var Polygon$1 = class Polygon {
|
|
|
11999
11999
|
return edge;
|
|
12000
12000
|
}
|
|
12001
12001
|
/**
|
|
12002
|
-
* Split polygon into array of
|
|
12003
|
-
*
|
|
12002
|
+
* Split polygon into an array of islands with their contained holes.
|
|
12003
|
+
* The largest face defines the outer orientation; opposite-oriented faces represent voids.
|
|
12004
|
+
* Holes not contained in any island are omitted from the result, without changing
|
|
12005
|
+
* their orientation or the input polygon. This method does not clip overlapping faces.
|
|
12004
12006
|
* @returns {Flatten.Polygon[]}
|
|
12005
12007
|
*/
|
|
12006
12008
|
splitToIslands() {
|
|
@@ -12045,7 +12047,7 @@ var Polygon$1 = class Polygon {
|
|
|
12045
12047
|
}
|
|
12046
12048
|
/**
|
|
12047
12049
|
* Helper method to check if face is outer face of the polygon
|
|
12048
|
-
* @param face
|
|
12050
|
+
* @param {Flatten.Face} face - face to check
|
|
12049
12051
|
* @returns {boolean}
|
|
12050
12052
|
*/
|
|
12051
12053
|
isOuter(face) {
|
|
@@ -12830,14 +12832,41 @@ var Distance = class _Distance {
|
|
|
12830
12832
|
};
|
|
12831
12833
|
Flatten.Distance = Distance;
|
|
12832
12834
|
var { Multiline: Multiline2, Point: Point2, Segment: Segment2, Polygon: Polygon2 } = Flatten;
|
|
12835
|
+
function splitComponents(str) {
|
|
12836
|
+
const components = [];
|
|
12837
|
+
let depth = 0;
|
|
12838
|
+
let start = 0;
|
|
12839
|
+
for (let i = 0; i < str.length; i++) {
|
|
12840
|
+
if (str[i] === "(") depth++;
|
|
12841
|
+
if (str[i] === ")") depth--;
|
|
12842
|
+
if (depth < 0) throw Flatten.Errors.ILLEGAL_PARAMETERS;
|
|
12843
|
+
if (str[i] === "," && depth === 0) {
|
|
12844
|
+
components.push(str.slice(start, i).trim());
|
|
12845
|
+
start = i + 1;
|
|
12846
|
+
}
|
|
12847
|
+
}
|
|
12848
|
+
if (depth !== 0) throw Flatten.Errors.ILLEGAL_PARAMETERS;
|
|
12849
|
+
components.push(str.slice(start).trim());
|
|
12850
|
+
return components;
|
|
12851
|
+
}
|
|
12852
|
+
function unwrap(str) {
|
|
12853
|
+
str = str.trim();
|
|
12854
|
+
if (str === "EMPTY") throw new Error("Empty geometry not supported");
|
|
12855
|
+
if (!str.startsWith("(") || !str.endsWith(")")) {
|
|
12856
|
+
throw Flatten.Errors.ILLEGAL_PARAMETERS;
|
|
12857
|
+
}
|
|
12858
|
+
return str.slice(1, -1).trim();
|
|
12859
|
+
}
|
|
12833
12860
|
function parseSinglePoint(pointStr) {
|
|
12834
|
-
|
|
12861
|
+
pointStr = pointStr.trim();
|
|
12862
|
+
if (pointStr === "EMPTY") throw new Error("Empty geometry not supported");
|
|
12863
|
+
return new Point2(pointStr.split(/\s+/).map(Number));
|
|
12835
12864
|
}
|
|
12836
12865
|
function parseMultiPoint(multipointStr) {
|
|
12837
|
-
return multipointStr.
|
|
12866
|
+
return splitComponents(multipointStr).map((str) => parseSinglePoint(str.startsWith("(") ? unwrap(str) : str));
|
|
12838
12867
|
}
|
|
12839
12868
|
function parseLineString(lineStr) {
|
|
12840
|
-
const points =
|
|
12869
|
+
const points = splitComponents(lineStr).map(parseSinglePoint);
|
|
12841
12870
|
let segments = [];
|
|
12842
12871
|
for (let i = 0; i < points.length - 1; i++) {
|
|
12843
12872
|
segments.push(new Segment2(points[i], points[i + 1]));
|
|
@@ -12845,45 +12874,31 @@ function parseLineString(lineStr) {
|
|
|
12845
12874
|
return new Multiline2(segments);
|
|
12846
12875
|
}
|
|
12847
12876
|
function parseMultiLineString(multilineStr) {
|
|
12848
|
-
|
|
12849
|
-
return lineStrings.map(parseLineString);
|
|
12877
|
+
return splitComponents(multilineStr).map((str) => parseLineString(unwrap(str)));
|
|
12850
12878
|
}
|
|
12851
12879
|
function parseSinglePolygon(polygonStr) {
|
|
12852
|
-
const facesStr = polygonStr.replace(/\(\(/, "").replace(/\)\)$/, "").split("), (");
|
|
12853
12880
|
const polygon2 = new Polygon2();
|
|
12881
|
+
if (polygonStr.trim() === "EMPTY") return polygon2;
|
|
12882
|
+
const facesStr = splitComponents(unwrap(polygonStr));
|
|
12854
12883
|
let orientation2;
|
|
12855
|
-
facesStr.forEach((
|
|
12856
|
-
|
|
12857
|
-
return new Point2(coordStr.split(" ").map(Number));
|
|
12858
|
-
});
|
|
12884
|
+
facesStr.forEach((faceStr, idx) => {
|
|
12885
|
+
const points = splitComponents(unwrap(faceStr)).map(parseSinglePoint);
|
|
12859
12886
|
const face = polygon2.addFace(points);
|
|
12860
12887
|
if (idx === 0) {
|
|
12861
12888
|
orientation2 = face.orientation();
|
|
12862
|
-
} else {
|
|
12863
|
-
|
|
12864
|
-
face.reverse();
|
|
12865
|
-
}
|
|
12889
|
+
} else if (face.orientation() === orientation2) {
|
|
12890
|
+
face.reverse();
|
|
12866
12891
|
}
|
|
12867
12892
|
});
|
|
12868
12893
|
return polygon2;
|
|
12869
12894
|
}
|
|
12870
|
-
function
|
|
12871
|
-
const polygonStrings = multiPolygonString.split(/\)\), \(\(/).map((polygon3) => "((" + polygon3 + "))");
|
|
12872
|
-
const polygons = polygonStrings.map(parseSinglePolygon);
|
|
12895
|
+
function parseMultiPolygon(multiPolygonStr) {
|
|
12873
12896
|
const polygon2 = new Polygon2();
|
|
12874
|
-
|
|
12875
|
-
|
|
12897
|
+
splitComponents(multiPolygonStr).map(parseSinglePolygon).forEach((part) => {
|
|
12898
|
+
part.faces.forEach((face) => polygon2.addFace([...face.shapes]));
|
|
12899
|
+
});
|
|
12876
12900
|
return polygon2;
|
|
12877
12901
|
}
|
|
12878
|
-
function parsePolygon(wkt) {
|
|
12879
|
-
if (wkt.startsWith("POLYGON")) {
|
|
12880
|
-
const polygonStr = wkt.replace(/^POLYGON /, "");
|
|
12881
|
-
return parseSinglePolygon(polygonStr);
|
|
12882
|
-
} else {
|
|
12883
|
-
const multiPolygonString = wkt.replace(/^MULTIPOLYGON \(\(\((.*)\)\)\)$/, "$1");
|
|
12884
|
-
return parseMutliPolygon(multiPolygonString);
|
|
12885
|
-
}
|
|
12886
|
-
}
|
|
12887
12902
|
function parseArrayOfPoints(str) {
|
|
12888
12903
|
const arr = str.split("\n").map((x) => x.match(/\(([^)]+)\)/)[1]);
|
|
12889
12904
|
return arr.map(parseSinglePoint);
|
|
@@ -12893,28 +12908,39 @@ function parseArrayOfLineStrings(str) {
|
|
|
12893
12908
|
return arr.map(parseLineString).reduce((acc, x) => [...acc, ...x], []);
|
|
12894
12909
|
}
|
|
12895
12910
|
function parseWKT(str) {
|
|
12896
|
-
|
|
12897
|
-
|
|
12898
|
-
|
|
12899
|
-
|
|
12900
|
-
|
|
12901
|
-
|
|
12902
|
-
|
|
12903
|
-
|
|
12904
|
-
|
|
12905
|
-
|
|
12906
|
-
|
|
12907
|
-
|
|
12908
|
-
|
|
12909
|
-
|
|
12910
|
-
|
|
12911
|
-
|
|
12912
|
-
const
|
|
12913
|
-
|
|
12914
|
-
|
|
12915
|
-
|
|
12916
|
-
|
|
12917
|
-
|
|
12911
|
+
const records = str.trim().split("\n");
|
|
12912
|
+
if (records.length > 1) {
|
|
12913
|
+
if (records.every((record) => /^\s*POINT\s*\([^()]*\)\s*$/.test(record))) {
|
|
12914
|
+
return parseArrayOfPoints(str.trim());
|
|
12915
|
+
}
|
|
12916
|
+
if (records.every((record) => /^\s*LINESTRING\s*\([^()]*\)\s*$/.test(record))) {
|
|
12917
|
+
return parseArrayOfLineStrings(str.trim());
|
|
12918
|
+
}
|
|
12919
|
+
}
|
|
12920
|
+
const geometry = str.trim().match(/^(POINT|MULTIPOINT|LINESTRING|MULTILINESTRING|POLYGON|MULTIPOLYGON|GEOMETRYCOLLECTION)\s*(EMPTY|\([\s\S]*\))$/);
|
|
12921
|
+
if (geometry) {
|
|
12922
|
+
const [, type, body] = geometry;
|
|
12923
|
+
if (body === "EMPTY") {
|
|
12924
|
+
if (type === "POLYGON") return new Polygon2();
|
|
12925
|
+
throw new Error("Empty geometry not supported");
|
|
12926
|
+
}
|
|
12927
|
+
const content = unwrap(body);
|
|
12928
|
+
switch (type) {
|
|
12929
|
+
case "POINT":
|
|
12930
|
+
return parseSinglePoint(content);
|
|
12931
|
+
case "MULTIPOINT":
|
|
12932
|
+
return parseMultiPoint(content);
|
|
12933
|
+
case "LINESTRING":
|
|
12934
|
+
return parseLineString(content);
|
|
12935
|
+
case "MULTILINESTRING":
|
|
12936
|
+
return parseMultiLineString(content);
|
|
12937
|
+
case "POLYGON":
|
|
12938
|
+
return parseSinglePolygon(body);
|
|
12939
|
+
case "MULTIPOLYGON":
|
|
12940
|
+
return parseMultiPolygon(content);
|
|
12941
|
+
case "GEOMETRYCOLLECTION":
|
|
12942
|
+
return splitComponents(content).map(parseWKT).reduce((acc, shapes) => acc.concat(shapes), []);
|
|
12943
|
+
}
|
|
12918
12944
|
} else if (isArrayOfPoints(str)) {
|
|
12919
12945
|
return parseArrayOfPoints(str);
|
|
12920
12946
|
} else if (isArrayOfLines(str)) {
|
|
@@ -14479,30 +14505,37 @@ var expandEasyEdaPathData = (pathData) => {
|
|
|
14479
14505
|
const command = commandMatch[1]?.toUpperCase();
|
|
14480
14506
|
const values = commandMatch[2]?.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
|
|
14481
14507
|
if ((command === "M" || command === "L") && values.length >= 2) {
|
|
14482
|
-
|
|
14483
|
-
|
|
14508
|
+
for (let offset = 0; offset + 1 < values.length; offset += 2) {
|
|
14509
|
+
currentPoint = { x: values[offset], y: values[offset + 1] };
|
|
14510
|
+
rawRoute.push(currentPoint);
|
|
14511
|
+
}
|
|
14484
14512
|
} else if (command === "A" && currentPoint && values.length >= 7) {
|
|
14485
|
-
|
|
14486
|
-
|
|
14487
|
-
|
|
14488
|
-
|
|
14489
|
-
|
|
14490
|
-
|
|
14491
|
-
|
|
14492
|
-
|
|
14493
|
-
|
|
14494
|
-
|
|
14495
|
-
|
|
14496
|
-
|
|
14497
|
-
|
|
14498
|
-
|
|
14499
|
-
|
|
14500
|
-
|
|
14513
|
+
for (let offset = 0; offset + 6 < values.length; offset += 7) {
|
|
14514
|
+
const [radiusX, , , largeArcFlag, sweepFlag, endX, endY] = values.slice(
|
|
14515
|
+
offset,
|
|
14516
|
+
offset + 7
|
|
14517
|
+
);
|
|
14518
|
+
const generatedArcRoute = generateArcFromSweep(
|
|
14519
|
+
currentPoint.x,
|
|
14520
|
+
currentPoint.y,
|
|
14521
|
+
endX,
|
|
14522
|
+
endY,
|
|
14523
|
+
radiusX,
|
|
14524
|
+
largeArcFlag === 1,
|
|
14525
|
+
sweepFlag === 1
|
|
14526
|
+
);
|
|
14527
|
+
const maxArcSegments = 16;
|
|
14528
|
+
const arcRoute = generatedArcRoute.length <= maxArcSegments + 1 ? generatedArcRoute : Array.from(
|
|
14529
|
+
{ length: maxArcSegments + 1 },
|
|
14530
|
+
(_, pointIndex) => generatedArcRoute.at(
|
|
14531
|
+
Math.round(
|
|
14532
|
+
pointIndex * (generatedArcRoute.length - 1) / maxArcSegments
|
|
14533
|
+
)
|
|
14501
14534
|
)
|
|
14502
|
-
)
|
|
14503
|
-
|
|
14504
|
-
|
|
14505
|
-
|
|
14535
|
+
).filter((point4) => !!point4);
|
|
14536
|
+
rawRoute.push(...arcRoute.slice(1));
|
|
14537
|
+
currentPoint = { x: endX, y: endY };
|
|
14538
|
+
}
|
|
14506
14539
|
}
|
|
14507
14540
|
}
|
|
14508
14541
|
return rawRoute;
|
|
@@ -16580,7 +16613,7 @@ var PolygonShapeOutputSchema = z223.object({
|
|
|
16580
16613
|
lineColor: z223.string(),
|
|
16581
16614
|
id: z223.string()
|
|
16582
16615
|
});
|
|
16583
|
-
var
|
|
16616
|
+
var parsePolygon = (str) => {
|
|
16584
16617
|
const [, ...rest] = str.split("~");
|
|
16585
16618
|
const [pointsStr, lineColor, lineWidth, , fillColor, id] = rest;
|
|
16586
16619
|
return {
|
|
@@ -16592,7 +16625,7 @@ var parsePolygon2 = (str) => {
|
|
|
16592
16625
|
id
|
|
16593
16626
|
};
|
|
16594
16627
|
};
|
|
16595
|
-
var PolygonShapeSchema = z223.string().startsWith("PG~").transform(
|
|
16628
|
+
var PolygonShapeSchema = z223.string().startsWith("PG~").transform(parsePolygon).pipe(PolygonShapeOutputSchema);
|
|
16596
16629
|
var PathShapeOutputSchema = z223.object({
|
|
16597
16630
|
type: z223.literal("PATH"),
|
|
16598
16631
|
pathData: z223.string(),
|