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/main.cjs
CHANGED
|
@@ -3441,7 +3441,14 @@ async function fetchEasyEDAComponent(jlcpcbPartNumber, {
|
|
|
3441
3441
|
body: searchData
|
|
3442
3442
|
});
|
|
3443
3443
|
if (!searchResponse.ok) {
|
|
3444
|
-
|
|
3444
|
+
if (searchResponse.status === 403) {
|
|
3445
|
+
throw new Error(
|
|
3446
|
+
`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.`
|
|
3447
|
+
);
|
|
3448
|
+
}
|
|
3449
|
+
throw new Error(
|
|
3450
|
+
`Failed to search for the component (HTTP ${searchResponse.status})`
|
|
3451
|
+
);
|
|
3445
3452
|
}
|
|
3446
3453
|
const searchResult = await searchResponse.json();
|
|
3447
3454
|
if (!searchResult.success || !searchResult.result.lists.lcsc.length) {
|
|
@@ -3459,7 +3466,14 @@ async function fetchEasyEDAComponent(jlcpcbPartNumber, {
|
|
|
3459
3466
|
}
|
|
3460
3467
|
});
|
|
3461
3468
|
if (!componentResponse.ok) {
|
|
3462
|
-
|
|
3469
|
+
if (componentResponse.status === 403) {
|
|
3470
|
+
throw new Error(
|
|
3471
|
+
`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.`
|
|
3472
|
+
);
|
|
3473
|
+
}
|
|
3474
|
+
throw new Error(
|
|
3475
|
+
`Failed to fetch the component details (HTTP ${componentResponse.status})`
|
|
3476
|
+
);
|
|
3463
3477
|
}
|
|
3464
3478
|
const componentResult = await componentResponse.json();
|
|
3465
3479
|
const result = componentResult.result;
|
|
@@ -3499,7 +3513,7 @@ var import_promises = __toESM(require("fs/promises"), 1);
|
|
|
3499
3513
|
var package_default = {
|
|
3500
3514
|
name: "easyeda",
|
|
3501
3515
|
type: "module",
|
|
3502
|
-
version: "0.0.
|
|
3516
|
+
version: "0.0.275",
|
|
3503
3517
|
files: [
|
|
3504
3518
|
"dist"
|
|
3505
3519
|
],
|
|
@@ -3519,7 +3533,7 @@ var package_default = {
|
|
|
3519
3533
|
"@types/bun": "latest",
|
|
3520
3534
|
"bun-match-svg": "^0.0.13",
|
|
3521
3535
|
"circuit-json-to-gltf": "^0.0.106",
|
|
3522
|
-
"circuit-to-svg": "^0.0.
|
|
3536
|
+
"circuit-to-svg": "^0.0.392",
|
|
3523
3537
|
"looks-same": "^9.0.1",
|
|
3524
3538
|
poppygl: "^0.0.24",
|
|
3525
3539
|
"transformation-matrix": "^2.16.1",
|
|
@@ -10376,10 +10390,11 @@ var RectangleShapeOutputSchema = import_zod180.z.object({
|
|
|
10376
10390
|
height: import_zod180.z.number(),
|
|
10377
10391
|
color: import_zod180.z.string(),
|
|
10378
10392
|
lineWidth: import_zod180.z.number(),
|
|
10393
|
+
fillColor: import_zod180.z.string().optional(),
|
|
10379
10394
|
id: import_zod180.z.string()
|
|
10380
10395
|
});
|
|
10381
10396
|
var parseRectangle = (str) => {
|
|
10382
|
-
const [, x, y, , , width, height, color, lineWidth, , , id] = str.split("~");
|
|
10397
|
+
const [, x, y, , , width, height, color, lineWidth, , fillColor, id] = str.split("~");
|
|
10383
10398
|
return {
|
|
10384
10399
|
type: "RECTANGLE",
|
|
10385
10400
|
position: { x: Number(x), y: Number(y) },
|
|
@@ -10387,6 +10402,7 @@ var parseRectangle = (str) => {
|
|
|
10387
10402
|
height: Number(height),
|
|
10388
10403
|
color,
|
|
10389
10404
|
lineWidth: Number(lineWidth),
|
|
10405
|
+
fillColor,
|
|
10390
10406
|
id
|
|
10391
10407
|
};
|
|
10392
10408
|
};
|
|
@@ -10398,10 +10414,11 @@ var EllipseShapeOutputSchema = import_zod180.z.object({
|
|
|
10398
10414
|
radiusY: import_zod180.z.number(),
|
|
10399
10415
|
color: import_zod180.z.string(),
|
|
10400
10416
|
lineWidth: import_zod180.z.number(),
|
|
10417
|
+
fillColor: import_zod180.z.string().optional(),
|
|
10401
10418
|
id: import_zod180.z.string()
|
|
10402
10419
|
});
|
|
10403
10420
|
var parseEllipse = (str) => {
|
|
10404
|
-
const [, x, y, radiusX, radiusY, color, lineWidth, , , id] = str.split("~");
|
|
10421
|
+
const [, x, y, radiusX, radiusY, color, lineWidth, , fillColor, id] = str.split("~");
|
|
10405
10422
|
return {
|
|
10406
10423
|
type: "ELLIPSE",
|
|
10407
10424
|
center: { x: Number(x), y: Number(y) },
|
|
@@ -10409,12 +10426,14 @@ var parseEllipse = (str) => {
|
|
|
10409
10426
|
radiusY: Number(radiusY),
|
|
10410
10427
|
color,
|
|
10411
10428
|
lineWidth: Number(lineWidth),
|
|
10429
|
+
fillColor,
|
|
10412
10430
|
id
|
|
10413
10431
|
};
|
|
10414
10432
|
};
|
|
10415
10433
|
var EllipseShapeSchema = import_zod180.z.string().startsWith("E~").transform(parseEllipse).pipe(EllipseShapeOutputSchema);
|
|
10416
10434
|
var ArcShapeOutputSchema = import_zod180.z.object({
|
|
10417
10435
|
type: import_zod180.z.literal("ARC"),
|
|
10436
|
+
pathData: import_zod180.z.string(),
|
|
10418
10437
|
start: PointSchema2,
|
|
10419
10438
|
end: PointSchema2,
|
|
10420
10439
|
radius: import_zod180.z.number(),
|
|
@@ -10424,26 +10443,25 @@ var ArcShapeOutputSchema = import_zod180.z.object({
|
|
|
10424
10443
|
id: import_zod180.z.string()
|
|
10425
10444
|
});
|
|
10426
10445
|
var parseArc = (str) => {
|
|
10427
|
-
const [, pathData,
|
|
10428
|
-
const
|
|
10429
|
-
const
|
|
10430
|
-
const
|
|
10431
|
-
const
|
|
10432
|
-
const
|
|
10433
|
-
const x2 =
|
|
10434
|
-
const y2 = Number(parts[9]) || 0;
|
|
10446
|
+
const [, pathData, ...fields] = str.split("~");
|
|
10447
|
+
const colorIndex = fields.findIndex((field) => /^#[0-9a-f]{6}$/i.test(field));
|
|
10448
|
+
const color = fields[colorIndex] || "#880000";
|
|
10449
|
+
const lineWidth = fields[colorIndex + 1];
|
|
10450
|
+
const id = fields.find((field) => /^(?:gge|rep)/.test(field)) || "gge1";
|
|
10451
|
+
const numbers = pathData.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
|
|
10452
|
+
const [x1 = 0, y1 = 0, radius = 0, , , , sweepFlag = 0, x2 = 0, y2 = 0] = numbers;
|
|
10435
10453
|
const parsedLineWidth = Number(lineWidth);
|
|
10436
10454
|
const finalLineWidth = Number.isNaN(parsedLineWidth) ? 1 : parsedLineWidth;
|
|
10437
10455
|
return {
|
|
10438
10456
|
type: "ARC",
|
|
10457
|
+
pathData,
|
|
10439
10458
|
start: { x: x1, y: y1 },
|
|
10440
10459
|
end: { x: x2, y: y2 },
|
|
10441
10460
|
radius,
|
|
10442
|
-
sweepFlag,
|
|
10443
|
-
color
|
|
10444
|
-
// Default color
|
|
10461
|
+
sweepFlag: sweepFlag === 1,
|
|
10462
|
+
color,
|
|
10445
10463
|
lineWidth: finalLineWidth,
|
|
10446
|
-
id
|
|
10464
|
+
id
|
|
10447
10465
|
};
|
|
10448
10466
|
};
|
|
10449
10467
|
var ArcShapeSchema = import_zod180.z.string().startsWith("A~").transform(parseArc).pipe(ArcShapeOutputSchema);
|
|
@@ -10471,8 +10489,7 @@ var parsePin = (pinString) => {
|
|
|
10471
10489
|
if (/^\+\d+(?:\.\d+)?V$/i.test(label)) label = `V${label.slice(1, -1)}`;
|
|
10472
10490
|
const colorMatch = pinString.match(/#[0-9A-F]{6}/);
|
|
10473
10491
|
const labelColor = colorMatch ? colorMatch[0] : "";
|
|
10474
|
-
const
|
|
10475
|
-
const path = pathMatch ? pathMatch[1] : "";
|
|
10492
|
+
const path = pinString.split("^^")[2]?.split("~")[0] ?? "";
|
|
10476
10493
|
const arrowMatch = pinString.match(/\^\^0~(.+)$/);
|
|
10477
10494
|
const arrow = arrowMatch ? arrowMatch[1] : "";
|
|
10478
10495
|
const r = Number.parseFloat(rotation2);
|
|
@@ -10530,7 +10547,7 @@ var PolygonShapeOutputSchema = import_zod180.z.object({
|
|
|
10530
10547
|
});
|
|
10531
10548
|
var parsePolygon = (str) => {
|
|
10532
10549
|
const [, ...rest] = str.split("~");
|
|
10533
|
-
const [pointsStr,
|
|
10550
|
+
const [pointsStr, lineColor, lineWidth, , fillColor, id] = rest;
|
|
10534
10551
|
return {
|
|
10535
10552
|
type: "POLYGON",
|
|
10536
10553
|
points: parsePoints2(pointsStr),
|
|
@@ -10550,7 +10567,7 @@ var PathShapeOutputSchema = import_zod180.z.object({
|
|
|
10550
10567
|
id: import_zod180.z.string()
|
|
10551
10568
|
});
|
|
10552
10569
|
var parsePath = (str) => {
|
|
10553
|
-
const [, pathData,
|
|
10570
|
+
const [, pathData, strokeColor, strokeWidth, , fillColor, id] = str.split("~");
|
|
10554
10571
|
return {
|
|
10555
10572
|
type: "PATH",
|
|
10556
10573
|
pathData,
|
|
@@ -10600,8 +10617,8 @@ var parseText = (str) => {
|
|
|
10600
10617
|
fontWeight,
|
|
10601
10618
|
fontStyle,
|
|
10602
10619
|
fontDecoration,
|
|
10603
|
-
content,
|
|
10604
10620
|
textType,
|
|
10621
|
+
content,
|
|
10605
10622
|
visibility,
|
|
10606
10623
|
mirror,
|
|
10607
10624
|
id
|
|
@@ -11049,7 +11066,8 @@ var generateTypescriptComponent = ({
|
|
|
11049
11066
|
circuitJson,
|
|
11050
11067
|
supplierPartNumbers,
|
|
11051
11068
|
manufacturerPartNumber,
|
|
11052
|
-
componentType = "chip"
|
|
11069
|
+
componentType = "chip",
|
|
11070
|
+
symbolTsx
|
|
11053
11071
|
}) => {
|
|
11054
11072
|
const safePinLabels = pinLabels ?? {};
|
|
11055
11073
|
const polarizedPinMetadata = getPolarizedPinMetadata(safePinLabels);
|
|
@@ -11076,6 +11094,10 @@ ${polarizedPinLabelsString}
|
|
|
11076
11094
|
|
|
11077
11095
|
` : "";
|
|
11078
11096
|
const polarizedPinLabelsProp = polarizedPinLabels ? ` pinLabels={pinLabels}
|
|
11097
|
+
` : "";
|
|
11098
|
+
const symbolProp = symbolTsx ? ` symbol={
|
|
11099
|
+
${symbolTsx.split("\n").map((line) => ` ${line}`).join("\n")}
|
|
11100
|
+
}
|
|
11079
11101
|
` : "";
|
|
11080
11102
|
const cadModelLines = [
|
|
11081
11103
|
objUrl ? `objUrl: "${objUrl}",` : "",
|
|
@@ -11093,7 +11115,7 @@ ${polarizedPinLabelsBlock}export const ${componentName} = (props: DiodeProps) =>
|
|
|
11093
11115
|
return (
|
|
11094
11116
|
<diode
|
|
11095
11117
|
name={name}
|
|
11096
|
-
${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11118
|
+
${polarizedPinLabelsProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11097
11119
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11098
11120
|
footprint={${footprintTsx}}
|
|
11099
11121
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11115,7 +11137,7 @@ ${polarizedPinLabelsBlock}export const ${componentName} = (props: LedProps) => {
|
|
|
11115
11137
|
return (
|
|
11116
11138
|
<led
|
|
11117
11139
|
name={name}
|
|
11118
|
-
${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11140
|
+
${polarizedPinLabelsProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11119
11141
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11120
11142
|
footprint={${footprintTsx}}
|
|
11121
11143
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11142,7 +11164,7 @@ export const ${componentName} = (props: PushButtonProps<typeof pinLabels>) => {
|
|
|
11142
11164
|
<pushbutton
|
|
11143
11165
|
name={name}
|
|
11144
11166
|
pinLabels={pinLabels}
|
|
11145
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11167
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11146
11168
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11147
11169
|
footprint={${footprintTsx}}
|
|
11148
11170
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11169,7 +11191,7 @@ export const ${componentName} = (props: SwitchProps) => {
|
|
|
11169
11191
|
<switch
|
|
11170
11192
|
name={name}
|
|
11171
11193
|
pinLabels={pinLabels}
|
|
11172
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11194
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11173
11195
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11174
11196
|
footprint={${footprintTsx}}
|
|
11175
11197
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11192,7 +11214,7 @@ export const ${componentName} = (props: ChipProps<typeof pinLabels>) => {
|
|
|
11192
11214
|
return (
|
|
11193
11215
|
<chip
|
|
11194
11216
|
pinLabels={pinLabels}
|
|
11195
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11217
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11196
11218
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11197
11219
|
footprint={${footprintTsx}}
|
|
11198
11220
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11321,6 +11343,307 @@ var isSwitchCategoryComponent = (betterEasy) => {
|
|
|
11321
11343
|
].some(categoryValueContainsSwitch);
|
|
11322
11344
|
};
|
|
11323
11345
|
|
|
11346
|
+
// lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
|
|
11347
|
+
var round = (value) => Number(value.toFixed(6));
|
|
11348
|
+
var toMillimeters = (value) => round(mil10ToMm(value));
|
|
11349
|
+
var getPointTransformer = (origin) => (point2) => ({
|
|
11350
|
+
x: toMillimeters(point2.x - origin.x),
|
|
11351
|
+
y: toMillimeters(origin.y - point2.y)
|
|
11352
|
+
});
|
|
11353
|
+
var formatNumber = (value) => String(round(value));
|
|
11354
|
+
var SVG_PATH_COMMAND_PARAMETER_COUNTS = {
|
|
11355
|
+
A: 7,
|
|
11356
|
+
C: 6,
|
|
11357
|
+
H: 1,
|
|
11358
|
+
L: 2,
|
|
11359
|
+
M: 2,
|
|
11360
|
+
Q: 4,
|
|
11361
|
+
S: 4,
|
|
11362
|
+
T: 2,
|
|
11363
|
+
V: 1,
|
|
11364
|
+
Z: 0
|
|
11365
|
+
};
|
|
11366
|
+
var transformSvgPath = (pathData, origin) => {
|
|
11367
|
+
const tokens = pathData.match(
|
|
11368
|
+
/[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g
|
|
11369
|
+
) ?? [];
|
|
11370
|
+
const output = [];
|
|
11371
|
+
let command = "";
|
|
11372
|
+
let tokenIndex = 0;
|
|
11373
|
+
let currentX = 0;
|
|
11374
|
+
let currentY = 0;
|
|
11375
|
+
let subpathStartX = 0;
|
|
11376
|
+
let subpathStartY = 0;
|
|
11377
|
+
const transformPoint = getPointTransformer(origin);
|
|
11378
|
+
const getOriginalPoint = (x, y, isRelative) => ({
|
|
11379
|
+
x: isRelative ? currentX + x : x,
|
|
11380
|
+
y: isRelative ? currentY + y : y
|
|
11381
|
+
});
|
|
11382
|
+
while (tokenIndex < tokens.length) {
|
|
11383
|
+
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) {
|
|
11384
|
+
command = tokens[tokenIndex];
|
|
11385
|
+
tokenIndex += 1;
|
|
11386
|
+
}
|
|
11387
|
+
if (!command) break;
|
|
11388
|
+
const upperCommand = command.toUpperCase();
|
|
11389
|
+
const parameterCount = SVG_PATH_COMMAND_PARAMETER_COUNTS[upperCommand];
|
|
11390
|
+
if (parameterCount === void 0) break;
|
|
11391
|
+
if (upperCommand === "Z") {
|
|
11392
|
+
output.push("Z");
|
|
11393
|
+
currentX = subpathStartX;
|
|
11394
|
+
currentY = subpathStartY;
|
|
11395
|
+
command = "";
|
|
11396
|
+
continue;
|
|
11397
|
+
}
|
|
11398
|
+
if (tokenIndex + parameterCount > tokens.length) break;
|
|
11399
|
+
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) continue;
|
|
11400
|
+
const values = tokens.slice(tokenIndex, tokenIndex + parameterCount).map(Number);
|
|
11401
|
+
tokenIndex += parameterCount;
|
|
11402
|
+
const isRelative = command === command.toLowerCase();
|
|
11403
|
+
if (upperCommand === "H" || upperCommand === "V") {
|
|
11404
|
+
const point2 = getOriginalPoint(
|
|
11405
|
+
upperCommand === "H" ? values[0] : isRelative ? 0 : currentX,
|
|
11406
|
+
upperCommand === "V" ? values[0] : isRelative ? 0 : currentY,
|
|
11407
|
+
isRelative
|
|
11408
|
+
);
|
|
11409
|
+
const transformed = transformPoint(point2);
|
|
11410
|
+
output.push(
|
|
11411
|
+
`L ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
11412
|
+
);
|
|
11413
|
+
currentX = point2.x;
|
|
11414
|
+
currentY = point2.y;
|
|
11415
|
+
continue;
|
|
11416
|
+
}
|
|
11417
|
+
if (["M", "L", "T"].includes(upperCommand)) {
|
|
11418
|
+
const point2 = getOriginalPoint(values[0], values[1], isRelative);
|
|
11419
|
+
const transformed = transformPoint(point2);
|
|
11420
|
+
output.push(
|
|
11421
|
+
`${upperCommand} ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
11422
|
+
);
|
|
11423
|
+
currentX = point2.x;
|
|
11424
|
+
currentY = point2.y;
|
|
11425
|
+
if (upperCommand === "M") {
|
|
11426
|
+
subpathStartX = point2.x;
|
|
11427
|
+
subpathStartY = point2.y;
|
|
11428
|
+
command = isRelative ? "l" : "L";
|
|
11429
|
+
}
|
|
11430
|
+
continue;
|
|
11431
|
+
}
|
|
11432
|
+
if (["C", "S", "Q"].includes(upperCommand)) {
|
|
11433
|
+
const transformedValues = [];
|
|
11434
|
+
for (let valueIndex = 0; valueIndex < values.length; valueIndex += 2) {
|
|
11435
|
+
const point2 = getOriginalPoint(
|
|
11436
|
+
values[valueIndex],
|
|
11437
|
+
values[valueIndex + 1],
|
|
11438
|
+
isRelative
|
|
11439
|
+
);
|
|
11440
|
+
const transformed = transformPoint(point2);
|
|
11441
|
+
transformedValues.push(transformed.x, transformed.y);
|
|
11442
|
+
}
|
|
11443
|
+
output.push(
|
|
11444
|
+
`${upperCommand} ${transformedValues.map(formatNumber).join(" ")}`
|
|
11445
|
+
);
|
|
11446
|
+
currentX = isRelative ? currentX + values[values.length - 2] : values[values.length - 2];
|
|
11447
|
+
currentY = isRelative ? currentY + values[values.length - 1] : values[values.length - 1];
|
|
11448
|
+
continue;
|
|
11449
|
+
}
|
|
11450
|
+
if (upperCommand === "A") {
|
|
11451
|
+
const endpoint = getOriginalPoint(values[5], values[6], isRelative);
|
|
11452
|
+
const transformedEndpoint = transformPoint(endpoint);
|
|
11453
|
+
output.push(
|
|
11454
|
+
[
|
|
11455
|
+
"A",
|
|
11456
|
+
formatNumber(toMillimeters(Math.abs(values[0]))),
|
|
11457
|
+
formatNumber(toMillimeters(Math.abs(values[1]))),
|
|
11458
|
+
formatNumber(-values[2]),
|
|
11459
|
+
String(values[3]),
|
|
11460
|
+
String(values[4] === 0 ? 1 : 0),
|
|
11461
|
+
formatNumber(transformedEndpoint.x),
|
|
11462
|
+
formatNumber(transformedEndpoint.y)
|
|
11463
|
+
].join(" ")
|
|
11464
|
+
);
|
|
11465
|
+
currentX = endpoint.x;
|
|
11466
|
+
currentY = endpoint.y;
|
|
11467
|
+
}
|
|
11468
|
+
}
|
|
11469
|
+
return output.join(" ");
|
|
11470
|
+
};
|
|
11471
|
+
var getPinDirection = (rotation2) => {
|
|
11472
|
+
const normalizedRotation = (rotation2 % 360 + 360) % 360;
|
|
11473
|
+
if (normalizedRotation === 90) return "up";
|
|
11474
|
+
if (normalizedRotation === 180) return "left";
|
|
11475
|
+
if (normalizedRotation === 270) return "down";
|
|
11476
|
+
return "right";
|
|
11477
|
+
};
|
|
11478
|
+
var getPinStemLength = (path) => {
|
|
11479
|
+
const segment = path.match(/[hHvV]\s*(-?(?:\d*\.\d+|\d+\.?))/);
|
|
11480
|
+
if (!segment) return void 0;
|
|
11481
|
+
return toMillimeters(Math.abs(Number(segment[1])));
|
|
11482
|
+
};
|
|
11483
|
+
var getTextFontSizeMm = (fontSize) => {
|
|
11484
|
+
const numericFontSize = Number.parseFloat(fontSize);
|
|
11485
|
+
if (!Number.isFinite(numericFontSize)) return 1;
|
|
11486
|
+
if (fontSize.toLowerCase().endsWith("pt")) {
|
|
11487
|
+
return round(numericFontSize * 25.4 / 72);
|
|
11488
|
+
}
|
|
11489
|
+
return toMillimeters(numericFontSize);
|
|
11490
|
+
};
|
|
11491
|
+
var getTextAnchor = (alignment) => {
|
|
11492
|
+
if (alignment === "L") return "left";
|
|
11493
|
+
if (alignment === "R") return "right";
|
|
11494
|
+
return "center";
|
|
11495
|
+
};
|
|
11496
|
+
var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
|
|
11497
|
+
const pins = easyEdaJson.dataStr.shape.filter(
|
|
11498
|
+
(shape) => shape.type === "PIN"
|
|
11499
|
+
);
|
|
11500
|
+
const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
|
|
11501
|
+
(shape) => shape.type === "PAD"
|
|
11502
|
+
);
|
|
11503
|
+
const sourcePorts = circuitJson.filter(
|
|
11504
|
+
(element) => element.type === "source_port"
|
|
11505
|
+
);
|
|
11506
|
+
const sourcePortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
11507
|
+
pads.forEach((pad, padIndex) => {
|
|
11508
|
+
const sourcePort = sourcePorts.find(
|
|
11509
|
+
(port) => port.source_port_id === `source_port_${padIndex + 1}`
|
|
11510
|
+
);
|
|
11511
|
+
if (!sourcePort) return;
|
|
11512
|
+
const padNumber = String(pad.number);
|
|
11513
|
+
sourcePortNamesByPadNumber.set(padNumber, [
|
|
11514
|
+
...sourcePortNamesByPadNumber.get(padNumber) ?? [],
|
|
11515
|
+
sourcePort.name
|
|
11516
|
+
]);
|
|
11517
|
+
});
|
|
11518
|
+
const usedPortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
11519
|
+
const usedPortNames = /* @__PURE__ */ new Set();
|
|
11520
|
+
const metadataByShapeId = /* @__PURE__ */ new Map();
|
|
11521
|
+
pins.forEach((pin, pinIndex) => {
|
|
11522
|
+
const pinNumberKey = String(pin.pinNumber);
|
|
11523
|
+
const matchingPortNames = sourcePortNamesByPadNumber.get(pinNumberKey) ?? [];
|
|
11524
|
+
const matchingPortIndex = usedPortNamesByPadNumber.get(pinNumberKey) ?? 0;
|
|
11525
|
+
let portName = matchingPortNames[matchingPortIndex];
|
|
11526
|
+
usedPortNamesByPadNumber.set(pinNumberKey, matchingPortIndex + 1);
|
|
11527
|
+
if (!portName && pin.label) {
|
|
11528
|
+
const normalizedLabel = normalizeSymbolName(pin.label);
|
|
11529
|
+
portName = sourcePorts.find(
|
|
11530
|
+
(port) => !usedPortNames.has(port.name) && port.port_hints?.includes(normalizedLabel)
|
|
11531
|
+
)?.name;
|
|
11532
|
+
}
|
|
11533
|
+
const numericPinNumber = Number(pin.pinNumber);
|
|
11534
|
+
if (!portName && Number.isInteger(numericPinNumber)) {
|
|
11535
|
+
const numericPortName = `pin${numericPinNumber}`;
|
|
11536
|
+
if (sourcePorts.some((port) => port.name === numericPortName)) {
|
|
11537
|
+
portName = numericPortName;
|
|
11538
|
+
}
|
|
11539
|
+
}
|
|
11540
|
+
portName ??= sourcePorts[pinIndex]?.name ?? `pin${pinIndex + 1}`;
|
|
11541
|
+
usedPortNames.add(portName);
|
|
11542
|
+
const sourcePort = sourcePorts.find((port) => port.name === portName);
|
|
11543
|
+
metadataByShapeId.set(pin.id, {
|
|
11544
|
+
name: portName,
|
|
11545
|
+
pinNumber: sourcePort?.pin_number,
|
|
11546
|
+
aliases: [
|
|
11547
|
+
...sourcePort?.port_hints ?? [],
|
|
11548
|
+
...pin.label ? [normalizeSymbolName(pin.label)] : []
|
|
11549
|
+
].filter(
|
|
11550
|
+
(alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
|
|
11551
|
+
)
|
|
11552
|
+
});
|
|
11553
|
+
});
|
|
11554
|
+
return metadataByShapeId;
|
|
11555
|
+
};
|
|
11556
|
+
var generateShapeTsx = ({
|
|
11557
|
+
shape,
|
|
11558
|
+
origin,
|
|
11559
|
+
portMetadata
|
|
11560
|
+
}) => {
|
|
11561
|
+
const transformPoint = getPointTransformer(origin);
|
|
11562
|
+
if (shape.type === "RECTANGLE") {
|
|
11563
|
+
const center = transformPoint({
|
|
11564
|
+
x: shape.position.x + shape.width / 2,
|
|
11565
|
+
y: shape.position.y + shape.height / 2
|
|
11566
|
+
});
|
|
11567
|
+
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)}` : ""} />`;
|
|
11568
|
+
}
|
|
11569
|
+
if (shape.type === "ELLIPSE") {
|
|
11570
|
+
const center = transformPoint(shape.center);
|
|
11571
|
+
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)}` : ""} />`;
|
|
11572
|
+
}
|
|
11573
|
+
if (shape.type === "POLYLINE" || shape.type === "POLYGON") {
|
|
11574
|
+
const isPolygon = shape.type === "POLYGON";
|
|
11575
|
+
const points = shape.points.map(transformPoint);
|
|
11576
|
+
if (isPolygon && points.length > 0) points.push(points[0]);
|
|
11577
|
+
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)}` : ""} />`;
|
|
11578
|
+
}
|
|
11579
|
+
if (shape.type === "PATH") {
|
|
11580
|
+
const transformedPath = transformSvgPath(shape.pathData, origin);
|
|
11581
|
+
if (!transformedPath) return void 0;
|
|
11582
|
+
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeWidth={${shape.strokeWidth}} strokeColor=${JSON.stringify(shape.strokeColor)}${shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
11583
|
+
}
|
|
11584
|
+
if (shape.type === "ARC") {
|
|
11585
|
+
const transformedPath = transformSvgPath(shape.pathData, origin);
|
|
11586
|
+
if (!transformedPath) return void 0;
|
|
11587
|
+
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeWidth={${toMillimeters(shape.lineWidth)}} strokeColor=${JSON.stringify(shape.color)} />`;
|
|
11588
|
+
}
|
|
11589
|
+
if (shape.type === "TEXT") {
|
|
11590
|
+
if (shape.visibility !== "1") return void 0;
|
|
11591
|
+
const position2 = transformPoint({ x: shape.x, y: shape.y });
|
|
11592
|
+
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)}} />`;
|
|
11593
|
+
}
|
|
11594
|
+
if (shape.type === "PIN" && portMetadata) {
|
|
11595
|
+
const position2 = transformPoint({ x: shape.x, y: shape.y });
|
|
11596
|
+
const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
|
|
11597
|
+
const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
|
|
11598
|
+
const stemLength = getPinStemLength(shape.path);
|
|
11599
|
+
const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
|
|
11600
|
+
return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(getPinDirection(shape.rotation))} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
|
|
11601
|
+
}
|
|
11602
|
+
return void 0;
|
|
11603
|
+
};
|
|
11604
|
+
var generateSymbolTsx = (easyEdaJson, circuitJson) => {
|
|
11605
|
+
const shapes = easyEdaJson.dataStr.shape;
|
|
11606
|
+
if (shapes.length === 0) return void 0;
|
|
11607
|
+
const headOrigin = {
|
|
11608
|
+
x: easyEdaJson.dataStr.head.x,
|
|
11609
|
+
y: easyEdaJson.dataStr.head.y
|
|
11610
|
+
};
|
|
11611
|
+
const bounds = easyEdaJson.dataStr.BBox;
|
|
11612
|
+
const isHeadOriginInsideBounds = headOrigin.x >= bounds.x && headOrigin.x <= bounds.x + bounds.width && headOrigin.y >= bounds.y && headOrigin.y <= bounds.y + bounds.height;
|
|
11613
|
+
const origin = isHeadOriginInsideBounds ? headOrigin : {
|
|
11614
|
+
x: bounds.x + bounds.width / 2,
|
|
11615
|
+
y: bounds.y + bounds.height / 2
|
|
11616
|
+
};
|
|
11617
|
+
const portMetadataByShapeId = getPortMetadataByShapeId(
|
|
11618
|
+
easyEdaJson,
|
|
11619
|
+
circuitJson
|
|
11620
|
+
);
|
|
11621
|
+
const shapeTsx = shapes.map(
|
|
11622
|
+
(shape) => generateShapeTsx({
|
|
11623
|
+
shape,
|
|
11624
|
+
origin,
|
|
11625
|
+
portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
|
|
11626
|
+
})
|
|
11627
|
+
).filter((tsx) => Boolean(tsx));
|
|
11628
|
+
if (shapeTsx.length === 0) return void 0;
|
|
11629
|
+
return `<symbol>
|
|
11630
|
+
${shapeTsx.map((tsx) => ` ${tsx}`).join("\n")}
|
|
11631
|
+
</symbol>`;
|
|
11632
|
+
};
|
|
11633
|
+
var hasNonBoxSchematicSymbol = (easyEdaJson) => {
|
|
11634
|
+
const drawableShapes = easyEdaJson.dataStr.shape.filter(
|
|
11635
|
+
(shape) => shape.type !== "PIN" && shape.type !== "TEXT"
|
|
11636
|
+
);
|
|
11637
|
+
if (drawableShapes.length === 0) return false;
|
|
11638
|
+
const rectangles = drawableShapes.filter(
|
|
11639
|
+
(shape) => shape.type === "RECTANGLE"
|
|
11640
|
+
);
|
|
11641
|
+
const onlyBoxPrimitives = drawableShapes.every(
|
|
11642
|
+
(shape) => shape.type === "RECTANGLE" || shape.type === "ELLIPSE" && shape.radiusX <= 2 && shape.radiusY <= 2
|
|
11643
|
+
);
|
|
11644
|
+
return rectangles.length !== 1 || !onlyBoxPrimitives;
|
|
11645
|
+
};
|
|
11646
|
+
|
|
11324
11647
|
// lib/websafe/convert-to-typescript-component/index.tsx
|
|
11325
11648
|
var getGeneratedComponentType = (betterEasy) => {
|
|
11326
11649
|
if (isLedCategoryComponent(betterEasy)) return "led";
|
|
@@ -11386,6 +11709,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
11386
11709
|
const supplierPartNumbers = {
|
|
11387
11710
|
jlcpcb: [betterEasy.lcsc.number]
|
|
11388
11711
|
};
|
|
11712
|
+
const componentType = getGeneratedComponentType(betterEasy);
|
|
11713
|
+
const symbolTsx = componentType === "chip" && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson) : void 0;
|
|
11389
11714
|
return generateTypescriptComponent({
|
|
11390
11715
|
componentName: pn,
|
|
11391
11716
|
manufacturerPartNumber: pn,
|
|
@@ -11394,7 +11719,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
11394
11719
|
stepUrl: modelStepUrl,
|
|
11395
11720
|
circuitJson,
|
|
11396
11721
|
supplierPartNumbers,
|
|
11397
|
-
componentType
|
|
11722
|
+
componentType,
|
|
11723
|
+
symbolTsx
|
|
11398
11724
|
});
|
|
11399
11725
|
};
|
|
11400
11726
|
var checkModelObjUrlValidity = async (url) => {
|