artalk 2.7.1 → 2.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -1
  3. package/dist/Artalk.cjs +2 -0
  4. package/dist/Artalk.cjs.map +1 -0
  5. package/dist/Artalk.css +1 -1
  6. package/dist/Artalk.iife.js +1 -1
  7. package/dist/Artalk.iife.js.map +1 -1
  8. package/dist/Artalk.js +1 -1
  9. package/dist/Artalk.js.map +1 -1
  10. package/dist/{Artalk.es.js → Artalk.mjs} +250 -222
  11. package/dist/Artalk.mjs.map +1 -0
  12. package/dist/ArtalkLite.cjs +2 -0
  13. package/dist/ArtalkLite.cjs.map +1 -0
  14. package/dist/ArtalkLite.css +1 -1
  15. package/dist/ArtalkLite.iife.js +1 -1
  16. package/dist/ArtalkLite.iife.js.map +1 -1
  17. package/dist/ArtalkLite.js +1 -1
  18. package/dist/ArtalkLite.js.map +1 -1
  19. package/dist/{ArtalkLite.es.js → ArtalkLite.mjs} +250 -227
  20. package/dist/ArtalkLite.mjs.map +1 -0
  21. package/dist/i18n/jp.cjs +1 -0
  22. package/dist/i18n/jp.d.cts +3 -0
  23. package/dist/i18n/jp.d.ts +3 -0
  24. package/dist/i18n/jp.js +1 -1
  25. package/dist/i18n/jp.mjs +93 -0
  26. package/dist/i18n/zh-TW.cjs +1 -0
  27. package/dist/i18n/zh-TW.d.cts +3 -0
  28. package/dist/i18n/zh-TW.d.ts +3 -0
  29. package/dist/i18n/zh-TW.js +1 -1
  30. package/dist/i18n/zh-TW.mjs +93 -0
  31. package/dist/main.d.cts +1476 -0
  32. package/dist/main.d.ts +1476 -0
  33. package/package.json +80 -22
  34. package/dist/Artalk.es.js.map +0 -1
  35. package/dist/ArtalkLite.es.js.map +0 -1
  36. package/dist/src/api/_base.d.ts +0 -10
  37. package/dist/src/api/_options.d.ts +0 -19
  38. package/dist/src/api/_request.d.ts +0 -12
  39. package/dist/src/api/admin.d.ts +0 -10
  40. package/dist/src/api/captcha.d.ts +0 -14
  41. package/dist/src/api/comment.d.ts +0 -29
  42. package/dist/src/api/index.d.ts +0 -29
  43. package/dist/src/api/page.d.ts +0 -22
  44. package/dist/src/api/site.d.ts +0 -17
  45. package/dist/src/api/system.d.ts +0 -33
  46. package/dist/src/api/upload.d.ts +0 -11
  47. package/dist/src/api/user.d.ts +0 -42
  48. package/dist/src/artalk.d.ts +0 -35
  49. package/dist/src/comment/actions.d.ts +0 -17
  50. package/dist/src/comment/comment.d.ts +0 -66
  51. package/dist/src/comment/height-limit.d.ts +0 -30
  52. package/dist/src/comment/index.d.ts +0 -2
  53. package/dist/src/comment/render.d.ts +0 -46
  54. package/dist/src/comment/renders/actions.d.ts +0 -5
  55. package/dist/src/comment/renders/avatar.d.ts +0 -5
  56. package/dist/src/comment/renders/content.d.ts +0 -5
  57. package/dist/src/comment/renders/header.d.ts +0 -5
  58. package/dist/src/comment/renders/index.d.ts +0 -2
  59. package/dist/src/comment/renders/pending.d.ts +0 -5
  60. package/dist/src/comment/renders/reply-at.d.ts +0 -5
  61. package/dist/src/comment/renders/reply-to.d.ts +0 -5
  62. package/dist/src/components/action-btn.d.ts +0 -50
  63. package/dist/src/components/checker/admin.d.ts +0 -3
  64. package/dist/src/components/checker/captcha-renders.d.ts +0 -5
  65. package/dist/src/components/checker/captcha.d.ts +0 -3
  66. package/dist/src/components/checker/index.d.ts +0 -51
  67. package/dist/src/components/dark-mode.d.ts +0 -2
  68. package/dist/src/components/dialog.d.ts +0 -16
  69. package/dist/src/components/error-dialog.d.ts +0 -8
  70. package/dist/src/components/pagination.d.ts +0 -31
  71. package/dist/src/components/read-more-btn.d.ts +0 -33
  72. package/dist/src/config.d.ts +0 -24
  73. package/dist/src/context.d.ts +0 -45
  74. package/dist/src/data.d.ts +0 -27
  75. package/dist/src/defaults.d.ts +0 -3
  76. package/dist/src/editor/editor.d.ts +0 -31
  77. package/dist/src/editor/state.d.ts +0 -20
  78. package/dist/src/editor/ui.d.ts +0 -25
  79. package/dist/src/i18n/en.d.ts +0 -72
  80. package/dist/src/i18n/external.d.ts +0 -73
  81. package/dist/src/i18n/index.d.ts +0 -233
  82. package/dist/src/i18n/jp.d.ts +0 -72
  83. package/dist/src/i18n/zh-CN.d.ts +0 -3
  84. package/dist/src/i18n/zh-TW.d.ts +0 -72
  85. package/dist/src/layer/index.d.ts +0 -4
  86. package/dist/src/layer/layer-manager.d.ts +0 -9
  87. package/dist/src/layer/layer.d.ts +0 -12
  88. package/dist/src/layer/scrollbar-helper.d.ts +0 -5
  89. package/dist/src/layer/sidebar-layer.d.ts +0 -20
  90. package/dist/src/layer/wrap.d.ts +0 -13
  91. package/dist/src/lib/component.d.ts +0 -7
  92. package/dist/src/lib/detect.d.ts +0 -10
  93. package/dist/src/lib/event-manager.d.ts +0 -28
  94. package/dist/src/lib/highlight.d.ts +0 -1
  95. package/dist/src/lib/marked-renderer.d.ts +0 -4
  96. package/dist/src/lib/marked.d.ts +0 -11
  97. package/dist/src/lib/sanitizer.d.ts +0 -1
  98. package/dist/src/lib/ui.d.ts +0 -24
  99. package/dist/src/lib/user.d.ts +0 -19
  100. package/dist/src/lib/utils.d.ts +0 -41
  101. package/dist/src/list/comment.d.ts +0 -3
  102. package/dist/src/list/layout.d.ts +0 -23
  103. package/dist/src/list/list.d.ts +0 -14
  104. package/dist/src/list/nest.d.ts +0 -10
  105. package/dist/src/list/page.d.ts +0 -2
  106. package/dist/src/list/paginator/index.d.ts +0 -25
  107. package/dist/src/list/paginator/read-more.d.ts +0 -18
  108. package/dist/src/list/paginator/up-down.d.ts +0 -14
  109. package/dist/src/main.d.ts +0 -7
  110. package/dist/src/plugins/admin-only-elem.d.ts +0 -2
  111. package/dist/src/plugins/conf-remoter.d.ts +0 -2
  112. package/dist/src/plugins/dark-mode.d.ts +0 -2
  113. package/dist/src/plugins/editor/_kit.d.ts +0 -27
  114. package/dist/src/plugins/editor/_plug.d.ts +0 -29
  115. package/dist/src/plugins/editor/_sample.d.ts +0 -5
  116. package/dist/src/plugins/editor/closable.d.ts +0 -7
  117. package/dist/src/plugins/editor/emoticons.d.ts +0 -30
  118. package/dist/src/plugins/editor/header-event.d.ts +0 -6
  119. package/dist/src/plugins/editor/header-link.d.ts +0 -6
  120. package/dist/src/plugins/editor/header-user.d.ts +0 -16
  121. package/dist/src/plugins/editor/index.d.ts +0 -6
  122. package/dist/src/plugins/editor/local-storage.d.ts +0 -6
  123. package/dist/src/plugins/editor/mover.d.ts +0 -6
  124. package/dist/src/plugins/editor/preview.d.ts +0 -7
  125. package/dist/src/plugins/editor/state-edit.d.ts +0 -11
  126. package/dist/src/plugins/editor/state-reply.d.ts +0 -8
  127. package/dist/src/plugins/editor/submit-add.d.ts +0 -18
  128. package/dist/src/plugins/editor/submit-btn.d.ts +0 -5
  129. package/dist/src/plugins/editor/submit.d.ts +0 -17
  130. package/dist/src/plugins/editor/textarea.d.ts +0 -8
  131. package/dist/src/plugins/editor/upload.d.ts +0 -9
  132. package/dist/src/plugins/editor-kit.d.ts +0 -42
  133. package/dist/src/plugins/index.d.ts +0 -2
  134. package/dist/src/plugins/list/copyright.d.ts +0 -2
  135. package/dist/src/plugins/list/count.d.ts +0 -2
  136. package/dist/src/plugins/list/dropdown.d.ts +0 -2
  137. package/dist/src/plugins/list/error-dialog.d.ts +0 -2
  138. package/dist/src/plugins/list/fetch.d.ts +0 -2
  139. package/dist/src/plugins/list/goto-first.d.ts +0 -3
  140. package/dist/src/plugins/list/goto.d.ts +0 -2
  141. package/dist/src/plugins/list/index.d.ts +0 -3
  142. package/dist/src/plugins/list/loading.d.ts +0 -2
  143. package/dist/src/plugins/list/no-comment.d.ts +0 -2
  144. package/dist/src/plugins/list/reach-bottom.d.ts +0 -2
  145. package/dist/src/plugins/list/sidebar-btn.d.ts +0 -2
  146. package/dist/src/plugins/list/time-ticking.d.ts +0 -3
  147. package/dist/src/plugins/list/unread-badge.d.ts +0 -2
  148. package/dist/src/plugins/list/unread.d.ts +0 -2
  149. package/dist/src/plugins/list/with-editor.d.ts +0 -2
  150. package/dist/src/plugins/markdown.d.ts +0 -2
  151. package/dist/src/plugins/stat.d.ts +0 -13
  152. package/dist/src/plugins/version-check.d.ts +0 -2
  153. package/dist/src/service.d.ts +0 -42
  154. package/dist/tests/e2e/comment-add.spec.d.ts +0 -1
  155. package/dist/types/config.d.ts +0 -110
  156. package/dist/types/context.d.ts +0 -62
  157. package/dist/types/data.d.ts +0 -194
  158. package/dist/types/editor.d.ts +0 -76
  159. package/dist/types/event.d.ts +0 -39
  160. package/dist/types/global.d.ts +0 -1
  161. package/dist/types/index.d.ts +0 -7
  162. package/dist/types/plugin.d.ts +0 -2
  163. package/dist/types/sidebar.d.ts +0 -3
  164. package/src/api/_base.ts +0 -18
  165. package/src/api/_options.ts +0 -25
  166. package/src/api/_request.ts +0 -104
  167. package/src/api/admin.ts +0 -18
  168. package/src/api/captcha.ts +0 -24
  169. package/src/api/comment.ts +0 -84
  170. package/src/api/index.ts +0 -29
  171. package/src/api/page.ts +0 -83
  172. package/src/api/site.ts +0 -51
  173. package/src/api/system.ts +0 -49
  174. package/src/api/upload.ts +0 -28
  175. package/src/api/user.ts +0 -132
  176. package/src/artalk.ts +0 -115
  177. package/src/comment/actions.ts +0 -83
  178. package/src/comment/comment.html +0 -18
  179. package/src/comment/comment.ts +0 -192
  180. package/src/comment/height-limit.ts +0 -100
  181. package/src/comment/index.ts +0 -3
  182. package/src/comment/render.ts +0 -150
  183. package/src/comment/renders/actions.ts +0 -114
  184. package/src/comment/renders/avatar.ts +0 -22
  185. package/src/comment/renders/content.ts +0 -39
  186. package/src/comment/renders/header.ts +0 -84
  187. package/src/comment/renders/index.ts +0 -19
  188. package/src/comment/renders/pending.ts +0 -12
  189. package/src/comment/renders/reply-at.ts +0 -16
  190. package/src/comment/renders/reply-to.ts +0 -24
  191. package/src/components/action-btn.ts +0 -170
  192. package/src/components/checker/admin.ts +0 -37
  193. package/src/components/checker/captcha-renders.ts +0 -69
  194. package/src/components/checker/captcha.ts +0 -26
  195. package/src/components/checker/index.ts +0 -192
  196. package/src/components/dark-mode.ts +0 -30
  197. package/src/components/dialog.ts +0 -62
  198. package/src/components/error-dialog.ts +0 -35
  199. package/src/components/pagination.ts +0 -153
  200. package/src/components/read-more-btn.ts +0 -92
  201. package/src/config.ts +0 -119
  202. package/src/context.ts +0 -146
  203. package/src/data.ts +0 -110
  204. package/src/defaults.ts +0 -61
  205. package/src/editor/editor.html +0 -18
  206. package/src/editor/editor.ts +0 -114
  207. package/src/editor/state.ts +0 -52
  208. package/src/editor/ui.ts +0 -36
  209. package/src/i18n/en.ts +0 -84
  210. package/src/i18n/external.ts +0 -10
  211. package/src/i18n/index.ts +0 -67
  212. package/src/i18n/jp.ts +0 -86
  213. package/src/i18n/zh-CN.ts +0 -88
  214. package/src/i18n/zh-TW.ts +0 -86
  215. package/src/layer/index.ts +0 -4
  216. package/src/layer/layer-manager.ts +0 -32
  217. package/src/layer/layer.ts +0 -39
  218. package/src/layer/scrollbar-helper.ts +0 -24
  219. package/src/layer/sidebar-layer.html +0 -8
  220. package/src/layer/sidebar-layer.ts +0 -155
  221. package/src/layer/wrap.ts +0 -77
  222. package/src/lib/component.ts +0 -12
  223. package/src/lib/detect.ts +0 -222
  224. package/src/lib/event-manager.ts +0 -47
  225. package/src/lib/highlight.ts +0 -5
  226. package/src/lib/marked-renderer.ts +0 -32
  227. package/src/lib/marked.ts +0 -72
  228. package/src/lib/sanitizer.ts +0 -57
  229. package/src/lib/ui.ts +0 -193
  230. package/src/lib/user.ts +0 -55
  231. package/src/lib/utils.ts +0 -236
  232. package/src/list/comment.ts +0 -20
  233. package/src/list/layout.ts +0 -120
  234. package/src/list/list.html +0 -20
  235. package/src/list/list.ts +0 -79
  236. package/src/list/nest.ts +0 -66
  237. package/src/list/page.ts +0 -97
  238. package/src/list/paginator/index.ts +0 -25
  239. package/src/list/paginator/read-more.ts +0 -67
  240. package/src/list/paginator/up-down.ts +0 -51
  241. package/src/main.ts +0 -14
  242. package/src/plugins/admin-only-elem.ts +0 -40
  243. package/src/plugins/conf-remoter.ts +0 -54
  244. package/src/plugins/dark-mode.ts +0 -12
  245. package/src/plugins/editor/_kit.ts +0 -57
  246. package/src/plugins/editor/_plug.ts +0 -60
  247. package/src/plugins/editor/_sample.ts +0 -8
  248. package/src/plugins/editor/closable.ts +0 -44
  249. package/src/plugins/editor/emoticons.scss +0 -72
  250. package/src/plugins/editor/emoticons.ts +0 -293
  251. package/src/plugins/editor/header-event.ts +0 -35
  252. package/src/plugins/editor/header-link.ts +0 -31
  253. package/src/plugins/editor/header-user.ts +0 -98
  254. package/src/plugins/editor/index.ts +0 -40
  255. package/src/plugins/editor/local-storage.ts +0 -36
  256. package/src/plugins/editor/mover.ts +0 -29
  257. package/src/plugins/editor/preview.scss +0 -7
  258. package/src/plugins/editor/preview.ts +0 -41
  259. package/src/plugins/editor/state-edit.ts +0 -116
  260. package/src/plugins/editor/state-reply.ts +0 -91
  261. package/src/plugins/editor/submit-add.ts +0 -33
  262. package/src/plugins/editor/submit-btn.ts +0 -25
  263. package/src/plugins/editor/submit.ts +0 -73
  264. package/src/plugins/editor/textarea.ts +0 -55
  265. package/src/plugins/editor/upload.ts +0 -145
  266. package/src/plugins/editor-kit.ts +0 -161
  267. package/src/plugins/index.ts +0 -16
  268. package/src/plugins/list/copyright.ts +0 -16
  269. package/src/plugins/list/count.ts +0 -31
  270. package/src/plugins/list/dropdown.ts +0 -95
  271. package/src/plugins/list/error-dialog.ts +0 -22
  272. package/src/plugins/list/fetch.ts +0 -64
  273. package/src/plugins/list/goto-first.ts +0 -23
  274. package/src/plugins/list/goto.ts +0 -72
  275. package/src/plugins/list/index.ts +0 -25
  276. package/src/plugins/list/loading.ts +0 -17
  277. package/src/plugins/list/no-comment.ts +0 -25
  278. package/src/plugins/list/reach-bottom.ts +0 -46
  279. package/src/plugins/list/sidebar-btn.ts +0 -39
  280. package/src/plugins/list/time-ticking.ts +0 -22
  281. package/src/plugins/list/unread-badge.ts +0 -26
  282. package/src/plugins/list/unread.ts +0 -38
  283. package/src/plugins/list/with-editor.ts +0 -59
  284. package/src/plugins/markdown.ts +0 -10
  285. package/src/plugins/stat.ts +0 -82
  286. package/src/plugins/version-check.ts +0 -36
  287. package/src/service.ts +0 -91
  288. package/src/style/_color.scss +0 -41
  289. package/src/style/_extend.scss +0 -20
  290. package/src/style/_variables.scss +0 -3
  291. package/src/style/comment.scss +0 -360
  292. package/src/style/editor.scss +0 -194
  293. package/src/style/list.scss +0 -212
  294. package/src/style/main.scss +0 -486
  295. package/src/style/pagination.scss +0 -58
  296. package/src/style/sidebar-layer.scss +0 -92
  297. package/types/config.ts +0 -153
  298. package/types/context.ts +0 -84
  299. package/types/data.ts +0 -271
  300. package/types/editor.ts +0 -95
  301. package/types/event.ts +0 -40
  302. package/types/global.d.ts +0 -1
  303. package/types/index.ts +0 -7
  304. package/types/plugin.ts +0 -3
  305. package/types/sidebar.ts +0 -3
