Comparing version 0.1.5 to 0.1.6
import { Mirror as NodeMirror } from 'rrweb-snapshot'; | ||
import type { canvasMutationData, canvasEventWithTime, inputData, scrollData } from 'rrweb/src/types'; | ||
import type { canvasMutationData, canvasEventWithTime, inputData, scrollData, styleDeclarationData, styleSheetRuleData } from 'rrweb/src/types'; | ||
import type { IRRNode } from './document'; | ||
@@ -10,40 +10,5 @@ import type { Mirror } from '.'; | ||
applyScroll: (data: scrollData, isSync: boolean) => void; | ||
applyStyleSheetMutation: (data: styleDeclarationData | styleSheetRuleData, styleSheet: CSSStyleSheet) => 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 getNestedRule(rules: CSSRuleList, position: number[]): CSSGroupingRule; | ||
export declare enum StyleRuleType { | ||
Insert = 0, | ||
Remove = 1, | ||
Snapshot = 2, | ||
SetProperty = 3, | ||
RemoveProperty = 4 | ||
} | ||
declare type InsertRule = { | ||
cssText: string; | ||
type: StyleRuleType.Insert; | ||
index?: number | number[]; | ||
}; | ||
declare type RemoveRule = { | ||
type: StyleRuleType.Remove; | ||
index: number | number[]; | ||
}; | ||
declare type SetPropertyRule = { | ||
type: StyleRuleType.SetProperty; | ||
index: number[]; | ||
property: string; | ||
value: string | null; | ||
priority: string | undefined; | ||
}; | ||
declare type RemovePropertyRule = { | ||
type: StyleRuleType.RemoveProperty; | ||
index: number[]; | ||
property: string; | ||
}; | ||
export declare type VirtualStyleRules = Array<InsertRule | RemoveRule | SetPropertyRule | RemovePropertyRule>; | ||
export declare function getPositionsAndIndex(nestedIndex: number[]): { | ||
positions: number[]; | ||
index: number | undefined; | ||
}; | ||
export declare function applyVirtualStyleRulesToNode(styleNode: HTMLStyleElement, virtualStyleRules: VirtualStyleRules): void; | ||
export {}; |
import { NodeType as RRNodeType } from 'rrweb-snapshot'; | ||
import type { Mirror as NodeMirror, IMirror, serializedNodeWithId } from 'rrweb-snapshot'; | ||
import type { canvasMutationData, canvasEventWithTime, inputData, scrollData } from 'rrweb/src/types'; | ||
import type { VirtualStyleRules } from './diff'; | ||
import type { canvasMutationData, canvasEventWithTime, inputData, scrollData, styleSheetRuleData, styleDeclarationData } from 'rrweb/src/types'; | ||
import { BaseRRNode as RRNode, IRRDocument, IRRElement, IRRNode, IRRDocumentType, IRRText, IRRComment } from './document'; | ||
@@ -264,3 +263,3 @@ declare const RRDocument_base: { | ||
export declare class RRStyleElement extends RRElement { | ||
rules: VirtualStyleRules; | ||
rules: (styleSheetRuleData | styleDeclarationData)[]; | ||
} | ||
@@ -371,3 +370,3 @@ export declare class RRIFrameElement extends RRElement { | ||
export { RRNode }; | ||
export { diff, createOrGetNode, StyleRuleType, ReplayerHandler, VirtualStyleRules, } from './diff'; | ||
export { diff, createOrGetNode, ReplayerHandler } from './diff'; | ||
export * from './document'; |
@@ -56,2 +56,8 @@ var rrdom = (function (exports) { | ||
Mirror.prototype.replace = function (id, n) { | ||
var oldNode = this.getNode(id); | ||
if (oldNode) { | ||
var meta = this.nodeMetaMap.get(oldNode); | ||
if (meta) | ||
this.nodeMetaMap.set(n, meta); | ||
} | ||
this.idNodeMap.set(id, n); | ||
@@ -621,3 +627,7 @@ }; | ||
case 'STYLE': | ||
applyVirtualStyleRulesToNode(oldElement, newTree.rules); | ||
{ | ||
const styleSheet = oldElement.sheet; | ||
styleSheet && | ||
newTree.rules.forEach((data) => replayer.applyStyleSheetMutation(data, styleSheet)); | ||
} | ||
break; | ||
@@ -820,65 +830,2 @@ } | ||
} | ||
function getNestedRule(rules, position) { | ||
const rule = rules[position[0]]; | ||
if (position.length === 1) { | ||
return rule; | ||
} | ||
else { | ||
return getNestedRule(rule.cssRules[position[1]].cssRules, position.slice(2)); | ||
} | ||
} | ||
exports.StyleRuleType = void 0; | ||
(function (StyleRuleType) { | ||
StyleRuleType[StyleRuleType["Insert"] = 0] = "Insert"; | ||
StyleRuleType[StyleRuleType["Remove"] = 1] = "Remove"; | ||
StyleRuleType[StyleRuleType["Snapshot"] = 2] = "Snapshot"; | ||
StyleRuleType[StyleRuleType["SetProperty"] = 3] = "SetProperty"; | ||
StyleRuleType[StyleRuleType["RemoveProperty"] = 4] = "RemoveProperty"; | ||
})(exports.StyleRuleType || (exports.StyleRuleType = {})); | ||
function getPositionsAndIndex(nestedIndex) { | ||
const positions = [...nestedIndex]; | ||
const index = positions.pop(); | ||
return { positions, index }; | ||
} | ||
function applyVirtualStyleRulesToNode(styleNode, virtualStyleRules) { | ||
const sheet = styleNode.sheet; | ||
virtualStyleRules.forEach((rule) => { | ||
if (rule.type === exports.StyleRuleType.Insert) { | ||
try { | ||
if (Array.isArray(rule.index)) { | ||
const { positions, index } = getPositionsAndIndex(rule.index); | ||
const nestedRule = getNestedRule(sheet.cssRules, positions); | ||
nestedRule.insertRule(rule.cssText, index); | ||
} | ||
else { | ||
sheet.insertRule(rule.cssText, rule.index); | ||
} | ||
} | ||
catch (e) { | ||
} | ||
} | ||
else if (rule.type === exports.StyleRuleType.Remove) { | ||
try { | ||
if (Array.isArray(rule.index)) { | ||
const { positions, index } = getPositionsAndIndex(rule.index); | ||
const nestedRule = getNestedRule(sheet.cssRules, positions); | ||
nestedRule.deleteRule(index || 0); | ||
} | ||
else { | ||
sheet.deleteRule(rule.index); | ||
} | ||
} | ||
catch (e) { | ||
} | ||
} | ||
else if (rule.type === exports.StyleRuleType.SetProperty) { | ||
const nativeRule = getNestedRule(sheet.cssRules, rule.index); | ||
nativeRule.style.setProperty(rule.property, rule.value, rule.priority); | ||
} | ||
else if (rule.type === exports.StyleRuleType.RemoveProperty) { | ||
const nativeRule = getNestedRule(sheet.cssRules, rule.index); | ||
nativeRule.style.removeProperty(rule.property); | ||
} | ||
}); | ||
} | ||
@@ -1062,3 +1009,4 @@ class RRDocument extends BaseRRDocumentImpl(BaseRRNode) { | ||
if (node.nodeName === 'IFRAME') { | ||
walk(node.contentDocument, rrNode); | ||
const iframeDoc = node.contentDocument; | ||
iframeDoc && walk(iframeDoc, rrNode); | ||
} | ||
@@ -1120,2 +1068,8 @@ else if (node.nodeType === exports.NodeType.DOCUMENT_NODE || | ||
replace(id, n) { | ||
const oldNode = this.getNode(id); | ||
if (oldNode) { | ||
const meta = this.nodeMetaMap.get(oldNode); | ||
if (meta) | ||
this.nodeMetaMap.set(n, meta); | ||
} | ||
this.idNodeMap.set(id, n); | ||
@@ -1122,0 +1076,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){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 R(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 R{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/"},E={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 y(o,n,r,s){const i=o.childNodes,a=n.childNodes;s=s||n.mirror||n.ownerDocument.mirror,(i.length>0||a.length>0)&&D(Array.from(i),a,o,r,s);let d=null,c=null;switch(n.RRNodeType){case t.Document:c=n.scrollData;break;case t.Element:{const t=o,i=n;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,i,s),c=i.scrollData,d=i.inputData,i.tagName){case"AUDIO":case"VIDEO":{const e=o,t=i;void 0!==t.paused&&(t.paused?e.pause():e.play()),void 0!==t.muted&&(e.muted=t.muted),void 0!==t.volume&&(e.volume=t.volume),void 0!==t.currentTime&&(e.currentTime=t.currentTime),void 0!==t.playbackRate&&(e.playbackRate=t.playbackRate);break}case"CANVAS":{const e=n;if(null!==e.rr_dataURL){const o=document.createElement("img");o.onload=()=>{const e=t.getContext("2d");e&&e.drawImage(o,0,0,o.width,o.height)},o.src=e.rr_dataURL}e.canvasMutations.forEach((e=>r.applyCanvas(e.event,e.mutation,o)))}break;case"STYLE":!function(t,o){const n=t.sheet;o.forEach((t=>{if(t.type===e.StyleRuleType.Insert)try{if(Array.isArray(t.index)){const{positions:e,index:o}=w(t.index);C(n.cssRules,e).insertRule(t.cssText,o)}else n.insertRule(t.cssText,t.index)}catch(e){}else if(t.type===e.StyleRuleType.Remove)try{if(Array.isArray(t.index)){const{positions:e,index:o}=w(t.index);C(n.cssRules,e).deleteRule(o||0)}else n.deleteRule(t.index)}catch(e){}else if(t.type===e.StyleRuleType.SetProperty){C(n.cssRules,t.index).style.setProperty(t.property,t.value,t.priority)}else if(t.type===e.StyleRuleType.RemoveProperty){C(n.cssRules,t.index).style.removeProperty(t.property)}}))}(t,n.rules)}if(i.shadowRoot){t.shadowRoot||t.attachShadow({mode:"open"});const e=t.shadowRoot.childNodes,o=i.shadowRoot.childNodes;(e.length>0||o.length>0)&&D(Array.from(e),o,t.shadowRoot,r,s)}break}case t.Text:case t.Comment:case t.CDATA:o.textContent!==n.data&&(o.textContent=n.data)}if(c&&r.applyScroll(c,!0),d&&r.applyInput(d),"IFRAME"===n.nodeName){const e=o.contentDocument,t=n;if(e){const o=s.getMeta(t.contentDocument);o&&r.mirror.add(e,Object.assign({},o)),y(e,t.contentDocument,r,s)}}}function D(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 R=r.mirror.getId(p),T=r.mirror.getId(m),E=s.getId(N),D=s.getId(f);if(void 0===p)p=e[++c];else if(void 0===m)m=e[--l];else if(-1!==R&&R===E)y(p,N,r,s),p=e[++c],N=o[++u];else if(-1!==T&&T===D)y(m,f,r,s),m=e[--l],f=o[--h];else if(-1!==R&&R===D)n.insertBefore(p,m.nextSibling),y(p,f,r,s),p=e[++c],f=o[--h];else if(-1!==T&&T===E)n.insertBefore(m,p),y(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),y(t,N,r,s),e[d]=void 0}else{const o=g(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),y(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=g(o[u],r.mirror,s);n.insertBefore(e,t),y(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 g(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=E[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}function C(e,t){const o=e[t[0]];return 1===t.length?o:C(o.cssRules[t[1]].cssRules,t.slice(2))}var M;function w(e){const t=[...e],o=t.pop();return{positions:t,index:o}}e.StyleRuleType=void 0,(M=e.StyleRuleType||(e.StyleRuleType={}))[M.Insert=0]="Insert",M[M.Remove=1]="Remove",M[M.Snapshot=2]="Snapshot",M[M.SetProperty=3]="SetProperty",M[M.RemoveProperty=4]="RemoveProperty";class O extends(l(c)){constructor(e){super(),this.UNSERIALIZED_STARTING_ID=-2,this._unserializedId=this.UNSERIALIZED_STARTING_ID,this.mirror=k(),this.scrollData=null,e&&(this.mirror=e)}get unserializedId(){return this._unserializedId--}createDocument(e,t,o){return new O}createDocumentType(e,t,o){const n=new x(e,t,o);return n.ownerDocument=this,n}createElement(e){const t=e.toUpperCase();let o;switch(t){case"AUDIO":case"VIDEO":o=new I(t);break;case"IFRAME":o=new S(t,this.mirror);break;case"CANVAS":o=new v(t);break;case"STYLE":o=new b(t);break;default:o=new A(t)}return o.ownerDocument=this,o}createComment(e){const t=new L(e);return t.ownerDocument=this,t}createCDATASection(e){const t=new F(e);return t.ownerDocument=this,t}createTextNode(e){const t=new _(e);return t.ownerDocument=this,t}destroyTree(){this.childNodes=[],this.mirror.reset()}open(){super.open(),this._unserializedId=this.UNSERIALIZED_STARTING_ID}}const x=u(c);class A extends(h(c)){constructor(){super(...arguments),this.inputData=null,this.scrollData=null}}class I extends(p(A)){}class v extends A{constructor(){super(...arguments),this.rr_dataURL=null,this.canvasMutations=[]}getContext(){return null}}class b extends A{constructor(){super(...arguments),this.rules=[]}}class S extends A{constructor(e,t){super(e),this.contentDocument=new O,this.contentDocument.mirror=t}}const _=m(c),L=N(c),F=f(c);function U(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 O&&(a||(a=P(s,o.unserializedId),n.add(t,a)),o.mirror.add(s,Object.assign({},a))),s}function k(){return new B}class B{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){this.idNodeMap.set(e,t)}reset(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}}function P(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 G(e,o,n){let r=`${n}${o.getId(e)} ${e.toString()}\n`;if(e.RRNodeType===t.Element){const t=e;t.shadowRoot&&(r+=G(t.shadowRoot,o,n+" "))}for(const t of e.childNodes)r+=G(t,o,n+" ");return"IFRAME"===e.nodeName&&(r+=G(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=R,e.Mirror=B,e.RRCDATASection=F,e.RRCanvasElement=v,e.RRComment=L,e.RRDocument=O,e.RRDocumentType=x,e.RRElement=A,e.RRIFrameElement=S,e.RRMediaElement=I,e.RRNode=c,e.RRStyleElement=b,e.RRText=_,e.buildFromDom=function(t,n=function(){return new o}(),r=new O){return function t(o,s){const i=U(o,r,n,s);null!==i&&("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?t(o.contentDocument,i):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=U,e.createMirror=k,e.createOrGetNode=g,e.diff=y,e.getDefaultSN=P,e.printRRDom=function(e,t){return G(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 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}({}); | ||
//# sourceMappingURL=rrdom.min.js.map |
import { Mirror as NodeMirror } from 'rrweb-snapshot'; | ||
import type { canvasMutationData, canvasEventWithTime, inputData, scrollData } from 'rrweb/src/types'; | ||
import type { canvasMutationData, canvasEventWithTime, inputData, scrollData, styleDeclarationData, styleSheetRuleData } from 'rrweb/src/types'; | ||
import type { IRRNode } from './document'; | ||
@@ -10,40 +10,5 @@ import type { Mirror } from '.'; | ||
applyScroll: (data: scrollData, isSync: boolean) => void; | ||
applyStyleSheetMutation: (data: styleDeclarationData | styleSheetRuleData, styleSheet: CSSStyleSheet) => 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 getNestedRule(rules: CSSRuleList, position: number[]): CSSGroupingRule; | ||
export declare enum StyleRuleType { | ||
Insert = 0, | ||
Remove = 1, | ||
Snapshot = 2, | ||
SetProperty = 3, | ||
RemoveProperty = 4 | ||
} | ||
declare type InsertRule = { | ||
cssText: string; | ||
type: StyleRuleType.Insert; | ||
index?: number | number[]; | ||
}; | ||
declare type RemoveRule = { | ||
type: StyleRuleType.Remove; | ||
index: number | number[]; | ||
}; | ||
declare type SetPropertyRule = { | ||
type: StyleRuleType.SetProperty; | ||
index: number[]; | ||
property: string; | ||
value: string | null; | ||
priority: string | undefined; | ||
}; | ||
declare type RemovePropertyRule = { | ||
type: StyleRuleType.RemoveProperty; | ||
index: number[]; | ||
property: string; | ||
}; | ||
export declare type VirtualStyleRules = Array<InsertRule | RemoveRule | SetPropertyRule | RemovePropertyRule>; | ||
export declare function getPositionsAndIndex(nestedIndex: number[]): { | ||
positions: number[]; | ||
index: number | undefined; | ||
}; | ||
export declare function applyVirtualStyleRulesToNode(styleNode: HTMLStyleElement, virtualStyleRules: VirtualStyleRules): void; | ||
export {}; |
import { NodeType as RRNodeType } from 'rrweb-snapshot'; | ||
import type { Mirror as NodeMirror, IMirror, serializedNodeWithId } from 'rrweb-snapshot'; | ||
import type { canvasMutationData, canvasEventWithTime, inputData, scrollData } from 'rrweb/src/types'; | ||
import type { VirtualStyleRules } from './diff'; | ||
import type { canvasMutationData, canvasEventWithTime, inputData, scrollData, styleSheetRuleData, styleDeclarationData } from 'rrweb/src/types'; | ||
import { BaseRRNode as RRNode, IRRDocument, IRRElement, IRRNode, IRRDocumentType, IRRText, IRRComment } from './document'; | ||
@@ -264,3 +263,3 @@ declare const RRDocument_base: { | ||
export declare class RRStyleElement extends RRElement { | ||
rules: VirtualStyleRules; | ||
rules: (styleSheetRuleData | styleDeclarationData)[]; | ||
} | ||
@@ -371,3 +370,3 @@ export declare class RRIFrameElement extends RRElement { | ||
export { RRNode }; | ||
export { diff, createOrGetNode, StyleRuleType, ReplayerHandler, VirtualStyleRules, } from './diff'; | ||
export { diff, createOrGetNode, ReplayerHandler } from './diff'; | ||
export * from './document'; |
@@ -53,2 +53,8 @@ var NodeType$1; | ||
Mirror.prototype.replace = function (id, n) { | ||
var oldNode = this.getNode(id); | ||
if (oldNode) { | ||
var meta = this.nodeMetaMap.get(oldNode); | ||
if (meta) | ||
this.nodeMetaMap.set(n, meta); | ||
} | ||
this.idNodeMap.set(id, n); | ||
@@ -618,3 +624,7 @@ }; | ||
case 'STYLE': | ||
applyVirtualStyleRulesToNode(oldElement, newTree.rules); | ||
{ | ||
const styleSheet = oldElement.sheet; | ||
styleSheet && | ||
newTree.rules.forEach((data) => replayer.applyStyleSheetMutation(data, styleSheet)); | ||
} | ||
break; | ||
@@ -817,65 +827,2 @@ } | ||
} | ||
function getNestedRule(rules, position) { | ||
const rule = rules[position[0]]; | ||
if (position.length === 1) { | ||
return rule; | ||
} | ||
else { | ||
return getNestedRule(rule.cssRules[position[1]].cssRules, position.slice(2)); | ||
} | ||
} | ||
var StyleRuleType; | ||
(function (StyleRuleType) { | ||
StyleRuleType[StyleRuleType["Insert"] = 0] = "Insert"; | ||
StyleRuleType[StyleRuleType["Remove"] = 1] = "Remove"; | ||
StyleRuleType[StyleRuleType["Snapshot"] = 2] = "Snapshot"; | ||
StyleRuleType[StyleRuleType["SetProperty"] = 3] = "SetProperty"; | ||
StyleRuleType[StyleRuleType["RemoveProperty"] = 4] = "RemoveProperty"; | ||
})(StyleRuleType || (StyleRuleType = {})); | ||
function getPositionsAndIndex(nestedIndex) { | ||
const positions = [...nestedIndex]; | ||
const index = positions.pop(); | ||
return { positions, index }; | ||
} | ||
function applyVirtualStyleRulesToNode(styleNode, virtualStyleRules) { | ||
const sheet = styleNode.sheet; | ||
virtualStyleRules.forEach((rule) => { | ||
if (rule.type === StyleRuleType.Insert) { | ||
try { | ||
if (Array.isArray(rule.index)) { | ||
const { positions, index } = getPositionsAndIndex(rule.index); | ||
const nestedRule = getNestedRule(sheet.cssRules, positions); | ||
nestedRule.insertRule(rule.cssText, index); | ||
} | ||
else { | ||
sheet.insertRule(rule.cssText, rule.index); | ||
} | ||
} | ||
catch (e) { | ||
} | ||
} | ||
else if (rule.type === StyleRuleType.Remove) { | ||
try { | ||
if (Array.isArray(rule.index)) { | ||
const { positions, index } = getPositionsAndIndex(rule.index); | ||
const nestedRule = getNestedRule(sheet.cssRules, positions); | ||
nestedRule.deleteRule(index || 0); | ||
} | ||
else { | ||
sheet.deleteRule(rule.index); | ||
} | ||
} | ||
catch (e) { | ||
} | ||
} | ||
else if (rule.type === StyleRuleType.SetProperty) { | ||
const nativeRule = getNestedRule(sheet.cssRules, rule.index); | ||
nativeRule.style.setProperty(rule.property, rule.value, rule.priority); | ||
} | ||
else if (rule.type === StyleRuleType.RemoveProperty) { | ||
const nativeRule = getNestedRule(sheet.cssRules, rule.index); | ||
nativeRule.style.removeProperty(rule.property); | ||
} | ||
}); | ||
} | ||
@@ -1059,3 +1006,4 @@ class RRDocument extends BaseRRDocumentImpl(BaseRRNode) { | ||
if (node.nodeName === 'IFRAME') { | ||
walk(node.contentDocument, rrNode); | ||
const iframeDoc = node.contentDocument; | ||
iframeDoc && walk(iframeDoc, rrNode); | ||
} | ||
@@ -1117,2 +1065,8 @@ else if (node.nodeType === NodeType.DOCUMENT_NODE || | ||
replace(id, n) { | ||
const oldNode = this.getNode(id); | ||
if (oldNode) { | ||
const meta = this.nodeMetaMap.get(oldNode); | ||
if (meta) | ||
this.nodeMetaMap.set(n, meta); | ||
} | ||
this.idNodeMap.set(id, n); | ||
@@ -1188,2 +1142,2 @@ } | ||
export { BaseRRCDATASectionImpl, BaseRRCommentImpl, BaseRRDocumentImpl, BaseRRDocumentTypeImpl, BaseRRElementImpl, BaseRRMediaElementImpl, BaseRRNode, BaseRRTextImpl, ClassList, Mirror, NodeType, RRCDATASection, RRCanvasElement, RRComment, RRDocument, RRDocumentType, RRElement, RRIFrameElement, RRMediaElement, BaseRRNode as RRNode, RRStyleElement, RRText, StyleRuleType, buildFromDom, buildFromNode, createMirror, createOrGetNode, diff, getDefaultSN, printRRDom }; | ||
export { BaseRRCDATASectionImpl, BaseRRCommentImpl, BaseRRDocumentImpl, BaseRRDocumentTypeImpl, BaseRRElementImpl, BaseRRMediaElementImpl, BaseRRNode, BaseRRTextImpl, ClassList, Mirror, NodeType, RRCDATASection, RRCanvasElement, RRComment, RRDocument, RRDocumentType, RRElement, RRIFrameElement, RRMediaElement, BaseRRNode as RRNode, RRStyleElement, RRText, buildFromDom, buildFromNode, createMirror, createOrGetNode, diff, getDefaultSN, printRRDom }; |
@@ -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){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(u(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 u(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 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=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 R={svg:"http://www.w3.org/2000/svg","xlink:href":"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},T={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&&R[o])e.setAttributeNS(R[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":!function(e,t){const n=e.sheet;t.forEach((e=>{if(e.type===M.Insert)try{if(Array.isArray(e.index)){const{positions:t,index:o}=w(e.index);C(n.cssRules,t).insertRule(e.cssText,o)}else n.insertRule(e.cssText,e.index)}catch(e){}else if(e.type===M.Remove)try{if(Array.isArray(e.index)){const{positions:t,index:o}=w(e.index);C(n.cssRules,t).deleteRule(o||0)}else n.deleteRule(e.index)}catch(e){}else if(e.type===M.SetProperty){C(n.cssRules,e.index).style.setProperty(e.property,e.value,e.priority)}else if(e.type===M.RemoveProperty){C(n.cssRules,e.index).style.removeProperty(e.property)}}))}(e,n.rules)}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,u=0,h=n.length-1,p=t[c],m=t[l],N=n[u],f=n[h];for(;c<=l&&u<=h;){const E=s.mirror.getId(p),R=s.mirror.getId(m),T=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===T)D(p,N,s,r),p=t[++c],N=n[++u];else if(-1!==R&&R===g)D(m,f,s,r),m=t[--l],f=n[--h];else if(-1!==E&&E===g)o.insertBefore(p,m.nextSibling),D(p,f,s,r),p=t[++c],f=n[--h];else if(-1!==R&&R===T)o.insertBefore(m,p),D(m,N,s,r),m=t[--l],N=n[++u];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=y(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[++u]}}if(c>l){const e=n[h+1];let t=null;for(e&&o.childNodes.forEach((n=>{s.mirror.getId(n)===r.getId(e)&&(t=n)}));u<=h;++u){const e=y(n[u],s.mirror,r);o.insertBefore(e,t),D(e,n[u],s,r)}}else if(u>h)for(;c<=l;c++){const e=t[c];e&&(o.removeChild(e),s.mirror.removeNodeFromMap(e))}}function y(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=T[e]||e,i=r&&"isSVG"in r&&(null==r?void 0:r.isSVG)?document.createElementNS(R.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}function C(e,t){const n=e[t[0]];return 1===t.length?n:C(n.cssRules[t[1]].cssRules,t.slice(2))}var M;function w(e){const t=[...e],n=t.pop();return{positions:t,index:n}}!function(e){e[e.Insert=0]="Insert",e[e.Remove=1]="Remove",e[e.Snapshot=2]="Snapshot",e[e.SetProperty=3]="SetProperty",e[e.RemoveProperty=4]="RemoveProperty"}(M||(M={}));class O 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 O}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 I(t);break;case"IFRAME":n=new _(t,this.mirror);break;case"CANVAS":n=new v(t);break;case"STYLE":n=new b(t);break;default:n=new A(t)}return n.ownerDocument=this,n}createComment(e){const t=new L(e);return t.ownerDocument=this,t}createCDATASection(e){const t=new F(e);return t.ownerDocument=this,t}createTextNode(e){const t=new S(e);return t.ownerDocument=this,t}destroyTree(){this.childNodes=[],this.mirror.reset()}open(){super.open(),this._unserializedId=this.UNSERIALIZED_STARTING_ID}}const x=l(d);class A extends(u(d)){constructor(){super(...arguments),this.inputData=null,this.scrollData=null}}class I extends(h(A)){}class v extends A{constructor(){super(...arguments),this.rr_dataURL=null,this.canvasMutations=[]}getContext(){return null}}class b extends A{constructor(){super(...arguments),this.rules=[]}}class _ extends A{constructor(e,t){super(e),this.contentDocument=new O,this.contentDocument.mirror=t}}const S=p(d),L=m(d),F=N(d);function U(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 O&&(i||(i=G(s,t.unserializedId),n.add(e,i)),t.mirror.add(s,Object.assign({},i))),s}function k(e,n=function(){return new t}(),o=new O){return function e(t,s){const r=U(t,o,n,s);null!==r&&("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?e(t.contentDocument,r):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 P(){return new B}class B{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){this.idNodeMap.set(e,t)}reset(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap}}function G(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 $(e,t){return Y(e,t,"")}function Y(t,n,o){let s=`${o}${n.getId(t)} ${t.toString()}\n`;if(t.RRNodeType===e.Element){const e=t;e.shadowRoot&&(s+=Y(e.shadowRoot,n,o+" "))}for(const e of t.childNodes)s+=Y(e,n,o+" ");return"IFRAME"===t.nodeName&&(s+=Y(t.contentDocument,n,o+" ")),s}export{N as BaseRRCDATASectionImpl,m as BaseRRCommentImpl,c as BaseRRDocumentImpl,l as BaseRRDocumentTypeImpl,u as BaseRRElementImpl,h as BaseRRMediaElementImpl,d as BaseRRNode,p as BaseRRTextImpl,f as ClassList,B as Mirror,E as NodeType,F as RRCDATASection,v as RRCanvasElement,L as RRComment,O as RRDocument,x as RRDocumentType,A as RRElement,_ as RRIFrameElement,I as RRMediaElement,d as RRNode,b as RRStyleElement,S as RRText,M as StyleRuleType,k as buildFromDom,U as buildFromNode,P as createMirror,y as createOrGetNode,D as diff,G as getDefaultSN,$ 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 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}; | ||
//# sourceMappingURL=rrdom.min.js.map |
import { Mirror as NodeMirror } from 'rrweb-snapshot'; | ||
import type { canvasMutationData, canvasEventWithTime, inputData, scrollData } from 'rrweb/src/types'; | ||
import type { canvasMutationData, canvasEventWithTime, inputData, scrollData, styleDeclarationData, styleSheetRuleData } from 'rrweb/src/types'; | ||
import type { IRRNode } from './document'; | ||
@@ -10,40 +10,5 @@ import type { Mirror } from '.'; | ||
applyScroll: (data: scrollData, isSync: boolean) => void; | ||
applyStyleSheetMutation: (data: styleDeclarationData | styleSheetRuleData, styleSheet: CSSStyleSheet) => 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 getNestedRule(rules: CSSRuleList, position: number[]): CSSGroupingRule; | ||
export declare enum StyleRuleType { | ||
Insert = 0, | ||
Remove = 1, | ||
Snapshot = 2, | ||
SetProperty = 3, | ||
RemoveProperty = 4 | ||
} | ||
declare type InsertRule = { | ||
cssText: string; | ||
type: StyleRuleType.Insert; | ||
index?: number | number[]; | ||
}; | ||
declare type RemoveRule = { | ||
type: StyleRuleType.Remove; | ||
index: number | number[]; | ||
}; | ||
declare type SetPropertyRule = { | ||
type: StyleRuleType.SetProperty; | ||
index: number[]; | ||
property: string; | ||
value: string | null; | ||
priority: string | undefined; | ||
}; | ||
declare type RemovePropertyRule = { | ||
type: StyleRuleType.RemoveProperty; | ||
index: number[]; | ||
property: string; | ||
}; | ||
export declare type VirtualStyleRules = Array<InsertRule | RemoveRule | SetPropertyRule | RemovePropertyRule>; | ||
export declare function getPositionsAndIndex(nestedIndex: number[]): { | ||
positions: number[]; | ||
index: number | undefined; | ||
}; | ||
export declare function applyVirtualStyleRulesToNode(styleNode: HTMLStyleElement, virtualStyleRules: VirtualStyleRules): void; | ||
export {}; |
import { NodeType as RRNodeType } from 'rrweb-snapshot'; | ||
import type { Mirror as NodeMirror, IMirror, serializedNodeWithId } from 'rrweb-snapshot'; | ||
import type { canvasMutationData, canvasEventWithTime, inputData, scrollData } from 'rrweb/src/types'; | ||
import type { VirtualStyleRules } from './diff'; | ||
import type { canvasMutationData, canvasEventWithTime, inputData, scrollData, styleSheetRuleData, styleDeclarationData } from 'rrweb/src/types'; | ||
import { BaseRRNode as RRNode, IRRDocument, IRRElement, IRRNode, IRRDocumentType, IRRText, IRRComment } from './document'; | ||
@@ -264,3 +263,3 @@ declare const RRDocument_base: { | ||
export declare class RRStyleElement extends RRElement { | ||
rules: VirtualStyleRules; | ||
rules: (styleSheetRuleData | styleDeclarationData)[]; | ||
} | ||
@@ -371,3 +370,3 @@ export declare class RRIFrameElement extends RRElement { | ||
export { RRNode }; | ||
export { diff, createOrGetNode, StyleRuleType, ReplayerHandler, VirtualStyleRules, } from './diff'; | ||
export { diff, createOrGetNode, ReplayerHandler } from './diff'; | ||
export * from './document'; |
@@ -57,2 +57,8 @@ 'use strict'; | ||
Mirror.prototype.replace = function (id, n) { | ||
var oldNode = this.getNode(id); | ||
if (oldNode) { | ||
var meta = this.nodeMetaMap.get(oldNode); | ||
if (meta) | ||
this.nodeMetaMap.set(n, meta); | ||
} | ||
this.idNodeMap.set(id, n); | ||
@@ -622,3 +628,7 @@ }; | ||
case 'STYLE': | ||
applyVirtualStyleRulesToNode(oldElement, newTree.rules); | ||
{ | ||
const styleSheet = oldElement.sheet; | ||
styleSheet && | ||
newTree.rules.forEach((data) => replayer.applyStyleSheetMutation(data, styleSheet)); | ||
} | ||
break; | ||
@@ -821,65 +831,2 @@ } | ||
} | ||
function getNestedRule(rules, position) { | ||
const rule = rules[position[0]]; | ||
if (position.length === 1) { | ||
return rule; | ||
} | ||
else { | ||
return getNestedRule(rule.cssRules[position[1]].cssRules, position.slice(2)); | ||
} | ||
} | ||
exports.StyleRuleType = void 0; | ||
(function (StyleRuleType) { | ||
StyleRuleType[StyleRuleType["Insert"] = 0] = "Insert"; | ||
StyleRuleType[StyleRuleType["Remove"] = 1] = "Remove"; | ||
StyleRuleType[StyleRuleType["Snapshot"] = 2] = "Snapshot"; | ||
StyleRuleType[StyleRuleType["SetProperty"] = 3] = "SetProperty"; | ||
StyleRuleType[StyleRuleType["RemoveProperty"] = 4] = "RemoveProperty"; | ||
})(exports.StyleRuleType || (exports.StyleRuleType = {})); | ||
function getPositionsAndIndex(nestedIndex) { | ||
const positions = [...nestedIndex]; | ||
const index = positions.pop(); | ||
return { positions, index }; | ||
} | ||
function applyVirtualStyleRulesToNode(styleNode, virtualStyleRules) { | ||
const sheet = styleNode.sheet; | ||
virtualStyleRules.forEach((rule) => { | ||
if (rule.type === exports.StyleRuleType.Insert) { | ||
try { | ||
if (Array.isArray(rule.index)) { | ||
const { positions, index } = getPositionsAndIndex(rule.index); | ||
const nestedRule = getNestedRule(sheet.cssRules, positions); | ||
nestedRule.insertRule(rule.cssText, index); | ||
} | ||
else { | ||
sheet.insertRule(rule.cssText, rule.index); | ||
} | ||
} | ||
catch (e) { | ||
} | ||
} | ||
else if (rule.type === exports.StyleRuleType.Remove) { | ||
try { | ||
if (Array.isArray(rule.index)) { | ||
const { positions, index } = getPositionsAndIndex(rule.index); | ||
const nestedRule = getNestedRule(sheet.cssRules, positions); | ||
nestedRule.deleteRule(index || 0); | ||
} | ||
else { | ||
sheet.deleteRule(rule.index); | ||
} | ||
} | ||
catch (e) { | ||
} | ||
} | ||
else if (rule.type === exports.StyleRuleType.SetProperty) { | ||
const nativeRule = getNestedRule(sheet.cssRules, rule.index); | ||
nativeRule.style.setProperty(rule.property, rule.value, rule.priority); | ||
} | ||
else if (rule.type === exports.StyleRuleType.RemoveProperty) { | ||
const nativeRule = getNestedRule(sheet.cssRules, rule.index); | ||
nativeRule.style.removeProperty(rule.property); | ||
} | ||
}); | ||
} | ||
@@ -1063,3 +1010,4 @@ class RRDocument extends BaseRRDocumentImpl(BaseRRNode) { | ||
if (node.nodeName === 'IFRAME') { | ||
walk(node.contentDocument, rrNode); | ||
const iframeDoc = node.contentDocument; | ||
iframeDoc && walk(iframeDoc, rrNode); | ||
} | ||
@@ -1121,2 +1069,8 @@ else if (node.nodeType === exports.NodeType.DOCUMENT_NODE || | ||
replace(id, n) { | ||
const oldNode = this.getNode(id); | ||
if (oldNode) { | ||
const meta = this.nodeMetaMap.get(oldNode); | ||
if (meta) | ||
this.nodeMetaMap.set(n, meta); | ||
} | ||
this.idNodeMap.set(id, n); | ||
@@ -1123,0 +1077,0 @@ } |
{ | ||
"name": "rrdom", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"homepage": "https://github.com/rrweb-io/rrweb/tree/main/packages/rrdom#readme", | ||
@@ -49,5 +49,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"rrweb-snapshot": "^2.0.0-alpha.2" | ||
"rrweb-snapshot": "^2.0.0-alpha.3" | ||
}, | ||
"gitHead": "58cd78799bdf26be5cc78dbf44a5cc6c093b1470" | ||
"gitHead": "e86d482ffd2f7b58ae1d6b67702ad5dc32bed0b5" | ||
} |
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
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
1448699
13548