easyeda 0.0.260 → 0.0.262
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/browser/index.d.ts +7 -1
- package/dist/browser/index.js +91 -11
- package/dist/browser/index.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +91 -11
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +92 -12
- package/dist/main.cjs.map +1 -1
- package/package.json +1 -1
package/dist/main.cjs
CHANGED
|
@@ -997,7 +997,7 @@ var import_promises = __toESM(require("fs/promises"), 1);
|
|
|
997
997
|
var package_default = {
|
|
998
998
|
name: "easyeda",
|
|
999
999
|
type: "module",
|
|
1000
|
-
version: "0.0.
|
|
1000
|
+
version: "0.0.261",
|
|
1001
1001
|
files: [
|
|
1002
1002
|
"dist"
|
|
1003
1003
|
],
|
|
@@ -7488,6 +7488,7 @@ var EasyEdaJsonSchema = import_zod163.z.object({
|
|
|
7488
7488
|
lcsc: LcscSchema,
|
|
7489
7489
|
owner: OwnerSchema,
|
|
7490
7490
|
tags: import_zod163.z.array(import_zod163.z.string()),
|
|
7491
|
+
category: import_zod163.z.string().optional(),
|
|
7491
7492
|
updateTime: import_zod163.z.number(),
|
|
7492
7493
|
updated_at: import_zod163.z.string(),
|
|
7493
7494
|
dataStr: DataStrSchema,
|
|
@@ -7704,7 +7705,11 @@ var getEasyEdaCadModelPlacement = async (easyEdaJson, { fetch: fetch2 = globalTh
|
|
|
7704
7705
|
};
|
|
7705
7706
|
|
|
7706
7707
|
// lib/websafe/generate-footprint-tsx.ts
|
|
7707
|
-
var
|
|
7708
|
+
var mapPortHints = (portHints, portHintsMap) => {
|
|
7709
|
+
if (!portHintsMap || !portHints) return portHints;
|
|
7710
|
+
return portHints.flatMap((hint) => portHintsMap[hint] ?? [hint]);
|
|
7711
|
+
};
|
|
7712
|
+
var generateFootprintTsx = (circuitJson, options = {}) => {
|
|
7708
7713
|
const holes = su(circuitJson).pcb_hole.list();
|
|
7709
7714
|
const platedHoles = su(circuitJson).pcb_plated_hole.list();
|
|
7710
7715
|
const smtPads = su(circuitJson).pcb_smtpad.list();
|
|
@@ -7727,36 +7732,36 @@ var generateFootprintTsx = (circuitJson) => {
|
|
|
7727
7732
|
const cccwRotationDegree = platedHole.ccw_rotation || 0;
|
|
7728
7733
|
const rotation2 = cccwRotationDegree ? ` pcbRotation="${cccwRotationDegree}deg"` : "";
|
|
7729
7734
|
elementStrings.push(
|
|
7730
|
-
`<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" holeWidth="${mmStr(platedHole.hole_width)}" holeHeight="${mmStr(platedHole.hole_height)}" outerWidth="${mmStr(platedHole.outer_width)}" outerHeight="${mmStr(platedHole.outer_height)}"${rotation2} shape="${platedHole.shape}" />`
|
|
7735
|
+
`<platedhole portHints={${JSON.stringify(mapPortHints(platedHole.port_hints, options.portHintsMap))}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" holeWidth="${mmStr(platedHole.hole_width)}" holeHeight="${mmStr(platedHole.hole_height)}" outerWidth="${mmStr(platedHole.outer_width)}" outerHeight="${mmStr(platedHole.outer_height)}"${rotation2} shape="${platedHole.shape}" />`
|
|
7731
7736
|
);
|
|
7732
7737
|
} else if (platedHole.shape === "pill_hole_with_rect_pad") {
|
|
7733
7738
|
elementStrings.push(
|
|
7734
|
-
`<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" holeWidth="${mmStr(platedHole.hole_width)}" holeHeight="${mmStr(platedHole.hole_height)}" outerWidth="${mmStr(platedHole.rect_pad_width)}" outerHeight="${mmStr(platedHole.rect_pad_height)}" shape="pill" />`
|
|
7739
|
+
`<platedhole portHints={${JSON.stringify(mapPortHints(platedHole.port_hints, options.portHintsMap))}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" holeWidth="${mmStr(platedHole.hole_width)}" holeHeight="${mmStr(platedHole.hole_height)}" outerWidth="${mmStr(platedHole.rect_pad_width)}" outerHeight="${mmStr(platedHole.rect_pad_height)}" shape="pill" />`
|
|
7735
7740
|
);
|
|
7736
7741
|
} else if (platedHole.shape === "circle") {
|
|
7737
7742
|
elementStrings.push(
|
|
7738
|
-
`<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" outerDiameter="${mmStr(platedHole.outer_diameter)}" holeDiameter="${mmStr(platedHole.hole_diameter)}" shape="circle" />`
|
|
7743
|
+
`<platedhole portHints={${JSON.stringify(mapPortHints(platedHole.port_hints, options.portHintsMap))}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" outerDiameter="${mmStr(platedHole.outer_diameter)}" holeDiameter="${mmStr(platedHole.hole_diameter)}" shape="circle" />`
|
|
7739
7744
|
);
|
|
7740
7745
|
} else if (platedHole.shape === "rotated_pill_hole_with_rect_pad") {
|
|
7741
7746
|
const rotation2 = platedHole.hole_ccw_rotation || 0;
|
|
7742
7747
|
elementStrings.push(
|
|
7743
|
-
`<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" holeWidth="${mmStr(platedHole.hole_width)}" holeHeight="${mmStr(platedHole.hole_height)}" outerWidth="${mmStr(platedHole.rect_pad_width)}" outerHeight="${mmStr(platedHole.rect_pad_height)}" rectPad={true} pcbRotation="${rotation2}deg" shape="pill" />`
|
|
7748
|
+
`<platedhole portHints={${JSON.stringify(mapPortHints(platedHole.port_hints, options.portHintsMap))}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" holeWidth="${mmStr(platedHole.hole_width)}" holeHeight="${mmStr(platedHole.hole_height)}" outerWidth="${mmStr(platedHole.rect_pad_width)}" outerHeight="${mmStr(platedHole.rect_pad_height)}" rectPad={true} pcbRotation="${rotation2}deg" shape="pill" />`
|
|
7744
7749
|
);
|
|
7745
7750
|
}
|
|
7746
7751
|
}
|
|
7747
7752
|
for (const smtPad of smtPads) {
|
|
7748
7753
|
if (smtPad.shape === "circle") {
|
|
7749
7754
|
elementStrings.push(
|
|
7750
|
-
`<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" radius="${mmStr(smtPad.radius)}" shape="circle" />`
|
|
7755
|
+
`<smtpad portHints={${JSON.stringify(mapPortHints(smtPad.port_hints, options.portHintsMap))}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" radius="${mmStr(smtPad.radius)}" shape="circle" />`
|
|
7751
7756
|
);
|
|
7752
7757
|
} else if (smtPad.shape === "rect") {
|
|
7753
7758
|
elementStrings.push(
|
|
7754
|
-
`<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}" shape="rect" />`
|
|
7759
|
+
`<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)}" shape="rect" />`
|
|
7755
7760
|
);
|
|
7756
7761
|
} else if (smtPad.shape === "polygon") {
|
|
7757
7762
|
const pointsStr = smtPad.points.map((p) => `{x: "${mmStr(p.x)}", y: "${mmStr(p.y)}"}`).join(", ");
|
|
7758
7763
|
elementStrings.push(
|
|
7759
|
-
`<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} points={[${pointsStr}]} shape="polygon" />`
|
|
7764
|
+
`<smtpad portHints={${JSON.stringify(mapPortHints(smtPad.port_hints, options.portHintsMap))}} points={[${pointsStr}]} shape="polygon" />`
|
|
7760
7765
|
);
|
|
7761
7766
|
}
|
|
7762
7767
|
}
|
|
@@ -7790,6 +7795,27 @@ var generateFootprintTsx = (circuitJson) => {
|
|
|
7790
7795
|
};
|
|
7791
7796
|
|
|
7792
7797
|
// lib/websafe/convert-to-typescript-component/generate-typescript-component.ts
|
|
7798
|
+
var getPinLabelValues = (labels) => {
|
|
7799
|
+
if (typeof labels === "string") return [labels];
|
|
7800
|
+
return [...labels];
|
|
7801
|
+
};
|
|
7802
|
+
var getDiodePortHintsMap = (pinLabels) => {
|
|
7803
|
+
const labelsByPin = Object.entries(pinLabels ?? {}).map(([pin, labels]) => ({
|
|
7804
|
+
pin,
|
|
7805
|
+
labels: getPinLabelValues(labels).map((label) => label.toLowerCase())
|
|
7806
|
+
}));
|
|
7807
|
+
const anodePin = labelsByPin.find(
|
|
7808
|
+
({ labels }) => labels.some((label) => ["a", "anode", "pos", "+"].includes(label))
|
|
7809
|
+
)?.pin;
|
|
7810
|
+
const cathodePin = labelsByPin.find(
|
|
7811
|
+
({ labels }) => labels.some((label) => ["c", "k", "cathode", "neg", "-"].includes(label))
|
|
7812
|
+
)?.pin;
|
|
7813
|
+
if (!anodePin || !cathodePin) return void 0;
|
|
7814
|
+
return {
|
|
7815
|
+
[anodePin]: ["pin1", "anode"],
|
|
7816
|
+
[cathodePin]: ["pin2", "cathode"]
|
|
7817
|
+
};
|
|
7818
|
+
};
|
|
7793
7819
|
var generateTypescriptComponent = ({
|
|
7794
7820
|
pinLabels,
|
|
7795
7821
|
componentName,
|
|
@@ -7797,11 +7823,15 @@ var generateTypescriptComponent = ({
|
|
|
7797
7823
|
stepUrl,
|
|
7798
7824
|
circuitJson,
|
|
7799
7825
|
supplierPartNumbers,
|
|
7800
|
-
manufacturerPartNumber
|
|
7826
|
+
manufacturerPartNumber,
|
|
7827
|
+
componentType = "chip"
|
|
7801
7828
|
}) => {
|
|
7802
7829
|
const safePinLabels = pinLabels ?? {};
|
|
7803
7830
|
const cadComponent = circuitJson.find((item) => item.type === "cad_component");
|
|
7804
|
-
const footprintTsx = generateFootprintTsx(
|
|
7831
|
+
const footprintTsx = generateFootprintTsx(
|
|
7832
|
+
circuitJson,
|
|
7833
|
+
componentType === "diode" ? { portHintsMap: getDiodePortHintsMap(safePinLabels) } : void 0
|
|
7834
|
+
);
|
|
7805
7835
|
const simplifiedPinLabels = Object.fromEntries(
|
|
7806
7836
|
Object.entries(safePinLabels).map(([pin, labels]) => {
|
|
7807
7837
|
if (Array.isArray(labels) && labels.length > 1) {
|
|
@@ -7817,6 +7847,28 @@ var generateTypescriptComponent = ({
|
|
|
7817
7847
|
`pcbRotationOffset: ${cadComponent?.rotation?.z ?? 0},`,
|
|
7818
7848
|
`modelOriginPosition: { x: ${cadComponent?.model_origin_position?.x ?? 0}, y: ${cadComponent?.model_origin_position?.y ?? 0}, z: ${cadComponent?.model_origin_position?.z ?? 0} },`
|
|
7819
7849
|
].filter(Boolean).map((line) => ` ${line}`).join("\n");
|
|
7850
|
+
if (componentType === "diode") {
|
|
7851
|
+
return `
|
|
7852
|
+
import type { DiodeProps } from "@tscircuit/props"
|
|
7853
|
+
|
|
7854
|
+
export const ${componentName} = (props: DiodeProps) => {
|
|
7855
|
+
const { name = "D1", ...restProps } = props
|
|
7856
|
+
|
|
7857
|
+
return (
|
|
7858
|
+
<diode
|
|
7859
|
+
name={name}
|
|
7860
|
+
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7861
|
+
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
7862
|
+
footprint={${footprintTsx}}
|
|
7863
|
+
${objUrl || stepUrl ? `cadModel={{
|
|
7864
|
+
${cadModelLines}
|
|
7865
|
+
}}` : ""}
|
|
7866
|
+
{...restProps}
|
|
7867
|
+
/>
|
|
7868
|
+
)
|
|
7869
|
+
}
|
|
7870
|
+
`.trim();
|
|
7871
|
+
}
|
|
7820
7872
|
return `
|
|
7821
7873
|
import type { ChipProps } from "@tscircuit/props"
|
|
7822
7874
|
|
|
@@ -7841,6 +7893,33 @@ ${cadModelLines}
|
|
|
7841
7893
|
`.trim();
|
|
7842
7894
|
};
|
|
7843
7895
|
|
|
7896
|
+
// lib/websafe/convert-to-typescript-component/category-value-contains-diode.ts
|
|
7897
|
+
var categoryValueContainsDiode = (value) => {
|
|
7898
|
+
if (typeof value === "string") {
|
|
7899
|
+
return /(^|[^a-z])diodes?([^a-z]|$)/i.test(value);
|
|
7900
|
+
}
|
|
7901
|
+
if (Array.isArray(value)) {
|
|
7902
|
+
return value.some(categoryValueContainsDiode);
|
|
7903
|
+
}
|
|
7904
|
+
if (value && typeof value === "object") {
|
|
7905
|
+
return Object.values(value).some(categoryValueContainsDiode);
|
|
7906
|
+
}
|
|
7907
|
+
return false;
|
|
7908
|
+
};
|
|
7909
|
+
|
|
7910
|
+
// lib/websafe/convert-to-typescript-component/is-diode-category-component.ts
|
|
7911
|
+
var isDiodeCategoryComponent = (betterEasy) => {
|
|
7912
|
+
const cPara = betterEasy.dataStr.head.c_para;
|
|
7913
|
+
return [
|
|
7914
|
+
betterEasy.tags,
|
|
7915
|
+
cPara.category,
|
|
7916
|
+
cPara.Category,
|
|
7917
|
+
cPara["LCSC Category"],
|
|
7918
|
+
cPara["JLCPCB Category"],
|
|
7919
|
+
betterEasy.category
|
|
7920
|
+
].some(categoryValueContainsDiode);
|
|
7921
|
+
};
|
|
7922
|
+
|
|
7844
7923
|
// lib/websafe/convert-to-typescript-component/index.tsx
|
|
7845
7924
|
var convertRawEasyToTsx = async ({ rawEasy }) => {
|
|
7846
7925
|
const betterEasy = EasyEdaJsonSchema.parse(rawEasy);
|
|
@@ -7905,7 +7984,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
7905
7984
|
objUrl: modelObjUrl,
|
|
7906
7985
|
stepUrl: modelStepUrl,
|
|
7907
7986
|
circuitJson,
|
|
7908
|
-
supplierPartNumbers
|
|
7987
|
+
supplierPartNumbers,
|
|
7988
|
+
componentType: isDiodeCategoryComponent(betterEasy) ? "diode" : "chip"
|
|
7909
7989
|
});
|
|
7910
7990
|
};
|
|
7911
7991
|
var checkModelObjUrlValidity = async (url) => {
|