easyeda 0.0.357 → 0.0.359

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/index.d.ts CHANGED
@@ -758,7 +758,7 @@ declare const DataStrSchema: z.ZodEffects<z.ZodObject<{
758
758
  c_spiceCmd?: any;
759
759
  };
760
760
  canvas: string;
761
- colors: Record<string, string> | string[];
761
+ colors: string[] | Record<string, string>;
762
762
  BBox?: {
763
763
  x: number;
764
764
  y: number;
@@ -787,7 +787,7 @@ declare const DataStrSchema: z.ZodEffects<z.ZodObject<{
787
787
  width: number;
788
788
  height: number;
789
789
  } | undefined;
790
- colors?: Record<string, string> | string[] | undefined;
790
+ colors?: string[] | Record<string, string> | undefined;
791
791
  }>, {
792
792
  BBox: {
793
793
  x: number;
@@ -908,7 +908,7 @@ declare const DataStrSchema: z.ZodEffects<z.ZodObject<{
908
908
  c_spiceCmd?: any;
909
909
  };
910
910
  canvas: string;
911
- colors: Record<string, string> | string[];
911
+ colors: string[] | Record<string, string>;
912
912
  }, {
913
913
  shape: string[];
914
914
  head: {
@@ -931,7 +931,7 @@ declare const DataStrSchema: z.ZodEffects<z.ZodObject<{
931
931
  width: number;
932
932
  height: number;
933
933
  } | undefined;
934
- colors?: Record<string, string> | string[] | undefined;
934
+ colors?: string[] | Record<string, string> | undefined;
935
935
  }>;
936
936
  declare const PackageDetailDataStrSchema: z.ZodObject<{
937
937
  head: z.ZodObject<{
@@ -3477,7 +3477,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
3477
3477
  c_spiceCmd?: any;
3478
3478
  };
3479
3479
  canvas: string;
3480
- colors: Record<string, string> | string[];
3480
+ colors: string[] | Record<string, string>;
3481
3481
  BBox?: {
3482
3482
  x: number;
3483
3483
  y: number;
@@ -3506,7 +3506,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
3506
3506
  width: number;
3507
3507
  height: number;
3508
3508
  } | undefined;
3509
- colors?: Record<string, string> | string[] | undefined;
3509
+ colors?: string[] | Record<string, string> | undefined;
3510
3510
  }>, {
3511
3511
  BBox: {
3512
3512
  x: number;
@@ -3627,7 +3627,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
3627
3627
  c_spiceCmd?: any;
3628
3628
  };
3629
3629
  canvas: string;
3630
- colors: Record<string, string> | string[];
3630
+ colors: string[] | Record<string, string>;
3631
3631
  }, {
3632
3632
  shape: string[];
3633
3633
  head: {
@@ -3650,7 +3650,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
3650
3650
  width: number;
3651
3651
  height: number;
3652
3652
  } | undefined;
3653
- colors?: Record<string, string> | string[] | undefined;
3653
+ colors?: string[] | Record<string, string> | undefined;
3654
3654
  }>;
3655
3655
  verify: z.ZodBoolean;
3656
3656
  SMT: z.ZodOptional<z.ZodBoolean>;
@@ -4895,7 +4895,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
4895
4895
  c_spiceCmd?: any;
4896
4896
  };
4897
4897
  canvas: string;
4898
- colors: Record<string, string> | string[];
4898
+ colors: string[] | Record<string, string>;
4899
4899
  };
4900
4900
  description: string;
4901
4901
  szlcsc: {
@@ -5146,7 +5146,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
5146
5146
  width: number;
5147
5147
  height: number;
5148
5148
  } | undefined;
5149
- colors?: Record<string, string> | string[] | undefined;
5149
+ colors?: string[] | Record<string, string> | undefined;
5150
5150
  };
5151
5151
  description: string;
