@tscircuit/core 0.0.105 → 0.0.107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ReactElement } from 'react';
1
+ import React, { ReactElement } from 'react';
2
2
  import * as zod from 'zod';
3
3
  import { ZodType, z } from 'zod';
4
4
  import { SchSymbol, BaseSymbolName } from 'schematic-symbols';
@@ -6,7 +6,7 @@ import { PcbTraceError, PcbPlacementError, LayerRef, AnyCircuitElement, AnySourc
6
6
  import { SoupUtilObjects } from '@tscircuit/soup-util';
7
7
  import { Matrix } from 'transformation-matrix';
8
8
  import * as Props from '@tscircuit/props';
9
- import { traceProps, groupProps, boardProps, footprintProps, smtPadProps, resistorProps, ledProps, diodeProps, capacitorProps, traceHintProps, chipProps, jumperProps, silkscreenPathProps, platedHoleProps, constraintProps, holeProps, silkscreenTextProps, pcbKeepoutProps, fabricationNoteTextProps, fabricationNotePathProps } from '@tscircuit/props';
9
+ import { traceProps, groupProps, boardProps, footprintProps, smtPadProps, resistorProps, ledProps, diodeProps, capacitorProps, traceHintProps, chipProps, jumperProps, silkscreenPathProps, platedHoleProps, constraintProps, holeProps, silkscreenTextProps, pcbKeepoutProps, fabricationNoteTextProps, fabricationNotePathProps, viaProps } from '@tscircuit/props';
10
10
 
11
11
  declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InitializePortsFromChildren", "CreateNetsFromProps", "CreateTracesFromProps", "CreateTraceHintsFromProps", "SourceRender", "SourceParentAttachment", "PortDiscovery", "PortMatching", "SourceTraceRender", "SchematicComponentRender", "SchematicLayout", "SchematicPortRender", "SchematicTraceRender", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbLayout", "PcbTraceRender", "PcbTraceHintRender", "PcbRouteNetIslands", "PcbComponentSizeCalculation", "CadModelRender"];
12
12
  type RenderPhase = (typeof orderedRenderPhases)[number];
