@xpadev-net/niconicomments 0.2.18 → 0.2.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- niconicomments.js v0.2.18
2
+ niconicomments.js v0.2.21
3
3
  (c) 2021 xpadev-net https://xpadev.net
4
4
  Released under the MIT License.
5
5
  */
@@ -25,21 +25,385 @@
25
25
  return _assign.apply(this, arguments);
26
26
  };
27
27
 
28
+ var typeGuard = {
29
+ formatted: {
30
+ comment: function (i) {
31
+ return typeVerify(i, ["id", "vpos", "content", "date", "date_usec", "owner", "premium", "mail", "user_id", "layer"]);
32
+ },
33
+ comments: function (i) {
34
+ if (typeof i !== "object")
35
+ return false;
36
+ for (var _i = 0, i_1 = i; _i < i_1.length; _i++) {
37
+ var item = i_1[_i];
38
+ if (!typeGuard.formatted.comment(item))
39
+ return false;
40
+ }
41
+ return true;
42
+ },
43
+ legacyComment: function (i) {
44
+ return typeVerify(i, ["id", "vpos", "content", "date", "owner", "premium", "mail"]);
45
+ },
46
+ legacyComments: function (i) {
47
+ if (typeof i !== "object")
48
+ return false;
49
+ for (var _i = 0, i_2 = i; _i < i_2.length; _i++) {
50
+ var item = i_2[_i];
51
+ if (!typeGuard.formatted.legacyComment(item))
52
+ return false;
53
+ }
54
+ return true;
55
+ }
56
+ },
57
+ legacy: {
58
+ rawApiResponses: function (i) {
59
+ if (typeof i !== "object")
60
+ return false;
61
+ for (var _i = 0, i_3 = i; _i < i_3.length; _i++) {
62
+ var itemWrapper = i_3[_i];
63
+ for (var _a = 0, itemWrapper_1 = itemWrapper; _a < itemWrapper_1.length; _a++) {
64
+ var item = itemWrapper_1[_a];
65
+ if (!(item.chat && typeGuard.legacy.apiChat(item) || typeGuard.legacy.apiGlobalNumRes(item) || typeGuard.legacy.apiLeaf(item) || typeGuard.legacy.apiPing(item) || typeGuard.legacy.apiThread(item))) {
66
+ return false;
67
+ }
68
+ }
69
+ }
70
+ return true;
71
+ },
72
+ apiChat: function (i) {
73
+ return typeVerify(i, ["anonymity", "content", "date", "date_usec", "no", "thread", "vpos"]);
74
+ },
75
+ apiGlobalNumRes: function (i) {
76
+ return typeVerify(i, ["num_res", "thread"]);
77
+ },
78
+ apiLeaf: function (i) {
79
+ return typeVerify(i, ["count", "thread"]);
80
+ },
81
+ apiPing: function (i) {
82
+ return typeVerify(i, ["content"]);
83
+ },
84
+ apiThread: function (i) {
85
+ return typeVerify(i, ["resultcode", "revision", "server_time", "thread", "ticket"]);
86
+ },
87
+ },
88
+ niconicome: {
89
+ xmlDocument: function (i) {
90
+ if (!i.documentElement || i.documentElement.nodeName !== "packet")
91
+ return false;
92
+ if (!i.documentElement.children)
93
+ return false;
94
+ for (var index in Array.from(i.documentElement.children)) {
95
+ var value = i.documentElement.children[index];
96
+ if (index === "0") {
97
+ if (value.nodeName !== "thread" || !typeAttributeVerify(value, ["resultcode", "thread", "server_time", "last_res", "revision"]))
98
+ return false;
99
+ }
100
+ else {
101
+ if (value.nodeName !== "chat" || !typeAttributeVerify(value, ["thread", "no", "vpos", "date", "date_usec", "anonymity", "user_id", "mail", "leaf", "premium", "score"]))
102
+ return false;
103
+ }
104
+ }
105
+ return true;
106
+ }
107
+ },
108
+ legacyOwner: {
109
+ comments: function (i) {
110
+ var lists = i.split("\n");
111
+ for (var list in lists) {
112
+ if (list.split(":").length < 3) {
113
+ return false;
114
+ }
115
+ }
116
+ return true;
117
+ }
118
+ },
119
+ owner: {
120
+ comment: function (i) {
121
+ return typeVerify(i, ["time", "command", "comment"]);
122
+ },
123
+ comments: function (i) {
124
+ if (typeof i !== "object")
125
+ return false;
126
+ for (var _i = 0, i_4 = i; _i < i_4.length; _i++) {
127
+ var item = i_4[_i];
128
+ if (!typeGuard.owner.comment(item))
129
+ return false;
130
+ }
131
+ return true;
132
+ }
133
+ },
134
+ v1: {
135
+ comment: function (i) {
136
+ return typeVerify(i, ["id", "no", "vposMs", "body", "commands", "userId", "isPremium", "score", "postedAt", "nicoruCount", "nicoruId", "source", "isMyPost"]);
137
+ },
138
+ thread: function (i) {
139
+ if (!typeVerify(i, ["id", "fork", "commentCount", "comments"]))
140
+ return false;
141
+ for (var _i = 0, _a = i.comments; _i < _a.length; _i++) {
142
+ var item = _a[_i];
143
+ if (!typeGuard.v1.comment(item))
144
+ return false;
145
+ }
146
+ return true;
147
+ },
148
+ threads: function (i) {
149
+ if (typeof i !== "object")
150
+ return false;
151
+ for (var _i = 0, i_5 = i; _i < i_5.length; _i++) {
152
+ var item = i_5[_i];
153
+ if (!typeGuard.v1.thread(item))
154
+ return false;
155
+ }
156
+ return true;
157
+ },
158
+ }
159
+ };
160
+ var typeVerify = function (item, keys) {
161
+ for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
162
+ var key = keys_1[_i];
163
+ if (item[key] === undefined)
164
+ return false;
165
+ }
166
+ return true;
167
+ };
168
+ var typeAttributeVerify = function (item, keys) {
169
+ for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
170
+ var key = keys_2[_i];
171
+ if (item.getAttribute(key) === null)
172
+ return false;
173
+ }
174
+ return true;
175
+ };
176
+
177
+ var convert2formattedComment = function (data, type) {
178
+ var result = [];
179
+ if (typeGuard.niconicome.xmlDocument(data) && type === "niconicome") {
180
+ result = fromNiconicome(data);
181
+ }
182
+ else if (typeGuard.formatted.legacyComments(data) && type === "formatted") {
183
+ result = fromFormatted(data);
184
+ }
185
+ else if (typeGuard.legacy.rawApiResponses(data) && type === "legacy") {
186
+ result = fromLegacy(data);
187
+ }
188
+ else if (typeGuard.owner.comments(data) && type === "owner") {
189
+ result = fromOwner(data);
190
+ }
191
+ else if (typeGuard.v1.threads(data) && type === "v1") {
192
+ result = fromV1(data);
193
+ }
194
+ else {
195
+ throw new Error("unknown input format");
196
+ }
197
+ return sort(result);
198
+ };
199
+ var fromNiconicome = function (data) {
200
+ var data_ = [], userList = [];
201
+ for (var _i = 0, _a = Array.from(data.documentElement.children); _i < _a.length; _i++) {
202
+ var item = _a[_i];
203
+ if (item.nodeName !== "chat")
204
+ continue;
205
+ var tmpParam = {
206
+ id: Number(item.getAttribute("no")),
207
+ vpos: Number(item.getAttribute("vpos")),
208
+ content: item.innerHTML,
209
+ date: Number(item.getAttribute("date")),
210
+ date_usec: Number(item.getAttribute("date_usec")),
211
+ owner: !item.getAttribute("user_id"),
212
+ premium: item.getAttribute("premium") === "1",
213
+ mail: [],
214
+ user_id: -1,
215
+ layer: -1
216
+ };
217
+ if (item.getAttribute("mail")) {
218
+ tmpParam.mail = item.getAttribute("mail").split(/[\s ]/g);
219
+ }
220
+ if (tmpParam.content.startsWith("/") && tmpParam.owner) {
221
+ tmpParam.mail.push("invisible");
222
+ }
223
+ var isUserExist = userList.indexOf(item.getAttribute("user_id"));
224
+ if (isUserExist === -1) {
225
+ tmpParam.user_id = userList.length;
226
+ userList.push(item.getAttribute("user_id"));
227
+ }
228
+ else {
229
+ tmpParam.user_id = isUserExist;
230
+ }
231
+ data_.push(tmpParam);
232
+ }
233
+ return data_;
234
+ };
235
+ var fromFormatted = function (data) {
236
+ var tmpData = data;
237
+ if (!typeGuard.formatted.comments(data)) {
238
+ for (var i in tmpData) {
239
+ tmpData[i].layer = -1;
240
+ tmpData[i].user_id = 0;
241
+ if (!tmpData[i].date_usec)
242
+ tmpData[i].date_usec = 0;
243
+ }
244
+ }
245
+ return tmpData;
246
+ };
247
+ var fromLegacy = function (data) {
248
+ var data_ = [], userList = [];
249
+ for (var i = 0; i < data.length; i++) {
250
+ var val = data[i];
251
+ if (!val)
252
+ continue;
253
+ for (var key in val) {
254
+ var value = val[key];
255
+ if (typeGuard.legacy.apiChat(value) && value.deleted !== 1) {
256
+ var tmpParam = {
257
+ id: value.no,
258
+ vpos: value.vpos,
259
+ content: value.content,
260
+ date: value.date,
261
+ date_usec: value.date_usec || 0,
262
+ owner: !value.user_id,
263
+ premium: value.premium === 1,
264
+ mail: [],
265
+ user_id: -1,
266
+ layer: -1
267
+ };
268
+ if (value.mail) {
269
+ tmpParam.mail = value.mail.split(/[\s ]/g);
270
+ }
271
+ if (value.content.startsWith("/") && !value.user_id) {
272
+ tmpParam.mail.push("invisible");
273
+ }
274
+ var isUserExist = userList.indexOf(value.mail);
275
+ if (isUserExist === -1) {
276
+ tmpParam.user_id = userList.length;
277
+ userList.push(value.user_id);
278
+ }
279
+ else {
280
+ tmpParam.user_id = isUserExist;
281
+ }
282
+ data_.push(tmpParam);
283
+ }
284
+ }
285
+ }
286
+ return data_;
287
+ };
288
+ var fromOwner = function (data) {
289
+ var data_ = [];
290
+ for (var i = 0; i < data.length; i++) {
291
+ var value = data[i];
292
+ var tmpParam = {
293
+ id: i,
294
+ vpos: time2vpos(value.time),
295
+ content: value.comment,
296
+ date: i,
297
+ date_usec: 0,
298
+ owner: true,
299
+ premium: true,
300
+ mail: [],
301
+ user_id: -1,
302
+ layer: -1
303
+ };
304
+ if (value.command) {
305
+ tmpParam.mail = value.command.split(/[\s ]/g);
306
+ }
307
+ if (tmpParam.content.startsWith("/")) {
308
+ tmpParam.mail.push("invisible");
309
+ }
310
+ data_.push(tmpParam);
311
+ }
312
+ return data_;
313
+ };
314
+ var fromV1 = function (data) {
315
+ var data_ = [], userList = [];
316
+ for (var i = 0; i < data.length; i++) {
317
+ var val = data[i].comments, forkName = data[i].fork;
318
+ for (var key in val) {
319
+ var value = val[key];
320
+ var tmpParam = {
321
+ id: value.no,
322
+ vpos: Math.floor(value.vposMs * 10),
323
+ content: value.body,
324
+ date: date2time(value.postedAt),
325
+ date_usec: 0,
326
+ owner: forkName === "owner",
327
+ premium: value.isPremium,
328
+ mail: value.commands,
329
+ user_id: -1,
330
+ layer: -1
331
+ };
332
+ if (tmpParam.content.startsWith("/") && tmpParam.owner) {
333
+ tmpParam.mail.push("invisible");
334
+ }
335
+ var isUserExist = userList.indexOf(value.userId);
336
+ if (isUserExist === -1) {
337
+ tmpParam.user_id = userList.length;
338
+ userList.push(value.userId);
339
+ }
340
+ else {
341
+ tmpParam.user_id = isUserExist;
342
+ }
343
+ data_.push(tmpParam);
344
+ }
345
+ }
346
+ return data_;
347
+ };
348
+ var sort = function (data) {
349
+ data.sort(function (a, b) {
350
+ if (a.vpos < b.vpos)
351
+ return -1;
352
+ if (a.vpos > b.vpos)
353
+ return 1;
354
+ if (a.date < b.date)
355
+ return -1;
356
+ if (a.date > b.date)
357
+ return 1;
358
+ if (a.date_usec < b.date_usec)
359
+ return -1;
360
+ if (a.date_usec > b.date_usec)
361
+ return 1;
362
+ return 0;
363
+ });
364
+ return data;
365
+ };
366
+ var time2vpos = function (time_str) {
367
+ var time = time_str.match(/^(\d+):(\d+)\.(\d+)|(\d+):(\d+)|(\d+)\.(\d+)|(\d+)$/);
368
+ if (time) {
369
+ if (time[1] !== undefined && time[2] !== undefined && time[3] !== undefined) {
370
+ return (Number(time[1]) * 60 + Number(time[2])) * 100 + Number(time[3]) / Math.pow(10, time[3].length - 2);
371
+ }
372
+ else if (time[4] !== undefined && time[5] !== undefined) {
373
+ return (Number(time[4]) * 60 + Number(time[5])) * 100;
374
+ }
375
+ else if (time[6] !== undefined && time[7] !== undefined) {
376
+ return Number(time[6]) * 100 + Number(time[7]) / Math.pow(10, time[7].length - 2);
377
+ }
378
+ else if (time[8] !== undefined) {
379
+ return Number(time[8]) * 100;
380
+ }
381
+ }
382
+ return 0;
383
+ };
384
+ var date2time = function (date) {
385
+ return Math.floor(new Date(date).getTime() / 1000);
386
+ };
387
+
28
388
  var isDebug = false;
