aptolix_chatbot 1.0.25 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===n&&s.firstChild?s.insertBefore(r,s.firstChild):s.appendChild(r),r.styleSheet?r.styleSheet.cssText=e:r.appendChild(document.createTextNode(e))}}('.aptolix-chat-window{box-sizing:border-box;display:flex;flex-direction:column;font-family:Inter,sans-serif;height:100%;margin:0;max-height:100%;max-width:100%;min-height:0;min-width:0;overflow:hidden;width:100%}[id^=aptolix-chat-header]{align-items:center;border-bottom-style:solid;border-bottom-width:2px;color:#fff;display:flex;font-size:1.15rem;font-weight:200;justify-content:space-between;padding:10px 13px}.aptolix-header-title{align-items:center;display:flex;flex:1;flex-direction:row;gap:12px;justify-content:flex-start;min-width:0}.aptolix-company-logo-wrapper{align-items:center;display:flex;flex-shrink:0}.aptolix-bot-name{align-items:center;display:flex;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;font-size:1rem;font-weight:600;letter-spacing:.01em;line-height:1.2;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.aptolix-header-subtitle{color:#ede9fe;font-size:.95rem;font-weight:400;margin-top:2px}.aptolix-header-actions{align-items:center;display:flex;gap:6px;margin-top:0;position:relative}.aptolix-menu-dropdown{background:#fff;border:1px solid rgba(0,0,0,.08);border-radius:6px;box-shadow:0 2px 8px rgba(0,0,0,.15);display:none;flex-direction:column;gap:0;min-width:120px;overflow:hidden;padding:3px 0;position:absolute;right:0;top:calc(100% + 6px);z-index:1000}.aptolix-menu-dropdown.show{display:flex}.aptolix-menu-item{align-items:center;background:transparent;border:none;color:#4b5563;cursor:pointer;direction:ltr;display:flex;gap:7px;justify-content:flex-start!important;padding:6px 10px;text-align:left!important;transition:background-color .1s ease;white-space:nowrap;width:100%}.aptolix-menu-item:hover{background-color:#f9fafb;color:#1f2937}.aptolix-menu-icon{align-items:center;display:inline-flex;flex-shrink:0;font-size:14px!important;justify-content:flex-start!important;line-height:1;text-align:left!important;width:14px}.aptolix-menu-text{flex:1;font-size:12px!important;font-weight:400;line-height:1.3;text-align:left!important}[id^=aptolix-chat-header] button{align-items:center;background:transparent;border:none;border-radius:6px;color:#fff;cursor:pointer;display:flex;font-size:22px;justify-content:center;min-height:20px;min-width:20px;transition:all .2s}[id^=aptolix-chat-header] button:hover{background:hsla(0,0%,100%,.15);transform:scale(1.05)}[id^=aptolix-chat-header] button:active{background:hsla(0,0%,100%,.25);transform:scale(.95)}.aptolix-header-flex{align-items:center;display:flex;justify-content:space-between;width:100%}[id^=aptolix-chat-messages]{display:flex;flex:1 1 auto;flex-direction:column;gap:10px;min-height:120px;overflow-y:auto;padding:18px 16px 16px}.aptolix-footer{align-items:center;background:transparent;display:flex;gap:10px;justify-content:center;min-height:36px;padding:0 8px}.aptolix-footer-separator{color:#d1d5db;font-size:.75rem;opacity:0;transition:opacity .4s ease .1s;user-select:none}.aptolix-footer-separator.show{opacity:1}.aptolix-powered-by{background:transparent;flex:0 0 auto;font-size:.75rem;font-weight:500;letter-spacing:.01em;padding:8px 0;text-align:center;transition:all .3s ease;white-space:nowrap}.aptolix-powered-by .aptolix-link{font-family:inherit;font-weight:600;text-decoration:underline}.aptolix-rating{align-items:center;color:#6b7280;display:flex;flex:0 0 auto;font-size:.75rem;gap:6px;max-width:0;opacity:0;overflow:hidden;transition:max-width .4s ease,opacity .4s ease,visibility .4s ease;visibility:hidden}.aptolix-rating.show{max-width:200px;opacity:1;visibility:visible}.aptolix-rating-label{font-size:.75rem;font-weight:500;white-space:nowrap}.aptolix-stars{align-items:center;display:flex;gap:2px}.star{color:#fbbf24;cursor:pointer;font-size:1.1rem;line-height:1;transition:transform .1s ease;user-select:none}.star:hover{transform:scale(1.1)}[id^=aptolix-chat-input]{align-items:center;background:#fff;border-top-style:solid;border-top-width:2px;display:flex;gap:8px;min-height:56px;padding:5px 10px}[id^=aptolix-chat-input] input{border:1.5px solid;border-radius:10px;flex:1 1 auto;font-size:1rem;min-width:0;padding:10px 14px;transition:border .2s}[id^=aptolix-chat-input] input:focus{outline:none}[id^=aptolix-chat-input] button{border:none;border-radius:10px;box-shadow:0 2px 8px rgba(0,0,0,.1);cursor:pointer;flex-shrink:0;font-size:1rem;font-weight:600;padding:8px 18px;transition:background .2s,box-shadow .2s}[id^=aptolix-chat-input] button:hover{box-shadow:0 4px 16px rgba(0,0,0,.15)}[id^=aptolix-chat-input] button:not(:first-child){background:rgba(167,139,250,.12);border-radius:8px;box-shadow:none;color:#9333ea;font-size:1.1rem;font-weight:500;padding:8px 12px}[id^=aptolix-chat-input] button:not(:first-child):hover{background:rgba(167,139,250,.22);color:#4b5563}[id^=aptolix-chat-inputbox]{border:1px solid;border-radius:4px;box-sizing:border-box;font-family:inherit;font-size:1rem;max-height:130px;min-height:42px;outline:none;overflow-y:auto;padding:6px 12px;resize:none;transition:border-color .2s;width:100%}.aptolix-messages-wrapper{display:flex;flex-direction:column;gap:10px;width:100%}.aptolix-messages-wrapper .message{align-items:flex-end;display:flex;font-family:Inter,sans-serif;gap:4px;margin-bottom:0;max-width:100%}.aptolix-messages-wrapper .message.user{align-self:flex-end;flex-direction:row-reverse}.aptolix-messages-wrapper .message.bot{align-self:flex-start;flex-direction:row}.aptolix-messages-wrapper .message-avatar{cursor:pointer;flex-shrink:0;height:16px;opacity:.7;position:relative;transition:opacity .2s;width:16px}.aptolix-messages-wrapper .message-avatar:hover{opacity:1}.aptolix-messages-wrapper .message-avatar img,.aptolix-messages-wrapper .message-avatar svg{border-radius:50%;height:16px;width:16px}.aptolix-messages-wrapper .message-sender{background:rgba(0,0,0,.8);border-radius:4px;bottom:100%;color:#fff;font-size:.75rem;font-weight:500;left:0;margin-bottom:4px;opacity:0;padding:4px 8px;pointer-events:none;position:absolute;transition:opacity .2s;white-space:nowrap;z-index:1000}.aptolix-messages-wrapper .message-avatar:hover .message-sender{opacity:1}.aptolix-messages-wrapper .message.user .message-sender{left:auto;right:0}.aptolix-messages-wrapper .message-content{align-items:flex-start;display:flex;flex-direction:column;gap:0;justify-content:flex-start;max-width:88%;min-width:0}.aptolix-messages-wrapper .message.user .message-content{align-items:flex-end}.aptolix-messages-wrapper .message-text{border-radius:14px;font-weight:500;line-height:1.5;margin-bottom:0;padding:8px 14px;word-break:break-word}.aptolix-messages-wrapper .message.user .message-text{border-radius:14px 14px 4px 14px;box-shadow:0 2px 8px rgba(167,139,250,.1)}.aptolix-messages-wrapper .message.bot .message-text{border-radius:14px 14px 14px 4px;box-shadow:0 2px 8px rgba(167,139,250,.08);margin-bottom:0}.aptolix-messages-wrapper .message-timestamp{align-self:flex-start;background:none;color:#9ca3af;font-size:.7rem;line-height:1.2;margin-top:2px;padding:0 8px;position:relative;z-index:1}.aptolix-messages-wrapper .message.user .message-timestamp{align-self:flex-end}.aptolix-messages-wrapper .message-rating{align-items:center;display:flex;margin-top:4px;padding:0 8px}.aptolix-messages-wrapper .message-rating .rating-stars{color:#fbbf24;font-size:.85rem;letter-spacing:1px}.aptolix-messages-wrapper .message-text a{color:inherit;text-decoration:underline;transition:opacity .2s;word-break:break-word}.aptolix-messages-wrapper .message-text a:hover{opacity:.8}.aptolix-messages-wrapper .message-text b,.aptolix-messages-wrapper .message-text strong{font-weight:700}.aptolix-messages-wrapper .message-text em,.aptolix-messages-wrapper .message-text i{font-style:italic}.aptolix-messages-wrapper .message-text h1,.aptolix-messages-wrapper .message-text h2,.aptolix-messages-wrapper .message-text h3{font-size:1.3rem;font-weight:600;line-height:1.3;margin:14px 0 8px}.aptolix-messages-wrapper .message-text h1:first-child,.aptolix-messages-wrapper .message-text h2:first-child,.aptolix-messages-wrapper .message-text h3:first-child{margin-top:0}.aptolix-messages-wrapper .message-text h2{font-size:1.15rem}.aptolix-messages-wrapper .message-text h3{font-size:1.05rem}.aptolix-messages-wrapper .message-text p{line-height:1.6;margin:8px 0}.aptolix-messages-wrapper .message-text p:first-child{margin-top:0}.aptolix-messages-wrapper .message-text p:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text ol,.aptolix-messages-wrapper .message-text ul{line-height:1.6;margin:8px 0;padding-left:0}.aptolix-messages-wrapper .message-text ol:first-child,.aptolix-messages-wrapper .message-text ul:first-child{margin-top:0}.aptolix-messages-wrapper .message-text ol:last-child,.aptolix-messages-wrapper .message-text ul:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text ul{list-style:none}.aptolix-messages-wrapper .message-text ol{list-style:decimal;padding-left:1.5em}.aptolix-messages-wrapper .message-text ul li{margin-bottom:6px;padding-left:1.5em;position:relative}.aptolix-messages-wrapper .message-text ul li:before{background:currentColor;border-radius:50%;content:"";height:.4em;left:.4em;opacity:.7;position:absolute;top:.65em;width:.4em}.aptolix-messages-wrapper .message-text ol li{margin-bottom:6px;padding-left:.3em}.aptolix-messages-wrapper .message-text li:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text blockquote{background:rgba(0,0,0,.03);border-left:3px solid;border-radius:0 6px 6px 0;font-style:italic;margin:10px 0;opacity:.8;padding:8px 12px}.aptolix-messages-wrapper .message-text blockquote:first-child{margin-top:0}.aptolix-messages-wrapper .message-text blockquote:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text code{background:rgba(0,0,0,.08);border-radius:4px;color:inherit;font-family:Fira Mono,Consolas,Monaco,monospace;font-size:.9em;font-weight:500;padding:2px 6px}.aptolix-messages-wrapper .message-text pre{background:rgba(0,0,0,.05);border:1px solid rgba(0,0,0,.1);border-radius:6px;margin:10px 0;overflow-x:auto;padding:12px}.aptolix-messages-wrapper .message-text pre:first-child{margin-top:0}.aptolix-messages-wrapper .message-text pre:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text pre code{background:transparent;border-radius:0;display:block;font-size:.85em;line-height:1.5;padding:0}.aptolix-messages-wrapper .message-text hr{border:none;border-top:1px solid rgba(0,0,0,.1);margin:12px 0}.aptolix-messages-wrapper .message-text table{border-collapse:collapse;margin:10px 0;width:100%}.aptolix-messages-wrapper .message-text table td,.aptolix-messages-wrapper .message-text table th{border:1px solid rgba(0,0,0,.1);padding:6px 10px;text-align:left}.aptolix-messages-wrapper .message-text table th{background:rgba(0,0,0,.05);font-weight:600}.aptolix-messages-wrapper .typing-dots span{animation:blink 1.2s infinite;font-size:1.5em;margin-right:2px;opacity:.5}.aptolix-messages-wrapper .typing-dots span:nth-child(2){animation-delay:.2s}.aptolix-messages-wrapper .typing-dots span:nth-child(3){animation-delay:.4s}@keyframes blink{0%,to{opacity:.2}50%{opacity:1}}.aptolix-chat-bubble{align-items:center;background:#9333ea;border-radius:50%;bottom:32px;box-shadow:0 6px 24px rgba(167,139,250,.18);color:#fff;cursor:pointer;display:flex;font-size:2rem;height:56px;justify-content:center;position:fixed;right:32px;transition:background .2s,box-shadow .2s;width:56px;z-index:9999}.aptolix-chat-bubble:hover{background:#7c3aed;box-shadow:0 8px 32px rgba(124,62,237,.28)}.aptolix-chat-window.bubble-mode{border-radius:16px;border-style:solid;border-width:2.5px;display:flex;flex-direction:column;height:100%;overflow:hidden}.aptolix-chat-window.section-mode{border-radius:18px;border-style:solid;border-width:2.5px;box-sizing:border-box!important;display:flex!important;flex-direction:column;height:100%;max-height:100%;max-width:100%;overflow:hidden;position:static!important;width:100%}.aptolix-chat-window.section-mode [id^=aptolix-chat-messages]{background:#f6f3ff;flex:1 1 auto;min-height:0;overflow-y:auto;padding:20px 18px 18px}.aptolix-chat-window.section-mode [id^=aptolix-chat-header]{background:#9333ea;color:#fff}.aptolix-chat-window.section-mode [id^=aptolix-chat-close],.aptolix-chat-window.section-mode [id^=aptolix-chat-expand],.aptolix-chat-window.section-mode~.aptolix-chat-bubble{display:none!important}@media (max-width:600px){[id^=aptolix-chat-header]{font-size:1rem;padding:10px 8px}[id^=aptolix-chat-messages]{padding:12px 8px}[id^=aptolix-chat-input]{padding:8px}.aptolix-chat-window.section-mode{border-radius:12px;border-width:1px}}@media (max-width:480px){.aptolix-chat-bubble{bottom:24px;height:52px;right:24px;width:52px}}.aptolix-retry-btn{background:#ede9fe;border:none;border-radius:6px;color:#7c3aed;cursor:pointer;font-weight:600;margin-top:8px;padding:4px 12px}.aptolix-retry-btn:hover{background:#d8b4fe}.aptolix-hint-bubble{background:#fff;border-radius:8px;bottom:110px;box-shadow:0 2px 8px rgba(0,0,0,.15);color:#333;font-size:1em;max-width:320px;min-width:180px;padding:16px 40px 16px 16px;pointer-events:auto;position:fixed;right:40px;z-index:9999}.aptolix-hint-bubble:after{border-left:10px solid transparent;border-right:10px solid transparent;border-top:12px solid #fff;bottom:-12px;content:"";height:0;position:absolute;right:28px;width:0}');class e{constructor(e=null){this.chatbotId=e,this.keys={config:"aptolix_chatbot_config",state:"aptolix_chatbot_state"}}_getState(e=null){if(!(e=e||this.chatbotId))return null;try{const t=`${this.keys.state}_${e}`,n=localStorage.getItem(t);return n?JSON.parse(n):null}catch(e){return null}}_saveState(e,t){if("object"==typeof e&&void 0===t&&(t=e,e=this.chatbotId),e)try{const n=`${this.keys.state}_${e}`;t.timestamp=Date.now(),t.version="1.0.24",localStorage.setItem(n,JSON.stringify(t))}catch(e){}}_isToday(e){const t=new Date,n=new Date(e);return t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate()}_getTodayStart(){const e=new Date;return e.setHours(0,0,0,0),e.getTime()}saveConfig(e,t){try{const n=`${this.keys.config}_${e}`,s={config:t,timestamp:Date.now()};localStorage.setItem(n,JSON.stringify(s))}catch(e){}}getConfig(e){try{const t=`${this.keys.config}_${e}`,n=localStorage.getItem(t);if(!n)return null;return JSON.parse(n).config}catch(e){return null}}clearConfig(e){try{const t=`${this.keys.config}_${e}`;localStorage.removeItem(t)}catch(e){}}hasConfig(e){const t=`${this.keys.config}_${e}`;return null!==localStorage.getItem(t)}saveVisitorId(e,t){try{const n=this._getState(e)||{};n.visitorId=t,this._saveState(e,n)}catch(e){}}getVisitorId(e){try{const t=this._getState(e);return t?.visitorId||null}catch(e){return null}}clearVisitorId(e){try{const t=this._getState(e);t&&(delete t.visitorId,this._saveState(e,t))}catch(e){}}hasVisitorId(e){return null!==this.getVisitorId(e)}saveSessionId(e,t){try{const n=this._getState(e)||{};n.sessionId=t,this._saveState(e,n)}catch(e){}}getSessionId(e){try{const t=this._getState(e);return t?.sessionId||null}catch(e){return null}}clearSessionId(e){try{const t=this._getState(e);t&&(delete t.sessionId,this._saveState(e,t))}catch(e){}}hasSessionId(e){return null!==this.getSessionId(e)}saveChatHistory(e,t,n){try{const t=this._getState(e)||{};t.history={messages:n,timestamp:Date.now()},this._saveState(e,t)}catch(e){}}getChatHistory(e,t){try{const n=this._getState(e);if(!n?.history)return null;const{history:s}=n;return n.sessionId!==t?null:this._isToday(s.timestamp)?s.messages:(this.clearChatHistory(e,t),null)}catch(e){return null}}clearChatHistory(e,t){try{const n=this._getState(e);n?.history&&n.sessionId===t&&(delete n.history,this._saveState(e,n))}catch(e){}}hasChatHistory(e,t){return null!==this.getChatHistory(e,t)}setUsageLimitReached(e,t,n){try{const t=this._getState(e)||{};t.usageLimitReached={limitReachedDate:n,timestamp:Date.now()},this._saveState(e,t)}catch(e){}}getUsageLimitReached(e,t){try{const n=this._getState(e);if(!n?.usageLimitReached)return null;const{usageLimitReached:s}=n;let r;r=10!==s.limitReachedDate.length||s.limitReachedDate.includes("T")?new Date(s.limitReachedDate):new Date(s.limitReachedDate+"T23:59:59.999Z");return new Date>r?(this.clearUsageLimitReached(e,t),null):{limitReachedDate:s.limitReachedDate,timestamp:s.timestamp}}catch(e){return null}}clearUsageLimitReached(e,t){try{const t=this._getState(e);t&&(delete t.usageLimitReached,this._saveState(e,t))}catch(e){}}hasUsageLimitReached(e,t){return null!==this.getUsageLimitReached(e,t)}clearAll(e=null,t=null,n=null){if(e=e||this.chatbotId){this.clearConfig(e);try{const t=`${this.keys.state}_${e}`;localStorage.removeItem(t)}catch(e){}}}getConversationHistory(){if(!this.chatbotId)return null;const e=this._getState(this.chatbotId);return e?.history?.messages||null}saveConversationHistory(e){if(!this.chatbotId)return;const t=this._getState(this.chatbotId)||{};t.history={messages:e,timestamp:Date.now()},this._saveState(this.chatbotId,t)}clearConversationHistory(){if(!this.chatbotId)return;const e=this._getState(this.chatbotId);e?.history&&(delete e.history,this._saveState(this.chatbotId,e))}getRating(e){if(!this.chatbotId)return null;const t=this._getState(this.chatbotId);return t?.ratings?.[e]||null}saveRating(e,t){if(!this.chatbotId)return;const n=this._getState(this.chatbotId)||{};n.ratings||(n.ratings={}),n.ratings[e]=t,this._saveState(this.chatbotId,n)}}function t(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var n={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function s(e){n=e}var r={exec:()=>null};function a(e,t=""){let n="string"==typeof e?e:e.source,s={replace:(e,t)=>{let r="string"==typeof t?t:t.source;return r=r.replace(i.caret,"$1"),n=n.replace(e,r),s},getRegex:()=>new RegExp(n,t)};return s}var i={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[\t ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},o=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,l=/(?:[*+-]|\d{1,9}[.)])/,p=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,c=a(p).replace(/bull/g,l).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).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/).replace(/\|table/g,"").getRegex(),h=a(p).replace(/bull/g,l).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).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/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),d=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,u=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,g=a(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",u).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),x=a(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,l).getRegex(),m="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",f=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,b=a("^ {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[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",f).replace("tag",m).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),w=a(d).replace("hr",o).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",m).getRegex(),k={blockquote:a(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",w).getRegex(),code:/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,def:g,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:o,html:b,lheading:c,list:x,newline:/^(?:[ \t]*(?:\n|$))+/,paragraph:w,table:r,text:/^[^\n]+/},y=a("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",o).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\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",m).getRegex(),$={...k,lheading:h,table:y,paragraph:a(d).replace("hr",o).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",y).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",m).getRegex()},v={...k,html:a("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",f).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:r,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:a(d).replace("hr",o).replace("heading"," *#{1,6} *[^\n]").replace("lheading",c).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},S=/^( {2,}|\\)\n(?!\s*$)/,I=/[\p{P}\p{S}]/u,R=/[\s\p{P}\p{S}]/u,T=/[^\s\p{P}\p{S}]/u,_=a(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,R).getRegex(),z=/(?!~)[\p{P}\p{S}]/u,C=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,A=a(C,"u").replace(/punct/g,I).getRegex(),L=a(C,"u").replace(/punct/g,z).getRegex(),E="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",D=a(E,"gu").replace(/notPunctSpace/g,T).replace(/punctSpace/g,R).replace(/punct/g,I).getRegex(),q=a(E,"gu").replace(/notPunctSpace/g,/(?:[^\s\p{P}\p{S}]|~)/u).replace(/punctSpace/g,/(?!~)[\s\p{P}\p{S}]/u).replace(/punct/g,z).getRegex(),P=a("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,T).replace(/punctSpace/g,R).replace(/punct/g,I).getRegex(),B=a(/\\(punct)/,"gu").replace(/punct/g,I).getRegex(),M=a(/^<(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(),H=a(f).replace("(?:--\x3e|$)","--\x3e").getRegex(),O=a("^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",H).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),j=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`[^`]*`|[^\[\]\\`])*?/,N=a(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",j).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Z=a(/^!?\[(label)\]\[(ref)\]/).replace("label",j).replace("ref",u).getRegex(),U=a(/^!?\[(ref)\](?:\[\])?/).replace("ref",u).getRegex(),Q={_backpedal:r,anyPunctuation:B,autolink:M,blockSkip:/\[[^\[\]]*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)|`[^`]*?`|<(?! )[^<>]*?>/g,br:S,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:r,emStrongLDelim:A,emStrongRDelimAst:D,emStrongRDelimUnd:P,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:N,nolink:U,punctuation:_,reflink:Z,reflinkSearch:a("reflink|nolink(?!\\()","g").replace("reflink",Z).replace("nolink",U).getRegex(),tag:O,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:r},W={...Q,link:a(/^!?\[(label)\]\((.*?)\)/).replace("label",j).getRegex(),reflink:a(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",j).getRegex()},G={...Q,emStrongRDelimAst:q,emStrongLDelim:L,url:a(/^((?: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\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.!#$%&'*+\/=?_`{\|}~-]+@)))/},F={...G,br:a(S).replace("{2,}","*").getRegex(),text:a(G.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},X={normal:k,gfm:$,pedantic:v},Y={normal:Q,gfm:G,breaks:F,pedantic:W},V={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},J=e=>V[e];function K(e,t){if(t){if(i.escapeTest.test(e))return e.replace(i.escapeReplace,J)}else if(i.escapeTestNoEncode.test(e))return e.replace(i.escapeReplaceNoEncode,J);return e}function ee(e){try{e=encodeURI(e).replace(i.percentDecode,"%")}catch{return null}return e}function te(e,t){let n=e.replace(i.findPipe,(e,t,n)=>{let s=!1,r=t;for(;--r>=0&&"\\"===n[r];)s=!s;return s?"|":" |"}).split(i.splitPipe),s=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;s<n.length;s++)n[s]=n[s].trim().replace(i.slashPipe,"|");return n}function ne(e,t,n){let s=e.length;if(0===s)return"";let r=0;for(;r<s;){let a=e.charAt(s-r-1);if(a!==t||n){if(a===t||!n)break;r++}else r++}return e.slice(0,s-r)}function se(e,t,n,s,r){let a=t.href,i=t.title||null,o=e[1].replace(r.other.outputLinkReplace,"$1");s.state.inLink=!0;let l={type:"!"===e[0].charAt(0)?"image":"link",raw:n,href:a,title:i,text:o,tokens:s.inlineTokens(o)};return s.state.inLink=!1,l}var re=class{options;rules;lexer;constructor(e){this.options=e||n}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:ne(e,"\n")}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=function(e,t,n){let s=e.match(n.other.indentCodeCompensation);if(null===s)return t;let r=s[1];return t.split("\n").map(e=>{let t=e.match(n.other.beginningSpace);if(null===t)return e;let[s]=t;return s.length>=r.length?e.slice(r.length):e}).join("\n")}(e,t[3]||"",this.rules);return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=ne(e,"#");(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:ne(t[0],"\n")}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=ne(t[0],"\n").split("\n"),n="",s="",r=[];for(;e.length>0;){let t,a=!1,i=[];for(t=0;t<e.length;t++)if(this.rules.other.blockquoteStart.test(e[t]))i.push(e[t]),a=!0;else{if(a)break;i.push(e[t])}e=e.slice(t);let o=i.join("\n"),l=o.replace(this.rules.other.blockquoteSetextReplace,"\n $1").replace(this.rules.other.blockquoteSetextReplace2,"");n=n?`${n}\n${o}`:o,s=s?`${s}\n${l}`:l;let p=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(l,r,!0),this.lexer.state.top=p,0===e.length)break;let c=r.at(-1);if("code"===c?.type)break;if("blockquote"===c?.type){let t=c,a=t.raw+"\n"+e.join("\n"),i=this.blockquote(a);r[r.length-1]=i,n=n.substring(0,n.length-t.raw.length)+i.raw,s=s.substring(0,s.length-t.text.length)+i.text;break}if("list"===c?.type){let t=c,a=t.raw+"\n"+e.join("\n"),i=this.list(a);r[r.length-1]=i,n=n.substring(0,n.length-c.raw.length)+i.raw,s=s.substring(0,s.length-t.raw.length)+i.raw,e=a.substring(r.at(-1).raw.length).split("\n");continue}}return{type:"blockquote",raw:n,tokens:r,text:s}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:!1,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?n:"[*+-]");let a=this.rules.other.listItemRegex(n),i=!1;for(;e;){let n=!1,s="",o="";if(!(t=a.exec(e))||this.rules.block.hr.test(e))break;s=t[0],e=e.substring(s.length);let l=t[2].split("\n",1)[0].replace(this.rules.other.listReplaceTabs,e=>" ".repeat(3*e.length)),p=e.split("\n",1)[0],c=!l.trim(),h=0;if(this.options.pedantic?(h=2,o=l.trimStart()):c?h=t[1].length+1:(h=t[2].search(this.rules.other.nonSpaceChar),h=h>4?1:h,o=l.slice(h),h+=t[1].length),c&&this.rules.other.blankLine.test(p)&&(s+=p+"\n",e=e.substring(p.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(h),n=this.rules.other.hrRegex(h),r=this.rules.other.fencesBeginRegex(h),a=this.rules.other.headingBeginRegex(h),i=this.rules.other.htmlBeginRegex(h);for(;e;){let d,u=e.split("\n",1)[0];if(p=u,this.options.pedantic?(p=p.replace(this.rules.other.listReplaceNesting," "),d=p):d=p.replace(this.rules.other.tabCharGlobal," "),r.test(p)||a.test(p)||i.test(p)||t.test(p)||n.test(p))break;if(d.search(this.rules.other.nonSpaceChar)>=h||!p.trim())o+="\n"+d.slice(h);else{if(c||l.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||r.test(l)||a.test(l)||n.test(l))break;o+="\n"+p}!c&&!p.trim()&&(c=!0),s+=u+"\n",e=e.substring(u.length+1),l=d.slice(h)}}r.loose||(i?r.loose=!0:this.rules.other.doubleBlankLine.test(s)&&(i=!0));let d,u=null;this.options.gfm&&(u=this.rules.other.listIsTask.exec(o),u&&(d="[ ] "!==u[0],o=o.replace(this.rules.other.listReplaceTask,""))),r.items.push({type:"list_item",raw:s,task:!!u,checked:d,loose:!1,text:o,tokens:[]}),r.raw+=s}let o=r.items.at(-1);if(!o)return;o.raw=o.raw.trimEnd(),o.text=o.text.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){let t=r.items[e].tokens.filter(e=>"space"===e.type),n=t.length>0&&t.some(e=>this.rules.other.anyLine.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){let 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){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=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:s}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=te(t[1]),s=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),r=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split("\n"):[],a={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===s.length){for(let e of s)this.rules.other.tableAlignRight.test(e)?a.align.push("right"):this.rules.other.tableAlignCenter.test(e)?a.align.push("center"):this.rules.other.tableAlignLeft.test(e)?a.align.push("left"):a.align.push(null);for(let e=0;e<n.length;e++)a.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:a.align[e]});for(let e of r)a.rows.push(te(e,a.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:a.align[t]})));return a}}lheading(e){let 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){let t=this.rules.block.paragraph.exec(e);if(t){let 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){let 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){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.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){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=ne(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{let e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let s=0;s<e.length;s++)if("\\"===e[s])s++;else if(e[s]===t[0])n++;else if(e[s]===t[1]&&(n--,n<0))return s;return n>0?-2:-1}(t[2],"()");if(-2===e)return;if(e>-1){let 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],s="";if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],s=e[3])}else s=t[3]?t[3].slice(1,-1):"";return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),se(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," ").toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return se(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!(!s||s[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!s[1]&&!s[2]||!n||this.rules.inline.punctuation.exec(n))){let n,r,a=[...s[0]].length-1,i=a,o=0,l="*"===s[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+a);null!=(s=l.exec(t));){if(n=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!n)continue;if(r=[...n].length,s[3]||s[4]){i+=r;continue}if((s[5]||s[6])&&a%3&&!((a+r)%3)){o+=r;continue}if(i-=r,i>0)continue;r=Math.min(r,r+i+o);let t=[...s[0]][0].length,l=e.slice(0,a+s.index+t+r);if(Math.min(a,r)%2){let e=l.slice(1,-1);return{type:"em",raw:l,text:e,tokens:this.lexer.inlineTokens(e)}}let p=l.slice(2,-2);return{type:"strong",raw:l,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal," "),n=this.rules.other.nonSpaceChar.test(e),s=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&s&&(e=e.substring(1,e.length-1)),{type:"codespan",raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){let 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){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=t[1],n="mailto:"+e):(e=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=t[0],n="mailto:"+e;else{let s;do{s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(s!==t[0]);e=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){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:e}}}},ae=class e{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||n,this.options.tokenizer=this.options.tokenizer||new re,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:i,block:X.normal,inline:Y.normal};this.options.pedantic?(t.block=X.pedantic,t.inline=Y.pedantic):this.options.gfm&&(t.block=X.gfm,this.options.breaks?t.inline=Y.breaks:t.inline=Y.gfm),this.tokenizer.rules=t}static get rules(){return{block:X,inline:Y}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(i.carriageReturn,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){for(this.options.pedantic&&(e=e.replace(i.tabCharGlobal," ").replace(i.spaceLine,""));e;){let s;if(this.options.extensions?.block?.some(n=>!!(s=n.call({lexer:this},e,t))&&(e=e.substring(s.raw.length),t.push(s),!0)))continue;if(s=this.tokenizer.space(e)){e=e.substring(s.raw.length);let n=t.at(-1);1===s.raw.length&&void 0!==n?n.raw+="\n":t.push(s);continue}if(s=this.tokenizer.code(e)){e=e.substring(s.raw.length);let n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+s.raw,n.text+="\n"+s.text,this.inlineQueue.at(-1).src=n.text):t.push(s);continue}if(s=this.tokenizer.fences(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.heading(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.hr(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.blockquote(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.list(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.html(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.def(e)){e=e.substring(s.raw.length);let n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+s.raw,n.text+="\n"+s.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[s.tag]||(this.tokens.links[s.tag]={href:s.href,title:s.title},t.push(s));continue}if(s=this.tokenizer.table(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.lheading(e)){e=e.substring(s.raw.length),t.push(s);continue}let r=e;if(this.options.extensions?.startBlock){let t,n=1/0,s=e.slice(1);this.options.extensions.startBlock.forEach(e=>{t=e.call({lexer:this},s),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(r=e.substring(0,n+1))}if(this.state.top&&(s=this.tokenizer.paragraph(r))){let a=t.at(-1);n&&"paragraph"===a?.type?(a.raw+=(a.raw.endsWith("\n")?"":"\n")+s.raw,a.text+="\n"+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):t.push(s),n=r.length!==e.length,e=e.substring(s.raw.length);continue}if(s=this.tokenizer.text(e)){e=e.substring(s.raw.length);let n=t.at(-1);"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+s.raw,n.text+="\n"+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(s);continue}if(e){let 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=e,s=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(s=this.tokenizer.rules.inline.reflinkSearch.exec(n));)e.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(n=n.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(s=this.tokenizer.rules.inline.anyPunctuation.exec(n));)n=n.slice(0,s.index)+"++"+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;null!=(s=this.tokenizer.rules.inline.blockSkip.exec(n));)n=n.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let r=!1,a="";for(;e;){let s;if(r||(a=""),r=!1,this.options.extensions?.inline?.some(n=>!!(s=n.call({lexer:this},e,t))&&(e=e.substring(s.raw.length),t.push(s),!0)))continue;if(s=this.tokenizer.escape(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.tag(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.link(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(s.raw.length);let n=t.at(-1);"text"===s.type&&"text"===n?.type?(n.raw+=s.raw,n.text+=s.text):t.push(s);continue}if(s=this.tokenizer.emStrong(e,n,a)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.codespan(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.br(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.del(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.autolink(e)){e=e.substring(s.raw.length),t.push(s);continue}if(!this.state.inLink&&(s=this.tokenizer.url(e))){e=e.substring(s.raw.length),t.push(s);continue}let i=e;if(this.options.extensions?.startInline){let t,n=1/0,s=e.slice(1);this.options.extensions.startInline.forEach(e=>{t=e.call({lexer:this},s),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(i=e.substring(0,n+1))}if(s=this.tokenizer.inlineText(i)){e=e.substring(s.raw.length),"_"!==s.raw.slice(-1)&&(a=s.raw.slice(-1)),r=!0;let n=t.at(-1);"text"===n?.type?(n.raw+=s.raw,n.text+=s.text):t.push(s);continue}if(e){let t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return t}},ie=class{options;parser;constructor(e){this.options=e||n}space(e){return""}code({text:e,lang:t,escaped:n}){let s=(t||"").match(i.notSpaceStart)?.[0],r=e.replace(i.endingNewline,"")+"\n";return s?'<pre><code class="language-'+K(s)+'">'+(n?r:K(r,!0))+"</code></pre>\n":"<pre><code>"+(n?r:K(r,!0))+"</code></pre>\n"}blockquote({tokens:e}){return`<blockquote>\n${this.parser.parse(e)}</blockquote>\n`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>\n`}hr(e){return"<hr>\n"}list(e){let t=e.ordered,n=e.start,s="";for(let t=0;t<e.items.length;t++){let n=e.items[t];s+=this.listitem(n)}let r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+s+"</"+r+">\n"}listitem(e){let t="";if(e.task){let n=this.checkbox({checked:!!e.checked});e.loose?"paragraph"===e.tokens[0]?.type?(e.tokens[0].text=n+" "+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&"text"===e.tokens[0].tokens[0].type&&(e.tokens[0].tokens[0].text=n+" "+K(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:"text",raw:n+" ",text:n+" ",escaped:!0}):t+=n+" "}return t+=this.parser.parse(e.tokens,!!e.loose),`<li>${t}</li>\n`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>\n`}table(e){let t="",n="";for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let s="";for(let t=0;t<e.rows.length;t++){let r=e.rows[t];n="";for(let e=0;e<r.length;e++)n+=this.tablecell(r[e]);s+=this.tablerow({text:n})}return s&&(s=`<tbody>${s}</tbody>`),"<table>\n<thead>\n"+t+"</thead>\n"+s+"</table>\n"}tablerow({text:e}){return`<tr>\n${e}</tr>\n`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>\n`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${K(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let s=this.parser.parseInline(n),r=ee(e);if(null===r)return s;let a='<a href="'+(e=r)+'"';return t&&(a+=' title="'+K(t)+'"'),a+=">"+s+"</a>",a}image({href:e,title:t,text:n,tokens:s}){s&&(n=this.parser.parseInline(s,this.parser.textRenderer));let r=ee(e);if(null===r)return K(n);let a=`<img src="${e=r}" alt="${n}"`;return t&&(a+=` title="${K(t)}"`),a+=">",a}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:K(e.text)}},oe=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}},le=class e{options;renderer;textRenderer;constructor(e){this.options=e||n,this.options.renderer=this.options.renderer||new ie,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new oe}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e,t=!0){let n="";for(let s=0;s<e.length;s++){let r=e[s];if(this.options.extensions?.renderers?.[r.type]){let e=r,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(e.type)){n+=t||"";continue}}let a=r;switch(a.type){case"space":n+=this.renderer.space(a);continue;case"hr":n+=this.renderer.hr(a);continue;case"heading":n+=this.renderer.heading(a);continue;case"code":n+=this.renderer.code(a);continue;case"table":n+=this.renderer.table(a);continue;case"blockquote":n+=this.renderer.blockquote(a);continue;case"list":n+=this.renderer.list(a);continue;case"html":n+=this.renderer.html(a);continue;case"def":n+=this.renderer.def(a);continue;case"paragraph":n+=this.renderer.paragraph(a);continue;case"text":{let r=a,i=this.renderer.text(r);for(;s+1<e.length&&"text"===e[s+1].type;)r=e[++s],i+="\n"+this.renderer.text(r);n+=t?this.renderer.paragraph({type:"paragraph",raw:i,text:i,tokens:[{type:"text",raw:i,text:i,escaped:!0}]}):i;continue}default:{let e='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}parseInline(e,t=this.renderer){let n="";for(let s=0;s<e.length;s++){let r=e[s];if(this.options.extensions?.renderers?.[r.type]){let 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}}let a=r;switch(a.type){case"escape":case"text":n+=t.text(a);break;case"html":n+=t.html(a);break;case"link":n+=t.link(a);break;case"image":n+=t.image(a);break;case"strong":n+=t.strong(a);break;case"em":n+=t.em(a);break;case"codespan":n+=t.codespan(a);break;case"br":n+=t.br(a);break;case"del":n+=t.del(a);break;default:{let e='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}},pe=class{options;block;constructor(e){this.options=e||n}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}provideLexer(){return this.block?ae.lex:ae.lexInline}provideParser(){return this.block?le.parse:le.parseInline}},ce=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.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=le;Renderer=ie;TextRenderer=oe;Lexer=ae;Tokenizer=re;Hooks=pe;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let s of e)switch(n=n.concat(t.call(this,s)),s.type){case"table":{let e=s;for(let s of e.header)n=n.concat(this.walkTokens(s.tokens,t));for(let s of e.rows)for(let e of s)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{let e=s;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=s;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(s=>{let r=e[s].flat(1/0);n=n.concat(this.walkTokens(r,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let 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){let n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let s=e.renderer.apply(this,t);return!1===s&&(s=n.apply(this,t)),s}: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'");let 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){let t=this.defaults.renderer||new ie(this.defaults);for(let n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if(["options","parser"].includes(n))continue;let s=n,r=e.renderer[s],a=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=a.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new re(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;let s=n,r=e.tokenizer[s],a=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new pe;for(let n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if(["options","block"].includes(n))continue;let s=n,r=e.hooks[s],a=t[s];pe.passThroughHooks.has(n)?t[s]=e=>{if(this.defaults.async)return Promise.resolve(r.call(t,e)).then(e=>a.call(t,e));let n=r.call(t,e);return a.call(t,n)}:t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,s=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(s.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 ae.lex(e,t??this.defaults)}parser(e,t){return le.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let s={...n},r={...this.defaults,...s},a=this.onError(!!r.silent,!!r.async);if(!0===this.defaults.async&&!1===s.async)return a(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||null===t)return a(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof t)return a(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));r.hooks&&(r.hooks.options=r,r.hooks.block=e);let i=r.hooks?r.hooks.provideLexer():e?ae.lex:ae.lexInline,o=r.hooks?r.hooks.provideParser():e?le.parse:le.parseInline;if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(t):t).then(e=>i(e,r)).then(e=>r.hooks?r.hooks.processAllTokens(e):e).then(e=>r.walkTokens?Promise.all(this.walkTokens(e,r.walkTokens)).then(()=>e):e).then(e=>o(e,r)).then(e=>r.hooks?r.hooks.postprocess(e):e).catch(a);try{r.hooks&&(t=r.hooks.preprocess(t));let e=i(t,r);r.hooks&&(e=r.hooks.processAllTokens(e)),r.walkTokens&&this.walkTokens(e,r.walkTokens);let n=o(e,r);return r.hooks&&(n=r.hooks.postprocess(n)),n}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){let e="<p>An error occurred:</p><pre>"+K(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function he(e,t){return ce.parse(e,t)}function de(e,t={}){const{botname:n="AI Assistant",username:s="You",botaccentColor:r="#4a57e2ff",botAvatar:a=ue(),userAvatar:i=ge(),showExactTime:o=!1}=t,l=function(e){const t=e=>{const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null};let n,s,r;if(e.startsWith("#")){const a=t(e);if(!a)return!1;n=a.r,s=a.g,r=a.b}else{if(!e.startsWith("rgb"))return!1;{const t=e.match(/\d+/g);[n,s,r]=t.map(Number)}}return(.299*n+.587*s+.114*r)/255>.5}(r),p=r,c=l?"#1f2937":"#ffffff",h=function(e,t){const n=(e=>{const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null})(e);if(!n)return e;const s=Math.min(255,Math.round(n.r+(255-n.r)*t)),r=Math.min(255,Math.round(n.g+(255-n.g)*t)),a=Math.min(255,Math.round(n.b+(255-n.b)*t));return`#${s.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}`}(r,.85);return`<div class="aptolix-messages-wrapper">${e.map(e=>{const t="user"===e.type,r=t?i:a,l=t?s:n,d=t?p:h,u=t?c:"#4b5563",g="bot"===e.type?he.parse(e.text):e.text,x=o?function(e){const t=new Date(e),n=new Date,s=t.toDateString()===n.toDateString(),r=new Date(n);r.setDate(r.getDate()-1);const a=t.toDateString()===r.toDateString(),i=t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});if(s)return`Today at ${i}`;if(a)return`Yesterday at ${i}`;return`${t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})} at ${i}`}(e.timestamp):function(e){const t=Date.now(),n=Math.floor((t-e)/1e3);if(n<10)return"just now";if(n<60)return`${n} secs ago`;if(n<3600){const e=Math.floor(n/60);return 1===e?"1 min ago":`${e} mins ago`}if(n<86400){const e=Math.floor(n/3600);return 1===e?"1 hour ago":`${e} hours ago`}const s=Math.floor(n/86400);return 1===s?"1 day ago":`${s} days ago`}(e.timestamp);return`\n <div class="message ${e.type}">\n <div class="message-avatar">\n ${r}\n <div class="message-sender">${l}</div>\n </div>\n <div class="message-content">\n <div class="message-text" style="background-color: ${d}; color: ${u};">\n ${g}\n </div>\n <span class="message-timestamp" data-timestamp="${e.timestamp}">${x}</span>\n ${e.rating&&e.rating>0?`\n <div class="message-rating">\n <span class="rating-stars">${"★".repeat(e.rating)}${"☆".repeat(5-e.rating)}</span>\n </div>\n `:""}\n </div>\n </div>\n `}).join("")}</div>`}function ue(){return'<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="20" cy="20" r="18" fill="#9333ea"/>\n <rect x="12" y="14" width="6" height="6" rx="1" fill="#fff"/>\n <rect x="22" y="14" width="6" height="6" rx="1" fill="#fff"/>\n <rect x="13" y="26" width="14" height="4" rx="2" fill="#fff"/>\n </svg>'}function ge(){return'<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="20" cy="20" r="20" fill="#64748b"/>\n <circle cx="20" cy="15" r="6" fill="#fff"/>\n <path d="M 8 35 Q 8 25 20 25 Q 32 25 32 35" fill="#fff"/>\n </svg>'}function xe(e){const t=e=>{const t=e.replace("#","").substring(0,6),n=/^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return n?{r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)}:null},n=(e,n)=>{const s=t(e);if(!s)return e;const r=Math.min(255,Math.round(s.r+(255-s.r)*n)),a=Math.min(255,Math.round(s.g+(255-s.g)*n)),i=Math.min(255,Math.round(s.b+(255-s.b)*n));return`#${r.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`},s=(e,n)=>{const s=t(e);if(!s)return e;const r=Math.max(0,Math.round(s.r*(1-n))),a=Math.max(0,Math.round(s.g*(1-n))),i=Math.max(0,Math.round(s.b*(1-n)));return`#${r.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`},r=(e,n)=>{const s=t(e);return s?`rgba(${s.r}, ${s.g}, ${s.b}, ${n})`:e},a=(e=>{let n,s,r;if(e.startsWith("#")){const a=t(e);if(!a)return!1;n=a.r,s=a.g,r=a.b}else{if(!e.startsWith("rgb"))return!1;{const t=e.match(/\d+/g);[n,s,r]=t.map(Number)}}return(.299*n+.587*s+.114*r)/255>.5})(e);return{primary:e,isLight:a,header:{background:e,text:a?"#1f2937":"#ffffff",button:a?"#374151":"#ffffff",border:n(e,.85)},messages:{userBackground:e,userText:a?"#1f2937":"#ffffff",botBackground:n(e,.85),botText:"#4b5563",link:s(e,.1),timestamp:"#9ca3af"},window:{background:n(e,.95),border:a?s(e,.2):n(e,.3),shadow:r(e,.15)},input:{background:"#ffffff",border:n(e,.85),text:"#1f2937",placeholder:"#9ca3af",buttonBackground:e,buttonText:a?"#1f2937":"#ffffff"},footer:{text:a?s(e,.3):n(e,.2),link:s(e,.1)},bubble:{background:e,icon:a?"#1f2937":"#ffffff"},hint:{background:"#ffffff",text:"#1f2937",border:n(e,.85),closeButton:e},menu:{background:"#ffffff",text:"#1f2937",hover:n(e,.9),border:"#e5e7eb"},rating:{star:"#fbbf24",text:"#6b7280"},utils:{lighten:n,darken:s,addAlpha:r,hexToRgb:t}}}he.options=he.setOptions=function(e){return ce.setOptions(e),he.defaults=ce.defaults,s(he.defaults),he},he.getDefaults=t,he.defaults=n,he.use=function(...e){return ce.use(...e),he.defaults=ce.defaults,s(he.defaults),he},he.walkTokens=function(e,t){return ce.walkTokens(e,t)},he.parseInline=ce.parseInline,he.Parser=le,he.parser=le.parse,he.Renderer=ie,he.TextRenderer=oe,he.Lexer=ae,he.lexer=ae.lex,he.Tokenizer=re,he.Hooks=pe,he.parse=he,he.options,he.setOptions,he.use,he.walkTokens,he.parseInline,le.parse,ae.lex;const me=window.self!==window.top;let fe=!1,be=null,we=null,ke=null,ye=null,$e=[],ve=null,Se=null;const Ie="APTOLIX_INIT",Re="APTOLIX_SHOW",Te="APTOLIX_READY",_e="APTOLIX_HEIGHT_CHANGE",ze="APTOLIX_CLOSE_REQUESTED";function Ce(e,t={}){me&&window.parent&&window.parent.postMessage({type:e,payload:t,source:"aptolix-chatbot-iframe"},"*")}async function Ae(t,n){if(!fe)return be=t,Se=n||be.apiHost,we=be.conversationId||`${be.chatbotId}-${Date.now()}`,ve=new e(be.chatbotId),ke=ve.getVisitorId(be.chatbotId),ye=ve.getSessionId(be.chatbotId),function(){const e=xe(be.botaccentColor),t=be.chatbotId;let n="";if(be.companyLogo){n=/^https?:\/\//.test(be.companyLogo)?`<img src="${be.companyLogo}" alt="Company Logo" class="aptolix-company-logo" style="max-width:40px;max-height:40px;" />`:be.companyLogo}const s=encodeURIComponent(window.location.hostname),r=encodeURIComponent("widget"),a=encodeURIComponent("refback"),i=`https://aptolix.com?utm_source=${s}&utm_medium=${r}&utm_campaign=${a}`,o=me&&window.__parentHostname__?window.__parentHostname__:window.location.hostname,l="localhost"===o||"127.0.0.1"===o||o.startsWith("192.168.")||o.endsWith(".local")?'<span style="background: #ef4444; color: white; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; margin-left: 8px; letter-spacing: 0.5px;">LOCAL</span>':"",p=me?"":`box-shadow: 0 4px 20px ${e.window.shadow};`,c=`\n <div id="aptolix-chat-window-${t}" class="aptolix-chat-window ${me?"bubble-mode":"section-mode"}" style="background-color: ${e.window.background}; border-color: ${e.window.border}; ${p}">\n <div id="aptolix-chat-header-${t}" style="background-color: ${be.botaccentColor}; color: ${e.header.text}; border-bottom: 2px solid ${e.header.border};">\n <div class="aptolix-header-flex">\n <div class="aptolix-header-title">\n ${n?`<div class="aptolix-company-logo-wrapper">${n}</div>`:""}\n <strong class="aptolix-bot-name">${be.botname}${l}</strong>\n </div>\n <div class="aptolix-header-actions">\n ${be.allowReset||be.allowDownloadTranscript?`<button id="aptolix-chat-menu-${t}" title="More options" aria-label="More options" style="color: ${e.header.button};">⋮</button>`:""}\n ${be.allowExpandChatWindow?`<button id="aptolix-chat-expand-${t}" title="Expand/Collapse" aria-label="Expand/Collapse" style="color: ${e.header.button};">\n <span id="aptolix-chat-expand-icon-${t}">⤢</span>\n </button>`:""}\n <button id="aptolix-chat-close-${t}" title="Close chat" aria-label="Close chat" style="color: ${e.header.button};">×</button>\n ${be.allowReset||be.allowDownloadTranscript?`<div id="aptolix-chat-menu-dropdown-${t}" class="aptolix-menu-dropdown" style="background-color: ${e.menu.background}; border-color: ${e.menu.border}; border: 1px solid ${e.menu.border};">\n ${be.allowReset?`<button id="aptolix-chat-reset-${t}" class="aptolix-menu-item" title="Reset chat" aria-label="Reset chat" style="background-color: ${e.menu.background}; color: ${e.menu.text};">\n <span class="aptolix-menu-icon">⟲</span>\n <span class="aptolix-menu-text">Reset Chat</span>\n </button>`:""}\n ${be.allowDownloadTranscript?`<button id="aptolix-chat-download-${t}" class="aptolix-menu-item" title="Download chat" aria-label="Download chat" style="background-color: ${e.menu.background}; color: ${e.menu.text};">\n <span class="aptolix-menu-icon">⤓</span>\n <span class="aptolix-menu-text">Download Chat</span>\n </button>`:""}\n </div>`:""}\n </div>\n </div>\n </div>\n <div id="aptolix-chat-messages-${t}" style="background-color: ${e.window.background}; position: relative;">\n </div>\n <div id="aptolix-chat-input-${t}" style="border-top: 2px solid ${e.input.border};">\n <textarea id="aptolix-chat-inputbox-${t}" rows="1" placeholder="Type your message..." style="resize:none; border-color: ${e.input.border}; background-color: ${e.window.background};"></textarea>\n <button style="background-color: ${be.botaccentColor}; color: ${e.input.buttonText};">Send</button>\n </div>\n <div class="aptolix-footer">\n <div class="aptolix-powered-by" style="color: ${e.footer.text};">\n Powered by <a href="${i}" target="_blank" rel="noopener" class="aptolix-link" style="color: ${be.botaccentColor};">Aptolix</a>\n </div>\n ${be.allowRating?`<span class="aptolix-footer-separator">|</span>\n <div class="aptolix-rating" id="aptolix-rating-${t}">\n <span class="aptolix-rating-label">Rate this chat:</span>\n <div class="aptolix-stars" id="aptolix-stars-${t}">\n <span class="star" data-rating="1">☆</span>\n <span class="star" data-rating="2">☆</span>\n <span class="star" data-rating="3">☆</span>\n <span class="star" data-rating="4">☆</span>\n <span class="star" data-rating="5">☆</span>\n </div>\n </div>`:""}\n </div>\n </div>\n `;if(me)document.body.innerHTML=c,document.documentElement.style.height="100%",document.documentElement.style.margin="0",document.documentElement.style.padding="0",document.body.style.height="100%",document.body.style.margin="0",document.body.style.padding="0",document.body.style.overflow="hidden",document.body.style.fontFamily="'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";else{let e=document.body;if(be.target){const t="string"==typeof be.target?document.querySelector(be.target):be.target;t&&(e=t)}e.insertAdjacentHTML("beforeend",c)}}(),await async function(){const e=ve.getConversationHistory();e&&e.length>0&&($e=e,function(){const e=document.querySelector(`#aptolix-chat-messages-${be.chatbotId}`);if(!e)return;const t=xe(be.botaccentColor);e.innerHTML=de($e,{botAvatar:be.botAvatar,userAvatar:be.userAvatar,botName:be.botname,userName:be.username||"You",accentColor:be.botaccentColor,userBgColor:t.messages.userBackground,userTextColor:t.messages.userText,botBgColor:t.messages.botBackground,botTextColor:t.messages.botText,timestampColor:t.messages.timestamp,useExactTime:!1}),Be(),Me()}())}(),function(){const e=be.chatbotId,t=xe(be.botaccentColor),n=document.querySelector(`#aptolix-chat-close-${e}`),s=be.allowReset?document.querySelector(`#aptolix-chat-reset-${e}`):null,r=be.allowExpandChatWindow?document.querySelector(`#aptolix-chat-expand-${e}`):null,a=be.allowExpandChatWindow?document.querySelector(`#aptolix-chat-expand-icon-${e}`):null,i=document.querySelector(`#aptolix-chat-inputbox-${e}`),o=document.querySelector(`#aptolix-chat-input-${e} button`);document.querySelector(`#aptolix-chat-messages-${e}`);const l=be.allowDownloadTranscript?document.querySelector(`#aptolix-chat-download-${e}`):null,p=be.allowReset||be.allowDownloadTranscript?document.querySelector(`#aptolix-chat-menu-${e}`):null,c=be.allowReset||be.allowDownloadTranscript?document.querySelector(`#aptolix-chat-menu-dropdown-${e}`):null;n&&n.addEventListener("click",()=>{if(me)Ce(ze);else{const t=document.querySelector(`#aptolix-chat-window-${e}`);t&&(t.style.display="none")}});s&&s.addEventListener("click",async()=>{confirm("Are you sure you want to reset the chat? This will clear all messages.")&&await async function(){$e=[],we=`${be.chatbotId}-${Date.now()}`,ye=null,ve.clearSessionId(be.chatbotId),ve.clearConversationHistory();const e=document.querySelector(`#aptolix-chat-messages-${be.chatbotId}`);e&&(e.innerHTML="");Le(),Me()}(),c&&(c.style.display="none")});if(r&&a){let t=!1;r.addEventListener("click",()=>{t=!t;const n=document.querySelector(`#aptolix-chat-window-${e}`);t?(n.classList.add("expanded"),a.textContent="⤡"):(n.classList.remove("expanded"),a.textContent="⤢"),me&&Ce("APTOLIX_EXPAND_TOGGLE",{isExpanded:t}),Me()})}l&&l.addEventListener("click",()=>{!function(){let e=`Aptolix Chat Transcript - ${be.botname}\n`;e+=`Date: ${(new Date).toLocaleString()}\n`,e+=`${"=".repeat(50)}\n\n`,$e.forEach(t=>{const n=new Date(t.timestamp).toLocaleString(),s="user"===t.type?be.username||"You":be.botname;e+=`[${n}] ${s}:\n${t.text}\n\n`});const t=new Blob([e],{type:"text/plain"}),n=URL.createObjectURL(t),s=document.createElement("a");s.href=n,s.download=`chat-transcript-${Date.now()}.txt`,s.click(),URL.revokeObjectURL(n)}(),c&&(c.style.display="none")});if(p&&c){p.addEventListener("click",e=>{e.stopPropagation();const t="block"===c.style.display;c.style.display=t?"none":"block"}),document.addEventListener("click",()=>{c.style.display="none"});c.querySelectorAll(".aptolix-menu-item").forEach(e=>{e.addEventListener("mouseenter",()=>{e.style.backgroundColor=t.menu.hover}),e.addEventListener("mouseleave",()=>{e.style.backgroundColor=t.menu.background})})}i&&(i.addEventListener("focus",()=>{i.style.borderColor=t.primary}),i.addEventListener("blur",()=>{i.style.borderColor=t.input.border}),i.addEventListener("keydown",e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),De())}),i.addEventListener("input",()=>{i.style.height="auto",i.style.height=i.scrollHeight+"px",Me()}),be.inputCharLimit&&i.setAttribute("maxlength",be.inputCharLimit));o&&o.addEventListener("click",De);if(be.allowRating){document.querySelectorAll(`#aptolix-stars-${e} .star`).forEach(e=>{e.addEventListener("click",()=>{!async function(e){ve.saveRating(we,e),Pe(e);try{await fetch(`${Se}/chatbot/${be.chatbotId}/rating`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chatbot_id:be.chatbotId,visitor_id:ke,session_id:ye,rating:e})})}catch(e){console.error("Failed to submit rating:",e)}}(parseInt(e.getAttribute("data-rating")))}),e.addEventListener("mouseenter",()=>{Pe(parseInt(e.getAttribute("data-rating")))})});const t=document.querySelector(`#aptolix-stars-${e}`);t&&t.addEventListener("mouseleave",()=>{Pe(ve.getRating(we)||0)})}}(),0===$e.length&&Le(),fe=!0,me&&Ce(Te),me&&Me(),be.chatbotId}function Le(){if(!be.greetingMessage)return;const e={text:be.greetingMessage,type:"bot",timestamp:Date.now(),messageId:`greeting-${Date.now()}`};$e.push(e),Ee(e)}function Ee(e){const t=document.querySelector(`#aptolix-chat-messages-${be.chatbotId}`);if(!t)return;const n=xe(be.botaccentColor),s=de([e],{botAvatar:be.botAvatar,userAvatar:be.userAvatar,botName:be.botname,userName:be.username||"You",accentColor:be.botaccentColor,userBgColor:n.messages.userBackground,userTextColor:n.messages.userText,botBgColor:n.messages.botBackground,botTextColor:n.messages.botText,timestampColor:n.messages.timestamp,useExactTime:!1});t.insertAdjacentHTML("beforeend",s),Be(),Me()}async function De(){const e=document.querySelector(`#aptolix-chat-inputbox-${be.chatbotId}`);if(!e)return;const t=e.value.trim();if(!t)return;e.value="",e.style.height="auto";const n={text:t,type:"user",timestamp:Date.now(),messageId:`user-${Date.now()}`};$e.push(n),Ee(n),ve.saveConversationHistory($e),function(){const e=document.querySelector(`#aptolix-chat-messages-${be.chatbotId}`);if(!e)return;const t=xe(be.botaccentColor),n=document.createElement("div");n.id="aptolix-typing-indicator",n.innerHTML=`\n <div class="aptolix-messages-wrapper">\n <div class="message bot typing">\n <div class="message-avatar">\n ${be.botAvatar}\n </div>\n <div class="message-content">\n <div class="message-text" style="background-color: ${t.messages.botBackground}; color: ${t.messages.botText};">\n <span class="typing-dots">\n <span>.</span><span>.</span><span>.</span>\n </span>\n </div>\n </div>\n </div>\n </div>\n `,e.appendChild(n),Be(),Me()}();try{const e=await fetch(`${Se}/chatbot/${be.chatbotId}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:t,chatbot_id:be.chatbotId,visitor_id:ke,session_id:ye})});if(!e.ok)throw new Error(`API error: ${e.status}`);qe({data:await e.json()})}catch(e){qe({error:e.message})}}function qe(e){if(function(){const e=document.getElementById("aptolix-typing-indicator");e&&(e.remove(),Me())}(),e.error){const t={text:`Error: ${e.error}`,type:"bot",timestamp:Date.now(),messageId:`error-${Date.now()}`};return $e.push(t),void Ee(t)}const t=e.data;t.visitor_id&&(ke=t.visitor_id,ve.saveVisitorId(be.chatbotId,ke)),t.session_id&&(ye=t.session_id,ve.saveSessionId(be.chatbotId,ye));const n={text:t.response||t.message||"No response",type:"bot",timestamp:Date.now(),messageId:t.message_id||`bot-${Date.now()}`};$e.push(n),Ee(n),ve.saveConversationHistory($e)}function Pe(e){document.querySelectorAll(`#aptolix-stars-${be.chatbotId} .star`).forEach((t,n)=>{t.textContent=n<e?"★":"☆"})}function Be(){const e=document.querySelector(`#aptolix-chat-messages-${be.chatbotId}`);e&&(e.scrollTop=e.scrollHeight)}function Me(){requestAnimationFrame(()=>{const e=document.body.scrollHeight;Ce(_e,{height:e})})}me&&(window.addEventListener("message",e=>{if(e.source!==window.parent)return;const{type:t,payload:n}=e.data;switch(t){case Ie:Ae(n,n.apiHost);break;case Re:setTimeout(()=>Be(),50)}}),Ce(Te));export{Ae as initializeChatbot};
1
+ !function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===n&&s.firstChild?s.insertBefore(r,s.firstChild):s.appendChild(r),r.styleSheet?r.styleSheet.cssText=e:r.appendChild(document.createTextNode(e))}}('.aptolix-chat-window{box-sizing:border-box;display:flex;flex-direction:column;font-family:Inter,sans-serif;height:100%;margin:0;max-height:100%;max-width:100%;min-height:0;min-width:0;overflow:hidden;width:100%}[id^=aptolix-chat-header]{align-items:center;border-bottom-style:solid;border-bottom-width:2px;color:#fff;display:flex;font-size:1.15rem;font-weight:200;justify-content:space-between;padding:10px 13px}.aptolix-header-title{align-items:center;display:flex;flex:1;flex-direction:row;gap:12px;justify-content:flex-start;min-width:0}.aptolix-company-logo-wrapper{align-items:center;display:flex;flex-shrink:0}.aptolix-bot-name{align-items:center;display:flex;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;font-size:1rem;font-weight:600;letter-spacing:.01em;line-height:1.2;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.aptolix-header-subtitle{color:#ede9fe;font-size:.95rem;font-weight:400;margin-top:2px}.aptolix-header-actions{align-items:center;display:flex;gap:6px;margin-top:0;position:relative}.aptolix-menu-dropdown{background:#fff;border:1px solid rgba(0,0,0,.08);border-radius:6px;box-shadow:0 2px 8px rgba(0,0,0,.15);display:none;flex-direction:column;gap:0;min-width:120px;overflow:hidden;padding:3px 0;position:absolute;right:0;top:calc(100% + 6px);z-index:1000}.aptolix-menu-dropdown.show{display:flex}.aptolix-menu-item{align-items:center;background:transparent;border:none;color:#4b5563;cursor:pointer;direction:ltr;display:flex;gap:7px;justify-content:flex-start!important;padding:6px 10px;text-align:left!important;transition:background-color .1s ease;white-space:nowrap;width:100%}.aptolix-menu-item:hover{background-color:#f9fafb;color:#1f2937}.aptolix-menu-icon{align-items:center;display:inline-flex;flex-shrink:0;font-size:14px!important;justify-content:flex-start!important;line-height:1;text-align:left!important;width:14px}.aptolix-menu-text{flex:1;font-size:12px!important;font-weight:400;line-height:1.3;text-align:left!important}[id^=aptolix-chat-header] button{align-items:center;background:transparent;border:none;border-radius:6px;color:#fff;cursor:pointer;display:flex;font-size:22px;justify-content:center;min-height:20px;min-width:20px;transition:all .2s}[id^=aptolix-chat-header] button:hover{background:hsla(0,0%,100%,.15);transform:scale(1.05)}[id^=aptolix-chat-header] button:active{background:hsla(0,0%,100%,.25);transform:scale(.95)}.aptolix-header-flex{align-items:center;display:flex;justify-content:space-between;width:100%}[id^=aptolix-chat-messages]{display:flex;flex:1 1 auto;flex-direction:column;gap:10px;min-height:120px;overflow-y:auto;padding:18px 16px 16px}.aptolix-footer{align-items:center;background:transparent;display:flex;gap:10px;justify-content:center;min-height:36px;padding:0 8px}.aptolix-footer-separator{color:#d1d5db;font-size:.75rem;opacity:0;transition:opacity .4s ease .1s;user-select:none}.aptolix-footer-separator.show{opacity:1}.aptolix-powered-by{background:transparent;flex:0 0 auto;font-size:.75rem;font-weight:500;letter-spacing:.01em;padding:8px 0;text-align:center;transition:all .3s ease;white-space:nowrap}.aptolix-powered-by .aptolix-link{font-family:inherit;font-weight:600;text-decoration:underline}.aptolix-rating{align-items:center;color:#6b7280;display:flex;flex:0 0 auto;font-size:.75rem;gap:6px;max-width:0;opacity:0;overflow:hidden;transition:max-width .4s ease,opacity .4s ease,visibility .4s ease;visibility:hidden}.aptolix-rating.show{max-width:200px;opacity:1;visibility:visible}.aptolix-rating-label{font-size:.75rem;font-weight:500;white-space:nowrap}.aptolix-stars{align-items:center;display:flex;gap:2px}.star{color:#fbbf24;cursor:pointer;font-size:1.1rem;line-height:1;transition:transform .1s ease;user-select:none}.star:hover{transform:scale(1.1)}[id^=aptolix-chat-input]{align-items:center;background:#fff;border-top-style:solid;border-top-width:2px;display:flex;gap:8px;min-height:56px;padding:5px 10px}[id^=aptolix-chat-input] input{border:1.5px solid;border-radius:10px;flex:1 1 auto;font-size:1rem;min-width:0;padding:10px 14px;transition:border .2s}[id^=aptolix-chat-input] input:focus{outline:none}[id^=aptolix-chat-input] button{border:none;border-radius:10px;box-shadow:0 2px 8px rgba(0,0,0,.1);cursor:pointer;flex-shrink:0;font-size:1rem;font-weight:600;padding:8px 18px;transition:background .2s,box-shadow .2s}[id^=aptolix-chat-input] button:hover{box-shadow:0 4px 16px rgba(0,0,0,.15)}[id^=aptolix-chat-input] button:not(:first-child){background:rgba(167,139,250,.12);border-radius:8px;box-shadow:none;color:#9333ea;font-size:1.1rem;font-weight:500;padding:8px 12px}[id^=aptolix-chat-input] button:not(:first-child):hover{background:rgba(167,139,250,.22);color:#4b5563}[id^=aptolix-chat-inputbox]{border:1px solid;border-radius:4px;box-sizing:border-box;font-family:inherit;font-size:1rem;max-height:130px;min-height:42px;outline:none;overflow-y:auto;padding:6px 12px;resize:none;transition:border-color .2s;width:100%}.aptolix-messages-wrapper{display:flex;flex-direction:column;gap:10px;width:100%}.aptolix-messages-wrapper .message{align-items:flex-end;display:flex;font-family:Inter,sans-serif;gap:4px;margin-bottom:0;max-width:100%}.aptolix-messages-wrapper .message.user{align-self:flex-end;flex-direction:row-reverse}.aptolix-messages-wrapper .message.bot{align-self:flex-start;flex-direction:row}.aptolix-messages-wrapper .message-avatar{cursor:pointer;flex-shrink:0;height:16px;opacity:.7;position:relative;transition:opacity .2s;width:16px}.aptolix-messages-wrapper .message-avatar:hover{opacity:1}.aptolix-messages-wrapper .message-avatar img,.aptolix-messages-wrapper .message-avatar svg{border-radius:50%;height:16px;width:16px}.aptolix-messages-wrapper .message-sender{background:rgba(0,0,0,.8);border-radius:4px;bottom:100%;color:#fff;font-size:.75rem;font-weight:500;left:0;margin-bottom:4px;opacity:0;padding:4px 8px;pointer-events:none;position:absolute;transition:opacity .2s;white-space:nowrap;z-index:1000}.aptolix-messages-wrapper .message-avatar:hover .message-sender{opacity:1}.aptolix-messages-wrapper .message.user .message-sender{left:auto;right:0}.aptolix-messages-wrapper .message-content{align-items:flex-start;display:flex;flex-direction:column;gap:0;justify-content:flex-start;max-width:88%;min-width:0}.aptolix-messages-wrapper .message.user .message-content{align-items:flex-end}.aptolix-messages-wrapper .message-text{border-radius:14px;font-weight:500;line-height:1.5;margin-bottom:0;padding:8px 14px;word-break:break-word}.aptolix-messages-wrapper .message.user .message-text{border-radius:14px 14px 4px 14px;box-shadow:0 2px 8px rgba(167,139,250,.1)}.aptolix-messages-wrapper .message.bot .message-text{border-radius:14px 14px 14px 4px;box-shadow:0 2px 8px rgba(167,139,250,.08);margin-bottom:0}.aptolix-messages-wrapper .message-timestamp{align-self:flex-start;background:none;color:#9ca3af;font-size:.7rem;line-height:1.2;margin-top:2px;padding:0 8px;position:relative;z-index:1}.aptolix-messages-wrapper .message.user .message-timestamp{align-self:flex-end}.aptolix-messages-wrapper .message-rating{align-items:center;display:flex;margin-top:4px;padding:0 8px}.aptolix-messages-wrapper .message-rating .rating-stars{color:#fbbf24;font-size:.85rem;letter-spacing:1px}.aptolix-messages-wrapper .message-text a{color:inherit;text-decoration:underline;transition:opacity .2s;word-break:break-word}.aptolix-messages-wrapper .message-text a:hover{opacity:.8}.aptolix-messages-wrapper .message-text b,.aptolix-messages-wrapper .message-text strong{font-weight:700}.aptolix-messages-wrapper .message-text em,.aptolix-messages-wrapper .message-text i{font-style:italic}.aptolix-messages-wrapper .message-text h1,.aptolix-messages-wrapper .message-text h2,.aptolix-messages-wrapper .message-text h3{font-size:1.3rem;font-weight:600;line-height:1.3;margin:14px 0 8px}.aptolix-messages-wrapper .message-text h1:first-child,.aptolix-messages-wrapper .message-text h2:first-child,.aptolix-messages-wrapper .message-text h3:first-child{margin-top:0}.aptolix-messages-wrapper .message-text h2{font-size:1.15rem}.aptolix-messages-wrapper .message-text h3{font-size:1.05rem}.aptolix-messages-wrapper .message-text p{line-height:1.6;margin:8px 0}.aptolix-messages-wrapper .message-text p:first-child{margin-top:0}.aptolix-messages-wrapper .message-text p:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text ol,.aptolix-messages-wrapper .message-text ul{line-height:1.6;margin:8px 0;padding-left:0}.aptolix-messages-wrapper .message-text ol:first-child,.aptolix-messages-wrapper .message-text ul:first-child{margin-top:0}.aptolix-messages-wrapper .message-text ol:last-child,.aptolix-messages-wrapper .message-text ul:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text ul{list-style:none}.aptolix-messages-wrapper .message-text ol{list-style:decimal;padding-left:1.5em}.aptolix-messages-wrapper .message-text ul li{margin-bottom:6px;padding-left:1.5em;position:relative}.aptolix-messages-wrapper .message-text ul li:before{background:currentColor;border-radius:50%;content:"";height:.4em;left:.4em;opacity:.7;position:absolute;top:.65em;width:.4em}.aptolix-messages-wrapper .message-text ol li{margin-bottom:6px;padding-left:.3em}.aptolix-messages-wrapper .message-text li:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text blockquote{background:rgba(0,0,0,.03);border-left:3px solid;border-radius:0 6px 6px 0;font-style:italic;margin:10px 0;opacity:.8;padding:8px 12px}.aptolix-messages-wrapper .message-text blockquote:first-child{margin-top:0}.aptolix-messages-wrapper .message-text blockquote:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text code{background:rgba(0,0,0,.08);border-radius:4px;color:inherit;font-family:Fira Mono,Consolas,Monaco,monospace;font-size:.9em;font-weight:500;padding:2px 6px}.aptolix-messages-wrapper .message-text pre{background:rgba(0,0,0,.05);border:1px solid rgba(0,0,0,.1);border-radius:6px;margin:10px 0;overflow-x:auto;padding:12px}.aptolix-messages-wrapper .message-text pre:first-child{margin-top:0}.aptolix-messages-wrapper .message-text pre:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text pre code{background:transparent;border-radius:0;display:block;font-size:.85em;line-height:1.5;padding:0}.aptolix-messages-wrapper .message-text hr{border:none;border-top:1px solid rgba(0,0,0,.1);margin:12px 0}.aptolix-messages-wrapper .message-text table{border-collapse:collapse;margin:10px 0;width:100%}.aptolix-messages-wrapper .message-text table td,.aptolix-messages-wrapper .message-text table th{border:1px solid rgba(0,0,0,.1);padding:6px 10px;text-align:left}.aptolix-messages-wrapper .message-text table th{background:rgba(0,0,0,.05);font-weight:600}.aptolix-messages-wrapper .typing-dots span{animation:blink 1.2s infinite;font-size:1.5em;margin-right:2px;opacity:.5}.aptolix-messages-wrapper .typing-dots span:nth-child(2){animation-delay:.2s}.aptolix-messages-wrapper .typing-dots span:nth-child(3){animation-delay:.4s}@keyframes blink{0%,to{opacity:.2}50%{opacity:1}}.aptolix-chat-bubble{align-items:center;background:#9333ea;border-radius:50%;bottom:32px;box-shadow:0 6px 24px rgba(167,139,250,.18);color:#fff;cursor:pointer;display:flex;font-size:2rem;height:56px;justify-content:center;position:fixed;right:32px;transition:background .2s,box-shadow .2s;width:56px;z-index:9999}.aptolix-chat-bubble:hover{background:#7c3aed;box-shadow:0 8px 32px rgba(124,62,237,.28)}.aptolix-chat-window.bubble-mode{border-radius:16px;border-style:solid;border-width:2.5px;display:flex;flex-direction:column;height:100%;overflow:hidden}.aptolix-chat-window.section-mode{border-radius:18px;border-style:solid;border-width:2.5px;box-sizing:border-box!important;display:flex!important;flex-direction:column;height:100%;max-height:100%;max-width:100%;overflow:hidden;position:static!important;width:100%}.aptolix-chat-window.section-mode [id^=aptolix-chat-messages]{background:#f6f3ff;flex:1 1 auto;min-height:0;overflow-y:auto;padding:20px 18px 18px}.aptolix-chat-window.section-mode [id^=aptolix-chat-header]{background:#9333ea;color:#fff}.aptolix-chat-window.section-mode [id^=aptolix-chat-close],.aptolix-chat-window.section-mode [id^=aptolix-chat-expand],.aptolix-chat-window.section-mode~.aptolix-chat-bubble{display:none!important}@media (max-width:600px){[id^=aptolix-chat-header]{font-size:1rem;padding:10px 8px}[id^=aptolix-chat-messages]{padding:12px 8px}[id^=aptolix-chat-input]{padding:8px}.aptolix-chat-window.section-mode{border-radius:12px;border-width:1px}}@media (max-width:480px){.aptolix-chat-bubble{bottom:24px;height:52px;right:24px;width:52px}}.aptolix-retry-btn{background:#ede9fe;border:none;border-radius:6px;color:#7c3aed;cursor:pointer;font-weight:600;margin-top:8px;padding:4px 12px}.aptolix-retry-btn:hover{background:#d8b4fe}.aptolix-hint-bubble{background:#fff;border-radius:8px;bottom:110px;box-shadow:0 2px 8px rgba(0,0,0,.15);color:#333;font-size:1em;max-width:320px;min-width:180px;padding:16px 40px 16px 16px;pointer-events:auto;position:fixed;right:40px;z-index:9999}.aptolix-hint-bubble:after{border-left:10px solid transparent;border-right:10px solid transparent;border-top:12px solid #fff;bottom:-12px;content:"";height:0;position:absolute;right:28px;width:0}');class e{constructor(e=null){this.chatbotId=e,this.keys={config:"aptolix_chatbot_config",state:"aptolix_chatbot_state"}}_getState(e=null){if(!(e=e||this.chatbotId))return null;try{const t=`${this.keys.state}_${e}`,n=localStorage.getItem(t);return n?JSON.parse(n):null}catch(e){return null}}_saveState(e,t){if("object"==typeof e&&void 0===t&&(t=e,e=this.chatbotId),e)try{const n=`${this.keys.state}_${e}`;t.timestamp=Date.now(),t.version="1.0.26",localStorage.setItem(n,JSON.stringify(t))}catch(e){}}_isToday(e){const t=new Date,n=new Date(e);return t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate()}_getTodayStart(){const e=new Date;return e.setHours(0,0,0,0),e.getTime()}saveConfig(e,t){try{const n=`${this.keys.config}_${e}`,s={config:t,timestamp:Date.now()};localStorage.setItem(n,JSON.stringify(s))}catch(e){}}getConfig(e){try{const t=`${this.keys.config}_${e}`,n=localStorage.getItem(t);if(!n)return null;return JSON.parse(n).config}catch(e){return null}}clearConfig(e){try{const t=`${this.keys.config}_${e}`;localStorage.removeItem(t)}catch(e){}}hasConfig(e){const t=`${this.keys.config}_${e}`;return null!==localStorage.getItem(t)}saveVisitorId(e,t){try{const n=this._getState(e)||{};n.visitorId=t,this._saveState(e,n)}catch(e){}}getVisitorId(e){try{const t=this._getState(e);return t?.visitorId||null}catch(e){return null}}clearVisitorId(e){try{const t=this._getState(e);t&&(delete t.visitorId,this._saveState(e,t))}catch(e){}}hasVisitorId(e){return null!==this.getVisitorId(e)}saveSessionId(e,t){try{const n=this._getState(e)||{};n.sessionId=t,this._saveState(e,n)}catch(e){}}getSessionId(e){try{const t=this._getState(e);return t?.sessionId||null}catch(e){return null}}clearSessionId(e){try{const t=this._getState(e);t&&(delete t.sessionId,this._saveState(e,t))}catch(e){}}hasSessionId(e){return null!==this.getSessionId(e)}saveChatHistory(e,t,n){try{const t=this._getState(e)||{};t.history={messages:n,timestamp:Date.now()},this._saveState(e,t)}catch(e){}}getChatHistory(e,t){try{const n=this._getState(e);if(!n?.history)return null;const{history:s}=n;return n.sessionId!==t?null:this._isToday(s.timestamp)?s.messages:(this.clearChatHistory(e,t),null)}catch(e){return null}}clearChatHistory(e,t){try{const n=this._getState(e);n?.history&&n.sessionId===t&&(delete n.history,this._saveState(e,n))}catch(e){}}hasChatHistory(e,t){return null!==this.getChatHistory(e,t)}setUsageLimitReached(e,t,n){try{const t=this._getState(e)||{};t.usageLimitReached={limitReachedDate:n,timestamp:Date.now()},this._saveState(e,t)}catch(e){}}getUsageLimitReached(e,t){try{const n=this._getState(e);if(!n?.usageLimitReached)return null;const{usageLimitReached:s}=n;let r;r=10!==s.limitReachedDate.length||s.limitReachedDate.includes("T")?new Date(s.limitReachedDate):new Date(s.limitReachedDate+"T23:59:59.999Z");return new Date>r?(this.clearUsageLimitReached(e,t),null):{limitReachedDate:s.limitReachedDate,timestamp:s.timestamp}}catch(e){return null}}clearUsageLimitReached(e,t){try{const t=this._getState(e);t&&(delete t.usageLimitReached,this._saveState(e,t))}catch(e){}}hasUsageLimitReached(e,t){return null!==this.getUsageLimitReached(e,t)}clearAll(e=null,t=null,n=null){if(e=e||this.chatbotId){this.clearConfig(e);try{const t=`${this.keys.state}_${e}`;localStorage.removeItem(t)}catch(e){}}}getConversationHistory(){if(!this.chatbotId)return null;const e=this._getState(this.chatbotId);return e?.history?.messages||null}saveConversationHistory(e){if(!this.chatbotId)return;const t=this._getState(this.chatbotId)||{};t.history={messages:e,timestamp:Date.now()},this._saveState(this.chatbotId,t)}clearConversationHistory(){if(!this.chatbotId)return;const e=this._getState(this.chatbotId);e?.history&&(delete e.history,this._saveState(this.chatbotId,e))}getRating(e){if(!this.chatbotId)return null;const t=this._getState(this.chatbotId);return t?.ratings?.[e]||null}saveRating(e,t){if(!this.chatbotId)return;const n=this._getState(this.chatbotId)||{};n.ratings||(n.ratings={}),n.ratings[e]=t,this._saveState(this.chatbotId,n)}}function t(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var n={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function s(e){n=e}var r={exec:()=>null};function a(e,t=""){let n="string"==typeof e?e:e.source,s={replace:(e,t)=>{let r="string"==typeof t?t:t.source;return r=r.replace(i.caret,"$1"),n=n.replace(e,r),s},getRegex:()=>new RegExp(n,t)};return s}var i={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[\t ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},o=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,l=/(?:[*+-]|\d{1,9}[.)])/,p=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,c=a(p).replace(/bull/g,l).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).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/).replace(/\|table/g,"").getRegex(),h=a(p).replace(/bull/g,l).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).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/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),d=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,u=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,g=a(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",u).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),x=a(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,l).getRegex(),m="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",f=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,b=a("^ {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[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",f).replace("tag",m).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),w=a(d).replace("hr",o).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",m).getRegex(),k={blockquote:a(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",w).getRegex(),code:/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,def:g,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:o,html:b,lheading:c,list:x,newline:/^(?:[ \t]*(?:\n|$))+/,paragraph:w,table:r,text:/^[^\n]+/},y=a("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",o).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\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",m).getRegex(),$={...k,lheading:h,table:y,paragraph:a(d).replace("hr",o).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",y).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",m).getRegex()},v={...k,html:a("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",f).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:r,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:a(d).replace("hr",o).replace("heading"," *#{1,6} *[^\n]").replace("lheading",c).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},S=/^( {2,}|\\)\n(?!\s*$)/,I=/[\p{P}\p{S}]/u,R=/[\s\p{P}\p{S}]/u,T=/[^\s\p{P}\p{S}]/u,_=a(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,R).getRegex(),z=/(?!~)[\p{P}\p{S}]/u,C=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,A=a(C,"u").replace(/punct/g,I).getRegex(),L=a(C,"u").replace(/punct/g,z).getRegex(),E="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",D=a(E,"gu").replace(/notPunctSpace/g,T).replace(/punctSpace/g,R).replace(/punct/g,I).getRegex(),q=a(E,"gu").replace(/notPunctSpace/g,/(?:[^\s\p{P}\p{S}]|~)/u).replace(/punctSpace/g,/(?!~)[\s\p{P}\p{S}]/u).replace(/punct/g,z).getRegex(),P=a("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,T).replace(/punctSpace/g,R).replace(/punct/g,I).getRegex(),B=a(/\\(punct)/,"gu").replace(/punct/g,I).getRegex(),M=a(/^<(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(),H=a(f).replace("(?:--\x3e|$)","--\x3e").getRegex(),O=a("^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",H).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),j=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`[^`]*`|[^\[\]\\`])*?/,N=a(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",j).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Z=a(/^!?\[(label)\]\[(ref)\]/).replace("label",j).replace("ref",u).getRegex(),U=a(/^!?\[(ref)\](?:\[\])?/).replace("ref",u).getRegex(),Q={_backpedal:r,anyPunctuation:B,autolink:M,blockSkip:/\[[^\[\]]*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)|`[^`]*?`|<(?! )[^<>]*?>/g,br:S,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:r,emStrongLDelim:A,emStrongRDelimAst:D,emStrongRDelimUnd:P,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:N,nolink:U,punctuation:_,reflink:Z,reflinkSearch:a("reflink|nolink(?!\\()","g").replace("reflink",Z).replace("nolink",U).getRegex(),tag:O,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:r},W={...Q,link:a(/^!?\[(label)\]\((.*?)\)/).replace("label",j).getRegex(),reflink:a(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",j).getRegex()},G={...Q,emStrongRDelimAst:q,emStrongLDelim:L,url:a(/^((?: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\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.!#$%&'*+\/=?_`{\|}~-]+@)))/},F={...G,br:a(S).replace("{2,}","*").getRegex(),text:a(G.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},X={normal:k,gfm:$,pedantic:v},Y={normal:Q,gfm:G,breaks:F,pedantic:W},V={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},J=e=>V[e];function K(e,t){if(t){if(i.escapeTest.test(e))return e.replace(i.escapeReplace,J)}else if(i.escapeTestNoEncode.test(e))return e.replace(i.escapeReplaceNoEncode,J);return e}function ee(e){try{e=encodeURI(e).replace(i.percentDecode,"%")}catch{return null}return e}function te(e,t){let n=e.replace(i.findPipe,(e,t,n)=>{let s=!1,r=t;for(;--r>=0&&"\\"===n[r];)s=!s;return s?"|":" |"}).split(i.splitPipe),s=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;s<n.length;s++)n[s]=n[s].trim().replace(i.slashPipe,"|");return n}function ne(e,t,n){let s=e.length;if(0===s)return"";let r=0;for(;r<s;){let a=e.charAt(s-r-1);if(a!==t||n){if(a===t||!n)break;r++}else r++}return e.slice(0,s-r)}function se(e,t,n,s,r){let a=t.href,i=t.title||null,o=e[1].replace(r.other.outputLinkReplace,"$1");s.state.inLink=!0;let l={type:"!"===e[0].charAt(0)?"image":"link",raw:n,href:a,title:i,text:o,tokens:s.inlineTokens(o)};return s.state.inLink=!1,l}var re=class{options;rules;lexer;constructor(e){this.options=e||n}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:ne(e,"\n")}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=function(e,t,n){let s=e.match(n.other.indentCodeCompensation);if(null===s)return t;let r=s[1];return t.split("\n").map(e=>{let t=e.match(n.other.beginningSpace);if(null===t)return e;let[s]=t;return s.length>=r.length?e.slice(r.length):e}).join("\n")}(e,t[3]||"",this.rules);return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=ne(e,"#");(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:ne(t[0],"\n")}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=ne(t[0],"\n").split("\n"),n="",s="",r=[];for(;e.length>0;){let t,a=!1,i=[];for(t=0;t<e.length;t++)if(this.rules.other.blockquoteStart.test(e[t]))i.push(e[t]),a=!0;else{if(a)break;i.push(e[t])}e=e.slice(t);let o=i.join("\n"),l=o.replace(this.rules.other.blockquoteSetextReplace,"\n $1").replace(this.rules.other.blockquoteSetextReplace2,"");n=n?`${n}\n${o}`:o,s=s?`${s}\n${l}`:l;let p=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(l,r,!0),this.lexer.state.top=p,0===e.length)break;let c=r.at(-1);if("code"===c?.type)break;if("blockquote"===c?.type){let t=c,a=t.raw+"\n"+e.join("\n"),i=this.blockquote(a);r[r.length-1]=i,n=n.substring(0,n.length-t.raw.length)+i.raw,s=s.substring(0,s.length-t.text.length)+i.text;break}if("list"===c?.type){let t=c,a=t.raw+"\n"+e.join("\n"),i=this.list(a);r[r.length-1]=i,n=n.substring(0,n.length-c.raw.length)+i.raw,s=s.substring(0,s.length-t.raw.length)+i.raw,e=a.substring(r.at(-1).raw.length).split("\n");continue}}return{type:"blockquote",raw:n,tokens:r,text:s}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:!1,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?n:"[*+-]");let a=this.rules.other.listItemRegex(n),i=!1;for(;e;){let n=!1,s="",o="";if(!(t=a.exec(e))||this.rules.block.hr.test(e))break;s=t[0],e=e.substring(s.length);let l=t[2].split("\n",1)[0].replace(this.rules.other.listReplaceTabs,e=>" ".repeat(3*e.length)),p=e.split("\n",1)[0],c=!l.trim(),h=0;if(this.options.pedantic?(h=2,o=l.trimStart()):c?h=t[1].length+1:(h=t[2].search(this.rules.other.nonSpaceChar),h=h>4?1:h,o=l.slice(h),h+=t[1].length),c&&this.rules.other.blankLine.test(p)&&(s+=p+"\n",e=e.substring(p.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(h),n=this.rules.other.hrRegex(h),r=this.rules.other.fencesBeginRegex(h),a=this.rules.other.headingBeginRegex(h),i=this.rules.other.htmlBeginRegex(h);for(;e;){let d,u=e.split("\n",1)[0];if(p=u,this.options.pedantic?(p=p.replace(this.rules.other.listReplaceNesting," "),d=p):d=p.replace(this.rules.other.tabCharGlobal," "),r.test(p)||a.test(p)||i.test(p)||t.test(p)||n.test(p))break;if(d.search(this.rules.other.nonSpaceChar)>=h||!p.trim())o+="\n"+d.slice(h);else{if(c||l.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||r.test(l)||a.test(l)||n.test(l))break;o+="\n"+p}!c&&!p.trim()&&(c=!0),s+=u+"\n",e=e.substring(u.length+1),l=d.slice(h)}}r.loose||(i?r.loose=!0:this.rules.other.doubleBlankLine.test(s)&&(i=!0));let d,u=null;this.options.gfm&&(u=this.rules.other.listIsTask.exec(o),u&&(d="[ ] "!==u[0],o=o.replace(this.rules.other.listReplaceTask,""))),r.items.push({type:"list_item",raw:s,task:!!u,checked:d,loose:!1,text:o,tokens:[]}),r.raw+=s}let o=r.items.at(-1);if(!o)return;o.raw=o.raw.trimEnd(),o.text=o.text.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){let t=r.items[e].tokens.filter(e=>"space"===e.type),n=t.length>0&&t.some(e=>this.rules.other.anyLine.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){let 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){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=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:s}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=te(t[1]),s=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),r=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split("\n"):[],a={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===s.length){for(let e of s)this.rules.other.tableAlignRight.test(e)?a.align.push("right"):this.rules.other.tableAlignCenter.test(e)?a.align.push("center"):this.rules.other.tableAlignLeft.test(e)?a.align.push("left"):a.align.push(null);for(let e=0;e<n.length;e++)a.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:a.align[e]});for(let e of r)a.rows.push(te(e,a.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:a.align[t]})));return a}}lheading(e){let 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){let t=this.rules.block.paragraph.exec(e);if(t){let 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){let 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){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.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){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=ne(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{let e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let s=0;s<e.length;s++)if("\\"===e[s])s++;else if(e[s]===t[0])n++;else if(e[s]===t[1]&&(n--,n<0))return s;return n>0?-2:-1}(t[2],"()");if(-2===e)return;if(e>-1){let 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],s="";if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],s=e[3])}else s=t[3]?t[3].slice(1,-1):"";return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),se(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," ").toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return se(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!(!s||s[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!s[1]&&!s[2]||!n||this.rules.inline.punctuation.exec(n))){let n,r,a=[...s[0]].length-1,i=a,o=0,l="*"===s[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+a);null!=(s=l.exec(t));){if(n=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!n)continue;if(r=[...n].length,s[3]||s[4]){i+=r;continue}if((s[5]||s[6])&&a%3&&!((a+r)%3)){o+=r;continue}if(i-=r,i>0)continue;r=Math.min(r,r+i+o);let t=[...s[0]][0].length,l=e.slice(0,a+s.index+t+r);if(Math.min(a,r)%2){let e=l.slice(1,-1);return{type:"em",raw:l,text:e,tokens:this.lexer.inlineTokens(e)}}let p=l.slice(2,-2);return{type:"strong",raw:l,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal," "),n=this.rules.other.nonSpaceChar.test(e),s=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&s&&(e=e.substring(1,e.length-1)),{type:"codespan",raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){let 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){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=t[1],n="mailto:"+e):(e=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=t[0],n="mailto:"+e;else{let s;do{s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(s!==t[0]);e=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){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:e}}}},ae=class e{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||n,this.options.tokenizer=this.options.tokenizer||new re,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:i,block:X.normal,inline:Y.normal};this.options.pedantic?(t.block=X.pedantic,t.inline=Y.pedantic):this.options.gfm&&(t.block=X.gfm,this.options.breaks?t.inline=Y.breaks:t.inline=Y.gfm),this.tokenizer.rules=t}static get rules(){return{block:X,inline:Y}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(i.carriageReturn,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){for(this.options.pedantic&&(e=e.replace(i.tabCharGlobal," ").replace(i.spaceLine,""));e;){let s;if(this.options.extensions?.block?.some(n=>!!(s=n.call({lexer:this},e,t))&&(e=e.substring(s.raw.length),t.push(s),!0)))continue;if(s=this.tokenizer.space(e)){e=e.substring(s.raw.length);let n=t.at(-1);1===s.raw.length&&void 0!==n?n.raw+="\n":t.push(s);continue}if(s=this.tokenizer.code(e)){e=e.substring(s.raw.length);let n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+s.raw,n.text+="\n"+s.text,this.inlineQueue.at(-1).src=n.text):t.push(s);continue}if(s=this.tokenizer.fences(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.heading(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.hr(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.blockquote(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.list(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.html(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.def(e)){e=e.substring(s.raw.length);let n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+s.raw,n.text+="\n"+s.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[s.tag]||(this.tokens.links[s.tag]={href:s.href,title:s.title},t.push(s));continue}if(s=this.tokenizer.table(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.lheading(e)){e=e.substring(s.raw.length),t.push(s);continue}let r=e;if(this.options.extensions?.startBlock){let t,n=1/0,s=e.slice(1);this.options.extensions.startBlock.forEach(e=>{t=e.call({lexer:this},s),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(r=e.substring(0,n+1))}if(this.state.top&&(s=this.tokenizer.paragraph(r))){let a=t.at(-1);n&&"paragraph"===a?.type?(a.raw+=(a.raw.endsWith("\n")?"":"\n")+s.raw,a.text+="\n"+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):t.push(s),n=r.length!==e.length,e=e.substring(s.raw.length);continue}if(s=this.tokenizer.text(e)){e=e.substring(s.raw.length);let n=t.at(-1);"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+s.raw,n.text+="\n"+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(s);continue}if(e){let 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=e,s=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(s=this.tokenizer.rules.inline.reflinkSearch.exec(n));)e.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(n=n.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(s=this.tokenizer.rules.inline.anyPunctuation.exec(n));)n=n.slice(0,s.index)+"++"+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;null!=(s=this.tokenizer.rules.inline.blockSkip.exec(n));)n=n.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let r=!1,a="";for(;e;){let s;if(r||(a=""),r=!1,this.options.extensions?.inline?.some(n=>!!(s=n.call({lexer:this},e,t))&&(e=e.substring(s.raw.length),t.push(s),!0)))continue;if(s=this.tokenizer.escape(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.tag(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.link(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(s.raw.length);let n=t.at(-1);"text"===s.type&&"text"===n?.type?(n.raw+=s.raw,n.text+=s.text):t.push(s);continue}if(s=this.tokenizer.emStrong(e,n,a)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.codespan(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.br(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.del(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.autolink(e)){e=e.substring(s.raw.length),t.push(s);continue}if(!this.state.inLink&&(s=this.tokenizer.url(e))){e=e.substring(s.raw.length),t.push(s);continue}let i=e;if(this.options.extensions?.startInline){let t,n=1/0,s=e.slice(1);this.options.extensions.startInline.forEach(e=>{t=e.call({lexer:this},s),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(i=e.substring(0,n+1))}if(s=this.tokenizer.inlineText(i)){e=e.substring(s.raw.length),"_"!==s.raw.slice(-1)&&(a=s.raw.slice(-1)),r=!0;let n=t.at(-1);"text"===n?.type?(n.raw+=s.raw,n.text+=s.text):t.push(s);continue}if(e){let t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return t}},ie=class{options;parser;constructor(e){this.options=e||n}space(e){return""}code({text:e,lang:t,escaped:n}){let s=(t||"").match(i.notSpaceStart)?.[0],r=e.replace(i.endingNewline,"")+"\n";return s?'<pre><code class="language-'+K(s)+'">'+(n?r:K(r,!0))+"</code></pre>\n":"<pre><code>"+(n?r:K(r,!0))+"</code></pre>\n"}blockquote({tokens:e}){return`<blockquote>\n${this.parser.parse(e)}</blockquote>\n`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>\n`}hr(e){return"<hr>\n"}list(e){let t=e.ordered,n=e.start,s="";for(let t=0;t<e.items.length;t++){let n=e.items[t];s+=this.listitem(n)}let r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+s+"</"+r+">\n"}listitem(e){let t="";if(e.task){let n=this.checkbox({checked:!!e.checked});e.loose?"paragraph"===e.tokens[0]?.type?(e.tokens[0].text=n+" "+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&"text"===e.tokens[0].tokens[0].type&&(e.tokens[0].tokens[0].text=n+" "+K(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:"text",raw:n+" ",text:n+" ",escaped:!0}):t+=n+" "}return t+=this.parser.parse(e.tokens,!!e.loose),`<li>${t}</li>\n`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>\n`}table(e){let t="",n="";for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let s="";for(let t=0;t<e.rows.length;t++){let r=e.rows[t];n="";for(let e=0;e<r.length;e++)n+=this.tablecell(r[e]);s+=this.tablerow({text:n})}return s&&(s=`<tbody>${s}</tbody>`),"<table>\n<thead>\n"+t+"</thead>\n"+s+"</table>\n"}tablerow({text:e}){return`<tr>\n${e}</tr>\n`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>\n`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${K(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let s=this.parser.parseInline(n),r=ee(e);if(null===r)return s;let a='<a href="'+(e=r)+'"';return t&&(a+=' title="'+K(t)+'"'),a+=">"+s+"</a>",a}image({href:e,title:t,text:n,tokens:s}){s&&(n=this.parser.parseInline(s,this.parser.textRenderer));let r=ee(e);if(null===r)return K(n);let a=`<img src="${e=r}" alt="${n}"`;return t&&(a+=` title="${K(t)}"`),a+=">",a}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:K(e.text)}},oe=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}},le=class e{options;renderer;textRenderer;constructor(e){this.options=e||n,this.options.renderer=this.options.renderer||new ie,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new oe}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e,t=!0){let n="";for(let s=0;s<e.length;s++){let r=e[s];if(this.options.extensions?.renderers?.[r.type]){let e=r,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(e.type)){n+=t||"";continue}}let a=r;switch(a.type){case"space":n+=this.renderer.space(a);continue;case"hr":n+=this.renderer.hr(a);continue;case"heading":n+=this.renderer.heading(a);continue;case"code":n+=this.renderer.code(a);continue;case"table":n+=this.renderer.table(a);continue;case"blockquote":n+=this.renderer.blockquote(a);continue;case"list":n+=this.renderer.list(a);continue;case"html":n+=this.renderer.html(a);continue;case"def":n+=this.renderer.def(a);continue;case"paragraph":n+=this.renderer.paragraph(a);continue;case"text":{let r=a,i=this.renderer.text(r);for(;s+1<e.length&&"text"===e[s+1].type;)r=e[++s],i+="\n"+this.renderer.text(r);n+=t?this.renderer.paragraph({type:"paragraph",raw:i,text:i,tokens:[{type:"text",raw:i,text:i,escaped:!0}]}):i;continue}default:{let e='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}parseInline(e,t=this.renderer){let n="";for(let s=0;s<e.length;s++){let r=e[s];if(this.options.extensions?.renderers?.[r.type]){let 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}}let a=r;switch(a.type){case"escape":case"text":n+=t.text(a);break;case"html":n+=t.html(a);break;case"link":n+=t.link(a);break;case"image":n+=t.image(a);break;case"strong":n+=t.strong(a);break;case"em":n+=t.em(a);break;case"codespan":n+=t.codespan(a);break;case"br":n+=t.br(a);break;case"del":n+=t.del(a);break;default:{let e='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}},pe=class{options;block;constructor(e){this.options=e||n}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}provideLexer(){return this.block?ae.lex:ae.lexInline}provideParser(){return this.block?le.parse:le.parseInline}},ce=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.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=le;Renderer=ie;TextRenderer=oe;Lexer=ae;Tokenizer=re;Hooks=pe;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let s of e)switch(n=n.concat(t.call(this,s)),s.type){case"table":{let e=s;for(let s of e.header)n=n.concat(this.walkTokens(s.tokens,t));for(let s of e.rows)for(let e of s)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{let e=s;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=s;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(s=>{let r=e[s].flat(1/0);n=n.concat(this.walkTokens(r,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let 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){let n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let s=e.renderer.apply(this,t);return!1===s&&(s=n.apply(this,t)),s}: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'");let 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){let t=this.defaults.renderer||new ie(this.defaults);for(let n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if(["options","parser"].includes(n))continue;let s=n,r=e.renderer[s],a=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=a.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new re(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;let s=n,r=e.tokenizer[s],a=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new pe;for(let n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if(["options","block"].includes(n))continue;let s=n,r=e.hooks[s],a=t[s];pe.passThroughHooks.has(n)?t[s]=e=>{if(this.defaults.async)return Promise.resolve(r.call(t,e)).then(e=>a.call(t,e));let n=r.call(t,e);return a.call(t,n)}:t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,s=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(s.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 ae.lex(e,t??this.defaults)}parser(e,t){return le.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let s={...n},r={...this.defaults,...s},a=this.onError(!!r.silent,!!r.async);if(!0===this.defaults.async&&!1===s.async)return a(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||null===t)return a(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof t)return a(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));r.hooks&&(r.hooks.options=r,r.hooks.block=e);let i=r.hooks?r.hooks.provideLexer():e?ae.lex:ae.lexInline,o=r.hooks?r.hooks.provideParser():e?le.parse:le.parseInline;if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(t):t).then(e=>i(e,r)).then(e=>r.hooks?r.hooks.processAllTokens(e):e).then(e=>r.walkTokens?Promise.all(this.walkTokens(e,r.walkTokens)).then(()=>e):e).then(e=>o(e,r)).then(e=>r.hooks?r.hooks.postprocess(e):e).catch(a);try{r.hooks&&(t=r.hooks.preprocess(t));let e=i(t,r);r.hooks&&(e=r.hooks.processAllTokens(e)),r.walkTokens&&this.walkTokens(e,r.walkTokens);let n=o(e,r);return r.hooks&&(n=r.hooks.postprocess(n)),n}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){let e="<p>An error occurred:</p><pre>"+K(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function he(e,t){return ce.parse(e,t)}function de(e,t={}){const{botname:n="AI Assistant",username:s="You",botaccentColor:r="#4a57e2ff",botAvatar:a=ue(),userAvatar:i=ge(),showExactTime:o=!1}=t,l=function(e){const t=e=>{const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null};let n,s,r;if(e.startsWith("#")){const a=t(e);if(!a)return!1;n=a.r,s=a.g,r=a.b}else{if(!e.startsWith("rgb"))return!1;{const t=e.match(/\d+/g);[n,s,r]=t.map(Number)}}return(.299*n+.587*s+.114*r)/255>.5}(r),p=r,c=l?"#1f2937":"#ffffff",h=function(e,t){const n=(e=>{const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null})(e);if(!n)return e;const s=Math.min(255,Math.round(n.r+(255-n.r)*t)),r=Math.min(255,Math.round(n.g+(255-n.g)*t)),a=Math.min(255,Math.round(n.b+(255-n.b)*t));return`#${s.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}`}(r,.85);return`<div class="aptolix-messages-wrapper">${e.map(e=>{const t="user"===e.type,r=t?i:a,l=t?s:n,d=t?p:h,u=t?c:"#4b5563",g="bot"===e.type?he.parse(e.text):e.text,x=o?function(e){const t=new Date(e),n=new Date,s=t.toDateString()===n.toDateString(),r=new Date(n);r.setDate(r.getDate()-1);const a=t.toDateString()===r.toDateString(),i=t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});if(s)return`Today at ${i}`;if(a)return`Yesterday at ${i}`;return`${t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})} at ${i}`}(e.timestamp):function(e){const t=Date.now(),n=Math.floor((t-e)/1e3);if(n<10)return"just now";if(n<60)return`${n} secs ago`;if(n<3600){const e=Math.floor(n/60);return 1===e?"1 min ago":`${e} mins ago`}if(n<86400){const e=Math.floor(n/3600);return 1===e?"1 hour ago":`${e} hours ago`}const s=Math.floor(n/86400);return 1===s?"1 day ago":`${s} days ago`}(e.timestamp);return`\n <div class="message ${e.type}">\n <div class="message-avatar">\n ${r}\n <div class="message-sender">${l}</div>\n </div>\n <div class="message-content">\n <div class="message-text" style="background-color: ${d}; color: ${u};">\n ${g}\n </div>\n <span class="message-timestamp" data-timestamp="${e.timestamp}">${x}</span>\n ${e.rating&&e.rating>0?`\n <div class="message-rating">\n <span class="rating-stars">${"★".repeat(e.rating)}${"☆".repeat(5-e.rating)}</span>\n </div>\n `:""}\n </div>\n </div>\n `}).join("")}</div>`}function ue(){return'<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="20" cy="20" r="18" fill="#9333ea"/>\n <rect x="12" y="14" width="6" height="6" rx="1" fill="#fff"/>\n <rect x="22" y="14" width="6" height="6" rx="1" fill="#fff"/>\n <rect x="13" y="26" width="14" height="4" rx="2" fill="#fff"/>\n </svg>'}function ge(){return'<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="20" cy="20" r="20" fill="#64748b"/>\n <circle cx="20" cy="15" r="6" fill="#fff"/>\n <path d="M 8 35 Q 8 25 20 25 Q 32 25 32 35" fill="#fff"/>\n </svg>'}function xe(e){const t=e=>{const t=e.replace("#","").substring(0,6),n=/^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return n?{r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)}:null},n=(e,n)=>{const s=t(e);if(!s)return e;const r=Math.min(255,Math.round(s.r+(255-s.r)*n)),a=Math.min(255,Math.round(s.g+(255-s.g)*n)),i=Math.min(255,Math.round(s.b+(255-s.b)*n));return`#${r.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`},s=(e,n)=>{const s=t(e);if(!s)return e;const r=Math.max(0,Math.round(s.r*(1-n))),a=Math.max(0,Math.round(s.g*(1-n))),i=Math.max(0,Math.round(s.b*(1-n)));return`#${r.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`},r=(e,n)=>{const s=t(e);return s?`rgba(${s.r}, ${s.g}, ${s.b}, ${n})`:e},a=(e=>{let n,s,r;if(e.startsWith("#")){const a=t(e);if(!a)return!1;n=a.r,s=a.g,r=a.b}else{if(!e.startsWith("rgb"))return!1;{const t=e.match(/\d+/g);[n,s,r]=t.map(Number)}}return(.299*n+.587*s+.114*r)/255>.5})(e);return{primary:e,isLight:a,header:{background:e,text:a?"#1f2937":"#ffffff",button:a?"#374151":"#ffffff",border:n(e,.85)},messages:{userBackground:e,userText:a?"#1f2937":"#ffffff",botBackground:n(e,.85),botText:"#4b5563",link:s(e,.1),timestamp:"#9ca3af"},window:{background:n(e,.95),border:a?s(e,.2):n(e,.3),shadow:r(e,.15)},input:{background:"#ffffff",border:n(e,.85),text:"#1f2937",placeholder:"#9ca3af",buttonBackground:e,buttonText:a?"#1f2937":"#ffffff"},footer:{text:a?s(e,.3):n(e,.2),link:s(e,.1)},bubble:{background:e,icon:a?"#1f2937":"#ffffff"},hint:{background:"#ffffff",text:"#1f2937",border:n(e,.85),closeButton:e},menu:{background:"#ffffff",text:"#1f2937",hover:n(e,.9),border:"#e5e7eb"},rating:{star:"#fbbf24",text:"#6b7280"},utils:{lighten:n,darken:s,addAlpha:r,hexToRgb:t}}}he.options=he.setOptions=function(e){return ce.setOptions(e),he.defaults=ce.defaults,s(he.defaults),he},he.getDefaults=t,he.defaults=n,he.use=function(...e){return ce.use(...e),he.defaults=ce.defaults,s(he.defaults),he},he.walkTokens=function(e,t){return ce.walkTokens(e,t)},he.parseInline=ce.parseInline,he.Parser=le,he.parser=le.parse,he.Renderer=ie,he.TextRenderer=oe,he.Lexer=ae,he.lexer=ae.lex,he.Tokenizer=re,he.Hooks=pe,he.parse=he,he.options,he.setOptions,he.use,he.walkTokens,he.parseInline,le.parse,ae.lex;const me=window.self!==window.top;let fe=!1,be=null,we=null,ke=null,ye=null,$e=[],ve=null,Se=null;const Ie="APTOLIX_INIT",Re="APTOLIX_SHOW",Te="APTOLIX_READY",_e="APTOLIX_HEIGHT_CHANGE",ze="APTOLIX_CLOSE_REQUESTED";function Ce(e,t={}){me&&window.parent&&window.parent.postMessage({type:e,payload:t,source:"aptolix-chatbot-iframe"},"*")}async function Ae(t,n){if(!fe)return be=t,Se=n||be.apiHost,we=be.conversationId||`${be.chatbotId}-${Date.now()}`,ve=new e(be.chatbotId),ke=ve.getVisitorId(be.chatbotId),ye=ve.getSessionId(be.chatbotId),function(){const e=xe(be.botaccentColor),t=be.chatbotId;let n="";if(be.companyLogo){n=/^https?:\/\//.test(be.companyLogo)?`<img src="${be.companyLogo}" alt="Company Logo" class="aptolix-company-logo" style="max-width:40px;max-height:40px;" />`:be.companyLogo}const s=encodeURIComponent(window.location.hostname),r=encodeURIComponent("widget"),a=encodeURIComponent("refback"),i=`https://aptolix.com?utm_source=${s}&utm_medium=${r}&utm_campaign=${a}`,o=me&&window.__parentHostname__?window.__parentHostname__:window.location.hostname,l="localhost"===o||"127.0.0.1"===o||o.startsWith("192.168.")||o.endsWith(".local")?'<span style="background: #ef4444; color: white; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; margin-left: 8px; letter-spacing: 0.5px;">LOCAL</span>':"",p=me?"":`box-shadow: 0 4px 20px ${e.window.shadow};`,c=`\n <div id="aptolix-chat-window-${t}" class="aptolix-chat-window ${me?"bubble-mode":"section-mode"}" style="background-color: ${e.window.background}; border-color: ${e.window.border}; ${p}">\n <div id="aptolix-chat-header-${t}" style="background-color: ${be.botaccentColor}; color: ${e.header.text}; border-bottom: 2px solid ${e.header.border};">\n <div class="aptolix-header-flex">\n <div class="aptolix-header-title">\n ${n?`<div class="aptolix-company-logo-wrapper">${n}</div>`:""}\n <strong class="aptolix-bot-name">${be.botname}${l}</strong>\n </div>\n <div class="aptolix-header-actions">\n ${be.allowReset||be.allowDownloadTranscript?`<button id="aptolix-chat-menu-${t}" title="More options" aria-label="More options" style="color: ${e.header.button};">⋮</button>`:""}\n ${be.allowExpandChatWindow?`<button id="aptolix-chat-expand-${t}" title="Expand/Collapse" aria-label="Expand/Collapse" style="color: ${e.header.button};">\n <span id="aptolix-chat-expand-icon-${t}">⤢</span>\n </button>`:""}\n <button id="aptolix-chat-close-${t}" title="Close chat" aria-label="Close chat" style="color: ${e.header.button};">×</button>\n ${be.allowReset||be.allowDownloadTranscript?`<div id="aptolix-chat-menu-dropdown-${t}" class="aptolix-menu-dropdown" style="background-color: ${e.menu.background}; border-color: ${e.menu.border}; border: 1px solid ${e.menu.border};">\n ${be.allowReset?`<button id="aptolix-chat-reset-${t}" class="aptolix-menu-item" title="Reset chat" aria-label="Reset chat" style="background-color: ${e.menu.background}; color: ${e.menu.text};">\n <span class="aptolix-menu-icon">⟲</span>\n <span class="aptolix-menu-text">Reset Chat</span>\n </button>`:""}\n ${be.allowDownloadTranscript?`<button id="aptolix-chat-download-${t}" class="aptolix-menu-item" title="Download chat" aria-label="Download chat" style="background-color: ${e.menu.background}; color: ${e.menu.text};">\n <span class="aptolix-menu-icon">⤓</span>\n <span class="aptolix-menu-text">Download Chat</span>\n </button>`:""}\n </div>`:""}\n </div>\n </div>\n </div>\n <div id="aptolix-chat-messages-${t}" style="background-color: ${e.window.background}; position: relative;">\n </div>\n <div id="aptolix-chat-input-${t}" style="border-top: 2px solid ${e.input.border};">\n <textarea id="aptolix-chat-inputbox-${t}" rows="1" placeholder="Type your message..." style="resize:none; border-color: ${e.input.border}; background-color: ${e.window.background};"></textarea>\n <button style="background-color: ${be.botaccentColor}; color: ${e.input.buttonText};">Send</button>\n </div>\n <div class="aptolix-footer">\n <div class="aptolix-powered-by" style="color: ${e.footer.text};">\n Powered by <a href="${i}" target="_blank" rel="noopener" class="aptolix-link" style="color: ${be.botaccentColor};">Aptolix</a>\n </div>\n ${be.allowRating?`<span class="aptolix-footer-separator">|</span>\n <div class="aptolix-rating" id="aptolix-rating-${t}">\n <span class="aptolix-rating-label">Rate this chat:</span>\n <div class="aptolix-stars" id="aptolix-stars-${t}">\n <span class="star" data-rating="1">☆</span>\n <span class="star" data-rating="2">☆</span>\n <span class="star" data-rating="3">☆</span>\n <span class="star" data-rating="4">☆</span>\n <span class="star" data-rating="5">☆</span>\n </div>\n </div>`:""}\n </div>\n </div>\n `;if(me)document.body.innerHTML=c,document.documentElement.style.height="100%",document.documentElement.style.margin="0",document.documentElement.style.padding="0",document.body.style.height="100%",document.body.style.margin="0",document.body.style.padding="0",document.body.style.overflow="hidden",document.body.style.fontFamily="'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";else{let e=document.body;if(be.target){const t="string"==typeof be.target?document.querySelector(be.target):be.target;t&&(e=t)}e.insertAdjacentHTML("beforeend",c)}}(),await async function(){const e=ve.getConversationHistory();e&&e.length>0&&($e=e,function(){const e=document.querySelector(`#aptolix-chat-messages-${be.chatbotId}`);if(!e)return;const t=xe(be.botaccentColor);e.innerHTML=de($e,{botAvatar:be.botAvatar,userAvatar:be.userAvatar,botName:be.botname,userName:be.username||"You",accentColor:be.botaccentColor,userBgColor:t.messages.userBackground,userTextColor:t.messages.userText,botBgColor:t.messages.botBackground,botTextColor:t.messages.botText,timestampColor:t.messages.timestamp,useExactTime:!1}),Be(),Me()}())}(),function(){const e=be.chatbotId,t=xe(be.botaccentColor),n=document.querySelector(`#aptolix-chat-close-${e}`),s=be.allowReset?document.querySelector(`#aptolix-chat-reset-${e}`):null,r=be.allowExpandChatWindow?document.querySelector(`#aptolix-chat-expand-${e}`):null,a=be.allowExpandChatWindow?document.querySelector(`#aptolix-chat-expand-icon-${e}`):null,i=document.querySelector(`#aptolix-chat-inputbox-${e}`),o=document.querySelector(`#aptolix-chat-input-${e} button`);document.querySelector(`#aptolix-chat-messages-${e}`);const l=be.allowDownloadTranscript?document.querySelector(`#aptolix-chat-download-${e}`):null,p=be.allowReset||be.allowDownloadTranscript?document.querySelector(`#aptolix-chat-menu-${e}`):null,c=be.allowReset||be.allowDownloadTranscript?document.querySelector(`#aptolix-chat-menu-dropdown-${e}`):null;n&&n.addEventListener("click",()=>{if(me)Ce(ze);else{const t=document.querySelector(`#aptolix-chat-window-${e}`);t&&(t.style.display="none")}});s&&s.addEventListener("click",async()=>{confirm("Are you sure you want to reset the chat? This will clear all messages.")&&await async function(){$e=[],we=`${be.chatbotId}-${Date.now()}`,ye=null,ve.clearSessionId(be.chatbotId),ve.clearConversationHistory();const e=document.querySelector(`#aptolix-chat-messages-${be.chatbotId}`);e&&(e.innerHTML="");Le(),Me()}(),c&&(c.style.display="none")});if(r&&a){let t=!1;r.addEventListener("click",()=>{t=!t;const n=document.querySelector(`#aptolix-chat-window-${e}`);t?(n.classList.add("expanded"),a.textContent="⤡"):(n.classList.remove("expanded"),a.textContent="⤢"),me&&Ce("APTOLIX_EXPAND_TOGGLE",{isExpanded:t}),Me()})}l&&l.addEventListener("click",()=>{!function(){let e=`Aptolix Chat Transcript - ${be.botname}\n`;e+=`Date: ${(new Date).toLocaleString()}\n`,e+=`${"=".repeat(50)}\n\n`,$e.forEach(t=>{const n=new Date(t.timestamp).toLocaleString(),s="user"===t.type?be.username||"You":be.botname;e+=`[${n}] ${s}:\n${t.text}\n\n`});const t=new Blob([e],{type:"text/plain"}),n=URL.createObjectURL(t),s=document.createElement("a");s.href=n,s.download=`chat-transcript-${Date.now()}.txt`,s.click(),URL.revokeObjectURL(n)}(),c&&(c.style.display="none")});if(p&&c){p.addEventListener("click",e=>{e.stopPropagation();const t="block"===c.style.display;c.style.display=t?"none":"block"}),document.addEventListener("click",()=>{c.style.display="none"});c.querySelectorAll(".aptolix-menu-item").forEach(e=>{e.addEventListener("mouseenter",()=>{e.style.backgroundColor=t.menu.hover}),e.addEventListener("mouseleave",()=>{e.style.backgroundColor=t.menu.background})})}i&&(i.addEventListener("focus",()=>{i.style.borderColor=t.primary}),i.addEventListener("blur",()=>{i.style.borderColor=t.input.border}),i.addEventListener("keydown",e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),De())}),i.addEventListener("input",()=>{i.style.height="auto",i.style.height=i.scrollHeight+"px",Me()}),be.inputCharLimit&&i.setAttribute("maxlength",be.inputCharLimit));o&&o.addEventListener("click",De);if(be.allowRating){document.querySelectorAll(`#aptolix-stars-${e} .star`).forEach(e=>{e.addEventListener("click",()=>{!async function(e){ve.saveRating(we,e),Pe(e);try{await fetch(`${Se}/chatbot/${be.chatbotId}/rating`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chatbot_id:be.chatbotId,visitor_id:ke,session_id:ye,rating:e})})}catch(e){console.error("Failed to submit rating:",e)}}(parseInt(e.getAttribute("data-rating")))}),e.addEventListener("mouseenter",()=>{Pe(parseInt(e.getAttribute("data-rating")))})});const t=document.querySelector(`#aptolix-stars-${e}`);t&&t.addEventListener("mouseleave",()=>{Pe(ve.getRating(we)||0)})}}(),0===$e.length&&Le(),fe=!0,me&&Ce(Te),me&&Me(),be.chatbotId}function Le(){if(!be.greetingMessage)return;const e={text:be.greetingMessage,type:"bot",timestamp:Date.now(),messageId:`greeting-${Date.now()}`};$e.push(e),Ee(e)}function Ee(e){const t=document.querySelector(`#aptolix-chat-messages-${be.chatbotId}`);if(!t)return;const n=xe(be.botaccentColor),s=de([e],{botAvatar:be.botAvatar,userAvatar:be.userAvatar,botName:be.botname,userName:be.username||"You",accentColor:be.botaccentColor,userBgColor:n.messages.userBackground,userTextColor:n.messages.userText,botBgColor:n.messages.botBackground,botTextColor:n.messages.botText,timestampColor:n.messages.timestamp,useExactTime:!1});t.insertAdjacentHTML("beforeend",s),Be(),Me()}async function De(){const e=document.querySelector(`#aptolix-chat-inputbox-${be.chatbotId}`);if(!e)return;const t=e.value.trim();if(!t)return;e.value="",e.style.height="auto";const n={text:t,type:"user",timestamp:Date.now(),messageId:`user-${Date.now()}`};$e.push(n),Ee(n),ve.saveConversationHistory($e),function(){const e=document.querySelector(`#aptolix-chat-messages-${be.chatbotId}`);if(!e)return;const t=xe(be.botaccentColor),n=document.createElement("div");n.id="aptolix-typing-indicator",n.innerHTML=`\n <div class="aptolix-messages-wrapper">\n <div class="message bot typing">\n <div class="message-avatar">\n ${be.botAvatar}\n </div>\n <div class="message-content">\n <div class="message-text" style="background-color: ${t.messages.botBackground}; color: ${t.messages.botText};">\n <span class="typing-dots">\n <span>.</span><span>.</span><span>.</span>\n </span>\n </div>\n </div>\n </div>\n </div>\n `,e.appendChild(n),Be(),Me()}();try{const e=await fetch(`${Se}/chatbot/${be.chatbotId}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:t,chatbot_id:be.chatbotId,visitor_id:ke,session_id:ye})});if(!e.ok)throw new Error(`API error: ${e.status}`);qe({data:await e.json()})}catch(e){qe({error:e.message})}}function qe(e){if(function(){const e=document.getElementById("aptolix-typing-indicator");e&&(e.remove(),Me())}(),e.error){const t={text:`Error: ${e.error}`,type:"bot",timestamp:Date.now(),messageId:`error-${Date.now()}`};return $e.push(t),void Ee(t)}const t=e.data;t.visitor_id&&(ke=t.visitor_id,ve.saveVisitorId(be.chatbotId,ke)),t.session_id&&(ye=t.session_id,ve.saveSessionId(be.chatbotId,ye));const n={text:t.response||t.message||"No response",type:"bot",timestamp:Date.now(),messageId:t.message_id||`bot-${Date.now()}`};$e.push(n),Ee(n),ve.saveConversationHistory($e)}function Pe(e){document.querySelectorAll(`#aptolix-stars-${be.chatbotId} .star`).forEach((t,n)=>{t.textContent=n<e?"★":"☆"})}function Be(){const e=document.querySelector(`#aptolix-chat-messages-${be.chatbotId}`);e&&(e.scrollTop=e.scrollHeight)}function Me(){requestAnimationFrame(()=>{const e=document.body.scrollHeight;Ce(_e,{height:e})})}me&&(window.addEventListener("message",e=>{if(e.source!==window.parent)return;const{type:t,payload:n}=e.data;switch(t){case Ie:Ae(n,n.apiHost);break;case Re:setTimeout(()=>Be(),50)}}),Ce(Te));export{Ae as initializeChatbot};
2
2
  //# sourceMappingURL=chatbot-core.mjs.map
package/dist/web.mjs CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var a=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===n&&a.firstChild?a.insertBefore(i,a.firstChild):a.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}('.aptolix-chat-window{box-sizing:border-box;display:flex;flex-direction:column;font-family:Inter,sans-serif;height:100%;margin:0;max-height:100%;max-width:100%;min-height:0;min-width:0;overflow:hidden;width:100%}[id^=aptolix-chat-header]{align-items:center;border-bottom-style:solid;border-bottom-width:2px;color:#fff;display:flex;font-size:1.15rem;font-weight:200;justify-content:space-between;padding:10px 13px}.aptolix-header-title{align-items:center;display:flex;flex:1;flex-direction:row;gap:12px;justify-content:flex-start;min-width:0}.aptolix-company-logo-wrapper{align-items:center;display:flex;flex-shrink:0}.aptolix-bot-name{align-items:center;display:flex;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;font-size:1rem;font-weight:600;letter-spacing:.01em;line-height:1.2;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.aptolix-header-subtitle{color:#ede9fe;font-size:.95rem;font-weight:400;margin-top:2px}.aptolix-header-actions{align-items:center;display:flex;gap:6px;margin-top:0;position:relative}.aptolix-menu-dropdown{background:#fff;border:1px solid rgba(0,0,0,.08);border-radius:6px;box-shadow:0 2px 8px rgba(0,0,0,.15);display:none;flex-direction:column;gap:0;min-width:120px;overflow:hidden;padding:3px 0;position:absolute;right:0;top:calc(100% + 6px);z-index:1000}.aptolix-menu-dropdown.show{display:flex}.aptolix-menu-item{align-items:center;background:transparent;border:none;color:#4b5563;cursor:pointer;direction:ltr;display:flex;gap:7px;justify-content:flex-start!important;padding:6px 10px;text-align:left!important;transition:background-color .1s ease;white-space:nowrap;width:100%}.aptolix-menu-item:hover{background-color:#f9fafb;color:#1f2937}.aptolix-menu-icon{align-items:center;display:inline-flex;flex-shrink:0;font-size:14px!important;justify-content:flex-start!important;line-height:1;text-align:left!important;width:14px}.aptolix-menu-text{flex:1;font-size:12px!important;font-weight:400;line-height:1.3;text-align:left!important}[id^=aptolix-chat-header] button{align-items:center;background:transparent;border:none;border-radius:6px;color:#fff;cursor:pointer;display:flex;font-size:22px;justify-content:center;min-height:20px;min-width:20px;transition:all .2s}[id^=aptolix-chat-header] button:hover{background:hsla(0,0%,100%,.15);transform:scale(1.05)}[id^=aptolix-chat-header] button:active{background:hsla(0,0%,100%,.25);transform:scale(.95)}.aptolix-header-flex{align-items:center;display:flex;justify-content:space-between;width:100%}[id^=aptolix-chat-messages]{display:flex;flex:1 1 auto;flex-direction:column;gap:10px;min-height:120px;overflow-y:auto;padding:18px 16px 16px}.aptolix-footer{align-items:center;background:transparent;display:flex;gap:10px;justify-content:center;min-height:36px;padding:0 8px}.aptolix-footer-separator{color:#d1d5db;font-size:.75rem;opacity:0;transition:opacity .4s ease .1s;user-select:none}.aptolix-footer-separator.show{opacity:1}.aptolix-powered-by{background:transparent;flex:0 0 auto;font-size:.75rem;font-weight:500;letter-spacing:.01em;padding:8px 0;text-align:center;transition:all .3s ease;white-space:nowrap}.aptolix-powered-by .aptolix-link{font-family:inherit;font-weight:600;text-decoration:underline}.aptolix-rating{align-items:center;color:#6b7280;display:flex;flex:0 0 auto;font-size:.75rem;gap:6px;max-width:0;opacity:0;overflow:hidden;transition:max-width .4s ease,opacity .4s ease,visibility .4s ease;visibility:hidden}.aptolix-rating.show{max-width:200px;opacity:1;visibility:visible}.aptolix-rating-label{font-size:.75rem;font-weight:500;white-space:nowrap}.aptolix-stars{align-items:center;display:flex;gap:2px}.star{color:#fbbf24;cursor:pointer;font-size:1.1rem;line-height:1;transition:transform .1s ease;user-select:none}.star:hover{transform:scale(1.1)}[id^=aptolix-chat-input]{align-items:center;background:#fff;border-top-style:solid;border-top-width:2px;display:flex;gap:8px;min-height:56px;padding:5px 10px}[id^=aptolix-chat-input] input{border:1.5px solid;border-radius:10px;flex:1 1 auto;font-size:1rem;min-width:0;padding:10px 14px;transition:border .2s}[id^=aptolix-chat-input] input:focus{outline:none}[id^=aptolix-chat-input] button{border:none;border-radius:10px;box-shadow:0 2px 8px rgba(0,0,0,.1);cursor:pointer;flex-shrink:0;font-size:1rem;font-weight:600;padding:8px 18px;transition:background .2s,box-shadow .2s}[id^=aptolix-chat-input] button:hover{box-shadow:0 4px 16px rgba(0,0,0,.15)}[id^=aptolix-chat-input] button:not(:first-child){background:rgba(167,139,250,.12);border-radius:8px;box-shadow:none;color:#9333ea;font-size:1.1rem;font-weight:500;padding:8px 12px}[id^=aptolix-chat-input] button:not(:first-child):hover{background:rgba(167,139,250,.22);color:#4b5563}[id^=aptolix-chat-inputbox]{border:1px solid;border-radius:4px;box-sizing:border-box;font-family:inherit;font-size:1rem;max-height:130px;min-height:42px;outline:none;overflow-y:auto;padding:6px 12px;resize:none;transition:border-color .2s;width:100%}.aptolix-messages-wrapper{display:flex;flex-direction:column;gap:10px;width:100%}.aptolix-messages-wrapper .message{align-items:flex-end;display:flex;font-family:Inter,sans-serif;gap:4px;margin-bottom:0;max-width:100%}.aptolix-messages-wrapper .message.user{align-self:flex-end;flex-direction:row-reverse}.aptolix-messages-wrapper .message.bot{align-self:flex-start;flex-direction:row}.aptolix-messages-wrapper .message-avatar{cursor:pointer;flex-shrink:0;height:16px;opacity:.7;position:relative;transition:opacity .2s;width:16px}.aptolix-messages-wrapper .message-avatar:hover{opacity:1}.aptolix-messages-wrapper .message-avatar img,.aptolix-messages-wrapper .message-avatar svg{border-radius:50%;height:16px;width:16px}.aptolix-messages-wrapper .message-sender{background:rgba(0,0,0,.8);border-radius:4px;bottom:100%;color:#fff;font-size:.75rem;font-weight:500;left:0;margin-bottom:4px;opacity:0;padding:4px 8px;pointer-events:none;position:absolute;transition:opacity .2s;white-space:nowrap;z-index:1000}.aptolix-messages-wrapper .message-avatar:hover .message-sender{opacity:1}.aptolix-messages-wrapper .message.user .message-sender{left:auto;right:0}.aptolix-messages-wrapper .message-content{align-items:flex-start;display:flex;flex-direction:column;gap:0;justify-content:flex-start;max-width:88%;min-width:0}.aptolix-messages-wrapper .message.user .message-content{align-items:flex-end}.aptolix-messages-wrapper .message-text{border-radius:14px;font-weight:500;line-height:1.5;margin-bottom:0;padding:8px 14px;word-break:break-word}.aptolix-messages-wrapper .message.user .message-text{border-radius:14px 14px 4px 14px;box-shadow:0 2px 8px rgba(167,139,250,.1)}.aptolix-messages-wrapper .message.bot .message-text{border-radius:14px 14px 14px 4px;box-shadow:0 2px 8px rgba(167,139,250,.08);margin-bottom:0}.aptolix-messages-wrapper .message-timestamp{align-self:flex-start;background:none;color:#9ca3af;font-size:.7rem;line-height:1.2;margin-top:2px;padding:0 8px;position:relative;z-index:1}.aptolix-messages-wrapper .message.user .message-timestamp{align-self:flex-end}.aptolix-messages-wrapper .message-rating{align-items:center;display:flex;margin-top:4px;padding:0 8px}.aptolix-messages-wrapper .message-rating .rating-stars{color:#fbbf24;font-size:.85rem;letter-spacing:1px}.aptolix-messages-wrapper .message-text a{color:inherit;text-decoration:underline;transition:opacity .2s;word-break:break-word}.aptolix-messages-wrapper .message-text a:hover{opacity:.8}.aptolix-messages-wrapper .message-text b,.aptolix-messages-wrapper .message-text strong{font-weight:700}.aptolix-messages-wrapper .message-text em,.aptolix-messages-wrapper .message-text i{font-style:italic}.aptolix-messages-wrapper .message-text h1,.aptolix-messages-wrapper .message-text h2,.aptolix-messages-wrapper .message-text h3{font-size:1.3rem;font-weight:600;line-height:1.3;margin:14px 0 8px}.aptolix-messages-wrapper .message-text h1:first-child,.aptolix-messages-wrapper .message-text h2:first-child,.aptolix-messages-wrapper .message-text h3:first-child{margin-top:0}.aptolix-messages-wrapper .message-text h2{font-size:1.15rem}.aptolix-messages-wrapper .message-text h3{font-size:1.05rem}.aptolix-messages-wrapper .message-text p{line-height:1.6;margin:8px 0}.aptolix-messages-wrapper .message-text p:first-child{margin-top:0}.aptolix-messages-wrapper .message-text p:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text ol,.aptolix-messages-wrapper .message-text ul{line-height:1.6;margin:8px 0;padding-left:0}.aptolix-messages-wrapper .message-text ol:first-child,.aptolix-messages-wrapper .message-text ul:first-child{margin-top:0}.aptolix-messages-wrapper .message-text ol:last-child,.aptolix-messages-wrapper .message-text ul:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text ul{list-style:none}.aptolix-messages-wrapper .message-text ol{list-style:decimal;padding-left:1.5em}.aptolix-messages-wrapper .message-text ul li{margin-bottom:6px;padding-left:1.5em;position:relative}.aptolix-messages-wrapper .message-text ul li:before{background:currentColor;border-radius:50%;content:"";height:.4em;left:.4em;opacity:.7;position:absolute;top:.65em;width:.4em}.aptolix-messages-wrapper .message-text ol li{margin-bottom:6px;padding-left:.3em}.aptolix-messages-wrapper .message-text li:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text blockquote{background:rgba(0,0,0,.03);border-left:3px solid;border-radius:0 6px 6px 0;font-style:italic;margin:10px 0;opacity:.8;padding:8px 12px}.aptolix-messages-wrapper .message-text blockquote:first-child{margin-top:0}.aptolix-messages-wrapper .message-text blockquote:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text code{background:rgba(0,0,0,.08);border-radius:4px;color:inherit;font-family:Fira Mono,Consolas,Monaco,monospace;font-size:.9em;font-weight:500;padding:2px 6px}.aptolix-messages-wrapper .message-text pre{background:rgba(0,0,0,.05);border:1px solid rgba(0,0,0,.1);border-radius:6px;margin:10px 0;overflow-x:auto;padding:12px}.aptolix-messages-wrapper .message-text pre:first-child{margin-top:0}.aptolix-messages-wrapper .message-text pre:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text pre code{background:transparent;border-radius:0;display:block;font-size:.85em;line-height:1.5;padding:0}.aptolix-messages-wrapper .message-text hr{border:none;border-top:1px solid rgba(0,0,0,.1);margin:12px 0}.aptolix-messages-wrapper .message-text table{border-collapse:collapse;margin:10px 0;width:100%}.aptolix-messages-wrapper .message-text table td,.aptolix-messages-wrapper .message-text table th{border:1px solid rgba(0,0,0,.1);padding:6px 10px;text-align:left}.aptolix-messages-wrapper .message-text table th{background:rgba(0,0,0,.05);font-weight:600}.aptolix-messages-wrapper .typing-dots span{animation:blink 1.2s infinite;font-size:1.5em;margin-right:2px;opacity:.5}.aptolix-messages-wrapper .typing-dots span:nth-child(2){animation-delay:.2s}.aptolix-messages-wrapper .typing-dots span:nth-child(3){animation-delay:.4s}@keyframes blink{0%,to{opacity:.2}50%{opacity:1}}.aptolix-chat-bubble{align-items:center;background:#9333ea;border-radius:50%;bottom:32px;box-shadow:0 6px 24px rgba(167,139,250,.18);color:#fff;cursor:pointer;display:flex;font-size:2rem;height:56px;justify-content:center;position:fixed;right:32px;transition:background .2s,box-shadow .2s;width:56px;z-index:9999}.aptolix-chat-bubble:hover{background:#7c3aed;box-shadow:0 8px 32px rgba(124,62,237,.28)}.aptolix-chat-window.bubble-mode{border-radius:16px;border-style:solid;border-width:2.5px;display:flex;flex-direction:column;height:100%;overflow:hidden}.aptolix-chat-window.section-mode{border-radius:18px;border-style:solid;border-width:2.5px;box-sizing:border-box!important;display:flex!important;flex-direction:column;height:100%;max-height:100%;max-width:100%;overflow:hidden;position:static!important;width:100%}.aptolix-chat-window.section-mode [id^=aptolix-chat-messages]{background:#f6f3ff;flex:1 1 auto;min-height:0;overflow-y:auto;padding:20px 18px 18px}.aptolix-chat-window.section-mode [id^=aptolix-chat-header]{background:#9333ea;color:#fff}.aptolix-chat-window.section-mode [id^=aptolix-chat-close],.aptolix-chat-window.section-mode [id^=aptolix-chat-expand],.aptolix-chat-window.section-mode~.aptolix-chat-bubble{display:none!important}@media (max-width:600px){[id^=aptolix-chat-header]{font-size:1rem;padding:10px 8px}[id^=aptolix-chat-messages]{padding:12px 8px}[id^=aptolix-chat-input]{padding:8px}.aptolix-chat-window.section-mode{border-radius:12px;border-width:1px}}@media (max-width:480px){.aptolix-chat-bubble{bottom:24px;height:52px;right:24px;width:52px}}.aptolix-retry-btn{background:#ede9fe;border:none;border-radius:6px;color:#7c3aed;cursor:pointer;font-weight:600;margin-top:8px;padding:4px 12px}.aptolix-retry-btn:hover{background:#d8b4fe}.aptolix-hint-bubble{background:#fff;border-radius:8px;bottom:110px;box-shadow:0 2px 8px rgba(0,0,0,.15);color:#333;font-size:1em;max-width:320px;min-width:180px;padding:16px 40px 16px 16px;pointer-events:auto;position:fixed;right:40px;z-index:9999}.aptolix-hint-bubble:after{border-left:10px solid transparent;border-right:10px solid transparent;border-top:12px solid #fff;bottom:-12px;content:"";height:0;position:absolute;right:28px;width:0}');class e{constructor(e=null){this.chatbotId=e,this.keys={config:"aptolix_chatbot_config",state:"aptolix_chatbot_state"}}_getState(e=null){if(!(e=e||this.chatbotId))return null;try{const t=`${this.keys.state}_${e}`,n=localStorage.getItem(t);return n?JSON.parse(n):null}catch(e){return null}}_saveState(e,t){if("object"==typeof e&&void 0===t&&(t=e,e=this.chatbotId),e)try{const n=`${this.keys.state}_${e}`;t.timestamp=Date.now(),t.version="1.0.24",localStorage.setItem(n,JSON.stringify(t))}catch(e){}}_isToday(e){const t=new Date,n=new Date(e);return t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate()}_getTodayStart(){const e=new Date;return e.setHours(0,0,0,0),e.getTime()}saveConfig(e,t){try{const n=`${this.keys.config}_${e}`,a={config:t,timestamp:Date.now()};localStorage.setItem(n,JSON.stringify(a))}catch(e){}}getConfig(e){try{const t=`${this.keys.config}_${e}`,n=localStorage.getItem(t);if(!n)return null;return JSON.parse(n).config}catch(e){return null}}clearConfig(e){try{const t=`${this.keys.config}_${e}`;localStorage.removeItem(t)}catch(e){}}hasConfig(e){const t=`${this.keys.config}_${e}`;return null!==localStorage.getItem(t)}saveVisitorId(e,t){try{const n=this._getState(e)||{};n.visitorId=t,this._saveState(e,n)}catch(e){}}getVisitorId(e){try{const t=this._getState(e);return t?.visitorId||null}catch(e){return null}}clearVisitorId(e){try{const t=this._getState(e);t&&(delete t.visitorId,this._saveState(e,t))}catch(e){}}hasVisitorId(e){return null!==this.getVisitorId(e)}saveSessionId(e,t){try{const n=this._getState(e)||{};n.sessionId=t,this._saveState(e,n)}catch(e){}}getSessionId(e){try{const t=this._getState(e);return t?.sessionId||null}catch(e){return null}}clearSessionId(e){try{const t=this._getState(e);t&&(delete t.sessionId,this._saveState(e,t))}catch(e){}}hasSessionId(e){return null!==this.getSessionId(e)}saveChatHistory(e,t,n){try{const t=this._getState(e)||{};t.history={messages:n,timestamp:Date.now()},this._saveState(e,t)}catch(e){}}getChatHistory(e,t){try{const n=this._getState(e);if(!n?.history)return null;const{history:a}=n;return n.sessionId!==t?null:this._isToday(a.timestamp)?a.messages:(this.clearChatHistory(e,t),null)}catch(e){return null}}clearChatHistory(e,t){try{const n=this._getState(e);n?.history&&n.sessionId===t&&(delete n.history,this._saveState(e,n))}catch(e){}}hasChatHistory(e,t){return null!==this.getChatHistory(e,t)}setUsageLimitReached(e,t,n){try{const t=this._getState(e)||{};t.usageLimitReached={limitReachedDate:n,timestamp:Date.now()},this._saveState(e,t)}catch(e){}}getUsageLimitReached(e,t){try{const n=this._getState(e);if(!n?.usageLimitReached)return null;const{usageLimitReached:a}=n;let i;i=10!==a.limitReachedDate.length||a.limitReachedDate.includes("T")?new Date(a.limitReachedDate):new Date(a.limitReachedDate+"T23:59:59.999Z");return new Date>i?(this.clearUsageLimitReached(e,t),null):{limitReachedDate:a.limitReachedDate,timestamp:a.timestamp}}catch(e){return null}}clearUsageLimitReached(e,t){try{const t=this._getState(e);t&&(delete t.usageLimitReached,this._saveState(e,t))}catch(e){}}hasUsageLimitReached(e,t){return null!==this.getUsageLimitReached(e,t)}clearAll(e=null,t=null,n=null){if(e=e||this.chatbotId){this.clearConfig(e);try{const t=`${this.keys.state}_${e}`;localStorage.removeItem(t)}catch(e){}}}getConversationHistory(){if(!this.chatbotId)return null;const e=this._getState(this.chatbotId);return e?.history?.messages||null}saveConversationHistory(e){if(!this.chatbotId)return;const t=this._getState(this.chatbotId)||{};t.history={messages:e,timestamp:Date.now()},this._saveState(this.chatbotId,t)}clearConversationHistory(){if(!this.chatbotId)return;const e=this._getState(this.chatbotId);e?.history&&(delete e.history,this._saveState(this.chatbotId,e))}getRating(e){if(!this.chatbotId)return null;const t=this._getState(this.chatbotId);return t?.ratings?.[e]||null}saveRating(e,t){if(!this.chatbotId)return;const n=this._getState(this.chatbotId)||{};n.ratings||(n.ratings={}),n.ratings[e]=t,this._saveState(this.chatbotId,n)}}const t={mode:"bubble",botname:"AI Assistant",widgetIcon:"💬",companyLogoBlack:'\n <svg width="24" height="32" viewBox="0 0 81 52" fill="none" xmlns="http://www.w3.org/2000/svg">\n <rect x="34.8" y="0" width="46" height="11.7" rx="5.9" fill="#000"/>\n <rect x="0.2" y="19.7" width="80.6" height="12" rx="6" fill="#000"/>\n <rect x="61.7" y="39.4" width="19" height="11.7" rx="6" fill="#000"/>\n <rect x="7.7" y="39.5" width="49" height="11.7" rx="6" fill="#000"/>\n </svg>\n ',companyLogoWhite:'\n <svg width="24" height="32" viewBox="0 0 81 52" fill="none" xmlns="http://www.w3.org/2000/svg">\n <rect x="34.8" y="0" width="46" height="11.7" rx="5.9" fill="#fcfcfcff"/>\n <rect x="0.2" y="19.7" width="80.6" height="12" rx="6" fill="#fcfcfcff"/>\n <rect x="61.7" y="39.4" width="19" height="11.7" rx="6" fill="#fcfcfcff"/>\n <rect x="7.7" y="39.5" width="49" height="11.7" rx="6" fill="#fcfcfcff"/>\n </svg>\n ',botAvatar:'\n <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="20" cy="20" r="18" fill="#9333ea"/>\n <rect x="12" y="14" width="6" height="6" rx="1" fill="#fff"/>\n <rect x="22" y="14" width="6" height="6" rx="1" fill="#fff"/>\n <rect x="13" y="26" width="14" height="4" rx="2" fill="#fff"/>\n </svg>\n ',userAvatar:'\n <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="20" cy="20" r="20" fill="#64748b"/>\n <circle cx="20" cy="15" r="6" fill="#fff"/>\n <path d="M 8 35 Q 8 25 20 25 Q 32 25 32 35" fill="#fff"/>\n </svg>\n ',username:"You",botaccentColor:"#4a57e2ff",floatingWelcomeMessage:"Hello! Looking for something? I'm here to assist - just ask!",floatingWelcomeDelay:2,greetingMessage:"Welcome! Let me know if you have any questions.",allowDownloadTranscript:!0,allowExpandChatWindow:!0,allowFullPageChat:!1,inputCharLimit:350,allowReset:!0,allowRating:!0,ratingThreshold:3,ratingInterval:4};function n(e){return!(!e||"string"!=typeof e)&&(!!(e.includes("<svg")||e.includes("<")&&e.includes(">"))||e.trim().length>0&&e.length<=100)}async function a(a,i){const s=new e;if(a&&i){const e=await async function(e,t){try{const a=await fetch(`${e}/chatbot/${t}/appearance`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!a.ok)return null;return(n=await a.json())?{botname:n.bot_name,widgetIcon:n.widget_icon,companyLogo:n.company_logo,botAvatar:n.bot_avatar,userAvatar:n.user_avatar,username:n.username,botaccentColor:n.accent_color,floatingWelcomeMessage:n.floating_welcome_message,floatingWelcomeDelay:n.floating_welcome_delay,greetingMessage:n.greeting_message,allowDownloadTranscript:n.download_transcript,allowExpandChatWindow:n.expand_chat_window,allowFullPageChat:n.full_page_chat,inputCharLimit:n.input_char_limit,allowReset:n.allow_reset,allowRating:n.allow_rating,ratingThreshold:n.rating_threshold,ratingInterval:n.rating_interval}:null}catch(e){return null}var n}(a,i);if(e)return e.widgetIcon&&n(e.widgetIcon)||(e.widgetIcon=t.widgetIcon),s.saveConfig(i,e),e;{const e=s.getConfig(i);return e?(e.widgetIcon&&n(e.widgetIcon)||(e.widgetIcon=t.widgetIcon),e):null}}return null}function i(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var s={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function r(e){s=e}var o={exec:()=>null};function l(e,t=""){let n="string"==typeof e?e:e.source,a={replace:(e,t)=>{let i="string"==typeof t?t:t.source;return i=i.replace(c.caret,"$1"),n=n.replace(e,i),a},getRegex:()=>new RegExp(n,t)};return a}var c={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[\t ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},p=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,h=/(?:[*+-]|\d{1,9}[.)])/,d=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,g=l(d).replace(/bull/g,h).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).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/).replace(/\|table/g,"").getRegex(),u=l(d).replace(/bull/g,h).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).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/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),x=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,m=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,f=l(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",m).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),b=l(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,h).getRegex(),w="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",y=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,k=l("^ {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[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",y).replace("tag",w).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),v=l(x).replace("hr",p).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",w).getRegex(),$={blockquote:l(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",v).getRegex(),code:/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,def:f,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:p,html:k,lheading:g,list:b,newline:/^(?:[ \t]*(?:\n|$))+/,paragraph:v,table:o,text:/^[^\n]+/},S=l("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",p).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\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",w).getRegex(),I={...$,lheading:u,table:S,paragraph:l(x).replace("hr",p).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",S).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",w).getRegex()},T={...$,html:l("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",y).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:o,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:l(x).replace("hr",p).replace("heading"," *#{1,6} *[^\n]").replace("lheading",g).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},C=/^( {2,}|\\)\n(?!\s*$)/,_=/[\p{P}\p{S}]/u,A=/[\s\p{P}\p{S}]/u,R=/[^\s\p{P}\p{S}]/u,L=l(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,A).getRegex(),z=/(?!~)[\p{P}\p{S}]/u,E=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,D=l(E,"u").replace(/punct/g,_).getRegex(),M=l(E,"u").replace(/punct/g,z).getRegex(),P="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",q=l(P,"gu").replace(/notPunctSpace/g,R).replace(/punctSpace/g,A).replace(/punct/g,_).getRegex(),H=l(P,"gu").replace(/notPunctSpace/g,/(?:[^\s\p{P}\p{S}]|~)/u).replace(/punctSpace/g,/(?!~)[\s\p{P}\p{S}]/u).replace(/punct/g,z).getRegex(),B=l("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,R).replace(/punctSpace/g,A).replace(/punct/g,_).getRegex(),W=l(/\\(punct)/,"gu").replace(/punct/g,_).getRegex(),O=l(/^<(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(),N=l(y).replace("(?:--\x3e|$)","--\x3e").getRegex(),j=l("^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",N).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),U=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`[^`]*`|[^\[\]\\`])*?/,F=l(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",U).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Z=l(/^!?\[(label)\]\[(ref)\]/).replace("label",U).replace("ref",m).getRegex(),G=l(/^!?\[(ref)\](?:\[\])?/).replace("ref",m).getRegex(),Q={_backpedal:o,anyPunctuation:W,autolink:O,blockSkip:/\[[^\[\]]*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)|`[^`]*?`|<(?! )[^<>]*?>/g,br:C,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:o,emStrongLDelim:D,emStrongRDelimAst:q,emStrongRDelimUnd:B,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:F,nolink:G,punctuation:L,reflink:Z,reflinkSearch:l("reflink|nolink(?!\\()","g").replace("reflink",Z).replace("nolink",G).getRegex(),tag:j,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:o},X={...Q,link:l(/^!?\[(label)\]\((.*?)\)/).replace("label",U).getRegex(),reflink:l(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",U).getRegex()},Y={...Q,emStrongRDelimAst:H,emStrongLDelim:M,url:l(/^((?: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\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.!#$%&'*+\/=?_`{\|}~-]+@)))/},J={...Y,br:l(C).replace("{2,}","*").getRegex(),text:l(Y.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},V={normal:$,gfm:I,pedantic:T},K={normal:Q,gfm:Y,breaks:J,pedantic:X},ee={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},te=e=>ee[e];function ne(e,t){if(t){if(c.escapeTest.test(e))return e.replace(c.escapeReplace,te)}else if(c.escapeTestNoEncode.test(e))return e.replace(c.escapeReplaceNoEncode,te);return e}function ae(e){try{e=encodeURI(e).replace(c.percentDecode,"%")}catch{return null}return e}function ie(e,t){let n=e.replace(c.findPipe,(e,t,n)=>{let a=!1,i=t;for(;--i>=0&&"\\"===n[i];)a=!a;return a?"|":" |"}).split(c.splitPipe),a=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;a<n.length;a++)n[a]=n[a].trim().replace(c.slashPipe,"|");return n}function se(e,t,n){let a=e.length;if(0===a)return"";let i=0;for(;i<a;){let s=e.charAt(a-i-1);if(s!==t||n){if(s===t||!n)break;i++}else i++}return e.slice(0,a-i)}function re(e,t,n,a,i){let s=t.href,r=t.title||null,o=e[1].replace(i.other.outputLinkReplace,"$1");a.state.inLink=!0;let l={type:"!"===e[0].charAt(0)?"image":"link",raw:n,href:s,title:r,text:o,tokens:a.inlineTokens(o)};return a.state.inLink=!1,l}var oe=class{options;rules;lexer;constructor(e){this.options=e||s}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:se(e,"\n")}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=function(e,t,n){let a=e.match(n.other.indentCodeCompensation);if(null===a)return t;let i=a[1];return t.split("\n").map(e=>{let t=e.match(n.other.beginningSpace);if(null===t)return e;let[a]=t;return a.length>=i.length?e.slice(i.length):e}).join("\n")}(e,t[3]||"",this.rules);return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=se(e,"#");(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:se(t[0],"\n")}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=se(t[0],"\n").split("\n"),n="",a="",i=[];for(;e.length>0;){let t,s=!1,r=[];for(t=0;t<e.length;t++)if(this.rules.other.blockquoteStart.test(e[t]))r.push(e[t]),s=!0;else{if(s)break;r.push(e[t])}e=e.slice(t);let o=r.join("\n"),l=o.replace(this.rules.other.blockquoteSetextReplace,"\n $1").replace(this.rules.other.blockquoteSetextReplace2,"");n=n?`${n}\n${o}`:o,a=a?`${a}\n${l}`:l;let c=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(l,i,!0),this.lexer.state.top=c,0===e.length)break;let p=i.at(-1);if("code"===p?.type)break;if("blockquote"===p?.type){let t=p,s=t.raw+"\n"+e.join("\n"),r=this.blockquote(s);i[i.length-1]=r,n=n.substring(0,n.length-t.raw.length)+r.raw,a=a.substring(0,a.length-t.text.length)+r.text;break}if("list"===p?.type){let t=p,s=t.raw+"\n"+e.join("\n"),r=this.list(s);i[i.length-1]=r,n=n.substring(0,n.length-p.raw.length)+r.raw,a=a.substring(0,a.length-t.raw.length)+r.raw,e=s.substring(i.at(-1).raw.length).split("\n");continue}}return{type:"blockquote",raw:n,tokens:i,text:a}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),a=n.length>1,i={type:"list",raw:"",ordered:a,start:a?+n.slice(0,-1):"",loose:!1,items:[]};n=a?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=a?n:"[*+-]");let s=this.rules.other.listItemRegex(n),r=!1;for(;e;){let n=!1,a="",o="";if(!(t=s.exec(e))||this.rules.block.hr.test(e))break;a=t[0],e=e.substring(a.length);let l=t[2].split("\n",1)[0].replace(this.rules.other.listReplaceTabs,e=>" ".repeat(3*e.length)),c=e.split("\n",1)[0],p=!l.trim(),h=0;if(this.options.pedantic?(h=2,o=l.trimStart()):p?h=t[1].length+1:(h=t[2].search(this.rules.other.nonSpaceChar),h=h>4?1:h,o=l.slice(h),h+=t[1].length),p&&this.rules.other.blankLine.test(c)&&(a+=c+"\n",e=e.substring(c.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(h),n=this.rules.other.hrRegex(h),i=this.rules.other.fencesBeginRegex(h),s=this.rules.other.headingBeginRegex(h),r=this.rules.other.htmlBeginRegex(h);for(;e;){let d,g=e.split("\n",1)[0];if(c=g,this.options.pedantic?(c=c.replace(this.rules.other.listReplaceNesting," "),d=c):d=c.replace(this.rules.other.tabCharGlobal," "),i.test(c)||s.test(c)||r.test(c)||t.test(c)||n.test(c))break;if(d.search(this.rules.other.nonSpaceChar)>=h||!c.trim())o+="\n"+d.slice(h);else{if(p||l.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||i.test(l)||s.test(l)||n.test(l))break;o+="\n"+c}!p&&!c.trim()&&(p=!0),a+=g+"\n",e=e.substring(g.length+1),l=d.slice(h)}}i.loose||(r?i.loose=!0:this.rules.other.doubleBlankLine.test(a)&&(r=!0));let d,g=null;this.options.gfm&&(g=this.rules.other.listIsTask.exec(o),g&&(d="[ ] "!==g[0],o=o.replace(this.rules.other.listReplaceTask,""))),i.items.push({type:"list_item",raw:a,task:!!g,checked:d,loose:!1,text:o,tokens:[]}),i.raw+=a}let o=i.items.at(-1);if(!o)return;o.raw=o.raw.trimEnd(),o.text=o.text.trimEnd(),i.raw=i.raw.trimEnd();for(let e=0;e<i.items.length;e++)if(this.lexer.state.top=!1,i.items[e].tokens=this.lexer.blockTokens(i.items[e].text,[]),!i.loose){let t=i.items[e].tokens.filter(e=>"space"===e.type),n=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw));i.loose=n}if(i.loose)for(let e=0;e<i.items.length;e++)i.items[e].loose=!0;return i}}html(e){let 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){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",a=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:a}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=ie(t[1]),a=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),i=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split("\n"):[],s={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===a.length){for(let e of a)this.rules.other.tableAlignRight.test(e)?s.align.push("right"):this.rules.other.tableAlignCenter.test(e)?s.align.push("center"):this.rules.other.tableAlignLeft.test(e)?s.align.push("left"):s.align.push(null);for(let e=0;e<n.length;e++)s.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:s.align[e]});for(let e of i)s.rows.push(ie(e,s.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:s.align[t]})));return s}}lheading(e){let 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){let t=this.rules.block.paragraph.exec(e);if(t){let 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){let 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){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.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){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=se(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{let e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let a=0;a<e.length;a++)if("\\"===e[a])a++;else if(e[a]===t[0])n++;else if(e[a]===t[1]&&(n--,n<0))return a;return n>0?-2:-1}(t[2],"()");if(-2===e)return;if(e>-1){let 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],a="";if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],a=e[3])}else a=t[3]?t[3].slice(1,-1):"";return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),re(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,"$1"),title:a&&a.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," ").toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return re(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let a=this.rules.inline.emStrongLDelim.exec(e);if(!(!a||a[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!a[1]&&!a[2]||!n||this.rules.inline.punctuation.exec(n))){let n,i,s=[...a[0]].length-1,r=s,o=0,l="*"===a[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+s);null!=(a=l.exec(t));){if(n=a[1]||a[2]||a[3]||a[4]||a[5]||a[6],!n)continue;if(i=[...n].length,a[3]||a[4]){r+=i;continue}if((a[5]||a[6])&&s%3&&!((s+i)%3)){o+=i;continue}if(r-=i,r>0)continue;i=Math.min(i,i+r+o);let t=[...a[0]][0].length,l=e.slice(0,s+a.index+t+i);if(Math.min(s,i)%2){let e=l.slice(1,-1);return{type:"em",raw:l,text:e,tokens:this.lexer.inlineTokens(e)}}let c=l.slice(2,-2);return{type:"strong",raw:l,text:c,tokens:this.lexer.inlineTokens(c)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal," "),n=this.rules.other.nonSpaceChar.test(e),a=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&a&&(e=e.substring(1,e.length-1)),{type:"codespan",raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){let 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){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=t[1],n="mailto:"+e):(e=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=t[0],n="mailto:"+e;else{let a;do{a=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(a!==t[0]);e=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){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:e}}}},le=class e{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||s,this.options.tokenizer=this.options.tokenizer||new oe,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:c,block:V.normal,inline:K.normal};this.options.pedantic?(t.block=V.pedantic,t.inline=K.pedantic):this.options.gfm&&(t.block=V.gfm,this.options.breaks?t.inline=K.breaks:t.inline=K.gfm),this.tokenizer.rules=t}static get rules(){return{block:V,inline:K}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(c.carriageReturn,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){for(this.options.pedantic&&(e=e.replace(c.tabCharGlobal," ").replace(c.spaceLine,""));e;){let a;if(this.options.extensions?.block?.some(n=>!!(a=n.call({lexer:this},e,t))&&(e=e.substring(a.raw.length),t.push(a),!0)))continue;if(a=this.tokenizer.space(e)){e=e.substring(a.raw.length);let n=t.at(-1);1===a.raw.length&&void 0!==n?n.raw+="\n":t.push(a);continue}if(a=this.tokenizer.code(e)){e=e.substring(a.raw.length);let n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+a.raw,n.text+="\n"+a.text,this.inlineQueue.at(-1).src=n.text):t.push(a);continue}if(a=this.tokenizer.fences(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.heading(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.hr(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.blockquote(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.list(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.html(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.def(e)){e=e.substring(a.raw.length);let n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+a.raw,n.text+="\n"+a.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[a.tag]||(this.tokens.links[a.tag]={href:a.href,title:a.title},t.push(a));continue}if(a=this.tokenizer.table(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.lheading(e)){e=e.substring(a.raw.length),t.push(a);continue}let i=e;if(this.options.extensions?.startBlock){let t,n=1/0,a=e.slice(1);this.options.extensions.startBlock.forEach(e=>{t=e.call({lexer:this},a),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(i=e.substring(0,n+1))}if(this.state.top&&(a=this.tokenizer.paragraph(i))){let s=t.at(-1);n&&"paragraph"===s?.type?(s.raw+=(s.raw.endsWith("\n")?"":"\n")+a.raw,s.text+="\n"+a.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=s.text):t.push(a),n=i.length!==e.length,e=e.substring(a.raw.length);continue}if(a=this.tokenizer.text(e)){e=e.substring(a.raw.length);let n=t.at(-1);"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+a.raw,n.text+="\n"+a.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(a);continue}if(e){let 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=e,a=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(a=this.tokenizer.rules.inline.reflinkSearch.exec(n));)e.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(n=n.slice(0,a.index)+"["+"a".repeat(a[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(a=this.tokenizer.rules.inline.anyPunctuation.exec(n));)n=n.slice(0,a.index)+"++"+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;null!=(a=this.tokenizer.rules.inline.blockSkip.exec(n));)n=n.slice(0,a.index)+"["+"a".repeat(a[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let i=!1,s="";for(;e;){let a;if(i||(s=""),i=!1,this.options.extensions?.inline?.some(n=>!!(a=n.call({lexer:this},e,t))&&(e=e.substring(a.raw.length),t.push(a),!0)))continue;if(a=this.tokenizer.escape(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.tag(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.link(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(a.raw.length);let n=t.at(-1);"text"===a.type&&"text"===n?.type?(n.raw+=a.raw,n.text+=a.text):t.push(a);continue}if(a=this.tokenizer.emStrong(e,n,s)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.codespan(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.br(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.del(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.autolink(e)){e=e.substring(a.raw.length),t.push(a);continue}if(!this.state.inLink&&(a=this.tokenizer.url(e))){e=e.substring(a.raw.length),t.push(a);continue}let r=e;if(this.options.extensions?.startInline){let t,n=1/0,a=e.slice(1);this.options.extensions.startInline.forEach(e=>{t=e.call({lexer:this},a),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(r=e.substring(0,n+1))}if(a=this.tokenizer.inlineText(r)){e=e.substring(a.raw.length),"_"!==a.raw.slice(-1)&&(s=a.raw.slice(-1)),i=!0;let n=t.at(-1);"text"===n?.type?(n.raw+=a.raw,n.text+=a.text):t.push(a);continue}if(e){let t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return t}},ce=class{options;parser;constructor(e){this.options=e||s}space(e){return""}code({text:e,lang:t,escaped:n}){let a=(t||"").match(c.notSpaceStart)?.[0],i=e.replace(c.endingNewline,"")+"\n";return a?'<pre><code class="language-'+ne(a)+'">'+(n?i:ne(i,!0))+"</code></pre>\n":"<pre><code>"+(n?i:ne(i,!0))+"</code></pre>\n"}blockquote({tokens:e}){return`<blockquote>\n${this.parser.parse(e)}</blockquote>\n`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>\n`}hr(e){return"<hr>\n"}list(e){let t=e.ordered,n=e.start,a="";for(let t=0;t<e.items.length;t++){let n=e.items[t];a+=this.listitem(n)}let i=t?"ol":"ul";return"<"+i+(t&&1!==n?' start="'+n+'"':"")+">\n"+a+"</"+i+">\n"}listitem(e){let t="";if(e.task){let n=this.checkbox({checked:!!e.checked});e.loose?"paragraph"===e.tokens[0]?.type?(e.tokens[0].text=n+" "+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&"text"===e.tokens[0].tokens[0].type&&(e.tokens[0].tokens[0].text=n+" "+ne(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:"text",raw:n+" ",text:n+" ",escaped:!0}):t+=n+" "}return t+=this.parser.parse(e.tokens,!!e.loose),`<li>${t}</li>\n`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>\n`}table(e){let t="",n="";for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let a="";for(let t=0;t<e.rows.length;t++){let i=e.rows[t];n="";for(let e=0;e<i.length;e++)n+=this.tablecell(i[e]);a+=this.tablerow({text:n})}return a&&(a=`<tbody>${a}</tbody>`),"<table>\n<thead>\n"+t+"</thead>\n"+a+"</table>\n"}tablerow({text:e}){return`<tr>\n${e}</tr>\n`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>\n`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${ne(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let a=this.parser.parseInline(n),i=ae(e);if(null===i)return a;let s='<a href="'+(e=i)+'"';return t&&(s+=' title="'+ne(t)+'"'),s+=">"+a+"</a>",s}image({href:e,title:t,text:n,tokens:a}){a&&(n=this.parser.parseInline(a,this.parser.textRenderer));let i=ae(e);if(null===i)return ne(n);let s=`<img src="${e=i}" alt="${n}"`;return t&&(s+=` title="${ne(t)}"`),s+=">",s}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:ne(e.text)}},pe=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}},he=class e{options;renderer;textRenderer;constructor(e){this.options=e||s,this.options.renderer=this.options.renderer||new ce,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new pe}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e,t=!0){let n="";for(let a=0;a<e.length;a++){let i=e[a];if(this.options.extensions?.renderers?.[i.type]){let e=i,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(e.type)){n+=t||"";continue}}let s=i;switch(s.type){case"space":n+=this.renderer.space(s);continue;case"hr":n+=this.renderer.hr(s);continue;case"heading":n+=this.renderer.heading(s);continue;case"code":n+=this.renderer.code(s);continue;case"table":n+=this.renderer.table(s);continue;case"blockquote":n+=this.renderer.blockquote(s);continue;case"list":n+=this.renderer.list(s);continue;case"html":n+=this.renderer.html(s);continue;case"def":n+=this.renderer.def(s);continue;case"paragraph":n+=this.renderer.paragraph(s);continue;case"text":{let i=s,r=this.renderer.text(i);for(;a+1<e.length&&"text"===e[a+1].type;)i=e[++a],r+="\n"+this.renderer.text(i);n+=t?this.renderer.paragraph({type:"paragraph",raw:r,text:r,tokens:[{type:"text",raw:r,text:r,escaped:!0}]}):r;continue}default:{let 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=this.renderer){let n="";for(let a=0;a<e.length;a++){let i=e[a];if(this.options.extensions?.renderers?.[i.type]){let e=this.options.extensions.renderers[i.type].call({parser:this},i);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){n+=e||"";continue}}let s=i;switch(s.type){case"escape":case"text":n+=t.text(s);break;case"html":n+=t.html(s);break;case"link":n+=t.link(s);break;case"image":n+=t.image(s);break;case"strong":n+=t.strong(s);break;case"em":n+=t.em(s);break;case"codespan":n+=t.codespan(s);break;case"br":n+=t.br(s);break;case"del":n+=t.del(s);break;default:{let e='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}},de=class{options;block;constructor(e){this.options=e||s}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}provideLexer(){return this.block?le.lex:le.lexInline}provideParser(){return this.block?he.parse:he.parseInline}},ge=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.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=he;Renderer=ce;TextRenderer=pe;Lexer=le;Tokenizer=oe;Hooks=de;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let a of e)switch(n=n.concat(t.call(this,a)),a.type){case"table":{let e=a;for(let a of e.header)n=n.concat(this.walkTokens(a.tokens,t));for(let a of e.rows)for(let e of a)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{let e=a;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=a;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(a=>{let i=e[a].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let 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){let n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let a=e.renderer.apply(this,t);return!1===a&&(a=n.apply(this,t)),a}: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'");let 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){let t=this.defaults.renderer||new ce(this.defaults);for(let n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if(["options","parser"].includes(n))continue;let a=n,i=e.renderer[a],s=t[a];t[a]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=s.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new oe(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;let a=n,i=e.tokenizer[a],s=t[a];t[a]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=s.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new de;for(let n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if(["options","block"].includes(n))continue;let a=n,i=e.hooks[a],s=t[a];de.passThroughHooks.has(n)?t[a]=e=>{if(this.defaults.async)return Promise.resolve(i.call(t,e)).then(e=>s.call(t,e));let n=i.call(t,e);return s.call(t,n)}:t[a]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=s.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,a=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(a.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 le.lex(e,t??this.defaults)}parser(e,t){return he.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let a={...n},i={...this.defaults,...a},s=this.onError(!!i.silent,!!i.async);if(!0===this.defaults.async&&!1===a.async)return s(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||null===t)return s(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof t)return s(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));i.hooks&&(i.hooks.options=i,i.hooks.block=e);let r=i.hooks?i.hooks.provideLexer():e?le.lex:le.lexInline,o=i.hooks?i.hooks.provideParser():e?he.parse:he.parseInline;if(i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(t):t).then(e=>r(e,i)).then(e=>i.hooks?i.hooks.processAllTokens(e):e).then(e=>i.walkTokens?Promise.all(this.walkTokens(e,i.walkTokens)).then(()=>e):e).then(e=>o(e,i)).then(e=>i.hooks?i.hooks.postprocess(e):e).catch(s);try{i.hooks&&(t=i.hooks.preprocess(t));let e=r(t,i);i.hooks&&(e=i.hooks.processAllTokens(e)),i.walkTokens&&this.walkTokens(e,i.walkTokens);let n=o(e,i);return i.hooks&&(n=i.hooks.postprocess(n)),n}catch(e){return s(e)}}}onError(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){let e="<p>An error occurred:</p><pre>"+ne(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function ue(e,t){return ge.parse(e,t)}function xe(e,t={}){const{botname:n="AI Assistant",username:a="You",botaccentColor:i="#4a57e2ff",botAvatar:s=me(),userAvatar:r=fe(),showExactTime:o=!1}=t,l=function(e){const t=e=>{const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null};let n,a,i;if(e.startsWith("#")){const s=t(e);if(!s)return!1;n=s.r,a=s.g,i=s.b}else{if(!e.startsWith("rgb"))return!1;{const t=e.match(/\d+/g);[n,a,i]=t.map(Number)}}return(.299*n+.587*a+.114*i)/255>.5}(i),c=i,p=l?"#1f2937":"#ffffff",h=function(e,t){const n=(e=>{const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null})(e);if(!n)return e;const a=Math.min(255,Math.round(n.r+(255-n.r)*t)),i=Math.min(255,Math.round(n.g+(255-n.g)*t)),s=Math.min(255,Math.round(n.b+(255-n.b)*t));return`#${a.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}(i,.85);return`<div class="aptolix-messages-wrapper">${e.map(e=>{const t="user"===e.type,i=t?r:s,l=t?a:n,d=t?c:h,g=t?p:"#4b5563",u="bot"===e.type?ue.parse(e.text):e.text,x=o?function(e){const t=new Date(e),n=new Date,a=t.toDateString()===n.toDateString(),i=new Date(n);i.setDate(i.getDate()-1);const s=t.toDateString()===i.toDateString(),r=t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});if(a)return`Today at ${r}`;if(s)return`Yesterday at ${r}`;return`${t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})} at ${r}`}(e.timestamp):function(e){const t=Date.now(),n=Math.floor((t-e)/1e3);if(n<10)return"just now";if(n<60)return`${n} secs ago`;if(n<3600){const e=Math.floor(n/60);return 1===e?"1 min ago":`${e} mins ago`}if(n<86400){const e=Math.floor(n/3600);return 1===e?"1 hour ago":`${e} hours ago`}const a=Math.floor(n/86400);return 1===a?"1 day ago":`${a} days ago`}(e.timestamp);return`\n <div class="message ${e.type}">\n <div class="message-avatar">\n ${i}\n <div class="message-sender">${l}</div>\n </div>\n <div class="message-content">\n <div class="message-text" style="background-color: ${d}; color: ${g};">\n ${u}\n </div>\n <span class="message-timestamp" data-timestamp="${e.timestamp}">${x}</span>\n ${e.rating&&e.rating>0?`\n <div class="message-rating">\n <span class="rating-stars">${"★".repeat(e.rating)}${"☆".repeat(5-e.rating)}</span>\n </div>\n `:""}\n </div>\n </div>\n `}).join("")}</div>`}function me(){return'<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="20" cy="20" r="18" fill="#9333ea"/>\n <rect x="12" y="14" width="6" height="6" rx="1" fill="#fff"/>\n <rect x="22" y="14" width="6" height="6" rx="1" fill="#fff"/>\n <rect x="13" y="26" width="14" height="4" rx="2" fill="#fff"/>\n </svg>'}function fe(){return'<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="20" cy="20" r="20" fill="#64748b"/>\n <circle cx="20" cy="15" r="6" fill="#fff"/>\n <path d="M 8 35 Q 8 25 20 25 Q 32 25 32 35" fill="#fff"/>\n </svg>'}ue.options=ue.setOptions=function(e){return ge.setOptions(e),ue.defaults=ge.defaults,r(ue.defaults),ue},ue.getDefaults=i,ue.defaults=s,ue.use=function(...e){return ge.use(...e),ue.defaults=ge.defaults,r(ue.defaults),ue},ue.walkTokens=function(e,t){return ge.walkTokens(e,t)},ue.parseInline=ge.parseInline,ue.Parser=he,ue.parser=he.parse,ue.Renderer=ce,ue.TextRenderer=pe,ue.Lexer=le,ue.lexer=le.lex,ue.Tokenizer=oe,ue.Hooks=de,ue.parse=ue,ue.options,ue.setOptions,ue.use,ue.walkTokens,ue.parseInline,he.parse,le.lex;const be="APTOLIX_INIT",we="APTOLIX_SHOW",ye="APTOLIX_READY",ke="APTOLIX_HEIGHT_CHANGE",ve="APTOLIX_CLOSE_REQUESTED";function $e(e){const t=e=>{const t=e.replace("#","").substring(0,6),n=/^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return n?{r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)}:null},n=(e,n)=>{const a=t(e);if(!a)return e;const i=Math.min(255,Math.round(a.r+(255-a.r)*n)),s=Math.min(255,Math.round(a.g+(255-a.g)*n)),r=Math.min(255,Math.round(a.b+(255-a.b)*n));return`#${i.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`},a=(e,n)=>{const a=t(e);if(!a)return e;const i=Math.max(0,Math.round(a.r*(1-n))),s=Math.max(0,Math.round(a.g*(1-n))),r=Math.max(0,Math.round(a.b*(1-n)));return`#${i.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`},i=(e,n)=>{const a=t(e);return a?`rgba(${a.r}, ${a.g}, ${a.b}, ${n})`:e},s=(e=>{let n,a,i;if(e.startsWith("#")){const s=t(e);if(!s)return!1;n=s.r,a=s.g,i=s.b}else{if(!e.startsWith("rgb"))return!1;{const t=e.match(/\d+/g);[n,a,i]=t.map(Number)}}return(.299*n+.587*a+.114*i)/255>.5})(e);return{primary:e,isLight:s,header:{background:e,text:s?"#1f2937":"#ffffff",button:s?"#374151":"#ffffff",border:n(e,.85)},messages:{userBackground:e,userText:s?"#1f2937":"#ffffff",botBackground:n(e,.85),botText:"#4b5563",link:a(e,.1),timestamp:"#9ca3af"},window:{background:n(e,.95),border:s?a(e,.2):n(e,.3),shadow:i(e,.15)},input:{background:"#ffffff",border:n(e,.85),text:"#1f2937",placeholder:"#9ca3af",buttonBackground:e,buttonText:s?"#1f2937":"#ffffff"},footer:{text:s?a(e,.3):n(e,.2),link:a(e,.1)},bubble:{background:e,icon:s?"#1f2937":"#ffffff"},hint:{background:"#ffffff",text:"#1f2937",border:n(e,.85),closeButton:e},menu:{background:"#ffffff",text:"#1f2937",hover:n(e,.9),border:"#e5e7eb"},rating:{star:"#fbbf24",text:"#6b7280"},utils:{lighten:n,darken:a,addAlpha:i,hexToRgb:t}}}const Se=window.self!==window.top;let Ie=!1,Te=null,Ce=null,_e=null,Ae=null,Re=[],Le=null,ze=null;const Ee="APTOLIX_INIT",De="APTOLIX_SHOW",Me="APTOLIX_READY",Pe="APTOLIX_HEIGHT_CHANGE",qe="APTOLIX_CLOSE_REQUESTED";function He(e,t={}){Se&&window.parent&&window.parent.postMessage({type:e,payload:t,source:"aptolix-chatbot-iframe"},"*")}async function Be(t,n){if(!Ie)return Te=t,ze=n||Te.apiHost,Ce=Te.conversationId||`${Te.chatbotId}-${Date.now()}`,Le=new e(Te.chatbotId),_e=Le.getVisitorId(Te.chatbotId),Ae=Le.getSessionId(Te.chatbotId),function(){const e=$e(Te.botaccentColor),t=Te.chatbotId;let n="";if(Te.companyLogo){n=/^https?:\/\//.test(Te.companyLogo)?`<img src="${Te.companyLogo}" alt="Company Logo" class="aptolix-company-logo" style="max-width:40px;max-height:40px;" />`:Te.companyLogo}const a=encodeURIComponent(window.location.hostname),i=encodeURIComponent("widget"),s=encodeURIComponent("refback"),r=`https://aptolix.com?utm_source=${a}&utm_medium=${i}&utm_campaign=${s}`,o=Se&&window.__parentHostname__?window.__parentHostname__:window.location.hostname,l="localhost"===o||"127.0.0.1"===o||o.startsWith("192.168.")||o.endsWith(".local")?'<span style="background: #ef4444; color: white; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; margin-left: 8px; letter-spacing: 0.5px;">LOCAL</span>':"",c=Se?"":`box-shadow: 0 4px 20px ${e.window.shadow};`,p=`\n <div id="aptolix-chat-window-${t}" class="aptolix-chat-window ${Se?"bubble-mode":"section-mode"}" style="background-color: ${e.window.background}; border-color: ${e.window.border}; ${c}">\n <div id="aptolix-chat-header-${t}" style="background-color: ${Te.botaccentColor}; color: ${e.header.text}; border-bottom: 2px solid ${e.header.border};">\n <div class="aptolix-header-flex">\n <div class="aptolix-header-title">\n ${n?`<div class="aptolix-company-logo-wrapper">${n}</div>`:""}\n <strong class="aptolix-bot-name">${Te.botname}${l}</strong>\n </div>\n <div class="aptolix-header-actions">\n ${Te.allowReset||Te.allowDownloadTranscript?`<button id="aptolix-chat-menu-${t}" title="More options" aria-label="More options" style="color: ${e.header.button};">⋮</button>`:""}\n ${Te.allowExpandChatWindow?`<button id="aptolix-chat-expand-${t}" title="Expand/Collapse" aria-label="Expand/Collapse" style="color: ${e.header.button};">\n <span id="aptolix-chat-expand-icon-${t}">⤢</span>\n </button>`:""}\n <button id="aptolix-chat-close-${t}" title="Close chat" aria-label="Close chat" style="color: ${e.header.button};">×</button>\n ${Te.allowReset||Te.allowDownloadTranscript?`<div id="aptolix-chat-menu-dropdown-${t}" class="aptolix-menu-dropdown" style="background-color: ${e.menu.background}; border-color: ${e.menu.border}; border: 1px solid ${e.menu.border};">\n ${Te.allowReset?`<button id="aptolix-chat-reset-${t}" class="aptolix-menu-item" title="Reset chat" aria-label="Reset chat" style="background-color: ${e.menu.background}; color: ${e.menu.text};">\n <span class="aptolix-menu-icon">⟲</span>\n <span class="aptolix-menu-text">Reset Chat</span>\n </button>`:""}\n ${Te.allowDownloadTranscript?`<button id="aptolix-chat-download-${t}" class="aptolix-menu-item" title="Download chat" aria-label="Download chat" style="background-color: ${e.menu.background}; color: ${e.menu.text};">\n <span class="aptolix-menu-icon">⤓</span>\n <span class="aptolix-menu-text">Download Chat</span>\n </button>`:""}\n </div>`:""}\n </div>\n </div>\n </div>\n <div id="aptolix-chat-messages-${t}" style="background-color: ${e.window.background}; position: relative;">\n </div>\n <div id="aptolix-chat-input-${t}" style="border-top: 2px solid ${e.input.border};">\n <textarea id="aptolix-chat-inputbox-${t}" rows="1" placeholder="Type your message..." style="resize:none; border-color: ${e.input.border}; background-color: ${e.window.background};"></textarea>\n <button style="background-color: ${Te.botaccentColor}; color: ${e.input.buttonText};">Send</button>\n </div>\n <div class="aptolix-footer">\n <div class="aptolix-powered-by" style="color: ${e.footer.text};">\n Powered by <a href="${r}" target="_blank" rel="noopener" class="aptolix-link" style="color: ${Te.botaccentColor};">Aptolix</a>\n </div>\n ${Te.allowRating?`<span class="aptolix-footer-separator">|</span>\n <div class="aptolix-rating" id="aptolix-rating-${t}">\n <span class="aptolix-rating-label">Rate this chat:</span>\n <div class="aptolix-stars" id="aptolix-stars-${t}">\n <span class="star" data-rating="1">☆</span>\n <span class="star" data-rating="2">☆</span>\n <span class="star" data-rating="3">☆</span>\n <span class="star" data-rating="4">☆</span>\n <span class="star" data-rating="5">☆</span>\n </div>\n </div>`:""}\n </div>\n </div>\n `;if(Se)document.body.innerHTML=p,document.documentElement.style.height="100%",document.documentElement.style.margin="0",document.documentElement.style.padding="0",document.body.style.height="100%",document.body.style.margin="0",document.body.style.padding="0",document.body.style.overflow="hidden",document.body.style.fontFamily="'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";else{let e=document.body;if(Te.target){const t="string"==typeof Te.target?document.querySelector(Te.target):Te.target;t&&(e=t)}e.insertAdjacentHTML("beforeend",p)}}(),await async function(){const e=Le.getConversationHistory();e&&e.length>0&&(Re=e,function(){const e=document.querySelector(`#aptolix-chat-messages-${Te.chatbotId}`);if(!e)return;const t=$e(Te.botaccentColor);e.innerHTML=xe(Re,{botAvatar:Te.botAvatar,userAvatar:Te.userAvatar,botName:Te.botname,userName:Te.username||"You",accentColor:Te.botaccentColor,userBgColor:t.messages.userBackground,userTextColor:t.messages.userText,botBgColor:t.messages.botBackground,botTextColor:t.messages.botText,timestampColor:t.messages.timestamp,useExactTime:!1}),Fe(),Ze()}())}(),function(){const e=Te.chatbotId,t=$e(Te.botaccentColor),n=document.querySelector(`#aptolix-chat-close-${e}`),a=Te.allowReset?document.querySelector(`#aptolix-chat-reset-${e}`):null,i=Te.allowExpandChatWindow?document.querySelector(`#aptolix-chat-expand-${e}`):null,s=Te.allowExpandChatWindow?document.querySelector(`#aptolix-chat-expand-icon-${e}`):null,r=document.querySelector(`#aptolix-chat-inputbox-${e}`),o=document.querySelector(`#aptolix-chat-input-${e} button`);document.querySelector(`#aptolix-chat-messages-${e}`);const l=Te.allowDownloadTranscript?document.querySelector(`#aptolix-chat-download-${e}`):null,c=Te.allowReset||Te.allowDownloadTranscript?document.querySelector(`#aptolix-chat-menu-${e}`):null,p=Te.allowReset||Te.allowDownloadTranscript?document.querySelector(`#aptolix-chat-menu-dropdown-${e}`):null;n&&n.addEventListener("click",()=>{if(Se)He(qe);else{const t=document.querySelector(`#aptolix-chat-window-${e}`);t&&(t.style.display="none")}});a&&a.addEventListener("click",async()=>{confirm("Are you sure you want to reset the chat? This will clear all messages.")&&await async function(){Re=[],Ce=`${Te.chatbotId}-${Date.now()}`,Ae=null,Le.clearSessionId(Te.chatbotId),Le.clearConversationHistory();const e=document.querySelector(`#aptolix-chat-messages-${Te.chatbotId}`);e&&(e.innerHTML="");We(),Ze()}(),p&&(p.style.display="none")});if(i&&s){let t=!1;i.addEventListener("click",()=>{t=!t;const n=document.querySelector(`#aptolix-chat-window-${e}`);t?(n.classList.add("expanded"),s.textContent="⤡"):(n.classList.remove("expanded"),s.textContent="⤢"),Se&&He("APTOLIX_EXPAND_TOGGLE",{isExpanded:t}),Ze()})}l&&l.addEventListener("click",()=>{!function(){let e=`Aptolix Chat Transcript - ${Te.botname}\n`;e+=`Date: ${(new Date).toLocaleString()}\n`,e+=`${"=".repeat(50)}\n\n`,Re.forEach(t=>{const n=new Date(t.timestamp).toLocaleString(),a="user"===t.type?Te.username||"You":Te.botname;e+=`[${n}] ${a}:\n${t.text}\n\n`});const t=new Blob([e],{type:"text/plain"}),n=URL.createObjectURL(t),a=document.createElement("a");a.href=n,a.download=`chat-transcript-${Date.now()}.txt`,a.click(),URL.revokeObjectURL(n)}(),p&&(p.style.display="none")});if(c&&p){c.addEventListener("click",e=>{e.stopPropagation();const t="block"===p.style.display;p.style.display=t?"none":"block"}),document.addEventListener("click",()=>{p.style.display="none"});p.querySelectorAll(".aptolix-menu-item").forEach(e=>{e.addEventListener("mouseenter",()=>{e.style.backgroundColor=t.menu.hover}),e.addEventListener("mouseleave",()=>{e.style.backgroundColor=t.menu.background})})}r&&(r.addEventListener("focus",()=>{r.style.borderColor=t.primary}),r.addEventListener("blur",()=>{r.style.borderColor=t.input.border}),r.addEventListener("keydown",e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),Ne())}),r.addEventListener("input",()=>{r.style.height="auto",r.style.height=r.scrollHeight+"px",Ze()}),Te.inputCharLimit&&r.setAttribute("maxlength",Te.inputCharLimit));o&&o.addEventListener("click",Ne);if(Te.allowRating){document.querySelectorAll(`#aptolix-stars-${e} .star`).forEach(e=>{e.addEventListener("click",()=>{!async function(e){Le.saveRating(Ce,e),Ue(e);try{await fetch(`${ze}/chatbot/${Te.chatbotId}/rating`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chatbot_id:Te.chatbotId,visitor_id:_e,session_id:Ae,rating:e})})}catch(e){console.error("Failed to submit rating:",e)}}(parseInt(e.getAttribute("data-rating")))}),e.addEventListener("mouseenter",()=>{Ue(parseInt(e.getAttribute("data-rating")))})});const t=document.querySelector(`#aptolix-stars-${e}`);t&&t.addEventListener("mouseleave",()=>{Ue(Le.getRating(Ce)||0)})}}(),0===Re.length&&We(),Ie=!0,Se&&He(Me),Se&&Ze(),Te.chatbotId}function We(){if(!Te.greetingMessage)return;const e={text:Te.greetingMessage,type:"bot",timestamp:Date.now(),messageId:`greeting-${Date.now()}`};Re.push(e),Oe(e)}function Oe(e){const t=document.querySelector(`#aptolix-chat-messages-${Te.chatbotId}`);if(!t)return;const n=$e(Te.botaccentColor),a=xe([e],{botAvatar:Te.botAvatar,userAvatar:Te.userAvatar,botName:Te.botname,userName:Te.username||"You",accentColor:Te.botaccentColor,userBgColor:n.messages.userBackground,userTextColor:n.messages.userText,botBgColor:n.messages.botBackground,botTextColor:n.messages.botText,timestampColor:n.messages.timestamp,useExactTime:!1});t.insertAdjacentHTML("beforeend",a),Fe(),Ze()}async function Ne(){const e=document.querySelector(`#aptolix-chat-inputbox-${Te.chatbotId}`);if(!e)return;const t=e.value.trim();if(!t)return;e.value="",e.style.height="auto";const n={text:t,type:"user",timestamp:Date.now(),messageId:`user-${Date.now()}`};Re.push(n),Oe(n),Le.saveConversationHistory(Re),function(){const e=document.querySelector(`#aptolix-chat-messages-${Te.chatbotId}`);if(!e)return;const t=$e(Te.botaccentColor),n=document.createElement("div");n.id="aptolix-typing-indicator",n.innerHTML=`\n <div class="aptolix-messages-wrapper">\n <div class="message bot typing">\n <div class="message-avatar">\n ${Te.botAvatar}\n </div>\n <div class="message-content">\n <div class="message-text" style="background-color: ${t.messages.botBackground}; color: ${t.messages.botText};">\n <span class="typing-dots">\n <span>.</span><span>.</span><span>.</span>\n </span>\n </div>\n </div>\n </div>\n </div>\n `,e.appendChild(n),Fe(),Ze()}();try{const e=await fetch(`${ze}/chatbot/${Te.chatbotId}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:t,chatbot_id:Te.chatbotId,visitor_id:_e,session_id:Ae})});if(!e.ok)throw new Error(`API error: ${e.status}`);je({data:await e.json()})}catch(e){je({error:e.message})}}function je(e){if(function(){const e=document.getElementById("aptolix-typing-indicator");e&&(e.remove(),Ze())}(),e.error){const t={text:`Error: ${e.error}`,type:"bot",timestamp:Date.now(),messageId:`error-${Date.now()}`};return Re.push(t),void Oe(t)}const t=e.data;t.visitor_id&&(_e=t.visitor_id,Le.saveVisitorId(Te.chatbotId,_e)),t.session_id&&(Ae=t.session_id,Le.saveSessionId(Te.chatbotId,Ae));const n={text:t.response||t.message||"No response",type:"bot",timestamp:Date.now(),messageId:t.message_id||`bot-${Date.now()}`};Re.push(n),Oe(n),Le.saveConversationHistory(Re)}function Ue(e){document.querySelectorAll(`#aptolix-stars-${Te.chatbotId} .star`).forEach((t,n)=>{t.textContent=n<e?"★":"☆"})}function Fe(){const e=document.querySelector(`#aptolix-chat-messages-${Te.chatbotId}`);e&&(e.scrollTop=e.scrollHeight)}function Ze(){requestAnimationFrame(()=>{const e=document.body.scrollHeight;He(Pe,{height:e})})}Se&&(window.addEventListener("message",e=>{if(e.source!==window.parent)return;const{type:t,payload:n}=e.data;switch(t){case Ee:Be(n,n.apiHost);break;case De:setTimeout(()=>Fe(),50)}}),He(Me));const Ge=new Map,Qe={init:async({apiHost:e,chatbotId:n,botname:i,widgetIcon:s,companyLogo:r,companyLogoUrl:o,botAvatar:l,botavatarUrl:c,botaccentColor:p,floatingWelcomeMessage:h,floatingWelcomeDelay:d,greetingMessage:g,allowDownloadTranscript:u,allowExpandChatWindow:x,allowFullPageChat:m,inputCharLimit:f,allowReset:b,allowRating:w,ratingThreshold:y,ratingInterval:k,mode:v="bubble",target:$})=>{if(e&&n){if(Ge.has(n)){console.error(`Duplicate chatbot detected: Chatbot ID "${n}" is already initialized on this page.`);const e=document.createElement("div");if(e.id=`window-${n}-error`,e.className="aptolix-chat-window",e.style.cssText="\n position: fixed;\n bottom: 100px;\n right: 32px;\n width: 400px;\n max-width: calc(100vw - 64px);\n background: #fee;\n border: 2px solid #f44;\n border-radius: 16px;\n padding: 20px;\n box-shadow: 0 4px 20px rgba(244, 67, 54, 0.3);\n z-index: 9998;\n font-family: 'Inter', sans-serif;\n ",e.innerHTML=`\n <div style="text-align: center;">\n <div style="font-size: 48px; margin-bottom: 10px;">⚠️</div>\n <h3 style="margin: 0 0 10px 0; color: #c62828; font-size: 1.1rem;">Duplicate Chatbot Detected</h3>\n <p style="margin: 0 0 15px 0; color: #666; font-size: 0.9rem; line-height: 1.5;">\n A chatbot with ID <strong style="color: #c62828;">${n}</strong> is already active on this page.\n </p>\n <p style="margin: 0; color: #888; font-size: 0.85rem; line-height: 1.4;">\n <strong>Solution:</strong> Use different Chatbot IDs for multiple chatbots on the same page.\n </p>\n <button onclick="this.parentElement.parentElement.remove()" style="\n margin-top: 15px;\n padding: 8px 16px;\n background: #c62828;\n color: white;\n border: none;\n border-radius: 6px;\n cursor: pointer;\n font-weight: 600;\n ">Close</button>\n </div>\n `,"bubble"===v)document.body.appendChild(e),setTimeout(()=>e.remove(),1e4);else if("section"===v&&$){const t="string"==typeof $?document.querySelector($):$;t&&(e.style.position="static",e.style.width="100%",e.style.height="100%",e.style.display="flex",e.style.alignItems="center",e.style.justifyContent="center",t.appendChild(e))}return null}Ge.set(n,{initializing:!0});try{const S=await a(e,n),I={botname:i||S?.botname||t.botname,widgetIcon:s||S?.widgetIcon||t.widgetIcon,companyLogo:r||S?.companyLogo||t.companyLogo,companyLogoUrl:o||S?.companyLogoUrl||"",botAvatar:l||S?.botAvatar||t.botAvatar,botavatarUrl:c||S?.botavatarUrl||"",userAvatar:S?.userAvatar||t.userAvatar,username:S?.username||t.username,botaccentColor:p||S?.botaccentColor||t.botaccentColor,floatingWelcomeMessage:h||S?.floatingWelcomeMessage||t.floatingWelcomeMessage,floatingWelcomeDelay:d||S?.floatingWelcomeDelay||t.floatingWelcomeDelay,greetingMessage:g||S?.greetingMessage||t.greetingMessage,allowDownloadTranscript:void 0!==u?u:void 0!==S?.allowDownloadTranscript?S.allowDownloadTranscript:t.allowDownloadTranscript,allowExpandChatWindow:void 0!==x?x:void 0!==S?.allowExpandChatWindow?S.allowExpandChatWindow:t.allowExpandChatWindow,allowFullPageChat:void 0!==m?m:void 0!==S?.allowFullPageChat?S.allowFullPageChat:t.allowFullPageChat,inputCharLimit:f||S?.inputCharLimit||t.inputCharLimit,allowReset:void 0!==b?b:void 0!==S?.allowReset?S.allowReset:t.allowReset,allowRating:void 0!==w?w:void 0!==S?.allowRating?S.allowRating:t.allowRating,ratingThreshold:y||S?.ratingThreshold||t.ratingThreshold,ratingInterval:k||S?.ratingInterval||t.ratingInterval,mode:v||t.mode,target:$},T=e=>!(!e||"string"!=typeof e)&&/^https?:\/\/.+/.test(e.trim()),C=async e=>new Promise(t=>{const n=new Image,a=setTimeout(()=>{n.src="",t(!1)},3e3);n.onload=()=>{clearTimeout(a),t(!0)},n.onerror=()=>{clearTimeout(a),t(!1)},n.src=e}),_=e=>{if(!e||"string"!=typeof e)return!1;if(!/^\s*<svg[\s\S]*<\/svg>\s*$/i.test(e))return!1;try{const t=(new DOMParser).parseFromString(e,"image/svg+xml");return!t.querySelector("parsererror")}catch(e){return!1}},A=$e(I.botaccentColor),R=(A.isLight,A.messages.userBackground,A.messages.userText,A.messages.botBackground,A.messages.botText,A.messages.link,A.header.text,A.header.button,A.input.buttonText,A.window.border,A.window.background,A.input.border,A.header.border,A.footer.text,A.window.shadow,r||S?.companyLogo);let L=R,z=!1;if(R&&T(R)){await C(R)||(z=!0)}else R&&!_(R)&&(z=!0);I.companyLogo=z?null:L;const E=I.botAvatar;let D=E,M=!1;if(E&&T(E)){await C(E)||(M=!0)}else E&&!_(E)&&(M=!0);if(I.botAvatar=M?null:D,"bubble"===I.mode){const t=await async function(e,t){const n=e.chatbotId;let a=null,i=null,s=null,r=!1;i=document.createElement("div"),i.id=`bubble-${n}`,i.className="aptolix-chat-bubble",i.setAttribute("data-chatbot-id",n),i.style.backgroundColor=e.botaccentColor;const o=e.widgetIcon;o.includes("<svg")||o.includes("<")&&o.includes(">")?i.innerHTML=o:i.innerText=o,document.body.appendChild(i),s=document.createElement("div"),s.id=`hint-${n}`,s.className="aptolix-hint-bubble",s.setAttribute("data-chatbot-id",n),s.style.display="none",s.style.position="fixed",s.style.right="40px",s.style.bottom="110px",s.style.zIndex="9999";const l=document.createElement("span");l.textContent=e.floatingWelcomeMessage;const c=document.createElement("button");let p;c.id="aptolix-hint-close",c.title="Close",c.setAttribute("aria-label","Close"),c.innerHTML="&#10005;",c.style.background="none",c.style.border="none",c.style.color=e.botaccentColor,c.style.fontSize="1.3em",c.style.position="absolute",c.style.top="8px",c.style.right="12px",c.style.cursor="pointer",c.style.padding="0",c.addEventListener("click",()=>{s.style.display="none",sessionStorage.setItem("aptolixHintClosed","true"),clearTimeout(p)}),s.appendChild(l),s.appendChild(c),document.body.appendChild(s),p=setTimeout(()=>{a&&"none"===a.style.display&&!sessionStorage.getItem("aptolixHintClosed")&&(s.style.display="block")},1e3*e.floatingWelcomeDelay),a=document.createElement("iframe"),a.id=`iframe-${n}`,a.className="aptolix-chat-iframe",a.setAttribute("data-chatbot-id",n);const h=window.innerWidth<=768;let d;a.style.cssText=`\n position: fixed;\n bottom: ${h?"80px":"100px"};\n right: ${h?"16px":"32px"};\n width: ${h?"calc(100vw - 32px)":"500px"};\n max-width: calc(100vw - ${h?"32px":"64px"});\n height: ${h?"calc(100vh - 120px)":"650px"};\n max-height: calc(100vh - ${h?"120px":"150px"});\n min-height: ${h?"400px":"450px"};\n border: none;\n border-radius: 16px;\n box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);\n z-index: 9998;\n display: none;\n background: white;\n transition: opacity 0.3s ease, transform 0.3s ease;\n `,window.addEventListener("resize",()=>{clearTimeout(d),d=setTimeout(()=>{const e=window.innerWidth<=768;a.style.bottom=e?"80px":"100px",a.style.right=e?"16px":"32px",a.style.width=e?"calc(100vw - 32px)":"500px",a.style.maxWidth=`calc(100vw - ${e?"32px":"64px"})`,a.style.height=e?"calc(100vh - 120px)":"650px",a.style.maxHeight=`calc(100vh - ${e?"120px":"150px"})`,a.style.minHeight=e?"400px":"450px"},100)});const g=new URL(import.meta.url),u=g.origin+g.pathname.substring(0,g.pathname.lastIndexOf("/"))+"/chatbot-core.mjs";console.log("[Aptolix] import.meta.url:",import.meta.url),console.log("[Aptolix] chatbotCoreUrl:",u);const x=window.location.hostname,m=`\n <!DOCTYPE html>\n <html lang="en">\n <head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <title>Aptolix Chat</title>\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n body {\n margin: 0;\n padding: 0;\n overflow: hidden;\n font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;\n }\n </style>\n </head>\n <body>\n <script>\n // Store parent hostname for LOCAL badge detection\n window.__parentHostname__ = ${JSON.stringify(x)};\n <\/script>\n <script type="module" src="${u}"><\/script>\n </body>\n </html>\n `;a.srcdoc=m,document.body.appendChild(a);const f=async i=>{if(i.source!==a.contentWindow)return;if(!i.data||"aptolix-chatbot-iframe"!==i.data.source)return;const{type:s,payload:o}=i.data;switch(s){case ye:b(be,{...e,apiHost:t,chatbotId:n,conversationId:`${n}-${Date.now()}`});break;case ke:o.height&&!r&&(a.style.height=Math.min(o.height,window.innerHeight-150)+"px");break;case"APTOLIX_EXPAND_TOGGLE":r=!!o.isExpanded;const i=window.innerWidth<=768;o.isExpanded?i?(a.style.width="calc(100vw - 16px)",a.style.maxWidth="calc(100vw - 16px)",a.style.height="calc(100vh - 80px)",a.style.maxHeight="calc(100vh - 80px)",a.style.minHeight="calc(100vh - 80px)",a.style.right="8px",a.style.bottom="70px"):(a.style.width="900px",a.style.maxWidth="900px",a.style.height="calc(100vh - 130px)",a.style.maxHeight="calc(100vh - 130px)",a.style.minHeight="calc(100vh - 130px)",a.style.right="32px",a.style.bottom="100px"):i?(a.style.minHeight="",a.style.width="calc(100vw - 32px)",a.style.maxWidth="calc(100vw - 32px)",a.style.height="calc(100vh - 120px)",a.style.maxHeight="calc(100vh - 120px)",a.style.minHeight="400px",a.style.right="16px",a.style.bottom="80px"):(a.style.minHeight="",a.style.width="500px",a.style.maxWidth="calc(100vw - 64px)",a.style.height="650px",a.style.maxHeight="calc(100vh - 150px)",a.style.minHeight="450px",a.style.right="32px",a.style.bottom="100px");break;case ve:a.style.display="none"}};function b(e,t={}){a&&a.contentWindow&&a.contentWindow.postMessage({type:e,payload:t},"*")}window.addEventListener("message",f),i.addEventListener("click",()=>{"none"===a.style.display?(a.style.display="block",s.style.display="none",clearTimeout(p),b(we)):a.style.display="none"});const w=new MutationObserver(()=>{"block"===a.style.display&&(s.style.display="none",clearTimeout(p))});return w.observe(a,{attributes:!0,attributeFilter:["style"]}),{bubbleId:i.id,hintBubbleId:s.id,iframeId:a.id,destroy:()=>{window.removeEventListener("message",f),w.disconnect(),i&&i.remove(),s&&s.remove(),a&&a.remove(),clearTimeout(p)}}}({...I,chatbotId:n,apiHost:e},e);return void Ge.set(n,{mode:"bubble",...t})}const P=await Be({...I,chatbotId:n},e);return Ge.set(n,{chatWindowId:`aptolix-chat-window-${n}`,mode:"section"}),P}catch(e){throw Ge.delete(n),console.error(`Failed to initialize chatbot ${n}:`,e),e}}else console.error("apiHost and chatbotId are mandatory parameters")},initFull:function(e){let t=document.querySelector("aptolix-chatbot");t&&Object.entries(e).forEach(([e,n])=>{t.setAttribute(e,n)})},destroy:function(e=null){if(e){const t=Ge.get(e);if(t){if("bubble"===t.mode&&t.destroy)t.destroy();else if(t.chatWindowId){const e=document.getElementById(t.chatWindowId);e&&e.remove()}Ge.delete(e)}const n=document.getElementById(`window-${e}-error`);n&&n.remove()}else Ge.forEach((e,t)=>{e.destroy&&e.destroy()}),document.querySelectorAll(".aptolix-chat-bubble").forEach(e=>e.remove()),document.querySelectorAll(".aptolix-hint-bubble").forEach(e=>e.remove()),document.querySelectorAll(".aptolix-chat-iframe").forEach(e=>e.remove()),document.querySelectorAll(".aptolix-chat-window").forEach(e=>e.remove()),document.querySelectorAll('[id$="-error"]').forEach(e=>{e.id.startsWith("window-")&&e.remove()}),Ge.clear()},getActiveInstances:function(){return Array.from(Ge.keys())}};class Xe extends HTMLElement{static get observedAttributes(){return["apihost","chatbotid","botname","widgeticon","companylogo","companylogourl","botavatar","botavatarurl","botaccentcolor","floatingwelcomemessage","floatingwelcomedelay","greetingmessage","allowdownloadtranscript","allowexpandchatwindow","allowfullpagechat","inputcharlimit","target"]}connectedCallback(){this.tryInit()}attributeChangedCallback(){this._initialized&&(clearTimeout(this._reinitTimeout),this._reinitTimeout=setTimeout(()=>{const e=this.getAttribute("chatbotid");e&&Qe.destroy(e),this._initialized=!1,this.tryInit()},100))}tryInit(){const e=this.getAttribute("apihost"),t=this.getAttribute("chatbotid");if(!e||!t)return;const n=this.getAttribute("botname"),a=this.getAttribute("widgeticon"),i=this.getAttribute("companylogo"),s=this.getAttribute("companylogourl"),r=this.getAttribute("botavatar"),o=this.getAttribute("botavatarurl"),l=this.getAttribute("botaccentcolor"),c=this.getAttribute("floatingwelcomemessage"),p=this.getAttribute("floatingwelcomedelay"),h=this.getAttribute("greetingmessage"),d="true"===this.getAttribute("allowdownloadtranscript"),g="true"===this.getAttribute("allowexpandchatwindow"),u="true"===this.getAttribute("allowfullpagechat"),x=parseInt(this.getAttribute("inputcharlimit"))||void 0,m=this.getAttribute("target");let f=this;if(m){const e=document.querySelector(m);e&&(f=e)}this._initialized||(this._initialized=!0,Qe.init({apiHost:e,chatbotId:t,botname:n,widgetIcon:a,companyLogo:i,companyLogoUrl:s,botAvatar:r,botavatarUrl:o,botaccentColor:l,floatingWelcomeMessage:c,floatingWelcomeDelay:p,greetingMessage:h,allowDownloadTranscript:d,allowExpandChatWindow:g,allowFullPageChat:u,inputCharLimit:x,mode:"section",target:f}))}}customElements.get("aptolix-chatbot")||customElements.define("aptolix-chatbot",Xe);export{Qe as default,xe as formatMessages};
1
+ !function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var a=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===n&&a.firstChild?a.insertBefore(i,a.firstChild):a.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}('.aptolix-chat-window{box-sizing:border-box;display:flex;flex-direction:column;font-family:Inter,sans-serif;height:100%;margin:0;max-height:100%;max-width:100%;min-height:0;min-width:0;overflow:hidden;width:100%}[id^=aptolix-chat-header]{align-items:center;border-bottom-style:solid;border-bottom-width:2px;color:#fff;display:flex;font-size:1.15rem;font-weight:200;justify-content:space-between;padding:10px 13px}.aptolix-header-title{align-items:center;display:flex;flex:1;flex-direction:row;gap:12px;justify-content:flex-start;min-width:0}.aptolix-company-logo-wrapper{align-items:center;display:flex;flex-shrink:0}.aptolix-bot-name{align-items:center;display:flex;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;font-size:1rem;font-weight:600;letter-spacing:.01em;line-height:1.2;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.aptolix-header-subtitle{color:#ede9fe;font-size:.95rem;font-weight:400;margin-top:2px}.aptolix-header-actions{align-items:center;display:flex;gap:6px;margin-top:0;position:relative}.aptolix-menu-dropdown{background:#fff;border:1px solid rgba(0,0,0,.08);border-radius:6px;box-shadow:0 2px 8px rgba(0,0,0,.15);display:none;flex-direction:column;gap:0;min-width:120px;overflow:hidden;padding:3px 0;position:absolute;right:0;top:calc(100% + 6px);z-index:1000}.aptolix-menu-dropdown.show{display:flex}.aptolix-menu-item{align-items:center;background:transparent;border:none;color:#4b5563;cursor:pointer;direction:ltr;display:flex;gap:7px;justify-content:flex-start!important;padding:6px 10px;text-align:left!important;transition:background-color .1s ease;white-space:nowrap;width:100%}.aptolix-menu-item:hover{background-color:#f9fafb;color:#1f2937}.aptolix-menu-icon{align-items:center;display:inline-flex;flex-shrink:0;font-size:14px!important;justify-content:flex-start!important;line-height:1;text-align:left!important;width:14px}.aptolix-menu-text{flex:1;font-size:12px!important;font-weight:400;line-height:1.3;text-align:left!important}[id^=aptolix-chat-header] button{align-items:center;background:transparent;border:none;border-radius:6px;color:#fff;cursor:pointer;display:flex;font-size:22px;justify-content:center;min-height:20px;min-width:20px;transition:all .2s}[id^=aptolix-chat-header] button:hover{background:hsla(0,0%,100%,.15);transform:scale(1.05)}[id^=aptolix-chat-header] button:active{background:hsla(0,0%,100%,.25);transform:scale(.95)}.aptolix-header-flex{align-items:center;display:flex;justify-content:space-between;width:100%}[id^=aptolix-chat-messages]{display:flex;flex:1 1 auto;flex-direction:column;gap:10px;min-height:120px;overflow-y:auto;padding:18px 16px 16px}.aptolix-footer{align-items:center;background:transparent;display:flex;gap:10px;justify-content:center;min-height:36px;padding:0 8px}.aptolix-footer-separator{color:#d1d5db;font-size:.75rem;opacity:0;transition:opacity .4s ease .1s;user-select:none}.aptolix-footer-separator.show{opacity:1}.aptolix-powered-by{background:transparent;flex:0 0 auto;font-size:.75rem;font-weight:500;letter-spacing:.01em;padding:8px 0;text-align:center;transition:all .3s ease;white-space:nowrap}.aptolix-powered-by .aptolix-link{font-family:inherit;font-weight:600;text-decoration:underline}.aptolix-rating{align-items:center;color:#6b7280;display:flex;flex:0 0 auto;font-size:.75rem;gap:6px;max-width:0;opacity:0;overflow:hidden;transition:max-width .4s ease,opacity .4s ease,visibility .4s ease;visibility:hidden}.aptolix-rating.show{max-width:200px;opacity:1;visibility:visible}.aptolix-rating-label{font-size:.75rem;font-weight:500;white-space:nowrap}.aptolix-stars{align-items:center;display:flex;gap:2px}.star{color:#fbbf24;cursor:pointer;font-size:1.1rem;line-height:1;transition:transform .1s ease;user-select:none}.star:hover{transform:scale(1.1)}[id^=aptolix-chat-input]{align-items:center;background:#fff;border-top-style:solid;border-top-width:2px;display:flex;gap:8px;min-height:56px;padding:5px 10px}[id^=aptolix-chat-input] input{border:1.5px solid;border-radius:10px;flex:1 1 auto;font-size:1rem;min-width:0;padding:10px 14px;transition:border .2s}[id^=aptolix-chat-input] input:focus{outline:none}[id^=aptolix-chat-input] button{border:none;border-radius:10px;box-shadow:0 2px 8px rgba(0,0,0,.1);cursor:pointer;flex-shrink:0;font-size:1rem;font-weight:600;padding:8px 18px;transition:background .2s,box-shadow .2s}[id^=aptolix-chat-input] button:hover{box-shadow:0 4px 16px rgba(0,0,0,.15)}[id^=aptolix-chat-input] button:not(:first-child){background:rgba(167,139,250,.12);border-radius:8px;box-shadow:none;color:#9333ea;font-size:1.1rem;font-weight:500;padding:8px 12px}[id^=aptolix-chat-input] button:not(:first-child):hover{background:rgba(167,139,250,.22);color:#4b5563}[id^=aptolix-chat-inputbox]{border:1px solid;border-radius:4px;box-sizing:border-box;font-family:inherit;font-size:1rem;max-height:130px;min-height:42px;outline:none;overflow-y:auto;padding:6px 12px;resize:none;transition:border-color .2s;width:100%}.aptolix-messages-wrapper{display:flex;flex-direction:column;gap:10px;width:100%}.aptolix-messages-wrapper .message{align-items:flex-end;display:flex;font-family:Inter,sans-serif;gap:4px;margin-bottom:0;max-width:100%}.aptolix-messages-wrapper .message.user{align-self:flex-end;flex-direction:row-reverse}.aptolix-messages-wrapper .message.bot{align-self:flex-start;flex-direction:row}.aptolix-messages-wrapper .message-avatar{cursor:pointer;flex-shrink:0;height:16px;opacity:.7;position:relative;transition:opacity .2s;width:16px}.aptolix-messages-wrapper .message-avatar:hover{opacity:1}.aptolix-messages-wrapper .message-avatar img,.aptolix-messages-wrapper .message-avatar svg{border-radius:50%;height:16px;width:16px}.aptolix-messages-wrapper .message-sender{background:rgba(0,0,0,.8);border-radius:4px;bottom:100%;color:#fff;font-size:.75rem;font-weight:500;left:0;margin-bottom:4px;opacity:0;padding:4px 8px;pointer-events:none;position:absolute;transition:opacity .2s;white-space:nowrap;z-index:1000}.aptolix-messages-wrapper .message-avatar:hover .message-sender{opacity:1}.aptolix-messages-wrapper .message.user .message-sender{left:auto;right:0}.aptolix-messages-wrapper .message-content{align-items:flex-start;display:flex;flex-direction:column;gap:0;justify-content:flex-start;max-width:88%;min-width:0}.aptolix-messages-wrapper .message.user .message-content{align-items:flex-end}.aptolix-messages-wrapper .message-text{border-radius:14px;font-weight:500;line-height:1.5;margin-bottom:0;padding:8px 14px;word-break:break-word}.aptolix-messages-wrapper .message.user .message-text{border-radius:14px 14px 4px 14px;box-shadow:0 2px 8px rgba(167,139,250,.1)}.aptolix-messages-wrapper .message.bot .message-text{border-radius:14px 14px 14px 4px;box-shadow:0 2px 8px rgba(167,139,250,.08);margin-bottom:0}.aptolix-messages-wrapper .message-timestamp{align-self:flex-start;background:none;color:#9ca3af;font-size:.7rem;line-height:1.2;margin-top:2px;padding:0 8px;position:relative;z-index:1}.aptolix-messages-wrapper .message.user .message-timestamp{align-self:flex-end}.aptolix-messages-wrapper .message-rating{align-items:center;display:flex;margin-top:4px;padding:0 8px}.aptolix-messages-wrapper .message-rating .rating-stars{color:#fbbf24;font-size:.85rem;letter-spacing:1px}.aptolix-messages-wrapper .message-text a{color:inherit;text-decoration:underline;transition:opacity .2s;word-break:break-word}.aptolix-messages-wrapper .message-text a:hover{opacity:.8}.aptolix-messages-wrapper .message-text b,.aptolix-messages-wrapper .message-text strong{font-weight:700}.aptolix-messages-wrapper .message-text em,.aptolix-messages-wrapper .message-text i{font-style:italic}.aptolix-messages-wrapper .message-text h1,.aptolix-messages-wrapper .message-text h2,.aptolix-messages-wrapper .message-text h3{font-size:1.3rem;font-weight:600;line-height:1.3;margin:14px 0 8px}.aptolix-messages-wrapper .message-text h1:first-child,.aptolix-messages-wrapper .message-text h2:first-child,.aptolix-messages-wrapper .message-text h3:first-child{margin-top:0}.aptolix-messages-wrapper .message-text h2{font-size:1.15rem}.aptolix-messages-wrapper .message-text h3{font-size:1.05rem}.aptolix-messages-wrapper .message-text p{line-height:1.6;margin:8px 0}.aptolix-messages-wrapper .message-text p:first-child{margin-top:0}.aptolix-messages-wrapper .message-text p:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text ol,.aptolix-messages-wrapper .message-text ul{line-height:1.6;margin:8px 0;padding-left:0}.aptolix-messages-wrapper .message-text ol:first-child,.aptolix-messages-wrapper .message-text ul:first-child{margin-top:0}.aptolix-messages-wrapper .message-text ol:last-child,.aptolix-messages-wrapper .message-text ul:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text ul{list-style:none}.aptolix-messages-wrapper .message-text ol{list-style:decimal;padding-left:1.5em}.aptolix-messages-wrapper .message-text ul li{margin-bottom:6px;padding-left:1.5em;position:relative}.aptolix-messages-wrapper .message-text ul li:before{background:currentColor;border-radius:50%;content:"";height:.4em;left:.4em;opacity:.7;position:absolute;top:.65em;width:.4em}.aptolix-messages-wrapper .message-text ol li{margin-bottom:6px;padding-left:.3em}.aptolix-messages-wrapper .message-text li:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text blockquote{background:rgba(0,0,0,.03);border-left:3px solid;border-radius:0 6px 6px 0;font-style:italic;margin:10px 0;opacity:.8;padding:8px 12px}.aptolix-messages-wrapper .message-text blockquote:first-child{margin-top:0}.aptolix-messages-wrapper .message-text blockquote:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text code{background:rgba(0,0,0,.08);border-radius:4px;color:inherit;font-family:Fira Mono,Consolas,Monaco,monospace;font-size:.9em;font-weight:500;padding:2px 6px}.aptolix-messages-wrapper .message-text pre{background:rgba(0,0,0,.05);border:1px solid rgba(0,0,0,.1);border-radius:6px;margin:10px 0;overflow-x:auto;padding:12px}.aptolix-messages-wrapper .message-text pre:first-child{margin-top:0}.aptolix-messages-wrapper .message-text pre:last-child{margin-bottom:0}.aptolix-messages-wrapper .message-text pre code{background:transparent;border-radius:0;display:block;font-size:.85em;line-height:1.5;padding:0}.aptolix-messages-wrapper .message-text hr{border:none;border-top:1px solid rgba(0,0,0,.1);margin:12px 0}.aptolix-messages-wrapper .message-text table{border-collapse:collapse;margin:10px 0;width:100%}.aptolix-messages-wrapper .message-text table td,.aptolix-messages-wrapper .message-text table th{border:1px solid rgba(0,0,0,.1);padding:6px 10px;text-align:left}.aptolix-messages-wrapper .message-text table th{background:rgba(0,0,0,.05);font-weight:600}.aptolix-messages-wrapper .typing-dots span{animation:blink 1.2s infinite;font-size:1.5em;margin-right:2px;opacity:.5}.aptolix-messages-wrapper .typing-dots span:nth-child(2){animation-delay:.2s}.aptolix-messages-wrapper .typing-dots span:nth-child(3){animation-delay:.4s}@keyframes blink{0%,to{opacity:.2}50%{opacity:1}}.aptolix-chat-bubble{align-items:center;background:#9333ea;border-radius:50%;bottom:32px;box-shadow:0 6px 24px rgba(167,139,250,.18);color:#fff;cursor:pointer;display:flex;font-size:2rem;height:56px;justify-content:center;position:fixed;right:32px;transition:background .2s,box-shadow .2s;width:56px;z-index:9999}.aptolix-chat-bubble:hover{background:#7c3aed;box-shadow:0 8px 32px rgba(124,62,237,.28)}.aptolix-chat-window.bubble-mode{border-radius:16px;border-style:solid;border-width:2.5px;display:flex;flex-direction:column;height:100%;overflow:hidden}.aptolix-chat-window.section-mode{border-radius:18px;border-style:solid;border-width:2.5px;box-sizing:border-box!important;display:flex!important;flex-direction:column;height:100%;max-height:100%;max-width:100%;overflow:hidden;position:static!important;width:100%}.aptolix-chat-window.section-mode [id^=aptolix-chat-messages]{background:#f6f3ff;flex:1 1 auto;min-height:0;overflow-y:auto;padding:20px 18px 18px}.aptolix-chat-window.section-mode [id^=aptolix-chat-header]{background:#9333ea;color:#fff}.aptolix-chat-window.section-mode [id^=aptolix-chat-close],.aptolix-chat-window.section-mode [id^=aptolix-chat-expand],.aptolix-chat-window.section-mode~.aptolix-chat-bubble{display:none!important}@media (max-width:600px){[id^=aptolix-chat-header]{font-size:1rem;padding:10px 8px}[id^=aptolix-chat-messages]{padding:12px 8px}[id^=aptolix-chat-input]{padding:8px}.aptolix-chat-window.section-mode{border-radius:12px;border-width:1px}}@media (max-width:480px){.aptolix-chat-bubble{bottom:24px;height:52px;right:24px;width:52px}}.aptolix-retry-btn{background:#ede9fe;border:none;border-radius:6px;color:#7c3aed;cursor:pointer;font-weight:600;margin-top:8px;padding:4px 12px}.aptolix-retry-btn:hover{background:#d8b4fe}.aptolix-hint-bubble{background:#fff;border-radius:8px;bottom:110px;box-shadow:0 2px 8px rgba(0,0,0,.15);color:#333;font-size:1em;max-width:320px;min-width:180px;padding:16px 40px 16px 16px;pointer-events:auto;position:fixed;right:40px;z-index:9999}.aptolix-hint-bubble:after{border-left:10px solid transparent;border-right:10px solid transparent;border-top:12px solid #fff;bottom:-12px;content:"";height:0;position:absolute;right:28px;width:0}');class e{constructor(e=null){this.chatbotId=e,this.keys={config:"aptolix_chatbot_config",state:"aptolix_chatbot_state"}}_getState(e=null){if(!(e=e||this.chatbotId))return null;try{const t=`${this.keys.state}_${e}`,n=localStorage.getItem(t);return n?JSON.parse(n):null}catch(e){return null}}_saveState(e,t){if("object"==typeof e&&void 0===t&&(t=e,e=this.chatbotId),e)try{const n=`${this.keys.state}_${e}`;t.timestamp=Date.now(),t.version="1.0.26",localStorage.setItem(n,JSON.stringify(t))}catch(e){}}_isToday(e){const t=new Date,n=new Date(e);return t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate()}_getTodayStart(){const e=new Date;return e.setHours(0,0,0,0),e.getTime()}saveConfig(e,t){try{const n=`${this.keys.config}_${e}`,a={config:t,timestamp:Date.now()};localStorage.setItem(n,JSON.stringify(a))}catch(e){}}getConfig(e){try{const t=`${this.keys.config}_${e}`,n=localStorage.getItem(t);if(!n)return null;return JSON.parse(n).config}catch(e){return null}}clearConfig(e){try{const t=`${this.keys.config}_${e}`;localStorage.removeItem(t)}catch(e){}}hasConfig(e){const t=`${this.keys.config}_${e}`;return null!==localStorage.getItem(t)}saveVisitorId(e,t){try{const n=this._getState(e)||{};n.visitorId=t,this._saveState(e,n)}catch(e){}}getVisitorId(e){try{const t=this._getState(e);return t?.visitorId||null}catch(e){return null}}clearVisitorId(e){try{const t=this._getState(e);t&&(delete t.visitorId,this._saveState(e,t))}catch(e){}}hasVisitorId(e){return null!==this.getVisitorId(e)}saveSessionId(e,t){try{const n=this._getState(e)||{};n.sessionId=t,this._saveState(e,n)}catch(e){}}getSessionId(e){try{const t=this._getState(e);return t?.sessionId||null}catch(e){return null}}clearSessionId(e){try{const t=this._getState(e);t&&(delete t.sessionId,this._saveState(e,t))}catch(e){}}hasSessionId(e){return null!==this.getSessionId(e)}saveChatHistory(e,t,n){try{const t=this._getState(e)||{};t.history={messages:n,timestamp:Date.now()},this._saveState(e,t)}catch(e){}}getChatHistory(e,t){try{const n=this._getState(e);if(!n?.history)return null;const{history:a}=n;return n.sessionId!==t?null:this._isToday(a.timestamp)?a.messages:(this.clearChatHistory(e,t),null)}catch(e){return null}}clearChatHistory(e,t){try{const n=this._getState(e);n?.history&&n.sessionId===t&&(delete n.history,this._saveState(e,n))}catch(e){}}hasChatHistory(e,t){return null!==this.getChatHistory(e,t)}setUsageLimitReached(e,t,n){try{const t=this._getState(e)||{};t.usageLimitReached={limitReachedDate:n,timestamp:Date.now()},this._saveState(e,t)}catch(e){}}getUsageLimitReached(e,t){try{const n=this._getState(e);if(!n?.usageLimitReached)return null;const{usageLimitReached:a}=n;let i;i=10!==a.limitReachedDate.length||a.limitReachedDate.includes("T")?new Date(a.limitReachedDate):new Date(a.limitReachedDate+"T23:59:59.999Z");return new Date>i?(this.clearUsageLimitReached(e,t),null):{limitReachedDate:a.limitReachedDate,timestamp:a.timestamp}}catch(e){return null}}clearUsageLimitReached(e,t){try{const t=this._getState(e);t&&(delete t.usageLimitReached,this._saveState(e,t))}catch(e){}}hasUsageLimitReached(e,t){return null!==this.getUsageLimitReached(e,t)}clearAll(e=null,t=null,n=null){if(e=e||this.chatbotId){this.clearConfig(e);try{const t=`${this.keys.state}_${e}`;localStorage.removeItem(t)}catch(e){}}}getConversationHistory(){if(!this.chatbotId)return null;const e=this._getState(this.chatbotId);return e?.history?.messages||null}saveConversationHistory(e){if(!this.chatbotId)return;const t=this._getState(this.chatbotId)||{};t.history={messages:e,timestamp:Date.now()},this._saveState(this.chatbotId,t)}clearConversationHistory(){if(!this.chatbotId)return;const e=this._getState(this.chatbotId);e?.history&&(delete e.history,this._saveState(this.chatbotId,e))}getRating(e){if(!this.chatbotId)return null;const t=this._getState(this.chatbotId);return t?.ratings?.[e]||null}saveRating(e,t){if(!this.chatbotId)return;const n=this._getState(this.chatbotId)||{};n.ratings||(n.ratings={}),n.ratings[e]=t,this._saveState(this.chatbotId,n)}}const t={mode:"bubble",botname:"AI Assistant",widgetIcon:"💬",companyLogoBlack:'\n <svg width="24" height="32" viewBox="0 0 81 52" fill="none" xmlns="http://www.w3.org/2000/svg">\n <rect x="34.8" y="0" width="46" height="11.7" rx="5.9" fill="#000"/>\n <rect x="0.2" y="19.7" width="80.6" height="12" rx="6" fill="#000"/>\n <rect x="61.7" y="39.4" width="19" height="11.7" rx="6" fill="#000"/>\n <rect x="7.7" y="39.5" width="49" height="11.7" rx="6" fill="#000"/>\n </svg>\n ',companyLogoWhite:'\n <svg width="24" height="32" viewBox="0 0 81 52" fill="none" xmlns="http://www.w3.org/2000/svg">\n <rect x="34.8" y="0" width="46" height="11.7" rx="5.9" fill="#fcfcfcff"/>\n <rect x="0.2" y="19.7" width="80.6" height="12" rx="6" fill="#fcfcfcff"/>\n <rect x="61.7" y="39.4" width="19" height="11.7" rx="6" fill="#fcfcfcff"/>\n <rect x="7.7" y="39.5" width="49" height="11.7" rx="6" fill="#fcfcfcff"/>\n </svg>\n ',botAvatar:'\n <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="20" cy="20" r="18" fill="#9333ea"/>\n <rect x="12" y="14" width="6" height="6" rx="1" fill="#fff"/>\n <rect x="22" y="14" width="6" height="6" rx="1" fill="#fff"/>\n <rect x="13" y="26" width="14" height="4" rx="2" fill="#fff"/>\n </svg>\n ',userAvatar:'\n <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="20" cy="20" r="20" fill="#64748b"/>\n <circle cx="20" cy="15" r="6" fill="#fff"/>\n <path d="M 8 35 Q 8 25 20 25 Q 32 25 32 35" fill="#fff"/>\n </svg>\n ',username:"You",botaccentColor:"#4a57e2ff",floatingWelcomeMessage:"Hello! Looking for something? I'm here to assist - just ask!",floatingWelcomeDelay:2,greetingMessage:"Welcome! Let me know if you have any questions.",allowDownloadTranscript:!0,allowExpandChatWindow:!0,allowFullPageChat:!1,inputCharLimit:350,allowReset:!0,allowRating:!0,ratingThreshold:3,ratingInterval:4};function n(e){return!(!e||"string"!=typeof e)&&(!!(e.includes("<svg")||e.includes("<")&&e.includes(">"))||e.trim().length>0&&e.length<=100)}async function a(a,i){const s=new e;if(a&&i){const e=await async function(e,t){try{const a=await fetch(`${e}/chatbot/${t}/appearance`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!a.ok)return null;return(n=await a.json())?{botname:n.bot_name,widgetIcon:n.widget_icon,companyLogo:n.company_logo,botAvatar:n.bot_avatar,userAvatar:n.user_avatar,username:n.username,botaccentColor:n.accent_color,floatingWelcomeMessage:n.floating_welcome_message,floatingWelcomeDelay:n.floating_welcome_delay,greetingMessage:n.greeting_message,allowDownloadTranscript:n.download_transcript,allowExpandChatWindow:n.expand_chat_window,allowFullPageChat:n.full_page_chat,inputCharLimit:n.input_char_limit,allowReset:n.allow_reset,allowRating:n.allow_rating,ratingThreshold:n.rating_threshold,ratingInterval:n.rating_interval}:null}catch(e){return null}var n}(a,i);if(e)return e.widgetIcon&&n(e.widgetIcon)||(e.widgetIcon=t.widgetIcon),s.saveConfig(i,e),e;{const e=s.getConfig(i);return e?(e.widgetIcon&&n(e.widgetIcon)||(e.widgetIcon=t.widgetIcon),e):null}}return null}function i(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var s={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function r(e){s=e}var o={exec:()=>null};function l(e,t=""){let n="string"==typeof e?e:e.source,a={replace:(e,t)=>{let i="string"==typeof t?t:t.source;return i=i.replace(c.caret,"$1"),n=n.replace(e,i),a},getRegex:()=>new RegExp(n,t)};return a}var c={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[\t ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},p=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,h=/(?:[*+-]|\d{1,9}[.)])/,d=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,g=l(d).replace(/bull/g,h).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).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/).replace(/\|table/g,"").getRegex(),u=l(d).replace(/bull/g,h).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).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/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),x=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,m=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,f=l(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",m).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),b=l(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,h).getRegex(),w="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",y=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,k=l("^ {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[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",y).replace("tag",w).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),v=l(x).replace("hr",p).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",w).getRegex(),$={blockquote:l(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",v).getRegex(),code:/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,def:f,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:p,html:k,lheading:g,list:b,newline:/^(?:[ \t]*(?:\n|$))+/,paragraph:v,table:o,text:/^[^\n]+/},S=l("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",p).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\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",w).getRegex(),I={...$,lheading:u,table:S,paragraph:l(x).replace("hr",p).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",S).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",w).getRegex()},T={...$,html:l("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",y).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:o,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:l(x).replace("hr",p).replace("heading"," *#{1,6} *[^\n]").replace("lheading",g).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},C=/^( {2,}|\\)\n(?!\s*$)/,_=/[\p{P}\p{S}]/u,A=/[\s\p{P}\p{S}]/u,R=/[^\s\p{P}\p{S}]/u,L=l(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,A).getRegex(),z=/(?!~)[\p{P}\p{S}]/u,E=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,D=l(E,"u").replace(/punct/g,_).getRegex(),M=l(E,"u").replace(/punct/g,z).getRegex(),P="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",q=l(P,"gu").replace(/notPunctSpace/g,R).replace(/punctSpace/g,A).replace(/punct/g,_).getRegex(),H=l(P,"gu").replace(/notPunctSpace/g,/(?:[^\s\p{P}\p{S}]|~)/u).replace(/punctSpace/g,/(?!~)[\s\p{P}\p{S}]/u).replace(/punct/g,z).getRegex(),B=l("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,R).replace(/punctSpace/g,A).replace(/punct/g,_).getRegex(),W=l(/\\(punct)/,"gu").replace(/punct/g,_).getRegex(),O=l(/^<(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(),N=l(y).replace("(?:--\x3e|$)","--\x3e").getRegex(),j=l("^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",N).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),U=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`[^`]*`|[^\[\]\\`])*?/,F=l(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",U).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Z=l(/^!?\[(label)\]\[(ref)\]/).replace("label",U).replace("ref",m).getRegex(),G=l(/^!?\[(ref)\](?:\[\])?/).replace("ref",m).getRegex(),Q={_backpedal:o,anyPunctuation:W,autolink:O,blockSkip:/\[[^\[\]]*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)|`[^`]*?`|<(?! )[^<>]*?>/g,br:C,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:o,emStrongLDelim:D,emStrongRDelimAst:q,emStrongRDelimUnd:B,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:F,nolink:G,punctuation:L,reflink:Z,reflinkSearch:l("reflink|nolink(?!\\()","g").replace("reflink",Z).replace("nolink",G).getRegex(),tag:j,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:o},X={...Q,link:l(/^!?\[(label)\]\((.*?)\)/).replace("label",U).getRegex(),reflink:l(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",U).getRegex()},Y={...Q,emStrongRDelimAst:H,emStrongLDelim:M,url:l(/^((?: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\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.!#$%&'*+\/=?_`{\|}~-]+@)))/},J={...Y,br:l(C).replace("{2,}","*").getRegex(),text:l(Y.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},V={normal:$,gfm:I,pedantic:T},K={normal:Q,gfm:Y,breaks:J,pedantic:X},ee={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},te=e=>ee[e];function ne(e,t){if(t){if(c.escapeTest.test(e))return e.replace(c.escapeReplace,te)}else if(c.escapeTestNoEncode.test(e))return e.replace(c.escapeReplaceNoEncode,te);return e}function ae(e){try{e=encodeURI(e).replace(c.percentDecode,"%")}catch{return null}return e}function ie(e,t){let n=e.replace(c.findPipe,(e,t,n)=>{let a=!1,i=t;for(;--i>=0&&"\\"===n[i];)a=!a;return a?"|":" |"}).split(c.splitPipe),a=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;a<n.length;a++)n[a]=n[a].trim().replace(c.slashPipe,"|");return n}function se(e,t,n){let a=e.length;if(0===a)return"";let i=0;for(;i<a;){let s=e.charAt(a-i-1);if(s!==t||n){if(s===t||!n)break;i++}else i++}return e.slice(0,a-i)}function re(e,t,n,a,i){let s=t.href,r=t.title||null,o=e[1].replace(i.other.outputLinkReplace,"$1");a.state.inLink=!0;let l={type:"!"===e[0].charAt(0)?"image":"link",raw:n,href:s,title:r,text:o,tokens:a.inlineTokens(o)};return a.state.inLink=!1,l}var oe=class{options;rules;lexer;constructor(e){this.options=e||s}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:se(e,"\n")}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=function(e,t,n){let a=e.match(n.other.indentCodeCompensation);if(null===a)return t;let i=a[1];return t.split("\n").map(e=>{let t=e.match(n.other.beginningSpace);if(null===t)return e;let[a]=t;return a.length>=i.length?e.slice(i.length):e}).join("\n")}(e,t[3]||"",this.rules);return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=se(e,"#");(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:se(t[0],"\n")}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=se(t[0],"\n").split("\n"),n="",a="",i=[];for(;e.length>0;){let t,s=!1,r=[];for(t=0;t<e.length;t++)if(this.rules.other.blockquoteStart.test(e[t]))r.push(e[t]),s=!0;else{if(s)break;r.push(e[t])}e=e.slice(t);let o=r.join("\n"),l=o.replace(this.rules.other.blockquoteSetextReplace,"\n $1").replace(this.rules.other.blockquoteSetextReplace2,"");n=n?`${n}\n${o}`:o,a=a?`${a}\n${l}`:l;let c=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(l,i,!0),this.lexer.state.top=c,0===e.length)break;let p=i.at(-1);if("code"===p?.type)break;if("blockquote"===p?.type){let t=p,s=t.raw+"\n"+e.join("\n"),r=this.blockquote(s);i[i.length-1]=r,n=n.substring(0,n.length-t.raw.length)+r.raw,a=a.substring(0,a.length-t.text.length)+r.text;break}if("list"===p?.type){let t=p,s=t.raw+"\n"+e.join("\n"),r=this.list(s);i[i.length-1]=r,n=n.substring(0,n.length-p.raw.length)+r.raw,a=a.substring(0,a.length-t.raw.length)+r.raw,e=s.substring(i.at(-1).raw.length).split("\n");continue}}return{type:"blockquote",raw:n,tokens:i,text:a}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),a=n.length>1,i={type:"list",raw:"",ordered:a,start:a?+n.slice(0,-1):"",loose:!1,items:[]};n=a?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=a?n:"[*+-]");let s=this.rules.other.listItemRegex(n),r=!1;for(;e;){let n=!1,a="",o="";if(!(t=s.exec(e))||this.rules.block.hr.test(e))break;a=t[0],e=e.substring(a.length);let l=t[2].split("\n",1)[0].replace(this.rules.other.listReplaceTabs,e=>" ".repeat(3*e.length)),c=e.split("\n",1)[0],p=!l.trim(),h=0;if(this.options.pedantic?(h=2,o=l.trimStart()):p?h=t[1].length+1:(h=t[2].search(this.rules.other.nonSpaceChar),h=h>4?1:h,o=l.slice(h),h+=t[1].length),p&&this.rules.other.blankLine.test(c)&&(a+=c+"\n",e=e.substring(c.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(h),n=this.rules.other.hrRegex(h),i=this.rules.other.fencesBeginRegex(h),s=this.rules.other.headingBeginRegex(h),r=this.rules.other.htmlBeginRegex(h);for(;e;){let d,g=e.split("\n",1)[0];if(c=g,this.options.pedantic?(c=c.replace(this.rules.other.listReplaceNesting," "),d=c):d=c.replace(this.rules.other.tabCharGlobal," "),i.test(c)||s.test(c)||r.test(c)||t.test(c)||n.test(c))break;if(d.search(this.rules.other.nonSpaceChar)>=h||!c.trim())o+="\n"+d.slice(h);else{if(p||l.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||i.test(l)||s.test(l)||n.test(l))break;o+="\n"+c}!p&&!c.trim()&&(p=!0),a+=g+"\n",e=e.substring(g.length+1),l=d.slice(h)}}i.loose||(r?i.loose=!0:this.rules.other.doubleBlankLine.test(a)&&(r=!0));let d,g=null;this.options.gfm&&(g=this.rules.other.listIsTask.exec(o),g&&(d="[ ] "!==g[0],o=o.replace(this.rules.other.listReplaceTask,""))),i.items.push({type:"list_item",raw:a,task:!!g,checked:d,loose:!1,text:o,tokens:[]}),i.raw+=a}let o=i.items.at(-1);if(!o)return;o.raw=o.raw.trimEnd(),o.text=o.text.trimEnd(),i.raw=i.raw.trimEnd();for(let e=0;e<i.items.length;e++)if(this.lexer.state.top=!1,i.items[e].tokens=this.lexer.blockTokens(i.items[e].text,[]),!i.loose){let t=i.items[e].tokens.filter(e=>"space"===e.type),n=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw));i.loose=n}if(i.loose)for(let e=0;e<i.items.length;e++)i.items[e].loose=!0;return i}}html(e){let 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){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",a=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:a}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=ie(t[1]),a=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),i=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split("\n"):[],s={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===a.length){for(let e of a)this.rules.other.tableAlignRight.test(e)?s.align.push("right"):this.rules.other.tableAlignCenter.test(e)?s.align.push("center"):this.rules.other.tableAlignLeft.test(e)?s.align.push("left"):s.align.push(null);for(let e=0;e<n.length;e++)s.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:s.align[e]});for(let e of i)s.rows.push(ie(e,s.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:s.align[t]})));return s}}lheading(e){let 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){let t=this.rules.block.paragraph.exec(e);if(t){let 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){let 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){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.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){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=se(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{let e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let a=0;a<e.length;a++)if("\\"===e[a])a++;else if(e[a]===t[0])n++;else if(e[a]===t[1]&&(n--,n<0))return a;return n>0?-2:-1}(t[2],"()");if(-2===e)return;if(e>-1){let 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],a="";if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],a=e[3])}else a=t[3]?t[3].slice(1,-1):"";return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),re(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,"$1"),title:a&&a.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," ").toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return re(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let a=this.rules.inline.emStrongLDelim.exec(e);if(!(!a||a[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!a[1]&&!a[2]||!n||this.rules.inline.punctuation.exec(n))){let n,i,s=[...a[0]].length-1,r=s,o=0,l="*"===a[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+s);null!=(a=l.exec(t));){if(n=a[1]||a[2]||a[3]||a[4]||a[5]||a[6],!n)continue;if(i=[...n].length,a[3]||a[4]){r+=i;continue}if((a[5]||a[6])&&s%3&&!((s+i)%3)){o+=i;continue}if(r-=i,r>0)continue;i=Math.min(i,i+r+o);let t=[...a[0]][0].length,l=e.slice(0,s+a.index+t+i);if(Math.min(s,i)%2){let e=l.slice(1,-1);return{type:"em",raw:l,text:e,tokens:this.lexer.inlineTokens(e)}}let c=l.slice(2,-2);return{type:"strong",raw:l,text:c,tokens:this.lexer.inlineTokens(c)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal," "),n=this.rules.other.nonSpaceChar.test(e),a=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&a&&(e=e.substring(1,e.length-1)),{type:"codespan",raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){let 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){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=t[1],n="mailto:"+e):(e=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=t[0],n="mailto:"+e;else{let a;do{a=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(a!==t[0]);e=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){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:e}}}},le=class e{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||s,this.options.tokenizer=this.options.tokenizer||new oe,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:c,block:V.normal,inline:K.normal};this.options.pedantic?(t.block=V.pedantic,t.inline=K.pedantic):this.options.gfm&&(t.block=V.gfm,this.options.breaks?t.inline=K.breaks:t.inline=K.gfm),this.tokenizer.rules=t}static get rules(){return{block:V,inline:K}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(c.carriageReturn,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){for(this.options.pedantic&&(e=e.replace(c.tabCharGlobal," ").replace(c.spaceLine,""));e;){let a;if(this.options.extensions?.block?.some(n=>!!(a=n.call({lexer:this},e,t))&&(e=e.substring(a.raw.length),t.push(a),!0)))continue;if(a=this.tokenizer.space(e)){e=e.substring(a.raw.length);let n=t.at(-1);1===a.raw.length&&void 0!==n?n.raw+="\n":t.push(a);continue}if(a=this.tokenizer.code(e)){e=e.substring(a.raw.length);let n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+a.raw,n.text+="\n"+a.text,this.inlineQueue.at(-1).src=n.text):t.push(a);continue}if(a=this.tokenizer.fences(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.heading(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.hr(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.blockquote(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.list(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.html(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.def(e)){e=e.substring(a.raw.length);let n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+a.raw,n.text+="\n"+a.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[a.tag]||(this.tokens.links[a.tag]={href:a.href,title:a.title},t.push(a));continue}if(a=this.tokenizer.table(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.lheading(e)){e=e.substring(a.raw.length),t.push(a);continue}let i=e;if(this.options.extensions?.startBlock){let t,n=1/0,a=e.slice(1);this.options.extensions.startBlock.forEach(e=>{t=e.call({lexer:this},a),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(i=e.substring(0,n+1))}if(this.state.top&&(a=this.tokenizer.paragraph(i))){let s=t.at(-1);n&&"paragraph"===s?.type?(s.raw+=(s.raw.endsWith("\n")?"":"\n")+a.raw,s.text+="\n"+a.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=s.text):t.push(a),n=i.length!==e.length,e=e.substring(a.raw.length);continue}if(a=this.tokenizer.text(e)){e=e.substring(a.raw.length);let n=t.at(-1);"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+a.raw,n.text+="\n"+a.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(a);continue}if(e){let 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=e,a=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(a=this.tokenizer.rules.inline.reflinkSearch.exec(n));)e.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(n=n.slice(0,a.index)+"["+"a".repeat(a[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(a=this.tokenizer.rules.inline.anyPunctuation.exec(n));)n=n.slice(0,a.index)+"++"+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;null!=(a=this.tokenizer.rules.inline.blockSkip.exec(n));)n=n.slice(0,a.index)+"["+"a".repeat(a[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let i=!1,s="";for(;e;){let a;if(i||(s=""),i=!1,this.options.extensions?.inline?.some(n=>!!(a=n.call({lexer:this},e,t))&&(e=e.substring(a.raw.length),t.push(a),!0)))continue;if(a=this.tokenizer.escape(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.tag(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.link(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(a.raw.length);let n=t.at(-1);"text"===a.type&&"text"===n?.type?(n.raw+=a.raw,n.text+=a.text):t.push(a);continue}if(a=this.tokenizer.emStrong(e,n,s)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.codespan(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.br(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.del(e)){e=e.substring(a.raw.length),t.push(a);continue}if(a=this.tokenizer.autolink(e)){e=e.substring(a.raw.length),t.push(a);continue}if(!this.state.inLink&&(a=this.tokenizer.url(e))){e=e.substring(a.raw.length),t.push(a);continue}let r=e;if(this.options.extensions?.startInline){let t,n=1/0,a=e.slice(1);this.options.extensions.startInline.forEach(e=>{t=e.call({lexer:this},a),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(r=e.substring(0,n+1))}if(a=this.tokenizer.inlineText(r)){e=e.substring(a.raw.length),"_"!==a.raw.slice(-1)&&(s=a.raw.slice(-1)),i=!0;let n=t.at(-1);"text"===n?.type?(n.raw+=a.raw,n.text+=a.text):t.push(a);continue}if(e){let t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return t}},ce=class{options;parser;constructor(e){this.options=e||s}space(e){return""}code({text:e,lang:t,escaped:n}){let a=(t||"").match(c.notSpaceStart)?.[0],i=e.replace(c.endingNewline,"")+"\n";return a?'<pre><code class="language-'+ne(a)+'">'+(n?i:ne(i,!0))+"</code></pre>\n":"<pre><code>"+(n?i:ne(i,!0))+"</code></pre>\n"}blockquote({tokens:e}){return`<blockquote>\n${this.parser.parse(e)}</blockquote>\n`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>\n`}hr(e){return"<hr>\n"}list(e){let t=e.ordered,n=e.start,a="";for(let t=0;t<e.items.length;t++){let n=e.items[t];a+=this.listitem(n)}let i=t?"ol":"ul";return"<"+i+(t&&1!==n?' start="'+n+'"':"")+">\n"+a+"</"+i+">\n"}listitem(e){let t="";if(e.task){let n=this.checkbox({checked:!!e.checked});e.loose?"paragraph"===e.tokens[0]?.type?(e.tokens[0].text=n+" "+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&"text"===e.tokens[0].tokens[0].type&&(e.tokens[0].tokens[0].text=n+" "+ne(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:"text",raw:n+" ",text:n+" ",escaped:!0}):t+=n+" "}return t+=this.parser.parse(e.tokens,!!e.loose),`<li>${t}</li>\n`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>\n`}table(e){let t="",n="";for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let a="";for(let t=0;t<e.rows.length;t++){let i=e.rows[t];n="";for(let e=0;e<i.length;e++)n+=this.tablecell(i[e]);a+=this.tablerow({text:n})}return a&&(a=`<tbody>${a}</tbody>`),"<table>\n<thead>\n"+t+"</thead>\n"+a+"</table>\n"}tablerow({text:e}){return`<tr>\n${e}</tr>\n`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>\n`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${ne(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let a=this.parser.parseInline(n),i=ae(e);if(null===i)return a;let s='<a href="'+(e=i)+'"';return t&&(s+=' title="'+ne(t)+'"'),s+=">"+a+"</a>",s}image({href:e,title:t,text:n,tokens:a}){a&&(n=this.parser.parseInline(a,this.parser.textRenderer));let i=ae(e);if(null===i)return ne(n);let s=`<img src="${e=i}" alt="${n}"`;return t&&(s+=` title="${ne(t)}"`),s+=">",s}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:ne(e.text)}},pe=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}},he=class e{options;renderer;textRenderer;constructor(e){this.options=e||s,this.options.renderer=this.options.renderer||new ce,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new pe}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e,t=!0){let n="";for(let a=0;a<e.length;a++){let i=e[a];if(this.options.extensions?.renderers?.[i.type]){let e=i,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(e.type)){n+=t||"";continue}}let s=i;switch(s.type){case"space":n+=this.renderer.space(s);continue;case"hr":n+=this.renderer.hr(s);continue;case"heading":n+=this.renderer.heading(s);continue;case"code":n+=this.renderer.code(s);continue;case"table":n+=this.renderer.table(s);continue;case"blockquote":n+=this.renderer.blockquote(s);continue;case"list":n+=this.renderer.list(s);continue;case"html":n+=this.renderer.html(s);continue;case"def":n+=this.renderer.def(s);continue;case"paragraph":n+=this.renderer.paragraph(s);continue;case"text":{let i=s,r=this.renderer.text(i);for(;a+1<e.length&&"text"===e[a+1].type;)i=e[++a],r+="\n"+this.renderer.text(i);n+=t?this.renderer.paragraph({type:"paragraph",raw:r,text:r,tokens:[{type:"text",raw:r,text:r,escaped:!0}]}):r;continue}default:{let 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=this.renderer){let n="";for(let a=0;a<e.length;a++){let i=e[a];if(this.options.extensions?.renderers?.[i.type]){let e=this.options.extensions.renderers[i.type].call({parser:this},i);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){n+=e||"";continue}}let s=i;switch(s.type){case"escape":case"text":n+=t.text(s);break;case"html":n+=t.html(s);break;case"link":n+=t.link(s);break;case"image":n+=t.image(s);break;case"strong":n+=t.strong(s);break;case"em":n+=t.em(s);break;case"codespan":n+=t.codespan(s);break;case"br":n+=t.br(s);break;case"del":n+=t.del(s);break;default:{let e='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}},de=class{options;block;constructor(e){this.options=e||s}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}provideLexer(){return this.block?le.lex:le.lexInline}provideParser(){return this.block?he.parse:he.parseInline}},ge=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.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=he;Renderer=ce;TextRenderer=pe;Lexer=le;Tokenizer=oe;Hooks=de;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let a of e)switch(n=n.concat(t.call(this,a)),a.type){case"table":{let e=a;for(let a of e.header)n=n.concat(this.walkTokens(a.tokens,t));for(let a of e.rows)for(let e of a)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{let e=a;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=a;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(a=>{let i=e[a].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let 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){let n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let a=e.renderer.apply(this,t);return!1===a&&(a=n.apply(this,t)),a}: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'");let 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){let t=this.defaults.renderer||new ce(this.defaults);for(let n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if(["options","parser"].includes(n))continue;let a=n,i=e.renderer[a],s=t[a];t[a]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=s.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new oe(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;let a=n,i=e.tokenizer[a],s=t[a];t[a]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=s.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new de;for(let n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if(["options","block"].includes(n))continue;let a=n,i=e.hooks[a],s=t[a];de.passThroughHooks.has(n)?t[a]=e=>{if(this.defaults.async)return Promise.resolve(i.call(t,e)).then(e=>s.call(t,e));let n=i.call(t,e);return s.call(t,n)}:t[a]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=s.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,a=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(a.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 le.lex(e,t??this.defaults)}parser(e,t){return he.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let a={...n},i={...this.defaults,...a},s=this.onError(!!i.silent,!!i.async);if(!0===this.defaults.async&&!1===a.async)return s(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||null===t)return s(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof t)return s(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));i.hooks&&(i.hooks.options=i,i.hooks.block=e);let r=i.hooks?i.hooks.provideLexer():e?le.lex:le.lexInline,o=i.hooks?i.hooks.provideParser():e?he.parse:he.parseInline;if(i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(t):t).then(e=>r(e,i)).then(e=>i.hooks?i.hooks.processAllTokens(e):e).then(e=>i.walkTokens?Promise.all(this.walkTokens(e,i.walkTokens)).then(()=>e):e).then(e=>o(e,i)).then(e=>i.hooks?i.hooks.postprocess(e):e).catch(s);try{i.hooks&&(t=i.hooks.preprocess(t));let e=r(t,i);i.hooks&&(e=i.hooks.processAllTokens(e)),i.walkTokens&&this.walkTokens(e,i.walkTokens);let n=o(e,i);return i.hooks&&(n=i.hooks.postprocess(n)),n}catch(e){return s(e)}}}onError(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){let e="<p>An error occurred:</p><pre>"+ne(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function ue(e,t){return ge.parse(e,t)}function xe(e,t={}){const{botname:n="AI Assistant",username:a="You",botaccentColor:i="#4a57e2ff",botAvatar:s=me(),userAvatar:r=fe(),showExactTime:o=!1}=t,l=function(e){const t=e=>{const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null};let n,a,i;if(e.startsWith("#")){const s=t(e);if(!s)return!1;n=s.r,a=s.g,i=s.b}else{if(!e.startsWith("rgb"))return!1;{const t=e.match(/\d+/g);[n,a,i]=t.map(Number)}}return(.299*n+.587*a+.114*i)/255>.5}(i),c=i,p=l?"#1f2937":"#ffffff",h=function(e,t){const n=(e=>{const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null})(e);if(!n)return e;const a=Math.min(255,Math.round(n.r+(255-n.r)*t)),i=Math.min(255,Math.round(n.g+(255-n.g)*t)),s=Math.min(255,Math.round(n.b+(255-n.b)*t));return`#${a.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}(i,.85);return`<div class="aptolix-messages-wrapper">${e.map(e=>{const t="user"===e.type,i=t?r:s,l=t?a:n,d=t?c:h,g=t?p:"#4b5563",u="bot"===e.type?ue.parse(e.text):e.text,x=o?function(e){const t=new Date(e),n=new Date,a=t.toDateString()===n.toDateString(),i=new Date(n);i.setDate(i.getDate()-1);const s=t.toDateString()===i.toDateString(),r=t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});if(a)return`Today at ${r}`;if(s)return`Yesterday at ${r}`;return`${t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})} at ${r}`}(e.timestamp):function(e){const t=Date.now(),n=Math.floor((t-e)/1e3);if(n<10)return"just now";if(n<60)return`${n} secs ago`;if(n<3600){const e=Math.floor(n/60);return 1===e?"1 min ago":`${e} mins ago`}if(n<86400){const e=Math.floor(n/3600);return 1===e?"1 hour ago":`${e} hours ago`}const a=Math.floor(n/86400);return 1===a?"1 day ago":`${a} days ago`}(e.timestamp);return`\n <div class="message ${e.type}">\n <div class="message-avatar">\n ${i}\n <div class="message-sender">${l}</div>\n </div>\n <div class="message-content">\n <div class="message-text" style="background-color: ${d}; color: ${g};">\n ${u}\n </div>\n <span class="message-timestamp" data-timestamp="${e.timestamp}">${x}</span>\n ${e.rating&&e.rating>0?`\n <div class="message-rating">\n <span class="rating-stars">${"★".repeat(e.rating)}${"☆".repeat(5-e.rating)}</span>\n </div>\n `:""}\n </div>\n </div>\n `}).join("")}</div>`}function me(){return'<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="20" cy="20" r="18" fill="#9333ea"/>\n <rect x="12" y="14" width="6" height="6" rx="1" fill="#fff"/>\n <rect x="22" y="14" width="6" height="6" rx="1" fill="#fff"/>\n <rect x="13" y="26" width="14" height="4" rx="2" fill="#fff"/>\n </svg>'}function fe(){return'<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="20" cy="20" r="20" fill="#64748b"/>\n <circle cx="20" cy="15" r="6" fill="#fff"/>\n <path d="M 8 35 Q 8 25 20 25 Q 32 25 32 35" fill="#fff"/>\n </svg>'}ue.options=ue.setOptions=function(e){return ge.setOptions(e),ue.defaults=ge.defaults,r(ue.defaults),ue},ue.getDefaults=i,ue.defaults=s,ue.use=function(...e){return ge.use(...e),ue.defaults=ge.defaults,r(ue.defaults),ue},ue.walkTokens=function(e,t){return ge.walkTokens(e,t)},ue.parseInline=ge.parseInline,ue.Parser=he,ue.parser=he.parse,ue.Renderer=ce,ue.TextRenderer=pe,ue.Lexer=le,ue.lexer=le.lex,ue.Tokenizer=oe,ue.Hooks=de,ue.parse=ue,ue.options,ue.setOptions,ue.use,ue.walkTokens,ue.parseInline,he.parse,le.lex;const be="APTOLIX_INIT",we="APTOLIX_SHOW",ye="APTOLIX_READY",ke="APTOLIX_HEIGHT_CHANGE",ve="APTOLIX_CLOSE_REQUESTED";function $e(e){const t=e=>{const t=e.replace("#","").substring(0,6),n=/^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return n?{r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)}:null},n=(e,n)=>{const a=t(e);if(!a)return e;const i=Math.min(255,Math.round(a.r+(255-a.r)*n)),s=Math.min(255,Math.round(a.g+(255-a.g)*n)),r=Math.min(255,Math.round(a.b+(255-a.b)*n));return`#${i.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`},a=(e,n)=>{const a=t(e);if(!a)return e;const i=Math.max(0,Math.round(a.r*(1-n))),s=Math.max(0,Math.round(a.g*(1-n))),r=Math.max(0,Math.round(a.b*(1-n)));return`#${i.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`},i=(e,n)=>{const a=t(e);return a?`rgba(${a.r}, ${a.g}, ${a.b}, ${n})`:e},s=(e=>{let n,a,i;if(e.startsWith("#")){const s=t(e);if(!s)return!1;n=s.r,a=s.g,i=s.b}else{if(!e.startsWith("rgb"))return!1;{const t=e.match(/\d+/g);[n,a,i]=t.map(Number)}}return(.299*n+.587*a+.114*i)/255>.5})(e);return{primary:e,isLight:s,header:{background:e,text:s?"#1f2937":"#ffffff",button:s?"#374151":"#ffffff",border:n(e,.85)},messages:{userBackground:e,userText:s?"#1f2937":"#ffffff",botBackground:n(e,.85),botText:"#4b5563",link:a(e,.1),timestamp:"#9ca3af"},window:{background:n(e,.95),border:s?a(e,.2):n(e,.3),shadow:i(e,.15)},input:{background:"#ffffff",border:n(e,.85),text:"#1f2937",placeholder:"#9ca3af",buttonBackground:e,buttonText:s?"#1f2937":"#ffffff"},footer:{text:s?a(e,.3):n(e,.2),link:a(e,.1)},bubble:{background:e,icon:s?"#1f2937":"#ffffff"},hint:{background:"#ffffff",text:"#1f2937",border:n(e,.85),closeButton:e},menu:{background:"#ffffff",text:"#1f2937",hover:n(e,.9),border:"#e5e7eb"},rating:{star:"#fbbf24",text:"#6b7280"},utils:{lighten:n,darken:a,addAlpha:i,hexToRgb:t}}}const Se=window.self!==window.top;let Ie=!1,Te=null,Ce=null,_e=null,Ae=null,Re=[],Le=null,ze=null;const Ee="APTOLIX_INIT",De="APTOLIX_SHOW",Me="APTOLIX_READY",Pe="APTOLIX_HEIGHT_CHANGE",qe="APTOLIX_CLOSE_REQUESTED";function He(e,t={}){Se&&window.parent&&window.parent.postMessage({type:e,payload:t,source:"aptolix-chatbot-iframe"},"*")}async function Be(t,n){if(!Ie)return Te=t,ze=n||Te.apiHost,Ce=Te.conversationId||`${Te.chatbotId}-${Date.now()}`,Le=new e(Te.chatbotId),_e=Le.getVisitorId(Te.chatbotId),Ae=Le.getSessionId(Te.chatbotId),function(){const e=$e(Te.botaccentColor),t=Te.chatbotId;let n="";if(Te.companyLogo){n=/^https?:\/\//.test(Te.companyLogo)?`<img src="${Te.companyLogo}" alt="Company Logo" class="aptolix-company-logo" style="max-width:40px;max-height:40px;" />`:Te.companyLogo}const a=encodeURIComponent(window.location.hostname),i=encodeURIComponent("widget"),s=encodeURIComponent("refback"),r=`https://aptolix.com?utm_source=${a}&utm_medium=${i}&utm_campaign=${s}`,o=Se&&window.__parentHostname__?window.__parentHostname__:window.location.hostname,l="localhost"===o||"127.0.0.1"===o||o.startsWith("192.168.")||o.endsWith(".local")?'<span style="background: #ef4444; color: white; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; margin-left: 8px; letter-spacing: 0.5px;">LOCAL</span>':"",c=Se?"":`box-shadow: 0 4px 20px ${e.window.shadow};`,p=`\n <div id="aptolix-chat-window-${t}" class="aptolix-chat-window ${Se?"bubble-mode":"section-mode"}" style="background-color: ${e.window.background}; border-color: ${e.window.border}; ${c}">\n <div id="aptolix-chat-header-${t}" style="background-color: ${Te.botaccentColor}; color: ${e.header.text}; border-bottom: 2px solid ${e.header.border};">\n <div class="aptolix-header-flex">\n <div class="aptolix-header-title">\n ${n?`<div class="aptolix-company-logo-wrapper">${n}</div>`:""}\n <strong class="aptolix-bot-name">${Te.botname}${l}</strong>\n </div>\n <div class="aptolix-header-actions">\n ${Te.allowReset||Te.allowDownloadTranscript?`<button id="aptolix-chat-menu-${t}" title="More options" aria-label="More options" style="color: ${e.header.button};">⋮</button>`:""}\n ${Te.allowExpandChatWindow?`<button id="aptolix-chat-expand-${t}" title="Expand/Collapse" aria-label="Expand/Collapse" style="color: ${e.header.button};">\n <span id="aptolix-chat-expand-icon-${t}">⤢</span>\n </button>`:""}\n <button id="aptolix-chat-close-${t}" title="Close chat" aria-label="Close chat" style="color: ${e.header.button};">×</button>\n ${Te.allowReset||Te.allowDownloadTranscript?`<div id="aptolix-chat-menu-dropdown-${t}" class="aptolix-menu-dropdown" style="background-color: ${e.menu.background}; border-color: ${e.menu.border}; border: 1px solid ${e.menu.border};">\n ${Te.allowReset?`<button id="aptolix-chat-reset-${t}" class="aptolix-menu-item" title="Reset chat" aria-label="Reset chat" style="background-color: ${e.menu.background}; color: ${e.menu.text};">\n <span class="aptolix-menu-icon">⟲</span>\n <span class="aptolix-menu-text">Reset Chat</span>\n </button>`:""}\n ${Te.allowDownloadTranscript?`<button id="aptolix-chat-download-${t}" class="aptolix-menu-item" title="Download chat" aria-label="Download chat" style="background-color: ${e.menu.background}; color: ${e.menu.text};">\n <span class="aptolix-menu-icon">⤓</span>\n <span class="aptolix-menu-text">Download Chat</span>\n </button>`:""}\n </div>`:""}\n </div>\n </div>\n </div>\n <div id="aptolix-chat-messages-${t}" style="background-color: ${e.window.background}; position: relative;">\n </div>\n <div id="aptolix-chat-input-${t}" style="border-top: 2px solid ${e.input.border};">\n <textarea id="aptolix-chat-inputbox-${t}" rows="1" placeholder="Type your message..." style="resize:none; border-color: ${e.input.border}; background-color: ${e.window.background};"></textarea>\n <button style="background-color: ${Te.botaccentColor}; color: ${e.input.buttonText};">Send</button>\n </div>\n <div class="aptolix-footer">\n <div class="aptolix-powered-by" style="color: ${e.footer.text};">\n Powered by <a href="${r}" target="_blank" rel="noopener" class="aptolix-link" style="color: ${Te.botaccentColor};">Aptolix</a>\n </div>\n ${Te.allowRating?`<span class="aptolix-footer-separator">|</span>\n <div class="aptolix-rating" id="aptolix-rating-${t}">\n <span class="aptolix-rating-label">Rate this chat:</span>\n <div class="aptolix-stars" id="aptolix-stars-${t}">\n <span class="star" data-rating="1">☆</span>\n <span class="star" data-rating="2">☆</span>\n <span class="star" data-rating="3">☆</span>\n <span class="star" data-rating="4">☆</span>\n <span class="star" data-rating="5">☆</span>\n </div>\n </div>`:""}\n </div>\n </div>\n `;if(Se)document.body.innerHTML=p,document.documentElement.style.height="100%",document.documentElement.style.margin="0",document.documentElement.style.padding="0",document.body.style.height="100%",document.body.style.margin="0",document.body.style.padding="0",document.body.style.overflow="hidden",document.body.style.fontFamily="'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";else{let e=document.body;if(Te.target){const t="string"==typeof Te.target?document.querySelector(Te.target):Te.target;t&&(e=t)}e.insertAdjacentHTML("beforeend",p)}}(),await async function(){const e=Le.getConversationHistory();e&&e.length>0&&(Re=e,function(){const e=document.querySelector(`#aptolix-chat-messages-${Te.chatbotId}`);if(!e)return;const t=$e(Te.botaccentColor);e.innerHTML=xe(Re,{botAvatar:Te.botAvatar,userAvatar:Te.userAvatar,botName:Te.botname,userName:Te.username||"You",accentColor:Te.botaccentColor,userBgColor:t.messages.userBackground,userTextColor:t.messages.userText,botBgColor:t.messages.botBackground,botTextColor:t.messages.botText,timestampColor:t.messages.timestamp,useExactTime:!1}),Fe(),Ze()}())}(),function(){const e=Te.chatbotId,t=$e(Te.botaccentColor),n=document.querySelector(`#aptolix-chat-close-${e}`),a=Te.allowReset?document.querySelector(`#aptolix-chat-reset-${e}`):null,i=Te.allowExpandChatWindow?document.querySelector(`#aptolix-chat-expand-${e}`):null,s=Te.allowExpandChatWindow?document.querySelector(`#aptolix-chat-expand-icon-${e}`):null,r=document.querySelector(`#aptolix-chat-inputbox-${e}`),o=document.querySelector(`#aptolix-chat-input-${e} button`);document.querySelector(`#aptolix-chat-messages-${e}`);const l=Te.allowDownloadTranscript?document.querySelector(`#aptolix-chat-download-${e}`):null,c=Te.allowReset||Te.allowDownloadTranscript?document.querySelector(`#aptolix-chat-menu-${e}`):null,p=Te.allowReset||Te.allowDownloadTranscript?document.querySelector(`#aptolix-chat-menu-dropdown-${e}`):null;n&&n.addEventListener("click",()=>{if(Se)He(qe);else{const t=document.querySelector(`#aptolix-chat-window-${e}`);t&&(t.style.display="none")}});a&&a.addEventListener("click",async()=>{confirm("Are you sure you want to reset the chat? This will clear all messages.")&&await async function(){Re=[],Ce=`${Te.chatbotId}-${Date.now()}`,Ae=null,Le.clearSessionId(Te.chatbotId),Le.clearConversationHistory();const e=document.querySelector(`#aptolix-chat-messages-${Te.chatbotId}`);e&&(e.innerHTML="");We(),Ze()}(),p&&(p.style.display="none")});if(i&&s){let t=!1;i.addEventListener("click",()=>{t=!t;const n=document.querySelector(`#aptolix-chat-window-${e}`);t?(n.classList.add("expanded"),s.textContent="⤡"):(n.classList.remove("expanded"),s.textContent="⤢"),Se&&He("APTOLIX_EXPAND_TOGGLE",{isExpanded:t}),Ze()})}l&&l.addEventListener("click",()=>{!function(){let e=`Aptolix Chat Transcript - ${Te.botname}\n`;e+=`Date: ${(new Date).toLocaleString()}\n`,e+=`${"=".repeat(50)}\n\n`,Re.forEach(t=>{const n=new Date(t.timestamp).toLocaleString(),a="user"===t.type?Te.username||"You":Te.botname;e+=`[${n}] ${a}:\n${t.text}\n\n`});const t=new Blob([e],{type:"text/plain"}),n=URL.createObjectURL(t),a=document.createElement("a");a.href=n,a.download=`chat-transcript-${Date.now()}.txt`,a.click(),URL.revokeObjectURL(n)}(),p&&(p.style.display="none")});if(c&&p){c.addEventListener("click",e=>{e.stopPropagation();const t="block"===p.style.display;p.style.display=t?"none":"block"}),document.addEventListener("click",()=>{p.style.display="none"});p.querySelectorAll(".aptolix-menu-item").forEach(e=>{e.addEventListener("mouseenter",()=>{e.style.backgroundColor=t.menu.hover}),e.addEventListener("mouseleave",()=>{e.style.backgroundColor=t.menu.background})})}r&&(r.addEventListener("focus",()=>{r.style.borderColor=t.primary}),r.addEventListener("blur",()=>{r.style.borderColor=t.input.border}),r.addEventListener("keydown",e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),Ne())}),r.addEventListener("input",()=>{r.style.height="auto",r.style.height=r.scrollHeight+"px",Ze()}),Te.inputCharLimit&&r.setAttribute("maxlength",Te.inputCharLimit));o&&o.addEventListener("click",Ne);if(Te.allowRating){document.querySelectorAll(`#aptolix-stars-${e} .star`).forEach(e=>{e.addEventListener("click",()=>{!async function(e){Le.saveRating(Ce,e),Ue(e);try{await fetch(`${ze}/chatbot/${Te.chatbotId}/rating`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chatbot_id:Te.chatbotId,visitor_id:_e,session_id:Ae,rating:e})})}catch(e){console.error("Failed to submit rating:",e)}}(parseInt(e.getAttribute("data-rating")))}),e.addEventListener("mouseenter",()=>{Ue(parseInt(e.getAttribute("data-rating")))})});const t=document.querySelector(`#aptolix-stars-${e}`);t&&t.addEventListener("mouseleave",()=>{Ue(Le.getRating(Ce)||0)})}}(),0===Re.length&&We(),Ie=!0,Se&&He(Me),Se&&Ze(),Te.chatbotId}function We(){if(!Te.greetingMessage)return;const e={text:Te.greetingMessage,type:"bot",timestamp:Date.now(),messageId:`greeting-${Date.now()}`};Re.push(e),Oe(e)}function Oe(e){const t=document.querySelector(`#aptolix-chat-messages-${Te.chatbotId}`);if(!t)return;const n=$e(Te.botaccentColor),a=xe([e],{botAvatar:Te.botAvatar,userAvatar:Te.userAvatar,botName:Te.botname,userName:Te.username||"You",accentColor:Te.botaccentColor,userBgColor:n.messages.userBackground,userTextColor:n.messages.userText,botBgColor:n.messages.botBackground,botTextColor:n.messages.botText,timestampColor:n.messages.timestamp,useExactTime:!1});t.insertAdjacentHTML("beforeend",a),Fe(),Ze()}async function Ne(){const e=document.querySelector(`#aptolix-chat-inputbox-${Te.chatbotId}`);if(!e)return;const t=e.value.trim();if(!t)return;e.value="",e.style.height="auto";const n={text:t,type:"user",timestamp:Date.now(),messageId:`user-${Date.now()}`};Re.push(n),Oe(n),Le.saveConversationHistory(Re),function(){const e=document.querySelector(`#aptolix-chat-messages-${Te.chatbotId}`);if(!e)return;const t=$e(Te.botaccentColor),n=document.createElement("div");n.id="aptolix-typing-indicator",n.innerHTML=`\n <div class="aptolix-messages-wrapper">\n <div class="message bot typing">\n <div class="message-avatar">\n ${Te.botAvatar}\n </div>\n <div class="message-content">\n <div class="message-text" style="background-color: ${t.messages.botBackground}; color: ${t.messages.botText};">\n <span class="typing-dots">\n <span>.</span><span>.</span><span>.</span>\n </span>\n </div>\n </div>\n </div>\n </div>\n `,e.appendChild(n),Fe(),Ze()}();try{const e=await fetch(`${ze}/chatbot/${Te.chatbotId}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:t,chatbot_id:Te.chatbotId,visitor_id:_e,session_id:Ae})});if(!e.ok)throw new Error(`API error: ${e.status}`);je({data:await e.json()})}catch(e){je({error:e.message})}}function je(e){if(function(){const e=document.getElementById("aptolix-typing-indicator");e&&(e.remove(),Ze())}(),e.error){const t={text:`Error: ${e.error}`,type:"bot",timestamp:Date.now(),messageId:`error-${Date.now()}`};return Re.push(t),void Oe(t)}const t=e.data;t.visitor_id&&(_e=t.visitor_id,Le.saveVisitorId(Te.chatbotId,_e)),t.session_id&&(Ae=t.session_id,Le.saveSessionId(Te.chatbotId,Ae));const n={text:t.response||t.message||"No response",type:"bot",timestamp:Date.now(),messageId:t.message_id||`bot-${Date.now()}`};Re.push(n),Oe(n),Le.saveConversationHistory(Re)}function Ue(e){document.querySelectorAll(`#aptolix-stars-${Te.chatbotId} .star`).forEach((t,n)=>{t.textContent=n<e?"★":"☆"})}function Fe(){const e=document.querySelector(`#aptolix-chat-messages-${Te.chatbotId}`);e&&(e.scrollTop=e.scrollHeight)}function Ze(){requestAnimationFrame(()=>{const e=document.body.scrollHeight;He(Pe,{height:e})})}Se&&(window.addEventListener("message",e=>{if(e.source!==window.parent)return;const{type:t,payload:n}=e.data;switch(t){case Ee:Be(n,n.apiHost);break;case De:setTimeout(()=>Fe(),50)}}),He(Me));const Ge=new Map,Qe={init:async({apiHost:e,chatbotId:n,botname:i,widgetIcon:s,companyLogo:r,companyLogoUrl:o,botAvatar:l,botavatarUrl:c,botaccentColor:p,floatingWelcomeMessage:h,floatingWelcomeDelay:d,greetingMessage:g,allowDownloadTranscript:u,allowExpandChatWindow:x,allowFullPageChat:m,inputCharLimit:f,allowReset:b,allowRating:w,ratingThreshold:y,ratingInterval:k,mode:v="bubble",target:$})=>{if(e&&n){if(Ge.has(n)){console.error(`Duplicate chatbot detected: Chatbot ID "${n}" is already initialized on this page.`);const e=document.createElement("div");if(e.id=`window-${n}-error`,e.className="aptolix-chat-window",e.style.cssText="\n position: fixed;\n bottom: 100px;\n right: 32px;\n width: 400px;\n max-width: calc(100vw - 64px);\n background: #fee;\n border: 2px solid #f44;\n border-radius: 16px;\n padding: 20px;\n box-shadow: 0 4px 20px rgba(244, 67, 54, 0.3);\n z-index: 9998;\n font-family: 'Inter', sans-serif;\n ",e.innerHTML=`\n <div style="text-align: center;">\n <div style="font-size: 48px; margin-bottom: 10px;">⚠️</div>\n <h3 style="margin: 0 0 10px 0; color: #c62828; font-size: 1.1rem;">Duplicate Chatbot Detected</h3>\n <p style="margin: 0 0 15px 0; color: #666; font-size: 0.9rem; line-height: 1.5;">\n A chatbot with ID <strong style="color: #c62828;">${n}</strong> is already active on this page.\n </p>\n <p style="margin: 0; color: #888; font-size: 0.85rem; line-height: 1.4;">\n <strong>Solution:</strong> Use different Chatbot IDs for multiple chatbots on the same page.\n </p>\n <button onclick="this.parentElement.parentElement.remove()" style="\n margin-top: 15px;\n padding: 8px 16px;\n background: #c62828;\n color: white;\n border: none;\n border-radius: 6px;\n cursor: pointer;\n font-weight: 600;\n ">Close</button>\n </div>\n `,"bubble"===v)document.body.appendChild(e),setTimeout(()=>e.remove(),1e4);else if("section"===v&&$){const t="string"==typeof $?document.querySelector($):$;t&&(e.style.position="static",e.style.width="100%",e.style.height="100%",e.style.display="flex",e.style.alignItems="center",e.style.justifyContent="center",t.appendChild(e))}return null}Ge.set(n,{initializing:!0});try{const S=await a(e,n),I={botname:i||S?.botname||t.botname,widgetIcon:s||S?.widgetIcon||t.widgetIcon,companyLogo:r||S?.companyLogo||t.companyLogo,companyLogoUrl:o||S?.companyLogoUrl||"",botAvatar:l||S?.botAvatar||t.botAvatar,botavatarUrl:c||S?.botavatarUrl||"",userAvatar:S?.userAvatar||t.userAvatar,username:S?.username||t.username,botaccentColor:p||S?.botaccentColor||t.botaccentColor,floatingWelcomeMessage:h||S?.floatingWelcomeMessage||t.floatingWelcomeMessage,floatingWelcomeDelay:d||S?.floatingWelcomeDelay||t.floatingWelcomeDelay,greetingMessage:g||S?.greetingMessage||t.greetingMessage,allowDownloadTranscript:void 0!==u?u:void 0!==S?.allowDownloadTranscript?S.allowDownloadTranscript:t.allowDownloadTranscript,allowExpandChatWindow:void 0!==x?x:void 0!==S?.allowExpandChatWindow?S.allowExpandChatWindow:t.allowExpandChatWindow,allowFullPageChat:void 0!==m?m:void 0!==S?.allowFullPageChat?S.allowFullPageChat:t.allowFullPageChat,inputCharLimit:f||S?.inputCharLimit||t.inputCharLimit,allowReset:void 0!==b?b:void 0!==S?.allowReset?S.allowReset:t.allowReset,allowRating:void 0!==w?w:void 0!==S?.allowRating?S.allowRating:t.allowRating,ratingThreshold:y||S?.ratingThreshold||t.ratingThreshold,ratingInterval:k||S?.ratingInterval||t.ratingInterval,mode:v||t.mode,target:$},T=e=>!(!e||"string"!=typeof e)&&/^https?:\/\/.+/.test(e.trim()),C=async e=>new Promise(t=>{const n=new Image,a=setTimeout(()=>{n.src="",t(!1)},3e3);n.onload=()=>{clearTimeout(a),t(!0)},n.onerror=()=>{clearTimeout(a),t(!1)},n.src=e}),_=e=>{if(!e||"string"!=typeof e)return!1;if(!/^\s*<svg[\s\S]*<\/svg>\s*$/i.test(e))return!1;try{const t=(new DOMParser).parseFromString(e,"image/svg+xml");return!t.querySelector("parsererror")}catch(e){return!1}},A=$e(I.botaccentColor),R=(A.isLight,A.messages.userBackground,A.messages.userText,A.messages.botBackground,A.messages.botText,A.messages.link,A.header.text,A.header.button,A.input.buttonText,A.window.border,A.window.background,A.input.border,A.header.border,A.footer.text,A.window.shadow,r||S?.companyLogo);let L=R,z=!1;if(R&&T(R)){await C(R)||(z=!0)}else R&&!_(R)&&(z=!0);I.companyLogo=z?null:L;const E=I.botAvatar;let D=E,M=!1;if(E&&T(E)){await C(E)||(M=!0)}else E&&!_(E)&&(M=!0);if(I.botAvatar=M?null:D,"bubble"===I.mode){const t=await async function(e,t){const n=e.chatbotId;let a=null,i=null,s=null,r=!1;i=document.createElement("div"),i.id=`bubble-${n}`,i.className="aptolix-chat-bubble",i.setAttribute("data-chatbot-id",n),i.style.backgroundColor=e.botaccentColor;const o=e.widgetIcon;o.includes("<svg")||o.includes("<")&&o.includes(">")?i.innerHTML=o:i.innerText=o,document.body.appendChild(i),s=document.createElement("div"),s.id=`hint-${n}`,s.className="aptolix-hint-bubble",s.setAttribute("data-chatbot-id",n),s.style.display="none",s.style.position="fixed",s.style.right="40px",s.style.bottom="110px",s.style.zIndex="9999";const l=document.createElement("span");l.textContent=e.floatingWelcomeMessage;const c=document.createElement("button");let p;c.id="aptolix-hint-close",c.title="Close",c.setAttribute("aria-label","Close"),c.innerHTML="&#10005;",c.style.background="none",c.style.border="none",c.style.color=e.botaccentColor,c.style.fontSize="1.3em",c.style.position="absolute",c.style.top="8px",c.style.right="12px",c.style.cursor="pointer",c.style.padding="0",c.addEventListener("click",()=>{s.style.display="none",sessionStorage.setItem("aptolixHintClosed","true"),clearTimeout(p)}),s.appendChild(l),s.appendChild(c),document.body.appendChild(s),p=setTimeout(()=>{a&&"none"===a.style.display&&!sessionStorage.getItem("aptolixHintClosed")&&(s.style.display="block")},1e3*e.floatingWelcomeDelay),a=document.createElement("iframe"),a.id=`iframe-${n}`,a.className="aptolix-chat-iframe",a.setAttribute("data-chatbot-id",n);const h=window.innerWidth<=768;let d;a.style.cssText=`\n position: fixed;\n bottom: ${h?"80px":"100px"};\n right: ${h?"16px":"32px"};\n width: ${h?"calc(100vw - 32px)":"500px"};\n max-width: calc(100vw - ${h?"32px":"64px"});\n height: ${h?"calc(100vh - 120px)":"650px"};\n max-height: calc(100vh - ${h?"120px":"150px"});\n min-height: ${h?"400px":"450px"};\n border: none;\n border-radius: 16px;\n box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);\n z-index: 9998;\n display: none;\n background: white;\n transition: opacity 0.3s ease, transform 0.3s ease;\n `,window.addEventListener("resize",()=>{clearTimeout(d),d=setTimeout(()=>{const e=window.innerWidth<=768;a.style.bottom=e?"80px":"100px",a.style.right=e?"16px":"32px",a.style.width=e?"calc(100vw - 32px)":"500px",a.style.maxWidth=`calc(100vw - ${e?"32px":"64px"})`,a.style.height=e?"calc(100vh - 120px)":"650px",a.style.maxHeight=`calc(100vh - ${e?"120px":"150px"})`,a.style.minHeight=e?"400px":"450px"},100)});const g=new URL(import.meta.url),u=g.origin+g.pathname.substring(0,g.pathname.lastIndexOf("/"))+"/chatbot-core.mjs";console.log("[Aptolix] import.meta.url:",import.meta.url),console.log("[Aptolix] chatbotCoreUrl:",u);const x=window.location.hostname,m=`\n <!DOCTYPE html>\n <html lang="en">\n <head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <title>Aptolix Chat</title>\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n body {\n margin: 0;\n padding: 0;\n overflow: hidden;\n font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;\n }\n </style>\n </head>\n <body>\n <script>\n // Store parent hostname for LOCAL badge detection\n window.__parentHostname__ = ${JSON.stringify(x)};\n <\/script>\n <script type="module" src="${u}"><\/script>\n </body>\n </html>\n `;a.srcdoc=m,document.body.appendChild(a);const f=async i=>{if(i.source!==a.contentWindow)return;if(!i.data||"aptolix-chatbot-iframe"!==i.data.source)return;const{type:s,payload:o}=i.data;switch(s){case ye:b(be,{...e,apiHost:t,chatbotId:n,conversationId:`${n}-${Date.now()}`});break;case ke:o.height&&!r&&(a.style.height=Math.min(o.height,window.innerHeight-150)+"px");break;case"APTOLIX_EXPAND_TOGGLE":r=!!o.isExpanded;const i=window.innerWidth<=768;o.isExpanded?i?(a.style.width="calc(100vw - 16px)",a.style.maxWidth="calc(100vw - 16px)",a.style.height="calc(100vh - 80px)",a.style.maxHeight="calc(100vh - 80px)",a.style.minHeight="calc(100vh - 80px)",a.style.right="8px",a.style.bottom="70px"):(a.style.width="900px",a.style.maxWidth="900px",a.style.height="calc(100vh - 130px)",a.style.maxHeight="calc(100vh - 130px)",a.style.minHeight="calc(100vh - 130px)",a.style.right="32px",a.style.bottom="100px"):i?(a.style.minHeight="",a.style.width="calc(100vw - 32px)",a.style.maxWidth="calc(100vw - 32px)",a.style.height="calc(100vh - 120px)",a.style.maxHeight="calc(100vh - 120px)",a.style.minHeight="400px",a.style.right="16px",a.style.bottom="80px"):(a.style.minHeight="",a.style.width="500px",a.style.maxWidth="calc(100vw - 64px)",a.style.height="650px",a.style.maxHeight="calc(100vh - 150px)",a.style.minHeight="450px",a.style.right="32px",a.style.bottom="100px");break;case ve:a.style.display="none"}};function b(e,t={}){a&&a.contentWindow&&a.contentWindow.postMessage({type:e,payload:t},"*")}window.addEventListener("message",f),i.addEventListener("click",()=>{"none"===a.style.display?(a.style.display="block",s.style.display="none",clearTimeout(p),b(we)):a.style.display="none"});const w=new MutationObserver(()=>{"block"===a.style.display&&(s.style.display="none",clearTimeout(p))});return w.observe(a,{attributes:!0,attributeFilter:["style"]}),{bubbleId:i.id,hintBubbleId:s.id,iframeId:a.id,destroy:()=>{window.removeEventListener("message",f),w.disconnect(),i&&i.remove(),s&&s.remove(),a&&a.remove(),clearTimeout(p)}}}({...I,chatbotId:n,apiHost:e},e);return void Ge.set(n,{mode:"bubble",...t})}const P=await Be({...I,chatbotId:n},e);return Ge.set(n,{chatWindowId:`aptolix-chat-window-${n}`,mode:"section"}),P}catch(e){throw Ge.delete(n),console.error(`Failed to initialize chatbot ${n}:`,e),e}}else console.error("apiHost and chatbotId are mandatory parameters")},initFull:function(e){let t=document.querySelector("aptolix-chatbot");t&&Object.entries(e).forEach(([e,n])=>{t.setAttribute(e,n)})},destroy:function(e=null){if(e){const t=Ge.get(e);if(t){if("bubble"===t.mode&&t.destroy)t.destroy();else if(t.chatWindowId){const e=document.getElementById(t.chatWindowId);e&&e.remove()}Ge.delete(e)}const n=document.getElementById(`window-${e}-error`);n&&n.remove()}else Ge.forEach((e,t)=>{e.destroy&&e.destroy()}),document.querySelectorAll(".aptolix-chat-bubble").forEach(e=>e.remove()),document.querySelectorAll(".aptolix-hint-bubble").forEach(e=>e.remove()),document.querySelectorAll(".aptolix-chat-iframe").forEach(e=>e.remove()),document.querySelectorAll(".aptolix-chat-window").forEach(e=>e.remove()),document.querySelectorAll('[id$="-error"]').forEach(e=>{e.id.startsWith("window-")&&e.remove()}),Ge.clear()},getActiveInstances:function(){return Array.from(Ge.keys())}};class Xe extends HTMLElement{static get observedAttributes(){return["apihost","chatbotid","botname","widgeticon","companylogo","companylogourl","botavatar","botavatarurl","botaccentcolor","floatingwelcomemessage","floatingwelcomedelay","greetingmessage","allowdownloadtranscript","allowexpandchatwindow","allowfullpagechat","inputcharlimit","target"]}connectedCallback(){this.tryInit()}attributeChangedCallback(){this._initialized&&(clearTimeout(this._reinitTimeout),this._reinitTimeout=setTimeout(()=>{const e=this.getAttribute("chatbotid");e&&Qe.destroy(e),this._initialized=!1,this.tryInit()},100))}tryInit(){const e=this.getAttribute("apihost"),t=this.getAttribute("chatbotid");if(!e||!t)return;const n=this.getAttribute("botname"),a=this.getAttribute("widgeticon"),i=this.getAttribute("companylogo"),s=this.getAttribute("companylogourl"),r=this.getAttribute("botavatar"),o=this.getAttribute("botavatarurl"),l=this.getAttribute("botaccentcolor"),c=this.getAttribute("floatingwelcomemessage"),p=this.getAttribute("floatingwelcomedelay"),h=this.getAttribute("greetingmessage"),d="true"===this.getAttribute("allowdownloadtranscript"),g="true"===this.getAttribute("allowexpandchatwindow"),u="true"===this.getAttribute("allowfullpagechat"),x=parseInt(this.getAttribute("inputcharlimit"))||void 0,m=this.getAttribute("target");let f=this;if(m){const e=document.querySelector(m);e&&(f=e)}this._initialized||(this._initialized=!0,Qe.init({apiHost:e,chatbotId:t,botname:n,widgetIcon:a,companyLogo:i,companyLogoUrl:s,botAvatar:r,botavatarUrl:o,botaccentColor:l,floatingWelcomeMessage:c,floatingWelcomeDelay:p,greetingMessage:h,allowDownloadTranscript:d,allowExpandChatWindow:g,allowFullPageChat:u,inputCharLimit:x,mode:"section",target:f}))}}customElements.get("aptolix-chatbot")||customElements.define("aptolix-chatbot",Xe);export{Qe as default,xe as formatMessages};
2
2
  //# sourceMappingURL=web.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aptolix_chatbot",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "Aptolix Chatbot for embedding on websites",
5
5
  "main": "dist/web.mjs",
6
6
  "module": "dist/web.mjs",