@createiq/htmldiff 1.0.5-beta.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"HtmlDiff.cjs","names":["Utils","Utils","Utils"],"sources":["../src/Match.ts","../src/Utils.ts","../src/MatchFinder.ts","../src/Operation.ts","../src/TableDiff.ts","../src/WordSplitter.ts","../src/HtmlDiff.ts"],"sourcesContent":["export default class Match {\n private _startInOld: number\n private _startInNew: number\n private _size: number\n\n constructor(startInOld: number, startInNew: number, size: number) {\n this._startInOld = startInOld\n this._startInNew = startInNew\n this._size = size\n }\n\n get startInOld() {\n return this._startInOld\n }\n\n get startInNew() {\n return this._startInNew\n }\n\n get size() {\n return this._size\n }\n\n get endInOld() {\n return this._startInOld + this._size\n }\n\n get endInNew() {\n return this._startInNew + this._size\n }\n}\n","const openingTagRegex = /^\\s*<[^>]+>\\s*$/\nconst closingTagTexRegex = /^\\s*<\\/[^>]+>\\s*$/\nconst tagWordRegex = /<[^\\s>]+/\nconst whitespaceRegex = /^(\\s|&nbsp;)+$/\nconst wordRegex = /[\\w#@]+/\nconst tagRegex = /<\\/?(?<name>[^\\s/>]+)[^>]*>/\n\nconst SpecialCaseWordTags: readonly string[] = ['<img']\n\nexport function isTag(item: string): boolean {\n if (SpecialCaseWordTags.some(re => item?.startsWith(re))) {\n return false\n }\n\n return isOpeningTag(item) || isClosingTag(item)\n}\n\nfunction isOpeningTag(item: string): boolean {\n return openingTagRegex.test(item)\n}\n\nfunction isClosingTag(item: string): boolean {\n return closingTagTexRegex.test(item)\n}\n\nexport function stripTagAttributes(word: string): string {\n const match = tagWordRegex.exec(word)\n if (match) {\n return `${match[0]}${word.endsWith('/>') ? '/>' : '>'}`\n }\n\n return word\n}\n\nexport function wrapText(text: string, tagName: string, cssClass: string): string {\n return `<${tagName} class='${cssClass}'>${text}</${tagName}>`\n}\n\nexport function isStartOfTag(val: string): boolean {\n return val === '<'\n}\n\nexport function isEndOfTag(val: string): boolean {\n return val === '>'\n}\n\nexport function isStartOfEntity(val: string): boolean {\n return val === '&'\n}\n\nexport function isEndOfEntity(val: string): boolean {\n return val === ';'\n}\n\nexport function isWhiteSpace(value: string): boolean {\n return whitespaceRegex.test(value)\n}\n\nexport function stripAnyAttributes(word: string): string {\n if (isTag(word)) {\n return stripTagAttributes(word)\n }\n\n return word\n}\n\nexport function isWord(text: string): boolean {\n return wordRegex.test(text)\n}\n\nexport function getTagName(word: string | null): string {\n if (word === null) {\n return ''\n }\n\n const match = tagRegex.exec(word)\n if (match) {\n return match.groups?.name.toLowerCase() ?? match[1].toLowerCase()\n }\n\n return ''\n}\n\nexport default {\n isTag,\n stripTagAttributes,\n wrapText,\n isStartOfTag,\n isEndOfTag,\n isStartOfEntity,\n isEndOfEntity,\n isWhiteSpace,\n stripAnyAttributes,\n isWord,\n getTagName,\n}\n","import Match from './Match'\nimport type MatchOptions from './MatchOptions'\nimport Utils from './Utils'\n\n/**\n * Finds the longest match in given texts. It uses indexing with fixed granularity that is used to compare blocks of text.\n */\nexport default class MatchFinder {\n private oldWords: string[]\n private newWords: string[]\n private startInOld: number\n private endInOld: number\n private startInNew: number\n private endInNew: number\n private wordIndices: { [word: string]: number[] } = {}\n private options: MatchOptions\n\n constructor(\n oldWords: string[],\n newWords: string[],\n startInOld: number,\n endInOld: number,\n startInNew: number,\n endInNew: number,\n options: MatchOptions\n ) {\n this.oldWords = oldWords\n this.newWords = newWords\n this.startInOld = startInOld\n this.endInOld = endInOld\n this.startInNew = startInNew\n this.endInNew = endInNew\n this.options = options\n }\n\n private indexNewWords() {\n this.wordIndices = {}\n const block: string[] = []\n for (let i = this.startInNew; i < this.endInNew; i++) {\n // if word is a tag, we should ignore attributes as attribute changes are not supported (yet)\n const word = this.normalizeForIndex(this.newWords[i])\n const key = MatchFinder.putNewWord(block, word, this.options.blockSize)\n\n if (key === null) {\n continue\n }\n\n if (!this.wordIndices[key]) {\n this.wordIndices[key] = []\n }\n this.wordIndices[key].push(i)\n }\n }\n\n private static putNewWord(block: string[], word: string, blockSize: number): string | null {\n block.push(word)\n\n if (block.length > blockSize) {\n block.shift()\n }\n\n if (block.length !== blockSize) {\n return null\n }\n\n return block.join('')\n }\n\n private normalizeForIndex(word: string): string {\n const output = Utils.stripAnyAttributes(word)\n if (this.options.ignoreWhitespaceDifferences && Utils.isWhiteSpace(output)) {\n return ' '\n }\n\n return output\n }\n\n findMatch(): Match | null {\n this.indexNewWords()\n this.removeRepeatingWords()\n\n let hasIndices = false\n for (const _key in this.wordIndices) {\n hasIndices = true\n break\n }\n if (!hasIndices) {\n return null\n }\n\n let bestMatchInOld = this.startInOld\n let bestMatchInNew = this.startInNew\n let bestMatchSize = 0\n\n let matchLengthAt: Map<number, number> = new Map()\n const block: string[] = []\n\n for (let indexInOld = this.startInOld; indexInOld < this.endInOld; indexInOld++) {\n const word = this.normalizeForIndex(this.oldWords[indexInOld])\n const index = MatchFinder.putNewWord(block, word, this.options.blockSize)\n\n if (index === null) {\n continue\n }\n\n const newMatchLengthAt: Map<number, number> = new Map()\n\n if (!this.wordIndices[index]) {\n matchLengthAt = newMatchLengthAt\n continue\n }\n\n for (const indexInNew of this.wordIndices[index]) {\n // biome-ignore lint/style/noNonNullAssertion: This is safe as guarded by has()\n const newMatchLength = (matchLengthAt.has(indexInNew - 1) ? matchLengthAt.get(indexInNew - 1)! : 0) + 1\n newMatchLengthAt.set(indexInNew, newMatchLength)\n\n if (newMatchLength > bestMatchSize) {\n bestMatchInOld = indexInOld - newMatchLength - this.options.blockSize + 2\n bestMatchInNew = indexInNew - newMatchLength - this.options.blockSize + 2\n bestMatchSize = newMatchLength\n }\n }\n\n matchLengthAt = newMatchLengthAt\n }\n\n return bestMatchSize !== 0\n ? new Match(bestMatchInOld, bestMatchInNew, bestMatchSize + this.options.blockSize - 1)\n : null\n }\n\n /**\n * This method removes words that occur too many times. This way it reduces total count of comparison operations\n * and as result the diff algorithm takes less time. But the side effect is that it may detect false differences of\n * the repeating words.\n * @private\n */\n private removeRepeatingWords() {\n const threshold = this.newWords.length * this.options.repeatingWordsAccuracy\n const repeatingWords = Object.entries(this.wordIndices)\n .filter(([, indices]) => indices.length > threshold)\n .map(([word]) => word)\n\n for (const w of repeatingWords) {\n delete this.wordIndices[w]\n }\n }\n}\n","import type Action from './Action'\n\nexport default class Operation {\n action: Action\n startInOld: number\n endInOld: number\n startInNew: number\n endInNew: number\n\n constructor(action: Action, startInOld: number, endInOld: number, startInNew: number, endInNew: number) {\n this.action = action\n this.startInOld = startInOld\n this.endInOld = endInOld\n this.startInNew = startInNew\n this.endInNew = endInNew\n }\n}\n","/**\n * Table-aware preprocessing for HtmlDiff.\n *\n * The word-level diff alone matches longest-common-subsequences across cell\n * boundaries and produces structurally wrong output for table edits — it\n * shuffles content between cells, introduces phantom `<td>`s, and provides\n * no signal that an entire row or column was added/deleted. We pre-process\n * the inputs to give Word-style results:\n *\n * • When dimensions match (same row count, same cell count per row), we\n * diff cell content positionally so cross-cell shifts produce one\n * independent del/ins per cell.\n * • When dimensions don't match (added/deleted row, added/deleted column),\n * we run a row-level LCS to identify structurally added/deleted rows,\n * then within preserved rows a cell-level LCS to identify added/deleted\n * columns. Structurally added rows/cells get `class='diffins'` on the\n * `<tr>`/`<td>`; deleted ones get `class='diffdel'`. Preserved cells\n * fall back to a content diff via the recursive HtmlDiff callback.\n *\n * Tables are spliced out into placeholders before the main diff runs and\n * spliced back in after, so the surrounding (non-table) content is diffed\n * by the normal word-level pipeline.\n */\n\ninterface CellRange {\n /** Start index of the cell's opening tag in the original html. */\n cellStart: number\n /** Index just past the cell's closing tag. */\n cellEnd: number\n /** Cell content range — the slice we feed into the cell-level diff. */\n contentStart: number\n contentEnd: number\n}\n\ninterface RowRange {\n rowStart: number\n rowEnd: number\n cells: CellRange[]\n}\n\ninterface TableRange {\n tableStart: number\n tableEnd: number\n rows: RowRange[]\n}\n\nexport interface PreprocessResult {\n modifiedOld: string\n modifiedNew: string\n /** Maps placeholder marker → already-diffed table HTML to splice back in. */\n placeholderToDiff: Map<string, string>\n}\n\n// HTML comments survive WordSplitter as a single atomic token and are\n// treated as equal on both sides, so they pass through the diff\n// untouched and are easy to substitute back later. The nonce is generated\n// per call so a previously-diffed document being re-diffed (or any input\n// that legitimately contains an `<!--HTMLDIFF_TABLE_*-->` comment) can't\n// collide with the placeholder we substitute. We additionally regenerate\n// the nonce if it appears in either input.\nconst PLACEHOLDER_PREFIX_BASE = '<!--HTMLDIFF_TABLE_'\nconst PLACEHOLDER_SUFFIX = '-->'\n\n/**\n * Hard cap on table dimensions handled by the structural-aware path.\n * The row-LCS is O(rows²), the per-row cell-LCS is O(cells²), and each\n * comparison string-equals row content (potentially many KB). Without a\n * cap, a several-thousand-row table can pin a CPU for seconds. Tables\n * larger than this fall through to the word-level diff, which scales\n * linearly. Tuned to comfortably cover real-world ISDA schedules\n * (which routinely have 1000+ rows).\n */\nconst MAX_TABLE_ROWS = 1500\nconst MAX_TABLE_CELLS_PER_ROW = 200\n\nfunction makePlaceholderPrefix(oldHtml: string, newHtml: string): string {\n // 4 random bytes → 8 hex chars → 16^8 ≈ 4.3 billion combinations. We\n // also retry if the generated nonce happens to occur in either input.\n // Using `Math.random` here is fine: we're not defending against a\n // malicious adversary, just avoiding accidental collisions.\n for (let attempt = 0; attempt < 8; attempt++) {\n const nonce = Math.floor(Math.random() * 0xffffffff)\n .toString(16)\n .padStart(8, '0')\n const prefix = `${PLACEHOLDER_PREFIX_BASE}${nonce}_`\n if (!oldHtml.includes(prefix) && !newHtml.includes(prefix)) {\n return prefix\n }\n }\n // Astronomically unlikely. Falling back to a counter ensures progress\n // rather than an infinite loop, and any remaining collision will simply\n // surface as a malformed diff that the caller can detect.\n return `${PLACEHOLDER_PREFIX_BASE}fallback_${Date.now()}_`\n}\n\ntype DiffCellFn = (oldCellContent: string, newCellContent: string) => string\n\n/**\n * Diffs every paired-by-position table in the inputs and replaces each\n * source table with a placeholder, returning the modified inputs plus the\n * placeholder→diff mapping. Returns null when there are no tables to\n * preprocess or the table counts don't line up.\n */\nexport function preprocessTables(oldHtml: string, newHtml: string, diffCell: DiffCellFn): PreprocessResult | null {\n const oldTables = findTopLevelTables(oldHtml)\n const newTables = findTopLevelTables(newHtml)\n\n if (oldTables.length === 0 && newTables.length === 0) return null\n if (oldTables.length !== newTables.length) return null\n\n // Bail out on pathologically large tables — see MAX_TABLE_ROWS comment.\n for (let i = 0; i < oldTables.length; i++) {\n if (exceedsSizeLimit(oldTables[i]) || exceedsSizeLimit(newTables[i])) return null\n }\n\n const pairs: Array<{ oldTable: TableRange; newTable: TableRange; diffed: string }> = []\n for (let i = 0; i < oldTables.length; i++) {\n pairs.push({\n oldTable: oldTables[i],\n newTable: newTables[i],\n diffed: diffTable(oldHtml, newHtml, oldTables[i], newTables[i], diffCell),\n })\n }\n\n // Splice from end → start so earlier offsets stay valid.\n let modifiedOld = oldHtml\n let modifiedNew = newHtml\n const placeholderPrefix = makePlaceholderPrefix(oldHtml, newHtml)\n const placeholderToDiff = new Map<string, string>()\n for (let i = pairs.length - 1; i >= 0; i--) {\n const placeholder = `${placeholderPrefix}${i}${PLACEHOLDER_SUFFIX}`\n placeholderToDiff.set(placeholder, pairs[i].diffed)\n modifiedOld = spliceString(modifiedOld, pairs[i].oldTable.tableStart, pairs[i].oldTable.tableEnd, placeholder)\n modifiedNew = spliceString(modifiedNew, pairs[i].newTable.tableStart, pairs[i].newTable.tableEnd, placeholder)\n }\n\n return { modifiedOld, modifiedNew, placeholderToDiff }\n}\n\nexport function restoreTablePlaceholders(diffOutput: string, placeholderToDiff: Map<string, string>): string {\n let result = diffOutput\n for (const [placeholder, html] of placeholderToDiff) {\n result = result.split(placeholder).join(html)\n }\n return result\n}\n\nfunction spliceString(s: string, start: number, end: number, replacement: string): string {\n return s.slice(0, start) + replacement + s.slice(end)\n}\n\nfunction exceedsSizeLimit(table: TableRange): boolean {\n if (table.rows.length > MAX_TABLE_ROWS) return true\n for (const row of table.rows) {\n if (row.cells.length > MAX_TABLE_CELLS_PER_ROW) return true\n }\n return false\n}\n\nfunction diffTable(\n oldHtml: string,\n newHtml: string,\n oldTable: TableRange,\n newTable: TableRange,\n diffCell: DiffCellFn\n): string {\n if (sameDimensions(oldTable, newTable)) {\n return diffPositionalTable(oldHtml, newHtml, oldTable, newTable, diffCell)\n }\n if (oldTable.rows.length === newTable.rows.length) {\n // Same row count, different cell counts: column add/delete only.\n // Aligning rows positionally avoids the LCS row-key mismatch that\n // happens when rows have different cell counts.\n return diffSameRowCountTable(oldHtml, newHtml, oldTable, newTable, diffCell)\n }\n return diffStructurallyAlignedTable(oldHtml, newHtml, oldTable, newTable, diffCell)\n}\n\nfunction diffSameRowCountTable(\n oldHtml: string,\n newHtml: string,\n oldTable: TableRange,\n newTable: TableRange,\n diffCell: DiffCellFn\n): string {\n // Walk the new table verbatim (preserving `<thead>`/`<tbody>` wrappers,\n // whitespace, etc.) and substitute each row's content with the diffed\n // form. The cursor-based emission keeps everything between rows intact.\n const out: string[] = []\n let cursor = newTable.tableStart\n let r = 0\n while (r < newTable.rows.length) {\n const merge = detectVerticalMerge(oldHtml, newHtml, oldTable, newTable, r)\n if (merge) {\n out.push(newHtml.slice(cursor, newTable.rows[r].rowStart))\n out.push(merge.diff)\n cursor = newTable.rows[r + merge.span - 1].rowEnd\n r += merge.span\n continue\n }\n const split = detectVerticalSplit(oldHtml, newHtml, oldTable, newTable, r)\n if (split) {\n out.push(newHtml.slice(cursor, newTable.rows[r].rowStart))\n out.push(split.diff)\n cursor = newTable.rows[r + split.span - 1].rowEnd\n r += split.span\n continue\n }\n const newRow = newTable.rows[r]\n out.push(newHtml.slice(cursor, newRow.rowStart))\n out.push(diffPreservedRow(oldHtml, newHtml, oldTable.rows[r], newRow, diffCell))\n cursor = newRow.rowEnd\n r++\n }\n out.push(newHtml.slice(cursor, newTable.tableEnd))\n return out.join('')\n}\n\n/**\n * Detects a vertical merge starting at row `r`: new row R has a single\n * cell with rowspan=K (and any colspan ≥ 1), with rows R+1..R+K-1 empty\n * in new. Old rows R..R+K-1 must have a logical column width equal to\n * the new cell's colspan and contain no rowspan'd cells of their own.\n * This handles both single-column merges (old rows are 1-cell, new cell\n * rowspan=K) and rectangular merges (e.g. 2×2 merge into a single\n * colspan=2 rowspan=2 cell). Output: emit the merged cell with\n * `class='mod rowspan'` and the empty trailing rows unchanged.\n */\nfunction detectVerticalMerge(\n oldHtml: string,\n newHtml: string,\n oldTable: TableRange,\n newTable: TableRange,\n r: number\n): { diff: string; span: number } | null {\n const newRow = newTable.rows[r]\n if (newRow.cells.length !== 1) return null\n const cell = newRow.cells[0]\n const span = getRowspan(newHtml, cell)\n if (span <= 1) return null\n if (r + span > newTable.rows.length) return null\n\n const colspan = getColspan(newHtml, cell)\n\n for (let k = 1; k < span; k++) {\n if (newTable.rows[r + k].cells.length !== 0) return null\n }\n for (let k = 0; k < span; k++) {\n const oldRow = oldTable.rows[r + k]\n if (!oldRow) return null\n // The absorbed region's logical width must match the merged cell's\n // colspan; otherwise this isn't a clean rectangular merge and we let\n // the caller fall through.\n if (sumColspans(oldHtml, oldRow.cells) !== colspan) return null\n for (const c of oldRow.cells) {\n if (getRowspan(oldHtml, c) !== 1) return null\n }\n }\n\n const out: string[] = []\n out.push(rowHeaderSlice(newHtml, newRow))\n out.push(emitSpanChangedCell(newHtml, cell, 'rowspan'))\n out.push('</tr>')\n for (let k = 1; k < span; k++) {\n out.push(emitEmptyRow(newHtml, newTable.rows[r + k]))\n }\n return { diff: out.join(''), span }\n}\n\n/**\n * Detects a vertical split starting at row `r`: old row R has a single\n * cell with rowspan=K, old rows R+1..R+K-1 are empty. New rows R..R+K-1\n * each have a single cell. Output: emit each new row with the new cell\n * tagged `class='mod rowspan'`.\n */\nfunction detectVerticalSplit(\n oldHtml: string,\n newHtml: string,\n oldTable: TableRange,\n newTable: TableRange,\n r: number\n): { diff: string; span: number } | null {\n const oldRow = oldTable.rows[r]\n if (oldRow.cells.length !== 1) return null\n const oldCell = oldRow.cells[0]\n const span = getRowspan(oldHtml, oldCell)\n if (span <= 1) return null\n if (r + span > oldTable.rows.length) return null\n\n const colspan = getColspan(oldHtml, oldCell)\n\n for (let k = 1; k < span; k++) {\n if (oldTable.rows[r + k].cells.length !== 0) return null\n }\n for (let k = 0; k < span; k++) {\n const newRow = newTable.rows[r + k]\n if (!newRow) return null\n // New rows must collectively cover the same logical width as the old\n // merged cell's colspan, with no rowspan'd cells of their own.\n if (sumColspans(newHtml, newRow.cells) !== colspan) return null\n for (const c of newRow.cells) {\n if (getRowspan(newHtml, c) !== 1) return null\n }\n }\n\n const out: string[] = []\n for (let k = 0; k < span; k++) {\n const newRow = newTable.rows[r + k]\n out.push(rowHeaderSlice(newHtml, newRow))\n for (const c of newRow.cells) {\n out.push(emitSpanChangedCell(newHtml, c, 'rowspan'))\n }\n out.push('</tr>')\n }\n return { diff: out.join(''), span }\n}\n\nfunction emitEmptyRow(html: string, row: RowRange): string {\n // Re-emit the source row's `<tr ...></tr>` verbatim.\n return html.slice(row.rowStart, row.rowEnd)\n}\n\nfunction sameDimensions(a: TableRange, b: TableRange): boolean {\n if (a.rows.length !== b.rows.length) return false\n for (let i = 0; i < a.rows.length; i++) {\n if (a.rows[i].cells.length !== b.rows[i].cells.length) return false\n }\n return true\n}\n\n/**\n * Same-dimension path: walk the new table verbatim and substitute each\n * cell content range with the cell-level diff. The surrounding\n * `<thead>`/`<tbody>`/whitespace passes through untouched.\n */\nfunction diffPositionalTable(\n oldHtml: string,\n newHtml: string,\n oldTable: TableRange,\n newTable: TableRange,\n diffCell: DiffCellFn\n): string {\n const out: string[] = []\n let cursor = newTable.tableStart\n for (let r = 0; r < newTable.rows.length; r++) {\n const oldRow = oldTable.rows[r]\n const newRow = newTable.rows[r]\n for (let c = 0; c < newRow.cells.length; c++) {\n const oldCell = oldRow.cells[c]\n const newCell = newRow.cells[c]\n out.push(newHtml.slice(cursor, newCell.contentStart))\n out.push(\n diffCell(\n oldHtml.slice(oldCell.contentStart, oldCell.contentEnd),\n newHtml.slice(newCell.contentStart, newCell.contentEnd)\n )\n )\n cursor = newCell.contentEnd\n }\n }\n out.push(newHtml.slice(cursor, newTable.tableEnd))\n return out.join('')\n}\n\n/**\n * Mismatched-dimensions path: row-level LCS to identify added/deleted rows,\n * then per preserved row a cell-level LCS to identify added/deleted cells.\n * Reconstructs the table from scratch — there's no \"single new structure\"\n * to walk verbatim, since we're stitching together kept rows from both\n * sides.\n */\nfunction diffStructurallyAlignedTable(\n oldHtml: string,\n newHtml: string,\n oldTable: TableRange,\n newTable: TableRange,\n diffCell: DiffCellFn\n): string {\n const oldKeys = oldTable.rows.map(row => rowKey(oldHtml, row))\n const newKeys = newTable.rows.map(row => rowKey(newHtml, row))\n const exactAlignment = lcsAlign(oldKeys, newKeys)\n const alignment = pairSimilarUnmatchedRows(exactAlignment, oldTable, newTable, oldHtml, newHtml)\n\n // Walk new's tableStart→tableEnd, substituting rows with their diffed\n // form so `<thead>`/`<tbody>` wrappers and inter-row whitespace are\n // preserved verbatim. Deleted rows (no position in new) are injected\n // inline at their alignment position. If new has no rows at all, fall\n // back to a from-scratch reconstruction so we still emit deleted rows.\n if (newTable.rows.length === 0) {\n return rebuildStructurallyAlignedTable(oldHtml, newHtml, oldTable, newTable, alignment, diffCell)\n }\n\n // Emit the table header (`<table>` + any `<thead>`/`<tbody>` opening\n // text up to the first row) up-front so a leading run of deleted-only\n // alignments doesn't slip in before the table opens.\n const out: string[] = []\n out.push(newHtml.slice(newTable.tableStart, newTable.rows[0].rowStart))\n let cursor = newTable.rows[0].rowStart\n for (const align of alignment) {\n if (align.newIdx !== null) {\n const newRow = newTable.rows[align.newIdx]\n out.push(newHtml.slice(cursor, newRow.rowStart))\n if (align.oldIdx !== null) {\n out.push(diffPreservedRow(oldHtml, newHtml, oldTable.rows[align.oldIdx], newRow, diffCell))\n } else {\n out.push(emitFullRow(newHtml, newRow, 'ins', diffCell))\n }\n cursor = newRow.rowEnd\n } else if (align.oldIdx !== null) {\n // Deleted row: inject inline at the current cursor (between the\n // previously emitted row and the next one in new).\n out.push(emitFullRow(oldHtml, oldTable.rows[align.oldIdx], 'del', diffCell))\n }\n }\n out.push(newHtml.slice(cursor, newTable.tableEnd))\n return out.join('')\n}\n\nfunction rebuildStructurallyAlignedTable(\n oldHtml: string,\n newHtml: string,\n oldTable: TableRange,\n newTable: TableRange,\n alignment: Alignment[],\n diffCell: DiffCellFn\n): string {\n // Used when new has no rows but old does — we lose the per-row\n // wrappers from new (there are none), so reconstruct from old's frame.\n const out: string[] = []\n out.push(headerSlice(newHtml, newTable, oldHtml, oldTable))\n for (const align of alignment) {\n if (align.oldIdx !== null) {\n out.push(emitFullRow(oldHtml, oldTable.rows[align.oldIdx], 'del', diffCell))\n } else if (align.newIdx !== null) {\n out.push(emitFullRow(newHtml, newTable.rows[align.newIdx], 'ins', diffCell))\n }\n }\n out.push('</table>')\n return out.join('')\n}\n\nfunction headerSlice(newHtml: string, newTable: TableRange, oldHtml: string, oldTable: TableRange): string {\n // Slice from <table> to the start of the first <tr>. Prefer new since\n // attribute changes on <table> itself should follow new.\n const newFirstRow = newTable.rows[0]?.rowStart ?? newTable.tableEnd - '</table>'.length\n if (newFirstRow > newTable.tableStart) {\n return newHtml.slice(newTable.tableStart, newFirstRow)\n }\n const oldFirstRow = oldTable.rows[0]?.rowStart ?? oldTable.tableEnd - '</table>'.length\n return oldHtml.slice(oldTable.tableStart, oldFirstRow)\n}\n\nfunction rowKey(html: string, row: RowRange): string {\n // Include cell tag text in the key so column-add doesn't accidentally\n // match a row to one with different cell counts. Whitespace-normalize to\n // tolerate formatting differences.\n return html.slice(row.rowStart, row.rowEnd).replace(/\\s+/g, ' ').trim()\n}\n\nfunction diffPreservedRow(\n oldHtml: string,\n newHtml: string,\n oldRow: RowRange,\n newRow: RowRange,\n diffCell: DiffCellFn\n): string {\n if (oldRow.cells.length === newRow.cells.length) {\n return diffPositionalRow(oldHtml, newHtml, oldRow, newRow, diffCell)\n }\n // Cell counts differ. Try to interpret it as a horizontal merge/split via\n // colspan first — preserving the new structure with `class='mod colspan'`\n // on each affected cell.\n const colspanAligned = diffColspanChangedRow(oldHtml, newHtml, oldRow, newRow, diffCell)\n if (colspanAligned !== null) return colspanAligned\n // For a single-column add/delete (cell count differs by exactly 1),\n // detect the position via positional similarity scan and align the\n // remaining cells positionally. This handles the case where a column\n // was added AND a different cell got an unrelated content edit — the\n // edited cell still aligns by position rather than getting orphaned by\n // the cell-LCS exact-match.\n const delta = newRow.cells.length - oldRow.cells.length\n // For column add/delete (cell counts differ), find the best insertion\n // or deletion positions via positional similarity scan and align the\n // remaining cells positionally. This handles content-edit alongside\n // column-add by keeping the edited cell in its column position rather\n // than orphaning it via the cell-LCS exact match.\n // Guardrail: combinatorial search is C(newCount, k); we cap to avoid\n // explosion on very wide tables. The cap is generous for real legal\n // schedules; anything above falls through to cell-LCS.\n const absDelta = Math.abs(delta)\n if (\n absDelta > 0 &&\n absDelta <= MAX_COLUMN_DELTA &&\n Math.max(oldRow.cells.length, newRow.cells.length) <= MAX_COLUMN_SEARCH_WIDTH\n ) {\n if (delta > 0) return diffMultiColumnAddRow(oldHtml, newHtml, oldRow, newRow, delta, diffCell)\n return diffMultiColumnDeleteRow(oldHtml, newHtml, oldRow, newRow, -delta, diffCell)\n }\n return diffStructurallyAlignedRow(oldHtml, newHtml, oldRow, newRow, diffCell)\n}\n\nconst MAX_COLUMN_DELTA = 6\nconst MAX_COLUMN_SEARCH_WIDTH = 40\n\n/**\n * For a row where new has K more cells than old, find the K column\n * positions in new where cells were inserted by scanning all C(newCount,\n * K) combinations and picking the one that maximises positional content\n * similarity with the remaining cells. The inserted cells are emitted\n * with diff markers; the rest are aligned positionally with content\n * diff for matched pairs.\n */\nfunction diffMultiColumnAddRow(\n oldHtml: string,\n newHtml: string,\n oldRow: RowRange,\n newRow: RowRange,\n k: number,\n diffCell: DiffCellFn\n): string {\n const insertedPositions = findBestColumnInsertPositions(oldRow, newRow, k, oldHtml, newHtml)\n const inserted = new Set(insertedPositions)\n const out: string[] = [rowHeaderSlice(newHtml, newRow)]\n let oldIdx = 0\n for (let c = 0; c < newRow.cells.length; c++) {\n if (inserted.has(c)) {\n out.push(emitFullCell(newHtml, newRow.cells[c], 'ins', diffCell))\n } else {\n out.push(emitDiffedCell(oldHtml, newHtml, oldRow.cells[oldIdx], newRow.cells[c], diffCell))\n oldIdx++\n }\n }\n out.push('</tr>')\n return out.join('')\n}\n\nfunction diffMultiColumnDeleteRow(\n oldHtml: string,\n newHtml: string,\n oldRow: RowRange,\n newRow: RowRange,\n k: number,\n diffCell: DiffCellFn\n): string {\n const deletedPositions = findBestColumnDeletePositions(oldRow, newRow, k, oldHtml, newHtml)\n const deleted = new Set(deletedPositions)\n const out: string[] = [rowHeaderSlice(newHtml, newRow)]\n let newIdx = 0\n for (let oldIdx = 0; oldIdx < oldRow.cells.length; oldIdx++) {\n if (deleted.has(oldIdx)) {\n out.push(emitFullCell(oldHtml, oldRow.cells[oldIdx], 'del', diffCell))\n continue\n }\n out.push(emitDiffedCell(oldHtml, newHtml, oldRow.cells[oldIdx], newRow.cells[newIdx], diffCell))\n newIdx++\n }\n out.push('</tr>')\n return out.join('')\n}\n\nfunction findBestColumnInsertPositions(\n oldRow: RowRange,\n newRow: RowRange,\n k: number,\n oldHtml: string,\n newHtml: string\n): number[] {\n let bestPositions: number[] = []\n let bestScore = -1\n for (const combo of combinationsOfRange(newRow.cells.length, k)) {\n const inserted = new Set(combo)\n let score = 0\n let oldIdx = 0\n for (let newIdx = 0; newIdx < newRow.cells.length; newIdx++) {\n if (inserted.has(newIdx)) continue\n score += cellSimilarity(oldRow.cells[oldIdx], newRow.cells[newIdx], oldHtml, newHtml)\n oldIdx++\n }\n if (score > bestScore) {\n bestScore = score\n bestPositions = combo\n }\n }\n return bestPositions\n}\n\nfunction findBestColumnDeletePositions(\n oldRow: RowRange,\n newRow: RowRange,\n k: number,\n oldHtml: string,\n newHtml: string\n): number[] {\n let bestPositions: number[] = []\n let bestScore = -1\n for (const combo of combinationsOfRange(oldRow.cells.length, k)) {\n const deleted = new Set(combo)\n let score = 0\n let newIdx = 0\n for (let oldIdx = 0; oldIdx < oldRow.cells.length; oldIdx++) {\n if (deleted.has(oldIdx)) continue\n score += cellSimilarity(oldRow.cells[oldIdx], newRow.cells[newIdx], oldHtml, newHtml)\n newIdx++\n }\n if (score > bestScore) {\n bestScore = score\n bestPositions = combo\n }\n }\n return bestPositions\n}\n\n/**\n * Yields all sorted-ascending combinations of `k` distinct integers\n * from [0, n). Iterative implementation avoids recursion overhead and\n * keeps memory at O(k).\n */\nfunction* combinationsOfRange(n: number, k: number): IterableIterator<number[]> {\n if (k === 0 || k > n) return\n const indices = Array.from({ length: k }, (_, i) => i)\n while (true) {\n yield indices.slice()\n let i = k - 1\n while (i >= 0 && indices[i] === n - k + i) i--\n if (i < 0) return\n indices[i]++\n for (let j = i + 1; j < k; j++) indices[j] = indices[j - 1] + 1\n }\n}\n\n/**\n * Try to align cells by logical column position (sum of colspans). When\n * one side has a colspan'd cell that absorbs multiple cells on the other\n * side, emit the new structure with `class='mod colspan'` on the\n * merged/split cells. Returns null if the rows don't align cleanly —\n * caller falls back to a generic cell-LCS.\n */\nfunction diffColspanChangedRow(\n oldHtml: string,\n newHtml: string,\n oldRow: RowRange,\n newRow: RowRange,\n diffCell: DiffCellFn\n): string | null {\n const oldWidth = sumColspans(oldHtml, oldRow.cells)\n const newWidth = sumColspans(newHtml, newRow.cells)\n if (oldWidth !== newWidth) return null\n\n const out: string[] = []\n out.push(rowHeaderSlice(newHtml, newRow))\n\n let oi = 0\n let ni = 0\n while (oi < oldRow.cells.length && ni < newRow.cells.length) {\n const oCell = oldRow.cells[oi]\n const nCell = newRow.cells[ni]\n const oSpan = getColspan(oldHtml, oCell)\n const nSpan = getColspan(newHtml, nCell)\n\n if (oSpan === nSpan) {\n out.push(emitDiffedCell(oldHtml, newHtml, oCell, nCell, diffCell))\n oi++\n ni++\n } else if (nSpan > oSpan) {\n // New cell absorbs multiple old cells — horizontal merge.\n let totalOldSpan = 0\n let oj = oi\n while (oj < oldRow.cells.length && totalOldSpan < nSpan) {\n totalOldSpan += getColspan(oldHtml, oldRow.cells[oj])\n oj++\n }\n if (totalOldSpan !== nSpan) return null\n out.push(emitSpanChangedCell(newHtml, nCell, 'colspan'))\n oi = oj\n ni++\n } else {\n // One old cell becomes multiple new cells — horizontal split.\n let totalNewSpan = 0\n let nj = ni\n while (nj < newRow.cells.length && totalNewSpan < oSpan) {\n totalNewSpan += getColspan(newHtml, newRow.cells[nj])\n nj++\n }\n if (totalNewSpan !== oSpan) return null\n for (let k = ni; k < nj; k++) {\n out.push(emitSpanChangedCell(newHtml, newRow.cells[k], 'colspan'))\n }\n oi++\n ni = nj\n }\n }\n\n // If we couldn't consume both sides cleanly, bail out.\n if (oi !== oldRow.cells.length || ni !== newRow.cells.length) return null\n\n out.push('</tr>')\n return out.join('')\n}\n\nfunction sumColspans(html: string, cells: CellRange[]): number {\n let total = 0\n for (const cell of cells) total += getColspan(html, cell)\n return total\n}\n\nfunction getColspan(html: string, cell: CellRange): number {\n return parseSpanAttribute(html.slice(cell.cellStart, cell.contentStart), 'colspan')\n}\n\nfunction getRowspan(html: string, cell: CellRange): number {\n return parseSpanAttribute(html.slice(cell.cellStart, cell.contentStart), 'rowspan')\n}\n\nfunction parseSpanAttribute(openingTag: string, name: 'colspan' | 'rowspan'): number {\n const re = name === 'colspan' ? /\\bcolspan\\s*=\\s*[\"']?(\\d+)[\"']?/i : /\\browspan\\s*=\\s*[\"']?(\\d+)[\"']?/i\n const m = re.exec(openingTag)\n if (!m) return 1\n const value = Number.parseInt(m[1], 10)\n return Number.isFinite(value) && value > 0 ? value : 1\n}\n\n/**\n * Emits a cell that's the merged/split product of a structural change,\n * tagged with `class='mod colspan'` or `class='mod rowspan'`. Content is\n * carried through unmodified — Word doesn't track these changes, and\n * inserting del/ins around content that didn't really change would be\n * misleading.\n */\nfunction emitSpanChangedCell(html: string, cell: CellRange, kind: 'colspan' | 'rowspan'): string {\n const tdOpening = parseOpeningTagAt(html, cell.cellStart)\n if (!tdOpening) return html.slice(cell.cellStart, cell.cellEnd)\n const tdOpenTag = injectClass(html.slice(cell.cellStart, tdOpening.end), `mod ${kind}`)\n return tdOpenTag + html.slice(cell.contentStart, cell.cellEnd)\n}\n\nfunction diffPositionalRow(\n oldHtml: string,\n newHtml: string,\n oldRow: RowRange,\n newRow: RowRange,\n diffCell: DiffCellFn\n): string {\n const out: string[] = []\n // Use new's <tr> opening tag (preserves attributes from new).\n const trHeader = rowHeaderSlice(newHtml, newRow)\n out.push(trHeader)\n\n let cursor = newRow.cells[0]?.cellStart ?? newRow.rowEnd\n for (let c = 0; c < newRow.cells.length; c++) {\n const oldCell = oldRow.cells[c]\n const newCell = newRow.cells[c]\n out.push(newHtml.slice(cursor, newCell.contentStart))\n out.push(\n diffCell(\n oldHtml.slice(oldCell.contentStart, oldCell.contentEnd),\n newHtml.slice(newCell.contentStart, newCell.contentEnd)\n )\n )\n cursor = newCell.contentEnd\n }\n out.push(newHtml.slice(cursor, newRow.rowEnd))\n return out.join('')\n}\n\nfunction diffStructurallyAlignedRow(\n oldHtml: string,\n newHtml: string,\n oldRow: RowRange,\n newRow: RowRange,\n diffCell: DiffCellFn\n): string {\n const oldKeys = oldRow.cells.map(cell => cellKey(oldHtml, cell))\n const newKeys = newRow.cells.map(cell => cellKey(newHtml, cell))\n const exactAlignment = lcsAlign(oldKeys, newKeys)\n // After exact LCS, fuzzy-pair adjacent unmatched old/new cells whose\n // content is similar enough — so a content-edit cell alongside a\n // column-add in the same row produces a content diff for the edited\n // cell rather than a phantom delete + insert + extra cell.\n const alignment = pairSimilarUnmatchedCells(exactAlignment, oldRow, newRow, oldHtml, newHtml)\n\n const out: string[] = []\n // Use new's <tr> if it exists; otherwise old's.\n out.push(rowHeaderSlice(newHtml, newRow))\n\n for (const align of alignment) {\n if (align.oldIdx !== null && align.newIdx !== null) {\n const oldCell = oldRow.cells[align.oldIdx]\n const newCell = newRow.cells[align.newIdx]\n out.push(emitDiffedCell(oldHtml, newHtml, oldCell, newCell, diffCell))\n } else if (align.newIdx !== null) {\n out.push(emitFullCell(newHtml, newRow.cells[align.newIdx], 'ins', diffCell))\n } else if (align.oldIdx !== null) {\n out.push(emitFullCell(oldHtml, oldRow.cells[align.oldIdx], 'del', diffCell))\n }\n }\n\n out.push('</tr>')\n return out.join('')\n}\n\nfunction cellKey(html: string, cell: CellRange): string {\n // Use cell content (not tag attributes) for matching, since column-add\n // typically changes content but not tag attributes — and matching purely\n // on attributes would mis-pair cells with the same content but different\n // styling.\n return html.slice(cell.contentStart, cell.contentEnd).replace(/\\s+/g, ' ').trim()\n}\n\n/**\n * Emits a row with all cells either inserted (kind='ins') or deleted\n * (kind='del'). Adds `class='diffins'`/`'diffdel'` to the `<tr>` and to\n * each `<td>`, with an `<ins>`/`<del>` wrapper around any cell content\n * (empty cells get the class but no wrapper).\n */\nfunction emitFullRow(html: string, row: RowRange, kind: 'ins' | 'del', diffCell: DiffCellFn): string {\n const cls = kind === 'ins' ? 'diffins' : 'diffdel'\n const trOpening = parseOpeningTagAt(html, row.rowStart)\n if (!trOpening) return html.slice(row.rowStart, row.rowEnd)\n const trOpenTag = injectClass(html.slice(row.rowStart, trOpening.end), cls)\n\n const out: string[] = [trOpenTag]\n let cursor = trOpening.end\n for (const cell of row.cells) {\n out.push(html.slice(cursor, cell.cellStart))\n out.push(emitFullCell(html, cell, kind, diffCell))\n cursor = cell.cellEnd\n }\n out.push(html.slice(cursor, row.rowEnd))\n return out.join('')\n}\n\n/**\n * Emits a fully-inserted or fully-deleted cell. Inner text runs are wrapped\n * with `<ins>`/`<del>` while formatting tags pass through unchanged, so\n * `<strong>B</strong>` renders as `<strong><ins>B</ins></strong>` —\n * matching htmldiff's general convention without the doubled-`<ins>` that\n * the full recursive diff would produce for newly-inserted formatting.\n * Empty cells get the class on the `<td>` but no inner wrapping.\n */\nfunction emitFullCell(html: string, cell: CellRange, kind: 'ins' | 'del', _diffCell: DiffCellFn): string {\n const cls = kind === 'ins' ? 'diffins' : 'diffdel'\n const tdOpening = parseOpeningTagAt(html, cell.cellStart)\n if (!tdOpening) return html.slice(cell.cellStart, cell.cellEnd)\n const tdOpenTag = injectClass(html.slice(cell.cellStart, tdOpening.end), cls)\n\n const content = html.slice(cell.contentStart, cell.contentEnd)\n const wrapped = content.trim().length === 0 ? content : wrapInlineTextRuns(content, kind)\n const closing = html.slice(cell.contentEnd, cell.cellEnd)\n return tdOpenTag + wrapped + closing\n}\n\n/**\n * Wraps every non-whitespace text run in the given content with an\n * `<ins>`/`<del>` tag, leaving HTML tags untouched. This produces output\n * like `<strong><ins>X</ins></strong>` for fully-inserted formatted\n * content — the same shape the rest of htmldiff emits for content\n * insertions inside existing formatting.\n */\nfunction wrapInlineTextRuns(content: string, kind: 'ins' | 'del'): string {\n const tag = kind === 'ins' ? 'ins' : 'del'\n const cls = kind === 'ins' ? 'diffins' : 'diffdel'\n\n const out: string[] = []\n let i = 0\n while (i < content.length) {\n if (content[i] === '<') {\n const tagEnd = parseOpeningTagAt(content, i)\n if (!tagEnd) {\n // Malformed — pass the rest through verbatim.\n out.push(content.slice(i))\n break\n }\n out.push(content.slice(i, tagEnd.end))\n i = tagEnd.end\n continue\n }\n let j = i\n while (j < content.length && content[j] !== '<') j++\n const text = content.slice(i, j)\n if (text.trim().length > 0) {\n out.push(`<${tag} class='${cls}'>${text}</${tag}>`)\n } else {\n out.push(text)\n }\n i = j\n }\n return out.join('')\n}\n\nfunction emitDiffedCell(\n oldHtml: string,\n newHtml: string,\n oldCell: CellRange,\n newCell: CellRange,\n diffCell: DiffCellFn\n): string {\n const tdOpening = parseOpeningTagAt(newHtml, newCell.cellStart)\n if (!tdOpening) return newHtml.slice(newCell.cellStart, newCell.cellEnd)\n const tdOpenTag = newHtml.slice(newCell.cellStart, tdOpening.end)\n const content = diffCell(\n oldHtml.slice(oldCell.contentStart, oldCell.contentEnd),\n newHtml.slice(newCell.contentStart, newCell.contentEnd)\n )\n const closing = newHtml.slice(newCell.contentEnd, newCell.cellEnd)\n return tdOpenTag + content + closing\n}\n\nfunction rowHeaderSlice(html: string, row: RowRange): string {\n // Slice from <tr> to just before the first <td> opening tag. Preserves\n // the <tr ...> attributes plus any inter-tag whitespace. For a row with\n // no cells, we only want the `<tr ...>` opening — the caller appends the\n // closing `</tr>` explicitly, so taking the whole `<tr></tr>` here would\n // double the close.\n const opening = parseOpeningTagAt(html, row.rowStart)\n if (!opening) return ''\n if (row.cells.length === 0) return html.slice(row.rowStart, opening.end)\n return html.slice(row.rowStart, row.cells[0].cellStart)\n}\n\ninterface Alignment {\n oldIdx: number | null\n newIdx: number | null\n}\n\n/** Character-level similarity threshold above which we treat two rows as \"the same row, edited\". */\nconst ROW_FUZZY_THRESHOLD = 0.5\n\n/**\n * Threshold for \"this cell is a content-edit of that cell.\" Tuned the same\n * as ROW_FUZZY_THRESHOLD; cells in legal docs that share most of their\n * content typically ARE the same logical cell with a body edit, so 0.5\n * works for both granularities in practice.\n */\nconst CELL_FUZZY_THRESHOLD = 0.5\n\n/**\n * After exact LCS, scan the alignment for runs of \"old deleted, then new\n * inserted\" (or vice versa) and pair entries whose content is similar\n * enough to be treated as an edit rather than a delete+insert. This keeps\n * row-level edits (a typo fix, a single word change) from being shown as\n * an entire row vanishing and a new one appearing — matching what users\n * expect from a typical track-changes view.\n */\nfunction pairSimilarUnmatchedRows(\n alignment: Alignment[],\n oldTable: TableRange,\n newTable: TableRange,\n oldHtml: string,\n newHtml: string\n): Alignment[] {\n return pairSimilarUnmatched(alignment, ROW_FUZZY_THRESHOLD, (oldIdx, newIdx) =>\n rowSimilarity(oldTable.rows[oldIdx], newTable.rows[newIdx], oldHtml, newHtml)\n )\n}\n\nfunction pairSimilarUnmatchedCells(\n alignment: Alignment[],\n oldRow: RowRange,\n newRow: RowRange,\n oldHtml: string,\n newHtml: string\n): Alignment[] {\n return pairSimilarUnmatched(alignment, CELL_FUZZY_THRESHOLD, (oldIdx, newIdx) =>\n cellSimilarity(oldRow.cells[oldIdx], newRow.cells[newIdx], oldHtml, newHtml)\n )\n}\n\n/**\n * Identify pairings inside each unmatched-only run, then build the output\n * alignment by walking the original and substituting paired entries at\n * the *ins position* (not the del position). This keeps the result\n * monotonic in newIdx — critical because the cursor-based emission\n * downstream walks new's html in order. Emitting at the del position\n * would be fine when del<ins in the alignment array (the typical case),\n * but can violate monotonicity when there are mixed unpaired entries in\n * between (column-add + row-add together, content-edit + column-add,\n * etc.).\n *\n * Generic over what's being paired — works for both rows (by full row\n * content similarity) and cells (by per-cell content similarity).\n */\nfunction pairSimilarUnmatched(\n alignment: Alignment[],\n threshold: number,\n similarity: (oldIdx: number, newIdx: number) => number\n): Alignment[] {\n const pairs = new Map<number, number>() // del-alignment-idx → ins-alignment-idx\n let i = 0\n while (i < alignment.length) {\n if (alignment[i].oldIdx !== null && alignment[i].newIdx !== null) {\n i++\n continue\n }\n const runStart = i\n while (i < alignment.length && (alignment[i].oldIdx === null) !== (alignment[i].newIdx === null)) i++\n const runEnd = i\n\n const delIndices: number[] = []\n const insIndices: number[] = []\n for (let k = runStart; k < runEnd; k++) {\n if (alignment[k].oldIdx !== null) delIndices.push(k)\n else insIndices.push(k)\n }\n\n const usedIns = new Set<number>()\n for (const di of delIndices) {\n let bestIi = -1\n let bestSim = threshold\n for (const ii of insIndices) {\n if (usedIns.has(ii)) continue\n const sim = similarity(alignment[di].oldIdx as number, alignment[ii].newIdx as number)\n if (sim > bestSim) {\n bestSim = sim\n bestIi = ii\n }\n }\n if (bestIi >= 0) {\n pairs.set(di, bestIi)\n usedIns.add(bestIi)\n }\n }\n }\n\n const insToDel = new Map<number, number>() // ins-alignment-idx → del-alignment-idx\n for (const [delAi, insAi] of pairs) insToDel.set(insAi, delAi)\n const pairedDels = new Set<number>(pairs.keys())\n\n const result: Alignment[] = []\n for (let k = 0; k < alignment.length; k++) {\n if (pairedDels.has(k)) continue // paired del — emitted when we reach its ins\n if (insToDel.has(k)) {\n const delAi = insToDel.get(k) as number\n result.push({ oldIdx: alignment[delAi].oldIdx, newIdx: alignment[k].newIdx })\n } else {\n result.push(alignment[k])\n }\n }\n return result\n}\n\n/**\n * Combined similarity metric used for both row-level and cell-level\n * fuzzy pairing. Returns the MAX of two complementary metrics:\n *\n * 1. **Character prefix+suffix similarity** — fraction of the longer\n * string covered by shared prefix + shared suffix. Catches small\n * edits in the middle of a string (one word changed in a row).\n * Misses cases where the bulk of common content is in the middle\n * and the ends differ.\n *\n * 2. **Token Jaccard similarity** — intersection-over-union of the\n * whitespace-split tokens. Catches \"most of the content is the\n * same but bookended by different bits\" — e.g. a row whose only\n * edit is a column added at the start and another at the end,\n * where the ~50 chars in the middle that DO match would be\n * invisible to prefix+suffix.\n *\n * Either metric exceeding the threshold means pair. Neither alone is\n * sufficient for the full range of legal-doc edits we see in\n * production tables.\n */\nfunction rowSimilarity(oldRow: RowRange, newRow: RowRange, oldHtml: string, newHtml: string): number {\n return textSimilarity(rowText(oldHtml, oldRow), rowText(newHtml, newRow))\n}\n\nfunction cellSimilarity(oldCell: CellRange, newCell: CellRange, oldHtml: string, newHtml: string): number {\n return textSimilarity(cellText(oldHtml, oldCell), cellText(newHtml, newCell))\n}\n\nfunction textSimilarity(a: string, b: string): number {\n if (a === b) return 1\n if (a.length === 0 || b.length === 0) return 0\n return Math.max(charPrefixSuffixSimilarity(a, b), tokenJaccardSimilarity(a, b))\n}\n\nfunction charPrefixSuffixSimilarity(a: string, b: string): number {\n let prefix = 0\n const minLen = Math.min(a.length, b.length)\n while (prefix < minLen && a[prefix] === b[prefix]) prefix++\n\n let suffix = 0\n while (\n suffix < a.length - prefix &&\n suffix < b.length - prefix &&\n a[a.length - 1 - suffix] === b[b.length - 1 - suffix]\n ) {\n suffix++\n }\n\n return (prefix + suffix) / Math.max(a.length, b.length)\n}\n\nfunction tokenJaccardSimilarity(a: string, b: string): number {\n const tokensA = new Set(a.split(/\\s+/).filter(Boolean))\n const tokensB = new Set(b.split(/\\s+/).filter(Boolean))\n if (tokensA.size === 0 && tokensB.size === 0) return 1\n let intersection = 0\n for (const t of tokensA) {\n if (tokensB.has(t)) intersection++\n }\n const union = tokensA.size + tokensB.size - intersection\n return union === 0 ? 0 : intersection / union\n}\n\nfunction rowText(html: string, row: RowRange): string {\n const parts: string[] = []\n for (const cell of row.cells) {\n parts.push(html.slice(cell.contentStart, cell.contentEnd).replace(/<[^>]+>/g, ' '))\n }\n return parts.join(' ').replace(/\\s+/g, ' ').trim().toLowerCase()\n}\n\nfunction cellText(html: string, cell: CellRange): string {\n return html\n .slice(cell.contentStart, cell.contentEnd)\n .replace(/<[^>]+>/g, ' ')\n .replace(/\\s+/g, ' ')\n .trim()\n .toLowerCase()\n}\n\n/**\n * Standard LCS alignment: walks both sequences and emits a list of pairs\n * where `(oldIdx, newIdx)` are both set for matching positions, and one\n * side is null for an unmatched entry on the other side. Equality uses\n * strict ===.\n */\nfunction lcsAlign(oldKeys: string[], newKeys: string[]): Alignment[] {\n const m = oldKeys.length\n const n = newKeys.length\n const dp: number[][] = Array.from({ length: m + 1 }, () => new Array<number>(n + 1).fill(0))\n for (let i = 1; i <= m; i++) {\n for (let j = 1; j <= n; j++) {\n if (oldKeys[i - 1] === newKeys[j - 1]) {\n dp[i][j] = dp[i - 1][j - 1] + 1\n } else {\n dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1])\n }\n }\n }\n\n const result: Alignment[] = []\n let i = m\n let j = n\n while (i > 0 || j > 0) {\n if (i > 0 && j > 0 && oldKeys[i - 1] === newKeys[j - 1]) {\n result.unshift({ oldIdx: i - 1, newIdx: j - 1 })\n i--\n j--\n } else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {\n result.unshift({ oldIdx: null, newIdx: j - 1 })\n j--\n } else {\n result.unshift({ oldIdx: i - 1, newIdx: null })\n i--\n }\n }\n return result\n}\n\n/**\n * Returns the opening tag string with the given class injected. Existing\n * `class` attributes are preserved and the new class appended.\n */\n/**\n * Returns the opening tag with the given class injected. Locates the real\n * `class` attribute via attribute-aware walking (NOT a flat regex — that\n * would mis-match inside a foreign attribute value like\n * `title=\"see class='x'\"`). When the class already partially overlaps with\n * `cls` — e.g. existing `class=\"mod\"` and we're injecting `mod colspan` —\n * only the missing tokens get appended, so we never end up with\n * `class=\"mod mod colspan\"`.\n */\nfunction injectClass(openingTag: string, cls: string): string {\n const clsTokens = cls.split(/\\s+/).filter(Boolean)\n if (clsTokens.length === 0) return openingTag\n\n const classAttr = findClassAttribute(openingTag)\n if (classAttr) {\n const existingTokens = classAttr.value.split(/\\s+/).filter(Boolean)\n const missing = clsTokens.filter(t => !existingTokens.includes(t))\n if (missing.length === 0) return openingTag\n const updatedValue =\n existingTokens.length === 0 ? missing.join(' ') : `${existingTokens.join(' ')} ${missing.join(' ')}`\n return openingTag.slice(0, classAttr.valueStart) + updatedValue + openingTag.slice(classAttr.valueEnd)\n }\n\n const isSelfClosing = openingTag.endsWith('/>')\n const insertAt = isSelfClosing ? openingTag.length - 2 : openingTag.length - 1\n return `${openingTag.slice(0, insertAt).replace(/\\s*$/, '')} class='${cls}'${openingTag.slice(insertAt)}`\n}\n\n/**\n * Walks the opening tag's attributes (respecting quoted values) to find\n * the actual `class` attribute. Returns the value range (start/end of the\n * value content, *excluding* the surrounding quotes) and the value, or\n * null if no `class` attribute is present.\n */\nfunction findClassAttribute(openingTag: string): { valueStart: number; valueEnd: number; value: string } | null {\n // Skip past the tag name. Tag starts with `<`; first run of [A-Za-z0-9-]\n // is the tag name. Anything after is attribute territory.\n let i = 1\n while (i < openingTag.length && /[A-Za-z0-9_:-]/.test(openingTag[i])) i++\n\n while (i < openingTag.length) {\n // Skip whitespace\n while (i < openingTag.length && /\\s/.test(openingTag[i])) i++\n if (i >= openingTag.length) break\n if (openingTag[i] === '>' || openingTag[i] === '/') break\n\n // Read attribute name\n const nameStart = i\n while (i < openingTag.length && !/[\\s=>/]/.test(openingTag[i])) i++\n const name = openingTag.slice(nameStart, i)\n\n // Optional whitespace + '=' + optional whitespace + value\n while (i < openingTag.length && /\\s/.test(openingTag[i])) i++\n if (openingTag[i] !== '=') {\n // Bare attribute (no value) — not class\n continue\n }\n i++ // past '='\n while (i < openingTag.length && /\\s/.test(openingTag[i])) i++\n\n // Value: quoted or unquoted\n let valueStart: number\n let valueEnd: number\n if (openingTag[i] === '\"' || openingTag[i] === \"'\") {\n const quote = openingTag[i]\n i++\n valueStart = i\n while (i < openingTag.length && openingTag[i] !== quote) i++\n valueEnd = i\n if (i < openingTag.length) i++ // past closing quote\n } else {\n valueStart = i\n while (i < openingTag.length && !/[\\s>/]/.test(openingTag[i])) i++\n valueEnd = i\n }\n\n if (name.toLowerCase() === 'class') {\n return { valueStart, valueEnd, value: openingTag.slice(valueStart, valueEnd) }\n }\n }\n\n return null\n}\n\n/**\n * Walks html and returns ranges for every top-level `<table>...</table>`\n * block. Nested tables aren't extracted as separate top-level entries —\n * they're captured inside the parent's content range and handled when the\n * cell-level diff recurses through them.\n */\nfunction findTopLevelTables(html: string): TableRange[] {\n const tables: TableRange[] = []\n let i = 0\n while (i < html.length) {\n if (matchesTagAt(html, i, 'table')) {\n const opening = parseOpeningTagAt(html, i)\n if (!opening) {\n i++\n continue\n }\n const tableContentStart = opening.end\n const tableEnd = findMatchingClosingTag(html, tableContentStart, 'table')\n if (tableEnd === -1) {\n i = opening.end\n continue\n }\n const closingTagStart = tableEnd - '</table>'.length\n const rows = findTopLevelRows(html, tableContentStart, closingTagStart)\n tables.push({ tableStart: i, tableEnd, rows })\n i = tableEnd\n } else {\n i++\n }\n }\n return tables\n}\n\nfunction findTopLevelRows(html: string, start: number, end: number): RowRange[] {\n const rows: RowRange[] = []\n let i = start\n while (i < end) {\n if (matchesTagAt(html, i, 'tr')) {\n const opening = parseOpeningTagAt(html, i)\n if (!opening) {\n i++\n continue\n }\n const rowContentStart = opening.end\n const rowEnd = findMatchingClosingTag(html, rowContentStart, 'tr', end)\n if (rowEnd === -1) {\n i = opening.end\n continue\n }\n const closingTagStart = rowEnd - '</tr>'.length\n const cells = findTopLevelCells(html, rowContentStart, closingTagStart)\n rows.push({ rowStart: i, rowEnd, cells })\n i = rowEnd\n } else if (matchesClosingTagAt(html, i, 'table')) {\n // Defensive: bail out if we encounter a closing </table> while\n // scanning rows (we should have stopped at `end` already).\n break\n } else {\n i++\n }\n }\n return rows\n}\n\nfunction findTopLevelCells(html: string, start: number, end: number): CellRange[] {\n const cells: CellRange[] = []\n let i = start\n while (i < end) {\n if (matchesTagAt(html, i, 'td') || matchesTagAt(html, i, 'th')) {\n const tagName = matchesTagAt(html, i, 'td') ? 'td' : 'th'\n const opening = parseOpeningTagAt(html, i)\n if (!opening) {\n i++\n continue\n }\n const contentStart = opening.end\n const cellEnd = findMatchingClosingTag(html, contentStart, tagName, end)\n if (cellEnd === -1) {\n i = opening.end\n continue\n }\n const contentEnd = cellEnd - `</${tagName}>`.length\n cells.push({ cellStart: i, cellEnd, contentStart, contentEnd })\n i = cellEnd\n } else if (matchesClosingTagAt(html, i, 'tr')) {\n break\n } else {\n i++\n }\n }\n return cells\n}\n\nfunction matchesTagAt(html: string, i: number, tagName: string): boolean {\n if (html[i] !== '<') return false\n const candidate = html.slice(i + 1, i + 1 + tagName.length).toLowerCase()\n if (candidate !== tagName) return false\n const after = html[i + 1 + tagName.length]\n return after === '>' || after === ' ' || after === '\\t' || after === '\\n' || after === '\\r' || after === '/'\n}\n\nfunction matchesClosingTagAt(html: string, i: number, tagName: string): boolean {\n if (html[i] !== '<' || html[i + 1] !== '/') return false\n const candidate = html.slice(i + 2, i + 2 + tagName.length).toLowerCase()\n if (candidate !== tagName) return false\n const after = html[i + 2 + tagName.length]\n return after === '>' || after === ' ' || after === '\\t' || after === '\\n' || after === '\\r'\n}\n\ninterface OpeningTag {\n /** Index just past the closing `>` of the opening tag. */\n end: number\n}\n\nfunction parseOpeningTagAt(html: string, i: number): OpeningTag | null {\n // HTML comments, CDATA, processing instructions, and DOCTYPE need their\n // own terminators — a plain `>`-walker would cut a comment like\n // `<!-- a > b -->` at the first inner `>`, treating the rest as text\n // and corrupting downstream offsets. Word-exported HTML routinely\n // emits comments inside tables (conditional comments, OLE markers) so\n // these have to be handled, not just be theoretical.\n if (html.startsWith('<!--', i)) {\n const close = html.indexOf('-->', i + 4)\n return close === -1 ? null : { end: close + 3 }\n }\n if (html.startsWith('<![CDATA[', i)) {\n const close = html.indexOf(']]>', i + 9)\n return close === -1 ? null : { end: close + 3 }\n }\n if (html.startsWith('<?', i)) {\n const close = html.indexOf('?>', i + 2)\n return close === -1 ? null : { end: close + 2 }\n }\n // Walk to the next unquoted '>'. Handles attributes whose values contain\n // a literal '>' inside quotes, which a plain indexOf would mishandle.\n let j = i + 1\n let quote: string | null = null\n while (j < html.length) {\n const ch = html[j]\n if (quote) {\n if (ch === quote) quote = null\n } else if (ch === '\"' || ch === \"'\") {\n quote = ch\n } else if (ch === '>') {\n return { end: j + 1 }\n }\n j++\n }\n return null\n}\n\n/**\n * Returns the index just past the matching `</tagName>`, accounting for\n * nested tags of the same name. Returns -1 if no match before `limit`.\n */\nfunction findMatchingClosingTag(html: string, from: number, tagName: string, limit: number = html.length): number {\n let depth = 1\n let i = from\n while (i < limit) {\n if (matchesTagAt(html, i, tagName)) {\n const opening = parseOpeningTagAt(html, i)\n if (!opening) {\n i++\n continue\n }\n const tagText = html.slice(i, opening.end)\n if (!tagText.endsWith('/>')) depth++\n i = opening.end\n } else if (matchesClosingTagAt(html, i, tagName)) {\n depth--\n const closing = parseOpeningTagAt(html, i)\n const closingEnd = closing?.end ?? i + `</${tagName}>`.length\n if (depth === 0) return closingEnd\n i = closingEnd\n } else {\n i++\n }\n }\n return -1\n}\n","import Mode from './Mode'\nimport Utils from './Utils'\n\nexport default class WordSplitter {\n private text: string\n private isBlockCheckRequired: boolean\n private blockLocations: BlockFinderResult\n private mode: Mode\n private isGrouping = false\n private globbingUntil: number\n private currentWord: string[]\n private words: string[]\n private static NotGlobbing = -1\n\n private get currentWordHasChars() {\n return this.currentWord.length > 0\n }\n\n constructor(text: string, blockExpressions: RegExp[]) {\n this.text = text\n this.blockLocations = new BlockFinder(text, blockExpressions).findBlocks()\n this.isBlockCheckRequired = this.blockLocations.hasBlocks\n this.mode = Mode.Character\n this.globbingUntil = WordSplitter.NotGlobbing\n this.currentWord = []\n this.words = []\n }\n\n process(): string[] {\n for (let index = 0; index < this.text.length; index++) {\n const character = this.text.charAt(index)\n this.processCharacter(index, character)\n }\n\n this.appendCurrentWordToWords()\n return this.words\n }\n\n private processCharacter(index: number, character: string) {\n if (this.isGlobbing(index, character)) {\n return\n }\n\n switch (this.mode) {\n case Mode.Character:\n this.processTextCharacter(character)\n break\n case Mode.Tag:\n this.processHtmlTagContinuation(character)\n break\n case Mode.Whitespace:\n this.processWhiteSpaceContinuation(character)\n break\n case Mode.Entity:\n this.processEntityContinuation(character)\n break\n }\n }\n\n private processEntityContinuation(character: string) {\n if (Utils.isStartOfTag(character)) {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Tag\n } else if (character.trim().length === 0) {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Whitespace\n } else if (Utils.isEndOfEntity(character)) {\n let switchToNextMode = true\n if (this.currentWordHasChars) {\n this.currentWord.push(character)\n this.words.push(this.currentWord.join(''))\n\n //join &nbsp; entity with last whitespace\n if (\n this.words.length > 2 &&\n Utils.isWhiteSpace(this.words[this.words.length - 2]) &&\n Utils.isWhiteSpace(this.words[this.words.length - 1])\n ) {\n const w1 = this.words[this.words.length - 2]\n const w2 = this.words[this.words.length - 1]\n this.words.splice(this.words.length - 2, 2)\n this.currentWord = `${w1}${w2}`.split('')\n this.mode = Mode.Whitespace\n switchToNextMode = false\n }\n }\n\n if (switchToNextMode) {\n this.currentWord = []\n this.mode = Mode.Character\n }\n } else if (Utils.isWord(character)) {\n this.currentWord.push(character)\n } else {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Character\n }\n }\n\n private processWhiteSpaceContinuation(character: string) {\n if (Utils.isStartOfTag(character)) {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Tag\n } else if (Utils.isStartOfEntity(character)) {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Entity\n } else if (Utils.isWhiteSpace(character)) {\n this.currentWord.push(character)\n } else {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Character\n }\n }\n\n private processHtmlTagContinuation(character: string) {\n if (Utils.isEndOfTag(character)) {\n this.currentWord.push(character)\n this.appendCurrentWordToWords()\n this.mode = Utils.isWhiteSpace(character) ? Mode.Whitespace : Mode.Character\n } else {\n this.currentWord.push(character)\n }\n }\n\n private processTextCharacter(character: string) {\n if (Utils.isStartOfTag(character)) {\n this.appendCurrentWordToWords()\n this.currentWord.push('<')\n this.mode = Mode.Tag\n } else if (Utils.isStartOfEntity(character)) {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Entity\n } else if (Utils.isWhiteSpace(character)) {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Whitespace\n } else if (\n Utils.isWord(character) &&\n (this.currentWord.length === 0 || Utils.isWord(this.currentWord[this.currentWord.length - 1]))\n ) {\n this.currentWord.push(character)\n } else {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n }\n }\n\n private appendCurrentWordToWords() {\n if (this.currentWordHasChars) {\n this.words.push(this.currentWord.join(''))\n this.currentWord = []\n }\n }\n\n private isGlobbing(index: number, character: string): boolean {\n if (!this.isBlockCheckRequired) {\n return false\n }\n const isCurrentBlockTerminating = index === this.globbingUntil\n if (isCurrentBlockTerminating) {\n this.globbingUntil = WordSplitter.NotGlobbing\n this.isGrouping = false\n this.appendCurrentWordToWords()\n }\n\n const until = this.blockLocations.isInBlock(index)\n if (until) {\n this.isGrouping = true\n this.globbingUntil = until\n }\n if (this.isGrouping) {\n this.currentWord.push(character)\n this.mode = Mode.Character\n }\n return this.isGrouping\n }\n\n static convertHtmlToListOfWords(text: string, blockExpressions: RegExp[]): string[] {\n return new WordSplitter(text, blockExpressions).process()\n }\n}\n\nclass BlockFinderResult {\n private blocks: Map<number, number> = new Map()\n\n addBlock(from: number, to: number) {\n if (this.blocks.has(from)) {\n throw new ArgumentError('One or more block expressions result in a text sequence that overlaps.')\n }\n\n this.blocks.set(from, to)\n }\n\n isInBlock(location: number): number | null {\n return this.blocks.get(location) ?? null\n }\n\n get hasBlocks() {\n return this.blocks.size > 0\n }\n}\n\nclass ArgumentError extends Error {}\n\nclass BlockFinder {\n private text: string\n private blockExpressions: RegExp[]\n\n constructor(text: string, blockExpressions: RegExp[]) {\n this.text = text\n this.blockExpressions = blockExpressions\n }\n\n findBlocks(): BlockFinderResult {\n const result = new BlockFinderResult()\n for (const expression of this.blockExpressions) {\n this.processBlockMatcher(expression, result)\n }\n return result\n }\n\n private processBlockMatcher(exp: RegExp, result: BlockFinderResult) {\n let match: RegExpExecArray | null\n // biome-ignore lint/suspicious/noAssignInExpressions: Couldn't think of a nicer way to do this\n while ((match = exp.exec(this.text)) !== null) {\n this.tryAddBlock(exp, match, result)\n }\n }\n\n private tryAddBlock(exp: RegExp, match: RegExpExecArray, result: BlockFinderResult) {\n try {\n const from = match.index\n const to = match.index + match[0].length\n result.addBlock(from, to)\n } catch {\n throw new ArgumentError(\n `One or more block expressions result in a text sequence that overlaps. Current expression: ${exp}`\n )\n }\n }\n}\n","import Action from './Action'\nimport Match from './Match'\nimport MatchFinder from './MatchFinder'\nimport Operation from './Operation'\nimport { preprocessTables, restoreTablePlaceholders } from './TableDiff'\nimport Utils from './Utils'\nimport WordSplitter from './WordSplitter'\n\nexport default class HtmlDiff {\n /**\n * This value defines balance between speed and memory utilization. The higher it is the faster it works and more memory consumes.\n * @private\n */\n private static MatchGranularityMaximum = 4\n\n private static DelTag = 'del'\n private static InsTag = 'ins'\n\n // ignore case\n private static SpecialCaseClosingTags = [\n '</strong>',\n '</em>',\n '</b>',\n '</i>',\n '</big>',\n '</small>',\n '</u>',\n '</sub>',\n '</sup>',\n '</strike>',\n '</s>',\n '</span>',\n ]\n\n private static SpecialCaseClosingTagsSet = new Set([\n '</strong>',\n '</em>',\n '</b>',\n '</i>',\n '</big>',\n '</small>',\n '</u>',\n '</sub>',\n '</sup>',\n '</strike>',\n '</s>',\n '</span>',\n ])\n\n private static SpecialCaseOpeningTagRegex =\n /<((strong)|(b)|(i)|(em)|(big)|(small)|(u)|(sub)|(sup)|(strike)|(s)|(span))[>\\s]+/i\n\n private static FormattingTags = new Set([\n 'strong',\n 'em',\n 'b',\n 'i',\n 'big',\n 'small',\n 'u',\n 'sub',\n 'sup',\n 'strike',\n 's',\n 'span',\n ])\n\n /**\n * Hard cap on nested `HtmlDiff.execute` calls (table preprocessing\n * recurses through `diffCell` for cell content). Each level allocates\n * fresh DP matrices and word arrays; without a guard a maliciously\n * nested table-in-cell-in-table-in-cell input could blow stack and\n * memory. Set high enough to comfortably handle real legal documents\n * (tables nested 2-3 deep at most), low enough to short-circuit\n * pathological input.\n */\n private static MaxTablePreprocessDepth = 8\n\n private content: string[] = []\n private newText: string\n private oldText: string\n private readonly tablePreprocessDepth: number\n\n private specialTagDiffStack: string[] = []\n private newWords: string[] = []\n private oldWords: string[] = []\n /**\n * Content-only projections of oldWords/newWords (structural tags and adjacent whitespace removed).\n * When null, no structural normalization is applied (the word arrays are identical for diffing).\n */\n private oldContentWords: string[] | null = null\n private newContentWords: string[] | null = null\n /** Maps content-word index → original word index */\n private oldContentToOriginal: number[] | null = null\n private newContentToOriginal: number[] | null = null\n /**\n * Tracks the next unwritten word index in oldWords/newWords. Mutated only by\n * {@link sliceOriginalWordsForOp} (each op reads a slice and advances its cursor).\n * Advances monotonically. Used so:\n * - subsequent equal/delete ops know where in old to resume from\n * - subsequent insert ops know where in new to resume from\n * The two cursors are independent: equal/delete output from old and advance the old\n * cursor; insert outputs from new and advances the new cursor.\n */\n private lastOriginalOldOutputIndex = 0\n private lastOriginalNewOutputIndex = 0\n private matchGranularity = 0\n private blockExpressions: RegExp[] = []\n\n /**\n * Defines how to compare repeating words. Valid values are from 0 to 1.\n * This value allows to exclude some words from comparison that eventually\n * reduces the total time of the diff algorithm.\n * 0 means that all words are excluded so the diff will not find any matching words at all.\n * 1 (default value) means that all words participate in comparison so this is the most accurate case.\n * 0.5 means that any word that occurs more than 50% times may be excluded from comparison. This doesn't\n * mean that such words will definitely be excluded but only gives a permission to exclude them if necessary.\n */\n repeatingWordsAccuracy = 1.0\n\n /**\n * If true all whitespaces are considered as equal\n */\n ignoreWhitespaceDifferences = false\n\n /**\n * If some match is too small and located far from its neighbors then it is considered as orphan\n * and removed. For example:\n * <code>\n * aaaaa bb ccccccccc dddddd ee\n * 11111 bb 222222222 dddddd ee\n * </code>\n * will find two matches <code>bb</code> and <code>dddddd ee</code> but the first will be considered\n * as orphan and ignored, as result it will consider texts <code>aaaaa bb ccccccccc</code> and\n * <code>11111 bb 222222222</code> as single replacement:\n * <code>\n * &lt;del&gt;aaaaa bb ccccccccc&lt;/del&gt;&lt;ins&gt;11111 bb 222222222&lt;/ins&gt; dddddd ee\n * </code>\n * This property defines relative size of the match to be considered as orphan, from 0 to 1.\n * 1 means that all matches will be considered as orphans.\n * 0 (default) means that no match will be considered as orphan.\n * 0.2 means that if match length is less than 20% of distance between its neighbors it is considered as orphan.\n */\n orphanMatchThreshold = 0.0\n\n /**\n * Initializes a new instance of the class.\n * @param oldText The old text.\n * @param newText The new text.\n * @param tablePreprocessDepth Internal: nested-call depth for table\n * preprocessing. Callers should leave at default (0); the recursive\n * `diffCell` callback in TableDiff bumps it.\n */\n constructor(oldText: string, newText: string, tablePreprocessDepth = 0) {\n this.oldText = oldText\n this.newText = newText\n this.tablePreprocessDepth = tablePreprocessDepth\n }\n\n static execute(oldText: string, newText: string, tablePreprocessDepth = 0) {\n return new HtmlDiff(oldText, newText, tablePreprocessDepth).build()\n }\n\n /**\n * Builds the HTML diff output\n * @return HTML diff markup\n */\n build(): string {\n // If there is no difference, don't bother checking for differences\n if (this.oldText === this.newText) {\n return this.newText\n }\n\n // Table preprocessing: when both sides have matching `<table>` structures,\n // diff cells positionally so cross-cell content shifts produce one\n // independent del/ins per cell rather than cell-misaligned output.\n // Recursion guarded by MaxTablePreprocessDepth to bound work on\n // deeply-nested table-in-cell-in-table inputs. Caller-configured\n // settings (block expressions, accuracy thresholds) are propagated to\n // the recursive cell diff so cell-level output is consistent with the\n // top-level configuration.\n const blockExpressions = this.blockExpressions\n const repeatingWordsAccuracy = this.repeatingWordsAccuracy\n const orphanMatchThreshold = this.orphanMatchThreshold\n const ignoreWhitespaceDifferences = this.ignoreWhitespaceDifferences\n const tablePreprocess =\n this.tablePreprocessDepth >= HtmlDiff.MaxTablePreprocessDepth\n ? null\n : preprocessTables(this.oldText, this.newText, (oldCell, newCell) => {\n const inner = new HtmlDiff(oldCell, newCell, this.tablePreprocessDepth + 1)\n for (const expr of blockExpressions) inner.addBlockExpression(expr)\n inner.repeatingWordsAccuracy = repeatingWordsAccuracy\n inner.orphanMatchThreshold = orphanMatchThreshold\n inner.ignoreWhitespaceDifferences = ignoreWhitespaceDifferences\n return inner.build()\n })\n if (tablePreprocess) {\n this.oldText = tablePreprocess.modifiedOld\n this.newText = tablePreprocess.modifiedNew\n }\n\n this.splitInputsToWords()\n this.buildContentProjections()\n\n const wordsForDiffOld = this.oldContentWords ?? this.oldWords\n const wordsForDiffNew = this.newContentWords ?? this.newWords\n\n this.matchGranularity = Math.min(\n HtmlDiff.MatchGranularityMaximum,\n Math.min(wordsForDiffOld.length, wordsForDiffNew.length)\n )\n\n const operations = this.operations()\n for (const op of operations) {\n this.performOperation(op)\n }\n\n const result = this.content.join('')\n return tablePreprocess ? restoreTablePlaceholders(result, tablePreprocess.placeholderToDiff) : result\n }\n\n /**\n * Uses {@link expression} to group text together so that any change detected within the group is treated as a single block\n * @param expression\n */\n addBlockExpression(expression: RegExp) {\n this.blockExpressions.push(expression)\n }\n\n private splitInputsToWords() {\n this.oldWords = WordSplitter.convertHtmlToListOfWords(this.oldText, this.blockExpressions)\n\n // free memory, allow it for GC\n this.oldText = ''\n\n this.newWords = WordSplitter.convertHtmlToListOfWords(this.newText, this.blockExpressions)\n\n // free memory, allow it for GC\n this.newText = ''\n }\n\n /**\n * Builds \"content projections\" — word arrays with structural wrapper tags stripped — when\n * structural normalization is appropriate for these inputs. The diff algorithm operates on\n * the projections so wrapper-tag differences (e.g. `<p>` vs `<div>`) don't appear as content\n * changes; structural tags are then folded back in at output time.\n */\n private buildContentProjections() {\n if (!HtmlDiff.hasStructuralDifferences(this.oldWords, this.newWords)) return\n\n const oldProjection = HtmlDiff.createContentProjection(this.oldWords)\n const newProjection = HtmlDiff.createContentProjection(this.newWords)\n\n if (!HtmlDiff.shouldUseContentProjections(this.oldWords, this.newWords, oldProjection, newProjection)) {\n return\n }\n\n this.oldContentWords = oldProjection.contentWords\n this.oldContentToOriginal = oldProjection.contentToOriginal\n this.newContentWords = newProjection.contentWords\n this.newContentToOriginal = newProjection.contentToOriginal\n }\n\n /**\n * Decides whether structural normalization should be activated for this pair of inputs.\n * Each clause is a distinct correctness or fitness check — extend by adding a named\n * sub-predicate rather than chaining ad-hoc conditions.\n */\n private static shouldUseContentProjections(\n oldWords: string[],\n newWords: string[],\n oldProjection: { contentWords: string[]; contentToOriginal: number[] },\n newProjection: { contentWords: string[]; contentToOriginal: number[] }\n ): boolean {\n // One side has no content at all: that's a genuine addition/deletion, not a wrapper rename.\n // Normalization would mis-attribute the wrappers as part of the diff.\n if (oldProjection.contentWords.length === 0 || newProjection.contentWords.length === 0) return false\n\n // Asymmetric structural state: one side has no structural wrappers at all (e.g. plain text\n // vs. wrapped HTML). Normalization would force the equal output to use the unwrapped side's\n // (missing) structure and emit dangling closing tags from the wrapped side. The plain\n // word-level diff handles this correctly without normalization.\n const oldHasStructuralTags = oldProjection.contentWords.length < oldWords.length\n const newHasStructuralTags = newProjection.contentWords.length < newWords.length\n if (oldHasStructuralTags !== newHasStructuralTags) return false\n\n return true\n }\n\n /**\n * Tags that commonly serve as content wrappers and may change structurally\n * without affecting the actual content. Only these tags are stripped during\n * structural normalization.\n */\n private static WrapperTags = new Set(['div', 'p', 'section', 'article', 'main', 'header', 'footer', 'aside', 'nav'])\n\n private static isStructuralTag(word: string): boolean {\n if (!Utils.isTag(word)) return false\n const tagName = Utils.getTagName(word)\n return HtmlDiff.WrapperTags.has(tagName)\n }\n\n /** True when the word is a structural opening tag (e.g. `<p>`, `<div>`). */\n private static isOpeningStructuralTag(word: string): boolean {\n return HtmlDiff.isStructuralTag(word) && !word.startsWith('</')\n }\n\n /**\n * Returns true if words between structural tags are just whitespace (indentation).\n */\n private static isStructuralWhitespace(words: string[], index: number): boolean {\n if (!Utils.isWhiteSpace(words[index])) return false\n\n // Check if this whitespace is adjacent to a structural tag on either side\n const prevIsStructural = index === 0 || HtmlDiff.isStructuralTag(words[index - 1])\n const nextIsStructural = index === words.length - 1 || HtmlDiff.isStructuralTag(words[index + 1])\n return prevIsStructural || nextIsStructural\n }\n\n private static createContentProjection(words: string[]): {\n contentWords: string[]\n contentToOriginal: number[]\n } {\n const contentWords: string[] = []\n const contentToOriginal: number[] = []\n\n for (let i = 0; i < words.length; i++) {\n if (HtmlDiff.isStructuralTag(words[i])) continue\n if (HtmlDiff.isStructuralWhitespace(words, i)) continue\n contentWords.push(words[i])\n contentToOriginal.push(i)\n }\n\n return { contentWords, contentToOriginal }\n }\n\n private static hasStructuralDifferences(oldWords: string[], newWords: string[]): boolean {\n const oldStructural: string[] = []\n const newStructural: string[] = []\n\n // Compare only tag names (stripped of attributes) since structural normalization\n // is about wrapper tag name changes (e.g. <p> vs <div>), not attribute differences.\n // Attribute changes on the same tag name don't need projection-based normalization.\n for (const w of oldWords) {\n if (HtmlDiff.isStructuralTag(w)) {\n oldStructural.push(Utils.stripTagAttributes(w))\n }\n }\n for (const w of newWords) {\n if (HtmlDiff.isStructuralTag(w)) {\n newStructural.push(Utils.stripTagAttributes(w))\n }\n }\n\n if (oldStructural.length !== newStructural.length) return true\n for (let i = 0; i < oldStructural.length; i++) {\n if (oldStructural[i] !== newStructural[i]) return true\n }\n return false\n }\n\n private performOperation(operation: Operation) {\n switch (operation.action) {\n case Action.Equal:\n this.processEqualOperation(operation)\n break\n case Action.Delete:\n this.processDeleteOperation(operation, 'diffdel')\n break\n case Action.Insert:\n this.processInsertOperation(operation, 'diffins')\n break\n case Action.None:\n break\n case Action.Replace:\n this.processReplaceOperation(operation)\n break\n }\n }\n\n private processReplaceOperation(operation: Operation) {\n this.processDeleteOperation(operation, 'diffmod')\n this.processInsertOperation(operation, 'diffmod')\n }\n\n private processInsertOperation(operation: Operation, cssClass: string) {\n const words = this.usingContentProjections()\n ? this.sliceOriginalWordsForOp('new', operation.startInNew, operation.endInNew)\n : this.newWords.slice(operation.startInNew, operation.endInNew)\n this.insertTag(HtmlDiff.InsTag, cssClass, words)\n }\n\n private processDeleteOperation(operation: Operation, cssClass: string) {\n const words = this.usingContentProjections()\n ? this.sliceOriginalWordsForOp('old', operation.startInOld, operation.endInOld)\n : this.oldWords.slice(operation.startInOld, operation.endInOld)\n this.insertTag(HtmlDiff.DelTag, cssClass, words)\n }\n\n private processEqualOperation(operation: Operation) {\n if (this.usingContentProjections()) {\n // Output from old to preserve old's HTML structure for the matched content.\n const result = this.sliceOriginalWordsForOp('old', operation.startInOld, operation.endInOld)\n this.content.push(result.join(''))\n\n // Advance new-side tracking past the equivalent range in new so the next insert op\n // resumes from the correct position. We compute new's range with the same rule used\n // for old (rather than mirroring old's count) so the two sides are independently sound\n // when their structural tags don't perfectly parallel each other.\n this.sliceOriginalWordsForOp('new', operation.startInNew, operation.endInNew)\n } else {\n const result = this.newWords.slice(operation.startInNew, operation.endInNew)\n this.content.push(result.join(''))\n }\n }\n\n /** True when content projections are active for both sides — i.e. structural normalization is in effect. */\n private usingContentProjections(): boolean {\n return this.oldContentToOriginal !== null && this.newContentToOriginal !== null\n }\n\n /**\n * Returns the slice of original (old or new) words covering a content-index range,\n * including the structural tags that surround the content. Advances the side's cursor\n * past the slice so the next op resumes correctly.\n *\n * The slice extends:\n * - LEADING: from the side's cursor (or the first content word's original index,\n * whichever is smaller) so structural tags that precede the first content word\n * are picked up by this op rather than left orphaned.\n * - TRAILING (non-last range): from just after the last content word, including\n * closing structural tags that close *this* op's paragraphs, but stopping at\n * the first opening structural tag — that opening tag belongs to the next\n * op's paragraph and would otherwise be emitted twice.\n * - TRAILING (last range): all the way to the end of words, since there is no next\n * op to claim the trailing tags.\n */\n private sliceOriginalWordsForOp(side: 'old' | 'new', contentStart: number, contentEnd: number): string[] {\n const words = side === 'old' ? this.oldWords : this.newWords\n const contentToOriginal = side === 'old' ? this.oldContentToOriginal : this.newContentToOriginal\n\n if (!contentToOriginal) return words.slice(contentStart, contentEnd)\n if (contentStart >= contentEnd) return []\n\n const firstContentOrigIdx = contentToOriginal[contentStart]\n const lastContentOrigIdx = contentToOriginal[contentEnd - 1]\n const cursor = side === 'old' ? this.lastOriginalOldOutputIndex : this.lastOriginalNewOutputIndex\n const origStart = Math.min(cursor, firstContentOrigIdx)\n\n let origEnd: number\n if (contentEnd < contentToOriginal.length) {\n // Non-last range: walk trailing tags after the last content word, stopping at the\n // first opening structural tag so it can be emitted by the next op.\n const limit = contentToOriginal[contentEnd]\n origEnd = lastContentOrigIdx + 1\n while (origEnd < limit && !HtmlDiff.isOpeningStructuralTag(words[origEnd])) {\n origEnd++\n }\n } else {\n // Last range: include everything to the end.\n origEnd = words.length\n }\n\n if (side === 'old') {\n this.lastOriginalOldOutputIndex = origEnd\n } else {\n this.lastOriginalNewOutputIndex = origEnd\n }\n\n return words.slice(origStart, origEnd)\n }\n\n /**\n * This method encloses words within a specified tag (ins or del), and adds this into \"content\",\n * with a twist: if there are words contain tags, it actually creates multiple ins or del,\n * so that they don't include any ins or del. This handles cases like\n * old: '<p>a</p>'\n * new: '<p>ab</p>\n * <p>\n * c</b>'\n * diff result: '<p>a<ins>b</ins></p>\n * <p>\n * <ins>c</ins>\n * </p>\n * '\n * this still doesn't guarantee valid HTML (hint: think about diffing a text containing ins or\n * del tags), but handles correctly more cases than the earlier version.\n * P.S.: Spare a thought for people who write HTML browsers. They live in this ... every day.\n * @param tag\n * @param cssClass\n * @param words\n * @private\n */\n private insertTag(tag: string, cssClass: string, words: string[]) {\n while (true) {\n if (words.length === 0) {\n break\n }\n\n const allWordsUntilFirstTag = this.extractConsecutiveWords(words, x => !Utils.isTag(x))\n if (allWordsUntilFirstTag.length > 0) {\n const text = Utils.wrapText(allWordsUntilFirstTag.join(''), tag, cssClass)\n this.content.push(text)\n }\n\n const isInsertOpCompleted = words.length === 0\n if (isInsertOpCompleted) {\n break\n }\n\n // if there are still words left, they must start with a tag, but still can contain nonTag entries.\n // e.g. </span></big>bar\n // the remaining words need to be handled separately divided in a tagBlock, which definitely contains\n // at least one word and a potentially existing second block which starts with a nonTag but may\n // contain tags later on.\n const indexOfFirstNonTag = words.findIndex(x => !Utils.isTag(x))\n\n // if there are no nonTags, the whole block is a tagBlock and the index of the last tag is the last index of the block.\n // if there are nonTags, the index of the last tag is the index before the first nonTag.\n const indexLastTagInFirstTagBlock = indexOfFirstNonTag === -1 ? words.length - 1 : indexOfFirstNonTag - 1\n\n let specialCaseTagInjection = ''\n let specialCaseTagInjectionIsBefore = false\n\n // handle opening tag\n if (HtmlDiff.SpecialCaseOpeningTagRegex.test(words[0])) {\n const tagNames = new Set<string>()\n for (const word of words) {\n if (Utils.isTag(word)) {\n tagNames.add(Utils.getTagName(word))\n }\n }\n const styledTagNames = Array.from(tagNames).join(' ')\n\n this.specialTagDiffStack.push(words[0])\n specialCaseTagInjection = `<ins class='mod ${styledTagNames}'>`\n if (tag === HtmlDiff.DelTag) {\n words.shift()\n\n // following tags may be formatting tags as well, follow through\n while (words.length > 0 && HtmlDiff.SpecialCaseOpeningTagRegex.test(words[0])) {\n words.shift()\n }\n }\n }\n // handle closing tag\n else if (HtmlDiff.SpecialCaseClosingTagsSet.has(words[0].toLowerCase())) {\n const openingTag = this.specialTagDiffStack.length === 0 ? null : this.specialTagDiffStack.pop()\n // For delete operations: when the tag block contains a mix of formatting and\n // non-formatting closing tags (e.g. </strong></div>), compare against the first\n // closing tag (the formatting one) rather than the last tag in the block.\n // For purely formatting tag blocks (e.g. </i></strong>) or insert operations,\n // use the last tag as before to match against the outermost opening tag.\n let tagIndexToCompare = indexLastTagInFirstTagBlock\n if (tag === HtmlDiff.DelTag && indexOfFirstNonTag === -1) {\n const hasNonFormattingClosingTag = words\n .slice(0, indexLastTagInFirstTagBlock + 1)\n .some(w => !HtmlDiff.SpecialCaseClosingTagsSet.has(w.toLowerCase()))\n if (hasNonFormattingClosingTag) {\n tagIndexToCompare = 0\n }\n }\n const openingAndClosingTagsMatch =\n !!openingTag && Utils.getTagName(openingTag) === Utils.getTagName(words[tagIndexToCompare])\n\n if (openingTag && openingAndClosingTagsMatch) {\n specialCaseTagInjection = '</ins>'\n specialCaseTagInjectionIsBefore = true\n }\n\n // if the tag has a corresponding opening tag, but they don't match,\n // we need to push the opening tag back onto the stack\n else if (openingTag) {\n this.specialTagDiffStack.push(openingTag)\n }\n\n if (tag === HtmlDiff.DelTag) {\n words.shift()\n // following tags may be formatting tags as well, follow through\n while (words.length > 0 && HtmlDiff.SpecialCaseClosingTagsSet.has(words[0].toLowerCase())) {\n words.shift()\n }\n }\n }\n\n if (words.length === 0 && specialCaseTagInjection.length === 0) {\n break\n }\n\n // For delete operations, only extract non-formatting tags. Formatting tags (special case\n // opening/closing tags) need to be handled in the next loop iteration so they go through\n // the proper specialTagDiffStack logic. Otherwise, opening formatting tags get output as\n // plain tags and their corresponding closing tags are later discarded, producing invalid HTML.\n const isTagForExtraction =\n tag === HtmlDiff.DelTag\n ? (x: string) =>\n Utils.isTag(x) &&\n !HtmlDiff.SpecialCaseOpeningTagRegex.test(x) &&\n !HtmlDiff.SpecialCaseClosingTagsSet.has(x.toLowerCase())\n : Utils.isTag\n\n if (specialCaseTagInjectionIsBefore) {\n this.content.push(specialCaseTagInjection + this.extractConsecutiveWords(words, isTagForExtraction).join(''))\n } else {\n this.content.push(this.extractConsecutiveWords(words, isTagForExtraction).join('') + specialCaseTagInjection)\n }\n\n if (words.length === 0) continue\n\n // if there are still words left, they must start with a nonTag and need to be handled in the next iteration.\n this.insertTag(tag, cssClass, words)\n break\n }\n }\n\n private extractConsecutiveWords(words: string[], condition: (character: string) => boolean): string[] {\n let indexOfFirstTag: number | null = null\n for (let i = 0; i < words.length; i++) {\n const word = words[i]\n if (i === 0 && word === ' ') {\n words[i] = '&nbsp;'\n }\n if (!condition(word)) {\n indexOfFirstTag = i\n break\n }\n }\n\n if (indexOfFirstTag !== null) {\n const items = words.slice(0, indexOfFirstTag)\n if (indexOfFirstTag > 0) {\n words.splice(0, indexOfFirstTag)\n }\n return items\n }\n\n const items = words.slice(0)\n words.splice(0, words.length)\n return items\n }\n\n private operations(): Operation[] {\n let positionInOld = 0\n let positionInNew = 0\n const operations: Operation[] = []\n\n const wordsForDiffOld = this.oldContentWords ?? this.oldWords\n const wordsForDiffNew = this.newContentWords ?? this.newWords\n\n const matches = this.matchingBlocks()\n matches.push(new Match(wordsForDiffOld.length, wordsForDiffNew.length, 0))\n\n //Remove orphans from matches.\n //If distance between left and right matches is 4 times longer than length of current match then it is considered as orphan\n const matchesWithoutOrphans = this.removeOrphans(matches)\n\n for (const match of matchesWithoutOrphans) {\n const matchStartsAtCurrentPositionInOld = positionInOld === match.startInOld\n const matchStartsAtCurrentPositionInNew = positionInNew === match.startInNew\n\n let action: Action\n\n if (!matchStartsAtCurrentPositionInOld && !matchStartsAtCurrentPositionInNew) {\n action = Action.Replace\n } else if (matchStartsAtCurrentPositionInOld && !matchStartsAtCurrentPositionInNew) {\n action = Action.Insert\n } else if (!matchStartsAtCurrentPositionInOld) {\n action = Action.Delete\n } // This occurs if the first few words are the same in both versions\n else {\n action = Action.None\n }\n\n if (action !== Action.None) {\n operations.push(new Operation(action, positionInOld, match.startInOld, positionInNew, match.startInNew))\n }\n\n if (match.size !== 0) {\n operations.push(new Operation(Action.Equal, match.startInOld, match.endInOld, match.startInNew, match.endInNew))\n }\n\n positionInOld = match.endInOld\n positionInNew = match.endInNew\n }\n\n return operations\n }\n\n private *removeOrphans(matches: Match[]) {\n const wordsForDiffOld = this.oldContentWords ?? this.oldWords\n const wordsForDiffNew = this.newContentWords ?? this.newWords\n\n let prev: Match = new Match(0, 0, 0)\n let curr: Match | null = null\n\n for (const next of matches) {\n if (curr === null) {\n curr = next\n continue\n }\n\n if (\n (prev.endInOld === curr.startInOld && prev.endInNew === curr.startInNew) ||\n (curr.endInOld === next.startInOld && curr.endInNew === next.startInNew)\n ) {\n //if match has no diff on the left or on the right\n yield curr\n prev = curr\n curr = next\n continue\n }\n\n let oldDistanceInChars = 0\n for (let i = prev.endInOld; i < next.startInOld; i++) {\n oldDistanceInChars += wordsForDiffOld[i].length\n }\n let newDistanceInChars = 0\n for (let i = prev.endInNew; i < next.startInNew; i++) {\n newDistanceInChars += wordsForDiffNew[i].length\n }\n let currMatchLengthInChars = 0\n for (let i = curr.startInNew; i < curr.endInNew; i++) {\n currMatchLengthInChars += wordsForDiffNew[i].length\n }\n\n if (currMatchLengthInChars > Math.max(oldDistanceInChars, newDistanceInChars) * this.orphanMatchThreshold) {\n yield curr\n }\n\n prev = curr\n curr = next\n }\n\n if (curr !== null) {\n yield curr //assume that the last match is always vital\n }\n }\n\n private matchingBlocks(): Match[] {\n const wordsForDiffOld = this.oldContentWords ?? this.oldWords\n const wordsForDiffNew = this.newContentWords ?? this.newWords\n const matchingBlocks: Match[] = []\n this.findMatchingBlocks(0, wordsForDiffOld.length, 0, wordsForDiffNew.length, matchingBlocks)\n return matchingBlocks\n }\n\n private findMatchingBlocks(\n startInOld: number,\n endInOld: number,\n startInNew: number,\n endInNew: number,\n matchingBlocks: Match[]\n ) {\n const match = this.findMatch(startInOld, endInOld, startInNew, endInNew)\n\n if (match !== null) {\n if (startInOld < match.startInOld && startInNew < match.startInNew) {\n this.findMatchingBlocks(startInOld, match.startInOld, startInNew, match.startInNew, matchingBlocks)\n }\n\n matchingBlocks.push(match)\n\n if (match.endInOld < endInOld && match.endInNew < endInNew) {\n this.findMatchingBlocks(match.endInOld, endInOld, match.endInNew, endInNew, matchingBlocks)\n }\n }\n }\n\n private findMatch(startInOld: number, endInOld: number, startInNew: number, endInNew: number): Match | null {\n const wordsForDiffOld = this.oldContentWords ?? this.oldWords\n const wordsForDiffNew = this.newContentWords ?? this.newWords\n\n // For large texts it is more likely that there is a Match of size bigger than maximum granularity.\n // If not then go down and try to find it with smaller granularity.\n for (let i = this.matchGranularity; i > 0; i--) {\n const options = {\n blockSize: i,\n repeatingWordsAccuracy: this.repeatingWordsAccuracy,\n ignoreWhitespaceDifferences: this.ignoreWhitespaceDifferences,\n }\n const finder = new MatchFinder(\n wordsForDiffOld,\n wordsForDiffNew,\n startInOld,\n endInOld,\n startInNew,\n endInNew,\n options\n )\n const match = finder.findMatch()\n if (match !== null) return match\n }\n return null\n }\n}\n"],"mappings":";AAAA,IAAqB,QAArB,MAA2B;CACzB;CACA;CACA;CAEA,YAAY,YAAoB,YAAoB,MAAc;EAChE,KAAK,cAAc;EACnB,KAAK,cAAc;EACnB,KAAK,QAAQ;;CAGf,IAAI,aAAa;EACf,OAAO,KAAK;;CAGd,IAAI,aAAa;EACf,OAAO,KAAK;;CAGd,IAAI,OAAO;EACT,OAAO,KAAK;;CAGd,IAAI,WAAW;EACb,OAAO,KAAK,cAAc,KAAK;;CAGjC,IAAI,WAAW;EACb,OAAO,KAAK,cAAc,KAAK;;;;;AC5BnC,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,eAAe;AACrB,MAAM,kBAAkB;AACxB,MAAM,YAAY;AAClB,MAAM,WAAW;AAEjB,MAAM,sBAAyC,CAAC,OAAO;AAEvD,SAAgB,MAAM,MAAuB;CAC3C,IAAI,oBAAoB,MAAK,OAAM,MAAM,WAAW,GAAG,CAAC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KAAK,sBACnF,MAAM;GAGR,OAAO;GACP,OAAO;;EAGT,IAAI,SAAS,MACX,MAAM;;CAIV,iBAAkC;EAChC,MAAM,kBAAkB,KAAK,mBAAmB,KAAK;EACrD,MAAM,kBAAkB,KAAK,mBAAmB,KAAK;EACrD,MAAM,iBAA0B,EAAE;EAClC,KAAK,mBAAmB,GAAG,gBAAgB,QAAQ,GAAG,gBAAgB,QAAQ,eAAe;EAC7F,OAAO;;CAGT,mBACE,YACA,UACA,YACA,UACA,gBACA;EACA,MAAM,QAAQ,KAAK,UAAU,YAAY,UAAU,YAAY,SAAS;EAExE,IAAI,UAAU,MAAM;GAClB,IAAI,aAAa,MAAM,cAAc,aAAa,MAAM,YACtD,KAAK,mBAAmB,YAAY,MAAM,YAAY,YAAY,MAAM,YAAY,eAAe;GAGrG,eAAe,KAAK,MAAM;GAE1B,IAAI,MAAM,WAAW,YAAY,MAAM,WAAW,UAChD,KAAK,mBAAmB,MAAM,UAAU,UAAU,MAAM,UAAU,UAAU,eAAe;;;CAKjG,UAAkB,YAAoB,UAAkB,YAAoB,UAAgC;EAC1G,MAAM,kBAAkB,KAAK,mBAAmB,KAAK;EACrD,MAAM,kBAAkB,KAAK,mBAAmB,KAAK;EAIrD,KAAK,IAAI,IAAI,KAAK,kBAAkB,IAAI,GAAG,KAAK;GAe9C,MAAM,QAAQ,IATK,YACjB,iBACA,iBACA,YACA,UACA,YACA,UACA;IAXA,WAAW;IACX,wBAAwB,KAAK;IAC7B,6BAA6B,KAAK;IAS3B,CAEW,CAAC,WAAW;GAChC,IAAI,UAAU,MAAM,OAAO;;EAE7B,OAAO"}
1
+ {"version":3,"file":"HtmlDiff.cjs","names":["Utils","Utils","Utils"],"sources":["../src/Match.ts","../src/Utils.ts","../src/MatchFinder.ts","../src/Operation.ts","../src/WordSplitter.ts","../src/HtmlDiff.ts"],"sourcesContent":["export default class Match {\n private _startInOld: number\n private _startInNew: number\n private _size: number\n\n constructor(startInOld: number, startInNew: number, size: number) {\n this._startInOld = startInOld\n this._startInNew = startInNew\n this._size = size\n }\n\n get startInOld() {\n return this._startInOld\n }\n\n get startInNew() {\n return this._startInNew\n }\n\n get size() {\n return this._size\n }\n\n get endInOld() {\n return this._startInOld + this._size\n }\n\n get endInNew() {\n return this._startInNew + this._size\n }\n}\n","const openingTagRegex = /^\\s*<[^>]+>\\s*$/\nconst closingTagTexRegex = /^\\s*<\\/[^>]+>\\s*$/\nconst tagWordRegex = /<[^\\s>]+/\nconst whitespaceRegex = /^(\\s|&nbsp;)+$/\nconst wordRegex = /[\\w#@]+/\nconst tagRegex = /<\\/?(?<name>[^\\s/>]+)[^>]*>/\n\nconst SpecialCaseWordTags: readonly string[] = ['<img']\n\nexport function isTag(item: string): boolean {\n if (SpecialCaseWordTags.some(re => item?.startsWith(re))) {\n return false\n }\n\n return isOpeningTag(item) || isClosingTag(item)\n}\n\nfunction isOpeningTag(item: string): boolean {\n return openingTagRegex.test(item)\n}\n\nfunction isClosingTag(item: string): boolean {\n return closingTagTexRegex.test(item)\n}\n\nexport function stripTagAttributes(word: string): string {\n const match = tagWordRegex.exec(word)\n if (match) {\n return `${match[0]}${word.endsWith('/>') ? '/>' : '>'}`\n }\n\n return word\n}\n\nexport function wrapText(text: string, tagName: string, cssClass: string): string {\n return `<${tagName} class='${cssClass}'>${text}</${tagName}>`\n}\n\nexport function isStartOfTag(val: string): boolean {\n return val === '<'\n}\n\nexport function isEndOfTag(val: string): boolean {\n return val === '>'\n}\n\nexport function isStartOfEntity(val: string): boolean {\n return val === '&'\n}\n\nexport function isEndOfEntity(val: string): boolean {\n return val === ';'\n}\n\nexport function isWhiteSpace(value: string): boolean {\n return whitespaceRegex.test(value)\n}\n\nexport function stripAnyAttributes(word: string): string {\n if (isTag(word)) {\n return stripTagAttributes(word)\n }\n\n return word\n}\n\nexport function isWord(text: string): boolean {\n return wordRegex.test(text)\n}\n\nexport function getTagName(word: string | null): string {\n if (word === null) {\n return ''\n }\n\n const match = tagRegex.exec(word)\n if (match) {\n return match.groups?.name.toLowerCase() ?? match[1].toLowerCase()\n }\n\n return ''\n}\n\nexport default {\n isTag,\n stripTagAttributes,\n wrapText,\n isStartOfTag,\n isEndOfTag,\n isStartOfEntity,\n isEndOfEntity,\n isWhiteSpace,\n stripAnyAttributes,\n isWord,\n getTagName,\n}\n","import Match from './Match'\nimport type MatchOptions from './MatchOptions'\nimport Utils from './Utils'\n\n/**\n * Finds the longest match in given texts. It uses indexing with fixed granularity that is used to compare blocks of text.\n */\nexport default class MatchFinder {\n private oldWords: string[]\n private newWords: string[]\n private startInOld: number\n private endInOld: number\n private startInNew: number\n private endInNew: number\n private wordIndices: { [word: string]: number[] } = {}\n private options: MatchOptions\n\n constructor(\n oldWords: string[],\n newWords: string[],\n startInOld: number,\n endInOld: number,\n startInNew: number,\n endInNew: number,\n options: MatchOptions\n ) {\n this.oldWords = oldWords\n this.newWords = newWords\n this.startInOld = startInOld\n this.endInOld = endInOld\n this.startInNew = startInNew\n this.endInNew = endInNew\n this.options = options\n }\n\n private indexNewWords() {\n this.wordIndices = {}\n const block: string[] = []\n for (let i = this.startInNew; i < this.endInNew; i++) {\n // if word is a tag, we should ignore attributes as attribute changes are not supported (yet)\n const word = this.normalizeForIndex(this.newWords[i])\n const key = MatchFinder.putNewWord(block, word, this.options.blockSize)\n\n if (key === null) {\n continue\n }\n\n if (!this.wordIndices[key]) {\n this.wordIndices[key] = []\n }\n this.wordIndices[key].push(i)\n }\n }\n\n private static putNewWord(block: string[], word: string, blockSize: number): string | null {\n block.push(word)\n\n if (block.length > blockSize) {\n block.shift()\n }\n\n if (block.length !== blockSize) {\n return null\n }\n\n return block.join('')\n }\n\n private normalizeForIndex(word: string): string {\n const output = Utils.stripAnyAttributes(word)\n if (this.options.ignoreWhitespaceDifferences && Utils.isWhiteSpace(output)) {\n return ' '\n }\n\n return output\n }\n\n findMatch(): Match | null {\n this.indexNewWords()\n this.removeRepeatingWords()\n\n let hasIndices = false\n for (const _key in this.wordIndices) {\n hasIndices = true\n break\n }\n if (!hasIndices) {\n return null\n }\n\n let bestMatchInOld = this.startInOld\n let bestMatchInNew = this.startInNew\n let bestMatchSize = 0\n\n let matchLengthAt: Map<number, number> = new Map()\n const block: string[] = []\n\n for (let indexInOld = this.startInOld; indexInOld < this.endInOld; indexInOld++) {\n const word = this.normalizeForIndex(this.oldWords[indexInOld])\n const index = MatchFinder.putNewWord(block, word, this.options.blockSize)\n\n if (index === null) {\n continue\n }\n\n const newMatchLengthAt: Map<number, number> = new Map()\n\n if (!this.wordIndices[index]) {\n matchLengthAt = newMatchLengthAt\n continue\n }\n\n for (const indexInNew of this.wordIndices[index]) {\n // biome-ignore lint/style/noNonNullAssertion: This is safe as guarded by has()\n const newMatchLength = (matchLengthAt.has(indexInNew - 1) ? matchLengthAt.get(indexInNew - 1)! : 0) + 1\n newMatchLengthAt.set(indexInNew, newMatchLength)\n\n if (newMatchLength > bestMatchSize) {\n bestMatchInOld = indexInOld - newMatchLength - this.options.blockSize + 2\n bestMatchInNew = indexInNew - newMatchLength - this.options.blockSize + 2\n bestMatchSize = newMatchLength\n }\n }\n\n matchLengthAt = newMatchLengthAt\n }\n\n return bestMatchSize !== 0\n ? new Match(bestMatchInOld, bestMatchInNew, bestMatchSize + this.options.blockSize - 1)\n : null\n }\n\n /**\n * This method removes words that occur too many times. This way it reduces total count of comparison operations\n * and as result the diff algorithm takes less time. But the side effect is that it may detect false differences of\n * the repeating words.\n * @private\n */\n private removeRepeatingWords() {\n const threshold = this.newWords.length * this.options.repeatingWordsAccuracy\n const repeatingWords = Object.entries(this.wordIndices)\n .filter(([, indices]) => indices.length > threshold)\n .map(([word]) => word)\n\n for (const w of repeatingWords) {\n delete this.wordIndices[w]\n }\n }\n}\n","import type Action from './Action'\n\nexport default class Operation {\n action: Action\n startInOld: number\n endInOld: number\n startInNew: number\n endInNew: number\n\n constructor(action: Action, startInOld: number, endInOld: number, startInNew: number, endInNew: number) {\n this.action = action\n this.startInOld = startInOld\n this.endInOld = endInOld\n this.startInNew = startInNew\n this.endInNew = endInNew\n }\n}\n","import Mode from './Mode'\nimport Utils from './Utils'\n\nexport default class WordSplitter {\n private text: string\n private isBlockCheckRequired: boolean\n private blockLocations: BlockFinderResult\n private mode: Mode\n private isGrouping = false\n private globbingUntil: number\n private currentWord: string[]\n private words: string[]\n private static NotGlobbing = -1\n\n private get currentWordHasChars() {\n return this.currentWord.length > 0\n }\n\n constructor(text: string, blockExpressions: RegExp[]) {\n this.text = text\n this.blockLocations = new BlockFinder(text, blockExpressions).findBlocks()\n this.isBlockCheckRequired = this.blockLocations.hasBlocks\n this.mode = Mode.Character\n this.globbingUntil = WordSplitter.NotGlobbing\n this.currentWord = []\n this.words = []\n }\n\n process(): string[] {\n for (let index = 0; index < this.text.length; index++) {\n const character = this.text.charAt(index)\n this.processCharacter(index, character)\n }\n\n this.appendCurrentWordToWords()\n return this.words\n }\n\n private processCharacter(index: number, character: string) {\n if (this.isGlobbing(index, character)) {\n return\n }\n\n switch (this.mode) {\n case Mode.Character:\n this.processTextCharacter(character)\n break\n case Mode.Tag:\n this.processHtmlTagContinuation(character)\n break\n case Mode.Whitespace:\n this.processWhiteSpaceContinuation(character)\n break\n case Mode.Entity:\n this.processEntityContinuation(character)\n break\n }\n }\n\n private processEntityContinuation(character: string) {\n if (Utils.isStartOfTag(character)) {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Tag\n } else if (character.trim().length === 0) {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Whitespace\n } else if (Utils.isEndOfEntity(character)) {\n let switchToNextMode = true\n if (this.currentWordHasChars) {\n this.currentWord.push(character)\n this.words.push(this.currentWord.join(''))\n\n //join &nbsp; entity with last whitespace\n if (\n this.words.length > 2 &&\n Utils.isWhiteSpace(this.words[this.words.length - 2]) &&\n Utils.isWhiteSpace(this.words[this.words.length - 1])\n ) {\n const w1 = this.words[this.words.length - 2]\n const w2 = this.words[this.words.length - 1]\n this.words.splice(this.words.length - 2, 2)\n this.currentWord = `${w1}${w2}`.split('')\n this.mode = Mode.Whitespace\n switchToNextMode = false\n }\n }\n\n if (switchToNextMode) {\n this.currentWord = []\n this.mode = Mode.Character\n }\n } else if (Utils.isWord(character)) {\n this.currentWord.push(character)\n } else {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Character\n }\n }\n\n private processWhiteSpaceContinuation(character: string) {\n if (Utils.isStartOfTag(character)) {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Tag\n } else if (Utils.isStartOfEntity(character)) {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Entity\n } else if (Utils.isWhiteSpace(character)) {\n this.currentWord.push(character)\n } else {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Character\n }\n }\n\n private processHtmlTagContinuation(character: string) {\n if (Utils.isEndOfTag(character)) {\n this.currentWord.push(character)\n this.appendCurrentWordToWords()\n this.mode = Utils.isWhiteSpace(character) ? Mode.Whitespace : Mode.Character\n } else {\n this.currentWord.push(character)\n }\n }\n\n private processTextCharacter(character: string) {\n if (Utils.isStartOfTag(character)) {\n this.appendCurrentWordToWords()\n this.currentWord.push('<')\n this.mode = Mode.Tag\n } else if (Utils.isStartOfEntity(character)) {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Entity\n } else if (Utils.isWhiteSpace(character)) {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n this.mode = Mode.Whitespace\n } else if (\n Utils.isWord(character) &&\n (this.currentWord.length === 0 || Utils.isWord(this.currentWord[this.currentWord.length - 1]))\n ) {\n this.currentWord.push(character)\n } else {\n this.appendCurrentWordToWords()\n this.currentWord.push(character)\n }\n }\n\n private appendCurrentWordToWords() {\n if (this.currentWordHasChars) {\n this.words.push(this.currentWord.join(''))\n this.currentWord = []\n }\n }\n\n private isGlobbing(index: number, character: string): boolean {\n if (!this.isBlockCheckRequired) {\n return false\n }\n const isCurrentBlockTerminating = index === this.globbingUntil\n if (isCurrentBlockTerminating) {\n this.globbingUntil = WordSplitter.NotGlobbing\n this.isGrouping = false\n this.appendCurrentWordToWords()\n }\n\n const until = this.blockLocations.isInBlock(index)\n if (until) {\n this.isGrouping = true\n this.globbingUntil = until\n }\n if (this.isGrouping) {\n this.currentWord.push(character)\n this.mode = Mode.Character\n }\n return this.isGrouping\n }\n\n static convertHtmlToListOfWords(text: string, blockExpressions: RegExp[]): string[] {\n return new WordSplitter(text, blockExpressions).process()\n }\n}\n\nclass BlockFinderResult {\n private blocks: Map<number, number> = new Map()\n\n addBlock(from: number, to: number) {\n if (this.blocks.has(from)) {\n throw new ArgumentError('One or more block expressions result in a text sequence that overlaps.')\n }\n\n this.blocks.set(from, to)\n }\n\n isInBlock(location: number): number | null {\n return this.blocks.get(location) ?? null\n }\n\n get hasBlocks() {\n return this.blocks.size > 0\n }\n}\n\nclass ArgumentError extends Error {}\n\nclass BlockFinder {\n private text: string\n private blockExpressions: RegExp[]\n\n constructor(text: string, blockExpressions: RegExp[]) {\n this.text = text\n this.blockExpressions = blockExpressions\n }\n\n findBlocks(): BlockFinderResult {\n const result = new BlockFinderResult()\n for (const expression of this.blockExpressions) {\n this.processBlockMatcher(expression, result)\n }\n return result\n }\n\n private processBlockMatcher(exp: RegExp, result: BlockFinderResult) {\n let match: RegExpExecArray | null\n // biome-ignore lint/suspicious/noAssignInExpressions: Couldn't think of a nicer way to do this\n while ((match = exp.exec(this.text)) !== null) {\n this.tryAddBlock(exp, match, result)\n }\n }\n\n private tryAddBlock(exp: RegExp, match: RegExpExecArray, result: BlockFinderResult) {\n try {\n const from = match.index\n const to = match.index + match[0].length\n result.addBlock(from, to)\n } catch {\n throw new ArgumentError(\n `One or more block expressions result in a text sequence that overlaps. Current expression: ${exp}`\n )\n }\n }\n}\n","import Action from './Action'\nimport Match from './Match'\nimport MatchFinder from './MatchFinder'\nimport Operation from './Operation'\nimport Utils from './Utils'\nimport WordSplitter from './WordSplitter'\n\nexport default class HtmlDiff {\n /**\n * This value defines balance between speed and memory utilization. The higher it is the faster it works and more memory consumes.\n * @private\n */\n private static MatchGranularityMaximum = 4\n\n private static DelTag = 'del'\n private static InsTag = 'ins'\n\n // ignore case\n private static SpecialCaseClosingTags = [\n '</strong>',\n '</em>',\n '</b>',\n '</i>',\n '</big>',\n '</small>',\n '</u>',\n '</sub>',\n '</sup>',\n '</strike>',\n '</s>',\n '</span>',\n ]\n\n private static SpecialCaseClosingTagsSet = new Set([\n '</strong>',\n '</em>',\n '</b>',\n '</i>',\n '</big>',\n '</small>',\n '</u>',\n '</sub>',\n '</sup>',\n '</strike>',\n '</s>',\n '</span>',\n ])\n\n private static SpecialCaseOpeningTagRegex =\n /<((strong)|(b)|(i)|(em)|(big)|(small)|(u)|(sub)|(sup)|(strike)|(s)|(span))[>\\s]+/i\n\n private static FormattingTags = new Set([\n 'strong',\n 'em',\n 'b',\n 'i',\n 'big',\n 'small',\n 'u',\n 'sub',\n 'sup',\n 'strike',\n 's',\n 'span',\n ])\n\n private content: string[] = []\n private newText: string\n private oldText: string\n\n private specialTagDiffStack: string[] = []\n private newWords: string[] = []\n private oldWords: string[] = []\n /**\n * Content-only projections of oldWords/newWords (structural tags and adjacent whitespace removed).\n * When null, no structural normalization is applied (the word arrays are identical for diffing).\n */\n private oldContentWords: string[] | null = null\n private newContentWords: string[] | null = null\n /** Maps content-word index → original word index */\n private oldContentToOriginal: number[] | null = null\n private newContentToOriginal: number[] | null = null\n /**\n * Tracks the next unwritten word index in oldWords/newWords. Mutated only by\n * {@link sliceOriginalWordsForOp} (each op reads a slice and advances its cursor).\n * Advances monotonically. Used so:\n * - subsequent equal/delete ops know where in old to resume from\n * - subsequent insert ops know where in new to resume from\n * The two cursors are independent: equal/delete output from old and advance the old\n * cursor; insert outputs from new and advances the new cursor.\n */\n private lastOriginalOldOutputIndex = 0\n private lastOriginalNewOutputIndex = 0\n private matchGranularity = 0\n private blockExpressions: RegExp[] = []\n\n /**\n * Defines how to compare repeating words. Valid values are from 0 to 1.\n * This value allows to exclude some words from comparison that eventually\n * reduces the total time of the diff algorithm.\n * 0 means that all words are excluded so the diff will not find any matching words at all.\n * 1 (default value) means that all words participate in comparison so this is the most accurate case.\n * 0.5 means that any word that occurs more than 50% times may be excluded from comparison. This doesn't\n * mean that such words will definitely be excluded but only gives a permission to exclude them if necessary.\n */\n repeatingWordsAccuracy = 1.0\n\n /**\n * If true all whitespaces are considered as equal\n */\n ignoreWhitespaceDifferences = false\n\n /**\n * If some match is too small and located far from its neighbors then it is considered as orphan\n * and removed. For example:\n * <code>\n * aaaaa bb ccccccccc dddddd ee\n * 11111 bb 222222222 dddddd ee\n * </code>\n * will find two matches <code>bb</code> and <code>dddddd ee</code> but the first will be considered\n * as orphan and ignored, as result it will consider texts <code>aaaaa bb ccccccccc</code> and\n * <code>11111 bb 222222222</code> as single replacement:\n * <code>\n * &lt;del&gt;aaaaa bb ccccccccc&lt;/del&gt;&lt;ins&gt;11111 bb 222222222&lt;/ins&gt; dddddd ee\n * </code>\n * This property defines relative size of the match to be considered as orphan, from 0 to 1.\n * 1 means that all matches will be considered as orphans.\n * 0 (default) means that no match will be considered as orphan.\n * 0.2 means that if match length is less than 20% of distance between its neighbors it is considered as orphan.\n */\n orphanMatchThreshold = 0.0\n\n /**\n * Initializes a new instance of the class.\n * @param oldText The old text.\n * @param newText The new text.\n */\n constructor(oldText: string, newText: string) {\n this.oldText = oldText\n this.newText = newText\n }\n\n static execute(oldText: string, newText: string) {\n return new HtmlDiff(oldText, newText).build()\n }\n\n /**\n * Builds the HTML diff output\n * @return HTML diff markup\n */\n build(): string {\n // If there is no difference, don't bother checking for differences\n if (this.oldText === this.newText) {\n return this.newText\n }\n\n this.splitInputsToWords()\n this.buildContentProjections()\n\n const wordsForDiffOld = this.oldContentWords ?? this.oldWords\n const wordsForDiffNew = this.newContentWords ?? this.newWords\n\n this.matchGranularity = Math.min(\n HtmlDiff.MatchGranularityMaximum,\n Math.min(wordsForDiffOld.length, wordsForDiffNew.length)\n )\n\n const operations = this.operations()\n for (const op of operations) {\n this.performOperation(op)\n }\n\n return this.content.join('')\n }\n\n /**\n * Uses {@link expression} to group text together so that any change detected within the group is treated as a single block\n * @param expression\n */\n addBlockExpression(expression: RegExp) {\n this.blockExpressions.push(expression)\n }\n\n private splitInputsToWords() {\n this.oldWords = WordSplitter.convertHtmlToListOfWords(this.oldText, this.blockExpressions)\n\n // free memory, allow it for GC\n this.oldText = ''\n\n this.newWords = WordSplitter.convertHtmlToListOfWords(this.newText, this.blockExpressions)\n\n // free memory, allow it for GC\n this.newText = ''\n }\n\n /**\n * Builds \"content projections\" — word arrays with structural wrapper tags stripped — when\n * structural normalization is appropriate for these inputs. The diff algorithm operates on\n * the projections so wrapper-tag differences (e.g. `<p>` vs `<div>`) don't appear as content\n * changes; structural tags are then folded back in at output time.\n */\n private buildContentProjections() {\n if (!HtmlDiff.hasStructuralDifferences(this.oldWords, this.newWords)) return\n\n const oldProjection = HtmlDiff.createContentProjection(this.oldWords)\n const newProjection = HtmlDiff.createContentProjection(this.newWords)\n\n if (!HtmlDiff.shouldUseContentProjections(this.oldWords, this.newWords, oldProjection, newProjection)) {\n return\n }\n\n this.oldContentWords = oldProjection.contentWords\n this.oldContentToOriginal = oldProjection.contentToOriginal\n this.newContentWords = newProjection.contentWords\n this.newContentToOriginal = newProjection.contentToOriginal\n }\n\n /**\n * Decides whether structural normalization should be activated for this pair of inputs.\n * Each clause is a distinct correctness or fitness check — extend by adding a named\n * sub-predicate rather than chaining ad-hoc conditions.\n */\n private static shouldUseContentProjections(\n oldWords: string[],\n newWords: string[],\n oldProjection: { contentWords: string[]; contentToOriginal: number[] },\n newProjection: { contentWords: string[]; contentToOriginal: number[] }\n ): boolean {\n // One side has no content at all: that's a genuine addition/deletion, not a wrapper rename.\n // Normalization would mis-attribute the wrappers as part of the diff.\n if (oldProjection.contentWords.length === 0 || newProjection.contentWords.length === 0) return false\n\n // Asymmetric structural state: one side has no structural wrappers at all (e.g. plain text\n // vs. wrapped HTML). Normalization would force the equal output to use the unwrapped side's\n // (missing) structure and emit dangling closing tags from the wrapped side. The plain\n // word-level diff handles this correctly without normalization.\n const oldHasStructuralTags = oldProjection.contentWords.length < oldWords.length\n const newHasStructuralTags = newProjection.contentWords.length < newWords.length\n if (oldHasStructuralTags !== newHasStructuralTags) return false\n\n return true\n }\n\n /**\n * Tags that commonly serve as content wrappers and may change structurally\n * without affecting the actual content. Only these tags are stripped during\n * structural normalization.\n */\n private static WrapperTags = new Set(['div', 'p', 'section', 'article', 'main', 'header', 'footer', 'aside', 'nav'])\n\n private static isStructuralTag(word: string): boolean {\n if (!Utils.isTag(word)) return false\n const tagName = Utils.getTagName(word)\n return HtmlDiff.WrapperTags.has(tagName)\n }\n\n /** True when the word is a structural opening tag (e.g. `<p>`, `<div>`). */\n private static isOpeningStructuralTag(word: string): boolean {\n return HtmlDiff.isStructuralTag(word) && !word.startsWith('</')\n }\n\n /**\n * Returns true if words between structural tags are just whitespace (indentation).\n */\n private static isStructuralWhitespace(words: string[], index: number): boolean {\n if (!Utils.isWhiteSpace(words[index])) return false\n\n // Check if this whitespace is adjacent to a structural tag on either side\n const prevIsStructural = index === 0 || HtmlDiff.isStructuralTag(words[index - 1])\n const nextIsStructural = index === words.length - 1 || HtmlDiff.isStructuralTag(words[index + 1])\n return prevIsStructural || nextIsStructural\n }\n\n private static createContentProjection(words: string[]): {\n contentWords: string[]\n contentToOriginal: number[]\n } {\n const contentWords: string[] = []\n const contentToOriginal: number[] = []\n\n for (let i = 0; i < words.length; i++) {\n if (HtmlDiff.isStructuralTag(words[i])) continue\n if (HtmlDiff.isStructuralWhitespace(words, i)) continue\n contentWords.push(words[i])\n contentToOriginal.push(i)\n }\n\n return { contentWords, contentToOriginal }\n }\n\n private static hasStructuralDifferences(oldWords: string[], newWords: string[]): boolean {\n const oldStructural: string[] = []\n const newStructural: string[] = []\n\n // Compare only tag names (stripped of attributes) since structural normalization\n // is about wrapper tag name changes (e.g. <p> vs <div>), not attribute differences.\n // Attribute changes on the same tag name don't need projection-based normalization.\n for (const w of oldWords) {\n if (HtmlDiff.isStructuralTag(w)) {\n oldStructural.push(Utils.stripTagAttributes(w))\n }\n }\n for (const w of newWords) {\n if (HtmlDiff.isStructuralTag(w)) {\n newStructural.push(Utils.stripTagAttributes(w))\n }\n }\n\n if (oldStructural.length !== newStructural.length) return true\n for (let i = 0; i < oldStructural.length; i++) {\n if (oldStructural[i] !== newStructural[i]) return true\n }\n return false\n }\n\n private performOperation(operation: Operation) {\n switch (operation.action) {\n case Action.Equal:\n this.processEqualOperation(operation)\n break\n case Action.Delete:\n this.processDeleteOperation(operation, 'diffdel')\n break\n case Action.Insert:\n this.processInsertOperation(operation, 'diffins')\n break\n case Action.None:\n break\n case Action.Replace:\n this.processReplaceOperation(operation)\n break\n }\n }\n\n private processReplaceOperation(operation: Operation) {\n this.processDeleteOperation(operation, 'diffmod')\n this.processInsertOperation(operation, 'diffmod')\n }\n\n private processInsertOperation(operation: Operation, cssClass: string) {\n const words = this.usingContentProjections()\n ? this.sliceOriginalWordsForOp('new', operation.startInNew, operation.endInNew)\n : this.newWords.slice(operation.startInNew, operation.endInNew)\n this.insertTag(HtmlDiff.InsTag, cssClass, words)\n }\n\n private processDeleteOperation(operation: Operation, cssClass: string) {\n const words = this.usingContentProjections()\n ? this.sliceOriginalWordsForOp('old', operation.startInOld, operation.endInOld)\n : this.oldWords.slice(operation.startInOld, operation.endInOld)\n this.insertTag(HtmlDiff.DelTag, cssClass, words)\n }\n\n private processEqualOperation(operation: Operation) {\n if (this.usingContentProjections()) {\n // Output from old to preserve old's HTML structure for the matched content.\n const result = this.sliceOriginalWordsForOp('old', operation.startInOld, operation.endInOld)\n this.content.push(result.join(''))\n\n // Advance new-side tracking past the equivalent range in new so the next insert op\n // resumes from the correct position. We compute new's range with the same rule used\n // for old (rather than mirroring old's count) so the two sides are independently sound\n // when their structural tags don't perfectly parallel each other.\n this.sliceOriginalWordsForOp('new', operation.startInNew, operation.endInNew)\n } else {\n const result = this.newWords.slice(operation.startInNew, operation.endInNew)\n this.content.push(result.join(''))\n }\n }\n\n /** True when content projections are active for both sides — i.e. structural normalization is in effect. */\n private usingContentProjections(): boolean {\n return this.oldContentToOriginal !== null && this.newContentToOriginal !== null\n }\n\n /**\n * Returns the slice of original (old or new) words covering a content-index range,\n * including the structural tags that surround the content. Advances the side's cursor\n * past the slice so the next op resumes correctly.\n *\n * The slice extends:\n * - LEADING: from the side's cursor (or the first content word's original index,\n * whichever is smaller) so structural tags that precede the first content word\n * are picked up by this op rather than left orphaned.\n * - TRAILING (non-last range): from just after the last content word, including\n * closing structural tags that close *this* op's paragraphs, but stopping at\n * the first opening structural tag — that opening tag belongs to the next\n * op's paragraph and would otherwise be emitted twice.\n * - TRAILING (last range): all the way to the end of words, since there is no next\n * op to claim the trailing tags.\n */\n private sliceOriginalWordsForOp(side: 'old' | 'new', contentStart: number, contentEnd: number): string[] {\n const words = side === 'old' ? this.oldWords : this.newWords\n const contentToOriginal = side === 'old' ? this.oldContentToOriginal : this.newContentToOriginal\n\n if (!contentToOriginal) return words.slice(contentStart, contentEnd)\n if (contentStart >= contentEnd) return []\n\n const firstContentOrigIdx = contentToOriginal[contentStart]\n const lastContentOrigIdx = contentToOriginal[contentEnd - 1]\n const cursor = side === 'old' ? this.lastOriginalOldOutputIndex : this.lastOriginalNewOutputIndex\n const origStart = Math.min(cursor, firstContentOrigIdx)\n\n let origEnd: number\n if (contentEnd < contentToOriginal.length) {\n // Non-last range: walk trailing tags after the last content word, stopping at the\n // first opening structural tag so it can be emitted by the next op.\n const limit = contentToOriginal[contentEnd]\n origEnd = lastContentOrigIdx + 1\n while (origEnd < limit && !HtmlDiff.isOpeningStructuralTag(words[origEnd])) {\n origEnd++\n }\n } else {\n // Last range: include everything to the end.\n origEnd = words.length\n }\n\n if (side === 'old') {\n this.lastOriginalOldOutputIndex = origEnd\n } else {\n this.lastOriginalNewOutputIndex = origEnd\n }\n\n return words.slice(origStart, origEnd)\n }\n\n /**\n * This method encloses words within a specified tag (ins or del), and adds this into \"content\",\n * with a twist: if there are words contain tags, it actually creates multiple ins or del,\n * so that they don't include any ins or del. This handles cases like\n * old: '<p>a</p>'\n * new: '<p>ab</p>\n * <p>\n * c</b>'\n * diff result: '<p>a<ins>b</ins></p>\n * <p>\n * <ins>c</ins>\n * </p>\n * '\n * this still doesn't guarantee valid HTML (hint: think about diffing a text containing ins or\n * del tags), but handles correctly more cases than the earlier version.\n * P.S.: Spare a thought for people who write HTML browsers. They live in this ... every day.\n * @param tag\n * @param cssClass\n * @param words\n * @private\n */\n private insertTag(tag: string, cssClass: string, words: string[]) {\n while (true) {\n if (words.length === 0) {\n break\n }\n\n const allWordsUntilFirstTag = this.extractConsecutiveWords(words, x => !Utils.isTag(x))\n if (allWordsUntilFirstTag.length > 0) {\n const text = Utils.wrapText(allWordsUntilFirstTag.join(''), tag, cssClass)\n this.content.push(text)\n }\n\n const isInsertOpCompleted = words.length === 0\n if (isInsertOpCompleted) {\n break\n }\n\n // if there are still words left, they must start with a tag, but still can contain nonTag entries.\n // e.g. </span></big>bar\n // the remaining words need to be handled separately divided in a tagBlock, which definitely contains\n // at least one word and a potentially existing second block which starts with a nonTag but may\n // contain tags later on.\n const indexOfFirstNonTag = words.findIndex(x => !Utils.isTag(x))\n\n // if there are no nonTags, the whole block is a tagBlock and the index of the last tag is the last index of the block.\n // if there are nonTags, the index of the last tag is the index before the first nonTag.\n const indexLastTagInFirstTagBlock = indexOfFirstNonTag === -1 ? words.length - 1 : indexOfFirstNonTag - 1\n\n let specialCaseTagInjection = ''\n let specialCaseTagInjectionIsBefore = false\n\n // handle opening tag\n if (HtmlDiff.SpecialCaseOpeningTagRegex.test(words[0])) {\n const tagNames = new Set<string>()\n for (const word of words) {\n if (Utils.isTag(word)) {\n tagNames.add(Utils.getTagName(word))\n }\n }\n const styledTagNames = Array.from(tagNames).join(' ')\n\n this.specialTagDiffStack.push(words[0])\n specialCaseTagInjection = `<ins class='mod ${styledTagNames}'>`\n if (tag === HtmlDiff.DelTag) {\n words.shift()\n\n // following tags may be formatting tags as well, follow through\n while (words.length > 0 && HtmlDiff.SpecialCaseOpeningTagRegex.test(words[0])) {\n words.shift()\n }\n }\n }\n // handle closing tag\n else if (HtmlDiff.SpecialCaseClosingTagsSet.has(words[0].toLowerCase())) {\n const openingTag = this.specialTagDiffStack.length === 0 ? null : this.specialTagDiffStack.pop()\n // For delete operations: when the tag block contains a mix of formatting and\n // non-formatting closing tags (e.g. </strong></div>), compare against the first\n // closing tag (the formatting one) rather than the last tag in the block.\n // For purely formatting tag blocks (e.g. </i></strong>) or insert operations,\n // use the last tag as before to match against the outermost opening tag.\n let tagIndexToCompare = indexLastTagInFirstTagBlock\n if (tag === HtmlDiff.DelTag && indexOfFirstNonTag === -1) {\n const hasNonFormattingClosingTag = words\n .slice(0, indexLastTagInFirstTagBlock + 1)\n .some(w => !HtmlDiff.SpecialCaseClosingTagsSet.has(w.toLowerCase()))\n if (hasNonFormattingClosingTag) {\n tagIndexToCompare = 0\n }\n }\n const openingAndClosingTagsMatch =\n !!openingTag && Utils.getTagName(openingTag) === Utils.getTagName(words[tagIndexToCompare])\n\n if (!!openingTag && openingAndClosingTagsMatch) {\n specialCaseTagInjection = '</ins>'\n specialCaseTagInjectionIsBefore = true\n }\n\n // if the tag has a corresponding opening tag, but they don't match,\n // we need to push the opening tag back onto the stack\n else if (openingTag) {\n this.specialTagDiffStack.push(openingTag)\n }\n\n if (tag === HtmlDiff.DelTag) {\n words.shift()\n // following tags may be formatting tags as well, follow through\n while (words.length > 0 && HtmlDiff.SpecialCaseClosingTagsSet.has(words[0].toLowerCase())) {\n words.shift()\n }\n }\n }\n\n if (words.length === 0 && specialCaseTagInjection.length === 0) {\n break\n }\n\n // For delete operations, only extract non-formatting tags. Formatting tags (special case\n // opening/closing tags) need to be handled in the next loop iteration so they go through\n // the proper specialTagDiffStack logic. Otherwise, opening formatting tags get output as\n // plain tags and their corresponding closing tags are later discarded, producing invalid HTML.\n const isTagForExtraction =\n tag === HtmlDiff.DelTag\n ? (x: string) =>\n Utils.isTag(x) &&\n !HtmlDiff.SpecialCaseOpeningTagRegex.test(x) &&\n !HtmlDiff.SpecialCaseClosingTagsSet.has(x.toLowerCase())\n : Utils.isTag\n\n if (specialCaseTagInjectionIsBefore) {\n this.content.push(specialCaseTagInjection + this.extractConsecutiveWords(words, isTagForExtraction).join(''))\n } else {\n this.content.push(this.extractConsecutiveWords(words, isTagForExtraction).join('') + specialCaseTagInjection)\n }\n\n if (words.length === 0) continue\n\n // if there are still words left, they must start with a nonTag and need to be handled in the next iteration.\n this.insertTag(tag, cssClass, words)\n break\n }\n }\n\n private extractConsecutiveWords(words: string[], condition: (character: string) => boolean): string[] {\n let indexOfFirstTag: number | null = null\n for (let i = 0; i < words.length; i++) {\n const word = words[i]\n if (i === 0 && word === ' ') {\n words[i] = '&nbsp;'\n }\n if (!condition(word)) {\n indexOfFirstTag = i\n break\n }\n }\n\n if (indexOfFirstTag !== null) {\n const items = words.slice(0, indexOfFirstTag)\n if (indexOfFirstTag > 0) {\n words.splice(0, indexOfFirstTag)\n }\n return items\n }\n\n const items = words.slice(0)\n words.splice(0, words.length)\n return items\n }\n\n private operations(): Operation[] {\n let positionInOld = 0\n let positionInNew = 0\n const operations: Operation[] = []\n\n const wordsForDiffOld = this.oldContentWords ?? this.oldWords\n const wordsForDiffNew = this.newContentWords ?? this.newWords\n\n const matches = this.matchingBlocks()\n matches.push(new Match(wordsForDiffOld.length, wordsForDiffNew.length, 0))\n\n //Remove orphans from matches.\n //If distance between left and right matches is 4 times longer than length of current match then it is considered as orphan\n const matchesWithoutOrphans = this.removeOrphans(matches)\n\n for (const match of matchesWithoutOrphans) {\n const matchStartsAtCurrentPositionInOld = positionInOld === match.startInOld\n const matchStartsAtCurrentPositionInNew = positionInNew === match.startInNew\n\n let action: Action\n\n if (!matchStartsAtCurrentPositionInOld && !matchStartsAtCurrentPositionInNew) {\n action = Action.Replace\n } else if (matchStartsAtCurrentPositionInOld && !matchStartsAtCurrentPositionInNew) {\n action = Action.Insert\n } else if (!matchStartsAtCurrentPositionInOld) {\n action = Action.Delete\n } // This occurs if the first few words are the same in both versions\n else {\n action = Action.None\n }\n\n if (action !== Action.None) {\n operations.push(new Operation(action, positionInOld, match.startInOld, positionInNew, match.startInNew))\n }\n\n if (match.size !== 0) {\n operations.push(new Operation(Action.Equal, match.startInOld, match.endInOld, match.startInNew, match.endInNew))\n }\n\n positionInOld = match.endInOld\n positionInNew = match.endInNew\n }\n\n return operations\n }\n\n private *removeOrphans(matches: Match[]) {\n const wordsForDiffOld = this.oldContentWords ?? this.oldWords\n const wordsForDiffNew = this.newContentWords ?? this.newWords\n\n let prev: Match = new Match(0, 0, 0)\n let curr: Match | null = null\n\n for (const next of matches) {\n if (curr === null) {\n curr = next\n continue\n }\n\n if (\n (prev.endInOld === curr.startInOld && prev.endInNew === curr.startInNew) ||\n (curr.endInOld === next.startInOld && curr.endInNew === next.startInNew)\n ) {\n //if match has no diff on the left or on the right\n yield curr\n prev = curr\n curr = next\n continue\n }\n\n let oldDistanceInChars = 0\n for (let i = prev.endInOld; i < next.startInOld; i++) {\n oldDistanceInChars += wordsForDiffOld[i].length\n }\n let newDistanceInChars = 0\n for (let i = prev.endInNew; i < next.startInNew; i++) {\n newDistanceInChars += wordsForDiffNew[i].length\n }\n let currMatchLengthInChars = 0\n for (let i = curr.startInNew; i < curr.endInNew; i++) {\n currMatchLengthInChars += wordsForDiffNew[i].length\n }\n\n if (currMatchLengthInChars > Math.max(oldDistanceInChars, newDistanceInChars) * this.orphanMatchThreshold) {\n yield curr\n }\n\n prev = curr\n curr = next\n }\n\n if (curr !== null) {\n yield curr //assume that the last match is always vital\n }\n }\n\n private matchingBlocks(): Match[] {\n const wordsForDiffOld = this.oldContentWords ?? this.oldWords\n const wordsForDiffNew = this.newContentWords ?? this.newWords\n const matchingBlocks: Match[] = []\n this.findMatchingBlocks(0, wordsForDiffOld.length, 0, wordsForDiffNew.length, matchingBlocks)\n return matchingBlocks\n }\n\n private findMatchingBlocks(\n startInOld: number,\n endInOld: number,\n startInNew: number,\n endInNew: number,\n matchingBlocks: Match[]\n ) {\n const match = this.findMatch(startInOld, endInOld, startInNew, endInNew)\n\n if (match !== null) {\n if (startInOld < match.startInOld && startInNew < match.startInNew) {\n this.findMatchingBlocks(startInOld, match.startInOld, startInNew, match.startInNew, matchingBlocks)\n }\n\n matchingBlocks.push(match)\n\n if (match.endInOld < endInOld && match.endInNew < endInNew) {\n this.findMatchingBlocks(match.endInOld, endInOld, match.endInNew, endInNew, matchingBlocks)\n }\n }\n }\n\n private findMatch(startInOld: number, endInOld: number, startInNew: number, endInNew: number): Match | null {\n const wordsForDiffOld = this.oldContentWords ?? this.oldWords\n const wordsForDiffNew = this.newContentWords ?? this.newWords\n\n // For large texts it is more likely that there is a Match of size bigger than maximum granularity.\n // If not then go down and try to find it with smaller granularity.\n for (let i = this.matchGranularity; i > 0; i--) {\n const options = {\n blockSize: i,\n repeatingWordsAccuracy: this.repeatingWordsAccuracy,\n ignoreWhitespaceDifferences: this.ignoreWhitespaceDifferences,\n }\n const finder = new MatchFinder(\n wordsForDiffOld,\n wordsForDiffNew,\n startInOld,\n endInOld,\n startInNew,\n endInNew,\n options\n )\n const match = finder.findMatch()\n if (match !== null) return match\n }\n return null\n }\n}\n"],"mappings":";AAAA,IAAqB,QAArB,MAA2B;CACzB;CACA;CACA;CAEA,YAAY,YAAoB,YAAoB,MAAc;EAChE,KAAK,cAAc;EACnB,KAAK,cAAc;EACnB,KAAK,QAAQ;;CAGf,IAAI,aAAa;EACf,OAAO,KAAK;;CAGd,IAAI,aAAa;EACf,OAAO,KAAK;;CAGd,IAAI,OAAO;EACT,OAAO,KAAK;;CAGd,IAAI,WAAW;EACb,OAAO,KAAK,cAAc,KAAK;;CAGjC,IAAI,WAAW;EACb,OAAO,KAAK,cAAc,KAAK;;;;;AC5BnC,MAAM,kBAAkB;AACxB,MAAM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K,YACjB,iBACA,iBACA,YACA,UACA,YACA,UACA;IAXA,WAAW;IACX,wBAAwB,KAAK;IAC7B,6BAA6B,KAAK;IAS3B,CAEW,CAAC,WAAW;GAChC,IAAI,UAAU,MAAM,OAAO;;EAE7B,OAAO"}
@@ -11,20 +11,9 @@ declare class HtmlDiff {
11
11
  private static SpecialCaseClosingTagsSet;
12
12
  private static SpecialCaseOpeningTagRegex;
13
13
  private static FormattingTags;
14
- /**
15
- * Hard cap on nested `HtmlDiff.execute` calls (table preprocessing
16
- * recurses through `diffCell` for cell content). Each level allocates
17
- * fresh DP matrices and word arrays; without a guard a maliciously
18
- * nested table-in-cell-in-table-in-cell input could blow stack and
19
- * memory. Set high enough to comfortably handle real legal documents
20
- * (tables nested 2-3 deep at most), low enough to short-circuit
21
- * pathological input.
22
- */
23
- private static MaxTablePreprocessDepth;
24
14
  private content;
25
15
  private newText;
26
16
  private oldText;
27
- private readonly tablePreprocessDepth;
28
17
  private specialTagDiffStack;
29
18
  private newWords;
30
19
  private oldWords;
@@ -87,12 +76,9 @@ declare class HtmlDiff {
87
76
  * Initializes a new instance of the class.
88
77
  * @param oldText The old text.
89
78
  * @param newText The new text.
90
- * @param tablePreprocessDepth Internal: nested-call depth for table
91
- * preprocessing. Callers should leave at default (0); the recursive
92
- * `diffCell` callback in TableDiff bumps it.
93
79
  */
94
- constructor(oldText: string, newText: string, tablePreprocessDepth?: number);
95
- static execute(oldText: string, newText: string, tablePreprocessDepth?: number): string;
80
+ constructor(oldText: string, newText: string);
81
+ static execute(oldText: string, newText: string): string;
96
82
  /**
97
83
  * Builds the HTML diff output
98
84
  * @return HTML diff markup
@@ -11,20 +11,9 @@ declare class HtmlDiff {
11
11
  private static SpecialCaseClosingTagsSet;
12
12
  private static SpecialCaseOpeningTagRegex;
13
13
  private static FormattingTags;
14
- /**
15
- * Hard cap on nested `HtmlDiff.execute` calls (table preprocessing
16
- * recurses through `diffCell` for cell content). Each level allocates
17
- * fresh DP matrices and word arrays; without a guard a maliciously
18
- * nested table-in-cell-in-table-in-cell input could blow stack and
19
- * memory. Set high enough to comfortably handle real legal documents
20
- * (tables nested 2-3 deep at most), low enough to short-circuit
21
- * pathological input.
22
- */
23
- private static MaxTablePreprocessDepth;
24
14
  private content;
25
15
  private newText;
26
16
  private oldText;
27
- private readonly tablePreprocessDepth;
28
17
  private specialTagDiffStack;
29
18
  private newWords;
30
19
  private oldWords;
@@ -87,12 +76,9 @@ declare class HtmlDiff {
87
76
  * Initializes a new instance of the class.
88
77
  * @param oldText The old text.
89
78
  * @param newText The new text.
90
- * @param tablePreprocessDepth Internal: nested-call depth for table
91
- * preprocessing. Callers should leave at default (0); the recursive
92
- * `diffCell` callback in TableDiff bumps it.
93
79
  */
94
- constructor(oldText: string, newText: string, tablePreprocessDepth?: number);
95
- static execute(oldText: string, newText: string, tablePreprocessDepth?: number): string;
80
+ constructor(oldText: string, newText: string);
81
+ static execute(oldText: string, newText: string): string;
96
82
  /**
97
83
  * Builds the HTML diff output
98
84
  * @return HTML diff markup