easyeda 0.0.261 → 0.0.263
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 +145 -11
- package/dist/browser/index.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +145 -11
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +146 -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.262",
|
|
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 getPolarizedPortHintsMap = (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" || componentType === "led" ? { portHintsMap: getPolarizedPortHintsMap(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,50 @@ 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
|
+
}
|
|
7872
|
+
if (componentType === "led") {
|
|
7873
|
+
return `
|
|
7874
|
+
import type { LedProps } from "@tscircuit/props"
|
|
7875
|
+
|
|
7876
|
+
export const ${componentName} = (props: LedProps) => {
|
|
7877
|
+
const { name = "LED1", ...restProps } = props
|
|
7878
|
+
|
|
7879
|
+
return (
|
|
7880
|
+
<led
|
|
7881
|
+
name={name}
|
|
7882
|
+
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7883
|
+
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
7884
|
+
footprint={${footprintTsx}}
|
|
7885
|
+
${objUrl || stepUrl ? `cadModel={{
|
|
7886
|
+
${cadModelLines}
|
|
7887
|
+
}}` : ""}
|
|
7888
|
+
{...restProps}
|
|
7889
|
+
/>
|
|
7890
|
+
)
|
|
7891
|
+
}
|
|
7892
|
+
`.trim();
|
|
7893
|
+
}
|
|
7820
7894
|
return `
|
|
7821
7895
|
import type { ChipProps } from "@tscircuit/props"
|
|
7822
7896
|
|
|
@@ -7841,7 +7915,66 @@ ${cadModelLines}
|
|
|
7841
7915
|
`.trim();
|
|
7842
7916
|
};
|
|
7843
7917
|
|
|
7918
|
+
// lib/websafe/convert-to-typescript-component/category-value-contains-diode.ts
|
|
7919
|
+
var categoryValueContainsDiode = (value) => {
|
|
7920
|
+
if (typeof value === "string") {
|
|
7921
|
+
return /(^|[^a-z])diodes?([^a-z]|$)/i.test(value);
|
|
7922
|
+
}
|
|
7923
|
+
if (Array.isArray(value)) {
|
|
7924
|
+
return value.some(categoryValueContainsDiode);
|
|
7925
|
+
}
|
|
7926
|
+
if (value && typeof value === "object") {
|
|
7927
|
+
return Object.values(value).some(categoryValueContainsDiode);
|
|
7928
|
+
}
|
|
7929
|
+
return false;
|
|
7930
|
+
};
|
|
7931
|
+
|
|
7932
|
+
// lib/websafe/convert-to-typescript-component/is-diode-category-component.ts
|
|
7933
|
+
var isDiodeCategoryComponent = (betterEasy) => {
|
|
7934
|
+
const cPara = betterEasy.dataStr.head.c_para;
|
|
7935
|
+
return [
|
|
7936
|
+
betterEasy.tags,
|
|
7937
|
+
cPara.category,
|
|
7938
|
+
cPara.Category,
|
|
7939
|
+
cPara["LCSC Category"],
|
|
7940
|
+
cPara["JLCPCB Category"],
|
|
7941
|
+
betterEasy.category
|
|
7942
|
+
].some(categoryValueContainsDiode);
|
|
7943
|
+
};
|
|
7944
|
+
|
|
7945
|
+
// lib/websafe/convert-to-typescript-component/category-value-contains-led.ts
|
|
7946
|
+
var categoryValueContainsLed = (value) => {
|
|
7947
|
+
if (typeof value === "string") {
|
|
7948
|
+
return /(^|[^a-z])leds?([^a-z]|$)/i.test(value) || /light[-\s]?emitting\s+diodes?/i.test(value);
|
|
7949
|
+
}
|
|
7950
|
+
if (Array.isArray(value)) {
|
|
7951
|
+
return value.some(categoryValueContainsLed);
|
|
7952
|
+
}
|
|
7953
|
+
if (value && typeof value === "object") {
|
|
7954
|
+
return Object.values(value).some(categoryValueContainsLed);
|
|
7955
|
+
}
|
|
7956
|
+
return false;
|
|
7957
|
+
};
|
|
7958
|
+
|
|
7959
|
+
// lib/websafe/convert-to-typescript-component/is-led-category-component.ts
|
|
7960
|
+
var isLedCategoryComponent = (betterEasy) => {
|
|
7961
|
+
const cPara = betterEasy.dataStr.head.c_para;
|
|
7962
|
+
return [
|
|
7963
|
+
betterEasy.tags,
|
|
7964
|
+
cPara.category,
|
|
7965
|
+
cPara.Category,
|
|
7966
|
+
cPara["LCSC Category"],
|
|
7967
|
+
cPara["JLCPCB Category"],
|
|
7968
|
+
betterEasy.category
|
|
7969
|
+
].some(categoryValueContainsLed);
|
|
7970
|
+
};
|
|
7971
|
+
|
|
7844
7972
|
// lib/websafe/convert-to-typescript-component/index.tsx
|
|
7973
|
+
var getGeneratedComponentType = (betterEasy) => {
|
|
7974
|
+
if (isLedCategoryComponent(betterEasy)) return "led";
|
|
7975
|
+
if (isDiodeCategoryComponent(betterEasy)) return "diode";
|
|
7976
|
+
return "chip";
|
|
7977
|
+
};
|
|
7845
7978
|
var convertRawEasyToTsx = async ({ rawEasy }) => {
|
|
7846
7979
|
const betterEasy = EasyEdaJsonSchema.parse(rawEasy);
|
|
7847
7980
|
const result = await convertBetterEasyToTsx({
|
|
@@ -7905,7 +8038,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
7905
8038
|
objUrl: modelObjUrl,
|
|
7906
8039
|
stepUrl: modelStepUrl,
|
|
7907
8040
|
circuitJson,
|
|
7908
|
-
supplierPartNumbers
|
|
8041
|
+
supplierPartNumbers,
|
|
8042
|
+
componentType: getGeneratedComponentType(betterEasy)
|
|
7909
8043
|
});
|
|
7910
8044
|
};
|
|
7911
8045
|
var checkModelObjUrlValidity = async (url) => {
|