29
389
  var NiconiComments = (function () {
30
- function NiconiComments(canvas, data, options) {
31
- if (options === void 0) { options = {
32
- useLegacy: false,
390
+ function NiconiComments(canvas, data, initOptions) {
391
+ if (initOptions === void 0) { initOptions = {}; }
392
+ var _this = this;
393
+ var defaultOptions = {
394
+ drawAllImageOnLoad: false,
395
+ format: "default",
33
396
  formatted: false,
34
- video: null,
397
+ debug: false,
398
+ enableLegacyPiP: false,
399
+ keepCA: false,
35
400
  showCollision: false,
36
- showFPS: false,
37
401
  showCommentCount: false,
38
- drawAllImageOnLoad: false,
39
- debug: false,
40
- enableLegacyPiP: false
41
- }; }
42
- var _this = this;
402
+ showFPS: false,
403
+ useLegacy: false,
404
+ video: null,
405
+ };
406
+ var options = Object.assign(defaultOptions, initOptions);
43
407
  isDebug = options.debug;
44
408
  var constructorStart = performance.now();
45
409
  this.canvas = canvas;
@@ -84,19 +448,27 @@
84
448
  this.doubleResizeMaxWidth = {
85
449
  full: {
86
450
  legacy: 3020,
87
- default: 3220
451
+ default: 3550
88
452
  },
89
453
  normal: {
90
454
  legacy: 2540,
91
- default: 2740
455
+ default: 2650
92
456
  }
93
457
  };
94
- var parsedData = options.formatted ? data : this.parseData(data);
458
+ var formatType = options.format;
459
+ if (options.formatted) {
460
+ console.warn("Deprecated: options.formatted is no longer recommended. Please use options.format");
461
+ }
462
+ if (formatType === "default") {
463
+ formatType = options.formatted ? "formatted" : "legacy";
464
+ }
465
+ var parsedData = convert2formattedComment(data, formatType);
95
466
  this.video = options.video ? options.video : null;
96
467
  this.showCollision = options.showCollision;
97
468
  this.showFPS = options.showFPS;
98
469
  this.showCommentCount = options.showCommentCount;
99
470
  this.enableLegacyPiP = options.enableLegacyPiP;
471
+ this.keepCA = options.keepCA;
100
472
  this.timeline = {};
101
473
  this.nicoScripts = { reverse: [], default: [], replace: [], ban: [] };
102
474
  this.collision_right = {};
@@ -115,61 +487,16 @@
115
487
  }, 500);
116
488
  logger("constructor complete: ".concat(performance.now() - constructorStart, "ms"));
117
489
  }
118
- NiconiComments.prototype.parseData = function (data) {
119
- var parseDataStart = performance.now();
120
- var data_ = [];
121
- for (var i = 0; i < data.length; i++) {
122
- var val = data[i];
123
- if (!val)
124
- continue;
125
- for (var key in val) {
126
- var value = val[key];
127
- if (isApiChat(value) && value["deleted"] !== 1) {
128
- var tmpParam = {
129
- "id": value["no"],
130
- "vpos": value["vpos"],
131
- "content": value["content"],
132
- "date": value["date"],
133
- "date_usec": value["date_usec"],
134
- "owner": !value["user_id"],
135
- "premium": value["premium"] === 1,
136
- "mail": []
137
- };
138
- if (value["mail"]) {
139
- tmpParam["mail"] = value["mail"].split(/[\s ]/g);
140
- }
141
- if (value["content"].startsWith("/") && !value["user_id"]) {
142
- tmpParam["mail"].push("invisible");
143
- }
144
- data_.push(tmpParam);
145
- }
146
- }
147
- }
148
- data_.sort(function (a, b) {
149
- if (a.vpos < b.vpos)
150
- return -1;
151
- if (a.vpos > b.vpos)
152
- return 1;
153
- if (a.date < b.date)
154
- return -1;
155
- if (a.date > b.date)
156
- return 1;
157
- if (a.date_usec < b.date_usec)
158
- return -1;
159
- if (a.date_usec > b.date_usec)
160
- return 1;
161
- return 0;
162
- });
163
- logger("parseData complete: ".concat(performance.now() - parseDataStart, "ms"));
164
- return data_;
165
- };
166
490
  NiconiComments.prototype.preRendering = function (rawData, drawAll) {
167
491
  var preRenderingStart = performance.now();
492
+ if (this.keepCA) {
493
+ rawData = changeCALayer(rawData);
494
+ }
168
495
  var parsedData = this.getCommentPos(this.getCommentSize(this.getFont(rawData)));
169
496
  this.data = this.sortComment(parsedData);
170
497
  if (drawAll) {
171
498
  for (var i in parsedData) {
172
- this.getTextImage(Number(i));
499
+ this.getTextImage(Number(i), true);
173
500
  }
174
501
  }
175
502
  logger("preRendering complete: ".concat(performance.now() - preRenderingStart, "ms"));
@@ -257,7 +584,7 @@
257
584
  if (left_pos + comment.width_max >= 1880) {
258
585
  for (var k in this.collision_right[vpos]) {
259
586
  var l = this.collision_right[vpos][k];
260
- if ((posY < data[l].posY + data[l].height && posY + comment.height > data[l].posY) && data[l].owner === comment.owner) {
587
+ if ((posY < data[l].posY + data[l].height && posY + comment.height > data[l].posY) && data[l].owner === comment.owner && data[l].layer === comment.layer) {
261
588
  if (data[l].posY + data[l].height > posY) {
262
589
  posY = data[l].posY + data[l].height;
263
590
  is_change = true;
@@ -281,7 +608,7 @@
281
608
  if (left_pos <= 40) {
282
609
  for (var k in this.collision_left[vpos]) {
283
610
  var l = this.collision_left[vpos][k];
284
- if ((posY < data[l].posY + data[l].height && posY + comment.height > data[l].posY) && data[l].owner === comment.owner) {
611
+ if ((posY < data[l].posY + data[l].height && posY + comment.height > data[l].posY) && data[l].owner === comment.owner && data[l].layer === comment.layer) {
285
612
  if (data[l].posY + data[l].height > posY) {
286
613
  posY = data[l].posY + data[l].height;
287
614
  is_change = true;
@@ -311,7 +638,6 @@
311
638
  for (var j = beforeVpos; j < comment.long + 125; j++) {
312
639
  var vpos = comment.vpos + j;
313
640
  var left_pos = 1680 - (1680 + comment.width_max) / (comment.long + 125) * j;
314
- console.log(vpos, i, j);
315
641
  arrayPush(this.timeline, vpos, i);
316
642
  if (left_pos + comment.width_max >= 1880) {
317
643
  arrayPush(this.collision_right, vpos, i);
@@ -337,7 +663,7 @@
337
663
  var vpos = comment.vpos + j;
338
664
  for (var k in collision[vpos]) {
339
665
  var l = collision[vpos][k];
340
- if ((posY < data[l].posY + data[l].height && posY + comment.height > data[l].posY) && data[l].owner === comment.owner) {
666
+ if ((posY < data[l].posY + data[l].height && posY + comment.height > data[l].posY) && data[l].owner === comment.owner && data[l].layer === comment.layer) {
341
667
  if (data[l].posY + data[l].height > posY) {
342
668
  posY = data[l].posY + data[l].height;
343
669
  is_change = true;
@@ -448,6 +774,7 @@
448
774
  }
449
775
  else if (comment.loc !== "naka" && comment.tateresized && (comment.full && width_max > 2120 || !comment.full && width_max > 1440) && !comment.yokoResized) {
450
776
  comment.fontSize = this.fontSize[comment.size].default;
777
+ comment.lineHeight = this.lineHeight[comment.size].default * 1.05;
451
778
  comment.resized = true;
452
779
  comment.yokoResized = true;
453
780
  this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
@@ -499,7 +826,6 @@
499
826
  }
500
827
  else {
501
828
  posX = 1680 - (1680 + comment.width_max) / (comment.long + 125) * (vpos - comment.vpos + 100);
502
- console.log(vpos - comment.vpos);
503
829
  }
504
830
  }
505
831
  else if (comment.loc === "shita") {
@@ -519,8 +845,9 @@
519
845
  }
520
846
  }
521
847
  };
522
- NiconiComments.prototype.getTextImage = function (i) {
848
+ NiconiComments.prototype.getTextImage = function (i, preRendering) {
523
849
  var _this = this;
850
+ if (preRendering === void 0) { preRendering = false; }
524
851
  var value = this.data[i];
525
852
  if (!value || value.invisible)
526
853
  return;
@@ -553,6 +880,8 @@
553
880
  context.fillText(line, 0, posY);
554
881
  }
555
882
  this.data[i].image = image;
883
+ if (preRendering)
884
+ return;
556
885
  setTimeout(function () {
557
886
  if (_this.data[i].image)
558
887
  delete _this.data[i].image;
@@ -869,6 +1198,8 @@
869
1198
  for (var i in this.timeline[vpos]) {
870
1199
  var index = this.timeline[vpos][Number(i)];
871
1200
  var comment = this.data[index];
1201
+ if (vpos > 23000 && vpos < 23100)
1202
+ console.log(comment);
872
1203
  if (!comment || comment.invisible) {
873
1204
  continue;
874
1205
  }
@@ -965,12 +1296,46 @@
965
1296
  }
966
1297
  return string;
967
1298
  };
968
- var isApiChat = function (item) {
969
- return item.no && item.vpos && item.content;
970
- };
971
1299
  var logger = function (msg) {
972
1300
  if (isDebug)
973
1301
  console.debug(msg);
1302
+ };
1303
+ var changeCALayer = function (rawData) {
1304
+ var userList = {};
1305
+ var data = [], index = {};
1306
+ for (var i in rawData) {
1307
+ var value = rawData[i];
1308
+ if (value.user_id === undefined || value.user_id === -1)
1309
+ continue;
1310
+ if (userList[value.user_id] === undefined)
1311
+ userList[value.user_id] = 0;
1312
+ if (value.mail.indexOf("ca") > -1 || value.mail.indexOf("patissier") > -1 || value.mail.indexOf("ender") > -1 || value.mail.indexOf("full") > -1) {
1313
+ userList[value.user_id] += 5;
1314
+ }
1315
+ if ((value.content.match(/\r\n|\n|\r/g) || []).length > 2) {
1316
+ userList[value.user_id] += (value.content.match(/\r\n|\n|\r/g) || []).length / 2;
1317
+ }
1318
+ var key = "".concat(value.content, "@@").concat(Array.from(new Set(JSON.parse(JSON.stringify(value.mail)).sort())).filter(function (e) { return !e.match(/@[\d.]+|184|device:.+|patissier|ca/); }).join("")), lastComment = index[key];
1319
+ if (lastComment !== undefined) {
1320
+ if (value.vpos > 29800 && 30200 > value.vpos)
1321
+ console.log(value.vpos - lastComment.vpos, Math.abs(value.date - lastComment.date));
1322
+ if (value.vpos - lastComment.vpos > 100 || Math.abs(value.date - lastComment.date) < 3600) {
1323
+ data.push(value);
1324
+ index[key] = value;
1325
+ }
1326
+ }
1327
+ else {
1328
+ data.push(value);
1329
+ index[key] = value;
1330
+ }
1331
+ }
1332
+ for (var i in data) {
1333
+ var value = data[i];
1334
+ if (userList[value.user_id] !== undefined && userList[value.user_id] >= 10) {
1335
+ value.layer = value.user_id;
1336
+ }
1337
+ }
1338
+ return data;
974
1339
  };
975
1340
 
976
1341
  return NiconiComments;
@@ -0,0 +1,154 @@
1
+ type inputFormatType = "niconicome"|"formatted"|"legacy"|"owner"|"v1"|"default";
2
+ type InitOptions = {
3
+ useLegacy?: boolean,
4
+ formatted?: boolean,
5
+ format?: inputFormatType,
6
+ video?: HTMLVideoElement | null
7
+ showCollision?: boolean,
8
+ showFPS?: boolean,
9
+ showCommentCount?: boolean,
10
+ drawAllImageOnLoad?: boolean,
11
+ debug?: boolean,
12
+ enableLegacyPiP?: boolean,
13
+ keepCA?: boolean
14
+ }
15
+ type Options = {
16
+ useLegacy: boolean,
17
+ formatted: boolean,
18
+ format: inputFormatType,
19
+ video: HTMLVideoElement | null,
20
+ showCollision: boolean,
21
+ showFPS: boolean,
22
+ showCommentCount: boolean,
23
+ drawAllImageOnLoad: boolean,
24
+ debug: boolean,
25
+ enableLegacyPiP: boolean,
26
+ keepCA: boolean
27
+ }
28
+ type rawApiResponse = {
29
+ [key: string]: apiPing | apiThread | apiLeaf | apiGlobalNumRes | apiChat
30
+ }
31
+ type apiPing = {
32
+ "content": string
33
+ }
34
+ type apiThread = {
35
+ "resultcode": number,
36
+ "thread": string,
37
+ "server_time": number,
38
+ "ticket": string,
39
+ "revision": number
40
+ }
41
+ type apiLeaf = {
42
+ "thread": string,
43
+ "count": number
44
+ }
45
+ type apiGlobalNumRes = {
46
+ "thread": string,
47
+ "num_res": number
48
+ }
49
+ type apiChat = {
50
+ "thread": string,
51
+ "no": number,
52
+ "vpos": number,
53
+ "date": number,
54
+ "date_usec": number,
55
+ "nicoru": number,
56
+ "premium": number,
57
+ "anonymity": number,
58
+ "user_id": string,
59
+ "mail": string,
60
+ "content": string,
61
+ "deleted": number
62
+ }
63
+ type formattedComment = {
64
+ "id": number,
65
+ "vpos": number,
66
+ "content": string,
67
+ "date": number,
68
+ "date_usec": number,
69
+ "owner": boolean,
70
+ "premium": boolean,
71
+ "mail": string[],
72
+ "user_id": number,
73
+ "layer": number,
74
+ }
75
+ type formattedLegacyComment = {
76
+ "id": number,
77
+ "vpos": number,
78
+ "content": string,
79
+ "date": number,
80
+ "date_usec": number,
81
+ "owner": boolean,
82
+ "premium": boolean,
83
+ "mail": string[],
84
+ }
85
+ type formattedCommentWithFont = formattedComment & {
86
+ "loc": string,
87
+ "size": string,
88
+ "fontSize": number,
89
+ "font": string,
90
+ "color": string,
91
+ "full": boolean,
92
+ "ender": boolean,
93
+ "_live": boolean,
94
+ "long": number,
95
+ "invisible": boolean
96
+ }
97
+ type formattedCommentWithSize = formattedCommentWithFont & {
98
+ "height": number,
99
+ "width": number,
100
+ "width_max": number,
101
+ "width_min": number,
102
+ "lineHeight": number
103
+ }
104
+ type parsedComment = formattedCommentWithSize & {
105
+ posY: number,
106
+ image?: HTMLCanvasElement | boolean
107
+ }
108
+ type measureTextResult = {
109
+ "width": number,
110
+ "width_max": number,
111
+ "width_min": number,
112
+ "height": number,
113
+ "resized": boolean,
114
+ "fontSize": number,
115
+ "lineHeight": number
116
+ }
117
+ type T_fontSize = {
118
+ [key: string]: {
119
+ "default": number,
120
+ "resized": number
121
+ }
122
+ }
123
+ type T_doubleResizeMaxWidth = {
124
+ [key: string]: {
125
+ "legacy": number,
126
+ "default": number
127
+ }
128
+ }
129
+ type v1Thread = {
130
+ "id": string,
131
+ "fork": string,
132
+ "commentCount": number,
133
+ "comments": { [key: string]:v1Comment }
134
+ }
135
+ type v1Comment = {
136
+ "id": string,
137
+ "no": number,
138
+ "vposMs": number,
139
+ "body": string,
140
+ "commands": string[],
141
+ "userId": string,
142
+ "isPremium": boolean,
143
+ "score": number,
144
+ "postedAt": string,
145
+ "nicoruCount": number,
146
+ "nicoruId": null,
147
+ "source": string,
148
+ "isMyPost": boolean
149
+ }
150
+ type ownerComment = {
151
+ "time": string,
152
+ "command": string,
153
+ "comment": string
154
+ }
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@xpadev-net/niconicomments",
3
- "version": "0.2.18",
3
+ "version": "0.2.21",
4
4
  "description": "NiconiComments is a comment drawing library that is somewhat compatible with the official Nico Nico Douga player.",
5
5
  "main": "dist/bundle.js",
6
- "types": "dist/dts/main.d.ts",
6
+ "types": "dist/dts/types.d.ts",
7
7
  "scripts": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1",
9
9
  "build": "rollup -c rollup.config.js",
10
10
  "watch": "rollup -c rollup.config.js -w",
11
- "typedoc": "typedoc --options tsdoc.json --out ./docs/type/ ./src/main.ts",
12
- "tsc": "tsc --emitDeclarationOnly",
13
- "prepublishOnly": "npm run tsc&&npm run build"
11
+ "typedoc": "typedoc --entryPointStrategy Expand --options tsdoc.json --out ./docs/type/ ./src/",
12
+ "copy-dts": "npx copyfiles -u 2 src/@types/*.d.ts dist/dts",
13
+ "prepublishOnly": "npm run copy-dts&&npm run build"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
@@ -25,18 +25,20 @@
25
25
  },
26
26
  "files": [
27
27
  "dist/bundle.js",
28
- "dist/dts/main.d.ts",
29
- "dist/dts/main.d.ts.map"
28
+ "dist/dts/types.d.ts"
30
29
  ],
31
30
  "homepage": "https://xpadev.net/niconicomments/docs/",
32
31
  "license": "MIT",
33
32
  "devDependencies": {
34
33
  "@babel/preset-env": "^7.18.2",
35
34
  "@rollup/plugin-babel": "^5.3.0",
36
- "@rollup/plugin-typescript": "^8.3.2",
37
- "rollup": "^2.75.6",
38
- "typedoc": "^0.22.17",
35
+ "@rollup/plugin-node-resolve": "^13.3.0",
36
+ "@rollup/plugin-typescript": "^8.3.3",
37
+ "copyfiles": "^2.4.1",
38
+ "rollup": "^2.75.7",
39
+ "rollup-plugin-dts": "^4.2.2",
40
+ "typedoc": "^0.22.18",
39
41
  "typedoc-plugin-missing-exports": "^0.22.6",
40
- "typescript": "^4.7.3"
42
+ "typescript": "^4.7.4"
41
43
  }
42
44
  }
@@ -1,152 +0,0 @@
1
- declare type InitOptions = {
2
- useLegacy: boolean;
3
- formatted: boolean;
4
- video: HTMLVideoElement | null;
5
- showCollision: boolean;
6
- showFPS: boolean;
7
- showCommentCount: boolean;
8
- drawAllImageOnLoad: boolean;
9
- debug: boolean;
10
- enableLegacyPiP: boolean;
11
- };
12
- declare type rawApiResponse = {
13
- [key: string]: apiPing | apiThread | apiLeaf | apiGlobalNumRes | apiChat;
14
- };
15
- declare type apiPing = {
16
- "content": string;
17
- };
18
- declare type apiThread = {
19
- "resultcode": number;
20
- "thread": string;
21
- "server_time": number;
22
- "ticket": string;
23
- "revision": number;
24
- };
25
- declare type apiLeaf = {
26
- "thread": string;
27
- "count": number;
28
- };
29
- declare type apiGlobalNumRes = {
30
- "thread": string;
31
- "num_res": number;
32
- };
33
- declare type apiChat = {
34
- "thread": string;
35
- "no": number;
36
- "vpos": number;
37
- "date": number;
38
- "date_usec": number;
39
- "nicoru": number;
40
- "premium": number;
41
- "anonymity": number;
42
- "user_id": string;
43
- "mail": string;
44
- "content": string;
45
- "deleted": number;
46
- };
47
- declare type formattedComment = {
48
- "id": number;
49
- "vpos": number;
50
- "content": string;
51
- "date": number;
52
- "date_usec": number;
53
- "owner": boolean;
54
- "premium": boolean;
55
- "mail": string[];
56
- };
57
- declare type formattedCommentWithFont = formattedComment & {
58
- "loc": string;
59
- "size": string;
60
- "fontSize": number;
61
- "font": string;
62
- "color": string;
63
- "full": boolean;
64
- "ender": boolean;
65
- "_live": boolean;
66
- "long": number;
67
- "invisible": boolean;
68
- };
69
- declare type formattedCommentWithSize = formattedCommentWithFont & {
70
- "height": number;
71
- "width": number;
72
- "width_max": number;
73
- "width_min": number;
74
- "lineHeight": number;
75
- };
76
- declare type parsedComment = formattedCommentWithSize & {
77
- posY: number;
78
- image?: HTMLCanvasElement | boolean;
79
- };
80
- declare type measureTextResult = {
81
- "width": number;
82
- "width_max": number;
83
- "width_min": number;
84
- "height": number;
85
- "resized": boolean;
86
- "fontSize": number;
87
- "lineHeight": number;
88
- };
89
- declare class NiconiComments {
90
- private canvas;
91
- private context;
92
- private readonly commentYPaddingTop;
93
- private readonly commentYMarginBottom;
94
- private readonly fontSize;
95
- private readonly lineHeight;
96
- private readonly doubleResizeMaxWidth;
97
- private video;
98
- private showCollision;
99
- showFPS: boolean;
100
- showCommentCount: boolean;
101
- enableLegacyPiP: boolean;
102
- private data;
103
- private timeline;
104
- private nicoScripts;
105
- private collision_right;
106
- private collision_left;
107
- private collision_ue;
108
- private collision_shita;
109
- private lastVpos;
110
- private useLegacy;
111
- private fpsCount;
112
- private fps;
113
- constructor(canvas: HTMLCanvasElement, data: (rawApiResponse | formattedComment)[], options?: InitOptions);
114
- parseData(data: rawApiResponse[]): formattedComment[];
115
- preRendering(rawData: formattedComment[], drawAll: boolean): void;
116
- getFont(parsedData: formattedComment[]): formattedCommentWithFont[];
117
- getCommentSize(parsedData: formattedCommentWithFont[]): formattedCommentWithSize[];
118
- getCommentPos(parsedData: parsedComment[]): parsedComment[];
119
- sortComment(parsedData: parsedComment[]): parsedComment[];
120
- measureText(comment: {
121
- content: string;
122
- resized: boolean;
123
- ender: any;
124
- size: string;
125
- fontSize: number;
126
- tateresized: boolean;
127
- font: any;
128
- loc: string;
129
- full: any;
130
- yokoResized: boolean;
131
- lineHeight: number | undefined;
132
- }): measureTextResult;
133
- drawText(comment: parsedComment, vpos: number): void;
134
- getTextImage(i: number): void;
135
- parseCommand(comment: any): {
136
- loc: string | null;
137
- size: string | null;
138
- fontSize: number | null;
139
- color: any;
140
- font: string | null;
141
- full: boolean;
142
- ender: boolean;
143
- _live: boolean;
144
- invisible: boolean;
145
- long: any;
146
- };
147
- parseCommandAndNicoscript(comment: formattedComment): formattedCommentWithFont;
148
- drawCanvas(vpos: number): void;
149
- clear(): void;
150
- }
151
- export default NiconiComments;
152
- //# sourceMappingURL=main.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,aAAK,WAAW,GAAG;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC/B,aAAa,EAAE,OAAO,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,eAAe,EAAE,OAAO,CAAA;CAC3B,CAAA;AACD,aAAK,cAAc,GAAG;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,eAAe,GAAG,OAAO,CAAA;CAC3E,CAAA;AACD,aAAK,OAAO,GAAG;IACX,SAAS,EAAE,MAAM,CAAA;CACpB,CAAA;AACD,aAAK,SAAS,GAAG;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAA;CACrB,CAAA;AACD,aAAK,OAAO,GAAG;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAA;CAClB,CAAA;AACD,aAAK,eAAe,GAAG;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM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