rrweb
Version:
record and replay the web
3 lines (2 loc) • 28.3 kB
JavaScript
var rrweb=function(e){"use strict";var t,n=function(){return(n=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};!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=1;function r(e){try{var t=e.rules||e.cssRules;return t?Array.from(t).reduce(function(e,t){return e+t.cssText},""):null}catch(e){return null}}var i=/url\((?:'([^']*)'|"([^"]*)"|([^)]*))\)/gm,a=/^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/,s=/^(data:)([\w\/\+]+);(charset=[\w-]+|base64).*,(.*)/gi;function l(e,t){return e.replace(i,function(e,n,o,r){var i,l=n||o||r;if(!l)return e;if(!a.test(l))return"url('"+l+"')";if(s.test(l))return"url("+l+")";if("/"===l[0])return"url('"+(((i=t).indexOf("//")>-1?i.split("/").slice(0,3).join("/"):i.split("/")[0]).split("?")[0]+l)+"')";var c=t.split("/"),u=l.split("/");c.pop();for(var d=0,f=u;d<f.length;d++){var p=f[d];"."!==p&&(".."===p?c.pop():c.push(p))}return"url('"+c.join("/")+"')"})}function c(e,t){var n=e.createElement("a");return n.href=t,n.href}function u(e,n,i,a,s){void 0===s&&(s=!1);var d=function(e,n,o){switch(e.nodeType){case e.DOCUMENT_NODE:return{type:t.Document,childNodes:[]};case e.DOCUMENT_TYPE_NODE:return{type:t.DocumentType,name:e.name,publicId:e.publicId,systemId:e.systemId};case e.ELEMENT_NODE:var i=!1;"string"==typeof o?i=e.classList.contains(o):e.classList.forEach(function(e){o.test(e)&&(i=!0)});for(var a=e.tagName.toLowerCase(),s={},u=0,d=Array.from(e.attributes);u<d.length;u++){var f=d[u],p=f.name,h=f.value;s[p]="src"===p||"href"===p?c(n,h):"style"===p?l(h,location.href):h}if("link"===a){var m,v=Array.from(n.styleSheets).find(function(t){return t.href===e.href});(m=r(v))&&(delete s.rel,delete s.href,s._cssText=l(m,v.href))}if("style"===a&&e.sheet&&!e.innerText.trim().length&&(m=r(e.sheet))&&(s._cssText=l(m,location.href)),"input"!==a&&"textarea"!==a&&"select"!==a||(h=e.value,"radio"!==s.type&&"checkbox"!==s.type&&h?s.value=h:e.checked&&(s.checked=e.checked)),"option"===a){var y=e.parentElement;s.value===y.value&&(s.selected=e.selected)}if(i){var g=e.getBoundingClientRect(),b=g.width,w=g.height;s.rr_width=b+"px",s.rr_height=w+"px"}return{type:t.Element,tagName:a,attributes:s,childNodes:[],isSVG:(C=e,"svg"===C.tagName||C instanceof SVGElement||void 0),needBlock:i};case e.TEXT_NODE:var E=e.parentNode&&e.parentNode.tagName,N=e.textContent,T="STYLE"===E||void 0;return T&&N&&(N=l(N,location.href)),"SCRIPT"===E&&(N="SCRIPT_PLACEHOLDER"),{type:t.Text,textContent:N||"",isStyle:T};case e.CDATA_SECTION_NODE:return{type:t.CDATA,textContent:""};case e.COMMENT_NODE:return{type:t.Comment,textContent:e.textContent||""};default:return!1}var C}(e,n,a);if(!d)return console.warn(e,"not serialized"),null;var f=Object.assign(d,{id:o++});e.__sn=f,i[f.id]=e;var p=!s;if(f.type===t.Element&&(p=p&&!f.needBlock,delete f.needBlock),(f.type===t.Document||f.type===t.Element)&&p)for(var h=0,m=Array.from(e.childNodes);h<m.length;h++){var v=u(m[h],n,i,a);v&&f.childNodes.push(v)}return f}function d(e,t){void 0===t&&(t="rr-block"),o=1;var n={};return[u(e,e,n,t),n]}var f={script:"noscript",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"};var p=/([^\r\n,{}]+)(,(?=[^}]*{)|\s*{)/g,h=/([^\\]):hover/g;function m(e){return e.replace(p,function(e,t,n){if(h.test(t)){var o=t.replace(h,"$1.\\:hover");return t.replace(/\s*$/,"")+", "+o.replace(/^\s*/,"")+n}return e})}function v(e,n){switch(e.type){case t.Document:return n.implementation.createDocument(null,"",null);case t.DocumentType:return n.implementation.createDocumentType(e.name,e.publicId,e.systemId);case t.Element:var o=function(e){var t=f[e.tagName]?f[e.tagName]:e.tagName;return"link"===t&&e.attributes._cssText&&(t="style"),t}(e),r=void 0;for(var i in r=e.isSVG?n.createElementNS("http://www.w3.org/2000/svg",o):n.createElement(o),e.attributes)if(e.attributes.hasOwnProperty(i)&&!i.startsWith("rr_")){var a=e.attributes[i];a="boolean"==typeof a?"":a;var s="textarea"===o&&"value"===i,l="style"===o&&"_cssText"===i;if(l&&(a=m(a)),s||l){var c=n.createTextNode(a);r.appendChild(c);continue}if("iframe"===o&&"src"===i)continue;try{r.setAttribute(i,a)}catch(e){}}else e.attributes.rr_width&&(r.style.width=e.attributes.rr_width),e.attributes.rr_height&&(r.style.height=e.attributes.rr_height);return r;case t.Text:return n.createTextNode(e.isStyle?m(e.textContent):e.textContent);case t.CDATA:return n.createCDATASection(e.textContent);case t.Comment:return n.createComment(e.textContent);default:return null}}function y(e,n,o,r){void 0===r&&(r=!1);var i=v(e,n);if(!i)return null;if(e.type===t.Document&&(n.close(),n.open(),i=n),i.__sn=e,o[e.id]=i,(e.type===t.Document||e.type===t.Element)&&!r)for(var a=0,s=e.childNodes;a<s.length;a++){var l=s[a],c=y(l,n,o);c?i.appendChild(c):console.warn("Failed to rebuild",l)}return i}function g(e,t,n){void 0===n&&(n=document);var o={capture:!0,passive:!0};return n.addEventListener(e,t,o),function(){return n.removeEventListener(e,t,o)}}var b,w,E,N,T={map:{},getId:function(e){return e.__sn?e.__sn.id:-1},getNode:function(e){return T.map[e]||null},removeNodeFromMap:function(e){var t=e.__sn&&e.__sn.id;delete T.map[t],e.childNodes&&e.childNodes.forEach(function(e){return T.removeNodeFromMap(e)})},has:function(e){return T.map.hasOwnProperty(e)}};function C(e,t,n){void 0===n&&(n={});var o=null,r=0;return function(){var i=Date.now();r||!1!==n.leading||(r=i);var a=t-(i-r),s=this,l=arguments;a<=0||a>t?(o&&(window.clearTimeout(o),o=null),r=i,e.apply(s,l)):o||!1===n.trailing||(o=window.setTimeout(function(){r=!1===n.leading?0:Date.now(),o=null,e.apply(s,l)},a))}}function S(){return window.innerHeight||document.documentElement&&document.documentElement.clientHeight||document.body&&document.body.clientHeight}function I(){return window.innerWidth||document.documentElement&&document.documentElement.clientWidth||document.body&&document.body.clientWidth}function x(e,t){if(!e)return!1;if(e.nodeType===e.ELEMENT_NODE){var n=!1;return"string"==typeof t?n=e.classList.contains(t):e.classList.forEach(function(e){t.test(e)&&(n=!0)}),n||x(e.parentNode,t)}return x(e.parentNode,t)}function M(e,t){var n=new MutationObserver(function(n){var o=[],r=[],i=[],a=[],s=new Set,l=new Set,c=function(e){x(e,t)||(s.add(e),l.delete(e),e.childNodes.forEach(function(e){return c(e)}))};n.forEach(function(e){var n=e.type,a=e.target,u=e.oldValue,d=e.addedNodes,f=e.removedNodes,p=e.attributeName;switch(n){case"characterData":var h=a.textContent;x(a,t)||h===u||o.push({value:h,node:a});break;case"attributes":h=a.getAttribute(p);if(x(a,t)||h===u)return;var m=r.find(function(e){return e.node===a});m||(m={node:a,attributes:{}},r.push(m)),m.attributes[p]=h;break;case"childList":d.forEach(function(e){return c(e)}),f.forEach(function(e){var n=T.getId(e),o=T.getId(a);x(e,t)||(s.has(e)?(!function e(t,n){t.delete(n),n.childNodes.forEach(function(n){return e(t,n)})}(s,e),l.add(e)):s.has(a)&&-1===n||function e(t){var n=T.getId(t);return!T.has(n)||(!t.parentNode||t.parentNode.nodeType!==t.DOCUMENT_NODE)&&(!t.parentNode||e(t.parentNode))}(a)||i.push({parentId:o,id:n}),T.removeNodeFromMap(e))})}}),Array.from(s).forEach(function(e){(function e(t,n){var o=n.parentNode;return!!o&&(!!t.has(o)||e(t,o))})(l,e)||function e(t,n){var o=n.parentNode;if(!o)return!1;var r=T.getId(o);return!!t.some(function(e){return e.id===r})||e(t,o)}(i,e)?l.add(e):a.push({parentId:T.getId(e.parentNode),previousId:e.previousSibling?T.getId(e.previousSibling):e.previousSibling,nextId:e.nextSibling?T.getId(e.nextSibling):e.nextSibling,node:u(e,document,T.map,t,!0)})});var d={texts:o.map(function(e){return{id:T.getId(e.node),value:e.value}}).filter(function(e){return T.has(e.id)}),attributes:r.map(function(e){return{id:T.getId(e.node),attributes:e.attributes}}).filter(function(e){return T.has(e.id)}),removes:i,adds:a};(d.texts.length||d.attributes.length||d.removes.length||d.adds.length)&&e(d)});return n.observe(document,{attributes:!0,attributeOldValue:!0,characterData:!0,characterDataOldValue:!0,childList:!0,subtree:!0}),n}function D(e,t){var n=[];return Object.keys(E).filter(function(e){return Number.isNaN(Number(e))}).forEach(function(o){var r=o.toLowerCase(),i=function(n){return function(o){if(!x(o.target,t)){var r=T.getId(o.target),i=o.clientX,a=o.clientY;e({type:E[n],id:r,x:i,y:a})}}}(o);n.push(g(r,i))}),function(){n.forEach(function(e){return e()})}}!function(e){e[e.DomContentLoaded=0]="DomContentLoaded",e[e.Load=1]="Load",e[e.FullSnapshot=2]="FullSnapshot",e[e.IncrementalSnapshot=3]="IncrementalSnapshot",e[e.Meta=4]="Meta"}(b||(b={})),function(e){e[e.Mutation=0]="Mutation",e[e.MouseMove=1]="MouseMove",e[e.MouseInteraction=2]="MouseInteraction",e[e.Scroll=3]="Scroll",e[e.ViewportResize=4]="ViewportResize",e[e.Input=5]="Input"}(w||(w={})),function(e){e[e.MouseUp=0]="MouseUp",e[e.MouseDown=1]="MouseDown",e[e.Click=2]="Click",e[e.ContextMenu=3]="ContextMenu",e[e.DblClick=4]="DblClick",e[e.Focus=5]="Focus",e[e.Blur=6]="Blur",e[e.TouchStart=7]="TouchStart",e[e.TouchMove=8]="TouchMove",e[e.TouchEnd=9]="TouchEnd"}(E||(E={})),function(e){e.Start="start",e.Pause="pause",e.Resume="resume",e.Resize="resize",e.Finish="finish",e.FullsnapshotRebuilded="fullsnapshot-rebuilded",e.LoadStylesheetStart="load-stylesheet-start",e.LoadStylesheetEnd="load-stylesheet-end",e.SkipStart="skip-start",e.SkipEnd="skip-end",e.MouseInteraction="mouse-interaction"}(N||(N={}));var k=["INPUT","TEXTAREA","SELECT"],O=new WeakMap;function L(e,t,o){function r(e){var n=e.target;if(n&&n.tagName&&!(k.indexOf(n.tagName)<0)&&!x(n,t)){var r=n.type;if("password"!==r&&!n.classList.contains(o)){var a=n.value,s=!1;"radio"!==r&&"checkbox"!==r||(s=n.checked),i(n,{text:a,isChecked:s});var l=n.name;"radio"===r&&l&&s&&document.querySelectorAll('input[type="radio"][name="'+l+'"]').forEach(function(e){e!==n&&i(e,{text:e.value,isChecked:!s})})}}}function i(t,o){var r=O.get(t);if(!r||r.text!==o.text||r.isChecked!==o.isChecked){O.set(t,o);var i=T.getId(t);e(n({},o,{id:i}))}}var a=["input","change"].map(function(e){return g(e,r)}),s=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value"),l=[[HTMLInputElement.prototype,"value"],[HTMLInputElement.prototype,"checked"],[HTMLSelectElement.prototype,"value"],[HTMLTextAreaElement.prototype,"value"]];return s&&s.set&&a.push.apply(a,l.map(function(e){return function e(t,n,o){var r=Object.getOwnPropertyDescriptor(t,n);return Object.defineProperty(t,n,{set:function(e){var t=this;setTimeout(function(){o.set.call(t,e)},0),r&&r.set&&r.set.call(this,e)}}),function(){return e(t,n,r||{})}}(e[0],e[1],{set:function(){r({target:this})}})})),function(){a.forEach(function(e){return e()})}}function A(e){var t,n,o,r,i=M(e.mutationCb,e.blockClass),a=(t=e.mousemoveCb,o=[],r=C(function(){var e=Date.now()-n;t(o.map(function(t){return t.timeOffset-=e,t})),o=[],n=null},500),g("mousemove",C(function(e){var t=e.clientX,i=e.clientY,a=e.target;n||(n=Date.now()),o.push({x:t,y:i,id:T.getId(a),timeOffset:Date.now()-n}),r()},50,{trailing:!1}))),s=D(e.mouseInteractionCb,e.blockClass),l=function(e,t){return g("scroll",C(function(n){if(n.target&&!x(n.target,t)){var o=T.getId(n.target);if(n.target===document){var r=document.scrollingElement||document.documentElement;e({id:o,x:r.scrollLeft,y:r.scrollTop})}else e({id:o,x:n.target.scrollLeft,y:n.target.scrollTop})}},100))}(e.scrollCb,e.blockClass),c=function(e){return g("resize",C(function(){var t=S(),n=I();e({width:Number(n),height:Number(t)})},200),window)}(e.viewportResizeCb),u=L(e.inputCb,e.blockClass,e.ignoreClass);return function(){i.disconnect(),a(),s(),l(),c(),u()}}function F(e){return n({},e,{timestamp:Date.now()})}function R(e){return e=e||Object.create(null),{on:function(t,n){(e[t]||(e[t]=[])).push(n)},off:function(t,n){e[t]&&e[t].splice(e[t].indexOf(n)>>>0,1)},emit:function(t,n){(e[t]||[]).slice().map(function(e){e(n)}),(e["*"]||[]).slice().map(function(e){e(t,n)})}}}var _=Object.freeze({default:R});var B,j=(function(e,t){!function(){e.exports={polyfill:function(){var e=window,t=document;if(!("scrollBehavior"in t.documentElement.style&&!0!==e.__forceSmoothScrollPolyfill__)){var n,o=e.HTMLElement||e.Element,r=468,i={scroll:e.scroll||e.scrollTo,scrollBy:e.scrollBy,elementScroll:o.prototype.scroll||l,scrollIntoView:o.prototype.scrollIntoView},a=e.performance&&e.performance.now?e.performance.now.bind(e.performance):Date.now,s=(n=e.navigator.userAgent,new RegExp(["MSIE ","Trident/","Edge/"].join("|")).test(n)?1:0);e.scroll=e.scrollTo=function(){void 0!==arguments[0]&&(!0!==c(arguments[0])?h.call(e,t.body,void 0!==arguments[0].left?~~arguments[0].left:e.scrollX||e.pageXOffset,void 0!==arguments[0].top?~~arguments[0].top:e.scrollY||e.pageYOffset):i.scroll.call(e,void 0!==arguments[0].left?arguments[0].left:"object"!=typeof arguments[0]?arguments[0]:e.scrollX||e.pageXOffset,void 0!==arguments[0].top?arguments[0].top:void 0!==arguments[1]?arguments[1]:e.scrollY||e.pageYOffset))},e.scrollBy=function(){void 0!==arguments[0]&&(c(arguments[0])?i.scrollBy.call(e,void 0!==arguments[0].left?arguments[0].left:"object"!=typeof arguments[0]?arguments[0]:0,void 0!==arguments[0].top?arguments[0].top:void 0!==arguments[1]?arguments[1]:0):h.call(e,t.body,~~arguments[0].left+(e.scrollX||e.pageXOffset),~~arguments[0].top+(e.scrollY||e.pageYOffset)))},o.prototype.scroll=o.prototype.scrollTo=function(){if(void 0!==arguments[0])if(!0!==c(arguments[0])){var e=arguments[0].left,t=arguments[0].top;h.call(this,this,void 0===e?this.scrollLeft:~~e,void 0===t?this.scrollTop:~~t)}else{if("number"==typeof arguments[0]&&void 0===arguments[1])throw new SyntaxError("Value could not be converted");i.elementScroll.call(this,void 0!==arguments[0].left?~~arguments[0].left:"object"!=typeof arguments[0]?~~arguments[0]:this.scrollLeft,void 0!==arguments[0].top?~~arguments[0].top:void 0!==arguments[1]?~~arguments[1]:this.scrollTop)}},o.prototype.scrollBy=function(){void 0!==arguments[0]&&(!0!==c(arguments[0])?this.scroll({left:~~arguments[0].left+this.scrollLeft,top:~~arguments[0].top+this.scrollTop,behavior:arguments[0].behavior}):i.elementScroll.call(this,void 0!==arguments[0].left?~~arguments[0].left+this.scrollLeft:~~arguments[0]+this.scrollLeft,void 0!==arguments[0].top?~~arguments[0].top+this.scrollTop:~~arguments[1]+this.scrollTop))},o.prototype.scrollIntoView=function(){if(!0!==c(arguments[0])){var n=function(e){for(;e!==t.body&&!1===f(e);)e=e.parentNode||e.host;return e}(this),o=n.getBoundingClientRect(),r=this.getBoundingClientRect();n!==t.body?(h.call(this,n,n.scrollLeft+r.left-o.left,n.scrollTop+r.top-o.top),"fixed"!==e.getComputedStyle(n).position&&e.scrollBy({left:o.left,top:o.top,behavior:"smooth"})):e.scrollBy({left:r.left,top:r.top,behavior:"smooth"})}else i.scrollIntoView.call(this,void 0===arguments[0]||arguments[0])}}function l(e,t){this.scrollLeft=e,this.scrollTop=t}function c(e){if(null===e||"object"!=typeof e||void 0===e.behavior||"auto"===e.behavior||"instant"===e.behavior)return!0;if("object"==typeof e&&"smooth"===e.behavior)return!1;throw new TypeError("behavior member of ScrollOptions "+e.behavior+" is not a valid value for enumeration ScrollBehavior.")}function u(e,t){return"Y"===t?e.clientHeight+s<e.scrollHeight:"X"===t?e.clientWidth+s<e.scrollWidth:void 0}function d(t,n){var o=e.getComputedStyle(t,null)["overflow"+n];return"auto"===o||"scroll"===o}function f(e){var t=u(e,"Y")&&d(e,"Y"),n=u(e,"X")&&d(e,"X");return t||n}function p(t){var n,o,i,s,l=(a()-t.startTime)/r;s=l=l>1?1:l,n=.5*(1-Math.cos(Math.PI*s)),o=t.startX+(t.x-t.startX)*n,i=t.startY+(t.y-t.startY)*n,t.method.call(t.scrollable,o,i),o===t.x&&i===t.y||e.requestAnimationFrame(p.bind(e,t))}function h(n,o,r){var s,c,u,d,f=a();n===t.body?(s=e,c=e.scrollX||e.pageXOffset,u=e.scrollY||e.pageYOffset,d=i.scroll):(s=n,c=n.scrollLeft,u=n.scrollTop,d=l),p({scrollable:s,method:d,startTime:f,startX:c,startY:u,x:o,y:r})}}}}()}(B={exports:{}},B.exports),B.exports).polyfill,z=function(){function e(e,t){void 0===t&&(t=[]),this.timeOffset=0,this.actions=t,this.config=e}return e.prototype.addAction=function(e){var t=this.findActionIndex(e);this.actions.splice(t,0,e)},e.prototype.addActions=function(e){var t;(t=this.actions).push.apply(t,e)},e.prototype.start=function(){this.actions.sort(function(e,t){return e.delay-t.delay}),this.timeOffset=0;var e=performance.now(),t=this.actions,n=this.config,o=this;this.raf=requestAnimationFrame(function r(i){for(o.timeOffset+=(i-e)*n.speed,e=i;t.length;){var a=t[0];if(!(o.timeOffset>=a.delay))break;t.shift(),a.doAction()}t.length>0&&(o.raf=requestAnimationFrame(r))})},e.prototype.clear=function(){this.raf&&cancelAnimationFrame(this.raf),this.actions.length=0},e.prototype.findActionIndex=function(e){for(var t=0,n=this.actions.length-1;t<=n;){var o=Math.floor((t+n)/2);if(this.actions[o].delay<e.delay)t=o+1;else{if(!(this.actions[o].delay>e.delay))return o;n=o-1}}return t},e}(),P=R||_,X=function(){function e(e,t){if(this.events=[],this.emitter=P(),this.baselineTime=0,this.noramlSpeed=-1,this.missingNodeRetryMap={},e.length<2)throw new Error("Replayer need at least 2 events.");this.events=e,this.handleResize=this.handleResize.bind(this);var n={speed:1,root:document.body,loadTimeout:0,skipInactive:!1,showWarning:!0,showDebug:!1,blockClass:"rr-block"};this.config=Object.assign({},n,t),this.timer=new z(this.config),j(),this.setupDom(),this.emitter.on("resize",this.handleResize)}return e.prototype.on=function(e,t){this.emitter.on(e,t)},e.prototype.setConfig=function(e){var t=this;Object.keys(e).forEach(function(n){t.config[n]=e[n]}),this.config.skipInactive||(this.noramlSpeed=-1)},e.prototype.getMetaData=function(){var e=this.events[0];return{totalTime:this.events[this.events.length-1].timestamp-e.timestamp}},e.prototype.getTimeOffset=function(){return this.baselineTime-this.events[0].timestamp},e.prototype.play=function(e){void 0===e&&(e=0),this.timer.clear(),this.baselineTime=this.events[0].timestamp+e;for(var t=new Array,n=0,o=this.events;n<o.length;n++){var r=o[n],i=r.timestamp<this.baselineTime,a=this.getCastFn(r,i);i?a():t.push({doAction:a,delay:this.getDelay(r)})}this.timer.addActions(t),this.timer.start(),this.emitter.emit(N.Start)},e.prototype.pause=function(){this.timer.clear(),this.emitter.emit(N.Pause)},e.prototype.resume=function(e){void 0===e&&(e=0),this.timer.clear(),this.baselineTime=this.events[0].timestamp+e;for(var t=new Array,n=0,o=this.events;n<o.length;n++){var r=o[n];if(!(r.timestamp<=this.lastPlayedEvent.timestamp||r===this.lastPlayedEvent)){var i=this.getCastFn(r);t.push({doAction:i,delay:this.getDelay(r)})}}this.timer.addActions(t),this.timer.start(),this.emitter.emit(N.Resume)},e.prototype.setupDom=function(){this.wrapper=document.createElement("div"),this.wrapper.classList.add("replayer-wrapper"),this.config.root.appendChild(this.wrapper),this.mouse=document.createElement("div"),this.mouse.classList.add("replayer-mouse"),this.wrapper.appendChild(this.mouse),this.iframe=document.createElement("iframe"),this.iframe.setAttribute("sandbox","allow-same-origin"),this.iframe.setAttribute("scrolling","no"),this.wrapper.appendChild(this.iframe)},e.prototype.handleResize=function(e){this.iframe.width=e.width+"px",this.iframe.height=e.height+"px"},e.prototype.getDelay=function(e){if(e.type===b.IncrementalSnapshot&&e.data.source===w.MouseMove){var t=e.data.positions[0].timeOffset,n=e.timestamp+t;return e.delay=n-this.baselineTime,n-this.baselineTime}return e.delay=e.timestamp-this.baselineTime,e.timestamp-this.baselineTime},e.prototype.getCastFn=function(e,t){var n,o=this;switch(void 0===t&&(t=!1),e.type){case b.DomContentLoaded:case b.Load:break;case b.Meta:n=function(){return o.emitter.emit(N.Resize,{width:e.data.width,height:e.data.height})};break;case b.FullSnapshot:n=function(){o.rebuildFullSnapshot(e),o.iframe.contentWindow.scrollTo(e.data.initialOffset)};break;case b.IncrementalSnapshot:n=function(){if(o.applyIncremental(e,t),e===o.nextUserInteractionEvent&&(o.nextUserInteractionEvent=null,o.restoreSpeed()),o.config.skipInactive&&!o.nextUserInteractionEvent){for(var n=0,r=o.events;n<r.length;n++){var i=r[n];if(!(i.timestamp<=e.timestamp)&&o.isUserInteraction(i)){i.delay-e.delay>1e4*o.config.speed&&(o.nextUserInteractionEvent=i);break}}if(o.nextUserInteractionEvent){o.noramlSpeed=o.config.speed;var a=o.nextUserInteractionEvent.delay-e.delay,s={speed:Math.min(Math.round(a/5e3),360)};o.setConfig(s),o.emitter.emit(N.SkipStart,s)}}}}return function(){n&&n(),o.lastPlayedEvent=e,e===o.events[o.events.length-1]&&(o.restoreSpeed(),o.emitter.emit(N.Finish))}},e.prototype.rebuildFullSnapshot=function(e){var t,n,o;Object.keys(this.missingNodeRetryMap).length&&console.warn("Found unresolved missing node map",this.missingNodeRetryMap),this.missingNodeRetryMap={},T.map=(t=e.data.node,n=this.iframe.contentDocument,o={},[y(t,n,o),o])[1];var r=document.createElement("style"),i=this.iframe.contentDocument,a=i.documentElement,s=i.head;a.insertBefore(r,s);for(var l=["iframe, ."+this.config.blockClass+" { background: #ccc }","noscript { display: none !important; }"],c=0;c<l.length;c++)r.sheet.insertRule(l[c],c);this.emitter.emit(N.FullsnapshotRebuilded),this.waitForStylesheetLoad()},e.prototype.waitForStylesheetLoad=function(){var e=this,t=this.iframe.contentDocument.head;if(t){var n,o=new Set;t.querySelectorAll('link[rel="stylesheet"]').forEach(function(t){t.sheet||(0===o.size&&(e.pause(),e.emitter.emit(N.LoadStylesheetStart),n=window.setTimeout(function(){e.resume(e.timer.timeOffset),n=-1},e.config.loadTimeout)),o.add(t),t.addEventListener("load",function(){o.delete(t),0===o.size&&-1!==n&&(e.resume(e.timer.timeOffset),e.emitter.emit(N.LoadStylesheetEnd),n&&window.clearTimeout(n))}))})}},e.prototype.applyIncremental=function(e,t){var o=this,r=e.data;switch(r.source){case w.Mutation:r.removes.forEach(function(e){var t=T.getNode(e.id);if(!t)return o.warnNodeNotFound(r,e.id);var n=T.getNode(e.parentId);if(!n)return o.warnNodeNotFound(r,e.parentId);T.removeNodeFromMap(t),n&&n.removeChild(t)});var i=n({},this.missingNodeRetryMap);r.adds.forEach(function(e){var t=y(e.node,o.iframe.contentDocument,T.map,!0),n=T.getNode(e.parentId);if(!n)return o.warnNodeNotFound(r,e.parentId);var a=null,s=null;e.previousId&&(a=T.getNode(e.previousId)),e.nextId&&(s=T.getNode(e.nextId)),-1!==e.previousId&&-1!==e.nextId?(a&&a.nextSibling&&a.nextSibling.parentNode?n.insertBefore(t,a.nextSibling):s&&s.parentNode?n.insertBefore(t,s):n.appendChild(t),(e.previousId||e.nextId)&&o.resolveMissingNode(i,n,t,e)):i[e.node.id]={node:t,mutation:e}}),Object.keys(i).length&&Object.assign(this.missingNodeRetryMap,i),r.texts.forEach(function(e){var t=T.getNode(e.id);if(!t)return o.warnNodeNotFound(r,e.id);t.textContent=e.value}),r.attributes.forEach(function(e){var t=T.getNode(e.id);if(!t)return o.warnNodeNotFound(r,e.id);for(var n in e.attributes)if("string"==typeof n){var i=e.attributes[n];null!==i?t.setAttribute(n,i):t.removeAttribute(n)}});break;case w.MouseMove:t||r.positions.forEach(function(t){var n={doAction:function(){o.moveAndHover(r,t.x,t.y,t.id)},delay:t.timeOffset+e.timestamp-o.baselineTime};o.timer.addAction(n)});break;case w.MouseInteraction:if(-1===r.id)break;var a=new Event(E[r.type].toLowerCase());if(!(s=T.getNode(r.id)))return this.debugNodeNotFound(r,r.id);switch(r.type){case E.Blur:s.blur&&s.blur();break;case E.Focus:s.focus&&s.focus({preventScroll:!0});break;case E.Click:t||(this.moveAndHover(r,r.x,r.y,r.id),this.mouse.classList.remove("active"),this.mouse.offsetWidth,this.mouse.classList.add("active"));break;default:s.dispatchEvent(a)}break;case w.Scroll:if(-1===r.id)break;if(!(s=T.getNode(r.id)))return this.debugNodeNotFound(r,r.id);if(s===this.iframe.contentDocument)this.iframe.contentWindow.scrollTo({top:r.y,left:r.x,behavior:t?"auto":"smooth"});else try{s.scrollTop=r.y,s.scrollLeft=r.x}catch(e){}break;case w.ViewportResize:this.emitter.emit(N.Resize,{width:r.width,height:r.height});break;case w.Input:if(-1===r.id)break;var s;if(!(s=T.getNode(r.id)))return this.debugNodeNotFound(r,r.id);try{s.checked=r.isChecked,s.value=r.text}catch(e){}}},e.prototype.resolveMissingNode=function(e,t,n,o){var r=o.previousId,i=o.nextId,a=r&&e[r],s=i&&e[i];if(a){var l=a,c=l.node,u=l.mutation;t.insertBefore(c,n),delete e[u.node.id],delete this.missingNodeRetryMap[u.node.id],(u.previousId||u.nextId)&&this.resolveMissingNode(e,t,c,u)}if(s){var d=s;c=d.node,u=d.mutation;t.insertBefore(c,n.nextSibling),delete e[u.node.id],delete this.missingNodeRetryMap[u.node.id],(u.previousId||u.nextId)&&this.resolveMissingNode(e,t,c,u)}},e.prototype.moveAndHover=function(e,t,n,o){this.mouse.style.left=t+"px",this.mouse.style.top=n+"px";var r=T.getNode(o);if(!r)return this.debugNodeNotFound(e,o);this.hoverElements(r)},e.prototype.hoverElements=function(e){this.iframe.contentDocument.querySelectorAll(".\\:hover").forEach(function(e){e.classList.remove(":hover")});for(var t=e;t;)t.classList.add(":hover"),t=t.parentElement},e.prototype.isUserInteraction=function(e){return e.type===b.IncrementalSnapshot&&(e.data.source>w.Mutation&&e.data.source<=w.Input)},e.prototype.restoreSpeed=function(){if(-1!==this.noramlSpeed){var e={speed:this.noramlSpeed};this.setConfig(e),this.emitter.emit(N.SkipEnd,e),this.noramlSpeed=-1}},e.prototype.warnNodeNotFound=function(e,t){this.config.showWarning&&console.warn("[replayer]","Node with id '"+t+"' not found in",e)},e.prototype.debugNodeNotFound=function(e,t){this.config.showDebug&&console.log("[replayer]","Node with id '"+t+"' not found in",e)},e}();return e.record=function(e){void 0===e&&(e={});var t,o=e.emit,r=e.checkoutEveryNms,i=e.checkoutEveryNth,a=e.blockClass,s=void 0===a?"rr-block":a,l=e.ignoreClass,c=void 0===l?"rr-ignore":l;if(!o)throw new Error("emit function is required");var u=0,f=function(e,n){if(o(e,n),e.type===b.FullSnapshot)t=e,u=0;else if(e.type===b.IncrementalSnapshot){u++;var a=i&&u>=i,s=r&&e.timestamp-t.timestamp>r;(a||s)&&p(!0)}};function p(e){void 0===e&&(e=!1),f(F({type:b.Meta,data:{href:window.location.href,width:I(),height:S()}}),e);var t=d(document,s),n=t[0],o=t[1];if(!n)return console.warn("Failed to snapshot the document");T.map=o,f(F({type:b.FullSnapshot,data:{node:n,initialOffset:{left:document.documentElement.scrollLeft,top:document.documentElement.scrollTop}}}))}try{var h=[];h.push(g("DOMContentLoaded",function(){f(F({type:b.DomContentLoaded,data:{}}))}));var m=function(){p(),h.push(A({mutationCb:function(e){return f(F({type:b.IncrementalSnapshot,data:n({source:w.Mutation},e)}))},mousemoveCb:function(e){return f(F({type:b.IncrementalSnapshot,data:{source:w.MouseMove,positions:e}}))},mouseInteractionCb:function(e){return f(F({type:b.IncrementalSnapshot,data:n({source:w.MouseInteraction},e)}))},scrollCb:function(e){return f(F({type:b.IncrementalSnapshot,data:n({source:w.Scroll},e)}))},viewportResizeCb:function(e){return f(F({type:b.IncrementalSnapshot,data:n({source:w.ViewportResize},e)}))},inputCb:function(e){return f(F({type:b.IncrementalSnapshot,data:n({source:w.Input},e)}))},blockClass:s,ignoreClass:c}))};return"interactive"===document.readyState||"complete"===document.readyState?m():h.push(g("load",function(){f(F({type:b.Load,data:{}})),m()},window)),function(){h.forEach(function(e){return e()})}}catch(e){console.warn(e)}},e.Replayer=X,e.mirror=T,e}({});
//# sourceMappingURL=rrweb.min.js.map