@esershnr/artalk 2.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/Artalk.cjs +11 -0
- package/dist/Artalk.cjs.map +1 -0
- package/dist/Artalk.css +1 -0
- package/dist/Artalk.iife.js +11 -0
- package/dist/Artalk.iife.js.map +1 -0
- package/dist/Artalk.js +11 -0
- package/dist/Artalk.js.map +1 -0
- package/dist/Artalk.mjs +9803 -0
- package/dist/Artalk.mjs.map +1 -0
- package/dist/ArtalkLite.cjs +11 -0
- package/dist/ArtalkLite.cjs.map +1 -0
- package/dist/ArtalkLite.css +1 -0
- package/dist/ArtalkLite.iife.js +11 -0
- package/dist/ArtalkLite.iife.js.map +1 -0
- package/dist/ArtalkLite.js +11 -0
- package/dist/ArtalkLite.js.map +1 -0
- package/dist/ArtalkLite.mjs +7738 -0
- package/dist/ArtalkLite.mjs.map +1 -0
- package/dist/i18n/fr.cjs +1 -0
- package/dist/i18n/fr.d.cts +3 -0
- package/dist/i18n/fr.d.ts +3 -0
- package/dist/i18n/fr.js +1 -0
- package/dist/i18n/fr.mjs +123 -0
- package/dist/i18n/ja.cjs +1 -0
- package/dist/i18n/ja.d.cts +3 -0
- package/dist/i18n/ja.d.ts +3 -0
- package/dist/i18n/ja.js +1 -0
- package/dist/i18n/ja.mjs +123 -0
- package/dist/i18n/ko.cjs +1 -0
- package/dist/i18n/ko.d.cts +3 -0
- package/dist/i18n/ko.d.ts +3 -0
- package/dist/i18n/ko.js +1 -0
- package/dist/i18n/ko.mjs +123 -0
- package/dist/i18n/ru.cjs +1 -0
- package/dist/i18n/ru.d.cts +3 -0
- package/dist/i18n/ru.d.ts +3 -0
- package/dist/i18n/ru.js +1 -0
- package/dist/i18n/ru.mjs +123 -0
- package/dist/i18n/tr.cjs +1 -0
- package/dist/i18n/tr.d.cts +3 -0
- package/dist/i18n/tr.d.ts +3 -0
- package/dist/i18n/tr.js +1 -0
- package/dist/i18n/tr.mjs +123 -0
- package/dist/i18n/zh-TW.cjs +1 -0
- package/dist/i18n/zh-TW.d.cts +3 -0
- package/dist/i18n/zh-TW.d.ts +3 -0
- package/dist/i18n/zh-TW.js +1 -0
- package/dist/i18n/zh-TW.mjs +115 -0
- package/dist/main.d.cts +3225 -0
- package/dist/main.d.ts +3225 -0
- package/package.json +182 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("marked")):"function"==typeof define&&define.amd?define(["exports","marked"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Artalk={},t.marked)}(this,(function(t,e){"use strict";var n=Object.defineProperty,s=Object.defineProperties,i=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,l=(t,e,s)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,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)=>s(t,i(e)),h=(t,e,n)=>l(t,"symbol"!=typeof e?e+"":e,n),u=(t,e,n)=>new Promise(((s,i)=>{var o=t=>{try{r(n.next(t))}catch(e){i(e)}},a=t=>{try{r(n.throw(t))}catch(e){i(e)}},r=t=>t.done?s(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){const e=document.createElement("div");e.innerText=t;return e.innerHTML}function g(t){const e=RegExp(`[?&]${t}=([^&]*)`).exec(window.location.search);return e&&decodeURIComponent(e[1].replace(/\+/g," "))}function f(t,e){const n=t=>{const e=t.getBoundingClientRect(),n=window.pageXOffset||document.documentElement.scrollLeft,s=window.pageYOffset||document.documentElement.scrollTop;return{top:e.top+s,left:e.left+n}},s=n(t);if(!e)return s;const i=n(e);return{top:s.top-i.top,left:s.left-i.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(),s=(new Date).getTime()-n,i=Math.floor(s/864e5);if(0===i){const t=s%864e5,n=Math.floor(t/36e5);if(0===n){const n=t%36e5,s=Math.floor(n/6e4);if(0===s){const t=n%6e4,s=Math.round(t/1e3);return s<10?e("now"):`${s} ${e("seconds")}`}return`${s} ${e("minutes")}`}return`${n} ${e("hours")}`}return i<0?e("now"):i<8?`${i} ${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 k(){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(i){return console.error(i),t}const s=Number(n.platformVersion.split(".")[0]);return"Windows"===e.platform&&s>=13?t.replace(/Windows NT 10.0/,"Windows NT 11.0"):"macOS"===e.platform&&s>=11?t.replace(/(Mac OS X \d+_\d+_\d+|Mac OS X)/,`Mac OS X ${n.platformVersion.replace(/\./g,"_")}`):t}))}function $(t){let e;try{e=new URL(t)}catch(n){return!1}return"http:"===e.protocol||"https:"===e.protocol}function w(t){return e=t.base,n=t.path,`${e.replace(/\/$/,"")}/${n.replace(/^\//,"")}`;var e,n}const E={placeholder:"Leave a comment",noComment:"No Comment",send:"Send",signIn:"Sign in",signUp:"Sign up",save:"Save",nick:"Nickname",email:"Email",link:"Website",emoticon:"Emoji",preview:"Preview",uploadImage:"Upload Image",uploadFail:"Upload Failed",commentFail:"Failed to comment",restoredMsg:"Content has been restored",onlyAdminCanReply:"Only admin can reply",uploadLoginMsg:"Please fill in your name and email to upload",counter:"{count} Comments",sortLatest:"Latest",sortOldest:"Oldest",sortBest:"Best",sortAuthor:"Author",openComment:"Open Comment",closeComment:"Close Comment",listLoadFailMsg:"Failed to load comments",listRetry:"Retry",loadMore:"Load More",admin:"Admin",reply:"Reply",voteUp:"Up",voteDown:"Down",voteFail:"Vote Failed",readMore:"Read More",actionConfirm:"Confirm",collapse:"Collapse",collapsed:"Collapsed",collapsedMsg:"This comment has been collapsed",expand:"Expand",approved:"Approved",pending:"Pending",pendingMsg:"Pending, visible only to commenter.",edit:"Edit",editCancel:"Cancel Edit",delete:"Delete",deleteConfirm:"Confirm",pin:"Pin",unpin:"Unpin",seconds:"seconds ago",minutes:"minutes ago",hours:"hours ago",days:"days ago",now:"just now",adminCheck:"Enter admin password:",captchaCheck:"Enter the CAPTCHA to continue:",confirm:"Confirm",cancel:"Cancel",msgCenter:"Messages",ctrlCenter:"Dashboard",userProfile:"Profile",noAccountPrompt:"Don't have an account?",haveAccountPrompt:"Already have an account?",forgetPassword:"Forget Password",resetPassword:"Reset Password",changePassword:"Change Password",confirmPassword:"Confirm Password",passwordMismatch:"Passwords do not match",verificationCode:"Verification Code",verifySend:"Send Code",verifyResend:"Resend",waitSeconds:"Wait {seconds}s",emailVerified:"Email has been verified",password:"Password",username:"Username",nextStep:"Next Step",skipVerify:"Skip verification",logoutConfirm:"Are you sure to logout?",accountMergeNotice:"Your email has multiple accounts with different id.",accountMergeSelectOne:"Please select one you want to merge all the data into it.",accountMergeConfirm:"All data will be merged into one account, the id is {id}.",dismiss:"Dismiss",merge:"Merge",client:"Client",server:"Server",loading:"Loading",loadFail:"Load Failed",editing:"Editing",editFail:"Edit Failed",deleting:"Deleting",deleteFail:"Delete Failed",reqGot:"Request got",reqAborted:"Request timed out or terminated unexpectedly",updateMsg:"Please update Artalk {name} to get the best experience!",currentVersion:"Current Version",ignore:"Ignore",open:"Open",openName:"Open {name}"},C="ArtalkI18n",b={en:E,"en-US":E,"zh-CN":{placeholder:"键入内容...",noComment:"「此时无声胜有声」",send:"发送",signIn:"登录",signUp:"注册",save:"保存",nick:"昵称",email:"邮箱",link:"网址",emoticon:"表情",preview:"预览",uploadImage:"上传图片",uploadFail:"上传失败",commentFail:"评论失败",restoredMsg:"内容已自动恢复",onlyAdminCanReply:"仅管理员可评论",uploadLoginMsg:"填入你的名字邮箱才能上传哦",counter:"{count} 条评论",sortLatest:"最新",sortOldest:"最早",sortBest:"最热",sortAuthor:"作者",openComment:"打开评论",closeComment:"关闭评论",listLoadFailMsg:"无法获取评论列表数据",listRetry:"点击重新获取",loadMore:"加载更多",admin:"管理员",reply:"回复",voteUp:"赞同",voteDown:"反对",voteFail:"投票失败",readMore:"阅读更多",actionConfirm:"确认操作",collapse:"折叠",collapsed:"已折叠",collapsedMsg:"该评论已被系统或管理员折叠",expand:"展开",approved:"已审",pending:"待审",pendingMsg:"审核中,仅本人可见。",edit:"编辑",editCancel:"取消编辑",delete:"删除",deleteConfirm:"确认删除",pin:"置顶",unpin:"取消置顶",seconds:"秒前",minutes:"分钟前",hours:"小时前",days:"天前",now:"刚刚",adminCheck:"键入密码来验证管理员身份:",captchaCheck:"键入验证码继续:",confirm:"确认",cancel:"取消",msgCenter:"通知中心",ctrlCenter:"控制中心",userProfile:"个人资料",noAccountPrompt:"没有账号?",haveAccountPrompt:"已有账号?",forgetPassword:"忘记密码",resetPassword:"重置密码",changePassword:"修改密码",confirmPassword:"确认密码",passwordMismatch:"两次输入的密码不一致",verificationCode:"验证码",verifySend:"发送验证码",verifyResend:"重新发送",waitSeconds:"等待 {seconds}秒",emailVerified:"邮箱已验证",password:"密码",username:"用户名",nextStep:"下一步",skipVerify:"跳过验证",logoutConfirm:"确定要退出登录吗?",accountMergeNotice:"您的电子邮件下有多个不同 ID 的账户。",accountMergeSelectOne:"请选择将所有数据合并到其中的一个。",accountMergeConfirm:"所有数据将合并到 ID 为 {id} 的账户中。",dismiss:"忽略",merge:"合并",client:"客户端",server:"服务器",loading:"加载中",loadFail:"加载失败",editing:"修改中",editFail:"修改失败",deleting:"删除中",deleteFail:"删除失败",reqGot:"请求响应",reqAborted:"请求超时或意外终止",updateMsg:"请更新 Artalk {name} 以获得更好的体验!",currentVersion:"当前版本",ignore:"忽略",open:"打开",openName:"打开{name}"}};function S(t){return t=t.replace(/^([a-zA-Z]+)(-[a-zA-Z]+)?$/,((t,e,n)=>e.toLowerCase()+(n||"").toUpperCase())),b[t]?b[t]:window[C]&&window[C][t]?window[C][t]:b.en}let x="en",T=S(x);function L(t,e={}){let n=(null==T?void 0:T[t])||t;return n=n.replace(/\{\s*(\w+?)\s*\}/g,((t,n)=>e[n]||"")),m(n)}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function A(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var M={"&":"&","<":"<",">":">",'"':""","'":"'"},P={"&":"&","<":"<",">":">",""":'"',"'":"'"},U=/(&|<|>|"|')/g,j=/[&<>"']/g;function O(t){return M[t]}function I(t){return P[t]}function D(t){return null==t?"":String(t).replace(j,O)}function q(t){return null==t?"":String(t).replace(U,I)}D.options=q.options={};var B={encode:D,escape:D,decode:q,unescape:q,version:"1.0.0-browser"};var R=function t(e){for(var n,s,i=Array.prototype.slice.call(arguments,1);i.length;)for(s in n=i.shift())n.hasOwnProperty(s)&&("[object Object]"===Object.prototype.toString.call(e[s])?e[s]=t(e[s],n[s]):e[s]=n[s]);return e},_=function(t){return"string"==typeof t?t.toLowerCase():t};function F(t,e){return t[e]=!0,t}var W=function(t){return t.reduce(F,{})},N={uris:W(["background","base","cite","href","longdesc","src","usemap"])},H={voids:W(["area","br","col","hr","img","wbr","input","base","basefont","link","meta"])},V=B,z=_,K=H,Q=/^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)\s*>/,G=/^<\s*\/\s*([\w:-]+)[^>]*>/,Y=/([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g,J=/^</,X=/^<\s*\//;var Z=B,tt=_,et=N,nt=H;var st=R,it=function(t,e){for(var n,s=function(){var t=[];return t.lastItem=function(){return t[t.length-1]},t}(),i=t;t;)o();function o(){n=!0,function(){"\x3c!--"===t.substr(0,4)?(s=t.indexOf("--\x3e"))>=0&&(e.comment&&e.comment(t.substring(4,s)),t=t.substring(s+3),n=!1):X.test(t)?a(G,l):J.test(t)&&a(Q,r);var s;!function(){if(!n)return;var s,i=t.indexOf("<");i>=0?(s=t.substring(0,i),t=t.substring(i)):(s=t,t="");e.chars&&e.chars(s)}()}();var s=t===i;i=t,s&&(t="")}function a(e,s){var i=t.match(e);i&&(t=t.substring(i[0].length),i[0].replace(e,s),n=!1)}function r(t,n,i,o){var a={},r=z(n),l=K.voids[r]||!!o;i.replace(Y,(function(t,e,n,s,i){a[e]=void 0===n&&void 0===s&&void 0===i?void 0:V.decode(n||s||i||"")})),l||s.push(r),e.start&&e.start(r,a,l)}function l(t,n){var i,o=0,a=z(n);if(a)for(o=s.length-1;o>=0&&s[o]!==a;o--);if(o>=0){for(i=s.length-1;i>=o;i--)e.end&&e.end(s[i]);s.length=o}}l()},ot=function(t,e){var n,s=e||{};return r(),{start:function(t,e,a){var r=tt(t);if(n.ignoring)return void o(r);if(-1===(s.allowedTags||[]).indexOf(r))return void o(r);if(s.filter&&!s.filter({tag:r,attrs:e}))return void o(r);i("<"),i(r),Object.keys(e).forEach((function(t){var n=e[t],o=(s.allowedClasses||{})[r]||[],a=(s.allowedAttributes||{})[r]||[],l=tt(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!==et.uris[l]||function(t){var e=t[0];if("#"===e||"/"===e)return!0;var n=t.indexOf(":");if(-1===n)return!0;var i=t.indexOf("?");if(-1!==i&&n>i)return!0;var o=t.indexOf("#");return-1!==o&&n>o||s.allowedSchemes.some(a);function a(e){return 0===t.indexOf(e+":")}}(n)))&&(i(" "),i(t),"string"==typeof n&&(i('="'),i(Z.encode(n)),i('"')))})),i(a?"/>":">")},end:function(t){var e=tt(t);-1!==(s.allowedTags||[]).indexOf(e)&&!1===n.ignoring?(i("</"),i(e),i(">")):a(e)},chars:function(t){!1===n.ignoring&&i(s.transformText?s.transformText(t):t)}};function i(e){t.push(e)}function o(t){nt.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}}},at={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 rt(t,e,n){var s=[],i=!0===n?e:st({},at,e),o=ot(s,i);return it(t,o),s.join("")}rt.defaults=at;const lt=A(rt),ct={allowedClasses:{},allowedSchemes:["http","https","mailto","data"],allowedTags:["a","abbr","article","b","blockquote","br","caption","code","del","details","div","em","h1","h2","h3","h4","h5","h6","hr","i","img","ins","kbd","li","main","mark","ol","p","pre","section","span","strike","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],allowedAttributes:{"*":["title","accesskey"],a:["href","name","target","aria-label","rel"],img:["src","alt","title","atk-emoticon","aria-label","data-src","class","loading"],code:["class"],span:["class","style"]},filter:t=>([["code",/^hljs\W+language-(.*)$/],["span",/^(hljs-.*)$/],["img",/^lazyload$/]].forEach((([e,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 dt(t){return lt(t,ct)}var ht={exports:{}};ht.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 s(t){return'<span style="color: slategray">'+t+"</span>"}return function(t,i){void 0===i&&(i={});var o=i.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 s(n);if("<"===e)return"<";var i;r[e]?i=r[e]:(i=o[a],r[e]=i);var l='<span style="color: #'+i+'">'+e+"</span>";return a=++a%o.length,l}))}}();const ut=A(ht.exports);function pt(t){return ut(t)}function mt(t){const n=new e.marked.Renderer;return n.link=gt(n,n.link),n.code=ft(),n.image=vt(n,n.image,t),n}const gt=(t,e)=>n=>{const s=(t=>{try{return new URL(t).origin}catch(e){return""}})(n.href)===window.location.origin;return e.call(t,n).replace(/^<a /,`<a target="_blank" ${s?"":'rel="noreferrer noopener nofollow"'} `)},ft=()=>({lang:t,text:e})=>{const n=t||"plaintext";let s=e;return window.hljs?n&&window.hljs.getLanguage(n)&&(s=window.hljs.highlight(n,e).value):s=pt(e),`<pre rel="${n}">\n<code class="hljs language-${n}">${s.replace(/&/g,"&")}</code>\n</pre>`},vt=(t,e,{imgLazyLoad:n})=>s=>{const i=e.call(t,s);return n?"native"===n||!0===n?i.replace(/^<img /,'<img class="lazyload" loading="lazy" '):"data-src"===n?i.replace(/^<img /,'<img class="lazyload" ').replace("src=","data-src="):i:i};let yt,kt=[];const $t={gfm:!0,breaks:!0,async:!1};function wt(){return yt}function Et(t){var e;let n=null==(e=wt())?void 0:e.parse(t);n||(n=function(t){return t.replace(/```\s*([^]+?.*?[^]+?[^]+?)```/g,((t,e)=>`<pre><code>${pt(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 s=dt(n);return kt.forEach((t=>{"function"==typeof t&&(s=t(s))})),s}class Ct{constructor(t){h(this,"_deps",function(){const t=new Map,e=new Map,n=s=>{const i=t.get(s);if(!i)throw new Error(`No provide for ${String(s)}`);if("singleton"===i.lifecycle&&e.has(s))return e.get(s);const{impl:o,deps:a}=i,r=o(...a.map((t=>n(t))));return e.set(s,r),r};return{provide:(e,n,s,i={})=>{t.set(e,{impl:n,deps:s||[],lifecycle:i.lifecycle||"singleton"})},inject:n}}()),h(this,"provide",((t,e,n,s)=>{this._deps.provide(t,e,n,s)})),h(this,"inject",(t=>this._deps.inject(t))),h(this,"get",this.inject),h(this,"on",((t,e)=>{this.inject("events").on(t,e)})),h(this,"off",((t,e)=>{this.inject("events").off(t,e)})),h(this,"trigger",((t,e)=>{this.inject("events").trigger(t,e)})),h(this,"getCommentList",this.getCommentNodes),h(this,"getCommentDataList",this.getComments),this._$root=t}getEl(){return this._$root}destroy(){for(this.trigger("unmounted");this._$root.firstChild;)this._$root.removeChild(this._$root.firstChild)}getConf(){return this.inject("config").get()}updateConf(t){this.inject("config").update(t)}watchConf(t,e){this.inject("config").watchConf(t,e)}getMarked(){return wt()}setDarkMode(t){this.updateConf({darkMode:t})}get conf(){return this.getConf()}set conf(t){console.error("Cannot set config directly, please call updateConf()")}get $root(){return this.getEl()}set $root(t){console.error("set $root is prohibited")}$t(t,e={}){return L(t,e)}getApi(){return this.inject("api")}getApiHandlers(){return this.inject("apiHandlers")}getUser(){return this.inject("user")}getData(){return this.inject("data")}fetch(t){this.getData().fetchComments(t)}reload(){this.getData().fetchComments({offset:0})}listGotoFirst(){this.trigger("list-goto-first")}getCommentNodes(){return this.inject("list").getCommentNodes()}getComments(){return this.getData().getComments()}replyComment(t,e){this.inject("editor").setReplyComment(t,e)}editComment(t,e){this.inject("editor").setEditComment(t,e)}editorShowLoading(){this.inject("editor").showLoading()}editorHideLoading(){this.inject("editor").hideLoading()}editorShowNotify(t,e){this.inject("editor").showNotify(t,e)}editorResetState(){this.inject("editor").resetState()}showSidebar(t){this.inject("sidebar").show(t)}hideSidebar(){this.inject("sidebar").hide()}checkAdmin(t){return this.inject("checkers").checkAdmin(t)}checkCaptcha(t){return this.inject("checkers").checkCaptcha(t)}}function bt(...t){const e=t=>t&&"object"==typeof t&&t.constructor===Object;return t.reduce(((t,n)=>(Object.keys(null!=n?n:{}).forEach((s=>{if("__proto__"===s||"constructor"===s||"prototype"===s)return;const i=t[s],o=n[s];Array.isArray(i)&&Array.isArray(o)?t[s]=i.concat(...o):e(i)&&e(o)?t[s]=bt(i,o):t[s]=o})),t)),{})}const St={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",pageVote:!0,vote:!0,voteDown:!1,uaBadge:!0,listSort:!0,preview:!0,countEl:".artalk-comment-count",pvEl:".artalk-pv-count",statPageKeyAttr:"data-page-key",gravatar:{mirror:"https://www.gravatar.com/avatar/",params:"sha256=1&d=mp&s=240"},pagination:{pageSize:20,readMore:!0,autoLoad:!0},heightLimit:{content:300,children:400,scrollable:!1},imgUpload:!0,imgLazyLoad:!1,reqTimeout:15e3,versionCheck:!0,useBackendConf:!0,preferRemoteConf:!1,listUnreadHighlight:!1,pvAdd:!0,fetchCommentsOnInit:!0,locale:"en",apiVersion:"",pluginURLs:[],markedReplacers:[],markedOptions:{}};function xt(t,e=!1){const n=e?bt(St,t):t;return""===n.pageKey&&(n.pageKey=`${window.location.pathname}`),""===n.pageTitle&&(n.pageTitle=`${document.title}`),n.server&&(n.server=n.server.replace(/\/$/,"").replace(/\/api\/?$/,"")),"auto"===n.locale&&(n.locale=navigator.language),"auto"===n.flatMode&&(n.flatMode=window.matchMedia("(max-width: 768px)").matches),"number"==typeof n.nestMax&&Number(n.nestMax)<=1&&(n.flatMode=!0),n}function Tt(t,e,n){return{baseURL:`${t.server}/api/v2`,siteName:t.site||"",pageKey:t.pageKey||"",pageTitle:t.pageTitle||"",timeout:t.reqTimeout,getApiToken:()=>null==e?void 0:e.getData().token,userInfo:(null==e?void 0:e.checkHasBasicUserInfo())?{name:null==e?void 0:e.getData().name,email:null==e?void 0:e.getData().email}:void 0,handlers:n}}function Lt(t){return u(this,null,(function*(){yield function(t){return u(this,null,(function*(){yield At({opt:t,query:"page_comment",containers:[t.countEl,"#ArtalkCount"]})}))}(t);const e=yield function(t){return u(this,null,(function*(){if(!t.pvAdd||!t.pageKey)return;const e=(yield t.getApi().pages.logPv({page_key:t.pageKey,page_title:t.pageTitle,site_name:t.siteName})).data.pv;return{[t.pageKey]:e}}))}(t);yield function(t,e){return u(this,null,(function*(){yield At({opt:t,query:"page_pv",containers:[t.pvEl,"#ArtalkPV"],cache:e})}))}(t,e)}))}function At(t){return u(this,null,(function*(){const{opt:e}=t;let n=t.cache||{};const s=function(t){const e=new Set;return new Set(t).forEach((t=>{document.querySelectorAll(t).forEach((t=>e.add(t)))})),e}(t.containers),i=function(t,e,n,s){const i=Array.from(t).map((t=>t.getAttribute(e)||n)).filter((t=>t&&"number"!=typeof s[t]));return[...new Set(i)]}(s,e.pageKeyAttr,e.pageKey,n);if(i.length>0){const s=(yield e.getApi().stats.getStats(t.query,{page_keys:i.join(","),site_name:e.siteName})).data.data;n=c(c({},n),s)}!function(t,e,n){t.forEach((t=>{const s=t.getAttribute("data-page-key"),i=s&&e[s]||n&&e[n]||0;t.innerText=`${Number(i)}`}))}(s,n,e.pageKey)}))}class Mt{constructor(t={}){h(this,"baseUrl","/api/v2"),h(this,"securityData",null),h(this,"securityWorker"),h(this,"abortControllers",new Map),h(this,"customFetch",((...t)=>fetch(...t))),h(this,"baseApiParams",{credentials:"same-origin",headers:{},redirect:"follow",referrerPolicy:"no-referrer"}),h(this,"setSecurityData",(t=>{this.securityData=t})),h(this,"contentFormatters",{"application/json":t=>null===t||"object"!=typeof t&&"string"!=typeof t?t:JSON.stringify(t),"text/plain":t=>null!==t&&"string"!=typeof t?JSON.stringify(t):t,"multipart/form-data":t=>Object.keys(t||{}).reduce(((e,n)=>{const s=t[n];return e.append(n,s instanceof Blob?s:"object"==typeof s&&null!==s?JSON.stringify(s):`${s}`),e}),new FormData),"application/x-www-form-urlencoded":t=>this.toQueryString(t)}),h(this,"createAbortSignal",(t=>{if(this.abortControllers.has(t)){const e=this.abortControllers.get(t);return e?e.signal:void 0}const e=new AbortController;return this.abortControllers.set(t,e),e.signal})),h(this,"abortRequest",(t=>{const e=this.abortControllers.get(t);e&&(e.abort(),this.abortControllers.delete(t))})),h(this,"request",(t=>u(this,null,(function*(){var e=t,{body:n,secure:s,path:i,type:l,query:h,format:p,baseUrl:m,cancelToken:g}=e,f=((t,e)=>{var n={};for(var s in t)a.call(t,s)&&e.indexOf(s)<0&&(n[s]=t[s]);if(null!=t&&o)for(var s of o(t))e.indexOf(s)<0&&r.call(t,s)&&(n[s]=t[s]);return n})(e,["body","secure","path","type","query","format","baseUrl","cancelToken"]);const v=("boolean"==typeof s?s:this.baseApiParams.secure)&&this.securityWorker&&(yield this.securityWorker(this.securityData))||{},y=this.mergeRequestParams(f,v),k=h&&this.toQueryString(h),$=this.contentFormatters[l||"application/json"],w=p||y.format;return this.customFetch(`${m||this.baseUrl||""}${i}${k?`?${k}`:""}`,d(c({},y),{headers:c(c({},y.headers||{}),l&&"multipart/form-data"!==l?{"Content-Type":l}:{}),signal:(g?this.createAbortSignal(g):y.signal)||null,body:null==n?null:$(n)})).then((t=>u(this,null,(function*(){const e=t.clone();e.data=null,e.error=null;const n=w?yield t[w]().then((t=>(e.ok?e.data=t:e.error=t,e))).catch((t=>(e.error=t,e))):e;if(g&&this.abortControllers.delete(g),!t.ok)throw n;return n}))))})))),Object.assign(this,t)}encodeQueryParam(t,e){return`${encodeURIComponent(t)}=${encodeURIComponent("number"==typeof e?e:`${e}`)}`}addQueryParam(t,e){return this.encodeQueryParam(e,t[e])}addArrayQueryParam(t,e){return t[e].map((t=>this.encodeQueryParam(e,t))).join("&")}toQueryString(t){const e=t||{};return Object.keys(e).filter((t=>void 0!==e[t])).map((t=>Array.isArray(e[t])?this.addArrayQueryParam(e,t):this.addQueryParam(e,t))).join("&")}addQueryParams(t){const e=this.toQueryString(t);return e?`?${e}`:""}mergeRequestParams(t,e){return d(c(c(c({},this.baseApiParams),t),e||{}),{headers:c(c(c({},this.baseApiParams.headers||{}),t.headers||{}),e&&e.headers||{})})}}
|
|
2
|
+
/**
|
|
3
|
+
* @title Artalk API
|
|
4
|
+
* @version 2.0
|
|
5
|
+
* @license MIT (https://github.com/ArtalkJS/Artalk/blob/master/LICENSE)
|
|
6
|
+
* @baseUrl /api/v2
|
|
7
|
+
* @contact API Support <artalkjs@gmail.com> (https://artalk.js.org)
|
|
8
|
+
*
|
|
9
|
+
* Artalk is a modern comment system based on Golang.
|
|
10
|
+
*/let Pt=class extends Mt{constructor(){super(...arguments),h(this,"auth",{loginByEmail:(t,e={})=>this.request(c({path:"/auth/email/login",method:"POST",body:t,type:"application/json",format:"json"},e)),registerByEmail:(t,e={})=>this.request(c({path:"/auth/email/register",method:"POST",body:t,type:"application/json",format:"json"},e)),sendVerifyEmail:(t,e={})=>this.request(c({path:"/auth/email/send",method:"POST",body:t,type:"application/json",format:"json"},e)),checkDataMerge:(t={})=>this.request(c({path:"/auth/merge",method:"GET",secure:!0,format:"json"},t)),applyDataMerge:(t,e={})=>this.request(c({path:"/auth/merge",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e))}),h(this,"cache",{flushCache:(t={})=>this.request(c({path:"/cache/flush",method:"POST",secure:!0,format:"json"},t)),warmUpCache:(t={})=>this.request(c({path:"/cache/warm_up",method:"POST",secure:!0,format:"json"},t))}),h(this,"captcha",{getCaptcha:(t={})=>this.request(c({path:"/captcha",method:"GET",format:"json"},t)),getCaptchaStatus:(t={})=>this.request(c({path:"/captcha/status",method:"GET",format:"json"},t)),verifyCaptcha:(t,e={})=>this.request(c({path:"/captcha/verify",method:"POST",body:t,type:"application/json",format:"json"},e))}),h(this,"comments",{getComments:(t,e={})=>this.request(c({path:"/comments",method:"GET",query:t,secure:!0,type:"application/json",format:"json"},e)),createComment:(t,e={})=>this.request(c({path:"/comments",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),getComment:(t,e={})=>this.request(c({path:`/comments/${t}`,method:"GET",type:"application/json",format:"json"},e)),updateComment:(t,e,n={})=>this.request(c({path:`/comments/${t}`,method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},n)),deleteComment:(t,e={})=>this.request(c({path:`/comments/${t}`,method:"DELETE",secure:!0,format:"json"},e))}),h(this,"conf",{conf:(t={})=>this.request(c({path:"/conf",method:"GET",format:"json"},t)),getSocialLoginProviders:(t={})=>this.request(c({path:"/conf/auth/providers",method:"GET",format:"json"},t)),getDomain:(t,e={})=>this.request(c({path:"/conf/domain",method:"GET",query:t,format:"json"},e))}),h(this,"notifies",{getNotifies:(t,e={})=>this.request(c({path:"/notifies",method:"GET",query:t,type:"application/json",format:"json"},e)),markAllNotifyRead:(t,e={})=>this.request(c({path:"/notifies/read",method:"POST",body:t,type:"application/json",format:"json"},e)),markNotifyRead:(t,e,n={})=>this.request(c({path:`/notifies/${t}/${e}`,method:"POST",format:"json"},n))}),h(this,"pages",{getPages:(t,e={})=>this.request(c({path:"/pages",method:"GET",query:t,secure:!0,type:"application/json",format:"json"},e)),fetchAllPages:(t,e={})=>this.request(c({path:"/pages/fetch",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),getPageFetchStatus:(t={})=>this.request(c({path:"/pages/fetch/status",method:"GET",secure:!0,format:"json"},t)),logPv:(t,e={})=>this.request(c({path:"/pages/pv",method:"POST",body:t,type:"application/json",format:"json"},e)),updatePage:(t,e,n={})=>this.request(c({path:`/pages/${t}`,method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},n)),deletePage:(t,e={})=>this.request(c({path:`/pages/${t}`,method:"DELETE",secure:!0,format:"json"},e)),fetchPage:(t,e={})=>this.request(c({path:`/pages/${t}/fetch`,method:"POST",secure:!0,type:"application/json",format:"json"},e))}),h(this,"sendEmail",{sendEmail:(t,e={})=>this.request(c({path:"/send_email",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e))}),h(this,"settings",{getSettings:(t={})=>this.request(c({path:"/settings",method:"GET",secure:!0,format:"json"},t)),applySettings:(t,e={})=>this.request(c({path:"/settings",method:"PUT",body:t,secure:!0,type:"application/json",format:"json"},e)),getSettingsTemplate:(t,e={})=>this.request(c({path:`/settings/template/${t}`,method:"GET",secure:!0,format:"json"},e))}),h(this,"sites",{getSites:(t={})=>this.request(c({path:"/sites",method:"GET",secure:!0,format:"json"},t)),createSite:(t,e={})=>this.request(c({path:"/sites",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),updateSite:(t,e,n={})=>this.request(c({path:`/sites/${t}`,method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},n)),deleteSite:(t,e={})=>this.request(c({path:`/sites/${t}`,method:"DELETE",secure:!0,format:"json"},e))}),h(this,"stats",{getStats:(t,e,n={})=>this.request(c({path:`/stats/${t}`,method:"GET",query:e,type:"application/json",format:"json"},n))}),h(this,"transfer",{exportArtrans:(t={})=>this.request(c({path:"/transfer/export",method:"GET",secure:!0,format:"json"},t)),importArtrans:(t,e={})=>this.request(c({path:"/transfer/import",method:"POST",body:t,secure:!0,type:"application/json"},e)),uploadArtrans:(t,e={})=>this.request(c({path:"/transfer/upload",method:"POST",body:t,secure:!0,type:"multipart/form-data",format:"json"},e))}),h(this,"upload",{upload:(t,e={})=>this.request(c({path:"/upload",method:"POST",body:t,secure:!0,type:"multipart/form-data",format:"json"},e))}),h(this,"user",{getUser:(t,e={})=>this.request(c({path:"/user",method:"GET",query:t,secure:!0,format:"json"},e)),updateProfile:(t,e={})=>this.request(c({path:"/user",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),login:(t,e={})=>this.request(c({path:"/user/access_token",method:"POST",body:t,type:"application/json",format:"json"},e)),getUserStatus:(t,e={})=>this.request(c({path:"/user/status",method:"GET",query:t,secure:!0,format:"json"},e))}),h(this,"users",{createUser:(t,e={})=>this.request(c({path:"/users",method:"POST",body:t,secure:!0,type:"application/json",format:"json"},e)),updateUser:(t,e,n={})=>this.request(c({path:`/users/${t}`,method:"PUT",body:e,secure:!0,type:"application/json",format:"json"},n)),deleteUser:(t,e={})=>this.request(c({path:`/users/${t}`,method:"DELETE",secure:!0,format:"json"},e)),getUsers:(t,e,n={})=>this.request(c({path:`/users/${t}`,method:"GET",query:e,secure:!0,type:"application/json",format:"json"},n))}),h(this,"version",{getVersion:(t={})=>this.request(c({path:"/version",method:"GET",format:"json"},t))}),h(this,"votes",{syncVotes:(t={})=>this.request(c({path:"/votes/sync",method:"POST",secure:!0,format:"json"},t)),getVote:(t,e,n={})=>this.request(c({path:`/votes/${t}/${e}`,method:"GET",type:"application/json",format:"json"},n)),createVote:(t,e,n,s,i={})=>this.request(c({path:`/votes/${t}/${e}/${n}`,method:"POST",body:s,type:"application/json",format:"json"},i))})}};const Ut=(t,e,n)=>u(this,null,(function*(){const s=t.getApiToken&&t.getApiToken(),i=new Headers(c({Authorization:s?`Bearer ${s}`:""},null==n?void 0:n.headers));i.get("Authorization")||i.delete("Authorization");const o=yield fetch(e,d(c({},n),{headers:i}));if(!o.ok){const s=(yield o.json().catch((()=>{})))||{};let i=!1;if(t.handlers&&(yield t.handlers.get().reduce(((t,e)=>u(this,null,(function*(){yield t,!0===s[e.action]&&(yield e.handler(s),i=!0)}))),Promise.resolve())),i)return Ut(t,e,n);throw function(t,e){const n=new jt;return n.message=e.msg||e.message||"fetch error",n.code=t,n.data=e,console.error(n),n}(o.status,s)}return o}));class jt extends Error{constructor(){super(...arguments),h(this,"code",0),h(this,"message","fetch error"),h(this,"data")}}class Ot extends Pt{constructor(t){super({baseUrl:t.baseURL,customFetch:(e,n)=>Ut(t,e,n)}),h(this,"_opts"),this._opts=t}getUserFields(){const t=this._opts.userInfo;if((null==t?void 0:t.name)&&(null==t?void 0:t.email))return{name:t.name,email:t.email}}}class It{constructor(t){h(this,"$btn"),h(this,"$panel"),h(this,"editorStateEffectWhen"),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}}const Dt="ArtalkContent";class qt{constructor(t){this.kit=t}reqAdd(){return u(this,null,(function*(){return(yield this.kit.useApi().comments.createComment(c({},yield this.getSubmitAddParams()))).data}))}getSubmitAddParams(){return u(this,null,(function*(){const{name:t,email:e,link:n}=this.kit.useUser().getData(),s=this.kit.useConf();return{content:this.kit.useEditor().getContentFinal(),name:t,email:e,link:n,rid:0,page_key:s.pageKey,page_title:s.pageTitle,site_name:s.site,ua:yield k()}}))}postSubmitAdd(t){this.kit.useData().insertComment(t)}}class Bt extends It{constructor(t){super(t),h(this,"customs",[]),h(this,"defaultPreset"),this.defaultPreset=new qt(this.kit);const e=()=>this.do();this.kit.useMounted((()=>{this.kit.useEvents().on("editor-submit",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().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(`${L("commentFail")}: ${e.message||String(e)}`,"e")}finally{this.kit.useEditor().hideLoading()}this.kit.useEditor().reset(),this.kit.useEvents().trigger("editor-submitted")}))}}class Rt extends It{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.useArtalkRootEl().querySelector(".atk-editor-travel-placeholder"))||t.replaceWith(this.kit.useUI().$el),this.kit.useUI().$el.classList.remove("editor-traveling"))}}function _t(t,e){let n=t.querySelector(":scope > .atk-loading");n||(n=p('<div class="atk-loading" style="display: none;">\n <div class="atk-loading-spinner">\n <svg viewBox="25 25 50 50"><circle cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10"></circle></svg>\n </div>\n </div>'),(null==e?void 0:e.transparentBg)&&(n.style.background="transparent"),t.appendChild(n)),n.style.display="";const s=n.querySelector(".atk-loading-spinner");s&&(s.style.display="none",window.setTimeout((()=>{s.isConnected&&(s.style.display="")}),500))}function Ft(t){const e=t.querySelector(":scope > .atk-loading");e&&(e.style.display="none")}function Wt(t,e){t?_t(e):Ft(e)}function Nt(t,e=!0,n){let s;if(n){const e=n.getBoundingClientRect();s=t.getBoundingClientRect().top-e.top+n.scrollTop-n.clientHeight/2+t.clientHeight/2}else{const e=t.getBoundingClientRect();s=e.top+window.scrollY-(window.innerHeight/2-e.height/2)}const i={top:s,left:0,behavior:"instant"};n?n.scroll(i):window.scroll(i)}function Ht(t,e){!function(t,e,n="in"){t.classList.add(`atk-fade-${n}`);const s=()=>{t.classList.remove(`atk-fade-${n}`),t.removeEventListener("animationend",s)};t.addEventListener("animationend",s)}(t,0,"in")}function Vt(t,e,n='<span class="atk-error-title">Artalk Error</span>'){let s=t.querySelector(".atk-error-layer");if(null===e)return void(null!==s&&s.remove());s||(s=p(`<div class="atk-error-layer">${n}<span class="atk-error-text"></span></div>`),t.appendChild(s));const i=s.querySelector(".atk-error-text");i.innerHTML="",null!==e&&(e instanceof HTMLElement?i.appendChild(e):i.innerText=e)}class zt extends It{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 aria-label="${L("emoticon")}"><svg fill="currentColor" aria-hidden="true" height="14" viewBox="0 0 14 14" width="14"><path d="m4.26829 5.29294c0-.94317.45893-1.7074 1.02439-1.7074.56547 0 1.02439.76423 1.02439 1.7074s-.45892 1.7074-1.02439 1.7074c-.56546 0-1.02439-.76423-1.02439-1.7074zm4.43903 1.7074c.56546 0 1.02439-.76423 1.02439-1.7074s-.45893-1.7074-1.02439-1.7074c-.56547 0-1.02439.76423-1.02439 1.7074s.45892 1.7074 1.02439 1.7074zm-1.70732 2.73184c-1.51883 0-2.06312-1.52095-2.08361-1.58173l-1.29551.43231c.03414.10244.868 2.51604 3.3798 2.51604 2.51181 0 3.34502-2.41291 3.37982-2.51604l-1.29484-.43573c-.02254.06488-.56683 1.58583-2.08498 1.58583zm7-2.73252c0 3.86004-3.1401 7.00034-7 7.00034s-7-3.1396-7-6.99966c0-3.86009 3.1401-7.00034 7-7.00034s7 3.14025 7 7.00034zm-1.3659 0c0-3.10679-2.5275-5.63442-5.6341-5.63442-3.10663 0-5.63415 2.52832-5.63415 5.6351 0 3.10676 2.52752 5.63446 5.63415 5.63446 3.1066 0 5.6341-2.5277 5.6341-5.63446z"/></svg></i>`)})),this.kit.useUnmounted((()=>{})),this.useContentTransformer((t=>this.transEmoticonImageText(t))),this.usePanelShow((()=>{(()=>{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*(){_t(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 Vt(this.$panel,`[${L("emoticon")}] Data must be of Array/Object/String type`),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,s)=>u(this,null,(function*(){if("object"!=typeof t||Array.isArray(t)){if(Array.isArray(t))yield n(t);else if("string"==typeof t){const s=yield this.remoteLoad(t);Array.isArray(s)?yield n(s):"object"==typeof s&&e(s)}}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),Vt(this.$panel,`[${L("emoticon")}] ${L("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 s={name:t,type:n.type,items:[]};n.container.forEach(((e,n)=>{const i=e.icon;if(/<(img|IMG)/.test(i)){const t=/src=["'](.*?)["']/.exec(i);t&&t.length>1&&(e.icon=t[1])}s.items.push({key:e.text||`${t} ${n+1}`,val:e.icon})})),e.push(s)})),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 s=p('<span class="atk-item"></span>');if(n.append(s),e.key&&!new RegExp(`^(${t.name})?\\s?[0-9]+$`).test(e.key)&&s.setAttribute("title",e.key),"image"===t.type){const t=document.createElement("img");t.src=e.val,t.alt=e.key,s.append(t)}else s.innerText=e.val;s.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,s;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==(s=null==(n=this.$grpSwitcher)?void 0:n.querySelector(`span[data-index="${t}"]`))||s.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 Kt=["png","jpg","jpeg","gif","bmp","svg","webp"];class Qt extends It{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=Kt.map((t=>`.${t}`)).join(",");const t=this.useBtn(`<i aria-label="${L("uploadImage")}"><svg fill="currentColor" aria-hidden="true" height="14" viewBox="0 0 14 14" width="14"><path d="m0 1.94444c0-1.074107.870333-1.94444 1.94444-1.94444h10.11116c1.0741 0 1.9444.870333 1.9444 1.94444v10.11116c0 1.0741-.8703 1.9444-1.9444 1.9444h-10.11116c-1.074107 0-1.94444-.8703-1.94444-1.9444zm1.94444-.38888c-.21466 0-.38888.17422-.38888.38888v7.06689l2.33333-2.33333 2.33333 2.33333 3.88888-3.88889 2.3333 2.33334v-5.51134c0-.21466-.1742-.38888-.3888-.38888zm10.49996 8.09977-2.3333-2.33333-3.88888 3.8889-2.33333-2.33334-2.33333 2.33334v.8447c0 .2146.17422.3888.38888.3888h10.11116c.2146 0 .3888-.1742.3888-.3888zm-7.1944-6.54422c-.75133 0-1.36111.60978-1.36111 1.36111 0 .75134.60978 1.36111 1.36111 1.36111s1.36111-.60977 1.36111-1.36111c0-.75133-.60978-1.36111-1.36111-1.36111z"/></svg></i>`);t.after(this.$imgUploadInput),t.onclick=()=>{const t=this.$imgUploadInput;t.onchange=()=>{(()=>{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 s=null==(n=e.dataTransfer)?void 0:n.files;(null==s?void 0:s.length)&&(e.preventDefault(),t(s))},s=e=>{var n;const s=null==(n=e.clipboardData)?void 0:n.files;(null==s?void 0:s.length)&&(e.preventDefault(),t(s))};this.kit.useMounted((()=>{this.kit.useUI().$textarea.addEventListener("dragover",e),this.kit.useUI().$textarea.addEventListener("drop",n),this.kit.useUI().$textarea.addEventListener("paste",s)})),this.kit.useUnmounted((()=>{this.kit.useUI().$textarea.removeEventListener("dragover",e),this.kit.useUI().$textarea.removeEventListener("drop",n),this.kit.useUI().$textarea.removeEventListener("paste",s)}))}uploadImg(t){return u(this,null,(function*(){const e=/[^.]+$/.exec(t.name);if(!e||!Kt.includes(String(e[0]).toLowerCase()))return;if(!this.kit.useUser().checkHasBasicUserInfo())return void this.kit.useEditor().showNotify(L("uploadLoginMsg"),"w");let n="\n";""===this.kit.useUI().$textarea.value.trim()&&(n="");const s=`${n}`;let i;this.kit.useEditor().insertContent(s);try{const e=this.kit.useConf().imgUploader;i=e?{public_url:yield e(t)}:(yield this.kit.useApi().upload.upload({file:t})).data}catch(o){console.error(o),this.kit.useEditor().showNotify(`${L("uploadFail")}: ${o.message}`,"e")}if(i&&i.public_url){let t=i.public_url;$(t)||(t=w({base:this.kit.useConf().server,path:t})),this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(s,`${n}`))}else this.kit.useEditor().setContent(this.kit.useUI().$textarea.value.replace(s,""))}))}}class Gt extends It{constructor(t){super(t),h(this,"isPlugPanelShow",!1),this.kit.useMounted((()=>{this.usePanel('<div class="atk-editor-plug-preview"></div>'),this.useBtn(`<i aria-label="${L("preview")}"><svg fill="currentColor" aria-hidden="true" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M14.85 3H1.15C.52 3 0 3.52 0 4.15v7.69C0 12.48.52 13 1.15 13h13.69c.64 0 1.15-.52 1.15-1.15v-7.7C16 3.52 15.48 3 14.85 3zM9 11H7V8L5.5 9.92 4 8v3H2V5h2l1.5 2L7 5h2v6zm2.99.5L9.5 8H11V5h2v3h1.5l-2.51 3.5z"></path></svg></i>`)})),this.kit.useUnmounted((()=>{})),this.kit.useEvents().on("content-updated",(t=>{this.isPlugPanelShow&&this.updateContent()})),this.usePanelShow((()=>{this.isPlugPanelShow=!0,this.updateContent()})),this.usePanelHide((()=>{this.isPlugPanelShow=!1}))}updateContent(){this.$panel.innerHTML=this.kit.useEditor().getContentMarked()}}const Yt=[class extends It{constructor(t){super(t);const e=()=>{this.save()};this.kit.useMounted((()=>{const t=window.localStorage.getItem(Dt)||"";""!==t.trim()&&(this.kit.useEditor().showNotify(L("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(Dt,this.kit.useEditor().getContentRaw().trim())}},class extends It{get $inputs(){return this.kit.useEditor().getHeaderInputEls()}constructor(t){super(t);const e={},n={},s=(t,e,n)=>()=>{this.kit.useEvents().trigger(t,{field:n,$input:e})};this.kit.useMounted((()=>{Object.entries(this.$inputs).forEach((([t,i])=>{i.addEventListener("input",e[t]=s("header-input",i,t)),i.addEventListener("change",n[t]=s("header-change",i,t))}))})),this.kit.useUnmounted((()=>{Object.entries(this.$inputs).forEach((([t,s])=>{s.removeEventListener("input",e[t]),s.removeEventListener("change",n[t])}))}))}},class extends It{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()}),"name"!==e&&"email"!==e||this.fetchUserInfo())},n={name:L("nick"),email:L("email"),link:L("link")};this.kit.useMounted((()=>{Object.entries(this.kit.useEditor().getHeaderInputEls()).forEach((([t,e])=>{e.placeholder=n[t],e.value=this.kit.useUser().getData()[t]||""})),this.kit.useEvents().on("header-input",e)})),this.kit.useUnmounted((()=>{this.kit.useEvents().off("header-input",e)}))}fetchUserInfo(){this.kit.useUser().logout(),this.query.timer&&window.clearTimeout(this.query.timer),this.query.abortFn&&this.query.abortFn(),this.query.timer=window.setTimeout((()=>{this.query.timer=null;const t=this.kit.useApi(),e="getUserCancelToken";this.query.abortFn=()=>t.abortRequest(e),t.user.getUser(c({},t.getUserFields()),{cancelToken:e}).then((t=>this.onUserInfoFetched(t.data))).catch((t=>{})).finally((()=>{this.query.abortFn=null}))}),400)}onUserInfoFetched(t){var e;t.is_login||this.kit.useUser().logout(),this.kit.useData().updateNotifies(t.notifies),this.kit.useUser().checkHasBasicUserInfo()&&!t.is_login&&(null==(e=t.user)?void 0:e.is_admin)&&this.kit.useCheckers().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 It{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 It{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||L("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`}},Bt,class extends It{constructor(t){super(t);const e=()=>{this.kit.useEditor().submit()};this.kit.useMounted((()=>{this.kit.useUI().$submitBtn.innerText=this.kit.useConf().sendBtn||L("send"),this.kit.useUI().$submitBtn.addEventListener("click",e)})),this.kit.useUnmounted((()=>{this.kit.useUI().$submitBtn.removeEventListener("click",e)}))}},Rt,class extends It{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(Bt);if(!t)throw Error("SubmitPlug not initialized");const e=new qt(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().comments.createComment(d(c({},yield e.getSubmitAddParams()),{rid:this.comment.id,page_key:this.comment.page_key,page_title:void 0,site_name:this.comment.site_name}))).data})),post:t=>{const 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();if(!e.$sendReplyBtn){const n=p(`<span class="atk-state-btn"><span class="atk-text-wrap">${L("reply")} <span class="atk-text"></span></span><span class="atk-cancel atk-icon-close atk-icon"></span></span>`);n.querySelector(".atk-text").innerText=`@${t.nick}`,n.addEventListener("click",(()=>{this.kit.useEditor().resetState()})),e.$stateWrap.append(n),e.$sendReplyBtn=n}this.comment=t,e.$textarea.focus()}cancelReply(){if(!this.comment)return;const t=this.kit.useUI();t.$sendReplyBtn&&(t.$sendReplyBtn.remove(),t.$sendReplyBtn=void 0),this.comment=void 0}},class extends It{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(Bt);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().$name.value,email:this.kit.useUI().$email.value,link:this.kit.useUI().$link.value},e=this.comment;return(yield this.kit.useApi().comments.updateComment(e.id,c(c({},e),t))).data})),post:t=>{this.kit.useData().updateComment(t)}})}))}edit(t){const e=this.kit.useUI();if(!e.$editCancelBtn){const t=p(`<span class="atk-state-btn"><span class="atk-text-wrap">${L("editCancel")}</span><span class="atk-cancel atk-icon-close atk-icon"></span></span>`);t.onclick=()=>{this.kit.useEditor().resetState()},e.$stateWrap.append(t),e.$editCancelBtn=t}this.comment=t,e.$header.style.display="none",e.$name.value=t.nick||"",e.$email.value=t.email||"",e.$link.value=t.link||"",this.kit.useEditor().setContent(t.content),e.$textarea.focus(),this.updateSubmitBtnText(L("save"))}cancelEdit(){if(!this.comment)return;const t=this.kit.useUI();t.$editCancelBtn&&(t.$editCancelBtn.remove(),t.$editCancelBtn=void 0),this.comment=void 0;const{name:e,email:n,link:s}=this.kit.useUser().getData();t.$name.value=e,t.$email.value=n,t.$link.value=s,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 It{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">${L("onlyAdminCanReply")}</div>`)),this.kit.useUser().getData().is_admin?(this.kit.useUI().$textarea.style.display="",this.kit.useUI().$bottom.style.display=""):(this.kit.useUI().$textarea.style.display="none",this.kit.useEvents().trigger("panel-close"),this.kit.useUI().$bottom.style.display="none")}},zt,Qt,Gt];class Jt{constructor(t){this.plugins=t}useEditor(){return this.plugins.getEditor()}useConf(){return this.plugins.getOptions().getConf().get()}useApi(){return this.plugins.getOptions().getApi()}useData(){return this.plugins.getOptions().getData()}useUser(){return this.plugins.getOptions().getUser()}useCheckers(){return this.plugins.getOptions().getCheckers()}useUI(){return this.plugins.getEditor().getUI()}useEvents(){return this.plugins.getEvents()}useMounted(t){this.useEvents().on("mounted",t)}useUnmounted(t){this.useEvents().on("unmounted",t)}useDeps(t){return this.plugins.get(t)}useArtalkRootEl(){return this.plugins.getOptions().getArtalkRootEl()}}class Xt{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)}))}}class Zt{constructor(t){h(this,"plugins",[]),h(this,"openedPlug",null),h(this,"events",new Xt),this.opts=t;let e=!1;this.opts.getConf().watchConf(["imgUpload","emoticons","preview","editorTravel","locale"],(t=>{e&&this.getEvents().trigger("unmounted"),this.clear(),function(t){const e=new Map;return e.set(Qt,t.imgUpload),e.set(zt,t.emoticons),e.set(Gt,t.preview),e.set(Rt,t.editorTravel),Yt.filter((t=>!e.has(t)||!!e.get(t)))}(t).forEach((t=>{const e=new Jt(this);this.plugins.push(new t(e))})),this.getEvents().trigger("mounted"),e=!0,this.loadPluginUI()})),this.events.on("panel-close",(()=>this.closePluginPanel())),this.events.on("editor-submitted",(()=>t.onSubmitted()))}getPlugins(){return this.plugins}getEvents(){return this.events}getEditor(){return this.opts.getEditor()}getOptions(){return this.opts}clear(){this.plugins=[],this.events=new Xt,this.openedPlug&&this.closePluginPanel()}loadPluginUI(){this.getEditor().getUI().$plugPanelWrap.innerHTML="",this.getEditor().getUI().$plugPanelWrap.style.display="none",this.getEditor().getUI().$plugBtnWrap.innerHTML="",this.plugins.forEach((t=>this.loadPluginItem(t)))}loadPluginItem(t){const e=t.$btn;if(!e)return;this.getEditor().getUI().$plugBtnWrap.appendChild(e),!e.onclick&&(e.onclick=()=>{this.opts.getEditor().getUI().$plugBtnWrap.querySelectorAll(".active").forEach((t=>t.classList.remove("active"))),t!==this.openedPlug?(this.openPluginPanel(t),e.classList.add("active")):this.closePluginPanel()});const n=t.$panel;n&&(n.style.display="none",this.getEditor().getUI().$plugPanelWrap.appendChild(n))}get(t){return this.plugins.find((e=>e instanceof t))}openPluginPanel(t){this.plugins.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.getEditor().getUI().$plugPanelWrap.style.display="",this.openedPlug=t}closePluginPanel(){this.openedPlug&&(this.getEditor().getUI().$plugPanelWrap.style.display="none",this.events.trigger("panel-hide",this.openedPlug),this.openedPlug=null)}getTransformedContent(t){let e=t;return this.plugins.forEach((t=>{t.contentTransformer&&(e=t.contentTransformer(e))})),e}}const te="2.9.1";function ee(t){const e=p('<span><span class="error-message"></span><br/><br/></span>');if(e.querySelector(".error-message").innerText=`${L("listLoadFailMsg")}\n${t.errMsg}`,t.retryFn){const n=p(`<span style="cursor:pointer;">${L("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;">${L("openName",{name:L("ctrlCenter")})}</span></span>`);e.appendChild(n),n.onclick=()=>t.onOpenSidebar&&t.onOpenSidebar()}Vt(t.$err,e)}const ne=[t=>{const e=t.inject("config");t.on("list-fetch",(n=>{if(t.getData().getLoading())return;t.getData().setLoading(!0);const s=c({offset:0,limit:e.get().pagination.pageSize,flatMode:e.get().flatMode,paramsModifier:e.get().listFetchParamsModifier},n);t.getData().setListLastFetch({params:s});const i={limit:s.limit,offset:s.offset,flat_mode:s.flatMode,page_key:e.get().pageKey,site_name:e.get().site};s.paramsModifier&&s.paramsModifier(i),t.getApi().comments.getComments(c(c({},i),t.getApi().getUserFields())).then((({data:e})=>{t.getData().setListLastFetch({params:s,data:e}),t.getData().loadComments(e.comments),t.getData().updatePage(e.page),s.onSuccess&&s.onSuccess(e),t.trigger("list-fetched",{params:s,data:e})})).catch((e=>{const n={msg:e.msg||String(e),data:e.data};throw s.onError&&s.onError(n),t.trigger("list-failed",n),t.trigger("list-fetched",{params:s,error:n}),e})).finally((()=>{t.getData().setLoading(!1)}))}))},t=>{const e=t.inject("list");t.on("list-fetch",(t=>{0===t.offset&&Wt(!0,e.getEl())})),t.on("list-fetched",(()=>{Wt(!1,e.getEl())}))},t=>{const e=t.inject("config");t.on("comment-rendered",(n=>{if(e.get().listUnreadHighlight){const e=t.getData().getNotifies(),s=e.find((t=>t.comment_id===n.getID()));s?(n.getRender().setUnread(!0),n.getRender().setOpenAction((()=>{window.open(s.read_link),t.getData().updateNotifies(e.filter((t=>t.comment_id!==n.getID())))}))):n.getRender().setUnread(!1)}})),t.on("list-goto",(e=>{const n=g("atk_notify_key");n&&t.getApi().notifies.markNotifyRead(e,n).then((()=>{t.getData().updateNotifies(t.getData().getNotifies().filter((t=>t.comment_id!==e)))}))}))},t=>{const e=t.inject("list"),n=t.inject("editorPlugs");let s;t.on("mounted",(()=>{s=e.getEl().querySelector('[data-action="admin-close-comment"]'),s.addEventListener("click",(()=>{const e=t.getData().getPage();if(!e)throw new Error("Page data not found");e.admin_only=!e.admin_only,function(t,e){t.editorShowLoading(),t.getApi().pages.updatePage(e.id,e).then((({data:e})=>{t.getData().updatePage(e)})).catch((e=>{t.editorShowNotify(`${L("editFail")}: ${e.message||String(e)}`,"e")})).finally((()=>{t.editorHideLoading()}))}(t,e)}))})),t.on("page-loaded",(t=>{!0===(null==t?void 0:t.admin_only)?(null==n||n.getEvents().trigger("editor-close"),s&&(s.innerText=L("openComment"))):(null==n||n.getEvents().trigger("editor-open"),s&&(s.innerText=L("closeComment")))})),t.on("list-loaded",(e=>{t.editorResetState()}))},t=>{const e=t.inject("list");t.on("list-loaded",(()=>{(()=>{var n,s;const i=e.getEl().querySelector(".atk-comment-count .atk-text");if(!i)return;const o=m(L("counter",{count:`${Number(null==(s=null==(n=t.getData().getListLastFetch())?void 0:n.data)?void 0:s.count)||0}`}));i.innerHTML=o.replace(/(\d+)/,'<span class="atk-comment-count-num">$1</span>')})()})),t.on("comment-inserted",(()=>{const e=t.getData().getListLastFetch();(null==e?void 0:e.data)&&(e.data.count+=1)})),t.on("comment-deleted",(()=>{const e=t.getData().getListLastFetch();(null==e?void 0:e.data)&&(e.data.count-=1)}))},t=>{const e=t.inject("list");let n=null;const s=()=>{if(!n)return;const e=t.inject("user").getData();if(e.name&&e.email){n.classList.remove("atk-hide");const t=n.querySelector(".atk-text");t&&(t.innerText=e.is_admin?L("ctrlCenter"):L("msgCenter"))}else n.classList.add("atk-hide")};t.watchConf(["locale"],(i=>{n=e.getEl().querySelector('[data-action="open-sidebar"]'),n&&(n.onclick=()=>{t.showSidebar()},s())})),t.on("user-changed",(t=>{s()}))},t=>{const e=t.inject("list");let n=null;t.on("mounted",(()=>{n=e.getEl().querySelector(".atk-unread-badge")})),t.on("notifies-updated",(t=>{var e;e=t.length||0,n&&(e>0?(n.innerText=`${Number(e||0)}`,n.style.display="block"):n.style.display="none")}))},t=>{const e=t.inject("list"),n=t.inject("config"),s=e=>{n.update({listFetchParamsModifier:e}),t.reload()},i=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 s=0;const i=(t,e,n,i)=>{i(),s=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,a]=t,r=p('<li class="atk-dropdown-item"><span></span></li>'),l=r.querySelector("span");l.innerText=n,l.onclick=()=>{i(e,r,n,a)},o.append(r),e===s&&r.classList.add("active")})),e.append(o)}({$dropdownWrap:t,dropdownList:[[L("sortLatest"),()=>{s((t=>{t.sort_by="date_desc"}))}],[L("sortBest"),()=>{s((t=>{t.sort_by="vote"}))}],[L("sortOldest"),()=>{s((t=>{t.sort_by="date_asc"}))}],[L("sortAuthor"),()=>{s((t=>{t.view_only_admin=!0}))}]]})};t.watchConf(["listSort","locale"],(t=>{const n=e.getEl().querySelector(".atk-comment-count");n&&(t.listSort?i(n):function(t){var e,n;const{$dropdownWrap:s}=t;s.classList.remove("atk-dropdown-wrap"),null==(e=s.querySelector(".atk-arrow-down-icon"))||e.remove(),null==(n=s.querySelector(".atk-dropdown"))||n.remove()}({$dropdownWrap:n}))}))},t=>{let e=0;const n=({locker:n})=>{const s=function(){const t=window.location.hash.match(/#atk-comment-([0-9]+)/);let e=t&&t[1]&&!Number.isNaN(parseFloat(t[1]))?parseFloat(t[1]):null;e||(e=Number(g("atk_comment")));return e||null}();s&&(n&&e===s||(e=s,t.trigger("list-goto",s)))},s=()=>n({locker:!1}),i=()=>n({locker:!0});t.on("mounted",(()=>{window.addEventListener("hashchange",s),t.on("list-loaded",i)})),t.on("unmounted",(()=>{window.removeEventListener("hashchange",s),t.off("list-loaded",i)}))},t=>{const e=t.inject("list");t.on("list-goto",(n=>u(this,null,(function*(){let s=t.getCommentNodes().find((t=>t.getID()===n));if(!s){const i=(yield t.getApi().comments.getComment(n)).data;e.getLayout({forceFlatMode:!0}).insert(i.comment,i.reply_comment),s=t.getCommentNodes().find((t=>t.getID()===n))}s&&s.focus()}))))},t=>{const e=t.inject("list"),n=t.inject("config");t.on("list-loaded",(s=>{const i=s.length<=0;let o=e.getCommentsWrapEl().querySelector(".atk-list-no-comment");i?o||(o=p('<div class="atk-list-no-comment"></div>'),o.innerHTML=dt(n.get().noComment||t.$t("noComment")),e.getCommentsWrapEl().appendChild(o)):null==o||o.remove()}))},t=>{const e=t.inject("list");t.on("mounted",(()=>{const t=e.getEl().querySelector(".atk-copyright");t&&(t.innerHTML=`Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${te}">Artalk</a>`)}))},t=>{const e=t.inject("list"),n=t.inject("config");let s=null;t.on("mounted",(()=>{s=window.setInterval((()=>{e.getEl().querySelectorAll("[data-atk-comment-date]").forEach((e=>{var s,i;const o=new Date(Number(e.getAttribute("data-atk-comment-date")));e.innerText=(null==(i=(s=n.get()).dateFormatter)?void 0:i.call(s,o))||y(o,t.$t)}))}),3e4)})),t.on("unmounted",(()=>{s&&window.clearInterval(s)}))},t=>{const e=t.inject("list");t.on("list-fetch",(()=>{Vt(e.getEl(),null)})),t.on("list-failed",(n=>{ee({$err:e.getEl(),errMsg:n.msg,errData:n.data,retryFn:()=>t.fetch({offset:0})})}))},t=>{const e=t.inject("list"),n=t.inject("config");let s=null;const i=()=>{null==s||s.disconnect(),s=null};t.on("list-loaded",(()=>{i();const o=e.getCommentsWrapEl().childNodes,a=o.length>2?o[o.length-2]:null;a&&("IntersectionObserver"in window?(e=>{var o,a;const r=(null==(a=(o=n.get()).scrollRelativeTo)?void 0:a.call(o))||null;s=new IntersectionObserver((([e])=>{e.isIntersecting&&(i(),t.trigger("list-reach-bottom"))}),{threshold:.9,root:r}),s.observe(e)})(a):console.warn("IntersectionObserver api not supported"))})),t.on("unmounted",(()=>{i()}))},t=>{const e=t.inject("list"),n=t.inject("config"),s=()=>{var t,s;const i=null==(s=(t=n.get()).scrollRelativeTo)?void 0:s.call(t);(i||window).scroll({top:f(e.getEl(),i).top,left:0})};t.on("mounted",(()=>{t.on("list-goto-first",s)})),t.on("unmounted",(()=>{t.off("list-goto-first",s)}))}];let se=!1;let ie;function oe(t,e){const n="atk-dark-mode";t.forEach((t=>{e?t.classList.add(n):t.classList.remove(n)}))}const ae={upBtnEl:".artalk-page-vote-up",downBtnEl:".artalk-page-vote-down",upCountEl:".artalk-page-vote-up-count",downCountEl:".artalk-page-vote-down-count",activeClass:"active"};function re(t,e,n,s,i){var o,a;t.upCountEl?t.upCountEl.innerText=String(e):t.upBtnEl&&(t.upBtnEl.innerText=`${L("voteUp")} (${e})`),t.downCountEl?t.downCountEl.innerText=String(n):t.downBtnEl&&(t.downBtnEl.innerText=`${L("voteDown")} (${n})`),"boolean"==typeof s&&(null==(o=t.upBtnEl)||o.classList.toggle(t.activeClass||"active",s)),"boolean"==typeof i&&(null==(a=t.downBtnEl)||a.classList.toggle(t.activeClass||"active",i))}const le=(t,e)=>n=>{n.preventDefault();const{state:s,pageId:i,httpApi:o}=e();i&&o.votes.createVote("page",i,t,c({},o.getUserFields())).then((({data:t})=>{re(s,t.up,t.down,t.is_up,t.is_down)})).catch((t=>{window.alert(L("voteFail")),console.error("[ArtalkPageVote]",t)}))};const ce="ArtalkUser";class de{constructor(t){h(this,"data"),this.opts=t;const e=JSON.parse(window.localStorage.getItem(ce)||"{}");this.data={name:e.name||e.nick||"",email:e.email||"",link:e.link||"",token:e.token||"",is_admin:e.is_admin||e.isAdmin||!1}}getData(){return this.data}update(t={}){Object.entries(t).forEach((([t,e])=>{this.data[t]=e})),window.localStorage.setItem(ce,JSON.stringify(this.data)),this.opts.onUserChanged&&this.opts.onUserChanged(this.data)}logout(){this.update({token:"",is_admin:!1})}checkHasBasicUserInfo(){return!!this.data.name&&!!this.data.email}}function he(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",_t(e,{transparentBg:!0}),n.src=t.getOpts().getCaptchaIframeURL(),n.onload=()=>{n.style.display="",Ft(e)},e.append(n);const s=p('<div class="atk-close-btn"><i class="atk-icon atk-icon-close"></i></div>');e.append(s),t.hideInteractInput();let i=!1;return function e(){return u(this,null,(function*(){var n;if(yield(n=1e3,new Promise((t=>{window.setTimeout((()=>{t(null)}),n)}))),i)return;let s=!1;try{s=(yield t.getApi().captcha.getCaptchaStatus()).data.is_pass}catch(o){s=!1}s?t.triggerSuccess():e()}))}(),s.onclick=()=>{i=!0,t.cancel()},e}const ue={request:(t,e)=>t.getApi().captcha.verifyCaptcha({value:e}),body:t=>t.get("iframe")?he(t):function(t){const e=p(`<span><img class="atk-captcha-img" src="${t.get("img_data")||""}">${L("captchaCheck")}</span>`);return e.querySelector(".atk-captcha-img").onclick=()=>{const n=e.querySelector(".atk-captcha-img");t.getApi().captcha.getCaptcha().then((t=>{n.setAttribute("src",t.data.img_data)})).catch((t=>{console.error("Failed to get captcha image ",t)}))},e}(t),onSuccess(t,e,n,s){t.set("val",n)},onError(t,e,n,s){s.querySelector(".atk-captcha-img").click(),s.querySelector('input[type="text"]').value=""}},pe={inputType:"password",request(t,e){return u(this,null,(function*(){return(yield t.getApi().user.login({name:t.getUser().getData().name,email:t.getUser().getData().email,password:e})).data}))},body:t=>p(`<span>${L("adminCheck")}</span>`),onSuccess(t,e,n,s){t.getUser().update({is_admin:!0,token:e.token}),t.getOpts().onReload()},onError(t,e,n,s){}};class me{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">${L("confirm")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}setNo(t){const e=p(`<button data-action="cancel">${L("cancel")}</button>`);return e.onclick=this.onBtnClick(t),this.$actions.appendChild(e),this}onBtnClick(t){return e=>{const n=t(e.currentTarget,this);void 0!==n&&!0!==n||this.$el.remove()}}}function ge(t){return e=>new Promise(((n,s)=>{const i=e.onCancel;e.onCancel=()=>{i&&i(),s(new Error("user canceled the checker"))};const o=e.onSuccess;e.onSuccess=()=>{o&&o(),n()},t(e)}))}class fe{constructor(t){h(this,"checkCaptcha",ge((t=>{this.check(ue,t,(e=>{e.set("img_data",t.img_data),e.set("iframe",t.iframe)}))}))),h(this,"checkAdmin",ge((t=>{this.check(pe,t)}))),this.opts=t}check(t,e,n){const s=this.opts.getLayers().create(`checker-${(new Date).getTime()}`);s.show();const i=()=>{s.destroy()},o={};let a=!1;const r={set:(t,e)=>{o[t]=e},get:t=>o[t],getOpts:()=>this.opts,getUser:()=>this.opts.getUser(),getApi:()=>this.opts.getApi(),hideInteractInput:()=>{a=!0},triggerSuccess:()=>{i(),t.onSuccess&&t.onSuccess(r,"","",l),e.onSuccess&&e.onSuccess()},cancel:()=>{i(),e.onCancel&&e.onCancel()}};n&&n(r);const l=p();l.appendChild(t.body(r));const c=p(`<input id="check" type="${t.inputType||"text"}" autocomplete="off" required placeholder="">`);let d;l.appendChild(c),setTimeout((()=>c.focus()),80),c.onkeyup=t=>{"Enter"!==t.key&&13!==t.keyCode||(t.preventDefault(),s.getEl().querySelector('button[data-action="confirm"]').click())};const h=new me(l);h.setYes((n=>{const s=c.value.trim();d||(d=n.innerText);const o=()=>{n.innerText=d||"",n.classList.remove("error")};return n.innerText=`${L("loading")}...`,t.request(r,s).then((n=>{i(),t.onSuccess&&t.onSuccess(r,n,s,l),e.onSuccess&&e.onSuccess()})).catch((e=>{var i;i=String(e.message||String(e)),n.innerText=i,n.classList.add("error"),t.onError&&t.onError(r,e,s,l);const a=setTimeout((()=>o()),3e3);c.onfocus=()=>{o(),clearTimeout(a)}})),!1})),h.setNo((()=>(i(),e.onCancel&&e.onCancel(),!1))),a&&(c.style.display="none",h.$el.querySelector(".atk-layer-dialog-actions").style.display="none"),s.getEl().append(h.$el),e.onMount&&e.onMount(h.$el)}}const ve={$header:".atk-header",$name:'.atk-header [name="name"]',$email:'.atk-header [name="email"]',$link:'.atk-header [name="link"]',$textareaWrap:".atk-textarea-wrap",$textarea:".atk-textarea",$bottom:".atk-bottom",$submitBtn:".atk-send-btn",$notifyWrap:".atk-notify-wrap",$bottomLeft:".atk-bottom-left",$stateWrap:".atk-state-wrap",$plugBtnWrap:".atk-plug-btn-wrap",$plugPanelWrap:".atk-plug-panel-wrap"};class ye{constructor(t){h(this,"stateCurt","normal"),h(this,"stateUnmountFn",null),this.editor=t}get(){return this.stateCurt}switch(t,e){var n,s,i,o,a,r,l;if(this.stateUnmountFn&&(this.stateUnmountFn(),this.stateUnmountFn=null,null==(s=null==(n=this.editor.getPlugins())?void 0:n.get(Rt))||s.back()),"normal"!==t&&e){let n=e.$comment;this.editor.getOptions().getConf().get().flatMode||(n=n.querySelector(".atk-footer")),null==(o=null==(i=this.editor.getPlugins())?void 0:i.get(Rt))||o.move(n);const s=null==(r=(a=this.editor.getOptions().getConf().get()).scrollRelativeTo)?void 0:r.call(a);Nt(this.editor.getUI().$el,!0,s);const c=null==(l=this.editor.getPlugins())?void 0:l.getPlugins().find((e=>e.editorStateEffectWhen===t));c&&c.editorStateEffect&&(this.stateUnmountFn=c.editorStateEffect(e.comment))}this.stateCurt=t}}class ke{constructor(t){h(this,"opts"),h(this,"$el"),h(this,"ui"),h(this,"state"),h(this,"plugins"),this.opts=t,this.ui=function(){const t=p('<div class="atk-main-editor">\n <div class="atk-header">\n <input name="name" class="atk-name" type="text" required="required" />\n <input name="email" class="atk-email" type="email" required="required" />\n <input name="link" class="atk-link" type="url" />\n </div>\n <div class="atk-textarea-wrap">\n <textarea class="atk-textarea"></textarea>\n </div>\n <div class="atk-plug-panel-wrap" style="display: none"></div>\n <div class="atk-bottom">\n <div class="atk-item atk-bottom-left">\n <span class="atk-state-wrap"></span>\n <span class="atk-plug-btn-wrap"></span>\n </div>\n <div class="atk-item">\n <button type="button" class="atk-send-btn"></button>\n </div>\n </div>\n <div class="atk-notify-wrap"></div>\n</div>\n'),e={$el:t};return Object.entries(ve).forEach((([n,s])=>{e[n]=t.querySelector(s)})),e}(),this.$el=this.ui.$el,this.state=new ye(this)}getOptions(){return this.opts}getEl(){return this.$el}getUI(){return this.ui}getPlugins(){return this.plugins}setPlugins(t){this.plugins=t}getState(){return this.state.get()}getHeaderInputEls(){return{name:this.ui.$name,email:this.ui.$email,link:this.ui.$link}}getContentFinal(){let t=this.getContentRaw();const e=this.getPlugins();return e&&(t=e.getTransformedContent(t)),t}getContentRaw(){return this.ui.$textarea.value||""}getContentMarked(){return Et(this.getContentFinal())}setContent(t){var e;this.ui.$textarea.value=t,null==(e=this.getPlugins())||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,s=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=s}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")}setReplyComment(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 s=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>`);s.querySelector(".atk-notify-content").innerHTML=m(e).replace("\n","<br/>"),t.appendChild(s);const i=()=>{s.classList.add("atk-fade-out"),setTimeout((()=>{s.remove()}),200)};let o;o=window.setTimeout((()=>{i()}),3e3),s.addEventListener("click",(()=>{i(),window.clearTimeout(o)}))}(this.ui.$notifyWrap,t,e)}showLoading(){_t(this.ui.$el)}hideLoading(){Ft(this.ui.$el)}submit(){const t=()=>{var t;null==(t=this.getPlugins())||t.getEvents().trigger("editor-submit"),this.opts.getEvents().trigger("editor-submit")},e=this.opts.getConf().get().beforeSubmit;e?e(this,t):t()}}class $e{constructor(t){h(this,"loading",!1),h(this,"listLastFetch"),h(this,"comments",[]),h(this,"notifies",[]),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)}getNotifies(){return this.notifies}updateNotifies(t){this.notifies=t,this.events.trigger("notifies-updated",this.notifies)}getPage(){return this.page}updatePage(t){this.page=t,this.events.trigger("page-loaded",t)}}class we{constructor(t,e){h(this,"allowMaskClose",!0),h(this,"onAfterHide"),this.$el=t,this.opts=e}setOnAfterHide(t){this.onAfterHide=t}setAllowMaskClose(t){this.allowMaskClose=t}getAllowMaskClose(){return this.allowMaskClose}getEl(){return this.$el}show(){this.opts.onShow(),this.$el.style.display=""}hide(){this.opts.onHide(),this.$el.style.display="none",this.onAfterHide&&this.onAfterHide()}destroy(){this.opts.onHide(),this.$el.remove(),this.onAfterHide&&this.onAfterHide()}}let Ee,Ce;function be(){return{init(){Ee=document.body.style.overflow,Ce=document.body.style.paddingRight},unlock(){document.body.style.overflow=Ee,document.body.style.paddingRight=Ce},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 s=t.offsetWidth;return n===s&&(s=e.clientWidth),document.body.removeChild(e),n-s}()+t||0}px`}}}class Se{constructor(){h(this,"$wrap"),h(this,"$mask"),h(this,"items",[]),this.$wrap=p('<div class="atk-layer-wrap" style="display: none;"><div class="atk-layer-mask"></div></div>'),this.$mask=this.$wrap.querySelector(".atk-layer-mask")}createItem(t,e){(e=e||this.createItemElement(t)).setAttribute("data-layer-name",t),this.$wrap.appendChild(e);const n=new we(e,{onHide:()=>this.hideWrap(e),onShow:()=>this.showWrap()});return this.getMask().addEventListener("click",(()=>{n.getAllowMaskClose()&&n.hide()})),this.items.push(n),n}createItemElement(t){const e=document.createElement("div");return e.classList.add("atk-layer-item"),e.style.display="none",this.$wrap.appendChild(e),e}getWrap(){return this.$wrap}getMask(){return this.$mask}showWrap(){this.$wrap.style.display="block",this.$mask.style.display="block",this.$mask.classList.add("atk-fade-in"),be().lock()}hideWrap(t){this.items.map((t=>t.getEl())).filter((e=>e!==t&&e.isConnected&&"none"!==e.style.display)).length>0||(this.$wrap.style.display="none",be().unlock())}}class xe{constructor(){h(this,"wrap",new Se),be().init()}getEl(){return this.wrap.getWrap()}create(t,e){return this.wrap.createItem(t,e)}destroy(){this.wrap.getWrap().remove()}}const Te=t=>({import:e=>{(function(t,e="DATE_DESC",n=2){const s=[];t.filter((t=>0===t.rid)).forEach((e=>{const i={id:e.id,comment:e,children:[],level:1};i.parent=i,s.push(i),function e(s){const i=t.filter((t=>t.rid===s.id));0!==i.length&&(s.level>=n&&(s=s.parent),i.forEach((t=>{const n={id:t.id,comment:t,children:[],parent:s,level:s.level+1};s.children.push(n),e(n)})))}(i)}));const i=(n,s)=>{let i=n.id-s.id;return"DATE_ASC"===e?i=+new Date(n.comment.date)-+new Date(s.comment.date):"DATE_DESC"===e?i=+new Date(s.comment.date)-+new Date(n.comment.date):"SRC_INDEX"===e?i=t.indexOf(n.comment)-t.indexOf(s.comment):"VOTE_UP_DESC"===e&&(i=s.comment.vote_up-n.comment.vote_up),i};return function t(e){e.forEach((e=>{e.children=e.children.sort(i),t(e.children)}))}(s),s})(e,t.nestSortBy,t.nestMax).forEach((n=>{var s;const i=t.createCommentNode(n.comment);null==(s=t.$commentsWrap)||s.appendChild(i.getEl()),i.getRender().playFadeAnim();const o=(n,s)=>{s.children.forEach((s=>{const i=e.find((t=>t.id===s.comment.rid)),a=s.comment,r=t.createCommentNode(a,i);n.putChild(r),o(r,s)}))};o(i,n),i.getRender().checkHeightLimit()}))},insert:(e,n)=>{var s;const i=t.createCommentNode(e,n);if(0===e.rid)null==(s=t.$commentsWrap)||s.prepend(i.getEl());else{const n=t.findCommentNode(e.rid);n&&(n.putChild(i,"DATE_ASC"===t.nestSortBy?"append":"prepend"),i.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()})))}i.getRender().checkHeightLimit(),i.scrollIntoView(),i.getRender().playFadeAnim()}});function Le(t,e,n,s){n.is_collapsed&&(n.is_allow_reply=!1);const i=t.createCommentNode(n,s);if(n.visible){const n=i.getEl(),s=t.$commentsWrap;"append"===e&&(null==s||s.append(n)),"prepend"===e&&(null==s||s.prepend(n)),i.getRender().playFadeAnim()}return i.getRender().checkHeightLimit(),i}class Ae{constructor(t){this.options=t}getStrategy(){return this.options.flatMode?(t=this.options,{import:e=>{e.forEach((n=>{const s=0===n.rid?void 0:e.find((t=>t.id===n.rid));Le(t,"append",n,s)}))},insert:(e,n)=>{Le(t,"prepend",e,n).scrollIntoView()}}):Te(this.options);var t}import(t){this.getStrategy().import(t)}insert(t,e){this.getStrategy().insert(t,e)}}function Me(t,e){e.forEach((({el:e,max:n,imgCheck:s})=>{if(!e)return;s&&(e.style.maxHeight=`${n+1}px`);let i=!1;const o=()=>{if(i)return;if(function(t){return parseFloat(getComputedStyle(t,null).height.replace("px",""))||0}(e)<=n)return;t.scrollable?function(t){if(!t.el)return;if(t.el.classList.contains(je))return;t.el.classList.add(je),t.el.style.height=`${t.max}px`}({el:e,max:n}):function(t){if(!t.el)return;if(!t.max)return;if(t.el.classList.contains(Pe))return;t.el.classList.add(Pe),t.el.style.height=`${t.max}px`,t.el.style.overflow="hidden";const e=p(`<div class="atk-height-limit-btn">${L("readMore")}</span>`);e.onclick=e=>{e.stopPropagation(),Ue(t.el),t.afterExpandBtnClick&&t.afterExpandBtnClick(e)},t.el.append(e)}({el:e,max:n,afterExpandBtnClick:()=>{var e;i=!0,null==(e=t.afterExpandBtnClick)||e.call(t)}})};if(o(),s){const t=e.querySelectorAll(".atk-content img");0===t.length&&(e.style.maxHeight=""),t.forEach((t=>{t.onload=()=>o()}))}}))}const Pe="atk-height-limit";function Ue(t){t&&t.classList.contains(Pe)&&(t.classList.remove(Pe),Array.from(t.children).forEach((t=>{t.classList.contains("atk-height-limit-btn")&&t.remove()})),t.style.height="",t.style.maxHeight="",t.style.overflow="")}const je="atk-height-limit-scroll";function Oe(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=$(t.data.link)?t.data.link:`https://${t.data.link}`,t.$headerNick.append(e)}else t.$headerNick.innerText=t.data.nick}function Ie(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 s=p('<span class="atk-badge"></span>');s.innerText=e.replace("管理员",L("admin")),s.style.backgroundColor=n||"",t.$headerBadgeWrap.append(s)}else if(t.data.is_verified){const e=p(`<span class="atk-icon-verified" title="${L("emailVerified")}"></span>`);t.$headerBadgeWrap.append(e)}if(t.data.is_pinned){const e=p(`<span class="atk-pinned-badge">${L("pin")}</span>`);t.$headerBadgeWrap.append(e)}}function De(t){const e=t.$el.querySelector(".atk-date");e.innerText=t.comment.getDateFormatted(),e.setAttribute("data-atk-comment-date",String(+new Date(t.data.date)))}function qe(t){if(!t.opts.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.opts.uaBadge){const{browser:n,os:s}=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(s).trim()){const t=p('<span class="atk-ua ua-os"></span>');t.innerText=s,e.append(t)}}}class Be{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||L("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||`${L("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,s){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),s&&s()}),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 Re(t){t.opts.vote&&(t.voteBtnUp=new Be((()=>`${L("voteUp")} (${t.data.vote_up||0})`)).appendTo(t.$actions),t.voteBtnUp.setClick((()=>{t.comment.getActions().vote("up")})),t.opts.voteDown&&(t.voteBtnDown=new Be((()=>`${L("voteDown")} (${t.data.vote_down||0})`)).appendTo(t.$actions),t.voteBtnDown.setClick((()=>{t.comment.getActions().vote("down")}))))}function _e(t){if(!t.data.is_allow_reply)return;const e=new Be({text:L("reply")});e.appendTo(t.$actions),e.setClick((()=>{t.opts.replyComment(t.data,t.$el)}))}function Fe(t){const e=new Be({text:()=>t.data.is_collapsed?L("expand"):L("collapse"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("collapsed",e)}))}function We(t){const e=new Be({text:()=>t.data.is_pending?L("pending"):L("approved"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pending",e)}))}function Ne(t){const e=new Be({text:()=>t.data.is_pinned?L("unpin"):L("pin"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminEdit("pinned",e)}))}function He(t){const e=new Be({text:L("edit"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.opts.editComment(t.data,t.$el)}))}function Ve(t){const e=new Be({text:L("delete"),confirm:!0,confirmText:L("deleteConfirm"),adminOnly:!0});e.appendTo(t.$actions),e.setClick((()=>{t.comment.getActions().adminDelete(e)}))}const ze={Avatar:function(t){const e=t.$el.querySelector(".atk-avatar"),n=p("<img />"),s=t.opts.avatarURLBuilder;if(n.src=s?s(t.data):t.comment.getGravatarURL(),t.data.link){const s=p('<a target="_blank" rel="noreferrer noopener nofollow"></a>');s.href=$(t.data.link)?t.data.link:`https://${t.data.link}`,s.append(n),e.append(s)}else e.append(n)},Header:function(t){Object.entries({renderNick:Oe,renderVerifyBadge:Ie,renderDate:De,renderUABadge:qe}).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">${L("collapsedMsg")}</span>\n <span class="atk-show-btn">${L("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=L("collapse")):(t.$content.innerHTML="",t.$content.classList.add("atk-hide"),n.innerText=L("expand"))}))},ReplyAt:function(t){t.opts.flatMode||0===t.data.rid||t.opts.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.opts.replyTo.nick}`,t.$replyAt.onclick=()=>{t.comment.getActions().goToReplyComment()},t.$headerBadgeWrap.insertAdjacentElement("afterend",t.$replyAt))},ReplyTo:function(t){if(!t.opts.flatMode)return;if(!t.opts.replyTo)return;t.$replyTo=p(`\n <div class="atk-reply-to">\n <div class="atk-meta">${L("reply")} <span class="atk-nick"></span>:</div>\n <div class="atk-content"></div>\n </div>`);const e=t.$replyTo.querySelector(".atk-nick");e.innerText=`@${t.opts.replyTo.nick}`,e.onclick=()=>{t.comment.getActions().goToReplyComment()};let n=Et(t.opts.replyTo.content);t.opts.replyTo.is_collapsed&&(n=`[${L("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">${L("pendingMsg")}</div>`);t.$body.prepend(e)},Actions:function(t){Object.entries({renderVote:Re,renderReply:_e,renderCollapse:Fe,renderModerator:We,renderPin:Ne,renderEdit:He,renderDel:Ve}).forEach((([e,n])=>{n(t)}))}};class Ke{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 data(){return this.comment.getData()}get opts(){return this.comment.getOpts()}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(ze).forEach((([e,n])=>{n(t)})),this.$childrenWrap&&this.$main.append(this.$childrenWrap),this.$el}checkHeightLimit(){const t=this.opts.heightLimit;if(!t||!t.content||!t.children)return;const e=t.content,n=t.children;Me({afterExpandBtnClick:()=>{const t=this.comment.getChildren();1===t.length&&Ue(t[0].getRender().$content)},scrollable:t.scrollable},[{el:this.$content,max:e,imgCheck:!0},{el:this.$replyTo,max:e,imgCheck:!0},{el:this.$childrenWrap,max:n,imgCheck:!1}])}heightLimitRemoveForChildren(){this.$childrenWrap&&Ue(this.$childrenWrap)}playFadeAnim(){Ht(this.comment.getRender().$el)}playFadeAnimForBody(){Ht(this.comment.getRender().$body)}playFlashAnim(){this.$el.classList.remove("atk-flash-once"),window.setTimeout((()=>{this.$el.classList.add("atk-flash-once")}),150)}getChildrenWrap(){return this.$childrenWrap||(this.$childrenWrap=p('<div class="atk-comment-children"></div>'),this.$main.append(this.$childrenWrap)),this.$childrenWrap}setUnread(t){t?this.$el.classList.add("atk-unread"):this.$el.classList.remove("atk-unread")}setOpenable(t){t?this.$el.classList.add("atk-openable"):this.$el.classList.remove("atk-openable")}setOpenURL(t){this.setOpenable(!0),this.$el.onclick=e=>{e.stopPropagation(),window.open(t)}}setOpenAction(t){this.setOpenable(!0),this.$el.onclick=e=>{e.stopPropagation(),t()}}}class Qe{constructor(t){h(this,"comment"),this.comment=t}get data(){return this.comment.getData()}get opts(){return this.comment.getOpts()}getApi(){return this.comment.getOpts().getApi()}vote(t){const e="up"===t?this.comment.getRender().voteBtnUp:this.comment.getRender().voteBtnDown;this.getApi().votes.createVote("comment",this.data.id,t,c({},this.getApi().getUserFields())).then((t=>{var e,n;this.data.vote_up=t.data.up,this.data.vote_down=t.data.down,null==(e=this.comment.getRender().voteBtnUp)||e.updateText(),null==(n=this.comment.getRender().voteBtnDown)||n.updateText()})).catch((t=>{null==e||e.setError(L("voteFail")),console.error(t)}))}adminEdit(t,e){if(e.isLoading)return;e.setLoading(!0,`${L("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.getApi().comments.updateComment(this.data.id,c({},n)).then((t=>{e.setLoading(!1),this.comment.setData(t.data)})).catch((t=>{console.error(t),e.setError(L("editFail"))}))}adminDelete(t){t.isLoading||(t.setLoading(!0,`${L("deleting")}...`),this.getApi().comments.deleteComment(this.data.id).then((()=>{t.setLoading(!1),this.opts.onDelete&&this.opts.onDelete(this.comment)})).catch((e=>{console.error(e),t.setError(L("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 Ge{constructor(t,e){h(this,"$el"),h(this,"renderInstance"),h(this,"actionInstance"),h(this,"data"),h(this,"opts"),h(this,"parent"),h(this,"children",[]),h(this,"nestCurt"),this.opts=e,this.data=c({},t),this.data.date=this.data.date.replace(/-/g,"/"),this.parent=null,this.nestCurt=1,this.actionInstance=new Qe(this),this.renderInstance=new Ke(this)}render(){const t=this.renderInstance.render();this.$el&&this.$el.replaceWith(t),this.$el=t,this.opts.onAfterRender&&this.opts.onAfterRender()}getActions(){return this.actionInstance}getRender(){return this.renderInstance}getData(){return this.data}setData(t){this.data=t,this.render(),this.getRender().playFadeAnimForBody()}getParent(){return this.parent}getChildren(){return this.children}getNestCurt(){return this.nestCurt}getIsRoot(){return 0===this.data.rid}getID(){return this.data.id}putChild(t,e="append"){t.parent=this,t.nestCurt=this.nestCurt+1,this.children.push(t);const n=this.getChildrenWrapEl(),s=t.getEl();"append"===e?n.append(s):"prepend"===e&&n.prepend(s),t.getRender().playFadeAnim(),t.getRender().checkHeightLimit()}getChildrenWrapEl(){return this.nestCurt>=this.opts.nestMax?this.parent.getChildrenWrapEl():this.getRender().getChildrenWrap()}getParents(){const t=[];let e=this.parent;for(;e;)t.push(e),e=e.getParent();return t}getEl(){if(!this.$el)throw new Error("comment element not initialized before `getEl()`");return this.$el}focus(){if(!this.$el)throw new Error("comment element not initialized before `focus()`");this.getParents().forEach((t=>{t.getRender().heightLimitRemoveForChildren()})),this.scrollIntoView(),this.getRender().playFlashAnim()}scrollIntoView(){this.$el&&Nt(this.$el,!1,this.opts.scrollRelativeTo&&this.opts.scrollRelativeTo())}remove(){var t;null==(t=this.$el)||t.remove()}getGravatarURL(){return`${(t={mirror:this.opts.gravatar.mirror,params:this.opts.gravatar.params,emailHash:this.data.email_encrypted}).mirror.replace(/\/$/,"")}/${t.emailHash}?${t.params.replace(/^\?/,"")}`;var t}getContentMarked(){return Et(this.data.content)}getDateFormatted(){var t,e;const n=new Date(this.data.date);return(null==(e=(t=this.opts).dateFormatter)?void 0:e.call(t,n))||y(n,L)}getUserUA(){const t=function(t){const e=window||{},n=navigator||{},s=String(t||n.userAgent),i={os:"",osVersion:"",engine:"",browser:"",device:"",language:"",version:""},o={Trident:s.includes("Trident")||s.includes("NET CLR"),Presto:s.includes("Presto"),WebKit:s.includes("AppleWebKit"),Gecko:s.includes("Gecko/")},a={Safari:s.includes("Safari"),Chrome:s.includes("Chrome")||s.includes("CriOS"),IE:s.includes("MSIE")||s.includes("Trident"),Edge:s.includes("Edge")||s.includes("Edg"),Firefox:s.includes("Firefox")||s.includes("FxiOS"),"Firefox Focus":s.includes("Focus"),Servo:s.includes("Servo"),Chromium:s.includes("Chromium"),Opera:s.includes("Opera")||s.includes("OPR"),Vivaldi:s.includes("Vivaldi"),Yandex:s.includes("YaBrowser"),Kindle:s.includes("Kindle")||s.includes("Silk/"),360:s.includes("360EE")||s.includes("360SE"),UC:s.includes("UC")||s.includes(" UBrowser"),QQBrowser:s.includes("QQBrowser"),QQ:s.includes("QQ/"),Baidu:s.includes("Baidu")||s.includes("BIDUBrowser"),Maxthon:s.includes("Maxthon"),Sogou:s.includes("MetaSr")||s.includes("Sogou"),LBBROWSER:s.includes("LBBROWSER"),"2345Explorer":s.includes("2345Explorer"),TheWorld:s.includes("TheWorld"),MIUI:s.includes("MiuiBrowser"),HuaweiBrowser:s.includes("HuaweiBrowser"),Quark:s.includes("Quark"),Qiyu:s.includes("Qiyu"),"360Browser":s.includes("360Browser"),Wechat:s.includes("MicroMessenger"),Taobao:s.includes("AliApp(TB"),Alipay:s.includes("AliApp(AP"),Weibo:s.includes("Weibo"),Douban:s.includes("com.douban.frodo"),Suning:s.includes("SNEBUY-APP"),iQiYi:s.includes("IqiyiApp")},r={Windows:s.includes("Windows"),Linux:s.includes("Linux")||s.includes("X11"),macOS:s.includes("Macintosh"),Android:s.includes("Android")||s.includes("Adr"),Ubuntu:s.includes("Ubuntu"),FreeBSD:s.includes("FreeBSD"),Debian:s.includes("Debian"),"Windows Phone":s.includes("IEMobile")||s.includes("Windows Phone"),BlackBerry:s.includes("BlackBerry")||s.includes("RIM"),MeeGo:s.includes("MeeGo"),Symbian:s.includes("Symbian"),iOS:s.includes("like Mac OS X"),OpenHarmony:s.includes("OpenHarmony"),"Chrome OS":s.includes("CrOS"),WebOS:s.includes("hpwOS")},l={Mobile:s.includes("Mobi")||s.includes("iPh")||s.includes("480")||s.includes("Phone"),Tablet:s.includes("Tablet")||s.includes("Pad")||s.includes("Nexus 7")};l.Mobile?l.Mobile=!s.includes("iPad"):a.Chrome&&s.includes("Edg")?(a.Chrome=!1,a.Edge=!0):e.showModalDialog&&e.chrome&&(a.Chrome=!1,a[360]=!0),i.device="PC",i.language=(()=>{const t=(n.browserLanguage||n.language).split("-");return t[1]&&(t[1]=t[1].toUpperCase()),t.join("_")})();const c={engine:o,browser:a,os:r,device:l};Object.entries(c).forEach((([t,e])=>{Object.entries(e).forEach((([e,n])=>{!0===n&&(i[t]=e)}))}));const d={Windows:()=>{const t=s.replace(/^.*Windows NT ([\d.]+);.*$/,"$1");return{6.4:"10",6.3:"8.1",6.2:"8",6.1:"7","6.0":"Vista",5.2:"XP",5.1:"XP","5.0":"2000","10.0":"10","11.0":"11"}[t]||t},Android:()=>s.replace(/^.*Android ([\d.]+);.*$/,"$1"),iOS:()=>s.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,"."),Debian:()=>s.replace(/^.*Debian\/([\d.]+).*$/,"$1"),"Windows Phone":()=>s.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2"),macOS:()=>s.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,"."),OpenHarmony:()=>s.replace(/^.*OpenHarmony ([\d.]+).*$/,"$1"),WebOS:()=>s.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")};i.osVersion="",d[i.os]&&(i.osVersion=d[i.os](),i.osVersion===s&&(i.osVersion=""));const h={Safari:()=>s.replace(/^.*Version\/([\d.]+).*$/,"$1"),Chrome:()=>s.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1"),IE:()=>s.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1"),Edge:()=>s.replace(/^.*(Edge|Edg|Edg[A-Z]{1})\/([\d.]+).*$/,"$2"),Firefox:()=>s.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1"),"Firefox Focus":()=>s.replace(/^.*Focus\/([\d.]+).*$/,"$1"),Servo:()=>s.replace(/^.*Servo\/?([\d.]+).*$/,"$1"),Chromium:()=>s.replace(/^.*Chromium\/([\d.]+).*$/,"$1"),Opera:()=>s.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1"),Vivaldi:()=>s.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1"),Yandex:()=>s.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1"),Kindle:()=>s.replace(/^.*Version\/([\d.]+).*$/,"$1"),Maxthon:()=>s.replace(/^.*Maxthon\/([\d.]+).*$/,"$1"),QQBrowser:()=>s.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1"),QQ:()=>s.replace(/^.*QQ\/([\d.]+).*$/,"$1"),Baidu:()=>s.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1"),UC:()=>s.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1"),Sogou:()=>s.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1"),"2345Explorer":()=>s.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1"),TheWorld:()=>s.replace(/^.*TheWorld ([\d.]+).*$/,"$1"),MIUI:()=>s.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1"),HuaweiBrowser:()=>s.replace(/^.*HuaweiBrowser\/([\d.]+).*$/,"$1"),Quark:()=>s.replace(/^.*Quark\/([\d.]+).*$/,"$1"),Qiyu:()=>s.replace(/^.*Qiyu\/([\d.]+).*$/,"$1"),"360Browser":()=>s.replace(/^.*360Browser\/([\d.]+).*$/,"$1"),Wechat:()=>s.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1"),Taobao:()=>s.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1"),Alipay:()=>s.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1"),Weibo:()=>s.replace(/^.*weibo__([\d.]+).*$/,"$1"),Douban:()=>s.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1"),Suning:()=>s.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1"),iQiYi:()=>s.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")};return i.version="",h[i.browser]&&(i.version=h[i.browser](),i.version===s&&(i.version="")),i.version.indexOf(".")&&(i.version=i.version.substring(0,i.version.indexOf("."))),"iOS"===i.os&&s.includes("iPad")?i.os="iPadOS":"Edge"!==i.browser||s.includes("Edg")?"MIUI"===i.browser?i.os="Android":"Chrome"===i.browser&&Number(i.version)>27||"Opera"===i.browser&&Number(i.version)>12||"Yandex"===i.browser?i.engine="Blink":void 0===i.browser&&(i.browser="Unknow App"):i.engine="EdgeHTML",i}(this.data.ua);return{browser:`${t.browser} ${t.version}`,os:`${t.os} ${t.osVersion}`}}getOpts(){return this.opts}}class Ye{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 Je{constructor(){h(this,"instance"),h(this,"onReachedBottom",null),h(this,"opt")}create(t){return this.opt=t,this.instance=new Ye({pageSize:t.pageSize,onClick:e=>u(this,null,(function*(){t.getData().fetchComments({offset:e})})),text:L("loadMore")}),t.readMoreAutoLoad&&(this.onReachedBottom=()=>{this.instance.hasMore&&!this.opt.getData().getLoading()&&this.instance.click()},this.opt.getEvents().on("list-reach-bottom",this.onReachedBottom)),this.instance.$el}setLoading(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.getEvents().off("list-reach-bottom",this.onReachedBottom),this.instance.$el.remove()}}class Xe{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" aria-label="Previous page">\n <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="14px" width="14px" xmlns="http://www.w3.org/2000/svg"><path d="M217.9 256L345 129c9.4-9.4 9.4-24.6 0-33.9-9.4-9.4-24.6-9.3-34 0L167 239c-9.1 9.1-9.3 23.7-.7 33.1L310.9 417c4.7 4.7 10.9 7 17 7s12.3-2.3 17-7c9.4-9.4 9.4-24.6 0-33.9L217.9 256z"></path></svg>\n </div>\n <input type="text" class="atk-input" aria-label="Enter the number of page" />\n <div class="atk-btn atk-btn-next" aria-label="Next page">\n <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="14px" width="14px" xmlns="http://www.w3.org/2000/svg"><path d="M294.1 256L167 129c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.3 34 0L345 239c9.1 9.1 9.3 23.7.7 33.1L201.1 417c-4.7 4.7-10.9 7-17 7s-12.3-2.3-17-7c-9.4-9.4-9.4-24.6 0-33.9l127-127.1z"></path></svg>\n </div>\n </div>\n </div>'),this.$input=this.$el.querySelector(".atk-input"),this.$input.value=`${this.page}`,this.$input.oninput=()=>this.input(),this.$input.onkeydown=t=>this.keydown(t),this.$prevBtn=this.$el.querySelector(".atk-btn-prev"),this.$nextBtn=this.$el.querySelector(".atk-btn-next"),this.$prevBtn.onclick=()=>this.prev(),this.$nextBtn.onclick=()=>this.next(),this.checkDisabled()}get pageSize(){return this.opts.pageSize}get offset(){return this.pageSize*(this.page-1)}get maxPage(){return Math.ceil(this.total/this.pageSize)}update(t,e){this.page=Math.ceil(t/this.pageSize)+1,this.total=e,this.setInput(this.page),this.checkDisabled()}setInput(t){this.$input.value=`${t}`}input(t=!1){window.clearTimeout(this.inputTimer);const e=this.$input.value.trim(),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?_t(this.$el):Ft(this.$el)}}class Ze{constructor(){h(this,"instance")}create(t){return this.instance=new Xe(t.total,{pageSize:t.pageSize,onChange:e=>u(this,null,(function*(){t.resetEditorState(),t.getData().fetchComments({offset:e,onSuccess:()=>{var e;null==(e=t.onListGotoFirst)||e.call(t)}})}))}),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 tn(t){const e={offset:0,total:0};return t?(e.offset=t.params.offset,t.data&&(e.total=t.params.flatMode?t.data.count:t.data.roots_count),e):e}const en=t=>{let e=null;t.getConf().watchConf(["pagination","locale"],(n=>{const s=t.getList(),i=t.getData();e&&e.dispose(),e=function(t){return t.pagination.readMore?new Je:new Ze}(n);const{offset:o,total:a}=tn(i.getListLastFetch()),r=e.create(c({pageSize:n.pagination.pageSize,total:a,readMoreAutoLoad:n.pagination.autoLoad},t));s.getCommentsWrapEl().after(r),null==e||e.update(o,a)})),t.getEvents().on("list-loaded",(n=>{const{offset:s,total:i}=tn(t.getData().getListLastFetch());null==e||e.update(s,i)})),t.getEvents().on("list-fetch",(n=>{t.getData().getComments().length>0&&(null==e?void 0:e.getIsClearComments(n))&&t.getData().clearComments()})),t.getEvents().on("list-failed",(()=>{var t;null==(t=null==e?void 0:e.showErr)||t.call(e,L("loadFail"))})),t.getEvents().on("list-fetch",(t=>{null==e||e.setLoading(!0)})),t.getEvents().on("list-fetched",(({params:t})=>{null==e||e.setLoading(!1)}))};class nn{constructor(t){h(this,"opts"),h(this,"$el"),h(this,"$commentsWrap"),h(this,"commentNodes",[]),this.opts=t,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"),en(c({getList:()=>this},t)),this.initCrudEvents()}getEl(){return this.$el}getCommentsWrapEl(){return this.$commentsWrap}getCommentNodes(){return this.commentNodes}getLayout({forceFlatMode:t}={}){return new Ae({$commentsWrap:this.$commentsWrap,nestSortBy:this.opts.getConf().get().nestSort,nestMax:this.opts.getConf().get().nestMax,flatMode:"boolean"==typeof t?t:this.opts.getConf().get().flatMode,createCommentNode:(e,n)=>{const s=function(t,e,n){const s=t.getConf().get(),i=new Ge(e,{onAfterRender:()=>{t.getEvents().trigger("comment-rendered",i)},onDelete:e=>{t.getData().deleteComment(e.getID())},replyTo:n,flatMode:"boolean"==typeof(null==t?void 0:t.forceFlatMode)?null==t?void 0:t.forceFlatMode:s.flatMode,gravatar:s.gravatar,nestMax:s.nestMax,heightLimit:s.heightLimit,avatarURLBuilder:s.avatarURLBuilder,scrollRelativeTo:s.scrollRelativeTo,vote:s.vote,voteDown:s.voteDown,uaBadge:s.uaBadge,dateFormatter:s.dateFormatter,getApi:t.getApi,replyComment:t.replyComment,editComment:t.editComment});return i.render(),i}(c({forceFlatMode:t},this.opts),e,n);return this.commentNodes.push(s),s},findCommentNode:t=>this.commentNodes.find((e=>e.getID()===t))})}initCrudEvents(){this.opts.getEvents().on("list-load",(t=>{this.getLayout().import(t)})),this.opts.getEvents().on("list-loaded",(t=>{0===t.length&&(this.commentNodes=[],this.$commentsWrap.innerHTML="")})),this.opts.getEvents().on("comment-inserted",(t=>{var e;const n=t.rid?null==(e=this.commentNodes.find((e=>e.getID()===t.rid)))?void 0:e.getData():void 0;this.getLayout().insert(t,n)})),this.opts.getEvents().on("comment-deleted",(t=>{const e=this.commentNodes.find((e=>e.getID()===t.id));e?(e.remove(),this.commentNodes=this.commentNodes.filter((e=>e.getID()!==t.id))):console.error(`comment node id=${t.id} not found`)})),this.opts.getEvents().on("comment-updated",(t=>{const e=this.commentNodes.find((e=>e.getID()===t.id));e&&e.setData(t)}))}}class sn{constructor(t){h(this,"opts"),h(this,"$el"),h(this,"layer"),h(this,"$header"),h(this,"$closeBtn"),h(this,"$iframeWrap"),h(this,"$iframe"),h(this,"refreshWhenShow",!0),h(this,"animTimer"),this.opts=t,this.$el=p('<div class="atk-sidebar-layer">\n <div class="atk-sidebar-inner">\n <div class="atk-sidebar-header">\n <div class="atk-sidebar-close">\n <i class="atk-icon atk-icon-close-slim"></i>\n </div>\n </div>\n <div class="atk-sidebar-iframe-wrap"></div>\n </div>\n</div>\n'),this.$header=this.$el.querySelector(".atk-sidebar-header"),this.$closeBtn=this.$header.querySelector(".atk-sidebar-close"),this.$iframeWrap=this.$el.querySelector(".atk-sidebar-iframe-wrap"),this.$closeBtn.onclick=()=>{this.hide()}}onUserChanged(){return u(this,null,(function*(){this.refreshWhenShow=!0}))}show(){return u(this,arguments,(function*(t={}){if(this.$el.style.transform="",this.initLayer(),this.layer.show(),this.refreshWhenShow)this.refreshWhenShow=!1,this.$iframeWrap.innerHTML="",this.$iframe=this.createIframe(t.view),this.$iframeWrap.append(this.$iframe);else{const t=this.$iframe,e=t.src;this.getDarkMode()!==e.includes("&darkMode=1")&&this.iframeLoad(t,e.replace(/&darkMode=\d/,`&darkMode=${Number(this.getDarkMode())}`))}this.authCheck({onSuccess:()=>this.show(t)}),this.animTimer=setTimeout((()=>{var t,e;this.animTimer=void 0,this.$el.style.transform="translate(0, 0)",null==(e=(t=this.opts).onShow)||e.call(t)}),100)}))}hide(){var t;null==(t=this.layer)||t.hide()}authCheck(t){return u(this,null,(function*(){const e=(yield this.opts.getApi().user.getUserStatus(c({},this.opts.getApi().getUserFields()))).data;e.is_admin&&!e.is_login&&(this.refreshWhenShow=!0,this.opts.getCheckers().checkAdmin({onSuccess:()=>{setTimeout((()=>{t.onSuccess()}),500)},onCancel:()=>{this.hide()}}),this.hide())}))}initLayer(){this.layer||(this.layer=this.opts.getLayers().create("sidebar",this.$el),this.layer.setOnAfterHide((()=>{var t,e;this.animTimer&&clearTimeout(this.animTimer),this.$el.style.transform="",null==(e=(t=this.opts).onHide)||e.call(t)})))}createIframe(t){const e=p('<iframe referrerpolicy="strict-origin-when-cross-origin"></iframe>'),n=w({base:this.opts.getConf().get().server,path:"/sidebar/"}),s={pageKey:this.opts.getConf().get().pageKey,site:this.opts.getConf().get().site||"",user:JSON.stringify(this.opts.getUser().getData()),time:+new Date};t&&(s.view=t),s.darkMode=this.getDarkMode()?"1":"0";const i=new URLSearchParams(s);return this.iframeLoad(e,`${n}?${i.toString()}`),e}getDarkMode(){return"auto"===this.opts.getConf().get().darkMode?window.matchMedia("(prefers-color-scheme: dark)").matches:this.opts.getConf().get().darkMode}iframeLoad(t,e){t.src=e,_t(this.$iframeWrap),t.onload=()=>{Ft(this.$iframeWrap)}}}const on=[...new Set([t=>{t.provide("data",(t=>new $e(t)),["events"]),t.on("mounted",(()=>{t.getConf().fetchCommentsOnInit&&t.getData().fetchComments({offset:0})}))},t=>{t.provide("apiHandlers",(()=>function(){const t=[];return{add:(e,n)=>{t.push({action:e,handler:n})},remove:e=>{const n=t.findIndex((t=>t.action===e));-1!==n&&t.splice(n,1)},get:()=>t}}()),[]),t.provide("api",((t,e,n)=>new Ot(Tt(e.get(),t,n))),["user","config","apiHandlers"],{lifecycle:"transient"})},t=>{t.watchConf(["locale"],(t=>{var e;(e=t.locale)!==x&&(x=e,T="string"==typeof e?S(e):e)}))},t=>{t.provide("user",(()=>new de({onUserChanged:e=>{t.trigger("user-changed",e)}})),[])},t=>{t.provide("editor",((e,n)=>{const s=new ke({getEvents:()=>e,getConf:()=>n});return t.getEl().appendChild(s.getEl()),s}),["events","config"])},t=>{t.provide("list",((e,n,s,i,o)=>{const a=new nn({getApi:()=>e,getEvents:()=>n,getConf:()=>s,getData:()=>i,replyComment:(t,e)=>o.setReplyComment(t,e),editComment:(t,e)=>o.setEditComment(t,e),resetEditorState:()=>o.resetState(),onListGotoFirst:()=>t.listGotoFirst()});return t.getEl().appendChild(a.getEl()),a}),["api","events","config","data","editor"])},t=>{t.provide("checkers",((e,n,s,i,o)=>{const a=new fe({getApi:()=>e,getLayers:()=>s,getUser:()=>i,onReload:()=>t.reload(),getCaptchaIframeURL:()=>`${o.get().server}/api/v2/captcha/?t=${+new Date}`});return n.add("need_captcha",(t=>a.checkCaptcha(t))),n.add("need_login",(()=>a.checkAdmin({}))),a}),["api","apiHandlers","layers","user","config"])},t=>{t.provide("layers",(()=>{const e=new xe;return document.body.appendChild(e.getEl()),t.on("unmounted",(()=>{null==e||e.destroy()})),e}))},t=>{t.provide("sidebar",((e,n,s,i,o,a,r,l)=>{const c=new sn({onShow:()=>{setTimeout((()=>{n.updateNotifies([])}),0),e.trigger("sidebar-show")},onHide:()=>{s.resetState(),e.trigger("sidebar-hide")},getCheckers:()=>i,getApi:()=>o,getConf:()=>a,getUser:()=>r,getLayers:()=>l});return t.on("user-changed",(()=>{null==c||c.onUserChanged()})),c}),["events","data","editor","checkers","api","config","user","layers"])}]),t=>{t.watchConf(["imgLazyLoad","markedOptions"],(t=>{!function(t){try{if(!e.Marked.name)return}catch(s){return}const n=new e.Marked;n.setOptions(c(c({renderer:mt({imgLazyLoad:t.imgLazyLoad})},$t),t.markedOptions)),yt=n}({markedOptions:t.markedOptions,imgLazyLoad:t.imgLazyLoad})})),t.watchConf(["markedReplacers"],(t=>{var e;t.markedReplacers&&(e=t.markedReplacers,kt=e)}))},t=>{t.provide("editorPlugs",((e,n,s,i,o,a)=>{const r=new Zt({getArtalkRootEl:()=>t.getEl(),getEditor:()=>e,getConf:()=>n,getUser:()=>s,getApi:()=>a,getData:()=>i,getCheckers:()=>o,onSubmitted:()=>t.trigger("editor-submitted")});return e.setPlugins(r),r}),["editor","config","user","data","checkers","api"])},t=>{const e=t.inject("user"),n=()=>{var n;n=e.getData().is_admin,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.getEl()}).forEach((t=>{n?t.classList.remove("atk-hide"):t.classList.add("atk-hide")}))};t.on("list-loaded",(()=>{n()})),t.on("user-changed",(t=>{n()}))},...ne,t=>{t.on("list-fetch",(e=>{if(0!==e.offset)return;const n=t.getApi().getUserFields();n&&t.getApi().notifies.getNotifies(n).then((e=>{t.getData().updateNotifies(e.data.notifies)}))}))},t=>{t.watchConf(["site","pageKey","pageTitle","countEl","pvEl","statPageKeyAttr","pvAdd"],(e=>{Lt({getApi:()=>t.getApi(),siteName:e.site,pageKey:e.pageKey,pageTitle:e.pageTitle,countEl:e.countEl,pvEl:e.pvEl,pageKeyAttr:e.statPageKeyAttr,pvAdd:e.pvAdd})}))},t=>{const e=t.inject("list");t.watchConf(["apiVersion","versionCheck"],(t=>{t.apiVersion&&t.versionCheck&&!se&&function(t,e,n){const s=function(t,e){const n=t.split("."),s=e.split(".");for(let i=0;i<3;i++){const t=Number(n[i]),e=Number(s[i]);if(t>e)return 1;if(e>t)return-1;if(!Number.isNaN(t)&&Number.isNaN(e))return 1;if(Number.isNaN(t)&&!Number.isNaN(e))return-1}return 0}(e,n);if(0===s)return;const i=p(`<div class="atk-version-check-notice">${L("updateMsg",{name:L(s<0?"client":"server")})} <span class="atk-info">${L("currentVersion")}: ${L("client")} ${e} / ${L("server")} ${n}</span></div>`),o=p(`<span class="atk-ignore-btn">${L("ignore")}</span>`);o.onclick=()=>{i.remove(),se=!0},i.append(o),t.getEl().parentElement.prepend(i)}(e,te,t.apiVersion)}))},t=>{const e=t.inject("config"),n=t.inject("layers");let s;const i=e=>{const i=[t.getEl(),n.getEl()];ie||(ie=window.matchMedia("(prefers-color-scheme: dark)")),"auto"===e?(s||(s=t=>oe(i,t.matches),ie.addEventListener("change",s)),oe(i,ie.matches)):(s&&(ie.removeEventListener("change",s),s=void 0),oe(i,e))};t.watchConf(["darkMode"],(t=>i(t.darkMode))),t.on("created",(()=>i(e.get().darkMode))),t.on("unmounted",(()=>{s&&(null==ie||ie.removeEventListener("change",s)),s=void 0}))},t=>{const e=t.inject("config");let n,s={};t.watchConf(["pageVote"],(t=>{const e=c(c({},ae),"object"==typeof t.pageVote?t.pageVote:{});null==n||n(),t.pageVote&&(s=function(t,e,n,s){var i,o;const a=c({},t);return a.upBtnEl=document.querySelector(e.upBtnEl),a.downBtnEl=document.querySelector(e.downBtnEl),a.upCountEl=document.querySelector(e.upCountEl),a.downCountEl=document.querySelector(e.downCountEl),a.activeClass=e.activeClass,a.voteUpHandler=n,a.voteDownHandler=s,null==(i=a.upBtnEl)||i.addEventListener("click",n),null==(o=a.downBtnEl)||o.addEventListener("click",s),a}(s,e,r,l),n=()=>s=function(t){var e,n;return t.voteUpHandler&&(null==(e=t.upBtnEl)||e.removeEventListener("click",t.voteUpHandler)),t.voteDownHandler&&(null==(n=t.downBtnEl)||n.removeEventListener("click",t.voteDownHandler)),{}}(s))})),t.on("unmounted",(()=>{null==n||n(),t.off("list-fetched",o)})),t.on("list-fetched",o);let i=0;function o({data:n}){e.get().pageVote&&function(t){return t.upBtnEl||t.downBtnEl||t.upCountEl||t.downCountEl}(s)&&n&&(i!==n.page.id?(i=n.page.id,re(s,n.page.vote_up,n.page.vote_down,!1,!1),function(t,e,n){n.votes.getVote("page",e).then((({data:e})=>{re(t,e.up,e.down,e.is_up,e.is_down)})).catch((t=>{console.error("[ArtalkPageVote]",t)}))}(s,i,t.getApi())):re(s,n.page.vote_up,n.page.vote_down))}const a=()=>{var e;return{state:s,pageId:(null==(e=t.getData().getPage())?void 0:e.id)||0,httpApi:t.getApi()}},r=le("up",a),l=le("down",a)}],an=new Set([...on]),rn=new WeakMap;function ln(t,e){return u(this,null,(function*(){var n;const s=new Set,i=t=>{t.forEach((t=>{"function"==typeof t&&(s.has(t)||(t(e,rn.get(t)),s.add(t)))}))};i(an);const{data:o}=yield e.getApi().conf.conf().catch((n=>{throw((t,e={})=>{var n;const s=t.inject("list"),i=t.inject("user"),o=t.inject("config"),a=e.err;if(!a)throw new Error("MountError: `err` is required");let r="";if(null==(n=a.data)?void 0:n.err_no_site){const t={create_name:o.get().site,create_urls:`${window.location.protocol}//${window.location.host}`};r=`sites|${JSON.stringify(t)}`}ee({$err:s.getEl(),errMsg:a.msg||String(a),errData:a.data,retryFn:()=>{var t;return null==(t=e.onRetry)?void 0:t.call(e)},onOpenSidebar:i.getData().is_admin?()=>t.showSidebar({view:r}):void 0})})(e,{err:n,onRetry:()=>ln(t,e)}),n}));let a=d(c({},t),{apiVersion:null==(n=o.version)?void 0:n.version});const r=function(t){const e=["el","pageKey","pageTitle","server","site","pvEl","countEl","statPageKeyAttr","pageVote"];return Object.keys(t).forEach((n=>{e.includes(n)&&delete t[n],"darkMode"===n&&"auto"!==t[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}(o.frontend_conf||{});a=a.preferRemoteConf?bt(a,r):bt(r,a),e.updateConf(a),a.pluginURLs&&(yield function(t,e){return u(this,null,(function*(){const n=new Set;if(!t||!Array.isArray(t))return n;const s=[];return t.forEach((t=>{/^(http|https):\/\//.test(t)||(t=`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`),s.push(new Promise((e=>{if(document.querySelector(`script[src="${t}"]`))return void e();const n=document.createElement("script");n.src=t,document.head.appendChild(n),n.onload=()=>e(),n.onerror=t=>{console.error("[artalk] Failed to load plugin",t),e()}})))})),yield Promise.all(s),Object.values(window.ArtalkPlugins||{}).forEach((t=>{"function"==typeof t&&n.add(t)})),n}))}(a.pluginURLs,e.getConf().server).then((t=>{i(t)})).catch((t=>{console.error("Failed to load plugin",t)})))}))}function cn({keys:t,effect:e,getConf:n,getEvents:s}){let i=null;const o=()=>{const s=(()=>{const e=n(),s={};return t.forEach((t=>{s[t]=e[t]})),s})();var o,a;(null==i||(o=i,a=s,!(JSON.stringify(o)===JSON.stringify(a))))&&(i=s,e(s))};s().on("mounted",o),s().on("updated",o)}class dn{constructor(t){h(this,"ctx");const e=function(t){let e;if("string"==typeof t.el){const n=document.querySelector(t.el);if(!n)throw new Error(`Element "${t.el}" not found.`);e=n}else{if(!(t.el instanceof HTMLElement))throw new Error("Please provide a valid `el` config for Artalk.");e=t.el}return e}(t);e.classList.add("artalk"),e.innerHTML="",1==t.darkMode&&e.classList.add("atk-dark-mode");const n=this.ctx=new Ct(e);(t=>{t.provide("events",(()=>new Xt))})(n),(t=>{let e=xt({},!0);t.provide("config",(t=>{let n=!1;return t.on("mounted",(()=>n=!0)),{watchConf:(n,s)=>{cn({keys:n,effect:s,getConf:()=>e,getEvents:()=>t})},get:()=>e,update:s=>{e=bt(e,xt(s,!1)),n&&t.trigger("updated",e)}}}),["events"])})(n),n.updateConf(t),n.trigger("created");(()=>{u(this,null,(function*(){yield ln(t,n),n.trigger("mounted")}))})()}getConf(){return this.ctx.getConf()}getEl(){return this.ctx.getEl()}update(t){this.ctx.updateConf(t)}reload(){this.ctx.reload()}destroy(){this.ctx.destroy()}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 dn(t)}static use(t,e){an.add(t),rn.set(t,e)}static loadCountWidget(t){const e=xt(t,!0);Lt({getApi:()=>new Ot(Tt(e)),siteName:e.site,countEl:e.countEl,pvEl:e.pvEl,pageKeyAttr:e.statPageKeyAttr,pvAdd:!1})}get $root(){return console.warn("`$root` is deprecated, please use `getEl()` instead"),this.getEl()}get conf(){return console.warn("`conf` is deprecated, please use `getConf()` instead"),this.getConf()}}const hn=dn.init,un=dn.use,pn=dn.loadCountWidget;t.Defaults=St,t.default=dn,t.init=hn,t.loadCountWidget=pn,t.use=un,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
11
|
+
//# sourceMappingURL=ArtalkLite.js.map
|