easyeda 0.0.39 → 0.0.41

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.
@@ -4,263 +4,6 @@ var __export = (target, all) => {
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
5
5
  };
6
6
 
7
- // lib/schemas/package-detail-shape-schema.ts
8
- import { z } from "zod";
9
- var tenthmil = z.union([z.number(), z.string()]).optional().transform(
10
- (n) => typeof n === "string" && n.endsWith("mil") ? n : `${Number.parseFloat(n) * 10}mil`
11
- ).pipe(z.string());
12
- var PointSchema = z.any().transform((p) => {
13
- if (Array.isArray(p)) {
14
- const [x, y] = p;
15
- return { x, y };
16
- } else if (typeof p === "object") {
17
- return p;
18
- }
19
- throw new Error(`Invalid point: ${p}`);
20
- }).pipe(
21
- z.object({
22
- x: z.number(),
23
- y: z.number()
24
- })
25
- );
26
- var BaseShapeSchema = z.object({
27
- type: z.string(),
28
- id: z.string().optional(),
29
- layer: z.coerce.number().optional()
30
- });
31
- var TrackSchema = BaseShapeSchema.extend({
32
- type: z.literal("TRACK"),
33
- width: z.coerce.number(),
34
- points: z.array(PointSchema)
35
- });
36
- var PadSchema = BaseShapeSchema.extend({
37
- type: z.literal("PAD"),
38
- shape: z.enum(["RECT", "ELLIPSE", "OVAL"]),
39
- center: z.object({
40
- x: tenthmil,
41
- y: tenthmil
42
- }),
43
- width: tenthmil,
44
- height: tenthmil,
45
- layermask: z.number(),
46
- net: z.union([z.string(), z.number()]).optional(),
47
- number: z.union([z.string(), z.number()]),
48
- holeRadius: tenthmil,
49
- points: z.array(PointSchema).optional(),
50
- rotation: z.number().optional(),
51
- plated: z.boolean()
52
- });
53
- var ArcSchema = BaseShapeSchema.extend({
54
- type: z.literal("ARC"),
55
- width: z.number(),
56
- start: PointSchema,
57
- end: PointSchema,
58
- radiusX: z.number(),
59
- radiusY: z.number(),
60
- largeArc: z.boolean(),
61
- sweepDirection: z.enum(["CW", "CCW"])
62
- });
63
- var CircleSchema = BaseShapeSchema.extend({
64
- type: z.literal("CIRCLE"),
65
- center: PointSchema,
66
- radius: z.number(),
67
- width: z.number()
68
- });
69
- var SolidRegionSchema = BaseShapeSchema.extend({
70
- type: z.literal("SOLIDREGION"),
71
- layermask: z.number(),
72
- points: z.array(PointSchema),
73
- fillStyle: z.string()
74
- });
75
- var SVGNodeSchema = BaseShapeSchema.extend({
76
- type: z.literal("SVGNODE"),
77
- svgData: z.object({
78
- gId: z.string(),
79
- nodeName: z.string(),
80
- nodeType: z.number(),
81
- layerid: z.string(),
82
- attrs: z.record(z.string(), z.string()),
83
- childNodes: z.array(z.unknown())
84
- })
85
- });
86
- var HoleSchema = BaseShapeSchema.extend({
87
- type: z.literal("HOLE"),
88
- center: PointSchema,
89
- radius: z.number()
90
- });
91
- var RectSchema = BaseShapeSchema.extend({
92
- type: z.literal("RECT"),
93
- x: tenthmil,
94
- y: tenthmil,
95
- width: tenthmil,
96
- height: tenthmil,
97
- lineWidth: z.number(),
98
- fillStyle: z.string(),
99
- rotation: z.number().optional()
100
- });
101
- var PackageDetailShapeSchema = z.discriminatedUnion("type", [
102
- TrackSchema,
103
- PadSchema,
104
- ArcSchema,
105
- CircleSchema,
106
- SolidRegionSchema,
107
- SVGNodeSchema,
108
- HoleSchema,
109
- RectSchema
110
- ]);
111
- var pairs = (arr) => {
112
- const pairs2 = [];
113
- for (let i = 0; i < arr.length; i += 2) {
114
- pairs2.push([arr[i], arr[i + 1]]);
115
- }
116
- return pairs2;
117
- };
118
- var parsePoints = (pointsStr) => pairs(
119
- pointsStr.trim().split(" ").map((n) => Number(n))
120
- );
121
- var ShapeItemSchema = z.object({
122
- type: z.string(),
123
- data: z.string()
124
- }).transform((shape) => {
125
- const [firstParam, ...restParams] = shape.data.split("~");
126
- const lastParam = restParams.pop();
127
- switch (shape.type) {
128
- case "TRACK": {
129
- const [width, layer, _, pointsStr, id, _n] = shape.data.split("~");
130
- const points = parsePoints(pointsStr);
131
- return TrackSchema.parse({ type: "TRACK", width, layer, points, id });
132
- }
133
- case "PAD": {
134
- const [padShape, ...params] = shape.data.split("~");
135
- const [
136
- centerX,
137
- centerY,
138
- width,
139
- height,
140
- layermask,
141
- net,
142
- number,
143
- holeRadius,
144
- ...rest
145
- ] = params.map((p) => isNaN(Number(p)) ? p : Number(p));
146
- const center = { x: centerX, y: centerY };
147
- let points, rotation2;
148
- if (padShape === "RECT") {
149
- points = parsePoints(rest[0]);
150
- rotation2 = Number(rest[1]);
151
- }
152
- const padInputParams = {
153
- type: "PAD",
154
- shape: padShape,
155
- center,
156
- width,
157
- height,
158
- layermask,
159
- net,
160
- number,
161
- holeRadius,
162
- points,
163
- rotation: rotation2,
164
- plated: rest.includes("Y")
165
- };
166
- const pad = PadSchema.parse(padInputParams);
167
- return pad;
168
- }
169
- case "ARC": {
170
- const [width, layer, , arcData] = shape.data.split("~");
171
- const [
172
- ,
173
- startX,
174
- startY,
175
- radiusX,
176
- radiusY,
177
- xAxisRotation,
178
- largeArcFlag,
179
- sweepFlag,
180
- endX,
181
- endY
182
- ] = arcData.match(
183
- /M\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)\s*A\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)\s*([\d.]+)\s*([01])\s*([01])\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)/
184
- );
185
- const start = [Number(startX), Number(startY)];
186
- const end = [Number(endX), Number(endY)];
187
- return ArcSchema.parse({
188
- type: "ARC",
189
- width: Number(width),
190
- layer: Number(layer),
191
- start,
192
- end,
193
- radiusX: Number(radiusX),
194
- radiusY: Number(radiusY),
195
- largeArc: largeArcFlag === "1",
196
- sweepDirection: sweepFlag === "1" ? "CW" : "CCW"
197
- });
198
- }
199
- case "CIRCLE": {
200
- const [centerX, centerY, radius, width, layer, id] = shape.data.split("~");
201
- const center = [Number(centerX), Number(centerY)];
202
- return CircleSchema.parse({
203
- type: "CIRCLE",
204
- center,
205
- radius: Number(radius),
206
- width: Number(width),
207
- layer: Number(layer),
208
- id
209
- });
210
- }
211
- case "HOLE": {
212
- const [centerX, centerY, radius, id] = shape.data.split("~");
213
- const center = [Number(centerX), Number(centerY)];
214
- return HoleSchema.parse({
215
- type: "HOLE",
216
- center,
217
- radius: Number(radius),
218
- id
219
- });
220
- }
221
- case "SOLIDREGION": {
222
- const [layermask, , pathData, fillStyle, id] = shape.data.split("~");
223
- const points = pathData.match(/[ML] ?(-?[\d.]+)[ ,](-?[\d.]+)/g)?.map((point2) => {
224
- const [, x, y] = point2.match(/[ML]? ?(-?[\d.]+)[ ,](-?[\d.]+)/) || [];
225
- return [Number(x), Number(y)];
226
- }) || [];
227
- return SolidRegionSchema.parse({
228
- type: "SOLIDREGION",
229
- layermask: Number(layermask),
230
- points,
231
- fillStyle,
232
- id
233
- });
234
- }
235
- case "SVGNODE": {
236
- const svgData = JSON.parse(shape.data);
237
- return SVGNodeSchema.parse({ type: "SVGNODE", svgData });
238
- }
239
- case "RECT": {
240
- const [x, y, width, height, lineWidth, id, rotation2, layer, fillStyle] = shape.data.split("~");
241
- return RectSchema.parse({
242
- type: "RECT",
243
- x,
244
- y,
245
- width,
246
- height,
247
- lineWidth: Number(lineWidth),
248
- id,
249
- rotation: rotation2 ? Number(rotation2) : void 0,
250
- layer: layer ? Number(layer) : void 0,
251
- fillStyle: fillStyle || void 0
252
- });
253
- }
254
- default:
255
- throw new Error(`Unknown shape type: ${shape.type}`);
256
- return BaseShapeSchema.parse({ type: shape.type });
257
- }
258
- }).pipe(PackageDetailShapeSchema);
259
- var ShapesArraySchema = z.array(ShapeItemSchema);
260
-
261
- // lib/convert-easyeda-json-to-tscircuit-soup-json.ts
262
- import "zod";
263
-
264
7
  // node_modules/circuit-json/dist/index.mjs
