easyeda 0.0.273 → 0.0.275
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 +33 -0
- package/dist/browser/index.js +340 -27
- package/dist/browser/index.js.map +1 -1
- package/dist/index.d.ts +33 -0
- package/dist/index.js +340 -27
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +342 -29
- package/dist/main.cjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6969,10 +6969,11 @@ var RectangleShapeOutputSchema = z180.object({
|
|
|
6969
6969
|
height: z180.number(),
|
|
6970
6970
|
color: z180.string(),
|
|
6971
6971
|
lineWidth: z180.number(),
|
|
6972
|
+
fillColor: z180.string().optional(),
|
|
6972
6973
|
id: z180.string()
|
|
6973
6974
|
});
|
|
6974
6975
|
var parseRectangle = (str) => {
|
|
6975
|
-
const [, x, y, , , width, height, color, lineWidth, , , id] = str.split("~");
|
|
6976
|
+
const [, x, y, , , width, height, color, lineWidth, , fillColor, id] = str.split("~");
|
|
6976
6977
|
return {
|
|
6977
6978
|
type: "RECTANGLE",
|
|
6978
6979
|
position: { x: Number(x), y: Number(y) },
|
|
@@ -6980,6 +6981,7 @@ var parseRectangle = (str) => {
|
|
|
6980
6981
|
height: Number(height),
|
|
6981
6982
|
color,
|
|
6982
6983
|
lineWidth: Number(lineWidth),
|
|
6984
|
+
fillColor,
|
|
6983
6985
|
id
|
|
6984
6986
|
};
|
|
6985
6987
|
};
|
|
@@ -6991,10 +6993,11 @@ var EllipseShapeOutputSchema = z180.object({
|
|
|
6991
6993
|
radiusY: z180.number(),
|
|
6992
6994
|
color: z180.string(),
|
|
6993
6995
|
lineWidth: z180.number(),
|
|
6996
|
+
fillColor: z180.string().optional(),
|
|
6994
6997
|
id: z180.string()
|
|
6995
6998
|
});
|
|
6996
6999
|
var parseEllipse = (str) => {
|
|
6997
|
-
const [, x, y, radiusX, radiusY, color, lineWidth, , , id] = str.split("~");
|
|
7000
|
+
const [, x, y, radiusX, radiusY, color, lineWidth, , fillColor, id] = str.split("~");
|
|
6998
7001
|
return {
|
|
6999
7002
|
type: "ELLIPSE",
|
|
7000
7003
|
center: { x: Number(x), y: Number(y) },
|
|
@@ -7002,12 +7005,14 @@ var parseEllipse = (str) => {
|
|
|
7002
7005
|
radiusY: Number(radiusY),
|
|
7003
7006
|
color,
|
|
7004
7007
|
lineWidth: Number(lineWidth),
|
|
7008
|
+
fillColor,
|
|
7005
7009
|
id
|
|
7006
7010
|
};
|
|
7007
7011
|
};
|
|
7008
7012
|
var EllipseShapeSchema = z180.string().startsWith("E~").transform(parseEllipse).pipe(EllipseShapeOutputSchema);
|
|
7009
7013
|
var ArcShapeOutputSchema = z180.object({
|
|
7010
7014
|
type: z180.literal("ARC"),
|
|
7015
|
+
pathData: z180.string(),
|
|
7011
7016
|
start: PointSchema2,
|
|
7012
7017
|
end: PointSchema2,
|
|
7013
7018
|
radius: z180.number(),
|
|
@@ -7017,26 +7022,25 @@ var ArcShapeOutputSchema = z180.object({
|
|
|
7017
7022
|
id: z180.string()
|
|
7018
7023
|
});
|
|
7019
7024
|
var parseArc = (str) => {
|
|
7020
|
-
const [, pathData,
|
|
7021
|
-
const
|
|
7022
|
-
const
|
|
7023
|
-
const
|
|
7024
|
-
const
|
|
7025
|
-
const
|
|
7026
|
-
const x2 =
|
|
7027
|
-
const y2 = Number(parts[9]) || 0;
|
|
7025
|
+
const [, pathData, ...fields] = str.split("~");
|
|
7026
|
+
const colorIndex = fields.findIndex((field) => /^#[0-9a-f]{6}$/i.test(field));
|
|
7027
|
+
const color = fields[colorIndex] || "#880000";
|
|
7028
|
+
const lineWidth = fields[colorIndex + 1];
|
|
7029
|
+
const id = fields.find((field) => /^(?:gge|rep)/.test(field)) || "gge1";
|
|
7030
|
+
const numbers = pathData.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
|
|
7031
|
+
const [x1 = 0, y1 = 0, radius = 0, , , , sweepFlag = 0, x2 = 0, y2 = 0] = numbers;
|
|
7028
7032
|
const parsedLineWidth = Number(lineWidth);
|
|
7029
7033
|
const finalLineWidth = Number.isNaN(parsedLineWidth) ? 1 : parsedLineWidth;
|
|
7030
7034
|
return {
|
|
7031
7035
|
type: "ARC",
|
|
7036
|
+
pathData,
|
|
7032
7037
|
start: { x: x1, y: y1 },
|
|
7033
7038
|
end: { x: x2, y: y2 },
|
|
7034
7039
|
radius,
|
|
7035
|
-
sweepFlag,
|
|
7036
|
-
color
|
|
7037
|
-
// Default color
|
|
7040
|
+
sweepFlag: sweepFlag === 1,
|
|
7041
|
+
color,
|
|
7038
7042
|
lineWidth: finalLineWidth,
|
|
7039
|
-
id
|
|
7043
|
+
id
|
|
7040
7044
|
};
|
|
7041
7045
|
};
|
|
7042
7046
|
var ArcShapeSchema = z180.string().startsWith("A~").transform(parseArc).pipe(ArcShapeOutputSchema);
|
|
@@ -7064,8 +7068,7 @@ var parsePin = (pinString) => {
|
|
|
7064
7068
|
if (/^\+\d+(?:\.\d+)?V$/i.test(label)) label = `V${label.slice(1, -1)}`;
|
|
7065
7069
|
const colorMatch = pinString.match(/#[0-9A-F]{6}/);
|
|
7066
7070
|
const labelColor = colorMatch ? colorMatch[0] : "";
|
|
7067
|
-
const
|
|
7068
|
-
const path = pathMatch ? pathMatch[1] : "";
|
|
7071
|
+
const path = pinString.split("^^")[2]?.split("~")[0] ?? "";
|
|
7069
7072
|
const arrowMatch = pinString.match(/\^\^0~(.+)$/);
|
|
7070
7073
|
const arrow = arrowMatch ? arrowMatch[1] : "";
|
|
7071
7074
|
const r = Number.parseFloat(rotation2);
|
|
@@ -7123,7 +7126,7 @@ var PolygonShapeOutputSchema = z180.object({
|
|
|
7123
7126
|
});
|
|
7124
7127
|
var parsePolygon = (str) => {
|
|
7125
7128
|
const [, ...rest] = str.split("~");
|
|
7126
|
-
const [pointsStr,
|
|
7129
|
+
const [pointsStr, lineColor, lineWidth, , fillColor, id] = rest;
|
|
7127
7130
|
return {
|
|
7128
7131
|
type: "POLYGON",
|
|
7129
7132
|
points: parsePoints2(pointsStr),
|
|
@@ -7143,7 +7146,7 @@ var PathShapeOutputSchema = z180.object({
|
|
|
7143
7146
|
id: z180.string()
|
|
7144
7147
|
});
|
|
7145
7148
|
var parsePath = (str) => {
|
|
7146
|
-
const [, pathData,
|
|
7149
|
+
const [, pathData, strokeColor, strokeWidth, , fillColor, id] = str.split("~");
|
|
7147
7150
|
return {
|
|
7148
7151
|
type: "PATH",
|
|
7149
7152
|
pathData,
|
|
@@ -7193,8 +7196,8 @@ var parseText = (str) => {
|
|
|
7193
7196
|
fontWeight,
|
|
7194
7197
|
fontStyle,
|
|
7195
7198
|
fontDecoration,
|
|
7196
|
-
content,
|
|
7197
7199
|
textType,
|
|
7200
|
+
content,
|
|
7198
7201
|
visibility,
|
|
7199
7202
|
mirror,
|
|
7200
7203
|
id
|
|
@@ -7604,6 +7607,7 @@ var getPinLabelValues = (labels) => {
|
|
|
7604
7607
|
if (typeof labels === "string") return [labels];
|
|
7605
7608
|
return [...labels];
|
|
7606
7609
|
};
|
|
7610
|
+
var stripEasyEdaPolarityHintDecoration = (label) => label.toLowerCase().replace(/[^a-z0-9+-]/g, "");
|
|
7607
7611
|
var getPinKeySortValue = (pinKey) => {
|
|
7608
7612
|
const match = /^pin(\d+)$/i.exec(pinKey);
|
|
7609
7613
|
return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;
|
|
@@ -7611,7 +7615,7 @@ var getPinKeySortValue = (pinKey) => {
|
|
|
7611
7615
|
var getPolarizedPinMetadata = (pinLabels) => {
|
|
7612
7616
|
const labelsByPin = Object.entries(pinLabels ?? {}).map(([pin, labels]) => ({
|
|
7613
7617
|
pin,
|
|
7614
|
-
labels: getPinLabelValues(labels).map(
|
|
7618
|
+
labels: getPinLabelValues(labels).map(stripEasyEdaPolarityHintDecoration)
|
|
7615
7619
|
}));
|
|
7616
7620
|
const anodePin = labelsByPin.find(
|
|
7617
7621
|
({ labels }) => labels.some((label) => ["a", "anode", "pos", "+"].includes(label))
|
|
@@ -7641,7 +7645,8 @@ var generateTypescriptComponent = ({
|
|
|
7641
7645
|
circuitJson,
|
|
7642
7646
|
supplierPartNumbers,
|
|
7643
7647
|
manufacturerPartNumber,
|
|
7644
|
-
componentType = "chip"
|
|
7648
|
+
componentType = "chip",
|
|
7649
|
+
symbolTsx
|
|
7645
7650
|
}) => {
|
|
7646
7651
|
const safePinLabels = pinLabels ?? {};
|
|
7647
7652
|
const polarizedPinMetadata = getPolarizedPinMetadata(safePinLabels);
|
|
@@ -7668,6 +7673,10 @@ ${polarizedPinLabelsString}
|
|
|
7668
7673
|
|
|
7669
7674
|
` : "";
|
|
7670
7675
|
const polarizedPinLabelsProp = polarizedPinLabels ? ` pinLabels={pinLabels}
|
|
7676
|
+
` : "";
|
|
7677
|
+
const symbolProp = symbolTsx ? ` symbol={
|
|
7678
|
+
${symbolTsx.split("\n").map((line) => ` ${line}`).join("\n")}
|
|
7679
|
+
}
|
|
7671
7680
|
` : "";
|
|
7672
7681
|
const cadModelLines = [
|
|
7673
7682
|
objUrl ? `objUrl: "${objUrl}",` : "",
|
|
@@ -7685,7 +7694,7 @@ ${polarizedPinLabelsBlock}export const ${componentName} = (props: DiodeProps) =>
|
|
|
7685
7694
|
return (
|
|
7686
7695
|
<diode
|
|
7687
7696
|
name={name}
|
|
7688
|
-
${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7697
|
+
${polarizedPinLabelsProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7689
7698
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
7690
7699
|
footprint={${footprintTsx}}
|
|
7691
7700
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -7707,7 +7716,7 @@ ${polarizedPinLabelsBlock}export const ${componentName} = (props: LedProps) => {
|
|
|
7707
7716
|
return (
|
|
7708
7717
|
<led
|
|
7709
7718
|
name={name}
|
|
7710
|
-
${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7719
|
+
${polarizedPinLabelsProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7711
7720
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
7712
7721
|
footprint={${footprintTsx}}
|
|
7713
7722
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -7734,7 +7743,7 @@ export const ${componentName} = (props: PushButtonProps<typeof pinLabels>) => {
|
|
|
7734
7743
|
<pushbutton
|
|
7735
7744
|
name={name}
|
|
7736
7745
|
pinLabels={pinLabels}
|
|
7737
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7746
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7738
7747
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
7739
7748
|
footprint={${footprintTsx}}
|
|
7740
7749
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -7761,7 +7770,7 @@ export const ${componentName} = (props: SwitchProps) => {
|
|
|
7761
7770
|
<switch
|
|
7762
7771
|
name={name}
|
|
7763
7772
|
pinLabels={pinLabels}
|
|
7764
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7773
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7765
7774
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
7766
7775
|
footprint={${footprintTsx}}
|
|
7767
7776
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -7784,7 +7793,7 @@ export const ${componentName} = (props: ChipProps<typeof pinLabels>) => {
|
|
|
7784
7793
|
return (
|
|
7785
7794
|
<chip
|
|
7786
7795
|
pinLabels={pinLabels}
|
|
7787
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7796
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7788
7797
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
7789
7798
|
footprint={${footprintTsx}}
|
|
7790
7799
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -7913,6 +7922,307 @@ var isSwitchCategoryComponent = (betterEasy) => {
|
|
|
7913
7922
|
].some(categoryValueContainsSwitch);
|
|
7914
7923
|
};
|
|
7915
7924
|
|
|
7925
|
+
// lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
|
|
7926
|
+
var round = (value) => Number(value.toFixed(6));
|
|
7927
|
+
var toMillimeters = (value) => round(mil10ToMm(value));
|
|
7928
|
+
var getPointTransformer = (origin) => (point2) => ({
|
|
7929
|
+
x: toMillimeters(point2.x - origin.x),
|
|
7930
|
+
y: toMillimeters(origin.y - point2.y)
|
|
7931
|
+
});
|
|
7932
|
+
var formatNumber = (value) => String(round(value));
|
|
7933
|
+
var SVG_PATH_COMMAND_PARAMETER_COUNTS = {
|
|
7934
|
+
A: 7,
|
|
7935
|
+
C: 6,
|
|
7936
|
+
H: 1,
|
|
7937
|
+
L: 2,
|
|
7938
|
+
M: 2,
|
|
7939
|
+
Q: 4,
|
|
7940
|
+
S: 4,
|
|
7941
|
+
T: 2,
|
|
7942
|
+
V: 1,
|
|
7943
|
+
Z: 0
|
|
7944
|
+
};
|
|
7945
|
+
var transformSvgPath = (pathData, origin) => {
|
|
7946
|
+
const tokens = pathData.match(
|
|
7947
|
+
/[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g
|
|
7948
|
+
) ?? [];
|
|
7949
|
+
const output = [];
|
|
7950
|
+
let command = "";
|
|
7951
|
+
let tokenIndex = 0;
|
|
7952
|
+
let currentX = 0;
|
|
7953
|
+
let currentY = 0;
|
|
7954
|
+
let subpathStartX = 0;
|
|
7955
|
+
let subpathStartY = 0;
|
|
7956
|
+
const transformPoint = getPointTransformer(origin);
|
|
7957
|
+
const getOriginalPoint = (x, y, isRelative) => ({
|
|
7958
|
+
x: isRelative ? currentX + x : x,
|
|
7959
|
+
y: isRelative ? currentY + y : y
|
|
7960
|
+
});
|
|
7961
|
+
while (tokenIndex < tokens.length) {
|
|
7962
|
+
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) {
|
|
7963
|
+
command = tokens[tokenIndex];
|
|
7964
|
+
tokenIndex += 1;
|
|
7965
|
+
}
|
|
7966
|
+
if (!command) break;
|
|
7967
|
+
const upperCommand = command.toUpperCase();
|
|
7968
|
+
const parameterCount = SVG_PATH_COMMAND_PARAMETER_COUNTS[upperCommand];
|
|
7969
|
+
if (parameterCount === void 0) break;
|
|
7970
|
+
if (upperCommand === "Z") {
|
|
7971
|
+
output.push("Z");
|
|
7972
|
+
currentX = subpathStartX;
|
|
7973
|
+
currentY = subpathStartY;
|
|
7974
|
+
command = "";
|
|
7975
|
+
continue;
|
|
7976
|
+
}
|
|
7977
|
+
if (tokenIndex + parameterCount > tokens.length) break;
|
|
7978
|
+
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) continue;
|
|
7979
|
+
const values = tokens.slice(tokenIndex, tokenIndex + parameterCount).map(Number);
|
|
7980
|
+
tokenIndex += parameterCount;
|
|
7981
|
+
const isRelative = command === command.toLowerCase();
|
|
7982
|
+
if (upperCommand === "H" || upperCommand === "V") {
|
|
7983
|
+
const point2 = getOriginalPoint(
|
|
7984
|
+
upperCommand === "H" ? values[0] : isRelative ? 0 : currentX,
|
|
7985
|
+
upperCommand === "V" ? values[0] : isRelative ? 0 : currentY,
|
|
7986
|
+
isRelative
|
|
7987
|
+
);
|
|
7988
|
+
const transformed = transformPoint(point2);
|
|
7989
|
+
output.push(
|
|
7990
|
+
`L ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
7991
|
+
);
|
|
7992
|
+
currentX = point2.x;
|
|
7993
|
+
currentY = point2.y;
|
|
7994
|
+
continue;
|
|
7995
|
+
}
|
|
7996
|
+
if (["M", "L", "T"].includes(upperCommand)) {
|
|
7997
|
+
const point2 = getOriginalPoint(values[0], values[1], isRelative);
|
|
7998
|
+
const transformed = transformPoint(point2);
|
|
7999
|
+
output.push(
|
|
8000
|
+
`${upperCommand} ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
8001
|
+
);
|
|
8002
|
+
currentX = point2.x;
|
|
8003
|
+
currentY = point2.y;
|
|
8004
|
+
if (upperCommand === "M") {
|
|
8005
|
+
subpathStartX = point2.x;
|
|
8006
|
+
subpathStartY = point2.y;
|
|
8007
|
+
command = isRelative ? "l" : "L";
|
|
8008
|
+
}
|
|
8009
|
+
continue;
|
|
8010
|
+
}
|
|
8011
|
+
if (["C", "S", "Q"].includes(upperCommand)) {
|
|
8012
|
+
const transformedValues = [];
|
|
8013
|
+
for (let valueIndex = 0; valueIndex < values.length; valueIndex += 2) {
|
|
8014
|
+
const point2 = getOriginalPoint(
|
|
8015
|
+
values[valueIndex],
|
|
8016
|
+
values[valueIndex + 1],
|
|
8017
|
+
isRelative
|
|
8018
|
+
);
|
|
8019
|
+
const transformed = transformPoint(point2);
|
|
8020
|
+
transformedValues.push(transformed.x, transformed.y);
|
|
8021
|
+
}
|
|
8022
|
+
output.push(
|
|
8023
|
+
`${upperCommand} ${transformedValues.map(formatNumber).join(" ")}`
|
|
8024
|
+
);
|
|
8025
|
+
currentX = isRelative ? currentX + values[values.length - 2] : values[values.length - 2];
|
|
8026
|
+
currentY = isRelative ? currentY + values[values.length - 1] : values[values.length - 1];
|
|
8027
|
+
continue;
|
|
8028
|
+
}
|
|
8029
|
+
if (upperCommand === "A") {
|
|
8030
|
+
const endpoint = getOriginalPoint(values[5], values[6], isRelative);
|
|
8031
|
+
const transformedEndpoint = transformPoint(endpoint);
|
|
8032
|
+
output.push(
|
|
8033
|
+
[
|
|
8034
|
+
"A",
|
|
8035
|
+
formatNumber(toMillimeters(Math.abs(values[0]))),
|
|
8036
|
+
formatNumber(toMillimeters(Math.abs(values[1]))),
|
|
8037
|
+
formatNumber(-values[2]),
|
|
8038
|
+
String(values[3]),
|
|
8039
|
+
String(values[4] === 0 ? 1 : 0),
|
|
8040
|
+
formatNumber(transformedEndpoint.x),
|
|
8041
|
+
formatNumber(transformedEndpoint.y)
|
|
8042
|
+
].join(" ")
|
|
8043
|
+
);
|
|
8044
|
+
currentX = endpoint.x;
|
|
8045
|
+
currentY = endpoint.y;
|
|
8046
|
+
}
|
|
8047
|
+
}
|
|
8048
|
+
return output.join(" ");
|
|
8049
|
+
};
|
|
8050
|
+
var getPinDirection = (rotation2) => {
|
|
8051
|
+
const normalizedRotation = (rotation2 % 360 + 360) % 360;
|
|
8052
|
+
if (normalizedRotation === 90) return "up";
|
|
8053
|
+
if (normalizedRotation === 180) return "left";
|
|
8054
|
+
if (normalizedRotation === 270) return "down";
|
|
8055
|
+
return "right";
|
|
8056
|
+
};
|
|
8057
|
+
var getPinStemLength = (path) => {
|
|
8058
|
+
const segment = path.match(/[hHvV]\s*(-?(?:\d*\.\d+|\d+\.?))/);
|
|
8059
|
+
if (!segment) return void 0;
|
|
8060
|
+
return toMillimeters(Math.abs(Number(segment[1])));
|
|
8061
|
+
};
|
|
8062
|
+
var getTextFontSizeMm = (fontSize) => {
|
|
8063
|
+
const numericFontSize = Number.parseFloat(fontSize);
|
|
8064
|
+
if (!Number.isFinite(numericFontSize)) return 1;
|
|
8065
|
+
if (fontSize.toLowerCase().endsWith("pt")) {
|
|
8066
|
+
return round(numericFontSize * 25.4 / 72);
|
|
8067
|
+
}
|
|
8068
|
+
return toMillimeters(numericFontSize);
|
|
8069
|
+
};
|
|
8070
|
+
var getTextAnchor = (alignment) => {
|
|
8071
|
+
if (alignment === "L") return "left";
|
|
8072
|
+
if (alignment === "R") return "right";
|
|
8073
|
+
return "center";
|
|
8074
|
+
};
|
|
8075
|
+
var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
|
|
8076
|
+
const pins = easyEdaJson.dataStr.shape.filter(
|
|
8077
|
+
(shape) => shape.type === "PIN"
|
|
8078
|
+
);
|
|
8079
|
+
const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
|
|
8080
|
+
(shape) => shape.type === "PAD"
|
|
8081
|
+
);
|
|
8082
|
+
const sourcePorts = circuitJson.filter(
|
|
8083
|
+
(element) => element.type === "source_port"
|
|
8084
|
+
);
|
|
8085
|
+
const sourcePortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
8086
|
+
pads.forEach((pad, padIndex) => {
|
|
8087
|
+
const sourcePort = sourcePorts.find(
|
|
8088
|
+
(port) => port.source_port_id === `source_port_${padIndex + 1}`
|
|
8089
|
+
);
|
|
8090
|
+
if (!sourcePort) return;
|
|
8091
|
+
const padNumber = String(pad.number);
|
|
8092
|
+
sourcePortNamesByPadNumber.set(padNumber, [
|
|
8093
|
+
...sourcePortNamesByPadNumber.get(padNumber) ?? [],
|
|
8094
|
+
sourcePort.name
|
|
8095
|
+
]);
|
|
8096
|
+
});
|
|
8097
|
+
const usedPortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
8098
|
+
const usedPortNames = /* @__PURE__ */ new Set();
|
|
8099
|
+
const metadataByShapeId = /* @__PURE__ */ new Map();
|
|
8100
|
+
pins.forEach((pin, pinIndex) => {
|
|
8101
|
+
const pinNumberKey = String(pin.pinNumber);
|
|
8102
|
+
const matchingPortNames = sourcePortNamesByPadNumber.get(pinNumberKey) ?? [];
|
|
8103
|
+
const matchingPortIndex = usedPortNamesByPadNumber.get(pinNumberKey) ?? 0;
|
|
8104
|
+
let portName = matchingPortNames[matchingPortIndex];
|
|
8105
|
+
usedPortNamesByPadNumber.set(pinNumberKey, matchingPortIndex + 1);
|
|
8106
|
+
if (!portName && pin.label) {
|
|
8107
|
+
const normalizedLabel = normalizeSymbolName(pin.label);
|
|
8108
|
+
portName = sourcePorts.find(
|
|
8109
|
+
(port) => !usedPortNames.has(port.name) && port.port_hints?.includes(normalizedLabel)
|
|
8110
|
+
)?.name;
|
|
8111
|
+
}
|
|
8112
|
+
const numericPinNumber = Number(pin.pinNumber);
|
|
8113
|
+
if (!portName && Number.isInteger(numericPinNumber)) {
|
|
8114
|
+
const numericPortName = `pin${numericPinNumber}`;
|
|
8115
|
+
if (sourcePorts.some((port) => port.name === numericPortName)) {
|
|
8116
|
+
portName = numericPortName;
|
|
8117
|
+
}
|
|
8118
|
+
}
|
|
8119
|
+
portName ??= sourcePorts[pinIndex]?.name ?? `pin${pinIndex + 1}`;
|
|
8120
|
+
usedPortNames.add(portName);
|
|
8121
|
+
const sourcePort = sourcePorts.find((port) => port.name === portName);
|
|
8122
|
+
metadataByShapeId.set(pin.id, {
|
|
8123
|
+
name: portName,
|
|
8124
|
+
pinNumber: sourcePort?.pin_number,
|
|
8125
|
+
aliases: [
|
|
8126
|
+
...sourcePort?.port_hints ?? [],
|
|
8127
|
+
...pin.label ? [normalizeSymbolName(pin.label)] : []
|
|
8128
|
+
].filter(
|
|
8129
|
+
(alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
|
|
8130
|
+
)
|
|
8131
|
+
});
|
|
8132
|
+
});
|
|
8133
|
+
return metadataByShapeId;
|
|
8134
|
+
};
|
|
8135
|
+
var generateShapeTsx = ({
|
|
8136
|
+
shape,
|
|
8137
|
+
origin,
|
|
8138
|
+
portMetadata
|
|
8139
|
+
}) => {
|
|
8140
|
+
const transformPoint = getPointTransformer(origin);
|
|
8141
|
+
if (shape.type === "RECTANGLE") {
|
|
8142
|
+
const center = transformPoint({
|
|
8143
|
+
x: shape.position.x + shape.width / 2,
|
|
8144
|
+
y: shape.position.y + shape.height / 2
|
|
8145
|
+
});
|
|
8146
|
+
return `<schematicrect schX={${center.x}} schY={${center.y}} width={${toMillimeters(shape.width)}} height={${toMillimeters(shape.height)}} strokeWidth={${toMillimeters(shape.lineWidth)}} color=${JSON.stringify(shape.color)}${shape.fillColor && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
8147
|
+
}
|
|
8148
|
+
if (shape.type === "ELLIPSE") {
|
|
8149
|
+
const center = transformPoint(shape.center);
|
|
8150
|
+
return `<schematiccircle center={{ x: ${center.x}, y: ${center.y} }} radius={${toMillimeters(Math.max(shape.radiusX, shape.radiusY))}} strokeWidth={${toMillimeters(shape.lineWidth)}} color=${JSON.stringify(shape.color)}${shape.fillColor && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
8151
|
+
}
|
|
8152
|
+
if (shape.type === "POLYLINE" || shape.type === "POLYGON") {
|
|
8153
|
+
const isPolygon = shape.type === "POLYGON";
|
|
8154
|
+
const points = shape.points.map(transformPoint);
|
|
8155
|
+
if (isPolygon && points.length > 0) points.push(points[0]);
|
|
8156
|
+
return `<schematicpath points={${JSON.stringify(points)}} strokeWidth={${toMillimeters(shape.lineWidth)}} strokeColor=${JSON.stringify(isPolygon ? shape.lineColor : shape.color)}${isPolygon && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
8157
|
+
}
|
|
8158
|
+
if (shape.type === "PATH") {
|
|
8159
|
+
const transformedPath = transformSvgPath(shape.pathData, origin);
|
|
8160
|
+
if (!transformedPath) return void 0;
|
|
8161
|
+
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeWidth={${shape.strokeWidth}} strokeColor=${JSON.stringify(shape.strokeColor)}${shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
8162
|
+
}
|
|
8163
|
+
if (shape.type === "ARC") {
|
|
8164
|
+
const transformedPath = transformSvgPath(shape.pathData, origin);
|
|
8165
|
+
if (!transformedPath) return void 0;
|
|
8166
|
+
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeWidth={${toMillimeters(shape.lineWidth)}} strokeColor=${JSON.stringify(shape.color)} />`;
|
|
8167
|
+
}
|
|
8168
|
+
if (shape.type === "TEXT") {
|
|
8169
|
+
if (shape.visibility !== "1") return void 0;
|
|
8170
|
+
const position2 = transformPoint({ x: shape.x, y: shape.y });
|
|
8171
|
+
return `<schematictext schX={${position2.x}} schY={${position2.y}} text=${JSON.stringify(shape.content)} fontSize={${getTextFontSizeMm(shape.fontSize)}} anchor=${JSON.stringify(getTextAnchor(shape.alignment))} color=${JSON.stringify(shape.fontColor)} schRotation={${round(-shape.rotation)}} />`;
|
|
8172
|
+
}
|
|
8173
|
+
if (shape.type === "PIN" && portMetadata) {
|
|
8174
|
+
const position2 = transformPoint({ x: shape.x, y: shape.y });
|
|
8175
|
+
const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
|
|
8176
|
+
const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
|
|
8177
|
+
const stemLength = getPinStemLength(shape.path);
|
|
8178
|
+
const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
|
|
8179
|
+
return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(getPinDirection(shape.rotation))} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
|
|
8180
|
+
}
|
|
8181
|
+
return void 0;
|
|
8182
|
+
};
|
|
8183
|
+
var generateSymbolTsx = (easyEdaJson, circuitJson) => {
|
|
8184
|
+
const shapes = easyEdaJson.dataStr.shape;
|
|
8185
|
+
if (shapes.length === 0) return void 0;
|
|
8186
|
+
const headOrigin = {
|
|
8187
|
+
x: easyEdaJson.dataStr.head.x,
|
|
8188
|
+
y: easyEdaJson.dataStr.head.y
|
|
8189
|
+
};
|
|
8190
|
+
const bounds = easyEdaJson.dataStr.BBox;
|
|
8191
|
+
const isHeadOriginInsideBounds = headOrigin.x >= bounds.x && headOrigin.x <= bounds.x + bounds.width && headOrigin.y >= bounds.y && headOrigin.y <= bounds.y + bounds.height;
|
|
8192
|
+
const origin = isHeadOriginInsideBounds ? headOrigin : {
|
|
8193
|
+
x: bounds.x + bounds.width / 2,
|
|
8194
|
+
y: bounds.y + bounds.height / 2
|
|
8195
|
+
};
|
|
8196
|
+
const portMetadataByShapeId = getPortMetadataByShapeId(
|
|
8197
|
+
easyEdaJson,
|
|
8198
|
+
circuitJson
|
|
8199
|
+
);
|
|
8200
|
+
const shapeTsx = shapes.map(
|
|
8201
|
+
(shape) => generateShapeTsx({
|
|
8202
|
+
shape,
|
|
8203
|
+
origin,
|
|
8204
|
+
portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
|
|
8205
|
+
})
|
|
8206
|
+
).filter((tsx) => Boolean(tsx));
|
|
8207
|
+
if (shapeTsx.length === 0) return void 0;
|
|
8208
|
+
return `<symbol>
|
|
8209
|
+
${shapeTsx.map((tsx) => ` ${tsx}`).join("\n")}
|
|
8210
|
+
</symbol>`;
|
|
8211
|
+
};
|
|
8212
|
+
var hasNonBoxSchematicSymbol = (easyEdaJson) => {
|
|
8213
|
+
const drawableShapes = easyEdaJson.dataStr.shape.filter(
|
|
8214
|
+
(shape) => shape.type !== "PIN" && shape.type !== "TEXT"
|
|
8215
|
+
);
|
|
8216
|
+
if (drawableShapes.length === 0) return false;
|
|
8217
|
+
const rectangles = drawableShapes.filter(
|
|
8218
|
+
(shape) => shape.type === "RECTANGLE"
|
|
8219
|
+
);
|
|
8220
|
+
const onlyBoxPrimitives = drawableShapes.every(
|
|
8221
|
+
(shape) => shape.type === "RECTANGLE" || shape.type === "ELLIPSE" && shape.radiusX <= 2 && shape.radiusY <= 2
|
|
8222
|
+
);
|
|
8223
|
+
return rectangles.length !== 1 || !onlyBoxPrimitives;
|
|
8224
|
+
};
|
|
8225
|
+
|
|
7916
8226
|
// lib/websafe/convert-to-typescript-component/index.tsx
|
|
7917
8227
|
var getGeneratedComponentType = (betterEasy) => {
|
|
7918
8228
|
if (isLedCategoryComponent(betterEasy)) return "led";
|
|
@@ -7978,6 +8288,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
7978
8288
|
const supplierPartNumbers = {
|
|
7979
8289
|
jlcpcb: [betterEasy.lcsc.number]
|
|
7980
8290
|
};
|
|
8291
|
+
const componentType = getGeneratedComponentType(betterEasy);
|
|
8292
|
+
const symbolTsx = componentType === "chip" && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson) : void 0;
|
|
7981
8293
|
return generateTypescriptComponent({
|
|
7982
8294
|
componentName: pn,
|
|
7983
8295
|
manufacturerPartNumber: pn,
|
|
@@ -7986,7 +8298,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
7986
8298
|
stepUrl: modelStepUrl,
|
|
7987
8299
|
circuitJson,
|
|
7988
8300
|
supplierPartNumbers,
|
|
7989
|
-
componentType
|
|
8301
|
+
componentType,
|
|
8302
|
+
symbolTsx
|
|
7990
8303
|
});
|
|
7991
8304
|
};
|
|
7992
8305
|
var checkModelObjUrlValidity = async (url) => {
|