@assistable/chat-widget
Version:
A chat widget that can be paired with Assistable workflows built using the Assistant API.
1 lines • 68.9 kB
JavaScript
function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},e.apply(this,arguments)}var t=["input:not([inert])","select:not([inert])","textarea:not([inert])","a[href]:not([inert])","button:not([inert])","[tabindex]:not(slot):not([inert])","audio[controls]:not([inert])","video[controls]:not([inert])",'[contenteditable]:not([contenteditable="false"]):not([inert])',"details>summary:first-of-type:not([inert])","details:not([inert])"],n=/* #__PURE__ */t.join(","),i="undefined"==typeof Element,r=i?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,s=!i&&Element.prototype.getRootNode?function(e){var t;return null==e||null===(t=e.getRootNode)||void 0===t?void 0:t.call(e)}:function(e){return null==e?void 0:e.ownerDocument},o=function e(t,n){var i;void 0===n&&(n=!0);var r=null==t||null===(i=t.getAttribute)||void 0===i?void 0:i.call(t,"inert");return""===r||"true"===r||n&&t&&e(t.parentNode)},a=function(e,t,i){if(o(e))return[];var s=Array.prototype.slice.apply(e.querySelectorAll(n));return t&&r.call(e,n)&&s.unshift(e),s.filter(i)},l=function e(t,i,s){for(var a=[],l=Array.from(t);l.length;){var c=l.shift();if(!o(c,!1))if("SLOT"===c.tagName){var u=c.assignedElements(),d=e(u.length?u:c.children,!0,s);s.flatten?a.push.apply(a,d):a.push({scopeParent:c,candidates:d})}else{r.call(c,n)&&s.filter(c)&&(i||!t.includes(c))&&a.push(c);var h=c.shadowRoot||"function"==typeof s.getShadowRoot&&s.getShadowRoot(c),p=!o(h,!1)&&(!s.shadowRootFilter||s.shadowRootFilter(c));if(h&&p){var g=e(!0===h?c.children:h.children,!0,s);s.flatten?a.push.apply(a,g):a.push({scopeParent:c,candidates:g})}else l.unshift.apply(l,c.children)}}return a},c=function(e){return!isNaN(parseInt(e.getAttribute("tabindex"),10))},u=function(e){if(!e)throw new Error("No node provided");return e.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName)||function(e){var t,n=null==e||null===(t=e.getAttribute)||void 0===t?void 0:t.call(e,"contenteditable");return""===n||"true"===n}(e))&&!c(e)?0:e.tabIndex},d=function(e,t){return e.tabIndex===t.tabIndex?e.documentOrder-t.documentOrder:e.tabIndex-t.tabIndex},h=function(e){return"INPUT"===e.tagName},p=function(e){var t=e.getBoundingClientRect();return 0===t.width&&0===t.height},g=function(e,t){return!(t.disabled||o(t)||function(e){return h(e)&&"hidden"===e.type}(t)||function(e,t){var n=t.displayCheck,i=t.getShadowRoot;if("hidden"===getComputedStyle(e).visibility)return!0;var o=r.call(e,"details>summary:first-of-type");if(r.call(o?e.parentElement:e,"details:not([open]) *"))return!0;if(n&&"full"!==n&&"legacy-full"!==n){if("non-zero-area"===n)return p(e)}else{if("function"==typeof i){for(var a=e;e;){var l=e.parentElement,c=s(e);if(l&&!l.shadowRoot&&!0===i(l))return p(e);e=e.assignedSlot?e.assignedSlot:l||c===e.ownerDocument?l:c.host}e=a}if(function(e){var t,n,i,r,o=e&&s(e),a=null===(t=o)||void 0===t?void 0:t.host,l=!1;if(o&&o!==e)for(l=!!(null!==(n=a)&&void 0!==n&&null!==(i=n.ownerDocument)&&void 0!==i&&i.contains(a)||null!=e&&null!==(r=e.ownerDocument)&&void 0!==r&&r.contains(e));!l&&a;){var c,u,d;l=!(null===(u=a=null===(c=o=s(a))||void 0===c?void 0:c.host)||void 0===u||null===(d=u.ownerDocument)||void 0===d||!d.contains(a))}return l}(e))return!e.getClientRects().length;if("legacy-full"!==n)return!0}return!1}(t,e)||function(e){return"DETAILS"===e.tagName&&Array.prototype.slice.apply(e.children).some(function(e){return"SUMMARY"===e.tagName})}(t)||function(e){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))for(var t=e.parentElement;t;){if("FIELDSET"===t.tagName&&t.disabled){for(var n=0;n<t.children.length;n++){var i=t.children.item(n);if("LEGEND"===i.tagName)return!!r.call(t,"fieldset[disabled] *")||!i.contains(e)}return!0}t=t.parentElement}return!1}(t))},f=function(e,t){return!(function(e){return function(e){return h(e)&&"radio"===e.type}(e)&&!function(e){if(!e.name)return!0;var t,n=e.form||s(e),i=function(e){return n.querySelectorAll('input[type="radio"][name="'+e+'"]')};if("undefined"!=typeof window&&void 0!==window.CSS&&"function"==typeof window.CSS.escape)t=i(window.CSS.escape(e.name));else try{t=i(e.name)}catch(e){return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s",e.message),!1}var r=function(e,t){for(var n=0;n<e.length;n++)if(e[n].checked&&e[n].form===t)return e[n]}(t,e.form);return!r||r===e}(e)}(t)||u(t)<0||!g(e,t))},b=function(e){var t=parseInt(e.getAttribute("tabindex"),10);return!!(isNaN(t)||t>=0)},m=function e(t){var n=[],i=[];return t.forEach(function(t,r){var s=!!t.scopeParent,o=s?t.scopeParent:t,a=function(e,t){var n=u(e);return n<0&&t&&!c(e)?0:n}(o,s),l=s?e(t.candidates):o;0===a?s?n.push.apply(n,l):n.push(o):i.push({documentOrder:r,tabIndex:a,item:t,isScope:s,content:l})}),i.sort(d).reduce(function(e,t){return t.isScope?e.push.apply(e,t.content):e.push(t.content),e},[]).concat(n)},w=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return!1!==r.call(e,n)&&f(t,e)},k=/* #__PURE__ */t.concat("iframe").join(","),x=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return!1!==r.call(e,k)&&g(t,e)};function v(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,i)}return n}function y(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?v(Object(n),!0).forEach(function(t){var i,r,s;i=e,s=n[t],(r=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:String(t)}(r=t))in i?Object.defineProperty(i,r,{value:s,enumerable:!0,configurable:!0,writable:!0}):i[r]=s}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):v(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var _=function(e){return"Tab"===(null==e?void 0:e.key)||9===(null==e?void 0:e.keyCode)},E=function(e){return _(e)&&!e.shiftKey},T=function(e){return _(e)&&e.shiftKey},S=function(e){return setTimeout(e,0)},$=function(e,t){var n=-1;return e.every(function(e,i){return!t(e)||(n=i,!1)}),n},R=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];return"function"==typeof e?e.apply(void 0,n):e},A=function(e){return e.target.shadowRoot&&"function"==typeof e.composedPath?e.composedPath()[0]:e.target},C=[];let z={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function I(e){z=e}const P=/[&<>"']/,O=new RegExp(P.source,"g"),N=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,L=new RegExp(N.source,"g"),D={"&":"&","<":"<",">":">",'"':""","'":"'"},F=e=>D[e];function B(e,t){if(t){if(P.test(e))return e.replace(O,F)}else if(N.test(e))return e.replace(L,F);return e}const j=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function M(e){return e.replace(j,(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 q=/(^|[^\[])\^/g;function Z(e,t){let n="string"==typeof e?e:e.source;t=t||"";const i={replace:(e,t)=>{let r="string"==typeof t?t:t.source;return r=r.replace(q,"$1"),n=n.replace(e,r),i},getRegex:()=>new RegExp(n,t)};return i}function G(e){try{e=encodeURI(e).replace(/%25/g,"%")}catch(e){return null}return e}const H={exec:()=>null};function Q(e,t){const n=e.replace(/\|/g,(e,t,n)=>{let i=!1,r=t;for(;--r>=0&&"\\"===n[r];)i=!i;return i?"|":" |"}).split(/ \|/);let i=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(;i<n.length;i++)n[i]=n[i].trim().replace(/\\\|/g,"|");return n}function U(e,t,n){const i=e.length;if(0===i)return"";let r=0;for(;r<i;){const s=e.charAt(i-r-1);if(s!==t||n){if(s===t||!n)break;r++}else r++}return e.slice(0,i-r)}function V(e,t,n,i){const r=t.href,s=t.title?B(t.title):null,o=e[1].replace(/\\([\[\]])/g,"$1");if("!"!==e[0].charAt(0)){i.state.inLink=!0;const e={type:"link",raw:n,href:r,title:s,text:o,tokens:i.inlineTokens(o)};return i.state.inLink=!1,e}return{type:"image",raw:n,href:r,title:s,text:B(o)}}class K{options;rules;lexer;constructor(e){this.options=e||z}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",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:U(e,"\n")}}}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 i=n[1];return t.split("\n").map(e=>{const t=e.match(/^\s+/);if(null===t)return e;const[n]=t;return n.length>=i.length?e.slice(i.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=U(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]}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){const e=U(t[0].replace(/^ *>[ \t]?/gm,""),"\n"),n=this.lexer.state.top;this.lexer.state.top=!0;const i=this.lexer.blockTokens(e);return this.lexer.state.top=n,{type:"blockquote",raw:t[0],tokens:i,text:e}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim();const i=n.length>1,r={type:"list",raw:"",ordered:i,start:i?+n.slice(0,-1):"",loose:!1,items:[]};n=i?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=i?n:"[*+-]");const s=new RegExp(`^( {0,3}${n})((?:[\t ][^\\n]*)?(?:\\n|$))`);let o="",a="",l=!1;for(;e;){let n=!1;if(!(t=s.exec(e)))break;if(this.rules.block.hr.test(e))break;o=t[0],e=e.substring(o.length);let i=t[2].split("\n",1)[0].replace(/^\t+/,e=>" ".repeat(3*e.length)),c=e.split("\n",1)[0],u=0;this.options.pedantic?(u=2,a=i.trimStart()):(u=t[2].search(/[^ ]/),u=u>4?1:u,a=i.slice(u),u+=t[1].length);let d=!1;if(!i&&/^ *$/.test(c)&&(o+=c+"\n",e=e.substring(c.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+|$)`),r=new RegExp(`^ {0,${Math.min(3,u-1)}}(?:\`\`\`|~~~)`),s=new RegExp(`^ {0,${Math.min(3,u-1)}}#`);for(;e;){const l=e.split("\n",1)[0];if(c=l,this.options.pedantic&&(c=c.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),r.test(c))break;if(s.test(c))break;if(t.test(c))break;if(n.test(e))break;if(c.search(/[^ ]/)>=u||!c.trim())a+="\n"+c.slice(u);else{if(d)break;if(i.search(/[^ ]/)>=4)break;if(r.test(i))break;if(s.test(i))break;if(n.test(i))break;a+="\n"+c}d||c.trim()||(d=!0),o+=l+"\n",e=e.substring(l.length+1),i=c.slice(u)}}r.loose||(l?r.loose=!0:/\n *\n *$/.test(o)&&(l=!0));let h,p=null;this.options.gfm&&(p=/^\[[ xX]\] /.exec(a),p&&(h="[ ] "!==p[0],a=a.replace(/^\[[ xX]\] +/,""))),r.items.push({type:"list_item",raw:o,task:!!p,checked:h,loose:!1,text:a,tokens:[]}),r.raw+=o}r.items[r.items.length-1].raw=o.trimEnd(),r.items[r.items.length-1].text=a.trimEnd(),r.raw=r.raw.trimEnd();for(let e=0;e<r.items.length;e++)if(this.lexer.state.top=!1,r.items[e].tokens=this.lexer.blockTokens(r.items[e].text,[]),!r.loose){const t=r.items[e].tokens.filter(e=>"space"===e.type),n=t.length>0&&t.some(e=>/\n.*\n/.test(e.raw));r.loose=n}if(r.loose)for(let e=0;e<r.items.length;e++)r.items[e].loose=!0;return r}}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]}}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"):"",i=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:i}}}table(e){const t=this.rules.block.table.exec(e);if(!t)return;if(!/[:|]/.test(t[2]))return;const n=Q(t[1]),i=t[2].replace(/^\||\| *$/g,"").split("|"),r=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split("\n"):[],s={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===i.length){for(const e of i)/^ *-+: *$/.test(e)?s.align.push("right"):/^ *:-+: *$/.test(e)?s.align.push("center"):/^ *:-+ *$/.test(e)?s.align.push("left"):s.align.push(null);for(const e of n)s.header.push({text:e,tokens:this.lexer.inline(e)});for(const e of r)s.rows.push(Q(e,s.header.length).map(e=>({text:e,tokens:this.lexer.inline(e)})));return s}}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])}}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)}}}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])}}escape(e){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:B(t[1])}}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]}}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=U(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 i=0;i<e.length;i++)if("\\"===e[i])i++;else if(e[i]===t[0])n++;else if(e[i]===t[1]&&(n--,n<0))return i;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],i="";if(this.options.pedantic){const e=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(n);e&&(n=e[1],i=e[3])}else i=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)),V(t,{href:n?n.replace(this.rules.inline.anyPunctuation,"$1"):n,title:i?i.replace(this.rules.inline.anyPunctuation,"$1"):i},t[0],this.lexer)}}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 V(n,e,n[0],this.lexer)}}emStrong(e,t,n=""){let i=this.rules.inline.emStrongLDelim.exec(e);if(i&&(!i[3]||!n.match(/[\p{L}\p{N}]/u))&&(!i[1]&&!i[2]||!n||this.rules.inline.punctuation.exec(n))){const n=[...i[0]].length-1;let r,s,o=n,a=0;const l="*"===i[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+n);null!=(i=l.exec(t));){if(r=i[1]||i[2]||i[3]||i[4]||i[5]||i[6],!r)continue;if(s=[...r].length,i[3]||i[4]){o+=s;continue}if((i[5]||i[6])&&n%3&&!((n+s)%3)){a+=s;continue}if(o-=s,o>0)continue;s=Math.min(s,s+o+a);const t=[...i[0]][0].length,l=e.slice(0,n+i.index+t+s);if(Math.min(n,s)%2){const e=l.slice(1,-1);return{type:"em",raw:l,text:e,tokens:this.lexer.inlineTokens(e)}}const c=l.slice(2,-2);return{type:"strong",raw:l,text:c,tokens:this.lexer.inlineTokens(c)}}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(/\n/g," ");const n=/[^ ]/.test(e),i=/^ /.test(e)&&/ $/.test(e);return n&&i&&(e=e.substring(1,e.length-1)),e=B(e,!0),{type:"codespan",raw:t[0],text:e}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}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])}}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=B(t[1]),n="mailto:"+e):(e=B(t[1]),n=e),{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if("@"===t[2])e=B(t[0]),n="mailto:"+e;else{let i;do{i=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(i!==t[0]);e=B(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}]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){let e;return e=this.lexer.state.inRawBlock?t[0]:B(t[0]),{type:"text",raw:t[0],text:e}}}}const W=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Y=/(?:[*+-]|\d{1,9}[.)])/,X=Z(/^(?!bull )((?:.|\n(?!\s*?\n|bull ))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,Y).getRegex(),J=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,ee=/(?!\s*\])(?:\\.|[^\[\]\\])+/,te=Z(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",ee).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),ne=Z(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Y).getRegex(),ie="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",re=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,se=Z("^ {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",re).replace("tag",ie).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),oe=Z(J).replace("hr",W).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",ie).getRegex(),ae={blockquote:Z(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",oe).getRegex(),code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,def:te,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:W,html:se,lheading:X,list:ne,newline:/^(?: *(?:\n|$))+/,paragraph:oe,table:H,text:/^[^\n]+/},le=Z("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",W).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",ie).getRegex(),ce={...ae,table:le,paragraph:Z(J).replace("hr",W).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",le).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",ie).getRegex()},ue={...ae,html:Z("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",re).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:H,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Z(J).replace("hr",W).replace("heading"," *#{1,6} *[^\n]").replace("lheading",X).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},de=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,he=/^( {2,}|\\)\n(?!\s*$)/,pe="\\p{P}\\p{S}",ge=Z(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,pe).getRegex(),fe=Z(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,pe).getRegex(),be=Z("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,pe).getRegex(),me=Z("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,pe).getRegex(),we=Z(/\\([punct])/,"gu").replace(/punct/g,pe).getRegex(),ke=Z(/^<(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(),xe=Z(re).replace("(?:--\x3e|$)","--\x3e").getRegex(),ve=Z("^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",xe).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),ye=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,_e=Z(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",ye).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Ee=Z(/^!?\[(label)\]\[(ref)\]/).replace("label",ye).replace("ref",ee).getRegex(),Te=Z(/^!?\[(ref)\](?:\[\])?/).replace("ref",ee).getRegex(),Se={_backpedal:H,anyPunctuation:we,autolink:ke,blockSkip:/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,br:he,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:H,emStrongLDelim:fe,emStrongRDelimAst:be,emStrongRDelimUnd:me,escape:de,link:_e,nolink:Te,punctuation:ge,reflink:Ee,reflinkSearch:Z("reflink|nolink(?!\\()","g").replace("reflink",Ee).replace("nolink",Te).getRegex(),tag:ve,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:H},$e={...Se,link:Z(/^!?\[(label)\]\((.*?)\)/).replace("label",ye).getRegex(),reflink:Z(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ye).getRegex()},Re={...Se,escape:Z(de).replace("])","~|])").getRegex(),url:Z(/^((?: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.!#$%&'*+\/=?_`{\|}~-]+@)))/},Ae={...Re,br:Z(he).replace("{2,}","*").getRegex(),text:Z(Re.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Ce={normal:ae,gfm:ce,pedantic:ue},ze={normal:Se,gfm:Re,breaks:Ae,pedantic:$e};class Ie{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||z,this.options.tokenizer=this.options.tokenizer||new K,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:ze.normal};this.options.pedantic?(t.block=Ce.pedantic,t.inline=ze.pedantic):this.options.gfm&&(t.block=Ce.gfm,t.inline=this.options.breaks?ze.breaks:ze.gfm),this.tokenizer.rules=t}static get rules(){return{block:Ce,inline:ze}}static lex(e,t){return new Ie(t).lex(e)}static lexInline(e,t){return new Ie(t).inlineTokens(e)}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}blockTokens(e,t=[]){let n,i,r,s;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(i=>!!(n=i.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),i=t[t.length-1],!i||"paragraph"!==i.type&&"text"!==i.type?t.push(n):(i.raw+="\n"+n.raw,i.text+="\n"+n.text,this.inlineQueue[this.inlineQueue.length-1].src=i.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),i=t[t.length-1],!i||"paragraph"!==i.type&&"text"!==i.type?this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title}):(i.raw+="\n"+n.raw,i.text+="\n"+n.raw,this.inlineQueue[this.inlineQueue.length-1].src=i.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(r=e,this.options.extensions&&this.options.extensions.startBlock){let t=Infinity;const n=e.slice(1);let i;this.options.extensions.startBlock.forEach(e=>{i=e.call({lexer:this},n),"number"==typeof i&&i>=0&&(t=Math.min(t,i))}),t<Infinity&&t>=0&&(r=e.substring(0,t+1))}if(this.state.top&&(n=this.tokenizer.paragraph(r)))i=t[t.length-1],s&&"paragraph"===i.type?(i.raw+="\n"+n.raw,i.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=i.text):t.push(n),s=r.length!==e.length,e=e.substring(n.raw.length);else if(n=this.tokenizer.text(e))e=e.substring(n.raw.length),i=t[t.length-1],i&&"text"===i.type?(i.raw+="\n"+n.raw,i.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=i.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,i,r,s,o,a,l=e;if(this.tokens.links){const e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(s=this.tokenizer.rules.inline.reflinkSearch.exec(l));)e.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(l=l.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+l.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(s=this.tokenizer.rules.inline.blockSkip.exec(l));)l=l.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+l.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;null!=(s=this.tokenizer.rules.inline.anyPunctuation.exec(l));)l=l.slice(0,s.index)+"++"+l.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;e;)if(o||(a=""),o=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(i=>!!(n=i.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),i=t[t.length-1],i&&"text"===n.type&&"text"===i.type?(i.raw+=n.raw,i.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),i=t[t.length-1],i&&"text"===n.type&&"text"===i.type?(i.raw+=n.raw,i.text+=n.text):t.push(n);else if(n=this.tokenizer.emStrong(e,l,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(r=e,this.options.extensions&&this.options.extensions.startInline){let t=Infinity;const n=e.slice(1);let i;this.options.extensions.startInline.forEach(e=>{i=e.call({lexer:this},n),"number"==typeof i&&i>=0&&(t=Math.min(t,i))}),t<Infinity&&t>=0&&(r=e.substring(0,t+1))}if(n=this.tokenizer.inlineText(r))e=e.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(a=n.raw.slice(-1)),o=!0,i=t[t.length-1],i&&"text"===i.type?(i.raw+=n.raw,i.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}}class Pe{options;constructor(e){this.options=e||z}code(e,t,n){const i=(t||"").match(/^\S*/)?.[0];return e=e.replace(/\n$/,"")+"\n",i?'<pre><code class="language-'+B(i)+'">'+(n?e:B(e,!0))+"</code></pre>\n":"<pre><code>"+(n?e:B(e,!0))+"</code></pre>\n"}blockquote(e){return`<blockquote>\n${e}</blockquote>\n`}html(e,t){return e}heading(e,t,n){return`<h${t}>${e}</h${t}>\n`}hr(){return"<hr>\n"}list(e,t,n){const i=t?"ol":"ul";return"<"+i+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"</"+i+">\n"}listitem(e,t,n){return`<li>${e}</li>\n`}checkbox(e){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph(e){return`<p>${e}</p>\n`}table(e,t){return t&&(t=`<tbody>${t}</tbody>`),"<table>\n<thead>\n"+e+"</thead>\n"+t+"</table>\n"}tablerow(e){return`<tr>\n${e}</tr>\n`}tablecell(e,t){const n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>\n`}strong(e){return`<strong>${e}</strong>`}em(e){return`<em>${e}</em>`}codespan(e){return`<code>${e}</code>`}br(){return"<br>"}del(e){return`<del>${e}</del>`}link(e,t,n){const i=G(e);if(null===i)return n;let r='<a href="'+(e=i)+'"';return t&&(r+=' title="'+t+'"'),r+=">"+n+"</a>",r}image(e,t,n){const i=G(e);if(null===i)return n;let r=`<img src="${e=i}" alt="${n}"`;return t&&(r+=` title="${t}"`),r+=">",r}text(e){return e}}class Oe{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,t,n){return""+n}image(e,t,n){return""+n}br(){return""}}class Ne{options;renderer;textRenderer;constructor(e){this.options=e||z,this.options.renderer=this.options.renderer||new Pe,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new Oe}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 i=0;i<e.length;i++){const r=e[i];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const e=r,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(r.type){case"space":continue;case"hr":n+=this.renderer.hr();continue;case"heading":{const e=r;n+=this.renderer.heading(this.parseInline(e.tokens),e.depth,M(this.parseInline(e.tokens,this.textRenderer)));continue}case"code":n+=this.renderer.code(r.text,r.lang,!!r.escaped);continue;case"table":{const e=r;let t="",i="";for(let t=0;t<e.header.length;t++)i+=this.renderer.tablecell(this.parseInline(e.header[t].tokens),{header:!0,align:e.align[t]});t+=this.renderer.tablerow(i);let s="";for(let t=0;t<e.rows.length;t++){const n=e.rows[t];i="";for(let t=0;t<n.length;t++)i+=this.renderer.tablecell(this.parseInline(n[t].tokens),{header:!1,align:e.align[t]});s+=this.renderer.tablerow(i)}n+=this.renderer.table(t,s);continue}case"blockquote":{const e=this.parse(r.tokens);n+=this.renderer.blockquote(e);continue}case"list":{const e=r,t=e.ordered,i=e.start,s=e.loose;let o="";for(let t=0;t<e.items.length;t++){const n=e.items[t],i=n.checked,r=n.task;let a="";if(n.task){const e=this.renderer.checkbox(!!i);s?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,s),o+=this.renderer.listitem(a,r,!!i)}n+=this.renderer.list(o,t,i);continue}case"html":n+=this.renderer.html(r.text,r.block);continue;case"paragraph":n+=this.renderer.paragraph(this.parseInline(r.tokens));continue;case"text":{let s=r,o=s.tokens?this.parseInline(s.tokens):s.text;for(;i+1<e.length&&"text"===e[i+1].type;)s=e[++i],o+="\n"+(s.tokens?this.parseInline(s.tokens):s.text);n+=t?this.renderer.paragraph(o):o;continue}default:{const e='Token with "'+r.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 i=0;i<e.length;i++){const r=e[i];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const e=this.options.extensions.renderers[r.type].call({parser:this},r);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(r.type)){n+=e||"";continue}}switch(r.type){case"escape":case"text":n+=t.text(r.text);break;case"html":n+=t.html(r.text);break;case"link":n+=t.link(r.href,r.title,this.parseInline(r.tokens,t));break;case"image":n+=t.image(r.href,r.title,r.text);break;case"strong":n+=t.strong(this.parseInline(r.tokens,t));break;case"em":n+=t.em(this.parseInline(r.tokens,t));break;case"codespan":n+=t.codespan(r.text);break;case"br":n+=t.br();break;case"del":n+=t.del(this.parseInline(r.tokens,t));break;default:{const e='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}}class Le{options;constructor(e){this.options=e||z}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}}const De=new class{defaults={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};options=this.setOptions;parse=this.#e(Ie.lex,Ne.parse);parseInline=this.#e(Ie.lexInline,Ne.parseInline);Parser=Ne;Renderer=Pe;TextRenderer=Oe;Lexer=Ie;Tokenizer=K;Hooks=Le;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(const i of e)switch(n=n.concat(t.call(this,i)),i.type){case"table":{const e=i;for(const i of e.header)n=n.concat(this.walkTokens(i.tokens,t));for(const i of e.rows)for(const e of i)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":n=n.concat(this.walkTokens(i.items,t));break;default:{const e=i;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(i=>{const r=e[i].flat(Infinity);n=n.concat(this.walkTokens(r,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}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 i=e.renderer.apply(this,t);return!1===i&&(i=n.apply(this,t)),i}: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 Pe(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 i=e.renderer[n],r=t[n];t[n]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=r.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){const t=this.defaults.tokenizer||new K(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 i=e.tokenizer[n],r=t[n];t[n]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=r.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){const t=this.defaults.hooks||new Le;for(const n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if("options"===n)continue;const i=e.hooks[n],r=t[n];t[n]=Le.passThroughHooks.has(n)?e=>{if(this.defaults.async)return Promise.resolve(i.call(t,e)).then(e=>r.call(t,e));const n=i.call(t,e);return r.call(t,n)}:(...e)=>{let n=i.apply(t,e);return!1===n&&(n=r.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){const t=this.defaults.walkTokens,i=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(i.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return Ie.lex(e,t??this.defaults)}parser(e,t){return Ne.parse(e,t??this.defaults)}#e(e,t){return(n,i)=>{const r={...i},s={...this.defaults,...r};!0===this.defaults.async&&!1===r.async&&(s.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),s.async=!0);const o=this.#t(!!s.silent,!!s.async);if(null==n)return o(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof n)return o(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(s.hooks&&(s.hooks.options=s),s.async)return Promise.resolve(s.hooks?s.hooks.preprocess(n):n).then(t=>e(t,s)).then(e=>s.hooks?s.hooks.processAllTokens(e):e).then(e=>s.walkTokens?Promise.all(this.walkTokens(e,s.walkTokens)).then(()=>e):e).then(e=>t(e,s)).then(e=>s.hooks?s.hooks.postprocess(e):e).catch(o);try{s.hooks&&(n=s.hooks.preprocess(n));let i=e(n,s);s.hooks&&(i=s.hooks.processAllTokens(i)),s.walkTokens&&this.walkTokens(i,s.walkTokens);let r=t(i,s);return s.hooks&&(r=s.hooks.postprocess(r)),r}catch(e){return o(e)}}}#t(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>"+B(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function Fe(e,t){return De.parse(e,t)}Fe.options=Fe.setOptions=function(e){return De.setOptions(e),I(Fe.defaults=De.defaults),Fe},Fe.getDefaults=function(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}},Fe.defaults=z,Fe.use=function(...e){return De.use(...e),I(Fe.defaults=De.defaults),Fe},Fe.walkTokens=function(e,t){return De.walkTokens(e,t)},Fe.parseInline=De.parseInline,Fe.Parser=Ne,Fe.parser=Ne.parse,Fe.Renderer=Pe,Fe.TextRenderer=Oe,Fe.Lexer=Ie,Fe.lexer=Ie.lex,Fe.Tokenizer=K,Fe.Hooks=Le,Fe.parse=Fe;var Be,je='<div id="buildship-chat-widget__header"><div id="buildship-chat-widget__title"><svg id="buildship-chat-widget__title_icon" width="24" height="19" viewBox="0 0 24 19"><path d="M9 6C9.55229 6 10 6.44772 10 7V9C10 9.55228 9.55229 10 9 10C8.44771 10 8 9.55228 8 9V7C8 6.44772 8.44771 6 9 6Z"/><path d="M16 7C16 6.44772 15.5523 6 15 6C14.4477 6 14 6.44772 14 7V9C14 9.55228 14.4477 10 15 10C15.5523 10 16 9.55228 16 9V7Z"/><path d="M19.2099 16C19.0086 16 18.815 16.0768 18.6684 16.2147L16.4858 18.269C15.2525 19.4298 13.2248 18.6278 13.1191 16.9374C13.0862 16.4105 12.6493 16 12.1213 16H5C3.34315 16 2 14.6569 2 13V9C2 9.55228 1.55228 10 1 10C0.447715 10 0 9.55228 0 9V6C0 5.44772 0.447715 5 1 5C1.55228 5 2 5.44772 2 6V3C2 1.34315 3.34315 0 5 0H19C20.6569 0 22 1.34315 22 3V6C22 5.44772 22.4477 5 23 5C23.5523 5 24 5.44772 24 6V9C24 9.55228 23.5523 10 23 10C22.4477 10 22 9.55228 22 9V13.2099C22 14.7508 20.7508 16 19.2099 16ZM5 2C4.44772 2 4 2.44772 4 3V13C4 13.5523 4.44772 14 5 14H12.1213C13.7053 14 15.0163 15.2315 15.1152 16.8124L17.2977 14.7583C17.8152 14.2712 18.4992 14 19.2099 14C19.6463 14 20 13.6463 20 13.2099V3C20 2.44772 19.5523 2 19 2H5Z"/></svg></div><div><a id="buildship-chat-widget__branding" target="_blank">Available 24/7</a></div></div><div id="buildship-chat-widget__body"><form id="buildship-chat-widget__form"><input autocomplete="off" id="buildship-chat-widget__input" name="message" type="text" placeholder="Ask me a question…" required aria-label="Message"><button id="buildship-chat-widget__submit" type="submit"><svg width="14" height="14" viewBox="0 0 16 14" fill="none"><path d="M1 7L15 7M15 7L9 13M15 7L9 1" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button></form></div>';function Me(e,t,n){if(!e.s){if(n instanceof Ze){if(!n.s)return void(n.o=Me.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Me.bind(null,e,t),Me.bind(null,e,2));e.s=t,e.v=n;var i=e.o;i&&i(e)}}var qe=function(t){try{t.preventDefault();var n=t.target;if(!Ke.url)return console.error("BuildShip Chat Widget: No URL provided"),Ke.disableErrorAlert||alert("Could not send chat message: No URL provided"),Promise.resolve();var i=document.getElementById("buildship-chat-widget__submit");i.setAttribute("disabled","");var r=new Headers;r.append("Content-Type","application/json");var s=e({},Ke.user,{message:n.elements.message.value,threadId:Ke.threadId,timestamp:Date.now(),location_id:Ke.location_id});return Promise.resolve(He(s.message,s.timestamp,"user")).then(function(){function e(){return i.removeAttribute("disabled"),!1}n.reset(),Xe.prepend(et);var t=function(e,t){try{var n=Promise.resolve(fetch(Ke.url,{method:"POST",headers:r,body:JSON.stringify(s)})).then(function(e){et.remove();var t=Ke.responseIsAStream?Promise.resolve(ot(e)).then(function(){}):Promise.resolve(st(e)).then(function(){});if(t&&t.then)return t.then(function(){})})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){et.remove(),console.error("BuildShip Chat Widget:",e),Ke.disableErrorAlert||alert("Could not send message: "+e.message)});return t&&t.then?t.then(e):e()})}catch(t){return Promise.reject(t)}},Ze=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var i=new e,r=this.s;if(r){var s=1&r?t:n;if(s){try{Me(i,1,s(this.v))}catch(e){Me(i,2,e)}return i}return this}return this.o=function(e){try{var r=e.v;1&e.s?Me(i,1,t?t(r):r):n?Me(i,1,n(r)):Me(i,2,r)}catch(e){Me(i,2,e)}},i},e}();function Ge(e){return e instanceof Ze&&1&e.s}var He=function(e,t,n){try{var i=document.createElement("div");i.classList.add("buildship-chat-widget__message"),i.classList.add("buildship-chat-widget__message--"+n),i.id="buildship-chat-widget__message--"+n+"--"+t;var r=document.createElement("p");return Promise.resolve(Fe(e,{renderer:Ue})).then(function(e){r.innerHTML=e,i.appendChild(r);var n=document.createElement("p");n.classList.add("buildship-chat-widget__message-timestamp"),n.textContent=("0"+new Date(t).getHours()).slice(-2)+":"+("0"+new Date(t).getMinutes()).slice(-2),i.appendChild(n),Xe.prepend(i)})}catch(e){return Promise.reject(e)}},Qe="buildship-chat-widget__backdrop",Ue=new Fe.Renderer,Ve=Ue.link;Ue.link=function(e,t,n){return Ve.call(Ue,e,t,n).replace(/^<a /,'<a target="_blank" rel="nofollow" ')};var Ke=e({url:"",threadId:null,responseIsAStream:!1,user:{},widgetTitle:"Chatbot",greetingMessage:null,disableErrorAlert:!1,closeOnOutsideClick:!0,openOnLoad:!1,location_id:null},null==(Be=window.buildShipChatWidget)?void 0:Be.config);function We(){var e=document.createElement("style");e.innerHTML=":root{--buildship-chat-widget-bg-color:#fff;--buildship-chat-widget-border-color:#e2e2e2;--buildship-chat-widget-shadow:rgba(7,0,20,.06) 0px 0px 0px 1px,rgba(7,0,20,.1) 0px 10px 15px -3px,rgba(7,0,20,.05) 0px 4px 6px,rgba(7,0,20,.05) 0px 30px 40px;--buildship-chat-widget-primary-color-text:#000;--buildship-chat-widget-secondary-color-text:#979797;--buildship-chat-widget-user-message-text-color:#fff;--buildship-chat-widget-user-message-bg-color:#2c91ed;--buildship-chat-widget-system-message-text-color:#000;--buildship-chat-widget-system-message-bg-color:#e4e4e4;--buildship-chat-widget-primary-color:#2c91ed;--buildship-chat-widget-header-height:4rem;--buildship-chat-widget-button-transition:background-color 0.2s ease-in-out,opacity 0.2s ease-in-out,transform 0.2s ease-in-out;--buildship-chat-widget-title-weight:600;--buildship-chat-widget-button-weight:500;--buildship-chat-widget-border-radius:1rem}@media (prefers-color-scheme:dark){:root{--buildship-chat-widget-bg-color:#2d2d30;--buildship-chat-widget-border-color:#424244;--buildship-chat-widget-shadow:rgba(0,0,5,.24) 0px 0px 0px 1px,rgba(0,0,5,.4) 0px 10px 15px -3px,rgba(0,0,5,.2) 0px 4px 6px,rgba(0,0,5,.2) 0px 30px 40px;--buildship-chat-widget-primary-color-text:#fff;--buildship-chat-widget-secondary-color-text:#818183;--buildship-chat-widget-user-message-text-color:#fff;--buildship-chat-widget-user-message-bg-color:#2c91ed;--buildship-chat-widget-system-message-text-color:#fff;--buildship-chat-widget-system-message-bg-color:#424244}}[data-theme=light]{--buildship-chat-widget-bg-color:#fff;--buildship-chat-widget-border-color:#e2e2e2;--buildship-chat-widget-shadow:rgba(7,0,20,.06) 0px 0px 0px 1px,rgba(7,0,20,.1) 0px 10px 15px -3px,rgba(7,0,20,.05) 0px 4px 6px,rgba(7,0,20,.05) 0px 30px 40px;--buildship-chat-widget-primary-color-text:#000;--buildship-chat-widget-secondary-color-text:#979797;--buildship-chat-widget-user-message-text-color:#fff;--buildship-chat-widget-user-message-bg-color:#2c91ed;--buildship-chat-widget-system-message-text-color:#000;--buildship-chat-widget-system-message-bg-color:#e4e4e4}[data-theme=dark]{--buildship-chat-widget-bg-color:#2d2d30;--buildship-chat-widget-border-color:#424244;--buildship-chat-widget-shadow:rgba(0,0,5,.24) 0px 0px 0px 1px,rgba(0,0,5,.4) 0px 10px 15px -3px,rgba(0,0,5,.2) 0px 4px 6px,rgba(0,0,5,.2) 0px 30px 40px;--buildship-chat-widget-primary-color-text:#fff;--buildship-chat-widget-secondary-color-text:#818183;--buildship-chat-widget-user-message-text-color:#fff;--buildship-chat-widget-user-message-bg-color:#2c91ed;--buildship-chat-widget-system-message-text-color:#fff;--buildship-chat-widget-system-message-bg-color:#424244}#buildship-chat-widget__container{background-color:var(--buildship-chat-widget-bg-color);border-radius:var(--buildship-chat-widget-border-radius);box-shadow:var(--buildship-chat-widget-shadow);box-sizing:border-box;color:var(--buildship-chat-widget-primary-color-text);font-family:inherit;font-size:1rem;height:40rem;max-height:calc(100vh - 100px);max-width:calc(100vw - 48px);position:fixed;transition:all .3s ease;width:25rem;z-index:9999}#buildship-chat-widget__container *{box-sizing:border-box}#buildship-chat-widget__container :focus{outline:none}#buildship-chat-widget__backdrop{background-color:transparent;box-sizing:border-box;height:100vh;left:0;position:fixed;top:0;width:100vw;z-index:9998}#buildship-chat-widget__header{align-items:center;border-bottom:2px solid var(--buildship-chat-widget-border-color);display:flex;height:var(--buildship-chat-widget-header-height);justify-content:space-between;padding:1rem}#buildship-chat-widget__title{align-items:center;display:flex;font-weight:var(--buildship-chat-widget-title-weight);width:60%}#buildship-chat-widget__title_icon{margin-right:.5rem}#buildship-chat-widget__title_icon path{fill:var(--buildship-chat-widget-primary-color-text)}#buildship-chat-widget__title_text{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;width:100%}#buildship-chat-widget__branding{color:var(--buildship-chat-widget-secondary-color-text);font-size:.75rem;text-decoration:none}#buildship-chat-widget__branding>span{color:var(--buildship-chat-widget-primary-color-text)}#buildship-chat-widget__body{display:flex;flex-direction:column;height:calc(100% - var(--buildship-chat-widget-header-height));padding:1rem;position:relative;width:100%}#buildship-chat-