easyeda 0.0.304 → 0.0.305

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
@@ -3528,7 +3528,7 @@ var import_promises = __toESM(require("fs/promises"), 1);
3528
3528
  var package_default = {
3529
3529
  name: "easyeda",
3530
3530
  type: "module",
3531
- version: "0.0.303",
3531
+ version: "0.0.304",
3532
3532
  files: [
3533
3533
  "dist"
3534
3534
  ],
@@ -9443,6 +9443,27 @@ var isLedCategoryComponent = (betterEasy) => {
9443
9443
  ].some(categoryValueContainsLed);
9444
9444
  };
9445
9445
 
9446
+ // node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
9447
+ function distance2(p1, p2) {
9448
+ const dx = p1.x - p2.x;
9449
+ const dy = p1.y - p2.y;
9450
+ return Math.sqrt(dx * dx + dy * dy);
9451
+ }
9452
+
9453
+ // node_modules/@tscircuit/math-utils/dist/chunk-GIGMPRPV.js
9454
+ var getUnitVectorFromDirection = (direction) => {
9455
+ switch (direction) {
9456
+ case "up":
9457
+ return { x: 0, y: 1 };
9458
+ case "down":
9459
+ return { x: 0, y: -1 };
9460
+ case "left":
9461
+ return { x: -1, y: 0 };
9462
+ case "right":
9463
+ return { x: 1, y: 0 };
9464
+ }
9465
+ };
9466
+
9446
9467
  // node_modules/@tscircuit/math-utils/dist/chunk-3WCUPG5S.js
9447
9468
  var getBoundsCenter = (bounds) => ({
9448
9469
  x: (bounds.minX + bounds.maxX) / 2,
@@ -11767,6 +11788,36 @@ var getPinStemLength = (path) => {
11767
11788
  if (!segment) return void 0;
11768
11789
  return toSchematicUnits(Math.abs(Number(segment[1])));
11769
11790
  };
11791
+ var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
11792
+ if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
11793
+ const first = shape.points[0];
11794
+ const last = shape.points[shape.points.length - 1];
11795
+ if (first.x === last.x && first.y === last.y) return [];
11796
+ return [transformPoint(first), transformPoint(last)];
11797
+ });
11798
+ var alignPortToDrawing = ({
11799
+ position: position2,
11800
+ direction,
11801
+ stemLength,
11802
+ drawingEndpoints
11803
+ }) => {
11804
+ if (stemLength === void 0) return position2;
11805
+ const outwardDirection = getUnitVectorFromDirection(direction);
11806
+ const expectedBodyConnection = {
11807
+ x: position2.x - outwardDirection.x * stemLength,
11808
+ y: position2.y - outwardDirection.y * stemLength
11809
+ };
11810
+ const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
11811
+ const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
11812
+ endpoint,
11813
+ distance: distance2(endpoint, expectedBodyConnection)
11814
+ })).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
11815
+ if (!nearestEndpoint) return position2;
11816
+ return {
11817
+ x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
11818
+ y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
11819
+ };
11820
+ };
11770
11821
  var getTextFontSize = (fontSize) => {
11771
11822
  const numericFontSize = Number.parseFloat(fontSize);
11772
11823
  if (!Number.isFinite(numericFontSize)) return 0.2;
@@ -11841,7 +11892,8 @@ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
11841
11892
  var generateShapeTsx = ({
11842
11893
  shape,
11843
11894
  origin,
11844
- portMetadata
11895
+ portMetadata,
11896
+ drawingEndpoints = []
11845
11897
  }) => {
11846
11898
  const transformPoint = getPointTransformer(origin);
11847
11899
  if (shape.type === "RECTANGLE") {
@@ -11877,17 +11929,26 @@ var generateShapeTsx = ({
11877
11929
  return `<schematictext schX={${position2.x}} schY={${position2.y}} text=${JSON.stringify(shape.content)} fontSize={${getTextFontSize(shape.fontSize)}} anchor=${JSON.stringify(getTextAnchor(shape.alignment))} color=${JSON.stringify(shape.fontColor)} schRotation={${round(-shape.rotation)}} />`;
11878
11930
  }
11879
11931
  if (shape.type === "PIN" && portMetadata) {
11880
- const position2 = transformPoint({ x: shape.x, y: shape.y });
11932
+ const direction = getPinDirection(shape.rotation);
11933
+ const stemLength = getPinStemLength(shape.path);
11934
+ const position2 = alignPortToDrawing({
11935
+ position: transformPoint({ x: shape.x, y: shape.y }),
11936
+ direction,
11937
+ stemLength,
11938
+ drawingEndpoints
11939
+ });
11881
11940
  const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
11882
11941
  const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
11883
- const stemLength = getPinStemLength(shape.path);
11884
11942
  const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
11885
- return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(getPinDirection(shape.rotation))} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
11943
+ return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
11886
11944
  }
11887
11945
  if (shape.type === "IGNORED") return void 0;
11888
11946
  return void 0;
11889
11947
  };
11890
- var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {}) => {
11948
+ var generateSymbolTsx = (easyEdaJson, circuitJson, {
11949
+ includePorts = true,
11950
+ alignPortsToDrawing = false
11951
+ } = {}) => {
11891
11952
  const shapes = easyEdaJson.dataStr.shape;
11892
11953
  if (shapes.length === 0) return void 0;
11893
11954
  const headOrigin = {
@@ -11904,11 +11965,14 @@ var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {})
11904
11965
  easyEdaJson,
11905
11966
  circuitJson
11906
11967
  );
11968
+ const transformPoint = getPointTransformer(origin);
11969
+ const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
11907
11970
  const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
11908
11971
  (shape) => generateShapeTsx({
11909
11972
  shape,
11910
11973
  origin,
11911
- portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
11974
+ portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
11975
+ drawingEndpoints
11912
11976
  })
11913
11977
  ).filter((tsx) => Boolean(tsx));
11914
11978
  if (shapeTsx.length === 0) return void 0;
@@ -12017,8 +12081,7 @@ var convertBetterEasyToTsx = async ({
12017
12081
  const isMultiPinDiode = isDiodeCategoryComponent(betterEasy) && sourcePorts.length !== 2;
12018
12082
  const isPassiveWithCustomSymbol = componentType === "capacitor" || componentType === "resistor";
12019
12083
  const symbolTsx = isPassiveWithCustomSymbol || componentType === "chip" && !isMultiPinDiode && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson, {
12020
- // Passive primitives already create their two source ports.
12021
- includePorts: !isPassiveWithCustomSymbol
12084
+ alignPortsToDrawing: isPassiveWithCustomSymbol
12022
12085
  }) : void 0;
12023
12086
  return generateTypescriptComponent({
12024
12087
  componentName,