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.
package/dist/index.d.ts CHANGED
@@ -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?: {
package/dist/index.js CHANGED
@@ -6585,6 +6585,7 @@ var EasyEdaJsonSchema = z163.object({
6585
6585
  lcsc: LcscSchema,
6586
6586
  owner: OwnerSchema,
6587
6587
  tags: z163.array(z163.string()),
6588
+ category: z163.string().optional(),
6588
6589
  updateTime: z163.number(),
6589
6590
  updated_at: z163.string(),
6590
6591
  dataStr: DataStrSchema,
@@ -6801,7 +6802,11 @@ var getEasyEdaCadModelPlacement = async (easyEdaJson, { fetch: fetch2 = globalTh
6801
6802
  };
6802
6803
 
6803
6804
  // lib/websafe/generate-footprint-tsx.ts
6804
- var generateFootprintTsx = (circuitJson) => {
6805
+ var mapPortHints = (portHints, portHintsMap) => {
6806
+ if (!portHintsMap || !portHints) return portHints;
6807
+ return portHints.flatMap((hint) => portHintsMap[hint] ?? [hint]);
6808
+ };
6809
+ var generateFootprintTsx = (circuitJson, options = {}) => {
6805
6810
  const holes = su(circuitJson).pcb_hole.list();
6806
6811
  const platedHoles = su(circuitJson).pcb_plated_hole.list();
6807
6812
  const smtPads = su(circuitJson).pcb_smtpad.list();
@@ -6824,36 +6829,36 @@ var generateFootprintTsx = (circuitJson) => {
6824
6829
  const cccwRotationDegree = platedHole.ccw_rotation || 0;
6825
6830
  const rotation2 = cccwRotationDegree ? ` pcbRotation="${cccwRotationDegree}deg"` : "";
6826
6831
  elementStrings.push(
6827
- `<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}" />`
6832
+ `<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}" />`
6828
6833
  );
6829
6834
  } else if (platedHole.shape === "pill_hole_with_rect_pad") {
6830
6835
  elementStrings.push(
6831
- `<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" />`
6836
+ `<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" />`
6832
6837
  );
6833
6838
  } else if (platedHole.shape === "circle") {
6834
6839
  elementStrings.push(
6835
- `<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" />`
6840
+ `<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" />`
6836
6841
  );
6837
6842
  } else if (platedHole.shape === "rotated_pill_hole_with_rect_pad") {
6838
6843
  const rotation2 = platedHole.hole_ccw_rotation || 0;
6839
6844
  elementStrings.push(
6840
- `<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" />`
6845
+ `<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" />`
6841
6846
  );
6842
6847
  }
6843
6848
  }
6844
6849
  for (const smtPad of smtPads) {
6845
6850
  if (smtPad.shape === "circle") {
6846
6851
  elementStrings.push(
6847
- `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" radius="${mmStr(smtPad.radius)}" shape="circle" />`
6852
+ `<smtpad portHints={${JSON.stringify(mapPortHints(smtPad.port_hints, options.portHintsMap))}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" radius="${mmStr(smtPad.radius)}" shape="circle" />`
6848
6853
  );
6849
6854
  } else if (smtPad.shape === "rect") {
6850
6855
  elementStrings.push(
6851
- `<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" />`
6856
+ `<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" />`
6852
6857
  );
6853
6858
  } else if (smtPad.shape === "polygon") {
6854
6859
  const pointsStr = smtPad.points.map((p) => `{x: "${mmStr(p.x)}", y: "${mmStr(p.y)}"}`).join(", ");
6855
6860
  elementStrings.push(
6856
- `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} points={[${pointsStr}]} shape="polygon" />`
6861
+ `<smtpad portHints={${JSON.stringify(mapPortHints(smtPad.port_hints, options.portHintsMap))}} points={[${pointsStr}]} shape="polygon" />`
6857
6862
  );
6858
6863
  }
6859
6864
  }
@@ -6887,6 +6892,27 @@ var generateFootprintTsx = (circuitJson) => {
6887
6892
  };
6888
6893
 
6889
6894
  // lib/websafe/convert-to-typescript-component/generate-typescript-component.ts
6895
+ var getPinLabelValues = (labels) => {
6896
+ if (typeof labels === "string") return [labels];
6897
+ return [...labels];
6898
+ };
6899
+ var getDiodePortHintsMap = (pinLabels) => {
6900
+ const labelsByPin = Object.entries(pinLabels ?? {}).map(([pin, labels]) => ({
6901
+ pin,
6902
+ labels: getPinLabelValues(labels).map((label) => label.toLowerCase())
6903
+ }));
6904
+ const anodePin = labelsByPin.find(
6905
+ ({ labels }) => labels.some((label) => ["a", "anode", "pos", "+"].includes(label))
6906
+ )?.pin;
6907
+ const cathodePin = labelsByPin.find(
6908
+ ({ labels }) => labels.some((label) => ["c", "k", "cathode", "neg", "-"].includes(label))
6909
+ )?.pin;
6910
+ if (!anodePin || !cathodePin) return void 0;
6911
+ return {
6912
+ [anodePin]: ["pin1", "anode"],
6913
+ [cathodePin]: ["pin2", "cathode"]
6914
+ };
6915
+ };
6890
6916
  var generateTypescriptComponent = ({
6891
6917
  pinLabels,
6892
6918
  componentName,
@@ -6894,11 +6920,15 @@ var generateTypescriptComponent = ({
6894
6920
  stepUrl,
6895
6921
  circuitJson,
6896
6922
  supplierPartNumbers,
6897
- manufacturerPartNumber
6923
+ manufacturerPartNumber,
6924
+ componentType = "chip"
6898
6925
  }) => {
6899
6926
  const safePinLabels = pinLabels ?? {};
6900
6927
  const cadComponent = circuitJson.find((item) => item.type === "cad_component");
6901
- const footprintTsx = generateFootprintTsx(circuitJson);
6928
+ const footprintTsx = generateFootprintTsx(
6929
+ circuitJson,
6930
+ componentType === "diode" ? { portHintsMap: getDiodePortHintsMap(safePinLabels) } : void 0
6931
+ );
6902
6932
  const simplifiedPinLabels = Object.fromEntries(
6903
6933
  Object.entries(safePinLabels).map(([pin, labels]) => {
6904
6934
  if (Array.isArray(labels) && labels.length > 1) {
@@ -6914,6 +6944,28 @@ var generateTypescriptComponent = ({
6914
6944
  `pcbRotationOffset: ${cadComponent?.rotation?.z ?? 0},`,
6915
6945
  `modelOriginPosition: { x: ${cadComponent?.model_origin_position?.x ?? 0}, y: ${cadComponent?.model_origin_position?.y ?? 0}, z: ${cadComponent?.model_origin_position?.z ?? 0} },`
6916
6946
  ].filter(Boolean).map((line) => ` ${line}`).join("\n");
6947
+ if (componentType === "diode") {
6948
+ return `
6949
+ import type { DiodeProps } from "@tscircuit/props"
6950
+
6951
+ export const ${componentName} = (props: DiodeProps) => {
6952
+ const { name = "D1", ...restProps } = props
6953
+
6954
+ return (
6955
+ <diode
6956
+ name={name}
6957
+ supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
6958
+ manufacturerPartNumber="${manufacturerPartNumber}"
6959
+ footprint={${footprintTsx}}
6960
+ ${objUrl || stepUrl ? `cadModel={{
6961
+ ${cadModelLines}
6962
+ }}` : ""}
6963
+ {...restProps}
6964
+ />
6965
+ )
6966
+ }
6967
+ `.trim();
6968
+ }
6917
6969
  return `
6918
6970
  import type { ChipProps } from "@tscircuit/props"
6919
6971
 
@@ -6938,6 +6990,33 @@ ${cadModelLines}
6938
6990
  `.trim();
6939
6991
  };
6940
6992
 
6993
+ // lib/websafe/convert-to-typescript-component/category-value-contains-diode.ts
6994
+ var categoryValueContainsDiode = (value) => {
6995
+ if (typeof value === "string") {
6996
+ return /(^|[^a-z])diodes?([^a-z]|$)/i.test(value);
6997
+ }
6998
+ if (Array.isArray(value)) {
6999
+ return value.some(categoryValueContainsDiode);
7000
+ }
7001
+ if (value && typeof value === "object") {
7002
+ return Object.values(value).some(categoryValueContainsDiode);
7003
+ }
7004
+ return false;
7005
+ };
7006
+
7007
+ // lib/websafe/convert-to-typescript-component/is-diode-category-component.ts
7008
+ var isDiodeCategoryComponent = (betterEasy) => {
7009
+ const cPara = betterEasy.dataStr.head.c_para;
7010
+ return [
7011
+ betterEasy.tags,
7012
+ cPara.category,
7013
+ cPara.Category,
7014
+ cPara["LCSC Category"],
7015
+ cPara["JLCPCB Category"],
7016
+ betterEasy.category
7017
+ ].some(categoryValueContainsDiode);
7018
+ };
7019
+
6941
7020
  // lib/websafe/convert-to-typescript-component/index.tsx
6942
7021
  var convertRawEasyToTsx = async ({ rawEasy }) => {
6943
7022
  const betterEasy = EasyEdaJsonSchema.parse(rawEasy);
@@ -7002,7 +7081,8 @@ var convertBetterEasyToTsx = async ({
7002
7081
  objUrl: modelObjUrl,
7003
7082
  stepUrl: modelStepUrl,
7004
7083
  circuitJson,
7005
- supplierPartNumbers
7084
+ supplierPartNumbers,
7085
+ componentType: isDiodeCategoryComponent(betterEasy) ? "diode" : "chip"
7006
7086
  });
7007
7087
  };
7008
7088
  var checkModelObjUrlValidity = async (url) => {