3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-16 21:30:25 +01:00

Answer architecture round 1: every container joining several walks sums their projections before it joins, the portable reduction refuses a list whose spelling is refused, and heldTextLength moves beside textLength

This commit is contained in:
2026-10-12 17:10:56 +02:00
committed by Lillem4n
parent e3aa790ec8
commit 2b5d22cbc6
10 changed files with 101 additions and 41 deletions
+11
View File
@@ -86,6 +86,17 @@ export function textLength(node: AdfNode): number {
return node.text?.length ?? 0
}
// A line spells every character of its nodes' text at least once, so this much text cannot fit.
export function heldTextLength(nodes: readonly AdfNode[]): number {
let length = 0
const pending = [...nodes]
for (let node = pending.pop(); node !== undefined; node = pending.pop()) {
length += textLength(node)
for (const child of nodeContent(node)) pending.push(child)
}
return length
}
export function mergeAdjacentText(nodes: readonly AdfNode[], joins: (previous: AdfNode, node: AdfNode) => boolean): AdfNode[] {
const merged: AdfNode[] = []
for (const node of nodes) {