@tscircuit/core 0.0.627 → 0.0.629

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
@@ -1128,6 +1128,7 @@ declare class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
1128
1128
  _doInitialSchematicLayoutMatchAdapt(): void;
1129
1129
  _doInitialSchematicLayoutMatchpack(): void;
1130
1130
  _doInitialSchematicLayoutGrid(): void;
1131
+ _doInitialSchematicLayoutFlex(): void;
1131
1132
  _getPcbLayoutMode(): "grid" | "flex" | "match-adapt" | "pack" | "none";
1132
1133
  doInitialPcbLayout(): void;
1133
1134
  _doInitialPcbLayoutGrid(): void;
package/dist/index.js CHANGED
@@ -4173,7 +4173,7 @@ var getMaxLengthFromConnectedCapacitors = (ports, { db }) => {
4173
4173
  return sourceComponent.max_decoupling_trace_length;
4174
4174
  }
4175
4175
  return null;
4176
- }).filter((length5) => length5 !== null);
4176
+ }).filter((length6) => length6 !== null);
4177
4177
  if (capacitorMaxLengths.length === 0) return void 0;
4178
4178
  return Math.min(...capacitorMaxLengths);
4179
4179
  };
@@ -8706,13 +8706,184 @@ function Group_doInitialSchematicLayoutGrid(group) {
8706
8706
  }
8707
8707
  }
8708
8708
 
