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.
package/dist/index.js CHANGED
@@ -5862,6 +5862,27 @@ var isLedCategoryComponent = (betterEasy) => {
5862
5862
  ].some(categoryValueContainsLed);
5863
5863
  };
5864
5864
 
5865
+ // node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
5866
+ function distance2(p1, p2) {
5867
+ const dx = p1.x - p2.x;
5868
+ const dy = p1.y - p2.y;
5869
+ return Math.sqrt(dx * dx + dy * dy);
5870
+ }
5871
+
5872
+ // node_modules/@tscircuit/math-utils/dist/chunk-GIGMPRPV.js
5873
+ var getUnitVectorFromDirection = (direction) => {
5874
+ switch (direction) {
5875
+ case "up":
5876
+ return { x: 0, y: 1 };
5877
+ case "down":
5878
+ return { x: 0, y: -1 };
5879
+ case "left":
5880
+ return { x: -1, y: 0 };
5881
+ case "right":
5882
+ return { x: 1, y: 0 };
5883
+ }
5884
+ };
5885
+
5865
5886
  // node_modules/@tscircuit/math-utils/dist/chunk-3WCUPG5S.js
5866
5887
  var getBoundsCenter = (bounds) => ({
5867
5888
  x: (bounds.minX + bounds.maxX) / 2,
@@ -7703,7 +7724,9 @@ var generateFootprintTsx = (circuitJson, options = {}) => {
7703
7724
  `<hole pcbX="${mmStr(hole.x)}" pcbY="${mmStr(hole.y)}" diameter="${mmStr(hole.hole_diameter)}" />`
7704
7725
  );
7705
7726
  } else if (hole.hole_shape === "oval") {
7706
- console.warn("Unhandled oval hole in conversion (needs implementation)");
7727
+ elementStrings.push(
7728
+ `<hole pcbX="${mmStr(hole.x)}" pcbY="${mmStr(hole.y)}" width="${mmStr(hole.hole_width)}" height="${mmStr(hole.hole_height)}" shape="oval" />`
7729
+ );
7707
7730
  }
7708
7731
  }
7709
7732
  for (const platedHole of platedHoles) {
@@ -8358,6 +8381,36 @@ var getPinStemLength = (path) => {
8358
8381
  if (!segment) return void 0;
8359
8382
  return toSchematicUnits(Math.abs(Number(segment[1])));
8360
8383
  };
8384
+ var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
8385
+ if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
8386
+ const first = shape.points[0];
8387
+ const last = shape.points[shape.points.length - 1];
8388
+ if (first.x === last.x && first.y === last.y) return [];
8389
+ return [transformPoint(first), transformPoint(last)];
8390
+ });
8391
+ var alignPortToDrawing = ({
8392
+ position: position2,
8393
+ direction,
8394
+ stemLength,
8395
+ drawingEndpoints
8396
+ }) => {
8397
+ if (stemLength === void 0) return position2;
8398
+ const outwardDirection = getUnitVectorFromDirection(direction);
8399
+ const expectedBodyConnection = {
8400
+ x: position2.x - outwardDirection.x * stemLength,
8401
+ y: position2.y - outwardDirection.y * stemLength
8402
+ };
8403
+ const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
8404
+ const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
8405
+ endpoint,
8406
+ distance: distance2(endpoint, expectedBodyConnection)
8407
+ })).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
8408
+ if (!nearestEndpoint) return position2;
8409
+ return {
8410
+ x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
8411
+ y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
8412
+ };
8413
+ };
8361
8414
  var getTextFontSize = (fontSize) => {
8362
8415
  const numericFontSize = Number.parseFloat(fontSize);
8363
8416
  if (!Number.isFinite(numericFontSize)) return 0.2;
@@ -8432,7 +8485,8 @@ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
8432
8485
  var generateShapeTsx = ({
8433
8486
  shape,
8434
8487
  origin,
8435
- portMetadata
8488
+ portMetadata,
8489
+ drawingEndpoints = []
8436
8490
  }) => {
8437
8491
  const transformPoint = getPointTransformer(origin);
8438
8492
  if (shape.type === "RECTANGLE") {
@@ -8468,17 +8522,26 @@ var generateShapeTsx = ({
8468
8522
  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)}} />`;
8469
8523
  }
8470
8524
  if (shape.type === "PIN" && portMetadata) {
8471
- const position2 = transformPoint({ x: shape.x, y: shape.y });
8525
+ const direction = getPinDirection(shape.rotation);
8526
+ const stemLength = getPinStemLength(shape.path);
8527
+ const position2 = alignPortToDrawing({
8528
+ position: transformPoint({ x: shape.x, y: shape.y }),
8529
+ direction,
8530
+ stemLength,
8531
+ drawingEndpoints
8532
+ });
8472
8533
  const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
8473
8534
  const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
8474
- const stemLength = getPinStemLength(shape.path);
8475
8535
  const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
8476
- return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(getPinDirection(shape.rotation))} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
8536
+ return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
8477
8537
  }
8478
8538
  if (shape.type === "IGNORED") return void 0;
8479
8539
  return void 0;
8480
8540
  };
8481
- var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {}) => {
8541
+ var generateSymbolTsx = (easyEdaJson, circuitJson, {
8542
+ includePorts = true,
8543
+ alignPortsToDrawing = false
8544
+ } = {}) => {
8482
8545
  const shapes = easyEdaJson.dataStr.shape;
8483
8546
  if (shapes.length === 0) return void 0;
8484
8547
  const headOrigin = {
@@ -8495,11 +8558,14 @@ var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {})
8495
8558
  easyEdaJson,
8496
8559
  circuitJson
8497
8560
  );
8561
+ const transformPoint = getPointTransformer(origin);
8562
+ const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
8498
8563
  const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
8499
8564
  (shape) => generateShapeTsx({
8500
8565
  shape,
8501
8566
  origin,
8502
- portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
8567
+ portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
8568
+ drawingEndpoints
8503
8569
  })
8504
8570
  ).filter((tsx) => Boolean(tsx));
8505
8571
  if (shapeTsx.length === 0) return void 0;
@@ -8608,8 +8674,7 @@ var convertBetterEasyToTsx = async ({
8608
8674
  const isMultiPinDiode = isDiodeCategoryComponent(betterEasy) && sourcePorts.length !== 2;
8609
8675
  const isPassiveWithCustomSymbol = componentType === "capacitor" || componentType === "resistor";
8610
8676
  const symbolTsx = isPassiveWithCustomSymbol || componentType === "chip" && !isMultiPinDiode && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson, {
8611
- // Passive primitives already create their two source ports.
8612
- includePorts: !isPassiveWithCustomSymbol
8677
+ alignPortsToDrawing: isPassiveWithCustomSymbol
8613
8678
  }) : void 0;
8614
8679
  return generateTypescriptComponent({
8615
8680
  componentName,