@tscircuit/core 0.0.929 → 0.0.931

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
@@ -1416,6 +1416,7 @@ declare class Board extends Group<typeof boardProps> implements BoardI, Subcircu
1416
1416
  pcbOffsetX: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
1417
1417
  pcbOffsetY: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
1418
1418
  pcbRotation: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
1419
+ pcbPositionAnchor: zod.ZodOptional<zod.ZodString>;
1419
1420
  pcbPositionMode: zod.ZodOptional<zod.ZodEnum<["relative_to_group_anchor", "auto", "relative_to_board_anchor", "relative_to_component_anchor"]>>;
1420
1421
  pcbMarginTop: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
1421
1422
  pcbMarginRight: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
@@ -1770,7 +1771,7 @@ declare class Board extends Group<typeof boardProps> implements BoardI, Subcircu
1770
1771
  pcbPaddingRight: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
1771
1772
  pcbPaddingTop: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
1772
1773
  pcbPaddingBottom: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
1773
- pcbPositionAnchor: zod.ZodOptional<zod.ZodType<_tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right">, zod.ZodTypeDef, _tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right">>>;
1774
+ pcbAnchorAlignment: zod.ZodOptional<zod.ZodType<_tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right">, zod.ZodTypeDef, _tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right">>>;
1774
1775
  layoutMode: zod.ZodOptional<zod.ZodEnum<["grid", "flex", "match-adapt", "relative", "none"]>>;
1775
1776
  position: zod.ZodOptional<zod.ZodEnum<["absolute", "relative"]>>;
1776
1777
  gridCols: zod.ZodOptional<zod.ZodUnion<[zod.ZodNumber, zod.ZodString]>>;
@@ -2169,7 +2170,7 @@ declare class Board extends Group<typeof boardProps> implements BoardI, Subcircu
2169
2170
  pcbOffsetX?: number | undefined;
2170
2171
  pcbOffsetY?: number | undefined;
2171
2172
  pcbRotation?: number | undefined;
2172
- pcbPositionAnchor?: _tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right"> | undefined;
2173
+ pcbPositionAnchor?: string | undefined;
2173
2174
  pcbPositionMode?: "relative_to_group_anchor" | "auto" | "relative_to_board_anchor" | "relative_to_component_anchor" | undefined;
2174
2175
  layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | undefined;
2175
2176
  pcbMarginTop?: number | undefined;
@@ -2371,6 +2372,7 @@ declare class Board extends Group<typeof boardProps> implements BoardI, Subcircu
2371
2372
  pcbPaddingRight?: number | undefined;
2372
2373
  pcbPaddingTop?: number | undefined;
2373
2374
  pcbPaddingBottom?: number | undefined;
