easyeda 0.0.303 → 0.0.305
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.js +74 -9
- package/dist/browser/index.js.map +1 -1
- package/dist/index.js +74 -9
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +75 -10
- package/dist/main.cjs.map +1 -1
- package/package.json +1 -1
package/dist/main.cjs
CHANGED
|
@@ -3528,7 +3528,7 @@ var import_promises = __toESM(require("fs/promises"), 1);
|
|
|
3528
3528
|
var package_default = {
|
|
3529
3529
|
name: "easyeda",
|
|
3530
3530
|
type: "module",
|
|
3531
|
-
version: "0.0.
|
|
3531
|
+
version: "0.0.304",
|
|
3532
3532
|
files: [
|
|
3533
3533
|
"dist"
|
|
3534
3534
|
],
|
|
@@ -9443,6 +9443,27 @@ var isLedCategoryComponent = (betterEasy) => {
|
|
|
9443
9443
|
].some(categoryValueContainsLed);
|
|
9444
9444
|
};
|
|
9445
9445
|
|
|
9446
|
+
// node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
|
|
9447
|
+
function distance2(p1, p2) {
|
|
9448
|
+
const dx = p1.x - p2.x;
|
|
9449
|
+
const dy = p1.y - p2.y;
|
|
9450
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
9451
|
+
}
|
|
9452
|
+
|
|
9453
|
+
// node_modules/@tscircuit/math-utils/dist/chunk-GIGMPRPV.js
|
|
9454
|
+
var getUnitVectorFromDirection = (direction) => {
|
|
9455
|
+
switch (direction) {
|
|
9456
|
+
case "up":
|
|
9457
|
+
return { x: 0, y: 1 };
|
|
9458
|
+
case "down":
|
|
9459
|
+
return { x: 0, y: -1 };
|
|
9460
|
+
case "left":
|
|
9461
|
+
return { x: -1, y: 0 };
|
|
9462
|
+
case "right":
|
|
9463
|
+
return { x: 1, y: 0 };
|
|
9464
|
+
}
|
|
9465
|
+
};
|
|
9466
|
+
|
|
9446
9467
|
// node_modules/@tscircuit/math-utils/dist/chunk-3WCUPG5S.js
|
|
9447
9468
|
var getBoundsCenter = (bounds) => ({
|
|
9448
9469
|
x: (bounds.minX + bounds.maxX) / 2,
|
|
@@ -11110,7 +11131,9 @@ var generateFootprintTsx = (circuitJson, options = {}) => {
|
|
|
11110
11131
|
`<hole pcbX="${mmStr(hole.x)}" pcbY="${mmStr(hole.y)}" diameter="${mmStr(hole.hole_diameter)}" />`
|
|
11111
11132
|
);
|
|
11112
11133
|
} else if (hole.hole_shape === "oval") {
|
|
11113
|
-
|
|
11134
|
+
elementStrings.push(
|
|
11135
|
+
`<hole pcbX="${mmStr(hole.x)}" pcbY="${mmStr(hole.y)}" width="${mmStr(hole.hole_width)}" height="${mmStr(hole.hole_height)}" shape="oval" />`
|
|
11136
|
+
);
|
|
11114
11137
|
}
|
|
11115
11138
|
}
|
|
11116
11139
|
for (const platedHole of platedHoles) {
|
|
@@ -11765,6 +11788,36 @@ var getPinStemLength = (path) => {
|
|
|
11765
11788
|
if (!segment) return void 0;
|
|
11766
11789
|
return toSchematicUnits(Math.abs(Number(segment[1])));
|
|
11767
11790
|
};
|
|
11791
|
+
var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
|
|
11792
|
+
if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
|
|
11793
|
+
const first = shape.points[0];
|
|
11794
|
+
const last = shape.points[shape.points.length - 1];
|
|
11795
|
+
if (first.x === last.x && first.y === last.y) return [];
|
|
11796
|
+
return [transformPoint(first), transformPoint(last)];
|
|
11797
|
+
});
|
|
11798
|
+
var alignPortToDrawing = ({
|
|
11799
|
+
position: position2,
|
|
11800
|
+
direction,
|
|
11801
|
+
stemLength,
|
|
11802
|
+
drawingEndpoints
|
|
11803
|
+
}) => {
|
|
11804
|
+
if (stemLength === void 0) return position2;
|
|
11805
|
+
const outwardDirection = getUnitVectorFromDirection(direction);
|
|
11806
|
+
const expectedBodyConnection = {
|
|
11807
|
+
x: position2.x - outwardDirection.x * stemLength,
|
|
11808
|
+
y: position2.y - outwardDirection.y * stemLength
|
|
11809
|
+
};
|
|
11810
|
+
const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
|
|
11811
|
+
const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
|
|
11812
|
+
endpoint,
|
|
11813
|
+
distance: distance2(endpoint, expectedBodyConnection)
|
|
11814
|
+
})).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
|
|
11815
|
+
if (!nearestEndpoint) return position2;
|
|
11816
|
+
return {
|
|
11817
|
+
x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
|
|
11818
|
+
y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
|
|
11819
|
+
};
|
|
11820
|
+
};
|
|
11768
11821
|
var getTextFontSize = (fontSize) => {
|
|
11769
11822
|
const numericFontSize = Number.parseFloat(fontSize);
|
|
11770
11823
|
if (!Number.isFinite(numericFontSize)) return 0.2;
|
|
@@ -11839,7 +11892,8 @@ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
|
|
|
11839
11892
|
var generateShapeTsx = ({
|
|
11840
11893
|
shape,
|
|
11841
11894
|
origin,
|
|
11842
|
-
portMetadata
|
|
11895
|
+
portMetadata,
|
|
11896
|
+
drawingEndpoints = []
|
|
11843
11897
|
}) => {
|
|
11844
11898
|
const transformPoint = getPointTransformer(origin);
|
|
11845
11899
|
if (shape.type === "RECTANGLE") {
|
|
@@ -11875,17 +11929,26 @@ var generateShapeTsx = ({
|
|
|
11875
11929
|
return `<schematictext schX={${position2.x}} schY={${position2.y}} text=${JSON.stringify(shape.content)} fontSize={${getTextFontSize(shape.fontSize)}} anchor=${JSON.stringify(getTextAnchor(shape.alignment))} color=${JSON.stringify(shape.fontColor)} schRotation={${round(-shape.rotation)}} />`;
|
|
11876
11930
|
}
|
|
11877
11931
|
if (shape.type === "PIN" && portMetadata) {
|
|
11878
|
-
const
|
|
11932
|
+
const direction = getPinDirection(shape.rotation);
|
|
11933
|
+
const stemLength = getPinStemLength(shape.path);
|
|
11934
|
+
const position2 = alignPortToDrawing({
|
|
11935
|
+
position: transformPoint({ x: shape.x, y: shape.y }),
|
|
11936
|
+
direction,
|
|
11937
|
+
stemLength,
|
|
11938
|
+
drawingEndpoints
|
|
11939
|
+
});
|
|
11879
11940
|
const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
|
|
11880
11941
|
const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
|
|
11881
|
-
const stemLength = getPinStemLength(shape.path);
|
|
11882
11942
|
const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
|
|
11883
|
-
return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(
|
|
11943
|
+
return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
|
|
11884
11944
|
}
|
|
11885
11945
|
if (shape.type === "IGNORED") return void 0;
|
|
11886
11946
|
return void 0;
|
|
11887
11947
|
};
|
|
11888
|
-
var generateSymbolTsx = (easyEdaJson, circuitJson, {
|
|
11948
|
+
var generateSymbolTsx = (easyEdaJson, circuitJson, {
|
|
11949
|
+
includePorts = true,
|
|
11950
|
+
alignPortsToDrawing = false
|
|
11951
|
+
} = {}) => {
|
|
11889
11952
|
const shapes = easyEdaJson.dataStr.shape;
|
|
11890
11953
|
if (shapes.length === 0) return void 0;
|
|
11891
11954
|
const headOrigin = {
|
|
@@ -11902,11 +11965,14 @@ var generateSymbolTsx = (easyEdaJson, circuitJson, { includePorts = true } = {})
|
|
|
11902
11965
|
easyEdaJson,
|
|
11903
11966
|
circuitJson
|
|
11904
11967
|
);
|
|
11968
|
+
const transformPoint = getPointTransformer(origin);
|
|
11969
|
+
const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
|
|
11905
11970
|
const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
|
|
11906
11971
|
(shape) => generateShapeTsx({
|
|
11907
11972
|
shape,
|
|
11908
11973
|
origin,
|
|
11909
|
-
portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
|
|
11974
|
+
portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
|
|
11975
|
+
drawingEndpoints
|
|
11910
11976
|
})
|
|
11911
11977
|
).filter((tsx) => Boolean(tsx));
|
|
11912
11978
|
if (shapeTsx.length === 0) return void 0;
|
|
@@ -12015,8 +12081,7 @@ var convertBetterEasyToTsx = async ({
|
|
|
12015
12081
|
const isMultiPinDiode = isDiodeCategoryComponent(betterEasy) && sourcePorts.length !== 2;
|
|
12016
12082
|
const isPassiveWithCustomSymbol = componentType === "capacitor" || componentType === "resistor";
|
|
12017
12083
|
const symbolTsx = isPassiveWithCustomSymbol || componentType === "chip" && !isMultiPinDiode && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson, {
|
|
12018
|
-
|
|
12019
|
-
includePorts: !isPassiveWithCustomSymbol
|
|
12084
|
+
alignPortsToDrawing: isPassiveWithCustomSymbol
|
|
12020
12085
|
}) : void 0;
|
|
12021
12086
|
return generateTypescriptComponent({
|
|
12022
12087
|
componentName,
|