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/main.cjs CHANGED
@@ -3499,7 +3499,7 @@ var import_promises = __toESM(require("fs/promises"), 1);
3499
3499
  var package_default = {
3500
3500
  name: "easyeda",
3501
3501
  type: "module",
3502
- version: "0.0.271",
3502
+ version: "0.0.273",
3503
3503
  files: [
3504
3504
  "dist"
3505
3505
  ],
@@ -10964,11 +10964,11 @@ var generateFootprintTsx = (circuitJson, options = {}) => {
10964
10964
  const cornerRadius = smtPad.corner_radius ?? smtPad.rect_border_radius ?? void 0;
10965
10965
  const cornerRadiusAttr = cornerRadius !== void 0 ? ` cornerRadius="${mmStr(cornerRadius)}"` : "";
10966
10966
  elementStrings.push(
10967
- `<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" />`
10967
+ `<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" />`
10968
10968
  );
10969
10969
  } else if (smtPad.shape === "pill") {
10970
10970
  elementStrings.push(
10971
- `<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" />`
10971
+ `<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" />`
10972
10972
  );
10973
10973
  } else if (smtPad.shape === "polygon") {
10974
10974
  const pointsStr = smtPad.points.map((p) => `{x: "${mmStr(p.x)}", y: "${mmStr(p.y)}"}`).join(", ");
@@ -11011,10 +11011,15 @@ var getPinLabelValues = (labels) => {
11011
11011
  if (typeof labels === "string") return [labels];
11012
11012
  return [...labels];
11013
11013
  };
11014
- var getPolarizedPortHintsMap = (pinLabels) => {
11014
+ var stripEasyEdaPolarityHintDecoration = (label) => label.toLowerCase().replace(/[^a-z0-9+-]/g, "");
11015
+ var getPinKeySortValue = (pinKey) => {
11016
+ const match = /^pin(\d+)$/i.exec(pinKey);
11017
+ return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;
11018
+ };
11019
+ var getPolarizedPinMetadata = (pinLabels) => {
11015
11020
  const labelsByPin = Object.entries(pinLabels ?? {}).map(([pin, labels]) => ({
11016
11021
  pin,
11017
- labels: getPinLabelValues(labels).map((label) => label.toLowerCase())
11022
+ labels: getPinLabelValues(labels).map(stripEasyEdaPolarityHintDecoration)
11018
11023
  }));
11019
11024
  const anodePin = labelsByPin.find(
11020
11025
  ({ labels }) => labels.some((label) => ["a", "anode", "pos", "+"].includes(label))
@@ -11023,9 +11028,17 @@ var getPolarizedPortHintsMap = (pinLabels) => {
11023
11028
  ({ labels }) => labels.some((label) => ["c", "k", "cathode", "neg", "-"].includes(label))
11024
11029
  )?.pin;
11025
11030
  if (!anodePin || !cathodePin) return void 0;
11031
+ const polarizedPinEntries = [
11032
+ [anodePin, ["anode", "pos"]],
11033
+ [cathodePin, ["cathode", "neg"]]
11034
+ ].sort(
11035
+ ([pinA], [pinB]) => getPinKeySortValue(pinA) - getPinKeySortValue(pinB)
11036
+ );
11026
11037
  return {
11027
- [anodePin]: ["pin1", "anode"],
11028
- [cathodePin]: ["pin2", "cathode"]
11038
+ portHintsMap: Object.fromEntries(
11039
+ polarizedPinEntries.map(([pin, labels]) => [pin, [pin, ...labels]])
11040
+ ),
11041
+ pinLabels: Object.fromEntries(polarizedPinEntries)
11029
11042
  };
11030
11043
  };
11031
11044
  var generateTypescriptComponent = ({
@@ -11039,10 +11052,13 @@ var generateTypescriptComponent = ({
11039
11052
  componentType = "chip"
11040
11053
  }) => {
11041
11054
  const safePinLabels = pinLabels ?? {};
11055
+ const polarizedPinMetadata = getPolarizedPinMetadata(safePinLabels);
11056
+ const polarizedPortHintsMap = polarizedPinMetadata?.portHintsMap;
11057
+ const polarizedPinLabels = polarizedPinMetadata?.pinLabels;
11042
11058
  const cadComponent = circuitJson.find((item) => item.type === "cad_component");
11043
11059
  const footprintTsx = generateFootprintTsx(
11044
11060
  circuitJson,
11045
- componentType === "diode" || componentType === "led" ? { portHintsMap: getPolarizedPortHintsMap(safePinLabels) } : void 0
11061
+ componentType === "diode" || componentType === "led" ? { portHintsMap: polarizedPortHintsMap } : void 0
11046
11062
  );
11047
11063
  const simplifiedPinLabels = Object.fromEntries(
11048
11064
  Object.entries(safePinLabels).map(([pin, labels]) => {
@@ -11053,6 +11069,14 @@ var generateTypescriptComponent = ({
11053
11069
  })
11054
11070
  );
11055
11071
  const pinLabelsString = Object.entries(simplifiedPinLabels).map(([pin, labels]) => ` ${pin}: ${JSON.stringify(labels)}`).join(",\n");
11072
+ const polarizedPinLabelsString = Object.entries(polarizedPinLabels ?? {}).map(([pin, labels]) => ` ${pin}: ${JSON.stringify(labels)}`).join(",\n");
11073
+ const polarizedPinLabelsBlock = polarizedPinLabels ? `const pinLabels = {
11074
+ ${polarizedPinLabelsString}
11075
+ } as const
11076
+
11077
+ ` : "";
11078
+ const polarizedPinLabelsProp = polarizedPinLabels ? ` pinLabels={pinLabels}
11079
+ ` : "";
11056
11080
  const cadModelLines = [
11057
11081
  objUrl ? `objUrl: "${objUrl}",` : "",
11058
11082
  stepUrl ? `stepUrl: "${stepUrl}",` : "",
@@ -11063,13 +11087,13 @@ var generateTypescriptComponent = ({
11063
11087
  return `
11064
11088
  import type { DiodeProps } from "@tscircuit/props"
11065
11089
 
11066
- export const ${componentName} = (props: DiodeProps) => {
11090
+ ${polarizedPinLabelsBlock}export const ${componentName} = (props: DiodeProps) => {
11067
11091
  const { name = "D1", ...restProps } = props
11068
11092
 
11069
11093
  return (
11070
11094
  <diode
11071
11095
  name={name}
11072
- supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
11096
+ ${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
11073
11097
  manufacturerPartNumber="${manufacturerPartNumber}"
11074
11098
  footprint={${footprintTsx}}
11075
11099
  ${objUrl || stepUrl ? `cadModel={{
@@ -11085,13 +11109,13 @@ ${cadModelLines}
11085
11109
  return `
11086
11110
  import type { LedProps } from "@tscircuit/props"
11087
11111
 
11088
- export const ${componentName} = (props: LedProps) => {
11112
+ ${polarizedPinLabelsBlock}export const ${componentName} = (props: LedProps) => {
11089
11113
  const { name = "LED1", ...restProps } = props
11090
11114
 
11091
11115
  return (
11092
11116
  <led
11093
11117
  name={name}
11094
- supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
11118
+ ${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
11095
11119
  manufacturerPartNumber="${manufacturerPartNumber}"
11096
11120
  footprint={${footprintTsx}}
11097
11121
  ${objUrl || stepUrl ? `cadModel={{