artalk 2.8.6 → 2.9.0

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 (44) hide show
  1. package/dist/Artalk.cjs +2 -2
  2. package/dist/Artalk.cjs.map +1 -1
  3. package/dist/Artalk.css +1 -1
  4. package/dist/Artalk.iife.js +2 -2
  5. package/dist/Artalk.iife.js.map +1 -1
  6. package/dist/Artalk.js +2 -2
  7. package/dist/Artalk.js.map +1 -1
  8. package/dist/Artalk.mjs +953 -1421
  9. package/dist/Artalk.mjs.map +1 -1
  10. package/dist/ArtalkLite.cjs +2 -2
  11. package/dist/ArtalkLite.cjs.map +1 -1
  12. package/dist/ArtalkLite.css +1 -1
  13. package/dist/ArtalkLite.iife.js +2 -2
  14. package/dist/ArtalkLite.iife.js.map +1 -1
  15. package/dist/ArtalkLite.js +2 -2
  16. package/dist/ArtalkLite.js.map +1 -1
  17. package/dist/ArtalkLite.mjs +641 -1148
  18. package/dist/ArtalkLite.mjs.map +1 -1
  19. package/dist/i18n/fr.cjs +1 -0
  20. package/dist/i18n/fr.js +1 -0
  21. package/dist/i18n/fr.mjs +123 -0
  22. package/dist/i18n/{jp.cjs → ja.cjs} +1 -1
  23. package/dist/i18n/ja.d.cts +3 -0
  24. package/dist/i18n/ja.d.ts +3 -0
  25. package/dist/i18n/{jp.js → ja.js} +1 -1
  26. package/dist/i18n/{jp.mjs → ja.mjs} +12 -9
  27. package/dist/i18n/ko.cjs +1 -0
  28. package/dist/i18n/ko.d.cts +3 -0
  29. package/dist/i18n/ko.d.ts +3 -0
  30. package/dist/i18n/ko.js +1 -0
  31. package/dist/i18n/ko.mjs +123 -0
  32. package/dist/i18n/ru.cjs +1 -0
  33. package/dist/i18n/ru.d.cts +3 -0
  34. package/dist/i18n/ru.d.ts +3 -0
  35. package/dist/i18n/ru.js +1 -0
  36. package/dist/i18n/ru.mjs +123 -0
  37. package/dist/i18n/zh-TW.cjs +1 -1
  38. package/dist/i18n/zh-TW.js +1 -1
  39. package/dist/i18n/zh-TW.mjs +6 -3
  40. package/dist/main.d.cts +157 -94
  41. package/dist/main.d.ts +157 -94
  42. package/package.json +56 -24
  43. /package/dist/i18n/{jp.d.cts → fr.d.cts} +0 -0
  44. /package/dist/i18n/{jp.d.ts → fr.d.ts} +0 -0
@@ -29,10 +29,7 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
- var __publicField = (obj, key, value) => {
33
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
34
- return value;
35
- };
32
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
36
33
  var __async = (__this, __arguments, generator) => {
37
34
  return new Promise((resolve, reject) => {
38
35
  var fulfilled = (value) => {
@@ -53,7 +50,7 @@ var __async = (__this, __arguments, generator) => {
53
50
  step((generator = generator.apply(__this, __arguments)).next());
54
51
  });
55
52
  };
56
- import { marked as marked$1 } from "marked";
53
+ import { marked as marked$1, Marked } from "marked";
57
54
  class HttpClient {
58
55
  constructor(apiConfig = {}) {
59
56
  __publicField(this, "baseUrl", "/api/v2");
@@ -150,7 +147,7 @@ class HttpClient {
150
147
  body: typeof body === "undefined" || body === null ? null : payloadFormatter(body)
151
148
  })
152
149
  ).then((response) => __async(this, null, function* () {
153
- const r = response;
150
+ const r = response.clone();
154
151
  r.data = null;
155
152
  r.error = null;
156
153
  const data = !responseFormat ? r : yield response[responseFormat]().then((data2) => {
@@ -167,8 +164,7 @@ class HttpClient {
167
164
  if (cancelToken) {
168
165
  this.abortControllers.delete(cancelToken);
169
166
  }
170
- if (!response.ok)
171
- throw data;
167
+ if (!response.ok) throw data;
172
168
  return data;
173
169
  }));
174
170
  }));
@@ -240,7 +236,7 @@ let Api$1 = class Api extends HttpClient {
240
236
  format: "json"
241
237
  }, params)),
242
238
  /**
243
- * @description Register by email and verify code (if user exists, will update user, like forget password. Need send email verify code first)
239
+ * @description Register by email and verify code (if user exists, will update user, like forget or change password. Need send email verify code first)
244
240
  *
245
241
  * @tags Auth
246
242
  * @name RegisterByEmail
@@ -1219,6 +1215,32 @@ let Api$1 = class Api extends HttpClient {
1219
1215
  secure: true,
1220
1216
  format: "json"
1221
1217
  }, params)),
1218
+ /**
1219
+ * @description Update user profile when user is logged in
1220
+ *
1221
+ * @tags Auth
1222
+ * @name UpdateProfile
1223
+ * @summary Update user profile
1224
+ * @request POST:/user
1225
+ * @secure
1226
+ * @response `200` `HandlerResponseUserInfoUpdate` OK
1227
+ * @response `400` `(HandlerMap & {
1228
+ msg?: string,
1229
+
1230
+ })` Bad Request
1231
+ * @response `500` `(HandlerMap & {
1232
+ msg?: string,
1233
+
1234
+ })` Internal Server Error
1235
+ */
1236
+ updateProfile: (data, params = {}) => this.request(__spreadValues({
1237
+ path: `/user`,
1238
+ method: "POST",
1239
+ body: data,
1240
+ secure: true,
1241
+ type: "application/json",
1242
+ format: "json"
1243
+ }, params)),
1222
1244
  /**
1223
1245
  * @description Login user by name or email
1224
1246
  *
@@ -1453,411 +1475,12 @@ let Api$1 = class Api extends HttpClient {
1453
1475
  });
1454
1476
  }
1455
1477
  };
1456
- var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
1457
- function getDefaultExportFromCjs(x) {
1458
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
1459
- }
1460
- (function(factory) {
1461
- factory();
1462
- })(function() {
1463
- function _classCallCheck(instance2, Constructor) {
1464
- if (!(instance2 instanceof Constructor)) {
1465
- throw new TypeError("Cannot call a class as a function");
1466
- }
1467
- }
1468
- function _defineProperties(target, props) {
1469
- for (var i = 0; i < props.length; i++) {
1470
- var descriptor = props[i];
1471
- descriptor.enumerable = descriptor.enumerable || false;
1472
- descriptor.configurable = true;
1473
- if ("value" in descriptor)
1474
- descriptor.writable = true;
1475
- Object.defineProperty(target, descriptor.key, descriptor);
1476
- }
1477
- }
1478
- function _createClass(Constructor, protoProps, staticProps) {
1479
- if (protoProps)
1480
- _defineProperties(Constructor.prototype, protoProps);
1481
- Object.defineProperty(Constructor, "prototype", {
1482
- writable: false
1483
- });
1484
- return Constructor;
1485
- }
1486
- function _inherits(subClass, superClass) {
1487
- if (typeof superClass !== "function" && superClass !== null) {
1488
- throw new TypeError("Super expression must either be null or a function");
1489
- }
1490
- subClass.prototype = Object.create(superClass && superClass.prototype, {
1491
- constructor: {
1492
- value: subClass,
1493
- writable: true,
1494
- configurable: true
1495
- }
1496
- });
1497
- Object.defineProperty(subClass, "prototype", {
1498
- writable: false
1499
- });
1500
- if (superClass)
1501
- _setPrototypeOf(subClass, superClass);
1502
- }
1503
- function _getPrototypeOf(o) {
1504
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf2(o2) {
1505
- return o2.__proto__ || Object.getPrototypeOf(o2);
1506
- };
1507
- return _getPrototypeOf(o);
1508
- }
1509
- function _setPrototypeOf(o, p) {
1510
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf2(o2, p2) {
1511
- o2.__proto__ = p2;
1512
- return o2;
1513
- };
1514
- return _setPrototypeOf(o, p);
1515
- }
1516
- function _isNativeReflectConstruct() {
1517
- if (typeof Reflect === "undefined" || !Reflect.construct)
1518
- return false;
1519
- if (Reflect.construct.sham)
1520
- return false;
1521
- if (typeof Proxy === "function")
1522
- return true;
1523
- try {
1524
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
1525
- }));
1526
- return true;
1527
- } catch (e) {
1528
- return false;
1529
- }
1530
- }
1531
- function _assertThisInitialized(self2) {
1532
- if (self2 === void 0) {
1533
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
1534
- }
1535
- return self2;
1536
- }
1537
- function _possibleConstructorReturn(self2, call) {
1538
- if (call && (typeof call === "object" || typeof call === "function")) {
1539
- return call;
1540
- } else if (call !== void 0) {
1541
- throw new TypeError("Derived constructors may only return object or undefined");
1542
- }
1543
- return _assertThisInitialized(self2);
1544
- }
1545
- function _createSuper(Derived) {
1546
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
1547
- return function _createSuperInternal() {
1548
- var Super = _getPrototypeOf(Derived), result;
1549
- if (hasNativeReflectConstruct) {
1550
- var NewTarget = _getPrototypeOf(this).constructor;
1551
- result = Reflect.construct(Super, arguments, NewTarget);
1552
- } else {
1553
- result = Super.apply(this, arguments);
1554
- }
1555
- return _possibleConstructorReturn(this, result);
1556
- };
1557
- }
1558
- function _superPropBase(object, property) {
1559
- while (!Object.prototype.hasOwnProperty.call(object, property)) {
1560
- object = _getPrototypeOf(object);
1561
- if (object === null)
1562
- break;
1563
- }
1564
- return object;
1565
- }
1566
- function _get() {
1567
- if (typeof Reflect !== "undefined" && Reflect.get) {
1568
- _get = Reflect.get.bind();
1569
- } else {
1570
- _get = function _get2(target, property, receiver) {
1571
- var base = _superPropBase(target, property);
1572
- if (!base)
1573
- return;
1574
- var desc = Object.getOwnPropertyDescriptor(base, property);
1575
- if (desc.get) {
1576
- return desc.get.call(arguments.length < 3 ? target : receiver);
1577
- }
1578
- return desc.value;
1579
- };
1580
- }
1581
- return _get.apply(this, arguments);
1582
- }
1583
- var Emitter = /* @__PURE__ */ function() {
1584
- function Emitter2() {
1585
- _classCallCheck(this, Emitter2);
1586
- Object.defineProperty(this, "listeners", {
1587
- value: {},
1588
- writable: true,
1589
- configurable: true
1590
- });
1591
- }
1592
- _createClass(Emitter2, [{
1593
- key: "addEventListener",
1594
- value: function addEventListener(type, callback, options) {
1595
- if (!(type in this.listeners)) {
1596
- this.listeners[type] = [];
1597
- }
1598
- this.listeners[type].push({
1599
- callback,
1600
- options
1601
- });
1602
- }
1603
- }, {
1604
- key: "removeEventListener",
1605
- value: function removeEventListener(type, callback) {
1606
- if (!(type in this.listeners)) {
1607
- return;
1608
- }
1609
- var stack = this.listeners[type];
1610
- for (var i = 0, l = stack.length; i < l; i++) {
1611
- if (stack[i].callback === callback) {
1612
- stack.splice(i, 1);
1613
- return;
1614
- }
1615
- }
1616
- }
1617
- }, {
1618
- key: "dispatchEvent",
1619
- value: function dispatchEvent(event) {
1620
- if (!(event.type in this.listeners)) {
1621
- return;
1622
- }
1623
- var stack = this.listeners[event.type];
1624
- var stackToCall = stack.slice();
1625
- for (var i = 0, l = stackToCall.length; i < l; i++) {
1626
- var listener = stackToCall[i];
1627
- try {
1628
- listener.callback.call(this, event);
1629
- } catch (e) {
1630
- Promise.resolve().then(function() {
1631
- throw e;
1632
- });
1633
- }
1634
- if (listener.options && listener.options.once) {
1635
- this.removeEventListener(event.type, listener.callback);
1636
- }
1637
- }
1638
- return !event.defaultPrevented;
1639
- }
1640
- }]);
1641
- return Emitter2;
1642
- }();
1643
- var AbortSignal = /* @__PURE__ */ function(_Emitter) {
1644
- _inherits(AbortSignal2, _Emitter);
1645
- var _super = _createSuper(AbortSignal2);
1646
- function AbortSignal2() {
1647
- var _this;
1648
- _classCallCheck(this, AbortSignal2);
1649
- _this = _super.call(this);
1650
- if (!_this.listeners) {
1651
- Emitter.call(_assertThisInitialized(_this));
1652
- }
1653
- Object.defineProperty(_assertThisInitialized(_this), "aborted", {
1654
- value: false,
1655
- writable: true,
1656
- configurable: true
1657
- });
1658
- Object.defineProperty(_assertThisInitialized(_this), "onabort", {
1659
- value: null,
1660
- writable: true,
1661
- configurable: true
1662
- });
1663
- Object.defineProperty(_assertThisInitialized(_this), "reason", {
1664
- value: void 0,
1665
- writable: true,
1666
- configurable: true
1667
- });
1668
- return _this;
1669
- }
1670
- _createClass(AbortSignal2, [{
1671
- key: "toString",
1672
- value: function toString() {
1673
- return "[object AbortSignal]";
1674
- }
1675
- }, {
1676
- key: "dispatchEvent",
1677
- value: function dispatchEvent(event) {
1678
- if (event.type === "abort") {
1679
- this.aborted = true;
1680
- if (typeof this.onabort === "function") {
1681
- this.onabort.call(this, event);
1682
- }
1683
- }
1684
- _get(_getPrototypeOf(AbortSignal2.prototype), "dispatchEvent", this).call(this, event);
1685
- }
1686
- }]);
1687
- return AbortSignal2;
1688
- }(Emitter);
1689
- var AbortController2 = /* @__PURE__ */ function() {
1690
- function AbortController3() {
1691
- _classCallCheck(this, AbortController3);
1692
- Object.defineProperty(this, "signal", {
1693
- value: new AbortSignal(),
1694
- writable: true,
1695
- configurable: true
1696
- });
1697
- }
1698
- _createClass(AbortController3, [{
1699
- key: "abort",
1700
- value: function abort(reason) {
1701
- var event;
1702
- try {
1703
- event = new Event("abort");
1704
- } catch (e) {
1705
- if (typeof document !== "undefined") {
1706
- if (!document.createEvent) {
1707
- event = document.createEventObject();
1708
- event.type = "abort";
1709
- } else {
1710
- event = document.createEvent("Event");
1711
- event.initEvent("abort", false, false);
1712
- }
1713
- } else {
1714
- event = {
1715
- type: "abort",
1716
- bubbles: false,
1717
- cancelable: false
1718
- };
1719
- }
1720
- }
1721
- var signalReason = reason;
1722
- if (signalReason === void 0) {
1723
- if (typeof document === "undefined") {
1724
- signalReason = new Error("This operation was aborted");
1725
- signalReason.name = "AbortError";
1726
- } else {
1727
- try {
1728
- signalReason = new DOMException("signal is aborted without reason");
1729
- } catch (err) {
1730
- signalReason = new Error("This operation was aborted");
1731
- signalReason.name = "AbortError";
1732
- }
1733
- }
1734
- }
1735
- this.signal.reason = signalReason;
1736
- this.signal.dispatchEvent(event);
1737
- }
1738
- }, {
1739
- key: "toString",
1740
- value: function toString() {
1741
- return "[object AbortController]";
1742
- }
1743
- }]);
1744
- return AbortController3;
1745
- }();
1746
- if (typeof Symbol !== "undefined" && Symbol.toStringTag) {
1747
- AbortController2.prototype[Symbol.toStringTag] = "AbortController";
1748
- AbortSignal.prototype[Symbol.toStringTag] = "AbortSignal";
1749
- }
1750
- function polyfillNeeded(self2) {
1751
- if (self2.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) {
1752
- console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill");
1753
- return true;
1754
- }
1755
- return typeof self2.Request === "function" && !self2.Request.prototype.hasOwnProperty("signal") || !self2.AbortController;
1756
- }
1757
- function abortableFetchDecorator(patchTargets) {
1758
- if ("function" === typeof patchTargets) {
1759
- patchTargets = {
1760
- fetch: patchTargets
1761
- };
1762
- }
1763
- var _patchTargets = patchTargets, fetch2 = _patchTargets.fetch, _patchTargets$Request = _patchTargets.Request, NativeRequest = _patchTargets$Request === void 0 ? fetch2.Request : _patchTargets$Request, NativeAbortController = _patchTargets.AbortController, _patchTargets$__FORCE = _patchTargets.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL, __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = _patchTargets$__FORCE === void 0 ? false : _patchTargets$__FORCE;
1764
- if (!polyfillNeeded({
1765
- fetch: fetch2,
1766
- Request: NativeRequest,
1767
- AbortController: NativeAbortController,
1768
- __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL
1769
- })) {
1770
- return {
1771
- fetch: fetch2,
1772
- Request
1773
- };
1774
- }
1775
- var Request = NativeRequest;
1776
- if (Request && !Request.prototype.hasOwnProperty("signal") || __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) {
1777
- Request = function Request2(input, init2) {
1778
- var signal;
1779
- if (init2 && init2.signal) {
1780
- signal = init2.signal;
1781
- delete init2.signal;
1782
- }
1783
- var request = new NativeRequest(input, init2);
1784
- if (signal) {
1785
- Object.defineProperty(request, "signal", {
1786
- writable: false,
1787
- enumerable: false,
1788
- configurable: true,
1789
- value: signal
1790
- });
1791
- }
1792
- return request;
1793
- };
1794
- Request.prototype = NativeRequest.prototype;
1795
- }
1796
- var realFetch = fetch2;
1797
- var abortableFetch = function abortableFetch2(input, init2) {
1798
- var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init2 ? init2.signal : void 0;
1799
- if (signal) {
1800
- var abortError;
1801
- try {
1802
- abortError = new DOMException("Aborted", "AbortError");
1803
- } catch (err) {
1804
- abortError = new Error("Aborted");
1805
- abortError.name = "AbortError";
1806
- }
1807
- if (signal.aborted) {
1808
- return Promise.reject(abortError);
1809
- }
1810
- var cancellation = new Promise(function(_, reject) {
1811
- signal.addEventListener("abort", function() {
1812
- return reject(abortError);
1813
- }, {
1814
- once: true
1815
- });
1816
- });
1817
- if (init2 && init2.signal) {
1818
- delete init2.signal;
1819
- }
1820
- return Promise.race([cancellation, realFetch(input, init2)]);
1821
- }
1822
- return realFetch(input, init2);
1823
- };
1824
- return {
1825
- fetch: abortableFetch,
1826
- Request
1827
- };
1828
- }
1829
- (function(self2) {
1830
- if (!polyfillNeeded(self2)) {
1831
- return;
1832
- }
1833
- if (!self2.fetch) {
1834
- console.warn("fetch() is not available, cannot install abortcontroller-polyfill");
1835
- return;
1836
- }
1837
- var _abortableFetch = abortableFetchDecorator(self2), fetch2 = _abortableFetch.fetch, Request = _abortableFetch.Request;
1838
- self2.fetch = fetch2;
1839
- self2.Request = Request;
1840
- Object.defineProperty(self2, "AbortController", {
1841
- writable: true,
1842
- enumerable: false,
1843
- configurable: true,
1844
- value: AbortController2
1845
- });
1846
- Object.defineProperty(self2, "AbortSignal", {
1847
- writable: true,
1848
- enumerable: false,
1849
- configurable: true,
1850
- value: AbortSignal
1851
- });
1852
- })(typeof self !== "undefined" ? self : commonjsGlobal);
1853
- });
1854
1478
  const Fetch$1 = (opts, input, init2) => __async(void 0, null, function* () {
1855
1479
  const apiToken = opts.getApiToken && opts.getApiToken();
1856
1480
  const headers = new Headers(__spreadValues({
1857
1481
  Authorization: apiToken ? `Bearer ${apiToken}` : ""
1858
1482
  }, init2 == null ? void 0 : init2.headers));
1859
- if (!headers.get("Authorization"))
1860
- headers.delete("Authorization");
1483
+ if (!headers.get("Authorization")) headers.delete("Authorization");
1861
1484
  const resp = yield fetch(input, __spreadProps(__spreadValues({}, init2), {
1862
1485
  headers
1863
1486
  }));
@@ -1872,8 +1495,7 @@ const Fetch$1 = (opts, input, init2) => __async(void 0, null, function* () {
1872
1495
  retry = true;
1873
1496
  }
1874
1497
  }), Promise.resolve()));
