@tscircuit/cli 0.1.187 → 0.1.189

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.
Files changed (2) hide show
  1. package/dist/main.js +3128 -86
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -60975,7 +60975,7 @@ import { isDeepStrictEqual } from "node:util";
60975
60975
  import process7 from "node:process";
60976
60976
  import fs5 from "node:fs";
60977
60977
  import path8 from "node:path";
60978
- import crypto from "node:crypto";
60978
+ import crypto2 from "node:crypto";
60979
60979
  import assert from "node:assert";
60980
60980
 
60981
60981
  // node_modules/dot-prop/index.js
@@ -62068,8 +62068,8 @@ class Conf {
62068
62068
  }
62069
62069
  try {
62070
62070
  const initializationVector = data.slice(0, 16);
62071
- const password = crypto.pbkdf2Sync(this.#encryptionKey, initializationVector.toString(), 1e4, 32, "sha512");
62072
- const decipher = crypto.createDecipheriv(encryptionAlgorithm, password, initializationVector);
62071
+ const password = crypto2.pbkdf2Sync(this.#encryptionKey, initializationVector.toString(), 1e4, 32, "sha512");
62072
+ const decipher = crypto2.createDecipheriv(encryptionAlgorithm, password, initializationVector);
62073
62073
  const slice = data.slice(17);
62074
62074
  const dataUpdate = typeof slice === "string" ? stringToUint8Array(slice) : slice;
62075
62075
  return uint8ArrayToString(concatUint8Arrays([decipher.update(dataUpdate), decipher.final()]));
@@ -62111,9 +62111,9 @@ class Conf {
62111
62111
  _write(value) {
62112
62112
  let data = this._serialize(value);
62113
62113
  if (this.#encryptionKey) {
62114
- const initializationVector = crypto.randomBytes(16);
62115
- const password = crypto.pbkdf2Sync(this.#encryptionKey, initializationVector.toString(), 1e4, 32, "sha512");
62116
- const cipher = crypto.createCipheriv(encryptionAlgorithm, password, initializationVector);
62114
+ const initializationVector = crypto2.randomBytes(16);
62115
+ const password = crypto2.pbkdf2Sync(this.#encryptionKey, initializationVector.toString(), 1e4, 32, "sha512");
62116
+ const cipher = crypto2.createCipheriv(encryptionAlgorithm, password, initializationVector);
62117
62117
  data = concatUint8Arrays([initializationVector, stringToUint8Array(":"), cipher.update(stringToUint8Array(data)), cipher.final()]);
62118
62118
  }
62119
62119
  if (process7.env.SNAP) {
@@ -62951,7 +62951,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
62951
62951
  import { execSync as execSync2 } from "node:child_process";
62952
62952
  var import_semver2 = __toESM2(require_semver2(), 1);
62953
62953
  // package.json
62954
- var version = "0.1.186";
62954
+ var version = "0.1.188";
62955
62955
  var package_default = {
62956
62956
  name: "@tscircuit/cli",
62957
62957
  version,
@@ -69569,54 +69569,3095 @@ var registerConfigSet = (program3) => {
69569
69569
  };
69570
69570
 
69571
69571
  // cli/search/register.ts
69572
- var import_prompts5 = __toESM2(require_prompts3(), 1);
69573
69572
  var registerSearch = (program3) => {
69574
69573
  program3.command("search").description("Search for packages in the tscircuit registry").argument("<query>", "Search query (e.g. keyword, author, or package name)").action(async (query) => {
69575
69574
  const ky2 = getRegistryApiKy();
69576
69575
  let results = { packages: [] };
69576
+ let jlcResults = [];
69577
69577
  try {
69578
69578
  results = await ky2.post("packages/search", {
69579
69579
  json: { query }
69580
69580
  }).json();
69581
+ const jlcSearchUrl = "https://jlcsearch.tscircuit.com/api/search?limit=10&q=" + encodeURIComponent(query);
69582
+ jlcResults = (await fetch(jlcSearchUrl).then((r) => r.json())).components;
69581
69583
  } catch (error) {
69582
69584
  console.error(kleur_default.red("Failed to search registry:"), error instanceof Error ? error.message : error);
69583
69585
  process.exit(1);
69584
69586
  }
69585
- if (!results.packages.length) {
69586
- console.log(kleur_default.yellow("No packages found matching your query."));
69587
+ if (!results.packages.length && !jlcResults.length) {
69588
+ console.log(kleur_default.yellow("No results found matching your query."));
69587
69589
  return;
69588
69590
  }
69589
- console.log(kleur_default.bold().underline(`Found ${results.packages.length} package(s):`));
69590
- const choices = results.packages.map((pkg) => ({
69591
- title: pkg.name,
69592
- description: pkg.description || "",
69593
- value: pkg.name
69594
- }));
69595
- const { selectedPackage } = await import_prompts5.default({
69596
- type: "select",
69597
- name: "selectedPackage",
69598
- message: "Select a package to add:",
69599
- choices,
69600
- initial: 0
69591
+ if (results.packages.length) {
69592
+ console.log(kleur_default.bold().underline(`Found ${results.packages.length} package(s) in the tscircuit registry:`));
69593
+ results.packages.forEach((pkg, idx) => {
69594
+ const star = pkg.star_count ?? 0;
69595
+ console.log(`${idx + 1}. ${pkg.name} (v${pkg.version}) - Stars: ${star}${pkg.description ? ` - ${pkg.description}` : ""}`);
69596
+ });
69597
+ }
69598
+ if (jlcResults.length) {
69599
+ console.log();
69600
+ console.log(kleur_default.bold().underline(`Found ${jlcResults.length} component(s) in JLC search:`));
69601
+ jlcResults.forEach((comp, idx) => {
69602
+ console.log(`${idx + 1}. ${comp.mfr} (C${comp.lcsc}) - ${comp.description}`);
69603
+ });
69604
+ }
69605
+ console.log(`
69606
+ `);
69607
+ });
69608
+ };
69609
+
69610
+ // node_modules/easyeda/dist/browser/index.js
69611
+ import { z as z33 } from "zod";
69612
+ import { z as z20 } from "zod";
69613
+ import { z as z23 } from "zod";
69614
+
69615
+ // node_modules/@tscircuit/mm/dist/index.js
69616
+ var unitToMm = {
69617
+ in: 25.4,
69618
+ inch: 25.4,
69619
+ mil: 0.0254,
69620
+ mm: 1,
69621
+ m: 1000,
69622
+ cm: 10,
69623
+ ft: 304.8,
69624
+ feet: 304.8
69625
+ };
69626
+ var mm = (n2) => {
69627
+ let unit = typeof n2 === "number" ? "mm" : n2.replace(/^[^a-zA-Z]+/g, "").toLowerCase();
69628
+ if (!unit)
69629
+ unit = "mm";
69630
+ const val = typeof n2 === "number" ? n2 : Number.parseFloat(n2.split(unit)[0]);
69631
+ if (unit in unitToMm) {
69632
+ return val * unitToMm[unit];
69633
+ }
69634
+ throw new Error(`Unsupported unit: ${unit}`);
69635
+ };
69636
+ var mmStr = (n2) => {
69637
+ return `${mm(n2)}mm`;
69638
+ };
69639
+
69640
+ // node_modules/easyeda/dist/browser/index.js
69641
+ import { z as z43 } from "zod";
69642
+ import { z as z222 } from "zod";
69643
+ import { z as z322 } from "zod";
69644
+ import { z as z422 } from "zod";
69645
+ import { z as z53 } from "zod";
69646
+ import { z as z82 } from "zod";
69647
+ import { z as z62 } from "zod";
69648
+ import { z as z72 } from "zod";
69649
+ import { z as z92 } from "zod";
69650
+ import { z as z102 } from "zod";
69651
+ import { z as z112 } from "zod";
69652
+ import { z as z122 } from "zod";
69653
+ import { z as z132 } from "zod";
69654
+ import { z as z142 } from "zod";
69655
+ import { z as z152 } from "zod";
69656
+ import { z as z27 } from "zod";
69657
+ import { z as z162 } from "zod";
69658
+ import { z as z172 } from "zod";
69659
+ import { z as z182 } from "zod";
69660
+ import { z as z192 } from "zod";
69661
+ import { z as z202 } from "zod";
69662
+ import { z as z21 } from "zod";
69663
+ import { z as z2222 } from "zod";
69664
+ import { z as z232 } from "zod";
69665
+ import { z as z24 } from "zod";
69666
+ import { z as z25 } from "zod";
69667
+ import { z as z26 } from "zod";
69668
+ import { z as z28 } from "zod";
69669
+ import { z as z29 } from "zod";
69670
+ import { z as z30 } from "zod";
69671
+ import { z as z31 } from "zod";
69672
+ import { z as z3222 } from "zod";
69673
+ import { z as z332 } from "zod";
69674
+ import { z as z34 } from "zod";
69675
+ import { z as z35 } from "zod";
69676
+ import { z as z36 } from "zod";
69677
+ import { z as z37 } from "zod";
69678
+ import { z as z38 } from "zod";
69679
+ import { z as z39 } from "zod";
69680
+ import { z as z40 } from "zod";
69681
+ import { z as z41 } from "zod";
69682
+ import { z as z4222 } from "zod";
69683
+ import { z as z432 } from "zod";
69684
+ import { z as z44 } from "zod";
69685
+ import { z as z45 } from "zod";
69686
+ import { z as z46 } from "zod";
69687
+ import { z as z47 } from "zod";
69688
+ import { z as z48 } from "zod";
69689
+ import { z as z49 } from "zod";
69690
+ import { z as z50 } from "zod";
69691
+ import { z as z51 } from "zod";
69692
+ import { z as z522 } from "zod";
69693
+ import { z as z532 } from "zod";
69694
+ import { z as z54 } from "zod";
69695
+ import { z as z55 } from "zod";
69696
+ import { z as z56 } from "zod";
69697
+ import { z as z57 } from "zod";
69698
+ import { z as z58 } from "zod";
69699
+ import { z as z59 } from "zod";
69700
+ import { z as z60 } from "zod";
69701
+ import { z as z61 } from "zod";
69702
+ import { z as z622 } from "zod";
69703
+ import { z as z63 } from "zod";
69704
+ import { z as z64 } from "zod";
69705
+ import { z as z65 } from "zod";
69706
+ import { z as z66 } from "zod";
69707
+ import { z as z67 } from "zod";
69708
+ import { z as z68 } from "zod";
69709
+ import { z as z69 } from "zod";
69710
+ import { z as z70 } from "zod";
69711
+ import { z as z71 } from "zod";
69712
+ import { z as z722 } from "zod";
69713
+ import { z as z73 } from "zod";
69714
+ import { z as z74 } from "zod";
69715
+ import { applyToPoint as applyToPoint3, decomposeTSR as decomposeTSR2 } from "transformation-matrix";
69716
+ import { compose, scale as scale6, translate } from "transformation-matrix";
69717
+ var __defProp3 = Object.defineProperty;
69718
+ var __export2 = (target, all) => {
69719
+ for (var name in all)
69720
+ __defProp3(target, name, { get: all[name], enumerable: true });
69721
+ };
69722
+ var tenthmil = z20.union([z20.number(), z20.string()]).optional().transform((n2) => typeof n2 === "string" && n2.endsWith("mil") ? n2 : `${Number.parseFloat(n2) * 10}mil`).pipe(z20.string());
69723
+ var PointSchema = z20.any().transform((p) => {
69724
+ if (Array.isArray(p)) {
69725
+ const [x, y] = p;
69726
+ return { x, y };
69727
+ } else if (typeof p === "object") {
69728
+ return p;
69729
+ }
69730
+ throw new Error(`Invalid point: ${p}`);
69731
+ }).pipe(z20.object({
69732
+ x: z20.number(),
69733
+ y: z20.number()
69734
+ }));
69735
+ var BaseShapeSchema = z20.object({
69736
+ type: z20.string(),
69737
+ id: z20.string().optional(),
69738
+ layer: z20.coerce.number().optional()
69739
+ });
69740
+ var TrackSchema = BaseShapeSchema.extend({
69741
+ type: z20.literal("TRACK"),
69742
+ width: z20.coerce.number(),
69743
+ points: z20.array(PointSchema)
69744
+ });
69745
+ var PadSchema = BaseShapeSchema.extend({
69746
+ type: z20.literal("PAD"),
69747
+ shape: z20.enum(["RECT", "ELLIPSE", "OVAL"]),
69748
+ center: z20.object({
69749
+ x: tenthmil,
69750
+ y: tenthmil
69751
+ }),
69752
+ width: tenthmil,
69753
+ height: tenthmil,
69754
+ layermask: z20.number(),
69755
+ net: z20.union([z20.string(), z20.number()]).optional(),
69756
+ number: z20.union([z20.string(), z20.number()]),
69757
+ holeRadius: tenthmil,
69758
+ points: z20.array(PointSchema).optional(),
69759
+ rotation: z20.number().optional(),
69760
+ plated: z20.boolean()
69761
+ });
69762
+ var ArcSchema = BaseShapeSchema.extend({
69763
+ type: z20.literal("ARC"),
69764
+ width: z20.number(),
69765
+ start: PointSchema,
69766
+ end: PointSchema,
69767
+ radiusX: z20.number(),
69768
+ radiusY: z20.number(),
69769
+ largeArc: z20.boolean(),
69770
+ sweepDirection: z20.enum(["CW", "CCW"])
69771
+ });
69772
+ var CircleSchema = BaseShapeSchema.extend({
69773
+ type: z20.literal("CIRCLE"),
69774
+ center: PointSchema,
69775
+ radius: z20.number(),
69776
+ width: z20.number()
69777
+ });
69778
+ var SolidRegionSchema = BaseShapeSchema.extend({
69779
+ type: z20.literal("SOLIDREGION"),
69780
+ layermask: z20.number(),
69781
+ points: z20.array(PointSchema),
69782
+ fillStyle: z20.string()
69783
+ });
69784
+ var SVGNodeSchema = BaseShapeSchema.extend({
69785
+ type: z20.literal("SVGNODE"),
69786
+ svgData: z20.object({
69787
+ gId: z20.string(),
69788
+ nodeName: z20.string(),
69789
+ nodeType: z20.number(),
69790
+ layerid: z20.string(),
69791
+ attrs: z20.record(z20.string(), z20.string()),
69792
+ childNodes: z20.array(z20.unknown())
69793
+ })
69794
+ });
69795
+ var HoleSchema = BaseShapeSchema.extend({
69796
+ type: z20.literal("HOLE"),
69797
+ center: PointSchema,
69798
+ radius: z20.number()
69799
+ });
69800
+ var RectSchema = BaseShapeSchema.extend({
69801
+ type: z20.literal("RECT"),
69802
+ x: tenthmil,
69803
+ y: tenthmil,
69804
+ width: tenthmil,
69805
+ height: tenthmil,
69806
+ lineWidth: z20.number(),
69807
+ fillStyle: z20.string(),
69808
+ rotation: z20.number().optional()
69809
+ });
69810
+ var TextSchema = BaseShapeSchema.extend({
69811
+ type: z20.literal("TEXT"),
69812
+ text: z20.string(),
69813
+ x: tenthmil,
69814
+ y: tenthmil,
69815
+ size_mm: z20.number(),
69816
+ rotation: z20.number().optional(),
69817
+ layer: z20.number().optional(),
69818
+ textAnchor: z20.enum(["L", "C", "R", ""]).optional().transform((val) => val === "" ? undefined : val),
69819
+ font: z20.string().optional()
69820
+ });
69821
+ var PackageDetailShapeSchema = z20.discriminatedUnion("type", [
69822
+ TrackSchema,
69823
+ PadSchema,
69824
+ ArcSchema,
69825
+ CircleSchema,
69826
+ SolidRegionSchema,
69827
+ SVGNodeSchema,
69828
+ HoleSchema,
69829
+ RectSchema,
69830
+ TextSchema
69831
+ ]);
69832
+ var pairs = (arr) => {
69833
+ const pairs2 = [];
69834
+ for (let i = 0;i < arr.length; i += 2) {
69835
+ pairs2.push([arr[i], arr[i + 1]]);
69836
+ }
69837
+ return pairs2;
69838
+ };
69839
+ var parsePoints = (pointsStr) => pairs(pointsStr.trim().split(" ").map((n2) => Number(n2)));
69840
+ var ShapeItemSchema = z20.object({
69841
+ type: z20.string(),
69842
+ data: z20.string()
69843
+ }).transform((shape) => {
69844
+ const [firstParam, ...restParams] = shape.data.split("~");
69845
+ const lastParam = restParams.pop();
69846
+ switch (shape.type) {
69847
+ case "TRACK": {
69848
+ const [width, layer, _, pointsStr, id, _n] = shape.data.split("~");
69849
+ const points = parsePoints(pointsStr);
69850
+ return TrackSchema.parse({ type: "TRACK", width, layer, points, id });
69851
+ }
69852
+ case "PAD": {
69853
+ const [padShape, ...params2] = shape.data.split("~");
69854
+ const [
69855
+ centerX,
69856
+ centerY,
69857
+ width,
69858
+ height,
69859
+ layermask,
69860
+ net2,
69861
+ number,
69862
+ holeRadius,
69863
+ ...rest
69864
+ ] = params2.map((p) => isNaN(Number(p)) ? p : Number(p));
69865
+ const center = { x: centerX, y: centerY };
69866
+ let points, rotation2;
69867
+ if (padShape === "RECT") {
69868
+ points = parsePoints(rest[0]);
69869
+ rotation2 = Number(rest[1]);
69870
+ }
69871
+ const padInputParams = {
69872
+ type: "PAD",
69873
+ shape: padShape,
69874
+ center,
69875
+ width,
69876
+ height,
69877
+ layermask,
69878
+ net: net2,
69879
+ number,
69880
+ holeRadius,
69881
+ points,
69882
+ rotation: rotation2,
69883
+ plated: rest.includes("Y")
69884
+ };
69885
+ const pad = PadSchema.parse(padInputParams);
69886
+ return pad;
69887
+ }
69888
+ case "ARC": {
69889
+ const [width, layer, , arcData] = shape.data.split("~");
69890
+ const match = arcData.match(/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.-]+)/);
69891
+ if (!match) {
69892
+ throw new Error(`Invalid arc data: ${arcData}`);
69893
+ }
69894
+ const [
69895
+ ,
69896
+ startX,
69897
+ startY,
69898
+ radiusX,
69899
+ radiusY,
69900
+ xAxisRotation,
69901
+ largeArcFlag,
69902
+ sweepFlag,
69903
+ endX,
69904
+ endY
69905
+ ] = match;
69906
+ const start = [Number(startX), Number(startY)];
69907
+ const end = [Number(endX), Number(endY)];
69908
+ return ArcSchema.parse({
69909
+ type: "ARC",
69910
+ width: Number(width),
69911
+ layer: Number(layer),
69912
+ start,
69913
+ end,
69914
+ radiusX: Number(radiusX),
69915
+ radiusY: Number(radiusY),
69916
+ largeArc: largeArcFlag === "1",
69917
+ sweepDirection: sweepFlag === "1" ? "CW" : "CCW"
69918
+ });
69919
+ }
69920
+ case "CIRCLE": {
69921
+ const [centerX, centerY, radius, width, layer, id] = shape.data.split("~");
69922
+ const center = [Number(centerX), Number(centerY)];
69923
+ return CircleSchema.parse({
69924
+ type: "CIRCLE",
69925
+ center,
69926
+ radius: Number(radius),
69927
+ width: Number(width),
69928
+ layer: Number(layer),
69929
+ id
69930
+ });
69931
+ }
69932
+ case "HOLE": {
69933
+ const [centerX, centerY, radius, id] = shape.data.split("~");
69934
+ const center = [Number(centerX), Number(centerY)];
69935
+ return HoleSchema.parse({
69936
+ type: "HOLE",
69937
+ center,
69938
+ radius: Number(radius),
69939
+ id
69940
+ });
69941
+ }
69942
+ case "SOLIDREGION": {
69943
+ const [layermask, , pathData, fillStyle, id] = shape.data.split("~");
69944
+ const points = pathData.match(/[ML] ?(-?[\d.]+)[ ,](-?[\d.]+)/g)?.map((point2) => {
69945
+ const [, x, y] = point2.match(/[ML]? ?(-?[\d.]+)[ ,](-?[\d.]+)/) || [];
69946
+ return [Number(x), Number(y)];
69947
+ }) || [];
69948
+ return SolidRegionSchema.parse({
69949
+ type: "SOLIDREGION",
69950
+ layermask: Number(layermask),
69951
+ points,
69952
+ fillStyle,
69953
+ id
69954
+ });
69955
+ }
69956
+ case "SVGNODE": {
69957
+ const svgData = JSON.parse(shape.data);
69958
+ return SVGNodeSchema.parse({ type: "SVGNODE", svgData });
69959
+ }
69960
+ case "RECT": {
69961
+ const [x, y, width, height, lineWidth, id, rotation2, layer, fillStyle] = shape.data.split("~");
69962
+ return RectSchema.parse({
69963
+ type: "RECT",
69964
+ x,
69965
+ y,
69966
+ width,
69967
+ height,
69968
+ lineWidth: Number(lineWidth),
69969
+ id,
69970
+ rotation: rotation2 ? Number(rotation2) : undefined,
69971
+ layer: layer ? Number(layer) : undefined,
69972
+ fillStyle: fillStyle || undefined
69973
+ });
69974
+ }
69975
+ case "TEXT": {
69976
+ const [textAnchor, x, y, size2, layer, id, rotation2, , font, text] = shape.data.split("~");
69977
+ return TextSchema.parse({
69978
+ type: "TEXT",
69979
+ text,
69980
+ x,
69981
+ y,
69982
+ size_mm: Number(size2) * 2.54,
69983
+ layer: layer ? Number(layer) : undefined,
69984
+ id,
69985
+ rotation: rotation2 ? Number(rotation2) : undefined,
69986
+ textAnchor,
69987
+ font: font || undefined
69988
+ });
69989
+ }
69990
+ default:
69991
+ throw new Error(`Unknown shape type: ${shape.type}`);
69992
+ return BaseShapeSchema.parse({ type: shape.type });
69993
+ }
69994
+ }).pipe(PackageDetailShapeSchema);
69995
+ var ShapesArraySchema = z20.array(ShapeItemSchema);
69996
+ var mil10ToMm = (value) => value * 10 * 0.0254;
69997
+ var PointSchema2 = z23.object({
69998
+ x: z23.number(),
69999
+ y: z23.number()
70000
+ });
70001
+ var RectangleShapeOutputSchema = z23.object({
70002
+ type: z23.literal("RECTANGLE"),
70003
+ position: PointSchema2,
70004
+ width: z23.number(),
70005
+ height: z23.number(),
70006
+ color: z23.string(),
70007
+ lineWidth: z23.number(),
70008
+ id: z23.string()
70009
+ });
70010
+ var parseRectangle = (str) => {
70011
+ const [, x, y, , , width, height, color, lineWidth, , , id] = str.split("~");
70012
+ return {
70013
+ type: "RECTANGLE",
70014
+ position: { x: Number(x), y: Number(y) },
70015
+ width: Number(width),
70016
+ height: Number(height),
70017
+ color,
70018
+ lineWidth: Number(lineWidth),
70019
+ id
70020
+ };
70021
+ };
70022
+ var RectangleShapeSchema = z23.string().startsWith("R~").transform(parseRectangle).pipe(RectangleShapeOutputSchema);
70023
+ var EllipseShapeOutputSchema = z23.object({
70024
+ type: z23.literal("ELLIPSE"),
70025
+ center: PointSchema2,
70026
+ radiusX: z23.number(),
70027
+ radiusY: z23.number(),
70028
+ color: z23.string(),
70029
+ lineWidth: z23.number(),
70030
+ id: z23.string()
70031
+ });
70032
+ var parseEllipse = (str) => {
70033
+ const [, x, y, radiusX, radiusY, color, lineWidth, , , id] = str.split("~");
70034
+ return {
70035
+ type: "ELLIPSE",
70036
+ center: { x: Number(x), y: Number(y) },
70037
+ radiusX: Number(radiusX),
70038
+ radiusY: Number(radiusY),
70039
+ color,
70040
+ lineWidth: Number(lineWidth),
70041
+ id
70042
+ };
70043
+ };
70044
+ var EllipseShapeSchema = z23.string().startsWith("E~").transform(parseEllipse).pipe(EllipseShapeOutputSchema);
70045
+ var PinShapeOutputSchema = z23.object({
70046
+ type: z23.literal("PIN"),
70047
+ visibility: z23.enum(["show", "hide"]),
70048
+ pinNumber: z23.union([z23.string(), z23.number()]),
70049
+ x: z23.number(),
70050
+ y: z23.number(),
70051
+ rotation: z23.number(),
70052
+ id: z23.string(),
70053
+ label: z23.string(),
70054
+ labelColor: z23.string(),
70055
+ path: z23.string(),
70056
+ arrow: z23.string()
70057
+ });
70058
+ var parsePin = (pinString) => {
70059
+ const parts = pinString.split("~");
70060
+ const [, visibility, , pinNumber, x, y, rotation2, id] = parts;
70061
+ const nameMatch = pinString.match(/~(\w+)~(start|end)~/);
70062
+ const label = nameMatch ? nameMatch[1] : "";
70063
+ const colorMatch = pinString.match(/#[0-9A-F]{6}/);
70064
+ const labelColor = colorMatch ? colorMatch[0] : "";
70065
+ const pathMatch = pinString.match(/\^\^([^~]+)/);
70066
+ const path23 = pathMatch ? pathMatch[1] : "";
70067
+ const arrowMatch = pinString.match(/\^\^0~(.+)$/);
70068
+ const arrow = arrowMatch ? arrowMatch[1] : "";
70069
+ return {
70070
+ type: "PIN",
70071
+ visibility,
70072
+ id,
70073
+ pinNumber: isNaN(Number(pinNumber)) ? pinNumber : Number(pinNumber),
70074
+ x: parseFloat(x),
70075
+ y: parseFloat(y),
70076
+ rotation: parseFloat(rotation2),
70077
+ label,
70078
+ labelColor,
70079
+ path: path23,
70080
+ arrow
70081
+ };
70082
+ };
70083
+ var PinShapeSchema = z23.string().startsWith("P~").transform(parsePin).pipe(PinShapeOutputSchema);
70084
+ var PolylineShapeOutputSchema = z23.object({
70085
+ type: z23.literal("POLYLINE"),
70086
+ points: z23.array(PointSchema2),
70087
+ color: z23.string(),
70088
+ lineWidth: z23.number(),
70089
+ id: z23.string()
70090
+ });
70091
+ var parsePoints2 = (pointsStr) => {
70092
+ return pointsStr.split(" ").reduce((acc, value, index) => {
70093
+ if (index % 2 === 0) {
70094
+ acc.push({ x: Number(value), y: 0 });
70095
+ } else {
70096
+ acc[acc.length - 1].y = Number(value);
70097
+ }
70098
+ return acc;
70099
+ }, []);
70100
+ };
70101
+ var parsePolyline = (str) => {
70102
+ const [, ...rest] = str.split("~");
70103
+ const [pointsStr, color, lineWidth, , , id] = rest;
70104
+ return {
70105
+ type: "POLYLINE",
70106
+ points: parsePoints2(pointsStr),
70107
+ color,
70108
+ lineWidth: Number(lineWidth),
70109
+ id
70110
+ };
70111
+ };
70112
+ var PolylineShapeSchema = z23.string().startsWith("PL~").transform(parsePolyline).pipe(PolylineShapeOutputSchema);
70113
+ var PolygonShapeOutputSchema = z23.object({
70114
+ type: z23.literal("POLYGON"),
70115
+ points: z23.array(PointSchema2),
70116
+ fillColor: z23.string(),
70117
+ lineWidth: z23.number(),
70118
+ lineColor: z23.string(),
70119
+ id: z23.string()
70120
+ });
70121
+ var parsePolygon = (str) => {
70122
+ const [, ...rest] = str.split("~");
70123
+ const [pointsStr, fillColor, lineWidth, lineColor, , id] = rest;
70124
+ return {
70125
+ type: "POLYGON",
70126
+ points: parsePoints2(pointsStr),
70127
+ fillColor,
70128
+ lineWidth: Number(lineWidth),
70129
+ lineColor,
70130
+ id
70131
+ };
70132
+ };
70133
+ var PolygonShapeSchema = z23.string().startsWith("PG~").transform(parsePolygon).pipe(PolygonShapeOutputSchema);
70134
+ var PathShapeOutputSchema = z23.object({
70135
+ type: z23.literal("PATH"),
70136
+ pathData: z23.string(),
70137
+ fillColor: z23.string(),
70138
+ strokeWidth: z23.number(),
70139
+ strokeColor: z23.string(),
70140
+ id: z23.string()
70141
+ });
70142
+ var parsePath = (str) => {
70143
+ const [, pathData, fillColor, strokeWidth, strokeColor, , id] = str.split("~");
70144
+ return {
70145
+ type: "PATH",
70146
+ pathData,
70147
+ fillColor,
70148
+ strokeWidth: mil10ToMm(Number(strokeWidth)),
70149
+ strokeColor,
70150
+ id
70151
+ };
70152
+ };
70153
+ var PathShapeSchema = z23.string().startsWith("PT~").transform(parsePath).pipe(PathShapeOutputSchema);
70154
+ var TextShapeOutputSchema = z23.object({
70155
+ type: z23.literal("TEXT"),
70156
+ alignment: z23.enum(["L", "C", "R"]),
70157
+ x: z23.number(),
70158
+ y: z23.number(),
70159
+ rotation: z23.number(),
70160
+ fontColor: z23.string(),
70161
+ backgroundColor: z23.string().optional(),
70162
+ fontSize: z23.string(),
70163
+ fontWeight: z23.enum(["normal", "bold"]).optional().default("normal"),
70164
+ fontStyle: z23.enum(["normal", "italic"]).optional().default("normal"),
70165
+ fontDecoration: z23.enum(["", "underline"]),
70166
+ content: z23.string(),
70167
+ textType: z23.string(),
70168
+ visibility: z23.enum(["0", "1"]),
70169
+ mirror: z23.string(),
70170
+ id: z23.string()
70171
+ });
70172
+ var parseText = (str) => {
70173
+ const [
70174
+ ,
70175
+ alignment,
70176
+ x,
70177
+ y,
70178
+ rotation2,
70179
+ fontColor,
70180
+ backgroundColor,
70181
+ fontSize,
70182
+ fontWeight,
70183
+ fontStyle,
70184
+ fontDecoration,
70185
+ content,
70186
+ textType,
70187
+ visibility,
70188
+ mirror,
70189
+ id
70190
+ ] = str.split("~");
70191
+ return {
70192
+ type: "TEXT",
70193
+ alignment,
70194
+ x: Number(x),
70195
+ y: Number(y),
70196
+ rotation: Number(rotation2),
70197
+ fontColor,
70198
+ backgroundColor: backgroundColor || undefined,
70199
+ fontSize,
70200
+ fontWeight: fontWeight || "normal",
70201
+ fontStyle: fontStyle || "normal",
70202
+ fontDecoration,
70203
+ content,
70204
+ textType,
70205
+ visibility,
70206
+ mirror,
70207
+ id
70208
+ };
70209
+ };
70210
+ var TextShapeSchema = z23.string().startsWith("T~").transform(parseText).pipe(TextShapeOutputSchema);
70211
+ var SingleLetterShapeSchema = z23.string().transform((x) => {
70212
+ if (x.startsWith("R~"))
70213
+ return RectangleShapeSchema.parse(x);
70214
+ if (x.startsWith("E~"))
70215
+ return EllipseShapeSchema.parse(x);
70216
+ if (x.startsWith("P~"))
70217
+ return PinShapeSchema.parse(x);
70218
+ if (x.startsWith("PL~"))
70219
+ return PolylineShapeSchema.parse(x);
70220
+ if (x.startsWith("PG~"))
70221
+ return PolygonShapeSchema.parse(x);
70222
+ if (x.startsWith("PT~"))
70223
+ return PathShapeSchema.parse(x);
70224
+ if (x.startsWith("T~"))
70225
+ return TextShapeSchema.parse(x);
70226
+ throw new Error(`Invalid shape type: ${x}`);
70227
+ }).pipe(z23.union([
70228
+ RectangleShapeOutputSchema,
70229
+ EllipseShapeOutputSchema,
70230
+ PinShapeOutputSchema,
70231
+ PolylineShapeOutputSchema,
70232
+ PolygonShapeOutputSchema,
70233
+ PathShapeOutputSchema,
70234
+ TextShapeOutputSchema
70235
+ ]));
70236
+ var maybeNumber = z33.any().transform((k) => k === "nan" || Number.isNaN(k) ? null : k).pipe(z33.number().nullable().optional());
70237
+ var SzlcscSchema = z33.object({
70238
+ id: z33.number(),
70239
+ number: z33.string(),
70240
+ step: z33.number().optional(),
70241
+ min: z33.number().optional(),
70242
+ price: z33.number().optional(),
70243
+ stock: z33.number().optional(),
70244
+ url: z33.string().url().optional(),
70245
+ image: z33.string().optional().optional()
70246
+ });
70247
+ var LcscSchema = z33.object({
70248
+ id: z33.number(),
70249
+ number: z33.string(),
70250
+ step: z33.number().optional(),
70251
+ min: z33.number().optional(),
70252
+ price: z33.number().optional(),
70253
+ stock: z33.number().optional(),
70254
+ url: z33.string().url().optional()
70255
+ });
70256
+ var OwnerSchema = z33.object({
70257
+ uuid: z33.string(),
70258
+ username: z33.string(),
70259
+ nickname: z33.string(),
70260
+ avatar: z33.string()
70261
+ });
70262
+ var HeadSchema = z33.object({
70263
+ docType: z33.string(),
70264
+ editorVersion: z33.string(),
70265
+ c_para: z33.record(z33.string(), z33.string()),
70266
+ x: z33.number(),
70267
+ y: z33.number(),
70268
+ puuid: z33.string().optional(),
70269
+ uuid: z33.string(),
70270
+ utime: z33.number(),
70271
+ importFlag: z33.number().optional(),
70272
+ c_spiceCmd: z33.any().optional(),
70273
+ hasIdFlag: z33.boolean()
70274
+ });
70275
+ var BBoxSchema = z33.object({
70276
+ x: z33.number(),
70277
+ y: z33.number(),
70278
+ width: z33.number(),
70279
+ height: z33.number()
70280
+ });
70281
+ var LayerItemSchema = z33.object({
70282
+ name: z33.string(),
70283
+ color: z33.string(),
70284
+ visible: z33.boolean(),
70285
+ active: z33.boolean(),
70286
+ config: z33.boolean(),
70287
+ transparency: z33.boolean()
70288
+ });
70289
+ var ObjectItemSchema = z33.object({
70290
+ name: z33.string(),
70291
+ visible: z33.boolean(),
70292
+ locked: z33.boolean()
70293
+ });
70294
+ var DataStrSchema = z33.object({
70295
+ head: HeadSchema,
70296
+ canvas: z33.string(),
70297
+ shape: z33.array(SingleLetterShapeSchema),
70298
+ BBox: BBoxSchema,
70299
+ colors: z33.array(z33.unknown())
70300
+ });
70301
+ var PackageDetailDataStrSchema = z33.object({
70302
+ head: HeadSchema,
70303
+ canvas: z33.string(),
70304
+ shape: z33.array(z33.string()).transform((shapes) => shapes.map((shape) => {
70305
+ const [type, ...data] = shape.split("~");
70306
+ return ShapeItemSchema.parse({ type, data: data.join("~") });
70307
+ })).pipe(z33.array(PackageDetailShapeSchema)),
70308
+ layers: z33.array(z33.string()).transform((layers) => layers.map((layer) => {
70309
+ const [name, color, visible, active, config, transparency] = layer.split("~");
70310
+ return LayerItemSchema.parse({
70311
+ name,
70312
+ color,
70313
+ visible: visible === "true",
70314
+ active: active === "true",
70315
+ config: config === "true",
70316
+ transparency: transparency === "true"
69601
70317
  });
69602
- if (!selectedPackage) {
69603
- console.log(kleur_default.yellow("No package selected."));
70318
+ })),
70319
+ objects: z33.array(z33.string()).transform((objects) => objects.map((obj) => {
70320
+ const [name, visible, locked] = obj.split("~");
70321
+ return ObjectItemSchema.parse({
70322
+ name,
70323
+ visible: visible === "true",
70324
+ locked: locked === "true"
70325
+ });
70326
+ })),
70327
+ BBox: BBoxSchema,
70328
+ netColors: z33.array(z33.unknown()).optional()
70329
+ });
70330
+ var PackageDetailSchema = z33.object({
70331
+ uuid: z33.string(),
70332
+ title: z33.string(),
70333
+ docType: z33.number(),
70334
+ updateTime: z33.number(),
70335
+ owner: OwnerSchema,
70336
+ datastrid: z33.string(),
70337
+ writable: z33.boolean(),
70338
+ dataStr: PackageDetailDataStrSchema
70339
+ });
70340
+ var EasyEdaJsonSchema = z33.object({
70341
+ uuid: z33.string(),
70342
+ title: z33.string(),
70343
+ description: z33.string(),
70344
+ docType: z33.number(),
70345
+ type: z33.number(),
70346
+ szlcsc: SzlcscSchema,
70347
+ lcsc: LcscSchema,
70348
+ owner: OwnerSchema,
70349
+ tags: z33.array(z33.string()),
70350
+ updateTime: z33.number(),
70351
+ updated_at: z33.string(),
70352
+ dataStr: DataStrSchema,
70353
+ verify: z33.boolean(),
70354
+ SMT: z33.boolean().optional(),
70355
+ datastrid: z33.string(),
70356
+ jlcOnSale: z33.number().optional(),
70357
+ writable: z33.boolean(),
70358
+ isFavorite: z33.boolean(),
70359
+ packageDetail: PackageDetailSchema
70360
+ });
70361
+ var dist_exports = {};
70362
+ __export2(dist_exports, {
70363
+ all_layers: () => all_layers,
70364
+ any_circuit_element: () => any_circuit_element,
70365
+ any_soup_element: () => any_soup_element2,
70366
+ any_source_component: () => any_source_component,
70367
+ battery_capacity: () => battery_capacity,
70368
+ cad_component: () => cad_component,
70369
+ capacitance: () => capacitance,
70370
+ current: () => current,
70371
+ distance: () => distance,
70372
+ frequency: () => frequency,
70373
+ getZodPrefixedIdWithDefault: () => getZodPrefixedIdWithDefault,
70374
+ inductance: () => inductance,
70375
+ layer_ref: () => layer_ref,
70376
+ layer_string: () => layer_string,
70377
+ length: () => length,
70378
+ pcb_autorouting_error: () => pcb_autorouting_error,
70379
+ pcb_board: () => pcb_board,
70380
+ pcb_component: () => pcb_component,
70381
+ pcb_fabrication_note_path: () => pcb_fabrication_note_path,
70382
+ pcb_fabrication_note_text: () => pcb_fabrication_note_text,
70383
+ pcb_group: () => pcb_group,
70384
+ pcb_hole: () => pcb_hole,
70385
+ pcb_hole_circle_or_square_shape: () => pcb_hole_circle_or_square_shape,
70386
+ pcb_hole_oval_shape: () => pcb_hole_oval_shape,
70387
+ pcb_keepout: () => pcb_keepout,
70388
+ pcb_manual_edit_conflict_error: () => pcb_manual_edit_conflict_error,
70389
+ pcb_missing_footprint_error: () => pcb_missing_footprint_error,
70390
+ pcb_placement_error: () => pcb_placement_error,
70391
+ pcb_plated_hole: () => pcb_plated_hole,
70392
+ pcb_port: () => pcb_port,
70393
+ pcb_port_not_matched_error: () => pcb_port_not_matched_error,
70394
+ pcb_route_hint: () => pcb_route_hint,
70395
+ pcb_route_hints: () => pcb_route_hints,
70396
+ pcb_silkscreen_circle: () => pcb_silkscreen_circle,
70397
+ pcb_silkscreen_line: () => pcb_silkscreen_line,
70398
+ pcb_silkscreen_oval: () => pcb_silkscreen_oval,
70399
+ pcb_silkscreen_path: () => pcb_silkscreen_path,
70400
+ pcb_silkscreen_rect: () => pcb_silkscreen_rect,
70401
+ pcb_silkscreen_text: () => pcb_silkscreen_text,
70402
+ pcb_smtpad: () => pcb_smtpad,
70403
+ pcb_smtpad_pill: () => pcb_smtpad_pill,
70404
+ pcb_solder_paste: () => pcb_solder_paste,
70405
+ pcb_text: () => pcb_text,
70406
+ pcb_trace: () => pcb_trace,
70407
+ pcb_trace_error: () => pcb_trace_error,
70408
+ pcb_trace_hint: () => pcb_trace_hint,
70409
+ pcb_trace_route_point: () => pcb_trace_route_point,
70410
+ pcb_trace_route_point_via: () => pcb_trace_route_point_via,
70411
+ pcb_trace_route_point_wire: () => pcb_trace_route_point_wire,
70412
+ pcb_via: () => pcb_via,
70413
+ point: () => point,
70414
+ point3: () => point3,
70415
+ port_arrangement: () => port_arrangement,
70416
+ position: () => position,
70417
+ position3: () => position3,
70418
+ resistance: () => resistance,
70419
+ rotation: () => rotation,
70420
+ route_hint_point: () => route_hint_point,
70421
+ schematic_box: () => schematic_box,
70422
+ schematic_component: () => schematic_component,
70423
+ schematic_component_port_arrangement_by_sides: () => schematic_component_port_arrangement_by_sides,
70424
+ schematic_component_port_arrangement_by_size: () => schematic_component_port_arrangement_by_size,
70425
+ schematic_debug_line: () => schematic_debug_line,
70426
+ schematic_debug_object: () => schematic_debug_object,
70427
+ schematic_debug_object_base: () => schematic_debug_object_base,
70428
+ schematic_debug_point: () => schematic_debug_point,
70429
+ schematic_debug_rect: () => schematic_debug_rect,
70430
+ schematic_error: () => schematic_error,
70431
+ schematic_line: () => schematic_line,
70432
+ schematic_net_label: () => schematic_net_label,
70433
+ schematic_path: () => schematic_path,
70434
+ schematic_pin_styles: () => schematic_pin_styles,
70435
+ schematic_port: () => schematic_port,
70436
+ schematic_text: () => schematic_text,
70437
+ schematic_trace: () => schematic_trace,
70438
+ schematic_voltage_probe: () => schematic_voltage_probe,
70439
+ size: () => size,
70440
+ source_component_base: () => source_component_base,
70441
+ source_group: () => source_group,
70442
+ source_led: () => source_led,
70443
+ source_net: () => source_net,
70444
+ source_port: () => source_port,
70445
+ source_project_metadata: () => source_project_metadata,
70446
+ source_simple_battery: () => source_simple_battery,
70447
+ source_simple_bug: () => source_simple_bug,
70448
+ source_simple_capacitor: () => source_simple_capacitor,
70449
+ source_simple_chip: () => source_simple_chip,
70450
+ source_simple_crystal: () => source_simple_crystal,
70451
+ source_simple_diode: () => source_simple_diode,
70452
+ source_simple_ground: () => source_simple_ground,
70453
+ source_simple_inductor: () => source_simple_inductor,
70454
+ source_simple_mosfet: () => source_simple_mosfet,
70455
+ source_simple_pin_header: () => source_simple_pin_header,
70456
+ source_simple_potentiometer: () => source_simple_potentiometer,
70457
+ source_simple_power_source: () => source_simple_power_source,
70458
+ source_simple_push_button: () => source_simple_push_button,
70459
+ source_simple_resistor: () => source_simple_resistor,
70460
+ source_simple_resonator: () => source_simple_resonator,
70461
+ source_simple_switch: () => source_simple_switch,
70462
+ source_simple_transistor: () => source_simple_transistor,
70463
+ source_trace: () => source_trace,
70464
+ supplier_name: () => supplier_name,
70465
+ time: () => time,
70466
+ visible_layer: () => visible_layer,
70467
+ voltage: () => voltage
70468
+ });
70469
+ var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
70470
+ var nanoid = (size2 = 21) => {
70471
+ let id = "";
70472
+ let bytes = crypto.getRandomValues(new Uint8Array(size2));
70473
+ while (size2--) {
70474
+ id += urlAlphabet[bytes[size2] & 63];
70475
+ }
70476
+ return id;
70477
+ };
70478
+ var unitMappings = {
70479
+ Hz: {
70480
+ baseUnit: "Hz",
70481
+ variants: {
70482
+ MHz: 1e6,
70483
+ kHz: 1000,
70484
+ Hz: 1
70485
+ }
70486
+ },
70487
+ g: {
70488
+ baseUnit: "g",
70489
+ variants: {
70490
+ kg: 1000,
70491
+ g: 1
70492
+ }
70493
+ },
70494
+ Ω: {
70495
+ baseUnit: "Ω",
70496
+ variants: {
70497
+ mΩ: 0.001,
70498
+ Ω: 1,
70499
+ kΩ: 1000,
70500
+ KΩ: 1000,
70501
+ kohm: 1000,
70502
+ MΩ: 1e6,
70503
+ GΩ: 1e9,
70504
+ TΩ: 1000000000000
70505
+ }
70506
+ },
70507
+ V: {
70508
+ baseUnit: "V",
70509
+ variants: {
70510
+ mV: 0.001,
70511
+ V: 1,
70512
+ kV: 1000,
70513
+ KV: 1000,
70514
+ MV: 1e6,
70515
+ GV: 1e9,
70516
+ TV: 1000000000000
70517
+ }
70518
+ },
70519
+ A: {
70520
+ baseUnit: "A",
70521
+ variants: {
70522
+ µA: 0.000001,
70523
+ mA: 0.001,
70524
+ ma: 0.001,
70525
+ A: 1,
70526
+ kA: 1000,
70527
+ MA: 1e6
70528
+ }
70529
+ },
70530
+ F: {
70531
+ baseUnit: "F",
70532
+ variants: {
70533
+ pF: 0.000000000001,
70534
+ nF: 0.000000001,
70535
+ µF: 0.000001,
70536
+ uF: 0.000001,
70537
+ mF: 0.001,
70538
+ F: 1
70539
+ }
70540
+ },
70541
+ ml: {
70542
+ baseUnit: "ml",
70543
+ variants: {
70544
+ ml: 1,
70545
+ mL: 1,
70546
+ l: 1000,
70547
+ L: 1000
70548
+ }
70549
+ },
70550
+ deg: {
70551
+ baseUnit: "deg",
70552
+ variants: {
70553
+ rad: 180 / Math.PI
70554
+ }
70555
+ },
70556
+ ms: {
70557
+ baseUnit: "ms",
70558
+ variants: {
70559
+ s: 1000
70560
+ }
70561
+ },
70562
+ mm: {
70563
+ baseUnit: "mm",
70564
+ variants: {
70565
+ nm: 0.000001,
70566
+ µm: 0.001,
70567
+ um: 0.001,
70568
+ mm: 1,
70569
+ cm: 10,
70570
+ dm: 100,
70571
+ m: 1000,
70572
+ km: 1e6,
70573
+ in: 25.4,
70574
+ ft: 304.8,
70575
+ IN: 25.4,
70576
+ FT: 304.8,
70577
+ yd: 914.4,
70578
+ mi: 1609344,
70579
+ mil: 0.0254
70580
+ }
70581
+ }
70582
+ };
70583
+ var unitMappingAndVariantSuffixes = /* @__PURE__ */ new Set;
70584
+ for (const [baseUnit, info] of Object.entries(unitMappings)) {
70585
+ unitMappingAndVariantSuffixes.add(baseUnit);
70586
+ for (const variant of Object.keys(info.variants)) {
70587
+ unitMappingAndVariantSuffixes.add(variant);
70588
+ }
70589
+ }
70590
+ function getBaseTscircuitUnit(unit) {
70591
+ for (const [baseUnit, info] of Object.entries(unitMappings)) {
70592
+ if (unit in info.variants) {
70593
+ return {
70594
+ baseUnit: info.baseUnit,
70595
+ conversionFactor: info.variants[unit]
70596
+ };
70597
+ }
70598
+ }
70599
+ return {
70600
+ baseUnit: unit,
70601
+ conversionFactor: 1
70602
+ };
70603
+ }
70604
+ var si_prefix_multiplier = {
70605
+ tera: 1000000000000,
70606
+ T: 1000000000000,
70607
+ giga: 1e9,
70608
+ G: 1e9,
70609
+ mega: 1e6,
70610
+ M: 1e6,
70611
+ kilo: 1000,
70612
+ k: 1000,
70613
+ deci: 0.1,
70614
+ d: 0.1,
70615
+ centi: 0.01,
70616
+ c: 0.01,
70617
+ milli: 0.001,
70618
+ m: 0.001,
70619
+ micro: 0.000001,
70620
+ u: 0.000001,
70621
+ µ: 0.000001,
70622
+ nano: 0.000000001,
70623
+ n: 0.000000001,
70624
+ pico: 0.000000000001,
70625
+ p: 0.000000000001
70626
+ };
70627
+ var parseAndConvertSiUnit = (v) => {
70628
+ if (typeof v === "undefined")
70629
+ return { parsedUnit: null, unitOfValue: null, value: null };
70630
+ if (typeof v === "string" && v.match(/^-?[\d\.]+$/))
70631
+ return {
70632
+ value: Number.parseFloat(v),
70633
+ parsedUnit: null,
70634
+ unitOfValue: null
70635
+ };
70636
+ if (typeof v === "number")
70637
+ return { value: v, parsedUnit: null, unitOfValue: null };
70638
+ if (typeof v === "object" && "x" in v && "y" in v) {
70639
+ const { parsedUnit, unitOfValue } = parseAndConvertSiUnit(v.x);
70640
+ return {
70641
+ parsedUnit,
70642
+ unitOfValue,
70643
+ value: {
70644
+ x: parseAndConvertSiUnit(v.x).value,
70645
+ y: parseAndConvertSiUnit(v.y).value
70646
+ }
70647
+ };
70648
+ }
70649
+ const reversed_input_string = v.toString().split("").reverse().join("");
70650
+ const unit_reversed = reversed_input_string.match(/[^\d\s]+/)?.[0];
70651
+ if (!unit_reversed) {
70652
+ throw new Error(`Could not determine unit: "${v}"`);
70653
+ }
70654
+ const unit = unit_reversed.split("").reverse().join("");
70655
+ const numberPart = v.slice(0, -unit.length);
70656
+ if (unit in si_prefix_multiplier && !unitMappingAndVariantSuffixes.has(unit)) {
70657
+ const siMultiplier = si_prefix_multiplier[unit];
70658
+ return {
70659
+ parsedUnit: null,
70660
+ unitOfValue: null,
70661
+ value: Number.parseFloat(numberPart) * siMultiplier
70662
+ };
70663
+ }
70664
+ const { baseUnit, conversionFactor } = getBaseTscircuitUnit(unit);
70665
+ return {
70666
+ parsedUnit: unit,
70667
+ unitOfValue: baseUnit,
70668
+ value: conversionFactor * Number.parseFloat(numberPart)
70669
+ };
70670
+ };
70671
+ var resistance = z43.string().or(z43.number()).transform((v) => parseAndConvertSiUnit(v).value);
70672
+ var capacitance = z43.string().or(z43.number()).transform((v) => parseAndConvertSiUnit(v).value).transform((value) => {
70673
+ return Number.parseFloat(value.toPrecision(12));
70674
+ });
70675
+ var inductance = z43.string().or(z43.number()).transform((v) => parseAndConvertSiUnit(v).value);
70676
+ var voltage = z43.string().or(z43.number()).transform((v) => parseAndConvertSiUnit(v).value);
70677
+ var length = z43.string().or(z43.number()).transform((v) => parseAndConvertSiUnit(v).value);
70678
+ var frequency = z43.string().or(z43.number()).transform((v) => parseAndConvertSiUnit(v).value);
70679
+ var distance = length;
70680
+ var current = z43.string().or(z43.number()).transform((v) => parseAndConvertSiUnit(v).value);
70681
+ var time = z43.string().or(z43.number()).transform((v) => parseAndConvertSiUnit(v).value);
70682
+ var rotation = z43.string().or(z43.number()).transform((arg) => {
70683
+ if (typeof arg === "number")
70684
+ return arg;
70685
+ if (arg.endsWith("deg")) {
70686
+ return Number.parseFloat(arg.split("deg")[0]);
70687
+ }
70688
+ if (arg.endsWith("rad")) {
70689
+ return Number.parseFloat(arg.split("rad")[0]) * 180 / Math.PI;
70690
+ }
70691
+ return Number.parseFloat(arg);
70692
+ });
70693
+ var battery_capacity = z43.number().or(z43.string().endsWith("mAh")).transform((v) => {
70694
+ if (typeof v === "string") {
70695
+ const valString = v.replace("mAh", "");
70696
+ const num = Number.parseFloat(valString);
70697
+ if (Number.isNaN(num)) {
70698
+ throw new Error("Invalid capacity");
70699
+ }
70700
+ return num;
70701
+ }
70702
+ return v;
70703
+ }).describe("Battery capacity in mAh");
70704
+ var point = z222.object({
70705
+ x: distance,
70706
+ y: distance
70707
+ });
70708
+ var position = point;
70709
+ var point3 = z322.object({
70710
+ x: distance,
70711
+ y: distance,
70712
+ z: distance
70713
+ });
70714
+ var position3 = point3;
70715
+ var size = z422.object({
70716
+ width: z422.number(),
70717
+ height: z422.number()
70718
+ });
70719
+ var getZodPrefixedIdWithDefault = (prefix) => {
70720
+ return z53.string().optional().default(() => `${prefix}_${nanoid(10)}`);
70721
+ };
70722
+ var supplier_name = z62.enum([
70723
+ "jlcpcb",
70724
+ "macrofab",
70725
+ "pcbway",
70726
+ "digikey",
70727
+ "mouser",
70728
+ "lcsc"
70729
+ ]);
70730
+ var expectTypesMatch = (shouldBe) => {};
70731
+ expectTypesMatch("extra props b");
70732
+ expectTypesMatch("missing props b");
70733
+ expectTypesMatch(true);
70734
+ expectTypesMatch("mismatched prop types: a");
70735
+ var source_component_base = z72.object({
70736
+ type: z72.literal("source_component"),
70737
+ ftype: z72.string().optional(),
70738
+ source_component_id: z72.string(),
70739
+ name: z72.string(),
70740
+ manufacturer_part_number: z72.string().optional(),
70741
+ supplier_part_numbers: z72.record(supplier_name, z72.array(z72.string())).optional(),
70742
+ display_value: z72.string().optional()
70743
+ });
70744
+ expectTypesMatch(true);
70745
+ var source_simple_capacitor = source_component_base.extend({
70746
+ ftype: z82.literal("simple_capacitor"),
70747
+ capacitance,
70748
+ max_voltage_rating: voltage.optional(),
70749
+ display_capacitance: z82.string().optional(),
70750
+ max_decoupling_trace_length: distance.optional()
70751
+ });
70752
+ expectTypesMatch(true);
70753
+ var source_simple_resistor = source_component_base.extend({
70754
+ ftype: z92.literal("simple_resistor"),
70755
+ resistance,
70756
+ display_resistance: z92.string().optional()
70757
+ });
70758
+ expectTypesMatch(true);
70759
+ var source_simple_diode = source_component_base.extend({
70760
+ ftype: z102.literal("simple_diode")
70761
+ });
70762
+ expectTypesMatch(true);
70763
+ var source_simple_ground = source_component_base.extend({
70764
+ ftype: z112.literal("simple_ground")
70765
+ });
70766
+ expectTypesMatch(true);
70767
+ var source_simple_bug = source_component_base.extend({
70768
+ ftype: z122.literal("simple_bug")
70769
+ }).describe("@deprecated");
70770
+ var source_simple_chip = source_component_base.extend({
70771
+ ftype: z132.literal("simple_chip")
70772
+ });
70773
+ expectTypesMatch(true);
70774
+ var source_led = source_simple_diode.extend({
70775
+ ftype: z142.literal("led")
70776
+ });
70777
+ expectTypesMatch(true);
70778
+ var source_simple_power_source = source_component_base.extend({
70779
+ ftype: z152.literal("simple_power_source"),
70780
+ voltage
70781
+ });
70782
+ expectTypesMatch(true);
70783
+ var source_simple_battery = source_component_base.extend({
70784
+ ftype: z162.literal("simple_battery"),
70785
+ capacity: battery_capacity
70786
+ });
70787
+ expectTypesMatch(true);
70788
+ var source_simple_inductor = source_component_base.extend({
70789
+ ftype: z172.literal("simple_inductor"),
70790
+ inductance
70791
+ });
70792
+ expectTypesMatch(true);
70793
+ var source_simple_push_button = source_component_base.extend({
70794
+ ftype: z182.literal("simple_push_button")
70795
+ });
70796
+ expectTypesMatch(true);
70797
+ var source_simple_potentiometer = source_component_base.extend({
70798
+ ftype: z192.literal("simple_potentiometer"),
70799
+ max_resistance: resistance
70800
+ });
70801
+ var source_simple_crystal = source_component_base.extend({
70802
+ ftype: z202.literal("simple_crystal"),
70803
+ frequency: z202.number().describe("Frequency in Hz"),
70804
+ load_capacitance: z202.number().optional().describe("Load capacitance in pF")
70805
+ });
70806
+ expectTypesMatch(true);
70807
+ var source_simple_pin_header = source_component_base.extend({
70808
+ ftype: z21.literal("simple_pin_header"),
70809
+ pin_count: z21.number(),
70810
+ gender: z21.enum(["male", "female"]).optional().default("male")
70811
+ });
70812
+ var source_simple_resonator = source_component_base.extend({
70813
+ ftype: z2222.literal("simple_resonator"),
70814
+ load_capacitance: capacitance,
70815
+ equivalent_series_resistance: resistance.optional(),
70816
+ frequency
70817
+ });
70818
+ expectTypesMatch(true);
70819
+ var source_simple_transistor = source_component_base.extend({
70820
+ ftype: z232.literal("simple_transistor"),
70821
+ transistor_type: z232.enum(["npn", "pnp"])
70822
+ });
70823
+ expectTypesMatch(true);
70824
+ var source_simple_mosfet = source_component_base.extend({
70825
+ ftype: z24.literal("simple_mosfet"),
70826
+ channel_type: z24.enum(["n", "p"]),
70827
+ mosfet_mode: z24.enum(["enhancement", "depletion"])
70828
+ });
70829
+ expectTypesMatch(true);
70830
+ var source_simple_switch = source_component_base.extend({
70831
+ ftype: z25.literal("simple_switch")
70832
+ });
70833
+ expectTypesMatch(true);
70834
+ var source_project_metadata = z26.object({
70835
+ type: z26.literal("source_project_metadata"),
70836
+ name: z26.string().optional(),
70837
+ software_used_string: z26.string().optional(),
70838
+ created_at: z26.string().datetime().optional()
70839
+ });
70840
+ expectTypesMatch(true);
70841
+ var any_source_component = z27.union([
70842
+ source_simple_resistor,
70843
+ source_simple_capacitor,
70844
+ source_simple_diode,
70845
+ source_simple_ground,
70846
+ source_simple_chip,
70847
+ source_simple_bug,
70848
+ source_led,
70849
+ source_simple_power_source,
70850
+ source_simple_battery,
70851
+ source_simple_inductor,
70852
+ source_simple_push_button,
70853
+ source_simple_potentiometer,
70854
+ source_simple_crystal,
70855
+ source_simple_pin_header,
70856
+ source_simple_resonator,
70857
+ source_simple_switch,
70858
+ source_simple_transistor,
70859
+ source_simple_mosfet,
70860
+ source_project_metadata
70861
+ ]);
70862
+ var source_port = z28.object({
70863
+ type: z28.literal("source_port"),
70864
+ pin_number: z28.number().optional(),
70865
+ port_hints: z28.array(z28.string()).optional(),
70866
+ name: z28.string(),
70867
+ source_port_id: z28.string(),
70868
+ source_component_id: z28.string(),
70869
+ subcircuit_id: z28.string().optional()
70870
+ });
70871
+ expectTypesMatch(true);
70872
+ var source_trace = z29.object({
70873
+ type: z29.literal("source_trace"),
70874
+ source_trace_id: z29.string(),
70875
+ connected_source_port_ids: z29.array(z29.string()),
70876
+ connected_source_net_ids: z29.array(z29.string()),
70877
+ subcircuit_id: z29.string().optional(),
70878
+ subcircuit_connectivity_map_key: z29.string().optional(),
70879
+ max_length: z29.number().optional(),
70880
+ min_trace_thickness: z29.number().optional(),
70881
+ display_name: z29.string().optional()
70882
+ });
70883
+ expectTypesMatch(true);
70884
+ var source_group = z30.object({
70885
+ type: z30.literal("source_group"),
70886
+ source_group_id: z30.string(),
70887
+ subcircuit_id: z30.string().optional(),
70888
+ parent_subcircuit_id: z30.string().optional(),
70889
+ is_subcircuit: z30.boolean().optional(),
70890
+ name: z30.string().optional()
70891
+ });
70892
+ var source_net = z31.object({
70893
+ type: z31.literal("source_net"),
70894
+ source_net_id: z31.string(),
70895
+ name: z31.string(),
70896
+ member_source_group_ids: z31.array(z31.string()),
70897
+ is_power: z31.boolean().optional(),
70898
+ is_ground: z31.boolean().optional(),
70899
+ is_digital_signal: z31.boolean().optional(),
70900
+ is_analog_signal: z31.boolean().optional(),
70901
+ trace_width: z31.number().optional(),
70902
+ subcircuit_id: z31.string().optional()
70903
+ });
70904
+ var schematic_box = z3222.object({
70905
+ type: z3222.literal("schematic_box"),
70906
+ schematic_component_id: z3222.string(),
70907
+ width: distance,
70908
+ height: distance,
70909
+ x: distance,
70910
+ y: distance
70911
+ }).describe("Draws a box on the schematic");
70912
+ expectTypesMatch(true);
70913
+ var schematic_path = z332.object({
70914
+ type: z332.literal("schematic_path"),
70915
+ schematic_component_id: z332.string(),
70916
+ fill_color: z332.enum(["red", "blue"]).optional(),
70917
+ is_filled: z332.boolean().optional(),
70918
+ points: z332.array(point)
70919
+ });
70920
+ expectTypesMatch(true);
70921
+ var schematic_pin_styles = z34.record(z34.object({
70922
+ left_margin: length.optional(),
70923
+ right_margin: length.optional(),
70924
+ top_margin: length.optional(),
70925
+ bottom_margin: length.optional()
70926
+ }));
70927
+ var schematic_component_port_arrangement_by_size = z34.object({
70928
+ left_size: z34.number(),
70929
+ right_size: z34.number(),
70930
+ top_size: z34.number().optional(),
70931
+ bottom_size: z34.number().optional()
70932
+ });
70933
+ expectTypesMatch(true);
70934
+ var schematic_component_port_arrangement_by_sides = z34.object({
70935
+ left_side: z34.object({
70936
+ pins: z34.array(z34.number()),
70937
+ direction: z34.enum(["top-to-bottom", "bottom-to-top"]).optional()
70938
+ }).optional(),
70939
+ right_side: z34.object({
70940
+ pins: z34.array(z34.number()),
70941
+ direction: z34.enum(["top-to-bottom", "bottom-to-top"]).optional()
70942
+ }).optional(),
70943
+ top_side: z34.object({
70944
+ pins: z34.array(z34.number()),
70945
+ direction: z34.enum(["left-to-right", "right-to-left"]).optional()
70946
+ }).optional(),
70947
+ bottom_side: z34.object({
70948
+ pins: z34.array(z34.number()),
70949
+ direction: z34.enum(["left-to-right", "right-to-left"]).optional()
70950
+ }).optional()
70951
+ });
70952
+ expectTypesMatch(true);
70953
+ var port_arrangement = z34.union([
70954
+ schematic_component_port_arrangement_by_size,
70955
+ schematic_component_port_arrangement_by_sides
70956
+ ]);
70957
+ var schematic_component = z34.object({
70958
+ type: z34.literal("schematic_component"),
70959
+ size,
70960
+ center: point,
70961
+ source_component_id: z34.string(),
70962
+ schematic_component_id: z34.string(),
70963
+ pin_spacing: length.optional(),
70964
+ pin_styles: schematic_pin_styles.optional(),
70965
+ box_width: length.optional(),
70966
+ symbol_name: z34.string().optional(),
70967
+ port_arrangement: port_arrangement.optional(),
70968
+ port_labels: z34.record(z34.string()).optional(),
70969
+ symbol_display_value: z34.string().optional()
70970
+ });
70971
+ expectTypesMatch(true);
70972
+ var schematic_line = z35.object({
70973
+ type: z35.literal("schematic_line"),
70974
+ schematic_component_id: z35.string(),
70975
+ x1: distance,
70976
+ x2: distance,
70977
+ y1: distance,
70978
+ y2: distance
70979
+ });
70980
+ expectTypesMatch(true);
70981
+ var schematic_trace = z36.object({
70982
+ type: z36.literal("schematic_trace"),
70983
+ schematic_trace_id: z36.string(),
70984
+ source_trace_id: z36.string(),
70985
+ junctions: z36.array(z36.object({
70986
+ x: z36.number(),
70987
+ y: z36.number()
70988
+ })),
70989
+ edges: z36.array(z36.object({
70990
+ from: z36.object({
70991
+ x: z36.number(),
70992
+ y: z36.number()
70993
+ }),
70994
+ to: z36.object({
70995
+ x: z36.number(),
70996
+ y: z36.number()
70997
+ }),
70998
+ is_crossing: z36.boolean().optional(),
70999
+ from_schematic_port_id: z36.string().optional(),
71000
+ to_schematic_port_id: z36.string().optional()
71001
+ }))
71002
+ });
71003
+ expectTypesMatch(true);
71004
+ var schematic_text = z37.object({
71005
+ type: z37.literal("schematic_text"),
71006
+ schematic_component_id: z37.string(),
71007
+ schematic_text_id: z37.string(),
71008
+ text: z37.string(),
71009
+ position: z37.object({
71010
+ x: distance,
71011
+ y: distance
71012
+ }),
71013
+ rotation: z37.number().default(0),
71014
+ anchor: z37.enum(["center", "left", "right", "top", "bottom"]).default("center"),
71015
+ color: z37.string().default("#000000")
71016
+ });
71017
+ expectTypesMatch(true);
71018
+ var schematic_port = z38.object({
71019
+ type: z38.literal("schematic_port"),
71020
+ schematic_port_id: z38.string(),
71021
+ source_port_id: z38.string(),
71022
+ schematic_component_id: z38.string().optional(),
71023
+ center: point,
71024
+ facing_direction: z38.enum(["up", "down", "left", "right"]).optional(),
71025
+ distance_from_component_edge: z38.number().optional(),
71026
+ side_of_component: z38.enum(["top", "bottom", "left", "right"]).optional(),
71027
+ true_ccw_index: z38.number().optional(),
71028
+ pin_number: z38.number().optional(),
71029
+ display_pin_label: z38.string().optional()
71030
+ }).describe("Defines a port on a schematic component");
71031
+ expectTypesMatch(true);
71032
+ var schematic_net_label = z39.object({
71033
+ type: z39.literal("schematic_net_label"),
71034
+ source_net_id: z39.string(),
71035
+ center: point,
71036
+ anchor_position: point.optional(),
71037
+ anchor_side: z39.enum(["top", "bottom", "left", "right"]),
71038
+ text: z39.string(),
71039
+ symbol_name: z39.string().optional()
71040
+ });
71041
+ var schematic_error = z40.object({
71042
+ type: z40.literal("schematic_error"),
71043
+ schematic_error_id: z40.string(),
71044
+ error_type: z40.literal("schematic_port_not_found"),
71045
+ message: z40.string()
71046
+ }).describe("Defines a schematic error on the schematic");
71047
+ expectTypesMatch(true);
71048
+ var schematic_debug_object_base = z41.object({
71049
+ type: z41.literal("schematic_debug_object"),
71050
+ label: z41.string().optional()
71051
+ });
71052
+ var schematic_debug_rect = schematic_debug_object_base.extend({
71053
+ shape: z41.literal("rect"),
71054
+ center: point,
71055
+ size
71056
+ });
71057
+ var schematic_debug_line = schematic_debug_object_base.extend({
71058
+ shape: z41.literal("line"),
71059
+ start: point,
71060
+ end: point
71061
+ });
71062
+ var schematic_debug_point = schematic_debug_object_base.extend({
71063
+ shape: z41.literal("point"),
71064
+ center: point
71065
+ });
71066
+ var schematic_debug_object = z41.discriminatedUnion("shape", [
71067
+ schematic_debug_rect,
71068
+ schematic_debug_line,
71069
+ schematic_debug_point
71070
+ ]);
71071
+ expectTypesMatch(true);
71072
+ var schematic_voltage_probe = z4222.object({
71073
+ type: z4222.literal("schematic_voltage_probe"),
71074
+ schematic_voltage_probe_id: z4222.string(),
71075
+ position: point,
71076
+ schematic_trace_id: z4222.string(),
71077
+ voltage: voltage.optional()
71078
+ }).describe("Defines a voltage probe measurement point on a schematic trace");
71079
+ expectTypesMatch(true);
71080
+ var all_layers = [
71081
+ "top",
71082
+ "bottom",
71083
+ "inner1",
71084
+ "inner2",
71085
+ "inner3",
71086
+ "inner4",
71087
+ "inner5",
71088
+ "inner6"
71089
+ ];
71090
+ var layer_string = z432.enum(all_layers);
71091
+ var layer_ref = layer_string.or(z432.object({
71092
+ name: layer_string
71093
+ })).transform((layer) => {
71094
+ if (typeof layer === "string") {
71095
+ return layer;
71096
+ }
71097
+ return layer.name;
71098
+ });
71099
+ var visible_layer = z432.enum(["top", "bottom"]);
71100
+ var pcb_route_hint = z44.object({
71101
+ x: distance,
71102
+ y: distance,
71103
+ via: z44.boolean().optional(),
71104
+ via_to_layer: layer_ref.optional()
71105
+ });
71106
+ var pcb_route_hints = z44.array(pcb_route_hint);
71107
+ var route_hint_point = z45.object({
71108
+ x: distance,
71109
+ y: distance,
71110
+ via: z45.boolean().optional(),
71111
+ to_layer: layer_ref.optional(),
71112
+ trace_width: distance.optional()
71113
+ });
71114
+ var pcb_component = z46.object({
71115
+ type: z46.literal("pcb_component"),
71116
+ pcb_component_id: getZodPrefixedIdWithDefault("pcb_component"),
71117
+ source_component_id: z46.string(),
71118
+ center: point,
71119
+ layer: layer_ref,
71120
+ rotation,
71121
+ width: length,
71122
+ height: length,
71123
+ subcircuit_id: z46.string().optional()
71124
+ }).describe("Defines a component on the PCB");
71125
+ expectTypesMatch(true);
71126
+ var pcb_hole_circle_or_square = z47.object({
71127
+ type: z47.literal("pcb_hole"),
71128
+ pcb_hole_id: getZodPrefixedIdWithDefault("pcb_hole"),
71129
+ pcb_group_id: z47.string().optional(),
71130
+ subcircuit_id: z47.string().optional(),
71131
+ hole_shape: z47.enum(["circle", "square"]),
71132
+ hole_diameter: z47.number(),
71133
+ x: distance,
71134
+ y: distance
71135
+ });
71136
+ var pcb_hole_circle_or_square_shape = pcb_hole_circle_or_square.describe("Defines a circular or square hole on the PCB");
71137
+ expectTypesMatch(true);
71138
+ var pcb_hole_oval = z47.object({
71139
+ type: z47.literal("pcb_hole"),
71140
+ pcb_hole_id: getZodPrefixedIdWithDefault("pcb_hole"),
71141
+ pcb_group_id: z47.string().optional(),
71142
+ subcircuit_id: z47.string().optional(),
71143
+ hole_shape: z47.literal("oval"),
71144
+ hole_width: z47.number(),
71145
+ hole_height: z47.number(),
71146
+ x: distance,
71147
+ y: distance
71148
+ });
71149
+ var pcb_hole_oval_shape = pcb_hole_oval.describe("Defines an oval hole on the PCB");
71150
+ expectTypesMatch(true);
71151
+ var pcb_hole = pcb_hole_circle_or_square.or(pcb_hole_oval);
71152
+ var pcb_plated_hole_circle = z48.object({
71153
+ type: z48.literal("pcb_plated_hole"),
71154
+ shape: z48.literal("circle"),
71155
+ pcb_group_id: z48.string().optional(),
71156
+ subcircuit_id: z48.string().optional(),
71157
+ outer_diameter: z48.number(),
71158
+ hole_diameter: z48.number(),
71159
+ x: distance,
71160
+ y: distance,
71161
+ layers: z48.array(layer_ref),
71162
+ port_hints: z48.array(z48.string()).optional(),
71163
+ pcb_component_id: z48.string().optional(),
71164
+ pcb_port_id: z48.string().optional(),
71165
+ pcb_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole")
71166
+ });
71167
+ var pcb_plated_hole_oval = z48.object({
71168
+ type: z48.literal("pcb_plated_hole"),
71169
+ shape: z48.enum(["oval", "pill"]),
71170
+ pcb_group_id: z48.string().optional(),
71171
+ subcircuit_id: z48.string().optional(),
71172
+ outer_width: z48.number(),
71173
+ outer_height: z48.number(),
71174
+ hole_width: z48.number(),
71175
+ hole_height: z48.number(),
71176
+ x: distance,
71177
+ y: distance,
71178
+ layers: z48.array(layer_ref),
71179
+ port_hints: z48.array(z48.string()).optional(),
71180
+ pcb_component_id: z48.string().optional(),
71181
+ pcb_port_id: z48.string().optional(),
71182
+ pcb_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole")
71183
+ });
71184
+ var pcb_circular_hole_with_rect_pad = z48.object({
71185
+ type: z48.literal("pcb_plated_hole"),
71186
+ shape: z48.literal("circular_hole_with_rect_pad"),
71187
+ pcb_group_id: z48.string().optional(),
71188
+ subcircuit_id: z48.string().optional(),
71189
+ hole_shape: z48.literal("circle"),
71190
+ pad_shape: z48.literal("rect"),
71191
+ hole_diameter: z48.number(),
71192
+ rect_pad_width: z48.number(),
71193
+ rect_pad_height: z48.number(),
71194
+ x: distance,
71195
+ y: distance,
71196
+ layers: z48.array(layer_ref),
71197
+ port_hints: z48.array(z48.string()).optional(),
71198
+ pcb_component_id: z48.string().optional(),
71199
+ pcb_port_id: z48.string().optional(),
71200
+ pcb_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole")
71201
+ });
71202
+ var pcb_pill_hole_with_rect_pad = z48.object({
71203
+ type: z48.literal("pcb_plated_hole"),
71204
+ shape: z48.literal("pill_hole_with_rect_pad"),
71205
+ pcb_group_id: z48.string().optional(),
71206
+ subcircuit_id: z48.string().optional(),
71207
+ hole_shape: z48.literal("pill"),
71208
+ pad_shape: z48.literal("rect"),
71209
+ hole_width: z48.number(),
71210
+ hole_height: z48.number(),
71211
+ rect_pad_width: z48.number(),
71212
+ rect_pad_height: z48.number(),
71213
+ x: distance,
71214
+ y: distance,
71215
+ layers: z48.array(layer_ref),
71216
+ port_hints: z48.array(z48.string()).optional(),
71217
+ pcb_component_id: z48.string().optional(),
71218
+ pcb_port_id: z48.string().optional(),
71219
+ pcb_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole")
71220
+ });
71221
+ var pcb_plated_hole = z48.union([
71222
+ pcb_plated_hole_circle,
71223
+ pcb_plated_hole_oval,
71224
+ pcb_circular_hole_with_rect_pad
71225
+ ]);
71226
+ expectTypesMatch(true);
71227
+ expectTypesMatch(true);
71228
+ expectTypesMatch(true);
71229
+ var pcb_port = z49.object({
71230
+ type: z49.literal("pcb_port"),
71231
+ pcb_port_id: getZodPrefixedIdWithDefault("pcb_port"),
71232
+ pcb_group_id: z49.string().optional(),
71233
+ subcircuit_id: z49.string().optional(),
71234
+ source_port_id: z49.string(),
71235
+ pcb_component_id: z49.string(),
71236
+ x: distance,
71237
+ y: distance,
71238
+ layers: z49.array(layer_ref)
71239
+ }).describe("Defines a port on the PCB");
71240
+ expectTypesMatch(true);
71241
+ var pcb_smtpad_circle = z50.object({
71242
+ type: z50.literal("pcb_smtpad"),
71243
+ shape: z50.literal("circle"),
71244
+ pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"),
71245
+ pcb_group_id: z50.string().optional(),
71246
+ subcircuit_id: z50.string().optional(),
71247
+ x: distance,
71248
+ y: distance,
71249
+ radius: z50.number(),
71250
+ layer: layer_ref,
71251
+ port_hints: z50.array(z50.string()).optional(),
71252
+ pcb_component_id: z50.string().optional(),
71253
+ pcb_port_id: z50.string().optional()
71254
+ });
71255
+ var pcb_smtpad_rect = z50.object({
71256
+ type: z50.literal("pcb_smtpad"),
71257
+ shape: z50.literal("rect"),
71258
+ pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"),
71259
+ pcb_group_id: z50.string().optional(),
71260
+ subcircuit_id: z50.string().optional(),
71261
+ x: distance,
71262
+ y: distance,
71263
+ width: z50.number(),
71264
+ height: z50.number(),
71265
+ layer: layer_ref,
71266
+ port_hints: z50.array(z50.string()).optional(),
71267
+ pcb_component_id: z50.string().optional(),
71268
+ pcb_port_id: z50.string().optional()
71269
+ });
71270
+ var pcb_smtpad_rotated_rect = z50.object({
71271
+ type: z50.literal("pcb_smtpad"),
71272
+ shape: z50.literal("rotated_rect"),
71273
+ pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"),
71274
+ pcb_group_id: z50.string().optional(),
71275
+ subcircuit_id: z50.string().optional(),
71276
+ x: distance,
71277
+ y: distance,
71278
+ width: z50.number(),
71279
+ height: z50.number(),
71280
+ ccw_rotation: rotation,
71281
+ layer: layer_ref,
71282
+ port_hints: z50.array(z50.string()).optional(),
71283
+ pcb_component_id: z50.string().optional(),
71284
+ pcb_port_id: z50.string().optional()
71285
+ });
71286
+ var pcb_smtpad_pill = z50.object({
71287
+ type: z50.literal("pcb_smtpad"),
71288
+ shape: z50.literal("pill"),
71289
+ pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"),
71290
+ pcb_group_id: z50.string().optional(),
71291
+ subcircuit_id: z50.string().optional(),
71292
+ x: distance,
71293
+ y: distance,
71294
+ width: z50.number(),
71295
+ height: z50.number(),
71296
+ radius: z50.number(),
71297
+ layer: layer_ref,
71298
+ port_hints: z50.array(z50.string()).optional(),
71299
+ pcb_component_id: z50.string().optional(),
71300
+ pcb_port_id: z50.string().optional()
71301
+ });
71302
+ var pcb_smtpad = z50.union([
71303
+ pcb_smtpad_circle,
71304
+ pcb_smtpad_rect,
71305
+ pcb_smtpad_rotated_rect,
71306
+ pcb_smtpad_pill
71307
+ ]).describe("Defines an SMT pad on the PCB");
71308
+ expectTypesMatch(true);
71309
+ expectTypesMatch(true);
71310
+ expectTypesMatch(true);
71311
+ expectTypesMatch(true);
71312
+ var pcb_solder_paste_circle = z51.object({
71313
+ type: z51.literal("pcb_solder_paste"),
71314
+ shape: z51.literal("circle"),
71315
+ pcb_solder_paste_id: getZodPrefixedIdWithDefault("pcb_solder_paste"),
71316
+ pcb_group_id: z51.string().optional(),
71317
+ subcircuit_id: z51.string().optional(),
71318
+ x: distance,
71319
+ y: distance,
71320
+ radius: z51.number(),
71321
+ layer: layer_ref,
71322
+ pcb_component_id: z51.string().optional(),
71323
+ pcb_smtpad_id: z51.string().optional()
71324
+ });
71325
+ var pcb_solder_paste_rect = z51.object({
71326
+ type: z51.literal("pcb_solder_paste"),
71327
+ shape: z51.literal("rect"),
71328
+ pcb_solder_paste_id: getZodPrefixedIdWithDefault("pcb_solder_paste"),
71329
+ pcb_group_id: z51.string().optional(),
71330
+ subcircuit_id: z51.string().optional(),
71331
+ x: distance,
71332
+ y: distance,
71333
+ width: z51.number(),
71334
+ height: z51.number(),
71335
+ layer: layer_ref,
71336
+ pcb_component_id: z51.string().optional(),
71337
+ pcb_smtpad_id: z51.string().optional()
71338
+ });
71339
+ var pcb_solder_paste = z51.union([pcb_solder_paste_circle, pcb_solder_paste_rect]).describe("Defines solderpaste on the PCB");
71340
+ expectTypesMatch(true);
71341
+ expectTypesMatch(true);
71342
+ var pcb_text = z522.object({
71343
+ type: z522.literal("pcb_text"),
71344
+ pcb_text_id: getZodPrefixedIdWithDefault("pcb_text"),
71345
+ pcb_group_id: z522.string().optional(),
71346
+ subcircuit_id: z522.string().optional(),
71347
+ text: z522.string(),
71348
+ center: point,
71349
+ layer: layer_ref,
71350
+ width: length,
71351
+ height: length,
71352
+ lines: z522.number(),
71353
+ align: z522.enum(["bottom-left"])
71354
+ }).describe("Defines text on the PCB");
71355
+ expectTypesMatch(true);
71356
+ var pcb_trace_route_point_wire = z532.object({
71357
+ route_type: z532.literal("wire"),
71358
+ x: distance,
71359
+ y: distance,
71360
+ width: distance,
71361
+ start_pcb_port_id: z532.string().optional(),
71362
+ end_pcb_port_id: z532.string().optional(),
71363
+ layer: layer_ref
71364
+ });
71365
+ var pcb_trace_route_point_via = z532.object({
71366
+ route_type: z532.literal("via"),
71367
+ x: distance,
71368
+ y: distance,
71369
+ from_layer: z532.string(),
71370
+ to_layer: z532.string()
71371
+ });
71372
+ var pcb_trace_route_point = z532.union([
71373
+ pcb_trace_route_point_wire,
71374
+ pcb_trace_route_point_via
71375
+ ]);
71376
+ var pcb_trace = z532.object({
71377
+ type: z532.literal("pcb_trace"),
71378
+ source_trace_id: z532.string().optional(),
71379
+ pcb_component_id: z532.string().optional(),
71380
+ pcb_trace_id: getZodPrefixedIdWithDefault("pcb_trace"),
71381
+ pcb_group_id: z532.string().optional(),
71382
+ subcircuit_id: z532.string().optional(),
71383
+ route_thickness_mode: z532.enum(["constant", "interpolated"]).default("constant").optional(),
71384
+ route_order_index: z532.number().optional(),
71385
+ should_round_corners: z532.boolean().optional(),
71386
+ trace_length: z532.number().optional(),
71387
+ route: z532.array(z532.union([
71388
+ z532.object({
71389
+ route_type: z532.literal("wire"),
71390
+ x: distance,
71391
+ y: distance,
71392
+ width: distance,
71393
+ start_pcb_port_id: z532.string().optional(),
71394
+ end_pcb_port_id: z532.string().optional(),
71395
+ layer: layer_ref
71396
+ }),
71397
+ z532.object({
71398
+ route_type: z532.literal("via"),
71399
+ x: distance,
71400
+ y: distance,
71401
+ from_layer: z532.string(),
71402
+ to_layer: z532.string()
71403
+ })
71404
+ ]))
71405
+ }).describe("Defines a trace on the PCB");
71406
+ expectTypesMatch(true);
71407
+ expectTypesMatch(true);
71408
+ var pcb_trace_error = z54.object({
71409
+ type: z54.literal("pcb_trace_error"),
71410
+ pcb_trace_error_id: getZodPrefixedIdWithDefault("pcb_trace_error"),
71411
+ error_type: z54.literal("pcb_trace_error"),
71412
+ message: z54.string(),
71413
+ center: point.optional(),
71414
+ pcb_trace_id: z54.string(),
71415
+ source_trace_id: z54.string(),
71416
+ pcb_component_ids: z54.array(z54.string()),
71417
+ pcb_port_ids: z54.array(z54.string())
71418
+ }).describe("Defines a trace error on the PCB");
71419
+ expectTypesMatch(true);
71420
+ var pcb_port_not_matched_error = z55.object({
71421
+ type: z55.literal("pcb_port_not_matched_error"),
71422
+ pcb_error_id: getZodPrefixedIdWithDefault("pcb_error"),
71423
+ message: z55.string(),
71424
+ pcb_component_ids: z55.array(z55.string())
71425
+ }).describe("Defines a trace error on the PCB where a port is not matched");
71426
+ expectTypesMatch(true);
71427
+ var pcb_via = z56.object({
71428
+ type: z56.literal("pcb_via"),
71429
+ pcb_via_id: getZodPrefixedIdWithDefault("pcb_via"),
71430
+ pcb_group_id: z56.string().optional(),
71431
+ subcircuit_id: z56.string().optional(),
71432
+ x: distance,
71433
+ y: distance,
71434
+ outer_diameter: distance.default("0.6mm"),
71435
+ hole_diameter: distance.default("0.25mm"),
71436
+ from_layer: layer_ref.optional(),
71437
+ to_layer: layer_ref.optional(),
71438
+ layers: z56.array(layer_ref),
71439
+ pcb_trace_id: z56.string().optional()
71440
+ }).describe("Defines a via on the PCB");
71441
+ expectTypesMatch(true);
71442
+ var pcb_board = z57.object({
71443
+ type: z57.literal("pcb_board"),
71444
+ pcb_board_id: getZodPrefixedIdWithDefault("pcb_board"),
71445
+ is_subcircuit: z57.boolean().optional(),
71446
+ subcircuit_id: z57.string().optional(),
71447
+ width: length,
71448
+ height: length,
71449
+ center: point,
71450
+ thickness: length.optional().default(1.4),
71451
+ num_layers: z57.number().optional().default(4),
71452
+ outline: z57.array(point).optional()
71453
+ }).describe("Defines the board outline of the PCB");
71454
+ expectTypesMatch(true);
71455
+ var pcb_placement_error = z58.object({
71456
+ type: z58.literal("pcb_placement_error"),
71457
+ pcb_placement_error_id: getZodPrefixedIdWithDefault("pcb_placement_error"),
71458
+ message: z58.string()
71459
+ }).describe("Defines a placement error on the PCB");
71460
+ expectTypesMatch(true);
71461
+ var pcb_trace_hint = z59.object({
71462
+ type: z59.literal("pcb_trace_hint"),
71463
+ pcb_trace_hint_id: getZodPrefixedIdWithDefault("pcb_trace_hint"),
71464
+ pcb_port_id: z59.string(),
71465
+ pcb_component_id: z59.string(),
71466
+ route: z59.array(route_hint_point)
71467
+ }).describe("A hint that can be used during generation of a PCB trace");
71468
+ expectTypesMatch(true);
71469
+ var pcb_silkscreen_line = z60.object({
71470
+ type: z60.literal("pcb_silkscreen_line"),
71471
+ pcb_silkscreen_line_id: getZodPrefixedIdWithDefault("pcb_silkscreen_line"),
71472
+ pcb_component_id: z60.string(),
71473
+ pcb_group_id: z60.string().optional(),
71474
+ subcircuit_id: z60.string().optional(),
71475
+ stroke_width: distance.default("0.1mm"),
71476
+ x1: distance,
71477
+ y1: distance,
71478
+ x2: distance,
71479
+ y2: distance,
71480
+ layer: visible_layer
71481
+ }).describe("Defines a silkscreen line on the PCB");
71482
+ expectTypesMatch(true);
71483
+ var pcb_silkscreen_path = z61.object({
71484
+ type: z61.literal("pcb_silkscreen_path"),
71485
+ pcb_silkscreen_path_id: getZodPrefixedIdWithDefault("pcb_silkscreen_path"),
71486
+ pcb_component_id: z61.string(),
71487
+ pcb_group_id: z61.string().optional(),
71488
+ subcircuit_id: z61.string().optional(),
71489
+ layer: visible_layer,
71490
+ route: z61.array(point),
71491
+ stroke_width: length
71492
+ }).describe("Defines a silkscreen path on the PCB");
71493
+ expectTypesMatch(true);
71494
+ var pcb_silkscreen_text = z622.object({
71495
+ type: z622.literal("pcb_silkscreen_text"),
71496
+ pcb_silkscreen_text_id: getZodPrefixedIdWithDefault("pcb_silkscreen_text"),
71497
+ pcb_group_id: z622.string().optional(),
71498
+ subcircuit_id: z622.string().optional(),
71499
+ font: z622.literal("tscircuit2024").default("tscircuit2024"),
71500
+ font_size: distance.default("0.2mm"),
71501
+ pcb_component_id: z622.string(),
71502
+ text: z622.string(),
71503
+ ccw_rotation: z622.number().optional(),
71504
+ layer: layer_ref,
71505
+ is_mirrored: z622.boolean().default(false).optional(),
71506
+ anchor_position: point.default({ x: 0, y: 0 }),
71507
+ anchor_alignment: z622.enum(["center", "top_left", "top_right", "bottom_left", "bottom_right"]).default("center")
71508
+ }).describe("Defines silkscreen text on the PCB");
71509
+ expectTypesMatch(true);
71510
+ var pcb_silkscreen_rect = z63.object({
71511
+ type: z63.literal("pcb_silkscreen_rect"),
71512
+ pcb_silkscreen_rect_id: getZodPrefixedIdWithDefault("pcb_silkscreen_rect"),
71513
+ pcb_component_id: z63.string(),
71514
+ pcb_group_id: z63.string().optional(),
71515
+ subcircuit_id: z63.string().optional(),
71516
+ center: point,
71517
+ width: length,
71518
+ height: length,
71519
+ layer: layer_ref,
71520
+ stroke_width: length.default("1mm")
71521
+ }).describe("Defines a silkscreen rect on the PCB");
71522
+ expectTypesMatch(true);
71523
+ var pcb_silkscreen_circle = z64.object({
71524
+ type: z64.literal("pcb_silkscreen_circle"),
71525
+ pcb_silkscreen_circle_id: getZodPrefixedIdWithDefault("pcb_silkscreen_circle"),
71526
+ pcb_component_id: z64.string(),
71527
+ pcb_group_id: z64.string().optional(),
71528
+ subcircuit_id: z64.string().optional(),
71529
+ center: point,
71530
+ radius: length,
71531
+ layer: visible_layer,
71532
+ stroke_width: length.default("1mm")
71533
+ }).describe("Defines a silkscreen circle on the PCB");
71534
+ expectTypesMatch(true);
71535
+ var pcb_silkscreen_oval = z65.object({
71536
+ type: z65.literal("pcb_silkscreen_oval"),
71537
+ pcb_silkscreen_oval_id: getZodPrefixedIdWithDefault("pcb_silkscreen_oval"),
71538
+ pcb_component_id: z65.string(),
71539
+ pcb_group_id: z65.string().optional(),
71540
+ subcircuit_id: z65.string().optional(),
71541
+ center: point,
71542
+ radius_x: distance,
71543
+ radius_y: distance,
71544
+ layer: visible_layer
71545
+ }).describe("Defines a silkscreen oval on the PCB");
71546
+ expectTypesMatch(true);
71547
+ var pcb_fabrication_note_text = z66.object({
71548
+ type: z66.literal("pcb_fabrication_note_text"),
71549
+ pcb_fabrication_note_text_id: getZodPrefixedIdWithDefault("pcb_fabrication_note_text"),
71550
+ subcircuit_id: z66.string().optional(),
71551
+ pcb_group_id: z66.string().optional(),
71552
+ font: z66.literal("tscircuit2024").default("tscircuit2024"),
71553
+ font_size: distance.default("1mm"),
71554
+ pcb_component_id: z66.string(),
71555
+ text: z66.string(),
71556
+ layer: visible_layer,
71557
+ anchor_position: point.default({ x: 0, y: 0 }),
71558
+ anchor_alignment: z66.enum(["center", "top_left", "top_right", "bottom_left", "bottom_right"]).default("center"),
71559
+ color: z66.string().optional()
71560
+ }).describe("Defines a fabrication note in text on the PCB, useful for leaving notes for assemblers or fabricators");
71561
+ expectTypesMatch(true);
71562
+ var pcb_fabrication_note_path = z67.object({
71563
+ type: z67.literal("pcb_fabrication_note_path"),
71564
+ pcb_fabrication_note_path_id: getZodPrefixedIdWithDefault("pcb_fabrication_note_path"),
71565
+ pcb_component_id: z67.string(),
71566
+ subcircuit_id: z67.string().optional(),
71567
+ layer: layer_ref,
71568
+ route: z67.array(point),
71569
+ stroke_width: length,
71570
+ color: z67.string().optional()
71571
+ }).describe("Defines a fabrication path on the PCB for fabricators or assemblers");
71572
+ expectTypesMatch(true);
71573
+ var pcb_keepout = z68.object({
71574
+ type: z68.literal("pcb_keepout"),
71575
+ shape: z68.literal("rect"),
71576
+ pcb_group_id: z68.string().optional(),
71577
+ subcircuit_id: z68.string().optional(),
71578
+ center: point,
71579
+ width: distance,
71580
+ height: distance,
71581
+ pcb_keepout_id: z68.string(),
71582
+ layers: z68.array(z68.string()),
71583
+ description: z68.string().optional()
71584
+ }).or(z68.object({
71585
+ type: z68.literal("pcb_keepout"),
71586
+ shape: z68.literal("circle"),
71587
+ pcb_group_id: z68.string().optional(),
71588
+ subcircuit_id: z68.string().optional(),
71589
+ center: point,
71590
+ radius: distance,
71591
+ pcb_keepout_id: z68.string(),
71592
+ layers: z68.array(z68.string()),
71593
+ description: z68.string().optional()
71594
+ }));
71595
+ var pcb_missing_footprint_error = z69.object({
71596
+ type: z69.literal("pcb_missing_footprint_error"),
71597
+ pcb_missing_footprint_error_id: getZodPrefixedIdWithDefault("pcb_missing_footprint_error"),
71598
+ pcb_group_id: z69.string().optional(),
71599
+ subcircuit_id: z69.string().optional(),
71600
+ error_type: z69.literal("pcb_missing_footprint_error"),
71601
+ source_component_id: z69.string(),
71602
+ message: z69.string()
71603
+ }).describe("Defines a missing footprint error on the PCB");
71604
+ expectTypesMatch(true);
71605
+ var pcb_manual_edit_conflict_error = z70.object({
71606
+ type: z70.literal("pcb_manual_edit_conflict_error"),
71607
+ pcb_error_id: getZodPrefixedIdWithDefault("pcb_manual_edit_conflict_error"),
71608
+ message: z70.string(),
71609
+ pcb_component_id: z70.string(),
71610
+ pcb_group_id: z70.string().optional(),
71611
+ subcircuit_id: z70.string().optional(),
71612
+ source_component_id: z70.string()
71613
+ }).describe("Error emitted when a component has both manual placement and explicit pcbX/pcbY coordinates");
71614
+ expectTypesMatch(true);
71615
+ var pcb_group = z71.object({
71616
+ type: z71.literal("pcb_group"),
71617
+ pcb_group_id: getZodPrefixedIdWithDefault("pcb_group"),
71618
+ source_group_id: z71.string(),
71619
+ is_subcircuit: z71.boolean().optional(),
71620
+ subcircuit_id: z71.string().optional(),
71621
+ width: length,
71622
+ height: length,
71623
+ center: point,
71624
+ pcb_component_ids: z71.array(z71.string()),
71625
+ name: z71.string().optional(),
71626
+ description: z71.string().optional()
71627
+ }).describe("Defines a group of components on the PCB");
71628
+ expectTypesMatch(true);
71629
+ var pcb_autorouting_error = z722.object({
71630
+ type: z722.literal("pcb_autorouting_error"),
71631
+ pcb_error_id: getZodPrefixedIdWithDefault("pcb_autorouting_error"),
71632
+ message: z722.string()
71633
+ }).describe("The autorouting has failed to route a portion of the board");
71634
+ expectTypesMatch(true);
71635
+ var cad_component = z73.object({
71636
+ type: z73.literal("cad_component"),
71637
+ cad_component_id: z73.string(),
71638
+ pcb_component_id: z73.string(),
71639
+ source_component_id: z73.string(),
71640
+ position: point3,
71641
+ rotation: point3.optional(),
71642
+ size: point3.optional(),
71643
+ layer: layer_ref.optional(),
71644
+ footprinter_string: z73.string().optional(),
71645
+ model_obj_url: z73.string().optional(),
71646
+ model_stl_url: z73.string().optional(),
71647
+ model_3mf_url: z73.string().optional(),
71648
+ model_jscad: z73.any().optional()
71649
+ }).describe("Defines a component on the PCB");
71650
+ var any_circuit_element = z74.union([
71651
+ source_trace,
71652
+ source_port,
71653
+ any_source_component,
71654
+ source_led,
71655
+ source_net,
71656
+ source_group,
71657
+ source_simple_bug,
71658
+ source_simple_chip,
71659
+ source_simple_capacitor,
71660
+ source_simple_diode,
71661
+ source_simple_resistor,
71662
+ source_simple_power_source,
71663
+ source_simple_battery,
71664
+ source_simple_inductor,
71665
+ source_simple_pin_header,
71666
+ source_simple_resonator,
71667
+ source_simple_switch,
71668
+ source_simple_transistor,
71669
+ source_simple_mosfet,
71670
+ source_simple_potentiometer,
71671
+ source_simple_push_button,
71672
+ source_project_metadata,
71673
+ pcb_component,
71674
+ pcb_hole,
71675
+ pcb_missing_footprint_error,
71676
+ pcb_manual_edit_conflict_error,
71677
+ pcb_plated_hole,
71678
+ pcb_keepout,
71679
+ pcb_port,
71680
+ pcb_text,
71681
+ pcb_trace,
71682
+ pcb_via,
71683
+ pcb_smtpad,
71684
+ pcb_solder_paste,
71685
+ pcb_board,
71686
+ pcb_group,
71687
+ pcb_trace_hint,
71688
+ pcb_silkscreen_line,
71689
+ pcb_silkscreen_path,
71690
+ pcb_silkscreen_text,
71691
+ pcb_silkscreen_rect,
71692
+ pcb_silkscreen_circle,
71693
+ pcb_silkscreen_oval,
71694
+ pcb_trace_error,
71695
+ pcb_placement_error,
71696
+ pcb_port_not_matched_error,
71697
+ pcb_fabrication_note_path,
71698
+ pcb_fabrication_note_text,
71699
+ pcb_autorouting_error,
71700
+ schematic_box,
71701
+ schematic_text,
71702
+ schematic_line,
71703
+ schematic_component,
71704
+ schematic_port,
71705
+ schematic_trace,
71706
+ schematic_path,
71707
+ schematic_error,
71708
+ schematic_net_label,
71709
+ schematic_debug_object,
71710
+ schematic_voltage_probe,
71711
+ cad_component
71712
+ ]);
71713
+ var any_soup_element2 = any_circuit_element;
71714
+ var su6 = (soup, options = {}) => {
71715
+ let internalStore = soup._internal_store;
71716
+ if (!internalStore) {
71717
+ internalStore = {
71718
+ counts: {}
71719
+ };
71720
+ soup._internal_store = internalStore;
71721
+ for (const elm of soup) {
71722
+ const type = elm.type;
71723
+ const idVal = elm[`${type}_id`];
71724
+ if (!idVal)
71725
+ continue;
71726
+ const idNum = Number.parseInt(idVal.split("_").pop());
71727
+ if (!Number.isNaN(idNum)) {
71728
+ internalStore.counts[type] = Math.max(internalStore.counts[type] ?? 0, idNum);
71729
+ }
71730
+ }
71731
+ }
71732
+ const su22 = new Proxy({}, {
71733
+ get: (proxy_target, component_type) => {
71734
+ if (component_type === "toArray") {
71735
+ return () => soup;
71736
+ }
71737
+ return {
71738
+ get: (id) => soup.find((e) => e.type === component_type && e[`${component_type}_id`] === id),
71739
+ getUsing: (using) => {
71740
+ const keys = Object.keys(using);
71741
+ if (keys.length !== 1) {
71742
+ throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");
71743
+ }
71744
+ const join_key = keys[0];
71745
+ const join_type = join_key.replace("_id", "");
71746
+ const joiner = soup.find((e) => e.type === join_type && e[join_key] === using[join_key]);
71747
+ if (!joiner)
71748
+ return null;
71749
+ return soup.find((e) => e.type === component_type && e[`${component_type}_id`] === joiner[`${component_type}_id`]);
71750
+ },
71751
+ getWhere: (where) => {
71752
+ const keys = Object.keys(where);
71753
+ return soup.find((e) => e.type === component_type && keys.every((key) => e[key] === where[key]));
71754
+ },
71755
+ list: (where) => {
71756
+ const keys = !where ? [] : Object.keys(where);
71757
+ return soup.filter((e) => e.type === component_type && keys.every((key) => e[key] === where[key]));
71758
+ },
71759
+ insert: (elm) => {
71760
+ internalStore.counts[component_type] ??= -1;
71761
+ internalStore.counts[component_type]++;
71762
+ const index = internalStore.counts[component_type];
71763
+ const newElm = {
71764
+ type: component_type,
71765
+ [`${component_type}_id`]: `${component_type}_${index}`,
71766
+ ...elm
71767
+ };
71768
+ if (options.validateInserts) {
71769
+ const parser = dist_exports[component_type] ?? any_soup_element2;
71770
+ parser.parse(newElm);
71771
+ }
71772
+ soup.push(newElm);
71773
+ return newElm;
71774
+ },
71775
+ delete: (id) => {
71776
+ const elm = soup.find((e) => e[`${component_type}_id`] === id);
71777
+ if (!elm)
71778
+ return;
71779
+ soup.splice(soup.indexOf(elm), 1);
71780
+ },
71781
+ update: (id, newProps) => {
71782
+ const elm = soup.find((e) => e.type === component_type && e[`${component_type}_id`] === id);
71783
+ if (!elm)
71784
+ return;
71785
+ Object.assign(elm, newProps);
71786
+ return elm;
71787
+ },
71788
+ select: (selector) => {
71789
+ if (component_type === "source_component") {
71790
+ return soup.find((e) => e.type === "source_component" && e.name === selector.replace(/\./g, ""));
71791
+ } else if (component_type === "pcb_port" || component_type === "source_port" || component_type === "schematic_port") {
71792
+ const [component_name, port_selector] = selector.replace(/\./g, "").split(/[\s\>]+/);
71793
+ const source_component = soup.find((e) => e.type === "source_component" && e.name === component_name);
71794
+ if (!source_component)
71795
+ return null;
71796
+ const source_port2 = soup.find((e) => e.type === "source_port" && e.source_component_id === source_component.source_component_id && (e.name === port_selector || (e.port_hints ?? []).includes(port_selector)));
71797
+ if (!source_port2)
71798
+ return null;
71799
+ if (component_type === "source_port")
71800
+ return source_port2;
71801
+ if (component_type === "pcb_port") {
71802
+ return soup.find((e) => e.type === "pcb_port" && e.source_port_id === source_port2.source_port_id);
71803
+ } else if (component_type === "schematic_port") {
71804
+ return soup.find((e) => e.type === "schematic_port" && e.source_port_id === source_port2.source_port_id);
71805
+ }
71806
+ }
71807
+ }
71808
+ };
71809
+ }
71810
+ });
71811
+ return su22;
71812
+ };
71813
+ su6.unparsed = su6;
71814
+ var su_default2 = su6;
71815
+ var transformPCBElement = (elm, matrix) => {
71816
+ if (elm.type === "pcb_plated_hole" || elm.type === "pcb_hole" || elm.type === "pcb_via" || elm.type === "pcb_smtpad" || elm.type === "pcb_port") {
71817
+ const { x, y } = applyToPoint3(matrix, { x: elm.x, y: elm.y });
71818
+ elm.x = x;
71819
+ elm.y = y;
71820
+ } else if (elm.type === "pcb_keepout" || elm.type === "pcb_board") {
71821
+ elm.center = applyToPoint3(matrix, elm.center);
71822
+ } else if (elm.type === "pcb_silkscreen_text" || elm.type === "pcb_fabrication_note_text") {
71823
+ elm.anchor_position = applyToPoint3(matrix, elm.anchor_position);
71824
+ } else if (elm.type === "pcb_silkscreen_circle" || elm.type === "pcb_silkscreen_rect" || elm.type === "pcb_component") {
71825
+ elm.center = applyToPoint3(matrix, elm.center);
71826
+ } else if (elm.type === "pcb_silkscreen_path" || elm.type === "pcb_trace" || elm.type === "pcb_fabrication_note_path") {
71827
+ elm.route = elm.route.map((rp) => {
71828
+ const tp = applyToPoint3(matrix, rp);
71829
+ rp.x = tp.x;
71830
+ rp.y = tp.y;
71831
+ return rp;
71832
+ });
71833
+ } else if (elm.type === "pcb_silkscreen_line") {
71834
+ const p1 = { x: elm.x1, y: elm.y1 };
71835
+ const p2 = { x: elm.x2, y: elm.y2 };
71836
+ const p1t = applyToPoint3(matrix, p1);
71837
+ const p2t = applyToPoint3(matrix, p2);
71838
+ elm.x1 = p1t.x;
71839
+ elm.y1 = p1t.y;
71840
+ elm.x2 = p2t.x;
71841
+ elm.y2 = p2t.y;
71842
+ } else if (elm.type === "cad_component") {
71843
+ const newPos = applyToPoint3(matrix, {
71844
+ x: elm.position.x,
71845
+ y: elm.position.y
71846
+ });
71847
+ elm.position.x = newPos.x;
71848
+ elm.position.y = newPos.y;
71849
+ }
71850
+ return elm;
71851
+ };
71852
+ var transformPCBElements = (elms, matrix) => {
71853
+ const tsr = decomposeTSR2(matrix);
71854
+ const flipPadWidthHeight = Math.round(tsr.rotation.angle / (Math.PI / 2)) % 2 === 1;
71855
+ let transformedElms = elms.map((elm) => transformPCBElement(elm, matrix));
71856
+ if (flipPadWidthHeight) {
71857
+ transformedElms = transformedElms.map((elm) => {
71858
+ if (elm.type === "pcb_smtpad" && elm.shape === "rect") {
71859
+ [elm.width, elm.height] = [elm.height, elm.width];
71860
+ }
71861
+ return elm;
71862
+ });
71863
+ }
71864
+ return transformedElms;
71865
+ };
71866
+ function stringHash(str) {
71867
+ let hash = 0;
71868
+ if (str.length == 0)
71869
+ return hash;
71870
+ for (var i = 0;i < str.length; i++) {
71871
+ var char = str.charCodeAt(i);
71872
+ hash = (hash << 5) - hash + char;
71873
+ hash = hash & hash;
71874
+ }
71875
+ return Math.abs(hash);
71876
+ }
71877
+ var nice_color_palettes = [
71878
+ ["#69d2e7", "#a7dbd8", "#e0e4cc", "#f38630", "#fa6900"],
71879
+ ["#fe4365", "#fc9d9a", "#f9cdad", "#c8c8a9", "#83af9b"],
71880
+ ["#ecd078", "#d95b43", "#c02942", "#542437", "#53777a"],
71881
+ ["#556270", "#4ecdc4", "#c7f464", "#ff6b6b", "#c44d58"],
71882
+ ["#774f38", "#e08e79", "#f1d4af", "#ece5ce", "#c5e0dc"],
71883
+ ["#e8ddcb", "#cdb380", "#036564", "#033649", "#031634"],
71884
+ ["#490a3d", "#bd1550", "#e97f02", "#f8ca00", "#8a9b0f"],
71885
+ ["#594f4f", "#547980", "#45ada8", "#9de0ad", "#e5fcc2"],
71886
+ ["#00a0b0", "#6a4a3c", "#cc333f", "#eb6841", "#edc951"],
71887
+ ["#e94e77", "#d68189", "#c6a49a", "#c6e5d9", "#f4ead5"],
71888
+ ["#3fb8af", "#7fc7af", "#dad8a7", "#ff9e9d", "#ff3d7f"],
71889
+ ["#d9ceb2", "#948c75", "#d5ded9", "#7a6a53", "#99b2b7"],
71890
+ ["#ffffff", "#cbe86b", "#f2e9e1", "#1c140d", "#cbe86b"],
71891
+ ["#efffcd", "#dce9be", "#555152", "#2e2633", "#99173c"],
71892
+ ["#343838", "#005f6b", "#008c9e", "#00b4cc", "#00dffc"],
71893
+ ["#413e4a", "#73626e", "#b38184", "#f0b49e", "#f7e4be"],
71894
+ ["#ff4e50", "#fc913a", "#f9d423", "#ede574", "#e1f5c4"],
71895
+ ["#99b898", "#fecea8", "#ff847c", "#e84a5f", "#2a363b"],
71896
+ ["#655643", "#80bca3", "#f6f7bd", "#e6ac27", "#bf4d28"],
71897
+ ["#00a8c6", "#40c0cb", "#f9f2e7", "#aee239", "#8fbe00"],
71898
+ ["#351330", "#424254", "#64908a", "#e8caa4", "#cc2a41"],
71899
+ ["#554236", "#f77825", "#d3ce3d", "#f1efa5", "#60b99a"],
71900
+ ["#5d4157", "#838689", "#a8caba", "#cad7b2", "#ebe3aa"],
71901
+ ["#8c2318", "#5e8c6a", "#88a65e", "#bfb35a", "#f2c45a"],
71902
+ ["#fad089", "#ff9c5b", "#f5634a", "#ed303c", "#3b8183"],
71903
+ ["#ff4242", "#f4fad2", "#d4ee5e", "#e1edb9", "#f0f2eb"],
71904
+ ["#f8b195", "#f67280", "#c06c84", "#6c5b7b", "#355c7d"],
71905
+ ["#d1e751", "#ffffff", "#000000", "#4dbce9", "#26ade4"],
71906
+ ["#1b676b", "#519548", "#88c425", "#bef202", "#eafde6"],
71907
+ ["#5e412f", "#fcebb6", "#78c0a8", "#f07818", "#f0a830"],
71908
+ ["#bcbdac", "#cfbe27", "#f27435", "#f02475", "#3b2d38"],
71909
+ ["#452632", "#91204d", "#e4844a", "#e8bf56", "#e2f7ce"],
71910
+ ["#eee6ab", "#c5bc8e", "#696758", "#45484b", "#36393b"],
71911
+ ["#f0d8a8", "#3d1c00", "#86b8b1", "#f2d694", "#fa2a00"],
71912
+ ["#2a044a", "#0b2e59", "#0d6759", "#7ab317", "#a0c55f"],
71913
+ ["#f04155", "#ff823a", "#f2f26f", "#fff7bd", "#95cfb7"],
71914
+ ["#b9d7d9", "#668284", "#2a2829", "#493736", "#7b3b3b"],
71915
+ ["#bbbb88", "#ccc68d", "#eedd99", "#eec290", "#eeaa88"],
71916
+ ["#b3cc57", "#ecf081", "#ffbe40", "#ef746f", "#ab3e5b"],
71917
+ ["#a3a948", "#edb92e", "#f85931", "#ce1836", "#009989"],
71918
+ ["#300030", "#480048", "#601848", "#c04848", "#f07241"],
71919
+ ["#67917a", "#170409", "#b8af03", "#ccbf82", "#e33258"],
71920
+ ["#aab3ab", "#c4cbb7", "#ebefc9", "#eee0b7", "#e8caaf"],
71921
+ ["#e8d5b7", "#0e2430", "#fc3a51", "#f5b349", "#e8d5b9"],
71922
+ ["#ab526b", "#bca297", "#c5ceae", "#f0e2a4", "#f4ebc3"],
71923
+ ["#607848", "#789048", "#c0d860", "#f0f0d8", "#604848"],
71924
+ ["#b6d8c0", "#c8d9bf", "#dadabd", "#ecdbbc", "#fedcba"],
71925
+ ["#a8e6ce", "#dcedc2", "#ffd3b5", "#ffaaa6", "#ff8c94"],
71926
+ ["#3e4147", "#fffedf", "#dfba69", "#5a2e2e", "#2a2c31"],
71927
+ ["#fc354c", "#29221f", "#13747d", "#0abfbc", "#fcf7c5"],
71928
+ ["#cc0c39", "#e6781e", "#c8cf02", "#f8fcc1", "#1693a7"],
71929
+ ["#1c2130", "#028f76", "#b3e099", "#ffeaad", "#d14334"],
71930
+ ["#a7c5bd", "#e5ddcb", "#eb7b59", "#cf4647", "#524656"],
71931
+ ["#dad6ca", "#1bb0ce", "#4f8699", "#6a5e72", "#563444"],
71932
+ ["#5c323e", "#a82743", "#e15e32", "#c0d23e", "#e5f04c"],
71933
+ ["#edebe6", "#d6e1c7", "#94c7b6", "#403b33", "#d3643b"],
71934
+ ["#fdf1cc", "#c6d6b8", "#987f69", "#e3ad40", "#fcd036"],
71935
+ ["#230f2b", "#f21d41", "#ebebbc", "#bce3c5", "#82b3ae"],
71936
+ ["#b9d3b0", "#81bda4", "#b28774", "#f88f79", "#f6aa93"],
71937
+ ["#3a111c", "#574951", "#83988e", "#bcdea5", "#e6f9bc"],
71938
+ ["#5e3929", "#cd8c52", "#b7d1a3", "#dee8be", "#fcf7d3"],
71939
+ ["#1c0113", "#6b0103", "#a30006", "#c21a01", "#f03c02"],
71940
+ ["#000000", "#9f111b", "#b11623", "#292c37", "#cccccc"],
71941
+ ["#382f32", "#ffeaf2", "#fcd9e5", "#fbc5d8", "#f1396d"],
71942
+ ["#e3dfba", "#c8d6bf", "#93ccc6", "#6cbdb5", "#1a1f1e"],
71943
+ ["#f6f6f6", "#e8e8e8", "#333333", "#990100", "#b90504"],
71944
+ ["#1b325f", "#9cc4e4", "#e9f2f9", "#3a89c9", "#f26c4f"],
71945
+ ["#a1dbb2", "#fee5ad", "#faca66", "#f7a541", "#f45d4c"],
71946
+ ["#c1b398", "#605951", "#fbeec2", "#61a6ab", "#accec0"],
71947
+ ["#5e9fa3", "#dcd1b4", "#fab87f", "#f87e7b", "#b05574"],
71948
+ ["#951f2b", "#f5f4d7", "#e0dfb1", "#a5a36c", "#535233"],
71949
+ ["#8dccad", "#988864", "#fea6a2", "#f9d6ac", "#ffe9af"],
71950
+ ["#2d2d29", "#215a6d", "#3ca2a2", "#92c7a3", "#dfece6"],
71951
+ ["#413d3d", "#040004", "#c8ff00", "#fa023c", "#4b000f"],
71952
+ ["#eff3cd", "#b2d5ba", "#61ada0", "#248f8d", "#605063"],
71953
+ ["#ffefd3", "#fffee4", "#d0ecea", "#9fd6d2", "#8b7a5e"],
71954
+ ["#cfffdd", "#b4dec1", "#5c5863", "#a85163", "#ff1f4c"],
71955
+ ["#9dc9ac", "#fffec7", "#f56218", "#ff9d2e", "#919167"],
71956
+ ["#4e395d", "#827085", "#8ebe94", "#ccfc8e", "#dc5b3e"],
71957
+ ["#a8a7a7", "#cc527a", "#e8175d", "#474747", "#363636"],
71958
+ ["#f8edd1", "#d88a8a", "#474843", "#9d9d93", "#c5cfc6"],
71959
+ ["#046d8b", "#309292", "#2fb8ac", "#93a42a", "#ecbe13"],
71960
+ ["#f38a8a", "#55443d", "#a0cab5", "#cde9ca", "#f1edd0"],
71961
+ ["#a70267", "#f10c49", "#fb6b41", "#f6d86b", "#339194"],
71962
+ ["#ff003c", "#ff8a00", "#fabe28", "#88c100", "#00c176"],
71963
+ ["#ffedbf", "#f7803c", "#f54828", "#2e0d23", "#f8e4c1"],
71964
+ ["#4e4d4a", "#353432", "#94ba65", "#2790b0", "#2b4e72"],
71965
+ ["#0ca5b0", "#4e3f30", "#fefeeb", "#f8f4e4", "#a5b3aa"],
71966
+ ["#4d3b3b", "#de6262", "#ffb88c", "#ffd0b3", "#f5e0d3"],
71967
+ ["#fffbb7", "#a6f6af", "#66b6ab", "#5b7c8d", "#4f2958"],
71968
+ ["#edf6ee", "#d1c089", "#b3204d", "#412e28", "#151101"],
71969
+ ["#9d7e79", "#ccac95", "#9a947c", "#748b83", "#5b756c"],
71970
+ ["#fcfef5", "#e9ffe1", "#cdcfb7", "#d6e6c3", "#fafbe3"],
71971
+ ["#9cddc8", "#bfd8ad", "#ddd9ab", "#f7af63", "#633d2e"],
71972
+ ["#30261c", "#403831", "#36544f", "#1f5f61", "#0b8185"],
71973
+ ["#aaff00", "#ffaa00", "#ff00aa", "#aa00ff", "#00aaff"],
71974
+ ["#d1313d", "#e5625c", "#f9bf76", "#8eb2c5", "#615375"],
71975
+ ["#ffe181", "#eee9e5", "#fad3b2", "#ffba7f", "#ff9c97"],
71976
+ ["#73c8a9", "#dee1b6", "#e1b866", "#bd5532", "#373b44"],
71977
+ ["#805841", "#dcf7f3", "#fffcdd", "#ffd8d8", "#f5a2a2"]
71978
+ ];
71979
+ var getDebugLayoutObject = (lo) => {
71980
+ let {
71981
+ x,
71982
+ y,
71983
+ width,
71984
+ height
71985
+ } = {
71986
+ ...lo,
71987
+ ...lo.size,
71988
+ ...lo.center,
71989
+ ...lo.position
71990
+ };
71991
+ if (lo.x1 !== undefined && lo.x2 !== undefined && lo.y1 !== undefined && lo.y2 !== undefined) {
71992
+ x = (lo.x1 + lo.x2) / 2;
71993
+ y = (lo.y1 + lo.y2) / 2;
71994
+ width = Math.abs(lo.x1 - lo.x2);
71995
+ height = Math.abs(lo.y1 - lo.y2);
71996
+ }
71997
+ const title = lo.text || lo.name || lo.source?.text || lo.source?.name || "?";
71998
+ const content = lo;
71999
+ if (x === undefined || y === undefined)
72000
+ return null;
72001
+ if (width === undefined) {
72002
+ if ("outer_diameter" in lo) {
72003
+ width = lo.outer_diameter;
72004
+ height = lo.outer_diameter;
72005
+ }
72006
+ }
72007
+ if (width === undefined || height === undefined) {
72008
+ width = 0.1;
72009
+ height = 0.1;
72010
+ }
72011
+ return {
72012
+ x,
72013
+ y,
72014
+ width,
72015
+ height,
72016
+ title,
72017
+ content,
72018
+ bg_color: nice_color_palettes[stringHash(lo.type || title) % nice_color_palettes.length]?.[4] ?? "#f00"
72019
+ };
72020
+ };
72021
+ var isTruthy = (value) => Boolean(value);
72022
+ var findBoundsAndCenter = (elements) => {
72023
+ const debugObjects = elements.filter((elm) => elm.type.startsWith("pcb_")).concat(elements.filter((elm) => elm.type === "pcb_trace").flatMap((elm) => elm.route)).map((elm) => getDebugLayoutObject(elm)).filter(isTruthy);
72024
+ if (debugObjects.length === 0)
72025
+ return { center: { x: 0, y: 0 }, width: 0, height: 0 };
72026
+ let minX = debugObjects[0].x - debugObjects[0].width / 2;
72027
+ let maxX = debugObjects[0].x + debugObjects[0].width / 2;
72028
+ let minY = debugObjects[0].y - debugObjects[0].height / 2;
72029
+ let maxY = debugObjects[0].y + debugObjects[0].height / 2;
72030
+ for (const obj of debugObjects.slice(1)) {
72031
+ minX = Math.min(minX, obj.x - obj.width / 2);
72032
+ maxX = Math.max(maxX, obj.x + obj.width / 2);
72033
+ minY = Math.min(minY, obj.y - obj.height / 2);
72034
+ maxY = Math.max(maxY, obj.y + obj.height / 2);
72035
+ }
72036
+ const width = maxX - minX;
72037
+ const height = maxY - minY;
72038
+ const center = { x: minX + width / 2, y: minY + height / 2 };
72039
+ return { center, width, height };
72040
+ };
72041
+ var generateFootprintTsx = (circuitJson) => {
72042
+ const holes = su_default2(circuitJson).pcb_hole.list();
72043
+ const platedHoles = su_default2(circuitJson).pcb_plated_hole.list();
72044
+ const smtPads = su_default2(circuitJson).pcb_smtpad.list();
72045
+ const silkscreenPaths = su_default2(circuitJson).pcb_silkscreen_path.list();
72046
+ const silkscreenTexts = su_default2(circuitJson).pcb_silkscreen_text.list();
72047
+ const elementStrings = [];
72048
+ for (const hole of holes) {
72049
+ if (hole.hole_shape === "circle") {
72050
+ elementStrings.push(`<hole pcbX="${mmStr(hole.x)}" pcbY="${mmStr(hole.y)}" diameter="${mmStr(hole.hole_diameter)}" />`);
72051
+ } else if (hole.hole_shape === "oval") {
72052
+ console.warn("Unhandled oval hole in conversion (needs implementation)");
72053
+ }
72054
+ }
72055
+ for (const platedHole of platedHoles) {
72056
+ if (platedHole.shape === "oval" || platedHole.shape === "pill") {
72057
+ elementStrings.push(`<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}" />`);
72058
+ } else if (platedHole.shape === "circle") {
72059
+ elementStrings.push(`<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" />`);
72060
+ }
72061
+ }
72062
+ for (const smtPad of smtPads) {
72063
+ if (smtPad.shape === "circle") {
72064
+ elementStrings.push(`<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" radius="${mmStr(smtPad.radius)}" shape="circle" />`);
72065
+ } else if (smtPad.shape === "rect") {
72066
+ elementStrings.push(`<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" />`);
72067
+ }
72068
+ }
72069
+ for (const silkscreenPath of silkscreenPaths) {
72070
+ elementStrings.push(`<silkscreenpath route={${JSON.stringify(silkscreenPath.route)}} />`);
72071
+ }
72072
+ for (const silkscreenText of silkscreenTexts) {
72073
+ elementStrings.push(`<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)}"` : ""} />`);
72074
+ }
72075
+ return `
72076
+ <footprint>
72077
+ ${elementStrings.join(`
72078
+ `)}
72079
+ </footprint>
72080
+ `.trim();
72081
+ };
72082
+ var generateTypescriptComponent = ({
72083
+ pinLabels,
72084
+ componentName,
72085
+ objUrl,
72086
+ circuitJson,
72087
+ supplierPartNumbers,
72088
+ manufacturerPartNumber
72089
+ }) => {
72090
+ const safePinLabels = pinLabels ?? {};
72091
+ const footprintTsx = generateFootprintTsx(circuitJson);
72092
+ const simplifiedPinLabels = Object.fromEntries(Object.entries(safePinLabels).map(([pin, labels]) => {
72093
+ if (Array.isArray(labels) && labels.length > 1) {
72094
+ return [pin, [labels[1]]];
72095
+ }
72096
+ return [pin, labels];
72097
+ }));
72098
+ const pinLabelsString = Object.entries(simplifiedPinLabels).map(([pin, labels]) => ` ${pin}: ${JSON.stringify(labels)}`).join(`,
72099
+ `);
72100
+ return `
72101
+ import type { ChipProps } from "@tscircuit/props"
72102
+
72103
+ const pinLabels = {
72104
+ ${pinLabelsString}
72105
+ } as const
72106
+
72107
+ export const ${componentName} = (props: ChipProps<typeof pinLabels>) => {
72108
+ return (
72109
+ <chip
72110
+ pinLabels={pinLabels}
72111
+ supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
72112
+ manufacturerPartNumber="${manufacturerPartNumber}"
72113
+ footprint={${footprintTsx}}
72114
+ ${objUrl ? `cadModel={{
72115
+ objUrl: "${objUrl}",
72116
+ rotationOffset: { x: 0, y: 0, z: 0 },
72117
+ positionOffset: { x: 0, y: 0, z: 0 },
72118
+ }}` : ""}
72119
+ {...props}
72120
+ />
72121
+ )
72122
+ }
72123
+ `.trim();
72124
+ };
72125
+ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag, sweepFlag) {
72126
+ const start = { x: startX, y: startY };
72127
+ const end = { x: endX, y: endY };
72128
+ const midX = (startX + endX) / 2;
72129
+ const midY = (startY + endY) / 2;
72130
+ const dx = endX - startX;
72131
+ const dy = endY - startY;
72132
+ const distance2 = Math.sqrt(dx * dx + dy * dy);
72133
+ if (distance2 === 0 || radius < distance2 / 2) {
72134
+ return [start, end];
72135
+ }
72136
+ const h = Math.sqrt(radius * radius - distance2 * distance2 / 4);
72137
+ const angle = Math.atan2(dy, dx);
72138
+ const centerX = midX + h * Math.sin(angle) * (sweepFlag ? 1 : -1);
72139
+ const centerY = midY - h * Math.cos(angle) * (sweepFlag ? 1 : -1);
72140
+ const startAngle = Math.atan2(startY - centerY, startX - centerX);
72141
+ let endAngle = Math.atan2(endY - centerY, endX - centerX);
72142
+ if (!sweepFlag && endAngle > startAngle) {
72143
+ endAngle -= 2 * Math.PI;
72144
+ } else if (sweepFlag && endAngle < startAngle) {
72145
+ endAngle += 2 * Math.PI;
72146
+ }
72147
+ if (!largeArcFlag && Math.abs(endAngle - startAngle) > Math.PI || largeArcFlag && Math.abs(endAngle - startAngle) < Math.PI) {
72148
+ if (endAngle > startAngle) {
72149
+ endAngle -= 2 * Math.PI;
72150
+ } else {
72151
+ endAngle += 2 * Math.PI;
72152
+ }
72153
+ }
72154
+ const numPoints = Math.max(2, Math.ceil(Math.abs(endAngle - startAngle) * radius));
72155
+ const path23 = [];
72156
+ for (let i = 0;i <= numPoints; i++) {
72157
+ const t2 = i / numPoints;
72158
+ const angle2 = startAngle + t2 * (endAngle - startAngle);
72159
+ const x = centerX + radius * Math.cos(angle2);
72160
+ const y = centerY + radius * Math.sin(angle2);
72161
+ path23.push({ x, y });
72162
+ }
72163
+ return path23;
72164
+ }
72165
+ var computeCenterOffset = (easyeda) => {
72166
+ const pads = easyeda.packageDetail.dataStr.shape.filter((shape) => shape.type === "PAD");
72167
+ const minX = Math.min(...pads.map((pad) => mm(pad.center.x)));
72168
+ const maxX = Math.max(...pads.map((pad) => mm(pad.center.x)));
72169
+ const minY = Math.min(...pads.map((pad) => mm(pad.center.y)));
72170
+ const maxY = Math.max(...pads.map((pad) => mm(pad.center.y)));
72171
+ const centerX = (minX + maxX) / 2;
72172
+ const centerY = (minY + maxY) / 2;
72173
+ return {
72174
+ x: centerX,
72175
+ y: centerY
72176
+ };
72177
+ };
72178
+ var normalizePinLabels = (inputPinLabels) => {
72179
+ const unqInputPinLabels = inputPinLabels.map((labels) => [...new Set(labels)]);
72180
+ const result = unqInputPinLabels.map(() => []);
72181
+ const desiredNumbers = unqInputPinLabels.map(() => null);
72182
+ for (let i = 0;i < unqInputPinLabels.length; i++) {
72183
+ for (const label of unqInputPinLabels[i]) {
72184
+ if (/^\d+$/.test(label)) {
72185
+ desiredNumbers[i] = Number.parseInt(label);
72186
+ break;
72187
+ }
72188
+ }
72189
+ }
72190
+ let highestPinNumber = 0;
72191
+ const alreadyAcceptedDesiredNumbers = /* @__PURE__ */ new Set;
72192
+ for (let i = 0;i < desiredNumbers.length; i++) {
72193
+ const desiredNumber = desiredNumbers[i];
72194
+ if (desiredNumber === null || desiredNumber < 1) {
72195
+ continue;
72196
+ }
72197
+ if (!alreadyAcceptedDesiredNumbers.has(desiredNumber)) {
72198
+ alreadyAcceptedDesiredNumbers.add(desiredNumber);
72199
+ result[i].push(`pin${desiredNumber}`);
72200
+ highestPinNumber = Math.max(highestPinNumber, desiredNumber);
72201
+ continue;
72202
+ }
72203
+ let existingAltsForPin = 0;
72204
+ for (const label of result[i]) {
72205
+ if (label.startsWith(`pin${desiredNumber}_alt`)) {
72206
+ existingAltsForPin++;
72207
+ }
72208
+ }
72209
+ result[i].push(`pin${desiredNumber}_alt${existingAltsForPin + 1}`);
72210
+ }
72211
+ for (let i = 0;i < result.length; i++) {
72212
+ const firstLabel = result[i][0];
72213
+ if (firstLabel?.includes("_alt")) {
72214
+ highestPinNumber++;
72215
+ result[i].unshift(`pin${highestPinNumber}`);
72216
+ }
72217
+ }
72218
+ for (let i = 0;i < result.length; i++) {
72219
+ if (result[i].length === 0) {
72220
+ highestPinNumber++;
72221
+ result[i].push(`pin${highestPinNumber}`);
72222
+ }
72223
+ }
72224
+ const totalLabelCounts = {};
72225
+ for (const inputLabels of unqInputPinLabels) {
72226
+ for (const label of inputLabels) {
72227
+ if (/^\d+$/.test(label)) {
72228
+ continue;
72229
+ }
72230
+ totalLabelCounts[label] = (totalLabelCounts[label] ?? 0) + 1;
72231
+ }
72232
+ }
72233
+ const incrementalLabelCounts = {};
72234
+ for (let i = 0;i < unqInputPinLabels.length; i++) {
72235
+ const inputLabels = unqInputPinLabels[i];
72236
+ for (const label of inputLabels) {
72237
+ if (/^\d+$/.test(label)) {
72238
+ continue;
72239
+ }
72240
+ if (totalLabelCounts[label] === 1) {
72241
+ result[i].push(label);
72242
+ } else {
72243
+ incrementalLabelCounts[label] = (incrementalLabelCounts[label] ?? 0) + 1;
72244
+ result[i].push(`${label}${incrementalLabelCounts[label]}`);
72245
+ }
72246
+ }
72247
+ }
72248
+ return result;
72249
+ };
72250
+ var mil2mm = (mil) => {
72251
+ if (typeof mil === "number")
72252
+ return mm(`${mil}mil`);
72253
+ if (mil.match(/^\d+$/))
72254
+ return mm(`${mil}mil`);
72255
+ return mm(mil);
72256
+ };
72257
+ var milx10 = (mil10) => {
72258
+ if (typeof mil10 === "number")
72259
+ return mil2mm(mil10) * 10;
72260
+ if (mil10.match(/^\d+$/))
72261
+ return mil2mm(mil10) * 10;
72262
+ return mil2mm(mil10);
72263
+ };
72264
+ var handleSilkscreenPath = (track, index) => {
72265
+ return pcb_silkscreen_path.parse({
72266
+ type: "pcb_silkscreen_path",
72267
+ pcb_silkscreen_path_id: `pcb_silkscreen_path_${index + 1}`,
72268
+ pcb_component_id: "pcb_component_1",
72269
+ layer: "top",
72270
+ route: track.points.map((point2) => ({
72271
+ x: milx10(point2.x),
72272
+ y: milx10(point2.y)
72273
+ })),
72274
+ stroke_width: mil10ToMm(track.width)
72275
+ });
72276
+ };
72277
+ var handleSilkscreenArc = (arc, index) => {
72278
+ const arcPath = generateArcFromSweep(arc.start.x, arc.start.y, arc.end.x, arc.end.y, arc.radiusX, arc.largeArc, arc.sweepDirection === "CW");
72279
+ return pcb_silkscreen_path.parse({
72280
+ type: "pcb_silkscreen_path",
72281
+ pcb_silkscreen_path_id: `pcb_silkscreen_arc_${index + 1}`,
72282
+ pcb_component_id: "pcb_component_1",
72283
+ layer: "top",
72284
+ route: arcPath.map((p) => ({
72285
+ x: milx10(p.x),
72286
+ y: milx10(p.y)
72287
+ })),
72288
+ stroke_width: mil10ToMm(arc.width)
72289
+ });
72290
+ };
72291
+ var handleHole = (hole, index) => {
72292
+ return pcb_hole.parse({
72293
+ type: "pcb_hole",
72294
+ x: milx10(hole.center.x),
72295
+ y: milx10(hole.center.y),
72296
+ hole_diameter: milx10(hole.radius) * 2,
72297
+ hole_shape: "circle",
72298
+ pcb_hole_id: `pcb_hole_${index + 1}`
72299
+ });
72300
+ };
72301
+ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, { useModelCdn, shouldRecenter = true } = {}) => {
72302
+ const soupElements = [];
72303
+ const centerOffset = computeCenterOffset(easyEdaJson);
72304
+ const source_component = any_source_component.parse({
72305
+ type: "source_component",
72306
+ source_component_id: "source_component_1",
72307
+ name: "U1",
72308
+ ftype: "simple_bug"
72309
+ });
72310
+ const pcb_component2 = pcb_component.parse({
72311
+ type: "pcb_component",
72312
+ pcb_component_id: "pcb_component_1",
72313
+ source_component_id: "source_component_1",
72314
+ name: "U1",
72315
+ ftype: "simple_bug",
72316
+ width: 0,
72317
+ height: 0,
72318
+ rotation: 0,
72319
+ center: { x: 0, y: 0 },
72320
+ layer: "top"
72321
+ });
72322
+ soupElements.push(source_component, pcb_component2);
72323
+ const pads = easyEdaJson.packageDetail.dataStr.shape.filter((shape) => shape.type === "PAD");
72324
+ const pins = easyEdaJson.dataStr.shape.filter((shape) => shape.type === "PIN");
72325
+ const pinLabelSets = pads.map((pad) => {
72326
+ const labels = [];
72327
+ if (pad.number)
72328
+ labels.push(pad.number.toString());
72329
+ const pin = pins.find((p) => p.pinNumber === pad.number);
72330
+ if (pin)
72331
+ labels.push(pin.label);
72332
+ return labels;
72333
+ });
72334
+ const normalizedPinLabels = normalizePinLabels(pinLabelSets);
72335
+ pads.forEach((pad, index) => {
72336
+ const portHints = normalizedPinLabels[index];
72337
+ const pinNumber = Number.parseInt(portHints.find((hint) => hint.match(/pin\d+/)).replace("pin", ""));
72338
+ soupElements.push({
72339
+ type: "source_port",
72340
+ source_port_id: `source_port_${index + 1}`,
72341
+ source_component_id: "source_component_1",
72342
+ name: `pin${pinNumber}`,
72343
+ pin_number: pinNumber,
72344
+ port_hints: portHints.filter((hint) => hint !== `pin${pinNumber}`)
72345
+ });
72346
+ if (pad.holeRadius !== undefined && mil2mm(pad.holeRadius) !== 0) {
72347
+ const commonPlatedHoleProps = {
72348
+ type: "pcb_plated_hole",
72349
+ pcb_plated_hole_id: `pcb_plated_hole_${index + 1}`,
72350
+ x: mil2mm(pad.center.x),
72351
+ y: mil2mm(pad.center.y),
72352
+ layers: ["top"],
72353
+ port_hints: [`pin${pinNumber}`],
72354
+ pcb_component_id: "pcb_component_1",
72355
+ pcb_port_id: `pcb_port_${index + 1}`
72356
+ };
72357
+ let additionalPlatedHoleProps;
72358
+ if (pad.shape === "OVAL") {
72359
+ const largestOuterDimensionName = mil2mm(pad.width) > mil2mm(pad.height) ? "width" : "height";
72360
+ const smallestOuterDimension = Math.min(mil2mm(pad.width), mil2mm(pad.height));
72361
+ const largestOuterDimension = Math.max(mil2mm(pad.width), mil2mm(pad.height));
72362
+ const distanceFromOuterPlatingToHole = smallestOuterDimension / 2 - mil2mm(pad.holeRadius);
72363
+ const largestInnerDimension = largestOuterDimension - distanceFromOuterPlatingToHole * 2;
72364
+ const smallestInnerDimension = mil2mm(pad.holeRadius) * 2;
72365
+ const innerWidth = largestOuterDimensionName === "width" ? largestInnerDimension : smallestInnerDimension;
72366
+ const innerHeight = largestOuterDimensionName === "height" ? largestInnerDimension : smallestInnerDimension;
72367
+ additionalPlatedHoleProps = {
72368
+ shape: "pill",
72369
+ outer_width: mil2mm(pad.width),
72370
+ outer_height: mil2mm(pad.height),
72371
+ hole_width: innerWidth,
72372
+ hole_height: innerHeight
72373
+ };
72374
+ } else {
72375
+ additionalPlatedHoleProps = {
72376
+ shape: "circle",
72377
+ hole_diameter: mil2mm(pad.holeRadius) * 2,
72378
+ outer_diameter: mil2mm(pad.width),
72379
+ radius: mil2mm(pad.holeRadius)
72380
+ };
72381
+ }
72382
+ soupElements.push(pcb_plated_hole.parse({
72383
+ ...commonPlatedHoleProps,
72384
+ ...additionalPlatedHoleProps
72385
+ }));
72386
+ } else {
72387
+ let soupShape;
72388
+ if (pad.shape === "RECT") {
72389
+ soupShape = "rect";
72390
+ } else if (pad.shape === "ELLIPSE") {
72391
+ soupShape = "rect";
72392
+ } else if (pad.shape === "OVAL") {
72393
+ soupShape = "rect";
72394
+ }
72395
+ if (!soupShape) {
72396
+ throw new Error(`unknown pad.shape: "${pad.shape}"`);
72397
+ }
72398
+ const rectSize = { width: mil2mm(pad.width), height: mil2mm(pad.height) };
72399
+ if (pad.rotation === 90 || pad.rotation === 270) {
72400
+ rectSize.width = mil2mm(pad.height);
72401
+ rectSize.height = mil2mm(pad.width);
72402
+ }
72403
+ const parsedPcbSmtpad = pcb_smtpad.parse({
72404
+ type: "pcb_smtpad",
72405
+ pcb_smtpad_id: `pcb_smtpad_${index + 1}`,
72406
+ shape: soupShape,
72407
+ x: mil2mm(pad.center.x),
72408
+ y: mil2mm(pad.center.y),
72409
+ ...soupShape === "rect" ? rectSize : { radius: Math.min(mil2mm(pad.width), mil2mm(pad.height)) / 2 },
72410
+ layer: "top",
72411
+ port_hints: [`pin${pinNumber}`],
72412
+ pcb_component_id: "pcb_component_1",
72413
+ pcb_port_id: `pcb_port_${index + 1}`
72414
+ });
72415
+ soupElements.push(parsedPcbSmtpad);
72416
+ }
72417
+ });
72418
+ easyEdaJson.packageDetail.dataStr.shape.filter((shape) => shape.type === "HOLE").forEach((h, index) => {
72419
+ soupElements.push(handleHole(h, index));
72420
+ });
72421
+ easyEdaJson.packageDetail.dataStr.shape.forEach((shape, index) => {
72422
+ if (shape.type === "TRACK") {
72423
+ soupElements.push(handleSilkscreenPath(shape, index));
72424
+ } else if (shape.type === "ARC") {
72425
+ soupElements.push(handleSilkscreenArc(shape, index));
72426
+ } else if (shape.type === "TEXT") {
72427
+ soupElements.push(pcb_silkscreen_text.parse({
72428
+ type: "pcb_silkscreen_text",
72429
+ pcb_silkscreen_text_id: `pcb_silkscreen_text_${index + 1}`,
72430
+ pcb_component_id: "pcb_component_1",
72431
+ text: shape.text,
72432
+ anchor_position: {
72433
+ x: mil2mm(shape.x),
72434
+ y: mil2mm(shape.y)
72435
+ },
72436
+ anchor_alignment: {
72437
+ L: "bottom_left",
72438
+ C: "center",
72439
+ R: "bottom_right"
72440
+ }[shape.textAnchor ?? "L"],
72441
+ font_size: shape.size_mm ? shape.size_mm : undefined,
72442
+ layer: "top"
72443
+ }));
72444
+ }
72445
+ });
72446
+ const svgNode = easyEdaJson.packageDetail.dataStr.shape.find((a) => Boolean(a.type === "SVGNODE" && a.svgData.attrs?.uuid));
72447
+ const objFileUuid = svgNode?.svgData?.attrs?.uuid;
72448
+ const objFileUrl = objFileUuid ? useModelCdn ? `https://modelcdn.tscircuit.com/easyeda_models/download?uuid=${objFileUuid}&pn=${easyEdaJson.lcsc.number}` : `https://modules.easyeda.com/3dmodel/${objFileUuid}` : undefined;
72449
+ if (objFileUrl !== undefined) {
72450
+ const [rx, ry, rz] = (svgNode?.svgData.attrs?.c_rotation ?? "0,0,0").split(",").map(Number);
72451
+ soupElements.push(cad_component.parse({
72452
+ type: "cad_component",
72453
+ cad_component_id: "cad_component_1",
72454
+ source_component_id: "source_component_1",
72455
+ pcb_component_id: "pcb_component_1",
72456
+ position: { x: 0, y: 0, z: 0 },
72457
+ rotation: { x: rx, y: ry, z: rz },
72458
+ model_obj_url: objFileUrl
72459
+ }));
72460
+ }
72461
+ if (shouldRecenter) {
72462
+ const bounds = findBoundsAndCenter(soupElements.filter((e) => e.type !== "pcb_component"));
72463
+ transformPCBElements(soupElements, compose(translate(-bounds.center.x, bounds.center.y), scale6(1, -1)));
72464
+ pcb_component2.center = { x: 0, y: 0 };
72465
+ }
72466
+ return soupElements;
72467
+ };
72468
+ function normalizeManufacturerPartNumber(partNumber) {
72469
+ let normalized = partNumber.replace(/[-]/g, "_").replace(/[^a-zA-Z0-9_$]/g, "_");
72470
+ if (/^\d/.test(normalized)) {
72471
+ normalized = "A_" + normalized;
72472
+ }
72473
+ return normalized;
72474
+ }
72475
+ var convertRawEasyToTsx = async (rawEasy) => {
72476
+ const betterEasy = EasyEdaJsonSchema.parse(rawEasy);
72477
+ const result = await convertBetterEasyToTsx({
72478
+ betterEasy
72479
+ });
72480
+ return result;
72481
+ };
72482
+ var convertBetterEasyToTsx = async ({
72483
+ betterEasy
72484
+ }) => {
72485
+ const circuitJson = convertEasyEdaJsonToCircuitJson(betterEasy, {
72486
+ useModelCdn: true,
72487
+ shouldRecenter: true
72488
+ });
72489
+ const rawPn = betterEasy.dataStr.head.c_para["Manufacturer Part"];
72490
+ const pn = normalizeManufacturerPartNumber(rawPn);
72491
+ const sourcePorts = su_default2(circuitJson).source_port.list();
72492
+ const pinLabels = {};
72493
+ const sortedPorts = sourcePorts.sort((a, b) => {
72494
+ const aNum = parseInt(a.name.replace("pin", ""));
72495
+ const bNum = parseInt(b.name.replace("pin", ""));
72496
+ return aNum - bNum;
72497
+ });
72498
+ for (const sourcePort of sortedPorts) {
72499
+ pinLabels[sourcePort.name] = [
72500
+ sourcePort.name,
72501
+ ...sourcePort.port_hints ?? []
72502
+ ];
72503
+ }
72504
+ const [cadComponent] = su_default2(circuitJson).cad_component.list();
72505
+ let modelObjUrl;
72506
+ if (cadComponent?.model_obj_url) {
72507
+ const isValidUrl = await checkModelObjUrlValidity(cadComponent.model_obj_url);
72508
+ if (isValidUrl) {
72509
+ modelObjUrl = cadComponent.model_obj_url;
72510
+ }
72511
+ }
72512
+ const supplierPartNumbers = {
72513
+ jlcpcb: [betterEasy.lcsc.number]
72514
+ };
72515
+ return generateTypescriptComponent({
72516
+ componentName: pn,
72517
+ manufacturerPartNumber: pn,
72518
+ pinLabels,
72519
+ objUrl: modelObjUrl,
72520
+ circuitJson,
72521
+ supplierPartNumbers
72522
+ });
72523
+ };
72524
+ var checkModelObjUrlValidity = async (url) => {
72525
+ try {
72526
+ const response = await fetch(url, { method: "HEAD" });
72527
+ return response.status === 200;
72528
+ } catch (error) {
72529
+ console.error(`Error checking model object URL ${url}:`, error);
72530
+ return false;
72531
+ }
72532
+ };
72533
+ async function fetchEasyEDAComponent(jlcpcbPartNumber, { fetch: fetch2 = globalThis.fetch } = {}) {
72534
+ const searchUrl = "https://easyeda.com/api/components/search";
72535
+ const componentUrl = (uuid) => `https://easyeda.com/api/components/${uuid}?version=6.4.7&uuid=${uuid}&datastrid=`;
72536
+ const searchHeaders = {
72537
+ authority: "easyeda.com",
72538
+ pragma: "no-cache",
72539
+ "cache-control": "no-cache",
72540
+ accept: "application/json, text/javascript, */*; q=0.01",
72541
+ "x-requested-with": "XMLHttpRequest",
72542
+ "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
72543
+ "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
72544
+ origin: "https://easyeda.com",
72545
+ "sec-fetch-site": "same-origin",
72546
+ "sec-fetch-mode": "cors",
72547
+ "sec-fetch-dest": "empty",
72548
+ referer: "https://easyeda.com/editor",
72549
+ "accept-language": "cs,en;q=0.9,sk;q=0.8,en-GB;q=0.7",
72550
+ cookie: "<PUT your cookies here>"
72551
+ };
72552
+ const searchData = `type=3&doctype%5B%5D=2&uid=0819f05c4eef4c71ace90d822a990e87&returnListStyle=classifyarr&wd=${jlcpcbPartNumber}&version=6.4.7`;
72553
+ const searchResponse = await fetch2(searchUrl, {
72554
+ method: "POST",
72555
+ headers: searchHeaders,
72556
+ body: searchData
72557
+ });
72558
+ if (!searchResponse.ok) {
72559
+ throw new Error("Failed to search for the component");
72560
+ }
72561
+ const searchResult = await searchResponse.json();
72562
+ if (!searchResult.success || !searchResult.result.lists.lcsc.length) {
72563
+ throw new Error("Component not found");
72564
+ }
72565
+ const bestMatchComponent = searchResult.result.lists.lcsc.find((component) => component.dataStr.head.c_para["Supplier Part"] === jlcpcbPartNumber) ?? searchResult.result.lists.lcsc[0];
72566
+ const componentUUID = bestMatchComponent.uuid;
72567
+ const componentResponse = await fetch2(componentUrl(componentUUID), {
72568
+ method: "GET",
72569
+ headers: {
72570
+ ...searchHeaders,
72571
+ referer: `https://easyeda.com/editor?uuid=${componentUUID}`
72572
+ }
72573
+ });
72574
+ if (!componentResponse.ok) {
72575
+ throw new Error("Failed to fetch the component details");
72576
+ }
72577
+ const componentResult = await componentResponse.json();
72578
+ return componentResult.result;
72579
+ }
72580
+
72581
+ // lib/import/import-component-from-jlcpcb.ts
72582
+ import fs23 from "node:fs/promises";
72583
+ import path23 from "node:path";
72584
+ var importComponentFromJlcpcb = async (jlcpcbPartNumber, projectDir = process.cwd()) => {
72585
+ const component = await fetchEasyEDAComponent(jlcpcbPartNumber);
72586
+ const tsx = await convertRawEasyToTsx(component);
72587
+ const fileName = tsx.match(/export const (\w+) = .*/)?.[1];
72588
+ if (!fileName) {
72589
+ throw new Error("Could not determine file name of converted component");
72590
+ }
72591
+ const importsDir = path23.join(projectDir, "imports");
72592
+ await fs23.mkdir(importsDir, { recursive: true });
72593
+ const filePath = path23.join(importsDir, `${fileName}.tsx`);
72594
+ await fs23.writeFile(filePath, tsx);
72595
+ return { filePath };
72596
+ };
72597
+
72598
+ // cli/import/register.ts
72599
+ var registerImport = (program3) => {
72600
+ program3.command("import").description("Search JLCPCB or the tscircuit registry and import a component").argument("<query>", "Chip name, part number, or package name").action(async (query) => {
72601
+ const ky2 = getRegistryApiKy();
72602
+ let registryResults = [];
72603
+ let jlcResults = [];
72604
+ try {
72605
+ registryResults = (await ky2.post("packages/search", { json: { query } }).json()).packages;
72606
+ } catch (error) {
72607
+ console.error(kleur_default.red("Failed to search registry:"), error instanceof Error ? error.message : error);
72608
+ }
72609
+ try {
72610
+ const searchUrl = "https://jlcsearch.tscircuit.com/api/search?limit=10&q=" + encodeURIComponent(query);
72611
+ const resp = await fetch(searchUrl).then((r) => r.json());
72612
+ jlcResults = resp.components;
72613
+ } catch (error) {
72614
+ console.error(kleur_default.red("Failed to search JLCPCB:"), error instanceof Error ? error.message : error);
72615
+ }
72616
+ if (!registryResults.length && !jlcResults.length) {
72617
+ console.log(kleur_default.yellow("No results found matching your query."));
69604
72618
  return;
69605
72619
  }
69606
- const { confirm } = await import_prompts5.default({
69607
- type: "confirm",
69608
- name: "confirm",
69609
- message: `Do you want to add ${kleur_default.green(selectedPackage)}?`,
69610
- initial: true
72620
+ const choices = [];
72621
+ registryResults.forEach((pkg, idx) => {
72622
+ choices.push({
72623
+ title: `${pkg.name}${pkg.description ? ` - ${pkg.description}` : ""}`,
72624
+ value: { type: "registry", name: pkg.name },
72625
+ selected: idx === 0
72626
+ });
72627
+ });
72628
+ jlcResults.forEach((comp, idx) => {
72629
+ choices.push({
72630
+ title: `[jlcpcb] ${comp.mfr} (C${comp.lcsc}) - ${comp.description}`,
72631
+ value: { type: "jlcpcb", part: comp.lcsc },
72632
+ selected: !choices.length && idx === 0
72633
+ });
69611
72634
  });
69612
- if (confirm) {
72635
+ const { choice } = await prompts({
72636
+ type: "select",
72637
+ name: "choice",
72638
+ message: "Select a part to import",
72639
+ choices
72640
+ });
72641
+ if (!choice) {
72642
+ console.log("Aborted.");
72643
+ return process.exit(0);
72644
+ }
72645
+ if (choice.type === "registry") {
69613
72646
  try {
69614
- console.log(kleur_default.blue(`Installing ${selectedPackage}...`));
69615
- await addPackage(selectedPackage);
69616
- console.log(kleur_default.green(`Successfully installed ${selectedPackage}`));
72647
+ await addPackage(choice.name);
72648
+ console.log(kleur_default.green(`Installed ${choice.name}`));
69617
72649
  } catch (error) {
69618
- console.error(kleur_default.red(`Failed to install ${selectedPackage}:`), error);
69619
- process.exit(1);
72650
+ console.error(kleur_default.red("Failed to add package:"), error instanceof Error ? error.message : error);
72651
+ return process.exit(1);
72652
+ }
72653
+ } else {
72654
+ try {
72655
+ console.log(kleur_default.yellow(`Importing "C${choice.part}" from JLCPCB...`));
72656
+ const { filePath } = await importComponentFromJlcpcb(`C${String(choice.part)}`);
72657
+ console.log(kleur_default.green(`Imported ${filePath}`));
72658
+ } catch (error) {
72659
+ console.error(kleur_default.red("Failed to import part:"), error instanceof Error ? error.message : error);
72660
+ return process.exit(1);
69620
72661
  }
69621
72662
  }
69622
72663
  });
@@ -69651,12 +72692,12 @@ var registerRemove = (program3) => {
69651
72692
  };
69652
72693
 
69653
72694
  // cli/build/register.ts
69654
- import path25 from "node:path";
69655
- import fs25 from "node:fs";
72695
+ import path26 from "node:path";
72696
+ import fs26 from "node:fs";
69656
72697
 
69657
72698
  // cli/build/build-file.ts
69658
- import path23 from "node:path";
69659
- import fs23 from "node:fs";
72699
+ import path24 from "node:path";
72700
+ import fs24 from "node:fs";
69660
72701
 
69661
72702
  // lib/shared/circuit-json-diagnostics.ts
69662
72703
  function analyzeCircuitJson(circuitJson) {
@@ -69687,9 +72728,9 @@ var buildFile = async (input, output, projectDir, options) => {
69687
72728
  filePath: input,
69688
72729
  platformConfig: options?.platformConfig
69689
72730
  });
69690
- fs23.mkdirSync(path23.dirname(output), { recursive: true });
69691
- fs23.writeFileSync(output, JSON.stringify(result.circuitJson, null, 2));
69692
- console.log(`Circuit JSON written to ${path23.relative(projectDir, output)}`);
72731
+ fs24.mkdirSync(path24.dirname(output), { recursive: true });
72732
+ fs24.writeFileSync(output, JSON.stringify(result.circuitJson, null, 2));
72733
+ console.log(`Circuit JSON written to ${path24.relative(projectDir, output)}`);
69693
72734
  const { errors, warnings } = analyzeCircuitJson(result.circuitJson);
69694
72735
  if (!options?.ignoreWarnings) {
69695
72736
  for (const warn of warnings) {
@@ -69717,16 +72758,16 @@ var buildFile = async (input, output, projectDir, options) => {
69717
72758
  };
69718
72759
 
69719
72760
  // cli/build/get-build-entrypoints.ts
69720
- import fs24 from "node:fs";
69721
- import path24 from "node:path";
72761
+ import fs25 from "node:fs";
72762
+ import path25 from "node:path";
69722
72763
  async function getBuildEntrypoints({
69723
72764
  fileOrDir,
69724
72765
  rootDir = process.cwd()
69725
72766
  }) {
69726
- const resolvedRoot = path24.resolve(rootDir);
72767
+ const resolvedRoot = path25.resolve(rootDir);
69727
72768
  if (fileOrDir) {
69728
- const resolved = path24.resolve(resolvedRoot, fileOrDir);
69729
- if (fs24.existsSync(resolved) && fs24.statSync(resolved).isDirectory()) {
72769
+ const resolved = path25.resolve(resolvedRoot, fileOrDir);
72770
+ if (fs25.existsSync(resolved) && fs25.statSync(resolved).isDirectory()) {
69730
72771
  const projectDir2 = resolved;
69731
72772
  const files2 = globbySync(["**/*.board.tsx", "**/*.circuit.tsx"], {
69732
72773
  cwd: projectDir2,
@@ -69734,10 +72775,10 @@ async function getBuildEntrypoints({
69734
72775
  });
69735
72776
  return {
69736
72777
  projectDir: projectDir2,
69737
- circuitFiles: files2.map((f) => path24.join(projectDir2, f))
72778
+ circuitFiles: files2.map((f) => path25.join(projectDir2, f))
69738
72779
  };
69739
72780
  }
69740
- return { projectDir: path24.dirname(resolved), circuitFiles: [resolved] };
72781
+ return { projectDir: path25.dirname(resolved), circuitFiles: [resolved] };
69741
72782
  }
69742
72783
  const projectDir = resolvedRoot;
69743
72784
  const files = globbySync(["**/*.board.tsx", "**/*.circuit.tsx"], {
@@ -69746,7 +72787,7 @@ async function getBuildEntrypoints({
69746
72787
  });
69747
72788
  return {
69748
72789
  projectDir,
69749
- circuitFiles: files.map((f) => path24.join(projectDir, f))
72790
+ circuitFiles: files.map((f) => path25.join(projectDir, f))
69750
72791
  };
69751
72792
  }
69752
72793
 
@@ -69754,13 +72795,13 @@ async function getBuildEntrypoints({
69754
72795
  var registerBuild = (program3) => {
69755
72796
  program3.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ignore-errors", "Do not exit with code 1 on errors").option("--ignore-warnings", "Do not log warnings").option("--disable-pcb", "Disable PCB outputs").action(async (file, options) => {
69756
72797
  const { projectDir, mainEntrypoint, circuitFiles } = await getBuildEntrypoints({ fileOrDir: file });
69757
- const distDir = path25.join(projectDir, "dist");
69758
- fs25.mkdirSync(distDir, { recursive: true });
72798
+ const distDir = path26.join(projectDir, "dist");
72799
+ fs26.mkdirSync(distDir, { recursive: true });
69759
72800
  let hasErrors = false;
69760
72801
  for (const filePath of circuitFiles) {
69761
- const relative8 = path25.relative(projectDir, filePath);
72802
+ const relative8 = path26.relative(projectDir, filePath);
69762
72803
  const outputDirName = relative8.replace(/(\.board|\.circuit)?\.tsx$/, "");
69763
- const outputPath = path25.join(distDir, outputDirName, "circuit.json");
72804
+ const outputPath = path26.join(distDir, outputDirName, "circuit.json");
69764
72805
  const ok = await buildFile(filePath, outputPath, projectDir, options);
69765
72806
  if (!ok)
69766
72807
  hasErrors = true;
@@ -69772,8 +72813,8 @@ var registerBuild = (program3) => {
69772
72813
  };
69773
72814
 
69774
72815
  // lib/shared/snapshot-project.ts
69775
- import fs26 from "node:fs";
69776
- import path26 from "node:path";
72816
+ import fs27 from "node:fs";
72817
+ import path27 from "node:path";
69777
72818
  import looksSame from "looks-same";
69778
72819
  import {
69779
72820
  convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg2,
@@ -69797,10 +72838,10 @@ var snapshotProject = async ({
69797
72838
  ...DEFAULT_IGNORED_PATTERNS,
69798
72839
  ...ignored.map(normalizeIgnorePattern)
69799
72840
  ];
69800
- const boardFiles = filePaths.length > 0 ? filePaths.map((f) => path26.resolve(projectDir, f)) : globbySync(["**/*.board.tsx", "**/*.circuit.tsx"], {
72841
+ const boardFiles = filePaths.length > 0 ? filePaths.map((f) => path27.resolve(projectDir, f)) : globbySync(["**/*.board.tsx", "**/*.circuit.tsx"], {
69801
72842
  cwd: projectDir,
69802
72843
  ignore
69803
- }).map((f) => path26.join(projectDir, f));
72844
+ }).map((f) => path27.join(projectDir, f));
69804
72845
  if (boardFiles.length === 0) {
69805
72846
  console.log("No entrypoint found. Run 'tsci init' to bootstrap a project or specify a file with 'tsci snapshot <file>'");
69806
72847
  return onExit(0);
@@ -69812,30 +72853,30 @@ var snapshotProject = async ({
69812
72853
  const pcbSvg = convertCircuitJsonToPcbSvg2(circuitJson);
69813
72854
  const schSvg = convertCircuitJsonToSchematicSvg2(circuitJson);
69814
72855
  const svg3d = threeD ? await convertCircuitJsonToSimple3dSvg(circuitJson) : null;
69815
- const snapDir = path26.join(path26.dirname(file), "__snapshots__");
69816
- fs26.mkdirSync(snapDir, { recursive: true });
69817
- const base = path26.basename(file).replace(/\.tsx$/, "");
69818
- const pairs = [];
72856
+ const snapDir = path27.join(path27.dirname(file), "__snapshots__");
72857
+ fs27.mkdirSync(snapDir, { recursive: true });
72858
+ const base = path27.basename(file).replace(/\.tsx$/, "");
72859
+ const pairs2 = [];
69819
72860
  if (pcbOnly || !schematicOnly)
69820
- pairs.push(["pcb", pcbSvg]);
72861
+ pairs2.push(["pcb", pcbSvg]);
69821
72862
  if (schematicOnly || !pcbOnly)
69822
- pairs.push(["schematic", schSvg]);
72863
+ pairs2.push(["schematic", schSvg]);
69823
72864
  if (threeD && svg3d)
69824
- pairs.push(["3d", svg3d]);
72865
+ pairs2.push(["3d", svg3d]);
69825
72866
  if (!looksSame) {
69826
72867
  console.error("looks-same is required. Install it with 'bun add -d looks-same'");
69827
72868
  return onExit(1);
69828
72869
  }
69829
- for (const [type, newSvg] of pairs) {
69830
- const snapPath = path26.join(snapDir, `${base}-${type}.snap.svg`);
69831
- const existing = fs26.existsSync(snapPath);
72870
+ for (const [type, newSvg] of pairs2) {
72871
+ const snapPath = path27.join(snapDir, `${base}-${type}.snap.svg`);
72872
+ const existing = fs27.existsSync(snapPath);
69832
72873
  if (!existing) {
69833
- fs26.writeFileSync(snapPath, newSvg, "utf8");
69834
- console.log("✅", kleur_default.gray(path26.relative(projectDir, snapPath)));
72874
+ fs27.writeFileSync(snapPath, newSvg, "utf8");
72875
+ console.log("✅", kleur_default.gray(path27.relative(projectDir, snapPath)));
69835
72876
  didUpdate = true;
69836
72877
  continue;
69837
72878
  }
69838
- const oldSvg = fs26.readFileSync(snapPath, "utf8");
72879
+ const oldSvg = fs27.readFileSync(snapPath, "utf8");
69839
72880
  const bufNew = Buffer.from(newSvg, "utf8");
69840
72881
  const bufOld = Buffer.from(oldSvg, "utf8");
69841
72882
  const { equal } = await looksSame(bufNew, bufOld, {
@@ -69844,10 +72885,10 @@ var snapshotProject = async ({
69844
72885
  });
69845
72886
  if (update) {
69846
72887
  if (!forceUpdate && equal) {
69847
- console.log("✅", kleur_default.gray(path26.relative(projectDir, snapPath)));
72888
+ console.log("✅", kleur_default.gray(path27.relative(projectDir, snapPath)));
69848
72889
  } else {
69849
- fs26.writeFileSync(snapPath, newSvg, "utf8");
69850
- console.log("✅", kleur_default.gray(path26.relative(projectDir, snapPath)));
72890
+ fs27.writeFileSync(snapPath, newSvg, "utf8");
72891
+ console.log("✅", kleur_default.gray(path27.relative(projectDir, snapPath)));
69851
72892
  didUpdate = true;
69852
72893
  }
69853
72894
  } else if (!equal) {
@@ -69858,10 +72899,10 @@ var snapshotProject = async ({
69858
72899
  highlightColor: "#ff00ff",
69859
72900
  tolerance: 2
69860
72901
  });
69861
- fs26.writeFileSync(diffPath, diffBuffer);
72902
+ fs27.writeFileSync(diffPath, diffBuffer);
69862
72903
  mismatches.push(`${snapPath} (diff: ${diffPath})`);
69863
72904
  } else {
69864
- console.log("✅", kleur_default.gray(path26.relative(projectDir, snapPath)));
72905
+ console.log("✅", kleur_default.gray(path27.relative(projectDir, snapPath)));
69865
72906
  }
69866
72907
  }
69867
72908
  }
@@ -69899,22 +72940,22 @@ var registerSnapshot = (program3) => {
69899
72940
  };
69900
72941
 
69901
72942
  // lib/shared/setup-github-actions.ts
69902
- import fs27 from "node:fs";
69903
- import path27 from "node:path";
72943
+ import fs28 from "node:fs";
72944
+ import path28 from "node:path";
69904
72945
  var setupGithubActions = (projectDir = process.cwd()) => {
69905
72946
  const findGitRoot = (startDir) => {
69906
- let dir = path27.resolve(startDir);
69907
- while (dir !== path27.parse(dir).root) {
69908
- if (fs27.existsSync(path27.join(dir, ".git"))) {
72947
+ let dir = path28.resolve(startDir);
72948
+ while (dir !== path28.parse(dir).root) {
72949
+ if (fs28.existsSync(path28.join(dir, ".git"))) {
69909
72950
  return dir;
69910
72951
  }
69911
- dir = path27.dirname(dir);
72952
+ dir = path28.dirname(dir);
69912
72953
  }
69913
72954
  return null;
69914
72955
  };
69915
72956
  const gitRoot = findGitRoot(projectDir) ?? projectDir;
69916
- const workflowsDir = path27.join(gitRoot, ".github", "workflows");
69917
- fs27.mkdirSync(workflowsDir, { recursive: true });
72957
+ const workflowsDir = path28.join(gitRoot, ".github", "workflows");
72958
+ fs28.mkdirSync(workflowsDir, { recursive: true });
69918
72959
  const buildWorkflow = `name: tscircuit Build
69919
72960
 
69920
72961
  on:
@@ -69953,8 +72994,8 @@ jobs:
69953
72994
  - run: bun install
69954
72995
  - run: bunx tsci snapshot
69955
72996
  `;
69956
- writeFileIfNotExists(path27.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
69957
- writeFileIfNotExists(path27.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
72997
+ writeFileIfNotExists(path28.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
72998
+ writeFileIfNotExists(path28.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
69958
72999
  };
69959
73000
 
69960
73001
  // cli/setup/register.ts
@@ -70002,6 +73043,7 @@ registerSnapshot(program2);
70002
73043
  registerSetup(program2);
70003
73044
  registerUpgradeCommand(program2);
70004
73045
  registerSearch(program2);
73046
+ registerImport(program2);
70005
73047
  if (process.argv.includes("--version") || process.argv.includes("-v") || process.argv.includes("-V")) {
70006
73048
  console.log(getVersion());
70007
73049
  process.exit(0);