easyeda 0.0.294 → 0.0.296

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.js CHANGED
@@ -7755,6 +7755,8 @@ var generateTypescriptComponent = ({
7755
7755
  supplierPartNumbers,
7756
7756
  manufacturerPartNumber,
7757
7757
  componentType = "chip",
7758
+ capacitance: capacitance2,
7759
+ resistance: resistance2,
7758
7760
  inductance: inductance2,
7759
7761
  crystalFrequency,
7760
7762
  crystalPinVariant,
@@ -7892,6 +7894,58 @@ ${cadModelLines}
7892
7894
  />
7893
7895
  )
7894
7896
  }
7897
+ `.trim();
7898
+ }
7899
+ if (componentType === "capacitor") {
7900
+ if (!capacitance2) {
7901
+ throw new Error("Capacitance is required for capacitor components");
7902
+ }
7903
+ return `
7904
+ import type { CapacitorProps } from "@tscircuit/props"
7905
+
7906
+ export const ${componentName} = (props: Omit<CapacitorProps, "capacitance">) => {
7907
+ const { name = "C1", ...restProps } = props
7908
+
7909
+ return (
7910
+ <capacitor
7911
+ name={name}
7912
+ capacitance=${JSON.stringify(capacitance2)}
7913
+ supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
7914
+ manufacturerPartNumber="${manufacturerPartNumber}"
7915
+ footprint={${footprintTsx}}
7916
+ ${objUrl || stepUrl ? `cadModel={{
7917
+ ${cadModelLines}
7918
+ }}` : ""}
7919
+ {...restProps}
7920
+ />
7921
+ )
7922
+ }
7923
+ `.trim();
7924
+ }
7925
+ if (componentType === "resistor") {
7926
+ if (!resistance2) {
7927
+ throw new Error("Resistance is required for resistor components");
7928
+ }
7929
+ return `
7930
+ import type { ResistorProps } from "@tscircuit/props"
7931
+
7932
+ export const ${componentName} = (props: Omit<ResistorProps, "resistance">) => {
7933
+ const { name = "R1", ...restProps } = props
7934
+
7935
+ return (
7936
+ <resistor
7937
+ name={name}
7938
+ resistance=${JSON.stringify(resistance2)}
7939
+ supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
7940
+ manufacturerPartNumber="${manufacturerPartNumber}"
7941
+ footprint={${footprintTsx}}
7942
+ ${objUrl || stepUrl ? `cadModel={{
7943
+ ${cadModelLines}
7944
+ }}` : ""}
7945
+ {...restProps}
7946
+ />
7947
+ )
7948
+ }
7895
7949
  `.trim();
7896
7950
  }
7897
7951
  if (componentType === "inductor") {
@@ -7994,6 +8048,21 @@ ${cadModelLines}
7994
8048
  `.trim();
7995
8049
  };
7996
8050
 
8051
+ // lib/websafe/convert-to-typescript-component/is-capacitor-component.ts
8052
+ var capacitancePattern = /^\d+(?:\.\d+)?\s*(?:pF|nF|[uµμ]F|mF|F)$/i;
8053
+ var normalizeCapacitanceValue = (value) => {
8054
+ if (typeof value !== "string") return void 0;
8055
+ const trimmedValue = value.trim();
8056
+ if (!capacitancePattern.test(trimmedValue)) return void 0;
8057
+ return trimmedValue.replace(/\s+/g, "").replace(/[µμ]/g, "u");
8058
+ };
8059
+ var isCapacitorComponent = (betterEasy) => {
8060
+ const componentParameters = betterEasy.dataStr.head.c_para;
8061
+ const prefix = componentParameters.pre;
8062
+ const value = componentParameters.Value;
8063
+ return prefix?.toUpperCase() === "C?" && normalizeCapacitanceValue(value) !== void 0;
8064
+ };
8065
+
7997
8066
  // lib/websafe/convert-to-typescript-component/is-crystal-component.ts
7998
8067
  var frequencyPattern = /^\d+(?:\.\d+)?\s*(?:Hz|kHz|MHz|GHz)$/i;
7999
8068
  var isCrystalComponent = (betterEasy) => {
@@ -8049,6 +8118,43 @@ var isPushbuttonCategoryComponent = (betterEasy) => {
8049
8118
  ].some(categoryValueContainsPushbutton);
8050
8119
  };
8051
8120
 
