artalk 2.7.0 → 2.7.2
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/README.md +1 -1
- package/dist/Artalk.css +1 -1
- package/dist/Artalk.es.js +209 -188
- package/dist/Artalk.es.js.map +1 -0
- package/dist/Artalk.iife.js +2 -1
- package/dist/Artalk.iife.js.map +1 -0
- package/dist/Artalk.js +2 -1
- package/dist/Artalk.js.map +1 -0
- package/dist/ArtalkLite.css +1 -1
- package/dist/ArtalkLite.es.js +209 -188
- package/dist/ArtalkLite.es.js.map +1 -0
- package/dist/ArtalkLite.iife.js +2 -1
- package/dist/ArtalkLite.iife.js.map +1 -0
- package/dist/ArtalkLite.js +2 -1
- package/dist/ArtalkLite.js.map +1 -0
- package/dist/i18n/jp.js +1 -1
- package/dist/i18n/zh-TW.js +1 -1
- package/dist/src/api/_base.d.ts +7 -0
- package/dist/src/api/_options.d.ts +5 -0
- package/dist/src/artalk.d.ts +0 -2
- package/dist/src/components/checker/index.d.ts +2 -0
- package/dist/src/i18n/en.d.ts +4 -0
- package/dist/src/i18n/external.d.ts +4 -0
- package/dist/src/i18n/index.d.ts +12 -0
- package/dist/src/i18n/jp.d.ts +4 -0
- package/dist/src/i18n/zh-TW.d.ts +4 -0
- package/dist/src/lib/user.d.ts +8 -6
- package/dist/src/main.d.ts +3 -0
- package/dist/src/plugins/editor/_kit.d.ts +7 -1
- package/dist/src/service.d.ts +2 -8
- package/dist/types/event.d.ts +1 -1
- package/package.json +43 -17
- package/dist/src/components/dark-mode.d.ts +0 -2
- package/src/api/_base.ts +0 -18
- package/src/api/_options.ts +0 -25
- package/src/api/_request.ts +0 -104
- package/src/api/admin.ts +0 -18
- package/src/api/captcha.ts +0 -24
- package/src/api/comment.ts +0 -84
- package/src/api/index.ts +0 -29
- package/src/api/page.ts +0 -83
- package/src/api/site.ts +0 -51
- package/src/api/system.ts +0 -49
- package/src/api/upload.ts +0 -28
- package/src/api/user.ts +0 -132
- package/src/artalk.ts +0 -119
- package/src/comment/actions.ts +0 -83
- package/src/comment/comment.html +0 -18
- package/src/comment/comment.ts +0 -192
- package/src/comment/height-limit.ts +0 -100
- package/src/comment/index.ts +0 -3
- package/src/comment/render.ts +0 -150
- package/src/comment/renders/actions.ts +0 -114
- package/src/comment/renders/avatar.ts +0 -22
- package/src/comment/renders/content.ts +0 -39
- package/src/comment/renders/header.ts +0 -84
- package/src/comment/renders/index.ts +0 -19
- package/src/comment/renders/pending.ts +0 -12
- package/src/comment/renders/reply-at.ts +0 -16
- package/src/comment/renders/reply-to.ts +0 -24
- package/src/components/action-btn.ts +0 -170
- package/src/components/checker/admin.ts +0 -37
- package/src/components/checker/captcha-renders.ts +0 -69
- package/src/components/checker/captcha.ts +0 -26
- package/src/components/checker/index.ts +0 -192
- package/src/components/dark-mode.ts +0 -30
- package/src/components/dialog.ts +0 -62
- package/src/components/error-dialog.ts +0 -35
- package/src/components/pagination.ts +0 -153
- package/src/components/read-more-btn.ts +0 -92
- package/src/config.ts +0 -119
- package/src/context.ts +0 -146
- package/src/data.ts +0 -110
- package/src/defaults.ts +0 -61
- package/src/editor/editor.html +0 -18
- package/src/editor/editor.ts +0 -114
- package/src/editor/state.ts +0 -52
- package/src/editor/ui.ts +0 -36
- package/src/i18n/en.ts +0 -81
- package/src/i18n/external.ts +0 -10
- package/src/i18n/index.ts +0 -67
- package/src/i18n/jp.ts +0 -83
- package/src/i18n/zh-CN.ts +0 -85
- package/src/i18n/zh-TW.ts +0 -83
- package/src/layer/index.ts +0 -4
- package/src/layer/layer-manager.ts +0 -32
- package/src/layer/layer.ts +0 -39
- package/src/layer/scrollbar-helper.ts +0 -24
- package/src/layer/sidebar-layer.html +0 -8
- package/src/layer/sidebar-layer.ts +0 -155
- package/src/layer/wrap.ts +0 -77
- package/src/lib/component.ts +0 -12
- package/src/lib/detect.ts +0 -222
- package/src/lib/event-manager.ts +0 -47
- package/src/lib/highlight.ts +0 -5
- package/src/lib/marked-renderer.ts +0 -32
- package/src/lib/marked.ts +0 -72
- package/src/lib/sanitizer.ts +0 -57
- package/src/lib/ui.ts +0 -193
- package/src/lib/user.ts +0 -55
- package/src/lib/utils.ts +0 -236
- package/src/list/comment.ts +0 -20
- package/src/list/layout.ts +0 -120
- package/src/list/list.html +0 -20
- package/src/list/list.ts +0 -79
- package/src/list/nest.ts +0 -66
- package/src/list/page.ts +0 -97
- package/src/list/paginator/index.ts +0 -25
- package/src/list/paginator/read-more.ts +0 -67
- package/src/list/paginator/up-down.ts +0 -51
- package/src/main.ts +0 -5
- package/src/plugins/admin-only-elem.ts +0 -40
- package/src/plugins/conf-remoter.ts +0 -54
- package/src/plugins/dark-mode.ts +0 -12
- package/src/plugins/editor/_kit.ts +0 -57
- package/src/plugins/editor/_plug.ts +0 -60
- package/src/plugins/editor/_sample.ts +0 -8
- package/src/plugins/editor/closable.ts +0 -44
- package/src/plugins/editor/emoticons.scss +0 -72
- package/src/plugins/editor/emoticons.ts +0 -293
- package/src/plugins/editor/header-event.ts +0 -35
- package/src/plugins/editor/header-link.ts +0 -31
- package/src/plugins/editor/header-user.ts +0 -98
- package/src/plugins/editor/index.ts +0 -40
- package/src/plugins/editor/local-storage.ts +0 -36
- package/src/plugins/editor/mover.ts +0 -29
- package/src/plugins/editor/preview.scss +0 -7
- package/src/plugins/editor/preview.ts +0 -41
- package/src/plugins/editor/state-edit.ts +0 -116
- package/src/plugins/editor/state-reply.ts +0 -91
- package/src/plugins/editor/submit-add.ts +0 -33
- package/src/plugins/editor/submit-btn.ts +0 -25
- package/src/plugins/editor/submit.ts +0 -73
- package/src/plugins/editor/textarea.ts +0 -55
- package/src/plugins/editor/upload.ts +0 -145
- package/src/plugins/editor-kit.ts +0 -161
- package/src/plugins/index.ts +0 -16
- package/src/plugins/list/copyright.ts +0 -16
- package/src/plugins/list/count.ts +0 -31
- package/src/plugins/list/dropdown.ts +0 -95
- package/src/plugins/list/error-dialog.ts +0 -22
- package/src/plugins/list/fetch.ts +0 -64
- package/src/plugins/list/goto-first.ts +0 -23
- package/src/plugins/list/goto.ts +0 -72
- package/src/plugins/list/index.ts +0 -25
- package/src/plugins/list/loading.ts +0 -17
- package/src/plugins/list/no-comment.ts +0 -25
- package/src/plugins/list/reach-bottom.ts +0 -46
- package/src/plugins/list/sidebar-btn.ts +0 -39
- package/src/plugins/list/time-ticking.ts +0 -22
- package/src/plugins/list/unread-badge.ts +0 -26
- package/src/plugins/list/unread.ts +0 -38
- package/src/plugins/list/with-editor.ts +0 -59
- package/src/plugins/markdown.ts +0 -10
- package/src/plugins/stat.ts +0 -79
- package/src/plugins/version-check.ts +0 -37
- package/src/service.ts +0 -91
- package/src/style/_color.scss +0 -41
- package/src/style/_extend.scss +0 -20
- package/src/style/_variables.scss +0 -3
- package/src/style/comment.scss +0 -360
- package/src/style/editor.scss +0 -194
- package/src/style/list.scss +0 -212
- package/src/style/main.scss +0 -486
- package/src/style/pagination.scss +0 -58
- package/src/style/sidebar-layer.scss +0 -92
- package/types/config.ts +0 -153
- package/types/context.ts +0 -84
- package/types/data.ts +0 -271
- package/types/editor.ts +0 -95
- package/types/event.ts +0 -40
- package/types/global.d.ts +0 -1
- package/types/index.ts +0 -7
- package/types/plugin.ts +0 -3
- package/types/sidebar.ts +0 -3
package/dist/ArtalkLite.iife.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
var Artalk=function(t,e){"use strict";var n=Object.defineProperty,i=Object.defineProperties,s=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,l=(t,e,i)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,c=(t,e)=>{for(var n in e||(e={}))a.call(e,n)&&l(t,n,e[n]);if(o)for(var n of o(e))r.call(e,n)&&l(t,n,e[n]);return t},d=(t,e)=>i(t,s(e)),h=(t,e,n)=>(l(t,"symbol"!=typeof e?e+"":e,n),n),u=(t,e,n)=>new Promise(((i,s)=>{var o=t=>{try{r(n.next(t))}catch(e){s(e)}},a=t=>{try{r(n.throw(t))}catch(e){s(e)}},r=t=>t.done?i(t.value):Promise.resolve(t.value).then(o,a);r((n=n.apply(t,e)).next())}));function p(t=""){const e=document.createElement("div");return e.innerHTML=t.trim(),e.firstElementChild||e}function m(t){return parseFloat(getComputedStyle(t,null).height.replace("px",""))}function g(t){const e=document.createElement("div");e.innerText=t;return e.innerHTML}function f(t){const e=RegExp(`[?&]${t}=([^&]*)`).exec(window.location.search);return e&&decodeURIComponent(e[1].replace(/\+/g," "))}function k(t,e){const n=t=>{const e=t.getBoundingClientRect(),n=window.pageXOffset||document.documentElement.scrollLeft,i=window.pageYOffset||document.documentElement.scrollTop;return{top:e.top+i,left:e.left+n}},i=n(t);if(!e)return i;const s=n(e);return{top:i.top-s.top,left:i.left-s.left}}function y(t,e){let n=t.toString();for(;n.length<e;)n=`0${n}`;return n}function v(t,e=(t=>t)){try{const n=t.getTime(),i=(new Date).getTime()-n,s=Math.floor(i/864e5);if(0===s){const t=i%864e5,n=Math.floor(t/36e5);if(0===n){const n=t%36e5,i=Math.floor(n/6e4);if(0===i){const t=n%6e4,i=Math.round(t/1e3);return i<10?e("now"):`${i} ${e("seconds")}`}return`${i} ${e("minutes")}`}return`${n} ${e("hours")}`}return s<0?e("now"):s<8?`${s} ${e("days")}`:function(t){const e=y(t.getDate(),2),n=y(t.getMonth()+1,2);return`${y(t.getFullYear(),2)}-${n}-${e}`}(t)}catch(n){return console.error(n)," - "}}function $(){return u(this,null,(function*(){const t=navigator.userAgent;if(!navigator.userAgentData||!navigator.userAgentData.getHighEntropyValues)return t;const e=navigator.userAgentData;let n=null;try{n=yield e.getHighEntropyValues(["platformVersion"])}catch(s){return console.error(s),t}const i=Number(n.platformVersion.split(".")[0]);return"Windows"===e.platform&&i>=13?t.replace(/Windows NT 10.0/,"Windows NT 11.0"):"macOS"===e.platform&&i>=11?t.replace(/(Mac OS X \d+_\d+_\d+|Mac OS X)/,`Mac OS X ${n.platformVersion.replace(/\./g,"_")}`):t}))}function w(t){let e;try{e=new URL(t)}catch(n){return!1}return"http:"===e.protocol||"https:"===e.protocol}function b(t){return e=t.base,n=t.path,`${e.replace(/\/$/,"")}/${n.replace(/^\//,"")}`;var e,n}function x(t,e){const n=t=>t&&"object"==typeof t;return n(t)&&n(e)?(Object.keys(e).forEach((i=>{const s=t[i],o=e[i];Array.isArray(s)&&Array.isArray(o)?t[i]=s.concat(o):n(s)&&n(o)?t[i]=x(c({},s),o):t[i]=o})),t):e}var C="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function E(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}!function(){function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function n(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e)}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,e){return(o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function r(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return r(t)}function c(t){var e=a();return function(){var n,i=s(t);if(e){var o=s(this).constructor;n=Reflect.construct(i,arguments,o)}else n=i.apply(this,arguments);return l(this,n)}}function d(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=s(t)););return t}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var i=d(t,e);if(i){var s=Object.getOwnPropertyDescriptor(i,e);return s.get?s.get.call(arguments.length<3?t:n):s.value}},h.apply(this,arguments)}var u=function(){function e(){t(this,e),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return n(e,[{key:"addEventListener",value:function(t,e,n){t in this.listeners||(this.listeners[t]=[]),this.listeners[t].push({callback:e,options:n})}},{key:"removeEventListener",value:function(t,e){if(t in this.listeners)for(var n=this.listeners[t],i=0,s=n.length;i<s;i++)if(n[i].callback===e)return void n.splice(i,1)}},{key:"dispatchEvent",value:function(t){if(t.type in this.listeners){for(var e=this.listeners[t.type].slice(),n=0,i=e.length;n<i;n++){var s=e[n];try{s.callback.call(this,t)}catch(o){Promise.resolve().then((function(){throw o}))}s.options&&s.options.once&&this.removeEventListener(t.type,s.callback)}return!t.defaultPrevented}}}]),e}(),p=function(e){i(a,e);var o=c(a);function a(){var e;return t(this,a),(e=o.call(this)).listeners||u.call(r(e)),Object.defineProperty(r(e),"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(r(e),"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(r(e),"reason",{value:void 0,writable:!0,configurable:!0}),e}return n(a,[{key:"toString",value:function(){return"[object AbortSignal]"}},{key:"dispatchEvent",value:function(t){"abort"===t.type&&(this.aborted=!0,"function"==typeof this.onabort&&this.onabort.call(this,t)),h(s(a.prototype),"dispatchEvent",this).call(this,t)}}]),a}(u),m=function(){function e(){t(this,e),Object.defineProperty(this,"signal",{value:new p,writable:!0,configurable:!0})}return n(e,[{key:"abort",value:function(t){var e;try{e=new Event("abort")}catch(i){"undefined"!=typeof document?document.createEvent?(e=document.createEvent("Event")).initEvent("abort",!1,!1):(e=document.createEventObject()).type="abort":e={type:"abort",bubbles:!1,cancelable:!1}}var n=t;if(void 0===n)if("undefined"==typeof document)(n=new Error("This operation was aborted")).name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(s){(n=new Error("This operation was aborted")).name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(e)}},{key:"toString",value:function(){return"[object AbortController]"}}]),e}();function g(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):"function"==typeof t.Request&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function f(t){"function"==typeof t&&(t={fetch:t});var e=t,n=e.fetch,i=e.Request,s=void 0===i?n.Request:i,o=e.AbortController,a=e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,r=void 0!==a&&a;if(!g({fetch:n,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:n,Request:l};var l=s;(l&&!l.prototype.hasOwnProperty("signal")||r)&&((l=function(t,e){var n;e&&e.signal&&(n=e.signal,delete e.signal);var i=new s(t,e);return n&&Object.defineProperty(i,"signal",{writable:!1,enumerable:!1,configurable:!0,value:n}),i}).prototype=s.prototype);var c=n;return{fetch:function(t,e){var n=l&&l.prototype.isPrototypeOf(t)?t.signal:e?e.signal:void 0;if(n){var i;try{i=new DOMException("Aborted","AbortError")}catch(o){(i=new Error("Aborted")).name="AbortError"}if(n.aborted)return Promise.reject(i);var s=new Promise((function(t,e){n.addEventListener("abort",(function(){return e(i)}),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([s,c(t,e)])}return c(t,e)},Request:l}}"undefined"!=typeof Symbol&&Symbol.toStringTag&&(m.prototype[Symbol.toStringTag]="AbortController",p.prototype[Symbol.toStringTag]="AbortSignal"),function(t){if(g(t))if(t.fetch){var e=f(t),n=e.fetch,i=e.Request;t.fetch=n,t.Request=i,Object.defineProperty(t,"AbortController",{writable:!0,enumerable:!1,configurable:!0,value:m}),Object.defineProperty(t,"AbortSignal",{writable:!0,enumerable:!1,configurable:!0,value:p})}else console.warn("fetch() is not available, cannot install abortcontroller-polyfill")}("undefined"!=typeof self?self:C)}();const S="ArtalkUser";const T=new class{constructor(){h(this,"data"),h(this,"onUserChanged",null);const t=JSON.parse(window.localStorage.getItem(S)||"{}");this.data={nick:t.nick||"",email:t.email||"",link:t.link||"",token:t.token||"",isAdmin:t.isAdmin||!1}}update(t={}){Object.entries(t).forEach((([t,e])=>{this.data[t]=e})),window.localStorage.setItem(S,JSON.stringify(this.data)),this.onUserChanged&&this.onUserChanged(this.data)}setOnUserChanged(t){this.onUserChanged=t}logout(){this.update({token:"",isAdmin:!1})}checkHasBasicUserInfo(){return!!this.data.nick&&!!this.data.email}},L={placeholder:"Leave a comment",noComment:"No Comment",send:"Send",save:"Save",nick:"Nickname",email:"Email",link:"Website",emoticon:"Emoji",preview:"Preview",image:"Image",uploadFail:"Upload Failed",commentFail:"Failed to comment",restoredMsg:"Content has been restored",onlyAdminCanReply:"Only admin can reply",uploadLoginMsg:"Please fill in your name and email to upload",counter:"{count} Comments",sortLatest:"Latest",sortOldest:"Oldest",sortBest:"Best",sortAuthor:"Author",openComment:"Open Comment",closeComment:"Close Comment",listLoadFailMsg:"Failed to load comments",listRetry:"Click to retry",loadMore:"Load More",admin:"Admin",reply:"Reply",voteUp:"Up",voteDown:"Down",voteFail:"Vote Failed",readMore:"Read More",actionConfirm:"Confirm",collapse:"Collapse",collapsed:"Collapsed",collapsedMsg:"This comment has been collapsed",expand:"Expand",approved:"Approved",pending:"Pending",pendingMsg:"Pending, visible only to commenter.",edit:"Edit",editCancel:"Cancel Edit",delete:"Delete",deleteConfirm:"Confirm",pin:"Pin",unpin:"Unpin",seconds:"seconds ago",minutes:"minutes ago",hours:"hours ago",days:"days ago",now:"just now",adminCheck:"Enter admin password:",captchaCheck:"Enter the CAPTCHA to continue:",confirm:"Confirm",cancel:"Cancel",msgCenter:"Messages",ctrlCenter:"Admin",frontend:"Frontend",backend:"Backend",loading:"Loading",loadFail:"Load Failed",editing:"Editing",editFail:"Edit Failed",deleting:"Deleting",deleteFail:"Delete Failed",reqGot:"Request got",reqAborted:"Request timed out or terminated unexpectedly"},A="ArtalkI18n",O={en:L,"en-US":L,"zh-CN":{placeholder:"键入内容...",noComment:"「此时无声胜有声」",send:"发送评论",save:"保存评论",nick:"昵称",email:"邮箱",link:"网址",emoticon:"表情",preview:"预览",image:"图片",uploadFail:"上传失败",commentFail:"评论失败",restoredMsg:"内容已自动恢复",onlyAdminCanReply:"仅管理员可评论",uploadLoginMsg:"填入你的名字邮箱才能上传哦",counter:"{count} 条评论",sortLatest:"最新",sortOldest:"最早",sortBest:"最热",sortAuthor:"作者",openComment:"打开评论",closeComment:"关闭评论",listLoadFailMsg:"无法获取评论列表数据",listRetry:"点击重新获取",loadMore:"加载更多",admin:"管理员",reply:"回复",voteUp:"赞同",voteDown:"反对",voteFail:"投票失败",readMore:"阅读更多",actionConfirm:"确认操作",collapse:"折叠",collapsed:"已折叠",collapsedMsg:"该评论已被系统或管理员折叠",expand:"展开",approved:"已审",pending:"待审",pendingMsg:"审核中,仅本人可见。",edit:"编辑",editCancel:"取消编辑",delete:"删除",deleteConfirm:"确认删除",pin:"置顶",unpin:"取消置顶",seconds:"秒前",minutes:"分钟前",hours:"小时前",days:"天前",now:"刚刚",adminCheck:"键入密码来验证管理员身份:",captchaCheck:"键入验证码继续:",confirm:"确认",cancel:"取消",msgCenter:"通知中心",ctrlCenter:"控制中心",frontend:"前端",backend:"后端",loading:"加载中",loadFail:"加载失败",editing:"修改中",editFail:"修改失败",deleting:"删除中",deleteFail:"删除失败",reqGot:"请求响应",reqAborted:"请求超时或意外终止"}};function M(t){return t=t.replace(/^([a-zA-Z]+)(-[a-zA-Z]+)?$/,((t,e,n)=>e.toLowerCase()+(n||"").toUpperCase())),O[t]?O[t]:window[A]&&window[A][t]?window[A][t]:O.en}let P="en",_=M(P);function R(t){t!==P&&(P=t,_="string"==typeof t?M(t):t)}function I(t,e={}){let n=(null==_?void 0:_[t])||t;return n=n.replace(/\{\s*(\w+?)\s*\}/g,((t,n)=>e[n]||"")),n}function U(t,e,n,i){return u(this,null,(function*(){var s,o;if(T.data.token){const t=new Headers(n.headers);t.set("Authorization",`Bearer ${T.data.token}`),n.headers=t}const a=yield function(t,e,n){var i;const s=new AbortController;null==(i=n.signal)||i.addEventListener("abort",(()=>s.abort()));let o=fetch(t,d(c({},n),{signal:s.signal}));if(e>0){const t=setTimeout((()=>s.abort()),e);o.finally((()=>{clearTimeout(t)}))}return o=o.catch((t=>{throw"AbortError"===(t||{}).name?new Error(I("reqAborted")):t})),o}(e,i||t.timeout||15e3,n),r=a.status,l=[401,400].includes(r);if(!a.ok&&!l)throw new Error(`${I("reqGot")} ${r}`);let h=yield a.json();const u=(i,s)=>{U(t,e,n).then((t=>{i(t)})).catch((t=>{s(t)}))};if((null==(s=h.data)?void 0:s.need_captcha)?h=yield new Promise(((e,n)=>{t.onNeedCheckCaptcha&&t.onNeedCheckCaptcha({data:{imgData:h.data.img_data,iframe:h.data.iframe},recall:()=>{u(e,n)},reject:()=>{n(h)}})})):((null==(o=h.data)?void 0:o.need_login)||l)&&(h=yield new Promise(((e,n)=>{t.onNeedCheckAdmin&&t.onNeedCheckAdmin({recall:()=>{u(e,n)},reject:()=>{n(h)}})}))),!h.success)throw h;return h}))}function B(t){const e=new FormData;return Object.keys(t).forEach((n=>e.append(n,String(t[n])))),e}class D{constructor(t){this.options=t}POST(t,e){return u(this,null,(function*(){return function(t,e,n){return u(this,null,(function*(){const i={method:"POST"};return n=c({site_name:t.siteName||""},n||{}),i.body=B(n),(yield U(t,e,i)).data||{}}))}(this.options,this.options.baseURL+t,e)}))}Fetch(t,e,n){return u(this,null,(function*(){return U(this.options,this.options.baseURL+t,e,n)}))}}const F={comment:class extends D{get(t,e,n,i){const s={page_key:this.options.pageKey,site_name:this.options.siteName,limit:e,offset:t};return n&&(s.flat_mode=n),T.checkHasBasicUserInfo()&&(s.name=T.data.nick,s.email=T.data.email),i&&i(s),this.POST("/get",s)}add(t){return u(this,null,(function*(){const e={name:t.nick,email:t.email,link:t.link,content:t.content,rid:t.rid,page_key:t.page_key,ua:yield $()};t.page_title&&(e.page_title=t.page_title),t.site_name&&(e.site_name=t.site_name);return(yield this.POST("/add",e)).comment}))}commentEdit(t){return u(this,null,(function*(){const e=c({},t);return(yield this.POST("/admin/comment-edit",e)).comment}))}commentDel(t,e){const n={id:String(t),site_name:e||""};return this.POST("/admin/comment-del",n)}vote(t,e){return u(this,null,(function*(){const n={target_id:t,type:e};T.checkHasBasicUserInfo()&&(n.name=T.data.nick,n.email=T.data.email);return yield this.POST("/vote",n)}))}},page:class extends D{pageGet(t,e,n){return u(this,null,(function*(){const i={site_name:t||"",offset:e||0,limit:n||15};return yield this.POST("/admin/page-get",i)}))}pageEdit(t){return u(this,null,(function*(){const e={id:t.id,key:t.key,title:t.title,admin_only:t.admin_only,site_name:t.site_name||this.options.siteName};return(yield this.POST("/admin/page-edit",e)).page}))}pageDel(t,e){const n={key:String(t),site_name:e||""};return this.POST("/admin/page-del",n)}pageFetch(t,e,n){return u(this,null,(function*(){const i={};t&&(i.id=t),e&&(i.site_name=e),n&&(i.get_status=n);return yield this.POST("/admin/page-fetch",i)}))}pv(){return u(this,null,(function*(){const t={page_key:this.options.pageKey||"",page_title:this.options.pageTitle||""};return(yield this.POST("/pv",t)).pv}))}stat(t,e,n){return u(this,null,(function*(){const i={type:t};e&&(i.page_keys=Array.isArray(e)?e.join(","):e),n&&(i.limit=n);return yield this.POST("/stat",i)}))}},site:class extends D{siteGet(){return u(this,null,(function*(){return(yield this.POST("/admin/site-get",{})).sites}))}siteAdd(t,e){return u(this,null,(function*(){const n={name:t,urls:e,site_name:""};return(yield this.POST("/admin/site-add",n)).site}))}siteEdit(t){return u(this,null,(function*(){const e={id:t.id,name:t.name||"",urls:t.urls||""};return(yield this.POST("/admin/site-edit",e)).site}))}siteDel(t,e=!1){const n={id:t,del_content:e};return this.POST("/admin/site-del",n)}export(){return u(this,null,(function*(){var t;return(null==(t=(yield this.Fetch("/admin/export",{method:"POST"},0)).data)?void 0:t.data)||""}))}},user:class extends D{login(t,e,n){return u(this,null,(function*(){const i={name:t,email:e,password:n};return yield this.POST("/login",i)}))}userGet(t,e){const n=new AbortController,i={name:t,email:e};return{req:this.Fetch("/user-get",{method:"POST",body:B(i),signal:n.signal}).then((t=>({user:t.data.user,is_login:t.data.is_login,unread:t.data.unread||[],unread_count:t.data.unread_count||0}))),abort:()=>{n.abort()}}}loginStatus(){return u(this,null,(function*(){return(yield this.POST("/login-status",{name:T.data.nick,email:T.data.email}))||{is_login:!1,is_admin:!1}}))}logout(){return u(this,null,(function*(){return this.POST("/logout")}))}markRead(t,e,n=!1){const i={comment_id:t,notify_key:e};return n&&(delete i.comment_id,delete i.notify_key,i.read_all=!0,i.name=T.data.nick,i.email=T.data.email),this.POST("/mark-read",i)}userList(t,e,n){return u(this,null,(function*(){const i={offset:t||0,limit:e||15};n&&(i.type=n);return yield this.POST("/admin/user-get",i)}))}userAdd(t,e){return u(this,null,(function*(){const n={name:t.name||"",email:t.email||"",password:e||"",link:t.link||"",is_admin:t.is_admin||!1,site_names:t.site_names_raw||"",receive_email:t.receive_email||!0,badge_name:t.badge_name||"",badge_color:t.badge_color||""};return(yield this.POST("/admin/user-add",n)).user}))}userEdit(t,e){return u(this,null,(function*(){const n={id:t.id,name:t.name||"",email:t.email||"",password:e||"",link:t.link||"",is_admin:t.is_admin||!1,site_names:t.site_names_raw||"",receive_email:t.receive_email||!0,badge_name:t.badge_name||"",badge_color:t.badge_color||""};return(yield this.POST("/admin/user-edit",n)).user}))}userDel(t){return this.POST("/admin/user-del",{id:String(t)})}},system:class extends D{conf(){return u(this,null,(function*(){const t=yield this.POST("/conf");return{frontend_conf:t.frontend_conf,version:t.version}}))}getSettings(){return u(this,null,(function*(){return yield this.POST("/admin/setting-get")}))}saveSettings(t){return u(this,null,(function*(){return yield this.POST("/admin/setting-save",{data:t})}))}version(){return u(this,null,(function*(){const t=yield fetch(`${this.options.baseURL}/version`,{method:"POST"});return yield t.json()}))}},captcha:class extends D{captchaGet(){return u(this,null,(function*(){return(yield this.POST("/captcha/refresh")).img_data||""}))}captchaCheck(t){return u(this,null,(function*(){return(yield this.POST("/captcha/check",{value:t})).img_data||""}))}captchaStatus(){return u(this,null,(function*(){return(yield this.POST("/captcha/status"))||{is_pass:!1}}))}},admin:class extends D{cacheFlushAll(){return this.POST("/admin/cache-flush",{flush_all:!0})}cacheWarmUp(){return this.POST("/admin/cache-warm",{})}},upload:class extends D{imgUpload(t){return u(this,null,(function*(){const e=B({name:T.data.nick,email:T.data.email,page_key:this.options.pageKey});e.set("file",t);const n={method:"POST",body:e};return(yield this.Fetch("/img-upload",n)).data||{}}))}}};class q{constructor(t){Object.entries(F).forEach((([e,n])=>{this[e]=new n(t)}))}}var W={"&":"&","<":"<",">":">",'"':""","'":"'"},N={"&":"&","<":"<",">":">",""":'"',"'":"'"},j=/(&|<|>|"|')/g,H=/[&<>"']/g;function K(t){return W[t]}function V(t){return N[t]}function G(t){return null==t?"":String(t).replace(H,K)}function z(t){return null==t?"":String(t).replace(j,V)}G.options=z.options={};var Q={encode:G,escape:G,decode:z,unescape:z,version:"1.0.0-browser"};var Y=function t(e){for(var n,i,s=Array.prototype.slice.call(arguments,1);s.length;)for(i in n=s.shift())n.hasOwnProperty(i)&&("[object Object]"===Object.prototype.toString.call(e[i])?e[i]=t(e[i],n[i]):e[i]=n[i]);return e},X=function(t){return"string"==typeof t?t.toLowerCase():t};function J(t,e){return t[e]=!0,t}var Z=function(t){return t.reduce(J,{})},tt={uris:Z(["background","base","cite","href","longdesc","src","usemap"])},et={voids:Z(["area","br","col","hr","img","wbr","input","base","basefont","link","meta"])},nt=Q,it=X,st=et,ot=/^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)\s*>/,at=/^<\s*\/\s*([\w:-]+)[^>]*>/,rt=/([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g,lt=/^</,ct=/^<\s*\//;var dt=Q,ht=X,ut=tt,pt=et;var mt=Y,gt=function(t,e){for(var n,i=function(){var t=[];return t.lastItem=function(){return t[t.length-1]},t}(),s=t;t;)o();function o(){n=!0,function(){"\x3c!--"===t.substr(0,4)?(i=t.indexOf("--\x3e"))>=0&&(e.comment&&e.comment(t.substring(4,i)),t=t.substring(i+3),n=!1):ct.test(t)?a(at,l):lt.test(t)&&a(ot,r);var i;!function(){if(!n)return;var i,s=t.indexOf("<");s>=0?(i=t.substring(0,s),t=t.substring(s)):(i=t,t="");e.chars&&e.chars(i)}()}();var i=t===s;s=t,i&&(t="")}function a(e,i){var s=t.match(e);s&&(t=t.substring(s[0].length),s[0].replace(e,i),n=!1)}function r(t,n,s,o){var a={},r=it(n),l=st.voids[r]||!!o;s.replace(rt,(function(t,e,n,i,s){a[e]=void 0===n&&void 0===i&&void 0===s?void 0:nt.decode(n||i||s||"")})),l||i.push(r),e.start&&e.start(r,a,l)}function l(t,n){var s,o=0,a=it(n);if(a)for(o=i.length-1;o>=0&&i[o]!==a;o--);if(o>=0){for(s=i.length-1;s>=o;s--)e.end&&e.end(i[s]);i.length=o}}l()},ft=function(t,e){var n,i=e||{};return r(),{start:function(t,e,a){var r=ht(t);if(n.ignoring)return void o(r);if(-1===(i.allowedTags||[]).indexOf(r))return void o(r);if(i.filter&&!i.filter({tag:r,attrs:e}))return void o(r);s("<"),s(r),Object.keys(e).forEach((function(t){var n=e[t],o=(i.allowedClasses||{})[r]||[],a=(i.allowedAttributes||{})[r]||[],l=ht(t);("class"===l&&-1===a.indexOf(l)?(n=n.split(" ").filter((function(t){return o&&-1!==o.indexOf(t)})).join(" ").trim()).length:-1!==a.indexOf(l)&&(!0!==ut.uris[l]||function(t){var e=t[0];if("#"===e||"/"===e)return!0;var n=t.indexOf(":");if(-1===n)return!0;var s=t.indexOf("?");if(-1!==s&&n>s)return!0;var o=t.indexOf("#");return-1!==o&&n>o||i.allowedSchemes.some(a);function a(e){return 0===t.indexOf(e+":")}}(n)))&&(s(" "),s(t),"string"==typeof n&&(s('="'),s(dt.encode(n)),s('"')))})),s(a?"/>":">")},end:function(t){var e=ht(t);-1!==(i.allowedTags||[]).indexOf(e)&&!1===n.ignoring?(s("</"),s(e),s(">")):a(e)},chars:function(t){!1===n.ignoring&&s(i.transformText?i.transformText(t):t)}};function s(e){t.push(e)}function o(t){pt.voids[t]||(!1===n.ignoring?n={ignoring:t,depth:1}:n.ignoring===t&&n.depth++)}function a(t){n.ignoring===t&&--n.depth<=0&&r()}function r(){n={ignoring:!1,depth:0}}},kt={allowedAttributes:{a:["href","name","target","title","aria-label"],iframe:["allowfullscreen","frameborder","src"],img:["src","alt","title","aria-label"]},allowedClasses:{},allowedSchemes:["http","https","mailto"],allowedTags:["a","abbr","article","b","blockquote","br","caption","code","del","details","div","em","h1","h2","h3","h4","h5","h6","hr","i","img","ins","kbd","li","main","mark","ol","p","pre","section","span","strike","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],filter:null};function yt(t,e,n){var i=[],s=!0===n?e:mt({},kt,e),o=ft(i,s);return gt(t,o),i.join("")}yt.defaults=kt;const vt=E(yt),$t={allowedClasses:{},allowedSchemes:["http","https","mailto","data"],allowedTags:["a","abbr","article","b","blockquote","br","caption","code","del","details","div","em","h1","h2","h3","h4","h5","h6","hr","i","img","ins","kbd","li","main","mark","ol","p","pre","section","span","strike","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],allowedAttributes:{"*":["title","accesskey"],a:["href","name","target","aria-label","rel"],img:["src","alt","title","atk-emoticon","aria-label"],code:["class"],span:["class","style"]},filter:t=>([["code",/^hljs\W+language-(.*)$/],["span",/^(hljs-.*)$/]].forEach((([e,n])=>{t.tag===e&&t.attrs.class&&!n.test(t.attrs.class)&&delete t.attrs.class})),"span"===t.tag&&t.attrs.style&&!/^color:(\W+)?#[0-9a-f]{3,6};?$/i.test(t.attrs.style)&&delete t.attrs.style,!0)};function wt(t){return vt(t,$t)}var bt={exports:{}};bt.exports=function(){function t(t,e){return t(e={exports:{}},e.exports),e.exports}var e=t((function(t){var e=t.exports=function(){return new RegExp("(?:"+e.line().source+")|(?:"+e.block().source+")","gm")};e.line=function(){return/(?:^|\s)\/\/(.+?)$/gm},e.block=function(){return/\/\*([\S\s]*?)\*\//gm}})),n=["23AC69","91C132","F19726","E8552D","1AAB8E","E1147F","2980C1","1BA1E6","9FA0A0","F19726","E30B20","E30B20","A3338B"];function i(t){return'<span style="color: slategray">'+t+"</span>"}return function(t,s){void 0===s&&(s={});var o=s.colors;void 0===o&&(o=n);var a=0,r={},l=new RegExp("("+/[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af\u0400-\u04FF]+|\w+/.source+"|"+/</.source+")|("+e().source+")","gmi");return t.replace(l,(function(t,e,n){if(n)return i(n);if("<"===e)return"<";var s;r[e]?s=r[e]:(s=o[a],r[e]=s);var l='<span style="color: #'+s+'">'+e+"</span>";return a=++a%o.length,l}))}}();const xt=E(bt.exports);function Ct(t){return xt(t)}function Et(){const t=new e.marked.Renderer;return t.link=St(t,t.link),t.code=Tt(),t}const St=(t,e)=>(n,i,s)=>{const o=null==n?void 0:n.startsWith(`${window.location.protocol}//${window.location.hostname}`);return e.call(t,n,i,s).replace(/^<a /,`<a target="_blank" ${o?"":'rel="noreferrer noopener nofollow"'} `)},Tt=()=>(t,e)=>{const n=e||"plaintext";let i=t;return window.hljs?n&&window.hljs.getLanguage(n)&&(i=window.hljs.highlight(n,t).value):i=Ct(t),`<pre rel="${n}">\n<code class="hljs language-${n}">${i.replace(/&/g,"&")}</code>\n</pre>`};let Lt,At=[];const Ot={pedantic:!1,gfm:!0,breaks:!0,smartLists:!0,smartypants:!0,xhtml:!1,sanitize:!1,silent:!0};function Mt(){return Lt}function Pt(t){var e;let n=null==(e=Mt())?void 0:e.parse(t);n||(n=function(t){return t.replace(/```\s*([^]+?.*?[^]+?[^]+?)```/g,((t,e)=>`<pre><code>${Ct(e)}</code></pre>`)).replace(/!\[(.*?)\]\((.*?)\)/g,((t,e,n)=>`<img src="${n}" alt="${e}" />`)).replace(/\[(.*?)\]\((.*?)\)/g,((t,e,n)=>`<a href="${n}" target="_blank">${e}</a>`)).replace(/\n/g,"<br>")}(t));let i=wt(n);return At.forEach((t=>{"function"==typeof t&&(i=t(i))})),i}class _t{constructor(t){h(this,"loading",!1),h(this,"listLastFetch"),h(this,"comments",[]),h(this,"unreads",[]),h(this,"page"),this.events=t}getLoading(){return this.loading}setLoading(t){this.loading=t}getListLastFetch(){return this.listLastFetch}setListLastFetch(t){this.listLastFetch=t}getComments(){return this.comments}fetchComments(t){this.events.trigger("list-fetch",t)}findComment(t){return this.comments.find((e=>e.id===t))}clearComments(){this.comments=[],this.events.trigger("list-loaded",this.comments)}loadComments(t){this.events.trigger("list-load",t),this.comments.push(...t),this.events.trigger("list-loaded",this.comments)}insertComment(t){this.comments.push(t),this.events.trigger("comment-inserted",t),this.events.trigger("list-loaded",this.comments)}updateComment(t){this.comments=this.comments.map((e=>e.id===t.id?t:e)),this.events.trigger("comment-updated",t),this.events.trigger("list-loaded",this.comments)}deleteComment(t){const e=this.comments.find((e=>e.id===t));if(!e)throw new Error(`Comment ${t} not found`);this.comments=this.comments.filter((e=>e.id!==t)),this.events.trigger("comment-deleted",e),this.events.trigger("list-loaded",this.comments)}getUnreads(){return this.unreads}updateUnreads(t){this.unreads=t,this.events.trigger("unreads-updated",this.unreads)}getPage(){return this.page}updatePage(t){this.page=t,this.events.trigger("page-loaded",t)}}class Rt{constructor(){h(this,"events",[])}on(t,e,n={}){this.events.push(c({name:t,handler:e},n))}off(t,e){e&&(this.events=this.events.filter((n=>!(n.name===t&&n.handler===e))))}trigger(t,e){this.events.slice(0).filter((e=>e.name===t&&"function"==typeof e.handler)).forEach((n=>{n.once&&this.off(t,n.handler),n.handler(e)}))}}const It={el:"",pageKey:"",pageTitle:"",server:"",site:"",placeholder:"",noComment:"",sendBtn:"",darkMode:!1,editorTravel:!0,flatMode:"auto",nestMax:2,nestSort:"DATE_ASC",emoticons:"https://cdn.jsdelivr.net/gh/ArtalkJS/Emoticons/grps/default.json",vote:!0,voteDown:!1,uaBadge:!0,listSort:!0,preview:!0,countEl:"#ArtalkCount",pvEl:"#ArtalkPV",gravatar:{mirror:"https://cravatar.cn/avatar/",params:"d=mp&s=240"},pagination:{pageSize:20,readMore:!0,autoLoad:!0},heightLimit:{content:300,children:400,scrollable:!1},imgUpload:!0,reqTimeout:15e3,versionCheck:!0,useBackendConf:!0,locale:"zh-CN"};function Ut(t){const e=x(It,t);if(t.el&&(e.el=t.el),"string"==typeof e.el&&e.el)try{const t=document.querySelector(e.el);if(!t)throw Error(`Target element "${e.el}" was not found.`);e.el=t}catch(n){throw console.error(n),new Error("Please check your Artalk `el` config.")}return e.server=e.server.replace(/\/$/,"").replace(/\/api\/?$/,""),e.pageKey||(e.pageKey=`${window.location.pathname}`),e.pageTitle||(e.pageTitle=`${document.title}`),"auto"===e.locale&&(e.locale=navigator.language),(!0===e.flatMode||Number(e.nestMax)<=1)&&(e.flatMode=!0),"auto"===e.flatMode&&(e.flatMode=window.matchMedia("(max-width: 768px)").matches),e}function Bt(t,e){return{baseURL:`${t.server}/api`,siteName:t.site||"",pageKey:t.pageKey||"",pageTitle:t.pageTitle||"",timeout:t.reqTimeout,onNeedCheckAdmin(t){null==e||e.checkAdmin({onSuccess:()=>{t.recall()},onCancel:()=>{t.reject()}})},onNeedCheckCaptcha(t){null==e||e.checkCaptcha({imgData:t.data.imgData,iframe:t.data.iframe,onSuccess:()=>{t.recall()},onCancel:()=>{t.reject()}})}}}It.vote=!1,It.uaBadge=!1,It.emoticons=!1;class Dt{constructor(t,e){h(this,"conf"),h(this,"data"),h(this,"$root"),h(this,"events",new Rt),this.conf=t,this.$root=e||document.createElement("div"),this.$root.classList.add("artalk"),this.$root.innerHTML="",this.data=new _t(this.events)}inject(t,e){this[t]=e}get(t){return this[t]}getApi(){return new q(Bt(this.conf,this))}getData(){return this.data}replyComment(t,e){this.editor.setReply(t,e)}editComment(t,e){this.editor.setEditComment(t,e)}fetch(t){this.data.fetchComments(t)}reload(){this.data.fetchComments({offset:0})}listGotoFirst(){this.trigger("list-goto-first")}editorShowLoading(){this.editor.showLoading()}editorHideLoading(){this.editor.hideLoading()}editorShowNotify(t,e){this.editor.showNotify(t,e)}editorResetState(){this.editor.resetState()}showSidebar(t){this.sidebarLayer.show(t)}hideSidebar(){this.sidebarLayer.hide()}checkAdmin(t){this.checkerLauncher.checkAdmin(t)}checkCaptcha(t){this.checkerLauncher.checkCaptcha(t)}on(t,e){this.events.on(t,e)}off(t,e){this.events.off(t,e)}trigger(t,e){this.events.trigger(t,e)}$t(t,e={}){return I(t,e)}setDarkMode(t){this.conf.darkMode=t,this.trigger("dark-mode-changed",t)}updateConf(t){this.conf=x(this.conf,Ut(t)),this.trigger("conf-loaded",this.conf)}getMarked(){return Mt()}}class Ft{constructor(t){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(t)}setYes(t){const e=p(`<button data-action="confirm">${I("confirm")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}setNo(t){const e=p(`<button data-action="cancel">${I("cancel")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}onBtnClick(t){return e=>{const n=t(e.currentTarget,this);void 0!==n&&!0!==n||this.$el.remove()}}}function qt(t,e){let n=t.querySelector(":scope > .atk-loading");n||(n=p('<div class="atk-loading atk-fade-in" style="display: none;">\n <div class="atk-loading-spinner">\n <svg viewBox="25 25 50 50"><circle cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10"></circle></svg>\n </div>\n </div>'),(null==e?void 0:e.transparentBg)&&(n.style.background="transparent"),t.appendChild(n)),n.style.display="";const i=n.querySelector(".atk-loading-spinner");i&&(i.style.display="none",window.setTimeout((()=>{i.style.display=""}),500))}function Wt(t){const e=t.querySelector(":scope > .atk-loading");e&&(e.style.display="none")}function Nt(t,e){t?qt(e):Wt(e)}function jt(t,e=!0,n){let i;if(n){const e=n.getBoundingClientRect();i=t.getBoundingClientRect().top-e.top+n.scrollTop,i+=m(n)/2-m(t)/2}else{const e=t.getBoundingClientRect();i=e.top+window.scrollY-(window.innerHeight/2-e.height/2)}const s={top:i,left:0,behavior:"instant"};n?n.scroll(s):window.scroll(s)}function Ht(t,e){!function(t,e,n="in"){t.classList.add(`atk-fade-${n}`);const i=()=>{t.classList.remove(`atk-fade-${n}`),t.removeEventListener("animationend",i),e&&e()};t.addEventListener("animationend",i)}(t,e,"in")}function Kt(t,e,n='<span class="atk-error-title">Artalk Error</span>'){let i=t.querySelector(".atk-error-layer");if(null===e)return void(null!==i&&i.remove());i||(i=p(`<div class="atk-error-layer">${n}<span class="atk-error-text"></span></div>`),t.appendChild(i));const s=i.querySelector(".atk-error-text");s.innerHTML="",null!==e&&(e instanceof HTMLElement?s.appendChild(e):s.innerText=e)}function Vt(t){const e=p('<div class="atk-checker-iframe-wrap"></div>'),n=p('<iframe class="atk-fade-in"></iframe>');n.style.display="none",qt(e,{transparentBg:!0}),n.src=`${t.getOpts().getIframeURLBase()||""}/api/captcha/get?t=${+new Date}`,n.onload=()=>{n.style.display="",Wt(e)},e.append(n);const i=p('<div class="atk-close-btn"><i class="atk-icon atk-icon-close"></i></div>');e.append(i),t.hideInteractInput();let s=!1;return function e(){return u(this,null,(function*(){var n;if(yield(n=1e3,new Promise((t=>{window.setTimeout((()=>{t(null)}),n)}))),s)return;let i=!1;try{i=(yield t.getApi().captcha.captchaStatus()).is_pass}catch(o){i=!1}i?t.triggerSuccess():e()}))}(),i.onclick=()=>{s=!0,t.cancel()},e}const Gt={request:(t,e)=>t.getApi().captcha.captchaCheck(e),body:t=>t.get("iframe")?Vt(t):function(t){const e=p(`<span><img class="atk-captcha-img" src="${t.get("img_data")||""}">${I("captchaCheck")}</span>`);return e.querySelector(".atk-captcha-img").onclick=()=>{const n=e.querySelector(".atk-captcha-img");t.getApi().captcha.captchaGet().then((t=>{n.setAttribute("src",t)})).catch((t=>{console.error("Failed to get captcha image ",t)}))},e}(t),onSuccess(t,e,n,i){t.set("val",n)},onError(t,e,n,i){i.querySelector(".atk-captcha-img").click(),i.querySelector('input[type="text"]').value=""}},zt={inputType:"password",request(t,e){const n={name:T.data.nick,email:T.data.email,password:e};return(()=>u(this,null,(function*(){return(yield t.getApi().user.login(n.name,n.email,n.password)).token})))()},body:t=>p(`<span>${I("adminCheck")}</span>`),onSuccess(t,e,n,i){T.update({isAdmin:!0,token:e}),t.getOpts().onReload()},onError(t,e,n,i){}};class Qt{constructor(t){this.opts=t}checkCaptcha(t){this.fire(Gt,t,(e=>{e.set("img_data",t.imgData),e.set("iframe",t.iframe)}))}checkAdmin(t){this.fire(zt,t)}fire(t,e,n){const i=this.opts.getCtx().get("layerManager").create(`checker-${(new Date).getTime()}`);i.show();const s={};let o=!1;const a={set:(t,e)=>{s[t]=e},get:t=>s[t],getOpts:()=>this.opts,getApi:()=>this.opts.getApi(),hideInteractInput:()=>{o=!0},triggerSuccess:()=>{this.close(t,i),t.onSuccess&&t.onSuccess(a,"","",r),e.onSuccess&&e.onSuccess("",d.$el)},cancel:()=>{this.close(t,i),e.onCancel&&e.onCancel()}};n&&n(a);const r=p();r.appendChild(t.body(a));const l=p(`<input id="check" type="${t.inputType||"text"}" autocomplete="off" required placeholder="">`);let c;r.appendChild(l),setTimeout((()=>l.focus()),80),l.onkeyup=t=>{"Enter"!==t.key&&13!==t.keyCode||(t.preventDefault(),i.getEl().querySelector('button[data-action="confirm"]').click())};const d=new Ft(r);d.setYes((n=>{const s=l.value.trim();c||(c=n.innerText);const o=()=>{n.innerText=c||"",n.classList.remove("error")};return n.innerText=`${I("loading")}...`,t.request(a,s).then((n=>{this.close(t,i),t.onSuccess&&t.onSuccess(a,n,s,r),e.onSuccess&&e.onSuccess(s,d.$el)})).catch((e=>{var i;i=String(e.msg||String(e)),n.innerText=i,n.classList.add("error"),t.onError&&t.onError(a,e,s,r);const c=setTimeout((()=>o()),3e3);l.onfocus=()=>{o(),clearTimeout(c)}})),!1})),d.setNo((()=>(this.close(t,i),e.onCancel&&e.onCancel(),!1))),o&&(l.style.display="none",d.$el.querySelector(".atk-layer-dialog-actions").style.display="none"),i.getEl().append(d.$el),e.onMount&&e.onMount(d.$el)}close(t,e){e.destroy()}}class Yt{constructor(t){h(this,"$el"),h(this,"conf"),this.ctx=t,this.conf=t.conf}}const Xt={$header:".atk-header",$nick:'.atk-header [name="nick"]',$email:'.atk-header [name="email"]',$link:'.atk-header [name="link"]',$textareaWrap:".atk-textarea-wrap",$textarea:".atk-textarea",$bottom:".atk-bottom",$submitBtn:".atk-send-btn",$notifyWrap:".atk-notify-wrap",$plugBtnWrap:".atk-plug-btn-wrap",$plugPanelWrap:".atk-plug-panel-wrap"};class Jt{constructor(t){this.kit=t}useBtn(t="<div></div>"){return this.$btn=p(`<span class="atk-plug-btn">${t}</span>`),this.$btn}usePanel(t="<div></div>"){return this.$panel=p(t),this.$panel}useContentTransformer(t){this.contentTransformer=t}usePanelShow(t){this.kit.useEvents().on("panel-show",(e=>{e===this&&t()}))}usePanelHide(t){this.kit.useEvents().on("panel-hide",(e=>{e===this&&t()}))}useEditorStateEffect(t,e){this.editorStateEffectWhen=t,this.editorStateEffect=e}}class Zt extends Jt{constructor(){super(...arguments),h(this,"isMoved",!1)}move(t){if(this.isMoved)return;this.isMoved=!0;const e=this.kit.useUI().$el;e.after(p('<div class="atk-editor-travel-placeholder"></div>'));const n=p("<div></div>");t.after(n),n.replaceWith(e),e.classList.add("atk-fade-in"),e.classList.add("editor-traveling")}back(){var t;this.isMoved&&(this.isMoved=!1,null==(t=this.kit.useGlobalCtx().$root.querySelector(".atk-editor-travel-placeholder"))||t.replaceWith(this.kit.useUI().$el),this.kit.useUI().$el.classList.remove("editor-traveling"))}}class te{constructor(t){h(this,"stateCurt","normal"),h(this,"stateUnmountFn",null),this.editor=t}get(){return this.stateCurt}switch(t,e){var n,i,s,o,a;if(this.stateUnmountFn&&(this.stateUnmountFn(),this.stateUnmountFn=null,null==(i=null==(n=this.editor.getPlugs())?void 0:n.get(Zt))||i.back()),"normal"!==t&&e){let n=e.$comment;this.editor.conf.flatMode||(n=n.querySelector(".atk-footer")),null==(o=null==(s=this.editor.getPlugs())?void 0:s.get(Zt))||o.move(n);const i=this.editor.ctx.conf.scrollRelativeTo&&this.editor.ctx.conf.scrollRelativeTo();jt(this.editor.getUI().$el,!0,i);const r=null==(a=this.editor.getPlugs())?void 0:a.getPlugs().find((e=>e.editorStateEffectWhen===t));r&&r.editorStateEffect&&(this.stateUnmountFn=r.editorStateEffect(e.comment))}this.stateCurt=t}}class ee extends Yt{constructor(t){super(t),h(this,"ui"),h(this,"state"),this.ui=function(){const t=p('<div class="atk-main-editor">\n <div class="atk-header">\n <input name="nick" class="atk-nick" type="text" required="required">\n <input name="email" class="atk-email" type="email" required="required">\n <input name="link" class="atk-link" type="url">\n </div>\n <div class="atk-textarea-wrap">\n <textarea class="atk-textarea"></textarea>\n </div>\n <div class="atk-plug-panel-wrap" style="display: none;"></div>\n <div class="atk-bottom">\n <div class="atk-item atk-plug-btn-wrap"></div>\n <div class="atk-item">\n <button type="button" class="atk-send-btn"></button>\n </div>\n </div>\n <div class="atk-notify-wrap"></div>\n</div>\n'),e={$el:t};return Object.entries(Xt).forEach((([n,i])=>{e[n]=t.querySelector(i)})),e}(),this.$el=this.ui.$el,this.state=new te(this)}getUI(){return this.ui}getPlugs(){return this.ctx.get("editorPlugs")}getState(){return this.state.get()}getHeaderInputEls(){return{nick:this.ui.$nick,email:this.ui.$email,link:this.ui.$link}}getContentFinal(){let t=this.getContentRaw();const e=this.getPlugs();return e&&(t=e.getTransformedContent(t)),t}getContentRaw(){return this.ui.$textarea.value||""}getContentMarked(){return Pt(this.getContentFinal())}setContent(t){var e;this.ui.$textarea.value=t,null==(e=this.getPlugs())||e.getEvents().trigger("content-updated",t)}insertContent(t){if(document.selection)this.ui.$textarea.focus(),document.selection.createRange().text=t,this.ui.$textarea.focus();else if(this.ui.$textarea.selectionStart||0===this.ui.$textarea.selectionStart){const e=this.ui.$textarea.selectionStart,n=this.ui.$textarea.selectionEnd,i=this.ui.$textarea.scrollTop;this.setContent(this.ui.$textarea.value.substring(0,e)+t+this.ui.$textarea.value.substring(n,this.ui.$textarea.value.length)),this.ui.$textarea.focus(),this.ui.$textarea.selectionStart=e+t.length,this.ui.$textarea.selectionEnd=e+t.length,this.ui.$textarea.scrollTop=i}else this.ui.$textarea.focus(),this.ui.$textarea.value+=t}focus(){this.ui.$textarea.focus()}reset(){this.setContent(""),this.resetState()}resetState(){this.state.switch("normal")}setReply(t,e){this.state.switch("reply",{comment:t,$comment:e})}setEditComment(t,e){this.state.switch("edit",{comment:t,$comment:e})}showNotify(t,e){!function(t,e,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=g(e).replace("\n","<br/>"),t.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,t,e)}showLoading(){qt(this.ui.$el)}hideLoading(){Wt(this.ui.$el)}submit(){this.ctx.trigger("editor-submit")}}class ne extends Yt{constructor(t){super(t),h(this,"layer"),h(this,"$header"),h(this,"$closeBtn"),h(this,"$iframeWrap"),h(this,"$iframe"),h(this,"firstShow",!0),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"><i class="atk-icon atk-icon-close"></i></div>\n </div>\n <div class="atk-sidebar-iframe-wrap"></div>\n </div>\n</div>\n'),this.$header=this.$el.querySelector(".atk-sidebar-header"),this.$closeBtn=this.$header.querySelector(".atk-sidebar-close"),this.$iframeWrap=this.$el.querySelector(".atk-sidebar-iframe-wrap"),this.$closeBtn.onclick=()=>{this.hide()},this.ctx.on("user-changed",(()=>{this.firstShow=!0}))}show(){return u(this,arguments,(function*(t={}){if(this.$el.style.transform="",this.initLayer(),this.layer.show(),this.authCheck({onSuccess:()=>this.show(t)}),this.firstShow)this.$iframeWrap.innerHTML="",this.$iframe=this.createIframe(t.view),this.$iframeWrap.append(this.$iframe),this.firstShow=!1;else{const t=this.$iframe,e=t.src.includes("darkMode=1");this.conf.darkMode&&!e&&this.iframeLoad(t,`${this.$iframe.src}&darkMode=1`),!this.conf.darkMode&&e&&this.iframeLoad(t,this.$iframe.src.replace("&darkMode=1",""))}setTimeout((()=>{this.$el.style.transform="translate(0, 0)"}),100),setTimeout((()=>{this.ctx.getData().updateUnreads([])}),0),this.ctx.trigger("sidebar-show")}))}hide(){var t;this.$el.style.transform="",null==(t=this.layer)||t.hide(),this.ctx.trigger("sidebar-hide")}authCheck(t){return u(this,null,(function*(){const e=yield this.ctx.getApi().user.loginStatus();e.is_admin&&!e.is_login&&(this.firstShow=!0,this.ctx.checkAdmin({onSuccess:()=>{setTimeout((()=>{t.onSuccess()}),500)},onCancel:()=>{this.hide()}}))}))}initLayer(){this.layer||(this.layer=this.ctx.get("layerManager").create("sidebar",this.$el),this.layer.setOnAfterHide((()=>{this.ctx.editorResetState()})))}createIframe(t){const e=p("<iframe></iframe>"),n=b({base:this.ctx.conf.server,path:"/sidebar/"}),i={pageKey:this.conf.pageKey,site:this.conf.site||"",user:JSON.stringify(T.data),time:+new Date};t&&(i.view=t),this.conf.darkMode&&(i.darkMode="1"),"string"==typeof this.conf.locale&&(i.locale=this.conf.locale);const s=new URLSearchParams(i);return this.iframeLoad(e,`${n}?${s.toString()}`),e}iframeLoad(t,e){t.src=e,qt(this.$iframeWrap),t.onload=()=>{Wt(this.$iframeWrap)}}}class ie{constructor(t){this.options=t}import(t){this.options.flatMode?t.forEach((e=>{this.putCommentFlatMode(e,t,"append")})):this.importCommentsNestMode(t)}insert(t){this.options.flatMode?this.insertCommentFlatMode(t):this.insertCommentNest(t)}importCommentsNestMode(t){const e=function(t,e="DATE_DESC",n=2){const i=[];t.filter((t=>0===t.rid)).forEach((e=>{const s={id:e.id,comment:e,children:[],level:1};s.parent=s,i.push(s),function e(i){const s=t.filter((t=>t.rid===i.id));0!==s.length&&(i.level>=n&&(i=i.parent),s.forEach((t=>{const n={id:t.id,comment:t,children:[],parent:i,level:i.level+1};i.children.push(n),e(n)})))}(s)}));const s=(n,i)=>{let s=n.id-i.id;return"DATE_ASC"===e?s=+new Date(n.comment.date)-+new Date(i.comment.date):"DATE_DESC"===e?s=+new Date(i.comment.date)-+new Date(n.comment.date):"SRC_INDEX"===e?s=t.indexOf(n.comment)-t.indexOf(i.comment):"VOTE_UP_DESC"===e&&(s=i.comment.vote_up-n.comment.vote_up),s};return function t(e){e.forEach((e=>{e.children=e.children.sort(s),t(e.children)}))}(i),i}(t,this.options.nestSortBy,this.options.nestMax);e.forEach((e=>{var n;const i=this.options.createCommentNode(e.comment,t);null==(n=this.options.$commentsWrap)||n.appendChild(i.getEl()),i.getRender().playFadeAnim();const s=(e,n)=>{n.children.forEach((n=>{const i=n.comment,o=this.options.createCommentNode(i,t);e.putChild(o),s(o,n)}))};s(i,e),i.getRender().checkHeightLimit()}))}putCommentFlatMode(t,e,n){var i,s;t.is_collapsed&&(t.is_allow_reply=!1);const o=this.options.createCommentNode(t,e);return t.visible&&("append"===n&&(null==(i=this.options.$commentsWrap)||i.append(o.getEl())),"prepend"===n&&(null==(s=this.options.$commentsWrap)||s.prepend(o.getEl())),o.getRender().playFadeAnim()),o.getRender().checkHeightLimit(),o}insertCommentNest(t){var e;const n=this.options.createCommentNode(t,this.options.getCommentDataList());if(0===t.rid)null==(e=this.options.$commentsWrap)||e.prepend(n.getEl());else{const e=this.options.findCommentNode(t.rid);e&&(e.putChild(n,"DATE_ASC"===this.options.nestSortBy?"append":"prepend"),n.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()})))}n.getRender().checkHeightLimit(),jt(n.getEl()),n.getRender().playFadeAnim()}insertCommentFlatMode(t){jt(this.putCommentFlatMode(t,this.options.getCommentDataList(),"prepend").getEl())}}const se=window||{},oe=navigator||{};function ae(t,e){e.forEach((({el:e,max:n,imgContains:i})=>{const s=()=>{e&&(t.scrollable?function(t){if(!t.el)return;if(t.el.classList.contains(ce))return;t.el.classList.add(ce),t.el.style.height=`${t.maxHeight}px`}({el:e,maxHeight:n}):function(t){if(!t.el)return;if(!t.maxHeight)return;if(t.el.classList.contains(re))return;t.el.classList.add(re),t.el.style.height=`${t.maxHeight}px`,t.el.style.overflow="hidden";const e=p(`<div class="atk-height-limit-btn">${I("readMore")}</span>`);e.onclick=e=>{e.stopPropagation(),le(t.el),t.postBtnClick&&t.postBtnClick(e)},t.el.append(e)}({el:e,maxHeight:n,postBtnClick:t.postExpandBtnClick}))},o=()=>{e&&m(e)>n&&s()};o(),i&&e&&function(t,e){if(!t)return;const n=t.getElementsByTagName("img");if(!n.length)return;let i=n.length;for(let s=0;s<n.length;s++)n[s].complete?i--:n[s].addEventListener("load",(()=>{i--,0===i&&e()})),0===i&&e()}(e,(()=>o()))}))}const re="atk-height-limit";function le(t){t&&t.classList.contains(re)&&(t.classList.remove(re),Array.from(t.children).forEach((t=>{t.classList.contains("atk-height-limit-btn")&&t.remove()})),t.style.height="",t.style.overflow="")}const ce="atk-height-limit-scroll";function de(t){if(t.$headerNick=t.$el.querySelector(".atk-nick"),t.data.link){const e=p('<a target="_blank" rel="noreferrer noopener nofollow"></a>');e.innerText=t.data.nick,e.href=w(t.data.link)?t.data.link:`https://${t.data.link}`,t.$headerNick.append(e)}else t.$headerNick.innerText=t.data.nick}function he(t){t.$headerBadgeWrap=t.$el.querySelector(".atk-badge-wrap"),t.$headerBadgeWrap.innerHTML="";const e=t.data.badge_name,n=t.data.badge_color;if(e){const i=p('<span class="atk-badge"></span>');i.innerText=e.replace("管理员",t.ctx.$t("admin")),i.style.backgroundColor=n||"",t.$headerBadgeWrap.append(i)}if(t.data.is_pinned){const e=p(`<span class="atk-pinned-badge">${t.ctx.$t("pin")}</span>`);t.$headerBadgeWrap.append(e)}}function ue(t){const e=t.$el.querySelector(".atk-date");e.innerText=t.comment.getDateFormatted(),e.setAttribute("data-atk-comment-date",String(+new Date(t.data.date)))}function pe(t){if(!t.ctx.conf.uaBadge&&!t.data.ip_region)return;let e=t.$header.querySelector("atk-ua-wrap");if(e||(e=p('<span class="atk-ua-wrap"></span>'),t.$header.append(e)),e.innerHTML="",t.data.ip_region){const n=p('<span class="atk-region-badge"></span>');n.innerText=t.data.ip_region,e.append(n)}if(t.ctx.conf.uaBadge){const{browser:n,os:i}=t.comment.getUserUA();if(String(n).trim()){const t=p('<span class="atk-ua ua-browser"></span>');t.innerText=n,e.append(t)}if(String(i).trim()){const t=p('<span class="atk-ua ua-os"></span>');t.innerText=i,e.append(t)}}}class me{constructor(t){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 t?{text:t}:t,this.$el.innerText=this.getText(),this.opts.adminOnly&&this.$el.setAttribute("atk-only-admin-show","")}get isMessaging(){return!!this.msgRecTimer}appendTo(t){return t.append(this.$el),this}getText(){return"string"==typeof this.opts.text?this.opts.text:this.opts.text()}setClick(t){this.$el.onclick=e=>{if(e.stopPropagation(),!this.isLoading){if(this.opts.confirm&&!this.isMessaging){const t=()=>{this.isConfirming=!1,this.$el.classList.remove("atk-btn-confirm"),this.$el.innerText=this.getText()};if(!this.isConfirming)return this.isConfirming=!0,this.$el.classList.add("atk-btn-confirm"),this.$el.innerText=this.opts.confirmText||I("actionConfirm"),void(this.confirmRecTimer=window.setTimeout((()=>t()),5e3));this.confirmRecTimer&&window.clearTimeout(this.confirmRecTimer),t()}if(this.msgRecTimer)return this.fireMsgRecTimer(),void this.clearMsgRecTimer();t()}}}updateText(t){t&&(this.opts.text=t),this.setLoading(!1),this.$el.innerText=this.getText()}setLoading(t,e){this.isLoading!==t&&(this.isLoading=t,t?(this.$el.classList.add("atk-btn-loading"),this.$el.innerText=e||`${I("loading")}...`):(this.$el.classList.remove("atk-btn-loading"),this.$el.innerText=this.getText()))}setError(t){this.setMsg(t,"atk-btn-error")}setWarn(t){this.setMsg(t,"atk-btn-warn")}setSuccess(t){this.setMsg(t,"atk-btn-success")}setMsg(t,e,n,i){this.setLoading(!1),e&&this.$el.classList.add(e),this.$el.innerText=t,this.setMsgRecTimer((()=>{this.$el.innerText=this.getText(),e&&this.$el.classList.remove(e),i&&i()}),n||2500)}setMsgRecTimer(t,e){this.fireMsgRecTimer(),this.clearMsgRecTimer(),this.msgRecTimerFunc=t,this.msgRecTimer=window.setTimeout((()=>{t(),this.clearMsgRecTimer()}),e)}fireMsgRecTimer(){this.msgRecTimerFunc&&this.msgRecTimerFunc()}clearMsgRecTimer(){this.msgRecTimer&&window.clearTimeout(this.msgRecTimer),this.msgRecTimer=void 0,this.msgRecTimerFunc=void 0}}function ge(t){t.ctx.conf.vote&&(t.voteBtnUp=new me((()=>`${t.ctx.$t("voteUp")} (${t.data.vote_up||0})`)).appendTo(t.$actions),t.voteBtnUp.setClick((()=>{t.comment.getActions().vote("up")})),t.ctx.conf.voteDown&&(t.voteBtnDown=new me((()=>`${t.ctx.$t("voteDown")} (${t.data.vote_down||0})`)).appendTo(t.$actions),t.voteBtnDown.setClick((()=>{t.comment.getActions().vote("down")}))))}function fe(t){if(!t.data.is_allow_reply)return;const e=p(`<span>${t.ctx.$t("reply")}</span>`);t.$actions.append(e),e.addEventListener("click",(e=>{e.stopPropagation(),t.cConf.onReplyBtnClick?t.cConf.onReplyBtnClick():t.ctx.replyComment(t.data,t.$el)}))}function ke(t){const e=new me({text:()=>t.data.is_collapsed?t.ctx.$t("expand"):t.ctx.$t("collapse"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("collapsed",e)}))}function ye(t){const e=new me({text:()=>t.data.is_pending?t.ctx.$t("pending"):t.ctx.$t("approved"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pending",e)}))}function ve(t){const e=new me({text:()=>t.data.is_pinned?t.ctx.$t("unpin"):t.ctx.$t("pin"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pinned",e)}))}function $e(t){const e=new me({text:t.ctx.$t("edit"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.ctx.editComment(t.data,t.$el)}))}function we(t){const e=new me({text:t.ctx.$t("delete"),confirm:!0,confirmText:t.ctx.$t("deleteConfirm"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminDelete(e)}))}const be={Avatar:function(t){const e=t.$el.querySelector(".atk-avatar"),n=p("<img />"),i=t.conf.avatarURLBuilder;if(n.src=i?i(t.data):t.comment.getGravatarURL(),t.data.link){const i=p('<a target="_blank" rel="noreferrer noopener nofollow"></a>');i.href=w(t.data.link)?t.data.link:`https://${t.data.link}`,i.append(n),e.append(i)}else e.append(n)},Header:function(t){Object.entries({renderNick:de,renderVerifyBadge:he,renderDate:ue,renderUABadge:pe}).forEach((([e,n])=>{n(t)}))},Content:function(t){if(!t.data.is_collapsed)return t.$content.innerHTML=t.comment.getContentMarked(),void t.$content.classList.remove("atk-hide","atk-collapsed");t.$content.classList.add("atk-hide","atk-type-collapsed");const e=p(`\n <div class="atk-collapsed">\n <span class="atk-text">${t.ctx.$t("collapsedMsg")}</span>\n <span class="atk-show-btn">${t.ctx.$t("expand")}</span>\n </div>`);t.$body.insertAdjacentElement("beforeend",e);const n=e.querySelector(".atk-show-btn");n.addEventListener("click",(e=>{e.stopPropagation(),t.$content.classList.contains("atk-hide")?(t.$content.innerHTML=t.comment.getContentMarked(),t.$content.classList.remove("atk-hide"),Ht(t.$content),n.innerText=t.ctx.$t("collapse")):(t.$content.innerHTML="",t.$content.classList.add("atk-hide"),n.innerText=t.ctx.$t("expand"))}))},ReplyAt:function(t){t.cConf.isFlatMode||0===t.data.rid||t.cConf.replyTo&&(t.$replyAt=p('<span class="atk-item atk-reply-at"><span class="atk-arrow"></span><span class="atk-nick"></span></span>'),t.$replyAt.querySelector(".atk-nick").innerText=`${t.cConf.replyTo.nick}`,t.$replyAt.onclick=()=>{t.comment.getActions().goToReplyComment()},t.$headerBadgeWrap.insertAdjacentElement("afterend",t.$replyAt))},ReplyTo:function(t){if(!t.cConf.isFlatMode)return;if(!t.cConf.replyTo)return;t.$replyTo=p(`\n <div class="atk-reply-to">\n <div class="atk-meta">${t.ctx.$t("reply")} <span class="atk-nick"></span>:</div>\n <div class="atk-content"></div>\n </div>`);const e=t.$replyTo.querySelector(".atk-nick");e.innerText=`@${t.cConf.replyTo.nick}`,e.onclick=()=>{t.comment.getActions().goToReplyComment()};let n=Pt(t.cConf.replyTo.content);t.cConf.replyTo.is_collapsed&&(n=`[${g(t.ctx.$t("collapsed"))}]`),t.$replyTo.querySelector(".atk-content").innerHTML=n,t.$body.prepend(t.$replyTo)},Pending:function(t){if(!t.data.is_pending)return;const e=p(`<div class="atk-pending">${t.ctx.$t("pendingMsg")}</div>`);t.$body.prepend(e)},Actions:function(t){Object.entries({renderVote:ge,renderReply:fe,renderCollapse:ke,renderModerator:ye,renderPin:ve,renderEdit:$e,renderDel:we}).forEach((([e,n])=>{n(t)}))}};class xe{constructor(t){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=t}get ctx(){return this.comment.ctx}get data(){return this.comment.getData()}get conf(){return this.comment.conf}get cConf(){return this.comment.getConf()}render(){var t;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}`),t=this,Object.entries(be).forEach((([e,n])=>{n(t)})),this.recoveryChildrenWrap(),this.$el}checkHeightLimit(){const t=this.ctx.conf.heightLimit;if(!t||!t.content||!t.children)return;const e=t.content,n=t.children;ae({postExpandBtnClick:()=>{const t=this.comment.getChildren();1===t.length&&le(t[0].getRender().$content)},scrollable:t.scrollable},[{el:this.$content,max:e,imgContains:!0},{el:this.$replyTo,max:e,imgContains:!0},{el:this.$childrenWrap,max:n,imgContains:!1}])}heightLimitRemoveForChildren(){this.$childrenWrap&&le(this.$childrenWrap)}playFadeAnim(){Ht(this.comment.getRender().$el)}playFadeAnimForBody(){Ht(this.comment.getRender().$body)}getChildrenWrap(){return this.$childrenWrap}renderChildrenWrap(){return this.$childrenWrap||(this.$childrenWrap=p('<div class="atk-comment-children"></div>'),this.$main.append(this.$childrenWrap)),this.$childrenWrap}recoveryChildrenWrap(){this.$childrenWrap&&this.$main.append(this.$childrenWrap)}setUnread(t){t?this.$el.classList.add("atk-unread"):this.$el.classList.remove("atk-unread")}setOpenable(t){t?this.$el.classList.add("atk-openable"):this.$el.classList.remove("atk-openable")}setOpenURL(t){this.setOpenable(!0),this.$el.onclick=e=>{e.preventDefault(),window.open(t),this.cConf.openEvt&&this.cConf.openEvt()}}setOpenAction(t){this.setOpenable(!0),this.$el.onclick=e=>{e.preventDefault(),t()}}}class Ce{constructor(t){h(this,"comment"),this.comment=t}get ctx(){return this.comment.ctx}get data(){return this.comment.getData()}get cConf(){return this.comment.getConf()}vote(t){const e="up"===t?this.comment.getRender().voteBtnUp:this.comment.getRender().voteBtnDown;this.ctx.getApi().comment.vote(this.data.id,`comment_${t}`).then((t=>{var e,n;this.data.vote_up=t.up,this.data.vote_down=t.down,null==(e=this.comment.getRender().voteBtnUp)||e.updateText(),null==(n=this.comment.getRender().voteBtnDown)||n.updateText()})).catch((t=>{null==e||e.setError(this.ctx.$t("voteFail")),console.log(t)}))}adminEdit(t,e){if(e.isLoading)return;e.setLoading(!0,`${this.ctx.$t("editing")}...`);const n=c({},this.data);"collapsed"===t?n.is_collapsed=!n.is_collapsed:"pending"===t?n.is_pending=!n.is_pending:"pinned"===t&&(n.is_pinned=!n.is_pinned),this.ctx.getApi().comment.commentEdit(n).then((t=>{e.setLoading(!1),this.comment.setData(t)})).catch((t=>{console.error(t),e.setError(this.ctx.$t("editFail"))}))}adminDelete(t){t.isLoading||(t.setLoading(!0,`${this.ctx.$t("deleting")}...`),this.ctx.getApi().comment.commentDel(this.data.id,this.data.site_name).then((()=>{t.setLoading(!1),this.cConf.onDelete&&this.cConf.onDelete(this.comment)})).catch((e=>{console.error(e),t.setError(this.ctx.$t("deleteFail"))})))}goToReplyComment(){const t=window.location.hash,e=`#atk-comment-${this.data.rid}`;window.location.hash=e,e===t&&window.dispatchEvent(new Event("hashchange"))}}class Ee extends Yt{constructor(t,e,n){super(t),h(this,"renderInstance"),h(this,"actionInstance"),h(this,"data"),h(this,"cConf"),h(this,"parent"),h(this,"children",[]),h(this,"nestCurt"),h(this,"nestMax"),this.nestMax=t.conf.nestMax||3,this.cConf=n,this.data=c({},e),this.data.date=this.data.date.replace(/-/g,"/"),this.parent=null,this.nestCurt=1,this.actionInstance=new Ce(this),this.renderInstance=new xe(this)}render(){const t=this.renderInstance.render();this.$el&&this.$el.replaceWith(t),this.$el=t,this.cConf.afterRender&&this.cConf.afterRender()}getActions(){return this.actionInstance}getRender(){return this.renderInstance}getData(){return this.data}setData(t){this.data=t,this.render(),this.getRender().playFadeAnimForBody()}getParent(){return this.parent}getChildren(){return this.children}getNestCurt(){return this.nestCurt}getIsRoot(){return 0===this.data.rid}getID(){return this.data.id}putChild(t,e="append"){t.parent=this,t.nestCurt=this.nestCurt+1,this.children.push(t);const n=this.getChildrenEl();"append"===e?n.append(t.getEl()):"prepend"===e&&n.prepend(t.getEl()),t.getRender().playFadeAnim(),t.getRender().checkHeightLimit()}getChildrenEl(){let t=this.getRender().getChildrenWrap();return t||(t=this.nestCurt<this.nestMax?this.getRender().renderChildrenWrap():this.parent.getChildrenEl()),t}getParents(){const t=[],e=n=>{n.parent&&(t.push(n.parent),e(n.parent))};return e(this),t}getEl(){return this.$el}getGravatarURL(){return`${(t={mirror:this.ctx.conf.gravatar.mirror,params:this.ctx.conf.gravatar.params,emailMD5:this.data.email_encrypted}).mirror.replace(/\/$/,"")}/${t.emailMD5}?${t.params.replace(/^\?/,"")}`;var t}getContentMarked(){return Pt(this.data.content)}getDateFormatted(){return v(new Date(this.data.date),this.ctx.$t)}getUserUA(){const t=function(t){const e=String(t||oe.userAgent),n={os:"",osVersion:"",engine:"",browser:"",device:"",language:"",version:""},i={Trident:e.includes("Trident")||e.includes("NET CLR"),Presto:e.includes("Presto"),WebKit:e.includes("AppleWebKit"),Gecko:e.includes("Gecko/")},s={Safari:e.includes("Safari"),Chrome:e.includes("Chrome")||e.includes("CriOS"),IE:e.includes("MSIE")||e.includes("Trident"),Edge:e.includes("Edge")||e.includes("Edg"),Firefox:e.includes("Firefox")||e.includes("FxiOS"),"Firefox Focus":e.includes("Focus"),Chromium:e.includes("Chromium"),Opera:e.includes("Opera")||e.includes("OPR"),Vivaldi:e.includes("Vivaldi"),Yandex:e.includes("YaBrowser"),Kindle:e.includes("Kindle")||e.includes("Silk/"),360:e.includes("360EE")||e.includes("360SE"),UC:e.includes("UC")||e.includes(" UBrowser"),QQBrowser:e.includes("QQBrowser"),QQ:e.includes("QQ/"),Baidu:e.includes("Baidu")||e.includes("BIDUBrowser"),Maxthon:e.includes("Maxthon"),Sogou:e.includes("MetaSr")||e.includes("Sogou"),LBBROWSER:e.includes("LBBROWSER"),"2345Explorer":e.includes("2345Explorer"),TheWorld:e.includes("TheWorld"),MIUI:e.includes("MiuiBrowser"),Quark:e.includes("Quark"),Qiyu:e.includes("Qiyu"),Wechat:e.includes("MicroMessenger"),Taobao:e.includes("AliApp(TB"),Alipay:e.includes("AliApp(AP"),Weibo:e.includes("Weibo"),Douban:e.includes("com.douban.frodo"),Suning:e.includes("SNEBUY-APP"),iQiYi:e.includes("IqiyiApp")},o={Windows:e.includes("Windows"),Linux:e.includes("Linux")||e.includes("X11"),macOS:e.includes("Macintosh"),Android:e.includes("Android")||e.includes("Adr"),Ubuntu:e.includes("Ubuntu"),FreeBSD:e.includes("FreeBSD"),Debian:e.includes("Debian"),"Windows Phone":e.includes("IEMobile")||e.includes("Windows Phone"),BlackBerry:e.includes("BlackBerry")||e.includes("RIM"),MeeGo:e.includes("MeeGo"),Symbian:e.includes("Symbian"),iOS:e.includes("like Mac OS X"),"Chrome OS":e.includes("CrOS"),WebOS:e.includes("hpwOS")},a={Mobile:e.includes("Mobi")||e.includes("iPh")||e.includes("480"),Tablet:e.includes("Tablet")||e.includes("Pad")||e.includes("Nexus 7")};a.Mobile?a.Mobile=!e.includes("iPad"):s.Chrome&&e.includes("Edg")?(s.Chrome=!1,s.Edge=!0):se.showModalDialog&&se.chrome&&(s.Chrome=!1,s[360]=!0),n.device="PC",n.language=(()=>{const t=(oe.browserLanguage||oe.language).split("-");return t[1]&&(t[1]=t[1].toUpperCase()),t.join("_")})();const r={engine:i,browser:s,os:o,device:a};Object.entries(r).forEach((([t,e])=>{Object.entries(e).forEach((([e,i])=>{!0===i&&(n[t]=e)}))}));const l={Windows:()=>{const t=e.replace(/^.*Windows NT ([\d.]+);.*$/,"$1");return{6.4:"10",6.3:"8.1",6.2:"8",6.1:"7","6.0":"Vista",5.2:"XP",5.1:"XP","5.0":"2000","10.0":"10","11.0":"11"}[t]||t},Android:()=>e.replace(/^.*Android ([\d.]+);.*$/,"$1"),iOS:()=>e.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,"."),Debian:()=>e.replace(/^.*Debian\/([\d.]+).*$/,"$1"),"Windows Phone":()=>e.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2"),macOS:()=>e.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,"."),WebOS:()=>e.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")};n.osVersion="",l[n.os]&&(n.osVersion=l[n.os](),n.osVersion===e&&(n.osVersion=""));const c={Safari:()=>e.replace(/^.*Version\/([\d.]+).*$/,"$1"),Chrome:()=>e.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1"),IE:()=>e.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1"),Edge:()=>e.replace(/^.*(Edge|Edg|Edg[A-Z]{1})\/([\d.]+).*$/,"$2"),Firefox:()=>e.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1"),"Firefox Focus":()=>e.replace(/^.*Focus\/([\d.]+).*$/,"$1"),Chromium:()=>e.replace(/^.*Chromium\/([\d.]+).*$/,"$1"),Opera:()=>e.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1"),Vivaldi:()=>e.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1"),Yandex:()=>e.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1"),Kindle:()=>e.replace(/^.*Version\/([\d.]+).*$/,"$1"),Maxthon:()=>e.replace(/^.*Maxthon\/([\d.]+).*$/,"$1"),QQBrowser:()=>e.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1"),QQ:()=>e.replace(/^.*QQ\/([\d.]+).*$/,"$1"),Baidu:()=>e.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1"),UC:()=>e.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1"),Sogou:()=>e.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1"),"2345Explorer":()=>e.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1"),TheWorld:()=>e.replace(/^.*TheWorld ([\d.]+).*$/,"$1"),MIUI:()=>e.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1"),Quark:()=>e.replace(/^.*Quark\/([\d.]+).*$/,"$1"),Qiyu:()=>e.replace(/^.*Qiyu\/([\d.]+).*$/,"$1"),Wechat:()=>e.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1"),Taobao:()=>e.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1"),Alipay:()=>e.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1"),Weibo:()=>e.replace(/^.*weibo__([\d.]+).*$/,"$1"),Douban:()=>e.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1"),Suning:()=>e.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1"),iQiYi:()=>e.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")};return n.version="",c[n.browser]&&(n.version=c[n.browser](),n.version===e&&(n.version="")),n.version.indexOf(".")&&(n.version=n.version.substring(0,n.version.indexOf("."))),"iOS"===n.os&&e.includes("iPad")?n.os="iPadOS":"Edge"!==n.browser||e.includes("Edg")?"MIUI"===n.browser?n.os="Android":"Chrome"===n.browser&&Number(n.version)>27||"Opera"===n.browser&&Number(n.version)>12||"Yandex"===n.browser?n.engine="Blink":void 0===n.browser&&(n.browser="Unknow App"):n.engine="EdgeHTML",n}(this.data.ua);return{browser:`${t.browser} ${t.version}`,os:`${t.os} ${t.osVersion}`}}getConf(){return this.cConf}}class Se{constructor(t){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=t,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(t){this.$loading.style.display=t?"":"none",this.$text.style.display=t?"none":""}showErr(t){this.setLoading(!1),this.$text.innerText=t,this.$el.classList.add("atk-err"),window.setTimeout((()=>{this.$text.innerText=this.origText,this.$el.classList.remove("atk-err")}),2e3)}update(t,e){this.offset=t,this.total=e,this.checkDisabled()}checkDisabled(){this.hasMore?this.show():this.hide()}}class Te{constructor(){h(this,"instance"),h(this,"onReachedBottom",null),h(this,"opt")}create(t){return this.opt=t,this.instance=new Se({pageSize:t.pageSize,onClick:e=>u(this,null,(function*(){t.ctx.fetch({offset:e})})),text:I("loadMore")}),t.readMoreAutoLoad&&(this.onReachedBottom=()=>{this.instance.hasMore&&!this.opt.ctx.getData().getLoading()&&this.instance.click()},this.opt.ctx.on("list-reach-bottom",this.onReachedBottom)),this.instance.$el}setLoading(t){this.instance.setLoading(t)}update(t,e){this.instance.update(t,e)}showErr(t){this.instance.showErr(t)}next(){this.instance.click()}getHasMore(){return this.instance.hasMore}getIsClearComments(t){return 0===t.offset}dispose(){this.onReachedBottom&&this.opt.ctx.off("list-reach-bottom",this.onReachedBottom),this.instance.$el.remove()}}class Le{constructor(t,e){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=t,this.opts=e,this.$el=p('<div class="atk-pagination-wrap">\n <div class="atk-pagination">\n <div class="atk-btn atk-btn-prev">Prev</div>\n <input type="text" class="atk-input" aria-label="Enter the number of page" />\n <div class="atk-btn atk-btn-next">Next</div>\n </div>\n </div>'),this.$input=this.$el.querySelector(".atk-input"),this.$input.value=`${this.page}`,this.$input.oninput=()=>this.input(),this.$input.onkeydown=t=>this.keydown(t),this.$prevBtn=this.$el.querySelector(".atk-btn-prev"),this.$nextBtn=this.$el.querySelector(".atk-btn-next"),this.$prevBtn.onclick=()=>this.prev(),this.$nextBtn.onclick=()=>this.next(),this.checkDisabled()}get pageSize(){return this.opts.pageSize}get offset(){return this.pageSize*(this.page-1)}get maxPage(){return Math.ceil(this.total/this.pageSize)}update(t,e){this.page=Math.ceil(t/this.pageSize)+1,this.total=e,this.setInput(this.page),this.checkDisabled()}setInput(t){this.$input.value=`${t}`}input(t=!1){window.clearTimeout(this.inputTimer);const e=this.$input.value.trim(),n=()=>{if(""===e)return void this.setInput(this.page);let t=Number(e);Number.isNaN(t)||t<1?this.setInput(this.page):(t>this.maxPage&&(this.setInput(this.maxPage),t=this.maxPage),this.change(t))};t?n():this.inputTimer=window.setTimeout((()=>n()),800)}prev(){const t=this.page-1;t<1||this.change(t)}next(){const t=this.page+1;t>this.maxPage||this.change(t)}getHasMore(){return this.page+1<=this.maxPage}change(t){this.page=t,this.opts.onChange(this.offset),this.setInput(t),this.checkDisabled()}checkDisabled(){this.page+1>this.maxPage?this.$nextBtn.classList.add("atk-disabled"):this.$nextBtn.classList.remove("atk-disabled"),this.page-1<1?this.$prevBtn.classList.add("atk-disabled"):this.$prevBtn.classList.remove("atk-disabled")}keydown(t){const e=t.keyCode||t.which;if(38===e){const t=Number(this.$input.value)+1;if(t>this.maxPage)return;this.setInput(t),this.input()}else if(40===e){const t=Number(this.$input.value)-1;if(t<1)return;this.setInput(t),this.input()}else 13===e&&this.input(!0)}setLoading(t){t?qt(this.$el):Wt(this.$el)}}class Ae{constructor(){h(this,"instance")}create(t){return this.instance=new Le(t.total,{pageSize:t.pageSize,onChange:e=>u(this,null,(function*(){t.ctx.editorResetState(),t.ctx.fetch({offset:e,onSuccess:()=>{t.ctx.listGotoFirst()}})}))}),this.instance.$el}setLoading(t){this.instance.setLoading(t)}update(t,e){this.instance.update(t,e)}next(){this.instance.next()}getHasMore(){return this.instance.getHasMore()}getIsClearComments(){return!0}dispose(){this.instance.$el.remove()}}function Oe(t){const e=t.getData().getListLastFetch(),n={offset:0,total:0};return e?(n.offset=e.params.offset,e.data&&(n.total=e.params.flatMode?e.data.total:e.data.total_roots),n):n}const Me=t=>{let e=null;t.on("conf-loaded",(n=>{const i=t.get("list");e&&e.dispose(),e=function(t){return t.pagination.readMore?new Te:new Ae}(n);const{offset:s,total:o}=Oe(t),a=e.create({ctx:t,pageSize:n.pagination.pageSize,total:o,readMoreAutoLoad:n.pagination.autoLoad});i.$commentsWrap.after(a),null==e||e.update(s,o)})),t.on("list-loaded",(n=>{const{offset:i,total:s}=Oe(t);null==e||e.update(i,s)})),t.on("list-fetch",(n=>{t.getData().getComments().length>0&&(null==e?void 0:e.getIsClearComments(n))&&t.getData().clearComments()})),t.on("list-error",(()=>{var t;null==(t=null==e?void 0:e.showErr)||t.call(e,I("loadFail"))}));const n=i=>{!t.getData().findComment(i)&&(null==e?void 0:e.getHasMore())&&(t.on("list-loaded",(()=>{n(i)}),{once:!0}),setTimeout((()=>{null==e||e.next()}),80))};t.on("list-goto",(t=>{n(t)})),t.on("list-fetch",(t=>{null==e||e.setLoading(!0)})),t.on("list-fetched",(({params:t})=>{null==e||e.setLoading(!1)}))};class Pe extends Yt{constructor(t){super(t),h(this,"$commentsWrap"),h(this,"commentNodes",[]),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"),Me(t),this.initCrudEvents()}getCommentsWrapEl(){return this.$commentsWrap}getCommentNodes(){return this.commentNodes}getListLayout(){return new ie({$commentsWrap:this.$commentsWrap,nestSortBy:this.ctx.conf.nestSort,nestMax:this.ctx.conf.nestMax,flatMode:this.ctx.conf.flatMode,createCommentNode:(t,e)=>{const n=function(t,e,n){var i;const s=new Ee(t,e,{isFlatMode:null==(i=t.getData().getListLastFetch())?void 0:i.params.flatMode,afterRender:()=>{t.trigger("comment-rendered",s)},onDelete:e=>{t.getData().deleteComment(e.getID())},replyTo:e.rid?n.find((t=>t.id===e.rid)):void 0});return s.render(),s}(this.ctx,t,e);return this.commentNodes.push(n),n},findCommentNode:t=>this.commentNodes.find((e=>e.getID()===t)),getCommentDataList:()=>this.ctx.getData().getComments()})}initCrudEvents(){this.ctx.on("list-load",(t=>{this.getListLayout().import(t)})),this.ctx.on("list-loaded",(t=>{0===t.length&&(this.$commentsWrap.innerHTML="")})),this.ctx.on("comment-inserted",(t=>{this.getListLayout().insert(t)})),this.ctx.on("comment-deleted",(t=>{const e=this.commentNodes.find((e=>e.getID()===t.id));e?(e.getEl().remove(),this.commentNodes=this.commentNodes.filter((e=>e.getID()!==t.id))):console.error(`comment node id=${t.id} not found`)})),this.ctx.on("comment-updated",(t=>{const e=this.commentNodes.find((e=>e.getID()===t.id));e&&e.setData(t)}))}}let _e,Re;function Ie(){return{init(){_e=document.body.style.overflow,Re=document.body.style.paddingRight},unlock(){document.body.style.overflow=_e,document.body.style.paddingRight=Re},lock(){document.body.style.overflow="hidden";const t=parseInt(window.getComputedStyle(document.body,null).getPropertyValue("padding-right"),10);document.body.style.paddingRight=`${function(){const t=document.createElement("p");t.style.width="100%",t.style.height="200px";const e=document.createElement("div");e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.visibility="hidden",e.style.width="200px",e.style.height="150px",e.style.overflow="hidden",e.appendChild(t),document.body.appendChild(e);const n=t.offsetWidth;e.style.overflow="scroll";let i=t.offsetWidth;return n===i&&(i=e.clientWidth),document.body.removeChild(e),n-i}()+t||0}px`}}}class Ue{constructor(){h(this,"$wrap"),h(this,"$mask"),h(this,"allowMaskClose",!0),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(t,e){return e||((e=document.createElement("div")).classList.add("atk-layer-item"),e.setAttribute("data-layer-name",t),e.style.display="none"),this.$wrap.appendChild(e),this.items.push(e),e}getWrap(){return this.$wrap}getMask(){return this.$mask}setMaskClose(t){this.allowMaskClose=t}show(){this.$wrap.style.display="block",this.$mask.style.display="block",this.$mask.classList.add("atk-fade-in"),this.$mask.onclick=()=>{this.allowMaskClose&&this.hide()},Ie().lock()}hide(t){if(this.items.filter((t=>t.isConnected&&"none"!==t.style.display)).length>1)return void(t&&t());const e=()=>{this.$wrap.style.display="none",this.$wrap.classList.remove("atk-fade-out"),t&&t(),Ie().unlock(),this.$wrap.onanimationend=null};this.$wrap.classList.add("atk-fade-out"),"none"!==window.getComputedStyle(this.$wrap)["animation-name"]?this.$wrap.onanimationend=()=>e():e()}}class Be{constructor(t,e,n){h(this,"$el"),h(this,"wrap"),h(this,"onAfterHide"),this.wrap=t,this.$el=this.wrap.createItem(e,n)}setOnAfterHide(t){this.onAfterHide=t}getEl(){return this.$el}show(){this.$el.style.display="",this.wrap.show()}hide(){this.wrap.hide((()=>{this.$el.style.display="none",this.onAfterHide&&this.onAfterHide()}))}destroy(){this.wrap.hide((()=>{this.$el.remove(),this.onAfterHide&&this.onAfterHide()}))}}class De{constructor(t){h(this,"wrap"),h(this,"ctx"),this.ctx=t,this.wrap=new Ue,document.body.appendChild(this.wrap.getWrap()),t.on("destroy",(()=>{this.wrap.getWrap().remove()})),Ie().init()}getEl(){return this.wrap.getWrap()}create(t,e){return new Be(this.wrap,t,e)}}const Fe={i18n(t){R(t.conf.locale),t.on("conf-loaded",(()=>{R(t.conf.locale)}))},user:t=>(T.setOnUserChanged((e=>{null==t||t.trigger("user-changed",e)})),T),layerManager:t=>new De(t),checkerLauncher:t=>new Qt({getCtx:()=>t,getApi:()=>t.getApi(),getIframeURLBase:()=>t.conf.server,onReload:()=>t.reload()}),editor(t){const e=new ee(t);return t.$root.appendChild(e.$el),e},list(t){const e=new Pe(t);return t.$root.appendChild(e.$el),e},sidebarLayer:t=>new ne(t),editorPlugs(){}};function qe(t){const e=p(`<span>${t.errMsg},${I("listLoadFailMsg")}<br/></span>`);if(t.retryFn){const n=p(`<span style="cursor:pointer;">${I("listRetry")}</span>`);n.onclick=()=>t.retryFn&&t.retryFn(),e.appendChild(n)}if(t.onOpenSidebar){const n=p('<span atk-only-admin-show> | <span style="cursor:pointer;">打开控制台</span></span>');e.appendChild(n),T.data.isAdmin||n.classList.add("atk-hide"),n.onclick=()=>t.onOpenSidebar&&t.onOpenSidebar()}Kt(t.$err,e)}function We(t){t.getApi().system.conf().then((e=>{let n={apiVersion:e.version.version};if(t.conf.useBackendConf){if(!e.frontend_conf)throw new Error("The remote backend does not respond to the frontend conf, but `useBackendConf` conf is enabled");n=c(c({},n),function(t){const e=["el","pageKey","pageTitle","server","site","darkMode"];return Object.keys(t).forEach((n=>{e.includes(n)&&delete t[n]})),t.emoticons&&"string"==typeof t.emoticons&&(t.emoticons=t.emoticons.trim(),t.emoticons.startsWith("[")||t.emoticons.startsWith("{")?t.emoticons=JSON.parse(t.emoticons):"false"===t.emoticons&&(t.emoticons=!1)),t}(e.frontend_conf))}t.conf.remoteConfModifier&&t.conf.remoteConfModifier(n),t.updateConf(n)})).catch((e=>{var n;t.updateConf({});let i="";if(null==(n=e.data)?void 0:n.err_no_site){const e={create_name:t.conf.site,create_urls:`${window.location.protocol}//${window.location.host}`};i=`sites|${JSON.stringify(e)}`}throw qe({$err:t.get("list").$el,errMsg:e.msg||String(e),errData:e.data,retryFn:()=>We(t),onOpenSidebar:()=>t.showSidebar({view:i})}),e})).then((()=>{t.conf.remoteConfModifier||t.fetch({offset:0})})).catch((()=>{}))}const Ne="ArtalkContent";class je{constructor(t){this.kit=t}reqAdd(){return u(this,null,(function*(){return yield this.kit.useApi().comment.add(c({},this.getSubmitAddParams()))}))}getSubmitAddParams(){const{nick:t,email:e,link:n}=T.data,i=this.kit.useConf();return{content:this.kit.useEditor().getContentFinal(),nick:t,email:e,link:n,rid:0,page_key:i.pageKey,page_title:i.pageTitle,site_name:i.site}}postSubmitAdd(t){this.kit.useGlobalCtx().getData().insertComment(t)}}class He extends Jt{constructor(t){super(t),h(this,"customs",[]),h(this,"defaultPreset"),this.defaultPreset=new je(this.kit);const e=()=>this.do();this.kit.useMounted((()=>{this.kit.useGlobalCtx().on("editor-submit",e)})),this.kit.useUnmounted((()=>{this.kit.useGlobalCtx().off("editor-submit",e)}))}registerCustom(t){this.customs.push(t)}do(){return u(this,null,(function*(){if(""===this.kit.useEditor().getContentFinal().trim())return void this.kit.useEditor().focus();const t=this.customs.find((t=>t.activeCond()));this.kit.useEditor().showLoading();try{let e;(null==t?void 0:t.pre)&&t.pre(),e=(null==t?void 0:t.req)?yield t.req():yield this.defaultPreset.reqAdd(),(null==t?void 0:t.post)?t.post(e):this.defaultPreset.postSubmitAdd(e)}catch(e){return console.error(e),void this.kit.useEditor().showNotify(`${I("commentFail")},${e.msg||String(e)}`,"e")}finally{this.kit.useEditor().hideLoading()}this.kit.useEditor().reset(),this.kit.useGlobalCtx().trigger("editor-submitted")}))}}class Ke extends Jt{constructor(t){super(t),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("emoticon"))})),this.kit.useUnmounted((()=>{})),this.useContentTransformer((t=>this.transEmoticonImageText(t))),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*(){qt(this.$panel),this.emoticons=yield this.handleData(this.kit.useConf().emoticons),Wt(this.$panel),this.loadingTask=null,this.isListLoaded=!0})))(),yield this.loadingTask):yield this.loadingTask)}))}handleData(t){return u(this,null,(function*(){if(!Array.isArray(t)&&["object","string"].includes(typeof t)&&(t=[t]),!Array.isArray(t))return Kt(this.$panel,"表情包数据必须为 Array/Object/String 类型"),Wt(this.$panel),[];const e=e=>{"object"==typeof e&&(e.name&&t.find((t=>t.name===e.name))||t.push(e))},n=t=>u(this,null,(function*(){yield Promise.all(t.map(((t,i)=>u(this,null,(function*(){if("object"!=typeof t||Array.isArray(t)){if(Array.isArray(t))yield n(t);else if("string"==typeof t){const i=yield this.remoteLoad(t);Array.isArray(i)?yield n(i):"object"==typeof i&&e(i)}}else e(t)})))))}));return yield n(t),t.forEach((t=>{if(this.isOwOFormat(t)){this.convertOwO(t).forEach((t=>{e(t)}))}else Array.isArray(t)&&t.forEach((t=>{e(t)}))})),t=t.filter((t=>"object"==typeof t&&!Array.isArray(t)&&!!t&&!!t.name)),this.solveNullKey(t),this.solveSameKey(t),t}))}remoteLoad(t){return u(this,null,(function*(){if(!t)return[];try{const e=yield fetch(t);return yield e.json()}catch(e){return Wt(this.$panel),Kt(this.$panel,`表情加载失败 ${String(e)}`),[]}}))}solveNullKey(t){t.forEach((t=>{t.items.forEach(((e,n)=>{e.key||(e.key=`${t.name} ${n+1}`)}))}))}solveSameKey(t){const e={};t.forEach((t=>{t.items.forEach((t=>{t.key&&""!==String(t.key).trim()&&(e[t.key]?e[t.key]++:e[t.key]=1,e[t.key]>1&&(t.key=`${t.key} ${e[t.key]}`))}))}))}isOwOFormat(t){try{return"object"==typeof t&&!!Object.values(t).length&&Array.isArray(Object.keys(Object.values(t)[0].container))&&Object.keys(Object.values(t)[0].container[0]).includes("icon")}catch(e){return!1}}convertOwO(t){const e=[];return Object.entries(t).forEach((([t,n])=>{const i={name:t,type:n.type,items:[]};n.container.forEach(((e,n)=>{const s=e.icon;if(/<(img|IMG)/.test(s)){const t=/src=["'](.*?)["']/.exec(s);t&&t.length>1&&(e.icon=t[1])}i.items.push({key:e.text||`${t} ${n+1}`,val:e.icon})})),e.push(i)})),e}initEmoticonsList(){this.$grpWrap=p('<div class="atk-grp-wrap"></div>'),this.$panel.append(this.$grpWrap),this.emoticons.forEach(((t,e)=>{const n=p('<div class="atk-grp" style="display: none;"></div>');this.$grpWrap.append(n),n.setAttribute("data-index",String(e)),n.setAttribute("data-grp-name",t.name),n.setAttribute("data-type",t.type),t.items.forEach((e=>{const i=p('<span class="atk-item"></span>');if(n.append(i),e.key&&!new RegExp(`^(${t.name})?\\s?[0-9]+$`).test(e.key)&&i.setAttribute("title",e.key),"image"===t.type){const t=document.createElement("img");t.src=e.val,t.alt=e.key,i.append(t)}else i.innerText=e.val;i.onclick=()=>{"image"===t.type?this.kit.useEditor().insertContent(`:[${e.key}]`):this.kit.useEditor().insertContent(e.val||"")}}))})),this.emoticons.length>1&&(this.$grpSwitcher=p('<div class="atk-grp-switcher"></div>'),this.$panel.append(this.$grpSwitcher),this.emoticons.forEach(((t,e)=>{const n=p("<span />");n.innerText=t.name,n.setAttribute("data-index",String(e)),n.onclick=()=>this.openGrp(e),this.$grpSwitcher.append(n)}))),this.emoticons.length>0&&this.openGrp(0)}openGrp(t){var e,n,i;Array.from(this.$grpWrap.children).forEach((e=>{const n=e;n.getAttribute("data-index")!==String(t)?n.style.display="none":n.style.display=""})),null==(e=this.$grpSwitcher)||e.querySelectorAll("span.active").forEach((t=>t.classList.remove("active"))),null==(i=null==(n=this.$grpSwitcher)?void 0:n.querySelector(`span[data-index="${t}"]`))||i.classList.add("active"),this.changeListHeight()}changeListHeight(){}transEmoticonImageText(t){return this.emoticons&&Array.isArray(this.emoticons)?(this.emoticons.forEach((e=>{"image"===e.type&&Object.entries(e.items).forEach((([e,n])=>{t=t.split(`:[${n.key}]`).join(`<img src="${n.val}" atk-emoticon="${n.key}">`)}))})),t):t}}const Ve=["png","jpg","jpeg","gif","bmp","svg","webp"];class Ge extends Jt{constructor(t){super(t),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=Ve.map((t=>`.${t}`)).join(",");const t=this.useBtn(`${I("image")}`);t.after(this.$imgUploadInput),t.onclick=()=>{const t=this.$imgUploadInput;t.onchange=()=>{(()=>{u(this,null,(function*(){if(!t.files||0===t.files.length)return;const e=t.files[0];this.uploadImg(e)}))})()},t.click()},this.kit.useConf().imgUpload||this.$btn.setAttribute("atk-only-admin-show","")}initDragImg(){const t=t=>{if(t)for(let e=0;e<t.length;e++){const n=t[e];this.uploadImg(n)}},e=t=>{t.stopPropagation(),t.preventDefault()},n=e=>{var n;const i=null==(n=e.dataTransfer)?void 0:n.files;(null==i?void 0:i.length)&&(e.preventDefault(),t(i))},i=e=>{var n;const i=null==(n=e.clipboardData)?void 0:n.files;(null==i?void 0:i.length)&&(e.preventDefault(),t(i))};this.kit.useMounted((()=>{this.kit.useUI().$textarea.addEventListener("dragover",e),this.kit.useUI().$textarea.addEventListener("drop",n),this.kit.useUI().$textarea.addEventListener("paste",i)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("dragover",e),this.kit.useUI().$textarea.removeEventListener("drop",n),this.kit.useUI().$textarea.removeEventListener("paste",i)}))}uploadImg(t){return u(this,null,(function*(){const e=/[^.]+$/.exec(t.name);if(!e||!Ve.includes(e[0]))return;if(!T.checkHasBasicUserInfo())return void this.kit.useEditor().showNotify(I("uploadLoginMsg"),"w");let n="\n";""===this.kit.useUI().$textarea.value.trim()&&(n="");const i=`${n}`;let s;this.kit.useEditor().insertContent(i);try{const e=this.kit.useConf().imgUploader;s=e?{img_url:yield e(t)}:yield this.kit.useApi().upload.imgUpload(t)}catch(o){console.error(o),this.kit.useEditor().showNotify(`${I("uploadFail")},${o.msg}`,"e")}if(s&&s.img_url){let t=s.img_url;w(t)||(t=b({base:this.kit.useConf().server,path:t})),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 ze extends Jt{constructor(t){super(t),h(this,"isPlugPanelShow",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-preview"></div>');let t=I("preview");Mt()&&(t+=' <i title="Markdown is supported"><svg class="markdown" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M14.85 3H1.15C.52 3 0 3.52 0 4.15v7.69C0 12.48.52 13 1.15 13h13.69c.64 0 1.15-.52 1.15-1.15v-7.7C16 3.52 15.48 3 14.85 3zM9 11H7V8L5.5 9.92 4 8v3H2V5h2l1.5 2L7 5h2v6zm2.99.5L9.5 8H11V5h2v3h1.5l-2.51 3.5z"></path></svg></i>'),this.useBtn(t)})),this.kit.useUnmounted((()=>{})),this.kit.useEvents().on("content-updated",(t=>{this.isPlugPanelShow&&this.updateContent()})),this.usePanelShow((()=>{this.isPlugPanelShow=!0,this.updateContent()})),this.usePanelHide((()=>{this.isPlugPanelShow=!1}))}updateContent(){this.$panel.innerHTML=this.kit.useEditor().getContentMarked()}}const Qe=[class extends Jt{constructor(t){super(t);const e=()=>{this.save()};this.kit.useMounted((()=>{const t=window.localStorage.getItem(Ne)||"";""!==t.trim()&&(this.kit.useEditor().showNotify(I("restoredMsg"),"i"),this.kit.useEditor().setContent(t)),this.kit.useEvents().on("content-updated",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("content-updated",e)}))}save(){window.localStorage.setItem(Ne,this.kit.useEditor().getContentRaw().trim())}},class extends Jt{get $inputs(){return this.kit.useEditor().getHeaderInputEls()}constructor(t){super(t);const e={},n={},i=(t,e,n)=>()=>{this.kit.useEvents().trigger(t,{field:n,$input:e})};this.kit.useMounted((()=>{Object.entries(this.$inputs).forEach((([t,s])=>{s.addEventListener("input",e[t]=i("header-input",s,t)),s.addEventListener("change",n[t]=i("header-change",s,t))}))})),this.kit.useUnmounted((()=>{Object.entries(this.$inputs).forEach((([t,i])=>{i.removeEventListener("input",e[t]),i.removeEventListener("change",n[t])}))}))}},class extends Jt{constructor(t){super(t),h(this,"query",{timer:null,abortFn:null});const e=({$input:t,field:e})=>{"edit"!==this.kit.useEditor().getState()&&(T.update({[e]:t.value.trim()}),"nick"!==e&&"email"!==e||this.fetchUserInfo())};this.kit.useMounted((()=>{Object.entries(this.kit.useEditor().getHeaderInputEls()).forEach((([t,e])=>{e.placeholder=`${I(t)}`,e.value=T.data[t]||""})),this.kit.useEvents().on("header-input",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-input",e)}))}fetchUserInfo(){T.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{req:t,abort:e}=this.kit.useApi().user.userGet(T.data.nick,T.data.email);this.query.abortFn=e,t.then((t=>this.onUserInfoFetched(t))).catch((t=>{})).finally((()=>{this.query.abortFn=null}))}),400)}onUserInfoFetched(t){var e;t.is_login||T.logout(),this.kit.useGlobalCtx().getData().updateUnreads(t.unread),T.checkHasBasicUserInfo()&&!t.is_login&&(null==(e=t.user)?void 0:e.is_admin)&&this.kit.useGlobalCtx().checkAdmin({onSuccess:()=>{}}),t.user&&t.user.link&&(this.kit.useUI().$link.value=t.user.link,T.update({link:t.user.link}))}},class extends Jt{constructor(t){super(t);const e=({field:t})=>{"link"===t&&this.onLinkInputChange()};this.kit.useMounted((()=>{this.kit.useEvents().on("header-change",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-change",e)}))}onLinkInputChange(){const t=this.kit.useUI().$link.value.trim();t&&!/^(http|https):\/\//.test(t)&&(this.kit.useUI().$link.value=`https://${t}`,T.update({link:this.kit.useUI().$link.value}))}},class extends Jt{constructor(t){super(t);const e=t=>this.onKeydown(t),n=()=>this.onInput();this.kit.useMounted((()=>{this.kit.useUI().$textarea.placeholder=this.kit.useConf().placeholder||I("placeholder"),this.kit.useUI().$textarea.addEventListener("keydown",e),this.kit.useUI().$textarea.addEventListener("input",n)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("keydown",e),this.kit.useUI().$textarea.removeEventListener("input",n)})),this.kit.useEvents().on("content-updated",(()=>{window.setTimeout((()=>{this.adaptiveHeightByContent()}),80)}))}onKeydown(t){9===(t.keyCode||t.which)&&(t.preventDefault(),this.kit.useEditor().insertContent("\t"))}onInput(){this.kit.useEvents().trigger("content-updated",this.kit.useEditor().getContentRaw())}adaptiveHeightByContent(){const t=this.kit.useUI().$textarea.offsetHeight-this.kit.useUI().$textarea.clientHeight;this.kit.useUI().$textarea.style.height="0px",this.kit.useUI().$textarea.style.height=`${this.kit.useUI().$textarea.scrollHeight+t}px`}},He,class extends Jt{constructor(t){super(t);const e=()=>{this.kit.useEditor().submit()};this.kit.useMounted((()=>{this.kit.useUI().$submitBtn.innerText=this.kit.useConf().sendBtn||I("send"),this.kit.useUI().$submitBtn.addEventListener("click",e)})),this.kit.useUnmounted((()=>{this.kit.useUI().$submitBtn.removeEventListener("click",e)}))}},Zt,class extends Jt{constructor(t){super(t),h(this,"comment"),this.useEditorStateEffect("reply",(t=>(this.setReply(t),()=>{this.cancelReply()}))),this.kit.useEvents().on("mounted",(()=>{const t=this.kit.useDeps(He);if(!t)throw Error("SubmitPlug not initialized");const e=new je(this.kit);t.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().comment.add(d(c({},e.getSubmitAddParams()),{rid:this.comment.id,page_key:this.comment.page_key,page_title:void 0,site_name:this.comment.site_name}))})),post:t=>{const n=this.kit.useConf();t.page_key!==n.pageKey&&window.open(`${t.page_url}#atk-comment-${t.id}`),e.postSubmitAdd(t)}})}))}setReply(t){const e=this.kit.useUI();e.$sendReply||(e.$sendReply=p(`<div class="atk-send-reply">${I("reply")} <span class="atk-text"></span><span class="atk-cancel">×</span></div>`),e.$sendReply.querySelector(".atk-text").innerText=`@${t.nick}`,e.$sendReply.addEventListener("click",(()=>{this.kit.useEditor().resetState()})),e.$textareaWrap.append(e.$sendReply)),this.comment=t,e.$textarea.focus()}cancelReply(){if(!this.comment)return;const t=this.kit.useUI();t.$sendReply&&(t.$sendReply.remove(),t.$sendReply=void 0),this.comment=void 0}},class extends Jt{constructor(t){super(t),h(this,"comment"),h(this,"originalSubmitBtnText","Send"),this.useEditorStateEffect("edit",(t=>(this.edit(t),()=>{this.cancelEdit()}))),this.kit.useMounted((()=>{const t=this.kit.useDeps(He);if(!t)throw Error("SubmitPlug not initialized");t.registerCustom({activeCond:()=>!!this.comment,req:()=>u(this,null,(function*(){const t={content:this.kit.useEditor().getContentFinal(),nick:this.kit.useUI().$nick.value,email:this.kit.useUI().$email.value,link:this.kit.useUI().$link.value};return yield this.kit.useApi().comment.commentEdit(c(c({},this.comment),t))})),post:t=>{this.kit.useGlobalCtx().getData().updateComment(t)}})}))}edit(t){const e=this.kit.useUI();if(!e.$editCancelBtn){const t=p(`<div class="atk-send-reply">${I("editCancel")} <span class="atk-cancel">×</span></div>`);t.onclick=()=>{this.kit.useEditor().resetState()},e.$textareaWrap.append(t),e.$editCancelBtn=t}this.comment=t,e.$header.style.display="none",e.$nick.value=t.nick||"",e.$email.value=t.email||"",e.$link.value=t.link||"",this.kit.useEditor().setContent(t.content),e.$textarea.focus(),this.updateSubmitBtnText(I("save"))}cancelEdit(){if(!this.comment)return;const t=this.kit.useUI();t.$editCancelBtn&&(t.$editCancelBtn.remove(),t.$editCancelBtn=void 0),this.comment=void 0;const{nick:e,email:n,link:i}=T.data;t.$nick.value=e,t.$email.value=n,t.$link.value=i,this.kit.useEditor().setContent(""),this.restoreSubmitBtnText(),t.$header.style.display=""}updateSubmitBtnText(t){this.originalSubmitBtnText=this.kit.useUI().$submitBtn.innerText,this.kit.useUI().$submitBtn.innerText=t}restoreSubmitBtnText(){this.kit.useUI().$submitBtn.innerText=this.originalSubmitBtnText}},class extends Jt{constructor(t){super(t);const e=()=>this.open(),n=()=>this.close();this.kit.useMounted((()=>{this.kit.useEvents().on("editor-open",e),this.kit.useEvents().on("editor-close",n)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("editor-open",e),this.kit.useEvents().off("editor-close",n)}))}open(){var t;null==(t=this.kit.useUI().$textareaWrap.querySelector(".atk-comment-closed"))||t.remove(),this.kit.useUI().$textarea.style.display="",this.kit.useUI().$bottom.style.display=""}close(){this.kit.useUI().$textareaWrap.querySelector(".atk-comment-closed")||this.kit.useUI().$textareaWrap.prepend(p(`<div class="atk-comment-closed">${I("onlyAdminCanReply")}</div>`)),T.data.isAdmin?(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,Ge,ze];class Ye{constructor(t){this.plugs=t}useEditor(){return this.plugs.editor}useGlobalCtx(){return this.plugs.editor.ctx}useConf(){return this.plugs.editor.ctx.conf}useApi(){return this.plugs.editor.ctx.getApi()}useUI(){return this.plugs.editor.getUI()}useEvents(){return this.plugs.getEvents()}useMounted(t){this.useEvents().on("mounted",t)}useUnmounted(t){this.useEvents().on("unmounted",t)}useDeps(t){return this.plugs.get(t)}}class Xe{constructor(t){h(this,"plugs",[]),h(this,"openedPlug",null),h(this,"events",new Rt),this.editor=t;let e=!1;this.editor.ctx.on("conf-loaded",(()=>{e&&this.getEvents().trigger("unmounted"),this.clear();const t=(n=this.editor.ctx.conf,[{k:Ge,v:n.imgUpload},{k:Ke,v:n.emoticons},{k:ze,v:n.preview},{k:Zt,v:n.editorTravel}].filter((t=>!t.v)).flatMap((t=>t.k)));var n;Qe.filter((e=>!t.includes(e))).forEach((t=>{const e=new Ye(this);this.plugs.push(new t(e))})),this.getEvents().trigger("mounted"),e=!0,this.loadPluginUI()})),this.events.on("panel-close",(()=>this.closePlugPanel()))}getPlugs(){return this.plugs}getEvents(){return this.events}clear(){this.plugs=[],this.events=new Rt,this.openedPlug&&this.closePlugPanel()}loadPluginUI(){this.editor.getUI().$plugPanelWrap.innerHTML="",this.editor.getUI().$plugPanelWrap.style.display="none",this.editor.getUI().$plugBtnWrap.innerHTML="",this.plugs.forEach((t=>this.loadPluginItem(t)))}loadPluginItem(t){const e=t.$btn;if(!e)return;this.editor.getUI().$plugBtnWrap.appendChild(e),!e.onclick&&(e.onclick=()=>{this.editor.getUI().$plugBtnWrap.querySelectorAll(".active").forEach((t=>t.classList.remove("active"))),t!==this.openedPlug?(this.openPlugPanel(t),e.classList.add("active")):this.closePlugPanel()});const n=t.$panel;n&&(n.style.display="none",this.editor.getUI().$plugPanelWrap.appendChild(n))}get(t){return this.plugs.find((e=>e instanceof t))}openPlugPanel(t){this.plugs.forEach((e=>{const n=e.$panel;n&&(e===t?(n.style.display="",this.events.trigger("panel-show",t)):(n.style.display="none",this.events.trigger("panel-hide",t)))})),this.editor.getUI().$plugPanelWrap.style.display="",this.openedPlug=t}closePlugPanel(){this.openedPlug&&(this.editor.getUI().$plugPanelWrap.style.display="none",this.events.trigger("panel-hide",this.openedPlug),this.openedPlug=null)}getTransformedContent(t){let e=t;return this.plugs.forEach((t=>{t.contentTransformer&&(e=t.contentTransformer(e))})),e}}const Je="2.7.0";const Ze=[t=>{t.on("list-fetch",(e=>{if(t.getData().getLoading())return;t.getData().setLoading(!0);const n=c({offset:0,limit:t.conf.pagination.pageSize,flatMode:t.conf.flatMode,paramsModifier:t.conf.listFetchParamsModifier},e);t.getData().setListLastFetch({params:n}),t.getApi().comment.get(n.offset,n.limit,n.flatMode,n.paramsModifier).then((e=>{t.getData().setListLastFetch({params:n,data:e}),t.getData().loadComments(e.comments),t.getData().updatePage(e.page),t.getData().updateUnreads(e.unread||[]),n.onSuccess&&n.onSuccess(e),t.trigger("list-fetched",{params:n,data:e})})).catch((e=>{const i={msg:e.msg||String(e),data:e.data};throw n.onError&&n.onError(i),t.trigger("list-error",i),t.trigger("list-fetched",{params:n,error:i}),e})).finally((()=>{t.getData().setLoading(!1)}))}))},t=>{t.on("list-fetch",(e=>{const n=t.get("list");0===e.offset&&Nt(!0,n.$el)})),t.on("list-fetched",(()=>{Nt(!1,t.get("list").$el)}))},t=>{t.on("comment-rendered",(e=>{if(!0===t.conf.listUnreadHighlight){const n=t.getData().getUnreads(),i=n.find((t=>t.comment_id===e.getID()));i?(e.getRender().setUnread(!0),e.getRender().setOpenAction((()=>{window.open(i.read_link),t.getData().updateUnreads(n.filter((t=>t.comment_id!==e.getID())))}))):e.getRender().setUnread(!1)}})),t.on("list-goto",(e=>{const n=f("atk_notify_key");n&&t.getApi().user.markRead(e,n).then((()=>{t.getData().updateUnreads(t.getData().getUnreads().filter((t=>t.comment_id!==e)))}))}))},t=>{let e;t.on("inited",(()=>{const n=t.get("list");e=n.$el.querySelector('[data-action="admin-close-comment"]'),e.addEventListener("click",(()=>{const e=t.getData().getPage();if(!e)throw new Error("Page data not found");e.admin_only=!e.admin_only,function(t,e){t.editorShowLoading(),t.getApi().page.pageEdit(e).then((e=>{t.getData().updatePage(e)})).catch((e=>{t.editorShowNotify(`${I("editFail")}: ${e.msg||String(e)}`,"e")})).finally((()=>{t.editorHideLoading()}))}(t,e)}))})),t.on("page-loaded",(n=>{var i,s;const o=t.get("editor");!0===(null==n?void 0:n.admin_only)?(null==(i=o.getPlugs())||i.getEvents().trigger("editor-close"),e&&(e.innerText=I("openComment"))):(null==(s=o.getPlugs())||s.getEvents().trigger("editor-open"),e&&(e.innerText=I("closeComment")))})),t.on("list-loaded",(e=>{t.editorResetState()}))},t=>{t.on("list-loaded",(()=>{(()=>{var e,n;const i=t.get("list").$el.querySelector(".atk-comment-count .atk-text");if(!i)return;const s=g(I("counter",{count:`${Number(null==(n=null==(e=t.getData().getListLastFetch())?void 0:e.data)?void 0:n.total)||0}`}));i.innerHTML=s.replace(/(\d+)/,'<span class="atk-comment-count-num">$1</span>')})()})),t.on("comment-inserted",(()=>{const e=t.getData().getListLastFetch();(null==e?void 0:e.data)&&(e.data.total+=1)})),t.on("comment-deleted",(()=>{const e=t.getData().getListLastFetch();(null==e?void 0:e.data)&&(e.data.total-=1)}))},t=>{let e=null;const n=()=>{if(!e)return;const n=t.get("user").data;if(n.nick&&n.email){e.classList.remove("atk-hide");const t=e.querySelector(".atk-text");t&&(t.innerText=n.isAdmin?I("ctrlCenter"):I("msgCenter"))}else e.classList.add("atk-hide")};t.on("conf-loaded",(()=>{const i=t.get("list");e=i.$el.querySelector('[data-action="open-sidebar"]'),e&&(e.onclick=()=>{t.showSidebar()},n())})),t.on("user-changed",(t=>{n()}))},t=>{let e=null;t.on("conf-loaded",(()=>{const n=t.get("list");e=n.$el.querySelector(".atk-unread-badge")})),t.on("unreads-updated",(t=>{var n;n=t.length||0,e&&(n>0?(e.innerText=`${Number(n||0)}`,e.style.display="block"):e.style.display="none")}))},t=>{const e=e=>{t.conf.listFetchParamsModifier=e,t.reload()},n=t=>{!function(t){const{$dropdownWrap:e,dropdownList:n}=t;if(e.querySelector(".atk-dropdown"))return;e.classList.add("atk-dropdown-wrap"),e.append(p('<span class="atk-arrow-down-icon"></span>'));let i=0;const s=(t,e,n,s)=>{s(),i=t,o.querySelectorAll(".active").forEach((t=>{t.classList.remove("active")})),e.classList.add("active"),o.style.display="none",setTimeout((()=>{o.style.display=""}),80)},o=p('<ul class="atk-dropdown atk-fade-in"></ul>');n.forEach(((t,e)=>{const n=t[0],a=t[1],r=p('<li class="atk-dropdown-item"><span></span></li>'),l=r.querySelector("span");l.innerText=n,l.onclick=()=>{s(e,r,n,a)},o.append(r),e===i&&r.classList.add("active")})),e.append(o)}({$dropdownWrap:t,dropdownList:[[I("sortLatest"),()=>{e((t=>{t.sort_by="date_desc"}))}],[I("sortBest"),()=>{e((t=>{t.sort_by="vote"}))}],[I("sortOldest"),()=>{e((t=>{t.sort_by="date_asc"}))}],[I("sortAuthor"),()=>{e((t=>{t.view_only_admin=!0}))}]]})};t.on("conf-loaded",(()=>{const e=t.get("list").$el.querySelector(".atk-comment-count");e&&(t.conf.listSort?n(e):function(t){var e,n;const{$dropdownWrap:i}=t;i.classList.remove("atk-dropdown-wrap"),null==(e=i.querySelector(".atk-arrow-down-icon"))||e.remove(),null==(n=i.querySelector(".atk-dropdown"))||n.remove()}({$dropdownWrap:e}))}))},t=>{let e=!0;const n=()=>{const n=function(){let t=Number(f("atk_comment"));if(!t){const e=window.location.hash.match(/#atk-comment-([0-9]+)/);if(!e||!e[1]||Number.isNaN(Number(e[1])))return null;t=Number(e[1])}return t||null}();n&&(t.trigger("list-goto",n),e=!0)},i=()=>{e=!1,n()};t.on("inited",(()=>{window.addEventListener("hashchange",i),t.on("list-loaded",n)})),t.on("destroy",(()=>{window.removeEventListener("hashchange",i),t.off("list-loaded",n)}));let s=0;t.on("list-goto",(n=>{if(s===n)return;const i=t.get("list").getCommentNodes().find((t=>t.getID()===n));if(!i)return;s=n,i.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()}));const o=()=>{jt(i.getEl(),!1),i.getEl().classList.remove("atk-flash-once"),window.setTimeout((()=>{i.getEl().classList.add("atk-flash-once")}),150)};e?window.setTimeout((()=>o()),350):o()}))},t=>{t.on("list-loaded",(e=>{const n=t.get("list"),i=e.length<=0;let s=n.getCommentsWrapEl().querySelector(".atk-list-no-comment");i?s||(s=p('<div class="atk-list-no-comment"></div>'),s.innerHTML=wt(n.ctx.conf.noComment||n.ctx.$t("noComment")),n.getCommentsWrapEl().appendChild(s)):null==s||s.remove()}))},t=>{t.on("conf-loaded",(()=>{const e=t.get("list").$el.querySelector(".atk-copyright");e&&(e.innerHTML=`Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${Je}">Artalk</a>`)}))},t=>{let e=null;t.on("inited",(()=>{e=window.setInterval((()=>{t.get("list").$el.querySelectorAll("[data-atk-comment-date]").forEach((e=>{const n=e.getAttribute("data-atk-comment-date");e.innerText=v(new Date(Number(n)),t.$t)}))}),3e4)})),t.on("destroy",(()=>{e&&window.clearInterval(e)}))},t=>{t.on("list-fetch",(()=>{Kt(t.get("list").$el,null)})),t.on("list-error",(e=>{qe({$err:t.get("list").$el,errMsg:e.msg,errData:e.data,retryFn:()=>t.fetch({offset:0})})}))},t=>{const e=document;let n=null;const i=()=>{null==n||n.disconnect(),n=null};t.on("list-loaded",(()=>{i();const s=t.get("list").getCommentsWrapEl().querySelector(".atk-comment-wrap:nth-last-child(3)");s&&("IntersectionObserver"in window?(s=>{n=new IntersectionObserver((([e])=>{e.isIntersecting&&(i(),t.trigger("list-reach-bottom"))}),{root:e}),n.observe(s)})(s):console.warn("IntersectionObserver api not supported"))})),t.on("destroy",(()=>{i()}))},t=>{const e=()=>{const e=t.get("list"),n=t.conf.scrollRelativeTo&&t.conf.scrollRelativeTo();(n||window).scroll({top:k(e.$el,n).top,left:0})};t.on("inited",(()=>{t.on("list-goto-first",e)})),t.on("destroy",(()=>{t.off("list-goto-first",e)}))}];function tn(t){return u(this,null,(function*(){t.countEl&&document.querySelector(t.countEl)&&en(t,{query:"page_comment",numEl:t.countEl});const e=t.pvAdd?yield t.getApi().page.pv():NaN;t.pvEl&&document.querySelector(t.pvEl)&&en(t,{query:"page_pv",numEl:t.pvEl,data:{[t.pageKey]:e}})}))}function en(t,e){return u(this,null,(function*(){let n=e.data||{},i=Array.from(document.querySelectorAll(e.numEl)).map((e=>e.getAttribute("data-page-key")||t.pageKey)).filter((t=>Number.isNaN(n[t])));if(i=[...new Set(i)],i.length>0){const s=yield t.getApi().page.stat(e.query,i);n=c(c({},n),s)}!function(t,e,n){document.querySelectorAll(t).forEach((t=>{const i=t.getAttribute("data-page-key"),s=Number(i?e[i]:n);t.innerHTML=`${s}`}))}(e.numEl,n,n[t.pageKey])}))}let nn=!1;const sn=window.matchMedia("(prefers-color-scheme: dark)");let on;function an(t,e){const n=e=>{t.forEach((t=>function(t,e){e?t.classList.add(rn):t.classList.remove(rn)}(t,e)))};"auto"===e?(on||(on=t=>n(t.matches),sn.addEventListener("change",on)),n(sn.matches)):(on&&sn.removeEventListener("change",on),n(e))}const rn="atk-dark-mode";const ln=[...[t=>{t.on("inited",(()=>{We(t)}))},t=>{!function(){try{if(!e.marked.name)return}catch(t){return}e.marked.setOptions(c({renderer:Et()},Ot)),Lt=e.marked}(),t.on("conf-loaded",(t=>{var e;t.markedReplacers&&(e=t.markedReplacers,At=e)}))},t=>{const e=t.get("editor"),n=new Xe(e);t.inject("editorPlugs",n)},t=>{const e=()=>{var e;e=t.get("user").data.isAdmin,function(t){const e=[];t.$root.querySelectorAll("[atk-only-admin-show]").forEach((t=>e.push(t)));const n=document.querySelector(".atk-sidebar");return n&&n.querySelectorAll("[atk-only-admin-show]").forEach((t=>e.push(t))),e}({$root:t.$root}).forEach((t=>{e?t.classList.remove("atk-hide"):t.classList.add("atk-hide")}))};t.on("list-loaded",(()=>{e()})),t.on("user-changed",(t=>{e()}))},...Ze,t=>{t.on("conf-loaded",(()=>{tn({getApi:()=>t.getApi(),pageKey:t.conf.pageKey,countEl:t.conf.countEl,pvEl:t.conf.pvEl,pvAdd:!0})}))},t=>{t.on("conf-loaded",(()=>{const e=t.get("list");t.conf.apiVersion&&t.conf.versionCheck&&!nn&&function(t,e,n){const i=function(t,e){const n=t.split("."),i=e.split(".");for(let s=0;s<3;s++){const t=Number(n[s]),e=Number(i[s]);if(t>e)return 1;if(e>t)return-1;if(!Number.isNaN(t)&&Number.isNaN(e))return 1;if(Number.isNaN(t)&&!Number.isNaN(e))return-1}return 0}(e,n);if(0===i)return;const s=p(`<div>请更新 Artalk ${I(i<0?"frontend":"backend")}以获得完整体验 (<a href="https://artalk.js.org/" target="_blank">帮助文档</a>)<br/><br/><span style="color: var(--at-color-meta);">当前版本:${I("frontend")} ${e} / ${I("backend")} ${n}</span><br/><br/></div>`),o=p('<span style="cursor:pointer">忽略</span>');o.onclick=()=>{Kt(t.$el.parentElement,null),nn=!0,t.ctx.fetch({offset:0})},s.append(o),Kt(t.$el.parentElement,s,'<span class="atk-warn-title">Artalk Warn</span>')}(e,Je,t.conf.apiVersion)}))},t=>{const e=()=>{an([t.$root,t.get("layerManager").getEl()],t.conf.darkMode)};t.on("inited",(()=>e())),t.on("conf-loaded",(()=>e())),t.on("dark-mode-changed",(()=>e()))}]],cn=class t{constructor(t){h(this,"conf"),h(this,"ctx"),h(this,"$root"),h(this,"plugins",[...ln]),this.conf=Ut(t),this.conf.el instanceof HTMLElement&&(this.$root=this.conf.el),this.ctx=new Dt(this.conf,this.$root),Object.entries(Fe).forEach((([t,e])=>{const n=e(this.ctx);n&&this.ctx.inject(t,n)})),this.plugins.forEach((t=>{"function"==typeof t&&t(this.ctx)})),this.ctx.trigger("inited")}update(t){return this.ctx.updateConf(t),this}reload(){this.ctx.reload()}destroy(){this.ctx.trigger("destroy"),this.$root.remove()}on(t,e){this.ctx.on(t,e)}off(t,e){this.ctx.off(t,e)}trigger(t,e){this.ctx.trigger(t,e)}setDarkMode(t){this.ctx.setDarkMode(t)}static init(e){return new t(e)}static use(t){ln.includes(t)||ln.push(t)}static loadCountWidget(t){const e=Ut(t);tn({getApi:()=>new q(Bt(e)),pageKey:e.pageKey,countEl:e.countEl,pvEl:e.pvEl,pvAdd:!1})}};h(cn,"defaults",It);let dn=cn;const hn=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));return t.ArtalkType=hn,t.default=dn,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),t}({},marked);
|
|
1
|
+
var Artalk=function(t,e){"use strict";var n=Object.defineProperty,i=Object.defineProperties,s=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,l=(t,e,i)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,c=(t,e)=>{for(var n in e||(e={}))r.call(e,n)&&l(t,n,e[n]);if(o)for(var n of o(e))a.call(e,n)&&l(t,n,e[n]);return t},d=(t,e)=>i(t,s(e)),h=(t,e,n)=>(l(t,"symbol"!=typeof e?e+"":e,n),n),u=(t,e,n)=>new Promise(((i,s)=>{var o=t=>{try{a(n.next(t))}catch(e){s(e)}},r=t=>{try{a(n.throw(t))}catch(e){s(e)}},a=t=>t.done?i(t.value):Promise.resolve(t.value).then(o,r);a((n=n.apply(t,e)).next())}));function p(t=""){const e=document.createElement("div");return e.innerHTML=t.trim(),e.firstElementChild||e}function m(t){return parseFloat(getComputedStyle(t,null).height.replace("px",""))}function g(t){const e=document.createElement("div");e.innerText=t;return e.innerHTML}function f(t){const e=RegExp(`[?&]${t}=([^&]*)`).exec(window.location.search);return e&&decodeURIComponent(e[1].replace(/\+/g," "))}function k(t,e){const n=t=>{const e=t.getBoundingClientRect(),n=window.pageXOffset||document.documentElement.scrollLeft,i=window.pageYOffset||document.documentElement.scrollTop;return{top:e.top+i,left:e.left+n}},i=n(t);if(!e)return i;const s=n(e);return{top:i.top-s.top,left:i.left-s.left}}function v(t,e){let n=t.toString();for(;n.length<e;)n=`0${n}`;return n}function y(t,e=(t=>t)){try{const n=t.getTime(),i=(new Date).getTime()-n,s=Math.floor(i/864e5);if(0===s){const t=i%864e5,n=Math.floor(t/36e5);if(0===n){const n=t%36e5,i=Math.floor(n/6e4);if(0===i){const t=n%6e4,i=Math.round(t/1e3);return i<10?e("now"):`${i} ${e("seconds")}`}return`${i} ${e("minutes")}`}return`${n} ${e("hours")}`}return s<0?e("now"):s<8?`${s} ${e("days")}`:function(t){const e=v(t.getDate(),2),n=v(t.getMonth()+1,2);return`${v(t.getFullYear(),2)}-${n}-${e}`}(t)}catch(n){return console.error(n)," - "}}function $(){return u(this,null,(function*(){const t=navigator.userAgent;if(!navigator.userAgentData||!navigator.userAgentData.getHighEntropyValues)return t;const e=navigator.userAgentData;let n=null;try{n=yield e.getHighEntropyValues(["platformVersion"])}catch(s){return console.error(s),t}const i=Number(n.platformVersion.split(".")[0]);return"Windows"===e.platform&&i>=13?t.replace(/Windows NT 10.0/,"Windows NT 11.0"):"macOS"===e.platform&&i>=11?t.replace(/(Mac OS X \d+_\d+_\d+|Mac OS X)/,`Mac OS X ${n.platformVersion.replace(/\./g,"_")}`):t}))}function w(t){let e;try{e=new URL(t)}catch(n){return!1}return"http:"===e.protocol||"https:"===e.protocol}function b(t){return e=t.base,n=t.path,`${e.replace(/\/$/,"")}/${n.replace(/^\//,"")}`;var e,n}function x(t,e){const n=t=>t&&"object"==typeof t;return n(t)&&n(e)?(Object.keys(e).forEach((i=>{const s=t[i],o=e[i];Array.isArray(s)&&Array.isArray(o)?t[i]=s.concat(o):n(s)&&n(o)?t[i]=x(c({},s),o):t[i]=o})),t):e}var C="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function E(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}!function(){function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function n(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e)}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,e){return(o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function a(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return a(t)}function c(t){var e=r();return function(){var n,i=s(t);if(e){var o=s(this).constructor;n=Reflect.construct(i,arguments,o)}else n=i.apply(this,arguments);return l(this,n)}}function d(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=s(t)););return t}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var i=d(t,e);if(i){var s=Object.getOwnPropertyDescriptor(i,e);return s.get?s.get.call(arguments.length<3?t:n):s.value}},h.apply(this,arguments)}var u=function(){function e(){t(this,e),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return n(e,[{key:"addEventListener",value:function(t,e,n){t in this.listeners||(this.listeners[t]=[]),this.listeners[t].push({callback:e,options:n})}},{key:"removeEventListener",value:function(t,e){if(t in this.listeners)for(var n=this.listeners[t],i=0,s=n.length;i<s;i++)if(n[i].callback===e)return void n.splice(i,1)}},{key:"dispatchEvent",value:function(t){if(t.type in this.listeners){for(var e=this.listeners[t.type].slice(),n=0,i=e.length;n<i;n++){var s=e[n];try{s.callback.call(this,t)}catch(o){Promise.resolve().then((function(){throw o}))}s.options&&s.options.once&&this.removeEventListener(t.type,s.callback)}return!t.defaultPrevented}}}]),e}(),p=function(e){i(r,e);var o=c(r);function r(){var e;return t(this,r),(e=o.call(this)).listeners||u.call(a(e)),Object.defineProperty(a(e),"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(a(e),"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(a(e),"reason",{value:void 0,writable:!0,configurable:!0}),e}return n(r,[{key:"toString",value:function(){return"[object AbortSignal]"}},{key:"dispatchEvent",value:function(t){"abort"===t.type&&(this.aborted=!0,"function"==typeof this.onabort&&this.onabort.call(this,t)),h(s(r.prototype),"dispatchEvent",this).call(this,t)}}]),r}(u),m=function(){function e(){t(this,e),Object.defineProperty(this,"signal",{value:new p,writable:!0,configurable:!0})}return n(e,[{key:"abort",value:function(t){var e;try{e=new Event("abort")}catch(i){"undefined"!=typeof document?document.createEvent?(e=document.createEvent("Event")).initEvent("abort",!1,!1):(e=document.createEventObject()).type="abort":e={type:"abort",bubbles:!1,cancelable:!1}}var n=t;if(void 0===n)if("undefined"==typeof document)(n=new Error("This operation was aborted")).name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(s){(n=new Error("This operation was aborted")).name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(e)}},{key:"toString",value:function(){return"[object AbortController]"}}]),e}();function g(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):"function"==typeof t.Request&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function f(t){"function"==typeof t&&(t={fetch:t});var e=t,n=e.fetch,i=e.Request,s=void 0===i?n.Request:i,o=e.AbortController,r=e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,a=void 0!==r&&r;if(!g({fetch:n,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:a}))return{fetch:n,Request:l};var l=s;(l&&!l.prototype.hasOwnProperty("signal")||a)&&((l=function(t,e){var n;e&&e.signal&&(n=e.signal,delete e.signal);var i=new s(t,e);return n&&Object.defineProperty(i,"signal",{writable:!1,enumerable:!1,configurable:!0,value:n}),i}).prototype=s.prototype);var c=n;return{fetch:function(t,e){var n=l&&l.prototype.isPrototypeOf(t)?t.signal:e?e.signal:void 0;if(n){var i;try{i=new DOMException("Aborted","AbortError")}catch(o){(i=new Error("Aborted")).name="AbortError"}if(n.aborted)return Promise.reject(i);var s=new Promise((function(t,e){n.addEventListener("abort",(function(){return e(i)}),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([s,c(t,e)])}return c(t,e)},Request:l}}"undefined"!=typeof Symbol&&Symbol.toStringTag&&(m.prototype[Symbol.toStringTag]="AbortController",p.prototype[Symbol.toStringTag]="AbortSignal"),function(t){if(g(t))if(t.fetch){var e=f(t),n=e.fetch,i=e.Request;t.fetch=n,t.Request=i,Object.defineProperty(t,"AbortController",{writable:!0,enumerable:!1,configurable:!0,value:m}),Object.defineProperty(t,"AbortSignal",{writable:!0,enumerable:!1,configurable:!0,value:p})}else console.warn("fetch() is not available, cannot install abortcontroller-polyfill")}("undefined"!=typeof self?self:C)}();const S={placeholder:"Leave a comment",noComment:"No Comment",send:"Send",save:"Save",nick:"Nickname",email:"Email",link:"Website",emoticon:"Emoji",preview:"Preview",image:"Image",uploadFail:"Upload Failed",commentFail:"Failed to comment",restoredMsg:"Content has been restored",onlyAdminCanReply:"Only admin can reply",uploadLoginMsg:"Please fill in your name and email to upload",counter:"{count} Comments",sortLatest:"Latest",sortOldest:"Oldest",sortBest:"Best",sortAuthor:"Author",openComment:"Open Comment",closeComment:"Close Comment",listLoadFailMsg:"Failed to load comments",listRetry:"Click to retry",loadMore:"Load More",admin:"Admin",reply:"Reply",voteUp:"Up",voteDown:"Down",voteFail:"Vote Failed",readMore:"Read More",actionConfirm:"Confirm",collapse:"Collapse",collapsed:"Collapsed",collapsedMsg:"This comment has been collapsed",expand:"Expand",approved:"Approved",pending:"Pending",pendingMsg:"Pending, visible only to commenter.",edit:"Edit",editCancel:"Cancel Edit",delete:"Delete",deleteConfirm:"Confirm",pin:"Pin",unpin:"Unpin",seconds:"seconds ago",minutes:"minutes ago",hours:"hours ago",days:"days ago",now:"just now",adminCheck:"Enter admin password:",captchaCheck:"Enter the CAPTCHA to continue:",confirm:"Confirm",cancel:"Cancel",msgCenter:"Messages",ctrlCenter:"Admin",frontend:"Frontend",backend:"Backend",loading:"Loading",loadFail:"Load Failed",editing:"Editing",editFail:"Edit Failed",deleting:"Deleting",deleteFail:"Delete Failed",reqGot:"Request got",reqAborted:"Request timed out or terminated unexpectedly",updateMsg:"Please update Artalk {name} to get the full experience",currentVersion:"Current Version",ignore:"Ignore",open:"Open"},T="ArtalkI18n",L={en:S,"en-US":S,"zh-CN":{placeholder:"键入内容...",noComment:"「此时无声胜有声」",send:"发送评论",save:"保存评论",nick:"昵称",email:"邮箱",link:"网址",emoticon:"表情",preview:"预览",image:"图片",uploadFail:"上传失败",commentFail:"评论失败",restoredMsg:"内容已自动恢复",onlyAdminCanReply:"仅管理员可评论",uploadLoginMsg:"填入你的名字邮箱才能上传哦",counter:"{count} 条评论",sortLatest:"最新",sortOldest:"最早",sortBest:"最热",sortAuthor:"作者",openComment:"打开评论",closeComment:"关闭评论",listLoadFailMsg:"无法获取评论列表数据",listRetry:"点击重新获取",loadMore:"加载更多",admin:"管理员",reply:"回复",voteUp:"赞同",voteDown:"反对",voteFail:"投票失败",readMore:"阅读更多",actionConfirm:"确认操作",collapse:"折叠",collapsed:"已折叠",collapsedMsg:"该评论已被系统或管理员折叠",expand:"展开",approved:"已审",pending:"待审",pendingMsg:"审核中,仅本人可见。",edit:"编辑",editCancel:"取消编辑",delete:"删除",deleteConfirm:"确认删除",pin:"置顶",unpin:"取消置顶",seconds:"秒前",minutes:"分钟前",hours:"小时前",days:"天前",now:"刚刚",adminCheck:"键入密码来验证管理员身份:",captchaCheck:"键入验证码继续:",confirm:"确认",cancel:"取消",msgCenter:"通知中心",ctrlCenter:"控制中心",frontend:"前端",backend:"后端",loading:"加载中",loadFail:"加载失败",editing:"修改中",editFail:"修改失败",deleting:"删除中",deleteFail:"删除失败",reqGot:"请求响应",reqAborted:"请求超时或意外终止",updateMsg:"请更新 Artalk {name} 以获得完整体验",currentVersion:"当前版本",ignore:"忽略",open:"打开"}};function A(t){return t=t.replace(/^([a-zA-Z]+)(-[a-zA-Z]+)?$/,((t,e,n)=>e.toLowerCase()+(n||"").toUpperCase())),L[t]?L[t]:window[T]&&window[T][t]?window[T][t]:L.en}let M="en",O=A(M);function P(t){t!==M&&(M=t,O="string"==typeof t?A(t):t)}function _(t,e={}){let n=(null==O?void 0:O[t])||t;return n=n.replace(/\{\s*(\w+?)\s*\}/g,((t,n)=>e[n]||"")),n}function U(t,e,n,i){return u(this,null,(function*(){var s,o;if(t.apiToken){const e=new Headers(n.headers);e.set("Authorization",`Bearer ${t.apiToken}`),n.headers=e}const r=yield function(t,e,n){var i;const s=new AbortController;null==(i=n.signal)||i.addEventListener("abort",(()=>s.abort()));let o=fetch(t,d(c({},n),{signal:s.signal}));if(e>0){const t=setTimeout((()=>s.abort()),e);o.finally((()=>{clearTimeout(t)}))}return o=o.catch((t=>{throw"AbortError"===(t||{}).name?new Error(_("reqAborted")):t})),o}(e,i||t.timeout||15e3,n),a=r.status,l=[401,400].includes(a);if(!r.ok&&!l)throw new Error(`${_("reqGot")} ${a}`);let h=yield r.json();const u=(i,s)=>{U(t,e,n).then((t=>{i(t)})).catch((t=>{s(t)}))};if((null==(s=h.data)?void 0:s.need_captcha)?h=yield new Promise(((e,n)=>{t.onNeedCheckCaptcha&&t.onNeedCheckCaptcha({data:{imgData:h.data.img_data,iframe:h.data.iframe},recall:()=>{u(e,n)},reject:()=>{n(h)}})})):((null==(o=h.data)?void 0:o.need_login)||l)&&(h=yield new Promise(((e,n)=>{t.onNeedCheckAdmin&&t.onNeedCheckAdmin({recall:()=>{u(e,n)},reject:()=>{n(h)}})}))),!h.success)throw h;return h}))}function I(t){const e=new FormData;return Object.keys(t).forEach((n=>e.append(n,String(t[n])))),e}class R{constructor(t){this.options=t}POST(t,e){return u(this,null,(function*(){return function(t,e,n){return u(this,null,(function*(){const i={method:"POST"};return n=c({site_name:t.siteName||""},n||{}),i.body=I(n),(yield U(t,e,i)).data||{}}))}(this.options,this.options.baseURL+t,e)}))}Fetch(t,e,n){return u(this,null,(function*(){return U(this.options,this.options.baseURL+t,e,n)}))}withUserInfo(t){const e=this.options.userInfo;return(null==e?void 0:e.name)&&(t.name=e.name),(null==e?void 0:e.email)&&(t.email=e.email),t}}const D={comment:class extends R{get(t,e,n,i){const s={page_key:this.options.pageKey,site_name:this.options.siteName,limit:e,offset:t};return n&&(s.flat_mode=n),this.withUserInfo(s),i&&i(s),this.POST("/get",s)}add(t){return u(this,null,(function*(){const e={name:t.nick,email:t.email,link:t.link,content:t.content,rid:t.rid,page_key:t.page_key,ua:yield $()};t.page_title&&(e.page_title=t.page_title),t.site_name&&(e.site_name=t.site_name);return(yield this.POST("/add",e)).comment}))}commentEdit(t){return u(this,null,(function*(){const e=c({},t);return(yield this.POST("/admin/comment-edit",e)).comment}))}commentDel(t,e){const n={id:String(t),site_name:e||""};return this.POST("/admin/comment-del",n)}vote(t,e){return u(this,null,(function*(){const n={target_id:t,type:e};this.withUserInfo(n);return yield this.POST("/vote",n)}))}},page:class extends R{pageGet(t,e,n){return u(this,null,(function*(){const i={site_name:t||"",offset:e||0,limit:n||15};return yield this.POST("/admin/page-get",i)}))}pageEdit(t){return u(this,null,(function*(){const e={id:t.id,key:t.key,title:t.title,admin_only:t.admin_only,site_name:t.site_name||this.options.siteName};return(yield this.POST("/admin/page-edit",e)).page}))}pageDel(t,e){const n={key:String(t),site_name:e||""};return this.POST("/admin/page-del",n)}pageFetch(t,e,n){return u(this,null,(function*(){const i={};t&&(i.id=t),e&&(i.site_name=e),n&&(i.get_status=n);return yield this.POST("/admin/page-fetch",i)}))}pv(){return u(this,null,(function*(){const t={page_key:this.options.pageKey||"",page_title:this.options.pageTitle||""};return(yield this.POST("/pv",t)).pv}))}stat(t,e,n){return u(this,null,(function*(){const i={type:t};e&&(i.page_keys=Array.isArray(e)?e.join(","):e),n&&(i.limit=n);return yield this.POST("/stat",i)}))}},site:class extends R{siteGet(){return u(this,null,(function*(){return(yield this.POST("/admin/site-get",{})).sites}))}siteAdd(t,e){return u(this,null,(function*(){const n={name:t,urls:e,site_name:""};return(yield this.POST("/admin/site-add",n)).site}))}siteEdit(t){return u(this,null,(function*(){const e={id:t.id,name:t.name||"",urls:t.urls||""};return(yield this.POST("/admin/site-edit",e)).site}))}siteDel(t,e=!1){const n={id:t,del_content:e};return this.POST("/admin/site-del",n)}export(){return u(this,null,(function*(){var t;return(null==(t=(yield this.Fetch("/admin/export",{method:"POST"},0)).data)?void 0:t.data)||""}))}},user:class extends R{login(t,e,n){return u(this,null,(function*(){const i={name:t,email:e,password:n};return yield this.POST("/login",i)}))}userGet(t,e){const n=new AbortController,i={name:t,email:e};return{req:this.Fetch("/user-get",{method:"POST",body:I(i),signal:n.signal}).then((t=>({user:t.data.user,is_login:t.data.is_login,unread:t.data.unread||[],unread_count:t.data.unread_count||0}))),abort:()=>{n.abort()}}}loginStatus(){return u(this,null,(function*(){return(yield this.POST("/login-status",this.withUserInfo({})))||{is_login:!1,is_admin:!1}}))}logout(){return u(this,null,(function*(){return this.POST("/logout")}))}markRead(t,e,n=!1){const i={comment_id:t,notify_key:e};return n&&(delete i.comment_id,delete i.notify_key,i.read_all=!0,this.withUserInfo(i)),this.POST("/mark-read",i)}userList(t,e,n){return u(this,null,(function*(){const i={offset:t||0,limit:e||15};n&&(i.type=n);return yield this.POST("/admin/user-get",i)}))}userAdd(t,e){return u(this,null,(function*(){const n={name:t.name||"",email:t.email||"",password:e||"",link:t.link||"",is_admin:t.is_admin||!1,site_names:t.site_names_raw||"",receive_email:t.receive_email||!0,badge_name:t.badge_name||"",badge_color:t.badge_color||""};return(yield this.POST("/admin/user-add",n)).user}))}userEdit(t,e){return u(this,null,(function*(){const n={id:t.id,name:t.name||"",email:t.email||"",password:e||"",link:t.link||"",is_admin:t.is_admin||!1,site_names:t.site_names_raw||"",receive_email:t.receive_email||!0,badge_name:t.badge_name||"",badge_color:t.badge_color||""};return(yield this.POST("/admin/user-edit",n)).user}))}userDel(t){return this.POST("/admin/user-del",{id:String(t)})}},system:class extends R{conf(){return u(this,null,(function*(){const t=yield this.POST("/conf");return{frontend_conf:t.frontend_conf,version:t.version}}))}getSettings(){return u(this,null,(function*(){return yield this.POST("/admin/setting-get")}))}saveSettings(t){return u(this,null,(function*(){return yield this.POST("/admin/setting-save",{data:t})}))}version(){return u(this,null,(function*(){const t=yield fetch(`${this.options.baseURL}/version`,{method:"POST"});return yield t.json()}))}},captcha:class extends R{captchaGet(){return u(this,null,(function*(){return(yield this.POST("/captcha/refresh")).img_data||""}))}captchaCheck(t){return u(this,null,(function*(){return(yield this.POST("/captcha/check",{value:t})).img_data||""}))}captchaStatus(){return u(this,null,(function*(){return(yield this.POST("/captcha/status"))||{is_pass:!1}}))}},admin:class extends R{cacheFlushAll(){return this.POST("/admin/cache-flush",{flush_all:!0})}cacheWarmUp(){return this.POST("/admin/cache-warm",{})}},upload:class extends R{imgUpload(t){return u(this,null,(function*(){const e={page_key:this.options.pageKey};this.withUserInfo(e);const n=I(e);n.set("file",t);const i={method:"POST",body:n};return(yield this.Fetch("/img-upload",i)).data||{}}))}}};class B{constructor(t){Object.entries(D).forEach((([e,n])=>{this[e]=new n(t)}))}}var F={"&":"&","<":"<",">":">",'"':""","'":"'"},q={"&":"&","<":"<",">":">",""":'"',"'":"'"},W=/(&|<|>|"|')/g,N=/[&<>"']/g;function j(t){return F[t]}function H(t){return q[t]}function V(t){return null==t?"":String(t).replace(N,j)}function K(t){return null==t?"":String(t).replace(W,H)}V.options=K.options={};var G={encode:V,escape:V,decode:K,unescape:K,version:"1.0.0-browser"};var z=function t(e){for(var n,i,s=Array.prototype.slice.call(arguments,1);s.length;)for(i in n=s.shift())n.hasOwnProperty(i)&&("[object Object]"===Object.prototype.toString.call(e[i])?e[i]=t(e[i],n[i]):e[i]=n[i]);return e},Q=function(t){return"string"==typeof t?t.toLowerCase():t};function Y(t,e){return t[e]=!0,t}var X=function(t){return t.reduce(Y,{})},J={uris:X(["background","base","cite","href","longdesc","src","usemap"])},Z={voids:X(["area","br","col","hr","img","wbr","input","base","basefont","link","meta"])},tt=G,et=Q,nt=Z,it=/^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)\s*>/,st=/^<\s*\/\s*([\w:-]+)[^>]*>/,ot=/([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g,rt=/^</,at=/^<\s*\//;var lt=G,ct=Q,dt=J,ht=Z;var ut=z,pt=function(t,e){for(var n,i=function(){var t=[];return t.lastItem=function(){return t[t.length-1]},t}(),s=t;t;)o();function o(){n=!0,function(){"\x3c!--"===t.substr(0,4)?(i=t.indexOf("--\x3e"))>=0&&(e.comment&&e.comment(t.substring(4,i)),t=t.substring(i+3),n=!1):at.test(t)?r(st,l):rt.test(t)&&r(it,a);var i;!function(){if(!n)return;var i,s=t.indexOf("<");s>=0?(i=t.substring(0,s),t=t.substring(s)):(i=t,t="");e.chars&&e.chars(i)}()}();var i=t===s;s=t,i&&(t="")}function r(e,i){var s=t.match(e);s&&(t=t.substring(s[0].length),s[0].replace(e,i),n=!1)}function a(t,n,s,o){var r={},a=et(n),l=nt.voids[a]||!!o;s.replace(ot,(function(t,e,n,i,s){r[e]=void 0===n&&void 0===i&&void 0===s?void 0:tt.decode(n||i||s||"")})),l||i.push(a),e.start&&e.start(a,r,l)}function l(t,n){var s,o=0,r=et(n);if(r)for(o=i.length-1;o>=0&&i[o]!==r;o--);if(o>=0){for(s=i.length-1;s>=o;s--)e.end&&e.end(i[s]);i.length=o}}l()},mt=function(t,e){var n,i=e||{};return a(),{start:function(t,e,r){var a=ct(t);if(n.ignoring)return void o(a);if(-1===(i.allowedTags||[]).indexOf(a))return void o(a);if(i.filter&&!i.filter({tag:a,attrs:e}))return void o(a);s("<"),s(a),Object.keys(e).forEach((function(t){var n=e[t],o=(i.allowedClasses||{})[a]||[],r=(i.allowedAttributes||{})[a]||[],l=ct(t);("class"===l&&-1===r.indexOf(l)?(n=n.split(" ").filter((function(t){return o&&-1!==o.indexOf(t)})).join(" ").trim()).length:-1!==r.indexOf(l)&&(!0!==dt.uris[l]||function(t){var e=t[0];if("#"===e||"/"===e)return!0;var n=t.indexOf(":");if(-1===n)return!0;var s=t.indexOf("?");if(-1!==s&&n>s)return!0;var o=t.indexOf("#");return-1!==o&&n>o||i.allowedSchemes.some(r);function r(e){return 0===t.indexOf(e+":")}}(n)))&&(s(" "),s(t),"string"==typeof n&&(s('="'),s(lt.encode(n)),s('"')))})),s(r?"/>":">")},end:function(t){var e=ct(t);-1!==(i.allowedTags||[]).indexOf(e)&&!1===n.ignoring?(s("</"),s(e),s(">")):r(e)},chars:function(t){!1===n.ignoring&&s(i.transformText?i.transformText(t):t)}};function s(e){t.push(e)}function o(t){ht.voids[t]||(!1===n.ignoring?n={ignoring:t,depth:1}:n.ignoring===t&&n.depth++)}function r(t){n.ignoring===t&&--n.depth<=0&&a()}function a(){n={ignoring:!1,depth:0}}},gt={allowedAttributes:{a:["href","name","target","title","aria-label"],iframe:["allowfullscreen","frameborder","src"],img:["src","alt","title","aria-label"]},allowedClasses:{},allowedSchemes:["http","https","mailto"],allowedTags:["a","abbr","article","b","blockquote","br","caption","code","del","details","div","em","h1","h2","h3","h4","h5","h6","hr","i","img","ins","kbd","li","main","mark","ol","p","pre","section","span","strike","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],filter:null};function ft(t,e,n){var i=[],s=!0===n?e:ut({},gt,e),o=mt(i,s);return pt(t,o),i.join("")}ft.defaults=gt;const kt=E(ft),vt={allowedClasses:{},allowedSchemes:["http","https","mailto","data"],allowedTags:["a","abbr","article","b","blockquote","br","caption","code","del","details","div","em","h1","h2","h3","h4","h5","h6","hr","i","img","ins","kbd","li","main","mark","ol","p","pre","section","span","strike","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],allowedAttributes:{"*":["title","accesskey"],a:["href","name","target","aria-label","rel"],img:["src","alt","title","atk-emoticon","aria-label"],code:["class"],span:["class","style"]},filter:t=>([["code",/^hljs\W+language-(.*)$/],["span",/^(hljs-.*)$/]].forEach((([e,n])=>{t.tag===e&&t.attrs.class&&!n.test(t.attrs.class)&&delete t.attrs.class})),"span"===t.tag&&t.attrs.style&&!/^color:(\W+)?#[0-9a-f]{3,6};?$/i.test(t.attrs.style)&&delete t.attrs.style,!0)};function yt(t){return kt(t,vt)}var $t={exports:{}};$t.exports=function(){function t(t,e){return t(e={exports:{}},e.exports),e.exports}var e=t((function(t){var e=t.exports=function(){return new RegExp("(?:"+e.line().source+")|(?:"+e.block().source+")","gm")};e.line=function(){return/(?:^|\s)\/\/(.+?)$/gm},e.block=function(){return/\/\*([\S\s]*?)\*\//gm}})),n=["23AC69","91C132","F19726","E8552D","1AAB8E","E1147F","2980C1","1BA1E6","9FA0A0","F19726","E30B20","E30B20","A3338B"];function i(t){return'<span style="color: slategray">'+t+"</span>"}return function(t,s){void 0===s&&(s={});var o=s.colors;void 0===o&&(o=n);var r=0,a={},l=new RegExp("("+/[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af\u0400-\u04FF]+|\w+/.source+"|"+/</.source+")|("+e().source+")","gmi");return t.replace(l,(function(t,e,n){if(n)return i(n);if("<"===e)return"<";var s;a[e]?s=a[e]:(s=o[r],a[e]=s);var l='<span style="color: #'+s+'">'+e+"</span>";return r=++r%o.length,l}))}}();const wt=E($t.exports);function bt(t){return wt(t)}function xt(){const t=new e.marked.Renderer;return t.link=Ct(t,t.link),t.code=Et(),t}const Ct=(t,e)=>(n,i,s)=>{const o=null==n?void 0:n.startsWith(`${window.location.protocol}//${window.location.hostname}`);return e.call(t,n,i,s).replace(/^<a /,`<a target="_blank" ${o?"":'rel="noreferrer noopener nofollow"'} `)},Et=()=>(t,e)=>{const n=e||"plaintext";let i=t;return window.hljs?n&&window.hljs.getLanguage(n)&&(i=window.hljs.highlight(n,t).value):i=bt(t),`<pre rel="${n}">\n<code class="hljs language-${n}">${i.replace(/&/g,"&")}</code>\n</pre>`};let St,Tt=[];const Lt={pedantic:!1,gfm:!0,breaks:!0,smartLists:!0,smartypants:!0,xhtml:!1,sanitize:!1,silent:!0};function At(){return St}function Mt(t){var e;let n=null==(e=At())?void 0:e.parse(t);n||(n=function(t){return t.replace(/```\s*([^]+?.*?[^]+?[^]+?)```/g,((t,e)=>`<pre><code>${bt(e)}</code></pre>`)).replace(/!\[(.*?)\]\((.*?)\)/g,((t,e,n)=>`<img src="${n}" alt="${e}" />`)).replace(/\[(.*?)\]\((.*?)\)/g,((t,e,n)=>`<a href="${n}" target="_blank">${e}</a>`)).replace(/\n/g,"<br>")}(t));let i=yt(n);return Tt.forEach((t=>{"function"==typeof t&&(i=t(i))})),i}class Ot{constructor(t){h(this,"loading",!1),h(this,"listLastFetch"),h(this,"comments",[]),h(this,"unreads",[]),h(this,"page"),this.events=t}getLoading(){return this.loading}setLoading(t){this.loading=t}getListLastFetch(){return this.listLastFetch}setListLastFetch(t){this.listLastFetch=t}getComments(){return this.comments}fetchComments(t){this.events.trigger("list-fetch",t)}findComment(t){return this.comments.find((e=>e.id===t))}clearComments(){this.comments=[],this.events.trigger("list-loaded",this.comments)}loadComments(t){this.events.trigger("list-load",t),this.comments.push(...t),this.events.trigger("list-loaded",this.comments)}insertComment(t){this.comments.push(t),this.events.trigger("comment-inserted",t),this.events.trigger("list-loaded",this.comments)}updateComment(t){this.comments=this.comments.map((e=>e.id===t.id?t:e)),this.events.trigger("comment-updated",t),this.events.trigger("list-loaded",this.comments)}deleteComment(t){const e=this.comments.find((e=>e.id===t));if(!e)throw new Error(`Comment ${t} not found`);this.comments=this.comments.filter((e=>e.id!==t)),this.events.trigger("comment-deleted",e),this.events.trigger("list-loaded",this.comments)}getUnreads(){return this.unreads}updateUnreads(t){this.unreads=t,this.events.trigger("unreads-updated",this.unreads)}getPage(){return this.page}updatePage(t){this.page=t,this.events.trigger("page-loaded",t)}}class Pt{constructor(){h(this,"events",[])}on(t,e,n={}){this.events.push(c({name:t,handler:e},n))}off(t,e){e&&(this.events=this.events.filter((n=>!(n.name===t&&n.handler===e))))}trigger(t,e){this.events.slice(0).filter((e=>e.name===t&&"function"==typeof e.handler)).forEach((n=>{n.once&&this.off(t,n.handler),n.handler(e)}))}}const _t={el:"",pageKey:"",pageTitle:"",server:"",site:"",placeholder:"",noComment:"",sendBtn:"",darkMode:!1,editorTravel:!0,flatMode:"auto",nestMax:2,nestSort:"DATE_ASC",emoticons:"https://cdn.jsdelivr.net/gh/ArtalkJS/Emoticons/grps/default.json",vote:!0,voteDown:!1,uaBadge:!0,listSort:!0,preview:!0,countEl:"#ArtalkCount",pvEl:"#ArtalkPV",gravatar:{mirror:"https://cravatar.cn/avatar/",params:"d=mp&s=240"},pagination:{pageSize:20,readMore:!0,autoLoad:!0},heightLimit:{content:300,children:400,scrollable:!1},imgUpload:!0,reqTimeout:15e3,versionCheck:!0,useBackendConf:!0,locale:"zh-CN"};function Ut(t){const e=x(_t,t);if(t.el&&(e.el=t.el),"string"==typeof e.el&&e.el)try{const t=document.querySelector(e.el);if(!t)throw Error(`Target element "${e.el}" was not found.`);e.el=t}catch(n){throw console.error(n),new Error("Please check your Artalk `el` config.")}return e.server=e.server.replace(/\/$/,"").replace(/\/api\/?$/,""),e.pageKey||(e.pageKey=`${window.location.pathname}`),e.pageTitle||(e.pageTitle=`${document.title}`),"auto"===e.locale&&(e.locale=navigator.language),(!0===e.flatMode||Number(e.nestMax)<=1)&&(e.flatMode=!0),"auto"===e.flatMode&&(e.flatMode=window.matchMedia("(max-width: 768px)").matches),e}function It(t,e){return{baseURL:`${t.server}/api`,siteName:t.site||"",pageKey:t.pageKey||"",pageTitle:t.pageTitle||"",timeout:t.reqTimeout,apiToken:null==e?void 0:e.get("user").getData().token,userInfo:(null==e?void 0:e.get("user").checkHasBasicUserInfo())?{name:null==e?void 0:e.get("user").getData().nick,email:null==e?void 0:e.get("user").getData().email}:void 0,onNeedCheckAdmin(t){null==e||e.checkAdmin({onSuccess:()=>{t.recall()},onCancel:()=>{t.reject()}})},onNeedCheckCaptcha(t){null==e||e.checkCaptcha({imgData:t.data.imgData,iframe:t.data.iframe,onSuccess:()=>{t.recall()},onCancel:()=>{t.reject()}})}}}_t.vote=!1,_t.uaBadge=!1,_t.emoticons=!1;class Rt{constructor(t,e){h(this,"conf"),h(this,"data"),h(this,"$root"),h(this,"events",new Pt),this.conf=t,this.$root=e||document.createElement("div"),this.$root.classList.add("artalk"),this.$root.innerHTML="",this.data=new Ot(this.events)}inject(t,e){this[t]=e}get(t){return this[t]}getApi(){return new B(It(this.conf,this))}getData(){return this.data}replyComment(t,e){this.editor.setReply(t,e)}editComment(t,e){this.editor.setEditComment(t,e)}fetch(t){this.data.fetchComments(t)}reload(){this.data.fetchComments({offset:0})}listGotoFirst(){this.events.trigger("list-goto-first")}editorShowLoading(){this.editor.showLoading()}editorHideLoading(){this.editor.hideLoading()}editorShowNotify(t,e){this.editor.showNotify(t,e)}editorResetState(){this.editor.resetState()}showSidebar(t){this.sidebarLayer.show(t)}hideSidebar(){this.sidebarLayer.hide()}checkAdmin(t){this.checkerLauncher.checkAdmin(t)}checkCaptcha(t){this.checkerLauncher.checkCaptcha(t)}on(t,e){this.events.on(t,e)}off(t,e){this.events.off(t,e)}trigger(t,e){this.events.trigger(t,e)}$t(t,e={}){return _(t,e)}setDarkMode(t){this.conf.darkMode=t,this.events.trigger("dark-mode-changed",t)}updateConf(t){this.conf=x(this.conf,Ut(t)),this.events.trigger("conf-loaded",this.conf)}getMarked(){return At()}}class Dt{constructor(t){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(t)}setYes(t){const e=p(`<button data-action="confirm">${_("confirm")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}setNo(t){const e=p(`<button data-action="cancel">${_("cancel")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}onBtnClick(t){return e=>{const n=t(e.currentTarget,this);void 0!==n&&!0!==n||this.$el.remove()}}}function Bt(t,e){let n=t.querySelector(":scope > .atk-loading");n||(n=p('<div class="atk-loading atk-fade-in" style="display: none;">\n <div class="atk-loading-spinner">\n <svg viewBox="25 25 50 50"><circle cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10"></circle></svg>\n </div>\n </div>'),(null==e?void 0:e.transparentBg)&&(n.style.background="transparent"),t.appendChild(n)),n.style.display="";const i=n.querySelector(".atk-loading-spinner");i&&(i.style.display="none",window.setTimeout((()=>{i.style.display=""}),500))}function Ft(t){const e=t.querySelector(":scope > .atk-loading");e&&(e.style.display="none")}function qt(t,e){t?Bt(e):Ft(e)}function Wt(t,e=!0,n){let i;if(n){const e=n.getBoundingClientRect();i=t.getBoundingClientRect().top-e.top+n.scrollTop,i+=m(n)/2-m(t)/2}else{const e=t.getBoundingClientRect();i=e.top+window.scrollY-(window.innerHeight/2-e.height/2)}const s={top:i,left:0,behavior:"instant"};n?n.scroll(s):window.scroll(s)}function Nt(t,e){!function(t,e,n="in"){t.classList.add(`atk-fade-${n}`);const i=()=>{t.classList.remove(`atk-fade-${n}`),t.removeEventListener("animationend",i),e&&e()};t.addEventListener("animationend",i)}(t,e,"in")}function jt(t,e,n='<span class="atk-error-title">Artalk Error</span>'){let i=t.querySelector(".atk-error-layer");if(null===e)return void(null!==i&&i.remove());i||(i=p(`<div class="atk-error-layer">${n}<span class="atk-error-text"></span></div>`),t.appendChild(i));const s=i.querySelector(".atk-error-text");s.innerHTML="",null!==e&&(e instanceof HTMLElement?s.appendChild(e):s.innerText=e)}function Ht(t){const e=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",Bt(e,{transparentBg:!0}),n.src=`${t.getOpts().getIframeURLBase()||""}/api/captcha/get?t=${+new Date}`,n.onload=()=>{n.style.display="",Ft(e)},e.append(n);const i=p('<div class="atk-close-btn"><i class="atk-icon atk-icon-close"></i></div>');e.append(i),t.hideInteractInput();let s=!1;return function e(){return u(this,null,(function*(){var n;if(yield(n=1e3,new Promise((t=>{window.setTimeout((()=>{t(null)}),n)}))),s)return;let i=!1;try{i=(yield t.getApi().captcha.captchaStatus()).is_pass}catch(o){i=!1}i?t.triggerSuccess():e()}))}(),i.onclick=()=>{s=!0,t.cancel()},e}const Vt={request:(t,e)=>t.getApi().captcha.captchaCheck(e),body:t=>t.get("iframe")?Ht(t):function(t){const e=p(`<span><img class="atk-captcha-img" src="${t.get("img_data")||""}">${_("captchaCheck")}</span>`);return e.querySelector(".atk-captcha-img").onclick=()=>{const n=e.querySelector(".atk-captcha-img");t.getApi().captcha.captchaGet().then((t=>{n.setAttribute("src",t)})).catch((t=>{console.error("Failed to get captcha image ",t)}))},e}(t),onSuccess(t,e,n,i){t.set("val",n)},onError(t,e,n,i){i.querySelector(".atk-captcha-img").click(),i.querySelector('input[type="text"]').value=""}},Kt={inputType:"password",request(t,e){const n={name:t.getUser().getData().nick,email:t.getUser().getData().email,password:e};return(()=>u(this,null,(function*(){return(yield t.getApi().user.login(n.name,n.email,n.password)).token})))()},body:t=>p(`<span>${_("adminCheck")}</span>`),onSuccess(t,e,n,i){t.getUser().update({isAdmin:!0,token:e}),t.getOpts().onReload()},onError(t,e,n,i){}};class Gt{constructor(t){this.opts=t}checkCaptcha(t){this.fire(Vt,t,(e=>{e.set("img_data",t.imgData),e.set("iframe",t.iframe)}))}checkAdmin(t){this.fire(Kt,t)}fire(t,e,n){const i=this.opts.getCtx().get("layerManager").create(`checker-${(new Date).getTime()}`);i.show();const s={};let o=!1;const r={set:(t,e)=>{s[t]=e},get:t=>s[t],getOpts:()=>this.opts,getUser:()=>this.opts.getCtx().get("user"),getApi:()=>this.opts.getApi(),hideInteractInput:()=>{o=!0},triggerSuccess:()=>{this.close(t,i),t.onSuccess&&t.onSuccess(r,"","",a),e.onSuccess&&e.onSuccess("",d.$el)},cancel:()=>{this.close(t,i),e.onCancel&&e.onCancel()}};n&&n(r);const a=p();a.appendChild(t.body(r));const l=p(`<input id="check" type="${t.inputType||"text"}" autocomplete="off" required placeholder="">`);let c;a.appendChild(l),setTimeout((()=>l.focus()),80),l.onkeyup=t=>{"Enter"!==t.key&&13!==t.keyCode||(t.preventDefault(),i.getEl().querySelector('button[data-action="confirm"]').click())};const d=new Dt(a);d.setYes((n=>{const s=l.value.trim();c||(c=n.innerText);const o=()=>{n.innerText=c||"",n.classList.remove("error")};return n.innerText=`${_("loading")}...`,t.request(r,s).then((n=>{this.close(t,i),t.onSuccess&&t.onSuccess(r,n,s,a),e.onSuccess&&e.onSuccess(s,d.$el)})).catch((e=>{var i;i=String(e.msg||String(e)),n.innerText=i,n.classList.add("error"),t.onError&&t.onError(r,e,s,a);const c=setTimeout((()=>o()),3e3);l.onfocus=()=>{o(),clearTimeout(c)}})),!1})),d.setNo((()=>(this.close(t,i),e.onCancel&&e.onCancel(),!1))),o&&(l.style.display="none",d.$el.querySelector(".atk-layer-dialog-actions").style.display="none"),i.getEl().append(d.$el),e.onMount&&e.onMount(d.$el)}close(t,e){e.destroy()}}class zt{constructor(t){h(this,"$el"),h(this,"conf"),this.ctx=t,this.conf=t.conf}}const Qt={$header:".atk-header",$nick:'.atk-header [name="nick"]',$email:'.atk-header [name="email"]',$link:'.atk-header [name="link"]',$textareaWrap:".atk-textarea-wrap",$textarea:".atk-textarea",$bottom:".atk-bottom",$submitBtn:".atk-send-btn",$notifyWrap:".atk-notify-wrap",$plugBtnWrap:".atk-plug-btn-wrap",$plugPanelWrap:".atk-plug-panel-wrap"};class Yt{constructor(t){this.kit=t}useBtn(t="<div></div>"){return this.$btn=p(`<span class="atk-plug-btn">${t}</span>`),this.$btn}usePanel(t="<div></div>"){return this.$panel=p(t),this.$panel}useContentTransformer(t){this.contentTransformer=t}usePanelShow(t){this.kit.useEvents().on("panel-show",(e=>{e===this&&t()}))}usePanelHide(t){this.kit.useEvents().on("panel-hide",(e=>{e===this&&t()}))}useEditorStateEffect(t,e){this.editorStateEffectWhen=t,this.editorStateEffect=e}}class Xt extends Yt{constructor(){super(...arguments),h(this,"isMoved",!1)}move(t){if(this.isMoved)return;this.isMoved=!0;const e=this.kit.useUI().$el;e.after(p('<div class="atk-editor-travel-placeholder"></div>'));const n=p("<div></div>");t.after(n),n.replaceWith(e),e.classList.add("atk-fade-in"),e.classList.add("editor-traveling")}back(){var t;this.isMoved&&(this.isMoved=!1,null==(t=this.kit.useGlobalCtx().$root.querySelector(".atk-editor-travel-placeholder"))||t.replaceWith(this.kit.useUI().$el),this.kit.useUI().$el.classList.remove("editor-traveling"))}}class Jt{constructor(t){h(this,"stateCurt","normal"),h(this,"stateUnmountFn",null),this.editor=t}get(){return this.stateCurt}switch(t,e){var n,i,s,o,r;if(this.stateUnmountFn&&(this.stateUnmountFn(),this.stateUnmountFn=null,null==(i=null==(n=this.editor.getPlugs())?void 0:n.get(Xt))||i.back()),"normal"!==t&&e){let n=e.$comment;this.editor.conf.flatMode||(n=n.querySelector(".atk-footer")),null==(o=null==(s=this.editor.getPlugs())?void 0:s.get(Xt))||o.move(n);const i=this.editor.ctx.conf.scrollRelativeTo&&this.editor.ctx.conf.scrollRelativeTo();Wt(this.editor.getUI().$el,!0,i);const a=null==(r=this.editor.getPlugs())?void 0:r.getPlugs().find((e=>e.editorStateEffectWhen===t));a&&a.editorStateEffect&&(this.stateUnmountFn=a.editorStateEffect(e.comment))}this.stateCurt=t}}class Zt extends zt{constructor(t){super(t),h(this,"ui"),h(this,"state"),this.ui=function(){const t=p('<div class="atk-main-editor">\n <div class="atk-header">\n <input name="nick" class="atk-nick" type="text" required="required">\n <input name="email" class="atk-email" type="email" required="required">\n <input name="link" class="atk-link" type="url">\n </div>\n <div class="atk-textarea-wrap">\n <textarea class="atk-textarea"></textarea>\n </div>\n <div class="atk-plug-panel-wrap" style="display: none;"></div>\n <div class="atk-bottom">\n <div class="atk-item atk-plug-btn-wrap"></div>\n <div class="atk-item">\n <button type="button" class="atk-send-btn"></button>\n </div>\n </div>\n <div class="atk-notify-wrap"></div>\n</div>\n'),e={$el:t};return Object.entries(Qt).forEach((([n,i])=>{e[n]=t.querySelector(i)})),e}(),this.$el=this.ui.$el,this.state=new Jt(this)}getUI(){return this.ui}getPlugs(){return this.ctx.get("editorPlugs")}getState(){return this.state.get()}getHeaderInputEls(){return{nick:this.ui.$nick,email:this.ui.$email,link:this.ui.$link}}getContentFinal(){let t=this.getContentRaw();const e=this.getPlugs();return e&&(t=e.getTransformedContent(t)),t}getContentRaw(){return this.ui.$textarea.value||""}getContentMarked(){return Mt(this.getContentFinal())}setContent(t){var e;this.ui.$textarea.value=t,null==(e=this.getPlugs())||e.getEvents().trigger("content-updated",t)}insertContent(t){if(document.selection)this.ui.$textarea.focus(),document.selection.createRange().text=t,this.ui.$textarea.focus();else if(this.ui.$textarea.selectionStart||0===this.ui.$textarea.selectionStart){const e=this.ui.$textarea.selectionStart,n=this.ui.$textarea.selectionEnd,i=this.ui.$textarea.scrollTop;this.setContent(this.ui.$textarea.value.substring(0,e)+t+this.ui.$textarea.value.substring(n,this.ui.$textarea.value.length)),this.ui.$textarea.focus(),this.ui.$textarea.selectionStart=e+t.length,this.ui.$textarea.selectionEnd=e+t.length,this.ui.$textarea.scrollTop=i}else this.ui.$textarea.focus(),this.ui.$textarea.value+=t}focus(){this.ui.$textarea.focus()}reset(){this.setContent(""),this.resetState()}resetState(){this.state.switch("normal")}setReply(t,e){this.state.switch("reply",{comment:t,$comment:e})}setEditComment(t,e){this.state.switch("edit",{comment:t,$comment:e})}showNotify(t,e){!function(t,e,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=g(e).replace("\n","<br/>"),t.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,t,e)}showLoading(){Bt(this.ui.$el)}hideLoading(){Ft(this.ui.$el)}submit(){this.ctx.trigger("editor-submit")}}class te extends zt{constructor(t){super(t),h(this,"layer"),h(this,"$header"),h(this,"$closeBtn"),h(this,"$iframeWrap"),h(this,"$iframe"),h(this,"firstShow",!0),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"><i class="atk-icon atk-icon-close"></i></div>\n </div>\n <div class="atk-sidebar-iframe-wrap"></div>\n </div>\n</div>\n'),this.$header=this.$el.querySelector(".atk-sidebar-header"),this.$closeBtn=this.$header.querySelector(".atk-sidebar-close"),this.$iframeWrap=this.$el.querySelector(".atk-sidebar-iframe-wrap"),this.$closeBtn.onclick=()=>{this.hide()},this.ctx.on("user-changed",(()=>{this.firstShow=!0}))}show(){return u(this,arguments,(function*(t={}){if(this.$el.style.transform="",this.initLayer(),this.layer.show(),this.authCheck({onSuccess:()=>this.show(t)}),this.firstShow)this.$iframeWrap.innerHTML="",this.$iframe=this.createIframe(t.view),this.$iframeWrap.append(this.$iframe),this.firstShow=!1;else{const t=this.$iframe,e=t.src.includes("darkMode=1");this.conf.darkMode&&!e&&this.iframeLoad(t,`${this.$iframe.src}&darkMode=1`),!this.conf.darkMode&&e&&this.iframeLoad(t,this.$iframe.src.replace("&darkMode=1",""))}setTimeout((()=>{this.$el.style.transform="translate(0, 0)"}),100),setTimeout((()=>{this.ctx.getData().updateUnreads([])}),0),this.ctx.trigger("sidebar-show")}))}hide(){var t;this.$el.style.transform="",null==(t=this.layer)||t.hide(),this.ctx.trigger("sidebar-hide")}authCheck(t){return u(this,null,(function*(){const e=yield this.ctx.getApi().user.loginStatus();e.is_admin&&!e.is_login&&(this.firstShow=!0,this.ctx.checkAdmin({onSuccess:()=>{setTimeout((()=>{t.onSuccess()}),500)},onCancel:()=>{this.hide()}}))}))}initLayer(){this.layer||(this.layer=this.ctx.get("layerManager").create("sidebar",this.$el),this.layer.setOnAfterHide((()=>{this.ctx.editorResetState()})))}createIframe(t){const e=p('<iframe referrerpolicy="strict-origin-when-cross-origin"></iframe>'),n=b({base:this.ctx.conf.server,path:"/sidebar/"}),i={pageKey:this.conf.pageKey,site:this.conf.site||"",user:JSON.stringify(this.ctx.get("user").getData()),time:+new Date};t&&(i.view=t),this.conf.darkMode&&(i.darkMode="1"),"string"==typeof this.conf.locale&&(i.locale=this.conf.locale);const s=new URLSearchParams(i);return this.iframeLoad(e,`${n}?${s.toString()}`),e}iframeLoad(t,e){t.src=e,Bt(this.$iframeWrap),t.onload=()=>{Ft(this.$iframeWrap)}}}class ee{constructor(t){this.options=t}import(t){this.options.flatMode?t.forEach((e=>{this.putCommentFlatMode(e,t,"append")})):this.importCommentsNestMode(t)}insert(t){this.options.flatMode?this.insertCommentFlatMode(t):this.insertCommentNest(t)}importCommentsNestMode(t){const e=function(t,e="DATE_DESC",n=2){const i=[];t.filter((t=>0===t.rid)).forEach((e=>{const s={id:e.id,comment:e,children:[],level:1};s.parent=s,i.push(s),function e(i){const s=t.filter((t=>t.rid===i.id));0!==s.length&&(i.level>=n&&(i=i.parent),s.forEach((t=>{const n={id:t.id,comment:t,children:[],parent:i,level:i.level+1};i.children.push(n),e(n)})))}(s)}));const s=(n,i)=>{let s=n.id-i.id;return"DATE_ASC"===e?s=+new Date(n.comment.date)-+new Date(i.comment.date):"DATE_DESC"===e?s=+new Date(i.comment.date)-+new Date(n.comment.date):"SRC_INDEX"===e?s=t.indexOf(n.comment)-t.indexOf(i.comment):"VOTE_UP_DESC"===e&&(s=i.comment.vote_up-n.comment.vote_up),s};return function t(e){e.forEach((e=>{e.children=e.children.sort(s),t(e.children)}))}(i),i}(t,this.options.nestSortBy,this.options.nestMax);e.forEach((e=>{var n;const i=this.options.createCommentNode(e.comment,t);null==(n=this.options.$commentsWrap)||n.appendChild(i.getEl()),i.getRender().playFadeAnim();const s=(e,n)=>{n.children.forEach((n=>{const i=n.comment,o=this.options.createCommentNode(i,t);e.putChild(o),s(o,n)}))};s(i,e),i.getRender().checkHeightLimit()}))}putCommentFlatMode(t,e,n){var i,s;t.is_collapsed&&(t.is_allow_reply=!1);const o=this.options.createCommentNode(t,e);return t.visible&&("append"===n&&(null==(i=this.options.$commentsWrap)||i.append(o.getEl())),"prepend"===n&&(null==(s=this.options.$commentsWrap)||s.prepend(o.getEl())),o.getRender().playFadeAnim()),o.getRender().checkHeightLimit(),o}insertCommentNest(t){var e;const n=this.options.createCommentNode(t,this.options.getCommentDataList());if(0===t.rid)null==(e=this.options.$commentsWrap)||e.prepend(n.getEl());else{const e=this.options.findCommentNode(t.rid);e&&(e.putChild(n,"DATE_ASC"===this.options.nestSortBy?"append":"prepend"),n.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()})))}n.getRender().checkHeightLimit(),Wt(n.getEl()),n.getRender().playFadeAnim()}insertCommentFlatMode(t){Wt(this.putCommentFlatMode(t,this.options.getCommentDataList(),"prepend").getEl())}}function ne(t,e){e.forEach((({el:e,max:n,imgContains:i})=>{const s=()=>{e&&(t.scrollable?function(t){if(!t.el)return;if(t.el.classList.contains(oe))return;t.el.classList.add(oe),t.el.style.height=`${t.maxHeight}px`}({el:e,maxHeight:n}):function(t){if(!t.el)return;if(!t.maxHeight)return;if(t.el.classList.contains(ie))return;t.el.classList.add(ie),t.el.style.height=`${t.maxHeight}px`,t.el.style.overflow="hidden";const e=p(`<div class="atk-height-limit-btn">${_("readMore")}</span>`);e.onclick=e=>{e.stopPropagation(),se(t.el),t.postBtnClick&&t.postBtnClick(e)},t.el.append(e)}({el:e,maxHeight:n,postBtnClick:t.postExpandBtnClick}))},o=()=>{e&&m(e)>n&&s()};o(),i&&e&&function(t,e){if(!t)return;const n=t.getElementsByTagName("img");if(!n.length)return;let i=n.length;for(let s=0;s<n.length;s++)n[s].complete?i--:n[s].addEventListener("load",(()=>{i--,0===i&&e()})),0===i&&e()}(e,(()=>o()))}))}const ie="atk-height-limit";function se(t){t&&t.classList.contains(ie)&&(t.classList.remove(ie),Array.from(t.children).forEach((t=>{t.classList.contains("atk-height-limit-btn")&&t.remove()})),t.style.height="",t.style.overflow="")}const oe="atk-height-limit-scroll";function re(t){if(t.$headerNick=t.$el.querySelector(".atk-nick"),t.data.link){const e=p('<a target="_blank" rel="noreferrer noopener nofollow"></a>');e.innerText=t.data.nick,e.href=w(t.data.link)?t.data.link:`https://${t.data.link}`,t.$headerNick.append(e)}else t.$headerNick.innerText=t.data.nick}function ae(t){t.$headerBadgeWrap=t.$el.querySelector(".atk-badge-wrap"),t.$headerBadgeWrap.innerHTML="";const e=t.data.badge_name,n=t.data.badge_color;if(e){const i=p('<span class="atk-badge"></span>');i.innerText=e.replace("管理员",t.ctx.$t("admin")),i.style.backgroundColor=n||"",t.$headerBadgeWrap.append(i)}if(t.data.is_pinned){const e=p(`<span class="atk-pinned-badge">${t.ctx.$t("pin")}</span>`);t.$headerBadgeWrap.append(e)}}function le(t){const e=t.$el.querySelector(".atk-date");e.innerText=t.comment.getDateFormatted(),e.setAttribute("data-atk-comment-date",String(+new Date(t.data.date)))}function ce(t){if(!t.ctx.conf.uaBadge&&!t.data.ip_region)return;let e=t.$header.querySelector("atk-ua-wrap");if(e||(e=p('<span class="atk-ua-wrap"></span>'),t.$header.append(e)),e.innerHTML="",t.data.ip_region){const n=p('<span class="atk-region-badge"></span>');n.innerText=t.data.ip_region,e.append(n)}if(t.ctx.conf.uaBadge){const{browser:n,os:i}=t.comment.getUserUA();if(String(n).trim()){const t=p('<span class="atk-ua ua-browser"></span>');t.innerText=n,e.append(t)}if(String(i).trim()){const t=p('<span class="atk-ua ua-os"></span>');t.innerText=i,e.append(t)}}}class de{constructor(t){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 t?{text:t}:t,this.$el.innerText=this.getText(),this.opts.adminOnly&&this.$el.setAttribute("atk-only-admin-show","")}get isMessaging(){return!!this.msgRecTimer}appendTo(t){return t.append(this.$el),this}getText(){return"string"==typeof this.opts.text?this.opts.text:this.opts.text()}setClick(t){this.$el.onclick=e=>{if(e.stopPropagation(),!this.isLoading){if(this.opts.confirm&&!this.isMessaging){const t=()=>{this.isConfirming=!1,this.$el.classList.remove("atk-btn-confirm"),this.$el.innerText=this.getText()};if(!this.isConfirming)return this.isConfirming=!0,this.$el.classList.add("atk-btn-confirm"),this.$el.innerText=this.opts.confirmText||_("actionConfirm"),void(this.confirmRecTimer=window.setTimeout((()=>t()),5e3));this.confirmRecTimer&&window.clearTimeout(this.confirmRecTimer),t()}if(this.msgRecTimer)return this.fireMsgRecTimer(),void this.clearMsgRecTimer();t()}}}updateText(t){t&&(this.opts.text=t),this.setLoading(!1),this.$el.innerText=this.getText()}setLoading(t,e){this.isLoading!==t&&(this.isLoading=t,t?(this.$el.classList.add("atk-btn-loading"),this.$el.innerText=e||`${_("loading")}...`):(this.$el.classList.remove("atk-btn-loading"),this.$el.innerText=this.getText()))}setError(t){this.setMsg(t,"atk-btn-error")}setWarn(t){this.setMsg(t,"atk-btn-warn")}setSuccess(t){this.setMsg(t,"atk-btn-success")}setMsg(t,e,n,i){this.setLoading(!1),e&&this.$el.classList.add(e),this.$el.innerText=t,this.setMsgRecTimer((()=>{this.$el.innerText=this.getText(),e&&this.$el.classList.remove(e),i&&i()}),n||2500)}setMsgRecTimer(t,e){this.fireMsgRecTimer(),this.clearMsgRecTimer(),this.msgRecTimerFunc=t,this.msgRecTimer=window.setTimeout((()=>{t(),this.clearMsgRecTimer()}),e)}fireMsgRecTimer(){this.msgRecTimerFunc&&this.msgRecTimerFunc()}clearMsgRecTimer(){this.msgRecTimer&&window.clearTimeout(this.msgRecTimer),this.msgRecTimer=void 0,this.msgRecTimerFunc=void 0}}function he(t){t.ctx.conf.vote&&(t.voteBtnUp=new de((()=>`${t.ctx.$t("voteUp")} (${t.data.vote_up||0})`)).appendTo(t.$actions),t.voteBtnUp.setClick((()=>{t.comment.getActions().vote("up")})),t.ctx.conf.voteDown&&(t.voteBtnDown=new de((()=>`${t.ctx.$t("voteDown")} (${t.data.vote_down||0})`)).appendTo(t.$actions),t.voteBtnDown.setClick((()=>{t.comment.getActions().vote("down")}))))}function ue(t){if(!t.data.is_allow_reply)return;const e=p(`<span>${t.ctx.$t("reply")}</span>`);t.$actions.append(e),e.addEventListener("click",(e=>{e.stopPropagation(),t.cConf.onReplyBtnClick?t.cConf.onReplyBtnClick():t.ctx.replyComment(t.data,t.$el)}))}function pe(t){const e=new de({text:()=>t.data.is_collapsed?t.ctx.$t("expand"):t.ctx.$t("collapse"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("collapsed",e)}))}function me(t){const e=new de({text:()=>t.data.is_pending?t.ctx.$t("pending"):t.ctx.$t("approved"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pending",e)}))}function ge(t){const e=new de({text:()=>t.data.is_pinned?t.ctx.$t("unpin"):t.ctx.$t("pin"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pinned",e)}))}function fe(t){const e=new de({text:t.ctx.$t("edit"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.ctx.editComment(t.data,t.$el)}))}function ke(t){const e=new de({text:t.ctx.$t("delete"),confirm:!0,confirmText:t.ctx.$t("deleteConfirm"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminDelete(e)}))}const ve={Avatar:function(t){const e=t.$el.querySelector(".atk-avatar"),n=p("<img />"),i=t.conf.avatarURLBuilder;if(n.src=i?i(t.data):t.comment.getGravatarURL(),t.data.link){const i=p('<a target="_blank" rel="noreferrer noopener nofollow"></a>');i.href=w(t.data.link)?t.data.link:`https://${t.data.link}`,i.append(n),e.append(i)}else e.append(n)},Header:function(t){Object.entries({renderNick:re,renderVerifyBadge:ae,renderDate:le,renderUABadge:ce}).forEach((([e,n])=>{n(t)}))},Content:function(t){if(!t.data.is_collapsed)return t.$content.innerHTML=t.comment.getContentMarked(),void t.$content.classList.remove("atk-hide","atk-collapsed");t.$content.classList.add("atk-hide","atk-type-collapsed");const e=p(`\n <div class="atk-collapsed">\n <span class="atk-text">${t.ctx.$t("collapsedMsg")}</span>\n <span class="atk-show-btn">${t.ctx.$t("expand")}</span>\n </div>`);t.$body.insertAdjacentElement("beforeend",e);const n=e.querySelector(".atk-show-btn");n.addEventListener("click",(e=>{e.stopPropagation(),t.$content.classList.contains("atk-hide")?(t.$content.innerHTML=t.comment.getContentMarked(),t.$content.classList.remove("atk-hide"),Nt(t.$content),n.innerText=t.ctx.$t("collapse")):(t.$content.innerHTML="",t.$content.classList.add("atk-hide"),n.innerText=t.ctx.$t("expand"))}))},ReplyAt:function(t){t.cConf.isFlatMode||0===t.data.rid||t.cConf.replyTo&&(t.$replyAt=p('<span class="atk-item atk-reply-at"><span class="atk-arrow"></span><span class="atk-nick"></span></span>'),t.$replyAt.querySelector(".atk-nick").innerText=`${t.cConf.replyTo.nick}`,t.$replyAt.onclick=()=>{t.comment.getActions().goToReplyComment()},t.$headerBadgeWrap.insertAdjacentElement("afterend",t.$replyAt))},ReplyTo:function(t){if(!t.cConf.isFlatMode)return;if(!t.cConf.replyTo)return;t.$replyTo=p(`\n <div class="atk-reply-to">\n <div class="atk-meta">${t.ctx.$t("reply")} <span class="atk-nick"></span>:</div>\n <div class="atk-content"></div>\n </div>`);const e=t.$replyTo.querySelector(".atk-nick");e.innerText=`@${t.cConf.replyTo.nick}`,e.onclick=()=>{t.comment.getActions().goToReplyComment()};let n=Mt(t.cConf.replyTo.content);t.cConf.replyTo.is_collapsed&&(n=`[${g(t.ctx.$t("collapsed"))}]`),t.$replyTo.querySelector(".atk-content").innerHTML=n,t.$body.prepend(t.$replyTo)},Pending:function(t){if(!t.data.is_pending)return;const e=p(`<div class="atk-pending">${t.ctx.$t("pendingMsg")}</div>`);t.$body.prepend(e)},Actions:function(t){Object.entries({renderVote:he,renderReply:ue,renderCollapse:pe,renderModerator:me,renderPin:ge,renderEdit:fe,renderDel:ke}).forEach((([e,n])=>{n(t)}))}};class ye{constructor(t){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=t}get ctx(){return this.comment.ctx}get data(){return this.comment.getData()}get conf(){return this.comment.conf}get cConf(){return this.comment.getConf()}render(){var t;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}`),t=this,Object.entries(ve).forEach((([e,n])=>{n(t)})),this.recoveryChildrenWrap(),this.$el}checkHeightLimit(){const t=this.ctx.conf.heightLimit;if(!t||!t.content||!t.children)return;const e=t.content,n=t.children;ne({postExpandBtnClick:()=>{const t=this.comment.getChildren();1===t.length&&se(t[0].getRender().$content)},scrollable:t.scrollable},[{el:this.$content,max:e,imgContains:!0},{el:this.$replyTo,max:e,imgContains:!0},{el:this.$childrenWrap,max:n,imgContains:!1}])}heightLimitRemoveForChildren(){this.$childrenWrap&&se(this.$childrenWrap)}playFadeAnim(){Nt(this.comment.getRender().$el)}playFadeAnimForBody(){Nt(this.comment.getRender().$body)}getChildrenWrap(){return this.$childrenWrap}renderChildrenWrap(){return this.$childrenWrap||(this.$childrenWrap=p('<div class="atk-comment-children"></div>'),this.$main.append(this.$childrenWrap)),this.$childrenWrap}recoveryChildrenWrap(){this.$childrenWrap&&this.$main.append(this.$childrenWrap)}setUnread(t){t?this.$el.classList.add("atk-unread"):this.$el.classList.remove("atk-unread")}setOpenable(t){t?this.$el.classList.add("atk-openable"):this.$el.classList.remove("atk-openable")}setOpenURL(t){this.setOpenable(!0),this.$el.onclick=e=>{e.preventDefault(),window.open(t),this.cConf.openEvt&&this.cConf.openEvt()}}setOpenAction(t){this.setOpenable(!0),this.$el.onclick=e=>{e.preventDefault(),t()}}}class $e{constructor(t){h(this,"comment"),this.comment=t}get ctx(){return this.comment.ctx}get data(){return this.comment.getData()}get cConf(){return this.comment.getConf()}vote(t){const e="up"===t?this.comment.getRender().voteBtnUp:this.comment.getRender().voteBtnDown;this.ctx.getApi().comment.vote(this.data.id,`comment_${t}`).then((t=>{var e,n;this.data.vote_up=t.up,this.data.vote_down=t.down,null==(e=this.comment.getRender().voteBtnUp)||e.updateText(),null==(n=this.comment.getRender().voteBtnDown)||n.updateText()})).catch((t=>{null==e||e.setError(this.ctx.$t("voteFail")),console.log(t)}))}adminEdit(t,e){if(e.isLoading)return;e.setLoading(!0,`${this.ctx.$t("editing")}...`);const n=c({},this.data);"collapsed"===t?n.is_collapsed=!n.is_collapsed:"pending"===t?n.is_pending=!n.is_pending:"pinned"===t&&(n.is_pinned=!n.is_pinned),this.ctx.getApi().comment.commentEdit(n).then((t=>{e.setLoading(!1),this.comment.setData(t)})).catch((t=>{console.error(t),e.setError(this.ctx.$t("editFail"))}))}adminDelete(t){t.isLoading||(t.setLoading(!0,`${this.ctx.$t("deleting")}...`),this.ctx.getApi().comment.commentDel(this.data.id,this.data.site_name).then((()=>{t.setLoading(!1),this.cConf.onDelete&&this.cConf.onDelete(this.comment)})).catch((e=>{console.error(e),t.setError(this.ctx.$t("deleteFail"))})))}goToReplyComment(){const t=window.location.hash,e=`#atk-comment-${this.data.rid}`;window.location.hash=e,e===t&&window.dispatchEvent(new Event("hashchange"))}}class we extends zt{constructor(t,e,n){super(t),h(this,"renderInstance"),h(this,"actionInstance"),h(this,"data"),h(this,"cConf"),h(this,"parent"),h(this,"children",[]),h(this,"nestCurt"),h(this,"nestMax"),this.nestMax=t.conf.nestMax||3,this.cConf=n,this.data=c({},e),this.data.date=this.data.date.replace(/-/g,"/"),this.parent=null,this.nestCurt=1,this.actionInstance=new $e(this),this.renderInstance=new ye(this)}render(){const t=this.renderInstance.render();this.$el&&this.$el.replaceWith(t),this.$el=t,this.cConf.afterRender&&this.cConf.afterRender()}getActions(){return this.actionInstance}getRender(){return this.renderInstance}getData(){return this.data}setData(t){this.data=t,this.render(),this.getRender().playFadeAnimForBody()}getParent(){return this.parent}getChildren(){return this.children}getNestCurt(){return this.nestCurt}getIsRoot(){return 0===this.data.rid}getID(){return this.data.id}putChild(t,e="append"){t.parent=this,t.nestCurt=this.nestCurt+1,this.children.push(t);const n=this.getChildrenEl();"append"===e?n.append(t.getEl()):"prepend"===e&&n.prepend(t.getEl()),t.getRender().playFadeAnim(),t.getRender().checkHeightLimit()}getChildrenEl(){let t=this.getRender().getChildrenWrap();return t||(t=this.nestCurt<this.nestMax?this.getRender().renderChildrenWrap():this.parent.getChildrenEl()),t}getParents(){const t=[],e=n=>{n.parent&&(t.push(n.parent),e(n.parent))};return e(this),t}getEl(){return this.$el}getGravatarURL(){return`${(t={mirror:this.ctx.conf.gravatar.mirror,params:this.ctx.conf.gravatar.params,emailMD5:this.data.email_encrypted}).mirror.replace(/\/$/,"")}/${t.emailMD5}?${t.params.replace(/^\?/,"")}`;var t}getContentMarked(){return Mt(this.data.content)}getDateFormatted(){return y(new Date(this.data.date),this.ctx.$t)}getUserUA(){const t=function(t){const e=window||{},n=navigator||{},i=String(t||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/")},r={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"),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"),Quark:i.includes("Quark"),Qiyu:i.includes("Qiyu"),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")},a={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"),"Chrome OS":i.includes("CrOS"),WebOS:i.includes("hpwOS")},l={Mobile:i.includes("Mobi")||i.includes("iPh")||i.includes("480"),Tablet:i.includes("Tablet")||i.includes("Pad")||i.includes("Nexus 7")};l.Mobile?l.Mobile=!i.includes("iPad"):r.Chrome&&i.includes("Edg")?(r.Chrome=!1,r.Edge=!0):e.showModalDialog&&e.chrome&&(r.Chrome=!1,r[360]=!0),s.device="PC",s.language=(()=>{const t=(n.browserLanguage||n.language).split("-");return t[1]&&(t[1]=t[1].toUpperCase()),t.join("_")})();const c={engine:o,browser:r,os:a,device:l};Object.entries(c).forEach((([t,e])=>{Object.entries(e).forEach((([e,n])=>{!0===n&&(s[t]=e)}))}));const d={Windows:()=>{const t=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"}[t]||t},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,"."),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"),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"),Quark:()=>i.replace(/^.*Quark\/([\d.]+).*$/,"$1"),Qiyu:()=>i.replace(/^.*Qiyu\/([\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:`${t.browser} ${t.version}`,os:`${t.os} ${t.osVersion}`}}getConf(){return this.cConf}}class be{constructor(t){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=t,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(t){this.$loading.style.display=t?"":"none",this.$text.style.display=t?"none":""}showErr(t){this.setLoading(!1),this.$text.innerText=t,this.$el.classList.add("atk-err"),window.setTimeout((()=>{this.$text.innerText=this.origText,this.$el.classList.remove("atk-err")}),2e3)}update(t,e){this.offset=t,this.total=e,this.checkDisabled()}checkDisabled(){this.hasMore?this.show():this.hide()}}class xe{constructor(){h(this,"instance"),h(this,"onReachedBottom",null),h(this,"opt")}create(t){return this.opt=t,this.instance=new be({pageSize:t.pageSize,onClick:e=>u(this,null,(function*(){t.ctx.fetch({offset:e})})),text:_("loadMore")}),t.readMoreAutoLoad&&(this.onReachedBottom=()=>{this.instance.hasMore&&!this.opt.ctx.getData().getLoading()&&this.instance.click()},this.opt.ctx.on("list-reach-bottom",this.onReachedBottom)),this.instance.$el}setLoading(t){this.instance.setLoading(t)}update(t,e){this.instance.update(t,e)}showErr(t){this.instance.showErr(t)}next(){this.instance.click()}getHasMore(){return this.instance.hasMore}getIsClearComments(t){return 0===t.offset}dispose(){this.onReachedBottom&&this.opt.ctx.off("list-reach-bottom",this.onReachedBottom),this.instance.$el.remove()}}class Ce{constructor(t,e){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=t,this.opts=e,this.$el=p('<div class="atk-pagination-wrap">\n <div class="atk-pagination">\n <div class="atk-btn atk-btn-prev">Prev</div>\n <input type="text" class="atk-input" aria-label="Enter the number of page" />\n <div class="atk-btn atk-btn-next">Next</div>\n </div>\n </div>'),this.$input=this.$el.querySelector(".atk-input"),this.$input.value=`${this.page}`,this.$input.oninput=()=>this.input(),this.$input.onkeydown=t=>this.keydown(t),this.$prevBtn=this.$el.querySelector(".atk-btn-prev"),this.$nextBtn=this.$el.querySelector(".atk-btn-next"),this.$prevBtn.onclick=()=>this.prev(),this.$nextBtn.onclick=()=>this.next(),this.checkDisabled()}get pageSize(){return this.opts.pageSize}get offset(){return this.pageSize*(this.page-1)}get maxPage(){return Math.ceil(this.total/this.pageSize)}update(t,e){this.page=Math.ceil(t/this.pageSize)+1,this.total=e,this.setInput(this.page),this.checkDisabled()}setInput(t){this.$input.value=`${t}`}input(t=!1){window.clearTimeout(this.inputTimer);const e=this.$input.value.trim(),n=()=>{if(""===e)return void this.setInput(this.page);let t=Number(e);Number.isNaN(t)||t<1?this.setInput(this.page):(t>this.maxPage&&(this.setInput(this.maxPage),t=this.maxPage),this.change(t))};t?n():this.inputTimer=window.setTimeout((()=>n()),800)}prev(){const t=this.page-1;t<1||this.change(t)}next(){const t=this.page+1;t>this.maxPage||this.change(t)}getHasMore(){return this.page+1<=this.maxPage}change(t){this.page=t,this.opts.onChange(this.offset),this.setInput(t),this.checkDisabled()}checkDisabled(){this.page+1>this.maxPage?this.$nextBtn.classList.add("atk-disabled"):this.$nextBtn.classList.remove("atk-disabled"),this.page-1<1?this.$prevBtn.classList.add("atk-disabled"):this.$prevBtn.classList.remove("atk-disabled")}keydown(t){const e=t.keyCode||t.which;if(38===e){const t=Number(this.$input.value)+1;if(t>this.maxPage)return;this.setInput(t),this.input()}else if(40===e){const t=Number(this.$input.value)-1;if(t<1)return;this.setInput(t),this.input()}else 13===e&&this.input(!0)}setLoading(t){t?Bt(this.$el):Ft(this.$el)}}class Ee{constructor(){h(this,"instance")}create(t){return this.instance=new Ce(t.total,{pageSize:t.pageSize,onChange:e=>u(this,null,(function*(){t.ctx.editorResetState(),t.ctx.fetch({offset:e,onSuccess:()=>{t.ctx.listGotoFirst()}})}))}),this.instance.$el}setLoading(t){this.instance.setLoading(t)}update(t,e){this.instance.update(t,e)}next(){this.instance.next()}getHasMore(){return this.instance.getHasMore()}getIsClearComments(){return!0}dispose(){this.instance.$el.remove()}}function Se(t){const e=t.getData().getListLastFetch(),n={offset:0,total:0};return e?(n.offset=e.params.offset,e.data&&(n.total=e.params.flatMode?e.data.total:e.data.total_roots),n):n}const Te=t=>{let e=null;t.on("conf-loaded",(n=>{const i=t.get("list");e&&e.dispose(),e=function(t){return t.pagination.readMore?new xe:new Ee}(n);const{offset:s,total:o}=Se(t),r=e.create({ctx:t,pageSize:n.pagination.pageSize,total:o,readMoreAutoLoad:n.pagination.autoLoad});i.$commentsWrap.after(r),null==e||e.update(s,o)})),t.on("list-loaded",(n=>{const{offset:i,total:s}=Se(t);null==e||e.update(i,s)})),t.on("list-fetch",(n=>{t.getData().getComments().length>0&&(null==e?void 0:e.getIsClearComments(n))&&t.getData().clearComments()})),t.on("list-error",(()=>{var t;null==(t=null==e?void 0:e.showErr)||t.call(e,_("loadFail"))})),t.on("list-fetch",(t=>{null==e||e.setLoading(!0)})),t.on("list-fetched",(({params:t})=>{null==e||e.setLoading(!1)}))};class Le extends zt{constructor(t){super(t),h(this,"$commentsWrap"),h(this,"commentNodes",[]),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"),Te(t),this.initCrudEvents()}getCommentsWrapEl(){return this.$commentsWrap}getCommentNodes(){return this.commentNodes}getListLayout(){return new ee({$commentsWrap:this.$commentsWrap,nestSortBy:this.ctx.conf.nestSort,nestMax:this.ctx.conf.nestMax,flatMode:this.ctx.conf.flatMode,createCommentNode:(t,e)=>{const n=function(t,e,n){var i;const s=new we(t,e,{isFlatMode:null==(i=t.getData().getListLastFetch())?void 0:i.params.flatMode,afterRender:()=>{t.trigger("comment-rendered",s)},onDelete:e=>{t.getData().deleteComment(e.getID())},replyTo:e.rid?n.find((t=>t.id===e.rid)):void 0});return s.render(),s}(this.ctx,t,e);return this.commentNodes.push(n),n},findCommentNode:t=>this.commentNodes.find((e=>e.getID()===t)),getCommentDataList:()=>this.ctx.getData().getComments()})}initCrudEvents(){this.ctx.on("list-load",(t=>{this.getListLayout().import(t)})),this.ctx.on("list-loaded",(t=>{0===t.length&&(this.$commentsWrap.innerHTML="")})),this.ctx.on("comment-inserted",(t=>{this.getListLayout().insert(t)})),this.ctx.on("comment-deleted",(t=>{const e=this.commentNodes.find((e=>e.getID()===t.id));e?(e.getEl().remove(),this.commentNodes=this.commentNodes.filter((e=>e.getID()!==t.id))):console.error(`comment node id=${t.id} not found`)})),this.ctx.on("comment-updated",(t=>{const e=this.commentNodes.find((e=>e.getID()===t.id));e&&e.setData(t)}))}}let Ae,Me;function Oe(){return{init(){Ae=document.body.style.overflow,Me=document.body.style.paddingRight},unlock(){document.body.style.overflow=Ae,document.body.style.paddingRight=Me},lock(){document.body.style.overflow="hidden";const t=parseInt(window.getComputedStyle(document.body,null).getPropertyValue("padding-right"),10);document.body.style.paddingRight=`${function(){const t=document.createElement("p");t.style.width="100%",t.style.height="200px";const e=document.createElement("div");e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.visibility="hidden",e.style.width="200px",e.style.height="150px",e.style.overflow="hidden",e.appendChild(t),document.body.appendChild(e);const n=t.offsetWidth;e.style.overflow="scroll";let i=t.offsetWidth;return n===i&&(i=e.clientWidth),document.body.removeChild(e),n-i}()+t||0}px`}}}class Pe{constructor(){h(this,"$wrap"),h(this,"$mask"),h(this,"allowMaskClose",!0),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(t,e){return e||((e=document.createElement("div")).classList.add("atk-layer-item"),e.setAttribute("data-layer-name",t),e.style.display="none"),this.$wrap.appendChild(e),this.items.push(e),e}getWrap(){return this.$wrap}getMask(){return this.$mask}setMaskClose(t){this.allowMaskClose=t}show(){this.$wrap.style.display="block",this.$mask.style.display="block",this.$mask.classList.add("atk-fade-in"),this.$mask.onclick=()=>{this.allowMaskClose&&this.hide()},Oe().lock()}hide(t){if(this.items.filter((t=>t.isConnected&&"none"!==t.style.display)).length>1)return void(t&&t());const e=()=>{this.$wrap.style.display="none",this.$wrap.classList.remove("atk-fade-out"),t&&t(),Oe().unlock(),this.$wrap.onanimationend=null};this.$wrap.classList.add("atk-fade-out"),"none"!==window.getComputedStyle(this.$wrap)["animation-name"]?this.$wrap.onanimationend=()=>e():e()}}class _e{constructor(t,e,n){h(this,"$el"),h(this,"wrap"),h(this,"onAfterHide"),this.wrap=t,this.$el=this.wrap.createItem(e,n)}setOnAfterHide(t){this.onAfterHide=t}getEl(){return this.$el}show(){this.$el.style.display="",this.wrap.show()}hide(){this.wrap.hide((()=>{this.$el.style.display="none",this.onAfterHide&&this.onAfterHide()}))}destroy(){this.wrap.hide((()=>{this.$el.remove(),this.onAfterHide&&this.onAfterHide()}))}}class Ue{constructor(t){h(this,"wrap"),h(this,"ctx"),this.ctx=t,this.wrap=new Pe,document.body.appendChild(this.wrap.getWrap()),t.on("destroy",(()=>{this.wrap.getWrap().remove()})),Oe().init()}getEl(){return this.wrap.getWrap()}create(t,e){return new _e(this.wrap,t,e)}}const Ie="ArtalkUser";class Re{constructor(t){h(this,"data"),this.opts=t;const e=JSON.parse(window.localStorage.getItem(Ie)||"{}");this.data={nick:e.nick||"",email:e.email||"",link:e.link||"",token:e.token||"",isAdmin:e.isAdmin||!1}}getData(){return this.data}update(t={}){Object.entries(t).forEach((([t,e])=>{this.data[t]=e})),window.localStorage.setItem(Ie,JSON.stringify(this.data)),this.opts.onUserChanged&&this.opts.onUserChanged(this.data)}logout(){this.update({token:"",isAdmin:!1})}checkHasBasicUserInfo(){return!!this.data.nick&&!!this.data.email}}const De={i18n(t){P(t.conf.locale),t.on("conf-loaded",(()=>{P(t.conf.locale)}))},user:t=>new Re({onUserChanged:e=>{t.trigger("user-changed",e)}}),layerManager:t=>new Ue(t),checkerLauncher:t=>new Gt({getCtx:()=>t,getApi:()=>t.getApi(),getIframeURLBase:()=>t.conf.server,onReload:()=>t.reload()}),editor(t){const e=new Zt(t);return t.$root.appendChild(e.$el),e},list(t){const e=new Le(t);return t.$root.appendChild(e.$el),e},sidebarLayer:t=>new te(t),editorPlugs(){}};function Be(t){const e=p(`<span>${t.errMsg},${_("listLoadFailMsg")}<br/></span>`);if(t.retryFn){const n=p(`<span style="cursor:pointer;">${_("listRetry")}</span>`);n.onclick=()=>t.retryFn&&t.retryFn(),e.appendChild(n)}if(t.onOpenSidebar){const n=p(`<span atk-only-admin-show> | <span style="cursor:pointer;">${_("open")+_("ctrlCenter")}</span></span>`);e.appendChild(n),n.onclick=()=>t.onOpenSidebar&&t.onOpenSidebar()}jt(t.$err,e)}function Fe(t){t.getApi().system.conf().then((e=>{let n={apiVersion:e.version.version};if(t.conf.useBackendConf){if(!e.frontend_conf)throw new Error("The remote backend does not respond to the frontend conf, but `useBackendConf` conf is enabled");n=c(c({},n),function(t){const e=["el","pageKey","pageTitle","server","site","darkMode"];return Object.keys(t).forEach((n=>{e.includes(n)&&delete t[n]})),t.emoticons&&"string"==typeof t.emoticons&&(t.emoticons=t.emoticons.trim(),t.emoticons.startsWith("[")||t.emoticons.startsWith("{")?t.emoticons=JSON.parse(t.emoticons):"false"===t.emoticons&&(t.emoticons=!1)),t}(e.frontend_conf))}t.conf.remoteConfModifier&&t.conf.remoteConfModifier(n),t.updateConf(n)})).catch((e=>{var n;t.updateConf({});let i="";if(null==(n=e.data)?void 0:n.err_no_site){const e={create_name:t.conf.site,create_urls:`${window.location.protocol}//${window.location.host}`};i=`sites|${JSON.stringify(e)}`}throw Be({$err:t.get("list").$el,errMsg:e.msg||String(e),errData:e.data,retryFn:()=>Fe(t),onOpenSidebar:t.get("user").getData().isAdmin?()=>t.showSidebar({view:i}):void 0}),e})).then((()=>{t.conf.remoteConfModifier||t.fetch({offset:0})})).catch((()=>{}))}const qe="ArtalkContent";class We{constructor(t){this.kit=t}reqAdd(){return u(this,null,(function*(){return yield this.kit.useApi().comment.add(c({},this.getSubmitAddParams()))}))}getSubmitAddParams(){const{nick:t,email:e,link:n}=this.kit.useUser().getData(),i=this.kit.useConf();return{content:this.kit.useEditor().getContentFinal(),nick:t,email:e,link:n,rid:0,page_key:i.pageKey,page_title:i.pageTitle,site_name:i.site}}postSubmitAdd(t){this.kit.useGlobalCtx().getData().insertComment(t)}}class Ne extends Yt{constructor(t){super(t),h(this,"customs",[]),h(this,"defaultPreset"),this.defaultPreset=new We(this.kit);const e=()=>this.do();this.kit.useMounted((()=>{this.kit.useGlobalCtx().on("editor-submit",e)})),this.kit.useUnmounted((()=>{this.kit.useGlobalCtx().off("editor-submit",e)}))}registerCustom(t){this.customs.push(t)}do(){return u(this,null,(function*(){if(""===this.kit.useEditor().getContentFinal().trim())return void this.kit.useEditor().focus();const t=this.customs.find((t=>t.activeCond()));this.kit.useEditor().showLoading();try{let e;(null==t?void 0:t.pre)&&t.pre(),e=(null==t?void 0:t.req)?yield t.req():yield this.defaultPreset.reqAdd(),(null==t?void 0:t.post)?t.post(e):this.defaultPreset.postSubmitAdd(e)}catch(e){return console.error(e),void this.kit.useEditor().showNotify(`${_("commentFail")},${e.msg||String(e)}`,"e")}finally{this.kit.useEditor().hideLoading()}this.kit.useEditor().reset(),this.kit.useGlobalCtx().trigger("editor-submitted")}))}}class je extends Yt{constructor(t){super(t),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(_("emoticon"))})),this.kit.useUnmounted((()=>{})),this.useContentTransformer((t=>this.transEmoticonImageText(t))),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*(){Bt(this.$panel),this.emoticons=yield this.handleData(this.kit.useConf().emoticons),Ft(this.$panel),this.loadingTask=null,this.isListLoaded=!0})))(),yield this.loadingTask):yield this.loadingTask)}))}handleData(t){return u(this,null,(function*(){if(!Array.isArray(t)&&["object","string"].includes(typeof t)&&(t=[t]),!Array.isArray(t))return jt(this.$panel,"表情包数据必须为 Array/Object/String 类型"),Ft(this.$panel),[];const e=e=>{"object"==typeof e&&(e.name&&t.find((t=>t.name===e.name))||t.push(e))},n=t=>u(this,null,(function*(){yield Promise.all(t.map(((t,i)=>u(this,null,(function*(){if("object"!=typeof t||Array.isArray(t)){if(Array.isArray(t))yield n(t);else if("string"==typeof t){const i=yield this.remoteLoad(t);Array.isArray(i)?yield n(i):"object"==typeof i&&e(i)}}else e(t)})))))}));return yield n(t),t.forEach((t=>{if(this.isOwOFormat(t)){this.convertOwO(t).forEach((t=>{e(t)}))}else Array.isArray(t)&&t.forEach((t=>{e(t)}))})),t=t.filter((t=>"object"==typeof t&&!Array.isArray(t)&&!!t&&!!t.name)),this.solveNullKey(t),this.solveSameKey(t),t}))}remoteLoad(t){return u(this,null,(function*(){if(!t)return[];try{const e=yield fetch(t);return yield e.json()}catch(e){return Ft(this.$panel),console.error("[Emoticons] Load Failed:",e),jt(this.$panel,`${_("emoticon")}${_("loadFail")} ${String(e)}`),[]}}))}solveNullKey(t){t.forEach((t=>{t.items.forEach(((e,n)=>{e.key||(e.key=`${t.name} ${n+1}`)}))}))}solveSameKey(t){const e={};t.forEach((t=>{t.items.forEach((t=>{t.key&&""!==String(t.key).trim()&&(e[t.key]?e[t.key]++:e[t.key]=1,e[t.key]>1&&(t.key=`${t.key} ${e[t.key]}`))}))}))}isOwOFormat(t){try{return"object"==typeof t&&!!Object.values(t).length&&Array.isArray(Object.keys(Object.values(t)[0].container))&&Object.keys(Object.values(t)[0].container[0]).includes("icon")}catch(e){return!1}}convertOwO(t){const e=[];return Object.entries(t).forEach((([t,n])=>{const i={name:t,type:n.type,items:[]};n.container.forEach(((e,n)=>{const s=e.icon;if(/<(img|IMG)/.test(s)){const t=/src=["'](.*?)["']/.exec(s);t&&t.length>1&&(e.icon=t[1])}i.items.push({key:e.text||`${t} ${n+1}`,val:e.icon})})),e.push(i)})),e}initEmoticonsList(){this.$grpWrap=p('<div class="atk-grp-wrap"></div>'),this.$panel.append(this.$grpWrap),this.emoticons.forEach(((t,e)=>{const n=p('<div class="atk-grp" style="display: none;"></div>');this.$grpWrap.append(n),n.setAttribute("data-index",String(e)),n.setAttribute("data-grp-name",t.name),n.setAttribute("data-type",t.type),t.items.forEach((e=>{const i=p('<span class="atk-item"></span>');if(n.append(i),e.key&&!new RegExp(`^(${t.name})?\\s?[0-9]+$`).test(e.key)&&i.setAttribute("title",e.key),"image"===t.type){const t=document.createElement("img");t.src=e.val,t.alt=e.key,i.append(t)}else i.innerText=e.val;i.onclick=()=>{"image"===t.type?this.kit.useEditor().insertContent(`:[${e.key}]`):this.kit.useEditor().insertContent(e.val||"")}}))})),this.emoticons.length>1&&(this.$grpSwitcher=p('<div class="atk-grp-switcher"></div>'),this.$panel.append(this.$grpSwitcher),this.emoticons.forEach(((t,e)=>{const n=p("<span />");n.innerText=t.name,n.setAttribute("data-index",String(e)),n.onclick=()=>this.openGrp(e),this.$grpSwitcher.append(n)}))),this.emoticons.length>0&&this.openGrp(0)}openGrp(t){var e,n,i;Array.from(this.$grpWrap.children).forEach((e=>{const n=e;n.getAttribute("data-index")!==String(t)?n.style.display="none":n.style.display=""})),null==(e=this.$grpSwitcher)||e.querySelectorAll("span.active").forEach((t=>t.classList.remove("active"))),null==(i=null==(n=this.$grpSwitcher)?void 0:n.querySelector(`span[data-index="${t}"]`))||i.classList.add("active"),this.changeListHeight()}changeListHeight(){}transEmoticonImageText(t){return this.emoticons&&Array.isArray(this.emoticons)?(this.emoticons.forEach((e=>{"image"===e.type&&Object.entries(e.items).forEach((([e,n])=>{t=t.split(`:[${n.key}]`).join(`<img src="${n.val}" atk-emoticon="${n.key}">`)}))})),t):t}}const He=["png","jpg","jpeg","gif","bmp","svg","webp"];class Ve extends Yt{constructor(t){super(t),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=He.map((t=>`.${t}`)).join(",");const t=this.useBtn(`${_("image")}`);t.after(this.$imgUploadInput),t.onclick=()=>{const t=this.$imgUploadInput;t.onchange=()=>{(()=>{u(this,null,(function*(){if(!t.files||0===t.files.length)return;const e=t.files[0];this.uploadImg(e)}))})()},t.click()},this.kit.useConf().imgUpload||this.$btn.setAttribute("atk-only-admin-show","")}initDragImg(){const t=t=>{if(t)for(let e=0;e<t.length;e++){const n=t[e];this.uploadImg(n)}},e=t=>{t.stopPropagation(),t.preventDefault()},n=e=>{var n;const i=null==(n=e.dataTransfer)?void 0:n.files;(null==i?void 0:i.length)&&(e.preventDefault(),t(i))},i=e=>{var n;const i=null==(n=e.clipboardData)?void 0:n.files;(null==i?void 0:i.length)&&(e.preventDefault(),t(i))};this.kit.useMounted((()=>{this.kit.useUI().$textarea.addEventListener("dragover",e),this.kit.useUI().$textarea.addEventListener("drop",n),this.kit.useUI().$textarea.addEventListener("paste",i)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("dragover",e),this.kit.useUI().$textarea.removeEventListener("drop",n),this.kit.useUI().$textarea.removeEventListener("paste",i)}))}uploadImg(t){return u(this,null,(function*(){const e=/[^.]+$/.exec(t.name);if(!e||!He.includes(e[0]))return;if(!this.kit.useUser().checkHasBasicUserInfo())return void this.kit.useEditor().showNotify(_("uploadLoginMsg"),"w");let n="\n";""===this.kit.useUI().$textarea.value.trim()&&(n="");const i=`${n}`;let s;this.kit.useEditor().insertContent(i);try{const e=this.kit.useConf().imgUploader;s=e?{img_url:yield e(t)}:yield this.kit.useApi().upload.imgUpload(t)}catch(o){console.error(o),this.kit.useEditor().showNotify(`${_("uploadFail")},${o.msg}`,"e")}if(s&&s.img_url){let t=s.img_url;w(t)||(t=b({base:this.kit.useConf().server,path:t})),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 Ke extends Yt{constructor(t){super(t),h(this,"isPlugPanelShow",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-preview"></div>');let t=_("preview");At()&&(t+=' <i title="Markdown is supported"><svg class="markdown" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M14.85 3H1.15C.52 3 0 3.52 0 4.15v7.69C0 12.48.52 13 1.15 13h13.69c.64 0 1.15-.52 1.15-1.15v-7.7C16 3.52 15.48 3 14.85 3zM9 11H7V8L5.5 9.92 4 8v3H2V5h2l1.5 2L7 5h2v6zm2.99.5L9.5 8H11V5h2v3h1.5l-2.51 3.5z"></path></svg></i>'),this.useBtn(t)})),this.kit.useUnmounted((()=>{})),this.kit.useEvents().on("content-updated",(t=>{this.isPlugPanelShow&&this.updateContent()})),this.usePanelShow((()=>{this.isPlugPanelShow=!0,this.updateContent()})),this.usePanelHide((()=>{this.isPlugPanelShow=!1}))}updateContent(){this.$panel.innerHTML=this.kit.useEditor().getContentMarked()}}const Ge=[class extends Yt{constructor(t){super(t);const e=()=>{this.save()};this.kit.useMounted((()=>{const t=window.localStorage.getItem(qe)||"";""!==t.trim()&&(this.kit.useEditor().showNotify(_("restoredMsg"),"i"),this.kit.useEditor().setContent(t)),this.kit.useEvents().on("content-updated",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("content-updated",e)}))}save(){window.localStorage.setItem(qe,this.kit.useEditor().getContentRaw().trim())}},class extends Yt{get $inputs(){return this.kit.useEditor().getHeaderInputEls()}constructor(t){super(t);const e={},n={},i=(t,e,n)=>()=>{this.kit.useEvents().trigger(t,{field:n,$input:e})};this.kit.useMounted((()=>{Object.entries(this.$inputs).forEach((([t,s])=>{s.addEventListener("input",e[t]=i("header-input",s,t)),s.addEventListener("change",n[t]=i("header-change",s,t))}))})),this.kit.useUnmounted((()=>{Object.entries(this.$inputs).forEach((([t,i])=>{i.removeEventListener("input",e[t]),i.removeEventListener("change",n[t])}))}))}},class extends Yt{constructor(t){super(t),h(this,"query",{timer:null,abortFn:null});const e=({$input:t,field:e})=>{"edit"!==this.kit.useEditor().getState()&&(this.kit.useUser().update({[e]:t.value.trim()}),"nick"!==e&&"email"!==e||this.fetchUserInfo())};this.kit.useMounted((()=>{Object.entries(this.kit.useEditor().getHeaderInputEls()).forEach((([t,e])=>{e.placeholder=`${_(t)}`,e.value=this.kit.useUser().getData()[t]||""})),this.kit.useEvents().on("header-input",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-input",e)}))}fetchUserInfo(){this.kit.useUser().logout(),this.query.timer&&window.clearTimeout(this.query.timer),this.query.abortFn&&this.query.abortFn(),this.query.timer=window.setTimeout((()=>{this.query.timer=null;const{req:t,abort:e}=this.kit.useApi().user.userGet(this.kit.useUser().getData().nick,this.kit.useUser().getData().email);this.query.abortFn=e,t.then((t=>this.onUserInfoFetched(t))).catch((t=>{})).finally((()=>{this.query.abortFn=null}))}),400)}onUserInfoFetched(t){var e;t.is_login||this.kit.useUser().logout(),this.kit.useGlobalCtx().getData().updateUnreads(t.unread),this.kit.useUser().checkHasBasicUserInfo()&&!t.is_login&&(null==(e=t.user)?void 0:e.is_admin)&&this.kit.useGlobalCtx().checkAdmin({onSuccess:()=>{}}),t.user&&t.user.link&&(this.kit.useUI().$link.value=t.user.link,this.kit.useUser().update({link:t.user.link}))}},class extends Yt{constructor(t){super(t);const e=({field:t})=>{"link"===t&&this.onLinkInputChange()};this.kit.useMounted((()=>{this.kit.useEvents().on("header-change",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-change",e)}))}onLinkInputChange(){const t=this.kit.useUI().$link.value.trim();t&&!/^(http|https):\/\//.test(t)&&(this.kit.useUI().$link.value=`https://${t}`,this.kit.useUser().update({link:this.kit.useUI().$link.value}))}},class extends Yt{constructor(t){super(t);const e=t=>this.onKeydown(t),n=()=>this.onInput();this.kit.useMounted((()=>{this.kit.useUI().$textarea.placeholder=this.kit.useConf().placeholder||_("placeholder"),this.kit.useUI().$textarea.addEventListener("keydown",e),this.kit.useUI().$textarea.addEventListener("input",n)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("keydown",e),this.kit.useUI().$textarea.removeEventListener("input",n)})),this.kit.useEvents().on("content-updated",(()=>{window.setTimeout((()=>{this.adaptiveHeightByContent()}),80)}))}onKeydown(t){9===(t.keyCode||t.which)&&(t.preventDefault(),this.kit.useEditor().insertContent("\t"))}onInput(){this.kit.useEvents().trigger("content-updated",this.kit.useEditor().getContentRaw())}adaptiveHeightByContent(){const t=this.kit.useUI().$textarea.offsetHeight-this.kit.useUI().$textarea.clientHeight;this.kit.useUI().$textarea.style.height="0px",this.kit.useUI().$textarea.style.height=`${this.kit.useUI().$textarea.scrollHeight+t}px`}},Ne,class extends Yt{constructor(t){super(t);const e=()=>{this.kit.useEditor().submit()};this.kit.useMounted((()=>{this.kit.useUI().$submitBtn.innerText=this.kit.useConf().sendBtn||_("send"),this.kit.useUI().$submitBtn.addEventListener("click",e)})),this.kit.useUnmounted((()=>{this.kit.useUI().$submitBtn.removeEventListener("click",e)}))}},Xt,class extends Yt{constructor(t){super(t),h(this,"comment"),this.useEditorStateEffect("reply",(t=>(this.setReply(t),()=>{this.cancelReply()}))),this.kit.useEvents().on("mounted",(()=>{const t=this.kit.useDeps(Ne);if(!t)throw Error("SubmitPlug not initialized");const e=new We(this.kit);t.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().comment.add(d(c({},e.getSubmitAddParams()),{rid:this.comment.id,page_key:this.comment.page_key,page_title:void 0,site_name:this.comment.site_name}))})),post:t=>{const n=this.kit.useConf();t.page_key!==n.pageKey&&window.open(`${t.page_url}#atk-comment-${t.id}`),e.postSubmitAdd(t)}})}))}setReply(t){const e=this.kit.useUI();e.$sendReply||(e.$sendReply=p(`<div class="atk-send-reply">${_("reply")} <span class="atk-text"></span><span class="atk-cancel">×</span></div>`),e.$sendReply.querySelector(".atk-text").innerText=`@${t.nick}`,e.$sendReply.addEventListener("click",(()=>{this.kit.useEditor().resetState()})),e.$textareaWrap.append(e.$sendReply)),this.comment=t,e.$textarea.focus()}cancelReply(){if(!this.comment)return;const t=this.kit.useUI();t.$sendReply&&(t.$sendReply.remove(),t.$sendReply=void 0),this.comment=void 0}},class extends Yt{constructor(t){super(t),h(this,"comment"),h(this,"originalSubmitBtnText","Send"),this.useEditorStateEffect("edit",(t=>(this.edit(t),()=>{this.cancelEdit()}))),this.kit.useMounted((()=>{const t=this.kit.useDeps(Ne);if(!t)throw Error("SubmitPlug not initialized");t.registerCustom({activeCond:()=>!!this.comment,req:()=>u(this,null,(function*(){const t={content:this.kit.useEditor().getContentFinal(),nick:this.kit.useUI().$nick.value,email:this.kit.useUI().$email.value,link:this.kit.useUI().$link.value};return yield this.kit.useApi().comment.commentEdit(c(c({},this.comment),t))})),post:t=>{this.kit.useGlobalCtx().getData().updateComment(t)}})}))}edit(t){const e=this.kit.useUI();if(!e.$editCancelBtn){const t=p(`<div class="atk-send-reply">${_("editCancel")} <span class="atk-cancel">×</span></div>`);t.onclick=()=>{this.kit.useEditor().resetState()},e.$textareaWrap.append(t),e.$editCancelBtn=t}this.comment=t,e.$header.style.display="none",e.$nick.value=t.nick||"",e.$email.value=t.email||"",e.$link.value=t.link||"",this.kit.useEditor().setContent(t.content),e.$textarea.focus(),this.updateSubmitBtnText(_("save"))}cancelEdit(){if(!this.comment)return;const t=this.kit.useUI();t.$editCancelBtn&&(t.$editCancelBtn.remove(),t.$editCancelBtn=void 0),this.comment=void 0;const{nick:e,email:n,link:i}=this.kit.useUser().getData();t.$nick.value=e,t.$email.value=n,t.$link.value=i,this.kit.useEditor().setContent(""),this.restoreSubmitBtnText(),t.$header.style.display=""}updateSubmitBtnText(t){this.originalSubmitBtnText=this.kit.useUI().$submitBtn.innerText,this.kit.useUI().$submitBtn.innerText=t}restoreSubmitBtnText(){this.kit.useUI().$submitBtn.innerText=this.originalSubmitBtnText}},class extends Yt{constructor(t){super(t);const e=()=>this.open(),n=()=>this.close();this.kit.useMounted((()=>{this.kit.useEvents().on("editor-open",e),this.kit.useEvents().on("editor-close",n)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("editor-open",e),this.kit.useEvents().off("editor-close",n)}))}open(){var t;null==(t=this.kit.useUI().$textareaWrap.querySelector(".atk-comment-closed"))||t.remove(),this.kit.useUI().$textarea.style.display="",this.kit.useUI().$bottom.style.display=""}close(){this.kit.useUI().$textareaWrap.querySelector(".atk-comment-closed")||this.kit.useUI().$textareaWrap.prepend(p(`<div class="atk-comment-closed">${_("onlyAdminCanReply")}</div>`)),this.kit.useUser().getData().isAdmin?(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")}},je,Ve,Ke];class ze{constructor(t){this.plugs=t}useEditor(){return this.plugs.editor}useGlobalCtx(){return this.plugs.editor.ctx}useConf(){return this.plugs.editor.ctx.conf}useApi(){return this.plugs.editor.ctx.getApi()}useUser(){return this.plugs.editor.ctx.get("user")}useUI(){return this.plugs.editor.getUI()}useEvents(){return this.plugs.getEvents()}useMounted(t){this.useEvents().on("mounted",t)}useUnmounted(t){this.useEvents().on("unmounted",t)}useDeps(t){return this.plugs.get(t)}}class Qe{constructor(t){h(this,"plugs",[]),h(this,"openedPlug",null),h(this,"events",new Pt),this.editor=t;let e=!1;this.editor.ctx.on("conf-loaded",(()=>{e&&this.getEvents().trigger("unmounted"),this.clear();const t=(n=this.editor.ctx.conf,[{k:Ve,v:n.imgUpload},{k:je,v:n.emoticons},{k:Ke,v:n.preview},{k:Xt,v:n.editorTravel}].filter((t=>!t.v)).flatMap((t=>t.k)));var n;Ge.filter((e=>!t.includes(e))).forEach((t=>{const e=new ze(this);this.plugs.push(new t(e))})),this.getEvents().trigger("mounted"),e=!0,this.loadPluginUI()})),this.events.on("panel-close",(()=>this.closePlugPanel()))}getPlugs(){return this.plugs}getEvents(){return this.events}clear(){this.plugs=[],this.events=new Pt,this.openedPlug&&this.closePlugPanel()}loadPluginUI(){this.editor.getUI().$plugPanelWrap.innerHTML="",this.editor.getUI().$plugPanelWrap.style.display="none",this.editor.getUI().$plugBtnWrap.innerHTML="",this.plugs.forEach((t=>this.loadPluginItem(t)))}loadPluginItem(t){const e=t.$btn;if(!e)return;this.editor.getUI().$plugBtnWrap.appendChild(e),!e.onclick&&(e.onclick=()=>{this.editor.getUI().$plugBtnWrap.querySelectorAll(".active").forEach((t=>t.classList.remove("active"))),t!==this.openedPlug?(this.openPlugPanel(t),e.classList.add("active")):this.closePlugPanel()});const n=t.$panel;n&&(n.style.display="none",this.editor.getUI().$plugPanelWrap.appendChild(n))}get(t){return this.plugs.find((e=>e instanceof t))}openPlugPanel(t){this.plugs.forEach((e=>{const n=e.$panel;n&&(e===t?(n.style.display="",this.events.trigger("panel-show",t)):(n.style.display="none",this.events.trigger("panel-hide",t)))})),this.editor.getUI().$plugPanelWrap.style.display="",this.openedPlug=t}closePlugPanel(){this.openedPlug&&(this.editor.getUI().$plugPanelWrap.style.display="none",this.events.trigger("panel-hide",this.openedPlug),this.openedPlug=null)}getTransformedContent(t){let e=t;return this.plugs.forEach((t=>{t.contentTransformer&&(e=t.contentTransformer(e))})),e}}const Ye="2.7.2";function Xe(t){return u(this,null,(function*(){t.countEl&&document.querySelector(t.countEl)&&Je(t,{query:"page_comment",numEl:t.countEl});const e=t.pvAdd?{[t.pageKey]:yield t.getApi().page.pv()}:void 0;t.pvEl&&document.querySelector(t.pvEl)&&Je(t,{query:"page_pv",numEl:t.pvEl,data:e})}))}function Je(t,e){return u(this,null,(function*(){let n=e.data||{},i=Array.from(document.querySelectorAll(e.numEl)).map((e=>e.getAttribute("data-page-key")||t.pageKey)).filter((t=>"number"!=typeof n[t]));if(i=[...new Set(i)],i.length>0){const s=yield t.getApi().page.stat(e.query,i);n=c(c({},n),s)}!function(t,e,n){document.querySelectorAll(t).forEach((t=>{const i=t.getAttribute("data-page-key"),s=Number(i?e[i]:n);t.innerHTML=`${s}`}))}(e.numEl,n,n[t.pageKey])}))}let Ze=!1;let tn;function en(t,e){const n="atk-dark-mode";t.forEach((t=>{e?t.classList.add(n):t.classList.remove(n)}))}const nn=[...[t=>{t.on("inited",(()=>{Fe(t)}))},t=>{!function(){try{if(!e.marked.name)return}catch(t){return}e.marked.setOptions(c({renderer:xt()},Lt)),St=e.marked}(),t.on("conf-loaded",(t=>{var e;t.markedReplacers&&(e=t.markedReplacers,Tt=e)}))},t=>{const e=t.get("editor"),n=new Qe(e);t.inject("editorPlugs",n)},t=>{const e=()=>{var e;e=t.get("user").getData().isAdmin,function(t){const e=[];t.$root.querySelectorAll("[atk-only-admin-show]").forEach((t=>e.push(t)));const n=document.querySelector(".atk-sidebar");return n&&n.querySelectorAll("[atk-only-admin-show]").forEach((t=>e.push(t))),e}({$root:t.$root}).forEach((t=>{e?t.classList.remove("atk-hide"):t.classList.add("atk-hide")}))};t.on("list-loaded",(()=>{e()})),t.on("user-changed",(t=>{e()}))},...[t=>{t.on("list-fetch",(e=>{if(t.getData().getLoading())return;t.getData().setLoading(!0);const n=c({offset:0,limit:t.conf.pagination.pageSize,flatMode:t.conf.flatMode,paramsModifier:t.conf.listFetchParamsModifier},e);t.getData().setListLastFetch({params:n}),t.getApi().comment.get(n.offset,n.limit,n.flatMode,n.paramsModifier).then((e=>{t.getData().setListLastFetch({params:n,data:e}),t.getData().loadComments(e.comments),t.getData().updatePage(e.page),t.getData().updateUnreads(e.unread||[]),n.onSuccess&&n.onSuccess(e),t.trigger("list-fetched",{params:n,data:e})})).catch((e=>{const i={msg:e.msg||String(e),data:e.data};throw n.onError&&n.onError(i),t.trigger("list-error",i),t.trigger("list-fetched",{params:n,error:i}),e})).finally((()=>{t.getData().setLoading(!1)}))}))},t=>{t.on("list-fetch",(e=>{const n=t.get("list");0===e.offset&&qt(!0,n.$el)})),t.on("list-fetched",(()=>{qt(!1,t.get("list").$el)}))},t=>{t.on("comment-rendered",(e=>{if(!0===t.conf.listUnreadHighlight){const n=t.getData().getUnreads(),i=n.find((t=>t.comment_id===e.getID()));i?(e.getRender().setUnread(!0),e.getRender().setOpenAction((()=>{window.open(i.read_link),t.getData().updateUnreads(n.filter((t=>t.comment_id!==e.getID())))}))):e.getRender().setUnread(!1)}})),t.on("list-goto",(e=>{const n=f("atk_notify_key");n&&t.getApi().user.markRead(e,n).then((()=>{t.getData().updateUnreads(t.getData().getUnreads().filter((t=>t.comment_id!==e)))}))}))},t=>{let e;t.on("inited",(()=>{const n=t.get("list");e=n.$el.querySelector('[data-action="admin-close-comment"]'),e.addEventListener("click",(()=>{const e=t.getData().getPage();if(!e)throw new Error("Page data not found");e.admin_only=!e.admin_only,function(t,e){t.editorShowLoading(),t.getApi().page.pageEdit(e).then((e=>{t.getData().updatePage(e)})).catch((e=>{t.editorShowNotify(`${_("editFail")}: ${e.msg||String(e)}`,"e")})).finally((()=>{t.editorHideLoading()}))}(t,e)}))})),t.on("page-loaded",(n=>{var i,s;const o=t.get("editor");!0===(null==n?void 0:n.admin_only)?(null==(i=o.getPlugs())||i.getEvents().trigger("editor-close"),e&&(e.innerText=_("openComment"))):(null==(s=o.getPlugs())||s.getEvents().trigger("editor-open"),e&&(e.innerText=_("closeComment")))})),t.on("list-loaded",(e=>{t.editorResetState()}))},t=>{t.on("list-loaded",(()=>{(()=>{var e,n;const i=t.get("list").$el.querySelector(".atk-comment-count .atk-text");if(!i)return;const s=g(_("counter",{count:`${Number(null==(n=null==(e=t.getData().getListLastFetch())?void 0:e.data)?void 0:n.total)||0}`}));i.innerHTML=s.replace(/(\d+)/,'<span class="atk-comment-count-num">$1</span>')})()})),t.on("comment-inserted",(()=>{const e=t.getData().getListLastFetch();(null==e?void 0:e.data)&&(e.data.total+=1)})),t.on("comment-deleted",(()=>{const e=t.getData().getListLastFetch();(null==e?void 0:e.data)&&(e.data.total-=1)}))},t=>{let e=null;const n=()=>{if(!e)return;const n=t.get("user").getData();if(n.nick&&n.email){e.classList.remove("atk-hide");const t=e.querySelector(".atk-text");t&&(t.innerText=n.isAdmin?_("ctrlCenter"):_("msgCenter"))}else e.classList.add("atk-hide")};t.on("conf-loaded",(()=>{const i=t.get("list");e=i.$el.querySelector('[data-action="open-sidebar"]'),e&&(e.onclick=()=>{t.showSidebar()},n())})),t.on("user-changed",(t=>{n()}))},t=>{let e=null;t.on("conf-loaded",(()=>{const n=t.get("list");e=n.$el.querySelector(".atk-unread-badge")})),t.on("unreads-updated",(t=>{var n;n=t.length||0,e&&(n>0?(e.innerText=`${Number(n||0)}`,e.style.display="block"):e.style.display="none")}))},t=>{const e=e=>{t.conf.listFetchParamsModifier=e,t.reload()},n=t=>{!function(t){const{$dropdownWrap:e,dropdownList:n}=t;if(e.querySelector(".atk-dropdown"))return;e.classList.add("atk-dropdown-wrap"),e.append(p('<span class="atk-arrow-down-icon"></span>'));let i=0;const s=(t,e,n,s)=>{s(),i=t,o.querySelectorAll(".active").forEach((t=>{t.classList.remove("active")})),e.classList.add("active"),o.style.display="none",setTimeout((()=>{o.style.display=""}),80)},o=p('<ul class="atk-dropdown atk-fade-in"></ul>');n.forEach(((t,e)=>{const n=t[0],r=t[1],a=p('<li class="atk-dropdown-item"><span></span></li>'),l=a.querySelector("span");l.innerText=n,l.onclick=()=>{s(e,a,n,r)},o.append(a),e===i&&a.classList.add("active")})),e.append(o)}({$dropdownWrap:t,dropdownList:[[_("sortLatest"),()=>{e((t=>{t.sort_by="date_desc"}))}],[_("sortBest"),()=>{e((t=>{t.sort_by="vote"}))}],[_("sortOldest"),()=>{e((t=>{t.sort_by="date_asc"}))}],[_("sortAuthor"),()=>{e((t=>{t.view_only_admin=!0}))}]]})};t.on("conf-loaded",(()=>{const e=t.get("list").$el.querySelector(".atk-comment-count");e&&(t.conf.listSort?n(e):function(t){var e,n;const{$dropdownWrap:i}=t;i.classList.remove("atk-dropdown-wrap"),null==(e=i.querySelector(".atk-arrow-down-icon"))||e.remove(),null==(n=i.querySelector(".atk-dropdown"))||n.remove()}({$dropdownWrap:e}))}))},t=>{let e=!0;const n=()=>{const n=function(){let t=Number(f("atk_comment"));if(!t){const e=window.location.hash.match(/#atk-comment-([0-9]+)/);if(!e||!e[1]||Number.isNaN(Number(e[1])))return null;t=Number(e[1])}return t||null}();n&&(t.trigger("list-goto",n),e=!0)},i=()=>{e=!1,n()};t.on("inited",(()=>{window.addEventListener("hashchange",i),t.on("list-loaded",n)})),t.on("destroy",(()=>{window.removeEventListener("hashchange",i),t.off("list-loaded",n)}));let s=0;t.on("list-goto",(n=>{if(s===n)return;const i=t.get("list").getCommentNodes().find((t=>t.getID()===n));if(!i)return;s=n,i.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()}));const o=()=>{Wt(i.getEl(),!1),i.getEl().classList.remove("atk-flash-once"),window.setTimeout((()=>{i.getEl().classList.add("atk-flash-once")}),150)};e?window.setTimeout((()=>o()),350):o()}))},t=>{t.on("list-loaded",(e=>{const n=t.get("list"),i=e.length<=0;let s=n.getCommentsWrapEl().querySelector(".atk-list-no-comment");i?s||(s=p('<div class="atk-list-no-comment"></div>'),s.innerHTML=yt(n.ctx.conf.noComment||n.ctx.$t("noComment")),n.getCommentsWrapEl().appendChild(s)):null==s||s.remove()}))},t=>{t.on("conf-loaded",(()=>{const e=t.get("list").$el.querySelector(".atk-copyright");e&&(e.innerHTML=`Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${Ye}">Artalk</a>`)}))},t=>{let e=null;t.on("inited",(()=>{e=window.setInterval((()=>{t.get("list").$el.querySelectorAll("[data-atk-comment-date]").forEach((e=>{const n=e.getAttribute("data-atk-comment-date");e.innerText=y(new Date(Number(n)),t.$t)}))}),3e4)})),t.on("destroy",(()=>{e&&window.clearInterval(e)}))},t=>{t.on("list-fetch",(()=>{jt(t.get("list").$el,null)})),t.on("list-error",(e=>{Be({$err:t.get("list").$el,errMsg:e.msg,errData:e.data,retryFn:()=>t.fetch({offset:0})})}))},t=>{const e=document;let n=null;const i=()=>{null==n||n.disconnect(),n=null};t.on("list-loaded",(()=>{i();const s=t.get("list").getCommentsWrapEl().querySelector(".atk-comment-wrap:nth-last-child(3)");s&&("IntersectionObserver"in window?(s=>{n=new IntersectionObserver((([e])=>{e.isIntersecting&&(i(),t.trigger("list-reach-bottom"))}),{root:e}),n.observe(s)})(s):console.warn("IntersectionObserver api not supported"))})),t.on("destroy",(()=>{i()}))},t=>{const e=()=>{const e=t.get("list"),n=t.conf.scrollRelativeTo&&t.conf.scrollRelativeTo();(n||window).scroll({top:k(e.$el,n).top,left:0})};t.on("inited",(()=>{t.on("list-goto-first",e)})),t.on("destroy",(()=>{t.off("list-goto-first",e)}))}],t=>{t.on("conf-loaded",(()=>{Xe({getApi:()=>t.getApi(),pageKey:t.conf.pageKey,countEl:t.conf.countEl,pvEl:t.conf.pvEl,pvAdd:!0})}))},t=>{t.on("conf-loaded",(()=>{const e=t.get("list");t.conf.apiVersion&&t.conf.versionCheck&&!Ze&&function(t,e,n){const i=function(t,e){const n=t.split("."),i=e.split(".");for(let s=0;s<3;s++){const t=Number(n[s]),e=Number(i[s]);if(t>e)return 1;if(e>t)return-1;if(!Number.isNaN(t)&&Number.isNaN(e))return 1;if(Number.isNaN(t)&&!Number.isNaN(e))return-1}return 0}(e,n);if(0===i)return;const s=p(`<div>${_("updateMsg",{name:_(i<0?"frontend":"backend")})}<br/><br/><span style="color: var(--at-color-meta);">${_("currentVersion")}: ${_("frontend")} ${e} / ${_("backend")} ${n}</span><br/><br/></div>`),o=p(`<span style="cursor:pointer">${_("ignore")}</span>`);o.onclick=()=>{jt(t.$el.parentElement,null),Ze=!0,t.ctx.fetch({offset:0})},s.append(o),jt(t.$el.parentElement,s,'<span class="atk-warn-title">Artalk Warn</span>')}(e,Ye,t.conf.apiVersion)}))},t=>{let e;const n=n=>{const i=[t.$root,t.get("layerManager").getEl()];tn||(tn=window.matchMedia("(prefers-color-scheme: dark)")),"auto"===n?(e||(e=t=>en(i,t.matches),tn.addEventListener("change",e)),en(i,tn.matches)):(e&&(tn.removeEventListener("change",e),e=void 0),en(i,n))};t.on("inited",(()=>n(t.conf.darkMode))),t.on("conf-loaded",(t=>n(t.darkMode))),t.on("dark-mode-changed",(t=>n(t))),t.on("destroy",(()=>{e&&(null==tn||tn.removeEventListener("change",e)),e=void 0}))}]];class sn{constructor(t){h(this,"conf"),h(this,"ctx"),h(this,"$root"),h(this,"plugins",[...nn]),this.conf=Ut(t),this.conf.el instanceof HTMLElement&&(this.$root=this.conf.el),this.ctx=new Rt(this.conf,this.$root),Object.entries(De).forEach((([t,e])=>{const n=e(this.ctx);n&&this.ctx.inject(t,n)})),this.plugins.forEach((t=>{"function"==typeof t&&t(this.ctx)})),this.ctx.trigger("inited")}update(t){return this.ctx.updateConf(t),this}reload(){this.ctx.reload()}destroy(){this.ctx.trigger("destroy"),this.$root.remove()}on(t,e){this.ctx.on(t,e)}off(t,e){this.ctx.off(t,e)}trigger(t,e){this.ctx.trigger(t,e)}setDarkMode(t){this.ctx.setDarkMode(t)}static init(t){return new sn(t)}static use(t){nn.includes(t)||nn.push(t)}static loadCountWidget(t){const e=Ut(t);Xe({getApi:()=>new B(It(e)),pageKey:e.pageKey,countEl:e.countEl,pvEl:e.pvEl,pvAdd:!1})}}const on=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),rn=sn.init,an=sn.use,ln=sn.loadCountWidget;return t.ArtalkType=on,t.default=sn,t.init=rn,t.loadCountWidget=ln,t.use=an,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),t}({},marked);
|
|
2
|
+
//# sourceMappingURL=ArtalkLite.iife.js.map
|