1875
- if (retry)
1876
- return Fetch$1(opts, input, init2);
1498
+ if (retry) return Fetch$1(opts, input, init2);
1877
1499
  throw createError(resp.status, json);
1878
1500
  }
1879
1501
  return resp;
@@ -1900,6 +1522,10 @@ function createApiHandlers() {
1900
1522
  add: (action, handler) => {
1901
1523
  handlers.push({ action, handler });
1902
1524
  },
1525
+ remove: (action) => {
1526
+ const index = handlers.findIndex((h) => h.action === action);
1527
+ if (index !== -1) handlers.splice(index, 1);
1528
+ },
1903
1529
  get: () => handlers
1904
1530
  };
1905
1531
  }
@@ -1919,11 +1545,14 @@ class Api2 extends Api$1 {
1919
1545
  */
1920
1546
  getUserFields() {
1921
1547
  const user = this._opts.userInfo;
1922
- if (!(user == null ? void 0 : user.name) || !(user == null ? void 0 : user.email))
1923
- return void 0;
1548
+ if (!(user == null ? void 0 : user.name) || !(user == null ? void 0 : user.email)) return void 0;
1924
1549
  return { name: user.name, email: user.email };
1925
1550
  }
1926
1551
  }
1552
+ var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
1553
+ function getDefaultExportFromCjs(x) {
1554
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
1555
+ }
1927
1556
  var escapes = {
1928
1557
  "&": "&amp;",
1929
1558
  "<": "&lt;",
@@ -2422,11 +2051,9 @@ var hanabi$1 = { exports: {} };
2422
2051
  });
2423
2052
  var defaultColors = ["23AC69", "91C132", "F19726", "E8552D", "1AAB8E", "E1147F", "2980C1", "1BA1E6", "9FA0A0", "F19726", "E30B20", "E30B20", "A3338B"];
