dimsum-chat 0.4.7 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  var T = Object.defineProperty;
2
- var A = (r, t, i) => t in r ? T(r, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : r[t] = i;
3
- var b = (r, t, i) => (A(r, typeof t != "symbol" ? t + "" : t, i), i);
4
- const I = {
2
+ var k = (b, t, i) => t in b ? T(b, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : b[t] = i;
3
+ var a = (b, t, i) => (k(b, typeof t != "symbol" ? t + "" : t, i), i);
4
+ const A = {
5
5
  type: "LIVE_OPEN_PLATFORM_DM",
6
6
  content: {
7
7
  cmd: "LIVE_OPEN_PLATFORM_DM",
@@ -14,7 +14,7 @@ const I = {
14
14
  dm_type: 0
15
15
  }
16
16
  }
17
- }, k = {
17
+ }, I = {
18
18
  type: "LIVE_OPEN_PLATFORM_SEND_GIFT",
19
19
  content: {
20
20
  cmd: "LIVE_OPEN_PLATFORM_SEND_GIFT",
@@ -30,17 +30,17 @@ const I = {
30
30
  gift_icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAB+FBMVEX/////UFD/TFD/TVD/TE7/TU//TU//TU//SUv/Skz/Sk3/S03/S07/TE3/TE7/TE//TU7/TU//TVD/Tk//TlD/T1D/T1H/UFH/UFL/UFP/UVL/UVP/UlP/UlT/U1T/U1X/VFX/VFb/VVb/VVf/Vlf/Vlj/V1j/V1n/WFn/WFr/WVr/WVv/Wlv/Wlz/W1z/W13/XF3/XF7/XV7/XV//Xl//XmD/X2D/X2H/YGH/YGL/YWL/YWP/YmP/YmT/Y2T/Y2X/ZGX/ZGb/ZWb/ZWf/Zmf/Zmj/Z2j/Z2n/aGn/aWv/bG7/bW7/bm//b3D/cXL/cnT/dHX/dXb/d3n/eXr/env/e33/fH7/foD/gYP/goP/iIn/iY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Sr62NdeRlRdldDwMr2M7Lx7KzuRFINrdfIpbdoBQGzPZuIvEigRKJnZ2tlRr1/4Wmmz6Gx9JTAAAAAElFTkSuQmCC"
31
31
  }
32
32
  }
33
- }, _ = [I, k], m = class m {
33
+ }, D = [A, I], f = class f {
34
34
  constructor() {
35
- b(this, "AUTH_HOST", "https://dimsum-widget-auth-1301031323.cos.ap-guangzhou.myqcloud.com");
36
- b(this, "WHITELIST_WIDGETS", ["dimsum-bonk-2024-widget", "douyin-bonk-2024-widget"]);
37
- b(this, "MAX_RETRY_COUNT", 3);
38
- b(this, "authenticatedPlatformAndRoomId");
39
- b(this, "isPiracy", !1);
40
- b(this, "retryCount", 0);
35
+ a(this, "AUTH_HOST", "https://dimsum-widget-auth-1301031323.cos.ap-guangzhou.myqcloud.com");
36
+ a(this, "WHITELIST_WIDGETS", ["dimsum-bonk-2024-widget", "douyin-bonk-2024-widget"]);
37
+ a(this, "MAX_RETRY_COUNT", 3);
38
+ a(this, "authenticatedPlatformAndRoomId");
39
+ a(this, "isPiracy", !1);
40
+ a(this, "retryCount", 0);
41
41
  }
42
42
  static getInstance() {
43
- return m.instance || (m.instance = new m()), m.instance;
43
+ return f.instance || (f.instance = new f()), f.instance;
44
44
  }
45
45
  updateWidgetId(t) {
46
46
  return t === "douyin-bonk-2024-widget" ? "dimsum-bonk-2024-widget" : t;
@@ -77,15 +77,15 @@ const I = {
77
77
  this.checkAuthentication(n, s, e);
78
78
  }
79
79
  if (this.isPiracy)
80
- return _[Math.floor(Math.random() * _.length)];
80
+ return D[Math.floor(Math.random() * D.length)];
81
81
  } catch (i) {
82
82
  console.log("DimSumAuth error", i);
83
83
  }
84
84
  return t;
85
85
  }
86
86
  };
87
- b(m, "instance");
88
- let l = m;
87
+ a(f, "instance");
88
+ let _ = f;
89
89
  const B = {
90
90
  type: "LIVE_OPEN_PLATFORM_DM",
91
91
  content: {
@@ -108,7 +108,7 @@ const B = {
108
108
  guard_level: 1
109
109
  }
110
110
  }
111
- }, z = {
111
+ }, w = {
112
112
  connected: B,
113
113
  welcome: M
114
114
  };
@@ -116,34 +116,57 @@ function E() {
116
116
  const t = window.location.pathname.split("/");
117
117
  return t.length > 1 ? t[1] : "unknown base name";
118
118
  }
119
- function L(r) {
120
- let t;
121
- switch (r.type) {
119
+ function S(b, t = {}) {
120
+ const { widgetNickName: i } = t;
121
+ let s;
122
+ switch (b.type) {
122
123
  case "DimSumChatWidgetInfoRequest":
123
- t = {
124
+ s = {
124
125
  type: "DimSumChatWidgetInfoResponse",
125
126
  content: {
126
127
  base: E(),
127
- url: window.location.href
128
+ url: window.location.href,
129
+ ...i ? { widgetNickName: i } : {}
128
130
  }
129
131
  };
130
132
  }
131
- return t;
133
+ return s;
132
134
  }
133
135
  const x = class x {
134
136
  constructor() {
135
- b(this, "webSocket");
136
- b(this, "messageListeners");
137
+ a(this, "webSocket");
138
+ a(this, "messageListeners");
139
+ /**
140
+ * Nickname for this widget instance.
141
+ * Set before connection (via onMessageOptions) or dynamically at runtime.
142
+ * When non-empty, it will be included in DimSumChatWidgetInfoResponse
143
+ * so other components can identify this widget via DimSumChatCallMessageRequest.
144
+ */
145
+ a(this, "widgetNickName", "");
137
146
  this.webSocket = null, this.messageListeners = [];
138
147
  }
148
+ /**
149
+ * 获取唯一的 WebSocket 管理器实例。
150
+ *
151
+ * @returns WebSocketManager 单例
152
+ */
139
153
  static getInstance() {
140
154
  return x.instance || (x.instance = new x()), x.instance;
141
155
  }
156
+ /**
157
+ * 连接到指定 WebSocket 服务器。
158
+ *
159
+ * 仅可调用一次,重复调用将被忽略。
160
+ * 连接断开后自动每 3 秒尝试重连。
161
+ *
162
+ * @param url - WebSocket 服务器 URL
163
+ * @see {@link https://dimsum.chat/zh/api/websocket-manager.html#websocketmanager-connect}
164
+ */
142
165
  connect(t) {
143
166
  this.webSocket || (this.webSocket = new WebSocket(t), this.webSocket.onmessage = this.handleMessage.bind(this), this.webSocket.onopen = () => {
144
167
  console.log("connected"), setTimeout(() => {
145
168
  this.messageListeners.forEach(
146
- (i) => i(JSON.stringify(z.connected))
169
+ (i) => i(JSON.stringify(w.connected))
147
170
  );
148
171
  }, 100);
149
172
  }, this.webSocket.onclose = () => {
@@ -156,39 +179,82 @@ const x = class x {
156
179
  var n;
157
180
  const i = t.data;
158
181
  this.messageListeners.forEach((p) => p(i));
159
- const s = JSON.parse(i), e = L(s);
182
+ const s = JSON.parse(i), e = S(s, {
183
+ widgetNickName: this.widgetNickName
184
+ });
160
185
  e && ((n = this.webSocket) == null || n.send(JSON.stringify(e)));
161
186
  }
187
+ /**
188
+ * 注册消息监听器。
189
+ *
190
+ * 收到 WebSocket 消息后以字符串形式传递给监听器。
191
+ * 添加监听器时若连接已建立,会自动推送一条欢迎消息。
192
+ *
193
+ * @param listener - 消息回调,接收原始 JSON 字符串
194
+ * @see {@link https://dimsum.chat/zh/api/websocket-manager.html#websocketmanager-addmessagelistener}
195
+ */
162
196
  addMessageListener(t) {
163
197
  this.messageListeners.push(t), setTimeout(() => {
164
- t(JSON.stringify(z.welcome));
198
+ t(JSON.stringify(w.welcome));
165
199
  }, 100);
166
200
  }
201
+ /**
202
+ * 移除已注册的消息监听器。
203
+ *
204
+ * @param listener - 之前通过 addMessageListener 注册的回调
205
+ */
167
206
  removeMessageListener(t) {
168
207
  const i = this.messageListeners.indexOf(t);
169
208
  i !== -1 && this.messageListeners.splice(i, 1);
170
209
  }
210
+ /**
211
+ * 通过 WebSocket 主动发送消息到主程序。
212
+ *
213
+ * 连接未就绪时静默失败,不会抛出异常。
214
+ *
215
+ * @param message - 要发送的消息对象,会自动 JSON.stringify
216
+ * @returns 发送成功返回 true,连接未就绪返回 false
217
+ *
218
+ * @example
219
+ * ```ts
220
+ * import { WebSocketManager } from 'dimsum-chat'
221
+ *
222
+ * const ws = WebSocketManager.getInstance()
223
+ * ws.send({
224
+ * type: 'DimSumChatCallMessageRequest',
225
+ * content: {
226
+ * targetNickName: 'another-widget',
227
+ * requestData: { action: 'refresh' }
228
+ * }
229
+ * })
230
+ * ```
231
+ */
232
+ send(t) {
233
+ var i;
234
+ return ((i = this.webSocket) == null ? void 0 : i.readyState) === WebSocket.OPEN ? (this.webSocket.send(JSON.stringify(t)), !0) : !1;
235
+ }
171
236
  };
172
- b(x, "instance");
173
- let j = x;
174
- function S() {
175
- const r = new URL(window.location.href), t = r.protocol === "https:" ? "wss:" : "ws:", i = r.host;
237
+ a(x, "instance");
238
+ let z = x;
239
+ function L() {
240
+ const b = new URL(window.location.href), t = b.protocol === "https:" ? "wss:" : "ws:", i = b.host;
176
241
  return `${t}//${i}/websocket`;
177
242
  }
178
- function N(r) {
243
+ function P(b) {
179
244
  const t = new URL(window.location.href), i = t.protocol, s = t.host;
180
- return `${i}//${s}/bface/${r}`;
245
+ return `${i}//${s}/bface/${b}`;
181
246
  }
182
- function U(r, t = {}) {
247
+ function U(b, t = {}) {
183
248
  const {
184
- customWsServer: i = S()
185
- } = t, s = l.getInstance(), e = j.getInstance();
186
- e.connect(i), e.addMessageListener((n) => {
187
- const p = JSON.parse(n), d = s.passMessage(p), f = new v(d);
188
- r(d, f);
249
+ customWsServer: i = L(),
250
+ widgetNickName: s = ""
251
+ } = t, e = _.getInstance(), n = z.getInstance();
252
+ n.widgetNickName = s, n.connect(i), n.addMessageListener((p) => {
253
+ const h = JSON.parse(p), m = e.passMessage(h), o = new C(m);
254
+ b(m, o);
189
255
  });
190
256
  }
191
- const C = [
257
+ const l = [
192
258
  ["[过年牛]", "https://p3-pc-sign.douyinpic.com/obj/tos-cn-i-tsj2vxp0zn/3bb984085d52480ca846fa8f9a1782f6?x-expires=1949886000&x-signature=d8vUokaGkWD%2B4sAHNTLJquCrHrs%3D"],
193
259
  ["[元宝]", "https://p3-pc-sign.douyinpic.com/obj/tos-cn-i-tsj2vxp0zn/5f8ac1b1ddd347c4be34b81b496fcc45?x-expires=2023614000&x-signature=UT%2F8fnFld4xuvjj2bttu6fh76lI%3D"],
194
260
  ["[鞭炮]", "https://p3-pc-sign.douyinpic.com/obj/tos-cn-i-tsj2vxp0zn/02f8ee9536de4c6595171584e2322f0f?x-expires=2023614000&x-signature=Aa8eXgZqb0bx0QNeLONQVgNUbLI%3D"],
@@ -449,7 +515,7 @@ const C = [
449
515
  ["[糖葫芦]", "https://p3-pc-sign.douyinpic.com/obj/tos-cn-i-tsj2vxp0zn/d4aa8a0ff46a445e861ad8fb78c07140?x-expires=2023614000&x-signature=FvN4ytTGjC7Mww8KX4BRIg9wcTE%3D"],
450
516
  ["[虎头]", "https://p3-pc-sign.douyinpic.com/obj/tos-cn-i-tsj2vxp0zn/7569ffeaa3894b8b8ea843c0e5a05f63?x-expires=2023614000&x-signature=m%2Bi3d034xBQkuBqx4xrvzru5q6A%3D"],
451
517
  ["[iloveyou]", "https://p3-pc-sign.douyinpic.com/obj/tos-cn-i-tsj2vxp0zn/798bcfd9811f4fcd97df92af06c87a0e?x-expires=2023614000&x-signature=DuK8xhX7glgLx44H53PrhM32D44%3D"]
452
- ], D = [
518
+ ], j = [
453
519
  ["[dog]", "http://i0.hdslb.com/bfs/live/4428c84e694fbf4e0ef6c06e958d9352c3582740.png"],
454
520
  ["[花]", "http://i0.hdslb.com/bfs/live/7dd2ef03e13998575e4d8a803c6e12909f94e72b.png"],
455
521
  ["[妙]", "http://i0.hdslb.com/bfs/live/08f735d950a0fba267dda140673c9ab2edf6410d.png"],
@@ -532,7 +598,7 @@ const C = [
532
598
  ["[抱拳]", "http://i0.hdslb.com/bfs/live/3f170894dd08827ee293afcb5a3d2b60aecdb5b1.png"],
533
599
  ["[给力]", "http://i0.hdslb.com/bfs/live/d1ba5f4c54332a21ed2ca0dcecaedd2add587839.png"],
534
600
  ["[耶]", "http://i0.hdslb.com/bfs/live/eb2d84ba623e2335a48f73fb5bef87bcf53c1239.png"]
535
- ], w = [
601
+ ], v = [
536
602
  ["[666]", "https://ali2.a.yximgs.com/bs2/emotion/1704763447505third_party_s1296657489.png"],
537
603
  ["[奸笑]", "https://ali2.a.yximgs.com/bs2/emotion/1704776059816third_party_s1296748052.png"],
538
604
  ["[捂脸]", "https://bd.a.yximgs.com/bs2/emotion/1704776021202third_party_s1296747457.png"],
@@ -740,11 +806,13 @@ const C = [
740
806
  ["[抱拳]", "https://bd.a.yximgs.com/bs2/emotion/1704790113221third_party_s1296853443.png"],
741
807
  ["[早上好]", "https://ali2.a.yximgs.com/bs2/emotion/1704790167344third_party_s1296853922.png"],
742
808
  ["[胡思乱想]", "https://ali2.a.yximgs.com/bs2/emotion/1704790657229third_party_s1296858542.png"]
743
- ], h = class h {
809
+ ], r = class r {
744
810
  constructor(t) {
745
- b(this, "rawType");
746
- b(this, "rawContent");
747
- b(this, "_cachedValues", {});
811
+ /** 原始消息类型。 */
812
+ a(this, "rawType");
813
+ /** 原始消息内容(字符串已自动反序列化为对象)。 */
814
+ a(this, "rawContent");
815
+ a(this, "_cachedValues", {});
748
816
  this.rawType = t.type;
749
817
  try {
750
818
  typeof t.content == "string" ? this.rawContent = JSON.parse(t.content) : this.rawContent = t.content;
@@ -916,6 +984,7 @@ const C = [
916
984
  if (this.platform === "chzzk" && "uid" in this.rawContent)
917
985
  return this.rawContent.uid;
918
986
  }
987
+ /** 粉丝团/守护团等级。 */
919
988
  get clubLevel() {
920
989
  if (this.platform === "bilibili" || this.platform === "openblive") {
921
990
  if (this.rawType === "DANMU_MSG")
@@ -937,6 +1006,7 @@ const C = [
937
1006
  if (this.platform === "douyin" && "user" in this.rawContent && this.rawContent.user.fansClub !== null)
938
1007
  return this.rawContent.user.fansClub.data.level;
939
1008
  }
1009
+ /** 粉丝团/守护团名称。 */
940
1010
  get clubName() {
941
1011
  var t, i;
942
1012
  if (this.platform === "bilibili" || this.platform === "openblive") {
@@ -959,6 +1029,7 @@ const C = [
959
1029
  if (this.platform === "douyin" && "user" in this.rawContent)
960
1030
  return (i = (t = this.rawContent.user.fansClub) == null ? void 0 : t.data) == null ? void 0 : i.clubName;
961
1031
  }
1032
+ /** AcFun 守护团所属主播的用户 ID。 */
962
1033
  get acfunClubUid() {
963
1034
  if (this.platform === "acfun") {
964
1035
  let t;
@@ -978,6 +1049,13 @@ const C = [
978
1049
  return "6" in t && t[6].uri.includes("subscribe_year") || "5" in t && t[5].uri.includes("subscribe_year") ? 2 : "3" in t || "5" in t ? 1 : 0;
979
1050
  }
980
1051
  }
1052
+ /**
1053
+ * 用户头像 URL。
1054
+ *
1055
+ * B 站头像存在跨域限制,建议配合 getBfaceURL() 使用。
1056
+ *
1057
+ * @see {@link https://dimsum.chat/zh/api/parser.html#parser-avatar}
1058
+ */
981
1059
  get avatar() {
982
1060
  var t, i;
983
1061
  if ((this.platform === "bilibili" || this.platform === "openblive") && "data" in this.rawContent) {
@@ -1005,6 +1083,13 @@ const C = [
1005
1083
  if (this.platform === "kuaishou" && "user" in this.rawContent && "headUrl" in this.rawContent.user && this.rawContent.user.headUrl)
1006
1084
  return this.rawContent.user.headUrl;
1007
1085
  }
1086
+ /**
1087
+ * 弹幕聊天内容。
1088
+ *
1089
+ * 当 type 为 comment 或 superchat 时均有值。
1090
+ *
1091
+ * @see {@link https://dimsum.chat/zh/api/parser.html#parser-comment}
1092
+ */
1008
1093
  get comment() {
1009
1094
  const t = {
1010
1095
  acfun: () => this.rawContent.content,
@@ -1030,16 +1115,16 @@ const C = [
1030
1115
  emotStyle: e = "",
1031
1116
  emotClass: n = "",
1032
1117
  acfunCustomStickers: p = [],
1033
- acfunCustomHtmlBuilder: d
1034
- } = t, f = {
1118
+ acfunCustomHtmlBuilder: h
1119
+ } = t, m = {
1035
1120
  acfun: () => {
1036
1121
  let o = g(this.rawContent.content);
1037
1122
  if ("emotionUrl" in this.rawContent && this.rawContent.emotionUrl)
1038
1123
  return `<img src="${this.rawContent.emotionUrl}" alt="" style="${i}" class="${s}">`;
1039
1124
  let c;
1040
- return p.forEach((a) => {
1041
- o.includes(a.keyWord) && (c = a.path);
1042
- }), c != null ? d != null ? d(c, o) : `<div style="display:flex;">
1125
+ return p.forEach((d) => {
1126
+ o.includes(d.keyWord) && (c = d.path);
1127
+ }), c != null ? h != null ? h(c, o) : `<div style="display:flex;">
1043
1128
  <img src="${c}" alt="" style="${i}" class="${s}">
1044
1129
  <div style="flex-grow:1;">${o}</div>
1045
1130
  </div>` : g(this.rawContent.content);
@@ -1048,51 +1133,51 @@ const C = [
1048
1133
  if (typeof this.rawContent.info[0][13] == "object")
1049
1134
  return `<img src="${this.rawContent.info[0][13].url}" alt="" style="${i}" class="${s}">`;
1050
1135
  const o = this.rawContent.info[0][15].extra, c = JSON.parse(o);
1051
- let a = g(c.content);
1136
+ let d = g(c.content);
1052
1137
  const u = c.emots;
1053
1138
  for (let y in u) {
1054
1139
  const F = new RegExp(`\\${y}`, "g");
1055
- a = a.replace(F, `<img src="${u[y].url}" alt="" style="${e}" class="${n}">`);
1140
+ d = d.replace(F, `<img src="${u[y].url}" alt="" style="${e}" class="${n}">`);
1056
1141
  }
1057
- return a;
1142
+ return d;
1058
1143
  },
1059
1144
  openblive: () => {
1060
1145
  if (this.rawContent.data.emoji_img_url)
1061
1146
  return `<img src="${this.rawContent.data.emoji_img_url}" alt="" style="${i}" class="${s}">`;
1062
1147
  let o = g(this.rawContent.data.msg);
1063
- return D.forEach((c) => {
1064
- const a = new RegExp(`\\${c[0]}`, "g");
1065
- o = o.replace(a, `<img src="${c[1]}" alt="" style="${e}" class="${n}">`);
1148
+ return j.forEach((c) => {
1149
+ const d = new RegExp(`\\${c[0]}`, "g");
1150
+ o = o.replace(d, `<img src="${c[1]}" alt="" style="${e}" class="${n}">`);
1066
1151
  }), o;
1067
1152
  },
1068
1153
  douyin: () => {
1069
1154
  let o = g(this.rawContent.content);
1070
- return C.forEach((c) => {
1071
- const a = new RegExp(`\\${c[0]}`, "g");
1072
- o = o.replace(a, `<img src="${c[1]}" alt="" style="${e}" class="${n}">`);
1155
+ return l.forEach((c) => {
1156
+ const d = new RegExp(`\\${c[0]}`, "g");
1157
+ o = o.replace(d, `<img src="${c[1]}" alt="" style="${e}" class="${n}">`);
1073
1158
  }), o;
1074
1159
  },
1075
1160
  kuaishou: () => {
1076
1161
  let o = g(this.rawContent.content);
1077
- return w.forEach((c) => {
1078
- const a = new RegExp(`\\${c[0]}`, "g");
1079
- o = o.replace(a, `<img src="${c[1]}" alt="" style="${e}" class="${n}">`);
1162
+ return v.forEach((c) => {
1163
+ const d = new RegExp(`\\${c[0]}`, "g");
1164
+ o = o.replace(d, `<img src="${c[1]}" alt="" style="${e}" class="${n}">`);
1080
1165
  }), o;
1081
1166
  },
1082
1167
  chzzk: () => {
1083
1168
  let o = g(this.rawContent.msg);
1084
1169
  if (this.rawContent.extras) {
1085
- const a = JSON.parse(this.rawContent.extras).emojis || {};
1086
- for (let u in a) {
1170
+ const d = JSON.parse(this.rawContent.extras).emojis || {};
1171
+ for (let u in d) {
1087
1172
  const y = new RegExp(`\\{:${u}:}`, "g");
1088
- o = o.replace(y, `<img src="${a[u]}" alt="" style="${e}" class="${n}">`);
1173
+ o = o.replace(y, `<img src="${d[u]}" alt="" style="${e}" class="${n}">`);
1089
1174
  }
1090
1175
  return o;
1091
1176
  }
1092
1177
  }
1093
1178
  };
1094
- if (this.type === "comment" && f[this.platform])
1095
- return f[this.platform]();
1179
+ if (this.type === "comment" && m[this.platform])
1180
+ return m[this.platform]();
1096
1181
  }
1097
1182
  /**
1098
1183
  * Custom comment content builder.
@@ -1110,31 +1195,31 @@ const C = [
1110
1195
  bilibili: () => {
1111
1196
  let s, e = [];
1112
1197
  typeof this.rawContent.info[0][13] == "object" && (s = this.rawContent.info[0][13].url);
1113
- const n = this.rawContent.info[0][15].extra, p = JSON.parse(n), d = g(p.content), f = p.emots;
1114
- for (let o in f)
1115
- e.push([o, f[o].url]);
1116
- return t(d, s, e);
1198
+ const n = this.rawContent.info[0][15].extra, p = JSON.parse(n), h = g(p.content), m = p.emots;
1199
+ for (let o in m)
1200
+ e.push([o, m[o].url]);
1201
+ return t(h, s, e);
1117
1202
  },
1118
1203
  openblive: () => {
1119
1204
  let s;
1120
1205
  this.rawContent.data.emoji_img_url && (s = this.rawContent.data.emoji_img_url);
1121
1206
  const e = g(this.rawContent.data.msg);
1122
- return t(e, s, D);
1207
+ return t(e, s, j);
1123
1208
  },
1124
1209
  douyin: () => {
1125
1210
  const s = g(this.rawContent.content);
1126
- return t(s, void 0, C);
1211
+ return t(s, void 0, l);
1127
1212
  },
1128
1213
  kuaishou: () => {
1129
1214
  const s = g(this.rawContent.content);
1130
- return t(s, void 0, w);
1215
+ return t(s, void 0, v);
1131
1216
  },
1132
1217
  chzzk: () => {
1133
1218
  let s = g(this.rawContent.msg), e = [];
1134
1219
  if (this.rawContent.extras) {
1135
1220
  const p = JSON.parse(this.rawContent.extras).emojis || {};
1136
- for (let d in p)
1137
- e.push([`{:${d}:}`, p[d]]);
1221
+ for (let h in p)
1222
+ e.push([`{:${h}:}`, p[h]]);
1138
1223
  }
1139
1224
  return t(s, void 0, e);
1140
1225
  }
@@ -1143,8 +1228,14 @@ const C = [
1143
1228
  return i[this.platform]();
1144
1229
  }
1145
1230
  /**
1146
- * 大航海等级:0-无 3-舰长 2-提督 1-总督
1147
- * 若type为guard,则为购买的大航海等级
1231
+ * 大航海等级。
1232
+ *
1233
+ * 0=无,3=舰长,2=提督,1=总督。
1234
+ * 当 type 为 guard 时,表示本次购买的大航海等级;
1235
+ * 其他消息类型中表示该用户当前的大航海等级。
1236
+ * Chzzk 平台的 Subscription 事件也支持此属性。
1237
+ *
1238
+ * @see {@link https://dimsum.chat/zh/api/parser.html#parser-guardlevel}
1148
1239
  */
1149
1240
  get guardLevel() {
1150
1241
  if (this.platform === "bilibili" || this.platform === "openblive") {
@@ -1162,6 +1253,13 @@ const C = [
1162
1253
  return t && t <= 3 && t >= 1 ? 4 - t : 0;
1163
1254
  }
1164
1255
  }
1256
+ /**
1257
+ * 大航海购买数量。
1258
+ *
1259
+ * B 站表示购买月数,Chzzk 表示订阅月数。
1260
+ *
1261
+ * @see {@link https://dimsum.chat/zh/api/parser.html#parser-guardnum}
1262
+ */
1165
1263
  get guardNum() {
1166
1264
  if (this.platform === "bilibili" || this.platform === "openblive") {
1167
1265
  if (this.rawType === "GUARD_BUY")
@@ -1172,19 +1270,27 @@ const C = [
1172
1270
  if (this.platform === "chzzk")
1173
1271
  return this.chzzkTierMonth;
1174
1272
  }
1273
+ /**
1274
+ * 大航海购买价格(CNY)。
1275
+ *
1276
+ * @see {@link https://dimsum.chat/zh/api/parser.html#parser-guardprice}
1277
+ */
1175
1278
  // 可能是单价(未确认),舰长价格198实际可能为138
1176
1279
  get guardPrice() {
1177
1280
  if ((this.platform === "bilibili" || this.platform === "openblive") && "data" in this.rawContent && "price" in this.rawContent.data)
1178
1281
  return this.rawContent.data.price / 1e3;
1179
1282
  }
1283
+ /** Chzzk 订阅等级(1-3)。 */
1180
1284
  get chzzkTier() {
1181
1285
  if (this.platform === "chzzk" && this.rawType === "ChzzkSubscriptionMessage" && this.rawContent.extras)
1182
1286
  return JSON.parse(this.rawContent.extras).tierNo;
1183
1287
  }
1288
+ /** Chzzk 订阅月数。 */
1184
1289
  get chzzkTierMonth() {
1185
1290
  if (this.platform === "chzzk" && this.rawType === "ChzzkSubscriptionMessage" && this.rawContent.extras)
1186
1291
  return JSON.parse(this.rawContent.extras).month;
1187
1292
  }
1293
+ /** 礼物名称。 */
1188
1294
  get giftName() {
1189
1295
  const t = {
1190
1296
  acfun: () => this.rawContent.giftInfo.name,
@@ -1196,6 +1302,13 @@ const C = [
1196
1302
  if (this.type === "gift" && t[this.platform])
1197
1303
  return t[this.platform]();
1198
1304
  }
1305
+ /**
1306
+ * 礼物数量。
1307
+ *
1308
+ * 抖音和快手已由 SDK 内部处理连击去重,每次返回增量值。
1309
+ *
1310
+ * @see {@link https://dimsum.chat/zh/api/parser.html#parser-giftnum}
1311
+ */
1199
1312
  get giftNum() {
1200
1313
  const t = {
1201
1314
  acfun: () => this.rawContent.gift.batchSize,
@@ -1203,21 +1316,28 @@ const C = [
1203
1316
  openblive: () => this.rawContent.data.gift_num,
1204
1317
  douyin: () => {
1205
1318
  if (this.rawContent.sendType === 4) {
1206
- const s = this.rawContent.comboCount, e = this.rawContent.groupId, n = this.rawContent.giftId, p = this.uid, d = `${e}_${p}_${n}`;
1207
- let f = 0;
1208
- return h.douyinGiftGroup.has(d) && (f = h.douyinGiftGroup.get(d) ?? 0), h.douyinGiftGroup.set(d, s), h.douyinGiftGroup.size > 1024 && h.douyinGiftGroup.delete(h.douyinGiftGroup.keys().next().value ?? ""), s - f;
1319
+ const s = this.rawContent.comboCount, e = this.rawContent.groupId, n = this.rawContent.giftId, p = this.uid, h = `${e}_${p}_${n}`;
1320
+ let m = 0;
1321
+ return r.douyinGiftGroup.has(h) && (m = r.douyinGiftGroup.get(h) ?? 0), r.douyinGiftGroup.set(h, s), r.douyinGiftGroup.size > 1024 && r.douyinGiftGroup.delete(r.douyinGiftGroup.keys().next().value ?? ""), s - m;
1209
1322
  }
1210
1323
  return this.rawContent.groupCount;
1211
1324
  },
1212
1325
  kuaishou: () => {
1213
1326
  const s = this.rawContent.batchSize * this.rawContent.comboCount, e = this.rawContent.mergeKey;
1214
1327
  let n = 0;
1215
- return h.kuaishouGiftGroup.has(e) && (n = h.kuaishouGiftGroup.get(e) ?? 0), h.kuaishouGiftGroup.set(e, s), h.kuaishouGiftGroup.size > 1024 && h.kuaishouGiftGroup.delete(h.kuaishouGiftGroup.keys().next().value ?? ""), s - n;
1328
+ return r.kuaishouGiftGroup.has(e) && (n = r.kuaishouGiftGroup.get(e) ?? 0), r.kuaishouGiftGroup.set(e, s), r.kuaishouGiftGroup.size > 1024 && r.kuaishouGiftGroup.delete(r.kuaishouGiftGroup.keys().next().value ?? ""), s - n;
1216
1329
  }
1217
1330
  };
1218
1331
  if (this.type === "gift" && t[this.platform])
1219
1332
  return t[this.platform]();
1220
1333
  }
1334
+ /**
1335
+ * 单个礼物价格(CNY)。
1336
+ *
1337
+ * 免费礼物(如 B 站银瓜子)返回 0。
1338
+ *
1339
+ * @see {@link https://dimsum.chat/zh/api/parser.html#parser-giftunitprice}
1340
+ */
1221
1341
  get giftUnitPrice() {
1222
1342
  const t = {
1223
1343
  acfun: () => this.rawContent.gift.giftId !== 1 ? this.rawContent.giftInfo.value / 10 : 0,
@@ -1229,10 +1349,18 @@ const C = [
1229
1349
  if (this.type === "gift" && t[this.platform])
1230
1350
  return t[this.platform]();
1231
1351
  }
1352
+ /**
1353
+ * 礼物总价值(CNY)。
1354
+ *
1355
+ * 等价于 giftNum × giftUnitPrice。
1356
+ *
1357
+ * @see {@link https://dimsum.chat/zh/api/parser.html#parser-gifttotalprice}
1358
+ */
1232
1359
  get giftTotalPrice() {
1233
1360
  if (this.giftNum !== void 0 && this.giftUnitPrice !== void 0)
1234
1361
  return this.giftNum * this.giftUnitPrice;
1235
1362
  }
1363
+ /** 礼物图片 URL。 */
1236
1364
  get giftImage() {
1237
1365
  return this.type !== "gift" ? void 0 : {
1238
1366
  acfun: () => this.rawContent.giftInfo.pic,
@@ -1246,6 +1374,7 @@ const C = [
1246
1374
  kuaishou: () => this.rawContent.giftInfo.picUrl[0].url
1247
1375
  }[this.platform]();
1248
1376
  }
1377
+ /** 超级聊天评论内容。 */
1249
1378
  get superChatComment() {
1250
1379
  const t = {
1251
1380
  bilibili: () => this.rawContent.data.message,
@@ -1255,6 +1384,13 @@ const C = [
1255
1384
  if (this.type === "superchat" && t[this.platform])
1256
1385
  return t[this.platform]();
1257
1386
  }
1387
+ /**
1388
+ * 超级聊天价格。
1389
+ *
1390
+ * B 站与 OpenBLive 为人民币(元),Chzzk 为韩元(KRW)。
1391
+ *
1392
+ * @see {@link https://dimsum.chat/zh/api/parser.html#parser-superchatprice}
1393
+ */
1258
1394
  get superChatPrice() {
1259
1395
  const t = {
1260
1396
  bilibili: () => this.rawContent.data.price,
@@ -1267,6 +1403,18 @@ const C = [
1267
1403
  if (this.type === "superchat" && t[this.platform])
1268
1404
  return t[this.platform]();
1269
1405
  }
1406
+ /**
1407
+ * 广义价格,根据消息类型自动选择对应价格属性:
1408
+ *
1409
+ * | 消息类型 | 对应属性 |
1410
+ * |-----------|-----------------|
1411
+ * | gift | giftTotalPrice |
1412
+ * | superchat | superChatPrice |
1413
+ * | guard | guardPrice |
1414
+ * | 其它 | undefined |
1415
+ *
1416
+ * @see {@link https://dimsum.chat/zh/api/parser.html#parser-price}
1417
+ */
1270
1418
  get price() {
1271
1419
  if (this.type === "gift")
1272
1420
  return this.giftTotalPrice;
@@ -1275,6 +1423,15 @@ const C = [
1275
1423
  if (this.type === "guard")
1276
1424
  return this.guardPrice;
1277
1425
  }
1426
+ /**
1427
+ * 获取用户的抽象化分级,用于渲染用户等级标识。
1428
+ *
1429
+ * 不同平台的映射规则见官网文档。
1430
+ *
1431
+ * @param options - 各平台分段阈值配置,见 {@link abstractLevelOptions}
1432
+ * @returns 0-3 等级,undefined 表示不支持
1433
+ * @see {@link https://dimsum.chat/zh/api/parser.html#parser-getabstractlevel}
1434
+ */
1278
1435
  getAbstractLevel(t = {}) {
1279
1436
  const {
1280
1437
  douyinSteps: i = [7, 11, 15],
@@ -1284,25 +1441,43 @@ const C = [
1284
1441
  } = t, p = (o) => {
1285
1442
  if (this.clubLevel === void 0)
1286
1443
  return 0;
1287
- const c = o.findIndex((a) => this.clubLevel <= a);
1444
+ const c = o.findIndex((d) => this.clubLevel <= d);
1288
1445
  return c !== -1 ? c : o.length;
1289
- }, d = () => this.guardLevel && this.guardLevel > 0 ? 4 - this.guardLevel : 0, f = {
1446
+ }, h = () => this.guardLevel && this.guardLevel > 0 ? 4 - this.guardLevel : 0, m = {
1290
1447
  douyin: () => p(i),
1291
1448
  kuaishou: () => p(s),
1292
1449
  acfun: () => n > 0 && this.acfunClubUid !== n ? 0 : p(e),
1293
- bilibili: () => d(),
1294
- openblive: () => d(),
1450
+ bilibili: () => h(),
1451
+ openblive: () => h(),
1295
1452
  chzzk: () => this.chzzkTier ?? 0
1296
1453
  };
1297
- if (f[this.platform])
1298
- return f[this.platform]();
1454
+ if (m[this.platform])
1455
+ return m[this.platform]();
1299
1456
  }
1300
1457
  };
1301
- // groupId_userId_giftId : comboCount
1302
- b(h, "douyinGiftGroup", /* @__PURE__ */ new Map()), b(h, "kuaishouGiftGroup", /* @__PURE__ */ new Map());
1303
- let v = h;
1304
- function g(r) {
1305
- return r.replace(/[&<>"']/g, function(t) {
1458
+ /**
1459
+ * Douyin emoji mappings. Accessible directly without going through CommentBuilder.
1460
+ *
1461
+ * @example
1462
+ * Parser.DouyinEmots.forEach(([emot, url]) => console.log(emot, url));
1463
+ */
1464
+ a(r, "DouyinEmots", l), /**
1465
+ * Bilibili emoji mappings (also used by OpenBLive).
1466
+ *
1467
+ * @example
1468
+ * Parser.BilibiliEmots.forEach(([emot, url]) => console.log(emot, url));
1469
+ */
1470
+ a(r, "BilibiliEmots", j), /**
1471
+ * Kuaishou emoji mappings.
1472
+ *
1473
+ * @example
1474
+ * Parser.KuaishouEmots.forEach(([emot, url]) => console.log(emot, url));
1475
+ */
1476
+ a(r, "KuaishouEmots", v), // groupId_userId_giftId : comboCount
1477
+ a(r, "douyinGiftGroup", /* @__PURE__ */ new Map()), a(r, "kuaishouGiftGroup", /* @__PURE__ */ new Map());
1478
+ let C = r;
1479
+ function g(b) {
1480
+ return b.replace(/[&<>"']/g, function(t) {
1306
1481
  switch (t) {
1307
1482
  case "&":
1308
1483
  return "&amp;";
@@ -1320,9 +1495,9 @@ function g(r) {
1320
1495
  });
1321
1496
  }
1322
1497
  export {
1323
- v as Parser,
1324
- j as WebSocketManager,
1325
- N as getBfaceURL,
1326
- S as getWebSocketURL,
1498
+ C as Parser,
1499
+ z as WebSocketManager,
1500
+ P as getBfaceURL,
1501
+ L as getWebSocketURL,
1327
1502
  U as onMessage
1328
1503
  };