265
8
  var dist_exports = {};
266
9
  __export(dist_exports, {
@@ -343,8 +86,8 @@ __export(dist_exports, {
343
86
  visible_layer: () => visible_layer,
344
87
  voltage: () => voltage
345
88
  });
89
+ import { z } from "zod";
346
90
  import { z as z2 } from "zod";
347
- import { z as z22 } from "zod";
348
91
  import { z as z3 } from "zod";
349
92
  import { z as z4 } from "zod";
350
93
  import { z as z5 } from "zod";
@@ -396,7 +139,7 @@ import { z as z18 } from "zod";
396
139
  import { z as z19 } from "zod";
397
140
  import { z as z20 } from "zod";
398
141
  import { z as z21 } from "zod";
399
- import { z as z222 } from "zod";
142
+ import { z as z22 } from "zod";
400
143
  import { z as z23 } from "zod";
401
144
  import { z as z24 } from "zod";
402
145
  import { z as z25 } from "zod";
@@ -582,15 +325,15 @@ var parseAndConvertSiUnit = (v) => {
582
325
  value: conversionFactor * Number.parseFloat(value)
583
326
  };
584
327
  };
585
- var resistance = z2.string().or(z2.number()).transform((v) => parseAndConvertSiUnit(v).value);
586
- var capacitance = z2.string().or(z2.number()).transform((v) => parseAndConvertSiUnit(v).value);
587
- var inductance = z2.string().or(z2.number()).transform((v) => parseAndConvertSiUnit(v).value);
588
- var voltage = z2.string().or(z2.number()).transform((v) => parseAndConvertSiUnit(v).value);
589
- var length = z2.string().or(z2.number()).transform((v) => parseAndConvertSiUnit(v).value);
328
+ var resistance = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
329
+ var capacitance = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
330
+ var inductance = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
331
+ var voltage = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
332
+ var length = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
590
333
  var distance = length;
591
- var current = z2.string().or(z2.number()).transform((v) => parseAndConvertSiUnit(v).value);
592
- var time = z2.string().or(z2.number()).transform((v) => parseAndConvertSiUnit(v).value);
593
- var rotation = z2.string().or(z2.number()).transform((arg) => {
334
+ var current = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
335
+ var time = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
336
+ var rotation = z.string().or(z.number()).transform((arg) => {
594
337
  if (typeof arg === "number") return arg;
595
338
  if (arg.endsWith("deg")) {
596
339
  return Number.parseFloat(arg.split("deg")[0]);
@@ -600,7 +343,7 @@ var rotation = z2.string().or(z2.number()).transform((arg) => {
600
343
  }
601
344
  return Number.parseFloat(arg);
602
345
  });
603
- var point = z22.object({
346
+ var point = z2.object({
604
347
  x: distance,
605
348
  y: distance
606
349
  });
@@ -705,9 +448,9 @@ var source_net = z21.object({
705
448
  is_analog_signal: z21.boolean().optional(),
706
449
  trace_width: z21.number().optional()
707
450
  });
708
- var schematic_box = z222.object({
709
- type: z222.literal("schematic_box"),
710
- schematic_component_id: z222.string(),
451
+ var schematic_box = z22.object({
452
+ type: z22.literal("schematic_box"),
453
+ schematic_component_id: z22.string(),
711
454
  width: distance,
712
455
  height: distance,
713
456
  x: distance,
@@ -1544,7 +1287,7 @@ var transformPCBElements = (elms, matrix) => {
1544
1287
  };
1545
1288
 
1546
1289
  // lib/convert-easyeda-json-to-tscircuit-soup-json.ts
1547
- import { scale, translate } from "transformation-matrix";
1290
+ import { compose, scale, translate } from "transformation-matrix";
1548
1291
 
1549
1292
  // lib/compute-center-offset.ts
1550
1293
  import { mm } from "@tscircuit/mm";
@@ -1566,6 +1309,16 @@ var computeCenterOffset = (easyeda) => {
1566
1309
 
1567
1310
  // lib/convert-easyeda-json-to-tscircuit-soup-json.ts
1568
1311
  import { mm as mm2 } from "@tscircuit/mm";
1312
+ var mil2mm = (mil) => {
1313
+ if (typeof mil === "number") return mm2(`${mil}mil`);
1314
+ if (mil.match(/^\d+$/)) return mm2(`${mil}mil`);
1315
+ return mm2(mil);
1316
+ };
1317
+ var milx10 = (mil10) => {
1318
+ if (typeof mil10 === "number") return mil2mm(mil10) * 10;
1319
+ if (mil10.match(/^\d+$/)) return mil2mm(mil10) * 10;
1320
+ return mil2mm(mil10);
1321
+ };
1569
1322
  var handleSilkscreenPath = (track, index) => {
1570
1323
  return pcb_silkscreen_path.parse({
1571
1324
  type: "pcb_silkscreen_path",
@@ -1573,7 +1326,10 @@ var handleSilkscreenPath = (track, index) => {
1573
1326
  pcb_component_id: "pcb_component_1",
1574
1327
  layer: "top",
1575
1328
  // Assuming all silkscreen is on top layer
1576
- route: track.points.map((point2) => ({ x: point2.x, y: point2.y })),
1329
+ route: track.points.map((point2) => ({
1330
+ x: milx10(point2.x),
1331
+ y: milx10(point2.y)
1332
+ })),
1577
1333
  stroke_width: track.width
1578
1334
  });
1579
1335
  };
@@ -1593,8 +1349,21 @@ var handleSilkscreenArc = (arc, index) => {
1593
1349
  pcb_component_id: "pcb_component_1",
1594
1350
  layer: "top",
1595
1351
  // Assuming all silkscreen is on top layer
1596
- route: arcPath,
1597
- stroke_width: arc.width
1352
+ route: arcPath.map((p) => ({
1353
+ x: milx10(p.x),
1354
+ y: milx10(p.y)
1355
+ })),
1356
+ stroke_width: mm2(arc.width)
1357
+ });
1358
+ };
1359
+ var handleHole = (hole, index) => {
1360
+ return pcb_hole.parse({
1361
+ type: "pcb_hole",
1362
+ x: milx10(hole.center.x),
1363
+ y: milx10(hole.center.y),
1364
+ hole_diameter: milx10(hole.radius) * 2,
1365
+ hole_shape: "circle",
1366
+ pcb_hole_id: `pcb_hole_${index + 1}`
1598
1367
  });
1599
1368
  };
1600
1369
  var convertEasyEdaJsonToCircuitJson = (easyEdaJson, { useModelCdn, shouldRecenter = true } = {}) => {
@@ -1629,17 +1398,17 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, { useModelCdn, shouldRecente
1629
1398
  source_component_id: "source_component_1",
1630
1399
  name: portNumber
1631
1400
  });
1632
- if (pad.holeRadius !== void 0 && mm2(pad.holeRadius) !== 0) {
1401
+ if (pad.holeRadius !== void 0 && mil2mm(pad.holeRadius) !== 0) {
1633
1402
  soupElements.push(
1634
1403
  pcb_plated_hole.parse({
1635
1404
  type: "pcb_plated_hole",
1636
1405
  pcb_plated_hole_id: `pcb_plated_hole_${index + 1}`,
1637
1406
  shape: "circle",
1638
- x: mm2(pad.center.x),
1639
- y: mm2(pad.center.y),
1640
- hole_diameter: mm2(pad.holeRadius) * 2,
1641
- outer_diameter: mm2(pad.width),
1642
- radius: mm2(pad.holeRadius),
1407
+ x: mil2mm(pad.center.x),
1408
+ y: mil2mm(pad.center.y),
1409
+ hole_diameter: mil2mm(pad.holeRadius) * 2,
1410
+ outer_diameter: mil2mm(pad.width),
1411
+ radius: mil2mm(pad.holeRadius),
1643
1412
  port_hints: [portNumber],
1644
1413
  pcb_component_id: "pcb_component_1",
1645
1414
  pcb_port_id: `pcb_port_${index + 1}`,
@@ -1658,22 +1427,26 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, { useModelCdn, shouldRecente
1658
1427
  if (!soupShape) {
1659
1428
  throw new Error(`unknown pad.shape: "${pad.shape}"`);
1660
1429
  }
1661
- soupElements.push(
1662
- pcb_smtpad.parse({
1663
- type: "pcb_smtpad",
1664
- pcb_smtpad_id: `pcb_smtpad_${index + 1}`,
1665
- shape: soupShape,
1666
- x: mm2(pad.center.x),
1667
- y: mm2(pad.center.y),
1668
- ...soupShape === "rect" ? { width: mm2(pad.width), height: mm2(pad.height) } : { radius: Math.min(mm2(pad.width), mm2(pad.height)) / 2 },
1669
- layer: "top",
1670
- port_hints: [portNumber],
1671
- pcb_component_id: "pcb_component_1",
1672
- pcb_port_id: `pcb_port_${index + 1}`
1673
- })
1674
- );
1430
+ const parsedPcbSmtpad = pcb_smtpad.parse({
1431
+ type: "pcb_smtpad",
1432
+ pcb_smtpad_id: `pcb_smtpad_${index + 1}`,
1433
+ shape: soupShape,
1434
+ x: mil2mm(pad.center.x),
1435
+ y: mil2mm(pad.center.y),
1436
+ ...soupShape === "rect" ? { width: mil2mm(pad.width), height: mil2mm(pad.height) } : { radius: Math.min(mil2mm(pad.width), mil2mm(pad.height)) / 2 },
1437
+ layer: "top",
1438
+ port_hints: [portNumber],
1439
+ pcb_component_id: "pcb_component_1",
1440
+ pcb_port_id: `pcb_port_${index + 1}`
1441
+ });
1442
+ soupElements.push(parsedPcbSmtpad);
1675
1443
  }
1676
1444
  });
1445
+ easyEdaJson.packageDetail.dataStr.shape.filter(
1446
+ (shape) => shape.type === "HOLE"
1447
+ ).forEach((h, index) => {
1448
+ soupElements.push(handleHole(h, index));
1449
+ });
1677
1450
  easyEdaJson.packageDetail.dataStr.shape.forEach((shape, index) => {
1678
1451
  if (shape.type === "TRACK") {
1679
1452
  soupElements.push(handleSilkscreenPath(shape, index));
@@ -1704,7 +1477,7 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, { useModelCdn, shouldRecente
1704
1477
  if (shouldRecenter) {
1705
1478
  transformPCBElements(
1706
1479
  soupElements,
1707
- translate(-centerOffset.x, centerOffset.y)
1480
+ compose(translate(-centerOffset.x, centerOffset.y), scale(1, -1))
1708
1481
  );
1709
1482
  }
1710
1483
  return soupElements;
@@ -1762,6 +1535,260 @@ async function fetchEasyEDAComponent(jlcpcbPartNumber) {
1762
1535
  // lib/schemas/easy-eda-json-schema.ts
1763
1536
  import { z as z61 } from "zod";
1764
1537
 
1538
+ // lib/schemas/package-detail-shape-schema.ts
1539
+ import { z as z59 } from "zod";
1540
+ var tenthmil = z59.union([z59.number(), z59.string()]).optional().transform(
1541
+ (n) => typeof n === "string" && n.endsWith("mil") ? n : `${Number.parseFloat(n) * 10}mil`
1542
+ ).pipe(z59.string());
1543
+ var PointSchema = z59.any().transform((p) => {
1544
+ if (Array.isArray(p)) {
1545
+ const [x, y] = p;
1546
+ return { x, y };
1547
+ } else if (typeof p === "object") {
1548
+ return p;
1549
+ }
1550
+ throw new Error(`Invalid point: ${p}`);
1551
+ }).pipe(
1552
+ z59.object({
1553
+ x: z59.number(),
1554
+ y: z59.number()
1555
+ })
1556
+ );
1557
+ var BaseShapeSchema = z59.object({
1558
+ type: z59.string(),
1559
+ id: z59.string().optional(),
1560
+ layer: z59.coerce.number().optional()
1561
+ });
1562
+ var TrackSchema = BaseShapeSchema.extend({
1563
+ type: z59.literal("TRACK"),
1564
+ width: z59.coerce.number(),
1565
+ points: z59.array(PointSchema)
1566
+ });
1567
+ var PadSchema = BaseShapeSchema.extend({
1568
+ type: z59.literal("PAD"),
1569
+ shape: z59.enum(["RECT", "ELLIPSE", "OVAL"]),
1570
+ center: z59.object({
1571
+ x: tenthmil,
1572
+ y: tenthmil
1573
+ }),
1574
+ width: tenthmil,
1575
+ height: tenthmil,
1576
+ layermask: z59.number(),
1577
+ net: z59.union([z59.string(), z59.number()]).optional(),
1578
+ number: z59.union([z59.string(), z59.number()]),
1579
+ holeRadius: tenthmil,
1580
+ points: z59.array(PointSchema).optional(),
1581
+ rotation: z59.number().optional(),
1582
+ plated: z59.boolean()
1583
+ });
1584
+ var ArcSchema = BaseShapeSchema.extend({
1585
+ type: z59.literal("ARC"),
1586
+ width: z59.number(),
1587
+ start: PointSchema,
1588
+ end: PointSchema,
1589
+ radiusX: z59.number(),
1590
+ radiusY: z59.number(),
1591
+ largeArc: z59.boolean(),
1592
+ sweepDirection: z59.enum(["CW", "CCW"])
1593
+ });
1594
+ var CircleSchema = BaseShapeSchema.extend({
1595
+ type: z59.literal("CIRCLE"),
1596
+ center: PointSchema,
1597
+ radius: z59.number(),
1598
+ width: z59.number()
1599
+ });
1600
+ var SolidRegionSchema = BaseShapeSchema.extend({
1601
+ type: z59.literal("SOLIDREGION"),
1602
+ layermask: z59.number(),
1603
+ points: z59.array(PointSchema),
1604
+ fillStyle: z59.string()
1605
+ });
1606
+ var SVGNodeSchema = BaseShapeSchema.extend({
1607
+ type: z59.literal("SVGNODE"),
1608
+ svgData: z59.object({
1609
+ gId: z59.string(),
1610
+ nodeName: z59.string(),
1611
+ nodeType: z59.number(),
1612
+ layerid: z59.string(),
1613
+ attrs: z59.record(z59.string(), z59.string()),
1614
+ childNodes: z59.array(z59.unknown())
1615
+ })
1616
+ });
1617
+ var HoleSchema = BaseShapeSchema.extend({
1618
+ type: z59.literal("HOLE"),
1619
+ center: PointSchema,
1620
+ radius: z59.number()
1621
+ });
1622
+ var RectSchema = BaseShapeSchema.extend({
1623
+ type: z59.literal("RECT"),
1624
+ x: tenthmil,
1625
+ y: tenthmil,
1626
+ width: tenthmil,
1627
+ height: tenthmil,
1628
+ lineWidth: z59.number(),
1629
+ fillStyle: z59.string(),
1630
+ rotation: z59.number().optional()
1631
+ });
1632
+ var PackageDetailShapeSchema = z59.discriminatedUnion("type", [
1633
+ TrackSchema,
1634
+ PadSchema,
1635
+ ArcSchema,
1636
+ CircleSchema,
1637
+ SolidRegionSchema,
1638
+ SVGNodeSchema,
1639
+ HoleSchema,
1640
+ RectSchema
1641
+ ]);
1642
+ var pairs = (arr) => {
1643
+ const pairs2 = [];
1644
+ for (let i = 0; i < arr.length; i += 2) {
1645
+ pairs2.push([arr[i], arr[i + 1]]);
1646
+ }
1647
+ return pairs2;
1648
+ };
1649
+ var parsePoints = (pointsStr) => pairs(
1650
+ pointsStr.trim().split(" ").map((n) => Number(n))
1651
+ );
1652
+ var ShapeItemSchema = z59.object({
1653
+ type: z59.string(),
1654
+ data: z59.string()
1655
+ }).transform((shape) => {
1656
+ const [firstParam, ...restParams] = shape.data.split("~");
1657
+ const lastParam = restParams.pop();
1658
+ switch (shape.type) {
1659
+ case "TRACK": {
1660
+ const [width, layer, _, pointsStr, id, _n] = shape.data.split("~");
1661
+ const points = parsePoints(pointsStr);
1662
+ return TrackSchema.parse({ type: "TRACK", width, layer, points, id });
1663
+ }
1664
+ case "PAD": {
1665
+ const [padShape, ...params] = shape.data.split("~");
1666
+ const [
1667
+ centerX,
1668
+ centerY,
1669
+ width,
1670
+ height,
1671
+ layermask,
1672
+ net,
1673
+ number,
1674
+ holeRadius,
1675
+ ...rest
1676
+ ] = params.map((p) => isNaN(Number(p)) ? p : Number(p));
1677
+ const center = { x: centerX, y: centerY };
1678
+ let points, rotation2;
1679
+ if (padShape === "RECT") {
1680
+ points = parsePoints(rest[0]);
1681
+ rotation2 = Number(rest[1]);
1682
+ }
1683
+ const padInputParams = {
1684
+ type: "PAD",
1685
+ shape: padShape,
1686
+ center,
1687
+ width,
1688
+ height,
1689
+ layermask,
1690
+ net,
1691
+ number,
1692
+ holeRadius,
1693
+ points,
1694
+ rotation: rotation2,
1695
+ plated: rest.includes("Y")
1696
+ };
1697
+ const pad = PadSchema.parse(padInputParams);
1698
+ return pad;
1699
+ }
1700
+ case "ARC": {
1701
+ const [width, layer, , arcData] = shape.data.split("~");
1702
+ const [
1703
+ ,
1704
+ startX,
1705
+ startY,
1706
+ radiusX,
1707
+ radiusY,
1708
+ xAxisRotation,
1709
+ largeArcFlag,
1710
+ sweepFlag,
1711
+ endX,
1712
+ endY
1713
+ ] = arcData.match(
1714
+ /M\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)\s*A\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)\s*([\d.]+)\s*([01])\s*([01])\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)/
1715
+ );
1716
+ const start = [Number(startX), Number(startY)];
1717
+ const end = [Number(endX), Number(endY)];
1718
+ return ArcSchema.parse({
1719
+ type: "ARC",
1720
+ width: Number(width),
1721
+ layer: Number(layer),
1722
+ start,
1723
+ end,
1724
+ radiusX: Number(radiusX),
1725
+ radiusY: Number(radiusY),
1726
+ largeArc: largeArcFlag === "1",
1727
+ sweepDirection: sweepFlag === "1" ? "CW" : "CCW"
1728
+ });
1729
+ }
1730
+ case "CIRCLE": {
1731
+ const [centerX, centerY, radius, width, layer, id] = shape.data.split("~");
1732
+ const center = [Number(centerX), Number(centerY)];
1733
+ return CircleSchema.parse({
1734
+ type: "CIRCLE",
1735
+ center,
1736
+ radius: Number(radius),
1737
+ width: Number(width),
1738
+ layer: Number(layer),
1739
+ id
1740
+ });
1741
+ }
1742
+ case "HOLE": {
1743
+ const [centerX, centerY, radius, id] = shape.data.split("~");
1744
+ const center = [Number(centerX), Number(centerY)];
1745
+ return HoleSchema.parse({
1746
+ type: "HOLE",
1747
+ center,
1748
+ radius: Number(radius),
1749
+ id
1750
+ });
1751
+ }
1752
+ case "SOLIDREGION": {
1753
+ const [layermask, , pathData, fillStyle, id] = shape.data.split("~");
1754
+ const points = pathData.match(/[ML] ?(-?[\d.]+)[ ,](-?[\d.]+)/g)?.map((point2) => {
1755
+ const [, x, y] = point2.match(/[ML]? ?(-?[\d.]+)[ ,](-?[\d.]+)/) || [];
1756
+ return [Number(x), Number(y)];
1757
+ }) || [];
1758
+ return SolidRegionSchema.parse({
1759
+ type: "SOLIDREGION",
1760
+ layermask: Number(layermask),
1761
+ points,
1762
+ fillStyle,
1763
+ id
1764
+ });
1765
+ }
1766
+ case "SVGNODE": {
1767
+ const svgData = JSON.parse(shape.data);
1768
+ return SVGNodeSchema.parse({ type: "SVGNODE", svgData });
1769
+ }
1770
+ case "RECT": {
1771
+ const [x, y, width, height, lineWidth, id, rotation2, layer, fillStyle] = shape.data.split("~");
1772
+ return RectSchema.parse({
1773
+ type: "RECT",
1774
+ x,
1775
+ y,
1776
+ width,
1777
+ height,
1778
+ lineWidth: Number(lineWidth),
1779
+ id,
1780
+ rotation: rotation2 ? Number(rotation2) : void 0,
1781
+ layer: layer ? Number(layer) : void 0,
1782
+ fillStyle: fillStyle || void 0
1783
+ });
1784
+ }
1785
+ default:
1786
+ throw new Error(`Unknown shape type: ${shape.type}`);
1787
+ return BaseShapeSchema.parse({ type: shape.type });
1788
+ }
1789
+ }).pipe(PackageDetailShapeSchema);
1790
+ var ShapesArraySchema = z59.array(ShapeItemSchema);
1791
+
1765
1792
  // lib/schemas/single-letter-shape-schema.ts
1766
1793
  import { z as z60 } from "zod";
1767
1794
  var PointSchema2 = z60.object({
@@ -2299,4 +2326,4 @@ export {
2299
2326
  convertRawEasyEdaToTs,
2300
2327
  convertEasyEdaJsonToVariousFormats
2301
2328
  };
2302
- //# sourceMappingURL=chunk-PIHMKST6.js.map
2329
+ //# sourceMappingURL=chunk-RNEHSTL4.js.map