@tscircuit/core 0.0.106 → 0.0.108

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 (3) hide show
  1. package/dist/index.d.ts +1315 -1118
  2. package/dist/index.js +297 -168
  3. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -27,11 +27,14 @@ __export(components_exports, {
27
27
  PrimitiveComponent: () => PrimitiveComponent,
28
28
  Renderable: () => Renderable,
29
29
  Resistor: () => Resistor,
30
+ SilkscreenCircle: () => SilkscreenCircle,
30
31
  SilkscreenPath: () => SilkscreenPath,
32
+ SilkscreenRect: () => SilkscreenRect,
31
33
  SilkscreenText: () => SilkscreenText,
32
34
  SmtPad: () => SmtPad,
33
35
  Trace: () => Trace,
34
- TraceHint: () => TraceHint
36
+ TraceHint: () => TraceHint,
37
+ Via: () => Via
35
38
  });
36
39
 
37
40
  // lib/components/base-components/NormalComponent.ts
@@ -661,7 +664,7 @@ var PrimitiveComponent = class extends Renderable {
661
664
  }
662
665
  getSubcircuit() {
663
666
  if (this.isSubcircuit) return this;
664
- const group = this.parent?.getSubcircuit();
667
+ const group = this.parent?.getSubcircuit?.();
665
668
  if (!group)
666
669
  throw new Error("Component is not inside an opaque group (no board?)");
667
670
  return group;
@@ -2336,8 +2339,17 @@ var Board = class extends Group {
2336
2339
  }
2337
2340
  };
2338
2341
 
2339
- // lib/components/normal-components/Resistor.ts
2340
- import { resistorProps } from "@tscircuit/props";
2342
+ // lib/components/normal-components/Capacitor.ts
2343
+ import { capacitorProps } from "@tscircuit/props";
2344
+
2345
+ // lib/utils/constants.ts
2346
+ var stringProxy = new Proxy(
2347
+ {},
2348
+ {
2349
+ get: (target, prop) => prop
2350
+ }
2351
+ );
2352
+ var FTYPE = stringProxy;
2341
2353
 
2342
2354
  // lib/components/primitive-components/Trace.ts
2343
2355
  import { traceProps } from "@tscircuit/props";
@@ -2986,116 +2998,7 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
2986
2998
  }
2987
2999
  };
2988
3000
 