@@ -73,6 +73,7 @@ declare class Circuit {
73
73
  render(): void;
74
74
  getSoup(): AnyCircuitElement[];
75
75
  getCircuitJson(): AnyCircuitElement[];
76
+ toJson(): AnyCircuitElement[];
76
77
  getSvg(options: {
77
78
  view: "pcb";
78
79
  layer?: string;
@@ -4598,6 +4599,117 @@ declare class FabricationNotePath extends PrimitiveComponent<typeof fabricationN
4598
4599
  doInitialPcbPrimitiveRender(): void;
4599
4600
  }
4600
4601
 
4602
+ declare class Via extends PrimitiveComponent<typeof viaProps> {
4603
+ pcb_via_id: string | null;
4604
+ matchedPort: Port | null;
4605
+ isPcbPrimitive: boolean;
4606
+ get config(): {
4607
+ componentName: string;
4608
+ zodProps: zod.ZodObject<zod.objectUtil.extendShape<{
4609
+ pcbX: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
4610
+ pcbY: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
4611
+ pcbRotation: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
4612
+ schX: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
4613
+ schY: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
4614
+ schRotation: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
4615
+ layer: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodEnum<["top", "bottom", "inner1", "inner2", "inner3", "inner4", "inner5", "inner6"]>, zod.ZodObject<{
4616
+ name: zod.ZodEnum<["top", "bottom", "inner1", "inner2", "inner3", "inner4", "inner5", "inner6"]>;
4617
+ }, "strip", zod.ZodTypeAny, {
4618
+ name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4619
+ }, {
4620
+ name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4621
+ }>]>, "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6", "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | {
4622
+ name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4623
+ }>>;
4624
+ footprint: zod.ZodOptional<zod.ZodType<Props.Footprint, zod.ZodTypeDef, Props.Footprint>>;
4625
+ }, {
4626
+ fromLayer: zod.ZodEffects<zod.ZodUnion<[zod.ZodEnum<["top", "bottom", "inner1", "inner2", "inner3", "inner4", "inner5", "inner6"]>, zod.ZodObject<{
4627
+ name: zod.ZodEnum<["top", "bottom", "inner1", "inner2", "inner3", "inner4", "inner5", "inner6"]>;
4628
+ }, "strip", zod.ZodTypeAny, {
4629
+ name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4630
+ }, {
4631
+ name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4632
+ }>]>, "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6", "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | {
4633
+ name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4634
+ }>;
4635
+ toLayer: zod.ZodEffects<zod.ZodUnion<[zod.ZodEnum<["top", "bottom", "inner1", "inner2", "inner3", "inner4", "inner5", "inner6"]>, zod.ZodObject<{
4636
+ name: zod.ZodEnum<["top", "bottom", "inner1", "inner2", "inner3", "inner4", "inner5", "inner6"]>;
4637
+ }, "strip", zod.ZodTypeAny, {
4638
+ name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4639
+ }, {
4640
+ name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4641
+ }>]>, "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6", "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | {
4642
+ name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4643
+ }>;
4644
+ holeDiameter: zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>;
4645
+ outerDiameter: zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>;
4646
+ }>, "strip", zod.ZodTypeAny, {
4647
+ fromLayer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4648
+ toLayer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4649
+ holeDiameter: number;
4650
+ outerDiameter: number;
4651
+ pcbX?: number | undefined;
4652
+ pcbY?: number | undefined;
4653
+ pcbRotation?: number | undefined;
4654
+ schX?: number | undefined;
4655
+ schY?: number | undefined;
4656
+ schRotation?: number | undefined;
4657
+ layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | undefined;
4658
+ footprint?: Props.Footprint | undefined;
4659
+ }, {
4660
+ fromLayer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | {
4661
+ name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4662
+ };
4663
+ toLayer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | {
4664
+ name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4665
+ };
4666
+ holeDiameter: string | number;
4667
+ outerDiameter: string | number;
4668
+ pcbX?: string | number | undefined;
4669
+ pcbY?: string | number | undefined;
4670
+ pcbRotation?: string | number | undefined;
4671
+ schX?: string | number | undefined;
4672
+ schY?: string | number | undefined;
4673
+ schRotation?: string | number | undefined;
4674
+ layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | {
4675
+ name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
4676
+ } | undefined;
4677
+ footprint?: Props.Footprint | undefined;
4678
+ }>;
4679
+ };
4680
+ getAvailablePcbLayers(): string[];
4681
+ getPcbSize(): {
4682
+ width: number;
4683
+ height: number;
4684
+ };
4685
+ _getPcbCircuitJsonBounds(): {
4686
+ center: {
4687
+ x: number;
4688
+ y: number;
4689
+ };
4690
+ bounds: {
4691
+ left: number;
4692
+ top: number;
4693
+ right: number;
4694
+ bottom: number;
4695
+ };
4696
+ width: number;
4697
+ height: number;
4698
+ };
4699
+ _setPositionFromLayout(newCenter: {
4700
+ x: number;
4701
+ y: number;
4702
+ }): void;
4703
+ doInitialPcbPrimitiveRender(): void;
4704
+ }
4705
+
4706
+ declare const useRenderedCircuit: (reactElements: React.ReactElement) => {
4707
+ isLoading: boolean;
4708
+ error?: Error | null;
4709
+ circuit?: Circuit;
4710
+ circuitJson?: AnyCircuitElement[];
4711
+ };
4712
+
4601
4713
  declare global {
4602
4714
  namespace JSX {
4603
4715
  interface IntrinsicElements {
@@ -4644,4 +4756,4 @@ declare global {
4644
4756
  }
4645
4757
  }
4646
4758
 
4647
- export { Board, Capacitor, Chip, Circuit, Constraint, Diode, FabricationNotePath, FabricationNoteText, Footprint, Group, Hole, type IRenderable, Jumper, Keepout, Led, Net, NormalComponent, PlatedHole, Port, PrimitiveComponent, Project, Renderable, Resistor, SilkscreenPath, SilkscreenText, SmtPad, Trace, TraceHint };
4759
+ export { Board, Capacitor, Chip, Circuit, Constraint, Diode, FabricationNotePath, FabricationNoteText, Footprint, Group, Hole, type IRenderable, Jumper, Keepout, Led, Net, NormalComponent, PlatedHole, Port, PrimitiveComponent, Project, Renderable, Resistor, SilkscreenPath, SilkscreenText, SmtPad, Trace, TraceHint, Via, useRenderedCircuit };
package/dist/index.js CHANGED
@@ -31,7 +31,8 @@ __export(components_exports, {
31
31
  SilkscreenText: () => SilkscreenText,
32
32
  SmtPad: () => SmtPad,
33
33
  Trace: () => Trace,
34
- TraceHint: () => TraceHint
34
+ TraceHint: () => TraceHint,
35
+ Via: () => Via
35
36
  });
36
37
 
37
38
  // lib/components/base-components/NormalComponent.ts
@@ -3796,6 +3797,66 @@ var FabricationNotePath = class extends PrimitiveComponent {
3796
3797
  }
3797
3798
  };
3798
3799
 
3800
+ // lib/components/primitive-components/Via.ts
3801
+ import { viaProps } from "@tscircuit/props";
3802
+ var Via = class extends PrimitiveComponent {
3803
+ pcb_via_id = null;
3804
+ matchedPort = null;
3805
+ isPcbPrimitive = true;
3806
+ get config() {
3807
+ return {
3808
+ componentName: "Via",
3809
+ zodProps: viaProps
3810
+ };
3811
+ }
3812
+ getAvailablePcbLayers() {
3813
+ return ["top", "inner1", "inner2", "bottom"];
3814
+ }
3815
+ getPcbSize() {
3816
+ const { _parsedProps: props } = this;
3817
+ return { width: props.outerDiameter, height: props.outerDiameter };
3818
+ }
3819
+ _getPcbCircuitJsonBounds() {
3820
+ const { db } = this.root;
3821
+ const via = db.pcb_via.get(this.pcb_via_id);
3822
+ const size = this.getPcbSize();
3823
+ return {
3824
+ center: { x: via.x, y: via.y },
3825
+ bounds: {
3826
+ left: via.x - size.width / 2,
3827
+ top: via.y - size.height / 2,
3828
+ right: via.x + size.width / 2,
3829
+ bottom: via.y + size.height / 2
3830
+ },
3831
+ width: size.width,
3832
+ height: size.height
3833
+ };
3834
+ }
3835
+ _setPositionFromLayout(newCenter) {
3836
+ const { db } = this.root;
3837
+ db.pcb_via.update(this.pcb_via_id, {
3838
+ x: newCenter.x,
3839
+ y: newCenter.y
3840
+ });
3841
+ this.matchedPort?._setPositionFromLayout(newCenter);
3842
+ }
3843
+ doInitialPcbPrimitiveRender() {
3844
+ const { db } = this.root;
3845
+ const { _parsedProps: props } = this;
3846
+ const position = this._getGlobalPcbPositionBeforeLayout();
3847
+ const pcb_via = db.pcb_via.insert({
3848
+ x: position.x,
3849
+ y: position.y,
3850
+ hole_diameter: props.holeDiameter,
3851
+ outer_diameter: props.outerDiameter,
3852
+ layers: ["bottom", "top"],
3853
+ from_layer: props.fromLayer || "bottom",
3854
+ to_layer: props.toLayer || "top"
3855
+ });
3856
+ this.pcb_via_id = pcb_via.pcb_via_id;
3857
+ }
3858
+ };
3859
+
3799
3860
  // lib/Circuit.ts
3800
3861
  import { su } from "@tscircuit/soup-util";
3801
3862
  import { isValidElement as isValidElement2 } from "react";
@@ -3868,6 +3929,9 @@ var Circuit = class {
3868
3929
  getCircuitJson() {
3869
3930
  return this.getSoup();
3870
3931
  }
3932
+ toJson() {
3933
+ return this.getSoup();
3934
+ }
3871
3935
  async getSvg(options) {
3872
3936
  const circuitToSvg = await import("circuit-to-svg").catch((e) => {
3873
3937
  throw new Error(
@@ -3897,6 +3961,33 @@ var Circuit = class {
3897
3961
  };
3898
3962
  var Project = Circuit;
3899
3963
 
3964
+ // lib/hooks/use-rendered-circuit.ts
3965
+ import React from "react";
3966
+ var useRenderedCircuit = (reactElements) => {
3967
+ const [isLoading, setIsLoading] = React.useState(true);
3968
+ const [error, setError] = React.useState(null);
3969
+ const [circuit, setCircuit] = React.useState();
3970
+ const [circuitJson, setCircuitJson] = React.useState();
3971
+ React.useEffect(() => {
3972
+ setIsLoading(true);
3973
+ setError(null);
3974
+ if (reactElements) {
3975
+ setTimeout(() => {
3976
+ try {
3977
+ const circuit2 = new Circuit();
3978
+ circuit2.add(reactElements);
3979
+ setCircuit(circuit2);
3980
+ setCircuitJson(circuit2.toJson());
3981
+ } catch (error2) {
3982
+ setError(error2);
3983
+ }
3984
+ setIsLoading(false);
3985
+ }, 1);
3986
+ }
3987
+ }, [reactElements]);
3988
+ return { isLoading, error, circuit, circuitJson };
3989
+ };
3990
+
3900
3991
  // lib/register-catalogue.ts
3901
3992
  extendCatalogue(components_exports);
3902
3993
  extendCatalogue({
@@ -3929,5 +4020,7 @@ export {
3929
4020
  SilkscreenText,
3930
4021
  SmtPad,
3931
4022
  Trace,
3932
- TraceHint
4023
+ TraceHint,
4024
+ Via,
4025
+ useRenderedCircuit
3933
4026
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.105",
4
+ "version": "0.0.107",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -39,8 +39,8 @@
39
39
  "@tscircuit/infgrid-ijump-astar": "^0.0.21",
40
40
  "@tscircuit/math-utils": "^0.0.4",
41
41
  "@tscircuit/props": "^0.0.68",
42
- "@tscircuit/soup-util": "^0.0.32",
43
- "circuit-json": "^0.0.83",
42
+ "@tscircuit/soup-util": "^0.0.33",
43
+ "circuit-json": "^0.0.85",
44
44
  "circuit-json-to-connectivity-map": "^0.0.17",
45
45
  "@tscircuit/footprinter": "^0.0.66",
46
46
  "nanoid": "^5.0.7",