@createiq/htmldiff 1.0.4-beta.1 → 1.0.4-beta.3
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.
- package/dist/HtmlDiff.cjs +11 -6
- package/dist/HtmlDiff.cjs.map +1 -1
- package/dist/HtmlDiff.mjs +11 -6
- package/dist/HtmlDiff.mjs.map +1 -1
- package/package.json +1 -1
- package/src/HtmlDiff.ts +35 -10
- package/test/HtmlDiff.spec.ts +1 -1
- package/test/structural1.html +0 -366
- package/test/structural2.html +0 -366
package/dist/HtmlDiff.cjs
CHANGED
|
@@ -545,9 +545,9 @@ var HtmlDiff = class HtmlDiff {
|
|
|
545
545
|
* strip structural noise so the diff algorithm only sees meaningful content and formatting changes.
|
|
546
546
|
*/
|
|
547
547
|
buildContentProjections() {
|
|
548
|
+
if (!HtmlDiff.hasStructuralDifferences(this.oldWords, this.newWords)) return;
|
|
548
549
|
const oldProjection = HtmlDiff.createContentProjection(this.oldWords);
|
|
549
550
|
const newProjection = HtmlDiff.createContentProjection(this.newWords);
|
|
550
|
-
if (!HtmlDiff.hasStructuralDifferences(this.oldWords, this.newWords)) return;
|
|
551
551
|
if (oldProjection.contentWords.length === 0 || newProjection.contentWords.length === 0) return;
|
|
552
552
|
this.oldContentWords = oldProjection.contentWords;
|
|
553
553
|
this.oldContentToOriginal = oldProjection.contentToOriginal;
|
|
@@ -601,8 +601,8 @@ var HtmlDiff = class HtmlDiff {
|
|
|
601
601
|
static hasStructuralDifferences(oldWords, newWords) {
|
|
602
602
|
const oldStructural = [];
|
|
603
603
|
const newStructural = [];
|
|
604
|
-
for (const w of oldWords) if (HtmlDiff.isStructuralTag(w)) oldStructural.push(
|
|
605
|
-
for (const w of newWords) if (HtmlDiff.isStructuralTag(w)) newStructural.push(
|
|
604
|
+
for (const w of oldWords) if (HtmlDiff.isStructuralTag(w)) oldStructural.push(w);
|
|
605
|
+
for (const w of newWords) if (HtmlDiff.isStructuralTag(w)) newStructural.push(w);
|
|
606
606
|
if (oldStructural.length !== newStructural.length) return true;
|
|
607
607
|
for (let i = 0; i < oldStructural.length; i++) if (oldStructural[i] !== newStructural[i]) return true;
|
|
608
608
|
return false;
|
|
@@ -728,7 +728,11 @@ var HtmlDiff = class HtmlDiff {
|
|
|
728
728
|
}
|
|
729
729
|
} else if (HtmlDiff.SpecialCaseClosingTagsSet.has(words[0].toLowerCase())) {
|
|
730
730
|
const openingTag = this.specialTagDiffStack.length === 0 ? null : this.specialTagDiffStack.pop();
|
|
731
|
-
|
|
731
|
+
let tagIndexToCompare = indexLastTagInFirstTagBlock;
|
|
732
|
+
if (tag === HtmlDiff.DelTag && indexOfFirstNonTag === -1) {
|
|
733
|
+
if (words.slice(0, indexLastTagInFirstTagBlock + 1).some((w) => !HtmlDiff.SpecialCaseClosingTagsSet.has(w.toLowerCase()))) tagIndexToCompare = 0;
|
|
734
|
+
}
|
|
735
|
+
const openingAndClosingTagsMatch = !!openingTag && Utils_default.getTagName(openingTag) === Utils_default.getTagName(words[tagIndexToCompare]);
|
|
732
736
|
if (!!openingTag && openingAndClosingTagsMatch) {
|
|
733
737
|
specialCaseTagInjection = "</ins>";
|
|
734
738
|
specialCaseTagInjectionIsBefore = true;
|
|
@@ -739,8 +743,9 @@ var HtmlDiff = class HtmlDiff {
|
|
|
739
743
|
}
|
|
740
744
|
}
|
|
741
745
|
if (words.length === 0 && specialCaseTagInjection.length === 0) break;
|
|
742
|
-
|
|
743
|
-
|
|
746
|
+
const isTagForExtraction = tag === HtmlDiff.DelTag ? (x) => Utils_default.isTag(x) && !HtmlDiff.SpecialCaseOpeningTagRegex.test(x) && !HtmlDiff.SpecialCaseClosingTagsSet.has(x.toLowerCase()) : Utils_default.isTag;
|
|
747
|
+
if (specialCaseTagInjectionIsBefore) this.content.push(specialCaseTagInjection + this.extractConsecutiveWords(words, isTagForExtraction).join(""));
|
|
748
|
+
else this.content.push(this.extractConsecutiveWords(words, isTagForExtraction).join("") + specialCaseTagInjection);
|
|
744
749
|
if (words.length === 0) continue;
|
|
745
750
|
this.insertTag(tag, cssClass, words);
|
|
746
751
|
break;
|
package/dist/HtmlDiff.cjs.map
CHANGED
|
@@ -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/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| )+$/\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 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 /** Tracks the last original old word index output, so equal operations can include leading structural tags */\n private lastOriginalOldOutputIndex = 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 * <del>aaaaa bb ccccccccc</del><ins>11111 bb 222222222</ins> 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 * Checks whether the two word arrays have structural HTML differences (different non-formatting tags\n * or different whitespace between structural tags). When they do, builds \"content projections\" that\n * strip structural noise so the diff algorithm only sees meaningful content and formatting changes.\n */\n private buildContentProjections() {\n const oldProjection = HtmlDiff.createContentProjection(this.oldWords)\n const newProjection = HtmlDiff.createContentProjection(this.newWords)\n\n // Only use projections if the structural tags actually differ.\n // If structural tags are the same, the normal diff works fine and is simpler.\n const structurallyDifferent = HtmlDiff.hasStructuralDifferences(this.oldWords, this.newWords)\n if (!structurallyDifferent) {\n return\n }\n\n // Don't activate structural normalization when one side has no content —\n // that's a genuine addition/deletion, not a re-wrapping scenario.\n if (oldProjection.contentWords.length === 0 || newProjection.contentWords.length === 0) {\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 * 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 /**\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 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.oldContentWords\n ? this.getOriginalNewWords(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.oldContentWords\n ? this.getOriginalOldWords(operation.startInOld, operation.endInOld)\n : this.oldWords.slice(operation.startInOld, operation.endInOld)\n this.insertTag(HtmlDiff.DelTag, cssClass, words)\n\n // Advance the tracking index past the deleted range so subsequent equal operations\n // don't re-include structural tags from the deleted section.\n if (this.oldContentToOriginal && operation.endInOld > 0) {\n const lastDeletedOrigIdx = this.oldContentToOriginal[operation.endInOld - 1]\n this.lastOriginalOldOutputIndex = Math.max(this.lastOriginalOldOutputIndex, lastDeletedOrigIdx + 1)\n }\n }\n\n private processEqualOperation(operation: Operation) {\n if (this.oldContentWords) {\n // When using content projections, output from old original words to preserve old structure\n const result = this.getOriginalOldWordsWithStructure(operation.startInOld, operation.endInOld)\n this.content.push(result.join(''))\n } else {\n const result = this.newWords.slice(operation.startInNew, operation.endInNew)\n this.content.push(result.join(''))\n }\n }\n\n /**\n * Gets original old words for a content-index range, including only content and formatting tags\n * (used for delete/replace operations where we don't want structural tags).\n */\n private getOriginalOldWords(contentStart: number, contentEnd: number): string[] {\n if (!this.oldContentToOriginal) return this.oldWords.slice(contentStart, contentEnd)\n const result: string[] = []\n for (let i = contentStart; i < contentEnd; i++) {\n result.push(this.oldWords[this.oldContentToOriginal[i]])\n }\n return result\n }\n\n /**\n * Gets original new words for a content-index range, including only content and formatting tags\n * (used for insert/replace operations where we don't want structural tags).\n */\n private getOriginalNewWords(contentStart: number, contentEnd: number): string[] {\n if (!this.newContentToOriginal) return this.newWords.slice(contentStart, contentEnd)\n const result: string[] = []\n for (let i = contentStart; i < contentEnd; i++) {\n result.push(this.newWords[this.newContentToOriginal[i]])\n }\n return result\n }\n\n /**\n * Gets original old words for a content-index range, INCLUDING structural tags and whitespace\n * between the content words (used for equal operations to preserve old HTML structure).\n */\n private getOriginalOldWordsWithStructure(contentStart: number, contentEnd: number): string[] {\n if (!this.oldContentToOriginal) return this.oldWords.slice(contentStart, contentEnd)\n if (contentStart >= contentEnd) return []\n\n // Start from where we last left off in the original array (or the first content word's\n // original index, whichever is smaller) to include any structural tags that precede\n // the content words in this range.\n const firstContentOrigIdx = this.oldContentToOriginal[contentStart]\n const origStart = Math.min(this.lastOriginalOldOutputIndex, firstContentOrigIdx)\n\n // Include up to (but not including) the next content word's original index,\n // or to the end of oldWords if this is the last content range\n const origEnd =\n contentEnd < this.oldContentToOriginal.length ? this.oldContentToOriginal[contentEnd] : this.oldWords.length\n\n this.lastOriginalOldOutputIndex = origEnd\n return this.oldWords.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 const openingAndClosingTagsMatch =\n !!openingTag && Utils.getTagName(openingTag) === Utils.getTagName(words[indexLastTagInFirstTagBlock])\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 if (specialCaseTagInjectionIsBefore) {\n this.content.push(specialCaseTagInjection + this.extractConsecutiveWords(words, Utils.isTag).join(''))\n } else {\n this.content.push(this.extractConsecutiveWords(words, Utils.isTag).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] = ' '\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;AAChE,OAAK,cAAc;AACnB,OAAK,cAAc;AACnB,OAAK,QAAQ;;CAGf,IAAI,aAAa;AACf,SAAO,KAAK;;CAGd,IAAI,aAAa;AACf,SAAO,KAAK;;CAGd,IAAI,OAAO;AACT,SAAO,KAAK;;CAGd,IAAI,WAAW;AACb,SAAO,KAAK,cAAc,KAAK;;CAGjC,IAAI,WAAW;AACb,SAAO,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;AAC3C,KAAI,oBAAoB,MAAK,OAAM,MAAM,WAAW,GAAG,CAAC,CACtD,QAAO;AAGT,QAAO,aAAa,KA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AmB,YAAY,MAAM,YAAY,YAAY,MAAM,YAAY,eAAe;AAGrG,kBAAe,KAAK,MAAM;AAE1B,OAAI,MAAM,WAAW,YAAY,MAAM,WAAW,SAChD,MAAK,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;AAIrD,OAAK,IAAI,IAAI,KAAK,kBAAkB,IAAI,GAAG,KAAK;GAe9C,MAAM,QATS,IAAI,YACjB,iBACA,iBACA,YACA,UACA,YACA,UAXc;IACd,WAAW;IACX,wBAAwB,KAAK;IAC7B,6BAA6B,KAAK;IACnC,CASA,CACoB,WAAW;AAChC,OAAI,UAAU,KAAM,QAAO;;AAE7B,SAAO"}
|
|
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| )+$/\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 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 /** Tracks the last original old word index output, so equal operations can include leading structural tags */\n private lastOriginalOldOutputIndex = 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 * <del>aaaaa bb ccccccccc</del><ins>11111 bb 222222222</ins> 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 * Checks whether the two word arrays have structural HTML differences (different non-formatting tags\n * or different whitespace between structural tags). When they do, builds \"content projections\" that\n * strip structural noise so the diff algorithm only sees meaningful content and formatting changes.\n */\n private buildContentProjections() {\n // Only use projections if the structural tags actually differ.\n // If structural tags are the same, the normal diff works fine and is simpler.\n if (!HtmlDiff.hasStructuralDifferences(this.oldWords, this.newWords)) {\n return\n }\n\n const oldProjection = HtmlDiff.createContentProjection(this.oldWords)\n const newProjection = HtmlDiff.createContentProjection(this.newWords)\n\n // Don't activate structural normalization when one side has no content —\n // that's a genuine addition/deletion, not a re-wrapping scenario.\n if (oldProjection.contentWords.length === 0 || newProjection.contentWords.length === 0) {\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 * 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 /**\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 for (const w of oldWords) {\n if (HtmlDiff.isStructuralTag(w)) {\n oldStructural.push(w)\n }\n }\n for (const w of newWords) {\n if (HtmlDiff.isStructuralTag(w)) {\n newStructural.push(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.oldContentWords\n ? this.getOriginalNewWords(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.oldContentWords\n ? this.getOriginalOldWords(operation.startInOld, operation.endInOld)\n : this.oldWords.slice(operation.startInOld, operation.endInOld)\n this.insertTag(HtmlDiff.DelTag, cssClass, words)\n\n // Advance the tracking index past the deleted range so subsequent equal operations\n // don't re-include structural tags from the deleted section.\n if (this.oldContentToOriginal && operation.endInOld > 0) {\n const lastDeletedOrigIdx = this.oldContentToOriginal[operation.endInOld - 1]\n this.lastOriginalOldOutputIndex = Math.max(this.lastOriginalOldOutputIndex, lastDeletedOrigIdx + 1)\n }\n }\n\n private processEqualOperation(operation: Operation) {\n if (this.oldContentWords) {\n // When using content projections, output from old original words to preserve old structure\n const result = this.getOriginalOldWordsWithStructure(operation.startInOld, operation.endInOld)\n this.content.push(result.join(''))\n } else {\n const result = this.newWords.slice(operation.startInNew, operation.endInNew)\n this.content.push(result.join(''))\n }\n }\n\n /**\n * Gets original old words for a content-index range, including only content and formatting tags\n * (used for delete/replace operations where we don't want structural tags).\n */\n private getOriginalOldWords(contentStart: number, contentEnd: number): string[] {\n if (!this.oldContentToOriginal) return this.oldWords.slice(contentStart, contentEnd)\n const result: string[] = []\n for (let i = contentStart; i < contentEnd; i++) {\n result.push(this.oldWords[this.oldContentToOriginal[i]])\n }\n return result\n }\n\n /**\n * Gets original new words for a content-index range, including only content and formatting tags\n * (used for insert/replace operations where we don't want structural tags).\n */\n private getOriginalNewWords(contentStart: number, contentEnd: number): string[] {\n if (!this.newContentToOriginal) return this.newWords.slice(contentStart, contentEnd)\n const result: string[] = []\n for (let i = contentStart; i < contentEnd; i++) {\n result.push(this.newWords[this.newContentToOriginal[i]])\n }\n return result\n }\n\n /**\n * Gets original old words for a content-index range, INCLUDING structural tags and whitespace\n * between the content words (used for equal operations to preserve old HTML structure).\n */\n private getOriginalOldWordsWithStructure(contentStart: number, contentEnd: number): string[] {\n if (!this.oldContentToOriginal) return this.oldWords.slice(contentStart, contentEnd)\n if (contentStart >= contentEnd) return []\n\n // Start from where we last left off in the original array (or the first content word's\n // original index, whichever is smaller) to include any structural tags that precede\n // the content words in this range.\n const firstContentOrigIdx = this.oldContentToOriginal[contentStart]\n const origStart = Math.min(this.lastOriginalOldOutputIndex, firstContentOrigIdx)\n\n // Include up to (but not including) the next content word's original index,\n // or to the end of oldWords if this is the last content range\n const origEnd =\n contentEnd < this.oldContentToOriginal.length ? this.oldContentToOriginal[contentEnd] : this.oldWords.length\n\n this.lastOriginalOldOutputIndex = origEnd\n return this.oldWords.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] = ' '\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;AAChE,OAAK,cAAc;AACnB,OAAK,cAAc;AACnB,OAAK,QAAQ;;CAGf,IAAI,aAAa;AACf,SAAO,KAAK;;CAGd,IAAI,aAAa;AACf,SAAO,KAAK;;CAGd,IAAI,OAAO;AACT,SAAO,KAAK;;CAGd,IAAI,WAAW;AACb,SAAO,KAAK,cAAc,KAAK;;CAGjC,IAAI,WAAW;AACb,SAAO,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;AAC3C,KAAI,oBAAoB,MAAK,OAAM,MAAM,WAAW,GAAG,CAAC,CACtD,QAAO;AAGT,QAAO,aAAa,KAAK,IAAI,aAAa,KAAK;;AAGjD,SAAS,aAAa,MAAuB;AAC3C,QAAO,gBAAgB,KAAK,KAAK;;AAGnC,SAAS,aAAa,MAAuB;AAC3C,QAAO,mBAAmB,KAAK,KAAK;;AAGtC,SAAgB,mBAAm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ACA,MAAM,QAAQ,KAAK,UAAU,YAAY,UAAU,YAAY,SAAS;AAExE,MAAI,UAAU,MAAM;AAClB,OAAI,aAAa,MAAM,cAAc,aAAa,MAAM,WACtD,MAAK,mBAAmB,YAAY,MAAM,YAAY,YAAY,MAAM,YAAY,eAAe;AAGrG,kBAAe,KAAK,MAAM;AAE1B,OAAI,MAAM,WAAW,YAAY,MAAM,WAAW,SAChD,MAAK,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;AAIrD,OAAK,IAAI,IAAI,KAAK,kBAAkB,IAAI,GAAG,KAAK;GAe9C,MAAM,QATS,IAAI,YACjB,iBACA,iBACA,YACA,UACA,YACA,UAXc;IACd,WAAW;IACX,wBAAwB,KAAK;IAC7B,6BAA6B,KAAK;IACnC,CASA,CACoB,WAAW;AAChC,OAAI,UAAU,KAAM,QAAO;;AAE7B,SAAO"}
|
package/dist/HtmlDiff.mjs
CHANGED
|
@@ -545,9 +545,9 @@ var HtmlDiff = class HtmlDiff {
|
|
|
545
545
|
* strip structural noise so the diff algorithm only sees meaningful content and formatting changes.
|
|
546
546
|
*/
|
|
547
547
|
buildContentProjections() {
|
|
548
|
+
if (!HtmlDiff.hasStructuralDifferences(this.oldWords, this.newWords)) return;
|
|
548
549
|
const oldProjection = HtmlDiff.createContentProjection(this.oldWords);
|
|
549
550
|
const newProjection = HtmlDiff.createContentProjection(this.newWords);
|
|
550
|
-
if (!HtmlDiff.hasStructuralDifferences(this.oldWords, this.newWords)) return;
|
|
551
551
|
if (oldProjection.contentWords.length === 0 || newProjection.contentWords.length === 0) return;
|
|
552
552
|
this.oldContentWords = oldProjection.contentWords;
|
|
553
553
|
this.oldContentToOriginal = oldProjection.contentToOriginal;
|
|
@@ -601,8 +601,8 @@ var HtmlDiff = class HtmlDiff {
|
|
|
601
601
|
static hasStructuralDifferences(oldWords, newWords) {
|
|
602
602
|
const oldStructural = [];
|
|
603
603
|
const newStructural = [];
|
|
604
|
-
for (const w of oldWords) if (HtmlDiff.isStructuralTag(w)) oldStructural.push(
|
|
605
|
-
for (const w of newWords) if (HtmlDiff.isStructuralTag(w)) newStructural.push(
|
|
604
|
+
for (const w of oldWords) if (HtmlDiff.isStructuralTag(w)) oldStructural.push(w);
|
|
605
|
+
for (const w of newWords) if (HtmlDiff.isStructuralTag(w)) newStructural.push(w);
|
|
606
606
|
if (oldStructural.length !== newStructural.length) return true;
|
|
607
607
|
for (let i = 0; i < oldStructural.length; i++) if (oldStructural[i] !== newStructural[i]) return true;
|
|
608
608
|
return false;
|
|
@@ -728,7 +728,11 @@ var HtmlDiff = class HtmlDiff {
|
|
|
728
728
|
}
|
|
729
729
|
} else if (HtmlDiff.SpecialCaseClosingTagsSet.has(words[0].toLowerCase())) {
|
|
730
730
|
const openingTag = this.specialTagDiffStack.length === 0 ? null : this.specialTagDiffStack.pop();
|
|
731
|
-
|
|
731
|
+
let tagIndexToCompare = indexLastTagInFirstTagBlock;
|
|
732
|
+
if (tag === HtmlDiff.DelTag && indexOfFirstNonTag === -1) {
|
|
733
|
+
if (words.slice(0, indexLastTagInFirstTagBlock + 1).some((w) => !HtmlDiff.SpecialCaseClosingTagsSet.has(w.toLowerCase()))) tagIndexToCompare = 0;
|
|
734
|
+
}
|
|
735
|
+
const openingAndClosingTagsMatch = !!openingTag && Utils_default.getTagName(openingTag) === Utils_default.getTagName(words[tagIndexToCompare]);
|
|
732
736
|
if (!!openingTag && openingAndClosingTagsMatch) {
|
|
733
737
|
specialCaseTagInjection = "</ins>";
|
|
734
738
|
specialCaseTagInjectionIsBefore = true;
|
|
@@ -739,8 +743,9 @@ var HtmlDiff = class HtmlDiff {
|
|
|
739
743
|
}
|
|
740
744
|
}
|
|
741
745
|
if (words.length === 0 && specialCaseTagInjection.length === 0) break;
|
|
742
|
-
|
|
743
|
-
|
|
746
|
+
const isTagForExtraction = tag === HtmlDiff.DelTag ? (x) => Utils_default.isTag(x) && !HtmlDiff.SpecialCaseOpeningTagRegex.test(x) && !HtmlDiff.SpecialCaseClosingTagsSet.has(x.toLowerCase()) : Utils_default.isTag;
|
|
747
|
+
if (specialCaseTagInjectionIsBefore) this.content.push(specialCaseTagInjection + this.extractConsecutiveWords(words, isTagForExtraction).join(""));
|
|
748
|
+
else this.content.push(this.extractConsecutiveWords(words, isTagForExtraction).join("") + specialCaseTagInjection);
|
|
744
749
|
if (words.length === 0) continue;
|
|
745
750
|
this.insertTag(tag, cssClass, words);
|
|
746
751
|
break;
|