!function(){"use strict";function e(e){return"number"==typeof e?e:"string"==typeof e?e.split(":").reverse().map(parseFloat).reduce(((e,t,n)=>e+t*Math.pow(60,n))):void 0}function t(e){return{name:"string"==typeof e?.name?e.name:"Error",message:"string"==typeof e?.message?e.message:String(e)}}const n=/^#[0-9a-f]{6}$/,r=/^#[0-9a-f]{3}$/;function i(e,t=void 0){if("string"!=typeof e)return t;const i=e.trim().toLowerCase();return n.test(i)?i:r.test(i)?`#${i[1]}${i[1]}${i[2]}${i[2]}${i[3]}${i[3]}`:t}class o{constructor(e,t){this.logger=e,this.prefix=t}log(e,...t){this.logger.log(`${this.prefix}${e}`,...t)}debug(e,...t){this.logger.debug(`${this.prefix}${e}`,...t)}info(e,...t){this.logger.info(`${this.prefix}${e}`,...t)}warn(e,...t){this.logger.warn(`${this.prefix}${e}`,...t)}error(e,...t){this.logger.error(`${this.prefix}${e}`,...t)}}class s{constructor(e=1){this.speed=e,this.startTime=performance.now()}getTime(){return this.speed*(performance.now()-this.startTime)}setTime(e){this.startTime=performance.now()-e/this.speed}}class a{constructor(){}getTime(e){}setTime(e){}}class u{constructor(e,t){this.input="function"==typeof e.next?e:e[Symbol.iterator](),this.xfs=t??[]}map(e){return this.transform(function(e){return t=>n=>{t(e(n))}}(e))}flatMap(e){return this.transform(function(e){return t=>n=>{e(n).forEach(t)}}(e))}filter(e){return this.transform(function(e){return t=>n=>{e(n)&&t(n)}}(e))}take(e){return this.transform(function(e){let t=0;return n=>r=>{tr=>{t+=1,t>e&&n(r)}}(e))}transform(e){return new u(this.input,this.xfs.concat([e]))}multiplex(e,t){return new u(new d(this[Symbol.iterator](),e[Symbol.iterator](),t))}toArray(){return Array.from(this)}[Symbol.iterator](){let e=0,t=[],n=!1;const r=(i=this.xfs,o=e=>t.push(e),i.reverse().reduce(((e,t)=>{const n=c(t(e.step));return{step:n.step,flush:()=>{n.flush(),e.flush()}}}),c(o)));var i,o;return{next:()=>{for(e===t.length&&(t=[],e=0);0===t.length;){const e=this.input.next();if(e.done)break;r.step(e.value)}return 0!==t.length||n||(r.flush(),n=!0),t.length>0?{done:!1,value:t[e++]}:{done:!0}}}}}function c(e){return"function"==typeof e?{step:e,flush:()=>{}}:e}class d{constructor(e,t,n){this.left=e,this.right=t,this.comparator=n}[Symbol.iterator](){let e,t;return{next:()=>{if(void 0===e&&void 0!==this.left){const t=this.left.next();t.done?this.left=void 0:e=t.value}if(void 0===t&&void 0!==this.right){const e=this.right.next();e.done?this.right=void 0:t=e.value}if(void 0===e&&void 0===t)return{done:!0};if(void 0===e){const e=t;return t=void 0,{done:!1,value:e}}if(void 0===t){const t=e;return e=void 0,{done:!1,value:t}}if(this.comparator(e,t)){const t=e;return e=void 0,{done:!1,value:t}}{const e=t;return t=void 0,{done:!1,value:e}}}}}}async function l(e,t){return function(e){const t={start:0},n=e.events.filter((e=>"m"===e[1])).map((e=>[e[0],e[2].label]));return{cols:e.cols,rows:e.rows,theme:e.theme,duration:e.duration,effectiveStartAt:e.effectiveStartAt,markers:n,segments:[t],async loadSegment(t){if(0!==t)throw new Error("unknown recording segment");return{snapshot:{cols:e.cols,rows:e.rows,init:""},events:e.events}}}}(function(e,{startAt:t=0,idleTimeLimit:n,inputOffset:r,markers:i}){let{events:o}=e;o instanceof u||(o=new u(o));t*=1e3,n=n??e.idleTimeLimit,n=void 0!==n?1e3*n:1/0,r=void 0!==r?1e3*r:void 0;const s={offset:0};o=o.map(function(e,t,n){let r=0,i=0;return function(o){const s=o[0]-r-e;return r=o[0],s>0&&(i+=s,o[0]"m"!==e[1])).multiplex(i,((e,t)=>e[0]"i"===e[1]?[e[0]+r,e[1],e[2]]:e)),o.sort(((e,t)=>e[0]-t[0])));if(0===o.length)throw new Error("recording is missing events");const a=o[o.length-1][0],c=t-s.offset;return{...e,events:o,duration:a,effectiveStartAt:c}}(await async function(e){const{parser:t,encoding:n="utf-8"}=e,r=await async function({url:e,data:t,fetchOpts:n={}}){if("string"==typeof e)return await f(e,n);if(Array.isArray(e))return await Promise.all(e.map((e=>f(e,n))));if(void 0!==t){"function"==typeof t&&(t=t()),t instanceof Promise||(t=Promise.resolve(t));const e=await t;return"string"==typeof e||e instanceof ArrayBuffer?new Response(e):e}throw new Error("failed fetching recording file: url/data missing in src")}(e);return await t(r,{encoding:n})}(e),t))}async function f(e,t){const n=await fetch(e,t);if(!n.ok)throw new Error(`failed fetching recording from ${e}: ${n.status} ${n.statusText}`);return n}function m(e){return"number"==typeof e?[1e3*e,"m",""]:[1e3*e[0],"m",e[1]]}function p(e){const t=i(e.foreground),n=i(e.background),r=e.palette;if(void 0===r)return;if(!t||!n||r.length<8)return;const o=[],s=Math.min(r.length,16);for(let e=0;e0)throw new Error(`segmented recordings do not support option: ${r.join(", ")}`)}(e,t),async function(e,{startAt:t=0}){const n=await g(e.url,e.fetchOpts??{});let r;try{r=await n.json()}catch(t){throw new Error(`failed parsing segmented recording index from ${e.url}: ${t.message}`)}!function(e){if(1!==e?.version)throw new Error(`unsupported segmented recording version: ${JSON.stringify(e?.version)}`);if(v(e.duration,"recording duration"),w(e.term,"recording terminal"),!Array.isArray(e.segments)||0===e.segments.length)throw new Error("segmented recording index is missing segments");let t=-1;if(e.segments.forEach(((n,r)=>{if(v(n?.start,`segment ${r} start`),"string"!=typeof n?.url||0===n.url.length)throw new Error(`segment ${r} is missing its URL`);if(0===r&&0!==n.start)throw new Error("first segment must start at 0");if(r>0&&(n.start<=t||n.start>=e.duration))throw new Error(`segment ${r} start must be strictly increasing and before duration`);t=n.start})),void 0!==e.markers&&!Array.isArray(e.markers))throw new Error("segmented recording markers must be an array");let n=-1;for(const[t,r]of(e.markers??[]).entries()){if(!Array.isArray(r)||2!==r.length||"string"!=typeof r[1])throw new Error(`invalid marker ${t} in segmented recording index`);if(v(r[0],`marker ${t} time`),r[0]e.duration)throw new Error(`marker ${t} time is out of order or range`);n=r[0]}}(r);const i=1e3*r.duration,o=(r.markers??[]).map((([e,t])=>[1e3*e,t])),s=r.segments.map((t=>({start:1e3*t.start,url:E(t.url,n.url||e.url)}))),a={cols:r.term.cols,rows:r.term.rows,theme:y(r.term.theme),duration:i,effectiveStartAt:Math.min(Math.max(1e3*t,0),i),markers:o,segments:s,async loadSegment(t){if(!Number.isInteger(t)||t<0||t>=s.length)throw new Error("unknown recording segment");const n=s[t],r=await g(n.url,e.fetchOpts??{});let i;try{i=await r.json()}catch(e){throw new Error(`failed parsing recording segment from ${n.url}: ${e.message}`)}return function(e,t,n){const r=n?.snapshot;if(w(r,`segment ${t} snapshot`),"string"!=typeof r.init)throw new Error(`segment ${t} snapshot init must be a string`);if(!Array.isArray(n.events)||0===n.events.length)throw new Error(`segment ${t} is missing events`);const i=e.segments[t].start,o=e.segments[t+1]?.start??e.duration;let s=-1,a=e.markers.findIndex((([e])=>e>=i));-1===a&&(a=e.markers.length);const u=n.events.map(((n,r)=>{if(!Array.isArray(n)||3!==n.length||"string"!=typeof n[1])throw new Error(`invalid event ${r} in segment ${t}`);const u=1e3*n[0];if(v(u,`event ${r} time in segment ${t}`,!0),u=o:u>o))throw new Error(`event ${r} time is out of range in segment ${t}`);if(s=u,"m"===n[1]){if("string"!=typeof n[2])throw new Error(`marker event ${r} in segment ${t} must have a string label`);return[u,"m",{index:a++,time:u,label:n[2]}]}return[u,n[1],n[2]]}));if(t>0&&u[0][0]!==i)throw new Error(`segment ${t} first event must match its start`);if(t===e.segments.length-1&&u[u.length-1][0]!==e.duration)throw new Error("final segment event must match recording duration");return{snapshot:{cols:r.cols,rows:r.rows,init:r.init},events:u}}(a,t,i)}};return a}(e,t)}async function g(e,t){const n=await fetch(e,t);if(!n.ok)throw new Error(`failed fetching recording from ${e}: ${n.status} ${n.statusText}`);return n}function v(e,t,n=!1){if(!Number.isFinite(e)||e<0)throw new Error(`${t} must be a finite non-negative ${n?"millisecond":"second"} value`)}function w(e,t){if(!Number.isInteger(e?.cols)||e.cols<=0||!Number.isInteger(e?.rows)||e.rows<=0)throw new Error(`${t} must have positive integer cols and rows`)}function y(e){return p({foreground:e?.fg,background:e?.bg,palette:"string"==typeof e?.palette?e.palette.split(":"):void 0})}function E(e,t){return new URL(e,new URL(t,globalThis.location?.href??"http://localhost/")).href}function x(e,t){let n=0,r=e.segments.length;for(;n+1"["===e[0])).map(JSON.parse);return{header:n,events:r}}(t);if(void 0!==n){const{header:e,events:t}=n;if(2===e.version)return k(e,t);if(3===e.version)return S(e,t);throw new Error(`asciicast v${e.version} format not supported`)}{const e=JSON.parse(t);if(1===e.version)return T(e)}}else{if("object"==typeof e&&1===e.version)return T(e);if(Array.isArray(e)){const t=e[0];if(2===t.version){return k(t,e.slice(1,e.length))}if(3===t.version){return S(t,e.slice(1,e.length))}throw new Error(`asciicast v${t.version} format not supported`)}}throw new Error("invalid data")}function T(e){let t=0;const n=new u(e.stdout).map((e=>(t+=1e3*e[0],[t,"o",e[1]])));return{cols:0===e.width?80:e.width,rows:0===e.height?24:e.height,events:n}}function k(e,t){return t instanceof u||(t=new u(t)),t=t.map((e=>[1e3*e[0],e[1],e[2]])),{cols:0===e.width?80:e.width,rows:0===e.height?24:e.height,theme:$(e.theme),events:t,idleTimeLimit:e.idle_time_limit}}function S(e,t){t instanceof u||(t=new u(t));let n=0;return t=t.map((e=>(n+=1e3*e[0],[n,e[1],e[2]]))),{cols:0===e.term.cols?80:e.term.cols,rows:0===e.term.rows?24:e.term.rows,theme:$(e.term?.theme),events:t,idleTimeLimit:e.idle_time_limit}}function $(e){const t="string"==typeof e?.palette?e.palette.split(":"):void 0;return p({foreground:e?.fg,background:e?.bg,palette:t})}function I(e,t,n,r,i,o){const s=function(e){return function(t,n){"o"===t?e("output",n):"i"===t?e("input",{data:n}):"r"===t?e("resize",n):"m"===t&&e("marker",n)}}(t);if(0===e)return o.debug("using no buffer"),function(e){return{pushEvent(t){e(t[1],t[2])},pushText(t){e("o",t)},stop(){}}}(s);{let t;return"number"==typeof(e=e??{})?(o.debug(`using fixed time buffer (${e} ms)`),t=t=>e):"function"==typeof e?(o.debug("using custom dynamic buffer"),t=e({logger:o})):(o.debug("using adaptive buffer",e),t=function({logger:e}={},{minBufferTime:t=50,bufferLevelStep:n=100,maxBufferLevel:r=50,transitionDuration:i=500,peakHalfLifeUp:o=100,peakHalfLifeDown:s=1e4,floorHalfLifeUp:a=5e3,floorHalfLifeDown:u=100,idealHalfLifeUp:c=1e3,idealHalfLifeDown:d=5e3,safetyMultiplier:l=1.2,minImprovementDuration:f=3e3}={}){function m(e){return 0===e?t:n*e}let p=1,h=m(p),g=performance.now(),v=null,w=null,y=null,E=null,x=null,b=null;return function(T){const k=performance.now(),S=Math.max(0,k-g);if(g=k,null===v)v=T;else if(T>v){const e=1-Math.pow(2,-S/o);v+=e*(T-v)}else{const e=1-Math.pow(2,-S/s);v+=e*(T-v)}if(v=Math.max(v,0),null===w)w=T;else if(T>w){const e=1-Math.pow(2,-S/a);w+=e*(T-w)}else{const e=1-Math.pow(2,-S/u);w+=e*(T-w)}w=Math.max(w,0);const $=l*(v+(v-w));if(null===y)y=$;else if($>y){const e=1-Math.pow(2,-S/c);y+=+e*($-y)}else{const e=1-Math.pow(2,-S/d);y+=+e*($-y)}let I;var A,M,L;return y<=t?I=0:(A=Math.ceil(y/n),M=1,L=r,I=Math.min(L,Math.max(M,A))),T>h&&e.debug("buffer underrun",{latency:T,bufferTime:h}),I>p?(T>h?p=Math.min(I,p+3):p+=1,x=m(p),b=(x-h)/i,E=null,e.debug("raising buffer",{latency:T,bufferTime:h,targetBufferTime:x})):I=f&&(p-=1,x=m(p),b=(x-h)/i,E=k,e.debug("lowering buffer",{latency:T,bufferTime:h,targetBufferTime:x}))):E=null,null!==x&&(h+=b*S,(b>=0&&h>x||b<0&&h0){const e=d;return d=[],e}return new Promise((e=>{a=e}))}async function g(){for(;!f;){const e=await h();if(f)return;let t=0;for(;t=s){const t=o-m();if(t>0&&(await(a=t,new Promise((e=>{setTimeout(e,a)}))),f))return e.length;n(i[0]),l=o}var a;return"o"===i[1]?w(e,r):(t(i[1],i[2]),r+1)}function w(e,n){const r=e[n],i=r[0]+s,o=[];let a=r;for(;void 0!==a&&"o"===a[1]&&a[0]0&&(m=t.decode(new Uint8Array(n,e.offset,f))),i=u,{time:s,term:{size:{cols:a,rows:c},theme:l,init:m}}}function u(u){const c=new N(new DataView(u)),d=c.getUint8();return 1===d?a(c,u):111===d?function(e,n){e.decodeVarUint();const i=e.decodeVarUint();r+=i;const o=e.decodeVarUint(),s=t.decode(new Uint8Array(n,e.offset,o));return[r/A,"o",s]}(c,u):105===d?function(e,t){e.decodeVarUint();const i=e.decodeVarUint();r+=i;const o=e.decodeVarUint(),s=n.decode(new Uint8Array(t,e.offset,o));return[r/A,"i",s]}(c,u):114===d?function(e){e.decodeVarUint();const t=e.decodeVarUint();r+=t;const n=e.decodeVarUint(),i=e.decodeVarUint();return[r/A,"r",{cols:n,rows:i}]}(c):109===d?function(e,t){e.decodeVarUint();const n=e.decodeVarUint();r+=n;const i=e.decodeVarUint(),s=new TextDecoder,a=o++,u=r/A,c=r/M,d=s.decode(new Uint8Array(t,e.offset,i));return[u,"m",{index:a,time:c,label:d}]}(c,u):120===d?function(e){e.decodeVarUint();const t=e.decodeVarUint();r+=t;const n=e.decodeVarUint();return[r/A,"x",{status:n}]}(c):4===d?(i=s,!1):void e.debug(`alis: unknown frame type: ${d}`)}return function(e){return i(e)}}function U(e){const t=e.length/3,n=C(e[0],e[1],e[2]),r=C(e[3],e[4],e[5]),i=[];for(let n=2;n127;)n&=127,e+=BigInt(n)<t(e,n,r)}throw new Error(`unsupported driver: ${JSON.stringify(e)}`)}(t),this.driver=null,this.cols=n.cols,this.rows=n.rows,this.speed=n.speed,this.loop=n.loop,this.autoPlay=n.autoPlay,this.idleTimeLimit=n.idleTimeLimit,this.preload=n.preload,this.startAt=e(n.startAt),this.poster=this._parsePoster(n.poster),this.markers=n.markers,this.pauseOnMarkers=n.pauseOnMarkers,this.audioUrl=n.audioUrl,this.initPromise=null,this.commandQueue=Promise.resolve(),this.startupPromise=new Promise((e=>{this.resolveStartup=e})),this.eventHandlers=new Map([["ended",[]],["error",[]],["input",[]],["loading",[]],["marker",[]],["metadata",[]],["muted",[]],["offline",[]],["output",[]],["pause",[]],["play",[]],["playing",[]],["reset",[]],["resize",[]],["ready",[]],["seeked",[]]])}init(){return null===this.initPromise&&(this.initPromise=this._init()),this.initPromise}terminalReady(){this.resolveStartup()}async _init(){await this.startupPromise,this.driver=this.driverFactory({dispatch:this._dispatchEvent.bind(this),logger:this.logger},{cols:this.cols,rows:this.rows,speed:this.speed,idleTimeLimit:this.idleTimeLimit,startAt:this.startAt,preload:this.preload,loop:this.loop,poster:this.autoPlay?void 0:this.poster,markers:this.markers,pauseOnMarkers:this.pauseOnMarkers,audioUrl:this.audioUrl});const e={isPausable:!!this.driver.pause,isSeekable:!!this.driver.seek};this._installDriverDefaults(),this.driver.init&&await this.driver.init(),this.autoPlay&&await this.driver.play(),this._dispatchEvent("ready",e)}_installDriverDefaults(){if(void 0===this.driver.stop&&(this.driver.stop=()=>{}),void 0===this.driver.pause&&(this.driver.pause=()=>{}),void 0===this.driver.seek&&(this.driver.seek=e=>!1),void 0===this.driver.step&&(this.driver.step=e=>{}),void 0===this.driver.mute&&(this.driver.mute=()=>{}),void 0===this.driver.unmute&&(this.driver.unmute=()=>{}),void 0===this.driver.getDuration&&(this.driver.getDuration=()=>{}),void 0===this.driver.getCurrentTime){const e=this.driver.play;let t=new a;this.driver.play=()=>(t=new s(this.speed),e()),this.driver.getCurrentTime=()=>{const e=t.getTime();return"number"==typeof e?e/1e3:e}}}_enqueue(e){const t=async()=>(await this.init(),e.call(this)),n=this.commandQueue.then(t,t);return this.commandQueue=n.catch((()=>{})),n}play(){return this._enqueue((function(){return this.driver.play()}))}pause(){return this._enqueue((function(){return this.driver.pause()}))}seek(e){return this._enqueue((function(){return this.driver.seek(e)}))}step(e){return this._enqueue((function(){return this.driver.step(e)}))}stop(){return this._enqueue((function(){return this.driver.stop()}))}mute(){return this._enqueue((function(){return this.driver.mute()}))}unmute(){return this._enqueue((function(){return this.driver.unmute()}))}getCurrentTime(){return this.driver?this.driver.getCurrentTime():0}getRemainingTime(){const e=this.getDuration();if("number"==typeof e)return e-Math.min(this.getCurrentTime(),e)}getProgress(){const e=this.getDuration();if("number"==typeof e)return Math.min(this.getCurrentTime(),e)/e}getDuration(){if(this.driver)return this.driver.getDuration()}addEventListener(e,t){this.eventHandlers.get(e).push(t)}removeEventListener(e,t){const n=this.eventHandlers.get(e);if(!n)return;const r=n.indexOf(t);-1!==r&&n.splice(r,1)}_dispatchEvent(e,t={}){for(const n of[...this.eventHandlers.get(e)])try{n(t)}catch(t){this.logger.error(`event handler for "${e}" failed`,t),"function"==typeof globalThis.reportError?globalThis.reportError(t):setTimeout((()=>{throw t}),0)}}_parsePoster(t){if("string"==typeof t)return"data:text/plain,"==t.substring(0,16)?{type:"text",value:t.substring(16)}:"npt:"==t.substring(0,4)?{type:"npt",value:e(t.substring(4))}:void 0}}const _=new Map([["benchmark",function({url:e,iterations:t=10},{dispatch:n}){let r,i=0;return{async init(){const t=await b(await fetch(e)),{cols:o,rows:s,events:a}=t;r=Array.from(a).filter((([e,t,n])=>"o"===t)).map((([e,t,n])=>[e,n]));for(const[e,t]of r)i+=new Blob([t]).size;n("reset",{size:{cols:o,rows:s}})},play(){const e=performance.now();for(let e=0;e{n("ended")}),0),!0}}}],["clock",function({hourColor:e=3,minuteColor:t=4,separatorColor:n=9},{dispatch:r},{cols:i=5,rows:o=1}){const s=Math.floor(o/2),a=Math.floor(i/2)-2,u=`[?25l[${s}B`;let c;const d=()=>{(()=>{const r=new Date,i=r.getHours(),o=r.getMinutes(),s=[];s.push("\r");for(let e=0;e{r("output",e)}))};return{init:()=>{r("reset",{size:{cols:i,rows:o}}),r("output",u),d()},play:()=>(void 0!==c||(r("play"),r("playing"),r("output",u),d(),c=setInterval(d,1e3)),!0),stop:()=>{clearInterval(c)},getCurrentTime:()=>{const e=new Date;return 60*e.getHours()+e.getMinutes()}}}],["eventsource",function({url:e,bufferTime:t,minFrameTime:n},{dispatch:r,logger:i}){let u,c;i=new o(i,"eventsource: ");let d=new a;function l(e){void 0!==c&&c.stop(),c=I(t,r,(e=>d.setTime(e)),e,n,i)}return{play:()=>(u||(r("play"),u=new EventSource(e),u.addEventListener("open",(()=>{i.info("opened"),l()})),u.addEventListener("error",(e=>{i.info("errored"),i.debug({e:e}),r("loading")})),u.addEventListener("message",(e=>{const t=JSON.parse(e.data);if(Array.isArray(t))c.pushEvent([1e3*t[0],t[1],t[2]]);else if(void 0!==t.cols||void 0!==t.width){const e=t.cols??t.width,n=t.rows??t.height,o="number"==typeof t.time?1e3*t.time:void 0;i.debug(`vt reset (${e}x${n})`),l(o),r("reset",{size:{cols:e,rows:n},init:t.init??void 0}),d=new s,void 0!==o&&d.setTime(o),r("playing")}else"offline"===t.state&&(i.info("stream offline"),r("offline",{message:"Stream offline"}),d=new a)})),u.addEventListener("done",(()=>{i.info("closed"),u.close(),r("ended",{message:"Stream ended"})}))),!0),stop:()=>{void 0!==c&&c.stop(),void 0!==u&&u.close()},getCurrentTime:()=>{const e=d.getTime();return"number"==typeof e?e/1e3:e}}}],["random",function(e,{dispatch:t},{speed:n}){const r=" ".charCodeAt(0),i="~".charCodeAt(0)-r;let o;const s=()=>{const e=Math.pow(5,4*Math.random());o=setTimeout(a,e/n)},a=()=>{s();const e=String.fromCharCode(r+Math.floor(Math.random()*i));t("output",e)};return{play(){if(void 0!==o)return!0;t("play"),t("playing"),s()},stop(){clearInterval(o)}}}],["recording",function(e,{dispatch:n,logger:r},{speed:i,idleTimeLimit:o,startAt:s,preload:a,loop:u,poster:c,markers:d,pauseOnMarkers:f,cols:m,rows:p,audioUrl:g}){const v="cold",w="loading",y="ready.initial",E="ready.paused",b="ready.starting",T="ready.playing",k="ready.buffering.whilePaused",S="ready.buffering.toResume",$="ready.ended",I="failed",A="stopped",M="initRequested",L="playRequested",U="deferredPlayReady",C="pauseRequested",O="seekRequested",N="stepRequested",D="stopRequested",P="loadSucceeded",R="loadFailed",V="playbackStartConfirmed",G="playbackStartRejected",_="playbackEnded",q="audioWaiting",H="audioPlaying",B="segmentWaiting",z="segmentReady",W="markerReached",F="play",J="seek",j=1e3*(e.minFrameTime??1/60);let Q=()=>performance.now()*i,X=v,K=[],Y=!1;const Z={recording:void 0,segmentIndex:void 0,segment:void 0,segmentCache:new Map,positionGeneration:0,markers:void 0,duration:void 0,effectiveStartAt:void 0,recordingEventTimeoutId:void 0,nextEventIndex:0,lastEventTime:0,startTime:void 0,pauseElapsedTime:void 0,playCount:0,waitingTimeout:void 0,loadingTimeout:void 0,audioCtx:void 0,audioElement:void 0,audioSeekable:!1,loaded:void 0,posterVisible:!1,posterRenderableAfterLoad:void 0!==c,failureError:null,segmentWaiting:!1};function ee(e=X){return e===k||e===S}function te(){return!0===u||"number"==typeof u&&Z.playCount{n("loading")}),3e3);try{const n=function(e,t){if("segmented"===e.format)return h(e,t);return l(e,t)}(e,{idleTimeLimit:o,startAt:s,markers:d,inputOffset:e.inputOffset}),a=async function(e){if(!e)return!1;Z.audioElement=await async function(e){const t=new Audio;let n,r;t.preload="metadata",t.loop=!1,t.crossOrigin="anonymous";const i=new Promise(((e,t)=>{n=e,r=t}));function o(){t.removeEventListener("canplay",s),t.removeEventListener("error",a),t.removeEventListener("abort",u)}function s(){o(),n()}function a(){o(),r(new Error(`failed loading audio from ${e}`))}function u(){o(),r(new Error(`audio loading aborted for ${e}`))}return t.addEventListener("canplay",s),t.addEventListener("error",a),t.addEventListener("abort",u),t.src=e,t.load(),await i,t}(e),Z.audioSeekable=!Number.isNaN(Z.audioElement.duration)&&Z.audioElement.duration!==1/0&&Z.audioElement.seekable.length>0&&Z.audioElement.seekable.end(Z.audioElement.seekable.length-1)===Z.audioElement.duration,Z.audioSeekable?(Z.audioElement.addEventListener("playing",Ne),Z.audioElement.addEventListener("waiting",Oe)):r.warn(`audio is not seekable - you must enable range request support on the server providing ${Z.audioElement.src} for audio seeking to work`);return!0}(g).catch((e=>(r.warn(`audio load failed: ${e.message}`),!1))),u=await n;if(i!==Z.positionGeneration)return!1;Z.recording=u,Z.duration=u.duration,Z.effectiveStartAt=u.effectiveStartAt,Z.markers=u.markers;const f=x(u,t??("npt"===c?.type?1e3*c.value:Z.effectiveStartAt)??0),m=await pe(f,!0);if(i!==Z.positionGeneration)return!1;me(f,m);const p=await a;if(i!==Z.positionGeneration)return!1;ce(P,{hasAudio:p})}catch(e){throw de(R,{error:e}),e}finally{Je()}}(t),Z.loaded.catch((()=>{}))),Z.loaded}function re(e,o,s={}){switch(o){case M:if(e===v){if(a||"npt"==c?.type)return{nextState:w,action:()=>ne()};if("text"==c?.type)return{nextState:e,action:()=>(le(),void(Z.posterRenderableAfterLoad=!1))}}return{nextState:e};case P:return e!==w?{nextState:e}:{nextState:y,action:()=>{n("metadata",{duration:Z.duration/1e3,markers:Z.markers.map((([e,t])=>[e/1e3,t])),hasAudio:s.hasAudio}),_e(Z.segment),le()}};case R:return e!==w?{nextState:e}:{nextState:I,action:()=>{Z.failureError=s.error,n("error",t(s.error))}};case L:return e===v?{nextState:w,action:()=>(fe(),n("play"),ne().then((()=>ce(U))))}:e===y||e===E||e===$?{nextState:b,action:()=>(n("play"),fe(),Be(F))}:e===k?{nextState:S,action:()=>(n("play"),!!Z.segmentWaiting||(!Z.audioElement||Z.audioElement.play().catch((e=>{throw ce(G),e}))))}:e===S||e===T?{nextState:e,action:()=>(n("play"),!0)}:{nextState:e};case U:return e===y?{nextState:b,action:()=>(fe(),Be(F))}:{nextState:e};case V:return e!==b?{nextState:e}:{nextState:T,action:()=>(Ae(),s.reason===J?n("seeked"):n("playing"),!0)};case G:return e===b?{nextState:E}:e===S?{nextState:k}:{nextState:e};case _:return e!==T?{nextState:e}:te()?{nextState:T,action:Qe}:{nextState:$,action:Xe};case q:return e===T?{nextState:S,action:()=>{r.debug("pausing session playback"),$e(),We()}}:e===k||e===S?{nextState:e,action:We}:{nextState:e};case H:return Z.segmentWaiting?{nextState:e}:e===S?{nextState:T,action:()=>{r.debug("resuming session playback"),Fe(),Ae(),n("playing")}}:e===k?{nextState:E,action:()=>{Fe()}}:{nextState:e};case B:return e===T?{nextState:S,action:()=>{var e;Z.segmentWaiting=!0,e=s.time,ke(),Z.pauseElapsedTime=e,We(),Z.audioElement&&Z.audioElement.pause()}}:{nextState:e};case z:return Z.segmentWaiting=!1,e===S?{nextState:e,action:ye}:e===k?{nextState:E,action:Fe}:{nextState:e};case C:return e===T?{nextState:E,action:ze}:e===S?{nextState:k,action:()=>(Z.audioElement&&Z.audioElement.pause(),!0)}:{nextState:e,action:()=>!0};case O:{if(e===v)return{nextState:w,action:()=>ne("number"==typeof s.where?1e3*s.where:void 0).then((()=>Me(s.where)))};if(ee(e)&&!Z.segmentWaiting)return{nextState:e,action:()=>!1};if(e!==y&&e!==E&&e!==$&&e!==T&&e!==k&&e!==S)return{nextState:e};const t=s.seekOperation;return t.noOp?{nextState:e,action:()=>!1}:{nextState:t.reachedEnd?$:e===T||e===S?b:E,action:()=>(fe(),async function(e,t){const r=t===T||t===S,i=++Z.positionGeneration;t===T&&$e();Z.segmentWaiting=!1,Fe(),Z.audioElement&&Z.audioElement.pause();if(!await He(e.targetTime,i))return!1;if(i!==Z.positionGeneration)return!1;if(e.reachedEnd)return n("seeked"),n("ended"),!0;if(r)return await Be(J);return n("seeked"),!0}(t,e))}}case N:return e===v?{nextState:w,action:()=>ne().then((()=>ue(N,s)))}:e===T||ee(e)||e!==y&&e!==E&&e!==$?{nextState:e}:{nextState:e,action:()=>async function(e=1){const t=++Z.positionGeneration,r=await async function(e,t){let n,r=Math.abs(e),i=Z.segmentIndex,o=e>0?Z.nextEventIndex:Z.nextEventIndex-2;for(;i>=0&&i0){for(let e=Math.max(o,0);e=0;e--)if("o"===s.events[e][1]&&0===--r){n={time:s.events[e][0]};break}if(n)break;i--,o=Number.MAX_SAFE_INTEGER}}n&&(n.reachedEnd=n.time>=Z.duration);return n}(e,t);if(void 0===r||t!==Z.positionGeneration)return;if(fe(),!await He(r.time,t,e<0))return;Z.audioElement&&Z.audioSeekable&&(Z.audioElement.currentTime=r.time/1e3/i);r.reachedEnd?(X=$,n("ended")):X=E}(s.n)};case W:return e!==T?{nextState:e}:f?{nextState:E,action:()=>(Pe(s.data),ze(s.time))}:{nextState:e,action:()=>Pe(s.data)};case D:return{nextState:A,action:Ke};default:return{nextState:e}}}function ie(e,t={}){K.push({event:e,payload:t})}function oe(e,t={}){const n=X,{nextState:r,action:i}=re(n,e,t);return r!==X&&(X=r),i?.()}function se(e){Z.failureError||X===A||(K.length=0,Z.segmentWaiting=!1,je(),Z.audioElement&&Z.audioElement.pause(),Z.failureError=e,X=I,n("error",t(e)))}function ae(){if(Z.failureError)throw Z.failureError;if(X===A)throw new Error("driver has been stopped")}function ue(e,t={}){return ae(),ce(e,t)}function ce(e,t={}){if(!Z.failureError&&X!==A){if(Y)throw new Error("re-entrant sendDriverEvent() is not allowed during queue processing");Y=!0;try{const n=oe(e,t);for(;K.length>0;){const e=K.shift();oe(e.event,e.payload)}return n}catch(e){throw se(e),e}finally{Y=!1,K.length=0}}}function de(e,t={}){return Y?(ie(e,t),!0):ce(e,t)}function le(){Z.posterRenderableAfterLoad&&("npt"==c.type?qe(1e3*c.value,!1,!1):"text"==c.type&&De(c.value),Z.posterVisible=!0)}function fe(){Z.posterVisible&&De("c"),Z.posterVisible=!1,Z.posterRenderableAfterLoad=!1}function me(e,t){Z.segmentIndex=e,Z.segment=t,Z.nextEventIndex=0,Z.lastEventTime=Z.recording.segments[e].start}function pe(e,t=!1){let n=Z.segmentCache.get(e);return void 0===n&&(n={},n.promise=Z.recording.loadSegment(e).then((t=>(Z.segmentCache.get(e)===n&&(n.data=t),t)),(i=>{throw Z.segmentCache.get(e)===n&&Z.segmentCache.delete(e),t||r.warn(`segment prefetch failed: ${i.message}`),i})),Z.segmentCache.set(e,n),t||n.promise.catch((()=>{}))),n.promise}async function he(e,t,n){void 0===Z.segmentCache.get(e)?.data&&n?.();try{return await pe(e,!0)}catch(e){throw t===Z.positionGeneration&&X!==A&&se(e),e}}function ge(e){const t=new Set(e.filter((e=>e>=0)));for(const e of Z.segmentCache.keys())t.has(e)||Z.segmentCache.delete(e)}function ve(){const e=Z.recording.segments.length-1,t=Z.segmentIndex{ce(B,{time:t})}));if(n!==Z.positionGeneration||X===A)return;me(e,r),ve(),X===S||X===k?await ce(z):X===T&&Ee()}catch{}}function ye(){if(Fe(),Z.audioElement)return Z.audioElement.play().then((()=>ce(H)),(e=>(ce(G),r.warn(`audio resume failed: ${e.message}`),!1)));ie(H)}function Ee(){const e=Z.segment.events[Z.nextEventIndex];if(e)Z.recordingEventTimeoutId=xe(be,e[0]);else if(Z.segmentIndexNumber.parseInt(e,10)));n("resize",Ge(e,t))}else if("m"===r)return!0===ce(W,{data:i,time:t});return!1}function $e(){ke(),Z.pauseElapsedTime=Q()-Z.startTime}function Ie(){Z.audioElement&&!Z.audioCtx&&function(){Z.audioCtx=new AudioContext({latencyHint:"interactive"});const e=Z.audioCtx.createMediaElementSource(Z.audioElement);e.connect(Z.audioCtx.destination),Q=Ce}()}function Ae(){Z.startTime=Q()-Z.pauseElapsedTime,Z.pauseElapsedTime=null,Ee()}function Me(e){return ae(),function(e){if("number"==typeof e){if(Number.isFinite(e))return}else if("string"==typeof e){if(function(e){return"<<"===e||">>"===e||"<<<"===e||">>>"===e}(e)||void 0!==Re(e))return}else if("object"==typeof e&&null!==e&&("prev"===e.marker||"next"===e.marker||Number.isInteger(e.marker)&&e.marker>=0))return;throw new Error(`invalid seek target: ${JSON.stringify(e)}`)}(e),ce(O,X===v?{where:e}:{seekOperation:Ve(X,e)})}function Le(e){if(0==Z.markers.length)return;let t,n=0,r=Z.markers[n];for(;r&&r[0]>"===i?i=n+5e3:"<<<"===i?i=n-.1*Z.duration:">>>"===i?i=n+.1*Z.duration:"%"===i[i.length-1]&&(i=Re(i)/100*Z.duration);else if("object"==typeof i)if("prev"===i.marker)i=Le(n)??0,r&&n-i<1e3&&(i=Le(i)??0);else if("next"===i.marker)i=function(e){if(0==Z.markers.length)return;let t,n=Z.markers.length-1,r=Z.markers[n];for(;r&&r[0]>e;)t=r[0],r=Z.markers[--n];return t}(n)??Z.duration;else if("number"==typeof i.marker){const e=Z.markers[i.marker];if(void 0===e)throw new Error(`invalid marker index: ${i.marker}`);i=e[0]}const o=Math.min(Math.max(i,0),Z.duration);return{targetTime:o,reachedEnd:o>=Z.duration,noOp:o===Z.pauseElapsedTime}}function Ge(e,t){return{cols:m??e,rows:p??t}}function _e(e,t=!1){t&&De("c"),n("reset",{size:Ge(e.snapshot.cols,e.snapshot.rows),init:e.snapshot.init,theme:Z.recording.theme??null})}function qe(e,t=!0,n=!0){let r=Z.segment.events[Z.nextEventIndex],o=[];for(;r&&(n?r[0]<=e:r[0]0&&(De(o),o=[]),Se(r)),Z.lastEventTime=r[0],r=Z.segment.events[++Z.nextEventIndex];o.length>0&&De(o),Z.pauseElapsedTime=e,t&&(Z.effectiveStartAt=null),Z.audioElement&&Z.audioSeekable&&(Z.audioElement.currentTime=e/1e3/i)}async function He(e,t,n=!1){const r=x(Z.recording,e);if(t!==Z.positionGeneration)return!1;if(!n&&r===Z.segmentIndex&&e>=Z.lastEventTime)return qe(e),!0;ge([r-1,r,r+1]);const i=await he(r,t);return t===Z.positionGeneration&&(me(r,i),_e(i,!0),qe(e),!0)}async function Be(e){const t=Z.positionGeneration;if(Z.segmentIndex===Z.recording.segments.length-1&&void 0===Z.segment.events[Z.nextEventIndex]){if(!await He(0,t,!0))return!1}else if(null!==Z.effectiveStartAt&&!await He(Z.effectiveStartAt,t))return!1;if(t!==Z.positionGeneration)return!1;if(ve(),Ie(),Z.audioElement)try{return await Z.audioElement.play(),ce(V,{reason:e})}catch(e){throw ce(G),e}return de(V,{reason:e})}function ze(e){return Z.audioElement&&Z.audioElement.pause(),$e(),void 0!==e&&(Z.pauseElapsedTime=e),n("pause"),!0}function We(){clearTimeout(Z.waitingTimeout),Z.waitingTimeout=setTimeout((()=>{n("loading")}),1e3)}function Fe(){clearTimeout(Z.waitingTimeout),Z.waitingTimeout=null}function Je(){clearTimeout(Z.loadingTimeout),Z.loadingTimeout=null}function je(){Je(),Fe(),ke()}async function Qe(){ke(),Z.playCount++;const e=++Z.positionGeneration;try{const t=await he(0,e,(()=>{ie(B,{time:Z.duration})}));if(e!==Z.positionGeneration)return;me(0,t),_e(t,!0),Z.pauseElapsedTime=0,Z.startTime=Q(),ve(),Z.audioElement&&Z.audioSeekable&&(Z.audioElement.currentTime=0),X===S||X===k?await ce(z):(Z.pauseElapsedTime=null,Ee())}catch{}}function Xe(){ke(),Z.playCount++,Z.pauseElapsedTime=Z.duration,Z.audioElement&&Z.audioElement.pause(),ge([Z.segmentIndex-1,Z.segmentIndex]),n("ended")}function Ke(){return Z.positionGeneration++,Z.segmentCache.clear(),je(),async function(){clearTimeout(Z.waitingTimeout),Z.audioElement&&(Z.audioElement.removeEventListener("playing",Ne),Z.audioElement.removeEventListener("waiting",Oe),Z.audioElement.pause(),Z.audioElement.src="",Z.audioElement.load(),Z.audioElement=void 0),Z.audioCtx&&(await Z.audioCtx.close(),Z.audioCtx=void 0)}()}return{init:function(){return ue(M)},stop:function(){return ue(D)},getDuration:function(){return void 0===Z.duration?void 0:Z.duration/1e3},getCurrentTime:function(){return Ue()/1e3},play:function(){return ue(L)},pause:function(){return ue(C)},seek:Me,step:function(e){return ue(N,{n:e})},mute:function(){if(Z.audioElement)return Z.audioElement.muted=!0,n("muted",!0),!0},unmute:function(){if(Z.audioElement)return Z.audioElement.muted=!1,n("muted",!1),!0}}}],["websocket",function({url:e,bufferTime:t,reconnectDelay:n=P,minFrameTime:r},{dispatch:i,logger:u},{audioUrl:c}){let d,l;u=new o(u,"websocket: ");let f,m,h,g=new a,v=0,w=!1,y=!1,E=!1,x=!1;function b(){let t;d=new WebSocket(e,["v1.alis","v2.asciicast","v3.asciicast","raw"]),d.binaryType="arraybuffer",d.onopen=()=>{t=d.protocol||"raw",u.info("opened"),u.info(`activating ${t} protocol handler`),"v1.alis"===t?d.onmessage=T(L(u)):"v2.asciicast"===t?d.onmessage=T(function(){let e=function(n){const r=JSON.parse(n);if(2!==r.version)throw new Error("not an asciicast v2 stream");return e=t,{time:0,term:{size:{cols:r.width,rows:r.height}}}};function t(e){const t=JSON.parse(e),n=1e3*t[0];if("r"===t[1]){const[e,r]=t[2].split("x");return[n,"r",{cols:parseInt(e,10),rows:parseInt(r,10)}]}return[n,t[1],t[2]]}return function(t){return e(t)}}()):"v3.asciicast"===t?d.onmessage=T(function(){let e=function(t){const r=JSON.parse(t);if(3!==r.version)throw new Error("not an asciicast v3 stream");e=n;const i={size:{cols:r.term.cols,rows:r.term.rows}};if(r.term.theme){const e="string"==typeof r.term.theme.palette?r.term.theme.palette.split(":"):void 0,t=p({foreground:r.term.theme.fg,background:r.term.theme.bg,palette:e});t&&(i.theme=t)}return{time:0,term:i}},t=0;function n(e){const n=JSON.parse(e),[r,i,o]=n;if(t+=1e3*r,"r"===i){const[e,n]=o.split("x");return[t,"r",{cols:parseInt(e,10),rows:parseInt(n,10)}]}return[t,i,o]}return function(t){return e(t)}}()):"raw"===t&&(d.onmessage=T(D())),f=setTimeout((()=>{v=0}),1e3)},d.onclose=e=>{if(clearTimeout(m),$(),w)return;let r=!1,o="Stream ended";if("v1.alis"===t?(x||e.code>=4e3&&e.code<=4100)&&(r=!0,o=e.reason||o):(E||1e3===e.code||1005===e.code)&&(r=!0),r)u.info("closed"),i("ended",{message:o});else if(1002===e.code)u.debug(`close reason: ${e.reason}`),i("ended",{message:"Err: Player not compatible with the server"});else{clearTimeout(f);const e=n(v++);u.info(`unexpected close, reconnecting in ${e}...`),i("loading"),setTimeout(b,e)}},y=!1}function T(e){return m=setTimeout(S,5e3),function(t){try{const n=e(t.data);if(l)if(Array.isArray(n))l.pushEvent(n),"x"===n[1]&&(E=!0);else if("string"==typeof n)l.pushText(n);else if("object"!=typeof n||Array.isArray(n)){if(!1===n)S(),x=!0;else if(void 0!==n)throw new Error(`unexpected value from protocol handler: ${n}`)}else k(n);else if("object"!=typeof n||Array.isArray(n)){if(void 0!==n)throw clearTimeout(m),new Error(`unexpected value from protocol handler: ${n}`);clearTimeout(m),m=setTimeout(S,1e3)}else k(n),clearTimeout(m)}catch(e){throw d.close(),e}}}function k({time:e,term:n}){const{size:o,init:a,theme:c}=n,{cols:d,rows:f}=o;u.info(`stream reset (${d}x${f} @${e})`),$(),l=I(t,i,(e=>g.setTime(e)),e,r,u),i("reset",{size:{cols:d,rows:f},init:a,theme:c??null}),g=new s,y=!0,E=!1,x=!1,"number"==typeof e&&g.setTime(e),i("playing")}function S(){$(),y?(u.info("stream ended"),i("offline",{message:"Stream ended"})):(u.info("stream offline"),i("offline",{message:"Stream offline"})),g=new a}function $(){l&&l.stop(),l=null}return{init:()=>{i("metadata",{hasAudio:!!c})},play:()=>(d||(i("play"),b(),c&&(h=new Audio,h.preload="auto",h.crossOrigin="anonymous",h.src=c,h.play())),!0),stop:()=>{w=!0,$(),void 0!==d&&d.close(),h&&h.pause()},mute:function(){if(h)return h.muted=!0,!0},unmute:function(){if(h)return h.muted=!1,!0},getCurrentTime:()=>{const e=g.getTime();return"number"==typeof e?e/1e3:e}}}]]),q=new Map([["asciicast",b],["typescript",async function(e,{encoding:t}){const n=new TextDecoder(t);let r,i,o=(await e[0].text()).split("\n").filter((e=>e.length>0)).map((e=>e.split(" ")));o[0].length<3&&(o=o.map((e=>["O",e[0],e[1]])));const s=await e[1].arrayBuffer(),a=new Uint8Array(s),u=a.findIndex((e=>10==e))+1,c=n.decode(a.subarray(0,u)).match(/COLUMNS="(\d+)" LINES="(\d+)"/);null!==c&&(r=parseInt(c[1],10),i=parseInt(c[2],10));const d={array:a,cursor:u};let l=d;if(void 0!==e[2]){const t=await e[2].arrayBuffer();l={array:new Uint8Array(t),cursor:u}}const f=[];let m=0;for(const e of o)if(m+=1e3*parseFloat(e[1]),"O"===e[0]){const t=parseInt(e[2],10),r=d.array.subarray(d.cursor,d.cursor+t),i=n.decode(r);f.push([m,"o",i]),d.cursor+=t}else if("I"===e[0]){const t=parseInt(e[2],10),r=l.array.subarray(l.cursor,l.cursor+t),i=n.decode(r);f.push([m,"i",i]),l.cursor+=t}else if("S"===e[0]&&"SIGWINCH"===e[2]){const t=parseInt(e[4].slice(5),10),n=parseInt(e[3].slice(5),10);f.push([m,"r",`${t}x${n}`])}else"H"===e[0]&&"COLUMNS"===e[2]?r=parseInt(e[3],10):"H"===e[0]&&"LINES"===e[2]&&(i=parseInt(e[3],10));return r=r??80,i=i??24,{cols:r,rows:i,events:f}}],["ttyrec",async function(e,{encoding:t}){const n=new TextDecoder(t),r=await e.arrayBuffer(),i=new Uint8Array(r),o=R(i),s=o.time,a=n.decode(o.data).match(/\x1b\[8;(\d+);(\d+)t/),u=[];let c=80,d=24;null!==a&&(c=parseInt(a[2],10),d=parseInt(a[1],10));let l=0,f=R(i);for(;void 0!==f;){const e=1e3*(f.time-s),t=n.decode(f.data);u.push([e,"o",t]),l+=f.len,f=R(i.subarray(l))}return{cols:c,rows:d,events:u}}]]);let H,B=new class{log(...e){}debug(...e){}info(...e){}warn(...e){}error(...e){}};function z(e,t){switch(e){case"getChanges":return H.getChanges();case"new":const n=t[1];return!0===n.logger&&(B=console),n.logger=B,void(H=new G(t[0],n));case"init":return H.init();case"terminalReady":return H.terminalReady();case"play":return H.play();case"pause":return H.pause();case"stop":return H.stop();case"seek":return H.seek(t);case"step":return H.step(t);case"getCurrentTime":return H.getCurrentTime();case"getRemainingTime":return H.getRemainingTime();case"getProgress":return H.getProgress();case"addEventListener":return void H.addEventListener(t[0],(e=>{postMessage({method:"onEvent",params:{name:t[0],event:e}})}));default:throw new Error(`invalid method ${e}`)}}onmessage=async function(e){if(void 0!==e.data.id)try{const t=await z(e.data.method,e.data.params);postMessage({result:t,id:e.data.id})}catch(n){postMessage({error:t(n),id:e.data.id})}else await z(e.data.method,e.data.params)}}();