easyeda 0.0.253 → 0.0.254

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.d.ts CHANGED
@@ -4864,8 +4864,9 @@ interface Options {
4864
4864
  cadPositionXMm?: number;
4865
4865
  cadPositionYMm?: number;
4866
4866
  cadPositionZMm?: number;
4867
+ showDesignator?: boolean;
4867
4868
  }
4868
- declare const convertEasyEdaJsonToCircuitJson: (easyEdaJson: BetterEasyEdaJson, { useModelCdn, shouldRecenter, cadPositionXMm, cadPositionYMm, cadPositionZMm, }?: Options) => AnyCircuitElement[];
4869
+ declare const convertEasyEdaJsonToCircuitJson: (easyEdaJson: BetterEasyEdaJson, { useModelCdn, shouldRecenter, cadPositionXMm, cadPositionYMm, cadPositionZMm, showDesignator, }?: Options) => AnyCircuitElement[];
4869
4870
 
4870
4871
  declare function fetchEasyEDAComponent(jlcpcbPartNumber: string, { fetch, includeModelMetadata, }?: {
4871
4872
  fetch?: typeof globalThis.fetch;
package/dist/index.js CHANGED
@@ -5013,9 +5013,6 @@ var mmStr = (n) => {
5013
5013
  return `${mm(n)}mm`;
5014
5014
  };
5015
5015
 
5016
- // lib/constants.ts
5017
- var DEFAULT_PCB_THICKNESS_MM = 1.6;
5018
-
5019
5016
  // lib/math/arc-utils.ts
5020
5017
  function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag, sweepFlag) {
5021
5018
  const start = { x: startX, y: startY };
@@ -5141,6 +5138,9 @@ var normalizeSymbolName = (name) => {
5141
5138
  return trimmedName;
5142
5139
  };
5143
5140
 
5141
+ // lib/constants.ts
5142
+ var DEFAULT_PCB_THICKNESS_MM = 1.6;
5143
+
5144
5144
  // lib/convert-easyeda-json-to-tscircuit-soup-json.ts
5145
5145
  var EASYEDA_STEP_MODEL_URL = "https://modules.easyeda.com/qAxj6KHrDKw4blvCG8QJPs7Y";
5146
5146
  var EASYEDA_OBJ_MODEL_URL = "https://modules.easyeda.com/3dmodel";
@@ -5281,7 +5281,8 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
5281
5281
  shouldRecenter = true,
5282
5282
  cadPositionXMm,
5283
5283
  cadPositionYMm,
5284
- cadPositionZMm
5284
+ cadPositionZMm,
5285
+ showDesignator = false
5285
5286
  } = {}) => {
5286
5287
  const resolvedCadPositionZMm = cadPositionZMm ?? getCadPositionZMmFromMetadata(easyEdaJson);
5287
5288
  const circuitElements = [];
@@ -5470,6 +5471,7 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
5470
5471
  ).forEach((sr, index) => {
5471
5472
  circuitElements.push(handleCutout(sr, index));
5472
5473
  });
