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/browser/index.js
CHANGED
|
@@ -10682,10 +10682,11 @@ var RectangleShapeOutputSchema = external_exports.object({
|
|
|
10682
10682
|
height: external_exports.number(),
|
|
10683
10683
|
color: external_exports.string(),
|
|
10684
10684
|
lineWidth: external_exports.number(),
|
|
10685
|
+
fillColor: external_exports.string().optional(),
|
|
10685
10686
|
id: external_exports.string()
|
|
10686
10687
|
});
|
|
10687
10688
|
var parseRectangle = (str) => {
|
|
10688
|
-
const [, x, y, , , width, height, color, lineWidth, , , id] = str.split("~");
|
|
10689
|
+
const [, x, y, , , width, height, color, lineWidth, , fillColor, id] = str.split("~");
|
|
10689
10690
|
return {
|
|
10690
10691
|
type: "RECTANGLE",
|
|
10691
10692
|
position: { x: Number(x), y: Number(y) },
|
|
@@ -10693,6 +10694,7 @@ var parseRectangle = (str) => {
|
|
|
10693
10694
|
height: Number(height),
|
|
10694
10695
|
color,
|
|
10695
10696
|
lineWidth: Number(lineWidth),
|
|
10697
|
+
fillColor,
|
|
10696
10698
|
id
|
|
10697
10699
|
};
|
|
10698
10700
|
};
|
|
@@ -10704,10 +10706,11 @@ var EllipseShapeOutputSchema = external_exports.object({
|
|
|
10704
10706
|
radiusY: external_exports.number(),
|
|
10705
10707
|
color: external_exports.string(),
|
|
10706
10708
|
lineWidth: external_exports.number(),
|
|
10709
|
+
fillColor: external_exports.string().optional(),
|
|
10707
10710
|
id: external_exports.string()
|
|
10708
10711
|
});
|
|
10709
10712
|
var parseEllipse = (str) => {
|
|
10710
|
-
const [, x, y, radiusX, radiusY, color, lineWidth, , , id] = str.split("~");
|
|
10713
|
+
const [, x, y, radiusX, radiusY, color, lineWidth, , fillColor, id] = str.split("~");
|
|
10711
10714
|
return {
|
|
10712
10715
|
type: "ELLIPSE",
|
|
10713
10716
|
center: { x: Number(x), y: Number(y) },
|
|
@@ -10715,12 +10718,14 @@ var parseEllipse = (str) => {
|
|
|
10715
10718
|
radiusY: Number(radiusY),
|
|
10716
10719
|
color,
|
|
10717
10720
|
lineWidth: Number(lineWidth),
|
|
10721
|
+
fillColor,
|
|
10718
10722
|
id
|
|
10719
10723
|
};
|
|
10720
10724
|
};
|
|
10721
10725
|
var EllipseShapeSchema = external_exports.string().startsWith("E~").transform(parseEllipse).pipe(EllipseShapeOutputSchema);
|
|
10722
10726
|
var ArcShapeOutputSchema = external_exports.object({
|
|
10723
10727
|
type: external_exports.literal("ARC"),
|
|
10728
|
+
pathData: external_exports.string(),
|
|
10724
10729
|
start: PointSchema2,
|
|
10725
10730
|
end: PointSchema2,
|
|
10726
10731
|
radius: external_exports.number(),
|
|
@@ -10730,26 +10735,25 @@ var ArcShapeOutputSchema = external_exports.object({
|
|
|
10730
10735
|
id: external_exports.string()
|
|
10731
10736
|
});
|
|
10732
10737
|
var parseArc = (str) => {
|
|
10733
|
-
const [, pathData,
|
|
10734
|
-
const
|
|
10735
|
-
const
|
|
10736
|
-
const
|
|
10737
|
-
const
|
|
10738
|
-
const
|
|
10739
|
-
const x2 =
|
|
10740
|
-
const y2 = Number(parts[9]) || 0;
|
|
10738
|
+
const [, pathData, ...fields] = str.split("~");
|
|
10739
|
+
const colorIndex = fields.findIndex((field) => /^#[0-9a-f]{6}$/i.test(field));
|
|
10740
|
+
const color = fields[colorIndex] || "#880000";
|
|
10741
|
+
const lineWidth = fields[colorIndex + 1];
|
|
10742
|
+
const id = fields.find((field) => /^(?:gge|rep)/.test(field)) || "gge1";
|
|
10743
|
+
const numbers = pathData.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
|
|
10744
|
+
const [x1 = 0, y1 = 0, radius = 0, , , , sweepFlag = 0, x2 = 0, y2 = 0] = numbers;
|
|
10741
10745
|
const parsedLineWidth = Number(lineWidth);
|
|
10742
10746
|
const finalLineWidth = Number.isNaN(parsedLineWidth) ? 1 : parsedLineWidth;
|
|
10743
10747
|
return {
|
|
10744
10748
|
type: "ARC",
|
|
10749
|
+
pathData,
|
|
10745
10750
|
start: { x: x1, y: y1 },
|
|
10746
10751
|
end: { x: x2, y: y2 },
|
|
10747
10752
|
radius,
|
|
10748
|
-
sweepFlag,
|
|
10749
|
-
color
|
|
10750
|
-
// Default color
|
|
10753
|
+
sweepFlag: sweepFlag === 1,
|
|
10754
|
+
color,
|
|
10751
10755
|
lineWidth: finalLineWidth,
|
|
10752
|
-
id
|
|
10756
|
+
id
|
|
10753
10757
|
};
|
|
10754
10758
|
};
|
|
10755
10759
|
var ArcShapeSchema = external_exports.string().startsWith("A~").transform(parseArc).pipe(ArcShapeOutputSchema);
|
|
@@ -10777,8 +10781,7 @@ var parsePin = (pinString) => {
|
|
|
10777
10781
|
if (/^\+\d+(?:\.\d+)?V$/i.test(label)) label = `V${label.slice(1, -1)}`;
|
|
10778
10782
|
const colorMatch = pinString.match(/#[0-9A-F]{6}/);
|
|
10779
10783
|
const labelColor = colorMatch ? colorMatch[0] : "";
|
|
10780
|
-
const
|
|
10781
|
-
const path = pathMatch ? pathMatch[1] : "";
|
|
10784
|
+
const path = pinString.split("^^")[2]?.split("~")[0] ?? "";
|
|
10782
10785
|
const arrowMatch = pinString.match(/\^\^0~(.+)$/);
|
|
10783
10786
|
const arrow = arrowMatch ? arrowMatch[1] : "";
|
|
10784
10787
|
const r = Number.parseFloat(rotation2);
|
|
@@ -10836,7 +10839,7 @@ var PolygonShapeOutputSchema = external_exports.object({
|
|
|
10836
10839
|
});
|
|
10837
10840
|
var parsePolygon = (str) => {
|
|
10838
10841
|
const [, ...rest] = str.split("~");
|
|
10839
|
-
const [pointsStr,
|
|
10842
|
+
const [pointsStr, lineColor, lineWidth, , fillColor, id] = rest;
|
|
10840
10843
|
return {
|
|
10841
10844
|
type: "POLYGON",
|
|
10842
10845
|
points: parsePoints2(pointsStr),
|
|
@@ -10856,7 +10859,7 @@ var PathShapeOutputSchema = external_exports.object({
|
|
|
10856
10859
|
id: external_exports.string()
|
|
10857
10860
|
});
|
|
10858
10861
|
var parsePath = (str) => {
|
|
10859
|
-
const [, pathData,
|
|
10862
|
+
const [, pathData, strokeColor, strokeWidth, , fillColor, id] = str.split("~");
|
|
10860
10863
|
return {
|
|
10861
10864
|
type: "PATH",
|
|
10862
10865
|
pathData,
|
|
@@ -10906,8 +10909,8 @@ var parseText = (str) => {
|
|
|
10906
10909
|
fontWeight,
|
|
10907
10910
|
fontStyle,
|
|
10908
10911
|
fontDecoration,
|
|
10909
|
-
content,
|
|
10910
10912
|
textType,
|
|
10913
|
+
content,
|
|
10911
10914
|
visibility,
|
|
10912
10915
|
mirror,
|
|
10913
10916
|
id
|
|
@@ -11332,6 +11335,7 @@ var getPinLabelValues = (labels) => {
|
|
|
11332
11335
|
if (typeof labels === "string") return [labels];
|
|
11333
11336
|
return [...labels];
|
|
11334
11337
|
};
|
|
11338
|
+
var stripEasyEdaPolarityHintDecoration = (label) => label.toLowerCase().replace(/[^a-z0-9+-]/g, "");
|
|
11335
11339
|
var getPinKeySortValue = (pinKey) => {
|
|
11336
11340
|
const match = /^pin(\d+)$/i.exec(pinKey);
|
|
11337
11341
|
return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;
|
|
@@ -11339,7 +11343,7 @@ var getPinKeySortValue = (pinKey) => {
|
|
|
11339
11343
|
var getPolarizedPinMetadata = (pinLabels) => {
|
|
11340
11344
|
const labelsByPin = Object.entries(pinLabels ?? {}).map(([pin, labels]) => ({
|
|
11341
11345
|
pin,
|
|
11342
|
-
labels: getPinLabelValues(labels).map(
|
|
11346
|
+
labels: getPinLabelValues(labels).map(stripEasyEdaPolarityHintDecoration)
|
|
11343
11347
|
}));
|
|
11344
11348
|
const anodePin = labelsByPin.find(
|
|
11345
11349
|
({ labels }) => labels.some((label) => ["a", "anode", "pos", "+"].includes(label))
|
|
@@ -11369,7 +11373,8 @@ var generateTypescriptComponent = ({
|
|
|
11369
11373
|
circuitJson,
|
|
11370
11374
|
supplierPartNumbers,
|
|
11371
11375
|
manufacturerPartNumber,
|
|
11372
|
-
componentType = "chip"
|
|
11376
|
+
componentType = "chip",
|
|
11377
|
+
symbolTsx
|
|
11373
11378
|
}) => {
|
|
11374
11379
|
const safePinLabels = pinLabels ?? {};
|
|
11375
11380
|
const polarizedPinMetadata = getPolarizedPinMetadata(safePinLabels);
|
|
@@ -11396,6 +11401,10 @@ ${polarizedPinLabelsString}
|
|
|
11396
11401
|
|
|
11397
11402
|
` : "";
|
|
11398
11403
|
const polarizedPinLabelsProp = polarizedPinLabels ? ` pinLabels={pinLabels}
|
|
11404
|
+
` : "";
|
|
11405
|
+
const symbolProp = symbolTsx ? ` symbol={
|
|
11406
|
+
${symbolTsx.split("\n").map((line) => ` ${line}`).join("\n")}
|
|
11407
|
+
}
|
|
11399
11408
|
` : "";
|
|
11400
11409
|
const cadModelLines = [
|
|
11401
11410
|
objUrl ? `objUrl: "${objUrl}",` : "",
|
|
@@ -11413,7 +11422,7 @@ ${polarizedPinLabelsBlock}export const ${componentName} = (props: DiodeProps) =>
|
|
|
11413
11422
|
return (
|
|
11414
11423
|
<diode
|
|
11415
11424
|
name={name}
|
|
11416
|
-
${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11425
|
+
${polarizedPinLabelsProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11417
11426
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11418
11427
|
footprint={${footprintTsx}}
|
|
11419
11428
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11435,7 +11444,7 @@ ${polarizedPinLabelsBlock}export const ${componentName} = (props: LedProps) => {
|
|
|
11435
11444
|
return (
|
|
11436
11445
|
<led
|
|
11437
11446
|
name={name}
|
|
11438
|
-
${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11447
|
+
${polarizedPinLabelsProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11439
11448
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11440
11449
|
footprint={${footprintTsx}}
|
|
11441
11450
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11462,7 +11471,7 @@ export const ${componentName} = (props: PushButtonProps<typeof pinLabels>) => {
|
|
|
11462
11471
|
<pushbutton
|
|
11463
11472
|
name={name}
|
|
11464
11473
|
pinLabels={pinLabels}
|
|
11465
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11474
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11466
11475
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11467
11476
|
footprint={${footprintTsx}}
|
|
11468
11477
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11489,7 +11498,7 @@ export const ${componentName} = (props: SwitchProps) => {
|
|
|
11489
11498
|
<switch
|
|
11490
11499
|
name={name}
|
|
11491
11500
|
pinLabels={pinLabels}
|
|
11492
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11501
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11493
11502
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11494
11503
|
footprint={${footprintTsx}}
|
|
11495
11504
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11512,7 +11521,7 @@ export const ${componentName} = (props: ChipProps<typeof pinLabels>) => {
|
|
|
11512
11521
|
return (
|
|
11513
11522
|
<chip
|
|
11514
11523
|
pinLabels={pinLabels}
|
|
11515
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11524
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11516
11525
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11517
11526
|
footprint={${footprintTsx}}
|
|
11518
11527
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11641,6 +11650,307 @@ var isSwitchCategoryComponent = (betterEasy) => {
|
|
|
11641
11650
|
].some(categoryValueContainsSwitch);
|
|
11642
11651
|
};
|
|
11643
11652
|
|
|
11653
|
+
// lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
|
|
11654
|
+
var round = (value) => Number(value.toFixed(6));
|
|
11655
|
+
var toMillimeters = (value) => round(mil10ToMm(value));
|
|
11656
|
+
var getPointTransformer = (origin) => (point2) => ({
|
|
11657
|
+
x: toMillimeters(point2.x - origin.x),
|
|
11658
|
+
y: toMillimeters(origin.y - point2.y)
|
|
11659
|
+
});
|
|
11660
|
+
var formatNumber = (value) => String(round(value));
|
|
11661
|
+
var SVG_PATH_COMMAND_PARAMETER_COUNTS = {
|
|
11662
|
+
A: 7,
|
|
11663
|
+
C: 6,
|
|
11664
|
+
H: 1,
|
|
11665
|
+
L: 2,
|
|
11666
|
+
M: 2,
|
|
11667
|
+
Q: 4,
|
|
11668
|
+
S: 4,
|
|
11669
|
+
T: 2,
|
|
11670
|
+
V: 1,
|
|
11671
|
+
Z: 0
|
|
11672
|
+
};
|
|
11673
|
+
var transformSvgPath = (pathData, origin) => {
|
|
11674
|
+
const tokens = pathData.match(
|
|
11675
|
+
/[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g
|
|
11676
|
+
) ?? [];
|
|
11677
|
+
const output = [];
|
|
11678
|
+
let command = "";
|
|
11679
|
+
let tokenIndex = 0;
|
|
11680
|
+
let currentX = 0;
|
|
11681
|
+
let currentY = 0;
|
|
11682
|
+
let subpathStartX = 0;
|
|
11683
|
+
let subpathStartY = 0;
|
|
11684
|
+
const transformPoint = getPointTransformer(origin);
|
|
11685
|
+
const getOriginalPoint = (x, y, isRelative) => ({
|
|
11686
|
+
x: isRelative ? currentX + x : x,
|
|
11687
|
+
y: isRelative ? currentY + y : y
|
|
11688
|
+
});
|
|
11689
|
+
while (tokenIndex < tokens.length) {
|
|
11690
|
+
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) {
|
|
11691
|
+
command = tokens[tokenIndex];
|
|
11692
|
+
tokenIndex += 1;
|
|
11693
|
+
}
|
|
11694
|
+
if (!command) break;
|
|
11695
|
+
const upperCommand = command.toUpperCase();
|
|
11696
|
+
const parameterCount = SVG_PATH_COMMAND_PARAMETER_COUNTS[upperCommand];
|
|
11697
|
+
if (parameterCount === void 0) break;
|
|
11698
|
+
if (upperCommand === "Z") {
|
|
11699
|
+
output.push("Z");
|
|
11700
|
+
currentX = subpathStartX;
|
|
11701
|
+
currentY = subpathStartY;
|
|
11702
|
+
command = "";
|
|
11703
|
+
continue;
|
|
11704
|
+
}
|
|
11705
|
+
if (tokenIndex + parameterCount > tokens.length) break;
|
|
11706
|
+
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) continue;
|
|
11707
|
+
const values = tokens.slice(tokenIndex, tokenIndex + parameterCount).map(Number);
|
|
11708
|
+
tokenIndex += parameterCount;
|
|
11709
|
+
const isRelative = command === command.toLowerCase();
|
|
11710
|
+
if (upperCommand === "H" || upperCommand === "V") {
|
|
11711
|
+
const point2 = getOriginalPoint(
|
|
11712
|
+
upperCommand === "H" ? values[0] : isRelative ? 0 : currentX,
|
|
11713
|
+
upperCommand === "V" ? values[0] : isRelative ? 0 : currentY,
|
|
11714
|
+
isRelative
|
|
11715
|
+
);
|
|
11716
|
+
const transformed = transformPoint(point2);
|
|
11717
|
+
output.push(
|
|
11718
|
+
`L ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
11719
|
+
);
|
|
11720
|
+
currentX = point2.x;
|
|
11721
|
+
currentY = point2.y;
|
|
11722
|
+
continue;
|
|
11723
|
+
}
|
|
11724
|
+
if (["M", "L", "T"].includes(upperCommand)) {
|
|
11725
|
+
const point2 = getOriginalPoint(values[0], values[1], isRelative);
|
|
11726
|
+
const transformed = transformPoint(point2);
|
|
11727
|
+
output.push(
|
|
11728
|
+
`${upperCommand} ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
11729
|
+
);
|
|
11730
|
+
currentX = point2.x;
|
|
11731
|
+
currentY = point2.y;
|
|
11732
|
+
if (upperCommand === "M") {
|
|
11733
|
+
subpathStartX = point2.x;
|
|
11734
|
+
subpathStartY = point2.y;
|
|
11735
|
+
command = isRelative ? "l" : "L";
|
|
11736
|
+
}
|
|
11737
|
+
continue;
|
|
11738
|
+
}
|
|
11739
|
+
if (["C", "S", "Q"].includes(upperCommand)) {
|
|
11740
|
+
const transformedValues = [];
|
|
11741
|
+
for (let valueIndex = 0; valueIndex < values.length; valueIndex += 2) {
|
|
11742
|
+
const point2 = getOriginalPoint(
|
|
11743
|
+
values[valueIndex],
|
|
11744
|
+
values[valueIndex + 1],
|
|
11745
|
+
isRelative
|
|
11746
|
+
);
|
|
11747
|
+
const transformed = transformPoint(point2);
|
|
11748
|
+
transformedValues.push(transformed.x, transformed.y);
|
|
11749
|
+
}
|
|
11750
|
+
output.push(
|
|
11751
|
+
`${upperCommand} ${transformedValues.map(formatNumber).join(" ")}`
|
|
11752
|
+
);
|
|
11753
|
+
currentX = isRelative ? currentX + values[values.length - 2] : values[values.length - 2];
|
|
11754
|
+
currentY = isRelative ? currentY + values[values.length - 1] : values[values.length - 1];
|
|
11755
|
+
continue;
|
|
11756
|
+
}
|
|
11757
|
+
if (upperCommand === "A") {
|
|
11758
|
+
const endpoint = getOriginalPoint(values[5], values[6], isRelative);
|
|
11759
|
+
const transformedEndpoint = transformPoint(endpoint);
|
|
11760
|
+
output.push(
|
|
11761
|
+
[
|
|
11762
|
+
"A",
|
|
11763
|
+
formatNumber(toMillimeters(Math.abs(values[0]))),
|
|
11764
|
+
formatNumber(toMillimeters(Math.abs(values[1]))),
|
|
11765
|
+
formatNumber(-values[2]),
|
|
11766
|
+
String(values[3]),
|
|
11767
|
+
String(values[4] === 0 ? 1 : 0),
|
|
11768
|
+
formatNumber(transformedEndpoint.x),
|
|
11769
|
+
formatNumber(transformedEndpoint.y)
|
|
11770
|
+
].join(" ")
|
|
11771
|
+
);
|
|
11772
|
+
currentX = endpoint.x;
|
|
11773
|
+
currentY = endpoint.y;
|
|
11774
|
+
}
|
|
11775
|
+
}
|
|
11776
|
+
return output.join(" ");
|
|
11777
|
+
};
|
|
11778
|
+
var getPinDirection = (rotation2) => {
|
|
11779
|
+
const normalizedRotation = (rotation2 % 360 + 360) % 360;
|
|
11780
|
+
if (normalizedRotation === 90) return "up";
|
|
11781
|
+
if (normalizedRotation === 180) return "left";
|
|
11782
|
+
if (normalizedRotation === 270) return "down";
|
|
11783
|
+
return "right";
|
|
11784
|
+
};
|
|
11785
|
+
var getPinStemLength = (path) => {
|
|
11786
|
+
const segment = path.match(/[hHvV]\s*(-?(?:\d*\.\d+|\d+\.?))/);
|
|
11787
|
+
if (!segment) return void 0;
|
|
11788
|
+
return toMillimeters(Math.abs(Number(segment[1])));
|
|
11789
|
+
};
|
|
11790
|
+
var getTextFontSizeMm = (fontSize) => {
|
|
11791
|
+
const numericFontSize = Number.parseFloat(fontSize);
|
|
11792
|
+
if (!Number.isFinite(numericFontSize)) return 1;
|
|
11793
|
+
if (fontSize.toLowerCase().endsWith("pt")) {
|
|
11794
|
+
return round(numericFontSize * 25.4 / 72);
|
|
11795
|
+
}
|
|
11796
|
+
return toMillimeters(numericFontSize);
|
|
11797
|
+
};
|
|
11798
|
+
var getTextAnchor = (alignment) => {
|
|
11799
|
+
if (alignment === "L") return "left";
|
|
11800
|
+
if (alignment === "R") return "right";
|
|
11801
|
+
return "center";
|
|
11802
|
+
};
|
|
11803
|
+
var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
|
|
11804
|
+
const pins = easyEdaJson.dataStr.shape.filter(
|
|
11805
|
+
(shape) => shape.type === "PIN"
|
|
11806
|
+
);
|
|
11807
|
+
const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
|
|
11808
|
+
(shape) => shape.type === "PAD"
|
|
11809
|
+
);
|
|
11810
|
+
const sourcePorts = circuitJson.filter(
|
|
11811
|
+
(element) => element.type === "source_port"
|
|
11812
|
+
);
|
|
11813
|
+
const sourcePortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
11814
|
+
pads.forEach((pad, padIndex) => {
|
|
11815
|
+
const sourcePort = sourcePorts.find(
|
|
11816
|
+
(port) => port.source_port_id === `source_port_${padIndex + 1}`
|
|
11817
|
+
);
|
|
11818
|
+
if (!sourcePort) return;
|
|
11819
|
+
const padNumber = String(pad.number);
|
|
11820
|
+
sourcePortNamesByPadNumber.set(padNumber, [
|
|
11821
|
+
...sourcePortNamesByPadNumber.get(padNumber) ?? [],
|
|
11822
|
+
sourcePort.name
|
|
11823
|
+
]);
|
|
11824
|
+
});
|
|
11825
|
+
const usedPortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
11826
|
+
const usedPortNames = /* @__PURE__ */ new Set();
|
|
11827
|
+
const metadataByShapeId = /* @__PURE__ */ new Map();
|
|
11828
|
+
pins.forEach((pin, pinIndex) => {
|
|
11829
|
+
const pinNumberKey = String(pin.pinNumber);
|
|
11830
|
+
const matchingPortNames = sourcePortNamesByPadNumber.get(pinNumberKey) ?? [];
|
|
11831
|
+
const matchingPortIndex = usedPortNamesByPadNumber.get(pinNumberKey) ?? 0;
|
|
11832
|
+
let portName = matchingPortNames[matchingPortIndex];
|
|
11833
|
+
usedPortNamesByPadNumber.set(pinNumberKey, matchingPortIndex + 1);
|
|
11834
|
+
if (!portName && pin.label) {
|
|
11835
|
+
const normalizedLabel = normalizeSymbolName(pin.label);
|
|
11836
|
+
portName = sourcePorts.find(
|
|
11837
|
+
(port) => !usedPortNames.has(port.name) && port.port_hints?.includes(normalizedLabel)
|
|
11838
|
+
)?.name;
|
|
11839
|
+
}
|
|
11840
|
+
const numericPinNumber = Number(pin.pinNumber);
|
|
11841
|
+
if (!portName && Number.isInteger(numericPinNumber)) {
|
|
11842
|
+
const numericPortName = `pin${numericPinNumber}`;
|
|
11843
|
+
if (sourcePorts.some((port) => port.name === numericPortName)) {
|
|
11844
|
+
portName = numericPortName;
|
|
11845
|
+
}
|
|
11846
|
+
}
|
|
11847
|
+
portName ??= sourcePorts[pinIndex]?.name ?? `pin${pinIndex + 1}`;
|
|
11848
|
+
usedPortNames.add(portName);
|
|
11849
|
+
const sourcePort = sourcePorts.find((port) => port.name === portName);
|
|
11850
|
+
metadataByShapeId.set(pin.id, {
|
|
11851
|
+
name: portName,
|
|
11852
|
+
pinNumber: sourcePort?.pin_number,
|
|
11853
|
+
aliases: [
|
|
11854
|
+
...sourcePort?.port_hints ?? [],
|
|
11855
|
+
...pin.label ? [normalizeSymbolName(pin.label)] : []
|
|
11856
|
+
].filter(
|
|
11857
|
+
(alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
|
|
11858
|
+
)
|
|
11859
|
+
});
|
|
11860
|
+
});
|
|
11861
|
+
return metadataByShapeId;
|
|
11862
|
+
};
|
|
11863
|
+
var generateShapeTsx = ({
|
|
11864
|
+
shape,
|
|
11865
|
+
origin,
|
|
11866
|
+
portMetadata
|
|
11867
|
+
}) => {
|
|
11868
|
+
const transformPoint = getPointTransformer(origin);
|
|
11869
|
+
if (shape.type === "RECTANGLE") {
|
|
11870
|
+
const center = transformPoint({
|
|
11871
|
+
x: shape.position.x + shape.width / 2,
|
|
11872
|
+
y: shape.position.y + shape.height / 2
|
|
11873
|
+
});
|
|
11874
|
+
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)}` : ""} />`;
|
|
11875
|
+
}
|
|
11876
|
+
if (shape.type === "ELLIPSE") {
|
|
11877
|
+
const center = transformPoint(shape.center);
|
|
11878
|
+
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)}` : ""} />`;
|
|
11879
|
+
}
|
|
11880
|
+
if (shape.type === "POLYLINE" || shape.type === "POLYGON") {
|
|
11881
|
+
const isPolygon = shape.type === "POLYGON";
|
|
11882
|
+
const points = shape.points.map(transformPoint);
|
|
11883
|
+
if (isPolygon && points.length > 0) points.push(points[0]);
|
|
11884
|
+
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)}` : ""} />`;
|
|
11885
|
+
}
|
|
11886
|
+
if (shape.type === "PATH") {
|
|
11887
|
+
const transformedPath = transformSvgPath(shape.pathData, origin);
|
|
11888
|
+
if (!transformedPath) return void 0;
|
|
11889
|
+
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeWidth={${shape.strokeWidth}} strokeColor=${JSON.stringify(shape.strokeColor)}${shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
11890
|
+
}
|
|
11891
|
+
if (shape.type === "ARC") {
|
|
11892
|
+
const transformedPath = transformSvgPath(shape.pathData, origin);
|
|
11893
|
+
if (!transformedPath) return void 0;
|
|
11894
|
+
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeWidth={${toMillimeters(shape.lineWidth)}} strokeColor=${JSON.stringify(shape.color)} />`;
|
|
11895
|
+
}
|
|
11896
|
+
if (shape.type === "TEXT") {
|
|
11897
|
+
if (shape.visibility !== "1") return void 0;
|
|
11898
|
+
const position2 = transformPoint({ x: shape.x, y: shape.y });
|
|
11899
|
+
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)}} />`;
|
|
11900
|
+
}
|
|
11901
|
+
if (shape.type === "PIN" && portMetadata) {
|
|
11902
|
+
const position2 = transformPoint({ x: shape.x, y: shape.y });
|
|
11903
|
+
const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
|
|
11904
|
+
const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
|
|
11905
|
+
const stemLength = getPinStemLength(shape.path);
|
|
11906
|
+
const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
|
|
11907
|
+
return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(getPinDirection(shape.rotation))} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
|
|
11908
|
+
}
|
|
11909
|
+
return void 0;
|
|
11910
|
+
};
|
|
11911
|
+
var generateSymbolTsx = (easyEdaJson, circuitJson) => {
|
|
11912
|
+
const shapes = easyEdaJson.dataStr.shape;
|
|
11913
|
+
if (shapes.length === 0) return void 0;
|
|
11914
|
+
const headOrigin = {
|
|
11915
|
+
x: easyEdaJson.dataStr.head.x,
|
|
11916
|
+
y: easyEdaJson.dataStr.head.y
|
|
11917
|
+
};
|
|
11918
|
+
const bounds = easyEdaJson.dataStr.BBox;
|
|
11919
|
+
const isHeadOriginInsideBounds = headOrigin.x >= bounds.x && headOrigin.x <= bounds.x + bounds.width && headOrigin.y >= bounds.y && headOrigin.y <= bounds.y + bounds.height;
|
|
11920
|
+
const origin = isHeadOriginInsideBounds ? headOrigin : {
|
|
11921
|
+
x: bounds.x + bounds.width / 2,
|
|
11922
|
+
y: bounds.y + bounds.height / 2
|
|
11923
|
+
};
|
|
11924
|
+
const portMetadataByShapeId = getPortMetadataByShapeId(
|
|
11925
|
+
easyEdaJson,
|
|
11926
|
+
circuitJson
|
|
11927
|
+
);
|
|
11928
|
+
const shapeTsx = shapes.map(
|
|
11929
|
+
(shape) => generateShapeTsx({
|
|
11930
|
+
shape,
|
|
11931
|
+
origin,
|
|
11932
|
+
portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
|
|
11933
|
+
})
|
|
11934
|
+
).filter((tsx) => Boolean(tsx));
|
|
11935
|
+
if (shapeTsx.length === 0) return void 0;
|
|
11936
|
+
return `<symbol>
|
|
11937
|
+
${shapeTsx.map((tsx) => ` ${tsx}`).join("\n")}
|
|
11938
|
+
</symbol>`;
|
|
11939
|
+
};
|
|
11940
|
+
var hasNonBoxSchematicSymbol = (easyEdaJson) => {
|
|
11941
|
+
const drawableShapes = easyEdaJson.dataStr.shape.filter(
|
|
11942
|
+
(shape) => shape.type !== "PIN" && shape.type !== "TEXT"
|
|
11943
|
+
);
|
|
11944
|
+
if (drawableShapes.length === 0) return false;
|
|
11945
|
+
const rectangles = drawableShapes.filter(
|
|
11946
|
+
(shape) => shape.type === "RECTANGLE"
|
|
11947
|
+
);
|
|
11948
|
+
const onlyBoxPrimitives = drawableShapes.every(
|
|
11949
|
+
(shape) => shape.type === "RECTANGLE" || shape.type === "ELLIPSE" && shape.radiusX <= 2 && shape.radiusY <= 2
|
|
11950
|
+
);
|
|
11951
|
+
return rectangles.length !== 1 || !onlyBoxPrimitives;
|
|
11952
|
+
};
|
|
11953
|
+
|
|
11644
11954
|
// lib/websafe/convert-to-typescript-component/index.tsx
|
|
11645
11955
|
var getGeneratedComponentType = (betterEasy) => {
|
|
11646
11956
|
if (isLedCategoryComponent(betterEasy)) return "led";
|
|
@@ -11706,6 +12016,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
11706
12016
|
const supplierPartNumbers = {
|
|
11707
12017
|
jlcpcb: [betterEasy.lcsc.number]
|
|
11708
12018
|
};
|
|
12019
|
+
const componentType = getGeneratedComponentType(betterEasy);
|
|
12020
|
+
const symbolTsx = componentType === "chip" && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson) : void 0;
|
|
11709
12021
|
return generateTypescriptComponent({
|
|
11710
12022
|
componentName: pn,
|
|
11711
12023
|
manufacturerPartNumber: pn,
|
|
@@ -11714,7 +12026,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
11714
12026
|
stepUrl: modelStepUrl,
|
|
11715
12027
|
circuitJson,
|
|
11716
12028
|
supplierPartNumbers,
|
|
11717
|
-
componentType
|
|
12029
|
+
componentType,
|
|
12030
|
+
symbolTsx
|
|
11718
12031
|
});
|
|
11719
12032
|
};
|
|
11720
12033
|
var checkModelObjUrlValidity = async (url) => {
|