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/main.cjs CHANGED
@@ -3528,7 +3528,7 @@ var import_promises = __toESM(require("fs/promises"), 1);
3528
3528
  var package_default = {
3529
3529
  name: "easyeda",
3530
3530
  type: "module",
3531
- version: "0.0.303",
3531
+ version: "0.0.305",
3532
3532
  files: [
3533
3533
  "dist"
3534
3534
  ],
@@ -9443,6 +9443,27 @@ var isLedCategoryComponent = (betterEasy) => {
9443
9443
  ].some(categoryValueContainsLed);
9444
9444
  };
9445
9445
 
9446
+ // node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
9447
+ function distance2(p1, p2) {
9448
+ const dx = p1.x - p2.x;
9449
+ const dy = p1.y - p2.y;
9450
+ return Math.sqrt(dx * dx + dy * dy);
9451
+ }
9452
+
9453
+ // node_modules/@tscircuit/math-utils/dist/chunk-GIGMPRPV.js
9454
+ var getUnitVectorFromDirection = (direction) => {
9455
+ switch (direction) {
9456
+ case "up":
9457
+ return { x: 0, y: 1 };
9458
+ case "down":
9459
+ return { x: 0, y: -1 };
9460
+ case "left":
9461
+ return { x: -1, y: 0 };
9462
+ case "right":
9463
+ return { x: 1, y: 0 };
9464
+ }
9465
+ };
9466
+
9446
9467
  // node_modules/@tscircuit/math-utils/dist/chunk-3WCUPG5S.js
9447
9468
  var getBoundsCenter = (bounds) => ({
9448
9469
  x: (bounds.minX + bounds.maxX) / 2,
@@ -9681,6 +9702,40 @@ var handleSilkscreenCircle = (circle, index) => {
9681
9702
  stroke_width: mil10ToMm(circle.width)
9682
9703
  });
9683
9704
  };
