@nlux/react
Version:
nlux React is a library for building conversational AI interfaces, with support for OpenAI, HuggingFace, and more.
1 lines • 99.1 kB
JavaScript
"use strict";var e=require("react"),t=require("react/jsx-runtime"),n=require("@nlux/core"),r=Object.prototype.hasOwnProperty;function s(e,t){for(let n of e.keys())if(o(n,t))return n}function o(e,t){var n,i,a;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((i=e.length)===t.length)for(;i--&&o(e[i],t[i]););return-1===i}if(n===Set){if(e.size!==t.size)return!1;for(i of e){if((a=i)&&"object"==typeof a&&!(a=s(t,a)))return!1;if(!t.has(a))return!1}return!0}if(n===Map){if(e.size!==t.size)return!1;for(i of e){if((a=i[0])&&"object"==typeof a&&!(a=s(t,a)))return!1;if(!o(i[1],t.get(a)))return!1}return!0}if(n===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(n===DataView){if((i=e.byteLength)===t.byteLength)for(;i--&&e.getInt8(i)===t.getInt8(i););return-1===i}if(ArrayBuffer.isView(e)){if((i=e.byteLength)===t.byteLength)for(;i--&&e[i]===t[i];);return-1===i}if(!n||"object"==typeof e){for(n in i=0,e){if(r.call(e,n)&&++i&&!r.call(t,n))return!1;if(!(n in t)||!o(e[n],t[n]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}const i=e=>{const t=new Set;let n=!1,r=null,s=null;const o=()=>{if(n)return;if(0===t.size)return;n=!0;const o=t.values().next().value;t.delete(o),r=(({message:e})=>{const t=document.createElement("div");t.classList.add("nlux-comp-exceptionItem");const n=document.createElement("span");return n.classList.add("nlux-comp-exp_itm_msg"),n.append(document.createTextNode(e)),t.append(n),t})(o),e.append(r),s=setTimeout(i,3e3)},i=()=>{r?.classList.add("nlux-comp-exceptionItem--hiding"),s=setTimeout((()=>{n=!1,r?.remove(),r=null,o()}),500)};return{displayException:e=>{t.add({message:e}),n||o()},destroy:()=>{t.clear(),r?.remove(),s&&clearTimeout(s)}}},a=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)})),c=e=>{"string"!=typeof e?e&&"function"==typeof e.toString?console.warn(`[nlux] ${e.toString()}`):console.warn("[nlux]"):console.warn(`[nlux] ${e}`)},l=[],u=e=>{l.includes(e)||(l.push(e),c(e))},d={typing:"nlux-composer--typing","submitting-prompt":"nlux-composer--submitting","submitting-conversation-starter":"nlux-composer--submitting",waiting:"nlux-composer--waiting"},p=(e,t)=>{if(!t||"Enter"===t){const t="Enter"===e.key&&!e.nativeEvent.isComposing,n=e.altKey||e.ctrlKey||e.metaKey||e.shiftKey;return t&&!n}if("CommandEnter"===t){if("Enter"===e.key&&(e.getModifierState("Control")||e.getModifierState("Meta")))return!0}return!1},m=()=>t.jsx("div",{className:"nlux-comp-cancelIcon",children:t.jsx("div",{className:"nlux-comp-cancelIcon-container"})}),h=()=>t.jsx("div",{className:"nlux-comp-sendIcon",children:t.jsx("div",{className:"nlux-comp-sendIcon-container"})}),g=["submitting-prompt","submitting-edit","submitting-conversation-starter","submitting-external-message"],f=n=>{const r=`nlux-comp-composer ${d[n.status]||""}`,s=g.includes(n.status),o=!n.hasValidInput||"waiting"===n.status||g.includes(n.status),i="typing"===n.status||"waiting"===n.status,a=!(!0===n.hideStopButton)&&(g.includes(n.status)||"waiting"===n.status),c=e.useRef(null);e.useEffect((()=>{"typing"===n.status&&n.autoFocus&&c.current&&c.current.focus()}),[n.status,n.autoFocus,c.current]);const l=e.useMemo((()=>e=>{n.onChange?.(e.target.value)}),[n.onChange]),u=e.useMemo((()=>()=>{n.onSubmit?.()}),[n.onSubmit]),f=e.useMemo((()=>e=>{p(e,n.submitShortcut)&&(e.preventDefault(),u())}),[u,n.submitShortcut]);return e.useEffect((()=>{if(!c.current)return;const e=()=>{const e=c.current;e&&(e.style.height="auto",e.style.height=`${e.scrollHeight}px`)};return c.current.addEventListener("input",e),()=>{c.current?.removeEventListener("input",e)}}),[c.current]),t.jsxs("div",{className:r,children:[t.jsx("textarea",{tabIndex:0,ref:c,disabled:s,placeholder:n.placeholder,value:n.prompt,onChange:l,onKeyDown:f,"aria-label":n.placeholder}),!a&&t.jsxs("button",{tabIndex:0,disabled:o,onClick:()=>n.onSubmit(),"aria-label":"Send",children:[i&&t.jsx(h,{}),!i&&n.Loader]}),a&&t.jsx("button",{tabIndex:0,onClick:n.onCancel,"aria-label":"Cancel",children:t.jsx(m,{})})]})},x=(e,t)=>"assistant"===e?t?.assistant?.name??"Assistant":"user"===e?t?.user?.name??"User":"",k=e=>{const t="nlux-chatSegment";return"complete"===e?`${t} nlux-chatSegment--complete`:"error"===e?`${t} nlux-chatSegment--error`:`${t} nlux-chatSegment--active`},w={received:"nlux_msg_received",sent:"nlux_msg_sent"},b={streaming:"nlux_msg_streaming",complete:"nlux_msg_complete"},v=e=>{if(!(e instanceof HTMLButtonElement))return;if("true"===e.dataset.clickListenerSet)return;let t=!1;const n=e.nextElementSibling;e.addEventListener("click",(()=>{if(t||!n)return;const r=n.innerText;navigator.clipboard.writeText(r??""),t=!0,e.classList.add("clicked"),setTimeout((()=>{t=!1,e.classList.remove("clicked")}),1e3)})),e.dataset.clickListenerSet="true"},y=e=>{const t="nlux-comp-copyButton";e instanceof HTMLButtonElement&&e.classList.contains(t)?v(e):e.querySelectorAll(`.${t}`).forEach(v)};function S(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let C={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function A(e){C=e}var R=Object.defineProperty,E=(e,t,n)=>((e,t,n)=>t in e?R(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class T{constructor(e){E(this,"options"),this.options=e||C}postprocess(e){return e}preprocess(e){return e}processAllTokens(e){return e}}E(T,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"]));const M=/[&<>"']/,I=new RegExp(M.source,"g"),B=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,O=new RegExp(B.source,"g"),L={"&":"&","<":"<",">":">",'"':""","'":"'"},j=e=>L[e];function z(e,t){if(t){if(M.test(e))return e.replace(I,j)}else if(B.test(e))return e.replace(O,j);return e}const P=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function H(e){return e.replace(P,((e,t)=>"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""))}const D=/(^|[^\[])\^/g;function N(e,t){let n="string"==typeof e?e:e.source;t=t||"";const r={replace:(e,t)=>{let s="string"==typeof t?t:t.source;return s=s.replace(D,"$1"),n=n.replace(e,s),r},getRegex:()=>new RegExp(n,t)};return r}function q(e){try{e=encodeURI(e).replace(/%25/g,"%")}catch(e){return null}return e}const Q={exec:()=>null};function U(e,t){const n=e.replace(/\|/g,((e,t,n)=>{let r=!1,s=t;for(;--s>=0&&"\\"===n[s];)r=!r;return r?"|":" |"})).split(/ \|/);let r=0;if(n[0].trim()||n.shift(),n.length>0&&!n[n.length-1].trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;r<n.length;r++)n[r]=n[r].trim().replace(/\\\|/g,"|");return n}function Y(e,t,n){const r=e.length;if(0===r)return"";let s=0;for(;s<r;){const o=e.charAt(r-s-1);if(o!==t||n){if(o===t||!n)break;s++}else s++}return e.slice(0,r-s)}const F=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,X=/(?:[*+-]|\d{1,9}[.)])/,Z=N(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,X).replace(/blockCode/g,/ {4}/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).getRegex(),K=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,W=/(?!\s*\])(?:\\.|[^\[\]\\])+/,J=N(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",W).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),G=N(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,X).getRegex(),V="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|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",$=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,_=N("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))","i").replace("comment",$).replace("tag",V).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ee=N(K).replace("hr",F).replace("heading"," {0,3}#{1,6}(?:\\s|$)").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","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",V).getRegex(),te={blockquote:N(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",ee).getRegex(),code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,def:J,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:F,html:_,lheading:Z,list:G,newline:/^(?: *(?:\n|$))+/,paragraph:ee,table:Q,text:/^[^\n]+/},ne=N("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",F).replace("heading"," {0,3}#{1,6}(?:\\s|$)").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","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",V).getRegex(),re={...te,table:ne,paragraph:N(K).replace("hr",F).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",ne).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",V).getRegex()},se={...te,html:N("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("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:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Q,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:N(K).replace("hr",F).replace("heading"," *#{1,6} *[^\n]").replace("lheading",Z).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},oe=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,ie=/^( {2,}|\\)\n(?!\s*$)/,ae="\\p{P}\\p{S}",ce=N(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,ae).getRegex(),le=N(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,ae).getRegex(),ue=N("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,ae).getRegex(),de=N("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,ae).getRegex(),pe=N(/\\([punct])/,"gu").replace(/punct/g,ae).getRegex(),me=N(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("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])?)+(?![-_])/).getRegex(),he=N($).replace("(?:--\x3e|$)","--\x3e").getRegex(),ge=N("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",he).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),fe=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,xe=N(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",fe).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),ke=N(/^!?\[(label)\]\[(ref)\]/).replace("label",fe).replace("ref",W).getRegex(),we=N(/^!?\[(ref)\](?:\[\])?/).replace("ref",W).getRegex(),be={_backpedal:Q,anyPunctuation:pe,autolink:me,blockSkip:/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,br:ie,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:Q,emStrongLDelim:le,emStrongRDelimAst:ue,emStrongRDelimUnd:de,escape:oe,link:xe,nolink:we,punctuation:ce,reflink:ke,reflinkSearch:N("reflink|nolink(?!\\()","g").replace("reflink",ke).replace("nolink",we).getRegex(),tag:ge,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:Q},ve={...be,link:N(/^!?\[(label)\]\((.*?)\)/).replace("label",fe).getRegex(),reflink:N(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",fe).getRegex()},ye={...be,escape:N(oe).replace("])","~|])").getRegex(),url:N(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},Se={...ye,br:N(ie).replace("{2,}","*").getRegex(),text:N(ye.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Ce={normal:te,gfm:re,pedantic:se},Ae={normal:be,gfm:ye,breaks:Se,pedantic:ve};var Re=Object.defineProperty,Ee=(e,t,n)=>((e,t,n)=>t in e?Re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);function Te(e,t,n,r){const s=t.href,o=t.title?z(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if("!"!==e[0].charAt(0)){r.state.inLink=!0;const e={type:"link",raw:n,href:s,title:o,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,e}return{type:"image",raw:n,href:s,title:o,text:z(i)}}class Me{constructor(e){Ee(this,"lexer"),Ee(this,"options"),Ee(this,"rules"),this.options=e||C}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=z(t[1]),n="mailto:"+e):(e=z(t[1]),n=e),{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){let e=t[0].replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,"\n $1");e=Y(e.replace(/^ *>[ \t]?/gm,""),"\n");const n=this.lexer.state.top;this.lexer.state.top=!0;const r=this.lexer.blockTokens(e);return this.lexer.state.top=n,{type:"blockquote",raw:t[0],tokens:r,text:e}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:Y(e,"\n")}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(/\n/g," ");const n=/[^ ]/.test(e),r=/^ /.test(e)&&/ $/.test(e);return n&&r&&(e=e.substring(1,e.length-1)),e=z(e,!0),{type:"codespan",raw:t[0],text:e}}}def(e){const t=this.rules.block.def.exec(e);if(t){const e=t[1].toLowerCase().replace(/\s+/g," "),n=t[2]?t[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:n,title:r}}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(!r)return;if(r[3]&&n.match(/[\p{L}\p{N}]/u))return;if(!(r[1]||r[2]||"")||!n||this.rules.inline.punctuation.exec(n)){const n=[...r[0]].length-1;let s,o,i=n,a=0;const c="*"===r[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,t=t.slice(-1*e.length+n);null!=(r=c.exec(t));){if(s=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!s)continue;if(o=[...s].length,r[3]||r[4]){i+=o;continue}if((r[5]||r[6])&&n%3&&!((n+o)%3)){a+=o;continue}if(i-=o,i>0)continue;o=Math.min(o,o+i+a);const t=[...r[0]][0].length,c=e.slice(0,n+r.index+t+o);if(Math.min(n,o)%2){const e=c.slice(1,-1);return{type:"em",raw:c,text:e,tokens:this.lexer.inlineTokens(e)}}const l=c.slice(2,-2);return{type:"strong",raw:c,text:l,tokens:this.lexer.inlineTokens(l)}}}}escape(e){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:z(t[1])}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],n=function(e,t){const n=e.match(/^(\s+)(?:```)/);if(null===n)return t;const r=n[1];return t.split("\n").map((e=>{const t=e.match(/^\s+/);if(null===t)return e;const[n]=t;return n.length>=r.length?e.slice(r.length):e})).join("\n")}(e,t[3]||"");return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(/#$/.test(e)){const t=Y(e,"#");this.options.pedantic?e=t.trim():t&&!/ $/.test(t)||(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:t[0]}}html(e){const t=this.rules.block.html.exec(e);if(t){return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){let e;return e=this.lexer.state.inRawBlock?t[0]:z(t[0]),{type:"text",raw:t[0],text:e}}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}link(e){const t=this.rules.inline.link.exec(e);if(t){const e=t[2].trim();if(!this.options.pedantic&&/^</.test(e)){if(!/>$/.test(e))return;const t=Y(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{const e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let r=0;r<e.length;r++)if("\\"===e[r])r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return-1}(t[2],"()");if(e>-1){const n=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=""}}let n=t[2],r="";if(this.options.pedantic){const e=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):"";return n=n.trim(),/^</.test(n)&&(n=this.options.pedantic&&!/>$/.test(e)?n.slice(1):n.slice(1,-1)),Te(t,{href:n?n.replace(this.rules.inline.anyPunctuation,"$1"):n,title:r?r.replace(this.rules.inline.anyPunctuation,"$1"):r},t[0],this.lexer)}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim();const r=n.length>1,s={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");const o=new RegExp(`^( {0,3}${n})((?:[\t ][^\\n]*)?(?:\\n|$))`);let i="",a="",c=!1;for(;e;){let n=!1;if(!(t=o.exec(e)))break;if(this.rules.block.hr.test(e))break;i=t[0],e=e.substring(i.length);let r=t[2].split("\n",1)[0].replace(/^\t+/,(e=>" ".repeat(3*e.length))),l=e.split("\n",1)[0],u=0;this.options.pedantic?(u=2,a=r.trimStart()):(u=t[2].search(/[^ ]/),u=u>4?1:u,a=r.slice(u),u+=t[1].length);let d=!1;if(!r&&/^ *$/.test(l)&&(i+=l+"\n",e=e.substring(l.length+1),n=!0),!n){const t=new RegExp(`^ {0,${Math.min(3,u-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),n=new RegExp(`^ {0,${Math.min(3,u-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),s=new RegExp(`^ {0,${Math.min(3,u-1)}}(?:\`\`\`|~~~)`),o=new RegExp(`^ {0,${Math.min(3,u-1)}}#`);for(;e;){const c=e.split("\n",1)[0];if(l=c,this.options.pedantic&&(l=l.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),s.test(l))break;if(o.test(l))break;if(t.test(l))break;if(n.test(e))break;if(l.search(/[^ ]/)>=u||!l.trim())a+="\n"+l.slice(u);else{if(d)break;if(r.search(/[^ ]/)>=4)break;if(s.test(r))break;if(o.test(r))break;if(n.test(r))break;a+="\n"+l}d||l.trim()||(d=!0),i+=c+"\n",e=e.substring(c.length+1),r=l.slice(u)}}s.loose||(c?s.loose=!0:/\n *\n *$/.test(i)&&(c=!0));let p,m=null;this.options.gfm&&(m=/^\[[ xX]\] /.exec(a),m&&(p="[ ] "!==m[0],a=a.replace(/^\[[ xX]\] +/,""))),s.items.push({type:"list_item",raw:i,task:!!m,checked:p,loose:!1,text:a,tokens:[]}),s.raw+=i}s.items[s.items.length-1].raw=i.trimEnd(),s.items[s.items.length-1].text=a.trimEnd(),s.raw=s.raw.trimEnd();for(let e=0;e<s.items.length;e++)if(this.lexer.state.top=!1,s.items[e].tokens=this.lexer.blockTokens(s.items[e].text,[]),!s.loose){const t=s.items[e].tokens.filter((e=>"space"===e.type)),n=t.length>0&&t.some((e=>/\n.*\n/.test(e.raw)));s.loose=n}if(s.loose)for(let e=0;e<s.items.length;e++)s.items[e].loose=!0;return s}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){const e=t[(n[2]||n[1]).replace(/\s+/g," ").toLowerCase()];if(!e){const e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return Te(n,e,n[0],this.lexer)}}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}table(e){const t=this.rules.block.table.exec(e);if(!t)return;if(!/[:|]/.test(t[2]))return;const n=U(t[1]),r=t[2].replace(/^\||\| *$/g,"").split("|"),s=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split("\n"):[],o={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===r.length){for(const e of r)/^ *-+: *$/.test(e)?o.align.push("right"):/^ *:-+: *$/.test(e)?o.align.push("center"):/^ *:-+ *$/.test(e)?o.align.push("left"):o.align.push(null);for(const e of n)o.header.push({text:e,tokens:this.lexer.inline(e)});for(const e of s)o.rows.push(U(e,o.header.length).map((e=>({text:e,tokens:this.lexer.inline(e)}))));return o}}tag(e){const t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&/^<a /i.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}text(e){const t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if("@"===t[2])e=z(t[0]),n="mailto:"+e;else{let r;do{r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(r!==t[0]);e=z(t[0]),n="www."===t[1]?"http://"+t[0]:t[0]}return{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}}var Ie=Object.defineProperty,Be=(e,t,n)=>((e,t,n)=>t in e?Ie(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class Oe{constructor(e){Be(this,"options"),Be(this,"state"),Be(this,"tokens"),Be(this,"inlineQueue"),Be(this,"tokenizer"),this.tokens=[],this.tokens.links=Object.create(null),this.options=e||C,this.options.tokenizer=this.options.tokenizer||new Me,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 t={block:Ce.normal,inline:Ae.normal};this.options.pedantic?(t.block=Ce.pedantic,t.inline=Ae.pedantic):this.options.gfm&&(t.block=Ce.gfm,this.options.breaks?t.inline=Ae.breaks:t.inline=Ae.gfm),this.tokenizer.rules=t}static get rules(){return{block:Ce,inline:Ae}}static lex(e,t){return new Oe(t).lex(e)}static lexInline(e,t){return new Oe(t).inlineTokens(e)}blockTokens(e,t=[]){let n,r,s,o;for(e=this.options.pedantic?e.replace(/\t/g," ").replace(/^ +$/gm,""):e.replace(/^( *)(\t+)/gm,((e,t,n)=>t+" ".repeat(n.length)));e;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some((r=>!!(n=r.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))))if(n=this.tokenizer.space(e))e=e.substring(n.raw.length),1===n.raw.length&&t.length>0?t[t.length-1].raw+="\n":t.push(n);else if(n=this.tokenizer.code(e))e=e.substring(n.raw.length),r=t[t.length-1],!r||"paragraph"!==r.type&&"text"!==r.type?t.push(n):(r.raw+="\n"+n.raw,r.text+="\n"+n.text,this.inlineQueue[this.inlineQueue.length-1].src=r.text);else if(n=this.tokenizer.fences(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.heading(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.hr(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.blockquote(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.list(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.html(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.def(e))e=e.substring(n.raw.length),r=t[t.length-1],!r||"paragraph"!==r.type&&"text"!==r.type?this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title}):(r.raw+="\n"+n.raw,r.text+="\n"+n.raw,this.inlineQueue[this.inlineQueue.length-1].src=r.text);else if(n=this.tokenizer.table(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.lheading(e))e=e.substring(n.raw.length),t.push(n);else{if(s=e,this.options.extensions&&this.options.extensions.startBlock){let t=1/0;const n=e.slice(1);let r;this.options.extensions.startBlock.forEach((e=>{r=e.call({lexer:this},n),"number"==typeof r&&r>=0&&(t=Math.min(t,r))})),t<1/0&&t>=0&&(s=e.substring(0,t+1))}if(this.state.top&&(n=this.tokenizer.paragraph(s)))r=t[t.length-1],o&&"paragraph"===r.type?(r.raw+="\n"+n.raw,r.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=r.text):t.push(n),o=s.length!==e.length,e=e.substring(n.raw.length);else if(n=this.tokenizer.text(e))e=e.substring(n.raw.length),r=t[t.length-1],r&&"text"===r.type?(r.raw+="\n"+n.raw,r.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=r.text):t.push(n);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n,r,s,o,i,a,c=e;if(this.tokens.links){const e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(o=this.tokenizer.rules.inline.reflinkSearch.exec(c));)e.includes(o[0].slice(o[0].lastIndexOf("[")+1,-1))&&(c=c.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+c.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(o=this.tokenizer.rules.inline.blockSkip.exec(c));)c=c.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+c.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;null!=(o=this.tokenizer.rules.inline.anyPunctuation.exec(c));)c=c.slice(0,o.index)+"++"+c.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;e;)if(i||(a=""),i=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some((r=>!!(n=r.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))))if(n=this.tokenizer.escape(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.tag(e))e=e.substring(n.raw.length),r=t[t.length-1],r&&"text"===n.type&&"text"===r.type?(r.raw+=n.raw,r.text+=n.text):t.push(n);else if(n=this.tokenizer.link(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.reflink(e,this.tokens.links))e=e.substring(n.raw.length),r=t[t.length-1],r&&"text"===n.type&&"text"===r.type?(r.raw+=n.raw,r.text+=n.text):t.push(n);else if(n=this.tokenizer.emStrong(e,c,a))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.codespan(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.br(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.del(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.autolink(e))e=e.substring(n.raw.length),t.push(n);else if(this.state.inLink||!(n=this.tokenizer.url(e))){if(s=e,this.options.extensions&&this.options.extensions.startInline){let t=1/0;const n=e.slice(1);let r;this.options.extensions.startInline.forEach((e=>{r=e.call({lexer:this},n),"number"==typeof r&&r>=0&&(t=Math.min(t,r))})),t<1/0&&t>=0&&(s=e.substring(0,t+1))}if(n=this.tokenizer.inlineText(s))e=e.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(a=n.raw.slice(-1)),i=!0,r=t[t.length-1],r&&"text"===r.type?(r.raw+=n.raw,r.text+=n.text):t.push(n);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}else e=e.substring(n.raw.length),t.push(n);return t}lex(e){e=e.replace(/\r\n|\r/g,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){const t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}}var Le=Object.defineProperty,je=(e,t,n)=>((e,t,n)=>t in e?Le(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class ze{constructor(e){je(this,"options"),this.options=e||C}blockquote(e){return`<blockquote>\n${e}</blockquote>\n`}br(){return"<br>"}checkbox(e){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}code(e,t,n){const r=(t||"").match(/^\S*/)?.[0];return e=e.replace(/\n$/,"")+"\n",r?'<pre><code class="language-'+z(r)+'">'+(n?e:z(e,!0))+"</code></pre>\n":"<pre><code>"+(n?e:z(e,!0))+"</code></pre>\n"}codespan(e){return`<code>${e}</code>`}del(e){return`<del>${e}</del>`}em(e){return`<em>${e}</em>`}heading(e,t,n){return`<h${t}>${e}</h${t}>\n`}hr(){return"<hr>\n"}html(e,t){return e}image(e,t,n){const r=q(e);if(null===r)return n;let s=`<img src="${e=r}" alt="${n}"`;return t&&(s+=` title="${t}"`),s+=">",s}link(e,t,n){const r=q(e);if(null===r)return n;let s='<a href="'+(e=r)+'"';return t&&(s+=' title="'+t+'"'),s+=">"+n+"</a>",s}list(e,t,n){const r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"</"+r+">\n"}listitem(e,t,n){return`<li>${e}</li>\n`}paragraph(e){return`<p>${e}</p>\n`}strong(e){return`<strong>${e}</strong>`}table(e,t){return t&&(t=`<tbody>${t}</tbody>`),"<table>\n<thead>\n"+e+"</thead>\n"+t+"</table>\n"}tablecell(e,t){const n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>\n`}tablerow(e){return`<tr>\n${e}</tr>\n`}text(e){return e}}class Pe{br(){return""}codespan(e){return e}del(e){return e}em(e){return e}html(e){return e}image(e,t,n){return""+n}link(e,t,n){return""+n}strong(e){return e}text(e){return e}}var He=Object.defineProperty,De=(e,t,n)=>((e,t,n)=>t in e?He(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class Ne{constructor(e){De(this,"options"),De(this,"renderer"),De(this,"textRenderer"),this.options=e||C,this.options.renderer=this.options.renderer||new ze,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new Pe}static parse(e,t){return new Ne(t).parse(e)}static parseInline(e,t){return new Ne(t).parseInline(e)}parse(e,t=!0){let n="";for(let r=0;r<e.length;r++){const s=e[r];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]){const e=s,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(e.type)){n+=t||"";continue}}switch(s.type){case"space":continue;case"hr":n+=this.renderer.hr();continue;case"heading":{const e=s;n+=this.renderer.heading(this.parseInline(e.tokens),e.depth,H(this.parseInline(e.tokens,this.textRenderer)));continue}case"code":{const e=s;n+=this.renderer.code(e.text,e.lang,!!e.escaped);continue}case"table":{const e=s;let t="",r="";for(let t=0;t<e.header.length;t++)r+=this.renderer.tablecell(this.parseInline(e.header[t].tokens),{header:!0,align:e.align[t]});t+=this.renderer.tablerow(r);let o="";for(let t=0;t<e.rows.length;t++){const n=e.rows[t];r="";for(let t=0;t<n.length;t++)r+=this.renderer.tablecell(this.parseInline(n[t].tokens),{header:!1,align:e.align[t]});o+=this.renderer.tablerow(r)}n+=this.renderer.table(t,o);continue}case"blockquote":{const e=s,t=this.parse(e.tokens);n+=this.renderer.blockquote(t);continue}case"list":{const e=s,t=e.ordered,r=e.start,o=e.loose;let i="";for(let t=0;t<e.items.length;t++){const n=e.items[t],r=n.checked,s=n.task;let a="";if(n.task){const e=this.renderer.checkbox(!!r);o?n.tokens.length>0&&"paragraph"===n.tokens[0].type?(n.tokens[0].text=e+" "+n.tokens[0].text,n.tokens[0].tokens&&n.tokens[0].tokens.length>0&&"text"===n.tokens[0].tokens[0].type&&(n.tokens[0].tokens[0].text=e+" "+n.tokens[0].tokens[0].text)):n.tokens.unshift({type:"text",text:e+" "}):a+=e+" "}a+=this.parse(n.tokens,o),i+=this.renderer.listitem(a,s,!!r)}n+=this.renderer.list(i,t,r);continue}case"html":{const e=s;n+=this.renderer.html(e.text,e.block);continue}case"paragraph":{const e=s;n+=this.renderer.paragraph(this.parseInline(e.tokens));continue}case"text":{let o=s,i=o.tokens?this.parseInline(o.tokens):o.text;for(;r+1<e.length&&"text"===e[r+1].type;)o=e[++r],i+="\n"+(o.tokens?this.parseInline(o.tokens):o.text);n+=t?this.renderer.paragraph(i):i;continue}default:{const e='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}parseInline(e,t){t=t||this.renderer;let n="";for(let r=0;r<e.length;r++){const s=e[r];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]){const e=this.options.extensions.renderers[s.type].call({parser:this},s);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type)){n+=e||"";continue}}switch(s.type){case"escape":{const e=s;n+=t.text(e.text);break}case"html":{const e=s;n+=t.html(e.text);break}case"link":{const e=s;n+=t.link(e.href,e.title,this.parseInline(e.tokens,t));break}case"image":{const e=s;n+=t.image(e.href,e.title,e.text);break}case"strong":{const e=s;n+=t.strong(this.parseInline(e.tokens,t));break}case"em":{const e=s;n+=t.em(this.parseInline(e.tokens,t));break}case"codespan":{const e=s;n+=t.codespan(e.text);break}case"br":n+=t.br();break;case"del":{const e=s;n+=t.del(this.parseInline(e.tokens,t));break}case"text":{const e=s;n+=t.text(e.text);break}default:{const e='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}}var qe,Qe,Ue,Ye=Object.defineProperty,Fe=e=>{throw TypeError(e)},Xe=(e,t,n)=>((e,t,n)=>t in e?Ye(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n),Ze=(e,t,n)=>(((e,t,n)=>{t.has(e)||Fe("Cannot "+n)})(e,t,"access private method"),n);qe=new WeakSet,Qe=function(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){const e="<p>An error occurred:</p><pre>"+z(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}},Ue=function(e,t){return(n,r)=>{const s={...r},o={...this.defaults,...s};!0===this.defaults.async&&!1===s.async&&(o.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),o.async=!0);const i=Ze(this,qe,Qe).call(this,!!o.silent,!!o.async);if(null==n)return i(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof n)return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(o.hooks&&(o.hooks.options=o),o.async)return Promise.resolve(o.hooks?o.hooks.preprocess(n):n).then((t=>e(t,o))).then((e=>o.hooks?o.hooks.processAllTokens(e):e)).then((e=>o.walkTokens?Promise.all(this.walkTokens(e,o.walkTokens)).then((()=>e)):e)).then((e=>t(e,o))).then((e=>o.hooks?o.hooks.postprocess(e):e)).catch(i);try{o.hooks&&(n=o.hooks.preprocess(n));let r=e(n,o);o.hooks&&(r=o.hooks.processAllTokens(r)),o.walkTokens&&this.walkTokens(r,o.walkTokens);let s=t(r,o);return o.hooks&&(s=o.hooks.postprocess(s)),s}catch(e){return i(e)}}};const Ke=new class{constructor(...e){var t,n,r;t=this,(n=qe).has(t)?Fe("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(t):n.set(t,r),Xe(this,"Hooks",T),Xe(this,"Lexer",Oe),Xe(this,"Parser",Ne),Xe(this,"Renderer",ze),Xe(this,"TextRenderer",Pe),Xe(this,"Tokenizer",Me),Xe(this,"defaults",{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}),Xe(this,"options",this.setOptions),Xe(this,"parse",Ze(this,qe,Ue).call(this,Oe.lex,Ne.parse)),Xe(this,"parseInline",Ze(this,qe,Ue).call(this,Oe.lexInline,Ne.parseInline)),this.use(...e)}lexer(e,t){return Oe.lex(e,t??this.defaults)}parser(e,t){return Ne.parse(e,t??this.defaults)}setOptions(e){return this.defaults={...this.defaults,...e},this}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach((e=>{const n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach((e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){const n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let r=e.renderer.apply(this,t);return!1===r&&(r=n.apply(this,t)),r}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");const n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)})),n.extensions=t),e.renderer){const t=this.defaults.renderer||new ze(this.defaults);for(const n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if("options"===n)continue;const r=n,s=e.renderer[r],o=t[r];t[r]=(...e)=>{let n=s.apply(t,e);return!1===n&&(n=o.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){const t=this.defaults.tokenizer||new Me(this.defaults);for(const n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;const r=n,s=e.tokenizer[r],o=t[r];t[r]=(...e)=>{let n=s.apply(t,e);return!1===n&&(n=o.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){const t=this.defaults.hooks||new T;for(const n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if("options"===n)continue;const r=n,s=e.hooks[r],o=t[r];T.passThroughHooks.has(n)?t[r]=e=>{if(this.defaults.async)return Promise.resolve(s.call(t,e)).then((e=>o.call(t,e)));const n=s.call(t,e);return o.call(t,n)}:t[r]=(...e)=>{let n=s.apply(t,e);return!1===n&&(n=o.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){const t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}})),this}walkTokens(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":{const e=r;for(const r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(const r of e.rows)for(const e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{const e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{const e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach((r=>{const s=e[r].flat(1/0);n=n.concat(this.walkTokens(s,t))})):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}};function We(e,t){return Ke.parse(e,t)}We.options=We.setOptions=function(e){return Ke.setOptions(e),We.defaults=Ke.defaults,A(We.defaults),We},We.getDefaults=S,We.defaults=C,We.use=function(...e){return Ke.use(...e),We.defaults=Ke.defaults,A(We.defaults),We},We.walkTokens=function(e,t){return Ke.walkTokens(e,t)},We.parseInline=Ke.parseInline,We.Parser=Ne,We.parser=Ne.parse,We.Renderer=ze,We.TextRenderer=Pe,We.Lexer=Oe,We.lexer=Oe.lex,We.Tokenizer=Me,We.Hooks=T,We.parse=We;const Je=(e,t)=>{const{showCodeBlockCopyButton:n,markdownLinkTarget:r,syntaxHighlighter:s,htmlSanitizer:o}=t||{},i=We(e,{async:!1,breaks:!0});if("string"!=typeof i)throw new Error("Markdown parsing failed");const a=document.createElement("div");return a.innerHTML=o?o(i):i,a.querySelectorAll("pre").forEach((e=>{const n=document.createElement("div");n.className="code-block";const r=e.querySelector("code");if(!r){const t=e.innerHTML;return n.innerHTML=o?o(t):t,void e.replaceWith(n)}let i;for(let e=0;e<r.classList.length;e++){const t=r.classList[e];if(t.startsWith("language-")){i=t.slice(9);break}}const a=document.createElement("pre"),c="<div>"+r.innerHTML+"</div>";if(a.innerHTML=t?.htmlSanitizer?t.htmlSanitizer(c):c,i&&(a.setAttribute("data-language",i),s)){const e="<div>"+s.createHighlighter()(r.textContent||"",i)+"</div>";a.innerHTML=o?o(e):e,a.className="highlighter-dark"}(e=>{e.replaceChildren()})(n),n.appendChild(a),e.replaceWith(n)})),!1!==n&&a.querySelectorAll(".code-block").forEach((e=>{if(!e.querySelector("pre"))return;if(e.previousElementSibling?.classList.contains("nlux-comp-copyButton"))return;const t="Copy code block to clipboard",n=document.createElement("button");n.classList.add("nlux-comp-copyButton"),n.setAttribute("aria-label",t),n.setAttribute("title",t);const r=document.createElement("span");r.classList.add("icon-copy"),n.appendChild(r),e.appendChild(n)})),"self"!==r&&a.querySelectorAll("a").forEach((e=>{e.setAttribute("target","_blank")})),a.innerHTML},Ge="nlux-comp-message",Ve={received:"nlux-comp-chatItem--received",sent:"nlux-comp-chatItem--sent"},$e="nlux-comp-chatItem--bubblesLayout",_e="nlux-comp-chatItem--listLayout",et=(e,t)=>{let n=!1;const{onComplete:r}=t||{},s=[],o="timeout"===(t?.skipStreamingAnimation?"timeout":"animationFrame")?e=>setTimeout(e,0):e=>requestAnimationFrame(e);const i=document.createElement("div");i.classList.add("md-in-progress"),e.append(i);const a=()=>{for(;i.firstChild;){const e=i.firstChild;e instanceof HTMLElement&&y(e),i.before(e)}},l=!t?.skipStreamingAnimation&&t?.streamingAnimationSpeed&&t.streamingAnimationSpeed>=0?t.streamingAnimationSpeed:t?.skipStreamingAnimation?0:8,u={timeSinceLastProcessing:(new Date).getTime(),currentMarkdown:"",previousHtml:void 0};let d=setInterval((()=>{const e=(new Date).getTime(),l="never"!==t?.waitTimeBeforeStreamCompletion;if(0===s.length&&l){const s="number"==typeof t?.waitTimeBeforeStreamCompletion?t.waitTimeBeforeStreamCompletion:2e3;return void((n||e-u.timeSinceLastProcessing>s)&&(n=!0,d&&(clearInterval(d),d=void 0),a(),i.remove(),r?.()))}u.timeSinceLastProcessing=e;const p=s.shift();void 0!==p&&"string"==typeof p&&o((()=>{const e=u.currentMarkdown+p,n=Je(e,t).trim();if("string"!=typeof n)return u.currentMarkdown=u.currentMarkdown.slice(0,-p.length),void c("Markdown parsing failed");if(u.previousHtml&&n.length>u.previousHtml.length&&n.startsWith(u.previousHtml)){a();const e=n.slice(u.previousHtml.length).trim();i.innerHTML=t?.htmlSanitizer?t.htmlSanitizer(e):e,u.currentMarkdown=p,u.previousHtml=void 0}else i.innerHTML=t?.htmlSanitizer?t.htmlSanitizer(n):n,u.currentMarkdown=e,u.previousHtml=n}))}),l);return{next:e=>{if(n)c("Stream is already complete. No more chunks can be added");else for(const t of e)s.push(t)},complete:()=>{s.push("\n"),n=!0},cancel:()=>{d&&(clearInterval(d),d=void 0),n=!0,i.remove()},error:()=>{n=!0}}},tt=function(n,r){const{uid:s,status:o,responseRenderer:i,markdownOptions:a,initialMarkdownMessage:c,markdownContainersController:l}=n,[u,d]=e.useState([]),p=e.useRef(null),m=e.useRef(null),h=e.useRef(null),g=e.useRef(null),[f,x]=e.useState();e.useEffect((()=>{p.current!==m.current&&(m.current=p.current,x(p.current||void 0))})),e.useEffect((()=>{if(f){const e=l.getStreamingDomElement(s);f.append(e)}}),[f]),e.useEffect((()=>{g.current=e=>{d((t=>[...t,e]))}}),[d]),e.useEffect((()=>{const e=l.getStreamingDomElement(s);return h.current=et(e,{syntaxHighlighter:a?.syntaxHighlighter,htmlSanitizer:a?.htmlSanitizer,markdownLinkTarget:a?.markdownLinkTarget,showCodeBlockCopyButton:a?.showCodeBlockCopyButton,skipStreamingAnimation:a?.skipStreamingAnimation,streamingAnimationSpeed:a?.streamingAnimationSpeed,waitTimeBeforeStreamCompletion:a?.waitTimeBeforeStreamCompletion,onComplete:a?.onStreamComplete}),c&&h.current.next(c),()=>{l.deleteStreamingDomElement(s)}}),[]),e.useEffect((()=>()=>{m.current=null,h.current=null,g.current=null,x(void 0)}),[]),e.useImperativeHandle(r,(()=>({streamChunk:e=>{g.current&&g.current?.(e),"string"==typeof e&&h.current?.next(e)},completeStream:()=>{h.current?.complete()},cancelStream:()=>{h.current?.cancel()}})),[]);const k=`${Ge} ${b[o]} ${w.received}`,v=i||void 0;return t.jsxs("div",{className:k,children:[v&&t.jsx(v,{uid:s,status:o,containerRef:p,content:u,contentType:"text",serverResponse:[],dataTransferMode:"stream"}),!v&&t.jsx("div",{className:"nlux-markdownStream-root",ref:p})]})},nt=n=>{const{markdownOptions:r}=n,s=e.useRef(null),o=e.useMemo((()=>n.content?Je(n.content,{syntaxHighlighter:r?.syntaxHighlighter,htmlSanitizer:r?.htmlSanitizer,markdownLinkTarget:r?.markdownLinkTarget,showCodeBlockCopyButton:r?.showCodeBlockCopyButton}):""),[n.content,r?.markdownLinkTarget,r?.syntaxHighlighter,r?.htmlSanitizer,r?.showCodeBlockCopyButton]);e.useEffect((()=>{s.current&&!1!==r?.showCodeBlockCopyButton&&y(s.current)}),[o,s.current,r?.showCodeBlockCopyButton]);const i=e.useMemo((()=>r?.htmlSanitizer?r.htmlSanitizer(o):o),[o,r?.htmlSanitizer]),a=e.useCallback((e=>{if(!n.canResubmit)return;const t=e.currentTarget.textContent;return t?p(e,n.submitShortcutKey)?(e.preventDefault(),void(n.onResubmit&&n.onResubmit(t))):void("Escape"===e.key&&(e.preventDefault(),e.currentTarget.textContent=n.content,e.currentTarget.blur())):void 0}),[n.canResubmit,n.onResubmit,n.content]),c=e.useCallback((e=>{n.canResubmit&&(e.preventDefault(),e.currentTarget.textContent=n.content,e.currentTarget.blur())}),[n.canResubmit,n.content]),l=e.useCallback((e=>{if(!n.canResubmit)return;e.preventDefault();const t=document.createRange();t.selectNodeContents(e.currentTarget);const r=window.getSelection();r?.removeAllRanges(),r?.addRange(t)}),[n.canResubmit]),u=n.canResubmit?"editable-markdown-container":"";return t.jsx(rt,{children:t.jsx("div",{className:"nlux-markdownStream-root"+(u?` ${u}`:""),children:t.jsx("div",{className:"nlux-markdown-container",ref:s,dangerouslySetInnerHTML:{__html:i},contentEditable:n.canResubmit,onKeyDown:a,onBlur:c,onFocus:l})})})};class rt extends e.Component{constructor(){super(...arguments),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){c("Markdown rendering error occurred. This could be due to a malformed markdown content, or it could be because the page requires an HTML sanitizer. Please check the error message for more details and consider configuring NLUX with a compatible sanitizer."),this.props.onMarkdownRenderingError&&this.props.onMarkdownRenderingError(e)}render(){return this.state.hasError?null:this.props.children}}const st=e=>t.jsx(rt,{children:t.jsx(nt,{...e})}),ot=n=>{const r="string"==typeof n.avatar,s=!r&&e.isValidElement(n.avatar);return t.jsxs("div",{className:"nlux-comp-avatar",children:[s&&n.avatar,!s&&r&&t.jsx("div",{className:"nlux-comp-avatarContainer",children:n.avatar&&t.jsx("div",{className:"nlux-comp-avatarPicture",style:{backgroundImage:`url("${encodeURI(n.avatar)}")`}})})]})},it=function(n,r){const s=e.useRef(null);e.useImperativeHandle(r,(()=>({streamChunk:e=>setTimeout((()=>s?.current?.streamChunk(e))),completeStream:()=>setTimeout((()=>s?.current?.completeStream())),cancelStream:()=>s?.current?.cancelStream()})),[]);const o="server-component"===n.contentType,i="received"===n.direction,a="sent"===n.direction,c="stream"===n.dataTransferMode,l=n.isPartOfInitialSegment,u=e.useCallback((()=>n.onMarkdownStreamRendered?.(n.uid)),[n.uid]);e.useEffect((()=>{c||o||l||n.onMarkdownStreamRendered?.(n.uid)}),[]);const d=function(n){const{uid:r,status:s,dataTransferMode:o,contentType:i,fetchedContent:a,streamedContent:c,streamedServerResponse:l,fetchedServerResponse:u,direction:d,messageOptions:p}=n;if(void 0!==p?.responseRenderer){if("stream"===o){const e={uid:r,status:s,dataTransferMode:o,contentType:i,content:c??[],serverResponse:l??[]};return()=>{const n=p.responseRenderer;return t.jsx(n,{...e})}}const n=e.isValidElement(a),d={uid:r,status:"complete",dataTransferMode:o,contentType:i,content:a?n?[]:[a]:[],serverComponent:n?a:void 0,serverResponse:u?[u]:[]};return()=>{const e=p.responseRenderer;return t.jsx(e,{...d})}}if("sent"===d){if("string"==typeof a){const e=a;return()=>t.jsx(t.Fragment,{children:e})}return()=>""}if("string"==t