artalk 2.9.0 → 2.9.1
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.cjs +1 -1
- package/dist/Artalk.cjs.map +1 -1
- package/dist/Artalk.iife.js +1 -1
- package/dist/Artalk.iife.js.map +1 -1
- package/dist/Artalk.js +1 -1
- package/dist/Artalk.js.map +1 -1
- package/dist/Artalk.mjs +28 -21
- package/dist/Artalk.mjs.map +1 -1
- package/dist/ArtalkLite.cjs +1 -1
- package/dist/ArtalkLite.cjs.map +1 -1
- package/dist/ArtalkLite.iife.js +1 -1
- package/dist/ArtalkLite.iife.js.map +1 -1
- package/dist/ArtalkLite.js +1 -1
- package/dist/ArtalkLite.js.map +1 -1
- package/dist/ArtalkLite.mjs +6 -3
- package/dist/ArtalkLite.mjs.map +1 -1
- package/package.json +2 -2
package/dist/ArtalkLite.cjs
CHANGED
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
* @contact API Support <artalkjs@gmail.com> (https://artalk.js.org)
|
|
8
8
|
*
|
|
9
9
|
* Artalk is a modern comment system based on Golang.
|
|
10
|
-
*/let p=class extends u{constructor(){super(...arguments),c(this,"auth",{loginByEmail:(t,e={})=>this.request(r({path:"/auth/email/login",method:"POST",body:t,type:"application/json",format:"json"},e)),registerByEmail:(t,e={})=>this.request(r({path:"/auth/email/register",method:"POST",body:t,type:"application/json",format:"json"},e)),sendVerifyEmail:(t,e={})=>this.request(r({path:"/auth/email/send",method:"POST",body:t,type:"application/json",format:"json"},e)),checkDataMerge:(t={})=>this.request(r({path:"/auth/merge",method:"GET",secure:!0,format:"json"},t)),applyDataMerge:(t,e={})=>this.request(r({path:"/auth/merge",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e))}),c(this,"cache",{flushCache:(t={})=>this.request(r({path:"/cache/flush",method:"POST",secure:!0,format:"json"},t)),warmUpCache:(t={})=>this.request(r({path:"/cache/warm_up",method:"POST",secure:!0,format:"json"},t))}),c(this,"captcha",{getCaptcha:(t={})=>this.request(r({path:"/captcha",method:"GET",format:"json"},t)),getCaptchaStatus:(t={})=>this.request(r({path:"/captcha/status",method:"GET",format:"json"},t)),verifyCaptcha:(t,e={})=>this.request(r({path:"/captcha/verify",method:"POST",body:t,type:"application/json",format:"json"},e))}),c(this,"comments",{getComments:(t,e={})=>this.request(r({path:"/comments",method:"GET",query:t,secure:!0,type:"application/json",format:"json"},e)),createComment:(t,e={})=>this.request(r({path:"/comments",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),getComment:(t,e={})=>this.request(r({path:`/comments/${t}`,method:"GET",type:"application/json",format:"json"},e)),updateComment:(t,e,s={})=>this.request(r({path:`/comments/${t}`,method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},s)),deleteComment:(t,e={})=>this.request(r({path:`/comments/${t}`,method:"DELETE",secure:!0,format:"json"},e))}),c(this,"conf",{conf:(t={})=>this.request(r({path:"/conf",method:"GET",format:"json"},t)),getSocialLoginProviders:(t={})=>this.request(r({path:"/conf/auth/providers",method:"GET",format:"json"},t)),getDomain:(t,e={})=>this.request(r({path:"/conf/domain",method:"GET",query:t,format:"json"},e))}),c(this,"notifies",{getNotifies:(t,e={})=>this.request(r({path:"/notifies",method:"GET",query:t,type:"application/json",format:"json"},e)),markAllNotifyRead:(t,e={})=>this.request(r({path:"/notifies/read",method:"POST",body:t,type:"application/json",format:"json"},e)),markNotifyRead:(t,e,s={})=>this.request(r({path:`/notifies/${t}/${e}`,method:"POST",format:"json"},s))}),c(this,"pages",{getPages:(t,e={})=>this.request(r({path:"/pages",method:"GET",query:t,secure:!0,type:"application/json",format:"json"},e)),fetchAllPages:(t,e={})=>this.request(r({path:"/pages/fetch",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),getPageFetchStatus:(t={})=>this.request(r({path:"/pages/fetch/status",method:"GET",secure:!0,format:"json"},t)),logPv:(t,e={})=>this.request(r({path:"/pages/pv",method:"POST",body:t,type:"application/json",format:"json"},e)),updatePage:(t,e,s={})=>this.request(r({path:`/pages/${t}`,method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},s)),deletePage:(t,e={})=>this.request(r({path:`/pages/${t}`,method:"DELETE",secure:!0,format:"json"},e)),fetchPage:(t,e={})=>this.request(r({path:`/pages/${t}/fetch`,method:"POST",secure:!0,type:"application/json",format:"json"},e))}),c(this,"sendEmail",{sendEmail:(t,e={})=>this.request(r({path:"/send_email",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e))}),c(this,"settings",{getSettings:(t={})=>this.request(r({path:"/settings",method:"GET",secure:!0,format:"json"},t)),applySettings:(t,e={})=>this.request(r({path:"/settings",method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},e)),getSettingsTemplate:(t,e={})=>this.request(r({path:`/settings/template/${t}`,method:"GET",secure:!0,format:"json"},e))}),c(this,"sites",{getSites:(t={})=>this.request(r({path:"/sites",method:"GET",secure:!0,format:"json"},t)),createSite:(t,e={})=>this.request(r({path:"/sites",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),updateSite:(t,e,s={})=>this.request(r({path:`/sites/${t}`,method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},s)),deleteSite:(t,e={})=>this.request(r({path:`/sites/${t}`,method:"DELETE",secure:!0,format:"json"},e))}),c(this,"stats",{getStats:(t,e,s={})=>this.request(r({path:`/stats/${t}`,method:"GET",query:e,type:"application/json",format:"json"},s))}),c(this,"transfer",{exportArtrans:(t={})=>this.request(r({path:"/transfer/export",method:"GET",secure:!0,format:"json"},t)),importArtrans:(t,e={})=>this.request(r({path:"/transfer/import",method:"POST",body:t,secure:!0,type:"application/json"},e)),uploadArtrans:(t,e={})=>this.request(r({path:"/transfer/upload",method:"POST",body:t,secure:!0,type:"multipart/form-data",format:"json"},e))}),c(this,"upload",{upload:(t,e={})=>this.request(r({path:"/upload",method:"POST",body:t,secure:!0,type:"multipart/form-data",format:"json"},e))}),c(this,"user",{getUser:(t,e={})=>this.request(r({path:"/user",method:"GET",query:t,secure:!0,format:"json"},e)),updateProfile:(t,e={})=>this.request(r({path:"/user",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),login:(t,e={})=>this.request(r({path:"/user/access_token",method:"POST",body:t,type:"application/json",format:"json"},e)),getUserStatus:(t,e={})=>this.request(r({path:"/user/status",method:"GET",query:t,secure:!0,format:"json"},e))}),c(this,"users",{createUser:(t,e={})=>this.request(r({path:"/users",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),updateUser:(t,e,s={})=>this.request(r({path:`/users/${t}`,method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},s)),deleteUser:(t,e={})=>this.request(r({path:`/users/${t}`,method:"DELETE",secure:!0,format:"json"},e)),getUsers:(t,e,s={})=>this.request(r({path:`/users/${t}`,method:"GET",query:e,secure:!0,type:"application/json",format:"json"},s))}),c(this,"version",{getVersion:(t={})=>this.request(r({path:"/version",method:"GET",format:"json"},t))}),c(this,"votes",{syncVotes:(t={})=>this.request(r({path:"/votes/sync",method:"POST",secure:!0,format:"json"},t)),vote:(t,e,s,n={})=>this.request(r({path:`/votes/${t}/${e}`,method:"POST",body:s,type:"application/json",format:"json"},n))})}};const m=(t,e,s)=>d(exports,null,(function*(){const n=t.getApiToken&&t.getApiToken(),i=new Headers(r({Authorization:n?`Bearer ${n}`:""},null==s?void 0:s.headers));i.get("Authorization")||i.delete("Authorization");const o=yield fetch(e,l(r({},s),{headers:i}));if(!o.ok){const n=(yield o.json().catch((()=>{})))||{};let i=!1;if(t.handlers&&(yield t.handlers.get().reduce(((t,e)=>d(exports,null,(function*(){yield t,!0===n[e.action]&&(yield e.handler(n),i=!0)}))),Promise.resolve())),i)return m(t,e,s);throw function(t,e){const s=new g;return s.message=e.msg||e.message||"fetch error",s.code=t,s.data=e,console.error(s),s}(o.status,n)}return o}));class g extends Error{constructor(){super(...arguments),c(this,"code",0),c(this,"message","fetch error"),c(this,"data")}}class f extends p{constructor(t){super({baseUrl:t.baseURL,customFetch:(e,s)=>m(t,e,s)}),c(this,"_opts"),this._opts=t}getUserFields(){const t=this._opts.userInfo;if((null==t?void 0:t.name)&&(null==t?void 0:t.email))return{name:t.name,email:t.email}}}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function y(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var k={"&":"&","<":"<",">":">",'"':""","'":"'"},v={"&":"&","<":"<",">":">",""":'"',"'":"'"},$=/(&|<|>|"|')/g,w=/[&<>"']/g;function b(t){return k[t]}function C(t){return v[t]}function x(t){return null==t?"":String(t).replace(w,b)}function E(t){return null==t?"":String(t).replace($,C)}x.options=E.options={};var S={encode:x,escape:x,decode:E,unescape:E,version:"1.0.0-browser"};var T=function t(e){for(var s,n,i=Array.prototype.slice.call(arguments,1);i.length;)for(n in s=i.shift())s.hasOwnProperty(n)&&("[object Object]"===Object.prototype.toString.call(e[n])?e[n]=t(e[n],s[n]):e[n]=s[n]);return e},L=function(t){return"string"==typeof t?t.toLowerCase():t};function A(t,e){return t[e]=!0,t}var M=function(t){return t.reduce(A,{})},P={uris:M(["background","base","cite","href","longdesc","src","usemap"])},U={voids:M(["area","br","col","hr","img","wbr","input","base","basefont","link","meta"])},I=S,O=L,q=U,D=/^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)\s*>/,R=/^<\s*\/\s*([\w:-]+)[^>]*>/,B=/([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g,j=/^</,F=/^<\s*\//;var _=S,W=L,N=P,H=U;var z=T,V=function(t,e){for(var s,n=function(){var t=[];return t.lastItem=function(){return t[t.length-1]},t}(),i=t;t;)o();function o(){s=!0,function(){"\x3c!--"===t.substr(0,4)?(n=t.indexOf("--\x3e"))>=0&&(e.comment&&e.comment(t.substring(4,n)),t=t.substring(n+3),s=!1):F.test(t)?a(R,l):j.test(t)&&a(D,r);var n;!function(){if(!s)return;var n,i=t.indexOf("<");i>=0?(n=t.substring(0,i),t=t.substring(i)):(n=t,t="");e.chars&&e.chars(n)}()}();var n=t===i;i=t,n&&(t="")}function a(e,n){var i=t.match(e);i&&(t=t.substring(i[0].length),i[0].replace(e,n),s=!1)}function r(t,s,i,o){var a={},r=O(s),l=q.voids[r]||!!o;i.replace(B,(function(t,e,s,n,i){a[e]=void 0===s&&void 0===n&&void 0===i?void 0:I.decode(s||n||i||"")})),l||n.push(r),e.start&&e.start(r,a,l)}function l(t,s){var i,o=0,a=O(s);if(a)for(o=n.length-1;o>=0&&n[o]!==a;o--);if(o>=0){for(i=n.length-1;i>=o;i--)e.end&&e.end(n[i]);n.length=o}}l()},G=function(t,e){var s,n=e||{};return r(),{start:function(t,e,a){var r=W(t);if(s.ignoring)return void o(r);if(-1===(n.allowedTags||[]).indexOf(r))return void o(r);if(n.filter&&!n.filter({tag:r,attrs:e}))return void o(r);i("<"),i(r),Object.keys(e).forEach((function(t){var s=e[t],o=(n.allowedClasses||{})[r]||[],a=(n.allowedAttributes||{})[r]||[],l=W(t);("class"===l&&-1===a.indexOf(l)?(s=s.split(" ").filter((function(t){return o&&-1!==o.indexOf(t)})).join(" ").trim()).length:-1!==a.indexOf(l)&&(!0!==N.uris[l]||function(t){var e=t[0];if("#"===e||"/"===e)return!0;var s=t.indexOf(":");if(-1===s)return!0;var i=t.indexOf("?");if(-1!==i&&s>i)return!0;var o=t.indexOf("#");return-1!==o&&s>o||n.allowedSchemes.some(a);function a(e){return 0===t.indexOf(e+":")}}(s)))&&(i(" "),i(t),"string"==typeof s&&(i('="'),i(_.encode(s)),i('"')))})),i(a?"/>":">")},end:function(t){var e=W(t);-1!==(n.allowedTags||[]).indexOf(e)&&!1===s.ignoring?(i("</"),i(e),i(">")):a(e)},chars:function(t){!1===s.ignoring&&i(n.transformText?n.transformText(t):t)}};function i(e){t.push(e)}function o(t){H.voids[t]||(!1===s.ignoring?s={ignoring:t,depth:1}:s.ignoring===t&&s.depth++)}function a(t){s.ignoring===t&&--s.depth<=0&&r()}function r(){s={ignoring:!1,depth:0}}},K={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 Q(t,e,s){var n=[],i=!0===s?e:z({},K,e),o=G(n,i);return V(t,o),n.join("")}Q.defaults=K;const Y=y(Q),J={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","data-src","class","loading"],code:["class"],span:["class","style"]},filter:t=>([["code",/^hljs\W+language-(.*)$/],["span",/^(hljs-.*)$/],["img",/^lazyload$/]].forEach((([e,s])=>{t.tag===e&&t.attrs.class&&!s.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)};function X(t){return Y(t,J)}var Z={exports:{}};const tt=y(Z.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}})),s=["23AC69","91C132","F19726","E8552D","1AAB8E","E1147F","2980C1","1BA1E6","9FA0A0","F19726","E30B20","E30B20","A3338B"];function n(t){return'<span style="color: slategray">'+t+"</span>"}return function(t,i){void 0===i&&(i={});var o=i.colors;void 0===o&&(o=s);var a=0,r={},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,s){if(s)return n(s);if("<"===e)return"<";var i;r[e]?i=r[e]:(i=o[a],r[e]=i);var l='<span style="color: #'+i+'">'+e+"</span>";return a=++a%o.length,l}))}}());function et(t){return tt(t)}function st(t){const e=new h.marked.Renderer;return e.link=nt(e,e.link),e.code=it(),e.image=ot(e,e.image,t),e}const nt=(t,e)=>s=>{const n=(t=>{try{return new URL(t).origin}catch(e){return""}})(s.href)===window.location.origin;return e.call(t,s).replace(/^<a /,`<a target="_blank" ${n?"":'rel="noreferrer noopener nofollow"'} `)},it=()=>({lang:t,text:e})=>{const s=t||"plaintext";let n=e;return window.hljs?s&&window.hljs.getLanguage(s)&&(n=window.hljs.highlight(s,e).value):n=et(e),`<pre rel="${s}">\n<code class="hljs language-${s}">${n.replace(/&/g,"&")}</code>\n</pre>`},ot=(t,e,{imgLazyLoad:s})=>n=>{const i=e.call(t,n);return s?"native"===s||!0===s?i.replace(/^<img /,'<img class="lazyload" loading="lazy" '):"data-src"===s?i.replace(/^<img /,'<img class="lazyload" ').replace("src=","data-src="):i:i};let at,rt=[];const lt={gfm:!0,breaks:!0,async:!1};function ct(){return at}function dt(t){var e;let s=null==(e=ct())?void 0:e.parse(t);s||(s=function(t){return t.replace(/```\s*([^]+?.*?[^]+?[^]+?)```/g,((t,e)=>`<pre><code>${et(e)}</code></pre>`)).replace(/!\[(.*?)\]\((.*?)\)/g,((t,e,s)=>`<img src="${s}" alt="${e}" />`)).replace(/\[(.*?)\]\((.*?)\)/g,((t,e,s)=>`<a href="${s}" target="_blank">${e}</a>`)).replace(/\n/g,"<br>")}(t));let n=X(s);return rt.forEach((t=>{"function"==typeof t&&(n=t(n))})),n}function ht(...t){const e=t=>t&&"object"==typeof t&&t.constructor===Object;return t.reduce(((t,s)=>(Object.keys(null!=s?s:{}).forEach((n=>{if("__proto__"===n||"constructor"===n||"prototype"===n)return;const i=t[n],o=s[n];Array.isArray(i)&&Array.isArray(o)?t[n]=i.concat(...o):e(i)&&e(o)?t[n]=ht(i,o):t[n]=o})),t)),{})}class ut{constructor(t){c(this,"loading",!1),c(this,"listLastFetch"),c(this,"comments",[]),c(this,"notifies",[]),c(this,"page"),this.events=t}getLoading(){return this.loading}setLoading(t){this.loading=t}getListLastFetch(){return this.listLastFetch}setListLastFetch(t){this.listLastFetch=t}getComments(){return this.comments}fetchComments(t){this.events.trigger("list-fetch",t)}findComment(t){return this.comments.find((e=>e.id===t))}clearComments(){this.comments=[],this.events.trigger("list-loaded",this.comments)}loadComments(t){this.events.trigger("list-load",t),this.comments.push(...t),this.events.trigger("list-loaded",this.comments)}insertComment(t){this.comments.push(t),this.events.trigger("comment-inserted",t),this.events.trigger("list-loaded",this.comments)}updateComment(t){this.comments=this.comments.map((e=>e.id===t.id?t:e)),this.events.trigger("comment-updated",t),this.events.trigger("list-loaded",this.comments)}deleteComment(t){const e=this.comments.find((e=>e.id===t));if(!e)throw new Error(`Comment ${t} not found`);this.comments=this.comments.filter((e=>e.id!==t)),this.events.trigger("comment-deleted",e),this.events.trigger("list-loaded",this.comments)}getNotifies(){return this.notifies}updateNotifies(t){this.notifies=t,this.events.trigger("notifies-updated",this.notifies)}getPage(){return this.page}updatePage(t){this.page=t,this.events.trigger("page-loaded",t)}}function pt(t=""){const e=document.createElement("div");return e.innerHTML=t.trim(),e.firstElementChild||e}function mt(t){const e=document.createElement("div");e.innerText=t;return e.innerHTML}function gt(t){const e=RegExp(`[?&]${t}=([^&]*)`).exec(window.location.search);return e&&decodeURIComponent(e[1].replace(/\+/g," "))}function ft(t,e){const s=t=>{const e=t.getBoundingClientRect(),s=window.pageXOffset||document.documentElement.scrollLeft,n=window.pageYOffset||document.documentElement.scrollTop;return{top:e.top+n,left:e.left+s}},n=s(t);if(!e)return n;const i=s(e);return{top:n.top-i.top,left:n.left-i.left}}function yt(t,e){let s=t.toString();for(;s.length<e;)s=`0${s}`;return s}function kt(t,e=t=>t){try{const s=t.getTime(),n=(new Date).getTime()-s,i=Math.floor(n/864e5);if(0===i){const t=n%864e5,s=Math.floor(t/36e5);if(0===s){const s=t%36e5,n=Math.floor(s/6e4);if(0===n){const t=s%6e4,n=Math.round(t/1e3);return n<10?e("now"):`${n} ${e("seconds")}`}return`${n} ${e("minutes")}`}return`${s} ${e("hours")}`}return i<0?e("now"):i<8?`${i} ${e("days")}`:function(t){const e=yt(t.getDate(),2),s=yt(t.getMonth()+1,2);return`${yt(t.getFullYear(),2)}-${s}-${e}`}(t)}catch(s){return console.error(s)," - "}}function vt(){return d(this,null,(function*(){const t=navigator.userAgent;if(!navigator.userAgentData||!navigator.userAgentData.getHighEntropyValues)return t;const e=navigator.userAgentData;let s=null;try{s=yield e.getHighEntropyValues(["platformVersion"])}catch(i){return console.error(i),t}const n=Number(s.platformVersion.split(".")[0]);return"Windows"===e.platform&&n>=13?t.replace(/Windows NT 10.0/,"Windows NT 11.0"):"macOS"===e.platform&&n>=11?t.replace(/(Mac OS X \d+_\d+_\d+|Mac OS X)/,`Mac OS X ${s.platformVersion.replace(/\./g,"_")}`):t}))}function $t(t){let e;try{e=new URL(t)}catch(s){return!1}return"http:"===e.protocol||"https:"===e.protocol}function wt(t){return e=t.base,s=t.path,`${e.replace(/\/$/,"")}/${s.replace(/^\//,"")}`;var e,s}const bt={placeholder:"Leave a comment",noComment:"No Comment",send:"Send",signIn:"Sign in",signUp:"Sign up",save:"Save",nick:"Nickname",email:"Email",link:"Website",emoticon:"Emoji",preview:"Preview",uploadImage:"Upload 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:"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:"Dashboard",userProfile:"Profile",noAccountPrompt:"Don't have an account?",haveAccountPrompt:"Already have an account?",forgetPassword:"Forget Password",resetPassword:"Reset Password",changePassword:"Change Password",confirmPassword:"Confirm Password",passwordMismatch:"Passwords do not match",verificationCode:"Verification Code",verifySend:"Send Code",verifyResend:"Resend",waitSeconds:"Wait {seconds}s",emailVerified:"Email has been verified",password:"Password",username:"Username",nextStep:"Next Step",skipVerify:"Skip verification",logoutConfirm:"Are you sure to logout?",accountMergeNotice:"Your email has multiple accounts with different id.",accountMergeSelectOne:"Please select one you want to merge all the data into it.",accountMergeConfirm:"All data will be merged into one account, the id is {id}.",dismiss:"Dismiss",merge:"Merge",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",updateMsg:"Please update Artalk {name} to get the best experience!",currentVersion:"Current Version",ignore:"Ignore",open:"Open",openName:"Open {name}"},Ct="ArtalkI18n",xt={en:bt,"en-US":bt,"zh-CN":{placeholder:"键入内容...",noComment:"「此时无声胜有声」",send:"发送",signIn:"登录",signUp:"注册",save:"保存",nick:"昵称",email:"邮箱",link:"网址",emoticon:"表情",preview:"预览",uploadImage:"上传图片",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:"控制中心",userProfile:"个人资料",noAccountPrompt:"没有账号?",haveAccountPrompt:"已有账号?",forgetPassword:"忘记密码",resetPassword:"重置密码",changePassword:"修改密码",confirmPassword:"确认密码",passwordMismatch:"两次输入的密码不一致",verificationCode:"验证码",verifySend:"发送验证码",verifyResend:"重新发送",waitSeconds:"等待 {seconds}秒",emailVerified:"邮箱已验证",password:"密码",username:"用户名",nextStep:"下一步",skipVerify:"跳过验证",logoutConfirm:"确定要退出登录吗?",accountMergeNotice:"您的电子邮件下有多个不同 ID 的账户。",accountMergeSelectOne:"请选择将所有数据合并到其中的一个。",accountMergeConfirm:"所有数据将合并到 ID 为 {id} 的账户中。",dismiss:"忽略",merge:"合并",frontend:"前端",backend:"后端",loading:"加载中",loadFail:"加载失败",editing:"修改中",editFail:"修改失败",deleting:"删除中",deleteFail:"删除失败",reqGot:"请求响应",reqAborted:"请求超时或意外终止",updateMsg:"请更新 Artalk {name} 以获得更好的体验!",currentVersion:"当前版本",ignore:"忽略",open:"打开",openName:"打开{name}"}};function Et(t){return t=t.replace(/^([a-zA-Z]+)(-[a-zA-Z]+)?$/,((t,e,s)=>e.toLowerCase()+(s||"").toUpperCase())),xt[t]?xt[t]:window[Ct]&&window[Ct][t]?window[Ct][t]:xt.en}let St="en",Tt=Et(St);function Lt(t){t!==St&&(St=t,Tt="string"==typeof t?Et(t):t)}function At(t,e={}){let s=(null==Tt?void 0:Tt[t])||t;return s=s.replace(/\{\s*(\w+?)\s*\}/g,((t,s)=>e[s]||"")),mt(s)}class Mt{constructor(){c(this,"events",[])}on(t,e,s={}){this.events.push(r({name:t,handler:e},s))}off(t,e){e&&(this.events=this.events.filter((s=>!(s.name===t&&s.handler===e))))}trigger(t,e){this.events.slice(0).filter((e=>e.name===t&&"function"==typeof e.handler)).forEach((s=>{s.once&&this.off(t,s.handler),s.handler(e)}))}}const Pt={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:".artalk-comment-count",pvEl:".artalk-pv-count",statPageKeyAttr:"data-page-key",gravatar:{mirror:"https://www.gravatar.com/avatar/",params:"sha256=1&d=mp&s=240"},pagination:{pageSize:20,readMore:!0,autoLoad:!0},heightLimit:{content:300,children:400,scrollable:!1},imgUpload:!0,reqTimeout:15e3,versionCheck:!0,useBackendConf:!0,locale:"en"};function Ut(t,e=!1){const s=e?ht(Pt,t):t;if(s.el&&"string"==typeof s.el)try{const t=document.querySelector(s.el);if(!t)throw Error(`Target element "${s.el}" was not found.`);s.el=t}catch(n){throw console.error(n),new Error("Please check your Artalk `el` config.")}return""===s.pageKey&&(s.pageKey=`${window.location.pathname}`),""===s.pageTitle&&(s.pageTitle=`${document.title}`),s.server&&(s.server=s.server.replace(/\/$/,"").replace(/\/api\/?$/,"")),"auto"===s.locale&&(s.locale=navigator.language),"auto"===s.flatMode&&(s.flatMode=window.matchMedia("(max-width: 768px)").matches),"number"==typeof s.nestMax&&Number(s.nestMax)<=1&&(s.flatMode=!0),s}function It(t,e){return{baseURL:`${t.server}/api/v2`,siteName:t.site||"",pageKey:t.pageKey||"",pageTitle:t.pageTitle||"",timeout:t.reqTimeout,getApiToken:()=>null==e?void 0:e.get("user").getData().token,userInfo:(null==e?void 0:e.get("user").checkHasBasicUserInfo())?{name:null==e?void 0:e.get("user").getData().name,email:null==e?void 0:e.get("user").getData().email}:void 0,handlers:null==e?void 0:e.getApiHandlers()}}function Ot(t,e,s){let n=null;const i=()=>{const i=(()=>{const s=t.getConf(),n={};return e.forEach((t=>{n[t]=s[t]})),n})();var o,a;(null==n||(o=n,a=i,!(JSON.stringify(o)===JSON.stringify(a))))&&(n=i,s(i))};t.on("mounted",i),t.on("updated",i)}class qt{constructor(t){c(this,"conf"),c(this,"data"),c(this,"$root"),c(this,"events",new Mt),c(this,"mounted",!1),c(this,"apiHandlers",null),c(this,"getCommentList",this.getCommentNodes),c(this,"getCommentDataList",this.getComments),this.conf=t,this.$root=t.el,this.$root.classList.add("artalk"),this.$root.innerHTML="",t.darkMode&&this.$root.classList.add("atk-dark-mode"),this.data=new ut(this.events),this.on("mounted",(()=>{this.mounted=!0}))}inject(t,e){this[t]=e}get(t){return this[t]}getApi(){return new f(It(this.conf,this))}getApiHandlers(){return this.apiHandlers||(this.apiHandlers=function(t){const e=function(){const t=[];return{add:(e,s)=>{t.push({action:e,handler:s})},remove:e=>{const s=t.findIndex((t=>t.action===e));-1!==s&&t.splice(s,1)},get:()=>t}}();return e.add("need_captcha",(e=>t.checkCaptcha(e))),e.add("need_login",(()=>t.checkAdmin({}))),e}(this)),this.apiHandlers}getData(){return this.data}replyComment(t,e){this.editor.setReply(t,e)}editComment(t,e){this.editor.setEditComment(t,e)}fetch(t){this.data.fetchComments(t)}reload(){this.data.fetchComments({offset:0})}listGotoFirst(){this.events.trigger("list-goto-first")}getCommentNodes(){return this.list.getCommentNodes()}getComments(){return this.data.getComments()}editorShowLoading(){this.editor.showLoading()}editorHideLoading(){this.editor.hideLoading()}editorShowNotify(t,e){this.editor.showNotify(t,e)}editorResetState(){this.editor.resetState()}showSidebar(t){this.sidebarLayer.show(t)}hideSidebar(){this.sidebarLayer.hide()}checkAdmin(t){return this.checkerLauncher.checkAdmin(t)}checkCaptcha(t){return this.checkerLauncher.checkCaptcha(t)}on(t,e){this.events.on(t,e)}off(t,e){this.events.off(t,e)}trigger(t,e){this.events.trigger(t,e)}$t(t,e={}){return At(t,e)}setDarkMode(t){this.updateConf({darkMode:t})}updateConf(t){this.conf=ht(this.conf,Ut(t,!1)),this.mounted&&this.events.trigger("updated",this.conf)}getConf(){return this.conf}getEl(){return this.$root}getMarked(){return ct()}watchConf(t,e){Ot(this,t,e)}}function Dt(t,e){let s=t.querySelector(":scope > .atk-loading");s||(s=pt('<div class="atk-loading" 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)&&(s.style.background="transparent"),t.appendChild(s)),s.style.display="";const n=s.querySelector(".atk-loading-spinner");n&&(n.style.display="none",window.setTimeout((()=>{n.isConnected&&(n.style.display="")}),500))}function Rt(t){const e=t.querySelector(":scope > .atk-loading");e&&(e.style.display="none")}function Bt(t,e){t?Dt(e):Rt(e)}function jt(t,e=!0,s){let n;if(s){const e=s.getBoundingClientRect();n=t.getBoundingClientRect().top-e.top+s.scrollTop-s.clientHeight/2+t.clientHeight/2}else{const e=t.getBoundingClientRect();n=e.top+window.scrollY-(window.innerHeight/2-e.height/2)}const i={top:n,left:0,behavior:"instant"};s?s.scroll(i):window.scroll(i)}function Ft(t,e){!function(t,e,s="in"){t.classList.add(`atk-fade-${s}`);const n=()=>{t.classList.remove(`atk-fade-${s}`),t.removeEventListener("animationend",n)};t.addEventListener("animationend",n)}(t,0,"in")}function _t(t,e,s='<span class="atk-error-title">Artalk Error</span>'){let n=t.querySelector(".atk-error-layer");if(null===e)return void(null!==n&&n.remove());n||(n=pt(`<div class="atk-error-layer">${s}<span class="atk-error-text"></span></div>`),t.appendChild(n));const i=n.querySelector(".atk-error-text");i.innerHTML="",null!==e&&(e instanceof HTMLElement?i.appendChild(e):i.innerText=e)}function Wt(t){const e=pt('<div class="atk-checker-iframe-wrap"></div>'),s=pt('<iframe class="atk-fade-in" referrerpolicy="strict-origin-when-cross-origin"></iframe>');s.style.display="none",Dt(e,{transparentBg:!0}),s.src=t.getOpts().getCaptchaIframeURL(),s.onload=()=>{s.style.display="",Rt(e)},e.append(s);const n=pt('<div class="atk-close-btn"><i class="atk-icon atk-icon-close"></i></div>');e.append(n),t.hideInteractInput();let i=!1;return function e(){return d(this,null,(function*(){var s;if(yield(s=1e3,new Promise((t=>{window.setTimeout((()=>{t(null)}),s)}))),i)return;let n=!1;try{n=(yield t.getApi().captcha.getCaptchaStatus()).data.is_pass}catch(o){n=!1}n?t.triggerSuccess():e()}))}(),n.onclick=()=>{i=!0,t.cancel()},e}const Nt={request:(t,e)=>t.getApi().captcha.verifyCaptcha({value:e}),body:t=>t.get("iframe")?Wt(t):function(t){const e=pt(`<span><img class="atk-captcha-img" src="${t.get("img_data")||""}">${At("captchaCheck")}</span>`);return e.querySelector(".atk-captcha-img").onclick=()=>{const s=e.querySelector(".atk-captcha-img");t.getApi().captcha.getCaptcha().then((t=>{s.setAttribute("src",t.data.img_data)})).catch((t=>{console.error("Failed to get captcha image ",t)}))},e}(t),onSuccess(t,e,s,n){t.set("val",s)},onError(t,e,s,n){n.querySelector(".atk-captcha-img").click(),n.querySelector('input[type="text"]').value=""}},Ht={inputType:"password",request(t,e){return d(this,null,(function*(){return(yield t.getApi().user.login({name:t.getUser().getData().name,email:t.getUser().getData().email,password:e})).data}))},body:t=>pt(`<span>${At("adminCheck")}</span>`),onSuccess(t,e,s,n){t.getUser().update({is_admin:!0,token:e.token}),t.getOpts().onReload()},onError(t,e,s,n){}};class zt{constructor(t){c(this,"$el"),c(this,"$content"),c(this,"$actions"),this.$el=pt('<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(t)}setYes(t){const e=pt(`<button data-action="confirm">${At("confirm")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}setNo(t){const e=pt(`<button data-action="cancel">${At("cancel")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}onBtnClick(t){return e=>{const s=t(e.currentTarget,this);void 0!==s&&!0!==s||this.$el.remove()}}}function Vt(t){return e=>new Promise(((s,n)=>{const i=e.onCancel;e.onCancel=()=>{i&&i(),n(new Error("user canceled the checker"))};const o=e.onSuccess;e.onSuccess=()=>{o&&o(),s()},t(e)}))}class Gt{constructor(t){c(this,"checkCaptcha",Vt((t=>{this.fire(Nt,t,(e=>{e.set("img_data",t.img_data),e.set("iframe",t.iframe)}))}))),c(this,"checkAdmin",Vt((t=>{this.fire(Ht,t)}))),this.opts=t}fire(t,e,s){const n=this.opts.getCtx().get("layerManager").create(`checker-${(new Date).getTime()}`);n.show();const i=()=>{n.destroy()},o={};let a=!1;const r={set:(t,e)=>{o[t]=e},get:t=>o[t],getOpts:()=>this.opts,getUser:()=>this.opts.getCtx().get("user"),getApi:()=>this.opts.getApi(),hideInteractInput:()=>{a=!0},triggerSuccess:()=>{i(),t.onSuccess&&t.onSuccess(r,"","",l),e.onSuccess&&e.onSuccess()},cancel:()=>{i(),e.onCancel&&e.onCancel()}};s&&s(r);const l=pt();l.appendChild(t.body(r));const c=pt(`<input id="check" type="${t.inputType||"text"}" autocomplete="off" required placeholder="">`);let d;l.appendChild(c),setTimeout((()=>c.focus()),80),c.onkeyup=t=>{"Enter"!==t.key&&13!==t.keyCode||(t.preventDefault(),n.getEl().querySelector('button[data-action="confirm"]').click())};const h=new zt(l);h.setYes((s=>{const n=c.value.trim();d||(d=s.innerText);const o=()=>{s.innerText=d||"",s.classList.remove("error")};return s.innerText=`${At("loading")}...`,t.request(r,n).then((s=>{i(),t.onSuccess&&t.onSuccess(r,s,n,l),e.onSuccess&&e.onSuccess()})).catch((e=>{var i;i=String(e.message||String(e)),s.innerText=i,s.classList.add("error"),t.onError&&t.onError(r,e,n,l);const a=setTimeout((()=>o()),3e3);c.onfocus=()=>{o(),clearTimeout(a)}})),!1})),h.setNo((()=>(i(),e.onCancel&&e.onCancel(),!1))),a&&(c.style.display="none",h.$el.querySelector(".atk-layer-dialog-actions").style.display="none"),n.getEl().append(h.$el),e.onMount&&e.onMount(h.$el)}}class Kt{constructor(t){c(this,"$el"),this.ctx=t}get conf(){return this.ctx.conf}getEl(){return this.$el}}const Qt={$header:".atk-header",$name:'.atk-header [name="name"]',$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",$bottomLeft:".atk-bottom-left",$stateWrap:".atk-state-wrap",$plugBtnWrap:".atk-plug-btn-wrap",$plugPanelWrap:".atk-plug-panel-wrap"};class Yt{constructor(t){c(this,"$btn"),c(this,"$panel"),c(this,"editorStateEffectWhen"),this.kit=t}useBtn(t="<div></div>"){return this.$btn=pt(`<span class="atk-plug-btn">${t}</span>`),this.$btn}usePanel(t="<div></div>"){return this.$panel=pt(t),this.$panel}useContentTransformer(t){this.contentTransformer=t}usePanelShow(t){this.kit.useEvents().on("panel-show",(e=>{e===this&&t()}))}usePanelHide(t){this.kit.useEvents().on("panel-hide",(e=>{e===this&&t()}))}useEditorStateEffect(t,e){this.editorStateEffectWhen=t,this.editorStateEffect=e}}class Jt extends Yt{constructor(){super(...arguments),c(this,"isMoved",!1)}move(t){if(this.isMoved)return;this.isMoved=!0;const e=this.kit.useUI().$el;e.after(pt('<div class="atk-editor-travel-placeholder"></div>'));const s=pt("<div></div>");t.after(s),s.replaceWith(e),e.classList.add("atk-fade-in"),e.classList.add("editor-traveling")}back(){var t;this.isMoved&&(this.isMoved=!1,null==(t=this.kit.useGlobalCtx().$root.querySelector(".atk-editor-travel-placeholder"))||t.replaceWith(this.kit.useUI().$el),this.kit.useUI().$el.classList.remove("editor-traveling"))}}class Xt{constructor(t){c(this,"stateCurt","normal"),c(this,"stateUnmountFn",null),this.editor=t}get(){return this.stateCurt}switch(t,e){var s,n,i,o,a;if(this.stateUnmountFn&&(this.stateUnmountFn(),this.stateUnmountFn=null,null==(n=null==(s=this.editor.getPlugs())?void 0:s.get(Jt))||n.back()),"normal"!==t&&e){let s=e.$comment;this.editor.conf.flatMode||(s=s.querySelector(".atk-footer")),null==(o=null==(i=this.editor.getPlugs())?void 0:i.get(Jt))||o.move(s);const n=this.editor.ctx.conf.scrollRelativeTo&&this.editor.ctx.conf.scrollRelativeTo();jt(this.editor.getUI().$el,!0,n);const r=null==(a=this.editor.getPlugs())?void 0:a.getPlugs().find((e=>e.editorStateEffectWhen===t));r&&r.editorStateEffect&&(this.stateUnmountFn=r.editorStateEffect(e.comment))}this.stateCurt=t}}class Zt extends Kt{constructor(t){super(t),c(this,"ui"),c(this,"state"),this.ui=function(){const t=pt('<div class="atk-main-editor">\n <div class="atk-header">\n <input name="name" class="atk-name" 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-bottom-left">\n <span class="atk-state-wrap"></span>\n <span class="atk-plug-btn-wrap"></span>\n </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(Qt).forEach((([s,n])=>{e[s]=t.querySelector(n)})),e}(),this.$el=this.ui.$el,this.state=new Xt(this)}getUI(){return this.ui}getPlugs(){return this.ctx.get("editorPlugs")}getState(){return this.state.get()}getHeaderInputEls(){return{name:this.ui.$name,email:this.ui.$email,link:this.ui.$link}}getContentFinal(){let t=this.getContentRaw();const e=this.getPlugs();return e&&(t=e.getTransformedContent(t)),t}getContentRaw(){return this.ui.$textarea.value||""}getContentMarked(){return dt(this.getContentFinal())}setContent(t){var e;this.ui.$textarea.value=t,null==(e=this.getPlugs())||e.getEvents().trigger("content-updated",t)}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,s=this.ui.$textarea.selectionEnd,n=this.ui.$textarea.scrollTop;this.setContent(this.ui.$textarea.value.substring(0,e)+t+this.ui.$textarea.value.substring(s,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=n}else this.ui.$textarea.focus(),this.ui.$textarea.value+=t}focus(){this.ui.$textarea.focus()}reset(){this.setContent(""),this.resetState()}resetState(){this.state.switch("normal")}setReply(t,e){this.state.switch("reply",{comment:t,$comment:e})}setEditComment(t,e){this.state.switch("edit",{comment:t,$comment:e})}showNotify(t,e){!function(t,e,s){const n=pt(`<div class="atk-notify atk-fade-in" style="background-color: ${{s:"#57d59f",e:"#ff6f6c",w:"#ffc721",i:"#2ebcfc"}[s]}"><span class="atk-notify-content"></span></div>`);n.querySelector(".atk-notify-content").innerHTML=mt(e).replace("\n","<br/>"),t.appendChild(n);const i=()=>{n.classList.add("atk-fade-out"),setTimeout((()=>{n.remove()}),200)};let o;o=window.setTimeout((()=>{i()}),3e3),n.addEventListener("click",(()=>{i(),window.clearTimeout(o)}))}(this.ui.$notifyWrap,t,e)}showLoading(){Dt(this.ui.$el)}hideLoading(){Rt(this.ui.$el)}submit(){const t=()=>this.ctx.trigger("editor-submit");this.ctx.conf.beforeSubmit?this.ctx.conf.beforeSubmit(this,t):t()}}class te extends Kt{constructor(t){super(t),c(this,"layer"),c(this,"$header"),c(this,"$closeBtn"),c(this,"$iframeWrap"),c(this,"$iframe"),c(this,"refreshWhenShow",!0),c(this,"animTimer"),this.$el=pt('<div class="atk-sidebar-layer">\n <div class="atk-sidebar-inner">\n <div class="atk-sidebar-header">\n <div class="atk-sidebar-close">\n <i class="atk-icon atk-icon-close-slim"></i>\n </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.refreshWhenShow=!0}))}show(){return d(this,arguments,(function*(t={}){if(this.$el.style.transform="",this.initLayer(),this.layer.show(),this.refreshWhenShow)this.refreshWhenShow=!1,this.$iframeWrap.innerHTML="",this.$iframe=this.createIframe(t.view),this.$iframeWrap.append(this.$iframe);else{const t=this.$iframe,e=t.src;this.getDarkMode()!==e.includes("&darkMode=1")&&this.iframeLoad(t,e.replace(/&darkMode=\d/,`&darkMode=${Number(this.getDarkMode())}`))}this.authCheck({onSuccess:()=>this.show(t)}),this.animTimer=setTimeout((()=>{this.animTimer=void 0,this.$el.style.transform="translate(0, 0)",setTimeout((()=>{this.ctx.getData().updateNotifies([])}),0),this.ctx.trigger("sidebar-show")}),100)}))}hide(){var t;null==(t=this.layer)||t.hide()}authCheck(t){return d(this,null,(function*(){const e=(yield this.ctx.getApi().user.getUserStatus(r({},this.ctx.getApi().getUserFields()))).data;e.is_admin&&!e.is_login&&(this.refreshWhenShow=!0,this.ctx.checkAdmin({onSuccess:()=>{setTimeout((()=>{t.onSuccess()}),500)},onCancel:()=>{this.hide()}}),this.hide())}))}initLayer(){this.layer||(this.layer=this.ctx.get("layerManager").create("sidebar",this.$el),this.layer.setOnAfterHide((()=>{this.ctx.editorResetState(),this.animTimer&&clearTimeout(this.animTimer),this.$el.style.transform="",this.ctx.trigger("sidebar-hide")})))}createIframe(t){const e=pt('<iframe referrerpolicy="strict-origin-when-cross-origin"></iframe>'),s=wt({base:this.ctx.conf.server,path:"/sidebar/"}),n={pageKey:this.conf.pageKey,site:this.conf.site||"",user:JSON.stringify(this.ctx.get("user").getData()),time:+new Date};t&&(n.view=t),n.darkMode=this.getDarkMode()?"1":"0";const i=new URLSearchParams(n);return this.iframeLoad(e,`${s}?${i.toString()}`),e}getDarkMode(){return"auto"===this.conf.darkMode?window.matchMedia("(prefers-color-scheme: dark)").matches:this.conf.darkMode}iframeLoad(t,e){t.src=e,Dt(this.$iframeWrap),t.onload=()=>{Rt(this.$iframeWrap)}}}const ee=t=>({import:e=>{(function(t,e="DATE_DESC",s=2){const n=[];t.filter((t=>0===t.rid)).forEach((e=>{const i={id:e.id,comment:e,children:[],level:1};i.parent=i,n.push(i),function e(n){const i=t.filter((t=>t.rid===n.id));0!==i.length&&(n.level>=s&&(n=n.parent),i.forEach((t=>{const s={id:t.id,comment:t,children:[],parent:n,level:n.level+1};n.children.push(s),e(s)})))}(i)}));const i=(s,n)=>{let i=s.id-n.id;return"DATE_ASC"===e?i=+new Date(s.comment.date)-+new Date(n.comment.date):"DATE_DESC"===e?i=+new Date(n.comment.date)-+new Date(s.comment.date):"SRC_INDEX"===e?i=t.indexOf(s.comment)-t.indexOf(n.comment):"VOTE_UP_DESC"===e&&(i=n.comment.vote_up-s.comment.vote_up),i};return function t(e){e.forEach((e=>{e.children=e.children.sort(i),t(e.children)}))}(n),n})(e,t.nestSortBy,t.nestMax).forEach((s=>{var n;const i=t.createCommentNode(s.comment);null==(n=t.$commentsWrap)||n.appendChild(i.getEl()),i.getRender().playFadeAnim();const o=(s,n)=>{n.children.forEach((n=>{const i=e.find((t=>t.id===n.comment.rid)),a=n.comment,r=t.createCommentNode(a,i);s.putChild(r),o(r,n)}))};o(i,s),i.getRender().checkHeightLimit()}))},insert:(e,s)=>{var n;const i=t.createCommentNode(e,s);if(0===e.rid)null==(n=t.$commentsWrap)||n.prepend(i.getEl());else{const s=t.findCommentNode(e.rid);s&&(s.putChild(i,"DATE_ASC"===t.nestSortBy?"append":"prepend"),i.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()})))}i.getRender().checkHeightLimit(),i.scrollIntoView(),i.getRender().playFadeAnim()}});function se(t,e,s,n){s.is_collapsed&&(s.is_allow_reply=!1);const i=t.createCommentNode(s,n);if(s.visible){const s=i.getEl(),n=t.$commentsWrap;"append"===e&&(null==n||n.append(s)),"prepend"===e&&(null==n||n.prepend(s)),i.getRender().playFadeAnim()}return i.getRender().checkHeightLimit(),i}class ne{constructor(t){this.options=t}getStrategy(){return this.options.flatMode?(t=this.options,{import:e=>{e.forEach((s=>{const n=0===s.rid?void 0:e.find((t=>t.id===s.rid));se(t,"append",s,n)}))},insert:(e,s)=>{se(t,"prepend",e,s).scrollIntoView()}}):ee(this.options);var t}import(t){this.getStrategy().import(t)}insert(t,e){this.getStrategy().insert(t,e)}}function ie(t,e){e.forEach((({el:e,max:s,imgCheck:n})=>{if(!e)return;n&&(e.style.maxHeight=`${s+1}px`);let i=!1;const o=()=>{if(i)return;if(function(t){return parseFloat(getComputedStyle(t,null).height.replace("px",""))||0}(e)<=s)return;t.scrollable?function(t){if(!t.el)return;if(t.el.classList.contains(re))return;t.el.classList.add(re),t.el.style.height=`${t.max}px`}({el:e,max:s}):function(t){if(!t.el)return;if(!t.max)return;if(t.el.classList.contains(oe))return;t.el.classList.add(oe),t.el.style.height=`${t.max}px`,t.el.style.overflow="hidden";const e=pt(`<div class="atk-height-limit-btn">${At("readMore")}</span>`);e.onclick=e=>{e.stopPropagation(),ae(t.el),t.afterExpandBtnClick&&t.afterExpandBtnClick(e)},t.el.append(e)}({el:e,max:s,afterExpandBtnClick:()=>{var e;i=!0,null==(e=t.afterExpandBtnClick)||e.call(t)}})};if(o(),n){const t=e.querySelectorAll(".atk-content img");0===t.length&&(e.style.maxHeight=""),t.forEach((t=>{t.onload=()=>o()}))}}))}const oe="atk-height-limit";function ae(t){t&&t.classList.contains(oe)&&(t.classList.remove(oe),Array.from(t.children).forEach((t=>{t.classList.contains("atk-height-limit-btn")&&t.remove()})),t.style.height="",t.style.maxHeight="",t.style.overflow="")}const re="atk-height-limit-scroll";function le(t){if(t.$headerNick=t.$el.querySelector(".atk-nick"),t.data.link){const e=pt('<a target="_blank" rel="noreferrer noopener nofollow"></a>');e.innerText=t.data.nick,e.href=$t(t.data.link)?t.data.link:`https://${t.data.link}`,t.$headerNick.append(e)}else t.$headerNick.innerText=t.data.nick}function ce(t){t.$headerBadgeWrap=t.$el.querySelector(".atk-badge-wrap"),t.$headerBadgeWrap.innerHTML="";const e=t.data.badge_name,s=t.data.badge_color;if(e){const n=pt('<span class="atk-badge"></span>');n.innerText=e.replace("管理员",At("admin")),n.style.backgroundColor=s||"",t.$headerBadgeWrap.append(n)}else if(t.data.is_verified){const e=pt(`<span class="atk-verified-icon" title="${At("emailVerified")}"></span>`);t.$headerBadgeWrap.append(e)}if(t.data.is_pinned){const e=pt(`<span class="atk-pinned-badge">${At("pin")}</span>`);t.$headerBadgeWrap.append(e)}}function de(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 he(t){if(!t.opts.uaBadge&&!t.data.ip_region)return;let e=t.$header.querySelector("atk-ua-wrap");if(e||(e=pt('<span class="atk-ua-wrap"></span>'),t.$header.append(e)),e.innerHTML="",t.data.ip_region){const s=pt('<span class="atk-region-badge"></span>');s.innerText=t.data.ip_region,e.append(s)}if(t.opts.uaBadge){const{browser:s,os:n}=t.comment.getUserUA();if(String(s).trim()){const t=pt('<span class="atk-ua ua-browser"></span>');t.innerText=s,e.append(t)}if(String(n).trim()){const t=pt('<span class="atk-ua ua-os"></span>');t.innerText=n,e.append(t)}}}class ue{constructor(t){c(this,"opts"),c(this,"$el"),c(this,"isLoading",!1),c(this,"msgRecTimer"),c(this,"msgRecTimerFunc"),c(this,"isConfirming",!1),c(this,"confirmRecTimer"),this.$el=pt('<span class="atk-common-action-btn"></span>'),this.opts="object"!=typeof t?{text:t}:t,this.$el.innerText=this.getText(),this.opts.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.opts.text?this.opts.text:this.opts.text()}setClick(t){this.$el.onclick=e=>{if(e.stopPropagation(),!this.isLoading){if(this.opts.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.opts.confirmText||At("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.opts.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||`${At("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,s,n){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),n&&n()}),s||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 pe(t){t.opts.vote&&(t.voteBtnUp=new ue((()=>`${At("voteUp")} (${t.data.vote_up||0})`)).appendTo(t.$actions),t.voteBtnUp.setClick((()=>{t.comment.getActions().vote("up")})),t.opts.voteDown&&(t.voteBtnDown=new ue((()=>`${At("voteDown")} (${t.data.vote_down||0})`)).appendTo(t.$actions),t.voteBtnDown.setClick((()=>{t.comment.getActions().vote("down")}))))}function me(t){if(!t.data.is_allow_reply)return;const e=pt(`<span>${At("reply")}</span>`);t.$actions.append(e),e.addEventListener("click",(e=>{e.stopPropagation(),t.opts.replyComment(t.data,t.$el)}))}function ge(t){const e=new ue({text:()=>t.data.is_collapsed?At("expand"):At("collapse"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("collapsed",e)}))}function fe(t){const e=new ue({text:()=>t.data.is_pending?At("pending"):At("approved"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pending",e)}))}function ye(t){const e=new ue({text:()=>t.data.is_pinned?At("unpin"):At("pin"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pinned",e)}))}function ke(t){const e=new ue({text:At("edit"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.opts.editComment(t.data,t.$el)}))}function ve(t){const e=new ue({text:At("delete"),confirm:!0,confirmText:At("deleteConfirm"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminDelete(e)}))}const $e={Avatar:function(t){const e=t.$el.querySelector(".atk-avatar"),s=pt("<img />"),n=t.opts.avatarURLBuilder;if(s.src=n?n(t.data):t.comment.getGravatarURL(),t.data.link){const n=pt('<a target="_blank" rel="noreferrer noopener nofollow"></a>');n.href=$t(t.data.link)?t.data.link:`https://${t.data.link}`,n.append(s),e.append(n)}else e.append(s)},Header:function(t){Object.entries({renderNick:le,renderVerifyBadge:ce,renderDate:de,renderUABadge:he}).forEach((([e,s])=>{s(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=pt(`\n <div class="atk-collapsed">\n <span class="atk-text">${At("collapsedMsg")}</span>\n <span class="atk-show-btn">${At("expand")}</span>\n </div>`);t.$body.insertAdjacentElement("beforeend",e);const s=e.querySelector(".atk-show-btn");s.addEventListener("click",(e=>{e.stopPropagation(),t.$content.classList.contains("atk-hide")?(t.$content.innerHTML=t.comment.getContentMarked(),t.$content.classList.remove("atk-hide"),Ft(t.$content),s.innerText=At("collapse")):(t.$content.innerHTML="",t.$content.classList.add("atk-hide"),s.innerText=At("expand"))}))},ReplyAt:function(t){t.opts.flatMode||0===t.data.rid||t.opts.replyTo&&(t.$replyAt=pt('<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.opts.replyTo.nick}`,t.$replyAt.onclick=()=>{t.comment.getActions().goToReplyComment()},t.$headerBadgeWrap.insertAdjacentElement("afterend",t.$replyAt))},ReplyTo:function(t){if(!t.opts.flatMode)return;if(!t.opts.replyTo)return;t.$replyTo=pt(`\n <div class="atk-reply-to">\n <div class="atk-meta">${At("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.opts.replyTo.nick}`,e.onclick=()=>{t.comment.getActions().goToReplyComment()};let s=dt(t.opts.replyTo.content);t.opts.replyTo.is_collapsed&&(s=`[${At("collapsed")}]`),t.$replyTo.querySelector(".atk-content").innerHTML=s,t.$body.prepend(t.$replyTo)},Pending:function(t){if(!t.data.is_pending)return;const e=pt(`<div class="atk-pending">${At("pendingMsg")}</div>`);t.$body.prepend(e)},Actions:function(t){Object.entries({renderVote:pe,renderReply:me,renderCollapse:ge,renderModerator:fe,renderPin:ye,renderEdit:ke,renderDel:ve}).forEach((([e,s])=>{s(t)}))}};class we{constructor(t){c(this,"comment"),c(this,"$el"),c(this,"$main"),c(this,"$header"),c(this,"$headerNick"),c(this,"$headerBadgeWrap"),c(this,"$body"),c(this,"$content"),c(this,"$childrenWrap"),c(this,"$actions"),c(this,"voteBtnUp"),c(this,"voteBtnDown"),c(this,"$replyTo"),c(this,"$replyAt"),this.comment=t}get data(){return this.comment.getData()}get opts(){return this.comment.getOpts()}render(){var t;return this.$el=pt('<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($e).forEach((([e,s])=>{s(t)})),this.$childrenWrap&&this.$main.append(this.$childrenWrap),this.$el}checkHeightLimit(){const t=this.opts.heightLimit;if(!t||!t.content||!t.children)return;const e=t.content,s=t.children;ie({afterExpandBtnClick:()=>{const t=this.comment.getChildren();1===t.length&&ae(t[0].getRender().$content)},scrollable:t.scrollable},[{el:this.$content,max:e,imgCheck:!0},{el:this.$replyTo,max:e,imgCheck:!0},{el:this.$childrenWrap,max:s,imgCheck:!1}])}heightLimitRemoveForChildren(){this.$childrenWrap&&ae(this.$childrenWrap)}playFadeAnim(){Ft(this.comment.getRender().$el)}playFadeAnimForBody(){Ft(this.comment.getRender().$body)}playFlashAnim(){this.$el.classList.remove("atk-flash-once"),window.setTimeout((()=>{this.$el.classList.add("atk-flash-once")}),150)}getChildrenWrap(){return this.$childrenWrap||(this.$childrenWrap=pt('<div class="atk-comment-children"></div>'),this.$main.append(this.$childrenWrap)),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.stopPropagation(),window.open(t)}}setOpenAction(t){this.setOpenable(!0),this.$el.onclick=e=>{e.stopPropagation(),t()}}}class be{constructor(t){c(this,"comment"),this.comment=t}get data(){return this.comment.getData()}get opts(){return this.comment.getOpts()}getApi(){return this.comment.getOpts().getApi()}vote(t){const e="up"===t?this.comment.getRender().voteBtnUp:this.comment.getRender().voteBtnDown;this.getApi().votes.vote(`comment_${t}`,this.data.id,r({},this.getApi().getUserFields())).then((t=>{var e,s;this.data.vote_up=t.data.up,this.data.vote_down=t.data.down,null==(e=this.comment.getRender().voteBtnUp)||e.updateText(),null==(s=this.comment.getRender().voteBtnDown)||s.updateText()})).catch((t=>{null==e||e.setError(At("voteFail")),console.error(t)}))}adminEdit(t,e){if(e.isLoading)return;e.setLoading(!0,`${At("editing")}...`);const s=r({},this.data);"collapsed"===t?s.is_collapsed=!s.is_collapsed:"pending"===t?s.is_pending=!s.is_pending:"pinned"===t&&(s.is_pinned=!s.is_pinned),this.getApi().comments.updateComment(this.data.id,r({},s)).then((t=>{e.setLoading(!1),this.comment.setData(t.data)})).catch((t=>{console.error(t),e.setError(At("editFail"))}))}adminDelete(t){t.isLoading||(t.setLoading(!0,`${At("deleting")}...`),this.getApi().comments.deleteComment(this.data.id).then((()=>{t.setLoading(!1),this.opts.onDelete&&this.opts.onDelete(this.comment)})).catch((e=>{console.error(e),t.setError(At("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 Ce{constructor(t,e){c(this,"$el"),c(this,"renderInstance"),c(this,"actionInstance"),c(this,"data"),c(this,"opts"),c(this,"parent"),c(this,"children",[]),c(this,"nestCurt"),this.opts=e,this.data=r({},t),this.data.date=this.data.date.replace(/-/g,"/"),this.parent=null,this.nestCurt=1,this.actionInstance=new be(this),this.renderInstance=new we(this)}render(){const t=this.renderInstance.render();this.$el&&this.$el.replaceWith(t),this.$el=t,this.opts.onAfterRender&&this.opts.onAfterRender()}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 s=this.getChildrenWrapEl(),n=t.getEl();"append"===e?s.append(n):"prepend"===e&&s.prepend(n),t.getRender().playFadeAnim(),t.getRender().checkHeightLimit()}getChildrenWrapEl(){return this.nestCurt>=this.opts.nestMax?this.parent.getChildrenWrapEl():this.getRender().getChildrenWrap()}getParents(){const t=[];let e=this.parent;for(;e;)t.push(e),e=e.getParent();return t}getEl(){if(!this.$el)throw new Error("comment element not initialized before `getEl()`");return this.$el}focus(){if(!this.$el)throw new Error("comment element not initialized before `focus()`");this.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()})),this.scrollIntoView(),this.getRender().playFlashAnim()}scrollIntoView(){this.$el&&jt(this.$el,!1,this.opts.scrollRelativeTo&&this.opts.scrollRelativeTo())}remove(){var t;null==(t=this.$el)||t.remove()}getGravatarURL(){return`${(t={mirror:this.opts.gravatar.mirror,params:this.opts.gravatar.params,emailHash:this.data.email_encrypted}).mirror.replace(/\/$/,"")}/${t.emailHash}?${t.params.replace(/^\?/,"")}`;var t}getContentMarked(){return dt(this.data.content)}getDateFormatted(){var t,e;const s=new Date(this.data.date);return(null==(e=(t=this.opts).dateFormatter)?void 0:e.call(t,s))||kt(s,At)}getUserUA(){const t=function(t){const e=window||{},s=navigator||{},n=String(t||s.userAgent),i={os:"",osVersion:"",engine:"",browser:"",device:"",language:"",version:""},o={Trident:n.includes("Trident")||n.includes("NET CLR"),Presto:n.includes("Presto"),WebKit:n.includes("AppleWebKit"),Gecko:n.includes("Gecko/")},a={Safari:n.includes("Safari"),Chrome:n.includes("Chrome")||n.includes("CriOS"),IE:n.includes("MSIE")||n.includes("Trident"),Edge:n.includes("Edge")||n.includes("Edg"),Firefox:n.includes("Firefox")||n.includes("FxiOS"),"Firefox Focus":n.includes("Focus"),Chromium:n.includes("Chromium"),Opera:n.includes("Opera")||n.includes("OPR"),Vivaldi:n.includes("Vivaldi"),Yandex:n.includes("YaBrowser"),Kindle:n.includes("Kindle")||n.includes("Silk/"),360:n.includes("360EE")||n.includes("360SE"),UC:n.includes("UC")||n.includes(" UBrowser"),QQBrowser:n.includes("QQBrowser"),QQ:n.includes("QQ/"),Baidu:n.includes("Baidu")||n.includes("BIDUBrowser"),Maxthon:n.includes("Maxthon"),Sogou:n.includes("MetaSr")||n.includes("Sogou"),LBBROWSER:n.includes("LBBROWSER"),"2345Explorer":n.includes("2345Explorer"),TheWorld:n.includes("TheWorld"),MIUI:n.includes("MiuiBrowser"),Quark:n.includes("Quark"),Qiyu:n.includes("Qiyu"),Wechat:n.includes("MicroMessenger"),Taobao:n.includes("AliApp(TB"),Alipay:n.includes("AliApp(AP"),Weibo:n.includes("Weibo"),Douban:n.includes("com.douban.frodo"),Suning:n.includes("SNEBUY-APP"),iQiYi:n.includes("IqiyiApp")},r={Windows:n.includes("Windows"),Linux:n.includes("Linux")||n.includes("X11"),macOS:n.includes("Macintosh"),Android:n.includes("Android")||n.includes("Adr"),Ubuntu:n.includes("Ubuntu"),FreeBSD:n.includes("FreeBSD"),Debian:n.includes("Debian"),"Windows Phone":n.includes("IEMobile")||n.includes("Windows Phone"),BlackBerry:n.includes("BlackBerry")||n.includes("RIM"),MeeGo:n.includes("MeeGo"),Symbian:n.includes("Symbian"),iOS:n.includes("like Mac OS X"),"Chrome OS":n.includes("CrOS"),WebOS:n.includes("hpwOS")},l={Mobile:n.includes("Mobi")||n.includes("iPh")||n.includes("480"),Tablet:n.includes("Tablet")||n.includes("Pad")||n.includes("Nexus 7")};l.Mobile?l.Mobile=!n.includes("iPad"):a.Chrome&&n.includes("Edg")?(a.Chrome=!1,a.Edge=!0):e.showModalDialog&&e.chrome&&(a.Chrome=!1,a[360]=!0),i.device="PC",i.language=(()=>{const t=(s.browserLanguage||s.language).split("-");return t[1]&&(t[1]=t[1].toUpperCase()),t.join("_")})();const c={engine:o,browser:a,os:r,device:l};Object.entries(c).forEach((([t,e])=>{Object.entries(e).forEach((([e,s])=>{!0===s&&(i[t]=e)}))}));const d={Windows:()=>{const t=n.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:()=>n.replace(/^.*Android ([\d.]+);.*$/,"$1"),iOS:()=>n.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,"."),Debian:()=>n.replace(/^.*Debian\/([\d.]+).*$/,"$1"),"Windows Phone":()=>n.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2"),macOS:()=>n.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,"."),WebOS:()=>n.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")};i.osVersion="",d[i.os]&&(i.osVersion=d[i.os](),i.osVersion===n&&(i.osVersion=""));const h={Safari:()=>n.replace(/^.*Version\/([\d.]+).*$/,"$1"),Chrome:()=>n.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1"),IE:()=>n.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1"),Edge:()=>n.replace(/^.*(Edge|Edg|Edg[A-Z]{1})\/([\d.]+).*$/,"$2"),Firefox:()=>n.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1"),"Firefox Focus":()=>n.replace(/^.*Focus\/([\d.]+).*$/,"$1"),Chromium:()=>n.replace(/^.*Chromium\/([\d.]+).*$/,"$1"),Opera:()=>n.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1"),Vivaldi:()=>n.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1"),Yandex:()=>n.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1"),Kindle:()=>n.replace(/^.*Version\/([\d.]+).*$/,"$1"),Maxthon:()=>n.replace(/^.*Maxthon\/([\d.]+).*$/,"$1"),QQBrowser:()=>n.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1"),QQ:()=>n.replace(/^.*QQ\/([\d.]+).*$/,"$1"),Baidu:()=>n.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1"),UC:()=>n.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1"),Sogou:()=>n.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1"),"2345Explorer":()=>n.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1"),TheWorld:()=>n.replace(/^.*TheWorld ([\d.]+).*$/,"$1"),MIUI:()=>n.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1"),Quark:()=>n.replace(/^.*Quark\/([\d.]+).*$/,"$1"),Qiyu:()=>n.replace(/^.*Qiyu\/([\d.]+).*$/,"$1"),Wechat:()=>n.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1"),Taobao:()=>n.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1"),Alipay:()=>n.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1"),Weibo:()=>n.replace(/^.*weibo__([\d.]+).*$/,"$1"),Douban:()=>n.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1"),Suning:()=>n.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1"),iQiYi:()=>n.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")};return i.version="",h[i.browser]&&(i.version=h[i.browser](),i.version===n&&(i.version="")),i.version.indexOf(".")&&(i.version=i.version.substring(0,i.version.indexOf("."))),"iOS"===i.os&&n.includes("iPad")?i.os="iPadOS":"Edge"!==i.browser||n.includes("Edg")?"MIUI"===i.browser?i.os="Android":"Chrome"===i.browser&&Number(i.version)>27||"Opera"===i.browser&&Number(i.version)>12||"Yandex"===i.browser?i.engine="Blink":void 0===i.browser&&(i.browser="Unknow App"):i.engine="EdgeHTML",i}(this.data.ua);return{browser:`${t.browser} ${t.version}`,os:`${t.os} ${t.osVersion}`}}getOpts(){return this.opts}}class xe{constructor(t){c(this,"opts"),c(this,"$el"),c(this,"$loading"),c(this,"$text"),c(this,"offset",0),c(this,"total",0),c(this,"origText","Load More"),this.opts=t,this.origText=this.opts.text||this.origText,this.$el=pt(`<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.opts.pageSize}click(){this.hasMore&&this.opts.onClick(this.offset+this.opts.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()}}class Ee{constructor(){c(this,"instance"),c(this,"onReachedBottom",null),c(this,"opt")}create(t){return this.opt=t,this.instance=new xe({pageSize:t.pageSize,onClick:e=>d(this,null,(function*(){t.ctx.fetch({offset:e})})),text:At("loadMore")}),t.readMoreAutoLoad&&(this.onReachedBottom=()=>{this.instance.hasMore&&!this.opt.ctx.getData().getLoading()&&this.instance.click()},this.opt.ctx.on("list-reach-bottom",this.onReachedBottom)),this.instance.$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()}getHasMore(){return this.instance.hasMore}getIsClearComments(t){return 0===t.offset}dispose(){this.onReachedBottom&&this.opt.ctx.off("list-reach-bottom",this.onReachedBottom),this.instance.$el.remove()}}class Se{constructor(t,e){c(this,"opts"),c(this,"total"),c(this,"$el"),c(this,"$input"),c(this,"inputTimer"),c(this,"$prevBtn"),c(this,"$nextBtn"),c(this,"page",1),this.total=t,this.opts=e,this.$el=pt('<div class="atk-pagination-wrap">\n <div class="atk-pagination">\n <div class="atk-btn atk-btn-prev" aria-label="Previous page">\n <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="14px" width="14px" xmlns="http://www.w3.org/2000/svg"><path d="M217.9 256L345 129c9.4-9.4 9.4-24.6 0-33.9-9.4-9.4-24.6-9.3-34 0L167 239c-9.1 9.1-9.3 23.7-.7 33.1L310.9 417c4.7 4.7 10.9 7 17 7s12.3-2.3 17-7c9.4-9.4 9.4-24.6 0-33.9L217.9 256z"></path></svg>\n </div>\n <input type="text" class="atk-input" aria-label="Enter the number of page" />\n <div class="atk-btn atk-btn-next" aria-label="Next page">\n <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="14px" width="14px" xmlns="http://www.w3.org/2000/svg"><path d="M294.1 256L167 129c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.3 34 0L345 239c9.1 9.1 9.3 23.7.7 33.1L201.1 417c-4.7 4.7-10.9 7-17 7s-12.3-2.3-17-7c-9.4-9.4-9.4-24.6 0-33.9l127-127.1z"></path></svg>\n </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.opts.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(),s=()=>{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?s():this.inputTimer=window.setTimeout((()=>s()),800)}prev(){const t=this.page-1;t<1||this.change(t)}next(){const t=this.page+1;t>this.maxPage||this.change(t)}getHasMore(){return this.page+1<=this.maxPage}change(t){this.page=t,this.opts.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?Dt(this.$el):Rt(this.$el)}}class Te{constructor(){c(this,"instance")}create(t){return this.instance=new Se(t.total,{pageSize:t.pageSize,onChange:e=>d(this,null,(function*(){t.ctx.editorResetState(),t.ctx.fetch({offset:e,onSuccess:()=>{t.ctx.listGotoFirst()}})}))}),this.instance.$el}setLoading(t){this.instance.setLoading(t)}update(t,e){this.instance.update(t,e)}next(){this.instance.next()}getHasMore(){return this.instance.getHasMore()}getIsClearComments(){return!0}dispose(){this.instance.$el.remove()}}function Le(t){const e=t.getData().getListLastFetch(),s={offset:0,total:0};return e?(s.offset=e.params.offset,e.data&&(s.total=e.params.flatMode?e.data.count:e.data.roots_count),s):s}const Ae=t=>{let e=null;t.watchConf(["pagination","locale"],(s=>{const n=t.get("list");e&&e.dispose(),e=function(t){return t.pagination.readMore?new Ee:new Te}(s);const{offset:i,total:o}=Le(t),a=e.create({ctx:t,pageSize:s.pagination.pageSize,total:o,readMoreAutoLoad:s.pagination.autoLoad});n.$commentsWrap.after(a),null==e||e.update(i,o)})),t.on("list-loaded",(s=>{const{offset:n,total:i}=Le(t);null==e||e.update(n,i)})),t.on("list-fetch",(s=>{t.getData().getComments().length>0&&(null==e?void 0:e.getIsClearComments(s))&&t.getData().clearComments()})),t.on("list-failed",(()=>{var t;null==(t=null==e?void 0:e.showErr)||t.call(e,At("loadFail"))})),t.on("list-fetch",(t=>{null==e||e.setLoading(!0)})),t.on("list-fetched",(({params:t})=>{null==e||e.setLoading(!1)}))};class Me extends Kt{constructor(t){super(t),c(this,"$commentsWrap"),c(this,"commentNodes",[]),this.$el=pt('<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">\n <div class="atk-list-comments-wrap"></div>\n </div>\n <div class="atk-list-footer">\n <div class="atk-copyright"></div>\n </div>\n</div>\n'),this.$commentsWrap=this.$el.querySelector(".atk-list-comments-wrap"),Ae(t),this.initCrudEvents()}getCommentsWrapEl(){return this.$commentsWrap}getCommentNodes(){return this.commentNodes}getListLayout({forceFlatMode:t}={}){return new ne({$commentsWrap:this.$commentsWrap,nestSortBy:this.ctx.conf.nestSort,nestMax:this.ctx.conf.nestMax,flatMode:"boolean"==typeof t?t:this.ctx.conf.flatMode,createCommentNode:(e,s)=>{const n=function(t,e,s,n){const i=new Ce(e,{onAfterRender:()=>{t.trigger("comment-rendered",i)},onDelete:e=>{t.getData().deleteComment(e.getID())},replyTo:s,flatMode:"boolean"==typeof(null==n?void 0:n.forceFlatMode)?null==n?void 0:n.forceFlatMode:t.conf.flatMode,gravatar:t.conf.gravatar,nestMax:t.conf.nestMax,heightLimit:t.conf.heightLimit,avatarURLBuilder:t.conf.avatarURLBuilder,scrollRelativeTo:t.conf.scrollRelativeTo,vote:t.conf.vote,voteDown:t.conf.voteDown,uaBadge:t.conf.uaBadge,dateFormatter:t.conf.dateFormatter,getApi:()=>t.getApi(),replyComment:(e,s)=>t.replyComment(e,s),editComment:(e,s)=>t.editComment(e,s)});return i.render(),i}(this.ctx,e,s,{forceFlatMode:t});return this.commentNodes.push(n),n},findCommentNode:t=>this.commentNodes.find((e=>e.getID()===t))})}initCrudEvents(){this.ctx.on("list-load",(t=>{this.getListLayout().import(t)})),this.ctx.on("list-loaded",(t=>{0===t.length&&(this.commentNodes=[],this.$commentsWrap.innerHTML="")})),this.ctx.on("comment-inserted",(t=>{var e;const s=t.rid?null==(e=this.commentNodes.find((e=>e.getID()===t.rid)))?void 0:e.getData():void 0;this.getListLayout().insert(t,s)})),this.ctx.on("comment-deleted",(t=>{const e=this.commentNodes.find((e=>e.getID()===t.id));e?(e.remove(),this.commentNodes=this.commentNodes.filter((e=>e.getID()!==t.id))):console.error(`comment node id=${t.id} not found`)})),this.ctx.on("comment-updated",(t=>{const e=this.commentNodes.find((e=>e.getID()===t.id));e&&e.setData(t)}))}}let Pe,Ue;function Ie(){return{init(){Pe=document.body.style.overflow,Ue=document.body.style.paddingRight},unlock(){document.body.style.overflow=Pe,document.body.style.paddingRight=Ue},lock(){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 s=t.offsetWidth;e.style.overflow="scroll";let n=t.offsetWidth;return s===n&&(n=e.clientWidth),document.body.removeChild(e),s-n}()+t||0}px`}}}class Oe{constructor(t,e){c(this,"allowMaskClose",!0),c(this,"onAfterHide"),this.$el=t,this.opts=e}setOnAfterHide(t){this.onAfterHide=t}setAllowMaskClose(t){this.allowMaskClose=t}getAllowMaskClose(){return this.allowMaskClose}getEl(){return this.$el}show(){this.opts.onShow(),this.$el.style.display=""}hide(){this.opts.onHide(),this.$el.style.display="none",this.onAfterHide&&this.onAfterHide()}destroy(){this.opts.onHide(),this.$el.remove(),this.onAfterHide&&this.onAfterHide()}}class qe{constructor(){c(this,"$wrap"),c(this,"$mask"),c(this,"items",[]),this.$wrap=pt('<div class="atk-layer-wrap" style="display: none;"><div class="atk-layer-mask"></div></div>'),this.$mask=this.$wrap.querySelector(".atk-layer-mask")}createItem(t,e){(e=e||this.createItemElement(t)).setAttribute("data-layer-name",t),this.$wrap.appendChild(e);const s=new Oe(e,{onHide:()=>this.hideWrap(e),onShow:()=>this.showWrap()});return this.getMask().addEventListener("click",(()=>{s.getAllowMaskClose()&&s.hide()})),this.items.push(s),s}createItemElement(t){const e=document.createElement("div");return e.classList.add("atk-layer-item"),e.style.display="none",this.$wrap.appendChild(e),e}getWrap(){return this.$wrap}getMask(){return this.$mask}showWrap(){this.$wrap.style.display="block",this.$mask.style.display="block",this.$mask.classList.add("atk-fade-in"),Ie().lock()}hideWrap(t){this.items.map((t=>t.getEl())).filter((e=>e!==t&&e.isConnected&&"none"!==e.style.display)).length>0||(this.$wrap.style.display="none",Ie().unlock())}}class De{constructor(t){c(this,"wrap"),this.wrap=new qe,document.body.appendChild(this.wrap.getWrap()),t.on("unmounted",(()=>{this.wrap.getWrap().remove()})),Ie().init()}getEl(){return this.wrap.getWrap()}create(t,e){return this.wrap.createItem(t,e)}}const Re="ArtalkUser";class Be{constructor(t){c(this,"data"),this.opts=t;const e=JSON.parse(window.localStorage.getItem(Re)||"{}");this.data={name:e.name||e.nick||"",email:e.email||"",link:e.link||"",token:e.token||"",is_admin:e.is_admin||e.isAdmin||!1}}getData(){return this.data}update(t={}){Object.entries(t).forEach((([t,e])=>{this.data[t]=e})),window.localStorage.setItem(Re,JSON.stringify(this.data)),this.opts.onUserChanged&&this.opts.onUserChanged(this.data)}logout(){this.update({token:"",is_admin:!1})}checkHasBasicUserInfo(){return!!this.data.name&&!!this.data.email}}const je={i18n(t){Lt(t.conf.locale),t.watchConf(["locale"],(t=>{Lt(t.locale)}))},user:t=>new Be({onUserChanged:e=>{t.trigger("user-changed",e)}}),layerManager:t=>new De(t),checkerLauncher:t=>new Gt({getCtx:()=>t,getApi:()=>t.getApi(),onReload:()=>t.reload(),getCaptchaIframeURL:()=>`${t.conf.server}/api/v2/captcha/?t=${+new Date}`}),editor(t){const e=new Zt(t);return t.$root.appendChild(e.$el),e},list(t){const e=new Me(t);return t.$root.appendChild(e.$el),e},sidebarLayer:t=>new te(t),editorPlugs(){}};function Fe(t){return d(this,null,(function*(){yield function(t){return d(this,null,(function*(){yield _e({opt:t,query:"page_comment",containers:[t.countEl,"#ArtalkCount"]})}))}(t);const e=yield function(t){return d(this,null,(function*(){if(!t.pvAdd||!t.pageKey)return;const e=(yield t.getApi().pages.logPv({page_key:t.pageKey,page_title:t.pageTitle,site_name:t.siteName})).data.pv;return{[t.pageKey]:e}}))}(t);yield function(t,e){return d(this,null,(function*(){yield _e({opt:t,query:"page_pv",containers:[t.pvEl,"#ArtalkPV"],cache:e})}))}(t,e)}))}function _e(t){return d(this,null,(function*(){const{opt:e}=t;let s=t.cache||{};const n=function(t){const e=new Set;return new Set(t).forEach((t=>{document.querySelectorAll(t).forEach((t=>e.add(t)))})),e}(t.containers),i=function(t,e,s,n){const i=Array.from(t).map((t=>t.getAttribute(e)||s)).filter((t=>t&&"number"!=typeof n[t]));return[...new Set(i)]}(n,e.pageKeyAttr,e.pageKey,s);if(i.length>0){const n=(yield e.getApi().stats.getStats(t.query,{page_keys:i.join(","),site_name:e.siteName})).data.data;s=r(r({},s),n)}!function(t,e,s){t.forEach((t=>{const n=t.getAttribute("data-page-key"),i=n&&e[n]||s&&e[s]||0;t.innerText=`${Number(i)}`}))}(n,s,e.pageKey)}))}const We="ArtalkContent";class Ne{constructor(t){this.kit=t}reqAdd(){return d(this,null,(function*(){return(yield this.kit.useApi().comments.createComment(r({},yield this.getSubmitAddParams()))).data}))}getSubmitAddParams(){return d(this,null,(function*(){const{name:t,email:e,link:s}=this.kit.useUser().getData(),n=this.kit.useConf();return{content:this.kit.useEditor().getContentFinal(),name:t,email:e,link:s,rid:0,page_key:n.pageKey,page_title:n.pageTitle,site_name:n.site,ua:yield vt()}}))}postSubmitAdd(t){this.kit.useGlobalCtx().getData().insertComment(t)}}class He extends Yt{constructor(t){super(t),c(this,"customs",[]),c(this,"defaultPreset"),this.defaultPreset=new Ne(this.kit);const e=()=>this.do();this.kit.useMounted((()=>{this.kit.useGlobalCtx().on("editor-submit",e)})),this.kit.useUnmounted((()=>{this.kit.useGlobalCtx().off("editor-submit",e)}))}registerCustom(t){this.customs.push(t)}do(){return d(this,null,(function*(){if(""===this.kit.useEditor().getContentFinal().trim())return void this.kit.useEditor().focus();const t=this.customs.find((t=>t.activeCond()));this.kit.useEditor().showLoading();try{let e;(null==t?void 0:t.pre)&&t.pre(),e=(null==t?void 0:t.req)?yield t.req():yield this.defaultPreset.reqAdd(),(null==t?void 0:t.post)?t.post(e):this.defaultPreset.postSubmitAdd(e)}catch(e){return console.error(e),void this.kit.useEditor().showNotify(`${At("commentFail")}: ${e.message||String(e)}`,"e")}finally{this.kit.useEditor().hideLoading()}this.kit.useEditor().reset(),this.kit.useGlobalCtx().trigger("editor-submitted")}))}}class ze extends Yt{constructor(t){super(t),c(this,"emoticons",[]),c(this,"loadingTask",null),c(this,"$grpWrap"),c(this,"$grpSwitcher"),c(this,"isListLoaded",!1),c(this,"isImgLoaded",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-emoticons"></div>'),this.useBtn(`<i aria-label="${At("emoticon")}"><svg fill="currentColor" aria-hidden="true" height="14" viewBox="0 0 14 14" width="14"><path d="m4.26829 5.29294c0-.94317.45893-1.7074 1.02439-1.7074.56547 0 1.02439.76423 1.02439 1.7074s-.45892 1.7074-1.02439 1.7074c-.56546 0-1.02439-.76423-1.02439-1.7074zm4.43903 1.7074c.56546 0 1.02439-.76423 1.02439-1.7074s-.45893-1.7074-1.02439-1.7074c-.56547 0-1.02439.76423-1.02439 1.7074s.45892 1.7074 1.02439 1.7074zm-1.70732 2.73184c-1.51883 0-2.06312-1.52095-2.08361-1.58173l-1.29551.43231c.03414.10244.868 2.51604 3.3798 2.51604 2.51181 0 3.34502-2.41291 3.37982-2.51604l-1.29484-.43573c-.02254.06488-.56683 1.58583-2.08498 1.58583zm7-2.73252c0 3.86004-3.1401 7.00034-7 7.00034s-7-3.1396-7-6.99966c0-3.86009 3.1401-7.00034 7-7.00034s7 3.14025 7 7.00034zm-1.3659 0c0-3.10679-2.5275-5.63442-5.6341-5.63442-3.10663 0-5.63415 2.52832-5.63415 5.6351 0 3.10676 2.52752 5.63446 5.63415 5.63446 3.1066 0 5.6341-2.5277 5.6341-5.63446z"/></svg></i>`)})),this.kit.useUnmounted((()=>{})),this.useContentTransformer((t=>this.transEmoticonImageText(t))),this.usePanelShow((()=>{(()=>{d(this,null,(function*(){yield this.loadEmoticonsData(),this.isImgLoaded||(this.initEmoticonsList(),this.isImgLoaded=!0),setTimeout((()=>{this.changeListHeight()}),30)}))})()})),this.usePanelHide((()=>{this.$panel.parentElement.style.height=""})),window.setTimeout((()=>{this.loadEmoticonsData()}),1e3)}loadEmoticonsData(){return d(this,null,(function*(){this.isListLoaded||(null===this.loadingTask?(this.loadingTask=(()=>d(this,null,(function*(){Dt(this.$panel),this.emoticons=yield this.handleData(this.kit.useConf().emoticons),Rt(this.$panel),this.loadingTask=null,this.isListLoaded=!0})))(),yield this.loadingTask):yield this.loadingTask)}))}handleData(t){return d(this,null,(function*(){if(!Array.isArray(t)&&["object","string"].includes(typeof t)&&(t=[t]),!Array.isArray(t))return _t(this.$panel,`[${At("emoticon")}] Data must be of Array/Object/String type`),Rt(this.$panel),[];const e=e=>{"object"==typeof e&&(e.name&&t.find((t=>t.name===e.name))||t.push(e))},s=t=>d(this,null,(function*(){yield Promise.all(t.map(((t,n)=>d(this,null,(function*(){if("object"!=typeof t||Array.isArray(t)){if(Array.isArray(t))yield s(t);else if("string"==typeof t){const n=yield this.remoteLoad(t);Array.isArray(n)?yield s(n):"object"==typeof n&&e(n)}}else e(t)})))))}));return yield s(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 d(this,null,(function*(){if(!t)return[];try{const e=yield fetch(t);return yield e.json()}catch(e){return Rt(this.$panel),console.error("[Emoticons] Load Failed:",e),_t(this.$panel,`[${At("emoticon")}] ${At("loadFail")}: ${String(e)}`),[]}}))}solveNullKey(t){t.forEach((t=>{t.items.forEach(((e,s)=>{e.key||(e.key=`${t.name} ${s+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,s])=>{const n={name:t,type:s.type,items:[]};s.container.forEach(((e,s)=>{const i=e.icon;if(/<(img|IMG)/.test(i)){const t=/src=["'](.*?)["']/.exec(i);t&&t.length>1&&(e.icon=t[1])}n.items.push({key:e.text||`${t} ${s+1}`,val:e.icon})})),e.push(n)})),e}initEmoticonsList(){this.$grpWrap=pt('<div class="atk-grp-wrap"></div>'),this.$panel.append(this.$grpWrap),this.emoticons.forEach(((t,e)=>{const s=pt('<div class="atk-grp" style="display: none;"></div>');this.$grpWrap.append(s),s.setAttribute("data-index",String(e)),s.setAttribute("data-grp-name",t.name),s.setAttribute("data-type",t.type),t.items.forEach((e=>{const n=pt('<span class="atk-item"></span>');if(s.append(n),e.key&&!new RegExp(`^(${t.name})?\\s?[0-9]+$`).test(e.key)&&n.setAttribute("title",e.key),"image"===t.type){const t=document.createElement("img");t.src=e.val,t.alt=e.key,n.append(t)}else n.innerText=e.val;n.onclick=()=>{"image"===t.type?this.kit.useEditor().insertContent(`:[${e.key}]`):this.kit.useEditor().insertContent(e.val||"")}}))})),this.emoticons.length>1&&(this.$grpSwitcher=pt('<div class="atk-grp-switcher"></div>'),this.$panel.append(this.$grpSwitcher),this.emoticons.forEach(((t,e)=>{const s=pt("<span />");s.innerText=t.name,s.setAttribute("data-index",String(e)),s.onclick=()=>this.openGrp(e),this.$grpSwitcher.append(s)}))),this.emoticons.length>0&&this.openGrp(0)}openGrp(t){var e,s,n;Array.from(this.$grpWrap.children).forEach((e=>{const s=e;s.getAttribute("data-index")!==String(t)?s.style.display="none":s.style.display=""})),null==(e=this.$grpSwitcher)||e.querySelectorAll("span.active").forEach((t=>t.classList.remove("active"))),null==(n=null==(s=this.$grpSwitcher)?void 0:s.querySelector(`span[data-index="${t}"]`))||n.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,s])=>{t=t.split(`:[${s.key}]`).join(`<img src="${s.val}" atk-emoticon="${s.key}">`)}))})),t):t}}const Ve=["png","jpg","jpeg","gif","bmp","svg","webp"];class Ge extends Yt{constructor(t){super(t),c(this,"$imgUploadInput"),this.kit.useMounted((()=>this.init())),this.initDragImg()}init(){this.$imgUploadInput=document.createElement("input"),this.$imgUploadInput.type="file",this.$imgUploadInput.style.display="none",this.$imgUploadInput.accept=Ve.map((t=>`.${t}`)).join(",");const t=this.useBtn(`<i aria-label="${At("uploadImage")}"><svg fill="currentColor" aria-hidden="true" height="14" viewBox="0 0 14 14" width="14"><path d="m0 1.94444c0-1.074107.870333-1.94444 1.94444-1.94444h10.11116c1.0741 0 1.9444.870333 1.9444 1.94444v10.11116c0 1.0741-.8703 1.9444-1.9444 1.9444h-10.11116c-1.074107 0-1.94444-.8703-1.94444-1.9444zm1.94444-.38888c-.21466 0-.38888.17422-.38888.38888v7.06689l2.33333-2.33333 2.33333 2.33333 3.88888-3.88889 2.3333 2.33334v-5.51134c0-.21466-.1742-.38888-.3888-.38888zm10.49996 8.09977-2.3333-2.33333-3.88888 3.8889-2.33333-2.33334-2.33333 2.33334v.8447c0 .2146.17422.3888.38888.3888h10.11116c.2146 0 .3888-.1742.3888-.3888zm-7.1944-6.54422c-.75133 0-1.36111.60978-1.36111 1.36111 0 .75134.60978 1.36111 1.36111 1.36111s1.36111-.60977 1.36111-1.36111c0-.75133-.60978-1.36111-1.36111-1.36111z"/></svg></i>`);t.after(this.$imgUploadInput),t.onclick=()=>{const t=this.$imgUploadInput;t.onchange=()=>{(()=>{d(this,null,(function*(){if(!t.files||0===t.files.length)return;const e=t.files[0];this.uploadImg(e)}))})()},t.click()},this.kit.useConf().imgUpload||this.$btn.setAttribute("atk-only-admin-show","")}initDragImg(){const t=t=>{if(t)for(let e=0;e<t.length;e++){const s=t[e];this.uploadImg(s)}},e=t=>{t.stopPropagation(),t.preventDefault()},s=e=>{var s;const n=null==(s=e.dataTransfer)?void 0:s.files;(null==n?void 0:n.length)&&(e.preventDefault(),t(n))},n=e=>{var s;const n=null==(s=e.clipboardData)?void 0:s.files;(null==n?void 0:n.length)&&(e.preventDefault(),t(n))};this.kit.useMounted((()=>{this.kit.useUI().$textarea.addEventListener("dragover",e),this.kit.useUI().$textarea.addEventListener("drop",s),this.kit.useUI().$textarea.addEventListener("paste",n)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("dragover",e),this.kit.useUI().$textarea.removeEventListener("drop",s),this.kit.useUI().$textarea.removeEventListener("paste",n)}))}uploadImg(t){return d(this,null,(function*(){const e=/[^.]+$/.exec(t.name);if(!e||!Ve.includes(String(e[0]).toLowerCase()))return;if(!this.kit.useUser().checkHasBasicUserInfo())return void this.kit.useEditor().showNotify(At("uploadLoginMsg"),"w");let s="\n";""===this.kit.useUI().$textarea.value.trim()&&(s="");const n=`${s}`;let i;this.kit.useEditor().insertContent(n);try{const e=this.kit.useConf().imgUploader;i=e?{public_url:yield e(t)}:(yield this.kit.useApi().upload.upload({file:t})).data}catch(o){console.error(o),this.kit.useEditor().showNotify(`${At("uploadFail")}: ${o.message}`,"e")}if(i&&i.public_url){let t=i.public_url;$t(t)||(t=wt({base:this.kit.useConf().server,path:t})),this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(n,`${s}`))}else this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(n,""))}))}}class Ke extends Yt{constructor(t){super(t),c(this,"isPlugPanelShow",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-preview"></div>'),this.useBtn(`<i aria-label="${At("preview")}"><svg fill="currentColor" aria-hidden="true" viewBox="0 0 16 16" width="16" height="16"><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.kit.useUnmounted((()=>{})),this.kit.useEvents().on("content-updated",(t=>{this.isPlugPanelShow&&this.updateContent()})),this.usePanelShow((()=>{this.isPlugPanelShow=!0,this.updateContent()})),this.usePanelHide((()=>{this.isPlugPanelShow=!1}))}updateContent(){this.$panel.innerHTML=this.kit.useEditor().getContentMarked()}}const Qe=[class extends Yt{constructor(t){super(t);const e=()=>{this.save()};this.kit.useMounted((()=>{const t=window.localStorage.getItem(We)||"";""!==t.trim()&&(this.kit.useEditor().showNotify(At("restoredMsg"),"i"),this.kit.useEditor().setContent(t)),this.kit.useEvents().on("content-updated",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("content-updated",e)}))}save(){window.localStorage.setItem(We,this.kit.useEditor().getContentRaw().trim())}},class extends Yt{get $inputs(){return this.kit.useEditor().getHeaderInputEls()}constructor(t){super(t);const e={},s={},n=(t,e,s)=>()=>{this.kit.useEvents().trigger(t,{field:s,$input:e})};this.kit.useMounted((()=>{Object.entries(this.$inputs).forEach((([t,i])=>{i.addEventListener("input",e[t]=n("header-input",i,t)),i.addEventListener("change",s[t]=n("header-change",i,t))}))})),this.kit.useUnmounted((()=>{Object.entries(this.$inputs).forEach((([t,n])=>{n.removeEventListener("input",e[t]),n.removeEventListener("change",s[t])}))}))}},class extends Yt{constructor(t){super(t),c(this,"query",{timer:null,abortFn:null});const e=({$input:t,field:e})=>{"edit"!==this.kit.useEditor().getState()&&(this.kit.useUser().update({[e]:t.value.trim()}),"name"!==e&&"email"!==e||this.fetchUserInfo())},s={name:At("nick"),email:At("email"),link:At("link")};this.kit.useMounted((()=>{Object.entries(this.kit.useEditor().getHeaderInputEls()).forEach((([t,e])=>{e.placeholder=s[t],e.value=this.kit.useUser().getData()[t]||""})),this.kit.useEvents().on("header-input",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-input",e)}))}fetchUserInfo(){this.kit.useUser().logout(),this.query.timer&&window.clearTimeout(this.query.timer),this.query.abortFn&&this.query.abortFn(),this.query.timer=window.setTimeout((()=>{this.query.timer=null;const t=this.kit.useApi(),e="getUserCancelToken";this.query.abortFn=()=>t.abortRequest(e),t.user.getUser(r({},t.getUserFields()),{cancelToken:e}).then((t=>this.onUserInfoFetched(t.data))).catch((t=>{})).finally((()=>{this.query.abortFn=null}))}),400)}onUserInfoFetched(t){var e;t.is_login||this.kit.useUser().logout(),this.kit.useGlobalCtx().getData().updateNotifies(t.notifies),this.kit.useUser().checkHasBasicUserInfo()&&!t.is_login&&(null==(e=t.user)?void 0:e.is_admin)&&this.kit.useGlobalCtx().checkAdmin({onSuccess:()=>{}}),t.user&&t.user.link&&(this.kit.useUI().$link.value=t.user.link,this.kit.useUser().update({link:t.user.link}))}},class extends Yt{constructor(t){super(t);const e=({field:t})=>{"link"===t&&this.onLinkInputChange()};this.kit.useMounted((()=>{this.kit.useEvents().on("header-change",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-change",e)}))}onLinkInputChange(){const t=this.kit.useUI().$link.value.trim();t&&!/^(http|https):\/\//.test(t)&&(this.kit.useUI().$link.value=`https://${t}`,this.kit.useUser().update({link:this.kit.useUI().$link.value}))}},class extends Yt{constructor(t){super(t);const e=t=>this.onKeydown(t),s=()=>this.onInput();this.kit.useMounted((()=>{this.kit.useUI().$textarea.placeholder=this.kit.useConf().placeholder||At("placeholder"),this.kit.useUI().$textarea.addEventListener("keydown",e),this.kit.useUI().$textarea.addEventListener("input",s)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("keydown",e),this.kit.useUI().$textarea.removeEventListener("input",s)})),this.kit.useEvents().on("content-updated",(()=>{window.setTimeout((()=>{this.adaptiveHeightByContent()}),80)}))}onKeydown(t){9===(t.keyCode||t.which)&&(t.preventDefault(),this.kit.useEditor().insertContent("\t"))}onInput(){this.kit.useEvents().trigger("content-updated",this.kit.useEditor().getContentRaw())}adaptiveHeightByContent(){const t=this.kit.useUI().$textarea.offsetHeight-this.kit.useUI().$textarea.clientHeight;this.kit.useUI().$textarea.style.height="0px",this.kit.useUI().$textarea.style.height=`${this.kit.useUI().$textarea.scrollHeight+t}px`}},He,class extends Yt{constructor(t){super(t);const e=()=>{this.kit.useEditor().submit()};this.kit.useMounted((()=>{this.kit.useUI().$submitBtn.innerText=this.kit.useConf().sendBtn||At("send"),this.kit.useUI().$submitBtn.addEventListener("click",e)})),this.kit.useUnmounted((()=>{this.kit.useUI().$submitBtn.removeEventListener("click",e)}))}},Jt,class extends Yt{constructor(t){super(t),c(this,"comment"),this.useEditorStateEffect("reply",(t=>(this.setReply(t),()=>{this.cancelReply()}))),this.kit.useEvents().on("mounted",(()=>{const t=this.kit.useDeps(He);if(!t)throw Error("SubmitPlug not initialized");const e=new Ne(this.kit);t.registerCustom({activeCond:()=>!!this.comment,req:()=>d(this,null,(function*(){if(!this.comment)throw new Error("reply comment cannot be empty");return(yield this.kit.useApi().comments.createComment(l(r({},yield e.getSubmitAddParams()),{rid:this.comment.id,page_key:this.comment.page_key,page_title:void 0,site_name:this.comment.site_name}))).data})),post:t=>{const s=this.kit.useConf();t.page_key!==s.pageKey&&window.open(`${t.page_url}#atk-comment-${t.id}`),e.postSubmitAdd(t)}})}))}setReply(t){const e=this.kit.useUI();if(!e.$sendReplyBtn){const s=pt(`<span class="atk-state-btn"><span class="atk-text-wrap">${At("reply")} <span class="atk-text"></span></span><span class="atk-cancel atk-icon-close atk-icon"></span></span>`);s.querySelector(".atk-text").innerText=`@${t.nick}`,s.addEventListener("click",(()=>{this.kit.useEditor().resetState()})),e.$stateWrap.append(s),e.$sendReplyBtn=s}this.comment=t,e.$textarea.focus()}cancelReply(){if(!this.comment)return;const t=this.kit.useUI();t.$sendReplyBtn&&(t.$sendReplyBtn.remove(),t.$sendReplyBtn=void 0),this.comment=void 0}},class extends Yt{constructor(t){super(t),c(this,"comment"),c(this,"originalSubmitBtnText","Send"),this.useEditorStateEffect("edit",(t=>(this.edit(t),()=>{this.cancelEdit()}))),this.kit.useMounted((()=>{const t=this.kit.useDeps(He);if(!t)throw Error("SubmitPlug not initialized");t.registerCustom({activeCond:()=>!!this.comment,req:()=>d(this,null,(function*(){const t={content:this.kit.useEditor().getContentFinal(),nick:this.kit.useUI().$name.value,email:this.kit.useUI().$email.value,link:this.kit.useUI().$link.value},e=this.comment;return(yield this.kit.useApi().comments.updateComment(e.id,r(r({},e),t))).data})),post:t=>{this.kit.useGlobalCtx().getData().updateComment(t)}})}))}edit(t){const e=this.kit.useUI();if(!e.$editCancelBtn){const t=pt(`<span class="atk-state-btn"><span class="atk-text-wrap">${At("editCancel")}</span><span class="atk-cancel atk-icon-close atk-icon"></span></span>`);t.onclick=()=>{this.kit.useEditor().resetState()},e.$stateWrap.append(t),e.$editCancelBtn=t}this.comment=t,e.$header.style.display="none",e.$name.value=t.nick||"",e.$email.value=t.email||"",e.$link.value=t.link||"",this.kit.useEditor().setContent(t.content),e.$textarea.focus(),this.updateSubmitBtnText(At("save"))}cancelEdit(){if(!this.comment)return;const t=this.kit.useUI();t.$editCancelBtn&&(t.$editCancelBtn.remove(),t.$editCancelBtn=void 0),this.comment=void 0;const{name:e,email:s,link:n}=this.kit.useUser().getData();t.$name.value=e,t.$email.value=s,t.$link.value=n,this.kit.useEditor().setContent(""),this.restoreSubmitBtnText(),t.$header.style.display=""}updateSubmitBtnText(t){this.originalSubmitBtnText=this.kit.useUI().$submitBtn.innerText,this.kit.useUI().$submitBtn.innerText=t}restoreSubmitBtnText(){this.kit.useUI().$submitBtn.innerText=this.originalSubmitBtnText}},class extends Yt{constructor(t){super(t);const e=()=>this.open(),s=()=>this.close();this.kit.useMounted((()=>{this.kit.useEvents().on("editor-open",e),this.kit.useEvents().on("editor-close",s)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("editor-open",e),this.kit.useEvents().off("editor-close",s)}))}open(){var t;null==(t=this.kit.useUI().$textareaWrap.querySelector(".atk-comment-closed"))||t.remove(),this.kit.useUI().$textarea.style.display="",this.kit.useUI().$bottom.style.display=""}close(){this.kit.useUI().$textareaWrap.querySelector(".atk-comment-closed")||this.kit.useUI().$textareaWrap.prepend(pt(`<div class="atk-comment-closed">${At("onlyAdminCanReply")}</div>`)),this.kit.useUser().getData().is_admin?(this.kit.useUI().$textarea.style.display="",this.kit.useUI().$bottom.style.display=""):(this.kit.useUI().$textarea.style.display="none",this.kit.useEvents().trigger("panel-close"),this.kit.useUI().$bottom.style.display="none")}},ze,Ge,Ke];class Ye{constructor(t){this.plugs=t}useEditor(){return this.plugs.editor}useGlobalCtx(){return this.plugs.editor.ctx}useConf(){return this.plugs.editor.ctx.conf}useApi(){return this.plugs.editor.ctx.getApi()}useUser(){return this.plugs.editor.ctx.get("user")}useUI(){return this.plugs.editor.getUI()}useEvents(){return this.plugs.getEvents()}useMounted(t){this.useEvents().on("mounted",t)}useUnmounted(t){this.useEvents().on("unmounted",t)}useDeps(t){return this.plugs.get(t)}}class Je{constructor(t){c(this,"plugs",[]),c(this,"openedPlug",null),c(this,"events",new Mt),this.editor=t;let e=!1;this.editor.ctx.watchConf(["imgUpload","emoticons","preview","editorTravel","locale"],(t=>{e&&this.getEvents().trigger("unmounted"),this.clear(),function(t){const e=new Map;return e.set(Ge,t.imgUpload),e.set(ze,t.emoticons),e.set(Ke,t.preview),e.set(Jt,t.editorTravel),Qe.filter((t=>!e.has(t)||!!e.get(t)))}(t).forEach((t=>{const e=new Ye(this);this.plugs.push(new t(e))})),this.getEvents().trigger("mounted"),e=!0,this.loadPluginUI()})),this.events.on("panel-close",(()=>this.closePlugPanel()))}getPlugs(){return this.plugs}getEvents(){return this.events}clear(){this.plugs=[],this.events=new Mt,this.openedPlug&&this.closePlugPanel()}loadPluginUI(){this.editor.getUI().$plugPanelWrap.innerHTML="",this.editor.getUI().$plugPanelWrap.style.display="none",this.editor.getUI().$plugBtnWrap.innerHTML="",this.plugs.forEach((t=>this.loadPluginItem(t)))}loadPluginItem(t){const e=t.$btn;if(!e)return;this.editor.getUI().$plugBtnWrap.appendChild(e),!e.onclick&&(e.onclick=()=>{this.editor.getUI().$plugBtnWrap.querySelectorAll(".active").forEach((t=>t.classList.remove("active"))),t!==this.openedPlug?(this.openPlugPanel(t),e.classList.add("active")):this.closePlugPanel()});const s=t.$panel;s&&(s.style.display="none",this.editor.getUI().$plugPanelWrap.appendChild(s))}get(t){return this.plugs.find((e=>e instanceof t))}openPlugPanel(t){this.plugs.forEach((e=>{const s=e.$panel;s&&(e===t?(s.style.display="",this.events.trigger("panel-show",t)):(s.style.display="none",this.events.trigger("panel-hide",t)))})),this.editor.getUI().$plugPanelWrap.style.display="",this.openedPlug=t}closePlugPanel(){this.openedPlug&&(this.editor.getUI().$plugPanelWrap.style.display="none",this.events.trigger("panel-hide",this.openedPlug),this.openedPlug=null)}getTransformedContent(t){let e=t;return this.plugs.forEach((t=>{t.contentTransformer&&(e=t.contentTransformer(e))})),e}}const Xe="2.9.0";function Ze(t){const e=pt('<span><span class="error-message"></span><br/><br/></span>');if(e.querySelector(".error-message").innerText=`${At("listLoadFailMsg")}\n${t.errMsg}`,t.retryFn){const s=pt(`<span style="cursor:pointer;">${At("listRetry")}</span>`);s.onclick=()=>t.retryFn&&t.retryFn(),e.appendChild(s)}if(t.onOpenSidebar){const s=pt(`<span atk-only-admin-show> | <span style="cursor:pointer;">${At("openName",{name:At("ctrlCenter")})}</span></span>`);e.appendChild(s),s.onclick=()=>t.onOpenSidebar&&t.onOpenSidebar()}_t(t.$err,e)}let ts=!1;let es;function ss(t,e){const s="atk-dark-mode";t.forEach((t=>{e?t.classList.add(s):t.classList.remove(s)}))}const ns=[t=>{t.watchConf(["imgLazyLoad","markedOptions"],(e=>{!function(t){try{if(!h.Marked.name)return}catch(s){return}const e=new h.Marked;e.setOptions(r(r({renderer:st({imgLazyLoad:t.imgLazyLoad})},lt),t.markedOptions)),at=e}({markedOptions:t.getConf().markedOptions,imgLazyLoad:t.getConf().imgLazyLoad})})),t.watchConf(["markedReplacers"],(t=>{var e;t.markedReplacers&&(e=t.markedReplacers,rt=e)}))},t=>{const e=t.get("editor"),s=new Je(e);t.inject("editorPlugs",s)},t=>{const e=()=>{var e;e=t.get("user").getData().is_admin,function(t){const e=[];t.$root.querySelectorAll("[atk-only-admin-show]").forEach((t=>e.push(t)));const s=document.querySelector(".atk-sidebar");return s&&s.querySelectorAll("[atk-only-admin-show]").forEach((t=>e.push(t))),e}({$root:t.$root}).forEach((t=>{e?t.classList.remove("atk-hide"):t.classList.add("atk-hide")}))};t.on("list-loaded",(()=>{e()})),t.on("user-changed",(t=>{e()}))},...[t=>{t.on("list-fetch",(e=>{if(t.getData().getLoading())return;t.getData().setLoading(!0);const s=r({offset:0,limit:t.conf.pagination.pageSize,flatMode:t.conf.flatMode,paramsModifier:t.conf.listFetchParamsModifier},e);t.getData().setListLastFetch({params:s});const n={limit:s.limit,offset:s.offset,flat_mode:s.flatMode,page_key:t.getConf().pageKey,site_name:t.getConf().site};s.paramsModifier&&s.paramsModifier(n),t.getApi().comments.getComments(r(r({},n),t.getApi().getUserFields())).then((({data:e})=>{t.getData().setListLastFetch({params:s,data:e}),t.getData().loadComments(e.comments),t.getData().updatePage(e.page),s.onSuccess&&s.onSuccess(e),t.trigger("list-fetched",{params:s,data:e})})).catch((e=>{const n={msg:e.msg||String(e),data:e.data};throw s.onError&&s.onError(n),t.trigger("list-failed",n),t.trigger("list-fetched",{params:s,error:n}),e})).finally((()=>{t.getData().setLoading(!1)}))}))},t=>{t.on("list-fetch",(e=>{const s=t.get("list");0===e.offset&&Bt(!0,s.$el)})),t.on("list-fetched",(()=>{Bt(!1,t.get("list").$el)}))},t=>{t.on("comment-rendered",(e=>{if(!0===t.conf.listUnreadHighlight){const s=t.getData().getNotifies(),n=s.find((t=>t.comment_id===e.getID()));n?(e.getRender().setUnread(!0),e.getRender().setOpenAction((()=>{window.open(n.read_link),t.getData().updateNotifies(s.filter((t=>t.comment_id!==e.getID())))}))):e.getRender().setUnread(!1)}})),t.on("list-goto",(e=>{const s=gt("atk_notify_key");s&&t.getApi().notifies.markNotifyRead(e,s).then((()=>{t.getData().updateNotifies(t.getData().getNotifies().filter((t=>t.comment_id!==e)))}))}))},t=>{let e;t.on("mounted",(()=>{const s=t.get("list");e=s.$el.querySelector('[data-action="admin-close-comment"]'),e.addEventListener("click",(()=>{const e=t.getData().getPage();if(!e)throw new Error("Page data not found");e.admin_only=!e.admin_only,function(t,e){t.editorShowLoading(),t.getApi().pages.updatePage(e.id,e).then((({data:e})=>{t.getData().updatePage(e)})).catch((e=>{t.editorShowNotify(`${At("editFail")}: ${e.message||String(e)}`,"e")})).finally((()=>{t.editorHideLoading()}))}(t,e)}))})),t.on("page-loaded",(s=>{var n,i;const o=t.get("editor");!0===(null==s?void 0:s.admin_only)?(null==(n=o.getPlugs())||n.getEvents().trigger("editor-close"),e&&(e.innerText=At("openComment"))):(null==(i=o.getPlugs())||i.getEvents().trigger("editor-open"),e&&(e.innerText=At("closeComment")))})),t.on("list-loaded",(e=>{t.editorResetState()}))},t=>{t.on("list-loaded",(()=>{(()=>{var e,s;const n=t.get("list").$el.querySelector(".atk-comment-count .atk-text");if(!n)return;const i=mt(At("counter",{count:`${Number(null==(s=null==(e=t.getData().getListLastFetch())?void 0:e.data)?void 0:s.count)||0}`}));n.innerHTML=i.replace(/(\d+)/,'<span class="atk-comment-count-num">$1</span>')})()})),t.on("comment-inserted",(()=>{const e=t.getData().getListLastFetch();(null==e?void 0:e.data)&&(e.data.count+=1)})),t.on("comment-deleted",(()=>{const e=t.getData().getListLastFetch();(null==e?void 0:e.data)&&(e.data.count-=1)}))},t=>{let e=null;const s=()=>{if(!e)return;const s=t.get("user").getData();if(s.name&&s.email){e.classList.remove("atk-hide");const t=e.querySelector(".atk-text");t&&(t.innerText=s.is_admin?At("ctrlCenter"):At("msgCenter"))}else e.classList.add("atk-hide")};t.watchConf(["locale"],(n=>{const i=t.get("list");e=i.$el.querySelector('[data-action="open-sidebar"]'),e&&(e.onclick=()=>{t.showSidebar()},s())})),t.on("user-changed",(t=>{s()}))},t=>{let e=null;t.on("mounted",(()=>{const s=t.get("list");e=s.$el.querySelector(".atk-unread-badge")})),t.on("notifies-updated",(t=>{var s;s=t.length||0,e&&(s>0?(e.innerText=`${Number(s||0)}`,e.style.display="block"):e.style.display="none")}))},t=>{const e=e=>{t.conf.listFetchParamsModifier=e,t.reload()},s=t=>{!function(t){const{$dropdownWrap:e,dropdownList:s}=t;if(e.querySelector(".atk-dropdown"))return;e.classList.add("atk-dropdown-wrap"),e.append(pt('<span class="atk-arrow-down-icon"></span>'));let n=0;const i=(t,e,s,i)=>{i(),n=t,o.querySelectorAll(".active").forEach((t=>{t.classList.remove("active")})),e.classList.add("active"),o.style.display="none",setTimeout((()=>{o.style.display=""}),80)},o=pt('<ul class="atk-dropdown atk-fade-in"></ul>');s.forEach(((t,e)=>{const[s,a]=t,r=pt('<li class="atk-dropdown-item"><span></span></li>'),l=r.querySelector("span");l.innerText=s,l.onclick=()=>{i(e,r,s,a)},o.append(r),e===n&&r.classList.add("active")})),e.append(o)}({$dropdownWrap:t,dropdownList:[[At("sortLatest"),()=>{e((t=>{t.sort_by="date_desc"}))}],[At("sortBest"),()=>{e((t=>{t.sort_by="vote"}))}],[At("sortOldest"),()=>{e((t=>{t.sort_by="date_asc"}))}],[At("sortAuthor"),()=>{e((t=>{t.view_only_admin=!0}))}]]})};t.watchConf(["listSort","locale"],(e=>{const n=t.get("list").$el.querySelector(".atk-comment-count");n&&(e.listSort?s(n):function(t){var e,s;const{$dropdownWrap:n}=t;n.classList.remove("atk-dropdown-wrap"),null==(e=n.querySelector(".atk-arrow-down-icon"))||e.remove(),null==(s=n.querySelector(".atk-dropdown"))||s.remove()}({$dropdownWrap:n}))}))},t=>{let e=0;const s=({locker:s})=>{const n=function(){const t=window.location.hash.match(/#atk-comment-([0-9]+)/);let e=t&&t[1]&&!Number.isNaN(parseFloat(t[1]))?parseFloat(t[1]):null;e||(e=Number(gt("atk_comment")));return e||null}();n&&(s&&e===n||(e=n,t.trigger("list-goto",n)))},n=()=>s({locker:!1}),i=()=>s({locker:!0});t.on("mounted",(()=>{window.addEventListener("hashchange",n),t.on("list-loaded",i)})),t.on("unmounted",(()=>{window.removeEventListener("hashchange",n),t.off("list-loaded",i)}))},t=>{t.on("list-goto",(e=>d(exports,null,(function*(){let s=t.getCommentNodes().find((t=>t.getID()===e));if(!s){const n=(yield t.getApi().comments.getComment(e)).data;t.get("list").getListLayout({forceFlatMode:!0}).insert(n.comment,n.reply_comment),s=t.getCommentNodes().find((t=>t.getID()===e))}s&&s.focus()}))))},t=>{t.on("list-loaded",(e=>{const s=t.get("list"),n=e.length<=0;let i=s.getCommentsWrapEl().querySelector(".atk-list-no-comment");n?i||(i=pt('<div class="atk-list-no-comment"></div>'),i.innerHTML=X(s.ctx.conf.noComment||s.ctx.$t("noComment")),s.getCommentsWrapEl().appendChild(i)):null==i||i.remove()}))},t=>{t.on("mounted",(()=>{const e=t.get("list").$el.querySelector(".atk-copyright");e&&(e.innerHTML=`Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${Xe}">Artalk</a>`)}))},t=>{let e=null;t.on("mounted",(()=>{e=window.setInterval((()=>{t.get("list").$el.querySelectorAll("[data-atk-comment-date]").forEach((e=>{var s,n;const i=new Date(Number(e.getAttribute("data-atk-comment-date")));e.innerText=(null==(n=(s=t.getConf()).dateFormatter)?void 0:n.call(s,i))||kt(i,t.$t)}))}),3e4)})),t.on("unmounted",(()=>{e&&window.clearInterval(e)}))},t=>{t.on("list-fetch",(()=>{_t(t.get("list").$el,null)})),t.on("list-failed",(e=>{Ze({$err:t.get("list").$el,errMsg:e.msg,errData:e.data,retryFn:()=>t.fetch({offset:0})})}))},t=>{let e=null;const s=()=>{null==e||e.disconnect(),e=null};t.on("list-loaded",(()=>{s();const n=t.get("list").getCommentsWrapEl().childNodes,i=n.length>2?n[n.length-2]:null;i&&("IntersectionObserver"in window?(n=>{const i=t.conf.scrollRelativeTo&&t.conf.scrollRelativeTo()||null;e=new IntersectionObserver((([e])=>{e.isIntersecting&&(s(),t.trigger("list-reach-bottom"))}),{threshold:.9,root:i}),e.observe(n)})(i):console.warn("IntersectionObserver api not supported"))})),t.on("unmounted",(()=>{s()}))},t=>{const e=()=>{const e=t.get("list"),s=t.conf.scrollRelativeTo&&t.conf.scrollRelativeTo();(s||window).scroll({top:ft(e.$el,s).top,left:0})};t.on("mounted",(()=>{t.on("list-goto-first",e)})),t.on("unmounted",(()=>{t.off("list-goto-first",e)}))}],t=>{t.on("list-fetch",(e=>{if(0!==e.offset)return;const s=t.getApi().getUserFields();s&&t.getApi().notifies.getNotifies(s).then((e=>{t.getData().updateNotifies(e.data.notifies)}))}))},t=>{t.watchConf(["site","pageKey","pageTitle","countEl","pvEl","statPageKeyAttr"],(e=>{Fe({getApi:()=>t.getApi(),siteName:e.site,pageKey:e.pageKey,pageTitle:e.pageTitle,countEl:e.countEl,pvEl:e.pvEl,pageKeyAttr:e.statPageKeyAttr,pvAdd:"boolean"!=typeof t.conf.pvAdd||t.conf.pvAdd})}))},t=>{t.watchConf(["apiVersion","versionCheck"],(e=>{const s=t.get("list");e.apiVersion&&e.versionCheck&&!ts&&function(t,e,s){const n=function(t,e){const s=t.split("."),n=e.split(".");for(let i=0;i<3;i++){const t=Number(s[i]),e=Number(n[i]);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,s);if(0===n)return;const i=pt(`<div class="atk-version-check-notice">${At("updateMsg",{name:At(n<0?"frontend":"backend")})} <span class="atk-info">${At("currentVersion")}: ${At("frontend")} ${e} / ${At("backend")} ${s}</span></div>`),o=pt(`<span class="atk-ignore-btn">${At("ignore")}</span>`);o.onclick=()=>{i.remove(),ts=!0},i.append(o),t.$el.parentElement.prepend(i)}(s,Xe,e.apiVersion)}))},t=>{let e;const s=s=>{const n=[t.$root,t.get("layerManager").getEl()];es||(es=window.matchMedia("(prefers-color-scheme: dark)")),"auto"===s?(e||(e=t=>ss(n,t.matches),es.addEventListener("change",e)),ss(n,es.matches)):(e&&(es.removeEventListener("change",e),e=void 0),ss(n,s))};t.watchConf(["darkMode"],(t=>s(t.darkMode))),t.on("created",(()=>s(t.conf.darkMode))),t.on("unmounted",(()=>{e&&(null==es||es.removeEventListener("change",e)),e=void 0}))}],is=new Set([...ns]),os=new WeakMap;function as(t){return d(this,null,(function*(){var e;const s=new Set,n=e=>{e.forEach((e=>{"function"!=typeof e||s.has(e)||(e(t,os.get(e)),s.add(e))}))};n(is);const{data:i}=yield t.getApi().conf.conf().catch((e=>{throw function(t,e){var s;let n="";if(null==(s=e.data)?void 0:s.err_no_site){const e={create_name:t.conf.site,create_urls:`${window.location.protocol}//${window.location.host}`};n=`sites|${JSON.stringify(e)}`}Ze({$err:t.get("list").$el,errMsg:e.msg||String(e),errData:e.data,retryFn:()=>as(t),onOpenSidebar:t.get("user").getData().is_admin?()=>t.showSidebar({view:n}):void 0})}(t,e),e}));let o={apiVersion:null==(e=i.version)?void 0:e.version};if(t.conf.useBackendConf){if(!i.frontend_conf)throw new Error("The remote backend does not respond to the frontend conf, but `useBackendConf` conf is enabled");o=r(r({},o),function(t){const e=["el","pageKey","pageTitle","server","site","pvEl","countEl","statPageKeyAttr"];return Object.keys(t).forEach((s=>{e.includes(s)&&delete t[s],"darkMode"===s&&"auto"!==t[s]&&delete t[s]})),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}(i.frontend_conf))}t.conf.remoteConfModifier&&t.conf.remoteConfModifier(o),o.pluginURLs&&(yield function(t,e){return d(this,null,(function*(){const s=new Set;if(!t||!Array.isArray(t))return s;const n=[];return t.forEach((t=>{/^(http|https):\/\//.test(t)||(t=`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`),n.push(new Promise(((e,s)=>{if(document.querySelector(`script[src="${t}"]`))return void e();const n=document.createElement("script");n.src=t,document.head.appendChild(n),n.onload=()=>e(),n.onerror=t=>s(t)})))})),yield Promise.all(n),Object.values(window.ArtalkPlugins||{}).forEach((t=>{"function"==typeof t&&s.add(t)})),s}))}(o.pluginURLs,t.conf.server).then((t=>{n(t)})).catch((t=>{console.error("Failed to load plugin",t)}))),t.trigger("created"),t.updateConf(o),t.trigger("mounted"),t.conf.remoteConfModifier||t.fetch({offset:0})}))}class rs{constructor(t){c(this,"ctx");const e=Ut(t,!0);this.ctx=new qt(e),Object.entries(je).forEach((([t,e])=>{const s=e(this.ctx);s&&this.ctx.inject(t,s)})),as(this.ctx)}getConf(){return this.ctx.getConf()}getEl(){return this.ctx.$root}update(t){return this.ctx.updateConf(t),this}reload(){this.ctx.reload()}destroy(){for(this.ctx.trigger("unmounted");this.ctx.$root.firstChild;)this.ctx.$root.removeChild(this.ctx.$root.firstChild)}on(t,e){this.ctx.on(t,e)}off(t,e){this.ctx.off(t,e)}trigger(t,e){this.ctx.trigger(t,e)}setDarkMode(t){this.ctx.setDarkMode(t)}static init(t){return new rs(t)}static use(t,e){is.add(t),os.set(t,e)}static loadCountWidget(t){const e=Ut(t,!0);Fe({getApi:()=>new f(It(e)),siteName:e.site,countEl:e.countEl,pvEl:e.pvEl,pageKeyAttr:e.statPageKeyAttr,pvAdd:!1})}get $root(){return this.ctx.$root}get conf(){return this.ctx.getConf()}}const ls=rs.init,cs=rs.use,ds=rs.loadCountWidget;exports.default=rs,exports.init=ls,exports.loadCountWidget=ds,exports.use=cs;
|
|
10
|
+
*/let p=class extends u{constructor(){super(...arguments),c(this,"auth",{loginByEmail:(t,e={})=>this.request(r({path:"/auth/email/login",method:"POST",body:t,type:"application/json",format:"json"},e)),registerByEmail:(t,e={})=>this.request(r({path:"/auth/email/register",method:"POST",body:t,type:"application/json",format:"json"},e)),sendVerifyEmail:(t,e={})=>this.request(r({path:"/auth/email/send",method:"POST",body:t,type:"application/json",format:"json"},e)),checkDataMerge:(t={})=>this.request(r({path:"/auth/merge",method:"GET",secure:!0,format:"json"},t)),applyDataMerge:(t,e={})=>this.request(r({path:"/auth/merge",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e))}),c(this,"cache",{flushCache:(t={})=>this.request(r({path:"/cache/flush",method:"POST",secure:!0,format:"json"},t)),warmUpCache:(t={})=>this.request(r({path:"/cache/warm_up",method:"POST",secure:!0,format:"json"},t))}),c(this,"captcha",{getCaptcha:(t={})=>this.request(r({path:"/captcha",method:"GET",format:"json"},t)),getCaptchaStatus:(t={})=>this.request(r({path:"/captcha/status",method:"GET",format:"json"},t)),verifyCaptcha:(t,e={})=>this.request(r({path:"/captcha/verify",method:"POST",body:t,type:"application/json",format:"json"},e))}),c(this,"comments",{getComments:(t,e={})=>this.request(r({path:"/comments",method:"GET",query:t,secure:!0,type:"application/json",format:"json"},e)),createComment:(t,e={})=>this.request(r({path:"/comments",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),getComment:(t,e={})=>this.request(r({path:`/comments/${t}`,method:"GET",type:"application/json",format:"json"},e)),updateComment:(t,e,s={})=>this.request(r({path:`/comments/${t}`,method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},s)),deleteComment:(t,e={})=>this.request(r({path:`/comments/${t}`,method:"DELETE",secure:!0,format:"json"},e))}),c(this,"conf",{conf:(t={})=>this.request(r({path:"/conf",method:"GET",format:"json"},t)),getSocialLoginProviders:(t={})=>this.request(r({path:"/conf/auth/providers",method:"GET",format:"json"},t)),getDomain:(t,e={})=>this.request(r({path:"/conf/domain",method:"GET",query:t,format:"json"},e))}),c(this,"notifies",{getNotifies:(t,e={})=>this.request(r({path:"/notifies",method:"GET",query:t,type:"application/json",format:"json"},e)),markAllNotifyRead:(t,e={})=>this.request(r({path:"/notifies/read",method:"POST",body:t,type:"application/json",format:"json"},e)),markNotifyRead:(t,e,s={})=>this.request(r({path:`/notifies/${t}/${e}`,method:"POST",format:"json"},s))}),c(this,"pages",{getPages:(t,e={})=>this.request(r({path:"/pages",method:"GET",query:t,secure:!0,type:"application/json",format:"json"},e)),fetchAllPages:(t,e={})=>this.request(r({path:"/pages/fetch",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),getPageFetchStatus:(t={})=>this.request(r({path:"/pages/fetch/status",method:"GET",secure:!0,format:"json"},t)),logPv:(t,e={})=>this.request(r({path:"/pages/pv",method:"POST",body:t,type:"application/json",format:"json"},e)),updatePage:(t,e,s={})=>this.request(r({path:`/pages/${t}`,method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},s)),deletePage:(t,e={})=>this.request(r({path:`/pages/${t}`,method:"DELETE",secure:!0,format:"json"},e)),fetchPage:(t,e={})=>this.request(r({path:`/pages/${t}/fetch`,method:"POST",secure:!0,type:"application/json",format:"json"},e))}),c(this,"sendEmail",{sendEmail:(t,e={})=>this.request(r({path:"/send_email",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e))}),c(this,"settings",{getSettings:(t={})=>this.request(r({path:"/settings",method:"GET",secure:!0,format:"json"},t)),applySettings:(t,e={})=>this.request(r({path:"/settings",method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},e)),getSettingsTemplate:(t,e={})=>this.request(r({path:`/settings/template/${t}`,method:"GET",secure:!0,format:"json"},e))}),c(this,"sites",{getSites:(t={})=>this.request(r({path:"/sites",method:"GET",secure:!0,format:"json"},t)),createSite:(t,e={})=>this.request(r({path:"/sites",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),updateSite:(t,e,s={})=>this.request(r({path:`/sites/${t}`,method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},s)),deleteSite:(t,e={})=>this.request(r({path:`/sites/${t}`,method:"DELETE",secure:!0,format:"json"},e))}),c(this,"stats",{getStats:(t,e,s={})=>this.request(r({path:`/stats/${t}`,method:"GET",query:e,type:"application/json",format:"json"},s))}),c(this,"transfer",{exportArtrans:(t={})=>this.request(r({path:"/transfer/export",method:"GET",secure:!0,format:"json"},t)),importArtrans:(t,e={})=>this.request(r({path:"/transfer/import",method:"POST",body:t,secure:!0,type:"application/json"},e)),uploadArtrans:(t,e={})=>this.request(r({path:"/transfer/upload",method:"POST",body:t,secure:!0,type:"multipart/form-data",format:"json"},e))}),c(this,"upload",{upload:(t,e={})=>this.request(r({path:"/upload",method:"POST",body:t,secure:!0,type:"multipart/form-data",format:"json"},e))}),c(this,"user",{getUser:(t,e={})=>this.request(r({path:"/user",method:"GET",query:t,secure:!0,format:"json"},e)),updateProfile:(t,e={})=>this.request(r({path:"/user",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),login:(t,e={})=>this.request(r({path:"/user/access_token",method:"POST",body:t,type:"application/json",format:"json"},e)),getUserStatus:(t,e={})=>this.request(r({path:"/user/status",method:"GET",query:t,secure:!0,format:"json"},e))}),c(this,"users",{createUser:(t,e={})=>this.request(r({path:"/users",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),updateUser:(t,e,s={})=>this.request(r({path:`/users/${t}`,method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},s)),deleteUser:(t,e={})=>this.request(r({path:`/users/${t}`,method:"DELETE",secure:!0,format:"json"},e)),getUsers:(t,e,s={})=>this.request(r({path:`/users/${t}`,method:"GET",query:e,secure:!0,type:"application/json",format:"json"},s))}),c(this,"version",{getVersion:(t={})=>this.request(r({path:"/version",method:"GET",format:"json"},t))}),c(this,"votes",{syncVotes:(t={})=>this.request(r({path:"/votes/sync",method:"POST",secure:!0,format:"json"},t)),vote:(t,e,s,n={})=>this.request(r({path:`/votes/${t}/${e}`,method:"POST",body:s,type:"application/json",format:"json"},n))})}};const m=(t,e,s)=>d(exports,null,(function*(){const n=t.getApiToken&&t.getApiToken(),i=new Headers(r({Authorization:n?`Bearer ${n}`:""},null==s?void 0:s.headers));i.get("Authorization")||i.delete("Authorization");const o=yield fetch(e,l(r({},s),{headers:i}));if(!o.ok){const n=(yield o.json().catch((()=>{})))||{};let i=!1;if(t.handlers&&(yield t.handlers.get().reduce(((t,e)=>d(exports,null,(function*(){yield t,!0===n[e.action]&&(yield e.handler(n),i=!0)}))),Promise.resolve())),i)return m(t,e,s);throw function(t,e){const s=new g;return s.message=e.msg||e.message||"fetch error",s.code=t,s.data=e,console.error(s),s}(o.status,n)}return o}));class g extends Error{constructor(){super(...arguments),c(this,"code",0),c(this,"message","fetch error"),c(this,"data")}}class f extends p{constructor(t){super({baseUrl:t.baseURL,customFetch:(e,s)=>m(t,e,s)}),c(this,"_opts"),this._opts=t}getUserFields(){const t=this._opts.userInfo;if((null==t?void 0:t.name)&&(null==t?void 0:t.email))return{name:t.name,email:t.email}}}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function y(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var k={"&":"&","<":"<",">":">",'"':""","'":"'"},v={"&":"&","<":"<",">":">",""":'"',"'":"'"},$=/(&|<|>|"|')/g,w=/[&<>"']/g;function b(t){return k[t]}function C(t){return v[t]}function x(t){return null==t?"":String(t).replace(w,b)}function E(t){return null==t?"":String(t).replace($,C)}x.options=E.options={};var S={encode:x,escape:x,decode:E,unescape:E,version:"1.0.0-browser"};var T=function t(e){for(var s,n,i=Array.prototype.slice.call(arguments,1);i.length;)for(n in s=i.shift())s.hasOwnProperty(n)&&("[object Object]"===Object.prototype.toString.call(e[n])?e[n]=t(e[n],s[n]):e[n]=s[n]);return e},L=function(t){return"string"==typeof t?t.toLowerCase():t};function A(t,e){return t[e]=!0,t}var M=function(t){return t.reduce(A,{})},P={uris:M(["background","base","cite","href","longdesc","src","usemap"])},U={voids:M(["area","br","col","hr","img","wbr","input","base","basefont","link","meta"])},I=S,O=L,q=U,D=/^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)\s*>/,R=/^<\s*\/\s*([\w:-]+)[^>]*>/,B=/([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g,j=/^</,F=/^<\s*\//;var _=S,W=L,N=P,H=U;var z=T,V=function(t,e){for(var s,n=function(){var t=[];return t.lastItem=function(){return t[t.length-1]},t}(),i=t;t;)o();function o(){s=!0,function(){"\x3c!--"===t.substr(0,4)?(n=t.indexOf("--\x3e"))>=0&&(e.comment&&e.comment(t.substring(4,n)),t=t.substring(n+3),s=!1):F.test(t)?a(R,l):j.test(t)&&a(D,r);var n;!function(){if(!s)return;var n,i=t.indexOf("<");i>=0?(n=t.substring(0,i),t=t.substring(i)):(n=t,t="");e.chars&&e.chars(n)}()}();var n=t===i;i=t,n&&(t="")}function a(e,n){var i=t.match(e);i&&(t=t.substring(i[0].length),i[0].replace(e,n),s=!1)}function r(t,s,i,o){var a={},r=O(s),l=q.voids[r]||!!o;i.replace(B,(function(t,e,s,n,i){a[e]=void 0===s&&void 0===n&&void 0===i?void 0:I.decode(s||n||i||"")})),l||n.push(r),e.start&&e.start(r,a,l)}function l(t,s){var i,o=0,a=O(s);if(a)for(o=n.length-1;o>=0&&n[o]!==a;o--);if(o>=0){for(i=n.length-1;i>=o;i--)e.end&&e.end(n[i]);n.length=o}}l()},G=function(t,e){var s,n=e||{};return r(),{start:function(t,e,a){var r=W(t);if(s.ignoring)return void o(r);if(-1===(n.allowedTags||[]).indexOf(r))return void o(r);if(n.filter&&!n.filter({tag:r,attrs:e}))return void o(r);i("<"),i(r),Object.keys(e).forEach((function(t){var s=e[t],o=(n.allowedClasses||{})[r]||[],a=(n.allowedAttributes||{})[r]||[],l=W(t);("class"===l&&-1===a.indexOf(l)?(s=s.split(" ").filter((function(t){return o&&-1!==o.indexOf(t)})).join(" ").trim()).length:-1!==a.indexOf(l)&&(!0!==N.uris[l]||function(t){var e=t[0];if("#"===e||"/"===e)return!0;var s=t.indexOf(":");if(-1===s)return!0;var i=t.indexOf("?");if(-1!==i&&s>i)return!0;var o=t.indexOf("#");return-1!==o&&s>o||n.allowedSchemes.some(a);function a(e){return 0===t.indexOf(e+":")}}(s)))&&(i(" "),i(t),"string"==typeof s&&(i('="'),i(_.encode(s)),i('"')))})),i(a?"/>":">")},end:function(t){var e=W(t);-1!==(n.allowedTags||[]).indexOf(e)&&!1===s.ignoring?(i("</"),i(e),i(">")):a(e)},chars:function(t){!1===s.ignoring&&i(n.transformText?n.transformText(t):t)}};function i(e){t.push(e)}function o(t){H.voids[t]||(!1===s.ignoring?s={ignoring:t,depth:1}:s.ignoring===t&&s.depth++)}function a(t){s.ignoring===t&&--s.depth<=0&&r()}function r(){s={ignoring:!1,depth:0}}},K={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 Q(t,e,s){var n=[],i=!0===s?e:z({},K,e),o=G(n,i);return V(t,o),n.join("")}Q.defaults=K;const Y=y(Q),J={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","data-src","class","loading"],code:["class"],span:["class","style"]},filter:t=>([["code",/^hljs\W+language-(.*)$/],["span",/^(hljs-.*)$/],["img",/^lazyload$/]].forEach((([e,s])=>{t.tag===e&&t.attrs.class&&!s.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)};function X(t){return Y(t,J)}var Z={exports:{}};const tt=y(Z.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}})),s=["23AC69","91C132","F19726","E8552D","1AAB8E","E1147F","2980C1","1BA1E6","9FA0A0","F19726","E30B20","E30B20","A3338B"];function n(t){return'<span style="color: slategray">'+t+"</span>"}return function(t,i){void 0===i&&(i={});var o=i.colors;void 0===o&&(o=s);var a=0,r={},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,s){if(s)return n(s);if("<"===e)return"<";var i;r[e]?i=r[e]:(i=o[a],r[e]=i);var l='<span style="color: #'+i+'">'+e+"</span>";return a=++a%o.length,l}))}}());function et(t){return tt(t)}function st(t){const e=new h.marked.Renderer;return e.link=nt(e,e.link),e.code=it(),e.image=ot(e,e.image,t),e}const nt=(t,e)=>s=>{const n=(t=>{try{return new URL(t).origin}catch(e){return""}})(s.href)===window.location.origin;return e.call(t,s).replace(/^<a /,`<a target="_blank" ${n?"":'rel="noreferrer noopener nofollow"'} `)},it=()=>({lang:t,text:e})=>{const s=t||"plaintext";let n=e;return window.hljs?s&&window.hljs.getLanguage(s)&&(n=window.hljs.highlight(s,e).value):n=et(e),`<pre rel="${s}">\n<code class="hljs language-${s}">${n.replace(/&/g,"&")}</code>\n</pre>`},ot=(t,e,{imgLazyLoad:s})=>n=>{const i=e.call(t,n);return s?"native"===s||!0===s?i.replace(/^<img /,'<img class="lazyload" loading="lazy" '):"data-src"===s?i.replace(/^<img /,'<img class="lazyload" ').replace("src=","data-src="):i:i};let at,rt=[];const lt={gfm:!0,breaks:!0,async:!1};function ct(){return at}function dt(t){var e;let s=null==(e=ct())?void 0:e.parse(t);s||(s=function(t){return t.replace(/```\s*([^]+?.*?[^]+?[^]+?)```/g,((t,e)=>`<pre><code>${et(e)}</code></pre>`)).replace(/!\[(.*?)\]\((.*?)\)/g,((t,e,s)=>`<img src="${s}" alt="${e}" />`)).replace(/\[(.*?)\]\((.*?)\)/g,((t,e,s)=>`<a href="${s}" target="_blank">${e}</a>`)).replace(/\n/g,"<br>")}(t));let n=X(s);return rt.forEach((t=>{"function"==typeof t&&(n=t(n))})),n}function ht(...t){const e=t=>t&&"object"==typeof t&&t.constructor===Object;return t.reduce(((t,s)=>(Object.keys(null!=s?s:{}).forEach((n=>{if("__proto__"===n||"constructor"===n||"prototype"===n)return;const i=t[n],o=s[n];Array.isArray(i)&&Array.isArray(o)?t[n]=i.concat(...o):e(i)&&e(o)?t[n]=ht(i,o):t[n]=o})),t)),{})}class ut{constructor(t){c(this,"loading",!1),c(this,"listLastFetch"),c(this,"comments",[]),c(this,"notifies",[]),c(this,"page"),this.events=t}getLoading(){return this.loading}setLoading(t){this.loading=t}getListLastFetch(){return this.listLastFetch}setListLastFetch(t){this.listLastFetch=t}getComments(){return this.comments}fetchComments(t){this.events.trigger("list-fetch",t)}findComment(t){return this.comments.find((e=>e.id===t))}clearComments(){this.comments=[],this.events.trigger("list-loaded",this.comments)}loadComments(t){this.events.trigger("list-load",t),this.comments.push(...t),this.events.trigger("list-loaded",this.comments)}insertComment(t){this.comments.push(t),this.events.trigger("comment-inserted",t),this.events.trigger("list-loaded",this.comments)}updateComment(t){this.comments=this.comments.map((e=>e.id===t.id?t:e)),this.events.trigger("comment-updated",t),this.events.trigger("list-loaded",this.comments)}deleteComment(t){const e=this.comments.find((e=>e.id===t));if(!e)throw new Error(`Comment ${t} not found`);this.comments=this.comments.filter((e=>e.id!==t)),this.events.trigger("comment-deleted",e),this.events.trigger("list-loaded",this.comments)}getNotifies(){return this.notifies}updateNotifies(t){this.notifies=t,this.events.trigger("notifies-updated",this.notifies)}getPage(){return this.page}updatePage(t){this.page=t,this.events.trigger("page-loaded",t)}}function pt(t=""){const e=document.createElement("div");return e.innerHTML=t.trim(),e.firstElementChild||e}function mt(t){const e=document.createElement("div");e.innerText=t;return e.innerHTML}function gt(t){const e=RegExp(`[?&]${t}=([^&]*)`).exec(window.location.search);return e&&decodeURIComponent(e[1].replace(/\+/g," "))}function ft(t,e){const s=t=>{const e=t.getBoundingClientRect(),s=window.pageXOffset||document.documentElement.scrollLeft,n=window.pageYOffset||document.documentElement.scrollTop;return{top:e.top+n,left:e.left+s}},n=s(t);if(!e)return n;const i=s(e);return{top:n.top-i.top,left:n.left-i.left}}function yt(t,e){let s=t.toString();for(;s.length<e;)s=`0${s}`;return s}function kt(t,e=t=>t){try{const s=t.getTime(),n=(new Date).getTime()-s,i=Math.floor(n/864e5);if(0===i){const t=n%864e5,s=Math.floor(t/36e5);if(0===s){const s=t%36e5,n=Math.floor(s/6e4);if(0===n){const t=s%6e4,n=Math.round(t/1e3);return n<10?e("now"):`${n} ${e("seconds")}`}return`${n} ${e("minutes")}`}return`${s} ${e("hours")}`}return i<0?e("now"):i<8?`${i} ${e("days")}`:function(t){const e=yt(t.getDate(),2),s=yt(t.getMonth()+1,2);return`${yt(t.getFullYear(),2)}-${s}-${e}`}(t)}catch(s){return console.error(s)," - "}}function vt(){return d(this,null,(function*(){const t=navigator.userAgent;if(!navigator.userAgentData||!navigator.userAgentData.getHighEntropyValues)return t;const e=navigator.userAgentData;let s=null;try{s=yield e.getHighEntropyValues(["platformVersion"])}catch(i){return console.error(i),t}const n=Number(s.platformVersion.split(".")[0]);return"Windows"===e.platform&&n>=13?t.replace(/Windows NT 10.0/,"Windows NT 11.0"):"macOS"===e.platform&&n>=11?t.replace(/(Mac OS X \d+_\d+_\d+|Mac OS X)/,`Mac OS X ${s.platformVersion.replace(/\./g,"_")}`):t}))}function $t(t){let e;try{e=new URL(t)}catch(s){return!1}return"http:"===e.protocol||"https:"===e.protocol}function wt(t){return e=t.base,s=t.path,`${e.replace(/\/$/,"")}/${s.replace(/^\//,"")}`;var e,s}const bt={placeholder:"Leave a comment",noComment:"No Comment",send:"Send",signIn:"Sign in",signUp:"Sign up",save:"Save",nick:"Nickname",email:"Email",link:"Website",emoticon:"Emoji",preview:"Preview",uploadImage:"Upload 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:"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:"Dashboard",userProfile:"Profile",noAccountPrompt:"Don't have an account?",haveAccountPrompt:"Already have an account?",forgetPassword:"Forget Password",resetPassword:"Reset Password",changePassword:"Change Password",confirmPassword:"Confirm Password",passwordMismatch:"Passwords do not match",verificationCode:"Verification Code",verifySend:"Send Code",verifyResend:"Resend",waitSeconds:"Wait {seconds}s",emailVerified:"Email has been verified",password:"Password",username:"Username",nextStep:"Next Step",skipVerify:"Skip verification",logoutConfirm:"Are you sure to logout?",accountMergeNotice:"Your email has multiple accounts with different id.",accountMergeSelectOne:"Please select one you want to merge all the data into it.",accountMergeConfirm:"All data will be merged into one account, the id is {id}.",dismiss:"Dismiss",merge:"Merge",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",updateMsg:"Please update Artalk {name} to get the best experience!",currentVersion:"Current Version",ignore:"Ignore",open:"Open",openName:"Open {name}"},Ct="ArtalkI18n",xt={en:bt,"en-US":bt,"zh-CN":{placeholder:"键入内容...",noComment:"「此时无声胜有声」",send:"发送",signIn:"登录",signUp:"注册",save:"保存",nick:"昵称",email:"邮箱",link:"网址",emoticon:"表情",preview:"预览",uploadImage:"上传图片",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:"控制中心",userProfile:"个人资料",noAccountPrompt:"没有账号?",haveAccountPrompt:"已有账号?",forgetPassword:"忘记密码",resetPassword:"重置密码",changePassword:"修改密码",confirmPassword:"确认密码",passwordMismatch:"两次输入的密码不一致",verificationCode:"验证码",verifySend:"发送验证码",verifyResend:"重新发送",waitSeconds:"等待 {seconds}秒",emailVerified:"邮箱已验证",password:"密码",username:"用户名",nextStep:"下一步",skipVerify:"跳过验证",logoutConfirm:"确定要退出登录吗?",accountMergeNotice:"您的电子邮件下有多个不同 ID 的账户。",accountMergeSelectOne:"请选择将所有数据合并到其中的一个。",accountMergeConfirm:"所有数据将合并到 ID 为 {id} 的账户中。",dismiss:"忽略",merge:"合并",frontend:"前端",backend:"后端",loading:"加载中",loadFail:"加载失败",editing:"修改中",editFail:"修改失败",deleting:"删除中",deleteFail:"删除失败",reqGot:"请求响应",reqAborted:"请求超时或意外终止",updateMsg:"请更新 Artalk {name} 以获得更好的体验!",currentVersion:"当前版本",ignore:"忽略",open:"打开",openName:"打开{name}"}};function Et(t){return t=t.replace(/^([a-zA-Z]+)(-[a-zA-Z]+)?$/,((t,e,s)=>e.toLowerCase()+(s||"").toUpperCase())),xt[t]?xt[t]:window[Ct]&&window[Ct][t]?window[Ct][t]:xt.en}let St="en",Tt=Et(St);function Lt(t){t!==St&&(St=t,Tt="string"==typeof t?Et(t):t)}function At(t,e={}){let s=(null==Tt?void 0:Tt[t])||t;return s=s.replace(/\{\s*(\w+?)\s*\}/g,((t,s)=>e[s]||"")),mt(s)}class Mt{constructor(){c(this,"events",[])}on(t,e,s={}){this.events.push(r({name:t,handler:e},s))}off(t,e){e&&(this.events=this.events.filter((s=>!(s.name===t&&s.handler===e))))}trigger(t,e){this.events.slice(0).filter((e=>e.name===t&&"function"==typeof e.handler)).forEach((s=>{s.once&&this.off(t,s.handler),s.handler(e)}))}}const Pt={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:".artalk-comment-count",pvEl:".artalk-pv-count",statPageKeyAttr:"data-page-key",gravatar:{mirror:"https://www.gravatar.com/avatar/",params:"sha256=1&d=mp&s=240"},pagination:{pageSize:20,readMore:!0,autoLoad:!0},heightLimit:{content:300,children:400,scrollable:!1},imgUpload:!0,reqTimeout:15e3,versionCheck:!0,useBackendConf:!0,locale:"en"};function Ut(t,e=!1){const s=e?ht(Pt,t):t;if(s.el&&"string"==typeof s.el)try{const t=document.querySelector(s.el);if(!t)throw Error(`Target element "${s.el}" was not found.`);s.el=t}catch(n){throw console.error(n),new Error("Please check your Artalk `el` config.")}return""===s.pageKey&&(s.pageKey=`${window.location.pathname}`),""===s.pageTitle&&(s.pageTitle=`${document.title}`),s.server&&(s.server=s.server.replace(/\/$/,"").replace(/\/api\/?$/,"")),"auto"===s.locale&&(s.locale=navigator.language),"auto"===s.flatMode&&(s.flatMode=window.matchMedia("(max-width: 768px)").matches),"number"==typeof s.nestMax&&Number(s.nestMax)<=1&&(s.flatMode=!0),s}function It(t,e){return{baseURL:`${t.server}/api/v2`,siteName:t.site||"",pageKey:t.pageKey||"",pageTitle:t.pageTitle||"",timeout:t.reqTimeout,getApiToken:()=>null==e?void 0:e.get("user").getData().token,userInfo:(null==e?void 0:e.get("user").checkHasBasicUserInfo())?{name:null==e?void 0:e.get("user").getData().name,email:null==e?void 0:e.get("user").getData().email}:void 0,handlers:null==e?void 0:e.getApiHandlers()}}function Ot(t,e,s){let n=null;const i=()=>{const i=(()=>{const s=t.getConf(),n={};return e.forEach((t=>{n[t]=s[t]})),n})();var o,a;(null==n||(o=n,a=i,!(JSON.stringify(o)===JSON.stringify(a))))&&(n=i,s(i))};t.on("mounted",i),t.on("updated",i)}class qt{constructor(t){c(this,"conf"),c(this,"data"),c(this,"$root"),c(this,"events",new Mt),c(this,"mounted",!1),c(this,"apiHandlers",null),c(this,"getCommentList",this.getCommentNodes),c(this,"getCommentDataList",this.getComments),this.conf=t,this.$root=t.el,this.$root.classList.add("artalk"),this.$root.innerHTML="",t.darkMode&&this.$root.classList.add("atk-dark-mode"),this.data=new ut(this.events),this.on("mounted",(()=>{this.mounted=!0}))}inject(t,e){this[t]=e}get(t){return this[t]}getApi(){return new f(It(this.conf,this))}getApiHandlers(){return this.apiHandlers||(this.apiHandlers=function(t){const e=function(){const t=[];return{add:(e,s)=>{t.push({action:e,handler:s})},remove:e=>{const s=t.findIndex((t=>t.action===e));-1!==s&&t.splice(s,1)},get:()=>t}}();return e.add("need_captcha",(e=>t.checkCaptcha(e))),e.add("need_login",(()=>t.checkAdmin({}))),e}(this)),this.apiHandlers}getData(){return this.data}replyComment(t,e){this.editor.setReply(t,e)}editComment(t,e){this.editor.setEditComment(t,e)}fetch(t){this.data.fetchComments(t)}reload(){this.data.fetchComments({offset:0})}listGotoFirst(){this.events.trigger("list-goto-first")}getCommentNodes(){return this.list.getCommentNodes()}getComments(){return this.data.getComments()}editorShowLoading(){this.editor.showLoading()}editorHideLoading(){this.editor.hideLoading()}editorShowNotify(t,e){this.editor.showNotify(t,e)}editorResetState(){this.editor.resetState()}showSidebar(t){this.sidebarLayer.show(t)}hideSidebar(){this.sidebarLayer.hide()}checkAdmin(t){return this.checkerLauncher.checkAdmin(t)}checkCaptcha(t){return this.checkerLauncher.checkCaptcha(t)}on(t,e){this.events.on(t,e)}off(t,e){this.events.off(t,e)}trigger(t,e){this.events.trigger(t,e)}$t(t,e={}){return At(t,e)}setDarkMode(t){this.updateConf({darkMode:t})}updateConf(t){this.conf=ht(this.conf,Ut(t,!1)),this.mounted&&this.events.trigger("updated",this.conf)}getConf(){return this.conf}getEl(){return this.$root}getMarked(){return ct()}watchConf(t,e){Ot(this,t,e)}}function Dt(t,e){let s=t.querySelector(":scope > .atk-loading");s||(s=pt('<div class="atk-loading" 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)&&(s.style.background="transparent"),t.appendChild(s)),s.style.display="";const n=s.querySelector(".atk-loading-spinner");n&&(n.style.display="none",window.setTimeout((()=>{n.isConnected&&(n.style.display="")}),500))}function Rt(t){const e=t.querySelector(":scope > .atk-loading");e&&(e.style.display="none")}function Bt(t,e){t?Dt(e):Rt(e)}function jt(t,e=!0,s){let n;if(s){const e=s.getBoundingClientRect();n=t.getBoundingClientRect().top-e.top+s.scrollTop-s.clientHeight/2+t.clientHeight/2}else{const e=t.getBoundingClientRect();n=e.top+window.scrollY-(window.innerHeight/2-e.height/2)}const i={top:n,left:0,behavior:"instant"};s?s.scroll(i):window.scroll(i)}function Ft(t,e){!function(t,e,s="in"){t.classList.add(`atk-fade-${s}`);const n=()=>{t.classList.remove(`atk-fade-${s}`),t.removeEventListener("animationend",n)};t.addEventListener("animationend",n)}(t,0,"in")}function _t(t,e,s='<span class="atk-error-title">Artalk Error</span>'){let n=t.querySelector(".atk-error-layer");if(null===e)return void(null!==n&&n.remove());n||(n=pt(`<div class="atk-error-layer">${s}<span class="atk-error-text"></span></div>`),t.appendChild(n));const i=n.querySelector(".atk-error-text");i.innerHTML="",null!==e&&(e instanceof HTMLElement?i.appendChild(e):i.innerText=e)}function Wt(t){const e=pt('<div class="atk-checker-iframe-wrap"></div>'),s=pt('<iframe class="atk-fade-in" referrerpolicy="strict-origin-when-cross-origin"></iframe>');s.style.display="none",Dt(e,{transparentBg:!0}),s.src=t.getOpts().getCaptchaIframeURL(),s.onload=()=>{s.style.display="",Rt(e)},e.append(s);const n=pt('<div class="atk-close-btn"><i class="atk-icon atk-icon-close"></i></div>');e.append(n),t.hideInteractInput();let i=!1;return function e(){return d(this,null,(function*(){var s;if(yield(s=1e3,new Promise((t=>{window.setTimeout((()=>{t(null)}),s)}))),i)return;let n=!1;try{n=(yield t.getApi().captcha.getCaptchaStatus()).data.is_pass}catch(o){n=!1}n?t.triggerSuccess():e()}))}(),n.onclick=()=>{i=!0,t.cancel()},e}const Nt={request:(t,e)=>t.getApi().captcha.verifyCaptcha({value:e}),body:t=>t.get("iframe")?Wt(t):function(t){const e=pt(`<span><img class="atk-captcha-img" src="${t.get("img_data")||""}">${At("captchaCheck")}</span>`);return e.querySelector(".atk-captcha-img").onclick=()=>{const s=e.querySelector(".atk-captcha-img");t.getApi().captcha.getCaptcha().then((t=>{s.setAttribute("src",t.data.img_data)})).catch((t=>{console.error("Failed to get captcha image ",t)}))},e}(t),onSuccess(t,e,s,n){t.set("val",s)},onError(t,e,s,n){n.querySelector(".atk-captcha-img").click(),n.querySelector('input[type="text"]').value=""}},Ht={inputType:"password",request(t,e){return d(this,null,(function*(){return(yield t.getApi().user.login({name:t.getUser().getData().name,email:t.getUser().getData().email,password:e})).data}))},body:t=>pt(`<span>${At("adminCheck")}</span>`),onSuccess(t,e,s,n){t.getUser().update({is_admin:!0,token:e.token}),t.getOpts().onReload()},onError(t,e,s,n){}};class zt{constructor(t){c(this,"$el"),c(this,"$content"),c(this,"$actions"),this.$el=pt('<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(t)}setYes(t){const e=pt(`<button data-action="confirm">${At("confirm")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}setNo(t){const e=pt(`<button data-action="cancel">${At("cancel")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}onBtnClick(t){return e=>{const s=t(e.currentTarget,this);void 0!==s&&!0!==s||this.$el.remove()}}}function Vt(t){return e=>new Promise(((s,n)=>{const i=e.onCancel;e.onCancel=()=>{i&&i(),n(new Error("user canceled the checker"))};const o=e.onSuccess;e.onSuccess=()=>{o&&o(),s()},t(e)}))}class Gt{constructor(t){c(this,"checkCaptcha",Vt((t=>{this.fire(Nt,t,(e=>{e.set("img_data",t.img_data),e.set("iframe",t.iframe)}))}))),c(this,"checkAdmin",Vt((t=>{this.fire(Ht,t)}))),this.opts=t}fire(t,e,s){const n=this.opts.getCtx().get("layerManager").create(`checker-${(new Date).getTime()}`);n.show();const i=()=>{n.destroy()},o={};let a=!1;const r={set:(t,e)=>{o[t]=e},get:t=>o[t],getOpts:()=>this.opts,getUser:()=>this.opts.getCtx().get("user"),getApi:()=>this.opts.getApi(),hideInteractInput:()=>{a=!0},triggerSuccess:()=>{i(),t.onSuccess&&t.onSuccess(r,"","",l),e.onSuccess&&e.onSuccess()},cancel:()=>{i(),e.onCancel&&e.onCancel()}};s&&s(r);const l=pt();l.appendChild(t.body(r));const c=pt(`<input id="check" type="${t.inputType||"text"}" autocomplete="off" required placeholder="">`);let d;l.appendChild(c),setTimeout((()=>c.focus()),80),c.onkeyup=t=>{"Enter"!==t.key&&13!==t.keyCode||(t.preventDefault(),n.getEl().querySelector('button[data-action="confirm"]').click())};const h=new zt(l);h.setYes((s=>{const n=c.value.trim();d||(d=s.innerText);const o=()=>{s.innerText=d||"",s.classList.remove("error")};return s.innerText=`${At("loading")}...`,t.request(r,n).then((s=>{i(),t.onSuccess&&t.onSuccess(r,s,n,l),e.onSuccess&&e.onSuccess()})).catch((e=>{var i;i=String(e.message||String(e)),s.innerText=i,s.classList.add("error"),t.onError&&t.onError(r,e,n,l);const a=setTimeout((()=>o()),3e3);c.onfocus=()=>{o(),clearTimeout(a)}})),!1})),h.setNo((()=>(i(),e.onCancel&&e.onCancel(),!1))),a&&(c.style.display="none",h.$el.querySelector(".atk-layer-dialog-actions").style.display="none"),n.getEl().append(h.$el),e.onMount&&e.onMount(h.$el)}}class Kt{constructor(t){c(this,"$el"),this.ctx=t}get conf(){return this.ctx.conf}getEl(){return this.$el}}const Qt={$header:".atk-header",$name:'.atk-header [name="name"]',$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",$bottomLeft:".atk-bottom-left",$stateWrap:".atk-state-wrap",$plugBtnWrap:".atk-plug-btn-wrap",$plugPanelWrap:".atk-plug-panel-wrap"};class Yt{constructor(t){c(this,"$btn"),c(this,"$panel"),c(this,"editorStateEffectWhen"),this.kit=t}useBtn(t="<div></div>"){return this.$btn=pt(`<span class="atk-plug-btn">${t}</span>`),this.$btn}usePanel(t="<div></div>"){return this.$panel=pt(t),this.$panel}useContentTransformer(t){this.contentTransformer=t}usePanelShow(t){this.kit.useEvents().on("panel-show",(e=>{e===this&&t()}))}usePanelHide(t){this.kit.useEvents().on("panel-hide",(e=>{e===this&&t()}))}useEditorStateEffect(t,e){this.editorStateEffectWhen=t,this.editorStateEffect=e}}class Jt extends Yt{constructor(){super(...arguments),c(this,"isMoved",!1)}move(t){if(this.isMoved)return;this.isMoved=!0;const e=this.kit.useUI().$el;e.after(pt('<div class="atk-editor-travel-placeholder"></div>'));const s=pt("<div></div>");t.after(s),s.replaceWith(e),e.classList.add("atk-fade-in"),e.classList.add("editor-traveling")}back(){var t;this.isMoved&&(this.isMoved=!1,null==(t=this.kit.useGlobalCtx().$root.querySelector(".atk-editor-travel-placeholder"))||t.replaceWith(this.kit.useUI().$el),this.kit.useUI().$el.classList.remove("editor-traveling"))}}class Xt{constructor(t){c(this,"stateCurt","normal"),c(this,"stateUnmountFn",null),this.editor=t}get(){return this.stateCurt}switch(t,e){var s,n,i,o,a;if(this.stateUnmountFn&&(this.stateUnmountFn(),this.stateUnmountFn=null,null==(n=null==(s=this.editor.getPlugs())?void 0:s.get(Jt))||n.back()),"normal"!==t&&e){let s=e.$comment;this.editor.conf.flatMode||(s=s.querySelector(".atk-footer")),null==(o=null==(i=this.editor.getPlugs())?void 0:i.get(Jt))||o.move(s);const n=this.editor.ctx.conf.scrollRelativeTo&&this.editor.ctx.conf.scrollRelativeTo();jt(this.editor.getUI().$el,!0,n);const r=null==(a=this.editor.getPlugs())?void 0:a.getPlugs().find((e=>e.editorStateEffectWhen===t));r&&r.editorStateEffect&&(this.stateUnmountFn=r.editorStateEffect(e.comment))}this.stateCurt=t}}class Zt extends Kt{constructor(t){super(t),c(this,"ui"),c(this,"state"),this.ui=function(){const t=pt('<div class="atk-main-editor">\n <div class="atk-header">\n <input name="name" class="atk-name" 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-bottom-left">\n <span class="atk-state-wrap"></span>\n <span class="atk-plug-btn-wrap"></span>\n </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(Qt).forEach((([s,n])=>{e[s]=t.querySelector(n)})),e}(),this.$el=this.ui.$el,this.state=new Xt(this)}getUI(){return this.ui}getPlugs(){return this.ctx.get("editorPlugs")}getState(){return this.state.get()}getHeaderInputEls(){return{name:this.ui.$name,email:this.ui.$email,link:this.ui.$link}}getContentFinal(){let t=this.getContentRaw();const e=this.getPlugs();return e&&(t=e.getTransformedContent(t)),t}getContentRaw(){return this.ui.$textarea.value||""}getContentMarked(){return dt(this.getContentFinal())}setContent(t){var e;this.ui.$textarea.value=t,null==(e=this.getPlugs())||e.getEvents().trigger("content-updated",t)}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,s=this.ui.$textarea.selectionEnd,n=this.ui.$textarea.scrollTop;this.setContent(this.ui.$textarea.value.substring(0,e)+t+this.ui.$textarea.value.substring(s,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=n}else this.ui.$textarea.focus(),this.ui.$textarea.value+=t}focus(){this.ui.$textarea.focus()}reset(){this.setContent(""),this.resetState()}resetState(){this.state.switch("normal")}setReply(t,e){this.state.switch("reply",{comment:t,$comment:e})}setEditComment(t,e){this.state.switch("edit",{comment:t,$comment:e})}showNotify(t,e){!function(t,e,s){const n=pt(`<div class="atk-notify atk-fade-in" style="background-color: ${{s:"#57d59f",e:"#ff6f6c",w:"#ffc721",i:"#2ebcfc"}[s]}"><span class="atk-notify-content"></span></div>`);n.querySelector(".atk-notify-content").innerHTML=mt(e).replace("\n","<br/>"),t.appendChild(n);const i=()=>{n.classList.add("atk-fade-out"),setTimeout((()=>{n.remove()}),200)};let o;o=window.setTimeout((()=>{i()}),3e3),n.addEventListener("click",(()=>{i(),window.clearTimeout(o)}))}(this.ui.$notifyWrap,t,e)}showLoading(){Dt(this.ui.$el)}hideLoading(){Rt(this.ui.$el)}submit(){const t=()=>this.ctx.trigger("editor-submit");this.ctx.conf.beforeSubmit?this.ctx.conf.beforeSubmit(this,t):t()}}class te extends Kt{constructor(t){super(t),c(this,"layer"),c(this,"$header"),c(this,"$closeBtn"),c(this,"$iframeWrap"),c(this,"$iframe"),c(this,"refreshWhenShow",!0),c(this,"animTimer"),this.$el=pt('<div class="atk-sidebar-layer">\n <div class="atk-sidebar-inner">\n <div class="atk-sidebar-header">\n <div class="atk-sidebar-close">\n <i class="atk-icon atk-icon-close-slim"></i>\n </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.refreshWhenShow=!0}))}show(){return d(this,arguments,(function*(t={}){if(this.$el.style.transform="",this.initLayer(),this.layer.show(),this.refreshWhenShow)this.refreshWhenShow=!1,this.$iframeWrap.innerHTML="",this.$iframe=this.createIframe(t.view),this.$iframeWrap.append(this.$iframe);else{const t=this.$iframe,e=t.src;this.getDarkMode()!==e.includes("&darkMode=1")&&this.iframeLoad(t,e.replace(/&darkMode=\d/,`&darkMode=${Number(this.getDarkMode())}`))}this.authCheck({onSuccess:()=>this.show(t)}),this.animTimer=setTimeout((()=>{this.animTimer=void 0,this.$el.style.transform="translate(0, 0)",setTimeout((()=>{this.ctx.getData().updateNotifies([])}),0),this.ctx.trigger("sidebar-show")}),100)}))}hide(){var t;null==(t=this.layer)||t.hide()}authCheck(t){return d(this,null,(function*(){const e=(yield this.ctx.getApi().user.getUserStatus(r({},this.ctx.getApi().getUserFields()))).data;e.is_admin&&!e.is_login&&(this.refreshWhenShow=!0,this.ctx.checkAdmin({onSuccess:()=>{setTimeout((()=>{t.onSuccess()}),500)},onCancel:()=>{this.hide()}}),this.hide())}))}initLayer(){this.layer||(this.layer=this.ctx.get("layerManager").create("sidebar",this.$el),this.layer.setOnAfterHide((()=>{this.ctx.editorResetState(),this.animTimer&&clearTimeout(this.animTimer),this.$el.style.transform="",this.ctx.trigger("sidebar-hide")})))}createIframe(t){const e=pt('<iframe referrerpolicy="strict-origin-when-cross-origin"></iframe>'),s=wt({base:this.ctx.conf.server,path:"/sidebar/"}),n={pageKey:this.conf.pageKey,site:this.conf.site||"",user:JSON.stringify(this.ctx.get("user").getData()),time:+new Date};t&&(n.view=t),n.darkMode=this.getDarkMode()?"1":"0";const i=new URLSearchParams(n);return this.iframeLoad(e,`${s}?${i.toString()}`),e}getDarkMode(){return"auto"===this.conf.darkMode?window.matchMedia("(prefers-color-scheme: dark)").matches:this.conf.darkMode}iframeLoad(t,e){t.src=e,Dt(this.$iframeWrap),t.onload=()=>{Rt(this.$iframeWrap)}}}const ee=t=>({import:e=>{(function(t,e="DATE_DESC",s=2){const n=[];t.filter((t=>0===t.rid)).forEach((e=>{const i={id:e.id,comment:e,children:[],level:1};i.parent=i,n.push(i),function e(n){const i=t.filter((t=>t.rid===n.id));0!==i.length&&(n.level>=s&&(n=n.parent),i.forEach((t=>{const s={id:t.id,comment:t,children:[],parent:n,level:n.level+1};n.children.push(s),e(s)})))}(i)}));const i=(s,n)=>{let i=s.id-n.id;return"DATE_ASC"===e?i=+new Date(s.comment.date)-+new Date(n.comment.date):"DATE_DESC"===e?i=+new Date(n.comment.date)-+new Date(s.comment.date):"SRC_INDEX"===e?i=t.indexOf(s.comment)-t.indexOf(n.comment):"VOTE_UP_DESC"===e&&(i=n.comment.vote_up-s.comment.vote_up),i};return function t(e){e.forEach((e=>{e.children=e.children.sort(i),t(e.children)}))}(n),n})(e,t.nestSortBy,t.nestMax).forEach((s=>{var n;const i=t.createCommentNode(s.comment);null==(n=t.$commentsWrap)||n.appendChild(i.getEl()),i.getRender().playFadeAnim();const o=(s,n)=>{n.children.forEach((n=>{const i=e.find((t=>t.id===n.comment.rid)),a=n.comment,r=t.createCommentNode(a,i);s.putChild(r),o(r,n)}))};o(i,s),i.getRender().checkHeightLimit()}))},insert:(e,s)=>{var n;const i=t.createCommentNode(e,s);if(0===e.rid)null==(n=t.$commentsWrap)||n.prepend(i.getEl());else{const s=t.findCommentNode(e.rid);s&&(s.putChild(i,"DATE_ASC"===t.nestSortBy?"append":"prepend"),i.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()})))}i.getRender().checkHeightLimit(),i.scrollIntoView(),i.getRender().playFadeAnim()}});function se(t,e,s,n){s.is_collapsed&&(s.is_allow_reply=!1);const i=t.createCommentNode(s,n);if(s.visible){const s=i.getEl(),n=t.$commentsWrap;"append"===e&&(null==n||n.append(s)),"prepend"===e&&(null==n||n.prepend(s)),i.getRender().playFadeAnim()}return i.getRender().checkHeightLimit(),i}class ne{constructor(t){this.options=t}getStrategy(){return this.options.flatMode?(t=this.options,{import:e=>{e.forEach((s=>{const n=0===s.rid?void 0:e.find((t=>t.id===s.rid));se(t,"append",s,n)}))},insert:(e,s)=>{se(t,"prepend",e,s).scrollIntoView()}}):ee(this.options);var t}import(t){this.getStrategy().import(t)}insert(t,e){this.getStrategy().insert(t,e)}}function ie(t,e){e.forEach((({el:e,max:s,imgCheck:n})=>{if(!e)return;n&&(e.style.maxHeight=`${s+1}px`);let i=!1;const o=()=>{if(i)return;if(function(t){return parseFloat(getComputedStyle(t,null).height.replace("px",""))||0}(e)<=s)return;t.scrollable?function(t){if(!t.el)return;if(t.el.classList.contains(re))return;t.el.classList.add(re),t.el.style.height=`${t.max}px`}({el:e,max:s}):function(t){if(!t.el)return;if(!t.max)return;if(t.el.classList.contains(oe))return;t.el.classList.add(oe),t.el.style.height=`${t.max}px`,t.el.style.overflow="hidden";const e=pt(`<div class="atk-height-limit-btn">${At("readMore")}</span>`);e.onclick=e=>{e.stopPropagation(),ae(t.el),t.afterExpandBtnClick&&t.afterExpandBtnClick(e)},t.el.append(e)}({el:e,max:s,afterExpandBtnClick:()=>{var e;i=!0,null==(e=t.afterExpandBtnClick)||e.call(t)}})};if(o(),n){const t=e.querySelectorAll(".atk-content img");0===t.length&&(e.style.maxHeight=""),t.forEach((t=>{t.onload=()=>o()}))}}))}const oe="atk-height-limit";function ae(t){t&&t.classList.contains(oe)&&(t.classList.remove(oe),Array.from(t.children).forEach((t=>{t.classList.contains("atk-height-limit-btn")&&t.remove()})),t.style.height="",t.style.maxHeight="",t.style.overflow="")}const re="atk-height-limit-scroll";function le(t){if(t.$headerNick=t.$el.querySelector(".atk-nick"),t.data.link){const e=pt('<a target="_blank" rel="noreferrer noopener nofollow"></a>');e.innerText=t.data.nick,e.href=$t(t.data.link)?t.data.link:`https://${t.data.link}`,t.$headerNick.append(e)}else t.$headerNick.innerText=t.data.nick}function ce(t){t.$headerBadgeWrap=t.$el.querySelector(".atk-badge-wrap"),t.$headerBadgeWrap.innerHTML="";const e=t.data.badge_name,s=t.data.badge_color;if(e){const n=pt('<span class="atk-badge"></span>');n.innerText=e.replace("管理员",At("admin")),n.style.backgroundColor=s||"",t.$headerBadgeWrap.append(n)}else if(t.data.is_verified){const e=pt(`<span class="atk-verified-icon" title="${At("emailVerified")}"></span>`);t.$headerBadgeWrap.append(e)}if(t.data.is_pinned){const e=pt(`<span class="atk-pinned-badge">${At("pin")}</span>`);t.$headerBadgeWrap.append(e)}}function de(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 he(t){if(!t.opts.uaBadge&&!t.data.ip_region)return;let e=t.$header.querySelector("atk-ua-wrap");if(e||(e=pt('<span class="atk-ua-wrap"></span>'),t.$header.append(e)),e.innerHTML="",t.data.ip_region){const s=pt('<span class="atk-region-badge"></span>');s.innerText=t.data.ip_region,e.append(s)}if(t.opts.uaBadge){const{browser:s,os:n}=t.comment.getUserUA();if(String(s).trim()){const t=pt('<span class="atk-ua ua-browser"></span>');t.innerText=s,e.append(t)}if(String(n).trim()){const t=pt('<span class="atk-ua ua-os"></span>');t.innerText=n,e.append(t)}}}class ue{constructor(t){c(this,"opts"),c(this,"$el"),c(this,"isLoading",!1),c(this,"msgRecTimer"),c(this,"msgRecTimerFunc"),c(this,"isConfirming",!1),c(this,"confirmRecTimer"),this.$el=pt('<span class="atk-common-action-btn"></span>'),this.opts="object"!=typeof t?{text:t}:t,this.$el.innerText=this.getText(),this.opts.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.opts.text?this.opts.text:this.opts.text()}setClick(t){this.$el.onclick=e=>{if(e.stopPropagation(),!this.isLoading){if(this.opts.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.opts.confirmText||At("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.opts.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||`${At("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,s,n){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),n&&n()}),s||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 pe(t){t.opts.vote&&(t.voteBtnUp=new ue((()=>`${At("voteUp")} (${t.data.vote_up||0})`)).appendTo(t.$actions),t.voteBtnUp.setClick((()=>{t.comment.getActions().vote("up")})),t.opts.voteDown&&(t.voteBtnDown=new ue((()=>`${At("voteDown")} (${t.data.vote_down||0})`)).appendTo(t.$actions),t.voteBtnDown.setClick((()=>{t.comment.getActions().vote("down")}))))}function me(t){if(!t.data.is_allow_reply)return;const e=pt(`<span>${At("reply")}</span>`);t.$actions.append(e),e.addEventListener("click",(e=>{e.stopPropagation(),t.opts.replyComment(t.data,t.$el)}))}function ge(t){const e=new ue({text:()=>t.data.is_collapsed?At("expand"):At("collapse"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("collapsed",e)}))}function fe(t){const e=new ue({text:()=>t.data.is_pending?At("pending"):At("approved"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pending",e)}))}function ye(t){const e=new ue({text:()=>t.data.is_pinned?At("unpin"):At("pin"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pinned",e)}))}function ke(t){const e=new ue({text:At("edit"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.opts.editComment(t.data,t.$el)}))}function ve(t){const e=new ue({text:At("delete"),confirm:!0,confirmText:At("deleteConfirm"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminDelete(e)}))}const $e={Avatar:function(t){const e=t.$el.querySelector(".atk-avatar"),s=pt("<img />"),n=t.opts.avatarURLBuilder;if(s.src=n?n(t.data):t.comment.getGravatarURL(),t.data.link){const n=pt('<a target="_blank" rel="noreferrer noopener nofollow"></a>');n.href=$t(t.data.link)?t.data.link:`https://${t.data.link}`,n.append(s),e.append(n)}else e.append(s)},Header:function(t){Object.entries({renderNick:le,renderVerifyBadge:ce,renderDate:de,renderUABadge:he}).forEach((([e,s])=>{s(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=pt(`\n <div class="atk-collapsed">\n <span class="atk-text">${At("collapsedMsg")}</span>\n <span class="atk-show-btn">${At("expand")}</span>\n </div>`);t.$body.insertAdjacentElement("beforeend",e);const s=e.querySelector(".atk-show-btn");s.addEventListener("click",(e=>{e.stopPropagation(),t.$content.classList.contains("atk-hide")?(t.$content.innerHTML=t.comment.getContentMarked(),t.$content.classList.remove("atk-hide"),Ft(t.$content),s.innerText=At("collapse")):(t.$content.innerHTML="",t.$content.classList.add("atk-hide"),s.innerText=At("expand"))}))},ReplyAt:function(t){t.opts.flatMode||0===t.data.rid||t.opts.replyTo&&(t.$replyAt=pt('<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.opts.replyTo.nick}`,t.$replyAt.onclick=()=>{t.comment.getActions().goToReplyComment()},t.$headerBadgeWrap.insertAdjacentElement("afterend",t.$replyAt))},ReplyTo:function(t){if(!t.opts.flatMode)return;if(!t.opts.replyTo)return;t.$replyTo=pt(`\n <div class="atk-reply-to">\n <div class="atk-meta">${At("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.opts.replyTo.nick}`,e.onclick=()=>{t.comment.getActions().goToReplyComment()};let s=dt(t.opts.replyTo.content);t.opts.replyTo.is_collapsed&&(s=`[${At("collapsed")}]`),t.$replyTo.querySelector(".atk-content").innerHTML=s,t.$body.prepend(t.$replyTo)},Pending:function(t){if(!t.data.is_pending)return;const e=pt(`<div class="atk-pending">${At("pendingMsg")}</div>`);t.$body.prepend(e)},Actions:function(t){Object.entries({renderVote:pe,renderReply:me,renderCollapse:ge,renderModerator:fe,renderPin:ye,renderEdit:ke,renderDel:ve}).forEach((([e,s])=>{s(t)}))}};class we{constructor(t){c(this,"comment"),c(this,"$el"),c(this,"$main"),c(this,"$header"),c(this,"$headerNick"),c(this,"$headerBadgeWrap"),c(this,"$body"),c(this,"$content"),c(this,"$childrenWrap"),c(this,"$actions"),c(this,"voteBtnUp"),c(this,"voteBtnDown"),c(this,"$replyTo"),c(this,"$replyAt"),this.comment=t}get data(){return this.comment.getData()}get opts(){return this.comment.getOpts()}render(){var t;return this.$el=pt('<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($e).forEach((([e,s])=>{s(t)})),this.$childrenWrap&&this.$main.append(this.$childrenWrap),this.$el}checkHeightLimit(){const t=this.opts.heightLimit;if(!t||!t.content||!t.children)return;const e=t.content,s=t.children;ie({afterExpandBtnClick:()=>{const t=this.comment.getChildren();1===t.length&&ae(t[0].getRender().$content)},scrollable:t.scrollable},[{el:this.$content,max:e,imgCheck:!0},{el:this.$replyTo,max:e,imgCheck:!0},{el:this.$childrenWrap,max:s,imgCheck:!1}])}heightLimitRemoveForChildren(){this.$childrenWrap&&ae(this.$childrenWrap)}playFadeAnim(){Ft(this.comment.getRender().$el)}playFadeAnimForBody(){Ft(this.comment.getRender().$body)}playFlashAnim(){this.$el.classList.remove("atk-flash-once"),window.setTimeout((()=>{this.$el.classList.add("atk-flash-once")}),150)}getChildrenWrap(){return this.$childrenWrap||(this.$childrenWrap=pt('<div class="atk-comment-children"></div>'),this.$main.append(this.$childrenWrap)),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.stopPropagation(),window.open(t)}}setOpenAction(t){this.setOpenable(!0),this.$el.onclick=e=>{e.stopPropagation(),t()}}}class be{constructor(t){c(this,"comment"),this.comment=t}get data(){return this.comment.getData()}get opts(){return this.comment.getOpts()}getApi(){return this.comment.getOpts().getApi()}vote(t){const e="up"===t?this.comment.getRender().voteBtnUp:this.comment.getRender().voteBtnDown;this.getApi().votes.vote(`comment_${t}`,this.data.id,r({},this.getApi().getUserFields())).then((t=>{var e,s;this.data.vote_up=t.data.up,this.data.vote_down=t.data.down,null==(e=this.comment.getRender().voteBtnUp)||e.updateText(),null==(s=this.comment.getRender().voteBtnDown)||s.updateText()})).catch((t=>{null==e||e.setError(At("voteFail")),console.error(t)}))}adminEdit(t,e){if(e.isLoading)return;e.setLoading(!0,`${At("editing")}...`);const s=r({},this.data);"collapsed"===t?s.is_collapsed=!s.is_collapsed:"pending"===t?s.is_pending=!s.is_pending:"pinned"===t&&(s.is_pinned=!s.is_pinned),this.getApi().comments.updateComment(this.data.id,r({},s)).then((t=>{e.setLoading(!1),this.comment.setData(t.data)})).catch((t=>{console.error(t),e.setError(At("editFail"))}))}adminDelete(t){t.isLoading||(t.setLoading(!0,`${At("deleting")}...`),this.getApi().comments.deleteComment(this.data.id).then((()=>{t.setLoading(!1),this.opts.onDelete&&this.opts.onDelete(this.comment)})).catch((e=>{console.error(e),t.setError(At("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 Ce{constructor(t,e){c(this,"$el"),c(this,"renderInstance"),c(this,"actionInstance"),c(this,"data"),c(this,"opts"),c(this,"parent"),c(this,"children",[]),c(this,"nestCurt"),this.opts=e,this.data=r({},t),this.data.date=this.data.date.replace(/-/g,"/"),this.parent=null,this.nestCurt=1,this.actionInstance=new be(this),this.renderInstance=new we(this)}render(){const t=this.renderInstance.render();this.$el&&this.$el.replaceWith(t),this.$el=t,this.opts.onAfterRender&&this.opts.onAfterRender()}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 s=this.getChildrenWrapEl(),n=t.getEl();"append"===e?s.append(n):"prepend"===e&&s.prepend(n),t.getRender().playFadeAnim(),t.getRender().checkHeightLimit()}getChildrenWrapEl(){return this.nestCurt>=this.opts.nestMax?this.parent.getChildrenWrapEl():this.getRender().getChildrenWrap()}getParents(){const t=[];let e=this.parent;for(;e;)t.push(e),e=e.getParent();return t}getEl(){if(!this.$el)throw new Error("comment element not initialized before `getEl()`");return this.$el}focus(){if(!this.$el)throw new Error("comment element not initialized before `focus()`");this.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()})),this.scrollIntoView(),this.getRender().playFlashAnim()}scrollIntoView(){this.$el&&jt(this.$el,!1,this.opts.scrollRelativeTo&&this.opts.scrollRelativeTo())}remove(){var t;null==(t=this.$el)||t.remove()}getGravatarURL(){return`${(t={mirror:this.opts.gravatar.mirror,params:this.opts.gravatar.params,emailHash:this.data.email_encrypted}).mirror.replace(/\/$/,"")}/${t.emailHash}?${t.params.replace(/^\?/,"")}`;var t}getContentMarked(){return dt(this.data.content)}getDateFormatted(){var t,e;const s=new Date(this.data.date);return(null==(e=(t=this.opts).dateFormatter)?void 0:e.call(t,s))||kt(s,At)}getUserUA(){const t=function(t){const e=window||{},s=navigator||{},n=String(t||s.userAgent),i={os:"",osVersion:"",engine:"",browser:"",device:"",language:"",version:""},o={Trident:n.includes("Trident")||n.includes("NET CLR"),Presto:n.includes("Presto"),WebKit:n.includes("AppleWebKit"),Gecko:n.includes("Gecko/")},a={Safari:n.includes("Safari"),Chrome:n.includes("Chrome")||n.includes("CriOS"),IE:n.includes("MSIE")||n.includes("Trident"),Edge:n.includes("Edge")||n.includes("Edg"),Firefox:n.includes("Firefox")||n.includes("FxiOS"),"Firefox Focus":n.includes("Focus"),Chromium:n.includes("Chromium"),Opera:n.includes("Opera")||n.includes("OPR"),Vivaldi:n.includes("Vivaldi"),Yandex:n.includes("YaBrowser"),Kindle:n.includes("Kindle")||n.includes("Silk/"),360:n.includes("360EE")||n.includes("360SE"),UC:n.includes("UC")||n.includes(" UBrowser"),QQBrowser:n.includes("QQBrowser"),QQ:n.includes("QQ/"),Baidu:n.includes("Baidu")||n.includes("BIDUBrowser"),Maxthon:n.includes("Maxthon"),Sogou:n.includes("MetaSr")||n.includes("Sogou"),LBBROWSER:n.includes("LBBROWSER"),"2345Explorer":n.includes("2345Explorer"),TheWorld:n.includes("TheWorld"),MIUI:n.includes("MiuiBrowser"),Quark:n.includes("Quark"),Qiyu:n.includes("Qiyu"),Wechat:n.includes("MicroMessenger"),Taobao:n.includes("AliApp(TB"),Alipay:n.includes("AliApp(AP"),Weibo:n.includes("Weibo"),Douban:n.includes("com.douban.frodo"),Suning:n.includes("SNEBUY-APP"),iQiYi:n.includes("IqiyiApp")},r={Windows:n.includes("Windows"),Linux:n.includes("Linux")||n.includes("X11"),macOS:n.includes("Macintosh"),Android:n.includes("Android")||n.includes("Adr"),Ubuntu:n.includes("Ubuntu"),FreeBSD:n.includes("FreeBSD"),Debian:n.includes("Debian"),"Windows Phone":n.includes("IEMobile")||n.includes("Windows Phone"),BlackBerry:n.includes("BlackBerry")||n.includes("RIM"),MeeGo:n.includes("MeeGo"),Symbian:n.includes("Symbian"),iOS:n.includes("like Mac OS X"),"Chrome OS":n.includes("CrOS"),WebOS:n.includes("hpwOS")},l={Mobile:n.includes("Mobi")||n.includes("iPh")||n.includes("480"),Tablet:n.includes("Tablet")||n.includes("Pad")||n.includes("Nexus 7")};l.Mobile?l.Mobile=!n.includes("iPad"):a.Chrome&&n.includes("Edg")?(a.Chrome=!1,a.Edge=!0):e.showModalDialog&&e.chrome&&(a.Chrome=!1,a[360]=!0),i.device="PC",i.language=(()=>{const t=(s.browserLanguage||s.language).split("-");return t[1]&&(t[1]=t[1].toUpperCase()),t.join("_")})();const c={engine:o,browser:a,os:r,device:l};Object.entries(c).forEach((([t,e])=>{Object.entries(e).forEach((([e,s])=>{!0===s&&(i[t]=e)}))}));const d={Windows:()=>{const t=n.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:()=>n.replace(/^.*Android ([\d.]+);.*$/,"$1"),iOS:()=>n.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,"."),Debian:()=>n.replace(/^.*Debian\/([\d.]+).*$/,"$1"),"Windows Phone":()=>n.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2"),macOS:()=>n.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,"."),WebOS:()=>n.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")};i.osVersion="",d[i.os]&&(i.osVersion=d[i.os](),i.osVersion===n&&(i.osVersion=""));const h={Safari:()=>n.replace(/^.*Version\/([\d.]+).*$/,"$1"),Chrome:()=>n.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1"),IE:()=>n.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1"),Edge:()=>n.replace(/^.*(Edge|Edg|Edg[A-Z]{1})\/([\d.]+).*$/,"$2"),Firefox:()=>n.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1"),"Firefox Focus":()=>n.replace(/^.*Focus\/([\d.]+).*$/,"$1"),Chromium:()=>n.replace(/^.*Chromium\/([\d.]+).*$/,"$1"),Opera:()=>n.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1"),Vivaldi:()=>n.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1"),Yandex:()=>n.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1"),Kindle:()=>n.replace(/^.*Version\/([\d.]+).*$/,"$1"),Maxthon:()=>n.replace(/^.*Maxthon\/([\d.]+).*$/,"$1"),QQBrowser:()=>n.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1"),QQ:()=>n.replace(/^.*QQ\/([\d.]+).*$/,"$1"),Baidu:()=>n.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1"),UC:()=>n.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1"),Sogou:()=>n.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1"),"2345Explorer":()=>n.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1"),TheWorld:()=>n.replace(/^.*TheWorld ([\d.]+).*$/,"$1"),MIUI:()=>n.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1"),Quark:()=>n.replace(/^.*Quark\/([\d.]+).*$/,"$1"),Qiyu:()=>n.replace(/^.*Qiyu\/([\d.]+).*$/,"$1"),Wechat:()=>n.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1"),Taobao:()=>n.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1"),Alipay:()=>n.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1"),Weibo:()=>n.replace(/^.*weibo__([\d.]+).*$/,"$1"),Douban:()=>n.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1"),Suning:()=>n.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1"),iQiYi:()=>n.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")};return i.version="",h[i.browser]&&(i.version=h[i.browser](),i.version===n&&(i.version="")),i.version.indexOf(".")&&(i.version=i.version.substring(0,i.version.indexOf("."))),"iOS"===i.os&&n.includes("iPad")?i.os="iPadOS":"Edge"!==i.browser||n.includes("Edg")?"MIUI"===i.browser?i.os="Android":"Chrome"===i.browser&&Number(i.version)>27||"Opera"===i.browser&&Number(i.version)>12||"Yandex"===i.browser?i.engine="Blink":void 0===i.browser&&(i.browser="Unknow App"):i.engine="EdgeHTML",i}(this.data.ua);return{browser:`${t.browser} ${t.version}`,os:`${t.os} ${t.osVersion}`}}getOpts(){return this.opts}}class xe{constructor(t){c(this,"opts"),c(this,"$el"),c(this,"$loading"),c(this,"$text"),c(this,"offset",0),c(this,"total",0),c(this,"origText","Load More"),this.opts=t,this.origText=this.opts.text||this.origText,this.$el=pt(`<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.opts.pageSize}click(){this.hasMore&&this.opts.onClick(this.offset+this.opts.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()}}class Ee{constructor(){c(this,"instance"),c(this,"onReachedBottom",null),c(this,"opt")}create(t){return this.opt=t,this.instance=new xe({pageSize:t.pageSize,onClick:e=>d(this,null,(function*(){t.ctx.fetch({offset:e})})),text:At("loadMore")}),t.readMoreAutoLoad&&(this.onReachedBottom=()=>{this.instance.hasMore&&!this.opt.ctx.getData().getLoading()&&this.instance.click()},this.opt.ctx.on("list-reach-bottom",this.onReachedBottom)),this.instance.$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()}getHasMore(){return this.instance.hasMore}getIsClearComments(t){return 0===t.offset}dispose(){this.onReachedBottom&&this.opt.ctx.off("list-reach-bottom",this.onReachedBottom),this.instance.$el.remove()}}class Se{constructor(t,e){c(this,"opts"),c(this,"total"),c(this,"$el"),c(this,"$input"),c(this,"inputTimer"),c(this,"$prevBtn"),c(this,"$nextBtn"),c(this,"page",1),this.total=t,this.opts=e,this.$el=pt('<div class="atk-pagination-wrap">\n <div class="atk-pagination">\n <div class="atk-btn atk-btn-prev" aria-label="Previous page">\n <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="14px" width="14px" xmlns="http://www.w3.org/2000/svg"><path d="M217.9 256L345 129c9.4-9.4 9.4-24.6 0-33.9-9.4-9.4-24.6-9.3-34 0L167 239c-9.1 9.1-9.3 23.7-.7 33.1L310.9 417c4.7 4.7 10.9 7 17 7s12.3-2.3 17-7c9.4-9.4 9.4-24.6 0-33.9L217.9 256z"></path></svg>\n </div>\n <input type="text" class="atk-input" aria-label="Enter the number of page" />\n <div class="atk-btn atk-btn-next" aria-label="Next page">\n <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="14px" width="14px" xmlns="http://www.w3.org/2000/svg"><path d="M294.1 256L167 129c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.3 34 0L345 239c9.1 9.1 9.3 23.7.7 33.1L201.1 417c-4.7 4.7-10.9 7-17 7s-12.3-2.3-17-7c-9.4-9.4-9.4-24.6 0-33.9l127-127.1z"></path></svg>\n </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.opts.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(),s=()=>{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?s():this.inputTimer=window.setTimeout((()=>s()),800)}prev(){const t=this.page-1;t<1||this.change(t)}next(){const t=this.page+1;t>this.maxPage||this.change(t)}getHasMore(){return this.page+1<=this.maxPage}change(t){this.page=t,this.opts.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?Dt(this.$el):Rt(this.$el)}}class Te{constructor(){c(this,"instance")}create(t){return this.instance=new Se(t.total,{pageSize:t.pageSize,onChange:e=>d(this,null,(function*(){t.ctx.editorResetState(),t.ctx.fetch({offset:e,onSuccess:()=>{t.ctx.listGotoFirst()}})}))}),this.instance.$el}setLoading(t){this.instance.setLoading(t)}update(t,e){this.instance.update(t,e)}next(){this.instance.next()}getHasMore(){return this.instance.getHasMore()}getIsClearComments(){return!0}dispose(){this.instance.$el.remove()}}function Le(t){const e=t.getData().getListLastFetch(),s={offset:0,total:0};return e?(s.offset=e.params.offset,e.data&&(s.total=e.params.flatMode?e.data.count:e.data.roots_count),s):s}const Ae=t=>{let e=null;t.watchConf(["pagination","locale"],(s=>{const n=t.get("list");e&&e.dispose(),e=function(t){return t.pagination.readMore?new Ee:new Te}(s);const{offset:i,total:o}=Le(t),a=e.create({ctx:t,pageSize:s.pagination.pageSize,total:o,readMoreAutoLoad:s.pagination.autoLoad});n.$commentsWrap.after(a),null==e||e.update(i,o)})),t.on("list-loaded",(s=>{const{offset:n,total:i}=Le(t);null==e||e.update(n,i)})),t.on("list-fetch",(s=>{t.getData().getComments().length>0&&(null==e?void 0:e.getIsClearComments(s))&&t.getData().clearComments()})),t.on("list-failed",(()=>{var t;null==(t=null==e?void 0:e.showErr)||t.call(e,At("loadFail"))})),t.on("list-fetch",(t=>{null==e||e.setLoading(!0)})),t.on("list-fetched",(({params:t})=>{null==e||e.setLoading(!1)}))};class Me extends Kt{constructor(t){super(t),c(this,"$commentsWrap"),c(this,"commentNodes",[]),this.$el=pt('<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">\n <div class="atk-list-comments-wrap"></div>\n </div>\n <div class="atk-list-footer">\n <div class="atk-copyright"></div>\n </div>\n</div>\n'),this.$commentsWrap=this.$el.querySelector(".atk-list-comments-wrap"),Ae(t),this.initCrudEvents()}getCommentsWrapEl(){return this.$commentsWrap}getCommentNodes(){return this.commentNodes}getListLayout({forceFlatMode:t}={}){return new ne({$commentsWrap:this.$commentsWrap,nestSortBy:this.ctx.conf.nestSort,nestMax:this.ctx.conf.nestMax,flatMode:"boolean"==typeof t?t:this.ctx.conf.flatMode,createCommentNode:(e,s)=>{const n=function(t,e,s,n){const i=new Ce(e,{onAfterRender:()=>{t.trigger("comment-rendered",i)},onDelete:e=>{t.getData().deleteComment(e.getID())},replyTo:s,flatMode:"boolean"==typeof(null==n?void 0:n.forceFlatMode)?null==n?void 0:n.forceFlatMode:t.conf.flatMode,gravatar:t.conf.gravatar,nestMax:t.conf.nestMax,heightLimit:t.conf.heightLimit,avatarURLBuilder:t.conf.avatarURLBuilder,scrollRelativeTo:t.conf.scrollRelativeTo,vote:t.conf.vote,voteDown:t.conf.voteDown,uaBadge:t.conf.uaBadge,dateFormatter:t.conf.dateFormatter,getApi:()=>t.getApi(),replyComment:(e,s)=>t.replyComment(e,s),editComment:(e,s)=>t.editComment(e,s)});return i.render(),i}(this.ctx,e,s,{forceFlatMode:t});return this.commentNodes.push(n),n},findCommentNode:t=>this.commentNodes.find((e=>e.getID()===t))})}initCrudEvents(){this.ctx.on("list-load",(t=>{this.getListLayout().import(t)})),this.ctx.on("list-loaded",(t=>{0===t.length&&(this.commentNodes=[],this.$commentsWrap.innerHTML="")})),this.ctx.on("comment-inserted",(t=>{var e;const s=t.rid?null==(e=this.commentNodes.find((e=>e.getID()===t.rid)))?void 0:e.getData():void 0;this.getListLayout().insert(t,s)})),this.ctx.on("comment-deleted",(t=>{const e=this.commentNodes.find((e=>e.getID()===t.id));e?(e.remove(),this.commentNodes=this.commentNodes.filter((e=>e.getID()!==t.id))):console.error(`comment node id=${t.id} not found`)})),this.ctx.on("comment-updated",(t=>{const e=this.commentNodes.find((e=>e.getID()===t.id));e&&e.setData(t)}))}}let Pe,Ue;function Ie(){return{init(){Pe=document.body.style.overflow,Ue=document.body.style.paddingRight},unlock(){document.body.style.overflow=Pe,document.body.style.paddingRight=Ue},lock(){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 s=t.offsetWidth;e.style.overflow="scroll";let n=t.offsetWidth;return s===n&&(n=e.clientWidth),document.body.removeChild(e),s-n}()+t||0}px`}}}class Oe{constructor(t,e){c(this,"allowMaskClose",!0),c(this,"onAfterHide"),this.$el=t,this.opts=e}setOnAfterHide(t){this.onAfterHide=t}setAllowMaskClose(t){this.allowMaskClose=t}getAllowMaskClose(){return this.allowMaskClose}getEl(){return this.$el}show(){this.opts.onShow(),this.$el.style.display=""}hide(){this.opts.onHide(),this.$el.style.display="none",this.onAfterHide&&this.onAfterHide()}destroy(){this.opts.onHide(),this.$el.remove(),this.onAfterHide&&this.onAfterHide()}}class qe{constructor(){c(this,"$wrap"),c(this,"$mask"),c(this,"items",[]),this.$wrap=pt('<div class="atk-layer-wrap" style="display: none;"><div class="atk-layer-mask"></div></div>'),this.$mask=this.$wrap.querySelector(".atk-layer-mask")}createItem(t,e){(e=e||this.createItemElement(t)).setAttribute("data-layer-name",t),this.$wrap.appendChild(e);const s=new Oe(e,{onHide:()=>this.hideWrap(e),onShow:()=>this.showWrap()});return this.getMask().addEventListener("click",(()=>{s.getAllowMaskClose()&&s.hide()})),this.items.push(s),s}createItemElement(t){const e=document.createElement("div");return e.classList.add("atk-layer-item"),e.style.display="none",this.$wrap.appendChild(e),e}getWrap(){return this.$wrap}getMask(){return this.$mask}showWrap(){this.$wrap.style.display="block",this.$mask.style.display="block",this.$mask.classList.add("atk-fade-in"),Ie().lock()}hideWrap(t){this.items.map((t=>t.getEl())).filter((e=>e!==t&&e.isConnected&&"none"!==e.style.display)).length>0||(this.$wrap.style.display="none",Ie().unlock())}}class De{constructor(t){c(this,"wrap"),this.wrap=new qe,document.body.appendChild(this.wrap.getWrap()),t.on("unmounted",(()=>{this.wrap.getWrap().remove()})),Ie().init()}getEl(){return this.wrap.getWrap()}create(t,e){return this.wrap.createItem(t,e)}}const Re="ArtalkUser";class Be{constructor(t){c(this,"data"),this.opts=t;const e=JSON.parse(window.localStorage.getItem(Re)||"{}");this.data={name:e.name||e.nick||"",email:e.email||"",link:e.link||"",token:e.token||"",is_admin:e.is_admin||e.isAdmin||!1}}getData(){return this.data}update(t={}){Object.entries(t).forEach((([t,e])=>{this.data[t]=e})),window.localStorage.setItem(Re,JSON.stringify(this.data)),this.opts.onUserChanged&&this.opts.onUserChanged(this.data)}logout(){this.update({token:"",is_admin:!1})}checkHasBasicUserInfo(){return!!this.data.name&&!!this.data.email}}const je={i18n(t){Lt(t.conf.locale),t.watchConf(["locale"],(t=>{Lt(t.locale)}))},user:t=>new Be({onUserChanged:e=>{t.trigger("user-changed",e)}}),layerManager:t=>new De(t),checkerLauncher:t=>new Gt({getCtx:()=>t,getApi:()=>t.getApi(),onReload:()=>t.reload(),getCaptchaIframeURL:()=>`${t.conf.server}/api/v2/captcha/?t=${+new Date}`}),editor(t){const e=new Zt(t);return t.$root.appendChild(e.$el),e},list(t){const e=new Me(t);return t.$root.appendChild(e.$el),e},sidebarLayer:t=>new te(t),editorPlugs(){}};function Fe(t){return d(this,null,(function*(){yield function(t){return d(this,null,(function*(){yield _e({opt:t,query:"page_comment",containers:[t.countEl,"#ArtalkCount"]})}))}(t);const e=yield function(t){return d(this,null,(function*(){if(!t.pvAdd||!t.pageKey)return;const e=(yield t.getApi().pages.logPv({page_key:t.pageKey,page_title:t.pageTitle,site_name:t.siteName})).data.pv;return{[t.pageKey]:e}}))}(t);yield function(t,e){return d(this,null,(function*(){yield _e({opt:t,query:"page_pv",containers:[t.pvEl,"#ArtalkPV"],cache:e})}))}(t,e)}))}function _e(t){return d(this,null,(function*(){const{opt:e}=t;let s=t.cache||{};const n=function(t){const e=new Set;return new Set(t).forEach((t=>{document.querySelectorAll(t).forEach((t=>e.add(t)))})),e}(t.containers),i=function(t,e,s,n){const i=Array.from(t).map((t=>t.getAttribute(e)||s)).filter((t=>t&&"number"!=typeof n[t]));return[...new Set(i)]}(n,e.pageKeyAttr,e.pageKey,s);if(i.length>0){const n=(yield e.getApi().stats.getStats(t.query,{page_keys:i.join(","),site_name:e.siteName})).data.data;s=r(r({},s),n)}!function(t,e,s){t.forEach((t=>{const n=t.getAttribute("data-page-key"),i=n&&e[n]||s&&e[s]||0;t.innerText=`${Number(i)}`}))}(n,s,e.pageKey)}))}const We="ArtalkContent";class Ne{constructor(t){this.kit=t}reqAdd(){return d(this,null,(function*(){return(yield this.kit.useApi().comments.createComment(r({},yield this.getSubmitAddParams()))).data}))}getSubmitAddParams(){return d(this,null,(function*(){const{name:t,email:e,link:s}=this.kit.useUser().getData(),n=this.kit.useConf();return{content:this.kit.useEditor().getContentFinal(),name:t,email:e,link:s,rid:0,page_key:n.pageKey,page_title:n.pageTitle,site_name:n.site,ua:yield vt()}}))}postSubmitAdd(t){this.kit.useGlobalCtx().getData().insertComment(t)}}class He extends Yt{constructor(t){super(t),c(this,"customs",[]),c(this,"defaultPreset"),this.defaultPreset=new Ne(this.kit);const e=()=>this.do();this.kit.useMounted((()=>{this.kit.useGlobalCtx().on("editor-submit",e)})),this.kit.useUnmounted((()=>{this.kit.useGlobalCtx().off("editor-submit",e)}))}registerCustom(t){this.customs.push(t)}do(){return d(this,null,(function*(){if(""===this.kit.useEditor().getContentFinal().trim())return void this.kit.useEditor().focus();const t=this.customs.find((t=>t.activeCond()));this.kit.useEditor().showLoading();try{let e;(null==t?void 0:t.pre)&&t.pre(),e=(null==t?void 0:t.req)?yield t.req():yield this.defaultPreset.reqAdd(),(null==t?void 0:t.post)?t.post(e):this.defaultPreset.postSubmitAdd(e)}catch(e){return console.error(e),void this.kit.useEditor().showNotify(`${At("commentFail")}: ${e.message||String(e)}`,"e")}finally{this.kit.useEditor().hideLoading()}this.kit.useEditor().reset(),this.kit.useGlobalCtx().trigger("editor-submitted")}))}}class ze extends Yt{constructor(t){super(t),c(this,"emoticons",[]),c(this,"loadingTask",null),c(this,"$grpWrap"),c(this,"$grpSwitcher"),c(this,"isListLoaded",!1),c(this,"isImgLoaded",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-emoticons"></div>'),this.useBtn(`<i aria-label="${At("emoticon")}"><svg fill="currentColor" aria-hidden="true" height="14" viewBox="0 0 14 14" width="14"><path d="m4.26829 5.29294c0-.94317.45893-1.7074 1.02439-1.7074.56547 0 1.02439.76423 1.02439 1.7074s-.45892 1.7074-1.02439 1.7074c-.56546 0-1.02439-.76423-1.02439-1.7074zm4.43903 1.7074c.56546 0 1.02439-.76423 1.02439-1.7074s-.45893-1.7074-1.02439-1.7074c-.56547 0-1.02439.76423-1.02439 1.7074s.45892 1.7074 1.02439 1.7074zm-1.70732 2.73184c-1.51883 0-2.06312-1.52095-2.08361-1.58173l-1.29551.43231c.03414.10244.868 2.51604 3.3798 2.51604 2.51181 0 3.34502-2.41291 3.37982-2.51604l-1.29484-.43573c-.02254.06488-.56683 1.58583-2.08498 1.58583zm7-2.73252c0 3.86004-3.1401 7.00034-7 7.00034s-7-3.1396-7-6.99966c0-3.86009 3.1401-7.00034 7-7.00034s7 3.14025 7 7.00034zm-1.3659 0c0-3.10679-2.5275-5.63442-5.6341-5.63442-3.10663 0-5.63415 2.52832-5.63415 5.6351 0 3.10676 2.52752 5.63446 5.63415 5.63446 3.1066 0 5.6341-2.5277 5.6341-5.63446z"/></svg></i>`)})),this.kit.useUnmounted((()=>{})),this.useContentTransformer((t=>this.transEmoticonImageText(t))),this.usePanelShow((()=>{(()=>{d(this,null,(function*(){yield this.loadEmoticonsData(),this.isImgLoaded||(this.initEmoticonsList(),this.isImgLoaded=!0),setTimeout((()=>{this.changeListHeight()}),30)}))})()})),this.usePanelHide((()=>{this.$panel.parentElement.style.height=""})),window.setTimeout((()=>{this.loadEmoticonsData()}),1e3)}loadEmoticonsData(){return d(this,null,(function*(){this.isListLoaded||(null===this.loadingTask?(this.loadingTask=(()=>d(this,null,(function*(){Dt(this.$panel),this.emoticons=yield this.handleData(this.kit.useConf().emoticons),Rt(this.$panel),this.loadingTask=null,this.isListLoaded=!0})))(),yield this.loadingTask):yield this.loadingTask)}))}handleData(t){return d(this,null,(function*(){if(!Array.isArray(t)&&["object","string"].includes(typeof t)&&(t=[t]),!Array.isArray(t))return _t(this.$panel,`[${At("emoticon")}] Data must be of Array/Object/String type`),Rt(this.$panel),[];const e=e=>{"object"==typeof e&&(e.name&&t.find((t=>t.name===e.name))||t.push(e))},s=t=>d(this,null,(function*(){yield Promise.all(t.map(((t,n)=>d(this,null,(function*(){if("object"!=typeof t||Array.isArray(t)){if(Array.isArray(t))yield s(t);else if("string"==typeof t){const n=yield this.remoteLoad(t);Array.isArray(n)?yield s(n):"object"==typeof n&&e(n)}}else e(t)})))))}));return yield s(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 d(this,null,(function*(){if(!t)return[];try{const e=yield fetch(t);return yield e.json()}catch(e){return Rt(this.$panel),console.error("[Emoticons] Load Failed:",e),_t(this.$panel,`[${At("emoticon")}] ${At("loadFail")}: ${String(e)}`),[]}}))}solveNullKey(t){t.forEach((t=>{t.items.forEach(((e,s)=>{e.key||(e.key=`${t.name} ${s+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,s])=>{const n={name:t,type:s.type,items:[]};s.container.forEach(((e,s)=>{const i=e.icon;if(/<(img|IMG)/.test(i)){const t=/src=["'](.*?)["']/.exec(i);t&&t.length>1&&(e.icon=t[1])}n.items.push({key:e.text||`${t} ${s+1}`,val:e.icon})})),e.push(n)})),e}initEmoticonsList(){this.$grpWrap=pt('<div class="atk-grp-wrap"></div>'),this.$panel.append(this.$grpWrap),this.emoticons.forEach(((t,e)=>{const s=pt('<div class="atk-grp" style="display: none;"></div>');this.$grpWrap.append(s),s.setAttribute("data-index",String(e)),s.setAttribute("data-grp-name",t.name),s.setAttribute("data-type",t.type),t.items.forEach((e=>{const n=pt('<span class="atk-item"></span>');if(s.append(n),e.key&&!new RegExp(`^(${t.name})?\\s?[0-9]+$`).test(e.key)&&n.setAttribute("title",e.key),"image"===t.type){const t=document.createElement("img");t.src=e.val,t.alt=e.key,n.append(t)}else n.innerText=e.val;n.onclick=()=>{"image"===t.type?this.kit.useEditor().insertContent(`:[${e.key}]`):this.kit.useEditor().insertContent(e.val||"")}}))})),this.emoticons.length>1&&(this.$grpSwitcher=pt('<div class="atk-grp-switcher"></div>'),this.$panel.append(this.$grpSwitcher),this.emoticons.forEach(((t,e)=>{const s=pt("<span />");s.innerText=t.name,s.setAttribute("data-index",String(e)),s.onclick=()=>this.openGrp(e),this.$grpSwitcher.append(s)}))),this.emoticons.length>0&&this.openGrp(0)}openGrp(t){var e,s,n;Array.from(this.$grpWrap.children).forEach((e=>{const s=e;s.getAttribute("data-index")!==String(t)?s.style.display="none":s.style.display=""})),null==(e=this.$grpSwitcher)||e.querySelectorAll("span.active").forEach((t=>t.classList.remove("active"))),null==(n=null==(s=this.$grpSwitcher)?void 0:s.querySelector(`span[data-index="${t}"]`))||n.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,s])=>{t=t.split(`:[${s.key}]`).join(`<img src="${s.val}" atk-emoticon="${s.key}">`)}))})),t):t}}const Ve=["png","jpg","jpeg","gif","bmp","svg","webp"];class Ge extends Yt{constructor(t){super(t),c(this,"$imgUploadInput"),this.kit.useMounted((()=>this.init())),this.initDragImg()}init(){this.$imgUploadInput=document.createElement("input"),this.$imgUploadInput.type="file",this.$imgUploadInput.style.display="none",this.$imgUploadInput.accept=Ve.map((t=>`.${t}`)).join(",");const t=this.useBtn(`<i aria-label="${At("uploadImage")}"><svg fill="currentColor" aria-hidden="true" height="14" viewBox="0 0 14 14" width="14"><path d="m0 1.94444c0-1.074107.870333-1.94444 1.94444-1.94444h10.11116c1.0741 0 1.9444.870333 1.9444 1.94444v10.11116c0 1.0741-.8703 1.9444-1.9444 1.9444h-10.11116c-1.074107 0-1.94444-.8703-1.94444-1.9444zm1.94444-.38888c-.21466 0-.38888.17422-.38888.38888v7.06689l2.33333-2.33333 2.33333 2.33333 3.88888-3.88889 2.3333 2.33334v-5.51134c0-.21466-.1742-.38888-.3888-.38888zm10.49996 8.09977-2.3333-2.33333-3.88888 3.8889-2.33333-2.33334-2.33333 2.33334v.8447c0 .2146.17422.3888.38888.3888h10.11116c.2146 0 .3888-.1742.3888-.3888zm-7.1944-6.54422c-.75133 0-1.36111.60978-1.36111 1.36111 0 .75134.60978 1.36111 1.36111 1.36111s1.36111-.60977 1.36111-1.36111c0-.75133-.60978-1.36111-1.36111-1.36111z"/></svg></i>`);t.after(this.$imgUploadInput),t.onclick=()=>{const t=this.$imgUploadInput;t.onchange=()=>{(()=>{d(this,null,(function*(){if(!t.files||0===t.files.length)return;const e=t.files[0];this.uploadImg(e)}))})()},t.click()},this.kit.useConf().imgUpload||this.$btn.setAttribute("atk-only-admin-show","")}initDragImg(){const t=t=>{if(t)for(let e=0;e<t.length;e++){const s=t[e];this.uploadImg(s)}},e=t=>{t.stopPropagation(),t.preventDefault()},s=e=>{var s;const n=null==(s=e.dataTransfer)?void 0:s.files;(null==n?void 0:n.length)&&(e.preventDefault(),t(n))},n=e=>{var s;const n=null==(s=e.clipboardData)?void 0:s.files;(null==n?void 0:n.length)&&(e.preventDefault(),t(n))};this.kit.useMounted((()=>{this.kit.useUI().$textarea.addEventListener("dragover",e),this.kit.useUI().$textarea.addEventListener("drop",s),this.kit.useUI().$textarea.addEventListener("paste",n)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("dragover",e),this.kit.useUI().$textarea.removeEventListener("drop",s),this.kit.useUI().$textarea.removeEventListener("paste",n)}))}uploadImg(t){return d(this,null,(function*(){const e=/[^.]+$/.exec(t.name);if(!e||!Ve.includes(String(e[0]).toLowerCase()))return;if(!this.kit.useUser().checkHasBasicUserInfo())return void this.kit.useEditor().showNotify(At("uploadLoginMsg"),"w");let s="\n";""===this.kit.useUI().$textarea.value.trim()&&(s="");const n=`${s}`;let i;this.kit.useEditor().insertContent(n);try{const e=this.kit.useConf().imgUploader;i=e?{public_url:yield e(t)}:(yield this.kit.useApi().upload.upload({file:t})).data}catch(o){console.error(o),this.kit.useEditor().showNotify(`${At("uploadFail")}: ${o.message}`,"e")}if(i&&i.public_url){let t=i.public_url;$t(t)||(t=wt({base:this.kit.useConf().server,path:t})),this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(n,`${s}`))}else this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(n,""))}))}}class Ke extends Yt{constructor(t){super(t),c(this,"isPlugPanelShow",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-preview"></div>'),this.useBtn(`<i aria-label="${At("preview")}"><svg fill="currentColor" aria-hidden="true" viewBox="0 0 16 16" width="16" height="16"><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.kit.useUnmounted((()=>{})),this.kit.useEvents().on("content-updated",(t=>{this.isPlugPanelShow&&this.updateContent()})),this.usePanelShow((()=>{this.isPlugPanelShow=!0,this.updateContent()})),this.usePanelHide((()=>{this.isPlugPanelShow=!1}))}updateContent(){this.$panel.innerHTML=this.kit.useEditor().getContentMarked()}}const Qe=[class extends Yt{constructor(t){super(t);const e=()=>{this.save()};this.kit.useMounted((()=>{const t=window.localStorage.getItem(We)||"";""!==t.trim()&&(this.kit.useEditor().showNotify(At("restoredMsg"),"i"),this.kit.useEditor().setContent(t)),this.kit.useEvents().on("content-updated",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("content-updated",e)}))}save(){window.localStorage.setItem(We,this.kit.useEditor().getContentRaw().trim())}},class extends Yt{get $inputs(){return this.kit.useEditor().getHeaderInputEls()}constructor(t){super(t);const e={},s={},n=(t,e,s)=>()=>{this.kit.useEvents().trigger(t,{field:s,$input:e})};this.kit.useMounted((()=>{Object.entries(this.$inputs).forEach((([t,i])=>{i.addEventListener("input",e[t]=n("header-input",i,t)),i.addEventListener("change",s[t]=n("header-change",i,t))}))})),this.kit.useUnmounted((()=>{Object.entries(this.$inputs).forEach((([t,n])=>{n.removeEventListener("input",e[t]),n.removeEventListener("change",s[t])}))}))}},class extends Yt{constructor(t){super(t),c(this,"query",{timer:null,abortFn:null});const e=({$input:t,field:e})=>{"edit"!==this.kit.useEditor().getState()&&(this.kit.useUser().update({[e]:t.value.trim()}),"name"!==e&&"email"!==e||this.fetchUserInfo())},s={name:At("nick"),email:At("email"),link:At("link")};this.kit.useMounted((()=>{Object.entries(this.kit.useEditor().getHeaderInputEls()).forEach((([t,e])=>{e.placeholder=s[t],e.value=this.kit.useUser().getData()[t]||""})),this.kit.useEvents().on("header-input",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-input",e)}))}fetchUserInfo(){this.kit.useUser().logout(),this.query.timer&&window.clearTimeout(this.query.timer),this.query.abortFn&&this.query.abortFn(),this.query.timer=window.setTimeout((()=>{this.query.timer=null;const t=this.kit.useApi(),e="getUserCancelToken";this.query.abortFn=()=>t.abortRequest(e),t.user.getUser(r({},t.getUserFields()),{cancelToken:e}).then((t=>this.onUserInfoFetched(t.data))).catch((t=>{})).finally((()=>{this.query.abortFn=null}))}),400)}onUserInfoFetched(t){var e;t.is_login||this.kit.useUser().logout(),this.kit.useGlobalCtx().getData().updateNotifies(t.notifies),this.kit.useUser().checkHasBasicUserInfo()&&!t.is_login&&(null==(e=t.user)?void 0:e.is_admin)&&this.kit.useGlobalCtx().checkAdmin({onSuccess:()=>{}}),t.user&&t.user.link&&(this.kit.useUI().$link.value=t.user.link,this.kit.useUser().update({link:t.user.link}))}},class extends Yt{constructor(t){super(t);const e=({field:t})=>{"link"===t&&this.onLinkInputChange()};this.kit.useMounted((()=>{this.kit.useEvents().on("header-change",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-change",e)}))}onLinkInputChange(){const t=this.kit.useUI().$link.value.trim();t&&!/^(http|https):\/\//.test(t)&&(this.kit.useUI().$link.value=`https://${t}`,this.kit.useUser().update({link:this.kit.useUI().$link.value}))}},class extends Yt{constructor(t){super(t);const e=t=>this.onKeydown(t),s=()=>this.onInput();this.kit.useMounted((()=>{this.kit.useUI().$textarea.placeholder=this.kit.useConf().placeholder||At("placeholder"),this.kit.useUI().$textarea.addEventListener("keydown",e),this.kit.useUI().$textarea.addEventListener("input",s)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("keydown",e),this.kit.useUI().$textarea.removeEventListener("input",s)})),this.kit.useEvents().on("content-updated",(()=>{window.setTimeout((()=>{this.adaptiveHeightByContent()}),80)}))}onKeydown(t){9===(t.keyCode||t.which)&&(t.preventDefault(),this.kit.useEditor().insertContent("\t"))}onInput(){this.kit.useEvents().trigger("content-updated",this.kit.useEditor().getContentRaw())}adaptiveHeightByContent(){const t=this.kit.useUI().$textarea.offsetHeight-this.kit.useUI().$textarea.clientHeight;this.kit.useUI().$textarea.style.height="0px",this.kit.useUI().$textarea.style.height=`${this.kit.useUI().$textarea.scrollHeight+t}px`}},He,class extends Yt{constructor(t){super(t);const e=()=>{this.kit.useEditor().submit()};this.kit.useMounted((()=>{this.kit.useUI().$submitBtn.innerText=this.kit.useConf().sendBtn||At("send"),this.kit.useUI().$submitBtn.addEventListener("click",e)})),this.kit.useUnmounted((()=>{this.kit.useUI().$submitBtn.removeEventListener("click",e)}))}},Jt,class extends Yt{constructor(t){super(t),c(this,"comment"),this.useEditorStateEffect("reply",(t=>(this.setReply(t),()=>{this.cancelReply()}))),this.kit.useEvents().on("mounted",(()=>{const t=this.kit.useDeps(He);if(!t)throw Error("SubmitPlug not initialized");const e=new Ne(this.kit);t.registerCustom({activeCond:()=>!!this.comment,req:()=>d(this,null,(function*(){if(!this.comment)throw new Error("reply comment cannot be empty");return(yield this.kit.useApi().comments.createComment(l(r({},yield e.getSubmitAddParams()),{rid:this.comment.id,page_key:this.comment.page_key,page_title:void 0,site_name:this.comment.site_name}))).data})),post:t=>{const s=this.kit.useConf();t.page_key!==s.pageKey&&window.open(`${t.page_url}#atk-comment-${t.id}`),e.postSubmitAdd(t)}})}))}setReply(t){const e=this.kit.useUI();if(!e.$sendReplyBtn){const s=pt(`<span class="atk-state-btn"><span class="atk-text-wrap">${At("reply")} <span class="atk-text"></span></span><span class="atk-cancel atk-icon-close atk-icon"></span></span>`);s.querySelector(".atk-text").innerText=`@${t.nick}`,s.addEventListener("click",(()=>{this.kit.useEditor().resetState()})),e.$stateWrap.append(s),e.$sendReplyBtn=s}this.comment=t,e.$textarea.focus()}cancelReply(){if(!this.comment)return;const t=this.kit.useUI();t.$sendReplyBtn&&(t.$sendReplyBtn.remove(),t.$sendReplyBtn=void 0),this.comment=void 0}},class extends Yt{constructor(t){super(t),c(this,"comment"),c(this,"originalSubmitBtnText","Send"),this.useEditorStateEffect("edit",(t=>(this.edit(t),()=>{this.cancelEdit()}))),this.kit.useMounted((()=>{const t=this.kit.useDeps(He);if(!t)throw Error("SubmitPlug not initialized");t.registerCustom({activeCond:()=>!!this.comment,req:()=>d(this,null,(function*(){const t={content:this.kit.useEditor().getContentFinal(),nick:this.kit.useUI().$name.value,email:this.kit.useUI().$email.value,link:this.kit.useUI().$link.value},e=this.comment;return(yield this.kit.useApi().comments.updateComment(e.id,r(r({},e),t))).data})),post:t=>{this.kit.useGlobalCtx().getData().updateComment(t)}})}))}edit(t){const e=this.kit.useUI();if(!e.$editCancelBtn){const t=pt(`<span class="atk-state-btn"><span class="atk-text-wrap">${At("editCancel")}</span><span class="atk-cancel atk-icon-close atk-icon"></span></span>`);t.onclick=()=>{this.kit.useEditor().resetState()},e.$stateWrap.append(t),e.$editCancelBtn=t}this.comment=t,e.$header.style.display="none",e.$name.value=t.nick||"",e.$email.value=t.email||"",e.$link.value=t.link||"",this.kit.useEditor().setContent(t.content),e.$textarea.focus(),this.updateSubmitBtnText(At("save"))}cancelEdit(){if(!this.comment)return;const t=this.kit.useUI();t.$editCancelBtn&&(t.$editCancelBtn.remove(),t.$editCancelBtn=void 0),this.comment=void 0;const{name:e,email:s,link:n}=this.kit.useUser().getData();t.$name.value=e,t.$email.value=s,t.$link.value=n,this.kit.useEditor().setContent(""),this.restoreSubmitBtnText(),t.$header.style.display=""}updateSubmitBtnText(t){this.originalSubmitBtnText=this.kit.useUI().$submitBtn.innerText,this.kit.useUI().$submitBtn.innerText=t}restoreSubmitBtnText(){this.kit.useUI().$submitBtn.innerText=this.originalSubmitBtnText}},class extends Yt{constructor(t){super(t);const e=()=>this.open(),s=()=>this.close();this.kit.useMounted((()=>{this.kit.useEvents().on("editor-open",e),this.kit.useEvents().on("editor-close",s)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("editor-open",e),this.kit.useEvents().off("editor-close",s)}))}open(){var t;null==(t=this.kit.useUI().$textareaWrap.querySelector(".atk-comment-closed"))||t.remove(),this.kit.useUI().$textarea.style.display="",this.kit.useUI().$bottom.style.display=""}close(){this.kit.useUI().$textareaWrap.querySelector(".atk-comment-closed")||this.kit.useUI().$textareaWrap.prepend(pt(`<div class="atk-comment-closed">${At("onlyAdminCanReply")}</div>`)),this.kit.useUser().getData().is_admin?(this.kit.useUI().$textarea.style.display="",this.kit.useUI().$bottom.style.display=""):(this.kit.useUI().$textarea.style.display="none",this.kit.useEvents().trigger("panel-close"),this.kit.useUI().$bottom.style.display="none")}},ze,Ge,Ke];class Ye{constructor(t){this.plugs=t}useEditor(){return this.plugs.editor}useGlobalCtx(){return this.plugs.editor.ctx}useConf(){return this.plugs.editor.ctx.conf}useApi(){return this.plugs.editor.ctx.getApi()}useUser(){return this.plugs.editor.ctx.get("user")}useUI(){return this.plugs.editor.getUI()}useEvents(){return this.plugs.getEvents()}useMounted(t){this.useEvents().on("mounted",t)}useUnmounted(t){this.useEvents().on("unmounted",t)}useDeps(t){return this.plugs.get(t)}}class Je{constructor(t){c(this,"plugs",[]),c(this,"openedPlug",null),c(this,"events",new Mt),this.editor=t;let e=!1;this.editor.ctx.watchConf(["imgUpload","emoticons","preview","editorTravel","locale"],(t=>{e&&this.getEvents().trigger("unmounted"),this.clear(),function(t){const e=new Map;return e.set(Ge,t.imgUpload),e.set(ze,t.emoticons),e.set(Ke,t.preview),e.set(Jt,t.editorTravel),Qe.filter((t=>!e.has(t)||!!e.get(t)))}(t).forEach((t=>{const e=new Ye(this);this.plugs.push(new t(e))})),this.getEvents().trigger("mounted"),e=!0,this.loadPluginUI()})),this.events.on("panel-close",(()=>this.closePlugPanel()))}getPlugs(){return this.plugs}getEvents(){return this.events}clear(){this.plugs=[],this.events=new Mt,this.openedPlug&&this.closePlugPanel()}loadPluginUI(){this.editor.getUI().$plugPanelWrap.innerHTML="",this.editor.getUI().$plugPanelWrap.style.display="none",this.editor.getUI().$plugBtnWrap.innerHTML="",this.plugs.forEach((t=>this.loadPluginItem(t)))}loadPluginItem(t){const e=t.$btn;if(!e)return;this.editor.getUI().$plugBtnWrap.appendChild(e),!e.onclick&&(e.onclick=()=>{this.editor.getUI().$plugBtnWrap.querySelectorAll(".active").forEach((t=>t.classList.remove("active"))),t!==this.openedPlug?(this.openPlugPanel(t),e.classList.add("active")):this.closePlugPanel()});const s=t.$panel;s&&(s.style.display="none",this.editor.getUI().$plugPanelWrap.appendChild(s))}get(t){return this.plugs.find((e=>e instanceof t))}openPlugPanel(t){this.plugs.forEach((e=>{const s=e.$panel;s&&(e===t?(s.style.display="",this.events.trigger("panel-show",t)):(s.style.display="none",this.events.trigger("panel-hide",t)))})),this.editor.getUI().$plugPanelWrap.style.display="",this.openedPlug=t}closePlugPanel(){this.openedPlug&&(this.editor.getUI().$plugPanelWrap.style.display="none",this.events.trigger("panel-hide",this.openedPlug),this.openedPlug=null)}getTransformedContent(t){let e=t;return this.plugs.forEach((t=>{t.contentTransformer&&(e=t.contentTransformer(e))})),e}}const Xe="2.9.1";function Ze(t){const e=pt('<span><span class="error-message"></span><br/><br/></span>');if(e.querySelector(".error-message").innerText=`${At("listLoadFailMsg")}\n${t.errMsg}`,t.retryFn){const s=pt(`<span style="cursor:pointer;">${At("listRetry")}</span>`);s.onclick=()=>t.retryFn&&t.retryFn(),e.appendChild(s)}if(t.onOpenSidebar){const s=pt(`<span atk-only-admin-show> | <span style="cursor:pointer;">${At("openName",{name:At("ctrlCenter")})}</span></span>`);e.appendChild(s),s.onclick=()=>t.onOpenSidebar&&t.onOpenSidebar()}_t(t.$err,e)}let ts=!1;let es;function ss(t,e){const s="atk-dark-mode";t.forEach((t=>{e?t.classList.add(s):t.classList.remove(s)}))}const ns=[t=>{t.watchConf(["imgLazyLoad","markedOptions"],(e=>{!function(t){try{if(!h.Marked.name)return}catch(s){return}const e=new h.Marked;e.setOptions(r(r({renderer:st({imgLazyLoad:t.imgLazyLoad})},lt),t.markedOptions)),at=e}({markedOptions:t.getConf().markedOptions,imgLazyLoad:t.getConf().imgLazyLoad})})),t.watchConf(["markedReplacers"],(t=>{var e;t.markedReplacers&&(e=t.markedReplacers,rt=e)}))},t=>{const e=t.get("editor"),s=new Je(e);t.inject("editorPlugs",s)},t=>{const e=()=>{var e;e=t.get("user").getData().is_admin,function(t){const e=[];t.$root.querySelectorAll("[atk-only-admin-show]").forEach((t=>e.push(t)));const s=document.querySelector(".atk-sidebar");return s&&s.querySelectorAll("[atk-only-admin-show]").forEach((t=>e.push(t))),e}({$root:t.$root}).forEach((t=>{e?t.classList.remove("atk-hide"):t.classList.add("atk-hide")}))};t.on("list-loaded",(()=>{e()})),t.on("user-changed",(t=>{e()}))},...[t=>{t.on("list-fetch",(e=>{if(t.getData().getLoading())return;t.getData().setLoading(!0);const s=r({offset:0,limit:t.conf.pagination.pageSize,flatMode:t.conf.flatMode,paramsModifier:t.conf.listFetchParamsModifier},e);t.getData().setListLastFetch({params:s});const n={limit:s.limit,offset:s.offset,flat_mode:s.flatMode,page_key:t.getConf().pageKey,site_name:t.getConf().site};s.paramsModifier&&s.paramsModifier(n),t.getApi().comments.getComments(r(r({},n),t.getApi().getUserFields())).then((({data:e})=>{t.getData().setListLastFetch({params:s,data:e}),t.getData().loadComments(e.comments),t.getData().updatePage(e.page),s.onSuccess&&s.onSuccess(e),t.trigger("list-fetched",{params:s,data:e})})).catch((e=>{const n={msg:e.msg||String(e),data:e.data};throw s.onError&&s.onError(n),t.trigger("list-failed",n),t.trigger("list-fetched",{params:s,error:n}),e})).finally((()=>{t.getData().setLoading(!1)}))}))},t=>{t.on("list-fetch",(e=>{const s=t.get("list");0===e.offset&&Bt(!0,s.$el)})),t.on("list-fetched",(()=>{Bt(!1,t.get("list").$el)}))},t=>{t.on("comment-rendered",(e=>{if(!0===t.conf.listUnreadHighlight){const s=t.getData().getNotifies(),n=s.find((t=>t.comment_id===e.getID()));n?(e.getRender().setUnread(!0),e.getRender().setOpenAction((()=>{window.open(n.read_link),t.getData().updateNotifies(s.filter((t=>t.comment_id!==e.getID())))}))):e.getRender().setUnread(!1)}})),t.on("list-goto",(e=>{const s=gt("atk_notify_key");s&&t.getApi().notifies.markNotifyRead(e,s).then((()=>{t.getData().updateNotifies(t.getData().getNotifies().filter((t=>t.comment_id!==e)))}))}))},t=>{let e;t.on("mounted",(()=>{const s=t.get("list");e=s.$el.querySelector('[data-action="admin-close-comment"]'),e.addEventListener("click",(()=>{const e=t.getData().getPage();if(!e)throw new Error("Page data not found");e.admin_only=!e.admin_only,function(t,e){t.editorShowLoading(),t.getApi().pages.updatePage(e.id,e).then((({data:e})=>{t.getData().updatePage(e)})).catch((e=>{t.editorShowNotify(`${At("editFail")}: ${e.message||String(e)}`,"e")})).finally((()=>{t.editorHideLoading()}))}(t,e)}))})),t.on("page-loaded",(s=>{var n,i;const o=t.get("editor");!0===(null==s?void 0:s.admin_only)?(null==(n=o.getPlugs())||n.getEvents().trigger("editor-close"),e&&(e.innerText=At("openComment"))):(null==(i=o.getPlugs())||i.getEvents().trigger("editor-open"),e&&(e.innerText=At("closeComment")))})),t.on("list-loaded",(e=>{t.editorResetState()}))},t=>{t.on("list-loaded",(()=>{(()=>{var e,s;const n=t.get("list").$el.querySelector(".atk-comment-count .atk-text");if(!n)return;const i=mt(At("counter",{count:`${Number(null==(s=null==(e=t.getData().getListLastFetch())?void 0:e.data)?void 0:s.count)||0}`}));n.innerHTML=i.replace(/(\d+)/,'<span class="atk-comment-count-num">$1</span>')})()})),t.on("comment-inserted",(()=>{const e=t.getData().getListLastFetch();(null==e?void 0:e.data)&&(e.data.count+=1)})),t.on("comment-deleted",(()=>{const e=t.getData().getListLastFetch();(null==e?void 0:e.data)&&(e.data.count-=1)}))},t=>{let e=null;const s=()=>{if(!e)return;const s=t.get("user").getData();if(s.name&&s.email){e.classList.remove("atk-hide");const t=e.querySelector(".atk-text");t&&(t.innerText=s.is_admin?At("ctrlCenter"):At("msgCenter"))}else e.classList.add("atk-hide")};t.watchConf(["locale"],(n=>{const i=t.get("list");e=i.$el.querySelector('[data-action="open-sidebar"]'),e&&(e.onclick=()=>{t.showSidebar()},s())})),t.on("user-changed",(t=>{s()}))},t=>{let e=null;t.on("mounted",(()=>{const s=t.get("list");e=s.$el.querySelector(".atk-unread-badge")})),t.on("notifies-updated",(t=>{var s;s=t.length||0,e&&(s>0?(e.innerText=`${Number(s||0)}`,e.style.display="block"):e.style.display="none")}))},t=>{const e=e=>{t.conf.listFetchParamsModifier=e,t.reload()},s=t=>{!function(t){const{$dropdownWrap:e,dropdownList:s}=t;if(e.querySelector(".atk-dropdown"))return;e.classList.add("atk-dropdown-wrap"),e.append(pt('<span class="atk-arrow-down-icon"></span>'));let n=0;const i=(t,e,s,i)=>{i(),n=t,o.querySelectorAll(".active").forEach((t=>{t.classList.remove("active")})),e.classList.add("active"),o.style.display="none",setTimeout((()=>{o.style.display=""}),80)},o=pt('<ul class="atk-dropdown atk-fade-in"></ul>');s.forEach(((t,e)=>{const[s,a]=t,r=pt('<li class="atk-dropdown-item"><span></span></li>'),l=r.querySelector("span");l.innerText=s,l.onclick=()=>{i(e,r,s,a)},o.append(r),e===n&&r.classList.add("active")})),e.append(o)}({$dropdownWrap:t,dropdownList:[[At("sortLatest"),()=>{e((t=>{t.sort_by="date_desc"}))}],[At("sortBest"),()=>{e((t=>{t.sort_by="vote"}))}],[At("sortOldest"),()=>{e((t=>{t.sort_by="date_asc"}))}],[At("sortAuthor"),()=>{e((t=>{t.view_only_admin=!0}))}]]})};t.watchConf(["listSort","locale"],(e=>{const n=t.get("list").$el.querySelector(".atk-comment-count");n&&(e.listSort?s(n):function(t){var e,s;const{$dropdownWrap:n}=t;n.classList.remove("atk-dropdown-wrap"),null==(e=n.querySelector(".atk-arrow-down-icon"))||e.remove(),null==(s=n.querySelector(".atk-dropdown"))||s.remove()}({$dropdownWrap:n}))}))},t=>{let e=0;const s=({locker:s})=>{const n=function(){const t=window.location.hash.match(/#atk-comment-([0-9]+)/);let e=t&&t[1]&&!Number.isNaN(parseFloat(t[1]))?parseFloat(t[1]):null;e||(e=Number(gt("atk_comment")));return e||null}();n&&(s&&e===n||(e=n,t.trigger("list-goto",n)))},n=()=>s({locker:!1}),i=()=>s({locker:!0});t.on("mounted",(()=>{window.addEventListener("hashchange",n),t.on("list-loaded",i)})),t.on("unmounted",(()=>{window.removeEventListener("hashchange",n),t.off("list-loaded",i)}))},t=>{t.on("list-goto",(e=>d(exports,null,(function*(){let s=t.getCommentNodes().find((t=>t.getID()===e));if(!s){const n=(yield t.getApi().comments.getComment(e)).data;t.get("list").getListLayout({forceFlatMode:!0}).insert(n.comment,n.reply_comment),s=t.getCommentNodes().find((t=>t.getID()===e))}s&&s.focus()}))))},t=>{t.on("list-loaded",(e=>{const s=t.get("list"),n=e.length<=0;let i=s.getCommentsWrapEl().querySelector(".atk-list-no-comment");n?i||(i=pt('<div class="atk-list-no-comment"></div>'),i.innerHTML=X(s.ctx.conf.noComment||s.ctx.$t("noComment")),s.getCommentsWrapEl().appendChild(i)):null==i||i.remove()}))},t=>{t.on("mounted",(()=>{const e=t.get("list").$el.querySelector(".atk-copyright");e&&(e.innerHTML=`Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${Xe}">Artalk</a>`)}))},t=>{let e=null;t.on("mounted",(()=>{e=window.setInterval((()=>{t.get("list").$el.querySelectorAll("[data-atk-comment-date]").forEach((e=>{var s,n;const i=new Date(Number(e.getAttribute("data-atk-comment-date")));e.innerText=(null==(n=(s=t.getConf()).dateFormatter)?void 0:n.call(s,i))||kt(i,t.$t)}))}),3e4)})),t.on("unmounted",(()=>{e&&window.clearInterval(e)}))},t=>{t.on("list-fetch",(()=>{_t(t.get("list").$el,null)})),t.on("list-failed",(e=>{Ze({$err:t.get("list").$el,errMsg:e.msg,errData:e.data,retryFn:()=>t.fetch({offset:0})})}))},t=>{let e=null;const s=()=>{null==e||e.disconnect(),e=null};t.on("list-loaded",(()=>{s();const n=t.get("list").getCommentsWrapEl().childNodes,i=n.length>2?n[n.length-2]:null;i&&("IntersectionObserver"in window?(n=>{const i=t.conf.scrollRelativeTo&&t.conf.scrollRelativeTo()||null;e=new IntersectionObserver((([e])=>{e.isIntersecting&&(s(),t.trigger("list-reach-bottom"))}),{threshold:.9,root:i}),e.observe(n)})(i):console.warn("IntersectionObserver api not supported"))})),t.on("unmounted",(()=>{s()}))},t=>{const e=()=>{const e=t.get("list"),s=t.conf.scrollRelativeTo&&t.conf.scrollRelativeTo();(s||window).scroll({top:ft(e.$el,s).top,left:0})};t.on("mounted",(()=>{t.on("list-goto-first",e)})),t.on("unmounted",(()=>{t.off("list-goto-first",e)}))}],t=>{t.on("list-fetch",(e=>{if(0!==e.offset)return;const s=t.getApi().getUserFields();s&&t.getApi().notifies.getNotifies(s).then((e=>{t.getData().updateNotifies(e.data.notifies)}))}))},t=>{t.watchConf(["site","pageKey","pageTitle","countEl","pvEl","statPageKeyAttr"],(e=>{Fe({getApi:()=>t.getApi(),siteName:e.site,pageKey:e.pageKey,pageTitle:e.pageTitle,countEl:e.countEl,pvEl:e.pvEl,pageKeyAttr:e.statPageKeyAttr,pvAdd:"boolean"!=typeof t.conf.pvAdd||t.conf.pvAdd})}))},t=>{t.watchConf(["apiVersion","versionCheck"],(e=>{const s=t.get("list");e.apiVersion&&e.versionCheck&&!ts&&function(t,e,s){const n=function(t,e){const s=t.split("."),n=e.split(".");for(let i=0;i<3;i++){const t=Number(s[i]),e=Number(n[i]);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,s);if(0===n)return;const i=pt(`<div class="atk-version-check-notice">${At("updateMsg",{name:At(n<0?"frontend":"backend")})} <span class="atk-info">${At("currentVersion")}: ${At("frontend")} ${e} / ${At("backend")} ${s}</span></div>`),o=pt(`<span class="atk-ignore-btn">${At("ignore")}</span>`);o.onclick=()=>{i.remove(),ts=!0},i.append(o),t.$el.parentElement.prepend(i)}(s,Xe,e.apiVersion)}))},t=>{let e;const s=s=>{const n=[t.$root,t.get("layerManager").getEl()];es||(es=window.matchMedia("(prefers-color-scheme: dark)")),"auto"===s?(e||(e=t=>ss(n,t.matches),es.addEventListener("change",e)),ss(n,es.matches)):(e&&(es.removeEventListener("change",e),e=void 0),ss(n,s))};t.watchConf(["darkMode"],(t=>s(t.darkMode))),t.on("created",(()=>s(t.conf.darkMode))),t.on("unmounted",(()=>{e&&(null==es||es.removeEventListener("change",e)),e=void 0}))}],is=new Set([...ns]),os=new WeakMap;function as(t){return d(this,null,(function*(){var e;const s=new Set,n=e=>{e.forEach((e=>{"function"!=typeof e||s.has(e)||(e(t,os.get(e)),s.add(e))}))};n(is);const{data:i}=yield t.getApi().conf.conf().catch((e=>{throw function(t,e){var s;let n="";if(null==(s=e.data)?void 0:s.err_no_site){const e={create_name:t.conf.site,create_urls:`${window.location.protocol}//${window.location.host}`};n=`sites|${JSON.stringify(e)}`}Ze({$err:t.get("list").$el,errMsg:e.msg||String(e),errData:e.data,retryFn:()=>as(t),onOpenSidebar:t.get("user").getData().is_admin?()=>t.showSidebar({view:n}):void 0})}(t,e),e}));let o={apiVersion:null==(e=i.version)?void 0:e.version};if(t.conf.useBackendConf){if(!i.frontend_conf)throw new Error("The remote backend does not respond to the frontend conf, but `useBackendConf` conf is enabled");o=r(r({},o),function(t){const e=["el","pageKey","pageTitle","server","site","pvEl","countEl","statPageKeyAttr"];return Object.keys(t).forEach((s=>{e.includes(s)&&delete t[s],"darkMode"===s&&"auto"!==t[s]&&delete t[s]})),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}(i.frontend_conf))}t.conf.remoteConfModifier&&t.conf.remoteConfModifier(o),o.pluginURLs&&(yield function(t,e){return d(this,null,(function*(){const s=new Set;if(!t||!Array.isArray(t))return s;const n=[];return t.forEach((t=>{/^(http|https):\/\//.test(t)||(t=`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`),n.push(new Promise((e=>{if(document.querySelector(`script[src="${t}"]`))return void e();const s=document.createElement("script");s.src=t,document.head.appendChild(s),s.onload=()=>e(),s.onerror=t=>{console.error("[artalk] Failed to load plugin",t),e()}})))})),yield Promise.all(n),Object.values(window.ArtalkPlugins||{}).forEach((t=>{"function"==typeof t&&s.add(t)})),s}))}(o.pluginURLs,t.conf.server).then((t=>{n(t)})).catch((t=>{console.error("Failed to load plugin",t)}))),t.trigger("created"),t.updateConf(o),t.trigger("mounted"),t.conf.remoteConfModifier||t.fetch({offset:0})}))}class rs{constructor(t){c(this,"ctx");const e=Ut(t,!0);this.ctx=new qt(e),Object.entries(je).forEach((([t,e])=>{const s=e(this.ctx);s&&this.ctx.inject(t,s)})),as(this.ctx)}getConf(){return this.ctx.getConf()}getEl(){return this.ctx.$root}update(t){return this.ctx.updateConf(t),this}reload(){this.ctx.reload()}destroy(){for(this.ctx.trigger("unmounted");this.ctx.$root.firstChild;)this.ctx.$root.removeChild(this.ctx.$root.firstChild)}on(t,e){this.ctx.on(t,e)}off(t,e){this.ctx.off(t,e)}trigger(t,e){this.ctx.trigger(t,e)}setDarkMode(t){this.ctx.setDarkMode(t)}static init(t){return new rs(t)}static use(t,e){is.add(t),os.set(t,e)}static loadCountWidget(t){const e=Ut(t,!0);Fe({getApi:()=>new f(It(e)),siteName:e.site,countEl:e.countEl,pvEl:e.pvEl,pageKeyAttr:e.statPageKeyAttr,pvAdd:!1})}get $root(){return this.ctx.$root}get conf(){return this.ctx.getConf()}}const ls=rs.init,cs=rs.use,ds=rs.loadCountWidget;exports.default=rs,exports.init=ls,exports.loadCountWidget=ds,exports.use=cs;
|
|
11
11
|
//# sourceMappingURL=ArtalkLite.cjs.map
|