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/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,
@@ -8360,6 +8381,36 @@ var getPinStemLength = (path) => {
8360
8381
  if (!segment) return void 0;
8361
8382
  return toSchematicUnits(Math.abs(Number(segment[1])));
8362
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
+ };
8363
8414
  var getTextFontSize = (fontSize) => {
8364
8415
  const numericFontSize = Number.parseFloat(fontSize);
8365
8416
  if (!Number.isFinite(numericFontSize)) return 0.2;
@@ -8434,7 +8485,8 @@ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
8434
8485
  var generateShapeTsx = ({
8435
8486
  shape,
8436
8487
  origin,
8437
- portMetadata
8488
+ portMetadata,
8489
+ drawingEndpoints = []
8438
8490
  }) => {
8439
8491
  const transformPoint = getPointTransformer(origin);
8440
8492
  if (shape.type === "RECTANGLE") {
@@ -8470,17 +8522,26 @@ var generateShapeTsx = ({
8470
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)}} />`;
8471
8523
  }
8472
8524
  if (shape.type === "PIN" && portMetadata) {
8473
- 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
+ });
8474
8533
  const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
8475
8534
  const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
8476
- const stemLength = getPinStemLength(shape.path);
8477
8535
  const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
8478
- 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} />`;
8479
8537
  }
8480
8538
  if (shape.type === "IGNORED") return void 0;
8481
8539
  return void 0;
8482
8540
  };
8483
- var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {}) => {
8541
+ var generateSymbolTsx = (easyEdaJson, circuitJson, {
8542
+ includePorts = true,
8543
+ alignPortsToDrawing = false
8544
+ } = {}) => {
8484
8545
  const shapes = easyEdaJson.dataStr.shape;
8485
8546
  if (shapes.length === 0) return void 0;
8486
8547
  const headOrigin = {
@@ -8497,11 +8558,14 @@ var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {})
8497
8558
  easyEdaJson,
8498
8559
  circuitJson
8499
8560
  );
8561
+ const transformPoint = getPointTransformer(origin);
8562
+ const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
8500
8563
  const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
8501
8564
  (shape) => generateShapeTsx({
8502
8565
  shape,
8503
8566
  origin,
8504
- portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
8567
+ portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
8568
+ drawingEndpoints
8505
8569
  })
8506
8570
  ).filter((tsx) => Boolean(tsx));
8507
8571
  if (shapeTsx.length === 0) return void 0;
@@ -8610,8 +8674,7 @@ var convertBetterEasyToTsx = async ({
8610
8674
  const isMultiPinDiode = isDiodeCategoryComponent(betterEasy) && sourcePorts.length !== 2;
8611
8675
  const isPassiveWithCustomSymbol = componentType === "capacitor" || componentType === "resistor";
8612
8676
  const symbolTsx = isPassiveWithCustomSymbol || componentType === "chip" && !isMultiPinDiode && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson, {
8613
- // Passive primitives already create their two source ports.
8614
- includePorts: !isPassiveWithCustomSymbol
8677
+ alignPortsToDrawing: isPassiveWithCustomSymbol
8615
8678
  }) : void 0;
8616
8679
  return generateTypescriptComponent({
8617
8680
  componentName,