2989
- // lib/components/normal-components/Resistor.ts
2990
- var Resistor = class extends NormalComponent {
2991
- // @ts-ignore (cause the symbolName is string and not fixed)
2992
- get config() {
2993
- return {
2994
- componentName: "Resistor",
2995
- schematicSymbolName: this.props.symbolName ?? "boxresistor_horz",
2996
- zodProps: resistorProps,
2997
- sourceFtype: "simple_resistor"
2998
- };
2999
- }
3000
- initPorts() {
3001
- this.add(new Port({ name: "pin1", pinNumber: 1, aliases: ["anode", "pos"] }));
3002
- this.add(new Port({ name: "pin2", pinNumber: 2, aliases: ["cathode", "neg"] }));
3003
- }
3004
- doInitialCreateNetsFromProps() {
3005
- this._createNetsFromProps([this.props.pullupFor, this.props.pullupTo]);
3006
- }
3007
- doInitialCreateTracesFromProps() {
3008
- if (this.props.pullupFor && this.props.pullupTo) {
3009
- this.add(
3010
- new Trace({
3011
- from: `${this.getSubcircuitSelector()} > port.1`,
3012
- to: this.props.pullupFor
3013
- })
3014
- );
3015
- this.add(
3016
- new Trace({
3017
- from: `${this.getSubcircuitSelector()} > port.2`,
3018
- to: this.props.pullupTo
3019
- })
3020
- );
3021
- }
3022
- }
3023
- doInitialSourceRender() {
3024
- const { db } = this.root;
3025
- const { _parsedProps: props } = this;
3026
- const source_component = db.source_component.insert({
3027
- ftype: "simple_resistor",
3028
- name: props.name,
3029
- // @ts-ignore
3030
- manufacturer_part_number: props.manufacturerPartNumber ?? props.mfn,
3031
- supplier_part_numbers: props.supplierPartNumbers,
3032
- resistance: props.resistance
3033
- });
3034
- this.source_component_id = source_component.source_component_id;
3035
- }
3036
- };
3037
-
3038
- // lib/components/normal-components/Led.ts
3039
- import { ledProps } from "@tscircuit/props";
3040
- var Led = class extends NormalComponent {
3041
- // @ts-ignore
3042
- get config() {
3043
- return {
3044
- componentName: "Led",
3045
- schematicSymbolName: this.props.symbolName ?? "led_horz",
3046
- zodProps: ledProps,
3047
- sourceFtype: "simple_diode"
3048
- };
3049
- }
3050
- initPorts() {
3051
- this.add(new Port({ name: "pin1", pinNumber: 1, aliases: ["anode", "pos"] }));
3052
- this.add(new Port({ name: "pin2", pinNumber: 2, aliases: ["cathode", "neg"] }));
3053
- }
3054
- pos = this.portMap.pin1;
3055
- anode = this.portMap.pin1;
3056
- neg = this.portMap.pin2;
3057
- cathode = this.portMap.pin2;
3058
- };
3059
-
3060
- // lib/components/normal-components/Diode.ts
3061
- import { diodeProps } from "@tscircuit/props";
3062
-
3063
- // lib/utils/constants.ts
3064
- var stringProxy = new Proxy(
3065
- {},
3066
- {
3067
- get: (target, prop) => prop
3068
- }
3069
- );
3070
- var FTYPE = stringProxy;
3071
-
3072
- // lib/components/normal-components/Diode.ts
3073
- var Diode = class extends NormalComponent {
3074
- // @ts-ignore
3075
- get config() {
3076
- return {
3077
- schematicSymbolName: this.props.symbolName ?? "diode_horz",
3078
- componentName: "Diode",
3079
- zodProps: diodeProps,
3080
- sourceFtype: "simple_diode"
3081
- };
3082
- }
3083
- initPorts() {
3084
- this.add(
3085
- new Port({ name: "pin1", pinNumber: 1, aliases: ["anode", "pos"] })
3086
- );
3087
- this.add(
3088
- new Port({ name: "pin2", pinNumber: 2, aliases: ["cathode", "neg"] })
3089
- );
3090
- }
3091
- pos = this.portMap.pin1;
3092
- anode = this.portMap.pin1;
3093
- neg = this.portMap.pin2;
3094
- cathode = this.portMap.pin2;
3095
- };
3096
-
3097
3001
  // lib/components/normal-components/Capacitor.ts
