@xpadev-net/niconicomments 0.2.7 → 0.2.8
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 +153 -39
- 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.8
|
|
3
3
|
(c) 2021 xpadev-net https://xpadev.net
|
|
4
4
|
Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -9,6 +9,34 @@
|
|
|
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
|
+
|
|
12
40
|
var NiconiComments = (function () {
|
|
13
41
|
function NiconiComments(canvas, data, options) {
|
|
14
42
|
if (options === void 0) { options = {
|
|
@@ -40,7 +68,7 @@
|
|
|
40
68
|
},
|
|
41
69
|
"big": {
|
|
42
70
|
"default": 111,
|
|
43
|
-
"resized":
|
|
71
|
+
"resized": 62
|
|
44
72
|
}
|
|
45
73
|
};
|
|
46
74
|
this.doubleResizeMaxWidth = {
|
|
@@ -59,7 +87,7 @@
|
|
|
59
87
|
this.showFPS = options.showFPS;
|
|
60
88
|
this.showCommentCount = options.showCommentCount;
|
|
61
89
|
this.timeline = {};
|
|
62
|
-
this.nicoScripts = {
|
|
90
|
+
this.nicoScripts = { reverse: [], "default": [], replace: [], ban: [] };
|
|
63
91
|
this.collision_right = {};
|
|
64
92
|
this.collision_left = {};
|
|
65
93
|
this.collision_ue = {};
|
|
@@ -79,7 +107,7 @@
|
|
|
79
107
|
for (var i = 0; i < data.length; i++) {
|
|
80
108
|
for (var key in data[i]) {
|
|
81
109
|
var value = data[i][key];
|
|
82
|
-
if (key === "chat" && value["deleted"] !== 1
|
|
110
|
+
if (key === "chat" && value["deleted"] !== 1) {
|
|
83
111
|
var tmpParam = {
|
|
84
112
|
"id": value["no"],
|
|
85
113
|
"vpos": value["vpos"],
|
|
@@ -93,6 +121,9 @@
|
|
|
93
121
|
if (value["mail"]) {
|
|
94
122
|
tmpParam["mail"] = value["mail"].split(/[\s ]/g);
|
|
95
123
|
}
|
|
124
|
+
if (value["content"].startsWith("/") && !value["user_id"]) {
|
|
125
|
+
tmpParam["mail"].push("invisible");
|
|
126
|
+
}
|
|
96
127
|
data_.push(tmpParam);
|
|
97
128
|
}
|
|
98
129
|
}
|
|
@@ -115,9 +146,7 @@
|
|
|
115
146
|
return data_;
|
|
116
147
|
};
|
|
117
148
|
NiconiComments.prototype.preRendering = function (rawData, drawAll) {
|
|
118
|
-
|
|
119
|
-
rawData = this.getCommentSize(rawData);
|
|
120
|
-
var parsedData = this.getCommentPos(rawData);
|
|
149
|
+
var parsedData = this.getCommentPos(this.getCommentSize(this.getFont(rawData)));
|
|
121
150
|
this.data = this.sortComment(parsedData);
|
|
122
151
|
if (drawAll) {
|
|
123
152
|
for (var i in parsedData) {
|
|
@@ -126,27 +155,16 @@
|
|
|
126
155
|
}
|
|
127
156
|
};
|
|
128
157
|
NiconiComments.prototype.getFont = function (parsedData) {
|
|
158
|
+
var result = [];
|
|
129
159
|
for (var i in parsedData) {
|
|
130
|
-
|
|
131
|
-
|
|
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"));
|
|
160
|
+
parsedData[i].content = parsedData[i].content.replace(/\t/g, "\u2003\u2003");
|
|
161
|
+
result[i] = this.parseCommandAndNicoscript(parsedData[i]);
|
|
145
162
|
}
|
|
146
|
-
return
|
|
163
|
+
return result;
|
|
147
164
|
};
|
|
148
165
|
NiconiComments.prototype.getCommentSize = function (parsedData) {
|
|
149
166
|
var tmpData = groupBy(parsedData, "font", "fontSize");
|
|
167
|
+
var result = [];
|
|
150
168
|
for (var i in tmpData) {
|
|
151
169
|
for (var j in tmpData[i]) {
|
|
152
170
|
this.context.font = parseFont(i, j, this.useLegacy);
|
|
@@ -156,18 +174,19 @@
|
|
|
156
174
|
continue;
|
|
157
175
|
}
|
|
158
176
|
var measure = this.measureText(comment);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
177
|
+
result[comment.index] = parsedData[comment.index];
|
|
178
|
+
result[comment.index].height = measure.height;
|
|
179
|
+
result[comment.index].width = measure.width;
|
|
180
|
+
result[comment.index].width_max = measure.width_max;
|
|
181
|
+
result[comment.index].width_min = measure.width_min;
|
|
163
182
|
if (measure.resized) {
|
|
164
|
-
|
|
183
|
+
result[comment.index].fontSize = measure.fontSize;
|
|
165
184
|
this.context.font = parseFont(i, j, this.useLegacy);
|
|
166
185
|
}
|
|
167
186
|
}
|
|
168
187
|
}
|
|
169
188
|
}
|
|
170
|
-
return
|
|
189
|
+
return result;
|
|
171
190
|
};
|
|
172
191
|
NiconiComments.prototype.getCommentPos = function (parsedData) {
|
|
173
192
|
var data = parsedData;
|
|
@@ -350,19 +369,19 @@
|
|
|
350
369
|
if (comment.size === "big" && lines.length > 2) {
|
|
351
370
|
comment.fontSize = this.fontSize.big.resized;
|
|
352
371
|
comment.resized = true;
|
|
353
|
-
comment.
|
|
372
|
+
comment.tateresized = true;
|
|
354
373
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
355
374
|
}
|
|
356
375
|
else if (comment.size === "medium" && lines.length > 4) {
|
|
357
376
|
comment.fontSize = this.fontSize.medium.resized;
|
|
358
377
|
comment.resized = true;
|
|
359
|
-
comment.
|
|
378
|
+
comment.tateresized = true;
|
|
360
379
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
361
380
|
}
|
|
362
381
|
else if (comment.size === "small" && lines.length > 6) {
|
|
363
382
|
comment.fontSize = this.fontSize.small.resized;
|
|
364
383
|
comment.resized = true;
|
|
365
|
-
comment.
|
|
384
|
+
comment.tateresized = true;
|
|
366
385
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
367
386
|
}
|
|
368
387
|
}
|
|
@@ -374,7 +393,7 @@
|
|
|
374
393
|
width_max = Math.max.apply(Math, width_arr);
|
|
375
394
|
width_min = Math.min.apply(Math, width_arr);
|
|
376
395
|
height = (comment.fontSize * (1 + this.commentYPaddingTop) * lines.length) + (this.commentYMarginBottom * comment.fontSize);
|
|
377
|
-
if (comment.loc !== "naka" && !comment.
|
|
396
|
+
if (comment.loc !== "naka" && !comment.tateresized) {
|
|
378
397
|
if (comment.full && width_max > 1920) {
|
|
379
398
|
comment.fontSize -= 2;
|
|
380
399
|
comment.resized = true;
|
|
@@ -390,14 +409,14 @@
|
|
|
390
409
|
return this.measureText(comment);
|
|
391
410
|
}
|
|
392
411
|
}
|
|
393
|
-
else if (comment.loc !== "naka" && comment.
|
|
412
|
+
else if (comment.loc !== "naka" && comment.tateresized && (comment.full && width_max > 1920 || !comment.full && width_max > 1440) && !comment.yokoResized) {
|
|
394
413
|
comment.fontSize = this.fontSize[comment.size]["default"];
|
|
395
414
|
comment.resized = true;
|
|
396
415
|
comment.yokoResized = true;
|
|
397
416
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
398
417
|
return this.measureText(comment);
|
|
399
418
|
}
|
|
400
|
-
else if (comment.loc !== "naka" && comment.
|
|
419
|
+
else if (comment.loc !== "naka" && comment.tateresized && comment.yokoResized) {
|
|
401
420
|
if (comment.full && width_max > this.doubleResizeMaxWidth.full[this.useLegacy ? "legacy" : "default"]) {
|
|
402
421
|
comment.fontSize -= 1;
|
|
403
422
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
@@ -429,6 +448,12 @@
|
|
|
429
448
|
reverse = true;
|
|
430
449
|
}
|
|
431
450
|
}
|
|
451
|
+
for (var i in this.nicoScripts.ban) {
|
|
452
|
+
var range = this.nicoScripts.ban[i];
|
|
453
|
+
if (range.start < vpos && vpos < range.end) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
432
457
|
var posX = (1920 - comment.width_max) / 2, posY = comment.posY;
|
|
433
458
|
if (comment.loc === "naka") {
|
|
434
459
|
if (reverse) {
|
|
@@ -653,9 +678,61 @@
|
|
|
653
678
|
data.long = 30;
|
|
654
679
|
}
|
|
655
680
|
this.nicoScripts.reverse.push({
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
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
|
|
659
736
|
});
|
|
660
737
|
break;
|
|
661
738
|
}
|
|
@@ -680,6 +757,35 @@
|
|
|
680
757
|
font = this.nicoScripts["default"][i].font;
|
|
681
758
|
}
|
|
682
759
|
}
|
|
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
|
+
}
|
|
683
789
|
if (!data.loc) {
|
|
684
790
|
data.loc = loc;
|
|
685
791
|
}
|
|
@@ -701,7 +807,7 @@
|
|
|
701
807
|
data.long = Math.floor(data.long * 100);
|
|
702
808
|
}
|
|
703
809
|
}
|
|
704
|
-
return data;
|
|
810
|
+
return __assign(__assign({}, comment), data);
|
|
705
811
|
};
|
|
706
812
|
NiconiComments.prototype.drawCanvas = function (vpos) {
|
|
707
813
|
if (this.lastVpos === vpos)
|
|
@@ -804,6 +910,14 @@
|
|
|
804
910
|
return parseInt(str, 16);
|
|
805
911
|
});
|
|
806
912
|
};
|
|
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
|
+
};
|
|
807
921
|
|
|
808
922
|
return NiconiComments;
|
|
809
923
|
|
package/package.json
CHANGED