Comparing version 0.1.7 to 2.0.0-alpha.5
@@ -11,4 +11,7 @@ import { Mirror as NodeMirror } from 'rrweb-snapshot'; | ||
applyStyleSheetMutation: (data: styleDeclarationData | styleSheetRuleData, styleSheet: CSSStyleSheet) => void; | ||
afterAppend?(node: Node, id: number): void; | ||
}; | ||
export declare function diff(oldTree: Node, newTree: IRRNode, replayer: ReplayerHandler, rrnodeMirror?: Mirror): void; | ||
export declare function createOrGetNode(rrNode: IRRNode, domMirror: NodeMirror, rrnodeMirror: Mirror): Node; | ||
export declare function sameNodeType(node1: Node, node2: IRRNode): boolean; | ||
export declare function nodeMatching(node1: Node, node2: IRRNode, domMirror: NodeMirror, rrdomMirror: Mirror): boolean; |
@@ -5,4 +5,4 @@ import { NodeType as RRNodeType } from 'rrweb-snapshot'; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -15,2 +15,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -79,7 +80,10 @@ textContent: string | null; | ||
export declare class BaseRRNode implements IRRNode { | ||
childNodes: IRRNode[]; | ||
parentElement: IRRNode | null; | ||
parentNode: IRRNode | null; | ||
ownerDocument: IRRDocument; | ||
firstChild: IRRNode | null; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
ownerDocument: IRRDocument; | ||
readonly ELEMENT_NODE: number; | ||
@@ -91,5 +95,3 @@ readonly TEXT_NODE: number; | ||
constructor(..._args: any[]); | ||
get firstChild(): IRRNode | null; | ||
get lastChild(): IRRNode | null; | ||
get nextSibling(): IRRNode | null; | ||
get childNodes(): IRRNode[]; | ||
contains(node: IRRNode): boolean; | ||
@@ -107,3 +109,2 @@ appendChild(_newChild: IRRNode): IRRNode; | ||
readonly RRNodeType: RRNodeType.Document; | ||
textContent: string | null; | ||
readonly documentElement: IRRElement | null; | ||
@@ -114,3 +115,3 @@ readonly body: IRRElement | null; | ||
readonly firstElementChild: IRRElement | null; | ||
appendChild(childNode: IRRNode): IRRNode; | ||
appendChild(newChild: IRRNode): IRRNode; | ||
insertBefore(newChild: IRRNode, refChild: IRRNode | null): IRRNode; | ||
@@ -131,4 +132,4 @@ removeChild(node: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -138,3 +139,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -151,8 +154,7 @@ }; | ||
readonly systemId: string; | ||
textContent: string | null; | ||
toString(): string; | ||
parentElement: IRRNode | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -162,3 +164,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -197,4 +201,4 @@ appendChild(newChild: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -204,2 +208,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -235,4 +240,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -245,2 +250,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -265,4 +271,4 @@ textContent: string | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -272,2 +278,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -290,4 +297,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -297,2 +304,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -315,4 +323,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -322,2 +330,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -324,0 +333,0 @@ contains(node: IRRNode): boolean; |
@@ -11,3 +11,2 @@ import { NodeType as RRNodeType } from 'rrweb-snapshot'; | ||
readonly RRNodeType: RRNodeType.Document; | ||
textContent: string | null; | ||
readonly documentElement: IRRElement | null; | ||
@@ -18,3 +17,3 @@ readonly body: IRRElement | null; | ||
readonly firstElementChild: IRRElement | null; | ||
appendChild(childNode: IRRNode): IRRNode; | ||
appendChild(newChild: IRRNode): IRRNode; | ||
insertBefore(newChild: IRRNode, refChild: IRRNode | null): IRRNode; | ||
@@ -35,4 +34,4 @@ removeChild(node: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -42,3 +41,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -62,8 +63,7 @@ }; | ||
readonly systemId: string; | ||
textContent: string | null; | ||
toString(): string; | ||
parentElement: IRRNode | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -73,3 +73,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -91,4 +93,4 @@ appendChild(newChild: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -98,2 +100,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -114,4 +117,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -121,2 +124,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -137,4 +141,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -144,2 +148,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -162,8 +167,7 @@ contains(node: IRRNode): boolean; | ||
readonly systemId: string; | ||
textContent: string | null; | ||
toString(): string; | ||
parentElement: IRRNode | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -173,3 +177,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -208,4 +214,4 @@ appendChild(newChild: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -215,2 +221,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -250,4 +257,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -260,2 +267,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -297,4 +305,4 @@ textContent: string | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -304,2 +312,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -323,4 +332,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -330,2 +339,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -349,4 +359,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -356,2 +366,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -358,0 +369,0 @@ contains(node: IRRNode): boolean; |
@@ -115,28 +115,31 @@ var rrdom = (function (exports) { | ||
constructor(..._args) { | ||
this.childNodes = []; | ||
this.parentElement = null; | ||
this.parentNode = null; | ||
this.firstChild = null; | ||
this.lastChild = null; | ||
this.previousSibling = null; | ||
this.nextSibling = null; | ||
this.ELEMENT_NODE = exports.NodeType.ELEMENT_NODE; | ||
this.TEXT_NODE = exports.NodeType.TEXT_NODE; | ||
} | ||
get firstChild() { | ||
return this.childNodes[0] || null; | ||
get childNodes() { | ||
const childNodes = []; | ||
let childIterator = this.firstChild; | ||
while (childIterator) { | ||
childNodes.push(childIterator); | ||
childIterator = childIterator.nextSibling; | ||
} | ||
return childNodes; | ||
} | ||
get lastChild() { | ||
return this.childNodes[this.childNodes.length - 1] || null; | ||
} | ||
get nextSibling() { | ||
const parentNode = this.parentNode; | ||
if (!parentNode) | ||
return null; | ||
const siblings = parentNode.childNodes; | ||
const index = siblings.indexOf(this); | ||
return siblings[index + 1] || null; | ||
} | ||
contains(node) { | ||
if (node === this) | ||
if (!(node instanceof BaseRRNode)) | ||
return false; | ||
else if (node.ownerDocument !== this.ownerDocument) | ||
return false; | ||
else if (node === this) | ||
return true; | ||
for (const child of this.childNodes) { | ||
if (child.contains(node)) | ||
while (node.parentNode) { | ||
if (node.parentNode === this) | ||
return true; | ||
node = node.parentNode; | ||
} | ||
@@ -160,4 +163,4 @@ return false; | ||
return class BaseRRDocument extends RRNodeClass { | ||
constructor() { | ||
super(...arguments); | ||
constructor(...args) { | ||
super(args); | ||
this.nodeType = exports.NodeType.DOCUMENT_NODE; | ||
@@ -168,2 +171,3 @@ this.nodeName = '#document'; | ||
this.textContent = null; | ||
this.ownerDocument = this; | ||
} | ||
@@ -190,4 +194,4 @@ get documentElement() { | ||
} | ||
appendChild(childNode) { | ||
const nodeType = childNode.RRNodeType; | ||
appendChild(newChild) { | ||
const nodeType = newChild.RRNodeType; | ||
if (nodeType === NodeType.Element || | ||
@@ -199,6 +203,5 @@ nodeType === NodeType.DocumentType) { | ||
} | ||
childNode.parentElement = null; | ||
childNode.parentNode = this; | ||
this.childNodes.push(childNode); | ||
return childNode; | ||
const child = appendChild(this, newChild); | ||
child.parentElement = null; | ||
return child; | ||
} | ||
@@ -213,23 +216,12 @@ insertBefore(newChild, refChild) { | ||
} | ||
if (refChild === null) | ||
return this.appendChild(newChild); | ||
const childIndex = this.childNodes.indexOf(refChild); | ||
if (childIndex == -1) | ||
throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode."); | ||
this.childNodes.splice(childIndex, 0, newChild); | ||
newChild.parentElement = null; | ||
newChild.parentNode = this; | ||
return newChild; | ||
const child = insertBefore(this, newChild, refChild); | ||
child.parentElement = null; | ||
return child; | ||
} | ||
removeChild(node) { | ||
const indexOfChild = this.childNodes.indexOf(node); | ||
if (indexOfChild === -1) | ||
throw new Error("Failed to execute 'removeChild' on 'RRDocument': The RRNode to be removed is not a child of this RRNode."); | ||
this.childNodes.splice(indexOfChild, 1); | ||
node.parentElement = null; | ||
node.parentNode = null; | ||
return node; | ||
return removeChild(this, node); | ||
} | ||
open() { | ||
this.childNodes = []; | ||
this.firstChild = null; | ||
this.lastChild = null; | ||
} | ||
@@ -294,3 +286,2 @@ close() { | ||
this.RRNodeType = NodeType.DocumentType; | ||
this.textContent = null; | ||
this.name = qualifiedName; | ||
@@ -300,2 +291,3 @@ this.publicId = publicId; | ||
this.nodeName = qualifiedName; | ||
this.textContent = null; | ||
} | ||
@@ -324,3 +316,5 @@ toString() { | ||
set textContent(textContent) { | ||
this.childNodes = [this.ownerDocument.createTextNode(textContent)]; | ||
this.firstChild = null; | ||
this.lastChild = null; | ||
this.appendChild(this.ownerDocument.createTextNode(textContent)); | ||
} | ||
@@ -339,5 +333,3 @@ get classList() { | ||
get style() { | ||
const style = (this.attributes.style | ||
? parseCSSText(this.attributes.style) | ||
: {}); | ||
const style = (this.attributes.style ? parseCSSText(this.attributes.style) : {}); | ||
const hyphenateRE = /\B([A-Z])/g; | ||
@@ -380,26 +372,9 @@ style.setProperty = (name, value, priority) => { | ||
appendChild(newChild) { | ||
this.childNodes.push(newChild); | ||
newChild.parentNode = this; | ||
newChild.parentElement = this; | ||
return newChild; | ||
return appendChild(this, newChild); | ||
} | ||
insertBefore(newChild, refChild) { | ||
if (refChild === null) | ||
return this.appendChild(newChild); | ||
const childIndex = this.childNodes.indexOf(refChild); | ||
if (childIndex == -1) | ||
throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode."); | ||
this.childNodes.splice(childIndex, 0, newChild); | ||
newChild.parentElement = this; | ||
newChild.parentNode = this; | ||
return newChild; | ||
return insertBefore(this, newChild, refChild); | ||
} | ||
removeChild(node) { | ||
const indexOfChild = this.childNodes.indexOf(node); | ||
if (indexOfChild === -1) | ||
throw new Error("Failed to execute 'removeChild' on 'RRElement': The RRNode to be removed is not a child of this RRNode."); | ||
this.childNodes.splice(indexOfChild, 1); | ||
node.parentElement = null; | ||
node.parentNode = null; | ||
return node; | ||
return removeChild(this, node); | ||
} | ||
@@ -519,2 +494,52 @@ attachShadow(_init) { | ||
} | ||
function appendChild(parent, newChild) { | ||
if (parent.lastChild) { | ||
parent.lastChild.nextSibling = newChild; | ||
newChild.previousSibling = parent.lastChild; | ||
} | ||
else { | ||
parent.firstChild = newChild; | ||
newChild.previousSibling = null; | ||
} | ||
parent.lastChild = newChild; | ||
newChild.nextSibling = null; | ||
newChild.parentNode = parent; | ||
newChild.parentElement = parent; | ||
newChild.ownerDocument = parent.ownerDocument; | ||
return newChild; | ||
} | ||
function insertBefore(parent, newChild, refChild) { | ||
if (!refChild) | ||
return appendChild(parent, newChild); | ||
if (refChild.parentNode !== parent) | ||
throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode."); | ||
newChild.previousSibling = refChild.previousSibling; | ||
refChild.previousSibling = newChild; | ||
newChild.nextSibling = refChild; | ||
if (newChild.previousSibling) | ||
newChild.previousSibling.nextSibling = newChild; | ||
else | ||
parent.firstChild = newChild; | ||
newChild.parentElement = parent; | ||
newChild.parentNode = parent; | ||
newChild.ownerDocument = parent.ownerDocument; | ||
return newChild; | ||
} | ||
function removeChild(parent, child) { | ||
if (child.parentNode !== parent) | ||
throw new Error("Failed to execute 'removeChild' on 'RRNode': The RRNode to be removed is not a child of this RRNode."); | ||
if (child.previousSibling) | ||
child.previousSibling.nextSibling = child.nextSibling; | ||
else | ||
parent.firstChild = child.nextSibling; | ||
if (child.nextSibling) | ||
child.nextSibling.previousSibling = child.previousSibling; | ||
else | ||
parent.lastChild = child.previousSibling; | ||
child.previousSibling = null; | ||
child.nextSibling = null; | ||
child.parentElement = null; | ||
child.parentNode = null; | ||
return child; | ||
} | ||
exports.NodeType = void 0; | ||
@@ -579,17 +604,38 @@ (function (NodeType) { | ||
}; | ||
function diff(oldTree, newTree, replayer, rrnodeMirror) { | ||
let createdNodeSet = null; | ||
function diff(oldTree, newTree, replayer, rrnodeMirror = newTree.mirror || | ||
newTree.ownerDocument.mirror) { | ||
oldTree = diffBeforeUpdatingChildren(oldTree, newTree, replayer, rrnodeMirror); | ||
const oldChildren = oldTree.childNodes; | ||
const newChildren = newTree.childNodes; | ||
rrnodeMirror = | ||
rrnodeMirror || | ||
newTree.mirror || | ||
newTree.ownerDocument.mirror; | ||
if (oldChildren.length > 0 || newChildren.length > 0) { | ||
diffChildren(Array.from(oldChildren), newChildren, oldTree, replayer, rrnodeMirror); | ||
} | ||
let inputDataToApply = null, scrollDataToApply = null; | ||
diffAfterUpdatingChildren(oldTree, newTree, replayer, rrnodeMirror); | ||
} | ||
function diffBeforeUpdatingChildren(oldTree, newTree, replayer, rrnodeMirror) { | ||
var _a; | ||
if (replayer.afterAppend && !createdNodeSet) { | ||
createdNodeSet = new WeakSet(); | ||
setTimeout(() => { | ||
createdNodeSet = null; | ||
}, 0); | ||
} | ||
if (!sameNodeType(oldTree, newTree)) { | ||
const calibratedOldTree = createOrGetNode(newTree, replayer.mirror, rrnodeMirror); | ||
(_a = oldTree.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(calibratedOldTree, oldTree); | ||
oldTree = calibratedOldTree; | ||
} | ||
switch (newTree.RRNodeType) { | ||
case NodeType.Document: { | ||
const newRRDocument = newTree; | ||
scrollDataToApply = newRRDocument.scrollData; | ||
if (!nodeMatching(oldTree, newTree, replayer.mirror, rrnodeMirror)) { | ||
const newMeta = rrnodeMirror.getMeta(newTree); | ||
if (newMeta) { | ||
replayer.mirror.removeNodeFromMap(oldTree); | ||
oldTree.close(); | ||
oldTree.open(); | ||
replayer.mirror.add(oldTree, newMeta); | ||
createdNodeSet === null || createdNodeSet === void 0 ? void 0 : createdNodeSet.add(oldTree); | ||
} | ||
} | ||
break; | ||
@@ -600,5 +646,40 @@ } | ||
const newRRElement = newTree; | ||
switch (newRRElement.tagName) { | ||
case 'IFRAME': { | ||
const oldContentDocument = oldTree | ||
.contentDocument; | ||
if (!oldContentDocument) | ||
break; | ||
diff(oldContentDocument, newTree.contentDocument, replayer, rrnodeMirror); | ||
break; | ||
} | ||
} | ||
if (newRRElement.shadowRoot) { | ||
if (!oldElement.shadowRoot) | ||
oldElement.attachShadow({ mode: 'open' }); | ||
const oldChildren = oldElement.shadowRoot.childNodes; | ||
const newChildren = newRRElement.shadowRoot.childNodes; | ||
if (oldChildren.length > 0 || newChildren.length > 0) | ||
diffChildren(Array.from(oldChildren), newChildren, oldElement.shadowRoot, replayer, rrnodeMirror); | ||
} | ||
break; | ||
} | ||
} | ||
return oldTree; | ||
} | ||
function diffAfterUpdatingChildren(oldTree, newTree, replayer, rrnodeMirror) { | ||
var _a; | ||
switch (newTree.RRNodeType) { | ||
case NodeType.Document: { | ||
const scrollData = newTree.scrollData; | ||
scrollData && replayer.applyScroll(scrollData, true); | ||
break; | ||
} | ||
case NodeType.Element: { | ||
const oldElement = oldTree; | ||
const newRRElement = newTree; | ||
diffProps(oldElement, newRRElement, rrnodeMirror); | ||
scrollDataToApply = newRRElement.scrollData; | ||
inputDataToApply = newRRElement.inputData; | ||
newRRElement.scrollData && | ||
replayer.applyScroll(newRRElement.scrollData, true); | ||
newRRElement.inputData && replayer.applyInput(newRRElement.inputData); | ||
switch (newRRElement.tagName) { | ||
@@ -623,34 +704,24 @@ case 'AUDIO': | ||
} | ||
case 'CANVAS': | ||
{ | ||
const rrCanvasElement = newTree; | ||
if (rrCanvasElement.rr_dataURL !== null) { | ||
const image = document.createElement('img'); | ||
image.onload = () => { | ||
const ctx = oldElement.getContext('2d'); | ||
if (ctx) { | ||
ctx.drawImage(image, 0, 0, image.width, image.height); | ||
} | ||
}; | ||
image.src = rrCanvasElement.rr_dataURL; | ||
} | ||
rrCanvasElement.canvasMutations.forEach((canvasMutation) => replayer.applyCanvas(canvasMutation.event, canvasMutation.mutation, oldTree)); | ||
case 'CANVAS': { | ||
const rrCanvasElement = newTree; | ||
if (rrCanvasElement.rr_dataURL !== null) { | ||
const image = document.createElement('img'); | ||
image.onload = () => { | ||
const ctx = oldElement.getContext('2d'); | ||
if (ctx) { | ||
ctx.drawImage(image, 0, 0, image.width, image.height); | ||
} | ||
}; | ||
image.src = rrCanvasElement.rr_dataURL; | ||
} | ||
rrCanvasElement.canvasMutations.forEach((canvasMutation) => replayer.applyCanvas(canvasMutation.event, canvasMutation.mutation, oldTree)); | ||
break; | ||
case 'STYLE': | ||
{ | ||
const styleSheet = oldElement.sheet; | ||
styleSheet && | ||
newTree.rules.forEach((data) => replayer.applyStyleSheetMutation(data, styleSheet)); | ||
} | ||
} | ||
case 'STYLE': { | ||
const styleSheet = oldElement.sheet; | ||
styleSheet && | ||
newTree.rules.forEach((data) => replayer.applyStyleSheetMutation(data, styleSheet)); | ||
break; | ||
} | ||
} | ||
if (newRRElement.shadowRoot) { | ||
if (!oldElement.shadowRoot) | ||
oldElement.attachShadow({ mode: 'open' }); | ||
const oldChildren = oldElement.shadowRoot.childNodes; | ||
const newChildren = newRRElement.shadowRoot.childNodes; | ||
if (oldChildren.length > 0 || newChildren.length > 0) | ||
diffChildren(Array.from(oldChildren), newChildren, oldElement.shadowRoot, replayer, rrnodeMirror); | ||
} | ||
break; | ||
@@ -660,3 +731,3 @@ } | ||
case NodeType.Comment: | ||
case NodeType.CDATA: | ||
case NodeType.CDATA: { | ||
if (oldTree.textContent !== | ||
@@ -666,16 +737,8 @@ newTree.data) | ||
break; | ||
} | ||
scrollDataToApply && replayer.applyScroll(scrollDataToApply, true); | ||
inputDataToApply && replayer.applyInput(inputDataToApply); | ||
if (newTree.nodeName === 'IFRAME') { | ||
const oldContentDocument = oldTree.contentDocument; | ||
const newIFrameElement = newTree; | ||
if (oldContentDocument) { | ||
const sn = rrnodeMirror.getMeta(newIFrameElement.contentDocument); | ||
if (sn) { | ||
replayer.mirror.add(oldContentDocument, Object.assign({}, sn)); | ||
} | ||
diff(oldContentDocument, newIFrameElement.contentDocument, replayer, rrnodeMirror); | ||
} | ||
} | ||
if (createdNodeSet === null || createdNodeSet === void 0 ? void 0 : createdNodeSet.has(oldTree)) { | ||
createdNodeSet.delete(oldTree); | ||
(_a = replayer.afterAppend) === null || _a === void 0 ? void 0 : _a.call(replayer, oldTree, replayer.mirror.getId(oldTree)); | ||
} | ||
} | ||
@@ -688,3 +751,3 @@ function diffProps(oldTree, newTree, rrnodeMirror) { | ||
const sn = rrnodeMirror.getMeta(newTree); | ||
if (sn && 'isSVG' in sn && sn.isSVG && NAMESPACES[name]) | ||
if ((sn === null || sn === void 0 ? void 0 : sn.isSVG) && NAMESPACES[name]) | ||
oldTree.setAttributeNS(NAMESPACES[name], name, newValue); | ||
@@ -711,11 +774,6 @@ else if (newTree.tagName === 'CANVAS' && name === 'rr_dataURL') { | ||
function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirror) { | ||
var _a; | ||
let oldStartIndex = 0, oldEndIndex = oldChildren.length - 1, newStartIndex = 0, newEndIndex = newChildren.length - 1; | ||
let oldStartNode = oldChildren[oldStartIndex], oldEndNode = oldChildren[oldEndIndex], newStartNode = newChildren[newStartIndex], newEndNode = newChildren[newEndIndex]; | ||
let oldIdToIndex = undefined, indexInOld; | ||
let oldIdToIndex = undefined, indexInOld = undefined; | ||
while (oldStartIndex <= oldEndIndex && newStartIndex <= newEndIndex) { | ||
const oldStartId = replayer.mirror.getId(oldStartNode); | ||
const oldEndId = replayer.mirror.getId(oldEndNode); | ||
const newStartId = rrnodeMirror.getId(newStartNode); | ||
const newEndId = rrnodeMirror.getId(newEndNode); | ||
if (oldStartNode === undefined) { | ||
@@ -727,4 +785,3 @@ oldStartNode = oldChildren[++oldStartIndex]; | ||
} | ||
else if (oldStartId !== -1 && | ||
oldStartId === newStartId) { | ||
else if (nodeMatching(oldStartNode, newStartNode, replayer.mirror, rrnodeMirror)) { | ||
diff(oldStartNode, newStartNode, replayer, rrnodeMirror); | ||
@@ -734,4 +791,3 @@ oldStartNode = oldChildren[++oldStartIndex]; | ||
} | ||
else if (oldEndId !== -1 && | ||
oldEndId === newEndId) { | ||
else if (nodeMatching(oldEndNode, newEndNode, replayer.mirror, rrnodeMirror)) { | ||
diff(oldEndNode, newEndNode, replayer, rrnodeMirror); | ||
@@ -741,5 +797,9 @@ oldEndNode = oldChildren[--oldEndIndex]; | ||
} | ||
else if (oldStartId !== -1 && | ||
oldStartId === newEndId) { | ||
parentNode.insertBefore(oldStartNode, oldEndNode.nextSibling); | ||
else if (nodeMatching(oldStartNode, newEndNode, replayer.mirror, rrnodeMirror)) { | ||
try { | ||
parentNode.insertBefore(oldStartNode, oldEndNode.nextSibling); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
} | ||
diff(oldStartNode, newEndNode, replayer, rrnodeMirror); | ||
@@ -749,5 +809,9 @@ oldStartNode = oldChildren[++oldStartIndex]; | ||
} | ||
else if (oldEndId !== -1 && | ||
oldEndId === newStartId) { | ||
parentNode.insertBefore(oldEndNode, oldStartNode); | ||
else if (nodeMatching(oldEndNode, newStartNode, replayer.mirror, rrnodeMirror)) { | ||
try { | ||
parentNode.insertBefore(oldEndNode, oldStartNode); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
} | ||
diff(oldEndNode, newStartNode, replayer, rrnodeMirror); | ||
@@ -767,5 +831,12 @@ oldEndNode = oldChildren[--oldEndIndex]; | ||
indexInOld = oldIdToIndex[rrnodeMirror.getId(newStartNode)]; | ||
if (indexInOld) { | ||
const nodeToMove = oldChildren[indexInOld]; | ||
parentNode.insertBefore(nodeToMove, oldStartNode); | ||
const nodeToMove = oldChildren[indexInOld]; | ||
if (indexInOld !== undefined && | ||
nodeToMove && | ||
nodeMatching(nodeToMove, newStartNode, replayer.mirror, rrnodeMirror)) { | ||
try { | ||
parentNode.insertBefore(nodeToMove, oldStartNode); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
} | ||
diff(nodeToMove, newStartNode, replayer, rrnodeMirror); | ||
@@ -777,10 +848,18 @@ oldChildren[indexInOld] = undefined; | ||
if (parentNode.nodeName === '#document' && | ||
((_a = replayer.mirror.getMeta(newNode)) === null || _a === void 0 ? void 0 : _a.type) === NodeType.Element && | ||
parentNode.documentElement) { | ||
parentNode.removeChild(parentNode.documentElement); | ||
oldChildren[oldStartIndex] = undefined; | ||
oldStartNode = undefined; | ||
oldStartNode && | ||
((newNode.nodeType === newNode.DOCUMENT_TYPE_NODE && | ||
oldStartNode.nodeType === oldStartNode.DOCUMENT_TYPE_NODE) || | ||
(newNode.nodeType === newNode.ELEMENT_NODE && | ||
oldStartNode.nodeType === oldStartNode.ELEMENT_NODE))) { | ||
parentNode.removeChild(oldStartNode); | ||
replayer.mirror.removeNodeFromMap(oldStartNode); | ||
oldStartNode = oldChildren[++oldStartIndex]; | ||
} | ||
parentNode.insertBefore(newNode, oldStartNode || null); | ||
diff(newNode, newStartNode, replayer, rrnodeMirror); | ||
try { | ||
parentNode.insertBefore(newNode, oldStartNode || null); | ||
diff(newNode, newStartNode, replayer, rrnodeMirror); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
} | ||
} | ||
@@ -794,10 +873,12 @@ newStartNode = newChildren[++newStartIndex]; | ||
if (referenceRRNode) | ||
parentNode.childNodes.forEach((child) => { | ||
if (replayer.mirror.getId(child) === rrnodeMirror.getId(referenceRRNode)) | ||
referenceNode = child; | ||
}); | ||
referenceNode = replayer.mirror.getNode(rrnodeMirror.getId(referenceRRNode)); | ||
for (; newStartIndex <= newEndIndex; ++newStartIndex) { | ||
const newNode = createOrGetNode(newChildren[newStartIndex], replayer.mirror, rrnodeMirror); | ||
parentNode.insertBefore(newNode, referenceNode); | ||
diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror); | ||
try { | ||
parentNode.insertBefore(newNode, referenceNode); | ||
diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
} | ||
} | ||
@@ -808,6 +889,11 @@ } | ||
const node = oldChildren[oldStartIndex]; | ||
if (node) { | ||
if (!node || !parentNode.contains(node)) | ||
continue; | ||
try { | ||
parentNode.removeChild(node); | ||
replayer.mirror.removeNodeFromMap(node); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
} | ||
} | ||
@@ -822,3 +908,3 @@ } | ||
node = domMirror.getNode(nodeId); | ||
if (node !== null) | ||
if (node !== null && sameNodeType(node, rrNode)) | ||
return node; | ||
@@ -854,4 +940,23 @@ switch (rrNode.RRNodeType) { | ||
domMirror.add(node, Object.assign({}, sn)); | ||
try { | ||
createdNodeSet === null || createdNodeSet === void 0 ? void 0 : createdNodeSet.add(node); | ||
} | ||
catch (e) { | ||
} | ||
return node; | ||
} | ||
function sameNodeType(node1, node2) { | ||
if (node1.nodeType !== node2.nodeType) | ||
return false; | ||
return (node1.nodeType !== node1.ELEMENT_NODE || | ||
node1.tagName.toUpperCase() === | ||
node2.tagName); | ||
} | ||
function nodeMatching(node1, node2, domMirror, rrdomMirror) { | ||
const node1Id = domMirror.getId(node1); | ||
const node2Id = rrdomMirror.getId(node2); | ||
if (node1Id === -1 || node1Id !== node2Id) | ||
return false; | ||
return sameNodeType(node1, node2); | ||
} | ||
@@ -920,3 +1025,4 @@ class RRDocument extends BaseRRDocumentImpl(BaseRRNode) { | ||
destroyTree() { | ||
this.childNodes = []; | ||
this.firstChild = null; | ||
this.lastChild = null; | ||
this.mirror.reset(); | ||
@@ -923,0 +1029,0 @@ } |
@@ -1,2 +0,2 @@ | ||
var rrdom=function(e){"use strict";var t;!function(e){e[e.Document=0]="Document",e[e.DocumentType=1]="DocumentType",e[e.Element=2]="Element",e[e.Text=3]="Text",e[e.CDATA=4]="CDATA",e[e.Comment=5]="Comment"}(t||(t={}));var o=function(){function e(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}return e.prototype.getId=function(e){var t;if(!e)return-1;var o=null===(t=this.getMeta(e))||void 0===t?void 0:t.id;return null!=o?o:-1},e.prototype.getNode=function(e){return this.idNodeMap.get(e)||null},e.prototype.getIds=function(){return Array.from(this.idNodeMap.keys())},e.prototype.getMeta=function(e){return this.nodeMetaMap.get(e)||null},e.prototype.removeNodeFromMap=function(e){var t=this,o=this.getId(e);this.idNodeMap.delete(o),e.childNodes&&e.childNodes.forEach((function(e){return t.removeNodeFromMap(e)}))},e.prototype.has=function(e){return this.idNodeMap.has(e)},e.prototype.hasNode=function(e){return this.nodeMetaMap.has(e)},e.prototype.add=function(e,t){var o=t.id;this.idNodeMap.set(o,e),this.nodeMetaMap.set(e,t)},e.prototype.replace=function(e,t){var o=this.getNode(e);if(o){var n=this.nodeMetaMap.get(o);n&&this.nodeMetaMap.set(t,n)}this.idNodeMap.set(e,t)},e.prototype.reset=function(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap},e}();function n(e){const t=[];for(const o in e){const n=e[o];if("string"!=typeof n)continue;const r=d(o);t.push(`${r}: ${n};`)}return t.join(" ")}const r=/-([a-z])/g,s=/^--[a-zA-Z0-9-]+$/,i=e=>s.test(e)?e:e.replace(r,((e,t)=>t?t.toUpperCase():"")),a=/\B([A-Z])/g,d=e=>e.replace(a,"-$1").toLowerCase();class c{constructor(...t){this.childNodes=[],this.parentElement=null,this.parentNode=null,this.ELEMENT_NODE=e.NodeType.ELEMENT_NODE,this.TEXT_NODE=e.NodeType.TEXT_NODE}get firstChild(){return this.childNodes[0]||null}get lastChild(){return this.childNodes[this.childNodes.length-1]||null}get nextSibling(){const e=this.parentNode;if(!e)return null;const t=e.childNodes,o=t.indexOf(this);return t[o+1]||null}contains(e){if(e===this)return!0;for(const t of this.childNodes)if(t.contains(e))return!0;return!1}appendChild(e){throw new Error("RRDomException: Failed to execute 'appendChild' on 'RRNode': This RRNode type does not support this method.")}insertBefore(e,t){throw new Error("RRDomException: Failed to execute 'insertBefore' on 'RRNode': This RRNode type does not support this method.")}removeChild(e){throw new Error("RRDomException: Failed to execute 'removeChild' on 'RRNode': This RRNode type does not support this method.")}toString(){return"RRNode"}}function l(o){return class n extends o{constructor(){super(...arguments),this.nodeType=e.NodeType.DOCUMENT_NODE,this.nodeName="#document",this.compatMode="CSS1Compat",this.RRNodeType=t.Document,this.textContent=null}get documentElement(){return this.childNodes.find((e=>e.RRNodeType===t.Element&&"HTML"===e.tagName))||null}get body(){var e;return(null===(e=this.documentElement)||void 0===e?void 0:e.childNodes.find((e=>e.RRNodeType===t.Element&&"BODY"===e.tagName)))||null}get head(){var e;return(null===(e=this.documentElement)||void 0===e?void 0:e.childNodes.find((e=>e.RRNodeType===t.Element&&"HEAD"===e.tagName)))||null}get implementation(){return this}get firstElementChild(){return this.documentElement}appendChild(e){const o=e.RRNodeType;if((o===t.Element||o===t.DocumentType)&&this.childNodes.some((e=>e.RRNodeType===o)))throw new Error(`RRDomException: Failed to execute 'appendChild' on 'RRNode': Only one ${o===t.Element?"RRElement":"RRDoctype"} on RRDocument allowed.`);return e.parentElement=null,e.parentNode=this,this.childNodes.push(e),e}insertBefore(e,o){const n=e.RRNodeType;if((n===t.Element||n===t.DocumentType)&&this.childNodes.some((e=>e.RRNodeType===n)))throw new Error(`RRDomException: Failed to execute 'insertBefore' on 'RRNode': Only one ${n===t.Element?"RRElement":"RRDoctype"} on RRDocument allowed.`);if(null===o)return this.appendChild(e);const r=this.childNodes.indexOf(o);if(-1==r)throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode.");return this.childNodes.splice(r,0,e),e.parentElement=null,e.parentNode=this,e}removeChild(e){const t=this.childNodes.indexOf(e);if(-1===t)throw new Error("Failed to execute 'removeChild' on 'RRDocument': The RRNode to be removed is not a child of this RRNode.");return this.childNodes.splice(t,1),e.parentElement=null,e.parentNode=null,e}open(){this.childNodes=[]}close(){}write(e){let t;if('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">'===e?t="-//W3C//DTD XHTML 1.0 Transitional//EN":'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">'===e&&(t="-//W3C//DTD HTML 4.0 Transitional//EN"),t){const e=this.createDocumentType("html",t,"");this.open(),this.appendChild(e)}}createDocument(e,t,o){return new n}createDocumentType(e,t,o){const n=new(u(c))(e,t,o);return n.ownerDocument=this,n}createElement(e){const t=new(h(c))(e);return t.ownerDocument=this,t}createElementNS(e,t){return this.createElement(t)}createTextNode(e){const t=new(m(c))(e);return t.ownerDocument=this,t}createComment(e){const t=new(N(c))(e);return t.ownerDocument=this,t}createCDATASection(e){const t=new(f(c))(e);return t.ownerDocument=this,t}toString(){return"RRDocument"}}}function u(o){return class extends o{constructor(o,n,r){super(),this.nodeType=e.NodeType.DOCUMENT_TYPE_NODE,this.RRNodeType=t.DocumentType,this.textContent=null,this.name=o,this.publicId=n,this.systemId=r,this.nodeName=o}toString(){return"RRDocumentType"}}}function h(o){return class extends o{constructor(o){super(),this.nodeType=e.NodeType.ELEMENT_NODE,this.RRNodeType=t.Element,this.attributes={},this.shadowRoot=null,this.tagName=o.toUpperCase(),this.nodeName=o.toUpperCase()}get textContent(){let e="";return this.childNodes.forEach((t=>e+=t.textContent)),e}set textContent(e){this.childNodes=[this.ownerDocument.createTextNode(e)]}get classList(){return new E(this.attributes.class,(e=>{this.attributes.class=e}))}get id(){return this.attributes.id||""}get className(){return this.attributes.class||""}get style(){const e=this.attributes.style?function(e){const t={},o=/:(.+)/;return e.replace(/\/\*.*?\*\//g,"").split(/;(?![^(]*\))/g).forEach((function(e){if(e){const n=e.split(o);n.length>1&&(t[i(n[0].trim())]=n[1].trim())}})),t}(this.attributes.style):{},t=/\B([A-Z])/g;return e.setProperty=(o,r,s)=>{if(t.test(o))return;const a=i(o);r?e[a]=r:delete e[a],"important"===s&&(e[a]+=" !important"),this.attributes.style=n(e)},e.removeProperty=o=>{if(t.test(o))return"";const r=i(o),s=e[r]||"";return delete e[r],this.attributes.style=n(e),s},e}getAttribute(e){return this.attributes[e]||null}setAttribute(e,t){this.attributes[e]=t}setAttributeNS(e,t,o){this.setAttribute(t,o)}removeAttribute(e){delete this.attributes[e]}appendChild(e){return this.childNodes.push(e),e.parentNode=this,e.parentElement=this,e}insertBefore(e,t){if(null===t)return this.appendChild(e);const o=this.childNodes.indexOf(t);if(-1==o)throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode.");return this.childNodes.splice(o,0,e),e.parentElement=this,e.parentNode=this,e}removeChild(e){const t=this.childNodes.indexOf(e);if(-1===t)throw new Error("Failed to execute 'removeChild' on 'RRElement': The RRNode to be removed is not a child of this RRNode.");return this.childNodes.splice(t,1),e.parentElement=null,e.parentNode=null,e}attachShadow(e){const t=this.ownerDocument.createElement("SHADOWROOT");return this.shadowRoot=t,t}dispatchEvent(e){return!0}toString(){let e="";for(const t in this.attributes)e+=`${t}="${this.attributes[t]}" `;return`${this.tagName} ${e}`}}}function p(e){return class extends e{attachShadow(e){throw new Error("RRDomException: Failed to execute 'attachShadow' on 'RRElement': This RRElement does not support attachShadow")}play(){this.paused=!1}pause(){this.paused=!0}}}function m(o){return class extends o{constructor(o){super(),this.nodeType=e.NodeType.TEXT_NODE,this.nodeName="#text",this.RRNodeType=t.Text,this.data=o}get textContent(){return this.data}set textContent(e){this.data=e}toString(){return`RRText text=${JSON.stringify(this.data)}`}}}function N(o){return class extends o{constructor(o){super(),this.nodeType=e.NodeType.COMMENT_NODE,this.nodeName="#comment",this.RRNodeType=t.Comment,this.data=o}get textContent(){return this.data}set textContent(e){this.data=e}toString(){return`RRComment text=${JSON.stringify(this.data)}`}}}function f(o){return class extends o{constructor(o){super(),this.nodeName="#cdata-section",this.nodeType=e.NodeType.CDATA_SECTION_NODE,this.RRNodeType=t.CDATA,this.data=o}get textContent(){return this.data}set textContent(e){this.data=e}toString(){return`RRCDATASection data=${JSON.stringify(this.data)}`}}}class E{constructor(e,t){if(this.classes=[],this.add=(...e)=>{for(const t of e){const e=String(t);this.classes.indexOf(e)>=0||this.classes.push(e)}this.onChange&&this.onChange(this.classes.join(" "))},this.remove=(...e)=>{this.classes=this.classes.filter((t=>-1===e.indexOf(t))),this.onChange&&this.onChange(this.classes.join(" "))},e){const t=e.trim().split(/\s+/);this.classes.push(...t)}this.onChange=t}}e.NodeType=void 0,function(e){e[e.PLACEHOLDER=0]="PLACEHOLDER",e[e.ELEMENT_NODE=1]="ELEMENT_NODE",e[e.ATTRIBUTE_NODE=2]="ATTRIBUTE_NODE",e[e.TEXT_NODE=3]="TEXT_NODE",e[e.CDATA_SECTION_NODE=4]="CDATA_SECTION_NODE",e[e.ENTITY_REFERENCE_NODE=5]="ENTITY_REFERENCE_NODE",e[e.ENTITY_NODE=6]="ENTITY_NODE",e[e.PROCESSING_INSTRUCTION_NODE=7]="PROCESSING_INSTRUCTION_NODE",e[e.COMMENT_NODE=8]="COMMENT_NODE",e[e.DOCUMENT_NODE=9]="DOCUMENT_NODE",e[e.DOCUMENT_TYPE_NODE=10]="DOCUMENT_TYPE_NODE",e[e.DOCUMENT_FRAGMENT_NODE=11]="DOCUMENT_FRAGMENT_NODE"}(e.NodeType||(e.NodeType={}));const T={svg:"http://www.w3.org/2000/svg","xlink:href":"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},R={altglyph:"altGlyph",altglyphdef:"altGlyphDef",altglyphitem:"altGlyphItem",animatecolor:"animateColor",animatemotion:"animateMotion",animatetransform:"animateTransform",clippath:"clipPath",feblend:"feBlend",fecolormatrix:"feColorMatrix",fecomponenttransfer:"feComponentTransfer",fecomposite:"feComposite",feconvolvematrix:"feConvolveMatrix",fediffuselighting:"feDiffuseLighting",fedisplacementmap:"feDisplacementMap",fedistantlight:"feDistantLight",fedropshadow:"feDropShadow",feflood:"feFlood",fefunca:"feFuncA",fefuncb:"feFuncB",fefuncg:"feFuncG",fefuncr:"feFuncR",fegaussianblur:"feGaussianBlur",feimage:"feImage",femerge:"feMerge",femergenode:"feMergeNode",femorphology:"feMorphology",feoffset:"feOffset",fepointlight:"fePointLight",fespecularlighting:"feSpecularLighting",fespotlight:"feSpotLight",fetile:"feTile",feturbulence:"feTurbulence",foreignobject:"foreignObject",glyphref:"glyphRef",lineargradient:"linearGradient",radialgradient:"radialGradient"};function D(e,o,n,r){const s=e.childNodes,i=o.childNodes;r=r||o.mirror||o.ownerDocument.mirror,(s.length>0||i.length>0)&&g(Array.from(s),i,e,n,r);let a=null,d=null;switch(o.RRNodeType){case t.Document:d=o.scrollData;break;case t.Element:{const t=e,s=o;switch(function(e,t,o){const n=e.attributes,r=t.attributes;for(const n in r){const s=r[n],i=o.getMeta(t);if(i&&"isSVG"in i&&i.isSVG&&T[n])e.setAttributeNS(T[n],n,s);else if("CANVAS"===t.tagName&&"rr_dataURL"===n){const t=document.createElement("img");t.src=s,t.onload=()=>{const o=e.getContext("2d");o&&o.drawImage(t,0,0,t.width,t.height)}}else e.setAttribute(n,s)}for(const{name:t}of Array.from(n))t in r||e.removeAttribute(t);t.scrollLeft&&(e.scrollLeft=t.scrollLeft),t.scrollTop&&(e.scrollTop=t.scrollTop)}(t,s,r),d=s.scrollData,a=s.inputData,s.tagName){case"AUDIO":case"VIDEO":{const t=e,o=s;void 0!==o.paused&&(o.paused?t.pause():t.play()),void 0!==o.muted&&(t.muted=o.muted),void 0!==o.volume&&(t.volume=o.volume),void 0!==o.currentTime&&(t.currentTime=o.currentTime),void 0!==o.playbackRate&&(t.playbackRate=o.playbackRate);break}case"CANVAS":{const r=o;if(null!==r.rr_dataURL){const e=document.createElement("img");e.onload=()=>{const o=t.getContext("2d");o&&o.drawImage(e,0,0,e.width,e.height)},e.src=r.rr_dataURL}r.canvasMutations.forEach((t=>n.applyCanvas(t.event,t.mutation,e)))}break;case"STYLE":{const e=t.sheet;e&&o.rules.forEach((t=>n.applyStyleSheetMutation(t,e)))}}if(s.shadowRoot){t.shadowRoot||t.attachShadow({mode:"open"});const e=t.shadowRoot.childNodes,o=s.shadowRoot.childNodes;(e.length>0||o.length>0)&&g(Array.from(e),o,t.shadowRoot,n,r)}break}case t.Text:case t.Comment:case t.CDATA:e.textContent!==o.data&&(e.textContent=o.data)}if(d&&n.applyScroll(d,!0),a&&n.applyInput(a),"IFRAME"===o.nodeName){const t=e.contentDocument,s=o;if(t){const e=r.getMeta(s.contentDocument);e&&n.mirror.add(t,Object.assign({},e)),D(t,s.contentDocument,n,r)}}}function g(e,o,n,r,s){var i;let a,d,c=0,l=e.length-1,u=0,h=o.length-1,p=e[c],m=e[l],N=o[u],f=o[h];for(;c<=l&&u<=h;){const E=r.mirror.getId(p),T=r.mirror.getId(m),R=s.getId(N),g=s.getId(f);if(void 0===p)p=e[++c];else if(void 0===m)m=e[--l];else if(-1!==E&&E===R)D(p,N,r,s),p=e[++c],N=o[++u];else if(-1!==T&&T===g)D(m,f,r,s),m=e[--l],f=o[--h];else if(-1!==E&&E===g)n.insertBefore(p,m.nextSibling),D(p,f,r,s),p=e[++c],f=o[--h];else if(-1!==T&&T===R)n.insertBefore(m,p),D(m,N,r,s),m=e[--l],N=o[++u];else{if(!a){a={};for(let t=c;t<=l;t++){const o=e[t];o&&r.mirror.hasNode(o)&&(a[r.mirror.getId(o)]=t)}}if(d=a[s.getId(N)],d){const t=e[d];n.insertBefore(t,p),D(t,N,r,s),e[d]=void 0}else{const o=y(N,r.mirror,s);"#document"===n.nodeName&&(null===(i=r.mirror.getMeta(o))||void 0===i?void 0:i.type)===t.Element&&n.documentElement&&(n.removeChild(n.documentElement),e[c]=void 0,p=void 0),n.insertBefore(o,p||null),D(o,N,r,s)}N=o[++u]}}if(c>l){const e=o[h+1];let t=null;for(e&&n.childNodes.forEach((o=>{r.mirror.getId(o)===s.getId(e)&&(t=o)}));u<=h;++u){const e=y(o[u],r.mirror,s);n.insertBefore(e,t),D(e,o[u],r,s)}}else if(u>h)for(;c<=l;c++){const t=e[c];t&&(n.removeChild(t),r.mirror.removeNodeFromMap(t))}}function y(e,o,n){const r=n.getId(e),s=n.getMeta(e);let i=null;if(r>-1&&(i=o.getNode(r)),null!==i)return i;switch(e.RRNodeType){case t.Document:i=new Document;break;case t.DocumentType:i=document.implementation.createDocumentType(e.name,e.publicId,e.systemId);break;case t.Element:{let t=e.tagName.toLowerCase();t=R[t]||t,i=s&&"isSVG"in s&&(null==s?void 0:s.isSVG)?document.createElementNS(T.svg,t):document.createElement(e.tagName);break}case t.Text:i=document.createTextNode(e.data);break;case t.Comment:i=document.createComment(e.data);break;case t.CDATA:i=document.createCDATASection(e.data)}return s&&o.add(i,Object.assign({},s)),i}class C extends(l(c)){constructor(e){super(),this.UNSERIALIZED_STARTING_ID=-2,this._unserializedId=this.UNSERIALIZED_STARTING_ID,this.mirror=L(),this.scrollData=null,e&&(this.mirror=e)}get unserializedId(){return this._unserializedId--}createDocument(e,t,o){return new C}createDocumentType(e,t,o){const n=new M(e,t,o);return n.ownerDocument=this,n}createElement(e){const t=e.toUpperCase();let o;switch(t){case"AUDIO":case"VIDEO":o=new O(t);break;case"IFRAME":o=new A(t,this.mirror);break;case"CANVAS":o=new x(t);break;case"STYLE":o=new I(t);break;default:o=new w(t)}return o.ownerDocument=this,o}createComment(e){const t=new _(e);return t.ownerDocument=this,t}createCDATASection(e){const t=new v(e);return t.ownerDocument=this,t}createTextNode(e){const t=new b(e);return t.ownerDocument=this,t}destroyTree(){this.childNodes=[],this.mirror.reset()}open(){super.open(),this._unserializedId=this.UNSERIALIZED_STARTING_ID}}const M=u(c);class w extends(h(c)){constructor(){super(...arguments),this.inputData=null,this.scrollData=null}}class O extends(p(w)){}class x extends w{constructor(){super(...arguments),this.rr_dataURL=null,this.canvasMutations=[]}getContext(){return null}}class I extends w{constructor(){super(...arguments),this.rules=[]}}class A extends w{constructor(e,t){super(e),this.contentDocument=new C,this.contentDocument.mirror=t}}const b=m(c),_=N(c),v=f(c);function S(t,o,n,r){let s;switch(t.nodeType){case e.NodeType.DOCUMENT_NODE:r&&"IFRAME"===r.nodeName?s=r.contentDocument:(s=o,s.compatMode=t.compatMode);break;case e.NodeType.DOCUMENT_TYPE_NODE:{const e=t;s=o.createDocumentType(e.name,e.publicId,e.systemId);break}case e.NodeType.ELEMENT_NODE:{const e=t,n=(i=e)instanceof HTMLFormElement?"FORM":i.tagName.toUpperCase();s=o.createElement(n);const r=s;for(const{name:t,value:o}of Array.from(e.attributes))r.attributes[t]=o;e.scrollLeft&&(r.scrollLeft=e.scrollLeft),e.scrollTop&&(r.scrollTop=e.scrollTop);break}case e.NodeType.TEXT_NODE:s=o.createTextNode(t.textContent||"");break;case e.NodeType.CDATA_SECTION_NODE:s=o.createCDATASection(t.data);break;case e.NodeType.COMMENT_NODE:s=o.createComment(t.textContent||"");break;case e.NodeType.DOCUMENT_FRAGMENT_NODE:s=r.attachShadow({mode:"open"});break;default:return null}var i;let a=n.getMeta(t);return o instanceof C&&(a||(a=U(s,o.unserializedId),n.add(t,a)),o.mirror.add(s,Object.assign({},a))),s}function L(){return new F}class F{constructor(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}getId(e){var t;if(!e)return-1;const o=null===(t=this.getMeta(e))||void 0===t?void 0:t.id;return null!=o?o:-1}getNode(e){return this.idNodeMap.get(e)||null}getIds(){return Array.from(this.idNodeMap.keys())}getMeta(e){return this.nodeMetaMap.get(e)||null}removeNodeFromMap(e){const t=this.getId(e);this.idNodeMap.delete(t),e.childNodes&&e.childNodes.forEach((e=>this.removeNodeFromMap(e)))}has(e){return this.idNodeMap.has(e)}hasNode(e){return this.nodeMetaMap.has(e)}add(e,t){const o=t.id;this.idNodeMap.set(o,e),this.nodeMetaMap.set(e,t)}replace(e,t){const o=this.getNode(e);if(o){const e=this.nodeMetaMap.get(o);e&&this.nodeMetaMap.set(t,e)}this.idNodeMap.set(e,t)}reset(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}}function U(e,o){switch(e.RRNodeType){case t.Document:return{id:o,type:e.RRNodeType,childNodes:[]};case t.DocumentType:{const t=e;return{id:o,type:e.RRNodeType,name:t.name,publicId:t.publicId,systemId:t.systemId}}case t.Element:return{id:o,type:e.RRNodeType,tagName:e.tagName.toLowerCase(),attributes:{},childNodes:[]};case t.Text:case t.Comment:return{id:o,type:e.RRNodeType,textContent:e.textContent||""};case t.CDATA:return{id:o,type:e.RRNodeType,textContent:""}}}function k(e,o,n){let r=`${n}${o.getId(e)} ${e.toString()}\n`;if(e.RRNodeType===t.Element){const t=e;t.shadowRoot&&(r+=k(t.shadowRoot,o,n+" "))}for(const t of e.childNodes)r+=k(t,o,n+" ");return"IFRAME"===e.nodeName&&(r+=k(e.contentDocument,o,n+" ")),r}return e.BaseRRCDATASectionImpl=f,e.BaseRRCommentImpl=N,e.BaseRRDocumentImpl=l,e.BaseRRDocumentTypeImpl=u,e.BaseRRElementImpl=h,e.BaseRRMediaElementImpl=p,e.BaseRRNode=c,e.BaseRRTextImpl=m,e.ClassList=E,e.Mirror=F,e.RRCDATASection=v,e.RRCanvasElement=x,e.RRComment=_,e.RRDocument=C,e.RRDocumentType=M,e.RRElement=w,e.RRIFrameElement=A,e.RRMediaElement=O,e.RRNode=c,e.RRStyleElement=I,e.RRText=b,e.buildFromDom=function(t,n=function(){return new o}(),r=new C){return function t(o,s){const i=S(o,r,n,s);if(null!==i)if("IFRAME"!==(null==s?void 0:s.nodeName)&&o.nodeType!==e.NodeType.DOCUMENT_FRAGMENT_NODE&&(null==s||s.appendChild(i),i.parentNode=s,i.parentElement=s),"IFRAME"===o.nodeName){const e=o.contentDocument;e&&t(e,i)}else o.nodeType!==e.NodeType.DOCUMENT_NODE&&o.nodeType!==e.NodeType.ELEMENT_NODE&&o.nodeType!==e.NodeType.DOCUMENT_FRAGMENT_NODE||(o.nodeType===e.NodeType.ELEMENT_NODE&&o.shadowRoot&&t(o.shadowRoot,i),o.childNodes.forEach((e=>t(e,i))))}(t,null),r},e.buildFromNode=S,e.createMirror=L,e.createOrGetNode=y,e.diff=D,e.getDefaultSN=U,e.printRRDom=function(e,t){return k(e,t,"")},Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
var rrdom=function(e){"use strict";var t;!function(e){e[e.Document=0]="Document",e[e.DocumentType=1]="DocumentType",e[e.Element=2]="Element",e[e.Text=3]="Text",e[e.CDATA=4]="CDATA",e[e.Comment=5]="Comment"}(t||(t={}));var n=function(){function e(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}return e.prototype.getId=function(e){var t;if(!e)return-1;var n=null===(t=this.getMeta(e))||void 0===t?void 0:t.id;return null!=n?n:-1},e.prototype.getNode=function(e){return this.idNodeMap.get(e)||null},e.prototype.getIds=function(){return Array.from(this.idNodeMap.keys())},e.prototype.getMeta=function(e){return this.nodeMetaMap.get(e)||null},e.prototype.removeNodeFromMap=function(e){var t=this,n=this.getId(e);this.idNodeMap.delete(n),e.childNodes&&e.childNodes.forEach((function(e){return t.removeNodeFromMap(e)}))},e.prototype.has=function(e){return this.idNodeMap.has(e)},e.prototype.hasNode=function(e){return this.nodeMetaMap.has(e)},e.prototype.add=function(e,t){var n=t.id;this.idNodeMap.set(n,e),this.nodeMetaMap.set(e,t)},e.prototype.replace=function(e,t){var n=this.getNode(e);if(n){var o=this.nodeMetaMap.get(n);o&&this.nodeMetaMap.set(t,o)}this.idNodeMap.set(e,t)},e.prototype.reset=function(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap},e}();function o(e){const t=[];for(const n in e){const o=e[n];if("string"!=typeof o)continue;const r=l(n);t.push(`${r}: ${o};`)}return t.join(" ")}const r=/-([a-z])/g,i=/^--[a-zA-Z0-9-]+$/,s=e=>i.test(e)?e:e.replace(r,((e,t)=>t?t.toUpperCase():"")),a=/\B([A-Z])/g,l=e=>e.replace(a,"-$1").toLowerCase();class d{constructor(...t){this.parentElement=null,this.parentNode=null,this.firstChild=null,this.lastChild=null,this.previousSibling=null,this.nextSibling=null,this.ELEMENT_NODE=e.NodeType.ELEMENT_NODE,this.TEXT_NODE=e.NodeType.TEXT_NODE}get childNodes(){const e=[];let t=this.firstChild;for(;t;)e.push(t),t=t.nextSibling;return e}contains(e){if(!(e instanceof d))return!1;if(e.ownerDocument!==this.ownerDocument)return!1;if(e===this)return!0;for(;e.parentNode;){if(e.parentNode===this)return!0;e=e.parentNode}return!1}appendChild(e){throw new Error("RRDomException: Failed to execute 'appendChild' on 'RRNode': This RRNode type does not support this method.")}insertBefore(e,t){throw new Error("RRDomException: Failed to execute 'insertBefore' on 'RRNode': This RRNode type does not support this method.")}removeChild(e){throw new Error("RRDomException: Failed to execute 'removeChild' on 'RRNode': This RRNode type does not support this method.")}toString(){return"RRNode"}}function c(n){return class o extends n{constructor(...n){super(n),this.nodeType=e.NodeType.DOCUMENT_NODE,this.nodeName="#document",this.compatMode="CSS1Compat",this.RRNodeType=t.Document,this.textContent=null,this.ownerDocument=this}get documentElement(){return this.childNodes.find((e=>e.RRNodeType===t.Element&&"HTML"===e.tagName))||null}get body(){var e;return(null===(e=this.documentElement)||void 0===e?void 0:e.childNodes.find((e=>e.RRNodeType===t.Element&&"BODY"===e.tagName)))||null}get head(){var e;return(null===(e=this.documentElement)||void 0===e?void 0:e.childNodes.find((e=>e.RRNodeType===t.Element&&"HEAD"===e.tagName)))||null}get implementation(){return this}get firstElementChild(){return this.documentElement}appendChild(e){const n=e.RRNodeType;if((n===t.Element||n===t.DocumentType)&&this.childNodes.some((e=>e.RRNodeType===n)))throw new Error(`RRDomException: Failed to execute 'appendChild' on 'RRNode': Only one ${n===t.Element?"RRElement":"RRDoctype"} on RRDocument allowed.`);const o=T(this,e);return o.parentElement=null,o}insertBefore(e,n){const o=e.RRNodeType;if((o===t.Element||o===t.DocumentType)&&this.childNodes.some((e=>e.RRNodeType===o)))throw new Error(`RRDomException: Failed to execute 'insertBefore' on 'RRNode': Only one ${o===t.Element?"RRElement":"RRDoctype"} on RRDocument allowed.`);const r=R(this,e,n);return r.parentElement=null,r}removeChild(e){return D(this,e)}open(){this.firstChild=null,this.lastChild=null}close(){}write(e){let t;if('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">'===e?t="-//W3C//DTD XHTML 1.0 Transitional//EN":'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">'===e&&(t="-//W3C//DTD HTML 4.0 Transitional//EN"),t){const e=this.createDocumentType("html",t,"");this.open(),this.appendChild(e)}}createDocument(e,t,n){return new o}createDocumentType(e,t,n){const o=new(u(d))(e,t,n);return o.ownerDocument=this,o}createElement(e){const t=new(h(d))(e);return t.ownerDocument=this,t}createElementNS(e,t){return this.createElement(t)}createTextNode(e){const t=new(m(d))(e);return t.ownerDocument=this,t}createComment(e){const t=new(N(d))(e);return t.ownerDocument=this,t}createCDATASection(e){const t=new(f(d))(e);return t.ownerDocument=this,t}toString(){return"RRDocument"}}}function u(n){return class extends n{constructor(n,o,r){super(),this.nodeType=e.NodeType.DOCUMENT_TYPE_NODE,this.RRNodeType=t.DocumentType,this.name=n,this.publicId=o,this.systemId=r,this.nodeName=n,this.textContent=null}toString(){return"RRDocumentType"}}}function h(n){return class extends n{constructor(n){super(),this.nodeType=e.NodeType.ELEMENT_NODE,this.RRNodeType=t.Element,this.attributes={},this.shadowRoot=null,this.tagName=n.toUpperCase(),this.nodeName=n.toUpperCase()}get textContent(){let e="";return this.childNodes.forEach((t=>e+=t.textContent)),e}set textContent(e){this.firstChild=null,this.lastChild=null,this.appendChild(this.ownerDocument.createTextNode(e))}get classList(){return new E(this.attributes.class,(e=>{this.attributes.class=e}))}get id(){return this.attributes.id||""}get className(){return this.attributes.class||""}get style(){const e=this.attributes.style?function(e){const t={},n=/:(.+)/;return e.replace(/\/\*.*?\*\//g,"").split(/;(?![^(]*\))/g).forEach((function(e){if(e){const o=e.split(n);o.length>1&&(t[s(o[0].trim())]=o[1].trim())}})),t}(this.attributes.style):{},t=/\B([A-Z])/g;return e.setProperty=(n,r,i)=>{if(t.test(n))return;const a=s(n);r?e[a]=r:delete e[a],"important"===i&&(e[a]+=" !important"),this.attributes.style=o(e)},e.removeProperty=n=>{if(t.test(n))return"";const r=s(n),i=e[r]||"";return delete e[r],this.attributes.style=o(e),i},e}getAttribute(e){return this.attributes[e]||null}setAttribute(e,t){this.attributes[e]=t}setAttributeNS(e,t,n){this.setAttribute(t,n)}removeAttribute(e){delete this.attributes[e]}appendChild(e){return T(this,e)}insertBefore(e,t){return R(this,e,t)}removeChild(e){return D(this,e)}attachShadow(e){const t=this.ownerDocument.createElement("SHADOWROOT");return this.shadowRoot=t,t}dispatchEvent(e){return!0}toString(){let e="";for(const t in this.attributes)e+=`${t}="${this.attributes[t]}" `;return`${this.tagName} ${e}`}}}function p(e){return class extends e{attachShadow(e){throw new Error("RRDomException: Failed to execute 'attachShadow' on 'RRElement': This RRElement does not support attachShadow")}play(){this.paused=!1}pause(){this.paused=!0}}}function m(n){return class extends n{constructor(n){super(),this.nodeType=e.NodeType.TEXT_NODE,this.nodeName="#text",this.RRNodeType=t.Text,this.data=n}get textContent(){return this.data}set textContent(e){this.data=e}toString(){return`RRText text=${JSON.stringify(this.data)}`}}}function N(n){return class extends n{constructor(n){super(),this.nodeType=e.NodeType.COMMENT_NODE,this.nodeName="#comment",this.RRNodeType=t.Comment,this.data=n}get textContent(){return this.data}set textContent(e){this.data=e}toString(){return`RRComment text=${JSON.stringify(this.data)}`}}}function f(n){return class extends n{constructor(n){super(),this.nodeName="#cdata-section",this.nodeType=e.NodeType.CDATA_SECTION_NODE,this.RRNodeType=t.CDATA,this.data=n}get textContent(){return this.data}set textContent(e){this.data=e}toString(){return`RRCDATASection data=${JSON.stringify(this.data)}`}}}class E{constructor(e,t){if(this.classes=[],this.add=(...e)=>{for(const t of e){const e=String(t);this.classes.indexOf(e)>=0||this.classes.push(e)}this.onChange&&this.onChange(this.classes.join(" "))},this.remove=(...e)=>{this.classes=this.classes.filter((t=>-1===e.indexOf(t))),this.onChange&&this.onChange(this.classes.join(" "))},e){const t=e.trim().split(/\s+/);this.classes.push(...t)}this.onChange=t}}function T(e,t){return e.lastChild?(e.lastChild.nextSibling=t,t.previousSibling=e.lastChild):(e.firstChild=t,t.previousSibling=null),e.lastChild=t,t.nextSibling=null,t.parentNode=e,t.parentElement=e,t.ownerDocument=e.ownerDocument,t}function R(e,t,n){if(!n)return T(e,t);if(n.parentNode!==e)throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode.");return t.previousSibling=n.previousSibling,n.previousSibling=t,t.nextSibling=n,t.previousSibling?t.previousSibling.nextSibling=t:e.firstChild=t,t.parentElement=e,t.parentNode=e,t.ownerDocument=e.ownerDocument,t}function D(e,t){if(t.parentNode!==e)throw new Error("Failed to execute 'removeChild' on 'RRNode': The RRNode to be removed is not a child of this RRNode.");return t.previousSibling?t.previousSibling.nextSibling=t.nextSibling:e.firstChild=t.nextSibling,t.nextSibling?t.nextSibling.previousSibling=t.previousSibling:e.lastChild=t.previousSibling,t.previousSibling=null,t.nextSibling=null,t.parentElement=null,t.parentNode=null,t}e.NodeType=void 0,function(e){e[e.PLACEHOLDER=0]="PLACEHOLDER",e[e.ELEMENT_NODE=1]="ELEMENT_NODE",e[e.ATTRIBUTE_NODE=2]="ATTRIBUTE_NODE",e[e.TEXT_NODE=3]="TEXT_NODE",e[e.CDATA_SECTION_NODE=4]="CDATA_SECTION_NODE",e[e.ENTITY_REFERENCE_NODE=5]="ENTITY_REFERENCE_NODE",e[e.ENTITY_NODE=6]="ENTITY_NODE",e[e.PROCESSING_INSTRUCTION_NODE=7]="PROCESSING_INSTRUCTION_NODE",e[e.COMMENT_NODE=8]="COMMENT_NODE",e[e.DOCUMENT_NODE=9]="DOCUMENT_NODE",e[e.DOCUMENT_TYPE_NODE=10]="DOCUMENT_TYPE_NODE",e[e.DOCUMENT_FRAGMENT_NODE=11]="DOCUMENT_FRAGMENT_NODE"}(e.NodeType||(e.NodeType={}));const g={svg:"http://www.w3.org/2000/svg","xlink:href":"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},y={altglyph:"altGlyph",altglyphdef:"altGlyphDef",altglyphitem:"altGlyphItem",animatecolor:"animateColor",animatemotion:"animateMotion",animatetransform:"animateTransform",clippath:"clipPath",feblend:"feBlend",fecolormatrix:"feColorMatrix",fecomponenttransfer:"feComponentTransfer",fecomposite:"feComposite",feconvolvematrix:"feConvolveMatrix",fediffuselighting:"feDiffuseLighting",fedisplacementmap:"feDisplacementMap",fedistantlight:"feDistantLight",fedropshadow:"feDropShadow",feflood:"feFlood",fefunca:"feFuncA",fefuncb:"feFuncB",fefuncg:"feFuncG",fefuncr:"feFuncR",fegaussianblur:"feGaussianBlur",feimage:"feImage",femerge:"feMerge",femergenode:"feMergeNode",femorphology:"feMorphology",feoffset:"feOffset",fepointlight:"fePointLight",fespecularlighting:"feSpecularLighting",fespotlight:"feSpotLight",fetile:"feTile",feturbulence:"feTurbulence",foreignobject:"foreignObject",glyphref:"glyphRef",lineargradient:"linearGradient",radialgradient:"radialGradient"};let C=null;function M(e,n,o,r=n.mirror||n.ownerDocument.mirror){e=function(e,n,o,r){var i;o.afterAppend&&!C&&(C=new WeakSet,setTimeout((()=>{C=null}),0));if(!O(e,n)){const t=b(n,o.mirror,r);null===(i=e.parentNode)||void 0===i||i.replaceChild(t,e),e=t}switch(n.RRNodeType){case t.Document:if(!S(e,n,o.mirror,r)){const t=r.getMeta(n);t&&(o.mirror.removeNodeFromMap(e),e.close(),e.open(),o.mirror.add(e,t),null==C||C.add(e))}break;case t.Element:{const t=e,i=n;switch(i.tagName){case"IFRAME":{const t=e.contentDocument;if(!t)break;M(t,n.contentDocument,o,r);break}}if(i.shadowRoot){t.shadowRoot||t.attachShadow({mode:"open"});const e=t.shadowRoot.childNodes,n=i.shadowRoot.childNodes;(e.length>0||n.length>0)&&w(Array.from(e),n,t.shadowRoot,o,r)}break}}return e}(e,n,o,r);const i=e.childNodes,s=n.childNodes;(i.length>0||s.length>0)&&w(Array.from(i),s,e,o,r),function(e,n,o,r){var i;switch(n.RRNodeType){case t.Document:{const e=n.scrollData;e&&o.applyScroll(e,!0);break}case t.Element:{const t=e,i=n;switch(function(e,t,n){const o=e.attributes,r=t.attributes;for(const o in r){const i=r[o],s=n.getMeta(t);if((null==s?void 0:s.isSVG)&&g[o])e.setAttributeNS(g[o],o,i);else if("CANVAS"===t.tagName&&"rr_dataURL"===o){const t=document.createElement("img");t.src=i,t.onload=()=>{const n=e.getContext("2d");n&&n.drawImage(t,0,0,t.width,t.height)}}else e.setAttribute(o,i)}for(const{name:t}of Array.from(o))t in r||e.removeAttribute(t);t.scrollLeft&&(e.scrollLeft=t.scrollLeft),t.scrollTop&&(e.scrollTop=t.scrollTop)}(t,i,r),i.scrollData&&o.applyScroll(i.scrollData,!0),i.inputData&&o.applyInput(i.inputData),i.tagName){case"AUDIO":case"VIDEO":{const t=e,n=i;void 0!==n.paused&&(n.paused?t.pause():t.play()),void 0!==n.muted&&(t.muted=n.muted),void 0!==n.volume&&(t.volume=n.volume),void 0!==n.currentTime&&(t.currentTime=n.currentTime),void 0!==n.playbackRate&&(t.playbackRate=n.playbackRate);break}case"CANVAS":{const r=n;if(null!==r.rr_dataURL){const e=document.createElement("img");e.onload=()=>{const n=t.getContext("2d");n&&n.drawImage(e,0,0,e.width,e.height)},e.src=r.rr_dataURL}r.canvasMutations.forEach((t=>o.applyCanvas(t.event,t.mutation,e)));break}case"STYLE":{const e=t.sheet;e&&n.rules.forEach((t=>o.applyStyleSheetMutation(t,e)));break}}break}case t.Text:case t.Comment:case t.CDATA:e.textContent!==n.data&&(e.textContent=n.data)}(null==C?void 0:C.has(e))&&(C.delete(e),null===(i=o.afterAppend)||void 0===i||i.call(o,e,o.mirror.getId(e)))}(e,n,o,r)}function w(e,t,n,o,r){let i,s,a=0,l=e.length-1,d=0,c=t.length-1,u=e[a],h=e[l],p=t[d],m=t[c];for(;a<=l&&d<=c;)if(void 0===u)u=e[++a];else if(void 0===h)h=e[--l];else if(S(u,p,o.mirror,r))M(u,p,o,r),u=e[++a],p=t[++d];else if(S(h,m,o.mirror,r))M(h,m,o,r),h=e[--l],m=t[--c];else if(S(u,m,o.mirror,r)){try{n.insertBefore(u,h.nextSibling)}catch(e){console.warn(e)}M(u,m,o,r),u=e[++a],m=t[--c]}else if(S(h,p,o.mirror,r)){try{n.insertBefore(h,u)}catch(e){console.warn(e)}M(h,p,o,r),h=e[--l],p=t[++d]}else{if(!i){i={};for(let t=a;t<=l;t++){const n=e[t];n&&o.mirror.hasNode(n)&&(i[o.mirror.getId(n)]=t)}}s=i[r.getId(p)];const c=e[s];if(void 0!==s&&c&&S(c,p,o.mirror,r)){try{n.insertBefore(c,u)}catch(e){console.warn(e)}M(c,p,o,r),e[s]=void 0}else{const t=b(p,o.mirror,r);"#document"===n.nodeName&&u&&(t.nodeType===t.DOCUMENT_TYPE_NODE&&u.nodeType===u.DOCUMENT_TYPE_NODE||t.nodeType===t.ELEMENT_NODE&&u.nodeType===u.ELEMENT_NODE)&&(n.removeChild(u),o.mirror.removeNodeFromMap(u),u=e[++a]);try{n.insertBefore(t,u||null),M(t,p,o,r)}catch(e){console.warn(e)}}p=t[++d]}if(a>l){const e=t[c+1];let i=null;for(e&&(i=o.mirror.getNode(r.getId(e)));d<=c;++d){const e=b(t[d],o.mirror,r);try{n.insertBefore(e,i),M(e,t[d],o,r)}catch(e){console.warn(e)}}}else if(d>c)for(;a<=l;a++){const t=e[a];if(t&&n.contains(t))try{n.removeChild(t),o.mirror.removeNodeFromMap(t)}catch(e){console.warn(e)}}}function b(e,n,o){const r=o.getId(e),i=o.getMeta(e);let s=null;if(r>-1&&(s=n.getNode(r)),null!==s&&O(s,e))return s;switch(e.RRNodeType){case t.Document:s=new Document;break;case t.DocumentType:s=document.implementation.createDocumentType(e.name,e.publicId,e.systemId);break;case t.Element:{let t=e.tagName.toLowerCase();t=y[t]||t,s=i&&"isSVG"in i&&(null==i?void 0:i.isSVG)?document.createElementNS(g.svg,t):document.createElement(e.tagName);break}case t.Text:s=document.createTextNode(e.data);break;case t.Comment:s=document.createComment(e.data);break;case t.CDATA:s=document.createCDATASection(e.data)}i&&n.add(s,Object.assign({},i));try{null==C||C.add(s)}catch(e){}return s}function O(e,t){return e.nodeType===t.nodeType&&(e.nodeType!==e.ELEMENT_NODE||e.tagName.toUpperCase()===t.tagName)}function S(e,t,n,o){const r=n.getId(e),i=o.getId(t);return-1!==r&&r===i&&O(e,t)}class v extends(c(d)){constructor(e){super(),this.UNSERIALIZED_STARTING_ID=-2,this._unserializedId=this.UNSERIALIZED_STARTING_ID,this.mirror=P(),this.scrollData=null,e&&(this.mirror=e)}get unserializedId(){return this._unserializedId--}createDocument(e,t,n){return new v}createDocumentType(e,t,n){const o=new x(e,t,n);return o.ownerDocument=this,o}createElement(e){const t=e.toUpperCase();let n;switch(t){case"AUDIO":case"VIDEO":n=new _(t);break;case"IFRAME":n=new F(t,this.mirror);break;case"CANVAS":n=new I(t);break;case"STYLE":n=new L(t);break;default:n=new A(t)}return n.ownerDocument=this,n}createComment(e){const t=new U(e);return t.ownerDocument=this,t}createCDATASection(e){const t=new B(e);return t.ownerDocument=this,t}createTextNode(e){const t=new k(e);return t.ownerDocument=this,t}destroyTree(){this.firstChild=null,this.lastChild=null,this.mirror.reset()}open(){super.open(),this._unserializedId=this.UNSERIALIZED_STARTING_ID}}const x=u(d);class A extends(h(d)){constructor(){super(...arguments),this.inputData=null,this.scrollData=null}}class _ extends(p(A)){}class I extends A{constructor(){super(...arguments),this.rr_dataURL=null,this.canvasMutations=[]}getContext(){return null}}class L extends A{constructor(){super(...arguments),this.rules=[]}}class F extends A{constructor(e,t){super(e),this.contentDocument=new v,this.contentDocument.mirror=t}}const k=m(d),U=N(d),B=f(d);function G(t,n,o,r){let i;switch(t.nodeType){case e.NodeType.DOCUMENT_NODE:r&&"IFRAME"===r.nodeName?i=r.contentDocument:(i=n,i.compatMode=t.compatMode);break;case e.NodeType.DOCUMENT_TYPE_NODE:{const e=t;i=n.createDocumentType(e.name,e.publicId,e.systemId);break}case e.NodeType.ELEMENT_NODE:{const e=t,o=(s=e)instanceof HTMLFormElement?"FORM":s.tagName.toUpperCase();i=n.createElement(o);const r=i;for(const{name:t,value:n}of Array.from(e.attributes))r.attributes[t]=n;e.scrollLeft&&(r.scrollLeft=e.scrollLeft),e.scrollTop&&(r.scrollTop=e.scrollTop);break}case e.NodeType.TEXT_NODE:i=n.createTextNode(t.textContent||"");break;case e.NodeType.CDATA_SECTION_NODE:i=n.createCDATASection(t.data);break;case e.NodeType.COMMENT_NODE:i=n.createComment(t.textContent||"");break;case e.NodeType.DOCUMENT_FRAGMENT_NODE:i=r.attachShadow({mode:"open"});break;default:return null}var s;let a=o.getMeta(t);return n instanceof v&&(a||(a=Y(i,n.unserializedId),o.add(t,a)),n.mirror.add(i,Object.assign({},a))),i}function P(){return new $}class ${constructor(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}getId(e){var t;if(!e)return-1;const n=null===(t=this.getMeta(e))||void 0===t?void 0:t.id;return null!=n?n:-1}getNode(e){return this.idNodeMap.get(e)||null}getIds(){return Array.from(this.idNodeMap.keys())}getMeta(e){return this.nodeMetaMap.get(e)||null}removeNodeFromMap(e){const t=this.getId(e);this.idNodeMap.delete(t),e.childNodes&&e.childNodes.forEach((e=>this.removeNodeFromMap(e)))}has(e){return this.idNodeMap.has(e)}hasNode(e){return this.nodeMetaMap.has(e)}add(e,t){const n=t.id;this.idNodeMap.set(n,e),this.nodeMetaMap.set(e,t)}replace(e,t){const n=this.getNode(e);if(n){const e=this.nodeMetaMap.get(n);e&&this.nodeMetaMap.set(t,e)}this.idNodeMap.set(e,t)}reset(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}}function Y(e,n){switch(e.RRNodeType){case t.Document:return{id:n,type:e.RRNodeType,childNodes:[]};case t.DocumentType:{const t=e;return{id:n,type:e.RRNodeType,name:t.name,publicId:t.publicId,systemId:t.systemId}}case t.Element:return{id:n,type:e.RRNodeType,tagName:e.tagName.toLowerCase(),attributes:{},childNodes:[]};case t.Text:case t.Comment:return{id:n,type:e.RRNodeType,textContent:e.textContent||""};case t.CDATA:return{id:n,type:e.RRNodeType,textContent:""}}}function H(e,n,o){let r=`${o}${n.getId(e)} ${e.toString()}\n`;if(e.RRNodeType===t.Element){const t=e;t.shadowRoot&&(r+=H(t.shadowRoot,n,o+" "))}for(const t of e.childNodes)r+=H(t,n,o+" ");return"IFRAME"===e.nodeName&&(r+=H(e.contentDocument,n,o+" ")),r}return e.BaseRRCDATASectionImpl=f,e.BaseRRCommentImpl=N,e.BaseRRDocumentImpl=c,e.BaseRRDocumentTypeImpl=u,e.BaseRRElementImpl=h,e.BaseRRMediaElementImpl=p,e.BaseRRNode=d,e.BaseRRTextImpl=m,e.ClassList=E,e.Mirror=$,e.RRCDATASection=B,e.RRCanvasElement=I,e.RRComment=U,e.RRDocument=v,e.RRDocumentType=x,e.RRElement=A,e.RRIFrameElement=F,e.RRMediaElement=_,e.RRNode=d,e.RRStyleElement=L,e.RRText=k,e.buildFromDom=function(t,o=function(){return new n}(),r=new v){return function t(n,i){const s=G(n,r,o,i);if(null!==s)if("IFRAME"!==(null==i?void 0:i.nodeName)&&n.nodeType!==e.NodeType.DOCUMENT_FRAGMENT_NODE&&(null==i||i.appendChild(s),s.parentNode=i,s.parentElement=i),"IFRAME"===n.nodeName){const e=n.contentDocument;e&&t(e,s)}else n.nodeType!==e.NodeType.DOCUMENT_NODE&&n.nodeType!==e.NodeType.ELEMENT_NODE&&n.nodeType!==e.NodeType.DOCUMENT_FRAGMENT_NODE||(n.nodeType===e.NodeType.ELEMENT_NODE&&n.shadowRoot&&t(n.shadowRoot,s),n.childNodes.forEach((e=>t(e,s))))}(t,null),r},e.buildFromNode=G,e.createMirror=P,e.createOrGetNode=b,e.diff=M,e.getDefaultSN=Y,e.printRRDom=function(e,t){return H(e,t,"")},Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
//# sourceMappingURL=rrdom.min.js.map |
@@ -11,4 +11,7 @@ import { Mirror as NodeMirror } from 'rrweb-snapshot'; | ||
applyStyleSheetMutation: (data: styleDeclarationData | styleSheetRuleData, styleSheet: CSSStyleSheet) => void; | ||
afterAppend?(node: Node, id: number): void; | ||
}; | ||
export declare function diff(oldTree: Node, newTree: IRRNode, replayer: ReplayerHandler, rrnodeMirror?: Mirror): void; | ||
export declare function createOrGetNode(rrNode: IRRNode, domMirror: NodeMirror, rrnodeMirror: Mirror): Node; | ||
export declare function sameNodeType(node1: Node, node2: IRRNode): boolean; | ||
export declare function nodeMatching(node1: Node, node2: IRRNode, domMirror: NodeMirror, rrdomMirror: Mirror): boolean; |
@@ -5,4 +5,4 @@ import { NodeType as RRNodeType } from 'rrweb-snapshot'; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -15,2 +15,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -79,7 +80,10 @@ textContent: string | null; | ||
export declare class BaseRRNode implements IRRNode { | ||
childNodes: IRRNode[]; | ||
parentElement: IRRNode | null; | ||
parentNode: IRRNode | null; | ||
ownerDocument: IRRDocument; | ||
firstChild: IRRNode | null; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
ownerDocument: IRRDocument; | ||
readonly ELEMENT_NODE: number; | ||
@@ -91,5 +95,3 @@ readonly TEXT_NODE: number; | ||
constructor(..._args: any[]); | ||
get firstChild(): IRRNode | null; | ||
get lastChild(): IRRNode | null; | ||
get nextSibling(): IRRNode | null; | ||
get childNodes(): IRRNode[]; | ||
contains(node: IRRNode): boolean; | ||
@@ -107,3 +109,2 @@ appendChild(_newChild: IRRNode): IRRNode; | ||
readonly RRNodeType: RRNodeType.Document; | ||
textContent: string | null; | ||
readonly documentElement: IRRElement | null; | ||
@@ -114,3 +115,3 @@ readonly body: IRRElement | null; | ||
readonly firstElementChild: IRRElement | null; | ||
appendChild(childNode: IRRNode): IRRNode; | ||
appendChild(newChild: IRRNode): IRRNode; | ||
insertBefore(newChild: IRRNode, refChild: IRRNode | null): IRRNode; | ||
@@ -131,4 +132,4 @@ removeChild(node: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -138,3 +139,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -151,8 +154,7 @@ }; | ||
readonly systemId: string; | ||
textContent: string | null; | ||
toString(): string; | ||
parentElement: IRRNode | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -162,3 +164,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -197,4 +201,4 @@ appendChild(newChild: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -204,2 +208,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -235,4 +240,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -245,2 +250,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -265,4 +271,4 @@ textContent: string | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -272,2 +278,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -290,4 +297,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -297,2 +304,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -315,4 +323,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -322,2 +330,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -324,0 +333,0 @@ contains(node: IRRNode): boolean; |
@@ -11,3 +11,2 @@ import { NodeType as RRNodeType } from 'rrweb-snapshot'; | ||
readonly RRNodeType: RRNodeType.Document; | ||
textContent: string | null; | ||
readonly documentElement: IRRElement | null; | ||
@@ -18,3 +17,3 @@ readonly body: IRRElement | null; | ||
readonly firstElementChild: IRRElement | null; | ||
appendChild(childNode: IRRNode): IRRNode; | ||
appendChild(newChild: IRRNode): IRRNode; | ||
insertBefore(newChild: IRRNode, refChild: IRRNode | null): IRRNode; | ||
@@ -35,4 +34,4 @@ removeChild(node: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -42,3 +41,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -62,8 +63,7 @@ }; | ||
readonly systemId: string; | ||
textContent: string | null; | ||
toString(): string; | ||
parentElement: IRRNode | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -73,3 +73,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -91,4 +93,4 @@ appendChild(newChild: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -98,2 +100,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -114,4 +117,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -121,2 +124,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -137,4 +141,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -144,2 +148,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -162,8 +167,7 @@ contains(node: IRRNode): boolean; | ||
readonly systemId: string; | ||
textContent: string | null; | ||
toString(): string; | ||
parentElement: IRRNode | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -173,3 +177,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -208,4 +214,4 @@ appendChild(newChild: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -215,2 +221,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -250,4 +257,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -260,2 +267,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -297,4 +305,4 @@ textContent: string | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -304,2 +312,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -323,4 +332,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -330,2 +339,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -349,4 +359,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -356,2 +366,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -358,0 +369,0 @@ contains(node: IRRNode): boolean; |
414
es/rrdom.js
@@ -112,28 +112,31 @@ var NodeType$1; | ||
constructor(..._args) { | ||
this.childNodes = []; | ||
this.parentElement = null; | ||
this.parentNode = null; | ||
this.firstChild = null; | ||
this.lastChild = null; | ||
this.previousSibling = null; | ||
this.nextSibling = null; | ||
this.ELEMENT_NODE = NodeType.ELEMENT_NODE; | ||
this.TEXT_NODE = NodeType.TEXT_NODE; | ||
} | ||
get firstChild() { | ||
return this.childNodes[0] || null; | ||
get childNodes() { | ||
const childNodes = []; | ||
let childIterator = this.firstChild; | ||
while (childIterator) { | ||
childNodes.push(childIterator); | ||
childIterator = childIterator.nextSibling; | ||
} | ||
return childNodes; | ||
} | ||
get lastChild() { | ||
return this.childNodes[this.childNodes.length - 1] || null; | ||
} | ||
get nextSibling() { | ||
const parentNode = this.parentNode; | ||
if (!parentNode) | ||
return null; | ||
const siblings = parentNode.childNodes; | ||
const index = siblings.indexOf(this); | ||
return siblings[index + 1] || null; | ||
} | ||
contains(node) { | ||
if (node === this) | ||
if (!(node instanceof BaseRRNode)) | ||
return false; | ||
else if (node.ownerDocument !== this.ownerDocument) | ||
return false; | ||
else if (node === this) | ||
return true; | ||
for (const child of this.childNodes) { | ||
if (child.contains(node)) | ||
while (node.parentNode) { | ||
if (node.parentNode === this) | ||
return true; | ||
node = node.parentNode; | ||
} | ||
@@ -157,4 +160,4 @@ return false; | ||
return class BaseRRDocument extends RRNodeClass { | ||
constructor() { | ||
super(...arguments); | ||
constructor(...args) { | ||
super(args); | ||
this.nodeType = NodeType.DOCUMENT_NODE; | ||
@@ -165,2 +168,3 @@ this.nodeName = '#document'; | ||
this.textContent = null; | ||
this.ownerDocument = this; | ||
} | ||
@@ -187,4 +191,4 @@ get documentElement() { | ||
} | ||
appendChild(childNode) { | ||
const nodeType = childNode.RRNodeType; | ||
appendChild(newChild) { | ||
const nodeType = newChild.RRNodeType; | ||
if (nodeType === NodeType$1.Element || | ||
@@ -196,6 +200,5 @@ nodeType === NodeType$1.DocumentType) { | ||
} | ||
childNode.parentElement = null; | ||
childNode.parentNode = this; | ||
this.childNodes.push(childNode); | ||
return childNode; | ||
const child = appendChild(this, newChild); | ||
child.parentElement = null; | ||
return child; | ||
} | ||
@@ -210,23 +213,12 @@ insertBefore(newChild, refChild) { | ||
} | ||
if (refChild === null) | ||
return this.appendChild(newChild); | ||
const childIndex = this.childNodes.indexOf(refChild); | ||
if (childIndex == -1) | ||
throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode."); | ||
this.childNodes.splice(childIndex, 0, newChild); | ||
newChild.parentElement = null; | ||
newChild.parentNode = this; | ||
return newChild; | ||
const child = insertBefore(this, newChild, refChild); | ||
child.parentElement = null; | ||
return child; | ||
} | ||
removeChild(node) { | ||
const indexOfChild = this.childNodes.indexOf(node); | ||
if (indexOfChild === -1) | ||
throw new Error("Failed to execute 'removeChild' on 'RRDocument': The RRNode to be removed is not a child of this RRNode."); | ||
this.childNodes.splice(indexOfChild, 1); | ||
node.parentElement = null; | ||
node.parentNode = null; | ||
return node; | ||
return removeChild(this, node); | ||
} | ||
open() { | ||
this.childNodes = []; | ||
this.firstChild = null; | ||
this.lastChild = null; | ||
} | ||
@@ -291,3 +283,2 @@ close() { | ||
this.RRNodeType = NodeType$1.DocumentType; | ||
this.textContent = null; | ||
this.name = qualifiedName; | ||
@@ -297,2 +288,3 @@ this.publicId = publicId; | ||
this.nodeName = qualifiedName; | ||
this.textContent = null; | ||
} | ||
@@ -321,3 +313,5 @@ toString() { | ||
set textContent(textContent) { | ||
this.childNodes = [this.ownerDocument.createTextNode(textContent)]; | ||
this.firstChild = null; | ||
this.lastChild = null; | ||
this.appendChild(this.ownerDocument.createTextNode(textContent)); | ||
} | ||
@@ -336,5 +330,3 @@ get classList() { | ||
get style() { | ||
const style = (this.attributes.style | ||
? parseCSSText(this.attributes.style) | ||
: {}); | ||
const style = (this.attributes.style ? parseCSSText(this.attributes.style) : {}); | ||
const hyphenateRE = /\B([A-Z])/g; | ||
@@ -377,26 +369,9 @@ style.setProperty = (name, value, priority) => { | ||
appendChild(newChild) { | ||
this.childNodes.push(newChild); | ||
newChild.parentNode = this; | ||
newChild.parentElement = this; | ||
return newChild; | ||
return appendChild(this, newChild); | ||
} | ||
insertBefore(newChild, refChild) { | ||
if (refChild === null) | ||
return this.appendChild(newChild); | ||
const childIndex = this.childNodes.indexOf(refChild); | ||
if (childIndex == -1) | ||
throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode."); | ||
this.childNodes.splice(childIndex, 0, newChild); | ||
newChild.parentElement = this; | ||
newChild.parentNode = this; | ||
return newChild; | ||
return insertBefore(this, newChild, refChild); | ||
} | ||
removeChild(node) { | ||
const indexOfChild = this.childNodes.indexOf(node); | ||
if (indexOfChild === -1) | ||
throw new Error("Failed to execute 'removeChild' on 'RRElement': The RRNode to be removed is not a child of this RRNode."); | ||
this.childNodes.splice(indexOfChild, 1); | ||
node.parentElement = null; | ||
node.parentNode = null; | ||
return node; | ||
return removeChild(this, node); | ||
} | ||
@@ -516,2 +491,52 @@ attachShadow(_init) { | ||
} | ||
function appendChild(parent, newChild) { | ||
if (parent.lastChild) { | ||
parent.lastChild.nextSibling = newChild; | ||
newChild.previousSibling = parent.lastChild; | ||
} | ||
else { | ||
parent.firstChild = newChild; | ||
newChild.previousSibling = null; | ||
} | ||
parent.lastChild = newChild; | ||
newChild.nextSibling = null; | ||
newChild.parentNode = parent; | ||
newChild.parentElement = parent; | ||
newChild.ownerDocument = parent.ownerDocument; | ||
return newChild; | ||
} | ||
function insertBefore(parent, newChild, refChild) { | ||
if (!refChild) | ||
return appendChild(parent, newChild); | ||
if (refChild.parentNode !== parent) | ||
throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode."); | ||
newChild.previousSibling = refChild.previousSibling; | ||
refChild.previousSibling = newChild; | ||
newChild.nextSibling = refChild; | ||
if (newChild.previousSibling) | ||
newChild.previousSibling.nextSibling = newChild; | ||
else | ||
parent.firstChild = newChild; | ||
newChild.parentElement = parent; | ||
newChild.parentNode = parent; | ||
newChild.ownerDocument = parent.ownerDocument; | ||
return newChild; | ||
} | ||
function removeChild(parent, child) { | ||
if (child.parentNode !== parent) | ||
throw new Error("Failed to execute 'removeChild' on 'RRNode': The RRNode to be removed is not a child of this RRNode."); | ||
if (child.previousSibling) | ||
child.previousSibling.nextSibling = child.nextSibling; | ||
else | ||
parent.firstChild = child.nextSibling; | ||
if (child.nextSibling) | ||
child.nextSibling.previousSibling = child.previousSibling; | ||
else | ||
parent.lastChild = child.previousSibling; | ||
child.previousSibling = null; | ||
child.nextSibling = null; | ||
child.parentElement = null; | ||
child.parentNode = null; | ||
return child; | ||
} | ||
var NodeType; | ||
@@ -576,17 +601,38 @@ (function (NodeType) { | ||
}; | ||
function diff(oldTree, newTree, replayer, rrnodeMirror) { | ||
let createdNodeSet = null; | ||
function diff(oldTree, newTree, replayer, rrnodeMirror = newTree.mirror || | ||
newTree.ownerDocument.mirror) { | ||
oldTree = diffBeforeUpdatingChildren(oldTree, newTree, replayer, rrnodeMirror); | ||
const oldChildren = oldTree.childNodes; | ||
const newChildren = newTree.childNodes; | ||
rrnodeMirror = | ||
rrnodeMirror || | ||
newTree.mirror || | ||
newTree.ownerDocument.mirror; | ||
if (oldChildren.length > 0 || newChildren.length > 0) { | ||
diffChildren(Array.from(oldChildren), newChildren, oldTree, replayer, rrnodeMirror); | ||
} | ||
let inputDataToApply = null, scrollDataToApply = null; | ||
diffAfterUpdatingChildren(oldTree, newTree, replayer, rrnodeMirror); | ||
} | ||
function diffBeforeUpdatingChildren(oldTree, newTree, replayer, rrnodeMirror) { | ||
var _a; | ||
if (replayer.afterAppend && !createdNodeSet) { | ||
createdNodeSet = new WeakSet(); | ||
setTimeout(() => { | ||
createdNodeSet = null; | ||
}, 0); | ||
} | ||
if (!sameNodeType(oldTree, newTree)) { | ||
const calibratedOldTree = createOrGetNode(newTree, replayer.mirror, rrnodeMirror); | ||
(_a = oldTree.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(calibratedOldTree, oldTree); | ||
oldTree = calibratedOldTree; | ||
} | ||
switch (newTree.RRNodeType) { | ||
case NodeType$1.Document: { | ||
const newRRDocument = newTree; | ||
scrollDataToApply = newRRDocument.scrollData; | ||
if (!nodeMatching(oldTree, newTree, replayer.mirror, rrnodeMirror)) { | ||
const newMeta = rrnodeMirror.getMeta(newTree); | ||
if (newMeta) { | ||
replayer.mirror.removeNodeFromMap(oldTree); | ||
oldTree.close(); | ||
oldTree.open(); | ||
replayer.mirror.add(oldTree, newMeta); | ||
createdNodeSet === null || createdNodeSet === void 0 ? void 0 : createdNodeSet.add(oldTree); | ||
} | ||
} | ||
break; | ||
@@ -597,5 +643,40 @@ } | ||
const newRRElement = newTree; | ||
switch (newRRElement.tagName) { | ||
case 'IFRAME': { | ||
const oldContentDocument = oldTree | ||
.contentDocument; | ||
if (!oldContentDocument) | ||
break; | ||
diff(oldContentDocument, newTree.contentDocument, replayer, rrnodeMirror); | ||
break; | ||
} | ||
} | ||
if (newRRElement.shadowRoot) { | ||
if (!oldElement.shadowRoot) | ||
oldElement.attachShadow({ mode: 'open' }); | ||
const oldChildren = oldElement.shadowRoot.childNodes; | ||
const newChildren = newRRElement.shadowRoot.childNodes; | ||
if (oldChildren.length > 0 || newChildren.length > 0) | ||
diffChildren(Array.from(oldChildren), newChildren, oldElement.shadowRoot, replayer, rrnodeMirror); | ||
} | ||
break; | ||
} | ||
} | ||
return oldTree; | ||
} | ||
function diffAfterUpdatingChildren(oldTree, newTree, replayer, rrnodeMirror) { | ||
var _a; | ||
switch (newTree.RRNodeType) { | ||
case NodeType$1.Document: { | ||
const scrollData = newTree.scrollData; | ||
scrollData && replayer.applyScroll(scrollData, true); | ||
break; | ||
} | ||
case NodeType$1.Element: { | ||
const oldElement = oldTree; | ||
const newRRElement = newTree; | ||
diffProps(oldElement, newRRElement, rrnodeMirror); | ||
scrollDataToApply = newRRElement.scrollData; | ||
inputDataToApply = newRRElement.inputData; | ||
newRRElement.scrollData && | ||
replayer.applyScroll(newRRElement.scrollData, true); | ||
newRRElement.inputData && replayer.applyInput(newRRElement.inputData); | ||
switch (newRRElement.tagName) { | ||
@@ -620,34 +701,24 @@ case 'AUDIO': | ||
} | ||
case 'CANVAS': | ||
{ | ||
const rrCanvasElement = newTree; | ||
if (rrCanvasElement.rr_dataURL !== null) { | ||
const image = document.createElement('img'); | ||
image.onload = () => { | ||
const ctx = oldElement.getContext('2d'); | ||
if (ctx) { | ||
ctx.drawImage(image, 0, 0, image.width, image.height); | ||
} | ||
}; | ||
image.src = rrCanvasElement.rr_dataURL; | ||
} | ||
rrCanvasElement.canvasMutations.forEach((canvasMutation) => replayer.applyCanvas(canvasMutation.event, canvasMutation.mutation, oldTree)); | ||
case 'CANVAS': { | ||
const rrCanvasElement = newTree; | ||
if (rrCanvasElement.rr_dataURL !== null) { | ||
const image = document.createElement('img'); | ||
image.onload = () => { | ||
const ctx = oldElement.getContext('2d'); | ||
if (ctx) { | ||
ctx.drawImage(image, 0, 0, image.width, image.height); | ||
} | ||
}; | ||
image.src = rrCanvasElement.rr_dataURL; | ||
} | ||
rrCanvasElement.canvasMutations.forEach((canvasMutation) => replayer.applyCanvas(canvasMutation.event, canvasMutation.mutation, oldTree)); | ||
break; | ||
case 'STYLE': | ||
{ | ||
const styleSheet = oldElement.sheet; | ||
styleSheet && | ||
newTree.rules.forEach((data) => replayer.applyStyleSheetMutation(data, styleSheet)); | ||
} | ||
} | ||
case 'STYLE': { | ||
const styleSheet = oldElement.sheet; | ||
styleSheet && | ||
newTree.rules.forEach((data) => replayer.applyStyleSheetMutation(data, styleSheet)); | ||
break; | ||
} | ||
} | ||
if (newRRElement.shadowRoot) { | ||
if (!oldElement.shadowRoot) | ||
oldElement.attachShadow({ mode: 'open' }); | ||
const oldChildren = oldElement.shadowRoot.childNodes; | ||
const newChildren = newRRElement.shadowRoot.childNodes; | ||
if (oldChildren.length > 0 || newChildren.length > 0) | ||
diffChildren(Array.from(oldChildren), newChildren, oldElement.shadowRoot, replayer, rrnodeMirror); | ||
} | ||
break; | ||
@@ -657,3 +728,3 @@ } | ||
case NodeType$1.Comment: | ||
case NodeType$1.CDATA: | ||
case NodeType$1.CDATA: { | ||
if (oldTree.textContent !== | ||
@@ -663,16 +734,8 @@ newTree.data) | ||
break; | ||
} | ||
scrollDataToApply && replayer.applyScroll(scrollDataToApply, true); | ||
inputDataToApply && replayer.applyInput(inputDataToApply); | ||
if (newTree.nodeName === 'IFRAME') { | ||
const oldContentDocument = oldTree.contentDocument; | ||
const newIFrameElement = newTree; | ||
if (oldContentDocument) { | ||
const sn = rrnodeMirror.getMeta(newIFrameElement.contentDocument); | ||
if (sn) { | ||
replayer.mirror.add(oldContentDocument, Object.assign({}, sn)); | ||
} | ||
diff(oldContentDocument, newIFrameElement.contentDocument, replayer, rrnodeMirror); | ||
} | ||
} | ||
if (createdNodeSet === null || createdNodeSet === void 0 ? void 0 : createdNodeSet.has(oldTree)) { | ||
createdNodeSet.delete(oldTree); | ||
(_a = replayer.afterAppend) === null || _a === void 0 ? void 0 : _a.call(replayer, oldTree, replayer.mirror.getId(oldTree)); | ||
} | ||
} | ||
@@ -685,3 +748,3 @@ function diffProps(oldTree, newTree, rrnodeMirror) { | ||
const sn = rrnodeMirror.getMeta(newTree); | ||
if (sn && 'isSVG' in sn && sn.isSVG && NAMESPACES[name]) | ||
if ((sn === null || sn === void 0 ? void 0 : sn.isSVG) && NAMESPACES[name]) | ||
oldTree.setAttributeNS(NAMESPACES[name], name, newValue); | ||
@@ -708,11 +771,6 @@ else if (newTree.tagName === 'CANVAS' && name === 'rr_dataURL') { | ||
function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirror) { | ||
var _a; | ||
let oldStartIndex = 0, oldEndIndex = oldChildren.length - 1, newStartIndex = 0, newEndIndex = newChildren.length - 1; | ||
let oldStartNode = oldChildren[oldStartIndex], oldEndNode = oldChildren[oldEndIndex], newStartNode = newChildren[newStartIndex], newEndNode = newChildren[newEndIndex]; | ||
let oldIdToIndex = undefined, indexInOld; | ||
let oldIdToIndex = undefined, indexInOld = undefined; | ||
while (oldStartIndex <= oldEndIndex && newStartIndex <= newEndIndex) { | ||
const oldStartId = replayer.mirror.getId(oldStartNode); | ||
const oldEndId = replayer.mirror.getId(oldEndNode); | ||
const newStartId = rrnodeMirror.getId(newStartNode); | ||
const newEndId = rrnodeMirror.getId(newEndNode); | ||
if (oldStartNode === undefined) { | ||
@@ -724,4 +782,3 @@ oldStartNode = oldChildren[++oldStartIndex]; | ||
} | ||
else if (oldStartId !== -1 && | ||
oldStartId === newStartId) { | ||
else if (nodeMatching(oldStartNode, newStartNode, replayer.mirror, rrnodeMirror)) { | ||
diff(oldStartNode, newStartNode, replayer, rrnodeMirror); | ||
@@ -731,4 +788,3 @@ oldStartNode = oldChildren[++oldStartIndex]; | ||
} | ||
else if (oldEndId !== -1 && | ||
oldEndId === newEndId) { | ||
else if (nodeMatching(oldEndNode, newEndNode, replayer.mirror, rrnodeMirror)) { | ||
diff(oldEndNode, newEndNode, replayer, rrnodeMirror); | ||
@@ -738,5 +794,9 @@ oldEndNode = oldChildren[--oldEndIndex]; | ||
} | ||
else if (oldStartId !== -1 && | ||
oldStartId === newEndId) { | ||
parentNode.insertBefore(oldStartNode, oldEndNode.nextSibling); | ||
else if (nodeMatching(oldStartNode, newEndNode, replayer.mirror, rrnodeMirror)) { | ||
try { | ||
parentNode.insertBefore(oldStartNode, oldEndNode.nextSibling); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
} | ||
diff(oldStartNode, newEndNode, replayer, rrnodeMirror); | ||
@@ -746,5 +806,9 @@ oldStartNode = oldChildren[++oldStartIndex]; | ||
} | ||
else if (oldEndId !== -1 && | ||
oldEndId === newStartId) { | ||
parentNode.insertBefore(oldEndNode, oldStartNode); | ||
else if (nodeMatching(oldEndNode, newStartNode, replayer.mirror, rrnodeMirror)) { | ||
try { | ||
parentNode.insertBefore(oldEndNode, oldStartNode); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
} | ||
diff(oldEndNode, newStartNode, replayer, rrnodeMirror); | ||
@@ -764,5 +828,12 @@ oldEndNode = oldChildren[--oldEndIndex]; | ||
indexInOld = oldIdToIndex[rrnodeMirror.getId(newStartNode)]; | ||
if (indexInOld) { | ||
const nodeToMove = oldChildren[indexInOld]; | ||
parentNode.insertBefore(nodeToMove, oldStartNode); | ||
const nodeToMove = oldChildren[indexInOld]; | ||
if (indexInOld !== undefined && | ||
nodeToMove && | ||
nodeMatching(nodeToMove, newStartNode, replayer.mirror, rrnodeMirror)) { | ||
try { | ||
parentNode.insertBefore(nodeToMove, oldStartNode); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
} | ||
diff(nodeToMove, newStartNode, replayer, rrnodeMirror); | ||
@@ -774,10 +845,18 @@ oldChildren[indexInOld] = undefined; | ||
if (parentNode.nodeName === '#document' && | ||
((_a = replayer.mirror.getMeta(newNode)) === null || _a === void 0 ? void 0 : _a.type) === NodeType$1.Element && | ||
parentNode.documentElement) { | ||
parentNode.removeChild(parentNode.documentElement); | ||
oldChildren[oldStartIndex] = undefined; | ||
oldStartNode = undefined; | ||
oldStartNode && | ||
((newNode.nodeType === newNode.DOCUMENT_TYPE_NODE && | ||
oldStartNode.nodeType === oldStartNode.DOCUMENT_TYPE_NODE) || | ||
(newNode.nodeType === newNode.ELEMENT_NODE && | ||
oldStartNode.nodeType === oldStartNode.ELEMENT_NODE))) { | ||
parentNode.removeChild(oldStartNode); | ||
replayer.mirror.removeNodeFromMap(oldStartNode); | ||
oldStartNode = oldChildren[++oldStartIndex]; | ||
} | ||
parentNode.insertBefore(newNode, oldStartNode || null); | ||
diff(newNode, newStartNode, replayer, rrnodeMirror); | ||
try { | ||
parentNode.insertBefore(newNode, oldStartNode || null); | ||
diff(newNode, newStartNode, replayer, rrnodeMirror); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
} | ||
} | ||
@@ -791,10 +870,12 @@ newStartNode = newChildren[++newStartIndex]; | ||
if (referenceRRNode) | ||
parentNode.childNodes.forEach((child) => { | ||
if (replayer.mirror.getId(child) === rrnodeMirror.getId(referenceRRNode)) | ||
referenceNode = child; | ||
}); | ||
referenceNode = replayer.mirror.getNode(rrnodeMirror.getId(referenceRRNode)); | ||
for (; newStartIndex <= newEndIndex; ++newStartIndex) { | ||
const newNode = createOrGetNode(newChildren[newStartIndex], replayer.mirror, rrnodeMirror); | ||
parentNode.insertBefore(newNode, referenceNode); | ||
diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror); | ||
try { | ||
parentNode.insertBefore(newNode, referenceNode); | ||
diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
} | ||
} | ||
@@ -805,6 +886,11 @@ } | ||
const node = oldChildren[oldStartIndex]; | ||
if (node) { | ||
if (!node || !parentNode.contains(node)) | ||
continue; | ||
try { | ||
parentNode.removeChild(node); | ||
replayer.mirror.removeNodeFromMap(node); | ||
} | ||
catch (e) { | ||
console.warn(e); | ||
} | ||
} | ||
@@ -819,3 +905,3 @@ } | ||
node = domMirror.getNode(nodeId); | ||
if (node !== null) | ||
if (node !== null && sameNodeType(node, rrNode)) | ||
return node; | ||
@@ -851,4 +937,23 @@ switch (rrNode.RRNodeType) { | ||
domMirror.add(node, Object.assign({}, sn)); | ||
try { | ||
createdNodeSet === null || createdNodeSet === void 0 ? void 0 : createdNodeSet.add(node); | ||
} | ||
catch (e) { | ||
} | ||
return node; | ||
} | ||
function sameNodeType(node1, node2) { | ||
if (node1.nodeType !== node2.nodeType) | ||
return false; | ||
return (node1.nodeType !== node1.ELEMENT_NODE || | ||
node1.tagName.toUpperCase() === | ||
node2.tagName); | ||
} | ||
function nodeMatching(node1, node2, domMirror, rrdomMirror) { | ||
const node1Id = domMirror.getId(node1); | ||
const node2Id = rrdomMirror.getId(node2); | ||
if (node1Id === -1 || node1Id !== node2Id) | ||
return false; | ||
return sameNodeType(node1, node2); | ||
} | ||
@@ -917,3 +1022,4 @@ class RRDocument extends BaseRRDocumentImpl(BaseRRNode) { | ||
destroyTree() { | ||
this.childNodes = []; | ||
this.firstChild = null; | ||
this.lastChild = null; | ||
this.mirror.reset(); | ||
@@ -920,0 +1026,0 @@ } |
@@ -1,2 +0,2 @@ | ||
var e;!function(e){e[e.Document=0]="Document",e[e.DocumentType=1]="DocumentType",e[e.Element=2]="Element",e[e.Text=3]="Text",e[e.CDATA=4]="CDATA",e[e.Comment=5]="Comment"}(e||(e={}));var t=function(){function e(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}return e.prototype.getId=function(e){var t;if(!e)return-1;var n=null===(t=this.getMeta(e))||void 0===t?void 0:t.id;return null!=n?n:-1},e.prototype.getNode=function(e){return this.idNodeMap.get(e)||null},e.prototype.getIds=function(){return Array.from(this.idNodeMap.keys())},e.prototype.getMeta=function(e){return this.nodeMetaMap.get(e)||null},e.prototype.removeNodeFromMap=function(e){var t=this,n=this.getId(e);this.idNodeMap.delete(n),e.childNodes&&e.childNodes.forEach((function(e){return t.removeNodeFromMap(e)}))},e.prototype.has=function(e){return this.idNodeMap.has(e)},e.prototype.hasNode=function(e){return this.nodeMetaMap.has(e)},e.prototype.add=function(e,t){var n=t.id;this.idNodeMap.set(n,e),this.nodeMetaMap.set(e,t)},e.prototype.replace=function(e,t){var n=this.getNode(e);if(n){var o=this.nodeMetaMap.get(n);o&&this.nodeMetaMap.set(t,o)}this.idNodeMap.set(e,t)},e.prototype.reset=function(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap},e}();function n(e){const t=[];for(const n in e){const o=e[n];if("string"!=typeof o)continue;const s=a(n);t.push(`${s}: ${o};`)}return t.join(" ")}const o=/-([a-z])/g,s=/^--[a-zA-Z0-9-]+$/,r=e=>s.test(e)?e:e.replace(o,((e,t)=>t?t.toUpperCase():"")),i=/\B([A-Z])/g,a=e=>e.replace(i,"-$1").toLowerCase();class d{constructor(...e){this.childNodes=[],this.parentElement=null,this.parentNode=null,this.ELEMENT_NODE=E.ELEMENT_NODE,this.TEXT_NODE=E.TEXT_NODE}get firstChild(){return this.childNodes[0]||null}get lastChild(){return this.childNodes[this.childNodes.length-1]||null}get nextSibling(){const e=this.parentNode;if(!e)return null;const t=e.childNodes,n=t.indexOf(this);return t[n+1]||null}contains(e){if(e===this)return!0;for(const t of this.childNodes)if(t.contains(e))return!0;return!1}appendChild(e){throw new Error("RRDomException: Failed to execute 'appendChild' on 'RRNode': This RRNode type does not support this method.")}insertBefore(e,t){throw new Error("RRDomException: Failed to execute 'insertBefore' on 'RRNode': This RRNode type does not support this method.")}removeChild(e){throw new Error("RRDomException: Failed to execute 'removeChild' on 'RRNode': This RRNode type does not support this method.")}toString(){return"RRNode"}}function c(t){return class n extends t{constructor(){super(...arguments),this.nodeType=E.DOCUMENT_NODE,this.nodeName="#document",this.compatMode="CSS1Compat",this.RRNodeType=e.Document,this.textContent=null}get documentElement(){return this.childNodes.find((t=>t.RRNodeType===e.Element&&"HTML"===t.tagName))||null}get body(){var t;return(null===(t=this.documentElement)||void 0===t?void 0:t.childNodes.find((t=>t.RRNodeType===e.Element&&"BODY"===t.tagName)))||null}get head(){var t;return(null===(t=this.documentElement)||void 0===t?void 0:t.childNodes.find((t=>t.RRNodeType===e.Element&&"HEAD"===t.tagName)))||null}get implementation(){return this}get firstElementChild(){return this.documentElement}appendChild(t){const n=t.RRNodeType;if((n===e.Element||n===e.DocumentType)&&this.childNodes.some((e=>e.RRNodeType===n)))throw new Error(`RRDomException: Failed to execute 'appendChild' on 'RRNode': Only one ${n===e.Element?"RRElement":"RRDoctype"} on RRDocument allowed.`);return t.parentElement=null,t.parentNode=this,this.childNodes.push(t),t}insertBefore(t,n){const o=t.RRNodeType;if((o===e.Element||o===e.DocumentType)&&this.childNodes.some((e=>e.RRNodeType===o)))throw new Error(`RRDomException: Failed to execute 'insertBefore' on 'RRNode': Only one ${o===e.Element?"RRElement":"RRDoctype"} on RRDocument allowed.`);if(null===n)return this.appendChild(t);const s=this.childNodes.indexOf(n);if(-1==s)throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode.");return this.childNodes.splice(s,0,t),t.parentElement=null,t.parentNode=this,t}removeChild(e){const t=this.childNodes.indexOf(e);if(-1===t)throw new Error("Failed to execute 'removeChild' on 'RRDocument': The RRNode to be removed is not a child of this RRNode.");return this.childNodes.splice(t,1),e.parentElement=null,e.parentNode=null,e}open(){this.childNodes=[]}close(){}write(e){let t;if('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">'===e?t="-//W3C//DTD XHTML 1.0 Transitional//EN":'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">'===e&&(t="-//W3C//DTD HTML 4.0 Transitional//EN"),t){const e=this.createDocumentType("html",t,"");this.open(),this.appendChild(e)}}createDocument(e,t,o){return new n}createDocumentType(e,t,n){const o=new(l(d))(e,t,n);return o.ownerDocument=this,o}createElement(e){const t=new(h(d))(e);return t.ownerDocument=this,t}createElementNS(e,t){return this.createElement(t)}createTextNode(e){const t=new(p(d))(e);return t.ownerDocument=this,t}createComment(e){const t=new(m(d))(e);return t.ownerDocument=this,t}createCDATASection(e){const t=new(N(d))(e);return t.ownerDocument=this,t}toString(){return"RRDocument"}}}function l(t){return class extends t{constructor(t,n,o){super(),this.nodeType=E.DOCUMENT_TYPE_NODE,this.RRNodeType=e.DocumentType,this.textContent=null,this.name=t,this.publicId=n,this.systemId=o,this.nodeName=t}toString(){return"RRDocumentType"}}}function h(t){return class extends t{constructor(t){super(),this.nodeType=E.ELEMENT_NODE,this.RRNodeType=e.Element,this.attributes={},this.shadowRoot=null,this.tagName=t.toUpperCase(),this.nodeName=t.toUpperCase()}get textContent(){let e="";return this.childNodes.forEach((t=>e+=t.textContent)),e}set textContent(e){this.childNodes=[this.ownerDocument.createTextNode(e)]}get classList(){return new f(this.attributes.class,(e=>{this.attributes.class=e}))}get id(){return this.attributes.id||""}get className(){return this.attributes.class||""}get style(){const e=this.attributes.style?function(e){const t={},n=/:(.+)/;return e.replace(/\/\*.*?\*\//g,"").split(/;(?![^(]*\))/g).forEach((function(e){if(e){const o=e.split(n);o.length>1&&(t[r(o[0].trim())]=o[1].trim())}})),t}(this.attributes.style):{},t=/\B([A-Z])/g;return e.setProperty=(o,s,i)=>{if(t.test(o))return;const a=r(o);s?e[a]=s:delete e[a],"important"===i&&(e[a]+=" !important"),this.attributes.style=n(e)},e.removeProperty=o=>{if(t.test(o))return"";const s=r(o),i=e[s]||"";return delete e[s],this.attributes.style=n(e),i},e}getAttribute(e){return this.attributes[e]||null}setAttribute(e,t){this.attributes[e]=t}setAttributeNS(e,t,n){this.setAttribute(t,n)}removeAttribute(e){delete this.attributes[e]}appendChild(e){return this.childNodes.push(e),e.parentNode=this,e.parentElement=this,e}insertBefore(e,t){if(null===t)return this.appendChild(e);const n=this.childNodes.indexOf(t);if(-1==n)throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode.");return this.childNodes.splice(n,0,e),e.parentElement=this,e.parentNode=this,e}removeChild(e){const t=this.childNodes.indexOf(e);if(-1===t)throw new Error("Failed to execute 'removeChild' on 'RRElement': The RRNode to be removed is not a child of this RRNode.");return this.childNodes.splice(t,1),e.parentElement=null,e.parentNode=null,e}attachShadow(e){const t=this.ownerDocument.createElement("SHADOWROOT");return this.shadowRoot=t,t}dispatchEvent(e){return!0}toString(){let e="";for(const t in this.attributes)e+=`${t}="${this.attributes[t]}" `;return`${this.tagName} ${e}`}}}function u(e){return class extends e{attachShadow(e){throw new Error("RRDomException: Failed to execute 'attachShadow' on 'RRElement': This RRElement does not support attachShadow")}play(){this.paused=!1}pause(){this.paused=!0}}}function p(t){return class extends t{constructor(t){super(),this.nodeType=E.TEXT_NODE,this.nodeName="#text",this.RRNodeType=e.Text,this.data=t}get textContent(){return this.data}set textContent(e){this.data=e}toString(){return`RRText text=${JSON.stringify(this.data)}`}}}function m(t){return class extends t{constructor(t){super(),this.nodeType=E.COMMENT_NODE,this.nodeName="#comment",this.RRNodeType=e.Comment,this.data=t}get textContent(){return this.data}set textContent(e){this.data=e}toString(){return`RRComment text=${JSON.stringify(this.data)}`}}}function N(t){return class extends t{constructor(t){super(),this.nodeName="#cdata-section",this.nodeType=E.CDATA_SECTION_NODE,this.RRNodeType=e.CDATA,this.data=t}get textContent(){return this.data}set textContent(e){this.data=e}toString(){return`RRCDATASection data=${JSON.stringify(this.data)}`}}}class f{constructor(e,t){if(this.classes=[],this.add=(...e)=>{for(const t of e){const e=String(t);this.classes.indexOf(e)>=0||this.classes.push(e)}this.onChange&&this.onChange(this.classes.join(" "))},this.remove=(...e)=>{this.classes=this.classes.filter((t=>-1===e.indexOf(t))),this.onChange&&this.onChange(this.classes.join(" "))},e){const t=e.trim().split(/\s+/);this.classes.push(...t)}this.onChange=t}}var E;!function(e){e[e.PLACEHOLDER=0]="PLACEHOLDER",e[e.ELEMENT_NODE=1]="ELEMENT_NODE",e[e.ATTRIBUTE_NODE=2]="ATTRIBUTE_NODE",e[e.TEXT_NODE=3]="TEXT_NODE",e[e.CDATA_SECTION_NODE=4]="CDATA_SECTION_NODE",e[e.ENTITY_REFERENCE_NODE=5]="ENTITY_REFERENCE_NODE",e[e.ENTITY_NODE=6]="ENTITY_NODE",e[e.PROCESSING_INSTRUCTION_NODE=7]="PROCESSING_INSTRUCTION_NODE",e[e.COMMENT_NODE=8]="COMMENT_NODE",e[e.DOCUMENT_NODE=9]="DOCUMENT_NODE",e[e.DOCUMENT_TYPE_NODE=10]="DOCUMENT_TYPE_NODE",e[e.DOCUMENT_FRAGMENT_NODE=11]="DOCUMENT_FRAGMENT_NODE"}(E||(E={}));const T={svg:"http://www.w3.org/2000/svg","xlink:href":"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},R={altglyph:"altGlyph",altglyphdef:"altGlyphDef",altglyphitem:"altGlyphItem",animatecolor:"animateColor",animatemotion:"animateMotion",animatetransform:"animateTransform",clippath:"clipPath",feblend:"feBlend",fecolormatrix:"feColorMatrix",fecomponenttransfer:"feComponentTransfer",fecomposite:"feComposite",feconvolvematrix:"feConvolveMatrix",fediffuselighting:"feDiffuseLighting",fedisplacementmap:"feDisplacementMap",fedistantlight:"feDistantLight",fedropshadow:"feDropShadow",feflood:"feFlood",fefunca:"feFuncA",fefuncb:"feFuncB",fefuncg:"feFuncG",fefuncr:"feFuncR",fegaussianblur:"feGaussianBlur",feimage:"feImage",femerge:"feMerge",femergenode:"feMergeNode",femorphology:"feMorphology",feoffset:"feOffset",fepointlight:"fePointLight",fespecularlighting:"feSpecularLighting",fespotlight:"feSpotLight",fetile:"feTile",feturbulence:"feTurbulence",foreignobject:"foreignObject",glyphref:"glyphRef",lineargradient:"linearGradient",radialgradient:"radialGradient"};function D(t,n,o,s){const r=t.childNodes,i=n.childNodes;s=s||n.mirror||n.ownerDocument.mirror,(r.length>0||i.length>0)&&g(Array.from(r),i,t,o,s);let a=null,d=null;switch(n.RRNodeType){case e.Document:d=n.scrollData;break;case e.Element:{const e=t,r=n;switch(function(e,t,n){const o=e.attributes,s=t.attributes;for(const o in s){const r=s[o],i=n.getMeta(t);if(i&&"isSVG"in i&&i.isSVG&&T[o])e.setAttributeNS(T[o],o,r);else if("CANVAS"===t.tagName&&"rr_dataURL"===o){const t=document.createElement("img");t.src=r,t.onload=()=>{const n=e.getContext("2d");n&&n.drawImage(t,0,0,t.width,t.height)}}else e.setAttribute(o,r)}for(const{name:t}of Array.from(o))t in s||e.removeAttribute(t);t.scrollLeft&&(e.scrollLeft=t.scrollLeft),t.scrollTop&&(e.scrollTop=t.scrollTop)}(e,r,s),d=r.scrollData,a=r.inputData,r.tagName){case"AUDIO":case"VIDEO":{const e=t,n=r;void 0!==n.paused&&(n.paused?e.pause():e.play()),void 0!==n.muted&&(e.muted=n.muted),void 0!==n.volume&&(e.volume=n.volume),void 0!==n.currentTime&&(e.currentTime=n.currentTime),void 0!==n.playbackRate&&(e.playbackRate=n.playbackRate);break}case"CANVAS":{const s=n;if(null!==s.rr_dataURL){const t=document.createElement("img");t.onload=()=>{const n=e.getContext("2d");n&&n.drawImage(t,0,0,t.width,t.height)},t.src=s.rr_dataURL}s.canvasMutations.forEach((e=>o.applyCanvas(e.event,e.mutation,t)))}break;case"STYLE":{const t=e.sheet;t&&n.rules.forEach((e=>o.applyStyleSheetMutation(e,t)))}}if(r.shadowRoot){e.shadowRoot||e.attachShadow({mode:"open"});const t=e.shadowRoot.childNodes,n=r.shadowRoot.childNodes;(t.length>0||n.length>0)&&g(Array.from(t),n,e.shadowRoot,o,s)}break}case e.Text:case e.Comment:case e.CDATA:t.textContent!==n.data&&(t.textContent=n.data)}if(d&&o.applyScroll(d,!0),a&&o.applyInput(a),"IFRAME"===n.nodeName){const e=t.contentDocument,r=n;if(e){const t=s.getMeta(r.contentDocument);t&&o.mirror.add(e,Object.assign({},t)),D(e,r.contentDocument,o,s)}}}function g(t,n,o,s,r){var i;let a,d,c=0,l=t.length-1,h=0,u=n.length-1,p=t[c],m=t[l],N=n[h],f=n[u];for(;c<=l&&h<=u;){const E=s.mirror.getId(p),T=s.mirror.getId(m),R=r.getId(N),g=r.getId(f);if(void 0===p)p=t[++c];else if(void 0===m)m=t[--l];else if(-1!==E&&E===R)D(p,N,s,r),p=t[++c],N=n[++h];else if(-1!==T&&T===g)D(m,f,s,r),m=t[--l],f=n[--u];else if(-1!==E&&E===g)o.insertBefore(p,m.nextSibling),D(p,f,s,r),p=t[++c],f=n[--u];else if(-1!==T&&T===R)o.insertBefore(m,p),D(m,N,s,r),m=t[--l],N=n[++h];else{if(!a){a={};for(let e=c;e<=l;e++){const n=t[e];n&&s.mirror.hasNode(n)&&(a[s.mirror.getId(n)]=e)}}if(d=a[r.getId(N)],d){const e=t[d];o.insertBefore(e,p),D(e,N,s,r),t[d]=void 0}else{const n=C(N,s.mirror,r);"#document"===o.nodeName&&(null===(i=s.mirror.getMeta(n))||void 0===i?void 0:i.type)===e.Element&&o.documentElement&&(o.removeChild(o.documentElement),t[c]=void 0,p=void 0),o.insertBefore(n,p||null),D(n,N,s,r)}N=n[++h]}}if(c>l){const e=n[u+1];let t=null;for(e&&o.childNodes.forEach((n=>{s.mirror.getId(n)===r.getId(e)&&(t=n)}));h<=u;++h){const e=C(n[h],s.mirror,r);o.insertBefore(e,t),D(e,n[h],s,r)}}else if(h>u)for(;c<=l;c++){const e=t[c];e&&(o.removeChild(e),s.mirror.removeNodeFromMap(e))}}function C(t,n,o){const s=o.getId(t),r=o.getMeta(t);let i=null;if(s>-1&&(i=n.getNode(s)),null!==i)return i;switch(t.RRNodeType){case e.Document:i=new Document;break;case e.DocumentType:i=document.implementation.createDocumentType(t.name,t.publicId,t.systemId);break;case e.Element:{let e=t.tagName.toLowerCase();e=R[e]||e,i=r&&"isSVG"in r&&(null==r?void 0:r.isSVG)?document.createElementNS(T.svg,e):document.createElement(t.tagName);break}case e.Text:i=document.createTextNode(t.data);break;case e.Comment:i=document.createComment(t.data);break;case e.CDATA:i=document.createCDATASection(t.data)}return r&&n.add(i,Object.assign({},r)),i}class M extends(c(d)){constructor(e){super(),this.UNSERIALIZED_STARTING_ID=-2,this._unserializedId=this.UNSERIALIZED_STARTING_ID,this.mirror=F(),this.scrollData=null,e&&(this.mirror=e)}get unserializedId(){return this._unserializedId--}createDocument(e,t,n){return new M}createDocumentType(e,t,n){const o=new y(e,t,n);return o.ownerDocument=this,o}createElement(e){const t=e.toUpperCase();let n;switch(t){case"AUDIO":case"VIDEO":n=new O(t);break;case"IFRAME":n=new I(t,this.mirror);break;case"CANVAS":n=new x(t);break;case"STYLE":n=new A(t);break;default:n=new w(t)}return n.ownerDocument=this,n}createComment(e){const t=new _(e);return t.ownerDocument=this,t}createCDATASection(e){const t=new v(e);return t.ownerDocument=this,t}createTextNode(e){const t=new b(e);return t.ownerDocument=this,t}destroyTree(){this.childNodes=[],this.mirror.reset()}open(){super.open(),this._unserializedId=this.UNSERIALIZED_STARTING_ID}}const y=l(d);class w extends(h(d)){constructor(){super(...arguments),this.inputData=null,this.scrollData=null}}class O extends(u(w)){}class x extends w{constructor(){super(...arguments),this.rr_dataURL=null,this.canvasMutations=[]}getContext(){return null}}class A extends w{constructor(){super(...arguments),this.rules=[]}}class I extends w{constructor(e,t){super(e),this.contentDocument=new M,this.contentDocument.mirror=t}}const b=p(d),_=m(d),v=N(d);function S(e,t,n,o){let s;switch(e.nodeType){case E.DOCUMENT_NODE:o&&"IFRAME"===o.nodeName?s=o.contentDocument:(s=t,s.compatMode=e.compatMode);break;case E.DOCUMENT_TYPE_NODE:{const n=e;s=t.createDocumentType(n.name,n.publicId,n.systemId);break}case E.ELEMENT_NODE:{const n=e,o=(r=n)instanceof HTMLFormElement?"FORM":r.tagName.toUpperCase();s=t.createElement(o);const i=s;for(const{name:e,value:t}of Array.from(n.attributes))i.attributes[e]=t;n.scrollLeft&&(i.scrollLeft=n.scrollLeft),n.scrollTop&&(i.scrollTop=n.scrollTop);break}case E.TEXT_NODE:s=t.createTextNode(e.textContent||"");break;case E.CDATA_SECTION_NODE:s=t.createCDATASection(e.data);break;case E.COMMENT_NODE:s=t.createComment(e.textContent||"");break;case E.DOCUMENT_FRAGMENT_NODE:s=o.attachShadow({mode:"open"});break;default:return null}var r;let i=n.getMeta(e);return t instanceof M&&(i||(i=k(s,t.unserializedId),n.add(e,i)),t.mirror.add(s,Object.assign({},i))),s}function L(e,n=function(){return new t}(),o=new M){return function e(t,s){const r=S(t,o,n,s);if(null!==r)if("IFRAME"!==(null==s?void 0:s.nodeName)&&t.nodeType!==E.DOCUMENT_FRAGMENT_NODE&&(null==s||s.appendChild(r),r.parentNode=s,r.parentElement=s),"IFRAME"===t.nodeName){const n=t.contentDocument;n&&e(n,r)}else t.nodeType!==E.DOCUMENT_NODE&&t.nodeType!==E.ELEMENT_NODE&&t.nodeType!==E.DOCUMENT_FRAGMENT_NODE||(t.nodeType===E.ELEMENT_NODE&&t.shadowRoot&&e(t.shadowRoot,r),t.childNodes.forEach((t=>e(t,r))))}(e,null),o}function F(){return new U}class U{constructor(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}getId(e){var t;if(!e)return-1;const n=null===(t=this.getMeta(e))||void 0===t?void 0:t.id;return null!=n?n:-1}getNode(e){return this.idNodeMap.get(e)||null}getIds(){return Array.from(this.idNodeMap.keys())}getMeta(e){return this.nodeMetaMap.get(e)||null}removeNodeFromMap(e){const t=this.getId(e);this.idNodeMap.delete(t),e.childNodes&&e.childNodes.forEach((e=>this.removeNodeFromMap(e)))}has(e){return this.idNodeMap.has(e)}hasNode(e){return this.nodeMetaMap.has(e)}add(e,t){const n=t.id;this.idNodeMap.set(n,e),this.nodeMetaMap.set(e,t)}replace(e,t){const n=this.getNode(e);if(n){const e=this.nodeMetaMap.get(n);e&&this.nodeMetaMap.set(t,e)}this.idNodeMap.set(e,t)}reset(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}}function k(t,n){switch(t.RRNodeType){case e.Document:return{id:n,type:t.RRNodeType,childNodes:[]};case e.DocumentType:{const e=t;return{id:n,type:t.RRNodeType,name:e.name,publicId:e.publicId,systemId:e.systemId}}case e.Element:return{id:n,type:t.RRNodeType,tagName:t.tagName.toLowerCase(),attributes:{},childNodes:[]};case e.Text:case e.Comment:return{id:n,type:t.RRNodeType,textContent:t.textContent||""};case e.CDATA:return{id:n,type:t.RRNodeType,textContent:""}}}function B(e,t){return G(e,t,"")}function G(t,n,o){let s=`${o}${n.getId(t)} ${t.toString()}\n`;if(t.RRNodeType===e.Element){const e=t;e.shadowRoot&&(s+=G(e.shadowRoot,n,o+" "))}for(const e of t.childNodes)s+=G(e,n,o+" ");return"IFRAME"===t.nodeName&&(s+=G(t.contentDocument,n,o+" ")),s}export{N as BaseRRCDATASectionImpl,m as BaseRRCommentImpl,c as BaseRRDocumentImpl,l as BaseRRDocumentTypeImpl,h as BaseRRElementImpl,u as BaseRRMediaElementImpl,d as BaseRRNode,p as BaseRRTextImpl,f as ClassList,U as Mirror,E as NodeType,v as RRCDATASection,x as RRCanvasElement,_ as RRComment,M as RRDocument,y as RRDocumentType,w as RRElement,I as RRIFrameElement,O as RRMediaElement,d as RRNode,A as RRStyleElement,b as RRText,L as buildFromDom,S as buildFromNode,F as createMirror,C as createOrGetNode,D as diff,k as getDefaultSN,B as printRRDom}; | ||
var e;!function(e){e[e.Document=0]="Document",e[e.DocumentType=1]="DocumentType",e[e.Element=2]="Element",e[e.Text=3]="Text",e[e.CDATA=4]="CDATA",e[e.Comment=5]="Comment"}(e||(e={}));var t=function(){function e(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}return e.prototype.getId=function(e){var t;if(!e)return-1;var n=null===(t=this.getMeta(e))||void 0===t?void 0:t.id;return null!=n?n:-1},e.prototype.getNode=function(e){return this.idNodeMap.get(e)||null},e.prototype.getIds=function(){return Array.from(this.idNodeMap.keys())},e.prototype.getMeta=function(e){return this.nodeMetaMap.get(e)||null},e.prototype.removeNodeFromMap=function(e){var t=this,n=this.getId(e);this.idNodeMap.delete(n),e.childNodes&&e.childNodes.forEach((function(e){return t.removeNodeFromMap(e)}))},e.prototype.has=function(e){return this.idNodeMap.has(e)},e.prototype.hasNode=function(e){return this.nodeMetaMap.has(e)},e.prototype.add=function(e,t){var n=t.id;this.idNodeMap.set(n,e),this.nodeMetaMap.set(e,t)},e.prototype.replace=function(e,t){var n=this.getNode(e);if(n){var o=this.nodeMetaMap.get(n);o&&this.nodeMetaMap.set(t,o)}this.idNodeMap.set(e,t)},e.prototype.reset=function(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap},e}();function n(e){const t=[];for(const n in e){const o=e[n];if("string"!=typeof o)continue;const r=a(n);t.push(`${r}: ${o};`)}return t.join(" ")}const o=/-([a-z])/g,r=/^--[a-zA-Z0-9-]+$/,i=e=>r.test(e)?e:e.replace(o,((e,t)=>t?t.toUpperCase():"")),s=/\B([A-Z])/g,a=e=>e.replace(s,"-$1").toLowerCase();class l{constructor(...e){this.parentElement=null,this.parentNode=null,this.firstChild=null,this.lastChild=null,this.previousSibling=null,this.nextSibling=null,this.ELEMENT_NODE=g.ELEMENT_NODE,this.TEXT_NODE=g.TEXT_NODE}get childNodes(){const e=[];let t=this.firstChild;for(;t;)e.push(t),t=t.nextSibling;return e}contains(e){if(!(e instanceof l))return!1;if(e.ownerDocument!==this.ownerDocument)return!1;if(e===this)return!0;for(;e.parentNode;){if(e.parentNode===this)return!0;e=e.parentNode}return!1}appendChild(e){throw new Error("RRDomException: Failed to execute 'appendChild' on 'RRNode': This RRNode type does not support this method.")}insertBefore(e,t){throw new Error("RRDomException: Failed to execute 'insertBefore' on 'RRNode': This RRNode type does not support this method.")}removeChild(e){throw new Error("RRDomException: Failed to execute 'removeChild' on 'RRNode': This RRNode type does not support this method.")}toString(){return"RRNode"}}function c(t){return class n extends t{constructor(...t){super(t),this.nodeType=g.DOCUMENT_NODE,this.nodeName="#document",this.compatMode="CSS1Compat",this.RRNodeType=e.Document,this.textContent=null,this.ownerDocument=this}get documentElement(){return this.childNodes.find((t=>t.RRNodeType===e.Element&&"HTML"===t.tagName))||null}get body(){var t;return(null===(t=this.documentElement)||void 0===t?void 0:t.childNodes.find((t=>t.RRNodeType===e.Element&&"BODY"===t.tagName)))||null}get head(){var t;return(null===(t=this.documentElement)||void 0===t?void 0:t.childNodes.find((t=>t.RRNodeType===e.Element&&"HEAD"===t.tagName)))||null}get implementation(){return this}get firstElementChild(){return this.documentElement}appendChild(t){const n=t.RRNodeType;if((n===e.Element||n===e.DocumentType)&&this.childNodes.some((e=>e.RRNodeType===n)))throw new Error(`RRDomException: Failed to execute 'appendChild' on 'RRNode': Only one ${n===e.Element?"RRElement":"RRDoctype"} on RRDocument allowed.`);const o=E(this,t);return o.parentElement=null,o}insertBefore(t,n){const o=t.RRNodeType;if((o===e.Element||o===e.DocumentType)&&this.childNodes.some((e=>e.RRNodeType===o)))throw new Error(`RRDomException: Failed to execute 'insertBefore' on 'RRNode': Only one ${o===e.Element?"RRElement":"RRDoctype"} on RRDocument allowed.`);const r=T(this,t,n);return r.parentElement=null,r}removeChild(e){return D(this,e)}open(){this.firstChild=null,this.lastChild=null}close(){}write(e){let t;if('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">'===e?t="-//W3C//DTD XHTML 1.0 Transitional//EN":'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">'===e&&(t="-//W3C//DTD HTML 4.0 Transitional//EN"),t){const e=this.createDocumentType("html",t,"");this.open(),this.appendChild(e)}}createDocument(e,t,o){return new n}createDocumentType(e,t,n){const o=new(d(l))(e,t,n);return o.ownerDocument=this,o}createElement(e){const t=new(u(l))(e);return t.ownerDocument=this,t}createElementNS(e,t){return this.createElement(t)}createTextNode(e){const t=new(p(l))(e);return t.ownerDocument=this,t}createComment(e){const t=new(m(l))(e);return t.ownerDocument=this,t}createCDATASection(e){const t=new(N(l))(e);return t.ownerDocument=this,t}toString(){return"RRDocument"}}}function d(t){return class extends t{constructor(t,n,o){super(),this.nodeType=g.DOCUMENT_TYPE_NODE,this.RRNodeType=e.DocumentType,this.name=t,this.publicId=n,this.systemId=o,this.nodeName=t,this.textContent=null}toString(){return"RRDocumentType"}}}function u(t){return class extends t{constructor(t){super(),this.nodeType=g.ELEMENT_NODE,this.RRNodeType=e.Element,this.attributes={},this.shadowRoot=null,this.tagName=t.toUpperCase(),this.nodeName=t.toUpperCase()}get textContent(){let e="";return this.childNodes.forEach((t=>e+=t.textContent)),e}set textContent(e){this.firstChild=null,this.lastChild=null,this.appendChild(this.ownerDocument.createTextNode(e))}get classList(){return new f(this.attributes.class,(e=>{this.attributes.class=e}))}get id(){return this.attributes.id||""}get className(){return this.attributes.class||""}get style(){const e=this.attributes.style?function(e){const t={},n=/:(.+)/;return e.replace(/\/\*.*?\*\//g,"").split(/;(?![^(]*\))/g).forEach((function(e){if(e){const o=e.split(n);o.length>1&&(t[i(o[0].trim())]=o[1].trim())}})),t}(this.attributes.style):{},t=/\B([A-Z])/g;return e.setProperty=(o,r,s)=>{if(t.test(o))return;const a=i(o);r?e[a]=r:delete e[a],"important"===s&&(e[a]+=" !important"),this.attributes.style=n(e)},e.removeProperty=o=>{if(t.test(o))return"";const r=i(o),s=e[r]||"";return delete e[r],this.attributes.style=n(e),s},e}getAttribute(e){return this.attributes[e]||null}setAttribute(e,t){this.attributes[e]=t}setAttributeNS(e,t,n){this.setAttribute(t,n)}removeAttribute(e){delete this.attributes[e]}appendChild(e){return E(this,e)}insertBefore(e,t){return T(this,e,t)}removeChild(e){return D(this,e)}attachShadow(e){const t=this.ownerDocument.createElement("SHADOWROOT");return this.shadowRoot=t,t}dispatchEvent(e){return!0}toString(){let e="";for(const t in this.attributes)e+=`${t}="${this.attributes[t]}" `;return`${this.tagName} ${e}`}}}function h(e){return class extends e{attachShadow(e){throw new Error("RRDomException: Failed to execute 'attachShadow' on 'RRElement': This RRElement does not support attachShadow")}play(){this.paused=!1}pause(){this.paused=!0}}}function p(t){return class extends t{constructor(t){super(),this.nodeType=g.TEXT_NODE,this.nodeName="#text",this.RRNodeType=e.Text,this.data=t}get textContent(){return this.data}set textContent(e){this.data=e}toString(){return`RRText text=${JSON.stringify(this.data)}`}}}function m(t){return class extends t{constructor(t){super(),this.nodeType=g.COMMENT_NODE,this.nodeName="#comment",this.RRNodeType=e.Comment,this.data=t}get textContent(){return this.data}set textContent(e){this.data=e}toString(){return`RRComment text=${JSON.stringify(this.data)}`}}}function N(t){return class extends t{constructor(t){super(),this.nodeName="#cdata-section",this.nodeType=g.CDATA_SECTION_NODE,this.RRNodeType=e.CDATA,this.data=t}get textContent(){return this.data}set textContent(e){this.data=e}toString(){return`RRCDATASection data=${JSON.stringify(this.data)}`}}}class f{constructor(e,t){if(this.classes=[],this.add=(...e)=>{for(const t of e){const e=String(t);this.classes.indexOf(e)>=0||this.classes.push(e)}this.onChange&&this.onChange(this.classes.join(" "))},this.remove=(...e)=>{this.classes=this.classes.filter((t=>-1===e.indexOf(t))),this.onChange&&this.onChange(this.classes.join(" "))},e){const t=e.trim().split(/\s+/);this.classes.push(...t)}this.onChange=t}}function E(e,t){return e.lastChild?(e.lastChild.nextSibling=t,t.previousSibling=e.lastChild):(e.firstChild=t,t.previousSibling=null),e.lastChild=t,t.nextSibling=null,t.parentNode=e,t.parentElement=e,t.ownerDocument=e.ownerDocument,t}function T(e,t,n){if(!n)return E(e,t);if(n.parentNode!==e)throw new Error("Failed to execute 'insertBefore' on 'RRNode': The RRNode before which the new node is to be inserted is not a child of this RRNode.");return t.previousSibling=n.previousSibling,n.previousSibling=t,t.nextSibling=n,t.previousSibling?t.previousSibling.nextSibling=t:e.firstChild=t,t.parentElement=e,t.parentNode=e,t.ownerDocument=e.ownerDocument,t}function D(e,t){if(t.parentNode!==e)throw new Error("Failed to execute 'removeChild' on 'RRNode': The RRNode to be removed is not a child of this RRNode.");return t.previousSibling?t.previousSibling.nextSibling=t.nextSibling:e.firstChild=t.nextSibling,t.nextSibling?t.nextSibling.previousSibling=t.previousSibling:e.lastChild=t.previousSibling,t.previousSibling=null,t.nextSibling=null,t.parentElement=null,t.parentNode=null,t}var g;!function(e){e[e.PLACEHOLDER=0]="PLACEHOLDER",e[e.ELEMENT_NODE=1]="ELEMENT_NODE",e[e.ATTRIBUTE_NODE=2]="ATTRIBUTE_NODE",e[e.TEXT_NODE=3]="TEXT_NODE",e[e.CDATA_SECTION_NODE=4]="CDATA_SECTION_NODE",e[e.ENTITY_REFERENCE_NODE=5]="ENTITY_REFERENCE_NODE",e[e.ENTITY_NODE=6]="ENTITY_NODE",e[e.PROCESSING_INSTRUCTION_NODE=7]="PROCESSING_INSTRUCTION_NODE",e[e.COMMENT_NODE=8]="COMMENT_NODE",e[e.DOCUMENT_NODE=9]="DOCUMENT_NODE",e[e.DOCUMENT_TYPE_NODE=10]="DOCUMENT_TYPE_NODE",e[e.DOCUMENT_FRAGMENT_NODE=11]="DOCUMENT_FRAGMENT_NODE"}(g||(g={}));const R={svg:"http://www.w3.org/2000/svg","xlink:href":"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},C={altglyph:"altGlyph",altglyphdef:"altGlyphDef",altglyphitem:"altGlyphItem",animatecolor:"animateColor",animatemotion:"animateMotion",animatetransform:"animateTransform",clippath:"clipPath",feblend:"feBlend",fecolormatrix:"feColorMatrix",fecomponenttransfer:"feComponentTransfer",fecomposite:"feComposite",feconvolvematrix:"feConvolveMatrix",fediffuselighting:"feDiffuseLighting",fedisplacementmap:"feDisplacementMap",fedistantlight:"feDistantLight",fedropshadow:"feDropShadow",feflood:"feFlood",fefunca:"feFuncA",fefuncb:"feFuncB",fefuncg:"feFuncG",fefuncr:"feFuncR",fegaussianblur:"feGaussianBlur",feimage:"feImage",femerge:"feMerge",femergenode:"feMergeNode",femorphology:"feMorphology",feoffset:"feOffset",fepointlight:"fePointLight",fespecularlighting:"feSpecularLighting",fespotlight:"feSpotLight",fetile:"feTile",feturbulence:"feTurbulence",foreignobject:"foreignObject",glyphref:"glyphRef",lineargradient:"linearGradient",radialgradient:"radialGradient"};let M=null;function y(t,n,o,r=n.mirror||n.ownerDocument.mirror){t=function(t,n,o,r){var i;o.afterAppend&&!M&&(M=new WeakSet,setTimeout((()=>{M=null}),0));if(!b(t,n)){const e=O(n,o.mirror,r);null===(i=t.parentNode)||void 0===i||i.replaceChild(e,t),t=e}switch(n.RRNodeType){case e.Document:if(!S(t,n,o.mirror,r)){const e=r.getMeta(n);e&&(o.mirror.removeNodeFromMap(t),t.close(),t.open(),o.mirror.add(t,e),null==M||M.add(t))}break;case e.Element:{const e=t,i=n;switch(i.tagName){case"IFRAME":{const e=t.contentDocument;if(!e)break;y(e,n.contentDocument,o,r);break}}if(i.shadowRoot){e.shadowRoot||e.attachShadow({mode:"open"});const t=e.shadowRoot.childNodes,n=i.shadowRoot.childNodes;(t.length>0||n.length>0)&&w(Array.from(t),n,e.shadowRoot,o,r)}break}}return t}(t,n,o,r);const i=t.childNodes,s=n.childNodes;(i.length>0||s.length>0)&&w(Array.from(i),s,t,o,r),function(t,n,o,r){var i;switch(n.RRNodeType){case e.Document:{const e=n.scrollData;e&&o.applyScroll(e,!0);break}case e.Element:{const e=t,i=n;switch(function(e,t,n){const o=e.attributes,r=t.attributes;for(const o in r){const i=r[o],s=n.getMeta(t);if((null==s?void 0:s.isSVG)&&R[o])e.setAttributeNS(R[o],o,i);else if("CANVAS"===t.tagName&&"rr_dataURL"===o){const t=document.createElement("img");t.src=i,t.onload=()=>{const n=e.getContext("2d");n&&n.drawImage(t,0,0,t.width,t.height)}}else e.setAttribute(o,i)}for(const{name:t}of Array.from(o))t in r||e.removeAttribute(t);t.scrollLeft&&(e.scrollLeft=t.scrollLeft),t.scrollTop&&(e.scrollTop=t.scrollTop)}(e,i,r),i.scrollData&&o.applyScroll(i.scrollData,!0),i.inputData&&o.applyInput(i.inputData),i.tagName){case"AUDIO":case"VIDEO":{const e=t,n=i;void 0!==n.paused&&(n.paused?e.pause():e.play()),void 0!==n.muted&&(e.muted=n.muted),void 0!==n.volume&&(e.volume=n.volume),void 0!==n.currentTime&&(e.currentTime=n.currentTime),void 0!==n.playbackRate&&(e.playbackRate=n.playbackRate);break}case"CANVAS":{const r=n;if(null!==r.rr_dataURL){const t=document.createElement("img");t.onload=()=>{const n=e.getContext("2d");n&&n.drawImage(t,0,0,t.width,t.height)},t.src=r.rr_dataURL}r.canvasMutations.forEach((e=>o.applyCanvas(e.event,e.mutation,t)));break}case"STYLE":{const t=e.sheet;t&&n.rules.forEach((e=>o.applyStyleSheetMutation(e,t)));break}}break}case e.Text:case e.Comment:case e.CDATA:t.textContent!==n.data&&(t.textContent=n.data)}(null==M?void 0:M.has(t))&&(M.delete(t),null===(i=o.afterAppend)||void 0===i||i.call(o,t,o.mirror.getId(t)))}(t,n,o,r)}function w(e,t,n,o,r){let i,s,a=0,l=e.length-1,c=0,d=t.length-1,u=e[a],h=e[l],p=t[c],m=t[d];for(;a<=l&&c<=d;)if(void 0===u)u=e[++a];else if(void 0===h)h=e[--l];else if(S(u,p,o.mirror,r))y(u,p,o,r),u=e[++a],p=t[++c];else if(S(h,m,o.mirror,r))y(h,m,o,r),h=e[--l],m=t[--d];else if(S(u,m,o.mirror,r)){try{n.insertBefore(u,h.nextSibling)}catch(e){console.warn(e)}y(u,m,o,r),u=e[++a],m=t[--d]}else if(S(h,p,o.mirror,r)){try{n.insertBefore(h,u)}catch(e){console.warn(e)}y(h,p,o,r),h=e[--l],p=t[++c]}else{if(!i){i={};for(let t=a;t<=l;t++){const n=e[t];n&&o.mirror.hasNode(n)&&(i[o.mirror.getId(n)]=t)}}s=i[r.getId(p)];const d=e[s];if(void 0!==s&&d&&S(d,p,o.mirror,r)){try{n.insertBefore(d,u)}catch(e){console.warn(e)}y(d,p,o,r),e[s]=void 0}else{const t=O(p,o.mirror,r);"#document"===n.nodeName&&u&&(t.nodeType===t.DOCUMENT_TYPE_NODE&&u.nodeType===u.DOCUMENT_TYPE_NODE||t.nodeType===t.ELEMENT_NODE&&u.nodeType===u.ELEMENT_NODE)&&(n.removeChild(u),o.mirror.removeNodeFromMap(u),u=e[++a]);try{n.insertBefore(t,u||null),y(t,p,o,r)}catch(e){console.warn(e)}}p=t[++c]}if(a>l){const e=t[d+1];let i=null;for(e&&(i=o.mirror.getNode(r.getId(e)));c<=d;++c){const e=O(t[c],o.mirror,r);try{n.insertBefore(e,i),y(e,t[c],o,r)}catch(e){console.warn(e)}}}else if(c>d)for(;a<=l;a++){const t=e[a];if(t&&n.contains(t))try{n.removeChild(t),o.mirror.removeNodeFromMap(t)}catch(e){console.warn(e)}}}function O(t,n,o){const r=o.getId(t),i=o.getMeta(t);let s=null;if(r>-1&&(s=n.getNode(r)),null!==s&&b(s,t))return s;switch(t.RRNodeType){case e.Document:s=new Document;break;case e.DocumentType:s=document.implementation.createDocumentType(t.name,t.publicId,t.systemId);break;case e.Element:{let e=t.tagName.toLowerCase();e=C[e]||e,s=i&&"isSVG"in i&&(null==i?void 0:i.isSVG)?document.createElementNS(R.svg,e):document.createElement(t.tagName);break}case e.Text:s=document.createTextNode(t.data);break;case e.Comment:s=document.createComment(t.data);break;case e.CDATA:s=document.createCDATASection(t.data)}i&&n.add(s,Object.assign({},i));try{null==M||M.add(s)}catch(e){}return s}function b(e,t){return e.nodeType===t.nodeType&&(e.nodeType!==e.ELEMENT_NODE||e.tagName.toUpperCase()===t.tagName)}function S(e,t,n,o){const r=n.getId(e),i=o.getId(t);return-1!==r&&r===i&&b(e,t)}class v extends(c(l)){constructor(e){super(),this.UNSERIALIZED_STARTING_ID=-2,this._unserializedId=this.UNSERIALIZED_STARTING_ID,this.mirror=$(),this.scrollData=null,e&&(this.mirror=e)}get unserializedId(){return this._unserializedId--}createDocument(e,t,n){return new v}createDocumentType(e,t,n){const o=new x(e,t,n);return o.ownerDocument=this,o}createElement(e){const t=e.toUpperCase();let n;switch(t){case"AUDIO":case"VIDEO":n=new _(t);break;case"IFRAME":n=new k(t,this.mirror);break;case"CANVAS":n=new I(t);break;case"STYLE":n=new L(t);break;default:n=new A(t)}return n.ownerDocument=this,n}createComment(e){const t=new F(e);return t.ownerDocument=this,t}createCDATASection(e){const t=new B(e);return t.ownerDocument=this,t}createTextNode(e){const t=new U(e);return t.ownerDocument=this,t}destroyTree(){this.firstChild=null,this.lastChild=null,this.mirror.reset()}open(){super.open(),this._unserializedId=this.UNSERIALIZED_STARTING_ID}}const x=d(l);class A extends(u(l)){constructor(){super(...arguments),this.inputData=null,this.scrollData=null}}class _ extends(h(A)){}class I extends A{constructor(){super(...arguments),this.rr_dataURL=null,this.canvasMutations=[]}getContext(){return null}}class L extends A{constructor(){super(...arguments),this.rules=[]}}class k extends A{constructor(e,t){super(e),this.contentDocument=new v,this.contentDocument.mirror=t}}const U=p(l),F=m(l),B=N(l);function G(e,t,n,o){let r;switch(e.nodeType){case g.DOCUMENT_NODE:o&&"IFRAME"===o.nodeName?r=o.contentDocument:(r=t,r.compatMode=e.compatMode);break;case g.DOCUMENT_TYPE_NODE:{const n=e;r=t.createDocumentType(n.name,n.publicId,n.systemId);break}case g.ELEMENT_NODE:{const n=e,o=(i=n)instanceof HTMLFormElement?"FORM":i.tagName.toUpperCase();r=t.createElement(o);const s=r;for(const{name:e,value:t}of Array.from(n.attributes))s.attributes[e]=t;n.scrollLeft&&(s.scrollLeft=n.scrollLeft),n.scrollTop&&(s.scrollTop=n.scrollTop);break}case g.TEXT_NODE:r=t.createTextNode(e.textContent||"");break;case g.CDATA_SECTION_NODE:r=t.createCDATASection(e.data);break;case g.COMMENT_NODE:r=t.createComment(e.textContent||"");break;case g.DOCUMENT_FRAGMENT_NODE:r=o.attachShadow({mode:"open"});break;default:return null}var i;let s=n.getMeta(e);return t instanceof v&&(s||(s=H(r,t.unserializedId),n.add(e,s)),t.mirror.add(r,Object.assign({},s))),r}function P(e,n=function(){return new t}(),o=new v){return function e(t,r){const i=G(t,o,n,r);if(null!==i)if("IFRAME"!==(null==r?void 0:r.nodeName)&&t.nodeType!==g.DOCUMENT_FRAGMENT_NODE&&(null==r||r.appendChild(i),i.parentNode=r,i.parentElement=r),"IFRAME"===t.nodeName){const n=t.contentDocument;n&&e(n,i)}else t.nodeType!==g.DOCUMENT_NODE&&t.nodeType!==g.ELEMENT_NODE&&t.nodeType!==g.DOCUMENT_FRAGMENT_NODE||(t.nodeType===g.ELEMENT_NODE&&t.shadowRoot&&e(t.shadowRoot,i),t.childNodes.forEach((t=>e(t,i))))}(e,null),o}function $(){return new Y}class Y{constructor(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}getId(e){var t;if(!e)return-1;const n=null===(t=this.getMeta(e))||void 0===t?void 0:t.id;return null!=n?n:-1}getNode(e){return this.idNodeMap.get(e)||null}getIds(){return Array.from(this.idNodeMap.keys())}getMeta(e){return this.nodeMetaMap.get(e)||null}removeNodeFromMap(e){const t=this.getId(e);this.idNodeMap.delete(t),e.childNodes&&e.childNodes.forEach((e=>this.removeNodeFromMap(e)))}has(e){return this.idNodeMap.has(e)}hasNode(e){return this.nodeMetaMap.has(e)}add(e,t){const n=t.id;this.idNodeMap.set(n,e),this.nodeMetaMap.set(e,t)}replace(e,t){const n=this.getNode(e);if(n){const e=this.nodeMetaMap.get(n);e&&this.nodeMetaMap.set(t,e)}this.idNodeMap.set(e,t)}reset(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}}function H(t,n){switch(t.RRNodeType){case e.Document:return{id:n,type:t.RRNodeType,childNodes:[]};case e.DocumentType:{const e=t;return{id:n,type:t.RRNodeType,name:e.name,publicId:e.publicId,systemId:e.systemId}}case e.Element:return{id:n,type:t.RRNodeType,tagName:t.tagName.toLowerCase(),attributes:{},childNodes:[]};case e.Text:case e.Comment:return{id:n,type:t.RRNodeType,textContent:t.textContent||""};case e.CDATA:return{id:n,type:t.RRNodeType,textContent:""}}}function W(e,t){return V(e,t,"")}function V(t,n,o){let r=`${o}${n.getId(t)} ${t.toString()}\n`;if(t.RRNodeType===e.Element){const e=t;e.shadowRoot&&(r+=V(e.shadowRoot,n,o+" "))}for(const e of t.childNodes)r+=V(e,n,o+" ");return"IFRAME"===t.nodeName&&(r+=V(t.contentDocument,n,o+" ")),r}export{N as BaseRRCDATASectionImpl,m as BaseRRCommentImpl,c as BaseRRDocumentImpl,d as BaseRRDocumentTypeImpl,u as BaseRRElementImpl,h as BaseRRMediaElementImpl,l as BaseRRNode,p as BaseRRTextImpl,f as ClassList,Y as Mirror,g as NodeType,B as RRCDATASection,I as RRCanvasElement,F as RRComment,v as RRDocument,x as RRDocumentType,A as RRElement,k as RRIFrameElement,_ as RRMediaElement,l as RRNode,L as RRStyleElement,U as RRText,P as buildFromDom,G as buildFromNode,$ as createMirror,O as createOrGetNode,y as diff,H as getDefaultSN,W as printRRDom}; | ||
//# sourceMappingURL=rrdom.min.js.map |
@@ -11,4 +11,7 @@ import { Mirror as NodeMirror } from 'rrweb-snapshot'; | ||
applyStyleSheetMutation: (data: styleDeclarationData | styleSheetRuleData, styleSheet: CSSStyleSheet) => void; | ||
afterAppend?(node: Node, id: number): void; | ||
}; | ||
export declare function diff(oldTree: Node, newTree: IRRNode, replayer: ReplayerHandler, rrnodeMirror?: Mirror): void; | ||
export declare function createOrGetNode(rrNode: IRRNode, domMirror: NodeMirror, rrnodeMirror: Mirror): Node; | ||
export declare function sameNodeType(node1: Node, node2: IRRNode): boolean; | ||
export declare function nodeMatching(node1: Node, node2: IRRNode, domMirror: NodeMirror, rrdomMirror: Mirror): boolean; |
@@ -5,4 +5,4 @@ import { NodeType as RRNodeType } from 'rrweb-snapshot'; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -15,2 +15,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -79,7 +80,10 @@ textContent: string | null; | ||
export declare class BaseRRNode implements IRRNode { | ||
childNodes: IRRNode[]; | ||
parentElement: IRRNode | null; | ||
parentNode: IRRNode | null; | ||
ownerDocument: IRRDocument; | ||
firstChild: IRRNode | null; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
ownerDocument: IRRDocument; | ||
readonly ELEMENT_NODE: number; | ||
@@ -91,5 +95,3 @@ readonly TEXT_NODE: number; | ||
constructor(..._args: any[]); | ||
get firstChild(): IRRNode | null; | ||
get lastChild(): IRRNode | null; | ||
get nextSibling(): IRRNode | null; | ||
get childNodes(): IRRNode[]; | ||
contains(node: IRRNode): boolean; | ||
@@ -107,3 +109,2 @@ appendChild(_newChild: IRRNode): IRRNode; | ||
readonly RRNodeType: RRNodeType.Document; | ||
textContent: string | null; | ||
readonly documentElement: IRRElement | null; | ||
@@ -114,3 +115,3 @@ readonly body: IRRElement | null; | ||
readonly firstElementChild: IRRElement | null; | ||
appendChild(childNode: IRRNode): IRRNode; | ||
appendChild(newChild: IRRNode): IRRNode; | ||
insertBefore(newChild: IRRNode, refChild: IRRNode | null): IRRNode; | ||
@@ -131,4 +132,4 @@ removeChild(node: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -138,3 +139,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -151,8 +154,7 @@ }; | ||
readonly systemId: string; | ||
textContent: string | null; | ||
toString(): string; | ||
parentElement: IRRNode | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -162,3 +164,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -197,4 +201,4 @@ appendChild(newChild: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -204,2 +208,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -235,4 +240,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -245,2 +250,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -265,4 +271,4 @@ textContent: string | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -272,2 +278,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -290,4 +297,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -297,2 +304,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -315,4 +323,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -322,2 +330,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -324,0 +333,0 @@ contains(node: IRRNode): boolean; |
@@ -11,3 +11,2 @@ import { NodeType as RRNodeType } from 'rrweb-snapshot'; | ||
readonly RRNodeType: RRNodeType.Document; | ||
textContent: string | null; | ||
readonly documentElement: IRRElement | null; | ||
@@ -18,3 +17,3 @@ readonly body: IRRElement | null; | ||
readonly firstElementChild: IRRElement | null; | ||
appendChild(childNode: IRRNode): IRRNode; | ||
appendChild(newChild: IRRNode): IRRNode; | ||
insertBefore(newChild: IRRNode, refChild: IRRNode | null): IRRNode; | ||
@@ -35,4 +34,4 @@ removeChild(node: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -42,3 +41,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -62,8 +63,7 @@ }; | ||
readonly systemId: string; | ||
textContent: string | null; | ||
toString(): string; | ||
parentElement: IRRNode | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -73,3 +73,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -91,4 +93,4 @@ appendChild(newChild: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -98,2 +100,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -114,4 +117,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -121,2 +124,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -137,4 +141,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -144,2 +148,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -162,8 +167,7 @@ contains(node: IRRNode): boolean; | ||
readonly systemId: string; | ||
textContent: string | null; | ||
toString(): string; | ||
parentElement: IRRNode | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -173,3 +177,5 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
textContent: string | null; | ||
contains(node: IRRNode): boolean; | ||
@@ -208,4 +214,4 @@ appendChild(newChild: IRRNode): IRRNode; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -215,2 +221,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -250,4 +257,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -260,2 +267,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -297,4 +305,4 @@ textContent: string | null; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -304,2 +312,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -323,4 +332,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -330,2 +339,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -349,4 +359,4 @@ contains(node: IRRNode): boolean; | ||
parentNode: IRRNode | null; | ||
childNodes: IRRNode[]; | ||
ownerDocument: IRRDocument; | ||
readonly childNodes: IRRNode[]; | ||
readonly ELEMENT_NODE: number; | ||
@@ -356,2 +366,3 @@ readonly TEXT_NODE: number; | ||
lastChild: IRRNode | null; | ||
previousSibling: IRRNode | null; | ||
nextSibling: IRRNode | null; | ||
@@ -358,0 +369,0 @@ contains(node: IRRNode): boolean; |
{ | ||
"name": "rrdom", | ||
"version": "0.1.7", | ||
"version": "2.0.0-alpha.5", | ||
"homepage": "https://github.com/rrweb-io/rrweb/tree/main/packages/rrdom#readme", | ||
"license": "MIT", | ||
"main": "lib/rrdom.js", | ||
"main": "lib/rrdom.cjs", | ||
"module": "es/rrdom.js", | ||
@@ -16,2 +16,3 @@ "typings": "es", | ||
], | ||
"type": "module", | ||
"repository": { | ||
@@ -35,3 +36,3 @@ "type": "git", | ||
"@rollup/plugin-commonjs": "^20.0.0", | ||
"@rrweb/types": "^2.0.0-alpha.4", | ||
"@rrweb/types": "^2.0.0-alpha.5", | ||
"@types/jest": "^27.4.1", | ||
@@ -43,3 +44,3 @@ "@types/puppeteer": "^5.4.4", | ||
"jest": "^27.5.1", | ||
"puppeteer": "^9.1.1", | ||
"puppeteer": "^17.1.3", | ||
"rollup": "^2.56.3", | ||
@@ -53,5 +54,4 @@ "rollup-plugin-terser": "^7.0.2", | ||
"dependencies": { | ||
"rrweb-snapshot": "^2.0.0-alpha.4" | ||
}, | ||
"gitHead": "7bb68625e3ff39258a8cc8614f0691f265cb5bee" | ||
"rrweb-snapshot": "^2.0.0-alpha.5" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
2
Yes
601232
20
6171
1