Teamwork / visual-dom-diff

Highlight differences between two DOM trees.
https://teamwork.github.io/visual-dom-diff/
MIT License
47 stars 11 forks source link
diffing dom-tree

visual-dom-diff

Highlight differences between two DOM trees.

Installation

npm i visual-dom-diff

Usage

import { visualDomDiff } from 'visual-dom-diff'

const diffNode = visualDomDiff(originalNode, changedNode, options)

API

visualDomDiff(originalNode: Node, changedNode: Node, options?: Options): DocumentFragment

Returns a new document fragment with the content from the two input nodes and annotations indicating if the given fragment was removed, modified or added in the changedNode, ralative to the originalNode.

Changes to text content are represented as deletions (<del class="vdd-removed">) followed by insertions (<ins class="vdd-added">).

Changes to the document structure are indicated by adding the vdd-removed and vdd-added classes to the removed and inserted elements respectively.

Changes to formatting are treated as content modifications (<ins class="vdd-modified"> wraps the modified text) and only the new formatting is carried over to the returned document fragment.

Changes to attributes of structural elements are treated as modifications (vdd-modified class is added to the element) and only the new attributes are carried over to the returned document fragment.

Options