var fi=Object.defineProperty;var hi=(a,e,n)=>e in a?fi(a,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):a[e]=n;var $n=(a,e,n)=>(hi(a,typeof e!="symbol"?e+"":e,n),n);import{S as Ee,i as Te,s as de,J as _e,K as be,m as D,h as E,n as g,b as V,G as L,H as Y,L as wt,k as W,y as ce,q as nt,a as we,l as q,z as ke,r as rt,c as xe,A as fe,M as tt,g as P,v as De,d as $,f as Me,B as he,I as xt,o as or,e as ue,N as pi,O as ur,u as Nt,P as cr,Q as di,R as mi,x as Et,T as it,U as sn,V as Pe,W as fr,X as Tt,Y as hr,Z as gi,w as pr,_ as Hn,$ as Fn,a0 as Bn,a1 as _i,a2 as bi,a3 as ki}from"../chunks/index.3641fafa.js";import{w as an,d as vi}from"../chunks/index.fa397836.js";function yi(a){let e,n;return{c(){e=_e("svg"),n=_e("path"),this.h()},l(t){e=be(t,"svg",{stroke:!0,fill:!0,"stroke-width":!0,viewBox:!0,"stroke-linecap":!0,"stroke-linejoin":!0,class:!0,height:!0,width:!0,xmlns:!0});var r=D(e);n=be(r,"path",{d:!0}),D(n).forEach(E),r.forEach(E),this.h()},h(){g(n,"d","M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"),g(e,"stroke","currentColor"),g(e,"fill","none"),g(e,"stroke-width","2"),g(e,"viewBox","0 0 24 24"),g(e,"stroke-linecap","round"),g(e,"stroke-linejoin","round"),g(e,"class","h-4 w-4"),g(e,"height","1em"),g(e,"width","1em"),g(e,"xmlns","http://www.w3.org/2000/svg")},m(t,r){V(t,e,r),L(e,n)},p:Y,i:Y,o:Y,d(t){t&&E(e)}}}class wi extends Ee{constructor(e){super(),Te(this,e,null,yi,de,{})}}function xi(a){let e,n,t;return{c(){e=_e("svg"),n=_e("path"),t=_e("path"),this.h()},l(r){e=be(r,"svg",{stroke:!0,fill:!0,"stroke-width":!0,viewBox:!0,"stroke-linecap":!0,"stroke-linejoin":!0,class:!0,height:!0,width:!0,xmlns:!0});var i=D(e);n=be(i,"path",{d:!0}),D(n).forEach(E),t=be(i,"path",{d:!0}),D(t).forEach(E),i.forEach(E),this.h()},h(){g(n,"d","M12 20h9"),g(t,"d","M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"),g(e,"stroke","currentColor"),g(e,"fill","none"),g(e,"stroke-width","2"),g(e,"viewBox","0 0 24 24"),g(e,"stroke-linecap","round"),g(e,"stroke-linejoin","round"),g(e,"class","h-4 w-4"),g(e,"height","1em"),g(e,"width","1em"),g(e,"xmlns","http://www.w3.org/2000/svg")},m(r,i){V(r,e,i),L(e,n),L(e,t)},p:Y,i:Y,o:Y,d(r){r&&E(e)}}}class Ei extends Ee{constructor(e){super(),Te(this,e,null,xi,de,{})}}function Ti(a){let e,n,t;return{c(){e=_e("svg"),n=_e("line"),t=_e("line"),this.h()},l(r){e=be(r,"svg",{stroke:!0,fill:!0,"stroke-width":!0,viewBox:!0,"stroke-linecap":!0,"stroke-linejoin":!0,class:!0,height:!0,width:!0,xmlns:!0});var i=D(e);n=be(i,"line",{x1:!0,y1:!0,x2:!0,y2:!0}),D(n).forEach(E),t=be(i,"line",{x1:!0,y1:!0,x2:!0,y2:!0}),D(t).forEach(E),i.forEach(E),this.h()},h(){g(n,"x1","12"),g(n,"y1","5"),g(n,"x2","12"),g(n,"y2","19"),g(t,"x1","5"),g(t,"y1","12"),g(t,"x2","19"),g(t,"y2","12"),g(e,"stroke","currentColor"),g(e,"fill","none"),g(e,"stroke-width","2"),g(e,"viewBox","0 0 24 24"),g(e,"stroke-linecap","round"),g(e,"stroke-linejoin","round"),g(e,"class","h-4 w-4"),g(e,"height","1em"),g(e,"width","1em"),g(e,"xmlns","http://www.w3.org/2000/svg")},m(r,i){V(r,e,i),L(e,n),L(e,t)},p:Y,i:Y,o:Y,d(r){r&&E(e)}}}class Ai extends Ee{constructor(e){super(),Te(this,e,null,Ti,de,{})}}function Si(a){let e,n,t,r,i;return{c(){e=_e("svg"),n=_e("polyline"),t=_e("path"),r=_e("line"),i=_e("line"),this.h()},l(l){e=be(l,"svg",{stroke:!0,fill:!0,"stroke-width":!0,viewBox:!0,"stroke-linecap":!0,"stroke-linejoin":!0,class:!0,height:!0,width:!0,xmlns:!0});var s=D(e);n=be(s,"polyline",{points:!0}),D(n).forEach(E),t=be(s,"path",{d:!0}),D(t).forEach(E),r=be(s,"line",{x1:!0,y1:!0,x2:!0,y2:!0}),D(r).forEach(E),i=be(s,"line",{x1:!0,y1:!0,x2:!0,y2:!0}),D(i).forEach(E),s.forEach(E),this.h()},h(){g(n,"points","3 6 5 6 21 6"),g(t,"d","M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"),g(r,"x1","10"),g(r,"y1","11"),g(r,"x2","10"),g(r,"y2","17"),g(i,"x1","14"),g(i,"y1","11"),g(i,"x2","14"),g(i,"y2","17"),g(e,"stroke","currentColor"),g(e,"fill","none"),g(e,"stroke-width","2"),g(e,"viewBox","0 0 24 24"),g(e,"stroke-linecap","round"),g(e,"stroke-linejoin","round"),g(e,"class","h-4 w-4"),g(e,"height","1em"),g(e,"width","1em"),g(e,"xmlns","http://www.w3.org/2000/svg")},m(l,s){V(l,e,s),L(e,n),L(e,t),L(e,r),L(e,i)},p:Y,i:Y,o:Y,d(l){l&&E(e)}}}class Ri extends Ee{constructor(e){super(),Te(this,e,null,Si,de,{})}}var Ii=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},dr={};(function(a){var e=function(n,t){if(!(this instanceof e))return new e(n,t);this.INITIALIZING=-1,this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,this.url=n,t=t||{},this.headers=t.headers||{},this.payload=t.payload!==void 0?t.payload:"",this.method=t.method||this.payload&&"POST"||"GET",this.withCredentials=!!t.withCredentials,this.FIELD_SEPARATOR=":",this.listeners={},this.xhr=null,this.readyState=this.INITIALIZING,this.progress=0,this.chunk="",this.addEventListener=function(r,i){this.listeners[r]===void 0&&(this.listeners[r]=[]),this.listeners[r].indexOf(i)===-1&&this.listeners[r].push(i)},this.removeEventListener=function(r,i){if(this.listeners[r]!==void 0){var l=[];this.listeners[r].forEach(function(s){s!==i&&l.push(s)}),l.length===0?delete this.listeners[r]:this.listeners[r]=l}},this.dispatchEvent=function(r){if(!r)return!0;r.source=this;var i="on"+r.type;return this.hasOwnProperty(i)&&(this[i].call(this,r),r.defaultPrevented)?!1:this.listeners[r.type]?this.listeners[r.type].every(function(l){return l(r),!r.defaultPrevented}):!0},this._setReadyState=function(r){var i=new CustomEvent("readystatechange");i.readyState=r,this.readyState=r,this.dispatchEvent(i)},this._onStreamFailure=function(r){var i=new CustomEvent("error");i.data=r.currentTarget.response,this.dispatchEvent(i),this.close()},this._onStreamAbort=function(r){this.dispatchEvent(new CustomEvent("abort")),this.close()},this._onStreamProgress=function(r){if(this.xhr){if(this.xhr.status!==200){this._onStreamFailure(r);return}this.readyState==this.CONNECTING&&(this.dispatchEvent(new CustomEvent("open")),this._setReadyState(this.OPEN));var i=this.xhr.responseText.substring(this.progress);this.progress+=i.length,i.split(/(\r\n|\r|\n){2}/g).forEach(function(l){l.trim().length===0?(this.dispatchEvent(this._parseEventChunk(this.chunk.trim())),this.chunk=""):this.chunk+=l}.bind(this))}},this._onStreamLoaded=function(r){this._onStreamProgress(r),this.dispatchEvent(this._parseEventChunk(this.chunk)),this.chunk=""},this._parseEventChunk=function(r){if(!r||r.length===0)return null;var i={id:null,retry:null,data:"",event:"message"};r.split(/\n|\r\n|\r/).forEach(function(s){s=s.trimRight();var o=s.indexOf(this.FIELD_SEPARATOR);if(!(o<=0)){var c=s.substring(0,o);if(c in i){var f=s.substring(o+1).trimLeft();c==="data"?i[c]+=f:i[c]=f}}}.bind(this));var l=new CustomEvent(i.event);return l.data=i.data,l.id=i.id,l},this._checkStreamClosed=function(){this.xhr&&this.xhr.readyState===XMLHttpRequest.DONE&&this._setReadyState(this.CLOSED)},this.stream=function(){this._setReadyState(this.CONNECTING),this.xhr=new XMLHttpRequest,this.xhr.addEventListener("progress",this._onStreamProgress.bind(this)),this.xhr.addEventListener("load",this._onStreamLoaded.bind(this)),this.xhr.addEventListener("readystatechange",this._checkStreamClosed.bind(this)),this.xhr.addEventListener("error",this._onStreamFailure.bind(this)),this.xhr.addEventListener("abort",this._onStreamAbort.bind(this)),this.xhr.open(this.method,this.url);for(var r in this.headers)this.xhr.setRequestHeader(r,this.headers[r]);this.xhr.withCredentials=this.withCredentials,this.xhr.send(this.payload)},this.close=function(){this.readyState!==this.CLOSED&&(this.xhr.abort(),this.xhr=null,this._setReadyState(this.CLOSED))}};a.SSE=e})(dr);const{subscribe:Ni,update:Li,...mr}=an({messages:[{role:"assistant",content:"Welcome! Please introduce yourself to your AI competitor."}],chatState:"idle"}),Oi=async a=>{ln(a,"user","loading"),Ci()},Ci=async a=>{const e=new dr.SSE("/api/chat",{headers:{"Content-Type":"application/json"},payload:JSON.stringify({messages:wt(Ue).messages})});e.addEventListener("error",gr),e.addEventListener("message",zi),e.stream()},Di=a=>{mr.set(a)},Mi=()=>mr.set({messages:[{role:"assistant",content:"Welcome! Please introduce yourself to your AI competitor."}],chatState:"idle"}),ln=(a,e,n)=>{Ue.update(t=>({messages:[...t.messages,{role:e,content:a}],chatState:n}))},gr=a=>{ln(a,"system","error"),console.error(a)},zi=a=>{try{if(a.data==="[DONE]")return ln(wt(We),"assistant","idle"),We.set("");wt(We)==="..."&&We.set("");const e=JSON.parse(a.data),[{delta:n}]=e.choices;n.content&&We.update(t=>t+n.content)}catch(e){gr(e)}},Ue={subscribe:Ni,set:Oi,update:Li,reset:Mi,replace:Di},We=an(""),At=an(),rn=a=>localStorage.setItem("chatHistory",JSON.stringify(a)),on=()=>JSON.parse(localStorage.getItem("chatHistory")||"{}"),Pi=vi(Ue,a=>{let e=localStorage.getItem("chatHistory");if(!e&&a.messages.length===1)return null;if(e&&a.messages.length===1)return JSON.parse(e);const n=a.messages[1].content,t=a.messages,r={[n]:t};e||rn(r);const i=on();return i?(i[n]=t,rn(i),At.set(i),i):null}),Ui=a=>{const e=on();delete e[a],rn(e),At.set(e)},$i=a=>on()[a],Gn=a=>{if(wt(Ue).chatState!=="idle"||!a)return;const e=$i(a);Ue.replace({messages:e,chatState:"idle"})};function jn(a,e,n){const t=a.slice();return t[5]=e[n],t}function Wn(a){let e=[],n=new Map,t,r,i=a[0];const l=s=>s[5];for(let s=0;s0&&Wn(a);return{c(){e=W("div"),n=W("button"),ce(t.$$.fragment),r=nt(" New Game"),i=we(),c&&c.c(),this.h()},l(f){e=q(f,"DIV",{class:!0});var h=D(e);n=q(h,"BUTTON",{class:!0});var b=D(n);ke(t.$$.fragment,b),r=rt(b," New Game"),b.forEach(E),i=xe(h),c&&c.l(h),h.forEach(E),this.h()},h(){g(n,"class","flex py-3 px-3 items-center gap-3 rounded-md hover:bg-gray-500/10 transition-colors duration-200 text-white cursor-pointer text-sm mb-2 flex-shrink-0 border border-white/20"),g(e,"class","h-[700px] w-[350px] bg-black bg-opacity-20 rounded-md py-4 px-2 overflow-y-auto flex flex-col gap-2")},m(f,h){V(f,e,h),L(e,n),fe(t,n,null),L(n,r),L(e,i),c&&c.m(e,null),l=!0,s||(o=tt(n,"click",Ue.reset),s=!0)},p(f,[h]){f[0].length>0?c?(c.p(f,h),h&1&&P(c,1)):(c=Wn(f),c.c(),P(c,1),c.m(e,null)):c&&(De(),$(c,1,1,()=>{c=null}),Me())},i(f){l||(P(t.$$.fragment,f),P(c),l=!0)},o(f){$(t.$$.fragment,f),$(c),l=!1},d(f){f&&E(e),he(t),c&&c.d(),s=!1,o()}}}function Fi(a,e,n){let t;xt(a,Pi,o=>n(4,t=o));let r=[];return or(()=>{At.set(t),At.subscribe(o=>{n(0,r=Object.keys(o))})}),[r,o=>Gn(o),o=>Ui(o),o=>Gn(o)]}class Bi extends Ee{constructor(e){super(),Te(this,e,Fi,Hi,de,{})}}const Gi={},ji=()=>mi(Gi);function Wi(a){let e,n,t;const r=[a[0],{__index:a[1]}];var i=a[2][a[0].type];function l(s){let o={};for(let c=0;c{he(f,1)}),Me()}i?(e=Et(i,l()),ce(e.$$.fragment),P(e.$$.fragment,1),fe(e,n.parentNode,n)):e=null}else i&&e.$set(c)},i(s){t||(e&&P(e.$$.fragment,s),t=!0)},o(s){e&&$(e.$$.fragment,s),t=!1},d(s){s&&E(n),e&&he(e,s)}}}function qi(a){let e,n,t;const r=[a[0],{__index:a[1]}];var i=a[2][a[0].tagName];function l(s){let o={};for(let c=0;c{he(f,1)}),Me()}i?(e=Et(i,l()),ce(e.$$.fragment),P(e.$$.fragment,1),fe(e,n.parentNode,n)):e=null}else i&&e.$set(c)},i(s){t||(e&&P(e.$$.fragment,s),t=!0)},o(s){e&&$(e.$$.fragment,s),t=!1},d(s){s&&E(n),e&&he(e,s)}}}function Zi(a){let e,n;const t=[a[0]];let r={};for(let i=0;i{l[f]=null}),Me()),~e?(n=l[e],n?n.p(o,c):(n=l[e]=i[e](o),n.c()),P(n,1),n.m(t.parentNode,t)):n=null)},i(o){r||(P(n),r=!0)},o(o){$(n),r=!1},d(o){~e&&l[e].d(o),o&&E(t)}}}function Xi(a,e,n){let t,{astNode:r}=e,{__index:i=0}=e,{type:l=void 0}=e,{position:s=void 0}=e;const o=ji();return xt(a,o,c=>n(2,t=c)),a.$$set=c=>{"astNode"in c&&n(0,r=c.astNode),"__index"in c&&n(1,i=c.__index),"type"in c&&n(4,l=c.type),"position"in c&&n(5,s=c.position)},[r,i,t,o,l,s]}let Qi=class extends Ee{constructor(e){super(),Te(this,e,Xi,Vi,de,{astNode:0,__index:1,type:4,position:5})}};function Zn(a,e,n){const t=a.slice();return t[4]=e[n],t[1]=n,t}function Vn(a){let e,n;return e=new Qi({props:{astNode:a[4],__index:a[1]}}),{c(){ce(e.$$.fragment)},l(t){ke(e.$$.fragment,t)},m(t,r){fe(e,t,r),n=!0},p(t,r){const i={};r&1&&(i.astNode=t[4]),e.$set(i)},i(t){n||(P(e.$$.fragment,t),n=!0)},o(t){$(e.$$.fragment,t),n=!1},d(t){he(e,t)}}}function Yi(a){let e,n,t=a[0],r=[];for(let l=0;l$(r[l],1,1,()=>{r[l]=null});return{c(){for(let l=0;l{"children"in s&&n(0,t=s.children),"type"in s&&n(2,r=s.type),"position"in s&&n(3,i=s.position),"__index"in s&&n(1,l=s.__index)},[t,l,r,i]}class _r extends Ee{constructor(e){super(),Te(this,e,Ki,Yi,de,{children:0,type:2,position:3,__index:1})}}function Ji(a){let e=a[0],n,t=a[0]&&tn(a);return{c(){t&&t.c(),n=ue()},l(r){t&&t.l(r),n=ue()},m(r,i){t&&t.m(r,i),V(r,n,i)},p(r,i){r[0]?e?de(e,r[0])?(t.d(1),t=tn(r),e=r[0],t.c(),t.m(n.parentNode,n)):t.p(r,i):(t=tn(r),e=r[0],t.c(),t.m(n.parentNode,n)):e&&(t.d(1),t=null,e=r[0])},i:Y,o:Y,d(r){r&&E(n),t&&t.d(r)}}}function es(a){let e=a[0],n,t=a[0]&&nn(a);return{c(){t&&t.c(),n=ue()},l(r){t&&t.l(r),n=ue()},m(r,i){t&&t.m(r,i),V(r,n,i)},p(r,i){r[0]?e?de(e,r[0])?(t.d(1),t=nn(r),e=r[0],t.c(),t.m(n.parentNode,n)):t.p(r,i):(t=nn(r),e=r[0],t.c(),t.m(n.parentNode,n)):e&&(t.d(1),t=null,e=r[0])},i:Y,o(r){$(t)},d(r){r&&E(n),t&&t.d(r)}}}function tn(a){let e,n=[a[2]],t={};for(let r=0;r{s[h]=null}),Me(),t=s[n],t?t.p(c,f):(t=s[n]=l[n](c),t.c()),P(t,1),t.m(r.parentNode,r))},i(c){i||(P(t),i=!0)},o(c){$(t),i=!1},d(c){s[n].d(c),c&&E(r)}}}function ns(a,e,n){let{tagName:t}=e,{children:r}=e,{properties:i}=e,{type:l=void 0}=e,{position:s=void 0}=e,{__index:o=void 0}=e;return a.$$set=c=>{"tagName"in c&&n(0,t=c.tagName),"children"in c&&n(1,r=c.children),"properties"in c&&n(2,i=c.properties),"type"in c&&n(3,l=c.type),"position"in c&&n(4,s=c.position),"__index"in c&&n(5,o=c.__index)},[t,r,i,l,s,o]}class rs extends Ee{constructor(e){super(),Te(this,e,ns,ts,de,{tagName:0,children:1,properties:2,type:3,position:4,__index:5})}}const is=["address","article","aside","footer","header","h1","h2","h3","h4","h5","h6","main","nav","section","blockquote","dd","div","dl","dt","figcaption","figure","hr","li","menu","ol","p","pre","ul","a","abbr","b","bdi","bdo","br","cite","code","data","dfn","em","i","kbd","mark","q","rp","rt","ruby","s","samp","small","span","strong","sub","sup","time","u","var","wbr","area","audio","img","map","track","video","embed","iframe","object","param","picture","portal","source","svg","math","del","ins","caption","col","colgroup","table","tbody","td","tfoot","th","thead","tr","button","datalist","fieldset","form","input","label","legend","meter","optgroup","option","output","progress","select","textarea","details","dialog","summary"],ss=is.reduce((a,e)=>({...a,[e]:rs}),{});function as(a){let e;return{c(){e=nt(a[0])},l(n){e=rt(n,a[0])},m(n,t){V(n,e,t)},p(n,[t]){t&1&&Nt(e,n[0])},i:Y,o:Y,d(n){n&&E(e)}}}function ls(a,e,n){let{value:t=""}=e,{type:r=void 0}=e,{position:i=void 0}=e,{__index:l=void 0}=e;return a.$$set=s=>{"value"in s&&n(0,t=s.value),"type"in s&&n(1,r=s.type),"position"in s&&n(2,i=s.position),"__index"in s&&n(3,l=s.__index)},[t,r,i,l]}class Xn extends Ee{constructor(e){super(),Te(this,e,ls,as,de,{value:0,type:1,position:2,__index:3})}}({...ss});function br(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let qe=br();function os(a){qe=a}const kr=/[&<>"']/,us=new RegExp(kr.source,"g"),vr=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,cs=new RegExp(vr.source,"g"),fs={"&":"&","<":"<",">":">",'"':""","'":"'"},Qn=a=>fs[a];function oe(a,e){if(e){if(kr.test(a))return a.replace(us,Qn)}else if(vr.test(a))return a.replace(cs,Qn);return a}const hs=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function yr(a){return a.replace(hs,(e,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const ps=/(^|[^\[])\^/g;function B(a,e){a=typeof a=="string"?a:a.source,e=e||"";const n={replace:(t,r)=>(r=r.source||r,r=r.replace(ps,"$1"),a=a.replace(t,r),n),getRegex:()=>new RegExp(a,e)};return n}const ds=/[^\w:]/g,ms=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Yn(a,e,n){if(a){let t;try{t=decodeURIComponent(yr(n)).replace(ds,"").toLowerCase()}catch{return null}if(t.indexOf("javascript:")===0||t.indexOf("vbscript:")===0||t.indexOf("data:")===0)return null}e&&!ms.test(n)&&(n=ks(e,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const vt={},gs=/^[^:]+:\/*[^/]*$/,_s=/^([^:]+:)[\s\S]*$/,bs=/^([^:]+:\/*[^/]*)[\s\S]*$/;function ks(a,e){vt[" "+a]||(gs.test(a)?vt[" "+a]=a+"/":vt[" "+a]=yt(a,"/",!0)),a=vt[" "+a];const n=a.indexOf(":")===-1;return e.substring(0,2)==="//"?n?e:a.replace(_s,"$1")+e:e.charAt(0)==="/"?n?e:a.replace(bs,"$1")+e:a+e}const St={exec:function(){}};function Kn(a,e){const n=a.replace(/\|/g,(i,l,s)=>{let o=!1,c=l;for(;--c>=0&&s[c]==="\\";)o=!o;return o?"|":" |"}),t=n.split(/ \|/);let r=0;if(t[0].trim()||t.shift(),t.length>0&&!t[t.length-1].trim()&&t.pop(),t.length>e)t.splice(e);else for(;t.length1;)e&1&&(n+=a),e>>=1,a+=a;return n+a}function er(a,e,n,t){const r=e.href,i=e.title?oe(e.title):null,l=a[1].replace(/\\([\[\]])/g,"$1");if(a[0].charAt(0)!=="!"){t.state.inLink=!0;const s={type:"link",raw:n,href:r,title:i,text:l,tokens:t.inlineTokens(l)};return t.state.inLink=!1,s}return{type:"image",raw:n,href:r,title:i,text:oe(l)}}function ws(a,e){const n=a.match(/^(\s+)(?:```)/);if(n===null)return e;const t=n[1];return e.split(` `).map(r=>{const i=r.match(/^\s+/);if(i===null)return r;const[l]=i;return l.length>=t.length?r.slice(t.length):r}).join(` `)}class un{constructor(e){this.options=e||qe}space(e){const n=this.rules.block.newline.exec(e);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(e){const n=this.rules.block.code.exec(e);if(n){const t=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?t:yt(t,` `)}}}fences(e){const n=this.rules.block.fences.exec(e);if(n){const t=n[0],r=ws(t,n[3]||"");return{type:"code",raw:t,lang:n[2]?n[2].trim().replace(this.rules.inline._escapes,"$1"):n[2],text:r}}}heading(e){const n=this.rules.block.heading.exec(e);if(n){let t=n[2].trim();if(/#$/.test(t)){const r=yt(t,"#");(this.options.pedantic||!r||/ $/.test(r))&&(t=r.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:t,tokens:this.lexer.inline(t)}}}hr(e){const n=this.rules.block.hr.exec(e);if(n)return{type:"hr",raw:n[0]}}blockquote(e){const n=this.rules.block.blockquote.exec(e);if(n){const t=n[0].replace(/^ *>[ \t]?/gm,""),r=this.lexer.state.top;this.lexer.state.top=!0;const i=this.lexer.blockTokens(t);return this.lexer.state.top=r,{type:"blockquote",raw:n[0],tokens:i,text:t}}}list(e){let n=this.rules.block.list.exec(e);if(n){let t,r,i,l,s,o,c,f,h,b,p,M,G=n[1].trim();const j=G.length>1,x={type:"list",raw:"",ordered:j,start:j?+G.slice(0,-1):"",loose:!1,items:[]};G=j?`\\d{1,9}\\${G.slice(-1)}`:`\\${G}`,this.options.pedantic&&(G=j?G:"[*+-]");const O=new RegExp(`^( {0,3}${G})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;e&&(M=!1,!(!(n=O.exec(e))||this.rules.block.hr.test(e)));){if(t=n[0],e=e.substring(t.length),f=n[2].split(` `,1)[0].replace(/^\t+/,R=>" ".repeat(3*R.length)),h=e.split(` `,1)[0],this.options.pedantic?(l=2,p=f.trimLeft()):(l=n[2].search(/[^ ]/),l=l>4?1:l,p=f.slice(l),l+=n[1].length),o=!1,!f&&/^ *$/.test(h)&&(t+=h+` `,e=e.substring(h.length+1),M=!0),!M){const R=new RegExp(`^ {0,${Math.min(3,l-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),K=new RegExp(`^ {0,${Math.min(3,l-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),w=new RegExp(`^ {0,${Math.min(3,l-1)}}(?:\`\`\`|~~~)`),U=new RegExp(`^ {0,${Math.min(3,l-1)}}#`);for(;e&&(b=e.split(` `,1)[0],h=b,this.options.pedantic&&(h=h.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(w.test(h)||U.test(h)||R.test(h)||K.test(e)));){if(h.search(/[^ ]/)>=l||!h.trim())p+=` `+h.slice(l);else{if(o||f.search(/[^ ]/)>=4||w.test(f)||U.test(f)||K.test(f))break;p+=` `+h}!o&&!h.trim()&&(o=!0),t+=b+` `,e=e.substring(b.length+1),f=h.slice(l)}}x.loose||(c?x.loose=!0:/\n *\n *$/.test(t)&&(c=!0)),this.options.gfm&&(r=/^\[[ xX]\] /.exec(p),r&&(i=r[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:t,task:!!r,checked:i,loose:!1,text:p}),x.raw+=t}x.items[x.items.length-1].raw=t.trimRight(),x.items[x.items.length-1].text=p.trimRight(),x.raw=x.raw.trimRight();const X=x.items.length;for(s=0;sw.type==="space"),K=R.length>0&&R.some(w=>/\n.*\n/.test(w.raw));x.loose=K}if(x.loose)for(s=0;s$/,"$1").replace(this.rules.inline._escapes,"$1"):"",i=n[3]?n[3].substring(1,n[3].length-1).replace(this.rules.inline._escapes,"$1"):n[3];return{type:"def",tag:t,raw:n[0],href:r,title:i}}}table(e){const n=this.rules.block.table.exec(e);if(n){const t={type:"table",header:Kn(n[1]).map(r=>({text:r})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(` `):[]};if(t.header.length===t.align.length){t.raw=n[0];let r=t.align.length,i,l,s,o;for(i=0;i({text:c}));for(r=t.header.length,l=0;l/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):oe(n[0]):n[0]}}link(e){const n=this.rules.inline.link.exec(e);if(n){const t=n[2].trim();if(!this.options.pedantic&&/^$/.test(t))return;const l=yt(t.slice(0,-1),"\\");if((t.length-l.length)%2===0)return}else{const l=vs(n[2],"()");if(l>-1){const o=(n[0].indexOf("!")===0?5:4)+n[1].length+l;n[2]=n[2].substring(0,l),n[0]=n[0].substring(0,o).trim(),n[3]=""}}let r=n[2],i="";if(this.options.pedantic){const l=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(r);l&&(r=l[1],i=l[3])}else i=n[3]?n[3].slice(1,-1):"";return r=r.trim(),/^$/.test(t)?r=r.slice(1):r=r.slice(1,-1)),er(n,{href:r&&r.replace(this.rules.inline._escapes,"$1"),title:i&&i.replace(this.rules.inline._escapes,"$1")},n[0],this.lexer)}}reflink(e,n){let t;if((t=this.rules.inline.reflink.exec(e))||(t=this.rules.inline.nolink.exec(e))){let r=(t[2]||t[1]).replace(/\s+/g," ");if(r=n[r.toLowerCase()],!r){const i=t[0].charAt(0);return{type:"text",raw:i,text:i}}return er(t,r,t[0],this.lexer)}}emStrong(e,n,t=""){let r=this.rules.inline.emStrong.lDelim.exec(e);if(!r||r[3]&&t.match(/[\p{L}\p{N}]/u))return;const i=r[1]||r[2]||"";if(!i||i&&(t===""||this.rules.inline.punctuation.exec(t))){const l=r[0].length-1;let s,o,c=l,f=0;const h=r[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(h.lastIndex=0,n=n.slice(-1*e.length+l);(r=h.exec(n))!=null;){if(s=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!s)continue;if(o=s.length,r[3]||r[4]){c+=o;continue}else if((r[5]||r[6])&&l%3&&!((l+o)%3)){f+=o;continue}if(c-=o,c>0)continue;o=Math.min(o,o+c+f);const b=e.slice(0,l+r.index+(r[0].length-s.length)+o);if(Math.min(l,o)%2){const M=b.slice(1,-1);return{type:"em",raw:b,text:M,tokens:this.lexer.inlineTokens(M)}}const p=b.slice(2,-2);return{type:"strong",raw:b,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(e){const n=this.rules.inline.code.exec(e);if(n){let t=n[2].replace(/\n/g," ");const r=/[^ ]/.test(t),i=/^ /.test(t)&&/ $/.test(t);return r&&i&&(t=t.substring(1,t.length-1)),t=oe(t,!0),{type:"codespan",raw:n[0],text:t}}}br(e){const n=this.rules.inline.br.exec(e);if(n)return{type:"br",raw:n[0]}}del(e){const n=this.rules.inline.del.exec(e);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(e,n){const t=this.rules.inline.autolink.exec(e);if(t){let r,i;return t[2]==="@"?(r=oe(this.options.mangle?n(t[1]):t[1]),i="mailto:"+r):(r=oe(t[1]),i=r),{type:"link",raw:t[0],text:r,href:i,tokens:[{type:"text",raw:r,text:r}]}}}url(e,n){let t;if(t=this.rules.inline.url.exec(e)){let r,i;if(t[2]==="@")r=oe(this.options.mangle?n(t[0]):t[0]),i="mailto:"+r;else{let l;do l=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])[0];while(l!==t[0]);r=oe(t[0]),t[1]==="www."?i="http://"+t[0]:i=t[0]}return{type:"link",raw:t[0],text:r,href:i,tokens:[{type:"text",raw:r,text:r}]}}}inlineText(e,n){const t=this.rules.inline.text.exec(e);if(t){let r;return this.lexer.state.inRawBlock?r=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(t[0]):oe(t[0]):t[0]:r=oe(this.options.smartypants?n(t[0]):t[0]),{type:"text",raw:t[0],text:r}}}}const A={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|\\n*|$)|\\n*|$)|)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:St,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};A._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/;A._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;A.def=B(A.def).replace("label",A._label).replace("title",A._title).getRegex();A.bullet=/(?:[*+-]|\d{1,9}[.)])/;A.listItemStart=B(/^( *)(bull) */).replace("bull",A.bullet).getRegex();A.list=B(A.list).replace(/bull/g,A.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+A.def.source+")").getRegex();A._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";A._comment=/|$)/;A.html=B(A.html,"i").replace("comment",A._comment).replace("tag",A._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();A.paragraph=B(A._paragraph).replace("hr",A.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",A._tag).getRegex();A.blockquote=B(A.blockquote).replace("paragraph",A.paragraph).getRegex();A.normal={...A};A.gfm={...A.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"};A.gfm.table=B(A.gfm.table).replace("hr",A.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",A._tag).getRegex();A.gfm.paragraph=B(A._paragraph).replace("hr",A.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",A.gfm.table).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",A._tag).getRegex();A.pedantic={...A.normal,html:B(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",A._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:St,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:B(A.normal._paragraph).replace("hr",A.hr).replace("heading",` *#{1,6} *[^ ]`).replace("lheading",A.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const v={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:St,tag:"^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(ref)\]/,nolink:/^!?\[(ref)\](?:\[\])?/,reflinkSearch:"reflink|nolink(?!\\()",emStrong:{lDelim:/^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,rDelimAst:/^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,rDelimUnd:/^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/},code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:St,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\?@\\[\\]`^{|}~";v.punctuation=B(v.punctuation).replace(/punctuation/g,v._punctuation).getRegex();v.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g;v.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g;v._comment=B(A._comment).replace("(?:-->|$)","-->").getRegex();v.emStrong.lDelim=B(v.emStrong.lDelim).replace(/punct/g,v._punctuation).getRegex();v.emStrong.rDelimAst=B(v.emStrong.rDelimAst,"g").replace(/punct/g,v._punctuation).getRegex();v.emStrong.rDelimUnd=B(v.emStrong.rDelimUnd,"g").replace(/punct/g,v._punctuation).getRegex();v._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;v._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;v._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;v.autolink=B(v.autolink).replace("scheme",v._scheme).replace("email",v._email).getRegex();v._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;v.tag=B(v.tag).replace("comment",v._comment).replace("attribute",v._attribute).getRegex();v._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;v._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/;v._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;v.link=B(v.link).replace("label",v._label).replace("href",v._href).replace("title",v._title).getRegex();v.reflink=B(v.reflink).replace("label",v._label).replace("ref",A._label).getRegex();v.nolink=B(v.nolink).replace("ref",A._label).getRegex();v.reflinkSearch=B(v.reflinkSearch,"g").replace("reflink",v.reflink).replace("nolink",v.nolink).getRegex();v.normal={...v};v.pedantic={...v.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:B(/^!?\[(label)\]\((.*?)\)/).replace("label",v._label).getRegex(),reflink:B(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",v._label).getRegex()};v.gfm={...v.normal,escape:B(v.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\.5&&(t="x"+t.toString(16)),e+="&#"+t+";";return e}class $e{constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||qe,this.options.tokenizer=this.options.tokenizer||new un,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:A.normal,inline:v.normal};this.options.pedantic?(n.block=A.pedantic,n.inline=v.pedantic):this.options.gfm&&(n.block=A.gfm,this.options.breaks?n.inline=v.breaks:n.inline=v.gfm),this.tokenizer.rules=n}static get rules(){return{block:A,inline:v}}static lex(e,n){return new $e(n).lex(e)}static lexInline(e,n){return new $e(n).inlineTokens(e)}lex(e){e=e.replace(/\r\n|\r/g,` `),this.blockTokens(e,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(e,n=[]){this.options.pedantic?e=e.replace(/\t/g," ").replace(/^ +$/gm,""):e=e.replace(/^( *)(\t+)/gm,(s,o,c)=>o+" ".repeat(c.length));let t,r,i,l;for(;e;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(s=>(t=s.call({lexer:this},e,n))?(e=e.substring(t.raw.length),n.push(t),!0):!1))){if(t=this.tokenizer.space(e)){e=e.substring(t.raw.length),t.raw.length===1&&n.length>0?n[n.length-1].raw+=` `:n.push(t);continue}if(t=this.tokenizer.code(e)){e=e.substring(t.raw.length),r=n[n.length-1],r&&(r.type==="paragraph"||r.type==="text")?(r.raw+=` `+t.raw,r.text+=` `+t.text,this.inlineQueue[this.inlineQueue.length-1].src=r.text):n.push(t);continue}if(t=this.tokenizer.fences(e)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.heading(e)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.hr(e)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.blockquote(e)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.list(e)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.html(e)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.def(e)){e=e.substring(t.raw.length),r=n[n.length-1],r&&(r.type==="paragraph"||r.type==="text")?(r.raw+=` `+t.raw,r.text+=` `+t.raw,this.inlineQueue[this.inlineQueue.length-1].src=r.text):this.tokens.links[t.tag]||(this.tokens.links[t.tag]={href:t.href,title:t.title});continue}if(t=this.tokenizer.table(e)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.lheading(e)){e=e.substring(t.raw.length),n.push(t);continue}if(i=e,this.options.extensions&&this.options.extensions.startBlock){let s=1/0;const o=e.slice(1);let c;this.options.extensions.startBlock.forEach(function(f){c=f.call({lexer:this},o),typeof c=="number"&&c>=0&&(s=Math.min(s,c))}),s<1/0&&s>=0&&(i=e.substring(0,s+1))}if(this.state.top&&(t=this.tokenizer.paragraph(i))){r=n[n.length-1],l&&r.type==="paragraph"?(r.raw+=` `+t.raw,r.text+=` `+t.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=r.text):n.push(t),l=i.length!==e.length,e=e.substring(t.raw.length);continue}if(t=this.tokenizer.text(e)){e=e.substring(t.raw.length),r=n[n.length-1],r&&r.type==="text"?(r.raw+=` `+t.raw,r.text+=` `+t.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=r.text):n.push(t);continue}if(e){const s="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(s);break}else throw new Error(s)}}return this.state.top=!0,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}inlineTokens(e,n=[]){let t,r,i,l=e,s,o,c;if(this.tokens.links){const f=Object.keys(this.tokens.links);if(f.length>0)for(;(s=this.tokenizer.rules.inline.reflinkSearch.exec(l))!=null;)f.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(l=l.slice(0,s.index)+"["+Jn("a",s[0].length-2)+"]"+l.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(s=this.tokenizer.rules.inline.blockSkip.exec(l))!=null;)l=l.slice(0,s.index)+"["+Jn("a",s[0].length-2)+"]"+l.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(s=this.tokenizer.rules.inline.escapedEmSt.exec(l))!=null;)l=l.slice(0,s.index+s[0].length-2)+"++"+l.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex),this.tokenizer.rules.inline.escapedEmSt.lastIndex--;for(;e;)if(o||(c=""),o=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(f=>(t=f.call({lexer:this},e,n))?(e=e.substring(t.raw.length),n.push(t),!0):!1))){if(t=this.tokenizer.escape(e)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.tag(e)){e=e.substring(t.raw.length),r=n[n.length-1],r&&t.type==="text"&&r.type==="text"?(r.raw+=t.raw,r.text+=t.text):n.push(t);continue}if(t=this.tokenizer.link(e)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(t.raw.length),r=n[n.length-1],r&&t.type==="text"&&r.type==="text"?(r.raw+=t.raw,r.text+=t.text):n.push(t);continue}if(t=this.tokenizer.emStrong(e,l,c)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.codespan(e)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.br(e)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.del(e)){e=e.substring(t.raw.length),n.push(t);continue}if(t=this.tokenizer.autolink(e,tr)){e=e.substring(t.raw.length),n.push(t);continue}if(!this.state.inLink&&(t=this.tokenizer.url(e,tr))){e=e.substring(t.raw.length),n.push(t);continue}if(i=e,this.options.extensions&&this.options.extensions.startInline){let f=1/0;const h=e.slice(1);let b;this.options.extensions.startInline.forEach(function(p){b=p.call({lexer:this},h),typeof b=="number"&&b>=0&&(f=Math.min(f,b))}),f<1/0&&f>=0&&(i=e.substring(0,f+1))}if(t=this.tokenizer.inlineText(i,xs)){e=e.substring(t.raw.length),t.raw.slice(-1)!=="_"&&(c=t.raw.slice(-1)),o=!0,r=n[n.length-1],r&&r.type==="text"?(r.raw+=t.raw,r.text+=t.text):n.push(t);continue}if(e){const f="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(f);break}else throw new Error(f)}}return n}}class cn{constructor(e){this.options=e||qe}code(e,n,t){const r=(n||"").match(/\S*/)[0];if(this.options.highlight){const i=this.options.highlight(e,r);i!=null&&i!==e&&(t=!0,e=i)}return e=e.replace(/\n$/,"")+` `,r?'
'+(t?e:oe(e,!0))+`
`:"
"+(t?e:oe(e,!0))+`
`}blockquote(e){return`
${e}
`}html(e){return e}heading(e,n,t,r){if(this.options.headerIds){const i=this.options.headerPrefix+r.slug(t);return`${e} `}return`${e} `}hr(){return this.options.xhtml?`
`:`
`}list(e,n,t){const r=n?"ol":"ul",i=n&&t!==1?' start="'+t+'"':"";return"<"+r+i+`> `+e+" `}listitem(e){return`
  • ${e}
  • `}checkbox(e){return" "}paragraph(e){return`

    ${e}

    `}table(e,n){return n&&(n=`${n}`),` `+e+` `+n+`
    `}tablerow(e){return` ${e} `}tablecell(e,n){const t=n.header?"th":"td";return(n.align?`<${t} align="${n.align}">`:`<${t}>`)+e+` `}strong(e){return`${e}`}em(e){return`${e}`}codespan(e){return`${e}`}br(){return this.options.xhtml?"
    ":"
    "}del(e){return`${e}`}link(e,n,t){if(e=Yn(this.options.sanitize,this.options.baseUrl,e),e===null)return t;let r='",r}image(e,n,t){if(e=Yn(this.options.sanitize,this.options.baseUrl,e),e===null)return t;let r=`${t}":">",r}text(e){return e}}class wr{strong(e){return e}em(e){return e}codespan(e){return e}del(e){return e}html(e){return e}text(e){return e}link(e,n,t){return""+t}image(e,n,t){return""+t}br(){return""}}class xr{constructor(){this.seen={}}serialize(e){return e.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(e,n){let t=e,r=0;if(this.seen.hasOwnProperty(t)){r=this.seen[e];do r++,t=e+"-"+r;while(this.seen.hasOwnProperty(t))}return n||(this.seen[e]=r,this.seen[t]=0),t}slug(e,n={}){const t=this.serialize(e);return this.getNextSafeSlug(t,n.dryrun)}}class He{constructor(e){this.options=e||qe,this.options.renderer=this.options.renderer||new cn,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new wr,this.slugger=new xr}static parse(e,n){return new He(n).parse(e)}static parseInline(e,n){return new He(n).parseInline(e)}parse(e,n=!0){let t="",r,i,l,s,o,c,f,h,b,p,M,G,j,x,O,X,R,K,w;const U=e.length;for(r=0;r0&&O.tokens[0].type==="paragraph"?(O.tokens[0].text=K+" "+O.tokens[0].text,O.tokens[0].tokens&&O.tokens[0].tokens.length>0&&O.tokens[0].tokens[0].type==="text"&&(O.tokens[0].tokens[0].text=K+" "+O.tokens[0].tokens[0].text)):O.tokens.unshift({type:"text",text:K}):x+=K),x+=this.parse(O.tokens,j),b+=this.renderer.listitem(x,R,X);t+=this.renderer.list(b,M,G);continue}case"html":{t+=this.renderer.html(p.text);continue}case"paragraph":{t+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(b=p.tokens?this.parseInline(p.tokens):p.text;r+1{if(t.message+=` Please report this to https://github.com/markedjs/marked.`,a){const r="

    An error occurred:

    "+oe(t.message+"",!0)+"
    ";if(e)return Promise.resolve(r);if(n){n(null,r);return}return r}if(e)return Promise.reject(t);if(n){n(t);return}throw t}}function Er(a,e){return(n,t,r)=>{typeof t=="function"&&(r=t,t=null);const i={...t};t={...T.defaults,...i};const l=Es(t.silent,t.async,r);if(typeof n>"u"||n===null)return l(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(ys(t),t.hooks&&(t.hooks.options=t),r){const s=t.highlight;let o;try{t.hooks&&(n=t.hooks.preprocess(n)),o=a(n,t)}catch(h){return l(h)}const c=function(h){let b;if(!h)try{t.walkTokens&&T.walkTokens(o,t.walkTokens),b=e(o,t),t.hooks&&(b=t.hooks.postprocess(b))}catch(p){h=p}return t.highlight=s,h?l(h):r(null,b)};if(!s||s.length<3||(delete t.highlight,!o.length))return c();let f=0;T.walkTokens(o,function(h){h.type==="code"&&(f++,setTimeout(()=>{s(h.text,h.lang,function(b,p){if(b)return c(b);p!=null&&p!==h.text&&(h.text=p,h.escaped=!0),f--,f===0&&c()})},0))}),f===0&&c();return}if(t.async)return Promise.resolve(t.hooks?t.hooks.preprocess(n):n).then(s=>a(s,t)).then(s=>t.walkTokens?Promise.all(T.walkTokens(s,t.walkTokens)).then(()=>s):s).then(s=>e(s,t)).then(s=>t.hooks?t.hooks.postprocess(s):s).catch(l);try{t.hooks&&(n=t.hooks.preprocess(n));const s=a(n,t);t.walkTokens&&T.walkTokens(s,t.walkTokens);let o=e(s,t);return t.hooks&&(o=t.hooks.postprocess(o)),o}catch(s){return l(s)}}}function T(a,e,n){return Er($e.lex,He.parse)(a,e,n)}T.options=T.setOptions=function(a){return T.defaults={...T.defaults,...a},os(T.defaults),T};T.getDefaults=br;T.defaults=qe;T.use=function(...a){const e=T.defaults.extensions||{renderers:{},childTokens:{}};a.forEach(n=>{const t={...n};if(t.async=T.defaults.async||t.async||!1,n.extensions&&(n.extensions.forEach(r=>{if(!r.name)throw new Error("extension name required");if(r.renderer){const i=e.renderers[r.name];i?e.renderers[r.name]=function(...l){let s=r.renderer.apply(this,l);return s===!1&&(s=i.apply(this,l)),s}:e.renderers[r.name]=r.renderer}if(r.tokenizer){if(!r.level||r.level!=="block"&&r.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");e[r.level]?e[r.level].unshift(r.tokenizer):e[r.level]=[r.tokenizer],r.start&&(r.level==="block"?e.startBlock?e.startBlock.push(r.start):e.startBlock=[r.start]:r.level==="inline"&&(e.startInline?e.startInline.push(r.start):e.startInline=[r.start]))}r.childTokens&&(e.childTokens[r.name]=r.childTokens)}),t.extensions=e),n.renderer){const r=T.defaults.renderer||new cn;for(const i in n.renderer){const l=r[i];r[i]=(...s)=>{let o=n.renderer[i].apply(r,s);return o===!1&&(o=l.apply(r,s)),o}}t.renderer=r}if(n.tokenizer){const r=T.defaults.tokenizer||new un;for(const i in n.tokenizer){const l=r[i];r[i]=(...s)=>{let o=n.tokenizer[i].apply(r,s);return o===!1&&(o=l.apply(r,s)),o}}t.tokenizer=r}if(n.hooks){const r=T.defaults.hooks||new Rt;for(const i in n.hooks){const l=r[i];Rt.passThroughHooks.has(i)?r[i]=s=>{if(T.defaults.async)return Promise.resolve(n.hooks[i].call(r,s)).then(c=>l.call(r,c));const o=n.hooks[i].call(r,s);return l.call(r,o)}:r[i]=(...s)=>{let o=n.hooks[i].apply(r,s);return o===!1&&(o=l.apply(r,s)),o}}t.hooks=r}if(n.walkTokens){const r=T.defaults.walkTokens;t.walkTokens=function(i){let l=[];return l.push(n.walkTokens.call(this,i)),r&&(l=l.concat(r.call(this,i))),l}}T.setOptions(t)})};T.walkTokens=function(a,e){let n=[];for(const t of a)switch(n=n.concat(e.call(T,t)),t.type){case"table":{for(const r of t.header)n=n.concat(T.walkTokens(r.tokens,e));for(const r of t.rows)for(const i of r)n=n.concat(T.walkTokens(i.tokens,e));break}case"list":{n=n.concat(T.walkTokens(t.items,e));break}default:T.defaults.extensions&&T.defaults.extensions.childTokens&&T.defaults.extensions.childTokens[t.type]?T.defaults.extensions.childTokens[t.type].forEach(function(r){n=n.concat(T.walkTokens(t[r],e))}):t.tokens&&(n=n.concat(T.walkTokens(t.tokens,e)))}return n};T.parseInline=Er($e.lexInline,He.parseInline);T.Parser=He;T.parser=He.parse;T.Renderer=cn;T.TextRenderer=wr;T.Lexer=$e;T.lexer=$e.lex;T.Tokenizer=un;T.Slugger=xr;T.Hooks=Rt;T.parse=T;T.options;T.setOptions;T.use;T.walkTokens;T.parseInline;He.parse;$e.lex;var It={},Ts={get exports(){return It},set exports(a){It=a}};/*! @license DOMPurify 3.0.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.1/LICENSE */var nr;function rr(){return nr||(nr=1,function(a,e){(function(n,t){a.exports=t()})(Ii,function(){function n(m){return n=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(_){return typeof _}:function(_){return _&&typeof Symbol=="function"&&_.constructor===Symbol&&_!==Symbol.prototype?"symbol":typeof _},n(m)}function t(m,_){return t=Object.setPrototypeOf||function(I,z){return I.__proto__=z,I},t(m,_)}function r(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function i(m,_,y){return r()?i=Reflect.construct:i=function(z,J,se){var ee=[null];ee.push.apply(ee,J);var pe=Function.bind.apply(z,ee),at=new pe;return se&&t(at,se.prototype),at},i.apply(null,arguments)}function l(m,_){return c(m)||h(m,_)||b(m,_)||G()}function s(m){return o(m)||f(m)||b(m)||M()}function o(m){if(Array.isArray(m))return p(m)}function c(m){if(Array.isArray(m))return m}function f(m){if(typeof Symbol<"u"&&m[Symbol.iterator]!=null||m["@@iterator"]!=null)return Array.from(m)}function h(m,_){var y=m==null?null:typeof Symbol<"u"&&m[Symbol.iterator]||m["@@iterator"];if(y!=null){var I=[],z=!0,J=!1,se,ee;try{for(y=y.call(m);!(z=(se=y.next()).done)&&(I.push(se.value),!(_&&I.length===_));z=!0);}catch(pe){J=!0,ee=pe}finally{try{!z&&y.return!=null&&y.return()}finally{if(J)throw ee}}return I}}function b(m,_){if(m){if(typeof m=="string")return p(m,_);var y=Object.prototype.toString.call(m).slice(8,-1);if(y==="Object"&&m.constructor&&(y=m.constructor.name),y==="Map"||y==="Set")return Array.from(m);if(y==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(y))return p(m,_)}}function p(m,_){(_==null||_>m.length)&&(_=m.length);for(var y=0,I=new Array(_);y<_;y++)I[y]=m[y];return I}function M(){throw new TypeError(`Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function G(){throw new TypeError(`Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function j(m,_){var y=typeof Symbol<"u"&&m[Symbol.iterator]||m["@@iterator"];if(!y){if(Array.isArray(m)||(y=b(m))||_&&m&&typeof m.length=="number"){y&&(m=y);var I=0,z=function(){};return{s:z,n:function(){return I>=m.length?{done:!0}:{done:!1,value:m[I++]}},e:function(pe){throw pe},f:z}}throw new TypeError(`Invalid attempt to iterate non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var J=!0,se=!1,ee;return{s:function(){y=y.call(m)},n:function(){var pe=y.next();return J=pe.done,pe},e:function(pe){se=!0,ee=pe},f:function(){try{!J&&y.return!=null&&y.return()}finally{if(se)throw ee}}}}var x=Object.entries,O=Object.setPrototypeOf,X=Object.isFrozen,R=Object.getPrototypeOf,K=Object.getOwnPropertyDescriptor,w=Object.freeze,U=Object.seal,Re=Object.create,N=typeof Reflect<"u"&&Reflect,F=N.apply,ie=N.construct;F||(F=function(_,y,I){return _.apply(y,I)}),w||(w=function(_){return _}),U||(U=function(_){return _}),ie||(ie=function(_,y){return i(_,s(y))});var Z=ve(Array.prototype.forEach),ze=ve(Array.prototype.pop),Ie=ve(Array.prototype.push),Le=ve(String.prototype.toLowerCase),Ze=ve(String.prototype.toString),st=ve(String.prototype.match),Ae=ve(String.prototype.replace),Ar=ve(String.prototype.indexOf),Sr=ve(String.prototype.trim),me=ve(RegExp.prototype.test),Lt=Rr(TypeError);function ve(m){return function(_){for(var y=arguments.length,I=new Array(y>1?y-1:0),z=1;z/gm),Cr=U(/\${[\w\W]*}/gm),Dr=U(/^data-[\-\w.\u00B7-\uFFFF]/),Mr=U(/^aria-[\-\w]+$/),zr=U(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Pr=U(/^(?:\w+script|data):/i),Ur=U(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),$r=U(/^html$/i),Hr=function(){return typeof window>"u"?null:window},Fr=function(_,y){if(n(_)!=="object"||typeof _.createPolicy!="function")return null;var I=null,z="data-tt-policy-suffix";y.currentScript&&y.currentScript.hasAttribute(z)&&(I=y.currentScript.getAttribute(z));var J="dompurify"+(I?"#"+I:"");try{return _.createPolicy(J,{createHTML:function(ee){return ee},createScriptURL:function(ee){return ee}})}catch{return console.warn("TrustedTypes policy "+J+" could not be created."),null}};function mn(){var m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Hr(),_=function(u){return mn(u)};if(_.version="3.0.1",_.removed=[],!m||!m.document||m.document.nodeType!==9)return _.isSupported=!1,_;var y=m.document,I=m.document,z=m.DocumentFragment,J=m.HTMLTemplateElement,se=m.Node,ee=m.Element,pe=m.NodeFilter,at=m.NamedNodeMap,Gr=at===void 0?m.NamedNodeMap||m.MozNamedAttrMap:at,jr=m.HTMLFormElement,Wr=m.DOMParser,ft=m.trustedTypes,ht=ee.prototype,qr=ut(ht,"cloneNode"),Zr=ut(ht,"nextSibling"),Vr=ut(ht,"childNodes"),zt=ut(ht,"parentNode");if(typeof J=="function"){var Pt=I.createElement("template");Pt.content&&Pt.content.ownerDocument&&(I=Pt.content.ownerDocument)}var Se=Fr(ft,y),gn=Se?Se.createHTML(""):"",pt=I,Ut=pt.implementation,Xr=pt.createNodeIterator,Qr=pt.createDocumentFragment,Yr=pt.getElementsByTagName,Kr=y.importNode,Ne={};_.isSupported=typeof x=="function"&&typeof zt=="function"&&Ut&&typeof Ut.createHTMLDocument<"u";var $t=Lr,Ht=Or,Ft=Cr,Jr=Dr,ei=Mr,ti=Pr,_n=Ur,Bt=zr,te=null,bn=C({},[].concat(s(fn),s(Ot),s(Ct),s(Dt),s(hn))),ne=null,kn=C({},[].concat(s(pn),s(Mt),s(dn),s(ct))),Q=Object.seal(Object.create(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),lt=null,Gt=null,vn=!0,jt=!0,yn=!1,wn=!0,Xe=!1,Fe=!1,Wt=!1,qt=!1,Qe=!1,dt=!1,mt=!1,xn=!0,En=!1,ni="user-content-",Zt=!0,ot=!1,Ye={},Ke=null,Tn=C({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),An=null,Sn=C({},["audio","video","img","source","image","track"]),Vt=null,Rn=C({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),gt="http://www.w3.org/1998/Math/MathML",_t="http://www.w3.org/2000/svg",Oe="http://www.w3.org/1999/xhtml",Je=Oe,Xt=!1,Qt=null,ri=C({},[gt,_t,Oe],Ze),Be,ii=["application/xhtml+xml","text/html"],si="text/html",re,et=null,ai=I.createElement("form"),In=function(u){return u instanceof RegExp||u instanceof Function},Yt=function(u){et&&et===u||((!u||n(u)!=="object")&&(u={}),u=Ve(u),Be=ii.indexOf(u.PARSER_MEDIA_TYPE)===-1?Be=si:Be=u.PARSER_MEDIA_TYPE,re=Be==="application/xhtml+xml"?Ze:Le,te="ALLOWED_TAGS"in u?C({},u.ALLOWED_TAGS,re):bn,ne="ALLOWED_ATTR"in u?C({},u.ALLOWED_ATTR,re):kn,Qt="ALLOWED_NAMESPACES"in u?C({},u.ALLOWED_NAMESPACES,Ze):ri,Vt="ADD_URI_SAFE_ATTR"in u?C(Ve(Rn),u.ADD_URI_SAFE_ATTR,re):Rn,An="ADD_DATA_URI_TAGS"in u?C(Ve(Sn),u.ADD_DATA_URI_TAGS,re):Sn,Ke="FORBID_CONTENTS"in u?C({},u.FORBID_CONTENTS,re):Tn,lt="FORBID_TAGS"in u?C({},u.FORBID_TAGS,re):{},Gt="FORBID_ATTR"in u?C({},u.FORBID_ATTR,re):{},Ye="USE_PROFILES"in u?u.USE_PROFILES:!1,vn=u.ALLOW_ARIA_ATTR!==!1,jt=u.ALLOW_DATA_ATTR!==!1,yn=u.ALLOW_UNKNOWN_PROTOCOLS||!1,wn=u.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Xe=u.SAFE_FOR_TEMPLATES||!1,Fe=u.WHOLE_DOCUMENT||!1,Qe=u.RETURN_DOM||!1,dt=u.RETURN_DOM_FRAGMENT||!1,mt=u.RETURN_TRUSTED_TYPE||!1,qt=u.FORCE_BODY||!1,xn=u.SANITIZE_DOM!==!1,En=u.SANITIZE_NAMED_PROPS||!1,Zt=u.KEEP_CONTENT!==!1,ot=u.IN_PLACE||!1,Bt=u.ALLOWED_URI_REGEXP||Bt,Je=u.NAMESPACE||Oe,Q=u.CUSTOM_ELEMENT_HANDLING||{},u.CUSTOM_ELEMENT_HANDLING&&In(u.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Q.tagNameCheck=u.CUSTOM_ELEMENT_HANDLING.tagNameCheck),u.CUSTOM_ELEMENT_HANDLING&&In(u.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Q.attributeNameCheck=u.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),u.CUSTOM_ELEMENT_HANDLING&&typeof u.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(Q.allowCustomizedBuiltInElements=u.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),Xe&&(jt=!1),dt&&(Qe=!0),Ye&&(te=C({},s(hn)),ne=[],Ye.html===!0&&(C(te,fn),C(ne,pn)),Ye.svg===!0&&(C(te,Ot),C(ne,Mt),C(ne,ct)),Ye.svgFilters===!0&&(C(te,Ct),C(ne,Mt),C(ne,ct)),Ye.mathMl===!0&&(C(te,Dt),C(ne,dn),C(ne,ct))),u.ADD_TAGS&&(te===bn&&(te=Ve(te)),C(te,u.ADD_TAGS,re)),u.ADD_ATTR&&(ne===kn&&(ne=Ve(ne)),C(ne,u.ADD_ATTR,re)),u.ADD_URI_SAFE_ATTR&&C(Vt,u.ADD_URI_SAFE_ATTR,re),u.FORBID_CONTENTS&&(Ke===Tn&&(Ke=Ve(Ke)),C(Ke,u.FORBID_CONTENTS,re)),Zt&&(te["#text"]=!0),Fe&&C(te,["html","head","body"]),te.table&&(C(te,["tbody"]),delete lt.tbody),w&&w(u),et=u)},Nn=C({},["mi","mo","mn","ms","mtext"]),Ln=C({},["foreignobject","desc","title","annotation-xml"]),li=C({},["title","style","font","a","script"]),bt=C({},Ot);C(bt,Ct),C(bt,Ir);var Kt=C({},Dt);C(Kt,Nr);var oi=function(u){var d=zt(u);(!d||!d.tagName)&&(d={namespaceURI:Je,tagName:"template"});var k=Le(u.tagName),H=Le(d.tagName);return Qt[u.namespaceURI]?u.namespaceURI===_t?d.namespaceURI===Oe?k==="svg":d.namespaceURI===gt?k==="svg"&&(H==="annotation-xml"||Nn[H]):!!bt[k]:u.namespaceURI===gt?d.namespaceURI===Oe?k==="math":d.namespaceURI===_t?k==="math"&&Ln[H]:!!Kt[k]:u.namespaceURI===Oe?d.namespaceURI===_t&&!Ln[H]||d.namespaceURI===gt&&!Nn[H]?!1:!Kt[k]&&(li[k]||!bt[k]):!!(Be==="application/xhtml+xml"&&Qt[u.namespaceURI]):!1},Ge=function(u){Ie(_.removed,{element:u});try{u.parentNode.removeChild(u)}catch{u.remove()}},Jt=function(u,d){try{Ie(_.removed,{attribute:d.getAttributeNode(u),from:d})}catch{Ie(_.removed,{attribute:null,from:d})}if(d.removeAttribute(u),u==="is"&&!ne[u])if(Qe||dt)try{Ge(d)}catch{}else try{d.setAttribute(u,"")}catch{}},On=function(u){var d,k;if(qt)u=""+u;else{var H=st(u,/^[\r\n\t ]+/);k=H&&H[0]}Be==="application/xhtml+xml"&&Je===Oe&&(u=''+u+"");var ae=Se?Se.createHTML(u):u;if(Je===Oe)try{d=new Wr().parseFromString(ae,Be)}catch{}if(!d||!d.documentElement){d=Ut.createDocument(Je,"template",null);try{d.documentElement.innerHTML=Xt?gn:ae}catch{}}var ye=d.body||d.documentElement;return u&&k&&ye.insertBefore(I.createTextNode(k),ye.childNodes[0]||null),Je===Oe?Yr.call(d,Fe?"html":"body")[0]:Fe?d.documentElement:ye},Cn=function(u){return Xr.call(u.ownerDocument||u,u,pe.SHOW_ELEMENT|pe.SHOW_COMMENT|pe.SHOW_TEXT,null,!1)},ui=function(u){return u instanceof jr&&(typeof u.nodeName!="string"||typeof u.textContent!="string"||typeof u.removeChild!="function"||!(u.attributes instanceof Gr)||typeof u.removeAttribute!="function"||typeof u.setAttribute!="function"||typeof u.namespaceURI!="string"||typeof u.insertBefore!="function"||typeof u.hasChildNodes!="function")},kt=function(u){return n(se)==="object"?u instanceof se:u&&n(u)==="object"&&typeof u.nodeType=="number"&&typeof u.nodeName=="string"},Ce=function(u,d,k){Ne[u]&&Z(Ne[u],function(H){H.call(_,d,k,et)})},Dn=function(u){var d;if(Ce("beforeSanitizeElements",u,null),ui(u))return Ge(u),!0;var k=re(u.nodeName);if(Ce("uponSanitizeElement",u,{tagName:k,allowedTags:te}),u.hasChildNodes()&&!kt(u.firstElementChild)&&(!kt(u.content)||!kt(u.content.firstElementChild))&&me(/<[/\w]/g,u.innerHTML)&&me(/<[/\w]/g,u.textContent))return Ge(u),!0;if(!te[k]||lt[k]){if(!lt[k]&&zn(k)&&(Q.tagNameCheck instanceof RegExp&&me(Q.tagNameCheck,k)||Q.tagNameCheck instanceof Function&&Q.tagNameCheck(k)))return!1;if(Zt&&!Ke[k]){var H=zt(u)||u.parentNode,ae=Vr(u)||u.childNodes;if(ae&&H)for(var ye=ae.length,le=ye-1;le>=0;--le)H.insertBefore(qr(ae[le],!0),Zr(u))}return Ge(u),!0}return u instanceof ee&&!oi(u)||(k==="noscript"||k==="noembed")&&me(/<\/no(script|embed)/i,u.innerHTML)?(Ge(u),!0):(Xe&&u.nodeType===3&&(d=u.textContent,d=Ae(d,$t," "),d=Ae(d,Ht," "),d=Ae(d,Ft," "),u.textContent!==d&&(Ie(_.removed,{element:u.cloneNode()}),u.textContent=d)),Ce("afterSanitizeElements",u,null),!1)},Mn=function(u,d,k){if(xn&&(d==="id"||d==="name")&&(k in I||k in ai))return!1;if(!(jt&&!Gt[d]&&me(Jr,d))){if(!(vn&&me(ei,d))){if(!ne[d]||Gt[d]){if(!(zn(u)&&(Q.tagNameCheck instanceof RegExp&&me(Q.tagNameCheck,u)||Q.tagNameCheck instanceof Function&&Q.tagNameCheck(u))&&(Q.attributeNameCheck instanceof RegExp&&me(Q.attributeNameCheck,d)||Q.attributeNameCheck instanceof Function&&Q.attributeNameCheck(d))||d==="is"&&Q.allowCustomizedBuiltInElements&&(Q.tagNameCheck instanceof RegExp&&me(Q.tagNameCheck,k)||Q.tagNameCheck instanceof Function&&Q.tagNameCheck(k))))return!1}else if(!Vt[d]){if(!me(Bt,Ae(k,_n,""))){if(!((d==="src"||d==="xlink:href"||d==="href")&&u!=="script"&&Ar(k,"data:")===0&&An[u])){if(!(yn&&!me(ti,Ae(k,_n,"")))){if(k)return!1}}}}}}return!0},zn=function(u){return u.indexOf("-")>0},Pn=function(u){var d,k,H,ae;Ce("beforeSanitizeAttributes",u,null);var ye=u.attributes;if(ye){var le={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ne};for(ae=ye.length;ae--;){d=ye[ae];var ge=d,je=ge.name,en=ge.namespaceURI;if(k=je==="value"?d.value:Sr(d.value),H=re(je),le.attrName=H,le.attrValue=k,le.keepAttr=!0,le.forceKeepAttr=void 0,Ce("uponSanitizeAttribute",u,le),k=le.attrValue,!le.forceKeepAttr&&(Jt(je,u),!!le.keepAttr)){if(!wn&&me(/\/>/i,k)){Jt(je,u);continue}Xe&&(k=Ae(k,$t," "),k=Ae(k,Ht," "),k=Ae(k,Ft," "));var Un=re(u.nodeName);if(Mn(Un,H,k)){if(En&&(H==="id"||H==="name")&&(Jt(je,u),k=ni+k),Se&&n(ft)==="object"&&typeof ft.getAttributeType=="function"&&!en)switch(ft.getAttributeType(Un,H)){case"TrustedHTML":k=Se.createHTML(k);break;case"TrustedScriptURL":k=Se.createScriptURL(k);break}try{en?u.setAttributeNS(en,je,k):u.setAttribute(je,k),ze(_.removed)}catch{}}}}Ce("afterSanitizeAttributes",u,null)}},ci=function S(u){var d,k=Cn(u);for(Ce("beforeSanitizeShadowDOM",u,null);d=k.nextNode();)Ce("uponSanitizeShadowNode",d,null),!Dn(d)&&(d.content instanceof z&&S(d.content),Pn(d));Ce("afterSanitizeShadowDOM",u,null)};return _.sanitize=function(S){var u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},d,k,H,ae;if(Xt=!S,Xt&&(S=""),typeof S!="string"&&!kt(S)){if(typeof S.toString!="function")throw Lt("toString is not a function");if(S=S.toString(),typeof S!="string")throw Lt("dirty is not a string, aborting")}if(!_.isSupported)return S;if(Wt||Yt(u),_.removed=[],typeof S=="string"&&(ot=!1),ot){if(S.nodeName){var ye=re(S.nodeName);if(!te[ye]||lt[ye])throw Lt("root node is forbidden and cannot be sanitized in-place")}}else if(S instanceof se)d=On(""),k=d.ownerDocument.importNode(S,!0),k.nodeType===1&&k.nodeName==="BODY"||k.nodeName==="HTML"?d=k:d.appendChild(k);else{if(!Qe&&!Xe&&!Fe&&S.indexOf("<")===-1)return Se&&mt?Se.createHTML(S):S;if(d=On(S),!d)return Qe?null:mt?gn:""}d&&qt&&Ge(d.firstChild);for(var le=Cn(ot?S:d);H=le.nextNode();)Dn(H)||(H.content instanceof z&&ci(H.content),Pn(H));if(ot)return S;if(Qe){if(dt)for(ae=Qr.call(d.ownerDocument);d.firstChild;)ae.appendChild(d.firstChild);else ae=d;return(ne.shadowroot||ne.shadowrootmod)&&(ae=Kr.call(y,ae,!0)),ae}var ge=Fe?d.outerHTML:d.innerHTML;return Fe&&te["!doctype"]&&d.ownerDocument&&d.ownerDocument.doctype&&d.ownerDocument.doctype.name&&me($r,d.ownerDocument.doctype.name)&&(ge=" `+ge),Xe&&(ge=Ae(ge,$t," "),ge=Ae(ge,Ht," "),ge=Ae(ge,Ft," ")),Se&&mt?Se.createHTML(ge):ge},_.setConfig=function(S){Yt(S),Wt=!0},_.clearConfig=function(){et=null,Wt=!1},_.isValidAttribute=function(S,u,d){et||Yt({});var k=re(S),H=re(u);return Mn(k,H,d)},_.addHook=function(S,u){typeof u=="function"&&(Ne[S]=Ne[S]||[],Ie(Ne[S],u))},_.removeHook=function(S){if(Ne[S])return ze(Ne[S])},_.removeHooks=function(S){Ne[S]&&(Ne[S]=[])},_.removeAllHooks=function(){Ne={}},_}var Br=mn();return Br})}(Ts)),It}var ir=window.DOMPurify||(window.DOMPurify=rr().default||rr());function As(a){let e,n,t=a[0]==="user"?"Me":"Bot",r,i,l,s,o,c=ir.sanitize(T.parse(a[1]))+"",f,h,b,p,M,G,j;return{c(){e=W("div"),n=W("p"),r=nt(t),l=we(),s=W("div"),o=W("div"),b=we(),p=W("div"),this.h()},l(x){e=q(x,"DIV",{class:!0});var O=D(e);n=q(O,"P",{class:!0});var X=D(n);r=rt(X,t),X.forEach(E),O.forEach(E),l=xe(x),s=q(x,"DIV",{class:!0});var R=D(s);o=q(R,"DIV",{class:!0});var K=D(o);K.forEach(E),b=xe(R),p=q(R,"DIV",{}),D(p).forEach(E),R.forEach(E),this.h()},h(){g(n,"class","text-xs px-2"),g(e,"class",i="flex items-center "+a[4][a[0]]),g(o,"class",f="bg-black py-0.5 px-4 max-w-2xl rounded leading-loose "+a[2]+" "+a[4][a[0]]),g(s,"class",M="flex "+a[4][a[0]])},m(x,O){V(x,e,O),L(e,n),L(n,r),V(x,l,O),V(x,s,O),L(s,o),o.innerHTML=c,L(s,b),L(s,p),a[6](p),G||(j=hr(h=a[5].call(null,o,a[1])),G=!0)},p(x,[O]){O&1&&t!==(t=x[0]==="user"?"Me":"Bot")&&Nt(r,t),O&1&&i!==(i="flex items-center "+x[4][x[0]])&&g(e,"class",i),O&2&&c!==(c=ir.sanitize(T.parse(x[1]))+"")&&(o.innerHTML=c),O&5&&f!==(f="bg-black py-0.5 px-4 max-w-2xl rounded leading-loose "+x[2]+" "+x[4][x[0]])&&g(o,"class",f),h&&gi(h.update)&&O&2&&h.update.call(null,x[1]),O&1&&M!==(M="flex "+x[4][x[0]])&&g(s,"class",M)},i:Y,o:Y,d(x){x&&E(e),x&&E(l),x&&E(s),a[6](null),G=!1,j()}}}function Ss(a,e,n){let{type:t}=e,{message:r=""}=e,{class:i=""}=e,l;const s={user:"justify-end text-rose-700",assistant:"justify-start text-teal-400",system:"justify-center text-gray-400"},o=(f,h)=>({update(b){l.scrollIntoView({behavior:"auto",block:"end",inline:"end"})}});or(()=>{l.scrollIntoView({behavior:"auto",block:"end",inline:"end"})});function c(f){pr[f?"unshift":"push"](()=>{l=f,n(3,l)})}return a.$$set=f=>{"type"in f&&n(0,t=f.type),"message"in f&&n(1,r=f.message),"class"in f&&n(2,i=f.class)},[t,r,i,l,s,o,c]}class Tr extends Ee{constructor(e){super(),Te(this,e,Ss,As,de,{type:0,message:1,class:2})}}function Rs(a){let e,n,t,r,i,l,s,o,c=[{name:a[2]},{placeholder:a[1]},{class:"shadow bg-white/10 rounded-md px-4 py-1.5 min-w-xl text-teal-300 border border-transparent focus:outline-none focus:ring-1 focus:ring-teal-300 focus:border-transparent"},a[6]],f={};for(let h=0;h{p.type=o};function b(){i=this.value,n(0,i)}return a.$$set=p=>{e=Pe(Pe({},e),_i(p)),n(6,r=Bn(e,t)),"value"in p&&n(0,i=p.value),"placeholder"in p&&n(1,l=p.placeholder),"name"in p&&n(2,s=p.name),"type"in p&&n(7,o=p.type),"label"in p&&n(3,c=p.label),"class"in p&&n(4,f=p.class)},[i,l,s,c,f,h,r,o,b]}class Ns extends Ee{constructor(e){super(),Te(this,e,Is,Rs,de,{value:0,placeholder:1,name:2,type:7,label:3,class:4})}}function sr(a,e,n){const t=a.slice();return t[6]=e[n],t}function ar(a){let e,n;return e=new Tr({props:{type:a[6].role,message:a[6].content}}),{c(){ce(e.$$.fragment)},l(t){ke(e.$$.fragment,t)},m(t,r){fe(e,t,r),n=!0},p(t,r){const i={};r&2&&(i.type=t[6].role),r&2&&(i.message=t[6].content),e.$set(i)},i(t){n||(P(e.$$.fragment,t),n=!0)},o(t){$(e.$$.fragment,t),n=!1},d(t){he(e,t)}}}function lr(a){let e,n;return e=new Tr({props:{type:"assistant",message:a[2]}}),{c(){ce(e.$$.fragment)},l(t){ke(e.$$.fragment,t)},m(t,r){fe(e,t,r),n=!0},p(t,r){const i={};r&4&&(i.message=t[2]),e.$set(i)},i(t){n||(P(e.$$.fragment,t),n=!0)},o(t){$(e.$$.fragment,t),n=!1},d(t){he(e,t)}}}function Ls(a){let e,n,t,r,i,l,s,o,c,f,h,b,p,M,G,j,x,O;t=new Bi({});let X=a[1].messages,R=[];for(let N=0;N$(R[N],1,1,()=>{R[N]=null});let w=a[2]&&lr(a);function U(N){a[4](N)}let Re={type:"text",class:"w-full"};return a[0]!==void 0&&(Re.value=a[0]),h=new Ns({props:Re}),pr.push(()=>bi(h,"value",U)),{c(){e=W("section"),n=W("div"),ce(t.$$.fragment),r=we(),i=W("div"),l=W("div"),s=W("div");for(let N=0;N{w=null}),Me());const ie={};!b&&F&1&&(b=!0,ie.value=N[0],ki(()=>b=!1)),h.$set(ie)},i(N){if(!j){P(t.$$.fragment,N);for(let F=0;Fn(1,t=o)),xt(a,We,o=>n(2,r=o));let i="";const l=async()=>{We.set("..."),await Ue.set(i),n(0,i="")};function s(o){i=o,n(0,i)}return[i,t,r,l,s]}class Us extends Ee{constructor(e){super(),Te(this,e,Os,Ls,de,{})}}export{Us as default};