easyeda 0.0.31 → 0.0.33

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/cli/main.cjs DELETED
@@ -1,2377 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
-
30
- // cli/main.ts
31
- var import_commander = require("commander");
32
-
33
- // lib/fetch-easyeda-json.ts
34
- async function fetchEasyEDAComponent(jlcpcbPartNumber) {
35
- const searchUrl = "https://easyeda.com/api/components/search";
36
- const componentUrl = (uuid) => `https://easyeda.com/api/components/${uuid}?version=6.4.7&uuid=${uuid}&datastrid=`;
37
- const searchHeaders = {
38
- authority: "easyeda.com",
39
- pragma: "no-cache",
40
- "cache-control": "no-cache",
41
- accept: "application/json, text/javascript, */*; q=0.01",
42
- "x-requested-with": "XMLHttpRequest",
43
- "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
44
- "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
45
- origin: "https://easyeda.com",
46
- "sec-fetch-site": "same-origin",
47
- "sec-fetch-mode": "cors",
48
- "sec-fetch-dest": "empty",
49
- referer: "https://easyeda.com/editor",
50
- "accept-language": "cs,en;q=0.9,sk;q=0.8,en-GB;q=0.7",
51
- cookie: "<PUT your cookies here>"
52
- };
53
- const searchData = `type=3&doctype%5B%5D=2&uid=0819f05c4eef4c71ace90d822a990e87&returnListStyle=classifyarr&wd=${jlcpcbPartNumber}&version=6.4.7`;
54
- const searchResponse = await fetch(searchUrl, {
55
- method: "POST",
56
- headers: searchHeaders,
57
- body: searchData
58
- });
59
- if (!searchResponse.ok) {
60
- throw new Error("Failed to search for the component");
61
- }
62
- const searchResult = await searchResponse.json();
63
- if (!searchResult.success || !searchResult.result.lists.lcsc.length) {
64
- throw new Error("Component not found");
65
- }
66
- const componentUUID = searchResult.result.lists.lcsc[0].uuid;
67
- const componentResponse = await fetch(componentUrl(componentUUID), {
68
- method: "GET",
69
- headers: {
70
- ...searchHeaders,
71
- referer: `https://easyeda.com/editor?uuid=${componentUUID}`
72
- }
73
- });
74
- if (!componentResponse.ok) {
75
- throw new Error("Failed to fetch the component details");
76
- }
77
- const componentResult = await componentResponse.json();
78
- return componentResult.result;
79
- }
80
-
81
- // lib/schemas/package-detail-shape-schema.ts
82
- var import_zod = require("zod");
83
- var tenthmil = import_zod.z.union([import_zod.z.number(), import_zod.z.string()]).optional().transform(
84
- (n) => typeof n === "string" && n.endsWith("mil") ? n : `${Number.parseFloat(n) * 10}mil`
85
- ).pipe(import_zod.z.string());
86
- var PointSchema = import_zod.z.any().transform((p) => {
87
- if (Array.isArray(p)) {
88
- const [x, y] = p;
89
- return { x, y };
90
- } else if (typeof p === "object") {
91
- return p;
92
- }
93
- throw new Error(`Invalid point: ${p}`);
94
- }).pipe(
95
- import_zod.z.object({
96
- x: import_zod.z.number(),
97
- y: import_zod.z.number()
98
- })
99
- );
100
- var BaseShapeSchema = import_zod.z.object({
101
- type: import_zod.z.string(),
102
- id: import_zod.z.string().optional(),
103
- layer: import_zod.z.coerce.number().optional()
104
- });
105
- var TrackSchema = BaseShapeSchema.extend({
106
- type: import_zod.z.literal("TRACK"),
107
- width: import_zod.z.coerce.number(),
108
- points: import_zod.z.array(PointSchema)
109
- });
110
- var PadSchema = BaseShapeSchema.extend({
111
- type: import_zod.z.literal("PAD"),
112
- shape: import_zod.z.enum(["RECT", "ELLIPSE", "OVAL"]),
113
- center: import_zod.z.object({
114
- x: tenthmil,
115
- y: tenthmil
116
- }),
117
- width: tenthmil,
118
- height: tenthmil,
119
- layermask: import_zod.z.number(),
120
- net: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]).optional(),
121
- number: import_zod.z.number(),
122
- holeRadius: tenthmil,
123
- points: import_zod.z.array(PointSchema).optional(),
124
- rotation: import_zod.z.number().optional(),
125
- plated: import_zod.z.boolean()
126
- });
127
- var ArcSchema = BaseShapeSchema.extend({
128
- type: import_zod.z.literal("ARC"),
129
- width: import_zod.z.number(),
130
- start: PointSchema,
131
- end: PointSchema,
132
- radiusX: import_zod.z.number(),
133
- radiusY: import_zod.z.number(),
134
- largeArc: import_zod.z.boolean(),
135
- sweepDirection: import_zod.z.enum(["CW", "CCW"])
136
- });
137
- var CircleSchema = BaseShapeSchema.extend({
138
- type: import_zod.z.literal("CIRCLE"),
139
- center: PointSchema,
140
- radius: import_zod.z.number(),
141
- width: import_zod.z.number()
142
- });
143
- var SolidRegionSchema = BaseShapeSchema.extend({
144
- type: import_zod.z.literal("SOLIDREGION"),
145
- layermask: import_zod.z.number(),
146
- points: import_zod.z.array(PointSchema),
147
- fillStyle: import_zod.z.string()
148
- });
149
- var SVGNodeSchema = BaseShapeSchema.extend({
150
- type: import_zod.z.literal("SVGNODE"),
151
- svgData: import_zod.z.object({
152
- gId: import_zod.z.string(),
153
- nodeName: import_zod.z.string(),
154
- nodeType: import_zod.z.number(),
155
- layerid: import_zod.z.string(),
156
- attrs: import_zod.z.record(import_zod.z.string(), import_zod.z.string()),
157
- childNodes: import_zod.z.array(import_zod.z.unknown())
158
- })
159
- });
160
- var HoleSchema = BaseShapeSchema.extend({
161
- type: import_zod.z.literal("HOLE"),
162
- center: PointSchema,
163
- radius: import_zod.z.number()
164
- });
165
- var RectSchema = BaseShapeSchema.extend({
166
- type: import_zod.z.literal("RECT"),
167
- x: tenthmil,
168
- y: tenthmil,
169
- width: tenthmil,
170
- height: tenthmil,
171
- lineWidth: import_zod.z.number(),
172
- fillStyle: import_zod.z.string(),
173
- rotation: import_zod.z.number().optional()
174
- });
175
- var PackageDetailShapeSchema = import_zod.z.discriminatedUnion("type", [
176
- TrackSchema,
177
- PadSchema,
178
- ArcSchema,
179
- CircleSchema,
180
- SolidRegionSchema,
181
- SVGNodeSchema,
182
- HoleSchema,
183
- RectSchema
184
- ]);
185
- var pairs = (arr) => {
186
- const pairs2 = [];
187
- for (let i = 0; i < arr.length; i += 2) {
188
- pairs2.push([arr[i], arr[i + 1]]);
189
- }
190
- return pairs2;
191
- };
192
- var parsePoints = (pointsStr) => pairs(
193
- pointsStr.trim().split(" ").map((n) => Number(n))
194
- );
195
- var ShapeItemSchema = import_zod.z.object({
196
- type: import_zod.z.string(),
197
- data: import_zod.z.string()
198
- }).transform((shape) => {
199
- const [firstParam, ...restParams] = shape.data.split("~");
200
- const lastParam = restParams.pop();
201
- switch (shape.type) {
202
- case "TRACK": {
203
- const [width, layer, _, pointsStr, id, _n] = shape.data.split("~");
204
- const points = parsePoints(pointsStr);
205
- return TrackSchema.parse({ type: "TRACK", width, layer, points, id });
206
- }
207
- case "PAD": {
208
- const [padShape, ...params] = shape.data.split("~");
209
- const [
210
- centerX,
211
- centerY,
212
- width,
213
- height,
214
- layermask,
215
- net,
216
- number,
217
- holeRadius,
218
- ...rest
219
- ] = params.map((p) => isNaN(Number(p)) ? p : Number(p));
220
- const center = { x: centerX, y: centerY };
221
- let points, rotation2;
222
- if (padShape === "RECT") {
223
- points = parsePoints(rest[0]);
224
- rotation2 = Number(rest[1]);
225
- }
226
- const padInputParams = {
227
- type: "PAD",
228
- shape: padShape,
229
- center,
230
- width,
231
- height,
232
- layermask,
233
- net,
234
- number,
235
- holeRadius,
236
- points,
237
- rotation: rotation2,
238
- plated: rest.includes("Y")
239
- };
240
- const pad = PadSchema.parse(padInputParams);
241
- return pad;
242
- }
243
- case "ARC": {
244
- const [width, layer, , arcData] = shape.data.split("~");
245
- const [
246
- ,
247
- startX,
248
- startY,
249
- radiusX,
250
- radiusY,
251
- xAxisRotation,
252
- largeArcFlag,
253
- sweepFlag,
254
- endX,
255
- endY
256
- ] = arcData.match(
257
- /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.]+)/
258
- );
259
- const start = [Number(startX), Number(startY)];
260
- const end = [Number(endX), Number(endY)];
261
- return ArcSchema.parse({
262
- type: "ARC",
263
- width: Number(width),
264
- layer: Number(layer),
265
- start,
266
- end,
267
- radiusX: Number(radiusX),
268
- radiusY: Number(radiusY),
269
- largeArc: largeArcFlag === "1",
270
- sweepDirection: sweepFlag === "1" ? "CW" : "CCW"
271
- });
272
- }
273
- case "CIRCLE": {
274
- const [centerX, centerY, radius, width, layer, id] = shape.data.split("~");
275
- const center = [Number(centerX), Number(centerY)];
276
- return CircleSchema.parse({
277
- type: "CIRCLE",
278
- center,
279
- radius: Number(radius),
280
- width: Number(width),
281
- layer: Number(layer),
282
- id
283
- });
284
- }
285
- case "HOLE": {
286
- const [centerX, centerY, radius, id] = shape.data.split("~");
287
- const center = [Number(centerX), Number(centerY)];
288
- return HoleSchema.parse({
289
- type: "HOLE",
290
- center,
291
- radius: Number(radius),
292
- id
293
- });
294
- }
295
- case "SOLIDREGION": {
296
- const [layermask, , pathData, fillStyle, id] = shape.data.split("~");
297
- const points = pathData.match(/[ML] ?(-?[\d.]+)[ ,](-?[\d.]+)/g)?.map((point2) => {
298
- const [, x, y] = point2.match(/[ML]? ?(-?[\d.]+)[ ,](-?[\d.]+)/) || [];
299
- return [Number(x), Number(y)];
300
- }) || [];
301
- return SolidRegionSchema.parse({
302
- type: "SOLIDREGION",
303
- layermask: Number(layermask),
304
- points,
305
- fillStyle,
306
- id
307
- });
308
- }
309
- case "SVGNODE": {
310
- const svgData = JSON.parse(shape.data);
311
- return SVGNodeSchema.parse({ type: "SVGNODE", svgData });
312
- }
313
- case "RECT": {
314
- const [x, y, width, height, lineWidth, id, rotation2, layer, fillStyle] = shape.data.split("~");
315
- return RectSchema.parse({
316
- type: "RECT",
317
- x,
318
- y,
319
- width,
320
- height,
321
- lineWidth: Number(lineWidth),
322
- id,
323
- rotation: rotation2 ? Number(rotation2) : void 0,
324
- layer: layer ? Number(layer) : void 0,
325
- fillStyle: fillStyle || void 0
326
- });
327
- }
328
- default:
329
- throw new Error(`Unknown shape type: ${shape.type}`);
330
- return BaseShapeSchema.parse({ type: shape.type });
331
- }
332
- }).pipe(PackageDetailShapeSchema);
333
- var ShapesArraySchema = import_zod.z.array(ShapeItemSchema);
334
-
335
- // lib/convert-easyeda-json-to-tscircuit-soup-json.ts
336
- var import_zod60 = require("zod");
337
-
338
- // node_modules/circuit-json/dist/index.mjs
339
- var dist_exports = {};
340
- __export(dist_exports, {
341
- all_layers: () => all_layers,
342
- any_circuit_element: () => any_circuit_element,
343
- any_soup_element: () => any_soup_element,
344
- any_source_component: () => any_source_component,
345
- cad_component: () => cad_component,
346
- capacitance: () => capacitance,
347
- current: () => current,
348
- distance: () => distance,
349
- getZodPrefixedIdWithDefault: () => getZodPrefixedIdWithDefault,
350
- inductance: () => inductance,
351
- layer_ref: () => layer_ref,
352
- layer_string: () => layer_string,
353
- length: () => length,
354
- pcb_board: () => pcb_board,
355
- pcb_component: () => pcb_component,
356
- pcb_fabrication_note_path: () => pcb_fabrication_note_path,
357
- pcb_fabrication_note_text: () => pcb_fabrication_note_text,
358
- pcb_hole: () => pcb_hole,
359
- pcb_hole_circle_or_square_shape: () => pcb_hole_circle_or_square_shape,
360
- pcb_hole_oval_shape: () => pcb_hole_oval_shape,
361
- pcb_keepout: () => pcb_keepout,
362
- pcb_placement_error: () => pcb_placement_error,
363
- pcb_plated_hole: () => pcb_plated_hole,
364
- pcb_port: () => pcb_port,
365
- pcb_port_not_matched_error: () => pcb_port_not_matched_error,
366
- pcb_route_hint: () => pcb_route_hint,
367
- pcb_route_hints: () => pcb_route_hints,
368
- pcb_silkscreen_circle: () => pcb_silkscreen_circle,
369
- pcb_silkscreen_line: () => pcb_silkscreen_line,
370
- pcb_silkscreen_oval: () => pcb_silkscreen_oval,
371
- pcb_silkscreen_path: () => pcb_silkscreen_path,
372
- pcb_silkscreen_rect: () => pcb_silkscreen_rect,
373
- pcb_silkscreen_text: () => pcb_silkscreen_text,
374
- pcb_smtpad: () => pcb_smtpad,
375
- pcb_solder_paste: () => pcb_solder_paste,
376
- pcb_text: () => pcb_text,
377
- pcb_trace: () => pcb_trace,
378
- pcb_trace_error: () => pcb_trace_error,
379
- pcb_trace_hint: () => pcb_trace_hint,
380
- pcb_trace_route_point: () => pcb_trace_route_point,
381
- pcb_trace_route_point_via: () => pcb_trace_route_point_via,
382
- pcb_trace_route_point_wire: () => pcb_trace_route_point_wire,
383
- pcb_via: () => pcb_via,
384
- point: () => point,
385
- point3: () => point3,
386
- position: () => position,
387
- position3: () => position3,
388
- resistance: () => resistance,
389
- rotation: () => rotation,
390
- route_hint_point: () => route_hint_point,
391
- schematic_box: () => schematic_box,
392
- schematic_component: () => schematic_component,
393
- schematic_error: () => schematic_error,
394
- schematic_line: () => schematic_line,
395
- schematic_net_label: () => schematic_net_label,
396
- schematic_path: () => schematic_path,
397
- schematic_pin_styles: () => schematic_pin_styles,
398
- schematic_port: () => schematic_port,
399
- schematic_text: () => schematic_text,
400
- schematic_trace: () => schematic_trace,
401
- size: () => size,
402
- source_component_base: () => source_component_base,
403
- source_group: () => source_group,
404
- source_led: () => source_led,
405
- source_net: () => source_net,
406
- source_port: () => source_port,
407
- source_simple_bug: () => source_simple_bug,
408
- source_simple_capacitor: () => source_simple_capacitor,
409
- source_simple_chip: () => source_simple_chip,
410
- source_simple_diode: () => source_simple_diode,
411
- source_simple_ground: () => source_simple_ground,
412
- source_simple_power_source: () => source_simple_power_source,
413
- source_simple_resistor: () => source_simple_resistor,
414
- source_trace: () => source_trace,
415
- supplier_name: () => supplier_name,
416
- time: () => time,
417
- visible_layer: () => visible_layer,
418
- voltage: () => voltage
419
- });
420
- var import_zod2 = require("zod");
421
- var import_zod3 = require("zod");
422
- var import_zod4 = require("zod");
423
- var import_zod5 = require("zod");
424
- var import_zod6 = require("zod");
425
-
426
- // node_modules/nanoid/index.js
427
- var import_node_crypto = require("crypto");
428
-
429
- // node_modules/nanoid/url-alphabet/index.js
430
- var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
431
-
432
- // node_modules/nanoid/index.js
433
- var POOL_SIZE_MULTIPLIER = 128;
434
- var pool;
435
- var poolOffset;
436
- function fillPool(bytes) {
437
- if (!pool || pool.length < bytes) {
438
- pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
439
- import_node_crypto.webcrypto.getRandomValues(pool);
440
- poolOffset = 0;
441
- } else if (poolOffset + bytes > pool.length) {
442
- import_node_crypto.webcrypto.getRandomValues(pool);
443
- poolOffset = 0;
444
- }
445
- poolOffset += bytes;
446
- }
447
- function nanoid(size2 = 21) {
448
- fillPool(size2 -= 0);
449
- let id = "";
450
- for (let i = poolOffset - size2; i < poolOffset; i++) {
451
- id += urlAlphabet[pool[i] & 63];
452
- }
453
- return id;
454
- }
455
-
456
- // node_modules/circuit-json/dist/index.mjs
457
- var import_zod7 = require("zod");
458
- var import_zod8 = require("zod");
459
- var import_zod9 = require("zod");
460
- var import_zod10 = require("zod");
461
- var import_zod11 = require("zod");
462
- var import_zod12 = require("zod");
463
- var import_zod13 = require("zod");
464
- var import_zod14 = require("zod");
465
- var import_zod15 = require("zod");
466
- var import_zod16 = require("zod");
467
- var import_zod17 = require("zod");
468
- var import_zod18 = require("zod");
469
- var import_zod19 = require("zod");
470
- var import_zod20 = require("zod");
471
- var import_zod21 = require("zod");
472
- var import_zod22 = require("zod");
473
- var import_zod23 = require("zod");
474
- var import_zod24 = require("zod");
475
- var import_zod25 = require("zod");
476
- var import_zod26 = require("zod");
477
- var import_zod27 = require("zod");
478
- var import_zod28 = require("zod");
479
- var import_zod29 = require("zod");
480
- var import_zod30 = require("zod");
481
- var import_zod31 = require("zod");
482
- var import_zod32 = require("zod");
483
- var import_zod33 = require("zod");
484
- var import_zod34 = require("zod");
485
- var import_zod35 = require("zod");
486
- var import_zod36 = require("zod");
487
- var import_zod37 = require("zod");
488
- var import_zod38 = require("zod");
489
- var import_zod39 = require("zod");
490
- var import_zod40 = require("zod");
491
- var import_zod41 = require("zod");
492
- var import_zod42 = require("zod");
493
- var import_zod43 = require("zod");
494
- var import_zod44 = require("zod");
495
- var import_zod45 = require("zod");
496
- var import_zod46 = require("zod");
497
- var import_zod47 = require("zod");
498
- var import_zod48 = require("zod");
499
- var import_zod49 = require("zod");
500
- var import_zod50 = require("zod");
501
- var import_zod51 = require("zod");
502
- var import_zod52 = require("zod");
503
- var import_zod53 = require("zod");
504
- var import_zod54 = require("zod");
505
- var import_zod55 = require("zod");
506
- var import_zod56 = require("zod");
507
- var import_zod57 = require("zod");
508
- var import_zod58 = require("zod");
509
- var import_zod59 = require("zod");
510
- var unitMappings = {
511
- Hz: {
512
- baseUnit: "Hz",
513
- variants: {
514
- MHz: 1e6,
515
- kHz: 1e3,
516
- Hz: 1
517
- }
518
- },
519
- g: {
520
- baseUnit: "g",
521
- variants: {
522
- kg: 1e3,
523
- g: 1
524
- }
525
- },
526
- \u03A9: {
527
- baseUnit: "\u03A9",
528
- variants: {
529
- m\u03A9: 1e-3,
530
- \u03A9: 1,
531
- k\u03A9: 1e3,
532
- M\u03A9: 1e6,
533
- G\u03A9: 1e9,
534
- T\u03A9: 1e12
535
- }
536
- },
537
- V: {
538
- baseUnit: "V",
539
- variants: {
540
- mV: 1e-3,
541
- V: 1,
542
- kV: 1e3,
543
- MV: 1e6,
544
- GV: 1e9,
545
- TV: 1e12
546
- }
547
- },
548
- A: {
549
- baseUnit: "A",
550
- variants: {
551
- \u00B5A: 1e-6,
552
- mA: 1e-3,
553
- ma: 1e-3,
554
- A: 1,
555
- kA: 1e3,
556
- MA: 1e6
557
- }
558
- },
559
- F: {
560
- baseUnit: "F",
561
- variants: {
562
- pF: 1e-12,
563
- nF: 1e-9,
564
- \u00B5F: 1e-6,
565
- mF: 1e-3,
566
- F: 1
567
- }
568
- },
569
- ml: {
570
- baseUnit: "ml",
571
- variants: {
572
- ml: 1,
573
- mL: 1,
574
- l: 1e3,
575
- L: 1e3
576
- }
577
- },
578
- deg: {
579
- baseUnit: "deg",
580
- variants: {
581
- rad: 180 / Math.PI
582
- }
583
- },
584
- ms: {
585
- baseUnit: "ms",
586
- variants: {
587
- s: 1e3
588
- }
589
- },
590
- mm: {
591
- baseUnit: "mm",
592
- variants: {
593
- nm: 1e-6,
594
- \u00B5m: 1e-3,
595
- um: 1e-3,
596
- mm: 1,
597
- cm: 10,
598
- dm: 100,
599
- m: 1e3,
600
- km: 1e6,
601
- in: 25.4,
602
- ft: 304.8,
603
- IN: 25.4,
604
- FT: 304.8,
605
- yd: 914.4,
606
- mi: 1609344
607
- }
608
- }
609
- };
610
- function getBaseTscircuitUnit(unit) {
611
- for (const [baseUnit, info] of Object.entries(unitMappings)) {
612
- if (unit in info.variants) {
613
- return {
614
- baseUnit: info.baseUnit,
615
- conversionFactor: info.variants[unit]
616
- };
617
- }
618
- }
619
- return {
620
- baseUnit: unit,
621
- conversionFactor: 1
622
- };
623
- }
624
- var parseAndConvertSiUnit = (v) => {
625
- if (typeof v === "undefined")
626
- return { parsedUnit: null, unitOfValue: null, value: null };
627
- if (typeof v === "string" && v.match(/^[\d\.]+$/))
628
- return {
629
- value: Number.parseFloat(v),
630
- parsedUnit: null,
631
- unitOfValue: null
632
- };
633
- if (typeof v === "number")
634
- return { value: v, parsedUnit: null, unitOfValue: null };
635
- if (typeof v === "object" && "x" in v && "y" in v) {
636
- const { parsedUnit, unitOfValue } = parseAndConvertSiUnit(v.x);
637
- return {
638
- parsedUnit,
639
- unitOfValue,
640
- value: {
641
- x: parseAndConvertSiUnit(v.x).value,
642
- y: parseAndConvertSiUnit(v.y).value
643
- }
644
- };
645
- }
646
- const unit_reversed = v.split("").reverse().join("").match(/[a-zA-Z]+/)?.[0];
647
- if (!unit_reversed) {
648
- throw new Error(`Could not determine unit: "${v}"`);
649
- }
650
- const unit = unit_reversed.split("").reverse().join("");
651
- const value = v.slice(0, -unit.length);
652
- const { baseUnit, conversionFactor } = getBaseTscircuitUnit(unit);
653
- return {
654
- parsedUnit: unit,
655
- unitOfValue: baseUnit,
656
- value: conversionFactor * Number.parseFloat(value)
657
- };
658
- };
659
- var resistance = import_zod2.z.string().or(import_zod2.z.number()).transform((v) => parseAndConvertSiUnit(v).value);
660
- var capacitance = import_zod2.z.string().or(import_zod2.z.number()).transform((v) => parseAndConvertSiUnit(v).value);
661
- var inductance = import_zod2.z.string().or(import_zod2.z.number()).transform((v) => parseAndConvertSiUnit(v).value);
662
- var voltage = import_zod2.z.string().or(import_zod2.z.number()).transform((v) => parseAndConvertSiUnit(v).value);
663
- var length = import_zod2.z.string().or(import_zod2.z.number()).transform((v) => parseAndConvertSiUnit(v).value);
664
- var distance = length;
665
- var current = import_zod2.z.string().or(import_zod2.z.number()).transform((v) => parseAndConvertSiUnit(v).value);
666
- var time = import_zod2.z.string().or(import_zod2.z.number()).transform((v) => parseAndConvertSiUnit(v).value);
667
- var rotation = import_zod2.z.string().or(import_zod2.z.number()).transform((arg) => {
668
- if (typeof arg === "number") return arg;
669
- if (arg.endsWith("deg")) {
670
- return Number.parseFloat(arg.split("deg")[0]);
671
- }
672
- if (arg.endsWith("rad")) {
673
- return Number.parseFloat(arg.split("rad")[0]) * 180 / Math.PI;
674
- }
675
- return Number.parseFloat(arg);
676
- });
677
- var point = import_zod3.z.object({
678
- x: distance,
679
- y: distance
680
- });
681
- var position = point;
682
- var point3 = import_zod4.z.object({
683
- x: distance,
684
- y: distance,
685
- z: distance
686
- });
687
- var position3 = point3;
688
- var size = import_zod5.z.object({
689
- width: import_zod5.z.number(),
690
- height: import_zod5.z.number()
691
- });
692
- var getZodPrefixedIdWithDefault = (prefix) => {
693
- return import_zod6.z.string().optional().default(() => `${prefix}_${nanoid(10)}`);
694
- };
695
- var supplier_name = import_zod8.z.enum([
696
- "jlcpcb",
697
- "macrofab",
698
- "pcbway",
699
- "digikey",
700
- "mouser",
701
- "lcsc"
702
- ]);
703
- var source_component_base = import_zod9.z.object({
704
- type: import_zod9.z.literal("source_component"),
705
- ftype: import_zod9.z.string().optional(),
706
- source_component_id: import_zod9.z.string(),
707
- name: import_zod9.z.string(),
708
- manufacturer_part_number: import_zod9.z.string().optional(),
709
- supplier_part_numbers: import_zod9.z.record(supplier_name, import_zod9.z.array(import_zod9.z.string())).optional()
710
- });
711
- var source_simple_capacitor = source_component_base.extend({
712
- ftype: import_zod7.z.literal("simple_capacitor"),
713
- capacitance
714
- });
715
- var source_simple_resistor = source_component_base.extend({
716
- ftype: import_zod10.z.literal("simple_resistor"),
717
- resistance
718
- });
719
- var source_simple_diode = source_component_base.extend({
720
- ftype: import_zod11.z.literal("simple_diode")
721
- });
722
- var source_simple_ground = source_component_base.extend({
723
- ftype: import_zod12.z.literal("simple_ground")
724
- });
725
- var source_simple_bug = source_component_base.extend({
726
- ftype: import_zod13.z.literal("simple_bug")
727
- }).describe("@deprecated");
728
- var source_simple_chip = source_component_base.extend({
729
- ftype: import_zod14.z.literal("simple_chip")
730
- });
731
- var source_simple_inductor = source_component_base.extend({
732
- ftype: import_zod15.z.literal("simple_inductor"),
733
- inductance
734
- });
735
- var source_led = source_simple_diode.extend({
736
- ftype: import_zod16.z.literal("led")
737
- });
738
- var source_simple_power_source = source_component_base.extend({
739
- ftype: import_zod17.z.literal("simple_power_source"),
740
- voltage
741
- });
742
- var any_source_component = import_zod18.z.union([
743
- source_simple_resistor,
744
- source_simple_capacitor,
745
- source_simple_diode,
746
- source_simple_ground,
747
- source_simple_chip,
748
- source_simple_bug,
749
- source_led,
750
- source_simple_power_source
751
- ]);
752
- var source_port = import_zod19.z.object({
753
- type: import_zod19.z.literal("source_port"),
754
- pin_number: import_zod19.z.number().optional(),
755
- port_hints: import_zod19.z.array(import_zod19.z.string()).optional(),
756
- name: import_zod19.z.string(),
757
- source_port_id: import_zod19.z.string(),
758
- source_component_id: import_zod19.z.string()
759
- });
760
- var source_trace = import_zod20.z.object({
761
- type: import_zod20.z.literal("source_trace"),
762
- source_trace_id: import_zod20.z.string(),
763
- connected_source_port_ids: import_zod20.z.array(import_zod20.z.string()),
764
- connected_source_net_ids: import_zod20.z.array(import_zod20.z.string())
765
- });
766
- var source_group = import_zod21.z.object({
767
- type: import_zod21.z.literal("source_group"),
768
- source_group_id: import_zod21.z.string(),
769
- name: import_zod21.z.string().optional()
770
- });
771
- var source_net = import_zod22.z.object({
772
- type: import_zod22.z.literal("source_net"),
773
- source_net_id: import_zod22.z.string(),
774
- name: import_zod22.z.string(),
775
- member_source_group_ids: import_zod22.z.array(import_zod22.z.string()),
776
- is_power: import_zod22.z.boolean().optional(),
777
- is_ground: import_zod22.z.boolean().optional(),
778
- is_digital_signal: import_zod22.z.boolean().optional(),
779
- is_analog_signal: import_zod22.z.boolean().optional(),
780
- trace_width: import_zod22.z.number().optional()
781
- });
782
- var schematic_box = import_zod23.z.object({
783
- type: import_zod23.z.literal("schematic_box"),
784
- schematic_component_id: import_zod23.z.string(),
785
- width: distance,
786
- height: distance,
787
- x: distance,
788
- y: distance
789
- }).describe("Draws a box on the schematic");
790
- var schematic_path = import_zod24.z.object({
791
- type: import_zod24.z.literal("schematic_path"),
792
- schematic_component_id: import_zod24.z.string(),
793
- fill_color: import_zod24.z.enum(["red", "blue"]).optional(),
794
- is_filled: import_zod24.z.boolean().optional(),
795
- points: import_zod24.z.array(point)
796
- });
797
- var schematic_pin_styles = import_zod25.z.record(
798
- import_zod25.z.object({
799
- left_margin: length.optional(),
800
- right_margin: length.optional(),
801
- top_margin: length.optional(),
802
- bottom_margin: length.optional()
803
- })
804
- );
805
- var schematic_component = import_zod25.z.object({
806
- type: import_zod25.z.literal("schematic_component"),
807
- rotation: rotation.default(0),
808
- size,
809
- center: point,
810
- source_component_id: import_zod25.z.string(),
811
- schematic_component_id: import_zod25.z.string(),
812
- pin_spacing: length.optional(),
813
- pin_styles: schematic_pin_styles.optional(),
814
- box_width: length.optional(),
815
- symbol_name: import_zod25.z.string().optional(),
816
- port_arrangement: import_zod25.z.union([
817
- import_zod25.z.object({
818
- left_size: import_zod25.z.number(),
819
- right_size: import_zod25.z.number(),
820
- top_size: import_zod25.z.number().optional(),
821
- bottom_size: import_zod25.z.number().optional()
822
- }),
823
- import_zod25.z.object({
824
- left_side: import_zod25.z.object({
825
- pins: import_zod25.z.array(import_zod25.z.number()),
826
- direction: import_zod25.z.enum(["top-to-bottom", "bottom-to-top"]).optional()
827
- }).optional(),
828
- right_side: import_zod25.z.object({
829
- pins: import_zod25.z.array(import_zod25.z.number()),
830
- direction: import_zod25.z.enum(["top-to-bottom", "bottom-to-top"]).optional()
831
- }).optional(),
832
- top_side: import_zod25.z.object({
833
- pins: import_zod25.z.array(import_zod25.z.number()),
834
- direction: import_zod25.z.enum(["left-to-right", "right-to-left"]).optional()
835
- }).optional(),
836
- bottom_side: import_zod25.z.object({
837
- pins: import_zod25.z.array(import_zod25.z.number()),
838
- direction: import_zod25.z.enum(["left-to-right", "right-to-left"]).optional()
839
- }).optional()
840
- })
841
- ]).optional(),
842
- port_labels: import_zod25.z.record(import_zod25.z.string()).optional()
843
- });
844
- var schematic_line = import_zod26.z.object({
845
- type: import_zod26.z.literal("schematic_line"),
846
- schematic_component_id: import_zod26.z.string(),
847
- x1: distance,
848
- x2: distance,
849
- y1: distance,
850
- y2: distance
851
- });
852
- var schematic_trace = import_zod27.z.object({
853
- type: import_zod27.z.literal("schematic_trace"),
854
- schematic_trace_id: import_zod27.z.string(),
855
- source_trace_id: import_zod27.z.string(),
856
- edges: import_zod27.z.array(
857
- import_zod27.z.object({
858
- from: import_zod27.z.object({
859
- x: import_zod27.z.number(),
860
- y: import_zod27.z.number()
861
- }),
862
- to: import_zod27.z.object({
863
- x: import_zod27.z.number(),
864
- y: import_zod27.z.number()
865
- }),
866
- from_schematic_port_id: import_zod27.z.string().optional(),
867
- to_schematic_port_id: import_zod27.z.string().optional()
868
- })
869
- )
870
- });
871
- var schematic_text = import_zod28.z.object({
872
- type: import_zod28.z.literal("schematic_text"),
873
- schematic_component_id: import_zod28.z.string(),
874
- schematic_text_id: import_zod28.z.string(),
875
- text: import_zod28.z.string(),
876
- position: import_zod28.z.object({
877
- x: distance,
878
- y: distance
879
- }),
880
- rotation: import_zod28.z.number().default(0),
881
- anchor: import_zod28.z.enum(["center", "left", "right", "top", "bottom"]).default("center")
882
- });
883
- var schematic_port = import_zod29.z.object({
884
- type: import_zod29.z.literal("schematic_port"),
885
- schematic_port_id: import_zod29.z.string(),
886
- source_port_id: import_zod29.z.string(),
887
- schematic_component_id: import_zod29.z.string().optional(),
888
- center: point,
889
- facing_direction: import_zod29.z.enum(["up", "down", "left", "right"]).optional()
890
- }).describe("Defines a port on a schematic component");
891
- var schematic_net_label = import_zod30.z.object({
892
- type: import_zod30.z.literal("schematic_net_label"),
893
- source_net_id: import_zod30.z.string(),
894
- center: point,
895
- anchor_side: import_zod30.z.enum(["top", "bottom", "left", "right"]),
896
- text: import_zod30.z.string()
897
- });
898
- var schematic_error = import_zod31.z.object({
899
- schematic_error_id: import_zod31.z.string(),
900
- type: import_zod31.z.literal("schematic_error"),
901
- // eventually each error type should be broken out into a dir of files
902
- error_type: import_zod31.z.literal("schematic_port_not_found"),
903
- message: import_zod31.z.string()
904
- }).describe("Defines a schematic error on the schematic");
905
- var all_layers = [
906
- "top",
907
- "bottom",
908
- "inner1",
909
- "inner2",
910
- "inner3",
911
- "inner4",
912
- "inner5",
913
- "inner6"
914
- ];
915
- var layer_string = import_zod32.z.enum(all_layers);
916
- var layer_ref = layer_string.or(
917
- import_zod32.z.object({
918
- name: layer_string
919
- })
920
- ).transform((layer) => {
921
- if (typeof layer === "string") {
922
- return layer;
923
- }
924
- return layer.name;
925
- });
926
- var visible_layer = import_zod32.z.enum(["top", "bottom"]);
927
- var pcb_route_hint = import_zod33.z.object({
928
- x: distance,
929
- y: distance,
930
- via: import_zod33.z.boolean().optional(),
931
- via_to_layer: layer_ref.optional()
932
- });
933
- var pcb_route_hints = import_zod33.z.array(pcb_route_hint);
934
- var route_hint_point = import_zod34.z.object({
935
- x: distance,
936
- y: distance,
937
- via: import_zod34.z.boolean().optional(),
938
- to_layer: layer_ref.optional(),
939
- trace_width: distance.optional()
940
- });
941
- var expectTypesMatch = (shouldBe) => {
942
- };
943
- var pcb_component = import_zod35.z.object({
944
- type: import_zod35.z.literal("pcb_component"),
945
- pcb_component_id: getZodPrefixedIdWithDefault("pcb_component"),
946
- source_component_id: import_zod35.z.string(),
947
- center: point,
948
- layer: layer_ref,
949
- rotation,
950
- width: length,
951
- height: length
952
- }).describe("Defines a component on the PCB");
953
- expectTypesMatch(true);
954
- var pcb_hole_circle_or_square = import_zod36.z.object({
955
- type: import_zod36.z.literal("pcb_hole"),
956
- pcb_hole_id: getZodPrefixedIdWithDefault("pcb_hole"),
957
- hole_shape: import_zod36.z.enum(["circle", "square"]),
958
- hole_diameter: import_zod36.z.number(),
959
- x: distance,
960
- y: distance
961
- });
962
- var pcb_hole_circle_or_square_shape = pcb_hole_circle_or_square.describe(
963
- "Defines a circular or square hole on the PCB"
964
- );
965
- expectTypesMatch(true);
966
- var pcb_hole_oval = import_zod36.z.object({
967
- type: import_zod36.z.literal("pcb_hole"),
968
- pcb_hole_id: getZodPrefixedIdWithDefault("pcb_hole"),
969
- hole_shape: import_zod36.z.literal("oval"),
970
- hole_width: import_zod36.z.number(),
971
- hole_height: import_zod36.z.number(),
972
- x: distance,
973
- y: distance
974
- });
975
- var pcb_hole_oval_shape = pcb_hole_oval.describe(
976
- "Defines an oval hole on the PCB"
977
- );
978
- expectTypesMatch(true);
979
- var pcb_hole = pcb_hole_circle_or_square.or(pcb_hole_oval);
980
- var pcb_plated_hole_circle = import_zod37.z.object({
981
- type: import_zod37.z.literal("pcb_plated_hole"),
982
- shape: import_zod37.z.literal("circle"),
983
- outer_diameter: import_zod37.z.number(),
984
- hole_diameter: import_zod37.z.number(),
985
- x: distance,
986
- y: distance,
987
- layers: import_zod37.z.array(layer_ref),
988
- port_hints: import_zod37.z.array(import_zod37.z.string()).optional(),
989
- pcb_component_id: import_zod37.z.string().optional(),
990
- pcb_port_id: import_zod37.z.string().optional(),
991
- pcb_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole")
992
- });
993
- var pcb_plated_hole_oval = import_zod37.z.object({
994
- type: import_zod37.z.literal("pcb_plated_hole"),
995
- shape: import_zod37.z.enum(["oval", "pill"]),
996
- outer_width: import_zod37.z.number(),
997
- outer_height: import_zod37.z.number(),
998
- hole_width: import_zod37.z.number(),
999
- hole_height: import_zod37.z.number(),
1000
- x: distance,
1001
- y: distance,
1002
- layers: import_zod37.z.array(layer_ref),
1003
- port_hints: import_zod37.z.array(import_zod37.z.string()).optional(),
1004
- pcb_component_id: import_zod37.z.string().optional(),
1005
- pcb_port_id: import_zod37.z.string().optional(),
1006
- pcb_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole")
1007
- });
1008
- var pcb_plated_hole = import_zod37.z.union([
1009
- pcb_plated_hole_circle,
1010
- pcb_plated_hole_oval
1011
- ]);
1012
- expectTypesMatch(
1013
- true
1014
- );
1015
- expectTypesMatch(true);
1016
- var pcb_port = import_zod38.z.object({
1017
- type: import_zod38.z.literal("pcb_port"),
1018
- pcb_port_id: getZodPrefixedIdWithDefault("pcb_port"),
1019
- source_port_id: import_zod38.z.string(),
1020
- pcb_component_id: import_zod38.z.string(),
1021
- x: distance,
1022
- y: distance,
1023
- layers: import_zod38.z.array(layer_ref)
1024
- }).describe("Defines a port on the PCB");
1025
- expectTypesMatch(true);
1026
- var pcb_smtpad_circle = import_zod39.z.object({
1027
- type: import_zod39.z.literal("pcb_smtpad"),
1028
- shape: import_zod39.z.literal("circle"),
1029
- pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"),
1030
- x: distance,
1031
- y: distance,
1032
- radius: import_zod39.z.number(),
1033
- layer: layer_ref,
1034
- port_hints: import_zod39.z.array(import_zod39.z.string()).optional(),
1035
- pcb_component_id: import_zod39.z.string().optional(),
1036
- pcb_port_id: import_zod39.z.string().optional()
1037
- });
1038
- var pcb_smtpad_rect = import_zod39.z.object({
1039
- type: import_zod39.z.literal("pcb_smtpad"),
1040
- shape: import_zod39.z.literal("rect"),
1041
- pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"),
1042
- x: distance,
1043
- y: distance,
1044
- width: import_zod39.z.number(),
1045
- height: import_zod39.z.number(),
1046
- layer: layer_ref,
1047
- port_hints: import_zod39.z.array(import_zod39.z.string()).optional(),
1048
- pcb_component_id: import_zod39.z.string().optional(),
1049
- pcb_port_id: import_zod39.z.string().optional()
1050
- });
1051
- var pcb_smtpad = import_zod39.z.union([pcb_smtpad_circle, pcb_smtpad_rect]).describe("Defines an SMT pad on the PCB");
1052
- expectTypesMatch(true);
1053
- expectTypesMatch(true);
1054
- var pcb_solder_paste_circle = import_zod40.z.object({
1055
- type: import_zod40.z.literal("pcb_solder_paste"),
1056
- shape: import_zod40.z.literal("circle"),
1057
- pcb_solder_paste_id: getZodPrefixedIdWithDefault("pcb_solder_paste"),
1058
- x: distance,
1059
- y: distance,
1060
- radius: import_zod40.z.number(),
1061
- layer: layer_ref,
1062
- pcb_component_id: import_zod40.z.string().optional(),
1063
- pcb_smtpad_id: import_zod40.z.string().optional()
1064
- });
1065
- var pcb_solder_paste_rect = import_zod40.z.object({
1066
- type: import_zod40.z.literal("pcb_solder_paste"),
1067
- shape: import_zod40.z.literal("rect"),
1068
- pcb_solder_paste_id: getZodPrefixedIdWithDefault("pcb_solder_paste"),
1069
- x: distance,
1070
- y: distance,
1071
- width: import_zod40.z.number(),
1072
- height: import_zod40.z.number(),
1073
- layer: layer_ref,
1074
- pcb_component_id: import_zod40.z.string().optional(),
1075
- pcb_smtpad_id: import_zod40.z.string().optional()
1076
- });
1077
- var pcb_solder_paste = import_zod40.z.union([pcb_solder_paste_circle, pcb_solder_paste_rect]).describe("Defines solderpaste on the PCB");
1078
- expectTypesMatch(true);
1079
- expectTypesMatch(true);
1080
- var pcb_text = import_zod41.z.object({
1081
- type: import_zod41.z.literal("pcb_text"),
1082
- pcb_text_id: getZodPrefixedIdWithDefault("pcb_text"),
1083
- text: import_zod41.z.string(),
1084
- center: point,
1085
- layer: layer_ref,
1086
- width: length,
1087
- height: length,
1088
- lines: import_zod41.z.number(),
1089
- align: import_zod41.z.enum(["bottom-left"])
1090
- }).describe("Defines text on the PCB");
1091
- expectTypesMatch(true);
1092
- var pcb_trace_route_point_wire = import_zod42.z.object({
1093
- route_type: import_zod42.z.literal("wire"),
1094
- x: distance,
1095
- y: distance,
1096
- width: distance,
1097
- start_pcb_port_id: import_zod42.z.string().optional(),
1098
- end_pcb_port_id: import_zod42.z.string().optional(),
1099
- layer: layer_ref
1100
- });
1101
- var pcb_trace_route_point_via = import_zod42.z.object({
1102
- route_type: import_zod42.z.literal("via"),
1103
- x: distance,
1104
- y: distance,
1105
- from_layer: import_zod42.z.string(),
1106
- to_layer: import_zod42.z.string()
1107
- });
1108
- var pcb_trace_route_point = import_zod42.z.union([
1109
- pcb_trace_route_point_wire,
1110
- pcb_trace_route_point_via
1111
- ]);
1112
- var pcb_trace = import_zod42.z.object({
1113
- type: import_zod42.z.literal("pcb_trace"),
1114
- source_trace_id: import_zod42.z.string().optional(),
1115
- pcb_component_id: import_zod42.z.string().optional(),
1116
- pcb_trace_id: getZodPrefixedIdWithDefault("pcb_trace"),
1117
- route_thickness_mode: import_zod42.z.enum(["constant", "interpolated"]).default("constant").optional(),
1118
- route_order_index: import_zod42.z.number().optional(),
1119
- should_round_corners: import_zod42.z.boolean().optional(),
1120
- route: import_zod42.z.array(
1121
- import_zod42.z.union([
1122
- import_zod42.z.object({
1123
- route_type: import_zod42.z.literal("wire"),
1124
- x: distance,
1125
- y: distance,
1126
- width: distance,
1127
- start_pcb_port_id: import_zod42.z.string().optional(),
1128
- end_pcb_port_id: import_zod42.z.string().optional(),
1129
- layer: layer_ref
1130
- }),
1131
- import_zod42.z.object({
1132
- route_type: import_zod42.z.literal("via"),
1133
- x: distance,
1134
- y: distance,
1135
- from_layer: import_zod42.z.string(),
1136
- to_layer: import_zod42.z.string()
1137
- })
1138
- ])
1139
- )
1140
- }).describe("Defines a trace on the PCB");
1141
- expectTypesMatch(true);
1142
- expectTypesMatch(true);
1143
- var pcb_trace_error = import_zod43.z.object({
1144
- type: import_zod43.z.literal("pcb_trace_error"),
1145
- pcb_trace_error_id: getZodPrefixedIdWithDefault("pcb_trace_error"),
1146
- error_type: import_zod43.z.literal("pcb_trace_error"),
1147
- message: import_zod43.z.string(),
1148
- center: point.optional(),
1149
- pcb_trace_id: import_zod43.z.string(),
1150
- source_trace_id: import_zod43.z.string(),
1151
- pcb_component_ids: import_zod43.z.array(import_zod43.z.string()),
1152
- pcb_port_ids: import_zod43.z.array(import_zod43.z.string())
1153
- }).describe("Defines a trace error on the PCB");
1154
- expectTypesMatch(true);
1155
- var pcb_port_not_matched_error = import_zod44.z.object({
1156
- type: import_zod44.z.literal("pcb_port_not_matched_error"),
1157
- pcb_error_id: getZodPrefixedIdWithDefault("pcb_error"),
1158
- message: import_zod44.z.string(),
1159
- pcb_component_ids: import_zod44.z.array(import_zod44.z.string())
1160
- }).describe("Defines a trace error on the PCB where a port is not matched");
1161
- expectTypesMatch(true);
1162
- var pcb_via = import_zod45.z.object({
1163
- type: import_zod45.z.literal("pcb_via"),
1164
- pcb_via_id: getZodPrefixedIdWithDefault("pcb_via"),
1165
- x: distance,
1166
- y: distance,
1167
- outer_diameter: distance.default("0.6mm"),
1168
- hole_diameter: distance.default("0.25mm"),
1169
- /** @deprecated */
1170
- from_layer: layer_ref.optional(),
1171
- /** @deprecated */
1172
- to_layer: layer_ref.optional(),
1173
- layers: import_zod45.z.array(layer_ref),
1174
- pcb_trace_id: import_zod45.z.string().optional()
1175
- }).describe("Defines a via on the PCB");
1176
- expectTypesMatch(true);
1177
- var pcb_board = import_zod46.z.object({
1178
- type: import_zod46.z.literal("pcb_board"),
1179
- pcb_board_id: getZodPrefixedIdWithDefault("pcb_board"),
1180
- width: length,
1181
- height: length,
1182
- center: point,
1183
- thickness: length.optional().default(1.4),
1184
- num_layers: import_zod46.z.number().optional().default(4),
1185
- outline: import_zod46.z.array(point).optional()
1186
- }).describe("Defines the board outline of the PCB");
1187
- expectTypesMatch(true);
1188
- var pcb_placement_error = import_zod47.z.object({
1189
- type: import_zod47.z.literal("pcb_placement_error"),
1190
- pcb_placement_error_id: getZodPrefixedIdWithDefault("pcb_placement_error"),
1191
- message: import_zod47.z.string()
1192
- }).describe("Defines a placement error on the PCB");
1193
- expectTypesMatch(true);
1194
- var pcb_trace_hint = import_zod48.z.object({
1195
- type: import_zod48.z.literal("pcb_trace_hint"),
1196
- pcb_trace_hint_id: getZodPrefixedIdWithDefault("pcb_trace_hint"),
1197
- pcb_port_id: import_zod48.z.string(),
1198
- pcb_component_id: import_zod48.z.string(),
1199
- route: import_zod48.z.array(route_hint_point)
1200
- }).describe("A hint that can be used during generation of a PCB trace");
1201
- expectTypesMatch(true);
1202
- var pcb_silkscreen_line = import_zod49.z.object({
1203
- type: import_zod49.z.literal("pcb_silkscreen_line"),
1204
- pcb_silkscreen_line_id: getZodPrefixedIdWithDefault("pcb_silkscreen_line"),
1205
- pcb_component_id: import_zod49.z.string(),
1206
- stroke_width: distance.default("0.1mm"),
1207
- x1: distance,
1208
- y1: distance,
1209
- x2: distance,
1210
- y2: distance,
1211
- layer: visible_layer
1212
- }).describe("Defines a silkscreen line on the PCB");
1213
- expectTypesMatch(true);
1214
- var pcb_silkscreen_path = import_zod50.z.object({
1215
- type: import_zod50.z.literal("pcb_silkscreen_path"),
1216
- pcb_silkscreen_path_id: getZodPrefixedIdWithDefault("pcb_silkscreen_path"),
1217
- pcb_component_id: import_zod50.z.string(),
1218
- layer: visible_layer,
1219
- route: import_zod50.z.array(point),
1220
- stroke_width: length
1221
- }).describe("Defines a silkscreen path on the PCB");
1222
- expectTypesMatch(true);
1223
- var pcb_silkscreen_text = import_zod51.z.object({
1224
- type: import_zod51.z.literal("pcb_silkscreen_text"),
1225
- pcb_silkscreen_text_id: getZodPrefixedIdWithDefault("pcb_silkscreen_text"),
1226
- font: import_zod51.z.literal("tscircuit2024").default("tscircuit2024"),
1227
- font_size: distance.default("0.2mm"),
1228
- pcb_component_id: import_zod51.z.string(),
1229
- text: import_zod51.z.string(),
1230
- layer: layer_ref,
1231
- is_mirrored: import_zod51.z.boolean().default(false).optional(),
1232
- anchor_position: point.default({ x: 0, y: 0 }),
1233
- anchor_alignment: import_zod51.z.enum(["center", "top_left", "top_right", "bottom_left", "bottom_right"]).default("center")
1234
- }).describe("Defines silkscreen text on the PCB");
1235
- expectTypesMatch(true);
1236
- var pcb_silkscreen_rect = import_zod52.z.object({
1237
- type: import_zod52.z.literal("pcb_silkscreen_rect"),
1238
- pcb_silkscreen_rect_id: getZodPrefixedIdWithDefault("pcb_silkscreen_rect"),
1239
- pcb_component_id: import_zod52.z.string(),
1240
- center: point,
1241
- width: length,
1242
- height: length,
1243
- layer: layer_ref
1244
- }).describe("Defines a silkscreen rect on the PCB");
1245
- expectTypesMatch(true);
1246
- var pcb_silkscreen_circle = import_zod53.z.object({
1247
- type: import_zod53.z.literal("pcb_silkscreen_circle"),
1248
- pcb_silkscreen_circle_id: getZodPrefixedIdWithDefault(
1249
- "pcb_silkscreen_circle"
1250
- ),
1251
- pcb_component_id: import_zod53.z.string(),
1252
- center: point,
1253
- radius: length,
1254
- layer: visible_layer
1255
- }).describe("Defines a silkscreen circle on the PCB");
1256
- expectTypesMatch(true);
1257
- var pcb_silkscreen_oval = import_zod54.z.object({
1258
- type: import_zod54.z.literal("pcb_silkscreen_oval"),
1259
- pcb_silkscreen_oval_id: getZodPrefixedIdWithDefault("pcb_silkscreen_oval"),
1260
- pcb_component_id: import_zod54.z.string(),
1261
- center: point,
1262
- radius_x: distance,
1263
- radius_y: distance,
1264
- layer: visible_layer
1265
- }).describe("Defines a silkscreen oval on the PCB");
1266
- expectTypesMatch(true);
1267
- var pcb_fabrication_note_text = import_zod55.z.object({
1268
- type: import_zod55.z.literal("pcb_fabrication_note_text"),
1269
- pcb_fabrication_note_text_id: getZodPrefixedIdWithDefault(
1270
- "pcb_fabrication_note_text"
1271
- ),
1272
- font: import_zod55.z.literal("tscircuit2024").default("tscircuit2024"),
1273
- font_size: distance.default("1mm"),
1274
- pcb_component_id: import_zod55.z.string(),
1275
- text: import_zod55.z.string(),
1276
- layer: visible_layer,
1277
- anchor_position: point.default({ x: 0, y: 0 }),
1278
- anchor_alignment: import_zod55.z.enum(["center", "top_left", "top_right", "bottom_left", "bottom_right"]).default("center"),
1279
- color: import_zod55.z.string().optional()
1280
- }).describe(
1281
- "Defines a fabrication note in text on the PCB, useful for leaving notes for assemblers or fabricators"
1282
- );
1283
- expectTypesMatch(true);
1284
- var pcb_fabrication_note_path = import_zod56.z.object({
1285
- type: import_zod56.z.literal("pcb_fabrication_note_path"),
1286
- pcb_fabrication_note_path_id: getZodPrefixedIdWithDefault(
1287
- "pcb_fabrication_note_path"
1288
- ),
1289
- pcb_component_id: import_zod56.z.string(),
1290
- layer: layer_ref,
1291
- route: import_zod56.z.array(point),
1292
- stroke_width: length,
1293
- color: import_zod56.z.string().optional()
1294
- }).describe(
1295
- "Defines a fabrication path on the PCB for fabricators or assemblers"
1296
- );
1297
- expectTypesMatch(true);
1298
- var pcb_keepout = import_zod57.z.object({
1299
- type: import_zod57.z.literal("pcb_keepout"),
1300
- shape: import_zod57.z.literal("rect"),
1301
- center: point,
1302
- width: distance,
1303
- height: distance,
1304
- pcb_keepout_id: import_zod57.z.string(),
1305
- layers: import_zod57.z.array(import_zod57.z.string()),
1306
- // Specify layers where the keepout applies
1307
- description: import_zod57.z.string().optional()
1308
- // Optional description of the keepout
1309
- }).or(
1310
- import_zod57.z.object({
1311
- type: import_zod57.z.literal("pcb_keepout"),
1312
- shape: import_zod57.z.literal("circle"),
1313
- center: point,
1314
- radius: distance,
1315
- pcb_keepout_id: import_zod57.z.string(),
1316
- layers: import_zod57.z.array(import_zod57.z.string()),
1317
- // Specify layers where the keepout applies
1318
- description: import_zod57.z.string().optional()
1319
- // Optional description of the keepout
1320
- })
1321
- );
1322
- var cad_component = import_zod58.z.object({
1323
- type: import_zod58.z.literal("cad_component"),
1324
- cad_component_id: import_zod58.z.string(),
1325
- pcb_component_id: import_zod58.z.string(),
1326
- source_component_id: import_zod58.z.string(),
1327
- position: point3,
1328
- rotation: point3.optional(),
1329
- size: point3.optional(),
1330
- layer: layer_ref.optional(),
1331
- // These are all ways to generate/load the 3d model
1332
- footprinter_string: import_zod58.z.string().optional(),
1333
- model_obj_url: import_zod58.z.string().optional(),
1334
- model_stl_url: import_zod58.z.string().optional(),
1335
- model_3mf_url: import_zod58.z.string().optional(),
1336
- model_jscad: import_zod58.z.any().optional()
1337
- }).describe("Defines a component on the PCB");
1338
- var any_circuit_element = import_zod59.z.union([
1339
- source_trace,
1340
- source_port,
1341
- any_source_component,
1342
- source_led,
1343
- source_net,
1344
- source_group,
1345
- source_simple_bug,
1346
- source_simple_chip,
1347
- source_simple_capacitor,
1348
- source_simple_diode,
1349
- source_simple_resistor,
1350
- source_simple_power_source,
1351
- pcb_component,
1352
- pcb_hole,
1353
- pcb_plated_hole,
1354
- pcb_keepout,
1355
- pcb_port,
1356
- pcb_text,
1357
- pcb_trace,
1358
- pcb_via,
1359
- pcb_smtpad,
1360
- pcb_solder_paste,
1361
- pcb_board,
1362
- pcb_trace_hint,
1363
- pcb_silkscreen_line,
1364
- pcb_silkscreen_path,
1365
- pcb_silkscreen_text,
1366
- pcb_silkscreen_rect,
1367
- pcb_silkscreen_circle,
1368
- pcb_silkscreen_oval,
1369
- pcb_trace_error,
1370
- pcb_placement_error,
1371
- pcb_port_not_matched_error,
1372
- pcb_fabrication_note_path,
1373
- pcb_fabrication_note_text,
1374
- schematic_box,
1375
- schematic_text,
1376
- schematic_line,
1377
- schematic_component,
1378
- schematic_port,
1379
- schematic_trace,
1380
- schematic_path,
1381
- schematic_error,
1382
- schematic_net_label,
1383
- cad_component
1384
- ]);
1385
- var any_soup_element = any_circuit_element;
1386
-
1387
- // lib/math/arc-utils.ts
1388
- function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag, sweepFlag) {
1389
- const start = { x: startX, y: startY };
1390
- const end = { x: endX, y: endY };
1391
- const midX = (startX + endX) / 2;
1392
- const midY = (startY + endY) / 2;
1393
- const dx = endX - startX;
1394
- const dy = endY - startY;
1395
- const distance2 = Math.sqrt(dx * dx + dy * dy);
1396
- if (distance2 === 0 || radius < distance2 / 2) {
1397
- return [start, end];
1398
- }
1399
- const h = Math.sqrt(radius * radius - distance2 * distance2 / 4);
1400
- const angle = Math.atan2(dy, dx);
1401
- const centerX = midX + h * Math.sin(angle) * (sweepFlag ? 1 : -1);
1402
- const centerY = midY - h * Math.cos(angle) * (sweepFlag ? 1 : -1);
1403
- const startAngle = Math.atan2(startY - centerY, startX - centerX);
1404
- let endAngle = Math.atan2(endY - centerY, endX - centerX);
1405
- if (!sweepFlag && endAngle > startAngle) {
1406
- endAngle -= 2 * Math.PI;
1407
- } else if (sweepFlag && endAngle < startAngle) {
1408
- endAngle += 2 * Math.PI;
1409
- }
1410
- if (!largeArcFlag && Math.abs(endAngle - startAngle) > Math.PI || largeArcFlag && Math.abs(endAngle - startAngle) < Math.PI) {
1411
- if (endAngle > startAngle) {
1412
- endAngle -= 2 * Math.PI;
1413
- } else {
1414
- endAngle += 2 * Math.PI;
1415
- }
1416
- }
1417
- const numPoints = Math.max(
1418
- 2,
1419
- Math.ceil(Math.abs(endAngle - startAngle) * radius)
1420
- );
1421
- const path2 = [];
1422
- for (let i = 0; i <= numPoints; i++) {
1423
- const t = i / numPoints;
1424
- const angle2 = startAngle + t * (endAngle - startAngle);
1425
- const x = centerX + radius * Math.cos(angle2);
1426
- const y = centerY + radius * Math.sin(angle2);
1427
- path2.push({ x, y });
1428
- }
1429
- return path2;
1430
- }
1431
-
1432
- // node_modules/@tscircuit/soup-util/dist/index.js
1433
- var import_transformation_matrix = require("transformation-matrix");
1434
- var su = (soup, options = {}) => {
1435
- let internalStore = soup._internal_store;
1436
- if (!internalStore) {
1437
- internalStore = {
1438
- counts: {}
1439
- };
1440
- soup._internal_store = internalStore;
1441
- for (const elm of soup) {
1442
- const type = elm.type;
1443
- const idVal = elm[`${type}_id`];
1444
- if (!idVal)
1445
- continue;
1446
- const idNum = Number.parseInt(idVal.split("_").pop());
1447
- if (!Number.isNaN(idNum)) {
1448
- internalStore.counts[type] = Math.max(
1449
- internalStore.counts[type] ?? 0,
1450
- idNum
1451
- );
1452
- }
1453
- }
1454
- }
1455
- const su22 = new Proxy(
1456
- {},
1457
- {
1458
- get: (proxy_target, component_type) => {
1459
- if (component_type === "toArray") {
1460
- return () => soup;
1461
- }
1462
- return {
1463
- get: (id) => soup.find(
1464
- (e) => e.type === component_type && e[`${component_type}_id`] === id
1465
- ),
1466
- getUsing: (using) => {
1467
- const keys = Object.keys(using);
1468
- if (keys.length !== 1) {
1469
- throw new Error(
1470
- "getUsing requires exactly one key, e.g. { pcb_component_id }"
1471
- );
1472
- }
1473
- const join_key = keys[0];
1474
- const join_type = join_key.replace("_id", "");
1475
- const joiner = soup.find(
1476
- (e) => e.type === join_type && e[join_key] === using[join_key]
1477
- );
1478
- if (!joiner)
1479
- return null;
1480
- return soup.find(
1481
- (e) => e.type === component_type && e[`${component_type}_id`] === joiner[`${component_type}_id`]
1482
- );
1483
- },
1484
- getWhere: (where) => {
1485
- const keys = Object.keys(where);
1486
- return soup.find(
1487
- (e) => e.type === component_type && keys.every((key) => e[key] === where[key])
1488
- );
1489
- },
1490
- list: (where) => {
1491
- const keys = !where ? [] : Object.keys(where);
1492
- return soup.filter(
1493
- (e) => e.type === component_type && keys.every((key) => e[key] === where[key])
1494
- );
1495
- },
1496
- insert: (elm) => {
1497
- internalStore.counts[component_type] ??= -1;
1498
- internalStore.counts[component_type]++;
1499
- const index = internalStore.counts[component_type];
1500
- const newElm = {
1501
- type: component_type,
1502
- [`${component_type}_id`]: `${component_type}_${index}`,
1503
- ...elm
1504
- };
1505
- if (options.validateInserts) {
1506
- const parser = dist_exports[component_type] ?? any_soup_element;
1507
- parser.parse(newElm);
1508
- }
1509
- soup.push(newElm);
1510
- return newElm;
1511
- },
1512
- delete: (id) => {
1513
- const elm = soup.find(
1514
- (e) => e[`${component_type}_id`] === id
1515
- );
1516
- if (!elm)
1517
- return;
1518
- soup.splice(soup.indexOf(elm), 1);
1519
- },
1520
- update: (id, newProps) => {
1521
- const elm = soup.find(
1522
- (e) => e[`${component_type}_id`] === id
1523
- );
1524
- if (!elm)
1525
- return;
1526
- Object.assign(elm, newProps);
1527
- return elm;
1528
- },
1529
- select: (selector) => {
1530
- if (component_type === "source_component") {
1531
- return soup.find(
1532
- (e) => e.type === "source_component" && e.name === selector.replace(/\./g, "")
1533
- );
1534
- } else if (component_type === "pcb_port" || component_type === "source_port" || component_type === "schematic_port") {
1535
- const [component_name, port_selector] = selector.replace(/\./g, "").split(/[\s\>]+/);
1536
- const source_component = soup.find(
1537
- (e) => e.type === "source_component" && e.name === component_name
1538
- );
1539
- if (!source_component)
1540
- return null;
1541
- const source_port2 = soup.find(
1542
- (e) => e.type === "source_port" && e.source_component_id === source_component.source_component_id && (e.name === port_selector || (e.port_hints ?? []).includes(port_selector))
1543
- );
1544
- if (!source_port2)
1545
- return null;
1546
- if (component_type === "source_port")
1547
- return source_port2;
1548
- if (component_type === "pcb_port") {
1549
- return soup.find(
1550
- (e) => e.type === "pcb_port" && e.source_port_id === source_port2.source_port_id
1551
- );
1552
- } else if (component_type === "schematic_port") {
1553
- return soup.find(
1554
- (e) => e.type === "schematic_port" && e.source_port_id === source_port2.source_port_id
1555
- );
1556
- }
1557
- }
1558
- }
1559
- };
1560
- }
1561
- }
1562
- );
1563
- return su22;
1564
- };
1565
- su.unparsed = su;
1566
- var su_default = su;
1567
- var transformPCBElement = (elm, matrix) => {
1568
- if (elm.type === "pcb_plated_hole" || elm.type === "pcb_hole" || elm.type === "pcb_via" || elm.type === "pcb_smtpad" || elm.type === "pcb_port") {
1569
- const { x, y } = (0, import_transformation_matrix.applyToPoint)(matrix, { x: elm.x, y: elm.y });
1570
- elm.x = x;
1571
- elm.y = y;
1572
- } else if (elm.type === "pcb_keepout" || elm.type === "pcb_board") {
1573
- elm.center = (0, import_transformation_matrix.applyToPoint)(matrix, elm.center);
1574
- } else if (elm.type === "pcb_silkscreen_text" || elm.type === "pcb_fabrication_note_text") {
1575
- elm.anchor_position = (0, import_transformation_matrix.applyToPoint)(matrix, elm.anchor_position);
1576
- } else if (elm.type === "pcb_silkscreen_circle" || elm.type === "pcb_silkscreen_rect" || elm.type === "pcb_component") {
1577
- elm.center = (0, import_transformation_matrix.applyToPoint)(matrix, elm.center);
1578
- } else if (elm.type === "pcb_silkscreen_path" || elm.type === "pcb_trace" || elm.type === "pcb_fabrication_note_path") {
1579
- elm.route = elm.route.map((rp) => {
1580
- const tp = (0, import_transformation_matrix.applyToPoint)(matrix, rp);
1581
- rp.x = tp.x;
1582
- rp.y = tp.y;
1583
- return rp;
1584
- });
1585
- } else if (elm.type === "pcb_silkscreen_line") {
1586
- const p1 = { x: elm.x1, y: elm.y1 };
1587
- const p2 = { x: elm.x2, y: elm.y2 };
1588
- const p1t = (0, import_transformation_matrix.applyToPoint)(matrix, p1);
1589
- const p2t = (0, import_transformation_matrix.applyToPoint)(matrix, p2);
1590
- elm.x1 = p1t.x;
1591
- elm.y1 = p1t.y;
1592
- elm.x2 = p2t.x;
1593
- elm.y2 = p2t.y;
1594
- } else if (elm.type === "cad_component") {
1595
- const newPos = (0, import_transformation_matrix.applyToPoint)(matrix, {
1596
- x: elm.position.x,
1597
- y: elm.position.y
1598
- });
1599
- elm.position.x = newPos.x;
1600
- elm.position.y = newPos.y;
1601
- }
1602
- return elm;
1603
- };
1604
- var transformPCBElements = (elms, matrix) => {
1605
- const tsr = (0, import_transformation_matrix.decomposeTSR)(matrix);
1606
- const flipPadWidthHeight = Math.round(tsr.rotation.angle / (Math.PI / 2)) % 2 === 1;
1607
- let transformedElms = elms.map((elm) => transformPCBElement(elm, matrix));
1608
- if (flipPadWidthHeight) {
1609
- transformedElms = transformedElms.map((elm) => {
1610
- if (elm.type === "pcb_smtpad" && elm.shape === "rect") {
1611
- ;
1612
- [elm.width, elm.height] = [elm.height, elm.width];
1613
- }
1614
- return elm;
1615
- });
1616
- }
1617
- return transformedElms;
1618
- };
1619
-
1620
- // lib/convert-easyeda-json-to-tscircuit-soup-json.ts
1621
- var import_transformation_matrix2 = require("transformation-matrix");
1622
-
1623
- // lib/compute-center-offset.ts
1624
- var import_mm = require("@tscircuit/mm");
1625
- var computeCenterOffset = (easyeda) => {
1626
- const pads = easyeda.packageDetail.dataStr.shape.filter(
1627
- (shape) => shape.type === "PAD"
1628
- );
1629
- const minX = Math.min(...pads.map((pad) => (0, import_mm.mm)(pad.center.x)));
1630
- const maxX = Math.max(...pads.map((pad) => (0, import_mm.mm)(pad.center.x)));
1631
- const minY = Math.min(...pads.map((pad) => (0, import_mm.mm)(pad.center.y)));
1632
- const maxY = Math.max(...pads.map((pad) => (0, import_mm.mm)(pad.center.y)));
1633
- const centerX = (minX + maxX) / 2;
1634
- const centerY = (minY + maxY) / 2;
1635
- return {
1636
- x: centerX,
1637
- y: centerY
1638
- };
1639
- };
1640
-
1641
- // lib/convert-easyeda-json-to-tscircuit-soup-json.ts
1642
- var import_mm2 = require("@tscircuit/mm");
1643
- var handleSilkscreenPath = (track, index) => {
1644
- return pcb_silkscreen_path.parse({
1645
- type: "pcb_silkscreen_path",
1646
- pcb_silkscreen_path_id: `pcb_silkscreen_path_${index + 1}`,
1647
- pcb_component_id: "pcb_component_1",
1648
- layer: "top",
1649
- // Assuming all silkscreen is on top layer
1650
- route: track.points.map((point2) => ({ x: point2.x, y: point2.y })),
1651
- stroke_width: track.width
1652
- });
1653
- };
1654
- var handleSilkscreenArc = (arc, index) => {
1655
- const arcPath = generateArcFromSweep(
1656
- arc.start.x,
1657
- arc.start.y,
1658
- arc.end.x,
1659
- arc.end.y,
1660
- arc.radiusX,
1661
- arc.largeArc,
1662
- arc.sweepDirection === "CW"
1663
- );
1664
- return pcb_silkscreen_path.parse({
1665
- type: "pcb_silkscreen_path",
1666
- pcb_silkscreen_path_id: `pcb_silkscreen_arc_${index + 1}`,
1667
- pcb_component_id: "pcb_component_1",
1668
- layer: "top",
1669
- // Assuming all silkscreen is on top layer
1670
- route: arcPath,
1671
- stroke_width: arc.width
1672
- });
1673
- };
1674
- var convertEasyEdaJsonToCircuitJson = (easyEdaJson, { useModelCdn, shouldRecenter = true } = {}) => {
1675
- const soupElements = [];
1676
- const centerOffset = computeCenterOffset(easyEdaJson);
1677
- const source_component = any_source_component.parse({
1678
- type: "source_component",
1679
- source_component_id: "source_component_1",
1680
- name: "U1",
1681
- ftype: "simple_bug"
1682
- });
1683
- const pcb_component2 = pcb_component.parse({
1684
- type: "pcb_component",
1685
- pcb_component_id: "pcb_component_1",
1686
- source_component_id: "source_component_1",
1687
- name: "U1",
1688
- ftype: "simple_bug",
1689
- width: 0,
1690
- // TODO compute width
1691
- height: 0,
1692
- // TODO compute height
1693
- rotation: 0,
1694
- center: { x: centerOffset.x, y: centerOffset.y },
1695
- layer: "top"
1696
- });
1697
- soupElements.push(source_component, pcb_component2);
1698
- easyEdaJson.packageDetail.dataStr.shape.filter((shape) => shape.type === "PAD").forEach((pad, index) => {
1699
- const portNumber = pad.number.toString();
1700
- soupElements.push({
1701
- type: "source_port",
1702
- source_port_id: `source_port_${index + 1}`,
1703
- source_component_id: "source_component_1",
1704
- name: portNumber
1705
- });
1706
- if (pad.holeRadius !== void 0 && (0, import_mm2.mm)(pad.holeRadius) !== 0) {
1707
- soupElements.push(
1708
- pcb_plated_hole.parse({
1709
- type: "pcb_plated_hole",
1710
- pcb_plated_hole_id: `pcb_plated_hole_${index + 1}`,
1711
- shape: "circle",
1712
- x: (0, import_mm2.mm)(pad.center.x),
1713
- y: (0, import_mm2.mm)(pad.center.y),
1714
- hole_diameter: (0, import_mm2.mm)(pad.holeRadius) * 2,
1715
- outer_diameter: (0, import_mm2.mm)(pad.width),
1716
- radius: (0, import_mm2.mm)(pad.holeRadius),
1717
- port_hints: [portNumber],
1718
- pcb_component_id: "pcb_component_1",
1719
- pcb_port_id: `pcb_port_${index + 1}`,
1720
- layers: ["top"]
1721
- })
1722
- );
1723
- } else {
1724
- let soupShape;
1725
- if (pad.shape === "RECT") {
1726
- soupShape = "rect";
1727
- } else if (pad.shape === "ELLIPSE") {
1728
- soupShape = "rect";
1729
- } else if (pad.shape === "OVAL") {
1730
- soupShape = "rect";
1731
- }
1732
- if (!soupShape) {
1733
- throw new Error(`unknown pad.shape: "${pad.shape}"`);
1734
- }
1735
- soupElements.push(
1736
- pcb_smtpad.parse({
1737
- type: "pcb_smtpad",
1738
- pcb_smtpad_id: `pcb_smtpad_${index + 1}`,
1739
- shape: soupShape,
1740
- x: (0, import_mm2.mm)(pad.center.x),
1741
- y: (0, import_mm2.mm)(pad.center.y),
1742
- ...soupShape === "rect" ? { width: (0, import_mm2.mm)(pad.width), height: (0, import_mm2.mm)(pad.height) } : { radius: Math.min((0, import_mm2.mm)(pad.width), (0, import_mm2.mm)(pad.height)) / 2 },
1743
- layer: "top",
1744
- port_hints: [portNumber],
1745
- pcb_component_id: "pcb_component_1",
1746
- pcb_port_id: `pcb_port_${index + 1}`
1747
- })
1748
- );
1749
- }
1750
- });
1751
- easyEdaJson.packageDetail.dataStr.shape.forEach((shape, index) => {
1752
- if (shape.type === "TRACK") {
1753
- soupElements.push(handleSilkscreenPath(shape, index));
1754
- } else if (shape.type === "ARC") {
1755
- soupElements.push(handleSilkscreenArc(shape, index));
1756
- }
1757
- });
1758
- transformPCBElements(soupElements, (0, import_transformation_matrix2.scale)(1, -1));
1759
- const svgNode = easyEdaJson.packageDetail.dataStr.shape.find(
1760
- (a) => Boolean(a.type === "SVGNODE" && a.svgData.attrs?.uuid)
1761
- );
1762
- const objFileUuid = svgNode?.svgData?.attrs?.uuid;
1763
- const objFileUrl = objFileUuid ? useModelCdn ? `https://modelcdn.tscircuit.com/easyeda_models/download?uuid=${objFileUuid}&pn=${easyEdaJson.lcsc.number}` : `https://modules.easyeda.com/3dmodel/${objFileUuid}` : void 0;
1764
- if (objFileUrl !== void 0) {
1765
- const [rx, ry, rz] = (svgNode?.svgData.attrs?.c_rotation ?? "0,0,0").split(",").map(Number);
1766
- soupElements.push(
1767
- cad_component.parse({
1768
- type: "cad_component",
1769
- cad_component_id: "cad_component_1",
1770
- source_component_id: "source_component_1",
1771
- pcb_component_id: "pcb_component_1",
1772
- position: { x: 0, y: 0, z: 0 },
1773
- rotation: { x: rx, y: ry, z: rz },
1774
- model_obj_url: objFileUrl
1775
- })
1776
- );
1777
- }
1778
- if (shouldRecenter) {
1779
- transformPCBElements(
1780
- soupElements,
1781
- (0, import_transformation_matrix2.translate)(-centerOffset.x, centerOffset.y)
1782
- );
1783
- }
1784
- return soupElements;
1785
- };
1786
- var convertEasyEdaJsonToTscircuitSoupJson = convertEasyEdaJsonToCircuitJson;
1787
-
1788
- // cli/main.ts
1789
- var import_promises2 = __toESM(require("fs/promises"), 1);
1790
-
1791
- // package.json
1792
- var package_default = {
1793
- name: "easyeda",
1794
- type: "module",
1795
- version: "0.0.30",
1796
- files: [
1797
- "dist"
1798
- ],
1799
- repository: {
1800
- type: "git",
1801
- url: "https://github.com/tscircuit/easyeda-converter"
1802
- },
1803
- scripts: {
1804
- test: "bun test",
1805
- build: "tsup lib/index.ts cli/main.ts --dts --sourcemap",
1806
- aider: "aider",
1807
- "format:check": "biome format .",
1808
- format: "biome format . --write"
1809
- },
1810
- main: "./dist/lib/index.cjs",
1811
- bin: {
1812
- "easyeda-converter": "./dist/cli/main.cjs",
1813
- easyeda: "./dist/cli/main.cjs"
1814
- },
1815
- devDependencies: {
1816
- "@biomejs/biome": "^1.8.3",
1817
- "@tscircuit/log-soup": "1.0.2",
1818
- "@tscircuit/props": "^0.0.68",
1819
- "@tscircuit/soup-util": "^0.0.31",
1820
- "@types/bun": "latest",
1821
- "circuit-json": "^0.0.83",
1822
- tsup: "^8.1.0"
1823
- },
1824
- peerDependencies: {
1825
- typescript: "^5.5.2"
1826
- },
1827
- dependencies: {
1828
- "@tscircuit/mm": "^0.0.8",
1829
- commander: "^12.1.0",
1830
- "transformation-matrix": "^2.16.1",
1831
- zod: "^3.23.8"
1832
- }
1833
- };
1834
-
1835
- // lib/schemas/easy-eda-json-schema.ts
1836
- var import_zod62 = require("zod");
1837
-
1838
- // lib/schemas/single-letter-shape-schema.ts
1839
- var import_zod61 = require("zod");
1840
- var PointSchema2 = import_zod61.z.object({
1841
- x: import_zod61.z.number(),
1842
- y: import_zod61.z.number()
1843
- });
1844
- var RectangleShapeOutputSchema = import_zod61.z.object({
1845
- type: import_zod61.z.literal("RECTANGLE"),
1846
- position: PointSchema2,
1847
- width: import_zod61.z.number(),
1848
- height: import_zod61.z.number(),
1849
- color: import_zod61.z.string(),
1850
- lineWidth: import_zod61.z.number(),
1851
- id: import_zod61.z.string()
1852
- });
1853
- var parseRectangle = (str) => {
1854
- const [, x, y, , , width, height, color, lineWidth, , , id] = str.split("~");
1855
- return {
1856
- type: "RECTANGLE",
1857
- position: { x: Number(x), y: Number(y) },
1858
- width: Number(width),
1859
- height: Number(height),
1860
- color,
1861
- lineWidth: Number(lineWidth),
1862
- id
1863
- };
1864
- };
1865
- var RectangleShapeSchema = import_zod61.z.string().startsWith("R~").transform(parseRectangle).pipe(RectangleShapeOutputSchema);
1866
- var EllipseShapeOutputSchema = import_zod61.z.object({
1867
- type: import_zod61.z.literal("ELLIPSE"),
1868
- center: PointSchema2,
1869
- radiusX: import_zod61.z.number(),
1870
- radiusY: import_zod61.z.number(),
1871
- color: import_zod61.z.string(),
1872
- lineWidth: import_zod61.z.number(),
1873
- id: import_zod61.z.string()
1874
- });
1875
- var parseEllipse = (str) => {
1876
- const [, x, y, radiusX, radiusY, color, lineWidth, , , id] = str.split("~");
1877
- return {
1878
- type: "ELLIPSE",
1879
- center: { x: Number(x), y: Number(y) },
1880
- radiusX: Number(radiusX),
1881
- radiusY: Number(radiusY),
1882
- color,
1883
- lineWidth: Number(lineWidth),
1884
- id
1885
- };
1886
- };
1887
- var EllipseShapeSchema = import_zod61.z.string().startsWith("E~").transform(parseEllipse).pipe(EllipseShapeOutputSchema);
1888
- var PinShapeOutputSchema = import_zod61.z.object({
1889
- type: import_zod61.z.literal("PIN"),
1890
- visibility: import_zod61.z.enum(["show", "hide"]),
1891
- pinNumber: import_zod61.z.number(),
1892
- x: import_zod61.z.number(),
1893
- y: import_zod61.z.number(),
1894
- rotation: import_zod61.z.number(),
1895
- id: import_zod61.z.string(),
1896
- label: import_zod61.z.string(),
1897
- labelColor: import_zod61.z.string(),
1898
- path: import_zod61.z.string(),
1899
- arrow: import_zod61.z.string()
1900
- });
1901
- var parsePin = (pinString) => {
1902
- const parts = pinString.split("~");
1903
- const [, visibility, , pinNumber, x, y, rotation2, id] = parts;
1904
- const nameMatch = pinString.match(/~(\w+)~start~/);
1905
- const label = nameMatch ? nameMatch[1] : "";
1906
- const colorMatch = pinString.match(/#[0-9A-F]{6}/);
1907
- const labelColor = colorMatch ? colorMatch[0] : "";
1908
- const pathMatch = pinString.match(/\^\^([^~]+)/);
1909
- const path2 = pathMatch ? pathMatch[1] : "";
1910
- const arrowMatch = pinString.match(/\^\^0~(.+)$/);
1911
- const arrow = arrowMatch ? arrowMatch[1] : "";
1912
- return {
1913
- type: "PIN",
1914
- visibility,
1915
- id,
1916
- pinNumber: parseInt(pinNumber),
1917
- x: parseFloat(x),
1918
- y: parseFloat(y),
1919
- rotation: parseFloat(rotation2),
1920
- label,
1921
- labelColor,
1922
- path: path2,
1923
- arrow
1924
- };
1925
- };
1926
- var PinShapeSchema = import_zod61.z.string().startsWith("P~").transform(parsePin).pipe(PinShapeOutputSchema);
1927
- var PolylineShapeOutputSchema = import_zod61.z.object({
1928
- type: import_zod61.z.literal("POLYLINE"),
1929
- points: import_zod61.z.array(PointSchema2),
1930
- color: import_zod61.z.string(),
1931
- lineWidth: import_zod61.z.number(),
1932
- id: import_zod61.z.string()
1933
- });
1934
- var parsePoints2 = (pointsStr) => {
1935
- return pointsStr.split(" ").reduce((acc, value, index) => {
1936
- if (index % 2 === 0) {
1937
- acc.push({ x: Number(value), y: 0 });
1938
- } else {
1939
- acc[acc.length - 1].y = Number(value);
1940
- }
1941
- return acc;
1942
- }, []);
1943
- };
1944
- var parsePolyline = (str) => {
1945
- const [, ...rest] = str.split("~");
1946
- const [pointsStr, color, lineWidth, , , id] = rest;
1947
- return {
1948
- type: "POLYLINE",
1949
- points: parsePoints2(pointsStr),
1950
- color,
1951
- lineWidth: Number(lineWidth),
1952
- id
1953
- };
1954
- };
1955
- var PolylineShapeSchema = import_zod61.z.string().startsWith("PL~").transform(parsePolyline).pipe(PolylineShapeOutputSchema);
1956
- var PolygonShapeOutputSchema = import_zod61.z.object({
1957
- type: import_zod61.z.literal("POLYGON"),
1958
- points: import_zod61.z.array(PointSchema2),
1959
- fillColor: import_zod61.z.string(),
1960
- lineWidth: import_zod61.z.number(),
1961
- lineColor: import_zod61.z.string(),
1962
- id: import_zod61.z.string()
1963
- });
1964
- var parsePolygon = (str) => {
1965
- const [, ...rest] = str.split("~");
1966
- const [pointsStr, fillColor, lineWidth, lineColor, , id] = rest;
1967
- return {
1968
- type: "POLYGON",
1969
- points: parsePoints2(pointsStr),
1970
- fillColor,
1971
- lineWidth: Number(lineWidth),
1972
- lineColor,
1973
- id
1974
- };
1975
- };
1976
- var PolygonShapeSchema = import_zod61.z.string().startsWith("PG~").transform(parsePolygon).pipe(PolygonShapeOutputSchema);
1977
- var SingleLetterShapeSchema = import_zod61.z.string().transform((x) => {
1978
- if (x.startsWith("R~")) return RectangleShapeSchema.parse(x);
1979
- if (x.startsWith("E~")) return EllipseShapeSchema.parse(x);
1980
- if (x.startsWith("P~")) return PinShapeSchema.parse(x);
1981
- if (x.startsWith("PL~")) return PolylineShapeSchema.parse(x);
1982
- if (x.startsWith("PG~")) return PolygonShapeSchema.parse(x);
1983
- throw new Error(`Invalid shape type: ${x}`);
1984
- }).pipe(
1985
- import_zod61.z.union([
1986
- RectangleShapeOutputSchema,
1987
- EllipseShapeOutputSchema,
1988
- PinShapeOutputSchema,
1989
- PolylineShapeOutputSchema,
1990
- PolygonShapeOutputSchema
1991
- ])
1992
- );
1993
-
1994
- // lib/schemas/easy-eda-json-schema.ts
1995
- var maybeNumber = import_zod62.z.any().transform((k) => k === "nan" || Number.isNaN(k) ? null : k).pipe(import_zod62.z.number().nullable().optional());
1996
- var SzlcscSchema = import_zod62.z.object({
1997
- id: import_zod62.z.number(),
1998
- number: import_zod62.z.string(),
1999
- step: import_zod62.z.number().optional(),
2000
- min: import_zod62.z.number().optional(),
2001
- price: import_zod62.z.number().optional(),
2002
- stock: import_zod62.z.number().optional(),
2003
- url: import_zod62.z.string().url().optional(),
2004
- image: import_zod62.z.string().optional().optional()
2005
- });
2006
- var LcscSchema = import_zod62.z.object({
2007
- id: import_zod62.z.number(),
2008
- number: import_zod62.z.string(),
2009
- step: import_zod62.z.number().optional(),
2010
- min: import_zod62.z.number().optional(),
2011
- price: import_zod62.z.number().optional(),
2012
- stock: import_zod62.z.number().optional(),
2013
- url: import_zod62.z.string().url().optional()
2014
- });
2015
- var OwnerSchema = import_zod62.z.object({
2016
- uuid: import_zod62.z.string(),
2017
- username: import_zod62.z.string(),
2018
- nickname: import_zod62.z.string(),
2019
- avatar: import_zod62.z.string()
2020
- });
2021
- var HeadSchema = import_zod62.z.object({
2022
- docType: import_zod62.z.string(),
2023
- editorVersion: import_zod62.z.string(),
2024
- c_para: import_zod62.z.record(import_zod62.z.string(), import_zod62.z.string()),
2025
- x: import_zod62.z.number(),
2026
- y: import_zod62.z.number(),
2027
- puuid: import_zod62.z.string().optional(),
2028
- uuid: import_zod62.z.string(),
2029
- utime: import_zod62.z.number(),
2030
- importFlag: import_zod62.z.number(),
2031
- c_spiceCmd: import_zod62.z.any().optional(),
2032
- hasIdFlag: import_zod62.z.boolean()
2033
- });
2034
- var BBoxSchema = import_zod62.z.object({
2035
- x: import_zod62.z.number(),
2036
- y: import_zod62.z.number(),
2037
- width: import_zod62.z.number(),
2038
- height: import_zod62.z.number()
2039
- });
2040
- var LayerItemSchema = import_zod62.z.object({
2041
- name: import_zod62.z.string(),
2042
- color: import_zod62.z.string(),
2043
- visible: import_zod62.z.boolean(),
2044
- active: import_zod62.z.boolean(),
2045
- config: import_zod62.z.boolean(),
2046
- transparency: import_zod62.z.boolean()
2047
- });
2048
- var ObjectItemSchema = import_zod62.z.object({
2049
- name: import_zod62.z.string(),
2050
- visible: import_zod62.z.boolean(),
2051
- locked: import_zod62.z.boolean()
2052
- });
2053
- var DataStrSchema = import_zod62.z.object({
2054
- head: HeadSchema,
2055
- canvas: import_zod62.z.string(),
2056
- shape: import_zod62.z.array(SingleLetterShapeSchema),
2057
- BBox: BBoxSchema,
2058
- colors: import_zod62.z.array(import_zod62.z.unknown())
2059
- });
2060
- var PackageDetailDataStrSchema = import_zod62.z.object({
2061
- head: HeadSchema,
2062
- canvas: import_zod62.z.string(),
2063
- shape: import_zod62.z.array(import_zod62.z.string()).transform(
2064
- (shapes) => shapes.map((shape) => {
2065
- const [type, ...data] = shape.split("~");
2066
- return ShapeItemSchema.parse({ type, data: data.join("~") });
2067
- })
2068
- ).pipe(import_zod62.z.array(PackageDetailShapeSchema)),
2069
- layers: import_zod62.z.array(import_zod62.z.string()).transform(
2070
- (layers) => layers.map((layer) => {
2071
- const [name, color, visible, active, config, transparency] = layer.split("~");
2072
- return LayerItemSchema.parse({
2073
- name,
2074
- color,
2075
- visible: visible === "true",
2076
- active: active === "true",
2077
- config: config === "true",
2078
- transparency: transparency === "true"
2079
- });
2080
- })
2081
- ),
2082
- objects: import_zod62.z.array(import_zod62.z.string()).transform(
2083
- (objects) => objects.map((obj) => {
2084
- const [name, visible, locked] = obj.split("~");
2085
- return ObjectItemSchema.parse({
2086
- name,
2087
- visible: visible === "true",
2088
- locked: locked === "true"
2089
- });
2090
- })
2091
- ),
2092
- BBox: BBoxSchema,
2093
- netColors: import_zod62.z.array(import_zod62.z.unknown()).optional()
2094
- });
2095
- var PackageDetailSchema = import_zod62.z.object({
2096
- uuid: import_zod62.z.string(),
2097
- title: import_zod62.z.string(),
2098
- docType: import_zod62.z.number(),
2099
- updateTime: import_zod62.z.number(),
2100
- owner: OwnerSchema,
2101
- datastrid: import_zod62.z.string(),
2102
- writable: import_zod62.z.boolean(),
2103
- dataStr: PackageDetailDataStrSchema
2104
- });
2105
- var EasyEdaJsonSchema = import_zod62.z.object({
2106
- uuid: import_zod62.z.string(),
2107
- title: import_zod62.z.string(),
2108
- description: import_zod62.z.string(),
2109
- docType: import_zod62.z.number(),
2110
- type: import_zod62.z.number(),
2111
- szlcsc: SzlcscSchema,
2112
- lcsc: LcscSchema,
2113
- owner: OwnerSchema,
2114
- tags: import_zod62.z.array(import_zod62.z.string()),
2115
- updateTime: import_zod62.z.number(),
2116
- updated_at: import_zod62.z.string(),
2117
- dataStr: DataStrSchema,
2118
- verify: import_zod62.z.boolean(),
2119
- SMT: import_zod62.z.boolean().optional(),
2120
- datastrid: import_zod62.z.string(),
2121
- jlcOnSale: import_zod62.z.number().optional(),
2122
- writable: import_zod62.z.boolean(),
2123
- isFavorite: import_zod62.z.boolean(),
2124
- packageDetail: PackageDetailSchema
2125
- });
2126
-
2127
- // lib/generate-footprint-tsx.ts
2128
- var import_zod63 = require("zod");
2129
- var import_mm3 = require("@tscircuit/mm");
2130
- var generateFootprintTsx = (easyEdaJson) => {
2131
- const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
2132
- (shape) => shape.type === "PAD"
2133
- );
2134
- const centerOffset = computeCenterOffset(easyEdaJson);
2135
- const centerX = centerOffset.x;
2136
- const centerY = centerOffset.y;
2137
- const footprintElements = pads.map((pad) => {
2138
- const { center, width, height, holeRadius, number } = pad;
2139
- const isPlatedHole = holeRadius !== void 0 && (0, import_mm3.mm)(holeRadius) > 0;
2140
- const normalizedX = (0, import_mm3.mm)(center.x) - centerX;
2141
- const normalizedY = (0, import_mm3.mm)(center.y) - centerY;
2142
- if (isPlatedHole) {
2143
- return `
2144
- <platedhole
2145
- pcbX="${normalizedX.toFixed(2)}mm"
2146
- pcbY="${normalizedY.toFixed(2)}mm"
2147
- hole_diameter="${(0, import_mm3.mm)(holeRadius) * 2}mm"
2148
- outer_diameter="${(0, import_mm3.mm)(width)}mm"
2149
- portHints={["${number}"]}
2150
- />`.replace(/\n/, "");
2151
- } else {
2152
- return `
2153
- <smtpad
2154
- pcbX="${normalizedX.toFixed(2)}mm"
2155
- pcbY="${normalizedY.toFixed(2)}mm"
2156
- width="${(0, import_mm3.mm)(width)}mm"
2157
- height="${(0, import_mm3.mm)(height)}mm"
2158
- shape="rect"
2159
- portHints={["${number}"]}
2160
- />`.replace(/\n/, "");
2161
- }
2162
- });
2163
- return `
2164
- <footprint>
2165
- ${footprintElements.join("\n")}
2166
- </footprint>
2167
- `.trim();
2168
- };
2169
-
2170
- // lib/convert-to-typescript-component/soup-typescript-component-template.ts
2171
- var soupTypescriptComponentTemplate = ({
2172
- pinLabels,
2173
- componentName,
2174
- schPinArrangement,
2175
- objUrl,
2176
- easyEdaJson
2177
- }) => {
2178
- const footprintTsx = generateFootprintTsx(easyEdaJson);
2179
- return `
2180
- import { createUseComponent } from "tscircuit"
2181
- import type { CommonLayoutProps } from "@tscircuit/props"
2182
-
2183
- const pinLabels = ${JSON.stringify(pinLabels, null, " ")} as const
2184
- const pinNames = Object.values(pinLabels)
2185
-
2186
- interface Props extends CommonLayoutProps {
2187
- name: string
2188
- }
2189
-
2190
- export const ${componentName} = (props: Props) => {
2191
- return (
2192
- <bug
2193
- {...props}
2194
- footprint={${footprintTsx}}
2195
- ${objUrl ? `cadModel={{
2196
- objUrl: "${objUrl}"
2197
- }}` : ""}
2198
- pinLabels={pinLabels}
2199
- schPinSpacing={0.75}
2200
- schPortArrangement={${JSON.stringify(schPinArrangement, null, " ")}}
2201
- />
2202
- )
2203
- }
2204
-
2205
- export const use${componentName} = createUseComponent(${componentName}, pinNames)
2206
-
2207
- `.trim();
2208
- };
2209
-
2210
- // lib/utils/normalize-manufacturer-part-number.ts
2211
- function normalizeManufacturerPartNumber(partNumber) {
2212
- let normalized = partNumber.replace(/[-]/g, "_").replace(/[^a-zA-Z0-9_$]/g, "_");
2213
- if (/^\d/.test(normalized)) {
2214
- normalized = "A_" + normalized;
2215
- }
2216
- return normalized;
2217
- }
2218
-
2219
- // lib/convert-to-typescript-component/index.tsx
2220
- var convertRawEasyEdaToTs = async (rawEasy) => {
2221
- const easyeda = EasyEdaJsonSchema.parse(rawEasy);
2222
- const soup = convertEasyEdaJsonToTscircuitSoupJson(easyeda, {
2223
- useModelCdn: true
2224
- });
2225
- const result = await convertToTypescriptComponent({
2226
- easyeda,
2227
- soup
2228
- });
2229
- return result;
2230
- };
2231
- var convertToTypescriptComponent = async ({
2232
- soup,
2233
- easyeda: easyEdaJson
2234
- }) => {
2235
- const rawPn = easyEdaJson.dataStr.head.c_para["Manufacturer Part"];
2236
- const pn = normalizeManufacturerPartNumber(rawPn);
2237
- const [cad_component2] = su_default(soup).cad_component.list();
2238
- const pinLabels = {};
2239
- easyEdaJson.dataStr.shape.filter((shape) => shape.type === "PIN").forEach((pin) => {
2240
- const isPinLabelNumeric = /^\d+$/.test(pin.label);
2241
- const label = isPinLabelNumeric ? `pin${pin.label}` : pin.label;
2242
- pinLabels[pin.pinNumber.toString()] = label;
2243
- });
2244
- const pins = easyEdaJson.dataStr.shape.filter((shape) => shape.type === "PIN");
2245
- const leftPins = pins.filter((pin) => pin.rotation === 180);
2246
- const rightPins = pins.filter((pin) => pin.rotation === 0);
2247
- const schPinArrangement = {
2248
- leftSide: {
2249
- direction: "top-to-bottom",
2250
- pins: leftPins.map((pin) => pin.pinNumber)
2251
- },
2252
- rightSide: {
2253
- direction: "bottom-to-top",
2254
- pins: rightPins.map((pin) => pin.pinNumber).reverse()
2255
- }
2256
- };
2257
- let modelObjUrl;
2258
- if (cad_component2.model_obj_url) {
2259
- const isValidUrl = await checkModelObjUrlValidity(
2260
- cad_component2.model_obj_url
2261
- );
2262
- if (isValidUrl) {
2263
- modelObjUrl = cad_component2.model_obj_url;
2264
- }
2265
- }
2266
- return soupTypescriptComponentTemplate({
2267
- componentName: pn,
2268
- pinLabels,
2269
- schPinArrangement,
2270
- objUrl: modelObjUrl,
2271
- easyEdaJson
2272
- });
2273
- };
2274
- var checkModelObjUrlValidity = async (url) => {
2275
- try {
2276
- const response = await fetch(url, { method: "HEAD" });
2277
- return response.status === 200;
2278
- } catch (error) {
2279
- console.error(`Error checking model object URL ${url}:`, error);
2280
- return false;
2281
- }
2282
- };
2283
-
2284
- // lib/convert-easyeda-json-to-various-formats.ts
2285
- var import_promises = __toESM(require("fs/promises"), 1);
2286
- var path = __toESM(require("path"), 1);
2287
- var convertEasyEdaJsonToVariousFormats = async ({
2288
- jlcpcbPartNumberOrFilepath,
2289
- outputFilename,
2290
- formatType
2291
- }) => {
2292
- let rawEasyEdaJson;
2293
- if (jlcpcbPartNumberOrFilepath.includes(".") || jlcpcbPartNumberOrFilepath.includes("/")) {
2294
- rawEasyEdaJson = JSON.parse(
2295
- await import_promises.default.readFile(jlcpcbPartNumberOrFilepath, "utf-8")
2296
- );
2297
- } else {
2298
- rawEasyEdaJson = await fetchEasyEDAComponent(jlcpcbPartNumberOrFilepath);
2299
- }
2300
- const tsxExtension = "tsx";
2301
- if (formatType === "ts") formatType = tsxExtension;
2302
- if (!outputFilename && formatType) {
2303
- let filename = path.basename(jlcpcbPartNumberOrFilepath).split(".")[0];
2304
- if (formatType === tsxExtension) {
2305
- const {
2306
- dataStr: {
2307
- head: {
2308
- c_para: { "Manufacturer Part": manufacturerPartNumber }
2309
- }
2310
- }
2311
- } = rawEasyEdaJson;
2312
- filename = normalizeManufacturerPartNumber(manufacturerPartNumber);
2313
- }
2314
- outputFilename = `${filename}.${formatType}`;
2315
- }
2316
- if (!outputFilename) {
2317
- console.log("specify --output file (-o) or --type (-t)");
2318
- process.exit(1);
2319
- }
2320
- if (outputFilename.endsWith(".raweasy.json")) {
2321
- await import_promises.default.writeFile(outputFilename, JSON.stringify(rawEasyEdaJson, null, 2));
2322
- console.log(`Saved raw EasyEDA JSON: ${outputFilename}`);
2323
- return;
2324
- }
2325
- try {
2326
- const betterEasy = EasyEdaJsonSchema.parse(rawEasyEdaJson);
2327
- const tscircuitSoup = convertEasyEdaJsonToTscircuitSoupJson(betterEasy);
2328
- if (outputFilename.endsWith(".soup.json")) {
2329
- await import_promises.default.writeFile(outputFilename, JSON.stringify(tscircuitSoup, null, 2));
2330
- console.log(`Converted to tscircuit soup JSON: ${outputFilename}`);
2331
- } else if (outputFilename.endsWith(".kicad_mod")) {
2332
- console.log("Conversion to KiCad footprint not yet implemented");
2333
- } else if (outputFilename.endsWith(".bettereasy.json")) {
2334
- await import_promises.default.writeFile(outputFilename, JSON.stringify(betterEasy, null, 2));
2335
- console.log(`Saved better EasyEDA JSON: ${outputFilename}`);
2336
- } else if (outputFilename.endsWith(".tsx") || outputFilename.endsWith(".ts")) {
2337
- const tsComp = await convertRawEasyEdaToTs(rawEasyEdaJson);
2338
- await import_promises.default.writeFile(outputFilename, tsComp);
2339
- console.log(`Saved TypeScript component: ${outputFilename}`);
2340
- } else {
2341
- console.error("Unsupported output format");
2342
- }
2343
- } catch (error) {
2344
- console.error("Error:", error.message);
2345
- }
2346
- };
2347
-
2348
- // cli/main.ts
2349
- var program = new import_commander.Command();
2350
- program.name("easyeda-converter").description("Convert EasyEDA JSON PCB footprints into tscircuit json soup").version(package_default.version);
2351
- program.command("convert").description("Convert EasyEDA JSON to various formats").option("-i, --input <jlcpcbPartNumber>", "JLCPCB part number").option("-o, --output <filename>", "Output filename").option(
2352
- "-t, --type <type>",
2353
- "Output type: soup.json, kicad_mod, raweasy.json, bettereasy.json, tsx"
2354
- ).action(async (options) => {
2355
- await convertEasyEdaJsonToVariousFormats({
2356
- jlcpcbPartNumberOrFilepath: options.input,
2357
- outputFilename: options.output,
2358
- formatType: options.type
2359
- });
2360
- });
2361
- program.command("download").description("Download JSON for footprint").requiredOption("-i, --input <jlcpcbPartNumber>", "JLCPCB part number").option("-o, --output <filename>", "Output filename").action(async (options) => {
2362
- if (!options.output) {
2363
- options.output = `${options.input}.raweasy.json`;
2364
- }
2365
- try {
2366
- const easyEdaJsonRes = await fetchEasyEDAComponent(options.input);
2367
- await import_promises2.default.writeFile(
2368
- options.output,
2369
- JSON.stringify(easyEdaJsonRes, null, 2)
2370
- );
2371
- console.log(`Downloaded JSON footprint: ${options.output}`);
2372
- } catch (error) {
2373
- console.error("Error:", error.message);
2374
- }
2375
- });
2376
- program.parse(process.argv);
2377
- //# sourceMappingURL=main.cjs.map