@tscircuit/core 0.0.626 → 0.0.628

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
  };
@@ -5080,7 +5080,10 @@ var Trace_doInitialSchematicTraceRender = (trace) => {
5080
5080
  connectedPorts = result.portsWithSelectors ?? [];
5081
5081
  } catch (error) {
5082
5082
  if (error instanceof TraceConnectionError) {
5083
- db.source_trace_not_connected.insert(error.errorData);
5083
+ db.source_trace_not_connected_error.insert({
5084
+ ...error.errorData,
5085
+ error_type: "source_trace_not_connected_error"
5086
+ });
5084
5087
  return;
5085
5088
  }
5086
5089
  throw error;
@@ -5897,7 +5900,7 @@ function Trace__findConnectedPorts(trace) {
5897
5900
  const subcircuit2 = trace.getSubcircuit();
5898
5901
  const sourceGroup2 = subcircuit2.getGroup();
5899
5902
  throw new TraceConnectionError({
5900
- error_type: "source_trace_not_connected",
5903
+ error_type: "source_trace_not_connected_error",
5901
5904
  message: errorMessage2,
5902
5905
  subcircuit_id: subcircuit2.subcircuit_id ?? void 0,
5903
5906
  source_group_id: sourceGroup2?.source_group_id ?? void 0,
@@ -5924,7 +5927,7 @@ function Trace__findConnectedPorts(trace) {
5924
5927
  const subcircuit = trace.getSubcircuit();
5925
5928
  const sourceGroup = subcircuit.getGroup();
5926
5929
  throw new TraceConnectionError({
5927
- error_type: "source_trace_not_connected",
5930
+ error_type: "source_trace_not_connected_error",
5928
5931
  message: errorMessage,
5929
5932
  subcircuit_id: subcircuit.subcircuit_id ?? void 0,
5930
5933
  source_group_id: sourceGroup?.source_group_id ?? void 0,
@@ -6076,7 +6079,10 @@ var Trace3 = class extends PrimitiveComponent2 {
6076
6079
  ports = result.portsWithSelectors ?? [];
6077
6080
  } catch (error) {
6078
6081
  if (error instanceof TraceConnectionError) {
6079
- db.source_trace_not_connected.insert(error.errorData);
6082
+ db.source_trace_not_connected_error.insert({
6083
+ ...error.errorData,
6084
+ error_type: "source_trace_not_connected_error"
6085
+ });
6080
6086
  this._couldNotFindPort = true;
6081
6087
  return;
6082
6088
  }
@@ -8700,13 +8706,184 @@ function Group_doInitialSchematicLayoutGrid(group) {
8700
8706
  }
8701
8707
  }
8702
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
+
8703
8880
  // lib/components/primitive-components/Group/Group_doInitialPcbLayoutGrid.ts
8704
8881
  import { translate as translate5 } from "transformation-matrix";
8705
8882
  import {
8706
8883
  transformPCBElements,
8707
8884
  getPrimaryId
8708
8885
  } from "@tscircuit/circuit-json-util";
8709
- import { length as length2 } from "circuit-json";
8886
+ import { length as length3 } from "circuit-json";
8710
8887
  function Group_doInitialPcbLayoutGrid(group) {
8711
8888
  const { db } = group.root;
8712
8889
  const props = group._parsedProps;
@@ -8763,7 +8940,7 @@ function Group_doInitialPcbLayoutGrid(group) {
8763
8940
  let gridGapY;
8764
8941
  const parseGap = (val) => {
8765
8942
  if (val === void 0) return void 0;
8766
- return typeof val === "number" ? val : length2.parse(val);
8943
+ return typeof val === "number" ? val : length3.parse(val);
8767
8944
  };
8768
8945
  if (gridRowGapOption !== void 0 || gridColumnGapOption !== void 0) {
8769
8946
  const fallbackX = typeof gridGapOption === "object" && gridGapOption !== null ? gridGapOption.x : gridGapOption;
@@ -8774,14 +8951,14 @@ function Group_doInitialPcbLayoutGrid(group) {
8774
8951
  gridGapX = gridGapOption;
8775
8952
  gridGapY = gridGapOption;
8776
8953
  } else if (typeof gridGapOption === "string") {
8777
- const parsed = length2.parse(gridGapOption);
8954
+ const parsed = length3.parse(gridGapOption);
8778
8955
  gridGapX = parsed;
8779
8956
  gridGapY = parsed;
8780
8957
  } else if (typeof gridGapOption === "object" && gridGapOption !== null) {
8781
8958
  const xRaw = gridGapOption.x;
8782
8959
  const yRaw = gridGapOption.y;
8783
- gridGapX = typeof xRaw === "number" ? xRaw : length2.parse(xRaw ?? "0mm");
8784
- 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");
8785
8962
  } else {
8786
8963
  gridGapX = 1;
8787
8964
  gridGapY = 1;
@@ -8898,7 +9075,7 @@ import {
8898
9075
  convertPackOutputToPackInput,
8899
9076
  getGraphicsFromPackOutput
8900
9077
  } from "calculate-packing";
8901
- import { length as length3 } from "circuit-json";
9078
+ import { length as length4 } from "circuit-json";
8902
9079
  import {
8903
9080
  transformPCBElements as transformPCBElements2
8904
9081
  } from "@tscircuit/circuit-json-util";
@@ -8917,7 +9094,7 @@ var Group_doInitialPcbLayoutPack = (group) => {
8917
9094
  pcbPackGap
8918
9095
  } = props;
8919
9096
  const gap = pcbPackGap ?? pcbGap ?? gapProp;
8920
- const gapMm = length3.parse(gap ?? "0mm");
9097
+ const gapMm = length4.parse(gap ?? "0mm");
8921
9098
  const packInput = {
8922
9099
  ...convertPackOutputToPackInput(
8923
9100
  convertCircuitJsonToPackOutput(db.toArray(), {
@@ -8969,14 +9146,14 @@ var Group_doInitialPcbLayoutPack = (group) => {
8969
9146
 
8970
9147
  // lib/components/primitive-components/Group/Group_doInitialPcbLayoutFlex.ts
8971
9148
  import {
8972
- getCircuitJsonTree as getCircuitJsonTree2,
9149
+ getCircuitJsonTree as getCircuitJsonTree3,
8973
9150
  repositionPcbComponentTo,
8974
9151
  repositionPcbGroupTo,
8975
- getMinimumFlexContainer
9152
+ getMinimumFlexContainer as getMinimumFlexContainer2
8976
9153
  } from "@tscircuit/circuit-json-util";
8977
- import { RootFlexBox } from "@tscircuit/miniflex";
8978
- import { length as length4 } from "circuit-json";
8979
- 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) => {
8980
9157
  const { sourceComponent, sourceGroup } = child;
8981
9158
  if (child.nodeType === "component") {
8982
9159
  const pcbComponent = db.pcb_component.getWhere({
@@ -9003,7 +9180,7 @@ var getSizeOfTreeNodeChild = (db, child) => {
9003
9180
  var Group_doInitialPcbLayoutFlex = (group) => {
9004
9181
  const { db } = group.root;
9005
9182
  const { _parsedProps: props } = group;
9006
- const tree = getCircuitJsonTree2(db.toArray(), {
9183
+ const tree = getCircuitJsonTree3(db.toArray(), {
9007
9184
  source_group_id: group.source_group_id
9008
9185
  });
9009
9186
  const rawJustify = props.pcbJustifyContent ?? props.justifyContent;
@@ -9044,16 +9221,16 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9044
9221
  rowGap = rawGap;
9045
9222
  columnGap = rawGap;
9046
9223
  } else if (typeof rawGap === "string") {
9047
- rowGap = length4.parse(rawGap);
9048
- columnGap = length4.parse(rawGap);
9224
+ rowGap = length5.parse(rawGap);
9225
+ columnGap = length5.parse(rawGap);
9049
9226
  }
9050
9227
  let minFlexContainer;
9051
9228
  let width = props.width ?? props.pcbWidth ?? void 0;
9052
9229
  let height = props.height ?? props.pcbHeight ?? void 0;
9053
9230
  const isInline = Boolean(width === void 0 || height === void 0);
9054
9231
  if (isInline) {
9055
- minFlexContainer = getMinimumFlexContainer(
9056
- 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),
9057
9234
  {
9058
9235
  alignItems,
9059
9236
  justifyContent,
@@ -9065,7 +9242,7 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9065
9242
  width = minFlexContainer.width;
9066
9243
  height = minFlexContainer.height;
9067
9244
  }
9068
- const flexBox = new RootFlexBox(width, height, {
9245
+ const flexBox = new RootFlexBox2(width, height, {
9069
9246
  alignItems,
9070
9247
  justifyContent,
9071
9248
  direction,
@@ -9073,7 +9250,7 @@ var Group_doInitialPcbLayoutFlex = (group) => {
9073
9250
  columnGap
9074
9251
  });
9075
9252
  for (const child of tree.childNodes) {
9076
- const size = getSizeOfTreeNodeChild(db, child);
9253
+ const size = getSizeOfTreeNodeChild2(db, child);
9077
9254
  flexBox.addChild({
9078
9255
  metadata: child,
9079
9256
  // TODO these should be minWidth/minHeight
@@ -9650,6 +9827,9 @@ var Group = class extends NormalComponent {
9650
9827
  if (props.schLayout?.matchAdapt) return "match-adapt";
9651
9828
  if (props.schLayout?.flex) return "flex";
9652
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";
9653
9833
  if (props.matchAdapt) return "match-adapt";
9654
9834
  if (props.flex) return "flex";
9655
9835
  if (props.grid) return "grid";
@@ -9671,6 +9851,9 @@ var Group = class extends NormalComponent {
9671
9851
  if (schematicLayoutMode === "grid") {
9672
9852
  this._doInitialSchematicLayoutGrid();
9673
9853
  }
9854
+ if (schematicLayoutMode === "flex") {
9855
+ this._doInitialSchematicLayoutFlex();
9856
+ }
9674
9857
  this._insertSchematicBorder();
9675
9858
  }
9676
9859
  _doInitialSchematicLayoutMatchAdapt() {
@@ -9682,6 +9865,9 @@ var Group = class extends NormalComponent {
9682
9865
  _doInitialSchematicLayoutGrid() {
9683
9866
  Group_doInitialSchematicLayoutGrid(this);
9684
9867
  }
9868
+ _doInitialSchematicLayoutFlex() {
9869
+ Group_doInitialSchematicLayoutFlex(this);
9870
+ }
9685
9871
  _getPcbLayoutMode() {
9686
9872
  const props = this._parsedProps;
9687
9873
  if (props.pcbLayout?.matchAdapt) return "match-adapt";
@@ -12325,7 +12511,7 @@ import { identity as identity5 } from "transformation-matrix";
12325
12511
  var package_default = {
12326
12512
  name: "@tscircuit/core",
12327
12513
  type: "module",
12328
- version: "0.0.625",
12514
+ version: "0.0.627",
12329
12515
  types: "dist/index.d.ts",
12330
12516
  main: "dist/index.js",
12331
12517
  module: "dist/index.js",
@@ -12349,8 +12535,8 @@ var package_default = {
12349
12535
  devDependencies: {
12350
12536
  "@biomejs/biome": "^1.8.3",
12351
12537
  "@tscircuit/capacity-autorouter": "^0.0.100",
12352
- "@tscircuit/checks": "^0.0.64",
12353
- "@tscircuit/circuit-json-util": "^0.0.64",
12538
+ "@tscircuit/checks": "^0.0.68",
12539
+ "@tscircuit/circuit-json-util": "^0.0.65",
12354
12540
  "@tscircuit/footprinter": "^0.0.208",
12355
12541
  "@tscircuit/import-snippet": "^0.0.4",
12356
12542
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
@@ -12371,7 +12557,7 @@ var package_default = {
12371
12557
  "bun-match-svg": "0.0.12",
12372
12558
  "calculate-elbow": "^0.0.5",
12373
12559
  "chokidar-cli": "^3.0.0",
12374
- "circuit-json": "^0.0.226",
12560
+ "circuit-json": "^0.0.228",
12375
12561
  "circuit-json-to-bpc": "^0.0.13",
12376
12562
  "circuit-json-to-connectivity-map": "^0.0.22",
12377
12563
  "circuit-json-to-simple-3d": "^0.0.6",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.626",
4
+ "version": "0.0.628",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -25,8 +25,8 @@
25
25
  "devDependencies": {
26
26
  "@biomejs/biome": "^1.8.3",
27
27
  "@tscircuit/capacity-autorouter": "^0.0.100",
28
- "@tscircuit/checks": "^0.0.64",
29
- "@tscircuit/circuit-json-util": "^0.0.64",
28
+ "@tscircuit/checks": "^0.0.68",
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",
@@ -47,7 +47,7 @@
47
47
  "bun-match-svg": "0.0.12",
48
48
  "calculate-elbow": "^0.0.5",
49
49
  "chokidar-cli": "^3.0.0",
50
- "circuit-json": "^0.0.226",
50
+ "circuit-json": "^0.0.228",
51
51
  "circuit-json-to-bpc": "^0.0.13",
52
52
  "circuit-json-to-connectivity-map": "^0.0.22",
53
53
  "circuit-json-to-simple-3d": "^0.0.6",