2375
+ pcbAnchorAlignment?: _tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right"> | undefined;
2374
2376
  manualEdits?: {
2375
2377
  pcb_placements?: {
2376
2378
  center: {
@@ -2483,7 +2485,7 @@ declare class Board extends Group<typeof boardProps> implements BoardI, Subcircu
2483
2485
  pcbOffsetX?: string | number | undefined;
2484
2486
  pcbOffsetY?: string | number | undefined;
2485
2487
  pcbRotation?: string | number | undefined;
2486
- pcbPositionAnchor?: _tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right"> | undefined;
2488
+ pcbPositionAnchor?: string | undefined;
2487
2489
  pcbPositionMode?: "relative_to_group_anchor" | "auto" | "relative_to_board_anchor" | "relative_to_component_anchor" | undefined;
2488
2490
  layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | {
2489
2491
  name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
@@ -2687,6 +2689,7 @@ declare class Board extends Group<typeof boardProps> implements BoardI, Subcircu
2687
2689
  pcbPaddingRight?: string | number | undefined;
2688
2690
  pcbPaddingTop?: string | number | undefined;
2689
2691
  pcbPaddingBottom?: string | number | undefined;
2692
+ pcbAnchorAlignment?: _tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right"> | undefined;
2690
2693
  manualEdits?: {
2691
2694
  pcb_placements?: {
2692
2695
  center: {
@@ -2836,6 +2839,7 @@ declare class Panel extends Group<typeof panelProps> {
2836
2839
  pcbOffsetX: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
2837
2840
  pcbOffsetY: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
2838
2841
  pcbRotation: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
2842
+ pcbPositionAnchor: zod.ZodOptional<zod.ZodString>;
2839
2843
  pcbPositionMode: zod.ZodOptional<zod.ZodEnum<["relative_to_group_anchor", "auto", "relative_to_board_anchor", "relative_to_component_anchor"]>>;
2840
2844
  pcbMarginTop: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
2841
2845
  pcbMarginRight: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
@@ -3192,7 +3196,7 @@ declare class Panel extends Group<typeof panelProps> {
3192
3196
  pcbPaddingRight: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
3193
3197
  pcbPaddingTop: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
3194
3198
  pcbPaddingBottom: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
3195
- pcbPositionAnchor: zod.ZodOptional<zod.ZodType<_tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right">, zod.ZodTypeDef, _tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right">>>;
3199
+ pcbAnchorAlignment: zod.ZodOptional<zod.ZodType<_tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right">, zod.ZodTypeDef, _tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right">>>;
3196
3200
  layoutMode: zod.ZodOptional<zod.ZodEnum<["grid", "flex", "match-adapt", "relative", "none"]>>;
3197
3201
  position: zod.ZodOptional<zod.ZodEnum<["absolute", "relative"]>>;
3198
3202
  gridCols: zod.ZodOptional<zod.ZodUnion<[zod.ZodNumber, zod.ZodString]>>;
@@ -3391,7 +3395,7 @@ declare class Panel extends Group<typeof panelProps> {
3391
3395
  pcbOffsetX?: number | undefined;
3392
3396
  pcbOffsetY?: number | undefined;
3393
3397
  pcbRotation?: number | undefined;
3394
- pcbPositionAnchor?: _tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right"> | undefined;
3398
+ pcbPositionAnchor?: string | undefined;
3395
3399
  pcbPositionMode?: "relative_to_group_anchor" | "auto" | "relative_to_board_anchor" | "relative_to_component_anchor" | undefined;
3396
3400
  layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | undefined;
3397
3401
  pcbMarginTop?: number | undefined;
@@ -3595,6 +3599,7 @@ declare class Panel extends Group<typeof panelProps> {
3595
3599
  pcbPaddingRight?: number | undefined;
3596
3600
  pcbPaddingTop?: number | undefined;
3597
3601
  pcbPaddingBottom?: number | undefined;
3602
+ pcbAnchorAlignment?: _tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right"> | undefined;
3598
3603
  pcbGrid?: boolean | undefined;
3599
3604
  pcbGridCols?: string | number | undefined;
3600
3605
  pcbGridRows?: string | number | undefined;
@@ -3660,7 +3665,7 @@ declare class Panel extends Group<typeof panelProps> {
3660
3665
  pcbOffsetX?: string | number | undefined;
3661
3666
  pcbOffsetY?: string | number | undefined;
3662
3667
  pcbRotation?: string | number | undefined;
3663
- pcbPositionAnchor?: _tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right"> | undefined;
3668
+ pcbPositionAnchor?: string | undefined;
3664
3669
  pcbPositionMode?: "relative_to_group_anchor" | "auto" | "relative_to_board_anchor" | "relative_to_component_anchor" | undefined;
3665
3670
  layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | {
3666
3671
  name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
@@ -3866,6 +3871,7 @@ declare class Panel extends Group<typeof panelProps> {
3866
3871
  pcbPaddingRight?: string | number | undefined;
3867
3872
  pcbPaddingTop?: string | number | undefined;
3868
3873
  pcbPaddingBottom?: string | number | undefined;
3874
+ pcbAnchorAlignment?: _tscircuit_props.AutocompleteString<"top_left" | "top_center" | "top_right" | "center_left" | "center" | "center_right" | "bottom_left" | "bottom_center" | "bottom_right"> | undefined;
3869
3875
  pcbGrid?: boolean | undefined;
3870
3876
  pcbGridCols?: string | number | undefined;
3871
3877
  pcbGridRows?: string | number | undefined;
package/dist/index.js CHANGED
@@ -10027,7 +10027,19 @@ var getSimpleRouteJsonFromCircuitJson = ({
10027
10027
  const subcircuitElements = (circuitJson ?? db.toArray()).filter(
10028
10028
  (e) => !subcircuit_id || "subcircuit_id" in e && relevantSubcircuitIds.has(e.subcircuit_id)
10029
10029
  );
10030
- const board = db.pcb_board.list()[0];
10030
+ let board = null;
10031
+ if (subcircuit_id) {
10032
+ const source_group_id = subcircuit_id.replace(/^subcircuit_/, "");
10033
+ const source_board = db.source_board.getWhere({ source_group_id });
10034
+ if (source_board) {
10035
+ board = db.pcb_board.getWhere({
10036
+ source_board_id: source_board.source_board_id
10037
+ });
10038
+ }
10039
+ }
10040
+ if (!board) {
10041
+ board = db.pcb_board.list()[0];
10042
+ }
10031
10043
  db = su4(subcircuitElements);
10032
10044
  const connMap = getFullConnectivityMapFromCircuitJson3(subcircuitElements);
10033
10045
  const obstacles = getObstaclesFromCircuitJson(
@@ -13681,6 +13693,39 @@ function Group_doInitialPcbComponentAnchorAlignment(group) {
13681
13693
  });
13682
13694
  }
13683
13695
 
13696
+ // lib/components/primitive-components/Group/utils/computeCenterFromAnchorPosition.ts
13697
+ function computeCenterFromAnchorPosition(anchorPosition, ctx) {
13698
+ const { width, height, pcbAnchorAlignment } = ctx;
13699
+ if (!pcbAnchorAlignment) return anchorPosition;
13700
+ const alignment = pcbAnchorAlignment;
13701
+ if (typeof width !== "number" || typeof height !== "number") {
13702
+ console.log("width or height is not a number");
13703
+ return anchorPosition;
13704
+ }
13705
+ const ax = anchorPosition.x;
13706
+ const ay = anchorPosition.y;
13707
+ switch (alignment) {
13708
+ case "top_left":
13709
+ return { x: ax + width / 2, y: ay - height / 2 };
13710
+ case "top_center":
13711
+ return { x: ax, y: ay - height / 2 };
13712
+ case "top_right":
13713
+ return { x: ax - width / 2, y: ay - height / 2 };
13714
+ case "center_left":
13715
+ return { x: ax + width / 2, y: ay };
13716
+ case "center_right":
13717
+ return { x: ax - width / 2, y: ay };
13718
+ case "bottom_left":
13719
+ return { x: ax + width / 2, y: ay + height / 2 };
13720
+ case "bottom_center":
13721
+ return { x: ax, y: ay + height / 2 };
13722
+ case "bottom_right":
13723
+ return { x: ax - width / 2, y: ay + height / 2 };
13724
+ default:
13725
+ return anchorPosition;
13726
+ }
13727
+ }
13728
+
13684
13729
  // lib/components/primitive-components/Group/Group.ts
13685
13730
  var Group6 = class extends NormalComponent3 {
13686
13731
  pcb_group_id = null;
@@ -13743,18 +13788,22 @@ var Group6 = class extends NormalComponent3 {
13743
13788
  x: distance8.parse(point2.x),
13744
13789
  y: distance8.parse(point2.y)
13745
13790
  })) : void 0;
13791
+ const ctx = this.props;
13792
+ const anchorPosition = this._getGlobalPcbPositionBeforeLayout();
13793
+ const center = computeCenterFromAnchorPosition(anchorPosition, ctx);
13746
13794
  const pcb_group = db.pcb_group.insert({
13747
13795
  is_subcircuit: this.isSubcircuit,
13748
13796
  subcircuit_id: this.subcircuit_id ?? this.getSubcircuit()?.subcircuit_id,
13749
13797
  name: this.name,
13750
- center: this._getGlobalPcbPositionBeforeLayout(),
13751
- anchor_alignment: "center",
13798
+ anchor_position: anchorPosition,
13799
+ center,
13752
13800
  ...hasOutline ? { outline: numericOutline } : { width: 0, height: 0 },
13753
13801
  pcb_component_ids: [],
13754
13802
  source_group_id: this.source_group_id,
13755
13803
  autorouter_configuration: props.autorouter ? {
13756
13804
  trace_clearance: props.autorouter.traceClearance
13757
- } : void 0
13805
+ } : void 0,
13806
+ anchor_alignment: props.pcbAnchorAlignment ?? null
13758
13807
  });
13759
13808
  this.pcb_group_id = pcb_group.pcb_group_id;
13760
13809
  for (const child of this.children) {
@@ -15772,6 +15821,7 @@ var Board = class extends Group6 {
15772
15821
  );
15773
15822
  }
15774
15823
  const pcb_board = db.pcb_board.insert({
15824
+ source_board_id: this.source_board_id,
15775
15825
  center,
15776
15826
  thickness: this.boardThickness,
15777
15827
  num_layers: this.allLayers.length,
@@ -19595,7 +19645,7 @@ import { identity as identity5 } from "transformation-matrix";
19595
19645
  var package_default = {
19596
19646
  name: "@tscircuit/core",
19597
19647
  type: "module",
19598
- version: "0.0.928",
19648
+ version: "0.0.930",
19599
19649
  types: "dist/index.d.ts",
19600
19650
  main: "dist/index.js",
19601
19651
  module: "dist/index.js",
@@ -19639,7 +19689,7 @@ var package_default = {
19639
19689
  "@tscircuit/math-utils": "^0.0.29",
19640
19690
  "@tscircuit/miniflex": "^0.0.4",
19641
19691
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
19642
- "@tscircuit/props": "^0.0.428",
19692
+ "@tscircuit/props": "^0.0.429",
19643
19693
  "@tscircuit/schematic-autolayout": "^0.0.6",
19644
19694
  "@tscircuit/schematic-match-adapt": "^0.0.16",
19645
19695
  "@tscircuit/schematic-trace-solver": "^v0.0.45",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.929",
4
+ "version": "0.0.931",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -45,7 +45,7 @@
45
45
  "@tscircuit/math-utils": "^0.0.29",
46
46
  "@tscircuit/miniflex": "^0.0.4",
47
47
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
48
- "@tscircuit/props": "^0.0.428",
48
+ "@tscircuit/props": "^0.0.429",
49
49
  "@tscircuit/schematic-autolayout": "^0.0.6",
50
50
  "@tscircuit/schematic-match-adapt": "^0.0.16",
51
51
  "@tscircuit/schematic-trace-solver": "^v0.0.45",