easyeda 0.0.198 → 0.0.199

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.
@@ -1,4253 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // node_modules/circuit-json/dist/index.mjs
8
- var dist_exports = {};
9
- __export(dist_exports, {
10
- all_layers: () => all_layers,
11
- any_circuit_element: () => any_circuit_element,
12
- any_soup_element: () => any_soup_element,
13
- any_source_component: () => any_source_component,
14
- battery_capacity: () => battery_capacity,
15
- cad_component: () => cad_component,
16
- capacitance: () => capacitance,
17
- current: () => current,
18
- distance: () => distance,
19
- frequency: () => frequency,
20
- getZodPrefixedIdWithDefault: () => getZodPrefixedIdWithDefault,
21
- inductance: () => inductance,
22
- layer_ref: () => layer_ref,
23
- layer_string: () => layer_string,
24
- length: () => length,
25
- ninePointAnchor: () => ninePointAnchor,
26
- pcb_autorouting_error: () => pcb_autorouting_error,
27
- pcb_board: () => pcb_board,
28
- pcb_breakout_point: () => pcb_breakout_point,
29
- pcb_component: () => pcb_component,
30
- pcb_cutout: () => pcb_cutout,
31
- pcb_cutout_circle: () => pcb_cutout_circle,
32
- pcb_cutout_polygon: () => pcb_cutout_polygon,
33
- pcb_cutout_rect: () => pcb_cutout_rect,
34
- pcb_fabrication_note_path: () => pcb_fabrication_note_path,
35
- pcb_fabrication_note_text: () => pcb_fabrication_note_text,
36
- pcb_ground_plane: () => pcb_ground_plane,
37
- pcb_ground_plane_region: () => pcb_ground_plane_region,
38
- pcb_group: () => pcb_group,
39
- pcb_hole: () => pcb_hole,
40
- pcb_hole_circle_or_square_shape: () => pcb_hole_circle_or_square_shape,
41
- pcb_hole_oval_shape: () => pcb_hole_oval_shape,
42
- pcb_keepout: () => pcb_keepout,
43
- pcb_manual_edit_conflict_warning: () => pcb_manual_edit_conflict_warning,
44
- pcb_missing_footprint_error: () => pcb_missing_footprint_error,
45
- pcb_placement_error: () => pcb_placement_error,
46
- pcb_plated_hole: () => pcb_plated_hole,
47
- pcb_port: () => pcb_port,
48
- pcb_port_not_matched_error: () => pcb_port_not_matched_error,
49
- pcb_route_hint: () => pcb_route_hint,
50
- pcb_route_hints: () => pcb_route_hints,
51
- pcb_silkscreen_circle: () => pcb_silkscreen_circle,
52
- pcb_silkscreen_line: () => pcb_silkscreen_line,
53
- pcb_silkscreen_oval: () => pcb_silkscreen_oval,
54
- pcb_silkscreen_path: () => pcb_silkscreen_path,
55
- pcb_silkscreen_rect: () => pcb_silkscreen_rect,
56
- pcb_silkscreen_text: () => pcb_silkscreen_text,
57
- pcb_smtpad: () => pcb_smtpad,
58
- pcb_smtpad_pill: () => pcb_smtpad_pill,
59
- pcb_solder_paste: () => pcb_solder_paste,
60
- pcb_text: () => pcb_text,
61
- pcb_thermal_spoke: () => pcb_thermal_spoke,
62
- pcb_trace: () => pcb_trace,
63
- pcb_trace_error: () => pcb_trace_error,
64
- pcb_trace_hint: () => pcb_trace_hint,
65
- pcb_trace_route_point: () => pcb_trace_route_point,
66
- pcb_trace_route_point_via: () => pcb_trace_route_point_via,
67
- pcb_trace_route_point_wire: () => pcb_trace_route_point_wire,
68
- pcb_via: () => pcb_via,
69
- point: () => point,
70
- point3: () => point3,
71
- port_arrangement: () => port_arrangement,
72
- position: () => position,
73
- position3: () => position3,
74
- resistance: () => resistance,
75
- rotation: () => rotation,
76
- route_hint_point: () => route_hint_point,
77
- schematic_box: () => schematic_box,
78
- schematic_component: () => schematic_component,
79
- schematic_component_port_arrangement_by_sides: () => schematic_component_port_arrangement_by_sides,
80
- schematic_component_port_arrangement_by_size: () => schematic_component_port_arrangement_by_size,
81
- schematic_debug_line: () => schematic_debug_line,
82
- schematic_debug_object: () => schematic_debug_object,
83
- schematic_debug_object_base: () => schematic_debug_object_base,
84
- schematic_debug_point: () => schematic_debug_point,
85
- schematic_debug_rect: () => schematic_debug_rect,
86
- schematic_error: () => schematic_error,
87
- schematic_group: () => schematic_group,
88
- schematic_layout_error: () => schematic_layout_error,
89
- schematic_line: () => schematic_line,
90
- schematic_manual_edit_conflict_warning: () => schematic_manual_edit_conflict_warning,
91
- schematic_net_label: () => schematic_net_label,
92
- schematic_path: () => schematic_path,
93
- schematic_pin_styles: () => schematic_pin_styles,
94
- schematic_port: () => schematic_port,
95
- schematic_text: () => schematic_text,
96
- schematic_trace: () => schematic_trace,
97
- schematic_voltage_probe: () => schematic_voltage_probe,
98
- size: () => size,
99
- source_component_base: () => source_component_base,
100
- source_failed_to_create_component_error: () => source_failed_to_create_component_error,
101
- source_group: () => source_group,
102
- source_missing_property_error: () => source_missing_property_error,
103
- source_net: () => source_net,
104
- source_pcb_ground_plane: () => source_pcb_ground_plane,
105
- source_port: () => source_port,
106
- source_project_metadata: () => source_project_metadata,
107
- source_simple_battery: () => source_simple_battery,
108
- source_simple_capacitor: () => source_simple_capacitor,
109
- source_simple_chip: () => source_simple_chip,
110
- source_simple_crystal: () => source_simple_crystal,
111
- source_simple_diode: () => source_simple_diode,
112
- source_simple_ground: () => source_simple_ground,
113
- source_simple_inductor: () => source_simple_inductor,
114
- source_simple_led: () => source_simple_led,
115
- source_simple_mosfet: () => source_simple_mosfet,
116
- source_simple_pin_header: () => source_simple_pin_header,
117
- source_simple_potentiometer: () => source_simple_potentiometer,
118
- source_simple_power_source: () => source_simple_power_source,
119
- source_simple_push_button: () => source_simple_push_button,
120
- source_simple_resistor: () => source_simple_resistor,
121
- source_simple_resonator: () => source_simple_resonator,
122
- source_simple_switch: () => source_simple_switch,
123
- source_simple_test_point: () => source_simple_test_point,
124
- source_simple_transistor: () => source_simple_transistor,
125
- source_trace: () => source_trace,
126
- supplier_name: () => supplier_name,
127
- time: () => time,
128
- visible_layer: () => visible_layer,
129
- voltage: () => voltage
130
- });
131
- import { z } from "zod";
132
- import { z as z2 } from "zod";
133
- import { z as z3 } from "zod";
134
- import { z as z4 } from "zod";
135
- import { z as z5 } from "zod";
136
-
137
- // node_modules/nanoid/index.js
138
- import { webcrypto as crypto } from "crypto";
139
-
140
- // node_modules/nanoid/url-alphabet/index.js
141
- var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
142
-
143
- // node_modules/nanoid/index.js
144
- var POOL_SIZE_MULTIPLIER = 128;
145
- var pool;
146
- var poolOffset;
147
- function fillPool(bytes) {
148
- if (!pool || pool.length < bytes) {
149
- pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
150
- crypto.getRandomValues(pool);
151
- poolOffset = 0;
152
- } else if (poolOffset + bytes > pool.length) {
153
- crypto.getRandomValues(pool);
154
- poolOffset = 0;
155
- }
156
- poolOffset += bytes;
157
- }
158
- function nanoid(size2 = 21) {
159
- fillPool(size2 -= 0);
160
- let id = "";
161
- for (let i = poolOffset - size2; i < poolOffset; i++) {
162
- id += urlAlphabet[pool[i] & 63];
163
- }
164
- return id;
165
- }
166
-
167
- // node_modules/circuit-json/dist/index.mjs
168
- import { z as z6 } from "zod";
169
- import { z as z9 } from "zod";
170
- import { z as z7 } from "zod";
171
- import { z as z8 } from "zod";
172
- import { z as z10 } from "zod";
173
- import { z as z11 } from "zod";
174
- import { z as z12 } from "zod";
175
- import { z as z13 } from "zod";
176
- import { z as z14 } from "zod";
177
- import { z as z15 } from "zod";
178
- import { z as z31 } from "zod";
179
- import { z as z16 } from "zod";
180
- import { z as z17 } from "zod";
181
- import { z as z18 } from "zod";
182
- import { z as z19 } from "zod";
183
- import { z as z20 } from "zod";
184
- import { z as z21 } from "zod";
185
- import { z as z22 } from "zod";
186
- import { z as z23 } from "zod";
187
- import { z as z24 } from "zod";
188
- import { z as z25 } from "zod";
189
- import { z as z26 } from "zod";
190
- import { z as z27 } from "zod";
191
- import { z as z28 } from "zod";
192
- import { z as z29 } from "zod";
193
- import { z as z30 } from "zod";
194
- import { z as z32 } from "zod";
195
- import { z as z33 } from "zod";
196
- import { z as z34 } from "zod";
197
- import { z as z35 } from "zod";
198
- import { z as z36 } from "zod";
199
- import { z as z37 } from "zod";
200
- import { z as z38 } from "zod";
201
- import { z as z39 } from "zod";
202
- import { z as z40 } from "zod";
203
- import { z as z41 } from "zod";
204
- import { z as z43 } from "zod";
205
- import { z as z42 } from "zod";
206
- import { z as z44 } from "zod";
207
- import { z as z45 } from "zod";
208
- import { z as z46 } from "zod";
209
- import { z as z47 } from "zod";
210
- import { z as z48 } from "zod";
211
- import { z as z49 } from "zod";
212
- import { z as z50 } from "zod";
213
- import { z as z51 } from "zod";
214
- import { z as z52 } from "zod";
215
- import { z as z53 } from "zod";
216
- import { z as z54 } from "zod";
217
- import { z as z55 } from "zod";
218
- import { z as z56 } from "zod";
219
- import { z as z57 } from "zod";
220
- import { z as z58 } from "zod";
221
- import { z as z59 } from "zod";
222
- import { z as z60 } from "zod";
223
- import { z as z61 } from "zod";
224
- import { z as z62 } from "zod";
225
- import { z as z63 } from "zod";
226
- import { z as z64 } from "zod";
227
- import { z as z65 } from "zod";
228
- import { z as z66 } from "zod";
229
- import { z as z67 } from "zod";
230
- import { z as z68 } from "zod";
231
- import { z as z69 } from "zod";
232
- import { z as z70 } from "zod";
233
- import { z as z71 } from "zod";
234
- import { z as z72 } from "zod";
235
- import { z as z73 } from "zod";
236
- import { z as z74 } from "zod";
237
- import { z as z75 } from "zod";
238
- import { z as z76 } from "zod";
239
- import { z as z77 } from "zod";
240
- import { z as z78 } from "zod";
241
- import { z as z79 } from "zod";
242
- import { z as z80 } from "zod";
243
- import { z as z81 } from "zod";
244
- import { z as z82 } from "zod";
245
- import { z as z83 } from "zod";
246
- import { z as z84 } from "zod";
247
- import { z as z85 } from "zod";
248
- import { z as z86 } from "zod";
249
- import { z as z87 } from "zod";
250
- import { z as z88 } from "zod";
251
- var unitMappings = {
252
- Hz: {
253
- baseUnit: "Hz",
254
- variants: {
255
- MHz: 1e6,
256
- kHz: 1e3,
257
- Hz: 1
258
- }
259
- },
260
- g: {
261
- baseUnit: "g",
262
- variants: {
263
- kg: 1e3,
264
- g: 1
265
- }
266
- },
267
- \u03A9: {
268
- baseUnit: "\u03A9",
269
- variants: {
270
- m\u03A9: 1e-3,
271
- \u03A9: 1,
272
- k\u03A9: 1e3,
273
- K\u03A9: 1e3,
274
- kohm: 1e3,
275
- M\u03A9: 1e6,
276
- G\u03A9: 1e9,
277
- T\u03A9: 1e12
278
- }
279
- },
280
- V: {
281
- baseUnit: "V",
282
- variants: {
283
- mV: 1e-3,
284
- V: 1,
285
- kV: 1e3,
286
- KV: 1e3,
287
- MV: 1e6,
288
- GV: 1e9,
289
- TV: 1e12
290
- }
291
- },
292
- A: {
293
- baseUnit: "A",
294
- variants: {
295
- \u00B5A: 1e-6,
296
- mA: 1e-3,
297
- ma: 1e-3,
298
- A: 1,
299
- kA: 1e3,
300
- MA: 1e6
301
- }
302
- },
303
- F: {
304
- baseUnit: "F",
305
- variants: {
306
- pF: 1e-12,
307
- nF: 1e-9,
308
- \u00B5F: 1e-6,
309
- uF: 1e-6,
310
- mF: 1e-3,
311
- F: 1
312
- }
313
- },
314
- ml: {
315
- baseUnit: "ml",
316
- variants: {
317
- ml: 1,
318
- mL: 1,
319
- l: 1e3,
320
- L: 1e3
321
- }
322
- },
323
- deg: {
324
- baseUnit: "deg",
325
- variants: {
326
- rad: 180 / Math.PI
327
- }
328
- },
329
- ms: {
330
- baseUnit: "ms",
331
- variants: {
332
- s: 1e3
333
- }
334
- },
335
- mm: {
336
- baseUnit: "mm",
337
- variants: {
338
- nm: 1e-6,
339
- \u00B5m: 1e-3,
340
- um: 1e-3,
341
- mm: 1,
342
- cm: 10,
343
- dm: 100,
344
- m: 1e3,
345
- km: 1e6,
346
- in: 25.4,
347
- ft: 304.8,
348
- IN: 25.4,
349
- FT: 304.8,
350
- yd: 914.4,
351
- mi: 1609344,
352
- mil: 0.0254
353
- }
354
- }
355
- };
356
- var unitMappingAndVariantSuffixes = /* @__PURE__ */ new Set();
357
- for (const [baseUnit, info] of Object.entries(unitMappings)) {
358
- unitMappingAndVariantSuffixes.add(baseUnit);
359
- for (const variant of Object.keys(info.variants)) {
360
- unitMappingAndVariantSuffixes.add(variant);
361
- }
362
- }
363
- function getBaseTscircuitUnit(unit) {
364
- for (const [baseUnit, info] of Object.entries(unitMappings)) {
365
- if (unit in info.variants) {
366
- return {
367
- baseUnit: info.baseUnit,
368
- conversionFactor: info.variants[unit]
369
- };
370
- }
371
- }
372
- return {
373
- baseUnit: unit,
374
- conversionFactor: 1
375
- };
376
- }
377
- var si_prefix_multiplier = {
378
- tera: 1e12,
379
- T: 1e12,
380
- giga: 1e9,
381
- G: 1e9,
382
- mega: 1e6,
383
- M: 1e6,
384
- kilo: 1e3,
385
- k: 1e3,
386
- deci: 0.1,
387
- d: 0.1,
388
- centi: 0.01,
389
- c: 0.01,
390
- milli: 1e-3,
391
- m: 1e-3,
392
- micro: 1e-6,
393
- u: 1e-6,
394
- \u00B5: 1e-6,
395
- nano: 1e-9,
396
- n: 1e-9,
397
- pico: 1e-12,
398
- p: 1e-12
399
- };
400
- var parseAndConvertSiUnit = (v) => {
401
- if (typeof v === "undefined")
402
- return { parsedUnit: null, unitOfValue: null, value: null };
403
- if (typeof v === "string" && v.match(/^-?[\d\.]+$/))
404
- return {
405
- value: Number.parseFloat(v),
406
- parsedUnit: null,
407
- unitOfValue: null
408
- };
409
- if (typeof v === "number")
410
- return { value: v, parsedUnit: null, unitOfValue: null };
411
- if (typeof v === "object" && "x" in v && "y" in v) {
412
- const { parsedUnit, unitOfValue } = parseAndConvertSiUnit(v.x);
413
- return {
414
- parsedUnit,
415
- unitOfValue,
416
- value: {
417
- x: parseAndConvertSiUnit(v.x).value,
418
- y: parseAndConvertSiUnit(v.y).value
419
- }
420
- };
421
- }
422
- const reversed_input_string = v.toString().split("").reverse().join("");
423
- const unit_reversed = reversed_input_string.match(/[^\d\s]+/)?.[0];
424
- if (!unit_reversed) {
425
- throw new Error(`Could not determine unit: "${v}"`);
426
- }
427
- const unit = unit_reversed.split("").reverse().join("");
428
- const numberPart = v.slice(0, -unit.length);
429
- if (unit in si_prefix_multiplier && !unitMappingAndVariantSuffixes.has(unit)) {
430
- const siMultiplier = si_prefix_multiplier[unit];
431
- return {
432
- parsedUnit: null,
433
- unitOfValue: null,
434
- value: Number.parseFloat(numberPart) * siMultiplier
435
- };
436
- }
437
- const { baseUnit, conversionFactor } = getBaseTscircuitUnit(unit);
438
- return {
439
- parsedUnit: unit,
440
- unitOfValue: baseUnit,
441
- value: conversionFactor * Number.parseFloat(numberPart)
442
- };
443
- };
444
- var resistance = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
445
- var capacitance = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value).transform((value) => {
446
- return Number.parseFloat(value.toPrecision(12));
447
- });
448
- var inductance = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
449
- var voltage = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
450
- var length = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
451
- var frequency = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
452
- var distance = length;
453
- var current = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
454
- var time = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
455
- var rotation = z.string().or(z.number()).transform((arg) => {
456
- if (typeof arg === "number") return arg;
457
- if (arg.endsWith("deg")) {
458
- return Number.parseFloat(arg.split("deg")[0]);
459
- }
460
- if (arg.endsWith("rad")) {
461
- return Number.parseFloat(arg.split("rad")[0]) * 180 / Math.PI;
462
- }
463
- return Number.parseFloat(arg);
464
- });
465
- var battery_capacity = z.number().or(z.string().endsWith("mAh")).transform((v) => {
466
- if (typeof v === "string") {
467
- const valString = v.replace("mAh", "");
468
- const num = Number.parseFloat(valString);
469
- if (Number.isNaN(num)) {
470
- throw new Error("Invalid capacity");
471
- }
472
- return num;
473
- }
474
- return v;
475
- }).describe("Battery capacity in mAh");
476
- var expectTypesMatch = (shouldBe) => {
477
- };
478
- expectTypesMatch("extra props b");
479
- expectTypesMatch("missing props b");
480
- expectTypesMatch(true);
481
- expectTypesMatch("mismatched prop types: a");
482
- var expectStringUnionsMatch = (shouldBe) => {
483
- };
484
- expectStringUnionsMatch(true);
485
- expectStringUnionsMatch(
486
- 'T1 has extra: "c", T2 has extra: "d"'
487
- );
488
- expectStringUnionsMatch('T1 has extra: "c"');
489
- expectStringUnionsMatch('T2 has extra: "c"');
490
- expectStringUnionsMatch(
491
- 'T1 has extra: "d", T2 has extra: "c"'
492
- );
493
- expectStringUnionsMatch(true);
494
- var point = z2.object({
495
- x: distance,
496
- y: distance
497
- });
498
- var position = point;
499
- expectTypesMatch(true);
500
- expectTypesMatch(true);
501
- var point3 = z3.object({
502
- x: distance,
503
- y: distance,
504
- z: distance
505
- });
506
- var position3 = point3;
507
- expectTypesMatch(true);
508
- var size = z4.object({
509
- width: z4.number(),
510
- height: z4.number()
511
- });
512
- expectTypesMatch(true);
513
- var getZodPrefixedIdWithDefault = (prefix) => {
514
- return z5.string().optional().default(() => `${prefix}_${nanoid(10)}`);
515
- };
516
- var ninePointAnchor = z6.enum([
517
- "top_left",
518
- "top_center",
519
- "top_right",
520
- "center_left",
521
- "center",
522
- "center_right",
523
- "bottom_left",
524
- "bottom_center",
525
- "bottom_right"
526
- ]);
527
- expectTypesMatch(true);
528
- var supplier_name = z7.enum([
529
- "jlcpcb",
530
- "macrofab",
531
- "pcbway",
532
- "digikey",
533
- "mouser",
534
- "lcsc"
535
- ]);
536
- expectTypesMatch(true);
537
- var source_component_base = z8.object({
538
- type: z8.literal("source_component"),
539
- ftype: z8.string().optional(),
540
- source_component_id: z8.string(),
541
- name: z8.string(),
542
- manufacturer_part_number: z8.string().optional(),
543
- supplier_part_numbers: z8.record(supplier_name, z8.array(z8.string())).optional(),
544
- display_value: z8.string().optional(),
545
- are_pins_interchangeable: z8.boolean().optional(),
546
- internally_connected_source_port_ids: z8.array(z8.array(z8.string())).optional(),
547
- source_group_id: z8.string().optional(),
548
- subcircuit_id: z8.string().optional()
549
- });
550
- expectTypesMatch(true);
551
- var source_simple_capacitor = source_component_base.extend({
552
- ftype: z9.literal("simple_capacitor"),
553
- capacitance,
554
- max_voltage_rating: voltage.optional(),
555
- display_capacitance: z9.string().optional(),
556
- max_decoupling_trace_length: distance.optional()
557
- });
558
- expectTypesMatch(true);
559
- var source_simple_resistor = source_component_base.extend({
560
- ftype: z10.literal("simple_resistor"),
561
- resistance,
562
- display_resistance: z10.string().optional()
563
- });
564
- expectTypesMatch(true);
565
- var source_simple_diode = source_component_base.extend({
566
- ftype: z11.literal("simple_diode")
567
- });
568
- expectTypesMatch(true);
569
- var source_simple_led = source_simple_diode.extend({
570
- ftype: z12.literal("simple_led"),
571
- color: z12.string().optional(),
572
- wavelength: z12.string().optional()
573
- });
574
- expectTypesMatch(true);
575
- var source_simple_ground = source_component_base.extend({
576
- ftype: z13.literal("simple_ground")
577
- });
578
- expectTypesMatch(true);
579
- var source_simple_chip = source_component_base.extend({
580
- ftype: z14.literal("simple_chip")
581
- });
582
- expectTypesMatch(true);
583
- var source_simple_power_source = source_component_base.extend({
584
- ftype: z15.literal("simple_power_source"),
585
- voltage
586
- });
587
- expectTypesMatch(true);
588
- var source_simple_fuse = source_component_base.extend({
589
- ftype: z16.literal("simple_fuse"),
590
- current_rating_amps: z16.number().describe("Nominal current in amps the fuse is rated for"),
591
- voltage_rating_volts: z16.number().describe("Voltage rating in volts, e.g. \xB15V would be 5")
592
- });
593
- expectTypesMatch(true);
594
- var source_simple_battery = source_component_base.extend({
595
- ftype: z17.literal("simple_battery"),
596
- capacity: battery_capacity
597
- });
598
- expectTypesMatch(true);
599
- var source_simple_inductor = source_component_base.extend({
600
- ftype: z18.literal("simple_inductor"),
601
- inductance,
602
- max_current_rating: z18.number().optional()
603
- });
604
- expectTypesMatch(true);
605
- var source_simple_push_button = source_component_base.extend({
606
- ftype: z19.literal("simple_push_button")
607
- });
608
- expectTypesMatch(true);
609
- var source_simple_potentiometer = source_component_base.extend({
610
- ftype: z20.literal("simple_potentiometer"),
611
- max_resistance: resistance
612
- });
613
- expectTypesMatch(
614
- true
615
- );
616
- var source_simple_crystal = source_component_base.extend({
617
- ftype: z21.literal("simple_crystal"),
618
- frequency: z21.number().describe("Frequency in Hz"),
619
- load_capacitance: z21.number().optional().describe("Load capacitance in pF")
620
- });
621
- expectTypesMatch(true);
622
- var source_simple_pin_header = source_component_base.extend({
623
- ftype: z22.literal("simple_pin_header"),
624
- pin_count: z22.number(),
625
- gender: z22.enum(["male", "female"]).optional().default("male")
626
- });
627
- expectTypesMatch(true);
628
- var source_simple_resonator = source_component_base.extend({
629
- ftype: z23.literal("simple_resonator"),
630
- load_capacitance: capacitance,
631
- equivalent_series_resistance: resistance.optional(),
632
- frequency
633
- });
634
- expectTypesMatch(true);
635
- var source_simple_transistor = source_component_base.extend({
636
- ftype: z24.literal("simple_transistor"),
637
- transistor_type: z24.enum(["npn", "pnp"])
638
- });
639
- expectTypesMatch(true);
640
- var source_simple_test_point = source_component_base.extend({
641
- ftype: z25.literal("simple_test_point"),
642
- footprint_variant: z25.enum(["pad", "through_hole"]).optional(),
643
- pad_shape: z25.enum(["rect", "circle"]).optional(),
644
- pad_diameter: z25.union([z25.number(), z25.string()]).optional(),
645
- hole_diameter: z25.union([z25.number(), z25.string()]).optional(),
646
- width: z25.union([z25.number(), z25.string()]).optional(),
647
- height: z25.union([z25.number(), z25.string()]).optional()
648
- });
649
- expectTypesMatch(true);
650
- var source_simple_mosfet = source_component_base.extend({
651
- ftype: z26.literal("simple_mosfet"),
652
- channel_type: z26.enum(["n", "p"]),
653
- mosfet_mode: z26.enum(["enhancement", "depletion"])
654
- });
655
- expectTypesMatch(true);
656
- var source_simple_switch = source_component_base.extend({
657
- ftype: z27.literal("simple_switch")
658
- });
659
- expectTypesMatch(true);
660
- var source_project_metadata = z28.object({
661
- type: z28.literal("source_project_metadata"),
662
- name: z28.string().optional(),
663
- software_used_string: z28.string().optional(),
664
- project_url: z28.string().optional(),
665
- created_at: z28.string().datetime().optional()
666
- });
667
- expectTypesMatch(true);
668
- var source_missing_property_error = z29.object({
669
- type: z29.literal("source_missing_property_error"),
670
- source_missing_property_error_id: getZodPrefixedIdWithDefault(
671
- "source_missing_property_error"
672
- ),
673
- source_component_id: z29.string(),
674
- property_name: z29.string(),
675
- subcircuit_id: z29.string().optional(),
676
- error_type: z29.literal("source_missing_property_error").default("source_missing_property_error"),
677
- message: z29.string()
678
- }).describe("The source code is missing a property");
679
- expectTypesMatch(true);
680
- var source_failed_to_create_component_error = z30.object({
681
- type: z30.literal("source_failed_to_create_component_error"),
682
- source_failed_to_create_component_error_id: getZodPrefixedIdWithDefault(
683
- "source_failed_to_create_component_error"
684
- ),
685
- error_type: z30.literal("source_failed_to_create_component_error").default("source_failed_to_create_component_error"),
686
- component_name: z30.string().optional(),
687
- subcircuit_id: z30.string().optional(),
688
- parent_source_component_id: z30.string().optional(),
689
- message: z30.string(),
690
- pcb_center: z30.object({
691
- x: z30.number().optional(),
692
- y: z30.number().optional()
693
- }).optional(),
694
- schematic_center: z30.object({
695
- x: z30.number().optional(),
696
- y: z30.number().optional()
697
- }).optional()
698
- }).describe("Error emitted when a component fails to be constructed");
699
- expectTypesMatch(true);
700
- var any_source_component = z31.union([
701
- source_simple_resistor,
702
- source_simple_capacitor,
703
- source_simple_diode,
704
- source_simple_led,
705
- source_simple_ground,
706
- source_simple_chip,
707
- source_simple_power_source,
708
- source_simple_battery,
709
- source_simple_inductor,
710
- source_simple_push_button,
711
- source_simple_potentiometer,
712
- source_simple_crystal,
713
- source_simple_pin_header,
714
- source_simple_resonator,
715
- source_simple_switch,
716
- source_simple_transistor,
717
- source_simple_test_point,
718
- source_simple_mosfet,
719
- source_simple_fuse,
720
- source_project_metadata,
721
- source_missing_property_error,
722
- source_failed_to_create_component_error
723
- ]);
724
- expectTypesMatch(true);
725
- var source_port = z32.object({
726
- type: z32.literal("source_port"),
727
- pin_number: z32.number().optional(),
728
- port_hints: z32.array(z32.string()).optional(),
729
- name: z32.string(),
730
- source_port_id: z32.string(),
731
- source_component_id: z32.string(),
732
- subcircuit_id: z32.string().optional(),
733
- subcircuit_connectivity_map_key: z32.string().optional()
734
- });
735
- expectTypesMatch(true);
736
- var source_trace = z33.object({
737
- type: z33.literal("source_trace"),
738
- source_trace_id: z33.string(),
739
- connected_source_port_ids: z33.array(z33.string()),
740
- connected_source_net_ids: z33.array(z33.string()),
741
- subcircuit_id: z33.string().optional(),
742
- subcircuit_connectivity_map_key: z33.string().optional(),
743
- max_length: z33.number().optional(),
744
- min_trace_thickness: z33.number().optional(),
745
- display_name: z33.string().optional()
746
- });
747
- expectTypesMatch(true);
748
- var source_group = z34.object({
749
- type: z34.literal("source_group"),
750
- source_group_id: z34.string(),
751
- subcircuit_id: z34.string().optional(),
752
- parent_subcircuit_id: z34.string().optional(),
753
- is_subcircuit: z34.boolean().optional(),
754
- name: z34.string().optional()
755
- });
756
- expectTypesMatch(true);
757
- var source_net = z35.object({
758
- type: z35.literal("source_net"),
759
- source_net_id: z35.string(),
760
- name: z35.string(),
761
- member_source_group_ids: z35.array(z35.string()),
762
- is_power: z35.boolean().optional(),
763
- is_ground: z35.boolean().optional(),
764
- is_digital_signal: z35.boolean().optional(),
765
- is_analog_signal: z35.boolean().optional(),
766
- trace_width: z35.number().optional(),
767
- subcircuit_id: z35.string().optional(),
768
- subcircuit_connectivity_map_key: z35.string().optional()
769
- });
770
- expectTypesMatch(true);
771
- var source_pcb_ground_plane = z36.object({
772
- type: z36.literal("source_pcb_ground_plane"),
773
- source_pcb_ground_plane_id: z36.string(),
774
- source_group_id: z36.string(),
775
- source_net_id: z36.string(),
776
- subcircuit_id: z36.string().optional()
777
- }).describe("Defines a ground plane in the source domain");
778
- expectTypesMatch(true);
779
- var schematic_box = z37.object({
780
- type: z37.literal("schematic_box"),
781
- schematic_component_id: z37.string().optional(),
782
- width: distance,
783
- height: distance,
784
- is_dashed: z37.boolean().default(false),
785
- x: distance,
786
- y: distance,
787
- subcircuit_id: z37.string().optional()
788
- }).describe("Draws a box on the schematic");
789
- expectTypesMatch(true);
790
- var schematic_path = z38.object({
791
- type: z38.literal("schematic_path"),
792
- schematic_component_id: z38.string(),
793
- fill_color: z38.enum(["red", "blue"]).optional(),
794
- is_filled: z38.boolean().optional(),
795
- points: z38.array(point),
796
- subcircuit_id: z38.string().optional()
797
- });
798
- expectTypesMatch(true);
799
- var schematic_pin_styles = z39.record(
800
- z39.object({
801
- left_margin: length.optional(),
802
- right_margin: length.optional(),
803
- top_margin: length.optional(),
804
- bottom_margin: length.optional()
805
- })
806
- );
807
- var schematic_component_port_arrangement_by_size = z39.object({
808
- left_size: z39.number(),
809
- right_size: z39.number(),
810
- top_size: z39.number().optional(),
811
- bottom_size: z39.number().optional()
812
- });
813
- expectTypesMatch(true);
814
- var schematic_component_port_arrangement_by_sides = z39.object({
815
- left_side: z39.object({
816
- pins: z39.array(z39.number()),
817
- // @ts-ignore
818
- direction: z39.enum(["top-to-bottom", "bottom-to-top"]).optional()
819
- }).optional(),
820
- right_side: z39.object({
821
- pins: z39.array(z39.number()),
822
- // @ts-ignore
823
- direction: z39.enum(["top-to-bottom", "bottom-to-top"]).optional()
824
- }).optional(),
825
- top_side: z39.object({
826
- pins: z39.array(z39.number()),
827
- // @ts-ignore
828
- direction: z39.enum(["left-to-right", "right-to-left"]).optional()
829
- }).optional(),
830
- bottom_side: z39.object({
831
- pins: z39.array(z39.number()),
832
- // @ts-ignore
833
- direction: z39.enum(["left-to-right", "right-to-left"]).optional()
834
- }).optional()
835
- });
836
- expectTypesMatch(true);
837
- var port_arrangement = z39.union([
838
- schematic_component_port_arrangement_by_size,
839
- schematic_component_port_arrangement_by_sides
840
- ]);
841
- var schematic_component = z39.object({
842
- type: z39.literal("schematic_component"),
843
- size,
844
- center: point,
845
- source_component_id: z39.string(),
846
- schematic_component_id: z39.string(),
847
- pin_spacing: length.optional(),
848
- pin_styles: schematic_pin_styles.optional(),
849
- box_width: length.optional(),
850
- symbol_name: z39.string().optional(),
851
- port_arrangement: port_arrangement.optional(),
852
- port_labels: z39.record(z39.string()).optional(),
853
- symbol_display_value: z39.string().optional(),
854
- subcircuit_id: z39.string().optional(),
855
- schematic_group_id: z39.string().optional()
856
- });
857
- expectTypesMatch(true);
858
- var schematic_line = z40.object({
859
- type: z40.literal("schematic_line"),
860
- schematic_component_id: z40.string(),
861
- x1: distance,
862
- x2: distance,
863
- y1: distance,
864
- y2: distance,
865
- subcircuit_id: z40.string().optional()
866
- });
867
- expectTypesMatch(true);
868
- var schematic_trace = z41.object({
869
- type: z41.literal("schematic_trace"),
870
- schematic_trace_id: z41.string(),
871
- source_trace_id: z41.string(),
872
- junctions: z41.array(
873
- z41.object({
874
- x: z41.number(),
875
- y: z41.number()
876
- })
877
- ),
878
- edges: z41.array(
879
- z41.object({
880
- from: z41.object({
881
- x: z41.number(),
882
- y: z41.number()
883
- }),
884
- to: z41.object({
885
- x: z41.number(),
886
- y: z41.number()
887
- }),
888
- is_crossing: z41.boolean().optional(),
889
- from_schematic_port_id: z41.string().optional(),
890
- to_schematic_port_id: z41.string().optional()
891
- })
892
- ),
893
- subcircuit_id: z41.string().optional()
894
- });
895
- expectTypesMatch(true);
896
- var fivePointAnchor = z42.enum([
897
- "center",
898
- "left",
899
- "right",
900
- "top",
901
- "bottom"
902
- ]);
903
- expectTypesMatch(true);
904
- var schematic_text = z43.object({
905
- type: z43.literal("schematic_text"),
906
- schematic_component_id: z43.string().optional(),
907
- schematic_text_id: z43.string(),
908
- text: z43.string(),
909
- font_size: z43.number().default(0.18),
910
- position: z43.object({
911
- x: distance,
912
- y: distance
913
- }),
914
- rotation: z43.number().default(0),
915
- anchor: z43.union([fivePointAnchor.describe("legacy"), ninePointAnchor]).default("center"),
916
- color: z43.string().default("#000000"),
917
- subcircuit_id: z43.string().optional()
918
- });
919
- expectTypesMatch(true);
920
- var schematic_port = z44.object({
921
- type: z44.literal("schematic_port"),
922
- schematic_port_id: z44.string(),
923
- source_port_id: z44.string(),
924
- schematic_component_id: z44.string().optional(),
925
- center: point,
926
- facing_direction: z44.enum(["up", "down", "left", "right"]).optional(),
927
- distance_from_component_edge: z44.number().optional(),
928
- side_of_component: z44.enum(["top", "bottom", "left", "right"]).optional(),
929
- true_ccw_index: z44.number().optional(),
930
- pin_number: z44.number().optional(),
931
- display_pin_label: z44.string().optional(),
932
- subcircuit_id: z44.string().optional(),
933
- is_connected: z44.boolean().optional()
934
- }).describe("Defines a port on a schematic component");
935
- expectTypesMatch(true);
936
- var schematic_net_label = z45.object({
937
- type: z45.literal("schematic_net_label"),
938
- schematic_net_label_id: getZodPrefixedIdWithDefault("schematic_net_label"),
939
- schematic_trace_id: z45.string().optional(),
940
- source_trace_id: z45.string().optional(),
941
- source_net_id: z45.string(),
942
- center: point,
943
- anchor_position: point.optional(),
944
- anchor_side: z45.enum(["top", "bottom", "left", "right"]),
945
- text: z45.string(),
946
- symbol_name: z45.string().optional(),
947
- is_movable: z45.boolean().optional(),
948
- subcircuit_id: z45.string().optional()
949
- });
950
- expectTypesMatch(true);
951
- var schematic_error = z46.object({
952
- type: z46.literal("schematic_error"),
953
- schematic_error_id: z46.string(),
954
- // eventually each error type should be broken out into a dir of files
955
- error_type: z46.literal("schematic_port_not_found").default("schematic_port_not_found"),
956
- message: z46.string(),
957
- subcircuit_id: z46.string().optional()
958
- }).describe("Defines a schematic error on the schematic");
959
- expectTypesMatch(true);
960
- var schematic_layout_error = z47.object({
961
- type: z47.literal("schematic_layout_error"),
962
- schematic_layout_error_id: getZodPrefixedIdWithDefault(
963
- "schematic_layout_error"
964
- ),
965
- error_type: z47.literal("schematic_layout_error").default("schematic_layout_error"),
966
- message: z47.string(),
967
- source_group_id: z47.string(),
968
- schematic_group_id: z47.string(),
969
- subcircuit_id: z47.string().optional()
970
- }).describe("Error emitted when schematic layout fails for a group");
971
- expectTypesMatch(true);
972
- var schematic_debug_object_base = z48.object({
973
- type: z48.literal("schematic_debug_object"),
974
- label: z48.string().optional(),
975
- subcircuit_id: z48.string().optional()
976
- });
977
- var schematic_debug_rect = schematic_debug_object_base.extend({
978
- shape: z48.literal("rect"),
979
- center: point,
980
- size
981
- });
982
- var schematic_debug_line = schematic_debug_object_base.extend({
983
- shape: z48.literal("line"),
984
- start: point,
985
- end: point
986
- });
987
- var schematic_debug_point = schematic_debug_object_base.extend({
988
- shape: z48.literal("point"),
989
- center: point
990
- });
991
- var schematic_debug_object = z48.discriminatedUnion("shape", [
992
- schematic_debug_rect,
993
- schematic_debug_line,
994
- schematic_debug_point
995
- ]);
996
- expectTypesMatch(true);
997
- var schematic_voltage_probe = z49.object({
998
- type: z49.literal("schematic_voltage_probe"),
999
- schematic_voltage_probe_id: z49.string(),
1000
- position: point,
1001
- schematic_trace_id: z49.string(),
1002
- voltage: voltage.optional(),
1003
- subcircuit_id: z49.string().optional()
1004
- }).describe("Defines a voltage probe measurement point on a schematic trace");
1005
- expectTypesMatch(true);
1006
- var schematic_manual_edit_conflict_warning = z50.object({
1007
- type: z50.literal("schematic_manual_edit_conflict_warning"),
1008
- schematic_manual_edit_conflict_warning_id: getZodPrefixedIdWithDefault(
1009
- "schematic_manual_edit_conflict_warning"
1010
- ),
1011
- warning_type: z50.literal("schematic_manual_edit_conflict_warning").default("schematic_manual_edit_conflict_warning"),
1012
- message: z50.string(),
1013
- schematic_component_id: z50.string(),
1014
- schematic_group_id: z50.string().optional(),
1015
- subcircuit_id: z50.string().optional(),
1016
- source_component_id: z50.string()
1017
- }).describe(
1018
- "Warning emitted when a component has both manual placement and explicit schX/schY coordinates"
1019
- );
1020
- expectTypesMatch(true);
1021
- var schematic_group = z51.object({
1022
- type: z51.literal("schematic_group"),
1023
- schematic_group_id: getZodPrefixedIdWithDefault("schematic_group"),
1024
- source_group_id: z51.string(),
1025
- is_subcircuit: z51.boolean().optional(),
1026
- subcircuit_id: z51.string().optional(),
1027
- width: length,
1028
- height: length,
1029
- center: point,
1030
- schematic_component_ids: z51.array(z51.string()),
1031
- name: z51.string().optional(),
1032
- description: z51.string().optional()
1033
- }).describe("Defines a group of components on the schematic");
1034
- expectTypesMatch(true);
1035
- var all_layers = [
1036
- "top",
1037
- "bottom",
1038
- "inner1",
1039
- "inner2",
1040
- "inner3",
1041
- "inner4",
1042
- "inner5",
1043
- "inner6"
1044
- ];
1045
- var layer_string = z52.enum(all_layers);
1046
- var layer_ref = layer_string.or(
1047
- z52.object({
1048
- name: layer_string
1049
- })
1050
- ).transform((layer) => {
1051
- if (typeof layer === "string") {
1052
- return layer;
1053
- }
1054
- return layer.name;
1055
- });
1056
- expectTypesMatch(true);
1057
- var visible_layer = z52.enum(["top", "bottom"]);
1058
- var pcb_route_hint = z53.object({
1059
- x: distance,
1060
- y: distance,
1061
- via: z53.boolean().optional(),
1062
- via_to_layer: layer_ref.optional()
1063
- });
1064
- var pcb_route_hints = z53.array(pcb_route_hint);
1065
- expectTypesMatch(true);
1066
- expectTypesMatch(true);
1067
- var route_hint_point = z54.object({
1068
- x: distance,
1069
- y: distance,
1070
- via: z54.boolean().optional(),
1071
- to_layer: layer_ref.optional(),
1072
- trace_width: distance.optional()
1073
- });
1074
- expectTypesMatch(true);
1075
- var pcb_component = z55.object({
1076
- type: z55.literal("pcb_component"),
1077
- pcb_component_id: getZodPrefixedIdWithDefault("pcb_component"),
1078
- source_component_id: z55.string(),
1079
- center: point,
1080
- layer: layer_ref,
1081
- rotation,
1082
- width: length,
1083
- height: length,
1084
- subcircuit_id: z55.string().optional(),
1085
- pcb_group_id: z55.string().optional()
1086
- }).describe("Defines a component on the PCB");
1087
- expectTypesMatch(true);
1088
- var pcb_hole_circle_or_square = z56.object({
1089
- type: z56.literal("pcb_hole"),
1090
- pcb_hole_id: getZodPrefixedIdWithDefault("pcb_hole"),
1091
- pcb_group_id: z56.string().optional(),
1092
- subcircuit_id: z56.string().optional(),
1093
- hole_shape: z56.enum(["circle", "square"]),
1094
- hole_diameter: z56.number(),
1095
- x: distance,
1096
- y: distance
1097
- });
1098
- var pcb_hole_circle_or_square_shape = pcb_hole_circle_or_square.describe(
1099
- "Defines a circular or square hole on the PCB"
1100
- );
1101
- expectTypesMatch(true);
1102
- var pcb_hole_oval = z56.object({
1103
- type: z56.literal("pcb_hole"),
1104
- pcb_hole_id: getZodPrefixedIdWithDefault("pcb_hole"),
1105
- pcb_group_id: z56.string().optional(),
1106
- subcircuit_id: z56.string().optional(),
1107
- hole_shape: z56.literal("oval"),
1108
- hole_width: z56.number(),
1109
- hole_height: z56.number(),
1110
- x: distance,
1111
- y: distance
1112
- });
1113
- var pcb_hole_oval_shape = pcb_hole_oval.describe(
1114
- "Defines an oval hole on the PCB"
1115
- );
1116
- expectTypesMatch(true);
1117
- var pcb_hole = pcb_hole_circle_or_square.or(pcb_hole_oval);
1118
- var pcb_plated_hole_circle = z57.object({
1119
- type: z57.literal("pcb_plated_hole"),
1120
- shape: z57.literal("circle"),
1121
- pcb_group_id: z57.string().optional(),
1122
- subcircuit_id: z57.string().optional(),
1123
- outer_diameter: z57.number(),
1124
- hole_diameter: z57.number(),
1125
- x: distance,
1126
- y: distance,
1127
- layers: z57.array(layer_ref),
1128
- port_hints: z57.array(z57.string()).optional(),
1129
- pcb_component_id: z57.string().optional(),
1130
- pcb_port_id: z57.string().optional(),
1131
- pcb_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole")
1132
- });
1133
- var pcb_plated_hole_oval = z57.object({
1134
- type: z57.literal("pcb_plated_hole"),
1135
- shape: z57.enum(["oval", "pill"]),
1136
- pcb_group_id: z57.string().optional(),
1137
- subcircuit_id: z57.string().optional(),
1138
- outer_width: z57.number(),
1139
- outer_height: z57.number(),
1140
- hole_width: z57.number(),
1141
- hole_height: z57.number(),
1142
- x: distance,
1143
- y: distance,
1144
- layers: z57.array(layer_ref),
1145
- port_hints: z57.array(z57.string()).optional(),
1146
- pcb_component_id: z57.string().optional(),
1147
- pcb_port_id: z57.string().optional(),
1148
- pcb_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole")
1149
- });
1150
- var pcb_circular_hole_with_rect_pad = z57.object({
1151
- type: z57.literal("pcb_plated_hole"),
1152
- shape: z57.literal("circular_hole_with_rect_pad"),
1153
- pcb_group_id: z57.string().optional(),
1154
- subcircuit_id: z57.string().optional(),
1155
- hole_shape: z57.literal("circle"),
1156
- pad_shape: z57.literal("rect"),
1157
- hole_diameter: z57.number(),
1158
- rect_pad_width: z57.number(),
1159
- rect_pad_height: z57.number(),
1160
- x: distance,
1161
- y: distance,
1162
- layers: z57.array(layer_ref),
1163
- port_hints: z57.array(z57.string()).optional(),
1164
- pcb_component_id: z57.string().optional(),
1165
- pcb_port_id: z57.string().optional(),
1166
- pcb_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole")
1167
- });
1168
- var pcb_pill_hole_with_rect_pad = z57.object({
1169
- type: z57.literal("pcb_plated_hole"),
1170
- shape: z57.literal("pill_hole_with_rect_pad"),
1171
- pcb_group_id: z57.string().optional(),
1172
- subcircuit_id: z57.string().optional(),
1173
- hole_shape: z57.literal("pill"),
1174
- pad_shape: z57.literal("rect"),
1175
- hole_width: z57.number(),
1176
- hole_height: z57.number(),
1177
- rect_pad_width: z57.number(),
1178
- rect_pad_height: z57.number(),
1179
- x: distance,
1180
- y: distance,
1181
- layers: z57.array(layer_ref),
1182
- port_hints: z57.array(z57.string()).optional(),
1183
- pcb_component_id: z57.string().optional(),
1184
- pcb_port_id: z57.string().optional(),
1185
- pcb_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole")
1186
- });
1187
- var pcb_plated_hole = z57.union([
1188
- pcb_plated_hole_circle,
1189
- pcb_plated_hole_oval,
1190
- pcb_circular_hole_with_rect_pad,
1191
- pcb_pill_hole_with_rect_pad
1192
- ]);
1193
- expectTypesMatch(
1194
- true
1195
- );
1196
- expectTypesMatch(true);
1197
- expectTypesMatch(true);
1198
- expectTypesMatch(true);
1199
- var pcb_port = z58.object({
1200
- type: z58.literal("pcb_port"),
1201
- pcb_port_id: getZodPrefixedIdWithDefault("pcb_port"),
1202
- pcb_group_id: z58.string().optional(),
1203
- subcircuit_id: z58.string().optional(),
1204
- source_port_id: z58.string(),
1205
- pcb_component_id: z58.string(),
1206
- x: distance,
1207
- y: distance,
1208
- layers: z58.array(layer_ref)
1209
- }).describe("Defines a port on the PCB");
1210
- expectTypesMatch(true);
1211
- var pcb_smtpad_circle = z59.object({
1212
- type: z59.literal("pcb_smtpad"),
1213
- shape: z59.literal("circle"),
1214
- pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"),
1215
- pcb_group_id: z59.string().optional(),
1216
- subcircuit_id: z59.string().optional(),
1217
- x: distance,
1218
- y: distance,
1219
- radius: z59.number(),
1220
- layer: layer_ref,
1221
- port_hints: z59.array(z59.string()).optional(),
1222
- pcb_component_id: z59.string().optional(),
1223
- pcb_port_id: z59.string().optional()
1224
- });
1225
- var pcb_smtpad_rect = z59.object({
1226
- type: z59.literal("pcb_smtpad"),
1227
- shape: z59.literal("rect"),
1228
- pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"),
1229
- pcb_group_id: z59.string().optional(),
1230
- subcircuit_id: z59.string().optional(),
1231
- x: distance,
1232
- y: distance,
1233
- width: z59.number(),
1234
- height: z59.number(),
1235
- layer: layer_ref,
1236
- port_hints: z59.array(z59.string()).optional(),
1237
- pcb_component_id: z59.string().optional(),
1238
- pcb_port_id: z59.string().optional()
1239
- });
1240
- var pcb_smtpad_rotated_rect = z59.object({
1241
- type: z59.literal("pcb_smtpad"),
1242
- shape: z59.literal("rotated_rect"),
1243
- pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"),
1244
- pcb_group_id: z59.string().optional(),
1245
- subcircuit_id: z59.string().optional(),
1246
- x: distance,
1247
- y: distance,
1248
- width: z59.number(),
1249
- height: z59.number(),
1250
- ccw_rotation: rotation,
1251
- layer: layer_ref,
1252
- port_hints: z59.array(z59.string()).optional(),
1253
- pcb_component_id: z59.string().optional(),
1254
- pcb_port_id: z59.string().optional()
1255
- });
1256
- var pcb_smtpad_pill = z59.object({
1257
- type: z59.literal("pcb_smtpad"),
1258
- shape: z59.literal("pill"),
1259
- pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"),
1260
- pcb_group_id: z59.string().optional(),
1261
- subcircuit_id: z59.string().optional(),
1262
- x: distance,
1263
- y: distance,
1264
- width: z59.number(),
1265
- height: z59.number(),
1266
- radius: z59.number(),
1267
- layer: layer_ref,
1268
- port_hints: z59.array(z59.string()).optional(),
1269
- pcb_component_id: z59.string().optional(),
1270
- pcb_port_id: z59.string().optional()
1271
- });
1272
- var pcb_smtpad_polygon = z59.object({
1273
- type: z59.literal("pcb_smtpad"),
1274
- shape: z59.literal("polygon"),
1275
- pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"),
1276
- pcb_group_id: z59.string().optional(),
1277
- subcircuit_id: z59.string().optional(),
1278
- points: z59.array(point),
1279
- layer: layer_ref,
1280
- port_hints: z59.array(z59.string()).optional(),
1281
- pcb_component_id: z59.string().optional(),
1282
- pcb_port_id: z59.string().optional()
1283
- });
1284
- var pcb_smtpad = z59.discriminatedUnion("shape", [
1285
- pcb_smtpad_circle,
1286
- pcb_smtpad_rect,
1287
- pcb_smtpad_rotated_rect,
1288
- pcb_smtpad_pill,
1289
- pcb_smtpad_polygon
1290
- ]).describe("Defines an SMT pad on the PCB");
1291
- expectTypesMatch(true);
1292
- expectTypesMatch(true);
1293
- expectTypesMatch(true);
1294
- expectTypesMatch(true);
1295
- expectTypesMatch(true);
1296
- var pcb_solder_paste_circle = z60.object({
1297
- type: z60.literal("pcb_solder_paste"),
1298
- shape: z60.literal("circle"),
1299
- pcb_solder_paste_id: getZodPrefixedIdWithDefault("pcb_solder_paste"),
1300
- pcb_group_id: z60.string().optional(),
1301
- subcircuit_id: z60.string().optional(),
1302
- x: distance,
1303
- y: distance,
1304
- radius: z60.number(),
1305
- layer: layer_ref,
1306
- pcb_component_id: z60.string().optional(),
1307
- pcb_smtpad_id: z60.string().optional()
1308
- });
1309
- var pcb_solder_paste_rect = z60.object({
1310
- type: z60.literal("pcb_solder_paste"),
1311
- shape: z60.literal("rect"),
1312
- pcb_solder_paste_id: getZodPrefixedIdWithDefault("pcb_solder_paste"),
1313
- pcb_group_id: z60.string().optional(),
1314
- subcircuit_id: z60.string().optional(),
1315
- x: distance,
1316
- y: distance,
1317
- width: z60.number(),
1318
- height: z60.number(),
1319
- layer: layer_ref,
1320
- pcb_component_id: z60.string().optional(),
1321
- pcb_smtpad_id: z60.string().optional()
1322
- });
1323
- var pcb_solder_paste_pill = z60.object({
1324
- type: z60.literal("pcb_solder_paste"),
1325
- shape: z60.literal("pill"),
1326
- pcb_solder_paste_id: getZodPrefixedIdWithDefault("pcb_solder_paste"),
1327
- pcb_group_id: z60.string().optional(),
1328
- subcircuit_id: z60.string().optional(),
1329
- x: distance,
1330
- y: distance,
1331
- width: z60.number(),
1332
- height: z60.number(),
1333
- radius: z60.number(),
1334
- layer: layer_ref,
1335
- pcb_component_id: z60.string().optional(),
1336
- pcb_smtpad_id: z60.string().optional()
1337
- });
1338
- var pcb_solder_paste_rotated_rect = z60.object({
1339
- type: z60.literal("pcb_solder_paste"),
1340
- shape: z60.literal("rotated_rect"),
1341
- pcb_solder_paste_id: getZodPrefixedIdWithDefault("pcb_solder_paste"),
1342
- pcb_group_id: z60.string().optional(),
1343
- subcircuit_id: z60.string().optional(),
1344
- x: distance,
1345
- y: distance,
1346
- width: z60.number(),
1347
- height: z60.number(),
1348
- ccw_rotation: distance,
1349
- layer: layer_ref,
1350
- pcb_component_id: z60.string().optional(),
1351
- pcb_smtpad_id: z60.string().optional()
1352
- });
1353
- var pcb_solder_paste_oval = z60.object({
1354
- type: z60.literal("pcb_solder_paste"),
1355
- shape: z60.literal("oval"),
1356
- pcb_solder_paste_id: getZodPrefixedIdWithDefault("pcb_solder_paste"),
1357
- pcb_group_id: z60.string().optional(),
1358
- subcircuit_id: z60.string().optional(),
1359
- x: distance,
1360
- y: distance,
1361
- width: z60.number(),
1362
- height: z60.number(),
1363
- layer: layer_ref,
1364
- pcb_component_id: z60.string().optional(),
1365
- pcb_smtpad_id: z60.string().optional()
1366
- });
1367
- var pcb_solder_paste = z60.union([
1368
- pcb_solder_paste_circle,
1369
- pcb_solder_paste_rect,
1370
- pcb_solder_paste_pill,
1371
- pcb_solder_paste_rotated_rect,
1372
- pcb_solder_paste_oval
1373
- ]).describe("Defines solderpaste on the PCB");
1374
- expectTypesMatch(true);
1375
- expectTypesMatch(true);
1376
- expectTypesMatch(true);
1377
- expectTypesMatch(
1378
- true
1379
- );
1380
- expectTypesMatch(true);
1381
- var pcb_text = z61.object({
1382
- type: z61.literal("pcb_text"),
1383
- pcb_text_id: getZodPrefixedIdWithDefault("pcb_text"),
1384
- pcb_group_id: z61.string().optional(),
1385
- subcircuit_id: z61.string().optional(),
1386
- text: z61.string(),
1387
- center: point,
1388
- layer: layer_ref,
1389
- width: length,
1390
- height: length,
1391
- lines: z61.number(),
1392
- // @ts-ignore
1393
- align: z61.enum(["bottom-left"])
1394
- }).describe("Defines text on the PCB");
1395
- expectTypesMatch(true);
1396
- var pcb_trace_route_point_wire = z62.object({
1397
- route_type: z62.literal("wire"),
1398
- x: distance,
1399
- y: distance,
1400
- width: distance,
1401
- start_pcb_port_id: z62.string().optional(),
1402
- end_pcb_port_id: z62.string().optional(),
1403
- layer: layer_ref
1404
- });
1405
- var pcb_trace_route_point_via = z62.object({
1406
- route_type: z62.literal("via"),
1407
- x: distance,
1408
- y: distance,
1409
- hole_diameter: distance.optional(),
1410
- outer_diameter: distance.optional(),
1411
- from_layer: z62.string(),
1412
- to_layer: z62.string()
1413
- });
1414
- var pcb_trace_route_point = z62.union([
1415
- pcb_trace_route_point_wire,
1416
- pcb_trace_route_point_via
1417
- ]);
1418
- var pcb_trace = z62.object({
1419
- type: z62.literal("pcb_trace"),
1420
- source_trace_id: z62.string().optional(),
1421
- pcb_component_id: z62.string().optional(),
1422
- pcb_trace_id: getZodPrefixedIdWithDefault("pcb_trace"),
1423
- pcb_group_id: z62.string().optional(),
1424
- subcircuit_id: z62.string().optional(),
1425
- route_thickness_mode: z62.enum(["constant", "interpolated"]).default("constant").optional(),
1426
- route_order_index: z62.number().optional(),
1427
- should_round_corners: z62.boolean().optional(),
1428
- trace_length: z62.number().optional(),
1429
- route: z62.array(pcb_trace_route_point)
1430
- }).describe("Defines a trace on the PCB");
1431
- expectTypesMatch(true);
1432
- expectTypesMatch(true);
1433
- var pcb_trace_error = z63.object({
1434
- type: z63.literal("pcb_trace_error"),
1435
- pcb_trace_error_id: getZodPrefixedIdWithDefault("pcb_trace_error"),
1436
- error_type: z63.literal("pcb_trace_error").default("pcb_trace_error"),
1437
- message: z63.string(),
1438
- center: point.optional(),
1439
- pcb_trace_id: z63.string(),
1440
- source_trace_id: z63.string(),
1441
- pcb_component_ids: z63.array(z63.string()),
1442
- pcb_port_ids: z63.array(z63.string()),
1443
- subcircuit_id: z63.string().optional()
1444
- }).describe("Defines a trace error on the PCB");
1445
- expectTypesMatch(true);
1446
- var pcb_port_not_matched_error = z64.object({
1447
- type: z64.literal("pcb_port_not_matched_error"),
1448
- pcb_error_id: getZodPrefixedIdWithDefault("pcb_error"),
1449
- error_type: z64.literal("pcb_port_not_matched_error").default("pcb_port_not_matched_error"),
1450
- message: z64.string(),
1451
- pcb_component_ids: z64.array(z64.string()),
1452
- subcircuit_id: z64.string().optional()
1453
- }).describe("Defines a trace error on the PCB where a port is not matched");
1454
- expectTypesMatch(true);
1455
- var pcb_via = z65.object({
1456
- type: z65.literal("pcb_via"),
1457
- pcb_via_id: getZodPrefixedIdWithDefault("pcb_via"),
1458
- pcb_group_id: z65.string().optional(),
1459
- subcircuit_id: z65.string().optional(),
1460
- x: distance,
1461
- y: distance,
1462
- outer_diameter: distance.default("0.6mm"),
1463
- hole_diameter: distance.default("0.25mm"),
1464
- /** @deprecated */
1465
- from_layer: layer_ref.optional(),
1466
- /** @deprecated */
1467
- to_layer: layer_ref.optional(),
1468
- layers: z65.array(layer_ref),
1469
- pcb_trace_id: z65.string().optional()
1470
- }).describe("Defines a via on the PCB");
1471
- expectTypesMatch(true);
1472
- var pcb_board = z66.object({
1473
- type: z66.literal("pcb_board"),
1474
- pcb_board_id: getZodPrefixedIdWithDefault("pcb_board"),
1475
- is_subcircuit: z66.boolean().optional(),
1476
- subcircuit_id: z66.string().optional(),
1477
- width: length,
1478
- height: length,
1479
- center: point,
1480
- thickness: length.optional().default(1.4),
1481
- num_layers: z66.number().optional().default(4),
1482
- outline: z66.array(point).optional(),
1483
- material: z66.enum(["fr4", "fr1"]).default("fr4")
1484
- }).describe("Defines the board outline of the PCB");
1485
- expectTypesMatch(true);
1486
- var pcb_placement_error = z67.object({
1487
- type: z67.literal("pcb_placement_error"),
1488
- pcb_placement_error_id: getZodPrefixedIdWithDefault("pcb_placement_error"),
1489
- error_type: z67.literal("pcb_placement_error").default("pcb_placement_error"),
1490
- message: z67.string(),
1491
- subcircuit_id: z67.string().optional()
1492
- }).describe("Defines a placement error on the PCB");
1493
- expectTypesMatch(true);
1494
- var pcb_trace_hint = z68.object({
1495
- type: z68.literal("pcb_trace_hint"),
1496
- pcb_trace_hint_id: getZodPrefixedIdWithDefault("pcb_trace_hint"),
1497
- pcb_port_id: z68.string(),
1498
- pcb_component_id: z68.string(),
1499
- route: z68.array(route_hint_point),
1500
- subcircuit_id: z68.string().optional()
1501
- }).describe("A hint that can be used during generation of a PCB trace");
1502
- expectTypesMatch(true);
1503
- var pcb_silkscreen_line = z69.object({
1504
- type: z69.literal("pcb_silkscreen_line"),
1505
- pcb_silkscreen_line_id: getZodPrefixedIdWithDefault("pcb_silkscreen_line"),
1506
- pcb_component_id: z69.string(),
1507
- pcb_group_id: z69.string().optional(),
1508
- subcircuit_id: z69.string().optional(),
1509
- stroke_width: distance.default("0.1mm"),
1510
- x1: distance,
1511
- y1: distance,
1512
- x2: distance,
1513
- y2: distance,
1514
- layer: visible_layer
1515
- }).describe("Defines a silkscreen line on the PCB");
1516
- expectTypesMatch(true);
1517
- var pcb_silkscreen_path = z70.object({
1518
- type: z70.literal("pcb_silkscreen_path"),
1519
- pcb_silkscreen_path_id: getZodPrefixedIdWithDefault("pcb_silkscreen_path"),
1520
- pcb_component_id: z70.string(),
1521
- pcb_group_id: z70.string().optional(),
1522
- subcircuit_id: z70.string().optional(),
1523
- layer: visible_layer,
1524
- route: z70.array(point),
1525
- stroke_width: length
1526
- }).describe("Defines a silkscreen path on the PCB");
1527
- expectTypesMatch(true);
1528
- var pcb_silkscreen_text = z71.object({
1529
- type: z71.literal("pcb_silkscreen_text"),
1530
- pcb_silkscreen_text_id: getZodPrefixedIdWithDefault("pcb_silkscreen_text"),
1531
- pcb_group_id: z71.string().optional(),
1532
- subcircuit_id: z71.string().optional(),
1533
- font: z71.literal("tscircuit2024").default("tscircuit2024"),
1534
- font_size: distance.default("0.2mm"),
1535
- pcb_component_id: z71.string(),
1536
- text: z71.string(),
1537
- ccw_rotation: z71.number().optional(),
1538
- layer: layer_ref,
1539
- is_mirrored: z71.boolean().default(false).optional(),
1540
- anchor_position: point.default({ x: 0, y: 0 }),
1541
- anchor_alignment: ninePointAnchor.default("center")
1542
- }).describe("Defines silkscreen text on the PCB");
1543
- expectTypesMatch(true);
1544
- var pcb_silkscreen_rect = z72.object({
1545
- type: z72.literal("pcb_silkscreen_rect"),
1546
- pcb_silkscreen_rect_id: getZodPrefixedIdWithDefault("pcb_silkscreen_rect"),
1547
- pcb_component_id: z72.string(),
1548
- pcb_group_id: z72.string().optional(),
1549
- subcircuit_id: z72.string().optional(),
1550
- center: point,
1551
- width: length,
1552
- height: length,
1553
- layer: layer_ref,
1554
- stroke_width: length.default("1mm"),
1555
- is_filled: z72.boolean().default(true).optional(),
1556
- has_stroke: z72.boolean().optional(),
1557
- is_stroke_dashed: z72.boolean().optional()
1558
- }).describe("Defines a silkscreen rect on the PCB");
1559
- expectTypesMatch(true);
1560
- var pcb_silkscreen_circle = z73.object({
1561
- type: z73.literal("pcb_silkscreen_circle"),
1562
- pcb_silkscreen_circle_id: getZodPrefixedIdWithDefault(
1563
- "pcb_silkscreen_circle"
1564
- ),
1565
- pcb_component_id: z73.string(),
1566
- pcb_group_id: z73.string().optional(),
1567
- subcircuit_id: z73.string().optional(),
1568
- center: point,
1569
- radius: length,
1570
- layer: visible_layer,
1571
- stroke_width: length.default("1mm")
1572
- }).describe("Defines a silkscreen circle on the PCB");
1573
- expectTypesMatch(true);
1574
- var pcb_silkscreen_oval = z74.object({
1575
- type: z74.literal("pcb_silkscreen_oval"),
1576
- pcb_silkscreen_oval_id: getZodPrefixedIdWithDefault("pcb_silkscreen_oval"),
1577
- pcb_component_id: z74.string(),
1578
- pcb_group_id: z74.string().optional(),
1579
- subcircuit_id: z74.string().optional(),
1580
- center: point,
1581
- radius_x: distance,
1582
- radius_y: distance,
1583
- layer: visible_layer
1584
- }).describe("Defines a silkscreen oval on the PCB");
1585
- expectTypesMatch(true);
1586
- var pcb_fabrication_note_text = z75.object({
1587
- type: z75.literal("pcb_fabrication_note_text"),
1588
- pcb_fabrication_note_text_id: getZodPrefixedIdWithDefault(
1589
- "pcb_fabrication_note_text"
1590
- ),
1591
- subcircuit_id: z75.string().optional(),
1592
- pcb_group_id: z75.string().optional(),
1593
- font: z75.literal("tscircuit2024").default("tscircuit2024"),
1594
- font_size: distance.default("1mm"),
1595
- pcb_component_id: z75.string(),
1596
- text: z75.string(),
1597
- layer: visible_layer,
1598
- anchor_position: point.default({ x: 0, y: 0 }),
1599
- anchor_alignment: z75.enum(["center", "top_left", "top_right", "bottom_left", "bottom_right"]).default("center"),
1600
- color: z75.string().optional()
1601
- }).describe(
1602
- "Defines a fabrication note in text on the PCB, useful for leaving notes for assemblers or fabricators"
1603
- );
1604
- expectTypesMatch(true);
1605
- var pcb_fabrication_note_path = z76.object({
1606
- type: z76.literal("pcb_fabrication_note_path"),
1607
- pcb_fabrication_note_path_id: getZodPrefixedIdWithDefault(
1608
- "pcb_fabrication_note_path"
1609
- ),
1610
- pcb_component_id: z76.string(),
1611
- subcircuit_id: z76.string().optional(),
1612
- layer: layer_ref,
1613
- route: z76.array(point),
1614
- stroke_width: length,
1615
- color: z76.string().optional()
1616
- }).describe(
1617
- "Defines a fabrication path on the PCB for fabricators or assemblers"
1618
- );
1619
- expectTypesMatch(true);
1620
- var pcb_keepout = z77.object({
1621
- type: z77.literal("pcb_keepout"),
1622
- shape: z77.literal("rect"),
1623
- pcb_group_id: z77.string().optional(),
1624
- subcircuit_id: z77.string().optional(),
1625
- center: point,
1626
- width: distance,
1627
- height: distance,
1628
- pcb_keepout_id: z77.string(),
1629
- layers: z77.array(z77.string()),
1630
- // Specify layers where the keepout applies
1631
- description: z77.string().optional()
1632
- // Optional description of the keepout
1633
- }).or(
1634
- z77.object({
1635
- type: z77.literal("pcb_keepout"),
1636
- shape: z77.literal("circle"),
1637
- pcb_group_id: z77.string().optional(),
1638
- subcircuit_id: z77.string().optional(),
1639
- center: point,
1640
- radius: distance,
1641
- pcb_keepout_id: z77.string(),
1642
- layers: z77.array(z77.string()),
1643
- // Specify layers where the keepout applies
1644
- description: z77.string().optional()
1645
- // Optional description of the keepout
1646
- })
1647
- );
1648
- expectTypesMatch(true);
1649
- var pcb_cutout_base = z78.object({
1650
- type: z78.literal("pcb_cutout"),
1651
- pcb_cutout_id: getZodPrefixedIdWithDefault("pcb_cutout"),
1652
- pcb_group_id: z78.string().optional(),
1653
- subcircuit_id: z78.string().optional()
1654
- });
1655
- var pcb_cutout_rect = pcb_cutout_base.extend({
1656
- shape: z78.literal("rect"),
1657
- center: point,
1658
- width: length,
1659
- height: length,
1660
- rotation: rotation.optional()
1661
- });
1662
- expectTypesMatch(true);
1663
- var pcb_cutout_circle = pcb_cutout_base.extend({
1664
- shape: z78.literal("circle"),
1665
- center: point,
1666
- radius: length
1667
- });
1668
- expectTypesMatch(true);
1669
- var pcb_cutout_polygon = pcb_cutout_base.extend({
1670
- shape: z78.literal("polygon"),
1671
- points: z78.array(point)
1672
- });
1673
- expectTypesMatch(true);
1674
- var pcb_cutout = z78.discriminatedUnion("shape", [
1675
- pcb_cutout_rect,
1676
- pcb_cutout_circle,
1677
- pcb_cutout_polygon
1678
- ]).describe("Defines a cutout on the PCB, removing board material.");
1679
- expectTypesMatch(true);
1680
- var pcb_missing_footprint_error = z79.object({
1681
- type: z79.literal("pcb_missing_footprint_error"),
1682
- pcb_missing_footprint_error_id: getZodPrefixedIdWithDefault(
1683
- "pcb_missing_footprint_error"
1684
- ),
1685
- pcb_group_id: z79.string().optional(),
1686
- subcircuit_id: z79.string().optional(),
1687
- error_type: z79.literal("pcb_missing_footprint_error").default("pcb_missing_footprint_error"),
1688
- source_component_id: z79.string(),
1689
- message: z79.string()
1690
- }).describe("Defines a missing footprint error on the PCB");
1691
- expectTypesMatch(
1692
- true
1693
- );
1694
- var pcb_group = z80.object({
1695
- type: z80.literal("pcb_group"),
1696
- pcb_group_id: getZodPrefixedIdWithDefault("pcb_group"),
1697
- source_group_id: z80.string(),
1698
- is_subcircuit: z80.boolean().optional(),
1699
- subcircuit_id: z80.string().optional(),
1700
- width: length,
1701
- height: length,
1702
- center: point,
1703
- pcb_component_ids: z80.array(z80.string()),
1704
- name: z80.string().optional(),
1705
- description: z80.string().optional(),
1706
- autorouter_configuration: z80.object({
1707
- trace_clearance: length
1708
- }).optional(),
1709
- autorouter_used_string: z80.string().optional()
1710
- }).describe("Defines a group of components on the PCB");
1711
- expectTypesMatch(true);
1712
- var pcb_autorouting_error = z81.object({
1713
- type: z81.literal("pcb_autorouting_error"),
1714
- pcb_error_id: getZodPrefixedIdWithDefault("pcb_autorouting_error"),
1715
- error_type: z81.literal("pcb_autorouting_error").default("pcb_autorouting_error"),
1716
- message: z81.string(),
1717
- subcircuit_id: z81.string().optional()
1718
- }).describe("The autorouting has failed to route a portion of the board");
1719
- expectTypesMatch(true);
1720
- var pcb_manual_edit_conflict_warning = z82.object({
1721
- type: z82.literal("pcb_manual_edit_conflict_warning"),
1722
- pcb_manual_edit_conflict_warning_id: getZodPrefixedIdWithDefault(
1723
- "pcb_manual_edit_conflict_warning"
1724
- ),
1725
- warning_type: z82.literal("pcb_manual_edit_conflict_warning").default("pcb_manual_edit_conflict_warning"),
1726
- message: z82.string(),
1727
- pcb_component_id: z82.string(),
1728
- pcb_group_id: z82.string().optional(),
1729
- subcircuit_id: z82.string().optional(),
1730
- source_component_id: z82.string()
1731
- }).describe(
1732
- "Warning emitted when a component has both manual placement and explicit pcbX/pcbY coordinates"
1733
- );
1734
- expectTypesMatch(true);
1735
- var pcb_breakout_point = z83.object({
1736
- type: z83.literal("pcb_breakout_point"),
1737
- pcb_breakout_point_id: getZodPrefixedIdWithDefault("pcb_breakout_point"),
1738
- pcb_group_id: z83.string(),
1739
- subcircuit_id: z83.string().optional(),
1740
- source_trace_id: z83.string().optional(),
1741
- source_port_id: z83.string().optional(),
1742
- source_net_id: z83.string().optional(),
1743
- x: distance,
1744
- y: distance
1745
- }).describe(
1746
- "Defines a routing target within a pcb_group for a source_trace or source_net"
1747
- );
1748
- expectTypesMatch(true);
1749
- var pcb_ground_plane = z84.object({
1750
- type: z84.literal("pcb_ground_plane"),
1751
- pcb_ground_plane_id: getZodPrefixedIdWithDefault("pcb_ground_plane"),
1752
- source_pcb_ground_plane_id: z84.string(),
1753
- source_net_id: z84.string(),
1754
- pcb_group_id: z84.string().optional(),
1755
- subcircuit_id: z84.string().optional()
1756
- }).describe("Defines a ground plane on the PCB");
1757
- expectTypesMatch(true);
1758
- var pcb_ground_plane_region = z85.object({
1759
- type: z85.literal("pcb_ground_plane_region"),
1760
- pcb_ground_plane_region_id: getZodPrefixedIdWithDefault(
1761
- "pcb_ground_plane_region"
1762
- ),
1763
- pcb_ground_plane_id: z85.string(),
1764
- pcb_group_id: z85.string().optional(),
1765
- subcircuit_id: z85.string().optional(),
1766
- layer: layer_ref,
1767
- points: z85.array(point)
1768
- }).describe("Defines a polygon region of a ground plane");
1769
- expectTypesMatch(true);
1770
- var pcb_thermal_spoke = z86.object({
1771
- type: z86.literal("pcb_thermal_spoke"),
1772
- pcb_thermal_spoke_id: getZodPrefixedIdWithDefault("pcb_thermal_spoke"),
1773
- pcb_ground_plane_id: z86.string(),
1774
- shape: z86.string(),
1775
- spoke_count: z86.number(),
1776
- spoke_thickness: distance,
1777
- spoke_inner_diameter: distance,
1778
- spoke_outer_diameter: distance,
1779
- pcb_plated_hole_id: z86.string().optional(),
1780
- subcircuit_id: z86.string().optional()
1781
- }).describe("Pattern for connecting a ground plane to a plated hole");
1782
- expectTypesMatch(true);
1783
- var cad_component = z87.object({
1784
- type: z87.literal("cad_component"),
1785
- cad_component_id: z87.string(),
1786
- pcb_component_id: z87.string(),
1787
- source_component_id: z87.string(),
1788
- position: point3,
1789
- rotation: point3.optional(),
1790
- size: point3.optional(),
1791
- layer: layer_ref.optional(),
1792
- subcircuit_id: z87.string().optional(),
1793
- // These are all ways to generate/load the 3d model
1794
- footprinter_string: z87.string().optional(),
1795
- model_obj_url: z87.string().optional(),
1796
- model_stl_url: z87.string().optional(),
1797
- model_3mf_url: z87.string().optional(),
1798
- model_jscad: z87.any().optional()
1799
- }).describe("Defines a component on the PCB");
1800
- expectTypesMatch(true);
1801
- var any_circuit_element = z88.union([
1802
- source_trace,
1803
- source_port,
1804
- any_source_component,
1805
- source_net,
1806
- source_group,
1807
- source_simple_chip,
1808
- source_simple_capacitor,
1809
- source_simple_diode,
1810
- source_simple_led,
1811
- source_simple_resistor,
1812
- source_simple_power_source,
1813
- source_simple_battery,
1814
- source_simple_inductor,
1815
- source_simple_pin_header,
1816
- source_simple_resonator,
1817
- source_simple_switch,
1818
- source_simple_transistor,
1819
- source_simple_test_point,
1820
- source_simple_mosfet,
1821
- source_simple_potentiometer,
1822
- source_simple_push_button,
1823
- source_pcb_ground_plane,
1824
- source_project_metadata,
1825
- pcb_component,
1826
- pcb_hole,
1827
- pcb_missing_footprint_error,
1828
- pcb_manual_edit_conflict_warning,
1829
- pcb_plated_hole,
1830
- pcb_keepout,
1831
- pcb_port,
1832
- pcb_text,
1833
- pcb_trace,
1834
- pcb_via,
1835
- pcb_smtpad,
1836
- pcb_solder_paste,
1837
- pcb_board,
1838
- pcb_group,
1839
- pcb_trace_hint,
1840
- pcb_silkscreen_line,
1841
- pcb_silkscreen_path,
1842
- pcb_silkscreen_text,
1843
- pcb_silkscreen_rect,
1844
- pcb_silkscreen_circle,
1845
- pcb_silkscreen_oval,
1846
- pcb_trace_error,
1847
- pcb_placement_error,
1848
- pcb_port_not_matched_error,
1849
- pcb_fabrication_note_path,
1850
- pcb_fabrication_note_text,
1851
- pcb_autorouting_error,
1852
- pcb_breakout_point,
1853
- pcb_cutout,
1854
- pcb_ground_plane,
1855
- pcb_ground_plane_region,
1856
- pcb_thermal_spoke,
1857
- schematic_box,
1858
- schematic_text,
1859
- schematic_line,
1860
- schematic_component,
1861
- schematic_port,
1862
- schematic_trace,
1863
- schematic_path,
1864
- schematic_error,
1865
- schematic_layout_error,
1866
- schematic_net_label,
1867
- schematic_debug_object,
1868
- schematic_voltage_probe,
1869
- schematic_manual_edit_conflict_warning,
1870
- schematic_group,
1871
- cad_component
1872
- ]);
1873
- var any_soup_element = any_circuit_element;
1874
- expectTypesMatch(true);
1875
- expectStringUnionsMatch(true);
1876
-
1877
- // lib/math/arc-utils.ts
1878
- function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag, sweepFlag) {
1879
- const start = { x: startX, y: startY };
1880
- const end = { x: endX, y: endY };
1881
- const midX = (startX + endX) / 2;
1882
- const midY = (startY + endY) / 2;
1883
- const dx = endX - startX;
1884
- const dy = endY - startY;
1885
- const distance2 = Math.sqrt(dx * dx + dy * dy);
1886
- if (distance2 === 0 || radius < distance2 / 2) {
1887
- return [start, end];
1888
- }
1889
- const h = Math.sqrt(radius * radius - distance2 * distance2 / 4);
1890
- const angle = Math.atan2(dy, dx);
1891
- const centerX = midX + h * Math.sin(angle) * (sweepFlag ? -1 : 1);
1892
- const centerY = midY - h * Math.cos(angle) * (sweepFlag ? -1 : 1);
1893
- const startAngle = Math.atan2(startY - centerY, startX - centerX);
1894
- let endAngle = Math.atan2(endY - centerY, endX - centerX);
1895
- if (sweepFlag && endAngle > startAngle) {
1896
- endAngle -= 2 * Math.PI;
1897
- } else if (!sweepFlag && endAngle < startAngle) {
1898
- endAngle += 2 * Math.PI;
1899
- }
1900
- if (!largeArcFlag && Math.abs(endAngle - startAngle) > Math.PI || largeArcFlag && Math.abs(endAngle - startAngle) < Math.PI) {
1901
- if (endAngle > startAngle) {
1902
- endAngle -= 2 * Math.PI;
1903
- } else {
1904
- endAngle += 2 * Math.PI;
1905
- }
1906
- }
1907
- const numPoints = Math.max(
1908
- 2,
1909
- Math.ceil(Math.abs(endAngle - startAngle) * radius)
1910
- );
1911
- const path2 = [];
1912
- for (let i = 0; i <= numPoints; i++) {
1913
- const t = i / numPoints;
1914
- const angle2 = startAngle + t * (endAngle - startAngle);
1915
- const x = centerX + radius * Math.cos(angle2);
1916
- const y = centerY + radius * Math.sin(angle2);
1917
- path2.push({ x, y });
1918
- }
1919
- return path2;
1920
- }
1921
-
1922
- // node_modules/@tscircuit/circuit-json-util/dist/index.js
1923
- import { applyToPoint, decomposeTSR } from "transformation-matrix";
1924
- function connect(map, a, b) {
1925
- if (!a || !b)
1926
- return;
1927
- let setA = map.get(a);
1928
- if (!setA) {
1929
- setA = /* @__PURE__ */ new Set();
1930
- map.set(a, setA);
1931
- }
1932
- setA.add(b);
1933
- let setB = map.get(b);
1934
- if (!setB) {
1935
- setB = /* @__PURE__ */ new Set();
1936
- map.set(b, setB);
1937
- }
1938
- setB.add(a);
1939
- }
1940
- function buildSubtree(soup, opts) {
1941
- if (!opts.subcircuit_id && !opts.source_group_id)
1942
- return [...soup];
1943
- const idMap = /* @__PURE__ */ new Map();
1944
- for (const elm of soup) {
1945
- const idVal = elm[`${elm.type}_id`];
1946
- if (typeof idVal === "string") {
1947
- idMap.set(idVal, elm);
1948
- }
1949
- }
1950
- const adj = /* @__PURE__ */ new Map();
1951
- for (const elm of soup) {
1952
- const entries = Object.entries(elm);
1953
- for (const [key, val] of entries) {
1954
- if (key.endsWith("_id") && typeof val === "string") {
1955
- const other = idMap.get(val);
1956
- connect(adj, elm, other);
1957
- } else if (key.endsWith("_ids") && Array.isArray(val)) {
1958
- for (const v of val) {
1959
- if (typeof v === "string") {
1960
- const other = idMap.get(v);
1961
- connect(adj, elm, other);
1962
- }
1963
- }
1964
- }
1965
- }
1966
- }
1967
- const queue = [];
1968
- const included = /* @__PURE__ */ new Set();
1969
- for (const elm of soup) {
1970
- if (opts.subcircuit_id && elm.subcircuit_id === opts.subcircuit_id || opts.source_group_id && (elm.source_group_id === opts.source_group_id || Array.isArray(elm.member_source_group_ids) && elm.member_source_group_ids.includes(
1971
- opts.source_group_id
1972
- ))) {
1973
- queue.push(elm);
1974
- included.add(elm);
1975
- }
1976
- }
1977
- while (queue.length > 0) {
1978
- const elm = queue.shift();
1979
- const neighbors = adj.get(elm);
1980
- if (!neighbors)
1981
- continue;
1982
- for (const n of neighbors) {
1983
- if (!included.has(n)) {
1984
- included.add(n);
1985
- queue.push(n);
1986
- }
1987
- }
1988
- }
1989
- return soup.filter((e) => included.has(e));
1990
- }
1991
- var cju = (circuitJsonInput, options = {}) => {
1992
- const circuitJson = circuitJsonInput;
1993
- let internalStore = circuitJson._internal_store;
1994
- if (!internalStore) {
1995
- internalStore = {
1996
- counts: {},
1997
- editCount: 0
1998
- };
1999
- circuitJson._internal_store = internalStore;
2000
- for (const elm of circuitJson) {
2001
- const type = elm.type;
2002
- const idVal = elm[`${type}_id`];
2003
- if (!idVal)
2004
- continue;
2005
- const idNum = Number.parseInt(idVal.split("_").pop());
2006
- if (!Number.isNaN(idNum)) {
2007
- internalStore.counts[type] = Math.max(
2008
- internalStore.counts[type] ?? 0,
2009
- idNum
2010
- );
2011
- }
2012
- }
2013
- }
2014
- const su2 = new Proxy(
2015
- {},
2016
- {
2017
- get: (proxy_target, prop) => {
2018
- if (prop === "toArray") {
2019
- return () => {
2020
- ;
2021
- circuitJson.editCount = internalStore.editCount;
2022
- return circuitJson;
2023
- };
2024
- }
2025
- if (prop === "editCount") {
2026
- return internalStore.editCount;
2027
- }
2028
- if (prop === "subtree") {
2029
- return (opts) => cju(buildSubtree(circuitJson, opts), options);
2030
- }
2031
- const component_type = prop;
2032
- return {
2033
- get: (id) => circuitJson.find(
2034
- (e) => e.type === component_type && e[`${component_type}_id`] === id
2035
- ),
2036
- getUsing: (using) => {
2037
- const keys = Object.keys(using);
2038
- if (keys.length !== 1) {
2039
- throw new Error(
2040
- "getUsing requires exactly one key, e.g. { pcb_component_id }"
2041
- );
2042
- }
2043
- const join_key = keys[0];
2044
- const join_type = join_key.replace("_id", "");
2045
- const joiner = circuitJson.find(
2046
- (e) => e.type === join_type && e[join_key] === using[join_key]
2047
- );
2048
- if (!joiner)
2049
- return null;
2050
- return circuitJson.find(
2051
- (e) => e.type === component_type && e[`${component_type}_id`] === joiner[`${component_type}_id`]
2052
- );
2053
- },
2054
- getWhere: (where) => {
2055
- const keys = Object.keys(where);
2056
- return circuitJson.find(
2057
- (e) => e.type === component_type && keys.every((key) => e[key] === where[key])
2058
- );
2059
- },
2060
- list: (where) => {
2061
- const keys = !where ? [] : Object.keys(where);
2062
- return circuitJson.filter(
2063
- (e) => e.type === component_type && keys.every((key) => e[key] === where[key])
2064
- );
2065
- },
2066
- insert: (elm) => {
2067
- internalStore.counts[component_type] ??= -1;
2068
- internalStore.counts[component_type]++;
2069
- const index = internalStore.counts[component_type];
2070
- const newElm = {
2071
- type: component_type,
2072
- [`${component_type}_id`]: `${component_type}_${index}`,
2073
- ...elm
2074
- };
2075
- if (options.validateInserts) {
2076
- const parser = dist_exports[component_type] ?? any_soup_element;
2077
- parser.parse(newElm);
2078
- }
2079
- circuitJson.push(newElm);
2080
- internalStore.editCount++;
2081
- return newElm;
2082
- },
2083
- delete: (id) => {
2084
- const elm = circuitJson.find(
2085
- (e) => e[`${component_type}_id`] === id
2086
- );
2087
- if (!elm)
2088
- return;
2089
- circuitJson.splice(circuitJson.indexOf(elm), 1);
2090
- internalStore.editCount++;
2091
- },
2092
- update: (id, newProps) => {
2093
- const elm = circuitJson.find(
2094
- (e) => e.type === component_type && e[`${component_type}_id`] === id
2095
- );
2096
- if (!elm)
2097
- return null;
2098
- Object.assign(elm, newProps);
2099
- internalStore.editCount++;
2100
- return elm;
2101
- },
2102
- select: (selector) => {
2103
- if (component_type === "source_component") {
2104
- return circuitJson.find(
2105
- (e) => e.type === "source_component" && e.name === selector.replace(/\./g, "")
2106
- );
2107
- } else if (component_type === "pcb_port" || component_type === "source_port" || component_type === "schematic_port") {
2108
- const [component_name, port_selector] = selector.replace(/\./g, "").split(/[\s\>]+/);
2109
- const source_component = circuitJson.find(
2110
- (e) => e.type === "source_component" && e.name === component_name
2111
- );
2112
- if (!source_component)
2113
- return null;
2114
- const source_port2 = circuitJson.find(
2115
- (e) => e.type === "source_port" && e.source_component_id === source_component.source_component_id && (e.name === port_selector || (e.port_hints ?? []).includes(port_selector))
2116
- );
2117
- if (!source_port2)
2118
- return null;
2119
- if (component_type === "source_port")
2120
- return source_port2;
2121
- if (component_type === "pcb_port") {
2122
- return circuitJson.find(
2123
- (e) => e.type === "pcb_port" && e.source_port_id === source_port2.source_port_id
2124
- );
2125
- } else if (component_type === "schematic_port") {
2126
- return circuitJson.find(
2127
- (e) => e.type === "schematic_port" && e.source_port_id === source_port2.source_port_id
2128
- );
2129
- }
2130
- }
2131
- }
2132
- };
2133
- }
2134
- }
2135
- );
2136
- return su2;
2137
- };
2138
- cju.unparsed = cju;
2139
- var su = cju;
2140
- function createIdKey(element) {
2141
- const type = element.type;
2142
- return `${type}:${element[`${type}_id`]}`;
2143
- }
2144
- var cjuIndexed = (soup, options = {}) => {
2145
- let internalStore = soup._internal_store_indexed;
2146
- if (!internalStore) {
2147
- internalStore = {
2148
- counts: {},
2149
- editCount: 0,
2150
- indexes: {}
2151
- };
2152
- for (const elm of soup) {
2153
- const type = elm.type;
2154
- const idVal = elm[`${type}_id`];
2155
- if (!idVal)
2156
- continue;
2157
- const idNum = Number.parseInt(idVal.split("_").pop() || "");
2158
- if (!Number.isNaN(idNum)) {
2159
- internalStore.counts[type] = Math.max(
2160
- internalStore.counts[type] ?? 0,
2161
- idNum
2162
- );
2163
- }
2164
- }
2165
- const indexConfig = options.indexConfig || {};
2166
- const indexes = internalStore.indexes;
2167
- if (indexConfig.byId) {
2168
- indexes.byId = /* @__PURE__ */ new Map();
2169
- }
2170
- if (indexConfig.byType) {
2171
- indexes.byType = /* @__PURE__ */ new Map();
2172
- }
2173
- if (indexConfig.byRelation) {
2174
- indexes.byRelation = /* @__PURE__ */ new Map();
2175
- }
2176
- if (indexConfig.bySubcircuit) {
2177
- indexes.bySubcircuit = /* @__PURE__ */ new Map();
2178
- }
2179
- if (indexConfig.byCustomField && indexConfig.byCustomField.length > 0) {
2180
- indexes.byCustomField = /* @__PURE__ */ new Map();
2181
- for (const field of indexConfig.byCustomField) {
2182
- indexes.byCustomField.set(field, /* @__PURE__ */ new Map());
2183
- }
2184
- }
2185
- for (const element of soup) {
2186
- if (indexConfig.byId) {
2187
- const idKey = createIdKey(element);
2188
- indexes.byId.set(idKey, element);
2189
- }
2190
- if (indexConfig.byType) {
2191
- const elementsOfType = indexes.byType.get(element.type) || [];
2192
- elementsOfType.push(element);
2193
- indexes.byType.set(element.type, elementsOfType);
2194
- }
2195
- if (indexConfig.byRelation) {
2196
- const elementEntries = Object.entries(element);
2197
- for (const [key, value] of elementEntries) {
2198
- if (key.endsWith("_id") && key !== `${element.type}_id` && typeof value === "string") {
2199
- const relationTypeMap = indexes.byRelation.get(key) || /* @__PURE__ */ new Map();
2200
- const relatedElements = relationTypeMap.get(value) || [];
2201
- relatedElements.push(element);
2202
- relationTypeMap.set(value, relatedElements);
2203
- indexes.byRelation.set(key, relationTypeMap);
2204
- }
2205
- }
2206
- }
2207
- if (indexConfig.bySubcircuit && "subcircuit_id" in element) {
2208
- const subcircuitId = element.subcircuit_id;
2209
- if (subcircuitId && typeof subcircuitId === "string") {
2210
- const subcircuitElements = indexes.bySubcircuit.get(subcircuitId) || [];
2211
- subcircuitElements.push(element);
2212
- indexes.bySubcircuit.set(subcircuitId, subcircuitElements);
2213
- }
2214
- }
2215
- if (indexConfig.byCustomField && indexes.byCustomField) {
2216
- for (const field of indexConfig.byCustomField) {
2217
- if (field in element) {
2218
- const fieldValue = element[field];
2219
- if (fieldValue !== void 0 && (typeof fieldValue === "string" || typeof fieldValue === "number")) {
2220
- const fieldValueStr = String(fieldValue);
2221
- const fieldMap = indexes.byCustomField.get(field);
2222
- const elementsWithFieldValue = fieldMap.get(fieldValueStr) || [];
2223
- elementsWithFieldValue.push(element);
2224
- fieldMap.set(fieldValueStr, elementsWithFieldValue);
2225
- }
2226
- }
2227
- }
2228
- }
2229
- }
2230
- ;
2231
- soup._internal_store_indexed = internalStore;
2232
- }
2233
- const suIndexed = new Proxy(
2234
- {},
2235
- {
2236
- get: (proxy_target, prop) => {
2237
- if (prop === "toArray") {
2238
- return () => {
2239
- ;
2240
- soup.editCount = internalStore.editCount;
2241
- return soup;
2242
- };
2243
- }
2244
- if (prop === "editCount") {
2245
- return internalStore.editCount;
2246
- }
2247
- const component_type = prop;
2248
- return {
2249
- get: (id) => {
2250
- const indexConfig = options.indexConfig || {};
2251
- if (indexConfig.byId && internalStore.indexes.byId) {
2252
- return internalStore.indexes.byId.get(
2253
- `${component_type}:${id}`
2254
- ) || null;
2255
- }
2256
- if (indexConfig.byType && internalStore.indexes.byType) {
2257
- const elementsOfType = internalStore.indexes.byType.get(component_type) || [];
2258
- return elementsOfType.find(
2259
- (e) => e[`${component_type}_id`] === id
2260
- ) || null;
2261
- }
2262
- return soup.find(
2263
- (e) => e.type === component_type && e[`${component_type}_id`] === id
2264
- ) || null;
2265
- },
2266
- getUsing: (using) => {
2267
- const indexConfig = options.indexConfig || {};
2268
- const keys = Object.keys(using);
2269
- if (keys.length !== 1) {
2270
- throw new Error(
2271
- "getUsing requires exactly one key, e.g. { pcb_component_id }"
2272
- );
2273
- }
2274
- const join_key = keys[0];
2275
- const join_type = join_key.replace("_id", "");
2276
- if (indexConfig.byRelation && internalStore.indexes.byRelation) {
2277
- const relationMap = internalStore.indexes.byRelation.get(join_key);
2278
- if (relationMap) {
2279
- const relatedElements = relationMap.get(using[join_key]) || [];
2280
- const joiner2 = relatedElements.find((e) => e.type === join_type);
2281
- if (!joiner2)
2282
- return null;
2283
- const joinerId = joiner2[`${component_type}_id`];
2284
- if (indexConfig.byId && internalStore.indexes.byId) {
2285
- return internalStore.indexes.byId.get(
2286
- `${component_type}:${joinerId}`
2287
- ) || null;
2288
- }
2289
- if (indexConfig.byType && internalStore.indexes.byType) {
2290
- const elementsOfType = internalStore.indexes.byType.get(component_type) || [];
2291
- return elementsOfType.find(
2292
- (e) => e[`${component_type}_id`] === joinerId
2293
- ) || null;
2294
- }
2295
- return soup.find(
2296
- (e) => e.type === component_type && e[`${component_type}_id`] === joinerId
2297
- ) || null;
2298
- }
2299
- }
2300
- const joiner = soup.find(
2301
- (e) => e.type === join_type && e[join_key] === using[join_key]
2302
- );
2303
- if (!joiner)
2304
- return null;
2305
- return soup.find(
2306
- (e) => e.type === component_type && e[`${component_type}_id`] === joiner[`${component_type}_id`]
2307
- ) || null;
2308
- },
2309
- getWhere: (where) => {
2310
- const indexConfig = options.indexConfig || {};
2311
- const keys = Object.keys(where);
2312
- if (keys.length === 1 && indexConfig.byCustomField && internalStore.indexes.byCustomField) {
2313
- const field = keys[0];
2314
- const fieldMap = internalStore.indexes.byCustomField.get(field);
2315
- if (fieldMap) {
2316
- const fieldValue = String(where[field]);
2317
- const elementsWithFieldValue = fieldMap.get(fieldValue) || [];
2318
- return elementsWithFieldValue.find(
2319
- (e) => e.type === component_type
2320
- ) || null;
2321
- }
2322
- }
2323
- if ("subcircuit_id" in where && indexConfig.bySubcircuit && internalStore.indexes.bySubcircuit) {
2324
- const subcircuitId = where.subcircuit_id;
2325
- const subcircuitElements = internalStore.indexes.bySubcircuit.get(subcircuitId) || [];
2326
- return subcircuitElements.find(
2327
- (e) => e.type === component_type && keys.every((key) => e[key] === where[key])
2328
- ) || null;
2329
- }
2330
- if (indexConfig.byType && internalStore.indexes.byType) {
2331
- const elementsOfType = internalStore.indexes.byType.get(component_type) || [];
2332
- return elementsOfType.find(
2333
- (e) => keys.every((key) => e[key] === where[key])
2334
- ) || null;
2335
- }
2336
- return soup.find(
2337
- (e) => e.type === component_type && keys.every((key) => e[key] === where[key])
2338
- ) || null;
2339
- },
2340
- list: (where) => {
2341
- const indexConfig = options.indexConfig || {};
2342
- const keys = !where ? [] : Object.keys(where);
2343
- if (keys.length === 0 && indexConfig.byType && internalStore.indexes.byType) {
2344
- return internalStore.indexes.byType.get(component_type) || [];
2345
- }
2346
- if (keys.length === 1 && keys[0] === "subcircuit_id" && indexConfig.bySubcircuit && internalStore.indexes.bySubcircuit) {
2347
- const subcircuitId = where.subcircuit_id;
2348
- const subcircuitElements = internalStore.indexes.bySubcircuit.get(subcircuitId) || [];
2349
- return subcircuitElements.filter(
2350
- (e) => e.type === component_type
2351
- );
2352
- }
2353
- let elementsToFilter;
2354
- if (indexConfig.byType && internalStore.indexes.byType) {
2355
- elementsToFilter = internalStore.indexes.byType.get(component_type) || [];
2356
- } else {
2357
- elementsToFilter = soup.filter((e) => e.type === component_type);
2358
- }
2359
- if (keys.length > 0) {
2360
- return elementsToFilter.filter(
2361
- (e) => keys.every((key) => e[key] === where[key])
2362
- );
2363
- }
2364
- return elementsToFilter;
2365
- },
2366
- insert: (elm) => {
2367
- internalStore.counts[component_type] ??= -1;
2368
- internalStore.counts[component_type]++;
2369
- const index = internalStore.counts[component_type];
2370
- const newElm = {
2371
- type: component_type,
2372
- [`${component_type}_id`]: `${component_type}_${index}`,
2373
- ...elm
2374
- };
2375
- if (options.validateInserts) {
2376
- const parser = dist_exports[component_type] ?? any_soup_element;
2377
- parser.parse(newElm);
2378
- }
2379
- soup.push(newElm);
2380
- internalStore.editCount++;
2381
- const indexConfig = options.indexConfig || {};
2382
- if (indexConfig.byId && internalStore.indexes.byId) {
2383
- const idKey = createIdKey(newElm);
2384
- internalStore.indexes.byId.set(idKey, newElm);
2385
- }
2386
- if (indexConfig.byType && internalStore.indexes.byType) {
2387
- const elementsOfType = internalStore.indexes.byType.get(component_type) || [];
2388
- elementsOfType.push(newElm);
2389
- internalStore.indexes.byType.set(component_type, elementsOfType);
2390
- }
2391
- if (indexConfig.byRelation && internalStore.indexes.byRelation) {
2392
- const elementEntries = Object.entries(newElm);
2393
- for (const [key, value] of elementEntries) {
2394
- if (key.endsWith("_id") && key !== `${newElm.type}_id` && typeof value === "string") {
2395
- const relationTypeMap = internalStore.indexes.byRelation.get(key) || /* @__PURE__ */ new Map();
2396
- const relatedElements = relationTypeMap.get(value) || [];
2397
- relatedElements.push(newElm);
2398
- relationTypeMap.set(value, relatedElements);
2399
- internalStore.indexes.byRelation.set(key, relationTypeMap);
2400
- }
2401
- }
2402
- }
2403
- if (indexConfig.bySubcircuit && internalStore.indexes.bySubcircuit && "subcircuit_id" in newElm) {
2404
- const subcircuitId = newElm.subcircuit_id;
2405
- if (subcircuitId && typeof subcircuitId === "string") {
2406
- const subcircuitElements = internalStore.indexes.bySubcircuit.get(subcircuitId) || [];
2407
- subcircuitElements.push(newElm);
2408
- internalStore.indexes.bySubcircuit.set(
2409
- subcircuitId,
2410
- subcircuitElements
2411
- );
2412
- }
2413
- }
2414
- if (indexConfig.byCustomField && internalStore.indexes.byCustomField) {
2415
- for (const field of indexConfig.byCustomField) {
2416
- if (field in newElm) {
2417
- const fieldValue = newElm[field];
2418
- if (fieldValue !== void 0 && (typeof fieldValue === "string" || typeof fieldValue === "number")) {
2419
- const fieldValueStr = String(fieldValue);
2420
- const fieldMap = internalStore.indexes.byCustomField.get(field);
2421
- const elementsWithFieldValue = fieldMap.get(fieldValueStr) || [];
2422
- elementsWithFieldValue.push(newElm);
2423
- fieldMap.set(fieldValueStr, elementsWithFieldValue);
2424
- }
2425
- }
2426
- }
2427
- }
2428
- return newElm;
2429
- },
2430
- delete: (id) => {
2431
- const indexConfig = options.indexConfig || {};
2432
- let elm;
2433
- if (indexConfig.byId && internalStore.indexes.byId) {
2434
- elm = internalStore.indexes.byId.get(`${component_type}:${id}`);
2435
- } else if (indexConfig.byType && internalStore.indexes.byType) {
2436
- const elementsOfType = internalStore.indexes.byType.get(component_type) || [];
2437
- elm = elementsOfType.find(
2438
- (e) => e[`${component_type}_id`] === id
2439
- );
2440
- } else {
2441
- elm = soup.find((e) => e[`${component_type}_id`] === id);
2442
- }
2443
- if (!elm)
2444
- return;
2445
- const elmIndex = soup.indexOf(elm);
2446
- if (elmIndex >= 0) {
2447
- soup.splice(elmIndex, 1);
2448
- internalStore.editCount++;
2449
- }
2450
- if (indexConfig.byId && internalStore.indexes.byId) {
2451
- const idKey = createIdKey(elm);
2452
- internalStore.indexes.byId.delete(idKey);
2453
- }
2454
- if (indexConfig.byType && internalStore.indexes.byType) {
2455
- const elementsOfType = internalStore.indexes.byType.get(component_type) || [];
2456
- const filteredElements = elementsOfType.filter(
2457
- (e) => e[`${component_type}_id`] !== id
2458
- );
2459
- internalStore.indexes.byType.set(component_type, filteredElements);
2460
- }
2461
- if (indexConfig.byRelation && internalStore.indexes.byRelation) {
2462
- for (const [
2463
- relationKey,
2464
- relationMap
2465
- ] of internalStore.indexes.byRelation.entries()) {
2466
- for (const [relationValue, elements] of relationMap.entries()) {
2467
- const updatedElements = elements.filter((e) => e !== elm);
2468
- if (updatedElements.length === 0) {
2469
- relationMap.delete(relationValue);
2470
- } else {
2471
- relationMap.set(relationValue, updatedElements);
2472
- }
2473
- }
2474
- }
2475
- }
2476
- if (indexConfig.bySubcircuit && internalStore.indexes.bySubcircuit && "subcircuit_id" in elm) {
2477
- const subcircuitId = elm.subcircuit_id;
2478
- if (subcircuitId) {
2479
- const subcircuitElements = internalStore.indexes.bySubcircuit.get(subcircuitId) || [];
2480
- const updatedElements = subcircuitElements.filter(
2481
- (e) => e !== elm
2482
- );
2483
- if (updatedElements.length === 0) {
2484
- internalStore.indexes.bySubcircuit.delete(subcircuitId);
2485
- } else {
2486
- internalStore.indexes.bySubcircuit.set(
2487
- subcircuitId,
2488
- updatedElements
2489
- );
2490
- }
2491
- }
2492
- }
2493
- if (indexConfig.byCustomField && internalStore.indexes.byCustomField) {
2494
- for (const fieldMap of internalStore.indexes.byCustomField.values()) {
2495
- for (const [fieldValue, elements] of fieldMap.entries()) {
2496
- const updatedElements = elements.filter((e) => e !== elm);
2497
- if (updatedElements.length === 0) {
2498
- fieldMap.delete(fieldValue);
2499
- } else {
2500
- fieldMap.set(fieldValue, updatedElements);
2501
- }
2502
- }
2503
- }
2504
- }
2505
- },
2506
- update: (id, newProps) => {
2507
- const indexConfig = options.indexConfig || {};
2508
- let elm;
2509
- if (indexConfig.byId && internalStore.indexes.byId) {
2510
- elm = internalStore.indexes.byId.get(`${component_type}:${id}`);
2511
- } else if (indexConfig.byType && internalStore.indexes.byType) {
2512
- const elementsOfType = internalStore.indexes.byType.get(component_type) || [];
2513
- elm = elementsOfType.find(
2514
- (e) => e[`${component_type}_id`] === id
2515
- );
2516
- } else {
2517
- elm = soup.find(
2518
- (e) => e.type === component_type && e[`${component_type}_id`] === id
2519
- );
2520
- }
2521
- if (!elm)
2522
- return null;
2523
- if (indexConfig.byRelation && internalStore.indexes.byRelation) {
2524
- const elementEntries = Object.entries(elm);
2525
- for (const [key, value] of elementEntries) {
2526
- if (key.endsWith("_id") && key !== `${elm.type}_id` && typeof value === "string") {
2527
- if (key in newProps && newProps[key] !== value) {
2528
- const relationTypeMap = internalStore.indexes.byRelation.get(key);
2529
- if (relationTypeMap) {
2530
- const relatedElements = relationTypeMap.get(value) || [];
2531
- const updatedElements = relatedElements.filter(
2532
- (e) => e !== elm
2533
- );
2534
- if (updatedElements.length === 0) {
2535
- relationTypeMap.delete(value);
2536
- } else {
2537
- relationTypeMap.set(value, updatedElements);
2538
- }
2539
- }
2540
- }
2541
- }
2542
- }
2543
- }
2544
- if (indexConfig.bySubcircuit && internalStore.indexes.bySubcircuit && "subcircuit_id" in elm && "subcircuit_id" in newProps) {
2545
- const oldSubcircuitId = elm.subcircuit_id;
2546
- const newSubcircuitId = newProps.subcircuit_id;
2547
- if (oldSubcircuitId !== newSubcircuitId) {
2548
- const subcircuitElements = internalStore.indexes.bySubcircuit.get(oldSubcircuitId) || [];
2549
- const updatedElements = subcircuitElements.filter(
2550
- (e) => e !== elm
2551
- );
2552
- if (updatedElements.length === 0) {
2553
- internalStore.indexes.bySubcircuit.delete(oldSubcircuitId);
2554
- } else {
2555
- internalStore.indexes.bySubcircuit.set(
2556
- oldSubcircuitId,
2557
- updatedElements
2558
- );
2559
- }
2560
- }
2561
- }
2562
- if (indexConfig.byCustomField && internalStore.indexes.byCustomField) {
2563
- for (const field of indexConfig.byCustomField) {
2564
- if (field in elm && field in newProps && elm[field] !== newProps[field]) {
2565
- const fieldMap = internalStore.indexes.byCustomField.get(field);
2566
- if (fieldMap) {
2567
- const oldValue = String(elm[field]);
2568
- const elements = fieldMap.get(oldValue) || [];
2569
- const updatedElements = elements.filter((e) => e !== elm);
2570
- if (updatedElements.length === 0) {
2571
- fieldMap.delete(oldValue);
2572
- } else {
2573
- fieldMap.set(oldValue, updatedElements);
2574
- }
2575
- }
2576
- }
2577
- }
2578
- }
2579
- Object.assign(elm, newProps);
2580
- internalStore.editCount++;
2581
- if (indexConfig.byRelation && internalStore.indexes.byRelation) {
2582
- const elementEntries = Object.entries(elm);
2583
- for (const [key, value] of elementEntries) {
2584
- if (key.endsWith("_id") && key !== `${elm.type}_id` && typeof value === "string") {
2585
- if (key in newProps) {
2586
- const relationTypeMap = internalStore.indexes.byRelation.get(key) || /* @__PURE__ */ new Map();
2587
- const relatedElements = relationTypeMap.get(value) || [];
2588
- if (!relatedElements.includes(elm)) {
2589
- relatedElements.push(elm);
2590
- relationTypeMap.set(value, relatedElements);
2591
- internalStore.indexes.byRelation.set(key, relationTypeMap);
2592
- }
2593
- }
2594
- }
2595
- }
2596
- }
2597
- if (indexConfig.bySubcircuit && internalStore.indexes.bySubcircuit && "subcircuit_id" in elm && "subcircuit_id" in newProps) {
2598
- const subcircuitId = elm.subcircuit_id;
2599
- if (subcircuitId && typeof subcircuitId === "string") {
2600
- const subcircuitElements = internalStore.indexes.bySubcircuit.get(subcircuitId) || [];
2601
- if (!subcircuitElements.includes(elm)) {
2602
- subcircuitElements.push(elm);
2603
- internalStore.indexes.bySubcircuit.set(
2604
- subcircuitId,
2605
- subcircuitElements
2606
- );
2607
- }
2608
- }
2609
- }
2610
- if (indexConfig.byCustomField && internalStore.indexes.byCustomField) {
2611
- for (const field of indexConfig.byCustomField) {
2612
- if (field in elm && field in newProps) {
2613
- const fieldValue = elm[field];
2614
- if (fieldValue !== void 0 && (typeof fieldValue === "string" || typeof fieldValue === "number")) {
2615
- const fieldValueStr = String(fieldValue);
2616
- const fieldMap = internalStore.indexes.byCustomField.get(field);
2617
- const elementsWithFieldValue = fieldMap.get(fieldValueStr) || [];
2618
- if (!elementsWithFieldValue.includes(elm)) {
2619
- elementsWithFieldValue.push(elm);
2620
- fieldMap.set(fieldValueStr, elementsWithFieldValue);
2621
- }
2622
- }
2623
- }
2624
- }
2625
- }
2626
- return elm;
2627
- },
2628
- select: (selector) => {
2629
- if (component_type === "source_component") {
2630
- return soup.find(
2631
- (e) => e.type === "source_component" && e.name === selector.replace(/\./g, "")
2632
- ) || null;
2633
- } else if (component_type === "pcb_port" || component_type === "source_port" || component_type === "schematic_port") {
2634
- const [component_name, port_selector] = selector.replace(/\./g, "").split(/[\s\>]+/);
2635
- const source_component = soup.find(
2636
- (e) => e.type === "source_component" && e.name === component_name
2637
- );
2638
- if (!source_component)
2639
- return null;
2640
- const source_port2 = soup.find(
2641
- (e) => e.type === "source_port" && e.source_component_id === source_component.source_component_id && (e.name === port_selector || (e.port_hints ?? []).includes(port_selector))
2642
- );
2643
- if (!source_port2)
2644
- return null;
2645
- if (component_type === "source_port")
2646
- return source_port2;
2647
- if (component_type === "pcb_port") {
2648
- return soup.find(
2649
- (e) => e.type === "pcb_port" && e.source_port_id === source_port2.source_port_id
2650
- ) || null;
2651
- } else if (component_type === "schematic_port") {
2652
- return soup.find(
2653
- (e) => e.type === "schematic_port" && e.source_port_id === source_port2.source_port_id
2654
- ) || null;
2655
- }
2656
- }
2657
- return null;
2658
- }
2659
- };
2660
- }
2661
- }
2662
- );
2663
- return suIndexed;
2664
- };
2665
- cjuIndexed.unparsed = cjuIndexed;
2666
- var transformPCBElement = (elm, matrix) => {
2667
- if (elm.type === "pcb_plated_hole" || elm.type === "pcb_hole" || elm.type === "pcb_via" || elm.type === "pcb_smtpad" || elm.type === "pcb_port") {
2668
- const { x, y } = applyToPoint(matrix, {
2669
- x: Number(elm.x),
2670
- y: Number(elm.y)
2671
- });
2672
- elm.x = x;
2673
- elm.y = y;
2674
- } else if (elm.type === "pcb_keepout" || elm.type === "pcb_board") {
2675
- elm.center = applyToPoint(matrix, elm.center);
2676
- } else if (elm.type === "pcb_silkscreen_text" || elm.type === "pcb_fabrication_note_text") {
2677
- elm.anchor_position = applyToPoint(matrix, elm.anchor_position);
2678
- } else if (elm.type === "pcb_silkscreen_circle" || elm.type === "pcb_silkscreen_rect" || elm.type === "pcb_component") {
2679
- elm.center = applyToPoint(matrix, elm.center);
2680
- } else if (elm.type === "pcb_silkscreen_path" || elm.type === "pcb_trace" || elm.type === "pcb_fabrication_note_path") {
2681
- elm.route = elm.route.map((rp) => {
2682
- const tp = applyToPoint(matrix, rp);
2683
- rp.x = tp.x;
2684
- rp.y = tp.y;
2685
- return rp;
2686
- });
2687
- } else if (elm.type === "pcb_silkscreen_line") {
2688
- const p1 = { x: elm.x1, y: elm.y1 };
2689
- const p2 = { x: elm.x2, y: elm.y2 };
2690
- const p1t = applyToPoint(matrix, p1);
2691
- const p2t = applyToPoint(matrix, p2);
2692
- elm.x1 = p1t.x;
2693
- elm.y1 = p1t.y;
2694
- elm.x2 = p2t.x;
2695
- elm.y2 = p2t.y;
2696
- } else if (elm.type === "cad_component") {
2697
- const newPos = applyToPoint(matrix, {
2698
- x: elm.position.x,
2699
- y: elm.position.y
2700
- });
2701
- elm.position.x = newPos.x;
2702
- elm.position.y = newPos.y;
2703
- }
2704
- return elm;
2705
- };
2706
- var transformPCBElements = (elms, matrix) => {
2707
- const tsr = decomposeTSR(matrix);
2708
- const flipPadWidthHeight = Math.round(tsr.rotation.angle / (Math.PI / 2)) % 2 === 1;
2709
- let transformedElms = elms.map((elm) => transformPCBElement(elm, matrix));
2710
- if (flipPadWidthHeight) {
2711
- transformedElms = transformedElms.map((elm) => {
2712
- if (elm.type === "pcb_smtpad" && elm.shape === "rect") {
2713
- ;
2714
- [elm.width, elm.height] = [elm.height, elm.width];
2715
- }
2716
- return elm;
2717
- });
2718
- }
2719
- return transformedElms;
2720
- };
2721
- function stringHash(str) {
2722
- let hash = 0;
2723
- if (str.length == 0)
2724
- return hash;
2725
- for (var i = 0; i < str.length; i++) {
2726
- var char = str.charCodeAt(i);
2727
- hash = (hash << 5) - hash + char;
2728
- hash = hash & hash;
2729
- }
2730
- return Math.abs(hash);
2731
- }
2732
- var nice_color_palettes = [
2733
- ["#69d2e7", "#a7dbd8", "#e0e4cc", "#f38630", "#fa6900"],
2734
- ["#fe4365", "#fc9d9a", "#f9cdad", "#c8c8a9", "#83af9b"],
2735
- ["#ecd078", "#d95b43", "#c02942", "#542437", "#53777a"],
2736
- ["#556270", "#4ecdc4", "#c7f464", "#ff6b6b", "#c44d58"],
2737
- ["#774f38", "#e08e79", "#f1d4af", "#ece5ce", "#c5e0dc"],
2738
- ["#e8ddcb", "#cdb380", "#036564", "#033649", "#031634"],
2739
- ["#490a3d", "#bd1550", "#e97f02", "#f8ca00", "#8a9b0f"],
2740
- ["#594f4f", "#547980", "#45ada8", "#9de0ad", "#e5fcc2"],
2741
- ["#00a0b0", "#6a4a3c", "#cc333f", "#eb6841", "#edc951"],
2742
- ["#e94e77", "#d68189", "#c6a49a", "#c6e5d9", "#f4ead5"],
2743
- ["#3fb8af", "#7fc7af", "#dad8a7", "#ff9e9d", "#ff3d7f"],
2744
- ["#d9ceb2", "#948c75", "#d5ded9", "#7a6a53", "#99b2b7"],
2745
- ["#ffffff", "#cbe86b", "#f2e9e1", "#1c140d", "#cbe86b"],
2746
- ["#efffcd", "#dce9be", "#555152", "#2e2633", "#99173c"],
2747
- ["#343838", "#005f6b", "#008c9e", "#00b4cc", "#00dffc"],
2748
- ["#413e4a", "#73626e", "#b38184", "#f0b49e", "#f7e4be"],
2749
- ["#ff4e50", "#fc913a", "#f9d423", "#ede574", "#e1f5c4"],
2750
- ["#99b898", "#fecea8", "#ff847c", "#e84a5f", "#2a363b"],
2751
- ["#655643", "#80bca3", "#f6f7bd", "#e6ac27", "#bf4d28"],
2752
- ["#00a8c6", "#40c0cb", "#f9f2e7", "#aee239", "#8fbe00"],
2753
- ["#351330", "#424254", "#64908a", "#e8caa4", "#cc2a41"],
2754
- ["#554236", "#f77825", "#d3ce3d", "#f1efa5", "#60b99a"],
2755
- ["#5d4157", "#838689", "#a8caba", "#cad7b2", "#ebe3aa"],
2756
- ["#8c2318", "#5e8c6a", "#88a65e", "#bfb35a", "#f2c45a"],
2757
- ["#fad089", "#ff9c5b", "#f5634a", "#ed303c", "#3b8183"],
2758
- ["#ff4242", "#f4fad2", "#d4ee5e", "#e1edb9", "#f0f2eb"],
2759
- ["#f8b195", "#f67280", "#c06c84", "#6c5b7b", "#355c7d"],
2760
- ["#d1e751", "#ffffff", "#000000", "#4dbce9", "#26ade4"],
2761
- ["#1b676b", "#519548", "#88c425", "#bef202", "#eafde6"],
2762
- ["#5e412f", "#fcebb6", "#78c0a8", "#f07818", "#f0a830"],
2763
- ["#bcbdac", "#cfbe27", "#f27435", "#f02475", "#3b2d38"],
2764
- ["#452632", "#91204d", "#e4844a", "#e8bf56", "#e2f7ce"],
2765
- ["#eee6ab", "#c5bc8e", "#696758", "#45484b", "#36393b"],
2766
- ["#f0d8a8", "#3d1c00", "#86b8b1", "#f2d694", "#fa2a00"],
2767
- ["#2a044a", "#0b2e59", "#0d6759", "#7ab317", "#a0c55f"],
2768
- ["#f04155", "#ff823a", "#f2f26f", "#fff7bd", "#95cfb7"],
2769
- ["#b9d7d9", "#668284", "#2a2829", "#493736", "#7b3b3b"],
2770
- ["#bbbb88", "#ccc68d", "#eedd99", "#eec290", "#eeaa88"],
2771
- ["#b3cc57", "#ecf081", "#ffbe40", "#ef746f", "#ab3e5b"],
2772
- ["#a3a948", "#edb92e", "#f85931", "#ce1836", "#009989"],
2773
- ["#300030", "#480048", "#601848", "#c04848", "#f07241"],
2774
- ["#67917a", "#170409", "#b8af03", "#ccbf82", "#e33258"],
2775
- ["#aab3ab", "#c4cbb7", "#ebefc9", "#eee0b7", "#e8caaf"],
2776
- ["#e8d5b7", "#0e2430", "#fc3a51", "#f5b349", "#e8d5b9"],
2777
- ["#ab526b", "#bca297", "#c5ceae", "#f0e2a4", "#f4ebc3"],
2778
- ["#607848", "#789048", "#c0d860", "#f0f0d8", "#604848"],
2779
- ["#b6d8c0", "#c8d9bf", "#dadabd", "#ecdbbc", "#fedcba"],
2780
- ["#a8e6ce", "#dcedc2", "#ffd3b5", "#ffaaa6", "#ff8c94"],
2781
- ["#3e4147", "#fffedf", "#dfba69", "#5a2e2e", "#2a2c31"],
2782
- ["#fc354c", "#29221f", "#13747d", "#0abfbc", "#fcf7c5"],
2783
- ["#cc0c39", "#e6781e", "#c8cf02", "#f8fcc1", "#1693a7"],
2784
- ["#1c2130", "#028f76", "#b3e099", "#ffeaad", "#d14334"],
2785
- ["#a7c5bd", "#e5ddcb", "#eb7b59", "#cf4647", "#524656"],
2786
- ["#dad6ca", "#1bb0ce", "#4f8699", "#6a5e72", "#563444"],
2787
- ["#5c323e", "#a82743", "#e15e32", "#c0d23e", "#e5f04c"],
2788
- ["#edebe6", "#d6e1c7", "#94c7b6", "#403b33", "#d3643b"],
2789
- ["#fdf1cc", "#c6d6b8", "#987f69", "#e3ad40", "#fcd036"],
2790
- ["#230f2b", "#f21d41", "#ebebbc", "#bce3c5", "#82b3ae"],
2791
- ["#b9d3b0", "#81bda4", "#b28774", "#f88f79", "#f6aa93"],
2792
- ["#3a111c", "#574951", "#83988e", "#bcdea5", "#e6f9bc"],
2793
- ["#5e3929", "#cd8c52", "#b7d1a3", "#dee8be", "#fcf7d3"],
2794
- ["#1c0113", "#6b0103", "#a30006", "#c21a01", "#f03c02"],
2795
- ["#000000", "#9f111b", "#b11623", "#292c37", "#cccccc"],
2796
- ["#382f32", "#ffeaf2", "#fcd9e5", "#fbc5d8", "#f1396d"],
2797
- ["#e3dfba", "#c8d6bf", "#93ccc6", "#6cbdb5", "#1a1f1e"],
2798
- ["#f6f6f6", "#e8e8e8", "#333333", "#990100", "#b90504"],
2799
- ["#1b325f", "#9cc4e4", "#e9f2f9", "#3a89c9", "#f26c4f"],
2800
- ["#a1dbb2", "#fee5ad", "#faca66", "#f7a541", "#f45d4c"],
2801
- ["#c1b398", "#605951", "#fbeec2", "#61a6ab", "#accec0"],
2802
- ["#5e9fa3", "#dcd1b4", "#fab87f", "#f87e7b", "#b05574"],
2803
- ["#951f2b", "#f5f4d7", "#e0dfb1", "#a5a36c", "#535233"],
2804
- ["#8dccad", "#988864", "#fea6a2", "#f9d6ac", "#ffe9af"],
2805
- ["#2d2d29", "#215a6d", "#3ca2a2", "#92c7a3", "#dfece6"],
2806
- ["#413d3d", "#040004", "#c8ff00", "#fa023c", "#4b000f"],
2807
- ["#eff3cd", "#b2d5ba", "#61ada0", "#248f8d", "#605063"],
2808
- ["#ffefd3", "#fffee4", "#d0ecea", "#9fd6d2", "#8b7a5e"],
2809
- ["#cfffdd", "#b4dec1", "#5c5863", "#a85163", "#ff1f4c"],
2810
- ["#9dc9ac", "#fffec7", "#f56218", "#ff9d2e", "#919167"],
2811
- ["#4e395d", "#827085", "#8ebe94", "#ccfc8e", "#dc5b3e"],
2812
- ["#a8a7a7", "#cc527a", "#e8175d", "#474747", "#363636"],
2813
- ["#f8edd1", "#d88a8a", "#474843", "#9d9d93", "#c5cfc6"],
2814
- ["#046d8b", "#309292", "#2fb8ac", "#93a42a", "#ecbe13"],
2815
- ["#f38a8a", "#55443d", "#a0cab5", "#cde9ca", "#f1edd0"],
2816
- ["#a70267", "#f10c49", "#fb6b41", "#f6d86b", "#339194"],
2817
- ["#ff003c", "#ff8a00", "#fabe28", "#88c100", "#00c176"],
2818
- ["#ffedbf", "#f7803c", "#f54828", "#2e0d23", "#f8e4c1"],
2819
- ["#4e4d4a", "#353432", "#94ba65", "#2790b0", "#2b4e72"],
2820
- ["#0ca5b0", "#4e3f30", "#fefeeb", "#f8f4e4", "#a5b3aa"],
2821
- ["#4d3b3b", "#de6262", "#ffb88c", "#ffd0b3", "#f5e0d3"],
2822
- ["#fffbb7", "#a6f6af", "#66b6ab", "#5b7c8d", "#4f2958"],
2823
- ["#edf6ee", "#d1c089", "#b3204d", "#412e28", "#151101"],
2824
- ["#9d7e79", "#ccac95", "#9a947c", "#748b83", "#5b756c"],
2825
- ["#fcfef5", "#e9ffe1", "#cdcfb7", "#d6e6c3", "#fafbe3"],
2826
- ["#9cddc8", "#bfd8ad", "#ddd9ab", "#f7af63", "#633d2e"],
2827
- ["#30261c", "#403831", "#36544f", "#1f5f61", "#0b8185"],
2828
- ["#aaff00", "#ffaa00", "#ff00aa", "#aa00ff", "#00aaff"],
2829
- ["#d1313d", "#e5625c", "#f9bf76", "#8eb2c5", "#615375"],
2830
- ["#ffe181", "#eee9e5", "#fad3b2", "#ffba7f", "#ff9c97"],
2831
- ["#73c8a9", "#dee1b6", "#e1b866", "#bd5532", "#373b44"],
2832
- ["#805841", "#dcf7f3", "#fffcdd", "#ffd8d8", "#f5a2a2"]
2833
- ];
2834
- var getDebugLayoutObject = (lo) => {
2835
- let {
2836
- x,
2837
- y,
2838
- width,
2839
- height
2840
- } = {
2841
- ...lo,
2842
- ...lo.size,
2843
- ...lo.center,
2844
- ...lo.position
2845
- };
2846
- if (lo.x1 !== void 0 && lo.x2 !== void 0 && lo.y1 !== void 0 && lo.y2 !== void 0) {
2847
- x = (lo.x1 + lo.x2) / 2;
2848
- y = (lo.y1 + lo.y2) / 2;
2849
- width = Math.abs(lo.x1 - lo.x2);
2850
- height = Math.abs(lo.y1 - lo.y2);
2851
- }
2852
- const title = lo.text || lo.name || lo.source?.text || lo.source?.name || "?";
2853
- const content = lo;
2854
- if (x === void 0 || y === void 0)
2855
- return null;
2856
- if (width === void 0) {
2857
- if ("outer_diameter" in lo) {
2858
- width = lo.outer_diameter;
2859
- height = lo.outer_diameter;
2860
- }
2861
- }
2862
- if (width === void 0 || height === void 0) {
2863
- width = 0.1;
2864
- height = 0.1;
2865
- }
2866
- return {
2867
- x,
2868
- y,
2869
- width,
2870
- height,
2871
- title,
2872
- content,
2873
- bg_color: nice_color_palettes[stringHash(lo.type || title) % nice_color_palettes.length]?.[4] ?? "#f00"
2874
- };
2875
- };
2876
- var isTruthy = (value) => Boolean(value);
2877
- var findBoundsAndCenter = (elements) => {
2878
- const debugObjects = elements.filter((elm) => elm.type.startsWith("pcb_")).concat(
2879
- elements.filter((elm) => elm.type === "pcb_trace").flatMap((elm) => elm.route)
2880
- ).map((elm) => getDebugLayoutObject(elm)).filter(isTruthy);
2881
- if (debugObjects.length === 0)
2882
- return { center: { x: 0, y: 0 }, width: 0, height: 0 };
2883
- let minX = debugObjects[0].x - debugObjects[0].width / 2;
2884
- let maxX = debugObjects[0].x + debugObjects[0].width / 2;
2885
- let minY = debugObjects[0].y - debugObjects[0].height / 2;
2886
- let maxY = debugObjects[0].y + debugObjects[0].height / 2;
2887
- for (const obj of debugObjects.slice(1)) {
2888
- minX = Math.min(minX, obj.x - obj.width / 2);
2889
- maxX = Math.max(maxX, obj.x + obj.width / 2);
2890
- minY = Math.min(minY, obj.y - obj.height / 2);
2891
- maxY = Math.max(maxY, obj.y + obj.height / 2);
2892
- }
2893
- const width = maxX - minX;
2894
- const height = maxY - minY;
2895
- const center = { x: minX + width / 2, y: minY + height / 2 };
2896
- return { center, width, height };
2897
- };
2898
-
2899
- // lib/convert-easyeda-json-to-tscircuit-soup-json.ts
2900
- import { compose, scale, translate, applyToPoint as applyToPoint2 } from "transformation-matrix";
2901
- import { mm } from "@tscircuit/mm";
2902
-
2903
- // lib/utils/easyeda-unit-to-mm.ts
2904
- var mil10ToMm = (value) => value * 10 * 0.0254;
2905
-
2906
- // lib/convert-easyeda-json-to-tscircuit-soup-json.ts
2907
- import { normalizePinLabels } from "@tscircuit/core";
2908
- var mil2mm = (mil) => {
2909
- if (typeof mil === "number") return mm(`${mil}mil`);
2910
- if (mil.match(/^\d+$/)) return mm(`${mil}mil`);
2911
- return mm(mil);
2912
- };
2913
- var milx10 = (mil10) => {
2914
- if (typeof mil10 === "number") return mil2mm(mil10) * 10;
2915
- if (mil10.match(/^\d+$/)) return mil2mm(mil10) * 10;
2916
- return mil2mm(mil10);
2917
- };
2918
- var handleSilkscreenPath = (track, index) => {
2919
- return pcb_silkscreen_path.parse({
2920
- type: "pcb_silkscreen_path",
2921
- pcb_silkscreen_path_id: `pcb_silkscreen_path_${index + 1}`,
2922
- pcb_component_id: "pcb_component_1",
2923
- layer: "top",
2924
- // Assuming all silkscreen is on top layer
2925
- route: track.points.map((point2) => ({
2926
- x: milx10(point2.x),
2927
- y: milx10(point2.y)
2928
- })),
2929
- stroke_width: mil10ToMm(track.width)
2930
- });
2931
- };
2932
- var handleSilkscreenArc = (arc, index) => {
2933
- const arcPath = generateArcFromSweep(
2934
- arc.start.x,
2935
- arc.start.y,
2936
- arc.end.x,
2937
- arc.end.y,
2938
- arc.radiusX,
2939
- arc.largeArc,
2940
- arc.sweepDirection === "CW"
2941
- );
2942
- return pcb_silkscreen_path.parse({
2943
- type: "pcb_silkscreen_path",
2944
- pcb_silkscreen_path_id: `pcb_silkscreen_arc_${index + 1}`,
2945
- pcb_component_id: "pcb_component_1",
2946
- layer: "top",
2947
- // Assuming all silkscreen is on top layer
2948
- route: arcPath.map((p) => ({
2949
- x: milx10(p.x),
2950
- y: milx10(p.y)
2951
- })),
2952
- stroke_width: mil10ToMm(arc.width)
2953
- });
2954
- };
2955
- var handleHole = (hole, index) => {
2956
- return pcb_hole.parse({
2957
- type: "pcb_hole",
2958
- x: milx10(hole.center.x),
2959
- y: milx10(hole.center.y),
2960
- hole_diameter: milx10(hole.radius) * 2,
2961
- hole_shape: "circle",
2962
- pcb_hole_id: `pcb_hole_${index + 1}`
2963
- });
2964
- };
2965
- var handleHoleCutout = (hole, index) => {
2966
- return pcb_cutout.parse({
2967
- type: "pcb_cutout",
2968
- pcb_cutout_id: `pcb_cutout_from_hole_${index + 1}`,
2969
- shape: "circle",
2970
- center: { x: milx10(hole.center.x), y: milx10(hole.center.y) },
2971
- radius: milx10(hole.radius)
2972
- });
2973
- };
2974
- var handleVia = (via, index) => {
2975
- return pcb_via.parse({
2976
- type: "pcb_via",
2977
- pcb_via_id: `pcb_via_${index + 1}`,
2978
- x: milx10(via.center.x),
2979
- y: milx10(via.center.y),
2980
- outer_diameter: milx10(via.outerDiameter),
2981
- hole_diameter: milx10(via.holeDiameter),
2982
- layers: ["top", "bottom"]
2983
- });
2984
- };
2985
- var handleCutout = (solidRegion, index) => {
2986
- return pcb_cutout.parse({
2987
- type: "pcb_cutout",
2988
- pcb_cutout_id: `pcb_cutout_${index + 1}`,
2989
- shape: "polygon",
2990
- points: solidRegion.points.map((p) => ({
2991
- x: milx10(p.x),
2992
- y: milx10(p.y)
2993
- }))
2994
- });
2995
- };
2996
- var convertEasyEdaJsonToCircuitJson = (easyEdaJson, { useModelCdn, shouldRecenter = true } = {}) => {
2997
- const circuitElements = [];
2998
- const source_component = any_source_component.parse({
2999
- type: "source_component",
3000
- source_component_id: "source_component_1",
3001
- name: "U1",
3002
- ftype: "simple_chip"
3003
- });
3004
- const pcb_component2 = pcb_component.parse({
3005
- type: "pcb_component",
3006
- pcb_component_id: "pcb_component_1",
3007
- source_component_id: "source_component_1",
3008
- name: "U1",
3009
- ftype: "simple_chip",
3010
- width: 0,
3011
- // we update this at the end
3012
- height: 0,
3013
- // we update this at the end
3014
- rotation: 0,
3015
- center: { x: 0, y: 0 },
3016
- layer: "top"
3017
- });
3018
- circuitElements.push(source_component, pcb_component2);
3019
- const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
3020
- (shape) => shape.type === "PAD"
3021
- );
3022
- const pins = easyEdaJson.dataStr.shape.filter((shape) => shape.type === "PIN");
3023
- const pinLabelSets = pads.map((pad) => {
3024
- const labels = [];
3025
- if (pad.number) labels.push(pad.number.toString());
3026
- const pin = pins.find((p) => p.pinNumber === pad.number);
3027
- if (pin) labels.push(pin.label);
3028
- return labels;
3029
- });
3030
- const normalizedPinLabels = normalizePinLabels(pinLabelSets);
3031
- pads.forEach((pad, index) => {
3032
- const portHints = normalizedPinLabels[index];
3033
- const pinNumber = Number.parseInt(
3034
- portHints.find((hint) => hint.match(/pin\d+/)).replace("pin", "")
3035
- );
3036
- circuitElements.push({
3037
- type: "source_port",
3038
- source_port_id: `source_port_${index + 1}`,
3039
- source_component_id: "source_component_1",
3040
- name: `pin${pinNumber}`,
3041
- pin_number: pinNumber,
3042
- port_hints: portHints.filter((hint) => hint !== `pin${pinNumber}`)
3043
- });
3044
- if (pad.holeRadius !== void 0 && mil2mm(pad.holeRadius) !== 0) {
3045
- const commonPlatedHoleProps = {
3046
- type: "pcb_plated_hole",
3047
- pcb_plated_hole_id: `pcb_plated_hole_${index + 1}`,
3048
- x: mil2mm(pad.center.x),
3049
- y: mil2mm(pad.center.y),
3050
- layers: ["top"],
3051
- port_hints: [`pin${pinNumber}`],
3052
- pcb_component_id: "pcb_component_1",
3053
- pcb_port_id: `pcb_port_${index + 1}`
3054
- };
3055
- let additionalPlatedHoleProps;
3056
- if (pad.shape === "OVAL") {
3057
- const largestOuterDimensionName = mil2mm(pad.width) > mil2mm(pad.height) ? "width" : "height";
3058
- const smallestOuterDimension = Math.min(
3059
- mil2mm(pad.width),
3060
- mil2mm(pad.height)
3061
- );
3062
- const largestOuterDimension = Math.max(
3063
- mil2mm(pad.width),
3064
- mil2mm(pad.height)
3065
- );
3066
- const distanceFromOuterPlatingToHole = smallestOuterDimension / 2 - mil2mm(pad.holeRadius);
3067
- const largestInnerDimension = largestOuterDimension - distanceFromOuterPlatingToHole * 2;
3068
- const smallestInnerDimension = mil2mm(pad.holeRadius) * 2;
3069
- const innerWidth = largestOuterDimensionName === "width" ? largestInnerDimension : smallestInnerDimension;
3070
- const innerHeight = largestOuterDimensionName === "height" ? largestInnerDimension : smallestInnerDimension;
3071
- additionalPlatedHoleProps = {
3072
- shape: "pill",
3073
- outer_width: mil2mm(pad.width),
3074
- outer_height: mil2mm(pad.height),
3075
- hole_width: innerWidth,
3076
- hole_height: innerHeight
3077
- };
3078
- } else {
3079
- additionalPlatedHoleProps = {
3080
- shape: "circle",
3081
- hole_diameter: mil2mm(pad.holeRadius) * 2,
3082
- outer_diameter: mil2mm(pad.width),
3083
- radius: mil2mm(pad.holeRadius)
3084
- };
3085
- }
3086
- circuitElements.push(
3087
- pcb_plated_hole.parse({
3088
- ...commonPlatedHoleProps,
3089
- ...additionalPlatedHoleProps
3090
- })
3091
- );
3092
- } else {
3093
- let soupShape;
3094
- if (pad.shape === "RECT") {
3095
- soupShape = "rect";
3096
- } else if (pad.shape === "ELLIPSE") {
3097
- soupShape = "rect";
3098
- } else if (pad.shape === "OVAL") {
3099
- soupShape = "rect";
3100
- }
3101
- if (!soupShape) {
3102
- throw new Error(`unknown pad.shape: "${pad.shape}"`);
3103
- }
3104
- const rectSize = { width: mil2mm(pad.width), height: mil2mm(pad.height) };
3105
- if (pad.rotation === 90 || pad.rotation === 270) {
3106
- rectSize.width = mil2mm(pad.height);
3107
- rectSize.height = mil2mm(pad.width);
3108
- }
3109
- const parsedPcbSmtpad = pcb_smtpad.parse({
3110
- type: "pcb_smtpad",
3111
- pcb_smtpad_id: `pcb_smtpad_${index + 1}`,
3112
- shape: soupShape,
3113
- x: mil2mm(pad.center.x),
3114
- y: mil2mm(pad.center.y),
3115
- ...soupShape === "rect" ? rectSize : { radius: Math.min(mil2mm(pad.width), mil2mm(pad.height)) / 2 },
3116
- layer: "top",
3117
- port_hints: [`pin${pinNumber}`],
3118
- pcb_component_id: "pcb_component_1",
3119
- pcb_port_id: `pcb_port_${index + 1}`
3120
- });
3121
- circuitElements.push(parsedPcbSmtpad);
3122
- }
3123
- });
3124
- easyEdaJson.packageDetail.dataStr.shape.filter(
3125
- (shape) => shape.type === "HOLE"
3126
- ).forEach((h, index) => {
3127
- circuitElements.push(handleHole(h, index));
3128
- circuitElements.push(handleHoleCutout(h, index));
3129
- });
3130
- easyEdaJson.packageDetail.dataStr.shape.filter((shape) => shape.type === "VIA").forEach((v, index) => {
3131
- circuitElements.push(handleVia(v, index));
3132
- });
3133
- easyEdaJson.packageDetail.dataStr.shape.filter(
3134
- (shape) => shape.type === "SOLIDREGION" && shape.fillStyle === "cutout"
3135
- ).forEach((sr, index) => {
3136
- circuitElements.push(handleCutout(sr, index));
3137
- });
3138
- easyEdaJson.packageDetail.dataStr.shape.forEach((shape, index) => {
3139
- if (shape.type === "TRACK") {
3140
- circuitElements.push(handleSilkscreenPath(shape, index));
3141
- } else if (shape.type === "ARC") {
3142
- circuitElements.push(handleSilkscreenArc(shape, index));
3143
- } else if (shape.type === "TEXT") {
3144
- circuitElements.push(
3145
- pcb_silkscreen_text.parse({
3146
- type: "pcb_silkscreen_text",
3147
- pcb_silkscreen_text_id: `pcb_silkscreen_text_${index + 1}`,
3148
- pcb_component_id: "pcb_component_1",
3149
- text: shape.text,
3150
- anchor_position: {
3151
- x: mil2mm(shape.x),
3152
- y: mil2mm(shape.y)
3153
- },
3154
- anchor_alignment: {
3155
- L: "bottom_left",
3156
- C: "center",
3157
- R: "bottom_right"
3158
- }[shape.textAnchor ?? "L"],
3159
- font_size: shape.size_mm ? shape.size_mm : void 0,
3160
- layer: "top"
3161
- })
3162
- );
3163
- }
3164
- });
3165
- const svgNode = easyEdaJson.packageDetail.dataStr.shape.find(
3166
- (a) => Boolean(a.type === "SVGNODE" && a.svgData.attrs?.uuid)
3167
- );
3168
- const objFileUuid = svgNode?.svgData?.attrs?.uuid;
3169
- 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;
3170
- if (objFileUrl !== void 0) {
3171
- const [rx, ry, rz] = (svgNode?.svgData.attrs?.c_rotation ?? "0,0,0").split(",").map(Number);
3172
- circuitElements.push(
3173
- cad_component.parse({
3174
- type: "cad_component",
3175
- cad_component_id: "cad_component_1",
3176
- source_component_id: "source_component_1",
3177
- pcb_component_id: "pcb_component_1",
3178
- position: { x: 0, y: 0, z: 0 },
3179
- rotation: { x: rx, y: ry, z: rz },
3180
- model_obj_url: objFileUrl
3181
- })
3182
- );
3183
- }
3184
- if (shouldRecenter) {
3185
- const bounds = findBoundsAndCenter(
3186
- // exclude the pcb_component because it's center is currently incorrect,
3187
- // we set it to (0,0)
3188
- circuitElements.filter((e) => e.type !== "pcb_component")
3189
- );
3190
- const matrix = compose(
3191
- translate(-bounds.center.x, bounds.center.y),
3192
- scale(1, -1)
3193
- );
3194
- transformPCBElements(circuitElements, matrix);
3195
- for (const e of circuitElements) {
3196
- if (e.type === "pcb_cutout") {
3197
- if (e.shape === "polygon") {
3198
- e.points = e.points.map((p) => applyToPoint2(matrix, p));
3199
- } else {
3200
- e.center = applyToPoint2(matrix, e.center);
3201
- }
3202
- }
3203
- }
3204
- pcb_component2.center = { x: 0, y: 0 };
3205
- }
3206
- return circuitElements;
3207
- };
3208
- var convertEasyEdaJsonToTscircuitSoupJson = convertEasyEdaJsonToCircuitJson;
3209
-
3210
- // lib/websafe/fetch-easyeda-json.ts
3211
- async function fetchEasyEDAComponent(jlcpcbPartNumber, { fetch: fetch2 = globalThis.fetch } = {}) {
3212
- const searchUrl = "https://easyeda.com/api/components/search";
3213
- const componentUrl = (uuid) => `https://easyeda.com/api/components/${uuid}?version=6.4.7&uuid=${uuid}&datastrid=`;
3214
- const searchHeaders = {
3215
- authority: "easyeda.com",
3216
- pragma: "no-cache",
3217
- "cache-control": "no-cache",
3218
- accept: "application/json, text/javascript, */*; q=0.01",
3219
- "x-requested-with": "XMLHttpRequest",
3220
- "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
3221
- "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
3222
- origin: "https://easyeda.com",
3223
- "sec-fetch-site": "same-origin",
3224
- "sec-fetch-mode": "cors",
3225
- "sec-fetch-dest": "empty",
3226
- referer: "https://easyeda.com/editor",
3227
- "accept-language": "cs,en;q=0.9,sk;q=0.8,en-GB;q=0.7",
3228
- cookie: "<PUT your cookies here>"
3229
- };
3230
- const searchData = `type=3&doctype%5B%5D=2&uid=0819f05c4eef4c71ace90d822a990e87&returnListStyle=classifyarr&wd=${jlcpcbPartNumber}&version=6.4.7`;
3231
- const searchResponse = await fetch2(searchUrl, {
3232
- method: "POST",
3233
- headers: searchHeaders,
3234
- body: searchData
3235
- });
3236
- if (!searchResponse.ok) {
3237
- throw new Error("Failed to search for the component");
3238
- }
3239
- const searchResult = await searchResponse.json();
3240
- if (!searchResult.success || !searchResult.result.lists.lcsc.length) {
3241
- throw new Error("Component not found");
3242
- }
3243
- const bestMatchComponent = searchResult.result.lists.lcsc.find(
3244
- (component) => component.dataStr.head.c_para["Supplier Part"] === jlcpcbPartNumber
3245
- ) ?? searchResult.result.lists.lcsc[0];
3246
- const componentUUID = bestMatchComponent.uuid;
3247
- const componentResponse = await fetch2(componentUrl(componentUUID), {
3248
- method: "GET",
3249
- headers: {
3250
- ...searchHeaders,
3251
- referer: `https://easyeda.com/editor?uuid=${componentUUID}`
3252
- }
3253
- });
3254
- if (!componentResponse.ok) {
3255
- throw new Error("Failed to fetch the component details");
3256
- }
3257
- const componentResult = await componentResponse.json();
3258
- return componentResult.result;
3259
- }
3260
-
3261
- // lib/schemas/easy-eda-json-schema.ts
3262
- import { z as z91 } from "zod";
3263
-
3264
- // lib/schemas/package-detail-shape-schema.ts
3265
- import { z as z89 } from "zod";
3266
- var tenthmil = z89.union([z89.number(), z89.string()]).optional().transform(
3267
- (n) => typeof n === "string" && n.endsWith("mil") ? n : `${Number.parseFloat(n) * 10}mil`
3268
- ).pipe(z89.string());
3269
- var PointSchema = z89.any().transform((p) => {
3270
- if (Array.isArray(p)) {
3271
- const [x, y] = p;
3272
- return { x, y };
3273
- }
3274
- if (typeof p === "object") {
3275
- return p;
3276
- }
3277
- throw new Error(`Invalid point: ${p}`);
3278
- }).pipe(
3279
- z89.object({
3280
- x: z89.number(),
3281
- y: z89.number()
3282
- })
3283
- );
3284
- var BaseShapeSchema = z89.object({
3285
- type: z89.string(),
3286
- id: z89.string().optional(),
3287
- layer: z89.coerce.number().optional()
3288
- });
3289
- var TrackSchema = BaseShapeSchema.extend({
3290
- type: z89.literal("TRACK"),
3291
- width: z89.coerce.number(),
3292
- points: z89.array(PointSchema)
3293
- });
3294
- var PadSchema = BaseShapeSchema.extend({
3295
- type: z89.literal("PAD"),
3296
- shape: z89.enum(["RECT", "ELLIPSE", "OVAL"]),
3297
- center: z89.object({
3298
- x: tenthmil,
3299
- y: tenthmil
3300
- }),
3301
- width: tenthmil,
3302
- height: tenthmil,
3303
- layermask: z89.number(),
3304
- net: z89.union([z89.string(), z89.number()]).optional(),
3305
- number: z89.union([z89.string(), z89.number()]),
3306
- holeRadius: tenthmil,
3307
- points: z89.array(PointSchema).optional(),
3308
- rotation: z89.number().optional(),
3309
- plated: z89.boolean()
3310
- });
3311
- var ArcSchema = BaseShapeSchema.extend({
3312
- type: z89.literal("ARC"),
3313
- width: z89.number(),
3314
- start: PointSchema,
3315
- end: PointSchema,
3316
- radiusX: z89.number(),
3317
- radiusY: z89.number(),
3318
- largeArc: z89.boolean(),
3319
- sweepDirection: z89.enum(["CW", "CCW"])
3320
- });
3321
- var CircleSchema = BaseShapeSchema.extend({
3322
- type: z89.literal("CIRCLE"),
3323
- center: PointSchema,
3324
- radius: z89.number(),
3325
- width: z89.number()
3326
- });
3327
- var SolidRegionSchema = BaseShapeSchema.extend({
3328
- type: z89.literal("SOLIDREGION"),
3329
- layermask: z89.number(),
3330
- points: z89.array(PointSchema),
3331
- fillStyle: z89.string()
3332
- });
3333
- var SVGNodeSchema = BaseShapeSchema.extend({
3334
- type: z89.literal("SVGNODE"),
3335
- svgData: z89.object({
3336
- gId: z89.string(),
3337
- nodeName: z89.string(),
3338
- nodeType: z89.number(),
3339
- layerid: z89.string(),
3340
- attrs: z89.record(z89.string(), z89.string()),
3341
- childNodes: z89.array(z89.unknown())
3342
- })
3343
- });
3344
- var HoleSchema = BaseShapeSchema.extend({
3345
- type: z89.literal("HOLE"),
3346
- center: PointSchema,
3347
- radius: z89.number()
3348
- });
3349
- var ViaSchema = BaseShapeSchema.extend({
3350
- type: z89.literal("VIA"),
3351
- center: PointSchema,
3352
- outerDiameter: z89.number(),
3353
- holeDiameter: z89.number()
3354
- });
3355
- var RectSchema = BaseShapeSchema.extend({
3356
- type: z89.literal("RECT"),
3357
- x: tenthmil,
3358
- y: tenthmil,
3359
- width: tenthmil,
3360
- height: tenthmil,
3361
- lineWidth: z89.number(),
3362
- fillStyle: z89.string(),
3363
- rotation: z89.number().optional()
3364
- });
3365
- var TextSchema = BaseShapeSchema.extend({
3366
- type: z89.literal("TEXT"),
3367
- text: z89.string(),
3368
- x: tenthmil,
3369
- y: tenthmil,
3370
- size_mm: z89.number(),
3371
- rotation: z89.number().optional(),
3372
- layer: z89.number().optional(),
3373
- textAnchor: z89.enum(["L", "C", "R", ""]).optional().transform((val) => val === "" ? void 0 : val),
3374
- font: z89.string().optional()
3375
- });
3376
- var PackageDetailShapeSchema = z89.discriminatedUnion("type", [
3377
- TrackSchema,
3378
- PadSchema,
3379
- ArcSchema,
3380
- CircleSchema,
3381
- SolidRegionSchema,
3382
- SVGNodeSchema,
3383
- HoleSchema,
3384
- ViaSchema,
3385
- RectSchema,
3386
- TextSchema
3387
- ]);
3388
- var pairs = (arr) => {
3389
- const pairs2 = [];
3390
- for (let i = 0; i < arr.length; i += 2) {
3391
- pairs2.push([arr[i], arr[i + 1]]);
3392
- }
3393
- return pairs2;
3394
- };
3395
- var parsePoints = (pointsStr) => pairs(
3396
- pointsStr.trim().split(" ").map((n) => Number(n))
3397
- );
3398
- var ShapeItemSchema = z89.object({
3399
- type: z89.string(),
3400
- data: z89.string()
3401
- }).transform((shape) => {
3402
- switch (shape.type) {
3403
- case "TRACK": {
3404
- const [width, layer, _, pointsStr, id, _n] = shape.data.split("~");
3405
- const points = parsePoints(pointsStr);
3406
- return TrackSchema.parse({ type: "TRACK", width, layer, points, id });
3407
- }
3408
- case "PAD": {
3409
- const [padShape, ...params] = shape.data.split("~");
3410
- const [
3411
- centerX,
3412
- centerY,
3413
- width,
3414
- height,
3415
- layermask,
3416
- net,
3417
- number,
3418
- holeRadius,
3419
- ...rest
3420
- ] = params.map((p) => Number.isNaN(Number(p)) ? p : Number(p));
3421
- const center = { x: centerX, y: centerY };
3422
- let points;
3423
- if (padShape === "RECT") {
3424
- points = parsePoints(rest[0]);
3425
- }
3426
- const r = Number(rest[1]);
3427
- const rotation2 = Number.isNaN(r) ? void 0 : r;
3428
- const padInputParams = {
3429
- type: "PAD",
3430
- shape: padShape,
3431
- center,
3432
- width,
3433
- height,
3434
- layermask,
3435
- net,
3436
- number,
3437
- holeRadius,
3438
- points,
3439
- rotation: rotation2,
3440
- plated: rest.includes("Y")
3441
- };
3442
- const pad = PadSchema.parse(padInputParams);
3443
- return pad;
3444
- }
3445
- case "ARC": {
3446
- const [width, layer, , arcData] = shape.data.split("~");
3447
- const match = arcData.match(
3448
- /M\s*([\d.-]+)(?:\s*,\s*|\s+)([\d.-]+)\s*A\s*([\d.-]+)(?:\s*,\s*|\s+)([\d.-]+)\s*([\d.-]+)\s*([\d.-]+)\s*([\d.-]+)\s*([\d.-]+)(?:\s*,\s*|\s+)([\d.-]+)/
3449
- );
3450
- if (!match) {
3451
- throw new Error(`Invalid arc data: ${arcData}`);
3452
- }
3453
- const [
3454
- ,
3455
- startX,
3456
- startY,
3457
- radiusX,
3458
- radiusY,
3459
- xAxisRotation,
3460
- largeArcFlag,
3461
- sweepFlag,
3462
- endX,
3463
- endY
3464
- ] = match;
3465
- const start = [Number(startX), Number(startY)];
3466
- const end = [Number(endX), Number(endY)];
3467
- return ArcSchema.parse({
3468
- type: "ARC",
3469
- width: Number(width),
3470
- layer: Number(layer),
3471
- start,
3472
- end,
3473
- radiusX: Number(radiusX),
3474
- radiusY: Number(radiusY),
3475
- largeArc: largeArcFlag === "1",
3476
- // sweepFlag=1 means clockwise (CW), sweepFlag=0 means counter-clockwise (CCW)
3477
- sweepDirection: sweepFlag === "1" ? "CW" : "CCW"
3478
- });
3479
- }
3480
- case "CIRCLE": {
3481
- const [centerX, centerY, radius, width, layer, id] = shape.data.split("~");
3482
- const center = [Number(centerX), Number(centerY)];
3483
- return CircleSchema.parse({
3484
- type: "CIRCLE",
3485
- center,
3486
- radius: Number(radius),
3487
- width: Number(width),
3488
- layer: Number(layer),
3489
- id
3490
- });
3491
- }
3492
- case "HOLE": {
3493
- const [centerX, centerY, radius, id] = shape.data.split("~");
3494
- const center = [Number(centerX), Number(centerY)];
3495
- return HoleSchema.parse({
3496
- type: "HOLE",
3497
- center,
3498
- radius: Number(radius),
3499
- id
3500
- });
3501
- }
3502
- case "VIA": {
3503
- const [x, y, outerDiameter, , holeDiameter, id] = shape.data.split("~");
3504
- const center = [Number(x), Number(y)];
3505
- return ViaSchema.parse({
3506
- type: "VIA",
3507
- center,
3508
- outerDiameter: Number(outerDiameter),
3509
- holeDiameter: Number(holeDiameter),
3510
- id
3511
- });
3512
- }
3513
- case "SOLIDREGION": {
3514
- const [layermask, , pathData, fillStyle, id] = shape.data.split("~");
3515
- const points = pathData.match(/[ML] ?(-?[\d.]+)[ ,](-?[\d.]+)/g)?.map((point2) => {
3516
- const [, x, y] = point2.match(/[ML]? ?(-?[\d.]+)[ ,](-?[\d.]+)/) || [];
3517
- return [Number(x), Number(y)];
3518
- }) || [];
3519
- return SolidRegionSchema.parse({
3520
- type: "SOLIDREGION",
3521
- layermask: Number(layermask),
3522
- points,
3523
- fillStyle,
3524
- id
3525
- });
3526
- }
3527
- case "SVGNODE": {
3528
- const svgData = JSON.parse(shape.data);
3529
- return SVGNodeSchema.parse({ type: "SVGNODE", svgData });
3530
- }
3531
- case "RECT": {
3532
- const [x, y, width, height, lineWidth, id, rotation2, layer, fillStyle] = shape.data.split("~");
3533
- const r = rotation2 ? Number(rotation2) : void 0;
3534
- return RectSchema.parse({
3535
- type: "RECT",
3536
- x,
3537
- y,
3538
- width,
3539
- height,
3540
- lineWidth: Number(lineWidth),
3541
- id,
3542
- rotation: Number.isNaN(r) ? void 0 : r,
3543
- layer: layer ? Number(layer) : void 0,
3544
- fillStyle: fillStyle || void 0
3545
- });
3546
- }
3547
- case "TEXT": {
3548
- const [textAnchor, x, y, size2, layer, id, rotation2, , font, text] = shape.data.split("~");
3549
- const r = rotation2 ? Number(rotation2) : void 0;
3550
- return TextSchema.parse({
3551
- type: "TEXT",
3552
- text,
3553
- x,
3554
- y,
3555
- size_mm: Number(size2) * 2.54,
3556
- // empirically this seems to match, C5248081 is a good test case
3557
- layer: layer ? Number(layer) : void 0,
3558
- id,
3559
- rotation: Number.isNaN(r) ? void 0 : r,
3560
- textAnchor,
3561
- font: font || void 0
3562
- });
3563
- }
3564
- default:
3565
- throw new Error(`Unknown shape type: ${shape.type}`);
3566
- }
3567
- }).pipe(PackageDetailShapeSchema);
3568
- var ShapesArraySchema = z89.array(ShapeItemSchema);
3569
-
3570
- // lib/schemas/single-letter-shape-schema.ts
3571
- import { z as z90 } from "zod";
3572
- var PointSchema2 = z90.object({
3573
- x: z90.number(),
3574
- y: z90.number()
3575
- });
3576
- var RectangleShapeOutputSchema = z90.object({
3577
- type: z90.literal("RECTANGLE"),
3578
- position: PointSchema2,
3579
- width: z90.number(),
3580
- height: z90.number(),
3581
- color: z90.string(),
3582
- lineWidth: z90.number(),
3583
- id: z90.string()
3584
- });
3585
- var parseRectangle = (str) => {
3586
- const [, x, y, , , width, height, color, lineWidth, , , id] = str.split("~");
3587
- return {
3588
- type: "RECTANGLE",
3589
- position: { x: Number(x), y: Number(y) },
3590
- width: Number(width),
3591
- height: Number(height),
3592
- color,
3593
- lineWidth: Number(lineWidth),
3594
- id
3595
- };
3596
- };
3597
- var RectangleShapeSchema = z90.string().startsWith("R~").transform(parseRectangle).pipe(RectangleShapeOutputSchema);
3598
- var EllipseShapeOutputSchema = z90.object({
3599
- type: z90.literal("ELLIPSE"),
3600
- center: PointSchema2,
3601
- radiusX: z90.number(),
3602
- radiusY: z90.number(),
3603
- color: z90.string(),
3604
- lineWidth: z90.number(),
3605
- id: z90.string()
3606
- });
3607
- var parseEllipse = (str) => {
3608
- const [, x, y, radiusX, radiusY, color, lineWidth, , , id] = str.split("~");
3609
- return {
3610
- type: "ELLIPSE",
3611
- center: { x: Number(x), y: Number(y) },
3612
- radiusX: Number(radiusX),
3613
- radiusY: Number(radiusY),
3614
- color,
3615
- lineWidth: Number(lineWidth),
3616
- id
3617
- };
3618
- };
3619
- var EllipseShapeSchema = z90.string().startsWith("E~").transform(parseEllipse).pipe(EllipseShapeOutputSchema);
3620
- var ArcShapeOutputSchema = z90.object({
3621
- type: z90.literal("ARC"),
3622
- start: PointSchema2,
3623
- end: PointSchema2,
3624
- radius: z90.number(),
3625
- sweepFlag: z90.boolean(),
3626
- color: z90.string(),
3627
- lineWidth: z90.number(),
3628
- id: z90.string()
3629
- });
3630
- var parseArc = (str) => {
3631
- const [, pathData, color, lineWidth, , , id] = str.split("~");
3632
- const parts = pathData.split(" ");
3633
- const x1 = Number(parts[1]) || 0;
3634
- const y1 = Number(parts[2]) || 0;
3635
- const radius = Number(parts[4]) || 0;
3636
- const sweepFlag = parts[7] === "1";
3637
- const x2 = Number(parts[8]) || 0;
3638
- const y2 = Number(parts[9]) || 0;
3639
- const parsedLineWidth = Number(lineWidth);
3640
- const finalLineWidth = Number.isNaN(parsedLineWidth) ? 1 : parsedLineWidth;
3641
- return {
3642
- type: "ARC",
3643
- start: { x: x1, y: y1 },
3644
- end: { x: x2, y: y2 },
3645
- radius,
3646
- sweepFlag,
3647
- color: color || "#880000",
3648
- // Default color
3649
- lineWidth: finalLineWidth,
3650
- id: id || "gge1"
3651
- };
3652
- };
3653
- var ArcShapeSchema = z90.string().startsWith("A~").transform(parseArc).pipe(ArcShapeOutputSchema);
3654
- var PinShapeOutputSchema = z90.object({
3655
- type: z90.literal("PIN"),
3656
- visibility: z90.enum(["show", "hide"]),
3657
- pinNumber: z90.union([z90.string(), z90.number()]),
3658
- x: z90.number(),
3659
- y: z90.number(),
3660
- rotation: z90.number(),
3661
- id: z90.string(),
3662
- label: z90.string(),
3663
- labelColor: z90.string(),
3664
- path: z90.string(),
3665
- arrow: z90.string()
3666
- });
3667
- var parsePin = (pinString) => {
3668
- const parts = pinString.split("~");
3669
- const [, visibility, , pinNumber, x, y, rotation2, id] = parts;
3670
- const nameMatch = pinString.match(/~(\w+)~(start|end)~/);
3671
- const label = nameMatch ? nameMatch[1] : "";
3672
- const colorMatch = pinString.match(/#[0-9A-F]{6}/);
3673
- const labelColor = colorMatch ? colorMatch[0] : "";
3674
- const pathMatch = pinString.match(/\^\^([^~]+)/);
3675
- const path2 = pathMatch ? pathMatch[1] : "";
3676
- const arrowMatch = pinString.match(/\^\^0~(.+)$/);
3677
- const arrow = arrowMatch ? arrowMatch[1] : "";
3678
- const r = Number.parseFloat(rotation2);
3679
- return {
3680
- type: "PIN",
3681
- visibility,
3682
- id,
3683
- pinNumber: Number.isNaN(Number(pinNumber)) ? pinNumber : Number(pinNumber),
3684
- x: Number.parseFloat(x),
3685
- y: Number.parseFloat(y),
3686
- rotation: Number.isNaN(r) ? 0 : r,
3687
- label,
3688
- labelColor,
3689
- path: path2,
3690
- arrow
3691
- };
3692
- };
3693
- var PinShapeSchema = z90.string().startsWith("P~").transform(parsePin).pipe(PinShapeOutputSchema);
3694
- var PolylineShapeOutputSchema = z90.object({
3695
- type: z90.literal("POLYLINE"),
3696
- points: z90.array(PointSchema2),
3697
- color: z90.string(),
3698
- lineWidth: z90.number(),
3699
- id: z90.string()
3700
- });
3701
- var parsePoints2 = (pointsStr) => {
3702
- return pointsStr.split(" ").reduce((acc, value, index) => {
3703
- if (index % 2 === 0) {
3704
- acc.push({ x: Number(value), y: 0 });
3705
- } else {
3706
- acc[acc.length - 1].y = Number(value);
3707
- }
3708
- return acc;
3709
- }, []);
3710
- };
3711
- var parsePolyline = (str) => {
3712
- const [, ...rest] = str.split("~");
3713
- const [pointsStr, color, lineWidth, , , id] = rest;
3714
- return {
3715
- type: "POLYLINE",
3716
- points: parsePoints2(pointsStr),
3717
- color,
3718
- lineWidth: Number(lineWidth),
3719
- id
3720
- };
3721
- };
3722
- var PolylineShapeSchema = z90.string().startsWith("PL~").transform(parsePolyline).pipe(PolylineShapeOutputSchema);
3723
- var PolygonShapeOutputSchema = z90.object({
3724
- type: z90.literal("POLYGON"),
3725
- points: z90.array(PointSchema2),
3726
- fillColor: z90.string(),
3727
- lineWidth: z90.number(),
3728
- lineColor: z90.string(),
3729
- id: z90.string()
3730
- });
3731
- var parsePolygon = (str) => {
3732
- const [, ...rest] = str.split("~");
3733
- const [pointsStr, fillColor, lineWidth, lineColor, , id] = rest;
3734
- return {
3735
- type: "POLYGON",
3736
- points: parsePoints2(pointsStr),
3737
- fillColor,
3738
- lineWidth: Number(lineWidth),
3739
- lineColor,
3740
- id
3741
- };
3742
- };
3743
- var PolygonShapeSchema = z90.string().startsWith("PG~").transform(parsePolygon).pipe(PolygonShapeOutputSchema);
3744
- var PathShapeOutputSchema = z90.object({
3745
- type: z90.literal("PATH"),
3746
- pathData: z90.string(),
3747
- fillColor: z90.string(),
3748
- strokeWidth: z90.number(),
3749
- strokeColor: z90.string(),
3750
- id: z90.string()
3751
- });
3752
- var parsePath = (str) => {
3753
- const [, pathData, fillColor, strokeWidth, strokeColor, , id] = str.split("~");
3754
- return {
3755
- type: "PATH",
3756
- pathData,
3757
- fillColor,
3758
- strokeWidth: mil10ToMm(Number(strokeWidth)),
3759
- strokeColor,
3760
- id
3761
- };
3762
- };
3763
- var PathShapeSchema = z90.string().startsWith("PT~").transform(parsePath).pipe(PathShapeOutputSchema);
3764
- var TextShapeOutputSchema = z90.object({
3765
- type: z90.literal("TEXT"),
3766
- alignment: z90.enum(["L", "C", "R"]),
3767
- x: z90.number(),
3768
- y: z90.number(),
3769
- rotation: z90.number(),
3770
- fontColor: z90.string(),
3771
- backgroundColor: z90.string().optional(),
3772
- fontSize: z90.string(),
3773
- fontWeight: z90.enum(["normal", "bold"]).optional().default("normal"),
3774
- fontStyle: z90.enum(["normal", "italic"]).optional().default("normal"),
3775
- fontDecoration: z90.enum(["", "underline"]),
3776
- content: z90.string(),
3777
- textType: z90.string(),
3778
- visibility: z90.enum(["0", "1"]),
3779
- mirror: z90.string(),
3780
- id: z90.string()
3781
- });
3782
- var parseText = (str) => {
3783
- const [
3784
- ,
3785
- alignment,
3786
- x,
3787
- y,
3788
- rotation2,
3789
- fontColor,
3790
- backgroundColor,
3791
- fontSize,
3792
- fontWeight,
3793
- fontStyle,
3794
- fontDecoration,
3795
- content,
3796
- textType,
3797
- visibility,
3798
- mirror,
3799
- id
3800
- ] = str.split("~");
3801
- return {
3802
- type: "TEXT",
3803
- alignment,
3804
- x: Number(x),
3805
- y: Number(y),
3806
- rotation: Number(rotation2),
3807
- fontColor,
3808
- backgroundColor: backgroundColor || void 0,
3809
- fontSize,
3810
- fontWeight: fontWeight || "normal",
3811
- fontStyle: fontStyle || "normal",
3812
- fontDecoration,
3813
- content,
3814
- textType,
3815
- visibility,
3816
- mirror,
3817
- id
3818
- };
3819
- };
3820
- var TextShapeSchema = z90.string().startsWith("T~").transform(parseText).pipe(TextShapeOutputSchema);
3821
- var SingleLetterShapeSchema = z90.string().transform((x) => {
3822
- if (x.startsWith("R~")) return RectangleShapeSchema.parse(x);
3823
- if (x.startsWith("E~")) return EllipseShapeSchema.parse(x);
3824
- if (x.startsWith("P~")) return PinShapeSchema.parse(x);
3825
- if (x.startsWith("PL~")) return PolylineShapeSchema.parse(x);
3826
- if (x.startsWith("PG~")) return PolygonShapeSchema.parse(x);
3827
- if (x.startsWith("PT~")) return PathShapeSchema.parse(x);
3828
- if (x.startsWith("T~")) return TextShapeSchema.parse(x);
3829
- if (x.startsWith("A~")) return ArcShapeSchema.parse(x);
3830
- throw new Error(`Invalid shape type: ${x}`);
3831
- }).pipe(
3832
- z90.union([
3833
- RectangleShapeOutputSchema,
3834
- EllipseShapeOutputSchema,
3835
- PinShapeOutputSchema,
3836
- PolylineShapeOutputSchema,
3837
- PolygonShapeOutputSchema,
3838
- PathShapeOutputSchema,
3839
- TextShapeOutputSchema,
3840
- ArcShapeOutputSchema
3841
- ])
3842
- );
3843
-
3844
- // lib/schemas/easy-eda-json-schema.ts
3845
- var maybeNumber = z91.any().transform((k) => k === "nan" || Number.isNaN(k) ? null : k).pipe(z91.number().nullable().optional());
3846
- var SzlcscSchema = z91.object({
3847
- id: z91.number(),
3848
- number: z91.string(),
3849
- step: z91.number().optional(),
3850
- min: z91.number().optional(),
3851
- price: z91.number().optional(),
3852
- stock: z91.number().optional(),
3853
- url: z91.string().url().optional(),
3854
- image: z91.string().optional().optional()
3855
- });
3856
- var LcscSchema = z91.object({
3857
- id: z91.number(),
3858
- number: z91.string(),
3859
- step: z91.number().optional(),
3860
- min: z91.number().optional(),
3861
- price: z91.number().optional(),
3862
- stock: z91.number().optional(),
3863
- url: z91.string().url().optional()
3864
- });
3865
- var OwnerSchema = z91.object({
3866
- uuid: z91.string(),
3867
- username: z91.string(),
3868
- nickname: z91.string(),
3869
- avatar: z91.string()
3870
- });
3871
- var HeadSchema = z91.object({
3872
- docType: z91.preprocess((val) => val == null ? val : String(val), z91.string()),
3873
- editorVersion: z91.string(),
3874
- c_para: z91.record(z91.string(), z91.string().nullable()),
3875
- x: z91.number(),
3876
- y: z91.number(),
3877
- puuid: z91.string().optional(),
3878
- uuid: z91.string(),
3879
- utime: z91.preprocess((val) => {
3880
- if (val === "") return 0;
3881
- if (typeof val === "string") return Number(val);
3882
- return val;
3883
- }, z91.number()),
3884
- importFlag: z91.number().optional(),
3885
- c_spiceCmd: z91.any().optional(),
3886
- hasIdFlag: z91.boolean()
3887
- });
3888
- var BBoxSchema = z91.object({
3889
- x: z91.number(),
3890
- y: z91.number(),
3891
- width: z91.number(),
3892
- height: z91.number()
3893
- });
3894
- var LayerItemSchema = z91.object({
3895
- name: z91.string(),
3896
- color: z91.string(),
3897
- visible: z91.boolean(),
3898
- active: z91.boolean(),
3899
- config: z91.boolean(),
3900
- transparency: z91.boolean()
3901
- });
3902
- var ObjectItemSchema = z91.object({
3903
- name: z91.string(),
3904
- visible: z91.boolean(),
3905
- locked: z91.boolean()
3906
- });
3907
- var DataStrSchema = z91.object({
3908
- head: HeadSchema,
3909
- canvas: z91.string(),
3910
- shape: z91.array(SingleLetterShapeSchema),
3911
- BBox: BBoxSchema,
3912
- colors: z91.array(z91.unknown())
3913
- });
3914
- var PackageDetailDataStrSchema = z91.object({
3915
- head: HeadSchema,
3916
- canvas: z91.string(),
3917
- shape: z91.array(z91.string()).transform(
3918
- (shapes) => shapes.map((shape) => {
3919
- const [type, ...data] = shape.split("~");
3920
- return ShapeItemSchema.parse({ type, data: data.join("~") });
3921
- })
3922
- ).pipe(z91.array(PackageDetailShapeSchema)),
3923
- layers: z91.array(z91.string()).transform(
3924
- (layers) => layers.map((layer) => {
3925
- const [name, color, visible, active, config, transparency] = layer.split("~");
3926
- return LayerItemSchema.parse({
3927
- name,
3928
- color,
3929
- visible: visible === "true",
3930
- active: active === "true",
3931
- config: config === "true",
3932
- transparency: transparency === "true"
3933
- });
3934
- })
3935
- ),
3936
- objects: z91.array(z91.string()).transform(
3937
- (objects) => objects.map((obj) => {
3938
- const [name, visible, locked] = obj.split("~");
3939
- return ObjectItemSchema.parse({
3940
- name,
3941
- visible: visible === "true",
3942
- locked: locked === "true"
3943
- });
3944
- })
3945
- ),
3946
- BBox: BBoxSchema,
3947
- netColors: z91.array(z91.unknown()).optional()
3948
- });
3949
- var PackageDetailSchema = z91.object({
3950
- uuid: z91.string(),
3951
- title: z91.string(),
3952
- docType: z91.number(),
3953
- updateTime: z91.number(),
3954
- owner: OwnerSchema,
3955
- datastrid: z91.string(),
3956
- writable: z91.boolean(),
3957
- dataStr: PackageDetailDataStrSchema
3958
- });
3959
- var EasyEdaJsonSchema = z91.object({
3960
- uuid: z91.string(),
3961
- title: z91.string(),
3962
- description: z91.string(),
3963
- docType: z91.number(),
3964
- type: z91.number(),
3965
- szlcsc: SzlcscSchema,
3966
- lcsc: LcscSchema,
3967
- owner: OwnerSchema,
3968
- tags: z91.array(z91.string()),
3969
- updateTime: z91.number(),
3970
- updated_at: z91.string(),
3971
- dataStr: DataStrSchema,
3972
- verify: z91.boolean(),
3973
- SMT: z91.boolean().optional(),
3974
- datastrid: z91.string(),
3975
- jlcOnSale: z91.number().optional(),
3976
- writable: z91.boolean(),
3977
- isFavorite: z91.boolean(),
3978
- packageDetail: PackageDetailSchema
3979
- });
3980
-
3981
- // lib/websafe/generate-footprint-tsx.ts
3982
- import { mmStr } from "@tscircuit/mm";
3983
- var generateFootprintTsx = (circuitJson) => {
3984
- const holes = su(circuitJson).pcb_hole.list();
3985
- const platedHoles = su(circuitJson).pcb_plated_hole.list();
3986
- const smtPads = su(circuitJson).pcb_smtpad.list();
3987
- const vias = su(circuitJson).pcb_via.list();
3988
- const silkscreenPaths = su(circuitJson).pcb_silkscreen_path.list();
3989
- const silkscreenTexts = su(circuitJson).pcb_silkscreen_text.list();
3990
- const elementStrings = [];
3991
- for (const hole of holes) {
3992
- if (hole.hole_shape === "circle") {
3993
- elementStrings.push(
3994
- `<hole pcbX="${mmStr(hole.x)}" pcbY="${mmStr(hole.y)}" diameter="${mmStr(hole.hole_diameter)}" />`
3995
- );
3996
- } else if (hole.hole_shape === "oval") {
3997
- console.warn("Unhandled oval hole in conversion (needs implementation)");
3998
- }
3999
- }
4000
- for (const platedHole of platedHoles) {
4001
- if (platedHole.shape === "oval" || platedHole.shape === "pill") {
4002
- elementStrings.push(
4003
- `<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" outerHeight="${mmStr(platedHole.outer_height)}" outerWidth="${mmStr(platedHole.outer_width)}" holeHeight="${mmStr(platedHole.hole_height)}" holeWidth="${mmStr(platedHole.hole_width)}" shape="${platedHole.shape}" />`
4004
- );
4005
- } else if (platedHole.shape === "circle") {
4006
- elementStrings.push(
4007
- `<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" outerDiameter="${mmStr(platedHole.outer_diameter)}" holeDiameter="${mmStr(platedHole.hole_diameter)}" shape="circle" />`
4008
- );
4009
- }
4010
- }
4011
- for (const smtPad of smtPads) {
4012
- if (smtPad.shape === "circle") {
4013
- elementStrings.push(
4014
- `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" radius="${mmStr(smtPad.radius)}" shape="circle" />`
4015
- );
4016
- } else if (smtPad.shape === "rect") {
4017
- elementStrings.push(
4018
- `<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}" shape="rect" />`
4019
- );
4020
- }
4021
- }
4022
- for (const via of vias) {
4023
- elementStrings.push(
4024
- `<via pcbX="${mmStr(via.x)}" pcbY="${mmStr(via.y)}" outerDiameter="${mmStr(via.outer_diameter)}" holeDiameter="${mmStr(via.hole_diameter)}" layers={${JSON.stringify(via.layers)}} />`
4025
- );
4026
- }
4027
- for (const silkscreenPath of silkscreenPaths) {
4028
- elementStrings.push(
4029
- `<silkscreenpath route={${JSON.stringify(silkscreenPath.route)}} />`
4030
- );
4031
- }
4032
- for (const silkscreenText of silkscreenTexts) {
4033
- elementStrings.push(
4034
- `<silkscreentext text="${silkscreenText.text}" pcbX="${mmStr(silkscreenText.anchor_position.x)}" pcbY="${mmStr(silkscreenText.anchor_position.y)}" anchorAlignment="${silkscreenText.anchor_alignment}" ${silkscreenText.font_size ? `fontSize="${mmStr(silkscreenText.font_size)}"` : ""} />`
4035
- );
4036
- }
4037
- return `
4038
- <footprint>
4039
- ${elementStrings.join("\n")}
4040
- </footprint>
4041
- `.trim();
4042
- };
4043
-
4044
- // lib/websafe/convert-to-typescript-component/generate-typescript-component.ts
4045
- var generateTypescriptComponent = ({
4046
- pinLabels,
4047
- componentName,
4048
- objUrl,
4049
- circuitJson,
4050
- supplierPartNumbers,
4051
- manufacturerPartNumber
4052
- }) => {
4053
- const safePinLabels = pinLabels ?? {};
4054
- const cadComponent = circuitJson.find((item) => item.type === "cad_component");
4055
- const footprintTsx = generateFootprintTsx(circuitJson);
4056
- const simplifiedPinLabels = Object.fromEntries(
4057
- Object.entries(safePinLabels).map(([pin, labels]) => {
4058
- if (Array.isArray(labels) && labels.length > 1) {
4059
- return [pin, [labels[1]]];
4060
- }
4061
- return [pin, labels];
4062
- })
4063
- );
4064
- const pinLabelsString = Object.entries(simplifiedPinLabels).map(([pin, labels]) => ` ${pin}: ${JSON.stringify(labels)}`).join(",\n");
4065
- return `
4066
- import type { ChipProps } from "@tscircuit/props"
4067
-
4068
- const pinLabels = {
4069
- ${pinLabelsString}
4070
- } as const
4071
-
4072
- export const ${componentName} = (props: ChipProps<typeof pinLabels>) => {
4073
- return (
4074
- <chip
4075
- pinLabels={pinLabels}
4076
- supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
4077
- manufacturerPartNumber="${manufacturerPartNumber}"
4078
- footprint={${footprintTsx}}
4079
- ${objUrl ? `cadModel={{
4080
- objUrl: "${objUrl}",
4081
- rotationOffset: { x: 0, y: 0, z: ${cadComponent?.rotation?.z ?? 0} },
4082
- positionOffset: { x: 0, y: 0, z: 0 },
4083
- }}` : ""}
4084
- {...props}
4085
- />
4086
- )
4087
- }
4088
- `.trim();
4089
- };
4090
-
4091
- // lib/utils/normalize-manufacturer-part-number.ts
4092
- function normalizeManufacturerPartNumber(partNumber) {
4093
- let normalized = partNumber.replace(/[-]/g, "_").replace(/[^a-zA-Z0-9_$]/g, "_");
4094
- if (/^\d/.test(normalized)) {
4095
- normalized = "A_" + normalized;
4096
- }
4097
- return normalized;
4098
- }
4099
-
4100
- // lib/websafe/convert-to-typescript-component/index.tsx
4101
- var convertRawEasyToTsx = async (rawEasy) => {
4102
- const betterEasy = EasyEdaJsonSchema.parse(rawEasy);
4103
- const result = await convertBetterEasyToTsx({
4104
- betterEasy
4105
- });
4106
- return result;
4107
- };
4108
- var convertBetterEasyToTsx = async ({
4109
- betterEasy
4110
- }) => {
4111
- const circuitJson = convertEasyEdaJsonToCircuitJson(betterEasy, {
4112
- useModelCdn: true,
4113
- shouldRecenter: true
4114
- });
4115
- const rawPn = betterEasy.dataStr.head.c_para["Manufacturer Part"];
4116
- const pn = rawPn ? normalizeManufacturerPartNumber(rawPn) : "unknown";
4117
- const sourcePorts = su(circuitJson).source_port.list();
4118
- const pinLabels = {};
4119
- const sortedPorts = sourcePorts.sort((a, b) => {
4120
- const aNum = Number.parseInt(a.name.replace("pin", ""));
4121
- const bNum = Number.parseInt(b.name.replace("pin", ""));
4122
- return aNum - bNum;
4123
- });
4124
- for (const sourcePort of sortedPorts) {
4125
- pinLabels[sourcePort.name] = [
4126
- sourcePort.name,
4127
- ...sourcePort.port_hints ?? []
4128
- ];
4129
- }
4130
- const [cadComponent] = su(circuitJson).cad_component.list();
4131
- let modelObjUrl;
4132
- if (cadComponent?.model_obj_url) {
4133
- const isValidUrl = await checkModelObjUrlValidity(
4134
- cadComponent.model_obj_url
4135
- );
4136
- if (isValidUrl) {
4137
- modelObjUrl = cadComponent.model_obj_url;
4138
- }
4139
- }
4140
- const supplierPartNumbers = {
4141
- jlcpcb: [betterEasy.lcsc.number]
4142
- };
4143
- return generateTypescriptComponent({
4144
- componentName: pn,
4145
- manufacturerPartNumber: pn,
4146
- pinLabels,
4147
- objUrl: modelObjUrl,
4148
- circuitJson,
4149
- supplierPartNumbers
4150
- });
4151
- };
4152
- var checkModelObjUrlValidity = async (url) => {
4153
- try {
4154
- const response = await fetch(url, { method: "HEAD" });
4155
- return response.status === 200;
4156
- } catch (error) {
4157
- console.error(`Error checking model object URL ${url}:`, error);
4158
- return false;
4159
- }
4160
- };
4161
-
4162
- // lib/convert-easyeda-json-to-various-formats.ts
4163
- import fs from "fs/promises";
4164
- import * as path from "path";
4165
- var convertEasyEdaJsonToVariousFormats = async ({
4166
- jlcpcbPartNumberOrFilepath,
4167
- outputFilename,
4168
- outputFormat
4169
- }) => {
4170
- let rawEasyEdaJson;
4171
- if (jlcpcbPartNumberOrFilepath.includes(".") || jlcpcbPartNumberOrFilepath.includes("/")) {
4172
- rawEasyEdaJson = JSON.parse(
4173
- await fs.readFile(jlcpcbPartNumberOrFilepath, "utf-8")
4174
- );
4175
- } else {
4176
- rawEasyEdaJson = await fetchEasyEDAComponent(jlcpcbPartNumberOrFilepath);
4177
- }
4178
- const tsxExtension = "tsx";
4179
- if (outputFormat === "ts") outputFormat = tsxExtension;
4180
- if (!outputFilename && outputFormat) {
4181
- let filename = path.basename(jlcpcbPartNumberOrFilepath).split(".")[0];
4182
- if (outputFormat === tsxExtension) {
4183
- const {
4184
- dataStr: {
4185
- head: {
4186
- c_para: { "Manufacturer Part": manufacturerPartNumber }
4187
- }
4188
- }
4189
- } = rawEasyEdaJson;
4190
- filename = normalizeManufacturerPartNumber(manufacturerPartNumber);
4191
- }
4192
- outputFilename = `${filename}.${outputFormat}`;
4193
- }
4194
- if (!outputFilename) {
4195
- console.log("specify --output file (-o) or --output-format");
4196
- process.exit(1);
4197
- }
4198
- if (outputFilename.endsWith(".raweasy.json")) {
4199
- await fs.writeFile(outputFilename, JSON.stringify(rawEasyEdaJson, null, 2));
4200
- console.log(`Saved raw EasyEDA JSON: ${outputFilename}`);
4201
- return;
4202
- }
4203
- try {
4204
- const betterEasy = EasyEdaJsonSchema.parse(rawEasyEdaJson);
4205
- const tscircuitSoup = convertEasyEdaJsonToTscircuitSoupJson(betterEasy);
4206
- if (outputFilename.endsWith(".soup.json") || outputFilename.endsWith(".circuit.json")) {
4207
- await fs.writeFile(outputFilename, JSON.stringify(tscircuitSoup, null, 2));
4208
- console.log(
4209
- `[${jlcpcbPartNumberOrFilepath}] Converted to circuit json: ${outputFilename}`
4210
- );
4211
- } else if (outputFilename.endsWith(".kicad_mod")) {
4212
- console.log("Conversion to KiCad footprint not yet implemented");
4213
- } else if (outputFilename.endsWith(".bettereasy.json")) {
4214
- await fs.writeFile(outputFilename, JSON.stringify(betterEasy, null, 2));
4215
- console.log(
4216
- `[${jlcpcbPartNumberOrFilepath}] Saved better EasyEDA JSON: ${outputFilename}`
4217
- );
4218
- } else if (outputFilename.endsWith(".tsx") || outputFilename.endsWith(".ts")) {
4219
- const tsComp = await convertRawEasyToTsx(rawEasyEdaJson);
4220
- await fs.writeFile(outputFilename, tsComp);
4221
- console.log(
4222
- `[${jlcpcbPartNumberOrFilepath}] Saved TypeScript component: ${outputFilename}`
4223
- );
4224
- } else {
4225
- console.error("Unsupported output format");
4226
- }
4227
- } catch (error) {
4228
- console.error("Error:", error.message);
4229
- throw error;
4230
- }
4231
- };
4232
-
4233
- export {
4234
- fetchEasyEDAComponent,
4235
- convertEasyEdaJsonToCircuitJson,
4236
- convertEasyEdaJsonToTscircuitSoupJson,
4237
- maybeNumber,
4238
- SzlcscSchema,
4239
- LcscSchema,
4240
- OwnerSchema,
4241
- HeadSchema,
4242
- BBoxSchema,
4243
- LayerItemSchema,
4244
- ObjectItemSchema,
4245
- DataStrSchema,
4246
- PackageDetailDataStrSchema,
4247
- PackageDetailSchema,
4248
- EasyEdaJsonSchema,
4249
- normalizeManufacturerPartNumber,
4250
- convertRawEasyToTsx,
4251
- convertEasyEdaJsonToVariousFormats
4252
- };
4253
- //# sourceMappingURL=chunk-E6OHT5YV.js.map