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.
@@ -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,
@@ -9963,6 +9984,40 @@ var handleSilkscreenCircle = (circle, index) => {
9963
9984
  stroke_width: mil10ToMm(circle.width)
9964
9985
  });
9965
9986
  };
9987
+ var handleRect = (rect, index) => {
9988
+ const width = milx10(rect.width);
9989
+ const height = milx10(rect.height);
9990
+ const center = {
9991
+ x: milx10(rect.x) + width / 2,
9992
+ y: milx10(rect.y) + height / 2
9993
+ };
9994
+ const layer = getSideFromLayer(rect.layer);
9995
+ if (isCourtyardLayer(rect.layer)) {
9996
+ return pcb_courtyard_rect.parse({
9997
+ type: "pcb_courtyard_rect",
9998
+ pcb_courtyard_rect_id: `pcb_courtyard_rect_${index + 1}`,
9999
+ pcb_component_id: "pcb_component_1",
10000
+ center,
10001
+ width,
10002
+ height,
10003
+ layer,
10004
+ ccw_rotation: rect.rotation
10005
+ });
10006
+ }
10007
+ return pcb_silkscreen_rect.parse({
10008
+ type: "pcb_silkscreen_rect",
10009
+ pcb_silkscreen_rect_id: `pcb_silkscreen_rect_${index + 1}`,
10010
+ pcb_component_id: "pcb_component_1",
10011
+ center,
10012
+ width,
10013
+ height,
10014
+ layer,
10015
+ stroke_width: mil2mm(rect.lineWidth),
10016
+ is_filled: rect.fillStyle !== "none",
10017
+ has_stroke: rect.lineWidth > 0,
10018
+ ccw_rotation: rect.rotation
10019
+ });
10020
+ };
9966
10021
  var handleHole = (hole, index) => {
9967
10022
  return pcb_hole.parse({
9968
10023
  type: "pcb_hole",
@@ -10238,6 +10293,8 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
10238
10293
  if (isSilkscreenLayer(shape.layer)) {
10239
10294
  circuitElements.push(handleSilkscreenCircle(shape, index));
10240
10295
  }
10296
+ } else if (shape.type === "RECT") {
10297
+ circuitElements.push(handleRect(shape, index));
10241
10298
  } else if (shape.type === "ARC") {
10242
10299
  if (!isCourtyardLayer(shape.layer)) {
10243
10300
  circuitElements.push(handleSilkscreenArc(shape, index));
@@ -10295,7 +10352,7 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
10295
10352
  );
10296
10353
  }
10297
10354
  const pcbElements = circuitElements.filter(
10298
- (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"
10355
+ (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"
10299
10356
  );
10300
10357
  if (pcbElements.length > 0) {
10301
10358
  const bounds = findBoundsAndCenter(pcbElements);
@@ -12059,6 +12116,36 @@ var getPinStemLength = (path) => {
12059
12116
  if (!segment) return void 0;
12060
12117
  return toSchematicUnits(Math.abs(Number(segment[1])));
12061
12118
  };
12119
+ var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
12120
+ if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
12121
+ const first = shape.points[0];
12122
+ const last = shape.points[shape.points.length - 1];
12123
+ if (first.x === last.x && first.y === last.y) return [];
12124
+ return [transformPoint(first), transformPoint(last)];
12125
+ });
12126
+ var alignPortToDrawing = ({
12127
+ position: position2,
12128
+ direction,
12129
+ stemLength,
12130
+ drawingEndpoints
12131
+ }) => {
12132
+ if (stemLength === void 0) return position2;
12133
+ const outwardDirection = getUnitVectorFromDirection(direction);
12134
+ const expectedBodyConnection = {
12135
+ x: position2.x - outwardDirection.x * stemLength,
12136
+ y: position2.y - outwardDirection.y * stemLength
12137
+ };
12138
+ const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
12139
+ const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
12140
+ endpoint,
12141
+ distance: distance2(endpoint, expectedBodyConnection)
12142
+ })).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
12143
+ if (!nearestEndpoint) return position2;
12144
+ return {
12145
+ x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
12146
+ y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
12147
+ };
12148
+ };
12062
12149
  var getTextFontSize = (fontSize) => {
12063
12150
  const numericFontSize = Number.parseFloat(fontSize);
12064
12151
  if (!Number.isFinite(numericFontSize)) return 0.2;
@@ -12133,7 +12220,8 @@ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
12133
12220
  var generateShapeTsx = ({
12134
12221
  shape,
12135
12222
  origin,
12136
- portMetadata
12223
+ portMetadata,
12224
+ drawingEndpoints = []
12137
12225
  }) => {
12138
12226
  const transformPoint = getPointTransformer(origin);
12139
12227
  if (shape.type === "RECTANGLE") {
@@ -12169,17 +12257,26 @@ var generateShapeTsx = ({
12169
12257
  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
12258
  }
12171
12259
  if (shape.type === "PIN" && portMetadata) {
12172
- const position2 = transformPoint({ x: shape.x, y: shape.y });
12260
+ const direction = getPinDirection(shape.rotation);
12261
+ const stemLength = getPinStemLength(shape.path);
12262
+ const position2 = alignPortToDrawing({
12263
+ position: transformPoint({ x: shape.x, y: shape.y }),
12264
+ direction,
12265
+ stemLength,
12266
+ drawingEndpoints
12267
+ });
12173
12268
  const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
12174
12269
  const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
12175
- const stemLength = getPinStemLength(shape.path);
12176
12270
  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} />`;
12271
+ return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
12178
12272
  }
12179
12273
  if (shape.type === "IGNORED") return void 0;
12180
12274
  return void 0;
12181
12275
  };
12182
- var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {}) => {
12276
+ var generateSymbolTsx = (easyEdaJson, circuitJson, {
12277
+ includePorts = true,
12278
+ alignPortsToDrawing = false
12279
+ } = {}) => {
12183
12280
  const shapes = easyEdaJson.dataStr.shape;
12184
12281
  if (shapes.length === 0) return void 0;
12185
12282
  const headOrigin = {
@@ -12196,11 +12293,14 @@ var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {})
12196
12293
  easyEdaJson,
12197
12294
  circuitJson
12198
12295
  );
12296
+ const transformPoint = getPointTransformer(origin);
12297
+ const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
12199
12298
  const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
12200
12299
  (shape) => generateShapeTsx({
12201
12300
  shape,
12202
12301
  origin,
12203
- portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
12302
+ portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
12303
+ drawingEndpoints
12204
12304
  })
12205
12305
  ).filter((tsx) => Boolean(tsx));
12206
12306
  if (shapeTsx.length === 0) return void 0;
@@ -12309,8 +12409,7 @@ var convertBetterEasyToTsx = async ({
12309
12409
  const isMultiPinDiode = isDiodeCategoryComponent(betterEasy) && sourcePorts.length !== 2;
12310
12410
  const isPassiveWithCustomSymbol = componentType === "capacitor" || componentType === "resistor";
12311
12411
  const symbolTsx = isPassiveWithCustomSymbol || componentType === "chip" && !isMultiPinDiode && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson, {
12312
- // Passive primitives already create their two source ports.
12313
- includePorts: !isPassiveWithCustomSymbol
12412
+ alignPortsToDrawing: isPassiveWithCustomSymbol
12314
12413
  }) : void 0;
12315
12414
  return generateTypescriptComponent({
12316
12415
  componentName,