9705
+ var handleRect = (rect, index) => {
9706
+ const width = milx10(rect.width);
9707
+ const height = milx10(rect.height);
9708
+ const center = {
9709
+ x: milx10(rect.x) + width / 2,
9710
+ y: milx10(rect.y) + height / 2
9711
+ };
9712
+ const layer = getSideFromLayer(rect.layer);
9713
+ if (isCourtyardLayer(rect.layer)) {
9714
+ return pcb_courtyard_rect.parse({
9715
+ type: "pcb_courtyard_rect",
9716
+ pcb_courtyard_rect_id: `pcb_courtyard_rect_${index + 1}`,
9717
+ pcb_component_id: "pcb_component_1",
9718
+ center,
9719
+ width,
9720
+ height,
9721
+ layer,
9722
+ ccw_rotation: rect.rotation
9723
+ });
9724
+ }
9725
+ return pcb_silkscreen_rect.parse({
9726
+ type: "pcb_silkscreen_rect",
9727
+ pcb_silkscreen_rect_id: `pcb_silkscreen_rect_${index + 1}`,
9728
+ pcb_component_id: "pcb_component_1",
9729
+ center,
9730
+ width,
9731
+ height,
9732
+ layer,
9733
+ stroke_width: mil2mm(rect.lineWidth),
9734
+ is_filled: rect.fillStyle !== "none",
9735
+ has_stroke: rect.lineWidth > 0,
9736
+ ccw_rotation: rect.rotation
9737
+ });
9738
+ };
9684
9739
  var handleHole = (hole, index) => {
9685
9740
  return pcb_hole.parse({
9686
9741
  type: "pcb_hole",
@@ -9956,6 +10011,8 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
9956
10011
  if (isSilkscreenLayer(shape.layer)) {
9957
10012
  circuitElements.push(handleSilkscreenCircle(shape, index));
9958
10013
  }
10014
+ } else if (shape.type === "RECT") {
10015
+ circuitElements.push(handleRect(shape, index));
9959
10016
  } else if (shape.type === "ARC") {
9960
10017
  if (!isCourtyardLayer(shape.layer)) {
9961
10018
  circuitElements.push(handleSilkscreenArc(shape, index));
@@ -10013,7 +10070,7 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
10013
10070
  );
10014
10071
  }
10015
10072
  const pcbElements = circuitElements.filter(
10016
- (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"
10073
+ (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"
10017
10074
  );
10018
10075
  if (pcbElements.length > 0) {
10019
10076
  const bounds = findBoundsAndCenter(pcbElements);
@@ -11767,6 +11824,36 @@ var getPinStemLength = (path) => {
11767
11824
  if (!segment) return void 0;
11768
11825
  return toSchematicUnits(Math.abs(Number(segment[1])));
11769
11826
  };
11827
+ var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
11828
+ if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
11829
+ const first = shape.points[0];
11830
+ const last = shape.points[shape.points.length - 1];
11831
+ if (first.x === last.x && first.y === last.y) return [];
11832
+ return [transformPoint(first), transformPoint(last)];
11833
+ });
11834
+ var alignPortToDrawing = ({
11835
+ position: position2,
11836
+ direction,
11837
+ stemLength,
11838
+ drawingEndpoints
11839
+ }) => {
11840
+ if (stemLength === void 0) return position2;
11841
+ const outwardDirection = getUnitVectorFromDirection(direction);
11842
+ const expectedBodyConnection = {
11843
+ x: position2.x - outwardDirection.x * stemLength,
11844
+ y: position2.y - outwardDirection.y * stemLength
11845
+ };
11846
+ const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
11847
+ const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
11848
+ endpoint,
11849
+ distance: distance2(endpoint, expectedBodyConnection)
11850
+ })).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
11851
+ if (!nearestEndpoint) return position2;
11852
+ return {
11853
+ x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
11854
+ y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
11855
+ };
11856
+ };
11770
11857
  var getTextFontSize = (fontSize) => {
11771
11858
  const numericFontSize = Number.parseFloat(fontSize);
11772
11859
  if (!Number.isFinite(numericFontSize)) return 0.2;
@@ -11841,7 +11928,8 @@ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
11841
11928
  var generateShapeTsx = ({
11842
11929
  shape,
11843
11930
  origin,
11844
- portMetadata
11931
+ portMetadata,
11932
+ drawingEndpoints = []
11845
11933
  }) => {
11846
11934
  const transformPoint = getPointTransformer(origin);
11847
11935
  if (shape.type === "RECTANGLE") {
@@ -11877,17 +11965,26 @@ var generateShapeTsx = ({
11877
11965
  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)}} />`;
11878
11966
  }
11879
11967
  if (shape.type === "PIN" && portMetadata) {
11880
- const position2 = transformPoint({ x: shape.x, y: shape.y });
11968
+ const direction = getPinDirection(shape.rotation);
11969
+ const stemLength = getPinStemLength(shape.path);
11970
+ const position2 = alignPortToDrawing({
11971
+ position: transformPoint({ x: shape.x, y: shape.y }),
11972
+ direction,
11973
+ stemLength,
11974
+ drawingEndpoints
11975
+ });
11881
11976
  const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
11882
11977
  const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
11883
- const stemLength = getPinStemLength(shape.path);
11884
11978
  const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
11885
- return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(getPinDirection(shape.rotation))} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
11979
+ return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
11886
11980
  }
11887
11981
  if (shape.type === "IGNORED") return void 0;
11888
11982
  return void 0;
11889
11983
  };
11890
- var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {}) => {
11984
+ var generateSymbolTsx = (easyEdaJson, circuitJson, {
11985
+ includePorts = true,
11986
+ alignPortsToDrawing = false
11987
+ } = {}) => {
11891
11988
  const shapes = easyEdaJson.dataStr.shape;
11892
11989
  if (shapes.length === 0) return void 0;
11893
11990
  const headOrigin = {
@@ -11904,11 +12001,14 @@ var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {})
11904
12001
  easyEdaJson,
11905
12002
  circuitJson
11906
12003
  );
12004
+ const transformPoint = getPointTransformer(origin);
12005
+ const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
11907
12006
  const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
11908
12007
  (shape) => generateShapeTsx({
11909
12008
  shape,
11910
12009
  origin,
11911
- portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
12010
+ portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
12011
+ drawingEndpoints
11912
12012
  })
11913
12013
  ).filter((tsx) => Boolean(tsx));
11914
12014
  if (shapeTsx.length === 0) return void 0;
@@ -12017,8 +12117,7 @@ var convertBetterEasyToTsx = async ({
12017
12117
  const isMultiPinDiode = isDiodeCategoryComponent(betterEasy) && sourcePorts.length !== 2;
12018
12118
  const isPassiveWithCustomSymbol = componentType === "capacitor" || componentType === "resistor";
12019
12119
  const symbolTsx = isPassiveWithCustomSymbol || componentType === "chip" && !isMultiPinDiode && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson, {
12020
- // Passive primitives already create their two source ports.
12021
- includePorts: !isPassiveWithCustomSymbol
12120
+ alignPortsToDrawing: isPassiveWithCustomSymbol
12022
12121
  }) : void 0;
12023
12122
  return generateTypescriptComponent({
12024
12123
  componentName,