From 0746cffe6d39204b1af519d7bab71448e65e9abb Mon Sep 17 00:00:00 2001 From: Codeman maintainer Date: Wed, 7 Oct 2026 03:47:55 +0200 Subject: [PATCH] refactor(tiles): the layout helpers read the minimum tile size directly computeTileLayout and tileGridCapacity took minTileW / minTileH, defaulted to TILE_MIN_W / TILE_MIN_H, and no caller or test ever passed them. The parameters are gone and both read the constants; the spec's signature line says so. Co-Authored-By: Claude Opus 5.5 (1M context) --- docs/tile-grid-plan.md | 5 +++-- src/web/public/constants.js | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/tile-grid-plan.md b/docs/tile-grid-plan.md index 930823bc..f518cd81 100644 --- a/docs/tile-grid-plan.md +++ b/docs/tile-grid-plan.md @@ -401,8 +401,9 @@ xterm. Nothing may outlive a removed tile (24-hour sessions rule). ### 2. `TileGrid` controller and layout helper -- `computeTileLayout({ count, width, height, minTileW, minTileH })` and - `tileGridCapacity(...)`: pure, in `constants.js`, exported on +- `computeTileLayout({ count, width, height })` and + `tileGridCapacity({ width, height })` (against the minimum tile size, + `TILE_MIN_W` x `TILE_MIN_H`): pure, in `constants.js`, exported on `window.CodemanTileGrid` beside the existing helper namespaces. `sanitizeTileGridState(raw, liveSessions, detachedIds)`: pure, same place. - The controller (in a new `src/web/public/tile-grid.js`, load order 7.6, as diff --git a/src/web/public/constants.js b/src/web/public/constants.js index bdcbd790..b0a802c0 100644 --- a/src/web/public/constants.js +++ b/src/web/public/constants.js @@ -1672,13 +1672,13 @@ const TILE_GRID_SSE_FILTER = 'tile-grid'; /** * Columns and rows for `count` tiles, by count (the spec's table), and whether - * that layout gives every cell at least the minimum tile size in a grid area - * of `width` x `height` px. + * that layout gives every cell at least the minimum tile size (TILE_MIN_W x + * TILE_MIN_H) in a grid area of `width` x `height` px. * - * @param {{count: number, width?: number, height?: number, minTileW?: number, minTileH?: number}} p + * @param {{count: number, width?: number, height?: number}} p * @returns {{cols: number, rows: number, fits: boolean}} */ -function computeTileLayout({ count, width = Infinity, height = Infinity, minTileW = TILE_MIN_W, minTileH = TILE_MIN_H }) { +function computeTileLayout({ count, width = Infinity, height = Infinity }) { const n = Math.min(Math.max(0, Math.floor(Number(count) || 0)), TILE_LAYOUT_MAX); let cols; let rows; @@ -1692,7 +1692,7 @@ function computeTileLayout({ count, width = Infinity, height = Infinity, minTile else if (n === 4) { cols = 2; rows = 2; } else if (n <= 6) { cols = 3; rows = 2; } else { cols = 3; rows = 3; } - const fits = width / cols >= minTileW && height / rows >= minTileH; + const fits = width / cols >= TILE_MIN_W && height / rows >= TILE_MIN_H; return { cols, rows, fits }; } @@ -1701,13 +1701,13 @@ function computeTileLayout({ count, width = Infinity, height = Infinity, minTile * whose layout, and every smaller count's layout, fits. 0 when not even one * tile fits. * - * @param {{width: number, height: number, minTileW?: number, minTileH?: number}} p + * @param {{width: number, height: number}} p * @returns {number} */ -function tileGridCapacity({ width, height, minTileW = TILE_MIN_W, minTileH = TILE_MIN_H }) { +function tileGridCapacity({ width, height }) { let capacity = 0; for (let n = 1; n <= TILE_GRID_MAX; n++) { - if (!computeTileLayout({ count: n, width, height, minTileW, minTileH }).fits) break; + if (!computeTileLayout({ count: n, width, height }).fits) break; capacity = n; } return capacity;