@esershnr/artalk 2.9.2 → 2.9.3

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 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 Bt=class extends Dt{constructor(){super(...arguments),c(this,"auth",{loginByEmail:(e,t={})=>this.request(a({path:"/auth/email/login",method:"POST",body:e,type:"application/json",format:"json"},t)),registerByEmail:(e,t={})=>this.request(a({path:"/auth/email/register",method:"POST",body:e,type:"application/json",format:"json"},t)),sendVerifyEmail:(e,t={})=>this.request(a({path:"/auth/email/send",method:"POST",body:e,type:"application/json",format:"json"},t)),checkDataMerge:(e={})=>this.request(a({path:"/auth/merge",method:"GET",secure:!0,format:"json"},e)),applyDataMerge:(e,t={})=>this.request(a({path:"/auth/merge",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t))}),c(this,"cache",{flushCache:(e={})=>this.request(a({path:"/cache/flush",method:"POST",secure:!0,format:"json"},e)),warmUpCache:(e={})=>this.request(a({path:"/cache/warm_up",method:"POST",secure:!0,format:"json"},e))}),c(this,"captcha",{getCaptcha:(e={})=>this.request(a({path:"/captcha",method:"GET",format:"json"},e)),getCaptchaStatus:(e={})=>this.request(a({path:"/captcha/status",method:"GET",format:"json"},e)),verifyCaptcha:(e,t={})=>this.request(a({path:"/captcha/verify",method:"POST",body:e,type:"application/json",format:"json"},t))}),c(this,"comments",{getComments:(e,t={})=>this.request(a({path:"/comments",method:"GET",query:e,secure:!0,type:"application/json",format:"json"},t)),createComment:(e,t={})=>this.request(a({path:"/comments",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),getComment:(e,t={})=>this.request(a({path:`/comments/${e}`,method:"GET",type:"application/json",format:"json"},t)),updateComment:(e,t,n={})=>this.request(a({path:`/comments/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deleteComment:(e,t={})=>this.request(a({path:`/comments/${e}`,method:"DELETE",secure:!0,format:"json"},t))}),c(this,"conf",{conf:(e={})=>this.request(a({path:"/conf",method:"GET",format:"json"},e)),getSocialLoginProviders:(e={})=>this.request(a({path:"/conf/auth/providers",method:"GET",format:"json"},e)),getDomain:(e,t={})=>this.request(a({path:"/conf/domain",method:"GET",query:e,format:"json"},t))}),c(this,"notifies",{getNotifies:(e,t={})=>this.request(a({path:"/notifies",method:"GET",query:e,type:"application/json",format:"json"},t)),markAllNotifyRead:(e,t={})=>this.request(a({path:"/notifies/read",method:"POST",body:e,type:"application/json",format:"json"},t)),markNotifyRead:(e,t,n={})=>this.request(a({path:`/notifies/${e}/${t}`,method:"POST",format:"json"},n))}),c(this,"pages",{getPages:(e,t={})=>this.request(a({path:"/pages",method:"GET",query:e,secure:!0,type:"application/json",format:"json"},t)),fetchAllPages:(e,t={})=>this.request(a({path:"/pages/fetch",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),getPageFetchStatus:(e={})=>this.request(a({path:"/pages/fetch/status",method:"GET",secure:!0,format:"json"},e)),logPv:(e,t={})=>this.request(a({path:"/pages/pv",method:"POST",body:e,type:"application/json",format:"json"},t)),updatePage:(e,t,n={})=>this.request(a({path:`/pages/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deletePage:(e,t={})=>this.request(a({path:`/pages/${e}`,method:"DELETE",secure:!0,format:"json"},t)),fetchPage:(e,t={})=>this.request(a({path:`/pages/${e}/fetch`,method:"POST",secure:!0,type:"application/json",format:"json"},t))}),c(this,"sendEmail",{sendEmail:(e,t={})=>this.request(a({path:"/send_email",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t))}),c(this,"settings",{getSettings:(e={})=>this.request(a({path:"/settings",method:"GET",secure:!0,format:"json"},e)),applySettings:(e,t={})=>this.request(a({path:"/settings",method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},t)),getSettingsTemplate:(e,t={})=>this.request(a({path:`/settings/template/${e}`,method:"GET",secure:!0,format:"json"},t))}),c(this,"sites",{getSites:(e={})=>this.request(a({path:"/sites",method:"GET",secure:!0,format:"json"},e)),createSite:(e,t={})=>this.request(a({path:"/sites",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),updateSite:(e,t,n={})=>this.request(a({path:`/sites/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deleteSite:(e,t={})=>this.request(a({path:`/sites/${e}`,method:"DELETE",secure:!0,format:"json"},t))}),c(this,"stats",{getStats:(e,t,n={})=>this.request(a({path:`/stats/${e}`,method:"GET",query:t,type:"application/json",format:"json"},n))}),c(this,"transfer",{exportArtrans:(e={})=>this.request(a({path:"/transfer/export",method:"GET",secure:!0,format:"json"},e)),importArtrans:(e,t={})=>this.request(a({path:"/transfer/import",method:"POST",body:e,secure:!0,type:"application/json"},t)),uploadArtrans:(e,t={})=>this.request(a({path:"/transfer/upload",method:"POST",body:e,secure:!0,type:"multipart/form-data",format:"json"},t))}),c(this,"upload",{upload:(e,t={})=>this.request(a({path:"/upload",method:"POST",body:e,secure:!0,type:"multipart/form-data",format:"json"},t))}),c(this,"user",{getUser:(e,t={})=>this.request(a({path:"/user",method:"GET",query:e,secure:!0,format:"json"},t)),updateProfile:(e,t={})=>this.request(a({path:"/user",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),login:(e,t={})=>this.request(a({path:"/user/access_token",method:"POST",body:e,type:"application/json",format:"json"},t)),getUserStatus:(e,t={})=>this.request(a({path:"/user/status",method:"GET",query:e,secure:!0,format:"json"},t))}),c(this,"users",{createUser:(e,t={})=>this.request(a({path:"/users",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),updateUser:(e,t,n={})=>this.request(a({path:`/users/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deleteUser:(e,t={})=>this.request(a({path:`/users/${e}`,method:"DELETE",secure:!0,format:"json"},t)),getUsers:(e,t,n={})=>this.request(a({path:`/users/${e}`,method:"GET",query:t,secure:!0,type:"application/json",format:"json"},n))}),c(this,"version",{getVersion:(e={})=>this.request(a({path:"/version",method:"GET",format:"json"},e))}),c(this,"votes",{syncVotes:(e={})=>this.request(a({path:"/votes/sync",method:"POST",secure:!0,format:"json"},e)),getVote:(e,t,n={})=>this.request(a({path:`/votes/${e}/${t}`,method:"GET",type:"application/json",format:"json"},n)),createVote:(e,t,n,s,i={})=>this.request(a({path:`/votes/${e}/${t}/${n}`,method:"POST",body:s,type:"application/json",format:"json"},i))})}};const qt=(e,t,n)=>d(exports,null,(function*(){const s=e.getApiToken&&e.getApiToken(),i=new Headers(a({Authorization:s?`Bearer ${s}`:""},null==n?void 0:n.headers));i.get("Authorization")||i.delete("Authorization");const r=yield fetch(t,l(a({},n),{headers:i}));if(!r.ok){const s=(yield r.json().catch((()=>{})))||{};let i=!1;if(e.handlers&&(yield e.handlers.get().reduce(((e,t)=>d(exports,null,(function*(){yield e,!0===s[t.action]&&(yield t.handler(s),i=!0)}))),Promise.resolve())),i)return qt(e,t,n);throw function(e,t){const n=new _t;return n.message=t.msg||t.message||"fetch error",n.code=e,n.data=t,console.error(n),n}(r.status,s)}return r}));class _t extends Error{constructor(){super(...arguments),c(this,"code",0),c(this,"message","fetch error"),c(this,"data")}}class zt extends Bt{constructor(e){super({baseUrl:e.baseURL,customFetch:(t,n)=>qt(e,t,n)}),c(this,"_opts"),this._opts=e}getUserFields(){const e=this._opts.userInfo;if((null==e?void 0:e.name)&&(null==e?void 0:e.email))return{name:e.name,email:e.email}}}class Ft{constructor(e){c(this,"$btn"),c(this,"$panel"),c(this,"editorStateEffectWhen"),this.kit=e}useBtn(e="<div></div>"){return this.$btn=h(`<span class="atk-plug-btn">${e}</span>`),this.$btn}usePanel(e="<div></div>"){return this.$panel=h(e),this.$panel}useContentTransformer(e){this.contentTransformer=e}usePanelShow(e){this.kit.useEvents().on("panel-show",(t=>{t===this&&e()}))}usePanelHide(e){this.kit.useEvents().on("panel-hide",(t=>{t===this&&e()}))}useEditorStateEffect(e,t){this.editorStateEffectWhen=e,this.editorStateEffect=t}}const Wt="ArtalkContent";class Nt{constructor(e){this.kit=e}reqAdd(){return d(this,null,(function*(){return(yield this.kit.useApi().comments.createComment(a({},yield this.getSubmitAddParams()))).data}))}getSubmitAddParams(){return d(this,null,(function*(){const{name:e,email:t,link:n}=this.kit.useUser().getData(),s=this.kit.useConf();return{content:this.kit.useEditor().getContentFinal(),name:e,email:t,link:n,rid:0,page_key:s.pageKey,page_title:s.pageTitle,site_name:s.site,ua:yield k()}}))}postSubmitAdd(e){this.kit.useData().insertComment(e)}}class Ht extends Ft{constructor(e){super(e),c(this,"customs",[]),c(this,"defaultPreset"),this.defaultPreset=new Nt(this.kit);const t=()=>this.do();this.kit.useMounted((()=>{this.kit.useEvents().on("editor-submit",t)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("editor-submit",t)}))}registerCustom(e){this.customs.push(e)}do(){return d(this,null,(function*(){if(""===this.kit.useEditor().getContentFinal().trim())return void this.kit.useEditor().focus();const e=this.customs.find((e=>e.activeCond()));this.kit.useEditor().showLoading();try{let t;(null==e?void 0:e.pre)&&e.pre(),t=(null==e?void 0:e.req)?yield e.req():yield this.defaultPreset.reqAdd(),(null==e?void 0:e.post)?e.post(t):this.defaultPreset.postSubmitAdd(t)}catch(t){return console.error(t),void this.kit.useEditor().showNotify(`${T("commentFail")}: ${t.message||String(t)}`,"e")}finally{this.kit.useEditor().hideLoading()}this.kit.useEditor().reset(),this.kit.useEvents().trigger("editor-submitted")}))}}class Vt extends Ft{constructor(){super(...arguments),c(this,"isMoved",!1)}move(e){if(this.isMoved)return;this.isMoved=!0;const t=this.kit.useUI().$el;t.after(h('<div class="atk-editor-travel-placeholder"></div>'));const n=h("<div></div>");e.after(n),n.replaceWith(t),t.classList.add("atk-fade-in"),t.classList.add("editor-traveling")}back(){var e;this.isMoved&&(this.isMoved=!1,null==(e=this.kit.useArtalkRootEl().querySelector(".atk-editor-travel-placeholder"))||e.replaceWith(this.kit.useUI().$el),this.kit.useUI().$el.classList.remove("editor-traveling"))}}function Qt(e,t){let n=e.querySelector(":scope > .atk-loading");n||(n=h('<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==t?void 0:t.transparentBg)&&(n.style.background="transparent"),e.appendChild(n)),n.style.display="";const s=n.querySelector(".atk-loading-spinner");s&&(s.style.display="none",window.setTimeout((()=>{s.isConnected&&(s.style.display="")}),500))}function Kt(e){const t=e.querySelector(":scope > .atk-loading");t&&(t.style.display="none")}function Gt(e,t){e?Qt(t):Kt(t)}function Yt(e,t=!0,n){let s;if(n){const t=n.getBoundingClientRect();s=e.getBoundingClientRect().top-t.top+n.scrollTop-n.clientHeight/2+e.clientHeight/2}else{const t=e.getBoundingClientRect();s=t.top+window.scrollY-(window.innerHeight/2-t.height/2)}const i={top:s,left:0,behavior:"instant"};n?n.scroll(i):window.scroll(i)}function Zt(e,t){!function(e,t,n="in"){e.classList.add(`atk-fade-${n}`);const s=()=>{e.classList.remove(`atk-fade-${n}`),e.removeEventListener("animationend",s)};e.addEventListener("animationend",s)}(e,0,"in")}function Xt(e,t,n='<span class="atk-error-title">Artalk Error</span>'){let s=e.querySelector(".atk-error-layer");if(null===t)return void(null!==s&&s.remove());s||(s=h(`<div class="atk-error-layer">${n}<span class="atk-error-text"></span></div>`),e.appendChild(s));const i=s.querySelector(".atk-error-text");i.innerHTML="",null!==t&&(t instanceof HTMLElement?i.appendChild(t):i.innerText=t)}class Jt extends Ft{constructor(e){super(e),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="${T("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((e=>this.transEmoticonImageText(e))),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*(){Qt(this.$panel),this.emoticons=yield this.handleData(this.kit.useConf().emoticons),Kt(this.$panel),this.loadingTask=null,this.isListLoaded=!0})))(),yield this.loadingTask):yield this.loadingTask)}))}handleData(e){return d(this,null,(function*(){if(!Array.isArray(e)&&["object","string"].includes(typeof e)&&(e=[e]),!Array.isArray(e))return Xt(this.$panel,`[${T("emoticon")}] Data must be of Array/Object/String type`),Kt(this.$panel),[];const t=t=>{"object"==typeof t&&(t.name&&e.find((e=>e.name===t.name))||e.push(t))},n=e=>d(this,null,(function*(){yield Promise.all(e.map(((e,s)=>d(this,null,(function*(){if("object"!=typeof e||Array.isArray(e)){if(Array.isArray(e))yield n(e);else if("string"==typeof e){const s=yield this.remoteLoad(e);Array.isArray(s)?yield n(s):"object"==typeof s&&t(s)}}else t(e)})))))}));return yield n(e),e.forEach((e=>{if(this.isOwOFormat(e)){this.convertOwO(e).forEach((e=>{t(e)}))}else Array.isArray(e)&&e.forEach((e=>{t(e)}))})),e=e.filter((e=>"object"==typeof e&&!Array.isArray(e)&&!!e&&!!e.name)),this.solveNullKey(e),this.solveSameKey(e),e}))}remoteLoad(e){return d(this,null,(function*(){if(!e)return[];try{const t=yield fetch(e);return yield t.json()}catch(t){return Kt(this.$panel),console.error("[Emoticons] Load Failed:",t),Xt(this.$panel,`[${T("emoticon")}] ${T("loadFail")}: ${String(t)}`),[]}}))}solveNullKey(e){e.forEach((e=>{e.items.forEach(((t,n)=>{t.key||(t.key=`${e.name} ${n+1}`)}))}))}solveSameKey(e){const t={};e.forEach((e=>{e.items.forEach((e=>{e.key&&""!==String(e.key).trim()&&(t[e.key]?t[e.key]++:t[e.key]=1,t[e.key]>1&&(e.key=`${e.key} ${t[e.key]}`))}))}))}isOwOFormat(e){try{return"object"==typeof e&&!!Object.values(e).length&&Array.isArray(Object.keys(Object.values(e)[0].container))&&Object.keys(Object.values(e)[0].container[0]).includes("icon")}catch(t){return!1}}convertOwO(e){const t=[];return Object.entries(e).forEach((([e,n])=>{const s={name:e,type:n.type,items:[]};n.container.forEach(((t,n)=>{const i=t.icon;if(/<(img|IMG)/.test(i)){const e=/src=["'](.*?)["']/.exec(i);e&&e.length>1&&(t.icon=e[1])}s.items.push({key:t.text||`${e} ${n+1}`,val:t.icon})})),t.push(s)})),t}initEmoticonsList(){this.$grpWrap=h('<div class="atk-grp-wrap"></div>'),this.$panel.append(this.$grpWrap),this.emoticons.forEach(((e,t)=>{const n=h('<div class="atk-grp" style="display: none;"></div>');this.$grpWrap.append(n),n.setAttribute("data-index",String(t)),n.setAttribute("data-grp-name",e.name),n.setAttribute("data-type",e.type),e.items.forEach((t=>{const s=h('<span class="atk-item"></span>');if(n.append(s),t.key&&!new RegExp(`^(${e.name})?\\s?[0-9]+$`).test(t.key)&&s.setAttribute("title",t.key),"image"===e.type){const e=document.createElement("img");e.src=t.val,e.alt=t.key,s.append(e)}else s.innerText=t.val;s.onclick=()=>{"image"===e.type?this.kit.useEditor().insertContent(`:[${t.key}]`):this.kit.useEditor().insertContent(t.val||"")}}))})),this.emoticons.length>1&&(this.$grpSwitcher=h('<div class="atk-grp-switcher"></div>'),this.$panel.append(this.$grpSwitcher),this.emoticons.forEach(((e,t)=>{const n=h("<span />");n.innerText=e.name,n.setAttribute("data-index",String(t)),n.onclick=()=>this.openGrp(t),this.$grpSwitcher.append(n)}))),this.emoticons.length>0&&this.openGrp(0)}openGrp(e){var t,n,s;Array.from(this.$grpWrap.children).forEach((t=>{const n=t;n.getAttribute("data-index")!==String(e)?n.style.display="none":n.style.display=""})),null==(t=this.$grpSwitcher)||t.querySelectorAll("span.active").forEach((e=>e.classList.remove("active"))),null==(s=null==(n=this.$grpSwitcher)?void 0:n.querySelector(`span[data-index="${e}"]`))||s.classList.add("active"),this.changeListHeight()}changeListHeight(){}transEmoticonImageText(e){return this.emoticons&&Array.isArray(this.emoticons)?(this.emoticons.forEach((t=>{"image"===t.type&&Object.entries(t.items).forEach((([t,n])=>{e=e.split(`:[${n.key}]`).join(`<img src="${n.val}" atk-emoticon="${n.key}">`)}))})),e):e}}const en=["png","jpg","jpeg","gif","bmp","svg","webp"];class tn extends Ft{constructor(e){super(e),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=en.map((e=>`.${e}`)).join(",");const e=this.useBtn(`<i aria-label="${T("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>`);e.after(this.$imgUploadInput),e.onclick=()=>{const e=this.$imgUploadInput;e.onchange=()=>{(()=>{d(this,null,(function*(){if(!e.files||0===e.files.length)return;const t=e.files[0];this.uploadImg(t)}))})()},e.click()},this.kit.useConf().imgUpload||this.$btn.setAttribute("atk-only-admin-show","")}initDragImg(){const e=e=>{if(e)for(let t=0;t<e.length;t++){const n=e[t];this.uploadImg(n)}},t=e=>{e.stopPropagation(),e.preventDefault()},n=t=>{var n;const s=null==(n=t.dataTransfer)?void 0:n.files;(null==s?void 0:s.length)&&(t.preventDefault(),e(s))},s=t=>{var n;const s=null==(n=t.clipboardData)?void 0:n.files;(null==s?void 0:s.length)&&(t.preventDefault(),e(s))};this.kit.useMounted((()=>{this.kit.useUI().$textarea.addEventListener("dragover",t),this.kit.useUI().$textarea.addEventListener("drop",n),this.kit.useUI().$textarea.addEventListener("paste",s)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("dragover",t),this.kit.useUI().$textarea.removeEventListener("drop",n),this.kit.useUI().$textarea.removeEventListener("paste",s)}))}uploadImg(e){return d(this,null,(function*(){const t=/[^.]+$/.exec(e.name);if(!t||!en.includes(String(t[0]).toLowerCase()))return;if(!this.kit.useUser().checkHasBasicUserInfo())return void this.kit.useEditor().showNotify(T("uploadLoginMsg"),"w");let n="\n";""===this.kit.useUI().$textarea.value.trim()&&(n="");const s=`${n}![](Uploading ${e.name}...)`;let i;this.kit.useEditor().insertContent(s);try{const t=this.kit.useConf().imgUploader;i=t?{public_url:yield t(e)}:(yield this.kit.useApi().upload.upload({file:e})).data}catch(r){console.error(r),this.kit.useEditor().showNotify(`${T("uploadFail")}: ${r.message}`,"e")}if(i&&i.public_url){let e=i.public_url;y(e)||(e=v({base:this.kit.useConf().server,path:e})),this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(s,`${n}![](${e})`))}else this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(s,""))}))}}class nn extends Ft{constructor(e){super(e),c(this,"isPlugPanelShow",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-preview"></div>'),this.useBtn(`<i aria-label="${T("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",(e=>{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 sn=[class extends Ft{constructor(e){super(e);const t=()=>{this.save()};this.kit.useMounted((()=>{const e=window.localStorage.getItem(Wt)||"";""!==e.trim()&&(this.kit.useEditor().showNotify(T("restoredMsg"),"i"),this.kit.useEditor().setContent(e)),this.kit.useEvents().on("content-updated",t)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("content-updated",t)}))}save(){window.localStorage.setItem(Wt,this.kit.useEditor().getContentRaw().trim())}},class extends Ft{get $inputs(){return this.kit.useEditor().getHeaderInputEls()}constructor(e){super(e);const t={},n={},s=(e,t,n)=>()=>{this.kit.useEvents().trigger(e,{field:n,$input:t})};this.kit.useMounted((()=>{Object.entries(this.$inputs).forEach((([e,i])=>{i.addEventListener("input",t[e]=s("header-input",i,e)),i.addEventListener("change",n[e]=s("header-change",i,e))}))})),this.kit.useUnmounted((()=>{Object.entries(this.$inputs).forEach((([e,s])=>{s.removeEventListener("input",t[e]),s.removeEventListener("change",n[e])}))}))}},class extends Ft{constructor(e){super(e),c(this,"query",{timer:null,abortFn:null});const t=({$input:e,field:t})=>{"edit"!==this.kit.useEditor().getState()&&(this.kit.useUser().update({[t]:e.value.trim()}),"name"!==t&&"email"!==t||this.fetchUserInfo())},n={name:T("nick"),email:T("email"),link:T("link")};this.kit.useMounted((()=>{Object.entries(this.kit.useEditor().getHeaderInputEls()).forEach((([e,t])=>{t.placeholder=n[e],t.value=this.kit.useUser().getData()[e]||""})),this.kit.useEvents().on("header-input",t)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-input",t)}))}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 e=this.kit.useApi(),t="getUserCancelToken";this.query.abortFn=()=>e.abortRequest(t),e.user.getUser(a({},e.getUserFields()),{cancelToken:t}).then((e=>this.onUserInfoFetched(e.data))).catch((e=>{})).finally((()=>{this.query.abortFn=null}))}),400)}onUserInfoFetched(e){var t;e.is_login||this.kit.useUser().logout(),this.kit.useData().updateNotifies(e.notifies),this.kit.useUser().checkHasBasicUserInfo()&&!e.is_login&&(null==(t=e.user)?void 0:t.is_admin)&&this.kit.useCheckers().checkAdmin({onSuccess:()=>{}}),e.user&&e.user.link&&(this.kit.useUI().$link.value=e.user.link,this.kit.useUser().update({link:e.user.link}))}},class extends Ft{constructor(e){super(e);const t=({field:e})=>{"link"===e&&this.onLinkInputChange()};this.kit.useMounted((()=>{this.kit.useEvents().on("header-change",t)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-change",t)}))}onLinkInputChange(){const e=this.kit.useUI().$link.value.trim();e&&!/^(http|https):\/\//.test(e)&&(this.kit.useUI().$link.value=`https://${e}`,this.kit.useUser().update({link:this.kit.useUI().$link.value}))}},class extends Ft{constructor(e){super(e);const t=e=>this.onKeydown(e),n=()=>this.onInput();this.kit.useMounted((()=>{this.kit.useUI().$textarea.placeholder=this.kit.useConf().placeholder||T("placeholder"),this.kit.useUI().$textarea.addEventListener("keydown",t),this.kit.useUI().$textarea.addEventListener("input",n)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("keydown",t),this.kit.useUI().$textarea.removeEventListener("input",n)})),this.kit.useEvents().on("content-updated",(()=>{window.setTimeout((()=>{this.adaptiveHeightByContent()}),80)}))}onKeydown(e){9===(e.keyCode||e.which)&&(e.preventDefault(),this.kit.useEditor().insertContent("\t"))}onInput(){this.kit.useEvents().trigger("content-updated",this.kit.useEditor().getContentRaw())}adaptiveHeightByContent(){const e=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+e}px`}},Ht,class extends Ft{constructor(e){super(e);const t=()=>{this.kit.useEditor().submit()};this.kit.useMounted((()=>{this.kit.useUI().$submitBtn.innerText=this.kit.useConf().sendBtn||T("send"),this.kit.useUI().$submitBtn.addEventListener("click",t)})),this.kit.useUnmounted((()=>{this.kit.useUI().$submitBtn.removeEventListener("click",t)}))}},Vt,class extends Ft{constructor(e){super(e),c(this,"comment"),this.useEditorStateEffect("reply",(e=>(this.setReply(e),()=>{this.cancelReply()}))),this.kit.useEvents().on("mounted",(()=>{const e=this.kit.useDeps(Ht);if(!e)throw Error("SubmitPlug not initialized");const t=new Nt(this.kit);e.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(a({},yield t.getSubmitAddParams()),{rid:this.comment.id,page_key:this.comment.page_key,page_title:void 0,site_name:this.comment.site_name}))).data})),post:e=>{const n=this.kit.useConf();e.page_key!==n.pageKey&&window.open(`${e.page_url}#atk-comment-${e.id}`),t.postSubmitAdd(e)}})}))}setReply(e){const t=this.kit.useUI();if(!t.$sendReplyBtn){const n=h(`<span class="atk-state-btn"><span class="atk-text-wrap">${T("reply")} <span class="atk-text"></span></span><span class="atk-cancel atk-icon-close atk-icon"></span></span>`);n.querySelector(".atk-text").innerText=`@${e.nick}`,n.addEventListener("click",(()=>{this.kit.useEditor().resetState()})),t.$stateWrap.append(n),t.$sendReplyBtn=n}this.comment=e,t.$textarea.focus()}cancelReply(){if(!this.comment)return;const e=this.kit.useUI();e.$sendReplyBtn&&(e.$sendReplyBtn.remove(),e.$sendReplyBtn=void 0),this.comment=void 0}},class extends Ft{constructor(e){super(e),c(this,"comment"),c(this,"originalSubmitBtnText","Send"),this.useEditorStateEffect("edit",(e=>(this.edit(e),()=>{this.cancelEdit()}))),this.kit.useMounted((()=>{const e=this.kit.useDeps(Ht);if(!e)throw Error("SubmitPlug not initialized");e.registerCustom({activeCond:()=>!!this.comment,req:()=>d(this,null,(function*(){const e={content:this.kit.useEditor().getContentFinal(),nick:this.kit.useUI().$name.value,email:this.kit.useUI().$email.value,link:this.kit.useUI().$link.value},t=this.comment;return(yield this.kit.useApi().comments.updateComment(t.id,a(a({},t),e))).data})),post:e=>{this.kit.useData().updateComment(e)}})}))}edit(e){const t=this.kit.useUI();if(!t.$editCancelBtn){const e=h(`<span class="atk-state-btn"><span class="atk-text-wrap">${T("editCancel")}</span><span class="atk-cancel atk-icon-close atk-icon"></span></span>`);e.onclick=()=>{this.kit.useEditor().resetState()},t.$stateWrap.append(e),t.$editCancelBtn=e}this.comment=e,t.$header.style.display="none",t.$name.value=e.nick||"",t.$email.value=e.email||"",t.$link.value=e.link||"",this.kit.useEditor().setContent(e.content),t.$textarea.focus(),this.updateSubmitBtnText(T("save"))}cancelEdit(){if(!this.comment)return;const e=this.kit.useUI();e.$editCancelBtn&&(e.$editCancelBtn.remove(),e.$editCancelBtn=void 0),this.comment=void 0;const{name:t,email:n,link:s}=this.kit.useUser().getData();e.$name.value=t,e.$email.value=n,e.$link.value=s,this.kit.useEditor().setContent(""),this.restoreSubmitBtnText(),e.$header.style.display=""}updateSubmitBtnText(e){this.originalSubmitBtnText=this.kit.useUI().$submitBtn.innerText,this.kit.useUI().$submitBtn.innerText=e}restoreSubmitBtnText(){this.kit.useUI().$submitBtn.innerText=this.originalSubmitBtnText}},class extends Ft{constructor(e){super(e);const t=()=>this.open(),n=()=>this.close();this.kit.useMounted((()=>{this.kit.useEvents().on("editor-open",t),this.kit.useEvents().on("editor-close",n)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("editor-open",t),this.kit.useEvents().off("editor-close",n)}))}open(){var e;null==(e=this.kit.useUI().$textareaWrap.querySelector(".atk-comment-closed"))||e.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(h(`<div class="atk-comment-closed">${T("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")}},Jt,tn,nn];class rn{constructor(e){this.plugins=e}useEditor(){return this.plugins.getEditor()}useConf(){return this.plugins.getOptions().getConf().get()}useApi(){return this.plugins.getOptions().getApi()}useData(){return this.plugins.getOptions().getData()}useUser(){return this.plugins.getOptions().getUser()}useCheckers(){return this.plugins.getOptions().getCheckers()}useUI(){return this.plugins.getEditor().getUI()}useEvents(){return this.plugins.getEvents()}useMounted(e){this.useEvents().on("mounted",e)}useUnmounted(e){this.useEvents().on("unmounted",e)}useDeps(e){return this.plugins.get(e)}useArtalkRootEl(){return this.plugins.getOptions().getArtalkRootEl()}}class on{constructor(){c(this,"events",[])}on(e,t,n={}){this.events.push(a({name:e,handler:t},n))}off(e,t){t&&(this.events=this.events.filter((n=>!(n.name===e&&n.handler===t))))}trigger(e,t){this.events.slice(0).filter((t=>t.name===e&&"function"==typeof t.handler)).forEach((n=>{n.once&&this.off(e,n.handler),n.handler(t)}))}}class an{constructor(e){c(this,"plugins",[]),c(this,"openedPlug",null),c(this,"events",new on),this.opts=e;let t=!1;this.opts.getConf().watchConf(["imgUpload","emoticons","preview","editorTravel","locale"],(e=>{t&&this.getEvents().trigger("unmounted"),this.clear(),function(e){const t=new Map;return t.set(tn,e.imgUpload),t.set(Jt,e.emoticons),t.set(nn,e.preview),t.set(Vt,e.editorTravel),sn.filter((e=>!t.has(e)||!!t.get(e)))}(e).forEach((e=>{const t=new rn(this);this.plugins.push(new e(t))})),this.getEvents().trigger("mounted"),t=!0,this.loadPluginUI()})),this.events.on("panel-close",(()=>this.closePluginPanel())),this.events.on("editor-submitted",(()=>e.onSubmitted()))}getPlugins(){return this.plugins}getEvents(){return this.events}getEditor(){return this.opts.getEditor()}getOptions(){return this.opts}clear(){this.plugins=[],this.events=new on,this.openedPlug&&this.closePluginPanel()}loadPluginUI(){this.getEditor().getUI().$plugPanelWrap.innerHTML="",this.getEditor().getUI().$plugPanelWrap.style.display="none",this.getEditor().getUI().$plugBtnWrap.innerHTML="",this.plugins.forEach((e=>this.loadPluginItem(e)))}loadPluginItem(e){const t=e.$btn;if(!t)return;this.getEditor().getUI().$plugBtnWrap.appendChild(t),!t.onclick&&(t.onclick=()=>{this.opts.getEditor().getUI().$plugBtnWrap.querySelectorAll(".active").forEach((e=>e.classList.remove("active"))),e!==this.openedPlug?(this.openPluginPanel(e),t.classList.add("active")):this.closePluginPanel()});const n=e.$panel;n&&(n.style.display="none",this.getEditor().getUI().$plugPanelWrap.appendChild(n))}get(e){return this.plugins.find((t=>t instanceof e))}openPluginPanel(e){this.plugins.forEach((t=>{const n=t.$panel;n&&(t===e?(n.style.display="",this.events.trigger("panel-show",e)):(n.style.display="none",this.events.trigger("panel-hide",e)))})),this.getEditor().getUI().$plugPanelWrap.style.display="",this.openedPlug=e}closePluginPanel(){this.openedPlug&&(this.getEditor().getUI().$plugPanelWrap.style.display="none",this.events.trigger("panel-hide",this.openedPlug),this.openedPlug=null)}getTransformedContent(e){let t=e;return this.plugins.forEach((e=>{e.contentTransformer&&(t=e.contentTransformer(t))})),t}}const ln="2.9.2";function cn(e){const t=h('<span><span class="error-message"></span><br/><br/></span>');if(t.querySelector(".error-message").innerText=`${T("listLoadFailMsg")}\n${e.errMsg}`,e.retryFn){const n=h(`<span style="cursor:pointer;">${T("listRetry")}</span>`);n.onclick=()=>e.retryFn&&e.retryFn(),t.appendChild(n)}if(e.onOpenSidebar){const n=h(`<span atk-only-admin-show> | <span style="cursor:pointer;">${T("openName",{name:T("ctrlCenter")})}</span></span>`);t.appendChild(n),n.onclick=()=>e.onOpenSidebar&&e.onOpenSidebar()}Xt(e.$err,t)}const dn=[e=>{const t=e.inject("config");e.on("list-fetch",(n=>{if(e.getData().getLoading())return;e.getData().setLoading(!0);const s=a({offset:0,limit:t.get().pagination.pageSize,flatMode:t.get().flatMode,paramsModifier:t.get().listFetchParamsModifier},n);e.getData().setListLastFetch({params:s});const i={limit:s.limit,offset:s.offset,flat_mode:s.flatMode,page_key:t.get().pageKey,site_name:t.get().site};s.paramsModifier&&s.paramsModifier(i),e.getApi().comments.getComments(a(a({},i),e.getApi().getUserFields())).then((({data:t})=>{e.getData().setListLastFetch({params:s,data:t}),e.getData().loadComments(t.comments),e.getData().updatePage(t.page),s.onSuccess&&s.onSuccess(t),e.trigger("list-fetched",{params:s,data:t})})).catch((t=>{const n={msg:t.msg||String(t),data:t.data};throw s.onError&&s.onError(n),e.trigger("list-failed",n),e.trigger("list-fetched",{params:s,error:n}),t})).finally((()=>{e.getData().setLoading(!1)}))}))},e=>{const t=e.inject("list");e.on("list-fetch",(e=>{0===e.offset&&Gt(!0,t.getEl())})),e.on("list-fetched",(()=>{Gt(!1,t.getEl())}))},e=>{const t=e.inject("config");e.on("comment-rendered",(n=>{if(t.get().listUnreadHighlight){const t=e.getData().getNotifies(),s=t.find((e=>e.comment_id===n.getID()));s?(n.getRender().setUnread(!0),n.getRender().setOpenAction((()=>{window.open(s.read_link),e.getData().updateNotifies(t.filter((e=>e.comment_id!==n.getID())))}))):n.getRender().setUnread(!1)}})),e.on("list-goto",(t=>{const n=p("atk_notify_key");n&&e.getApi().notifies.markNotifyRead(t,n).then((()=>{e.getData().updateNotifies(e.getData().getNotifies().filter((e=>e.comment_id!==t)))}))}))},e=>{const t=e.inject("list"),n=e.inject("editorPlugs");let s;e.on("mounted",(()=>{s=t.getEl().querySelector('[data-action="admin-close-comment"]'),s.addEventListener("click",(()=>{const t=e.getData().getPage();if(!t)throw new Error("Page data not found");t.admin_only=!t.admin_only,function(e,t){e.editorShowLoading(),e.getApi().pages.updatePage(t.id,t).then((({data:t})=>{e.getData().updatePage(t)})).catch((t=>{e.editorShowNotify(`${T("editFail")}: ${t.message||String(t)}`,"e")})).finally((()=>{e.editorHideLoading()}))}(e,t)}))})),e.on("page-loaded",(e=>{!0===(null==e?void 0:e.admin_only)?(null==n||n.getEvents().trigger("editor-close"),s&&(s.innerText=T("openComment"))):(null==n||n.getEvents().trigger("editor-open"),s&&(s.innerText=T("closeComment")))})),e.on("list-loaded",(t=>{e.editorResetState()}))},e=>{const t=e.inject("list");e.on("list-loaded",(()=>{(()=>{var n,s;const i=t.getEl().querySelector(".atk-comment-count .atk-text");if(!i)return;const r=u(T("counter",{count:`${Number(null==(s=null==(n=e.getData().getListLastFetch())?void 0:n.data)?void 0:s.count)||0}`}));i.innerHTML=r.replace(/(\d+)/,'<span class="atk-comment-count-num">$1</span>')})()})),e.on("comment-inserted",(()=>{const t=e.getData().getListLastFetch();(null==t?void 0:t.data)&&(t.data.count+=1)})),e.on("comment-deleted",(()=>{const t=e.getData().getListLastFetch();(null==t?void 0:t.data)&&(t.data.count-=1)}))},e=>{const t=e.inject("list");let n=null;const s=()=>{if(!n)return;const t=e.inject("user").getData();if(t.name&&t.email){n.classList.remove("atk-hide");const e=n.querySelector(".atk-text");e&&(e.innerText=t.is_admin?T("ctrlCenter"):T("msgCenter"))}else n.classList.add("atk-hide")};e.watchConf(["locale"],(i=>{n=t.getEl().querySelector('[data-action="open-sidebar"]'),n&&(n.onclick=()=>{e.showSidebar()},s())})),e.on("user-changed",(e=>{s()}))},e=>{const t=e.inject("list");let n=null;e.on("mounted",(()=>{n=t.getEl().querySelector(".atk-unread-badge")})),e.on("notifies-updated",(e=>{var t;t=e.length||0,n&&(t>0?(n.innerText=`${Number(t||0)}`,n.style.display="block"):n.style.display="none")}))},e=>{const t=e.inject("list"),n=e.inject("config"),s=t=>{n.update({listFetchParamsModifier:t}),e.reload()},i=e=>{!function(e){const{$dropdownWrap:t,dropdownList:n}=e;if(t.querySelector(".atk-dropdown"))return;t.classList.add("atk-dropdown-wrap"),t.append(h('<span class="atk-arrow-down-icon"></span>'));let s=0;const i=(e,t,n,i)=>{i(),s=e,r.querySelectorAll(".active").forEach((e=>{e.classList.remove("active")})),t.classList.add("active"),r.style.display="none",setTimeout((()=>{r.style.display=""}),80)},r=h('<ul class="atk-dropdown atk-fade-in"></ul>');n.forEach(((e,t)=>{const[n,o]=e,a=h('<li class="atk-dropdown-item"><span></span></li>'),l=a.querySelector("span");l.innerText=n,l.onclick=()=>{i(t,a,n,o)},r.append(a),t===s&&a.classList.add("active")})),t.append(r)}({$dropdownWrap:e,dropdownList:[[T("sortLatest"),()=>{s((e=>{e.sort_by="date_desc"}))}],[T("sortBest"),()=>{s((e=>{e.sort_by="vote"}))}],[T("sortOldest"),()=>{s((e=>{e.sort_by="date_asc"}))}],[T("sortAuthor"),()=>{s((e=>{e.view_only_admin=!0}))}]]})};e.watchConf(["listSort","locale"],(e=>{const n=t.getEl().querySelector(".atk-comment-count");n&&(e.listSort?i(n):function(e){var t,n;const{$dropdownWrap:s}=e;s.classList.remove("atk-dropdown-wrap"),null==(t=s.querySelector(".atk-arrow-down-icon"))||t.remove(),null==(n=s.querySelector(".atk-dropdown"))||n.remove()}({$dropdownWrap:n}))}))},e=>{let t=0;const n=({locker:n})=>{const s=function(){const e=window.location.hash.match(/#atk-comment-([0-9]+)/);let t=e&&e[1]&&!Number.isNaN(parseFloat(e[1]))?parseFloat(e[1]):null;t||(t=Number(p("atk_comment")));return t||null}();s&&(n&&t===s||(t=s,e.trigger("list-goto",s)))},s=()=>n({locker:!1}),i=()=>n({locker:!0});e.on("mounted",(()=>{window.addEventListener("hashchange",s),e.on("list-loaded",i)})),e.on("unmounted",(()=>{window.removeEventListener("hashchange",s),e.off("list-loaded",i)}))},e=>{const t=e.inject("list");e.on("list-goto",(n=>d(exports,null,(function*(){let s=e.getCommentNodes().find((e=>e.getID()===n));if(!s){const i=(yield e.getApi().comments.getComment(n)).data;t.getLayout({forceFlatMode:!0}).insert(i.comment,i.reply_comment),s=e.getCommentNodes().find((e=>e.getID()===n))}s&&s.focus()}))))},e=>{const t=e.inject("list"),n=e.inject("config");e.on("list-loaded",(s=>{const i=s.length<=0;let r=t.getCommentsWrapEl().querySelector(".atk-list-no-comment");i?r||(r=h('<div class="atk-list-no-comment"></div>'),r.innerHTML=kt(n.get().noComment||e.$t("noComment")),t.getCommentsWrapEl().appendChild(r)):null==r||r.remove()}))},e=>{const t=e.inject("list");e.on("mounted",(()=>{const e=t.getEl().querySelector(".atk-copyright");e&&(e.innerHTML=`Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${ln}">Artalk</a>`)}))},e=>{const t=e.inject("list"),n=e.inject("config");let s=null;e.on("mounted",(()=>{s=window.setInterval((()=>{t.getEl().querySelectorAll("[data-atk-comment-date]").forEach((t=>{var s,i;const r=new Date(Number(t.getAttribute("data-atk-comment-date")));t.innerText=(null==(i=(s=n.get()).dateFormatter)?void 0:i.call(s,r))||f(r,e.$t)}))}),3e4)})),e.on("unmounted",(()=>{s&&window.clearInterval(s)}))},e=>{const t=e.inject("list");e.on("list-fetch",(()=>{Xt(t.getEl(),null)})),e.on("list-failed",(n=>{cn({$err:t.getEl(),errMsg:n.msg,errData:n.data,retryFn:()=>e.fetch({offset:0})})}))},e=>{const t=e.inject("list"),n=e.inject("config");let s=null;const i=()=>{null==s||s.disconnect(),s=null};e.on("list-loaded",(()=>{i();const r=t.getCommentsWrapEl().childNodes,o=r.length>2?r[r.length-2]:null;o&&("IntersectionObserver"in window?(t=>{var r,o;const a=(null==(o=(r=n.get()).scrollRelativeTo)?void 0:o.call(r))||null;s=new IntersectionObserver((([t])=>{t.isIntersecting&&(i(),e.trigger("list-reach-bottom"))}),{threshold:.9,root:a}),s.observe(t)})(o):console.warn("IntersectionObserver api not supported"))})),e.on("unmounted",(()=>{i()}))},e=>{const t=e.inject("list"),n=e.inject("config"),s=()=>{var e,s;const i=null==(s=(e=n.get()).scrollRelativeTo)?void 0:s.call(e);(i||window).scroll({top:g(t.getEl(),i).top,left:0})};e.on("mounted",(()=>{e.on("list-goto-first",s)})),e.on("unmounted",(()=>{e.off("list-goto-first",s)}))}];let hn=!1;let un;function pn(e,t){const n="atk-dark-mode";e.forEach((e=>{t?e.classList.add(n):e.classList.remove(n)}))}const gn={upBtnEl:".artalk-page-vote-up",downBtnEl:".artalk-page-vote-down",upCountEl:".artalk-page-vote-up-count",downCountEl:".artalk-page-vote-down-count",activeClass:"active"};function mn(e,t,n,s,i){var r,o;e.upCountEl?e.upCountEl.innerText=String(t):e.upBtnEl&&(e.upBtnEl.innerText=`${T("voteUp")} (${t})`),e.downCountEl?e.downCountEl.innerText=String(n):e.downBtnEl&&(e.downBtnEl.innerText=`${T("voteDown")} (${n})`),"boolean"==typeof s&&(null==(r=e.upBtnEl)||r.classList.toggle(e.activeClass||"active",s)),"boolean"==typeof i&&(null==(o=e.downBtnEl)||o.classList.toggle(e.activeClass||"active",i))}const fn=(e,t)=>n=>{n.preventDefault();const{state:s,pageId:i,httpApi:r}=t();i&&r.votes.createVote("page",i,e,a({},r.getUserFields())).then((({data:e})=>{mn(s,e.up,e.down,e.is_up,e.is_down)})).catch((e=>{window.alert(T("voteFail")),console.error("[ArtalkPageVote]",e)}))};const kn="ArtalkUser";class yn{constructor(e){c(this,"data"),this.opts=e;const t=JSON.parse(window.localStorage.getItem(kn)||"{}");this.data={name:t.name||t.nick||"",email:t.email||"",link:t.link||"",token:t.token||"",is_admin:t.is_admin||t.isAdmin||!1}}getData(){return this.data}update(e={}){Object.entries(e).forEach((([e,t])=>{this.data[e]=t})),window.localStorage.setItem(kn,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}}function vn(e){const t=h('<div class="atk-checker-iframe-wrap"></div>'),n=h('<iframe class="atk-fade-in" referrerpolicy="strict-origin-when-cross-origin"></iframe>');n.style.display="none",Qt(t,{transparentBg:!0}),n.src=e.getOpts().getCaptchaIframeURL(),n.onload=()=>{n.style.display="",Kt(t)},t.append(n);const s=h('<div class="atk-close-btn"><i class="atk-icon atk-icon-close"></i></div>');t.append(s),e.hideInteractInput();let i=!1;return function t(){return d(this,null,(function*(){var n;if(yield(n=1e3,new Promise((e=>{window.setTimeout((()=>{e(null)}),n)}))),i)return;let s=!1;try{s=(yield e.getApi().captcha.getCaptchaStatus()).data.is_pass}catch(r){s=!1}s?e.triggerSuccess():t()}))}(),s.onclick=()=>{i=!0,e.cancel()},t}const wn={request:(e,t)=>e.getApi().captcha.verifyCaptcha({value:t}),body:e=>e.get("iframe")?vn(e):function(e){const t=h(`<span><img class="atk-captcha-img" src="${e.get("img_data")||""}">${T("captchaCheck")}</span>`);return t.querySelector(".atk-captcha-img").onclick=()=>{const n=t.querySelector(".atk-captcha-img");e.getApi().captcha.getCaptcha().then((e=>{n.setAttribute("src",e.data.img_data)})).catch((e=>{console.error("Failed to get captcha image ",e)}))},t}(e),onSuccess(e,t,n,s){e.set("val",n)},onError(e,t,n,s){s.querySelector(".atk-captcha-img").click(),s.querySelector('input[type="text"]').value=""}},$n={inputType:"password",request(e,t){return d(this,null,(function*(){return(yield e.getApi().user.login({name:e.getUser().getData().name,email:e.getUser().getData().email,password:t})).data}))},body:e=>h(`<span>${T("adminCheck")}</span>`),onSuccess(e,t,n,s){e.getUser().update({is_admin:!0,token:t.token}),e.getOpts().onReload()},onError(e,t,n,s){}};class bn{constructor(e){c(this,"$el"),c(this,"$content"),c(this,"$actions"),this.$el=h('<div class="atk-layer-dialog-wrap">\n <div class="atk-layer-dialog">\n <div class="atk-layer-dialog-content"></div>\n <div class="atk-layer-dialog-actions"></div>\n </div>\n </div>'),this.$actions=this.$el.querySelector(".atk-layer-dialog-actions"),this.$content=this.$el.querySelector(".atk-layer-dialog-content"),this.$content.appendChild(e)}setYes(e){const t=h(`<button data-action="confirm">${T("confirm")}</button>`);return t.onclick=this.onBtnClick(e),this.$actions.appendChild(t),this}setNo(e){const t=h(`<button data-action="cancel">${T("cancel")}</button>`);return t.onclick=this.onBtnClick(e),this.$actions.appendChild(t),this}onBtnClick(e){return t=>{const n=e(t.currentTarget,this);void 0!==n&&!0!==n||this.$el.remove()}}}function xn(e){return t=>new Promise(((n,s)=>{const i=t.onCancel;t.onCancel=()=>{i&&i(),s(new Error("user canceled the checker"))};const r=t.onSuccess;t.onSuccess=()=>{r&&r(),n()},e(t)}))}class En{constructor(e){c(this,"checkCaptcha",xn((e=>{this.check(wn,e,(t=>{t.set("img_data",e.img_data),t.set("iframe",e.iframe)}))}))),c(this,"checkAdmin",xn((e=>{this.check($n,e)}))),this.opts=e}check(e,t,n){const s=this.opts.getLayers().create(`checker-${(new Date).getTime()}`);s.show();const i=()=>{s.destroy()},r={};let o=!1;const a={set:(e,t)=>{r[e]=t},get:e=>r[e],getOpts:()=>this.opts,getUser:()=>this.opts.getUser(),getApi:()=>this.opts.getApi(),hideInteractInput:()=>{o=!0},triggerSuccess:()=>{i(),e.onSuccess&&e.onSuccess(a,"","",l),t.onSuccess&&t.onSuccess()},cancel:()=>{i(),t.onCancel&&t.onCancel()}};n&&n(a);const l=h();l.appendChild(e.body(a));const c=h(`<input id="check" type="${e.inputType||"text"}" autocomplete="off" required placeholder="">`);let d;l.appendChild(c),setTimeout((()=>c.focus()),80),c.onkeyup=e=>{"Enter"!==e.key&&13!==e.keyCode||(e.preventDefault(),s.getEl().querySelector('button[data-action="confirm"]').click())};const u=new bn(l);u.setYes((n=>{const s=c.value.trim();d||(d=n.innerText);const r=()=>{n.innerText=d||"",n.classList.remove("error")};return n.innerText=`${T("loading")}...`,e.request(a,s).then((n=>{i(),e.onSuccess&&e.onSuccess(a,n,s,l),t.onSuccess&&t.onSuccess()})).catch((t=>{var i;i=String(t.message||String(t)),n.innerText=i,n.classList.add("error"),e.onError&&e.onError(a,t,s,l);const o=setTimeout((()=>r()),3e3);c.onfocus=()=>{r(),clearTimeout(o)}})),!1})),u.setNo((()=>(i(),t.onCancel&&t.onCancel(),!1))),o&&(c.style.display="none",u.$el.querySelector(".atk-layer-dialog-actions").style.display="none"),s.getEl().append(u.$el),t.onMount&&t.onMount(u.$el)}}const Cn={$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 Sn{constructor(e){c(this,"stateCurt","normal"),c(this,"stateUnmountFn",null),this.editor=e}get(){return this.stateCurt}switch(e,t){var n,s,i,r,o,a,l;if(this.stateUnmountFn&&(this.stateUnmountFn(),this.stateUnmountFn=null,null==(s=null==(n=this.editor.getPlugins())?void 0:n.get(Vt))||s.back()),"normal"!==e&&t){let n=t.$comment;this.editor.getOptions().getConf().get().flatMode||(n=n.querySelector(".atk-footer")),null==(r=null==(i=this.editor.getPlugins())?void 0:i.get(Vt))||r.move(n);const s=null==(a=(o=this.editor.getOptions().getConf().get()).scrollRelativeTo)?void 0:a.call(o);Yt(this.editor.getUI().$el,!0,s);const c=null==(l=this.editor.getPlugins())?void 0:l.getPlugins().find((t=>t.editorStateEffectWhen===e));c&&c.editorStateEffect&&(this.stateUnmountFn=c.editorStateEffect(t.comment))}this.stateCurt=e}}class Tn{constructor(e){c(this,"opts"),c(this,"$el"),c(this,"ui"),c(this,"state"),c(this,"plugins"),this.opts=e,this.ui=function(){const e=h('<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'),t={$el:e};return Object.entries(Cn).forEach((([n,s])=>{t[n]=e.querySelector(s)})),t}(),this.$el=this.ui.$el,this.state=new Sn(this)}getOptions(){return this.opts}getEl(){return this.$el}getUI(){return this.ui}getPlugins(){return this.plugins}setPlugins(e){this.plugins=e}getState(){return this.state.get()}getHeaderInputEls(){return{name:this.ui.$name,email:this.ui.$email,link:this.ui.$link}}getContentFinal(){let e=this.getContentRaw();const t=this.getPlugins();return t&&(e=t.getTransformedContent(e)),e}getContentRaw(){return this.ui.$textarea.value||""}getContentMarked(){return Lt(this.getContentFinal())}setContent(e){var t;this.ui.$textarea.value=e,null==(t=this.getPlugins())||t.getEvents().trigger("content-updated",e)}insertContent(e){if(document.selection)this.ui.$textarea.focus(),document.selection.createRange().text=e,this.ui.$textarea.focus();else if(this.ui.$textarea.selectionStart||0===this.ui.$textarea.selectionStart){const t=this.ui.$textarea.selectionStart,n=this.ui.$textarea.selectionEnd,s=this.ui.$textarea.scrollTop;this.setContent(this.ui.$textarea.value.substring(0,t)+e+this.ui.$textarea.value.substring(n,this.ui.$textarea.value.length)),this.ui.$textarea.focus(),this.ui.$textarea.selectionStart=t+e.length,this.ui.$textarea.selectionEnd=t+e.length,this.ui.$textarea.scrollTop=s}else this.ui.$textarea.focus(),this.ui.$textarea.value+=e}focus(){this.ui.$textarea.focus()}reset(){this.setContent(""),this.resetState()}resetState(){this.state.switch("normal")}setReplyComment(e,t){this.state.switch("reply",{comment:e,$comment:t})}setEditComment(e,t){this.state.switch("edit",{comment:e,$comment:t})}showNotify(e,t){!function(e,t,n){const s=h(`<div class="atk-notify atk-fade-in" style="background-color: ${{s:"#57d59f",e:"#ff6f6c",w:"#ffc721",i:"#2ebcfc"}[n]}"><span class="atk-notify-content"></span></div>`);s.querySelector(".atk-notify-content").innerHTML=u(t).replace("\n","<br/>"),e.appendChild(s);const i=()=>{s.classList.add("atk-fade-out"),setTimeout((()=>{s.remove()}),200)};let r;r=window.setTimeout((()=>{i()}),3e3),s.addEventListener("click",(()=>{i(),window.clearTimeout(r)}))}(this.ui.$notifyWrap,e,t)}showLoading(){Qt(this.ui.$el)}hideLoading(){Kt(this.ui.$el)}submit(){const e=()=>{var e;null==(e=this.getPlugins())||e.getEvents().trigger("editor-submit"),this.opts.getEvents().trigger("editor-submit")},t=this.opts.getConf().get().beforeSubmit;t?t(this,e):e()}}class An{constructor(e){c(this,"loading",!1),c(this,"listLastFetch"),c(this,"comments",[]),c(this,"notifies",[]),c(this,"page"),this.events=e}getLoading(){return this.loading}setLoading(e){this.loading=e}getListLastFetch(){return this.listLastFetch}setListLastFetch(e){this.listLastFetch=e}getComments(){return this.comments}fetchComments(e){this.events.trigger("list-fetch",e)}findComment(e){return this.comments.find((t=>t.id===e))}clearComments(){this.comments=[],this.events.trigger("list-loaded",this.comments)}loadComments(e){this.events.trigger("list-load",e),this.comments.push(...e),this.events.trigger("list-loaded",this.comments)}insertComment(e){this.comments.push(e),this.events.trigger("comment-inserted",e),this.events.trigger("list-loaded",this.comments)}updateComment(e){this.comments=this.comments.map((t=>t.id===e.id?e:t)),this.events.trigger("comment-updated",e),this.events.trigger("list-loaded",this.comments)}deleteComment(e){const t=this.comments.find((t=>t.id===e));if(!t)throw new Error(`Comment ${e} not found`);this.comments=this.comments.filter((t=>t.id!==e)),this.events.trigger("comment-deleted",t),this.events.trigger("list-loaded",this.comments)}getNotifies(){return this.notifies}updateNotifies(e){this.notifies=e,this.events.trigger("notifies-updated",this.notifies)}getPage(){return this.page}updatePage(e){this.page=e,this.events.trigger("page-loaded",e)}}class Ln{constructor(e,t){c(this,"allowMaskClose",!0),c(this,"onAfterHide"),this.$el=e,this.opts=t}setOnAfterHide(e){this.onAfterHide=e}setAllowMaskClose(e){this.allowMaskClose=e}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()}}let Pn,Mn;function Rn(){return{init(){Pn=document.body.style.overflow,Mn=document.body.style.paddingRight},unlock(){document.body.style.overflow=Pn,document.body.style.paddingRight=Mn},lock(){document.body.style.overflow="hidden";const e=parseInt(window.getComputedStyle(document.body,null).getPropertyValue("padding-right"),10);document.body.style.paddingRight=`${function(){const e=document.createElement("p");e.style.width="100%",e.style.height="200px";const t=document.createElement("div");t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.visibility="hidden",t.style.width="200px",t.style.height="150px",t.style.overflow="hidden",t.appendChild(e),document.body.appendChild(t);const n=e.offsetWidth;t.style.overflow="scroll";let s=e.offsetWidth;return n===s&&(s=t.clientWidth),document.body.removeChild(t),n-s}()+e||0}px`}}}class Un{constructor(){c(this,"$wrap"),c(this,"$mask"),c(this,"items",[]),this.$wrap=h('<div class="atk-layer-wrap" style="display: none;"><div class="atk-layer-mask"></div></div>'),this.$mask=this.$wrap.querySelector(".atk-layer-mask")}createItem(e,t){(t=t||this.createItemElement(e)).setAttribute("data-layer-name",e),this.$wrap.appendChild(t);const n=new Ln(t,{onHide:()=>this.hideWrap(t),onShow:()=>this.showWrap()});return this.getMask().addEventListener("click",(()=>{n.getAllowMaskClose()&&n.hide()})),this.items.push(n),n}createItemElement(e){const t=document.createElement("div");return t.classList.add("atk-layer-item"),t.style.display="none",this.$wrap.appendChild(t),t}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"),Rn().lock()}hideWrap(e){this.items.map((e=>e.getEl())).filter((t=>t!==e&&t.isConnected&&"none"!==t.style.display)).length>0||(this.$wrap.style.display="none",Rn().unlock())}}class In{constructor(){c(this,"wrap",new Un),Rn().init()}getEl(){return this.wrap.getWrap()}create(e,t){return this.wrap.createItem(e,t)}destroy(){this.wrap.getWrap().remove()}}const jn=e=>({import:t=>{(function(e,t="DATE_DESC",n=2){const s=[];e.filter((e=>0===e.rid)).forEach((t=>{const i={id:t.id,comment:t,children:[],level:1};i.parent=i,s.push(i),function t(s){const i=e.filter((e=>e.rid===s.id));0!==i.length&&(s.level>=n&&(s=s.parent),i.forEach((e=>{const n={id:e.id,comment:e,children:[],parent:s,level:s.level+1};s.children.push(n),t(n)})))}(i)}));const i=(n,s)=>{let i=n.id-s.id;return"DATE_ASC"===t?i=+new Date(n.comment.date)-+new Date(s.comment.date):"DATE_DESC"===t?i=+new Date(s.comment.date)-+new Date(n.comment.date):"SRC_INDEX"===t?i=e.indexOf(n.comment)-e.indexOf(s.comment):"VOTE_UP_DESC"===t&&(i=s.comment.vote_up-n.comment.vote_up),i};return function e(t){t.forEach((t=>{t.children=t.children.sort(i),e(t.children)}))}(s),s})(t,e.nestSortBy,e.nestMax).forEach((n=>{var s;const i=e.createCommentNode(n.comment);null==(s=e.$commentsWrap)||s.appendChild(i.getEl()),i.getRender().playFadeAnim();const r=(n,s)=>{s.children.forEach((s=>{const i=t.find((e=>e.id===s.comment.rid)),o=s.comment,a=e.createCommentNode(o,i);n.putChild(a),r(a,s)}))};r(i,n),i.getRender().checkHeightLimit()}))},insert:(t,n)=>{var s;const i=e.createCommentNode(t,n);if(0===t.rid)null==(s=e.$commentsWrap)||s.prepend(i.getEl());else{const n=e.findCommentNode(t.rid);n&&(n.putChild(i,"DATE_ASC"===e.nestSortBy?"append":"prepend"),i.getParents().forEach((e=>{e.getRender().heightLimitRemoveForChildren()})))}i.getRender().checkHeightLimit(),i.scrollIntoView(),i.getRender().playFadeAnim()}});function On(e,t,n,s){n.is_collapsed&&(n.is_allow_reply=!1);const i=e.createCommentNode(n,s);if(n.visible){const n=i.getEl(),s=e.$commentsWrap;"append"===t&&(null==s||s.append(n)),"prepend"===t&&(null==s||s.prepend(n)),i.getRender().playFadeAnim()}return i.getRender().checkHeightLimit(),i}class Dn{constructor(e){this.options=e}getStrategy(){return this.options.flatMode?(e=this.options,{import:t=>{t.forEach((n=>{const s=0===n.rid?void 0:t.find((e=>e.id===n.rid));On(e,"append",n,s)}))},insert:(t,n)=>{On(e,"prepend",t,n).scrollIntoView()}}):jn(this.options);var e}import(e){this.getStrategy().import(e)}insert(e,t){this.getStrategy().insert(e,t)}}function Bn(e,t){t.forEach((({el:t,max:n,imgCheck:s})=>{if(!t)return;s&&(t.style.maxHeight=`${n+1}px`);let i=!1;const r=()=>{if(i)return;if(function(e){return parseFloat(getComputedStyle(e,null).height.replace("px",""))||0}(t)<=n)return;e.scrollable?function(e){if(!e.el)return;if(e.el.classList.contains(zn))return;e.el.classList.add(zn),e.el.style.height=`${e.max}px`}({el:t,max:n}):function(e){if(!e.el)return;if(!e.max)return;if(e.el.classList.contains(qn))return;e.el.classList.add(qn),e.el.style.height=`${e.max}px`,e.el.style.overflow="hidden";const t=h(`<div class="atk-height-limit-btn">${T("readMore")}</span>`);t.onclick=t=>{t.stopPropagation(),_n(e.el),e.afterExpandBtnClick&&e.afterExpandBtnClick(t)},e.el.append(t)}({el:t,max:n,afterExpandBtnClick:()=>{var t;i=!0,null==(t=e.afterExpandBtnClick)||t.call(e)}})};if(r(),s){const e=t.querySelectorAll(".atk-content img");0===e.length&&(t.style.maxHeight=""),e.forEach((e=>{e.onload=()=>r()}))}}))}const qn="atk-height-limit";function _n(e){e&&e.classList.contains(qn)&&(e.classList.remove(qn),Array.from(e.children).forEach((e=>{e.classList.contains("atk-height-limit-btn")&&e.remove()})),e.style.height="",e.style.maxHeight="",e.style.overflow="")}const zn="atk-height-limit-scroll";function Fn(e){if(e.$headerNick=e.$el.querySelector(".atk-nick"),e.data.link){const t=h('<a target="_blank" rel="noreferrer noopener nofollow"></a>');t.innerText=e.data.nick,t.href=y(e.data.link)?e.data.link:`https://${e.data.link}`,e.$headerNick.append(t)}else e.$headerNick.innerText=e.data.nick}function Wn(e){e.$headerBadgeWrap=e.$el.querySelector(".atk-badge-wrap"),e.$headerBadgeWrap.innerHTML="";const t=e.data.badge_name,n=e.data.badge_color;if(t){const s=h('<span class="atk-badge"></span>');s.innerText=t.replace("管理员",T("admin")),s.style.backgroundColor=n||"",e.$headerBadgeWrap.append(s)}else if(e.data.is_verified){const t=h(`<span class="atk-icon-verified" title="${T("emailVerified")}"></span>`);e.$headerBadgeWrap.append(t)}if(e.data.is_pinned){const t=h(`<span class="atk-pinned-badge">${T("pin")}</span>`);e.$headerBadgeWrap.append(t)}}function Nn(e){const t=e.$el.querySelector(".atk-date");t.innerText=e.comment.getDateFormatted(),t.setAttribute("data-atk-comment-date",String(+new Date(e.data.date)))}function Hn(e){if(!e.opts.uaBadge&&!e.data.ip_region)return;let t=e.$header.querySelector("atk-ua-wrap");if(t||(t=h('<span class="atk-ua-wrap"></span>'),e.$header.append(t)),t.innerHTML="",e.data.ip_region){const n=h('<span class="atk-region-badge"></span>');n.innerText=e.data.ip_region,t.append(n)}if(e.opts.uaBadge){const{browser:n,os:s}=e.comment.getUserUA();if(String(n).trim()){const e=h('<span class="atk-ua ua-browser"></span>');e.innerText=n,t.append(e)}if(String(s).trim()){const e=h('<span class="atk-ua ua-os"></span>');e.innerText=s,t.append(e)}}}class Vn{constructor(e){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=h('<span class="atk-common-action-btn"></span>'),this.opts="object"!=typeof e?{text:e}:e,this.$el.innerText=this.getText(),this.opts.adminOnly&&this.$el.setAttribute("atk-only-admin-show","")}get isMessaging(){return!!this.msgRecTimer}appendTo(e){return e.append(this.$el),this}getText(){return"string"==typeof this.opts.text?this.opts.text:this.opts.text()}setClick(e){this.$el.onclick=t=>{if(t.stopPropagation(),!this.isLoading){if(this.opts.confirm&&!this.isMessaging){const e=()=>{this.isConfirming=!1,this.$el.classList.remove("atk-btn-confirm"),this.$el.innerText=this.getText()};if(!this.isConfirming)return this.isConfirming=!0,this.$el.classList.add("atk-btn-confirm"),this.$el.innerText=this.opts.confirmText||T("actionConfirm"),void(this.confirmRecTimer=window.setTimeout((()=>e()),5e3));this.confirmRecTimer&&window.clearTimeout(this.confirmRecTimer),e()}if(this.msgRecTimer)return this.fireMsgRecTimer(),void this.clearMsgRecTimer();e()}}}updateText(e){e&&(this.opts.text=e),this.setLoading(!1),this.$el.innerText=this.getText()}setLoading(e,t){this.isLoading!==e&&(this.isLoading=e,e?(this.$el.classList.add("atk-btn-loading"),this.$el.innerText=t||`${T("loading")}...`):(this.$el.classList.remove("atk-btn-loading"),this.$el.innerText=this.getText()))}setError(e){this.setMsg(e,"atk-btn-error")}setWarn(e){this.setMsg(e,"atk-btn-warn")}setSuccess(e){this.setMsg(e,"atk-btn-success")}setMsg(e,t,n,s){this.setLoading(!1),t&&this.$el.classList.add(t),this.$el.innerText=e,this.setMsgRecTimer((()=>{this.$el.innerText=this.getText(),t&&this.$el.classList.remove(t),s&&s()}),n||2500)}setMsgRecTimer(e,t){this.fireMsgRecTimer(),this.clearMsgRecTimer(),this.msgRecTimerFunc=e,this.msgRecTimer=window.setTimeout((()=>{e(),this.clearMsgRecTimer()}),t)}fireMsgRecTimer(){this.msgRecTimerFunc&&this.msgRecTimerFunc()}clearMsgRecTimer(){this.msgRecTimer&&window.clearTimeout(this.msgRecTimer),this.msgRecTimer=void 0,this.msgRecTimerFunc=void 0}}function Qn(e){e.opts.vote&&(e.voteBtnUp=new Vn((()=>`${T("voteUp")} (${e.data.vote_up||0})`)).appendTo(e.$actions),e.voteBtnUp.setClick((()=>{e.comment.getActions().vote("up")})),e.opts.voteDown&&(e.voteBtnDown=new Vn((()=>`${T("voteDown")} (${e.data.vote_down||0})`)).appendTo(e.$actions),e.voteBtnDown.setClick((()=>{e.comment.getActions().vote("down")}))))}function Kn(e){if(!e.data.is_allow_reply)return;const t=new Vn({text:T("reply")});t.appendTo(e.$actions),t.setClick((()=>{e.opts.replyComment(e.data,e.$el)}))}function Gn(e){const t=new Vn({text:()=>e.data.is_collapsed?T("expand"):T("collapse"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminEdit("collapsed",t)}))}function Yn(e){const t=new Vn({text:()=>e.data.is_pending?T("pending"):T("approved"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminEdit("pending",t)}))}function Zn(e){const t=new Vn({text:()=>e.data.is_pinned?T("unpin"):T("pin"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminEdit("pinned",t)}))}function Xn(e){const t=new Vn({text:T("edit"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.opts.editComment(e.data,e.$el)}))}function Jn(e){const t=new Vn({text:T("delete"),confirm:!0,confirmText:T("deleteConfirm"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminDelete(t)}))}const es={Avatar:function(e){const t=e.$el.querySelector(".atk-avatar"),n=h("<img />"),s=e.opts.avatarURLBuilder;if(n.src=s?s(e.data):e.comment.getGravatarURL(),e.data.link){const s=h('<a target="_blank" rel="noreferrer noopener nofollow"></a>');s.href=y(e.data.link)?e.data.link:`https://${e.data.link}`,s.append(n),t.append(s)}else t.append(n)},Header:function(e){Object.entries({renderNick:Fn,renderVerifyBadge:Wn,renderDate:Nn,renderUABadge:Hn}).forEach((([t,n])=>{n(e)}))},Content:function(e){if(!e.data.is_collapsed)return e.$content.innerHTML=e.comment.getContentMarked(),void e.$content.classList.remove("atk-hide","atk-collapsed");e.$content.classList.add("atk-hide","atk-type-collapsed");const t=h(`\n <div class="atk-collapsed">\n <span class="atk-text">${T("collapsedMsg")}</span>\n <span class="atk-show-btn">${T("expand")}</span>\n </div>`);e.$body.insertAdjacentElement("beforeend",t);const n=t.querySelector(".atk-show-btn");n.addEventListener("click",(t=>{t.stopPropagation(),e.$content.classList.contains("atk-hide")?(e.$content.innerHTML=e.comment.getContentMarked(),e.$content.classList.remove("atk-hide"),Zt(e.$content),n.innerText=T("collapse")):(e.$content.innerHTML="",e.$content.classList.add("atk-hide"),n.innerText=T("expand"))}))},ReplyAt:function(e){e.opts.flatMode||0===e.data.rid||e.opts.replyTo&&(e.$replyAt=h('<span class="atk-item atk-reply-at"><span class="atk-arrow"></span><span class="atk-nick"></span></span>'),e.$replyAt.querySelector(".atk-nick").innerText=`${e.opts.replyTo.nick}`,e.$replyAt.onclick=()=>{e.comment.getActions().goToReplyComment()},e.$headerBadgeWrap.insertAdjacentElement("afterend",e.$replyAt))},ReplyTo:function(e){if(!e.opts.flatMode)return;if(!e.opts.replyTo)return;e.$replyTo=h(`\n <div class="atk-reply-to">\n <div class="atk-meta">${T("reply")} <span class="atk-nick"></span>:</div>\n <div class="atk-content"></div>\n </div>`);const t=e.$replyTo.querySelector(".atk-nick");t.innerText=`@${e.opts.replyTo.nick}`,t.onclick=()=>{e.comment.getActions().goToReplyComment()};let n=Lt(e.opts.replyTo.content);e.opts.replyTo.is_collapsed&&(n=`[${T("collapsed")}]`),e.$replyTo.querySelector(".atk-content").innerHTML=n,e.$body.prepend(e.$replyTo)},Pending:function(e){if(!e.data.is_pending)return;const t=h(`<div class="atk-pending">${T("pendingMsg")}</div>`);e.$body.prepend(t)},Actions:function(e){Object.entries({renderVote:Qn,renderReply:Kn,renderCollapse:Gn,renderModerator:Yn,renderPin:Zn,renderEdit:Xn,renderDel:Jn}).forEach((([t,n])=>{n(e)}))}};class ts{constructor(e){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=e}get data(){return this.comment.getData()}get opts(){return this.comment.getOpts()}render(){var e;return this.$el=h('<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}`),e=this,Object.entries(es).forEach((([t,n])=>{n(e)})),this.$childrenWrap&&this.$main.append(this.$childrenWrap),this.$el}checkHeightLimit(){const e=this.opts.heightLimit;if(!e||!e.content||!e.children)return;const t=e.content,n=e.children;Bn({afterExpandBtnClick:()=>{const e=this.comment.getChildren();1===e.length&&_n(e[0].getRender().$content)},scrollable:e.scrollable},[{el:this.$content,max:t,imgCheck:!0},{el:this.$replyTo,max:t,imgCheck:!0},{el:this.$childrenWrap,max:n,imgCheck:!1}])}heightLimitRemoveForChildren(){this.$childrenWrap&&_n(this.$childrenWrap)}playFadeAnim(){Zt(this.comment.getRender().$el)}playFadeAnimForBody(){Zt(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=h('<div class="atk-comment-children"></div>'),this.$main.append(this.$childrenWrap)),this.$childrenWrap}setUnread(e){e?this.$el.classList.add("atk-unread"):this.$el.classList.remove("atk-unread")}setOpenable(e){e?this.$el.classList.add("atk-openable"):this.$el.classList.remove("atk-openable")}setOpenURL(e){this.setOpenable(!0),this.$el.onclick=t=>{t.stopPropagation(),window.open(e)}}setOpenAction(e){this.setOpenable(!0),this.$el.onclick=t=>{t.stopPropagation(),e()}}}class ns{constructor(e){c(this,"comment"),this.comment=e}get data(){return this.comment.getData()}get opts(){return this.comment.getOpts()}getApi(){return this.comment.getOpts().getApi()}vote(e){const t="up"===e?this.comment.getRender().voteBtnUp:this.comment.getRender().voteBtnDown;this.getApi().votes.createVote("comment",this.data.id,e,a({},this.getApi().getUserFields())).then((e=>{var t,n;this.data.vote_up=e.data.up,this.data.vote_down=e.data.down,null==(t=this.comment.getRender().voteBtnUp)||t.updateText(),null==(n=this.comment.getRender().voteBtnDown)||n.updateText()})).catch((e=>{null==t||t.setError(T("voteFail")),console.error(e)}))}adminEdit(e,t){if(t.isLoading)return;t.setLoading(!0,`${T("editing")}...`);const n=a({},this.data);"collapsed"===e?n.is_collapsed=!n.is_collapsed:"pending"===e?n.is_pending=!n.is_pending:"pinned"===e&&(n.is_pinned=!n.is_pinned),this.getApi().comments.updateComment(this.data.id,a({},n)).then((e=>{t.setLoading(!1),this.comment.setData(e.data)})).catch((e=>{console.error(e),t.setError(T("editFail"))}))}adminDelete(e){e.isLoading||(e.setLoading(!0,`${T("deleting")}...`),this.getApi().comments.deleteComment(this.data.id).then((()=>{e.setLoading(!1),this.opts.onDelete&&this.opts.onDelete(this.comment)})).catch((t=>{console.error(t),e.setError(T("deleteFail"))})))}goToReplyComment(){const e=window.location.hash,t=`#atk-comment-${this.data.rid}`;window.location.hash=t,t===e&&window.dispatchEvent(new Event("hashchange"))}}class ss{constructor(e,t){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=t,this.data=a({},e),this.data.date=this.data.date.replace(/-/g,"/"),this.parent=null,this.nestCurt=1,this.actionInstance=new ns(this),this.renderInstance=new ts(this)}render(){const e=this.renderInstance.render();this.$el&&this.$el.replaceWith(e),this.$el=e,this.opts.onAfterRender&&this.opts.onAfterRender()}getActions(){return this.actionInstance}getRender(){return this.renderInstance}getData(){return this.data}setData(e){this.data=e,this.render(),this.getRender().playFadeAnimForBody()}getParent(){return this.parent}getChildren(){return this.children}getNestCurt(){return this.nestCurt}getIsRoot(){return 0===this.data.rid}getID(){return this.data.id}putChild(e,t="append"){e.parent=this,e.nestCurt=this.nestCurt+1,this.children.push(e);const n=this.getChildrenWrapEl(),s=e.getEl();"append"===t?n.append(s):"prepend"===t&&n.prepend(s),e.getRender().playFadeAnim(),e.getRender().checkHeightLimit()}getChildrenWrapEl(){return this.nestCurt>=this.opts.nestMax?this.parent.getChildrenWrapEl():this.getRender().getChildrenWrap()}getParents(){const e=[];let t=this.parent;for(;t;)e.push(t),t=t.getParent();return e}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((e=>{e.getRender().heightLimitRemoveForChildren()})),this.scrollIntoView(),this.getRender().playFlashAnim()}scrollIntoView(){this.$el&&Yt(this.$el,!1,this.opts.scrollRelativeTo&&this.opts.scrollRelativeTo())}remove(){var e;null==(e=this.$el)||e.remove()}getGravatarURL(){return`${(e={mirror:this.opts.gravatar.mirror,params:this.opts.gravatar.params,emailHash:this.data.email_encrypted}).mirror.replace(/\/$/,"")}/${e.emailHash}?${e.params.replace(/^\?/,"")}`;var e}getContentMarked(){return Lt(this.data.content)}getDateFormatted(){var e,t;const n=new Date(this.data.date);return(null==(t=(e=this.opts).dateFormatter)?void 0:t.call(e,n))||f(n,T)}getUserUA(){const e=function(e){const t=window||{},n=navigator||{},s=String(e||n.userAgent),i={os:"",osVersion:"",engine:"",browser:"",device:"",language:"",version:""},r={Trident:s.includes("Trident")||s.includes("NET CLR"),Presto:s.includes("Presto"),WebKit:s.includes("AppleWebKit"),Gecko:s.includes("Gecko/")},o={Safari:s.includes("Safari"),Chrome:s.includes("Chrome")||s.includes("CriOS"),IE:s.includes("MSIE")||s.includes("Trident"),Edge:s.includes("Edge")||s.includes("Edg"),Firefox:s.includes("Firefox")||s.includes("FxiOS"),"Firefox Focus":s.includes("Focus"),Servo:s.includes("Servo"),Chromium:s.includes("Chromium"),Opera:s.includes("Opera")||s.includes("OPR"),Vivaldi:s.includes("Vivaldi"),Yandex:s.includes("YaBrowser"),Kindle:s.includes("Kindle")||s.includes("Silk/"),360:s.includes("360EE")||s.includes("360SE"),UC:s.includes("UC")||s.includes(" UBrowser"),QQBrowser:s.includes("QQBrowser"),QQ:s.includes("QQ/"),Baidu:s.includes("Baidu")||s.includes("BIDUBrowser"),Maxthon:s.includes("Maxthon"),Sogou:s.includes("MetaSr")||s.includes("Sogou"),LBBROWSER:s.includes("LBBROWSER"),"2345Explorer":s.includes("2345Explorer"),TheWorld:s.includes("TheWorld"),MIUI:s.includes("MiuiBrowser"),HuaweiBrowser:s.includes("HuaweiBrowser"),Quark:s.includes("Quark"),Qiyu:s.includes("Qiyu"),"360Browser":s.includes("360Browser"),Wechat:s.includes("MicroMessenger"),Taobao:s.includes("AliApp(TB"),Alipay:s.includes("AliApp(AP"),Weibo:s.includes("Weibo"),Douban:s.includes("com.douban.frodo"),Suning:s.includes("SNEBUY-APP"),iQiYi:s.includes("IqiyiApp")},a={Windows:s.includes("Windows"),Linux:s.includes("Linux")||s.includes("X11"),macOS:s.includes("Macintosh"),Android:s.includes("Android")||s.includes("Adr"),Ubuntu:s.includes("Ubuntu"),FreeBSD:s.includes("FreeBSD"),Debian:s.includes("Debian"),"Windows Phone":s.includes("IEMobile")||s.includes("Windows Phone"),BlackBerry:s.includes("BlackBerry")||s.includes("RIM"),MeeGo:s.includes("MeeGo"),Symbian:s.includes("Symbian"),iOS:s.includes("like Mac OS X"),OpenHarmony:s.includes("OpenHarmony"),"Chrome OS":s.includes("CrOS"),WebOS:s.includes("hpwOS")},l={Mobile:s.includes("Mobi")||s.includes("iPh")||s.includes("480")||s.includes("Phone"),Tablet:s.includes("Tablet")||s.includes("Pad")||s.includes("Nexus 7")};l.Mobile?l.Mobile=!s.includes("iPad"):o.Chrome&&s.includes("Edg")?(o.Chrome=!1,o.Edge=!0):t.showModalDialog&&t.chrome&&(o.Chrome=!1,o[360]=!0),i.device="PC",i.language=(()=>{const e=(n.browserLanguage||n.language).split("-");return e[1]&&(e[1]=e[1].toUpperCase()),e.join("_")})();const c={engine:r,browser:o,os:a,device:l};Object.entries(c).forEach((([e,t])=>{Object.entries(t).forEach((([t,n])=>{!0===n&&(i[e]=t)}))}));const d={Windows:()=>{const e=s.replace(/^.*Windows NT ([\d.]+);.*$/,"$1");return{6.4:"10",6.3:"8.1",6.2:"8",6.1:"7","6.0":"Vista",5.2:"XP",5.1:"XP","5.0":"2000","10.0":"10","11.0":"11"}[e]||e},Android:()=>s.replace(/^.*Android ([\d.]+);.*$/,"$1"),iOS:()=>s.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,"."),Debian:()=>s.replace(/^.*Debian\/([\d.]+).*$/,"$1"),"Windows Phone":()=>s.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2"),macOS:()=>s.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,"."),OpenHarmony:()=>s.replace(/^.*OpenHarmony ([\d.]+).*$/,"$1"),WebOS:()=>s.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")};i.osVersion="",d[i.os]&&(i.osVersion=d[i.os](),i.osVersion===s&&(i.osVersion=""));const h={Safari:()=>s.replace(/^.*Version\/([\d.]+).*$/,"$1"),Chrome:()=>s.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1"),IE:()=>s.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1"),Edge:()=>s.replace(/^.*(Edge|Edg|Edg[A-Z]{1})\/([\d.]+).*$/,"$2"),Firefox:()=>s.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1"),"Firefox Focus":()=>s.replace(/^.*Focus\/([\d.]+).*$/,"$1"),Servo:()=>s.replace(/^.*Servo\/?([\d.]+).*$/,"$1"),Chromium:()=>s.replace(/^.*Chromium\/([\d.]+).*$/,"$1"),Opera:()=>s.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1"),Vivaldi:()=>s.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1"),Yandex:()=>s.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1"),Kindle:()=>s.replace(/^.*Version\/([\d.]+).*$/,"$1"),Maxthon:()=>s.replace(/^.*Maxthon\/([\d.]+).*$/,"$1"),QQBrowser:()=>s.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1"),QQ:()=>s.replace(/^.*QQ\/([\d.]+).*$/,"$1"),Baidu:()=>s.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1"),UC:()=>s.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1"),Sogou:()=>s.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1"),"2345Explorer":()=>s.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1"),TheWorld:()=>s.replace(/^.*TheWorld ([\d.]+).*$/,"$1"),MIUI:()=>s.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1"),HuaweiBrowser:()=>s.replace(/^.*HuaweiBrowser\/([\d.]+).*$/,"$1"),Quark:()=>s.replace(/^.*Quark\/([\d.]+).*$/,"$1"),Qiyu:()=>s.replace(/^.*Qiyu\/([\d.]+).*$/,"$1"),"360Browser":()=>s.replace(/^.*360Browser\/([\d.]+).*$/,"$1"),Wechat:()=>s.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1"),Taobao:()=>s.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1"),Alipay:()=>s.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1"),Weibo:()=>s.replace(/^.*weibo__([\d.]+).*$/,"$1"),Douban:()=>s.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1"),Suning:()=>s.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1"),iQiYi:()=>s.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")};return i.version="",h[i.browser]&&(i.version=h[i.browser](),i.version===s&&(i.version="")),i.version.indexOf(".")&&(i.version=i.version.substring(0,i.version.indexOf("."))),"iOS"===i.os&&s.includes("iPad")?i.os="iPadOS":"Edge"!==i.browser||s.includes("Edg")?"MIUI"===i.browser?i.os="Android":"Chrome"===i.browser&&Number(i.version)>27||"Opera"===i.browser&&Number(i.version)>12||"Yandex"===i.browser?i.engine="Blink":void 0===i.browser&&(i.browser="Unknow App"):i.engine="EdgeHTML",i}(this.data.ua);return{browser:`${e.browser} ${e.version}`,os:`${e.os} ${e.osVersion}`}}getOpts(){return this.opts}}class is{constructor(e){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=e,this.origText=this.opts.text||this.origText,this.$el=h(`<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(e){this.$loading.style.display=e?"":"none",this.$text.style.display=e?"none":""}showErr(e){this.setLoading(!1),this.$text.innerText=e,this.$el.classList.add("atk-err"),window.setTimeout((()=>{this.$text.innerText=this.origText,this.$el.classList.remove("atk-err")}),2e3)}update(e,t){this.offset=e,this.total=t,this.checkDisabled()}checkDisabled(){this.hasMore?this.show():this.hide()}}class rs{constructor(){c(this,"instance"),c(this,"onReachedBottom",null),c(this,"opt")}create(e){return this.opt=e,this.instance=new is({pageSize:e.pageSize,onClick:t=>d(this,null,(function*(){e.getData().fetchComments({offset:t})})),text:T("loadMore")}),e.readMoreAutoLoad&&(this.onReachedBottom=()=>{this.instance.hasMore&&!this.opt.getData().getLoading()&&this.instance.click()},this.opt.getEvents().on("list-reach-bottom",this.onReachedBottom)),this.instance.$el}setLoading(e){this.instance.setLoading(e)}update(e,t){this.instance.update(e,t)}showErr(e){this.instance.showErr(e)}next(){this.instance.click()}getHasMore(){return this.instance.hasMore}getIsClearComments(e){return 0===e.offset}dispose(){this.onReachedBottom&&this.opt.getEvents().off("list-reach-bottom",this.onReachedBottom),this.instance.$el.remove()}}class os{constructor(e,t){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=e,this.opts=t,this.$el=h('<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=e=>this.keydown(e),this.$prevBtn=this.$el.querySelector(".atk-btn-prev"),this.$nextBtn=this.$el.querySelector(".atk-btn-next"),this.$prevBtn.onclick=()=>this.prev(),this.$nextBtn.onclick=()=>this.next(),this.checkDisabled()}get pageSize(){return this.opts.pageSize}get offset(){return this.pageSize*(this.page-1)}get maxPage(){return Math.ceil(this.total/this.pageSize)}update(e,t){this.page=Math.ceil(e/this.pageSize)+1,this.total=t,this.setInput(this.page),this.checkDisabled()}setInput(e){this.$input.value=`${e}`}input(e=!1){window.clearTimeout(this.inputTimer);const t=this.$input.value.trim(),n=()=>{if(""===t)return void this.setInput(this.page);let e=Number(t);Number.isNaN(e)||e<1?this.setInput(this.page):(e>this.maxPage&&(this.setInput(this.maxPage),e=this.maxPage),this.change(e))};e?n():this.inputTimer=window.setTimeout((()=>n()),800)}prev(){const e=this.page-1;e<1||this.change(e)}next(){const e=this.page+1;e>this.maxPage||this.change(e)}getHasMore(){return this.page+1<=this.maxPage}change(e){this.page=e,this.opts.onChange(this.offset),this.setInput(e),this.checkDisabled()}checkDisabled(){this.page+1>this.maxPage?this.$nextBtn.classList.add("atk-disabled"):this.$nextBtn.classList.remove("atk-disabled"),this.page-1<1?this.$prevBtn.classList.add("atk-disabled"):this.$prevBtn.classList.remove("atk-disabled")}keydown(e){const t=e.keyCode||e.which;if(38===t){const e=Number(this.$input.value)+1;if(e>this.maxPage)return;this.setInput(e),this.input()}else if(40===t){const e=Number(this.$input.value)-1;if(e<1)return;this.setInput(e),this.input()}else 13===t&&this.input(!0)}setLoading(e){e?Qt(this.$el):Kt(this.$el)}}class as{constructor(){c(this,"instance")}create(e){return this.instance=new os(e.total,{pageSize:e.pageSize,onChange:t=>d(this,null,(function*(){e.resetEditorState(),e.getData().fetchComments({offset:t,onSuccess:()=>{var t;null==(t=e.onListGotoFirst)||t.call(e)}})}))}),this.instance.$el}setLoading(e){this.instance.setLoading(e)}update(e,t){this.instance.update(e,t)}next(){this.instance.next()}getHasMore(){return this.instance.getHasMore()}getIsClearComments(){return!0}dispose(){this.instance.$el.remove()}}function ls(e){const t={offset:0,total:0};return e?(t.offset=e.params.offset,e.data&&(t.total=e.params.flatMode?e.data.count:e.data.roots_count),t):t}const cs=e=>{let t=null;e.getConf().watchConf(["pagination","locale"],(n=>{const s=e.getList(),i=e.getData();t&&t.dispose(),t=function(e){return e.pagination.readMore?new rs:new as}(n);const{offset:r,total:o}=ls(i.getListLastFetch()),l=t.create(a({pageSize:n.pagination.pageSize,total:o,readMoreAutoLoad:n.pagination.autoLoad},e));s.getCommentsWrapEl().after(l),null==t||t.update(r,o)})),e.getEvents().on("list-loaded",(n=>{const{offset:s,total:i}=ls(e.getData().getListLastFetch());null==t||t.update(s,i)})),e.getEvents().on("list-fetch",(n=>{e.getData().getComments().length>0&&(null==t?void 0:t.getIsClearComments(n))&&e.getData().clearComments()})),e.getEvents().on("list-failed",(()=>{var e;null==(e=null==t?void 0:t.showErr)||e.call(t,T("loadFail"))})),e.getEvents().on("list-fetch",(e=>{null==t||t.setLoading(!0)})),e.getEvents().on("list-fetched",(({params:e})=>{null==t||t.setLoading(!1)}))};class ds{constructor(e){c(this,"opts"),c(this,"$el"),c(this,"$commentsWrap"),c(this,"commentNodes",[]),this.opts=e,this.$el=h('<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"),cs(a({getList:()=>this},e)),this.initCrudEvents()}getEl(){return this.$el}getCommentsWrapEl(){return this.$commentsWrap}getCommentNodes(){return this.commentNodes}getLayout({forceFlatMode:e}={}){return new Dn({$commentsWrap:this.$commentsWrap,nestSortBy:this.opts.getConf().get().nestSort,nestMax:this.opts.getConf().get().nestMax,flatMode:"boolean"==typeof e?e:this.opts.getConf().get().flatMode,createCommentNode:(t,n)=>{const s=function(e,t,n){const s=e.getConf().get(),i=new ss(t,{onAfterRender:()=>{e.getEvents().trigger("comment-rendered",i)},onDelete:t=>{e.getData().deleteComment(t.getID())},replyTo:n,flatMode:"boolean"==typeof(null==e?void 0:e.forceFlatMode)?null==e?void 0:e.forceFlatMode:s.flatMode,gravatar:s.gravatar,nestMax:s.nestMax,heightLimit:s.heightLimit,avatarURLBuilder:s.avatarURLBuilder,scrollRelativeTo:s.scrollRelativeTo,vote:s.vote,voteDown:s.voteDown,uaBadge:s.uaBadge,dateFormatter:s.dateFormatter,getApi:e.getApi,replyComment:e.replyComment,editComment:e.editComment});return i.render(),i}(a({forceFlatMode:e},this.opts),t,n);return this.commentNodes.push(s),s},findCommentNode:e=>this.commentNodes.find((t=>t.getID()===e))})}initCrudEvents(){this.opts.getEvents().on("list-load",(e=>{this.getLayout().import(e)})),this.opts.getEvents().on("list-loaded",(e=>{0===e.length&&(this.commentNodes=[],this.$commentsWrap.innerHTML="")})),this.opts.getEvents().on("comment-inserted",(e=>{var t;const n=e.rid?null==(t=this.commentNodes.find((t=>t.getID()===e.rid)))?void 0:t.getData():void 0;this.getLayout().insert(e,n)})),this.opts.getEvents().on("comment-deleted",(e=>{const t=this.commentNodes.find((t=>t.getID()===e.id));t?(t.remove(),this.commentNodes=this.commentNodes.filter((t=>t.getID()!==e.id))):console.error(`comment node id=${e.id} not found`)})),this.opts.getEvents().on("comment-updated",(e=>{const t=this.commentNodes.find((t=>t.getID()===e.id));t&&t.setData(e)}))}}class hs{constructor(e){c(this,"opts"),c(this,"$el"),c(this,"layer"),c(this,"$header"),c(this,"$closeBtn"),c(this,"$iframeWrap"),c(this,"$iframe"),c(this,"refreshWhenShow",!0),c(this,"animTimer"),this.opts=e,this.$el=h('<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()}}onUserChanged(){return d(this,null,(function*(){this.refreshWhenShow=!0}))}show(){return d(this,arguments,(function*(e={}){if(this.$el.style.transform="",this.initLayer(),this.layer.show(),this.refreshWhenShow)this.refreshWhenShow=!1,this.$iframeWrap.innerHTML="",this.$iframe=this.createIframe(e.view),this.$iframeWrap.append(this.$iframe);else{const e=this.$iframe,t=e.src;this.getDarkMode()!==t.includes("&darkMode=1")&&this.iframeLoad(e,t.replace(/&darkMode=\d/,`&darkMode=${Number(this.getDarkMode())}`))}this.authCheck({onSuccess:()=>this.show(e)}),this.animTimer=setTimeout((()=>{var e,t;this.animTimer=void 0,this.$el.style.transform="translate(0, 0)",null==(t=(e=this.opts).onShow)||t.call(e)}),100)}))}hide(){var e;null==(e=this.layer)||e.hide()}authCheck(e){return d(this,null,(function*(){const t=(yield this.opts.getApi().user.getUserStatus(a({},this.opts.getApi().getUserFields()))).data;t.is_admin&&!t.is_login&&(this.refreshWhenShow=!0,this.opts.getCheckers().checkAdmin({onSuccess:()=>{setTimeout((()=>{e.onSuccess()}),500)},onCancel:()=>{this.hide()}}),this.hide())}))}initLayer(){this.layer||(this.layer=this.opts.getLayers().create("sidebar",this.$el),this.layer.setOnAfterHide((()=>{var e,t;this.animTimer&&clearTimeout(this.animTimer),this.$el.style.transform="",null==(t=(e=this.opts).onHide)||t.call(e)})))}createIframe(e){const t=h('<iframe referrerpolicy="strict-origin-when-cross-origin"></iframe>'),n=v({base:this.opts.getConf().get().server,path:"/sidebar/"}),s={pageKey:this.opts.getConf().get().pageKey,site:this.opts.getConf().get().site||"",user:JSON.stringify(this.opts.getUser().getData()),time:+new Date};e&&(s.view=e),s.darkMode=this.getDarkMode()?"1":"0";const i=new URLSearchParams(s);return this.iframeLoad(t,`${n}?${i.toString()}`),t}getDarkMode(){return"auto"===this.opts.getConf().get().darkMode?window.matchMedia("(prefers-color-scheme: dark)").matches:this.opts.getConf().get().darkMode}iframeLoad(e,t){e.src=t,Qt(this.$iframeWrap),e.onload=()=>{Kt(this.$iframeWrap)}}}const us=[...new Set([e=>{e.provide("data",(e=>new An(e)),["events"]),e.on("mounted",(()=>{e.getConf().fetchCommentsOnInit&&e.getData().fetchComments({offset:0})}))},e=>{e.provide("apiHandlers",(()=>function(){const e=[];return{add:(t,n)=>{e.push({action:t,handler:n})},remove:t=>{const n=e.findIndex((e=>e.action===t));-1!==n&&e.splice(n,1)},get:()=>e}}()),[]),e.provide("api",((e,t,n)=>new zt(It(t.get(),e,n))),["user","config","apiHandlers"],{lifecycle:"transient"})},e=>{e.watchConf(["locale"],(e=>{var t;(t=e.locale)!==C&&(C=t,S="string"==typeof t?E(t):t)}))},e=>{e.provide("user",(()=>new yn({onUserChanged:t=>{e.trigger("user-changed",t)}})),[])},e=>{e.provide("editor",((t,n)=>{const s=new Tn({getEvents:()=>t,getConf:()=>n});return e.getEl().appendChild(s.getEl()),s}),["events","config"])},e=>{e.provide("list",((t,n,s,i,r)=>{const o=new ds({getApi:()=>t,getEvents:()=>n,getConf:()=>s,getData:()=>i,replyComment:(e,t)=>r.setReplyComment(e,t),editComment:(e,t)=>r.setEditComment(e,t),resetEditorState:()=>r.resetState(),onListGotoFirst:()=>e.listGotoFirst()});return e.getEl().appendChild(o.getEl()),o}),["api","events","config","data","editor"])},e=>{e.provide("checkers",((t,n,s,i,r)=>{const o=new En({getApi:()=>t,getLayers:()=>s,getUser:()=>i,onReload:()=>e.reload(),getCaptchaIframeURL:()=>`${r.get().server}/api/v2/captcha/?t=${+new Date}`});return n.add("need_captcha",(e=>o.checkCaptcha(e))),n.add("need_login",(()=>o.checkAdmin({}))),o}),["api","apiHandlers","layers","user","config"])},e=>{e.provide("layers",(()=>{const t=new In;return document.body.appendChild(t.getEl()),e.on("unmounted",(()=>{null==t||t.destroy()})),t}))},e=>{e.provide("sidebar",((t,n,s,i,r,o,a,l)=>{const c=new hs({onShow:()=>{setTimeout((()=>{n.updateNotifies([])}),0),t.trigger("sidebar-show")},onHide:()=>{s.resetState(),t.trigger("sidebar-hide")},getCheckers:()=>i,getApi:()=>r,getConf:()=>o,getUser:()=>a,getLayers:()=>l});return e.on("user-changed",(()=>{null==c||c.onUserChanged()})),c}),["events","data","editor","checkers","api","config","user","layers"])}]),e=>{e.watchConf(["imgLazyLoad","markedOptions"],(e=>{!function(e){try{if(!Ue.name)return}catch(n){return}const t=new Ue;t.setOptions(a(a({renderer:$t({imgLazyLoad:e.imgLazyLoad})},Tt),e.markedOptions)),Ct=t}({markedOptions:e.markedOptions,imgLazyLoad:e.imgLazyLoad})})),e.watchConf(["markedReplacers"],(e=>{var t;e.markedReplacers&&(t=e.markedReplacers,St=t)}))},e=>{e.provide("editorPlugs",((t,n,s,i,r,o)=>{const a=new an({getArtalkRootEl:()=>e.getEl(),getEditor:()=>t,getConf:()=>n,getUser:()=>s,getApi:()=>o,getData:()=>i,getCheckers:()=>r,onSubmitted:()=>e.trigger("editor-submitted")});return t.setPlugins(a),a}),["editor","config","user","data","checkers","api"])},e=>{const t=e.inject("user"),n=()=>{var n;n=t.getData().is_admin,function(e){const t=[];e.$root.querySelectorAll("[atk-only-admin-show]").forEach((e=>t.push(e)));const n=document.querySelector(".atk-sidebar");return n&&n.querySelectorAll("[atk-only-admin-show]").forEach((e=>t.push(e))),t}({$root:e.getEl()}).forEach((e=>{n?e.classList.remove("atk-hide"):e.classList.add("atk-hide")}))};e.on("list-loaded",(()=>{n()})),e.on("user-changed",(e=>{n()}))},...dn,e=>{e.on("list-fetch",(t=>{if(0!==t.offset)return;const n=e.getApi().getUserFields();n&&e.getApi().notifies.getNotifies(n).then((t=>{e.getData().updateNotifies(t.data.notifies)}))}))},e=>{e.watchConf(["site","pageKey","pageTitle","countEl","pvEl","statPageKeyAttr","pvAdd"],(t=>{jt({getApi:()=>e.getApi(),siteName:t.site,pageKey:t.pageKey,pageTitle:t.pageTitle,countEl:t.countEl,pvEl:t.pvEl,pageKeyAttr:t.statPageKeyAttr,pvAdd:t.pvAdd})}))},e=>{const t=e.inject("list");e.watchConf(["apiVersion","versionCheck"],(e=>{e.apiVersion&&e.versionCheck&&!hn&&function(e,t,n){const s=function(e,t){const n=e.split("."),s=t.split(".");for(let i=0;i<3;i++){const e=Number(n[i]),t=Number(s[i]);if(e>t)return 1;if(t>e)return-1;if(!Number.isNaN(e)&&Number.isNaN(t))return 1;if(Number.isNaN(e)&&!Number.isNaN(t))return-1}return 0}(t,n);if(0===s)return;const i=h(`<div class="atk-version-check-notice">${T("updateMsg",{name:T(s<0?"client":"server")})} <span class="atk-info">${T("currentVersion")}: ${T("client")} ${t} / ${T("server")} ${n}</span></div>`),r=h(`<span class="atk-ignore-btn">${T("ignore")}</span>`);r.onclick=()=>{i.remove(),hn=!0},i.append(r),e.getEl().parentElement.prepend(i)}(t,ln,e.apiVersion)}))},e=>{const t=e.inject("config"),n=e.inject("layers");let s;const i=t=>{const i=[e.getEl(),n.getEl()];un||(un=window.matchMedia("(prefers-color-scheme: dark)")),"auto"===t?(s||(s=e=>pn(i,e.matches),un.addEventListener("change",s)),pn(i,un.matches)):(s&&(un.removeEventListener("change",s),s=void 0),pn(i,t))};e.watchConf(["darkMode"],(e=>i(e.darkMode))),e.on("created",(()=>i(t.get().darkMode))),e.on("unmounted",(()=>{s&&(null==un||un.removeEventListener("change",s)),s=void 0}))},e=>{const t=e.inject("config");let n,s={};e.watchConf(["pageVote"],(e=>{const t=a(a({},gn),"object"==typeof e.pageVote?e.pageVote:{});null==n||n(),e.pageVote&&(s=function(e,t,n,s){var i,r;const o=a({},e);return o.upBtnEl=document.querySelector(t.upBtnEl),o.downBtnEl=document.querySelector(t.downBtnEl),o.upCountEl=document.querySelector(t.upCountEl),o.downCountEl=document.querySelector(t.downCountEl),o.activeClass=t.activeClass,o.voteUpHandler=n,o.voteDownHandler=s,null==(i=o.upBtnEl)||i.addEventListener("click",n),null==(r=o.downBtnEl)||r.addEventListener("click",s),o}(s,t,l,c),n=()=>s=function(e){var t,n;return e.voteUpHandler&&(null==(t=e.upBtnEl)||t.removeEventListener("click",e.voteUpHandler)),e.voteDownHandler&&(null==(n=e.downBtnEl)||n.removeEventListener("click",e.voteDownHandler)),{}}(s))})),e.on("unmounted",(()=>{null==n||n(),e.off("list-fetched",r)})),e.on("list-fetched",r);let i=0;function r({data:n}){t.get().pageVote&&function(e){return e.upBtnEl||e.downBtnEl||e.upCountEl||e.downCountEl}(s)&&n&&(i!==n.page.id?(i=n.page.id,mn(s,n.page.vote_up,n.page.vote_down,!1,!1),function(e,t,n){n.votes.getVote("page",t).then((({data:t})=>{mn(e,t.up,t.down,t.is_up,t.is_down)})).catch((e=>{console.error("[ArtalkPageVote]",e)}))}(s,i,e.getApi())):mn(s,n.page.vote_up,n.page.vote_down))}const o=()=>{var t;return{state:s,pageId:(null==(t=e.getData().getPage())?void 0:t.id)||0,httpApi:e.getApi()}},l=fn("up",o),c=fn("down",o)}],ps=new Set([...us]),gs=new WeakMap;function ms(e,t){return d(this,null,(function*(){var n;const s=new Set,i=e=>{e.forEach((e=>{"function"==typeof e&&(s.has(e)||(e(t,gs.get(e)),s.add(e)))}))};i(ps);const{data:r}=yield t.getApi().conf.conf().catch((n=>{throw((e,t={})=>{var n;const s=e.inject("list"),i=e.inject("user"),r=e.inject("config"),o=t.err;if(!o)throw new Error("MountError: `err` is required");let a="";if(null==(n=o.data)?void 0:n.err_no_site){const e={create_name:r.get().site,create_urls:`${window.location.protocol}//${window.location.host}`};a=`sites|${JSON.stringify(e)}`}cn({$err:s.getEl(),errMsg:o.msg||String(o),errData:o.data,retryFn:()=>{var e;return null==(e=t.onRetry)?void 0:e.call(t)},onOpenSidebar:i.getData().is_admin?()=>e.showSidebar({view:a}):void 0})})(t,{err:n,onRetry:()=>ms(e,t)}),n}));let o=l(a({},e),{apiVersion:null==(n=r.version)?void 0:n.version});const c=function(e){const t=["el","pageKey","pageTitle","server","site","pvEl","countEl","statPageKeyAttr","pageVote"];return Object.keys(e).forEach((n=>{t.includes(n)&&delete e[n],"darkMode"===n&&"auto"!==e[n]&&delete e[n]})),e.emoticons&&"string"==typeof e.emoticons&&(e.emoticons=e.emoticons.trim(),e.emoticons.startsWith("[")||e.emoticons.startsWith("{")?e.emoticons=JSON.parse(e.emoticons):"false"===e.emoticons&&(e.emoticons=!1)),e}(r.frontend_conf||{});o=o.preferRemoteConf?Mt(o,c):Mt(c,o),t.updateConf(o),o.pluginURLs&&(yield function(e,t){return d(this,null,(function*(){const n=new Set;if(!e||!Array.isArray(e))return n;const s=[];return e.forEach((e=>{/^(http|https):\/\//.test(e)||(e=`${t.replace(/\/$/,"")}/${e.replace(/^\//,"")}`),s.push(new Promise((t=>{if(document.querySelector(`script[src="${e}"]`))return void t();const n=document.createElement("script");n.src=e,document.head.appendChild(n),n.onload=()=>t(),n.onerror=e=>{console.error("[artalk] Failed to load plugin",e),t()}})))})),yield Promise.all(s),Object.values(window.ArtalkPlugins||{}).forEach((e=>{"function"==typeof e&&n.add(e)})),n}))}(o.pluginURLs,t.getConf().server).then((e=>{i(e)})).catch((e=>{console.error("Failed to load plugin",e)})))}))}function fs({keys:e,effect:t,getConf:n,getEvents:s}){let i=null;const r=()=>{const s=(()=>{const t=n(),s={};return e.forEach((e=>{s[e]=t[e]})),s})();var r,o;(null==i||(r=i,o=s,!(JSON.stringify(r)===JSON.stringify(o))))&&(i=s,t(s))};s().on("mounted",r),s().on("updated",r)}class ks{constructor(e){c(this,"ctx");const t=function(e){let t;if("string"==typeof e.el){const n=document.querySelector(e.el);if(!n)throw new Error(`Element "${e.el}" not found.`);t=n}else{if(!(e.el instanceof HTMLElement))throw new Error("Please provide a valid `el` config for Artalk.");t=e.el}return t}(e);t.classList.add("artalk"),t.innerHTML="",1==e.darkMode&&t.classList.add("atk-dark-mode");const n=this.ctx=new Pt(t);(e=>{e.provide("events",(()=>new on))})(n),(e=>{let t=Ut({},!0);e.provide("config",(e=>{let n=!1;return e.on("mounted",(()=>n=!0)),{watchConf:(n,s)=>{fs({keys:n,effect:s,getConf:()=>t,getEvents:()=>e})},get:()=>t,update:s=>{t=Mt(t,Ut(s,!1)),n&&e.trigger("updated",t)}}}),["events"])})(n),n.updateConf(e),n.trigger("created");(()=>{d(this,null,(function*(){yield ms(e,n),n.trigger("mounted")}))})()}getConf(){return this.ctx.getConf()}getEl(){return this.ctx.getEl()}update(e){this.ctx.updateConf(e)}reload(){this.ctx.reload()}destroy(){this.ctx.destroy()}on(e,t){this.ctx.on(e,t)}off(e,t){this.ctx.off(e,t)}trigger(e,t){this.ctx.trigger(e,t)}setDarkMode(e){this.ctx.setDarkMode(e)}static init(e){return new ks(e)}static use(e,t){ps.add(e),gs.set(e,t)}static loadCountWidget(e){const t=Ut(e,!0);jt({getApi:()=>new zt(It(t)),siteName:t.site,countEl:t.countEl,pvEl:t.pvEl,pageKeyAttr:t.statPageKeyAttr,pvAdd:!1})}get $root(){return console.warn("`$root` is deprecated, please use `getEl()` instead"),this.getEl()}get conf(){return console.warn("`conf` is deprecated, please use `getConf()` instead"),this.getConf()}}const ys=ks.init,vs=ks.use,ws=ks.loadCountWidget;exports.Defaults=Rt,exports.default=ks,exports.init=ys,exports.loadCountWidget=ws,exports.use=vs;
10
+ */let Bt=class extends Dt{constructor(){super(...arguments),c(this,"auth",{loginByEmail:(e,t={})=>this.request(a({path:"/auth/email/login",method:"POST",body:e,type:"application/json",format:"json"},t)),registerByEmail:(e,t={})=>this.request(a({path:"/auth/email/register",method:"POST",body:e,type:"application/json",format:"json"},t)),sendVerifyEmail:(e,t={})=>this.request(a({path:"/auth/email/send",method:"POST",body:e,type:"application/json",format:"json"},t)),checkDataMerge:(e={})=>this.request(a({path:"/auth/merge",method:"GET",secure:!0,format:"json"},e)),applyDataMerge:(e,t={})=>this.request(a({path:"/auth/merge",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t))}),c(this,"cache",{flushCache:(e={})=>this.request(a({path:"/cache/flush",method:"POST",secure:!0,format:"json"},e)),warmUpCache:(e={})=>this.request(a({path:"/cache/warm_up",method:"POST",secure:!0,format:"json"},e))}),c(this,"captcha",{getCaptcha:(e={})=>this.request(a({path:"/captcha",method:"GET",format:"json"},e)),getCaptchaStatus:(e={})=>this.request(a({path:"/captcha/status",method:"GET",format:"json"},e)),verifyCaptcha:(e,t={})=>this.request(a({path:"/captcha/verify",method:"POST",body:e,type:"application/json",format:"json"},t))}),c(this,"comments",{getComments:(e,t={})=>this.request(a({path:"/comments",method:"GET",query:e,secure:!0,type:"application/json",format:"json"},t)),createComment:(e,t={})=>this.request(a({path:"/comments",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),getComment:(e,t={})=>this.request(a({path:`/comments/${e}`,method:"GET",type:"application/json",format:"json"},t)),updateComment:(e,t,n={})=>this.request(a({path:`/comments/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deleteComment:(e,t={})=>this.request(a({path:`/comments/${e}`,method:"DELETE",secure:!0,format:"json"},t))}),c(this,"conf",{conf:(e={})=>this.request(a({path:"/conf",method:"GET",format:"json"},e)),getSocialLoginProviders:(e={})=>this.request(a({path:"/conf/auth/providers",method:"GET",format:"json"},e)),getDomain:(e,t={})=>this.request(a({path:"/conf/domain",method:"GET",query:e,format:"json"},t))}),c(this,"notifies",{getNotifies:(e,t={})=>this.request(a({path:"/notifies",method:"GET",query:e,type:"application/json",format:"json"},t)),markAllNotifyRead:(e,t={})=>this.request(a({path:"/notifies/read",method:"POST",body:e,type:"application/json",format:"json"},t)),markNotifyRead:(e,t,n={})=>this.request(a({path:`/notifies/${e}/${t}`,method:"POST",format:"json"},n))}),c(this,"pages",{getPages:(e,t={})=>this.request(a({path:"/pages",method:"GET",query:e,secure:!0,type:"application/json",format:"json"},t)),fetchAllPages:(e,t={})=>this.request(a({path:"/pages/fetch",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),getPageFetchStatus:(e={})=>this.request(a({path:"/pages/fetch/status",method:"GET",secure:!0,format:"json"},e)),logPv:(e,t={})=>this.request(a({path:"/pages/pv",method:"POST",body:e,type:"application/json",format:"json"},t)),updatePage:(e,t,n={})=>this.request(a({path:`/pages/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deletePage:(e,t={})=>this.request(a({path:`/pages/${e}`,method:"DELETE",secure:!0,format:"json"},t)),fetchPage:(e,t={})=>this.request(a({path:`/pages/${e}/fetch`,method:"POST",secure:!0,type:"application/json",format:"json"},t))}),c(this,"sendEmail",{sendEmail:(e,t={})=>this.request(a({path:"/send_email",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t))}),c(this,"settings",{getSettings:(e={})=>this.request(a({path:"/settings",method:"GET",secure:!0,format:"json"},e)),applySettings:(e,t={})=>this.request(a({path:"/settings",method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},t)),getSettingsTemplate:(e,t={})=>this.request(a({path:`/settings/template/${e}`,method:"GET",secure:!0,format:"json"},t))}),c(this,"sites",{getSites:(e={})=>this.request(a({path:"/sites",method:"GET",secure:!0,format:"json"},e)),createSite:(e,t={})=>this.request(a({path:"/sites",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),updateSite:(e,t,n={})=>this.request(a({path:`/sites/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deleteSite:(e,t={})=>this.request(a({path:`/sites/${e}`,method:"DELETE",secure:!0,format:"json"},t))}),c(this,"stats",{getStats:(e,t,n={})=>this.request(a({path:`/stats/${e}`,method:"GET",query:t,type:"application/json",format:"json"},n))}),c(this,"transfer",{exportArtrans:(e={})=>this.request(a({path:"/transfer/export",method:"GET",secure:!0,format:"json"},e)),importArtrans:(e,t={})=>this.request(a({path:"/transfer/import",method:"POST",body:e,secure:!0,type:"application/json"},t)),uploadArtrans:(e,t={})=>this.request(a({path:"/transfer/upload",method:"POST",body:e,secure:!0,type:"multipart/form-data",format:"json"},t))}),c(this,"upload",{upload:(e,t={})=>this.request(a({path:"/upload",method:"POST",body:e,secure:!0,type:"multipart/form-data",format:"json"},t))}),c(this,"user",{getUser:(e,t={})=>this.request(a({path:"/user",method:"GET",query:e,secure:!0,format:"json"},t)),updateProfile:(e,t={})=>this.request(a({path:"/user",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),login:(e,t={})=>this.request(a({path:"/user/access_token",method:"POST",body:e,type:"application/json",format:"json"},t)),getUserStatus:(e,t={})=>this.request(a({path:"/user/status",method:"GET",query:e,secure:!0,format:"json"},t))}),c(this,"users",{createUser:(e,t={})=>this.request(a({path:"/users",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),updateUser:(e,t,n={})=>this.request(a({path:`/users/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deleteUser:(e,t={})=>this.request(a({path:`/users/${e}`,method:"DELETE",secure:!0,format:"json"},t)),getUsers:(e,t,n={})=>this.request(a({path:`/users/${e}`,method:"GET",query:t,secure:!0,type:"application/json",format:"json"},n))}),c(this,"version",{getVersion:(e={})=>this.request(a({path:"/version",method:"GET",format:"json"},e))}),c(this,"votes",{syncVotes:(e={})=>this.request(a({path:"/votes/sync",method:"POST",secure:!0,format:"json"},e)),getVote:(e,t,n={})=>this.request(a({path:`/votes/${e}/${t}`,method:"GET",type:"application/json",format:"json"},n)),createVote:(e,t,n,s,i={})=>this.request(a({path:`/votes/${e}/${t}/${n}`,method:"POST",body:s,type:"application/json",format:"json"},i))})}};const qt=(e,t,n)=>d(exports,null,(function*(){const s=e.getApiToken&&e.getApiToken(),i=new Headers(a({Authorization:s?`Bearer ${s}`:""},null==n?void 0:n.headers));i.get("Authorization")||i.delete("Authorization");const r=yield fetch(t,l(a({},n),{headers:i}));if(!r.ok){const s=(yield r.json().catch((()=>{})))||{};let i=!1;if(e.handlers&&(yield e.handlers.get().reduce(((e,t)=>d(exports,null,(function*(){yield e,!0===s[t.action]&&(yield t.handler(s),i=!0)}))),Promise.resolve())),i)return qt(e,t,n);throw function(e,t){const n=new _t;return n.message=t.msg||t.message||"fetch error",n.code=e,n.data=t,console.error(n),n}(r.status,s)}return r}));class _t extends Error{constructor(){super(...arguments),c(this,"code",0),c(this,"message","fetch error"),c(this,"data")}}class zt extends Bt{constructor(e){super({baseUrl:e.baseURL,customFetch:(t,n)=>qt(e,t,n)}),c(this,"_opts"),this._opts=e}getUserFields(){const e=this._opts.userInfo;if((null==e?void 0:e.name)&&(null==e?void 0:e.email))return{name:e.name,email:e.email}}}class Ft{constructor(e){c(this,"$btn"),c(this,"$panel"),c(this,"editorStateEffectWhen"),this.kit=e}useBtn(e="<div></div>"){return this.$btn=h(`<span class="atk-plug-btn">${e}</span>`),this.$btn}usePanel(e="<div></div>"){return this.$panel=h(e),this.$panel}useContentTransformer(e){this.contentTransformer=e}usePanelShow(e){this.kit.useEvents().on("panel-show",(t=>{t===this&&e()}))}usePanelHide(e){this.kit.useEvents().on("panel-hide",(t=>{t===this&&e()}))}useEditorStateEffect(e,t){this.editorStateEffectWhen=e,this.editorStateEffect=t}}const Wt="ArtalkContent";class Nt{constructor(e){this.kit=e}reqAdd(){return d(this,null,(function*(){return(yield this.kit.useApi().comments.createComment(a({},yield this.getSubmitAddParams()))).data}))}getSubmitAddParams(){return d(this,null,(function*(){const{name:e,email:t,link:n}=this.kit.useUser().getData(),s=this.kit.useConf();return{content:this.kit.useEditor().getContentFinal(),name:e,email:t,link:n,rid:0,page_key:s.pageKey,page_title:s.pageTitle,site_name:s.site,ua:yield k()}}))}postSubmitAdd(e){this.kit.useData().insertComment(e)}}class Ht extends Ft{constructor(e){super(e),c(this,"customs",[]),c(this,"defaultPreset"),this.defaultPreset=new Nt(this.kit);const t=()=>this.do();this.kit.useMounted((()=>{this.kit.useEvents().on("editor-submit",t)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("editor-submit",t)}))}registerCustom(e){this.customs.push(e)}do(){return d(this,null,(function*(){if(""===this.kit.useEditor().getContentFinal().trim())return void this.kit.useEditor().focus();const e=this.customs.find((e=>e.activeCond()));this.kit.useEditor().showLoading();try{let t;(null==e?void 0:e.pre)&&e.pre(),t=(null==e?void 0:e.req)?yield e.req():yield this.defaultPreset.reqAdd(),(null==e?void 0:e.post)?e.post(t):this.defaultPreset.postSubmitAdd(t)}catch(t){return console.error(t),void this.kit.useEditor().showNotify(`${T("commentFail")}: ${t.message||String(t)}`,"e")}finally{this.kit.useEditor().hideLoading()}this.kit.useEditor().reset(),this.kit.useEvents().trigger("editor-submitted")}))}}class Vt extends Ft{constructor(){super(...arguments),c(this,"isMoved",!1)}move(e){if(this.isMoved)return;this.isMoved=!0;const t=this.kit.useUI().$el;t.after(h('<div class="atk-editor-travel-placeholder"></div>'));const n=h("<div></div>");e.after(n),n.replaceWith(t),t.classList.add("atk-fade-in"),t.classList.add("editor-traveling")}back(){var e;this.isMoved&&(this.isMoved=!1,null==(e=this.kit.useArtalkRootEl().querySelector(".atk-editor-travel-placeholder"))||e.replaceWith(this.kit.useUI().$el),this.kit.useUI().$el.classList.remove("editor-traveling"))}}function Qt(e,t){let n=e.querySelector(":scope > .atk-loading");n||(n=h('<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==t?void 0:t.transparentBg)&&(n.style.background="transparent"),e.appendChild(n)),n.style.display="";const s=n.querySelector(".atk-loading-spinner");s&&(s.style.display="none",window.setTimeout((()=>{s.isConnected&&(s.style.display="")}),500))}function Kt(e){const t=e.querySelector(":scope > .atk-loading");t&&(t.style.display="none")}function Gt(e,t){e?Qt(t):Kt(t)}function Yt(e,t=!0,n){let s;if(n){const t=n.getBoundingClientRect();s=e.getBoundingClientRect().top-t.top+n.scrollTop-n.clientHeight/2+e.clientHeight/2}else{const t=e.getBoundingClientRect();s=t.top+window.scrollY-(window.innerHeight/2-t.height/2)}const i={top:s,left:0,behavior:"instant"};n?n.scroll(i):window.scroll(i)}function Zt(e,t){!function(e,t,n="in"){e.classList.add(`atk-fade-${n}`);const s=()=>{e.classList.remove(`atk-fade-${n}`),e.removeEventListener("animationend",s)};e.addEventListener("animationend",s)}(e,0,"in")}function Xt(e,t,n='<span class="atk-error-title">Artalk Error</span>'){let s=e.querySelector(".atk-error-layer");if(null===t)return void(null!==s&&s.remove());s||(s=h(`<div class="atk-error-layer">${n}<span class="atk-error-text"></span></div>`),e.appendChild(s));const i=s.querySelector(".atk-error-text");i.innerHTML="",null!==t&&(t instanceof HTMLElement?i.appendChild(t):i.innerText=t)}class Jt extends Ft{constructor(e){super(e),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="${T("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((e=>this.transEmoticonImageText(e))),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*(){Qt(this.$panel),this.emoticons=yield this.handleData(this.kit.useConf().emoticons),Kt(this.$panel),this.loadingTask=null,this.isListLoaded=!0})))(),yield this.loadingTask):yield this.loadingTask)}))}handleData(e){return d(this,null,(function*(){if(!Array.isArray(e)&&["object","string"].includes(typeof e)&&(e=[e]),!Array.isArray(e))return Xt(this.$panel,`[${T("emoticon")}] Data must be of Array/Object/String type`),Kt(this.$panel),[];const t=t=>{"object"==typeof t&&(t.name&&e.find((e=>e.name===t.name))||e.push(t))},n=e=>d(this,null,(function*(){yield Promise.all(e.map(((e,s)=>d(this,null,(function*(){if("object"!=typeof e||Array.isArray(e)){if(Array.isArray(e))yield n(e);else if("string"==typeof e){const s=yield this.remoteLoad(e);Array.isArray(s)?yield n(s):"object"==typeof s&&t(s)}}else t(e)})))))}));return yield n(e),e.forEach((e=>{if(this.isOwOFormat(e)){this.convertOwO(e).forEach((e=>{t(e)}))}else Array.isArray(e)&&e.forEach((e=>{t(e)}))})),e=e.filter((e=>"object"==typeof e&&!Array.isArray(e)&&!!e&&!!e.name)),this.solveNullKey(e),this.solveSameKey(e),e}))}remoteLoad(e){return d(this,null,(function*(){if(!e)return[];try{const t=yield fetch(e);return yield t.json()}catch(t){return Kt(this.$panel),console.error("[Emoticons] Load Failed:",t),Xt(this.$panel,`[${T("emoticon")}] ${T("loadFail")}: ${String(t)}`),[]}}))}solveNullKey(e){e.forEach((e=>{e.items.forEach(((t,n)=>{t.key||(t.key=`${e.name} ${n+1}`)}))}))}solveSameKey(e){const t={};e.forEach((e=>{e.items.forEach((e=>{e.key&&""!==String(e.key).trim()&&(t[e.key]?t[e.key]++:t[e.key]=1,t[e.key]>1&&(e.key=`${e.key} ${t[e.key]}`))}))}))}isOwOFormat(e){try{return"object"==typeof e&&!!Object.values(e).length&&Array.isArray(Object.keys(Object.values(e)[0].container))&&Object.keys(Object.values(e)[0].container[0]).includes("icon")}catch(t){return!1}}convertOwO(e){const t=[];return Object.entries(e).forEach((([e,n])=>{const s={name:e,type:n.type,items:[]};n.container.forEach(((t,n)=>{const i=t.icon;if(/<(img|IMG)/.test(i)){const e=/src=["'](.*?)["']/.exec(i);e&&e.length>1&&(t.icon=e[1])}s.items.push({key:t.text||`${e} ${n+1}`,val:t.icon})})),t.push(s)})),t}initEmoticonsList(){this.$grpWrap=h('<div class="atk-grp-wrap"></div>'),this.$panel.append(this.$grpWrap),this.emoticons.forEach(((e,t)=>{const n=h('<div class="atk-grp" style="display: none;"></div>');this.$grpWrap.append(n),n.setAttribute("data-index",String(t)),n.setAttribute("data-grp-name",e.name),n.setAttribute("data-type",e.type),e.items.forEach((t=>{const s=h('<span class="atk-item"></span>');if(n.append(s),t.key&&!new RegExp(`^(${e.name})?\\s?[0-9]+$`).test(t.key)&&s.setAttribute("title",t.key),"image"===e.type){const e=document.createElement("img");e.src=t.val,e.alt=t.key,s.append(e)}else s.innerText=t.val;s.onclick=()=>{"image"===e.type?this.kit.useEditor().insertContent(`:[${t.key}]`):this.kit.useEditor().insertContent(t.val||"")}}))})),this.emoticons.length>1&&(this.$grpSwitcher=h('<div class="atk-grp-switcher"></div>'),this.$panel.append(this.$grpSwitcher),this.emoticons.forEach(((e,t)=>{const n=h("<span />");n.innerText=e.name,n.setAttribute("data-index",String(t)),n.onclick=()=>this.openGrp(t),this.$grpSwitcher.append(n)}))),this.emoticons.length>0&&this.openGrp(0)}openGrp(e){var t,n,s;Array.from(this.$grpWrap.children).forEach((t=>{const n=t;n.getAttribute("data-index")!==String(e)?n.style.display="none":n.style.display=""})),null==(t=this.$grpSwitcher)||t.querySelectorAll("span.active").forEach((e=>e.classList.remove("active"))),null==(s=null==(n=this.$grpSwitcher)?void 0:n.querySelector(`span[data-index="${e}"]`))||s.classList.add("active"),this.changeListHeight()}changeListHeight(){}transEmoticonImageText(e){return this.emoticons&&Array.isArray(this.emoticons)?(this.emoticons.forEach((t=>{"image"===t.type&&Object.entries(t.items).forEach((([t,n])=>{e=e.split(`:[${n.key}]`).join(`<img src="${n.val}" atk-emoticon="${n.key}">`)}))})),e):e}}const en=["png","jpg","jpeg","gif","bmp","svg","webp"];class tn extends Ft{constructor(e){super(e),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=en.map((e=>`.${e}`)).join(",");const e=this.useBtn(`<i aria-label="${T("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>`);e.after(this.$imgUploadInput),e.onclick=()=>{const e=this.$imgUploadInput;e.onchange=()=>{(()=>{d(this,null,(function*(){if(!e.files||0===e.files.length)return;const t=e.files[0];this.uploadImg(t)}))})()},e.click()},this.kit.useConf().imgUpload||this.$btn.setAttribute("atk-only-admin-show","")}initDragImg(){const e=e=>{if(e)for(let t=0;t<e.length;t++){const n=e[t];this.uploadImg(n)}},t=e=>{e.stopPropagation(),e.preventDefault()},n=t=>{var n;const s=null==(n=t.dataTransfer)?void 0:n.files;(null==s?void 0:s.length)&&(t.preventDefault(),e(s))},s=t=>{var n;const s=null==(n=t.clipboardData)?void 0:n.files;(null==s?void 0:s.length)&&(t.preventDefault(),e(s))};this.kit.useMounted((()=>{this.kit.useUI().$textarea.addEventListener("dragover",t),this.kit.useUI().$textarea.addEventListener("drop",n),this.kit.useUI().$textarea.addEventListener("paste",s)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("dragover",t),this.kit.useUI().$textarea.removeEventListener("drop",n),this.kit.useUI().$textarea.removeEventListener("paste",s)}))}uploadImg(e){return d(this,null,(function*(){const t=/[^.]+$/.exec(e.name);if(!t||!en.includes(String(t[0]).toLowerCase()))return;if(!this.kit.useUser().checkHasBasicUserInfo())return void this.kit.useEditor().showNotify(T("uploadLoginMsg"),"w");let n="\n";""===this.kit.useUI().$textarea.value.trim()&&(n="");const s=`${n}![](Uploading ${e.name}...)`;let i;this.kit.useEditor().insertContent(s);try{const t=this.kit.useConf().imgUploader;i=t?{public_url:yield t(e)}:(yield this.kit.useApi().upload.upload({file:e})).data}catch(r){console.error(r),this.kit.useEditor().showNotify(`${T("uploadFail")}: ${r.message}`,"e")}if(i&&i.public_url){let e=i.public_url;y(e)||(e=v({base:this.kit.useConf().server,path:e})),this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(s,`${n}![](${e})`))}else this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(s,""))}))}}class nn extends Ft{constructor(e){super(e),c(this,"isPlugPanelShow",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-preview"></div>'),this.useBtn(`<i aria-label="${T("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",(e=>{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 sn=[class extends Ft{constructor(e){super(e);const t=()=>{this.save()};this.kit.useMounted((()=>{const e=window.localStorage.getItem(Wt)||"";""!==e.trim()&&(this.kit.useEditor().showNotify(T("restoredMsg"),"i"),this.kit.useEditor().setContent(e)),this.kit.useEvents().on("content-updated",t)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("content-updated",t)}))}save(){window.localStorage.setItem(Wt,this.kit.useEditor().getContentRaw().trim())}},class extends Ft{get $inputs(){return this.kit.useEditor().getHeaderInputEls()}constructor(e){super(e);const t={},n={},s=(e,t,n)=>()=>{this.kit.useEvents().trigger(e,{field:n,$input:t})};this.kit.useMounted((()=>{Object.entries(this.$inputs).forEach((([e,i])=>{i.addEventListener("input",t[e]=s("header-input",i,e)),i.addEventListener("change",n[e]=s("header-change",i,e))}))})),this.kit.useUnmounted((()=>{Object.entries(this.$inputs).forEach((([e,s])=>{s.removeEventListener("input",t[e]),s.removeEventListener("change",n[e])}))}))}},class extends Ft{constructor(e){super(e),c(this,"query",{timer:null,abortFn:null});const t=({$input:e,field:t})=>{"edit"!==this.kit.useEditor().getState()&&(this.kit.useUser().update({[t]:e.value.trim()}),"name"!==t&&"email"!==t||this.fetchUserInfo())},n={name:T("nick"),email:T("email"),link:T("link")};this.kit.useMounted((()=>{Object.entries(this.kit.useEditor().getHeaderInputEls()).forEach((([e,t])=>{t.placeholder=n[e],t.value=this.kit.useUser().getData()[e]||""})),this.kit.useEvents().on("header-input",t)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-input",t)}))}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 e=this.kit.useApi(),t="getUserCancelToken";this.query.abortFn=()=>e.abortRequest(t),e.user.getUser(a({},e.getUserFields()),{cancelToken:t}).then((e=>this.onUserInfoFetched(e.data))).catch((e=>{})).finally((()=>{this.query.abortFn=null}))}),400)}onUserInfoFetched(e){var t;e.is_login||this.kit.useUser().logout(),this.kit.useData().updateNotifies(e.notifies),this.kit.useUser().checkHasBasicUserInfo()&&!e.is_login&&(null==(t=e.user)?void 0:t.is_admin)&&this.kit.useCheckers().checkAdmin({onSuccess:()=>{}}),e.user&&e.user.link&&(this.kit.useUI().$link.value=e.user.link,this.kit.useUser().update({link:e.user.link}))}},class extends Ft{constructor(e){super(e);const t=({field:e})=>{"link"===e&&this.onLinkInputChange()};this.kit.useMounted((()=>{this.kit.useEvents().on("header-change",t)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-change",t)}))}onLinkInputChange(){const e=this.kit.useUI().$link.value.trim();e&&!/^(http|https):\/\//.test(e)&&(this.kit.useUI().$link.value=`https://${e}`,this.kit.useUser().update({link:this.kit.useUI().$link.value}))}},class extends Ft{constructor(e){super(e);const t=e=>this.onKeydown(e),n=()=>this.onInput();this.kit.useMounted((()=>{this.kit.useUI().$textarea.placeholder=this.kit.useConf().placeholder||T("placeholder"),this.kit.useUI().$textarea.addEventListener("keydown",t),this.kit.useUI().$textarea.addEventListener("input",n)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("keydown",t),this.kit.useUI().$textarea.removeEventListener("input",n)})),this.kit.useEvents().on("content-updated",(()=>{window.setTimeout((()=>{this.adaptiveHeightByContent()}),80)}))}onKeydown(e){9===(e.keyCode||e.which)&&(e.preventDefault(),this.kit.useEditor().insertContent("\t"))}onInput(){this.kit.useEvents().trigger("content-updated",this.kit.useEditor().getContentRaw())}adaptiveHeightByContent(){const e=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+e}px`}},Ht,class extends Ft{constructor(e){super(e);const t=()=>{this.kit.useEditor().submit()};this.kit.useMounted((()=>{this.kit.useUI().$submitBtn.innerText=this.kit.useConf().sendBtn||T("send"),this.kit.useUI().$submitBtn.addEventListener("click",t)})),this.kit.useUnmounted((()=>{this.kit.useUI().$submitBtn.removeEventListener("click",t)}))}},Vt,class extends Ft{constructor(e){super(e),c(this,"comment"),this.useEditorStateEffect("reply",(e=>(this.setReply(e),()=>{this.cancelReply()}))),this.kit.useEvents().on("mounted",(()=>{const e=this.kit.useDeps(Ht);if(!e)throw Error("SubmitPlug not initialized");const t=new Nt(this.kit);e.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(a({},yield t.getSubmitAddParams()),{rid:this.comment.id,page_key:this.comment.page_key,page_title:void 0,site_name:this.comment.site_name}))).data})),post:e=>{const n=this.kit.useConf();e.page_key!==n.pageKey&&window.open(`${e.page_url}#atk-comment-${e.id}`),t.postSubmitAdd(e)}})}))}setReply(e){const t=this.kit.useUI();if(!t.$sendReplyBtn){const n=h(`<span class="atk-state-btn"><span class="atk-text-wrap">${T("reply")} <span class="atk-text"></span></span><span class="atk-cancel atk-icon-close atk-icon"></span></span>`);n.querySelector(".atk-text").innerText=`@${e.nick}`,n.addEventListener("click",(()=>{this.kit.useEditor().resetState()})),t.$stateWrap.append(n),t.$sendReplyBtn=n}this.comment=e,t.$textarea.focus()}cancelReply(){if(!this.comment)return;const e=this.kit.useUI();e.$sendReplyBtn&&(e.$sendReplyBtn.remove(),e.$sendReplyBtn=void 0),this.comment=void 0}},class extends Ft{constructor(e){super(e),c(this,"comment"),c(this,"originalSubmitBtnText","Send"),this.useEditorStateEffect("edit",(e=>(this.edit(e),()=>{this.cancelEdit()}))),this.kit.useMounted((()=>{const e=this.kit.useDeps(Ht);if(!e)throw Error("SubmitPlug not initialized");e.registerCustom({activeCond:()=>!!this.comment,req:()=>d(this,null,(function*(){const e={content:this.kit.useEditor().getContentFinal(),nick:this.kit.useUI().$name.value,email:this.kit.useUI().$email.value,link:this.kit.useUI().$link.value},t=this.comment;return(yield this.kit.useApi().comments.updateComment(t.id,a(a({},t),e))).data})),post:e=>{this.kit.useData().updateComment(e)}})}))}edit(e){const t=this.kit.useUI();if(!t.$editCancelBtn){const e=h(`<span class="atk-state-btn"><span class="atk-text-wrap">${T("editCancel")}</span><span class="atk-cancel atk-icon-close atk-icon"></span></span>`);e.onclick=()=>{this.kit.useEditor().resetState()},t.$stateWrap.append(e),t.$editCancelBtn=e}this.comment=e,t.$header.style.display="none",t.$name.value=e.nick||"",t.$email.value=e.email||"",t.$link.value=e.link||"",this.kit.useEditor().setContent(e.content),t.$textarea.focus(),this.updateSubmitBtnText(T("save"))}cancelEdit(){if(!this.comment)return;const e=this.kit.useUI();e.$editCancelBtn&&(e.$editCancelBtn.remove(),e.$editCancelBtn=void 0),this.comment=void 0;const{name:t,email:n,link:s}=this.kit.useUser().getData();e.$name.value=t,e.$email.value=n,e.$link.value=s,this.kit.useEditor().setContent(""),this.restoreSubmitBtnText(),e.$header.style.display=""}updateSubmitBtnText(e){this.originalSubmitBtnText=this.kit.useUI().$submitBtn.innerText,this.kit.useUI().$submitBtn.innerText=e}restoreSubmitBtnText(){this.kit.useUI().$submitBtn.innerText=this.originalSubmitBtnText}},class extends Ft{constructor(e){super(e);const t=()=>this.open(),n=()=>this.close();this.kit.useMounted((()=>{this.kit.useEvents().on("editor-open",t),this.kit.useEvents().on("editor-close",n)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("editor-open",t),this.kit.useEvents().off("editor-close",n)}))}open(){var e;null==(e=this.kit.useUI().$textareaWrap.querySelector(".atk-comment-closed"))||e.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(h(`<div class="atk-comment-closed">${T("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")}},Jt,tn,nn];class rn{constructor(e){this.plugins=e}useEditor(){return this.plugins.getEditor()}useConf(){return this.plugins.getOptions().getConf().get()}useApi(){return this.plugins.getOptions().getApi()}useData(){return this.plugins.getOptions().getData()}useUser(){return this.plugins.getOptions().getUser()}useCheckers(){return this.plugins.getOptions().getCheckers()}useUI(){return this.plugins.getEditor().getUI()}useEvents(){return this.plugins.getEvents()}useMounted(e){this.useEvents().on("mounted",e)}useUnmounted(e){this.useEvents().on("unmounted",e)}useDeps(e){return this.plugins.get(e)}useArtalkRootEl(){return this.plugins.getOptions().getArtalkRootEl()}}class on{constructor(){c(this,"events",[])}on(e,t,n={}){this.events.push(a({name:e,handler:t},n))}off(e,t){t&&(this.events=this.events.filter((n=>!(n.name===e&&n.handler===t))))}trigger(e,t){this.events.slice(0).filter((t=>t.name===e&&"function"==typeof t.handler)).forEach((n=>{n.once&&this.off(e,n.handler),n.handler(t)}))}}class an{constructor(e){c(this,"plugins",[]),c(this,"openedPlug",null),c(this,"events",new on),this.opts=e;let t=!1;this.opts.getConf().watchConf(["imgUpload","emoticons","preview","editorTravel","locale"],(e=>{t&&this.getEvents().trigger("unmounted"),this.clear(),function(e){const t=new Map;return t.set(tn,e.imgUpload),t.set(Jt,e.emoticons),t.set(nn,e.preview),t.set(Vt,e.editorTravel),sn.filter((e=>!t.has(e)||!!t.get(e)))}(e).forEach((e=>{const t=new rn(this);this.plugins.push(new e(t))})),this.getEvents().trigger("mounted"),t=!0,this.loadPluginUI()})),this.events.on("panel-close",(()=>this.closePluginPanel())),this.events.on("editor-submitted",(()=>e.onSubmitted()))}getPlugins(){return this.plugins}getEvents(){return this.events}getEditor(){return this.opts.getEditor()}getOptions(){return this.opts}clear(){this.plugins=[],this.events=new on,this.openedPlug&&this.closePluginPanel()}loadPluginUI(){this.getEditor().getUI().$plugPanelWrap.innerHTML="",this.getEditor().getUI().$plugPanelWrap.style.display="none",this.getEditor().getUI().$plugBtnWrap.innerHTML="",this.plugins.forEach((e=>this.loadPluginItem(e)))}loadPluginItem(e){const t=e.$btn;if(!t)return;this.getEditor().getUI().$plugBtnWrap.appendChild(t),!t.onclick&&(t.onclick=()=>{this.opts.getEditor().getUI().$plugBtnWrap.querySelectorAll(".active").forEach((e=>e.classList.remove("active"))),e!==this.openedPlug?(this.openPluginPanel(e),t.classList.add("active")):this.closePluginPanel()});const n=e.$panel;n&&(n.style.display="none",this.getEditor().getUI().$plugPanelWrap.appendChild(n))}get(e){return this.plugins.find((t=>t instanceof e))}openPluginPanel(e){this.plugins.forEach((t=>{const n=t.$panel;n&&(t===e?(n.style.display="",this.events.trigger("panel-show",e)):(n.style.display="none",this.events.trigger("panel-hide",e)))})),this.getEditor().getUI().$plugPanelWrap.style.display="",this.openedPlug=e}closePluginPanel(){this.openedPlug&&(this.getEditor().getUI().$plugPanelWrap.style.display="none",this.events.trigger("panel-hide",this.openedPlug),this.openedPlug=null)}getTransformedContent(e){let t=e;return this.plugins.forEach((e=>{e.contentTransformer&&(t=e.contentTransformer(t))})),t}}const ln="2.9.3";function cn(e){const t=h('<span><span class="error-message"></span><br/><br/></span>');if(t.querySelector(".error-message").innerText=`${T("listLoadFailMsg")}\n${e.errMsg}`,e.retryFn){const n=h(`<span style="cursor:pointer;">${T("listRetry")}</span>`);n.onclick=()=>e.retryFn&&e.retryFn(),t.appendChild(n)}if(e.onOpenSidebar){const n=h(`<span atk-only-admin-show> | <span style="cursor:pointer;">${T("openName",{name:T("ctrlCenter")})}</span></span>`);t.appendChild(n),n.onclick=()=>e.onOpenSidebar&&e.onOpenSidebar()}Xt(e.$err,t)}const dn=[e=>{const t=e.inject("config");e.on("list-fetch",(n=>{if(e.getData().getLoading())return;e.getData().setLoading(!0);const s=a({offset:0,limit:t.get().pagination.pageSize,flatMode:t.get().flatMode,paramsModifier:t.get().listFetchParamsModifier},n);e.getData().setListLastFetch({params:s});const i={limit:s.limit,offset:s.offset,flat_mode:s.flatMode,page_key:t.get().pageKey,site_name:t.get().site};s.paramsModifier&&s.paramsModifier(i),e.getApi().comments.getComments(a(a({},i),e.getApi().getUserFields())).then((({data:t})=>{e.getData().setListLastFetch({params:s,data:t}),e.getData().loadComments(t.comments),e.getData().updatePage(t.page),s.onSuccess&&s.onSuccess(t),e.trigger("list-fetched",{params:s,data:t})})).catch((t=>{const n={msg:t.msg||String(t),data:t.data};throw s.onError&&s.onError(n),e.trigger("list-failed",n),e.trigger("list-fetched",{params:s,error:n}),t})).finally((()=>{e.getData().setLoading(!1)}))}))},e=>{const t=e.inject("list");e.on("list-fetch",(e=>{0===e.offset&&Gt(!0,t.getEl())})),e.on("list-fetched",(()=>{Gt(!1,t.getEl())}))},e=>{const t=e.inject("config");e.on("comment-rendered",(n=>{if(t.get().listUnreadHighlight){const t=e.getData().getNotifies(),s=t.find((e=>e.comment_id===n.getID()));s?(n.getRender().setUnread(!0),n.getRender().setOpenAction((()=>{window.open(s.read_link),e.getData().updateNotifies(t.filter((e=>e.comment_id!==n.getID())))}))):n.getRender().setUnread(!1)}})),e.on("list-goto",(t=>{const n=p("atk_notify_key");n&&e.getApi().notifies.markNotifyRead(t,n).then((()=>{e.getData().updateNotifies(e.getData().getNotifies().filter((e=>e.comment_id!==t)))}))}))},e=>{const t=e.inject("list"),n=e.inject("editorPlugs");let s;e.on("mounted",(()=>{s=t.getEl().querySelector('[data-action="admin-close-comment"]'),s.addEventListener("click",(()=>{const t=e.getData().getPage();if(!t)throw new Error("Page data not found");t.admin_only=!t.admin_only,function(e,t){e.editorShowLoading(),e.getApi().pages.updatePage(t.id,t).then((({data:t})=>{e.getData().updatePage(t)})).catch((t=>{e.editorShowNotify(`${T("editFail")}: ${t.message||String(t)}`,"e")})).finally((()=>{e.editorHideLoading()}))}(e,t)}))})),e.on("page-loaded",(e=>{!0===(null==e?void 0:e.admin_only)?(null==n||n.getEvents().trigger("editor-close"),s&&(s.innerText=T("openComment"))):(null==n||n.getEvents().trigger("editor-open"),s&&(s.innerText=T("closeComment")))})),e.on("list-loaded",(t=>{e.editorResetState()}))},e=>{const t=e.inject("list");e.on("list-loaded",(()=>{(()=>{var n,s;const i=t.getEl().querySelector(".atk-comment-count .atk-text");if(!i)return;const r=u(T("counter",{count:`${Number(null==(s=null==(n=e.getData().getListLastFetch())?void 0:n.data)?void 0:s.count)||0}`}));i.innerHTML=r.replace(/(\d+)/,'<span class="atk-comment-count-num">$1</span>')})()})),e.on("comment-inserted",(()=>{const t=e.getData().getListLastFetch();(null==t?void 0:t.data)&&(t.data.count+=1)})),e.on("comment-deleted",(()=>{const t=e.getData().getListLastFetch();(null==t?void 0:t.data)&&(t.data.count-=1)}))},e=>{const t=e.inject("list");let n=null;const s=()=>{if(!n)return;const t=e.inject("user").getData();if(t.name&&t.email){n.classList.remove("atk-hide");const e=n.querySelector(".atk-text");e&&(e.innerText=t.is_admin?T("ctrlCenter"):T("msgCenter"))}else n.classList.add("atk-hide")};e.watchConf(["locale"],(i=>{n=t.getEl().querySelector('[data-action="open-sidebar"]'),n&&(n.onclick=()=>{e.showSidebar()},s())})),e.on("user-changed",(e=>{s()}))},e=>{const t=e.inject("list");let n=null;e.on("mounted",(()=>{n=t.getEl().querySelector(".atk-unread-badge")})),e.on("notifies-updated",(e=>{var t;t=e.length||0,n&&(t>0?(n.innerText=`${Number(t||0)}`,n.style.display="block"):n.style.display="none")}))},e=>{const t=e.inject("list"),n=e.inject("config"),s=t=>{n.update({listFetchParamsModifier:t}),e.reload()},i=e=>{!function(e){const{$dropdownWrap:t,dropdownList:n}=e;if(t.querySelector(".atk-dropdown"))return;t.classList.add("atk-dropdown-wrap"),t.append(h('<span class="atk-arrow-down-icon"></span>'));let s=0;const i=(e,t,n,i)=>{i(),s=e,r.querySelectorAll(".active").forEach((e=>{e.classList.remove("active")})),t.classList.add("active"),r.style.display="none",setTimeout((()=>{r.style.display=""}),80)},r=h('<ul class="atk-dropdown atk-fade-in"></ul>');n.forEach(((e,t)=>{const[n,o]=e,a=h('<li class="atk-dropdown-item"><span></span></li>'),l=a.querySelector("span");l.innerText=n,l.onclick=()=>{i(t,a,n,o)},r.append(a),t===s&&a.classList.add("active")})),t.append(r)}({$dropdownWrap:e,dropdownList:[[T("sortLatest"),()=>{s((e=>{e.sort_by="date_desc"}))}],[T("sortBest"),()=>{s((e=>{e.sort_by="vote"}))}],[T("sortOldest"),()=>{s((e=>{e.sort_by="date_asc"}))}],[T("sortAuthor"),()=>{s((e=>{e.view_only_admin=!0}))}]]})};e.watchConf(["listSort","locale"],(e=>{const n=t.getEl().querySelector(".atk-comment-count");n&&(e.listSort?i(n):function(e){var t,n;const{$dropdownWrap:s}=e;s.classList.remove("atk-dropdown-wrap"),null==(t=s.querySelector(".atk-arrow-down-icon"))||t.remove(),null==(n=s.querySelector(".atk-dropdown"))||n.remove()}({$dropdownWrap:n}))}))},e=>{let t=0;const n=({locker:n})=>{const s=function(){const e=window.location.hash.match(/#atk-comment-([0-9]+)/);let t=e&&e[1]&&!Number.isNaN(parseFloat(e[1]))?parseFloat(e[1]):null;t||(t=Number(p("atk_comment")));return t||null}();s&&(n&&t===s||(t=s,e.trigger("list-goto",s)))},s=()=>n({locker:!1}),i=()=>n({locker:!0});e.on("mounted",(()=>{window.addEventListener("hashchange",s),e.on("list-loaded",i)})),e.on("unmounted",(()=>{window.removeEventListener("hashchange",s),e.off("list-loaded",i)}))},e=>{const t=e.inject("list");e.on("list-goto",(n=>d(exports,null,(function*(){let s=e.getCommentNodes().find((e=>e.getID()===n));if(!s){const i=(yield e.getApi().comments.getComment(n)).data;t.getLayout({forceFlatMode:!0}).insert(i.comment,i.reply_comment),s=e.getCommentNodes().find((e=>e.getID()===n))}s&&s.focus()}))))},e=>{const t=e.inject("list"),n=e.inject("config");e.on("list-loaded",(s=>{const i=s.length<=0;let r=t.getCommentsWrapEl().querySelector(".atk-list-no-comment");i?r||(r=h('<div class="atk-list-no-comment"></div>'),r.innerHTML=kt(n.get().noComment||e.$t("noComment")),t.getCommentsWrapEl().appendChild(r)):null==r||r.remove()}))},e=>{const t=e.inject("list");e.on("mounted",(()=>{const e=t.getEl().querySelector(".atk-copyright");e&&(e.innerHTML=`Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${ln}">Artalk</a>`)}))},e=>{const t=e.inject("list"),n=e.inject("config");let s=null;e.on("mounted",(()=>{s=window.setInterval((()=>{t.getEl().querySelectorAll("[data-atk-comment-date]").forEach((t=>{var s,i;const r=new Date(Number(t.getAttribute("data-atk-comment-date")));t.innerText=(null==(i=(s=n.get()).dateFormatter)?void 0:i.call(s,r))||f(r,e.$t)}))}),3e4)})),e.on("unmounted",(()=>{s&&window.clearInterval(s)}))},e=>{const t=e.inject("list");e.on("list-fetch",(()=>{Xt(t.getEl(),null)})),e.on("list-failed",(n=>{cn({$err:t.getEl(),errMsg:n.msg,errData:n.data,retryFn:()=>e.fetch({offset:0})})}))},e=>{const t=e.inject("list"),n=e.inject("config");let s=null;const i=()=>{null==s||s.disconnect(),s=null};e.on("list-loaded",(()=>{i();const r=t.getCommentsWrapEl().childNodes,o=r.length>2?r[r.length-2]:null;o&&("IntersectionObserver"in window?(t=>{var r,o;const a=(null==(o=(r=n.get()).scrollRelativeTo)?void 0:o.call(r))||null;s=new IntersectionObserver((([t])=>{t.isIntersecting&&(i(),e.trigger("list-reach-bottom"))}),{threshold:.9,root:a}),s.observe(t)})(o):console.warn("IntersectionObserver api not supported"))})),e.on("unmounted",(()=>{i()}))},e=>{const t=e.inject("list"),n=e.inject("config"),s=()=>{var e,s;const i=null==(s=(e=n.get()).scrollRelativeTo)?void 0:s.call(e);(i||window).scroll({top:g(t.getEl(),i).top,left:0})};e.on("mounted",(()=>{e.on("list-goto-first",s)})),e.on("unmounted",(()=>{e.off("list-goto-first",s)}))}];let hn=!1;let un;function pn(e,t){const n="atk-dark-mode";e.forEach((e=>{t?e.classList.add(n):e.classList.remove(n)}))}const gn={upBtnEl:".artalk-page-vote-up",downBtnEl:".artalk-page-vote-down",upCountEl:".artalk-page-vote-up-count",downCountEl:".artalk-page-vote-down-count",activeClass:"active"};function mn(e,t,n,s,i){var r,o;e.upCountEl?e.upCountEl.innerText=String(t):e.upBtnEl&&(e.upBtnEl.innerText=`${T("voteUp")} (${t})`),e.downCountEl?e.downCountEl.innerText=String(n):e.downBtnEl&&(e.downBtnEl.innerText=`${T("voteDown")} (${n})`),"boolean"==typeof s&&(null==(r=e.upBtnEl)||r.classList.toggle(e.activeClass||"active",s)),"boolean"==typeof i&&(null==(o=e.downBtnEl)||o.classList.toggle(e.activeClass||"active",i))}const fn=(e,t)=>n=>{n.preventDefault();const{state:s,pageId:i,httpApi:r}=t();i&&r.votes.createVote("page",i,e,a({},r.getUserFields())).then((({data:e})=>{mn(s,e.up,e.down,e.is_up,e.is_down)})).catch((e=>{window.alert(T("voteFail")),console.error("[ArtalkPageVote]",e)}))};const kn="ArtalkUser";class yn{constructor(e){c(this,"data"),this.opts=e;const t=JSON.parse(window.localStorage.getItem(kn)||"{}");this.data={name:t.name||t.nick||"",email:t.email||"",link:t.link||"",token:t.token||"",is_admin:t.is_admin||t.isAdmin||!1}}getData(){return this.data}update(e={}){Object.entries(e).forEach((([e,t])=>{this.data[e]=t})),window.localStorage.setItem(kn,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}}function vn(e){const t=h('<div class="atk-checker-iframe-wrap"></div>'),n=h('<iframe class="atk-fade-in" referrerpolicy="strict-origin-when-cross-origin"></iframe>');n.style.display="none",Qt(t,{transparentBg:!0}),n.src=e.getOpts().getCaptchaIframeURL(),n.onload=()=>{n.style.display="",Kt(t)},t.append(n);const s=h('<div class="atk-close-btn"><i class="atk-icon atk-icon-close"></i></div>');t.append(s),e.hideInteractInput();let i=!1;return function t(){return d(this,null,(function*(){var n;if(yield(n=1e3,new Promise((e=>{window.setTimeout((()=>{e(null)}),n)}))),i)return;let s=!1;try{s=(yield e.getApi().captcha.getCaptchaStatus()).data.is_pass}catch(r){s=!1}s?e.triggerSuccess():t()}))}(),s.onclick=()=>{i=!0,e.cancel()},t}const wn={request:(e,t)=>e.getApi().captcha.verifyCaptcha({value:t}),body:e=>e.get("iframe")?vn(e):function(e){const t=h(`<span><img class="atk-captcha-img" src="${e.get("img_data")||""}">${T("captchaCheck")}</span>`);return t.querySelector(".atk-captcha-img").onclick=()=>{const n=t.querySelector(".atk-captcha-img");e.getApi().captcha.getCaptcha().then((e=>{n.setAttribute("src",e.data.img_data)})).catch((e=>{console.error("Failed to get captcha image ",e)}))},t}(e),onSuccess(e,t,n,s){e.set("val",n)},onError(e,t,n,s){s.querySelector(".atk-captcha-img").click(),s.querySelector('input[type="text"]').value=""}},$n={inputType:"password",request(e,t){return d(this,null,(function*(){return(yield e.getApi().user.login({name:e.getUser().getData().name,email:e.getUser().getData().email,password:t})).data}))},body:e=>h(`<span>${T("adminCheck")}</span>`),onSuccess(e,t,n,s){e.getUser().update({is_admin:!0,token:t.token}),e.getOpts().onReload()},onError(e,t,n,s){}};class bn{constructor(e){c(this,"$el"),c(this,"$content"),c(this,"$actions"),this.$el=h('<div class="atk-layer-dialog-wrap">\n <div class="atk-layer-dialog">\n <div class="atk-layer-dialog-content"></div>\n <div class="atk-layer-dialog-actions"></div>\n </div>\n </div>'),this.$actions=this.$el.querySelector(".atk-layer-dialog-actions"),this.$content=this.$el.querySelector(".atk-layer-dialog-content"),this.$content.appendChild(e)}setYes(e){const t=h(`<button data-action="confirm">${T("confirm")}</button>`);return t.onclick=this.onBtnClick(e),this.$actions.appendChild(t),this}setNo(e){const t=h(`<button data-action="cancel">${T("cancel")}</button>`);return t.onclick=this.onBtnClick(e),this.$actions.appendChild(t),this}onBtnClick(e){return t=>{const n=e(t.currentTarget,this);void 0!==n&&!0!==n||this.$el.remove()}}}function xn(e){return t=>new Promise(((n,s)=>{const i=t.onCancel;t.onCancel=()=>{i&&i(),s(new Error("user canceled the checker"))};const r=t.onSuccess;t.onSuccess=()=>{r&&r(),n()},e(t)}))}class En{constructor(e){c(this,"checkCaptcha",xn((e=>{this.check(wn,e,(t=>{t.set("img_data",e.img_data),t.set("iframe",e.iframe)}))}))),c(this,"checkAdmin",xn((e=>{this.check($n,e)}))),this.opts=e}check(e,t,n){const s=this.opts.getLayers().create(`checker-${(new Date).getTime()}`);s.show();const i=()=>{s.destroy()},r={};let o=!1;const a={set:(e,t)=>{r[e]=t},get:e=>r[e],getOpts:()=>this.opts,getUser:()=>this.opts.getUser(),getApi:()=>this.opts.getApi(),hideInteractInput:()=>{o=!0},triggerSuccess:()=>{i(),e.onSuccess&&e.onSuccess(a,"","",l),t.onSuccess&&t.onSuccess()},cancel:()=>{i(),t.onCancel&&t.onCancel()}};n&&n(a);const l=h();l.appendChild(e.body(a));const c=h(`<input id="check" type="${e.inputType||"text"}" autocomplete="off" required placeholder="">`);let d;l.appendChild(c),setTimeout((()=>c.focus()),80),c.onkeyup=e=>{"Enter"!==e.key&&13!==e.keyCode||(e.preventDefault(),s.getEl().querySelector('button[data-action="confirm"]').click())};const u=new bn(l);u.setYes((n=>{const s=c.value.trim();d||(d=n.innerText);const r=()=>{n.innerText=d||"",n.classList.remove("error")};return n.innerText=`${T("loading")}...`,e.request(a,s).then((n=>{i(),e.onSuccess&&e.onSuccess(a,n,s,l),t.onSuccess&&t.onSuccess()})).catch((t=>{var i;i=String(t.message||String(t)),n.innerText=i,n.classList.add("error"),e.onError&&e.onError(a,t,s,l);const o=setTimeout((()=>r()),3e3);c.onfocus=()=>{r(),clearTimeout(o)}})),!1})),u.setNo((()=>(i(),t.onCancel&&t.onCancel(),!1))),o&&(c.style.display="none",u.$el.querySelector(".atk-layer-dialog-actions").style.display="none"),s.getEl().append(u.$el),t.onMount&&t.onMount(u.$el)}}const Cn={$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 Sn{constructor(e){c(this,"stateCurt","normal"),c(this,"stateUnmountFn",null),this.editor=e}get(){return this.stateCurt}switch(e,t){var n,s,i,r,o,a,l;if(this.stateUnmountFn&&(this.stateUnmountFn(),this.stateUnmountFn=null,null==(s=null==(n=this.editor.getPlugins())?void 0:n.get(Vt))||s.back()),"normal"!==e&&t){let n=t.$comment;this.editor.getOptions().getConf().get().flatMode||(n=n.querySelector(".atk-footer")),null==(r=null==(i=this.editor.getPlugins())?void 0:i.get(Vt))||r.move(n);const s=null==(a=(o=this.editor.getOptions().getConf().get()).scrollRelativeTo)?void 0:a.call(o);Yt(this.editor.getUI().$el,!0,s);const c=null==(l=this.editor.getPlugins())?void 0:l.getPlugins().find((t=>t.editorStateEffectWhen===e));c&&c.editorStateEffect&&(this.stateUnmountFn=c.editorStateEffect(t.comment))}this.stateCurt=e}}class Tn{constructor(e){c(this,"opts"),c(this,"$el"),c(this,"ui"),c(this,"state"),c(this,"plugins"),this.opts=e,this.ui=function(){const e=h('<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'),t={$el:e};return Object.entries(Cn).forEach((([n,s])=>{t[n]=e.querySelector(s)})),t}(),this.$el=this.ui.$el,this.state=new Sn(this)}getOptions(){return this.opts}getEl(){return this.$el}getUI(){return this.ui}getPlugins(){return this.plugins}setPlugins(e){this.plugins=e}getState(){return this.state.get()}getHeaderInputEls(){return{name:this.ui.$name,email:this.ui.$email,link:this.ui.$link}}getContentFinal(){let e=this.getContentRaw();const t=this.getPlugins();return t&&(e=t.getTransformedContent(e)),e}getContentRaw(){return this.ui.$textarea.value||""}getContentMarked(){return Lt(this.getContentFinal())}setContent(e){var t;this.ui.$textarea.value=e,null==(t=this.getPlugins())||t.getEvents().trigger("content-updated",e)}insertContent(e){if(document.selection)this.ui.$textarea.focus(),document.selection.createRange().text=e,this.ui.$textarea.focus();else if(this.ui.$textarea.selectionStart||0===this.ui.$textarea.selectionStart){const t=this.ui.$textarea.selectionStart,n=this.ui.$textarea.selectionEnd,s=this.ui.$textarea.scrollTop;this.setContent(this.ui.$textarea.value.substring(0,t)+e+this.ui.$textarea.value.substring(n,this.ui.$textarea.value.length)),this.ui.$textarea.focus(),this.ui.$textarea.selectionStart=t+e.length,this.ui.$textarea.selectionEnd=t+e.length,this.ui.$textarea.scrollTop=s}else this.ui.$textarea.focus(),this.ui.$textarea.value+=e}focus(){this.ui.$textarea.focus()}reset(){this.setContent(""),this.resetState()}resetState(){this.state.switch("normal")}setReplyComment(e,t){this.state.switch("reply",{comment:e,$comment:t})}setEditComment(e,t){this.state.switch("edit",{comment:e,$comment:t})}showNotify(e,t){!function(e,t,n){const s=h(`<div class="atk-notify atk-fade-in" style="background-color: ${{s:"#57d59f",e:"#ff6f6c",w:"#ffc721",i:"#2ebcfc"}[n]}"><span class="atk-notify-content"></span></div>`);s.querySelector(".atk-notify-content").innerHTML=u(t).replace("\n","<br/>"),e.appendChild(s);const i=()=>{s.classList.add("atk-fade-out"),setTimeout((()=>{s.remove()}),200)};let r;r=window.setTimeout((()=>{i()}),3e3),s.addEventListener("click",(()=>{i(),window.clearTimeout(r)}))}(this.ui.$notifyWrap,e,t)}showLoading(){Qt(this.ui.$el)}hideLoading(){Kt(this.ui.$el)}submit(){const e=()=>{var e;null==(e=this.getPlugins())||e.getEvents().trigger("editor-submit"),this.opts.getEvents().trigger("editor-submit")},t=this.opts.getConf().get().beforeSubmit;t?t(this,e):e()}}class An{constructor(e){c(this,"loading",!1),c(this,"listLastFetch"),c(this,"comments",[]),c(this,"notifies",[]),c(this,"page"),this.events=e}getLoading(){return this.loading}setLoading(e){this.loading=e}getListLastFetch(){return this.listLastFetch}setListLastFetch(e){this.listLastFetch=e}getComments(){return this.comments}fetchComments(e){this.events.trigger("list-fetch",e)}findComment(e){return this.comments.find((t=>t.id===e))}clearComments(){this.comments=[],this.events.trigger("list-loaded",this.comments)}loadComments(e){this.events.trigger("list-load",e),this.comments.push(...e),this.events.trigger("list-loaded",this.comments)}insertComment(e){this.comments.push(e),this.events.trigger("comment-inserted",e),this.events.trigger("list-loaded",this.comments)}updateComment(e){this.comments=this.comments.map((t=>t.id===e.id?e:t)),this.events.trigger("comment-updated",e),this.events.trigger("list-loaded",this.comments)}deleteComment(e){const t=this.comments.find((t=>t.id===e));if(!t)throw new Error(`Comment ${e} not found`);this.comments=this.comments.filter((t=>t.id!==e)),this.events.trigger("comment-deleted",t),this.events.trigger("list-loaded",this.comments)}getNotifies(){return this.notifies}updateNotifies(e){this.notifies=e,this.events.trigger("notifies-updated",this.notifies)}getPage(){return this.page}updatePage(e){this.page=e,this.events.trigger("page-loaded",e)}}class Ln{constructor(e,t){c(this,"allowMaskClose",!0),c(this,"onAfterHide"),this.$el=e,this.opts=t}setOnAfterHide(e){this.onAfterHide=e}setAllowMaskClose(e){this.allowMaskClose=e}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()}}let Pn,Mn;function Rn(){return{init(){Pn=document.body.style.overflow,Mn=document.body.style.paddingRight},unlock(){document.body.style.overflow=Pn,document.body.style.paddingRight=Mn},lock(){document.body.style.overflow="hidden";const e=parseInt(window.getComputedStyle(document.body,null).getPropertyValue("padding-right"),10);document.body.style.paddingRight=`${function(){const e=document.createElement("p");e.style.width="100%",e.style.height="200px";const t=document.createElement("div");t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.visibility="hidden",t.style.width="200px",t.style.height="150px",t.style.overflow="hidden",t.appendChild(e),document.body.appendChild(t);const n=e.offsetWidth;t.style.overflow="scroll";let s=e.offsetWidth;return n===s&&(s=t.clientWidth),document.body.removeChild(t),n-s}()+e||0}px`}}}class Un{constructor(){c(this,"$wrap"),c(this,"$mask"),c(this,"items",[]),this.$wrap=h('<div class="atk-layer-wrap" style="display: none;"><div class="atk-layer-mask"></div></div>'),this.$mask=this.$wrap.querySelector(".atk-layer-mask")}createItem(e,t){(t=t||this.createItemElement(e)).setAttribute("data-layer-name",e),this.$wrap.appendChild(t);const n=new Ln(t,{onHide:()=>this.hideWrap(t),onShow:()=>this.showWrap()});return this.getMask().addEventListener("click",(()=>{n.getAllowMaskClose()&&n.hide()})),this.items.push(n),n}createItemElement(e){const t=document.createElement("div");return t.classList.add("atk-layer-item"),t.style.display="none",this.$wrap.appendChild(t),t}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"),Rn().lock()}hideWrap(e){this.items.map((e=>e.getEl())).filter((t=>t!==e&&t.isConnected&&"none"!==t.style.display)).length>0||(this.$wrap.style.display="none",Rn().unlock())}}class In{constructor(){c(this,"wrap",new Un),Rn().init()}getEl(){return this.wrap.getWrap()}create(e,t){return this.wrap.createItem(e,t)}destroy(){this.wrap.getWrap().remove()}}const jn=e=>({import:t=>{(function(e,t="DATE_DESC",n=2){const s=[];e.filter((e=>0===e.rid)).forEach((t=>{const i={id:t.id,comment:t,children:[],level:1};i.parent=i,s.push(i),function t(s){const i=e.filter((e=>e.rid===s.id));0!==i.length&&(s.level>=n&&(s=s.parent),i.forEach((e=>{const n={id:e.id,comment:e,children:[],parent:s,level:s.level+1};s.children.push(n),t(n)})))}(i)}));const i=(n,s)=>{let i=n.id-s.id;return"DATE_ASC"===t?i=+new Date(n.comment.date)-+new Date(s.comment.date):"DATE_DESC"===t?i=+new Date(s.comment.date)-+new Date(n.comment.date):"SRC_INDEX"===t?i=e.indexOf(n.comment)-e.indexOf(s.comment):"VOTE_UP_DESC"===t&&(i=s.comment.vote_up-n.comment.vote_up),i};return function e(t){t.forEach((t=>{t.children=t.children.sort(i),e(t.children)}))}(s),s})(t,e.nestSortBy,e.nestMax).forEach((n=>{var s;const i=e.createCommentNode(n.comment);null==(s=e.$commentsWrap)||s.appendChild(i.getEl()),i.getRender().playFadeAnim();const r=(n,s)=>{s.children.forEach((s=>{const i=t.find((e=>e.id===s.comment.rid)),o=s.comment,a=e.createCommentNode(o,i);n.putChild(a),r(a,s)}))};r(i,n),i.getRender().checkHeightLimit()}))},insert:(t,n)=>{var s;const i=e.createCommentNode(t,n);if(0===t.rid)null==(s=e.$commentsWrap)||s.prepend(i.getEl());else{const n=e.findCommentNode(t.rid);n&&(n.putChild(i,"DATE_ASC"===e.nestSortBy?"append":"prepend"),i.getParents().forEach((e=>{e.getRender().heightLimitRemoveForChildren()})))}i.getRender().checkHeightLimit(),i.scrollIntoView(),i.getRender().playFadeAnim()}});function On(e,t,n,s){n.is_collapsed&&(n.is_allow_reply=!1);const i=e.createCommentNode(n,s);if(n.visible){const n=i.getEl(),s=e.$commentsWrap;"append"===t&&(null==s||s.append(n)),"prepend"===t&&(null==s||s.prepend(n)),i.getRender().playFadeAnim()}return i.getRender().checkHeightLimit(),i}class Dn{constructor(e){this.options=e}getStrategy(){return this.options.flatMode?(e=this.options,{import:t=>{t.forEach((n=>{const s=0===n.rid?void 0:t.find((e=>e.id===n.rid));On(e,"append",n,s)}))},insert:(t,n)=>{On(e,"prepend",t,n).scrollIntoView()}}):jn(this.options);var e}import(e){this.getStrategy().import(e)}insert(e,t){this.getStrategy().insert(e,t)}}function Bn(e,t){t.forEach((({el:t,max:n,imgCheck:s})=>{if(!t)return;s&&(t.style.maxHeight=`${n+1}px`);let i=!1;const r=()=>{if(i)return;if(function(e){return parseFloat(getComputedStyle(e,null).height.replace("px",""))||0}(t)<=n)return;e.scrollable?function(e){if(!e.el)return;if(e.el.classList.contains(zn))return;e.el.classList.add(zn),e.el.style.height=`${e.max}px`}({el:t,max:n}):function(e){if(!e.el)return;if(!e.max)return;if(e.el.classList.contains(qn))return;e.el.classList.add(qn),e.el.style.height=`${e.max}px`,e.el.style.overflow="hidden";const t=h(`<div class="atk-height-limit-btn">${T("readMore")}</span>`);t.onclick=t=>{t.stopPropagation(),_n(e.el),e.afterExpandBtnClick&&e.afterExpandBtnClick(t)},e.el.append(t)}({el:t,max:n,afterExpandBtnClick:()=>{var t;i=!0,null==(t=e.afterExpandBtnClick)||t.call(e)}})};if(r(),s){const e=t.querySelectorAll(".atk-content img");0===e.length&&(t.style.maxHeight=""),e.forEach((e=>{e.onload=()=>r()}))}}))}const qn="atk-height-limit";function _n(e){e&&e.classList.contains(qn)&&(e.classList.remove(qn),Array.from(e.children).forEach((e=>{e.classList.contains("atk-height-limit-btn")&&e.remove()})),e.style.height="",e.style.maxHeight="",e.style.overflow="")}const zn="atk-height-limit-scroll";function Fn(e){if(e.$headerNick=e.$el.querySelector(".atk-nick"),e.data.link){const t=h('<a target="_blank" rel="noreferrer noopener nofollow"></a>');t.innerText=e.data.nick,t.href=y(e.data.link)?e.data.link:`https://${e.data.link}`,e.$headerNick.append(t)}else e.$headerNick.innerText=e.data.nick}function Wn(e){e.$headerBadgeWrap=e.$el.querySelector(".atk-badge-wrap"),e.$headerBadgeWrap.innerHTML="";const t=e.data.badge_name,n=e.data.badge_color;if(t){const s=h('<span class="atk-badge"></span>');s.innerText=t.replace("管理员",T("admin")),s.style.backgroundColor=n||"",e.$headerBadgeWrap.append(s)}else if(e.data.is_verified){const t=h(`<span class="atk-icon-verified" title="${T("emailVerified")}"></span>`);e.$headerBadgeWrap.append(t)}if(e.data.is_pinned){const t=h(`<span class="atk-pinned-badge">${T("pin")}</span>`);e.$headerBadgeWrap.append(t)}}function Nn(e){const t=e.$el.querySelector(".atk-date");t.innerText=e.comment.getDateFormatted(),t.setAttribute("data-atk-comment-date",String(+new Date(e.data.date)))}function Hn(e){if(!e.opts.uaBadge&&!e.data.ip_region)return;let t=e.$header.querySelector("atk-ua-wrap");if(t||(t=h('<span class="atk-ua-wrap"></span>'),e.$header.append(t)),t.innerHTML="",e.data.ip_region){const n=h('<span class="atk-region-badge"></span>');n.innerText=e.data.ip_region,t.append(n)}if(e.opts.uaBadge){const{browser:n,os:s}=e.comment.getUserUA();if(String(n).trim()){const e=h('<span class="atk-ua ua-browser"></span>');e.innerText=n,t.append(e)}if(String(s).trim()){const e=h('<span class="atk-ua ua-os"></span>');e.innerText=s,t.append(e)}}}class Vn{constructor(e){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=h('<span class="atk-common-action-btn"></span>'),this.opts="object"!=typeof e?{text:e}:e,this.$el.innerText=this.getText(),this.opts.adminOnly&&this.$el.setAttribute("atk-only-admin-show","")}get isMessaging(){return!!this.msgRecTimer}appendTo(e){return e.append(this.$el),this}getText(){return"string"==typeof this.opts.text?this.opts.text:this.opts.text()}setClick(e){this.$el.onclick=t=>{if(t.stopPropagation(),!this.isLoading){if(this.opts.confirm&&!this.isMessaging){const e=()=>{this.isConfirming=!1,this.$el.classList.remove("atk-btn-confirm"),this.$el.innerText=this.getText()};if(!this.isConfirming)return this.isConfirming=!0,this.$el.classList.add("atk-btn-confirm"),this.$el.innerText=this.opts.confirmText||T("actionConfirm"),void(this.confirmRecTimer=window.setTimeout((()=>e()),5e3));this.confirmRecTimer&&window.clearTimeout(this.confirmRecTimer),e()}if(this.msgRecTimer)return this.fireMsgRecTimer(),void this.clearMsgRecTimer();e()}}}updateText(e){e&&(this.opts.text=e),this.setLoading(!1),this.$el.innerText=this.getText()}setLoading(e,t){this.isLoading!==e&&(this.isLoading=e,e?(this.$el.classList.add("atk-btn-loading"),this.$el.innerText=t||`${T("loading")}...`):(this.$el.classList.remove("atk-btn-loading"),this.$el.innerText=this.getText()))}setError(e){this.setMsg(e,"atk-btn-error")}setWarn(e){this.setMsg(e,"atk-btn-warn")}setSuccess(e){this.setMsg(e,"atk-btn-success")}setMsg(e,t,n,s){this.setLoading(!1),t&&this.$el.classList.add(t),this.$el.innerText=e,this.setMsgRecTimer((()=>{this.$el.innerText=this.getText(),t&&this.$el.classList.remove(t),s&&s()}),n||2500)}setMsgRecTimer(e,t){this.fireMsgRecTimer(),this.clearMsgRecTimer(),this.msgRecTimerFunc=e,this.msgRecTimer=window.setTimeout((()=>{e(),this.clearMsgRecTimer()}),t)}fireMsgRecTimer(){this.msgRecTimerFunc&&this.msgRecTimerFunc()}clearMsgRecTimer(){this.msgRecTimer&&window.clearTimeout(this.msgRecTimer),this.msgRecTimer=void 0,this.msgRecTimerFunc=void 0}}function Qn(e){e.opts.vote&&(e.voteBtnUp=new Vn((()=>`${T("voteUp")} (${e.data.vote_up||0})`)).appendTo(e.$actions),e.voteBtnUp.setClick((()=>{e.comment.getActions().vote("up")})),e.opts.voteDown&&(e.voteBtnDown=new Vn((()=>`${T("voteDown")} (${e.data.vote_down||0})`)).appendTo(e.$actions),e.voteBtnDown.setClick((()=>{e.comment.getActions().vote("down")}))))}function Kn(e){if(!e.data.is_allow_reply)return;const t=new Vn({text:T("reply")});t.appendTo(e.$actions),t.setClick((()=>{e.opts.replyComment(e.data,e.$el)}))}function Gn(e){const t=new Vn({text:()=>e.data.is_collapsed?T("expand"):T("collapse"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminEdit("collapsed",t)}))}function Yn(e){const t=new Vn({text:()=>e.data.is_pending?T("pending"):T("approved"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminEdit("pending",t)}))}function Zn(e){const t=new Vn({text:()=>e.data.is_pinned?T("unpin"):T("pin"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminEdit("pinned",t)}))}function Xn(e){const t=new Vn({text:T("edit"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.opts.editComment(e.data,e.$el)}))}function Jn(e){const t=new Vn({text:T("delete"),confirm:!0,confirmText:T("deleteConfirm"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminDelete(t)}))}const es={Avatar:function(e){const t=e.$el.querySelector(".atk-avatar"),n=h("<img />"),s=e.opts.avatarURLBuilder;if(n.src=s?s(e.data):e.comment.getGravatarURL(),e.data.link){const s=h('<a target="_blank" rel="noreferrer noopener nofollow"></a>');s.href=y(e.data.link)?e.data.link:`https://${e.data.link}`,s.append(n),t.append(s)}else t.append(n)},Header:function(e){Object.entries({renderNick:Fn,renderVerifyBadge:Wn,renderDate:Nn,renderUABadge:Hn}).forEach((([t,n])=>{n(e)}))},Content:function(e){if(!e.data.is_collapsed)return e.$content.innerHTML=e.comment.getContentMarked(),void e.$content.classList.remove("atk-hide","atk-collapsed");e.$content.classList.add("atk-hide","atk-type-collapsed");const t=h(`\n <div class="atk-collapsed">\n <span class="atk-text">${T("collapsedMsg")}</span>\n <span class="atk-show-btn">${T("expand")}</span>\n </div>`);e.$body.insertAdjacentElement("beforeend",t);const n=t.querySelector(".atk-show-btn");n.addEventListener("click",(t=>{t.stopPropagation(),e.$content.classList.contains("atk-hide")?(e.$content.innerHTML=e.comment.getContentMarked(),e.$content.classList.remove("atk-hide"),Zt(e.$content),n.innerText=T("collapse")):(e.$content.innerHTML="",e.$content.classList.add("atk-hide"),n.innerText=T("expand"))}))},ReplyAt:function(e){e.opts.flatMode||0===e.data.rid||e.opts.replyTo&&(e.$replyAt=h('<span class="atk-item atk-reply-at"><span class="atk-arrow"></span><span class="atk-nick"></span></span>'),e.$replyAt.querySelector(".atk-nick").innerText=`${e.opts.replyTo.nick}`,e.$replyAt.onclick=()=>{e.comment.getActions().goToReplyComment()},e.$headerBadgeWrap.insertAdjacentElement("afterend",e.$replyAt))},ReplyTo:function(e){if(!e.opts.flatMode)return;if(!e.opts.replyTo)return;e.$replyTo=h(`\n <div class="atk-reply-to">\n <div class="atk-meta">${T("reply")} <span class="atk-nick"></span>:</div>\n <div class="atk-content"></div>\n </div>`);const t=e.$replyTo.querySelector(".atk-nick");t.innerText=`@${e.opts.replyTo.nick}`,t.onclick=()=>{e.comment.getActions().goToReplyComment()};let n=Lt(e.opts.replyTo.content);e.opts.replyTo.is_collapsed&&(n=`[${T("collapsed")}]`),e.$replyTo.querySelector(".atk-content").innerHTML=n,e.$body.prepend(e.$replyTo)},Pending:function(e){if(!e.data.is_pending)return;const t=h(`<div class="atk-pending">${T("pendingMsg")}</div>`);e.$body.prepend(t)},Actions:function(e){Object.entries({renderVote:Qn,renderReply:Kn,renderCollapse:Gn,renderModerator:Yn,renderPin:Zn,renderEdit:Xn,renderDel:Jn}).forEach((([t,n])=>{n(e)}))}};class ts{constructor(e){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=e}get data(){return this.comment.getData()}get opts(){return this.comment.getOpts()}render(){var e;return this.$el=h('<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}`),e=this,Object.entries(es).forEach((([t,n])=>{n(e)})),this.$childrenWrap&&this.$main.append(this.$childrenWrap),this.$el}checkHeightLimit(){const e=this.opts.heightLimit;if(!e||!e.content||!e.children)return;const t=e.content,n=e.children;Bn({afterExpandBtnClick:()=>{const e=this.comment.getChildren();1===e.length&&_n(e[0].getRender().$content)},scrollable:e.scrollable},[{el:this.$content,max:t,imgCheck:!0},{el:this.$replyTo,max:t,imgCheck:!0},{el:this.$childrenWrap,max:n,imgCheck:!1}])}heightLimitRemoveForChildren(){this.$childrenWrap&&_n(this.$childrenWrap)}playFadeAnim(){Zt(this.comment.getRender().$el)}playFadeAnimForBody(){Zt(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=h('<div class="atk-comment-children"></div>'),this.$main.append(this.$childrenWrap)),this.$childrenWrap}setUnread(e){e?this.$el.classList.add("atk-unread"):this.$el.classList.remove("atk-unread")}setOpenable(e){e?this.$el.classList.add("atk-openable"):this.$el.classList.remove("atk-openable")}setOpenURL(e){this.setOpenable(!0),this.$el.onclick=t=>{t.stopPropagation(),window.open(e)}}setOpenAction(e){this.setOpenable(!0),this.$el.onclick=t=>{t.stopPropagation(),e()}}}class ns{constructor(e){c(this,"comment"),this.comment=e}get data(){return this.comment.getData()}get opts(){return this.comment.getOpts()}getApi(){return this.comment.getOpts().getApi()}vote(e){const t="up"===e?this.comment.getRender().voteBtnUp:this.comment.getRender().voteBtnDown;this.getApi().votes.createVote("comment",this.data.id,e,a({},this.getApi().getUserFields())).then((e=>{var t,n;this.data.vote_up=e.data.up,this.data.vote_down=e.data.down,null==(t=this.comment.getRender().voteBtnUp)||t.updateText(),null==(n=this.comment.getRender().voteBtnDown)||n.updateText()})).catch((e=>{null==t||t.setError(T("voteFail")),console.error(e)}))}adminEdit(e,t){if(t.isLoading)return;t.setLoading(!0,`${T("editing")}...`);const n=a({},this.data);"collapsed"===e?n.is_collapsed=!n.is_collapsed:"pending"===e?n.is_pending=!n.is_pending:"pinned"===e&&(n.is_pinned=!n.is_pinned),this.getApi().comments.updateComment(this.data.id,a({},n)).then((e=>{t.setLoading(!1),this.comment.setData(e.data)})).catch((e=>{console.error(e),t.setError(T("editFail"))}))}adminDelete(e){e.isLoading||(e.setLoading(!0,`${T("deleting")}...`),this.getApi().comments.deleteComment(this.data.id).then((()=>{e.setLoading(!1),this.opts.onDelete&&this.opts.onDelete(this.comment)})).catch((t=>{console.error(t),e.setError(T("deleteFail"))})))}goToReplyComment(){const e=window.location.hash,t=`#atk-comment-${this.data.rid}`;window.location.hash=t,t===e&&window.dispatchEvent(new Event("hashchange"))}}class ss{constructor(e,t){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=t,this.data=a({},e),this.data.date=this.data.date.replace(/-/g,"/"),this.parent=null,this.nestCurt=1,this.actionInstance=new ns(this),this.renderInstance=new ts(this)}render(){const e=this.renderInstance.render();this.$el&&this.$el.replaceWith(e),this.$el=e,this.opts.onAfterRender&&this.opts.onAfterRender()}getActions(){return this.actionInstance}getRender(){return this.renderInstance}getData(){return this.data}setData(e){this.data=e,this.render(),this.getRender().playFadeAnimForBody()}getParent(){return this.parent}getChildren(){return this.children}getNestCurt(){return this.nestCurt}getIsRoot(){return 0===this.data.rid}getID(){return this.data.id}putChild(e,t="append"){e.parent=this,e.nestCurt=this.nestCurt+1,this.children.push(e);const n=this.getChildrenWrapEl(),s=e.getEl();"append"===t?n.append(s):"prepend"===t&&n.prepend(s),e.getRender().playFadeAnim(),e.getRender().checkHeightLimit()}getChildrenWrapEl(){return this.nestCurt>=this.opts.nestMax?this.parent.getChildrenWrapEl():this.getRender().getChildrenWrap()}getParents(){const e=[];let t=this.parent;for(;t;)e.push(t),t=t.getParent();return e}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((e=>{e.getRender().heightLimitRemoveForChildren()})),this.scrollIntoView(),this.getRender().playFlashAnim()}scrollIntoView(){this.$el&&Yt(this.$el,!1,this.opts.scrollRelativeTo&&this.opts.scrollRelativeTo())}remove(){var e;null==(e=this.$el)||e.remove()}getGravatarURL(){return`${(e={mirror:this.opts.gravatar.mirror,params:this.opts.gravatar.params,emailHash:this.data.email_encrypted}).mirror.replace(/\/$/,"")}/${e.emailHash}?${e.params.replace(/^\?/,"")}`;var e}getContentMarked(){return Lt(this.data.content)}getDateFormatted(){var e,t;const n=new Date(this.data.date);return(null==(t=(e=this.opts).dateFormatter)?void 0:t.call(e,n))||f(n,T)}getUserUA(){const e=function(e){const t=window||{},n=navigator||{},s=String(e||n.userAgent),i={os:"",osVersion:"",engine:"",browser:"",device:"",language:"",version:""},r={Trident:s.includes("Trident")||s.includes("NET CLR"),Presto:s.includes("Presto"),WebKit:s.includes("AppleWebKit"),Gecko:s.includes("Gecko/")},o={Safari:s.includes("Safari"),Chrome:s.includes("Chrome")||s.includes("CriOS"),IE:s.includes("MSIE")||s.includes("Trident"),Edge:s.includes("Edge")||s.includes("Edg"),Firefox:s.includes("Firefox")||s.includes("FxiOS"),"Firefox Focus":s.includes("Focus"),Servo:s.includes("Servo"),Chromium:s.includes("Chromium"),Opera:s.includes("Opera")||s.includes("OPR"),Vivaldi:s.includes("Vivaldi"),Yandex:s.includes("YaBrowser"),Kindle:s.includes("Kindle")||s.includes("Silk/"),360:s.includes("360EE")||s.includes("360SE"),UC:s.includes("UC")||s.includes(" UBrowser"),QQBrowser:s.includes("QQBrowser"),QQ:s.includes("QQ/"),Baidu:s.includes("Baidu")||s.includes("BIDUBrowser"),Maxthon:s.includes("Maxthon"),Sogou:s.includes("MetaSr")||s.includes("Sogou"),LBBROWSER:s.includes("LBBROWSER"),"2345Explorer":s.includes("2345Explorer"),TheWorld:s.includes("TheWorld"),MIUI:s.includes("MiuiBrowser"),HuaweiBrowser:s.includes("HuaweiBrowser"),Quark:s.includes("Quark"),Qiyu:s.includes("Qiyu"),"360Browser":s.includes("360Browser"),Wechat:s.includes("MicroMessenger"),Taobao:s.includes("AliApp(TB"),Alipay:s.includes("AliApp(AP"),Weibo:s.includes("Weibo"),Douban:s.includes("com.douban.frodo"),Suning:s.includes("SNEBUY-APP"),iQiYi:s.includes("IqiyiApp")},a={Windows:s.includes("Windows"),Linux:s.includes("Linux")||s.includes("X11"),macOS:s.includes("Macintosh"),Android:s.includes("Android")||s.includes("Adr"),Ubuntu:s.includes("Ubuntu"),FreeBSD:s.includes("FreeBSD"),Debian:s.includes("Debian"),"Windows Phone":s.includes("IEMobile")||s.includes("Windows Phone"),BlackBerry:s.includes("BlackBerry")||s.includes("RIM"),MeeGo:s.includes("MeeGo"),Symbian:s.includes("Symbian"),iOS:s.includes("like Mac OS X"),OpenHarmony:s.includes("OpenHarmony"),"Chrome OS":s.includes("CrOS"),WebOS:s.includes("hpwOS")},l={Mobile:s.includes("Mobi")||s.includes("iPh")||s.includes("480")||s.includes("Phone"),Tablet:s.includes("Tablet")||s.includes("Pad")||s.includes("Nexus 7")};l.Mobile?l.Mobile=!s.includes("iPad"):o.Chrome&&s.includes("Edg")?(o.Chrome=!1,o.Edge=!0):t.showModalDialog&&t.chrome&&(o.Chrome=!1,o[360]=!0),i.device="PC",i.language=(()=>{const e=(n.browserLanguage||n.language).split("-");return e[1]&&(e[1]=e[1].toUpperCase()),e.join("_")})();const c={engine:r,browser:o,os:a,device:l};Object.entries(c).forEach((([e,t])=>{Object.entries(t).forEach((([t,n])=>{!0===n&&(i[e]=t)}))}));const d={Windows:()=>{const e=s.replace(/^.*Windows NT ([\d.]+);.*$/,"$1");return{6.4:"10",6.3:"8.1",6.2:"8",6.1:"7","6.0":"Vista",5.2:"XP",5.1:"XP","5.0":"2000","10.0":"10","11.0":"11"}[e]||e},Android:()=>s.replace(/^.*Android ([\d.]+);.*$/,"$1"),iOS:()=>s.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,"."),Debian:()=>s.replace(/^.*Debian\/([\d.]+).*$/,"$1"),"Windows Phone":()=>s.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2"),macOS:()=>s.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,"."),OpenHarmony:()=>s.replace(/^.*OpenHarmony ([\d.]+).*$/,"$1"),WebOS:()=>s.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")};i.osVersion="",d[i.os]&&(i.osVersion=d[i.os](),i.osVersion===s&&(i.osVersion=""));const h={Safari:()=>s.replace(/^.*Version\/([\d.]+).*$/,"$1"),Chrome:()=>s.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1"),IE:()=>s.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1"),Edge:()=>s.replace(/^.*(Edge|Edg|Edg[A-Z]{1})\/([\d.]+).*$/,"$2"),Firefox:()=>s.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1"),"Firefox Focus":()=>s.replace(/^.*Focus\/([\d.]+).*$/,"$1"),Servo:()=>s.replace(/^.*Servo\/?([\d.]+).*$/,"$1"),Chromium:()=>s.replace(/^.*Chromium\/([\d.]+).*$/,"$1"),Opera:()=>s.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1"),Vivaldi:()=>s.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1"),Yandex:()=>s.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1"),Kindle:()=>s.replace(/^.*Version\/([\d.]+).*$/,"$1"),Maxthon:()=>s.replace(/^.*Maxthon\/([\d.]+).*$/,"$1"),QQBrowser:()=>s.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1"),QQ:()=>s.replace(/^.*QQ\/([\d.]+).*$/,"$1"),Baidu:()=>s.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1"),UC:()=>s.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1"),Sogou:()=>s.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1"),"2345Explorer":()=>s.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1"),TheWorld:()=>s.replace(/^.*TheWorld ([\d.]+).*$/,"$1"),MIUI:()=>s.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1"),HuaweiBrowser:()=>s.replace(/^.*HuaweiBrowser\/([\d.]+).*$/,"$1"),Quark:()=>s.replace(/^.*Quark\/([\d.]+).*$/,"$1"),Qiyu:()=>s.replace(/^.*Qiyu\/([\d.]+).*$/,"$1"),"360Browser":()=>s.replace(/^.*360Browser\/([\d.]+).*$/,"$1"),Wechat:()=>s.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1"),Taobao:()=>s.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1"),Alipay:()=>s.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1"),Weibo:()=>s.replace(/^.*weibo__([\d.]+).*$/,"$1"),Douban:()=>s.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1"),Suning:()=>s.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1"),iQiYi:()=>s.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")};return i.version="",h[i.browser]&&(i.version=h[i.browser](),i.version===s&&(i.version="")),i.version.indexOf(".")&&(i.version=i.version.substring(0,i.version.indexOf("."))),"iOS"===i.os&&s.includes("iPad")?i.os="iPadOS":"Edge"!==i.browser||s.includes("Edg")?"MIUI"===i.browser?i.os="Android":"Chrome"===i.browser&&Number(i.version)>27||"Opera"===i.browser&&Number(i.version)>12||"Yandex"===i.browser?i.engine="Blink":void 0===i.browser&&(i.browser="Unknow App"):i.engine="EdgeHTML",i}(this.data.ua);return{browser:`${e.browser} ${e.version}`,os:`${e.os} ${e.osVersion}`}}getOpts(){return this.opts}}class is{constructor(e){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=e,this.origText=this.opts.text||this.origText,this.$el=h(`<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(e){this.$loading.style.display=e?"":"none",this.$text.style.display=e?"none":""}showErr(e){this.setLoading(!1),this.$text.innerText=e,this.$el.classList.add("atk-err"),window.setTimeout((()=>{this.$text.innerText=this.origText,this.$el.classList.remove("atk-err")}),2e3)}update(e,t){this.offset=e,this.total=t,this.checkDisabled()}checkDisabled(){this.hasMore?this.show():this.hide()}}class rs{constructor(){c(this,"instance"),c(this,"onReachedBottom",null),c(this,"opt")}create(e){return this.opt=e,this.instance=new is({pageSize:e.pageSize,onClick:t=>d(this,null,(function*(){e.getData().fetchComments({offset:t})})),text:T("loadMore")}),e.readMoreAutoLoad&&(this.onReachedBottom=()=>{this.instance.hasMore&&!this.opt.getData().getLoading()&&this.instance.click()},this.opt.getEvents().on("list-reach-bottom",this.onReachedBottom)),this.instance.$el}setLoading(e){this.instance.setLoading(e)}update(e,t){this.instance.update(e,t)}showErr(e){this.instance.showErr(e)}next(){this.instance.click()}getHasMore(){return this.instance.hasMore}getIsClearComments(e){return 0===e.offset}dispose(){this.onReachedBottom&&this.opt.getEvents().off("list-reach-bottom",this.onReachedBottom),this.instance.$el.remove()}}class os{constructor(e,t){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=e,this.opts=t,this.$el=h('<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=e=>this.keydown(e),this.$prevBtn=this.$el.querySelector(".atk-btn-prev"),this.$nextBtn=this.$el.querySelector(".atk-btn-next"),this.$prevBtn.onclick=()=>this.prev(),this.$nextBtn.onclick=()=>this.next(),this.checkDisabled()}get pageSize(){return this.opts.pageSize}get offset(){return this.pageSize*(this.page-1)}get maxPage(){return Math.ceil(this.total/this.pageSize)}update(e,t){this.page=Math.ceil(e/this.pageSize)+1,this.total=t,this.setInput(this.page),this.checkDisabled()}setInput(e){this.$input.value=`${e}`}input(e=!1){window.clearTimeout(this.inputTimer);const t=this.$input.value.trim(),n=()=>{if(""===t)return void this.setInput(this.page);let e=Number(t);Number.isNaN(e)||e<1?this.setInput(this.page):(e>this.maxPage&&(this.setInput(this.maxPage),e=this.maxPage),this.change(e))};e?n():this.inputTimer=window.setTimeout((()=>n()),800)}prev(){const e=this.page-1;e<1||this.change(e)}next(){const e=this.page+1;e>this.maxPage||this.change(e)}getHasMore(){return this.page+1<=this.maxPage}change(e){this.page=e,this.opts.onChange(this.offset),this.setInput(e),this.checkDisabled()}checkDisabled(){this.page+1>this.maxPage?this.$nextBtn.classList.add("atk-disabled"):this.$nextBtn.classList.remove("atk-disabled"),this.page-1<1?this.$prevBtn.classList.add("atk-disabled"):this.$prevBtn.classList.remove("atk-disabled")}keydown(e){const t=e.keyCode||e.which;if(38===t){const e=Number(this.$input.value)+1;if(e>this.maxPage)return;this.setInput(e),this.input()}else if(40===t){const e=Number(this.$input.value)-1;if(e<1)return;this.setInput(e),this.input()}else 13===t&&this.input(!0)}setLoading(e){e?Qt(this.$el):Kt(this.$el)}}class as{constructor(){c(this,"instance")}create(e){return this.instance=new os(e.total,{pageSize:e.pageSize,onChange:t=>d(this,null,(function*(){e.resetEditorState(),e.getData().fetchComments({offset:t,onSuccess:()=>{var t;null==(t=e.onListGotoFirst)||t.call(e)}})}))}),this.instance.$el}setLoading(e){this.instance.setLoading(e)}update(e,t){this.instance.update(e,t)}next(){this.instance.next()}getHasMore(){return this.instance.getHasMore()}getIsClearComments(){return!0}dispose(){this.instance.$el.remove()}}function ls(e){const t={offset:0,total:0};return e?(t.offset=e.params.offset,e.data&&(t.total=e.params.flatMode?e.data.count:e.data.roots_count),t):t}const cs=e=>{let t=null;e.getConf().watchConf(["pagination","locale"],(n=>{const s=e.getList(),i=e.getData();t&&t.dispose(),t=function(e){return e.pagination.readMore?new rs:new as}(n);const{offset:r,total:o}=ls(i.getListLastFetch()),l=t.create(a({pageSize:n.pagination.pageSize,total:o,readMoreAutoLoad:n.pagination.autoLoad},e));s.getCommentsWrapEl().after(l),null==t||t.update(r,o)})),e.getEvents().on("list-loaded",(n=>{const{offset:s,total:i}=ls(e.getData().getListLastFetch());null==t||t.update(s,i)})),e.getEvents().on("list-fetch",(n=>{e.getData().getComments().length>0&&(null==t?void 0:t.getIsClearComments(n))&&e.getData().clearComments()})),e.getEvents().on("list-failed",(()=>{var e;null==(e=null==t?void 0:t.showErr)||e.call(t,T("loadFail"))})),e.getEvents().on("list-fetch",(e=>{null==t||t.setLoading(!0)})),e.getEvents().on("list-fetched",(({params:e})=>{null==t||t.setLoading(!1)}))};class ds{constructor(e){c(this,"opts"),c(this,"$el"),c(this,"$commentsWrap"),c(this,"commentNodes",[]),this.opts=e,this.$el=h('<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"),cs(a({getList:()=>this},e)),this.initCrudEvents()}getEl(){return this.$el}getCommentsWrapEl(){return this.$commentsWrap}getCommentNodes(){return this.commentNodes}getLayout({forceFlatMode:e}={}){return new Dn({$commentsWrap:this.$commentsWrap,nestSortBy:this.opts.getConf().get().nestSort,nestMax:this.opts.getConf().get().nestMax,flatMode:"boolean"==typeof e?e:this.opts.getConf().get().flatMode,createCommentNode:(t,n)=>{const s=function(e,t,n){const s=e.getConf().get(),i=new ss(t,{onAfterRender:()=>{e.getEvents().trigger("comment-rendered",i)},onDelete:t=>{e.getData().deleteComment(t.getID())},replyTo:n,flatMode:"boolean"==typeof(null==e?void 0:e.forceFlatMode)?null==e?void 0:e.forceFlatMode:s.flatMode,gravatar:s.gravatar,nestMax:s.nestMax,heightLimit:s.heightLimit,avatarURLBuilder:s.avatarURLBuilder,scrollRelativeTo:s.scrollRelativeTo,vote:s.vote,voteDown:s.voteDown,uaBadge:s.uaBadge,dateFormatter:s.dateFormatter,getApi:e.getApi,replyComment:e.replyComment,editComment:e.editComment});return i.render(),i}(a({forceFlatMode:e},this.opts),t,n);return this.commentNodes.push(s),s},findCommentNode:e=>this.commentNodes.find((t=>t.getID()===e))})}initCrudEvents(){this.opts.getEvents().on("list-load",(e=>{this.getLayout().import(e)})),this.opts.getEvents().on("list-loaded",(e=>{0===e.length&&(this.commentNodes=[],this.$commentsWrap.innerHTML="")})),this.opts.getEvents().on("comment-inserted",(e=>{var t;const n=e.rid?null==(t=this.commentNodes.find((t=>t.getID()===e.rid)))?void 0:t.getData():void 0;this.getLayout().insert(e,n)})),this.opts.getEvents().on("comment-deleted",(e=>{const t=this.commentNodes.find((t=>t.getID()===e.id));t?(t.remove(),this.commentNodes=this.commentNodes.filter((t=>t.getID()!==e.id))):console.error(`comment node id=${e.id} not found`)})),this.opts.getEvents().on("comment-updated",(e=>{const t=this.commentNodes.find((t=>t.getID()===e.id));t&&t.setData(e)}))}}class hs{constructor(e){c(this,"opts"),c(this,"$el"),c(this,"layer"),c(this,"$header"),c(this,"$closeBtn"),c(this,"$iframeWrap"),c(this,"$iframe"),c(this,"refreshWhenShow",!0),c(this,"animTimer"),this.opts=e,this.$el=h('<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()}}onUserChanged(){return d(this,null,(function*(){this.refreshWhenShow=!0}))}show(){return d(this,arguments,(function*(e={}){if(this.$el.style.transform="",this.initLayer(),this.layer.show(),this.refreshWhenShow)this.refreshWhenShow=!1,this.$iframeWrap.innerHTML="",this.$iframe=this.createIframe(e.view),this.$iframeWrap.append(this.$iframe);else{const e=this.$iframe,t=e.src;this.getDarkMode()!==t.includes("&darkMode=1")&&this.iframeLoad(e,t.replace(/&darkMode=\d/,`&darkMode=${Number(this.getDarkMode())}`))}this.authCheck({onSuccess:()=>this.show(e)}),this.animTimer=setTimeout((()=>{var e,t;this.animTimer=void 0,this.$el.style.transform="translate(0, 0)",null==(t=(e=this.opts).onShow)||t.call(e)}),100)}))}hide(){var e;null==(e=this.layer)||e.hide()}authCheck(e){return d(this,null,(function*(){const t=(yield this.opts.getApi().user.getUserStatus(a({},this.opts.getApi().getUserFields()))).data;t.is_admin&&!t.is_login&&(this.refreshWhenShow=!0,this.opts.getCheckers().checkAdmin({onSuccess:()=>{setTimeout((()=>{e.onSuccess()}),500)},onCancel:()=>{this.hide()}}),this.hide())}))}initLayer(){this.layer||(this.layer=this.opts.getLayers().create("sidebar",this.$el),this.layer.setOnAfterHide((()=>{var e,t;this.animTimer&&clearTimeout(this.animTimer),this.$el.style.transform="",null==(t=(e=this.opts).onHide)||t.call(e)})))}createIframe(e){const t=h('<iframe referrerpolicy="strict-origin-when-cross-origin"></iframe>'),n=v({base:this.opts.getConf().get().server,path:"/sidebar/"}),s={pageKey:this.opts.getConf().get().pageKey,site:this.opts.getConf().get().site||"",locale:this.opts.getConf().get().locale,user:JSON.stringify(this.opts.getUser().getData()),time:+new Date};e&&(s.view=e),s.darkMode=this.getDarkMode()?"1":"0";const i=new URLSearchParams(s);return this.iframeLoad(t,`${n}?${i.toString()}`),t}getDarkMode(){return"auto"===this.opts.getConf().get().darkMode?window.matchMedia("(prefers-color-scheme: dark)").matches:this.opts.getConf().get().darkMode}iframeLoad(e,t){e.src=t,Qt(this.$iframeWrap),e.onload=()=>{Kt(this.$iframeWrap)}}}const us=[...new Set([e=>{e.provide("data",(e=>new An(e)),["events"]),e.on("mounted",(()=>{e.getConf().fetchCommentsOnInit&&e.getData().fetchComments({offset:0})}))},e=>{e.provide("apiHandlers",(()=>function(){const e=[];return{add:(t,n)=>{e.push({action:t,handler:n})},remove:t=>{const n=e.findIndex((e=>e.action===t));-1!==n&&e.splice(n,1)},get:()=>e}}()),[]),e.provide("api",((e,t,n)=>new zt(It(t.get(),e,n))),["user","config","apiHandlers"],{lifecycle:"transient"})},e=>{e.watchConf(["locale"],(e=>{var t;(t=e.locale)!==C&&(C=t,S="string"==typeof t?E(t):t)}))},e=>{e.provide("user",(()=>new yn({onUserChanged:t=>{e.trigger("user-changed",t)}})),[])},e=>{e.provide("editor",((t,n)=>{const s=new Tn({getEvents:()=>t,getConf:()=>n});return e.getEl().appendChild(s.getEl()),s}),["events","config"])},e=>{e.provide("list",((t,n,s,i,r)=>{const o=new ds({getApi:()=>t,getEvents:()=>n,getConf:()=>s,getData:()=>i,replyComment:(e,t)=>r.setReplyComment(e,t),editComment:(e,t)=>r.setEditComment(e,t),resetEditorState:()=>r.resetState(),onListGotoFirst:()=>e.listGotoFirst()});return e.getEl().appendChild(o.getEl()),o}),["api","events","config","data","editor"])},e=>{e.provide("checkers",((t,n,s,i,r)=>{const o=new En({getApi:()=>t,getLayers:()=>s,getUser:()=>i,onReload:()=>e.reload(),getCaptchaIframeURL:()=>`${r.get().server}/api/v2/captcha/?t=${+new Date}`});return n.add("need_captcha",(e=>o.checkCaptcha(e))),n.add("need_login",(()=>o.checkAdmin({}))),o}),["api","apiHandlers","layers","user","config"])},e=>{e.provide("layers",(()=>{const t=new In;return document.body.appendChild(t.getEl()),e.on("unmounted",(()=>{null==t||t.destroy()})),t}))},e=>{e.provide("sidebar",((t,n,s,i,r,o,a,l)=>{const c=new hs({onShow:()=>{setTimeout((()=>{n.updateNotifies([])}),0),t.trigger("sidebar-show")},onHide:()=>{s.resetState(),t.trigger("sidebar-hide")},getCheckers:()=>i,getApi:()=>r,getConf:()=>o,getUser:()=>a,getLayers:()=>l});return e.on("user-changed",(()=>{null==c||c.onUserChanged()})),c}),["events","data","editor","checkers","api","config","user","layers"])}]),e=>{e.watchConf(["imgLazyLoad","markedOptions"],(e=>{!function(e){try{if(!Ue.name)return}catch(n){return}const t=new Ue;t.setOptions(a(a({renderer:$t({imgLazyLoad:e.imgLazyLoad})},Tt),e.markedOptions)),Ct=t}({markedOptions:e.markedOptions,imgLazyLoad:e.imgLazyLoad})})),e.watchConf(["markedReplacers"],(e=>{var t;e.markedReplacers&&(t=e.markedReplacers,St=t)}))},e=>{e.provide("editorPlugs",((t,n,s,i,r,o)=>{const a=new an({getArtalkRootEl:()=>e.getEl(),getEditor:()=>t,getConf:()=>n,getUser:()=>s,getApi:()=>o,getData:()=>i,getCheckers:()=>r,onSubmitted:()=>e.trigger("editor-submitted")});return t.setPlugins(a),a}),["editor","config","user","data","checkers","api"])},e=>{const t=e.inject("user"),n=()=>{var n;n=t.getData().is_admin,function(e){const t=[];e.$root.querySelectorAll("[atk-only-admin-show]").forEach((e=>t.push(e)));const n=document.querySelector(".atk-sidebar");return n&&n.querySelectorAll("[atk-only-admin-show]").forEach((e=>t.push(e))),t}({$root:e.getEl()}).forEach((e=>{n?e.classList.remove("atk-hide"):e.classList.add("atk-hide")}))};e.on("list-loaded",(()=>{n()})),e.on("user-changed",(e=>{n()}))},...dn,e=>{e.on("list-fetch",(t=>{if(0!==t.offset)return;const n=e.getApi().getUserFields();n&&e.getApi().notifies.getNotifies(n).then((t=>{e.getData().updateNotifies(t.data.notifies)}))}))},e=>{e.watchConf(["site","pageKey","pageTitle","countEl","pvEl","statPageKeyAttr","pvAdd"],(t=>{jt({getApi:()=>e.getApi(),siteName:t.site,pageKey:t.pageKey,pageTitle:t.pageTitle,countEl:t.countEl,pvEl:t.pvEl,pageKeyAttr:t.statPageKeyAttr,pvAdd:t.pvAdd})}))},e=>{const t=e.inject("list");e.watchConf(["apiVersion","versionCheck"],(e=>{e.apiVersion&&e.versionCheck&&!hn&&function(e,t,n){const s=function(e,t){const n=e.split("."),s=t.split(".");for(let i=0;i<3;i++){const e=Number(n[i]),t=Number(s[i]);if(e>t)return 1;if(t>e)return-1;if(!Number.isNaN(e)&&Number.isNaN(t))return 1;if(Number.isNaN(e)&&!Number.isNaN(t))return-1}return 0}(t,n);if(0===s)return;const i=h(`<div class="atk-version-check-notice">${T("updateMsg",{name:T(s<0?"client":"server")})} <span class="atk-info">${T("currentVersion")}: ${T("client")} ${t} / ${T("server")} ${n}</span></div>`),r=h(`<span class="atk-ignore-btn">${T("ignore")}</span>`);r.onclick=()=>{i.remove(),hn=!0},i.append(r),e.getEl().parentElement.prepend(i)}(t,ln,e.apiVersion)}))},e=>{const t=e.inject("config"),n=e.inject("layers");let s;const i=t=>{const i=[e.getEl(),n.getEl()];un||(un=window.matchMedia("(prefers-color-scheme: dark)")),"auto"===t?(s||(s=e=>pn(i,e.matches),un.addEventListener("change",s)),pn(i,un.matches)):(s&&(un.removeEventListener("change",s),s=void 0),pn(i,t))};e.watchConf(["darkMode"],(e=>i(e.darkMode))),e.on("created",(()=>i(t.get().darkMode))),e.on("unmounted",(()=>{s&&(null==un||un.removeEventListener("change",s)),s=void 0}))},e=>{const t=e.inject("config");let n,s={};e.watchConf(["pageVote"],(e=>{const t=a(a({},gn),"object"==typeof e.pageVote?e.pageVote:{});null==n||n(),e.pageVote&&(s=function(e,t,n,s){var i,r;const o=a({},e);return o.upBtnEl=document.querySelector(t.upBtnEl),o.downBtnEl=document.querySelector(t.downBtnEl),o.upCountEl=document.querySelector(t.upCountEl),o.downCountEl=document.querySelector(t.downCountEl),o.activeClass=t.activeClass,o.voteUpHandler=n,o.voteDownHandler=s,null==(i=o.upBtnEl)||i.addEventListener("click",n),null==(r=o.downBtnEl)||r.addEventListener("click",s),o}(s,t,l,c),n=()=>s=function(e){var t,n;return e.voteUpHandler&&(null==(t=e.upBtnEl)||t.removeEventListener("click",e.voteUpHandler)),e.voteDownHandler&&(null==(n=e.downBtnEl)||n.removeEventListener("click",e.voteDownHandler)),{}}(s))})),e.on("unmounted",(()=>{null==n||n(),e.off("list-fetched",r)})),e.on("list-fetched",r);let i=0;function r({data:n}){t.get().pageVote&&function(e){return e.upBtnEl||e.downBtnEl||e.upCountEl||e.downCountEl}(s)&&n&&(i!==n.page.id?(i=n.page.id,mn(s,n.page.vote_up,n.page.vote_down,!1,!1),function(e,t,n){n.votes.getVote("page",t).then((({data:t})=>{mn(e,t.up,t.down,t.is_up,t.is_down)})).catch((e=>{console.error("[ArtalkPageVote]",e)}))}(s,i,e.getApi())):mn(s,n.page.vote_up,n.page.vote_down))}const o=()=>{var t;return{state:s,pageId:(null==(t=e.getData().getPage())?void 0:t.id)||0,httpApi:e.getApi()}},l=fn("up",o),c=fn("down",o)}],ps=new Set([...us]),gs=new WeakMap;function ms(e,t){return d(this,null,(function*(){var n;const s=new Set,i=e=>{e.forEach((e=>{"function"==typeof e&&(s.has(e)||(e(t,gs.get(e)),s.add(e)))}))};i(ps);const{data:r}=yield t.getApi().conf.conf().catch((n=>{throw((e,t={})=>{var n;const s=e.inject("list"),i=e.inject("user"),r=e.inject("config"),o=t.err;if(!o)throw new Error("MountError: `err` is required");let a="";if(null==(n=o.data)?void 0:n.err_no_site){const e={create_name:r.get().site,create_urls:`${window.location.protocol}//${window.location.host}`};a=`sites|${JSON.stringify(e)}`}cn({$err:s.getEl(),errMsg:o.msg||String(o),errData:o.data,retryFn:()=>{var e;return null==(e=t.onRetry)?void 0:e.call(t)},onOpenSidebar:i.getData().is_admin?()=>e.showSidebar({view:a}):void 0})})(t,{err:n,onRetry:()=>ms(e,t)}),n}));let o=l(a({},e),{apiVersion:null==(n=r.version)?void 0:n.version});const c=function(e){const t=["el","pageKey","pageTitle","server","site","pvEl","countEl","statPageKeyAttr","pageVote"];return Object.keys(e).forEach((n=>{t.includes(n)&&delete e[n],"darkMode"===n&&"auto"!==e[n]&&delete e[n]})),e.emoticons&&"string"==typeof e.emoticons&&(e.emoticons=e.emoticons.trim(),e.emoticons.startsWith("[")||e.emoticons.startsWith("{")?e.emoticons=JSON.parse(e.emoticons):"false"===e.emoticons&&(e.emoticons=!1)),e}(r.frontend_conf||{});o=o.preferRemoteConf?Mt(o,c):Mt(c,o),t.updateConf(o),o.pluginURLs&&(yield function(e,t){return d(this,null,(function*(){const n=new Set;if(!e||!Array.isArray(e))return n;const s=[];return e.forEach((e=>{/^(http|https):\/\//.test(e)||(e=`${t.replace(/\/$/,"")}/${e.replace(/^\//,"")}`),s.push(new Promise((t=>{if(document.querySelector(`script[src="${e}"]`))return void t();const n=document.createElement("script");n.src=e,document.head.appendChild(n),n.onload=()=>t(),n.onerror=e=>{console.error("[artalk] Failed to load plugin",e),t()}})))})),yield Promise.all(s),Object.values(window.ArtalkPlugins||{}).forEach((e=>{"function"==typeof e&&n.add(e)})),n}))}(o.pluginURLs,t.getConf().server).then((e=>{i(e)})).catch((e=>{console.error("Failed to load plugin",e)})))}))}function fs({keys:e,effect:t,getConf:n,getEvents:s}){let i=null;const r=()=>{const s=(()=>{const t=n(),s={};return e.forEach((e=>{s[e]=t[e]})),s})();var r,o;(null==i||(r=i,o=s,!(JSON.stringify(r)===JSON.stringify(o))))&&(i=s,t(s))};s().on("mounted",r),s().on("updated",r)}class ks{constructor(e){c(this,"ctx");const t=function(e){let t;if("string"==typeof e.el){const n=document.querySelector(e.el);if(!n)throw new Error(`Element "${e.el}" not found.`);t=n}else{if(!(e.el instanceof HTMLElement))throw new Error("Please provide a valid `el` config for Artalk.");t=e.el}return t}(e);t.classList.add("artalk"),t.innerHTML="",1==e.darkMode&&t.classList.add("atk-dark-mode");const n=this.ctx=new Pt(t);(e=>{e.provide("events",(()=>new on))})(n),(e=>{let t=Ut({},!0);e.provide("config",(e=>{let n=!1;return e.on("mounted",(()=>n=!0)),{watchConf:(n,s)=>{fs({keys:n,effect:s,getConf:()=>t,getEvents:()=>e})},get:()=>t,update:s=>{t=Mt(t,Ut(s,!1)),n&&e.trigger("updated",t)}}}),["events"])})(n),n.updateConf(e),n.trigger("created");(()=>{d(this,null,(function*(){yield ms(e,n),n.trigger("mounted")}))})()}getConf(){return this.ctx.getConf()}getEl(){return this.ctx.getEl()}update(e){this.ctx.updateConf(e)}reload(){this.ctx.reload()}destroy(){this.ctx.destroy()}on(e,t){this.ctx.on(e,t)}off(e,t){this.ctx.off(e,t)}trigger(e,t){this.ctx.trigger(e,t)}setDarkMode(e){this.ctx.setDarkMode(e)}static init(e){return new ks(e)}static use(e,t){ps.add(e),gs.set(e,t)}static loadCountWidget(e){const t=Ut(e,!0);jt({getApi:()=>new zt(It(t)),siteName:t.site,countEl:t.countEl,pvEl:t.pvEl,pageKeyAttr:t.statPageKeyAttr,pvAdd:!1})}get $root(){return console.warn("`$root` is deprecated, please use `getEl()` instead"),this.getEl()}get conf(){return console.warn("`conf` is deprecated, please use `getConf()` instead"),this.getConf()}}const ys=ks.init,vs=ks.use,ws=ks.loadCountWidget;exports.Defaults=Rt,exports.default=ks,exports.init=ys,exports.loadCountWidget=ws,exports.use=vs;
11
11
  //# sourceMappingURL=Artalk.cjs.map