8121
+ // lib/websafe/convert-to-typescript-component/is-resistor-component.ts
8122
+ var standardSmdResistorPackagePattern = /^R(?:01005|0201|0402|0504|0603|0805|1206|1210|1812|2010|2512)(?:$|[_-])/i;
8123
+ var normalizeExplicitScale = (scale2) => {
8124
+ if (scale2 === "k" || scale2 === "K") return "k";
8125
+ if (scale2 === "m") return "m";
8126
+ if (scale2 === "M") return "M";
8127
+ if (scale2 === "g" || scale2 === "G") return "G";
8128
+ return "";
8129
+ };
8130
+ var normalizeResistorValue = (value) => {
8131
+ if (typeof value !== "string") return void 0;
8132
+ const compactValue = value.trim().replace(/\s+/g, "");
8133
+ const explicitUnitMatch = compactValue.match(
8134
+ /^(\d+(?:\.\d+)?)([mMkKgG]?)(?:Ω|ohms?)$/i
8135
+ );
8136
+ if (explicitUnitMatch) {
8137
+ const [, magnitude, scale2] = explicitUnitMatch;
8138
+ if (Number(magnitude) === 0) return "0ohm";
8139
+ return `${magnitude}${normalizeExplicitScale(scale2)}ohm`;
8140
+ }
8141
+ const resistorCodeMatch = compactValue.match(/^(\d+)([RrKkMm])(\d*)$/);
8142
+ if (resistorCodeMatch) {
8143
+ const [, whole, multiplier, fraction] = resistorCodeMatch;
8144
+ const magnitude = fraction ? `${whole}.${fraction}` : whole;
8145
+ if (Number(magnitude) === 0) return "0ohm";
8146
+ const scale2 = multiplier === "R" || multiplier === "r" ? "" : multiplier === "K" || multiplier === "k" ? "k" : "M";
8147
+ return `${magnitude}${scale2}ohm`;
8148
+ }
8149
+ if (/^0+(?:\.0+)?$/.test(compactValue)) return "0ohm";
8150
+ return void 0;
8151
+ };
8152
+ var isResistorComponent = (betterEasy) => {
8153
+ const componentParameters = betterEasy.dataStr.head.c_para;
8154
+ const packageName = componentParameters.package;
8155
+ return componentParameters.pre?.toUpperCase() === "R?" && typeof packageName === "string" && standardSmdResistorPackagePattern.test(packageName.trim()) && normalizeResistorValue(componentParameters.Value) !== void 0;
8156
+ };
8157
+
8052
8158
  // lib/websafe/convert-to-typescript-component/category-value-contains-switch.ts
8053
8159
  var categoryValueContainsSwitch = (value) => {
8054
8160
  if (typeof value === "string") {
@@ -8386,6 +8492,8 @@ var getGeneratedComponentType = (betterEasy, pinCount) => {
8386
8492
  if (isDiodeCategoryComponent(betterEasy) && pinCount === 2) return "diode";
8387
8493
  if (isPushbuttonCategoryComponent(betterEasy)) return "pushbutton";
8388
8494
  if (isSwitchCategoryComponent(betterEasy)) return "switch";
8495
+ if (isCapacitorComponent(betterEasy)) return "capacitor";
8496
+ if (isResistorComponent(betterEasy) && pinCount === 2) return "resistor";
8389
8497
  if (isInductorComponent(betterEasy)) return "inductor";
8390
8498
  if (isCrystalComponent(betterEasy)) return "crystal";
8391
8499
  if (isMicroUsbConnectorComponent(betterEasy)) return "connector";
@@ -8458,6 +8566,8 @@ var convertBetterEasyToTsx = async ({
8458
8566
  sourcePorts.length
8459
8567
  );
8460
8568
  const inductance2 = componentType === "inductor" ? betterEasy.dataStr.head.c_para.Value?.trim() : void 0;
8569
+ const capacitance2 = componentType === "capacitor" ? normalizeCapacitanceValue(betterEasy.dataStr.head.c_para.Value) : void 0;
8570
+ const resistance2 = componentType === "resistor" ? normalizeResistorValue(betterEasy.dataStr.head.c_para.Value) : void 0;
8461
8571
  const crystalFrequency = componentType === "crystal" ? betterEasy.dataStr.head.c_para.Value?.trim() : void 0;
8462
8572
  const crystalPinVariant = componentType !== "crystal" ? void 0 : sourcePorts.length === 4 ? "four_pin" : sourcePorts.length === 2 ? "two_pin" : void 0;
8463
8573
  const isMultiPinDiode = isDiodeCategoryComponent(betterEasy) && sourcePorts.length !== 2;
@@ -8471,6 +8581,8 @@ var convertBetterEasyToTsx = async ({
8471
8581
  circuitJson,
8472
8582
  supplierPartNumbers,
8473
8583
  componentType,
8584
+ capacitance: capacitance2,
8585
+ resistance: resistance2,
8474
8586
  inductance: inductance2,
8475
8587
  crystalFrequency,
8476
8588
  crystalPinVariant,