mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-09 08:59:40 +02:00
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) <noreply@anthropic.com>
This commit is contained in:
@@ -401,8 +401,9 @@ xterm. Nothing may outlive a removed tile (24-hour sessions rule).
|
|||||||
|
|
||||||
### 2. `TileGrid` controller and layout helper
|
### 2. `TileGrid` controller and layout helper
|
||||||
|
|
||||||
- `computeTileLayout({ count, width, height, minTileW, minTileH })` and
|
- `computeTileLayout({ count, width, height })` and
|
||||||
`tileGridCapacity(...)`: pure, in `constants.js`, exported on
|
`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.
|
`window.CodemanTileGrid` beside the existing helper namespaces.
|
||||||
`sanitizeTileGridState(raw, liveSessions, detachedIds)`: pure, same place.
|
`sanitizeTileGridState(raw, liveSessions, detachedIds)`: pure, same place.
|
||||||
- The controller (in a new `src/web/public/tile-grid.js`, load order 7.6, as
|
- The controller (in a new `src/web/public/tile-grid.js`, load order 7.6, as
|
||||||
|
|||||||
@@ -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
|
* 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
|
* that layout gives every cell at least the minimum tile size (TILE_MIN_W x
|
||||||
* of `width` x `height` px.
|
* 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}}
|
* @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);
|
const n = Math.min(Math.max(0, Math.floor(Number(count) || 0)), TILE_LAYOUT_MAX);
|
||||||
let cols;
|
let cols;
|
||||||
let rows;
|
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 === 4) { cols = 2; rows = 2; }
|
||||||
else if (n <= 6) { cols = 3; rows = 2; }
|
else if (n <= 6) { cols = 3; rows = 2; }
|
||||||
else { cols = 3; rows = 3; }
|
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 };
|
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
|
* whose layout, and every smaller count's layout, fits. 0 when not even one
|
||||||
* tile fits.
|
* tile fits.
|
||||||
*
|
*
|
||||||
* @param {{width: number, height: number, minTileW?: number, minTileH?: number}} p
|
* @param {{width: number, height: number}} p
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
function tileGridCapacity({ width, height, minTileW = TILE_MIN_W, minTileH = TILE_MIN_H }) {
|
function tileGridCapacity({ width, height }) {
|
||||||
let capacity = 0;
|
let capacity = 0;
|
||||||
for (let n = 1; n <= TILE_GRID_MAX; n++) {
|
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;
|
capacity = n;
|
||||||
}
|
}
|
||||||
return capacity;
|
return capacity;
|
||||||
|
|||||||
Reference in New Issue
Block a user