3098
- import { capacitorProps } from "@tscircuit/props";
3099
3002
  var Capacitor = class extends NormalComponent {
3100
3003
  // @ts-ignore (cause the symbolName is string and not fixed)
3101
3004
  get config() {
@@ -3496,6 +3399,32 @@ var Chip = class extends NormalComponent {
3496
3399
  }
3497
3400
  };
3498
3401
 
3402
+ // lib/components/normal-components/Diode.ts
3403
+ import { diodeProps } from "@tscircuit/props";
3404
+ var Diode = class extends NormalComponent {
3405
+ // @ts-ignore
3406
+ get config() {
3407
+ return {
3408
+ schematicSymbolName: this.props.symbolName ?? "diode_horz",
3409
+ componentName: "Diode",
3410
+ zodProps: diodeProps,
3411
+ sourceFtype: "simple_diode"
3412
+ };
3413
+ }
3414
+ initPorts() {
3415
+ this.add(
3416
+ new Port({ name: "pin1", pinNumber: 1, aliases: ["anode", "pos"] })
3417
+ );
3418
+ this.add(
3419
+ new Port({ name: "pin2", pinNumber: 2, aliases: ["cathode", "neg"] })
3420
+ );
3421
+ }
3422
+ pos = this.portMap.pin1;
3423
+ anode = this.portMap.pin1;
3424
+ neg = this.portMap.pin2;
3425
+ cathode = this.portMap.pin2;
3426
+ };
3427
+
3499
3428
  // lib/components/normal-components/Jumper.ts
3500
3429
  import { jumperProps } from "@tscircuit/props";
3501
3430
  var Jumper = class extends NormalComponent {
@@ -3570,6 +3499,78 @@ var Jumper = class extends NormalComponent {
3570
3499
  }
3571
3500
  };
3572
3501
 
3502
+ // lib/components/normal-components/Led.ts
3503
+ import { ledProps } from "@tscircuit/props";
3504
+ var Led = class extends NormalComponent {
3505
+ // @ts-ignore
3506
+ get config() {
3507
+ return {
3508
+ componentName: "Led",
3509
+ schematicSymbolName: this.props.symbolName ?? "led_horz",
3510
+ zodProps: ledProps,
3511
+ sourceFtype: "simple_diode"
3512
+ };
3513
+ }
3514
+ initPorts() {
3515
+ this.add(new Port({ name: "pin1", pinNumber: 1, aliases: ["anode", "pos"] }));
3516
+ this.add(new Port({ name: "pin2", pinNumber: 2, aliases: ["cathode", "neg"] }));
3517
+ }
3518
+ pos = this.portMap.pin1;
3519
+ anode = this.portMap.pin1;
3520
+ neg = this.portMap.pin2;
3521
+ cathode = this.portMap.pin2;
3522
+ };
3523
+
3524
+ // lib/components/normal-components/Resistor.ts
3525
+ import { resistorProps } from "@tscircuit/props";
3526
+ var Resistor = class extends NormalComponent {
3527
+ // @ts-ignore (cause the symbolName is string and not fixed)
3528
+ get config() {
3529
+ return {
3530
+ componentName: "Resistor",
3531
+ schematicSymbolName: this.props.symbolName ?? "boxresistor_horz",
3532
+ zodProps: resistorProps,
3533
+ sourceFtype: "simple_resistor"
3534
+ };
3535
+ }
3536
+ initPorts() {
3537
+ this.add(new Port({ name: "pin1", pinNumber: 1, aliases: ["anode", "pos"] }));
3538
+ this.add(new Port({ name: "pin2", pinNumber: 2, aliases: ["cathode", "neg"] }));
3539
+ }
3540
+ doInitialCreateNetsFromProps() {
3541
+ this._createNetsFromProps([this.props.pullupFor, this.props.pullupTo]);
3542
+ }
3543
+ doInitialCreateTracesFromProps() {
3544
+ if (this.props.pullupFor && this.props.pullupTo) {
3545
+ this.add(
3546
+ new Trace({
3547
+ from: `${this.getSubcircuitSelector()} > port.1`,
3548
+ to: this.props.pullupFor
3549
+ })
3550
+ );
3551
+ this.add(
3552
+ new Trace({
3553
+ from: `${this.getSubcircuitSelector()} > port.2`,
3554
+ to: this.props.pullupTo
3555
+ })
3556
+ );
3557
+ }
3558
+ }
3559
+ doInitialSourceRender() {
3560
+ const { db } = this.root;
3561
+ const { _parsedProps: props } = this;
3562
+ const source_component = db.source_component.insert({
3563
+ ftype: "simple_resistor",
3564
+ name: props.name,
3565
+ // @ts-ignore
3566
+ manufacturer_part_number: props.manufacturerPartNumber ?? props.mfn,
3567
+ supplier_part_numbers: props.supplierPartNumbers,
3568
+ resistance: props.resistance
3569
+ });
3570
+ this.source_component_id = source_component.source_component_id;
3571
+ }
3572
+ };
3573
+
3573
3574
  // lib/components/primitive-components/Constraint.ts
3574
3575
  import { constraintProps } from "@tscircuit/props";
3575
3576
  import "zod";
@@ -3633,6 +3634,77 @@ var Constraint2 = class extends PrimitiveComponent {
3633
3634
  }
3634
3635
  };
3635
3636
 
