easyeda 0.0.381 → 0.0.383

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.
@@ -15820,8 +15820,10 @@ var Polygon$1 = class Polygon {
15820
15820
  return edge;
15821
15821
  }
15822
15822
  /**
15823
- * Split polygon into array of polygons, where each polygon is an outer face with all
15824
- * containing inner faces
15823
+ * Split polygon into an array of islands with their contained holes.
15824
+ * The largest face defines the outer orientation; opposite-oriented faces represent voids.
15825
+ * Holes not contained in any island are omitted from the result, without changing
15826
+ * their orientation or the input polygon. This method does not clip overlapping faces.
15825
15827
  * @returns {Flatten.Polygon[]}
15826
15828
  */
15827
15829
  splitToIslands() {
@@ -15866,7 +15868,7 @@ var Polygon$1 = class Polygon {
15866
15868
  }
15867
15869
  /**
15868
15870
  * Helper method to check if face is outer face of the polygon
15869
- * @param face
15871
+ * @param {Flatten.Face} face - face to check
15870
15872
  * @returns {boolean}
15871
15873
  */
15872
15874
  isOuter(face) {
@@ -16651,14 +16653,41 @@ var Distance = class _Distance {
16651
16653
  };
16652
16654
  Flatten.Distance = Distance;
16653
16655
  var { Multiline: Multiline2, Point: Point2, Segment: Segment2, Polygon: Polygon2 } = Flatten;
16656
+ function splitComponents(str) {
16657
+ const components = [];
16658
+ let depth = 0;
16659
+ let start = 0;
16660
+ for (let i = 0; i < str.length; i++) {
16661
+ if (str[i] === "(") depth++;
16662
+ if (str[i] === ")") depth--;
16663
+ if (depth < 0) throw Flatten.Errors.ILLEGAL_PARAMETERS;
16664
+ if (str[i] === "," && depth === 0) {
16665
+ components.push(str.slice(start, i).trim());
16666
+ start = i + 1;
16667
+ }
16668
+ }
16669
+ if (depth !== 0) throw Flatten.Errors.ILLEGAL_PARAMETERS;
16670
+ components.push(str.slice(start).trim());
16671
+ return components;
16672
+ }
16673
+ function unwrap(str) {
16674
+ str = str.trim();
16675
+ if (str === "EMPTY") throw new Error("Empty geometry not supported");
16676
+ if (!str.startsWith("(") || !str.endsWith(")")) {
16677
+ throw Flatten.Errors.ILLEGAL_PARAMETERS;
16678
+ }
16679
+ return str.slice(1, -1).trim();
16680
+ }
16654
16681
  function parseSinglePoint(pointStr) {
16655
- return new Point2(pointStr.split(" ").map(Number));
16682
+ pointStr = pointStr.trim();
16683
+ if (pointStr === "EMPTY") throw new Error("Empty geometry not supported");
16684
+ return new Point2(pointStr.split(/\s+/).map(Number));
16656
16685
  }
16657
16686
  function parseMultiPoint(multipointStr) {
16658
- return multipointStr.split(", ").map(parseSinglePoint);
16687
+ return splitComponents(multipointStr).map((str) => parseSinglePoint(str.startsWith("(") ? unwrap(str) : str));
16659
16688
  }
16660
16689
  function parseLineString(lineStr) {
16661
- const points = parseMultiPoint(lineStr);
16690
+ const points = splitComponents(lineStr).map(parseSinglePoint);
16662
16691
  let segments = [];
16663
16692
  for (let i = 0; i < points.length - 1; i++) {
16664
16693
  segments.push(new Segment2(points[i], points[i + 1]));
@@ -16666,45 +16695,31 @@ function parseLineString(lineStr) {
16666
16695
  return new Multiline2(segments);
16667
16696
  }
16668
16697
  function parseMultiLineString(multilineStr) {
16669
- const lineStrings = multilineStr.replace(/\(\(/, "").replace(/\)\)$/, "").split("), (");
16670
- return lineStrings.map(parseLineString);
16698
+ return splitComponents(multilineStr).map((str) => parseLineString(unwrap(str)));
16671
16699
  }
16672
16700
  function parseSinglePolygon(polygonStr) {
16673
- const facesStr = polygonStr.replace(/\(\(/, "").replace(/\)\)$/, "").split("), (");
16674
16701
  const polygon2 = new Polygon2();
16702
+ if (polygonStr.trim() === "EMPTY") return polygon2;
16703
+ const facesStr = splitComponents(unwrap(polygonStr));
16675
16704
  let orientation2;
16676
- facesStr.forEach((facesStr2, idx) => {
16677
- let points = facesStr2.split(", ").map((coordStr) => {
16678
- return new Point2(coordStr.split(" ").map(Number));
16679
- });
16705
+ facesStr.forEach((faceStr, idx) => {
16706
+ const points = splitComponents(unwrap(faceStr)).map(parseSinglePoint);
16680
16707
  const face = polygon2.addFace(points);
16681
16708
  if (idx === 0) {
16682
16709
  orientation2 = face.orientation();
16683
- } else {
16684
- if (face.orientation() === orientation2) {
16685
- face.reverse();
16686
- }
16710
+ } else if (face.orientation() === orientation2) {
16711
+ face.reverse();
16687
16712
  }
16688
16713
  });
16689
16714
  return polygon2;
16690
16715
  }
16691
- function parseMutliPolygon(multiPolygonString) {
16692
- const polygonStrings = multiPolygonString.split(/\)\), \(\(/).map((polygon3) => "((" + polygon3 + "))");
16693
- const polygons = polygonStrings.map(parseSinglePolygon);
16716
+ function parseMultiPolygon(multiPolygonStr) {
16694
16717
  const polygon2 = new Polygon2();
16695
- const faces = polygons.reduce((acc, polygon3) => [...acc, ...polygon3?.faces], []);
16696
- faces.forEach((face) => polygon2.addFace([...face?.shapes]));
16718
+ splitComponents(multiPolygonStr).map(parseSinglePolygon).forEach((part) => {
16719
+ part.faces.forEach((face) => polygon2.addFace([...face.shapes]));
16720
+ });
16697
16721
  return polygon2;
16698
16722
  }
16699
- function parsePolygon(wkt) {
16700
- if (wkt.startsWith("POLYGON")) {
16701
- const polygonStr = wkt.replace(/^POLYGON /, "");
16702
- return parseSinglePolygon(polygonStr);
16703
- } else {
16704
- const multiPolygonString = wkt.replace(/^MULTIPOLYGON \(\(\((.*)\)\)\)$/, "$1");
16705
- return parseMutliPolygon(multiPolygonString);
16706
- }
16707
- }
16708
16723
  function parseArrayOfPoints(str) {
16709
16724
  const arr = str.split("\n").map((x) => x.match(/\(([^)]+)\)/)[1]);
16710
16725
  return arr.map(parseSinglePoint);
@@ -16714,28 +16729,39 @@ function parseArrayOfLineStrings(str) {
16714
16729
  return arr.map(parseLineString).reduce((acc, x) => [...acc, ...x], []);
16715
16730
  }
16716
16731
  function parseWKT(str) {
16717
- if (str.startsWith("POINT")) {
16718
- const pointStr = str.replace(/^POINT \(/, "").replace(/\)$/, "");
16719
- return parseSinglePoint(pointStr);
16720
- } else if (str.startsWith("MULTIPOINT")) {
16721
- const multiPointStr = str.replace(/^MULTIPOINT \(/, "").replace(/\)$/, "");
16722
- return parseMultiPoint(multiPointStr);
16723
- } else if (str.startsWith("LINESTRING")) {
16724
- const lineStr = str.replace(/^LINESTRING \(/, "").replace(/\)$/, "");
16725
- return parseLineString(lineStr);
16726
- } else if (str.startsWith("MULTILINESTRING")) {
16727
- const multilineStr = str.replace(/^MULTILINESTRING /, "");
16728
- return parseMultiLineString(multilineStr);
16729
- } else if (str.startsWith("POLYGON") || str.startsWith("MULTIPOLYGON")) {
16730
- return parsePolygon(str);
16731
- } else if (str.startsWith("GEOMETRYCOLLECTION")) {
16732
- const regex = /(?<type>POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON) \((?:[^\(\)]|\([^\)]*\))*\)/g;
16733
- const wktArray = str.match(regex);
16734
- if (wktArray[0].startsWith("GEOMETRYCOLLECTION")) {
16735
- wktArray[0] = wktArray[0].replace("GEOMETRYCOLLECTION (", "");
16736
- }
16737
- const flArray = wktArray.map(parseWKT).map((x) => x instanceof Array ? x : [x]);
16738
- return flArray.reduce((acc, x) => [...acc, ...x], []);
16732
+ const records = str.trim().split("\n");
16733
+ if (records.length > 1) {
16734
+ if (records.every((record) => /^\s*POINT\s*\([^()]*\)\s*$/.test(record))) {
16735
+ return parseArrayOfPoints(str.trim());
16736
+ }
16737
+ if (records.every((record) => /^\s*LINESTRING\s*\([^()]*\)\s*$/.test(record))) {
16738
+ return parseArrayOfLineStrings(str.trim());
16739
+ }
16740
+ }
16741
+ const geometry = str.trim().match(/^(POINT|MULTIPOINT|LINESTRING|MULTILINESTRING|POLYGON|MULTIPOLYGON|GEOMETRYCOLLECTION)\s*(EMPTY|\([\s\S]*\))$/);
16742
+ if (geometry) {
16743
+ const [, type, body] = geometry;
16744
+ if (body === "EMPTY") {
16745
+ if (type === "POLYGON") return new Polygon2();
16746
+ throw new Error("Empty geometry not supported");
16747
+ }
16748
+ const content = unwrap(body);
16749
+ switch (type) {
16750
+ case "POINT":
16751
+ return parseSinglePoint(content);
16752
+ case "MULTIPOINT":
16753
+ return parseMultiPoint(content);
16754
+ case "LINESTRING":
16755
+ return parseLineString(content);
16756
+ case "MULTILINESTRING":
16757
+ return parseMultiLineString(content);
16758
+ case "POLYGON":
16759
+ return parseSinglePolygon(body);
16760
+ case "MULTIPOLYGON":
16761
+ return parseMultiPolygon(content);
16762
+ case "GEOMETRYCOLLECTION":
16763
+ return splitComponents(content).map(parseWKT).reduce((acc, shapes) => acc.concat(shapes), []);
16764
+ }
16739
16765
  } else if (isArrayOfPoints(str)) {
16740
16766
  return parseArrayOfPoints(str);
16741
16767
  } else if (isArrayOfLines(str)) {
@@ -18300,30 +18326,37 @@ var expandEasyEdaPathData = (pathData) => {
18300
18326
  const command = commandMatch[1]?.toUpperCase();
18301
18327
  const values = commandMatch[2]?.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
18302
18328
  if ((command === "M" || command === "L") && values.length >= 2) {
18303
- currentPoint = { x: values[0], y: values[1] };
18304
- rawRoute.push(currentPoint);
18329
+ for (let offset = 0; offset + 1 < values.length; offset += 2) {
18330
+ currentPoint = { x: values[offset], y: values[offset + 1] };
18331
+ rawRoute.push(currentPoint);
18332
+ }
18305
18333
  } else if (command === "A" && currentPoint && values.length >= 7) {
18306
- const [radiusX, , , largeArcFlag, sweepFlag, endX, endY] = values;
18307
- const generatedArcRoute = generateArcFromSweep(
18308
- currentPoint.x,
18309
- currentPoint.y,
18310
- endX,
18311
- endY,
18312
- radiusX,
18313
- largeArcFlag === 1,
18314
- sweepFlag === 1
18315
- );
18316
- const maxArcSegments = 16;
18317
- const arcRoute = generatedArcRoute.length <= maxArcSegments + 1 ? generatedArcRoute : Array.from(
18318
- { length: maxArcSegments + 1 },
18319
- (_, pointIndex) => generatedArcRoute.at(
18320
- Math.round(
18321
- pointIndex * (generatedArcRoute.length - 1) / maxArcSegments
18334
+ for (let offset = 0; offset + 6 < values.length; offset += 7) {
18335
+ const [radiusX, , , largeArcFlag, sweepFlag, endX, endY] = values.slice(
18336
+ offset,
18337
+ offset + 7
18338
+ );
18339
+ const generatedArcRoute = generateArcFromSweep(
18340
+ currentPoint.x,
18341
+ currentPoint.y,
18342
+ endX,
18343
+ endY,
18344
+ radiusX,
18345
+ largeArcFlag === 1,
18346
+ sweepFlag === 1
18347
+ );
18348
+ const maxArcSegments = 16;
18349
+ const arcRoute = generatedArcRoute.length <= maxArcSegments + 1 ? generatedArcRoute : Array.from(
18350
+ { length: maxArcSegments + 1 },
18351
+ (_, pointIndex) => generatedArcRoute.at(
18352
+ Math.round(
18353
+ pointIndex * (generatedArcRoute.length - 1) / maxArcSegments
18354
+ )
18322
18355
  )
18323
- )
18324
- ).filter((point4) => !!point4);
18325
- rawRoute.push(...arcRoute.slice(1));
18326
- currentPoint = { x: endX, y: endY };
18356
+ ).filter((point4) => !!point4);
18357
+ rawRoute.push(...arcRoute.slice(1));
18358
+ currentPoint = { x: endX, y: endY };
18359
+ }
18327
18360
  }
18328
18361
  }
18329
18362
  return rawRoute;
@@ -20170,7 +20203,7 @@ var PolygonShapeOutputSchema = external_exports.object({
20170
20203
  lineColor: external_exports.string(),
20171
20204
  id: external_exports.string()
20172
20205
  });
20173
- var parsePolygon2 = (str) => {
20206
+ var parsePolygon = (str) => {
20174
20207
  const [, ...rest] = str.split("~");
20175
20208
  const [pointsStr, lineColor, lineWidth, , fillColor, id] = rest;
20176
20209
  return {
@@ -20182,7 +20215,7 @@ var parsePolygon2 = (str) => {
20182
20215
  id
20183
20216
  };
20184
20217
  };
20185
- var PolygonShapeSchema = external_exports.string().startsWith("PG~").transform(parsePolygon2).pipe(PolygonShapeOutputSchema);
20218
+ var PolygonShapeSchema = external_exports.string().startsWith("PG~").transform(parsePolygon).pipe(PolygonShapeOutputSchema);
20186
20219
  var PathShapeOutputSchema = external_exports.object({
20187
20220
  type: external_exports.literal("PATH"),
20188
20221
  pathData: external_exports.string(),
@@ -21638,7 +21671,8 @@ var isInductorComponent = (betterEasy) => {
21638
21671
  const componentParameters = betterEasy.dataStr.head.c_para;
21639
21672
  const packageName = componentParameters.package;
21640
21673
  const value = componentParameters.Value;
21641
- return packageName?.toUpperCase().startsWith("IND-") === true && typeof value === "string" && inductancePattern.test(value.trim());
21674
+ const hasInductorIdentity = componentParameters.pre?.toUpperCase() === "L?" || packageName?.toUpperCase().startsWith("IND-") === true;
21675
+ return hasInductorIdentity && typeof value === "string" && inductancePattern.test(value.trim());
21642
21676
  };
21643
21677
 
21644
21678
  // lib/websafe/convert-to-typescript-component/is-micro-usb-connector-component.ts