@sailfish-rrweb/replay 0.5.7 → 0.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/replay.cjs +26 -26
- package/dist/replay.cjs.map +1 -1
- package/dist/replay.js +636 -636
- package/dist/replay.js.br +0 -0
- package/dist/replay.js.gz +0 -0
- package/dist/replay.js.map +1 -1
- package/dist/replay.umd.cjs +24 -24
- package/dist/replay.umd.cjs.map +1 -1
- package/dist/replay.umd.min.cjs +1 -1
- package/dist/replay.umd.min.cjs.map +3 -3
- package/dist/replay.umd.umd.cjs +5 -5
- package/dist/replay.umd.umd.cjs.map +3 -3
- package/dist/replay.umd.umd.min.cjs +5 -5
- package/dist/replay.umd.umd.min.cjs.map +3 -3
- package/package.json +3 -3
package/dist/replay.umd.min.cjs
CHANGED
|
@@ -69,7 +69,7 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
69
69
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
70
70
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
71
71
|
PERFORMANCE OF THIS SOFTWARE.
|
|
72
|
-
***************************************************************************** */function Gr(t,e){var s=typeof Symbol=="function"&&t[Symbol.iterator];if(!s)return t;var r,i,o=s.call(t),a=[];try{for(;(e===void 0||e-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(n){i={error:n}}finally{try{r&&!r.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}return a}var oe;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(oe||(oe={}));var In={type:"xstate.init"};function Wt(t){return t===void 0?[]:[].concat(t)}function ne(t){return{type:"xstate.assign",assignment:t}}function Xr(t,e){return typeof(t=typeof t=="string"&&e&&e[t]?e[t]:t)=="string"?{type:t}:typeof t=="function"?{type:t.name,exec:t}:t}function yt(t){return function(e){return t===e}}function Pn(t){return typeof t=="string"?{type:t}:t}function Zr(t,e){return{value:t,context:e,actions:[],changed:!1,matches:yt(t)}}function Hr(t,e,s){var r=e,i=!1;return[t.filter(function(o){if(o.type==="xstate.assign"){i=!0;var a=Object.assign({},r);return typeof o.assignment=="function"?a=o.assignment(r,s):Object.keys(o.assignment).forEach(function(n){a[n]=typeof o.assignment[n]=="function"?o.assignment[n](r,s):o.assignment[n]}),r=a,!1}return!0}),r,i]}function Ln(t,e){e===void 0&&(e={});var s=Gr(Hr(Wt(t.states[t.initial].entry).map(function(a){return Xr(a,e.actions)}),t.context,In),2),r=s[0],i=s[1],o={config:t,_options:e,initialState:{value:t.initial,actions:r,context:i,matches:yt(t.initial)},transition:function(a,n){var c,l,h=typeof a=="string"?{value:a,context:t.context}:a,u=h.value,p=h.context,m=Pn(n),b=t.states[u];if(b.on){var d=Wt(b.on[m.type]);try{for(var S=function(U){var Rt=typeof Symbol=="function"&&Symbol.iterator,Zs=Rt&&U[Rt],Hs=0;if(Zs)return Zs.call(U);if(U&&typeof U.length=="number")return{next:function(){return U&&Hs>=U.length&&(U=void 0),{value:U&&U[Hs++],done:!U}}};throw new TypeError(Rt?"Object is not iterable.":"Symbol.iterator is not defined.")}(d),f=S.next();!f.done;f=S.next()){var w=f.value;if(w===void 0)return Zr(u,p);var g=typeof w=="string"?{target:w}:w,x=g.target,P=g.actions,B=P===void 0?[]:P,F=g.cond,V=F===void 0?function(){return!0}:F,ee=x===void 0,_n=x!=null?x:u,Un=t.states[_n];if(V(p,m)){var Dt=Gr(Hr((ee?Wt(B):[].concat(b.exit,B,Un.entry).filter(function(U){return U})).map(function(U){return Xr(U,o._options.actions)}),p,m),3),Gs=Dt[0],Bn=Dt[1],Wn=Dt[2],Xs=x!=null?x:u;return{value:Xs,context:Bn,actions:Gs,changed:x!==u||Gs.length>0||Wn,matches:yt(Xs)}}}}catch(U){c={error:U}}finally{try{f&&!f.done&&(l=S.return)&&l.call(S)}finally{if(c)throw c.error}}}return Zr(u,p)}};return o}var $r=function(t,e){return t.actions.forEach(function(s){var r=s.exec;return r&&r(t.context,e)})};function Fn(t){var e=t.initialState,s=oe.NotStarted,r=new Set,i={_machine:t,send:function(o){s===oe.Running&&(e=t.transition(e,o),$r(e,Pn(o)),r.forEach(function(a){return a(e)}))},subscribe:function(o){return r.add(o),o(e),{unsubscribe:function(){return r.delete(o)}}},start:function(o){if(o){var a=typeof o=="object"?o:{context:t.config.context,value:o};e={value:a.value,actions:[],context:a.context,matches:yt(a.value)}}return s=oe.Running,$r(e,In),i},stop:function(){return s=oe.Stopped,r.clear(),i},get state(){return e},get status(){return s}};return i}class Mh{constructor(e=[],s){v(this,"timeOffset",0),v(this,"speed"),v(this,"actions"),v(this,"raf",null),v(this,"lastTimestamp"),this.actions=e,this.speed=s.speed}addAction(e){const s=this.raf===!0;if(!this.actions.length||this.actions[this.actions.length-1].delay<=e.delay)this.actions.push(e);else{const r=this.findActionIndex(e);this.actions.splice(r,0,e)}s&&(this.raf=requestAnimationFrame(this.rafCheck.bind(this)))}start(){this.timeOffset=0,this.lastTimestamp=performance.now(),this.raf=requestAnimationFrame(this.rafCheck.bind(this))}rafCheck(){const e=performance.now();for(this.timeOffset+=(e-this.lastTimestamp)*this.speed,this.lastTimestamp=e;this.actions.length;){const s=this.actions[0];if(this.timeOffset>=s.delay)this.actions.shift(),s.doAction();else break}this.actions.length>0?this.raf=requestAnimationFrame(this.rafCheck.bind(this)):this.raf=!0}clear(){this.raf&&(this.raf!==!0&&cancelAnimationFrame(this.raf),this.raf=null),this.actions.length=0}setSpeed(e){this.speed=e}isActive(){return this.raf!==null}findActionIndex(e){let s=0,r=this.actions.length-1;for(;s<=r;){const i=Math.floor((s+r)/2);if(this.actions[i].delay<e.delay)s=i+1;else if(this.actions[i].delay>e.delay)r=i-1;else return i+1}return s}}function Jr(t,e){if(t.type===L.IncrementalSnapshot&&t.data.source===T.MouseMove&&t.data.positions&&t.data.positions.length){const s=t.data.positions[0].timeOffset,r=t.timestamp+s;return t.delay=r-e,r-e}return t.delay=t.timestamp-e,t.delay}function Nh(t,e){for(let s=t.length-1;s>=0;s--){const r=t[s];if(r.type===L.Meta&&r.timestamp<=e)return t.slice(s)}return t}function Th(t,{getCastFn:e,applyEventsSynchronously:s,emitter:r}){const i=Ln({id:"player",context:t,initial:"paused",states:{playing:{on:{PAUSE:{target:"paused",actions:["pause"]},CAST_EVENT:{target:"playing",actions:"castEvent"},END:{target:"paused",actions:["resetLastPlayedEvent","pause"]},ADD_EVENT:{target:"playing",actions:["addEvent"]}}},paused:{on:{PLAY:{target:"playing",actions:["recordTimeOffset","play"]},CAST_EVENT:{target:"paused",actions:"castEvent"},TO_LIVE:{target:"live",actions:["startLive"]},ADD_EVENT:{target:"paused",actions:["addEvent"]}}},live:{on:{ADD_EVENT:{target:"live",actions:["addEvent"]},CAST_EVENT:{target:"live",actions:["castEvent"]}}}}},{actions:{castEvent:ne({lastPlayedEvent:(o,a)=>a.type==="CAST_EVENT"?a.payload.event:o.lastPlayedEvent}),recordTimeOffset:ne((o,a)=>{let n=o.timeOffset;return"payload"in a&&"timeOffset"in a.payload&&(n=a.payload.timeOffset),W(O({},o),{timeOffset:n,baselineTime:o.events[0].timestamp+n})}),play(o){const{timer:a,events:n,baselineTime:c}=o;a.clear();for(const u of n)Jr(u,c);const l=Nh(n,c);r.emit(N.PlayBack);const h=new Array;for(const u of l)if(u.timestamp<c)h.push(u);else{const p=e(u,!1);a.addAction({doAction:()=>{p()},delay:u.delay})}s(h),r.emit(N.Flush),a.start()},pause(o){o.timer.clear()},resetLastPlayedEvent:ne(o=>W(O({},o),{lastPlayedEvent:null})),startLive:ne({baselineTime:(o,a)=>(o.timer.start(),a.type==="TO_LIVE"&&a.payload.baselineTime?a.payload.baselineTime:Date.now())}),addEvent:ne((o,a)=>{const{baselineTime:n,timer:c,events:l}=o;if(a.type==="ADD_EVENT"){const{event:h}=a.payload;Jr(h,n);let u=l.length-1;if(!l[u]||l[u].timestamp<=h.timestamp)l.push(h);else{let b=-1,d=0;for(;d<=u;){const S=Math.floor((d+u)/2);l[S].timestamp<=h.timestamp?d=S+1:u=S-1}b===-1&&(b=d),l.splice(b,0,h)}const p=h.timestamp<n,m=e(h,p);p?m():c.isActive()&&c.addAction({doAction:()=>{m()},delay:h.delay})}return W(O({},o),{events:l})})}});return Fn(i)}function kh(t){const e=Ln({id:"speed",context:t,initial:"normal",states:{normal:{on:{FAST_FORWARD:{target:"skipping",actions:["recordSpeed","setSpeed"]},SET_SPEED:{target:"normal",actions:["setSpeed"]}}},skipping:{on:{BACK_TO_NORMAL:{target:"normal",actions:["restoreSpeed"]},SET_SPEED:{target:"normal",actions:["setSpeed"]}}}}},{actions:{setSpeed:(s,r)=>{"payload"in r&&s.timer.setSpeed(r.payload.speed)},recordSpeed:ne({normalSpeed:s=>s.timer.speed}),restoreSpeed:s=>{s.timer.setSpeed(s.normalSpeed)}}});return Fn(e)}class Dh{constructor(e){v(this,"mediaMap",new Map),v(this,"warn"),v(this,"service"),v(this,"speedService"),v(this,"emitter"),v(this,"getCurrentTime"),v(this,"metadataCallbackMap",new Map),this.warn=e.warn,this.service=e.service,this.speedService=e.speedService,this.emitter=e.emitter,this.getCurrentTime=e.getCurrentTime,this.emitter.on(N.Start,this.start.bind(this)),this.emitter.on(N.SkipStart,this.start.bind(this)),this.emitter.on(N.Pause,this.pause.bind(this)),this.emitter.on(N.Finish,this.pause.bind(this)),this.speedService.subscribe(()=>{this.syncAllMediaElements()})}syncAllMediaElements(e={pause:!1}){this.mediaMap.forEach((s,r)=>{this.syncTargetWithState(r),e.pause&&r.pause()})}start(){this.syncAllMediaElements()}pause(){this.syncAllMediaElements({pause:!0})}seekTo({time:e,target:s,mediaState:r}){if(r.isPlaying){const i=(e-r.lastInteractionTimeOffset)/1e3*r.playbackRate,o="duration"in s&&s.duration;if(Number.isNaN(o)){this.waitForMetadata(s);return}let a=r.currentTimeAtLastInteraction+i;s.loop&&o!==!1&&(a=a%o),s.currentTime=a}else s.pause(),s.currentTime=r.currentTimeAtLastInteraction}waitForMetadata(e){if(this.metadataCallbackMap.has(e)||!("addEventListener"in e))return;const s=()=>{this.metadataCallbackMap.delete(e);const r=this.mediaMap.get(e);r&&this.seekTo({time:this.getCurrentTime(),target:e,mediaState:r})};this.metadataCallbackMap.set(e,s),e.addEventListener("loadedmetadata",s,{once:!0})}getMediaStateFromMutation({target:e,timeOffset:s,mutation:r}){var u,p,m,b,d;const i=this.mediaMap.get(e),{type:o,playbackRate:a,currentTime:n,muted:c,volume:l,loop:h}=r;return{isPlaying:o===rs.Play||o!==rs.Pause&&((i==null?void 0:i.isPlaying)||e.getAttribute("autoplay")!==null),currentTimeAtLastInteraction:(u=n!=null?n:i==null?void 0:i.currentTimeAtLastInteraction)!=null?u:0,lastInteractionTimeOffset:s,playbackRate:(p=a!=null?a:i==null?void 0:i.playbackRate)!=null?p:1,volume:(m=l!=null?l:i==null?void 0:i.volume)!=null?m:1,muted:(b=c!=null?c:i==null?void 0:i.muted)!=null?b:e.getAttribute("muted")===null,loop:(d=h!=null?h:i==null?void 0:i.loop)!=null?d:e.getAttribute("loop")===null}}syncTargetWithState(e){const s=this.mediaMap.get(e);if(!s)return;const{muted:r,loop:i,volume:o,isPlaying:a}=s,n=this.service.state.matches("paused"),c=s.playbackRate*this.speedService.state.context.timer.speed;try{this.seekTo({time:this.getCurrentTime(),target:e,mediaState:s}),e.volume!==o&&(e.volume=o),e.muted=r,e.loop=i,e.playbackRate!==c&&(e.playbackRate=c),a&&!n?e.play():e.pause()}catch(l){this.warn(`Failed to replay media interactions: ${l.message||l}`)}}addMediaElements(e,s,r){if(!["AUDIO","VIDEO"].includes(e.nodeName))return;const i=e,o=r.getMeta(i);if(!o||!("attributes"in o))return;const a=this.service.state.matches("paused"),n=o.attributes;let c=!1;n.rr_mediaState?c=n.rr_mediaState==="played":c=i.getAttribute("autoplay")!==null,c&&a&&i.pause();let l=1;typeof n.rr_mediaPlaybackRate=="number"&&(l=n.rr_mediaPlaybackRate);let h=!1;typeof n.rr_mediaMuted=="boolean"?h=n.rr_mediaMuted:h=i.getAttribute("muted")!==null;let u=!1;typeof n.rr_mediaLoop=="boolean"?u=n.rr_mediaLoop:u=i.getAttribute("loop")!==null;let p=1;typeof n.rr_mediaVolume=="number"&&(p=n.rr_mediaVolume);let m=0;typeof n.rr_mediaCurrentTime=="number"&&(m=n.rr_mediaCurrentTime),this.mediaMap.set(i,{isPlaying:c,currentTimeAtLastInteraction:m,lastInteractionTimeOffset:s,playbackRate:l,volume:p,muted:h,loop:u}),this.syncTargetWithState(i)}mediaMutation({target:e,timeOffset:s,mutation:r}){this.mediaMap.set(e,this.getMediaStateFromMutation({target:e,timeOffset:s,mutation:r})),this.syncTargetWithState(e)}isSupportedMediaElement(e){return["AUDIO","VIDEO"].includes(e.nodeName)}reset(){this.mediaMap.clear()}}function Rh(t=window,e=document){if("scrollBehavior"in e.documentElement.style&&t.__forceSmoothScrollPolyfill__!==!0)return;const s=t.HTMLElement||t.Element,r=468,i={scroll:t.scroll||t.scrollTo,scrollBy:t.scrollBy,elementScroll:s.prototype.scroll||c,scrollIntoView:s.prototype.scrollIntoView},o=t.performance&&t.performance.now?t.performance.now.bind(t.performance):Date.now;function a(f){const w=["MSIE ","Trident/","Edge/"];return new RegExp(w.join("|")).test(f)}const n=a(t.navigator.userAgent)?1:0;function c(f,w){this.scrollLeft=f,this.scrollTop=w}function l(f){return .5*(1-Math.cos(Math.PI*f))}function h(f){if(f===null||typeof f!="object"||f.behavior===void 0||f.behavior==="auto"||f.behavior==="instant")return!0;if(typeof f=="object"&&f.behavior==="smooth")return!1;throw new TypeError("behavior member of ScrollOptions "+f.behavior+" is not a valid value for enumeration ScrollBehavior.")}function u(f,w){if(w==="Y")return f.clientHeight+n<f.scrollHeight;if(w==="X")return f.clientWidth+n<f.scrollWidth}function p(f,w){const g=t.getComputedStyle(f,null)["overflow"+w];return g==="auto"||g==="scroll"}function m(f){const w=u(f,"Y")&&p(f,"Y"),g=u(f,"X")&&p(f,"X");return w||g}function b(f){for(;f!==e.body&&m(f)===!1;)f=f.parentNode||f.host;return f}function d(f){const w=o();let g,x,P,B=(w-f.startTime)/r;B=B>1?1:B,g=l(B),x=f.startX+(f.x-f.startX)*g,P=f.startY+(f.y-f.startY)*g,f.method.call(f.scrollable,x,P),(x!==f.x||P!==f.y)&&t.requestAnimationFrame(d.bind(t,f))}function S(f,w,g){let x,P,B,F;const V=o();f===e.body?(x=t,P=t.scrollX||t.pageXOffset,B=t.scrollY||t.pageYOffset,F=i.scroll):(x=f,P=f.scrollLeft,B=f.scrollTop,F=c),d({scrollable:x,method:F,startTime:V,startX:P,startY:B,x:w,y:g})}t.scroll=t.scrollTo=function(){if(arguments[0]!==void 0){if(h(arguments[0])===!0){i.scroll.call(t,arguments[0].left!==void 0?arguments[0].left:typeof arguments[0]!="object"?arguments[0]:t.scrollX||t.pageXOffset,arguments[0].top!==void 0?arguments[0].top:arguments[1]!==void 0?arguments[1]:t.scrollY||t.pageYOffset);return}S.call(t,e.body,arguments[0].left!==void 0?~~arguments[0].left:t.scrollX||t.pageXOffset,arguments[0].top!==void 0?~~arguments[0].top:t.scrollY||t.pageYOffset)}},t.scrollBy=function(){if(arguments[0]!==void 0){if(h(arguments[0])){i.scrollBy.call(t,arguments[0].left!==void 0?arguments[0].left:typeof arguments[0]!="object"?arguments[0]:0,arguments[0].top!==void 0?arguments[0].top:arguments[1]!==void 0?arguments[1]:0);return}S.call(t,e.body,~~arguments[0].left+(t.scrollX||t.pageXOffset),~~arguments[0].top+(t.scrollY||t.pageYOffset))}},s.prototype.scroll=s.prototype.scrollTo=function(){if(arguments[0]===void 0)return;if(h(arguments[0])===!0){if(typeof arguments[0]=="number"&&arguments[1]===void 0)throw new SyntaxError("Value could not be converted");i.elementScroll.call(this,arguments[0].left!==void 0?~~arguments[0].left:typeof arguments[0]!="object"?~~arguments[0]:this.scrollLeft,arguments[0].top!==void 0?~~arguments[0].top:arguments[1]!==void 0?~~arguments[1]:this.scrollTop);return}const f=arguments[0].left,w=arguments[0].top;S.call(this,this,typeof f>"u"?this.scrollLeft:~~f,typeof w>"u"?this.scrollTop:~~w)},s.prototype.scrollBy=function(){if(arguments[0]!==void 0){if(h(arguments[0])===!0){i.elementScroll.call(this,arguments[0].left!==void 0?~~arguments[0].left+this.scrollLeft:~~arguments[0]+this.scrollLeft,arguments[0].top!==void 0?~~arguments[0].top+this.scrollTop:~~arguments[1]+this.scrollTop);return}this.scroll({left:~~arguments[0].left+this.scrollLeft,top:~~arguments[0].top+this.scrollTop,behavior:arguments[0].behavior})}},s.prototype.scrollIntoView=function(){if(h(arguments[0])===!0){i.scrollIntoView.call(this,arguments[0]===void 0?!0:arguments[0]);return}const f=b(this),w=f.getBoundingClientRect(),g=this.getBoundingClientRect();f!==e.body?(S.call(this,f,f.scrollLeft+g.left-w.left,f.scrollTop+g.top-w.top),t.getComputedStyle(f).position!=="fixed"&&t.scrollBy({left:w.left,top:w.top,behavior:"smooth"})):t.scrollBy({left:g.left,top:g.top,behavior:"smooth"})}}const Oh=t=>[`.${t} { background: currentColor }`,"noscript { display: none !important; }"],Ah=5*1e3,Ih=On||bh,Qr="[replayer]",jt={duration:500,lineCap:"round",lineWidth:3,strokeStyle:"red"};function Kr(t){return t.type==L.IncrementalSnapshot&&(t.data.source==T.TouchMove||t.data.source==T.MouseInteraction&&t.data.type==_.TouchStart)}class Ph{constructor(e,s){if(v(this,"wrapper"),v(this,"iframe"),v(this,"service"),v(this,"speedService"),v(this,"config"),v(this,"usingVirtualDom",!1),v(this,"virtualDom",new de),v(this,"mouse"),v(this,"mouseTail",null),v(this,"tailPositions",[]),v(this,"emitter",Ih()),v(this,"nextUserInteractionEvent"),v(this,"legacy_missingNodeRetryMap",{}),v(this,"cache",br()),v(this,"imageMap",new Map),v(this,"canvasEventMap",new Map),v(this,"mirror",ei()),v(this,"styleMirror",new Qa),v(this,"mediaManager"),v(this,"firstFullSnapshot",null),v(this,"newDocumentQueue",[]),v(this,"mousePos",null),v(this,"touchActive",null),v(this,"lastMouseDownEvent",null),v(this,"lastHoveredRootNode"),v(this,"textValueMap",new Map),v(this,"lastSelectionData",null),v(this,"constructedStyleMutations",[]),v(this,"adoptedStyleSheets",[]),v(this,"handleResize",n=>{this.iframe.style.display="inherit";for(const c of[this.mouseTail,this.iframe])c&&(c.setAttribute("width",String(n.width)),c.setAttribute("height",String(n.height)))}),v(this,"applyEventsSynchronously",n=>{for(const c of n){switch(c.type){case L.DomContentLoaded:case L.Load:case L.Custom:continue;case L.FullSnapshot:case L.Meta:case L.Plugin:case L.IncrementalSnapshot:break}this.getCastFn(c,!0)()}}),v(this,"getCastFn",(n,c=!1)=>{let l;switch(n.type){case L.DomContentLoaded:case L.Load:break;case L.Custom:l=()=>{this.emitter.emit(N.CustomEvent,n)};break;case L.Meta:l=()=>this.emitter.emit(N.Resize,{width:n.data.width,height:n.data.height});break;case L.FullSnapshot:l=()=>{var h;if(this.firstFullSnapshot){if(this.firstFullSnapshot===n){this.firstFullSnapshot=!0;return}}else this.firstFullSnapshot=!0;this.mediaManager.reset(),this.styleMirror.reset(),this.rebuildFullSnapshot(n,c),(h=this.iframe.contentWindow)==null||h.scrollTo(n.data.initialOffset)};break;case L.IncrementalSnapshot:l=()=>{if(this.applyIncremental(n,c),!c&&(n===this.nextUserInteractionEvent&&(this.nextUserInteractionEvent=null,this.backToNormal()),!this.nextUserInteractionEvent)){for(const h of this.service.state.context.events)if(!(h.timestamp<=n.timestamp)&&this.isUserInteraction(h)){h.delay-n.delay>this.config.inactivePeriodThreshold*this.speedService.state.context.timer.speed&&(this.nextUserInteractionEvent=h);break}if(this.nextUserInteractionEvent)if(this.config.skipInactive)this.play(this.nextUserInteractionEvent.timestamp-this.getMetaData().startTime-1e3);else{const h=this.nextUserInteractionEvent.delay-n.delay,u={speed:Math.min(Math.round(h/Ah),this.config.maxSpeed)};this.speedService.send({type:"FAST_FORWARD",payload:u}),this.emitter.emit(N.SkipStart,u)}}};break}return()=>{l&&l();for(const u of this.config.plugins||[])u.handler&&u.handler(n,c,{replayer:this});this.service.send({type:"CAST_EVENT",payload:{event:n}});const h=this.service.state.context.events.length-1;if(!this.config.liveMode&&n===this.service.state.context.events[h]){const u=()=>{h<this.service.state.context.events.length-1||(this.backToNormal(),this.service.send("END"),this.emitter.emit(N.Finish))};let p=50;n.type===L.IncrementalSnapshot&&n.data.source===T.MouseMove&&n.data.positions.length&&(p+=Math.max(0,-n.data.positions[0].timeOffset)),setTimeout(u,p)}this.emitter.emit(N.EventCast,n)}}),!(s!=null&&s.liveMode)&&e.length<2)throw new Error("Replayer need at least 2 events.");const r={speed:1,maxSpeed:360,root:document.body,loadTimeout:0,skipInactive:!1,inactivePeriodThreshold:10*1e3,showWarning:!0,showDebug:!1,blockClass:"rr-block",liveMode:!1,insertStyleRules:[],triggerFocus:!0,UNSAFE_replayCanvas:!1,pauseAnimation:!0,mouseTail:jt,useVirtualDom:!0,logger:console};this.config=Object.assign({},r,s),this.handleResize=this.handleResize.bind(this),this.getCastFn=this.getCastFn.bind(this),this.applyEventsSynchronously=this.applyEventsSynchronously.bind(this),this.emitter.on(N.Resize,this.handleResize),this.setupDom();for(const n of this.config.plugins||[])n.getMirror&&n.getMirror({nodeMirror:this.mirror});this.emitter.on(N.Flush,()=>{if(this.usingVirtualDom){const n={mirror:this.mirror,applyCanvas:(c,l,h)=>{Yr({event:c,mutation:l,target:h,imageMap:this.imageMap,canvasEventMap:this.canvasEventMap,errorHandler:this.warnCanvasMutationFailed.bind(this)})},applyInput:this.applyInput.bind(this),applyScroll:this.applyScroll.bind(this),applyStyleSheetMutation:(c,l)=>{c.source===T.StyleSheetRule?this.applyStyleSheetRule(c,l):c.source===T.StyleDeclaration&&this.applyStyleDeclaration(c,l)},afterAppend:(c,l)=>{for(const h of this.config.plugins||[])h.onBuild&&h.onBuild(c,{id:l,replayer:this})}};if(this.iframe.contentDocument)try{mt(this.iframe.contentDocument,this.virtualDom,n,this.virtualDom.mirror)}catch(c){console.warn(c)}if(this.virtualDom.destroyTree(),this.usingVirtualDom=!1,Object.keys(this.legacy_missingNodeRetryMap).length)for(const c in this.legacy_missingNodeRetryMap)try{const l=this.legacy_missingNodeRetryMap[c],h=gt(l.node,this.mirror,this.virtualDom.mirror);mt(h,l.node,n,this.virtualDom.mirror),l.node=h}catch(l){this.warn(l)}this.constructedStyleMutations.forEach(c=>{this.applyStyleSheetMutation(c)}),this.constructedStyleMutations=[],this.adoptedStyleSheets.forEach(c=>{this.applyAdoptedStyleSheet(c)}),this.adoptedStyleSheets=[]}if(this.mousePos&&(this.moveAndHover(this.mousePos.x,this.mousePos.y,this.mousePos.id,!0,this.mousePos.debugData),this.mousePos=null),this.touchActive===!0?this.mouse.classList.add("touch-active"):this.touchActive===!1&&this.mouse.classList.remove("touch-active"),this.touchActive=null,this.lastMouseDownEvent){const[n,c]=this.lastMouseDownEvent;n.dispatchEvent(c)}this.lastMouseDownEvent=null,this.lastSelectionData&&(this.applySelection(this.lastSelectionData),this.lastSelectionData=null)}),this.emitter.on(N.PlayBack,()=>{this.firstFullSnapshot=null,this.mirror.reset(),this.styleMirror.reset(),this.mediaManager.reset(),this.textValueMap.clear()});const i=new Mh([],{speed:this.config.speed});this.service=Th({events:e.map(n=>s&&s.unpackFn?s.unpackFn(n):n).sort((n,c)=>n.timestamp-c.timestamp),timer:i,timeOffset:0,baselineTime:0,lastPlayedEvent:null},{getCastFn:this.getCastFn,applyEventsSynchronously:this.applyEventsSynchronously,emitter:this.emitter}),this.service.start(),this.service.subscribe(n=>{this.emitter.emit(N.StateChange,{player:n})}),this.speedService=kh({normalSpeed:-1,timer:i}),this.speedService.start(),this.speedService.subscribe(n=>{this.emitter.emit(N.StateChange,{speed:n})}),this.mediaManager=new Dh({warn:this.warn.bind(this),service:this.service,speedService:this.speedService,emitter:this.emitter,getCurrentTime:this.getCurrentTime.bind(this)});const o=this.service.state.context.events.find(n=>n.type===L.Meta),a=this.service.state.context.events.find(n=>n.type===L.FullSnapshot);if(o){const{width:n,height:c}=o.data;setTimeout(()=>{this.emitter.emit(N.Resize,{width:n,height:c})},0)}a&&setTimeout(()=>{var n;this.firstFullSnapshot||(this.firstFullSnapshot=a,this.rebuildFullSnapshot(a),(n=this.iframe.contentWindow)==null||n.scrollTo(a.data.initialOffset))},1),this.service.state.context.events.find(Kr)&&this.mouse.classList.add("touch-device")}get timer(){return this.service.state.context.timer}on(e,s){return this.emitter.on(e,s),this}off(e,s){return this.emitter.off(e,s),this}setConfig(e){Object.keys(e).forEach(s=>{e[s],this.config[s]=e[s]}),this.config.skipInactive||this.backToNormal(),typeof e.speed<"u"&&this.speedService.send({type:"SET_SPEED",payload:{speed:e.speed}}),typeof e.mouseTail<"u"&&(e.mouseTail===!1?this.mouseTail&&(this.mouseTail.style.display="none"):(this.mouseTail||(this.mouseTail=document.createElement("canvas"),this.mouseTail.width=Number.parseFloat(this.iframe.width),this.mouseTail.height=Number.parseFloat(this.iframe.height),this.mouseTail.classList.add("replayer-mouse-tail"),this.wrapper.insertBefore(this.mouseTail,this.iframe)),this.mouseTail.style.display="inherit"))}getMetaData(){const e=this.service.state.context.events[0],s=this.service.state.context.events[this.service.state.context.events.length-1];return{startTime:e.timestamp,endTime:s.timestamp,totalTime:s.timestamp-e.timestamp}}getCurrentTime(){return this.timer.timeOffset+this.getTimeOffset()}getTimeOffset(){const{baselineTime:e,events:s}=this.service.state.context;return e-s[0].timestamp}getMirror(){return this.mirror}play(e=0){var s,r;this.service.state.matches("paused")?this.service.send({type:"PLAY",payload:{timeOffset:e}}):(this.service.send({type:"PAUSE"}),this.service.send({type:"PLAY",payload:{timeOffset:e}})),(r=(s=this.iframe.contentDocument)==null?void 0:s.getElementsByTagName("html")[0])==null||r.classList.remove("@sailfish-rrweb/rrweb-paused"),this.emitter.emit(N.Start)}pause(e){var s,r;e===void 0&&this.service.state.matches("playing")&&this.service.send({type:"PAUSE"}),typeof e=="number"&&(this.play(e),this.service.send({type:"PAUSE"})),(r=(s=this.iframe.contentDocument)==null?void 0:s.getElementsByTagName("html")[0])==null||r.classList.add("@sailfish-rrweb/rrweb-paused"),this.emitter.emit(N.Pause)}resume(e=0){this.warn("The 'resume' was deprecated in 1.0. Please use 'play' method which has the same interface."),this.play(e),this.emitter.emit(N.Resume)}destroy(){this.pause(),this.mirror.reset(),this.styleMirror.reset(),this.mediaManager.reset(),this.textValueMap.clear(),this.config.root.removeChild(this.wrapper),this.emitter.emit(N.Destroy)}startLive(e){this.service.send({type:"TO_LIVE",payload:{baselineTime:e}})}addEvent(e){const s=this.config.unpackFn?this.config.unpackFn(e):e;Kr(s)&&this.mouse.classList.add("touch-device"),Promise.resolve().then(()=>this.service.send({type:"ADD_EVENT",payload:{event:s}}))}enableInteract(){this.iframe.setAttribute("scrolling","auto"),this.iframe.style.pointerEvents="auto"}disableInteract(){this.iframe.setAttribute("scrolling","no"),this.iframe.style.pointerEvents="none"}resetCache(){this.cache=br()}setupDom(){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.config.mouseTail!==!1&&(this.mouseTail=document.createElement("canvas"),this.mouseTail.classList.add("replayer-mouse-tail"),this.mouseTail.style.display="inherit",this.wrapper.appendChild(this.mouseTail)),this.iframe=document.createElement("iframe");const e=["allow-same-origin"];this.config.UNSAFE_replayCanvas&&e.push("allow-scripts"),this.iframe.style.display="none",this.iframe.setAttribute("sandbox",e.join(" ")),this.disableInteract(),this.wrapper.appendChild(this.iframe),this.iframe.contentWindow&&this.iframe.contentDocument&&(Rh(this.iframe.contentWindow,this.iframe.contentDocument),Ha(this.iframe.contentWindow))}rebuildFullSnapshot(e,s=!1){if(!this.iframe.contentDocument)return this.warn("Looks like your replayer has been destroyed.");Object.keys(this.legacy_missingNodeRetryMap).length&&this.warn("Found unresolved missing node map",this.legacy_missingNodeRetryMap),this.legacy_missingNodeRetryMap={};const r=[],i=(n,c)=>{if(this.collectIframeAndAttachDocument(r,n),this.mediaManager.isSupportedMediaElement(n)){const{events:l}=this.service.state.context;this.mediaManager.addMediaElements(n,e.timestamp-l[0].timestamp,this.mirror)}for(const l of this.config.plugins||[])l.onBuild&&l.onBuild(n,{id:c,replayer:this})};this.usingVirtualDom&&(this.virtualDom.destroyTree(),this.usingVirtualDom=!1),this.mirror.reset(),this.textValueMap.clear(),Za(e.data.node,{doc:this.iframe.contentDocument,afterAppend:i,cache:this.cache,mirror:this.mirror}),i(this.iframe.contentDocument,e.data.node.id);for(const{mutationInQueue:n,builtNode:c}of r)this.attachDocumentToIframe(n,c),this.newDocumentQueue=this.newDocumentQueue.filter(l=>l!==n);const{documentElement:o,head:a}=this.iframe.contentDocument;this.insertStyleRules(o,a),this.service.state.matches("playing")||this.iframe.contentDocument.getElementsByTagName("html")[0].classList.add("@sailfish-rrweb/rrweb-paused"),this.emitter.emit(N.FullsnapshotRebuilded,e),s||this.waitForStylesheetLoad(),this.config.UNSAFE_replayCanvas&&this.preloadAllImages()}insertStyleRules(e,s){var r;const i=Oh(this.config.blockClass).concat(this.config.insertStyleRules);if(this.config.pauseAnimation&&i.push("html.rrweb-paused *, html.rrweb-paused *:before, html.rrweb-paused *:after { animation-play-state: paused !important; }"),this.usingVirtualDom){const o=this.virtualDom.createElement("style");this.virtualDom.mirror.add(o,Rn(o,this.virtualDom.unserializedId)),e.insertBefore(o,s),o.rules.push({source:T.StyleSheetRule,adds:i.map((a,n)=>({rule:a,index:n}))})}else{const o=document.createElement("style");e.insertBefore(o,s);for(let a=0;a<i.length;a++)(r=o.sheet)==null||r.insertRule(i[a],a)}}attachDocumentToIframe(e,s){const r=this.usingVirtualDom?this.virtualDom.mirror:this.mirror,i=[],o=(a,n)=>{this.collectIframeAndAttachDocument(i,a);const c=r.getMeta(a);if((c==null?void 0:c.type)===R.Element&&(c==null?void 0:c.tagName.toUpperCase())==="HTML"){const{documentElement:l,head:h}=s.contentDocument;this.insertStyleRules(l,h)}if(!this.usingVirtualDom)for(const l of this.config.plugins||[])l.onBuild&&l.onBuild(a,{id:n,replayer:this})};Ee(e.node,{doc:s.contentDocument,mirror:r,hackCss:!0,skipChild:!1,afterAppend:o,cache:this.cache}),o(s.contentDocument,e.node.id);for(const{mutationInQueue:a,builtNode:n}of i)this.attachDocumentToIframe(a,n),this.newDocumentQueue=this.newDocumentQueue.filter(c=>c!==a)}collectIframeAndAttachDocument(e,s){if(Lt(s,this.mirror)){const r=this.newDocumentQueue.find(i=>i.parentId===this.mirror.getId(s));r&&e.push({mutationInQueue:r,builtNode:s})}}waitForStylesheetLoad(){var e;const s=(e=this.iframe.contentDocument)==null?void 0:e.head;if(s){const r=new Set;let i,o=this.service.state;const a=()=>{o=this.service.state};this.emitter.on(N.Start,a),this.emitter.on(N.Pause,a);const n=()=>{this.emitter.off(N.Start,a),this.emitter.off(N.Pause,a)};s.querySelectorAll('link[rel="stylesheet"]').forEach(c=>{c.sheet||(r.add(c),c.addEventListener("load",()=>{r.delete(c),r.size===0&&i!==-1&&(o.matches("playing")&&this.play(this.getCurrentTime()),this.emitter.emit(N.LoadStylesheetEnd),i&&clearTimeout(i),n())}))}),r.size>0&&(this.service.send({type:"PAUSE"}),this.emitter.emit(N.LoadStylesheetStart),i=setTimeout(()=>{o.matches("playing")&&this.play(this.getCurrentTime()),i=-1,n()},this.config.loadTimeout))}}async preloadAllImages(){const e=[];for(const s of this.service.state.context.events)s.type===L.IncrementalSnapshot&&s.data.source===T.CanvasMutation&&(e.push(this.deserializeAndPreloadCanvasEvents(s.data,s)),("commands"in s.data?s.data.commands:[s.data]).forEach(r=>{this.preloadImages(r,s)}));return Promise.all(e)}preloadImages(e,s){if(e.property==="drawImage"&&typeof e.args[0]=="string"&&!this.imageMap.has(s)){const r=document.createElement("canvas"),i=r.getContext("2d"),o=i==null?void 0:i.createImageData(r.width,r.height);i==null||i.putImageData(o,0,0)}}async deserializeAndPreloadCanvasEvents(e,s){if(!this.canvasEventMap.has(s)){const r={isUnchanged:!0};if("commands"in e){const i=await Promise.all(e.commands.map(async o=>{const a=await Promise.all(o.args.map(K(this.imageMap,null,r)));return W(O({},o),{args:a})}));r.isUnchanged===!1&&this.canvasEventMap.set(s,W(O({},e),{commands:i}))}else{const i=await Promise.all(e.args.map(K(this.imageMap,null,r)));r.isUnchanged===!1&&this.canvasEventMap.set(s,W(O({},e),{args:i}))}}}applyIncremental(e,s){var r,i,o;const{data:a}=e;switch(a.source){case T.Mutation:{try{this.applyMutation(a,s)}catch(n){this.warn(`Exception in mutation ${n.message||n}`,a)}break}case T.Drag:case T.TouchMove:case T.MouseMove:if(s){const n=a.positions[a.positions.length-1];this.mousePos={x:n.x,y:n.y,id:n.id,debugData:a}}else a.positions.forEach(n=>{const c={doAction:()=>{this.moveAndHover(n.x,n.y,n.id,s,a)},delay:n.timeOffset+e.timestamp-this.service.state.context.baselineTime};this.timer.addAction(c)}),this.timer.addAction({doAction(){},delay:e.delay-((r=a.positions[0])==null?void 0:r.timeOffset)});break;case T.MouseInteraction:{if(a.id===-1)break;const n=new Event($n(_[a.type])),c=this.mirror.getNode(a.id);if(!c)return this.debugNodeNotFound(a,a.id);this.emitter.emit(N.MouseInteraction,{type:a.type,target:c});const{triggerFocus:l}=this.config;switch(a.type){case _.Blur:"blur"in c&&c.blur();break;case _.Focus:l&&c.focus&&c.focus({preventScroll:!0});break;case _.Click:case _.TouchStart:case _.TouchEnd:case _.MouseDown:case _.MouseUp:s?(a.type===_.TouchStart?this.touchActive=!0:a.type===_.TouchEnd&&(this.touchActive=!1),a.type===_.MouseDown?this.lastMouseDownEvent=[c,n]:a.type===_.MouseUp&&(this.lastMouseDownEvent=null),this.mousePos={x:a.x||0,y:a.y||0,id:a.id,debugData:a}):(a.type===_.TouchStart&&(this.tailPositions.length=0),this.moveAndHover(a.x||0,a.y||0,a.id,s,a),a.type===_.Click?(this.mouse.classList.remove("active"),this.mouse.offsetWidth,this.mouse.classList.add("active")):a.type===_.TouchStart?(this.mouse.offsetWidth,this.mouse.classList.add("touch-active")):a.type===_.TouchEnd?this.mouse.classList.remove("touch-active"):c.dispatchEvent(n));break;case _.TouchCancel:s?this.touchActive=!1:this.mouse.classList.remove("touch-active");break;default:c.dispatchEvent(n)}break}case T.Scroll:{if(a.id===-1)break;if(this.usingVirtualDom){const n=this.virtualDom.mirror.getNode(a.id);if(!n)return this.debugNodeNotFound(a,a.id);n.scrollData=a;break}this.applyScroll(a,s);break}case T.ViewportResize:this.emitter.emit(N.Resize,{width:a.width,height:a.height});break;case T.Input:{if(a.id===-1)break;if(this.usingVirtualDom){const n=this.virtualDom.mirror.getNode(a.id);if(!n)return this.debugNodeNotFound(a,a.id);n.inputData=a;break}this.applyInput(a);break}case T.MediaInteraction:{const n=this.usingVirtualDom?this.virtualDom.mirror.getNode(a.id):this.mirror.getNode(a.id);if(!n)return this.debugNodeNotFound(a,a.id);const c=n,{events:l}=this.service.state.context;this.mediaManager.mediaMutation({target:c,timeOffset:e.timestamp-l[0].timestamp,mutation:a});break}case T.StyleSheetRule:case T.StyleDeclaration:{this.usingVirtualDom?a.styleId?this.constructedStyleMutations.push(a):a.id&&((i=this.virtualDom.mirror.getNode(a.id))==null||i.rules.push(a)):this.applyStyleSheetMutation(a);break}case T.CanvasMutation:{if(!this.config.UNSAFE_replayCanvas)return;if(this.usingVirtualDom){const n=this.virtualDom.mirror.getNode(a.id);if(!n)return this.debugNodeNotFound(a,a.id);n.canvasMutations.push({event:e,mutation:a})}else{const n=this.mirror.getNode(a.id);if(!n)return this.debugNodeNotFound(a,a.id);Yr({event:e,mutation:a,target:n,imageMap:this.imageMap,canvasEventMap:this.canvasEventMap,errorHandler:this.warnCanvasMutationFailed.bind(this)})}break}case T.Font:{try{const n=new FontFace(a.family,a.buffer?new Uint8Array(JSON.parse(a.fontSource)):a.fontSource,a.descriptors);(o=this.iframe.contentDocument)==null||o.fonts.add(n)}catch(n){this.warn(n)}break}case T.Selection:{if(s){this.lastSelectionData=a;break}this.applySelection(a);break}case T.AdoptedStyleSheet:{this.usingVirtualDom?this.adoptedStyleSheets.push(a):this.applyAdoptedStyleSheet(a);break}}}applyMutation(e,s){if(this.config.useVirtualDom&&!this.usingVirtualDom&&s&&(this.usingVirtualDom=!0,gh(this.iframe.contentDocument,this.mirror,this.virtualDom),Object.keys(this.legacy_missingNodeRetryMap).length))for(const l in this.legacy_missingNodeRetryMap)try{const h=this.legacy_missingNodeRetryMap[l],u=Dn(h.node,this.virtualDom,this.mirror);u&&(h.node=u)}catch(h){this.warn(h)}const r=this.usingVirtualDom?this.virtualDom.mirror:this.mirror;e.removes=e.removes.filter(l=>r.getNode(l.id)?!0:(this.warnNodeNotFound(e,l.id),!1)),e.removes.forEach(l=>{var h;const u=r.getNode(l.id);if(!u)return;let p=r.getNode(l.parentId);if(!p)return this.warnNodeNotFound(e,l.parentId);if(l.isShadow&&Xe(p)&&(p=p.shadowRoot),r.removeNodeFromMap(u),p)try{p.removeChild(u),this.usingVirtualDom&&u.nodeName==="#text"&&p.nodeName==="STYLE"&&((h=p.rules)==null?void 0:h.length)>0&&(p.rules=[])}catch(m){if(m instanceof DOMException)this.warn("parent could not remove child in mutation",p,u,e);else throw m}});const i=O({},this.legacy_missingNodeRetryMap),o=[],a=l=>{let h=null;return l.nextId&&(h=r.getNode(l.nextId)),l.nextId!==null&&l.nextId!==void 0&&l.nextId!==-1&&!h},n=l=>{var h,u;if(!this.iframe.contentDocument)return this.warn("Looks like your replayer has been destroyed.");let p=r.getNode(l.parentId);if(!p)return l.node.type===R.Document?this.newDocumentQueue.push(l):o.push(l);l.node.isShadow&&(Xe(p)||p.attachShadow({mode:"open"}),p=p.shadowRoot);let m=null,b=null;if(l.previousId&&(m=r.getNode(l.previousId)),l.nextId&&(b=r.getNode(l.nextId)),a(l))return o.push(l);if(l.node.rootId&&!r.getNode(l.node.rootId))return;const d=l.node.rootId?r.getNode(l.node.rootId):this.usingVirtualDom?this.virtualDom:this.iframe.contentDocument;if(Lt(p,r)){this.attachDocumentToIframe(l,p);return}const S=(g,x)=>{if(!this.usingVirtualDom)for(const P of this.config.plugins||[])P.onBuild&&P.onBuild(g,{id:x,replayer:this})},f=Ee(l.node,{doc:d,mirror:r,skipChild:!0,hackCss:!0,cache:this.cache,afterAppend:S});if(l.previousId===-1||l.nextId===-1){i[l.node.id]={node:f,mutation:l};return}const w=r.getMeta(p);if(w&&w.type===R.Element&&l.node.type===R.Text){const g=Array.isArray(p.childNodes)?p.childNodes:Array.from(p.childNodes);if(w.tagName==="textarea")for(const x of g)x.nodeType===p.TEXT_NODE&&p.removeChild(x);else if(w.tagName==="style"&&g.length===1)for(const x of g)x.nodeType===p.TEXT_NODE&&!r.hasNode(x)&&(f.textContent=x.textContent,p.removeChild(x))}else if((w==null?void 0:w.type)===R.Document){const g=p;l.node.type===R.DocumentType&&((h=g.childNodes[0])==null?void 0:h.nodeType)===Node.DOCUMENT_TYPE_NODE&&g.removeChild(g.childNodes[0]),f.nodeName==="HTML"&&g.documentElement&&g.removeChild(g.documentElement)}if(m&&m.nextSibling&&m.nextSibling.parentNode?p.insertBefore(f,m.nextSibling):b&&b.parentNode?p.contains(b)?p.insertBefore(f,b):p.insertBefore(f,null):p.appendChild(f),S(f,l.node.id),this.usingVirtualDom&&f.nodeName==="#text"&&p.nodeName==="STYLE"&&((u=p.rules)==null?void 0:u.length)>0&&(p.rules=[]),Lt(f,this.mirror)){const g=this.mirror.getId(f),x=this.newDocumentQueue.find(P=>P.parentId===g);x&&(this.attachDocumentToIframe(x,f),this.newDocumentQueue=this.newDocumentQueue.filter(P=>P!==x))}(l.previousId||l.nextId)&&this.legacy_resolveMissingNode(i,p,f,l)};e.adds.forEach(l=>{n(l)});const c=Date.now();for(;o.length;){const l=$a(o);if(o.length=0,Date.now()-c>500){this.warn("Timeout in the loop, please check the resolve tree data:",l);break}for(const h of l)r.getNode(h.value.parentId)?_i(h,u=>{n(u)}):this.debug("Drop resolve tree since there is no parent for the root node.",h)}Object.keys(i).length&&Object.assign(this.legacy_missingNodeRetryMap,i),Ja(e.texts).forEach(l=>{var m;var h;const u=r.getNode(l.id);if(!u)return e.removes.find(b=>b.id===l.id)?void 0:this.warnNodeNotFound(e,l.id);let p;if(l.delta){const b=this.textValueMap.get(l.id)||"";p=Ka(b,l.delta)}else p=(m=l.value)!=null?m:null;if(u.textContent=p,p!==null&&this.textValueMap.set(l.id,p),this.usingVirtualDom){const b=u.parentNode;((h=b==null?void 0:b.rules)==null?void 0:h.length)>0&&(b.rules=[])}}),e.attributes.forEach(l=>{var h;const u=r.getNode(l.id);if(!u)return e.removes.find(p=>p.id===l.id)?void 0:this.warnNodeNotFound(e,l.id);for(const p in l.attributes)if(typeof p=="string"){const m=l.attributes[p];if(m===null)u.removeAttribute(p);else if(typeof m=="string")try{if(p==="_cssText"&&(u.nodeName==="LINK"||u.nodeName==="STYLE"))try{const b=r.getMeta(u);Object.assign(b.attributes,l.attributes);const d=Ee(b,{doc:u.ownerDocument,mirror:r,skipChild:!0,hackCss:!0,cache:this.cache}),S=u.nextSibling,f=u.parentNode;if(d&&f){f.removeChild(u),f.insertBefore(d,S),r.replace(l.id,d);break}}catch(b){}if(p==="value"&&u.nodeName==="TEXTAREA"){const b=u;b.childNodes.forEach(S=>b.removeChild(S));const d=(h=u.ownerDocument)==null?void 0:h.createTextNode(m);d&&b.appendChild(d)}else u.setAttribute(p,m)}catch(b){this.warn("An error occurred may due to the checkout feature.",b)}else if(p==="style"){const b=m,d=u;for(const S in b)if(b[S]===!1)d.style.removeProperty(S);else if(b[S]instanceof Array){const f=b[S];d.style.setProperty(S,f[0],f[1])}else{const f=b[S];d.style.setProperty(S,f)}}}})}applyScroll(e,s){var r,i;const o=this.mirror.getNode(e.id);if(!o)return this.debugNodeNotFound(e,e.id);const a=this.mirror.getMeta(o);if(o===this.iframe.contentDocument)(r=this.iframe.contentWindow)==null||r.scrollTo({top:e.y,left:e.x,behavior:s?"auto":"smooth"});else if((a==null?void 0:a.type)===R.Document)(i=o.defaultView)==null||i.scrollTo({top:e.y,left:e.x,behavior:s?"auto":"smooth"});else try{o.scrollTo({top:e.y,left:e.x,behavior:s?"auto":"smooth"})}catch(n){}}applyInput(e){const s=this.mirror.getNode(e.id);if(!s)return this.debugNodeNotFound(e,e.id);try{s.checked=e.isChecked,s.value=e.text}catch(r){}}applySelection(e){try{const s=new Set,r=e.ranges.map(({start:i,startOffset:o,end:a,endOffset:n})=>{const c=this.mirror.getNode(i),l=this.mirror.getNode(a);if(!c||!l)return;const h=new Range;h.setStart(c,o),h.setEnd(l,n);const u=c.ownerDocument,p=u==null?void 0:u.getSelection();return p&&s.add(p),{range:h,selection:p}});s.forEach(i=>i.removeAllRanges()),r.forEach(i=>{var o;return i&&((o=i.selection)==null?void 0:o.addRange(i.range))})}catch(s){}}applyStyleSheetMutation(e){var s;let r=null;e.styleId?r=this.styleMirror.getStyle(e.styleId):e.id&&(r=((s=this.mirror.getNode(e.id))==null?void 0:s.sheet)||null),r&&(e.source===T.StyleSheetRule?this.applyStyleSheetRule(e,r):e.source===T.StyleDeclaration&&this.applyStyleDeclaration(e,r))}applyStyleSheetRule(e,s){var r,i,o,a;if((r=e.adds)==null||r.forEach(({rule:n,index:c})=>{try{if(Array.isArray(c)){const{positions:l,index:h}=Sr(c);xe(s.cssRules,l).insertRule(n,h)}else{const l=c===void 0?void 0:Math.min(c,s.cssRules.length);s==null||s.insertRule(n,l)}}catch(l){}}),(i=e.removes)==null||i.forEach(({index:n})=>{try{if(Array.isArray(n)){const{positions:c,index:l}=Sr(n);xe(s.cssRules,c).deleteRule(l||0)}else s==null||s.deleteRule(n)}catch(c){}}),e.replace)try{(o=s.replace)==null||o.call(s,e.replace)}catch(n){}if(e.replaceSync)try{(a=s.replaceSync)==null||a.call(s,e.replaceSync)}catch(n){}}applyStyleDeclaration(e,s){e.set&&xe(s.rules,e.index).style.setProperty(e.set.property,e.set.value,e.set.priority),e.remove&&xe(s.rules,e.index).style.removeProperty(e.remove.property)}applyAdoptedStyleSheet(e){var s;const r=this.mirror.getNode(e.id);if(!r)return;(s=e.styles)==null||s.forEach(n=>{var c;let l=null,h=null;if(Xe(r)?h=((c=r.ownerDocument)==null?void 0:c.defaultView)||null:r.nodeName==="#document"&&(h=r.defaultView),!!h)try{l=new h.CSSStyleSheet,this.styleMirror.add(l,n.styleId),this.applyStyleSheetRule({source:T.StyleSheetRule,adds:n.rules},l)}catch(u){}});const i=10;let o=0;const a=(n,c)=>{const l=c.map(h=>this.styleMirror.getStyle(h)).filter(h=>h!==null);Xe(n)?n.shadowRoot.adoptedStyleSheets=l:n.nodeName==="#document"&&(n.adoptedStyleSheets=l),l.length!==c.length&&o<i&&(setTimeout(()=>a(n,c),0+100*o),o++)};a(r,e.styleIds)}legacy_resolveMissingNode(e,s,r,i){const{previousId:o,nextId:a}=i,n=o&&e[o],c=a&&e[a];if(n){const{node:l,mutation:h}=n;s.insertBefore(l,r),delete e[h.node.id],delete this.legacy_missingNodeRetryMap[h.node.id],(h.previousId||h.nextId)&&this.legacy_resolveMissingNode(e,s,l,h)}if(c){const{node:l,mutation:h}=c;s.insertBefore(l,r.nextSibling),delete e[h.node.id],delete this.legacy_missingNodeRetryMap[h.node.id],(h.previousId||h.nextId)&&this.legacy_resolveMissingNode(e,s,l,h)}}moveAndHover(e,s,r,i,o){const a=this.mirror.getNode(r);if(!a)return this.debugNodeNotFound(o,r);const n=Ui(a,this.iframe),c=e*n.absoluteScale+n.x,l=s*n.absoluteScale+n.y;this.mouse.style.left=`${c}px`,this.mouse.style.top=`${l}px`,i||this.drawMouseTail({x:c,y:l}),this.hoverElements(a)}drawMouseTail(e){if(!this.mouseTail)return;const{lineCap:s,lineWidth:r,strokeStyle:i,duration:o}=this.config.mouseTail===!0?jt:Object.assign({},jt,this.config.mouseTail),a=()=>{if(!this.mouseTail)return;const n=this.mouseTail.getContext("2d");!n||!this.tailPositions.length||(n.clearRect(0,0,this.mouseTail.width,this.mouseTail.height),n.beginPath(),n.lineWidth=r,n.lineCap=s,n.strokeStyle=i,n.moveTo(this.tailPositions[0].x,this.tailPositions[0].y),this.tailPositions.forEach(c=>n.lineTo(c.x,c.y)),n.stroke())};this.tailPositions.push(e),a(),setTimeout(()=>{this.tailPositions=this.tailPositions.filter(n=>n!==e),a()},o/this.speedService.state.context.timer.speed)}hoverElements(e){var s;(s=this.lastHoveredRootNode||this.iframe.contentDocument)==null||s.querySelectorAll(".\\:hover").forEach(i=>{i.classList.remove(":hover")}),this.lastHoveredRootNode=e.getRootNode();let r=e;for(;r;)r.classList&&r.classList.add(":hover"),r=r.parentElement}isUserInteraction(e){return e.type!==L.IncrementalSnapshot?!1:e.data.source>T.Mutation&&e.data.source<=T.Input}backToNormal(){this.nextUserInteractionEvent=null,!this.speedService.state.matches("normal")&&(this.speedService.send({type:"BACK_TO_NORMAL"}),this.emitter.emit(N.SkipEnd,{speed:this.speedService.state.context.normalSpeed}))}warnNodeNotFound(e,s){this.warn(`Node with id '${s}' not found. `,e)}warnCanvasMutationFailed(e,s){this.warn("Has error on canvas update",s,"canvas mutation:",e)}debugNodeNotFound(e,s){this.debug(`Node with id '${s}' not found. `,e)}warn(...e){this.config.showWarning&&this.config.logger.warn(Qr,...e)}debug(...e){this.config.showDebug&&this.config.logger.log(Qr,...e)}}exports.Replayer=Ph;
|
|
72
|
+
***************************************************************************** */function Gr(t,e){var s=typeof Symbol=="function"&&t[Symbol.iterator];if(!s)return t;var r,i,o=s.call(t),a=[];try{for(;(e===void 0||e-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(n){i={error:n}}finally{try{r&&!r.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}return a}var oe;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(oe||(oe={}));var In={type:"xstate.init"};function Wt(t){return t===void 0?[]:[].concat(t)}function ne(t){return{type:"xstate.assign",assignment:t}}function Xr(t,e){return typeof(t=typeof t=="string"&&e&&e[t]?e[t]:t)=="string"?{type:t}:typeof t=="function"?{type:t.name,exec:t}:t}function yt(t){return function(e){return t===e}}function Pn(t){return typeof t=="string"?{type:t}:t}function Zr(t,e){return{value:t,context:e,actions:[],changed:!1,matches:yt(t)}}function Hr(t,e,s){var r=e,i=!1;return[t.filter(function(o){if(o.type==="xstate.assign"){i=!0;var a=Object.assign({},r);return typeof o.assignment=="function"?a=o.assignment(r,s):Object.keys(o.assignment).forEach(function(n){a[n]=typeof o.assignment[n]=="function"?o.assignment[n](r,s):o.assignment[n]}),r=a,!1}return!0}),r,i]}function Ln(t,e){e===void 0&&(e={});var s=Gr(Hr(Wt(t.states[t.initial].entry).map(function(a){return Xr(a,e.actions)}),t.context,In),2),r=s[0],i=s[1],o={config:t,_options:e,initialState:{value:t.initial,actions:r,context:i,matches:yt(t.initial)},transition:function(a,n){var c,l,h=typeof a=="string"?{value:a,context:t.context}:a,u=h.value,p=h.context,m=Pn(n),b=t.states[u];if(b.on){var d=Wt(b.on[m.type]);try{for(var S=function(U){var Rt=typeof Symbol=="function"&&Symbol.iterator,Zs=Rt&&U[Rt],Hs=0;if(Zs)return Zs.call(U);if(U&&typeof U.length=="number")return{next:function(){return U&&Hs>=U.length&&(U=void 0),{value:U&&U[Hs++],done:!U}}};throw new TypeError(Rt?"Object is not iterable.":"Symbol.iterator is not defined.")}(d),f=S.next();!f.done;f=S.next()){var w=f.value;if(w===void 0)return Zr(u,p);var g=typeof w=="string"?{target:w}:w,x=g.target,P=g.actions,B=P===void 0?[]:P,F=g.cond,V=F===void 0?function(){return!0}:F,ee=x===void 0,_n=x!=null?x:u,Un=t.states[_n];if(V(p,m)){var Dt=Gr(Hr((ee?Wt(B):[].concat(b.exit,B,Un.entry).filter(function(U){return U})).map(function(U){return Xr(U,o._options.actions)}),p,m),3),Gs=Dt[0],Bn=Dt[1],Wn=Dt[2],Xs=x!=null?x:u;return{value:Xs,context:Bn,actions:Gs,changed:x!==u||Gs.length>0||Wn,matches:yt(Xs)}}}}catch(U){c={error:U}}finally{try{f&&!f.done&&(l=S.return)&&l.call(S)}finally{if(c)throw c.error}}}return Zr(u,p)}};return o}var $r=function(t,e){return t.actions.forEach(function(s){var r=s.exec;return r&&r(t.context,e)})};function Fn(t){var e=t.initialState,s=oe.NotStarted,r=new Set,i={_machine:t,send:function(o){s===oe.Running&&(e=t.transition(e,o),$r(e,Pn(o)),r.forEach(function(a){return a(e)}))},subscribe:function(o){return r.add(o),o(e),{unsubscribe:function(){return r.delete(o)}}},start:function(o){if(o){var a=typeof o=="object"?o:{context:t.config.context,value:o};e={value:a.value,actions:[],context:a.context,matches:yt(a.value)}}return s=oe.Running,$r(e,In),i},stop:function(){return s=oe.Stopped,r.clear(),i},get state(){return e},get status(){return s}};return i}class Mh{constructor(e=[],s){v(this,"timeOffset",0),v(this,"speed"),v(this,"actions"),v(this,"raf",null),v(this,"lastTimestamp"),this.actions=e,this.speed=s.speed}addAction(e){const s=this.raf===!0;if(!this.actions.length||this.actions[this.actions.length-1].delay<=e.delay)this.actions.push(e);else{const r=this.findActionIndex(e);this.actions.splice(r,0,e)}s&&(this.raf=requestAnimationFrame(this.rafCheck.bind(this)))}start(){this.timeOffset=0,this.lastTimestamp=performance.now(),this.raf=requestAnimationFrame(this.rafCheck.bind(this))}rafCheck(){const e=performance.now();for(this.timeOffset+=(e-this.lastTimestamp)*this.speed,this.lastTimestamp=e;this.actions.length;){const s=this.actions[0];if(this.timeOffset>=s.delay)this.actions.shift(),s.doAction();else break}this.actions.length>0?this.raf=requestAnimationFrame(this.rafCheck.bind(this)):this.raf=!0}clear(){this.raf&&(this.raf!==!0&&cancelAnimationFrame(this.raf),this.raf=null),this.actions.length=0}setSpeed(e){this.speed=e}isActive(){return this.raf!==null}findActionIndex(e){let s=0,r=this.actions.length-1;for(;s<=r;){const i=Math.floor((s+r)/2);if(this.actions[i].delay<e.delay)s=i+1;else if(this.actions[i].delay>e.delay)r=i-1;else return i+1}return s}}function Jr(t,e){if(t.type===L.IncrementalSnapshot&&t.data.source===T.MouseMove&&t.data.positions&&t.data.positions.length){const s=t.data.positions[0].timeOffset,r=t.timestamp+s;return t.delay=r-e,r-e}return t.delay=t.timestamp-e,t.delay}function Nh(t,e){for(let s=t.length-1;s>=0;s--){const r=t[s];if(r.type===L.FullSnapshot&&r.timestamp<=e)return s>0&&t[s-1].type===L.Meta&&t[s-1].timestamp<=e?t.slice(s-1):t.slice(s)}return t}function Th(t,{getCastFn:e,applyEventsSynchronously:s,emitter:r}){const i=Ln({id:"player",context:t,initial:"paused",states:{playing:{on:{PAUSE:{target:"paused",actions:["pause"]},CAST_EVENT:{target:"playing",actions:"castEvent"},END:{target:"paused",actions:["resetLastPlayedEvent","pause"]},ADD_EVENT:{target:"playing",actions:["addEvent"]}}},paused:{on:{PLAY:{target:"playing",actions:["recordTimeOffset","play"]},CAST_EVENT:{target:"paused",actions:"castEvent"},TO_LIVE:{target:"live",actions:["startLive"]},ADD_EVENT:{target:"paused",actions:["addEvent"]}}},live:{on:{ADD_EVENT:{target:"live",actions:["addEvent"]},CAST_EVENT:{target:"live",actions:["castEvent"]}}}}},{actions:{castEvent:ne({lastPlayedEvent:(o,a)=>a.type==="CAST_EVENT"?a.payload.event:o.lastPlayedEvent}),recordTimeOffset:ne((o,a)=>{let n=o.timeOffset;return"payload"in a&&"timeOffset"in a.payload&&(n=a.payload.timeOffset),W(O({},o),{timeOffset:n,baselineTime:o.events[0].timestamp+n})}),play(o){const{timer:a,events:n,baselineTime:c}=o;a.clear();for(const u of n)Jr(u,c);const l=Nh(n,c);r.emit(N.PlayBack);const h=new Array;for(const u of l)if(u.timestamp<c)h.push(u);else{const p=e(u,!1);a.addAction({doAction:()=>{p()},delay:u.delay})}s(h),r.emit(N.Flush),a.start()},pause(o){o.timer.clear()},resetLastPlayedEvent:ne(o=>W(O({},o),{lastPlayedEvent:null})),startLive:ne({baselineTime:(o,a)=>(o.timer.start(),a.type==="TO_LIVE"&&a.payload.baselineTime?a.payload.baselineTime:Date.now())}),addEvent:ne((o,a)=>{const{baselineTime:n,timer:c,events:l}=o;if(a.type==="ADD_EVENT"){const{event:h}=a.payload;Jr(h,n);let u=l.length-1;if(!l[u]||l[u].timestamp<=h.timestamp)l.push(h);else{let b=-1,d=0;for(;d<=u;){const S=Math.floor((d+u)/2);l[S].timestamp<=h.timestamp?d=S+1:u=S-1}b===-1&&(b=d),l.splice(b,0,h)}const p=h.timestamp<n,m=e(h,p);p?m():c.isActive()&&c.addAction({doAction:()=>{m()},delay:h.delay})}return W(O({},o),{events:l})})}});return Fn(i)}function kh(t){const e=Ln({id:"speed",context:t,initial:"normal",states:{normal:{on:{FAST_FORWARD:{target:"skipping",actions:["recordSpeed","setSpeed"]},SET_SPEED:{target:"normal",actions:["setSpeed"]}}},skipping:{on:{BACK_TO_NORMAL:{target:"normal",actions:["restoreSpeed"]},SET_SPEED:{target:"normal",actions:["setSpeed"]}}}}},{actions:{setSpeed:(s,r)=>{"payload"in r&&s.timer.setSpeed(r.payload.speed)},recordSpeed:ne({normalSpeed:s=>s.timer.speed}),restoreSpeed:s=>{s.timer.setSpeed(s.normalSpeed)}}});return Fn(e)}class Dh{constructor(e){v(this,"mediaMap",new Map),v(this,"warn"),v(this,"service"),v(this,"speedService"),v(this,"emitter"),v(this,"getCurrentTime"),v(this,"metadataCallbackMap",new Map),this.warn=e.warn,this.service=e.service,this.speedService=e.speedService,this.emitter=e.emitter,this.getCurrentTime=e.getCurrentTime,this.emitter.on(N.Start,this.start.bind(this)),this.emitter.on(N.SkipStart,this.start.bind(this)),this.emitter.on(N.Pause,this.pause.bind(this)),this.emitter.on(N.Finish,this.pause.bind(this)),this.speedService.subscribe(()=>{this.syncAllMediaElements()})}syncAllMediaElements(e={pause:!1}){this.mediaMap.forEach((s,r)=>{this.syncTargetWithState(r),e.pause&&r.pause()})}start(){this.syncAllMediaElements()}pause(){this.syncAllMediaElements({pause:!0})}seekTo({time:e,target:s,mediaState:r}){if(r.isPlaying){const i=(e-r.lastInteractionTimeOffset)/1e3*r.playbackRate,o="duration"in s&&s.duration;if(Number.isNaN(o)){this.waitForMetadata(s);return}let a=r.currentTimeAtLastInteraction+i;s.loop&&o!==!1&&(a=a%o),s.currentTime=a}else s.pause(),s.currentTime=r.currentTimeAtLastInteraction}waitForMetadata(e){if(this.metadataCallbackMap.has(e)||!("addEventListener"in e))return;const s=()=>{this.metadataCallbackMap.delete(e);const r=this.mediaMap.get(e);r&&this.seekTo({time:this.getCurrentTime(),target:e,mediaState:r})};this.metadataCallbackMap.set(e,s),e.addEventListener("loadedmetadata",s,{once:!0})}getMediaStateFromMutation({target:e,timeOffset:s,mutation:r}){var u,p,m,b,d;const i=this.mediaMap.get(e),{type:o,playbackRate:a,currentTime:n,muted:c,volume:l,loop:h}=r;return{isPlaying:o===rs.Play||o!==rs.Pause&&((i==null?void 0:i.isPlaying)||e.getAttribute("autoplay")!==null),currentTimeAtLastInteraction:(u=n!=null?n:i==null?void 0:i.currentTimeAtLastInteraction)!=null?u:0,lastInteractionTimeOffset:s,playbackRate:(p=a!=null?a:i==null?void 0:i.playbackRate)!=null?p:1,volume:(m=l!=null?l:i==null?void 0:i.volume)!=null?m:1,muted:(b=c!=null?c:i==null?void 0:i.muted)!=null?b:e.getAttribute("muted")===null,loop:(d=h!=null?h:i==null?void 0:i.loop)!=null?d:e.getAttribute("loop")===null}}syncTargetWithState(e){const s=this.mediaMap.get(e);if(!s)return;const{muted:r,loop:i,volume:o,isPlaying:a}=s,n=this.service.state.matches("paused"),c=s.playbackRate*this.speedService.state.context.timer.speed;try{this.seekTo({time:this.getCurrentTime(),target:e,mediaState:s}),e.volume!==o&&(e.volume=o),e.muted=r,e.loop=i,e.playbackRate!==c&&(e.playbackRate=c),a&&!n?e.play():e.pause()}catch(l){this.warn(`Failed to replay media interactions: ${l.message||l}`)}}addMediaElements(e,s,r){if(!["AUDIO","VIDEO"].includes(e.nodeName))return;const i=e,o=r.getMeta(i);if(!o||!("attributes"in o))return;const a=this.service.state.matches("paused"),n=o.attributes;let c=!1;n.rr_mediaState?c=n.rr_mediaState==="played":c=i.getAttribute("autoplay")!==null,c&&a&&i.pause();let l=1;typeof n.rr_mediaPlaybackRate=="number"&&(l=n.rr_mediaPlaybackRate);let h=!1;typeof n.rr_mediaMuted=="boolean"?h=n.rr_mediaMuted:h=i.getAttribute("muted")!==null;let u=!1;typeof n.rr_mediaLoop=="boolean"?u=n.rr_mediaLoop:u=i.getAttribute("loop")!==null;let p=1;typeof n.rr_mediaVolume=="number"&&(p=n.rr_mediaVolume);let m=0;typeof n.rr_mediaCurrentTime=="number"&&(m=n.rr_mediaCurrentTime),this.mediaMap.set(i,{isPlaying:c,currentTimeAtLastInteraction:m,lastInteractionTimeOffset:s,playbackRate:l,volume:p,muted:h,loop:u}),this.syncTargetWithState(i)}mediaMutation({target:e,timeOffset:s,mutation:r}){this.mediaMap.set(e,this.getMediaStateFromMutation({target:e,timeOffset:s,mutation:r})),this.syncTargetWithState(e)}isSupportedMediaElement(e){return["AUDIO","VIDEO"].includes(e.nodeName)}reset(){this.mediaMap.clear()}}function Rh(t=window,e=document){if("scrollBehavior"in e.documentElement.style&&t.__forceSmoothScrollPolyfill__!==!0)return;const s=t.HTMLElement||t.Element,r=468,i={scroll:t.scroll||t.scrollTo,scrollBy:t.scrollBy,elementScroll:s.prototype.scroll||c,scrollIntoView:s.prototype.scrollIntoView},o=t.performance&&t.performance.now?t.performance.now.bind(t.performance):Date.now;function a(f){const w=["MSIE ","Trident/","Edge/"];return new RegExp(w.join("|")).test(f)}const n=a(t.navigator.userAgent)?1:0;function c(f,w){this.scrollLeft=f,this.scrollTop=w}function l(f){return .5*(1-Math.cos(Math.PI*f))}function h(f){if(f===null||typeof f!="object"||f.behavior===void 0||f.behavior==="auto"||f.behavior==="instant")return!0;if(typeof f=="object"&&f.behavior==="smooth")return!1;throw new TypeError("behavior member of ScrollOptions "+f.behavior+" is not a valid value for enumeration ScrollBehavior.")}function u(f,w){if(w==="Y")return f.clientHeight+n<f.scrollHeight;if(w==="X")return f.clientWidth+n<f.scrollWidth}function p(f,w){const g=t.getComputedStyle(f,null)["overflow"+w];return g==="auto"||g==="scroll"}function m(f){const w=u(f,"Y")&&p(f,"Y"),g=u(f,"X")&&p(f,"X");return w||g}function b(f){for(;f!==e.body&&m(f)===!1;)f=f.parentNode||f.host;return f}function d(f){const w=o();let g,x,P,B=(w-f.startTime)/r;B=B>1?1:B,g=l(B),x=f.startX+(f.x-f.startX)*g,P=f.startY+(f.y-f.startY)*g,f.method.call(f.scrollable,x,P),(x!==f.x||P!==f.y)&&t.requestAnimationFrame(d.bind(t,f))}function S(f,w,g){let x,P,B,F;const V=o();f===e.body?(x=t,P=t.scrollX||t.pageXOffset,B=t.scrollY||t.pageYOffset,F=i.scroll):(x=f,P=f.scrollLeft,B=f.scrollTop,F=c),d({scrollable:x,method:F,startTime:V,startX:P,startY:B,x:w,y:g})}t.scroll=t.scrollTo=function(){if(arguments[0]!==void 0){if(h(arguments[0])===!0){i.scroll.call(t,arguments[0].left!==void 0?arguments[0].left:typeof arguments[0]!="object"?arguments[0]:t.scrollX||t.pageXOffset,arguments[0].top!==void 0?arguments[0].top:arguments[1]!==void 0?arguments[1]:t.scrollY||t.pageYOffset);return}S.call(t,e.body,arguments[0].left!==void 0?~~arguments[0].left:t.scrollX||t.pageXOffset,arguments[0].top!==void 0?~~arguments[0].top:t.scrollY||t.pageYOffset)}},t.scrollBy=function(){if(arguments[0]!==void 0){if(h(arguments[0])){i.scrollBy.call(t,arguments[0].left!==void 0?arguments[0].left:typeof arguments[0]!="object"?arguments[0]:0,arguments[0].top!==void 0?arguments[0].top:arguments[1]!==void 0?arguments[1]:0);return}S.call(t,e.body,~~arguments[0].left+(t.scrollX||t.pageXOffset),~~arguments[0].top+(t.scrollY||t.pageYOffset))}},s.prototype.scroll=s.prototype.scrollTo=function(){if(arguments[0]===void 0)return;if(h(arguments[0])===!0){if(typeof arguments[0]=="number"&&arguments[1]===void 0)throw new SyntaxError("Value could not be converted");i.elementScroll.call(this,arguments[0].left!==void 0?~~arguments[0].left:typeof arguments[0]!="object"?~~arguments[0]:this.scrollLeft,arguments[0].top!==void 0?~~arguments[0].top:arguments[1]!==void 0?~~arguments[1]:this.scrollTop);return}const f=arguments[0].left,w=arguments[0].top;S.call(this,this,typeof f>"u"?this.scrollLeft:~~f,typeof w>"u"?this.scrollTop:~~w)},s.prototype.scrollBy=function(){if(arguments[0]!==void 0){if(h(arguments[0])===!0){i.elementScroll.call(this,arguments[0].left!==void 0?~~arguments[0].left+this.scrollLeft:~~arguments[0]+this.scrollLeft,arguments[0].top!==void 0?~~arguments[0].top+this.scrollTop:~~arguments[1]+this.scrollTop);return}this.scroll({left:~~arguments[0].left+this.scrollLeft,top:~~arguments[0].top+this.scrollTop,behavior:arguments[0].behavior})}},s.prototype.scrollIntoView=function(){if(h(arguments[0])===!0){i.scrollIntoView.call(this,arguments[0]===void 0?!0:arguments[0]);return}const f=b(this),w=f.getBoundingClientRect(),g=this.getBoundingClientRect();f!==e.body?(S.call(this,f,f.scrollLeft+g.left-w.left,f.scrollTop+g.top-w.top),t.getComputedStyle(f).position!=="fixed"&&t.scrollBy({left:w.left,top:w.top,behavior:"smooth"})):t.scrollBy({left:g.left,top:g.top,behavior:"smooth"})}}const Oh=t=>[`.${t} { background: currentColor }`,"noscript { display: none !important; }"],Ah=5*1e3,Ih=On||bh,Qr="[replayer]",jt={duration:500,lineCap:"round",lineWidth:3,strokeStyle:"red"};function Kr(t){return t.type==L.IncrementalSnapshot&&(t.data.source==T.TouchMove||t.data.source==T.MouseInteraction&&t.data.type==_.TouchStart)}class Ph{constructor(e,s){if(v(this,"wrapper"),v(this,"iframe"),v(this,"service"),v(this,"speedService"),v(this,"config"),v(this,"usingVirtualDom",!1),v(this,"virtualDom",new de),v(this,"mouse"),v(this,"mouseTail",null),v(this,"tailPositions",[]),v(this,"emitter",Ih()),v(this,"nextUserInteractionEvent"),v(this,"legacy_missingNodeRetryMap",{}),v(this,"cache",br()),v(this,"imageMap",new Map),v(this,"canvasEventMap",new Map),v(this,"mirror",ei()),v(this,"styleMirror",new Qa),v(this,"mediaManager"),v(this,"firstFullSnapshot",null),v(this,"newDocumentQueue",[]),v(this,"mousePos",null),v(this,"touchActive",null),v(this,"lastMouseDownEvent",null),v(this,"lastHoveredRootNode"),v(this,"textValueMap",new Map),v(this,"lastSelectionData",null),v(this,"constructedStyleMutations",[]),v(this,"adoptedStyleSheets",[]),v(this,"handleResize",n=>{this.iframe.style.display="inherit";for(const c of[this.mouseTail,this.iframe])c&&(c.setAttribute("width",String(n.width)),c.setAttribute("height",String(n.height)))}),v(this,"applyEventsSynchronously",n=>{for(const c of n){switch(c.type){case L.DomContentLoaded:case L.Load:case L.Custom:continue;case L.FullSnapshot:case L.Meta:case L.Plugin:case L.IncrementalSnapshot:break}this.getCastFn(c,!0)()}}),v(this,"getCastFn",(n,c=!1)=>{let l;switch(n.type){case L.DomContentLoaded:case L.Load:break;case L.Custom:l=()=>{this.emitter.emit(N.CustomEvent,n)};break;case L.Meta:l=()=>this.emitter.emit(N.Resize,{width:n.data.width,height:n.data.height});break;case L.FullSnapshot:l=()=>{var h;if(this.firstFullSnapshot){if(this.firstFullSnapshot===n){this.firstFullSnapshot=!0;return}}else this.firstFullSnapshot=!0;this.mediaManager.reset(),this.styleMirror.reset(),this.rebuildFullSnapshot(n,c),(h=this.iframe.contentWindow)==null||h.scrollTo(n.data.initialOffset)};break;case L.IncrementalSnapshot:l=()=>{if(this.applyIncremental(n,c),!c&&(n===this.nextUserInteractionEvent&&(this.nextUserInteractionEvent=null,this.backToNormal()),!this.nextUserInteractionEvent)){for(const h of this.service.state.context.events)if(!(h.timestamp<=n.timestamp)&&this.isUserInteraction(h)){h.delay-n.delay>this.config.inactivePeriodThreshold*this.speedService.state.context.timer.speed&&(this.nextUserInteractionEvent=h);break}if(this.nextUserInteractionEvent)if(this.config.skipInactive)this.play(this.nextUserInteractionEvent.timestamp-this.getMetaData().startTime-1e3);else{const h=this.nextUserInteractionEvent.delay-n.delay,u={speed:Math.min(Math.round(h/Ah),this.config.maxSpeed)};this.speedService.send({type:"FAST_FORWARD",payload:u}),this.emitter.emit(N.SkipStart,u)}}};break}return()=>{l&&l();for(const u of this.config.plugins||[])u.handler&&u.handler(n,c,{replayer:this});this.service.send({type:"CAST_EVENT",payload:{event:n}});const h=this.service.state.context.events.length-1;if(!this.config.liveMode&&n===this.service.state.context.events[h]){const u=()=>{h<this.service.state.context.events.length-1||(this.backToNormal(),this.service.send("END"),this.emitter.emit(N.Finish))};let p=50;n.type===L.IncrementalSnapshot&&n.data.source===T.MouseMove&&n.data.positions.length&&(p+=Math.max(0,-n.data.positions[0].timeOffset)),setTimeout(u,p)}this.emitter.emit(N.EventCast,n)}}),!(s!=null&&s.liveMode)&&e.length<2)throw new Error("Replayer need at least 2 events.");const r={speed:1,maxSpeed:360,root:document.body,loadTimeout:0,skipInactive:!1,inactivePeriodThreshold:10*1e3,showWarning:!0,showDebug:!1,blockClass:"rr-block",liveMode:!1,insertStyleRules:[],triggerFocus:!0,UNSAFE_replayCanvas:!1,pauseAnimation:!0,mouseTail:jt,useVirtualDom:!0,logger:console};this.config=Object.assign({},r,s),this.handleResize=this.handleResize.bind(this),this.getCastFn=this.getCastFn.bind(this),this.applyEventsSynchronously=this.applyEventsSynchronously.bind(this),this.emitter.on(N.Resize,this.handleResize),this.setupDom();for(const n of this.config.plugins||[])n.getMirror&&n.getMirror({nodeMirror:this.mirror});this.emitter.on(N.Flush,()=>{if(this.usingVirtualDom){const n={mirror:this.mirror,applyCanvas:(c,l,h)=>{Yr({event:c,mutation:l,target:h,imageMap:this.imageMap,canvasEventMap:this.canvasEventMap,errorHandler:this.warnCanvasMutationFailed.bind(this)})},applyInput:this.applyInput.bind(this),applyScroll:this.applyScroll.bind(this),applyStyleSheetMutation:(c,l)=>{c.source===T.StyleSheetRule?this.applyStyleSheetRule(c,l):c.source===T.StyleDeclaration&&this.applyStyleDeclaration(c,l)},afterAppend:(c,l)=>{for(const h of this.config.plugins||[])h.onBuild&&h.onBuild(c,{id:l,replayer:this})}};if(this.iframe.contentDocument)try{mt(this.iframe.contentDocument,this.virtualDom,n,this.virtualDom.mirror)}catch(c){console.warn(c)}if(this.virtualDom.destroyTree(),this.usingVirtualDom=!1,Object.keys(this.legacy_missingNodeRetryMap).length)for(const c in this.legacy_missingNodeRetryMap)try{const l=this.legacy_missingNodeRetryMap[c],h=gt(l.node,this.mirror,this.virtualDom.mirror);mt(h,l.node,n,this.virtualDom.mirror),l.node=h}catch(l){this.warn(l)}this.constructedStyleMutations.forEach(c=>{this.applyStyleSheetMutation(c)}),this.constructedStyleMutations=[],this.adoptedStyleSheets.forEach(c=>{this.applyAdoptedStyleSheet(c)}),this.adoptedStyleSheets=[]}if(this.mousePos&&(this.moveAndHover(this.mousePos.x,this.mousePos.y,this.mousePos.id,!0,this.mousePos.debugData),this.mousePos=null),this.touchActive===!0?this.mouse.classList.add("touch-active"):this.touchActive===!1&&this.mouse.classList.remove("touch-active"),this.touchActive=null,this.lastMouseDownEvent){const[n,c]=this.lastMouseDownEvent;n.dispatchEvent(c)}this.lastMouseDownEvent=null,this.lastSelectionData&&(this.applySelection(this.lastSelectionData),this.lastSelectionData=null)}),this.emitter.on(N.PlayBack,()=>{this.firstFullSnapshot=null,this.mirror.reset(),this.styleMirror.reset(),this.mediaManager.reset(),this.textValueMap.clear()});const i=new Mh([],{speed:this.config.speed});this.service=Th({events:e.map(n=>s&&s.unpackFn?s.unpackFn(n):n).sort((n,c)=>n.timestamp-c.timestamp),timer:i,timeOffset:0,baselineTime:0,lastPlayedEvent:null},{getCastFn:this.getCastFn,applyEventsSynchronously:this.applyEventsSynchronously,emitter:this.emitter}),this.service.start(),this.service.subscribe(n=>{this.emitter.emit(N.StateChange,{player:n})}),this.speedService=kh({normalSpeed:-1,timer:i}),this.speedService.start(),this.speedService.subscribe(n=>{this.emitter.emit(N.StateChange,{speed:n})}),this.mediaManager=new Dh({warn:this.warn.bind(this),service:this.service,speedService:this.speedService,emitter:this.emitter,getCurrentTime:this.getCurrentTime.bind(this)});const o=this.service.state.context.events.find(n=>n.type===L.Meta),a=this.service.state.context.events.find(n=>n.type===L.FullSnapshot);if(o){const{width:n,height:c}=o.data;setTimeout(()=>{this.emitter.emit(N.Resize,{width:n,height:c})},0)}a&&setTimeout(()=>{var n;this.firstFullSnapshot||(this.firstFullSnapshot=a,this.rebuildFullSnapshot(a),(n=this.iframe.contentWindow)==null||n.scrollTo(a.data.initialOffset))},1),this.service.state.context.events.find(Kr)&&this.mouse.classList.add("touch-device")}get timer(){return this.service.state.context.timer}on(e,s){return this.emitter.on(e,s),this}off(e,s){return this.emitter.off(e,s),this}setConfig(e){Object.keys(e).forEach(s=>{e[s],this.config[s]=e[s]}),this.config.skipInactive||this.backToNormal(),typeof e.speed<"u"&&this.speedService.send({type:"SET_SPEED",payload:{speed:e.speed}}),typeof e.mouseTail<"u"&&(e.mouseTail===!1?this.mouseTail&&(this.mouseTail.style.display="none"):(this.mouseTail||(this.mouseTail=document.createElement("canvas"),this.mouseTail.width=Number.parseFloat(this.iframe.width),this.mouseTail.height=Number.parseFloat(this.iframe.height),this.mouseTail.classList.add("replayer-mouse-tail"),this.wrapper.insertBefore(this.mouseTail,this.iframe)),this.mouseTail.style.display="inherit"))}getMetaData(){const e=this.service.state.context.events[0],s=this.service.state.context.events[this.service.state.context.events.length-1];return{startTime:e.timestamp,endTime:s.timestamp,totalTime:s.timestamp-e.timestamp}}getCurrentTime(){return this.timer.timeOffset+this.getTimeOffset()}getTimeOffset(){const{baselineTime:e,events:s}=this.service.state.context;return e-s[0].timestamp}getMirror(){return this.mirror}play(e=0){var s,r;this.service.state.matches("paused")?this.service.send({type:"PLAY",payload:{timeOffset:e}}):(this.service.send({type:"PAUSE"}),this.service.send({type:"PLAY",payload:{timeOffset:e}})),(r=(s=this.iframe.contentDocument)==null?void 0:s.getElementsByTagName("html")[0])==null||r.classList.remove("@sailfish-rrweb/rrweb-paused"),this.emitter.emit(N.Start)}pause(e){var s,r;e===void 0&&this.service.state.matches("playing")&&this.service.send({type:"PAUSE"}),typeof e=="number"&&(this.play(e),this.service.send({type:"PAUSE"})),(r=(s=this.iframe.contentDocument)==null?void 0:s.getElementsByTagName("html")[0])==null||r.classList.add("@sailfish-rrweb/rrweb-paused"),this.emitter.emit(N.Pause)}resume(e=0){this.warn("The 'resume' was deprecated in 1.0. Please use 'play' method which has the same interface."),this.play(e),this.emitter.emit(N.Resume)}destroy(){this.pause(),this.mirror.reset(),this.styleMirror.reset(),this.mediaManager.reset(),this.textValueMap.clear(),this.config.root.removeChild(this.wrapper),this.emitter.emit(N.Destroy)}startLive(e){this.service.send({type:"TO_LIVE",payload:{baselineTime:e}})}addEvent(e){const s=this.config.unpackFn?this.config.unpackFn(e):e;Kr(s)&&this.mouse.classList.add("touch-device"),Promise.resolve().then(()=>this.service.send({type:"ADD_EVENT",payload:{event:s}}))}enableInteract(){this.iframe.setAttribute("scrolling","auto"),this.iframe.style.pointerEvents="auto"}disableInteract(){this.iframe.setAttribute("scrolling","no"),this.iframe.style.pointerEvents="none"}resetCache(){this.cache=br()}setupDom(){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.config.mouseTail!==!1&&(this.mouseTail=document.createElement("canvas"),this.mouseTail.classList.add("replayer-mouse-tail"),this.mouseTail.style.display="inherit",this.wrapper.appendChild(this.mouseTail)),this.iframe=document.createElement("iframe");const e=["allow-same-origin"];this.config.UNSAFE_replayCanvas&&e.push("allow-scripts"),this.iframe.style.display="none",this.iframe.setAttribute("sandbox",e.join(" ")),this.disableInteract(),this.wrapper.appendChild(this.iframe),this.iframe.contentWindow&&this.iframe.contentDocument&&(Rh(this.iframe.contentWindow,this.iframe.contentDocument),Ha(this.iframe.contentWindow))}rebuildFullSnapshot(e,s=!1){if(!this.iframe.contentDocument)return this.warn("Looks like your replayer has been destroyed.");Object.keys(this.legacy_missingNodeRetryMap).length&&this.warn("Found unresolved missing node map",this.legacy_missingNodeRetryMap),this.legacy_missingNodeRetryMap={};const r=[],i=(n,c)=>{if(this.collectIframeAndAttachDocument(r,n),this.mediaManager.isSupportedMediaElement(n)){const{events:l}=this.service.state.context;this.mediaManager.addMediaElements(n,e.timestamp-l[0].timestamp,this.mirror)}for(const l of this.config.plugins||[])l.onBuild&&l.onBuild(n,{id:c,replayer:this})};this.usingVirtualDom&&(this.virtualDom.destroyTree(),this.usingVirtualDom=!1),this.mirror.reset(),this.textValueMap.clear(),Za(e.data.node,{doc:this.iframe.contentDocument,afterAppend:i,cache:this.cache,mirror:this.mirror}),i(this.iframe.contentDocument,e.data.node.id);for(const{mutationInQueue:n,builtNode:c}of r)this.attachDocumentToIframe(n,c),this.newDocumentQueue=this.newDocumentQueue.filter(l=>l!==n);const{documentElement:o,head:a}=this.iframe.contentDocument;this.insertStyleRules(o,a),this.service.state.matches("playing")||this.iframe.contentDocument.getElementsByTagName("html")[0].classList.add("@sailfish-rrweb/rrweb-paused"),this.emitter.emit(N.FullsnapshotRebuilded,e),s||this.waitForStylesheetLoad(),this.config.UNSAFE_replayCanvas&&this.preloadAllImages()}insertStyleRules(e,s){var r;const i=Oh(this.config.blockClass).concat(this.config.insertStyleRules);if(this.config.pauseAnimation&&i.push("html.rrweb-paused *, html.rrweb-paused *:before, html.rrweb-paused *:after { animation-play-state: paused !important; }"),this.usingVirtualDom){const o=this.virtualDom.createElement("style");this.virtualDom.mirror.add(o,Rn(o,this.virtualDom.unserializedId)),e.insertBefore(o,s),o.rules.push({source:T.StyleSheetRule,adds:i.map((a,n)=>({rule:a,index:n}))})}else{const o=document.createElement("style");e.insertBefore(o,s);for(let a=0;a<i.length;a++)(r=o.sheet)==null||r.insertRule(i[a],a)}}attachDocumentToIframe(e,s){const r=this.usingVirtualDom?this.virtualDom.mirror:this.mirror,i=[],o=(a,n)=>{this.collectIframeAndAttachDocument(i,a);const c=r.getMeta(a);if((c==null?void 0:c.type)===R.Element&&(c==null?void 0:c.tagName.toUpperCase())==="HTML"){const{documentElement:l,head:h}=s.contentDocument;this.insertStyleRules(l,h)}if(!this.usingVirtualDom)for(const l of this.config.plugins||[])l.onBuild&&l.onBuild(a,{id:n,replayer:this})};Ee(e.node,{doc:s.contentDocument,mirror:r,hackCss:!0,skipChild:!1,afterAppend:o,cache:this.cache}),o(s.contentDocument,e.node.id);for(const{mutationInQueue:a,builtNode:n}of i)this.attachDocumentToIframe(a,n),this.newDocumentQueue=this.newDocumentQueue.filter(c=>c!==a)}collectIframeAndAttachDocument(e,s){if(Lt(s,this.mirror)){const r=this.newDocumentQueue.find(i=>i.parentId===this.mirror.getId(s));r&&e.push({mutationInQueue:r,builtNode:s})}}waitForStylesheetLoad(){var e;const s=(e=this.iframe.contentDocument)==null?void 0:e.head;if(s){const r=new Set;let i,o=this.service.state;const a=()=>{o=this.service.state};this.emitter.on(N.Start,a),this.emitter.on(N.Pause,a);const n=()=>{this.emitter.off(N.Start,a),this.emitter.off(N.Pause,a)};s.querySelectorAll('link[rel="stylesheet"]').forEach(c=>{c.sheet||(r.add(c),c.addEventListener("load",()=>{r.delete(c),r.size===0&&i!==-1&&(o.matches("playing")&&this.play(this.getCurrentTime()),this.emitter.emit(N.LoadStylesheetEnd),i&&clearTimeout(i),n())}))}),r.size>0&&(this.service.send({type:"PAUSE"}),this.emitter.emit(N.LoadStylesheetStart),i=setTimeout(()=>{o.matches("playing")&&this.play(this.getCurrentTime()),i=-1,n()},this.config.loadTimeout))}}async preloadAllImages(){const e=[];for(const s of this.service.state.context.events)s.type===L.IncrementalSnapshot&&s.data.source===T.CanvasMutation&&(e.push(this.deserializeAndPreloadCanvasEvents(s.data,s)),("commands"in s.data?s.data.commands:[s.data]).forEach(r=>{this.preloadImages(r,s)}));return Promise.all(e)}preloadImages(e,s){if(e.property==="drawImage"&&typeof e.args[0]=="string"&&!this.imageMap.has(s)){const r=document.createElement("canvas"),i=r.getContext("2d"),o=i==null?void 0:i.createImageData(r.width,r.height);i==null||i.putImageData(o,0,0)}}async deserializeAndPreloadCanvasEvents(e,s){if(!this.canvasEventMap.has(s)){const r={isUnchanged:!0};if("commands"in e){const i=await Promise.all(e.commands.map(async o=>{const a=await Promise.all(o.args.map(K(this.imageMap,null,r)));return W(O({},o),{args:a})}));r.isUnchanged===!1&&this.canvasEventMap.set(s,W(O({},e),{commands:i}))}else{const i=await Promise.all(e.args.map(K(this.imageMap,null,r)));r.isUnchanged===!1&&this.canvasEventMap.set(s,W(O({},e),{args:i}))}}}applyIncremental(e,s){var r,i,o;const{data:a}=e;switch(a.source){case T.Mutation:{try{this.applyMutation(a,s)}catch(n){this.warn(`Exception in mutation ${n.message||n}`,a)}break}case T.Drag:case T.TouchMove:case T.MouseMove:if(s){const n=a.positions[a.positions.length-1];this.mousePos={x:n.x,y:n.y,id:n.id,debugData:a}}else a.positions.forEach(n=>{const c={doAction:()=>{this.moveAndHover(n.x,n.y,n.id,s,a)},delay:n.timeOffset+e.timestamp-this.service.state.context.baselineTime};this.timer.addAction(c)}),this.timer.addAction({doAction(){},delay:e.delay-((r=a.positions[0])==null?void 0:r.timeOffset)});break;case T.MouseInteraction:{if(a.id===-1)break;const n=new Event($n(_[a.type])),c=this.mirror.getNode(a.id);if(!c)return this.debugNodeNotFound(a,a.id);this.emitter.emit(N.MouseInteraction,{type:a.type,target:c});const{triggerFocus:l}=this.config;switch(a.type){case _.Blur:"blur"in c&&c.blur();break;case _.Focus:l&&c.focus&&c.focus({preventScroll:!0});break;case _.Click:case _.TouchStart:case _.TouchEnd:case _.MouseDown:case _.MouseUp:s?(a.type===_.TouchStart?this.touchActive=!0:a.type===_.TouchEnd&&(this.touchActive=!1),a.type===_.MouseDown?this.lastMouseDownEvent=[c,n]:a.type===_.MouseUp&&(this.lastMouseDownEvent=null),this.mousePos={x:a.x||0,y:a.y||0,id:a.id,debugData:a}):(a.type===_.TouchStart&&(this.tailPositions.length=0),this.moveAndHover(a.x||0,a.y||0,a.id,s,a),a.type===_.Click?(this.mouse.classList.remove("active"),this.mouse.offsetWidth,this.mouse.classList.add("active")):a.type===_.TouchStart?(this.mouse.offsetWidth,this.mouse.classList.add("touch-active")):a.type===_.TouchEnd?this.mouse.classList.remove("touch-active"):c.dispatchEvent(n));break;case _.TouchCancel:s?this.touchActive=!1:this.mouse.classList.remove("touch-active");break;default:c.dispatchEvent(n)}break}case T.Scroll:{if(a.id===-1)break;if(this.usingVirtualDom){const n=this.virtualDom.mirror.getNode(a.id);if(!n)return this.debugNodeNotFound(a,a.id);n.scrollData=a;break}this.applyScroll(a,s);break}case T.ViewportResize:this.emitter.emit(N.Resize,{width:a.width,height:a.height});break;case T.Input:{if(a.id===-1)break;if(this.usingVirtualDom){const n=this.virtualDom.mirror.getNode(a.id);if(!n)return this.debugNodeNotFound(a,a.id);n.inputData=a;break}this.applyInput(a);break}case T.MediaInteraction:{const n=this.usingVirtualDom?this.virtualDom.mirror.getNode(a.id):this.mirror.getNode(a.id);if(!n)return this.debugNodeNotFound(a,a.id);const c=n,{events:l}=this.service.state.context;this.mediaManager.mediaMutation({target:c,timeOffset:e.timestamp-l[0].timestamp,mutation:a});break}case T.StyleSheetRule:case T.StyleDeclaration:{this.usingVirtualDom?a.styleId?this.constructedStyleMutations.push(a):a.id&&((i=this.virtualDom.mirror.getNode(a.id))==null||i.rules.push(a)):this.applyStyleSheetMutation(a);break}case T.CanvasMutation:{if(!this.config.UNSAFE_replayCanvas)return;if(this.usingVirtualDom){const n=this.virtualDom.mirror.getNode(a.id);if(!n)return this.debugNodeNotFound(a,a.id);n.canvasMutations.push({event:e,mutation:a})}else{const n=this.mirror.getNode(a.id);if(!n)return this.debugNodeNotFound(a,a.id);Yr({event:e,mutation:a,target:n,imageMap:this.imageMap,canvasEventMap:this.canvasEventMap,errorHandler:this.warnCanvasMutationFailed.bind(this)})}break}case T.Font:{try{const n=new FontFace(a.family,a.buffer?new Uint8Array(JSON.parse(a.fontSource)):a.fontSource,a.descriptors);(o=this.iframe.contentDocument)==null||o.fonts.add(n)}catch(n){this.warn(n)}break}case T.Selection:{if(s){this.lastSelectionData=a;break}this.applySelection(a);break}case T.AdoptedStyleSheet:{this.usingVirtualDom?this.adoptedStyleSheets.push(a):this.applyAdoptedStyleSheet(a);break}}}applyMutation(e,s){if(this.config.useVirtualDom&&!this.usingVirtualDom&&s&&(this.usingVirtualDom=!0,gh(this.iframe.contentDocument,this.mirror,this.virtualDom),Object.keys(this.legacy_missingNodeRetryMap).length))for(const l in this.legacy_missingNodeRetryMap)try{const h=this.legacy_missingNodeRetryMap[l],u=Dn(h.node,this.virtualDom,this.mirror);u&&(h.node=u)}catch(h){this.warn(h)}const r=this.usingVirtualDom?this.virtualDom.mirror:this.mirror;e.removes.filter(l=>r.getNode(l.id)?!0:(this.warnNodeNotFound(e,l.id),!1)).forEach(l=>{var h;const u=r.getNode(l.id);if(!u)return;let p=r.getNode(l.parentId);if(!p)return this.warnNodeNotFound(e,l.parentId);if(l.isShadow&&Xe(p)&&(p=p.shadowRoot),r.removeNodeFromMap(u),p)try{p.removeChild(u),this.usingVirtualDom&&u.nodeName==="#text"&&p.nodeName==="STYLE"&&((h=p.rules)==null?void 0:h.length)>0&&(p.rules=[])}catch(m){if(m instanceof DOMException)this.warn("parent could not remove child in mutation",p,u,e);else throw m}});const i=O({},this.legacy_missingNodeRetryMap),o=[],a=l=>{let h=null;return l.nextId&&(h=r.getNode(l.nextId)),l.nextId!==null&&l.nextId!==void 0&&l.nextId!==-1&&!h},n=l=>{var h,u;if(!this.iframe.contentDocument)return this.warn("Looks like your replayer has been destroyed.");let p=r.getNode(l.parentId);if(!p)return l.node.type===R.Document?this.newDocumentQueue.push(l):o.push(l);l.node.isShadow&&(Xe(p)||p.attachShadow({mode:"open"}),p=p.shadowRoot);let m=null,b=null;if(l.previousId&&(m=r.getNode(l.previousId)),l.nextId&&(b=r.getNode(l.nextId)),a(l))return o.push(l);if(l.node.rootId&&!r.getNode(l.node.rootId))return;const d=l.node.rootId?r.getNode(l.node.rootId):this.usingVirtualDom?this.virtualDom:this.iframe.contentDocument;if(Lt(p,r)){this.attachDocumentToIframe(l,p);return}const S=(g,x)=>{if(!this.usingVirtualDom)for(const P of this.config.plugins||[])P.onBuild&&P.onBuild(g,{id:x,replayer:this})},f=Ee(l.node,{doc:d,mirror:r,skipChild:!0,hackCss:!0,cache:this.cache,afterAppend:S});if(l.previousId===-1||l.nextId===-1){i[l.node.id]={node:f,mutation:l};return}const w=r.getMeta(p);if(w&&w.type===R.Element&&l.node.type===R.Text){const g=Array.isArray(p.childNodes)?p.childNodes:Array.from(p.childNodes);if(w.tagName==="textarea")for(const x of g)x.nodeType===p.TEXT_NODE&&p.removeChild(x);else if(w.tagName==="style"&&g.length===1)for(const x of g)x.nodeType===p.TEXT_NODE&&!r.hasNode(x)&&(f.textContent=x.textContent,p.removeChild(x))}else if((w==null?void 0:w.type)===R.Document){const g=p;l.node.type===R.DocumentType&&((h=g.childNodes[0])==null?void 0:h.nodeType)===Node.DOCUMENT_TYPE_NODE&&g.removeChild(g.childNodes[0]),f.nodeName==="HTML"&&g.documentElement&&g.removeChild(g.documentElement)}if(m&&m.nextSibling&&m.nextSibling.parentNode?p.insertBefore(f,m.nextSibling):b&&b.parentNode?p.contains(b)?p.insertBefore(f,b):p.insertBefore(f,null):p.appendChild(f),S(f,l.node.id),this.usingVirtualDom&&f.nodeName==="#text"&&p.nodeName==="STYLE"&&((u=p.rules)==null?void 0:u.length)>0&&(p.rules=[]),Lt(f,this.mirror)){const g=this.mirror.getId(f),x=this.newDocumentQueue.find(P=>P.parentId===g);x&&(this.attachDocumentToIframe(x,f),this.newDocumentQueue=this.newDocumentQueue.filter(P=>P!==x))}(l.previousId||l.nextId)&&this.legacy_resolveMissingNode(i,p,f,l)};e.adds.forEach(l=>{n(l)});const c=Date.now();for(;o.length;){const l=$a(o);if(o.length=0,Date.now()-c>500){this.warn("Timeout in the loop, please check the resolve tree data:",l);break}for(const h of l)r.getNode(h.value.parentId)?_i(h,u=>{n(u)}):this.debug("Drop resolve tree since there is no parent for the root node.",h)}Object.keys(i).length&&Object.assign(this.legacy_missingNodeRetryMap,i),Ja(e.texts).forEach(l=>{var m;var h;const u=r.getNode(l.id);if(!u)return e.removes.find(b=>b.id===l.id)?void 0:this.warnNodeNotFound(e,l.id);let p;if(l.delta){const b=this.textValueMap.get(l.id)||"";p=Ka(b,l.delta)}else p=(m=l.value)!=null?m:null;if(u.textContent=p,p!==null&&this.textValueMap.set(l.id,p),this.usingVirtualDom){const b=u.parentNode;((h=b==null?void 0:b.rules)==null?void 0:h.length)>0&&(b.rules=[])}}),e.attributes.forEach(l=>{var h;const u=r.getNode(l.id);if(!u)return e.removes.find(p=>p.id===l.id)?void 0:this.warnNodeNotFound(e,l.id);for(const p in l.attributes)if(typeof p=="string"){const m=l.attributes[p];if(m===null)u.removeAttribute(p);else if(typeof m=="string")try{if(p==="_cssText"&&(u.nodeName==="LINK"||u.nodeName==="STYLE"))try{const b=r.getMeta(u);Object.assign(b.attributes,l.attributes);const d=Ee(b,{doc:u.ownerDocument,mirror:r,skipChild:!0,hackCss:!0,cache:this.cache}),S=u.nextSibling,f=u.parentNode;if(d&&f){f.removeChild(u),f.insertBefore(d,S),r.replace(l.id,d);break}}catch(b){}if(p==="value"&&u.nodeName==="TEXTAREA"){const b=u;b.childNodes.forEach(S=>b.removeChild(S));const d=(h=u.ownerDocument)==null?void 0:h.createTextNode(m);d&&b.appendChild(d)}else u.setAttribute(p,m)}catch(b){this.warn("An error occurred may due to the checkout feature.",b)}else if(p==="style"){const b=m,d=u;for(const S in b)if(b[S]===!1)d.style.removeProperty(S);else if(b[S]instanceof Array){const f=b[S];d.style.setProperty(S,f[0],f[1])}else{const f=b[S];d.style.setProperty(S,f)}}}})}applyScroll(e,s){var r,i;const o=this.mirror.getNode(e.id);if(!o)return this.debugNodeNotFound(e,e.id);const a=this.mirror.getMeta(o);if(o===this.iframe.contentDocument)(r=this.iframe.contentWindow)==null||r.scrollTo({top:e.y,left:e.x,behavior:s?"auto":"smooth"});else if((a==null?void 0:a.type)===R.Document)(i=o.defaultView)==null||i.scrollTo({top:e.y,left:e.x,behavior:s?"auto":"smooth"});else try{o.scrollTo({top:e.y,left:e.x,behavior:s?"auto":"smooth"})}catch(n){}}applyInput(e){const s=this.mirror.getNode(e.id);if(!s)return this.debugNodeNotFound(e,e.id);try{s.checked=e.isChecked,s.value=e.text}catch(r){}}applySelection(e){try{const s=new Set,r=e.ranges.map(({start:i,startOffset:o,end:a,endOffset:n})=>{const c=this.mirror.getNode(i),l=this.mirror.getNode(a);if(!c||!l)return;const h=new Range;h.setStart(c,o),h.setEnd(l,n);const u=c.ownerDocument,p=u==null?void 0:u.getSelection();return p&&s.add(p),{range:h,selection:p}});s.forEach(i=>i.removeAllRanges()),r.forEach(i=>{var o;return i&&((o=i.selection)==null?void 0:o.addRange(i.range))})}catch(s){}}applyStyleSheetMutation(e){var s;let r=null;e.styleId?r=this.styleMirror.getStyle(e.styleId):e.id&&(r=((s=this.mirror.getNode(e.id))==null?void 0:s.sheet)||null),r&&(e.source===T.StyleSheetRule?this.applyStyleSheetRule(e,r):e.source===T.StyleDeclaration&&this.applyStyleDeclaration(e,r))}applyStyleSheetRule(e,s){var r,i,o,a;if((r=e.adds)==null||r.forEach(({rule:n,index:c})=>{try{if(Array.isArray(c)){const{positions:l,index:h}=Sr(c);xe(s.cssRules,l).insertRule(n,h)}else{const l=c===void 0?void 0:Math.min(c,s.cssRules.length);s==null||s.insertRule(n,l)}}catch(l){}}),(i=e.removes)==null||i.forEach(({index:n})=>{try{if(Array.isArray(n)){const{positions:c,index:l}=Sr(n);xe(s.cssRules,c).deleteRule(l||0)}else s==null||s.deleteRule(n)}catch(c){}}),e.replace)try{(o=s.replace)==null||o.call(s,e.replace)}catch(n){}if(e.replaceSync)try{(a=s.replaceSync)==null||a.call(s,e.replaceSync)}catch(n){}}applyStyleDeclaration(e,s){e.set&&xe(s.rules,e.index).style.setProperty(e.set.property,e.set.value,e.set.priority),e.remove&&xe(s.rules,e.index).style.removeProperty(e.remove.property)}applyAdoptedStyleSheet(e){var s;const r=this.mirror.getNode(e.id);if(!r)return;(s=e.styles)==null||s.forEach(n=>{var c;let l=null,h=null;if(Xe(r)?h=((c=r.ownerDocument)==null?void 0:c.defaultView)||null:r.nodeName==="#document"&&(h=r.defaultView),!!h)try{l=new h.CSSStyleSheet,this.styleMirror.add(l,n.styleId),this.applyStyleSheetRule({source:T.StyleSheetRule,adds:n.rules},l)}catch(u){}});const i=10;let o=0;const a=(n,c)=>{const l=c.map(h=>this.styleMirror.getStyle(h)).filter(h=>h!==null);Xe(n)?n.shadowRoot.adoptedStyleSheets=l:n.nodeName==="#document"&&(n.adoptedStyleSheets=l),l.length!==c.length&&o<i&&(setTimeout(()=>a(n,c),0+100*o),o++)};a(r,e.styleIds)}legacy_resolveMissingNode(e,s,r,i){const{previousId:o,nextId:a}=i,n=o&&e[o],c=a&&e[a];if(n){const{node:l,mutation:h}=n;s.insertBefore(l,r),delete e[h.node.id],delete this.legacy_missingNodeRetryMap[h.node.id],(h.previousId||h.nextId)&&this.legacy_resolveMissingNode(e,s,l,h)}if(c){const{node:l,mutation:h}=c;s.insertBefore(l,r.nextSibling),delete e[h.node.id],delete this.legacy_missingNodeRetryMap[h.node.id],(h.previousId||h.nextId)&&this.legacy_resolveMissingNode(e,s,l,h)}}moveAndHover(e,s,r,i,o){const a=this.mirror.getNode(r);if(!a)return this.debugNodeNotFound(o,r);const n=Ui(a,this.iframe),c=e*n.absoluteScale+n.x,l=s*n.absoluteScale+n.y;this.mouse.style.left=`${c}px`,this.mouse.style.top=`${l}px`,i||this.drawMouseTail({x:c,y:l}),this.hoverElements(a)}drawMouseTail(e){if(!this.mouseTail)return;const{lineCap:s,lineWidth:r,strokeStyle:i,duration:o}=this.config.mouseTail===!0?jt:Object.assign({},jt,this.config.mouseTail),a=()=>{if(!this.mouseTail)return;const n=this.mouseTail.getContext("2d");!n||!this.tailPositions.length||(n.clearRect(0,0,this.mouseTail.width,this.mouseTail.height),n.beginPath(),n.lineWidth=r,n.lineCap=s,n.strokeStyle=i,n.moveTo(this.tailPositions[0].x,this.tailPositions[0].y),this.tailPositions.forEach(c=>n.lineTo(c.x,c.y)),n.stroke())};this.tailPositions.push(e),a(),setTimeout(()=>{this.tailPositions=this.tailPositions.filter(n=>n!==e),a()},o/this.speedService.state.context.timer.speed)}hoverElements(e){var s;(s=this.lastHoveredRootNode||this.iframe.contentDocument)==null||s.querySelectorAll(".\\:hover").forEach(i=>{i.classList.remove(":hover")}),this.lastHoveredRootNode=e.getRootNode();let r=e;for(;r;)r.classList&&r.classList.add(":hover"),r=r.parentElement}isUserInteraction(e){return e.type!==L.IncrementalSnapshot?!1:e.data.source>T.Mutation&&e.data.source<=T.Input}backToNormal(){this.nextUserInteractionEvent=null,!this.speedService.state.matches("normal")&&(this.speedService.send({type:"BACK_TO_NORMAL"}),this.emitter.emit(N.SkipEnd,{speed:this.speedService.state.context.normalSpeed}))}warnNodeNotFound(e,s){this.warn(`Node with id '${s}' not found. `,e)}warnCanvasMutationFailed(e,s){this.warn("Has error on canvas update",s,"canvas mutation:",e)}debugNodeNotFound(e,s){this.debug(`Node with id '${s}' not found. `,e)}warn(...e){this.config.showWarning&&this.config.logger.warn(Qr,...e)}debug(...e){this.config.showDebug&&this.config.logger.log(Qr,...e)}}exports.Replayer=Ph;
|
|
73
73
|
;if (typeof module.exports == "object" && typeof exports == "object") {
|
|
74
74
|
var __cp = (to, from, except, desc) => {
|
|
75
75
|
if ((from && typeof from === "object") || typeof from === "function") {
|