easyeda 0.0.260 → 0.0.262

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.
@@ -2690,6 +2690,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
2690
2690
  avatar: string;
2691
2691
  }>;
2692
2692
  tags: z.ZodArray<z.ZodString, "many">;
2693
+ category: z.ZodOptional<z.ZodString>;
2693
2694
  updateTime: z.ZodNumber;
2694
2695
  updated_at: z.ZodString;
2695
2696
  dataStr: z.ZodObject<{
@@ -4720,6 +4721,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
4720
4721
  netColors?: unknown[] | undefined;
4721
4722
  };
4722
4723
  };
4724
+ category?: string | undefined;
4723
4725
  SMT?: boolean | undefined;
4724
4726
  jlcOnSale?: number | undefined;
4725
4727
  _objMetadata?: {
@@ -4838,6 +4840,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
4838
4840
  netColors?: unknown[] | undefined;
4839
4841
  };
4840
4842
  };
4843
+ category?: string | undefined;
4841
4844
  SMT?: boolean | undefined;
4842
4845
  jlcOnSale?: number | undefined;
4843
4846
  _objMetadata?: {
@@ -4870,7 +4873,10 @@ declare function fetchEasyEDAComponent(jlcpcbPartNumber: string, { fetch, includ
4870
4873
  includeModelMetadata?: boolean;
4871
4874
  }): Promise<RawEasyEdaJson>;
4872
4875
 
4873
- declare const generateFootprintTsx: (circuitJson: AnyCircuitElement[]) => string;
4876
+ interface GenerateFootprintTsxOptions {
4877
+ portHintsMap?: Record<string, string[]>;
4878
+ }
4879
+ declare const generateFootprintTsx: (circuitJson: AnyCircuitElement[], options?: GenerateFootprintTsxOptions) => string;
4874
4880
 
4875
4881
  type Params = {
4876
4882
  easyedaPartNumber: string;
@@ -10318,6 +10318,7 @@ var EasyEdaJsonSchema = external_exports.object({
10318
10318
  lcsc: LcscSchema,
10319
10319
  owner: OwnerSchema,
10320
10320
  tags: external_exports.array(external_exports.string()),
10321
+ category: external_exports.string().optional(),
10321
10322
  updateTime: external_exports.number(),
10322
10323
  updated_at: external_exports.string(),
10323
10324
  dataStr: DataStrSchema,
@@ -10549,7 +10550,11 @@ var getEasyEdaCadModelPlacement = async (easyEdaJson, { fetch: fetch2 = globalTh
10549
10550
  };
10550
10551
 
10551
10552
  // lib/websafe/generate-footprint-tsx.ts
10552
- var generateFootprintTsx = (circuitJson) => {
10553
+ var mapPortHints = (portHints, portHintsMap) => {
10554
+ if (!portHintsMap || !portHints) return portHints;
10555
+ return portHints.flatMap((hint) => portHintsMap[hint] ?? [hint]);
10556
+ };
10557
+ var generateFootprintTsx = (circuitJson, options = {}) => {
10553
10558
  const holes = su(circuitJson).pcb_hole.list();
10554
10559
  const platedHoles = su(circuitJson).pcb_plated_hole.list();
10555
10560
  const smtPads = su(circuitJson).pcb_smtpad.list();
@@ -10572,36 +10577,36 @@ var generateFootprintTsx = (circuitJson) => {
10572
10577
  const cccwRotationDegree = platedHole.ccw_rotation || 0;
10573
10578
  const rotation2 = cccwRotationDegree ? ` pcbRotation="${cccwRotationDegree}deg"` : "";
10574
10579
  elementStrings.push(
10575
- `<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" holeWidth="${mmStr(platedHole.hole_width)}" holeHeight="${mmStr(platedHole.hole_height)}" outerWidth="${mmStr(platedHole.outer_width)}" outerHeight="${mmStr(platedHole.outer_height)}"${rotation2} shape="${platedHole.shape}" />`
10580
+ `<platedhole portHints={${JSON.stringify(mapPortHints(platedHole.port_hints, options.portHintsMap))}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" holeWidth="${mmStr(platedHole.hole_width)}" holeHeight="${mmStr(platedHole.hole_height)}" outerWidth="${mmStr(platedHole.outer_width)}" outerHeight="${mmStr(platedHole.outer_height)}"${rotation2} shape="${platedHole.shape}" />`
10576
10581
  );
10577
10582
  } else if (platedHole.shape === "pill_hole_with_rect_pad") {
10578
10583
  elementStrings.push(
10579
- `<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" holeWidth="${mmStr(platedHole.hole_width)}" holeHeight="${mmStr(platedHole.hole_height)}" outerWidth="${mmStr(platedHole.rect_pad_width)}" outerHeight="${mmStr(platedHole.rect_pad_height)}" shape="pill" />`
10584
+ `<platedhole portHints={${JSON.stringify(mapPortHints(platedHole.port_hints, options.portHintsMap))}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" holeWidth="${mmStr(platedHole.hole_width)}" holeHeight="${mmStr(platedHole.hole_height)}" outerWidth="${mmStr(platedHole.rect_pad_width)}" outerHeight="${mmStr(platedHole.rect_pad_height)}" shape="pill" />`
10580
10585
  );
10581
10586
  } else if (platedHole.shape === "circle") {
10582
10587
  elementStrings.push(
10583
- `<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" outerDiameter="${mmStr(platedHole.outer_diameter)}" holeDiameter="${mmStr(platedHole.hole_diameter)}" shape="circle" />`
10588
+ `<platedhole portHints={${JSON.stringify(mapPortHints(platedHole.port_hints, options.portHintsMap))}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" outerDiameter="${mmStr(platedHole.outer_diameter)}" holeDiameter="${mmStr(platedHole.hole_diameter)}" shape="circle" />`
10584
10589
  );
10585
10590
  } else if (platedHole.shape === "rotated_pill_hole_with_rect_pad") {
10586
10591
  const rotation2 = platedHole.hole_ccw_rotation || 0;
10587
10592
  elementStrings.push(
10588
- `<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" holeWidth="${mmStr(platedHole.hole_width)}" holeHeight="${mmStr(platedHole.hole_height)}" outerWidth="${mmStr(platedHole.rect_pad_width)}" outerHeight="${mmStr(platedHole.rect_pad_height)}" rectPad={true} pcbRotation="${rotation2}deg" shape="pill" />`
10593
+ `<platedhole portHints={${JSON.stringify(mapPortHints(platedHole.port_hints, options.portHintsMap))}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" holeWidth="${mmStr(platedHole.hole_width)}" holeHeight="${mmStr(platedHole.hole_height)}" outerWidth="${mmStr(platedHole.rect_pad_width)}" outerHeight="${mmStr(platedHole.rect_pad_height)}" rectPad={true} pcbRotation="${rotation2}deg" shape="pill" />`
10589
10594
  );
10590
10595
  }
10591
10596
  }
10592
10597
  for (const smtPad of smtPads) {
10593
10598
  if (smtPad.shape === "circle") {
10594
10599
  elementStrings.push(
10595
- `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" radius="${mmStr(smtPad.radius)}" shape="circle" />`
10600
+ `<smtpad portHints={${JSON.stringify(mapPortHints(smtPad.port_hints, options.portHintsMap))}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" radius="${mmStr(smtPad.radius)}" shape="circle" />`
10596
10601
  );
10597
10602
  } else if (smtPad.shape === "rect") {
10598
10603
  elementStrings.push(
10599
- `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}" shape="rect" />`
10604
+ `<smtpad portHints={${JSON.stringify(mapPortHints(smtPad.port_hints, options.portHintsMap))}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}" shape="rect" />`
10600
10605
  );
10601
10606
  } else if (smtPad.shape === "polygon") {
10602
10607
  const pointsStr = smtPad.points.map((p) => `{x: "${mmStr(p.x)}", y: "${mmStr(p.y)}"}`).join(", ");
10603
10608
  elementStrings.push(
10604
- `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} points={[${pointsStr}]} shape="polygon" />`
10609
+ `<smtpad portHints={${JSON.stringify(mapPortHints(smtPad.port_hints, options.portHintsMap))}} points={[${pointsStr}]} shape="polygon" />`
10605
10610
  );
10606
10611
  }
10607
10612
  }
@@ -10635,6 +10640,27 @@ var generateFootprintTsx = (circuitJson) => {
10635
10640
  };
10636
10641
 
10637
10642
  // lib/websafe/convert-to-typescript-component/generate-typescript-component.ts
10643
+ var getPinLabelValues = (labels) => {
10644
+ if (typeof labels === "string") return [labels];
10645
+ return [...labels];
10646
+ };
10647
+ var getDiodePortHintsMap = (pinLabels) => {
10648
+ const labelsByPin = Object.entries(pinLabels ?? {}).map(([pin, labels]) => ({
10649
+ pin,
10650
+ labels: getPinLabelValues(labels).map((label) => label.toLowerCase())
10651
+ }));
10652
+ const anodePin = labelsByPin.find(
10653
+ ({ labels }) => labels.some((label) => ["a", "anode", "pos", "+"].includes(label))
10654
+ )?.pin;
10655
+ const cathodePin = labelsByPin.find(
10656
+ ({ labels }) => labels.some((label) => ["c", "k", "cathode", "neg", "-"].includes(label))
10657
+ )?.pin;
10658
+ if (!anodePin || !cathodePin) return void 0;
10659
+ return {
10660
+ [anodePin]: ["pin1", "anode"],
10661
+ [cathodePin]: ["pin2", "cathode"]
10662
+ };
10663
+ };
10638
10664
  var generateTypescriptComponent = ({
10639
10665
  pinLabels,
10640
10666
  componentName,
@@ -10642,11 +10668,15 @@ var generateTypescriptComponent = ({
10642
10668
  stepUrl,
10643
10669
  circuitJson,
10644
10670
  supplierPartNumbers,
10645
- manufacturerPartNumber
10671
+ manufacturerPartNumber,
10672
+ componentType = "chip"
10646
10673
  }) => {
10647
10674
  const safePinLabels = pinLabels ?? {};
10648
10675
  const cadComponent = circuitJson.find((item) => item.type === "cad_component");
10649
- const footprintTsx = generateFootprintTsx(circuitJson);
10676
+ const footprintTsx = generateFootprintTsx(
10677
+ circuitJson,
10678
+ componentType === "diode" ? { portHintsMap: getDiodePortHintsMap(safePinLabels) } : void 0
10679
+ );
10650
10680
  const simplifiedPinLabels = Object.fromEntries(
10651
10681
  Object.entries(safePinLabels).map(([pin, labels]) => {
10652
10682
  if (Array.isArray(labels) && labels.length > 1) {
@@ -10662,6 +10692,28 @@ var generateTypescriptComponent = ({
10662
10692
  `pcbRotationOffset: ${cadComponent?.rotation?.z ?? 0},`,
10663
10693
  `modelOriginPosition: { x: ${cadComponent?.model_origin_position?.x ?? 0}, y: ${cadComponent?.model_origin_position?.y ?? 0}, z: ${cadComponent?.model_origin_position?.z ?? 0} },`
10664
10694
  ].filter(Boolean).map((line) => ` ${line}`).join("\n");
10695
+ if (componentType === "diode") {
10696
+ return `
10697
+ import type { DiodeProps } from "@tscircuit/props"
10698
+
10699
+ export const ${componentName} = (props: DiodeProps) => {
10700
+ const { name = "D1", ...restProps } = props
10701
+
10702
+ return (
10703
+ <diode
10704
+ name={name}
10705
+ supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
10706
+ manufacturerPartNumber="${manufacturerPartNumber}"
10707
+ footprint={${footprintTsx}}
10708
+ ${objUrl || stepUrl ? `cadModel={{
10709
+ ${cadModelLines}
10710
+ }}` : ""}
10711
+ {...restProps}
10712
+ />
10713
+ )
10714
+ }
10715
+ `.trim();
10716
+ }
10665
10717
  return `
10666
10718
  import type { ChipProps } from "@tscircuit/props"
10667
10719
 
@@ -10686,6 +10738,33 @@ ${cadModelLines}
10686
10738
  `.trim();
10687
10739
  };
10688
10740
 
10741
+ // lib/websafe/convert-to-typescript-component/category-value-contains-diode.ts
10742
+ var categoryValueContainsDiode = (value) => {
10743
+ if (typeof value === "string") {
10744
+ return /(^|[^a-z])diodes?([^a-z]|$)/i.test(value);
10745
+ }
10746
+ if (Array.isArray(value)) {
10747
+ return value.some(categoryValueContainsDiode);
10748
+ }
10749
+ if (value && typeof value === "object") {
10750
+ return Object.values(value).some(categoryValueContainsDiode);
10751
+ }
10752
+ return false;
10753
+ };
10754
+
10755
+ // lib/websafe/convert-to-typescript-component/is-diode-category-component.ts
10756
+ var isDiodeCategoryComponent = (betterEasy) => {
10757
+ const cPara = betterEasy.dataStr.head.c_para;
10758
+ return [
10759
+ betterEasy.tags,
10760
+ cPara.category,
10761
+ cPara.Category,
10762
+ cPara["LCSC Category"],
10763
+ cPara["JLCPCB Category"],
10764
+ betterEasy.category
10765
+ ].some(categoryValueContainsDiode);
10766
+ };
10767
+
10689
10768
  // lib/websafe/convert-to-typescript-component/index.tsx
10690
10769
  var convertRawEasyToTsx = async ({ rawEasy }) => {
10691
10770
  const betterEasy = EasyEdaJsonSchema.parse(rawEasy);
@@ -10750,7 +10829,8 @@ var convertBetterEasyToTsx = async ({
10750
10829
  objUrl: modelObjUrl,
10751
10830
  stepUrl: modelStepUrl,
10752
10831
  circuitJson,
10753
- supplierPartNumbers
10832
+ supplierPartNumbers,
10833
+ componentType: isDiodeCategoryComponent(betterEasy) ? "diode" : "chip"
10754
10834
  });
10755
10835
  };
10756
10836
  var checkModelObjUrlValidity = async (url) => {