@xpadev-net/niconicomments 0.2.5 → 0.2.6
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 +40 -154
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
niconicomments.js v0.2.
|
|
2
|
+
niconicomments.js v0.2.6
|
|
3
3
|
(c) 2021 xpadev-net https://xpadev.net
|
|
4
4
|
Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -9,34 +9,6 @@
|
|
|
9
9
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.NiconiComments = factory());
|
|
10
10
|
})(this, (function () { 'use strict';
|
|
11
11
|
|
|
12
|
-
/*! *****************************************************************************
|
|
13
|
-
Copyright (c) Microsoft Corporation.
|
|
14
|
-
|
|
15
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
16
|
-
purpose with or without fee is hereby granted.
|
|
17
|
-
|
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
19
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
20
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
21
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
22
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
23
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
24
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
25
|
-
***************************************************************************** */
|
|
26
|
-
var __assign = function () {
|
|
27
|
-
__assign = Object.assign || function __assign(t) {
|
|
28
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
29
|
-
s = arguments[i];
|
|
30
|
-
|
|
31
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return __assign.apply(this, arguments);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
12
|
var NiconiComments = (function () {
|
|
41
13
|
function NiconiComments(canvas, data, options) {
|
|
42
14
|
if (options === void 0) { options = {
|
|
@@ -68,7 +40,7 @@
|
|
|
68
40
|
},
|
|
69
41
|
"big": {
|
|
70
42
|
"default": 111,
|
|
71
|
-
"resized":
|
|
43
|
+
"resized": 61
|
|
72
44
|
}
|
|
73
45
|
};
|
|
74
46
|
this.doubleResizeMaxWidth = {
|
|
@@ -87,7 +59,7 @@
|
|
|
87
59
|
this.showFPS = options.showFPS;
|
|
88
60
|
this.showCommentCount = options.showCommentCount;
|
|
89
61
|
this.timeline = {};
|
|
90
|
-
this.nicoScripts = { reverse: [], "default": []
|
|
62
|
+
this.nicoScripts = { "reverse": [], "default": [] };
|
|
91
63
|
this.collision_right = {};
|
|
92
64
|
this.collision_left = {};
|
|
93
65
|
this.collision_ue = {};
|
|
@@ -107,7 +79,7 @@
|
|
|
107
79
|
for (var i = 0; i < data.length; i++) {
|
|
108
80
|
for (var key in data[i]) {
|
|
109
81
|
var value = data[i][key];
|
|
110
|
-
if (key === "chat" && value["deleted"] !== 1) {
|
|
82
|
+
if (key === "chat" && value["deleted"] !== 1 && !value["content"].startsWith("/")) {
|
|
111
83
|
var tmpParam = {
|
|
112
84
|
"id": value["no"],
|
|
113
85
|
"vpos": value["vpos"],
|
|
@@ -121,9 +93,6 @@
|
|
|
121
93
|
if (value["mail"]) {
|
|
122
94
|
tmpParam["mail"] = value["mail"].split(/[\s ]/g);
|
|
123
95
|
}
|
|
124
|
-
if (value["content"].startsWith("/") && !value["user_id"]) {
|
|
125
|
-
tmpParam["mail"].push("invisible");
|
|
126
|
-
}
|
|
127
96
|
data_.push(tmpParam);
|
|
128
97
|
}
|
|
129
98
|
}
|
|
@@ -146,7 +115,9 @@
|
|
|
146
115
|
return data_;
|
|
147
116
|
};
|
|
148
117
|
NiconiComments.prototype.preRendering = function (rawData, drawAll) {
|
|
149
|
-
|
|
118
|
+
rawData = this.getFont(rawData);
|
|
119
|
+
rawData = this.getCommentSize(rawData);
|
|
120
|
+
var parsedData = this.getCommentPos(rawData);
|
|
150
121
|
this.data = this.sortComment(parsedData);
|
|
151
122
|
if (drawAll) {
|
|
152
123
|
for (var i in parsedData) {
|
|
@@ -155,15 +126,27 @@
|
|
|
155
126
|
}
|
|
156
127
|
};
|
|
157
128
|
NiconiComments.prototype.getFont = function (parsedData) {
|
|
158
|
-
var result = [];
|
|
159
129
|
for (var i in parsedData) {
|
|
160
|
-
|
|
130
|
+
var comment = parsedData[i];
|
|
131
|
+
var command = this.parseCommandAndNicoscript(comment);
|
|
132
|
+
parsedData[i].loc = command.loc;
|
|
133
|
+
parsedData[i].size = command.size;
|
|
134
|
+
parsedData[i].fontSize = command.fontSize;
|
|
135
|
+
parsedData[i].font = command.font;
|
|
136
|
+
parsedData[i].color = command.color;
|
|
137
|
+
parsedData[i].full = command.full;
|
|
138
|
+
parsedData[i].ender = command.ender;
|
|
139
|
+
parsedData[i]._live = command._live;
|
|
140
|
+
parsedData[i].long = command.long;
|
|
141
|
+
parsedData[i].invisible = command.invisible;
|
|
142
|
+
parsedData[i].content = parsedData[i].content.replaceAll("\t", "\u2003\u2003");
|
|
143
|
+
if (parsedData[i].content.match(/\s{4,}/))
|
|
144
|
+
console.log(parsedData[i], parsedData[i].content.replace(/\t/g, "\u2003\u2003"));
|
|
161
145
|
}
|
|
162
|
-
return
|
|
146
|
+
return parsedData;
|
|
163
147
|
};
|
|
164
148
|
NiconiComments.prototype.getCommentSize = function (parsedData) {
|
|
165
149
|
var tmpData = groupBy(parsedData, "font", "fontSize");
|
|
166
|
-
var result = [];
|
|
167
150
|
for (var i in tmpData) {
|
|
168
151
|
for (var j in tmpData[i]) {
|
|
169
152
|
this.context.font = parseFont(i, j, this.useLegacy);
|
|
@@ -173,19 +156,18 @@
|
|
|
173
156
|
continue;
|
|
174
157
|
}
|
|
175
158
|
var measure = this.measureText(comment);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
result[comment.index].width_min = measure.width_min;
|
|
159
|
+
parsedData[comment.index].height = measure.height;
|
|
160
|
+
parsedData[comment.index].width = measure.width;
|
|
161
|
+
parsedData[comment.index].width_max = measure.width_max;
|
|
162
|
+
parsedData[comment.index].width_min = measure.width_min;
|
|
181
163
|
if (measure.resized) {
|
|
182
|
-
|
|
164
|
+
parsedData[comment.index].fontSize = measure.fontSize;
|
|
183
165
|
this.context.font = parseFont(i, j, this.useLegacy);
|
|
184
166
|
}
|
|
185
167
|
}
|
|
186
168
|
}
|
|
187
169
|
}
|
|
188
|
-
return
|
|
170
|
+
return parsedData;
|
|
189
171
|
};
|
|
190
172
|
NiconiComments.prototype.getCommentPos = function (parsedData) {
|
|
191
173
|
var data = parsedData;
|
|
@@ -368,19 +350,19 @@
|
|
|
368
350
|
if (comment.size === "big" && lines.length > 2) {
|
|
369
351
|
comment.fontSize = this.fontSize.big.resized;
|
|
370
352
|
comment.resized = true;
|
|
371
|
-
comment.
|
|
353
|
+
comment.tateRisized = true;
|
|
372
354
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
373
355
|
}
|
|
374
356
|
else if (comment.size === "medium" && lines.length > 4) {
|
|
375
357
|
comment.fontSize = this.fontSize.medium.resized;
|
|
376
358
|
comment.resized = true;
|
|
377
|
-
comment.
|
|
359
|
+
comment.tateRisized = true;
|
|
378
360
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
379
361
|
}
|
|
380
362
|
else if (comment.size === "small" && lines.length > 6) {
|
|
381
363
|
comment.fontSize = this.fontSize.small.resized;
|
|
382
364
|
comment.resized = true;
|
|
383
|
-
comment.
|
|
365
|
+
comment.tateRisized = true;
|
|
384
366
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
385
367
|
}
|
|
386
368
|
}
|
|
@@ -392,9 +374,9 @@
|
|
|
392
374
|
width_max = Math.max.apply(Math, width_arr);
|
|
393
375
|
width_min = Math.min.apply(Math, width_arr);
|
|
394
376
|
height = (comment.fontSize * (1 + this.commentYPaddingTop) * lines.length) + (this.commentYMarginBottom * comment.fontSize);
|
|
395
|
-
if (comment.loc !== "naka" && !comment.
|
|
377
|
+
if (comment.loc !== "naka" && !comment.tateRisized) {
|
|
396
378
|
if (comment.full && width_max > 1920) {
|
|
397
|
-
comment.fontSize -=
|
|
379
|
+
comment.fontSize -= 2;
|
|
398
380
|
comment.resized = true;
|
|
399
381
|
comment.yokoResized = true;
|
|
400
382
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
@@ -408,14 +390,14 @@
|
|
|
408
390
|
return this.measureText(comment);
|
|
409
391
|
}
|
|
410
392
|
}
|
|
411
|
-
else if (comment.loc !== "naka" && comment.
|
|
393
|
+
else if (comment.loc !== "naka" && comment.tateRisized && (comment.full && width_max > 1920 || !comment.full && width_max > 1440) && !comment.yokoResized) {
|
|
412
394
|
comment.fontSize = this.fontSize[comment.size]["default"];
|
|
413
395
|
comment.resized = true;
|
|
414
396
|
comment.yokoResized = true;
|
|
415
397
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
416
398
|
return this.measureText(comment);
|
|
417
399
|
}
|
|
418
|
-
else if (comment.loc !== "naka" && comment.
|
|
400
|
+
else if (comment.loc !== "naka" && comment.tateRisized && comment.yokoResized) {
|
|
419
401
|
if (comment.full && width_max > this.doubleResizeMaxWidth.full[this.useLegacy ? "legacy" : "default"]) {
|
|
420
402
|
comment.fontSize -= 1;
|
|
421
403
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
@@ -447,12 +429,6 @@
|
|
|
447
429
|
reverse = true;
|
|
448
430
|
}
|
|
449
431
|
}
|
|
450
|
-
for (var i in this.nicoScripts.ban) {
|
|
451
|
-
var range = this.nicoScripts.ban[i];
|
|
452
|
-
if (range.start < vpos && vpos < range.end) {
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
432
|
var posX = (1920 - comment.width_max) / 2, posY = comment.posY;
|
|
457
433
|
if (comment.loc === "naka") {
|
|
458
434
|
if (reverse) {
|
|
@@ -655,7 +631,6 @@
|
|
|
655
631
|
return { loc: loc, size: size, fontSize: fontSize, color: color, font: font, full: full, ender: ender, _live: _live, invisible: invisible, long: long };
|
|
656
632
|
};
|
|
657
633
|
NiconiComments.prototype.parseCommandAndNicoscript = function (comment) {
|
|
658
|
-
comment.content = comment.content.replace("/\t/g", " ");
|
|
659
634
|
var data = this.parseCommand(comment), nicoscript = comment.content.match(/^@(デフォルト|置換|逆|コメント禁止|シーク禁止|ジャンプ)/);
|
|
660
635
|
if (nicoscript) {
|
|
661
636
|
switch (nicoscript[1]) {
|
|
@@ -678,61 +653,9 @@
|
|
|
678
653
|
data.long = 30;
|
|
679
654
|
}
|
|
680
655
|
this.nicoScripts.reverse.push({
|
|
681
|
-
start: comment.vpos,
|
|
682
|
-
end: comment.vpos + (data.long * 100),
|
|
683
|
-
target: reverse[1]
|
|
684
|
-
});
|
|
685
|
-
break;
|
|
686
|
-
case "コメント禁止":
|
|
687
|
-
if (data.long === null) {
|
|
688
|
-
data.long = 30;
|
|
689
|
-
}
|
|
690
|
-
this.nicoScripts.reverse.push({
|
|
691
|
-
start: comment.vpos,
|
|
692
|
-
end: comment.vpos + (data.long * 100)
|
|
693
|
-
});
|
|
694
|
-
break;
|
|
695
|
-
case "置換":
|
|
696
|
-
var content = comment.content.split(""), quote = "", last_i = "", string = "", result = [];
|
|
697
|
-
for (var _i = 0, _a = content.slice(4); _i < _a.length; _i++) {
|
|
698
|
-
var i = _a[_i];
|
|
699
|
-
if (i.match(/["'「]/) && quote === "") {
|
|
700
|
-
quote = i;
|
|
701
|
-
}
|
|
702
|
-
else if (i.match(/["']/) && quote === i && last_i !== "\\") {
|
|
703
|
-
result.push(replaceAll(string, "\\n", "\n"));
|
|
704
|
-
quote = "";
|
|
705
|
-
string = "";
|
|
706
|
-
}
|
|
707
|
-
else if (i.match(/」/) && quote === "「") {
|
|
708
|
-
result.push(string);
|
|
709
|
-
quote = "";
|
|
710
|
-
string = "";
|
|
711
|
-
}
|
|
712
|
-
else if (quote === "" && i.match(/[\s ]/)) {
|
|
713
|
-
if (string) {
|
|
714
|
-
result.push(string);
|
|
715
|
-
string = "";
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
else {
|
|
719
|
-
string += i;
|
|
720
|
-
}
|
|
721
|
-
last_i = i;
|
|
722
|
-
}
|
|
723
|
-
result.push(string);
|
|
724
|
-
this.nicoScripts.replace.push({
|
|
725
|
-
start: comment.vpos,
|
|
726
|
-
long: data.long === null ? null : Math.floor(data.long * 100),
|
|
727
|
-
keyword: result[0],
|
|
728
|
-
replace: result[1] || "",
|
|
729
|
-
range: result[2] || "単",
|
|
730
|
-
target: result[3] || "コメ",
|
|
731
|
-
condition: result[4] || "部分一致",
|
|
732
|
-
color: data.color,
|
|
733
|
-
size: data.size,
|
|
734
|
-
font: data.font,
|
|
735
|
-
loc: data.loc
|
|
656
|
+
"start": comment.vpos,
|
|
657
|
+
"end": comment.vpos + (data.long * 100),
|
|
658
|
+
"target": reverse[1]
|
|
736
659
|
});
|
|
737
660
|
break;
|
|
738
661
|
}
|
|
@@ -757,35 +680,6 @@
|
|
|
757
680
|
font = this.nicoScripts["default"][i].font;
|
|
758
681
|
}
|
|
759
682
|
}
|
|
760
|
-
for (var i in this.nicoScripts.replace) {
|
|
761
|
-
if (this.nicoScripts.replace[i].long !== null && this.nicoScripts.replace[i].start + this.nicoScripts.replace[i].long < comment.vpos) {
|
|
762
|
-
this.nicoScripts["default"] = this.nicoScripts["default"].splice(Number(i), 1);
|
|
763
|
-
continue;
|
|
764
|
-
}
|
|
765
|
-
var item = this.nicoScripts.replace[i];
|
|
766
|
-
if ((item.target === "コメ" && comment.owner) || (item.target === "投コメ" && !comment.owner) || (item.target === "含まない" && comment.owner))
|
|
767
|
-
continue;
|
|
768
|
-
if ((item.condition === "完全一致" && comment.content === item.keyword) || (item.condition === "部分一致" && comment.content.indexOf(item.keyword) !== -1)) {
|
|
769
|
-
if (item.range === "単") {
|
|
770
|
-
comment.content = replaceAll(comment.content, item.keyword, item.replace);
|
|
771
|
-
}
|
|
772
|
-
else {
|
|
773
|
-
comment.content = item.replace;
|
|
774
|
-
}
|
|
775
|
-
if (item.loc) {
|
|
776
|
-
loc = item.loc;
|
|
777
|
-
}
|
|
778
|
-
if (item.color) {
|
|
779
|
-
color = item.color;
|
|
780
|
-
}
|
|
781
|
-
if (item.size) {
|
|
782
|
-
size = item.size;
|
|
783
|
-
}
|
|
784
|
-
if (item.font) {
|
|
785
|
-
font = item.font;
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
683
|
if (!data.loc) {
|
|
790
684
|
data.loc = loc;
|
|
791
685
|
}
|
|
@@ -807,7 +701,7 @@
|
|
|
807
701
|
data.long = Math.floor(data.long * 100);
|
|
808
702
|
}
|
|
809
703
|
}
|
|
810
|
-
return
|
|
704
|
+
return data;
|
|
811
705
|
};
|
|
812
706
|
NiconiComments.prototype.drawCanvas = function (vpos) {
|
|
813
707
|
if (this.lastVpos === vpos)
|
|
@@ -910,14 +804,6 @@
|
|
|
910
804
|
return parseInt(str, 16);
|
|
911
805
|
});
|
|
912
806
|
};
|
|
913
|
-
var replaceAll = function (string, target, replace) {
|
|
914
|
-
var count = 0;
|
|
915
|
-
while (string.indexOf(target) !== -1 && count < 100) {
|
|
916
|
-
string = string.replace(target, replace);
|
|
917
|
-
count++;
|
|
918
|
-
}
|
|
919
|
-
return string;
|
|
920
|
-
};
|
|
921
807
|
|
|
922
808
|
return NiconiComments;
|
|
923
809
|
|
package/package.json
CHANGED