@xpadev-net/niconicomments 0.0.11 → 0.1.5

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 (2) hide show
  1. package/dist/bundle.js +367 -153
  2. package/package.json +1 -1
package/dist/bundle.js CHANGED
@@ -1,3 +1,8 @@
1
+ /*!
2
+ niconicomments.js v0.1.5
3
+ (c) 2021 xpadev-net https://xpadevn.et
4
+ Released under the MIT License.
5
+ */
1
6
  (function (global, factory) {
2
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
8
  typeof define === 'function' && define.amd ? define(factory) :
@@ -18,9 +23,50 @@
18
23
  this.context.strokeStyle = "rgba(0,0,0,0.7)";
19
24
  this.context.textAlign = "left";
20
25
  this.context.textBaseline = "top";
21
- this.context.lineWidth = "6";
22
- this.commentYOffset = 0.25;
23
- this.commentYMarginTop = 0.05;
26
+ this.context.lineWidth = 2;
27
+
28
+ if (useLegacy) {
29
+ this.commentYOffset = 0.25;
30
+ } else {
31
+ this.commentYOffset = 0.2;
32
+ }
33
+
34
+ this.commentYMarginTop = 0.08;
35
+ this.fontSize = {
36
+ "small": {
37
+ "default": 47,
38
+ "resized": 27.5
39
+ },
40
+ "medium": {
41
+ "default": 76,
42
+ "resized": 39
43
+ },
44
+ "big": {
45
+ "default": 118,
46
+ "resized": 62.5
47
+ }
48
+ };
49
+ this.defaultCommandValue = {
50
+ loc: "naka",
51
+ size: "medium",
52
+ fontSize: this.fontSize.medium.default,
53
+ color: "#ffffff",
54
+ font: 'defont',
55
+ full: false,
56
+ ender: false,
57
+ _live: false,
58
+ invisible: false
59
+ };
60
+ this.doubleResizeMaxWidth = {
61
+ full: {
62
+ legacy: 3020,
63
+ default: 3220
64
+ },
65
+ normal: {
66
+ legacy: 2540,
67
+ default: 2740
68
+ }
69
+ };
24
70
 
25
71
  if (formatted) {
26
72
  this.data = data;
@@ -33,7 +79,8 @@
33
79
  this.showCommentCount = false;
34
80
  this.timeline = {};
35
81
  this.nicoScripts = {
36
- "reverse": []
82
+ "reverse": [],
83
+ "default": []
37
84
  };
38
85
  this.collision_right = {};
39
86
  this.collision_left = {};
@@ -62,18 +109,19 @@
62
109
  for (let key in data[i]) {
63
110
  let value = data[i][key];
64
111
 
65
- if (key === "chat") {
112
+ if (key === "chat" && value["deleted"] !== 1) {
66
113
  let tmpParam = {
67
114
  "id": value["no"],
68
115
  "vpos": value["vpos"],
69
116
  "content": value["content"],
70
117
  "date": value["date"],
71
118
  "date_usec": value["date_usec"],
72
- "owner": !value["user_id"]
119
+ "owner": !value["user_id"],
120
+ "premium": value["premium"] === 1
73
121
  };
74
122
 
75
123
  if (value["mail"]) {
76
- tmpParam["mail"] = value["mail"].split(" ");
124
+ tmpParam["mail"] = value["mail"].split(/[\s ]/g);
77
125
  } else {
78
126
  tmpParam["mail"] = [];
79
127
  }
@@ -112,7 +160,7 @@
112
160
  getFont() {
113
161
  for (let i in this.data) {
114
162
  let comment = this.data[i];
115
- let command = this.parseCommand(comment);
163
+ let command = this.parseCommandAndNicoscript(comment);
116
164
  this.data[i].loc = command.loc;
117
165
  this.data[i].size = command.size;
118
166
  this.data[i].fontSize = command.fontSize;
@@ -120,7 +168,10 @@
120
168
  this.data[i].color = command.color;
121
169
  this.data[i].full = command.full;
122
170
  this.data[i].ender = command.ender;
123
- this.data[i].content = this.data[i].content.replaceAll("\t", " ").replaceAll(/(\n){3,}/g, "\n\n\n");
171
+ this.data[i]._live = command._live;
172
+ this.data[i].long = command.long;
173
+ this.data[i].invisible = command.invisible;
174
+ this.data[i].content = this.data[i].content.replaceAll("\t", " ");
124
175
  }
125
176
  }
126
177
  /**
@@ -137,6 +188,11 @@
137
188
 
138
189
  for (let k in tmpData[i][j]) {
139
190
  let comment = tmpData[i][j][k];
191
+
192
+ if (comment.invisible) {
193
+ continue;
194
+ }
195
+
140
196
  let measure = this.measureText(comment);
141
197
  this.data[comment.index].height = measure.height;
142
198
  this.data[comment.index].width = measure.width;
@@ -162,6 +218,10 @@
162
218
  for (let i in data) {
163
219
  let comment = data[i];
164
220
 
221
+ if (comment.invisible) {
222
+ continue;
223
+ }
224
+
165
225
  for (let j = 0; j < 500; j++) {
166
226
  if (!this.timeline[comment.vpos + j]) {
167
227
  this.timeline[comment.vpos + j] = [];
@@ -192,73 +252,77 @@
192
252
  is_change = true,
193
253
  count = 0;
194
254
 
195
- while (is_change && count < 10) {
196
- is_change = false;
197
- count++;
198
-
199
- for (let j = 0; j < 500; j++) {
200
- let vpos = comment.vpos + j;
201
- let left_pos = 1920 - (1920 + comment.width_max) * j / 500;
255
+ if (1080 < comment.height) {
256
+ posY = (comment.height - 1080) / -2;
257
+ } else {
258
+ while (is_change && count < 10) {
259
+ is_change = false;
260
+ count++;
261
+
262
+ for (let j = 0; j < 500; j++) {
263
+ let vpos = comment.vpos + j;
264
+ let left_pos = 1920 - (1920 + comment.width_max) * j / 500;
265
+
266
+ if (left_pos + comment.width_max >= 1880) {
267
+ for (let k in this.collision_right[vpos]) {
268
+ let l = this.collision_right[vpos][k];
269
+
270
+ if (posY < data[l].posY + data[l].height && posY + comment.height > data[l].posY && data[l].owner === comment.owner) {
271
+ if (data[l].posY + data[l].height > posY) {
272
+ posY = data[l].posY + data[l].height;
273
+ is_change = true;
274
+ }
202
275
 
203
- if (left_pos + comment.width_max >= 1880) {
204
- for (let k in this.collision_right[vpos]) {
205
- let l = this.collision_right[vpos][k];
276
+ if (posY + comment.height > 1080) {
277
+ if (1080 < comment.height) {
278
+ posY = (comment.height - 1080) / -2;
279
+ } else {
280
+ posY = Math.floor(Math.random() * (1080 - comment.height));
281
+ }
206
282
 
207
- if (posY < data[l].posY + data[l].height && posY + comment.height > data[l].posY && data[l].owner === comment.owner) {
208
- if (data[l].posY + data[l].height > posY) {
209
- posY = data[l].posY + data[l].height;
210
- is_change = true;
211
- }
212
-
213
- if (posY + comment.height > 1080) {
214
- if (1080 < comment.height) {
215
- posY = 0;
216
- } else {
217
- posY = Math.floor(Math.random() * (1080 - comment.height));
283
+ is_break = true;
284
+ break;
218
285
  }
219
-
220
- is_break = true;
221
- break;
222
286
  }
223
287
  }
224
- }
225
288
 
226
- if (is_break) {
227
- break;
289
+ if (is_break) {
290
+ break;
291
+ }
228
292
  }
229
- }
230
293
 
231
- if (left_pos <= 40 && is_break === false) {
232
- for (let k in this.collision_left[vpos]) {
233
- let l = this.collision_left[vpos][k];
234
-
235
- if (posY < data[l].posY + data[l].height && posY + comment.height > data[l].posY && data[l].owner === comment.owner) {
236
- if (data[l].posY + data[l].height > posY) {
237
- posY = data[l].posY + data[l].height;
238
- is_change = true;
239
- }
294
+ if (left_pos <= 40 && is_break === false) {
295
+ for (let k in this.collision_left[vpos]) {
296
+ let l = this.collision_left[vpos][k];
240
297
 
241
- if (posY + comment.height > 1080) {
242
- if (1080 < comment.height) {
243
- posY = 0;
244
- } else {
245
- posY = Math.random() * (1080 - comment.height);
298
+ if (posY < data[l].posY + data[l].height && posY + comment.height > data[l].posY && data[l].owner === comment.owner) {
299
+ if (data[l].posY + data[l].height > posY) {
300
+ posY = data[l].posY + data[l].height;
301
+ is_change = true;
246
302
  }
247
303
 
248
- is_break = true;
249
- break;
304
+ if (posY + comment.height > 1080) {
305
+ if (1080 < comment.height) {
306
+ posY = 0;
307
+ } else {
308
+ posY = Math.random() * (1080 - comment.height);
309
+ }
310
+
311
+ is_break = true;
312
+ break;
313
+ }
250
314
  }
251
315
  }
316
+
317
+ if (is_break) {
318
+ break;
319
+ }
252
320
  }
253
321
 
254
322
  if (is_break) {
255
323
  break;
256
324
  }
257
325
  }
258
-
259
- if (is_break) {
260
- break;
261
- }
262
326
  }
263
327
  }
264
328
 
@@ -325,7 +389,7 @@
325
389
  }
326
390
  }
327
391
 
328
- for (let j = 0; j < 300; j++) {
392
+ for (let j = 0; j < comment.long; j++) {
329
393
  let vpos = comment.vpos + j;
330
394
  arrayPush(this.timeline, vpos, i);
331
395
 
@@ -349,20 +413,31 @@
349
413
 
350
414
 
351
415
  measureText(comment) {
352
- let msg = comment.content;
353
-
354
- if (!comment.defaultFontSize) {
355
- comment.defaultFontSize = comment.fontSize;
356
- } else {
357
- this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
358
- }
359
-
360
416
  let width,
361
417
  width_max,
362
418
  width_min,
363
419
  height,
364
420
  width_arr = [],
365
- lines = msg.split("\n");
421
+ lines = comment.content.split("\n");
422
+
423
+ if (!comment.resized && !comment.ender) {
424
+ if (comment.size === "big" && lines.length > 2) {
425
+ comment.fontSize = this.fontSize.big.resized;
426
+ comment.resized = true;
427
+ comment.tateRisized = true;
428
+ this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
429
+ } else if (comment.size === "medium" && lines.length > 4) {
430
+ comment.fontSize = this.fontSize.medium.resized;
431
+ comment.resized = true;
432
+ comment.tateRisized = true;
433
+ this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
434
+ } else if (comment.size === "small" && lines.length > 6) {
435
+ comment.fontSize = this.fontSize.small.resized;
436
+ comment.resized = true;
437
+ comment.tateRisized = true;
438
+ this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
439
+ }
440
+ }
366
441
 
367
442
  for (let i = 0; i < lines.length; i++) {
368
443
  let measure = this.context.measureText(lines[i]);
@@ -372,22 +447,35 @@
372
447
  width = width_arr.reduce((p, c) => p + c, 0) / width_arr.length;
373
448
  width_max = Math.max(...width_arr);
374
449
  width_min = Math.min(...width_arr);
375
- height = comment.fontSize * (this.commentYMarginTop + 1) * lines.length;
450
+ height = (comment.fontSize + this.commentYMarginTop * comment.fontSize) * lines.length;
376
451
 
377
- if (height > 1080) {
378
- comment.fontSize -= 1;
379
- comment.resized = true;
380
- this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
381
- return this.measureText(comment);
382
- } else if (comment.loc !== "naka" && (lines.length < 3 && comment.size === "big" || lines.length < 5 && comment.size === "medium" || lines.length < 7 && comment.size === "small" || comment.ender)) {
383
- if (comment.full && width > 1920) {
452
+ if (comment.loc !== "naka" && !comment.tateRisized) {
453
+ if (comment.full && width_max > 1920) {
384
454
  comment.fontSize -= 1;
385
455
  comment.resized = true;
456
+ comment.yokoResized = true;
386
457
  this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
387
458
  return this.measureText(comment);
388
- } else if (!comment.full && width > 1440) {
459
+ } else if (!comment.full && width_max > 1440) {
389
460
  comment.fontSize -= 1;
390
461
  comment.resized = true;
462
+ comment.yokoResized = true;
463
+ this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
464
+ return this.measureText(comment);
465
+ }
466
+ } else if (comment.loc !== "naka" && comment.tateRisized && (comment.full && width_max > 1920 || !comment.full && width_max > 1440) && !comment.yokoResized) {
467
+ comment.fontSize = this.fontSize[comment.size].default;
468
+ comment.resized = true;
469
+ comment.yokoResized = true;
470
+ this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
471
+ return this.measureText(comment);
472
+ } else if (comment.loc !== "naka" && comment.tateRisized && comment.yokoResized) {
473
+ if (comment.full && width_max > this.doubleResizeMaxWidth.full[this.useLegacy ? "legacy" : "default"]) {
474
+ comment.fontSize -= 1;
475
+ this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
476
+ return this.measureText(comment);
477
+ } else if (!comment.full && width_max > this.doubleResizeMaxWidth.normal[this.useLegacy ? "legacy" : "default"]) {
478
+ comment.fontSize -= 1.;
391
479
  this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
392
480
  return this.measureText(comment);
393
481
  }
@@ -433,30 +521,10 @@
433
521
  } else {
434
522
  posX = 1920 - (1920 + comment.width_max) * (vpos - comment.vpos) / 500;
435
523
  }
436
-
437
- for (let i in lines) {
438
- let line = lines[i];
439
- let posY = comment.posY + i * comment.fontSize * (1 + this.commentYMarginTop) + this.commentYOffset * comment.fontSize;
440
- this.context.strokeText(line, posX, posY);
441
- this.context.fillText(line, posX, posY);
442
- }
443
- } else if (comment.loc === "ue") {
444
- for (let i in lines) {
445
- let line = lines[i];
446
- this.context.strokeText(line, posX, comment.posY + i * comment.fontSize + this.commentYOffset * comment.fontSize + this.commentYMarginTop * comment.fontSize);
447
- this.context.fillText(line, posX, comment.posY + i * comment.fontSize + this.commentYOffset * comment.fontSize + this.commentYMarginTop * comment.fontSize);
448
- }
449
- } else if (comment.loc === "shita") {
450
- for (let i in lines) {
451
- let line = lines[i];
452
- let posY = 1080 - (comment.posY + comment.height) + i * comment.fontSize - this.commentYMarginTop * comment.fontSize + this.commentYMarginTop * comment.fontSize;
453
- this.context.strokeText(line, posX, posY);
454
- this.context.fillText(line, posX, posY);
455
- }
456
524
  }
457
525
 
458
526
  if (this.showCollision) {
459
- this.context.strokeStyle = "rgba(255,255,0,1)";
527
+ this.context.strokeStyle = "rgba(0,255,255,1)";
460
528
 
461
529
  if (comment.loc === "shita") {
462
530
  this.context.strokeRect(posX, 1080 - comment.posY - comment.height, comment.width_max, comment.height);
@@ -464,59 +532,67 @@
464
532
  this.context.strokeRect(posX, comment.posY, comment.width_max, comment.height);
465
533
  }
466
534
 
467
- this.context.strokeStyle = "rgba(0,0,0,0.7)";
535
+ if (comment.color === "#000000") {
536
+ this.context.strokeStyle = "rgba(255,255,255,0.7)";
537
+ } else {
538
+ this.context.strokeStyle = "rgba(0,0,0,0.7)";
539
+ }
540
+ }
541
+
542
+ for (let i in lines) {
543
+ let line = lines[i],
544
+ posY;
545
+
546
+ if (comment.loc === "shita") {
547
+ posY = 1080 - comment.posY + i * (comment.fontSize + this.commentYMarginTop * comment.fontSize) - comment.height + this.commentYOffset * comment.fontSize;
548
+ } else {
549
+ posY = comment.posY + i * (comment.fontSize + this.commentYMarginTop * comment.fontSize) + this.commentYOffset * comment.fontSize;
550
+ }
551
+
552
+ this.context.strokeText(line, posX, posY);
553
+ this.context.fillText(line, posX, posY);
554
+
555
+ if (this.showCollision) {
556
+ this.context.strokeStyle = "rgba(255,255,0,0.5)";
557
+ this.context.strokeRect(posX, posY, comment.width_max, comment.fontSize);
558
+
559
+ if (comment.color === "#000000") {
560
+ this.context.strokeStyle = "rgba(255,255,255,0.7)";
561
+ } else {
562
+ this.context.strokeStyle = "rgba(0,0,0,0.7)";
563
+ }
564
+ }
468
565
  }
469
566
  }
470
567
  /**
471
568
  * コメントに含まれるコマンドを解釈する
472
569
  * @param comment- 独自フォーマットのコメントデータ
473
- * @returns {{loc: string, size: string, color: string, fontSize: number, ender: boolean, font: string, full: boolean}}
570
+ * @returns {{loc: string|null, size: string|null, color: string|null, fontSize: number|null, ender: boolean, font: string|null, full: boolean, _live: boolean, invisible: boolean, long:number|null}}
474
571
  */
475
572
 
476
573
 
477
574
  parseCommand(comment) {
478
575
  let metadata = comment.mail,
479
- loc = "naka",
480
- size = "medium",
481
- fontSize = 70,
482
- color = "#FFFFFF",
483
- font = 'defont',
576
+ loc = null,
577
+ size = null,
578
+ fontSize = null,
579
+ color = null,
580
+ font = null,
484
581
  full = false,
485
582
  ender = false,
486
- reverse = comment.content.match(/@逆 ?(全|コメ|投コメ)?/);
583
+ _live = false,
584
+ invisible = false,
585
+ long = null;
487
586
 
488
- if (reverse) {
489
- if (!reverse[1]) {
490
- reverse[1] = "全";
491
- }
492
-
493
- let length = false;
494
-
495
- for (let i in metadata) {
496
- let match = metadata[i].match(/@([0-9]+)/);
497
-
498
- if (match) {
499
- length = match[1];
500
- break;
501
- }
502
- }
587
+ for (let i in metadata) {
588
+ let command = metadata[i].toLowerCase();
589
+ const match = command.match(/^@([0-9.]+)/);
503
590
 
504
- if (!length) {
505
- length = 30;
591
+ if (match) {
592
+ long = match[1];
506
593
  }
507
594
 
508
- this.nicoScripts.reverse.push({
509
- "start": comment.vpos,
510
- "end": comment.vpos + length * 100,
511
- "target": reverse[1]
512
- });
513
- fontSize = 0;
514
- }
515
-
516
- for (let i in metadata) {
517
- let command = metadata[i];
518
-
519
- if (loc === "naka") {
595
+ if (loc === null) {
520
596
  switch (command) {
521
597
  case "ue":
522
598
  loc = "ue";
@@ -528,22 +604,26 @@
528
604
  }
529
605
  }
530
606
 
531
- if (size === "medium") {
607
+ if (size === null) {
532
608
  switch (command) {
533
609
  case "big":
534
610
  size = "big";
535
- fontSize = 100;
611
+ fontSize = this.fontSize.big.default;
536
612
  break;
537
613
 
538
614
  case "small":
539
615
  size = "small";
540
- fontSize = 50;
616
+ fontSize = this.fontSize.small.default;
541
617
  break;
542
618
  }
543
619
  }
544
620
 
545
- if (color === "#FFFFFF") {
621
+ if (color === null) {
546
622
  switch (command) {
623
+ case "white":
624
+ color = "#FFFFFF";
625
+ break;
626
+
547
627
  case "red":
548
628
  color = "#FF0000";
549
629
  break;
@@ -628,16 +708,17 @@
628
708
  break;
629
709
 
630
710
  default:
631
- const match = command.match(/#[0-9a-zA-Z]{3,6}/);
711
+ const match = command.match(/#[0-9a-z]{3,6}/);
632
712
 
633
- if (match) {
634
- color = match[0];
713
+ if (match && comment.premium) {
714
+ color = match[0].toUpperCase();
635
715
  }
636
716
 
717
+ break;
637
718
  }
638
719
  }
639
720
 
640
- if (font === 'defont') {
721
+ if (font === null) {
641
722
  switch (command) {
642
723
  case "gothic":
643
724
  font = "gothic";
@@ -657,6 +738,14 @@
657
738
  case "ender":
658
739
  ender = true;
659
740
  break;
741
+
742
+ case "_live":
743
+ _live = true;
744
+ break;
745
+
746
+ case "invisible":
747
+ invisible = true;
748
+ break;
660
749
  }
661
750
  }
662
751
 
@@ -667,9 +756,107 @@
667
756
  color,
668
757
  font,
669
758
  full,
670
- ender
759
+ ender,
760
+ _live,
761
+ invisible,
762
+ long
671
763
  };
672
764
  }
765
+
766
+ parseCommandAndNicoscript(comment) {
767
+ let data = this.parseCommand(comment),
768
+ nicoscript = comment.content.match(/^@(デフォルト|置換|逆|コメント禁止|シーク禁止|ジャンプ)/);
769
+
770
+ if (nicoscript) {
771
+ switch (nicoscript[1]) {
772
+ case "デフォルト":
773
+ this.nicoScripts.default.push({
774
+ start: comment.vpos,
775
+ long: data.long === null ? null : Math.floor(data.long * 100),
776
+ color: data.color,
777
+ size: data.size,
778
+ font: data.font,
779
+ loc: data.loc
780
+ });
781
+ break;
782
+
783
+ case "逆":
784
+ let reverse = comment.content.match(/^@逆 ?(全|コメ|投コメ)?/);
785
+
786
+ if (!reverse[1]) {
787
+ reverse[1] = "全";
788
+ }
789
+
790
+ if (data.long === null) {
791
+ data.long = 30;
792
+ }
793
+
794
+ this.nicoScripts.reverse.push({
795
+ "start": comment.vpos,
796
+ "end": comment.vpos + data.long * 100,
797
+ "target": reverse[1]
798
+ });
799
+ break;
800
+ }
801
+
802
+ data.invisible = true;
803
+ }
804
+
805
+ let color = "#FFFFFF",
806
+ size = "medium",
807
+ font = "defont",
808
+ loc = "naka";
809
+
810
+ for (let i in this.nicoScripts.default) {
811
+ if (this.nicoScripts.default[i].long !== null && this.nicoScripts.default[i].start + this.nicoScripts.default[i].long < comment.vpos) {
812
+ this.nicoScripts.default = this.nicoScripts.default.splice(Number(i), 1);
813
+ continue;
814
+ }
815
+
816
+ if (this.nicoScripts.default[i].loc) {
817
+ loc = this.nicoScripts.default[i].loc;
818
+ }
819
+
820
+ if (this.nicoScripts.default[i].color) {
821
+ color = this.nicoScripts.default[i].color;
822
+ }
823
+
824
+ if (this.nicoScripts.default[i].size) {
825
+ size = this.nicoScripts.default[i].size;
826
+ }
827
+
828
+ if (this.nicoScripts.default[i].font) {
829
+ font = this.nicoScripts.default[i].font;
830
+ }
831
+ }
832
+
833
+ if (!data.loc) {
834
+ data.loc = loc;
835
+ }
836
+
837
+ if (!data.color) {
838
+ data.color = color;
839
+ }
840
+
841
+ if (!data.size) {
842
+ data.size = size;
843
+ data.fontSize = this.fontSize[data.size].default;
844
+ }
845
+
846
+ if (!data.font) {
847
+ data.font = font;
848
+ }
849
+
850
+ if (data.loc !== "naka") {
851
+ if (!data.long) {
852
+ data.long = 300;
853
+ } else {
854
+ data.long = Math.floor(data.long * 100);
855
+ }
856
+ }
857
+
858
+ return data;
859
+ }
673
860
  /**
674
861
  * キャンバスを描画する
675
862
  * @param vpos - 動画の現在位置の100倍 ニコニコから吐き出されるコメントの位置情報は主にこれ
@@ -680,19 +867,32 @@
680
867
  this.fpsCount++;
681
868
  this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
682
869
 
683
- for (let index in this.timeline[vpos]) {
684
- let comment = this.data[this.timeline[vpos][index]];
685
- this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
686
- this.context.fillStyle = comment.color;
870
+ if (this.timeline[vpos]) {
871
+ for (let index in this.timeline[vpos]) {
872
+ let comment = this.data[this.timeline[vpos][index]];
687
873
 
688
- if (comment.color === "#000000") {
689
- this.context.strokeStyle = "rgba(255,255,255,0.7)";
690
- }
874
+ if (comment.invisible) {
875
+ continue;
876
+ }
691
877
 
692
- this.drawText(comment, vpos);
878
+ this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
693
879
 
694
- if (comment.color === "#000000") {
695
- this.context.strokeStyle = "rgba(0,0,0,0.7)";
880
+ if (comment._live) {
881
+ let rgb = hex2rgb(comment.color);
882
+ this.context.fillStyle = `rgba(${rgb[0]},${rgb[1]},${rgb[2]},0.5)`;
883
+ } else {
884
+ this.context.fillStyle = comment.color;
885
+ }
886
+
887
+ if (comment.color === "#000000") {
888
+ this.context.strokeStyle = "rgba(255,255,255,0.7)";
889
+ }
890
+
891
+ this.drawText(comment, vpos);
892
+
893
+ if (comment.color === "#000000") {
894
+ this.context.strokeStyle = "rgba(0,0,0,0.7)";
895
+ }
696
896
  }
697
897
  }
698
898
 
@@ -792,6 +992,20 @@
792
992
 
793
993
  array[key].push(push);
794
994
  };
995
+ /**
996
+ * Hexからrgbに変換する(_live用)
997
+ * @param {string} hex
998
+ * @return {array} RGB
999
+ */
1000
+
1001
+
1002
+ const hex2rgb = hex => {
1003
+ if (hex.slice(0, 1) === "#") hex = hex.slice(1);
1004
+ if (hex.length === 3) hex = hex.slice(0, 1) + hex.slice(0, 1) + hex.slice(1, 2) + hex.slice(1, 2) + hex.slice(2, 3) + hex.slice(2, 3);
1005
+ return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map(function (str) {
1006
+ return parseInt(str, 16);
1007
+ });
1008
+ };
795
1009
 
796
1010
  return NiconiComments;
797
1011
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xpadev-net/niconicomments",
3
- "version": "0.0.11",
3
+ "version": "0.1.5",
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
6
  "scripts": {