8709
+ // lib/components/primitive-components/Group/Group_doInitialSchematicLayoutFlex.ts
8710
+ import {
8711
+ getCircuitJsonTree as getCircuitJsonTree2,
8712
+ getMinimumFlexContainer,
8713
+ repositionSchematicComponentTo,
8714
+ repositionSchematicGroupTo
8715
+ } from "@tscircuit/circuit-json-util";
8716
+ import { RootFlexBox } from "@tscircuit/miniflex";
8717
+ import { length as length2 } from "circuit-json";
8718
+ var getSizeOfTreeNodeChild = (db, child) => {
8719
+ const { sourceComponent, sourceGroup } = child;
8720
+ if (child.nodeType === "component") {
8721
+ const schComponent = db.schematic_component.getWhere({
8722
+ source_component_id: sourceComponent?.source_component_id
8723
+ });
8724
+ if (!schComponent?.size) return null;
8725
+ return {
8726
+ width: schComponent.size.width,
8727
+ height: schComponent.size.height
8728
+ };
8729
+ }
8730
+ if (child.nodeType === "group") {
8731
+ const schGroup = db.schematic_group.getWhere({
8732
+ source_group_id: sourceGroup?.source_group_id
8733
+ });
8734
+ if (!schGroup) return null;
8735
+ return {
8736
+ width: schGroup.width ?? 0,
8737
+ height: schGroup.height ?? 0
8738
+ };
8739
+ }
8740
+ return null;
8741
+ };
8742
+ var Group_doInitialSchematicLayoutFlex = (group) => {
8743
+ const { db } = group.root;
8744
+ const props = group._parsedProps;
8745
+ const tree = getCircuitJsonTree2(db.toArray(), {
8746
+ source_group_id: group.source_group_id
8747
+ });
8748
+ const rawJustify = props.schJustifyContent ?? props.justifyContent;
8749
+ const rawAlign = props.schAlignItems ?? props.alignItems;
8750
+ const rawGap = props.schFlexGap ?? props.schGap ?? props.gap;
8751
+ const direction = props.schFlexDirection ?? "row";
8752
+ const justifyContent = {
8753
+ start: "flex-start",
8754
+ end: "flex-end",
8755
+ "flex-start": "flex-start",
8756
+ "flex-end": "flex-end",
8757
+ stretch: "space-between",
8758
+ "space-between": "space-between",
8759
+ "space-around": "space-around",
8760
+ "space-evenly": "space-evenly",
8761
+ center: "center"
8762
+ }[rawJustify ?? "space-between"];
8763
+ const alignItems = {
8764
+ start: "flex-start",
8765
+ end: "flex-end",
8766
+ "flex-start": "flex-start",
8767
+ "flex-end": "flex-end",
8768
+ stretch: "stretch",
8769
+ center: "center"
8770
+ }[rawAlign ?? "center"];
8771
+ if (!justifyContent) {
8772
+ throw new Error(`Invalid justifyContent value: "${rawJustify}"`);
8773
+ }
8774
+ if (!alignItems) {
8775
+ throw new Error(`Invalid alignItems value: "${rawAlign}"`);
8776
+ }
8777
+ let rowGap = 0;
8778
+ let columnGap = 0;
8779
+ if (typeof rawGap === "object") {
8780
+ rowGap = rawGap.y ?? 0;
8781
+ columnGap = rawGap.x ?? 0;
8782
+ } else if (typeof rawGap === "number") {
8783
+ rowGap = rawGap;
8784
+ columnGap = rawGap;
8785
+ } else if (typeof rawGap === "string") {
8786
+ rowGap = length2.parse(rawGap);
8787
+ columnGap = length2.parse(rawGap);
8788
+ }
8789
+ let minFlexContainer;
8790
+ let width = props.width ?? props.schWidth ?? void 0;
8791
+ let height = props.height ?? props.schHeight ?? void 0;
8792
+ const isInline = Boolean(width === void 0 || height === void 0);
8793
+ if (isInline) {
8794
+ minFlexContainer = getMinimumFlexContainer(
8795
+ tree.childNodes.map((child) => getSizeOfTreeNodeChild(db, child)).filter((size) => size !== null),
8796
+ {
8797
+ alignItems,
8798
+ justifyContent,
8799
+ direction,
8800
+ rowGap,
8801
+ columnGap
8802
+ }
8803
+ );
8804
+ width = minFlexContainer.width;
8805
+ height = minFlexContainer.height;
8806
+ }
8807
+ const flexBox = new RootFlexBox(width, height, {
8808
+ alignItems,
8809
+ justifyContent,
8810
+ direction,
8811
+ rowGap,
8812
+ columnGap
8813
+ });
8814
+ for (const child of tree.childNodes) {
8815
+ const size = getSizeOfTreeNodeChild(db, child);
8816
+ flexBox.addChild({
8817
+ metadata: child,
8818
+ width: size?.width ?? 0,
8819
+ height: size?.height ?? 0,
8820
+ flexBasis: !size ? void 0 : direction === "row" ? size.width : size.height
8821
+ });
8822
+ }
8823
+ flexBox.build();
8824
+ const bounds = {
8825
+ minX: Infinity,
8826
+ minY: Infinity,
8827
+ maxX: -Infinity,
8828
+ maxY: -Infinity,
8829
+ width: 0,
8830
+ height: 0
8831
+ };
8832
+ for (const child of flexBox.children) {
8833
+ bounds.minX = Math.min(bounds.minX, child.position.x);
8834
+ bounds.minY = Math.min(bounds.minY, child.position.y);
8835
+ bounds.maxX = Math.max(bounds.maxX, child.position.x + child.size.width);
8836
+ bounds.maxY = Math.max(bounds.maxY, child.position.y + child.size.height);
8837
+ }
8838
+ bounds.width = bounds.maxX - bounds.minX;
8839
+ bounds.height = bounds.maxY - bounds.minY;
8840
+ const offset = {
8841
+ x: -(bounds.maxX + bounds.minX) / 2,
8842
+ y: -(bounds.maxY + bounds.minY) / 2
8843
+ };
8844
+ const allCircuitJson = db.toArray();
8845
+ for (const child of flexBox.children) {
8846
+ const { sourceComponent, sourceGroup } = child.metadata;
8847
+ if (sourceComponent) {
8848
+ const schComponent = db.schematic_component.getWhere({
8849
+ source_component_id: sourceComponent.source_component_id
8850
+ });
8851
+ if (!schComponent) continue;
8852
+ repositionSchematicComponentTo(
8853
+ allCircuitJson,
8854
+ schComponent.schematic_component_id,
8855
+ {
8856
+ x: child.position.x + child.size.width / 2 + offset.x,
8857
+ y: child.position.y + child.size.height / 2 + offset.y
8858
+ }
8859
+ );
8860
+ }
8861
+ if (sourceGroup) {
8862
+ const schGroup = db.schematic_group.getWhere({
8863
+ source_group_id: sourceGroup.source_group_id
8864
+ });
8865
+ if (!schGroup) continue;
8866
+ repositionSchematicGroupTo(allCircuitJson, sourceGroup.source_group_id, {
8867
+ x: child.position.x + child.size.width / 2 + offset.x,
8868
+ y: child.position.y + child.size.height / 2 + offset.y
8869
+ });
8870
+ }
8871
+ }
8872
+ if (group.schematic_group_id) {
8873
+ db.schematic_group.update(group.schematic_group_id, {
8874
+ width: bounds.width,
8875
+ height: bounds.height
8876
+ });
8877
+ }
8878
+ };
8879
+
8709
8880
  // lib/components/primitive-components/Group/Group_doInitialPcbLayoutGrid.ts