@@ -55,7 +55,6 @@ var __async = (__this, __arguments, generator) => {
55
55
  });
56
56
  };
57
57
  var _parseMarkdown, parseMarkdown_fn, _onError, onError_fn;
58
- const main = "";
59
58
  function createElement(htmlStr = "") {
60
59
  const div = document.createElement("div");
61
60
  div.innerHTML = htmlStr.trim();
@@ -224,24 +223,6 @@ function getURLBasedOnApi(opts) {
224
223
  function getURLBasedOn(baseURL, path) {
225
224
  return `${baseURL.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
226
225
  }
227
- function mergeDeep(target, source) {
228
- const isObject = (obj) => obj && typeof obj === "object";
229
- if (!isObject(target) || !isObject(source)) {
230
- return source;
231
- }
232
- Object.keys(source).forEach((key) => {
233
- const targetValue = target[key];
234
- const sourceValue = source[key];
235
- if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
236
- target[key] = targetValue.concat(sourceValue);
237
- } else if (isObject(targetValue) && isObject(sourceValue)) {
238
- target[key] = mergeDeep(__spreadValues({}, targetValue), sourceValue);
239
- } else {
240
- target[key] = sourceValue;
241
- }
242
- });
243
- return target;
244
- }
245
226
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
246
227
  function getDefaultExportFromCjs(x) {
247
228
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
@@ -642,48 +623,6 @@ function getDefaultExportFromCjs(x) {
642
623
  });
643
624
  })(typeof self !== "undefined" ? self : commonjsGlobal);
644
625
  });
645
- const LOCAL_USER_KEY = "ArtalkUser";
646
- class User {
647
- constructor() {
648
- __publicField(this, "data");
649
- __publicField(this, "onUserChanged", null);
650
- const localUser = JSON.parse(window.localStorage.getItem(LOCAL_USER_KEY) || "{}");
651
- this.data = {
652
- nick: localUser.nick || "",
653
- email: localUser.email || "",
654
- link: localUser.link || "",
655
- token: localUser.token || "",
656
- isAdmin: localUser.isAdmin || false
657
- };
658
- }
659
- /** 保存用户到 localStorage 中 */
660
- update(obj = {}) {
661
- Object.entries(obj).forEach(([key, value]) => {
662
- this.data[key] = value;
663
- });
664
- window.localStorage.setItem(LOCAL_USER_KEY, JSON.stringify(this.data));
665
- this.onUserChanged && this.onUserChanged(this.data);
666
- }
667
- setOnUserChanged(fn) {
668
- this.onUserChanged = fn;
669
- }
670
- /**
671
- * Logout
672
- *
673
- * @description Logout will clear login status, but not clear user data (nick, email, link)
674
- */
675
- logout() {
676
- this.update({
677
- token: "",
678
- isAdmin: false
679
- });
680
- }
681
- /** 是否已填写基本用户信息 */
682
- checkHasBasicUserInfo() {
683
- return !!this.data.nick && !!this.data.email;
684
- }
685
- }
686
- const UserInstance = new User();
687
626
  const en = {
688
627
  /* Editor */
689
628
  placeholder: "Leave a comment",
@@ -760,7 +699,8 @@ const en = {
760
699
  reqAborted: "Request timed out or terminated unexpectedly",
761
700
  updateMsg: "Please update Artalk {name} to get the full experience",
762
701
  currentVersion: "Current Version",
763
- ignore: "Ignore"
702
+ ignore: "Ignore",
703
+ open: "Open"
764
704
  };
765
705
  const zhCN = {
766
706
  /* Editor */
@@ -838,7 +778,8 @@ const zhCN = {
838
778
  reqAborted: "请求超时或意外终止",
839
779
  updateMsg: "请更新 Artalk {name} 以获得完整体验",
840
780
  currentVersion: "当前版本",
841
- ignore: "忽略"
781
+ ignore: "忽略",
782
+ open: "打开"
842
783
  };
843
784
  const GLOBAL_LOCALES_KEY = "ArtalkI18n";
844
785
  const internal = {
@@ -875,9 +816,9 @@ function t(key, args = {}) {
875
816
  function Fetch$1(opts, input, init2, timeout) {
876
817
  return __async(this, null, function* () {
877
818
  var _a, _b;
878
- if (UserInstance.data.token) {
819
+ if (opts.apiToken) {
879
820
  const headers = new Headers(init2.headers);
880
- headers.set("Authorization", `Bearer ${UserInstance.data.token}`);
821
+ headers.set("Authorization", `Bearer ${opts.apiToken}`);
881
822
  init2.headers = headers;
882
823
  }
883
824
  const resp = yield timeoutFetch(input, timeout || opts.timeout || 15e3, init2);
@@ -969,6 +910,20 @@ class ApiBase {
969
910
  return Fetch$1(this.options, this.options.baseURL + path, init2, timeout);
970
911
  });
971
912
  }
913
+ /**
914
+ * Carry user info to request params
915
+ *
916
+ * @param params Request params
917
+ * @returns Request params with user info
918
+ */
919
+ withUserInfo(params) {
920
+ const user = this.options.userInfo;
921
+ if (user == null ? void 0 : user.name)
922
+ params.name = user.name;
923
+ if (user == null ? void 0 : user.email)
924
+ params.email = user.email;
925
+ return params;
926
+ }
972
927
  }
973
928
  class CommentApi extends ApiBase {
974
929
  /** 评论 · 获取 */
@@ -981,10 +936,7 @@ class CommentApi extends ApiBase {
981
936
  };
982
937
  if (flatMode)
983
938
  params.flat_mode = flatMode;
984
- if (UserInstance.checkHasBasicUserInfo()) {
985
- params.name = UserInstance.data.nick;
986
- params.email = UserInstance.data.email;
987
- }
939
+ this.withUserInfo(params);
988
940
  if (paramsEditor)
989
941
  paramsEditor(params);
990
942
  return this.POST("/get", params);
@@ -1033,10 +985,7 @@ class CommentApi extends ApiBase {
1033
985
  target_id: targetID,
1034
986
  type
1035
987
  };
1036
- if (UserInstance.checkHasBasicUserInfo()) {
1037
- params.name = UserInstance.data.nick;
1038
- params.email = UserInstance.data.email;
1039
- }
988
+ this.withUserInfo(params);
1040
989
  const data = yield this.POST("/vote", params);
1041
990
  return data;
1042
991
  });
@@ -1205,10 +1154,7 @@ class UserApi extends ApiBase {
1205
1154
  /** 用户 · 登录状态 */
1206
1155
  loginStatus() {
1207
1156
  return __async(this, null, function* () {
1208
- const data = yield this.POST("/login-status", {
1209
- name: UserInstance.data.nick,
1210
- email: UserInstance.data.email
1211
- });
1157
+ const data = yield this.POST("/login-status", this.withUserInfo({}));
1212
1158
  return data || { is_login: false, is_admin: false };
1213
1159
  });
1214
1160
  }
@@ -1228,8 +1174,7 @@ class UserApi extends ApiBase {
1228
1174
  delete params.comment_id;
1229
1175
  delete params.notify_key;
1230
1176
  params.read_all = true;
1231
- params.name = UserInstance.data.nick;
1232
- params.email = UserInstance.data.email;
1177
+ this.withUserInfo(params);
1233
1178
  }
1234
1179
  return this.POST(`/mark-read`, params);
1235
1180
  }
@@ -1366,10 +1311,9 @@ class UploadApi extends ApiBase {
1366
1311
  imgUpload(file) {
1367
1312
  return __async(this, null, function* () {
1368
1313
  const params = {
1369
- name: UserInstance.data.nick,
1370
- email: UserInstance.data.email,
1371
1314
  page_key: this.options.pageKey
1372
1315
  };
1316
+ this.withUserInfo(params);
1373
1317
  const form = ToFormData(params);
1374
1318
  form.set("file", file);
1375
1319
  const init2 = {
@@ -3733,12 +3677,12 @@ function parser$1(html, handler) {
3733
3677
  }
3734
3678
  }
3735
3679
  function parseComment() {
3736
- var index2 = html.indexOf("-->");
3737
- if (index2 >= 0) {
3680
+ var index = html.indexOf("-->");
3681
+ if (index >= 0) {
3738
3682
  if (handler.comment) {
3739
- handler.comment(html.substring(4, index2));
3683
+ handler.comment(html.substring(4, index));
3740
3684
  }
3741
- html = html.substring(index2 + 3);
3685
+ html = html.substring(index + 3);
3742
3686
  chars = false;
3743
3687
  }
3744
3688
  }
@@ -3747,10 +3691,10 @@ function parser$1(html, handler) {
3747
3691
  return;
3748
3692
  }
3749
3693
  var text;
3750
- var index2 = html.indexOf("<");
3751
- if (index2 >= 0) {
3752
- text = html.substring(0, index2);
3753
- html = html.substring(index2);
3694
+ var index = html.indexOf("<");
3695
+ if (index >= 0) {
3696
+ text = html.substring(0, index);
3697
+ html = html.substring(index);
3754
3698
  } else {
3755
3699
  text = html;
3756
3700
  html = "";
@@ -4101,13 +4045,13 @@ var hanabi$1 = { exports: {} };
4101
4045
  };
4102
4046
  });
4103
4047
  var defaultColors = ["23AC69", "91C132", "F19726", "E8552D", "1AAB8E", "E1147F", "2980C1", "1BA1E6", "9FA0A0", "F19726", "E30B20", "E30B20", "A3338B"];
4104
- var index2 = function(input, ref) {
4048
+ var index = function(input, ref) {
4105
4049
  if (ref === void 0)
4106
4050
  ref = {};
4107
4051
  var colors = ref.colors;
4108
4052
  if (colors === void 0)
4109
4053
  colors = defaultColors;
4110
- var index3 = 0;
4054
+ var index2 = 0;
4111
4055
  var cache = {};
4112
4056
  var wordRe = /[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af\u0400-\u04FF]+|\w+/;
4113
4057
  var leftAngleRe = /</;
@@ -4123,18 +4067,18 @@ var hanabi$1 = { exports: {} };
4123
4067
  if (cache[word]) {
4124
4068
  color = cache[word];
4125
4069
  } else {
4126
- color = colors[index3];
4070
+ color = colors[index2];
4127
4071
  cache[word] = color;
4128
4072
  }
4129
4073
  var out = '<span style="color: #' + color + '">' + word + "</span>";
4130
- index3 = ++index3 % colors.length;
4074
+ index2 = ++index2 % colors.length;
4131
4075
  return out;
4132
4076
  });
4133
4077
  };
4134
4078
  function toComment(cm) {
4135
4079
  return '<span style="color: slategray">' + cm + "</span>";
4136
4080
  }
4137
- return index2;
4081
+ return index;
4138
4082
  });
4139
4083
  })(hanabi$1);
4140
4084
  var hanabiExports = hanabi$1.exports;
@@ -4213,6 +4157,26 @@ function marked(src) {
4213
4157
  function simpleMarked(src) {
4214
4158
  return src.replace(/```\s*([^]+?.*?[^]+?[^]+?)```/g, (_, code) => `<pre><code>${renderCode(code)}</code></pre>`).replace(/!\[(.*?)\]\((.*?)\)/g, (_, alt, imgSrc) => `<img src="${imgSrc}" alt="${alt}" />`).replace(/\[(.*?)\]\((.*?)\)/g, (_, text, link) => `<a href="${link}" target="_blank">${text}</a>`).replace(/\n/g, "<br>");
4215
4159
  }
4160
+ function mergeDeep(...objects) {
4161
+ const isObject = (obj) => obj && typeof obj === "object" && obj.constructor === Object;
4162
+ return objects.reduce((prev, obj) => {
4163
+ Object.keys(obj != null ? obj : {}).forEach((key) => {
4164
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
4165
+ return;
4166
+ }
4167
+ const pVal = prev[key];
4168
+ const oVal = obj[key];
4169
+ if (Array.isArray(pVal) && Array.isArray(oVal)) {
4170
+ prev[key] = pVal.concat(...oVal);
4171
+ } else if (isObject(pVal) && isObject(oVal)) {
4172
+ prev[key] = mergeDeep(pVal, oVal);
4173
+ } else {
4174
+ prev[key] = oVal;
4175
+ }
4176
+ });
4177
+ return prev;
4178
+ }, {});
4179
+ }
4216
4180
  class DataManager {
4217
4181
  constructor(events) {
4218
4182
  __publicField(this, "loading", false);
@@ -4370,11 +4334,9 @@ const defaults = {
4370
4334
  useBackendConf: true,
4371
4335
  locale: "zh-CN"
4372
4336
  };
4373
- function handelCustomConf(customConf) {
4374
- const conf = mergeDeep(defaults, customConf);
4375
- if (customConf.el)
4376
- conf.el = customConf.el;
4377
- if (typeof conf.el === "string" && !!conf.el) {
4337
+ function handelCustomConf(customConf, full = false) {
4338
+ const conf = full ? mergeDeep(defaults, customConf) : customConf;
4339
+ if (conf.el && typeof conf.el === "string") {
4378
4340
  try {
4379
4341
  const findEl = document.querySelector(conf.el);
4380
4342
  if (!findEl)
@@ -4385,20 +4347,18 @@ function handelCustomConf(customConf) {
4385
4347
  throw new Error("Please check your Artalk `el` config.");
4386
4348
  }
4387
4349
  }
4388
- conf.server = conf.server.replace(/\/$/, "").replace(/\/api\/?$/, "");
4389
- if (!conf.pageKey) {
4350
+ if (conf.pageKey === "")
4390
4351
  conf.pageKey = `${window.location.pathname}`;
4391
- }
4392
- if (!conf.pageTitle) {
4352
+ if (conf.pageTitle === "")
4393
4353
  conf.pageTitle = `${document.title}`;
4394
- }
4395
- if (conf.locale === "auto") {
4354
+ if (conf.server)
4355
+ conf.server = conf.server.replace(/\/$/, "").replace(/\/api\/?$/, "");
4356
+ if (conf.locale === "auto")
4396
4357
  conf.locale = navigator.language;
4397
- }
4398
- if (conf.flatMode === true || Number(conf.nestMax) <= 1)
4399
- conf.flatMode = true;
4400
4358
  if (conf.flatMode === "auto")
4401
4359
  conf.flatMode = window.matchMedia("(max-width: 768px)").matches;
4360
+ if (typeof conf.nestMax === "number" && Number(conf.nestMax) <= 1)
4361
+ conf.flatMode = true;
4402
4362
  return conf;
4403
4363
  }
4404
4364
  function handleConfFormServer(conf) {
@@ -4431,6 +4391,11 @@ function convertApiOptions(conf, ctx) {
4431
4391
  pageKey: conf.pageKey || "",
4432
4392
  pageTitle: conf.pageTitle || "",
4433
4393
  timeout: conf.reqTimeout,
4394
+ apiToken: ctx == null ? void 0 : ctx.get("user").getData().token,
4395
+ userInfo: (ctx == null ? void 0 : ctx.get("user").checkHasBasicUserInfo()) ? {
4396
+ name: ctx == null ? void 0 : ctx.get("user").getData().nick,
4397
+ email: ctx == null ? void 0 : ctx.get("user").getData().email
4398
+ } : void 0,
4434
4399
  onNeedCheckAdmin(payload) {
4435
4400
  ctx == null ? void 0 : ctx.checkAdmin({
4436
4401
  onSuccess: () => {
@@ -4456,7 +4421,7 @@ function convertApiOptions(conf, ctx) {
4456
4421
  };
4457
4422
  }
4458
4423
  class Context {
4459
- constructor(conf, $root) {
4424
+ constructor(conf) {
4460
4425
  /* 运行参数 */
4461
4426
  __publicField(this, "conf");
4462
4427
  __publicField(this, "data");
@@ -4464,7 +4429,7 @@ class Context {
4464
4429
  /* Event Manager */
4465
4430
  __publicField(this, "events", new EventManager());
4466
4431
  this.conf = conf;
4467
- this.$root = $root || document.createElement("div");
4432
+ this.$root = conf.el;
4468
4433
  this.$root.classList.add("artalk");
4469
4434
  this.$root.innerHTML = "";
4470
4435
  this.data = new DataManager(this.events);
@@ -4494,7 +4459,7 @@ class Context {
4494
4459
  this.data.fetchComments({ offset: 0 });
4495
4460
  }
4496
4461
  listGotoFirst() {
4497
- this.trigger("list-goto-first");
4462
+ this.events.trigger("list-goto-first");
4498
4463
  }
4499
4464
  /* 编辑器 */
4500
4465
  editorShowLoading() {
@@ -4539,11 +4504,17 @@ class Context {
4539
4504
  }
4540
4505
  setDarkMode(darkMode) {
4541
4506
  this.conf.darkMode = darkMode;
4542
- this.trigger("dark-mode-changed", darkMode);
4507
+ this.events.trigger("dark-mode-changed", darkMode);
4543
4508
  }
4544
4509
  updateConf(nConf) {
4545
- this.conf = mergeDeep(this.conf, handelCustomConf(nConf));
4546
- this.trigger("conf-loaded", this.conf);
4510
+ this.conf = mergeDeep(this.conf, handelCustomConf(nConf, false));
4511
+ this.events.trigger("conf-loaded", this.conf);
4512
+ }
4513
+ getConf() {
4514
+ return this.conf;
4515
+ }
4516
+ getEl() {
4517
+ return this.$root;
4547
4518
  }
4548
4519
  getMarked() {
4549
4520
  return getInstance();
@@ -4750,7 +4721,7 @@ function imgBody(checker) {
4750
4721
  }
4751
4722
  function iframeBody(checker) {
4752
4723
  const $iframeWrap = createElement(`<div class="atk-checker-iframe-wrap"></div>`);
4753
- const $iframe = createElement(`<iframe class="atk-fade-in"></iframe>`);
4724
+ const $iframe = createElement(`<iframe class="atk-fade-in" referrerpolicy="strict-origin-when-cross-origin"></iframe>`);
4754
4725
  $iframe.style.display = "none";
4755
4726
  showLoading($iframeWrap, { transparentBg: true });
4756
4727
  $iframe.src = `${checker.getOpts().getIframeURLBase() || ""}/api/captcha/get?t=${+/* @__PURE__ */ new Date()}`;
@@ -4814,8 +4785,8 @@ const AdminChecker = {
4814
4785
  inputType: "password",
4815
4786
  request(checker, inputVal) {
4816
4787
  const data = {
4817
- name: UserInstance.data.nick,
4818
- email: UserInstance.data.email,
4788
+ name: checker.getUser().getData().nick,
4789
+ email: checker.getUser().getData().email,
4819
4790
  password: inputVal
4820
4791
  };
4821
4792
  return (() => __async(this, null, function* () {
@@ -4827,7 +4798,7 @@ const AdminChecker = {
4827
4798
  return createElement(`<span>${t("adminCheck")}</span>`);
4828
4799
  },
4829
4800
  onSuccess(checker, userToken, inputVal, formEl) {
4830
- UserInstance.update({
4801
+ checker.getUser().update({
4831
4802
  isAdmin: true,
4832
4803
  token: userToken
4833
4804
  });
@@ -4860,6 +4831,7 @@ class CheckerLauncher {
4860
4831
  },
4861
4832
  get: (key) => checkerStore[key],
4862
4833
  getOpts: () => this.opts,
4834
+ getUser: () => this.opts.getCtx().get("user"),
4863
4835
  getApi: () => this.opts.getApi(),
4864
4836
  hideInteractInput: () => {
4865
4837
  hideInteractInput = true;
@@ -5251,7 +5223,7 @@ class SidebarLayer extends Component {
5251
5223
  });
5252
5224
  }
5253
5225
  createIframe(view) {
5254
- const $iframe = createElement("<iframe></iframe>");
5226
+ const $iframe = createElement('<iframe referrerpolicy="strict-origin-when-cross-origin"></iframe>');
5255
5227
  const baseURL = getURLBasedOnApi({
5256
5228
  base: this.ctx.conf.server,
5257
5229
  path: "/sidebar/"
@@ -5259,7 +5231,7 @@ class SidebarLayer extends Component {
5259
5231
  const query = {
5260
5232
  pageKey: this.conf.pageKey,
5261
5233
  site: this.conf.site || "",
5262
- user: JSON.stringify(UserInstance.data),
5234
+ user: JSON.stringify(this.ctx.get("user").getData()),
5263
5235
  time: +/* @__PURE__ */ new Date()
5264
5236
  };
5265
5237
  if (view)
@@ -5336,7 +5308,7 @@ class ListLayout {
5336
5308
  constructor(options) {
5337
5309
  this.options = options;
5338
5310
  }
5339
- // TODO refactor `if syntax` to strategy pattern
5311
+ // TODO: refactor `if syntax` to strategy pattern
5340
5312
  import(comments) {
5341
5313
  if (this.options.flatMode) {
5342
5314
  comments.forEach((commentData) => {
@@ -5412,9 +5384,9 @@ class ListLayout {
5412
5384
  scrollIntoView(comment.getEl());
5413
5385
  }
5414
5386
  }
5415
- const win = window || {};
5416
- const nav = navigator || {};
5417
5387
  function Detect(userAgent) {
5388
+ const win = window || {};
5389
+ const nav = navigator || {};
5418
5390
  const u = String(userAgent || nav.userAgent);
5419
5391
  const dest = {
5420
5392
  os: "",
@@ -6763,20 +6735,6 @@ const initListPaginatorFunc = (ctx) => {
6763
6735
  var _a;
6764
6736
  (_a = paginator == null ? void 0 : paginator.showErr) == null ? void 0 : _a.call(paginator, t("loadFail"));
6765
6737
  });
6766
- const autoSwitchPageForFindComment = (commentID) => {
6767
- const comment = ctx.getData().findComment(commentID);
6768
- if (!!comment || !(paginator == null ? void 0 : paginator.getHasMore()))
6769
- return;
6770
- ctx.on("list-loaded", () => {
6771
- autoSwitchPageForFindComment(commentID);
6772
- }, { once: true });
6773
- setTimeout(() => {
6774
- paginator == null ? void 0 : paginator.next();
6775
- }, 80);
6776
- };
6777
- ctx.on("list-goto", (commentID) => {
6778
- autoSwitchPageForFindComment(commentID);
6779
- });
6780
6738
  ctx.on("list-fetch", (params) => {
6781
6739
  paginator == null ? void 0 : paginator.setLoading(true);
6782
6740
  });
@@ -6974,6 +6932,47 @@ class LayerManager {
6974
6932
  return layer;
6975
6933
  }
6976
6934
  }
6935
+ const LOCAL_USER_KEY = "ArtalkUser";
6936
+ class User {
6937
+ constructor(opts) {
6938
+ __publicField(this, "data");
6939
+ this.opts = opts;
6940
+ const localUser = JSON.parse(window.localStorage.getItem(LOCAL_USER_KEY) || "{}");
6941
+ this.data = {
6942
+ nick: localUser.nick || "",
6943
+ email: localUser.email || "",
6944
+ link: localUser.link || "",
6945
+ token: localUser.token || "",
6946
+ isAdmin: localUser.isAdmin || false
6947
+ };
6948
+ }
6949
+ getData() {
6950
+ return this.data;
6951
+ }
6952
+ /** 保存用户到 localStorage 中 */
6953
+ update(obj = {}) {
6954
+ Object.entries(obj).forEach(([key, value]) => {
6955
+ this.data[key] = value;
6956
+ });
6957
+ window.localStorage.setItem(LOCAL_USER_KEY, JSON.stringify(this.data));
6958
+ this.opts.onUserChanged && this.opts.onUserChanged(this.data);
6959
+ }
6960
+ /**
6961
+ * Logout
6962
+ *
6963
+ * @description Logout will clear login status, but not clear user data (nick, email, link)
6964
+ */
6965
+ logout() {
6966
+ this.update({
6967
+ token: "",
6968
+ isAdmin: false
6969
+ });
6970
+ }
6971
+ /** 是否已填写基本用户信息 */
6972
+ checkHasBasicUserInfo() {
6973
+ return !!this.data.nick && !!this.data.email;
6974
+ }
6975
+ }
6977
6976
  const services = {
6978
6977
  // I18n
6979
6978
  i18n(ctx) {
@@ -6984,10 +6983,12 @@ const services = {
6984
6983
  },
6985
6984
  // User Store
6986
6985
  user(ctx) {
6987
- UserInstance.setOnUserChanged((user) => {
6988
- ctx == null ? void 0 : ctx.trigger("user-changed", user);
6986
+ const user = new User({
6987
+ onUserChanged: (data) => {
6988
+ ctx.trigger("user-changed", data);
6989
+ }
6989
6990
  });
6990
- return UserInstance;
6991
+ return user;
6991
6992
  },
6992
6993
  // 弹出层
6993
6994
  layerManager(ctx) {
@@ -7037,17 +7038,19 @@ function showErrorDialog(opts) {
7037
7038
  errEl.appendChild($retryBtn);
7038
7039
  }
7039
7040
  if (opts.onOpenSidebar) {
7040
- const $openSidebar = createElement('<span atk-only-admin-show> | <span style="cursor:pointer;">打开控制台</span></span>');
7041
+ const $openSidebar = createElement(`<span atk-only-admin-show> | <span style="cursor:pointer;">${t("open") + t("ctrlCenter")}</span></span>`);
7041
7042
  errEl.appendChild($openSidebar);
7042
- if (!UserInstance.data.isAdmin) {
7043
- $openSidebar.classList.add("atk-hide");
7044
- }
7045
7043
  $openSidebar.onclick = () => opts.onOpenSidebar && opts.onOpenSidebar();
7046
7044
  }
7047
7045
  setError(opts.$err, errEl);
7048
7046
  }
7049
7047
  const ConfRemoter = (ctx) => {
7050
7048
  ctx.on("inited", () => {
7049
+ if (ctx.conf.immediateFetch === false)
7050
+ return;
7051
+ ctx.trigger("conf-fetch");
7052
+ });
7053
+ ctx.on("conf-fetch", () => {
7051
7054
  loadConf(ctx);
7052
7055
  });
7053
7056
  };
@@ -7077,9 +7080,10 @@ function loadConf(ctx) {
7077
7080
  errMsg: err.msg || String(err),
7078
7081
  errData: err.data,
7079
7082
  retryFn: () => loadConf(ctx),
7080
- onOpenSidebar: () => ctx.showSidebar({
7083
+ onOpenSidebar: ctx.get("user").getData().isAdmin ? () => ctx.showSidebar({
7081
7084
  view: sidebarOpenView
7082
- })
7085
+ }) : void 0
7086
+ // only show open sidebar button when user is admin
7083
7087
  });
7084
7088
  throw err;
7085
7089
  }).then(() => {
@@ -7184,7 +7188,7 @@ class SubmitAddPreset {
7184
7188
  });
7185
7189
  }
7186
7190
  getSubmitAddParams() {
7187
- const { nick, email, link } = UserInstance.data;
7191
+ const { nick, email, link } = this.kit.useUser().getData();
7188
7192
  const conf = this.kit.useConf();
7189
7193
  return {
7190
7194
  content: this.kit.useEditor().getContentFinal(),
@@ -7382,7 +7386,7 @@ class StateEdit extends EditorPlug {
7382
7386
  ui.$editCancelBtn = void 0;
7383
7387
  }
7384
7388
  this.comment = void 0;
7385
- const { nick, email, link } = UserInstance.data;
7389
+ const { nick, email, link } = this.kit.useUser().getData();
7386
7390
  ui.$nick.value = nick;
7387
7391
  ui.$email.value = email;
7388
7392
  ui.$link.value = link;
@@ -7421,7 +7425,7 @@ class Closable extends EditorPlug {
7421
7425
  close() {
7422
7426
  if (!this.kit.useUI().$textareaWrap.querySelector(".atk-comment-closed"))
7423
7427
  this.kit.useUI().$textareaWrap.prepend(createElement(`<div class="atk-comment-closed">${t("onlyAdminCanReply")}</div>`));
7424
- if (!UserInstance.data.isAdmin) {
7428
+ if (!this.kit.useUser().getData().isAdmin) {
7425
7429
  this.kit.useUI().$textarea.style.display = "none";
7426
7430
  this.kit.useEvents().trigger("panel-close");
7427
7431
  this.kit.useUI().$bottom.style.display = "none";
@@ -7466,14 +7470,14 @@ class HeaderUser extends EditorPlug {
7466
7470
  const onInput = ({ $input, field }) => {
7467
7471
  if (this.kit.useEditor().getState() === "edit")
7468
7472
  return;
7469
- UserInstance.update({ [field]: $input.value.trim() });
7473
+ this.kit.useUser().update({ [field]: $input.value.trim() });
7470
7474
  if (field === "nick" || field === "email")
7471
7475
  this.fetchUserInfo();
7472
7476
  };
7473
7477
  this.kit.useMounted(() => {
7474
7478
  Object.entries(this.kit.useEditor().getHeaderInputEls()).forEach(([key, $input]) => {
7475
7479
  $input.placeholder = `${t(key)}`;
7476
- $input.value = UserInstance.data[key] || "";
7480
+ $input.value = this.kit.useUser().getData()[key] || "";
7477
7481
  });
7478
7482
  this.kit.useEvents().on("header-input", onInput);
7479
7483
  });
@@ -7485,7 +7489,7 @@ class HeaderUser extends EditorPlug {
7485
7489
  * Fetch user info from server
7486
7490
  */
7487
7491
  fetchUserInfo() {
7488
- UserInstance.logout();
7492
+ this.kit.useUser().logout();
7489
7493
  if (this.query.timer)
7490
7494
  window.clearTimeout(this.query.timer);
7491
7495
  if (this.query.abortFn)
@@ -7493,8 +7497,8 @@ class HeaderUser extends EditorPlug {
7493
7497
  this.query.timer = window.setTimeout(() => {
7494
7498
  this.query.timer = null;
7495
7499
  const { req, abort } = this.kit.useApi().user.userGet(
7496
- UserInstance.data.nick,
7497
- UserInstance.data.email
7500
+ this.kit.useUser().getData().nick,
7501
+ this.kit.useUser().getData().email
7498
7502
  );
7499
7503
  this.query.abortFn = abort;
7500
7504
  req.then((data) => this.onUserInfoFetched(data)).catch((err) => {
@@ -7511,9 +7515,9 @@ class HeaderUser extends EditorPlug {
7511
7515
  onUserInfoFetched(data) {
7512
7516
  var _a;
7513
7517
  if (!data.is_login)
7514
- UserInstance.logout();
7518
+ this.kit.useUser().logout();
7515
7519
  this.kit.useGlobalCtx().getData().updateUnreads(data.unread);
7516
- if (UserInstance.checkHasBasicUserInfo() && !data.is_login && ((_a = data.user) == null ? void 0 : _a.is_admin)) {
7520
+ if (this.kit.useUser().checkHasBasicUserInfo() && !data.is_login && ((_a = data.user) == null ? void 0 : _a.is_admin)) {
7517
7521
  this.kit.useGlobalCtx().checkAdmin({
7518
7522
  onSuccess: () => {
7519
7523
  }
@@ -7521,7 +7525,7 @@ class HeaderUser extends EditorPlug {
7521
7525
  }
7522
7526
  if (data.user && data.user.link) {
7523
7527
  this.kit.useUI().$link.value = data.user.link;
7524
- UserInstance.update({ link: data.user.link });
7528
+ this.kit.useUser().update({ link: data.user.link });
7525
7529
  }
7526
7530
  }
7527
7531
  }
@@ -7543,11 +7547,10 @@ class HeaderLink extends EditorPlug {
7543
7547
  const link = this.kit.useUI().$link.value.trim();
7544
7548
  if (!!link && !/^(http|https):\/\//.test(link)) {
7545
7549
  this.kit.useUI().$link.value = `https://${link}`;
7546
- UserInstance.update({ link: this.kit.useUI().$link.value });
7550
+ this.kit.useUser().update({ link: this.kit.useUI().$link.value });
7547
7551
  }
7548
7552
  }
7549
7553
  }
