1 | {"version":3,"file":"tiles-table.js","sources":["../../../../src/tile-layout/table-utils/tiles-table.ts"],"sourcesContent":["import { TilesTable, TilePositionInfo, TileInfo } from '../model';\nimport {\n findFirstFittingPosition,\n isEmptyRow,\n newTable,\n placeInTable,\n tableSize,\n} from './table';\n\nexport const interceptTiles = <T>(\n table: TilesTable<T>,\n startRow: number,\n startCol: number,\n rowSpan: number,\n colSpan: number\n) => {\n let interceptTiles: TilePositionInfo<T>[] = [];\n const { rows, cols } = tableSize(table);\n\n for (let row = startRow; row < startRow + rowSpan; row++) {\n if (row >= rows) continue;\n for (let col = startCol; col < startCol + colSpan; col++) {\n if (col >= cols) continue;\n const cell = table[row][col];\n if (cell && !interceptTiles.find(t => t.data === cell.data)) {\n interceptTiles.push(cell);\n }\n }\n }\n\n return interceptTiles.sort(\n (a, b) => a.col + a.row * cols - (b.col + b.row * cols)\n );\n};\n\nexport const tableToTilesList = <T>(table: TilesTable<T>) => {\n const { rows, cols } = tableSize(table);\n return interceptTiles(table, 0, 0, rows, cols);\n};\n\nexport const tilesListToTable = <T>(\n tiles: TileInfo<T>[],\n columns: number\n): TilesTable<T> => {\n const maxRows = tiles.reduce((memo, tile) => memo + tile.rowSpan, 0);\n let table = newTable<TilePositionInfo<T> | undefined>(\n maxRows,\n columns,\n undefined\n );\n tiles.forEach(tile => {\n let position = findFirstFittingPosition(tile, table);\n if (position) {\n const fittedTile: TilePositionInfo<T> = { ...tile, ...position };\n table = placeInTable(fittedTile, fittedTile, table);\n }\n });\n\n //trim the table\n\n return table.filter(row => !isEmptyRow(row)) as TilesTable<T>;\n};\n"],"names":[],"mappings":";;;IASa,cAAc,GAAG,UAC5B,KAAoB,EACpB,QAAgB,EAChB,QAAgB,EAChB,OAAe,EACf,OAAe;IAEf,IAAI,cAAc,GAA0B,EAAE,CAAC;IACzC,IAAA,KAAiB,SAAS,CAAC,KAAK,CAAC,EAA/B,IAAI,UAAA,EAAE,IAAI,UAAqB,CAAC;IAExC,KAAK,IAAI,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