easyeda 0.0.304 → 0.0.306

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,
@@ -6100,6 +6121,40 @@ var handleSilkscreenCircle = (circle, index) => {
6100
6121
  stroke_width: mil10ToMm(circle.width)
6101
6122
  });
6102
6123
  };
6124
+ var handleRect = (rect, index) => {
6125
+ const width = milx10(rect.width);
6126
+ const height = milx10(rect.height);
6127
+ const center = {
6128
+ x: milx10(rect.x) + width / 2,
6129
+ y: milx10(rect.y) + height / 2
6130
+ };
6131
+ const layer = getSideFromLayer(rect.layer);
6132
+ if (isCourtyardLayer(rect.layer)) {
6133
+ return pcb_courtyard_rect.parse({
6134
+ type: "pcb_courtyard_rect",
6135
+ pcb_courtyard_rect_id: `pcb_courtyard_rect_${index + 1}`,
6136
+ pcb_component_id: "pcb_component_1",
6137
+ center,
6138
+ width,
6139
+ height,
6140
+ layer,
6141
+ ccw_rotation: rect.rotation
6142
+ });
6143
+ }
6144
+ return pcb_silkscreen_rect.parse({
6145
+ type: "pcb_silkscreen_rect",
6146
+ pcb_silkscreen_rect_id: `pcb_silkscreen_rect_${index + 1}`,
6147
+ pcb_component_id: "pcb_component_1",
6148
+ center,
6149
+ width,
6150
+ height,
6151
+ layer,
6152
+ stroke_width: mil2mm(rect.lineWidth),
6153
+ is_filled: rect.fillStyle !== "none",
6154
+ has_stroke: rect.lineWidth > 0,
6155
+ ccw_rotation: rect.rotation
6156
+ });
6157
+ };
6103
6158
  var handleHole = (hole, index) => {
6104
6159
  return pcb_hole.parse({
6105
6160
  type: "pcb_hole",
@@ -6375,6 +6430,8 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
6375
6430
  if (isSilkscreenLayer(shape.layer)) {
6376
6431
  circuitElements.push(handleSilkscreenCircle(shape, index));
6377
6432
  }
6433
+ } else if (shape.type === "RECT") {
6434
+ circuitElements.push(handleRect(shape, index));
6378
6435
  } else if (shape.type === "ARC") {
6379
6436
  if (!isCourtyardLayer(shape.layer)) {
6380
6437
  circuitElements.push(handleSilkscreenArc(shape, index));
@@ -6432,7 +6489,7 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
6432
6489
  );
6433
6490
  }
6434
6491
  const pcbElements = circuitElements.filter(
6435
- (e) => e.type === "pcb_smtpad" || e.type === "pcb_plated_hole" || e.type === "pcb_hole" || e.type === "pcb_via" || e.type === "pcb_courtyard_outline" || e.type === "pcb_silkscreen_path" || e.type === "pcb_silkscreen_text"
6492
+ (e) => e.type === "pcb_smtpad" || e.type === "pcb_plated_hole" || e.type === "pcb_hole" || e.type === "pcb_via" || e.type === "pcb_courtyard_outline" || e.type === "pcb_courtyard_rect" || e.type === "pcb_silkscreen_path" || e.type === "pcb_silkscreen_rect" || e.type === "pcb_silkscreen_text"
6436
6493
  );
6437
6494
  if (pcbElements.length > 0) {
6438
6495
  const bounds = findBoundsAndCenter(pcbElements);
@@ -8360,6 +8417,36 @@ var getPinStemLength = (path) => {
8360
8417
  if (!segment) return void 0;
8361
8418
  return toSchematicUnits(Math.abs(Number(segment[1])));
8362
8419
  };
8420
+ var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
8421
+ if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
8422
+ const first = shape.points[0];
8423
+ const last = shape.points[shape.points.length - 1];
8424
+ if (first.x === last.x && first.y === last.y) return [];
8425
+ return [transformPoint(first), transformPoint(last)];
8426
+ });
8427
+ var alignPortToDrawing = ({
8428
+ position: position2,
8429
+ direction,
8430
+ stemLength,
8431
+ drawingEndpoints
8432
+ }) => {
8433
+ if (stemLength === void 0) return position2;
8434
+ const outwardDirection = getUnitVectorFromDirection(direction);
8435
+ const expectedBodyConnection = {
8436
+ x: position2.x - outwardDirection.x * stemLength,
8437
+ y: position2.y - outwardDirection.y * stemLength
8438
+ };
8439
+ const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
8440
+ const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
8441
+ endpoint,
8442
+ distance: distance2(endpoint, expectedBodyConnection)
8443
+ })).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
8444
+ if (!nearestEndpoint) return position2;
8445
+ return {
8446
+ x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
8447
+ y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
8448
+ };
8449
+ };
8363
8450
  var getTextFontSize = (fontSize) => {
8364
8451
  const numericFontSize = Number.parseFloat(fontSize);
8365
8452
  if (!Number.isFinite(numericFontSize)) return 0.2;
@@ -8434,7 +8521,8 @@ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
8434
8521
  var generateShapeTsx = ({
8435
8522
  shape,
8436
8523
  origin,
8437
- portMetadata
8524
+ portMetadata,
8525
+ drawingEndpoints = []
8438
8526
  }) => {
8439
8527
  const transformPoint = getPointTransformer(origin);
8440
8528
  if (shape.type === "RECTANGLE") {
@@ -8470,17 +8558,26 @@ var generateShapeTsx = ({
8470
8558
  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
8559
  }
8472
8560
  if (shape.type === "PIN" && portMetadata) {
8473
- const position2 = transformPoint({ x: shape.x, y: shape.y });
8561
+ const direction = getPinDirection(shape.rotation);
8562
+ const stemLength = getPinStemLength(shape.path);
8563
+ const position2 = alignPortToDrawing({
8564
+ position: transformPoint({ x: shape.x, y: shape.y }),
8565
+ direction,
8566
+ stemLength,
8567
+ drawingEndpoints
8568
+ });
8474
8569
  const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
8475
8570
  const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
8476
- const stemLength = getPinStemLength(shape.path);
8477
8571
  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} />`;
8572
+ return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
8479
8573
  }
8480
8574
  if (shape.type === "IGNORED") return void 0;
8481
8575
  return void 0;
8482
8576
  };
8483
- var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {}) => {
8577
+ var generateSymbolTsx = (easyEdaJson, circuitJson, {
8578
+ includePorts = true,
8579
+ alignPortsToDrawing = false
8580
+ } = {}) => {
8484
8581
  const shapes = easyEdaJson.dataStr.shape;
8485
8582
  if (shapes.length === 0) return void 0;
8486
8583
  const headOrigin = {
@@ -8497,11 +8594,14 @@ var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {})
8497
8594
  easyEdaJson,
8498
8595
  circuitJson
8499
8596
  );
8597
+ const transformPoint = getPointTransformer(origin);
8598
+ const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
8500
8599
  const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
8501
8600
  (shape) => generateShapeTsx({
8502
8601
  shape,
8503
8602
  origin,
8504
- portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
8603
+ portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
8604
+ drawingEndpoints
8505
8605
  })
8506
8606
  ).filter((tsx) => Boolean(tsx));
8507
8607
  if (shapeTsx.length === 0) return void 0;
@@ -8610,8 +8710,7 @@ var convertBetterEasyToTsx = async ({
8610
8710
  const isMultiPinDiode = isDiodeCategoryComponent(betterEasy) && sourcePorts.length !== 2;
8611
8711
  const isPassiveWithCustomSymbol = componentType === "capacitor" || componentType === "resistor";
8612
8712
  const symbolTsx = isPassiveWithCustomSymbol || componentType === "chip" && !isMultiPinDiode && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson, {
8613
- // Passive primitives already create their two source ports.
8614
- includePorts: !isPassiveWithCustomSymbol
8713
+ alignPortsToDrawing: isPassiveWithCustomSymbol
8615
8714
  }) : void 0;
8616
8715
  return generateTypescriptComponent({
8617
8716
  componentName,