7550
- const emoticons = "";
7551
7554
  class Emoticons extends EditorPlug {
7552
7555
  constructor(kit) {
7553
7556
  super(kit);
@@ -7619,7 +7622,7 @@ class Emoticons extends EditorPlug {
7619
7622
  data.push(grp);
7620
7623
  };
7621
7624
  const remoteLoad = (d) => __async(this, null, function* () {
7622
- yield Promise.all(d.map((grp, index2) => __async(this, null, function* () {
7625
+ yield Promise.all(d.map((grp, index) => __async(this, null, function* () {
7623
7626
  if (typeof grp === "object" && !Array.isArray(grp)) {
7624
7627
  pushGrp(grp);
7625
7628
  } else if (Array.isArray(grp)) {
@@ -7663,7 +7666,8 @@ class Emoticons extends EditorPlug {
7663
7666
  return json;
7664
7667
  } catch (err) {
7665
7668
  hideLoading(this.$panel);
7666
- setError(this.$panel, `表情加载失败 ${String(err)}`);
7669
+ console.error("[Emoticons] Load Failed:", err);
7670
+ setError(this.$panel, `${t("emoticon")}${t("loadFail")} ${String(err)}`);
7667
7671
  return [];
7668
7672
  }
7669
7673
  });
@@ -7671,9 +7675,9 @@ class Emoticons extends EditorPlug {
7671
7675
  /** 避免表情 item.key 为 null 的情况 */
7672
7676
  solveNullKey(data) {
7673
7677
  data.forEach((grp) => {
7674
- grp.items.forEach((item, index2) => {
7678
+ grp.items.forEach((item, index) => {
7675
7679
  if (!item.key)
7676
- item.key = `${grp.name} ${index2 + 1}`;
7680
+ item.key = `${grp.name} ${index + 1}`;
7677
7681
  });
7678
7682
  });
7679
7683
  }
@@ -7706,14 +7710,14 @@ class Emoticons extends EditorPlug {
7706
7710
  const dest = [];
7707
7711
  Object.entries(owoData).forEach(([grpName, grp]) => {
7708
7712
  const nGrp = { name: grpName, type: grp.type, items: [] };
7709
- grp.container.forEach((item, index2) => {
7713
+ grp.container.forEach((item, index) => {
7710
7714
  const iconStr = item.icon;
7711
7715
  if (/<(img|IMG)/.test(iconStr)) {
7712
7716
  const find = /src=["'](.*?)["']/.exec(iconStr);
7713
7717
  if (find && find.length > 1)
7714
7718
  item.icon = find[1];
7715
7719
  }
7716
- nGrp.items.push({ key: item.text || `${grpName} ${index2 + 1}`, val: item.icon });
7720
+ nGrp.items.push({ key: item.text || `${grpName} ${index + 1}`, val: item.icon });
7717
7721
  });
7718
7722
  dest.push(nGrp);
7719
7723
  });
@@ -7723,10 +7727,10 @@ class Emoticons extends EditorPlug {
7723
7727
  initEmoticonsList() {
7724
7728
  this.$grpWrap = createElement(`<div class="atk-grp-wrap"></div>`);
7725
7729
  this.$panel.append(this.$grpWrap);
7726
- this.emoticons.forEach((grp, index2) => {
7730
+ this.emoticons.forEach((grp, index) => {
7727
7731
  const $grp = createElement(`<div class="atk-grp" style="display: none;"></div>`);
7728
7732
  this.$grpWrap.append($grp);
7729
- $grp.setAttribute("data-index", String(index2));
7733
+ $grp.setAttribute("data-index", String(index));
7730
7734
  $grp.setAttribute("data-grp-name", grp.name);
7731
7735
  $grp.setAttribute("data-type", grp.type);
7732
7736
  grp.items.forEach((item) => {
@@ -7754,11 +7758,11 @@ class Emoticons extends EditorPlug {
7754
7758
  if (this.emoticons.length > 1) {
7755
7759
  this.$grpSwitcher = createElement(`<div class="atk-grp-switcher"></div>`);
7756
7760
  this.$panel.append(this.$grpSwitcher);
7757
- this.emoticons.forEach((grp, index2) => {
7761
+ this.emoticons.forEach((grp, index) => {
7758
7762
  const $item = createElement("<span />");
7759
7763
  $item.innerText = grp.name;
7760
- $item.setAttribute("data-index", String(index2));
7761
- $item.onclick = () => this.openGrp(index2);
7764
+ $item.setAttribute("data-index", String(index));
7765
+ $item.onclick = () => this.openGrp(index);
7762
7766
  this.$grpSwitcher.append($item);
7763
7767
  });
7764
7768
  }
@@ -7766,18 +7770,18 @@ class Emoticons extends EditorPlug {
7766
7770
  this.openGrp(0);
7767
7771
  }
7768
7772
  /** 打开一个表情组 */
7769
- openGrp(index2) {
7773
+ openGrp(index) {
7770
7774
  var _a, _b, _c;
7771
7775
  Array.from(this.$grpWrap.children).forEach((item) => {
7772
7776
  const el = item;
7773
- if (el.getAttribute("data-index") !== String(index2)) {
7777
+ if (el.getAttribute("data-index") !== String(index)) {
7774
7778
  el.style.display = "none";
7775
7779
  } else {
7776
7780
  el.style.display = "";
7777
7781
  }
7778
7782
  });
7779
7783
  (_a = this.$grpSwitcher) == null ? void 0 : _a.querySelectorAll("span.active").forEach((item) => item.classList.remove("active"));
7780
- (_c = (_b = this.$grpSwitcher) == null ? void 0 : _b.querySelector(`span[data-index="${index2}"]`)) == null ? void 0 : _c.classList.add("active");
7784
+ (_c = (_b = this.$grpSwitcher) == null ? void 0 : _b.querySelector(`span[data-index="${index}"]`)) == null ? void 0 : _c.classList.add("active");
7781
7785
  this.changeListHeight();
7782
7786
  }
7783
7787
  changeListHeight() {
@@ -7789,7 +7793,7 @@ class Emoticons extends EditorPlug {
7789
7793
  this.emoticons.forEach((grp) => {
7790
7794
  if (grp.type !== "image")
7791
7795
  return;
7792
- Object.entries(grp.items).forEach(([index2, item]) => {
7796
+ Object.entries(grp.items).forEach(([index, item]) => {
7793
7797
  text = text.split(`:[${item.key}]`).join(`<img src="${item.val}" atk-emoticon="${item.key}">`);
7794
7798
  });
7795
7799
  });
@@ -7872,7 +7876,7 @@ class Upload extends EditorPlug {
7872
7876
  const fileExt = /[^.]+$/.exec(file.name);
7873
7877
  if (!fileExt || !AllowImgExts.includes(fileExt[0]))
7874
7878
  return;
7875
- if (!UserInstance.checkHasBasicUserInfo()) {
7879
+ if (!this.kit.useUser().checkHasBasicUserInfo()) {
7876
7880
  this.kit.useEditor().showNotify(t("uploadLoginMsg"), "w");
7877
7881
  return;
7878
7882
  }
@@ -7907,7 +7911,6 @@ class Upload extends EditorPlug {
7907
7911
  });
7908
7912
  }
7909
7913
  }
7910
- const preview = "";
7911
7914
  class Preview extends EditorPlug {
7912
7915
  constructor(kit) {
7913
7916
  super(kit);
@@ -7970,7 +7973,11 @@ class PlugKit {
7970
7973
  useEditor() {
7971
7974
  return this.plugs.editor;
7972
7975
  }
7973
- /** Use the context of global */
7976
+ /**
7977
+ * Use the context of global
7978
+ *
7979
+ * @deprecated The calls to this function should be reduced as much as possible
7980
+ */
7974
7981
  useGlobalCtx() {
7975
7982
  return this.plugs.editor.ctx;
7976
7983
  }
@@ -7982,6 +7989,10 @@ class PlugKit {
7982
7989
  useApi() {
7983
7990
  return this.plugs.editor.ctx.getApi();
7984
7991
  }
7992
+ /** Use the user manager */
7993
+ useUser() {
7994
+ return this.plugs.editor.ctx.get("user");
7995
+ }
7985
7996
  /** Use the ui of editor */
7986
7997
  useUI() {
7987
7998
  return this.plugs.editor.getUI();
@@ -8199,7 +8210,7 @@ const SidebarBtn = (ctx) => {
8199
8210
  const syncByUser = () => {
8200
8211
  if (!$openSidebarBtn)
8201
8212
  return;
8202
- const user = ctx.get("user").data;
8213
+ const user = ctx.get("user").getData();
8203
8214
  if (!!user.nick && !!user.email) {
8204
8215
  $openSidebarBtn.classList.remove("atk-hide");
8205
8216
  const $btnText = $openSidebarBtn.querySelector(".atk-text");
@@ -8298,7 +8309,7 @@ function extractCommentID() {
8298
8309
  }
8299
8310
  return commentId || null;
8300
8311
  }
8301
- const version = "2.7.1";
8312
+ const version = "2.7.3";
8302
8313
  const Copyright = (ctx) => {
8303
8314
  ctx.on("conf-loaded", () => {
8304
8315
  const list = ctx.get("list");
@@ -8631,7 +8642,7 @@ function versionCheck(list, feVer, beVer) {
8631
8642
  }
8632
8643
  const AdminOnlyElem = (ctx) => {
8633
8644
  const scanApply = () => {
8634
- applyAdminOnlyEls(ctx.get("user").data.isAdmin, getAdminOnlyEls({
8645
+ applyAdminOnlyEls(ctx.get("user").getData().isAdmin, getAdminOnlyEls({
8635
8646
  $root: ctx.$root
8636
8647
  }));
8637
8648
  };
@@ -8658,38 +8669,44 @@ function applyAdminOnlyEls(isAdmin, els) {
8658
8669
  $item.classList.add("atk-hide");
8659
8670
  });
8660
8671
  }
8661
- const darkModeMedia = window.matchMedia("(prefers-color-scheme: dark)");
8662
- let darkModeAutoFunc;
8663
- function applyDarkMode($els, darkMode) {
8664
- const apply = (d) => {
8665
- $els.forEach(($el) => updateClassName($el, d));
8666
- };
8667
- if (darkMode === "auto") {
8668
- if (!darkModeAutoFunc) {
8669
- darkModeAutoFunc = (evt) => apply(evt.matches);
8670
- darkModeMedia.addEventListener("change", darkModeAutoFunc);
8671
- }
8672
- apply(darkModeMedia.matches);
8673
- } else {
8674
- if (darkModeAutoFunc)
8675
- darkModeMedia.removeEventListener("change", darkModeAutoFunc);
8676
- apply(darkMode);
8677
- }
8678
- }
8679
- const DarkModeClassName = "atk-dark-mode";
8680
- function updateClassName($el, darkMode) {
8681
- if (darkMode)
8682
- $el.classList.add(DarkModeClassName);
8683
- else
8684
- $el.classList.remove(DarkModeClassName);
8672
+ let darkModeMedia;
8673
+ function updateClassnames($els, darkMode) {
8674
+ const DarkModeClassName = "atk-dark-mode";
8675
+ $els.forEach(($el) => {
8676
+ if (darkMode)
8677
+ $el.classList.add(DarkModeClassName);
8678
+ else
8679
+ $el.classList.remove(DarkModeClassName);
8680
+ });
8685
8681
  }
8686
8682
  const DarkMode = (ctx) => {
8687
- const sync = () => {
8688
- applyDarkMode([ctx.$root, ctx.get("layerManager").getEl()], ctx.conf.darkMode);
8683
+ let darkModeAutoHandler;
8684
+ const sync = (darkMode) => {
8685
+ const $els = [ctx.$root, ctx.get("layerManager").getEl()];
8686
+ if (!darkModeMedia) {
8687
+ darkModeMedia = window.matchMedia("(prefers-color-scheme: dark)");
8688
+ }
8689
+ if (darkMode === "auto") {
8690
+ if (!darkModeAutoHandler) {
8691
+ darkModeAutoHandler = (evt) => updateClassnames($els, evt.matches);
8692
+ darkModeMedia.addEventListener("change", darkModeAutoHandler);
8693
+ }
8694
+ updateClassnames($els, darkModeMedia.matches);
8695
+ } else {
8696
+ if (darkModeAutoHandler) {
8697
+ darkModeMedia.removeEventListener("change", darkModeAutoHandler);
8698
+ darkModeAutoHandler = void 0;
8699
+ }
8700
+ updateClassnames($els, darkMode);
8701
+ }
8689
8702
  };
8690
- ctx.on("inited", () => sync());
8691
- ctx.on("conf-loaded", () => sync());
8692
- ctx.on("dark-mode-changed", () => sync());
8703
+ ctx.on("inited", () => sync(ctx.conf.darkMode));
8704
+ ctx.on("conf-loaded", (conf) => sync(conf.darkMode));
8705
+ ctx.on("dark-mode-changed", (darkMode) => sync(darkMode));
8706
+ ctx.on("destroy", () => {
8707
+ darkModeAutoHandler && (darkModeMedia == null ? void 0 : darkModeMedia.removeEventListener("change", darkModeAutoHandler));
8708
+ darkModeAutoHandler = void 0;
8709
+ });
8693
8710
  };
8694
8711
  const DefaultPlugins = [
8695
8712
  ConfRemoter,
@@ -8704,15 +8721,11 @@ const DefaultPlugins = [
8704
8721
  const GlobalPlugins = [...DefaultPlugins];
8705
8722
  class Artalk {
8706
8723
  constructor(conf) {
8707
- __publicField(this, "conf");
8708
8724
  __publicField(this, "ctx");
8709
- __publicField(this, "$root");
8710
8725
  /** Plugins */
8711
8726
  __publicField(this, "plugins", [...GlobalPlugins]);
8712
- this.conf = handelCustomConf(conf);
8713
- if (this.conf.el instanceof HTMLElement)
8714
- this.$root = this.conf.el;
8715
- this.ctx = new Context(this.conf, this.$root);
8727
+ const handledConf = handelCustomConf(conf, true);
8728
+ this.ctx = new Context(handledConf);
8716
8729
  Object.entries(services).forEach(([name, initService]) => {
8717
8730
  const obj = initService(this.ctx);
8718
8731
  if (obj)
@@ -8724,6 +8737,14 @@ class Artalk {
8724
8737
  });
8725
8738
  this.ctx.trigger("inited");
8726
8739
  }
8740
+ /** Get the config of Artalk */
8741
+ getConf() {
8742
+ return this.ctx.getConf();
8743
+ }
8744
+ /** Get the root element of Artalk */
8745
+ getEl() {
8746
+ return this.ctx.$root;
8747
+ }
8727
8748
  /** Update config of Artalk */
8728
8749
  update(conf) {
8729
8750
  this.ctx.updateConf(conf);
@@ -8736,7 +8757,7 @@ class Artalk {
8736
8757
  /** Destroy instance of Artalk */
8737
8758
  destroy() {
8738
8759
  this.ctx.trigger("destroy");
8739
- this.$root.remove();
8760
+ this.ctx.$root.remove();
8740
8761
  }
8741
8762
  /** Add an event listener */
8742
8763
  on(name, handler) {
@@ -8769,7 +8790,7 @@ class Artalk {
8769
8790
  }
8770
8791
  /** Load count widget */
8771
8792
  static loadCountWidget(c) {
8772
- const conf = handelCustomConf(c);
8793
+ const conf = handelCustomConf(c, true);
8773
8794
  initCountWidget({
8774
8795
  getApi: () => new Api(convertApiOptions(conf)),
8775
8796
  pageKey: conf.pageKey,
@@ -8778,18 +8799,25 @@ class Artalk {
8778
8799
  pvAdd: false
8779
8800
  });
8780
8801
  }
8802
+ // ===========================
8803
+ // Deprecated
8804
+ // ===========================
8805
+ /** @deprecated Please use `getEl()` instead */
8806
+ get $root() {
8807
+ return this.ctx.$root;
8808
+ }
8809
+ /** @description Please use `getConf()` instead */
8810
+ get conf() {
8811
+ return this.ctx.getConf();
8812
+ }
8781
8813
  }
8782
- const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
8783
- __proto__: null
8784
- }, Symbol.toStringTag, { value: "Module" }));
8785
8814
  const init = Artalk.init;
8786
8815
  const use = Artalk.use;
8787
8816
  const loadCountWidget = Artalk.loadCountWidget;
8788
8817
  export {
8789
- index as ArtalkType,
8790
8818
  Artalk as default,
8791
8819
  init,
8792
8820
  loadCountWidget,
8793
8821
  use
8794
8822
  };
8795
- //# sourceMappingURL=Artalk.es.js.map
8823
+ //# sourceMappingURL=Artalk.mjs.map