@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 +1 -1
- package/dist/Artalk.cjs.map +1 -1
- package/dist/Artalk.iife.js +1 -1
- package/dist/Artalk.iife.js.map +1 -1
- package/dist/Artalk.js +1 -1
- package/dist/Artalk.js.map +1 -1
- package/dist/Artalk.mjs +2 -1
- package/dist/Artalk.mjs.map +1 -1
- package/dist/ArtalkLite.cjs +1 -1
- package/dist/ArtalkLite.cjs.map +1 -1
- package/dist/ArtalkLite.iife.js +1 -1
- package/dist/ArtalkLite.iife.js.map +1 -1
- package/dist/ArtalkLite.js +1 -1
- package/dist/ArtalkLite.js.map +1 -1
- package/dist/ArtalkLite.mjs +2 -1
- package/dist/ArtalkLite.mjs.map +1 -1
- package/package.json +1 -1
package/dist/ArtalkLite.js
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 Ue=class extends Pe{constructor(){super(...arguments),h(this,"auth",{loginByEmail:(e,t={})=>this.request(c({path:"/auth/email/login",method:"POST",body:e,type:"application/json",format:"json"},t)),registerByEmail:(e,t={})=>this.request(c({path:"/auth/email/register",method:"POST",body:e,type:"application/json",format:"json"},t)),sendVerifyEmail:(e,t={})=>this.request(c({path:"/auth/email/send",method:"POST",body:e,type:"application/json",format:"json"},t)),checkDataMerge:(e={})=>this.request(c({path:"/auth/merge",method:"GET",secure:!0,format:"json"},e)),applyDataMerge:(e,t={})=>this.request(c({path:"/auth/merge",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t))}),h(this,"cache",{flushCache:(e={})=>this.request(c({path:"/cache/flush",method:"POST",secure:!0,format:"json"},e)),warmUpCache:(e={})=>this.request(c({path:"/cache/warm_up",method:"POST",secure:!0,format:"json"},e))}),h(this,"captcha",{getCaptcha:(e={})=>this.request(c({path:"/captcha",method:"GET",format:"json"},e)),getCaptchaStatus:(e={})=>this.request(c({path:"/captcha/status",method:"GET",format:"json"},e)),verifyCaptcha:(e,t={})=>this.request(c({path:"/captcha/verify",method:"POST",body:e,type:"application/json",format:"json"},t))}),h(this,"comments",{getComments:(e,t={})=>this.request(c({path:"/comments",method:"GET",query:e,secure:!0,type:"application/json",format:"json"},t)),createComment:(e,t={})=>this.request(c({path:"/comments",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),getComment:(e,t={})=>this.request(c({path:`/comments/${e}`,method:"GET",type:"application/json",format:"json"},t)),updateComment:(e,t,n={})=>this.request(c({path:`/comments/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deleteComment:(e,t={})=>this.request(c({path:`/comments/${e}`,method:"DELETE",secure:!0,format:"json"},t))}),h(this,"conf",{conf:(e={})=>this.request(c({path:"/conf",method:"GET",format:"json"},e)),getSocialLoginProviders:(e={})=>this.request(c({path:"/conf/auth/providers",method:"GET",format:"json"},e)),getDomain:(e,t={})=>this.request(c({path:"/conf/domain",method:"GET",query:e,format:"json"},t))}),h(this,"notifies",{getNotifies:(e,t={})=>this.request(c({path:"/notifies",method:"GET",query:e,type:"application/json",format:"json"},t)),markAllNotifyRead:(e,t={})=>this.request(c({path:"/notifies/read",method:"POST",body:e,type:"application/json",format:"json"},t)),markNotifyRead:(e,t,n={})=>this.request(c({path:`/notifies/${e}/${t}`,method:"POST",format:"json"},n))}),h(this,"pages",{getPages:(e,t={})=>this.request(c({path:"/pages",method:"GET",query:e,secure:!0,type:"application/json",format:"json"},t)),fetchAllPages:(e,t={})=>this.request(c({path:"/pages/fetch",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),getPageFetchStatus:(e={})=>this.request(c({path:"/pages/fetch/status",method:"GET",secure:!0,format:"json"},e)),logPv:(e,t={})=>this.request(c({path:"/pages/pv",method:"POST",body:e,type:"application/json",format:"json"},t)),updatePage:(e,t,n={})=>this.request(c({path:`/pages/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deletePage:(e,t={})=>this.request(c({path:`/pages/${e}`,method:"DELETE",secure:!0,format:"json"},t)),fetchPage:(e,t={})=>this.request(c({path:`/pages/${e}/fetch`,method:"POST",secure:!0,type:"application/json",format:"json"},t))}),h(this,"sendEmail",{sendEmail:(e,t={})=>this.request(c({path:"/send_email",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t))}),h(this,"settings",{getSettings:(e={})=>this.request(c({path:"/settings",method:"GET",secure:!0,format:"json"},e)),applySettings:(e,t={})=>this.request(c({path:"/settings",method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},t)),getSettingsTemplate:(e,t={})=>this.request(c({path:`/settings/template/${e}`,method:"GET",secure:!0,format:"json"},t))}),h(this,"sites",{getSites:(e={})=>this.request(c({path:"/sites",method:"GET",secure:!0,format:"json"},e)),createSite:(e,t={})=>this.request(c({path:"/sites",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),updateSite:(e,t,n={})=>this.request(c({path:`/sites/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deleteSite:(e,t={})=>this.request(c({path:`/sites/${e}`,method:"DELETE",secure:!0,format:"json"},t))}),h(this,"stats",{getStats:(e,t,n={})=>this.request(c({path:`/stats/${e}`,method:"GET",query:t,type:"application/json",format:"json"},n))}),h(this,"transfer",{exportArtrans:(e={})=>this.request(c({path:"/transfer/export",method:"GET",secure:!0,format:"json"},e)),importArtrans:(e,t={})=>this.request(c({path:"/transfer/import",method:"POST",body:e,secure:!0,type:"application/json"},t)),uploadArtrans:(e,t={})=>this.request(c({path:"/transfer/upload",method:"POST",body:e,secure:!0,type:"multipart/form-data",format:"json"},t))}),h(this,"upload",{upload:(e,t={})=>this.request(c({path:"/upload",method:"POST",body:e,secure:!0,type:"multipart/form-data",format:"json"},t))}),h(this,"user",{getUser:(e,t={})=>this.request(c({path:"/user",method:"GET",query:e,secure:!0,format:"json"},t)),updateProfile:(e,t={})=>this.request(c({path:"/user",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),login:(e,t={})=>this.request(c({path:"/user/access_token",method:"POST",body:e,type:"application/json",format:"json"},t)),getUserStatus:(e,t={})=>this.request(c({path:"/user/status",method:"GET",query:e,secure:!0,format:"json"},t))}),h(this,"users",{createUser:(e,t={})=>this.request(c({path:"/users",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),updateUser:(e,t,n={})=>this.request(c({path:`/users/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deleteUser:(e,t={})=>this.request(c({path:`/users/${e}`,method:"DELETE",secure:!0,format:"json"},t)),getUsers:(e,t,n={})=>this.request(c({path:`/users/${e}`,method:"GET",query:t,secure:!0,type:"application/json",format:"json"},n))}),h(this,"version",{getVersion:(e={})=>this.request(c({path:"/version",method:"GET",format:"json"},e))}),h(this,"votes",{syncVotes:(e={})=>this.request(c({path:"/votes/sync",method:"POST",secure:!0,format:"json"},e)),getVote:(e,t,n={})=>this.request(c({path:`/votes/${e}/${t}`,method:"GET",type:"application/json",format:"json"},n)),createVote:(e,t,n,i,s={})=>this.request(c({path:`/votes/${e}/${t}/${n}`,method:"POST",body:i,type:"application/json",format:"json"},s))})}};const je=(e,t,n)=>u(this,null,(function*(){const i=e.getApiToken&&e.getApiToken(),s=new Headers(c({Authorization:i?`Bearer ${i}`:""},null==n?void 0:n.headers));s.get("Authorization")||s.delete("Authorization");const o=yield fetch(t,d(c({},n),{headers:s}));if(!o.ok){const i=(yield o.json().catch((()=>{})))||{};let s=!1;if(e.handlers&&(yield e.handlers.get().reduce(((e,t)=>u(this,null,(function*(){yield e,!0===i[t.action]&&(yield t.handler(i),s=!0)}))),Promise.resolve())),s)return je(e,t,n);throw function(e,t){const n=new Oe;return n.message=t.msg||t.message||"fetch error",n.code=e,n.data=t,console.error(n),n}(o.status,i)}return o}));class Oe extends Error{constructor(){super(...arguments),h(this,"code",0),h(this,"message","fetch error"),h(this,"data")}}class De extends Ue{constructor(e){super({baseUrl:e.baseURL,customFetch:(t,n)=>je(e,t,n)}),h(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 Be{constructor(e){h(this,"$btn"),h(this,"$panel"),h(this,"editorStateEffectWhen"),this.kit=e}useBtn(e="<div></div>"){return this.$btn=p(`<span class="atk-plug-btn">${e}</span>`),this.$btn}usePanel(e="<div></div>"){return this.$panel=p(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 Ie="ArtalkContent";class qe{constructor(e){this.kit=e}reqAdd(){return u(this,null,(function*(){return(yield this.kit.useApi().comments.createComment(c({},yield this.getSubmitAddParams()))).data}))}getSubmitAddParams(){return u(this,null,(function*(){const{name:e,email:t,link:n}=this.kit.useUser().getData(),i=this.kit.useConf();return{content:this.kit.useEditor().getContentFinal(),name:e,email:t,link:n,rid:0,page_key:i.pageKey,page_title:i.pageTitle,site_name:i.site,ua:yield k()}}))}postSubmitAdd(e){this.kit.useData().insertComment(e)}}class Re extends Be{constructor(e){super(e),h(this,"customs",[]),h(this,"defaultPreset"),this.defaultPreset=new qe(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 u(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(`${A("commentFail")}: ${t.message||String(t)}`,"e")}finally{this.kit.useEditor().hideLoading()}this.kit.useEditor().reset(),this.kit.useEvents().trigger("editor-submitted")}))}}class _e extends Be{constructor(){super(...arguments),h(this,"isMoved",!1)}move(e){if(this.isMoved)return;this.isMoved=!0;const t=this.kit.useUI().$el;t.after(p('<div class="atk-editor-travel-placeholder"></div>'));const n=p("<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 Fe(e,t){let n=e.querySelector(":scope > .atk-loading");n||(n=p('<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 i=n.querySelector(".atk-loading-spinner");i&&(i.style.display="none",window.setTimeout((()=>{i.isConnected&&(i.style.display="")}),500))}function We(e){const t=e.querySelector(":scope > .atk-loading");t&&(t.style.display="none")}function Ne(e,t){e?Fe(t):We(t)}function He(e,t=!0,n){let i;if(n){const t=n.getBoundingClientRect();i=e.getBoundingClientRect().top-t.top+n.scrollTop-n.clientHeight/2+e.clientHeight/2}else{const t=e.getBoundingClientRect();i=t.top+window.scrollY-(window.innerHeight/2-t.height/2)}const s={top:i,left:0,behavior:"instant"};n?n.scroll(s):window.scroll(s)}function ze(e,t){!function(e,t,n="in"){e.classList.add(`atk-fade-${n}`);const i=()=>{e.classList.remove(`atk-fade-${n}`),e.removeEventListener("animationend",i)};e.addEventListener("animationend",i)}(e,0,"in")}function Ve(e,t,n='<span class="atk-error-title">Artalk Error</span>'){let i=e.querySelector(".atk-error-layer");if(null===t)return void(null!==i&&i.remove());i||(i=p(`<div class="atk-error-layer">${n}<span class="atk-error-text"></span></div>`),e.appendChild(i));const s=i.querySelector(".atk-error-text");s.innerHTML="",null!==t&&(t instanceof HTMLElement?s.appendChild(t):s.innerText=t)}class Ke extends Be{constructor(e){super(e),h(this,"emoticons",[]),h(this,"loadingTask",null),h(this,"$grpWrap"),h(this,"$grpSwitcher"),h(this,"isListLoaded",!1),h(this,"isImgLoaded",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-emoticons"></div>'),this.useBtn(`<i aria-label="${A("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((()=>{(()=>{u(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 u(this,null,(function*(){this.isListLoaded||(null===this.loadingTask?(this.loadingTask=(()=>u(this,null,(function*(){Fe(this.$panel),this.emoticons=yield this.handleData(this.kit.useConf().emoticons),We(this.$panel),this.loadingTask=null,this.isListLoaded=!0})))(),yield this.loadingTask):yield this.loadingTask)}))}handleData(e){return u(this,null,(function*(){if(!Array.isArray(e)&&["object","string"].includes(typeof e)&&(e=[e]),!Array.isArray(e))return Ve(this.$panel,`[${A("emoticon")}] Data must be of Array/Object/String type`),We(this.$panel),[];const t=t=>{"object"==typeof t&&(t.name&&e.find((e=>e.name===t.name))||e.push(t))},n=e=>u(this,null,(function*(){yield Promise.all(e.map(((e,i)=>u(this,null,(function*(){if("object"!=typeof e||Array.isArray(e)){if(Array.isArray(e))yield n(e);else if("string"==typeof e){const i=yield this.remoteLoad(e);Array.isArray(i)?yield n(i):"object"==typeof i&&t(i)}}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 u(this,null,(function*(){if(!e)return[];try{const t=yield fetch(e);return yield t.json()}catch(t){return We(this.$panel),console.error("[Emoticons] Load Failed:",t),Ve(this.$panel,`[${A("emoticon")}] ${A("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 i={name:e,type:n.type,items:[]};n.container.forEach(((t,n)=>{const s=t.icon;if(/<(img|IMG)/.test(s)){const e=/src=["'](.*?)["']/.exec(s);e&&e.length>1&&(t.icon=e[1])}i.items.push({key:t.text||`${e} ${n+1}`,val:t.icon})})),t.push(i)})),t}initEmoticonsList(){this.$grpWrap=p('<div class="atk-grp-wrap"></div>'),this.$panel.append(this.$grpWrap),this.emoticons.forEach(((e,t)=>{const n=p('<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 i=p('<span class="atk-item"></span>');if(n.append(i),t.key&&!new RegExp(`^(${e.name})?\\s?[0-9]+$`).test(t.key)&&i.setAttribute("title",t.key),"image"===e.type){const e=document.createElement("img");e.src=t.val,e.alt=t.key,i.append(e)}else i.innerText=t.val;i.onclick=()=>{"image"===e.type?this.kit.useEditor().insertContent(`:[${t.key}]`):this.kit.useEditor().insertContent(t.val||"")}}))})),this.emoticons.length>1&&(this.$grpSwitcher=p('<div class="atk-grp-switcher"></div>'),this.$panel.append(this.$grpSwitcher),this.emoticons.forEach(((e,t)=>{const n=p("<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,i;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==(i=null==(n=this.$grpSwitcher)?void 0:n.querySelector(`span[data-index="${e}"]`))||i.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 Ge=["png","jpg","jpeg","gif","bmp","svg","webp"];class Qe extends Be{constructor(e){super(e),h(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=Ge.map((e=>`.${e}`)).join(",");const e=this.useBtn(`<i aria-label="${A("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=()=>{(()=>{u(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 i=null==(n=t.dataTransfer)?void 0:n.files;(null==i?void 0:i.length)&&(t.preventDefault(),e(i))},i=t=>{var n;const i=null==(n=t.clipboardData)?void 0:n.files;(null==i?void 0:i.length)&&(t.preventDefault(),e(i))};this.kit.useMounted((()=>{this.kit.useUI().$textarea.addEventListener("dragover",t),this.kit.useUI().$textarea.addEventListener("drop",n),this.kit.useUI().$textarea.addEventListener("paste",i)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("dragover",t),this.kit.useUI().$textarea.removeEventListener("drop",n),this.kit.useUI().$textarea.removeEventListener("paste",i)}))}uploadImg(e){return u(this,null,(function*(){const t=/[^.]+$/.exec(e.name);if(!t||!Ge.includes(String(t[0]).toLowerCase()))return;if(!this.kit.useUser().checkHasBasicUserInfo())return void this.kit.useEditor().showNotify(A("uploadLoginMsg"),"w");let n="\n";""===this.kit.useUI().$textarea.value.trim()&&(n="");const i=`${n}`;let s;this.kit.useEditor().insertContent(i);try{const t=this.kit.useConf().imgUploader;s=t?{public_url:yield t(e)}:(yield this.kit.useApi().upload.upload({file:e})).data}catch(o){console.error(o),this.kit.useEditor().showNotify(`${A("uploadFail")}: ${o.message}`,"e")}if(s&&s.public_url){let e=s.public_url;$(e)||(e=w({base:this.kit.useConf().server,path:e})),this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(i,`${n}`))}else this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(i,""))}))}}class Ye extends Be{constructor(e){super(e),h(this,"isPlugPanelShow",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-preview"></div>'),this.useBtn(`<i aria-label="${A("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 Je=[class extends Be{constructor(e){super(e);const t=()=>{this.save()};this.kit.useMounted((()=>{const e=window.localStorage.getItem(Ie)||"";""!==e.trim()&&(this.kit.useEditor().showNotify(A("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(Ie,this.kit.useEditor().getContentRaw().trim())}},class extends Be{get $inputs(){return this.kit.useEditor().getHeaderInputEls()}constructor(e){super(e);const t={},n={},i=(e,t,n)=>()=>{this.kit.useEvents().trigger(e,{field:n,$input:t})};this.kit.useMounted((()=>{Object.entries(this.$inputs).forEach((([e,s])=>{s.addEventListener("input",t[e]=i("header-input",s,e)),s.addEventListener("change",n[e]=i("header-change",s,e))}))})),this.kit.useUnmounted((()=>{Object.entries(this.$inputs).forEach((([e,i])=>{i.removeEventListener("input",t[e]),i.removeEventListener("change",n[e])}))}))}},class extends Be{constructor(e){super(e),h(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:A("nick"),email:A("email"),link:A("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(c({},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 Be{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 Be{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||A("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`}},Re,class extends Be{constructor(e){super(e);const t=()=>{this.kit.useEditor().submit()};this.kit.useMounted((()=>{this.kit.useUI().$submitBtn.innerText=this.kit.useConf().sendBtn||A("send"),this.kit.useUI().$submitBtn.addEventListener("click",t)})),this.kit.useUnmounted((()=>{this.kit.useUI().$submitBtn.removeEventListener("click",t)}))}},_e,class extends Be{constructor(e){super(e),h(this,"comment"),this.useEditorStateEffect("reply",(e=>(this.setReply(e),()=>{this.cancelReply()}))),this.kit.useEvents().on("mounted",(()=>{const e=this.kit.useDeps(Re);if(!e)throw Error("SubmitPlug not initialized");const t=new qe(this.kit);e.registerCustom({activeCond:()=>!!this.comment,req:()=>u(this,null,(function*(){if(!this.comment)throw new Error("reply comment cannot be empty");return(yield this.kit.useApi().comments.createComment(d(c({},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=p(`<span class="atk-state-btn"><span class="atk-text-wrap">${A("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 Be{constructor(e){super(e),h(this,"comment"),h(this,"originalSubmitBtnText","Send"),this.useEditorStateEffect("edit",(e=>(this.edit(e),()=>{this.cancelEdit()}))),this.kit.useMounted((()=>{const e=this.kit.useDeps(Re);if(!e)throw Error("SubmitPlug not initialized");e.registerCustom({activeCond:()=>!!this.comment,req:()=>u(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,c(c({},t),e))).data})),post:e=>{this.kit.useData().updateComment(e)}})}))}edit(e){const t=this.kit.useUI();if(!t.$editCancelBtn){const e=p(`<span class="atk-state-btn"><span class="atk-text-wrap">${A("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(A("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:i}=this.kit.useUser().getData();e.$name.value=t,e.$email.value=n,e.$link.value=i,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 Be{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(p(`<div class="atk-comment-closed">${A("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")}},Ke,Qe,Ye];class Xe{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 Ze{constructor(){h(this,"events",[])}on(e,t,n={}){this.events.push(c({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 et{constructor(e){h(this,"plugins",[]),h(this,"openedPlug",null),h(this,"events",new Ze),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(Qe,e.imgUpload),t.set(Ke,e.emoticons),t.set(Ye,e.preview),t.set(_e,e.editorTravel),Je.filter((e=>!t.has(e)||!!t.get(e)))}(e).forEach((e=>{const t=new Xe(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 Ze,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 tt="2.9.2";function nt(e){const t=p('<span><span class="error-message"></span><br/><br/></span>');if(t.querySelector(".error-message").innerText=`${A("listLoadFailMsg")}\n${e.errMsg}`,e.retryFn){const n=p(`<span style="cursor:pointer;">${A("listRetry")}</span>`);n.onclick=()=>e.retryFn&&e.retryFn(),t.appendChild(n)}if(e.onOpenSidebar){const n=p(`<span atk-only-admin-show> | <span style="cursor:pointer;">${A("openName",{name:A("ctrlCenter")})}</span></span>`);t.appendChild(n),n.onclick=()=>e.onOpenSidebar&&e.onOpenSidebar()}Ve(e.$err,t)}const it=[e=>{const t=e.inject("config");e.on("list-fetch",(n=>{if(e.getData().getLoading())return;e.getData().setLoading(!0);const i=c({offset:0,limit:t.get().pagination.pageSize,flatMode:t.get().flatMode,paramsModifier:t.get().listFetchParamsModifier},n);e.getData().setListLastFetch({params:i});const s={limit:i.limit,offset:i.offset,flat_mode:i.flatMode,page_key:t.get().pageKey,site_name:t.get().site};i.paramsModifier&&i.paramsModifier(s),e.getApi().comments.getComments(c(c({},s),e.getApi().getUserFields())).then((({data:t})=>{e.getData().setListLastFetch({params:i,data:t}),e.getData().loadComments(t.comments),e.getData().updatePage(t.page),i.onSuccess&&i.onSuccess(t),e.trigger("list-fetched",{params:i,data:t})})).catch((t=>{const n={msg:t.msg||String(t),data:t.data};throw i.onError&&i.onError(n),e.trigger("list-failed",n),e.trigger("list-fetched",{params:i,error:n}),t})).finally((()=>{e.getData().setLoading(!1)}))}))},e=>{const t=e.inject("list");e.on("list-fetch",(e=>{0===e.offset&&Ne(!0,t.getEl())})),e.on("list-fetched",(()=>{Ne(!1,t.getEl())}))},e=>{const t=e.inject("config");e.on("comment-rendered",(n=>{if(t.get().listUnreadHighlight){const t=e.getData().getNotifies(),i=t.find((e=>e.comment_id===n.getID()));i?(n.getRender().setUnread(!0),n.getRender().setOpenAction((()=>{window.open(i.read_link),e.getData().updateNotifies(t.filter((e=>e.comment_id!==n.getID())))}))):n.getRender().setUnread(!1)}})),e.on("list-goto",(t=>{const n=g("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 i;e.on("mounted",(()=>{i=t.getEl().querySelector('[data-action="admin-close-comment"]'),i.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(`${A("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"),i&&(i.innerText=A("openComment"))):(null==n||n.getEvents().trigger("editor-open"),i&&(i.innerText=A("closeComment")))})),e.on("list-loaded",(t=>{e.editorResetState()}))},e=>{const t=e.inject("list");e.on("list-loaded",(()=>{(()=>{var n,i;const s=t.getEl().querySelector(".atk-comment-count .atk-text");if(!s)return;const o=m(A("counter",{count:`${Number(null==(i=null==(n=e.getData().getListLastFetch())?void 0:n.data)?void 0:i.count)||0}`}));s.innerHTML=o.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 i=()=>{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?A("ctrlCenter"):A("msgCenter"))}else n.classList.add("atk-hide")};e.watchConf(["locale"],(s=>{n=t.getEl().querySelector('[data-action="open-sidebar"]'),n&&(n.onclick=()=>{e.showSidebar()},i())})),e.on("user-changed",(e=>{i()}))},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"),i=t=>{n.update({listFetchParamsModifier:t}),e.reload()},s=e=>{!function(e){const{$dropdownWrap:t,dropdownList:n}=e;if(t.querySelector(".atk-dropdown"))return;t.classList.add("atk-dropdown-wrap"),t.append(p('<span class="atk-arrow-down-icon"></span>'));let i=0;const s=(e,t,n,s)=>{s(),i=e,o.querySelectorAll(".active").forEach((e=>{e.classList.remove("active")})),t.classList.add("active"),o.style.display="none",setTimeout((()=>{o.style.display=""}),80)},o=p('<ul class="atk-dropdown atk-fade-in"></ul>');n.forEach(((e,t)=>{const[n,a]=e,r=p('<li class="atk-dropdown-item"><span></span></li>'),l=r.querySelector("span");l.innerText=n,l.onclick=()=>{s(t,r,n,a)},o.append(r),t===i&&r.classList.add("active")})),t.append(o)}({$dropdownWrap:e,dropdownList:[[A("sortLatest"),()=>{i((e=>{e.sort_by="date_desc"}))}],[A("sortBest"),()=>{i((e=>{e.sort_by="vote"}))}],[A("sortOldest"),()=>{i((e=>{e.sort_by="date_asc"}))}],[A("sortAuthor"),()=>{i((e=>{e.view_only_admin=!0}))}]]})};e.watchConf(["listSort","locale"],(e=>{const n=t.getEl().querySelector(".atk-comment-count");n&&(e.listSort?s(n):function(e){var t,n;const{$dropdownWrap:i}=e;i.classList.remove("atk-dropdown-wrap"),null==(t=i.querySelector(".atk-arrow-down-icon"))||t.remove(),null==(n=i.querySelector(".atk-dropdown"))||n.remove()}({$dropdownWrap:n}))}))},e=>{let t=0;const n=({locker:n})=>{const i=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(g("atk_comment")));return t||null}();i&&(n&&t===i||(t=i,e.trigger("list-goto",i)))},i=()=>n({locker:!1}),s=()=>n({locker:!0});e.on("mounted",(()=>{window.addEventListener("hashchange",i),e.on("list-loaded",s)})),e.on("unmounted",(()=>{window.removeEventListener("hashchange",i),e.off("list-loaded",s)}))},e=>{const t=e.inject("list");e.on("list-goto",(n=>u(this,null,(function*(){let i=e.getCommentNodes().find((e=>e.getID()===n));if(!i){const s=(yield e.getApi().comments.getComment(n)).data;t.getLayout({forceFlatMode:!0}).insert(s.comment,s.reply_comment),i=e.getCommentNodes().find((e=>e.getID()===n))}i&&i.focus()}))))},e=>{const t=e.inject("list"),n=e.inject("config");e.on("list-loaded",(i=>{const s=i.length<=0;let o=t.getCommentsWrapEl().querySelector(".atk-list-no-comment");s?o||(o=p('<div class="atk-list-no-comment"></div>'),o.innerHTML=he(n.get().noComment||e.$t("noComment")),t.getCommentsWrapEl().appendChild(o)):null==o||o.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${tt}">Artalk</a>`)}))},e=>{const t=e.inject("list"),n=e.inject("config");let i=null;e.on("mounted",(()=>{i=window.setInterval((()=>{t.getEl().querySelectorAll("[data-atk-comment-date]").forEach((t=>{var i,s;const o=new Date(Number(t.getAttribute("data-atk-comment-date")));t.innerText=(null==(s=(i=n.get()).dateFormatter)?void 0:s.call(i,o))||y(o,e.$t)}))}),3e4)})),e.on("unmounted",(()=>{i&&window.clearInterval(i)}))},e=>{const t=e.inject("list");e.on("list-fetch",(()=>{Ve(t.getEl(),null)})),e.on("list-failed",(n=>{nt({$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 i=null;const s=()=>{null==i||i.disconnect(),i=null};e.on("list-loaded",(()=>{s();const o=t.getCommentsWrapEl().childNodes,a=o.length>2?o[o.length-2]:null;a&&("IntersectionObserver"in window?(t=>{var o,a;const r=(null==(a=(o=n.get()).scrollRelativeTo)?void 0:a.call(o))||null;i=new IntersectionObserver((([t])=>{t.isIntersecting&&(s(),e.trigger("list-reach-bottom"))}),{threshold:.9,root:r}),i.observe(t)})(a):console.warn("IntersectionObserver api not supported"))})),e.on("unmounted",(()=>{s()}))},e=>{const t=e.inject("list"),n=e.inject("config"),i=()=>{var e,i;const s=null==(i=(e=n.get()).scrollRelativeTo)?void 0:i.call(e);(s||window).scroll({top:f(t.getEl(),s).top,left:0})};e.on("mounted",(()=>{e.on("list-goto-first",i)})),e.on("unmounted",(()=>{e.off("list-goto-first",i)}))}];let st=!1;let ot;function at(e,t){const n="atk-dark-mode";e.forEach((e=>{t?e.classList.add(n):e.classList.remove(n)}))}const rt={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 lt(e,t,n,i,s){var o,a;e.upCountEl?e.upCountEl.innerText=String(t):e.upBtnEl&&(e.upBtnEl.innerText=`${A("voteUp")} (${t})`),e.downCountEl?e.downCountEl.innerText=String(n):e.downBtnEl&&(e.downBtnEl.innerText=`${A("voteDown")} (${n})`),"boolean"==typeof i&&(null==(o=e.upBtnEl)||o.classList.toggle(e.activeClass||"active",i)),"boolean"==typeof s&&(null==(a=e.downBtnEl)||a.classList.toggle(e.activeClass||"active",s))}const ct=(e,t)=>n=>{n.preventDefault();const{state:i,pageId:s,httpApi:o}=t();s&&o.votes.createVote("page",s,e,c({},o.getUserFields())).then((({data:e})=>{lt(i,e.up,e.down,e.is_up,e.is_down)})).catch((e=>{window.alert(A("voteFail")),console.error("[ArtalkPageVote]",e)}))};const dt="ArtalkUser";class ht{constructor(e){h(this,"data"),this.opts=e;const t=JSON.parse(window.localStorage.getItem(dt)||"{}");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(dt,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 ut(e){const t=p('<div class="atk-checker-iframe-wrap"></div>'),n=p('<iframe class="atk-fade-in" referrerpolicy="strict-origin-when-cross-origin"></iframe>');n.style.display="none",Fe(t,{transparentBg:!0}),n.src=e.getOpts().getCaptchaIframeURL(),n.onload=()=>{n.style.display="",We(t)},t.append(n);const i=p('<div class="atk-close-btn"><i class="atk-icon atk-icon-close"></i></div>');t.append(i),e.hideInteractInput();let s=!1;return function t(){return u(this,null,(function*(){var n;if(yield(n=1e3,new Promise((e=>{window.setTimeout((()=>{e(null)}),n)}))),s)return;let i=!1;try{i=(yield e.getApi().captcha.getCaptchaStatus()).data.is_pass}catch(o){i=!1}i?e.triggerSuccess():t()}))}(),i.onclick=()=>{s=!0,e.cancel()},t}const pt={request:(e,t)=>e.getApi().captcha.verifyCaptcha({value:t}),body:e=>e.get("iframe")?ut(e):function(e){const t=p(`<span><img class="atk-captcha-img" src="${e.get("img_data")||""}">${A("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,i){e.set("val",n)},onError(e,t,n,i){i.querySelector(".atk-captcha-img").click(),i.querySelector('input[type="text"]').value=""}},mt={inputType:"password",request(e,t){return u(this,null,(function*(){return(yield e.getApi().user.login({name:e.getUser().getData().name,email:e.getUser().getData().email,password:t})).data}))},body:e=>p(`<span>${A("adminCheck")}</span>`),onSuccess(e,t,n,i){e.getUser().update({is_admin:!0,token:t.token}),e.getOpts().onReload()},onError(e,t,n,i){}};class gt{constructor(e){h(this,"$el"),h(this,"$content"),h(this,"$actions"),this.$el=p('<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=p(`<button data-action="confirm">${A("confirm")}</button>`);return t.onclick=this.onBtnClick(e),this.$actions.appendChild(t),this}setNo(e){const t=p(`<button data-action="cancel">${A("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 ft(e){return t=>new Promise(((n,i)=>{const s=t.onCancel;t.onCancel=()=>{s&&s(),i(new Error("user canceled the checker"))};const o=t.onSuccess;t.onSuccess=()=>{o&&o(),n()},e(t)}))}class vt{constructor(e){h(this,"checkCaptcha",ft((e=>{this.check(pt,e,(t=>{t.set("img_data",e.img_data),t.set("iframe",e.iframe)}))}))),h(this,"checkAdmin",ft((e=>{this.check(mt,e)}))),this.opts=e}check(e,t,n){const i=this.opts.getLayers().create(`checker-${(new Date).getTime()}`);i.show();const s=()=>{i.destroy()},o={};let a=!1;const r={set:(e,t)=>{o[e]=t},get:e=>o[e],getOpts:()=>this.opts,getUser:()=>this.opts.getUser(),getApi:()=>this.opts.getApi(),hideInteractInput:()=>{a=!0},triggerSuccess:()=>{s(),e.onSuccess&&e.onSuccess(r,"","",l),t.onSuccess&&t.onSuccess()},cancel:()=>{s(),t.onCancel&&t.onCancel()}};n&&n(r);const l=p();l.appendChild(e.body(r));const c=p(`<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(),i.getEl().querySelector('button[data-action="confirm"]').click())};const h=new gt(l);h.setYes((n=>{const i=c.value.trim();d||(d=n.innerText);const o=()=>{n.innerText=d||"",n.classList.remove("error")};return n.innerText=`${A("loading")}...`,e.request(r,i).then((n=>{s(),e.onSuccess&&e.onSuccess(r,n,i,l),t.onSuccess&&t.onSuccess()})).catch((t=>{var s;s=String(t.message||String(t)),n.innerText=s,n.classList.add("error"),e.onError&&e.onError(r,t,i,l);const a=setTimeout((()=>o()),3e3);c.onfocus=()=>{o(),clearTimeout(a)}})),!1})),h.setNo((()=>(s(),t.onCancel&&t.onCancel(),!1))),a&&(c.style.display="none",h.$el.querySelector(".atk-layer-dialog-actions").style.display="none"),i.getEl().append(h.$el),t.onMount&&t.onMount(h.$el)}}const yt={$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 kt{constructor(e){h(this,"stateCurt","normal"),h(this,"stateUnmountFn",null),this.editor=e}get(){return this.stateCurt}switch(e,t){var n,i,s,o,a,r,l;if(this.stateUnmountFn&&(this.stateUnmountFn(),this.stateUnmountFn=null,null==(i=null==(n=this.editor.getPlugins())?void 0:n.get(_e))||i.back()),"normal"!==e&&t){let n=t.$comment;this.editor.getOptions().getConf().get().flatMode||(n=n.querySelector(".atk-footer")),null==(o=null==(s=this.editor.getPlugins())?void 0:s.get(_e))||o.move(n);const i=null==(r=(a=this.editor.getOptions().getConf().get()).scrollRelativeTo)?void 0:r.call(a);He(this.editor.getUI().$el,!0,i);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 $t{constructor(e){h(this,"opts"),h(this,"$el"),h(this,"ui"),h(this,"state"),h(this,"plugins"),this.opts=e,this.ui=function(){const e=p('<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(yt).forEach((([n,i])=>{t[n]=e.querySelector(i)})),t}(),this.$el=this.ui.$el,this.state=new kt(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 Ee(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,i=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=i}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 i=p(`<div class="atk-notify atk-fade-in" style="background-color: ${{s:"#57d59f",e:"#ff6f6c",w:"#ffc721",i:"#2ebcfc"}[n]}"><span class="atk-notify-content"></span></div>`);i.querySelector(".atk-notify-content").innerHTML=m(t).replace("\n","<br/>"),e.appendChild(i);const s=()=>{i.classList.add("atk-fade-out"),setTimeout((()=>{i.remove()}),200)};let o;o=window.setTimeout((()=>{s()}),3e3),i.addEventListener("click",(()=>{s(),window.clearTimeout(o)}))}(this.ui.$notifyWrap,e,t)}showLoading(){Fe(this.ui.$el)}hideLoading(){We(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 wt{constructor(e){h(this,"loading",!1),h(this,"listLastFetch"),h(this,"comments",[]),h(this,"notifies",[]),h(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 bt{constructor(e,t){h(this,"allowMaskClose",!0),h(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 Et,Ct;function St(){return{init(){Et=document.body.style.overflow,Ct=document.body.style.paddingRight},unlock(){document.body.style.overflow=Et,document.body.style.paddingRight=Ct},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 i=e.offsetWidth;return n===i&&(i=t.clientWidth),document.body.removeChild(t),n-i}()+e||0}px`}}}class xt{constructor(){h(this,"$wrap"),h(this,"$mask"),h(this,"items",[]),this.$wrap=p('<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 bt(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"),St().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",St().unlock())}}class Tt{constructor(){h(this,"wrap",new xt),St().init()}getEl(){return this.wrap.getWrap()}create(e,t){return this.wrap.createItem(e,t)}destroy(){this.wrap.getWrap().remove()}}const Lt=e=>({import:t=>{(function(e,t="DATE_DESC",n=2){const i=[];e.filter((e=>0===e.rid)).forEach((t=>{const s={id:t.id,comment:t,children:[],level:1};s.parent=s,i.push(s),function t(i){const s=e.filter((e=>e.rid===i.id));0!==s.length&&(i.level>=n&&(i=i.parent),s.forEach((e=>{const n={id:e.id,comment:e,children:[],parent:i,level:i.level+1};i.children.push(n),t(n)})))}(s)}));const s=(n,i)=>{let s=n.id-i.id;return"DATE_ASC"===t?s=+new Date(n.comment.date)-+new Date(i.comment.date):"DATE_DESC"===t?s=+new Date(i.comment.date)-+new Date(n.comment.date):"SRC_INDEX"===t?s=e.indexOf(n.comment)-e.indexOf(i.comment):"VOTE_UP_DESC"===t&&(s=i.comment.vote_up-n.comment.vote_up),s};return function e(t){t.forEach((t=>{t.children=t.children.sort(s),e(t.children)}))}(i),i})(t,e.nestSortBy,e.nestMax).forEach((n=>{var i;const s=e.createCommentNode(n.comment);null==(i=e.$commentsWrap)||i.appendChild(s.getEl()),s.getRender().playFadeAnim();const o=(n,i)=>{i.children.forEach((i=>{const s=t.find((e=>e.id===i.comment.rid)),a=i.comment,r=e.createCommentNode(a,s);n.putChild(r),o(r,i)}))};o(s,n),s.getRender().checkHeightLimit()}))},insert:(t,n)=>{var i;const s=e.createCommentNode(t,n);if(0===t.rid)null==(i=e.$commentsWrap)||i.prepend(s.getEl());else{const n=e.findCommentNode(t.rid);n&&(n.putChild(s,"DATE_ASC"===e.nestSortBy?"append":"prepend"),s.getParents().forEach((e=>{e.getRender().heightLimitRemoveForChildren()})))}s.getRender().checkHeightLimit(),s.scrollIntoView(),s.getRender().playFadeAnim()}});function At(e,t,n,i){n.is_collapsed&&(n.is_allow_reply=!1);const s=e.createCommentNode(n,i);if(n.visible){const n=s.getEl(),i=e.$commentsWrap;"append"===t&&(null==i||i.append(n)),"prepend"===t&&(null==i||i.prepend(n)),s.getRender().playFadeAnim()}return s.getRender().checkHeightLimit(),s}class Mt{constructor(e){this.options=e}getStrategy(){return this.options.flatMode?(e=this.options,{import:t=>{t.forEach((n=>{const i=0===n.rid?void 0:t.find((e=>e.id===n.rid));At(e,"append",n,i)}))},insert:(t,n)=>{At(e,"prepend",t,n).scrollIntoView()}}):Lt(this.options);var e}import(e){this.getStrategy().import(e)}insert(e,t){this.getStrategy().insert(e,t)}}function Pt(e,t){t.forEach((({el:t,max:n,imgCheck:i})=>{if(!t)return;i&&(t.style.maxHeight=`${n+1}px`);let s=!1;const o=()=>{if(s)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(Ot))return;e.el.classList.add(Ot),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(Ut))return;e.el.classList.add(Ut),e.el.style.height=`${e.max}px`,e.el.style.overflow="hidden";const t=p(`<div class="atk-height-limit-btn">${A("readMore")}</span>`);t.onclick=t=>{t.stopPropagation(),jt(e.el),e.afterExpandBtnClick&&e.afterExpandBtnClick(t)},e.el.append(t)}({el:t,max:n,afterExpandBtnClick:()=>{var t;s=!0,null==(t=e.afterExpandBtnClick)||t.call(e)}})};if(o(),i){const e=t.querySelectorAll(".atk-content img");0===e.length&&(t.style.maxHeight=""),e.forEach((e=>{e.onload=()=>o()}))}}))}const Ut="atk-height-limit";function jt(e){e&&e.classList.contains(Ut)&&(e.classList.remove(Ut),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 Ot="atk-height-limit-scroll";function Dt(e){if(e.$headerNick=e.$el.querySelector(".atk-nick"),e.data.link){const t=p('<a target="_blank" rel="noreferrer noopener nofollow"></a>');t.innerText=e.data.nick,t.href=$(e.data.link)?e.data.link:`https://${e.data.link}`,e.$headerNick.append(t)}else e.$headerNick.innerText=e.data.nick}function Bt(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 i=p('<span class="atk-badge"></span>');i.innerText=t.replace("管理员",A("admin")),i.style.backgroundColor=n||"",e.$headerBadgeWrap.append(i)}else if(e.data.is_verified){const t=p(`<span class="atk-icon-verified" title="${A("emailVerified")}"></span>`);e.$headerBadgeWrap.append(t)}if(e.data.is_pinned){const t=p(`<span class="atk-pinned-badge">${A("pin")}</span>`);e.$headerBadgeWrap.append(t)}}function It(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 qt(e){if(!e.opts.uaBadge&&!e.data.ip_region)return;let t=e.$header.querySelector("atk-ua-wrap");if(t||(t=p('<span class="atk-ua-wrap"></span>'),e.$header.append(t)),t.innerHTML="",e.data.ip_region){const n=p('<span class="atk-region-badge"></span>');n.innerText=e.data.ip_region,t.append(n)}if(e.opts.uaBadge){const{browser:n,os:i}=e.comment.getUserUA();if(String(n).trim()){const e=p('<span class="atk-ua ua-browser"></span>');e.innerText=n,t.append(e)}if(String(i).trim()){const e=p('<span class="atk-ua ua-os"></span>');e.innerText=i,t.append(e)}}}class Rt{constructor(e){h(this,"opts"),h(this,"$el"),h(this,"isLoading",!1),h(this,"msgRecTimer"),h(this,"msgRecTimerFunc"),h(this,"isConfirming",!1),h(this,"confirmRecTimer"),this.$el=p('<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||A("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||`${A("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,i){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),i&&i()}),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 _t(e){e.opts.vote&&(e.voteBtnUp=new Rt((()=>`${A("voteUp")} (${e.data.vote_up||0})`)).appendTo(e.$actions),e.voteBtnUp.setClick((()=>{e.comment.getActions().vote("up")})),e.opts.voteDown&&(e.voteBtnDown=new Rt((()=>`${A("voteDown")} (${e.data.vote_down||0})`)).appendTo(e.$actions),e.voteBtnDown.setClick((()=>{e.comment.getActions().vote("down")}))))}function Ft(e){if(!e.data.is_allow_reply)return;const t=new Rt({text:A("reply")});t.appendTo(e.$actions),t.setClick((()=>{e.opts.replyComment(e.data,e.$el)}))}function Wt(e){const t=new Rt({text:()=>e.data.is_collapsed?A("expand"):A("collapse"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminEdit("collapsed",t)}))}function Nt(e){const t=new Rt({text:()=>e.data.is_pending?A("pending"):A("approved"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminEdit("pending",t)}))}function Ht(e){const t=new Rt({text:()=>e.data.is_pinned?A("unpin"):A("pin"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminEdit("pinned",t)}))}function zt(e){const t=new Rt({text:A("edit"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.opts.editComment(e.data,e.$el)}))}function Vt(e){const t=new Rt({text:A("delete"),confirm:!0,confirmText:A("deleteConfirm"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminDelete(t)}))}const Kt={Avatar:function(e){const t=e.$el.querySelector(".atk-avatar"),n=p("<img />"),i=e.opts.avatarURLBuilder;if(n.src=i?i(e.data):e.comment.getGravatarURL(),e.data.link){const i=p('<a target="_blank" rel="noreferrer noopener nofollow"></a>');i.href=$(e.data.link)?e.data.link:`https://${e.data.link}`,i.append(n),t.append(i)}else t.append(n)},Header:function(e){Object.entries({renderNick:Dt,renderVerifyBadge:Bt,renderDate:It,renderUABadge:qt}).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=p(`\n <div class="atk-collapsed">\n <span class="atk-text">${A("collapsedMsg")}</span>\n <span class="atk-show-btn">${A("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"),ze(e.$content),n.innerText=A("collapse")):(e.$content.innerHTML="",e.$content.classList.add("atk-hide"),n.innerText=A("expand"))}))},ReplyAt:function(e){e.opts.flatMode||0===e.data.rid||e.opts.replyTo&&(e.$replyAt=p('<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=p(`\n <div class="atk-reply-to">\n <div class="atk-meta">${A("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=Ee(e.opts.replyTo.content);e.opts.replyTo.is_collapsed&&(n=`[${A("collapsed")}]`),e.$replyTo.querySelector(".atk-content").innerHTML=n,e.$body.prepend(e.$replyTo)},Pending:function(e){if(!e.data.is_pending)return;const t=p(`<div class="atk-pending">${A("pendingMsg")}</div>`);e.$body.prepend(t)},Actions:function(e){Object.entries({renderVote:_t,renderReply:Ft,renderCollapse:Wt,renderModerator:Nt,renderPin:Ht,renderEdit:zt,renderDel:Vt}).forEach((([t,n])=>{n(e)}))}};class Gt{constructor(e){h(this,"comment"),h(this,"$el"),h(this,"$main"),h(this,"$header"),h(this,"$headerNick"),h(this,"$headerBadgeWrap"),h(this,"$body"),h(this,"$content"),h(this,"$childrenWrap"),h(this,"$actions"),h(this,"voteBtnUp"),h(this,"voteBtnDown"),h(this,"$replyTo"),h(this,"$replyAt"),this.comment=e}get data(){return this.comment.getData()}get opts(){return this.comment.getOpts()}render(){var e;return this.$el=p('<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(Kt).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;Pt({afterExpandBtnClick:()=>{const e=this.comment.getChildren();1===e.length&&jt(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&&jt(this.$childrenWrap)}playFadeAnim(){ze(this.comment.getRender().$el)}playFadeAnimForBody(){ze(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=p('<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 Qt{constructor(e){h(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,c({},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(A("voteFail")),console.error(e)}))}adminEdit(e,t){if(t.isLoading)return;t.setLoading(!0,`${A("editing")}...`);const n=c({},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,c({},n)).then((e=>{t.setLoading(!1),this.comment.setData(e.data)})).catch((e=>{console.error(e),t.setError(A("editFail"))}))}adminDelete(e){e.isLoading||(e.setLoading(!0,`${A("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(A("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 Yt{constructor(e,t){h(this,"$el"),h(this,"renderInstance"),h(this,"actionInstance"),h(this,"data"),h(this,"opts"),h(this,"parent"),h(this,"children",[]),h(this,"nestCurt"),this.opts=t,this.data=c({},e),this.data.date=this.data.date.replace(/-/g,"/"),this.parent=null,this.nestCurt=1,this.actionInstance=new Qt(this),this.renderInstance=new Gt(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(),i=e.getEl();"append"===t?n.append(i):"prepend"===t&&n.prepend(i),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&&He(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 Ee(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))||y(n,A)}getUserUA(){const e=function(e){const t=window||{},n=navigator||{},i=String(e||n.userAgent),s={os:"",osVersion:"",engine:"",browser:"",device:"",language:"",version:""},o={Trident:i.includes("Trident")||i.includes("NET CLR"),Presto:i.includes("Presto"),WebKit:i.includes("AppleWebKit"),Gecko:i.includes("Gecko/")},a={Safari:i.includes("Safari"),Chrome:i.includes("Chrome")||i.includes("CriOS"),IE:i.includes("MSIE")||i.includes("Trident"),Edge:i.includes("Edge")||i.includes("Edg"),Firefox:i.includes("Firefox")||i.includes("FxiOS"),"Firefox Focus":i.includes("Focus"),Servo:i.includes("Servo"),Chromium:i.includes("Chromium"),Opera:i.includes("Opera")||i.includes("OPR"),Vivaldi:i.includes("Vivaldi"),Yandex:i.includes("YaBrowser"),Kindle:i.includes("Kindle")||i.includes("Silk/"),360:i.includes("360EE")||i.includes("360SE"),UC:i.includes("UC")||i.includes(" UBrowser"),QQBrowser:i.includes("QQBrowser"),QQ:i.includes("QQ/"),Baidu:i.includes("Baidu")||i.includes("BIDUBrowser"),Maxthon:i.includes("Maxthon"),Sogou:i.includes("MetaSr")||i.includes("Sogou"),LBBROWSER:i.includes("LBBROWSER"),"2345Explorer":i.includes("2345Explorer"),TheWorld:i.includes("TheWorld"),MIUI:i.includes("MiuiBrowser"),HuaweiBrowser:i.includes("HuaweiBrowser"),Quark:i.includes("Quark"),Qiyu:i.includes("Qiyu"),"360Browser":i.includes("360Browser"),Wechat:i.includes("MicroMessenger"),Taobao:i.includes("AliApp(TB"),Alipay:i.includes("AliApp(AP"),Weibo:i.includes("Weibo"),Douban:i.includes("com.douban.frodo"),Suning:i.includes("SNEBUY-APP"),iQiYi:i.includes("IqiyiApp")},r={Windows:i.includes("Windows"),Linux:i.includes("Linux")||i.includes("X11"),macOS:i.includes("Macintosh"),Android:i.includes("Android")||i.includes("Adr"),Ubuntu:i.includes("Ubuntu"),FreeBSD:i.includes("FreeBSD"),Debian:i.includes("Debian"),"Windows Phone":i.includes("IEMobile")||i.includes("Windows Phone"),BlackBerry:i.includes("BlackBerry")||i.includes("RIM"),MeeGo:i.includes("MeeGo"),Symbian:i.includes("Symbian"),iOS:i.includes("like Mac OS X"),OpenHarmony:i.includes("OpenHarmony"),"Chrome OS":i.includes("CrOS"),WebOS:i.includes("hpwOS")},l={Mobile:i.includes("Mobi")||i.includes("iPh")||i.includes("480")||i.includes("Phone"),Tablet:i.includes("Tablet")||i.includes("Pad")||i.includes("Nexus 7")};l.Mobile?l.Mobile=!i.includes("iPad"):a.Chrome&&i.includes("Edg")?(a.Chrome=!1,a.Edge=!0):t.showModalDialog&&t.chrome&&(a.Chrome=!1,a[360]=!0),s.device="PC",s.language=(()=>{const e=(n.browserLanguage||n.language).split("-");return e[1]&&(e[1]=e[1].toUpperCase()),e.join("_")})();const c={engine:o,browser:a,os:r,device:l};Object.entries(c).forEach((([e,t])=>{Object.entries(t).forEach((([t,n])=>{!0===n&&(s[e]=t)}))}));const d={Windows:()=>{const e=i.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:()=>i.replace(/^.*Android ([\d.]+);.*$/,"$1"),iOS:()=>i.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,"."),Debian:()=>i.replace(/^.*Debian\/([\d.]+).*$/,"$1"),"Windows Phone":()=>i.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2"),macOS:()=>i.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,"."),OpenHarmony:()=>i.replace(/^.*OpenHarmony ([\d.]+).*$/,"$1"),WebOS:()=>i.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")};s.osVersion="",d[s.os]&&(s.osVersion=d[s.os](),s.osVersion===i&&(s.osVersion=""));const h={Safari:()=>i.replace(/^.*Version\/([\d.]+).*$/,"$1"),Chrome:()=>i.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1"),IE:()=>i.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1"),Edge:()=>i.replace(/^.*(Edge|Edg|Edg[A-Z]{1})\/([\d.]+).*$/,"$2"),Firefox:()=>i.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1"),"Firefox Focus":()=>i.replace(/^.*Focus\/([\d.]+).*$/,"$1"),Servo:()=>i.replace(/^.*Servo\/?([\d.]+).*$/,"$1"),Chromium:()=>i.replace(/^.*Chromium\/([\d.]+).*$/,"$1"),Opera:()=>i.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1"),Vivaldi:()=>i.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1"),Yandex:()=>i.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1"),Kindle:()=>i.replace(/^.*Version\/([\d.]+).*$/,"$1"),Maxthon:()=>i.replace(/^.*Maxthon\/([\d.]+).*$/,"$1"),QQBrowser:()=>i.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1"),QQ:()=>i.replace(/^.*QQ\/([\d.]+).*$/,"$1"),Baidu:()=>i.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1"),UC:()=>i.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1"),Sogou:()=>i.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1"),"2345Explorer":()=>i.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1"),TheWorld:()=>i.replace(/^.*TheWorld ([\d.]+).*$/,"$1"),MIUI:()=>i.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1"),HuaweiBrowser:()=>i.replace(/^.*HuaweiBrowser\/([\d.]+).*$/,"$1"),Quark:()=>i.replace(/^.*Quark\/([\d.]+).*$/,"$1"),Qiyu:()=>i.replace(/^.*Qiyu\/([\d.]+).*$/,"$1"),"360Browser":()=>i.replace(/^.*360Browser\/([\d.]+).*$/,"$1"),Wechat:()=>i.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1"),Taobao:()=>i.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1"),Alipay:()=>i.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1"),Weibo:()=>i.replace(/^.*weibo__([\d.]+).*$/,"$1"),Douban:()=>i.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1"),Suning:()=>i.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1"),iQiYi:()=>i.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")};return s.version="",h[s.browser]&&(s.version=h[s.browser](),s.version===i&&(s.version="")),s.version.indexOf(".")&&(s.version=s.version.substring(0,s.version.indexOf("."))),"iOS"===s.os&&i.includes("iPad")?s.os="iPadOS":"Edge"!==s.browser||i.includes("Edg")?"MIUI"===s.browser?s.os="Android":"Chrome"===s.browser&&Number(s.version)>27||"Opera"===s.browser&&Number(s.version)>12||"Yandex"===s.browser?s.engine="Blink":void 0===s.browser&&(s.browser="Unknow App"):s.engine="EdgeHTML",s}(this.data.ua);return{browser:`${e.browser} ${e.version}`,os:`${e.os} ${e.osVersion}`}}getOpts(){return this.opts}}class Jt{constructor(e){h(this,"opts"),h(this,"$el"),h(this,"$loading"),h(this,"$text"),h(this,"offset",0),h(this,"total",0),h(this,"origText","Load More"),this.opts=e,this.origText=this.opts.text||this.origText,this.$el=p(`<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 Xt{constructor(){h(this,"instance"),h(this,"onReachedBottom",null),h(this,"opt")}create(e){return this.opt=e,this.instance=new Jt({pageSize:e.pageSize,onClick:t=>u(this,null,(function*(){e.getData().fetchComments({offset:t})})),text:A("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 Zt{constructor(e,t){h(this,"opts"),h(this,"total"),h(this,"$el"),h(this,"$input"),h(this,"inputTimer"),h(this,"$prevBtn"),h(this,"$nextBtn"),h(this,"page",1),this.total=e,this.opts=t,this.$el=p('<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?Fe(this.$el):We(this.$el)}}class en{constructor(){h(this,"instance")}create(e){return this.instance=new Zt(e.total,{pageSize:e.pageSize,onChange:t=>u(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 tn(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 nn=e=>{let t=null;e.getConf().watchConf(["pagination","locale"],(n=>{const i=e.getList(),s=e.getData();t&&t.dispose(),t=function(e){return e.pagination.readMore?new Xt:new en}(n);const{offset:o,total:a}=tn(s.getListLastFetch()),r=t.create(c({pageSize:n.pagination.pageSize,total:a,readMoreAutoLoad:n.pagination.autoLoad},e));i.getCommentsWrapEl().after(r),null==t||t.update(o,a)})),e.getEvents().on("list-loaded",(n=>{const{offset:i,total:s}=tn(e.getData().getListLastFetch());null==t||t.update(i,s)})),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,A("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 sn{constructor(e){h(this,"opts"),h(this,"$el"),h(this,"$commentsWrap"),h(this,"commentNodes",[]),this.opts=e,this.$el=p('<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"),nn(c({getList:()=>this},e)),this.initCrudEvents()}getEl(){return this.$el}getCommentsWrapEl(){return this.$commentsWrap}getCommentNodes(){return this.commentNodes}getLayout({forceFlatMode:e}={}){return new Mt({$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 i=function(e,t,n){const i=e.getConf().get(),s=new Yt(t,{onAfterRender:()=>{e.getEvents().trigger("comment-rendered",s)},onDelete:t=>{e.getData().deleteComment(t.getID())},replyTo:n,flatMode:"boolean"==typeof(null==e?void 0:e.forceFlatMode)?null==e?void 0:e.forceFlatMode:i.flatMode,gravatar:i.gravatar,nestMax:i.nestMax,heightLimit:i.heightLimit,avatarURLBuilder:i.avatarURLBuilder,scrollRelativeTo:i.scrollRelativeTo,vote:i.vote,voteDown:i.voteDown,uaBadge:i.uaBadge,dateFormatter:i.dateFormatter,getApi:e.getApi,replyComment:e.replyComment,editComment:e.editComment});return s.render(),s}(c({forceFlatMode:e},this.opts),t,n);return this.commentNodes.push(i),i},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 on{constructor(e){h(this,"opts"),h(this,"$el"),h(this,"layer"),h(this,"$header"),h(this,"$closeBtn"),h(this,"$iframeWrap"),h(this,"$iframe"),h(this,"refreshWhenShow",!0),h(this,"animTimer"),this.opts=e,this.$el=p('<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 u(this,null,(function*(){this.refreshWhenShow=!0}))}show(){return u(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 u(this,null,(function*(){const t=(yield this.opts.getApi().user.getUserStatus(c({},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=p('<iframe referrerpolicy="strict-origin-when-cross-origin"></iframe>'),n=w({base:this.opts.getConf().get().server,path:"/sidebar/"}),i={pageKey:this.opts.getConf().get().pageKey,site:this.opts.getConf().get().site||"",user:JSON.stringify(this.opts.getUser().getData()),time:+new Date};e&&(i.view=e),i.darkMode=this.getDarkMode()?"1":"0";const s=new URLSearchParams(i);return this.iframeLoad(t,`${n}?${s.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,Fe(this.$iframeWrap),e.onload=()=>{We(this.$iframeWrap)}}}const an=[...new Set([e=>{e.provide("data",(e=>new wt(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 De(Le(t.get(),e,n))),["user","config","apiHandlers"],{lifecycle:"transient"})},e=>{e.watchConf(["locale"],(e=>{var t;(t=e.locale)!==T&&(T=t,L="string"==typeof t?x(t):t)}))},e=>{e.provide("user",(()=>new ht({onUserChanged:t=>{e.trigger("user-changed",t)}})),[])},e=>{e.provide("editor",((t,n)=>{const i=new $t({getEvents:()=>t,getConf:()=>n});return e.getEl().appendChild(i.getEl()),i}),["events","config"])},e=>{e.provide("list",((t,n,i,s,o)=>{const a=new sn({getApi:()=>t,getEvents:()=>n,getConf:()=>i,getData:()=>s,replyComment:(e,t)=>o.setReplyComment(e,t),editComment:(e,t)=>o.setEditComment(e,t),resetEditorState:()=>o.resetState(),onListGotoFirst:()=>e.listGotoFirst()});return e.getEl().appendChild(a.getEl()),a}),["api","events","config","data","editor"])},e=>{e.provide("checkers",((t,n,i,s,o)=>{const a=new vt({getApi:()=>t,getLayers:()=>i,getUser:()=>s,onReload:()=>e.reload(),getCaptchaIframeURL:()=>`${o.get().server}/api/v2/captcha/?t=${+new Date}`});return n.add("need_captcha",(e=>a.checkCaptcha(e))),n.add("need_login",(()=>a.checkAdmin({}))),a}),["api","apiHandlers","layers","user","config"])},e=>{e.provide("layers",(()=>{const t=new Tt;return document.body.appendChild(t.getEl()),e.on("unmounted",(()=>{null==t||t.destroy()})),t}))},e=>{e.provide("sidebar",((t,n,i,s,o,a,r,l)=>{const c=new on({onShow:()=>{setTimeout((()=>{n.updateNotifies([])}),0),t.trigger("sidebar-show")},onHide:()=>{i.resetState(),t.trigger("sidebar-hide")},getCheckers:()=>s,getApi:()=>o,getConf:()=>a,getUser:()=>r,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(!t.Marked.name)return}catch(i){return}const n=new t.Marked;n.setOptions(c(c({renderer:ge({imgLazyLoad:e.imgLazyLoad})},we),e.markedOptions)),ke=n}({markedOptions:e.markedOptions,imgLazyLoad:e.imgLazyLoad})})),e.watchConf(["markedReplacers"],(e=>{var t;e.markedReplacers&&(t=e.markedReplacers,$e=t)}))},e=>{e.provide("editorPlugs",((t,n,i,s,o,a)=>{const r=new et({getArtalkRootEl:()=>e.getEl(),getEditor:()=>t,getConf:()=>n,getUser:()=>i,getApi:()=>a,getData:()=>s,getCheckers:()=>o,onSubmitted:()=>e.trigger("editor-submitted")});return t.setPlugins(r),r}),["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()}))},...it,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=>{Ae({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&&!st&&function(e,t,n){const i=function(e,t){const n=e.split("."),i=t.split(".");for(let s=0;s<3;s++){const e=Number(n[s]),t=Number(i[s]);if(e>t)return 1;if(t>e)return-1;if(!Number.isNaN(e)&&Number.isNaN(t))return 1;if(Number.isNaN(e)&&!Number.isNaN(t))return-1}return 0}(t,n);if(0===i)return;const s=p(`<div class="atk-version-check-notice">${A("updateMsg",{name:A(i<0?"client":"server")})} <span class="atk-info">${A("currentVersion")}: ${A("client")} ${t} / ${A("server")} ${n}</span></div>`),o=p(`<span class="atk-ignore-btn">${A("ignore")}</span>`);o.onclick=()=>{s.remove(),st=!0},s.append(o),e.getEl().parentElement.prepend(s)}(t,tt,e.apiVersion)}))},e=>{const t=e.inject("config"),n=e.inject("layers");let i;const s=t=>{const s=[e.getEl(),n.getEl()];ot||(ot=window.matchMedia("(prefers-color-scheme: dark)")),"auto"===t?(i||(i=e=>at(s,e.matches),ot.addEventListener("change",i)),at(s,ot.matches)):(i&&(ot.removeEventListener("change",i),i=void 0),at(s,t))};e.watchConf(["darkMode"],(e=>s(e.darkMode))),e.on("created",(()=>s(t.get().darkMode))),e.on("unmounted",(()=>{i&&(null==ot||ot.removeEventListener("change",i)),i=void 0}))},e=>{const t=e.inject("config");let n,i={};e.watchConf(["pageVote"],(e=>{const t=c(c({},rt),"object"==typeof e.pageVote?e.pageVote:{});null==n||n(),e.pageVote&&(i=function(e,t,n,i){var s,o;const a=c({},e);return a.upBtnEl=document.querySelector(t.upBtnEl),a.downBtnEl=document.querySelector(t.downBtnEl),a.upCountEl=document.querySelector(t.upCountEl),a.downCountEl=document.querySelector(t.downCountEl),a.activeClass=t.activeClass,a.voteUpHandler=n,a.voteDownHandler=i,null==(s=a.upBtnEl)||s.addEventListener("click",n),null==(o=a.downBtnEl)||o.addEventListener("click",i),a}(i,t,r,l),n=()=>i=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)),{}}(i))})),e.on("unmounted",(()=>{null==n||n(),e.off("list-fetched",o)})),e.on("list-fetched",o);let s=0;function o({data:n}){t.get().pageVote&&function(e){return e.upBtnEl||e.downBtnEl||e.upCountEl||e.downCountEl}(i)&&n&&(s!==n.page.id?(s=n.page.id,lt(i,n.page.vote_up,n.page.vote_down,!1,!1),function(e,t,n){n.votes.getVote("page",t).then((({data:t})=>{lt(e,t.up,t.down,t.is_up,t.is_down)})).catch((e=>{console.error("[ArtalkPageVote]",e)}))}(i,s,e.getApi())):lt(i,n.page.vote_up,n.page.vote_down))}const a=()=>{var t;return{state:i,pageId:(null==(t=e.getData().getPage())?void 0:t.id)||0,httpApi:e.getApi()}},r=ct("up",a),l=ct("down",a)}],rn=new Set([...an]),ln=new WeakMap;function cn(e,t){return u(this,null,(function*(){var n;const i=new Set,s=e=>{e.forEach((e=>{"function"==typeof e&&(i.has(e)||(e(t,ln.get(e)),i.add(e)))}))};s(rn);const{data:o}=yield t.getApi().conf.conf().catch((n=>{throw((e,t={})=>{var n;const i=e.inject("list"),s=e.inject("user"),o=e.inject("config"),a=t.err;if(!a)throw new Error("MountError: `err` is required");let r="";if(null==(n=a.data)?void 0:n.err_no_site){const e={create_name:o.get().site,create_urls:`${window.location.protocol}//${window.location.host}`};r=`sites|${JSON.stringify(e)}`}nt({$err:i.getEl(),errMsg:a.msg||String(a),errData:a.data,retryFn:()=>{var e;return null==(e=t.onRetry)?void 0:e.call(t)},onOpenSidebar:s.getData().is_admin?()=>e.showSidebar({view:r}):void 0})})(t,{err:n,onRetry:()=>cn(e,t)}),n}));let a=d(c({},e),{apiVersion:null==(n=o.version)?void 0:n.version});const r=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}(o.frontend_conf||{});a=a.preferRemoteConf?Se(a,r):Se(r,a),t.updateConf(a),a.pluginURLs&&(yield function(e,t){return u(this,null,(function*(){const n=new Set;if(!e||!Array.isArray(e))return n;const i=[];return e.forEach((e=>{/^(http|https):\/\//.test(e)||(e=`${t.replace(/\/$/,"")}/${e.replace(/^\//,"")}`),i.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(i),Object.values(window.ArtalkPlugins||{}).forEach((e=>{"function"==typeof e&&n.add(e)})),n}))}(a.pluginURLs,t.getConf().server).then((e=>{s(e)})).catch((e=>{console.error("Failed to load plugin",e)})))}))}function dn({keys:e,effect:t,getConf:n,getEvents:i}){let s=null;const o=()=>{const i=(()=>{const t=n(),i={};return e.forEach((e=>{i[e]=t[e]})),i})();var o,a;(null==s||(o=s,a=i,!(JSON.stringify(o)===JSON.stringify(a))))&&(s=i,t(i))};i().on("mounted",o),i().on("updated",o)}class hn{constructor(e){h(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 Ce(t);(e=>{e.provide("events",(()=>new Ze))})(n),(e=>{let t=Te({},!0);e.provide("config",(e=>{let n=!1;return e.on("mounted",(()=>n=!0)),{watchConf:(n,i)=>{dn({keys:n,effect:i,getConf:()=>t,getEvents:()=>e})},get:()=>t,update:i=>{t=Se(t,Te(i,!1)),n&&e.trigger("updated",t)}}}),["events"])})(n),n.updateConf(e),n.trigger("created");(()=>{u(this,null,(function*(){yield cn(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 hn(e)}static use(e,t){rn.add(e),ln.set(e,t)}static loadCountWidget(e){const t=Te(e,!0);Ae({getApi:()=>new De(Le(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 un=hn.init,pn=hn.use,mn=hn.loadCountWidget;e.Defaults=xe,e.default=hn,e.init=un,e.loadCountWidget=mn,e.use=pn,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
10
|
+
*/let Ue=class extends Pe{constructor(){super(...arguments),h(this,"auth",{loginByEmail:(e,t={})=>this.request(c({path:"/auth/email/login",method:"POST",body:e,type:"application/json",format:"json"},t)),registerByEmail:(e,t={})=>this.request(c({path:"/auth/email/register",method:"POST",body:e,type:"application/json",format:"json"},t)),sendVerifyEmail:(e,t={})=>this.request(c({path:"/auth/email/send",method:"POST",body:e,type:"application/json",format:"json"},t)),checkDataMerge:(e={})=>this.request(c({path:"/auth/merge",method:"GET",secure:!0,format:"json"},e)),applyDataMerge:(e,t={})=>this.request(c({path:"/auth/merge",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t))}),h(this,"cache",{flushCache:(e={})=>this.request(c({path:"/cache/flush",method:"POST",secure:!0,format:"json"},e)),warmUpCache:(e={})=>this.request(c({path:"/cache/warm_up",method:"POST",secure:!0,format:"json"},e))}),h(this,"captcha",{getCaptcha:(e={})=>this.request(c({path:"/captcha",method:"GET",format:"json"},e)),getCaptchaStatus:(e={})=>this.request(c({path:"/captcha/status",method:"GET",format:"json"},e)),verifyCaptcha:(e,t={})=>this.request(c({path:"/captcha/verify",method:"POST",body:e,type:"application/json",format:"json"},t))}),h(this,"comments",{getComments:(e,t={})=>this.request(c({path:"/comments",method:"GET",query:e,secure:!0,type:"application/json",format:"json"},t)),createComment:(e,t={})=>this.request(c({path:"/comments",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),getComment:(e,t={})=>this.request(c({path:`/comments/${e}`,method:"GET",type:"application/json",format:"json"},t)),updateComment:(e,t,n={})=>this.request(c({path:`/comments/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deleteComment:(e,t={})=>this.request(c({path:`/comments/${e}`,method:"DELETE",secure:!0,format:"json"},t))}),h(this,"conf",{conf:(e={})=>this.request(c({path:"/conf",method:"GET",format:"json"},e)),getSocialLoginProviders:(e={})=>this.request(c({path:"/conf/auth/providers",method:"GET",format:"json"},e)),getDomain:(e,t={})=>this.request(c({path:"/conf/domain",method:"GET",query:e,format:"json"},t))}),h(this,"notifies",{getNotifies:(e,t={})=>this.request(c({path:"/notifies",method:"GET",query:e,type:"application/json",format:"json"},t)),markAllNotifyRead:(e,t={})=>this.request(c({path:"/notifies/read",method:"POST",body:e,type:"application/json",format:"json"},t)),markNotifyRead:(e,t,n={})=>this.request(c({path:`/notifies/${e}/${t}`,method:"POST",format:"json"},n))}),h(this,"pages",{getPages:(e,t={})=>this.request(c({path:"/pages",method:"GET",query:e,secure:!0,type:"application/json",format:"json"},t)),fetchAllPages:(e,t={})=>this.request(c({path:"/pages/fetch",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),getPageFetchStatus:(e={})=>this.request(c({path:"/pages/fetch/status",method:"GET",secure:!0,format:"json"},e)),logPv:(e,t={})=>this.request(c({path:"/pages/pv",method:"POST",body:e,type:"application/json",format:"json"},t)),updatePage:(e,t,n={})=>this.request(c({path:`/pages/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deletePage:(e,t={})=>this.request(c({path:`/pages/${e}`,method:"DELETE",secure:!0,format:"json"},t)),fetchPage:(e,t={})=>this.request(c({path:`/pages/${e}/fetch`,method:"POST",secure:!0,type:"application/json",format:"json"},t))}),h(this,"sendEmail",{sendEmail:(e,t={})=>this.request(c({path:"/send_email",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t))}),h(this,"settings",{getSettings:(e={})=>this.request(c({path:"/settings",method:"GET",secure:!0,format:"json"},e)),applySettings:(e,t={})=>this.request(c({path:"/settings",method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},t)),getSettingsTemplate:(e,t={})=>this.request(c({path:`/settings/template/${e}`,method:"GET",secure:!0,format:"json"},t))}),h(this,"sites",{getSites:(e={})=>this.request(c({path:"/sites",method:"GET",secure:!0,format:"json"},e)),createSite:(e,t={})=>this.request(c({path:"/sites",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),updateSite:(e,t,n={})=>this.request(c({path:`/sites/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deleteSite:(e,t={})=>this.request(c({path:`/sites/${e}`,method:"DELETE",secure:!0,format:"json"},t))}),h(this,"stats",{getStats:(e,t,n={})=>this.request(c({path:`/stats/${e}`,method:"GET",query:t,type:"application/json",format:"json"},n))}),h(this,"transfer",{exportArtrans:(e={})=>this.request(c({path:"/transfer/export",method:"GET",secure:!0,format:"json"},e)),importArtrans:(e,t={})=>this.request(c({path:"/transfer/import",method:"POST",body:e,secure:!0,type:"application/json"},t)),uploadArtrans:(e,t={})=>this.request(c({path:"/transfer/upload",method:"POST",body:e,secure:!0,type:"multipart/form-data",format:"json"},t))}),h(this,"upload",{upload:(e,t={})=>this.request(c({path:"/upload",method:"POST",body:e,secure:!0,type:"multipart/form-data",format:"json"},t))}),h(this,"user",{getUser:(e,t={})=>this.request(c({path:"/user",method:"GET",query:e,secure:!0,format:"json"},t)),updateProfile:(e,t={})=>this.request(c({path:"/user",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),login:(e,t={})=>this.request(c({path:"/user/access_token",method:"POST",body:e,type:"application/json",format:"json"},t)),getUserStatus:(e,t={})=>this.request(c({path:"/user/status",method:"GET",query:e,secure:!0,format:"json"},t))}),h(this,"users",{createUser:(e,t={})=>this.request(c({path:"/users",method:"POST",body:e,secure:!0,type:"application/json",format:"json"},t)),updateUser:(e,t,n={})=>this.request(c({path:`/users/${e}`,method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},n)),deleteUser:(e,t={})=>this.request(c({path:`/users/${e}`,method:"DELETE",secure:!0,format:"json"},t)),getUsers:(e,t,n={})=>this.request(c({path:`/users/${e}`,method:"GET",query:t,secure:!0,type:"application/json",format:"json"},n))}),h(this,"version",{getVersion:(e={})=>this.request(c({path:"/version",method:"GET",format:"json"},e))}),h(this,"votes",{syncVotes:(e={})=>this.request(c({path:"/votes/sync",method:"POST",secure:!0,format:"json"},e)),getVote:(e,t,n={})=>this.request(c({path:`/votes/${e}/${t}`,method:"GET",type:"application/json",format:"json"},n)),createVote:(e,t,n,i,s={})=>this.request(c({path:`/votes/${e}/${t}/${n}`,method:"POST",body:i,type:"application/json",format:"json"},s))})}};const je=(e,t,n)=>u(this,null,(function*(){const i=e.getApiToken&&e.getApiToken(),s=new Headers(c({Authorization:i?`Bearer ${i}`:""},null==n?void 0:n.headers));s.get("Authorization")||s.delete("Authorization");const o=yield fetch(t,d(c({},n),{headers:s}));if(!o.ok){const i=(yield o.json().catch((()=>{})))||{};let s=!1;if(e.handlers&&(yield e.handlers.get().reduce(((e,t)=>u(this,null,(function*(){yield e,!0===i[t.action]&&(yield t.handler(i),s=!0)}))),Promise.resolve())),s)return je(e,t,n);throw function(e,t){const n=new Oe;return n.message=t.msg||t.message||"fetch error",n.code=e,n.data=t,console.error(n),n}(o.status,i)}return o}));class Oe extends Error{constructor(){super(...arguments),h(this,"code",0),h(this,"message","fetch error"),h(this,"data")}}class De extends Ue{constructor(e){super({baseUrl:e.baseURL,customFetch:(t,n)=>je(e,t,n)}),h(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 Be{constructor(e){h(this,"$btn"),h(this,"$panel"),h(this,"editorStateEffectWhen"),this.kit=e}useBtn(e="<div></div>"){return this.$btn=p(`<span class="atk-plug-btn">${e}</span>`),this.$btn}usePanel(e="<div></div>"){return this.$panel=p(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 Ie="ArtalkContent";class qe{constructor(e){this.kit=e}reqAdd(){return u(this,null,(function*(){return(yield this.kit.useApi().comments.createComment(c({},yield this.getSubmitAddParams()))).data}))}getSubmitAddParams(){return u(this,null,(function*(){const{name:e,email:t,link:n}=this.kit.useUser().getData(),i=this.kit.useConf();return{content:this.kit.useEditor().getContentFinal(),name:e,email:t,link:n,rid:0,page_key:i.pageKey,page_title:i.pageTitle,site_name:i.site,ua:yield k()}}))}postSubmitAdd(e){this.kit.useData().insertComment(e)}}class Re extends Be{constructor(e){super(e),h(this,"customs",[]),h(this,"defaultPreset"),this.defaultPreset=new qe(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 u(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(`${A("commentFail")}: ${t.message||String(t)}`,"e")}finally{this.kit.useEditor().hideLoading()}this.kit.useEditor().reset(),this.kit.useEvents().trigger("editor-submitted")}))}}class _e extends Be{constructor(){super(...arguments),h(this,"isMoved",!1)}move(e){if(this.isMoved)return;this.isMoved=!0;const t=this.kit.useUI().$el;t.after(p('<div class="atk-editor-travel-placeholder"></div>'));const n=p("<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 Fe(e,t){let n=e.querySelector(":scope > .atk-loading");n||(n=p('<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 i=n.querySelector(".atk-loading-spinner");i&&(i.style.display="none",window.setTimeout((()=>{i.isConnected&&(i.style.display="")}),500))}function We(e){const t=e.querySelector(":scope > .atk-loading");t&&(t.style.display="none")}function Ne(e,t){e?Fe(t):We(t)}function He(e,t=!0,n){let i;if(n){const t=n.getBoundingClientRect();i=e.getBoundingClientRect().top-t.top+n.scrollTop-n.clientHeight/2+e.clientHeight/2}else{const t=e.getBoundingClientRect();i=t.top+window.scrollY-(window.innerHeight/2-t.height/2)}const s={top:i,left:0,behavior:"instant"};n?n.scroll(s):window.scroll(s)}function ze(e,t){!function(e,t,n="in"){e.classList.add(`atk-fade-${n}`);const i=()=>{e.classList.remove(`atk-fade-${n}`),e.removeEventListener("animationend",i)};e.addEventListener("animationend",i)}(e,0,"in")}function Ve(e,t,n='<span class="atk-error-title">Artalk Error</span>'){let i=e.querySelector(".atk-error-layer");if(null===t)return void(null!==i&&i.remove());i||(i=p(`<div class="atk-error-layer">${n}<span class="atk-error-text"></span></div>`),e.appendChild(i));const s=i.querySelector(".atk-error-text");s.innerHTML="",null!==t&&(t instanceof HTMLElement?s.appendChild(t):s.innerText=t)}class Ke extends Be{constructor(e){super(e),h(this,"emoticons",[]),h(this,"loadingTask",null),h(this,"$grpWrap"),h(this,"$grpSwitcher"),h(this,"isListLoaded",!1),h(this,"isImgLoaded",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-emoticons"></div>'),this.useBtn(`<i aria-label="${A("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((()=>{(()=>{u(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 u(this,null,(function*(){this.isListLoaded||(null===this.loadingTask?(this.loadingTask=(()=>u(this,null,(function*(){Fe(this.$panel),this.emoticons=yield this.handleData(this.kit.useConf().emoticons),We(this.$panel),this.loadingTask=null,this.isListLoaded=!0})))(),yield this.loadingTask):yield this.loadingTask)}))}handleData(e){return u(this,null,(function*(){if(!Array.isArray(e)&&["object","string"].includes(typeof e)&&(e=[e]),!Array.isArray(e))return Ve(this.$panel,`[${A("emoticon")}] Data must be of Array/Object/String type`),We(this.$panel),[];const t=t=>{"object"==typeof t&&(t.name&&e.find((e=>e.name===t.name))||e.push(t))},n=e=>u(this,null,(function*(){yield Promise.all(e.map(((e,i)=>u(this,null,(function*(){if("object"!=typeof e||Array.isArray(e)){if(Array.isArray(e))yield n(e);else if("string"==typeof e){const i=yield this.remoteLoad(e);Array.isArray(i)?yield n(i):"object"==typeof i&&t(i)}}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 u(this,null,(function*(){if(!e)return[];try{const t=yield fetch(e);return yield t.json()}catch(t){return We(this.$panel),console.error("[Emoticons] Load Failed:",t),Ve(this.$panel,`[${A("emoticon")}] ${A("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 i={name:e,type:n.type,items:[]};n.container.forEach(((t,n)=>{const s=t.icon;if(/<(img|IMG)/.test(s)){const e=/src=["'](.*?)["']/.exec(s);e&&e.length>1&&(t.icon=e[1])}i.items.push({key:t.text||`${e} ${n+1}`,val:t.icon})})),t.push(i)})),t}initEmoticonsList(){this.$grpWrap=p('<div class="atk-grp-wrap"></div>'),this.$panel.append(this.$grpWrap),this.emoticons.forEach(((e,t)=>{const n=p('<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 i=p('<span class="atk-item"></span>');if(n.append(i),t.key&&!new RegExp(`^(${e.name})?\\s?[0-9]+$`).test(t.key)&&i.setAttribute("title",t.key),"image"===e.type){const e=document.createElement("img");e.src=t.val,e.alt=t.key,i.append(e)}else i.innerText=t.val;i.onclick=()=>{"image"===e.type?this.kit.useEditor().insertContent(`:[${t.key}]`):this.kit.useEditor().insertContent(t.val||"")}}))})),this.emoticons.length>1&&(this.$grpSwitcher=p('<div class="atk-grp-switcher"></div>'),this.$panel.append(this.$grpSwitcher),this.emoticons.forEach(((e,t)=>{const n=p("<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,i;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==(i=null==(n=this.$grpSwitcher)?void 0:n.querySelector(`span[data-index="${e}"]`))||i.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 Ge=["png","jpg","jpeg","gif","bmp","svg","webp"];class Qe extends Be{constructor(e){super(e),h(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=Ge.map((e=>`.${e}`)).join(",");const e=this.useBtn(`<i aria-label="${A("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=()=>{(()=>{u(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 i=null==(n=t.dataTransfer)?void 0:n.files;(null==i?void 0:i.length)&&(t.preventDefault(),e(i))},i=t=>{var n;const i=null==(n=t.clipboardData)?void 0:n.files;(null==i?void 0:i.length)&&(t.preventDefault(),e(i))};this.kit.useMounted((()=>{this.kit.useUI().$textarea.addEventListener("dragover",t),this.kit.useUI().$textarea.addEventListener("drop",n),this.kit.useUI().$textarea.addEventListener("paste",i)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("dragover",t),this.kit.useUI().$textarea.removeEventListener("drop",n),this.kit.useUI().$textarea.removeEventListener("paste",i)}))}uploadImg(e){return u(this,null,(function*(){const t=/[^.]+$/.exec(e.name);if(!t||!Ge.includes(String(t[0]).toLowerCase()))return;if(!this.kit.useUser().checkHasBasicUserInfo())return void this.kit.useEditor().showNotify(A("uploadLoginMsg"),"w");let n="\n";""===this.kit.useUI().$textarea.value.trim()&&(n="");const i=`${n}`;let s;this.kit.useEditor().insertContent(i);try{const t=this.kit.useConf().imgUploader;s=t?{public_url:yield t(e)}:(yield this.kit.useApi().upload.upload({file:e})).data}catch(o){console.error(o),this.kit.useEditor().showNotify(`${A("uploadFail")}: ${o.message}`,"e")}if(s&&s.public_url){let e=s.public_url;$(e)||(e=w({base:this.kit.useConf().server,path:e})),this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(i,`${n}`))}else this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(i,""))}))}}class Ye extends Be{constructor(e){super(e),h(this,"isPlugPanelShow",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-preview"></div>'),this.useBtn(`<i aria-label="${A("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 Je=[class extends Be{constructor(e){super(e);const t=()=>{this.save()};this.kit.useMounted((()=>{const e=window.localStorage.getItem(Ie)||"";""!==e.trim()&&(this.kit.useEditor().showNotify(A("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(Ie,this.kit.useEditor().getContentRaw().trim())}},class extends Be{get $inputs(){return this.kit.useEditor().getHeaderInputEls()}constructor(e){super(e);const t={},n={},i=(e,t,n)=>()=>{this.kit.useEvents().trigger(e,{field:n,$input:t})};this.kit.useMounted((()=>{Object.entries(this.$inputs).forEach((([e,s])=>{s.addEventListener("input",t[e]=i("header-input",s,e)),s.addEventListener("change",n[e]=i("header-change",s,e))}))})),this.kit.useUnmounted((()=>{Object.entries(this.$inputs).forEach((([e,i])=>{i.removeEventListener("input",t[e]),i.removeEventListener("change",n[e])}))}))}},class extends Be{constructor(e){super(e),h(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:A("nick"),email:A("email"),link:A("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(c({},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 Be{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 Be{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||A("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`}},Re,class extends Be{constructor(e){super(e);const t=()=>{this.kit.useEditor().submit()};this.kit.useMounted((()=>{this.kit.useUI().$submitBtn.innerText=this.kit.useConf().sendBtn||A("send"),this.kit.useUI().$submitBtn.addEventListener("click",t)})),this.kit.useUnmounted((()=>{this.kit.useUI().$submitBtn.removeEventListener("click",t)}))}},_e,class extends Be{constructor(e){super(e),h(this,"comment"),this.useEditorStateEffect("reply",(e=>(this.setReply(e),()=>{this.cancelReply()}))),this.kit.useEvents().on("mounted",(()=>{const e=this.kit.useDeps(Re);if(!e)throw Error("SubmitPlug not initialized");const t=new qe(this.kit);e.registerCustom({activeCond:()=>!!this.comment,req:()=>u(this,null,(function*(){if(!this.comment)throw new Error("reply comment cannot be empty");return(yield this.kit.useApi().comments.createComment(d(c({},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=p(`<span class="atk-state-btn"><span class="atk-text-wrap">${A("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 Be{constructor(e){super(e),h(this,"comment"),h(this,"originalSubmitBtnText","Send"),this.useEditorStateEffect("edit",(e=>(this.edit(e),()=>{this.cancelEdit()}))),this.kit.useMounted((()=>{const e=this.kit.useDeps(Re);if(!e)throw Error("SubmitPlug not initialized");e.registerCustom({activeCond:()=>!!this.comment,req:()=>u(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,c(c({},t),e))).data})),post:e=>{this.kit.useData().updateComment(e)}})}))}edit(e){const t=this.kit.useUI();if(!t.$editCancelBtn){const e=p(`<span class="atk-state-btn"><span class="atk-text-wrap">${A("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(A("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:i}=this.kit.useUser().getData();e.$name.value=t,e.$email.value=n,e.$link.value=i,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 Be{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(p(`<div class="atk-comment-closed">${A("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")}},Ke,Qe,Ye];class Xe{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 Ze{constructor(){h(this,"events",[])}on(e,t,n={}){this.events.push(c({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 et{constructor(e){h(this,"plugins",[]),h(this,"openedPlug",null),h(this,"events",new Ze),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(Qe,e.imgUpload),t.set(Ke,e.emoticons),t.set(Ye,e.preview),t.set(_e,e.editorTravel),Je.filter((e=>!t.has(e)||!!t.get(e)))}(e).forEach((e=>{const t=new Xe(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 Ze,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 tt="2.9.3";function nt(e){const t=p('<span><span class="error-message"></span><br/><br/></span>');if(t.querySelector(".error-message").innerText=`${A("listLoadFailMsg")}\n${e.errMsg}`,e.retryFn){const n=p(`<span style="cursor:pointer;">${A("listRetry")}</span>`);n.onclick=()=>e.retryFn&&e.retryFn(),t.appendChild(n)}if(e.onOpenSidebar){const n=p(`<span atk-only-admin-show> | <span style="cursor:pointer;">${A("openName",{name:A("ctrlCenter")})}</span></span>`);t.appendChild(n),n.onclick=()=>e.onOpenSidebar&&e.onOpenSidebar()}Ve(e.$err,t)}const it=[e=>{const t=e.inject("config");e.on("list-fetch",(n=>{if(e.getData().getLoading())return;e.getData().setLoading(!0);const i=c({offset:0,limit:t.get().pagination.pageSize,flatMode:t.get().flatMode,paramsModifier:t.get().listFetchParamsModifier},n);e.getData().setListLastFetch({params:i});const s={limit:i.limit,offset:i.offset,flat_mode:i.flatMode,page_key:t.get().pageKey,site_name:t.get().site};i.paramsModifier&&i.paramsModifier(s),e.getApi().comments.getComments(c(c({},s),e.getApi().getUserFields())).then((({data:t})=>{e.getData().setListLastFetch({params:i,data:t}),e.getData().loadComments(t.comments),e.getData().updatePage(t.page),i.onSuccess&&i.onSuccess(t),e.trigger("list-fetched",{params:i,data:t})})).catch((t=>{const n={msg:t.msg||String(t),data:t.data};throw i.onError&&i.onError(n),e.trigger("list-failed",n),e.trigger("list-fetched",{params:i,error:n}),t})).finally((()=>{e.getData().setLoading(!1)}))}))},e=>{const t=e.inject("list");e.on("list-fetch",(e=>{0===e.offset&&Ne(!0,t.getEl())})),e.on("list-fetched",(()=>{Ne(!1,t.getEl())}))},e=>{const t=e.inject("config");e.on("comment-rendered",(n=>{if(t.get().listUnreadHighlight){const t=e.getData().getNotifies(),i=t.find((e=>e.comment_id===n.getID()));i?(n.getRender().setUnread(!0),n.getRender().setOpenAction((()=>{window.open(i.read_link),e.getData().updateNotifies(t.filter((e=>e.comment_id!==n.getID())))}))):n.getRender().setUnread(!1)}})),e.on("list-goto",(t=>{const n=g("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 i;e.on("mounted",(()=>{i=t.getEl().querySelector('[data-action="admin-close-comment"]'),i.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(`${A("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"),i&&(i.innerText=A("openComment"))):(null==n||n.getEvents().trigger("editor-open"),i&&(i.innerText=A("closeComment")))})),e.on("list-loaded",(t=>{e.editorResetState()}))},e=>{const t=e.inject("list");e.on("list-loaded",(()=>{(()=>{var n,i;const s=t.getEl().querySelector(".atk-comment-count .atk-text");if(!s)return;const o=m(A("counter",{count:`${Number(null==(i=null==(n=e.getData().getListLastFetch())?void 0:n.data)?void 0:i.count)||0}`}));s.innerHTML=o.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 i=()=>{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?A("ctrlCenter"):A("msgCenter"))}else n.classList.add("atk-hide")};e.watchConf(["locale"],(s=>{n=t.getEl().querySelector('[data-action="open-sidebar"]'),n&&(n.onclick=()=>{e.showSidebar()},i())})),e.on("user-changed",(e=>{i()}))},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"),i=t=>{n.update({listFetchParamsModifier:t}),e.reload()},s=e=>{!function(e){const{$dropdownWrap:t,dropdownList:n}=e;if(t.querySelector(".atk-dropdown"))return;t.classList.add("atk-dropdown-wrap"),t.append(p('<span class="atk-arrow-down-icon"></span>'));let i=0;const s=(e,t,n,s)=>{s(),i=e,o.querySelectorAll(".active").forEach((e=>{e.classList.remove("active")})),t.classList.add("active"),o.style.display="none",setTimeout((()=>{o.style.display=""}),80)},o=p('<ul class="atk-dropdown atk-fade-in"></ul>');n.forEach(((e,t)=>{const[n,a]=e,r=p('<li class="atk-dropdown-item"><span></span></li>'),l=r.querySelector("span");l.innerText=n,l.onclick=()=>{s(t,r,n,a)},o.append(r),t===i&&r.classList.add("active")})),t.append(o)}({$dropdownWrap:e,dropdownList:[[A("sortLatest"),()=>{i((e=>{e.sort_by="date_desc"}))}],[A("sortBest"),()=>{i((e=>{e.sort_by="vote"}))}],[A("sortOldest"),()=>{i((e=>{e.sort_by="date_asc"}))}],[A("sortAuthor"),()=>{i((e=>{e.view_only_admin=!0}))}]]})};e.watchConf(["listSort","locale"],(e=>{const n=t.getEl().querySelector(".atk-comment-count");n&&(e.listSort?s(n):function(e){var t,n;const{$dropdownWrap:i}=e;i.classList.remove("atk-dropdown-wrap"),null==(t=i.querySelector(".atk-arrow-down-icon"))||t.remove(),null==(n=i.querySelector(".atk-dropdown"))||n.remove()}({$dropdownWrap:n}))}))},e=>{let t=0;const n=({locker:n})=>{const i=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(g("atk_comment")));return t||null}();i&&(n&&t===i||(t=i,e.trigger("list-goto",i)))},i=()=>n({locker:!1}),s=()=>n({locker:!0});e.on("mounted",(()=>{window.addEventListener("hashchange",i),e.on("list-loaded",s)})),e.on("unmounted",(()=>{window.removeEventListener("hashchange",i),e.off("list-loaded",s)}))},e=>{const t=e.inject("list");e.on("list-goto",(n=>u(this,null,(function*(){let i=e.getCommentNodes().find((e=>e.getID()===n));if(!i){const s=(yield e.getApi().comments.getComment(n)).data;t.getLayout({forceFlatMode:!0}).insert(s.comment,s.reply_comment),i=e.getCommentNodes().find((e=>e.getID()===n))}i&&i.focus()}))))},e=>{const t=e.inject("list"),n=e.inject("config");e.on("list-loaded",(i=>{const s=i.length<=0;let o=t.getCommentsWrapEl().querySelector(".atk-list-no-comment");s?o||(o=p('<div class="atk-list-no-comment"></div>'),o.innerHTML=he(n.get().noComment||e.$t("noComment")),t.getCommentsWrapEl().appendChild(o)):null==o||o.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${tt}">Artalk</a>`)}))},e=>{const t=e.inject("list"),n=e.inject("config");let i=null;e.on("mounted",(()=>{i=window.setInterval((()=>{t.getEl().querySelectorAll("[data-atk-comment-date]").forEach((t=>{var i,s;const o=new Date(Number(t.getAttribute("data-atk-comment-date")));t.innerText=(null==(s=(i=n.get()).dateFormatter)?void 0:s.call(i,o))||y(o,e.$t)}))}),3e4)})),e.on("unmounted",(()=>{i&&window.clearInterval(i)}))},e=>{const t=e.inject("list");e.on("list-fetch",(()=>{Ve(t.getEl(),null)})),e.on("list-failed",(n=>{nt({$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 i=null;const s=()=>{null==i||i.disconnect(),i=null};e.on("list-loaded",(()=>{s();const o=t.getCommentsWrapEl().childNodes,a=o.length>2?o[o.length-2]:null;a&&("IntersectionObserver"in window?(t=>{var o,a;const r=(null==(a=(o=n.get()).scrollRelativeTo)?void 0:a.call(o))||null;i=new IntersectionObserver((([t])=>{t.isIntersecting&&(s(),e.trigger("list-reach-bottom"))}),{threshold:.9,root:r}),i.observe(t)})(a):console.warn("IntersectionObserver api not supported"))})),e.on("unmounted",(()=>{s()}))},e=>{const t=e.inject("list"),n=e.inject("config"),i=()=>{var e,i;const s=null==(i=(e=n.get()).scrollRelativeTo)?void 0:i.call(e);(s||window).scroll({top:f(t.getEl(),s).top,left:0})};e.on("mounted",(()=>{e.on("list-goto-first",i)})),e.on("unmounted",(()=>{e.off("list-goto-first",i)}))}];let st=!1;let ot;function at(e,t){const n="atk-dark-mode";e.forEach((e=>{t?e.classList.add(n):e.classList.remove(n)}))}const rt={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 lt(e,t,n,i,s){var o,a;e.upCountEl?e.upCountEl.innerText=String(t):e.upBtnEl&&(e.upBtnEl.innerText=`${A("voteUp")} (${t})`),e.downCountEl?e.downCountEl.innerText=String(n):e.downBtnEl&&(e.downBtnEl.innerText=`${A("voteDown")} (${n})`),"boolean"==typeof i&&(null==(o=e.upBtnEl)||o.classList.toggle(e.activeClass||"active",i)),"boolean"==typeof s&&(null==(a=e.downBtnEl)||a.classList.toggle(e.activeClass||"active",s))}const ct=(e,t)=>n=>{n.preventDefault();const{state:i,pageId:s,httpApi:o}=t();s&&o.votes.createVote("page",s,e,c({},o.getUserFields())).then((({data:e})=>{lt(i,e.up,e.down,e.is_up,e.is_down)})).catch((e=>{window.alert(A("voteFail")),console.error("[ArtalkPageVote]",e)}))};const dt="ArtalkUser";class ht{constructor(e){h(this,"data"),this.opts=e;const t=JSON.parse(window.localStorage.getItem(dt)||"{}");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(dt,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 ut(e){const t=p('<div class="atk-checker-iframe-wrap"></div>'),n=p('<iframe class="atk-fade-in" referrerpolicy="strict-origin-when-cross-origin"></iframe>');n.style.display="none",Fe(t,{transparentBg:!0}),n.src=e.getOpts().getCaptchaIframeURL(),n.onload=()=>{n.style.display="",We(t)},t.append(n);const i=p('<div class="atk-close-btn"><i class="atk-icon atk-icon-close"></i></div>');t.append(i),e.hideInteractInput();let s=!1;return function t(){return u(this,null,(function*(){var n;if(yield(n=1e3,new Promise((e=>{window.setTimeout((()=>{e(null)}),n)}))),s)return;let i=!1;try{i=(yield e.getApi().captcha.getCaptchaStatus()).data.is_pass}catch(o){i=!1}i?e.triggerSuccess():t()}))}(),i.onclick=()=>{s=!0,e.cancel()},t}const pt={request:(e,t)=>e.getApi().captcha.verifyCaptcha({value:t}),body:e=>e.get("iframe")?ut(e):function(e){const t=p(`<span><img class="atk-captcha-img" src="${e.get("img_data")||""}">${A("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,i){e.set("val",n)},onError(e,t,n,i){i.querySelector(".atk-captcha-img").click(),i.querySelector('input[type="text"]').value=""}},mt={inputType:"password",request(e,t){return u(this,null,(function*(){return(yield e.getApi().user.login({name:e.getUser().getData().name,email:e.getUser().getData().email,password:t})).data}))},body:e=>p(`<span>${A("adminCheck")}</span>`),onSuccess(e,t,n,i){e.getUser().update({is_admin:!0,token:t.token}),e.getOpts().onReload()},onError(e,t,n,i){}};class gt{constructor(e){h(this,"$el"),h(this,"$content"),h(this,"$actions"),this.$el=p('<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=p(`<button data-action="confirm">${A("confirm")}</button>`);return t.onclick=this.onBtnClick(e),this.$actions.appendChild(t),this}setNo(e){const t=p(`<button data-action="cancel">${A("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 ft(e){return t=>new Promise(((n,i)=>{const s=t.onCancel;t.onCancel=()=>{s&&s(),i(new Error("user canceled the checker"))};const o=t.onSuccess;t.onSuccess=()=>{o&&o(),n()},e(t)}))}class vt{constructor(e){h(this,"checkCaptcha",ft((e=>{this.check(pt,e,(t=>{t.set("img_data",e.img_data),t.set("iframe",e.iframe)}))}))),h(this,"checkAdmin",ft((e=>{this.check(mt,e)}))),this.opts=e}check(e,t,n){const i=this.opts.getLayers().create(`checker-${(new Date).getTime()}`);i.show();const s=()=>{i.destroy()},o={};let a=!1;const r={set:(e,t)=>{o[e]=t},get:e=>o[e],getOpts:()=>this.opts,getUser:()=>this.opts.getUser(),getApi:()=>this.opts.getApi(),hideInteractInput:()=>{a=!0},triggerSuccess:()=>{s(),e.onSuccess&&e.onSuccess(r,"","",l),t.onSuccess&&t.onSuccess()},cancel:()=>{s(),t.onCancel&&t.onCancel()}};n&&n(r);const l=p();l.appendChild(e.body(r));const c=p(`<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(),i.getEl().querySelector('button[data-action="confirm"]').click())};const h=new gt(l);h.setYes((n=>{const i=c.value.trim();d||(d=n.innerText);const o=()=>{n.innerText=d||"",n.classList.remove("error")};return n.innerText=`${A("loading")}...`,e.request(r,i).then((n=>{s(),e.onSuccess&&e.onSuccess(r,n,i,l),t.onSuccess&&t.onSuccess()})).catch((t=>{var s;s=String(t.message||String(t)),n.innerText=s,n.classList.add("error"),e.onError&&e.onError(r,t,i,l);const a=setTimeout((()=>o()),3e3);c.onfocus=()=>{o(),clearTimeout(a)}})),!1})),h.setNo((()=>(s(),t.onCancel&&t.onCancel(),!1))),a&&(c.style.display="none",h.$el.querySelector(".atk-layer-dialog-actions").style.display="none"),i.getEl().append(h.$el),t.onMount&&t.onMount(h.$el)}}const yt={$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 kt{constructor(e){h(this,"stateCurt","normal"),h(this,"stateUnmountFn",null),this.editor=e}get(){return this.stateCurt}switch(e,t){var n,i,s,o,a,r,l;if(this.stateUnmountFn&&(this.stateUnmountFn(),this.stateUnmountFn=null,null==(i=null==(n=this.editor.getPlugins())?void 0:n.get(_e))||i.back()),"normal"!==e&&t){let n=t.$comment;this.editor.getOptions().getConf().get().flatMode||(n=n.querySelector(".atk-footer")),null==(o=null==(s=this.editor.getPlugins())?void 0:s.get(_e))||o.move(n);const i=null==(r=(a=this.editor.getOptions().getConf().get()).scrollRelativeTo)?void 0:r.call(a);He(this.editor.getUI().$el,!0,i);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 $t{constructor(e){h(this,"opts"),h(this,"$el"),h(this,"ui"),h(this,"state"),h(this,"plugins"),this.opts=e,this.ui=function(){const e=p('<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(yt).forEach((([n,i])=>{t[n]=e.querySelector(i)})),t}(),this.$el=this.ui.$el,this.state=new kt(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 Ee(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,i=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=i}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 i=p(`<div class="atk-notify atk-fade-in" style="background-color: ${{s:"#57d59f",e:"#ff6f6c",w:"#ffc721",i:"#2ebcfc"}[n]}"><span class="atk-notify-content"></span></div>`);i.querySelector(".atk-notify-content").innerHTML=m(t).replace("\n","<br/>"),e.appendChild(i);const s=()=>{i.classList.add("atk-fade-out"),setTimeout((()=>{i.remove()}),200)};let o;o=window.setTimeout((()=>{s()}),3e3),i.addEventListener("click",(()=>{s(),window.clearTimeout(o)}))}(this.ui.$notifyWrap,e,t)}showLoading(){Fe(this.ui.$el)}hideLoading(){We(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 wt{constructor(e){h(this,"loading",!1),h(this,"listLastFetch"),h(this,"comments",[]),h(this,"notifies",[]),h(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 bt{constructor(e,t){h(this,"allowMaskClose",!0),h(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 Et,Ct;function St(){return{init(){Et=document.body.style.overflow,Ct=document.body.style.paddingRight},unlock(){document.body.style.overflow=Et,document.body.style.paddingRight=Ct},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 i=e.offsetWidth;return n===i&&(i=t.clientWidth),document.body.removeChild(t),n-i}()+e||0}px`}}}class xt{constructor(){h(this,"$wrap"),h(this,"$mask"),h(this,"items",[]),this.$wrap=p('<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 bt(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"),St().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",St().unlock())}}class Tt{constructor(){h(this,"wrap",new xt),St().init()}getEl(){return this.wrap.getWrap()}create(e,t){return this.wrap.createItem(e,t)}destroy(){this.wrap.getWrap().remove()}}const Lt=e=>({import:t=>{(function(e,t="DATE_DESC",n=2){const i=[];e.filter((e=>0===e.rid)).forEach((t=>{const s={id:t.id,comment:t,children:[],level:1};s.parent=s,i.push(s),function t(i){const s=e.filter((e=>e.rid===i.id));0!==s.length&&(i.level>=n&&(i=i.parent),s.forEach((e=>{const n={id:e.id,comment:e,children:[],parent:i,level:i.level+1};i.children.push(n),t(n)})))}(s)}));const s=(n,i)=>{let s=n.id-i.id;return"DATE_ASC"===t?s=+new Date(n.comment.date)-+new Date(i.comment.date):"DATE_DESC"===t?s=+new Date(i.comment.date)-+new Date(n.comment.date):"SRC_INDEX"===t?s=e.indexOf(n.comment)-e.indexOf(i.comment):"VOTE_UP_DESC"===t&&(s=i.comment.vote_up-n.comment.vote_up),s};return function e(t){t.forEach((t=>{t.children=t.children.sort(s),e(t.children)}))}(i),i})(t,e.nestSortBy,e.nestMax).forEach((n=>{var i;const s=e.createCommentNode(n.comment);null==(i=e.$commentsWrap)||i.appendChild(s.getEl()),s.getRender().playFadeAnim();const o=(n,i)=>{i.children.forEach((i=>{const s=t.find((e=>e.id===i.comment.rid)),a=i.comment,r=e.createCommentNode(a,s);n.putChild(r),o(r,i)}))};o(s,n),s.getRender().checkHeightLimit()}))},insert:(t,n)=>{var i;const s=e.createCommentNode(t,n);if(0===t.rid)null==(i=e.$commentsWrap)||i.prepend(s.getEl());else{const n=e.findCommentNode(t.rid);n&&(n.putChild(s,"DATE_ASC"===e.nestSortBy?"append":"prepend"),s.getParents().forEach((e=>{e.getRender().heightLimitRemoveForChildren()})))}s.getRender().checkHeightLimit(),s.scrollIntoView(),s.getRender().playFadeAnim()}});function At(e,t,n,i){n.is_collapsed&&(n.is_allow_reply=!1);const s=e.createCommentNode(n,i);if(n.visible){const n=s.getEl(),i=e.$commentsWrap;"append"===t&&(null==i||i.append(n)),"prepend"===t&&(null==i||i.prepend(n)),s.getRender().playFadeAnim()}return s.getRender().checkHeightLimit(),s}class Mt{constructor(e){this.options=e}getStrategy(){return this.options.flatMode?(e=this.options,{import:t=>{t.forEach((n=>{const i=0===n.rid?void 0:t.find((e=>e.id===n.rid));At(e,"append",n,i)}))},insert:(t,n)=>{At(e,"prepend",t,n).scrollIntoView()}}):Lt(this.options);var e}import(e){this.getStrategy().import(e)}insert(e,t){this.getStrategy().insert(e,t)}}function Pt(e,t){t.forEach((({el:t,max:n,imgCheck:i})=>{if(!t)return;i&&(t.style.maxHeight=`${n+1}px`);let s=!1;const o=()=>{if(s)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(Ot))return;e.el.classList.add(Ot),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(Ut))return;e.el.classList.add(Ut),e.el.style.height=`${e.max}px`,e.el.style.overflow="hidden";const t=p(`<div class="atk-height-limit-btn">${A("readMore")}</span>`);t.onclick=t=>{t.stopPropagation(),jt(e.el),e.afterExpandBtnClick&&e.afterExpandBtnClick(t)},e.el.append(t)}({el:t,max:n,afterExpandBtnClick:()=>{var t;s=!0,null==(t=e.afterExpandBtnClick)||t.call(e)}})};if(o(),i){const e=t.querySelectorAll(".atk-content img");0===e.length&&(t.style.maxHeight=""),e.forEach((e=>{e.onload=()=>o()}))}}))}const Ut="atk-height-limit";function jt(e){e&&e.classList.contains(Ut)&&(e.classList.remove(Ut),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 Ot="atk-height-limit-scroll";function Dt(e){if(e.$headerNick=e.$el.querySelector(".atk-nick"),e.data.link){const t=p('<a target="_blank" rel="noreferrer noopener nofollow"></a>');t.innerText=e.data.nick,t.href=$(e.data.link)?e.data.link:`https://${e.data.link}`,e.$headerNick.append(t)}else e.$headerNick.innerText=e.data.nick}function Bt(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 i=p('<span class="atk-badge"></span>');i.innerText=t.replace("管理员",A("admin")),i.style.backgroundColor=n||"",e.$headerBadgeWrap.append(i)}else if(e.data.is_verified){const t=p(`<span class="atk-icon-verified" title="${A("emailVerified")}"></span>`);e.$headerBadgeWrap.append(t)}if(e.data.is_pinned){const t=p(`<span class="atk-pinned-badge">${A("pin")}</span>`);e.$headerBadgeWrap.append(t)}}function It(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 qt(e){if(!e.opts.uaBadge&&!e.data.ip_region)return;let t=e.$header.querySelector("atk-ua-wrap");if(t||(t=p('<span class="atk-ua-wrap"></span>'),e.$header.append(t)),t.innerHTML="",e.data.ip_region){const n=p('<span class="atk-region-badge"></span>');n.innerText=e.data.ip_region,t.append(n)}if(e.opts.uaBadge){const{browser:n,os:i}=e.comment.getUserUA();if(String(n).trim()){const e=p('<span class="atk-ua ua-browser"></span>');e.innerText=n,t.append(e)}if(String(i).trim()){const e=p('<span class="atk-ua ua-os"></span>');e.innerText=i,t.append(e)}}}class Rt{constructor(e){h(this,"opts"),h(this,"$el"),h(this,"isLoading",!1),h(this,"msgRecTimer"),h(this,"msgRecTimerFunc"),h(this,"isConfirming",!1),h(this,"confirmRecTimer"),this.$el=p('<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||A("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||`${A("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,i){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),i&&i()}),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 _t(e){e.opts.vote&&(e.voteBtnUp=new Rt((()=>`${A("voteUp")} (${e.data.vote_up||0})`)).appendTo(e.$actions),e.voteBtnUp.setClick((()=>{e.comment.getActions().vote("up")})),e.opts.voteDown&&(e.voteBtnDown=new Rt((()=>`${A("voteDown")} (${e.data.vote_down||0})`)).appendTo(e.$actions),e.voteBtnDown.setClick((()=>{e.comment.getActions().vote("down")}))))}function Ft(e){if(!e.data.is_allow_reply)return;const t=new Rt({text:A("reply")});t.appendTo(e.$actions),t.setClick((()=>{e.opts.replyComment(e.data,e.$el)}))}function Wt(e){const t=new Rt({text:()=>e.data.is_collapsed?A("expand"):A("collapse"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminEdit("collapsed",t)}))}function Nt(e){const t=new Rt({text:()=>e.data.is_pending?A("pending"):A("approved"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminEdit("pending",t)}))}function Ht(e){const t=new Rt({text:()=>e.data.is_pinned?A("unpin"):A("pin"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminEdit("pinned",t)}))}function zt(e){const t=new Rt({text:A("edit"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.opts.editComment(e.data,e.$el)}))}function Vt(e){const t=new Rt({text:A("delete"),confirm:!0,confirmText:A("deleteConfirm"),adminOnly:!0});t.appendTo(e.$actions),t.setClick((()=>{e.comment.getActions().adminDelete(t)}))}const Kt={Avatar:function(e){const t=e.$el.querySelector(".atk-avatar"),n=p("<img />"),i=e.opts.avatarURLBuilder;if(n.src=i?i(e.data):e.comment.getGravatarURL(),e.data.link){const i=p('<a target="_blank" rel="noreferrer noopener nofollow"></a>');i.href=$(e.data.link)?e.data.link:`https://${e.data.link}`,i.append(n),t.append(i)}else t.append(n)},Header:function(e){Object.entries({renderNick:Dt,renderVerifyBadge:Bt,renderDate:It,renderUABadge:qt}).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=p(`\n <div class="atk-collapsed">\n <span class="atk-text">${A("collapsedMsg")}</span>\n <span class="atk-show-btn">${A("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"),ze(e.$content),n.innerText=A("collapse")):(e.$content.innerHTML="",e.$content.classList.add("atk-hide"),n.innerText=A("expand"))}))},ReplyAt:function(e){e.opts.flatMode||0===e.data.rid||e.opts.replyTo&&(e.$replyAt=p('<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=p(`\n <div class="atk-reply-to">\n <div class="atk-meta">${A("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=Ee(e.opts.replyTo.content);e.opts.replyTo.is_collapsed&&(n=`[${A("collapsed")}]`),e.$replyTo.querySelector(".atk-content").innerHTML=n,e.$body.prepend(e.$replyTo)},Pending:function(e){if(!e.data.is_pending)return;const t=p(`<div class="atk-pending">${A("pendingMsg")}</div>`);e.$body.prepend(t)},Actions:function(e){Object.entries({renderVote:_t,renderReply:Ft,renderCollapse:Wt,renderModerator:Nt,renderPin:Ht,renderEdit:zt,renderDel:Vt}).forEach((([t,n])=>{n(e)}))}};class Gt{constructor(e){h(this,"comment"),h(this,"$el"),h(this,"$main"),h(this,"$header"),h(this,"$headerNick"),h(this,"$headerBadgeWrap"),h(this,"$body"),h(this,"$content"),h(this,"$childrenWrap"),h(this,"$actions"),h(this,"voteBtnUp"),h(this,"voteBtnDown"),h(this,"$replyTo"),h(this,"$replyAt"),this.comment=e}get data(){return this.comment.getData()}get opts(){return this.comment.getOpts()}render(){var e;return this.$el=p('<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(Kt).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;Pt({afterExpandBtnClick:()=>{const e=this.comment.getChildren();1===e.length&&jt(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&&jt(this.$childrenWrap)}playFadeAnim(){ze(this.comment.getRender().$el)}playFadeAnimForBody(){ze(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=p('<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 Qt{constructor(e){h(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,c({},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(A("voteFail")),console.error(e)}))}adminEdit(e,t){if(t.isLoading)return;t.setLoading(!0,`${A("editing")}...`);const n=c({},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,c({},n)).then((e=>{t.setLoading(!1),this.comment.setData(e.data)})).catch((e=>{console.error(e),t.setError(A("editFail"))}))}adminDelete(e){e.isLoading||(e.setLoading(!0,`${A("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(A("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 Yt{constructor(e,t){h(this,"$el"),h(this,"renderInstance"),h(this,"actionInstance"),h(this,"data"),h(this,"opts"),h(this,"parent"),h(this,"children",[]),h(this,"nestCurt"),this.opts=t,this.data=c({},e),this.data.date=this.data.date.replace(/-/g,"/"),this.parent=null,this.nestCurt=1,this.actionInstance=new Qt(this),this.renderInstance=new Gt(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(),i=e.getEl();"append"===t?n.append(i):"prepend"===t&&n.prepend(i),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&&He(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 Ee(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))||y(n,A)}getUserUA(){const e=function(e){const t=window||{},n=navigator||{},i=String(e||n.userAgent),s={os:"",osVersion:"",engine:"",browser:"",device:"",language:"",version:""},o={Trident:i.includes("Trident")||i.includes("NET CLR"),Presto:i.includes("Presto"),WebKit:i.includes("AppleWebKit"),Gecko:i.includes("Gecko/")},a={Safari:i.includes("Safari"),Chrome:i.includes("Chrome")||i.includes("CriOS"),IE:i.includes("MSIE")||i.includes("Trident"),Edge:i.includes("Edge")||i.includes("Edg"),Firefox:i.includes("Firefox")||i.includes("FxiOS"),"Firefox Focus":i.includes("Focus"),Servo:i.includes("Servo"),Chromium:i.includes("Chromium"),Opera:i.includes("Opera")||i.includes("OPR"),Vivaldi:i.includes("Vivaldi"),Yandex:i.includes("YaBrowser"),Kindle:i.includes("Kindle")||i.includes("Silk/"),360:i.includes("360EE")||i.includes("360SE"),UC:i.includes("UC")||i.includes(" UBrowser"),QQBrowser:i.includes("QQBrowser"),QQ:i.includes("QQ/"),Baidu:i.includes("Baidu")||i.includes("BIDUBrowser"),Maxthon:i.includes("Maxthon"),Sogou:i.includes("MetaSr")||i.includes("Sogou"),LBBROWSER:i.includes("LBBROWSER"),"2345Explorer":i.includes("2345Explorer"),TheWorld:i.includes("TheWorld"),MIUI:i.includes("MiuiBrowser"),HuaweiBrowser:i.includes("HuaweiBrowser"),Quark:i.includes("Quark"),Qiyu:i.includes("Qiyu"),"360Browser":i.includes("360Browser"),Wechat:i.includes("MicroMessenger"),Taobao:i.includes("AliApp(TB"),Alipay:i.includes("AliApp(AP"),Weibo:i.includes("Weibo"),Douban:i.includes("com.douban.frodo"),Suning:i.includes("SNEBUY-APP"),iQiYi:i.includes("IqiyiApp")},r={Windows:i.includes("Windows"),Linux:i.includes("Linux")||i.includes("X11"),macOS:i.includes("Macintosh"),Android:i.includes("Android")||i.includes("Adr"),Ubuntu:i.includes("Ubuntu"),FreeBSD:i.includes("FreeBSD"),Debian:i.includes("Debian"),"Windows Phone":i.includes("IEMobile")||i.includes("Windows Phone"),BlackBerry:i.includes("BlackBerry")||i.includes("RIM"),MeeGo:i.includes("MeeGo"),Symbian:i.includes("Symbian"),iOS:i.includes("like Mac OS X"),OpenHarmony:i.includes("OpenHarmony"),"Chrome OS":i.includes("CrOS"),WebOS:i.includes("hpwOS")},l={Mobile:i.includes("Mobi")||i.includes("iPh")||i.includes("480")||i.includes("Phone"),Tablet:i.includes("Tablet")||i.includes("Pad")||i.includes("Nexus 7")};l.Mobile?l.Mobile=!i.includes("iPad"):a.Chrome&&i.includes("Edg")?(a.Chrome=!1,a.Edge=!0):t.showModalDialog&&t.chrome&&(a.Chrome=!1,a[360]=!0),s.device="PC",s.language=(()=>{const e=(n.browserLanguage||n.language).split("-");return e[1]&&(e[1]=e[1].toUpperCase()),e.join("_")})();const c={engine:o,browser:a,os:r,device:l};Object.entries(c).forEach((([e,t])=>{Object.entries(t).forEach((([t,n])=>{!0===n&&(s[e]=t)}))}));const d={Windows:()=>{const e=i.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:()=>i.replace(/^.*Android ([\d.]+);.*$/,"$1"),iOS:()=>i.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,"."),Debian:()=>i.replace(/^.*Debian\/([\d.]+).*$/,"$1"),"Windows Phone":()=>i.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2"),macOS:()=>i.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,"."),OpenHarmony:()=>i.replace(/^.*OpenHarmony ([\d.]+).*$/,"$1"),WebOS:()=>i.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")};s.osVersion="",d[s.os]&&(s.osVersion=d[s.os](),s.osVersion===i&&(s.osVersion=""));const h={Safari:()=>i.replace(/^.*Version\/([\d.]+).*$/,"$1"),Chrome:()=>i.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1"),IE:()=>i.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1"),Edge:()=>i.replace(/^.*(Edge|Edg|Edg[A-Z]{1})\/([\d.]+).*$/,"$2"),Firefox:()=>i.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1"),"Firefox Focus":()=>i.replace(/^.*Focus\/([\d.]+).*$/,"$1"),Servo:()=>i.replace(/^.*Servo\/?([\d.]+).*$/,"$1"),Chromium:()=>i.replace(/^.*Chromium\/([\d.]+).*$/,"$1"),Opera:()=>i.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1"),Vivaldi:()=>i.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1"),Yandex:()=>i.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1"),Kindle:()=>i.replace(/^.*Version\/([\d.]+).*$/,"$1"),Maxthon:()=>i.replace(/^.*Maxthon\/([\d.]+).*$/,"$1"),QQBrowser:()=>i.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1"),QQ:()=>i.replace(/^.*QQ\/([\d.]+).*$/,"$1"),Baidu:()=>i.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1"),UC:()=>i.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1"),Sogou:()=>i.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1"),"2345Explorer":()=>i.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1"),TheWorld:()=>i.replace(/^.*TheWorld ([\d.]+).*$/,"$1"),MIUI:()=>i.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1"),HuaweiBrowser:()=>i.replace(/^.*HuaweiBrowser\/([\d.]+).*$/,"$1"),Quark:()=>i.replace(/^.*Quark\/([\d.]+).*$/,"$1"),Qiyu:()=>i.replace(/^.*Qiyu\/([\d.]+).*$/,"$1"),"360Browser":()=>i.replace(/^.*360Browser\/([\d.]+).*$/,"$1"),Wechat:()=>i.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1"),Taobao:()=>i.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1"),Alipay:()=>i.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1"),Weibo:()=>i.replace(/^.*weibo__([\d.]+).*$/,"$1"),Douban:()=>i.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1"),Suning:()=>i.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1"),iQiYi:()=>i.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")};return s.version="",h[s.browser]&&(s.version=h[s.browser](),s.version===i&&(s.version="")),s.version.indexOf(".")&&(s.version=s.version.substring(0,s.version.indexOf("."))),"iOS"===s.os&&i.includes("iPad")?s.os="iPadOS":"Edge"!==s.browser||i.includes("Edg")?"MIUI"===s.browser?s.os="Android":"Chrome"===s.browser&&Number(s.version)>27||"Opera"===s.browser&&Number(s.version)>12||"Yandex"===s.browser?s.engine="Blink":void 0===s.browser&&(s.browser="Unknow App"):s.engine="EdgeHTML",s}(this.data.ua);return{browser:`${e.browser} ${e.version}`,os:`${e.os} ${e.osVersion}`}}getOpts(){return this.opts}}class Jt{constructor(e){h(this,"opts"),h(this,"$el"),h(this,"$loading"),h(this,"$text"),h(this,"offset",0),h(this,"total",0),h(this,"origText","Load More"),this.opts=e,this.origText=this.opts.text||this.origText,this.$el=p(`<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 Xt{constructor(){h(this,"instance"),h(this,"onReachedBottom",null),h(this,"opt")}create(e){return this.opt=e,this.instance=new Jt({pageSize:e.pageSize,onClick:t=>u(this,null,(function*(){e.getData().fetchComments({offset:t})})),text:A("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 Zt{constructor(e,t){h(this,"opts"),h(this,"total"),h(this,"$el"),h(this,"$input"),h(this,"inputTimer"),h(this,"$prevBtn"),h(this,"$nextBtn"),h(this,"page",1),this.total=e,this.opts=t,this.$el=p('<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?Fe(this.$el):We(this.$el)}}class en{constructor(){h(this,"instance")}create(e){return this.instance=new Zt(e.total,{pageSize:e.pageSize,onChange:t=>u(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 tn(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 nn=e=>{let t=null;e.getConf().watchConf(["pagination","locale"],(n=>{const i=e.getList(),s=e.getData();t&&t.dispose(),t=function(e){return e.pagination.readMore?new Xt:new en}(n);const{offset:o,total:a}=tn(s.getListLastFetch()),r=t.create(c({pageSize:n.pagination.pageSize,total:a,readMoreAutoLoad:n.pagination.autoLoad},e));i.getCommentsWrapEl().after(r),null==t||t.update(o,a)})),e.getEvents().on("list-loaded",(n=>{const{offset:i,total:s}=tn(e.getData().getListLastFetch());null==t||t.update(i,s)})),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,A("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 sn{constructor(e){h(this,"opts"),h(this,"$el"),h(this,"$commentsWrap"),h(this,"commentNodes",[]),this.opts=e,this.$el=p('<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"),nn(c({getList:()=>this},e)),this.initCrudEvents()}getEl(){return this.$el}getCommentsWrapEl(){return this.$commentsWrap}getCommentNodes(){return this.commentNodes}getLayout({forceFlatMode:e}={}){return new Mt({$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 i=function(e,t,n){const i=e.getConf().get(),s=new Yt(t,{onAfterRender:()=>{e.getEvents().trigger("comment-rendered",s)},onDelete:t=>{e.getData().deleteComment(t.getID())},replyTo:n,flatMode:"boolean"==typeof(null==e?void 0:e.forceFlatMode)?null==e?void 0:e.forceFlatMode:i.flatMode,gravatar:i.gravatar,nestMax:i.nestMax,heightLimit:i.heightLimit,avatarURLBuilder:i.avatarURLBuilder,scrollRelativeTo:i.scrollRelativeTo,vote:i.vote,voteDown:i.voteDown,uaBadge:i.uaBadge,dateFormatter:i.dateFormatter,getApi:e.getApi,replyComment:e.replyComment,editComment:e.editComment});return s.render(),s}(c({forceFlatMode:e},this.opts),t,n);return this.commentNodes.push(i),i},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 on{constructor(e){h(this,"opts"),h(this,"$el"),h(this,"layer"),h(this,"$header"),h(this,"$closeBtn"),h(this,"$iframeWrap"),h(this,"$iframe"),h(this,"refreshWhenShow",!0),h(this,"animTimer"),this.opts=e,this.$el=p('<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 u(this,null,(function*(){this.refreshWhenShow=!0}))}show(){return u(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 u(this,null,(function*(){const t=(yield this.opts.getApi().user.getUserStatus(c({},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=p('<iframe referrerpolicy="strict-origin-when-cross-origin"></iframe>'),n=w({base:this.opts.getConf().get().server,path:"/sidebar/"}),i={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&&(i.view=e),i.darkMode=this.getDarkMode()?"1":"0";const s=new URLSearchParams(i);return this.iframeLoad(t,`${n}?${s.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,Fe(this.$iframeWrap),e.onload=()=>{We(this.$iframeWrap)}}}const an=[...new Set([e=>{e.provide("data",(e=>new wt(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 De(Le(t.get(),e,n))),["user","config","apiHandlers"],{lifecycle:"transient"})},e=>{e.watchConf(["locale"],(e=>{var t;(t=e.locale)!==T&&(T=t,L="string"==typeof t?x(t):t)}))},e=>{e.provide("user",(()=>new ht({onUserChanged:t=>{e.trigger("user-changed",t)}})),[])},e=>{e.provide("editor",((t,n)=>{const i=new $t({getEvents:()=>t,getConf:()=>n});return e.getEl().appendChild(i.getEl()),i}),["events","config"])},e=>{e.provide("list",((t,n,i,s,o)=>{const a=new sn({getApi:()=>t,getEvents:()=>n,getConf:()=>i,getData:()=>s,replyComment:(e,t)=>o.setReplyComment(e,t),editComment:(e,t)=>o.setEditComment(e,t),resetEditorState:()=>o.resetState(),onListGotoFirst:()=>e.listGotoFirst()});return e.getEl().appendChild(a.getEl()),a}),["api","events","config","data","editor"])},e=>{e.provide("checkers",((t,n,i,s,o)=>{const a=new vt({getApi:()=>t,getLayers:()=>i,getUser:()=>s,onReload:()=>e.reload(),getCaptchaIframeURL:()=>`${o.get().server}/api/v2/captcha/?t=${+new Date}`});return n.add("need_captcha",(e=>a.checkCaptcha(e))),n.add("need_login",(()=>a.checkAdmin({}))),a}),["api","apiHandlers","layers","user","config"])},e=>{e.provide("layers",(()=>{const t=new Tt;return document.body.appendChild(t.getEl()),e.on("unmounted",(()=>{null==t||t.destroy()})),t}))},e=>{e.provide("sidebar",((t,n,i,s,o,a,r,l)=>{const c=new on({onShow:()=>{setTimeout((()=>{n.updateNotifies([])}),0),t.trigger("sidebar-show")},onHide:()=>{i.resetState(),t.trigger("sidebar-hide")},getCheckers:()=>s,getApi:()=>o,getConf:()=>a,getUser:()=>r,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(!t.Marked.name)return}catch(i){return}const n=new t.Marked;n.setOptions(c(c({renderer:ge({imgLazyLoad:e.imgLazyLoad})},we),e.markedOptions)),ke=n}({markedOptions:e.markedOptions,imgLazyLoad:e.imgLazyLoad})})),e.watchConf(["markedReplacers"],(e=>{var t;e.markedReplacers&&(t=e.markedReplacers,$e=t)}))},e=>{e.provide("editorPlugs",((t,n,i,s,o,a)=>{const r=new et({getArtalkRootEl:()=>e.getEl(),getEditor:()=>t,getConf:()=>n,getUser:()=>i,getApi:()=>a,getData:()=>s,getCheckers:()=>o,onSubmitted:()=>e.trigger("editor-submitted")});return t.setPlugins(r),r}),["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()}))},...it,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=>{Ae({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&&!st&&function(e,t,n){const i=function(e,t){const n=e.split("."),i=t.split(".");for(let s=0;s<3;s++){const e=Number(n[s]),t=Number(i[s]);if(e>t)return 1;if(t>e)return-1;if(!Number.isNaN(e)&&Number.isNaN(t))return 1;if(Number.isNaN(e)&&!Number.isNaN(t))return-1}return 0}(t,n);if(0===i)return;const s=p(`<div class="atk-version-check-notice">${A("updateMsg",{name:A(i<0?"client":"server")})} <span class="atk-info">${A("currentVersion")}: ${A("client")} ${t} / ${A("server")} ${n}</span></div>`),o=p(`<span class="atk-ignore-btn">${A("ignore")}</span>`);o.onclick=()=>{s.remove(),st=!0},s.append(o),e.getEl().parentElement.prepend(s)}(t,tt,e.apiVersion)}))},e=>{const t=e.inject("config"),n=e.inject("layers");let i;const s=t=>{const s=[e.getEl(),n.getEl()];ot||(ot=window.matchMedia("(prefers-color-scheme: dark)")),"auto"===t?(i||(i=e=>at(s,e.matches),ot.addEventListener("change",i)),at(s,ot.matches)):(i&&(ot.removeEventListener("change",i),i=void 0),at(s,t))};e.watchConf(["darkMode"],(e=>s(e.darkMode))),e.on("created",(()=>s(t.get().darkMode))),e.on("unmounted",(()=>{i&&(null==ot||ot.removeEventListener("change",i)),i=void 0}))},e=>{const t=e.inject("config");let n,i={};e.watchConf(["pageVote"],(e=>{const t=c(c({},rt),"object"==typeof e.pageVote?e.pageVote:{});null==n||n(),e.pageVote&&(i=function(e,t,n,i){var s,o;const a=c({},e);return a.upBtnEl=document.querySelector(t.upBtnEl),a.downBtnEl=document.querySelector(t.downBtnEl),a.upCountEl=document.querySelector(t.upCountEl),a.downCountEl=document.querySelector(t.downCountEl),a.activeClass=t.activeClass,a.voteUpHandler=n,a.voteDownHandler=i,null==(s=a.upBtnEl)||s.addEventListener("click",n),null==(o=a.downBtnEl)||o.addEventListener("click",i),a}(i,t,r,l),n=()=>i=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)),{}}(i))})),e.on("unmounted",(()=>{null==n||n(),e.off("list-fetched",o)})),e.on("list-fetched",o);let s=0;function o({data:n}){t.get().pageVote&&function(e){return e.upBtnEl||e.downBtnEl||e.upCountEl||e.downCountEl}(i)&&n&&(s!==n.page.id?(s=n.page.id,lt(i,n.page.vote_up,n.page.vote_down,!1,!1),function(e,t,n){n.votes.getVote("page",t).then((({data:t})=>{lt(e,t.up,t.down,t.is_up,t.is_down)})).catch((e=>{console.error("[ArtalkPageVote]",e)}))}(i,s,e.getApi())):lt(i,n.page.vote_up,n.page.vote_down))}const a=()=>{var t;return{state:i,pageId:(null==(t=e.getData().getPage())?void 0:t.id)||0,httpApi:e.getApi()}},r=ct("up",a),l=ct("down",a)}],rn=new Set([...an]),ln=new WeakMap;function cn(e,t){return u(this,null,(function*(){var n;const i=new Set,s=e=>{e.forEach((e=>{"function"==typeof e&&(i.has(e)||(e(t,ln.get(e)),i.add(e)))}))};s(rn);const{data:o}=yield t.getApi().conf.conf().catch((n=>{throw((e,t={})=>{var n;const i=e.inject("list"),s=e.inject("user"),o=e.inject("config"),a=t.err;if(!a)throw new Error("MountError: `err` is required");let r="";if(null==(n=a.data)?void 0:n.err_no_site){const e={create_name:o.get().site,create_urls:`${window.location.protocol}//${window.location.host}`};r=`sites|${JSON.stringify(e)}`}nt({$err:i.getEl(),errMsg:a.msg||String(a),errData:a.data,retryFn:()=>{var e;return null==(e=t.onRetry)?void 0:e.call(t)},onOpenSidebar:s.getData().is_admin?()=>e.showSidebar({view:r}):void 0})})(t,{err:n,onRetry:()=>cn(e,t)}),n}));let a=d(c({},e),{apiVersion:null==(n=o.version)?void 0:n.version});const r=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}(o.frontend_conf||{});a=a.preferRemoteConf?Se(a,r):Se(r,a),t.updateConf(a),a.pluginURLs&&(yield function(e,t){return u(this,null,(function*(){const n=new Set;if(!e||!Array.isArray(e))return n;const i=[];return e.forEach((e=>{/^(http|https):\/\//.test(e)||(e=`${t.replace(/\/$/,"")}/${e.replace(/^\//,"")}`),i.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(i),Object.values(window.ArtalkPlugins||{}).forEach((e=>{"function"==typeof e&&n.add(e)})),n}))}(a.pluginURLs,t.getConf().server).then((e=>{s(e)})).catch((e=>{console.error("Failed to load plugin",e)})))}))}function dn({keys:e,effect:t,getConf:n,getEvents:i}){let s=null;const o=()=>{const i=(()=>{const t=n(),i={};return e.forEach((e=>{i[e]=t[e]})),i})();var o,a;(null==s||(o=s,a=i,!(JSON.stringify(o)===JSON.stringify(a))))&&(s=i,t(i))};i().on("mounted",o),i().on("updated",o)}class hn{constructor(e){h(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 Ce(t);(e=>{e.provide("events",(()=>new Ze))})(n),(e=>{let t=Te({},!0);e.provide("config",(e=>{let n=!1;return e.on("mounted",(()=>n=!0)),{watchConf:(n,i)=>{dn({keys:n,effect:i,getConf:()=>t,getEvents:()=>e})},get:()=>t,update:i=>{t=Se(t,Te(i,!1)),n&&e.trigger("updated",t)}}}),["events"])})(n),n.updateConf(e),n.trigger("created");(()=>{u(this,null,(function*(){yield cn(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 hn(e)}static use(e,t){rn.add(e),ln.set(e,t)}static loadCountWidget(e){const t=Te(e,!0);Ae({getApi:()=>new De(Le(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 un=hn.init,pn=hn.use,mn=hn.loadCountWidget;e.Defaults=xe,e.default=hn,e.init=un,e.loadCountWidget=mn,e.use=pn,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
11
11
|
//# sourceMappingURL=ArtalkLite.js.map
|