easyeda 0.0.274 → 0.0.276
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 +354 -28
- package/dist/browser/index.js.map +1 -1
- package/dist/index.d.ts +33 -0
- package/dist/index.js +354 -28
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +356 -30
- package/dist/main.cjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6591,7 +6591,14 @@ async function fetchEasyEDAComponent(jlcpcbPartNumber, {
|
|
|
6591
6591
|
body: searchData
|
|
6592
6592
|
});
|
|
6593
6593
|
if (!searchResponse.ok) {
|
|
6594
|
-
|
|
6594
|
+
if (searchResponse.status === 403) {
|
|
6595
|
+
throw new Error(
|
|
6596
|
+
`EasyEDA API rate limit exceeded while searching for "${jlcpcbPartNumber}" (HTTP 403). EasyEDA rate-limits by IP \u2014 the part number is likely fine. Wait ~2 minutes and try again.`
|
|
6597
|
+
);
|
|
6598
|
+
}
|
|
6599
|
+
throw new Error(
|
|
6600
|
+
`Failed to search for the component (HTTP ${searchResponse.status})`
|
|
6601
|
+
);
|
|
6595
6602
|
}
|
|
6596
6603
|
const searchResult = await searchResponse.json();
|
|
6597
6604
|
if (!searchResult.success || !searchResult.result.lists.lcsc.length) {
|
|
@@ -6609,7 +6616,14 @@ async function fetchEasyEDAComponent(jlcpcbPartNumber, {
|
|
|
6609
6616
|
}
|
|
6610
6617
|
});
|
|
6611
6618
|
if (!componentResponse.ok) {
|
|
6612
|
-
|
|
6619
|
+
if (componentResponse.status === 403) {
|
|
6620
|
+
throw new Error(
|
|
6621
|
+
`EasyEDA API rate limit exceeded while fetching "${jlcpcbPartNumber}" (HTTP 403). EasyEDA rate-limits by IP \u2014 the part number is likely fine. Wait ~2 minutes and try again.`
|
|
6622
|
+
);
|
|
6623
|
+
}
|
|
6624
|
+
throw new Error(
|
|
6625
|
+
`Failed to fetch the component details (HTTP ${componentResponse.status})`
|
|
6626
|
+
);
|
|
6613
6627
|
}
|
|
6614
6628
|
const componentResult = await componentResponse.json();
|
|
6615
6629
|
const result = componentResult.result;
|
|
@@ -6969,10 +6983,11 @@ var RectangleShapeOutputSchema = z180.object({
|
|
|
6969
6983
|
height: z180.number(),
|
|
6970
6984
|
color: z180.string(),
|
|
6971
6985
|
lineWidth: z180.number(),
|
|
6986
|
+
fillColor: z180.string().optional(),
|
|
6972
6987
|
id: z180.string()
|
|
6973
6988
|
});
|
|
6974
6989
|
var parseRectangle = (str) => {
|
|
6975
|
-
const [, x, y, , , width, height, color, lineWidth, , , id] = str.split("~");
|
|
6990
|
+
const [, x, y, , , width, height, color, lineWidth, , fillColor, id] = str.split("~");
|
|
6976
6991
|
return {
|
|
6977
6992
|
type: "RECTANGLE",
|
|
6978
6993
|
position: { x: Number(x), y: Number(y) },
|
|
@@ -6980,6 +6995,7 @@ var parseRectangle = (str) => {
|
|
|
6980
6995
|
height: Number(height),
|
|
6981
6996
|
color,
|
|
6982
6997
|
lineWidth: Number(lineWidth),
|
|
6998
|
+
fillColor,
|
|
6983
6999
|
id
|
|
6984
7000
|
};
|
|
6985
7001
|
};
|
|
@@ -6991,10 +7007,11 @@ var EllipseShapeOutputSchema = z180.object({
|
|
|
6991
7007
|
radiusY: z180.number(),
|
|
6992
7008
|
color: z180.string(),
|
|
6993
7009
|
lineWidth: z180.number(),
|
|
7010
|
+
fillColor: z180.string().optional(),
|
|
6994
7011
|
id: z180.string()
|
|
6995
7012
|
});
|
|
6996
7013
|
var parseEllipse = (str) => {
|
|
6997
|
-
const [, x, y, radiusX, radiusY, color, lineWidth, , , id] = str.split("~");
|
|
7014
|
+
const [, x, y, radiusX, radiusY, color, lineWidth, , fillColor, id] = str.split("~");
|
|
6998
7015
|
return {
|
|
6999
7016
|
type: "ELLIPSE",
|
|
7000
7017
|
center: { x: Number(x), y: Number(y) },
|
|
@@ -7002,12 +7019,14 @@ var parseEllipse = (str) => {
|
|
|
7002
7019
|
radiusY: Number(radiusY),
|
|
7003
7020
|
color,
|
|
7004
7021
|
lineWidth: Number(lineWidth),
|
|
7022
|
+
fillColor,
|
|
7005
7023
|
id
|
|
7006
7024
|
};
|
|
7007
7025
|
};
|
|
7008
7026
|
var EllipseShapeSchema = z180.string().startsWith("E~").transform(parseEllipse).pipe(EllipseShapeOutputSchema);
|
|
7009
7027
|
var ArcShapeOutputSchema = z180.object({
|
|
7010
7028
|
type: z180.literal("ARC"),
|
|
7029
|
+
pathData: z180.string(),
|
|
7011
7030
|
start: PointSchema2,
|
|
7012
7031
|
end: PointSchema2,
|
|
7013
7032
|
radius: z180.number(),
|
|
@@ -7017,26 +7036,25 @@ var ArcShapeOutputSchema = z180.object({
|
|
|
7017
7036
|
id: z180.string()
|
|
7018
7037
|
});
|
|
7019
7038
|
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;
|
|
7039
|
+
const [, pathData, ...fields] = str.split("~");
|
|
7040
|
+
const colorIndex = fields.findIndex((field) => /^#[0-9a-f]{6}$/i.test(field));
|
|
7041
|
+
const color = fields[colorIndex] || "#880000";
|
|
7042
|
+
const lineWidth = fields[colorIndex + 1];
|
|
7043
|
+
const id = fields.find((field) => /^(?:gge|rep)/.test(field)) || "gge1";
|
|
7044
|
+
const numbers = pathData.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
|
|
7045
|
+
const [x1 = 0, y1 = 0, radius = 0, , , , sweepFlag = 0, x2 = 0, y2 = 0] = numbers;
|
|
7028
7046
|
const parsedLineWidth = Number(lineWidth);
|
|
7029
7047
|
const finalLineWidth = Number.isNaN(parsedLineWidth) ? 1 : parsedLineWidth;
|
|
7030
7048
|
return {
|
|
7031
7049
|
type: "ARC",
|
|
7050
|
+
pathData,
|
|
7032
7051
|
start: { x: x1, y: y1 },
|
|
7033
7052
|
end: { x: x2, y: y2 },
|
|
7034
7053
|
radius,
|
|
7035
|
-
sweepFlag,
|
|
7036
|
-
color
|
|
7037
|
-
// Default color
|
|
7054
|
+
sweepFlag: sweepFlag === 1,
|
|
7055
|
+
color,
|
|
7038
7056
|
lineWidth: finalLineWidth,
|
|
7039
|
-
id
|
|
7057
|
+
id
|
|
7040
7058
|
};
|
|
7041
7059
|
};
|
|
7042
7060
|
var ArcShapeSchema = z180.string().startsWith("A~").transform(parseArc).pipe(ArcShapeOutputSchema);
|
|
@@ -7064,8 +7082,7 @@ var parsePin = (pinString) => {
|
|
|
7064
7082
|
if (/^\+\d+(?:\.\d+)?V$/i.test(label)) label = `V${label.slice(1, -1)}`;
|
|
7065
7083
|
const colorMatch = pinString.match(/#[0-9A-F]{6}/);
|
|
7066
7084
|
const labelColor = colorMatch ? colorMatch[0] : "";
|
|
7067
|
-
const
|
|
7068
|
-
const path = pathMatch ? pathMatch[1] : "";
|
|
7085
|
+
const path = pinString.split("^^")[2]?.split("~")[0] ?? "";
|
|
7069
7086
|
const arrowMatch = pinString.match(/\^\^0~(.+)$/);
|
|
7070
7087
|
const arrow = arrowMatch ? arrowMatch[1] : "";
|
|
7071
7088
|
const r = Number.parseFloat(rotation2);
|
|
@@ -7123,7 +7140,7 @@ var PolygonShapeOutputSchema = z180.object({
|
|
|
7123
7140
|
});
|
|
7124
7141
|
var parsePolygon = (str) => {
|
|
7125
7142
|
const [, ...rest] = str.split("~");
|
|
7126
|
-
const [pointsStr,
|
|
7143
|
+
const [pointsStr, lineColor, lineWidth, , fillColor, id] = rest;
|
|
7127
7144
|
return {
|
|
7128
7145
|
type: "POLYGON",
|
|
7129
7146
|
points: parsePoints2(pointsStr),
|
|
@@ -7143,7 +7160,7 @@ var PathShapeOutputSchema = z180.object({
|
|
|
7143
7160
|
id: z180.string()
|
|
7144
7161
|
});
|
|
7145
7162
|
var parsePath = (str) => {
|
|
7146
|
-
const [, pathData,
|
|
7163
|
+
const [, pathData, strokeColor, strokeWidth, , fillColor, id] = str.split("~");
|
|
7147
7164
|
return {
|
|
7148
7165
|
type: "PATH",
|
|
7149
7166
|
pathData,
|
|
@@ -7193,8 +7210,8 @@ var parseText = (str) => {
|
|
|
7193
7210
|
fontWeight,
|
|
7194
7211
|
fontStyle,
|
|
7195
7212
|
fontDecoration,
|
|
7196
|
-
content,
|
|
7197
7213
|
textType,
|
|
7214
|
+
content,
|
|
7198
7215
|
visibility,
|
|
7199
7216
|
mirror,
|
|
7200
7217
|
id
|
|
@@ -7642,7 +7659,8 @@ var generateTypescriptComponent = ({
|
|
|
7642
7659
|
circuitJson,
|
|
7643
7660
|
supplierPartNumbers,
|
|
7644
7661
|
manufacturerPartNumber,
|
|
7645
|
-
componentType = "chip"
|
|
7662
|
+
componentType = "chip",
|
|
7663
|
+
symbolTsx
|
|
7646
7664
|
}) => {
|
|
7647
7665
|
const safePinLabels = pinLabels ?? {};
|
|
7648
7666
|
const polarizedPinMetadata = getPolarizedPinMetadata(safePinLabels);
|
|
@@ -7669,6 +7687,10 @@ ${polarizedPinLabelsString}
|
|
|
7669
7687
|
|
|
7670
7688
|
` : "";
|
|
7671
7689
|
const polarizedPinLabelsProp = polarizedPinLabels ? ` pinLabels={pinLabels}
|
|
7690
|
+
` : "";
|
|
7691
|
+
const symbolProp = symbolTsx ? ` symbol={
|
|
7692
|
+
${symbolTsx.split("\n").map((line) => ` ${line}`).join("\n")}
|
|
7693
|
+
}
|
|
7672
7694
|
` : "";
|
|
7673
7695
|
const cadModelLines = [
|
|
7674
7696
|
objUrl ? `objUrl: "${objUrl}",` : "",
|
|
@@ -7686,7 +7708,7 @@ ${polarizedPinLabelsBlock}export const ${componentName} = (props: DiodeProps) =>
|
|
|
7686
7708
|
return (
|
|
7687
7709
|
<diode
|
|
7688
7710
|
name={name}
|
|
7689
|
-
${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7711
|
+
${polarizedPinLabelsProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7690
7712
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
7691
7713
|
footprint={${footprintTsx}}
|
|
7692
7714
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -7708,7 +7730,7 @@ ${polarizedPinLabelsBlock}export const ${componentName} = (props: LedProps) => {
|
|
|
7708
7730
|
return (
|
|
7709
7731
|
<led
|
|
7710
7732
|
name={name}
|
|
7711
|
-
${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7733
|
+
${polarizedPinLabelsProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7712
7734
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
7713
7735
|
footprint={${footprintTsx}}
|
|
7714
7736
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -7735,7 +7757,7 @@ export const ${componentName} = (props: PushButtonProps<typeof pinLabels>) => {
|
|
|
7735
7757
|
<pushbutton
|
|
7736
7758
|
name={name}
|
|
7737
7759
|
pinLabels={pinLabels}
|
|
7738
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7760
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7739
7761
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
7740
7762
|
footprint={${footprintTsx}}
|
|
7741
7763
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -7762,7 +7784,7 @@ export const ${componentName} = (props: SwitchProps) => {
|
|
|
7762
7784
|
<switch
|
|
7763
7785
|
name={name}
|
|
7764
7786
|
pinLabels={pinLabels}
|
|
7765
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7787
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7766
7788
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
7767
7789
|
footprint={${footprintTsx}}
|
|
7768
7790
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -7785,7 +7807,7 @@ export const ${componentName} = (props: ChipProps<typeof pinLabels>) => {
|
|
|
7785
7807
|
return (
|
|
7786
7808
|
<chip
|
|
7787
7809
|
pinLabels={pinLabels}
|
|
7788
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7810
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
7789
7811
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
7790
7812
|
footprint={${footprintTsx}}
|
|
7791
7813
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -7914,6 +7936,307 @@ var isSwitchCategoryComponent = (betterEasy) => {
|
|
|
7914
7936
|
].some(categoryValueContainsSwitch);
|
|
7915
7937
|
};
|
|
7916
7938
|
|
|
7939
|
+
// lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
|
|
7940
|
+
var round = (value) => Number(value.toFixed(6));
|
|
7941
|
+
var toMillimeters = (value) => round(mil10ToMm(value));
|
|
7942
|
+
var getPointTransformer = (origin) => (point2) => ({
|
|
7943
|
+
x: toMillimeters(point2.x - origin.x),
|
|
7944
|
+
y: toMillimeters(origin.y - point2.y)
|
|
7945
|
+
});
|
|
7946
|
+
var formatNumber = (value) => String(round(value));
|
|
7947
|
+
var SVG_PATH_COMMAND_PARAMETER_COUNTS = {
|
|
7948
|
+
A: 7,
|
|
7949
|
+
C: 6,
|
|
7950
|
+
H: 1,
|
|
7951
|
+
L: 2,
|
|
7952
|
+
M: 2,
|
|
7953
|
+
Q: 4,
|
|
7954
|
+
S: 4,
|
|
7955
|
+
T: 2,
|
|
7956
|
+
V: 1,
|
|
7957
|
+
Z: 0
|
|
7958
|
+
};
|
|
7959
|
+
var transformSvgPath = (pathData, origin) => {
|
|
7960
|
+
const tokens = pathData.match(
|
|
7961
|
+
/[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g
|
|
7962
|
+
) ?? [];
|
|
7963
|
+
const output = [];
|
|
7964
|
+
let command = "";
|
|
7965
|
+
let tokenIndex = 0;
|
|
7966
|
+
let currentX = 0;
|
|
7967
|
+
let currentY = 0;
|
|
7968
|
+
let subpathStartX = 0;
|
|
7969
|
+
let subpathStartY = 0;
|
|
7970
|
+
const transformPoint = getPointTransformer(origin);
|
|
7971
|
+
const getOriginalPoint = (x, y, isRelative) => ({
|
|
7972
|
+
x: isRelative ? currentX + x : x,
|
|
7973
|
+
y: isRelative ? currentY + y : y
|
|
7974
|
+
});
|
|
7975
|
+
while (tokenIndex < tokens.length) {
|
|
7976
|
+
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) {
|
|
7977
|
+
command = tokens[tokenIndex];
|
|
7978
|
+
tokenIndex += 1;
|
|
7979
|
+
}
|
|
7980
|
+
if (!command) break;
|
|
7981
|
+
const upperCommand = command.toUpperCase();
|
|
7982
|
+
const parameterCount = SVG_PATH_COMMAND_PARAMETER_COUNTS[upperCommand];
|
|
7983
|
+
if (parameterCount === void 0) break;
|
|
7984
|
+
if (upperCommand === "Z") {
|
|
7985
|
+
output.push("Z");
|
|
7986
|
+
currentX = subpathStartX;
|
|
7987
|
+
currentY = subpathStartY;
|
|
7988
|
+
command = "";
|
|
7989
|
+
continue;
|
|
7990
|
+
}
|
|
7991
|
+
if (tokenIndex + parameterCount > tokens.length) break;
|
|
7992
|
+
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) continue;
|
|
7993
|
+
const values = tokens.slice(tokenIndex, tokenIndex + parameterCount).map(Number);
|
|
7994
|
+
tokenIndex += parameterCount;
|
|
7995
|
+
const isRelative = command === command.toLowerCase();
|
|
7996
|
+
if (upperCommand === "H" || upperCommand === "V") {
|
|
7997
|
+
const point2 = getOriginalPoint(
|
|
7998
|
+
upperCommand === "H" ? values[0] : isRelative ? 0 : currentX,
|
|
7999
|
+
upperCommand === "V" ? values[0] : isRelative ? 0 : currentY,
|
|
8000
|
+
isRelative
|
|
8001
|
+
);
|
|
8002
|
+
const transformed = transformPoint(point2);
|
|
8003
|
+
output.push(
|
|
8004
|
+
`L ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
8005
|
+
);
|
|
8006
|
+
currentX = point2.x;
|
|
8007
|
+
currentY = point2.y;
|
|
8008
|
+
continue;
|
|
8009
|
+
}
|
|
8010
|
+
if (["M", "L", "T"].includes(upperCommand)) {
|
|
8011
|
+
const point2 = getOriginalPoint(values[0], values[1], isRelative);
|
|
8012
|
+
const transformed = transformPoint(point2);
|
|
8013
|
+
output.push(
|
|
8014
|
+
`${upperCommand} ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
8015
|
+
);
|
|
8016
|
+
currentX = point2.x;
|
|
8017
|
+
currentY = point2.y;
|
|
8018
|
+
if (upperCommand === "M") {
|
|
8019
|
+
subpathStartX = point2.x;
|
|
8020
|
+
subpathStartY = point2.y;
|
|
8021
|
+
command = isRelative ? "l" : "L";
|
|
8022
|
+
}
|
|
8023
|
+
continue;
|
|
8024
|
+
}
|
|
8025
|
+
if (["C", "S", "Q"].includes(upperCommand)) {
|
|
8026
|
+
const transformedValues = [];
|
|
8027
|
+
for (let valueIndex = 0; valueIndex < values.length; valueIndex += 2) {
|
|
8028
|
+
const point2 = getOriginalPoint(
|
|
8029
|
+
values[valueIndex],
|
|
8030
|
+
values[valueIndex + 1],
|
|
8031
|
+
isRelative
|
|
8032
|
+
);
|
|
8033
|
+
const transformed = transformPoint(point2);
|
|
8034
|
+
transformedValues.push(transformed.x, transformed.y);
|
|
8035
|
+
}
|
|
8036
|
+
output.push(
|
|
8037
|
+
`${upperCommand} ${transformedValues.map(formatNumber).join(" ")}`
|
|
8038
|
+
);
|
|
8039
|
+
currentX = isRelative ? currentX + values[values.length - 2] : values[values.length - 2];
|
|
8040
|
+
currentY = isRelative ? currentY + values[values.length - 1] : values[values.length - 1];
|
|
8041
|
+
continue;
|
|
8042
|
+
}
|
|
8043
|
+
if (upperCommand === "A") {
|
|
8044
|
+
const endpoint = getOriginalPoint(values[5], values[6], isRelative);
|
|
8045
|
+
const transformedEndpoint = transformPoint(endpoint);
|
|
8046
|
+
output.push(
|
|
8047
|
+
[
|
|
8048
|
+
"A",
|
|
8049
|
+
formatNumber(toMillimeters(Math.abs(values[0]))),
|
|
8050
|
+
formatNumber(toMillimeters(Math.abs(values[1]))),
|
|
8051
|
+
formatNumber(-values[2]),
|
|
8052
|
+
String(values[3]),
|
|
8053
|
+
String(values[4] === 0 ? 1 : 0),
|
|
8054
|
+
formatNumber(transformedEndpoint.x),
|
|
8055
|
+
formatNumber(transformedEndpoint.y)
|
|
8056
|
+
].join(" ")
|
|
8057
|
+
);
|
|
8058
|
+
currentX = endpoint.x;
|
|
8059
|
+
currentY = endpoint.y;
|
|
8060
|
+
}
|
|
8061
|
+
}
|
|
8062
|
+
return output.join(" ");
|
|
8063
|
+
};
|
|
8064
|
+
var getPinDirection = (rotation2) => {
|
|
8065
|
+
const normalizedRotation = (rotation2 % 360 + 360) % 360;
|
|
8066
|
+
if (normalizedRotation === 90) return "up";
|
|
8067
|
+
if (normalizedRotation === 180) return "left";
|
|
8068
|
+
if (normalizedRotation === 270) return "down";
|
|
8069
|
+
return "right";
|
|
8070
|
+
};
|
|
8071
|
+
var getPinStemLength = (path) => {
|
|
8072
|
+
const segment = path.match(/[hHvV]\s*(-?(?:\d*\.\d+|\d+\.?))/);
|
|
8073
|
+
if (!segment) return void 0;
|
|
8074
|
+
return toMillimeters(Math.abs(Number(segment[1])));
|
|
8075
|
+
};
|
|
8076
|
+
var getTextFontSizeMm = (fontSize) => {
|
|
8077
|
+
const numericFontSize = Number.parseFloat(fontSize);
|
|
8078
|
+
if (!Number.isFinite(numericFontSize)) return 1;
|
|
8079
|
+
if (fontSize.toLowerCase().endsWith("pt")) {
|
|
8080
|
+
return round(numericFontSize * 25.4 / 72);
|
|
8081
|
+
}
|
|
8082
|
+
return toMillimeters(numericFontSize);
|
|
8083
|
+
};
|
|
8084
|
+
var getTextAnchor = (alignment) => {
|
|
8085
|
+
if (alignment === "L") return "left";
|
|
8086
|
+
if (alignment === "R") return "right";
|
|
8087
|
+
return "center";
|
|
8088
|
+
};
|
|
8089
|
+
var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
|
|
8090
|
+
const pins = easyEdaJson.dataStr.shape.filter(
|
|
8091
|
+
(shape) => shape.type === "PIN"
|
|
8092
|
+
);
|
|
8093
|
+
const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
|
|
8094
|
+
(shape) => shape.type === "PAD"
|
|
8095
|
+
);
|
|
8096
|
+
const sourcePorts = circuitJson.filter(
|
|
8097
|
+
(element) => element.type === "source_port"
|
|
8098
|
+
);
|
|
8099
|
+
const sourcePortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
8100
|
+
pads.forEach((pad, padIndex) => {
|
|
8101
|
+
const sourcePort = sourcePorts.find(
|
|
8102
|
+
(port) => port.source_port_id === `source_port_${padIndex + 1}`
|
|
8103
|
+
);
|
|
8104
|
+
if (!sourcePort) return;
|
|
8105
|
+
const padNumber = String(pad.number);
|
|
8106
|
+
sourcePortNamesByPadNumber.set(padNumber, [
|
|
8107
|
+
...sourcePortNamesByPadNumber.get(padNumber) ?? [],
|
|
8108
|
+
sourcePort.name
|
|
8109
|
+
]);
|
|
8110
|
+
});
|
|
8111
|
+
const usedPortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
8112
|
+
const usedPortNames = /* @__PURE__ */ new Set();
|
|
8113
|
+
const metadataByShapeId = /* @__PURE__ */ new Map();
|
|
8114
|
+
pins.forEach((pin, pinIndex) => {
|
|
8115
|
+
const pinNumberKey = String(pin.pinNumber);
|
|
8116
|
+
const matchingPortNames = sourcePortNamesByPadNumber.get(pinNumberKey) ?? [];
|
|
8117
|
+
const matchingPortIndex = usedPortNamesByPadNumber.get(pinNumberKey) ?? 0;
|
|
8118
|
+
let portName = matchingPortNames[matchingPortIndex];
|
|
8119
|
+
usedPortNamesByPadNumber.set(pinNumberKey, matchingPortIndex + 1);
|
|
8120
|
+
if (!portName && pin.label) {
|
|
8121
|
+
const normalizedLabel = normalizeSymbolName(pin.label);
|
|
8122
|
+
portName = sourcePorts.find(
|
|
8123
|
+
(port) => !usedPortNames.has(port.name) && port.port_hints?.includes(normalizedLabel)
|
|
8124
|
+
)?.name;
|
|
8125
|
+
}
|
|
8126
|
+
const numericPinNumber = Number(pin.pinNumber);
|
|
8127
|
+
if (!portName && Number.isInteger(numericPinNumber)) {
|
|
8128
|
+
const numericPortName = `pin${numericPinNumber}`;
|
|
8129
|
+
if (sourcePorts.some((port) => port.name === numericPortName)) {
|
|
8130
|
+
portName = numericPortName;
|
|
8131
|
+
}
|
|
8132
|
+
}
|
|
8133
|
+
portName ??= sourcePorts[pinIndex]?.name ?? `pin${pinIndex + 1}`;
|
|
8134
|
+
usedPortNames.add(portName);
|
|
8135
|
+
const sourcePort = sourcePorts.find((port) => port.name === portName);
|
|
8136
|
+
metadataByShapeId.set(pin.id, {
|
|
8137
|
+
name: portName,
|
|
8138
|
+
pinNumber: sourcePort?.pin_number,
|
|
8139
|
+
aliases: [
|
|
8140
|
+
...sourcePort?.port_hints ?? [],
|
|
8141
|
+
...pin.label ? [normalizeSymbolName(pin.label)] : []
|
|
8142
|
+
].filter(
|
|
8143
|
+
(alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
|
|
8144
|
+
)
|
|
8145
|
+
});
|
|
8146
|
+
});
|
|
8147
|
+
return metadataByShapeId;
|
|
8148
|
+
};
|
|
8149
|
+
var generateShapeTsx = ({
|
|
8150
|
+
shape,
|
|
8151
|
+
origin,
|
|
8152
|
+
portMetadata
|
|
8153
|
+
}) => {
|
|
8154
|
+
const transformPoint = getPointTransformer(origin);
|
|
8155
|
+
if (shape.type === "RECTANGLE") {
|
|
8156
|
+
const center = transformPoint({
|
|
8157
|
+
x: shape.position.x + shape.width / 2,
|
|
8158
|
+
y: shape.position.y + shape.height / 2
|
|
8159
|
+
});
|
|
8160
|
+
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)}` : ""} />`;
|
|
8161
|
+
}
|
|
8162
|
+
if (shape.type === "ELLIPSE") {
|
|
8163
|
+
const center = transformPoint(shape.center);
|
|
8164
|
+
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)}` : ""} />`;
|
|
8165
|
+
}
|
|
8166
|
+
if (shape.type === "POLYLINE" || shape.type === "POLYGON") {
|
|
8167
|
+
const isPolygon = shape.type === "POLYGON";
|
|
8168
|
+
const points = shape.points.map(transformPoint);
|
|
8169
|
+
if (isPolygon && points.length > 0) points.push(points[0]);
|
|
8170
|
+
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)}` : ""} />`;
|
|
8171
|
+
}
|
|
8172
|
+
if (shape.type === "PATH") {
|
|
8173
|
+
const transformedPath = transformSvgPath(shape.pathData, origin);
|
|
8174
|
+
if (!transformedPath) return void 0;
|
|
8175
|
+
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeWidth={${shape.strokeWidth}} strokeColor=${JSON.stringify(shape.strokeColor)}${shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
8176
|
+
}
|
|
8177
|
+
if (shape.type === "ARC") {
|
|
8178
|
+
const transformedPath = transformSvgPath(shape.pathData, origin);
|
|
8179
|
+
if (!transformedPath) return void 0;
|
|
8180
|
+
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeWidth={${toMillimeters(shape.lineWidth)}} strokeColor=${JSON.stringify(shape.color)} />`;
|
|
8181
|
+
}
|
|
8182
|
+
if (shape.type === "TEXT") {
|
|
8183
|
+
if (shape.visibility !== "1") return void 0;
|
|
8184
|
+
const position2 = transformPoint({ x: shape.x, y: shape.y });
|
|
8185
|
+
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)}} />`;
|
|
8186
|
+
}
|
|
8187
|
+
if (shape.type === "PIN" && portMetadata) {
|
|
8188
|
+
const position2 = transformPoint({ x: shape.x, y: shape.y });
|
|
8189
|
+
const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
|
|
8190
|
+
const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
|
|
8191
|
+
const stemLength = getPinStemLength(shape.path);
|
|
8192
|
+
const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
|
|
8193
|
+
return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(getPinDirection(shape.rotation))} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
|
|
8194
|
+
}
|
|
8195
|
+
return void 0;
|
|
8196
|
+
};
|
|
8197
|
+
var generateSymbolTsx = (easyEdaJson, circuitJson) => {
|
|
8198
|
+
const shapes = easyEdaJson.dataStr.shape;
|
|
8199
|
+
if (shapes.length === 0) return void 0;
|
|
8200
|
+
const headOrigin = {
|
|
8201
|
+
x: easyEdaJson.dataStr.head.x,
|
|
8202
|
+
y: easyEdaJson.dataStr.head.y
|
|
8203
|
+
};
|
|
8204
|
+
const bounds = easyEdaJson.dataStr.BBox;
|
|
8205
|
+
const isHeadOriginInsideBounds = headOrigin.x >= bounds.x && headOrigin.x <= bounds.x + bounds.width && headOrigin.y >= bounds.y && headOrigin.y <= bounds.y + bounds.height;
|
|
8206
|
+
const origin = isHeadOriginInsideBounds ? headOrigin : {
|
|
8207
|
+
x: bounds.x + bounds.width / 2,
|
|
8208
|
+
y: bounds.y + bounds.height / 2
|
|
8209
|
+
};
|
|
8210
|
+
const portMetadataByShapeId = getPortMetadataByShapeId(
|
|
8211
|
+
easyEdaJson,
|
|
8212
|
+
circuitJson
|
|
8213
|
+
);
|
|
8214
|
+
const shapeTsx = shapes.map(
|
|
8215
|
+
(shape) => generateShapeTsx({
|
|
8216
|
+
shape,
|
|
8217
|
+
origin,
|
|
8218
|
+
portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
|
|
8219
|
+
})
|
|
8220
|
+
).filter((tsx) => Boolean(tsx));
|
|
8221
|
+
if (shapeTsx.length === 0) return void 0;
|
|
8222
|
+
return `<symbol>
|
|
8223
|
+
${shapeTsx.map((tsx) => ` ${tsx}`).join("\n")}
|
|
8224
|
+
</symbol>`;
|
|
8225
|
+
};
|
|
8226
|
+
var hasNonBoxSchematicSymbol = (easyEdaJson) => {
|
|
8227
|
+
const drawableShapes = easyEdaJson.dataStr.shape.filter(
|
|
8228
|
+
(shape) => shape.type !== "PIN" && shape.type !== "TEXT"
|
|
8229
|
+
);
|
|
8230
|
+
if (drawableShapes.length === 0) return false;
|
|
8231
|
+
const rectangles = drawableShapes.filter(
|
|
8232
|
+
(shape) => shape.type === "RECTANGLE"
|
|
8233
|
+
);
|
|
8234
|
+
const onlyBoxPrimitives = drawableShapes.every(
|
|
8235
|
+
(shape) => shape.type === "RECTANGLE" || shape.type === "ELLIPSE" && shape.radiusX <= 2 && shape.radiusY <= 2
|
|
8236
|
+
);
|
|
8237
|
+
return rectangles.length !== 1 || !onlyBoxPrimitives;
|
|
8238
|
+
};
|
|
8239
|
+
|
|
7917
8240
|
// lib/websafe/convert-to-typescript-component/index.tsx
|
|
7918
8241
|
var getGeneratedComponentType = (betterEasy) => {
|
|
7919
8242
|
if (isLedCategoryComponent(betterEasy)) return "led";
|
|
@@ -7979,6 +8302,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
7979
8302
|
const supplierPartNumbers = {
|
|
7980
8303
|
jlcpcb: [betterEasy.lcsc.number]
|
|
7981
8304
|
};
|
|
8305
|
+
const componentType = getGeneratedComponentType(betterEasy);
|
|
8306
|
+
const symbolTsx = componentType === "chip" && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson) : void 0;
|
|
7982
8307
|
return generateTypescriptComponent({
|
|
7983
8308
|
componentName: pn,
|
|
7984
8309
|
manufacturerPartNumber: pn,
|
|
@@ -7987,7 +8312,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
7987
8312
|
stepUrl: modelStepUrl,
|
|
7988
8313
|
circuitJson,
|
|
7989
8314
|
supplierPartNumbers,
|
|
7990
|
-
componentType
|
|
8315
|
+
componentType,
|
|
8316
|
+
symbolTsx
|
|
7991
8317
|
});
|
|
7992
8318
|
};
|
|
7993
8319
|
var checkModelObjUrlValidity = async (url) => {
|