5474
+ let hasFoundDesignator = false;
5473
5475
  easyEdaJson.packageDetail.dataStr.shape.forEach((shape, index) => {
5474
5476
  if (shape.type === "TRACK") {
5475
5477
  if (!isCourtyardLayer(shape.layer)) {
@@ -5481,12 +5483,22 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
5481
5483
  }
5482
5484
  } else if (shape.type === "TEXT") {
5483
5485
  if (isCourtyardLayer(shape.layer)) return;
5486
+ let text = shape.text;
5487
+ const designatorPrefix = easyEdaJson.dataStr.head.c_para.pre || "U";
5488
+ const normalizedPrefix = designatorPrefix.replace(/\?/g, "");
5489
+ const trimmedText = text.trim();
5490
+ const isDesignator = trimmedText === designatorPrefix || trimmedText === `${normalizedPrefix}?` || trimmedText === normalizedPrefix;
5491
+ if (isDesignator) {
5492
+ if (!showDesignator) return;
5493
+ text = "{NAME}";
5494
+ hasFoundDesignator = true;
5495
+ }
5484
5496
  circuitElements.push(
5485
5497
  pcb_silkscreen_text.parse({
5486
5498
  type: "pcb_silkscreen_text",
5487
5499
  pcb_silkscreen_text_id: `pcb_silkscreen_text_${index + 1}`,
5488
5500
  pcb_component_id: "pcb_component_1",
5489
- text: normalizeSymbolName(shape.text),
5501
+ text,
5490
5502
  anchor_position: {
5491
5503
  x: mil2mm(shape.x),
5492
5504
  y: mil2mm(shape.y)
@@ -5496,12 +5508,31 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
5496
5508
  C: "center",
5497
5509
  R: "bottom_right"
5498
5510
  }[shape.textAnchor ?? "L"],
5499
- font_size: shape.size_mm ? shape.size_mm : void 0,
5511
+ font_size: shape.size_mm || 1,
5500
5512
  layer: "top"
5501
5513
  })
5502
5514
  );
5503
5515
  }
5504
5516
  });
5517
+ if (!hasFoundDesignator && showDesignator) {
5518
+ const bbox = easyEdaJson.packageDetail.dataStr.BBox;
5519
+ circuitElements.push(
5520
+ pcb_silkscreen_text.parse({
5521
+ type: "pcb_silkscreen_text",
5522
+ pcb_silkscreen_text_id: `pcb_silkscreen_text_designator_fallback`,
5523
+ pcb_component_id: "pcb_component_1",
5524
+ text: "{NAME}",
5525
+ anchor_position: {
5526
+ x: milx10(bbox.x + bbox.width / 2),
5527
+ y: milx10(bbox.y) - 1
5528
+ // 1mm above top edge
5529
+ },
5530
+ anchor_alignment: "center",
5531
+ font_size: 1,
5532
+ layer: "top"
5533
+ })
5534
+ );
5535
+ }
5505
5536
  const pcbElements = circuitElements.filter(
5506
5537
  (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"
5507
5538
  );
@@ -6810,8 +6841,10 @@ var generateFootprintTsx = (circuitJson) => {
6810
6841
  );
6811
6842
  }
6812
6843
  for (const silkscreenText of silkscreenTexts) {
6844
+ const isRefDes = silkscreenText.text === "{NAME}";
6845
+ const textValue = isRefDes ? "{props.name}" : JSON.stringify(silkscreenText.text);
6813
6846
  elementStrings.push(
6814
- `<silkscreentext text="${silkscreenText.text}" pcbX="${mmStr(silkscreenText.anchor_position.x)}" pcbY="${mmStr(silkscreenText.anchor_position.y)}" anchorAlignment="${silkscreenText.anchor_alignment}" ${silkscreenText.font_size ? `fontSize="${mmStr(silkscreenText.font_size)}"` : ""} />`
6847
+ `<silkscreentext text=${textValue} pcbX="${mmStr(silkscreenText.anchor_position.x)}" pcbY="${mmStr(silkscreenText.anchor_position.y)}" anchorAlignment="${silkscreenText.anchor_alignment}" ${silkscreenText.font_size ? `fontSize="${mmStr(silkscreenText.font_size)}"` : ""} />`
6815
6848
  );
6816
6849
  }
6817
6850
  for (const courtyardOutline of courtyardOutlines) {
@@ -6895,7 +6928,8 @@ var convertBetterEasyToTsx = async ({
6895
6928
  shouldRecenter: true,
6896
6929
  cadPositionXMm: cadPlacement?.positionXMm,
6897
6930
  cadPositionYMm: cadPlacement?.positionYMm,
6898
- cadPositionZMm: cadPlacement?.positionZMm
6931
+ cadPositionZMm: cadPlacement?.positionZMm,
6932
+ showDesignator: true
6899
6933
  });
6900
6934
  const [cadComponent] = su(circuitJson).cad_component.list();
6901
6935
  if (cadComponent) {