easyeda 0.0.261 → 0.0.263

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 getPolarizedPortHintsMap = (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" || componentType === "led" ? { portHintsMap: getPolarizedPortHintsMap(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,50 @@ 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
+ }
10717
+ if (componentType === "led") {
10718
+ return `
10719
+ import type { LedProps } from "@tscircuit/props"
10720
+
10721
+ export const ${componentName} = (props: LedProps) => {
10722
+ const { name = "LED1", ...restProps } = props
10723
+
10724
+ return (
10725
+ <led
10726
+ name={name}
10727
+ supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
10728
+ manufacturerPartNumber="${manufacturerPartNumber}"
10729
+ footprint={${footprintTsx}}
10730
+ ${objUrl || stepUrl ? `cadModel={{
10731
+ ${cadModelLines}
10732
+ }}` : ""}
10733
+ {...restProps}
10734
+ />
10735
+ )
10736
+ }
10737
+ `.trim();
10738
+ }
10665
10739
  return `
10666
10740
  import type { ChipProps } from "@tscircuit/props"
10667
10741
 
@@ -10686,7 +10760,66 @@ ${cadModelLines}
10686
10760
  `.trim();
10687
10761
  };
10688
10762
 
10763
+ // lib/websafe/convert-to-typescript-component/category-value-contains-diode.ts
10764
+ var categoryValueContainsDiode = (value) => {
10765
+ if (typeof value === "string") {
10766
+ return /(^|[^a-z])diodes?([^a-z]|$)/i.test(value);
10767
+ }
10768
+ if (Array.isArray(value)) {
10769
+ return value.some(categoryValueContainsDiode);
10770
+ }
10771
+ if (value && typeof value === "object") {
10772
+ return Object.values(value).some(categoryValueContainsDiode);
10773
+ }
10774
+ return false;
10775
+ };
10776
+
10777
+ // lib/websafe/convert-to-typescript-component/is-diode-category-component.ts
10778
+ var isDiodeCategoryComponent = (betterEasy) => {
10779
+ const cPara = betterEasy.dataStr.head.c_para;
10780
+ return [
10781
+ betterEasy.tags,
10782
+ cPara.category,
10783
+ cPara.Category,
10784
+ cPara["LCSC Category"],
10785
+ cPara["JLCPCB Category"],
10786
+ betterEasy.category
10787
+ ].some(categoryValueContainsDiode);
10788
+ };
10789
+
10790
+ // lib/websafe/convert-to-typescript-component/category-value-contains-led.ts
10791
+ var categoryValueContainsLed = (value) => {
10792
+ if (typeof value === "string") {
10793
+ return /(^|[^a-z])leds?([^a-z]|$)/i.test(value) || /light[-\s]?emitting\s+diodes?/i.test(value);
10794
+ }
10795
+ if (Array.isArray(value)) {
10796
+ return value.some(categoryValueContainsLed);
10797
+ }
10798
+ if (value && typeof value === "object") {
10799
+ return Object.values(value).some(categoryValueContainsLed);
10800
+ }
10801
+ return false;
10802
+ };
10803
+
10804
+ // lib/websafe/convert-to-typescript-component/is-led-category-component.ts
10805
+ var isLedCategoryComponent = (betterEasy) => {
10806
+ const cPara = betterEasy.dataStr.head.c_para;
10807
+ return [
10808
+ betterEasy.tags,
10809
+ cPara.category,
10810
+ cPara.Category,
10811
+ cPara["LCSC Category"],
10812
+ cPara["JLCPCB Category"],
10813
+ betterEasy.category
10814
+ ].some(categoryValueContainsLed);
10815
+ };
10816
+
10689
10817
  // lib/websafe/convert-to-typescript-component/index.tsx
10818
+ var getGeneratedComponentType = (betterEasy) => {
10819
+ if (isLedCategoryComponent(betterEasy)) return "led";
10820
+ if (isDiodeCategoryComponent(betterEasy)) return "diode";
10821
+ return "chip";
10822
+ };
10690
10823
  var convertRawEasyToTsx = async ({ rawEasy }) => {
10691
10824
  const betterEasy = EasyEdaJsonSchema.parse(rawEasy);
10692
10825
  const result = await convertBetterEasyToTsx({
@@ -10750,7 +10883,8 @@ var convertBetterEasyToTsx = async ({
10750
10883
  objUrl: modelObjUrl,
10751
10884
  stepUrl: modelStepUrl,
10752
10885
  circuitJson,
10753
- supplierPartNumbers
10886
+ supplierPartNumbers,
10887
+ componentType: getGeneratedComponentType(betterEasy)
10754
10888
  });
10755
10889
  };
10756
10890
  var checkModelObjUrlValidity = async (url) => {