easyeda 0.0.278 → 0.0.279

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
@@ -5634,6 +5634,9 @@ var mil2mm = (mil) => {
5634
5634
  return mm(mil);
5635
5635
  };
5636
5636
 
5637
+ // lib/constants.ts
5638
+ var DEFAULT_PCB_THICKNESS_MM = 1.6;
5639
+
5637
5640
  // lib/math/arc-utils.ts
5638
5641
  function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag, sweepFlag) {
5639
5642
  const start = { x: startX, y: startY };
@@ -5682,6 +5685,173 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
5682
5685
  // lib/utils/easyeda-unit-to-mm.ts
5683
5686
  var mil10ToMm = (value) => value * 10 * 0.0254;
5684
5687
 
5688
+ // lib/utils/get-polarized-pin-metadata.ts
5689
+ var getPinLabelValues = (labels) => {
5690
+ if (typeof labels === "string") return [labels];
5691
+ return [...labels];
5692
+ };
5693
+ var stripEasyEdaPolarityHintDecoration = (label) => label.toLowerCase().replace(/[^a-z0-9+-]/g, "");
5694
+ var getPinKeySortValue = (pinKey) => {
5695
+ const match = /^pin(\d+)$/i.exec(pinKey);
5696
+ return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;
5697
+ };
5698
+ var getPolarizedPinMetadata = (pinLabels) => {
5699
+ const labelsByPin = Object.entries(pinLabels).map(([pin, labels]) => ({
5700
+ pin,
5701
+ labels: getPinLabelValues(labels).map(stripEasyEdaPolarityHintDecoration)
5702
+ }));
5703
+ const anodePin = labelsByPin.find(
5704
+ ({ labels }) => labels.some((label) => ["a", "anode", "pos", "+"].includes(label))
5705
+ )?.pin;
5706
+ const cathodePin = labelsByPin.find(
5707
+ ({ labels }) => labels.some((label) => ["c", "k", "cathode", "neg", "-"].includes(label))
5708
+ )?.pin;
5709
+ if (!anodePin || !cathodePin || anodePin === cathodePin) return void 0;
5710
+ const polarizedPinEntries = [
5711
+ [anodePin, ["anode", "pos"]],
5712
+ [cathodePin, ["cathode", "neg"]]
5713
+ ].sort(
5714
+ ([pinA], [pinB]) => getPinKeySortValue(pinA) - getPinKeySortValue(pinB)
5715
+ );
5716
+ return {
5717
+ portHintsMap: Object.fromEntries(
5718
+ polarizedPinEntries.map(([pin, labels]) => [pin, [pin, ...labels]])
5719
+ ),
5720
+ pinLabels: Object.fromEntries(polarizedPinEntries)
5721
+ };
5722
+ };
5723
+
5724
+ // lib/utils/normalize-pin-labels.ts
5725
+ var normalizePinLabels = (inputPinLabels) => {
5726
+ const uniqueInputPinLabels = inputPinLabels.map((labels) => [
5727
+ ...new Set(labels)
5728
+ ]);
5729
+ const result = uniqueInputPinLabels.map(() => []);
5730
+ const desiredNumbers = uniqueInputPinLabels.map(() => null);
5731
+ for (let i = 0; i < uniqueInputPinLabels.length; i++) {
5732
+ for (const label of uniqueInputPinLabels[i]) {
5733
+ if (/^\d+$/.test(label)) {
5734
+ desiredNumbers[i] = Number.parseInt(label);
5735
+ break;
5736
+ }
5737
+ }
5738
+ }
5739
+ let highestPinNumber = 0;
5740
+ const acceptedDesiredNumbers = /* @__PURE__ */ new Set();
5741
+ for (let i = 0; i < desiredNumbers.length; i++) {
5742
+ const desiredNumber = desiredNumbers[i];
5743
+ if (desiredNumber === null || desiredNumber < 1) continue;
5744
+ if (!acceptedDesiredNumbers.has(desiredNumber)) {
5745
+ acceptedDesiredNumbers.add(desiredNumber);
5746
+ result[i].push(`pin${desiredNumber}`);
5747
+ highestPinNumber = Math.max(highestPinNumber, desiredNumber);
5748
+ continue;
5749
+ }
5750
+ let existingAltCount = 0;
5751
+ for (const label of result[i]) {
5752
+ if (label.startsWith(`pin${desiredNumber}_alt`)) {
5753
+ existingAltCount += 1;
5754
+ }
5755
+ }
5756
+ result[i].push(`pin${desiredNumber}_alt${existingAltCount + 1}`);
5757
+ }
5758
+ for (let i = 0; i < result.length; i++) {
5759
+ const firstLabel = result[i][0];
5760
+ if (firstLabel?.includes("_alt")) {
5761
+ highestPinNumber += 1;
5762
+ result[i].unshift(`pin${highestPinNumber}`);
5763
+ }
5764
+ }
5765
+ for (let i = 0; i < result.length; i++) {
5766
+ if (result[i].length === 0) {
5767
+ highestPinNumber += 1;
5768
+ result[i].push(`pin${highestPinNumber}`);
5769
+ }
5770
+ }
5771
+ const totalLabelCounts = {};
5772
+ for (const inputLabels of uniqueInputPinLabels) {
5773
+ for (const label of inputLabels) {
5774
+ if (/^\d+$/.test(label)) continue;
5775
+ totalLabelCounts[label] = (totalLabelCounts[label] ?? 0) + 1;
5776
+ }
5777
+ }
5778
+ const incrementalLabelCounts = {};
5779
+ for (let i = 0; i < uniqueInputPinLabels.length; i++) {
5780
+ for (const label of uniqueInputPinLabels[i]) {
5781
+ if (/^\d+$/.test(label)) continue;
5782
+ if (totalLabelCounts[label] === 1) {
5783
+ result[i].push(label);
5784
+ } else {
5785
+ incrementalLabelCounts[label] = (incrementalLabelCounts[label] ?? 0) + 1;
5786
+ result[i].push(`${label}${incrementalLabelCounts[label]}`);
5787
+ }
5788
+ }
5789
+ }
5790
+ return result;
5791
+ };
5792
+
5793
+ // lib/utils/normalize-symbol-name.ts
5794
+ var normalizeSymbolName = (name) => {
5795
+ const trimmedName = name.trim();
5796
+ if (trimmedName === "+") return "_POS";
5797
+ if (trimmedName === "-") return "_NEG";
5798
+ return trimmedName;
5799
+ };
5800
+
5801
+ // lib/websafe/convert-to-typescript-component/category-value-contains-diode.ts
5802
+ var categoryValueContainsDiode = (value) => {
5803
+ if (typeof value === "string") {
5804
+ return /(^|[^a-z])diodes?([^a-z]|$)/i.test(value);
5805
+ }
5806
+ if (Array.isArray(value)) {
5807
+ return value.some(categoryValueContainsDiode);
5808
+ }
5809
+ if (value && typeof value === "object") {
5810
+ return Object.values(value).some(categoryValueContainsDiode);
5811
+ }
5812
+ return false;
5813
+ };
5814
+
5815
+ // lib/websafe/convert-to-typescript-component/is-diode-category-component.ts
5816
+ var isDiodeCategoryComponent = (betterEasy) => {
5817
+ const cPara = betterEasy.dataStr.head.c_para;
5818
+ return [
5819
+ betterEasy.tags,
5820
+ cPara.category,
5821
+ cPara.Category,
5822
+ cPara["LCSC Category"],
5823
+ cPara["JLCPCB Category"],
5824
+ betterEasy.category
5825
+ ].some(categoryValueContainsDiode);
5826
+ };
5827
+
5828
+ // lib/websafe/convert-to-typescript-component/category-value-contains-led.ts
5829
+ var categoryValueContainsLed = (value) => {
5830
+ if (typeof value === "string") {
5831
+ return /(^|[^a-z])leds?([^a-z]|$)/i.test(value) || /light[-\s]?emitting\s+diodes?/i.test(value);
5832
+ }
5833
+ if (Array.isArray(value)) {
5834
+ return value.some(categoryValueContainsLed);
5835
+ }
5836
+ if (value && typeof value === "object") {
5837
+ return Object.values(value).some(categoryValueContainsLed);
5838
+ }
5839
+ return false;
5840
+ };
5841
+
5842
+ // lib/websafe/convert-to-typescript-component/is-led-category-component.ts
5843
+ var isLedCategoryComponent = (betterEasy) => {
5844
+ const cPara = betterEasy.dataStr.head.c_para;
5845
+ return [
5846
+ betterEasy.tags,
5847
+ cPara.category,
5848
+ cPara.Category,
5849
+ cPara["LCSC Category"],
5850
+ cPara["JLCPCB Category"],
5851
+ betterEasy.category
5852
+ ].some(categoryValueContainsLed);
5853
+ };
5854
+
5685
5855
  // node_modules/@tscircuit/math-utils/dist/chunk-3WCUPG5S.js
5686
5856
  var getBoundsCenter = (bounds) => ({
5687
5857
  x: (bounds.minX + bounds.maxX) / 2,
@@ -5818,86 +5988,6 @@ var getCadSvgNodeZOffsetMm = (easyEdaJson) => {
5818
5988
  };
5819
5989
  var getCadSvgNodeModelUuid = (easyEdaJson) => getCadSvgNode(easyEdaJson)?.svgData.attrs?.uuid ?? null;
5820
5990
 
5821
- // lib/utils/normalize-pin-labels.ts
5822
- var normalizePinLabels = (inputPinLabels) => {
5823
- const uniqueInputPinLabels = inputPinLabels.map((labels) => [
5824
- ...new Set(labels)
5825
- ]);
5826
- const result = uniqueInputPinLabels.map(() => []);
5827
- const desiredNumbers = uniqueInputPinLabels.map(() => null);
5828
- for (let i = 0; i < uniqueInputPinLabels.length; i++) {
5829
- for (const label of uniqueInputPinLabels[i]) {
5830
- if (/^\d+$/.test(label)) {
5831
- desiredNumbers[i] = Number.parseInt(label);
5832
- break;
5833
- }
5834
- }
5835
- }
5836
- let highestPinNumber = 0;
5837
- const acceptedDesiredNumbers = /* @__PURE__ */ new Set();
5838
- for (let i = 0; i < desiredNumbers.length; i++) {
5839
- const desiredNumber = desiredNumbers[i];
5840
- if (desiredNumber === null || desiredNumber < 1) continue;
5841
- if (!acceptedDesiredNumbers.has(desiredNumber)) {
5842
- acceptedDesiredNumbers.add(desiredNumber);
5843
- result[i].push(`pin${desiredNumber}`);
5844
- highestPinNumber = Math.max(highestPinNumber, desiredNumber);
5845
- continue;
5846
- }
5847
- let existingAltCount = 0;
5848
- for (const label of result[i]) {
5849
- if (label.startsWith(`pin${desiredNumber}_alt`)) {
5850
- existingAltCount += 1;
5851
- }
5852
- }
5853
- result[i].push(`pin${desiredNumber}_alt${existingAltCount + 1}`);
5854
- }
5855
- for (let i = 0; i < result.length; i++) {
5856
- const firstLabel = result[i][0];
5857
- if (firstLabel?.includes("_alt")) {
5858
- highestPinNumber += 1;
5859
- result[i].unshift(`pin${highestPinNumber}`);
5860
- }
5861
- }
5862
- for (let i = 0; i < result.length; i++) {
5863
- if (result[i].length === 0) {
5864
- highestPinNumber += 1;
5865
- result[i].push(`pin${highestPinNumber}`);
5866
- }
5867
- }
5868
- const totalLabelCounts = {};
5869
- for (const inputLabels of uniqueInputPinLabels) {
5870
- for (const label of inputLabels) {
5871
- if (/^\d+$/.test(label)) continue;
5872
- totalLabelCounts[label] = (totalLabelCounts[label] ?? 0) + 1;
5873
- }
5874
- }
5875
- const incrementalLabelCounts = {};
5876
- for (let i = 0; i < uniqueInputPinLabels.length; i++) {
5877
- for (const label of uniqueInputPinLabels[i]) {
5878
- if (/^\d+$/.test(label)) continue;
5879
- if (totalLabelCounts[label] === 1) {
5880
- result[i].push(label);
5881
- } else {
5882
- incrementalLabelCounts[label] = (incrementalLabelCounts[label] ?? 0) + 1;
5883
- result[i].push(`${label}${incrementalLabelCounts[label]}`);
5884
- }
5885
- }
5886
- }
5887
- return result;
5888
- };
5889
-
5890
- // lib/utils/normalize-symbol-name.ts
5891
- var normalizeSymbolName = (name) => {
5892
- const trimmedName = name.trim();
5893
- if (trimmedName === "+") return "_POS";
5894
- if (trimmedName === "-") return "_NEG";
5895
- return trimmedName;
5896
- };
5897
-
5898
- // lib/constants.ts
5899
- var DEFAULT_PCB_THICKNESS_MM = 1.6;
5900
-
5901
5991
  // lib/convert-easyeda-json-to-tscircuit-soup-json.ts
5902
5992
  var EASYEDA_STEP_MODEL_URL = "https://modules.easyeda.com/qAxj6KHrDKw4blvCG8QJPs7Y";
5903
5993
  var EASYEDA_OBJ_MODEL_URL = "https://modules.easyeda.com/3dmodel";
@@ -6103,11 +6193,20 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
6103
6193
  return labels;
6104
6194
  });
6105
6195
  const normalizedPinLabels = normalizePinLabels(pinLabelSets);
6196
+ const normalizedPinLabelsByPin = Object.fromEntries(
6197
+ normalizedPinLabels.map((labels) => {
6198
+ const pin = labels.find((label) => /^pin\d+$/i.test(label));
6199
+ return [pin, labels.filter((label) => label !== pin)];
6200
+ })
6201
+ );
6202
+ const polarizedPinMetadata = pads.length === 2 && (isDiodeCategoryComponent(easyEdaJson) || isLedCategoryComponent(easyEdaJson)) ? getPolarizedPinMetadata(normalizedPinLabelsByPin) : void 0;
6106
6203
  pads.forEach((pad, index) => {
6107
6204
  const portHints = normalizedPinLabels[index];
6108
6205
  const pinNumber = Number.parseInt(
6109
6206
  portHints.find((hint) => hint.match(/pin\d+/)).replace("pin", "")
6110
6207
  );
6208
+ const canonicalPinName = `pin${pinNumber}`;
6209
+ const pcbPortHints = polarizedPinMetadata?.portHintsMap[canonicalPinName] ?? [canonicalPinName];
6111
6210
  circuitElements.push({
6112
6211
  type: "source_port",
6113
6212
  source_port_id: `source_port_${index + 1}`,
@@ -6124,7 +6223,7 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
6124
6223
  x: mil2mm(pad.center.x),
6125
6224
  y: mil2mm(pad.center.y),
6126
6225
  layers: ["top"],
6127
- port_hints: [`pin${pinNumber}`],
6226
+ port_hints: pcbPortHints,
6128
6227
  pcb_component_id: "pcb_component_1",
6129
6228
  pcb_port_id: `pcb_port_${index + 1}`
6130
6229
  };
@@ -6236,7 +6335,7 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
6236
6335
  radius: Math.min(mil2mm(pad.width), mil2mm(pad.height)) / 2
6237
6336
  },
6238
6337
  layer: "top",
6239
- port_hints: [`pin${pinNumber}`],
6338
+ port_hints: pcbPortHints,
6240
6339
  pcb_component_id: "pcb_component_1",
6241
6340
  pcb_port_id: `pcb_port_${index + 1}`
6242
6341
  });
@@ -7533,7 +7632,7 @@ var getEasyEdaCadModelPlacement = async (easyEdaJson, { fetch: fetch2 = globalTh
7533
7632
  // lib/websafe/generate-footprint-tsx.ts
7534
7633
  var mapPortHints = (portHints, portHintsMap) => {
7535
7634
  if (!portHintsMap || !portHints) return portHints;
7536
- return portHints.flatMap((hint) => portHintsMap[hint] ?? [hint]);
7635
+ return [...new Set(portHints.flatMap((hint) => portHintsMap[hint] ?? [hint]))];
7537
7636
  };
7538
7637
  var generateFootprintTsx = (circuitJson, options = {}) => {
7539
7638
  const holes = su(circuitJson).pcb_hole.list();
@@ -7627,40 +7726,6 @@ var generateFootprintTsx = (circuitJson, options = {}) => {
7627
7726
  };
7628
7727
 
7629
7728
  // lib/websafe/convert-to-typescript-component/generate-typescript-component.ts
7630
- var getPinLabelValues = (labels) => {
7631
- if (typeof labels === "string") return [labels];
7632
- return [...labels];
7633
- };
7634
- var stripEasyEdaPolarityHintDecoration = (label) => label.toLowerCase().replace(/[^a-z0-9+-]/g, "");
7635
- var getPinKeySortValue = (pinKey) => {
7636
- const match = /^pin(\d+)$/i.exec(pinKey);
7637
- return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;
7638
- };
7639
- var getPolarizedPinMetadata = (pinLabels) => {
7640
- const labelsByPin = Object.entries(pinLabels ?? {}).map(([pin, labels]) => ({
7641
- pin,
7642
- labels: getPinLabelValues(labels).map(stripEasyEdaPolarityHintDecoration)
7643
- }));
7644
- const anodePin = labelsByPin.find(
7645
- ({ labels }) => labels.some((label) => ["a", "anode", "pos", "+"].includes(label))
7646
- )?.pin;
7647
- const cathodePin = labelsByPin.find(
7648
- ({ labels }) => labels.some((label) => ["c", "k", "cathode", "neg", "-"].includes(label))
7649
- )?.pin;
7650
- if (!anodePin || !cathodePin) return void 0;
7651
- const polarizedPinEntries = [
7652
- [anodePin, ["anode", "pos"]],
7653
- [cathodePin, ["cathode", "neg"]]
7654
- ].sort(
7655
- ([pinA], [pinB]) => getPinKeySortValue(pinA) - getPinKeySortValue(pinB)
7656
- );
7657
- return {
7658
- portHintsMap: Object.fromEntries(
7659
- polarizedPinEntries.map(([pin, labels]) => [pin, [pin, ...labels]])
7660
- ),
7661
- pinLabels: Object.fromEntries(polarizedPinEntries)
7662
- };
7663
- };
7664
7729
  var generateTypescriptComponent = ({
7665
7730
  pinLabels,
7666
7731
  componentName,
@@ -7830,60 +7895,6 @@ ${cadModelLines}
7830
7895
  `.trim();
7831
7896
  };
7832
7897
 
7833
- // lib/websafe/convert-to-typescript-component/category-value-contains-diode.ts
7834
- var categoryValueContainsDiode = (value) => {
7835
- if (typeof value === "string") {
7836
- return /(^|[^a-z])diodes?([^a-z]|$)/i.test(value);
7837
- }
7838
- if (Array.isArray(value)) {
7839
- return value.some(categoryValueContainsDiode);
7840
- }
7841
- if (value && typeof value === "object") {
7842
- return Object.values(value).some(categoryValueContainsDiode);
7843
- }
7844
- return false;
7845
- };
7846
-
7847
- // lib/websafe/convert-to-typescript-component/is-diode-category-component.ts
7848
- var isDiodeCategoryComponent = (betterEasy) => {
7849
- const cPara = betterEasy.dataStr.head.c_para;
7850
- return [
7851
- betterEasy.tags,
7852
- cPara.category,
7853
- cPara.Category,
7854
- cPara["LCSC Category"],
7855
- cPara["JLCPCB Category"],
7856
- betterEasy.category
7857
- ].some(categoryValueContainsDiode);
7858
- };
7859
-
7860
- // lib/websafe/convert-to-typescript-component/category-value-contains-led.ts
7861
- var categoryValueContainsLed = (value) => {
7862
- if (typeof value === "string") {
7863
- return /(^|[^a-z])leds?([^a-z]|$)/i.test(value) || /light[-\s]?emitting\s+diodes?/i.test(value);
7864
- }
7865
- if (Array.isArray(value)) {
7866
- return value.some(categoryValueContainsLed);
7867
- }
7868
- if (value && typeof value === "object") {
7869
- return Object.values(value).some(categoryValueContainsLed);
7870
- }
7871
- return false;
7872
- };
7873
-
7874
- // lib/websafe/convert-to-typescript-component/is-led-category-component.ts
7875
- var isLedCategoryComponent = (betterEasy) => {
7876
- const cPara = betterEasy.dataStr.head.c_para;
7877
- return [
7878
- betterEasy.tags,
7879
- cPara.category,
7880
- cPara.Category,
7881
- cPara["LCSC Category"],
7882
- cPara["JLCPCB Category"],
7883
- betterEasy.category
7884
- ].some(categoryValueContainsLed);
7885
- };
7886
-
7887
7898
  // lib/websafe/convert-to-typescript-component/category-value-contains-pushbutton.ts
7888
7899
  var categoryValueContainsPushbutton = (value) => {
7889
7900
  if (typeof value === "string") {