easyeda 0.0.303 → 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.
@@ -9725,6 +9725,27 @@ var isLedCategoryComponent = (betterEasy) => {
9725
9725
  ].some(categoryValueContainsLed);
9726
9726
  };
9727
9727
 
9728
+ // node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
9729
+ function distance2(p1, p2) {
9730
+ const dx = p1.x - p2.x;
9731
+ const dy = p1.y - p2.y;
9732
+ return Math.sqrt(dx * dx + dy * dy);
9733
+ }
9734
+
9735
+ // node_modules/@tscircuit/math-utils/dist/chunk-GIGMPRPV.js
9736
+ var getUnitVectorFromDirection = (direction) => {
9737
+ switch (direction) {
9738
+ case "up":
9739
+ return { x: 0, y: 1 };
9740
+ case "down":
9741
+ return { x: 0, y: -1 };
9742
+ case "left":
9743
+ return { x: -1, y: 0 };
9744
+ case "right":
9745
+ return { x: 1, y: 0 };
9746
+ }
9747
+ };
9748
+
9728
9749
  // node_modules/@tscircuit/math-utils/dist/chunk-3WCUPG5S.js
9729
9750
  var getBoundsCenter = (bounds) => ({
9730
9751
  x: (bounds.minX + bounds.maxX) / 2,
@@ -11402,7 +11423,9 @@ var generateFootprintTsx = (circuitJson, options = {}) => {
11402
11423
  `<hole pcbX="${mmStr(hole.x)}" pcbY="${mmStr(hole.y)}" diameter="${mmStr(hole.hole_diameter)}" />`
11403
11424
  );
11404
11425
  } else if (hole.hole_shape === "oval") {
11405
- console.warn("Unhandled oval hole in conversion (needs implementation)");
11426
+ elementStrings.push(
11427
+ `<hole pcbX="${mmStr(hole.x)}" pcbY="${mmStr(hole.y)}" width="${mmStr(hole.hole_width)}" height="${mmStr(hole.hole_height)}" shape="oval" />`
11428
+ );
11406
11429
  }
11407
11430
  }
11408
11431
  for (const platedHole of platedHoles) {
@@ -12057,6 +12080,36 @@ var getPinStemLength = (path) => {
12057
12080
  if (!segment) return void 0;
12058
12081
  return toSchematicUnits(Math.abs(Number(segment[1])));
12059
12082
  };
12083
+ var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
12084
+ if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
12085
+ const first = shape.points[0];
12086
+ const last = shape.points[shape.points.length - 1];
12087
+ if (first.x === last.x && first.y === last.y) return [];
12088
+ return [transformPoint(first), transformPoint(last)];
12089
+ });
12090
+ var alignPortToDrawing = ({
12091
+ position: position2,
12092
+ direction,
12093
+ stemLength,
12094
+ drawingEndpoints
12095
+ }) => {
12096
+ if (stemLength === void 0) return position2;
12097
+ const outwardDirection = getUnitVectorFromDirection(direction);
12098
+ const expectedBodyConnection = {
12099
+ x: position2.x - outwardDirection.x * stemLength,
12100
+ y: position2.y - outwardDirection.y * stemLength
12101
+ };
12102
+ const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
12103
+ const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
12104
+ endpoint,
12105
+ distance: distance2(endpoint, expectedBodyConnection)
12106
+ })).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
12107
+ if (!nearestEndpoint) return position2;
12108
+ return {
12109
+ x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
12110
+ y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
12111
+ };
12112
+ };
12060
12113
  var getTextFontSize = (fontSize) => {
12061
12114
  const numericFontSize = Number.parseFloat(fontSize);
12062
12115
  if (!Number.isFinite(numericFontSize)) return 0.2;
@@ -12131,7 +12184,8 @@ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
12131
12184
  var generateShapeTsx = ({
12132
12185
  shape,
12133
12186
  origin,
12134
- portMetadata
12187
+ portMetadata,
12188
+ drawingEndpoints = []
12135
12189
  }) => {
12136
12190
  const transformPoint = getPointTransformer(origin);
12137
12191
  if (shape.type === "RECTANGLE") {
@@ -12167,17 +12221,26 @@ var generateShapeTsx = ({
12167
12221
  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)}} />`;
12168
12222
  }
12169
12223
  if (shape.type === "PIN" && portMetadata) {
12170
- const position2 = transformPoint({ x: shape.x, y: shape.y });
12224
+ const direction = getPinDirection(shape.rotation);
12225
+ const stemLength = getPinStemLength(shape.path);
12226
+ const position2 = alignPortToDrawing({
12227
+ position: transformPoint({ x: shape.x, y: shape.y }),
12228
+ direction,
12229
+ stemLength,
12230
+ drawingEndpoints
12231
+ });
12171
12232
  const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
12172
12233
  const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
12173
- const stemLength = getPinStemLength(shape.path);
12174
12234
  const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
12175
- return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(getPinDirection(shape.rotation))} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
12235
+ return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
12176
12236
  }
12177
12237
  if (shape.type === "IGNORED") return void 0;
12178
12238
  return void 0;
12179
12239
  };
12180
- var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {}) => {
12240
+ var generateSymbolTsx = (easyEdaJson, circuitJson, {
12241
+ includePorts = true,
12242
+ alignPortsToDrawing = false
12243
+ } = {}) => {
12181
12244
  const shapes = easyEdaJson.dataStr.shape;
12182
12245
  if (shapes.length === 0) return void 0;
12183
12246
  const headOrigin = {
@@ -12194,11 +12257,14 @@ var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {})
12194
12257
  easyEdaJson,
12195
12258
  circuitJson
12196
12259
  );
12260
+ const transformPoint = getPointTransformer(origin);
12261
+ const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
12197
12262
  const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
12198
12263
  (shape) => generateShapeTsx({
12199
12264
  shape,
12200
12265
  origin,
12201
- portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
12266
+ portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
12267
+ drawingEndpoints
12202
12268
  })
12203
12269
  ).filter((tsx) => Boolean(tsx));
12204
12270
  if (shapeTsx.length === 0) return void 0;
@@ -12307,8 +12373,7 @@ var convertBetterEasyToTsx = async ({
12307
12373
  const isMultiPinDiode = isDiodeCategoryComponent(betterEasy) && sourcePorts.length !== 2;
12308
12374
  const isPassiveWithCustomSymbol = componentType === "capacitor" || componentType === "resistor";
12309
12375
  const symbolTsx = isPassiveWithCustomSymbol || componentType === "chip" && !isMultiPinDiode && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson, {
12310
- // Passive primitives already create their two source ports.
12311
- includePorts: !isPassiveWithCustomSymbol
12376
+ alignPortsToDrawing: isPassiveWithCustomSymbol
12312
12377
  }) : void 0;
12313
12378
  return generateTypescriptComponent({
12314
12379
  componentName,