var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,i)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,__spreadValues=(e,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(e,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(e,i,t[i]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t)),__publicField=(e,t,i)=>(__defNormalProp(e,"symbol"!=typeof t?t+"":t,i),i),__async=(e,t,i)=>new Promise(((n,s)=>{var r=e=>{try{o(i.next(e))}catch(t){s(t)}},a=e=>{try{o(i.throw(e))}catch(t){s(t)}},o=e=>e.done?n(e.value):Promise.resolve(e.value).then(r,a);o((i=i.apply(e,t)).next())}));!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Artalk=t()}(this,(function(){"use strict";const e={placeholder:"Leave a comment",noComment:"No Comment",send:"Send",save:"Save",nick:"Nickname",email:"Email",link:"Website",emoticon:"Emoji",preview:"Preview",image:"Image",uploadFail:"Upload Failed",commentFail:"Failed to comment",restoredMsg:"Content has been restored",onlyAdminCanReply:"Only admin can reply",uploadLoginMsg:"Please fill in your name and email to upload",counter:"{count} Comments",sortLatest:"Latest",sortOldest:"Oldest",sortBest:"Best",sortAuthor:"Author",openComment:"Open Comment",closeComment:"Close Comment",listLoadFailMsg:"Failed to load comments",listRetry:"Click to retry",loadMore:"Load More",admin:"Admin",reply:"Reply",voteUp:"Up",voteDown:"Down",voteFail:"Vote Failed",readMore:"Read More",actionConfirm:"Confirm",collapse:"Collapse",collapsed:"Collapsed",collapsedMsg:"This comment has been collapsed",expand:"Expand",approved:"Approved",pending:"Pending",pendingMsg:"Pending, visible only to commenter.",edit:"Edit",editCancel:"Cancel Edit",delete:"Delete",deleteConfirm:"Confirm",pin:"Pin",unpin:"Unpin",seconds:"seconds ago",minutes:"minutes ago",hours:"hours ago",days:"days ago",now:"just now",adminCheck:"Enter admin password:",captchaCheck:"Enter the CAPTCHA to continue:",confirm:"Confirm",cancel:"Cancel",msgCenter:"Messages",ctrlCenter:"Admin",frontend:"Frontend",backend:"Backend",loading:"Loading",loadFail:"Load Failed",editing:"Editing",editFail:"Edit Failed",deleting:"Deleting",deleteFail:"Delete Failed",reqGot:"Request got",reqAborted:"Request timed out or terminated unexpectedly"},t={en:e,"en-US":e,"zh-CN":{placeholder:"键入内容...",noComment:"「此时无声胜有声」",send:"发送评论",save:"保存评论",nick:"昵称",email:"邮箱",link:"网址",emoticon:"表情",preview:"预览",image:"图片",uploadFail:"上传失败",commentFail:"评论失败",restoredMsg:"内容已自动恢复",onlyAdminCanReply:"仅管理员可评论",uploadLoginMsg:"填入你的名字邮箱才能上传哦",counter:"{count} 条评论",sortLatest:"最新",sortOldest:"最早",sortBest:"最热",sortAuthor:"作者",openComment:"打开评论",closeComment:"关闭评论",listLoadFailMsg:"无法获取评论列表数据",listRetry:"点击重新获取",loadMore:"加载更多",admin:"管理员",reply:"回复",voteUp:"赞同",voteDown:"反对",voteFail:"投票失败",readMore:"阅读更多",actionConfirm:"确认操作",collapse:"折叠",collapsed:"已折叠",collapsedMsg:"该评论已被系统或管理员折叠",expand:"展开",approved:"已审",pending:"待审",pendingMsg:"审核中,仅本人可见。",edit:"编辑",editCancel:"取消编辑",delete:"删除",deleteConfirm:"确认删除",pin:"置顶",unpin:"取消置顶",seconds:"秒前",minutes:"分钟前",hours:"小时前",days:"天前",now:"刚刚",adminCheck:"键入密码来验证管理员身份:",captchaCheck:"键入验证码继续:",confirm:"确认",cancel:"取消",msgCenter:"通知中心",ctrlCenter:"控制中心",frontend:"前端",backend:"后端",loading:"加载中",loadFail:"加载失败",editing:"修改中",editFail:"修改失败",deleting:"删除中",deleteFail:"删除失败",reqGot:"请求响应",reqAborted:"请求超时或意外终止"}};function i(e,i,n={}){var s;"string"==typeof e&&(s=(s=e).replace(/^([a-zA-Z]+)(-[a-zA-Z]+)?$/,((e,t,i)=>t.toLowerCase()+(i||"").toUpperCase())),e=t[s]?t[s]:window.ArtalkI18n&&window.ArtalkI18n[s]?window.ArtalkI18n[s]:t.en);let r=(null==e?void 0:e[i])||i;return r=r.replace(/\{\s*(\w+?)\s*\}/g,((e,t)=>n[t]||"")),r}class n{constructor(e){__publicField(this,"ctx"),__publicField(this,"data"),this.ctx=e;const t=JSON.parse(window.localStorage.getItem("ArtalkUser")||"{}");this.data={nick:t.nick||"",email:t.email||"",link:t.link||"",token:t.token||"",isAdmin:t.isAdmin||!1}}update(e={}){Object.entries(e).forEach((([e,t])=>{this.data[e]=t})),window.localStorage.setItem("ArtalkUser",JSON.stringify(this.data)),this.ctx.trigger("user-changed",this.ctx.user.data)}logout(){this.update({token:"",isAdmin:!1})}checkHasBasicUserInfo(){return!!this.data.nick&&!!this.data.email}}function s(){return{baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartLists:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let r={baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartLists:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1};const a=/[&<>"']/,o=/[&<>"']/g,l=/[<>"']|&(?!#?\w+;)/,c=/[<>"']|&(?!#?\w+;)/g,h={"&":"&","<":"<",">":">",'"':""","'":"'"},d=e=>h[e];function u(e,t){if(t){if(a.test(e))return e.replace(o,d)}else if(l.test(e))return e.replace(c,d);return e}const p=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function m(e){return e.replace(p,((e,t)=>"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""))}const g=/(^|[^\[])\^/g;function f(e,t){e="string"==typeof e?e:e.source,t=t||"";const i={replace:(t,n)=>(n=(n=n.source||n).replace(g,"$1"),e=e.replace(t,n),i),getRegex:()=>new RegExp(e,t)};return i}const k=/[^\w:]/g,y=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function $(e,t,i){if(e){let e;try{e=decodeURIComponent(m(i)).replace(k,"").toLowerCase()}catch(n){return null}if(0===e.indexOf("javascript:")||0===e.indexOf("vbscript:")||0===e.indexOf("data:"))return null}t&&!y.test(i)&&(i=function(e,t){b[" "+e]||(_.test(e)?b[" "+e]=e+"/":b[" "+e]=T(e,"/",!0));const i=-1===(e=b[" "+e]).indexOf(":");return"//"===t.substring(0,2)?i?t:e.replace(x,"$1")+t:"/"===t.charAt(0)?i?t:e.replace(v,"$1")+t:e+t}(t,i));try{i=encodeURI(i).replace(/%25/g,"%")}catch(n){return null}return i}const b={},_=/^[^:]+:\/*[^/]*$/,x=/^([^:]+:)[\s\S]*$/,v=/^([^:]+:\/*[^/]*)[\s\S]*$/;const w={exec:function(){}};function C(e){let t,i,n=1;for(;n{let n=!1,s=t;for(;--s>=0&&"\\"===i[s];)n=!n;return n?"|":" |"})).split(/ \|/);let n=0;if(i[0].trim()||i.shift(),i.length>0&&!i[i.length-1].trim()&&i.pop(),i.length>t)i.splice(t);else for(;i.length1;)1&t&&(i+=e),t>>=1,e+=e;return i+e}function A(e,t,i,n){const s=t.href,r=t.title?u(t.title):null,a=e[1].replace(/\\([\[\]])/g,"$1");if("!"!==e[0].charAt(0)){n.state.inLink=!0;const e={type:"link",raw:i,href:s,title:r,text:a,tokens:n.inlineTokens(a,[])};return n.state.inLink=!1,e}return{type:"image",raw:i,href:s,title:r,text:u(a)}}class F{constructor(e){this.options=e||r}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:T(e,"\n")}}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],i=function(e,t){const i=e.match(/^(\s+)(?:```)/);if(null===i)return t;const n=i[1];return t.split("\n").map((e=>{const t=e.match(/^\s+/);if(null===t)return e;const[i]=t;return i.length>=n.length?e.slice(n.length):e})).join("\n")}(e,t[3]||"");return{type:"code",raw:e,lang:t[2]?t[2].trim():t[2],text:i}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(/#$/.test(e)){const t=T(e,"#");this.options.pedantic?e=t.trim():t&&!/ $/.test(t)||(e=t.trim())}const i={type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:[]};return this.lexer.inline(i.text,i.tokens),i}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:t[0]}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){const e=t[0].replace(/^ *>[ \t]?/gm,"");return{type:"blockquote",raw:t[0],tokens:this.lexer.blockTokens(e,[]),text:e}}}list(e){let t=this.rules.block.list.exec(e);if(t){let i,n,s,r,a,o,l,c,h,d,u,p,m=t[1].trim();const g=m.length>1,f={type:"list",raw:"",ordered:g,start:g?+m.slice(0,-1):"",loose:!1,items:[]};m=g?`\\d{1,9}\\${m.slice(-1)}`:`\\${m}`,this.options.pedantic&&(m=g?m:"[*+-]");const k=new RegExp(`^( {0,3}${m})((?:[\t ][^\\n]*)?(?:\\n|$))`);for(;e&&(p=!1,t=k.exec(e))&&!this.rules.block.hr.test(e);){if(i=t[0],e=e.substring(i.length),c=t[2].split("\n",1)[0],h=e.split("\n",1)[0],this.options.pedantic?(r=2,u=c.trimLeft()):(r=t[2].search(/[^ ]/),r=r>4?1:r,u=c.slice(r),r+=t[1].length),o=!1,!c&&/^ *$/.test(h)&&(i+=h+"\n",e=e.substring(h.length+1),p=!0),!p){const t=new RegExp(`^ {0,${Math.min(3,r-1)}}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))`),n=new RegExp(`^ {0,${Math.min(3,r-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),s=new RegExp(`^ {0,${Math.min(3,r-1)}}(?:\`\`\`|~~~)`),a=new RegExp(`^ {0,${Math.min(3,r-1)}}#`);for(;e&&(d=e.split("\n",1)[0],c=d,this.options.pedantic&&(c=c.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!s.test(c))&&!a.test(c)&&!t.test(c)&&!n.test(e);){if(c.search(/[^ ]/)>=r||!c.trim())u+="\n"+c.slice(r);else{if(o)break;u+="\n"+c}o||c.trim()||(o=!0),i+=d+"\n",e=e.substring(d.length+1)}}f.loose||(l?f.loose=!0:/\n *\n *$/.test(i)&&(l=!0)),this.options.gfm&&(n=/^\[[ xX]\] /.exec(u),n&&(s="[ ] "!==n[0],u=u.replace(/^\[[ xX]\] +/,""))),f.items.push({type:"list_item",raw:i,task:!!n,checked:s,loose:!1,text:u}),f.raw+=i}f.items[f.items.length-1].raw=i.trimRight(),f.items[f.items.length-1].text=u.trimRight(),f.raw=f.raw.trimRight();const y=f.items.length;for(a=0;a"space"===e.type)),t=e.every((e=>{const t=e.raw.split("");let i=0;for(const n of t)if("\n"===n&&(i+=1),i>1)return!0;return!1}));!f.loose&&e.length&&t&&(f.loose=!0,f.items[a].loose=!0)}return f}}html(e){const t=this.rules.block.html.exec(e);if(t){const e={type:"html",raw:t[0],pre:!this.options.sanitizer&&("pre"===t[1]||"script"===t[1]||"style"===t[1]),text:t[0]};return this.options.sanitize&&(e.type="paragraph",e.text=this.options.sanitizer?this.options.sanitizer(t[0]):u(t[0]),e.tokens=[],this.lexer.inline(e.text,e.tokens)),e}}def(e){const t=this.rules.block.def.exec(e);if(t){t[3]&&(t[3]=t[3].substring(1,t[3].length-1));return{type:"def",tag:t[1].toLowerCase().replace(/\s+/g," "),raw:t[0],href:t[2],title:t[3]}}}table(e){const t=this.rules.block.table.exec(e);if(t){const e={type:"table",header:S(t[1]).map((e=>({text:e}))),align:t[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split("\n"):[]};if(e.header.length===e.align.length){e.raw=t[0];let i,n,s,r,a=e.align.length;for(i=0;i({text:e})));for(a=e.header.length,n=0;n/i.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(t[0]):u(t[0]):t[0]}}link(e){const t=this.rules.inline.link.exec(e);if(t){const e=t[2].trim();if(!this.options.pedantic&&/^$/.test(e))return;const t=T(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{const e=function(e,t){if(-1===e.indexOf(t[1]))return-1;const i=e.length;let n=0,s=0;for(;s-1){const i=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,i).trim(),t[3]=""}}let i=t[2],n="";if(this.options.pedantic){const e=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(i);e&&(i=e[1],n=e[3])}else n=t[3]?t[3].slice(1,-1):"";return i=i.trim(),/^$/.test(e)?i.slice(1):i.slice(1,-1)),A(t,{href:i?i.replace(this.rules.inline._escapes,"$1"):i,title:n?n.replace(this.rules.inline._escapes,"$1"):n},t[0],this.lexer)}}reflink(e,t){let i;if((i=this.rules.inline.reflink.exec(e))||(i=this.rules.inline.nolink.exec(e))){let e=(i[2]||i[1]).replace(/\s+/g," ");if(e=t[e.toLowerCase()],!e||!e.href){const e=i[0].charAt(0);return{type:"text",raw:e,text:e}}return A(i,e,i[0],this.lexer)}}emStrong(e,t,i=""){let n=this.rules.inline.emStrong.lDelim.exec(e);if(!n)return;if(n[3]&&i.match(/[\p{L}\p{N}]/u))return;const s=n[1]||n[2]||"";if(!s||s&&(""===i||this.rules.inline.punctuation.exec(i))){const i=n[0].length-1;let s,r,a=i,o=0;const l="*"===n[0][0]?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+i);null!=(n=l.exec(t));){if(s=n[1]||n[2]||n[3]||n[4]||n[5]||n[6],!s)continue;if(r=s.length,n[3]||n[4]){a+=r;continue}if((n[5]||n[6])&&i%3&&!((i+r)%3)){o+=r;continue}if(a-=r,a>0)continue;if(r=Math.min(r,r+a+o),Math.min(i,r)%2){const t=e.slice(1,i+n.index+r);return{type:"em",raw:e.slice(0,i+n.index+r+1),text:t,tokens:this.lexer.inlineTokens(t,[])}}const t=e.slice(2,i+n.index+r-1);return{type:"strong",raw:e.slice(0,i+n.index+r+1),text:t,tokens:this.lexer.inlineTokens(t,[])}}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(/\n/g," ");const i=/[^ ]/.test(e),n=/^ /.test(e)&&/ $/.test(e);return i&&n&&(e=e.substring(1,e.length-1)),e=u(e,!0),{type:"codespan",raw:t[0],text:e}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2],[])}}autolink(e,t){const i=this.rules.inline.autolink.exec(e);if(i){let e,n;return"@"===i[2]?(e=u(this.options.mangle?t(i[1]):i[1]),n="mailto:"+e):(e=u(i[1]),n=e),{type:"link",raw:i[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}url(e,t){let i;if(i=this.rules.inline.url.exec(e)){let e,n;if("@"===i[2])e=u(this.options.mangle?t(i[0]):i[0]),n="mailto:"+e;else{let t;do{t=i[0],i[0]=this.rules.inline._backpedal.exec(i[0])[0]}while(t!==i[0]);e=u(i[0]),n="www."===i[1]?"http://"+e:e}return{type:"link",raw:i[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}inlineText(e,t){const i=this.rules.inline.text.exec(e);if(i){let e;return e=this.lexer.state.inRawBlock?this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):u(i[0]):i[0]:u(this.options.smartypants?t(i[0]):i[0]),{type:"text",raw:i[0],text:e}}}}const O={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|\\n*|$)|\\n*|$)|)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?]+)>?(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:w,lheading:/^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/,_label:/(?!\s*\])(?:\\.|[^\[\]\\])+/,_title:/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/};O.def=f(O.def).replace("label",O._label).replace("title",O._title).getRegex(),O.bullet=/(?:[*+-]|\d{1,9}[.)])/,O.listItemStart=f(/^( *)(bull) */).replace("bull",O.bullet).getRegex(),O.list=f(O.list).replace(/bull/g,O.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+O.def.source+")").getRegex(),O._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",O._comment=/|$)/,O.html=f(O.html,"i").replace("comment",O._comment).replace("tag",O._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),O.paragraph=f(O._paragraph).replace("hr",O.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",O._tag).getRegex(),O.blockquote=f(O.blockquote).replace("paragraph",O.paragraph).getRegex(),O.normal=C({},O),O.gfm=C({},O.normal,{table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"}),O.gfm.table=f(O.gfm.table).replace("hr",O.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",O._tag).getRegex(),O.gfm.paragraph=f(O._paragraph).replace("hr",O.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",O.gfm.table).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",O._tag).getRegex(),O.pedantic=C({},O.normal,{html:f("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",O._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:w,paragraph:f(O.normal._paragraph).replace("hr",O.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",O.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()});const M={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:w,tag:"^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(ref)\]/,nolink:/^!?\[(ref)\](?:\[\])?/,reflinkSearch:"reflink|nolink(?!\\()",emStrong:{lDelim:/^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,rDelimAst:/^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[^*]+(?=[^*])|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,rDelimUnd:/^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/},code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:w,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\.5&&(i="x"+i.toString(16)),n+="&#"+i+";";return n}M._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",M.punctuation=f(M.punctuation).replace(/punctuation/g,M._punctuation).getRegex(),M.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,M.escapedEmSt=/\\\*|\\_/g,M._comment=f(O._comment).replace("(?:--\x3e|$)","--\x3e").getRegex(),M.emStrong.lDelim=f(M.emStrong.lDelim).replace(/punct/g,M._punctuation).getRegex(),M.emStrong.rDelimAst=f(M.emStrong.rDelimAst,"g").replace(/punct/g,M._punctuation).getRegex(),M.emStrong.rDelimUnd=f(M.emStrong.rDelimUnd,"g").replace(/punct/g,M._punctuation).getRegex(),M._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,M._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,M._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])?)+(?![-_])/,M.autolink=f(M.autolink).replace("scheme",M._scheme).replace("email",M._email).getRegex(),M._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,M.tag=f(M.tag).replace("comment",M._comment).replace("attribute",M._attribute).getRegex(),M._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,M._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,M._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,M.link=f(M.link).replace("label",M._label).replace("href",M._href).replace("title",M._title).getRegex(),M.reflink=f(M.reflink).replace("label",M._label).replace("ref",O._label).getRegex(),M.nolink=f(M.nolink).replace("ref",O._label).getRegex(),M.reflinkSearch=f(M.reflinkSearch,"g").replace("reflink",M.reflink).replace("nolink",M.nolink).getRegex(),M.normal=C({},M),M.pedantic=C({},M.normal,{strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:f(/^!?\[(label)\]\((.*?)\)/).replace("label",M._label).getRegex(),reflink:f(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",M._label).getRegex()}),M.gfm=C({},M.normal,{escape:f(M.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\t+" ".repeat(i.length)));e;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some((n=>!!(i=n.call({lexer:this},e,t))&&(e=e.substring(i.raw.length),t.push(i),!0)))))if(i=this.tokenizer.space(e))e=e.substring(i.raw.length),1===i.raw.length&&t.length>0?t[t.length-1].raw+="\n":t.push(i);else if(i=this.tokenizer.code(e))e=e.substring(i.raw.length),n=t[t.length-1],!n||"paragraph"!==n.type&&"text"!==n.type?t.push(i):(n.raw+="\n"+i.raw,n.text+="\n"+i.text,this.inlineQueue[this.inlineQueue.length-1].src=n.text);else if(i=this.tokenizer.fences(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.heading(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.hr(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.blockquote(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.list(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.html(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.def(e))e=e.substring(i.raw.length),n=t[t.length-1],!n||"paragraph"!==n.type&&"text"!==n.type?this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title}):(n.raw+="\n"+i.raw,n.text+="\n"+i.raw,this.inlineQueue[this.inlineQueue.length-1].src=n.text);else if(i=this.tokenizer.table(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.lheading(e))e=e.substring(i.raw.length),t.push(i);else{if(s=e,this.options.extensions&&this.options.extensions.startBlock){let t=1/0;const i=e.slice(1);let n;this.options.extensions.startBlock.forEach((function(e){n=e.call({lexer:this},i),"number"==typeof n&&n>=0&&(t=Math.min(t,n))})),t<1/0&&t>=0&&(s=e.substring(0,t+1))}if(this.state.top&&(i=this.tokenizer.paragraph(s)))n=t[t.length-1],r&&"paragraph"===n.type?(n.raw+="\n"+i.raw,n.text+="\n"+i.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=n.text):t.push(i),r=s.length!==e.length,e=e.substring(i.raw.length);else if(i=this.tokenizer.text(e))e=e.substring(i.raw.length),n=t[t.length-1],n&&"text"===n.type?(n.raw+="\n"+i.raw,n.text+="\n"+i.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=n.text):t.push(i);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let i,n,s,r,a,o,l=e;if(this.tokens.links){const e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(r=this.tokenizer.rules.inline.reflinkSearch.exec(l));)e.includes(r[0].slice(r[0].lastIndexOf("[")+1,-1))&&(l=l.slice(0,r.index)+"["+E("a",r[0].length-2)+"]"+l.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(r=this.tokenizer.rules.inline.blockSkip.exec(l));)l=l.slice(0,r.index)+"["+E("a",r[0].length-2)+"]"+l.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;null!=(r=this.tokenizer.rules.inline.escapedEmSt.exec(l));)l=l.slice(0,r.index)+"++"+l.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex);for(;e;)if(a||(o=""),a=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some((n=>!!(i=n.call({lexer:this},e,t))&&(e=e.substring(i.raw.length),t.push(i),!0)))))if(i=this.tokenizer.escape(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.tag(e))e=e.substring(i.raw.length),n=t[t.length-1],n&&"text"===i.type&&"text"===n.type?(n.raw+=i.raw,n.text+=i.text):t.push(i);else if(i=this.tokenizer.link(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.reflink(e,this.tokens.links))e=e.substring(i.raw.length),n=t[t.length-1],n&&"text"===i.type&&"text"===n.type?(n.raw+=i.raw,n.text+=i.text):t.push(i);else if(i=this.tokenizer.emStrong(e,l,o))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.codespan(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.br(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.del(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.autolink(e,B))e=e.substring(i.raw.length),t.push(i);else if(this.state.inLink||!(i=this.tokenizer.url(e,B))){if(s=e,this.options.extensions&&this.options.extensions.startInline){let t=1/0;const i=e.slice(1);let n;this.options.extensions.startInline.forEach((function(e){n=e.call({lexer:this},i),"number"==typeof n&&n>=0&&(t=Math.min(t,n))})),t<1/0&&t>=0&&(s=e.substring(0,t+1))}if(i=this.tokenizer.inlineText(s,R))e=e.substring(i.raw.length),"_"!==i.raw.slice(-1)&&(o=i.raw.slice(-1)),a=!0,n=t[t.length-1],n&&"text"===n.type?(n.raw+=i.raw,n.text+=i.text):t.push(i);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}else e=e.substring(i.raw.length),t.push(i);return t}}class I{constructor(e){this.options=e||r}code(e,t,i){const n=(t||"").match(/\S*/)[0];if(this.options.highlight){const t=this.options.highlight(e,n);null!=t&&t!==e&&(i=!0,e=t)}return e=e.replace(/\n$/,"")+"\n",n?'
'+(i?e:u(e,!0))+"
\n":"
"+(i?e:u(e,!0))+"
\n"}blockquote(e){return`
\n${e}
\n`}html(e){return e}heading(e,t,i,n){if(this.options.headerIds){return`${e}\n`}return`${e}\n`}hr(){return this.options.xhtml?"
\n":"
\n"}list(e,t,i){const n=t?"ol":"ul";return"<"+n+(t&&1!==i?' start="'+i+'"':"")+">\n"+e+"\n"}listitem(e){return`
  • ${e}
  • \n`}checkbox(e){return" "}paragraph(e){return`

    ${e}

    \n`}table(e,t){return t&&(t=`${t}`),"\n\n"+e+"\n"+t+"
    \n"}tablerow(e){return`\n${e}\n`}tablecell(e,t){const i=t.header?"th":"td";return(t.align?`<${i} align="${t.align}">`:`<${i}>`)+e+`\n`}strong(e){return`${e}`}em(e){return`${e}`}codespan(e){return`${e}`}br(){return this.options.xhtml?"
    ":"
    "}del(e){return`${e}`}link(e,t,i){if(null===(e=$(this.options.sanitize,this.options.baseUrl,e)))return i;let n='",n}image(e,t,i){if(null===(e=$(this.options.sanitize,this.options.baseUrl,e)))return i;let n=`${i}":">",n}text(e){return e}}class D{strong(e){return e}em(e){return e}codespan(e){return e}del(e){return e}html(e){return e}text(e){return e}link(e,t,i){return""+i}image(e,t,i){return""+i}br(){return""}}class q{constructor(){this.seen={}}serialize(e){return e.toLowerCase().trim().replace(/<[!\/a-z].*?>/gi,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(e,t){let i=e,n=0;if(this.seen.hasOwnProperty(i)){n=this.seen[e];do{n++,i=e+"-"+n}while(this.seen.hasOwnProperty(i))}return t||(this.seen[e]=n,this.seen[i]=0),i}slug(e,t={}){const i=this.serialize(e);return this.getNextSafeSlug(i,t.dryrun)}}class z{constructor(e){this.options=e||r,this.options.renderer=this.options.renderer||new I,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new D,this.slugger=new q}static parse(e,t){return new z(t).parse(e)}static parseInline(e,t){return new z(t).parseInline(e)}parse(e,t=!0){let i,n,s,r,a,o,l,c,h,d,u,p,g,f,k,y,$,b,_,x="";const v=e.length;for(i=0;i0&&"paragraph"===k.tokens[0].type?(k.tokens[0].text=b+" "+k.tokens[0].text,k.tokens[0].tokens&&k.tokens[0].tokens.length>0&&"text"===k.tokens[0].tokens[0].type&&(k.tokens[0].tokens[0].text=b+" "+k.tokens[0].tokens[0].text)):k.tokens.unshift({type:"text",text:b}):f+=b),f+=this.parse(k.tokens,g),h+=this.renderer.listitem(f,$,y);x+=this.renderer.list(h,u,p);continue;case"html":x+=this.renderer.html(d.text);continue;case"paragraph":x+=this.renderer.paragraph(this.parseInline(d.tokens));continue;case"text":for(h=d.tokens?this.parseInline(d.tokens):d.text;i+1{s(e.text,e.lang,(function(t,i){if(t)return a(t);null!=i&&i!==e.text&&(e.text=i,e.escaped=!0),o--,0===o&&a()}))}),0))})),void(0===o&&a())}try{const i=P.lex(e,t);return t.walkTokens&&U.walkTokens(i,t.walkTokens),z.parse(i,t)}catch(n){if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",t.silent)return"

    An error occurred:

    "+u(n.message+"",!0)+"
    ";throw n}}U.options=U.setOptions=function(e){var t;return C(U.defaults,e),t=U.defaults,r=t,U},U.getDefaults=s,U.defaults=r,U.use=function(...e){const t=C({},...e),i=U.defaults.extensions||{renderers:{},childTokens:{}};let n;e.forEach((e=>{if(e.extensions&&(n=!0,e.extensions.forEach((e=>{if(!e.name)throw new Error("extension name required");if(e.renderer){const t=i.renderers?i.renderers[e.name]:null;i.renderers[e.name]=t?function(...i){let n=e.renderer.apply(this,i);return!1===n&&(n=t.apply(this,i)),n}:e.renderer}if(e.tokenizer){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");i[e.level]?i[e.level].unshift(e.tokenizer):i[e.level]=[e.tokenizer],e.start&&("block"===e.level?i.startBlock?i.startBlock.push(e.start):i.startBlock=[e.start]:"inline"===e.level&&(i.startInline?i.startInline.push(e.start):i.startInline=[e.start]))}e.childTokens&&(i.childTokens[e.name]=e.childTokens)}))),e.renderer){const i=U.defaults.renderer||new I;for(const t in e.renderer){const n=i[t];i[t]=(...s)=>{let r=e.renderer[t].apply(i,s);return!1===r&&(r=n.apply(i,s)),r}}t.renderer=i}if(e.tokenizer){const i=U.defaults.tokenizer||new F;for(const t in e.tokenizer){const n=i[t];i[t]=(...s)=>{let r=e.tokenizer[t].apply(i,s);return!1===r&&(r=n.apply(i,s)),r}}t.tokenizer=i}if(e.walkTokens){const i=U.defaults.walkTokens;t.walkTokens=function(t){e.walkTokens.call(this,t),i&&i.call(this,t)}}n&&(t.extensions=i),U.setOptions(t)}))},U.walkTokens=function(e,t){for(const i of e)switch(t.call(U,i),i.type){case"table":for(const e of i.header)U.walkTokens(e.tokens,t);for(const e of i.rows)for(const i of e)U.walkTokens(i.tokens,t);break;case"list":U.walkTokens(i.items,t);break;default:U.defaults.extensions&&U.defaults.extensions.childTokens&&U.defaults.extensions.childTokens[i.type]?U.defaults.extensions.childTokens[i.type].forEach((function(e){U.walkTokens(i[e],t)})):i.tokens&&U.walkTokens(i.tokens,t)}},U.parseInline=function(e,t){if(null==e)throw new Error("marked.parseInline(): input parameter is undefined or null");if("string"!=typeof e)throw new Error("marked.parseInline(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected");L(t=C({},U.defaults,t||{}));try{const i=P.lexInline(e,t);return t.walkTokens&&U.walkTokens(i,t.walkTokens),z.parseInline(i,t)}catch(i){if(i.message+="\nPlease report this to https://github.com/markedjs/marked.",t.silent)return"

    An error occurred:

    "+u(i.message+"",!0)+"
    ";throw i}},U.Parser=z,U.parser=z.parse,U.Renderer=I,U.TextRenderer=D,U.Lexer=P,U.lexer=P.lex,U.Tokenizer=F,U.Slugger=q,U.parse=U,U.options,U.setOptions,U.use,U.walkTokens,U.parseInline,z.parse,P.lex;var N="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},W={"&":"&","<":"<",">":">",'"':""","'":"'"},H={"&":"&","<":"<",">":">",""":'"',"'":"'"},j=/(&|<|>|"|')/g,V=/[&<>"']/g;function Q(e){return W[e]}function G(e){return H[e]}function Z(e){return null==e?"":String(e).replace(V,Q)}function K(e){return null==e?"":String(e).replace(j,G)}Z.options=K.options={};var Y={encode:Z,escape:Z,decode:K,unescape:K,version:"1.0.0-browser"};var X=function e(t){for(var i,n,s=Array.prototype.slice.call(arguments,1);s.length;)for(n in i=s.shift())i.hasOwnProperty(n)&&("[object Object]"===Object.prototype.toString.call(t[n])?t[n]=e(t[n],i[n]):t[n]=i[n]);return t},J=function(e){return"string"==typeof e?e.toLowerCase():e};function ee(e,t){return e[t]=!0,e}var te=function(e){return e.reduce(ee,{})},ie={uris:te(["background","base","cite","href","longdesc","src","usemap"])},ne={voids:te(["area","br","col","hr","img","wbr","input","base","basefont","link","meta"])},se=Y,re=J,ae=ne,oe=/^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)\s*>/,le=/^<\s*\/\s*([\w:-]+)[^>]*>/,ce=/([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g,he=/^=0&&(t.comment&&t.comment(e.substring(4,n)),e=e.substring(n+3),i=!1):de.test(e)?a(le,l):he.test(e)&&a(oe,o);var n;!function(){if(!i)return;var n,s=e.indexOf("<");s>=0?(n=e.substring(0,s),e=e.substring(s)):(n=e,e="");t.chars&&t.chars(n)}()}();var n=e===s;s=e,n&&(e="")}function a(t,n){var s=e.match(t);s&&(e=e.substring(s[0].length),s[0].replace(t,n),i=!1)}function o(e,i,s,r){var a={},o=re(i),l=ae.voids[o]||!!r;s.replace(ce,(function(e,t,i,n,s){a[t]=void 0===i&&void 0===n&&void 0===s?void 0:se.decode(i||n||s||"")})),l||n.push(o),t.start&&t.start(o,a,l)}function l(e,i){var s,r=0,a=re(i);if(a)for(r=n.length-1;r>=0&&n[r]!==a;r--);if(r>=0){for(s=n.length-1;s>=r;s--)t.end&&t.end(n[s]);n.length=r}}l()},ye=function(e,t){var i,n=t||{};return o(),{start:function(e,t,a){var o=pe(e);if(i.ignoring)return void r(o);if(-1===(n.allowedTags||[]).indexOf(o))return void r(o);if(n.filter&&!n.filter({tag:o,attrs:t}))return void r(o);s("<"),s(o),Object.keys(t).forEach((function(e){var i=t[e],r=(n.allowedClasses||{})[o]||[],a=(n.allowedAttributes||{})[o]||[],l=pe(e);("class"===l&&-1===a.indexOf(l)?(i=i.split(" ").filter((function(e){return r&&-1!==r.indexOf(e)})).join(" ").trim()).length:-1!==a.indexOf(l)&&(!0!==me.uris[l]||function(e){var t=e[0];if("#"===t||"/"===t)return!0;var i=e.indexOf(":");if(-1===i)return!0;var s=e.indexOf("?");if(-1!==s&&i>s)return!0;var r=e.indexOf("#");return-1!==r&&i>r||n.allowedSchemes.some(a);function a(t){return 0===e.indexOf(t+":")}}(i)))&&(s(" "),s(e),"string"==typeof i&&(s('="'),s(ue.encode(i)),s('"')))})),s(a?"/>":">")},end:function(e){var t=pe(e);-1!==(n.allowedTags||[]).indexOf(t)&&!1===i.ignoring?(s("")):a(t)},chars:function(e){!1===i.ignoring&&s(n.transformText?n.transformText(e):e)}};function s(t){e.push(t)}function r(e){ge.voids[e]||(!1===i.ignoring?i={ignoring:e,depth:1}:i.ignoring===e&&i.depth++)}function a(e){i.ignoring===e&&--i.depth<=0&&o()}function o(){i={ignoring:!1,depth:0}}},$e={allowedAttributes:{a:["href","name","target","title","aria-label"],iframe:["allowfullscreen","frameborder","src"],img:["src","alt","title","aria-label"]},allowedClasses:{},allowedSchemes:["http","https","mailto"],allowedTags:["a","abbr","article","b","blockquote","br","caption","code","del","details","div","em","h1","h2","h3","h4","h5","h6","hr","i","img","ins","kbd","li","main","mark","ol","p","pre","section","span","strike","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],filter:null};function be(e,t,i){var n=[],s=!0===i?t:fe({},$e,t),r=ye(n,s);return ke(e,r),n.join("")}be.defaults=$e;var _e=be,xe={exports:{}};xe.exports=function(){function e(e,t){return e(t={exports:{}},t.exports),t.exports}var t=e((function(e){var t=e.exports=function(){return new RegExp("(?:"+t.line().source+")|(?:"+t.block().source+")","gm")};t.line=function(){return/(?:^|\s)\/\/(.+?)$/gm},t.block=function(){return/\/\*([\S\s]*?)\*\//gm}})),i=["23AC69","91C132","F19726","E8552D","1AAB8E","E1147F","2980C1","1BA1E6","9FA0A0","F19726","E30B20","E30B20","A3338B"];function n(e){return''+e+""}return function(e,s){void 0===s&&(s={});var r=s.colors;void 0===r&&(r=i);var a=0,o={},l=new RegExp("("+/[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af\u0400-\u04FF]+|\w+/.source+"|"+/'+t+"";return a=++a%r.length,l}))}}();const ve=xe.exports;function we(e=""){const t=document.createElement("div");return t.innerHTML=e.trim(),t.firstElementChild||t}function Ce(e){return parseFloat(getComputedStyle(e,null).height.replace("px",""))}function Se(e){const t=RegExp(`[?&]${e}=([^&]*)`).exec(window.location.search);return t&&decodeURIComponent(t[1].replace(/\+/g," "))}function Te(e){const t=e.getBoundingClientRect();return{top:t.top+window.scrollY,left:t.left+window.scrollX}}function Le(e,t){let i=e.toString();for(;i.length{n--,0===n&&t()})),0===n&&t()}function Fe(e,t){var i;let n=null==(i=e.markedInstance)?void 0:i.parse(t);n||(n=t.replace(/```\s*([^]+?.*?[^]+?[^]+?)```/g,((e,t)=>`
    ${ve(t)}
    `)).replace(/!\[(.*?)\]\((.*?)\)/g,((e,t,i)=>`${t}`)).replace(/\[(.*?)\]\((.*?)\)/g,((e,t,i)=>`
    ${t}`)).replace(/\n/g,"
    "));let s=_e(n,{allowedClasses:{},allowedSchemes:["http","https","mailto","data"],allowedTags:["a","abbr","article","b","blockquote","br","caption","code","del","details","div","em","h1","h2","h3","h4","h5","h6","hr","i","img","ins","kbd","li","main","mark","ol","p","pre","section","span","strike","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],allowedAttributes:{"*":["title","accesskey"],a:["href","name","target","aria-label","rel"],img:["src","alt","title","atk-emoticon","aria-label"],code:["class"],span:["class","style"]},filter:e=>([["code",/^hljs\W+language-(.*)$/],["span",/^(hljs-.*)$/]].forEach((([t,i])=>{e.tag===t&&e.attrs.class&&!i.test(e.attrs.class)&&delete e.attrs.class})),"span"===e.tag&&e.attrs.style&&!/^color:(\W+)?#[0-9a-f]{3,6};?$/i.test(e.attrs.style)&&delete e.attrs.style,!0)});return e.markedReplacers.forEach((e=>{"function"==typeof e&&(s=e(s))})),s}function Oe(){return __async(this,null,(function*(){const e=navigator.userAgent;if(!navigator.userAgentData||!navigator.userAgentData.getHighEntropyValues)return e;const t=navigator.userAgentData;let i=null;try{i=yield t.getHighEntropyValues(["platformVersion"])}catch(s){return console.error(s),e}const n=Number(i.platformVersion.split(".")[0]);return"Windows"===t.platform&&n>=13?e.replace(/Windows NT 10.0/,"Windows NT 11.0"):"macOS"===t.platform&&n>=11?e.replace(/(Mac OS X \d+_\d+_\d+|Mac OS X)/,`Mac OS X ${i.platformVersion.replace(/\./g,"_")}`):e}))}function Me(e){let t;try{t=new URL(e)}catch(i){return!1}return"http:"===t.protocol||"https:"===t.protocol}function Re(e,t){return function(e,t){return`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}(e.conf.server,t)}function Be(e,t){const i=e=>e&&"object"==typeof e;return i(e)&&i(t)?(Object.keys(t).forEach((n=>{const s=e[n],r=t[n];Array.isArray(s)&&Array.isArray(r)?e[n]=s.concat(r):i(s)&&i(r)?e[n]=Be(__spreadValues({},s),r):e[n]=r})),e):t}class Pe{constructor(e){__publicField(this,"$el"),__publicField(this,"ctx"),__publicField(this,"conf"),this.ctx=e,this.conf=e.conf}$t(e,t={}){return this.ctx.$t(e,t)}}function Ie(e,t){let i=e.querySelector(":scope > .atk-loading");i||(i=we(''),(null==t?void 0:t.transparentBg)&&(i.style.background="transparent"),e.appendChild(i)),i.style.display="";const n=i.querySelector(".atk-loading-spinner");n&&(n.style.display="none",window.setTimeout((()=>{n.style.display=""}),500))}function De(e){const t=e.querySelector(":scope > .atk-loading");t&&(t.style.display="none")}function qe(e,t=!0){const i=Te(e).top+Ce(e)/2-document.documentElement.clientHeight/2;t?window.scroll({top:i>0?i:0,left:0}):window.scroll(0,i>0?i:0)}function ze(e,t,i){const n=we(`
    `);n.querySelector(".atk-notify-content").innerHTML=function(e){const t=document.createElement("div");return t.innerText=e,t.innerHTML}(t).replace("\n","
    "),e.appendChild(n);const s=()=>{n.classList.add("atk-fade-out"),setTimeout((()=>{n.remove()}),200)};let r;r=window.setTimeout((()=>{s()}),3e3),n.addEventListener("click",(()=>{s(),window.clearTimeout(r)}))}function Ue(e,t){!function(e,t,i="in"){e.classList.add(`atk-fade-${i}`);const n=()=>{e.classList.remove(`atk-fade-${i}`),e.removeEventListener("animationend",n),t&&t()};e.addEventListener("animationend",n)}(e,t,"in")}function Ne(e,t,i='Artalk Error'){let n=e.querySelector(".atk-error-layer");if(null===t)return void(null!==n&&n.remove());n||(n=we(`
    ${i}
    `),e.appendChild(n));const s=n.querySelector(".atk-error-text");s.innerHTML="",null!==t&&(t instanceof HTMLElement?s.appendChild(t):s.innerText=t)}const We=class extends Pe{constructor(e,t,i){super(e),__publicField(this,"name"),__publicField(this,"$wrap"),__publicField(this,"$mask"),__publicField(this,"maskClickHideEnable",!0),__publicField(this,"afterHide"),this.name=t;const{$wrap:n,$mask:s}=je(e);this.$wrap=n,this.$mask=s,this.$el=this.$wrap.querySelector(`[data-layer-name="${t}"].atk-layer-item`),null===this.$el&&(i?this.$el=i:(this.$el=we(),this.$el.classList.add("atk-layer-item"))),this.$el.setAttribute("data-layer-name",t),this.$el.style.display="none",this.$wrap.append(this.$el)}getName(){return this.name}getWrapEl(){return this.$wrap}getEl(){return this.$el}show(){this.fireAllActionTimer(),this.$wrap.style.display="block",this.$mask.style.display="block",this.$mask.classList.add("atk-fade-in"),this.$el.style.display="",this.$mask.onclick=()=>{this.maskClickHideEnable&&this.hide()},this.pageBodyScrollBarHide()}hide(){this.afterHide&&this.afterHide(),this.$wrap.classList.add("atk-fade-out"),this.$el.style.display="none",this.pageBodyScrollBarShow(),this.newActionTimer((()=>{this.$wrap.style.display="none",this.checkCleanLayer()}),450),this.newActionTimer((()=>{this.$wrap.style.display="none",this.$wrap.classList.remove("atk-fade-out")}),200)}setMaskClickHide(e){this.maskClickHideEnable=e}pageBodyScrollBarHide(){document.body.style.overflow="hidden";const e=parseInt(window.getComputedStyle(document.body,null).getPropertyValue("padding-right"),10);document.body.style.paddingRight=`${function(){const e=document.createElement("p");e.style.width="100%",e.style.height="200px";const t=document.createElement("div");t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.visibility="hidden",t.style.width="200px",t.style.height="150px",t.style.overflow="hidden",t.appendChild(e),document.body.appendChild(t);const i=e.offsetWidth;t.style.overflow="scroll";let n=e.offsetWidth;return i===n&&(n=t.clientWidth),document.body.removeChild(t),i-n}()+e||0}px`}pageBodyScrollBarShow(){document.body.style.overflow=We.BodyOrgOverflow,document.body.style.paddingRight=We.BodyOrgPaddingRight}newActionTimer(e,t){const i=()=>{e(),We.actionTimers=We.actionTimers.filter((e=>e.act!==i))},n=window.setTimeout((()=>i()),t);We.actionTimers.push({act:i,tid:n})}fireAllActionTimer(){We.actionTimers.forEach((e=>{clearTimeout(e.tid),e.act()}))}disposeNow(){this.$el.remove(),this.pageBodyScrollBarShow(),this.checkCleanLayer()}dispose(){this.hide(),this.$el.remove(),this.checkCleanLayer()}checkCleanLayer(){0===this.getWrapEl().querySelectorAll(".atk-layer-item").length&&(this.$wrap.style.display="none")}};let He=We;function je(e){let t=document.querySelector(`.atk-layer-wrap#ctx-${e.cid}`);t||(t=we(``),document.body.appendChild(t));const i=t.querySelector(".atk-layer-mask");return{$wrap:t,$mask:i}}function Ve(e,t,i,n){return __async(this,null,(function*(){var s,r;if(e.user.data.token){const t=new Headers(i.headers);t.set("Authorization",`Bearer ${e.user.data.token}`),i.headers=t}const a=yield function(e,t,i,n){var s;const r=new AbortController;null==(s=n.signal)||s.addEventListener("abort",(()=>r.abort()));let a=fetch(t,__spreadProps(__spreadValues({},n),{signal:r.signal}));if(i>0){const e=setTimeout((()=>r.abort()),i);a.finally((()=>{clearTimeout(e)}))}return a=a.catch((t=>{throw"AbortError"===(t||{}).name?new Error(e.$t("reqAborted")):t})),a}(e,t,n||e.conf.reqTimeout||15e3,i),o=a.status,l=[401,400].includes(o);if(!a.ok&&!l)throw new Error(`${e.$t("reqGot")} ${o}`);let c=yield a.json();const h=(n,s)=>{Ve(e,t,i).then((e=>{n(e)})).catch((e=>{s(e)}))};if((null==(s=c.data)?void 0:s.need_captcha)?c=yield new Promise(((t,i)=>{e.checkCaptcha({imgData:c.data.img_data,iframe:c.data.iframe,onSuccess:()=>{h(t,i)},onCancel:()=>{i(c)}})})):((null==(r=c.data)?void 0:r.need_login)||l)&&(c=yield new Promise(((t,i)=>{e.checkAdmin({onSuccess:()=>{h(t,i)},onCancel:()=>{i(c)}})}))),!c.success)throw c;return c}))}function Qe(e){const t=new FormData;return Object.keys(e).forEach((i=>t.append(i,String(e[i])))),t}__publicField(He,"BodyOrgOverflow"),__publicField(He,"BodyOrgPaddingRight"),__publicField(He,"actionTimers",[]),function(){function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var i=0;i({user:e.data.user,is_login:e.data.is_login,unread:e.data.unread||[],unread_count:e.data.unread_count||0}))),abort:()=>{i.abort()}}}loginStatus(){return __async(this,null,(function*(){return(yield this.POST("/login-status",{name:this.ctx.user.data.nick,email:this.ctx.user.data.email}))||{is_login:!1,is_admin:!1}}))}logout(){return __async(this,null,(function*(){return this.POST("/logout")}))}markRead(e,t=!1){const i={site_name:this.ctx.conf.site||"",notify_key:e};return t&&(delete i.notify_key,i.read_all=!0,i.name=this.ctx.user.data.nick,i.email=this.ctx.user.data.email),this.POST("/mark-read",i)}userList(e,t,i){return __async(this,null,(function*(){const n={offset:e||0,limit:t||15};i&&(n.type=i);return yield this.POST("/admin/user-get",n)}))}userAdd(e,t){return __async(this,null,(function*(){const i={name:e.name||"",email:e.email||"",password:t||"",link:e.link||"",is_admin:e.is_admin||!1,site_names:e.site_names_raw||"",receive_email:e.receive_email||!0,badge_name:e.badge_name||"",badge_color:e.badge_color||""};return(yield this.POST("/admin/user-add",i)).user}))}userEdit(e,t){return __async(this,null,(function*(){const i={id:e.id,name:e.name||"",email:e.email||"",password:t||"",link:e.link||"",is_admin:e.is_admin||!1,site_names:e.site_names_raw||"",receive_email:e.receive_email||!0,badge_name:e.badge_name||"",badge_color:e.badge_color||""};return(yield this.POST("/admin/user-edit",i)).user}))}userDel(e){return this.POST("/admin/user-del",{id:String(e)})}},system:class extends Ge{conf(){return __async(this,null,(function*(){const e=(yield this.POST("/conf")).frontend_conf||{};return e.emoticons&&"string"==typeof e.emoticons&&(e.emoticons=e.emoticons.trim(),e.emoticons.startsWith("[")||e.emoticons.startsWith("{")?e.emoticons=JSON.parse(e.emoticons):"false"===e.emoticons&&(e.emoticons=!1)),e}))}getSettings(){return __async(this,null,(function*(){return yield this.POST("/admin/setting-get")}))}saveSettings(e){return __async(this,null,(function*(){return yield this.POST("/admin/setting-save",{data:e})}))}version(){return __async(this,null,(function*(){const e=yield fetch(`${this.api.baseURL}/version`,{method:"POST"});return yield e.json()}))}},captcha:class extends Ge{captchaGet(){return __async(this,null,(function*(){return(yield this.POST("/captcha/refresh")).img_data||""}))}captchaCheck(e){return __async(this,null,(function*(){return(yield this.POST("/captcha/check",{value:e})).img_data||""}))}captchaStatus(){return __async(this,null,(function*(){return(yield this.POST("/captcha/status"))||{is_pass:!1}}))}},admin:class extends Ge{cacheFlushAll(){return this.POST("/admin/cache-flush",{flush_all:!0})}cacheWarmUp(){return this.POST("/admin/cache-warm",{})}},upload:class extends Ge{imgUpload(e){return __async(this,null,(function*(){const t={name:this.ctx.user.data.nick,email:this.ctx.user.data.email,page_key:this.ctx.conf.pageKey};this.ctx.conf.site&&(t.site_name=this.ctx.conf.site);const i=Qe(t);i.set("file",e);const n={method:"POST",body:i};return(yield this.Fetch("/img-upload",n)).data||{}}))}}};class Ke{constructor(e){__publicField(this,"ctx"),this.ctx=e,Object.entries(Ze).forEach((([e,t])=>{this[e]=new t(this,this.ctx)}))}get baseURL(){return`${this.ctx.conf.server}/api`}}const Ye="2.4.4",Xe=window||{},Je=navigator||{};class et{constructor(e,t){__publicField(this,"ctx"),__publicField(this,"conf"),__publicField(this,"$el"),__publicField(this,"isLoading",!1),__publicField(this,"msgRecTimer"),__publicField(this,"msgRecTimerFunc"),__publicField(this,"isConfirming",!1),__publicField(this,"confirmRecTimer"),this.ctx=e,this.$el=we(''),this.conf="object"!=typeof t?{text:t}:t,this.$el.innerText=this.getText(),this.conf.adminOnly&&this.$el.setAttribute("atk-only-admin-show","")}get isMessaging(){return!!this.msgRecTimer}appendTo(e){return e.append(this.$el),this}getText(){return"string"==typeof this.conf.text?this.conf.text:this.conf.text()}setClick(e){this.$el.onclick=t=>{if(t.stopPropagation(),!this.isLoading){if(this.conf.confirm&&!this.isMessaging){const e=()=>{this.isConfirming=!1,this.$el.classList.remove("atk-btn-confirm"),this.$el.innerText=this.getText()};if(!this.isConfirming)return this.isConfirming=!0,this.$el.classList.add("atk-btn-confirm"),this.$el.innerText=this.conf.confirmText||this.ctx.$t("actionConfirm"),void(this.confirmRecTimer=window.setTimeout((()=>e()),5e3));this.confirmRecTimer&&window.clearTimeout(this.confirmRecTimer),e()}if(this.msgRecTimer)return this.fireMsgRecTimer(),void this.clearMsgRecTimer();e()}}}updateText(e){e&&(this.conf.text=e),this.setLoading(!1),this.$el.innerText=this.getText()}setLoading(e,t){this.isLoading!==e&&(this.isLoading=e,e?(this.$el.classList.add("atk-btn-loading"),this.$el.innerText=t||`${this.ctx.$t("loading")}...`):(this.$el.classList.remove("atk-btn-loading"),this.$el.innerText=this.getText()))}setError(e){this.setMsg(e,"atk-btn-error")}setWarn(e){this.setMsg(e,"atk-btn-warn")}setSuccess(e){this.setMsg(e,"atk-btn-success")}setMsg(e,t,i,n){this.setLoading(!1),t&&this.$el.classList.add(t),this.$el.innerText=e,this.setMsgRecTimer((()=>{this.$el.innerText=this.getText(),t&&this.$el.classList.remove(t),n&&n()}),i||2500)}setMsgRecTimer(e,t){this.fireMsgRecTimer(),this.clearMsgRecTimer(),this.msgRecTimerFunc=e,this.msgRecTimer=window.setTimeout((()=>{e(),this.clearMsgRecTimer()}),t)}fireMsgRecTimer(){this.msgRecTimerFunc&&this.msgRecTimerFunc()}clearMsgRecTimer(){this.msgRecTimer&&window.clearTimeout(this.msgRecTimer),this.msgRecTimer=void 0,this.msgRecTimerFunc=void 0}}class tt{constructor(e){__publicField(this,"comment"),__publicField(this,"$el"),__publicField(this,"$main"),__publicField(this,"$header"),__publicField(this,"$headerNick"),__publicField(this,"$headerBadgeWrap"),__publicField(this,"$body"),__publicField(this,"$content"),__publicField(this,"$childrenWrap"),__publicField(this,"$actions"),__publicField(this,"voteBtnUp"),__publicField(this,"voteBtnDown"),__publicField(this,"$replyTo"),__publicField(this,"$replyAt"),this.comment=e}get ctx(){return this.comment.ctx}get data(){return this.comment.getData()}get cConf(){return this.comment.getConf()}render(){return this.$el=we('
    \n
    \n
    \n
    \n
    \n \n \n \n
    \n
    \n
    \n
    \n \n
    \n
    \n
    \n'),this.$main=this.$el.querySelector(".atk-main"),this.$header=this.$el.querySelector(".atk-header"),this.$body=this.$el.querySelector(".atk-body"),this.$content=this.$body.querySelector(".atk-content"),this.$actions=this.$el.querySelector(".atk-actions"),this.$el.setAttribute("data-comment-id",`${this.data.id}`),this.renderAvatar(),this.renderHeader(),this.renderContent(),this.renderReplyAt(),this.renderReplyTo(),this.renderPending(),this.renderActions(),this.recoveryChildrenWrap(),this.$el}renderAvatar(){const e=this.$el.querySelector(".atk-avatar"),t=we(""),i=this.ctx.conf.avatarURLBuilder;if(t.src=i?i(this.data):this.comment.getGravatarURL(),this.data.link){const i=we('');i.href=Me(this.data.link)?this.data.link:`https://${this.data.link}`,i.append(t),e.append(i)}else e.append(t)}renderHeader(){this.renderHeader_Nick(),this.renderHeader_VerifyBadge(),this.renderHeader_Date(),this.renderHeader_UABadge()}renderHeader_Nick(){if(this.$headerNick=this.$el.querySelector(".atk-nick"),this.data.link){const e=we('');e.innerText=this.data.nick,e.href=Me(this.data.link)?this.data.link:`https://${this.data.link}`,this.$headerNick.append(e)}else this.$headerNick.innerText=this.data.nick}renderHeader_VerifyBadge(){this.$headerBadgeWrap=this.$el.querySelector(".atk-badge-wrap"),this.$headerBadgeWrap.innerHTML="";const e=this.data.badge_name,t=this.data.badge_color;if(e){const i=we('');i.innerText=e.replace("管理员",this.ctx.$t("admin")),i.style.backgroundColor=t||"",this.$headerBadgeWrap.append(i)}if(this.data.is_pinned){const e=we(`${this.ctx.$t("pin")}`);this.$headerBadgeWrap.append(e)}}renderHeader_Date(){const e=this.$el.querySelector(".atk-date");e.innerText=this.comment.getDateFormatted(),e.setAttribute("data-atk-comment-date",String(+new Date(this.data.date)))}renderHeader_UABadge(){if(this.ctx.conf.uaBadge){let e=this.$header.querySelector("atk-ua-wrap");e||(e=we(''),this.$header.append(e)),e.innerHTML="";const t=we(''),i=we(''),n=this.comment.getUserUA();t.innerText=n.browser,i.innerText=n.os,e.append(t),e.append(i)}}renderContent(){if(!this.data.is_collapsed)return this.$content.innerHTML=this.comment.getContentMarked(),void this.$content.classList.remove("atk-hide","atk-collapsed");this.$content.classList.add("atk-hide","atk-type-collapsed");const e=we(`\n
    \n ${this.ctx.$t("collapsedMsg")}\n ${this.ctx.$t("expand")}\n
    `);this.$body.insertAdjacentElement("beforeend",e);const t=e.querySelector(".atk-show-btn");t.addEventListener("click",(e=>{e.stopPropagation(),this.$content.classList.contains("atk-hide")?(this.$content.innerHTML=this.comment.getContentMarked(),this.$content.classList.remove("atk-hide"),Ue(this.$content),t.innerHTML=this.ctx.$t("collapse")):(this.$content.innerHTML="",this.$content.classList.add("atk-hide"),t.innerHTML=this.ctx.$t("expand"))}))}renderReplyAt(){this.cConf.isFlatMode||0===this.data.rid||this.cConf.replyTo&&(this.$replyAt=we(''),this.$replyAt.querySelector(".atk-nick").innerText=`${this.cConf.replyTo.nick}`,this.$replyAt.onclick=()=>{this.comment.getActions().goToReplyComment()},this.$headerBadgeWrap.insertAdjacentElement("afterend",this.$replyAt))}renderReplyTo(){if(!this.cConf.isFlatMode)return;if(!this.cConf.replyTo)return;this.$replyTo=we(`\n
    \n
    ${this.ctx.$t("reply")} :
    \n
    \n
    `);const e=this.$replyTo.querySelector(".atk-nick");e.innerText=`@${this.cConf.replyTo.nick}`,e.onclick=()=>{this.comment.getActions().goToReplyComment()};let t=Fe(this.ctx,this.cConf.replyTo.content);this.cConf.replyTo.is_collapsed&&(t=`[${this.ctx.$t("collapsed")}]`),this.$replyTo.querySelector(".atk-content").innerHTML=t,this.$body.prepend(this.$replyTo)}renderPending(){if(!this.data.is_pending)return;const e=we(`
    ${this.ctx.$t("pendingMsg")}
    `);this.$body.prepend(e)}renderActions(){this.renderActions_Vote(),this.renderActions_Reply(),this.renderActions_Collapse(),this.renderActions_Moderator(),this.renderActions_Pin(),this.renderActions_Edit(),this.renderActions_Del()}renderActions_Vote(){this.ctx.conf.vote&&(this.voteBtnUp=new et(this.ctx,(()=>`${this.ctx.$t("voteUp")} (${this.data.vote_up||0})`)).appendTo(this.$actions),this.voteBtnUp.setClick((()=>{this.comment.getActions().vote("up")})),this.ctx.conf.voteDown&&(this.voteBtnDown=new et(this.ctx,(()=>`${this.ctx.$t("voteDown")} (${this.data.vote_down||0})`)).appendTo(this.$actions),this.voteBtnDown.setClick((()=>{this.comment.getActions().vote("down")}))))}renderActions_Reply(){if(!this.data.is_allow_reply)return;const e=we(`${this.ctx.$t("reply")}`);this.$actions.append(e),e.addEventListener("click",(e=>{e.stopPropagation(),this.cConf.onReplyBtnClick?this.cConf.onReplyBtnClick():this.ctx.replyComment(this.data,this.$el)}))}renderActions_Collapse(){const e=new et(this.ctx,{text:()=>this.data.is_collapsed?this.ctx.$t("expand"):this.ctx.$t("collapse"),adminOnly:!0});e.appendTo(this.$actions),e.setClick((()=>{this.comment.getActions().adminEdit("collapsed",e)}))}renderActions_Moderator(){const e=new et(this.ctx,{text:()=>this.data.is_pending?this.ctx.$t("pending"):this.ctx.$t("approved"),adminOnly:!0});e.appendTo(this.$actions),e.setClick((()=>{this.comment.getActions().adminEdit("pending",e)}))}renderActions_Pin(){const e=new et(this.ctx,{text:()=>this.data.is_pinned?this.ctx.$t("unpin"):this.ctx.$t("pin"),adminOnly:!0});e.appendTo(this.$actions),e.setClick((()=>{this.comment.getActions().adminEdit("pinned",e)}))}renderActions_Edit(){const e=new et(this.ctx,{text:this.ctx.$t("edit"),adminOnly:!0});e.appendTo(this.$actions),e.setClick((()=>{this.ctx.editComment(this.data,this.$el)}))}renderActions_Del(){const e=new et(this.ctx,{text:this.ctx.$t("delete"),confirm:!0,confirmText:this.ctx.$t("deleteConfirm"),adminOnly:!0});e.appendTo(this.$actions),e.setClick((()=>{this.comment.getActions().adminDelete(e)}))}checkHeightLimit(){this.checkHeightLimitArea("content"),this.checkHeightLimitArea("children")}checkHeightLimitArea(e){const t=this.ctx.conf.heightLimit.children,i=this.ctx.conf.heightLimit.content;if("children"===e&&!t)return;if("content"===e&&!i)return;let n;"children"===e&&(n=t),"content"===e&&(n=i);const s=e=>{e&&Ce(e)>n&&this.heightLimitAdd(e,n)};"children"===e?s(this.$childrenWrap):"content"===e&&(s(this.$content),s(this.$replyTo),Ae(this.$content,(()=>{s(this.$content)})),this.$replyTo&&Ae(this.$replyTo,(()=>{s(this.$replyTo)})))}heightLimitRemove(e){e&&e.classList.contains("atk-height-limit")&&(e.classList.remove("atk-height-limit"),Array.from(e.children).forEach((e=>{e.classList.contains("atk-height-limit-btn")&&e.remove()})),e.style.height="",e.style.overflow="")}heightLimitRemoveForChildren(){this.$childrenWrap&&this.heightLimitRemove(this.$childrenWrap)}heightLimitAdd(e,t){if(!e)return;if(e.classList.contains("atk-height-limit"))return;e.classList.add("atk-height-limit"),e.style.height=`${t}px`,e.style.overflow="hidden";const i=we(`
    ${this.ctx.$t("readMore")}`);i.onclick=t=>{t.stopPropagation(),this.heightLimitRemove(e);const i=this.comment.getChildren();1===i.length&&i[0].getRender().heightLimitRemove(i[0].getRender().$content)},e.append(i)}playFadeAnim(){Ue(this.comment.getRender().$el)}playFadeAnimForBody(){Ue(this.comment.getRender().$body)}getChildrenWrap(){return this.$childrenWrap}renderChildrenWrap(){return this.$childrenWrap||(this.$childrenWrap=we('
    '),this.$main.append(this.$childrenWrap)),this.$childrenWrap}recoveryChildrenWrap(){this.$childrenWrap&&this.$main.append(this.$childrenWrap)}setUnread(e){e?this.$el.classList.add("atk-unread"):this.$el.classList.remove("atk-unread")}setOpenable(e){e?this.$el.classList.add("atk-openable"):this.$el.classList.remove("atk-openable")}setOpenURL(e){this.setOpenable(!0),this.$el.onclick=t=>{t.preventDefault(),window.open(e),this.cConf.openEvt&&this.cConf.openEvt()}}setOpenAction(e){this.setOpenable(!0),this.$el.onclick=t=>{t.preventDefault(),e()}}}class it{constructor(e){__publicField(this,"comment"),this.comment=e}get ctx(){return this.comment.ctx}get data(){return this.comment.getData()}get cConf(){return this.comment.getConf()}vote(e){const t="up"===e?this.comment.getRender().voteBtnUp:this.comment.getRender().voteBtnDown;this.ctx.getApi().comment.vote(this.data.id,`comment_${e}`).then((e=>{var t,i;this.data.vote_up=e.up,this.data.vote_down=e.down,null==(t=this.comment.getRender().voteBtnUp)||t.updateText(),null==(i=this.comment.getRender().voteBtnDown)||i.updateText()})).catch((e=>{null==t||t.setError(this.ctx.$t("voteFail")),console.log(e)}))}adminEdit(e,t){if(t.isLoading)return;t.setLoading(!0,`${this.ctx.$t("editing")}...`);const i=__spreadValues({},this.data);"collapsed"===e?i.is_collapsed=!i.is_collapsed:"pending"===e?i.is_pending=!i.is_pending:"pinned"===e&&(i.is_pinned=!i.is_pinned),this.ctx.getApi().comment.commentEdit(i).then((e=>{t.setLoading(!1),this.comment.setData(e),this.ctx.listRefreshUI()})).catch((e=>{console.error(e),t.setError(this.ctx.$t("editFail"))}))}adminDelete(e){e.isLoading||(e.setLoading(!0,`${this.ctx.$t("deleting")}...`),this.ctx.getApi().comment.commentDel(this.data.id,this.data.site_name).then((()=>{e.setLoading(!1),this.cConf.onDelete&&this.cConf.onDelete(this.comment)})).catch((t=>{console.error(t),e.setError(this.ctx.$t("deleteFail"))})))}goToReplyComment(){const e=window.location.hash,t=`#atk-comment-${this.data.rid}`;window.location.hash=t,t===e&&window.dispatchEvent(new Event("hashchange"))}}class nt extends Pe{constructor(e,t,i){super(e),__publicField(this,"renderInstance"),__publicField(this,"actionInstance"),__publicField(this,"data"),__publicField(this,"cConf"),__publicField(this,"parent"),__publicField(this,"children",[]),__publicField(this,"nestCurt"),__publicField(this,"nestMax"),this.nestMax=e.conf.nestMax||3,this.cConf=i,this.data=__spreadValues({},t),this.data.date=this.data.date.replace(/-/g,"/"),this.parent=null,this.nestCurt=1,this.actionInstance=new it(this),this.renderInstance=new tt(this)}render(){const e=this.renderInstance.render();this.$el&&this.$el.replaceWith(e),this.$el=e,this.cConf.afterRender&&this.cConf.afterRender()}getActions(){return this.actionInstance}getRender(){return this.renderInstance}getData(){return this.data}setData(e){this.data=e,this.render(),this.getRender().playFadeAnimForBody()}getParent(){return this.parent}getChildren(){return this.children}getNestCurt(){return this.nestCurt}getIsRoot(){return 0===this.data.rid}getID(){return this.data.id}putChild(e,t="append"){e.parent=this,e.nestCurt=this.nestCurt+1,this.children.push(e);const i=this.getChildrenEl();"append"===t?i.append(e.getEl()):"prepend"===t&&i.prepend(e.getEl()),e.getRender().playFadeAnim(),e.getRender().checkHeightLimitArea("content")}getChildrenEl(){let e=this.getRender().getChildrenWrap();return e||(e=this.nestCurt{i.parent&&(e.push(i.parent),t(i.parent))};return t(this),e}getEl(){return this.$el}getGravatarURL(){return e=this.ctx,t=this.data.email_encrypted,`${e.conf.gravatar.mirror.replace(/\/$/,"")}/${t}?d=${encodeURIComponent(e.conf.gravatar.default)}&s=80`;var e,t}getContentMarked(){return Fe(this.ctx,this.data.content)}getDateFormatted(){return Ee(new Date(this.data.date),this.ctx)}getUserUA(){const e=function(e){const t=String(e||Je.userAgent),i={os:"",osVersion:"",engine:"",browser:"",device:"",language:"",version:""},n={Trident:t.includes("Trident")||t.includes("NET CLR"),Presto:t.includes("Presto"),WebKit:t.includes("AppleWebKit"),Gecko:t.includes("Gecko/")},s={Safari:t.includes("Safari"),Chrome:t.includes("Chrome")||t.includes("CriOS"),IE:t.includes("MSIE")||t.includes("Trident"),Edge:t.includes("Edge")||t.includes("Edg"),Firefox:t.includes("Firefox")||t.includes("FxiOS"),"Firefox Focus":t.includes("Focus"),Chromium:t.includes("Chromium"),Opera:t.includes("Opera")||t.includes("OPR"),Vivaldi:t.includes("Vivaldi"),Yandex:t.includes("YaBrowser"),Kindle:t.includes("Kindle")||t.includes("Silk/"),360:t.includes("360EE")||t.includes("360SE"),UC:t.includes("UC")||t.includes(" UBrowser"),QQBrowser:t.includes("QQBrowser"),QQ:t.includes("QQ/"),Baidu:t.includes("Baidu")||t.includes("BIDUBrowser"),Maxthon:t.includes("Maxthon"),Sogou:t.includes("MetaSr")||t.includes("Sogou"),LBBROWSER:t.includes("LBBROWSER"),"2345Explorer":t.includes("2345Explorer"),TheWorld:t.includes("TheWorld"),MIUI:t.includes("MiuiBrowser"),Quark:t.includes("Quark"),Qiyu:t.includes("Qiyu"),Wechat:t.includes("MicroMessenger"),Taobao:t.includes("AliApp(TB"),Alipay:t.includes("AliApp(AP"),Weibo:t.includes("Weibo"),Douban:t.includes("com.douban.frodo"),Suning:t.includes("SNEBUY-APP"),iQiYi:t.includes("IqiyiApp")},r={Windows:t.includes("Windows"),Linux:t.includes("Linux")||t.includes("X11"),macOS:t.includes("Macintosh"),Android:t.includes("Android")||t.includes("Adr"),Ubuntu:t.includes("Ubuntu"),FreeBSD:t.includes("FreeBSD"),Debian:t.includes("Debian"),"Windows Phone":t.includes("IEMobile")||t.includes("Windows Phone"),BlackBerry:t.includes("BlackBerry")||t.includes("RIM"),MeeGo:t.includes("MeeGo"),Symbian:t.includes("Symbian"),iOS:t.includes("like Mac OS X"),"Chrome OS":t.includes("CrOS"),WebOS:t.includes("hpwOS")},a={Mobile:t.includes("Mobi")||t.includes("iPh")||t.includes("480"),Tablet:t.includes("Tablet")||t.includes("Pad")||t.includes("Nexus 7")};a.Mobile?a.Mobile=!t.includes("iPad"):s.Chrome&&t.includes("Edg")?(s.Chrome=!1,s.Edge=!0):Xe.showModalDialog&&Xe.chrome&&(s.Chrome=!1,s[360]=!0),i.device="PC",i.language=(()=>{const e=(Je.browserLanguage||Je.language).split("-");return e[1]&&(e[1]=e[1].toUpperCase()),e.join("_")})();const o={engine:n,browser:s,os:r,device:a};Object.entries(o).forEach((([e,t])=>{Object.entries(t).forEach((([t,n])=>{!0===n&&(i[e]=t)}))}));const l={Windows:()=>{const e=t.replace(/^.*Windows NT ([\d.]+);.*$/,"$1");return{6.4:"10",6.3:"8.1",6.2:"8",6.1:"7","6.0":"Vista",5.2:"XP",5.1:"XP","5.0":"2000","10.0":"10","11.0":"11"}[e]||e},Android:()=>t.replace(/^.*Android ([\d.]+);.*$/,"$1"),iOS:()=>t.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,"."),Debian:()=>t.replace(/^.*Debian\/([\d.]+).*$/,"$1"),"Windows Phone":()=>t.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2"),macOS:()=>t.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,"."),WebOS:()=>t.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")};i.osVersion="",l[i.os]&&(i.osVersion=l[i.os](),i.osVersion===t&&(i.osVersion=""));const c={Safari:()=>t.replace(/^.*Version\/([\d.]+).*$/,"$1"),Chrome:()=>t.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1"),IE:()=>t.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1"),Edge:()=>t.replace(/^.*(Edge|Edg|Edg[A-Z]{1})\/([\d.]+).*$/,"$2"),Firefox:()=>t.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1"),"Firefox Focus":()=>t.replace(/^.*Focus\/([\d.]+).*$/,"$1"),Chromium:()=>t.replace(/^.*Chromium\/([\d.]+).*$/,"$1"),Opera:()=>t.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1"),Vivaldi:()=>t.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1"),Yandex:()=>t.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1"),Kindle:()=>t.replace(/^.*Version\/([\d.]+).*$/,"$1"),Maxthon:()=>t.replace(/^.*Maxthon\/([\d.]+).*$/,"$1"),QQBrowser:()=>t.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1"),QQ:()=>t.replace(/^.*QQ\/([\d.]+).*$/,"$1"),Baidu:()=>t.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1"),UC:()=>t.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1"),Sogou:()=>t.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1"),"2345Explorer":()=>t.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1"),TheWorld:()=>t.replace(/^.*TheWorld ([\d.]+).*$/,"$1"),MIUI:()=>t.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1"),Quark:()=>t.replace(/^.*Quark\/([\d.]+).*$/,"$1"),Qiyu:()=>t.replace(/^.*Qiyu\/([\d.]+).*$/,"$1"),Wechat:()=>t.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1"),Taobao:()=>t.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1"),Alipay:()=>t.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1"),Weibo:()=>t.replace(/^.*weibo__([\d.]+).*$/,"$1"),Douban:()=>t.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1"),Suning:()=>t.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1"),iQiYi:()=>t.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")};return i.version="",c[i.browser]&&(i.version=c[i.browser](),i.version===t&&(i.version="")),i.version.indexOf(".")&&(i.version=i.version.substring(0,i.version.indexOf("."))),"iOS"===i.os&&t.includes("iPad")?i.os="iPadOS":"Edge"!==i.browser||t.includes("Edg")?"MIUI"===i.browser?i.os="Android":"Chrome"===i.browser&&Number(i.version)>27||"Opera"===i.browser&&Number(i.version)>12||"Yandex"===i.browser?i.engine="Blink":void 0===i.browser&&(i.browser="Unknow App"):i.engine="EdgeHTML",i}(this.data.ua);return{browser:`${e.browser} ${e.version}`,os:`${e.os} ${e.osVersion}`}}getConf(){return this.cConf}}class st{constructor(e,t){__publicField(this,"conf"),__publicField(this,"total"),__publicField(this,"$el"),__publicField(this,"$input"),__publicField(this,"inputTimer"),__publicField(this,"$prevBtn"),__publicField(this,"$nextBtn"),__publicField(this,"page",1),this.total=e,this.conf=t,this.$el=we('
    \n
    \n
    Prev
    \n \n
    Next
    \n
    \n
    '),this.$input=this.$el.querySelector(".atk-input"),this.$input.value=`${this.page}`,this.$input.oninput=()=>this.input(),this.$input.onkeydown=e=>this.keydown(e),this.$prevBtn=this.$el.querySelector(".atk-btn-prev"),this.$nextBtn=this.$el.querySelector(".atk-btn-next"),this.$prevBtn.onclick=()=>this.prev(),this.$nextBtn.onclick=()=>this.next(),this.checkDisabled()}get pageSize(){return this.conf.pageSize}get offset(){return this.pageSize*(this.page-1)}get maxPage(){return Math.ceil(this.total/this.pageSize)}update(e,t){this.page=Math.ceil(e/this.pageSize)+1,this.total=t,this.setInput(this.page),this.checkDisabled()}setInput(e){this.$input.value=`${e}`}input(e=!1){window.clearTimeout(this.inputTimer);const t=this.$input.value.trim(),i=()=>{if(""===t)return void this.setInput(this.page);let e=Number(t);Number.isNaN(e)||e<1?this.setInput(this.page):(e>this.maxPage&&(this.setInput(this.maxPage),e=this.maxPage),this.change(e))};e?i():this.inputTimer=window.setTimeout((()=>i()),800)}prev(){const e=this.page-1;e<1||this.change(e)}next(){const e=this.page+1;e>this.maxPage||this.change(e)}change(e){this.page=e,this.conf.onChange(this.offset),this.setInput(e),this.checkDisabled()}checkDisabled(){this.page+1>this.maxPage?this.$nextBtn.classList.add("atk-disabled"):this.$nextBtn.classList.remove("atk-disabled"),this.page-1<1?this.$prevBtn.classList.add("atk-disabled"):this.$prevBtn.classList.remove("atk-disabled")}keydown(e){const t=e.keyCode||e.which;if(38===t){const e=Number(this.$input.value)+1;if(e>this.maxPage)return;this.setInput(e),this.input()}else if(40===t){const e=Number(this.$input.value)-1;if(e<1)return;this.setInput(e),this.input()}else 13===t&&this.input(!0)}setLoading(e){e?Ie(this.$el):De(this.$el)}}class rt{constructor(e){__publicField(this,"conf"),__publicField(this,"$el"),__publicField(this,"$loading"),__publicField(this,"$text"),__publicField(this,"offset",0),__publicField(this,"total",0),__publicField(this,"origText","Load More"),this.conf=e,this.origText=this.conf.text||this.origText,this.$el=we(``),this.$loading=this.$el.querySelector(".atk-loading-icon"),this.$text=this.$el.querySelector(".atk-text"),this.$el.onclick=()=>{this.click()}}get hasMore(){return this.total>this.offset+this.conf.pageSize}click(){this.hasMore&&this.conf.onClick(this.offset+this.conf.pageSize),this.checkDisabled()}show(){this.$el.style.display=""}hide(){this.$el.style.display="none"}setLoading(e){this.$loading.style.display=e?"":"none",this.$text.style.display=e?"none":""}showErr(e){this.setLoading(!1),this.$text.innerText=e,this.$el.classList.add("atk-err"),window.setTimeout((()=>{this.$text.innerText=this.origText,this.$el.classList.remove("atk-err")}),2e3)}update(e,t){this.offset=e,this.total=t,this.checkDisabled()}checkDisabled(){this.hasMore?this.show():this.hide()}}class at extends Pe{constructor(e){super(e),__publicField(this,"$commentsWrap"),__publicField(this,"data"),__publicField(this,"isLoading",!1),__publicField(this,"noCommentText"),__publicField(this,"_nestSortBy"),__publicField(this,"_flatMode"),__publicField(this,"_pageMode"),__publicField(this,"_pageSize"),__publicField(this,"scrollListenerAt"),__publicField(this,"repositionAt"),__publicField(this,"pagination"),__publicField(this,"readMoreBtn"),__publicField(this,"autoLoadScrollEvent"),__publicField(this,"renderComment"),__publicField(this,"paramsEditor"),__publicField(this,"onAfterLoad"),__publicField(this,"unread",[]),__publicField(this,"unreadHighlight"),__publicField(this,"confLoaded",!1),this.$el=we('
    \n
    \n
    '),this.$commentsWrap=this.$el.querySelector(".atk-list-comments-wrap"),window.setInterval((()=>{this.$el.querySelectorAll("[data-atk-comment-date]").forEach((e=>{const t=e.getAttribute("data-atk-comment-date");e.innerText=Ee(new Date(Number(t)),this.ctx)}))}),3e4),this.ctx.on("conf-loaded",(()=>{}))}get nestSortBy(){return void 0!==this._nestSortBy?this._nestSortBy:this.ctx.conf.nestSort||"DATE_ASC"}set nestSortBy(e){this._nestSortBy=e}get flatMode(){return void 0!==this._flatMode?this._flatMode:!0===this.ctx.conf.flatMode||Number(this.ctx.conf.nestMax)<=1||!("auto"!==this.ctx.conf.flatMode||!window.matchMedia("(max-width: 768px)").matches)}set flatMode(e){this._flatMode=e}get pageMode(){return this._pageMode||(this.conf.pagination.readMore?"read-more":"pagination")}set pageMode(e){this._pageMode=e}get pageSize(){return this._pageSize||this.conf.pagination.pageSize}set pageSize(e){this._pageSize=e}getData(){return this.data}clearData(){this.data=void 0}getCommentsWrapEl(){return this.$commentsWrap}setLoading(e,t=!1){this.isLoading=e,t?function(e,t){e?Ie(t):De(t)}(e,this.$el):"read-more"===this.pageMode?this.readMoreBtn.setLoading(e):"pagination"===this.pageMode&&this.pagination.setLoading(e)}fetchComments(e){return __async(this,null,(function*(){if(this.isLoading)return;const t=0===e,i=e=>this.setLoading(e,t);let n;i(!0),this.ctx.trigger("list-load"),("read-more"===this.pageMode&&t||"pagination"===this.pageMode)&&this.ctx.clearAllComments();try{n=yield this.ctx.getApi().comment.get(e,this.pageSize,this.flatMode,this.paramsEditor)}catch(s){throw this.onError(s.msg||String(s),e,s.data),s}finally{i(!1)}Ne(this.$el,null);try{this.onLoad(n,e)}catch(s){throw this.onError(String(s),e),s}finally{i(!1)}}))}onLoad(e,t){var i,n;this.data=e,this.confLoaded||(this.conf.useBackendConf?this.ctx.updateConf(e.conf.frontend_conf):this.ctx.updateConf({}),this.confLoaded=!0);const s=(null==(i=e.api_version)?void 0:i.fe_min_version)||"0.0.0";this.ctx.conf.versionCheck&&this.versionCheck("frontend",s,Ye)||this.ctx.conf.versionCheck&&this.versionCheck("backend","2.3.0",null==(n=e.api_version)?void 0:n.version)||(this.importComments(e.comments),this.refreshPagination(t,this.flatMode?e.total:e.total_roots),this.refreshUI(),this.ctx.updateNotifies(e.unread||[]),this.ctx.trigger("list-loaded"),this.onAfterLoad&&this.onAfterLoad(e))}refreshPagination(e,t){const i="pagination"===this.pageMode,n="read-more"===this.pageMode;(i?!!this.pagination:!!this.readMoreBtn)||this.initPagination(),i&&this.pagination.update(e,t),n&&this.readMoreBtn.update(e,t)}initPagination(){if("read-more"===this.pageMode&&(this.readMoreBtn=new rt({pageSize:this.pageSize,onClick:e=>__async(this,null,(function*(){yield this.fetchComments(e)})),text:this.ctx.$t("loadMore")}),this.$el.append(this.readMoreBtn.$el),this.conf.pagination.autoLoad)){const e=this.scrollListenerAt||document;this.autoLoadScrollEvent&&e.removeEventListener("scroll",this.autoLoadScrollEvent),this.autoLoadScrollEvent=()=>{var e;if("read-more"!==this.pageMode||!(null==(e=this.readMoreBtn)?void 0:e.hasMore)||this.isLoading)return;const t=this.$el.querySelector(".atk-list-comments-wrap > .atk-comment-wrap:nth-last-child(3)");t&&function(e,t=document.documentElement){const i=t.clientHeight,n=t.scrollTop,s=n+i,r=e.getBoundingClientRect();return r.top+n+r.height<=s}(t,this.scrollListenerAt)&&this.readMoreBtn.click()},e.addEventListener("scroll",this.autoLoadScrollEvent)}"pagination"===this.pageMode&&(this.pagination=new st(this.flatMode?this.data.total:this.data.total_roots,{pageSize:this.pageSize,onChange:e=>__async(this,null,(function*(){if(!0===this.ctx.conf.editorTravel&&this.ctx.editorTravelBack(),yield this.fetchComments(e),this.repositionAt){(this.scrollListenerAt||window).scroll({top:this.repositionAt?Te(this.repositionAt).top:0,left:0})}}))}),this.$el.append(this.pagination.$el))}onError(e,t,i){var n;if(this.confLoaded||this.ctx.updateConf({}),e=String(e),console.error(e),0!==t&&"read-more"===this.pageMode)return void(null==(n=this.readMoreBtn)||n.showErr(this.$t("loadFail")));const s=we(`${e},${this.$t("listLoadFailMsg")}
    `),r=we(`${this.$t("listRetry")}`);r.onclick=()=>this.fetchComments(0),s.appendChild(r);const a=we(' | 打开控制台');s.appendChild(a),this.ctx.user.data.isAdmin||a.classList.add("atk-hide");let o="";if(null==i?void 0:i.err_no_site){const e={create_name:this.ctx.conf.site,create_urls:`${window.location.protocol}//${window.location.host}`};o=`sites|${JSON.stringify(e)}`}a.onclick=()=>this.ctx.showSidebar({view:o}),Ne(this.$el,s)}refreshUI(){const e=this.ctx.getCommentList().length<=0;let t=this.$commentsWrap.querySelector(".atk-list-no-comment");e?t||(t=we('
    '),t.innerHTML=this.noCommentText||this.ctx.conf.noComment||this.ctx.$t("noComment"),this.$commentsWrap.appendChild(t)):null==t||t.remove(),this.ctx.checkAdminShowEl()}reload(){this.fetchComments(0)}createComment(e,t){t||(t=this.ctx.getCommentDataList());const i=new nt(this.ctx,e,{isFlatMode:this.flatMode,afterRender:()=>{this.renderComment&&this.renderComment(i)},onDelete:e=>{this.ctx.deleteComment(e),this.refreshUI()},replyTo:e.rid?t.find((t=>t.id===e.rid)):void 0});return i.render(),this.ctx.getCommentList().push(i),i}importComments(e){this.flatMode?e.forEach((t=>{this.putCommentFlatMode(t,e,"append")})):this.importCommentsNest(e)}importCommentsNest(e){const t=function(e,t="DATE_DESC",i=2){const n=[];e.filter((e=>0===e.rid)).forEach((t=>{const s={id:t.id,comment:t,children:[],level:1};s.parent=s,n.push(s),function t(n){const s=e.filter((e=>e.rid===n.id));0!==s.length&&(n.level>=i&&(n=n.parent),s.forEach((e=>{const i={id:e.id,comment:e,children:[],parent:n,level:n.level+1};n.children.push(i),t(i)})))}(s)}));const s=(i,n)=>{let s=i.id-n.id;return"DATE_ASC"===t?s=+new Date(i.comment.date)-+new Date(n.comment.date):"DATE_DESC"===t?s=+new Date(n.comment.date)-+new Date(i.comment.date):"SRC_INDEX"===t?s=e.indexOf(i.comment)-e.indexOf(n.comment):"VOTE_UP_DESC"===t&&(s=n.comment.vote_up-i.comment.vote_up),s};return function e(t){t.forEach((t=>{t.children=t.children.sort(s),e(t.children)}))}(n),n}(e,this.nestSortBy,this.conf.nestMax);t.forEach((t=>{const i=this.createComment(t.comment,e);this.$commentsWrap.appendChild(i.getEl()),i.getRender().playFadeAnim();const n=this;!function t(i,s){s.children.forEach((s=>{const r=s.comment,a=n.createComment(r,e);i.putChild(a),t(a,s)}))}(i,t),i.getRender().checkHeightLimit()}))}putCommentFlatMode(e,t,i){e.is_collapsed&&(e.is_allow_reply=!1);const n=this.createComment(e,t);return e.visible&&("append"===i&&this.$commentsWrap.append(n.getEl()),"prepend"===i&&this.$commentsWrap.prepend(n.getEl()),n.getRender().playFadeAnim()),n.getRender().checkHeightLimit(),n}insertComment(e){if(this.flatMode){qe(this.putCommentFlatMode(e,this.ctx.getCommentDataList(),"prepend").getEl())}else{const t=this.createComment(e);if(0===e.rid)this.$commentsWrap.prepend(t.getEl());else{const i=this.ctx.findComment(e.rid);i&&(i.putChild(t,"DATE_ASC"===this.nestSortBy?"append":"prepend"),t.getParents().forEach((e=>{e.getRender().heightLimitRemoveForChildren()})))}t.getRender().checkHeightLimit(),qe(t.getEl()),t.getRender().playFadeAnim()}this.data&&(this.data.total+=1),this.refreshUI(),this.ctx.trigger("list-loaded"),this.ctx.trigger("list-inserted",e)}updateComment(e){const t=this.ctx.findComment(e.id);t&&t.setData(e)}updateUnread(e){this.unread=e,!0===this.unreadHighlight&&this.ctx.getCommentList().forEach((e=>{const t=this.unread.find((t=>t.comment_id===e.getID()));t?(e.getRender().setUnread(!0),e.getRender().setOpenAction((()=>{window.open(t.read_link),this.unread=this.unread.filter((t=>t.comment_id!==e.getID())),this.ctx.updateNotifies(this.unread)}))):e.getRender().setUnread(!1)}))}versionCheck(e,t,i){const n=1===function(e,t){const i=e.split("."),n=t.split(".");for(let s=0;s<3;s++){const e=Number(i[s]),t=Number(n[s]);if(e>t)return 1;if(t>e)return-1;if(!Number.isNaN(e)&&Number.isNaN(t))return 1;if(Number.isNaN(e)&&!Number.isNaN(t))return-1}return 0}(t,i);if(n){const n=we(`
    Artalk ${this.$t(e)}版本已过时,请更新以获得完整体验
    如果你是管理员,请前往 “官方文档” 获得帮助

    当前${this.$t(e)}版本 ${i},需求版本 >= ${t}

    `),s=we('忽略');s.onclick=()=>{Ne(this.$el.parentElement,null),this.ctx.conf.versionCheck=!1,this.fetchComments(0)},n.append(s),Ne(this.$el.parentElement,n,'Artalk Warn')}return n}}class ot extends at{constructor(e){const t=we('
    \n
    \n
    \n
    \n
    \n
    \n \n \n \n
    \n
    \n
    \n
    \n
    \n \n
    \n');super(e),__publicField(this,"$closeCommentBtn"),__publicField(this,"$openSidebarBtn"),__publicField(this,"$unreadBadge"),__publicField(this,"$commentCount"),__publicField(this,"$commentCountNum"),__publicField(this,"$dropdownWrap"),__publicField(this,"goToCommentFounded",!1),__publicField(this,"goToCommentDelay",!0),__publicField(this,"dropdownLoaded",!1),t.querySelector(".atk-list-body").append(this.$el),this.$el=t,this.repositionAt=this.$el,this.initListActionBtn(),this.$commentCount=this.$el.querySelector(".atk-comment-count"),this.$commentCount.innerHTML=this.$t("counter",{count:'0'}),this.$commentCountNum=this.$commentCount.querySelector(".atk-comment-count-num"),this.$el.querySelector(".atk-copyright").innerHTML='Powered By Artalk'}initListActionBtn(){this.$openSidebarBtn=this.$el.querySelector('[data-action="open-sidebar"]'),this.$closeCommentBtn=this.$el.querySelector('[data-action="admin-close-comment"]'),this.$unreadBadge=this.$el.querySelector(".atk-unread-badge"),this.$openSidebarBtn.addEventListener("click",(()=>{this.ctx.showSidebar()})),this.$closeCommentBtn.addEventListener("click",(()=>{this.data&&(this.data.page.admin_only=!this.data.page.admin_only,this.adminPageEditSave())}))}refreshUI(){var e;super.refreshUI(),this.$commentCountNum.innerText=String(Number(null==(e=this.data)?void 0:e.total)||0),this.ctx.user.data.nick&&this.ctx.user.data.email?this.$openSidebarBtn.classList.remove("atk-hide"):this.$openSidebarBtn.classList.add("atk-hide"),this.ctx.checkAdminShowEl(),this.$openSidebarBtn.querySelector(".atk-text").innerText=this.ctx.user.data.isAdmin?this.$t("ctrlCenter"):this.$t("msgCenter"),this.data&&this.data.page&&!0===this.data.page.admin_only?(this.ctx.editorClose(),this.$closeCommentBtn.innerHTML=this.$t("openComment")):(this.ctx.editorOpen(),this.$closeCommentBtn.innerHTML=this.$t("closeComment")),this.ctx.conf.listSort&&this.initDropdown()}onLoad(e,t){super.onLoad(e,t),this.goToCommentFounded||this.checkGoToCommentByUrlHash(),!0===this.ctx.conf.editorTravel&&this.ctx.editorTravelBack()}checkGoToCommentByUrlHash(){let e=Number(Se("atk_comment"));if(!e){const t=window.location.hash.match(/#atk-comment-([0-9]+)/);if(!t||!t[1]||Number.isNaN(Number(t[1])))return;e=Number(t[1])}if(!e)return;const t=this.ctx.findComment(e);if(!t)return void(this.readMoreBtn?this.readMoreBtn.click():this.pagination&&this.pagination.next());const i=Se("atk_notify_key");i&&this.ctx.getApi().user.markRead(i).then((()=>{this.unread=this.unread.filter((t=>t.comment_id!==e)),this.updateUnread(this.unread)})),t.getParents().forEach((e=>{e.getRender().heightLimitRemoveForChildren()}));const n=()=>{qe(t.getEl(),!1),t.getEl().classList.remove("atk-flash-once"),window.setTimeout((()=>{t.getEl().classList.add("atk-flash-once")}),150)};this.goToCommentDelay?window.setTimeout((()=>n()),350):n(),this.goToCommentFounded=!0}adminPageEditSave(){this.data&&this.data.page&&(this.ctx.editorShowLoading(),this.ctx.getApi().page.pageEdit(this.data.page).then((e=>{this.data&&(this.data.page=__spreadValues({},e)),this.refreshUI()})).catch((e=>{this.ctx.editorShowNotify(`${this.$t("editFail")}: ${e.msg||String(e)}`,"e")})).finally((()=>{this.ctx.editorHideLoading()})))}showUnreadBadge(e){e>0?(this.$unreadBadge.innerText=`${Number(e||0)}`,this.$unreadBadge.style.display="block"):this.$unreadBadge.style.display="none"}initDropdown(){if(this.dropdownLoaded)return;this.dropdownLoaded=!0,this.$dropdownWrap=this.$commentCount,this.$commentCount.classList.add("atk-dropdown-wrap"),this.$dropdownWrap.append(we(''));const e=e=>{this.paramsEditor=t=>{e(t)},this.fetchComments(0)},t=[[this.$t("sortLatest"),()=>{e((e=>{e.sort_by="date_desc"}))}],[this.$t("sortBest"),()=>{e((e=>{e.sort_by="vote"}))}],[this.$t("sortOldest"),()=>{e((e=>{e.sort_by="date_asc"}))}],[this.$t("sortAuthor"),()=>{e((e=>{e.view_only_admin=!0}))}]];let i=0;const n=we('
      ');t.forEach(((e,t)=>{const s=e[0],r=e[1],a=we('
    • '),o=a.querySelector("span");o.innerText=s,o.onclick=()=>{((e,t,s,r)=>{r(),i=e,n.querySelectorAll(".active").forEach((e=>{e.classList.remove("active")})),t.classList.add("active"),n.style.display="none",setTimeout((()=>{n.style.display=""}),80)})(t,a,0,r)},n.append(a),t===i&&a.classList.add("active")})),this.$dropdownWrap.append(n)}updateUnread(e){super.updateUnread(e),this.showUnreadBadge((null==e?void 0:e.length)||0)}}class lt{constructor(e,t){__publicField(this,"api"),__publicField(this,"editor"),__publicField(this,"list"),__publicField(this,"sidebarLayer"),__publicField(this,"checkerLauncher"),__publicField(this,"cid"),__publicField(this,"conf"),__publicField(this,"user"),__publicField(this,"$root"),__publicField(this,"markedInstance"),__publicField(this,"markedReplacers",[]),__publicField(this,"commentList",[]),__publicField(this,"eventList",[]),__publicField(this,"darkModeMedia",window.matchMedia("(prefers-color-scheme: dark)")),__publicField(this,"darkModeAutoFunc"),this.cid=+new Date,this.conf=e,this.user=new n(this),this.$root=t||document.createElement("div"),this.$root.setAttribute("atk-run-id",this.cid.toString()),this.$root.classList.add("artalk"),this.$root.innerHTML="",this.api=new Ke(this),this.on("conf-loaded",(()=>{this.refreshDarkModeConf()}))}setApi(e){this.api=e}setEditor(e){this.editor=e}setList(e){this.list=e}setSidebarLayer(e){this.sidebarLayer=e}setCheckerLauncher(e){this.checkerLauncher=e}getApi(){return this.api}getCommentList(){return this.commentList}getCommentDataList(){return this.commentList.map((e=>e.getData()))}findComment(e){return this.commentList.find((t=>t.getData().id===e))}deleteComment(e){let t;if("number"==typeof e){const i=this.findComment(e);if(!i)throw Error(`Comment ${e} cannot be found`);t=i}else t=e;if(t.getEl().remove(),this.commentList.splice(this.commentList.indexOf(t),1),this.list){const e=this.list.getData();e&&(e.total-=1),this.list.refreshUI()}}clearAllComments(){this.list&&(this.list.getCommentsWrapEl().innerHTML="",this.list.clearData()),this.commentList=[]}insertComment(e){var t;null==(t=this.list)||t.insertComment(e)}updateComment(e){var t;null==(t=this.list)||t.updateComment(e)}replyComment(e,t,i){this.editor.setReply(e,t,i)}cancelReplyComment(){this.editor.cancelReply()}editComment(e,t){this.editor.setEditComment(e,t)}cancelEditComment(){this.editor.cancelEditComment()}updateNotifies(e){var t;null==(t=this.list)||t.updateUnread(e)}listReload(){var e;null==(e=this.list)||e.reload()}reload(){this.listReload()}listRefreshUI(){var e;null==(e=this.list)||e.refreshUI()}listHashGotoCheck(){if(!this.list||this.list instanceof ot)return;const e=this.list;e.goToCommentDelay=!1,e.checkGoToCommentByUrlHash()}editorOpen(){this.editor.open()}editorClose(){this.editor.close()}editorShowLoading(){this.editor.showLoading()}editorHideLoading(){this.editor.hideLoading()}editorShowNotify(e,t){this.editor.showNotify(e,t)}editorTravel(e){this.editor.travel(e)}editorTravelBack(){this.editor.travelBack()}showSidebar(e){this.sidebarLayer.show(e)}hideSidebar(){this.sidebarLayer.hide()}checkAdmin(e){this.checkerLauncher.checkAdmin(e)}checkCaptcha(e){this.checkerLauncher.checkCaptcha(e)}checkAdminShowEl(){const e=[];this.$root.querySelectorAll("[atk-only-admin-show]").forEach((t=>e.push(t)));const{$wrap:t}=je(this);t&&t.querySelectorAll("[atk-only-admin-show]").forEach((t=>e.push(t)));const i=document.querySelector(".atk-sidebar");i&&i.querySelectorAll("[atk-only-admin-show]").forEach((t=>e.push(t))),e.forEach((e=>{this.user.data.isAdmin?e.classList.remove("atk-hide"):e.classList.add("atk-hide")}))}on(e,t,i="internal"){this.eventList.push({name:e,handler:t,scope:i})}off(e,t,i="internal"){this.eventList=this.eventList.filter((n=>t?!(n.name===e&&n.handler===t&&n.scope===i):!(n.name===e&&n.scope===i)))}trigger(e,t,i){this.eventList.filter((t=>t.name===e&&(!i||t.scope===i))).map((e=>e.handler)).forEach((e=>e(t)))}$t(e,t={}){return i(this.conf.locale,e,t)}setDarkMode(e){const t="atk-dark-mode";this.conf.darkMode=e,e?this.$root.classList.add(t):this.$root.classList.remove(t);const{$wrap:i}=je(this);i&&(e?i.classList.add(t):i.classList.remove(t))}refreshDarkModeConf(){"auto"===this.conf.darkMode?(this.setDarkMode(this.darkModeMedia.matches),this.darkModeAutoFunc||(this.darkModeAutoFunc=e=>{this.setDarkMode(e.matches)},this.darkModeMedia.addEventListener("change",this.darkModeAutoFunc))):(this.darkModeAutoFunc&&this.darkModeMedia.removeEventListener("change",this.darkModeAutoFunc),this.setDarkMode(this.conf.darkMode||!1))}updateConf(e){this.conf=Be(this.conf,e),this.trigger("conf-loaded")}}class ct{constructor(e,t){return __publicField(this,"ctx"),__publicField(this,"$el"),__publicField(this,"$content"),__publicField(this,"$actions"),this.ctx=e,this.$el=we('
      \n
      \n
      \n
      \n
      \n
      '),this.$actions=this.$el.querySelector(".atk-layer-dialog-actions"),this.$content=this.$el.querySelector(".atk-layer-dialog-content"),this.$content.appendChild(t),this}setYes(e){const t=we(``);return t.onclick=this.onBtnClick(e),this.$actions.appendChild(t),this}setNo(e){const t=we(``);return t.onclick=this.onBtnClick(e),this.$actions.appendChild(t),this}onBtnClick(e){return t=>{const i=e(t.currentTarget,this);void 0!==i&&!0!==i||this.$el.remove()}}}const ht={request:(e,t,i)=>e.ctx.getApi().captcha.captchaCheck(i),body(e,t){if(e.captchaConf.iframe){const i=we('
      '),n=we('');n.style.display="none",Ie(i,{transparentBg:!0}),n.src=`${e.ctx.conf.server}/api/captcha/get?t=${+new Date}`,n.onload=()=>{n.style.display="",De(i)},i.append(n);const s=we('
      ');i.append(s),t.hideInteractInput();let r=!1;const a=e=>new Promise((t=>{window.setTimeout((()=>{t(null)}),e)}));return function i(){return __async(this,null,(function*(){if(yield a(1e3),r)return;let n=!1;try{n=(yield e.ctx.getApi().captcha.captchaStatus()).is_pass}catch(s){n=!1}n?t.triggerSuccess():i()}))}(),s.onclick=()=>{r=!0,t.cancel()},i}const i=we(`${e.ctx.$t("captchaCheck")}`);return i.querySelector(".atk-captcha-img").onclick=()=>{const t=i.querySelector(".atk-captcha-img");e.ctx.getApi().captcha.captchaGet().then((e=>{t.setAttribute("src",e)})).catch((e=>{console.error("Failed to get captcha image ",e)}))},i},onSuccess(e,t,i,n,s){e.captchaConf.val=n},onError(e,t,i,n,s){s.querySelector(".atk-captcha-img").click(),s.querySelector('input[type="text"]').value=""}},dt={inputType:"password",request(e,t,i){const n={name:e.ctx.user.data.nick,email:e.ctx.user.data.email,password:i};return(()=>__async(this,null,(function*(){return(yield e.ctx.getApi().user.login(n.name,n.email,n.password)).token})))()},body:(e,t)=>we(`${e.ctx.$t("adminCheck")}`),onSuccess(e,t,i,n,s){e.ctx.user.update({isAdmin:!0,token:i}),e.ctx.trigger("user-changed",e.ctx.user.data),e.ctx.listReload()},onError(e,t,i,n,s){}};class ut{constructor(e){__publicField(this,"ctx"),__publicField(this,"launched",[]),__publicField(this,"captchaConf",{}),this.ctx=e}checkCaptcha(e){this.captchaConf.imgData=e.imgData,this.captchaConf.iframe=e.iframe,this.fire(ht,e)}checkAdmin(e){this.fire(dt,e)}fire(e,t){if(this.launched.includes(e))return;this.launched.push(e);const i=new He(this.ctx,`checker-${(new Date).getTime()}`);i.setMaskClickHide(!1),i.show();let n=!1;const s={getLayer:()=>i,hideInteractInput:()=>{n=!0},triggerSuccess:()=>{this.close(e,i),e.onSuccess&&e.onSuccess(this,s,"","",r),t.onSuccess&&t.onSuccess("",l.$el)},cancel:()=>{this.close(e,i),t.onCancel&&t.onCancel()}},r=we();r.appendChild(e.body(this,s));const a=we(``);let o;r.appendChild(a),setTimeout((()=>a.focus()),80),a.onkeyup=e=>{"Enter"!==e.key&&13!==e.keyCode||(e.preventDefault(),i.getEl().querySelector('button[data-action="confirm"]').click())};const l=new ct(this.ctx,r);l.setYes((n=>{const c=a.value.trim();o||(o=n.innerText);const h=()=>{n.innerText=o||"",n.classList.remove("error")};return n.innerText=`${this.ctx.$t("loading")}...`,e.request(this,s,c).then((n=>{this.close(e,i),e.onSuccess&&e.onSuccess(this,s,n,c,r),t.onSuccess&&t.onSuccess(c,l.$el)})).catch((t=>{var i;i=String(t.msg||String(t)),n.innerText=i,n.classList.add("error"),e.onError&&e.onError(this,s,t,c,r);const o=setTimeout((()=>h()),3e3);a.onfocus=()=>{h(),clearTimeout(o)}})),!1})),l.setNo((()=>(this.close(e,i),t.onCancel&&t.onCancel(),!1))),n&&(a.style.display="none",l.$el.querySelector(".atk-layer-dialog-actions").style.display="none"),i.getEl().append(l.$el),t.onMount&&t.onMount(l.$el)}close(e,t){t.disposeNow(),this.launched=this.launched.filter((t=>t!==e))}}class pt{constructor(e){__publicField(this,"editor"),__publicField(this,"$panel"),__publicField(this,"$btn"),__publicField(this,"onHeaderInput"),this.editor=e}get ctx(){return this.editor.ctx}registerPanel(e="
      "){return this.$panel=we(e),this.$panel}registerBtn(e){return this.$btn=we(`${e}`),this.$btn}registerHeaderInputEvt(e){this.onHeaderInput=e}getPanel(){return this.$panel}getBtn(){return this.$btn}}__publicField(pt,"Name");class mt extends pt{constructor(e){super(e),__publicField(this,"emoticons",[]),__publicField(this,"loadingTask",null),__publicField(this,"$grpWrap"),__publicField(this,"$grpSwitcher"),__publicField(this,"isListLoaded",!1),__publicField(this,"isImgLoaded",!1),this.editor=e,this.registerPanel('
      '),this.registerBtn(this.ctx.$t("emoticon")),window.setTimeout((()=>{this.loadEmoticonsData()}),1e3)}onPanelShow(){(()=>{__async(this,null,(function*(){yield this.loadEmoticonsData(),this.isImgLoaded||(this.initEmoticonsList(),this.isImgLoaded=!0),setTimeout((()=>{this.changeListHeight()}),30)}))})()}onPanelHide(){this.$panel.parentElement.style.height=""}loadEmoticonsData(){return __async(this,null,(function*(){this.isListLoaded||(null===this.loadingTask?(this.loadingTask=(()=>__async(this,null,(function*(){Ie(this.$panel),this.emoticons=yield this.handleData(this.ctx.conf.emoticons),De(this.$panel),this.loadingTask=null,this.isListLoaded=!0})))(),yield this.loadingTask):yield this.loadingTask)}))}handleData(e){return __async(this,null,(function*(){if(!Array.isArray(e)&&["object","string"].includes(typeof e)&&(e=[e]),!Array.isArray(e))return Ne(this.$panel,"表情包数据必须为 Array/Object/String 类型"),De(this.$panel),[];const t=t=>{"object"==typeof t&&(t.name&&e.find((e=>e.name===t.name))||e.push(t))},i=e=>__async(this,null,(function*(){yield Promise.all(e.map(((e,n)=>__async(this,null,(function*(){if("object"!=typeof e||Array.isArray(e)){if(Array.isArray(e))yield i(e);else if("string"==typeof e){const n=yield this.remoteLoad(e);Array.isArray(n)?yield i(n):"object"==typeof n&&t(n)}}else t(e)})))))}));return yield i(e),e.forEach((e=>{if(this.isOwOFormat(e)){this.convertOwO(e).forEach((e=>{t(e)}))}else Array.isArray(e)&&e.forEach((e=>{t(e)}))})),e=e.filter((e=>"object"==typeof e&&!Array.isArray(e)&&!!e&&!!e.name)),this.solveNullKey(e),this.solveSameKey(e),e}))}remoteLoad(e){return __async(this,null,(function*(){if(!e)return[];try{const t=yield fetch(e);return yield t.json()}catch(t){return De(this.$panel),Ne(this.$panel,`表情加载失败 ${String(t)}`),[]}}))}solveNullKey(e){e.forEach((e=>{e.items.forEach(((t,i)=>{t.key||(t.key=`${e.name} ${i+1}`)}))}))}solveSameKey(e){const t={};e.forEach((e=>{e.items.forEach((e=>{e.key&&""!==String(e.key).trim()&&(t[e.key]?t[e.key]++:t[e.key]=1,t[e.key]>1&&(e.key=`${e.key} ${t[e.key]}`))}))}))}isOwOFormat(e){try{return"object"==typeof e&&!!Object.values(e).length&&Array.isArray(Object.keys(Object.values(e)[0].container))&&Object.keys(Object.values(e)[0].container[0]).includes("icon")}catch(t){return!1}}convertOwO(e){const t=[];return Object.entries(e).forEach((([e,i])=>{const n={name:e,type:i.type,items:[]};i.container.forEach(((t,i)=>{const s=t.icon;if(/<(img|IMG)/.test(s)){const e=/src=["'](.*?)["']/.exec(s);e&&e.length>1&&(t.icon=e[1])}n.items.push({key:t.text||`${e} ${i+1}`,val:t.icon})})),t.push(n)})),t}initEmoticonsList(){this.$grpWrap=we('
      '),this.$panel.append(this.$grpWrap),this.emoticons.forEach(((e,t)=>{const i=we('');this.$grpWrap.append(i),i.setAttribute("data-index",String(t)),i.setAttribute("data-grp-name",e.name),i.setAttribute("data-type",e.type),e.items.forEach((t=>{const n=we('');if(i.append(n),t.key&&!new RegExp(`^(${e.name})?\\s?[0-9]+$`).test(t.key)&&n.setAttribute("title",t.key),"image"===e.type){const e=document.createElement("img");e.src=t.val,e.alt=t.key,n.append(e)}else n.innerText=t.val;n.onclick=()=>{"image"===e.type?this.editor.insertContent(`:[${t.key}]`):this.editor.insertContent(t.val||"")}}))})),this.emoticons.length>1&&(this.$grpSwitcher=we('
      '),this.$panel.append(this.$grpSwitcher),this.emoticons.forEach(((e,t)=>{const i=we("");i.innerText=e.name,i.setAttribute("data-index",String(t)),i.onclick=()=>this.openGrp(t),this.$grpSwitcher.append(i)}))),this.emoticons.length>0&&this.openGrp(0)}openGrp(e){var t,i,n;Array.from(this.$grpWrap.children).forEach((t=>{const i=t;i.getAttribute("data-index")!==String(e)?i.style.display="none":i.style.display=""})),null==(t=this.$grpSwitcher)||t.querySelectorAll("span.active").forEach((e=>e.classList.remove("active"))),null==(n=null==(i=this.$grpSwitcher)?void 0:i.querySelector(`span[data-index="${e}"]`))||n.classList.add("active"),this.changeListHeight()}changeListHeight(){}transEmoticonImageText(e){return this.emoticons&&Array.isArray(this.emoticons)?(this.emoticons.forEach((t=>{"image"===t.type&&Object.entries(t.items).forEach((([t,i])=>{e=e.split(`:[${i.key}]`).join(``)}))})),e):e}}__publicField(mt,"Name","emoticons");class gt extends pt{constructor(e){super(e),__publicField(this,"$imgUploadInput"),__publicField(this,"allowImgExts",["png","jpg","jpeg","gif","bmp","svg","webp"]),this.$imgUploadInput=document.createElement("input"),this.$imgUploadInput.type="file",this.$imgUploadInput.style.display="none",this.$imgUploadInput.accept=this.allowImgExts.map((e=>`.${e}`)).join(",");const t=this.registerBtn(`${this.ctx.$t("image")}`);t.after(this.$imgUploadInput),t.onclick=()=>{const e=this.$imgUploadInput;e.onchange=()=>{(()=>{__async(this,null,(function*(){if(!e.files||0===e.files.length)return;const t=e.files[0];this.uploadImg(t)}))})()},e.click()},this.ctx.on("conf-loaded",(()=>{this.ctx.conf.imgUpload||(this.getBtn().setAttribute("atk-only-admin-show",""),this.ctx.checkAdminShowEl())}));const i=e=>{if(e)for(let t=0;t{e.stopPropagation(),e.preventDefault()})),this.editor.$textarea.addEventListener("drop",(e=>{var t;const n=null==(t=e.dataTransfer)?void 0:t.files;(null==n?void 0:n.length)&&(e.preventDefault(),i(n))})),this.editor.$textarea.addEventListener("paste",(e=>{var t;const n=null==(t=e.clipboardData)?void 0:t.files;(null==n?void 0:n.length)&&(e.preventDefault(),i(n))}))}uploadImg(e){return __async(this,null,(function*(){const t=/[^.]+$/.exec(e.name);if(!t||!this.allowImgExts.includes(t[0]))return;if(!this.ctx.user.checkHasBasicUserInfo())return void this.editor.showNotify(this.ctx.$t("uploadLoginMsg"),"w");let i="\n";""===this.editor.$textarea.value.trim()&&(i="");const n=`${i}![](Uploading ${e.name}...)`;let s;this.editor.insertContent(n);try{s=this.ctx.conf.imgUploader?{img_url:yield this.ctx.conf.imgUploader(e)}:yield this.ctx.getApi().upload.imgUpload(e)}catch(r){console.error(r),this.editor.showNotify(`${this.ctx.$t("uploadFail")},${r.msg}`,"e")}if(s&&s.img_url){let e=s.img_url;Me(e)||(e=Re(this.ctx,e)),this.editor.setContent(this.editor.$textarea.value.replace(n,`${i}![](${e})`))}else this.editor.setContent(this.editor.$textarea.value.replace(n,""))}))}}__publicField(gt,"Name","upload");class ft extends pt{constructor(e){super(e),__publicField(this,"isBind",!1),this.registerPanel('
      ');let t=this.editor.$t("preview");this.ctx.markedInstance&&(t+=' '),this.registerBtn(t)}onPanelShow(){if(this.updateContent(),!this.isBind){const e=()=>{this.updateContent()};this.editor.$textarea.addEventListener("input",e),this.editor.$textarea.addEventListener("change",e),this.isBind=!0}}updateContent(){"none"!==this.$panel.style.display&&(this.$panel.innerHTML=this.editor.getContentMarked())}}__publicField(ft,"Name","preview");class kt extends pt{constructor(e){super(e),__publicField(this,"queryUserInfo",{timeout:null,abortFunc:null}),this.registerHeaderInputEvt(((e,t)=>{"nick"!==e&&"email"!==e||this.fetchUserInfo()})),this.editor.$link.addEventListener("change",(()=>{const e=this.editor.$link.value.trim();e&&!/^(http|https):\/\//.test(e)&&(this.editor.$link.value=`https://${e}`,this.ctx.user.update({link:this.editor.$link.value}))}))}fetchUserInfo(){this.ctx.user.logout(),this.queryUserInfo.timeout&&window.clearTimeout(this.queryUserInfo.timeout),this.queryUserInfo.abortFunc&&this.queryUserInfo.abortFunc(),this.queryUserInfo.timeout=window.setTimeout((()=>{this.queryUserInfo.timeout=null;const{req:e,abort:t}=this.ctx.getApi().user.userGet(this.ctx.user.data.nick,this.ctx.user.data.email);this.queryUserInfo.abortFunc=t,e.then((e=>{var t;e.is_login||this.ctx.user.logout(),this.ctx.updateNotifies(e.unread),this.ctx.user.checkHasBasicUserInfo()&&!e.is_login&&(null==(t=e.user)?void 0:t.is_admin)&&this.showLoginDialog(),e.user&&e.user.link&&(this.editor.$link.value=e.user.link,this.ctx.user.update({link:e.user.link}))})).catch((()=>{})).finally((()=>{this.queryUserInfo.abortFunc=null}))}),400)}showLoginDialog(){this.ctx.checkAdmin({onSuccess:()=>{}})}}__publicField(kt,"Name","headerInput");class yt extends Pe{constructor(e){super(e),__publicField(this,"$header"),__publicField(this,"$nick"),__publicField(this,"$email"),__publicField(this,"$link"),__publicField(this,"$textareaWrap"),__publicField(this,"$textarea"),__publicField(this,"$bottom"),__publicField(this,"$submitBtn"),__publicField(this,"$notifyWrap"),__publicField(this,"isTraveling",!1),__publicField(this,"replyComment",null),__publicField(this,"$sendReply",null),__publicField(this,"editComment",null),__publicField(this,"$editCancelBtn",null),__publicField(this,"ENABLED_PLUGS",[mt,gt,ft,kt]),__publicField(this,"plugList",{}),__publicField(this,"openedPlugName",null),__publicField(this,"$plugPanelWrap"),__publicField(this,"$plugBtnWrap"),this.$el=we('
      \n
      \n \n \n \n
      \n
      \n \n
      \n \n
      \n
      \n
      \n \n
      \n
      \n
      \n
      \n'),this.$header=this.$el.querySelector(".atk-header"),this.$nick=this.$header.querySelector('[name="nick"]'),this.$email=this.$header.querySelector('[name="email"]'),this.$link=this.$header.querySelector('[name="link"]'),this.$textareaWrap=this.$el.querySelector(".atk-textarea-wrap"),this.$textarea=this.$el.querySelector(".atk-textarea"),this.$bottom=this.$el.querySelector(".atk-bottom"),this.$submitBtn=this.$el.querySelector(".atk-send-btn"),this.$notifyWrap=this.$el.querySelector(".atk-notify-wrap"),this.$plugBtnWrap=this.$el.querySelector(".atk-plug-btn-wrap"),this.$plugPanelWrap=this.$el.querySelector(".atk-plug-panel-wrap"),this.ctx.on("conf-loaded",(()=>{this.initLocalStorage(),this.initHeader(),this.initTextarea(),this.initSubmitBtn(),this.initPlugs()}))}get user(){return this.ctx.user}get $inputs(){return{nick:this.$nick,email:this.$email,link:this.$link}}get isReplyMode(){return null!==this.replyComment}get isEditMode(){return null!==this.editComment}initLocalStorage(){const e=window.localStorage.getItem("ArtalkContent")||"";""!==e.trim()&&(this.showNotify(this.$t("restoredMsg"),"i"),this.setContent(e)),this.$textarea.addEventListener("input",(()=>this.saveToLocalStorage()))}saveToLocalStorage(){window.localStorage.setItem("ArtalkContent",this.getContentOriginal().trim())}initHeader(){Object.entries(this.$inputs).forEach((([e,t])=>{t.value=this.user.data[e]||"",t.addEventListener("input",(()=>this.onHeaderInput(e,t))),t.placeholder=`${this.$t(e)}`}))}onHeaderInput(e,t){this.isEditMode||(this.user.update({[e]:t.value.trim()}),Object.entries(this.plugList).forEach((([i,n])=>{n.onHeaderInput&&n.onHeaderInput(e,t)})))}initTextarea(){this.$textarea.placeholder=this.ctx.conf.placeholder||this.$t("placeholder"),this.$textarea.addEventListener("keydown",(e=>{9===(e.keyCode||e.which)&&(e.preventDefault(),this.insertContent("\t"))})),this.$textarea.addEventListener("input",(()=>{this.adjustTextareaHeight()}))}refreshSendBtnText(){this.isEditMode?this.$submitBtn.innerText=this.$t("save"):this.$submitBtn.innerText=this.ctx.conf.sendBtn||this.$t("send")}initSubmitBtn(){this.refreshSendBtnText(),this.$submitBtn.addEventListener("click",(()=>this.submit()))}getFinalContent(){let e=this.getContentOriginal();return this.plugList.emoticons&&(e=this.plugList.emoticons.transEmoticonImageText(e)),e}getContentOriginal(){return this.$textarea.value||""}getContentMarked(){return Fe(this.ctx,this.getFinalContent())}setContent(e){this.$textarea.value=e,this.saveToLocalStorage(),this.plugList.preview&&this.plugList.preview.updateContent(),window.setTimeout((()=>{this.adjustTextareaHeight()}),80)}insertContent(e){if(document.selection)this.$textarea.focus(),document.selection.createRange().text=e,this.$textarea.focus();else if(this.$textarea.selectionStart||0===this.$textarea.selectionStart){const t=this.$textarea.selectionStart,i=this.$textarea.selectionEnd,n=this.$textarea.scrollTop;this.setContent(this.$textarea.value.substring(0,t)+e+this.$textarea.value.substring(i,this.$textarea.value.length)),this.$textarea.focus(),this.$textarea.selectionStart=t+e.length,this.$textarea.selectionEnd=t+e.length,this.$textarea.scrollTop=n}else this.$textarea.focus(),this.$textarea.value+=e}adjustTextareaHeight(){const e=this.$textarea.offsetHeight-this.$textarea.clientHeight;this.$textarea.style.height="0px",this.$textarea.style.height=`${this.$textarea.scrollHeight+e}px`}setReply(e,t,i=!0){this.isEditMode&&this.cancelEditComment(),this.isReplyMode&&this.cancelReply(),null===this.$sendReply&&(this.$sendReply=we(`
      ${this.$t("reply")} ×
      `),this.$sendReply.querySelector(".atk-text").innerText=`@${e.nick}`,this.$sendReply.addEventListener("click",(()=>{this.cancelReply()})),this.$textareaWrap.append(this.$sendReply)),this.replyComment=e,!0===this.ctx.conf.editorTravel&&this.travel(t),i&&qe(this.$el),this.$textarea.focus()}cancelReply(){null!==this.$sendReply&&(this.$sendReply.remove(),this.$sendReply=null),this.replyComment=null,!0===this.ctx.conf.editorTravel&&this.travelBack()}setEditComment(e,t){this.isEditMode&&this.cancelEditComment(),this.isReplyMode&&this.cancelReply(),null===this.$editCancelBtn&&(this.$editCancelBtn=we(`
      ${this.$t("editCancel")}×
      `),this.$editCancelBtn.onclick=()=>{this.cancelEditComment()},this.$textareaWrap.append(this.$editCancelBtn)),this.editComment=e,this.$header.style.display="none",this.travel(t),this.$nick.value=e.nick,this.$email.value=e.email||"",this.$link.value=e.link,this.setContent(e.content),this.$textarea.focus(),this.refreshSendBtnText()}cancelEditComment(){null!==this.$editCancelBtn&&(this.$editCancelBtn.remove(),this.$editCancelBtn=null),this.editComment=null,this.travelBack(),this.$nick.value=this.user.data.nick,this.$email.value=this.user.data.email,this.$link.value=this.user.data.link,this.setContent(""),this.refreshSendBtnText(),this.$header.style.display=""}showNotify(e,t){ze(this.$notifyWrap,e,t)}showLoading(){Ie(this.$el)}hideLoading(){De(this.$el)}submit(){return __async(this,null,(function*(){""!==this.getFinalContent().trim()?(this.ctx.trigger("editor-submit"),this.showLoading(),this.isEditMode?yield this.submitEdit():yield this.submitAdd(),this.hideLoading()):this.$textarea.focus()}))}submitAdd(){return __async(this,null,(function*(){try{const e=yield this.ctx.getApi().comment.add({content:this.getFinalContent(),nick:this.user.data.nick,email:this.user.data.email,link:this.user.data.link,rid:null===this.replyComment?0:this.replyComment.id,page_key:null===this.replyComment?this.ctx.conf.pageKey:this.replyComment.page_key,page_title:null===this.replyComment?this.ctx.conf.pageTitle:void 0,site_name:null===this.replyComment?this.ctx.conf.site:this.replyComment.site_name});null!==this.replyComment&&this.replyComment.page_key!==this.ctx.conf.pageKey&&window.open(`${this.replyComment.page_url}#atk-comment-${e.id}`),this.ctx.insertComment(e),this.setContent(""),this.cancelReply(),this.ctx.trigger("editor-submitted")}catch(e){console.error(e),this.showNotify(`${this.$t("commentFail")},${e.msg||String(e)}`,"e")}}))}submitEdit(){return __async(this,null,(function*(){try{const e={content:this.getFinalContent(),nick:this.$nick.value,email:this.$email.value,link:this.$link.value},t=yield this.ctx.getApi().comment.commentEdit(__spreadValues(__spreadValues({},this.editComment),e));this.ctx.updateComment(t),this.setContent(""),this.cancelEditComment(),this.ctx.trigger("editor-submitted")}catch(e){console.error(e),this.showNotify(`${this.$t("commentFail")},${e.msg||String(e)}`,"e")}}))}close(){this.$textareaWrap.querySelector(".atk-comment-closed")||this.$textareaWrap.prepend(we(`
      ${this.$t("onlyAdminCanReply")}
      `)),this.user.data.isAdmin?(this.$textarea.style.display="",this.$bottom.style.display=""):(this.$textarea.style.display="none",this.closePlugPanel(),this.$bottom.style.display="none")}open(){var e;null==(e=this.$textareaWrap.querySelector(".atk-comment-closed"))||e.remove(),this.$textarea.style.display="",this.$bottom.style.display=""}travel(e){if(this.isTraveling)return;this.isTraveling=!0,this.$el.after(we('
      '));const t=we("
      ");e.after(t),t.replaceWith(this.$el),this.$el.classList.add("atk-fade-in")}travelBack(){var e;this.isTraveling&&(this.isTraveling=!1,null==(e=this.ctx.$root.querySelector(".atk-editor-travel-placeholder"))||e.replaceWith(this.$el),null!==this.replyComment&&this.cancelReply())}initPlugs(){this.plugList={},this.$plugPanelWrap.innerHTML="",this.$plugPanelWrap.style.display="none",this.openedPlugName=null,this.$plugBtnWrap.innerHTML="";const e=[];this.conf.imgUpload||e.push("upload"),this.conf.emoticons||e.push("emoticons"),this.conf.preview||e.push("preview"),this.ENABLED_PLUGS.forEach((t=>{const i=t.Name;if(e.includes(i))return;const n=new t(this);this.plugList[i]=n;const s=n.getBtn();if(s){this.$plugBtnWrap.appendChild(s),s.onclick=s.onclick||(()=>{this.$plugBtnWrap.querySelectorAll(".active").forEach((e=>e.classList.remove("active"))),i!==this.openedPlugName?(this.openPlugPanel(i),s.classList.add("active")):this.closePlugPanel()});const e=n.getPanel();e&&(e.setAttribute("data-plug-name",i),e.style.display="none",this.$plugPanelWrap.appendChild(e))}}))}openPlugPanel(e){Object.entries(this.plugList).forEach((([t,i])=>{const n=i.getPanel();n&&(t===e?(n.style.display="",i.onPanelShow&&i.onPanelShow()):(n.style.display="none",i.onPanelHide&&i.onPanelHide()))})),this.$plugPanelWrap.style.display="",this.openedPlugName=e}closePlugPanel(){if(!this.openedPlugName)return;const e=this.plugList[this.openedPlugName];e&&(e.onPanelHide&&e.onPanelHide(),this.$plugPanelWrap.style.display="none",this.openedPlugName=null)}}class $t extends Pe{constructor(e){super(e),__publicField(this,"layer"),__publicField(this,"$header"),__publicField(this,"$closeBtn"),__publicField(this,"$iframeWrap"),__publicField(this,"$iframe"),__publicField(this,"firstShow",!0),this.$el=we('
      \n
      \n
      \n
      \n
      \n
      \n
      \n
      \n'),this.$header=this.$el.querySelector(".atk-sidebar-header"),this.$closeBtn=this.$header.querySelector(".atk-sidebar-close"),this.$iframeWrap=this.$el.querySelector(".atk-sidebar-iframe-wrap"),this.$closeBtn.onclick=()=>{this.hide()},this.ctx.on("user-changed",(()=>{this.firstShow=!0}))}show(){return __async(this,arguments,(function*(e={}){if(this.$el.style.transform="",null==this.layer&&(this.layer=new He(this.ctx,"sidebar",this.$el),this.layer.afterHide=()=>{!0===this.ctx.conf.editorTravel&&this.ctx.editorTravelBack()}),this.layer.show(),(()=>{__async(this,null,(function*(){var t;const i=yield this.ctx.getApi().user.loginStatus();i.is_admin&&!i.is_login&&(null==(t=this.layer)||t.hide(),this.firstShow=!0,this.ctx.checkAdmin({onSuccess:()=>{setTimeout((()=>{this.show(e)}),500)},onCancel:()=>{}}))}))})(),this.firstShow){this.$iframeWrap.innerHTML="",this.$iframe=we("");const t=Re(this.ctx,"/sidebar/"),i={pageKey:this.conf.pageKey,site:this.conf.site||"",user:JSON.stringify(this.ctx.user.data),time:+new Date};e.view&&(i.view=e.view),this.conf.darkMode&&(i.darkMode="1");const n=new URLSearchParams(i);this.iframeLoad(`${t}?${n.toString()}`),this.$iframeWrap.append(this.$iframe),this.firstShow=!1}else{const e=this.$iframe.src.includes("darkMode=1");this.conf.darkMode&&!e&&this.iframeLoad(`${this.$iframe.src}&darkMode=1`),!this.conf.darkMode&&e&&this.iframeLoad(this.$iframe.src.replace("&darkMode=1",""))}setTimeout((()=>{this.$el.style.transform="translate(0, 0)"}),100),setTimeout((()=>{this.ctx.updateNotifies([])}),0),this.ctx.trigger("sidebar-show")}))}hide(){var e;this.$el.style.transform="",null==(e=this.layer)||e.hide(),this.ctx.trigger("sidebar-hide")}iframeLoad(e){this.$iframe&&(this.$iframe.src=e,Ie(this.$iframeWrap),this.$iframe.onload=()=>{De(this.$iframeWrap)})}}function bt(e){return __async(this,null,(function*(){const t=e.ctx.conf.countEl;t&&document.querySelector(t)&&_t(e,{api:"page_comment",countEl:t});const i=e.pvAdd?yield e.ctx.getApi().page.pv():void 0,n=e.ctx.conf.pvEl;n&&document.querySelector(n)&&_t(e,{api:"page_pv",countEl:n,curtPageCount:i})}))}function _t(e,t){return __async(this,null,(function*(){let i={};const n=e.ctx.conf.pageKey;t.curtPageCount&&(i[n]=t.curtPageCount);let s=Array.from(document.querySelectorAll(t.countEl)).map((e=>e.getAttribute("data-page-key")||n)).filter((e=>void 0===i[e]));if(s=[...new Set(s)],s.length>0){const n=yield e.ctx.getApi().page.stat(t.api,s);i=__spreadValues(__spreadValues({},i),n)}document.querySelectorAll(t.countEl).forEach((e=>{const t=e.getAttribute("data-page-key")||n;e.innerHTML=`${Number(i[t]||0)}`}))}))}const xt=class{constructor(e){__publicField(this,"conf"),__publicField(this,"ctx"),__publicField(this,"$root"),__publicField(this,"instancePlugins",[]),this.conf=xt.HandelBaseConf(e),this.conf.el instanceof HTMLElement&&(this.$root=this.conf.el),this.ctx=new lt(this.conf,this.$root),this.initComponents()}initComponents(){this.initLocale(),this.initLayer(),function(e){try{if(!U.name)return}catch(s){return}const t=new U.Renderer,i=t.link;t.link=(e,n,s)=>{const r=null==e?void 0:e.startsWith(`${window.location.protocol}//${window.location.hostname}`);return i.call(t,e,n,s).replace(/^{const i=t||"plaintext";let n=e;return window.hljs?i&&window.hljs.getLanguage(i)&&(n=window.hljs.highlight(i,e).value):n=ve(e),`
      \n${n.replace(/&/g,"&")}\n
      `};const n=U;U.setOptions({renderer:t,pedantic:!1,gfm:!0,breaks:!0,smartLists:!0,smartypants:!0,xhtml:!1,sanitize:!1,silent:!0}),e.markedInstance=n}(this.ctx);const e={checkerLauncher:()=>{const e=new ut(this.ctx);this.ctx.setCheckerLauncher(e)},editor:()=>{const e=new yt(this.ctx);this.ctx.setEditor(e),this.$root.appendChild(e.$el)},list:()=>{const e=new ot(this.ctx);this.ctx.setList(e),this.$root.appendChild(e.$el),e.fetchComments(0)},sidebarLayer:()=>{const e=new $t(this.ctx);this.ctx.setSidebarLayer(e)},eventsDefault:()=>{this.initEventBind()}};Object.entries(e).forEach((([e,t])=>{xt.DisabledComponents.includes(e)||t()})),xt.Plugins.forEach((e=>{"function"==typeof e&&e(this.ctx)}))}static HandelBaseConf(e){const t=Be(xt.defaults,e);if("string"==typeof t.el&&t.el)try{const e=document.querySelector(t.el);if(!e)throw Error(`Target element "${t.el}" was not found.`);t.el=e}catch(i){throw console.error(i),new Error("Please check your Artalk `el` config.")}return t.server=t.server.replace(/\/$/,"").replace(/\/api\/?$/,""),t.pageKey||(t.pageKey=`${window.location.pathname}`),t.pageTitle||(t.pageTitle=`${document.title}`),t}initEventBind(){window.addEventListener("hashchange",(()=>{this.ctx.listHashGotoCheck()})),this.ctx.on("user-changed",(()=>{this.ctx.checkAdminShowEl(),this.ctx.listRefreshUI()}))}initLocale(){"auto"===this.conf.locale&&(this.conf.locale=navigator.language)}initLayer(){He.BodyOrgOverflow=document.body.style.overflow,He.BodyOrgPaddingRight=document.body.style.paddingRight}on(e,t){this.ctx.on(e,t,"external")}off(e,t){this.ctx.off(e,t,"external")}trigger(e,t){this.ctx.trigger(e,t,"external")}reload(){this.ctx.listReload()}setDarkMode(e){this.ctx.setDarkMode(e)}use(e){this.instancePlugins.push(e),"function"==typeof e&&e(this.ctx)}static use(e){this.Plugins.push(e)}static Use(e){this.use(e),console.warn("`Use(...)` is deprecated, replace it with lowercase `use(...)`.")}static LoadCountWidget(e){const t=this.HandelBaseConf(e);bt({ctx:new lt(t),pvAdd:!1})}};let vt=xt;return __publicField(vt,"ListLite",at),__publicField(vt,"defaults",{el:"",pageKey:"",pageTitle:"",server:"",site:"",placeholder:"",noComment:"",sendBtn:"",darkMode:!1,editorTravel:!0,flatMode:"auto",nestMax:2,nestSort:"DATE_ASC",emoticons:"https://cdn.jsdelivr.net/gh/ArtalkJS/Emoticons/grps/default.json",vote:!0,voteDown:!1,uaBadge:!0,listSort:!0,preview:!0,countEl:"#ArtalkCount",pvEl:"#ArtalkPV",gravatar:{default:"mp",mirror:"https://cravatar.cn/avatar/"},pagination:{pageSize:20,readMore:!0,autoLoad:!0},heightLimit:{content:300,children:400},imgUpload:!0,reqTimeout:15e3,versionCheck:!0,useBackendConf:!0,locale:"zh-CN"}),__publicField(vt,"Plugins",[e=>{e.conf.useBackendConf?e.on("list-loaded",(()=>{bt({ctx:e,pvAdd:!0})})):bt({ctx:e,pvAdd:!0})}]),__publicField(vt,"DisabledComponents",[]),vt}));