artalk 2.5.2 → 2.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Artalk.es.js +176 -123
- package/dist/Artalk.iife.js +1 -1
- package/dist/Artalk.js +1 -1
- package/dist/ArtalkLite.es.js +1 -1
- package/dist/ArtalkLite.iife.js +1 -1
- package/dist/ArtalkLite.js +1 -1
- package/package.json +2 -2
package/dist/ArtalkLite.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Artalk=function(t){"use strict";var e=Object.defineProperty,n=Object.defineProperties,i=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,o=(t,n,i)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[n]=i,l=(t,e)=>{for(var n in e||(e={}))a.call(e,n)&&o(t,n,e[n]);if(s)for(var n of s(e))r.call(e,n)&&o(t,n,e[n]);return t},c=(t,e)=>n(t,i(e)),d=(t,e,n)=>(o(t,"symbol"!=typeof e?e+"":e,n),n),h=(t,e,n)=>new Promise(((i,s)=>{var a=t=>{try{o(n.next(t))}catch(e){s(e)}},r=t=>{try{o(n.throw(t))}catch(e){s(e)}},o=t=>t.done?i(t.value):Promise.resolve(t.value).then(a,r);o((n=n.apply(t,e)).next())}));function u(t=""){const e=document.createElement("div");return e.innerHTML=t.trim(),e.firstElementChild||e}function p(t){return parseFloat(getComputedStyle(t,null).height.replace("px",""))}function m(t){const e=RegExp(`[?&]${t}=([^&]*)`).exec(window.location.search);return e&&decodeURIComponent(e[1].replace(/\+/g," "))}function g(t){const e=t.getBoundingClientRect();return{top:e.top+window.scrollY,left:e.left+window.scrollX}}function f(t,e){let n=t.toString();for(;n.length<e;)n=`0${n}`;return n}function y(t,e){try{const n=t.getTime(),i=(new Date).getTime()-n,s=Math.floor(i/864e5);if(0===s){const t=i%864e5,n=Math.floor(t/36e5);if(0===n){const n=t%36e5,i=Math.floor(n/6e4);if(0===i){const t=n%6e4,i=Math.round(t/1e3);return i<10?e.$t("now"):`${i} ${e.$t("seconds")}`}return`${i} ${e.$t("minutes")}`}return`${n} ${e.$t("hours")}`}return s<0?e.$t("now"):s<8?`${s} ${e.$t("days")}`:function(t){const e=f(t.getDate(),2),n=f(t.getMonth()+1,2);return`${f(t.getFullYear(),2)}-${n}-${e}`}(t)}catch(n){return console.error(n)," - "}}function $(){return h(this,null,(function*(){const t=navigator.userAgent;if(!navigator.userAgentData||!navigator.userAgentData.getHighEntropyValues)return t;const e=navigator.userAgentData;let n=null;try{n=yield e.getHighEntropyValues(["platformVersion"])}catch(s){return console.error(s),t}const i=Number(n.platformVersion.split(".")[0]);return"Windows"===e.platform&&i>=13?t.replace(/Windows NT 10.0/,"Windows NT 11.0"):"macOS"===e.platform&&i>=11?t.replace(/(Mac OS X \d+_\d+_\d+|Mac OS X)/,`Mac OS X ${n.platformVersion.replace(/\./g,"_")}`):t}))}function v(t){let e;try{e=new URL(t)}catch(n){return!1}return"http:"===e.protocol||"https:"===e.protocol}function k(t,e){return function(t,e){return`${t.replace(/\/$/,"")}/${e.replace(/^\//,"")}`}(t.conf.server,e)}function w(t,e){const n=t=>t&&"object"==typeof t;return n(t)&&n(e)?(Object.keys(e).forEach((i=>{const s=t[i],a=e[i];Array.isArray(s)&&Array.isArray(a)?t[i]=s.concat(a):n(s)&&n(a)?t[i]=w(l({},s),a):t[i]=a})),t):e}class b{constructor(t){d(this,"$el"),d(this,"ctx"),d(this,"conf"),this.ctx=t,this.conf=t.conf}$t(t,e={}){return this.ctx.$t(t,e)}}function x(t,e){let n=t.querySelector(":scope > .atk-loading");n||(n=u('<div class="atk-loading atk-fade-in" style="display: none;">\n <div class="atk-loading-spinner">\n <svg viewBox="25 25 50 50"><circle cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10"></circle></svg>\n </div>\n </div>'),(null==e?void 0:e.transparentBg)&&(n.style.background="transparent"),t.appendChild(n)),n.style.display="";const i=n.querySelector(".atk-loading-spinner");i&&(i.style.display="none",window.setTimeout((()=>{i.style.display=""}),500))}function C(t){const e=t.querySelector(":scope > .atk-loading");e&&(e.style.display="none")}function S(t,e=!0){const n=g(t).top+p(t)/2-document.documentElement.clientHeight/2;e?window.scroll({top:n>0?n:0,left:0}):window.scroll(0,n>0?n:0)}function E(t,e,n){const i=u(`<div class="atk-notify atk-fade-in" style="background-color: ${{s:"#57d59f",e:"#ff6f6c",w:"#ffc721",i:"#2ebcfc"}[n]}"><span class="atk-notify-content"></span></div>`);i.querySelector(".atk-notify-content").innerHTML=function(t){const e=document.createElement("div");return e.innerText=t,e.innerHTML}(e).replace("\n","<br/>"),t.appendChild(i);const s=()=>{i.classList.add("atk-fade-out"),setTimeout((()=>{i.remove()}),200)};let a;a=window.setTimeout((()=>{s()}),3e3),i.addEventListener("click",(()=>{s(),window.clearTimeout(a)}))}function T(t,e){!function(t,e,n="in"){t.classList.add(`atk-fade-${n}`);const i=()=>{t.classList.remove(`atk-fade-${n}`),t.removeEventListener("animationend",i),e&&e()};t.addEventListener("animationend",i)}(t,e,"in")}function L(t,e,n='<span class="atk-error-title">Artalk Error</span>'){let i=t.querySelector(".atk-error-layer");if(null===e)return void(null!==i&&i.remove());i||(i=u(`<div class="atk-error-layer">${n}<span class="atk-error-text"></span></div>`),t.appendChild(i));const s=i.querySelector(".atk-error-text");s.innerHTML="",null!==e&&(e instanceof HTMLElement?s.appendChild(e):s.innerText=e)}const A=class extends b{constructor(t,e,n){super(t),d(this,"name"),d(this,"$wrap"),d(this,"$mask"),d(this,"maskClickHideEnable",!0),d(this,"afterHide"),this.name=e;const{$wrap:i,$mask:s}=O();this.$wrap=i,this.$mask=s,this.$el=this.$wrap.querySelector(`[data-layer-name="${e}"].atk-layer-item`),null===this.$el&&(n?this.$el=n:(this.$el=u(),this.$el.classList.add("atk-layer-item"))),this.$el.setAttribute("data-layer-name",e),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(t){this.maskClickHideEnable=t}pageBodyScrollBarHide(){document.body.style.overflow="hidden";const t=parseInt(window.getComputedStyle(document.body,null).getPropertyValue("padding-right"),10);document.body.style.paddingRight=`${function(){const t=document.createElement("p");t.style.width="100%",t.style.height="200px";const e=document.createElement("div");e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.visibility="hidden",e.style.width="200px",e.style.height="150px",e.style.overflow="hidden",e.appendChild(t),document.body.appendChild(e);const n=t.offsetWidth;e.style.overflow="scroll";let i=t.offsetWidth;return n===i&&(i=e.clientWidth),document.body.removeChild(e),n-i}()+t||0}px`}pageBodyScrollBarShow(){document.body.style.overflow=A.BodyOrgOverflow,document.body.style.paddingRight=A.BodyOrgPaddingRight}newActionTimer(t,e){const n=()=>{t(),A.actionTimers=A.actionTimers.filter((t=>t.act!==n))},i=window.setTimeout((()=>n()),e);A.actionTimers.push({act:n,tid:i})}fireAllActionTimer(){A.actionTimers.forEach((t=>{clearTimeout(t.tid),t.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 M=A;function O(){let t=document.querySelector(".atk-layer-wrap");t||(t=u('<div class="atk-layer-wrap" style="display: none;"><div class="atk-layer-mask"></div></div>'),document.body.appendChild(t));const e=t.querySelector(".atk-layer-mask");return{$wrap:t,$mask:e}}d(M,"BodyOrgOverflow"),d(M,"BodyOrgPaddingRight"),d(M,"actionTimers",[]);const _=window.matchMedia("(prefers-color-scheme: dark)");let B;function P(t){R(t,t.conf.darkMode,!1)}function R(t,e,n=!0){const i=e=>{!function(t,e){e?t.$root.classList.add(I):t.$root.classList.remove(I);const{$wrap:n}=O();n&&(e?n.classList.add(I):n.classList.remove(I))}(t,e),n&&function(t,e){t.conf.darkMode=e}(t,e)};"auto"===e?(B||(B=t=>i(t.matches),_.addEventListener("change",B)),i(_.matches)):(B&&_.removeEventListener("change",B),i(e))}const I="atk-dark-mode";var U="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},D={"&":"&","<":"<",">":">",'"':""","'":"'"},q={"&":"&","<":"<",">":">",""":'"',"'":"'"},W=/(&|<|>|"|')/g,F=/[&<>"']/g;function H(t){return D[t]}function N(t){return q[t]}function j(t){return null==t?"":String(t).replace(F,H)}function z(t){return null==t?"":String(t).replace(W,N)}j.options=z.options={};var V={encode:j,escape:j,decode:z,unescape:z,version:"1.0.0-browser"};var Q=function t(e){for(var n,i,s=Array.prototype.slice.call(arguments,1);s.length;)for(i in n=s.shift())n.hasOwnProperty(i)&&("[object Object]"===Object.prototype.toString.call(e[i])?e[i]=t(e[i],n[i]):e[i]=n[i]);return e},G=function(t){return"string"==typeof t?t.toLowerCase():t};function K(t,e){return t[e]=!0,t}var Y=function(t){return t.reduce(K,{})},X={uris:Y(["background","base","cite","href","longdesc","src","usemap"])},J={voids:Y(["area","br","col","hr","img","wbr","input","base","basefont","link","meta"])},Z=V,tt=G,et=J,nt=/^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)\s*>/,it=/^<\s*\/\s*([\w:-]+)[^>]*>/,st=/([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g,at=/^</,rt=/^<\s*\//;var ot=V,lt=G,ct=X,dt=J;var ht=Q,ut=function(t,e){for(var n,i=function(){var t=[];return t.lastItem=function(){return t[t.length-1]},t}(),s=t;t;)a();function a(){n=!0,function(){"\x3c!--"===t.substr(0,4)?(i=t.indexOf("--\x3e"))>=0&&(e.comment&&e.comment(t.substring(4,i)),t=t.substring(i+3),n=!1):rt.test(t)?r(it,l):at.test(t)&&r(nt,o);var i;!function(){if(!n)return;var i,s=t.indexOf("<");s>=0?(i=t.substring(0,s),t=t.substring(s)):(i=t,t="");e.chars&&e.chars(i)}()}();var i=t===s;s=t,i&&(t="")}function r(e,i){var s=t.match(e);s&&(t=t.substring(s[0].length),s[0].replace(e,i),n=!1)}function o(t,n,s,a){var r={},o=tt(n),l=et.voids[o]||!!a;s.replace(st,(function(t,e,n,i,s){r[e]=void 0===n&&void 0===i&&void 0===s?void 0:Z.decode(n||i||s||"")})),l||i.push(o),e.start&&e.start(o,r,l)}function l(t,n){var s,a=0,r=tt(n);if(r)for(a=i.length-1;a>=0&&i[a]!==r;a--);if(a>=0){for(s=i.length-1;s>=a;s--)e.end&&e.end(i[s]);i.length=a}}l()},pt=function(t,e){var n,i=e||{};return o(),{start:function(t,e,r){var o=lt(t);if(n.ignoring)return void a(o);if(-1===(i.allowedTags||[]).indexOf(o))return void a(o);if(i.filter&&!i.filter({tag:o,attrs:e}))return void a(o);s("<"),s(o),Object.keys(e).forEach((function(t){var n=e[t],a=(i.allowedClasses||{})[o]||[],r=(i.allowedAttributes||{})[o]||[],l=lt(t);("class"===l&&-1===r.indexOf(l)?(n=n.split(" ").filter((function(t){return a&&-1!==a.indexOf(t)})).join(" ").trim()).length:-1!==r.indexOf(l)&&(!0!==ct.uris[l]||function(t){var e=t[0];if("#"===e||"/"===e)return!0;var n=t.indexOf(":");if(-1===n)return!0;var s=t.indexOf("?");if(-1!==s&&n>s)return!0;var a=t.indexOf("#");return-1!==a&&n>a||i.allowedSchemes.some(r);function r(e){return 0===t.indexOf(e+":")}}(n)))&&(s(" "),s(t),"string"==typeof n&&(s('="'),s(ot.encode(n)),s('"')))})),s(r?"/>":">")},end:function(t){var e=lt(t);-1!==(i.allowedTags||[]).indexOf(e)&&!1===n.ignoring?(s("</"),s(e),s(">")):r(e)},chars:function(t){!1===n.ignoring&&s(i.transformText?i.transformText(t):t)}};function s(e){t.push(e)}function a(t){dt.voids[t]||(!1===n.ignoring?n={ignoring:t,depth:1}:n.ignoring===t&&n.depth++)}function r(t){n.ignoring===t&&--n.depth<=0&&o()}function o(){n={ignoring:!1,depth:0}}},mt={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 gt(t,e,n){var i=[],s=!0===n?e:ht({},mt,e),a=pt(i,s);return ut(t,a),i.join("")}gt.defaults=mt;var ft=gt,yt={};({get exports(){return yt},set exports(t){yt=t}}).exports=function(){function t(t,e){return t(e={exports:{}},e.exports),e.exports}var e=t((function(t){var e=t.exports=function(){return new RegExp("(?:"+e.line().source+")|(?:"+e.block().source+")","gm")};e.line=function(){return/(?:^|\s)\/\/(.+?)$/gm},e.block=function(){return/\/\*([\S\s]*?)\*\//gm}})),n=["23AC69","91C132","F19726","E8552D","1AAB8E","E1147F","2980C1","1BA1E6","9FA0A0","F19726","E30B20","E30B20","A3338B"];function i(t){return'<span style="color: slategray">'+t+"</span>"}return function(t,s){void 0===s&&(s={});var a=s.colors;void 0===a&&(a=n);var r=0,o={},l=new RegExp("("+/[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af\u0400-\u04FF]+|\w+/.source+"|"+/</.source+")|("+e().source+")","gmi");return t.replace(l,(function(t,e,n){if(n)return i(n);if("<"===e)return"<";var s;o[e]?s=o[e]:(s=a[r],o[e]=s);var l='<span style="color: #'+s+'">'+e+"</span>";return r=++r%a.length,l}))}}();const $t=yt;let vt;function kt(){return vt}function wt(t,e){var n;let i=null==(n=kt())?void 0:n.parse(e);i||(i=e.replace(/```\s*([^]+?.*?[^]+?[^]+?)```/g,((t,e)=>`<pre><code>${$t(e)}</code></pre>`)).replace(/!\[(.*?)\]\((.*?)\)/g,((t,e,n)=>`<img src="${n}" alt="${e}" />`)).replace(/\[(.*?)\]\((.*?)\)/g,((t,e,n)=>`<a href="${n}" target="_blank">${e}</a>`)).replace(/\n/g,"<br>"));let s=ft(i,{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:t=>([["code",/^hljs\W+language-(.*)$/],["span",/^(hljs-.*)$/]].forEach((([e,n])=>{t.tag===e&&t.attrs.class&&!n.test(t.attrs.class)&&delete t.attrs.class})),"span"===t.tag&&t.attrs.style&&!/^color:(\W+)?#[0-9a-f]{3,6};?$/i.test(t.attrs.style)&&delete t.attrs.style,!0)});return t.markedReplacers.forEach((t=>{"function"==typeof t&&(s=t(s))})),s}const bt={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"},xt="ArtalkI18n",Ct={en:bt,"en-US":bt,"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 St(t){return t=t.replace(/^([a-zA-Z]+)(-[a-zA-Z]+)?$/,((t,e,n)=>e.toLowerCase()+(n||"").toUpperCase())),Ct[t]?Ct[t]:window[xt]&&window[xt][t]?window[xt][t]:Ct.en}let Et="en",Tt=St(Et);function Lt(t){t!==Et&&(Et=t,Tt="string"==typeof t?St(t):t)}function At(t,e={}){let n=(null==Tt?void 0:Tt[t])||t;return n=n.replace(/\{\s*(\w+?)\s*\}/g,((t,n)=>e[n]||"")),n}const Mt="2.5.2";const Ot=new class{constructor(){d(this,"ctx"),d(this,"data");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}}setContext(t){this.ctx=t}update(t={}){var e;Object.entries(t).forEach((([t,e])=>{this.data[t]=e})),window.localStorage.setItem("ArtalkUser",JSON.stringify(this.data)),null==(e=this.ctx)||e.trigger("user-changed",this.data)}logout(){this.update({token:"",isAdmin:!1})}checkHasBasicUserInfo(){return!!this.data.nick&&!!this.data.email}},_t=window||{},Bt=navigator||{};class Pt{constructor(t){d(this,"comment"),d(this,"$el"),d(this,"$main"),d(this,"$header"),d(this,"$headerNick"),d(this,"$headerBadgeWrap"),d(this,"$body"),d(this,"$content"),d(this,"$childrenWrap"),d(this,"$actions"),d(this,"voteBtnUp"),d(this,"voteBtnDown"),d(this,"$replyTo"),d(this,"$replyAt"),this.comment=t}get ctx(){return this.comment.ctx}get data(){return this.comment.getData()}get conf(){return this.comment.conf}get cConf(){return this.comment.getConf()}}function Rt(t){if(t.$headerNick=t.$el.querySelector(".atk-nick"),t.data.link){const e=u('<a target="_blank" rel="noreferrer noopener nofollow"></a>');e.innerText=t.data.nick,e.href=v(t.data.link)?t.data.link:`https://${t.data.link}`,t.$headerNick.append(e)}else t.$headerNick.innerText=t.data.nick}function It(t){t.$headerBadgeWrap=t.$el.querySelector(".atk-badge-wrap"),t.$headerBadgeWrap.innerHTML="";const e=t.data.badge_name,n=t.data.badge_color;if(e){const i=u('<span class="atk-badge"></span>');i.innerText=e.replace("管理员",t.ctx.$t("admin")),i.style.backgroundColor=n||"",t.$headerBadgeWrap.append(i)}if(t.data.is_pinned){const e=u(`<span class="atk-pinned-badge">${t.ctx.$t("pin")}</span>`);t.$headerBadgeWrap.append(e)}}function Ut(t){const e=t.$el.querySelector(".atk-date");e.innerText=t.comment.getDateFormatted(),e.setAttribute("data-atk-comment-date",String(+new Date(t.data.date)))}function Dt(t){if(!t.ctx.conf.uaBadge&&!t.data.ip_region)return;let e=t.$header.querySelector("atk-ua-wrap");if(e||(e=u('<span class="atk-ua-wrap"></span>'),t.$header.append(e)),e.innerHTML="",t.data.ip_region){const n=u('<span class="atk-region-badge"></span>');n.innerText=t.data.ip_region,e.append(n)}if(t.ctx.conf.uaBadge){const{browser:n,os:i}=t.comment.getUserUA();if(String(n).trim()){const t=u('<span class="atk-ua ua-browser"></span>');t.innerText=n,e.append(t)}if(String(i).trim()){const t=u('<span class="atk-ua ua-os"></span>');t.innerText=i,e.append(t)}}}class qt{constructor(t,e){d(this,"ctx"),d(this,"conf"),d(this,"$el"),d(this,"isLoading",!1),d(this,"msgRecTimer"),d(this,"msgRecTimerFunc"),d(this,"isConfirming",!1),d(this,"confirmRecTimer"),this.ctx=t,this.$el=u('<span class="atk-common-action-btn"></span>'),this.conf="object"!=typeof e?{text:e}:e,this.$el.innerText=this.getText(),this.conf.adminOnly&&this.$el.setAttribute("atk-only-admin-show","")}get isMessaging(){return!!this.msgRecTimer}appendTo(t){return t.append(this.$el),this}getText(){return"string"==typeof this.conf.text?this.conf.text:this.conf.text()}setClick(t){this.$el.onclick=e=>{if(e.stopPropagation(),!this.isLoading){if(this.conf.confirm&&!this.isMessaging){const t=()=>{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((()=>t()),5e3));this.confirmRecTimer&&window.clearTimeout(this.confirmRecTimer),t()}if(this.msgRecTimer)return this.fireMsgRecTimer(),void this.clearMsgRecTimer();t()}}}updateText(t){t&&(this.conf.text=t),this.setLoading(!1),this.$el.innerText=this.getText()}setLoading(t,e){this.isLoading!==t&&(this.isLoading=t,t?(this.$el.classList.add("atk-btn-loading"),this.$el.innerText=e||`${this.ctx.$t("loading")}...`):(this.$el.classList.remove("atk-btn-loading"),this.$el.innerText=this.getText()))}setError(t){this.setMsg(t,"atk-btn-error")}setWarn(t){this.setMsg(t,"atk-btn-warn")}setSuccess(t){this.setMsg(t,"atk-btn-success")}setMsg(t,e,n,i){this.setLoading(!1),e&&this.$el.classList.add(e),this.$el.innerText=t,this.setMsgRecTimer((()=>{this.$el.innerText=this.getText(),e&&this.$el.classList.remove(e),i&&i()}),n||2500)}setMsgRecTimer(t,e){this.fireMsgRecTimer(),this.clearMsgRecTimer(),this.msgRecTimerFunc=t,this.msgRecTimer=window.setTimeout((()=>{t(),this.clearMsgRecTimer()}),e)}fireMsgRecTimer(){this.msgRecTimerFunc&&this.msgRecTimerFunc()}clearMsgRecTimer(){this.msgRecTimer&&window.clearTimeout(this.msgRecTimer),this.msgRecTimer=void 0,this.msgRecTimerFunc=void 0}}function Wt(t){t.ctx.conf.vote&&(t.voteBtnUp=new qt(t.ctx,(()=>`${t.ctx.$t("voteUp")} (${t.data.vote_up||0})`)).appendTo(t.$actions),t.voteBtnUp.setClick((()=>{t.comment.getActions().vote("up")})),t.ctx.conf.voteDown&&(t.voteBtnDown=new qt(t.ctx,(()=>`${t.ctx.$t("voteDown")} (${t.data.vote_down||0})`)).appendTo(t.$actions),t.voteBtnDown.setClick((()=>{t.comment.getActions().vote("down")}))))}function Ft(t){if(!t.data.is_allow_reply)return;const e=u(`<span>${t.ctx.$t("reply")}</span>`);t.$actions.append(e),e.addEventListener("click",(e=>{e.stopPropagation(),t.cConf.onReplyBtnClick?t.cConf.onReplyBtnClick():t.ctx.replyComment(t.data,t.$el)}))}function Ht(t){const e=new qt(t.ctx,{text:()=>t.data.is_collapsed?t.ctx.$t("expand"):t.ctx.$t("collapse"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("collapsed",e)}))}function Nt(t){const e=new qt(t.ctx,{text:()=>t.data.is_pending?t.ctx.$t("pending"):t.ctx.$t("approved"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pending",e)}))}function jt(t){const e=new qt(t.ctx,{text:()=>t.data.is_pinned?t.ctx.$t("unpin"):t.ctx.$t("pin"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pinned",e)}))}function zt(t){const e=new qt(t.ctx,{text:t.ctx.$t("edit"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.ctx.editComment(t.data,t.$el)}))}function Vt(t){const e=new qt(t.ctx,{text:t.ctx.$t("delete"),confirm:!0,confirmText:t.ctx.$t("deleteConfirm"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminDelete(e)}))}const Qt={Avatar:function(t){const e=t.$el.querySelector(".atk-avatar"),n=u("<img />"),i=t.conf.avatarURLBuilder;if(n.src=i?i(t.data):t.comment.getGravatarURL(),t.data.link){const i=u('<a target="_blank" rel="noreferrer noopener nofollow"></a>');i.href=v(t.data.link)?t.data.link:`https://${t.data.link}`,i.append(n),e.append(i)}else e.append(n)},Header:function(t){Object.entries({renderNick:Rt,renderVerifyBadge:It,renderDate:Ut,renderUABadge:Dt}).forEach((([e,n])=>{n(t)}))},Content:function(t){if(!t.data.is_collapsed)return t.$content.innerHTML=t.comment.getContentMarked(),void t.$content.classList.remove("atk-hide","atk-collapsed");t.$content.classList.add("atk-hide","atk-type-collapsed");const e=u(`\n <div class="atk-collapsed">\n <span class="atk-text">${t.ctx.$t("collapsedMsg")}</span>\n <span class="atk-show-btn">${t.ctx.$t("expand")}</span>\n </div>`);t.$body.insertAdjacentElement("beforeend",e);const n=e.querySelector(".atk-show-btn");n.addEventListener("click",(e=>{e.stopPropagation(),t.$content.classList.contains("atk-hide")?(t.$content.innerHTML=t.comment.getContentMarked(),t.$content.classList.remove("atk-hide"),T(t.$content),n.innerHTML=t.ctx.$t("collapse")):(t.$content.innerHTML="",t.$content.classList.add("atk-hide"),n.innerHTML=t.ctx.$t("expand"))}))},ReplyAt:function(t){t.cConf.isFlatMode||0===t.data.rid||t.cConf.replyTo&&(t.$replyAt=u('<span class="atk-item atk-reply-at"><span class="atk-arrow"></span><span class="atk-nick"></span></span>'),t.$replyAt.querySelector(".atk-nick").innerText=`${t.cConf.replyTo.nick}`,t.$replyAt.onclick=()=>{t.comment.getActions().goToReplyComment()},t.$headerBadgeWrap.insertAdjacentElement("afterend",t.$replyAt))},ReplyTo:function(t){if(!t.cConf.isFlatMode)return;if(!t.cConf.replyTo)return;t.$replyTo=u(`\n <div class="atk-reply-to">\n <div class="atk-meta">${t.ctx.$t("reply")} <span class="atk-nick"></span>:</div>\n <div class="atk-content"></div>\n </div>`);const e=t.$replyTo.querySelector(".atk-nick");e.innerText=`@${t.cConf.replyTo.nick}`,e.onclick=()=>{t.comment.getActions().goToReplyComment()};let n=wt(t.ctx,t.cConf.replyTo.content);t.cConf.replyTo.is_collapsed&&(n=`[${t.ctx.$t("collapsed")}]`),t.$replyTo.querySelector(".atk-content").innerHTML=n,t.$body.prepend(t.$replyTo)},Pending:function(t){if(!t.data.is_pending)return;const e=u(`<div class="atk-pending">${t.ctx.$t("pendingMsg")}</div>`);t.$body.prepend(e)},Actions:function(t){Object.entries({renderVote:Wt,renderReply:Ft,renderCollapse:Ht,renderModerator:Nt,renderPin:jt,renderEdit:zt,renderDel:Vt}).forEach((([e,n])=>{n(t)}))}};function Gt(t,e){e.forEach((({el:e,max:n,imgContains:i})=>{const s=()=>{e&&(t.scrollable?function(t){if(!t.el)return;if(t.el.classList.contains(Xt))return;t.el.classList.add(Xt),t.el.style.height=`${t.maxHeight}px`}({el:e,maxHeight:n}):function(t){if(!t.el)return;if(!t.maxHeight)return;if(t.el.classList.contains(Kt))return;t.el.classList.add(Kt),t.el.style.height=`${t.maxHeight}px`,t.el.style.overflow="hidden";const e=u(`<div class="atk-height-limit-btn">${At("readMore")}</span>`);e.onclick=e=>{e.stopPropagation(),Yt(t.el),t.postBtnClick&&t.postBtnClick(e)},t.el.append(e)}({el:e,maxHeight:n,postBtnClick:t.postExpandBtnClick}))},a=()=>{e&&p(e)>n&&s()};a(),i&&e&&function(t,e){if(!t)return;const n=t.getElementsByTagName("img");if(!n.length)return;let i=n.length;for(let s=0;s<n.length;s++)n[s].complete?i--:n[s].addEventListener("load",(()=>{i--,0===i&&e()})),0===i&&e()}(e,(()=>a()))}))}const Kt="atk-height-limit";function Yt(t){t&&t.classList.contains(Kt)&&(t.classList.remove(Kt),Array.from(t.children).forEach((t=>{t.classList.contains("atk-height-limit-btn")&&t.remove()})),t.style.height="",t.style.overflow="")}const Xt="atk-height-limit-scroll";class Jt extends Pt{constructor(t){super(t)}render(){var t;return this.$el=u('<div class="atk-comment-wrap">\n <div class="atk-comment">\n <div class="atk-avatar"></div>\n <div class="atk-main">\n <div class="atk-header">\n <span class="atk-item atk-nick"></span>\n <span class="atk-badge-wrap"></span>\n <span class="atk-item atk-date"></span>\n </div>\n <div class="atk-body">\n <div class="atk-content"></div>\n </div>\n <div class="atk-footer">\n <div class="atk-actions"></div>\n </div>\n </div>\n </div>\n</div>\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("id",`atk-comment-${this.data.id}`),t=this,Object.entries(Qt).forEach((([e,n])=>{n(t)})),this.recoveryChildrenWrap(),this.$el}checkHeightLimit(){const t=this.ctx.conf.heightLimit;if(!t||!t.content||!t.children)return;const e=t.content,n=t.children;Gt({postExpandBtnClick:()=>{const t=this.comment.getChildren();1===t.length&&Yt(t[0].getRender().$content)},scrollable:t.scrollable},[{el:this.$content,max:e,imgContains:!0},{el:this.$replyTo,max:e,imgContains:!0},{el:this.$childrenWrap,max:n,imgContains:!1}])}heightLimitRemoveForChildren(){this.$childrenWrap&&Yt(this.$childrenWrap)}playFadeAnim(){T(this.comment.getRender().$el)}playFadeAnimForBody(){T(this.comment.getRender().$body)}getChildrenWrap(){return this.$childrenWrap}renderChildrenWrap(){return this.$childrenWrap||(this.$childrenWrap=u('<div class="atk-comment-children"></div>'),this.$main.append(this.$childrenWrap)),this.$childrenWrap}recoveryChildrenWrap(){this.$childrenWrap&&this.$main.append(this.$childrenWrap)}setUnread(t){t?this.$el.classList.add("atk-unread"):this.$el.classList.remove("atk-unread")}setOpenable(t){t?this.$el.classList.add("atk-openable"):this.$el.classList.remove("atk-openable")}setOpenURL(t){this.setOpenable(!0),this.$el.onclick=e=>{e.preventDefault(),window.open(t),this.cConf.openEvt&&this.cConf.openEvt()}}setOpenAction(t){this.setOpenable(!0),this.$el.onclick=e=>{e.preventDefault(),t()}}}class Zt{constructor(t){d(this,"comment"),this.comment=t}get ctx(){return this.comment.ctx}get data(){return this.comment.getData()}get cConf(){return this.comment.getConf()}vote(t){const e="up"===t?this.comment.getRender().voteBtnUp:this.comment.getRender().voteBtnDown;this.ctx.getApi().comment.vote(this.data.id,`comment_${t}`).then((t=>{var e,n;this.data.vote_up=t.up,this.data.vote_down=t.down,null==(e=this.comment.getRender().voteBtnUp)||e.updateText(),null==(n=this.comment.getRender().voteBtnDown)||n.updateText()})).catch((t=>{null==e||e.setError(this.ctx.$t("voteFail")),console.log(t)}))}adminEdit(t,e){if(e.isLoading)return;e.setLoading(!0,`${this.ctx.$t("editing")}...`);const n=l({},this.data);"collapsed"===t?n.is_collapsed=!n.is_collapsed:"pending"===t?n.is_pending=!n.is_pending:"pinned"===t&&(n.is_pinned=!n.is_pinned),this.ctx.getApi().comment.commentEdit(n).then((t=>{e.setLoading(!1),this.comment.setData(t),this.ctx.listRefreshUI()})).catch((t=>{console.error(t),e.setError(this.ctx.$t("editFail"))}))}adminDelete(t){t.isLoading||(t.setLoading(!0,`${this.ctx.$t("deleting")}...`),this.ctx.getApi().comment.commentDel(this.data.id,this.data.site_name).then((()=>{t.setLoading(!1),this.cConf.onDelete&&this.cConf.onDelete(this.comment)})).catch((e=>{console.error(e),t.setError(this.ctx.$t("deleteFail"))})))}goToReplyComment(){const t=window.location.hash,e=`#atk-comment-${this.data.rid}`;window.location.hash=e,e===t&&window.dispatchEvent(new Event("hashchange"))}}class te extends b{constructor(t,e,n){super(t),d(this,"renderInstance"),d(this,"actionInstance"),d(this,"data"),d(this,"cConf"),d(this,"parent"),d(this,"children",[]),d(this,"nestCurt"),d(this,"nestMax"),this.nestMax=t.conf.nestMax||3,this.cConf=n,this.data=l({},e),this.data.date=this.data.date.replace(/-/g,"/"),this.parent=null,this.nestCurt=1,this.actionInstance=new Zt(this),this.renderInstance=new Jt(this)}render(){const t=this.renderInstance.render();this.$el&&this.$el.replaceWith(t),this.$el=t,this.cConf.afterRender&&this.cConf.afterRender()}getActions(){return this.actionInstance}getRender(){return this.renderInstance}getData(){return this.data}setData(t){this.data=t,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(t,e="append"){t.parent=this,t.nestCurt=this.nestCurt+1,this.children.push(t);const n=this.getChildrenEl();"append"===e?n.append(t.getEl()):"prepend"===e&&n.prepend(t.getEl()),t.getRender().playFadeAnim(),t.getRender().checkHeightLimit()}getChildrenEl(){let t=this.getRender().getChildrenWrap();return t||(t=this.nestCurt<this.nestMax?this.getRender().renderChildrenWrap():this.parent.getChildrenEl()),t}getParents(){const t=[],e=n=>{n.parent&&(t.push(n.parent),e(n.parent))};return e(this),t}getEl(){return this.$el}getGravatarURL(){return t=this.ctx,e=this.data.email_encrypted,`${t.conf.gravatar.mirror.replace(/\/$/,"")}/${e}?d=${encodeURIComponent(t.conf.gravatar.default)}&s=80`;var t,e}getContentMarked(){return wt(this.ctx,this.data.content)}getDateFormatted(){return y(new Date(this.data.date),this.ctx)}getUserUA(){const t=function(t){const e=String(t||Bt.userAgent),n={os:"",osVersion:"",engine:"",browser:"",device:"",language:"",version:""},i={Trident:e.includes("Trident")||e.includes("NET CLR"),Presto:e.includes("Presto"),WebKit:e.includes("AppleWebKit"),Gecko:e.includes("Gecko/")},s={Safari:e.includes("Safari"),Chrome:e.includes("Chrome")||e.includes("CriOS"),IE:e.includes("MSIE")||e.includes("Trident"),Edge:e.includes("Edge")||e.includes("Edg"),Firefox:e.includes("Firefox")||e.includes("FxiOS"),"Firefox Focus":e.includes("Focus"),Chromium:e.includes("Chromium"),Opera:e.includes("Opera")||e.includes("OPR"),Vivaldi:e.includes("Vivaldi"),Yandex:e.includes("YaBrowser"),Kindle:e.includes("Kindle")||e.includes("Silk/"),360:e.includes("360EE")||e.includes("360SE"),UC:e.includes("UC")||e.includes(" UBrowser"),QQBrowser:e.includes("QQBrowser"),QQ:e.includes("QQ/"),Baidu:e.includes("Baidu")||e.includes("BIDUBrowser"),Maxthon:e.includes("Maxthon"),Sogou:e.includes("MetaSr")||e.includes("Sogou"),LBBROWSER:e.includes("LBBROWSER"),"2345Explorer":e.includes("2345Explorer"),TheWorld:e.includes("TheWorld"),MIUI:e.includes("MiuiBrowser"),Quark:e.includes("Quark"),Qiyu:e.includes("Qiyu"),Wechat:e.includes("MicroMessenger"),Taobao:e.includes("AliApp(TB"),Alipay:e.includes("AliApp(AP"),Weibo:e.includes("Weibo"),Douban:e.includes("com.douban.frodo"),Suning:e.includes("SNEBUY-APP"),iQiYi:e.includes("IqiyiApp")},a={Windows:e.includes("Windows"),Linux:e.includes("Linux")||e.includes("X11"),macOS:e.includes("Macintosh"),Android:e.includes("Android")||e.includes("Adr"),Ubuntu:e.includes("Ubuntu"),FreeBSD:e.includes("FreeBSD"),Debian:e.includes("Debian"),"Windows Phone":e.includes("IEMobile")||e.includes("Windows Phone"),BlackBerry:e.includes("BlackBerry")||e.includes("RIM"),MeeGo:e.includes("MeeGo"),Symbian:e.includes("Symbian"),iOS:e.includes("like Mac OS X"),"Chrome OS":e.includes("CrOS"),WebOS:e.includes("hpwOS")},r={Mobile:e.includes("Mobi")||e.includes("iPh")||e.includes("480"),Tablet:e.includes("Tablet")||e.includes("Pad")||e.includes("Nexus 7")};r.Mobile?r.Mobile=!e.includes("iPad"):s.Chrome&&e.includes("Edg")?(s.Chrome=!1,s.Edge=!0):_t.showModalDialog&&_t.chrome&&(s.Chrome=!1,s[360]=!0),n.device="PC",n.language=(()=>{const t=(Bt.browserLanguage||Bt.language).split("-");return t[1]&&(t[1]=t[1].toUpperCase()),t.join("_")})();const o={engine:i,browser:s,os:a,device:r};Object.entries(o).forEach((([t,e])=>{Object.entries(e).forEach((([e,i])=>{!0===i&&(n[t]=e)}))}));const l={Windows:()=>{const t=e.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"}[t]||t},Android:()=>e.replace(/^.*Android ([\d.]+);.*$/,"$1"),iOS:()=>e.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,"."),Debian:()=>e.replace(/^.*Debian\/([\d.]+).*$/,"$1"),"Windows Phone":()=>e.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2"),macOS:()=>e.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,"."),WebOS:()=>e.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")};n.osVersion="",l[n.os]&&(n.osVersion=l[n.os](),n.osVersion===e&&(n.osVersion=""));const c={Safari:()=>e.replace(/^.*Version\/([\d.]+).*$/,"$1"),Chrome:()=>e.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1"),IE:()=>e.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1"),Edge:()=>e.replace(/^.*(Edge|Edg|Edg[A-Z]{1})\/([\d.]+).*$/,"$2"),Firefox:()=>e.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1"),"Firefox Focus":()=>e.replace(/^.*Focus\/([\d.]+).*$/,"$1"),Chromium:()=>e.replace(/^.*Chromium\/([\d.]+).*$/,"$1"),Opera:()=>e.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1"),Vivaldi:()=>e.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1"),Yandex:()=>e.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1"),Kindle:()=>e.replace(/^.*Version\/([\d.]+).*$/,"$1"),Maxthon:()=>e.replace(/^.*Maxthon\/([\d.]+).*$/,"$1"),QQBrowser:()=>e.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1"),QQ:()=>e.replace(/^.*QQ\/([\d.]+).*$/,"$1"),Baidu:()=>e.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1"),UC:()=>e.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1"),Sogou:()=>e.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1"),"2345Explorer":()=>e.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1"),TheWorld:()=>e.replace(/^.*TheWorld ([\d.]+).*$/,"$1"),MIUI:()=>e.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1"),Quark:()=>e.replace(/^.*Quark\/([\d.]+).*$/,"$1"),Qiyu:()=>e.replace(/^.*Qiyu\/([\d.]+).*$/,"$1"),Wechat:()=>e.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1"),Taobao:()=>e.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1"),Alipay:()=>e.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1"),Weibo:()=>e.replace(/^.*weibo__([\d.]+).*$/,"$1"),Douban:()=>e.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1"),Suning:()=>e.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1"),iQiYi:()=>e.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")};return n.version="",c[n.browser]&&(n.version=c[n.browser](),n.version===e&&(n.version="")),n.version.indexOf(".")&&(n.version=n.version.substring(0,n.version.indexOf("."))),"iOS"===n.os&&e.includes("iPad")?n.os="iPadOS":"Edge"!==n.browser||e.includes("Edg")?"MIUI"===n.browser?n.os="Android":"Chrome"===n.browser&&Number(n.version)>27||"Opera"===n.browser&&Number(n.version)>12||"Yandex"===n.browser?n.engine="Blink":void 0===n.browser&&(n.browser="Unknow App"):n.engine="EdgeHTML",n}(this.data.ua);return{browser:`${t.browser} ${t.version}`,os:`${t.os} ${t.osVersion}`}}getConf(){return this.cConf}}class ee{constructor(t,e){d(this,"conf"),d(this,"total"),d(this,"$el"),d(this,"$input"),d(this,"inputTimer"),d(this,"$prevBtn"),d(this,"$nextBtn"),d(this,"page",1),this.total=t,this.conf=e,this.$el=u('<div class="atk-pagination-wrap">\n <div class="atk-pagination">\n <div class="atk-btn atk-btn-prev">Prev</div>\n <input type="text" class="atk-input" aria-label="Enter the number of page" />\n <div class="atk-btn atk-btn-next">Next</div>\n </div>\n </div>'),this.$input=this.$el.querySelector(".atk-input"),this.$input.value=`${this.page}`,this.$input.oninput=()=>this.input(),this.$input.onkeydown=t=>this.keydown(t),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(t,e){this.page=Math.ceil(t/this.pageSize)+1,this.total=e,this.setInput(this.page),this.checkDisabled()}setInput(t){this.$input.value=`${t}`}input(t=!1){window.clearTimeout(this.inputTimer);const e=this.$input.value.trim(),n=()=>{if(""===e)return void this.setInput(this.page);let t=Number(e);Number.isNaN(t)||t<1?this.setInput(this.page):(t>this.maxPage&&(this.setInput(this.maxPage),t=this.maxPage),this.change(t))};t?n():this.inputTimer=window.setTimeout((()=>n()),800)}prev(){const t=this.page-1;t<1||this.change(t)}next(){const t=this.page+1;t>this.maxPage||this.change(t)}change(t){this.page=t,this.conf.onChange(this.offset),this.setInput(t),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(t){const e=t.keyCode||t.which;if(38===e){const t=Number(this.$input.value)+1;if(t>this.maxPage)return;this.setInput(t),this.input()}else if(40===e){const t=Number(this.$input.value)-1;if(t<1)return;this.setInput(t),this.input()}else 13===e&&this.input(!0)}setLoading(t){t?x(this.$el):C(this.$el)}}const ne={createInstance(t){const e=new ee(t.total,{pageSize:t.pageSize,onChange:e=>h(this,null,(function*(){if(!0===t.list.conf.editorTravel&&t.list.ctx.editorTravelBack(),yield t.list.fetchComments(e),t.list.repositionAt){(t.list.scrollListenerAt||window).scroll({top:t.list.repositionAt?g(t.list.repositionAt).top:0,left:0})}}))});return[e,e.$el]},setLoading(t){this.instance.setLoading(t)},update(t,e){this.instance.update(t,e)},next(){this.instance.next()}};class ie{constructor(t){d(this,"conf"),d(this,"$el"),d(this,"$loading"),d(this,"$text"),d(this,"offset",0),d(this,"total",0),d(this,"origText","Load More"),this.conf=t,this.origText=this.conf.text||this.origText,this.$el=u(`<div class="atk-list-read-more" style="display: none;">\n <div class="atk-list-read-more-inner">\n <div class="atk-loading-icon" style="display: none;"></div>\n <span class="atk-text">${this.origText}</span>\n </div>\n </div>`),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(t){this.$loading.style.display=t?"":"none",this.$text.style.display=t?"none":""}showErr(t){this.setLoading(!1),this.$text.innerText=t,this.$el.classList.add("atk-err"),window.setTimeout((()=>{this.$text.innerText=this.origText,this.$el.classList.remove("atk-err")}),2e3)}update(t,e){this.offset=t,this.total=e,this.checkDisabled()}checkDisabled(){this.hasMore?this.show():this.hide()}}const se={pagination:ne,"read-more":{createInstance(t){const e=new ie({pageSize:t.pageSize,onClick:e=>h(this,null,(function*(){yield t.list.fetchComments(e)})),text:At("loadMore")});if(t.list.conf.pagination.autoLoad){const n=t.list.scrollListenerAt||document;this.autoLoadScrollEvent&&n.removeEventListener("scroll",this.autoLoadScrollEvent),this.autoLoadScrollEvent=()=>{if("read-more"!==t.mode||!(null==e?void 0:e.hasMore)||t.list.getLoading())return;const n=t.list.$el.querySelector(".atk-list-comments-wrap > .atk-comment-wrap:nth-last-child(3)");n&&function(t,e=document.documentElement){const n=e.clientHeight,i=e.scrollTop,s=i+n,a=t.getBoundingClientRect();return a.top+i+a.height<=s}(n,t.list.scrollListenerAt)&&e.click()},n.addEventListener("scroll",this.autoLoadScrollEvent)}return[e,e.$el]},setLoading(t){this.instance.setLoading(t)},update(t,e){this.instance.update(t,e)},showErr(t){this.instance.showErr(t)},next(){this.instance.click()}}};class ae{constructor(t){d(this,"conf"),this.conf=t,this.init()}getAdaptor(){return se[this.conf.mode]}init(){const t=this.getAdaptor(),[e,n]=t.createInstance(this.conf);t.instance=e,t.el=n,this.conf.list.$el.append(t.el)}setLoading(t){this.getAdaptor().setLoading(t)}update(t,e){this.getAdaptor().update(t,e)}getEl(){return this.getAdaptor().el}showErr(t){const e=this.getAdaptor(),n=e.showErr;n&&n.bind(e)(t)}setMode(t){t!==this.conf.mode&&(this.getEl().remove(),this.conf.mode=t,this.init())}next(){this.getAdaptor().next()}}function re(t,e,n){const i=function(t,e){const n=t.split("."),i=e.split(".");for(let s=0;s<3;s++){const t=Number(n[s]),e=Number(i[s]);if(t>e)return 1;if(e>t)return-1;if(!Number.isNaN(t)&&Number.isNaN(e))return 1;if(Number.isNaN(t)&&!Number.isNaN(e))return-1}return 0}(e,n);if(0!==i){const s=u(`<div>请更新 Artalk ${At(i<0?"frontend":"backend")}以获得完整体验 (<a href="https://artalk.js.org/" target="_blank">帮助文档</a>)<br/><br/><span style="color: var(--at-color-meta);">当前版本:${At("frontend")} ${e} / ${At("backend")} ${n}</span><br/><br/></div>`),a=u('<span style="cursor:pointer">忽略</span>');return a.onclick=()=>{L(t.$el.parentElement,null),t.ctx.conf.versionCheck=!1,t.fetchComments(0)},s.append(a),L(t.$el.parentElement,s,'<span class="atk-warn-title">Artalk Warn</span>'),!0}return!1}function oe(t){const{$dropdownWrap:e,dropdownList:n}=t;if(e.querySelector(".atk-dropdown"))return;e.classList.add("atk-dropdown-wrap"),e.append(u('<span class="atk-arrow-down-icon"></span>'));let i=0;const s=u('<ul class="atk-dropdown atk-fade-in"></ul>');n.forEach(((t,e)=>{const n=t[0],a=t[1],r=u('<li class="atk-dropdown-item"><span></span></li>'),o=r.querySelector("span");o.innerText=n,o.onclick=()=>{((t,e,n,a)=>{a(),i=t,s.querySelectorAll(".active").forEach((t=>{t.classList.remove("active")})),e.classList.add("active"),s.style.display="none",setTimeout((()=>{s.style.display=""}),80)})(e,r,0,a)},s.append(r),e===i&&r.classList.add("active")})),e.append(s)}const le={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,scrollable:!1},imgUpload:!0,reqTimeout:15e3,versionCheck:!0,useBackendConf:!0,locale:"zh-CN"};function ce(t){const e=w(le,t);if("string"==typeof e.el&&e.el)try{const t=document.querySelector(e.el);if(!t)throw Error(`Target element "${e.el}" was not found.`);e.el=t}catch(n){throw console.error(n),new Error("Please check your Artalk `el` config.")}return e.server=e.server.replace(/\/$/,"").replace(/\/api\/?$/,""),e.pageKey||(e.pageKey=`${window.location.pathname}`),e.pageTitle||(e.pageTitle=`${document.title}`),"auto"===e.locale&&(e.locale=navigator.language),e}function de(t){const e=["el","pageKey","pageTitle","server","site","darkMode"];return Object.keys(t).forEach((n=>{e.includes(n)&&delete t[n]})),t.emoticons&&"string"==typeof t.emoticons&&(t.emoticons=t.emoticons.trim(),t.emoticons.startsWith("[")||t.emoticons.startsWith("{")?t.emoticons=JSON.parse(t.emoticons):"false"===t.emoticons&&(t.emoticons=!1)),t}le.vote=!1,le.uaBadge=!1,le.emoticons=!1;class he extends b{constructor(t){super(t),d(this,"$commentsWrap"),d(this,"data"),d(this,"isLoading",!1),d(this,"confLoaded",!1),d(this,"noCommentText"),d(this,"_nestSortBy"),d(this,"_flatMode"),d(this,"_pageMode"),d(this,"pgHolder"),d(this,"_pageSize"),d(this,"scrollListenerAt"),d(this,"repositionAt"),d(this,"renderComment"),d(this,"paramsEditor"),d(this,"onAfterLoad"),d(this,"unread",[]),d(this,"unreadHighlight"),this.$el=u('<div class="atk-list-lite">\n <div class="atk-list-comments-wrap"></div>\n </div>'),this.$commentsWrap=this.$el.querySelector(".atk-list-comments-wrap"),window.setInterval((()=>{this.$el.querySelectorAll("[data-atk-comment-date]").forEach((t=>{const e=t.getAttribute("data-atk-comment-date");t.innerText=y(new Date(Number(e)),this.ctx)}))}),3e4),this.ctx.on("conf-loaded",(()=>{}))}get nestSortBy(){return this._nestSortBy||this.ctx.conf.nestSort||"DATE_ASC"}set nestSortBy(t){this._nestSortBy=t}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(t){this._flatMode=t}get pageMode(){return this._pageMode||(this.conf.pagination.readMore?"read-more":"pagination")}set pageMode(t){var e;this._pageMode=t,null==(e=this.pgHolder)||e.setMode(this._pageMode)}get pageSize(){return this._pageSize||this.conf.pagination.pageSize}set pageSize(t){this._pageSize=t}getData(){return this.data}clearData(){this.data=void 0}getLoading(){return this.isLoading}getCommentsWrapEl(){return this.$commentsWrap}setLoading(t,e=!1){var n;this.isLoading=t,e?function(t,e){t?x(e):C(e)}(t,this.$el):null==(n=this.pgHolder)||n.setLoading(t)}fetchComments(t){return h(this,null,(function*(){if(this.isLoading)return;const e=0===t,n=t=>this.setLoading(t,e);let i;n(!0),this.ctx.trigger("list-load"),("read-more"===this.pageMode&&e||"pagination"===this.pageMode)&&this.ctx.clearAllComments();try{i=yield this.ctx.getApi().comment.get(t,this.pageSize,this.flatMode,this.paramsEditor)}catch(s){throw this.onError(s.msg||String(s),t,s.data),s}finally{n(!1)}L(this.$el,null);try{this.onLoad(i,t)}catch(s){throw this.onError(String(s),t),s}finally{n(!1)}}))}onLoad(t,e){if(this.data=t,!this.confLoaded){const e=de(t.conf.frontend_conf);this.conf.useBackendConf?this.ctx.updateConf(e):this.ctx.updateConf({}),this.confLoaded=!0}this.ctx.conf.versionCheck&&re(this,Mt,t.api_version.version)||(this.importComments(t.comments),this.refreshPagination(e,this.flatMode?t.total:t.total_roots),this.refreshUI(),this.ctx.updateNotifies(t.unread||[]),this.ctx.trigger("list-loaded"),this.onAfterLoad&&this.onAfterLoad(t))}refreshPagination(t,e){var n;this.pgHolder||(this.pgHolder=new ae({list:this,mode:this.pageMode,pageSize:this.pageSize,total:e})),null==(n=this.pgHolder)||n.update(t,e)}onError(t,e,n){var i;this.confLoaded||this.ctx.updateConf({}),t=String(t),console.error(t),0===e||"read-more"!==this.pageMode?L(this.$el,function(t,e,n){const i=u(`<span>${e},${At("listLoadFailMsg")}<br/></span>`),s=u(`<span style="cursor:pointer;">${At("listRetry")}</span>`);s.onclick=()=>t.fetchComments(0),i.appendChild(s);const a=u('<span atk-only-admin-show> | <span style="cursor:pointer;">打开控制台</span></span>');i.appendChild(a),Ot.data.isAdmin||a.classList.add("atk-hide");let r="";if(null==n?void 0:n.err_no_site){const e={create_name:t.ctx.conf.site,create_urls:`${window.location.protocol}//${window.location.host}`};r=`sites|${JSON.stringify(e)}`}return a.onclick=()=>t.ctx.showSidebar({view:r}),i}(this,t,n)):null==(i=this.pgHolder)||i.showErr(this.$t("loadFail"))}refreshUI(){!function(t){const e=t.ctx.getCommentList().length<=0;let n=t.getCommentsWrapEl().querySelector(".atk-list-no-comment");e?n||(n=u('<div class="atk-list-no-comment"></div>'),n.innerHTML=t.noCommentText||t.ctx.conf.noComment||t.ctx.$t("noComment"),t.getCommentsWrapEl().appendChild(n)):null==n||n.remove(),t.ctx.checkAdminShowEl()}(this)}reload(){this.fetchComments(0)}createComment(t,e){e||(e=this.ctx.getCommentDataList());const n=new te(this.ctx,t,{isFlatMode:this.flatMode,afterRender:()=>{this.renderComment&&this.renderComment(n)},onDelete:t=>{this.ctx.deleteComment(t),this.refreshUI()},replyTo:t.rid?e.find((e=>e.id===t.rid)):void 0});return n.render(),this.ctx.getCommentList().push(n),n}importComments(t){this.flatMode?t.forEach((e=>{this.putCommentFlatMode(e,t,"append")})):this.importCommentsNest(t)}importCommentsNest(t){const e=function(t,e="DATE_DESC",n=2){const i=[];t.filter((t=>0===t.rid)).forEach((e=>{const s={id:e.id,comment:e,children:[],level:1};s.parent=s,i.push(s),function e(i){const s=t.filter((t=>t.rid===i.id));0!==s.length&&(i.level>=n&&(i=i.parent),s.forEach((t=>{const n={id:t.id,comment:t,children:[],parent:i,level:i.level+1};i.children.push(n),e(n)})))}(s)}));const s=(n,i)=>{let s=n.id-i.id;return"DATE_ASC"===e?s=+new Date(n.comment.date)-+new Date(i.comment.date):"DATE_DESC"===e?s=+new Date(i.comment.date)-+new Date(n.comment.date):"SRC_INDEX"===e?s=t.indexOf(n.comment)-t.indexOf(i.comment):"VOTE_UP_DESC"===e&&(s=i.comment.vote_up-n.comment.vote_up),s};return function t(e){e.forEach((e=>{e.children=e.children.sort(s),t(e.children)}))}(i),i}(t,this.nestSortBy,this.conf.nestMax);e.forEach((e=>{const n=this.createComment(e.comment,t);this.$commentsWrap.appendChild(n.getEl()),n.getRender().playFadeAnim();const i=this;!function e(n,s){s.children.forEach((s=>{const a=s.comment,r=i.createComment(a,t);n.putChild(r),e(r,s)}))}(n,e),n.getRender().checkHeightLimit()}))}putCommentFlatMode(t,e,n){t.is_collapsed&&(t.is_allow_reply=!1);const i=this.createComment(t,e);return t.visible&&("append"===n&&this.$commentsWrap.append(i.getEl()),"prepend"===n&&this.$commentsWrap.prepend(i.getEl()),i.getRender().playFadeAnim()),i.getRender().checkHeightLimit(),i}insertComment(t){if(this.flatMode){S(this.putCommentFlatMode(t,this.ctx.getCommentDataList(),"prepend").getEl())}else{const e=this.createComment(t);if(0===t.rid)this.$commentsWrap.prepend(e.getEl());else{const n=this.ctx.findComment(t.rid);n&&(n.putChild(e,"DATE_ASC"===this.nestSortBy?"append":"prepend"),e.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()})))}e.getRender().checkHeightLimit(),S(e.getEl()),e.getRender().playFadeAnim()}this.data&&(this.data.total+=1),this.refreshUI(),this.ctx.trigger("list-loaded"),this.ctx.trigger("list-inserted",t)}updateComment(t){const e=this.ctx.findComment(t.id);e&&e.setData(t)}updateUnread(t){this.unread=t,!0===this.unreadHighlight&&this.ctx.getCommentList().forEach((t=>{const e=this.unread.find((e=>e.comment_id===t.getID()));e?(t.getRender().setUnread(!0),t.getRender().setOpenAction((()=>{window.open(e.read_link),this.unread=this.unread.filter((e=>e.comment_id!==t.getID())),this.ctx.updateNotifies(this.unread)}))):t.getRender().setUnread(!1)}))}}class ue extends he{constructor(t){const e=u('<div class="atk-list">\n <div class="atk-list-header">\n <div class="atk-comment-count">\n <div class="atk-text"></div>\n </div>\n <div class="atk-right-action">\n <span data-action="admin-close-comment" class="atk-hide" atk-only-admin-show></span>\n <span data-action="open-sidebar" class="atk-hide atk-on">\n <span class="atk-unread-badge" style="display: none;"></span>\n <div class="atk-text"></div>\n </span>\n </div>\n </div>\n <div class="atk-list-body"></div>\n <div class="atk-list-footer">\n <div class="atk-copyright"></div>\n </div>\n</div>\n');super(t),d(this,"$closeCommentBtn"),d(this,"$openSidebarBtn"),d(this,"$unreadBadge"),d(this,"$commentCount"),d(this,"$commentCountNum"),d(this,"$dropdownWrap"),d(this,"goToCommentFounded",!1),d(this,"goToCommentDelay",!0),e.querySelector(".atk-list-body").append(this.$el),this.$el=e,this.repositionAt=this.$el,this.initListActionBtn();this.$commentCount=this.$el.querySelector(".atk-comment-count");const n=()=>{this.$commentCount.innerHTML=this.$t("counter",{count:'<span class="atk-comment-count-num">0</span>'}),this.$commentCountNum=this.$commentCount.querySelector(".atk-comment-count-num")};n(),this.$el.querySelector(".atk-copyright").innerHTML=`Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${Mt}">Artalk</a>`,this.ctx.on("conf-loaded",(()=>{n(),this.refreshUI()}))}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 t;super.refreshUI(),this.$commentCountNum.innerText=String(Number(null==(t=this.data)?void 0:t.total)||0),Ot.data.nick&&Ot.data.email?this.$openSidebarBtn.classList.remove("atk-hide"):this.$openSidebarBtn.classList.add("atk-hide"),this.$openSidebarBtn.querySelector(".atk-text").innerText=Ot.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():function(t){var e,n;const{$dropdownWrap:i}=t;i.classList.remove("atk-dropdown-wrap"),null==(e=i.querySelector(".atk-arrow-down-icon"))||e.remove(),null==(n=i.querySelector(".atk-dropdown"))||n.remove()}({$dropdownWrap:this.$commentCount})}onLoad(t,e){super.onLoad(t,e),this.goToCommentFounded||this.checkGoToCommentByUrlHash(),!0===this.ctx.conf.editorTravel&&this.ctx.editorTravelBack()}checkGoToCommentByUrlHash(){var t;let e=Number(m("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 n=this.ctx.findComment(e);if(!n)return void(null==(t=this.pgHolder)||t.next());const i=m("atk_notify_key");i&&this.ctx.getApi().user.markRead(e,i).then((()=>{this.unread=this.unread.filter((t=>t.comment_id!==e)),this.updateUnread(this.unread)})),n.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()}));const s=()=>{S(n.getEl(),!1),n.getEl().classList.remove("atk-flash-once"),window.setTimeout((()=>{n.getEl().classList.add("atk-flash-once")}),150)};this.goToCommentDelay?window.setTimeout((()=>s()),350):s(),this.goToCommentFounded=!0,this.goToCommentDelay=!0}adminPageEditSave(){this.data&&this.data.page&&(this.ctx.editorShowLoading(),this.ctx.getApi().page.pageEdit(this.data.page).then((t=>{this.data&&(this.data.page=l({},t)),this.refreshUI()})).catch((t=>{this.ctx.editorShowNotify(`${this.$t("editFail")}: ${t.msg||String(t)}`,"e")})).finally((()=>{this.ctx.editorHideLoading()})))}showUnreadBadge(t){t>0?(this.$unreadBadge.innerText=`${Number(t||0)}`,this.$unreadBadge.style.display="block"):this.$unreadBadge.style.display="none"}initDropdown(){const t=t=>{this.paramsEditor=t,this.fetchComments(0)};oe({$dropdownWrap:this.$commentCount,dropdownList:[[this.$t("sortLatest"),()=>{t((t=>{t.sort_by="date_desc"}))}],[this.$t("sortBest"),()=>{t((t=>{t.sort_by="vote"}))}],[this.$t("sortOldest"),()=>{t((t=>{t.sort_by="date_asc"}))}],[this.$t("sortAuthor"),()=>{t((t=>{t.view_only_admin=!0}))}]]})}updateUnread(t){super.updateUnread(t),this.showUnreadBadge((null==t?void 0:t.length)||0)}}class pe{constructor(t,e){d(this,"conf"),d(this,"$root"),d(this,"markedReplacers",[]),d(this,"commentList",[]),d(this,"eventList",[]),this.conf=t,this.$root=e||document.createElement("div"),this.$root.classList.add("artalk"),this.$root.innerHTML=""}inject(t,e){this[t]=e}get(t){return this[t]}getApi(){return this.api}getCommentList(){return this.commentList}getCommentDataList(){return this.commentList.map((t=>t.getData()))}findComment(t){return this.commentList.find((e=>e.getData().id===t))}deleteComment(t){let e;if("number"==typeof t){const n=this.findComment(t);if(!n)throw Error(`Comment ${t} cannot be found`);e=n}else e=t;if(e.getEl().remove(),this.commentList.splice(this.commentList.indexOf(e),1),this.list){const t=this.list.getData();t&&(t.total-=1),this.list.refreshUI()}}clearAllComments(){this.list&&(this.list.getCommentsWrapEl().innerHTML="",this.list.clearData()),this.commentList=[]}insertComment(t){var e;null==(e=this.list)||e.insertComment(t)}updateComment(t){var e;null==(e=this.list)||e.updateComment(t)}replyComment(t,e,n){this.editor.setReply(t,e,n)}cancelReplyComment(){this.editor.cancelReply()}editComment(t,e){this.editor.setEditComment(t,e)}cancelEditComment(){this.editor.cancelEditComment()}updateNotifies(t){var e;null==(e=this.list)||e.updateUnread(t)}listReload(){var t;null==(t=this.list)||t.reload()}reload(){this.listReload()}listRefreshUI(){var t;null==(t=this.list)||t.refreshUI()}listHashGotoCheck(){if(!(this.list&&this.list instanceof ue))return;const t=this.list;t.goToCommentDelay=!1,t.checkGoToCommentByUrlHash()}editorOpen(){this.editor.open()}editorClose(){this.editor.close()}editorShowLoading(){this.editor.showLoading()}editorHideLoading(){this.editor.hideLoading()}editorShowNotify(t,e){this.editor.showNotify(t,e)}editorTravel(t){this.editor.travel(t)}editorTravelBack(){this.editor.travelBack()}showSidebar(t){this.sidebarLayer.show(t)}hideSidebar(){this.sidebarLayer.hide()}checkAdmin(t){this.checkerLauncher.checkAdmin(t)}checkCaptcha(t){this.checkerLauncher.checkCaptcha(t)}checkAdminShowEl(){const t=[];this.$root.querySelectorAll("[atk-only-admin-show]").forEach((e=>t.push(e)));const{$wrap:e}=O();e&&e.querySelectorAll("[atk-only-admin-show]").forEach((e=>t.push(e)));const n=document.querySelector(".atk-sidebar");n&&n.querySelectorAll("[atk-only-admin-show]").forEach((e=>t.push(e))),t.forEach((t=>{this.user.data.isAdmin?t.classList.remove("atk-hide"):t.classList.add("atk-hide")}))}on(t,e,n="internal"){this.eventList.push({name:t,handler:e,scope:n})}off(t,e,n="internal"){this.eventList=this.eventList.filter((i=>e?!(i.name===t&&i.handler===e&&i.scope===n):!(i.name===t&&i.scope===n)))}trigger(t,e,n){this.eventList.filter((e=>e.name===t&&(!n||e.scope===n))).map((t=>t.handler)).forEach((t=>t(e)))}$t(t,e={}){return At(t,e)}setDarkMode(t){R(this,t)}updateConf(t){this.conf=w(this.conf,t),this.trigger("conf-loaded")}getMarkedInstance(){return kt()}}class me{constructor(t,e){return d(this,"ctx"),d(this,"$el"),d(this,"$content"),d(this,"$actions"),this.ctx=t,this.$el=u('<div class="atk-layer-dialog-wrap">\n <div class="atk-layer-dialog">\n <div class="atk-layer-dialog-content"></div>\n <div class="atk-layer-dialog-actions"></div>\n </div>\n </div>'),this.$actions=this.$el.querySelector(".atk-layer-dialog-actions"),this.$content=this.$el.querySelector(".atk-layer-dialog-content"),this.$content.appendChild(e),this}setYes(t){const e=u(`<button data-action="confirm">${this.ctx.$t("confirm")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}setNo(t){const e=u(`<button data-action="cancel">${this.ctx.$t("cancel")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}onBtnClick(t){return e=>{const n=t(e.currentTarget,this);void 0!==n&&!0!==n||this.$el.remove()}}}function ge(t){const e=u('<div class="atk-checker-iframe-wrap"></div>'),n=u('<iframe class="atk-fade-in"></iframe>');n.style.display="none",x(e,{transparentBg:!0}),n.src=`${t.getCtx().conf.server}/api/captcha/get?t=${+new Date}`,n.onload=()=>{n.style.display="",C(e)},e.append(n);const i=u('<div class="atk-close-btn"><i class="atk-icon atk-icon-close"></i></div>');e.append(i),t.hideInteractInput();let s=!1;return function e(){return h(this,null,(function*(){var n;if(yield(n=1e3,new Promise((t=>{window.setTimeout((()=>{t(null)}),n)}))),s)return;let i=!1;try{i=(yield t.getCtx().getApi().captcha.captchaStatus()).is_pass}catch(a){i=!1}i?t.triggerSuccess():e()}))}(),i.onclick=()=>{s=!0,t.cancel()},e}const fe={request:(t,e)=>t.getApi().captcha.captchaCheck(e),body:t=>t.get("iframe")?ge(t):function(t){const e=u(`<span><img class="atk-captcha-img" src="${t.get("img_data")||""}">${t.getCtx().$t("captchaCheck")}</span>`);return e.querySelector(".atk-captcha-img").onclick=()=>{const n=e.querySelector(".atk-captcha-img");t.getApi().captcha.captchaGet().then((t=>{n.setAttribute("src",t)})).catch((t=>{console.error("Failed to get captcha image ",t)}))},e}(t),onSuccess(t,e,n,i){t.set("val",n)},onError(t,e,n,i){i.querySelector(".atk-captcha-img").click(),i.querySelector('input[type="text"]').value=""}},ye={inputType:"password",request(t,e){const n={name:Ot.data.nick,email:Ot.data.email,password:e};return(()=>h(this,null,(function*(){return(yield t.getApi().user.login(n.name,n.email,n.password)).token})))()},body:t=>u(`<span>${t.getCtx().$t("adminCheck")}</span>`),onSuccess(t,e,n,i){Ot.update({isAdmin:!0,token:e}),t.getCtx().trigger("user-changed",Ot.data),t.getCtx().listReload()},onError(t,e,n,i){}};class $e{constructor(t){d(this,"ctx"),d(this,"launched",[]),this.ctx=t}checkCaptcha(t){this.fire(fe,t,(e=>{e.set("img_data",t.imgData),e.set("iframe",t.iframe)}))}checkAdmin(t){this.fire(ye,t)}fire(t,e,n){if(this.launched.includes(t))return;this.launched.push(t);const i=new M(this.ctx,`checker-${(new Date).getTime()}`);i.setMaskClickHide(!1),i.show();const s={};let a=!1;const r={set:(t,e)=>{s[t]=e},get:t=>s[t],getCtx:()=>this.ctx,getApi:()=>this.ctx.getApi(),getLayer:()=>i,hideInteractInput:()=>{a=!0},triggerSuccess:()=>{this.close(t,i),t.onSuccess&&t.onSuccess(r,"","",o),e.onSuccess&&e.onSuccess("",d.$el)},cancel:()=>{this.close(t,i),e.onCancel&&e.onCancel()}};n&&n(r);const o=u();o.appendChild(t.body(r));const l=u(`<input id="check" type="${t.inputType||"text"}" autocomplete="off" required placeholder="">`);let c;o.appendChild(l),setTimeout((()=>l.focus()),80),l.onkeyup=t=>{"Enter"!==t.key&&13!==t.keyCode||(t.preventDefault(),i.getEl().querySelector('button[data-action="confirm"]').click())};const d=new me(this.ctx,o);d.setYes((n=>{const s=l.value.trim();c||(c=n.innerText);const a=()=>{n.innerText=c||"",n.classList.remove("error")};return n.innerText=`${this.ctx.$t("loading")}...`,t.request(r,s).then((n=>{this.close(t,i),t.onSuccess&&t.onSuccess(r,n,s,o),e.onSuccess&&e.onSuccess(s,d.$el)})).catch((e=>{var i;i=String(e.msg||String(e)),n.innerText=i,n.classList.add("error"),t.onError&&t.onError(r,e,s,o);const c=setTimeout((()=>a()),3e3);l.onfocus=()=>{a(),clearTimeout(c)}})),!1})),d.setNo((()=>(this.close(t,i),e.onCancel&&e.onCancel(),!1))),a&&(l.style.display="none",d.$el.querySelector(".atk-layer-dialog-actions").style.display="none"),i.getEl().append(d.$el),e.onMount&&e.onMount(d.$el)}close(t,e){e.disposeNow(),this.launched=this.launched.filter((e=>e!==t))}}function ve(t,e,n,i){return h(this,null,(function*(){var s,a;if(Ot.data.token){const t=new Headers(n.headers);t.set("Authorization",`Bearer ${Ot.data.token}`),n.headers=t}const r=yield function(t,e,n,i){var s;const a=new AbortController;null==(s=i.signal)||s.addEventListener("abort",(()=>a.abort()));let r=fetch(e,c(l({},i),{signal:a.signal}));if(n>0){const t=setTimeout((()=>a.abort()),n);r.finally((()=>{clearTimeout(t)}))}return r=r.catch((t=>{throw"AbortError"===(t||{}).name?new Error(At("reqAborted")):t})),r}(0,e,i||t.conf.reqTimeout||15e3,n),o=r.status,d=[401,400].includes(o);if(!r.ok&&!d)throw new Error(`${At("reqGot")} ${o}`);let h=yield r.json();const u=(i,s)=>{ve(t,e,n).then((t=>{i(t)})).catch((t=>{s(t)}))};if((null==(s=h.data)?void 0:s.need_captcha)?h=yield new Promise(((e,n)=>{t.checkCaptcha({imgData:h.data.img_data,iframe:h.data.iframe,onSuccess:()=>{u(e,n)},onCancel:()=>{n(h)}})})):((null==(a=h.data)?void 0:a.need_login)||d)&&(h=yield new Promise(((e,n)=>{t.checkAdmin({onSuccess:()=>{u(e,n)},onCancel:()=>{n(h)}})}))),!h.success)throw h;return h}))}function ke(t){const e=new FormData;return Object.keys(t).forEach((n=>e.append(n,String(t[n])))),e}!function(){function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function n(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&a(t,e)}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function a(t,e){return(a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function o(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return o(t)}function c(t){var e=r();return function(){var n,i=s(t);if(e){var a=s(this).constructor;n=Reflect.construct(i,arguments,a)}else n=i.apply(this,arguments);return l(this,n)}}function d(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=s(t)););return t}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var i=d(t,e);if(i){var s=Object.getOwnPropertyDescriptor(i,e);return s.get?s.get.call(arguments.length<3?t:n):s.value}},h.apply(this,arguments)}var u=function(){function e(){t(this,e),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return n(e,[{key:"addEventListener",value:function(t,e,n){t in this.listeners||(this.listeners[t]=[]),this.listeners[t].push({callback:e,options:n})}},{key:"removeEventListener",value:function(t,e){if(t in this.listeners)for(var n=this.listeners[t],i=0,s=n.length;i<s;i++)if(n[i].callback===e)return void n.splice(i,1)}},{key:"dispatchEvent",value:function(t){if(t.type in this.listeners){for(var e=this.listeners[t.type].slice(),n=0,i=e.length;n<i;n++){var s=e[n];try{s.callback.call(this,t)}catch(a){Promise.resolve().then((function(){throw a}))}s.options&&s.options.once&&this.removeEventListener(t.type,s.callback)}return!t.defaultPrevented}}}]),e}(),p=function(e){i(r,e);var a=c(r);function r(){var e;return t(this,r),(e=a.call(this)).listeners||u.call(o(e)),Object.defineProperty(o(e),"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(o(e),"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(o(e),"reason",{value:void 0,writable:!0,configurable:!0}),e}return n(r,[{key:"toString",value:function(){return"[object AbortSignal]"}},{key:"dispatchEvent",value:function(t){"abort"===t.type&&(this.aborted=!0,"function"==typeof this.onabort&&this.onabort.call(this,t)),h(s(r.prototype),"dispatchEvent",this).call(this,t)}}]),r}(u),m=function(){function e(){t(this,e),Object.defineProperty(this,"signal",{value:new p,writable:!0,configurable:!0})}return n(e,[{key:"abort",value:function(t){var e;try{e=new Event("abort")}catch(i){"undefined"!=typeof document?document.createEvent?(e=document.createEvent("Event")).initEvent("abort",!1,!1):(e=document.createEventObject()).type="abort":e={type:"abort",bubbles:!1,cancelable:!1}}var n=t;if(void 0===n)if("undefined"==typeof document)(n=new Error("This operation was aborted")).name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(s){(n=new Error("This operation was aborted")).name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(e)}},{key:"toString",value:function(){return"[object AbortController]"}}]),e}();function g(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):"function"==typeof t.Request&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function f(t){"function"==typeof t&&(t={fetch:t});var e=t,n=e.fetch,i=e.Request,s=void 0===i?n.Request:i,a=e.AbortController,r=e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,o=void 0!==r&&r;if(!g({fetch:n,Request:s,AbortController:a,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:n,Request:l};var l=s;(l&&!l.prototype.hasOwnProperty("signal")||o)&&((l=function(t,e){var n;e&&e.signal&&(n=e.signal,delete e.signal);var i=new s(t,e);return n&&Object.defineProperty(i,"signal",{writable:!1,enumerable:!1,configurable:!0,value:n}),i}).prototype=s.prototype);var c=n;return{fetch:function(t,e){var n=l&&l.prototype.isPrototypeOf(t)?t.signal:e?e.signal:void 0;if(n){var i;try{i=new DOMException("Aborted","AbortError")}catch(a){(i=new Error("Aborted")).name="AbortError"}if(n.aborted)return Promise.reject(i);var s=new Promise((function(t,e){n.addEventListener("abort",(function(){return e(i)}),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([s,c(t,e)])}return c(t,e)},Request:l}}"undefined"!=typeof Symbol&&Symbol.toStringTag&&(m.prototype[Symbol.toStringTag]="AbortController",p.prototype[Symbol.toStringTag]="AbortSignal"),function(t){if(g(t))if(t.fetch){var e=f(t),n=e.fetch,i=e.Request;t.fetch=n,t.Request=i,Object.defineProperty(t,"AbortController",{writable:!0,enumerable:!1,configurable:!0,value:m}),Object.defineProperty(t,"AbortSignal",{writable:!0,enumerable:!1,configurable:!0,value:p})}else console.warn("fetch() is not available, cannot install abortcontroller-polyfill")}("undefined"!=typeof self?self:U)}();class we{constructor(t,e){d(this,"api"),d(this,"ctx"),this.api=t,this.ctx=e}POST(t,e){return h(this,null,(function*(){return function(t,e,n){return h(this,null,(function*(){const i={method:"POST"};return n=l({site_name:t.conf.site||""},n||{}),i.body=ke(n),(yield ve(t,e,i)).data||{}}))}(this.ctx,this.api.baseURL+t,e)}))}Fetch(t,e,n){return h(this,null,(function*(){return ve(this.ctx,this.api.baseURL+t,e,n)}))}}const be={comment:class extends we{get(t,e,n,i){const s={page_key:this.ctx.conf.pageKey,site_name:this.ctx.conf.site||"",limit:e,offset:t};return n&&(s.flat_mode=n),Ot.checkHasBasicUserInfo()&&(s.name=Ot.data.nick,s.email=Ot.data.email),i&&i(s),this.POST("/get",s)}add(t){return h(this,null,(function*(){const e={name:t.nick,email:t.email,link:t.link,content:t.content,rid:t.rid,page_key:t.page_key,ua:yield $()};t.page_title&&(e.page_title=t.page_title),t.site_name&&(e.site_name=t.site_name);return(yield this.POST("/add",e)).comment}))}commentEdit(t){return h(this,null,(function*(){const e=l({},t);return(yield this.POST("/admin/comment-edit",e)).comment}))}commentDel(t,e){const n={id:String(t),site_name:e||""};return this.POST("/admin/comment-del",n)}vote(t,e){return h(this,null,(function*(){const n={target_id:t,type:e};Ot.checkHasBasicUserInfo()&&(n.name=Ot.data.nick,n.email=Ot.data.email);return yield this.POST("/vote",n)}))}},page:class extends we{pageGet(t,e,n){return h(this,null,(function*(){const i={site_name:t||"",offset:e||0,limit:n||15};return yield this.POST("/admin/page-get",i)}))}pageEdit(t){return h(this,null,(function*(){const e={id:t.id,key:t.key,title:t.title,admin_only:t.admin_only,site_name:t.site_name||this.ctx.conf.site};return(yield this.POST("/admin/page-edit",e)).page}))}pageDel(t,e){const n={key:String(t),site_name:e||""};return this.POST("/admin/page-del",n)}pageFetch(t,e,n){return h(this,null,(function*(){const i={};t&&(i.id=t),e&&(i.site_name=e),n&&(i.get_status=n);return yield this.POST("/admin/page-fetch",i)}))}pv(){return h(this,null,(function*(){const t={page_key:this.ctx.conf.pageKey||"",page_title:this.ctx.conf.pageTitle||""};return(yield this.POST("/pv",t)).pv}))}stat(t,e,n){return h(this,null,(function*(){const i={type:t};e&&(i.page_keys=Array.isArray(e)?e.join(","):e),n&&(i.limit=n);return yield this.POST("/stat",i)}))}},site:class extends we{siteGet(){return h(this,null,(function*(){return(yield this.POST("/admin/site-get",{})).sites}))}siteAdd(t,e){return h(this,null,(function*(){const n={name:t,urls:e,site_name:""};return(yield this.POST("/admin/site-add",n)).site}))}siteEdit(t){return h(this,null,(function*(){const e={id:t.id,name:t.name||"",urls:t.urls||""};return(yield this.POST("/admin/site-edit",e)).site}))}siteDel(t,e=!1){const n={id:t,del_content:e};return this.POST("/admin/site-del",n)}export(){return h(this,null,(function*(){var t;return(null==(t=(yield this.Fetch("/admin/export",{method:"POST"},0)).data)?void 0:t.data)||""}))}},user:class extends we{login(t,e,n){return h(this,null,(function*(){const i={name:t,email:e,password:n};return yield this.POST("/login",i)}))}userGet(t,e){const n=new AbortController,i={name:t,email:e};return{req:this.Fetch("/user-get",{method:"POST",body:ke(i),signal:n.signal}).then((t=>({user:t.data.user,is_login:t.data.is_login,unread:t.data.unread||[],unread_count:t.data.unread_count||0}))),abort:()=>{n.abort()}}}loginStatus(){return h(this,null,(function*(){return(yield this.POST("/login-status",{name:Ot.data.nick,email:Ot.data.email}))||{is_login:!1,is_admin:!1}}))}logout(){return h(this,null,(function*(){return this.POST("/logout")}))}markRead(t,e,n=!1){const i={comment_id:t,notify_key:e};return n&&(delete i.comment_id,delete i.notify_key,i.read_all=!0,i.name=Ot.data.nick,i.email=Ot.data.email),this.POST("/mark-read",i)}userList(t,e,n){return h(this,null,(function*(){const i={offset:t||0,limit:e||15};n&&(i.type=n);return yield this.POST("/admin/user-get",i)}))}userAdd(t,e){return h(this,null,(function*(){const n={name:t.name||"",email:t.email||"",password:e||"",link:t.link||"",is_admin:t.is_admin||!1,site_names:t.site_names_raw||"",receive_email:t.receive_email||!0,badge_name:t.badge_name||"",badge_color:t.badge_color||""};return(yield this.POST("/admin/user-add",n)).user}))}userEdit(t,e){return h(this,null,(function*(){const n={id:t.id,name:t.name||"",email:t.email||"",password:e||"",link:t.link||"",is_admin:t.is_admin||!1,site_names:t.site_names_raw||"",receive_email:t.receive_email||!0,badge_name:t.badge_name||"",badge_color:t.badge_color||""};return(yield this.POST("/admin/user-edit",n)).user}))}userDel(t){return this.POST("/admin/user-del",{id:String(t)})}},system:class extends we{conf(){return h(this,null,(function*(){return de((yield this.POST("/conf")).frontend_conf||{})}))}getSettings(){return h(this,null,(function*(){return yield this.POST("/admin/setting-get")}))}saveSettings(t){return h(this,null,(function*(){return yield this.POST("/admin/setting-save",{data:t})}))}version(){return h(this,null,(function*(){const t=yield fetch(`${this.api.baseURL}/version`,{method:"POST"});return yield t.json()}))}},captcha:class extends we{captchaGet(){return h(this,null,(function*(){return(yield this.POST("/captcha/refresh")).img_data||""}))}captchaCheck(t){return h(this,null,(function*(){return(yield this.POST("/captcha/check",{value:t})).img_data||""}))}captchaStatus(){return h(this,null,(function*(){return(yield this.POST("/captcha/status"))||{is_pass:!1}}))}},admin:class extends we{cacheFlushAll(){return this.POST("/admin/cache-flush",{flush_all:!0})}cacheWarmUp(){return this.POST("/admin/cache-warm",{})}},upload:class extends we{imgUpload(t){return h(this,null,(function*(){const e=ke({name:Ot.data.nick,email:Ot.data.email,page_key:this.ctx.conf.pageKey});e.set("file",t);const n={method:"POST",body:e};return(yield this.Fetch("/img-upload",n)).data||{}}))}}};class xe{constructor(t){d(this,"ctx"),this.ctx=t,Object.entries(be).forEach((([t,e])=>{this[t]=new e(this,this.ctx)}))}get baseURL(){return`${this.ctx.conf.server}/api`}}function Ce(t){const e={editor:t,isMoved:!1,move:t=>function(t,e){if(t.isMoved)return;t.isMoved=!0;const n=t.editor.getUI().$el;n.after(u('<div class="atk-editor-travel-placeholder"></div>'));const i=u("<div></div>");e.after(i),i.replaceWith(n),n.classList.add("atk-fade-in")}(e,t),back:()=>function(t){var e;if(!t.isMoved)return;t.isMoved=!1,null==(e=t.editor.ctx.$root.querySelector(".atk-editor-travel-placeholder"))||e.replaceWith(t.editor.getUI().$el),t.editor.cancelReply()}(e)};return e}class Se{constructor(t){d(this,"editor"),d(this,"$panel"),d(this,"$btn"),d(this,"onHeaderInput"),d(this,"contentTransformer"),d(this,"onContentUpdated"),this.editor=t}get ctx(){return this.editor.ctx}registerPanel(t="<div></div>"){return this.$panel=u(t),this.$panel}registerBtn(t){return this.$btn=u(`<span class="atk-plug-btn" data-plug-name="${this.constructor.name}">${t}</span>`),this.$btn}registerHeaderInputEvt(t){this.onHeaderInput=t}registerContentTransformer(t){this.contentTransformer=t}registerContentUpdatedEvt(t){this.onContentUpdated=t}getPanel(){return this.$panel}getBtn(){return this.$btn}}d(Se,"Name");class Ee extends Se{constructor(t){super(t),d(this,"emoticons",[]),d(this,"loadingTask",null),d(this,"$grpWrap"),d(this,"$grpSwitcher"),d(this,"isListLoaded",!1),d(this,"isImgLoaded",!1),this.editor=t,this.registerPanel('<div class="atk-editor-plug-emoticons"></div>'),this.registerBtn(this.ctx.$t("emoticon")),this.registerContentTransformer((t=>this.transEmoticonImageText(t))),window.setTimeout((()=>{this.loadEmoticonsData()}),1e3)}onPanelShow(){(()=>{h(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 h(this,null,(function*(){this.isListLoaded||(null===this.loadingTask?(this.loadingTask=(()=>h(this,null,(function*(){x(this.$panel),this.emoticons=yield this.handleData(this.ctx.conf.emoticons),C(this.$panel),this.loadingTask=null,this.isListLoaded=!0})))(),yield this.loadingTask):yield this.loadingTask)}))}handleData(t){return h(this,null,(function*(){if(!Array.isArray(t)&&["object","string"].includes(typeof t)&&(t=[t]),!Array.isArray(t))return L(this.$panel,"表情包数据必须为 Array/Object/String 类型"),C(this.$panel),[];const e=e=>{"object"==typeof e&&(e.name&&t.find((t=>t.name===e.name))||t.push(e))},n=t=>h(this,null,(function*(){yield Promise.all(t.map(((t,i)=>h(this,null,(function*(){if("object"!=typeof t||Array.isArray(t)){if(Array.isArray(t))yield n(t);else if("string"==typeof t){const i=yield this.remoteLoad(t);Array.isArray(i)?yield n(i):"object"==typeof i&&e(i)}}else e(t)})))))}));return yield n(t),t.forEach((t=>{if(this.isOwOFormat(t)){this.convertOwO(t).forEach((t=>{e(t)}))}else Array.isArray(t)&&t.forEach((t=>{e(t)}))})),t=t.filter((t=>"object"==typeof t&&!Array.isArray(t)&&!!t&&!!t.name)),this.solveNullKey(t),this.solveSameKey(t),t}))}remoteLoad(t){return h(this,null,(function*(){if(!t)return[];try{const e=yield fetch(t);return yield e.json()}catch(e){return C(this.$panel),L(this.$panel,`表情加载失败 ${String(e)}`),[]}}))}solveNullKey(t){t.forEach((t=>{t.items.forEach(((e,n)=>{e.key||(e.key=`${t.name} ${n+1}`)}))}))}solveSameKey(t){const e={};t.forEach((t=>{t.items.forEach((t=>{t.key&&""!==String(t.key).trim()&&(e[t.key]?e[t.key]++:e[t.key]=1,e[t.key]>1&&(t.key=`${t.key} ${e[t.key]}`))}))}))}isOwOFormat(t){try{return"object"==typeof t&&!!Object.values(t).length&&Array.isArray(Object.keys(Object.values(t)[0].container))&&Object.keys(Object.values(t)[0].container[0]).includes("icon")}catch(e){return!1}}convertOwO(t){const e=[];return Object.entries(t).forEach((([t,n])=>{const i={name:t,type:n.type,items:[]};n.container.forEach(((e,n)=>{const s=e.icon;if(/<(img|IMG)/.test(s)){const t=/src=["'](.*?)["']/.exec(s);t&&t.length>1&&(e.icon=t[1])}i.items.push({key:e.text||`${t} ${n+1}`,val:e.icon})})),e.push(i)})),e}initEmoticonsList(){this.$grpWrap=u('<div class="atk-grp-wrap"></div>'),this.$panel.append(this.$grpWrap),this.emoticons.forEach(((t,e)=>{const n=u('<div class="atk-grp" style="display: none;"></div>');this.$grpWrap.append(n),n.setAttribute("data-index",String(e)),n.setAttribute("data-grp-name",t.name),n.setAttribute("data-type",t.type),t.items.forEach((e=>{const i=u('<span class="atk-item"></span>');if(n.append(i),e.key&&!new RegExp(`^(${t.name})?\\s?[0-9]+$`).test(e.key)&&i.setAttribute("title",e.key),"image"===t.type){const t=document.createElement("img");t.src=e.val,t.alt=e.key,i.append(t)}else i.innerText=e.val;i.onclick=()=>{"image"===t.type?this.editor.insertContent(`:[${e.key}]`):this.editor.insertContent(e.val||"")}}))})),this.emoticons.length>1&&(this.$grpSwitcher=u('<div class="atk-grp-switcher"></div>'),this.$panel.append(this.$grpSwitcher),this.emoticons.forEach(((t,e)=>{const n=u("<span />");n.innerText=t.name,n.setAttribute("data-index",String(e)),n.onclick=()=>this.openGrp(e),this.$grpSwitcher.append(n)}))),this.emoticons.length>0&&this.openGrp(0)}openGrp(t){var e,n,i;Array.from(this.$grpWrap.children).forEach((e=>{const n=e;n.getAttribute("data-index")!==String(t)?n.style.display="none":n.style.display=""})),null==(e=this.$grpSwitcher)||e.querySelectorAll("span.active").forEach((t=>t.classList.remove("active"))),null==(i=null==(n=this.$grpSwitcher)?void 0:n.querySelector(`span[data-index="${t}"]`))||i.classList.add("active"),this.changeListHeight()}changeListHeight(){}transEmoticonImageText(t){return this.emoticons&&Array.isArray(this.emoticons)?(this.emoticons.forEach((e=>{"image"===e.type&&Object.entries(e.items).forEach((([e,n])=>{t=t.split(`:[${n.key}]`).join(`<img src="${n.val}" atk-emoticon="${n.key}">`)}))})),t):t}}d(Ee,"Name","emoticons");class Te extends Se{constructor(t){super(t),d(this,"$imgUploadInput"),d(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((t=>`.${t}`)).join(",");const e=this.registerBtn(`${this.ctx.$t("image")}`);e.after(this.$imgUploadInput),e.onclick=()=>{const t=this.$imgUploadInput;t.onchange=()=>{(()=>{h(this,null,(function*(){if(!t.files||0===t.files.length)return;const e=t.files[0];this.uploadImg(e)}))})()},t.click()},this.ctx.conf.imgUpload||this.getBtn().setAttribute("atk-only-admin-show","");const n=t=>{if(t)for(let e=0;e<t.length;e++){const n=t[e];this.uploadImg(n)}};this.editor.getUI().$textarea.addEventListener("dragover",(t=>{t.stopPropagation(),t.preventDefault()})),this.editor.getUI().$textarea.addEventListener("drop",(t=>{var e;const i=null==(e=t.dataTransfer)?void 0:e.files;(null==i?void 0:i.length)&&(t.preventDefault(),n(i))})),this.editor.getUI().$textarea.addEventListener("paste",(t=>{var e;const i=null==(e=t.clipboardData)?void 0:e.files;(null==i?void 0:i.length)&&(t.preventDefault(),n(i))}))}uploadImg(t){return h(this,null,(function*(){const e=/[^.]+$/.exec(t.name);if(!e||!this.allowImgExts.includes(e[0]))return;if(!Ot.checkHasBasicUserInfo())return void this.editor.showNotify(this.ctx.$t("uploadLoginMsg"),"w");let n="\n";""===this.editor.getUI().$textarea.value.trim()&&(n="");const i=`${n}`;let s;this.editor.insertContent(i);try{s=this.ctx.conf.imgUploader?{img_url:yield this.ctx.conf.imgUploader(t)}:yield this.ctx.getApi().upload.imgUpload(t)}catch(a){console.error(a),this.editor.showNotify(`${this.ctx.$t("uploadFail")},${a.msg}`,"e")}if(s&&s.img_url){let t=s.img_url;v(t)||(t=k(this.ctx,t)),this.editor.setContent(this.editor.getUI().$textarea.value.replace(i,`${n}`))}else this.editor.setContent(this.editor.getUI().$textarea.value.replace(i,""))}))}}d(Te,"Name","upload");class Le extends Se{constructor(t){super(t),d(this,"isBind",!1),this.registerPanel('<div class="atk-editor-plug-preview"></div>');let e=this.editor.$t("preview");this.ctx.getMarkedInstance()&&(e+=' <i title="Markdown is supported"><svg class="markdown" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M14.85 3H1.15C.52 3 0 3.52 0 4.15v7.69C0 12.48.52 13 1.15 13h13.69c.64 0 1.15-.52 1.15-1.15v-7.7C16 3.52 15.48 3 14.85 3zM9 11H7V8L5.5 9.92 4 8v3H2V5h2l1.5 2L7 5h2v6zm2.99.5L9.5 8H11V5h2v3h1.5l-2.51 3.5z"></path></svg></i>'),this.registerBtn(e),this.registerContentUpdatedEvt((t=>{this.updateContent()}))}onPanelShow(){if(this.updateContent(),!this.isBind){const t=()=>{this.updateContent()};this.editor.getUI().$textarea.addEventListener("input",t),this.editor.getUI().$textarea.addEventListener("change",t),this.isBind=!0}}updateContent(){"none"!==this.$panel.style.display&&(this.$panel.innerHTML=this.editor.getContentMarked())}}d(Le,"Name","preview");class Ae extends Se{constructor(t){super(t),d(this,"queryUserInfo",{timeout:null,abortFunc:null}),this.registerHeaderInputEvt(((t,e)=>{"nick"!==t&&"email"!==t||this.fetchUserInfo()})),this.editor.getUI().$link.addEventListener("change",(()=>{const t=this.editor.getUI().$link.value.trim();t&&!/^(http|https):\/\//.test(t)&&(this.editor.getUI().$link.value=`https://${t}`,Ot.update({link:this.editor.getUI().$link.value}))}))}fetchUserInfo(){Ot.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:t,abort:e}=this.ctx.getApi().user.userGet(Ot.data.nick,Ot.data.email);this.queryUserInfo.abortFunc=e,t.then((t=>{var e;t.is_login||Ot.logout(),this.ctx.updateNotifies(t.unread),Ot.checkHasBasicUserInfo()&&!t.is_login&&(null==(e=t.user)?void 0:e.is_admin)&&this.showLoginDialog(),t.user&&t.user.link&&(this.editor.getUI().$link.value=t.user.link,Ot.update({link:t.user.link}))})).catch((()=>{})).finally((()=>{this.queryUserInfo.abortFunc=null}))}),400)}showLoginDialog(){this.ctx.checkAdmin({onSuccess:()=>{}})}}d(Ae,"Name","headerInput");const Me=[Ee,Te,Le,Ae];function Oe(t){const e={editor:t,plugList:{},openedPlugName:null,openPlugPanel:t=>_e(e,t),closePlugPanel:()=>Be(e),triggerHeaderInputEvt:(t,n)=>function(t,e,n){Object.entries(t.plugList).forEach((([t,i])=>{i.onHeaderInput&&i.onHeaderInput(e,n)}))}(e,t,n),triggerContentUpdatedEvt:t=>function(t,e){Object.entries(t.plugList).forEach((([t,n])=>{n.onContentUpdated&&n.onContentUpdated(e)}))}(e,t),getTransformedContent:t=>function(t,e){let n=e;return Object.entries(t.plugList).forEach((([t,e])=>{e.contentTransformer&&(n=e.contentTransformer(n))})),n}(e,t)};t.getUI().$plugPanelWrap.innerHTML="",t.getUI().$plugPanelWrap.style.display="none",t.getUI().$plugBtnWrap.innerHTML="";const n=[{k:"upload",v:(i=t.conf).imgUpload},{k:"emoticons",v:i.emoticons},{k:"preview",v:i.preview}].filter((t=>!t.v)).flatMap((t=>t.k));var i;return Me.filter((t=>!n.includes(t.name))).forEach((t=>{!function(t,e){const n=e.Name,i=new e(t.editor);t.plugList[n]=i,function(t,e,n){const i=n.getBtn();if(!i)return;t.editor.getUI().$plugBtnWrap.appendChild(i),i.onclick=i.onclick||(()=>{t.editor.getUI().$plugBtnWrap.querySelectorAll(".active").forEach((t=>t.classList.remove("active"))),e!==t.openedPlugName?(_e(t,e),i.classList.add("active")):Be(t)});const s=n.getPanel();s&&(s.setAttribute("data-plug-name",e),s.style.display="none",t.editor.getUI().$plugPanelWrap.appendChild(s))}(t,n,i)}(e,t)})),e}function _e(t,e){Object.entries(t.plugList).forEach((([t,n])=>{const i=n.getPanel();i&&(t===e?(i.style.display="",n.onPanelShow&&n.onPanelShow()):(i.style.display="none",n.onPanelHide&&n.onPanelHide()))})),t.editor.getUI().$plugPanelWrap.style.display="",t.openedPlugName=e}function Be(t){if(!t.openedPlugName)return;const e=t.plugList[t.openedPlugName];e&&(e.onPanelHide&&e.onPanelHide(),t.editor.getUI().$plugPanelWrap.style.display="none",t.openedPlugName=null)}function Pe(t){const e={editor:t,comment:void 0,setReply:(t,n,i)=>function(t,e,n,i=!0){t.editor.cancelEditComment(),Re(t);const s=t.editor.getUI();s.$sendReply||(s.$sendReply=u(`<div class="atk-send-reply">${t.editor.$t("reply")} <span class="atk-text"></span><span class="atk-cancel">×</span></div>`),s.$sendReply.querySelector(".atk-text").innerText=`@${e.nick}`,s.$sendReply.addEventListener("click",(()=>{t.editor.cancelReply()})),s.$textareaWrap.append(s.$sendReply));t.comment=e,t.editor.travel(n),i&&S(s.$el);s.$textarea.focus()}(e,t,n,i),cancelReply:()=>Re(e)};return e}function Re(t){if(!t.comment)return;const e=t.editor.getUI();e.$sendReply&&(e.$sendReply.remove(),e.$sendReply=void 0),t.comment=void 0,t.editor.travelBack()}function Ie(t){const e={editor:t,comment:void 0,setEdit:(t,n)=>function(t,e,n){Ue(t),t.editor.cancelReply();const i=t.editor.getUI();if(!i.$editCancelBtn){const e=u(`<div class="atk-send-reply">${t.editor.$t("editCancel")} <span class="atk-cancel">×</span></div>`);e.onclick=()=>{Ue(t)},i.$textareaWrap.append(e),i.$editCancelBtn=e}t.comment=e,i.$header.style.display="none",t.editor.travel(n),i.$nick.value=e.nick||"",i.$email.value=e.email||"",i.$link.value=e.link||"",t.editor.setContent(e.content),i.$textarea.focus(),t.editor.refreshSendBtnText()}(e,t,n),cancelEdit:()=>Ue(e)};return function(t){t.editor.getSubmitManager().registerCustom({activeCond:()=>!!t.comment,req:()=>h(this,null,(function*(){const e={content:t.editor.getFinalContent(),nick:t.editor.getUI().$nick.value,email:t.editor.getUI().$email.value,link:t.editor.getUI().$link.value};return yield t.editor.ctx.getApi().comment.commentEdit(l(l({},t.comment),e))})),post:e=>{t.editor.ctx.updateComment(e)}})}(e),e}function Ue(t){if(!t.comment)return;const e=t.editor.getUI();e.$editCancelBtn&&(e.$editCancelBtn.remove(),e.$editCancelBtn=void 0),t.comment=void 0,t.editor.travelBack();const{nick:n,email:i,link:s}=Ot.data;e.$nick.value=n,e.$email.value=i,e.$link.value=s,t.editor.setContent(""),t.editor.refreshSendBtnText(),e.$header.style.display=""}function De(t){const e={editor:t,do:()=>function(t){return h(this,null,(function*(){if(""===t.editor.getFinalContent().trim())return void t.editor.focus();const e=t.customs.find((t=>t.activeCond()));t.editor.ctx.trigger("editor-submit"),t.editor.showLoading();try{let n;(null==e?void 0:e.pre)&&e.pre(),n=(null==e?void 0:e.req)?yield e.req():yield function(t){return h(this,null,(function*(){const e=yield t.editor.ctx.getApi().comment.add(l({},function(t){var e;const{nick:n,email:i,link:s}=Ot.data,a=t.editor.ctx.conf,r=null==(e=t.editor.getReplyManager())?void 0:e.comment;return{content:t.editor.getFinalContent(),nick:n,email:i,link:s,rid:r?r.id:0,page_key:r?r.page_key:a.pageKey,page_title:r?void 0:a.pageTitle,site_name:r?r.site_name:a.site}}(t)));return e}))}(t),(null==e?void 0:e.post)?e.post(n):function(t,e){const n=t.editor.getReplyManager(),i=t.editor.ctx.conf;(null==n?void 0:n.comment)&&n.comment.page_key!==i.pageKey&&window.open(`${n.comment.page_url}#atk-comment-${e.id}`);t.editor.ctx.insertComment(e)}(t,n)}catch(n){console.error(n),t.editor.showNotify(`${t.editor.$t("commentFail")},${n.msg||String(n)}`,"e")}t.editor.reset(),t.editor.ctx.trigger("editor-submitted"),t.editor.hideLoading()}))}(e),customs:[],registerCustom:t=>{e.customs.push(t)}};return e}const qe={localStorage:function(t){const e=window.localStorage.getItem("ArtalkContent")||"";""!==e.trim()&&(t.showNotify(t.$t("restoredMsg"),"i"),t.setContent(e));t.getUI().$textarea.addEventListener("input",(()=>t.saveToLocalStorage()))},header:function(t){const e=t.getHeaderInputEls();Object.entries(e).forEach((([e,n])=>{n.value=Ot.data[e]||"",n.addEventListener("input",(()=>function(t,e,n){var i;if(t.isEditMode)return;Ot.update({[e]:n.value.trim()}),null==(i=t.getPlugs())||i.triggerHeaderInputEvt(e,n)}(t,e,n))),n.placeholder=`${t.$t(e)}`}))},textarea:function(t){t.getUI().$textarea.placeholder=t.ctx.conf.placeholder||t.$t("placeholder"),t.getUI().$textarea.addEventListener("keydown",(e=>{9===(e.keyCode||e.which)&&(e.preventDefault(),t.insertContent("\t"))})),t.getUI().$textarea.addEventListener("input",(()=>{t.adjustTextareaHeight()}))},submitBtn:function(t){t.refreshSendBtnText(),t.getUI().$submitBtn.addEventListener("click",(()=>t.submit()))},submitManager:function(t){t.setSubmitManager(De(t))},plugs:function(t){t.setPlugs(Oe(t))},mover:function(t){if(!t.conf.editorTravel)return;t.setMover(Ce(t))},replyManager:function(t){t.setReplyManager(Pe(t))},editModeManager:function(t){t.setEditModeManager(Ie(t))}};const We='<div class="atk-main-editor">\n <div class="atk-header">\n <input name="nick" class="atk-nick" type="text" required="required">\n <input name="email" class="atk-email" type="email" required="required">\n <input name="link" class="atk-link" type="url">\n </div>\n <div class="atk-textarea-wrap">\n <textarea class="atk-textarea"></textarea>\n </div>\n <div class="atk-plug-panel-wrap" style="display: none;"></div>\n <div class="atk-bottom">\n <div class="atk-item atk-plug-btn-wrap"></div>\n <div class="atk-item">\n <button type="button" class="atk-send-btn"></button>\n </div>\n </div>\n <div class="atk-notify-wrap"></div>\n</div>\n',Fe={$header:".atk-header",$nick:'.atk-header [name="nick"]',$email:'.atk-header [name="email"]',$link:'.atk-header [name="link"]',$textareaWrap:".atk-textarea-wrap",$textarea:".atk-textarea",$bottom:".atk-bottom",$submitBtn:".atk-send-btn",$notifyWrap:".atk-notify-wrap",$plugBtnWrap:".atk-plug-btn-wrap",$plugPanelWrap:".atk-plug-panel-wrap"};class He extends b{constructor(t){super(t),d(this,"ui"),d(this,"plugs"),d(this,"mover"),d(this,"reply"),d(this,"editMode"),d(this,"submitManager"),this.ui=function(){const t=u(We),e={$el:t};return Object.entries(Fe).forEach((([n,i])=>{e[n]=t.querySelector(i)})),e}(),this.$el=this.ui.$el,this.ctx.on("conf-loaded",(()=>{var t;t=this,Object.entries(qe).forEach((([e,n])=>{n(t)}))}))}getUI(){return this.ui}getPlugs(){return this.plugs}setPlugs(t){this.plugs=t}setMover(t){this.mover=t}setReplyManager(t){this.reply=t}getReplyManager(){return this.reply}get isReplyMode(){var t;return!!(null==(t=this.reply)?void 0:t.comment)}setEditModeManager(t){this.editMode=t}get isEditMode(){var t;return!!(null==(t=this.editMode)?void 0:t.comment)}setSubmitManager(t){this.submitManager=t}getSubmitManager(){return this.submitManager}getHeaderInputEls(){return{nick:this.ui.$nick,email:this.ui.$email,link:this.ui.$link}}saveToLocalStorage(){window.localStorage.setItem("ArtalkContent",this.getContentOriginal().trim())}refreshSendBtnText(){this.isEditMode?this.ui.$submitBtn.innerText=this.$t("save"):this.ui.$submitBtn.innerText=this.ctx.conf.sendBtn||this.$t("send")}getFinalContent(){let t=this.getContentOriginal();return this.plugs&&(t=this.plugs.getTransformedContent(t)),t}getContentOriginal(){return this.ui.$textarea.value||""}getContentMarked(){return wt(this.ctx,this.getFinalContent())}setContent(t){this.ui.$textarea.value=t,this.saveToLocalStorage(),this.plugs&&this.plugs.triggerContentUpdatedEvt(t),window.setTimeout((()=>{this.adjustTextareaHeight()}),80)}insertContent(t){if(document.selection)this.ui.$textarea.focus(),document.selection.createRange().text=t,this.ui.$textarea.focus();else if(this.ui.$textarea.selectionStart||0===this.ui.$textarea.selectionStart){const e=this.ui.$textarea.selectionStart,n=this.ui.$textarea.selectionEnd,i=this.ui.$textarea.scrollTop;this.setContent(this.ui.$textarea.value.substring(0,e)+t+this.ui.$textarea.value.substring(n,this.ui.$textarea.value.length)),this.ui.$textarea.focus(),this.ui.$textarea.selectionStart=e+t.length,this.ui.$textarea.selectionEnd=e+t.length,this.ui.$textarea.scrollTop=i}else this.ui.$textarea.focus(),this.ui.$textarea.value+=t}adjustTextareaHeight(){const t=this.ui.$textarea.offsetHeight-this.ui.$textarea.clientHeight;this.ui.$textarea.style.height="0px",this.ui.$textarea.style.height=`${this.ui.$textarea.scrollHeight+t}px`}focus(){this.ui.$textarea.focus()}reset(){this.setContent(""),this.cancelReply(),this.cancelEditComment()}setReply(t,e,n=!0){var i;null==(i=this.reply)||i.setReply(t,e,n)}cancelReply(){var t;null==(t=this.reply)||t.cancelReply()}setEditComment(t,e){var n;null==(n=this.editMode)||n.setEdit(t,e)}cancelEditComment(){var t;null==(t=this.editMode)||t.cancelEdit()}showNotify(t,e){E(this.ui.$notifyWrap,t,e)}showLoading(){x(this.ui.$el)}hideLoading(){C(this.ui.$el)}submit(){return h(this,null,(function*(){this.submitManager&&(yield this.submitManager.do())}))}close(){this.ui.$textareaWrap.querySelector(".atk-comment-closed")||this.ui.$textareaWrap.prepend(u(`<div class="atk-comment-closed">${this.$t("onlyAdminCanReply")}</div>`)),Ot.data.isAdmin?(this.ui.$textarea.style.display="",this.ui.$bottom.style.display=""):(this.ui.$textarea.style.display="none",this.closePlugPanel(),this.ui.$bottom.style.display="none")}open(){var t;null==(t=this.ui.$textareaWrap.querySelector(".atk-comment-closed"))||t.remove(),this.ui.$textarea.style.display="",this.ui.$bottom.style.display=""}travel(t){var e;null==(e=this.mover)||e.move(t)}travelBack(){var t;null==(t=this.mover)||t.back()}openPlugPanel(t){var e;null==(e=this.plugs)||e.openPlugPanel(t)}closePlugPanel(){var t;null==(t=this.plugs)||t.closePlugPanel()}}class Ne extends b{constructor(t){super(t),d(this,"layer"),d(this,"$header"),d(this,"$closeBtn"),d(this,"$iframeWrap"),d(this,"$iframe"),d(this,"firstShow",!0),this.$el=u('<div class="atk-sidebar-layer">\n <div class="atk-sidebar-inner">\n <div class="atk-sidebar-header">\n <div class="atk-sidebar-close"><i class="atk-icon atk-icon-close"></i></div>\n </div>\n <div class="atk-sidebar-iframe-wrap"></div>\n </div>\n</div>\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 h(this,arguments,(function*(t={}){if(this.$el.style.transform="",null==this.layer&&(this.layer=new M(this.ctx,"sidebar",this.$el),this.layer.afterHide=()=>{!0===this.ctx.conf.editorTravel&&this.ctx.editorTravelBack()}),this.layer.show(),(()=>{h(this,null,(function*(){var e;const n=yield this.ctx.getApi().user.loginStatus();n.is_admin&&!n.is_login&&(null==(e=this.layer)||e.hide(),this.firstShow=!0,this.ctx.checkAdmin({onSuccess:()=>{setTimeout((()=>{this.show(t)}),500)},onCancel:()=>{}}))}))})(),this.firstShow){this.$iframeWrap.innerHTML="",this.$iframe=u("<iframe></iframe>");const e=k(this.ctx,"/sidebar/"),n={pageKey:this.conf.pageKey,site:this.conf.site||"",user:JSON.stringify(Ot.data),time:+new Date};t.view&&(n.view=t.view),this.conf.darkMode&&(n.darkMode="1"),"string"==typeof this.conf.locale&&(n.locale=this.conf.locale);const i=new URLSearchParams(n);this.iframeLoad(`${e}?${i.toString()}`),this.$iframeWrap.append(this.$iframe),this.firstShow=!1}else{const t=this.$iframe.src.includes("darkMode=1");this.conf.darkMode&&!t&&this.iframeLoad(`${this.$iframe.src}&darkMode=1`),!this.conf.darkMode&&t&&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 t;this.$el.style.transform="",null==(t=this.layer)||t.hide(),this.ctx.trigger("sidebar-hide")}iframeLoad(t){this.$iframe&&(this.$iframe.src=t,x(this.$iframeWrap),this.$iframe.onload=()=>{C(this.$iframeWrap)})}}const je={i18n(t){Lt(t.conf.locale),t.on("conf-loaded",(()=>{Lt(t.conf.locale)}))},markdown(){!function(){try{if(!t.marked.name)return}catch(s){return}const e=new t.marked.Renderer,n=e.link;e.link=(t,i,s)=>{const a=null==t?void 0:t.startsWith(`${window.location.protocol}//${window.location.hostname}`);return n.call(e,t,i,s).replace(/^<a /,`<a target="_blank" ${a?"":'rel="noreferrer noopener nofollow"'} `)},e.code=(t,e)=>{const n=e||"plaintext";let i=t;return window.hljs?n&&window.hljs.getLanguage(n)&&(i=window.hljs.highlight(n,t).value):i=$t(t),`<pre rel="${n}">\n<code class="hljs language-${n}">${i.replace(/&/g,"&")}</code>\n</pre>`};const i=t.marked;t.marked.setOptions({renderer:e,pedantic:!1,gfm:!0,breaks:!0,smartLists:!0,smartypants:!0,xhtml:!1,sanitize:!1,silent:!0}),vt=i}()},user:t=>(Ot.setContext(t),Ot),api:t=>new xe(t),checkerLauncher:t=>new $e(t),editor(t){const e=new He(t);return t.$root.appendChild(e.$el),e},list(t){const e=new ue(t);return t.$root.appendChild(e.$el),e.fetchComments(0),e},layer(t){M.BodyOrgOverflow=document.body.style.overflow,M.BodyOrgPaddingRight=document.body.style.paddingRight},sidebarLayer:t=>new Ne(t),eventsDefault(t){window.addEventListener("hashchange",(()=>{t.listHashGotoCheck()})),t.on("user-changed",(()=>{t.checkAdminShowEl(),t.listRefreshUI()}))},darkMode(t){P(t),t.on("conf-loaded",(()=>{P(t)}))}};function ze(t){return h(this,null,(function*(){const e=t.ctx.conf.countEl;e&&document.querySelector(e)&&Ve(t,{api:"page_comment",countEl:e});const n=t.pvAdd?yield t.ctx.getApi().page.pv():void 0,i=t.ctx.conf.pvEl;i&&document.querySelector(i)&&Ve(t,{api:"page_pv",countEl:i,curtPageCount:n})}))}function Ve(t,e){return h(this,null,(function*(){let n={};const i=t.ctx.conf.pageKey;e.curtPageCount&&(n[i]=e.curtPageCount);let s=Array.from(document.querySelectorAll(e.countEl)).map((t=>t.getAttribute("data-page-key")||i)).filter((t=>void 0===n[t]));if(s=[...new Set(s)],s.length>0){const i=yield t.ctx.getApi().page.stat(e.api,s);n=l(l({},n),i)}document.querySelectorAll(e.countEl).forEach((t=>{const e=t.getAttribute("data-page-key")||i;t.innerHTML=`${Number(n[e]||0)}`}))}))}const Qe=class{constructor(t){d(this,"conf"),d(this,"ctx"),d(this,"$root"),Qe.instance&&Qe.destroy(),this.conf=ce(t),this.conf.el instanceof HTMLElement&&(this.$root=this.conf.el),this.ctx=new pe(this.conf,this.$root),Object.entries(je).forEach((([t,e])=>{if(Qe.DisabledComponents.includes(t))return;const n=e(this.ctx);n&&this.ctx.inject(t,n)})),Qe.plugins.forEach((t=>{"function"==typeof t&&t(this.ctx)}))}static init(t){return this.instance&&Qe.destroy(),this.instance=new Qe(t),this.instance}use(t){Qe.plugins.push(t),"function"==typeof t&&t(this.ctx)}update(t){if(!Qe.instance)throw Error("cannot call `update` function before call `load`");return Qe.instance.ctx.updateConf(t),Qe.instance}reload(){this.ctx.listReload()}destroy(){if(!Qe.instance)throw Error("cannot call `destroy` function before call `load`");Qe.instance.$root.remove(),delete Qe.instance}on(t,e){this.ctx.on(t,e,"external")}off(t,e){this.ctx.off(t,e,"external")}trigger(t,e){this.ctx.trigger(t,e,"external")}setDarkMode(t){this.ctx.setDarkMode(t)}static use(t){this.plugins.push(t),this.instance&&"function"==typeof t&&t(this.instance.ctx)}static update(t){var e;return null==(e=this.instance)?void 0:e.update(t)}static reload(){var t;null==(t=this.instance)||t.reload()}static destroy(){var t;null==(t=this.instance)||t.destroy()}static on(t,e){var n;null==(n=this.instance)||n.on(t,e)}static off(t,e){var n;null==(n=this.instance)||n.off(t,e)}static trigger(t,e){var n;null==(n=this.instance)||n.trigger(t,e)}static setDarkMode(t){var e;null==(e=this.instance)||e.setDarkMode(t)}static loadCountWidget(t){const e=new pe(ce(t));e.inject("api",new xe(e)),ze({ctx:e,pvAdd:!1})}static LoadCountWidget(t){console.warn("The method `LoadCountWidget` is deprecated, please use `loadCountWidget` instead."),this.loadCountWidget(t)}};let Ge=Qe;return d(Ge,"instance"),d(Ge,"ListLite",he),d(Ge,"defaults",le),d(Ge,"plugins",[t=>{t.conf.useBackendConf?t.on("list-loaded",(()=>{ze({ctx:t,pvAdd:!0})})):ze({ctx:t,pvAdd:!0})}]),d(Ge,"DisabledComponents",[]),Ge}(marked);
|
|
1
|
+
var Artalk=function(t){"use strict";var e=Object.defineProperty,n=Object.defineProperties,i=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,o=(t,n,i)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[n]=i,l=(t,e)=>{for(var n in e||(e={}))a.call(e,n)&&o(t,n,e[n]);if(s)for(var n of s(e))r.call(e,n)&&o(t,n,e[n]);return t},c=(t,e)=>n(t,i(e)),d=(t,e,n)=>(o(t,"symbol"!=typeof e?e+"":e,n),n),h=(t,e,n)=>new Promise(((i,s)=>{var a=t=>{try{o(n.next(t))}catch(e){s(e)}},r=t=>{try{o(n.throw(t))}catch(e){s(e)}},o=t=>t.done?i(t.value):Promise.resolve(t.value).then(a,r);o((n=n.apply(t,e)).next())}));function u(t=""){const e=document.createElement("div");return e.innerHTML=t.trim(),e.firstElementChild||e}function p(t){return parseFloat(getComputedStyle(t,null).height.replace("px",""))}function m(t){const e=RegExp(`[?&]${t}=([^&]*)`).exec(window.location.search);return e&&decodeURIComponent(e[1].replace(/\+/g," "))}function g(t){const e=t.getBoundingClientRect();return{top:e.top+window.scrollY,left:e.left+window.scrollX}}function f(t,e){let n=t.toString();for(;n.length<e;)n=`0${n}`;return n}function y(t,e){try{const n=t.getTime(),i=(new Date).getTime()-n,s=Math.floor(i/864e5);if(0===s){const t=i%864e5,n=Math.floor(t/36e5);if(0===n){const n=t%36e5,i=Math.floor(n/6e4);if(0===i){const t=n%6e4,i=Math.round(t/1e3);return i<10?e.$t("now"):`${i} ${e.$t("seconds")}`}return`${i} ${e.$t("minutes")}`}return`${n} ${e.$t("hours")}`}return s<0?e.$t("now"):s<8?`${s} ${e.$t("days")}`:function(t){const e=f(t.getDate(),2),n=f(t.getMonth()+1,2);return`${f(t.getFullYear(),2)}-${n}-${e}`}(t)}catch(n){return console.error(n)," - "}}function $(){return h(this,null,(function*(){const t=navigator.userAgent;if(!navigator.userAgentData||!navigator.userAgentData.getHighEntropyValues)return t;const e=navigator.userAgentData;let n=null;try{n=yield e.getHighEntropyValues(["platformVersion"])}catch(s){return console.error(s),t}const i=Number(n.platformVersion.split(".")[0]);return"Windows"===e.platform&&i>=13?t.replace(/Windows NT 10.0/,"Windows NT 11.0"):"macOS"===e.platform&&i>=11?t.replace(/(Mac OS X \d+_\d+_\d+|Mac OS X)/,`Mac OS X ${n.platformVersion.replace(/\./g,"_")}`):t}))}function v(t){let e;try{e=new URL(t)}catch(n){return!1}return"http:"===e.protocol||"https:"===e.protocol}function k(t,e){return function(t,e){return`${t.replace(/\/$/,"")}/${e.replace(/^\//,"")}`}(t.conf.server,e)}function w(t,e){const n=t=>t&&"object"==typeof t;return n(t)&&n(e)?(Object.keys(e).forEach((i=>{const s=t[i],a=e[i];Array.isArray(s)&&Array.isArray(a)?t[i]=s.concat(a):n(s)&&n(a)?t[i]=w(l({},s),a):t[i]=a})),t):e}class b{constructor(t){d(this,"$el"),d(this,"ctx"),d(this,"conf"),this.ctx=t,this.conf=t.conf}$t(t,e={}){return this.ctx.$t(t,e)}}function x(t,e){let n=t.querySelector(":scope > .atk-loading");n||(n=u('<div class="atk-loading atk-fade-in" style="display: none;">\n <div class="atk-loading-spinner">\n <svg viewBox="25 25 50 50"><circle cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10"></circle></svg>\n </div>\n </div>'),(null==e?void 0:e.transparentBg)&&(n.style.background="transparent"),t.appendChild(n)),n.style.display="";const i=n.querySelector(".atk-loading-spinner");i&&(i.style.display="none",window.setTimeout((()=>{i.style.display=""}),500))}function C(t){const e=t.querySelector(":scope > .atk-loading");e&&(e.style.display="none")}function S(t,e=!0){const n=g(t).top+p(t)/2-document.documentElement.clientHeight/2;e?window.scroll({top:n>0?n:0,left:0}):window.scroll(0,n>0?n:0)}function E(t,e,n){const i=u(`<div class="atk-notify atk-fade-in" style="background-color: ${{s:"#57d59f",e:"#ff6f6c",w:"#ffc721",i:"#2ebcfc"}[n]}"><span class="atk-notify-content"></span></div>`);i.querySelector(".atk-notify-content").innerHTML=function(t){const e=document.createElement("div");return e.innerText=t,e.innerHTML}(e).replace("\n","<br/>"),t.appendChild(i);const s=()=>{i.classList.add("atk-fade-out"),setTimeout((()=>{i.remove()}),200)};let a;a=window.setTimeout((()=>{s()}),3e3),i.addEventListener("click",(()=>{s(),window.clearTimeout(a)}))}function T(t,e){!function(t,e,n="in"){t.classList.add(`atk-fade-${n}`);const i=()=>{t.classList.remove(`atk-fade-${n}`),t.removeEventListener("animationend",i),e&&e()};t.addEventListener("animationend",i)}(t,e,"in")}function L(t,e,n='<span class="atk-error-title">Artalk Error</span>'){let i=t.querySelector(".atk-error-layer");if(null===e)return void(null!==i&&i.remove());i||(i=u(`<div class="atk-error-layer">${n}<span class="atk-error-text"></span></div>`),t.appendChild(i));const s=i.querySelector(".atk-error-text");s.innerHTML="",null!==e&&(e instanceof HTMLElement?s.appendChild(e):s.innerText=e)}const A=class extends b{constructor(t,e,n){super(t),d(this,"name"),d(this,"$wrap"),d(this,"$mask"),d(this,"maskClickHideEnable",!0),d(this,"afterHide"),this.name=e;const{$wrap:i,$mask:s}=O();this.$wrap=i,this.$mask=s,this.$el=this.$wrap.querySelector(`[data-layer-name="${e}"].atk-layer-item`),null===this.$el&&(n?this.$el=n:(this.$el=u(),this.$el.classList.add("atk-layer-item"))),this.$el.setAttribute("data-layer-name",e),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(t){this.maskClickHideEnable=t}pageBodyScrollBarHide(){document.body.style.overflow="hidden";const t=parseInt(window.getComputedStyle(document.body,null).getPropertyValue("padding-right"),10);document.body.style.paddingRight=`${function(){const t=document.createElement("p");t.style.width="100%",t.style.height="200px";const e=document.createElement("div");e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.visibility="hidden",e.style.width="200px",e.style.height="150px",e.style.overflow="hidden",e.appendChild(t),document.body.appendChild(e);const n=t.offsetWidth;e.style.overflow="scroll";let i=t.offsetWidth;return n===i&&(i=e.clientWidth),document.body.removeChild(e),n-i}()+t||0}px`}pageBodyScrollBarShow(){document.body.style.overflow=A.BodyOrgOverflow,document.body.style.paddingRight=A.BodyOrgPaddingRight}newActionTimer(t,e){const n=()=>{t(),A.actionTimers=A.actionTimers.filter((t=>t.act!==n))},i=window.setTimeout((()=>n()),e);A.actionTimers.push({act:n,tid:i})}fireAllActionTimer(){A.actionTimers.forEach((t=>{clearTimeout(t.tid),t.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 M=A;function O(){let t=document.querySelector(".atk-layer-wrap");t||(t=u('<div class="atk-layer-wrap" style="display: none;"><div class="atk-layer-mask"></div></div>'),document.body.appendChild(t));const e=t.querySelector(".atk-layer-mask");return{$wrap:t,$mask:e}}d(M,"BodyOrgOverflow"),d(M,"BodyOrgPaddingRight"),d(M,"actionTimers",[]);const _=window.matchMedia("(prefers-color-scheme: dark)");let B;function P(t){R(t,t.conf.darkMode,!1)}function R(t,e,n=!0){const i=e=>{!function(t,e){e?t.$root.classList.add(I):t.$root.classList.remove(I);const{$wrap:n}=O();n&&(e?n.classList.add(I):n.classList.remove(I))}(t,e),n&&function(t,e){t.conf.darkMode=e}(t,e)};"auto"===e?(B||(B=t=>i(t.matches),_.addEventListener("change",B)),i(_.matches)):(B&&_.removeEventListener("change",B),i(e))}const I="atk-dark-mode";var U="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},D={"&":"&","<":"<",">":">",'"':""","'":"'"},q={"&":"&","<":"<",">":">",""":'"',"'":"'"},W=/(&|<|>|"|')/g,F=/[&<>"']/g;function H(t){return D[t]}function N(t){return q[t]}function j(t){return null==t?"":String(t).replace(F,H)}function z(t){return null==t?"":String(t).replace(W,N)}j.options=z.options={};var V={encode:j,escape:j,decode:z,unescape:z,version:"1.0.0-browser"};var Q=function t(e){for(var n,i,s=Array.prototype.slice.call(arguments,1);s.length;)for(i in n=s.shift())n.hasOwnProperty(i)&&("[object Object]"===Object.prototype.toString.call(e[i])?e[i]=t(e[i],n[i]):e[i]=n[i]);return e},G=function(t){return"string"==typeof t?t.toLowerCase():t};function K(t,e){return t[e]=!0,t}var Y=function(t){return t.reduce(K,{})},X={uris:Y(["background","base","cite","href","longdesc","src","usemap"])},J={voids:Y(["area","br","col","hr","img","wbr","input","base","basefont","link","meta"])},Z=V,tt=G,et=J,nt=/^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)\s*>/,it=/^<\s*\/\s*([\w:-]+)[^>]*>/,st=/([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g,at=/^</,rt=/^<\s*\//;var ot=V,lt=G,ct=X,dt=J;var ht=Q,ut=function(t,e){for(var n,i=function(){var t=[];return t.lastItem=function(){return t[t.length-1]},t}(),s=t;t;)a();function a(){n=!0,function(){"\x3c!--"===t.substr(0,4)?(i=t.indexOf("--\x3e"))>=0&&(e.comment&&e.comment(t.substring(4,i)),t=t.substring(i+3),n=!1):rt.test(t)?r(it,l):at.test(t)&&r(nt,o);var i;!function(){if(!n)return;var i,s=t.indexOf("<");s>=0?(i=t.substring(0,s),t=t.substring(s)):(i=t,t="");e.chars&&e.chars(i)}()}();var i=t===s;s=t,i&&(t="")}function r(e,i){var s=t.match(e);s&&(t=t.substring(s[0].length),s[0].replace(e,i),n=!1)}function o(t,n,s,a){var r={},o=tt(n),l=et.voids[o]||!!a;s.replace(st,(function(t,e,n,i,s){r[e]=void 0===n&&void 0===i&&void 0===s?void 0:Z.decode(n||i||s||"")})),l||i.push(o),e.start&&e.start(o,r,l)}function l(t,n){var s,a=0,r=tt(n);if(r)for(a=i.length-1;a>=0&&i[a]!==r;a--);if(a>=0){for(s=i.length-1;s>=a;s--)e.end&&e.end(i[s]);i.length=a}}l()},pt=function(t,e){var n,i=e||{};return o(),{start:function(t,e,r){var o=lt(t);if(n.ignoring)return void a(o);if(-1===(i.allowedTags||[]).indexOf(o))return void a(o);if(i.filter&&!i.filter({tag:o,attrs:e}))return void a(o);s("<"),s(o),Object.keys(e).forEach((function(t){var n=e[t],a=(i.allowedClasses||{})[o]||[],r=(i.allowedAttributes||{})[o]||[],l=lt(t);("class"===l&&-1===r.indexOf(l)?(n=n.split(" ").filter((function(t){return a&&-1!==a.indexOf(t)})).join(" ").trim()).length:-1!==r.indexOf(l)&&(!0!==ct.uris[l]||function(t){var e=t[0];if("#"===e||"/"===e)return!0;var n=t.indexOf(":");if(-1===n)return!0;var s=t.indexOf("?");if(-1!==s&&n>s)return!0;var a=t.indexOf("#");return-1!==a&&n>a||i.allowedSchemes.some(r);function r(e){return 0===t.indexOf(e+":")}}(n)))&&(s(" "),s(t),"string"==typeof n&&(s('="'),s(ot.encode(n)),s('"')))})),s(r?"/>":">")},end:function(t){var e=lt(t);-1!==(i.allowedTags||[]).indexOf(e)&&!1===n.ignoring?(s("</"),s(e),s(">")):r(e)},chars:function(t){!1===n.ignoring&&s(i.transformText?i.transformText(t):t)}};function s(e){t.push(e)}function a(t){dt.voids[t]||(!1===n.ignoring?n={ignoring:t,depth:1}:n.ignoring===t&&n.depth++)}function r(t){n.ignoring===t&&--n.depth<=0&&o()}function o(){n={ignoring:!1,depth:0}}},mt={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 gt(t,e,n){var i=[],s=!0===n?e:ht({},mt,e),a=pt(i,s);return ut(t,a),i.join("")}gt.defaults=mt;var ft=gt,yt={};({get exports(){return yt},set exports(t){yt=t}}).exports=function(){function t(t,e){return t(e={exports:{}},e.exports),e.exports}var e=t((function(t){var e=t.exports=function(){return new RegExp("(?:"+e.line().source+")|(?:"+e.block().source+")","gm")};e.line=function(){return/(?:^|\s)\/\/(.+?)$/gm},e.block=function(){return/\/\*([\S\s]*?)\*\//gm}})),n=["23AC69","91C132","F19726","E8552D","1AAB8E","E1147F","2980C1","1BA1E6","9FA0A0","F19726","E30B20","E30B20","A3338B"];function i(t){return'<span style="color: slategray">'+t+"</span>"}return function(t,s){void 0===s&&(s={});var a=s.colors;void 0===a&&(a=n);var r=0,o={},l=new RegExp("("+/[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af\u0400-\u04FF]+|\w+/.source+"|"+/</.source+")|("+e().source+")","gmi");return t.replace(l,(function(t,e,n){if(n)return i(n);if("<"===e)return"<";var s;o[e]?s=o[e]:(s=a[r],o[e]=s);var l='<span style="color: #'+s+'">'+e+"</span>";return r=++r%a.length,l}))}}();const $t=yt;let vt;function kt(){return vt}function wt(t,e){var n;let i=null==(n=kt())?void 0:n.parse(e);i||(i=e.replace(/```\s*([^]+?.*?[^]+?[^]+?)```/g,((t,e)=>`<pre><code>${$t(e)}</code></pre>`)).replace(/!\[(.*?)\]\((.*?)\)/g,((t,e,n)=>`<img src="${n}" alt="${e}" />`)).replace(/\[(.*?)\]\((.*?)\)/g,((t,e,n)=>`<a href="${n}" target="_blank">${e}</a>`)).replace(/\n/g,"<br>"));let s=ft(i,{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:t=>([["code",/^hljs\W+language-(.*)$/],["span",/^(hljs-.*)$/]].forEach((([e,n])=>{t.tag===e&&t.attrs.class&&!n.test(t.attrs.class)&&delete t.attrs.class})),"span"===t.tag&&t.attrs.style&&!/^color:(\W+)?#[0-9a-f]{3,6};?$/i.test(t.attrs.style)&&delete t.attrs.style,!0)});return t.markedReplacers.forEach((t=>{"function"==typeof t&&(s=t(s))})),s}const bt={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"},xt="ArtalkI18n",Ct={en:bt,"en-US":bt,"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 St(t){return t=t.replace(/^([a-zA-Z]+)(-[a-zA-Z]+)?$/,((t,e,n)=>e.toLowerCase()+(n||"").toUpperCase())),Ct[t]?Ct[t]:window[xt]&&window[xt][t]?window[xt][t]:Ct.en}let Et="en",Tt=St(Et);function Lt(t){t!==Et&&(Et=t,Tt="string"==typeof t?St(t):t)}function At(t,e={}){let n=(null==Tt?void 0:Tt[t])||t;return n=n.replace(/\{\s*(\w+?)\s*\}/g,((t,n)=>e[n]||"")),n}const Mt="2.5.4";const Ot=new class{constructor(){d(this,"ctx"),d(this,"data");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}}setContext(t){this.ctx=t}update(t={}){var e;Object.entries(t).forEach((([t,e])=>{this.data[t]=e})),window.localStorage.setItem("ArtalkUser",JSON.stringify(this.data)),null==(e=this.ctx)||e.trigger("user-changed",this.data)}logout(){this.update({token:"",isAdmin:!1})}checkHasBasicUserInfo(){return!!this.data.nick&&!!this.data.email}},_t=window||{},Bt=navigator||{};class Pt{constructor(t){d(this,"comment"),d(this,"$el"),d(this,"$main"),d(this,"$header"),d(this,"$headerNick"),d(this,"$headerBadgeWrap"),d(this,"$body"),d(this,"$content"),d(this,"$childrenWrap"),d(this,"$actions"),d(this,"voteBtnUp"),d(this,"voteBtnDown"),d(this,"$replyTo"),d(this,"$replyAt"),this.comment=t}get ctx(){return this.comment.ctx}get data(){return this.comment.getData()}get conf(){return this.comment.conf}get cConf(){return this.comment.getConf()}}function Rt(t){if(t.$headerNick=t.$el.querySelector(".atk-nick"),t.data.link){const e=u('<a target="_blank" rel="noreferrer noopener nofollow"></a>');e.innerText=t.data.nick,e.href=v(t.data.link)?t.data.link:`https://${t.data.link}`,t.$headerNick.append(e)}else t.$headerNick.innerText=t.data.nick}function It(t){t.$headerBadgeWrap=t.$el.querySelector(".atk-badge-wrap"),t.$headerBadgeWrap.innerHTML="";const e=t.data.badge_name,n=t.data.badge_color;if(e){const i=u('<span class="atk-badge"></span>');i.innerText=e.replace("管理员",t.ctx.$t("admin")),i.style.backgroundColor=n||"",t.$headerBadgeWrap.append(i)}if(t.data.is_pinned){const e=u(`<span class="atk-pinned-badge">${t.ctx.$t("pin")}</span>`);t.$headerBadgeWrap.append(e)}}function Ut(t){const e=t.$el.querySelector(".atk-date");e.innerText=t.comment.getDateFormatted(),e.setAttribute("data-atk-comment-date",String(+new Date(t.data.date)))}function Dt(t){if(!t.ctx.conf.uaBadge&&!t.data.ip_region)return;let e=t.$header.querySelector("atk-ua-wrap");if(e||(e=u('<span class="atk-ua-wrap"></span>'),t.$header.append(e)),e.innerHTML="",t.data.ip_region){const n=u('<span class="atk-region-badge"></span>');n.innerText=t.data.ip_region,e.append(n)}if(t.ctx.conf.uaBadge){const{browser:n,os:i}=t.comment.getUserUA();if(String(n).trim()){const t=u('<span class="atk-ua ua-browser"></span>');t.innerText=n,e.append(t)}if(String(i).trim()){const t=u('<span class="atk-ua ua-os"></span>');t.innerText=i,e.append(t)}}}class qt{constructor(t,e){d(this,"ctx"),d(this,"conf"),d(this,"$el"),d(this,"isLoading",!1),d(this,"msgRecTimer"),d(this,"msgRecTimerFunc"),d(this,"isConfirming",!1),d(this,"confirmRecTimer"),this.ctx=t,this.$el=u('<span class="atk-common-action-btn"></span>'),this.conf="object"!=typeof e?{text:e}:e,this.$el.innerText=this.getText(),this.conf.adminOnly&&this.$el.setAttribute("atk-only-admin-show","")}get isMessaging(){return!!this.msgRecTimer}appendTo(t){return t.append(this.$el),this}getText(){return"string"==typeof this.conf.text?this.conf.text:this.conf.text()}setClick(t){this.$el.onclick=e=>{if(e.stopPropagation(),!this.isLoading){if(this.conf.confirm&&!this.isMessaging){const t=()=>{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((()=>t()),5e3));this.confirmRecTimer&&window.clearTimeout(this.confirmRecTimer),t()}if(this.msgRecTimer)return this.fireMsgRecTimer(),void this.clearMsgRecTimer();t()}}}updateText(t){t&&(this.conf.text=t),this.setLoading(!1),this.$el.innerText=this.getText()}setLoading(t,e){this.isLoading!==t&&(this.isLoading=t,t?(this.$el.classList.add("atk-btn-loading"),this.$el.innerText=e||`${this.ctx.$t("loading")}...`):(this.$el.classList.remove("atk-btn-loading"),this.$el.innerText=this.getText()))}setError(t){this.setMsg(t,"atk-btn-error")}setWarn(t){this.setMsg(t,"atk-btn-warn")}setSuccess(t){this.setMsg(t,"atk-btn-success")}setMsg(t,e,n,i){this.setLoading(!1),e&&this.$el.classList.add(e),this.$el.innerText=t,this.setMsgRecTimer((()=>{this.$el.innerText=this.getText(),e&&this.$el.classList.remove(e),i&&i()}),n||2500)}setMsgRecTimer(t,e){this.fireMsgRecTimer(),this.clearMsgRecTimer(),this.msgRecTimerFunc=t,this.msgRecTimer=window.setTimeout((()=>{t(),this.clearMsgRecTimer()}),e)}fireMsgRecTimer(){this.msgRecTimerFunc&&this.msgRecTimerFunc()}clearMsgRecTimer(){this.msgRecTimer&&window.clearTimeout(this.msgRecTimer),this.msgRecTimer=void 0,this.msgRecTimerFunc=void 0}}function Wt(t){t.ctx.conf.vote&&(t.voteBtnUp=new qt(t.ctx,(()=>`${t.ctx.$t("voteUp")} (${t.data.vote_up||0})`)).appendTo(t.$actions),t.voteBtnUp.setClick((()=>{t.comment.getActions().vote("up")})),t.ctx.conf.voteDown&&(t.voteBtnDown=new qt(t.ctx,(()=>`${t.ctx.$t("voteDown")} (${t.data.vote_down||0})`)).appendTo(t.$actions),t.voteBtnDown.setClick((()=>{t.comment.getActions().vote("down")}))))}function Ft(t){if(!t.data.is_allow_reply)return;const e=u(`<span>${t.ctx.$t("reply")}</span>`);t.$actions.append(e),e.addEventListener("click",(e=>{e.stopPropagation(),t.cConf.onReplyBtnClick?t.cConf.onReplyBtnClick():t.ctx.replyComment(t.data,t.$el)}))}function Ht(t){const e=new qt(t.ctx,{text:()=>t.data.is_collapsed?t.ctx.$t("expand"):t.ctx.$t("collapse"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("collapsed",e)}))}function Nt(t){const e=new qt(t.ctx,{text:()=>t.data.is_pending?t.ctx.$t("pending"):t.ctx.$t("approved"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pending",e)}))}function jt(t){const e=new qt(t.ctx,{text:()=>t.data.is_pinned?t.ctx.$t("unpin"):t.ctx.$t("pin"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pinned",e)}))}function zt(t){const e=new qt(t.ctx,{text:t.ctx.$t("edit"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.ctx.editComment(t.data,t.$el)}))}function Vt(t){const e=new qt(t.ctx,{text:t.ctx.$t("delete"),confirm:!0,confirmText:t.ctx.$t("deleteConfirm"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminDelete(e)}))}const Qt={Avatar:function(t){const e=t.$el.querySelector(".atk-avatar"),n=u("<img />"),i=t.conf.avatarURLBuilder;if(n.src=i?i(t.data):t.comment.getGravatarURL(),t.data.link){const i=u('<a target="_blank" rel="noreferrer noopener nofollow"></a>');i.href=v(t.data.link)?t.data.link:`https://${t.data.link}`,i.append(n),e.append(i)}else e.append(n)},Header:function(t){Object.entries({renderNick:Rt,renderVerifyBadge:It,renderDate:Ut,renderUABadge:Dt}).forEach((([e,n])=>{n(t)}))},Content:function(t){if(!t.data.is_collapsed)return t.$content.innerHTML=t.comment.getContentMarked(),void t.$content.classList.remove("atk-hide","atk-collapsed");t.$content.classList.add("atk-hide","atk-type-collapsed");const e=u(`\n <div class="atk-collapsed">\n <span class="atk-text">${t.ctx.$t("collapsedMsg")}</span>\n <span class="atk-show-btn">${t.ctx.$t("expand")}</span>\n </div>`);t.$body.insertAdjacentElement("beforeend",e);const n=e.querySelector(".atk-show-btn");n.addEventListener("click",(e=>{e.stopPropagation(),t.$content.classList.contains("atk-hide")?(t.$content.innerHTML=t.comment.getContentMarked(),t.$content.classList.remove("atk-hide"),T(t.$content),n.innerHTML=t.ctx.$t("collapse")):(t.$content.innerHTML="",t.$content.classList.add("atk-hide"),n.innerHTML=t.ctx.$t("expand"))}))},ReplyAt:function(t){t.cConf.isFlatMode||0===t.data.rid||t.cConf.replyTo&&(t.$replyAt=u('<span class="atk-item atk-reply-at"><span class="atk-arrow"></span><span class="atk-nick"></span></span>'),t.$replyAt.querySelector(".atk-nick").innerText=`${t.cConf.replyTo.nick}`,t.$replyAt.onclick=()=>{t.comment.getActions().goToReplyComment()},t.$headerBadgeWrap.insertAdjacentElement("afterend",t.$replyAt))},ReplyTo:function(t){if(!t.cConf.isFlatMode)return;if(!t.cConf.replyTo)return;t.$replyTo=u(`\n <div class="atk-reply-to">\n <div class="atk-meta">${t.ctx.$t("reply")} <span class="atk-nick"></span>:</div>\n <div class="atk-content"></div>\n </div>`);const e=t.$replyTo.querySelector(".atk-nick");e.innerText=`@${t.cConf.replyTo.nick}`,e.onclick=()=>{t.comment.getActions().goToReplyComment()};let n=wt(t.ctx,t.cConf.replyTo.content);t.cConf.replyTo.is_collapsed&&(n=`[${t.ctx.$t("collapsed")}]`),t.$replyTo.querySelector(".atk-content").innerHTML=n,t.$body.prepend(t.$replyTo)},Pending:function(t){if(!t.data.is_pending)return;const e=u(`<div class="atk-pending">${t.ctx.$t("pendingMsg")}</div>`);t.$body.prepend(e)},Actions:function(t){Object.entries({renderVote:Wt,renderReply:Ft,renderCollapse:Ht,renderModerator:Nt,renderPin:jt,renderEdit:zt,renderDel:Vt}).forEach((([e,n])=>{n(t)}))}};function Gt(t,e){e.forEach((({el:e,max:n,imgContains:i})=>{const s=()=>{e&&(t.scrollable?function(t){if(!t.el)return;if(t.el.classList.contains(Xt))return;t.el.classList.add(Xt),t.el.style.height=`${t.maxHeight}px`}({el:e,maxHeight:n}):function(t){if(!t.el)return;if(!t.maxHeight)return;if(t.el.classList.contains(Kt))return;t.el.classList.add(Kt),t.el.style.height=`${t.maxHeight}px`,t.el.style.overflow="hidden";const e=u(`<div class="atk-height-limit-btn">${At("readMore")}</span>`);e.onclick=e=>{e.stopPropagation(),Yt(t.el),t.postBtnClick&&t.postBtnClick(e)},t.el.append(e)}({el:e,maxHeight:n,postBtnClick:t.postExpandBtnClick}))},a=()=>{e&&p(e)>n&&s()};a(),i&&e&&function(t,e){if(!t)return;const n=t.getElementsByTagName("img");if(!n.length)return;let i=n.length;for(let s=0;s<n.length;s++)n[s].complete?i--:n[s].addEventListener("load",(()=>{i--,0===i&&e()})),0===i&&e()}(e,(()=>a()))}))}const Kt="atk-height-limit";function Yt(t){t&&t.classList.contains(Kt)&&(t.classList.remove(Kt),Array.from(t.children).forEach((t=>{t.classList.contains("atk-height-limit-btn")&&t.remove()})),t.style.height="",t.style.overflow="")}const Xt="atk-height-limit-scroll";class Jt extends Pt{constructor(t){super(t)}render(){var t;return this.$el=u('<div class="atk-comment-wrap">\n <div class="atk-comment">\n <div class="atk-avatar"></div>\n <div class="atk-main">\n <div class="atk-header">\n <span class="atk-item atk-nick"></span>\n <span class="atk-badge-wrap"></span>\n <span class="atk-item atk-date"></span>\n </div>\n <div class="atk-body">\n <div class="atk-content"></div>\n </div>\n <div class="atk-footer">\n <div class="atk-actions"></div>\n </div>\n </div>\n </div>\n</div>\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("id",`atk-comment-${this.data.id}`),t=this,Object.entries(Qt).forEach((([e,n])=>{n(t)})),this.recoveryChildrenWrap(),this.$el}checkHeightLimit(){const t=this.ctx.conf.heightLimit;if(!t||!t.content||!t.children)return;const e=t.content,n=t.children;Gt({postExpandBtnClick:()=>{const t=this.comment.getChildren();1===t.length&&Yt(t[0].getRender().$content)},scrollable:t.scrollable},[{el:this.$content,max:e,imgContains:!0},{el:this.$replyTo,max:e,imgContains:!0},{el:this.$childrenWrap,max:n,imgContains:!1}])}heightLimitRemoveForChildren(){this.$childrenWrap&&Yt(this.$childrenWrap)}playFadeAnim(){T(this.comment.getRender().$el)}playFadeAnimForBody(){T(this.comment.getRender().$body)}getChildrenWrap(){return this.$childrenWrap}renderChildrenWrap(){return this.$childrenWrap||(this.$childrenWrap=u('<div class="atk-comment-children"></div>'),this.$main.append(this.$childrenWrap)),this.$childrenWrap}recoveryChildrenWrap(){this.$childrenWrap&&this.$main.append(this.$childrenWrap)}setUnread(t){t?this.$el.classList.add("atk-unread"):this.$el.classList.remove("atk-unread")}setOpenable(t){t?this.$el.classList.add("atk-openable"):this.$el.classList.remove("atk-openable")}setOpenURL(t){this.setOpenable(!0),this.$el.onclick=e=>{e.preventDefault(),window.open(t),this.cConf.openEvt&&this.cConf.openEvt()}}setOpenAction(t){this.setOpenable(!0),this.$el.onclick=e=>{e.preventDefault(),t()}}}class Zt{constructor(t){d(this,"comment"),this.comment=t}get ctx(){return this.comment.ctx}get data(){return this.comment.getData()}get cConf(){return this.comment.getConf()}vote(t){const e="up"===t?this.comment.getRender().voteBtnUp:this.comment.getRender().voteBtnDown;this.ctx.getApi().comment.vote(this.data.id,`comment_${t}`).then((t=>{var e,n;this.data.vote_up=t.up,this.data.vote_down=t.down,null==(e=this.comment.getRender().voteBtnUp)||e.updateText(),null==(n=this.comment.getRender().voteBtnDown)||n.updateText()})).catch((t=>{null==e||e.setError(this.ctx.$t("voteFail")),console.log(t)}))}adminEdit(t,e){if(e.isLoading)return;e.setLoading(!0,`${this.ctx.$t("editing")}...`);const n=l({},this.data);"collapsed"===t?n.is_collapsed=!n.is_collapsed:"pending"===t?n.is_pending=!n.is_pending:"pinned"===t&&(n.is_pinned=!n.is_pinned),this.ctx.getApi().comment.commentEdit(n).then((t=>{e.setLoading(!1),this.comment.setData(t),this.ctx.listRefreshUI()})).catch((t=>{console.error(t),e.setError(this.ctx.$t("editFail"))}))}adminDelete(t){t.isLoading||(t.setLoading(!0,`${this.ctx.$t("deleting")}...`),this.ctx.getApi().comment.commentDel(this.data.id,this.data.site_name).then((()=>{t.setLoading(!1),this.cConf.onDelete&&this.cConf.onDelete(this.comment)})).catch((e=>{console.error(e),t.setError(this.ctx.$t("deleteFail"))})))}goToReplyComment(){const t=window.location.hash,e=`#atk-comment-${this.data.rid}`;window.location.hash=e,e===t&&window.dispatchEvent(new Event("hashchange"))}}class te extends b{constructor(t,e,n){super(t),d(this,"renderInstance"),d(this,"actionInstance"),d(this,"data"),d(this,"cConf"),d(this,"parent"),d(this,"children",[]),d(this,"nestCurt"),d(this,"nestMax"),this.nestMax=t.conf.nestMax||3,this.cConf=n,this.data=l({},e),this.data.date=this.data.date.replace(/-/g,"/"),this.parent=null,this.nestCurt=1,this.actionInstance=new Zt(this),this.renderInstance=new Jt(this)}render(){const t=this.renderInstance.render();this.$el&&this.$el.replaceWith(t),this.$el=t,this.cConf.afterRender&&this.cConf.afterRender()}getActions(){return this.actionInstance}getRender(){return this.renderInstance}getData(){return this.data}setData(t){this.data=t,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(t,e="append"){t.parent=this,t.nestCurt=this.nestCurt+1,this.children.push(t);const n=this.getChildrenEl();"append"===e?n.append(t.getEl()):"prepend"===e&&n.prepend(t.getEl()),t.getRender().playFadeAnim(),t.getRender().checkHeightLimit()}getChildrenEl(){let t=this.getRender().getChildrenWrap();return t||(t=this.nestCurt<this.nestMax?this.getRender().renderChildrenWrap():this.parent.getChildrenEl()),t}getParents(){const t=[],e=n=>{n.parent&&(t.push(n.parent),e(n.parent))};return e(this),t}getEl(){return this.$el}getGravatarURL(){return t=this.ctx,e=this.data.email_encrypted,`${t.conf.gravatar.mirror.replace(/\/$/,"")}/${e}?d=${encodeURIComponent(t.conf.gravatar.default)}&s=80`;var t,e}getContentMarked(){return wt(this.ctx,this.data.content)}getDateFormatted(){return y(new Date(this.data.date),this.ctx)}getUserUA(){const t=function(t){const e=String(t||Bt.userAgent),n={os:"",osVersion:"",engine:"",browser:"",device:"",language:"",version:""},i={Trident:e.includes("Trident")||e.includes("NET CLR"),Presto:e.includes("Presto"),WebKit:e.includes("AppleWebKit"),Gecko:e.includes("Gecko/")},s={Safari:e.includes("Safari"),Chrome:e.includes("Chrome")||e.includes("CriOS"),IE:e.includes("MSIE")||e.includes("Trident"),Edge:e.includes("Edge")||e.includes("Edg"),Firefox:e.includes("Firefox")||e.includes("FxiOS"),"Firefox Focus":e.includes("Focus"),Chromium:e.includes("Chromium"),Opera:e.includes("Opera")||e.includes("OPR"),Vivaldi:e.includes("Vivaldi"),Yandex:e.includes("YaBrowser"),Kindle:e.includes("Kindle")||e.includes("Silk/"),360:e.includes("360EE")||e.includes("360SE"),UC:e.includes("UC")||e.includes(" UBrowser"),QQBrowser:e.includes("QQBrowser"),QQ:e.includes("QQ/"),Baidu:e.includes("Baidu")||e.includes("BIDUBrowser"),Maxthon:e.includes("Maxthon"),Sogou:e.includes("MetaSr")||e.includes("Sogou"),LBBROWSER:e.includes("LBBROWSER"),"2345Explorer":e.includes("2345Explorer"),TheWorld:e.includes("TheWorld"),MIUI:e.includes("MiuiBrowser"),Quark:e.includes("Quark"),Qiyu:e.includes("Qiyu"),Wechat:e.includes("MicroMessenger"),Taobao:e.includes("AliApp(TB"),Alipay:e.includes("AliApp(AP"),Weibo:e.includes("Weibo"),Douban:e.includes("com.douban.frodo"),Suning:e.includes("SNEBUY-APP"),iQiYi:e.includes("IqiyiApp")},a={Windows:e.includes("Windows"),Linux:e.includes("Linux")||e.includes("X11"),macOS:e.includes("Macintosh"),Android:e.includes("Android")||e.includes("Adr"),Ubuntu:e.includes("Ubuntu"),FreeBSD:e.includes("FreeBSD"),Debian:e.includes("Debian"),"Windows Phone":e.includes("IEMobile")||e.includes("Windows Phone"),BlackBerry:e.includes("BlackBerry")||e.includes("RIM"),MeeGo:e.includes("MeeGo"),Symbian:e.includes("Symbian"),iOS:e.includes("like Mac OS X"),"Chrome OS":e.includes("CrOS"),WebOS:e.includes("hpwOS")},r={Mobile:e.includes("Mobi")||e.includes("iPh")||e.includes("480"),Tablet:e.includes("Tablet")||e.includes("Pad")||e.includes("Nexus 7")};r.Mobile?r.Mobile=!e.includes("iPad"):s.Chrome&&e.includes("Edg")?(s.Chrome=!1,s.Edge=!0):_t.showModalDialog&&_t.chrome&&(s.Chrome=!1,s[360]=!0),n.device="PC",n.language=(()=>{const t=(Bt.browserLanguage||Bt.language).split("-");return t[1]&&(t[1]=t[1].toUpperCase()),t.join("_")})();const o={engine:i,browser:s,os:a,device:r};Object.entries(o).forEach((([t,e])=>{Object.entries(e).forEach((([e,i])=>{!0===i&&(n[t]=e)}))}));const l={Windows:()=>{const t=e.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"}[t]||t},Android:()=>e.replace(/^.*Android ([\d.]+);.*$/,"$1"),iOS:()=>e.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,"."),Debian:()=>e.replace(/^.*Debian\/([\d.]+).*$/,"$1"),"Windows Phone":()=>e.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2"),macOS:()=>e.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,"."),WebOS:()=>e.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")};n.osVersion="",l[n.os]&&(n.osVersion=l[n.os](),n.osVersion===e&&(n.osVersion=""));const c={Safari:()=>e.replace(/^.*Version\/([\d.]+).*$/,"$1"),Chrome:()=>e.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1"),IE:()=>e.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1"),Edge:()=>e.replace(/^.*(Edge|Edg|Edg[A-Z]{1})\/([\d.]+).*$/,"$2"),Firefox:()=>e.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1"),"Firefox Focus":()=>e.replace(/^.*Focus\/([\d.]+).*$/,"$1"),Chromium:()=>e.replace(/^.*Chromium\/([\d.]+).*$/,"$1"),Opera:()=>e.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1"),Vivaldi:()=>e.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1"),Yandex:()=>e.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1"),Kindle:()=>e.replace(/^.*Version\/([\d.]+).*$/,"$1"),Maxthon:()=>e.replace(/^.*Maxthon\/([\d.]+).*$/,"$1"),QQBrowser:()=>e.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1"),QQ:()=>e.replace(/^.*QQ\/([\d.]+).*$/,"$1"),Baidu:()=>e.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1"),UC:()=>e.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1"),Sogou:()=>e.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1"),"2345Explorer":()=>e.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1"),TheWorld:()=>e.replace(/^.*TheWorld ([\d.]+).*$/,"$1"),MIUI:()=>e.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1"),Quark:()=>e.replace(/^.*Quark\/([\d.]+).*$/,"$1"),Qiyu:()=>e.replace(/^.*Qiyu\/([\d.]+).*$/,"$1"),Wechat:()=>e.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1"),Taobao:()=>e.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1"),Alipay:()=>e.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1"),Weibo:()=>e.replace(/^.*weibo__([\d.]+).*$/,"$1"),Douban:()=>e.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1"),Suning:()=>e.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1"),iQiYi:()=>e.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")};return n.version="",c[n.browser]&&(n.version=c[n.browser](),n.version===e&&(n.version="")),n.version.indexOf(".")&&(n.version=n.version.substring(0,n.version.indexOf("."))),"iOS"===n.os&&e.includes("iPad")?n.os="iPadOS":"Edge"!==n.browser||e.includes("Edg")?"MIUI"===n.browser?n.os="Android":"Chrome"===n.browser&&Number(n.version)>27||"Opera"===n.browser&&Number(n.version)>12||"Yandex"===n.browser?n.engine="Blink":void 0===n.browser&&(n.browser="Unknow App"):n.engine="EdgeHTML",n}(this.data.ua);return{browser:`${t.browser} ${t.version}`,os:`${t.os} ${t.osVersion}`}}getConf(){return this.cConf}}class ee{constructor(t,e){d(this,"conf"),d(this,"total"),d(this,"$el"),d(this,"$input"),d(this,"inputTimer"),d(this,"$prevBtn"),d(this,"$nextBtn"),d(this,"page",1),this.total=t,this.conf=e,this.$el=u('<div class="atk-pagination-wrap">\n <div class="atk-pagination">\n <div class="atk-btn atk-btn-prev">Prev</div>\n <input type="text" class="atk-input" aria-label="Enter the number of page" />\n <div class="atk-btn atk-btn-next">Next</div>\n </div>\n </div>'),this.$input=this.$el.querySelector(".atk-input"),this.$input.value=`${this.page}`,this.$input.oninput=()=>this.input(),this.$input.onkeydown=t=>this.keydown(t),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(t,e){this.page=Math.ceil(t/this.pageSize)+1,this.total=e,this.setInput(this.page),this.checkDisabled()}setInput(t){this.$input.value=`${t}`}input(t=!1){window.clearTimeout(this.inputTimer);const e=this.$input.value.trim(),n=()=>{if(""===e)return void this.setInput(this.page);let t=Number(e);Number.isNaN(t)||t<1?this.setInput(this.page):(t>this.maxPage&&(this.setInput(this.maxPage),t=this.maxPage),this.change(t))};t?n():this.inputTimer=window.setTimeout((()=>n()),800)}prev(){const t=this.page-1;t<1||this.change(t)}next(){const t=this.page+1;t>this.maxPage||this.change(t)}change(t){this.page=t,this.conf.onChange(this.offset),this.setInput(t),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(t){const e=t.keyCode||t.which;if(38===e){const t=Number(this.$input.value)+1;if(t>this.maxPage)return;this.setInput(t),this.input()}else if(40===e){const t=Number(this.$input.value)-1;if(t<1)return;this.setInput(t),this.input()}else 13===e&&this.input(!0)}setLoading(t){t?x(this.$el):C(this.$el)}}const ne={createInstance(t){const e=new ee(t.total,{pageSize:t.pageSize,onChange:e=>h(this,null,(function*(){if(!0===t.list.conf.editorTravel&&t.list.ctx.editorTravelBack(),yield t.list.fetchComments(e),t.list.repositionAt){(t.list.scrollListenerAt||window).scroll({top:t.list.repositionAt?g(t.list.repositionAt).top:0,left:0})}}))});return[e,e.$el]},setLoading(t){this.instance.setLoading(t)},update(t,e){this.instance.update(t,e)},next(){this.instance.next()}};class ie{constructor(t){d(this,"conf"),d(this,"$el"),d(this,"$loading"),d(this,"$text"),d(this,"offset",0),d(this,"total",0),d(this,"origText","Load More"),this.conf=t,this.origText=this.conf.text||this.origText,this.$el=u(`<div class="atk-list-read-more" style="display: none;">\n <div class="atk-list-read-more-inner">\n <div class="atk-loading-icon" style="display: none;"></div>\n <span class="atk-text">${this.origText}</span>\n </div>\n </div>`),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(t){this.$loading.style.display=t?"":"none",this.$text.style.display=t?"none":""}showErr(t){this.setLoading(!1),this.$text.innerText=t,this.$el.classList.add("atk-err"),window.setTimeout((()=>{this.$text.innerText=this.origText,this.$el.classList.remove("atk-err")}),2e3)}update(t,e){this.offset=t,this.total=e,this.checkDisabled()}checkDisabled(){this.hasMore?this.show():this.hide()}}const se={pagination:ne,"read-more":{createInstance(t){const e=new ie({pageSize:t.pageSize,onClick:e=>h(this,null,(function*(){yield t.list.fetchComments(e)})),text:At("loadMore")});if(t.list.conf.pagination.autoLoad){const n=t.list.scrollListenerAt||document;this.autoLoadScrollEvent&&n.removeEventListener("scroll",this.autoLoadScrollEvent),this.autoLoadScrollEvent=()=>{if("read-more"!==t.mode||!(null==e?void 0:e.hasMore)||t.list.getLoading())return;const n=t.list.$el.querySelector(".atk-list-comments-wrap > .atk-comment-wrap:nth-last-child(3)");n&&function(t,e=document.documentElement){const n=e.clientHeight,i=e.scrollTop,s=i+n,a=t.getBoundingClientRect();return a.top+i+a.height<=s}(n,t.list.scrollListenerAt)&&e.click()},n.addEventListener("scroll",this.autoLoadScrollEvent)}return[e,e.$el]},setLoading(t){this.instance.setLoading(t)},update(t,e){this.instance.update(t,e)},showErr(t){this.instance.showErr(t)},next(){this.instance.click()}}};class ae{constructor(t){d(this,"conf"),this.conf=t,this.init()}getAdaptor(){return se[this.conf.mode]}init(){const t=this.getAdaptor(),[e,n]=t.createInstance(this.conf);t.instance=e,t.el=n,this.conf.list.$el.append(t.el)}setLoading(t){this.getAdaptor().setLoading(t)}update(t,e){this.getAdaptor().update(t,e)}getEl(){return this.getAdaptor().el}showErr(t){const e=this.getAdaptor(),n=e.showErr;n&&n.bind(e)(t)}setMode(t){t!==this.conf.mode&&(this.getEl().remove(),this.conf.mode=t,this.init())}next(){this.getAdaptor().next()}}function re(t,e,n){const i=function(t,e){const n=t.split("."),i=e.split(".");for(let s=0;s<3;s++){const t=Number(n[s]),e=Number(i[s]);if(t>e)return 1;if(e>t)return-1;if(!Number.isNaN(t)&&Number.isNaN(e))return 1;if(Number.isNaN(t)&&!Number.isNaN(e))return-1}return 0}(e,n);if(0!==i){const s=u(`<div>请更新 Artalk ${At(i<0?"frontend":"backend")}以获得完整体验 (<a href="https://artalk.js.org/" target="_blank">帮助文档</a>)<br/><br/><span style="color: var(--at-color-meta);">当前版本:${At("frontend")} ${e} / ${At("backend")} ${n}</span><br/><br/></div>`),a=u('<span style="cursor:pointer">忽略</span>');return a.onclick=()=>{L(t.$el.parentElement,null),t.ctx.conf.versionCheck=!1,t.fetchComments(0)},s.append(a),L(t.$el.parentElement,s,'<span class="atk-warn-title">Artalk Warn</span>'),!0}return!1}function oe(t){const{$dropdownWrap:e,dropdownList:n}=t;if(e.querySelector(".atk-dropdown"))return;e.classList.add("atk-dropdown-wrap"),e.append(u('<span class="atk-arrow-down-icon"></span>'));let i=0;const s=u('<ul class="atk-dropdown atk-fade-in"></ul>');n.forEach(((t,e)=>{const n=t[0],a=t[1],r=u('<li class="atk-dropdown-item"><span></span></li>'),o=r.querySelector("span");o.innerText=n,o.onclick=()=>{((t,e,n,a)=>{a(),i=t,s.querySelectorAll(".active").forEach((t=>{t.classList.remove("active")})),e.classList.add("active"),s.style.display="none",setTimeout((()=>{s.style.display=""}),80)})(e,r,0,a)},s.append(r),e===i&&r.classList.add("active")})),e.append(s)}const le={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,scrollable:!1},imgUpload:!0,reqTimeout:15e3,versionCheck:!0,useBackendConf:!0,locale:"zh-CN"};function ce(t){const e=w(le,t);if("string"==typeof e.el&&e.el)try{const t=document.querySelector(e.el);if(!t)throw Error(`Target element "${e.el}" was not found.`);e.el=t}catch(n){throw console.error(n),new Error("Please check your Artalk `el` config.")}return e.server=e.server.replace(/\/$/,"").replace(/\/api\/?$/,""),e.pageKey||(e.pageKey=`${window.location.pathname}`),e.pageTitle||(e.pageTitle=`${document.title}`),"auto"===e.locale&&(e.locale=navigator.language),e}function de(t){const e=["el","pageKey","pageTitle","server","site","darkMode"];return Object.keys(t).forEach((n=>{e.includes(n)&&delete t[n]})),t.emoticons&&"string"==typeof t.emoticons&&(t.emoticons=t.emoticons.trim(),t.emoticons.startsWith("[")||t.emoticons.startsWith("{")?t.emoticons=JSON.parse(t.emoticons):"false"===t.emoticons&&(t.emoticons=!1)),t}le.vote=!1,le.uaBadge=!1,le.emoticons=!1;class he extends b{constructor(t){super(t),d(this,"$commentsWrap"),d(this,"data"),d(this,"isLoading",!1),d(this,"confLoaded",!1),d(this,"noCommentText"),d(this,"_nestSortBy"),d(this,"_flatMode"),d(this,"_pageMode"),d(this,"pgHolder"),d(this,"_pageSize"),d(this,"scrollListenerAt"),d(this,"repositionAt"),d(this,"renderComment"),d(this,"paramsEditor"),d(this,"onAfterLoad"),d(this,"unread",[]),d(this,"unreadHighlight"),this.$el=u('<div class="atk-list-lite">\n <div class="atk-list-comments-wrap"></div>\n </div>'),this.$commentsWrap=this.$el.querySelector(".atk-list-comments-wrap"),window.setInterval((()=>{this.$el.querySelectorAll("[data-atk-comment-date]").forEach((t=>{const e=t.getAttribute("data-atk-comment-date");t.innerText=y(new Date(Number(e)),this.ctx)}))}),3e4),this.ctx.on("conf-loaded",(()=>{}))}get nestSortBy(){return this._nestSortBy||this.ctx.conf.nestSort||"DATE_ASC"}set nestSortBy(t){this._nestSortBy=t}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(t){this._flatMode=t}get pageMode(){return this._pageMode||(this.conf.pagination.readMore?"read-more":"pagination")}set pageMode(t){var e;this._pageMode=t,null==(e=this.pgHolder)||e.setMode(this._pageMode)}get pageSize(){return this._pageSize||this.conf.pagination.pageSize}set pageSize(t){this._pageSize=t}getData(){return this.data}clearData(){this.data=void 0}getLoading(){return this.isLoading}getCommentsWrapEl(){return this.$commentsWrap}setLoading(t,e=!1){var n;this.isLoading=t,e?function(t,e){t?x(e):C(e)}(t,this.$el):null==(n=this.pgHolder)||n.setLoading(t)}fetchComments(t){return h(this,null,(function*(){if(this.isLoading)return;const e=0===t,n=t=>this.setLoading(t,e);let i;n(!0),this.ctx.trigger("list-load"),("read-more"===this.pageMode&&e||"pagination"===this.pageMode)&&this.ctx.clearAllComments();try{i=yield this.ctx.getApi().comment.get(t,this.pageSize,this.flatMode,this.paramsEditor)}catch(s){throw this.onError(s.msg||String(s),t,s.data),s}finally{n(!1)}L(this.$el,null);try{this.onLoad(i,t)}catch(s){throw this.onError(String(s),t),s}finally{n(!1)}}))}onLoad(t,e){if(this.data=t,!this.confLoaded){const e=de(t.conf.frontend_conf);this.conf.useBackendConf?this.ctx.updateConf(e):this.ctx.updateConf({}),this.confLoaded=!0}this.ctx.conf.versionCheck&&re(this,Mt,t.api_version.version)||(this.importComments(t.comments),this.refreshPagination(e,this.flatMode?t.total:t.total_roots),this.refreshUI(),this.ctx.updateNotifies(t.unread||[]),this.ctx.trigger("list-loaded"),this.onAfterLoad&&this.onAfterLoad(t))}refreshPagination(t,e){var n;this.pgHolder||(this.pgHolder=new ae({list:this,mode:this.pageMode,pageSize:this.pageSize,total:e})),null==(n=this.pgHolder)||n.update(t,e)}onError(t,e,n){var i;this.confLoaded||this.ctx.updateConf({}),t=String(t),console.error(t),0===e||"read-more"!==this.pageMode?L(this.$el,function(t,e,n){const i=u(`<span>${e},${At("listLoadFailMsg")}<br/></span>`),s=u(`<span style="cursor:pointer;">${At("listRetry")}</span>`);s.onclick=()=>t.fetchComments(0),i.appendChild(s);const a=u('<span atk-only-admin-show> | <span style="cursor:pointer;">打开控制台</span></span>');i.appendChild(a),Ot.data.isAdmin||a.classList.add("atk-hide");let r="";if(null==n?void 0:n.err_no_site){const e={create_name:t.ctx.conf.site,create_urls:`${window.location.protocol}//${window.location.host}`};r=`sites|${JSON.stringify(e)}`}return a.onclick=()=>t.ctx.showSidebar({view:r}),i}(this,t,n)):null==(i=this.pgHolder)||i.showErr(this.$t("loadFail"))}refreshUI(){!function(t){const e=t.ctx.getCommentList().length<=0;let n=t.getCommentsWrapEl().querySelector(".atk-list-no-comment");e?n||(n=u('<div class="atk-list-no-comment"></div>'),n.innerHTML=t.noCommentText||t.ctx.conf.noComment||t.ctx.$t("noComment"),t.getCommentsWrapEl().appendChild(n)):null==n||n.remove(),t.ctx.checkAdminShowEl()}(this)}reload(){this.fetchComments(0)}createComment(t,e){e||(e=this.ctx.getCommentDataList());const n=new te(this.ctx,t,{isFlatMode:this.flatMode,afterRender:()=>{this.renderComment&&this.renderComment(n)},onDelete:t=>{this.ctx.deleteComment(t),this.refreshUI()},replyTo:t.rid?e.find((e=>e.id===t.rid)):void 0});return n.render(),this.ctx.getCommentList().push(n),n}importComments(t){this.flatMode?t.forEach((e=>{this.putCommentFlatMode(e,t,"append")})):this.importCommentsNest(t)}importCommentsNest(t){const e=function(t,e="DATE_DESC",n=2){const i=[];t.filter((t=>0===t.rid)).forEach((e=>{const s={id:e.id,comment:e,children:[],level:1};s.parent=s,i.push(s),function e(i){const s=t.filter((t=>t.rid===i.id));0!==s.length&&(i.level>=n&&(i=i.parent),s.forEach((t=>{const n={id:t.id,comment:t,children:[],parent:i,level:i.level+1};i.children.push(n),e(n)})))}(s)}));const s=(n,i)=>{let s=n.id-i.id;return"DATE_ASC"===e?s=+new Date(n.comment.date)-+new Date(i.comment.date):"DATE_DESC"===e?s=+new Date(i.comment.date)-+new Date(n.comment.date):"SRC_INDEX"===e?s=t.indexOf(n.comment)-t.indexOf(i.comment):"VOTE_UP_DESC"===e&&(s=i.comment.vote_up-n.comment.vote_up),s};return function t(e){e.forEach((e=>{e.children=e.children.sort(s),t(e.children)}))}(i),i}(t,this.nestSortBy,this.conf.nestMax);e.forEach((e=>{const n=this.createComment(e.comment,t);this.$commentsWrap.appendChild(n.getEl()),n.getRender().playFadeAnim();const i=this;!function e(n,s){s.children.forEach((s=>{const a=s.comment,r=i.createComment(a,t);n.putChild(r),e(r,s)}))}(n,e),n.getRender().checkHeightLimit()}))}putCommentFlatMode(t,e,n){t.is_collapsed&&(t.is_allow_reply=!1);const i=this.createComment(t,e);return t.visible&&("append"===n&&this.$commentsWrap.append(i.getEl()),"prepend"===n&&this.$commentsWrap.prepend(i.getEl()),i.getRender().playFadeAnim()),i.getRender().checkHeightLimit(),i}insertComment(t){if(this.flatMode){S(this.putCommentFlatMode(t,this.ctx.getCommentDataList(),"prepend").getEl())}else{const e=this.createComment(t);if(0===t.rid)this.$commentsWrap.prepend(e.getEl());else{const n=this.ctx.findComment(t.rid);n&&(n.putChild(e,"DATE_ASC"===this.nestSortBy?"append":"prepend"),e.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()})))}e.getRender().checkHeightLimit(),S(e.getEl()),e.getRender().playFadeAnim()}this.data&&(this.data.total+=1),this.refreshUI(),this.ctx.trigger("list-loaded"),this.ctx.trigger("list-inserted",t)}updateComment(t){const e=this.ctx.findComment(t.id);e&&e.setData(t)}updateUnread(t){this.unread=t,!0===this.unreadHighlight&&this.ctx.getCommentList().forEach((t=>{const e=this.unread.find((e=>e.comment_id===t.getID()));e?(t.getRender().setUnread(!0),t.getRender().setOpenAction((()=>{window.open(e.read_link),this.unread=this.unread.filter((e=>e.comment_id!==t.getID())),this.ctx.updateNotifies(this.unread)}))):t.getRender().setUnread(!1)}))}}class ue extends he{constructor(t){const e=u('<div class="atk-list">\n <div class="atk-list-header">\n <div class="atk-comment-count">\n <div class="atk-text"></div>\n </div>\n <div class="atk-right-action">\n <span data-action="admin-close-comment" class="atk-hide" atk-only-admin-show></span>\n <span data-action="open-sidebar" class="atk-hide atk-on">\n <span class="atk-unread-badge" style="display: none;"></span>\n <div class="atk-text"></div>\n </span>\n </div>\n </div>\n <div class="atk-list-body"></div>\n <div class="atk-list-footer">\n <div class="atk-copyright"></div>\n </div>\n</div>\n');super(t),d(this,"$closeCommentBtn"),d(this,"$openSidebarBtn"),d(this,"$unreadBadge"),d(this,"$commentCount"),d(this,"$commentCountNum"),d(this,"$dropdownWrap"),d(this,"goToCommentFounded",!1),d(this,"goToCommentDelay",!0),e.querySelector(".atk-list-body").append(this.$el),this.$el=e,this.repositionAt=this.$el,this.initListActionBtn();this.$commentCount=this.$el.querySelector(".atk-comment-count");const n=()=>{this.$commentCount.innerHTML=this.$t("counter",{count:'<span class="atk-comment-count-num">0</span>'}),this.$commentCountNum=this.$commentCount.querySelector(".atk-comment-count-num")};n(),this.$el.querySelector(".atk-copyright").innerHTML=`Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${Mt}">Artalk</a>`,this.ctx.on("conf-loaded",(()=>{n(),this.refreshUI()}))}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 t;super.refreshUI(),this.$commentCountNum.innerText=String(Number(null==(t=this.data)?void 0:t.total)||0),Ot.data.nick&&Ot.data.email?this.$openSidebarBtn.classList.remove("atk-hide"):this.$openSidebarBtn.classList.add("atk-hide"),this.$openSidebarBtn.querySelector(".atk-text").innerText=Ot.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():function(t){var e,n;const{$dropdownWrap:i}=t;i.classList.remove("atk-dropdown-wrap"),null==(e=i.querySelector(".atk-arrow-down-icon"))||e.remove(),null==(n=i.querySelector(".atk-dropdown"))||n.remove()}({$dropdownWrap:this.$commentCount})}onLoad(t,e){super.onLoad(t,e),this.goToCommentFounded||this.checkGoToCommentByUrlHash(),!0===this.ctx.conf.editorTravel&&this.ctx.editorTravelBack()}checkGoToCommentByUrlHash(){var t;let e=Number(m("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 n=this.ctx.findComment(e);if(!n)return void(null==(t=this.pgHolder)||t.next());const i=m("atk_notify_key");i&&this.ctx.getApi().user.markRead(e,i).then((()=>{this.unread=this.unread.filter((t=>t.comment_id!==e)),this.updateUnread(this.unread)})),n.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()}));const s=()=>{S(n.getEl(),!1),n.getEl().classList.remove("atk-flash-once"),window.setTimeout((()=>{n.getEl().classList.add("atk-flash-once")}),150)};this.goToCommentDelay?window.setTimeout((()=>s()),350):s(),this.goToCommentFounded=!0,this.goToCommentDelay=!0}adminPageEditSave(){this.data&&this.data.page&&(this.ctx.editorShowLoading(),this.ctx.getApi().page.pageEdit(this.data.page).then((t=>{this.data&&(this.data.page=l({},t)),this.refreshUI()})).catch((t=>{this.ctx.editorShowNotify(`${this.$t("editFail")}: ${t.msg||String(t)}`,"e")})).finally((()=>{this.ctx.editorHideLoading()})))}showUnreadBadge(t){t>0?(this.$unreadBadge.innerText=`${Number(t||0)}`,this.$unreadBadge.style.display="block"):this.$unreadBadge.style.display="none"}initDropdown(){const t=t=>{this.paramsEditor=t,this.fetchComments(0)};oe({$dropdownWrap:this.$commentCount,dropdownList:[[this.$t("sortLatest"),()=>{t((t=>{t.sort_by="date_desc"}))}],[this.$t("sortBest"),()=>{t((t=>{t.sort_by="vote"}))}],[this.$t("sortOldest"),()=>{t((t=>{t.sort_by="date_asc"}))}],[this.$t("sortAuthor"),()=>{t((t=>{t.view_only_admin=!0}))}]]})}updateUnread(t){super.updateUnread(t),this.showUnreadBadge((null==t?void 0:t.length)||0)}}class pe{constructor(t,e){d(this,"conf"),d(this,"$root"),d(this,"markedReplacers",[]),d(this,"commentList",[]),d(this,"eventList",[]),this.conf=t,this.$root=e||document.createElement("div"),this.$root.classList.add("artalk"),this.$root.innerHTML=""}inject(t,e){this[t]=e}get(t){return this[t]}getApi(){return this.api}getCommentList(){return this.commentList}getCommentDataList(){return this.commentList.map((t=>t.getData()))}findComment(t){return this.commentList.find((e=>e.getData().id===t))}deleteComment(t){let e;if("number"==typeof t){const n=this.findComment(t);if(!n)throw Error(`Comment ${t} cannot be found`);e=n}else e=t;if(e.getEl().remove(),this.commentList.splice(this.commentList.indexOf(e),1),this.list){const t=this.list.getData();t&&(t.total-=1),this.list.refreshUI()}}clearAllComments(){this.list&&(this.list.getCommentsWrapEl().innerHTML="",this.list.clearData()),this.commentList=[]}insertComment(t){var e;null==(e=this.list)||e.insertComment(t)}updateComment(t){var e;null==(e=this.list)||e.updateComment(t)}replyComment(t,e,n){this.editor.setReply(t,e,n)}cancelReplyComment(){this.editor.cancelReply()}editComment(t,e){this.editor.setEditComment(t,e)}cancelEditComment(){this.editor.cancelEditComment()}updateNotifies(t){var e;null==(e=this.list)||e.updateUnread(t)}listReload(){var t;null==(t=this.list)||t.reload()}reload(){this.listReload()}listRefreshUI(){var t;null==(t=this.list)||t.refreshUI()}listHashGotoCheck(){if(!(this.list&&this.list instanceof ue))return;const t=this.list;t.goToCommentDelay=!1,t.checkGoToCommentByUrlHash()}editorOpen(){this.editor.open()}editorClose(){this.editor.close()}editorShowLoading(){this.editor.showLoading()}editorHideLoading(){this.editor.hideLoading()}editorShowNotify(t,e){this.editor.showNotify(t,e)}editorTravel(t){this.editor.travel(t)}editorTravelBack(){this.editor.travelBack()}showSidebar(t){this.sidebarLayer.show(t)}hideSidebar(){this.sidebarLayer.hide()}checkAdmin(t){this.checkerLauncher.checkAdmin(t)}checkCaptcha(t){this.checkerLauncher.checkCaptcha(t)}checkAdminShowEl(){const t=[];this.$root.querySelectorAll("[atk-only-admin-show]").forEach((e=>t.push(e)));const{$wrap:e}=O();e&&e.querySelectorAll("[atk-only-admin-show]").forEach((e=>t.push(e)));const n=document.querySelector(".atk-sidebar");n&&n.querySelectorAll("[atk-only-admin-show]").forEach((e=>t.push(e))),t.forEach((t=>{this.user.data.isAdmin?t.classList.remove("atk-hide"):t.classList.add("atk-hide")}))}on(t,e,n="internal"){this.eventList.push({name:t,handler:e,scope:n})}off(t,e,n="internal"){this.eventList=this.eventList.filter((i=>e?!(i.name===t&&i.handler===e&&i.scope===n):!(i.name===t&&i.scope===n)))}trigger(t,e,n){this.eventList.filter((e=>e.name===t&&(!n||e.scope===n))).map((t=>t.handler)).forEach((t=>t(e)))}$t(t,e={}){return At(t,e)}setDarkMode(t){R(this,t)}updateConf(t){this.conf=w(this.conf,t),this.trigger("conf-loaded")}getMarkedInstance(){return kt()}}class me{constructor(t,e){return d(this,"ctx"),d(this,"$el"),d(this,"$content"),d(this,"$actions"),this.ctx=t,this.$el=u('<div class="atk-layer-dialog-wrap">\n <div class="atk-layer-dialog">\n <div class="atk-layer-dialog-content"></div>\n <div class="atk-layer-dialog-actions"></div>\n </div>\n </div>'),this.$actions=this.$el.querySelector(".atk-layer-dialog-actions"),this.$content=this.$el.querySelector(".atk-layer-dialog-content"),this.$content.appendChild(e),this}setYes(t){const e=u(`<button data-action="confirm">${this.ctx.$t("confirm")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}setNo(t){const e=u(`<button data-action="cancel">${this.ctx.$t("cancel")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}onBtnClick(t){return e=>{const n=t(e.currentTarget,this);void 0!==n&&!0!==n||this.$el.remove()}}}function ge(t){const e=u('<div class="atk-checker-iframe-wrap"></div>'),n=u('<iframe class="atk-fade-in"></iframe>');n.style.display="none",x(e,{transparentBg:!0}),n.src=`${t.getCtx().conf.server}/api/captcha/get?t=${+new Date}`,n.onload=()=>{n.style.display="",C(e)},e.append(n);const i=u('<div class="atk-close-btn"><i class="atk-icon atk-icon-close"></i></div>');e.append(i),t.hideInteractInput();let s=!1;return function e(){return h(this,null,(function*(){var n;if(yield(n=1e3,new Promise((t=>{window.setTimeout((()=>{t(null)}),n)}))),s)return;let i=!1;try{i=(yield t.getCtx().getApi().captcha.captchaStatus()).is_pass}catch(a){i=!1}i?t.triggerSuccess():e()}))}(),i.onclick=()=>{s=!0,t.cancel()},e}const fe={request:(t,e)=>t.getApi().captcha.captchaCheck(e),body:t=>t.get("iframe")?ge(t):function(t){const e=u(`<span><img class="atk-captcha-img" src="${t.get("img_data")||""}">${t.getCtx().$t("captchaCheck")}</span>`);return e.querySelector(".atk-captcha-img").onclick=()=>{const n=e.querySelector(".atk-captcha-img");t.getApi().captcha.captchaGet().then((t=>{n.setAttribute("src",t)})).catch((t=>{console.error("Failed to get captcha image ",t)}))},e}(t),onSuccess(t,e,n,i){t.set("val",n)},onError(t,e,n,i){i.querySelector(".atk-captcha-img").click(),i.querySelector('input[type="text"]').value=""}},ye={inputType:"password",request(t,e){const n={name:Ot.data.nick,email:Ot.data.email,password:e};return(()=>h(this,null,(function*(){return(yield t.getApi().user.login(n.name,n.email,n.password)).token})))()},body:t=>u(`<span>${t.getCtx().$t("adminCheck")}</span>`),onSuccess(t,e,n,i){Ot.update({isAdmin:!0,token:e}),t.getCtx().trigger("user-changed",Ot.data),t.getCtx().listReload()},onError(t,e,n,i){}};class $e{constructor(t){d(this,"ctx"),d(this,"launched",[]),this.ctx=t}checkCaptcha(t){this.fire(fe,t,(e=>{e.set("img_data",t.imgData),e.set("iframe",t.iframe)}))}checkAdmin(t){this.fire(ye,t)}fire(t,e,n){if(this.launched.includes(t))return;this.launched.push(t);const i=new M(this.ctx,`checker-${(new Date).getTime()}`);i.setMaskClickHide(!1),i.show();const s={};let a=!1;const r={set:(t,e)=>{s[t]=e},get:t=>s[t],getCtx:()=>this.ctx,getApi:()=>this.ctx.getApi(),getLayer:()=>i,hideInteractInput:()=>{a=!0},triggerSuccess:()=>{this.close(t,i),t.onSuccess&&t.onSuccess(r,"","",o),e.onSuccess&&e.onSuccess("",d.$el)},cancel:()=>{this.close(t,i),e.onCancel&&e.onCancel()}};n&&n(r);const o=u();o.appendChild(t.body(r));const l=u(`<input id="check" type="${t.inputType||"text"}" autocomplete="off" required placeholder="">`);let c;o.appendChild(l),setTimeout((()=>l.focus()),80),l.onkeyup=t=>{"Enter"!==t.key&&13!==t.keyCode||(t.preventDefault(),i.getEl().querySelector('button[data-action="confirm"]').click())};const d=new me(this.ctx,o);d.setYes((n=>{const s=l.value.trim();c||(c=n.innerText);const a=()=>{n.innerText=c||"",n.classList.remove("error")};return n.innerText=`${this.ctx.$t("loading")}...`,t.request(r,s).then((n=>{this.close(t,i),t.onSuccess&&t.onSuccess(r,n,s,o),e.onSuccess&&e.onSuccess(s,d.$el)})).catch((e=>{var i;i=String(e.msg||String(e)),n.innerText=i,n.classList.add("error"),t.onError&&t.onError(r,e,s,o);const c=setTimeout((()=>a()),3e3);l.onfocus=()=>{a(),clearTimeout(c)}})),!1})),d.setNo((()=>(this.close(t,i),e.onCancel&&e.onCancel(),!1))),a&&(l.style.display="none",d.$el.querySelector(".atk-layer-dialog-actions").style.display="none"),i.getEl().append(d.$el),e.onMount&&e.onMount(d.$el)}close(t,e){e.disposeNow(),this.launched=this.launched.filter((e=>e!==t))}}function ve(t,e,n,i){return h(this,null,(function*(){var s,a;if(Ot.data.token){const t=new Headers(n.headers);t.set("Authorization",`Bearer ${Ot.data.token}`),n.headers=t}const r=yield function(t,e,n,i){var s;const a=new AbortController;null==(s=i.signal)||s.addEventListener("abort",(()=>a.abort()));let r=fetch(e,c(l({},i),{signal:a.signal}));if(n>0){const t=setTimeout((()=>a.abort()),n);r.finally((()=>{clearTimeout(t)}))}return r=r.catch((t=>{throw"AbortError"===(t||{}).name?new Error(At("reqAborted")):t})),r}(0,e,i||t.conf.reqTimeout||15e3,n),o=r.status,d=[401,400].includes(o);if(!r.ok&&!d)throw new Error(`${At("reqGot")} ${o}`);let h=yield r.json();const u=(i,s)=>{ve(t,e,n).then((t=>{i(t)})).catch((t=>{s(t)}))};if((null==(s=h.data)?void 0:s.need_captcha)?h=yield new Promise(((e,n)=>{t.checkCaptcha({imgData:h.data.img_data,iframe:h.data.iframe,onSuccess:()=>{u(e,n)},onCancel:()=>{n(h)}})})):((null==(a=h.data)?void 0:a.need_login)||d)&&(h=yield new Promise(((e,n)=>{t.checkAdmin({onSuccess:()=>{u(e,n)},onCancel:()=>{n(h)}})}))),!h.success)throw h;return h}))}function ke(t){const e=new FormData;return Object.keys(t).forEach((n=>e.append(n,String(t[n])))),e}!function(){function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function n(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&a(t,e)}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function a(t,e){return(a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function o(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return o(t)}function c(t){var e=r();return function(){var n,i=s(t);if(e){var a=s(this).constructor;n=Reflect.construct(i,arguments,a)}else n=i.apply(this,arguments);return l(this,n)}}function d(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=s(t)););return t}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var i=d(t,e);if(i){var s=Object.getOwnPropertyDescriptor(i,e);return s.get?s.get.call(arguments.length<3?t:n):s.value}},h.apply(this,arguments)}var u=function(){function e(){t(this,e),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return n(e,[{key:"addEventListener",value:function(t,e,n){t in this.listeners||(this.listeners[t]=[]),this.listeners[t].push({callback:e,options:n})}},{key:"removeEventListener",value:function(t,e){if(t in this.listeners)for(var n=this.listeners[t],i=0,s=n.length;i<s;i++)if(n[i].callback===e)return void n.splice(i,1)}},{key:"dispatchEvent",value:function(t){if(t.type in this.listeners){for(var e=this.listeners[t.type].slice(),n=0,i=e.length;n<i;n++){var s=e[n];try{s.callback.call(this,t)}catch(a){Promise.resolve().then((function(){throw a}))}s.options&&s.options.once&&this.removeEventListener(t.type,s.callback)}return!t.defaultPrevented}}}]),e}(),p=function(e){i(r,e);var a=c(r);function r(){var e;return t(this,r),(e=a.call(this)).listeners||u.call(o(e)),Object.defineProperty(o(e),"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(o(e),"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(o(e),"reason",{value:void 0,writable:!0,configurable:!0}),e}return n(r,[{key:"toString",value:function(){return"[object AbortSignal]"}},{key:"dispatchEvent",value:function(t){"abort"===t.type&&(this.aborted=!0,"function"==typeof this.onabort&&this.onabort.call(this,t)),h(s(r.prototype),"dispatchEvent",this).call(this,t)}}]),r}(u),m=function(){function e(){t(this,e),Object.defineProperty(this,"signal",{value:new p,writable:!0,configurable:!0})}return n(e,[{key:"abort",value:function(t){var e;try{e=new Event("abort")}catch(i){"undefined"!=typeof document?document.createEvent?(e=document.createEvent("Event")).initEvent("abort",!1,!1):(e=document.createEventObject()).type="abort":e={type:"abort",bubbles:!1,cancelable:!1}}var n=t;if(void 0===n)if("undefined"==typeof document)(n=new Error("This operation was aborted")).name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(s){(n=new Error("This operation was aborted")).name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(e)}},{key:"toString",value:function(){return"[object AbortController]"}}]),e}();function g(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):"function"==typeof t.Request&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function f(t){"function"==typeof t&&(t={fetch:t});var e=t,n=e.fetch,i=e.Request,s=void 0===i?n.Request:i,a=e.AbortController,r=e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,o=void 0!==r&&r;if(!g({fetch:n,Request:s,AbortController:a,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:n,Request:l};var l=s;(l&&!l.prototype.hasOwnProperty("signal")||o)&&((l=function(t,e){var n;e&&e.signal&&(n=e.signal,delete e.signal);var i=new s(t,e);return n&&Object.defineProperty(i,"signal",{writable:!1,enumerable:!1,configurable:!0,value:n}),i}).prototype=s.prototype);var c=n;return{fetch:function(t,e){var n=l&&l.prototype.isPrototypeOf(t)?t.signal:e?e.signal:void 0;if(n){var i;try{i=new DOMException("Aborted","AbortError")}catch(a){(i=new Error("Aborted")).name="AbortError"}if(n.aborted)return Promise.reject(i);var s=new Promise((function(t,e){n.addEventListener("abort",(function(){return e(i)}),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([s,c(t,e)])}return c(t,e)},Request:l}}"undefined"!=typeof Symbol&&Symbol.toStringTag&&(m.prototype[Symbol.toStringTag]="AbortController",p.prototype[Symbol.toStringTag]="AbortSignal"),function(t){if(g(t))if(t.fetch){var e=f(t),n=e.fetch,i=e.Request;t.fetch=n,t.Request=i,Object.defineProperty(t,"AbortController",{writable:!0,enumerable:!1,configurable:!0,value:m}),Object.defineProperty(t,"AbortSignal",{writable:!0,enumerable:!1,configurable:!0,value:p})}else console.warn("fetch() is not available, cannot install abortcontroller-polyfill")}("undefined"!=typeof self?self:U)}();class we{constructor(t,e){d(this,"api"),d(this,"ctx"),this.api=t,this.ctx=e}POST(t,e){return h(this,null,(function*(){return function(t,e,n){return h(this,null,(function*(){const i={method:"POST"};return n=l({site_name:t.conf.site||""},n||{}),i.body=ke(n),(yield ve(t,e,i)).data||{}}))}(this.ctx,this.api.baseURL+t,e)}))}Fetch(t,e,n){return h(this,null,(function*(){return ve(this.ctx,this.api.baseURL+t,e,n)}))}}const be={comment:class extends we{get(t,e,n,i){const s={page_key:this.ctx.conf.pageKey,site_name:this.ctx.conf.site||"",limit:e,offset:t};return n&&(s.flat_mode=n),Ot.checkHasBasicUserInfo()&&(s.name=Ot.data.nick,s.email=Ot.data.email),i&&i(s),this.POST("/get",s)}add(t){return h(this,null,(function*(){const e={name:t.nick,email:t.email,link:t.link,content:t.content,rid:t.rid,page_key:t.page_key,ua:yield $()};t.page_title&&(e.page_title=t.page_title),t.site_name&&(e.site_name=t.site_name);return(yield this.POST("/add",e)).comment}))}commentEdit(t){return h(this,null,(function*(){const e=l({},t);return(yield this.POST("/admin/comment-edit",e)).comment}))}commentDel(t,e){const n={id:String(t),site_name:e||""};return this.POST("/admin/comment-del",n)}vote(t,e){return h(this,null,(function*(){const n={target_id:t,type:e};Ot.checkHasBasicUserInfo()&&(n.name=Ot.data.nick,n.email=Ot.data.email);return yield this.POST("/vote",n)}))}},page:class extends we{pageGet(t,e,n){return h(this,null,(function*(){const i={site_name:t||"",offset:e||0,limit:n||15};return yield this.POST("/admin/page-get",i)}))}pageEdit(t){return h(this,null,(function*(){const e={id:t.id,key:t.key,title:t.title,admin_only:t.admin_only,site_name:t.site_name||this.ctx.conf.site};return(yield this.POST("/admin/page-edit",e)).page}))}pageDel(t,e){const n={key:String(t),site_name:e||""};return this.POST("/admin/page-del",n)}pageFetch(t,e,n){return h(this,null,(function*(){const i={};t&&(i.id=t),e&&(i.site_name=e),n&&(i.get_status=n);return yield this.POST("/admin/page-fetch",i)}))}pv(){return h(this,null,(function*(){const t={page_key:this.ctx.conf.pageKey||"",page_title:this.ctx.conf.pageTitle||""};return(yield this.POST("/pv",t)).pv}))}stat(t,e,n){return h(this,null,(function*(){const i={type:t};e&&(i.page_keys=Array.isArray(e)?e.join(","):e),n&&(i.limit=n);return yield this.POST("/stat",i)}))}},site:class extends we{siteGet(){return h(this,null,(function*(){return(yield this.POST("/admin/site-get",{})).sites}))}siteAdd(t,e){return h(this,null,(function*(){const n={name:t,urls:e,site_name:""};return(yield this.POST("/admin/site-add",n)).site}))}siteEdit(t){return h(this,null,(function*(){const e={id:t.id,name:t.name||"",urls:t.urls||""};return(yield this.POST("/admin/site-edit",e)).site}))}siteDel(t,e=!1){const n={id:t,del_content:e};return this.POST("/admin/site-del",n)}export(){return h(this,null,(function*(){var t;return(null==(t=(yield this.Fetch("/admin/export",{method:"POST"},0)).data)?void 0:t.data)||""}))}},user:class extends we{login(t,e,n){return h(this,null,(function*(){const i={name:t,email:e,password:n};return yield this.POST("/login",i)}))}userGet(t,e){const n=new AbortController,i={name:t,email:e};return{req:this.Fetch("/user-get",{method:"POST",body:ke(i),signal:n.signal}).then((t=>({user:t.data.user,is_login:t.data.is_login,unread:t.data.unread||[],unread_count:t.data.unread_count||0}))),abort:()=>{n.abort()}}}loginStatus(){return h(this,null,(function*(){return(yield this.POST("/login-status",{name:Ot.data.nick,email:Ot.data.email}))||{is_login:!1,is_admin:!1}}))}logout(){return h(this,null,(function*(){return this.POST("/logout")}))}markRead(t,e,n=!1){const i={comment_id:t,notify_key:e};return n&&(delete i.comment_id,delete i.notify_key,i.read_all=!0,i.name=Ot.data.nick,i.email=Ot.data.email),this.POST("/mark-read",i)}userList(t,e,n){return h(this,null,(function*(){const i={offset:t||0,limit:e||15};n&&(i.type=n);return yield this.POST("/admin/user-get",i)}))}userAdd(t,e){return h(this,null,(function*(){const n={name:t.name||"",email:t.email||"",password:e||"",link:t.link||"",is_admin:t.is_admin||!1,site_names:t.site_names_raw||"",receive_email:t.receive_email||!0,badge_name:t.badge_name||"",badge_color:t.badge_color||""};return(yield this.POST("/admin/user-add",n)).user}))}userEdit(t,e){return h(this,null,(function*(){const n={id:t.id,name:t.name||"",email:t.email||"",password:e||"",link:t.link||"",is_admin:t.is_admin||!1,site_names:t.site_names_raw||"",receive_email:t.receive_email||!0,badge_name:t.badge_name||"",badge_color:t.badge_color||""};return(yield this.POST("/admin/user-edit",n)).user}))}userDel(t){return this.POST("/admin/user-del",{id:String(t)})}},system:class extends we{conf(){return h(this,null,(function*(){return de((yield this.POST("/conf")).frontend_conf||{})}))}getSettings(){return h(this,null,(function*(){return yield this.POST("/admin/setting-get")}))}saveSettings(t){return h(this,null,(function*(){return yield this.POST("/admin/setting-save",{data:t})}))}version(){return h(this,null,(function*(){const t=yield fetch(`${this.api.baseURL}/version`,{method:"POST"});return yield t.json()}))}},captcha:class extends we{captchaGet(){return h(this,null,(function*(){return(yield this.POST("/captcha/refresh")).img_data||""}))}captchaCheck(t){return h(this,null,(function*(){return(yield this.POST("/captcha/check",{value:t})).img_data||""}))}captchaStatus(){return h(this,null,(function*(){return(yield this.POST("/captcha/status"))||{is_pass:!1}}))}},admin:class extends we{cacheFlushAll(){return this.POST("/admin/cache-flush",{flush_all:!0})}cacheWarmUp(){return this.POST("/admin/cache-warm",{})}},upload:class extends we{imgUpload(t){return h(this,null,(function*(){const e=ke({name:Ot.data.nick,email:Ot.data.email,page_key:this.ctx.conf.pageKey});e.set("file",t);const n={method:"POST",body:e};return(yield this.Fetch("/img-upload",n)).data||{}}))}}};class xe{constructor(t){d(this,"ctx"),this.ctx=t,Object.entries(be).forEach((([t,e])=>{this[t]=new e(this,this.ctx)}))}get baseURL(){return`${this.ctx.conf.server}/api`}}function Ce(t){const e={editor:t,isMoved:!1,move:t=>function(t,e){if(t.isMoved)return;t.isMoved=!0;const n=t.editor.getUI().$el;n.after(u('<div class="atk-editor-travel-placeholder"></div>'));const i=u("<div></div>");e.after(i),i.replaceWith(n),n.classList.add("atk-fade-in")}(e,t),back:()=>function(t){var e;if(!t.isMoved)return;t.isMoved=!1,null==(e=t.editor.ctx.$root.querySelector(".atk-editor-travel-placeholder"))||e.replaceWith(t.editor.getUI().$el),t.editor.cancelReply()}(e)};return e}class Se{constructor(t){d(this,"editor"),d(this,"$panel"),d(this,"$btn"),d(this,"onHeaderInput"),d(this,"contentTransformer"),d(this,"onContentUpdated"),this.editor=t}get ctx(){return this.editor.ctx}registerPanel(t="<div></div>"){return this.$panel=u(t),this.$panel}registerBtn(t){return this.$btn=u(`<span class="atk-plug-btn" data-plug-name="${this.constructor.name}">${t}</span>`),this.$btn}registerHeaderInputEvt(t){this.onHeaderInput=t}registerContentTransformer(t){this.contentTransformer=t}registerContentUpdatedEvt(t){this.onContentUpdated=t}getPanel(){return this.$panel}getBtn(){return this.$btn}}d(Se,"Name");class Ee extends Se{constructor(t){super(t),d(this,"emoticons",[]),d(this,"loadingTask",null),d(this,"$grpWrap"),d(this,"$grpSwitcher"),d(this,"isListLoaded",!1),d(this,"isImgLoaded",!1),this.editor=t,this.registerPanel('<div class="atk-editor-plug-emoticons"></div>'),this.registerBtn(this.ctx.$t("emoticon")),this.registerContentTransformer((t=>this.transEmoticonImageText(t))),window.setTimeout((()=>{this.loadEmoticonsData()}),1e3)}onPanelShow(){(()=>{h(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 h(this,null,(function*(){this.isListLoaded||(null===this.loadingTask?(this.loadingTask=(()=>h(this,null,(function*(){x(this.$panel),this.emoticons=yield this.handleData(this.ctx.conf.emoticons),C(this.$panel),this.loadingTask=null,this.isListLoaded=!0})))(),yield this.loadingTask):yield this.loadingTask)}))}handleData(t){return h(this,null,(function*(){if(!Array.isArray(t)&&["object","string"].includes(typeof t)&&(t=[t]),!Array.isArray(t))return L(this.$panel,"表情包数据必须为 Array/Object/String 类型"),C(this.$panel),[];const e=e=>{"object"==typeof e&&(e.name&&t.find((t=>t.name===e.name))||t.push(e))},n=t=>h(this,null,(function*(){yield Promise.all(t.map(((t,i)=>h(this,null,(function*(){if("object"!=typeof t||Array.isArray(t)){if(Array.isArray(t))yield n(t);else if("string"==typeof t){const i=yield this.remoteLoad(t);Array.isArray(i)?yield n(i):"object"==typeof i&&e(i)}}else e(t)})))))}));return yield n(t),t.forEach((t=>{if(this.isOwOFormat(t)){this.convertOwO(t).forEach((t=>{e(t)}))}else Array.isArray(t)&&t.forEach((t=>{e(t)}))})),t=t.filter((t=>"object"==typeof t&&!Array.isArray(t)&&!!t&&!!t.name)),this.solveNullKey(t),this.solveSameKey(t),t}))}remoteLoad(t){return h(this,null,(function*(){if(!t)return[];try{const e=yield fetch(t);return yield e.json()}catch(e){return C(this.$panel),L(this.$panel,`表情加载失败 ${String(e)}`),[]}}))}solveNullKey(t){t.forEach((t=>{t.items.forEach(((e,n)=>{e.key||(e.key=`${t.name} ${n+1}`)}))}))}solveSameKey(t){const e={};t.forEach((t=>{t.items.forEach((t=>{t.key&&""!==String(t.key).trim()&&(e[t.key]?e[t.key]++:e[t.key]=1,e[t.key]>1&&(t.key=`${t.key} ${e[t.key]}`))}))}))}isOwOFormat(t){try{return"object"==typeof t&&!!Object.values(t).length&&Array.isArray(Object.keys(Object.values(t)[0].container))&&Object.keys(Object.values(t)[0].container[0]).includes("icon")}catch(e){return!1}}convertOwO(t){const e=[];return Object.entries(t).forEach((([t,n])=>{const i={name:t,type:n.type,items:[]};n.container.forEach(((e,n)=>{const s=e.icon;if(/<(img|IMG)/.test(s)){const t=/src=["'](.*?)["']/.exec(s);t&&t.length>1&&(e.icon=t[1])}i.items.push({key:e.text||`${t} ${n+1}`,val:e.icon})})),e.push(i)})),e}initEmoticonsList(){this.$grpWrap=u('<div class="atk-grp-wrap"></div>'),this.$panel.append(this.$grpWrap),this.emoticons.forEach(((t,e)=>{const n=u('<div class="atk-grp" style="display: none;"></div>');this.$grpWrap.append(n),n.setAttribute("data-index",String(e)),n.setAttribute("data-grp-name",t.name),n.setAttribute("data-type",t.type),t.items.forEach((e=>{const i=u('<span class="atk-item"></span>');if(n.append(i),e.key&&!new RegExp(`^(${t.name})?\\s?[0-9]+$`).test(e.key)&&i.setAttribute("title",e.key),"image"===t.type){const t=document.createElement("img");t.src=e.val,t.alt=e.key,i.append(t)}else i.innerText=e.val;i.onclick=()=>{"image"===t.type?this.editor.insertContent(`:[${e.key}]`):this.editor.insertContent(e.val||"")}}))})),this.emoticons.length>1&&(this.$grpSwitcher=u('<div class="atk-grp-switcher"></div>'),this.$panel.append(this.$grpSwitcher),this.emoticons.forEach(((t,e)=>{const n=u("<span />");n.innerText=t.name,n.setAttribute("data-index",String(e)),n.onclick=()=>this.openGrp(e),this.$grpSwitcher.append(n)}))),this.emoticons.length>0&&this.openGrp(0)}openGrp(t){var e,n,i;Array.from(this.$grpWrap.children).forEach((e=>{const n=e;n.getAttribute("data-index")!==String(t)?n.style.display="none":n.style.display=""})),null==(e=this.$grpSwitcher)||e.querySelectorAll("span.active").forEach((t=>t.classList.remove("active"))),null==(i=null==(n=this.$grpSwitcher)?void 0:n.querySelector(`span[data-index="${t}"]`))||i.classList.add("active"),this.changeListHeight()}changeListHeight(){}transEmoticonImageText(t){return this.emoticons&&Array.isArray(this.emoticons)?(this.emoticons.forEach((e=>{"image"===e.type&&Object.entries(e.items).forEach((([e,n])=>{t=t.split(`:[${n.key}]`).join(`<img src="${n.val}" atk-emoticon="${n.key}">`)}))})),t):t}}d(Ee,"Name","emoticons");class Te extends Se{constructor(t){super(t),d(this,"$imgUploadInput"),d(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((t=>`.${t}`)).join(",");const e=this.registerBtn(`${this.ctx.$t("image")}`);e.after(this.$imgUploadInput),e.onclick=()=>{const t=this.$imgUploadInput;t.onchange=()=>{(()=>{h(this,null,(function*(){if(!t.files||0===t.files.length)return;const e=t.files[0];this.uploadImg(e)}))})()},t.click()},this.ctx.conf.imgUpload||this.getBtn().setAttribute("atk-only-admin-show","");const n=t=>{if(t)for(let e=0;e<t.length;e++){const n=t[e];this.uploadImg(n)}};this.editor.getUI().$textarea.addEventListener("dragover",(t=>{t.stopPropagation(),t.preventDefault()})),this.editor.getUI().$textarea.addEventListener("drop",(t=>{var e;const i=null==(e=t.dataTransfer)?void 0:e.files;(null==i?void 0:i.length)&&(t.preventDefault(),n(i))})),this.editor.getUI().$textarea.addEventListener("paste",(t=>{var e;const i=null==(e=t.clipboardData)?void 0:e.files;(null==i?void 0:i.length)&&(t.preventDefault(),n(i))}))}uploadImg(t){return h(this,null,(function*(){const e=/[^.]+$/.exec(t.name);if(!e||!this.allowImgExts.includes(e[0]))return;if(!Ot.checkHasBasicUserInfo())return void this.editor.showNotify(this.ctx.$t("uploadLoginMsg"),"w");let n="\n";""===this.editor.getUI().$textarea.value.trim()&&(n="");const i=`${n}`;let s;this.editor.insertContent(i);try{s=this.ctx.conf.imgUploader?{img_url:yield this.ctx.conf.imgUploader(t)}:yield this.ctx.getApi().upload.imgUpload(t)}catch(a){console.error(a),this.editor.showNotify(`${this.ctx.$t("uploadFail")},${a.msg}`,"e")}if(s&&s.img_url){let t=s.img_url;v(t)||(t=k(this.ctx,t)),this.editor.setContent(this.editor.getUI().$textarea.value.replace(i,`${n}`))}else this.editor.setContent(this.editor.getUI().$textarea.value.replace(i,""))}))}}d(Te,"Name","upload");class Le extends Se{constructor(t){super(t),d(this,"isBind",!1),this.registerPanel('<div class="atk-editor-plug-preview"></div>');let e=this.editor.$t("preview");this.ctx.getMarkedInstance()&&(e+=' <i title="Markdown is supported"><svg class="markdown" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M14.85 3H1.15C.52 3 0 3.52 0 4.15v7.69C0 12.48.52 13 1.15 13h13.69c.64 0 1.15-.52 1.15-1.15v-7.7C16 3.52 15.48 3 14.85 3zM9 11H7V8L5.5 9.92 4 8v3H2V5h2l1.5 2L7 5h2v6zm2.99.5L9.5 8H11V5h2v3h1.5l-2.51 3.5z"></path></svg></i>'),this.registerBtn(e),this.registerContentUpdatedEvt((t=>{this.updateContent()}))}onPanelShow(){if(this.updateContent(),!this.isBind){const t=()=>{this.updateContent()};this.editor.getUI().$textarea.addEventListener("input",t),this.editor.getUI().$textarea.addEventListener("change",t),this.isBind=!0}}updateContent(){"none"!==this.$panel.style.display&&(this.$panel.innerHTML=this.editor.getContentMarked())}}d(Le,"Name","preview");class Ae extends Se{constructor(t){super(t),d(this,"queryUserInfo",{timeout:null,abortFunc:null}),this.registerHeaderInputEvt(((t,e)=>{"nick"!==t&&"email"!==t||this.fetchUserInfo()})),this.editor.getUI().$link.addEventListener("change",(()=>{const t=this.editor.getUI().$link.value.trim();t&&!/^(http|https):\/\//.test(t)&&(this.editor.getUI().$link.value=`https://${t}`,Ot.update({link:this.editor.getUI().$link.value}))}))}fetchUserInfo(){Ot.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:t,abort:e}=this.ctx.getApi().user.userGet(Ot.data.nick,Ot.data.email);this.queryUserInfo.abortFunc=e,t.then((t=>{var e;t.is_login||Ot.logout(),this.ctx.updateNotifies(t.unread),Ot.checkHasBasicUserInfo()&&!t.is_login&&(null==(e=t.user)?void 0:e.is_admin)&&this.showLoginDialog(),t.user&&t.user.link&&(this.editor.getUI().$link.value=t.user.link,Ot.update({link:t.user.link}))})).catch((()=>{})).finally((()=>{this.queryUserInfo.abortFunc=null}))}),400)}showLoginDialog(){this.ctx.checkAdmin({onSuccess:()=>{}})}}d(Ae,"Name","headerInput");const Me=[Ee,Te,Le,Ae];function Oe(t){const e={editor:t,plugList:{},openedPlugName:null,openPlugPanel:t=>_e(e,t),closePlugPanel:()=>Be(e),triggerHeaderInputEvt:(t,n)=>function(t,e,n){Object.entries(t.plugList).forEach((([t,i])=>{i.onHeaderInput&&i.onHeaderInput(e,n)}))}(e,t,n),triggerContentUpdatedEvt:t=>function(t,e){Object.entries(t.plugList).forEach((([t,n])=>{n.onContentUpdated&&n.onContentUpdated(e)}))}(e,t),getTransformedContent:t=>function(t,e){let n=e;return Object.entries(t.plugList).forEach((([t,e])=>{e.contentTransformer&&(n=e.contentTransformer(n))})),n}(e,t)};t.getUI().$plugPanelWrap.innerHTML="",t.getUI().$plugPanelWrap.style.display="none",t.getUI().$plugBtnWrap.innerHTML="";const n=[{k:"upload",v:(i=t.conf).imgUpload},{k:"emoticons",v:i.emoticons},{k:"preview",v:i.preview}].filter((t=>!t.v)).flatMap((t=>t.k));var i;return Me.filter((t=>!n.includes(t.name))).forEach((t=>{!function(t,e){const n=e.Name,i=new e(t.editor);t.plugList[n]=i,function(t,e,n){const i=n.getBtn();if(!i)return;t.editor.getUI().$plugBtnWrap.appendChild(i),i.onclick=i.onclick||(()=>{t.editor.getUI().$plugBtnWrap.querySelectorAll(".active").forEach((t=>t.classList.remove("active"))),e!==t.openedPlugName?(_e(t,e),i.classList.add("active")):Be(t)});const s=n.getPanel();s&&(s.setAttribute("data-plug-name",e),s.style.display="none",t.editor.getUI().$plugPanelWrap.appendChild(s))}(t,n,i)}(e,t)})),e}function _e(t,e){Object.entries(t.plugList).forEach((([t,n])=>{const i=n.getPanel();i&&(t===e?(i.style.display="",n.onPanelShow&&n.onPanelShow()):(i.style.display="none",n.onPanelHide&&n.onPanelHide()))})),t.editor.getUI().$plugPanelWrap.style.display="",t.openedPlugName=e}function Be(t){if(!t.openedPlugName)return;const e=t.plugList[t.openedPlugName];e&&(e.onPanelHide&&e.onPanelHide(),t.editor.getUI().$plugPanelWrap.style.display="none",t.openedPlugName=null)}function Pe(t){const e={editor:t,comment:void 0,setReply:(t,n,i)=>function(t,e,n,i=!0){t.editor.cancelEditComment(),Re(t);const s=t.editor.getUI();s.$sendReply||(s.$sendReply=u(`<div class="atk-send-reply">${t.editor.$t("reply")} <span class="atk-text"></span><span class="atk-cancel">×</span></div>`),s.$sendReply.querySelector(".atk-text").innerText=`@${e.nick}`,s.$sendReply.addEventListener("click",(()=>{t.editor.cancelReply()})),s.$textareaWrap.append(s.$sendReply));t.comment=e,t.editor.travel(n),i&&S(s.$el);s.$textarea.focus()}(e,t,n,i),cancelReply:()=>Re(e)};return e}function Re(t){if(!t.comment)return;const e=t.editor.getUI();e.$sendReply&&(e.$sendReply.remove(),e.$sendReply=void 0),t.comment=void 0,t.editor.travelBack()}function Ie(t){const e={editor:t,comment:void 0,setEdit:(t,n)=>function(t,e,n){Ue(t),t.editor.cancelReply();const i=t.editor.getUI();if(!i.$editCancelBtn){const e=u(`<div class="atk-send-reply">${t.editor.$t("editCancel")} <span class="atk-cancel">×</span></div>`);e.onclick=()=>{Ue(t)},i.$textareaWrap.append(e),i.$editCancelBtn=e}t.comment=e,i.$header.style.display="none",t.editor.travel(n),i.$nick.value=e.nick||"",i.$email.value=e.email||"",i.$link.value=e.link||"",t.editor.setContent(e.content),i.$textarea.focus(),t.editor.refreshSendBtnText()}(e,t,n),cancelEdit:()=>Ue(e)};return function(t){t.editor.getSubmitManager().registerCustom({activeCond:()=>!!t.comment,req:()=>h(this,null,(function*(){const e={content:t.editor.getFinalContent(),nick:t.editor.getUI().$nick.value,email:t.editor.getUI().$email.value,link:t.editor.getUI().$link.value};return yield t.editor.ctx.getApi().comment.commentEdit(l(l({},t.comment),e))})),post:e=>{t.editor.ctx.updateComment(e)}})}(e),e}function Ue(t){if(!t.comment)return;const e=t.editor.getUI();e.$editCancelBtn&&(e.$editCancelBtn.remove(),e.$editCancelBtn=void 0),t.comment=void 0,t.editor.travelBack();const{nick:n,email:i,link:s}=Ot.data;e.$nick.value=n,e.$email.value=i,e.$link.value=s,t.editor.setContent(""),t.editor.refreshSendBtnText(),e.$header.style.display=""}function De(t){const e={editor:t,do:()=>function(t){return h(this,null,(function*(){if(""===t.editor.getFinalContent().trim())return void t.editor.focus();const e=t.customs.find((t=>t.activeCond()));t.editor.ctx.trigger("editor-submit"),t.editor.showLoading();try{let n;(null==e?void 0:e.pre)&&e.pre(),n=(null==e?void 0:e.req)?yield e.req():yield function(t){return h(this,null,(function*(){const e=yield t.editor.ctx.getApi().comment.add(l({},function(t){var e;const{nick:n,email:i,link:s}=Ot.data,a=t.editor.ctx.conf,r=null==(e=t.editor.getReplyManager())?void 0:e.comment;return{content:t.editor.getFinalContent(),nick:n,email:i,link:s,rid:r?r.id:0,page_key:r?r.page_key:a.pageKey,page_title:r?void 0:a.pageTitle,site_name:r?r.site_name:a.site}}(t)));return e}))}(t),(null==e?void 0:e.post)?e.post(n):function(t,e){const n=t.editor.getReplyManager(),i=t.editor.ctx.conf;(null==n?void 0:n.comment)&&n.comment.page_key!==i.pageKey&&window.open(`${n.comment.page_url}#atk-comment-${e.id}`);t.editor.ctx.insertComment(e)}(t,n)}catch(n){console.error(n),t.editor.showNotify(`${t.editor.$t("commentFail")},${n.msg||String(n)}`,"e")}t.editor.reset(),t.editor.ctx.trigger("editor-submitted"),t.editor.hideLoading()}))}(e),customs:[],registerCustom:t=>{e.customs.push(t)}};return e}const qe={localStorage:function(t){const e=window.localStorage.getItem("ArtalkContent")||"";""!==e.trim()&&(t.showNotify(t.$t("restoredMsg"),"i"),t.setContent(e));t.getUI().$textarea.addEventListener("input",(()=>t.saveToLocalStorage()))},header:function(t){const e=t.getHeaderInputEls();Object.entries(e).forEach((([e,n])=>{n.value=Ot.data[e]||"",n.addEventListener("input",(()=>function(t,e,n){var i;if(t.isEditMode)return;Ot.update({[e]:n.value.trim()}),null==(i=t.getPlugs())||i.triggerHeaderInputEvt(e,n)}(t,e,n))),n.placeholder=`${t.$t(e)}`}))},textarea:function(t){t.getUI().$textarea.placeholder=t.ctx.conf.placeholder||t.$t("placeholder"),t.getUI().$textarea.addEventListener("keydown",(e=>{9===(e.keyCode||e.which)&&(e.preventDefault(),t.insertContent("\t"))})),t.getUI().$textarea.addEventListener("input",(()=>{t.adjustTextareaHeight()}))},submitBtn:function(t){t.refreshSendBtnText(),t.getUI().$submitBtn.addEventListener("click",(()=>t.submit()))},submitManager:function(t){t.setSubmitManager(De(t))},plugs:function(t){t.setPlugs(Oe(t))},mover:function(t){if(!t.conf.editorTravel)return;t.setMover(Ce(t))},replyManager:function(t){t.setReplyManager(Pe(t))},editModeManager:function(t){t.setEditModeManager(Ie(t))}};const We={$header:".atk-header",$nick:'.atk-header [name="nick"]',$email:'.atk-header [name="email"]',$link:'.atk-header [name="link"]',$textareaWrap:".atk-textarea-wrap",$textarea:".atk-textarea",$bottom:".atk-bottom",$submitBtn:".atk-send-btn",$notifyWrap:".atk-notify-wrap",$plugBtnWrap:".atk-plug-btn-wrap",$plugPanelWrap:".atk-plug-panel-wrap"};class Fe extends b{constructor(t){super(t),d(this,"ui"),d(this,"plugs"),d(this,"mover"),d(this,"reply"),d(this,"editMode"),d(this,"submitManager"),this.ui=function(){const t=u('<div class="atk-main-editor">\n <div class="atk-header">\n <input name="nick" class="atk-nick" type="text" required="required">\n <input name="email" class="atk-email" type="email" required="required">\n <input name="link" class="atk-link" type="url">\n </div>\n <div class="atk-textarea-wrap">\n <textarea class="atk-textarea"></textarea>\n </div>\n <div class="atk-plug-panel-wrap" style="display: none;"></div>\n <div class="atk-bottom">\n <div class="atk-item atk-plug-btn-wrap"></div>\n <div class="atk-item">\n <button type="button" class="atk-send-btn"></button>\n </div>\n </div>\n <div class="atk-notify-wrap"></div>\n</div>\n'),e={$el:t};return Object.entries(We).forEach((([n,i])=>{e[n]=t.querySelector(i)})),e}(),this.$el=this.ui.$el,this.ctx.on("conf-loaded",(()=>{var t;t=this,Object.entries(qe).forEach((([e,n])=>{n(t)}))}))}getUI(){return this.ui}getPlugs(){return this.plugs}setPlugs(t){this.plugs=t}setMover(t){this.mover=t}setReplyManager(t){this.reply=t}getReplyManager(){return this.reply}get isReplyMode(){var t;return!!(null==(t=this.reply)?void 0:t.comment)}setEditModeManager(t){this.editMode=t}get isEditMode(){var t;return!!(null==(t=this.editMode)?void 0:t.comment)}setSubmitManager(t){this.submitManager=t}getSubmitManager(){return this.submitManager}getHeaderInputEls(){return{nick:this.ui.$nick,email:this.ui.$email,link:this.ui.$link}}saveToLocalStorage(){window.localStorage.setItem("ArtalkContent",this.getContentOriginal().trim())}refreshSendBtnText(){this.isEditMode?this.ui.$submitBtn.innerText=this.$t("save"):this.ui.$submitBtn.innerText=this.ctx.conf.sendBtn||this.$t("send")}getFinalContent(){let t=this.getContentOriginal();return this.plugs&&(t=this.plugs.getTransformedContent(t)),t}getContentOriginal(){return this.ui.$textarea.value||""}getContentMarked(){return wt(this.ctx,this.getFinalContent())}setContent(t){this.ui.$textarea.value=t,this.saveToLocalStorage(),this.plugs&&this.plugs.triggerContentUpdatedEvt(t),window.setTimeout((()=>{this.adjustTextareaHeight()}),80)}insertContent(t){if(document.selection)this.ui.$textarea.focus(),document.selection.createRange().text=t,this.ui.$textarea.focus();else if(this.ui.$textarea.selectionStart||0===this.ui.$textarea.selectionStart){const e=this.ui.$textarea.selectionStart,n=this.ui.$textarea.selectionEnd,i=this.ui.$textarea.scrollTop;this.setContent(this.ui.$textarea.value.substring(0,e)+t+this.ui.$textarea.value.substring(n,this.ui.$textarea.value.length)),this.ui.$textarea.focus(),this.ui.$textarea.selectionStart=e+t.length,this.ui.$textarea.selectionEnd=e+t.length,this.ui.$textarea.scrollTop=i}else this.ui.$textarea.focus(),this.ui.$textarea.value+=t}adjustTextareaHeight(){const t=this.ui.$textarea.offsetHeight-this.ui.$textarea.clientHeight;this.ui.$textarea.style.height="0px",this.ui.$textarea.style.height=`${this.ui.$textarea.scrollHeight+t}px`}focus(){this.ui.$textarea.focus()}reset(){this.setContent(""),this.cancelReply(),this.cancelEditComment()}setReply(t,e,n=!0){var i;null==(i=this.reply)||i.setReply(t,e,n)}cancelReply(){var t;null==(t=this.reply)||t.cancelReply()}setEditComment(t,e){var n;null==(n=this.editMode)||n.setEdit(t,e)}cancelEditComment(){var t;null==(t=this.editMode)||t.cancelEdit()}showNotify(t,e){E(this.ui.$notifyWrap,t,e)}showLoading(){x(this.ui.$el)}hideLoading(){C(this.ui.$el)}submit(){return h(this,null,(function*(){this.submitManager&&(yield this.submitManager.do())}))}close(){this.ui.$textareaWrap.querySelector(".atk-comment-closed")||this.ui.$textareaWrap.prepend(u(`<div class="atk-comment-closed">${this.$t("onlyAdminCanReply")}</div>`)),Ot.data.isAdmin?(this.ui.$textarea.style.display="",this.ui.$bottom.style.display=""):(this.ui.$textarea.style.display="none",this.closePlugPanel(),this.ui.$bottom.style.display="none")}open(){var t;null==(t=this.ui.$textareaWrap.querySelector(".atk-comment-closed"))||t.remove(),this.ui.$textarea.style.display="",this.ui.$bottom.style.display=""}travel(t){var e;null==(e=this.mover)||e.move(t)}travelBack(){var t;null==(t=this.mover)||t.back()}openPlugPanel(t){var e;null==(e=this.plugs)||e.openPlugPanel(t)}closePlugPanel(){var t;null==(t=this.plugs)||t.closePlugPanel()}}class He extends b{constructor(t){super(t),d(this,"layer"),d(this,"$header"),d(this,"$closeBtn"),d(this,"$iframeWrap"),d(this,"$iframe"),d(this,"firstShow",!0),this.$el=u('<div class="atk-sidebar-layer">\n <div class="atk-sidebar-inner">\n <div class="atk-sidebar-header">\n <div class="atk-sidebar-close"><i class="atk-icon atk-icon-close"></i></div>\n </div>\n <div class="atk-sidebar-iframe-wrap"></div>\n </div>\n</div>\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 h(this,arguments,(function*(t={}){if(this.$el.style.transform="",null==this.layer&&(this.layer=new M(this.ctx,"sidebar",this.$el),this.layer.afterHide=()=>{!0===this.ctx.conf.editorTravel&&this.ctx.editorTravelBack()}),this.layer.show(),(()=>{h(this,null,(function*(){var e;const n=yield this.ctx.getApi().user.loginStatus();n.is_admin&&!n.is_login&&(null==(e=this.layer)||e.hide(),this.firstShow=!0,this.ctx.checkAdmin({onSuccess:()=>{setTimeout((()=>{this.show(t)}),500)},onCancel:()=>{}}))}))})(),this.firstShow){this.$iframeWrap.innerHTML="",this.$iframe=u("<iframe></iframe>");const e=k(this.ctx,"/sidebar/"),n={pageKey:this.conf.pageKey,site:this.conf.site||"",user:JSON.stringify(Ot.data),time:+new Date};t.view&&(n.view=t.view),this.conf.darkMode&&(n.darkMode="1"),"string"==typeof this.conf.locale&&(n.locale=this.conf.locale);const i=new URLSearchParams(n);this.iframeLoad(`${e}?${i.toString()}`),this.$iframeWrap.append(this.$iframe),this.firstShow=!1}else{const t=this.$iframe.src.includes("darkMode=1");this.conf.darkMode&&!t&&this.iframeLoad(`${this.$iframe.src}&darkMode=1`),!this.conf.darkMode&&t&&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 t;this.$el.style.transform="",null==(t=this.layer)||t.hide(),this.ctx.trigger("sidebar-hide")}iframeLoad(t){this.$iframe&&(this.$iframe.src=t,x(this.$iframeWrap),this.$iframe.onload=()=>{C(this.$iframeWrap)})}}const Ne={i18n(t){Lt(t.conf.locale),t.on("conf-loaded",(()=>{Lt(t.conf.locale)}))},markdown(){!function(){try{if(!t.marked.name)return}catch(s){return}const e=new t.marked.Renderer,n=e.link;e.link=(t,i,s)=>{const a=null==t?void 0:t.startsWith(`${window.location.protocol}//${window.location.hostname}`);return n.call(e,t,i,s).replace(/^<a /,`<a target="_blank" ${a?"":'rel="noreferrer noopener nofollow"'} `)},e.code=(t,e)=>{const n=e||"plaintext";let i=t;return window.hljs?n&&window.hljs.getLanguage(n)&&(i=window.hljs.highlight(n,t).value):i=$t(t),`<pre rel="${n}">\n<code class="hljs language-${n}">${i.replace(/&/g,"&")}</code>\n</pre>`};const i=t.marked;t.marked.setOptions({renderer:e,pedantic:!1,gfm:!0,breaks:!0,smartLists:!0,smartypants:!0,xhtml:!1,sanitize:!1,silent:!0}),vt=i}()},user:t=>(Ot.setContext(t),Ot),api:t=>new xe(t),checkerLauncher:t=>new $e(t),editor(t){const e=new Fe(t);return t.$root.appendChild(e.$el),e},list(t){const e=new ue(t);return t.$root.appendChild(e.$el),e.fetchComments(0),e},layer(t){M.BodyOrgOverflow=document.body.style.overflow,M.BodyOrgPaddingRight=document.body.style.paddingRight},sidebarLayer:t=>new He(t),eventsDefault(t){window.addEventListener("hashchange",(()=>{t.listHashGotoCheck()})),t.on("user-changed",(()=>{t.checkAdminShowEl(),t.listRefreshUI()}))},darkMode(t){P(t),t.on("conf-loaded",(()=>{P(t)}))}};function je(t){return h(this,null,(function*(){const e=t.ctx.conf.countEl;e&&document.querySelector(e)&&ze(t,{api:"page_comment",countEl:e});const n=t.pvAdd?yield t.ctx.getApi().page.pv():void 0,i=t.ctx.conf.pvEl;i&&document.querySelector(i)&&ze(t,{api:"page_pv",countEl:i,curtPageCount:n})}))}function ze(t,e){return h(this,null,(function*(){let n={};const i=t.ctx.conf.pageKey;e.curtPageCount&&(n[i]=e.curtPageCount);let s=Array.from(document.querySelectorAll(e.countEl)).map((t=>t.getAttribute("data-page-key")||i)).filter((t=>void 0===n[t]));if(s=[...new Set(s)],s.length>0){const i=yield t.ctx.getApi().page.stat(e.api,s);n=l(l({},n),i)}document.querySelectorAll(e.countEl).forEach((t=>{const e=t.getAttribute("data-page-key")||i;t.innerHTML=`${Number(n[e]||0)}`}))}))}const Ve=class{constructor(t){d(this,"conf"),d(this,"ctx"),d(this,"$root"),Ve.instance&&Ve.destroy(),this.conf=ce(t),this.conf.el instanceof HTMLElement&&(this.$root=this.conf.el),this.ctx=new pe(this.conf,this.$root),Object.entries(Ne).forEach((([t,e])=>{if(Ve.DisabledComponents.includes(t))return;const n=e(this.ctx);n&&this.ctx.inject(t,n)})),Ve.plugins.forEach((t=>{"function"==typeof t&&t(this.ctx)}))}static init(t){return this.instance&&Ve.destroy(),this.instance=new Ve(t),this.instance}use(t){Ve.plugins.push(t),"function"==typeof t&&t(this.ctx)}update(t){if(!Ve.instance)throw Error("cannot call `update` function before call `load`");return Ve.instance.ctx.updateConf(t),Ve.instance}reload(){this.ctx.listReload()}destroy(){if(!Ve.instance)throw Error("cannot call `destroy` function before call `load`");Ve.instance.$root.remove(),delete Ve.instance}on(t,e){this.ctx.on(t,e,"external")}off(t,e){this.ctx.off(t,e,"external")}trigger(t,e){this.ctx.trigger(t,e,"external")}setDarkMode(t){this.ctx.setDarkMode(t)}static use(t){this.plugins.push(t),this.instance&&"function"==typeof t&&t(this.instance.ctx)}static update(t){var e;return null==(e=this.instance)?void 0:e.update(t)}static reload(){var t;null==(t=this.instance)||t.reload()}static destroy(){var t;null==(t=this.instance)||t.destroy()}static on(t,e){var n;null==(n=this.instance)||n.on(t,e)}static off(t,e){var n;null==(n=this.instance)||n.off(t,e)}static trigger(t,e){var n;null==(n=this.instance)||n.trigger(t,e)}static setDarkMode(t){var e;null==(e=this.instance)||e.setDarkMode(t)}static loadCountWidget(t){const e=new pe(ce(t));e.inject("api",new xe(e)),je({ctx:e,pvAdd:!1})}static LoadCountWidget(t){console.warn("The method `LoadCountWidget` is deprecated, please use `loadCountWidget` instead."),this.loadCountWidget(t)}};let Qe=Ve;return d(Qe,"instance"),d(Qe,"ListLite",he),d(Qe,"defaults",le),d(Qe,"plugins",[t=>{t.conf.useBackendConf?t.on("list-loaded",(()=>{je({ctx:t,pvAdd:!0})})):je({ctx:t,pvAdd:!0})}]),d(Qe,"DisabledComponents",[]),Qe}(marked);
|