2424
2053
  var index = function(input, ref) {
2425
- if (ref === void 0)
2426
- ref = {};
2054
+ if (ref === void 0) ref = {};
2427
2055
  var colors = ref.colors;
2428
- if (colors === void 0)
2429
- colors = defaultColors;
2056
+ if (colors === void 0) colors = defaultColors;
2430
2057
  var index2 = 0;
2431
2058
  var cache = {};
2432
2059
  var wordRe = /[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af\u0400-\u04FF]+|\w+/;
@@ -2469,7 +2096,7 @@ function getRenderer(options) {
2469
2096
  renderer.image = markedImageRenderer(renderer, renderer.image, options);
2470
2097
  return renderer;
2471
2098
  }
2472
- const markedLinkRenderer = (renderer, orgLinkRenderer) => (href, title, text) => {
2099
+ const markedLinkRenderer = (renderer, orgLinkRenderer) => (args) => {
2473
2100
  const getLinkOrigin = (link) => {
2474
2101
  try {
2475
2102
  return new URL(link).origin;
@@ -2477,31 +2104,30 @@ const markedLinkRenderer = (renderer, orgLinkRenderer) => (href, title, text) =>
2477
2104
  return "";
2478
2105
  }
2479
2106
  };
2480
- const isSameOriginLink = getLinkOrigin(href) === window.location.origin;
2481
- const html = orgLinkRenderer.call(renderer, href, title, text);
2107
+ const isSameOriginLink = getLinkOrigin(args.href) === window.location.origin;
2108
+ const html = orgLinkRenderer.call(renderer, args);
2482
2109
  return html.replace(
2483
2110
  /^<a /,
2484
2111
  `<a target="_blank" ${!isSameOriginLink ? `rel="noreferrer noopener nofollow"` : ""} `
2485
2112
  );
2486
2113
  };
2487
- const markedCodeRenderer = () => (block, lang) => {
2114
+ const markedCodeRenderer = () => ({ lang, text }) => {
2488
2115
  const realLang = !lang ? "plaintext" : lang;
2489
- let colorized = block;
2116
+ let colorized = text;
2490
2117
  if (window.hljs) {
2491
2118
  if (realLang && window.hljs.getLanguage(realLang)) {
2492
- colorized = window.hljs.highlight(realLang, block).value;
2119
+ colorized = window.hljs.highlight(realLang, text).value;
2493
2120
  }
2494
2121
  } else {
2495
- colorized = renderCode(block);
2122
+ colorized = renderCode(text);
2496
2123
  }
2497
2124
  return `<pre rel="${realLang}">
2498
2125
  <code class="hljs language-${realLang}">${colorized.replace(/&amp;/g, "&")}</code>
2499
2126
  </pre>`;
2500
2127
  };
2501
- const markedImageRenderer = (renderer, orgImageRenderer, { imgLazyLoad }) => (href, title, text) => {
2502
- const html = orgImageRenderer.call(renderer, href, title, text);
2503
- if (!imgLazyLoad)
2504
- return html;
2128
+ const markedImageRenderer = (renderer, orgImageRenderer, { imgLazyLoad }) => (args) => {
2129
+ const html = orgImageRenderer.call(renderer, args);
2130
+ if (!imgLazyLoad) return html;
2505
2131
  if (imgLazyLoad === "native" || imgLazyLoad === true)
2506
2132
  return html.replace(/^<img /, '<img class="lazyload" loading="lazy" ');
2507
2133
  if (imgLazyLoad === "data-src")
@@ -2523,17 +2149,17 @@ function setReplacers(arr) {
2523
2149
  }
2524
2150
  function initMarked(options) {
2525
2151
  try {
2526
- if (!marked$1.name)
2527
- return;
2152
+ if (!Marked.name) return;
2528
2153
  } catch (e) {
2529
2154
  return;
2530
2155
  }
2531
- marked$1.setOptions(__spreadValues(__spreadValues({
2156
+ const marked2 = new Marked();
2157
+ marked2.setOptions(__spreadValues(__spreadValues({
2532
2158
  renderer: getRenderer({
2533
2159
  imgLazyLoad: options.imgLazyLoad
2534
2160
  })
2535
2161
  }, markedOptions), options.markedOptions));
2536
- instance = marked$1;
2162
+ instance = marked2;
2537
2163
  }
2538
2164
  function marked(src) {
2539
2165
  var _a;
@@ -2543,8 +2169,7 @@ function marked(src) {
2543
2169
  }
2544
2170
  let dest = sanitize(markedContent);
2545
2171
  replacers.forEach((replacer) => {
2546
- if (typeof replacer === "function")
2547
- dest = replacer(dest);
2172
+ if (typeof replacer === "function") dest = replacer(dest);
2548
2173
  });
2549
2174
  return dest;
2550
2175
  }
@@ -2627,8 +2252,7 @@ class DataManager {
2627
2252
  }
2628
2253
  updateComment(comment) {
2629
2254
  this.comments = this.comments.map((c) => {
2630
- if (c.id === comment.id)
2631
- return comment;
2255
+ if (c.id === comment.id) return comment;
2632
2256
  return c;
2633
2257
  });
2634
2258
  this.events.trigger("comment-updated", comment);
@@ -2636,8 +2260,7 @@ class DataManager {
2636
2260
  }
2637
2261
  deleteComment(id) {
2638
2262
  const comment = this.comments.find((c) => c.id === id);
2639
- if (!comment)
2640
- throw new Error(`Comment ${id} not found`);
2263
+ if (!comment) throw new Error(`Comment ${id} not found`);
2641
2264
  this.comments = this.comments.filter((c) => c.id !== id);
2642
2265
  this.events.trigger("comment-deleted", comment);
2643
2266
  this.events.trigger("list-loaded", this.comments);
@@ -2663,6 +2286,150 @@ class DataManager {
2663
2286
  this.events.trigger("page-loaded", pageData);
2664
2287
  }
2665
2288
  }
2289
+ function createElement(htmlStr = "") {
2290
+ const div = document.createElement("div");
2291
+ div.innerHTML = htmlStr.trim();
2292
+ return div.firstElementChild || div;
2293
+ }
2294
+ function getHeight(el) {
2295
+ const num = parseFloat(getComputedStyle(el, null).height.replace("px", ""));
2296
+ return num || 0;
2297
+ }
2298
+ function htmlEncode(str) {
2299
+ const temp = document.createElement("div");
2300
+ temp.innerText = str;
2301
+ const output = temp.innerHTML;
2302
+ return output;
2303
+ }
2304
+ function getQueryParam(name) {
2305
+ const match = RegExp(`[?&]${name}=([^&]*)`).exec(window.location.search);
2306
+ return match && decodeURIComponent(match[1].replace(/\+/g, " "));
2307
+ }
2308
+ function getOffset(el, relativeTo) {
2309
+ const getOffsetRecursive = (element) => {
2310
+ const rect = element.getBoundingClientRect();
2311
+ const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
2312
+ const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
2313
+ return {
2314
+ top: rect.top + scrollTop,
2315
+ left: rect.left + scrollLeft
2316
+ };
2317
+ };
2318
+ const elOffset = getOffsetRecursive(el);
2319
+ if (!relativeTo) return elOffset;
2320
+ const relativeToOffset = getOffsetRecursive(relativeTo);
2321
+ return {
2322
+ top: elOffset.top - relativeToOffset.top,
2323
+ left: elOffset.left - relativeToOffset.left
2324
+ };
2325
+ }
2326
+ function padWithZeros(vNumber, width) {
2327
+ let numAsString = vNumber.toString();
2328
+ while (numAsString.length < width) {
2329
+ numAsString = `0${numAsString}`;
2330
+ }
2331
+ return numAsString;
2332
+ }
2333
+ function dateFormat(date) {
2334
+ const vDay = padWithZeros(date.getDate(), 2);
2335
+ const vMonth = padWithZeros(date.getMonth() + 1, 2);
2336
+ const vYear = padWithZeros(date.getFullYear(), 2);
2337
+ return `${vYear}-${vMonth}-${vDay}`;
2338
+ }
2339
+ function timeAgo(date, $t = (n) => n) {
2340
+ try {
2341
+ const oldTime = date.getTime();
2342
+ const currTime = (/* @__PURE__ */ new Date()).getTime();
2343
+ const diffValue = currTime - oldTime;
2344
+ const days = Math.floor(diffValue / (24 * 3600 * 1e3));
2345
+ if (days === 0) {
2346
+ const leave1 = diffValue % (24 * 3600 * 1e3);
2347
+ const hours = Math.floor(leave1 / (3600 * 1e3));
2348
+ if (hours === 0) {
2349
+ const leave2 = leave1 % (3600 * 1e3);
2350
+ const minutes = Math.floor(leave2 / (60 * 1e3));
2351
+ if (minutes === 0) {
2352
+ const leave3 = leave2 % (60 * 1e3);
2353
+ const seconds = Math.round(leave3 / 1e3);
2354
+ if (seconds < 10) return $t("now");
2355
+ return `${seconds} ${$t("seconds")}`;
2356
+ }
2357
+ return `${minutes} ${$t("minutes")}`;
2358
+ }
2359
+ return `${hours} ${$t("hours")}`;
2360
+ }
2361
+ if (days < 0) return $t("now");
2362
+ if (days < 8) {
2363
+ return `${days} ${$t("days")}`;
2364
+ }
2365
+ return dateFormat(date);
2366
+ } catch (error) {
2367
+ console.error(error);
2368
+ return " - ";
2369
+ }
2370
+ }
2371
+ function getGravatarURL(opts) {
2372
+ return `${opts.mirror.replace(/\/$/, "")}/${opts.emailHash}?${opts.params.replace(/^\?/, "")}`;
2373
+ }
2374
+ function versionCompare(a, b) {
2375
+ const pa = a.split(".");
2376
+ const pb = b.split(".");
2377
+ for (let i = 0; i < 3; i++) {
2378
+ const na = Number(pa[i]);
2379
+ const nb = Number(pb[i]);
2380
+ if (na > nb) return 1;
2381
+ if (nb > na) return -1;
2382
+ if (!Number.isNaN(na) && Number.isNaN(nb)) return 1;
2383
+ if (Number.isNaN(na) && !Number.isNaN(nb)) return -1;
2384
+ }
2385
+ return 0;
2386
+ }
2387
+ function getCorrectUserAgent() {
2388
+ return __async(this, null, function* () {
2389
+ const uaRaw = navigator.userAgent;
2390
+ if (!navigator.userAgentData || !navigator.userAgentData.getHighEntropyValues) {
2391
+ return uaRaw;
2392
+ }
2393
+ const uaData = navigator.userAgentData;
2394
+ let uaGot = null;
2395
+ try {
2396
+ uaGot = yield uaData.getHighEntropyValues(["platformVersion"]);
2397
+ } catch (err) {
2398
+ console.error(err);
2399
+ return uaRaw;
2400
+ }
2401
+ const majorPlatformVersion = Number(uaGot.platformVersion.split(".")[0]);
2402
+ if (uaData.platform === "Windows") {
2403
+ if (majorPlatformVersion >= 13) {
2404
+ return uaRaw.replace(/Windows NT 10.0/, "Windows NT 11.0");
2405
+ }
2406
+ }
2407
+ if (uaData.platform === "macOS") {
2408
+ if (majorPlatformVersion >= 11) {
2409
+ return uaRaw.replace(
2410
+ /(Mac OS X \d+_\d+_\d+|Mac OS X)/,
2411
+ `Mac OS X ${uaGot.platformVersion.replace(/\./g, "_")}`
2412
+ );
2413
+ }
2414
+ }
2415
+ return uaRaw;
2416
+ });
2417
+ }
2418
+ function isValidURL(urlRaw) {
2419
+ let url;
2420
+ try {
2421
+ url = new URL(urlRaw);
2422
+ } catch (_) {
2423
+ return false;
2424
+ }
2425
+ return url.protocol === "http:" || url.protocol === "https:";
2426
+ }
2427
+ function getURLBasedOnApi(opts) {
2428
+ return getURLBasedOn(opts.base, opts.path);
2429
+ }
2430
+ function getURLBasedOn(baseURL, path) {
2431
+ return `${baseURL.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
2432
+ }
2666
2433
  const en = {
2667
2434
  /* Editor */
2668
2435
  placeholder: "Leave a comment",
@@ -2727,21 +2494,25 @@ const en = {
2727
2494
  cancel: "Cancel",
2728
2495
  /* Sidebar */
2729
2496
  msgCenter: "Messages",
2730
- ctrlCenter: "Admin",
2497
+ ctrlCenter: "Dashboard",
2731
2498
  /* Auth */
2499
+ userProfile: "Profile",
2732
2500
  noAccountPrompt: "Don't have an account?",
2733
2501
  haveAccountPrompt: "Already have an account?",
2734
2502
  forgetPassword: "Forget Password",
2735
2503
  resetPassword: "Reset Password",
2504
+ changePassword: "Change Password",
2505
+ confirmPassword: "Confirm Password",
2506
+ passwordMismatch: "Passwords do not match",
2736
2507
  verificationCode: "Verification Code",
2737
- verifySend: "Verify",
2508
+ verifySend: "Send Code",
2738
2509
  verifyResend: "Resend",
2739
2510
  waitSeconds: "Wait {seconds}s",
2740
2511
  emailVerified: "Email has been verified",
2741
2512
  password: "Password",
2742
2513
  username: "Username",
2743
2514
  nextStep: "Next Step",
2744
- skipNotVerify: "Skip, do not verify",
2515
+ skipVerify: "Skip verification",
2745
2516
  logoutConfirm: "Are you sure to logout?",
2746
2517
  accountMergeNotice: "Your email has multiple accounts with different id.",
2747
2518
  accountMergeSelectOne: "Please select one you want to merge all the data into it.",
@@ -2828,196 +2599,50 @@ const zhCN = {
2828
2599
  confirm: "确认",
2829
2600
  cancel: "取消",
2830
2601
  /* Sidebar */
2831
- msgCenter: "通知中心",
2832
- ctrlCenter: "控制中心",
2833
- /* Auth */
2834
- noAccountPrompt: "没有账号?",
2835
- haveAccountPrompt: "已有账号?",
2836
- forgetPassword: "忘记密码",
2837
- resetPassword: "重置密码",
2838
- verificationCode: "验证码",
2839
- verifySend: "发送验证码",
2840
- verifyResend: "重新发送",
2841
- waitSeconds: "等待 {seconds}秒",
2842
- emailVerified: "邮箱已验证",
2843
- password: "密码",
2844
- username: "用户名",
2845
- nextStep: "下一步",
2846
- skipNotVerify: "跳过,不验证",
2847
- logoutConfirm: "确定要退出登录吗?",
2848
- accountMergeNotice: "您的电子邮件下有多个不同 ID 的账户。",
2849
- accountMergeSelectOne: "请选择将所有数据合并到其中的一个。",
2850
- accountMergeConfirm: "所有数据将合并到 ID 为 {id} 的账户中。",
2851
- dismiss: "忽略",
2852
- merge: "合并",
2853
- /* General */
2854
- frontend: "前端",
2855
- backend: "后端",
2856
- loading: "加载中",
2857
- loadFail: "加载失败",
2858
- editing: "修改中",
2859
- editFail: "修改失败",
2860
- deleting: "删除中",
2861
- deleteFail: "删除失败",
2862
- reqGot: "请求响应",
2863
- reqAborted: "请求超时或意外终止",
2864
- updateMsg: "请更新 Artalk {name} 以获得更好的体验!",
2865
- currentVersion: "当前版本",
2866
- ignore: "忽略",
2867
- open: "打开",
2868
- openName: "打开{name}"
2869
- };
2870
- const GLOBAL_LOCALES_KEY = "ArtalkI18n";
2871
- function createElement(htmlStr = "") {
2872
- const div = document.createElement("div");
2873
- div.innerHTML = htmlStr.trim();
2874
- return div.firstElementChild || div;
2875
- }
2876
- function getHeight(el) {
2877
- return parseFloat(getComputedStyle(el, null).height.replace("px", ""));
2878
- }
2879
- function htmlEncode(str) {
2880
- const temp = document.createElement("div");
2881
- temp.innerText = str;
2882
- const output = temp.innerHTML;
2883
- return output;
2884
- }
2885
- function getQueryParam(name) {
2886
- const match = RegExp(`[?&]${name}=([^&]*)`).exec(window.location.search);
2887
- return match && decodeURIComponent(match[1].replace(/\+/g, " "));
2888
- }
2889
- function getOffset(el, relativeTo) {
2890
- const getOffsetRecursive = (element) => {
2891
- const rect = element.getBoundingClientRect();
2892
- const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
2893
- const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
2894
- return {
2895
- top: rect.top + scrollTop,
2896
- left: rect.left + scrollLeft
2897
- };
2898
- };
2899
- const elOffset = getOffsetRecursive(el);
2900
- if (!relativeTo)
2901
- return elOffset;
2902
- const relativeToOffset = getOffsetRecursive(relativeTo);
2903
- return {
2904
- top: elOffset.top - relativeToOffset.top,
2905
- left: elOffset.left - relativeToOffset.left
2906
- };
2907
- }
2908
- function padWithZeros(vNumber, width) {
2909
- let numAsString = vNumber.toString();
2910
- while (numAsString.length < width) {
2911
- numAsString = `0${numAsString}`;
2912
- }
2913
- return numAsString;
2914
- }
2915
- function dateFormat(date) {
2916
- const vDay = padWithZeros(date.getDate(), 2);
2917
- const vMonth = padWithZeros(date.getMonth() + 1, 2);
2918
- const vYear = padWithZeros(date.getFullYear(), 2);
2919
- return `${vYear}-${vMonth}-${vDay}`;
2920
- }
2921
- function timeAgo(date, $t = (n) => n) {
2922
- try {
2923
- const oldTime = date.getTime();
2924
- const currTime = (/* @__PURE__ */ new Date()).getTime();
2925
- const diffValue = currTime - oldTime;
2926
- const days = Math.floor(diffValue / (24 * 3600 * 1e3));
2927
- if (days === 0) {
2928
- const leave1 = diffValue % (24 * 3600 * 1e3);
2929
- const hours = Math.floor(leave1 / (3600 * 1e3));
2930
- if (hours === 0) {
2931
- const leave2 = leave1 % (3600 * 1e3);
2932
- const minutes = Math.floor(leave2 / (60 * 1e3));
2933
- if (minutes === 0) {
2934
- const leave3 = leave2 % (60 * 1e3);
2935
- const seconds = Math.round(leave3 / 1e3);
2936
- if (seconds < 10)
2937
- return $t("now");
2938
- return `${seconds} ${$t("seconds")}`;
2939
- }
2940
- return `${minutes} ${$t("minutes")}`;
2941
- }
2942
- return `${hours} ${$t("hours")}`;
2943
- }
2944
- if (days < 0)
2945
- return $t("now");
2946
- if (days < 8) {
2947
- return `${days} ${$t("days")}`;
2948
- }
2949
- return dateFormat(date);
2950
- } catch (error) {
2951
- console.error(error);
2952
- return " - ";
2953
- }
2954
- }
2955
- function getGravatarURL(opts) {
2956
- return `${opts.mirror.replace(/\/$/, "")}/${opts.emailMD5}?${opts.params.replace(/^\?/, "")}`;
2957
- }
2958
- function versionCompare(a, b) {
2959
- const pa = a.split(".");
2960
- const pb = b.split(".");
2961
- for (let i = 0; i < 3; i++) {
2962
- const na = Number(pa[i]);
2963
- const nb = Number(pb[i]);
2964
- if (na > nb)
2965
- return 1;
2966
- if (nb > na)
2967
- return -1;
2968
- if (!Number.isNaN(na) && Number.isNaN(nb))
2969
- return 1;
2970
- if (Number.isNaN(na) && !Number.isNaN(nb))
2971
- return -1;
2972
- }
2973
- return 0;
2974
- }
2975
- function getCorrectUserAgent() {
2976
- return __async(this, null, function* () {
2977
- const uaRaw = navigator.userAgent;
2978
- if (!navigator.userAgentData || !navigator.userAgentData.getHighEntropyValues) {
2979
- return uaRaw;
2980
- }
2981
- const uaData = navigator.userAgentData;
2982
- let uaGot = null;
2983
- try {
2984
- uaGot = yield uaData.getHighEntropyValues(["platformVersion"]);
2985
- } catch (err) {
2986
- console.error(err);
2987
- return uaRaw;
2988
- }
2989
- const majorPlatformVersion = Number(uaGot.platformVersion.split(".")[0]);
2990
- if (uaData.platform === "Windows") {
2991
- if (majorPlatformVersion >= 13) {
2992
- return uaRaw.replace(/Windows NT 10.0/, "Windows NT 11.0");
2993
- }
2994
- }
2995
- if (uaData.platform === "macOS") {
2996
- if (majorPlatformVersion >= 11) {
2997
- return uaRaw.replace(
2998
- /(Mac OS X \d+_\d+_\d+|Mac OS X)/,
2999
- `Mac OS X ${uaGot.platformVersion.replace(/\./g, "_")}`
3000
- );
3001
- }
3002
- }
3003
- return uaRaw;
3004
- });
3005
- }
3006
- function isValidURL(urlRaw) {
3007
- let url;
3008
- try {
3009
- url = new URL(urlRaw);
3010
- } catch (_) {
3011
- return false;
3012
- }
3013
- return url.protocol === "http:" || url.protocol === "https:";
3014
- }
3015
- function getURLBasedOnApi(opts) {
3016
- return getURLBasedOn(opts.base, opts.path);
3017
- }
3018
- function getURLBasedOn(baseURL, path) {
3019
- return `${baseURL.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
3020
- }
2602
+ msgCenter: "通知中心",
2603
+ ctrlCenter: "控制中心",
2604
+ /* Auth */
2605
+ userProfile: "个人资料",
2606
+ noAccountPrompt: "没有账号?",
2607
+ haveAccountPrompt: "已有账号?",
2608
+ forgetPassword: "忘记密码",
2609
+ resetPassword: "重置密码",
2610
+ changePassword: "修改密码",
2611
+ confirmPassword: "确认密码",
2612
+ passwordMismatch: "两次输入的密码不一致",
2613
+ verificationCode: "验证码",
2614
+ verifySend: "发送验证码",
2615
+ verifyResend: "重新发送",
2616
+ waitSeconds: "等待 {seconds}秒",
2617
+ emailVerified: "邮箱已验证",
2618
+ password: "密码",
2619
+ username: "用户名",
2620
+ nextStep: "下一步",
2621
+ skipVerify: "跳过验证",
2622
+ logoutConfirm: "确定要退出登录吗?",
2623
+ accountMergeNotice: "您的电子邮件下有多个不同 ID 的账户。",
2624
+ accountMergeSelectOne: "请选择将所有数据合并到其中的一个。",
2625
+ accountMergeConfirm: "所有数据将合并到 ID 为 {id} 的账户中。",
2626
+ dismiss: "忽略",
2627
+ merge: "合并",
2628
+ /* General */
2629
+ frontend: "前端",
2630
+ backend: "后端",
2631
+ loading: "加载中",
2632
+ loadFail: "加载失败",
2633
+ editing: "修改中",
2634
+ editFail: "修改失败",
2635
+ deleting: "删除中",
2636
+ deleteFail: "删除失败",
2637
+ reqGot: "请求响应",
2638
+ reqAborted: "请求超时或意外终止",
2639
+ updateMsg: "请更新 Artalk {name} 以获得更好的体验!",
2640
+ currentVersion: "当前版本",
2641
+ ignore: "忽略",
2642
+ open: "打开",
2643
+ openName: "打开{name}"
2644
+ };
2645
+ const GLOBAL_LOCALES_KEY = "ArtalkI18n";
3021
2646
  const internal = {
3022
2647
  en,
3023
2648
  "en-US": en,
@@ -3039,8 +2664,7 @@ function findLocaleSet(lang) {
3039
2664
  let LocaleConf = "en";
3040
2665
  let LocaleDict = findLocaleSet(LocaleConf);
3041
2666
  function setLocale(locale) {
3042
- if (locale === LocaleConf)
3043
- return;
2667
+ if (locale === LocaleConf) return;
3044
2668
  LocaleConf = locale;
3045
2669
  LocaleDict = typeof locale === "string" ? findLocaleSet(locale) : locale;
3046
2670
  }
@@ -3066,8 +2690,7 @@ class EventManager {
3066
2690
  * Remove an event listener for a specific event name and handler
3067
2691
  */
3068
2692
  off(name, handler) {
3069
- if (!handler)
3070
- return;
2693
+ if (!handler) return;
3071
2694
  this.events = this.events.filter((evt) => !(evt.name === name && evt.handler === handler));
3072
2695
  }
3073
2696
  /**
@@ -3075,8 +2698,7 @@ class EventManager {
3075
2698
  */
3076
2699
  trigger(name, payload) {
3077
2700
  this.events.slice(0).filter((evt) => evt.name === name && typeof evt.handler === "function").forEach((evt) => {
3078
- if (evt.once)
3079
- this.off(name, evt.handler);
2701
+ if (evt.once) this.off(name, evt.handler);
3080
2702
  evt.handler(payload);
3081
2703
  });
3082
2704
  }
@@ -3101,11 +2723,12 @@ const defaults = {
3101
2723
  uaBadge: true,
3102
2724
  listSort: true,
3103
2725
  preview: true,
3104
- countEl: "#ArtalkCount",
3105
- pvEl: "#ArtalkPV",
2726
+ countEl: ".artalk-comment-count",
2727
+ pvEl: ".artalk-pv-count",
2728
+ statPageKeyAttr: "data-page-key",
3106
2729
  gravatar: {
3107
- mirror: "https://cravatar.cn/avatar/",
3108
- params: "d=mp&s=240"
2730
+ mirror: "https://www.gravatar.com/avatar/",
2731
+ params: "sha256=1&d=mp&s=240"
3109
2732
  },
3110
2733
  pagination: {
3111
2734
  pageSize: 20,
@@ -3128,35 +2751,35 @@ function handelCustomConf(customConf, full = false) {
3128
2751
  if (conf.el && typeof conf.el === "string") {
3129
2752
  try {
3130
2753
  const findEl = document.querySelector(conf.el);
3131
- if (!findEl)
3132
- throw Error(`Target element "${conf.el}" was not found.`);
2754
+ if (!findEl) throw Error(`Target element "${conf.el}" was not found.`);
3133
2755
  conf.el = findEl;
3134
2756
  } catch (e) {
3135
2757
  console.error(e);
3136
2758
  throw new Error("Please check your Artalk `el` config.");
3137
2759
  }
3138
2760
  }
3139
- if (conf.pageKey === "")
3140
- conf.pageKey = `${window.location.pathname}`;
3141
- if (conf.pageTitle === "")
3142
- conf.pageTitle = `${document.title}`;
3143
- if (conf.server)
3144
- conf.server = conf.server.replace(/\/$/, "").replace(/\/api\/?$/, "");
3145
- if (conf.locale === "auto")
3146
- conf.locale = navigator.language;
3147
- if (conf.flatMode === "auto")
3148
- conf.flatMode = window.matchMedia("(max-width: 768px)").matches;
3149
- if (typeof conf.nestMax === "number" && Number(conf.nestMax) <= 1)
3150
- conf.flatMode = true;
2761
+ if (conf.pageKey === "") conf.pageKey = `${window.location.pathname}`;
2762
+ if (conf.pageTitle === "") conf.pageTitle = `${document.title}`;
2763
+ if (conf.server) conf.server = conf.server.replace(/\/$/, "").replace(/\/api\/?$/, "");
2764
+ if (conf.locale === "auto") conf.locale = navigator.language;
2765
+ if (conf.flatMode === "auto") conf.flatMode = window.matchMedia("(max-width: 768px)").matches;
2766
+ if (typeof conf.nestMax === "number" && Number(conf.nestMax) <= 1) conf.flatMode = true;
3151
2767
  return conf;
3152
2768
  }
3153
2769
  function handleConfFormServer(conf) {
3154
- const DisabledKeys = ["el", "pageKey", "pageTitle", "server", "site"];
2770
+ const ExcludedKeys = [
2771
+ "el",
2772
+ "pageKey",
2773
+ "pageTitle",
2774
+ "server",
2775
+ "site",
2776
+ "pvEl",
2777
+ "countEl",
2778
+ "statPageKeyAttr"
2779
+ ];
3155
2780
  Object.keys(conf).forEach((k) => {
3156
- if (DisabledKeys.includes(k))
3157
- delete conf[k];
3158
- if (k === "darkMode" && conf[k] !== "auto")
3159
- delete conf[k];
2781
+ if (ExcludedKeys.includes(k)) delete conf[k];
2782
+ if (k === "darkMode" && conf[k] !== "auto") delete conf[k];
3160
2783
  });
3161
2784
  if (conf.emoticons && typeof conf.emoticons === "string") {
3162
2785
  conf.emoticons = conf.emoticons.trim();
@@ -3177,7 +2800,7 @@ function convertApiOptions(conf, ctx) {
3177
2800
  timeout: conf.reqTimeout,
3178
2801
  getApiToken: () => ctx == null ? void 0 : ctx.get("user").getData().token,
3179
2802
  userInfo: (ctx == null ? void 0 : ctx.get("user").checkHasBasicUserInfo()) ? {
3180
- name: ctx == null ? void 0 : ctx.get("user").getData().nick,
2803
+ name: ctx == null ? void 0 : ctx.get("user").getData().name,
3181
2804
  email: ctx == null ? void 0 : ctx.get("user").getData().email
3182
2805
  } : void 0,
3183
2806
  handlers: ctx == null ? void 0 : ctx.getApiHandlers()
@@ -3227,6 +2850,7 @@ class Context {
3227
2850
  this.$root = conf.el;
3228
2851
  this.$root.classList.add("artalk");
3229
2852
  this.$root.innerHTML = "";
2853
+ conf.darkMode && this.$root.classList.add("atk-dark-mode");
3230
2854
  this.data = new DataManager(this.events);
3231
2855
  this.on("mounted", () => {
3232
2856
  this.mounted = true;
@@ -3242,8 +2866,7 @@ class Context {
3242
2866
  return new Api2(convertApiOptions(this.conf, this));
3243
2867
  }
3244
2868
  getApiHandlers() {
3245
- if (!this.apiHandlers)
3246
- this.apiHandlers = createNewApiHandlers(this);
2869
+ if (!this.apiHandlers) this.apiHandlers = createNewApiHandlers(this);
3247
2870
  return this.apiHandlers;
3248
2871
  }
3249
2872
  getData() {
@@ -3332,50 +2955,6 @@ class Context {
3332
2955
  watchConf(this, keys, effect);
3333
2956
  }
3334
2957
  }
3335
- class Dialog {
3336
- constructor(contentEl) {
3337
- __publicField(this, "$el");
3338
- __publicField(this, "$content");
3339
- __publicField(this, "$actions");
3340
- this.$el = createElement(
3341
- `<div class="atk-layer-dialog-wrap">
3342
- <div class="atk-layer-dialog">
3343
- <div class="atk-layer-dialog-content"></div>
3344
- <div class="atk-layer-dialog-actions"></div>
3345
- </div>
3346
- </div>`
3347
- );
3348
- this.$actions = this.$el.querySelector(".atk-layer-dialog-actions");
3349
- this.$content = this.$el.querySelector(".atk-layer-dialog-content");
3350
- this.$content.appendChild(contentEl);
3351
- }
3352
- /** 按钮 · 确定 */
3353
- setYes(handler) {
3354
- const btn = createElement(
3355
- `<button data-action="confirm">${t("confirm")}</button>`
3356
- );
3357
- btn.onclick = this.onBtnClick(handler);
3358
- this.$actions.appendChild(btn);
3359
- return this;
3360
- }
3361
- /** 按钮 · 取消 */
3362
- setNo(handler) {
3363
- const btn = createElement(
3364
- `<button data-action="cancel">${t("cancel")}</button>`
3365
- );
3366
- btn.onclick = this.onBtnClick(handler);
3367
- this.$actions.appendChild(btn);
3368
- return this;
3369
- }
3370
- onBtnClick(handler) {
3371
- return (evt) => {
3372
- const re = handler(evt.currentTarget, this);
3373
- if (re === void 0 || re === true) {
3374
- this.$el.remove();
3375
- }
3376
- };
3377
- }
3378
- }
3379
2958
  function showLoading(parentElem, conf) {
3380
2959
  let $loading = parentElem.querySelector(":scope > .atk-loading");
3381
2960
  if (!$loading) {
@@ -3386,8 +2965,7 @@ function showLoading(parentElem, conf) {
3386
2965
  </div>
3387
2966
  </div>`
3388
2967
  );
3389
- if (conf == null ? void 0 : conf.transparentBg)
3390
- $loading.style.background = "transparent";
2968
+ if (conf == null ? void 0 : conf.transparentBg) $loading.style.background = "transparent";
3391
2969
  parentElem.appendChild($loading);
3392
2970
  }
3393
2971
  $loading.style.display = "";
@@ -3395,21 +2973,17 @@ function showLoading(parentElem, conf) {
3395
2973
  if ($spinner) {
3396
2974
  $spinner.style.display = "none";
3397
2975
  window.setTimeout(() => {
3398
- if ($spinner.isConnected)
3399
- $spinner.style.display = "";
2976
+ if ($spinner.isConnected) $spinner.style.display = "";
3400
2977
  }, 500);
3401
2978
  }
3402
2979
  }
3403
2980
  function hideLoading(parentElem) {
3404
2981
  const $loading = parentElem.querySelector(":scope > .atk-loading");
3405
- if ($loading)
3406
- $loading.style.display = "none";
2982
+ if ($loading) $loading.style.display = "none";
3407
2983
  }
3408
2984
  function setLoading(val, parentElem) {
3409
- if (val)
3410
- showLoading(parentElem);
3411
- else
3412
- hideLoading(parentElem);
2985
+ if (val) showLoading(parentElem);
2986
+ else hideLoading(parentElem);
3413
2987
  }
3414
2988
  function scrollIntoView(elem, enableAnim = true, relativeTo) {
3415
2989
  let top;
@@ -3428,10 +3002,8 @@ function scrollIntoView(elem, enableAnim = true, relativeTo) {
3428
3002
  // behavior: enableAnim ? 'smooth' : 'instant',
3429
3003
  behavior: "instant"
3430
3004
  };
3431
- if (relativeTo)
3432
- relativeTo.scroll(scrollOptions);
3433
- else
3434
- window.scroll(scrollOptions);
3005
+ if (relativeTo) relativeTo.scroll(scrollOptions);
3006
+ else window.scroll(scrollOptions);
3435
3007
  }
3436
3008
  function showNotify(wrapElem, msg, type) {
3437
3009
  const colors = { s: "#57d59f", e: "#ff6f6c", w: "#ffc721", i: "#2ebcfc" };
@@ -3473,8 +3045,7 @@ function playFadeInAnim(elem, after) {
3473
3045
  function setError(parentElem, html, title = '<span class="atk-error-title">Artalk Error</span>') {
3474
3046
  let elem = parentElem.querySelector(".atk-error-layer");
3475
3047
  if (html === null) {
3476
- if (elem !== null)
3477
- elem.remove();
3048
+ if (elem !== null) elem.remove();
3478
3049
  return;
3479
3050
  }
3480
3051
  if (!elem) {
@@ -3485,8 +3056,7 @@ function setError(parentElem, html, title = '<span class="atk-error-title">Artal
3485
3056
  }
3486
3057
  const errorTextEl = elem.querySelector(".atk-error-text");
3487
3058
  errorTextEl.innerHTML = "";
3488
- if (html === null)
3489
- return;
3059
+ if (html === null) return;
3490
3060
  if (html instanceof HTMLElement) {
3491
3061
  errorTextEl.appendChild(html);
3492
3062
  } else {
@@ -3510,8 +3080,7 @@ function getScrollBarWidth() {
3510
3080
  const w1 = inner.offsetWidth;
3511
3081
  outer.style.overflow = "scroll";
3512
3082
  let w2 = inner.offsetWidth;
3513
- if (w1 === w2)
3514
- w2 = outer.clientWidth;
3083
+ if (w1 === w2) w2 = outer.clientWidth;
3515
3084
  document.body.removeChild(outer);
3516
3085
  return w1 - w2;
3517
3086
  }
@@ -3556,8 +3125,7 @@ function iframeBody(checker) {
3556
3125
  (function queryStatus() {
3557
3126
  return __async(this, null, function* () {
3558
3127
  yield sleep(1e3);
3559
- if (stop)
3560
- return;
3128
+ if (stop) return;
3561
3129
  let isPass = false;
3562
3130
  try {
3563
3131
  const resp = yield checker.getApi().captcha.getCaptchaStatus();
@@ -3585,8 +3153,7 @@ const CaptchaChecker = {
3585
3153
  });
3586
3154
  },
3587
3155
  body(checker) {
3588
- if (checker.get("iframe"))
3589
- return iframeBody(checker);
3156
+ if (checker.get("iframe")) return iframeBody(checker);
3590
3157
  return imgBody(checker);
3591
3158
  },
3592
3159
  onSuccess(checker, data, inputVal, formEl) {
@@ -3602,7 +3169,7 @@ const AdminChecker = {
3602
3169
  request(checker, inputVal) {
3603
3170
  return __async(this, null, function* () {
3604
3171
  return (yield checker.getApi().user.login({
3605
- name: checker.getUser().getData().nick,
3172
+ name: checker.getUser().getData().name,
3606
3173
  email: checker.getUser().getData().email,
3607
3174
  password: inputVal
3608
3175
  })).data;
@@ -3613,7 +3180,7 @@ const AdminChecker = {
3613
3180
  },
3614
3181
  onSuccess(checker, res, inputVal, formEl) {
3615
3182
  checker.getUser().update({
3616
- isAdmin: true,
3183
+ is_admin: true,
3617
3184
  token: res.token
3618
3185
  });
3619
3186
  checker.getOpts().onReload();
@@ -3621,6 +3188,50 @@ const AdminChecker = {
3621
3188
  onError(checker, err, inputVal, formEl) {
3622
3189
  }
3623
3190
  };
3191
+ class Dialog {
3192
+ constructor(contentEl) {
3193
+ __publicField(this, "$el");
3194
+ __publicField(this, "$content");
3195
+ __publicField(this, "$actions");
3196
+ this.$el = createElement(
3197
+ `<div class="atk-layer-dialog-wrap">
3198
+ <div class="atk-layer-dialog">
3199
+ <div class="atk-layer-dialog-content"></div>
3200
+ <div class="atk-layer-dialog-actions"></div>
3201
+ </div>
3202
+ </div>`
3203
+ );
3204
+ this.$actions = this.$el.querySelector(".atk-layer-dialog-actions");
3205
+ this.$content = this.$el.querySelector(".atk-layer-dialog-content");
3206
+ this.$content.appendChild(contentEl);
3207
+ }
3208
+ /** 按钮 · 确定 */
3209
+ setYes(handler) {
3210
+ const btn = createElement(
3211
+ `<button data-action="confirm">${t("confirm")}</button>`
3212
+ );
3213
+ btn.onclick = this.onBtnClick(handler);
3214
+ this.$actions.appendChild(btn);
3215
+ return this;
3216
+ }
3217
+ /** 按钮 · 取消 */
3218
+ setNo(handler) {
3219
+ const btn = createElement(
3220
+ `<button data-action="cancel">${t("cancel")}</button>`
3221
+ );
3222
+ btn.onclick = this.onBtnClick(handler);
3223
+ this.$actions.appendChild(btn);
3224
+ return this;
3225
+ }
3226
+ onBtnClick(handler) {
3227
+ return (evt) => {
3228
+ const re = handler(evt.currentTarget, this);
3229
+ if (re === void 0 || re === true) {
3230
+ this.$el.remove();
3231
+ }
3232
+ };
3233
+ }
3234
+ }
3624
3235
  function wrapPromise(fn) {
3625
3236
  return (payload) => new Promise((resolve, reject) => {
3626
3237
  const cancelFn = payload.onCancel;
@@ -3670,19 +3281,15 @@ class CheckerLauncher {
3670
3281
  },
3671
3282
  triggerSuccess: () => {
3672
3283
  close();
3673
- if (checker.onSuccess)
3674
- checker.onSuccess(checkerCtx, "", "", formEl);
3675
- if (payload.onSuccess)
3676
- payload.onSuccess();
3284
+ if (checker.onSuccess) checker.onSuccess(checkerCtx, "", "", formEl);
3285
+ if (payload.onSuccess) payload.onSuccess();
3677
3286
  },
3678
3287
  cancel: () => {
3679
3288
  close();
3680
- if (payload.onCancel)
3681
- payload.onCancel();
3289
+ if (payload.onCancel) payload.onCancel();
3682
3290
  }
3683
3291
  };
3684
- if (postFire)
3685
- postFire(checkerCtx);
3292
+ if (postFire) postFire(checkerCtx);
3686
3293
  const formEl = createElement();
3687
3294
  formEl.appendChild(checker.body(checkerCtx));
3688
3295
  const $input = createElement(
@@ -3700,8 +3307,7 @@ class CheckerLauncher {
3700
3307
  const dialog = new Dialog(formEl);
3701
3308
  dialog.setYes((btnEl) => {
3702
3309
  const inputVal = $input.value.trim();
3703
- if (!btnTextOrg)
3704
- btnTextOrg = btnEl.innerText;
3310
+ if (!btnTextOrg) btnTextOrg = btnEl.innerText;
3705
3311
  const btnTextSet = (btnText) => {
3706
3312
  btnEl.innerText = btnText;
3707
3313
  btnEl.classList.add("error");
@@ -3713,14 +3319,11 @@ class CheckerLauncher {
3713
3319
  btnEl.innerText = `${t("loading")}...`;
3714
3320
  checker.request(checkerCtx, inputVal).then((data) => {
3715
3321
  close();
3716
- if (checker.onSuccess)
3717
- checker.onSuccess(checkerCtx, data, inputVal, formEl);
3718
- if (payload.onSuccess)
3719
- payload.onSuccess();
3322
+ if (checker.onSuccess) checker.onSuccess(checkerCtx, data, inputVal, formEl);
3323
+ if (payload.onSuccess) payload.onSuccess();
3720
3324
  }).catch((err) => {
3721
3325
  btnTextSet(String(err.message || String(err)));
3722
- if (checker.onError)
3723
- checker.onError(checkerCtx, err, inputVal, formEl);
3326
+ if (checker.onError) checker.onError(checkerCtx, err, inputVal, formEl);
3724
3327
  const tf = setTimeout(() => btnTextRestore(), 3e3);
3725
3328
  $input.onfocus = () => {
3726
3329
  btnTextRestore();
@@ -3731,8 +3334,7 @@ class CheckerLauncher {
3731
3334
  });
3732
3335
  dialog.setNo(() => {
3733
3336
  close();
3734
- if (payload.onCancel)
3735
- payload.onCancel();
3337
+ if (payload.onCancel) payload.onCancel();
3736
3338
  return false;
3737
3339
  });
3738
3340
  if (hideInteractInput) {
@@ -3740,8 +3342,7 @@ class CheckerLauncher {
3740
3342
  dialog.$el.querySelector(".atk-layer-dialog-actions").style.display = "none";
3741
3343
  }
3742
3344
  layer.getEl().append(dialog.$el);
3743
- if (payload.onMount)
3744
- payload.onMount(dialog.$el);
3345
+ if (payload.onMount) payload.onMount(dialog.$el);
3745
3346
  }
3746
3347
  }
3747
3348
  class Component {
@@ -3756,10 +3357,10 @@ class Component {
3756
3357
  return this.$el;
3757
3358
  }
3758
3359
  }
3759
- const EditorHTML = '<div class="atk-main-editor">\n <div class="atk-header">\n <input name="nick" class="atk-nick" type="text" required="required" />\n <input name="email" class="atk-email" type="email" required="required" />\n <input name="link" class="atk-link" type="url" />\n </div>\n <div class="atk-textarea-wrap">\n <textarea class="atk-textarea"></textarea>\n </div>\n <div class="atk-plug-panel-wrap" style="display: none"></div>\n <div class="atk-bottom">\n <div class="atk-item atk-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';
3360
+ const EditorHTML = '<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';
3760
3361
  const Sel = {
3761
3362
  $header: ".atk-header",
3762
- $nick: '.atk-header [name="nick"]',
3363
+ $name: '.atk-header [name="name"]',
3763
3364
  $email: '.atk-header [name="email"]',
3764
3365
  $link: '.atk-header [name="link"]',
3765
3366
  $textareaWrap: ".atk-textarea-wrap",
@@ -3782,6 +3383,9 @@ function render() {
3782
3383
  }
3783
3384
  class EditorPlug {
3784
3385
  constructor(kit) {
3386
+ __publicField(this, "$btn");
3387
+ __publicField(this, "$panel");
3388
+ __publicField(this, "editorStateEffectWhen");
3785
3389
  this.kit = kit;
3786
3390
  }
3787
3391
  /** Use plug btn will add a btn on the bottom of editor */
@@ -3801,15 +3405,13 @@ class EditorPlug {
3801
3405
  /** Listen the event of panel show */
3802
3406
  usePanelShow(func) {
3803
3407
  this.kit.useEvents().on("panel-show", (aPlug) => {
3804
- if (aPlug === this)
3805
- func();
3408
+ if (aPlug === this) func();
3806
3409
  });
3807
3410
  }
3808
3411
  /** Listen the event of panel hide */
3809
3412
  usePanelHide(func) {
3810
3413
  this.kit.useEvents().on("panel-hide", (aPlug) => {
3811
- if (aPlug === this)
3812
- func();
3414
+ if (aPlug === this) func();
3813
3415
  });
3814
3416
  }
3815
3417
  /** Use editor state modifier */
@@ -3824,8 +3426,7 @@ class Mover extends EditorPlug {
3824
3426
  __publicField(this, "isMoved", false);
3825
3427
  }
3826
3428
  move(afterEl) {
3827
- if (this.isMoved)
3828
- return;
3429
+ if (this.isMoved) return;
3829
3430
  this.isMoved = true;
3830
3431
  const editorEl = this.kit.useUI().$el;
3831
3432
  editorEl.after(createElement('<div class="atk-editor-travel-placeholder"></div>'));
@@ -3837,8 +3438,7 @@ class Mover extends EditorPlug {
3837
3438
  }
3838
3439
  back() {
3839
3440
  var _a;
3840
- if (!this.isMoved)
3841
- return;
3441
+ if (!this.isMoved) return;
3842
3442
  this.isMoved = false;
3843
3443
  (_a = this.kit.useGlobalCtx().$root.querySelector(".atk-editor-travel-placeholder")) == null ? void 0 : _a.replaceWith(this.kit.useUI().$el);
3844
3444
  this.kit.useUI().$el.classList.remove("editor-traveling");
@@ -3901,13 +3501,12 @@ class Editor extends Component {
3901
3501
  return this.state.get();
3902
3502
  }
3903
3503
  getHeaderInputEls() {
3904
- return { nick: this.ui.$nick, email: this.ui.$email, link: this.ui.$link };
3504
+ return { name: this.ui.$name, email: this.ui.$email, link: this.ui.$link };
3905
3505
  }
3906
3506
  getContentFinal() {
3907
3507
  let content = this.getContentRaw();
3908
3508
  const plugs = this.getPlugs();
3909
- if (plugs)
3910
- content = plugs.getTransformedContent(content);
3509
+ if (plugs) content = plugs.getTransformedContent(content);
3911
3510
  return content;
3912
3511
  }
3913
3512
  getContentRaw() {
@@ -3985,8 +3584,8 @@ class SidebarLayer extends Component {
3985
3584
  __publicField(this, "$closeBtn");
3986
3585
  __publicField(this, "$iframeWrap");
3987
3586
  __publicField(this, "$iframe");
3988
- /** Refresh iFrame on show */
3989
- __publicField(this, "refreshOnShow", true);
3587
+ /** Refresh iFrame when show */
3588
+ __publicField(this, "refreshWhenShow", true);
3990
3589
  /** Animation timer */
3991
3590
  __publicField(this, "animTimer");
3992
3591
  this.$el = createElement(SidebarHTML);
@@ -3997,7 +3596,7 @@ class SidebarLayer extends Component {
3997
3596
  this.hide();
3998
3597
  };
3999
3598
  this.ctx.on("user-changed", () => {
4000
- this.refreshOnShow = true;
3599
+ this.refreshWhenShow = true;
4001
3600
  });
4002
3601
  }
4003
3602
  /** 显示 */
@@ -4006,8 +3605,8 @@ class SidebarLayer extends Component {
4006
3605
  this.$el.style.transform = "";
4007
3606
  this.initLayer();
4008
3607
  this.layer.show();
4009
- if (this.refreshOnShow) {
4010
- this.refreshOnShow = false;
3608
+ if (this.refreshWhenShow) {
3609
+ this.refreshWhenShow = false;
4011
3610
  this.$iframeWrap.innerHTML = "";
4012
3611
  this.$iframe = this.createIframe(conf.view);
4013
3612
  this.$iframeWrap.append(this.$iframe);
@@ -4017,7 +3616,7 @@ class SidebarLayer extends Component {
4017
3616
  if (this.getDarkMode() !== iFrameSrc.includes("&darkMode=1")) {
4018
3617
  this.iframeLoad(
4019
3618
  $iframe,
4020
- this.getDarkMode() ? iFrameSrc.concat("&darkMode=1") : iFrameSrc.replace("&darkMode=1", "")
3619
+ iFrameSrc.replace(/&darkMode=\d/, `&darkMode=${Number(this.getDarkMode())}`)
4021
3620
  );
4022
3621
  }
4023
3622
  }
@@ -4045,7 +3644,7 @@ class SidebarLayer extends Component {
4045
3644
  return __async(this, null, function* () {
4046
3645
  const data = (yield this.ctx.getApi().user.getUserStatus(__spreadValues({}, this.ctx.getApi().getUserFields()))).data;
4047
3646
  if (data.is_admin && !data.is_login) {
4048
- this.refreshOnShow = true;
3647
+ this.refreshWhenShow = true;
4049
3648
  this.ctx.checkAdmin({
4050
3649
  onSuccess: () => {
4051
3650
  setTimeout(() => {
@@ -4061,8 +3660,7 @@ class SidebarLayer extends Component {
4061
3660
  });
4062
3661
  }
4063
3662
  initLayer() {
4064
- if (this.layer)
4065
- return;
3663
+ if (this.layer) return;
4066
3664
  this.layer = this.ctx.get("layerManager").create("sidebar", this.$el);
4067
3665
  this.layer.setOnAfterHide(() => {
4068
3666
  this.ctx.editorResetState();
@@ -4085,10 +3683,8 @@ class SidebarLayer extends Component {
4085
3683
  user: JSON.stringify(this.ctx.get("user").getData()),
4086
3684
  time: +/* @__PURE__ */ new Date()
4087
3685
  };
4088
- if (view)
4089
- query.view = view;
4090
- if (this.getDarkMode())
4091
- query.darkMode = "1";
3686
+ if (view) query.view = view;
3687
+ query.darkMode = this.getDarkMode() ? "1" : "0";
4092
3688
  const urlParams = new URLSearchParams(query);
4093
3689
  this.iframeLoad($iframe, `${baseURL}?${urlParams.toString()}`);
4094
3690
  return $iframe;
@@ -4119,10 +3715,8 @@ function makeNestCommentNodeList(srcData, sortBy = "DATE_DESC", nestMax = 2) {
4119
3715
  nodeList.push(rootNode);
4120
3716
  (function loadChildren(parentNode) {
4121
3717
  const children = srcData.filter((o) => o.rid === parentNode.id);
4122
- if (children.length === 0)
4123
- return;
4124
- if (parentNode.level >= nestMax)
4125
- parentNode = parentNode.parent;
3718
+ if (children.length === 0) return;
3719
+ if (parentNode.level >= nestMax) parentNode = parentNode.parent;
4126
3720
  children.forEach((child) => {
4127
3721
  const childNode = {
4128
3722
  id: child.id,
@@ -4138,14 +3732,10 @@ function makeNestCommentNodeList(srcData, sortBy = "DATE_DESC", nestMax = 2) {
4138
3732
  });
4139
3733
  const sortFunc = (a, b) => {
4140
3734
  let v = a.id - b.id;
4141
- if (sortBy === "DATE_ASC")
4142
- v = +new Date(a.comment.date) - +new Date(b.comment.date);
4143
- else if (sortBy === "DATE_DESC")
4144
- v = +new Date(b.comment.date) - +new Date(a.comment.date);
4145
- else if (sortBy === "SRC_INDEX")
4146
- v = srcData.indexOf(a.comment) - srcData.indexOf(b.comment);
4147
- else if (sortBy === "VOTE_UP_DESC")
4148
- v = b.comment.vote_up - a.comment.vote_up;
3735
+ if (sortBy === "DATE_ASC") v = +new Date(a.comment.date) - +new Date(b.comment.date);
3736
+ else if (sortBy === "DATE_DESC") v = +new Date(b.comment.date) - +new Date(a.comment.date);
3737
+ else if (sortBy === "SRC_INDEX") v = srcData.indexOf(a.comment) - srcData.indexOf(b.comment);
3738
+ else if (sortBy === "VOTE_UP_DESC") v = b.comment.vote_up - a.comment.vote_up;
4149
3739
  return v;
4150
3740
  };
4151
3741
  (function sortLevels(nodes) {
@@ -4209,16 +3799,13 @@ const createFlatStrategy = (opts) => ({
4209
3799
  }
4210
3800
  });
4211
3801
  function insertComment(opts, insertMode, comment, replyComment) {
4212
- if (comment.is_collapsed)
4213
- comment.is_allow_reply = false;
3802
+ if (comment.is_collapsed) comment.is_allow_reply = false;
4214
3803
  const node = opts.createCommentNode(comment, replyComment);
4215
3804
  if (comment.visible) {
4216
3805
  const $comment = node.getEl();
4217
3806
  const $listCommentsWrap = opts.$commentsWrap;
4218
- if (insertMode === "append")
4219
- $listCommentsWrap == null ? void 0 : $listCommentsWrap.append($comment);
4220
- if (insertMode === "prepend")
4221
- $listCommentsWrap == null ? void 0 : $listCommentsWrap.prepend($comment);
3807
+ if (insertMode === "append") $listCommentsWrap == null ? void 0 : $listCommentsWrap.append($comment);
3808
+ if (insertMode === "prepend") $listCommentsWrap == null ? void 0 : $listCommentsWrap.prepend($comment);
4222
3809
  node.getRender().playFadeAnim();
4223
3810
  }
4224
3811
  node.getRender().checkHeightLimit();
@@ -4323,8 +3910,7 @@ function Detect(userAgent) {
4323
3910
  dest.language = (() => {
4324
3911
  const g = nav.browserLanguage || nav.language;
4325
3912
  const arr = g.split("-");
4326
- if (arr[1])
4327
- arr[1] = arr[1].toUpperCase();
3913
+ if (arr[1]) arr[1] = arr[1].toUpperCase();
4328
3914
  return arr.join("_");
4329
3915
  })();
4330
3916
  const hash = {
@@ -4335,8 +3921,7 @@ function Detect(userAgent) {
4335
3921
  };
4336
3922
  Object.entries(hash).forEach(([type, match]) => {
4337
3923
  Object.entries(match).forEach(([name, result]) => {
4338
- if (result === true)
4339
- dest[type] = name;
3924
+ if (result === true) dest[type] = name;
4340
3925
  });
4341
3926
  });
4342
3927
  const osVersion = {
@@ -4431,16 +4016,12 @@ function Detect(userAgent) {
4431
4016
  }
4432
4017
  function check(conf, rules) {
4433
4018
  rules.forEach(({ el, max, imgCheck }) => {
4434
- if (!el)
4435
- return;
4436
- if (imgCheck)
4437
- el.style.maxHeight = `${max + 1}px`;
4019
+ if (!el) return;
4020
+ if (imgCheck) el.style.maxHeight = `${max + 1}px`;
4438
4021
  let lock = false;
4439
4022
  const _check = () => {
4440
- if (lock)
4441
- return;
4442
- if (getHeight(el) <= max)
4443
- return;
4023
+ if (lock) return;
4024
+ if (getHeight(el) <= max) return;
4444
4025
  const afterExpandBtnClick = () => {
4445
4026
  var _a;
4446
4027
  lock = true;
@@ -4450,7 +4031,9 @@ function check(conf, rules) {
4450
4031
  };
4451
4032
  _check();
4452
4033
  if (imgCheck) {
4453
- el.querySelectorAll(".atk-content img").forEach((img) => {
4034
+ const imgs = el.querySelectorAll(".atk-content img");
4035
+ if (imgs.length === 0) el.style.maxHeight = "";
4036
+ imgs.forEach((img) => {
4454
4037
  img.onload = () => _check();
4455
4038
  });
4456
4039
  }
@@ -4458,12 +4041,9 @@ function check(conf, rules) {
4458
4041
  }
4459
4042
  const HEIGHT_LIMIT_CSS = "atk-height-limit";
4460
4043
  function applyHeightLimit(obj) {
4461
- if (!obj.el)
4462
- return;
4463
- if (!obj.max)
4464
- return;
4465
- if (obj.el.classList.contains(HEIGHT_LIMIT_CSS))
4466
- return;
4044
+ if (!obj.el) return;
4045
+ if (!obj.max) return;
4046
+ if (obj.el.classList.contains(HEIGHT_LIMIT_CSS)) return;
4467
4047
  obj.el.classList.add(HEIGHT_LIMIT_CSS);
4468
4048
  obj.el.style.height = `${obj.max}px`;
4469
4049
  obj.el.style.overflow = "hidden";
@@ -4473,20 +4053,16 @@ function applyHeightLimit(obj) {
4473
4053
  $expandBtn.onclick = (e) => {
4474
4054
  e.stopPropagation();
4475
4055
  disposeHeightLimit(obj.el);
4476
- if (obj.afterExpandBtnClick)
4477
- obj.afterExpandBtnClick(e);
4056
+ if (obj.afterExpandBtnClick) obj.afterExpandBtnClick(e);
4478
4057
  };
4479
4058
  obj.el.append($expandBtn);
4480
4059
  }
4481
4060
  function disposeHeightLimit($el) {
4482
- if (!$el)
4483
- return;
4484
- if (!$el.classList.contains(HEIGHT_LIMIT_CSS))
4485
- return;
4061
+ if (!$el) return;
4062
+ if (!$el.classList.contains(HEIGHT_LIMIT_CSS)) return;
4486
4063
  $el.classList.remove(HEIGHT_LIMIT_CSS);
4487
4064
  Array.from($el.children).forEach((e) => {
4488
- if (e.classList.contains("atk-height-limit-btn"))
4489
- e.remove();
4065
+ if (e.classList.contains("atk-height-limit-btn")) e.remove();
4490
4066
  });
4491
4067
  $el.style.height = "";
4492
4068
  $el.style.maxHeight = "";
@@ -4494,10 +4070,8 @@ function disposeHeightLimit($el) {
4494
4070
  }
4495
4071
  const HEIGHT_LIMIT_SCROLL_CSS = "atk-height-limit-scroll";
4496
4072
  function applyScrollableHeightLimit(opt) {
4497
- if (!opt.el)
4498
- return;
4499
- if (opt.el.classList.contains(HEIGHT_LIMIT_SCROLL_CSS))
4500
- return;
4073
+ if (!opt.el) return;
4074
+ if (opt.el.classList.contains(HEIGHT_LIMIT_SCROLL_CSS)) return;
4501
4075
  opt.el.classList.add(HEIGHT_LIMIT_SCROLL_CSS);
4502
4076
  opt.el.style.height = `${opt.max}px`;
4503
4077
  }
@@ -4568,8 +4142,7 @@ function renderDate(ctx) {
4568
4142
  $date.setAttribute("data-atk-comment-date", String(+new Date(ctx.data.date)));
4569
4143
  }
4570
4144
  function renderUABadge(ctx) {
4571
- if (!ctx.opts.uaBadge && !ctx.data.ip_region)
4572
- return;
4145
+ if (!ctx.opts.uaBadge && !ctx.data.ip_region) return;
4573
4146
  let $uaWrap = ctx.$header.querySelector("atk-ua-wrap");
4574
4147
  if (!$uaWrap) {
4575
4148
  $uaWrap = createElement(`<span class="atk-ua-wrap"></span>`);
@@ -4624,10 +4197,8 @@ function renderContent(r) {
4624
4197
  });
4625
4198
  }
4626
4199
  function renderReplyAt(r) {
4627
- if (r.opts.flatMode || r.data.rid === 0)
4628
- return;
4629
- if (!r.opts.replyTo)
4630
- return;
4200
+ if (r.opts.flatMode || r.data.rid === 0) return;
4201
+ if (!r.opts.replyTo) return;
4631
4202
  r.$replyAt = createElement(
4632
4203
  `<span class="atk-item atk-reply-at"><span class="atk-arrow"></span><span class="atk-nick"></span></span>`
4633
4204
  );
@@ -4638,10 +4209,8 @@ function renderReplyAt(r) {
4638
4209
  r.$headerBadgeWrap.insertAdjacentElement("afterend", r.$replyAt);
4639
4210
  }
4640
4211
  function renderReplyTo(r) {
4641
- if (!r.opts.flatMode)
4642
- return;
4643
- if (!r.opts.replyTo)
4644
- return;
4212
+ if (!r.opts.flatMode) return;
4213
+ if (!r.opts.replyTo) return;
4645
4214
  r.$replyTo = createElement(`
4646
4215
  <div class="atk-reply-to">
4647
4216
  <div class="atk-meta">${t("reply")} <span class="atk-nick"></span>:</div>
@@ -4653,14 +4222,12 @@ function renderReplyTo(r) {
4653
4222
  r.comment.getActions().goToReplyComment();
4654
4223
  };
4655
4224
  let replyContent = marked(r.opts.replyTo.content);
4656
- if (r.opts.replyTo.is_collapsed)
4657
- replyContent = `[${t("collapsed")}]`;
4225
+ if (r.opts.replyTo.is_collapsed) replyContent = `[${t("collapsed")}]`;
4658
4226
  r.$replyTo.querySelector(".atk-content").innerHTML = replyContent;
4659
4227
  r.$body.prepend(r.$replyTo);
4660
4228
  }
4661
4229
  function renderPending(r) {
4662
- if (!r.data.is_pending)
4663
- return;
4230
+ if (!r.data.is_pending) return;
4664
4231
  const pendingEl = createElement(`<div class="atk-pending">${t("pendingMsg")}</div>`);
4665
4232
  r.$body.prepend(pendingEl);
4666
4233
  }
@@ -4682,8 +4249,7 @@ class ActionBtn {
4682
4249
  this.$el = createElement(`<span class="atk-common-action-btn"></span>`);
4683
4250
  this.opts = typeof opts !== "object" ? { text: opts } : opts;
4684
4251
  this.$el.innerText = this.getText();
4685
- if (this.opts.adminOnly)
4686
- this.$el.setAttribute("atk-only-admin-show", "");
4252
+ if (this.opts.adminOnly) this.$el.setAttribute("atk-only-admin-show", "");
4687
4253
  }
4688
4254
  // 消息显示复原操作
4689
4255
  get isMessaging() {
@@ -4718,8 +4284,7 @@ class ActionBtn {
4718
4284
  this.confirmRecTimer = window.setTimeout(() => confirmRestore(), 5e3);
4719
4285
  return;
4720
4286
  }
4721
- if (this.confirmRecTimer)
4722
- window.clearTimeout(this.confirmRecTimer);
4287
+ if (this.confirmRecTimer) window.clearTimeout(this.confirmRecTimer);
4723
4288
  confirmRestore();
4724
4289
  }
4725
4290
  if (this.msgRecTimer) {
@@ -4732,15 +4297,13 @@ class ActionBtn {
4732
4297
  }
4733
4298
  /** 文字刷新(动态/静态) */
4734
4299
  updateText(text) {
4735
- if (text)
4736
- this.opts.text = text;
4300
+ if (text) this.opts.text = text;
4737
4301
  this.setLoading(false);
4738
4302
  this.$el.innerText = this.getText();
4739
4303
  }
4740
4304
  /** 设置加载状态 */
4741
4305
  setLoading(value, loadingText) {
4742
- if (this.isLoading === value)
4743
- return;
4306
+ if (this.isLoading === value) return;
4744
4307
  this.isLoading = value;
4745
4308
  if (value) {
4746
4309
  this.$el.classList.add("atk-btn-loading");
@@ -4765,15 +4328,12 @@ class ActionBtn {
4765
4328
  /** 设置消息 */
4766
4329
  setMsg(text, className, duringTime, after) {
4767
4330
  this.setLoading(false);
4768
- if (className)
4769
- this.$el.classList.add(className);
4331
+ if (className) this.$el.classList.add(className);
4770
4332
  this.$el.innerText = text;
4771
4333
  this.setMsgRecTimer(() => {
4772
4334
  this.$el.innerText = this.getText();
4773
- if (className)
4774
- this.$el.classList.remove(className);
4775
- if (after)
4776
- after();
4335
+ if (className) this.$el.classList.remove(className);
4336
+ if (after) after();
4777
4337
  }, duringTime || 2500);
4778
4338
  }
4779
4339
  /** 设置消息复原操作定时器 */
@@ -4788,13 +4348,11 @@ class ActionBtn {
4788
4348
  }
4789
4349
  /** 立刻触发器复原定时器 */
4790
4350
  fireMsgRecTimer() {
4791
- if (this.msgRecTimerFunc)
4792
- this.msgRecTimerFunc();
4351
+ if (this.msgRecTimerFunc) this.msgRecTimerFunc();
4793
4352
  }
4794
4353
  /** 仅清除 timer */
4795
4354
  clearMsgRecTimer() {
4796
- if (this.msgRecTimer)
4797
- window.clearTimeout(this.msgRecTimer);
4355
+ if (this.msgRecTimer) window.clearTimeout(this.msgRecTimer);
4798
4356
  this.msgRecTimer = void 0;
4799
4357
  this.msgRecTimerFunc = void 0;
4800
4358
  }
@@ -4814,8 +4372,7 @@ function renderActions(r) {
4814
4372
  });
4815
4373
  }
4816
4374
  function renderVote(r) {
4817
- if (!r.opts.vote)
4818
- return;
4375
+ if (!r.opts.vote) return;
4819
4376
  r.voteBtnUp = new ActionBtn(() => `${t("voteUp")} (${r.data.vote_up || 0})`).appendTo(r.$actions);
4820
4377
  r.voteBtnUp.setClick(() => {
4821
4378
  r.comment.getActions().vote("up");
@@ -4830,8 +4387,7 @@ function renderVote(r) {
4830
4387
  }
4831
4388
  }
4832
4389
  function renderReply(r) {
4833
- if (!r.data.is_allow_reply)
4834
- return;
4390
+ if (!r.data.is_allow_reply) return;
4835
4391
  const replyBtn = createElement(`<span>${t("reply")}</span>`);
4836
4392
  r.$actions.append(replyBtn);
4837
4393
  replyBtn.addEventListener("click", (e) => {
@@ -4957,8 +4513,7 @@ class Render {
4957
4513
  /** 内容限高检测 */
4958
4514
  checkHeightLimit() {
4959
4515
  const conf = this.opts.heightLimit;
4960
- if (!conf || !conf.content || !conf.children)
4961
- return;
4516
+ if (!conf || !conf.content || !conf.children) return;
4962
4517
  const contentMaxH = conf.content;
4963
4518
  const childrenMaxH = conf.children;
4964
4519
  check(
@@ -4981,8 +4536,7 @@ class Render {
4981
4536
  }
4982
4537
  /** 子评论区域移除限高 */
4983
4538
  heightLimitRemoveForChildren() {
4984
- if (!this.$childrenWrap)
4985
- return;
4539
+ if (!this.$childrenWrap) return;
4986
4540
  disposeHeightLimit(this.$childrenWrap);
4987
4541
  }
4988
4542
  /** 渐出动画 */
@@ -5010,17 +4564,13 @@ class Render {
5010
4564
  }
5011
4565
  /** 设置已读 */
5012
4566
  setUnread(val) {
5013
- if (val)
5014
- this.$el.classList.add("atk-unread");
5015
- else
5016
- this.$el.classList.remove("atk-unread");
4567
+ if (val) this.$el.classList.add("atk-unread");
4568
+ else this.$el.classList.remove("atk-unread");
5017
4569
  }
5018
4570
  /** 设置为可点击的评论 */
5019
4571
  setOpenable(val) {
5020
- if (val)
5021
- this.$el.classList.add("atk-openable");
5022
- else
5023
- this.$el.classList.remove("atk-openable");
4572
+ if (val) this.$el.classList.add("atk-openable");
4573
+ else this.$el.classList.remove("atk-openable");
5024
4574
  }
5025
4575
  /** 设置点击评论打开置顶 URL */
5026
4576
  setOpenURL(url) {
@@ -5069,8 +4619,7 @@ class CommentActions {
5069
4619
  }
5070
4620
  /** 管理员 - 评论状态修改 */
5071
4621
  adminEdit(type, btnElem) {
5072
- if (btnElem.isLoading)
5073
- return;
4622
+ if (btnElem.isLoading) return;
5074
4623
  btnElem.setLoading(true, `${t("editing")}...`);
5075
4624
  const modify = __spreadValues({}, this.data);
5076
4625
  if (type === "collapsed") {
@@ -5090,13 +4639,11 @@ class CommentActions {
5090
4639
  }
5091
4640
  /** 管理员 - 评论删除 */
5092
4641
  adminDelete(btnElem) {
5093
- if (btnElem.isLoading)
5094
- return;
4642
+ if (btnElem.isLoading) return;
5095
4643
  btnElem.setLoading(true, `${t("deleting")}...`);
5096
4644
  this.getApi().comments.deleteComment(this.data.id).then(() => {
5097
4645
  btnElem.setLoading(false);
5098
- if (this.opts.onDelete)
5099
- this.opts.onDelete(this.comment);
4646
+ if (this.opts.onDelete) this.opts.onDelete(this.comment);
5100
4647
  }).catch((e) => {
5101
4648
  console.error(e);
5102
4649
  btnElem.setError(t("deleteFail"));
@@ -5107,8 +4654,7 @@ class CommentActions {
5107
4654
  const origHash = window.location.hash;
5108
4655
  const modifyHash = `#atk-comment-${this.data.rid}`;
5109
4656
  window.location.hash = modifyHash;
5110
- if (modifyHash === origHash)
5111
- window.dispatchEvent(new Event("hashchange"));
4657
+ if (modifyHash === origHash) window.dispatchEvent(new Event("hashchange"));
5112
4658
  }
5113
4659
  }
5114
4660
  class CommentNode {
@@ -5133,11 +4679,9 @@ class CommentNode {
5133
4679
  /** 渲染 UI */
5134
4680
  render() {
5135
4681
  const newEl = this.renderInstance.render();
5136
- if (this.$el)
5137
- this.$el.replaceWith(newEl);
4682
+ if (this.$el) this.$el.replaceWith(newEl);
5138
4683
  this.$el = newEl;
5139
- if (this.opts.onAfterRender)
5140
- this.opts.onAfterRender();
4684
+ if (this.opts.onAfterRender) this.opts.onAfterRender();
5141
4685
  }
5142
4686
  /** 获取评论操作实例对象 */
5143
4687
  getActions() {
@@ -5184,10 +4728,8 @@ class CommentNode {
5184
4728
  this.children.push(childNode);
5185
4729
  const $childrenWrap = this.getChildrenWrapEl();
5186
4730
  const $childComment = childNode.getEl();
5187
- if (insertMode === "append")
5188
- $childrenWrap.append($childComment);
5189
- else if (insertMode === "prepend")
5190
- $childrenWrap.prepend($childComment);
4731
+ if (insertMode === "append") $childrenWrap.append($childComment);
4732
+ else if (insertMode === "prepend") $childrenWrap.prepend($childComment);
5191
4733
  childNode.getRender().playFadeAnim();
5192
4734
  childNode.getRender().checkHeightLimit();
5193
4735
  }
@@ -5215,8 +4757,7 @@ class CommentNode {
5215
4757
  * Please be aware of the memory leak if you use the $el reference directly.
5216
4758
  */
5217
4759
  getEl() {
5218
- if (!this.$el)
5219
- throw new Error("comment element not initialized before `getEl()`");
4760
+ if (!this.$el) throw new Error("comment element not initialized before `getEl()`");
5220
4761
  return this.$el;
5221
4762
  }
5222
4763
  /**
@@ -5225,8 +4766,7 @@ class CommentNode {
5225
4766
  * Scroll to the comment and perform flash animation
5226
4767
  */
5227
4768
  focus() {
5228
- if (!this.$el)
5229
- throw new Error("comment element not initialized before `focus()`");
4769
+ if (!this.$el) throw new Error("comment element not initialized before `focus()`");
5230
4770
  this.getParents().forEach((p) => {
5231
4771
  p.getRender().heightLimitRemoveForChildren();
5232
4772
  });
@@ -5248,7 +4788,7 @@ class CommentNode {
5248
4788
  return getGravatarURL({
5249
4789
  mirror: this.opts.gravatar.mirror,
5250
4790
  params: this.opts.gravatar.params,
5251
- emailMD5: this.data.email_encrypted
4791
+ emailHash: this.data.email_encrypted
5252
4792
  });
5253
4793
  }
5254
4794
  /** 获取评论 markdown 解析后的内容 */
@@ -5257,7 +4797,9 @@ class CommentNode {
5257
4797
  }
5258
4798
  /** 获取格式化后的日期 */
5259
4799
  getDateFormatted() {
5260
- return timeAgo(new Date(this.data.date), t);
4800
+ var _a, _b;
4801
+ const date = new Date(this.data.date);
4802
+ return ((_b = (_a = this.opts).dateFormatter) == null ? void 0 : _b.call(_a, date)) || timeAgo(date, t);
5261
4803
  }
5262
4804
  /** 获取用户 UserAgent 信息 */
5263
4805
  getUserUA() {
@@ -5291,6 +4833,7 @@ function createCommentNode(ctx, comment, replyComment, opts) {
5291
4833
  vote: ctx.conf.vote,
5292
4834
  voteDown: ctx.conf.voteDown,
5293
4835
  uaBadge: ctx.conf.uaBadge,
4836
+ dateFormatter: ctx.conf.dateFormatter,
5294
4837
  // TODO: move to plugin folder and remove from core
5295
4838
  getApi: () => ctx.getApi(),
5296
4839
  replyComment: (c, $el) => ctx.replyComment(c, $el),
@@ -5329,8 +4872,7 @@ class ReadMoreBtn {
5329
4872
  return this.total > this.offset + this.opts.pageSize;
5330
4873
  }
5331
4874
  click() {
5332
- if (this.hasMore)
5333
- this.opts.onClick(this.offset + this.opts.pageSize);
4875
+ if (this.hasMore) this.opts.onClick(this.offset + this.opts.pageSize);
5334
4876
  this.checkDisabled();
5335
4877
  }
5336
4878
  /** 显示 */
@@ -5363,10 +4905,8 @@ class ReadMoreBtn {
5363
4905
  this.checkDisabled();
5364
4906
  }
5365
4907
  checkDisabled() {
5366
- if (this.hasMore)
5367
- this.show();
5368
- else
5369
- this.hide();
4908
+ if (this.hasMore) this.show();
4909
+ else this.hide();
5370
4910
  }
5371
4911
  }
5372
4912
  class ReadMorePaginator {
@@ -5388,8 +4928,7 @@ class ReadMorePaginator {
5388
4928
  });
5389
4929
  if (opt.readMoreAutoLoad) {
5390
4930
  this.onReachedBottom = () => {
5391
- if (!this.instance.hasMore || this.opt.ctx.getData().getLoading())
5392
- return;
4931
+ if (!this.instance.hasMore || this.opt.ctx.getData().getLoading()) return;
5393
4932
  this.instance.click();
5394
4933
  };
5395
4934
  this.opt.ctx.on("list-reach-bottom", this.onReachedBottom);
@@ -5495,10 +5034,8 @@ class Pagination {
5495
5034
  }
5496
5035
  this.change(page);
5497
5036
  };
5498
- if (!now)
5499
- this.inputTimer = window.setTimeout(() => modify(), 800);
5500
- else
5501
- modify();
5037
+ if (!now) this.inputTimer = window.setTimeout(() => modify(), 800);
5038
+ else modify();
5502
5039
  }
5503
5040
  prev() {
5504
5041
  const page = this.page - 1;
@@ -5557,10 +5094,8 @@ class Pagination {
5557
5094
  }
5558
5095
  /** 加载 */
5559
5096
  setLoading(isLoading) {
5560
- if (isLoading)
5561
- showLoading(this.$el);
5562
- else
5563
- hideLoading(this.$el);
5097
+ if (isLoading) showLoading(this.$el);
5098
+ else hideLoading(this.$el);
5564
5099
  }
5565
5100
  }
5566
5101
  class UpDownPaginator {
@@ -5602,26 +5137,22 @@ class UpDownPaginator {
5602
5137
  }
5603
5138
  }
5604
5139
  function createPaginatorByConf(conf) {
5605
- if (conf.pagination.readMore)
5606
- return new ReadMorePaginator();
5140
+ if (conf.pagination.readMore) return new ReadMorePaginator();
5607
5141
  return new UpDownPaginator();
5608
5142
  }
5609
5143
  function getPageDataByLastData(ctx) {
5610
5144
  const last = ctx.getData().getListLastFetch();
5611
5145
  const r = { offset: 0, total: 0 };
5612
- if (!last)
5613
- return r;
5146
+ if (!last) return r;
5614
5147
  r.offset = last.params.offset;
5615
- if (last.data)
5616
- r.total = last.params.flatMode ? last.data.count : last.data.roots_count;
5148
+ if (last.data) r.total = last.params.flatMode ? last.data.count : last.data.roots_count;
5617
5149
  return r;
5618
5150
  }
5619
5151
  const initListPaginatorFunc = (ctx) => {
5620
5152
  let paginator = null;
5621
5153
  ctx.watchConf(["pagination", "locale"], (conf) => {
5622
5154
  const list = ctx.get("list");
5623
- if (paginator)
5624
- paginator.dispose();
5155
+ if (paginator) paginator.dispose();
5625
5156
  paginator = createPaginatorByConf(conf);
5626
5157
  const { offset, total } = getPageDataByLastData(ctx);
5627
5158
  const $paginator = paginator.create({
@@ -5761,18 +5292,14 @@ class Layer {
5761
5292
  this.$el.style.display = "";
5762
5293
  }
5763
5294
  hide() {
5764
- return __async(this, null, function* () {
5765
- this.opts.onHide();
5766
- this.$el.style.display = "none";
5767
- this.onAfterHide && this.onAfterHide();
5768
- });
5295
+ this.opts.onHide();
5296
+ this.$el.style.display = "none";
5297
+ this.onAfterHide && this.onAfterHide();
5769
5298
  }
5770
5299
  destroy() {
5771
- return __async(this, null, function* () {
5772
- this.opts.onHide();
5773
- this.$el.remove();
5774
- this.onAfterHide && this.onAfterHide();
5775
- });
5300
+ this.opts.onHide();
5301
+ this.$el.remove();
5302
+ this.onAfterHide && this.onAfterHide();
5776
5303
  }
5777
5304
  }
5778
5305
  class LayerWrap {
@@ -5850,11 +5377,12 @@ class User {
5850
5377
  this.opts = opts;
5851
5378
  const localUser = JSON.parse(window.localStorage.getItem(LOCAL_USER_KEY) || "{}");
5852
5379
  this.data = {
5853
- nick: localUser.nick || "",
5380
+ name: localUser.name || localUser.nick || "",
5381
+ // nick is deprecated (for historical compatibility)
5854
5382
  email: localUser.email || "",
5855
5383
  link: localUser.link || "",
5856
5384
  token: localUser.token || "",
5857
- isAdmin: localUser.isAdmin || false
5385
+ is_admin: localUser.is_admin || localUser.isAdmin || false
5858
5386
  };
5859
5387
  }
5860
5388
  getData() {
@@ -5871,17 +5399,17 @@ class User {
5871
5399
  /**
5872
5400
  * Logout
5873
5401
  *
5874
- * @description Logout will clear login status, but not clear user data (nick, email, link)
5402
+ * @description Logout will clear login status, but not clear user data (name, email, link)
5875
5403
  */
5876
5404
  logout() {
5877
5405
  this.update({
5878
5406
  token: "",
5879
- isAdmin: false
5407
+ is_admin: false
5880
5408
  });
5881
5409
  }
5882
5410
  /** Check if user has filled basic data */
5883
5411
  checkHasBasicUserInfo() {
5884
- return !!this.data.nick && !!this.data.email;
5412
+ return !!this.data.name && !!this.data.email;
5885
5413
  }
5886
5414
  }
5887
5415
  const services = {
@@ -5943,7 +5471,7 @@ const services = {
5943
5471
  }
5944
5472
  };
5945
5473
  const PvCountWidget = (ctx) => {
5946
- ctx.watchConf(["site", "pageKey", "pageTitle", "countEl", "pvEl"], (conf) => {
5474
+ ctx.watchConf(["site", "pageKey", "pageTitle", "countEl", "pvEl", "statPageKeyAttr"], (conf) => {
5947
5475
  initCountWidget({
5948
5476
  getApi: () => ctx.getApi(),
5949
5477
  siteName: conf.site,
@@ -5951,81 +5479,84 @@ const PvCountWidget = (ctx) => {
5951
5479
  pageTitle: conf.pageTitle,
5952
5480
  countEl: conf.countEl,
5953
5481
  pvEl: conf.pvEl,
5482
+ pageKeyAttr: conf.statPageKeyAttr,
5954
5483
  pvAdd: typeof ctx.conf.pvAdd === "boolean" ? ctx.conf.pvAdd : true
5955
5484
  });
5956
5485
  });
5957
5486
  };
5958
5487
  function initCountWidget(opt) {
5959
5488
  return __async(this, null, function* () {
5960
- if (opt.countEl && document.querySelector(opt.countEl)) {
5961
- refreshStatCount(opt, { query: "page_comment", numEl: opt.countEl });
5962
- }
5963
- const initialData = opt.pvAdd && opt.pageKey ? {
5964
- [opt.pageKey]: (yield opt.getApi().pages.logPv({
5965
- page_key: opt.pageKey,
5966
- page_title: opt.pageTitle,
5967
- site_name: opt.siteName
5968
- })).data.pv
5969
- // pv+1 and get pv count
5970
- } : void 0;
5971
- if (opt.pvEl && document.querySelector(opt.pvEl)) {
5972
- refreshStatCount(opt, {
5973
- query: "page_pv",
5974
- numEl: opt.pvEl,
5975
- data: initialData
5976
- });
5977
- }
5489
+ yield loadCommentCount(opt);
5490
+ const cacheData = yield incrementPvCount(opt);
5491
+ yield loadPvCount(opt, cacheData);
5492
+ });
5493
+ }
5494
+ function incrementPvCount(opt) {
5495
+ return __async(this, null, function* () {
5496
+ if (!opt.pvAdd || !opt.pageKey) return void 0;
5497
+ const pvCount = (yield opt.getApi().pages.logPv({
5498
+ page_key: opt.pageKey,
5499
+ page_title: opt.pageTitle,
5500
+ site_name: opt.siteName
5501
+ })).data.pv;
5502
+ return {
5503
+ [opt.pageKey]: pvCount
5504
+ };
5505
+ });
5506
+ }
5507
+ function loadCommentCount(opt) {
5508
+ return __async(this, null, function* () {
5509
+ yield loadStatCount({ opt, query: "page_comment", containers: [opt.countEl, "#ArtalkCount"] });
5510
+ });
5511
+ }
5512
+ function loadPvCount(opt, cache) {
5513
+ return __async(this, null, function* () {
5514
+ yield loadStatCount({ opt, query: "page_pv", containers: [opt.pvEl, "#ArtalkPV"], cache });
5978
5515
  });
5979
5516
  }
5980
- function refreshStatCount(opt, args) {
5517
+ function loadStatCount(args) {
5981
5518
  return __async(this, null, function* () {
5982
- let data = args.data || {};
5983
- let queryPageKeys = Array.from(document.querySelectorAll(args.numEl)).map((e) => e.getAttribute("data-page-key") || opt.pageKey).filter((k) => k && typeof data[k] !== "number");
5984
- queryPageKeys = [...new Set(queryPageKeys)];
5985
- if (queryPageKeys.length > 0) {
5519
+ const { opt } = args;
5520
+ let cache = args.cache || {};
5521
+ const els = retrieveElements(args.containers);
5522
+ const pageKeys = getPageKeys(els, opt.pageKeyAttr, opt.pageKey, cache);
5523
+ if (pageKeys.length > 0) {
5986
5524
  const res = (yield opt.getApi().stats.getStats(args.query, {
5987
- page_keys: queryPageKeys.join(","),
5525
+ page_keys: pageKeys.join(","),
5988
5526
  site_name: opt.siteName
5989
5527
  })).data.data;
5990
- data = __spreadValues(__spreadValues({}, data), res);
5528
+ cache = __spreadValues(__spreadValues({}, cache), res);
5991
5529
  }
5992
- const defaultCount = opt.pageKey ? data[opt.pageKey] : 0;
5993
- applyCountData(args.numEl, data, defaultCount);
5530
+ updateElementsText(els, cache, opt.pageKey);
5994
5531
  });
5995
5532
  }
5996
- function applyCountData(selector, data, defaultCount) {
5997
- document.querySelectorAll(selector).forEach((el) => {
5998
- const pageKey = el.getAttribute("data-page-key");
5999
- const count = Number(pageKey ? data[pageKey] : defaultCount);
6000
- el.innerHTML = `${count}`;
5533
+ function retrieveElements(containers) {
5534
+ const els = /* @__PURE__ */ new Set();
5535
+ new Set(containers).forEach((selector) => {
5536
+ document.querySelectorAll(selector).forEach((el) => els.add(el));
6001
5537
  });
5538
+ return els;
6002
5539
  }
6003
- function showErrorDialog(opts) {
6004
- const errEl = createElement(`<span><span class="error-message"></span><br/><br/></span>`);
6005
- errEl.querySelector(".error-message").innerText = `${t("listLoadFailMsg")}
6006
- ${opts.errMsg}`;
6007
- if (opts.retryFn) {
6008
- const $retryBtn = createElement(`<span style="cursor:pointer;">${t("listRetry")}</span>`);
6009
- $retryBtn.onclick = () => opts.retryFn && opts.retryFn();
6010
- errEl.appendChild($retryBtn);
6011
- }
6012
- if (opts.onOpenSidebar) {
6013
- const $openSidebar = createElement(
6014
- `<span atk-only-admin-show> | <span style="cursor:pointer;">${t("openName", { name: t("ctrlCenter") })}</span></span>`
6015
- );
6016
- errEl.appendChild($openSidebar);
6017
- $openSidebar.onclick = () => opts.onOpenSidebar && opts.onOpenSidebar();
6018
- }
6019
- setError(opts.$err, errEl);
5540
+ function getPageKeys(els, pageKeyAttr, pageKey, cache) {
5541
+ const pageKeys = Array.from(els).map((el) => el.getAttribute(pageKeyAttr) || pageKey).filter((key) => key && typeof cache[key] !== "number");
5542
+ return [...new Set(pageKeys)];
5543
+ }
5544
+ function updateElementsText(els, data, defaultPageKey) {
5545
+ els.forEach((el) => {
5546
+ const pageKey = el.getAttribute("data-page-key");
5547
+ const count = pageKey && data[pageKey] || defaultPageKey && data[defaultPageKey] || 0;
5548
+ el.innerText = `${Number(count)}`;
5549
+ });
6020
5550
  }
6021
5551
  const Markdown = (ctx) => {
6022
- ctx.watchConf(["markedReplacers", "imgLazyLoad", "markedOptions"], (conf) => {
5552
+ ctx.watchConf(["imgLazyLoad", "markedOptions"], (conf) => {
6023
5553
  initMarked({
6024
5554
  markedOptions: ctx.getConf().markedOptions,
6025
5555
  imgLazyLoad: ctx.getConf().imgLazyLoad
6026
5556
  });
6027
- if (conf.markedReplacers)
6028
- setReplacers(conf.markedReplacers);
5557
+ });
5558
+ ctx.watchConf(["markedReplacers"], (conf) => {
5559
+ conf.markedReplacers && setReplacers(conf.markedReplacers);
6029
5560
  });
6030
5561
  };
6031
5562
  const LocalStorageKey = "ArtalkContent";
@@ -6117,11 +5648,11 @@ class SubmitAddPreset {
6117
5648
  }
6118
5649
  getSubmitAddParams() {
6119
5650
  return __async(this, null, function* () {
6120
- const { nick, email, link } = this.kit.useUser().getData();
5651
+ const { name, email, link } = this.kit.useUser().getData();
6121
5652
  const conf = this.kit.useConf();
6122
5653
  return {
6123
5654
  content: this.kit.useEditor().getContentFinal(),
6124
- name: nick,
5655
+ name,
6125
5656
  email,
6126
5657
  link,
6127
5658
  rid: 0,
@@ -6163,17 +5694,12 @@ class Submit extends EditorPlug {
6163
5694
  const custom = this.customs.find((o) => o.activeCond());
6164
5695
  this.kit.useEditor().showLoading();
6165
5696
  try {
6166
- if (custom == null ? void 0 : custom.pre)
6167
- custom.pre();
5697
+ if (custom == null ? void 0 : custom.pre) custom.pre();
6168
5698
  let nComment;
6169
- if (custom == null ? void 0 : custom.req)
6170
- nComment = yield custom.req();
6171
- else
6172
- nComment = yield this.defaultPreset.reqAdd();
6173
- if (custom == null ? void 0 : custom.post)
6174
- custom.post(nComment);
6175
- else
6176
- this.defaultPreset.postSubmitAdd(nComment);
5699
+ if (custom == null ? void 0 : custom.req) nComment = yield custom.req();
5700
+ else nComment = yield this.defaultPreset.reqAdd();
5701
+ if (custom == null ? void 0 : custom.post) custom.post(nComment);
5702
+ else this.defaultPreset.postSubmitAdd(nComment);
6177
5703
  } catch (err) {
6178
5704
  console.error(err);
6179
5705
  this.kit.useEditor().showNotify(`${t("commentFail")}: ${err.message || String(err)}`, "e");
@@ -6198,15 +5724,13 @@ class StateReply extends EditorPlug {
6198
5724
  });
6199
5725
  this.kit.useEvents().on("mounted", () => {
6200
5726
  const submitPlug = this.kit.useDeps(Submit);
6201
- if (!submitPlug)
6202
- throw Error("SubmitPlug not initialized");
5727
+ if (!submitPlug) throw Error("SubmitPlug not initialized");
6203
5728
  const defaultPreset = new SubmitAddPreset(this.kit);
6204
5729
  submitPlug.registerCustom({
6205
5730
  activeCond: () => !!this.comment,
6206
5731
  // active this custom submit when reply mode
6207
5732
  req: () => __async(this, null, function* () {
6208
- if (!this.comment)
6209
- throw new Error("reply comment cannot be empty");
5733
+ if (!this.comment) throw new Error("reply comment cannot be empty");
6210
5734
  const nComment = (yield this.kit.useApi().comments.createComment(__spreadProps(__spreadValues({}, yield defaultPreset.getSubmitAddParams()), {
6211
5735
  rid: this.comment.id,
6212
5736
  page_key: this.comment.page_key,
@@ -6242,8 +5766,7 @@ class StateReply extends EditorPlug {
6242
5766
  ui.$textarea.focus();
6243
5767
  }
6244
5768
  cancelReply() {
6245
- if (!this.comment)
6246
- return;
5769
+ if (!this.comment) return;
6247
5770
  const ui = this.kit.useUI();
6248
5771
  if (ui.$sendReplyBtn) {
6249
5772
  ui.$sendReplyBtn.remove();
@@ -6268,15 +5791,14 @@ class StateEdit extends EditorPlug {
6268
5791
  });
6269
5792
  this.kit.useMounted(() => {
6270
5793
  const submitPlug = this.kit.useDeps(Submit);
6271
- if (!submitPlug)
6272
- throw Error("SubmitPlug not initialized");
5794
+ if (!submitPlug) throw Error("SubmitPlug not initialized");
6273
5795
  submitPlug.registerCustom({
6274
5796
  activeCond: () => !!this.comment,
6275
5797
  // active this custom submit when edit mode
6276
5798
  req: () => __async(this, null, function* () {
6277
5799
  const saveData = {
6278
5800
  content: this.kit.useEditor().getContentFinal(),
6279
- nick: this.kit.useUI().$nick.value,
5801
+ nick: this.kit.useUI().$name.value,
6280
5802
  email: this.kit.useUI().$email.value,
6281
5803
  link: this.kit.useUI().$link.value
6282
5804
  };
@@ -6304,7 +5826,7 @@ class StateEdit extends EditorPlug {
6304
5826
  }
6305
5827
  this.comment = comment;
6306
5828
  ui.$header.style.display = "none";
6307
- ui.$nick.value = comment.nick || "";
5829
+ ui.$name.value = comment.nick || "";
6308
5830
  ui.$email.value = comment.email || "";
6309
5831
  ui.$link.value = comment.link || "";
6310
5832
  this.kit.useEditor().setContent(comment.content);
@@ -6312,16 +5834,15 @@ class StateEdit extends EditorPlug {
6312
5834
  this.updateSubmitBtnText(t("save"));
6313
5835
  }
6314
5836
  cancelEdit() {
6315
- if (!this.comment)
6316
- return;
5837
+ if (!this.comment) return;
6317
5838
  const ui = this.kit.useUI();
6318
5839
  if (ui.$editCancelBtn) {
6319
5840
  ui.$editCancelBtn.remove();
6320
5841
  ui.$editCancelBtn = void 0;
6321
5842
  }
6322
5843
  this.comment = void 0;
6323
- const { nick, email, link } = this.kit.useUser().getData();
6324
- ui.$nick.value = nick;
5844
+ const { name, email, link } = this.kit.useUser().getData();
5845
+ ui.$name.value = name;
6325
5846
  ui.$email.value = email;
6326
5847
  ui.$link.value = link;
6327
5848
  this.kit.useEditor().setContent("");
@@ -6361,7 +5882,7 @@ class Closable extends EditorPlug {
6361
5882
  this.kit.useUI().$textareaWrap.prepend(
6362
5883
  createElement(`<div class="atk-comment-closed">${t("onlyAdminCanReply")}</div>`)
6363
5884
  );
6364
- if (!this.kit.useUser().getData().isAdmin) {
5885
+ if (!this.kit.useUser().getData().is_admin) {
6365
5886
  this.kit.useUI().$textarea.style.display = "none";
6366
5887
  this.kit.useEvents().trigger("panel-close");
6367
5888
  this.kit.useUI().$bottom.style.display = "none";
@@ -6410,15 +5931,18 @@ class HeaderUser extends EditorPlug {
6410
5931
  abortFn: null
6411
5932
  });
6412
5933
  const onInput = ({ $input, field }) => {
6413
- if (this.kit.useEditor().getState() === "edit")
6414
- return;
5934
+ if (this.kit.useEditor().getState() === "edit") return;
6415
5935
  this.kit.useUser().update({ [field]: $input.value.trim() });
6416
- if (field === "nick" || field === "email")
6417
- this.fetchUserInfo();
5936
+ if (field === "name" || field === "email") this.fetchUserInfo();
5937
+ };
5938
+ const placeholders = {
5939
+ name: t("nick"),
5940
+ email: t("email"),
5941
+ link: t("link")
6418
5942
  };
6419
5943
  this.kit.useMounted(() => {
6420
5944
  Object.entries(this.kit.useEditor().getHeaderInputEls()).forEach(([key, $input]) => {
6421
- $input.placeholder = `${t(key)}`;
5945
+ $input.placeholder = placeholders[key];
6422
5946
  $input.value = this.kit.useUser().getData()[key] || "";
6423
5947
  });
6424
5948
  this.kit.useEvents().on("header-input", onInput);
@@ -6432,10 +5956,8 @@ class HeaderUser extends EditorPlug {
6432
5956
  */
6433
5957
  fetchUserInfo() {
6434
5958
  this.kit.useUser().logout();
6435
- if (this.query.timer)
6436
- window.clearTimeout(this.query.timer);
6437
- if (this.query.abortFn)
6438
- this.query.abortFn();
5959
+ if (this.query.timer) window.clearTimeout(this.query.timer);
5960
+ if (this.query.abortFn) this.query.abortFn();
6439
5961
  this.query.timer = window.setTimeout(() => {
6440
5962
  this.query.timer = null;
6441
5963
  const api = this.kit.useApi();
@@ -6459,8 +5981,7 @@ class HeaderUser extends EditorPlug {
6459
5981
  */
6460
5982
  onUserInfoFetched(data) {
6461
5983
  var _a;
6462
- if (!data.is_login)
6463
- this.kit.useUser().logout();
5984
+ if (!data.is_login) this.kit.useUser().logout();
6464
5985
  this.kit.useGlobalCtx().getData().updateNotifies(data.notifies);
6465
5986
  if (this.kit.useUser().checkHasBasicUserInfo() && !data.is_login && ((_a = data.user) == null ? void 0 : _a.is_admin)) {
6466
5987
  this.kit.useGlobalCtx().checkAdmin({
@@ -6478,8 +5999,7 @@ class HeaderLink extends EditorPlug {
6478
5999
  constructor(kit) {
6479
6000
  super(kit);
6480
6001
  const onLinkChange = ({ field }) => {
6481
- if (field === "link")
6482
- this.onLinkInputChange();
6002
+ if (field === "link") this.onLinkInputChange();
6483
6003
  };
6484
6004
  this.kit.useMounted(() => {
6485
6005
  this.kit.useEvents().on("header-change", onLinkChange);
@@ -6535,8 +6055,7 @@ class Emoticons extends EditorPlug {
6535
6055
  }
6536
6056
  loadEmoticonsData() {
6537
6057
  return __async(this, null, function* () {
6538
- if (this.isListLoaded)
6539
- return;
6058
+ if (this.isListLoaded) return;
6540
6059
  if (this.loadingTask !== null) {
6541
6060
  yield this.loadingTask;
6542
6061
  return;
@@ -6562,10 +6081,8 @@ class Emoticons extends EditorPlug {
6562
6081
  return [];
6563
6082
  }
6564
6083
  const pushGrp = (grp) => {
6565
- if (typeof grp !== "object")
6566
- return;
6567
- if (grp.name && data.find((o) => o.name === grp.name))
6568
- return;
6084
+ if (typeof grp !== "object") return;
6085
+ if (grp.name && data.find((o) => o.name === grp.name)) return;
6569
6086
  data.push(grp);
6570
6087
  };
6571
6088
  const remoteLoad = (d) => __async(this, null, function* () {
@@ -6577,10 +6094,8 @@ class Emoticons extends EditorPlug {
6577
6094
  yield remoteLoad(grp);
6578
6095
  } else if (typeof grp === "string") {
6579
6096
  const grpData = yield this.remoteLoad(grp);
6580
- if (Array.isArray(grpData))
6581
- yield remoteLoad(grpData);
6582
- else if (typeof grpData === "object")
6583
- pushGrp(grpData);
6097
+ if (Array.isArray(grpData)) yield remoteLoad(grpData);
6098
+ else if (typeof grpData === "object") pushGrp(grpData);
6584
6099
  }
6585
6100
  }))
6586
6101
  );
@@ -6609,8 +6124,7 @@ class Emoticons extends EditorPlug {
6609
6124
  /** 远程加载 */
6610
6125
  remoteLoad(url) {
6611
6126
  return __async(this, null, function* () {
6612
- if (!url)
6613
- return [];
6127
+ if (!url) return [];
6614
6128
  try {
6615
6129
  const resp = yield fetch(url);
6616
6130
  const json = yield resp.json();
@@ -6627,8 +6141,7 @@ class Emoticons extends EditorPlug {
6627
6141
  solveNullKey(data) {
6628
6142
  data.forEach((grp) => {
6629
6143
  grp.items.forEach((item, index) => {
6630
- if (!item.key)
6631
- item.key = `${grp.name} ${index + 1}`;
6144
+ if (!item.key) item.key = `${grp.name} ${index + 1}`;
6632
6145
  });
6633
6146
  });
6634
6147
  }
@@ -6637,14 +6150,10 @@ class Emoticons extends EditorPlug {
6637
6150
  const tmp = {};
6638
6151
  data.forEach((grp) => {
6639
6152
  grp.items.forEach((item) => {
6640
- if (!item.key || String(item.key).trim() === "")
6641
- return;
6642
- if (!tmp[item.key])
6643
- tmp[item.key] = 1;
6644
- else
6645
- tmp[item.key]++;
6646
- if (tmp[item.key] > 1)
6647
- item.key = `${item.key} ${tmp[item.key]}`;
6153
+ if (!item.key || String(item.key).trim() === "") return;
6154
+ if (!tmp[item.key]) tmp[item.key] = 1;
6155
+ else tmp[item.key]++;
6156
+ if (tmp[item.key] > 1) item.key = `${item.key} ${tmp[item.key]}`;
6648
6157
  });
6649
6158
  });
6650
6159
  }
@@ -6665,8 +6174,7 @@ class Emoticons extends EditorPlug {
6665
6174
  const iconStr = item.icon;
6666
6175
  if (/<(img|IMG)/.test(iconStr)) {
6667
6176
  const find = /src=["'](.*?)["']/.exec(iconStr);
6668
- if (find && find.length > 1)
6669
- item.icon = find[1];
6177
+ if (find && find.length > 1) item.icon = find[1];
6670
6178
  }
6671
6179
  nGrp.items.push({
6672
6180
  key: item.text || `${grpName} ${index + 1}`,
@@ -6720,8 +6228,7 @@ class Emoticons extends EditorPlug {
6720
6228
  this.$grpSwitcher.append($item);
6721
6229
  });
6722
6230
  }
6723
- if (this.emoticons.length > 0)
6724
- this.openGrp(0);
6231
+ if (this.emoticons.length > 0) this.openGrp(0);
6725
6232
  }
6726
6233
  /** 打开一个表情组 */
6727
6234
  openGrp(index) {
@@ -6742,11 +6249,9 @@ class Emoticons extends EditorPlug {
6742
6249
  }
6743
6250
  /** 处理评论 content 中的表情内容 */
6744
6251
  transEmoticonImageText(text) {
6745
- if (!this.emoticons || !Array.isArray(this.emoticons))
6746
- return text;
6252
+ if (!this.emoticons || !Array.isArray(this.emoticons)) return text;
6747
6253
  this.emoticons.forEach((grp) => {
6748
- if (grp.type !== "image")
6749
- return;
6254
+ if (grp.type !== "image") return;
6750
6255
  Object.entries(grp.items).forEach(([index, item]) => {
6751
6256
  text = text.split(`:[${item.key}]`).join(`<img src="${item.val}" atk-emoticon="${item.key}">`);
6752
6257
  });
@@ -6775,8 +6280,7 @@ class Upload extends EditorPlug {
6775
6280
  const $input = this.$imgUploadInput;
6776
6281
  $input.onchange = () => {
6777
6282
  (() => __async(this, null, function* () {
6778
- if (!$input.files || $input.files.length === 0)
6779
- return;
6283
+ if (!$input.files || $input.files.length === 0) return;
6780
6284
  const file = $input.files[0];
6781
6285
  this.uploadImg(file);
6782
6286
  }))();
@@ -6789,8 +6293,7 @@ class Upload extends EditorPlug {
6789
6293
  }
6790
6294
  initDragImg() {
6791
6295
  const uploadFromFileList = (files) => {
6792
- if (!files)
6793
- return;
6296
+ if (!files) return;
6794
6297
  for (let i = 0; i < files.length; i++) {
6795
6298
  const file = files[i];
6796
6299
  this.uploadImg(file);
@@ -6830,15 +6333,13 @@ class Upload extends EditorPlug {
6830
6333
  uploadImg(file) {
6831
6334
  return __async(this, null, function* () {
6832
6335
  const fileExt = /[^.]+$/.exec(file.name);
6833
- if (!fileExt || !AllowImgExts.includes(String(fileExt[0]).toLowerCase()))
6834
- return;
6336
+ if (!fileExt || !AllowImgExts.includes(String(fileExt[0]).toLowerCase())) return;
6835
6337
  if (!this.kit.useUser().checkHasBasicUserInfo()) {
6836
6338
  this.kit.useEditor().showNotify(t("uploadLoginMsg"), "w");
6837
6339
  return;
6838
6340
  }
6839
6341
  let insertPrefix = "\n";
6840
- if (this.kit.useUI().$textarea.value.trim() === "")
6841
- insertPrefix = "";
6342
+ if (this.kit.useUI().$textarea.value.trim() === "") insertPrefix = "";
6842
6343
  const uploadPlaceholderTxt = `${insertPrefix}![](Uploading ${file.name}...)`;
6843
6344
  this.kit.useEditor().insertContent(uploadPlaceholderTxt);
6844
6345
  let resp;
@@ -7008,8 +6509,7 @@ class PlugManager {
7008
6509
  clear() {
7009
6510
  this.plugs = [];
7010
6511
  this.events = new EventManager();
7011
- if (this.openedPlug)
7012
- this.closePlugPanel();
6512
+ if (this.openedPlug) this.closePlugPanel();
7013
6513
  }
7014
6514
  loadPluginUI() {
7015
6515
  this.editor.getUI().$plugPanelWrap.innerHTML = "";
@@ -7020,8 +6520,7 @@ class PlugManager {
7020
6520
  /** Load the plug btn and plug panel on editor ui */
7021
6521
  loadPluginItem(plug) {
7022
6522
  const $btn = plug.$btn;
7023
- if (!$btn)
7024
- return;
6523
+ if (!$btn) return;
7025
6524
  this.editor.getUI().$plugBtnWrap.appendChild($btn);
7026
6525
  !$btn.onclick && ($btn.onclick = () => {
7027
6526
  this.editor.getUI().$plugBtnWrap.querySelectorAll(".active").forEach((item) => item.classList.remove("active"));
@@ -7045,8 +6544,7 @@ class PlugManager {
7045
6544
  openPlugPanel(plug) {
7046
6545
  this.plugs.forEach((aPlug) => {
7047
6546
  const plugPanel = aPlug.$panel;
7048
- if (!plugPanel)
7049
- return;
6547
+ if (!plugPanel) return;
7050
6548
  if (aPlug === plug) {
7051
6549
  plugPanel.style.display = "";
7052
6550
  this.events.trigger("panel-show", plug);
@@ -7060,8 +6558,7 @@ class PlugManager {
7060
6558
  }
7061
6559
  /** Close the editor plug panel */
7062
6560
  closePlugPanel() {
7063
- if (!this.openedPlug)
7064
- return;
6561
+ if (!this.openedPlug) return;
7065
6562
  this.editor.getUI().$plugPanelWrap.style.display = "none";
7066
6563
  this.events.trigger("panel-hide", this.openedPlug);
7067
6564
  this.openedPlug = null;
@@ -7070,8 +6567,7 @@ class PlugManager {
7070
6567
  getTransformedContent(rawContent) {
7071
6568
  let result = rawContent;
7072
6569
  this.plugs.forEach((aPlug) => {
7073
- if (!aPlug.contentTransformer)
7074
- return;
6570
+ if (!aPlug.contentTransformer) return;
7075
6571
  result = aPlug.contentTransformer(result);
7076
6572
  });
7077
6573
  return result;
@@ -7084,8 +6580,7 @@ const WithEditor = (ctx) => {
7084
6580
  $closeCommentBtn = list.$el.querySelector('[data-action="admin-close-comment"]');
7085
6581
  $closeCommentBtn.addEventListener("click", () => {
7086
6582
  const page = ctx.getData().getPage();
7087
- if (!page)
7088
- throw new Error("Page data not found");
6583
+ if (!page) throw new Error("Page data not found");
7089
6584
  page.admin_only = !page.admin_only;
7090
6585
  adminPageEditSave(ctx, page);
7091
6586
  });
@@ -7147,8 +6642,7 @@ const Count = (ctx) => {
7147
6642
  var _a, _b;
7148
6643
  const list = ctx.get("list");
7149
6644
  const $count = list.$el.querySelector(".atk-comment-count .atk-text");
7150
- if (!$count)
7151
- return;
6645
+ if (!$count) return;
7152
6646
  const text = htmlEncode(
7153
6647
  t("counter", {
7154
6648
  count: `${Number((_b = (_a = ctx.getData().getListLastFetch()) == null ? void 0 : _a.data) == null ? void 0 : _b.count) || 0}`
@@ -7161,26 +6655,22 @@ const Count = (ctx) => {
7161
6655
  });
7162
6656
  ctx.on("comment-inserted", () => {
7163
6657
  const last = ctx.getData().getListLastFetch();
7164
- if (last == null ? void 0 : last.data)
7165
- last.data.count += 1;
6658
+ if (last == null ? void 0 : last.data) last.data.count += 1;
7166
6659
  });
7167
6660
  ctx.on("comment-deleted", () => {
7168
6661
  const last = ctx.getData().getListLastFetch();
7169
- if (last == null ? void 0 : last.data)
7170
- last.data.count -= 1;
6662
+ if (last == null ? void 0 : last.data) last.data.count -= 1;
7171
6663
  });
7172
6664
  };
7173
6665
  const SidebarBtn = (ctx) => {
7174
6666
  let $openSidebarBtn = null;
7175
6667
  const syncByUser = () => {
7176
- if (!$openSidebarBtn)
7177
- return;
6668
+ if (!$openSidebarBtn) return;
7178
6669
  const user = ctx.get("user").getData();
7179
- if (!!user.nick && !!user.email) {
6670
+ if (!!user.name && !!user.email) {
7180
6671
  $openSidebarBtn.classList.remove("atk-hide");
7181
6672
  const $btnText = $openSidebarBtn.querySelector(".atk-text");
7182
- if ($btnText)
7183
- $btnText.innerText = !user.isAdmin ? t("msgCenter") : t("ctrlCenter");
6673
+ if ($btnText) $btnText.innerText = !user.is_admin ? t("msgCenter") : t("ctrlCenter");
7184
6674
  } else {
7185
6675
  $openSidebarBtn.classList.add("atk-hide");
7186
6676
  }
@@ -7188,8 +6678,7 @@ const SidebarBtn = (ctx) => {
7188
6678
  ctx.watchConf(["locale"], (conf) => {
7189
6679
  const list = ctx.get("list");
7190
6680
  $openSidebarBtn = list.$el.querySelector('[data-action="open-sidebar"]');
7191
- if (!$openSidebarBtn)
7192
- return;
6681
+ if (!$openSidebarBtn) return;
7193
6682
  $openSidebarBtn.onclick = () => {
7194
6683
  ctx.showSidebar();
7195
6684
  };
@@ -7202,8 +6691,7 @@ const SidebarBtn = (ctx) => {
7202
6691
  const UnreadBadge = (ctx) => {
7203
6692
  let $unreadBadge = null;
7204
6693
  const showUnreadBadge = (count) => {
7205
- if (!$unreadBadge)
7206
- return;
6694
+ if (!$unreadBadge) return;
7207
6695
  if (count > 0) {
7208
6696
  $unreadBadge.innerText = `${Number(count || 0)}`;
7209
6697
  $unreadBadge.style.display = "block";
@@ -7223,10 +6711,8 @@ const GotoDispatcher = (ctx) => {
7223
6711
  let lastID = 0;
7224
6712
  const check2 = ({ locker }) => {
7225
6713
  const commentID = extractCommentID();
7226
- if (!commentID)
7227
- return;
7228
- if (locker && lastID === commentID)
7229
- return;
6714
+ if (!commentID) return;
6715
+ if (locker && lastID === commentID) return;
7230
6716
  lastID = commentID;
7231
6717
  ctx.trigger("list-goto", commentID);
7232
6718
  };
@@ -7257,18 +6743,16 @@ const GotoFocus = (ctx) => {
7257
6743
  ctx.get("list").getListLayout({ forceFlatMode: true }).insert(data.comment, data.reply_comment);
7258
6744
  comment = ctx.getCommentNodes().find((c) => c.getID() === commentID);
7259
6745
  }
7260
- if (!comment)
7261
- return;
6746
+ if (!comment) return;
7262
6747
  comment.focus();
7263
6748
  }));
7264
6749
  };
7265
- const version = "2.8.6";
6750
+ const version = "2.9.0";
7266
6751
  const Copyright = (ctx) => {
7267
6752
  ctx.on("mounted", () => {
7268
6753
  const list = ctx.get("list");
7269
6754
  const $copyright = list.$el.querySelector(".atk-copyright");
7270
- if (!$copyright)
7271
- return;
6755
+ if (!$copyright) return;
7272
6756
  $copyright.innerHTML = `Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${version}">Artalk</a>`;
7273
6757
  });
7274
6758
  };
@@ -7335,8 +6819,7 @@ const Dropdown = (ctx) => {
7335
6819
  ctx.watchConf(["listSort", "locale"], (conf) => {
7336
6820
  const list = ctx.get("list");
7337
6821
  const $count = list.$el.querySelector(".atk-comment-count");
7338
- if (!$count)
7339
- return;
6822
+ if (!$count) return;
7340
6823
  if (conf.listSort) {
7341
6824
  initDropdown($count);
7342
6825
  } else {
@@ -7348,8 +6831,7 @@ const Dropdown = (ctx) => {
7348
6831
  };
7349
6832
  function renderDropdown(conf) {
7350
6833
  const { $dropdownWrap, dropdownList } = conf;
7351
- if ($dropdownWrap.querySelector(".atk-dropdown"))
7352
- return;
6834
+ if ($dropdownWrap.querySelector(".atk-dropdown")) return;
7353
6835
  $dropdownWrap.classList.add("atk-dropdown-wrap");
7354
6836
  $dropdownWrap.append(createElement(`<span class="atk-arrow-down-icon"></span>`));
7355
6837
  let curtActive = 0;
@@ -7367,8 +6849,7 @@ function renderDropdown(conf) {
7367
6849
  };
7368
6850
  const $dropdown = createElement(`<ul class="atk-dropdown atk-fade-in"></ul>`);
7369
6851
  dropdownList.forEach((item, i) => {
7370
- const name = item[0];
7371
- const action = item[1];
6852
+ const [name, action] = item;
7372
6853
  const $item = createElement(`<li class="atk-dropdown-item"><span></span></li>`);
7373
6854
  const $link = $item.querySelector("span");
7374
6855
  $link.innerText = name;
@@ -7376,8 +6857,7 @@ function renderDropdown(conf) {
7376
6857
  onItemClick(i, $item, name, action);
7377
6858
  };
7378
6859
  $dropdown.append($item);
7379
- if (i === curtActive)
7380
- $item.classList.add("active");
6860
+ if (i === curtActive) $item.classList.add("active");
7381
6861
  });
7382
6862
  $dropdownWrap.append($dropdown);
7383
6863
  }
@@ -7394,8 +6874,9 @@ const TimeTicking = (ctx) => {
7394
6874
  timer = window.setInterval(() => {
7395
6875
  const list = ctx.get("list");
7396
6876
  list.$el.querySelectorAll("[data-atk-comment-date]").forEach((el) => {
7397
- const date = el.getAttribute("data-atk-comment-date");
7398
- el.innerText = timeAgo(new Date(Number(date)), ctx.$t);
6877
+ var _a, _b;
6878
+ const date = new Date(Number(el.getAttribute("data-atk-comment-date")));
6879
+ el.innerText = ((_b = (_a = ctx.getConf()).dateFormatter) == null ? void 0 : _b.call(_a, date)) || timeAgo(date, ctx.$t);
7399
6880
  });
7400
6881
  }, 30 * 1e3);
7401
6882
  });
@@ -7403,6 +6884,24 @@ const TimeTicking = (ctx) => {
7403
6884
  timer && window.clearInterval(timer);
7404
6885
  });
7405
6886
  };
6887
+ function showErrorDialog(opts) {
6888
+ const errEl = createElement(`<span><span class="error-message"></span><br/><br/></span>`);
6889
+ errEl.querySelector(".error-message").innerText = `${t("listLoadFailMsg")}
6890
+ ${opts.errMsg}`;
6891
+ if (opts.retryFn) {
6892
+ const $retryBtn = createElement(`<span style="cursor:pointer;">${t("listRetry")}</span>`);
6893
+ $retryBtn.onclick = () => opts.retryFn && opts.retryFn();
6894
+ errEl.appendChild($retryBtn);
6895
+ }
6896
+ if (opts.onOpenSidebar) {
6897
+ const $openSidebar = createElement(
6898
+ `<span atk-only-admin-show> | <span style="cursor:pointer;">${t("openName", { name: t("ctrlCenter") })}</span></span>`
6899
+ );
6900
+ errEl.appendChild($openSidebar);
6901
+ $openSidebar.onclick = () => opts.onOpenSidebar && opts.onOpenSidebar();
6902
+ }
6903
+ setError(opts.$err, errEl);
6904
+ }
7406
6905
  const ErrorDialog = (ctx) => {
7407
6906
  ctx.on("list-fetch", () => {
7408
6907
  const list = ctx.get("list");
@@ -7430,8 +6929,7 @@ const Loading = (ctx) => {
7430
6929
  };
7431
6930
  const Fetch = (ctx) => {
7432
6931
  ctx.on("list-fetch", (_params) => {
7433
- if (ctx.getData().getLoading())
7434
- return;
6932
+ if (ctx.getData().getLoading()) return;
7435
6933
  ctx.getData().setLoading(true);
7436
6934
  const params = __spreadValues({
7437
6935
  // default params
@@ -7451,8 +6949,7 @@ const Fetch = (ctx) => {
7451
6949
  page_key: ctx.getConf().pageKey,
7452
6950
  site_name: ctx.getConf().site
7453
6951
  };
7454
- if (params.paramsModifier)
7455
- params.paramsModifier(reqParams);
6952
+ if (params.paramsModifier) params.paramsModifier(reqParams);
7456
6953
  ctx.getApi().comments.getComments(__spreadValues(__spreadValues({}, reqParams), ctx.getApi().getUserFields())).then(({ data }) => {
7457
6954
  ctx.getData().setListLastFetch({ params, data });
7458
6955
  ctx.getData().loadComments(data.comments);
@@ -7503,8 +7000,7 @@ const ReachBottom = (ctx) => {
7503
7000
  const list = ctx.get("list");
7504
7001
  const children = list.getCommentsWrapEl().childNodes;
7505
7002
  const $target = children.length > 2 ? children[children.length - 2] : null;
7506
- if (!$target)
7507
- return;
7003
+ if (!$target) return;
7508
7004
  if (!("IntersectionObserver" in window)) {
7509
7005
  console.warn("IntersectionObserver api not supported");
7510
7006
  return;
@@ -7551,11 +7047,9 @@ const ListPlugins = [
7551
7047
  ];
7552
7048
  const Notifies = (ctx) => {
7553
7049
  ctx.on("list-fetch", (params) => {
7554
- if (params.offset !== 0)
7555
- return;
7050
+ if (params.offset !== 0) return;
7556
7051
  const user = ctx.getApi().getUserFields();
7557
- if (!user)
7558
- return;
7052
+ if (!user) return;
7559
7053
  ctx.getApi().notifies.getNotifies(user).then((res) => {
7560
7054
  ctx.getData().updateNotifies(res.data.notifies);
7561
7055
  });
@@ -7572,8 +7066,7 @@ const VersionCheck = (ctx) => {
7572
7066
  function versionCheck(list, feVer, beVer) {
7573
7067
  const comp = versionCompare(feVer, beVer);
7574
7068
  const sameVer = comp === 0;
7575
- if (sameVer)
7576
- return;
7069
+ if (sameVer) return;
7577
7070
  const errEl = createElement(
7578
7071
  `<div class="atk-version-check-notice">${t("updateMsg", {
7579
7072
  name: comp < 0 ? t("frontend") : t("backend")
@@ -7590,7 +7083,7 @@ function versionCheck(list, feVer, beVer) {
7590
7083
  const AdminOnlyElem = (ctx) => {
7591
7084
  const scanApply = () => {
7592
7085
  applyAdminOnlyEls(
7593
- ctx.get("user").getData().isAdmin,
7086
+ ctx.get("user").getData().is_admin,
7594
7087
  getAdminOnlyEls({
7595
7088
  $root: ctx.$root
7596
7089
  })
@@ -7613,20 +7106,16 @@ function getAdminOnlyEls(opts) {
7613
7106
  }
7614
7107
  function applyAdminOnlyEls(isAdmin, els) {
7615
7108
  els.forEach(($item) => {
7616
- if (isAdmin)
7617
- $item.classList.remove("atk-hide");
7618
- else
7619
- $item.classList.add("atk-hide");
7109
+ if (isAdmin) $item.classList.remove("atk-hide");
7110
+ else $item.classList.add("atk-hide");
7620
7111
  });
7621
7112
  }
7622
7113
  let darkModeMedia;
7623
7114
  function updateClassnames($els, darkMode) {
7624
7115
  const DarkModeClassName = "atk-dark-mode";
7625
7116
  $els.forEach(($el) => {
7626
- if (darkMode)
7627
- $el.classList.add(DarkModeClassName);
7628
- else
7629
- $el.classList.remove(DarkModeClassName);
7117
+ if (darkMode) $el.classList.add(DarkModeClassName);
7118
+ else $el.classList.remove(DarkModeClassName);
7630
7119
  });
7631
7120
  }
7632
7121
  const DarkMode = (ctx) => {
@@ -7667,16 +7156,17 @@ const DefaultPlugins = [
7667
7156
  VersionCheck,
7668
7157
  DarkMode
7669
7158
  ];
7670
- const GlobalPlugins = [...DefaultPlugins];
7159
+ const GlobalPlugins = /* @__PURE__ */ new Set([...DefaultPlugins]);
7160
+ const PluginOptions = /* @__PURE__ */ new WeakMap();
7671
7161
  function load(ctx) {
7672
7162
  return __async(this, null, function* () {
7673
7163
  var _a;
7674
- const loadedPlugins = [];
7164
+ const loadedPlugins = /* @__PURE__ */ new Set();
7675
7165
  const loadPlugins = (plugins) => {
7676
7166
  plugins.forEach((plugin) => {
7677
- if (typeof plugin === "function" && !loadedPlugins.includes(plugin)) {
7678
- plugin(ctx);
7679
- loadedPlugins.push(plugin);
7167
+ if (typeof plugin === "function" && !loadedPlugins.has(plugin)) {
7168
+ plugin(ctx, PluginOptions.get(plugin));
7169
+ loadedPlugins.add(plugin);
7680
7170
  }
7681
7171
  });
7682
7172
  };
@@ -7712,8 +7202,8 @@ function load(ctx) {
7712
7202
  }
7713
7203
  function loadNetworkPlugins(scripts, apiBase) {
7714
7204
  return __async(this, null, function* () {
7715
- if (!scripts || !Array.isArray(scripts))
7716
- return [];
7205
+ const networkPlugins = /* @__PURE__ */ new Set();
7206
+ if (!scripts || !Array.isArray(scripts)) return networkPlugins;
7717
7207
  const tasks = [];
7718
7208
  scripts.forEach((url) => {
7719
7209
  if (!/^(http|https):\/\//.test(url))
@@ -7733,7 +7223,10 @@ function loadNetworkPlugins(scripts, apiBase) {
7733
7223
  );
7734
7224
  });
7735
7225
  yield Promise.all(tasks);
7736
- return Object.values(window.ArtalkPlugins || {});
7226
+ Object.values(window.ArtalkPlugins || {}).forEach((plugin) => {
7227
+ if (typeof plugin === "function") networkPlugins.add(plugin);
7228
+ });
7229
+ return networkPlugins;
7737
7230
  });
7738
7231
  }
7739
7232
  function onLoadErr(ctx, err) {
@@ -7751,7 +7244,7 @@ function onLoadErr(ctx, err) {
7751
7244
  errMsg: err.msg || String(err),
7752
7245
  errData: err.data,
7753
7246
  retryFn: () => load(ctx),
7754
- onOpenSidebar: ctx.get("user").getData().isAdmin ? () => ctx.showSidebar({
7247
+ onOpenSidebar: ctx.get("user").getData().is_admin ? () => ctx.showSidebar({
7755
7248
  view: sidebarOpenView
7756
7249
  }) : void 0
7757
7250
  // only show open sidebar button when user is admin
@@ -7818,10 +7311,9 @@ class Artalk {
7818
7311
  return new Artalk(conf);
7819
7312
  }
7820
7313
  /** Use plugin, the plugin will be used when Artalk.init */
7821
- static use(plugin) {
7822
- if (GlobalPlugins.includes(plugin))
7823
- return;
7824
- GlobalPlugins.push(plugin);
7314
+ static use(plugin, options) {
7315
+ GlobalPlugins.add(plugin);
7316
+ PluginOptions.set(plugin, options);
7825
7317
  }
7826
7318
  /** Load count widget */
7827
7319
  static loadCountWidget(c) {
@@ -7831,6 +7323,7 @@ class Artalk {
7831
7323
  siteName: conf.site,
7832
7324
  countEl: conf.countEl,
7833
7325
  pvEl: conf.pvEl,
7326
+ pageKeyAttr: conf.statPageKeyAttr,
7834
7327
  pvAdd: false
7835
7328
  });
7836
7329
  }