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.
@@ -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,
@@ -12059,6 +12080,36 @@ var getPinStemLength = (path) => {
12059
12080
  if (!segment) return void 0;
12060
12081
  return toSchematicUnits(Math.abs(Number(segment[1])));
12061
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
+ };
12062
12113
  var getTextFontSize = (fontSize) => {
12063
12114
  const numericFontSize = Number.parseFloat(fontSize);
12064
12115
  if (!Number.isFinite(numericFontSize)) return 0.2;
@@ -12133,7 +12184,8 @@ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
12133
12184
  var generateShapeTsx = ({
12134
12185
  shape,
12135
12186
  origin,
12136
- portMetadata
12187
+ portMetadata,
12188
+ drawingEndpoints = []
12137
12189
  }) => {
12138
12190
  const transformPoint = getPointTransformer(origin);
12139
12191
  if (shape.type === "RECTANGLE") {
@@ -12169,17 +12221,26 @@ var generateShapeTsx = ({
12169
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)}} />`;
12170
12222
  }
12171
12223
  if (shape.type === "PIN" && portMetadata) {
12172
- 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
+ });
12173
12232
  const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
12174
12233
  const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
12175
- const stemLength = getPinStemLength(shape.path);
12176
12234
  const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
12177
- 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} />`;
12178
12236
  }
12179
12237
  if (shape.type === "IGNORED") return void 0;
12180
12238
  return void 0;
12181
12239
  };
12182
- var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {}) => {
12240
+ var generateSymbolTsx = (easyEdaJson, circuitJson, {
12241
+ includePorts = true,
12242
+ alignPortsToDrawing = false
12243
+ } = {}) => {
12183
12244
  const shapes = easyEdaJson.dataStr.shape;
12184
12245
  if (shapes.length === 0) return void 0;
12185
12246
  const headOrigin = {
@@ -12196,11 +12257,14 @@ var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {})
12196
12257
  easyEdaJson,
12197
12258
  circuitJson
12198
12259
  );
12260
+ const transformPoint = getPointTransformer(origin);
12261
+ const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
12199
12262
  const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
12200
12263
  (shape) => generateShapeTsx({
12201
12264
  shape,
12202
12265
  origin,
12203
- portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
12266
+ portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
12267
+ drawingEndpoints
12204
12268
  })
12205
12269
  ).filter((tsx) => Boolean(tsx));
12206
12270
  if (shapeTsx.length === 0) return void 0;
@@ -12309,8 +12373,7 @@ var convertBetterEasyToTsx = async ({
12309
12373
  const isMultiPinDiode = isDiodeCategoryComponent(betterEasy) && sourcePorts.length !== 2;
12310
12374
  const isPassiveWithCustomSymbol = componentType === "capacitor" || componentType === "resistor";
12311
12375
  const symbolTsx = isPassiveWithCustomSymbol || componentType === "chip" && !isMultiPinDiode && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson, {
12312
- // Passive primitives already create their two source ports.
12313
- includePorts: !isPassiveWithCustomSymbol
12376
+ alignPortsToDrawing: isPassiveWithCustomSymbol
12314
12377
  }) : void 0;
12315
12378
  return generateTypescriptComponent({
12316
12379
  componentName,