@xpadev-net/niconicomments 0.1.5 → 0.1.9

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 +49 -9
  2. package/package.json +2 -4
package/dist/bundle.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- niconicomments.js v0.1.5
2
+ niconicomments.js v0.1.9
3
3
  (c) 2021 xpadev-net https://xpadevn.et
4
4
  Released under the MIT License.
5
5
  */
@@ -14,18 +14,21 @@
14
14
  * NiconiComments Constructor
15
15
  * @param {HTMLCanvasElement} canvas - 描画対象のキャンバス
16
16
  * @param {[]} data - 描画用のコメント
17
- * @param {boolean} useLegacy - defontにsans-serifを適用するか(trueでニコニコ公式に準拠)
18
- * @param {boolean} formatted - dataが独自フォーマットに変換されているか
17
+ * @param {{useLegacy: boolean, formatted: boolean, video: HTMLVideoElement|null}} options - 細かい設定類
19
18
  */
20
- constructor(canvas, data, useLegacy = false, formatted = false) {
19
+ constructor(canvas, data, options = {
20
+ useLegacy: false,
21
+ formatted: false,
22
+ video: null
23
+ }) {
21
24
  this.canvas = canvas;
22
25
  this.context = canvas.getContext("2d");
23
26
  this.context.strokeStyle = "rgba(0,0,0,0.7)";
24
27
  this.context.textAlign = "left";
25
28
  this.context.textBaseline = "top";
26
- this.context.lineWidth = 2;
29
+ this.context.lineWidth = 4;
27
30
 
28
- if (useLegacy) {
31
+ if (options.useLegacy) {
29
32
  this.commentYOffset = 0.25;
30
33
  } else {
31
34
  this.commentYOffset = 0.2;
@@ -68,12 +71,13 @@
68
71
  }
69
72
  };
70
73
 
71
- if (formatted) {
74
+ if (options.formatted) {
72
75
  this.data = data;
73
76
  } else {
74
77
  this.data = this.parseData(data);
75
78
  }
76
79
 
80
+ this.video = options.video ? options.video : null;
77
81
  this.showCollision = false;
78
82
  this.showFPS = false;
79
83
  this.showCommentCount = false;
@@ -86,7 +90,7 @@
86
90
  this.collision_left = {};
87
91
  this.collision_ue = {};
88
92
  this.collision_shita = {};
89
- this.useLegacy = useLegacy;
93
+ this.useLegacy = options.useLegacy;
90
94
  this.preRendering();
91
95
  this.fpsCount = 0;
92
96
  this.fps = 0;
@@ -109,7 +113,7 @@
109
113
  for (let key in data[i]) {
110
114
  let value = data[i][key];
111
115
 
112
- if (key === "chat" && value["deleted"] !== 1) {
116
+ if (key === "chat" && value["deleted"] !== 1 && !value["content"].startsWith("/")) {
113
117
  let tmpParam = {
114
118
  "id": value["no"],
115
119
  "vpos": value["vpos"],
@@ -151,6 +155,7 @@
151
155
  this.getFont();
152
156
  this.getCommentSize();
153
157
  this.getCommentPos();
158
+ this.sortComment();
154
159
  }
155
160
  /**
156
161
  * コマンドをもとに各コメントに適用するフォントを決定する
@@ -404,6 +409,23 @@
404
409
  }
405
410
  }
406
411
  }
412
+
413
+ sortComment() {
414
+ for (let vpos in this.timeline) {
415
+ this.timeline[vpos].sort((a, b) => {
416
+ const A = this.data[a];
417
+ const B = this.data[b];
418
+
419
+ if (!A.owner && B.owner) {
420
+ return -1;
421
+ } else if (A.owner && !B.owner) {
422
+ return 1;
423
+ } else {
424
+ return 0;
425
+ }
426
+ });
427
+ }
428
+ }
407
429
  /**
408
430
  * context.measureTextの複数行対応版
409
431
  * 画面外にはみ出すコメントの縮小も行う
@@ -867,6 +889,24 @@
867
889
  this.fpsCount++;
868
890
  this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
869
891
 
892
+ if (this.video) {
893
+ let offsetX,
894
+ offsetY,
895
+ scale,
896
+ height = this.canvas.height / this.video.videoHeight,
897
+ width = this.canvas.width / this.video.videoWidth;
898
+
899
+ if (height > width) {
900
+ scale = width;
901
+ } else {
902
+ scale = height;
903
+ }
904
+
905
+ offsetX = (this.canvas.width - this.video.videoWidth * scale) * 0.5;
906
+ offsetY = (this.canvas.height - this.video.videoHeight * scale) * 0.5;
907
+ this.context.drawImage(this.video, offsetX, offsetY, this.video.videoWidth * scale, this.video.videoHeight * scale);
908
+ }
909
+
870
910
  if (this.timeline[vpos]) {
871
911
  for (let index in this.timeline[vpos]) {
872
912
  let comment = this.data[this.timeline[vpos][index]];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xpadev-net/niconicomments",
3
- "version": "0.1.5",
3
+ "version": "0.1.9",
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": {
@@ -25,9 +25,7 @@
25
25
  "homepage": "https://xpadev.net/niconicomments/docs/",
26
26
  "license": "MIT",
27
27
  "devDependencies": {
28
- "rollup": "^2.61.1"
29
- },
30
- "dependencies": {
28
+ "rollup": "^2.61.1",
31
29
  "@rollup/plugin-babel": "^5.3.0"
32
30
  }
33
31
  }