返回 DeepSeek-Reasonix
markdownDomBudget.ts
根目录 / desktop / frontend / src / lib / markdownDomBudget.ts
1 import type { MarkdownBlock } from "./markdownPipeline";
2 import { RESOURCE_BUDGETS } from "./resourceBudgets";
3
4 export const MARKDOWN_AST_ELEMENT_PAGE = RESOURCE_BUDGETS.markdownAstElementsPerPage;
5
6 /** Publish whole top-level blocks until the page budget is reached. */
7 export function visibleMarkdownBlockCount(blocks: readonly MarkdownBlock[], elementBudget: number): number {
8 let elements = 0;
9 for (let index = 0; index < blocks.length; index += 1) {
10 const next = Math.max(1, blocks[index]?.elementCount ?? 1);
11 // A single semantic block is indivisible and remains visible even when it
12 // exceeds the target. Tables have their own nested cell-page budget.
13 if (index > 0 && elements + next > elementBudget) return index;
14 elements += next;
15 }
16 return blocks.length;
17 }
18
18 lines TYPESCRIPT