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.
@@ -9497,6 +9497,9 @@ var mil2mm = (mil) => {
9497
9497
  return mm(mil);
9498
9498
  };
9499
9499
 
9500
+ // lib/constants.ts
9501
+ var DEFAULT_PCB_THICKNESS_MM = 1.6;
9502
+
9500
9503
  // lib/math/arc-utils.ts
9501
9504
  function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag, sweepFlag) {
9502
9505
  const start = { x: startX, y: startY };
@@ -9545,6 +9548,173 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
9545
9548
  // lib/utils/easyeda-unit-to-mm.ts
9546
9549
  var mil10ToMm = (value) => value * 10 * 0.0254;
9547
9550
 
9551
+ // lib/utils/get-polarized-pin-metadata.ts
9552
+ var getPinLabelValues = (labels) => {
9553
+ if (typeof labels === "string") return [labels];
9554
+ return [...labels];
9555
+ };
9556
+ var stripEasyEdaPolarityHintDecoration = (label) => label.toLowerCase().replace(/[^a-z0-9+-]/g, "");
9557
+ var getPinKeySortValue = (pinKey) => {
9558
+ const match = /^pin(\d+)$/i.exec(pinKey);
9559
+ return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;
9560
+ };
9561
+ var getPolarizedPinMetadata = (pinLabels) => {
9562
+ const labelsByPin = Object.entries(pinLabels).map(([pin, labels]) => ({
9563
+ pin,
9564
+ labels: getPinLabelValues(labels).map(stripEasyEdaPolarityHintDecoration)
9565
+ }));
9566
+ const anodePin = labelsByPin.find(
9567
+ ({ labels }) => labels.some((label) => ["a", "anode", "pos", "+"].includes(label))
9568
+ )?.pin;
9569
+ const cathodePin = labelsByPin.find(
9570
+ ({ labels }) => labels.some((label) => ["c", "k", "cathode", "neg", "-"].includes(label))
9571
+ )?.pin;
9572
+ if (!anodePin || !cathodePin || anodePin === cathodePin) return void 0;
9573
+ const polarizedPinEntries = [
9574
+ [anodePin, ["anode", "pos"]],
9575
+ [cathodePin, ["cathode", "neg"]]
9576
+ ].sort(
9577
+ ([pinA], [pinB]) => getPinKeySortValue(pinA) - getPinKeySortValue(pinB)
9578
+ );
9579
+ return {
9580
+ portHintsMap: Object.fromEntries(
9581
+ polarizedPinEntries.map(([pin, labels]) => [pin, [pin, ...labels]])
9582
+ ),
9583
+ pinLabels: Object.fromEntries(polarizedPinEntries)
9584
+ };
9585
+ };
9586
+
9587
+ // lib/utils/normalize-pin-labels.ts
9588
+ var normalizePinLabels = (inputPinLabels) => {
9589
+ const uniqueInputPinLabels = inputPinLabels.map((labels) => [
9590
+ ...new Set(labels)
9591
+ ]);
9592
+ const result = uniqueInputPinLabels.map(() => []);
9593
+ const desiredNumbers = uniqueInputPinLabels.map(() => null);
9594
+ for (let i = 0; i < uniqueInputPinLabels.length; i++) {
9595
+ for (const label of uniqueInputPinLabels[i]) {
9596
+ if (/^\d+$/.test(label)) {
9597
+ desiredNumbers[i] = Number.parseInt(label);
9598
+ break;
9599
+ }
9600
+ }
9601
+ }
9602
+ let highestPinNumber = 0;
9603
+ const acceptedDesiredNumbers = /* @__PURE__ */ new Set();
9604
+ for (let i = 0; i < desiredNumbers.length; i++) {
9605
+ const desiredNumber = desiredNumbers[i];
9606
+ if (desiredNumber === null || desiredNumber < 1) continue;
9607
+ if (!acceptedDesiredNumbers.has(desiredNumber)) {
9608
+ acceptedDesiredNumbers.add(desiredNumber);
9609
+ result[i].push(`pin${desiredNumber}`);
9610
+ highestPinNumber = Math.max(highestPinNumber, desiredNumber);
9611
+ continue;
9612
+ }
9613
+ let existingAltCount = 0;
9614
+ for (const label of result[i]) {
9615
+ if (label.startsWith(`pin${desiredNumber}_alt`)) {
9616
+ existingAltCount += 1;
9617
+ }
9618
+ }
9619
+ result[i].push(`pin${desiredNumber}_alt${existingAltCount + 1}`);
9620
+ }
9621
+ for (let i = 0; i < result.length; i++) {
9622
+ const firstLabel = result[i][0];
9623
+ if (firstLabel?.includes("_alt")) {
9624
+ highestPinNumber += 1;
9625
+ result[i].unshift(`pin${highestPinNumber}`);
9626
+ }
9627
+ }
9628
+ for (let i = 0; i < result.length; i++) {
9629
+ if (result[i].length === 0) {
9630
+ highestPinNumber += 1;
9631
+ result[i].push(`pin${highestPinNumber}`);
9632
+ }
9633
+ }
9634
+ const totalLabelCounts = {};
9635
+ for (const inputLabels of uniqueInputPinLabels) {
9636
+ for (const label of inputLabels) {
9637
+ if (/^\d+$/.test(label)) continue;
9638
+ totalLabelCounts[label] = (totalLabelCounts[label] ?? 0) + 1;
9639
+ }
9640
+ }
9641
+ const incrementalLabelCounts = {};
9642
+ for (let i = 0; i < uniqueInputPinLabels.length; i++) {
9643
+ for (const label of uniqueInputPinLabels[i]) {
9644
+ if (/^\d+$/.test(label)) continue;
9645
+ if (totalLabelCounts[label] === 1) {
9646
+ result[i].push(label);
9647
+ } else {
9648
+ incrementalLabelCounts[label] = (incrementalLabelCounts[label] ?? 0) + 1;
9649
+ result[i].push(`${label}${incrementalLabelCounts[label]}`);
9650
+ }
9651
+ }
9652
+ }
9653
+ return result;
9654
+ };
9655
+
9656
+ // lib/utils/normalize-symbol-name.ts
9657
+ var normalizeSymbolName = (name) => {
9658
+ const trimmedName = name.trim();
9659
+ if (trimmedName === "+") return "_POS";
9660
+ if (trimmedName === "-") return "_NEG";
9661
+ return trimmedName;
9662
+ };
9663
+
9664
+ // lib/websafe/convert-to-typescript-component/category-value-contains-diode.ts
9665
+ var categoryValueContainsDiode = (value) => {
9666
+ if (typeof value === "string") {
9667
+ return /(^|[^a-z])diodes?([^a-z]|$)/i.test(value);
9668
+ }
9669
+ if (Array.isArray(value)) {
9670
+ return value.some(categoryValueContainsDiode);
9671
+ }
9672
+ if (value && typeof value === "object") {
9673
+ return Object.values(value).some(categoryValueContainsDiode);
9674
+ }
9675
+ return false;
9676
+ };
9677
+
9678
+ // lib/websafe/convert-to-typescript-component/is-diode-category-component.ts
9679
+ var isDiodeCategoryComponent = (betterEasy) => {
9680
+ const cPara = betterEasy.dataStr.head.c_para;
9681
+ return [
9682
+ betterEasy.tags,
9683
+ cPara.category,
9684
+ cPara.Category,
9685
+ cPara["LCSC Category"],
9686
+ cPara["JLCPCB Category"],
9687
+ betterEasy.category
9688
+ ].some(categoryValueContainsDiode);
9689
+ };
9690
+
9691
+ // lib/websafe/convert-to-typescript-component/category-value-contains-led.ts
9692
+ var categoryValueContainsLed = (value) => {
9693
+ if (typeof value === "string") {
9694
+ return /(^|[^a-z])leds?([^a-z]|$)/i.test(value) || /light[-\s]?emitting\s+diodes?/i.test(value);
9695
+ }
9696
+ if (Array.isArray(value)) {
9697
+ return value.some(categoryValueContainsLed);
9698
+ }
9699
+ if (value && typeof value === "object") {
9700
+ return Object.values(value).some(categoryValueContainsLed);
9701
+ }
9702
+ return false;
9703
+ };
9704
+
9705
+ // lib/websafe/convert-to-typescript-component/is-led-category-component.ts
9706
+ var isLedCategoryComponent = (betterEasy) => {
9707
+ const cPara = betterEasy.dataStr.head.c_para;
9708
+ return [
9709
+ betterEasy.tags,
9710
+ cPara.category,
9711
+ cPara.Category,
9712
+ cPara["LCSC Category"],
9713
+ cPara["JLCPCB Category"],
9714
+ betterEasy.category
9715
+ ].some(categoryValueContainsLed);
9716
+ };
9717
+
9548
9718
  // node_modules/@tscircuit/math-utils/dist/chunk-3WCUPG5S.js
9549
9719
  var getBoundsCenter = (bounds) => ({
9550
9720
  x: (bounds.minX + bounds.maxX) / 2,
@@ -9681,86 +9851,6 @@ var getCadSvgNodeZOffsetMm = (easyEdaJson) => {
9681
9851
  };
9682
9852
  var getCadSvgNodeModelUuid = (easyEdaJson) => getCadSvgNode(easyEdaJson)?.svgData.attrs?.uuid ?? null;
9683
9853
 
9684
- // lib/utils/normalize-pin-labels.ts
9685
- var normalizePinLabels = (inputPinLabels) => {
9686
- const uniqueInputPinLabels = inputPinLabels.map((labels) => [
9687
- ...new Set(labels)
9688
- ]);
9689
- const result = uniqueInputPinLabels.map(() => []);
9690
- const desiredNumbers = uniqueInputPinLabels.map(() => null);
9691
- for (let i = 0; i < uniqueInputPinLabels.length; i++) {
9692
- for (const label of uniqueInputPinLabels[i]) {
9693
- if (/^\d+$/.test(label)) {
9694
- desiredNumbers[i] = Number.parseInt(label);
9695
- break;
9696
- }
9697
- }
9698
- }
9699
- let highestPinNumber = 0;
9700
- const acceptedDesiredNumbers = /* @__PURE__ */ new Set();
9701
- for (let i = 0; i < desiredNumbers.length; i++) {
9702
- const desiredNumber = desiredNumbers[i];
9703
- if (desiredNumber === null || desiredNumber < 1) continue;
9704
- if (!acceptedDesiredNumbers.has(desiredNumber)) {
9705
- acceptedDesiredNumbers.add(desiredNumber);
9706
- result[i].push(`pin${desiredNumber}`);
9707
- highestPinNumber = Math.max(highestPinNumber, desiredNumber);
9708
- continue;
9709
- }
9710
- let existingAltCount = 0;
9711
- for (const label of result[i]) {
9712
- if (label.startsWith(`pin${desiredNumber}_alt`)) {
9713
- existingAltCount += 1;
9714
- }
9715
- }
9716
- result[i].push(`pin${desiredNumber}_alt${existingAltCount + 1}`);
9717
- }
9718
- for (let i = 0; i < result.length; i++) {
9719
- const firstLabel = result[i][0];
9720
- if (firstLabel?.includes("_alt")) {
9721
- highestPinNumber += 1;
9722
- result[i].unshift(`pin${highestPinNumber}`);
9723
- }
9724
- }
9725
- for (let i = 0; i < result.length; i++) {
9726
- if (result[i].length === 0) {
9727
- highestPinNumber += 1;
9728
- result[i].push(`pin${highestPinNumber}`);
9729
- }
9730
- }
9731
- const totalLabelCounts = {};
9732
- for (const inputLabels of uniqueInputPinLabels) {
9733
- for (const label of inputLabels) {
9734
- if (/^\d+$/.test(label)) continue;
9735
- totalLabelCounts[label] = (totalLabelCounts[label] ?? 0) + 1;
9736
- }
9737
- }
9738
- const incrementalLabelCounts = {};
9739
- for (let i = 0; i < uniqueInputPinLabels.length; i++) {
9740
- for (const label of uniqueInputPinLabels[i]) {
9741
- if (/^\d+$/.test(label)) continue;
9742
- if (totalLabelCounts[label] === 1) {
9743
- result[i].push(label);
9744
- } else {
9745
- incrementalLabelCounts[label] = (incrementalLabelCounts[label] ?? 0) + 1;
9746
- result[i].push(`${label}${incrementalLabelCounts[label]}`);
9747
- }
9748
- }
9749
- }
9750
- return result;
9751
- };
9752
-
9753
- // lib/utils/normalize-symbol-name.ts
9754
- var normalizeSymbolName = (name) => {
9755
- const trimmedName = name.trim();
9756
- if (trimmedName === "+") return "_POS";
9757
- if (trimmedName === "-") return "_NEG";
9758
- return trimmedName;
9759
- };
9760
-
9761
- // lib/constants.ts
9762
- var DEFAULT_PCB_THICKNESS_MM = 1.6;
9763
-
9764
9854
  // lib/convert-easyeda-json-to-tscircuit-soup-json.ts
9765
9855
  var EASYEDA_STEP_MODEL_URL = "https://modules.easyeda.com/qAxj6KHrDKw4blvCG8QJPs7Y";
9766
9856
  var EASYEDA_OBJ_MODEL_URL = "https://modules.easyeda.com/3dmodel";
@@ -9966,11 +10056,20 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
9966
10056
  return labels;
9967
10057
  });
9968
10058
  const normalizedPinLabels = normalizePinLabels(pinLabelSets);
10059
+ const normalizedPinLabelsByPin = Object.fromEntries(
10060
+ normalizedPinLabels.map((labels) => {
10061
+ const pin = labels.find((label) => /^pin\d+$/i.test(label));
10062
+ return [pin, labels.filter((label) => label !== pin)];
10063
+ })
10064
+ );
10065
+ const polarizedPinMetadata = pads.length === 2 && (isDiodeCategoryComponent(easyEdaJson) || isLedCategoryComponent(easyEdaJson)) ? getPolarizedPinMetadata(normalizedPinLabelsByPin) : void 0;
9969
10066
  pads.forEach((pad, index) => {
9970
10067
  const portHints = normalizedPinLabels[index];
9971
10068
  const pinNumber = Number.parseInt(
9972
10069
  portHints.find((hint) => hint.match(/pin\d+/)).replace("pin", "")
9973
10070
  );
10071
+ const canonicalPinName = `pin${pinNumber}`;
10072
+ const pcbPortHints = polarizedPinMetadata?.portHintsMap[canonicalPinName] ?? [canonicalPinName];
9974
10073
  circuitElements.push({
9975
10074
  type: "source_port",
9976
10075
  source_port_id: `source_port_${index + 1}`,
@@ -9987,7 +10086,7 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
9987
10086
  x: mil2mm(pad.center.x),
9988
10087
  y: mil2mm(pad.center.y),
9989
10088
  layers: ["top"],
9990
- port_hints: [`pin${pinNumber}`],
10089
+ port_hints: pcbPortHints,
9991
10090
  pcb_component_id: "pcb_component_1",
9992
10091
  pcb_port_id: `pcb_port_${index + 1}`
9993
10092
  };
@@ -10099,7 +10198,7 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
10099
10198
  radius: Math.min(mil2mm(pad.width), mil2mm(pad.height)) / 2
10100
10199
  },
10101
10200
  layer: "top",
10102
- port_hints: [`pin${pinNumber}`],
10201
+ port_hints: pcbPortHints,
10103
10202
  pcb_component_id: "pcb_component_1",
10104
10203
  pcb_port_id: `pcb_port_${index + 1}`
10105
10204
  });
@@ -11247,7 +11346,7 @@ var getEasyEdaCadModelPlacement = async (easyEdaJson, { fetch: fetch2 = globalTh
11247
11346
  // lib/websafe/generate-footprint-tsx.ts
11248
11347
  var mapPortHints = (portHints, portHintsMap) => {
11249
11348
  if (!portHintsMap || !portHints) return portHints;
11250
- return portHints.flatMap((hint) => portHintsMap[hint] ?? [hint]);
11349
+ return [...new Set(portHints.flatMap((hint) => portHintsMap[hint] ?? [hint]))];
11251
11350
  };
11252
11351
  var generateFootprintTsx = (circuitJson, options = {}) => {
11253
11352
  const holes = su(circuitJson).pcb_hole.list();
@@ -11341,40 +11440,6 @@ var generateFootprintTsx = (circuitJson, options = {}) => {
11341
11440
  };
11342
11441
 
11343
11442
  // lib/websafe/convert-to-typescript-component/generate-typescript-component.ts
11344
- var getPinLabelValues = (labels) => {
11345
- if (typeof labels === "string") return [labels];
11346
- return [...labels];
11347
- };
11348
- var stripEasyEdaPolarityHintDecoration = (label) => label.toLowerCase().replace(/[^a-z0-9+-]/g, "");
11349
- var getPinKeySortValue = (pinKey) => {
11350
- const match = /^pin(\d+)$/i.exec(pinKey);
11351
- return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;
11352
- };
11353
- var getPolarizedPinMetadata = (pinLabels) => {
11354
- const labelsByPin = Object.entries(pinLabels ?? {}).map(([pin, labels]) => ({
11355
- pin,
11356
- labels: getPinLabelValues(labels).map(stripEasyEdaPolarityHintDecoration)
11357
- }));
11358
- const anodePin = labelsByPin.find(
11359
- ({ labels }) => labels.some((label) => ["a", "anode", "pos", "+"].includes(label))
11360
- )?.pin;
11361
- const cathodePin = labelsByPin.find(
11362
- ({ labels }) => labels.some((label) => ["c", "k", "cathode", "neg", "-"].includes(label))
11363
- )?.pin;
11364
- if (!anodePin || !cathodePin) return void 0;
11365
- const polarizedPinEntries = [
11366
- [anodePin, ["anode", "pos"]],
11367
- [cathodePin, ["cathode", "neg"]]
11368
- ].sort(
11369
- ([pinA], [pinB]) => getPinKeySortValue(pinA) - getPinKeySortValue(pinB)
11370
- );
11371
- return {
11372
- portHintsMap: Object.fromEntries(
11373
- polarizedPinEntries.map(([pin, labels]) => [pin, [pin, ...labels]])
11374
- ),
11375
- pinLabels: Object.fromEntries(polarizedPinEntries)
11376
- };
11377
- };
11378
11443
  var generateTypescriptComponent = ({
11379
11444
  pinLabels,
11380
11445
  componentName,
@@ -11544,60 +11609,6 @@ ${cadModelLines}
11544
11609
  `.trim();
11545
11610
  };
11546
11611
 
11547
- // lib/websafe/convert-to-typescript-component/category-value-contains-diode.ts
11548
- var categoryValueContainsDiode = (value) => {
11549
- if (typeof value === "string") {
11550
- return /(^|[^a-z])diodes?([^a-z]|$)/i.test(value);
11551
- }
11552
- if (Array.isArray(value)) {
11553
- return value.some(categoryValueContainsDiode);
11554
- }
11555
- if (value && typeof value === "object") {
11556
- return Object.values(value).some(categoryValueContainsDiode);
11557
- }
11558
- return false;
11559
- };
11560
-
11561
- // lib/websafe/convert-to-typescript-component/is-diode-category-component.ts
11562
- var isDiodeCategoryComponent = (betterEasy) => {
11563
- const cPara = betterEasy.dataStr.head.c_para;
11564
- return [
11565
- betterEasy.tags,
11566
- cPara.category,
11567
- cPara.Category,
11568
- cPara["LCSC Category"],
11569
- cPara["JLCPCB Category"],
11570
- betterEasy.category
11571
- ].some(categoryValueContainsDiode);
11572
- };
11573
-
11574
- // lib/websafe/convert-to-typescript-component/category-value-contains-led.ts
11575
- var categoryValueContainsLed = (value) => {
11576
- if (typeof value === "string") {
11577
- return /(^|[^a-z])leds?([^a-z]|$)/i.test(value) || /light[-\s]?emitting\s+diodes?/i.test(value);
11578
- }
11579
- if (Array.isArray(value)) {
11580
- return value.some(categoryValueContainsLed);
11581
- }
11582
- if (value && typeof value === "object") {
11583
- return Object.values(value).some(categoryValueContainsLed);
11584
- }
11585
- return false;
11586
- };
11587
-
11588
- // lib/websafe/convert-to-typescript-component/is-led-category-component.ts
11589
- var isLedCategoryComponent = (betterEasy) => {
11590
- const cPara = betterEasy.dataStr.head.c_para;
11591
- return [
11592
- betterEasy.tags,
11593
- cPara.category,
11594
- cPara.Category,
11595
- cPara["LCSC Category"],
11596
- cPara["JLCPCB Category"],
11597
- betterEasy.category
11598
- ].some(categoryValueContainsLed);
11599
- };
11600
-
11601
11612
  // lib/websafe/convert-to-typescript-component/category-value-contains-pushbutton.ts
11602
11613
  var categoryValueContainsPushbutton = (value) => {
11603
11614
  if (typeof value === "string") {