3637
+ // lib/components/primitive-components/FabricationNotePath.ts
3638
+ import { fabricationNotePathProps } from "@tscircuit/props";
3639
+ import { applyToPoint as applyToPoint6 } from "transformation-matrix";
3640
+ var FabricationNotePath = class extends PrimitiveComponent {
3641
+ fabrication_note_path_id = null;
3642
+ get config() {
3643
+ return {
3644
+ componentName: "FabricationNotePath",
3645
+ zodProps: fabricationNotePathProps
3646
+ };
3647
+ }
3648
+ doInitialPcbPrimitiveRender() {
3649
+ const { db } = this.root;
3650
+ const { _parsedProps: props } = this;
3651
+ const layer = props.layer ?? "top";
3652
+ if (layer !== "top" && layer !== "bottom") {
3653
+ throw new Error(
3654
+ `Invalid layer "${layer}" for SilkscreenPath. Must be "top" or "bottom".`
3655
+ );
3656
+ }
3657
+ const transform = this._computePcbGlobalTransformBeforeLayout();
3658
+ const fabrication_note_path = db.pcb_fabrication_note_path.insert({
3659
+ pcb_component_id: this.parent?.pcb_component_id,
3660
+ layer,
3661
+ color: props.color,
3662
+ route: props.route.map((p) => {
3663
+ const transformedPosition = applyToPoint6(transform, {
3664
+ x: p.x,
3665
+ y: p.y
3666
+ });
3667
+ return {
3668
+ ...p,
3669
+ x: transformedPosition.x,
3670
+ y: transformedPosition.y
3671
+ };
3672
+ }),
3673
+ stroke_width: props.strokeWidth ?? 0.1
3674
+ });
3675
+ this.fabrication_note_path_id = fabrication_note_path.pcb_fabrication_note_path_id;
3676
+ }
3677
+ };
3678
+
3679
+ // lib/components/primitive-components/FabricationNoteText.ts
3680
+ import { fabricationNoteTextProps } from "@tscircuit/props";
3681
+ var FabricationNoteText = class extends PrimitiveComponent {
3682
+ get config() {
3683
+ return {
3684
+ componentName: "FabricationNoteText",
3685
+ zodProps: fabricationNoteTextProps
3686
+ };
3687
+ }
3688
+ doInitialPcbPrimitiveRender() {
3689
+ const { db } = this.root;
3690
+ const { _parsedProps: props } = this;
3691
+ const container = this.getPrimitiveContainer();
3692
+ db.pcb_fabrication_note_text.insert({
3693
+ anchor_alignment: props.anchorAlignment,
3694
+ anchor_position: {
3695
+ x: props.pcbX ?? 0,
3696
+ y: props.pcbY ?? 0
3697
+ },
3698
+ font: props.font ?? "tscircuit2024",
3699
+ font_size: props.fontSize ?? 1,
3700
+ layer: "top",
3701
+ color: props.color,
3702
+ text: props.text ?? "",
3703
+ pcb_component_id: container.pcb_component_id
3704
+ });
3705
+ }
3706
+ };
3707
+
3636
3708
  // lib/components/primitive-components/Hole.ts
3637
3709
  import { holeProps } from "@tscircuit/props";
3638
3710
  var Hole = class extends PrimitiveComponent {
@@ -3686,6 +3758,72 @@ var Hole = class extends PrimitiveComponent {
3686
3758
  }
3687
3759
  };
3688
3760
 
