@tscircuit/core 0.0.1003 → 0.0.1004

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 (2) hide show
  1. package/dist/index.js +100 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -16964,6 +16964,49 @@ var getBoardDimensionsFromProps = (board) => {
16964
16964
  };
16965
16965
 
16966
16966
  // lib/utils/panels/pack-boards-into-grid.ts
16967
+ function calculateOptimalGrid({
16968
+ boardsWithDims,
16969
+ availableWidth,
16970
+ availableHeight,
16971
+ boardGap,
16972
+ minCellWidth,
16973
+ minCellHeight
16974
+ }) {
16975
+ const boardCount = boardsWithDims.length;
16976
+ if (boardCount === 0) {
16977
+ return { rows: 0, cols: 0 };
16978
+ }
16979
+ const maxBoardWidth = Math.max(
16980
+ ...boardsWithDims.map((b) => b.width),
16981
+ minCellWidth
16982
+ );
16983
+ const maxBoardHeight = Math.max(
16984
+ ...boardsWithDims.map((b) => b.height),
16985
+ minCellHeight
16986
+ );
16987
+ const maxCols = Math.max(
16988
+ 1,
16989
+ Math.floor((availableWidth + boardGap) / (maxBoardWidth + boardGap))
16990
+ );
16991
+ const maxRows = Math.max(
16992
+ 1,
16993
+ Math.floor((availableHeight + boardGap) / (maxBoardHeight + boardGap))
16994
+ );
16995
+ let bestCols = maxCols;
16996
+ let bestRows = Math.ceil(boardCount / bestCols);
16997
+ if (bestRows > maxRows) {
16998
+ bestRows = maxRows;
16999
+ bestCols = Math.ceil(boardCount / bestRows);
17000
+ if (bestCols > maxCols) {
17001
+ bestCols = maxCols;
17002
+ bestRows = Math.ceil(boardCount / bestCols);
17003
+ }
17004
+ }
17005
+ return {
17006
+ rows: Math.max(1, bestRows),
17007
+ cols: Math.max(1, bestCols)
17008
+ };
17009
+ }
16967
17010
  var packBoardsIntoGrid = ({
16968
17011
  boards,
16969
17012
  db,
@@ -16971,7 +17014,9 @@ var packBoardsIntoGrid = ({
16971
17014
  col,
16972
17015
  cellWidth,
16973
17016
  cellHeight,
16974
- boardGap
17017
+ boardGap,
17018
+ availablePanelWidth,
17019
+ availablePanelHeight
16975
17020
  }) => {
16976
17021
  const boardsWithDims = boards.map((board) => {
16977
17022
  let width;
@@ -17002,8 +17047,29 @@ var packBoardsIntoGrid = ({
17002
17047
  }
17003
17048
  const explicitRow = row;
17004
17049
  const explicitCol = col;
17005
- const cols = explicitCol ?? (explicitRow ? Math.ceil(boardsWithDims.length / explicitRow) : Math.ceil(Math.sqrt(boardsWithDims.length)));
17006
- const rows = explicitRow ?? Math.ceil(boardsWithDims.length / cols);
17050
+ let cols;
17051
+ let rows;
17052
+ if (explicitCol !== void 0) {
17053
+ cols = explicitCol;
17054
+ rows = explicitRow ?? Math.ceil(boardsWithDims.length / cols);
17055
+ } else if (explicitRow !== void 0) {
17056
+ rows = explicitRow;
17057
+ cols = Math.ceil(boardsWithDims.length / rows);
17058
+ } else if (availablePanelWidth !== void 0 && availablePanelHeight !== void 0) {
17059
+ const result = calculateOptimalGrid({
17060
+ boardsWithDims,
17061
+ availableWidth: availablePanelWidth,
17062
+ availableHeight: availablePanelHeight,
17063
+ boardGap,
17064
+ minCellWidth: cellWidth ? distance10.parse(cellWidth) : 0,
17065
+ minCellHeight: cellHeight ? distance10.parse(cellHeight) : 0
17066
+ });
17067
+ cols = result.cols;
17068
+ rows = result.rows;
17069
+ } else {
17070
+ cols = Math.ceil(Math.sqrt(boardsWithDims.length));
17071
+ rows = Math.ceil(boardsWithDims.length / cols);
17072
+ }
17007
17073
  const colWidths = Array(cols).fill(0);
17008
17074
  const rowHeights = Array(rows).fill(0);
17009
17075
  boardsWithDims.forEach((b, i) => {
@@ -17158,13 +17224,42 @@ var Subpanel = class _Subpanel extends Group6 {
17158
17224
  if (layoutMode !== "grid") return;
17159
17225
  const tabWidth = this._parsedProps.tabWidth ?? DEFAULT_TAB_WIDTH;
17160
17226
  const boardGap = this._parsedProps.boardGap ?? tabWidth;
17227
+ let availablePanelWidth;
17228
+ let availablePanelHeight;
17229
+ const hasExplicitRowOrCol = this._parsedProps.row !== void 0 || this._parsedProps.col !== void 0;
17230
+ const hasExplicitWidth = this._parsedProps.width !== void 0;
17231
+ const hasExplicitHeight = this._parsedProps.height !== void 0;
17232
+ if (!hasExplicitRowOrCol && hasExplicitWidth && hasExplicitHeight) {
17233
+ const {
17234
+ edgePadding: edgePaddingProp,
17235
+ edgePaddingLeft: edgePaddingLeftProp,
17236
+ edgePaddingRight: edgePaddingRightProp,
17237
+ edgePaddingTop: edgePaddingTopProp,
17238
+ edgePaddingBottom: edgePaddingBottomProp
17239
+ } = this._parsedProps;
17240
+ const edgePadding = distance11.parse(edgePaddingProp ?? 5);
17241
+ const edgePaddingLeft = distance11.parse(edgePaddingLeftProp ?? edgePadding);
17242
+ const edgePaddingRight = distance11.parse(
17243
+ edgePaddingRightProp ?? edgePadding
17244
+ );
17245
+ const edgePaddingTop = distance11.parse(edgePaddingTopProp ?? edgePadding);
17246
+ const edgePaddingBottom = distance11.parse(
17247
+ edgePaddingBottomProp ?? edgePadding
17248
+ );
17249
+ const panelWidth = distance11.parse(this._parsedProps.width);
17250
+ const panelHeight = distance11.parse(this._parsedProps.height);
17251
+ availablePanelWidth = panelWidth - edgePaddingLeft - edgePaddingRight;
17252
+ availablePanelHeight = panelHeight - edgePaddingTop - edgePaddingBottom;
17253
+ }
17161
17254
  const { positions, gridWidth, gridHeight } = packBoardsIntoGrid({
17162
17255
  boards: childBoardInstances,
17163
17256
  row: this._parsedProps.row,
17164
17257
  col: this._parsedProps.col,
17165
17258
  cellWidth: this._parsedProps.cellWidth,
17166
17259
  cellHeight: this._parsedProps.cellHeight,
17167
- boardGap
17260
+ boardGap,
17261
+ availablePanelHeight,
17262
+ availablePanelWidth
17168
17263
  });
17169
17264
  this._cachedGridWidth = gridWidth;
17170
17265
  this._cachedGridHeight = gridHeight;
@@ -21605,7 +21700,7 @@ import { identity as identity5 } from "transformation-matrix";
21605
21700
  var package_default = {
21606
21701
  name: "@tscircuit/core",
21607
21702
  type: "module",
21608
- version: "0.0.1002",
21703
+ version: "0.0.1003",
21609
21704
  types: "dist/index.d.ts",
21610
21705
  main: "dist/index.js",
21611
21706
  module: "dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1003",
4
+ "version": "0.0.1004",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",