easyeda 0.0.272 → 0.0.274

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
@@ -7557,11 +7557,11 @@ var generateFootprintTsx = (circuitJson, options = {}) => {
7557
7557
  const cornerRadius = smtPad.corner_radius ?? smtPad.rect_border_radius ?? void 0;
7558
7558
  const cornerRadiusAttr = cornerRadius !== void 0 ? ` cornerRadius="${mmStr(cornerRadius)}"` : "";
7559
7559
  elementStrings.push(
7560
- `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}"${cornerRadiusAttr} shape="rect" />`
7560
+ `<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)}"${cornerRadiusAttr} shape="rect" />`
7561
7561
  );
7562
7562
  } else if (smtPad.shape === "pill") {
7563
7563
  elementStrings.push(
7564
- `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}" radius="${mmStr(smtPad.radius)}" shape="pill" />`
7564
+ `<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)}" radius="${mmStr(smtPad.radius)}" shape="pill" />`
7565
7565
  );
7566
7566
  } else if (smtPad.shape === "polygon") {
7567
7567
  const pointsStr = smtPad.points.map((p) => `{x: "${mmStr(p.x)}", y: "${mmStr(p.y)}"}`).join(", ");
@@ -7604,10 +7604,15 @@ var getPinLabelValues = (labels) => {
7604
7604
  if (typeof labels === "string") return [labels];
7605
7605
  return [...labels];
7606
7606
  };
7607
- var getPolarizedPortHintsMap = (pinLabels) => {
7607
+ var stripEasyEdaPolarityHintDecoration = (label) => label.toLowerCase().replace(/[^a-z0-9+-]/g, "");
7608
+ var getPinKeySortValue = (pinKey) => {
7609
+ const match = /^pin(\d+)$/i.exec(pinKey);
7610
+ return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;
7611
+ };
7612
+ var getPolarizedPinMetadata = (pinLabels) => {
7608
7613
  const labelsByPin = Object.entries(pinLabels ?? {}).map(([pin, labels]) => ({
7609
7614
  pin,
7610
- labels: getPinLabelValues(labels).map((label) => label.toLowerCase())
7615
+ labels: getPinLabelValues(labels).map(stripEasyEdaPolarityHintDecoration)
7611
7616
  }));
7612
7617
  const anodePin = labelsByPin.find(
7613
7618
  ({ labels }) => labels.some((label) => ["a", "anode", "pos", "+"].includes(label))
@@ -7616,9 +7621,17 @@ var getPolarizedPortHintsMap = (pinLabels) => {
7616
7621
  ({ labels }) => labels.some((label) => ["c", "k", "cathode", "neg", "-"].includes(label))
7617
7622
  )?.pin;
7618
7623
  if (!anodePin || !cathodePin) return void 0;
7624
+ const polarizedPinEntries = [
7625
+ [anodePin, ["anode", "pos"]],
7626
+ [cathodePin, ["cathode", "neg"]]
7627
+ ].sort(
7628
+ ([pinA], [pinB]) => getPinKeySortValue(pinA) - getPinKeySortValue(pinB)
7629
+ );
7619
7630
  return {
7620
- [anodePin]: ["pin1", "anode"],
7621
- [cathodePin]: ["pin2", "cathode"]
7631
+ portHintsMap: Object.fromEntries(
7632
+ polarizedPinEntries.map(([pin, labels]) => [pin, [pin, ...labels]])
7633
+ ),
7634
+ pinLabels: Object.fromEntries(polarizedPinEntries)
7622
7635
  };
7623
7636
  };
7624
7637
  var generateTypescriptComponent = ({
@@ -7632,10 +7645,13 @@ var generateTypescriptComponent = ({
7632
7645
  componentType = "chip"
7633
7646
  }) => {
7634
7647
  const safePinLabels = pinLabels ?? {};
7648
+ const polarizedPinMetadata = getPolarizedPinMetadata(safePinLabels);
7649
+ const polarizedPortHintsMap = polarizedPinMetadata?.portHintsMap;
7650
+ const polarizedPinLabels = polarizedPinMetadata?.pinLabels;
7635
7651
  const cadComponent = circuitJson.find((item) => item.type === "cad_component");
7636
7652
  const footprintTsx = generateFootprintTsx(
7637
7653
  circuitJson,
7638
- componentType === "diode" || componentType === "led" ? { portHintsMap: getPolarizedPortHintsMap(safePinLabels) } : void 0
7654
+ componentType === "diode" || componentType === "led" ? { portHintsMap: polarizedPortHintsMap } : void 0
7639
7655
  );
7640
7656
  const simplifiedPinLabels = Object.fromEntries(
7641
7657
  Object.entries(safePinLabels).map(([pin, labels]) => {
@@ -7646,6 +7662,14 @@ var generateTypescriptComponent = ({
7646
7662
  })
7647
7663
  );
7648
7664
  const pinLabelsString = Object.entries(simplifiedPinLabels).map(([pin, labels]) => ` ${pin}: ${JSON.stringify(labels)}`).join(",\n");
7665
+ const polarizedPinLabelsString = Object.entries(polarizedPinLabels ?? {}).map(([pin, labels]) => ` ${pin}: ${JSON.stringify(labels)}`).join(",\n");
7666
+ const polarizedPinLabelsBlock = polarizedPinLabels ? `const pinLabels = {
7667
+ ${polarizedPinLabelsString}
7668
+ } as const
7669
+
7670
+ ` : "";
7671
+ const polarizedPinLabelsProp = polarizedPinLabels ? ` pinLabels={pinLabels}
7672
+ ` : "";
7649
7673
  const cadModelLines = [
7650
7674
  objUrl ? `objUrl: "${objUrl}",` : "",
7651
7675
  stepUrl ? `stepUrl: "${stepUrl}",` : "",
@@ -7656,13 +7680,13 @@ var generateTypescriptComponent = ({
7656
7680
  return `
7657
7681
  import type { DiodeProps } from "@tscircuit/props"
7658
7682
 
7659
- export const ${componentName} = (props: DiodeProps) => {
7683
+ ${polarizedPinLabelsBlock}export const ${componentName} = (props: DiodeProps) => {
7660
7684
  const { name = "D1", ...restProps } = props
7661
7685
 
7662
7686
  return (
7663
7687
  <diode
7664
7688
  name={name}
7665
- supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
7689
+ ${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
7666
7690
  manufacturerPartNumber="${manufacturerPartNumber}"
7667
7691
  footprint={${footprintTsx}}
7668
7692
  ${objUrl || stepUrl ? `cadModel={{
@@ -7678,13 +7702,13 @@ ${cadModelLines}
7678
7702
  return `
7679
7703
  import type { LedProps } from "@tscircuit/props"
7680
7704
 
7681
- export const ${componentName} = (props: LedProps) => {
7705
+ ${polarizedPinLabelsBlock}export const ${componentName} = (props: LedProps) => {
7682
7706
  const { name = "LED1", ...restProps } = props
7683
7707
 
7684
7708
  return (
7685
7709
  <led
7686
7710
  name={name}
7687
- supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
7711
+ ${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
7688
7712
  manufacturerPartNumber="${manufacturerPartNumber}"
7689
7713
  footprint={${footprintTsx}}
7690
7714
  ${objUrl || stepUrl ? `cadModel={{