easyeda 0.0.274 → 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 +338 -26
- package/dist/browser/index.js.map +1 -1
- package/dist/index.d.ts +33 -0
- package/dist/index.js +338 -26
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +340 -28
- package/dist/main.cjs.map +1 -1
- package/package.json +2 -2
package/dist/main.cjs
CHANGED
|
@@ -3499,7 +3499,7 @@ var import_promises = __toESM(require("fs/promises"), 1);
|
|
|
3499
3499
|
var package_default = {
|
|
3500
3500
|
name: "easyeda",
|
|
3501
3501
|
type: "module",
|
|
3502
|
-
version: "0.0.
|
|
3502
|
+
version: "0.0.274",
|
|
3503
3503
|
files: [
|
|
3504
3504
|
"dist"
|
|
3505
3505
|
],
|
|
@@ -3519,7 +3519,7 @@ var package_default = {
|
|
|
3519
3519
|
"@types/bun": "latest",
|
|
3520
3520
|
"bun-match-svg": "^0.0.13",
|
|
3521
3521
|
"circuit-json-to-gltf": "^0.0.106",
|
|
3522
|
-
"circuit-to-svg": "^0.0.
|
|
3522
|
+
"circuit-to-svg": "^0.0.392",
|
|
3523
3523
|
"looks-same": "^9.0.1",
|
|
3524
3524
|
poppygl: "^0.0.24",
|
|
3525
3525
|
"transformation-matrix": "^2.16.1",
|
|
@@ -10376,10 +10376,11 @@ var RectangleShapeOutputSchema = import_zod180.z.object({
|
|
|
10376
10376
|
height: import_zod180.z.number(),
|
|
10377
10377
|
color: import_zod180.z.string(),
|
|
10378
10378
|
lineWidth: import_zod180.z.number(),
|
|
10379
|
+
fillColor: import_zod180.z.string().optional(),
|
|
10379
10380
|
id: import_zod180.z.string()
|
|
10380
10381
|
});
|
|
10381
10382
|
var parseRectangle = (str) => {
|
|
10382
|
-
const [, x, y, , , width, height, color, lineWidth, , , id] = str.split("~");
|
|
10383
|
+
const [, x, y, , , width, height, color, lineWidth, , fillColor, id] = str.split("~");
|
|
10383
10384
|
return {
|
|
10384
10385
|
type: "RECTANGLE",
|
|
10385
10386
|
position: { x: Number(x), y: Number(y) },
|
|
@@ -10387,6 +10388,7 @@ var parseRectangle = (str) => {
|
|
|
10387
10388
|
height: Number(height),
|
|
10388
10389
|
color,
|
|
10389
10390
|
lineWidth: Number(lineWidth),
|
|
10391
|
+
fillColor,
|
|
10390
10392
|
id
|
|
10391
10393
|
};
|
|
10392
10394
|
};
|
|
@@ -10398,10 +10400,11 @@ var EllipseShapeOutputSchema = import_zod180.z.object({
|
|
|
10398
10400
|
radiusY: import_zod180.z.number(),
|
|
10399
10401
|
color: import_zod180.z.string(),
|
|
10400
10402
|
lineWidth: import_zod180.z.number(),
|
|
10403
|
+
fillColor: import_zod180.z.string().optional(),
|
|
10401
10404
|
id: import_zod180.z.string()
|
|
10402
10405
|
});
|
|
10403
10406
|
var parseEllipse = (str) => {
|
|
10404
|
-
const [, x, y, radiusX, radiusY, color, lineWidth, , , id] = str.split("~");
|
|
10407
|
+
const [, x, y, radiusX, radiusY, color, lineWidth, , fillColor, id] = str.split("~");
|
|
10405
10408
|
return {
|
|
10406
10409
|
type: "ELLIPSE",
|
|
10407
10410
|
center: { x: Number(x), y: Number(y) },
|
|
@@ -10409,12 +10412,14 @@ var parseEllipse = (str) => {
|
|
|
10409
10412
|
radiusY: Number(radiusY),
|
|
10410
10413
|
color,
|
|
10411
10414
|
lineWidth: Number(lineWidth),
|
|
10415
|
+
fillColor,
|
|
10412
10416
|
id
|
|
10413
10417
|
};
|
|
10414
10418
|
};
|
|
10415
10419
|
var EllipseShapeSchema = import_zod180.z.string().startsWith("E~").transform(parseEllipse).pipe(EllipseShapeOutputSchema);
|
|
10416
10420
|
var ArcShapeOutputSchema = import_zod180.z.object({
|
|
10417
10421
|
type: import_zod180.z.literal("ARC"),
|
|
10422
|
+
pathData: import_zod180.z.string(),
|
|
10418
10423
|
start: PointSchema2,
|
|
10419
10424
|
end: PointSchema2,
|
|
10420
10425
|
radius: import_zod180.z.number(),
|
|
@@ -10424,26 +10429,25 @@ var ArcShapeOutputSchema = import_zod180.z.object({
|
|
|
10424
10429
|
id: import_zod180.z.string()
|
|
10425
10430
|
});
|
|
10426
10431
|
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;
|
|
10432
|
+
const [, pathData, ...fields] = str.split("~");
|
|
10433
|
+
const colorIndex = fields.findIndex((field) => /^#[0-9a-f]{6}$/i.test(field));
|
|
10434
|
+
const color = fields[colorIndex] || "#880000";
|
|
10435
|
+
const lineWidth = fields[colorIndex + 1];
|
|
10436
|
+
const id = fields.find((field) => /^(?:gge|rep)/.test(field)) || "gge1";
|
|
10437
|
+
const numbers = pathData.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
|
|
10438
|
+
const [x1 = 0, y1 = 0, radius = 0, , , , sweepFlag = 0, x2 = 0, y2 = 0] = numbers;
|
|
10435
10439
|
const parsedLineWidth = Number(lineWidth);
|
|
10436
10440
|
const finalLineWidth = Number.isNaN(parsedLineWidth) ? 1 : parsedLineWidth;
|
|
10437
10441
|
return {
|
|
10438
10442
|
type: "ARC",
|
|
10443
|
+
pathData,
|
|
10439
10444
|
start: { x: x1, y: y1 },
|
|
10440
10445
|
end: { x: x2, y: y2 },
|
|
10441
10446
|
radius,
|
|
10442
|
-
sweepFlag,
|
|
10443
|
-
color
|
|
10444
|
-
// Default color
|
|
10447
|
+
sweepFlag: sweepFlag === 1,
|
|
10448
|
+
color,
|
|
10445
10449
|
lineWidth: finalLineWidth,
|
|
10446
|
-
id
|
|
10450
|
+
id
|
|
10447
10451
|
};
|
|
10448
10452
|
};
|
|
10449
10453
|
var ArcShapeSchema = import_zod180.z.string().startsWith("A~").transform(parseArc).pipe(ArcShapeOutputSchema);
|
|
@@ -10471,8 +10475,7 @@ var parsePin = (pinString) => {
|
|
|
10471
10475
|
if (/^\+\d+(?:\.\d+)?V$/i.test(label)) label = `V${label.slice(1, -1)}`;
|
|
10472
10476
|
const colorMatch = pinString.match(/#[0-9A-F]{6}/);
|
|
10473
10477
|
const labelColor = colorMatch ? colorMatch[0] : "";
|
|
10474
|
-
const
|
|
10475
|
-
const path = pathMatch ? pathMatch[1] : "";
|
|
10478
|
+
const path = pinString.split("^^")[2]?.split("~")[0] ?? "";
|
|
10476
10479
|
const arrowMatch = pinString.match(/\^\^0~(.+)$/);
|
|
10477
10480
|
const arrow = arrowMatch ? arrowMatch[1] : "";
|
|
10478
10481
|
const r = Number.parseFloat(rotation2);
|
|
@@ -10530,7 +10533,7 @@ var PolygonShapeOutputSchema = import_zod180.z.object({
|
|
|
10530
10533
|
});
|
|
10531
10534
|
var parsePolygon = (str) => {
|
|
10532
10535
|
const [, ...rest] = str.split("~");
|
|
10533
|
-
const [pointsStr,
|
|
10536
|
+
const [pointsStr, lineColor, lineWidth, , fillColor, id] = rest;
|
|
10534
10537
|
return {
|
|
10535
10538
|
type: "POLYGON",
|
|
10536
10539
|
points: parsePoints2(pointsStr),
|
|
@@ -10550,7 +10553,7 @@ var PathShapeOutputSchema = import_zod180.z.object({
|
|
|
10550
10553
|
id: import_zod180.z.string()
|
|
10551
10554
|
});
|
|
10552
10555
|
var parsePath = (str) => {
|
|
10553
|
-
const [, pathData,
|
|
10556
|
+
const [, pathData, strokeColor, strokeWidth, , fillColor, id] = str.split("~");
|
|
10554
10557
|
return {
|
|
10555
10558
|
type: "PATH",
|
|
10556
10559
|
pathData,
|
|
@@ -10600,8 +10603,8 @@ var parseText = (str) => {
|
|
|
10600
10603
|
fontWeight,
|
|
10601
10604
|
fontStyle,
|
|
10602
10605
|
fontDecoration,
|
|
10603
|
-
content,
|
|
10604
10606
|
textType,
|
|
10607
|
+
content,
|
|
10605
10608
|
visibility,
|
|
10606
10609
|
mirror,
|
|
10607
10610
|
id
|
|
@@ -11049,7 +11052,8 @@ var generateTypescriptComponent = ({
|
|
|
11049
11052
|
circuitJson,
|
|
11050
11053
|
supplierPartNumbers,
|
|
11051
11054
|
manufacturerPartNumber,
|
|
11052
|
-
componentType = "chip"
|
|
11055
|
+
componentType = "chip",
|
|
11056
|
+
symbolTsx
|
|
11053
11057
|
}) => {
|
|
11054
11058
|
const safePinLabels = pinLabels ?? {};
|
|
11055
11059
|
const polarizedPinMetadata = getPolarizedPinMetadata(safePinLabels);
|
|
@@ -11076,6 +11080,10 @@ ${polarizedPinLabelsString}
|
|
|
11076
11080
|
|
|
11077
11081
|
` : "";
|
|
11078
11082
|
const polarizedPinLabelsProp = polarizedPinLabels ? ` pinLabels={pinLabels}
|
|
11083
|
+
` : "";
|
|
11084
|
+
const symbolProp = symbolTsx ? ` symbol={
|
|
11085
|
+
${symbolTsx.split("\n").map((line) => ` ${line}`).join("\n")}
|
|
11086
|
+
}
|
|
11079
11087
|
` : "";
|
|
11080
11088
|
const cadModelLines = [
|
|
11081
11089
|
objUrl ? `objUrl: "${objUrl}",` : "",
|
|
@@ -11093,7 +11101,7 @@ ${polarizedPinLabelsBlock}export const ${componentName} = (props: DiodeProps) =>
|
|
|
11093
11101
|
return (
|
|
11094
11102
|
<diode
|
|
11095
11103
|
name={name}
|
|
11096
|
-
${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11104
|
+
${polarizedPinLabelsProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11097
11105
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11098
11106
|
footprint={${footprintTsx}}
|
|
11099
11107
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11115,7 +11123,7 @@ ${polarizedPinLabelsBlock}export const ${componentName} = (props: LedProps) => {
|
|
|
11115
11123
|
return (
|
|
11116
11124
|
<led
|
|
11117
11125
|
name={name}
|
|
11118
|
-
${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11126
|
+
${polarizedPinLabelsProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11119
11127
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11120
11128
|
footprint={${footprintTsx}}
|
|
11121
11129
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11142,7 +11150,7 @@ export const ${componentName} = (props: PushButtonProps<typeof pinLabels>) => {
|
|
|
11142
11150
|
<pushbutton
|
|
11143
11151
|
name={name}
|
|
11144
11152
|
pinLabels={pinLabels}
|
|
11145
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11153
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11146
11154
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11147
11155
|
footprint={${footprintTsx}}
|
|
11148
11156
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11169,7 +11177,7 @@ export const ${componentName} = (props: SwitchProps) => {
|
|
|
11169
11177
|
<switch
|
|
11170
11178
|
name={name}
|
|
11171
11179
|
pinLabels={pinLabels}
|
|
11172
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11180
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11173
11181
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11174
11182
|
footprint={${footprintTsx}}
|
|
11175
11183
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11192,7 +11200,7 @@ export const ${componentName} = (props: ChipProps<typeof pinLabels>) => {
|
|
|
11192
11200
|
return (
|
|
11193
11201
|
<chip
|
|
11194
11202
|
pinLabels={pinLabels}
|
|
11195
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11203
|
+
${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11196
11204
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11197
11205
|
footprint={${footprintTsx}}
|
|
11198
11206
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11321,6 +11329,307 @@ var isSwitchCategoryComponent = (betterEasy) => {
|
|
|
11321
11329
|
].some(categoryValueContainsSwitch);
|
|
11322
11330
|
};
|
|
11323
11331
|
|
|
11332
|
+
// lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
|
|
11333
|
+
var round = (value) => Number(value.toFixed(6));
|
|
11334
|
+
var toMillimeters = (value) => round(mil10ToMm(value));
|
|
11335
|
+
var getPointTransformer = (origin) => (point2) => ({
|
|
11336
|
+
x: toMillimeters(point2.x - origin.x),
|
|
11337
|
+
y: toMillimeters(origin.y - point2.y)
|
|
11338
|
+
});
|
|
11339
|
+
var formatNumber = (value) => String(round(value));
|
|
11340
|
+
var SVG_PATH_COMMAND_PARAMETER_COUNTS = {
|
|
11341
|
+
A: 7,
|
|
11342
|
+
C: 6,
|
|
11343
|
+
H: 1,
|
|
11344
|
+
L: 2,
|
|
11345
|
+
M: 2,
|
|
11346
|
+
Q: 4,
|
|
11347
|
+
S: 4,
|
|
11348
|
+
T: 2,
|
|
11349
|
+
V: 1,
|
|
11350
|
+
Z: 0
|
|
11351
|
+
};
|
|
11352
|
+
var transformSvgPath = (pathData, origin) => {
|
|
11353
|
+
const tokens = pathData.match(
|
|
11354
|
+
/[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g
|
|
11355
|
+
) ?? [];
|
|
11356
|
+
const output = [];
|
|
11357
|
+
let command = "";
|
|
11358
|
+
let tokenIndex = 0;
|
|
11359
|
+
let currentX = 0;
|
|
11360
|
+
let currentY = 0;
|
|
11361
|
+
let subpathStartX = 0;
|
|
11362
|
+
let subpathStartY = 0;
|
|
11363
|
+
const transformPoint = getPointTransformer(origin);
|
|
11364
|
+
const getOriginalPoint = (x, y, isRelative) => ({
|
|
11365
|
+
x: isRelative ? currentX + x : x,
|
|
11366
|
+
y: isRelative ? currentY + y : y
|
|
11367
|
+
});
|
|
11368
|
+
while (tokenIndex < tokens.length) {
|
|
11369
|
+
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) {
|
|
11370
|
+
command = tokens[tokenIndex];
|
|
11371
|
+
tokenIndex += 1;
|
|
11372
|
+
}
|
|
11373
|
+
if (!command) break;
|
|
11374
|
+
const upperCommand = command.toUpperCase();
|
|
11375
|
+
const parameterCount = SVG_PATH_COMMAND_PARAMETER_COUNTS[upperCommand];
|
|
11376
|
+
if (parameterCount === void 0) break;
|
|
11377
|
+
if (upperCommand === "Z") {
|
|
11378
|
+
output.push("Z");
|
|
11379
|
+
currentX = subpathStartX;
|
|
11380
|
+
currentY = subpathStartY;
|
|
11381
|
+
command = "";
|
|
11382
|
+
continue;
|
|
11383
|
+
}
|
|
11384
|
+
if (tokenIndex + parameterCount > tokens.length) break;
|
|
11385
|
+
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) continue;
|
|
11386
|
+
const values = tokens.slice(tokenIndex, tokenIndex + parameterCount).map(Number);
|
|
11387
|
+
tokenIndex += parameterCount;
|
|
11388
|
+
const isRelative = command === command.toLowerCase();
|
|
11389
|
+
if (upperCommand === "H" || upperCommand === "V") {
|
|
11390
|
+
const point2 = getOriginalPoint(
|
|
11391
|
+
upperCommand === "H" ? values[0] : isRelative ? 0 : currentX,
|
|
11392
|
+
upperCommand === "V" ? values[0] : isRelative ? 0 : currentY,
|
|
11393
|
+
isRelative
|
|
11394
|
+
);
|
|
11395
|
+
const transformed = transformPoint(point2);
|
|
11396
|
+
output.push(
|
|
11397
|
+
`L ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
11398
|
+
);
|
|
11399
|
+
currentX = point2.x;
|
|
11400
|
+
currentY = point2.y;
|
|
11401
|
+
continue;
|
|
11402
|
+
}
|
|
11403
|
+
if (["M", "L", "T"].includes(upperCommand)) {
|
|
11404
|
+
const point2 = getOriginalPoint(values[0], values[1], isRelative);
|
|
11405
|
+
const transformed = transformPoint(point2);
|
|
11406
|
+
output.push(
|
|
11407
|
+
`${upperCommand} ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
11408
|
+
);
|
|
11409
|
+
currentX = point2.x;
|
|
11410
|
+
currentY = point2.y;
|
|
11411
|
+
if (upperCommand === "M") {
|
|
11412
|
+
subpathStartX = point2.x;
|
|
11413
|
+
subpathStartY = point2.y;
|
|
11414
|
+
command = isRelative ? "l" : "L";
|
|
11415
|
+
}
|
|
11416
|
+
continue;
|
|
11417
|
+
}
|
|
11418
|
+
if (["C", "S", "Q"].includes(upperCommand)) {
|
|
11419
|
+
const transformedValues = [];
|
|
11420
|
+
for (let valueIndex = 0; valueIndex < values.length; valueIndex += 2) {
|
|
11421
|
+
const point2 = getOriginalPoint(
|
|
11422
|
+
values[valueIndex],
|
|
11423
|
+
values[valueIndex + 1],
|
|
11424
|
+
isRelative
|
|
11425
|
+
);
|
|
11426
|
+
const transformed = transformPoint(point2);
|
|
11427
|
+
transformedValues.push(transformed.x, transformed.y);
|
|
11428
|
+
}
|
|
11429
|
+
output.push(
|
|
11430
|
+
`${upperCommand} ${transformedValues.map(formatNumber).join(" ")}`
|
|
11431
|
+
);
|
|
11432
|
+
currentX = isRelative ? currentX + values[values.length - 2] : values[values.length - 2];
|
|
11433
|
+
currentY = isRelative ? currentY + values[values.length - 1] : values[values.length - 1];
|
|
11434
|
+
continue;
|
|
11435
|
+
}
|
|
11436
|
+
if (upperCommand === "A") {
|
|
11437
|
+
const endpoint = getOriginalPoint(values[5], values[6], isRelative);
|
|
11438
|
+
const transformedEndpoint = transformPoint(endpoint);
|
|
11439
|
+
output.push(
|
|
11440
|
+
[
|
|
11441
|
+
"A",
|
|
11442
|
+
formatNumber(toMillimeters(Math.abs(values[0]))),
|
|
11443
|
+
formatNumber(toMillimeters(Math.abs(values[1]))),
|
|
11444
|
+
formatNumber(-values[2]),
|
|
11445
|
+
String(values[3]),
|
|
11446
|
+
String(values[4] === 0 ? 1 : 0),
|
|
11447
|
+
formatNumber(transformedEndpoint.x),
|
|
11448
|
+
formatNumber(transformedEndpoint.y)
|
|
11449
|
+
].join(" ")
|
|
11450
|
+
);
|
|
11451
|
+
currentX = endpoint.x;
|
|
11452
|
+
currentY = endpoint.y;
|
|
11453
|
+
}
|
|
11454
|
+
}
|
|
11455
|
+
return output.join(" ");
|
|
11456
|
+
};
|
|
11457
|
+
var getPinDirection = (rotation2) => {
|
|
11458
|
+
const normalizedRotation = (rotation2 % 360 + 360) % 360;
|
|
11459
|
+
if (normalizedRotation === 90) return "up";
|
|
11460
|
+
if (normalizedRotation === 180) return "left";
|
|
11461
|
+
if (normalizedRotation === 270) return "down";
|
|
11462
|
+
return "right";
|
|
11463
|
+
};
|
|
11464
|
+
var getPinStemLength = (path) => {
|
|
11465
|
+
const segment = path.match(/[hHvV]\s*(-?(?:\d*\.\d+|\d+\.?))/);
|
|
11466
|
+
if (!segment) return void 0;
|
|
11467
|
+
return toMillimeters(Math.abs(Number(segment[1])));
|
|
11468
|
+
};
|
|
11469
|
+
var getTextFontSizeMm = (fontSize) => {
|
|
11470
|
+
const numericFontSize = Number.parseFloat(fontSize);
|
|
11471
|
+
if (!Number.isFinite(numericFontSize)) return 1;
|
|
11472
|
+
if (fontSize.toLowerCase().endsWith("pt")) {
|
|
11473
|
+
return round(numericFontSize * 25.4 / 72);
|
|
11474
|
+
}
|
|
11475
|
+
return toMillimeters(numericFontSize);
|
|
11476
|
+
};
|
|
11477
|
+
var getTextAnchor = (alignment) => {
|
|
11478
|
+
if (alignment === "L") return "left";
|
|
11479
|
+
if (alignment === "R") return "right";
|
|
11480
|
+
return "center";
|
|
11481
|
+
};
|
|
11482
|
+
var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
|
|
11483
|
+
const pins = easyEdaJson.dataStr.shape.filter(
|
|
11484
|
+
(shape) => shape.type === "PIN"
|
|
11485
|
+
);
|
|
11486
|
+
const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
|
|
11487
|
+
(shape) => shape.type === "PAD"
|
|
11488
|
+
);
|
|
11489
|
+
const sourcePorts = circuitJson.filter(
|
|
11490
|
+
(element) => element.type === "source_port"
|
|
11491
|
+
);
|
|
11492
|
+
const sourcePortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
11493
|
+
pads.forEach((pad, padIndex) => {
|
|
11494
|
+
const sourcePort = sourcePorts.find(
|
|
11495
|
+
(port) => port.source_port_id === `source_port_${padIndex + 1}`
|
|
11496
|
+
);
|
|
11497
|
+
if (!sourcePort) return;
|
|
11498
|
+
const padNumber = String(pad.number);
|
|
11499
|
+
sourcePortNamesByPadNumber.set(padNumber, [
|
|
11500
|
+
...sourcePortNamesByPadNumber.get(padNumber) ?? [],
|
|
11501
|
+
sourcePort.name
|
|
11502
|
+
]);
|
|
11503
|
+
});
|
|
11504
|
+
const usedPortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
11505
|
+
const usedPortNames = /* @__PURE__ */ new Set();
|
|
11506
|
+
const metadataByShapeId = /* @__PURE__ */ new Map();
|
|
11507
|
+
pins.forEach((pin, pinIndex) => {
|
|
11508
|
+
const pinNumberKey = String(pin.pinNumber);
|
|
11509
|
+
const matchingPortNames = sourcePortNamesByPadNumber.get(pinNumberKey) ?? [];
|
|
11510
|
+
const matchingPortIndex = usedPortNamesByPadNumber.get(pinNumberKey) ?? 0;
|
|
11511
|
+
let portName = matchingPortNames[matchingPortIndex];
|
|
11512
|
+
usedPortNamesByPadNumber.set(pinNumberKey, matchingPortIndex + 1);
|
|
11513
|
+
if (!portName && pin.label) {
|
|
11514
|
+
const normalizedLabel = normalizeSymbolName(pin.label);
|
|
11515
|
+
portName = sourcePorts.find(
|
|
11516
|
+
(port) => !usedPortNames.has(port.name) && port.port_hints?.includes(normalizedLabel)
|
|
11517
|
+
)?.name;
|
|
11518
|
+
}
|
|
11519
|
+
const numericPinNumber = Number(pin.pinNumber);
|
|
11520
|
+
if (!portName && Number.isInteger(numericPinNumber)) {
|
|
11521
|
+
const numericPortName = `pin${numericPinNumber}`;
|
|
11522
|
+
if (sourcePorts.some((port) => port.name === numericPortName)) {
|
|
11523
|
+
portName = numericPortName;
|
|
11524
|
+
}
|
|
11525
|
+
}
|
|
11526
|
+
portName ??= sourcePorts[pinIndex]?.name ?? `pin${pinIndex + 1}`;
|
|
11527
|
+
usedPortNames.add(portName);
|
|
11528
|
+
const sourcePort = sourcePorts.find((port) => port.name === portName);
|
|
11529
|
+
metadataByShapeId.set(pin.id, {
|
|
11530
|
+
name: portName,
|
|
11531
|
+
pinNumber: sourcePort?.pin_number,
|
|
11532
|
+
aliases: [
|
|
11533
|
+
...sourcePort?.port_hints ?? [],
|
|
11534
|
+
...pin.label ? [normalizeSymbolName(pin.label)] : []
|
|
11535
|
+
].filter(
|
|
11536
|
+
(alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
|
|
11537
|
+
)
|
|
11538
|
+
});
|
|
11539
|
+
});
|
|
11540
|
+
return metadataByShapeId;
|
|
11541
|
+
};
|
|
11542
|
+
var generateShapeTsx = ({
|
|
11543
|
+
shape,
|
|
11544
|
+
origin,
|
|
11545
|
+
portMetadata
|
|
11546
|
+
}) => {
|
|
11547
|
+
const transformPoint = getPointTransformer(origin);
|
|
11548
|
+
if (shape.type === "RECTANGLE") {
|
|
11549
|
+
const center = transformPoint({
|
|
11550
|
+
x: shape.position.x + shape.width / 2,
|
|
11551
|
+
y: shape.position.y + shape.height / 2
|
|
11552
|
+
});
|
|
11553
|
+
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)}` : ""} />`;
|
|
11554
|
+
}
|
|
11555
|
+
if (shape.type === "ELLIPSE") {
|
|
11556
|
+
const center = transformPoint(shape.center);
|
|
11557
|
+
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)}` : ""} />`;
|
|
11558
|
+
}
|
|
11559
|
+
if (shape.type === "POLYLINE" || shape.type === "POLYGON") {
|
|
11560
|
+
const isPolygon = shape.type === "POLYGON";
|
|
11561
|
+
const points = shape.points.map(transformPoint);
|
|
11562
|
+
if (isPolygon && points.length > 0) points.push(points[0]);
|
|
11563
|
+
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)}` : ""} />`;
|
|
11564
|
+
}
|
|
11565
|
+
if (shape.type === "PATH") {
|
|
11566
|
+
const transformedPath = transformSvgPath(shape.pathData, origin);
|
|
11567
|
+
if (!transformedPath) return void 0;
|
|
11568
|
+
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeWidth={${shape.strokeWidth}} strokeColor=${JSON.stringify(shape.strokeColor)}${shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
11569
|
+
}
|
|
11570
|
+
if (shape.type === "ARC") {
|
|
11571
|
+
const transformedPath = transformSvgPath(shape.pathData, origin);
|
|
11572
|
+
if (!transformedPath) return void 0;
|
|
11573
|
+
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeWidth={${toMillimeters(shape.lineWidth)}} strokeColor=${JSON.stringify(shape.color)} />`;
|
|
11574
|
+
}
|
|
11575
|
+
if (shape.type === "TEXT") {
|
|
11576
|
+
if (shape.visibility !== "1") return void 0;
|
|
11577
|
+
const position2 = transformPoint({ x: shape.x, y: shape.y });
|
|
11578
|
+
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)}} />`;
|
|
11579
|
+
}
|
|
11580
|
+
if (shape.type === "PIN" && portMetadata) {
|
|
11581
|
+
const position2 = transformPoint({ x: shape.x, y: shape.y });
|
|
11582
|
+
const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
|
|
11583
|
+
const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
|
|
11584
|
+
const stemLength = getPinStemLength(shape.path);
|
|
11585
|
+
const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
|
|
11586
|
+
return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(getPinDirection(shape.rotation))} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
|
|
11587
|
+
}
|
|
11588
|
+
return void 0;
|
|
11589
|
+
};
|
|
11590
|
+
var generateSymbolTsx = (easyEdaJson, circuitJson) => {
|
|
11591
|
+
const shapes = easyEdaJson.dataStr.shape;
|
|
11592
|
+
if (shapes.length === 0) return void 0;
|
|
11593
|
+
const headOrigin = {
|
|
11594
|
+
x: easyEdaJson.dataStr.head.x,
|
|
11595
|
+
y: easyEdaJson.dataStr.head.y
|
|
11596
|
+
};
|
|
11597
|
+
const bounds = easyEdaJson.dataStr.BBox;
|
|
11598
|
+
const isHeadOriginInsideBounds = headOrigin.x >= bounds.x && headOrigin.x <= bounds.x + bounds.width && headOrigin.y >= bounds.y && headOrigin.y <= bounds.y + bounds.height;
|
|
11599
|
+
const origin = isHeadOriginInsideBounds ? headOrigin : {
|
|
11600
|
+
x: bounds.x + bounds.width / 2,
|
|
11601
|
+
y: bounds.y + bounds.height / 2
|
|
11602
|
+
};
|
|
11603
|
+
const portMetadataByShapeId = getPortMetadataByShapeId(
|
|
11604
|
+
easyEdaJson,
|
|
11605
|
+
circuitJson
|
|
11606
|
+
);
|
|
11607
|
+
const shapeTsx = shapes.map(
|
|
11608
|
+
(shape) => generateShapeTsx({
|
|
11609
|
+
shape,
|
|
11610
|
+
origin,
|
|
11611
|
+
portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0
|
|
11612
|
+
})
|
|
11613
|
+
).filter((tsx) => Boolean(tsx));
|
|
11614
|
+
if (shapeTsx.length === 0) return void 0;
|
|
11615
|
+
return `<symbol>
|
|
11616
|
+
${shapeTsx.map((tsx) => ` ${tsx}`).join("\n")}
|
|
11617
|
+
</symbol>`;
|
|
11618
|
+
};
|
|
11619
|
+
var hasNonBoxSchematicSymbol = (easyEdaJson) => {
|
|
11620
|
+
const drawableShapes = easyEdaJson.dataStr.shape.filter(
|
|
11621
|
+
(shape) => shape.type !== "PIN" && shape.type !== "TEXT"
|
|
11622
|
+
);
|
|
11623
|
+
if (drawableShapes.length === 0) return false;
|
|
11624
|
+
const rectangles = drawableShapes.filter(
|
|
11625
|
+
(shape) => shape.type === "RECTANGLE"
|
|
11626
|
+
);
|
|
11627
|
+
const onlyBoxPrimitives = drawableShapes.every(
|
|
11628
|
+
(shape) => shape.type === "RECTANGLE" || shape.type === "ELLIPSE" && shape.radiusX <= 2 && shape.radiusY <= 2
|
|
11629
|
+
);
|
|
11630
|
+
return rectangles.length !== 1 || !onlyBoxPrimitives;
|
|
11631
|
+
};
|
|
11632
|
+
|
|
11324
11633
|
// lib/websafe/convert-to-typescript-component/index.tsx
|
|
11325
11634
|
var getGeneratedComponentType = (betterEasy) => {
|
|
11326
11635
|
if (isLedCategoryComponent(betterEasy)) return "led";
|
|
@@ -11386,6 +11695,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
11386
11695
|
const supplierPartNumbers = {
|
|
11387
11696
|
jlcpcb: [betterEasy.lcsc.number]
|
|
11388
11697
|
};
|
|
11698
|
+
const componentType = getGeneratedComponentType(betterEasy);
|
|
11699
|
+
const symbolTsx = componentType === "chip" && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson) : void 0;
|
|
11389
11700
|
return generateTypescriptComponent({
|
|
11390
11701
|
componentName: pn,
|
|
11391
11702
|
manufacturerPartNumber: pn,
|
|
@@ -11394,7 +11705,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
11394
11705
|
stepUrl: modelStepUrl,
|
|
11395
11706
|
circuitJson,
|
|
11396
11707
|
supplierPartNumbers,
|
|
11397
|
-
componentType
|
|
11708
|
+
componentType,
|
|
11709
|
+
symbolTsx
|
|
11398
11710
|
});
|
|
11399
11711
|
};
|
|
11400
11712
|
var checkModelObjUrlValidity = async (url) => {
|