5152
5152
  szlcsc: {
package/dist/index.js CHANGED
@@ -4,6 +4,112 @@ var __export = (target, all) => {
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
5
5
  };
6
6
 
7
+ // lib/utils/normalize-pin-labels.ts
8
+ var normalizeActiveLowPinLabel = (label) => {
9
+ const hasActiveLowMarker = label.startsWith("#") || label.endsWith("#");
10
+ if (!hasActiveLowMarker) return label;
11
+ const activeLowLabel = label.replace(/^#/, "").replace(/#$/, "");
12
+ if (activeLowLabel.length === 0) return label;
13
+ if (activeLowLabel.startsWith("N_")) return activeLowLabel;
14
+ return `N_${activeLowLabel}`;
15
+ };
16
+ var normalizePinLabels = (inputPinLabels) => {
17
+ const normalizedInputPinLabels = inputPinLabels.map(
18
+ (labels) => labels.map(normalizeActiveLowPinLabel)
19
+ );
20
+ const uniqueInputPinLabels = normalizedInputPinLabels.map((labels) => [
21
+ ...new Set(labels)
22
+ ]);
23
+ const result = uniqueInputPinLabels.map(() => []);
24
+ const desiredNumbers = uniqueInputPinLabels.map(() => null);
25
+ for (let i = 0; i < uniqueInputPinLabels.length; i++) {
26
+ for (const label of uniqueInputPinLabels[i]) {
27
+ if (/^\d+$/.test(label)) {
28
+ desiredNumbers[i] = Number.parseInt(label);
29
+ break;
30
+ }
31
+ }
32
+ }
33
+ let highestPinNumber = 0;
34
+ const acceptedDesiredNumbers = /* @__PURE__ */ new Set();
35
+ for (let i = 0; i < desiredNumbers.length; i++) {
36
+ const desiredNumber = desiredNumbers[i];
37
+ if (desiredNumber === null || desiredNumber < 1) continue;
38
+ if (!acceptedDesiredNumbers.has(desiredNumber)) {
39
+ acceptedDesiredNumbers.add(desiredNumber);
40
+ result[i].push(`pin${desiredNumber}`);
41
+ highestPinNumber = Math.max(highestPinNumber, desiredNumber);
42
+ continue;
43
+ }
44
+ let existingAltCount = 0;
45
+ for (const label of result[i]) {
46
+ if (label.startsWith(`pin${desiredNumber}_alt`)) {
47
+ existingAltCount += 1;
48
+ }
49
+ }
50
+ result[i].push(`pin${desiredNumber}_alt${existingAltCount + 1}`);
51
+ }
52
+ for (let i = 0; i < result.length; i++) {
53
+ const firstLabel = result[i][0];
54
+ if (firstLabel?.includes("_alt")) {
55
+ highestPinNumber += 1;
56
+ result[i].unshift(`pin${highestPinNumber}`);
57
+ }
58
+ }
59
+ for (let i = 0; i < result.length; i++) {
60
+ if (result[i].length === 0) {
61
+ highestPinNumber += 1;
62
+ result[i].push(`pin${highestPinNumber}`);
63
+ }
64
+ }
65
+ const totalLabelCounts = {};
66
+ for (const inputLabels of uniqueInputPinLabels) {
67
+ for (const label of inputLabels) {
68
+ if (/^\d+$/.test(label)) continue;
69
+ totalLabelCounts[label] = (totalLabelCounts[label] ?? 0) + 1;
70
+ }
71
+ }
72
+ const incrementalLabelCounts = {};
73
+ for (let i = 0; i < uniqueInputPinLabels.length; i++) {
74
+ for (const label of uniqueInputPinLabels[i]) {
75
+ if (/^\d+$/.test(label)) continue;
76
+ if (totalLabelCounts[label] === 1) {
77
+ result[i].push(label);
78
+ } else {
79
+ incrementalLabelCounts[label] = (incrementalLabelCounts[label] ?? 0) + 1;
80
+ result[i].push(`${label}${incrementalLabelCounts[label]}`);
81
+ }
82
+ }
83
+ }
84
+ return result;
85
+ };
86
+
87
+ // lib/utils/normalize-easyeda-pin-label.ts
88
+ var normalizeEasyEdaPinLabel = (label) => {
89
+ if (label.endsWith("+")) label = `${label.slice(0, -1)}_POS`;
90
+ if (/[-–−]$/.test(label)) label = `${label.slice(0, -1)}_NEG`;
91
+ label = normalizeActiveLowPinLabel(label);
92
+ if (/^\+\d+(?:\.\d+)?V$/i.test(label)) label = `V${label.slice(1, -1)}`;
93
+ if (label.startsWith("+")) label = `${label.slice(1)}_POS`;
94
+ if (/^[-–−]/.test(label)) label = `${label.slice(1)}_NEG`;
95
+ return label;
96
+ };
97
+
98
+ // lib/utils/get-easyeda-pin-aliases.ts
99
+ var getEasyEdaPinAliases = (label) => {
100
+ label = label.replace(/&#(x[0-9a-f]+|[0-9]+);/gi, (entity, code) => {
101
+ let codePoint = Number(code);
102
+ if (/^x/i.test(code)) codePoint = Number.parseInt(code.slice(1), 16);
103
+ const maximumUnicodeCodePoint = 1114111;
104
+ if (codePoint > maximumUnicodeCodePoint) return entity;
105
+ return String.fromCodePoint(codePoint);
106
+ });
107
+ if (label.includes("/") && !/[a-zA-Z0-9]/.test(label)) return [];
108
+ return label.split("/").map(
109
+ (alias) => normalizeEasyEdaPinLabel(alias.trim()).replace(/[`′]/g, "_PRIME").replace(/^[()]+|[()]+$/g, "").replace(/[^a-zA-Z0-9_]/g, "_")
110
+ ).filter((alias) => /[a-zA-Z0-9]/.test(alias));
111
+ };
112
+
7
113
  // node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
8
114
  function orientation(p, q, r) {
9
115
  const val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
@@ -6119,6 +6225,225 @@ var transformPCBElements = (elms, matrix) => {
6119
6225
  }
6120
6226
  return transformedElms;
6121
6227
  };
6228
+ var mergeBounds = (currentBounds, nextBounds) => ({
6229
+ minX: Math.min(currentBounds.minX, nextBounds.minX),
6230
+ minY: Math.min(currentBounds.minY, nextBounds.minY),
6231
+ maxX: Math.max(currentBounds.maxX, nextBounds.maxX),
6232
+ maxY: Math.max(currentBounds.maxY, nextBounds.maxY)
6233
+ });
6234
+ var getCircleBounds = (x, y, diameter) => {
6235
+ const radius = diameter / 2;
6236
+ return {
6237
+ minX: x - radius,
6238
+ minY: y - radius,
6239
+ maxX: x + radius,
6240
+ maxY: y + radius
6241
+ };
6242
+ };
6243
+ var getRotatedRectBounds = (x, y, width, height, rotationDegrees) => {
6244
+ const halfWidth = width / 2;
6245
+ const halfHeight = height / 2;
6246
+ const theta = rotationDegrees * Math.PI / 180;
6247
+ const cosTheta = Math.cos(theta);
6248
+ const sinTheta = Math.sin(theta);
6249
+ const corners = [
6250
+ { x: -halfWidth, y: -halfHeight },
6251
+ { x: halfWidth, y: -halfHeight },
6252
+ { x: halfWidth, y: halfHeight },
6253
+ { x: -halfWidth, y: halfHeight }
6254
+ ].map((corner) => ({
6255
+ x: x + corner.x * cosTheta - corner.y * sinTheta,
6256
+ y: y + corner.x * sinTheta + corner.y * cosTheta
6257
+ }));
6258
+ return {
6259
+ minX: Math.min(...corners.map((corner) => corner.x)),
6260
+ minY: Math.min(...corners.map((corner) => corner.y)),
6261
+ maxX: Math.max(...corners.map((corner) => corner.x)),
6262
+ maxY: Math.max(...corners.map((corner) => corner.y))
6263
+ };
6264
+ };
6265
+ var getRotatedOvalBounds = (x, y, width, height, rotationDegrees) => {
6266
+ const radiusX = width / 2;
6267
+ const radiusY = height / 2;
6268
+ const theta = rotationDegrees * Math.PI / 180;
6269
+ const cosTheta = Math.cos(theta);
6270
+ const sinTheta = Math.sin(theta);
6271
+ const halfWidth = Math.hypot(radiusX * cosTheta, radiusY * sinTheta);
6272
+ const halfHeight = Math.hypot(radiusX * sinTheta, radiusY * cosTheta);
6273
+ return {
6274
+ minX: x - halfWidth,
6275
+ minY: y - halfHeight,
6276
+ maxX: x + halfWidth,
6277
+ maxY: y + halfHeight
6278
+ };
6279
+ };
6280
+ var getRotatedPillBounds = (x, y, width, height, rotationDegrees) => {
6281
+ const radius = Math.min(width, height) / 2;
6282
+ const halfLineLength = Math.max(width, height) / 2 - radius;
6283
+ const theta = rotationDegrees * Math.PI / 180;
6284
+ const axis = width >= height ? { x: halfLineLength, y: 0 } : { x: 0, y: halfLineLength };
6285
+ const rotatedAxis = {
6286
+ x: axis.x * Math.cos(theta) - axis.y * Math.sin(theta),
6287
+ y: axis.x * Math.sin(theta) + axis.y * Math.cos(theta)
6288
+ };
6289
+ const halfWidth = Math.abs(rotatedAxis.x) + radius;
6290
+ const halfHeight = Math.abs(rotatedAxis.y) + radius;
6291
+ return {
6292
+ minX: x - halfWidth,
6293
+ minY: y - halfHeight,
6294
+ maxX: x + halfWidth,
6295
+ maxY: y + halfHeight
6296
+ };
6297
+ };
6298
+ var getBoundsFromPoints2 = (points) => {
6299
+ if (points.length === 0) return null;
6300
+ return {
6301
+ minX: Math.min(...points.map((point2) => point2.x)),
6302
+ minY: Math.min(...points.map((point2) => point2.y)),
6303
+ maxX: Math.max(...points.map((point2) => point2.x)),
6304
+ maxY: Math.max(...points.map((point2) => point2.y))
6305
+ };
6306
+ };
6307
+ var getRoutePoints = (route) => {
6308
+ if (!Array.isArray(route)) return [];
6309
+ return route.flatMap((point2) => {
6310
+ if (!point2 || typeof point2 !== "object") return [];
6311
+ if ("x" in point2 && "y" in point2 && typeof point2.x === "number" && typeof point2.y === "number") {
6312
+ return [{ x: point2.x, y: point2.y }];
6313
+ }
6314
+ if ("start" in point2 && "end" in point2) {
6315
+ const positions = [point2.start, point2.end];
6316
+ return positions.filter(
6317
+ (position2) => Boolean(
6318
+ position2 && typeof position2 === "object" && "x" in position2 && "y" in position2 && typeof position2.x === "number" && typeof position2.y === "number"
6319
+ )
6320
+ );
6321
+ }
6322
+ return [];
6323
+ });
6324
+ };
6325
+ var getPcbElementBounds = (elm) => {
6326
+ if (!elm.type.startsWith("pcb_")) return null;
6327
+ if (elm.type === "pcb_smtpad" && elm.shape === "polygon" && Array.isArray(elm.points)) {
6328
+ return getBoundsFromPoints2(elm.points);
6329
+ }
6330
+ if (elm.type === "pcb_hole" && elm.hole_shape === "circle") {
6331
+ return getCircleBounds(elm.x, elm.y, elm.hole_diameter);
6332
+ }
6333
+ if (elm.type === "pcb_plated_hole") {
6334
+ let platedHoleBounds;
6335
+ if ("outer_diameter" in elm && typeof elm.outer_diameter === "number") {
6336
+ platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.outer_diameter);
6337
+ } else if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
6338
+ platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.hole_diameter);
6339
+ }
6340
+ if ((elm.shape === "oval" || elm.shape === "pill") && typeof elm.outer_width === "number" && typeof elm.outer_height === "number") {
6341
+ const getOuterBounds = elm.shape === "pill" ? getRotatedPillBounds : getRotatedOvalBounds;
6342
+ platedHoleBounds = getOuterBounds(
6343
+ elm.x,
6344
+ elm.y,
6345
+ elm.outer_width,
6346
+ elm.outer_height,
6347
+ elm.ccw_rotation ?? 0
6348
+ );
6349
+ }
6350
+ if ("rect_pad_width" in elm && typeof elm.rect_pad_width === "number" && "rect_pad_height" in elm && typeof elm.rect_pad_height === "number") {
6351
+ const rectBounds = getRotatedRectBounds(
6352
+ elm.x,
6353
+ elm.y,
6354
+ elm.rect_pad_width,
6355
+ elm.rect_pad_height,
6356
+ "rect_ccw_rotation" in elm ? elm.rect_ccw_rotation ?? 0 : 0
6357
+ );
6358
+ platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, rectBounds) : rectBounds;
6359
+ }
6360
+ if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
6361
+ const drillBounds = getCircleBounds(
6362
+ elm.x + ("hole_offset_x" in elm ? elm.hole_offset_x ?? 0 : 0),
6363
+ elm.y + ("hole_offset_y" in elm ? elm.hole_offset_y ?? 0 : 0),
6364
+ elm.hole_diameter
6365
+ );
6366
+ platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, drillBounds) : drillBounds;
6367
+ }
6368
+ if (platedHoleBounds) return platedHoleBounds;
6369
+ }
6370
+ const elementRecord = elm;
6371
+ const routeBounds = getBoundsFromPoints2(getRoutePoints(elementRecord.route));
6372
+ if (routeBounds) return routeBounds;
6373
+ const outlineBounds = getBoundsFromPoints2(
6374
+ getRoutePoints(elementRecord.outline)
6375
+ );
6376
+ if (outlineBounds) return outlineBounds;
6377
+ const pointsBounds = getBoundsFromPoints2(getRoutePoints(elementRecord.points));
6378
+ if (pointsBounds) return pointsBounds;
6379
+ let centerX;
6380
+ let centerY;
6381
+ let width;
6382
+ let height;
6383
+ if ("x" in elm && "y" in elm) {
6384
+ centerX = Number(elm.x);
6385
+ centerY = Number(elm.y);
6386
+ }
6387
+ if ("outer_diameter" in elm) {
6388
+ width = Number(elm.outer_diameter);
6389
+ height = Number(elm.outer_diameter);
6390
+ }
6391
+ if ("width" in elm) {
6392
+ width = Number(elm.width);
6393
+ }
6394
+ if ("height" in elm) {
6395
+ height = Number(elm.height);
6396
+ }
6397
+ if ("center" in elm && elm.center && typeof elm.center === "object" && "x" in elm.center && "y" in elm.center) {
6398
+ centerX = Number(elm.center.x);
6399
+ centerY = Number(elm.center.y);
6400
+ }
6401
+ let rotation2 = 0;
6402
+ if ("rotation" in elm && typeof elm.rotation === "number") {
6403
+ rotation2 = elm.rotation;
6404
+ }
6405
+ if ("ccw_rotation" in elm && typeof elm.ccw_rotation === "number") {
6406
+ rotation2 = elm.ccw_rotation;
6407
+ }
6408
+ if (centerX !== void 0 && centerY !== void 0) {
6409
+ if (width !== void 0 && height !== void 0) {
6410
+ return rotation2 ? getRotatedRectBounds(centerX, centerY, width, height, rotation2) : {
6411
+ minX: centerX - width / 2,
6412
+ minY: centerY - height / 2,
6413
+ maxX: centerX + width / 2,
6414
+ maxY: centerY + height / 2
6415
+ };
6416
+ }
6417
+ if ("radius" in elm && typeof elm.radius === "number") {
6418
+ return getCircleBounds(centerX, centerY, elm.radius * 2);
6419
+ }
6420
+ return { minX: centerX, minY: centerY, maxX: centerX, maxY: centerY };
6421
+ }
6422
+ const anchoredPoint = [elementRecord.anchor_position, elementRecord.position].filter(
6423
+ (position2) => Boolean(
6424
+ position2 && typeof position2 === "object" && "x" in position2 && "y" in position2 && typeof position2.x === "number" && typeof position2.y === "number"
6425
+ )
6426
+ ).at(0);
6427
+ return anchoredPoint ? {
6428
+ minX: anchoredPoint.x,
6429
+ minY: anchoredPoint.y,
6430
+ maxX: anchoredPoint.x,
6431
+ maxY: anchoredPoint.y
6432
+ } : null;
6433
+ };
6434
+ var getBoundsOfPcbElements = (elements) => {
6435
+ let bounds = {
6436
+ minX: Number.POSITIVE_INFINITY,
6437
+ minY: Number.POSITIVE_INFINITY,
6438
+ maxX: Number.NEGATIVE_INFINITY,
6439
+ maxY: Number.NEGATIVE_INFINITY
6440
+ };
6441
+ for (const element of elements) {
6442
+ const elementBounds = getPcbElementBounds(element);
6443
+ if (elementBounds) bounds = mergeBounds(bounds, elementBounds);
6444
+ }
6445
+ return bounds;
6446
+ };
6122
6447
  function stringHash(str) {
6123
6448
  let hash = 0;
6124
6449
  if (str.length == 0) return hash;
@@ -6525,94 +6850,6 @@ var getPolarizedPinMetadata = (pinLabels) => {
6525
6850
  };
6526
6851
  };
6527
6852
 
6528
- // lib/utils/normalize-pin-labels.ts
6529
- var normalizeActiveLowPinLabel = (label) => {
6530
- const hasActiveLowMarker = label.startsWith("#") || label.endsWith("#");
6531
- if (!hasActiveLowMarker) return label;
6532
- const activeLowLabel = label.replace(/^#/, "").replace(/#$/, "");
6533
- if (activeLowLabel.length === 0) return label;
6534
- if (activeLowLabel.startsWith("N_")) return activeLowLabel;
6535
- return `N_${activeLowLabel}`;
6536
- };
6537
- var normalizePinLabels = (inputPinLabels) => {
6538
- const normalizedInputPinLabels = inputPinLabels.map(
6539
- (labels) => labels.map(normalizeActiveLowPinLabel)
6540
- );
6541
- const uniqueInputPinLabels = normalizedInputPinLabels.map((labels) => [
6542
- ...new Set(labels)
6543
- ]);
6544
- const result = uniqueInputPinLabels.map(() => []);
6545
- const desiredNumbers = uniqueInputPinLabels.map(() => null);
6546
- for (let i = 0; i < uniqueInputPinLabels.length; i++) {
6547
- for (const label of uniqueInputPinLabels[i]) {
6548
- if (/^\d+$/.test(label)) {
6549
- desiredNumbers[i] = Number.parseInt(label);
6550
- break;
6551
- }
6552
- }
6553
- }
6554
- let highestPinNumber = 0;
6555
- const acceptedDesiredNumbers = /* @__PURE__ */ new Set();
6556
- for (let i = 0; i < desiredNumbers.length; i++) {
6557
- const desiredNumber = desiredNumbers[i];
6558
- if (desiredNumber === null || desiredNumber < 1) continue;
6559
- if (!acceptedDesiredNumbers.has(desiredNumber)) {
6560
- acceptedDesiredNumbers.add(desiredNumber);
6561
- result[i].push(`pin${desiredNumber}`);
6562
- highestPinNumber = Math.max(highestPinNumber, desiredNumber);
6563
- continue;
6564
- }
6565
- let existingAltCount = 0;
6566
- for (const label of result[i]) {
6567
- if (label.startsWith(`pin${desiredNumber}_alt`)) {
6568
- existingAltCount += 1;
6569
- }
6570
- }
6571
- result[i].push(`pin${desiredNumber}_alt${existingAltCount + 1}`);
6572
- }
6573
- for (let i = 0; i < result.length; i++) {
6574
- const firstLabel = result[i][0];
6575
- if (firstLabel?.includes("_alt")) {
6576
- highestPinNumber += 1;
6577
- result[i].unshift(`pin${highestPinNumber}`);
6578
- }
6579
- }
6580
- for (let i = 0; i < result.length; i++) {
6581
- if (result[i].length === 0) {
6582
- highestPinNumber += 1;
6583
- result[i].push(`pin${highestPinNumber}`);
6584
- }
6585
- }
6586
- const totalLabelCounts = {};
6587
- for (const inputLabels of uniqueInputPinLabels) {
6588
- for (const label of inputLabels) {
6589
- if (/^\d+$/.test(label)) continue;
6590
- totalLabelCounts[label] = (totalLabelCounts[label] ?? 0) + 1;
6591
- }
6592
- }
6593
- const incrementalLabelCounts = {};
6594
- for (let i = 0; i < uniqueInputPinLabels.length; i++) {
6595
- for (const label of uniqueInputPinLabels[i]) {
6596
- if (/^\d+$/.test(label)) continue;
6597
- if (totalLabelCounts[label] === 1) {
6598
- result[i].push(label);
6599
- } else {
6600
- incrementalLabelCounts[label] = (incrementalLabelCounts[label] ?? 0) + 1;
6601
- result[i].push(`${label}${incrementalLabelCounts[label]}`);
6602
- }
6603
- }
6604
- }
6605
- return result;
6606
- };
6607
-
6608
- // lib/utils/normalize-symbol-name.ts
6609
- var normalizeSymbolName = (name) => {
6610
- const trimmedName = name.trim();
6611
- if (trimmedName === "+") return "_POS";
6612
- if (trimmedName === "-") return "_NEG";
6613
- return trimmedName.replace(/(?<=[A-Za-z0-9])-(?=[A-Za-z0-9])/g, "_");
6614
- };
6615
-
6616
6853
  // lib/websafe/convert-to-typescript-component/category-value-contains-diode.ts
6617
6854
  var categoryValueContainsDiode = (value) => {
6618
6855
  if (typeof value === "string") {
@@ -6805,6 +7042,39 @@ var parseCadOffsetsFromSvgNode = (svgNode) => {
6805
7042
  })()
6806
7043
  };
6807
7044
  };
7045
+ var getCadModelOutlineBounds = (svgNode) => {
7046
+ const points = [];
7047
+ for (const childNode of svgNode?.svgData.childNodes ?? []) {
7048
+ if (typeof childNode !== "object" || childNode === null) continue;
7049
+ const attrs = childNode.attrs;
7050
+ if (typeof attrs !== "object" || attrs === null) continue;
7051
+ const rawPoints = attrs.points;
7052
+ if (typeof rawPoints !== "string") continue;
7053
+ const coordinates = rawPoints.trim().split(/\s+/).map(Number);
7054
+ for (let index = 0; index + 1 < coordinates.length; index += 2) {
7055
+ const x = coordinates[index];
7056
+ const y = coordinates[index + 1];
7057
+ if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
7058
+ points.push({ x: milx10(x), y: milx10(y) });
7059
+ }
7060
+ }
7061
+ if (points.length === 0) return void 0;
7062
+ return {
7063
+ minX: Math.min(...points.map((point2) => point2.x)),
7064
+ minY: Math.min(...points.map((point2) => point2.y)),
7065
+ maxX: Math.max(...points.map((point2) => point2.x)),
7066
+ maxY: Math.max(...points.map((point2) => point2.y))
7067
+ };
7068
+ };
7069
+ var unionBounds = (first, second) => {
7070
+ if (!second) return first;
7071
+ return {
7072
+ minX: Math.min(first.minX, second.minX),
7073
+ minY: Math.min(first.minY, second.minY),
7074
+ maxX: Math.max(first.maxX, second.maxX),
7075
+ maxY: Math.max(first.maxY, second.maxY)
7076
+ };
7077
+ };
6808
7078
  var readModelHeightMm = (raw) => {
6809
7079
  const fallback = 3.5;
6810
7080
  if (raw == null) return fallback;
@@ -7063,9 +7333,9 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
7063
7333
  const pins = easyEdaJson.dataStr.shape.filter((shape) => shape.type === "PIN");
7064
7334
  const pinLabelSets = pads.map((pad) => {
7065
7335
  const labels = [];
7066
- if (pad.number) labels.push(pad.number.toString());
7336
+ if (pad.number) labels.push(...getEasyEdaPinAliases(pad.number.toString()));
7067
7337
  const pin = pins.find((p) => p.pinNumber === pad.number);
7068
- if (pin) labels.push(normalizeSymbolName(pin.label));
7338
+ if (pin) labels.push(...getEasyEdaPinAliases(pin.label));
7069
7339
  return labels;
7070
7340
  });
7071
7341
  const padNumberKeys = pads.map((pad, index) => {
@@ -7396,17 +7666,29 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
7396
7666
  );
7397
7667
  }
7398
7668
  const hasExplicitCourtyard = circuitElements.some(
7399
- (e) => e.type === "pcb_courtyard_outline"
7669
+ (e) => e.type === "pcb_courtyard_outline" || e.type === "pcb_courtyard_rect"
7400
7670
  );
7401
7671
  if (!hasExplicitCourtyard) {
7402
7672
  const bbox = easyEdaJson.packageDetail.dataStr.BBox;
7403
- if (bbox) {
7673
+ const modelOutlineBounds = getCadModelOutlineBounds(svgNode);
7674
+ const packageElements = circuitElements.filter(
7675
+ (element) => element.type === "pcb_smtpad" || element.type === "pcb_plated_hole" || element.type === "pcb_hole" || element.type === "pcb_via"
7676
+ );
7677
+ const packageElementBounds = packageElements.length > 0 ? getBoundsOfPcbElements(packageElements) : void 0;
7678
+ const fallbackBounds = bbox ? {
7679
+ minX: milx10(bbox.x),
7680
+ minY: milx10(bbox.y),
7681
+ maxX: milx10(bbox.x + bbox.width),
7682
+ maxY: milx10(bbox.y + bbox.height)
7683
+ } : void 0;
7684
+ const courtyardBounds = modelOutlineBounds ? unionBounds(modelOutlineBounds, packageElementBounds) : fallbackBounds;
7685
+ if (courtyardBounds) {
7404
7686
  const strokeWidth = 0.05;
7405
7687
  const margin = 0.25;
7406
- const x1 = milx10(bbox.x) - margin;
7407
- const y1 = milx10(bbox.y) - margin;
7408
- const x2 = milx10(bbox.x + bbox.width) + margin;
7409
- const y2 = milx10(bbox.y + bbox.height) + margin;
7688
+ const x1 = courtyardBounds.minX - margin;
7689
+ const y1 = courtyardBounds.minY - margin;
7690
+ const x2 = courtyardBounds.maxX + margin;
7691
+ const y2 = courtyardBounds.maxY + margin;
7410
7692
  circuitElements.push(
7411
7693
  pcb_courtyard_outline.parse({
7412
7694
  type: "pcb_courtyard_outline",
@@ -8199,14 +8481,9 @@ var PinShapeOutputSchema = z201.object({
8199
8481
  var parsePin = (pinString) => {
8200
8482
  const parts = pinString.split("~");
8201
8483
  const [, visibility, , pinNumber, x, y, rotation2, id] = parts;
8202
- const nameMatch = pinString.match(/~([\w+#-]+)~(start|end)~/);
8203
- let label = nameMatch ? nameMatch[1] : "";
8204
- if (label.endsWith("+")) label = `${label.slice(0, -1)}_POS`;
8205
- if (label.endsWith("-")) label = `${label.slice(0, -1)}_NEG`;
8206
- label = normalizeActiveLowPinLabel(label);
8207
- if (/^\+\d+(?:\.\d+)?V$/i.test(label)) label = `V${label.slice(1, -1)}`;
8208
- if (label.startsWith("+")) label = `${label.slice(1)}_POS`;
8209
- if (label.startsWith("-")) label = `${label.slice(1)}_NEG`;
8484
+ const pinNameSection = pinString.split("^^")[3];
8485
+ let label = pinNameSection?.split("~")[4] ?? "";
8486
+ if (!label.includes("/")) label = normalizeEasyEdaPinLabel(label);
8210
8487
  const colorMatch = pinString.match(/#[0-9A-F]{6}/);
8211
8488
  const labelColor = colorMatch ? colorMatch[0] : "";
8212
8489
  const path = pinString.split("^^")[2]?.split("~")[0] ?? "";
@@ -8685,6 +8962,14 @@ var getEasyEdaCadModelPlacement = async (easyEdaJson, { fetch: fetch2 = globalTh
8685
8962
  return placementPromise;
8686
8963
  };
8687
8964
 
8965
+ // lib/utils/normalize-symbol-name.ts
8966
+ var normalizeSymbolName = (name) => {
8967
+ const trimmedName = name.trim();
8968
+ if (trimmedName === "+") return "_POS";
8969
+ if (trimmedName === "-") return "_NEG";
8970
+ return trimmedName.replace(/(?<=[A-Za-z0-9])-(?=[A-Za-z0-9])/g, "_");
8971
+ };
8972
+
8688
8973
  // lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
8689
8974
  var round = (value) => Number(value.toFixed(6));
8690
8975
  var EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT = 0.02;
@@ -8911,14 +9196,15 @@ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
8911
9196
  portName ??= `pin${pinIndex + 1}`;
8912
9197
  usedPortNames.add(portName);
8913
9198
  const sourcePort = sourcePorts.find((port) => port.name === portName);
9199
+ let aliases = getEasyEdaPinAliases(pin.label);
9200
+ if (sourcePort?.port_hints?.length) {
9201
+ aliases = sourcePort.port_hints;
9202
+ }
8914
9203
  metadataByShapeId.set(pin.id, {
8915
9204
  name: portName,
8916
9205
  pinNumber: sourcePort?.pin_number,
8917
- aliases: [
8918
- ...sourcePort?.port_hints ?? [],
8919
- ...pin.label ? [normalizeSymbolName(pin.label)] : []
8920
- ].filter(
8921
- (alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
9206
+ aliases: aliases.filter(
9207
+ (alias, index, aliases2) => alias !== portName && aliases2.indexOf(alias) === index
8922
9208
  )
8923
9209
  });
8924
9210
  });