/* Copyright 2026 Marimo. All rights reserved. */ import type { CellId } from "@/core/cells/ids"; import type { SlideType, SlidesLayout } from "./types"; export interface SlideCellLike { id: CellId; output: { data: unknown } | null; } export interface SlideCellsInfo { cellsWithOutput: T[]; skippedIds: Set; slideTypes: Map; // Index of the first cell in `cellsWithOutput` that is not skipped startCellIndex: number; } export function computeSlideCellsInfo( cells: readonly T[], layout: Pick, ): SlideCellsInfo { const cellsWithOutput = cells.filter( (cell) => cell.output != null && cell.output.data !== "", ); const skippedIds = new Set(); const slideTypes = new Map(); let startCell: T | null = null; let startCellIndex = 0; for (const [index, cell] of cellsWithOutput.entries()) { const type = layout.cells.get(cell.id)?.type; if (type) { slideTypes.set(cell.id, type); } if (type === "skip") { skippedIds.add(cell.id); } else if (startCell === null) { startCell = cell; startCellIndex = index; } } return { cellsWithOutput, skippedIds, slideTypes, startCellIndex, }; }