8710
8881
  import { translate as translate5 } from "transformation-matrix";
8711
8882
  import {
8712
8883
  transformPCBElements,
8713
8884
  getPrimaryId
8714
8885
  } from "@tscircuit/circuit-json-util";
8715
- import { length as length2 } from "circuit-json";
8886
+ import { length as length3 } from "circuit-json";
8716
8887
  function Group_doInitialPcbLayoutGrid(group) {
8717
8888
  const { db } = group.root;
8718
8889
  const props = group._parsedProps;
@@ -8769,7 +8940,7 @@ function Group_doInitialPcbLayoutGrid(group) {
8769
8940
  let gridGapY;
8770
8941
  const parseGap = (val) => {
8771
8942
  if (val === void 0) return void 0;
8772
- return typeof val === "number" ? val : length2.parse(val);
8943
+ return typeof val === "number" ? val : length3.parse(val);
8773
8944
  };
8774
8945
  if (gridRowGapOption !== void 0 || gridColumnGapOption !== void 0) {
8775
8946
  const fallbackX = typeof gridGapOption === "object" && gridGapOption !== null ? gridGapOption.x : gridGapOption;
@@ -8780,14 +8951,14 @@ function Group_doInitialPcbLayoutGrid(group) {
8780
8951
  gridGapX = gridGapOption;
8781
8952
  gridGapY = gridGapOption;
8782
8953
  } else if (typeof gridGapOption === "string") {
8783
- const parsed = length2.parse(gridGapOption);
8954
+ const parsed = length3.parse(gridGapOption);
8784
8955
  gridGapX = parsed;
8785
8956
  gridGapY = parsed;
8786
8957
  } else if (typeof gridGapOption === "object" && gridGapOption !== null) {
8787
8958
  const xRaw = gridGapOption.x;
8788
8959
  const yRaw = gridGapOption.y;
8789
- gridGapX = typeof xRaw === "number" ? xRaw : length2.parse(xRaw ?? "0mm");
8790
- gridGapY = typeof yRaw === "number" ? yRaw : length2.parse(yRaw ?? "0mm");
8960
+ gridGapX = typeof xRaw === "number" ? xRaw : length3.parse(xRaw ?? "0mm");
8961
+ gridGapY = typeof yRaw === "number" ? yRaw : length3.parse(yRaw ?? "0mm");
8791
8962
  } else {
8792
8963
  gridGapX = 1;
8793
8964
  gridGapY = 1;
@@ -8904,7 +9075,7 @@ import {
8904
9075
  convertPackOutputToPackInput,
8905
9076
  getGraphicsFromPackOutput
8906
9077
  } from "calculate-packing";
8907
- import { length as length3 } from "circuit-json";
9078
+ import { length as length4 } from "circuit-json";
8908
9079
  import {
8909
9080
  transformPCBElements as transformPCBElements2
8910
9081
  } from "@tscircuit/circuit-json-util";
@@ -8923,7 +9094,7 @@ var Group_doInitialPcbLayoutPack = (group) => {
8923
9094
  pcbPackGap
8924
9095
  } = props;
8925
9096
  const gap = pcbPackGap ?? pcbGap ?? gapProp;
8926
- const gapMm = length3.parse(gap ?? "0mm");
9097
+ const gapMm = length4.parse(gap ?? "0mm");
8927
9098
  const packInput = {
8928
9099
  ...convertPackOutputToPackInput(
8929
9100
  convertCircuitJsonToPackOutput(db.toArray(), {
@@ -8975,14 +9146,14 @@ var Group_doInitialPcbLayoutPack = (group) => {
8975
9146
 
8976
9147
  // lib/components/primitive-components/Group/Group_doInitialPcbLayoutFlex.ts
8977
9148
  import {
8978
- getCircuitJsonTree as getCircuitJsonTree2,
9149
+ getCircuitJsonTree as getCircuitJsonTree3,
8979
9150
  repositionPcbComponentTo,
8980
9151
  repositionPcbGroupTo,
8981
- getMinimumFlexContainer
9152
+ getMinimumFlexContainer as getMinimumFlexContainer2
8982
9153
  } from "@tscircuit/circuit-json-util";
8983
- import { RootFlexBox } from "@tscircuit/miniflex";
8984
- import { length as length4 } from "circuit-json";
8985
- var getSizeOfTreeNodeChild = (db, child) => {
9154
+ import { RootFlexBox as RootFlexBox2 } from "@tscircuit/miniflex";
9155
+ import { length as length5 } from "circuit-json";
9156
+ var getSizeOfTreeNodeChild2 = (db, child) => {
8986
9157
  const { sourceComponent, sourceGroup } = child;
8987
9158
  if (child.nodeType === "component") {
8988
9159
  const pcbComponent = db.pcb_component.getWhere({
@@ -9009,7 +9180,7 @@ var getSizeOfTreeNodeChild = (db, child) => {
9009
9180
  var Group_doInitialPcbLayoutFlex = (group) => {
9010
9181
  const { db } = group.root;
9011
9182
  const { _parsedProps: props } = group;
9012
- const tree = getCircuitJsonTree2(db.toArray(), {
9183
+ const tree = getCircuitJsonTree3(db.toArray(), {
9013
9184
  source_group_id: group.source_group_id
9014
9185
  });
9015
9186
  const rawJustify = props.pcbJustifyContent ?? props.justifyContent;
@@ -9050,16 +9221,16 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9050
9221
  rowGap = rawGap;
9051
9222
  columnGap = rawGap;
9052
9223
  } else if (typeof rawGap === "string") {
9053
- rowGap = length4.parse(rawGap);
9054
- columnGap = length4.parse(rawGap);
9224
+ rowGap = length5.parse(rawGap);
9225
+ columnGap = length5.parse(rawGap);
9055
9226
  }
9056
9227
  let minFlexContainer;
9057
9228
  let width = props.width ?? props.pcbWidth ?? void 0;
9058
9229
  let height = props.height ?? props.pcbHeight ?? void 0;
9059
9230
  const isInline = Boolean(width === void 0 || height === void 0);
9060
9231
  if (isInline) {
9061
- minFlexContainer = getMinimumFlexContainer(
9062
- tree.childNodes.map((child) => getSizeOfTreeNodeChild(db, child)).filter((size) => size !== null),
9232
+ minFlexContainer = getMinimumFlexContainer2(
9233
+ tree.childNodes.map((child) => getSizeOfTreeNodeChild2(db, child)).filter((size) => size !== null),
9063
9234
  {
9064
9235
  alignItems,
9065
9236
  justifyContent,
@@ -9071,7 +9242,7 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9071
9242
  width = minFlexContainer.width;
9072
9243
  height = minFlexContainer.height;
9073
9244
  }
9074
- const flexBox = new RootFlexBox(width, height, {
9245
+ const flexBox = new RootFlexBox2(width, height, {
9075
9246
  alignItems,
9076
9247
  justifyContent,
9077
9248
  direction,
@@ -9079,7 +9250,7 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9079
9250
  columnGap
9080
9251
  });
9081
9252
  for (const child of tree.childNodes) {
9082
- const size = getSizeOfTreeNodeChild(db, child);
9253
+ const size = getSizeOfTreeNodeChild2(db, child);
9083
9254
  flexBox.addChild({
9084
9255
  metadata: child,
9085
9256
  // TODO these should be minWidth/minHeight
@@ -9656,6 +9827,9 @@ var Group = class extends NormalComponent {
9656
9827
  if (props.schLayout?.matchAdapt) return "match-adapt";
9657
9828
  if (props.schLayout?.flex) return "flex";
9658
9829
  if (props.schLayout?.grid) return "grid";
9830
+ if (props.schMatchAdapt) return "match-adapt";
9831
+ if (props.schFlex) return "flex";
9832
+ if (props.schGrid) return "grid";
9659
9833
  if (props.matchAdapt) return "match-adapt";
9660
9834
  if (props.flex) return "flex";
9661
9835
  if (props.grid) return "grid";
@@ -9677,6 +9851,9 @@ var Group = class extends NormalComponent {
9677
9851
  if (schematicLayoutMode === "grid") {
9678
9852
  this._doInitialSchematicLayoutGrid();
9679
9853
  }
9854
+ if (schematicLayoutMode === "flex") {
9855
+ this._doInitialSchematicLayoutFlex();
9856
+ }
9680
9857
  this._insertSchematicBorder();
9681
9858
  }
9682
9859
  _doInitialSchematicLayoutMatchAdapt() {
@@ -9688,6 +9865,9 @@ var Group = class extends NormalComponent {
9688
9865
  _doInitialSchematicLayoutGrid() {
9689
9866
  Group_doInitialSchematicLayoutGrid(this);
9690
9867
  }
9868
+ _doInitialSchematicLayoutFlex() {
9869
+ Group_doInitialSchematicLayoutFlex(this);
9870
+ }
9691
9871
  _getPcbLayoutMode() {
9692
9872
  const props = this._parsedProps;
9693
9873
  if (props.pcbLayout?.matchAdapt) return "match-adapt";
@@ -12331,7 +12511,7 @@ import { identity as identity5 } from "transformation-matrix";
12331
12511
  var package_default = {
12332
12512
  name: "@tscircuit/core",
12333
12513
  type: "module",
12334
- version: "0.0.626",
12514
+ version: "0.0.628",
12335
12515
  types: "dist/index.d.ts",
12336
12516
  main: "dist/index.js",
12337
12517
  module: "dist/index.js",
@@ -12356,7 +12536,7 @@ var package_default = {
12356
12536
  "@biomejs/biome": "^1.8.3",
12357
12537
  "@tscircuit/capacity-autorouter": "^0.0.100",
12358
12538
  "@tscircuit/checks": "^0.0.68",
12359
- "@tscircuit/circuit-json-util": "^0.0.64",
12539
+ "@tscircuit/circuit-json-util": "^0.0.65",
12360
12540
  "@tscircuit/footprinter": "^0.0.208",
12361
12541
  "@tscircuit/import-snippet": "^0.0.4",
12362
12542
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
@@ -12375,7 +12555,7 @@ var package_default = {
12375
12555
  "@types/react-reconciler": "^0.28.9",
12376
12556
  "bpc-graph": "^0.0.57",
12377
12557
  "bun-match-svg": "0.0.12",
12378
- "calculate-elbow": "^0.0.5",
12558
+ "calculate-elbow": "^0.0.9",
12379
12559
  "chokidar-cli": "^3.0.0",
12380
12560
  "circuit-json": "^0.0.228",
12381
12561
  "circuit-json-to-bpc": "^0.0.13",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.627",
4
+ "version": "0.0.629",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -26,7 +26,7 @@
26
26
  "@biomejs/biome": "^1.8.3",
27
27
  "@tscircuit/capacity-autorouter": "^0.0.100",
28
28
  "@tscircuit/checks": "^0.0.68",
29
- "@tscircuit/circuit-json-util": "^0.0.64",
29
+ "@tscircuit/circuit-json-util": "^0.0.65",
30
30
  "@tscircuit/footprinter": "^0.0.208",
31
31
  "@tscircuit/import-snippet": "^0.0.4",
32
32
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
@@ -45,7 +45,7 @@
45
45
  "@types/react-reconciler": "^0.28.9",
46
46
  "bpc-graph": "^0.0.57",
47
47
  "bun-match-svg": "0.0.12",
48
- "calculate-elbow": "^0.0.5",
48
+ "calculate-elbow": "^0.0.9",
49
49
  "chokidar-cli": "^3.0.0",
50
50
  "circuit-json": "^0.0.228",
51
51
  "circuit-json-to-bpc": "^0.0.13",