3761
+ // lib/components/primitive-components/SilkscreenCircle.ts
3762
+ import { silkscreenCircleProps } from "@tscircuit/props";
3763
+ var SilkscreenCircle = class extends PrimitiveComponent {
3764
+ pcb_silkscreen_circle_id = null;
3765
+ get config() {
3766
+ return {
3767
+ componentName: "SilkscreenCircle",
3768
+ zodProps: silkscreenCircleProps
3769
+ };
3770
+ }
3771
+ doInitialPcbPrimitiveRender() {
3772
+ const { db } = this.root;
3773
+ const { _parsedProps: props } = this;
3774
+ const layer = props.layer ?? "top";
3775
+ if (layer !== "top" && layer !== "bottom") {
3776
+ throw new Error(
3777
+ `Invalid layer "${layer}" for SilkscreenCircle. Must be "top" or "bottom".`
3778
+ );
3779
+ }
3780
+ const transform = this._computePcbGlobalTransformBeforeLayout();
3781
+ const pcb_silkscreen_circle = db.pcb_silkscreen_circle.insert({
3782
+ pcb_component_id: this.parent?.pcb_component_id,
3783
+ layer,
3784
+ center: {
3785
+ x: props.pcbX ?? 0,
3786
+ y: props.pcbY ?? 0
3787
+ },
3788
+ radius: props.radius
3789
+ });
3790
+ this.pcb_silkscreen_circle_id = pcb_silkscreen_circle.pcb_silkscreen_circle_id;
3791
+ }
3792
+ };
3793
+
3794
+ // lib/components/primitive-components/SilkscreenRect.ts
3795
+ import { silkscreenRectProps } from "@tscircuit/props";
3796
+ var SilkscreenRect = class extends PrimitiveComponent {
3797
+ pcb_silkscreen_rect_id = null;
3798
+ get config() {
3799
+ return {
3800
+ componentName: "SilkscreenRect",
3801
+ zodProps: silkscreenRectProps
3802
+ };
3803
+ }
3804
+ doInitialPcbPrimitiveRender() {
3805
+ const { db } = this.root;
3806
+ const { _parsedProps: props } = this;
3807
+ const layer = props.layer ?? "top";
3808
+ if (layer !== "top" && layer !== "bottom") {
3809
+ throw new Error(
3810
+ `Invalid layer "${layer}" for SilkscreenRect. Must be "top" or "bottom".`
3811
+ );
3812
+ }
3813
+ const pcb_silkscreen_rect = db.pcb_silkscreen_rect.insert({
3814
+ pcb_component_id: this.parent?.pcb_component_id,
3815
+ layer,
3816
+ center: {
3817
+ x: props.pcbX ?? 0,
3818
+ y: props.pcbY ?? 0
3819
+ },
3820
+ width: props.width,
3821
+ height: props.height
3822
+ });
3823
+ this.pcb_silkscreen_rect_id = pcb_silkscreen_rect.pcb_silkscreen_rect_id;
3824
+ }
3825
+ };
3826
+
3689
3827
  // lib/components/primitive-components/SilkscreenText.ts
3690
3828
  import { silkscreenTextProps } from "@tscircuit/props";
3691
3829
  var SilkscreenText = class extends PrimitiveComponent {
@@ -3725,74 +3863,62 @@ var SilkscreenText = class extends PrimitiveComponent {
3725
3863
  }
3726
3864
  };
3727
3865
 
3728
- // lib/components/primitive-components/FabricationNoteText.ts
3729
- import { fabricationNoteTextProps } from "@tscircuit/props";
3730
- var FabricationNoteText = class extends PrimitiveComponent {
3866
+ // lib/components/primitive-components/Via.ts
3867
+ import { viaProps } from "@tscircuit/props";
3868
+ var Via = class extends PrimitiveComponent {
3869
+ pcb_via_id = null;
3870
+ matchedPort = null;
3871
+ isPcbPrimitive = true;
3731
3872
  get config() {
3732
3873
  return {
3733
- componentName: "FabricationNoteText",
3734
- zodProps: fabricationNoteTextProps
3874
+ componentName: "Via",
3875
+ zodProps: viaProps
3735
3876
  };
3736
3877
  }
3737
- doInitialPcbPrimitiveRender() {
3738
- const { db } = this.root;
3878
+ getAvailablePcbLayers() {
3879
+ return ["top", "inner1", "inner2", "bottom"];
3880
+ }
3881
+ getPcbSize() {
3739
3882
  const { _parsedProps: props } = this;
3740
- const container = this.getPrimitiveContainer();
3741
- db.pcb_fabrication_note_text.insert({
3742
- anchor_alignment: props.anchorAlignment,
3743
- anchor_position: {
3744
- x: props.pcbX ?? 0,
3745
- y: props.pcbY ?? 0
3746
- },
3747
- font: props.font ?? "tscircuit2024",
3748
- font_size: props.fontSize ?? 1,
3749
- layer: "top",
3750
- color: props.color,
3751
- text: props.text ?? "",
3752
- pcb_component_id: container.pcb_component_id
3753
- });
3883
+ return { width: props.outerDiameter, height: props.outerDiameter };
3754
3884
  }
3755
- };
3756
-
3757
- // lib/components/primitive-components/FabricationNotePath.ts
3758
- import { fabricationNotePathProps } from "@tscircuit/props";
3759
- import { applyToPoint as applyToPoint6 } from "transformation-matrix";
3760
- var FabricationNotePath = class extends PrimitiveComponent {
3761
- fabrication_note_path_id = null;
3762
- get config() {
3885
+ _getPcbCircuitJsonBounds() {
3886
+ const { db } = this.root;
3887
+ const via = db.pcb_via.get(this.pcb_via_id);
3888
+ const size = this.getPcbSize();
3763
3889
  return {
3764
- componentName: "FabricationNotePath",
3765
- zodProps: fabricationNotePathProps
3890
+ center: { x: via.x, y: via.y },
3891
+ bounds: {
3892
+ left: via.x - size.width / 2,
3893
+ top: via.y - size.height / 2,
3894
+ right: via.x + size.width / 2,
3895
+ bottom: via.y + size.height / 2
3896
+ },
3897
+ width: size.width,
3898
+ height: size.height
3766
3899
  };
3767
3900
  }
3901
+ _setPositionFromLayout(newCenter) {
3902
+ const { db } = this.root;
3903
+ db.pcb_via.update(this.pcb_via_id, {
3904
+ x: newCenter.x,
3905
+ y: newCenter.y
3906
+ });
3907
+ }
3768
3908
  doInitialPcbPrimitiveRender() {
3769
3909
  const { db } = this.root;
3770
3910
  const { _parsedProps: props } = this;
3771
- const layer = props.layer ?? "top";
3772
- if (layer !== "top" && layer !== "bottom") {
3773
- throw new Error(
3774
- `Invalid layer "${layer}" for SilkscreenPath. Must be "top" or "bottom".`
3775
- );
3776
- }
3777
- const transform = this._computePcbGlobalTransformBeforeLayout();
3778
- const fabrication_note_path = db.pcb_fabrication_note_path.insert({
3779
- pcb_component_id: this.parent?.pcb_component_id,
3780
- layer,
3781
- color: props.color,
3782
- route: props.route.map((p) => {
3783
- const transformedPosition = applyToPoint6(transform, {
3784
- x: p.x,
3785
- y: p.y
3786
- });
3787
- return {
3788
- ...p,
3789
- x: transformedPosition.x,
3790
- y: transformedPosition.y
3791
- };
3792
- }),
3793
- stroke_width: props.strokeWidth ?? 0.1
3911
+ const position = this._getGlobalPcbPositionBeforeLayout();
3912
+ const pcb_via = db.pcb_via.insert({
3913
+ x: position.x,
3914
+ y: position.y,
3915
+ hole_diameter: props.holeDiameter,
3916
+ outer_diameter: props.outerDiameter,
3917
+ layers: ["bottom", "top"],
3918
+ from_layer: props.fromLayer || "bottom",
3919
+ to_layer: props.toLayer || "top"
3794
3920
  });
3795
- this.fabrication_note_path_id = fabrication_note_path.pcb_fabrication_note_path_id;
3921
+ this.pcb_via_id = pcb_via.pcb_via_id;
3796
3922
  }
3797
3923
  };
3798
3924
 
@@ -3955,10 +4081,13 @@ export {
3955
4081
  Project,
3956
4082
  Renderable,
3957
4083
  Resistor,
4084
+ SilkscreenCircle,
3958
4085
  SilkscreenPath,
4086
+ SilkscreenRect,
3959
4087
  SilkscreenText,
3960
4088
  SmtPad,
3961
4089
  Trace,
3962
4090
  TraceHint,
4091
+ Via,
3963
4092
  useRenderedCircuit
3964
4093
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.106",
4
+ "version": "0.0.108",
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",