@xpadev-net/niconicomments 0.2.32 → 0.2.33
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/README.ja.md +41 -0
- package/README.md +13 -14
- package/dist/bundle.d.ts +8 -5
- package/dist/bundle.js +332 -524
- package/package.json +11 -11
package/README.ja.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# [niconicomments](https://xpadev.net/niconicomments/)
|
|
2
|
+
[](https://github.com/xpadev-net/niconicomments/blob/master/LICENSE)
|
|
3
|
+
|
|
4
|
+
[English](https://github.com/xpadev-net/niconicomments/blob/develop/README.md)
|
|
5
|
+
|
|
6
|
+
ニコニコ動画の公式プレイヤー互換の高パフォーマンスなコメント描画ライブラリ
|
|
7
|
+
High peformance High compatibility comment drawing library
|
|
8
|
+
Reference: https://xpadev-net.github.io/niconicomments/
|
|
9
|
+
Github: https://github.com/xpadev-net/niconicomments
|
|
10
|
+
npm: https://www.npmjs.com/package/@xpadev-net/niconicomments
|
|
11
|
+
|
|
12
|
+
## [重要]このライブラリを使用される方へ
|
|
13
|
+
ニコニコ運営が画面にコメントを流すアドオンを特許侵害だと騒ぎ立てて潰して回っているようです
|
|
14
|
+
このライブラリ本体は描画部分のみのため特許侵害に当たるとは考えていませんが、ニコニコ動画運営(とその近辺の人)に叩かれる可能性があります
|
|
15
|
+
(名前は出しませんがすでにいくつかのOSSに被害が出ています)
|
|
16
|
+
また、このライブラリを使用するかどうかに関わらず、リアルタイムでコメントを取得、画面を描画、コメントの投稿という一連の流れを実装した場合、ニコニコの特許を侵害する可能性があります
|
|
17
|
+
詳しくはこちら[ニコニコが保有する特許について](https://github.com/xpadev-net/niconicomments/blob/develop/ABOUT_PATENT.md)を参照してください
|
|
18
|
+
**※当ライブラリを削除する予定は一切ありません**
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
```html
|
|
22
|
+
<script src="https://cdn.jsdelivr.net/npm/@xpadev-net/niconicomments@latest/dist/bundle.min.js"></script>
|
|
23
|
+
```
|
|
24
|
+
or
|
|
25
|
+
```
|
|
26
|
+
npm i @xpadev-net/niconicomments
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Examples
|
|
30
|
+
```javascript
|
|
31
|
+
const canvas = document.getElementById("canvas");
|
|
32
|
+
const video = document.getElementById("video");
|
|
33
|
+
const req = await fetch("sample.json");
|
|
34
|
+
const res = await req.json();
|
|
35
|
+
const niconiComments = new NiconiComments(canvas, res);
|
|
36
|
+
//video.ontimeupdateを使用すると、呼び出し回数の関係でコメントカクつく
|
|
37
|
+
setInterval(() => niconiComments.drawCanvas(Math.floor(video.currentTime * 100)), 10);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Sample
|
|
41
|
+
[サンプル](https://xpadev-net.github.io/niconicomments/sample/)
|
package/README.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
# [niconicomments](https://xpadev.net/niconicomments/)
|
|
2
2
|
[](https://github.com/xpadev-net/niconicomments/blob/master/LICENSE)
|
|
3
|
-
[](https://lgtm.com/projects/g/xpadev-net/niconicomments/alerts/)
|
|
4
|
-
[](https://lgtm.com/projects/g/xpadev-net/niconicomments/context:javascript)
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
[日本語](https://github.com/xpadev-net/niconicomments/blob/develop/README.ja.md)
|
|
5
|
+
|
|
6
|
+
Comment rendering library that is somewhat compatible with the official Nico Nico Douga player
|
|
8
7
|
Reference: https://xpadev-net.github.io/niconicomments/
|
|
9
8
|
Github: https://github.com/xpadev-net/niconicomments
|
|
10
9
|
npm: https://www.npmjs.com/package/@xpadev-net/niconicomments
|
|
11
10
|
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
## For users who use this library for domestic use in Japan
|
|
12
|
+
This library may infringe on Dwango's patents depending on how it is used
|
|
13
|
+
Please carefully review the following applicable patents and case law before using this library with caution.
|
|
14
|
+
[JP,2006-333851](https://www.j-platpat.inpit.go.jp/c1800/PU/JP-2006-333851/7294651F33633E1EBF3DEC66FAE0ECAD878D19E1829C378FC81D26BBD0A4263B/10/en)
|
|
15
|
+
[JP,2010-267283](https://www.j-platpat.inpit.go.jp/c1800/PU/JP-4734471/9085C128B7ED7D57F6C2F09D9BE4FCB496E638331DB9EC7ADE1E3A44999A3878/15/en)
|
|
16
|
+
[JP,2018-202475](https://www.j-platpat.inpit.go.jp/c1800/PU/JP-6526304/D8AF77CFB92D96C785FEECBD690C53E2F9023F1739E7A5BBDAB588E2ECAC5316/15/en)
|
|
17
|
+
[2018: Case No. Heisei 28 (wa) 38565, Patent Infringement Injunction, etc. Patent Right Civil Litigation](https://www.courts.go.jp/app/files/hanrei_jp/073/088073_hanrei.pdf)
|
|
18
|
+
[2022: Heisei 30 (ne) 10077 Appeal for Patent Infringement Injunction, etc. Patent Right Civil Litigation](https://www.courts.go.jp/app/files/hanrei_jp/418/091418_hanrei.pdf)
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
```html
|
|
@@ -33,10 +33,9 @@ const video = document.getElementById("video");
|
|
|
33
33
|
const req = await fetch("sample.json");
|
|
34
34
|
const res = await req.json();
|
|
35
35
|
const niconiComments = new NiconiComments(canvas, res);
|
|
36
|
-
//video.ontimeupdate
|
|
36
|
+
//If video.ontimeupdate is used, the comments will be choppy due to the small number of calls.
|
|
37
37
|
setInterval(() => niconiComments.drawCanvas(Math.floor(video.currentTime * 100)), 10);
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Sample
|
|
41
|
-
[
|
|
42
|
-
[CodePen](https://codepen.io/xpadev-net/pen/mdBdQmX)
|
|
41
|
+
[Sample](https://xpadev-net.github.io/niconicomments/sample/)
|
package/dist/bundle.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ declare class FlashComment implements IComment {
|
|
|
3
3
|
readonly comment: formattedCommentWithSize;
|
|
4
4
|
private readonly _globalScale;
|
|
5
5
|
private scale;
|
|
6
|
+
private scaleX;
|
|
6
7
|
posY: number;
|
|
7
8
|
image?: HTMLCanvasElement | null;
|
|
8
9
|
constructor(comment: formattedComment, context: CanvasRenderingContext2D);
|
|
@@ -43,7 +44,6 @@ declare class HTML5Comment implements IComment {
|
|
|
43
44
|
get owner(): boolean;
|
|
44
45
|
get mail(): string[];
|
|
45
46
|
get lineCount(): number;
|
|
46
|
-
parseCommand(comment: formattedComment): parsedCommand;
|
|
47
47
|
parseCommandAndNicoscript(comment: formattedComment): formattedCommentWithFont;
|
|
48
48
|
measureText(comment: measureTextInput): measureTextResult;
|
|
49
49
|
getCommentSize(parsedData: formattedCommentWithFont): formattedCommentWithSize;
|
|
@@ -245,8 +245,8 @@ type Config = {
|
|
|
245
245
|
canvasWidth: number;
|
|
246
246
|
collisionRange: { [key in "left" | "right"]: number };
|
|
247
247
|
colors: { [key: string]: string };
|
|
248
|
-
commentDrawPadding:
|
|
249
|
-
commentDrawRange:
|
|
248
|
+
commentDrawPadding: number;
|
|
249
|
+
commentDrawRange: number;
|
|
250
250
|
commentScale: configItem<number>;
|
|
251
251
|
commentStageSize: configItem<commentStageSize>;
|
|
252
252
|
commentYMarginBottom: configSizeItem<number>;
|
|
@@ -273,6 +273,8 @@ type Config = {
|
|
|
273
273
|
sameCAGap: number;
|
|
274
274
|
sameCAMinScore: number;
|
|
275
275
|
sameCARange: number;
|
|
276
|
+
letterSpacing: number;
|
|
277
|
+
scriptCharOffset: number;
|
|
276
278
|
};
|
|
277
279
|
|
|
278
280
|
type ConfigNullable = Partial<Config>;
|
|
@@ -646,7 +648,7 @@ declare const typeGuard: {
|
|
|
646
648
|
comments: (i: unknown) => i is ownerComment[];
|
|
647
649
|
};
|
|
648
650
|
v1: {
|
|
649
|
-
comment: (i: unknown) => i is
|
|
651
|
+
comment: (i: unknown) => i is v1Comment;
|
|
650
652
|
thread: (i: unknown) => i is v1Thread;
|
|
651
653
|
threads: (i: unknown) => i is v1Thread[];
|
|
652
654
|
};
|
|
@@ -679,7 +681,7 @@ declare const getPosY: (currentPos: number, targetComment: IComment, collision:
|
|
|
679
681
|
isChanged: boolean;
|
|
680
682
|
isBreak: boolean;
|
|
681
683
|
};
|
|
682
|
-
declare const getPosX: (width: number, vpos: number, long: number
|
|
684
|
+
declare const getPosX: (width: number, vpos: number, long: number) => number;
|
|
683
685
|
declare const parseFont: (font: commentFont, size: string | number) => string;
|
|
684
686
|
declare const arrayPush: (array: {
|
|
685
687
|
[key: number]: number[];
|
|
@@ -689,6 +691,7 @@ declare const replaceAll: (string: string, target: string, replace: string) => s
|
|
|
689
691
|
declare const changeCALayer: (rawData: formattedComment[]) => formattedComment[];
|
|
690
692
|
declare const getConfig: <T>(input: configItem<T>, isFlash?: boolean) => T;
|
|
691
693
|
declare const isFlashComment: (comment: formattedComment) => boolean;
|
|
694
|
+
declare const parseCommandAndNicoScript: (comment: formattedComment) => formattedCommentWithFont;
|
|
692
695
|
|
|
693
696
|
|
|
694
697
|
export default NiconiComments;
|
package/dist/bundle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
niconicomments.js v0.2.
|
|
2
|
+
niconicomments.js v0.2.33
|
|
3
3
|
(c) 2021 xpadev-net https://xpadev.net
|
|
4
4
|
Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -788,7 +788,7 @@
|
|
|
788
788
|
},
|
|
789
789
|
flash: {
|
|
790
790
|
width: 512,
|
|
791
|
-
fullWidth:
|
|
791
|
+
fullWidth: 640,
|
|
792
792
|
height: 385,
|
|
793
793
|
},
|
|
794
794
|
},
|
|
@@ -804,7 +804,7 @@
|
|
|
804
804
|
},
|
|
805
805
|
big: {
|
|
806
806
|
default: 39,
|
|
807
|
-
resized:
|
|
807
|
+
resized: 19.5,
|
|
808
808
|
},
|
|
809
809
|
},
|
|
810
810
|
flash: {
|
|
@@ -846,8 +846,8 @@
|
|
|
846
846
|
cacheAge: 2000,
|
|
847
847
|
canvasWidth: 1920,
|
|
848
848
|
canvasHeight: 1080,
|
|
849
|
-
commentDrawRange:
|
|
850
|
-
commentDrawPadding:
|
|
849
|
+
commentDrawRange: 1530,
|
|
850
|
+
commentDrawPadding: 195,
|
|
851
851
|
collisionRange: {
|
|
852
852
|
left: 235,
|
|
853
853
|
right: 1685,
|
|
@@ -906,6 +906,8 @@
|
|
|
906
906
|
resized: -0.2,
|
|
907
907
|
},
|
|
908
908
|
},
|
|
909
|
+
letterSpacing: 1,
|
|
910
|
+
scriptCharOffset: 0.12,
|
|
909
911
|
};
|
|
910
912
|
};
|
|
911
913
|
var defaultOptions = {
|
|
@@ -928,6 +930,21 @@
|
|
|
928
930
|
var setConfig = function (value) { return (config = value); };
|
|
929
931
|
var setOptions = function (value) { return (options = value); };
|
|
930
932
|
|
|
933
|
+
var nicoScripts = {
|
|
934
|
+
reverse: [],
|
|
935
|
+
default: [],
|
|
936
|
+
replace: [],
|
|
937
|
+
ban: [],
|
|
938
|
+
};
|
|
939
|
+
var resetNicoScripts = function () {
|
|
940
|
+
nicoScripts = {
|
|
941
|
+
reverse: [],
|
|
942
|
+
default: [],
|
|
943
|
+
replace: [],
|
|
944
|
+
ban: [],
|
|
945
|
+
};
|
|
946
|
+
};
|
|
947
|
+
|
|
931
948
|
var getPosY = function (currentPos, targetComment, collision, data) {
|
|
932
949
|
var isChanged = false, isBreak = false;
|
|
933
950
|
if (!collision)
|
|
@@ -964,14 +981,9 @@
|
|
|
964
981
|
}
|
|
965
982
|
return { currentPos: currentPos, isChanged: isChanged, isBreak: isBreak };
|
|
966
983
|
};
|
|
967
|
-
var getPosX = function (width, vpos, long
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
((vpos + 100) / 100)) /
|
|
971
|
-
4) *
|
|
972
|
-
300) /
|
|
973
|
-
long +
|
|
974
|
-
getConfig(config.commentDrawPadding, isFlash));
|
|
984
|
+
var getPosX = function (width, vpos, long) {
|
|
985
|
+
var speed = (config.commentDrawRange + width) / (long + 100);
|
|
986
|
+
return (config.commentDrawPadding + config.commentDrawRange - (vpos + 100) * speed);
|
|
975
987
|
};
|
|
976
988
|
var parseFont = function (font, size) {
|
|
977
989
|
switch (font) {
|
|
@@ -1075,21 +1087,247 @@
|
|
|
1075
1087
|
comment.mail.includes("mincho")) &&
|
|
1076
1088
|
(comment.date < config.flashThreshold ||
|
|
1077
1089
|
comment.mail.includes("nico:flash")));
|
|
1078
|
-
};
|
|
1079
|
-
|
|
1080
|
-
var nicoScripts = {
|
|
1081
|
-
reverse: [],
|
|
1082
|
-
default: [],
|
|
1083
|
-
replace: [],
|
|
1084
|
-
ban: [],
|
|
1085
1090
|
};
|
|
1086
|
-
var
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1091
|
+
var parseCommandAndNicoScript = function (comment) {
|
|
1092
|
+
var isFlash = isFlashComment(comment);
|
|
1093
|
+
var data = parseCommand(comment), string = comment.content, nicoscript = string.match(/^(?:@|\uff20)(\u30c7\u30d5\u30a9\u30eb\u30c8|\u7f6e\u63db|\u9006|\u30b3\u30e1\u30f3\u30c8\u7981\u6b62|\u30b7\u30fc\u30af\u7981\u6b62|\u30b8\u30e3\u30f3\u30d7)/);
|
|
1094
|
+
if (nicoscript && comment.owner) {
|
|
1095
|
+
var reverse = comment.content.match(/^(?:@|\uff20)\u9006 ?(\u5168|\u30b3\u30e1|\u6295\u30b3\u30e1)?/);
|
|
1096
|
+
var content = comment.content.split(""), result = [];
|
|
1097
|
+
var quote = "", last_i = "", string_1 = "";
|
|
1098
|
+
switch (nicoscript[1]) {
|
|
1099
|
+
case "\u30c7\u30d5\u30a9\u30eb\u30c8":
|
|
1100
|
+
nicoScripts.default.unshift({
|
|
1101
|
+
start: comment.vpos,
|
|
1102
|
+
long: data.long === undefined ? undefined : Math.floor(data.long * 100),
|
|
1103
|
+
color: data.color,
|
|
1104
|
+
size: data.size,
|
|
1105
|
+
font: data.font,
|
|
1106
|
+
loc: data.loc,
|
|
1107
|
+
});
|
|
1108
|
+
break;
|
|
1109
|
+
case "\u9006":
|
|
1110
|
+
if (!reverse ||
|
|
1111
|
+
!reverse[1] ||
|
|
1112
|
+
!typeGuard.nicoScript.range.target(reverse[1]))
|
|
1113
|
+
break;
|
|
1114
|
+
if (data.long === undefined) {
|
|
1115
|
+
data.long = 30;
|
|
1116
|
+
}
|
|
1117
|
+
nicoScripts.reverse.unshift({
|
|
1118
|
+
start: comment.vpos,
|
|
1119
|
+
end: comment.vpos + data.long * 100,
|
|
1120
|
+
target: reverse[1],
|
|
1121
|
+
});
|
|
1122
|
+
break;
|
|
1123
|
+
case "\u30b3\u30e1\u30f3\u30c8\u7981\u6b62":
|
|
1124
|
+
if (data.long === undefined) {
|
|
1125
|
+
data.long = 30;
|
|
1126
|
+
}
|
|
1127
|
+
nicoScripts.ban.unshift({
|
|
1128
|
+
start: comment.vpos,
|
|
1129
|
+
end: comment.vpos + data.long * 100,
|
|
1130
|
+
});
|
|
1131
|
+
break;
|
|
1132
|
+
case "\u7f6e\u63db":
|
|
1133
|
+
for (var _i = 0, _a = content.slice(4); _i < _a.length; _i++) {
|
|
1134
|
+
var i = _a[_i];
|
|
1135
|
+
if (i.match(/["'\u300c]/) && quote === "") {
|
|
1136
|
+
quote = i;
|
|
1137
|
+
}
|
|
1138
|
+
else if (i.match(/["']/) && quote === i && last_i !== "\\") {
|
|
1139
|
+
result.push(replaceAll(string_1, "\\n", "\n"));
|
|
1140
|
+
quote = "";
|
|
1141
|
+
string_1 = "";
|
|
1142
|
+
}
|
|
1143
|
+
else if (i.match(/\u300d/) && quote === "\u300c") {
|
|
1144
|
+
result.push(string_1);
|
|
1145
|
+
quote = "";
|
|
1146
|
+
string_1 = "";
|
|
1147
|
+
}
|
|
1148
|
+
else if (quote === "" && i.match(/\s+/)) {
|
|
1149
|
+
if (string_1) {
|
|
1150
|
+
result.push(string_1);
|
|
1151
|
+
string_1 = "";
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
else {
|
|
1155
|
+
string_1 += i;
|
|
1156
|
+
}
|
|
1157
|
+
last_i = i;
|
|
1158
|
+
}
|
|
1159
|
+
result.push(string_1);
|
|
1160
|
+
if (result[0] === undefined ||
|
|
1161
|
+
(result[2] !== undefined &&
|
|
1162
|
+
!typeGuard.nicoScript.replace.range(result[2])) ||
|
|
1163
|
+
(result[3] !== undefined &&
|
|
1164
|
+
!typeGuard.nicoScript.replace.target(result[3])) ||
|
|
1165
|
+
(result[4] !== undefined &&
|
|
1166
|
+
!typeGuard.nicoScript.replace.condition(result[4])))
|
|
1167
|
+
break;
|
|
1168
|
+
nicoScripts.replace.unshift({
|
|
1169
|
+
start: comment.vpos,
|
|
1170
|
+
long: data.long === undefined ? undefined : Math.floor(data.long * 100),
|
|
1171
|
+
keyword: result[0],
|
|
1172
|
+
replace: result[1] || "",
|
|
1173
|
+
range: result[2] || "\u5358",
|
|
1174
|
+
target: result[3] || "\u30b3\u30e1",
|
|
1175
|
+
condition: result[4] || "\u90e8\u5206\u4e00\u81f4",
|
|
1176
|
+
color: data.color,
|
|
1177
|
+
size: data.size,
|
|
1178
|
+
font: data.font,
|
|
1179
|
+
loc: data.loc,
|
|
1180
|
+
no: comment.id,
|
|
1181
|
+
});
|
|
1182
|
+
nicoScripts.replace.sort(function (a, b) {
|
|
1183
|
+
if (a.start < b.start)
|
|
1184
|
+
return -1;
|
|
1185
|
+
if (a.start > b.start)
|
|
1186
|
+
return 1;
|
|
1187
|
+
if (a.no < b.no)
|
|
1188
|
+
return -1;
|
|
1189
|
+
if (a.no > b.no)
|
|
1190
|
+
return 1;
|
|
1191
|
+
return 0;
|
|
1192
|
+
});
|
|
1193
|
+
break;
|
|
1194
|
+
}
|
|
1195
|
+
data.invisible = true;
|
|
1196
|
+
}
|
|
1197
|
+
var color = undefined, size = undefined, font = undefined, loc = undefined;
|
|
1198
|
+
for (var i = 0; i < nicoScripts.default.length; i++) {
|
|
1199
|
+
var item = nicoScripts.default[i];
|
|
1200
|
+
if (!item)
|
|
1201
|
+
continue;
|
|
1202
|
+
if (item.long !== undefined && item.start + item.long < comment.vpos) {
|
|
1203
|
+
nicoScripts.default = nicoScripts.default.splice(Number(i), 1);
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1206
|
+
if (item.loc) {
|
|
1207
|
+
loc = item.loc;
|
|
1208
|
+
}
|
|
1209
|
+
if (item.color) {
|
|
1210
|
+
color = item.color;
|
|
1211
|
+
}
|
|
1212
|
+
if (item.size) {
|
|
1213
|
+
size = item.size;
|
|
1214
|
+
}
|
|
1215
|
+
if (item.font) {
|
|
1216
|
+
font = item.font;
|
|
1217
|
+
}
|
|
1218
|
+
if (loc && color && size && font)
|
|
1219
|
+
break;
|
|
1220
|
+
}
|
|
1221
|
+
for (var i = 0; i < nicoScripts.replace.length; i++) {
|
|
1222
|
+
var item = nicoScripts.replace[i];
|
|
1223
|
+
if (!item)
|
|
1224
|
+
continue;
|
|
1225
|
+
if (item.long !== undefined && item.start + item.long < comment.vpos) {
|
|
1226
|
+
nicoScripts.default = nicoScripts.default.splice(Number(i), 1);
|
|
1227
|
+
continue;
|
|
1228
|
+
}
|
|
1229
|
+
if ((item.target === "\u30b3\u30e1" && comment.owner) ||
|
|
1230
|
+
(item.target === "\u6295\u30b3\u30e1" && !comment.owner) ||
|
|
1231
|
+
(item.target === "\u542b\u307e\u306a\u3044" && comment.owner))
|
|
1232
|
+
continue;
|
|
1233
|
+
if ((item.condition === "\u5b8c\u5168\u4e00\u81f4" &&
|
|
1234
|
+
comment.content === item.keyword) ||
|
|
1235
|
+
(item.condition === "\u90e8\u5206\u4e00\u81f4" &&
|
|
1236
|
+
comment.content.indexOf(item.keyword) !== -1)) {
|
|
1237
|
+
if (item.range === "\u5358") {
|
|
1238
|
+
comment.content = replaceAll(comment.content, item.keyword, item.replace);
|
|
1239
|
+
}
|
|
1240
|
+
else {
|
|
1241
|
+
comment.content = item.replace;
|
|
1242
|
+
}
|
|
1243
|
+
if (item.loc) {
|
|
1244
|
+
data.loc = item.loc;
|
|
1245
|
+
}
|
|
1246
|
+
if (item.color) {
|
|
1247
|
+
data.color = item.color;
|
|
1248
|
+
}
|
|
1249
|
+
if (item.size) {
|
|
1250
|
+
data.size = item.size;
|
|
1251
|
+
data.fontSize = getConfig(config.fontSize, isFlash)[data.size].default;
|
|
1252
|
+
}
|
|
1253
|
+
if (item.font) {
|
|
1254
|
+
data.font = item.font;
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
if (!data.loc) {
|
|
1259
|
+
data.loc = loc || "naka";
|
|
1260
|
+
}
|
|
1261
|
+
if (!data.color) {
|
|
1262
|
+
data.color = color || "#FFFFFF";
|
|
1263
|
+
}
|
|
1264
|
+
if (!data.size) {
|
|
1265
|
+
data.size = size || "medium";
|
|
1266
|
+
data.fontSize = getConfig(config.fontSize, isFlash)[data.size].default;
|
|
1267
|
+
}
|
|
1268
|
+
if (!data.font) {
|
|
1269
|
+
data.font = font || "defont";
|
|
1270
|
+
}
|
|
1271
|
+
if (!data.long) {
|
|
1272
|
+
data.long = 300;
|
|
1273
|
+
}
|
|
1274
|
+
else {
|
|
1275
|
+
data.long = Math.floor(Number(data.long) * 100);
|
|
1276
|
+
}
|
|
1277
|
+
return _assign(_assign(_assign(_assign({}, comment), { content: [], lineCount: 0, lineOffset: 0 }), data), { flash: isFlash });
|
|
1278
|
+
};
|
|
1279
|
+
var parseCommand = function (comment) {
|
|
1280
|
+
var metadata = comment.mail, isFlash = isFlashComment(comment);
|
|
1281
|
+
var result = {
|
|
1282
|
+
loc: undefined,
|
|
1283
|
+
size: undefined,
|
|
1284
|
+
fontSize: undefined,
|
|
1285
|
+
color: undefined,
|
|
1286
|
+
font: undefined,
|
|
1287
|
+
full: false,
|
|
1288
|
+
ender: false,
|
|
1289
|
+
_live: false,
|
|
1290
|
+
invisible: false,
|
|
1291
|
+
long: undefined,
|
|
1092
1292
|
};
|
|
1293
|
+
for (var _i = 0, metadata_1 = metadata; _i < metadata_1.length; _i++) {
|
|
1294
|
+
var command = metadata_1[_i];
|
|
1295
|
+
command = command.toLowerCase();
|
|
1296
|
+
var match = command.match(/^(?:@|\uff20)([0-9.]+)/);
|
|
1297
|
+
if (match && match[1]) {
|
|
1298
|
+
result.long = Number(match[1]);
|
|
1299
|
+
}
|
|
1300
|
+
else if (result.loc === undefined && typeGuard.comment.loc(command)) {
|
|
1301
|
+
result.loc = command;
|
|
1302
|
+
}
|
|
1303
|
+
else if (result.size === undefined && typeGuard.comment.size(command)) {
|
|
1304
|
+
result.size = command;
|
|
1305
|
+
result.fontSize = getConfig(config.fontSize, isFlash)[command].default;
|
|
1306
|
+
}
|
|
1307
|
+
else {
|
|
1308
|
+
if (result.color === undefined) {
|
|
1309
|
+
var color = config.colors[command];
|
|
1310
|
+
if (color) {
|
|
1311
|
+
result.color = color;
|
|
1312
|
+
continue;
|
|
1313
|
+
}
|
|
1314
|
+
else {
|
|
1315
|
+
var match_1 = command.match(/#[0-9a-z]{3,6}/);
|
|
1316
|
+
if (match_1 && match_1[0] && comment.premium) {
|
|
1317
|
+
result.color = match_1[0].toUpperCase();
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
if (result.font === undefined && typeGuard.comment.font(command)) {
|
|
1323
|
+
result.font = command;
|
|
1324
|
+
}
|
|
1325
|
+
else if (typeGuard.comment.command.key(command)) {
|
|
1326
|
+
result[command] = true;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
return result;
|
|
1093
1331
|
};
|
|
1094
1332
|
|
|
1095
1333
|
var canvas;
|
|
@@ -1257,243 +1495,8 @@
|
|
|
1257
1495
|
enumerable: false,
|
|
1258
1496
|
configurable: true
|
|
1259
1497
|
});
|
|
1260
|
-
HTML5Comment.prototype.parseCommand = function (comment) {
|
|
1261
|
-
var metadata = comment.mail, isFlash = isFlashComment(comment);
|
|
1262
|
-
var result = {
|
|
1263
|
-
loc: undefined,
|
|
1264
|
-
size: undefined,
|
|
1265
|
-
fontSize: undefined,
|
|
1266
|
-
color: undefined,
|
|
1267
|
-
font: undefined,
|
|
1268
|
-
full: false,
|
|
1269
|
-
ender: false,
|
|
1270
|
-
_live: false,
|
|
1271
|
-
invisible: false,
|
|
1272
|
-
long: undefined,
|
|
1273
|
-
};
|
|
1274
|
-
for (var _i = 0, metadata_1 = metadata; _i < metadata_1.length; _i++) {
|
|
1275
|
-
var command = metadata_1[_i];
|
|
1276
|
-
command = command.toLowerCase();
|
|
1277
|
-
var match = command.match(/^@([0-9.]+)/);
|
|
1278
|
-
if (match && match[1]) {
|
|
1279
|
-
result.long = Number(match[1]);
|
|
1280
|
-
}
|
|
1281
|
-
else if (result.loc === undefined && typeGuard.comment.loc(command)) {
|
|
1282
|
-
result.loc = command;
|
|
1283
|
-
}
|
|
1284
|
-
else if (result.size === undefined && typeGuard.comment.size(command)) {
|
|
1285
|
-
result.size = command;
|
|
1286
|
-
result.fontSize = getConfig(config.fontSize, isFlash)[command].default;
|
|
1287
|
-
}
|
|
1288
|
-
else {
|
|
1289
|
-
if (result.color === undefined) {
|
|
1290
|
-
var color = config.colors[command];
|
|
1291
|
-
if (color) {
|
|
1292
|
-
result.color = color;
|
|
1293
|
-
continue;
|
|
1294
|
-
}
|
|
1295
|
-
else {
|
|
1296
|
-
var match_1 = command.match(/#[0-9a-z]{3,6}/);
|
|
1297
|
-
if (match_1 && match_1[0] && comment.premium) {
|
|
1298
|
-
result.color = match_1[0].toUpperCase();
|
|
1299
|
-
continue;
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
if (result.font === undefined && typeGuard.comment.font(command)) {
|
|
1304
|
-
result.font = command;
|
|
1305
|
-
}
|
|
1306
|
-
else if (typeGuard.comment.command.key(command)) {
|
|
1307
|
-
result[command] = true;
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
return result;
|
|
1312
|
-
};
|
|
1313
1498
|
HTML5Comment.prototype.parseCommandAndNicoscript = function (comment) {
|
|
1314
|
-
var data =
|
|
1315
|
-
if (nicoscript && comment.owner) {
|
|
1316
|
-
var reverse = comment.content.match(/^@逆 ?(全|コメ|投コメ)?/);
|
|
1317
|
-
var content_1 = comment.content.split(""), result = [];
|
|
1318
|
-
var quote = "", last_i = "", string_1 = "";
|
|
1319
|
-
switch (nicoscript[1]) {
|
|
1320
|
-
case "デフォルト":
|
|
1321
|
-
nicoScripts.default.unshift({
|
|
1322
|
-
start: comment.vpos,
|
|
1323
|
-
long: data.long === undefined ? undefined : Math.floor(data.long * 100),
|
|
1324
|
-
color: data.color,
|
|
1325
|
-
size: data.size,
|
|
1326
|
-
font: data.font,
|
|
1327
|
-
loc: data.loc,
|
|
1328
|
-
});
|
|
1329
|
-
break;
|
|
1330
|
-
case "逆":
|
|
1331
|
-
if (!reverse ||
|
|
1332
|
-
!reverse[1] ||
|
|
1333
|
-
!typeGuard.nicoScript.range.target(reverse[1]))
|
|
1334
|
-
break;
|
|
1335
|
-
if (data.long === undefined) {
|
|
1336
|
-
data.long = 30;
|
|
1337
|
-
}
|
|
1338
|
-
nicoScripts.reverse.unshift({
|
|
1339
|
-
start: comment.vpos,
|
|
1340
|
-
end: comment.vpos + data.long * 100,
|
|
1341
|
-
target: reverse[1],
|
|
1342
|
-
});
|
|
1343
|
-
break;
|
|
1344
|
-
case "コメント禁止":
|
|
1345
|
-
if (data.long === undefined) {
|
|
1346
|
-
data.long = 30;
|
|
1347
|
-
}
|
|
1348
|
-
nicoScripts.ban.unshift({
|
|
1349
|
-
start: comment.vpos,
|
|
1350
|
-
end: comment.vpos + data.long * 100,
|
|
1351
|
-
});
|
|
1352
|
-
break;
|
|
1353
|
-
case "置換":
|
|
1354
|
-
for (var _i = 0, _a = content_1.slice(4); _i < _a.length; _i++) {
|
|
1355
|
-
var i = _a[_i];
|
|
1356
|
-
if (i.match(/["'「]/) && quote === "") {
|
|
1357
|
-
quote = i;
|
|
1358
|
-
}
|
|
1359
|
-
else if (i.match(/["']/) && quote === i && last_i !== "\\") {
|
|
1360
|
-
result.push(replaceAll(string_1, "\\n", "\n"));
|
|
1361
|
-
quote = "";
|
|
1362
|
-
string_1 = "";
|
|
1363
|
-
}
|
|
1364
|
-
else if (i.match(/」/) && quote === "「") {
|
|
1365
|
-
result.push(string_1);
|
|
1366
|
-
quote = "";
|
|
1367
|
-
string_1 = "";
|
|
1368
|
-
}
|
|
1369
|
-
else if (quote === "" && i.match(/\s+/)) {
|
|
1370
|
-
if (string_1) {
|
|
1371
|
-
result.push(string_1);
|
|
1372
|
-
string_1 = "";
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
else {
|
|
1376
|
-
string_1 += i;
|
|
1377
|
-
}
|
|
1378
|
-
last_i = i;
|
|
1379
|
-
}
|
|
1380
|
-
result.push(string_1);
|
|
1381
|
-
if (result[0] === undefined ||
|
|
1382
|
-
result[1] === undefined ||
|
|
1383
|
-
(result[2] !== undefined &&
|
|
1384
|
-
!typeGuard.nicoScript.replace.range(result[2])) ||
|
|
1385
|
-
(result[3] !== undefined &&
|
|
1386
|
-
!typeGuard.nicoScript.replace.target(result[3])) ||
|
|
1387
|
-
(result[4] !== undefined &&
|
|
1388
|
-
!typeGuard.nicoScript.replace.condition(result[4])))
|
|
1389
|
-
break;
|
|
1390
|
-
nicoScripts.replace.unshift({
|
|
1391
|
-
start: comment.vpos,
|
|
1392
|
-
long: data.long === undefined ? undefined : Math.floor(data.long * 100),
|
|
1393
|
-
keyword: result[0],
|
|
1394
|
-
replace: result[1] || "",
|
|
1395
|
-
range: result[2] || "単",
|
|
1396
|
-
target: result[3] || "コメ",
|
|
1397
|
-
condition: result[4] || "部分一致",
|
|
1398
|
-
color: data.color,
|
|
1399
|
-
size: data.size,
|
|
1400
|
-
font: data.font,
|
|
1401
|
-
loc: data.loc,
|
|
1402
|
-
no: comment.id,
|
|
1403
|
-
});
|
|
1404
|
-
nicoScripts.replace.sort(function (a, b) {
|
|
1405
|
-
if (a.start < b.start)
|
|
1406
|
-
return -1;
|
|
1407
|
-
if (a.start > b.start)
|
|
1408
|
-
return 1;
|
|
1409
|
-
if (a.no < b.no)
|
|
1410
|
-
return -1;
|
|
1411
|
-
if (a.no > b.no)
|
|
1412
|
-
return 1;
|
|
1413
|
-
return 0;
|
|
1414
|
-
});
|
|
1415
|
-
break;
|
|
1416
|
-
}
|
|
1417
|
-
data.invisible = true;
|
|
1418
|
-
}
|
|
1419
|
-
var color = undefined, size = undefined, font = undefined, loc = undefined;
|
|
1420
|
-
for (var i = 0; i < nicoScripts.default.length; i++) {
|
|
1421
|
-
var item = nicoScripts.default[i];
|
|
1422
|
-
if (!item)
|
|
1423
|
-
continue;
|
|
1424
|
-
if (item.long !== undefined && item.start + item.long < comment.vpos) {
|
|
1425
|
-
nicoScripts.default = nicoScripts.default.splice(Number(i), 1);
|
|
1426
|
-
continue;
|
|
1427
|
-
}
|
|
1428
|
-
if (item.loc) {
|
|
1429
|
-
loc = item.loc;
|
|
1430
|
-
}
|
|
1431
|
-
if (item.color) {
|
|
1432
|
-
color = item.color;
|
|
1433
|
-
}
|
|
1434
|
-
if (item.size) {
|
|
1435
|
-
size = item.size;
|
|
1436
|
-
}
|
|
1437
|
-
if (item.font) {
|
|
1438
|
-
font = item.font;
|
|
1439
|
-
}
|
|
1440
|
-
if (loc && color && size && font)
|
|
1441
|
-
break;
|
|
1442
|
-
}
|
|
1443
|
-
for (var i = 0; i < nicoScripts.replace.length; i++) {
|
|
1444
|
-
var item = nicoScripts.replace[i];
|
|
1445
|
-
if (!item)
|
|
1446
|
-
continue;
|
|
1447
|
-
if (item.long !== undefined && item.start + item.long < comment.vpos) {
|
|
1448
|
-
nicoScripts.default = nicoScripts.default.splice(Number(i), 1);
|
|
1449
|
-
continue;
|
|
1450
|
-
}
|
|
1451
|
-
if ((item.target === "コメ" && comment.owner) ||
|
|
1452
|
-
(item.target === "投コメ" && !comment.owner) ||
|
|
1453
|
-
(item.target === "含まない" && comment.owner))
|
|
1454
|
-
continue;
|
|
1455
|
-
if ((item.condition === "完全一致" && comment.content === item.keyword) ||
|
|
1456
|
-
(item.condition === "部分一致" &&
|
|
1457
|
-
comment.content.indexOf(item.keyword) !== -1)) {
|
|
1458
|
-
if (item.range === "単") {
|
|
1459
|
-
comment.content = replaceAll(comment.content, item.keyword, item.replace);
|
|
1460
|
-
}
|
|
1461
|
-
else {
|
|
1462
|
-
comment.content = item.replace;
|
|
1463
|
-
}
|
|
1464
|
-
if (item.loc) {
|
|
1465
|
-
data.loc = item.loc;
|
|
1466
|
-
}
|
|
1467
|
-
if (item.color) {
|
|
1468
|
-
data.color = item.color;
|
|
1469
|
-
}
|
|
1470
|
-
if (item.size) {
|
|
1471
|
-
data.size = item.size;
|
|
1472
|
-
}
|
|
1473
|
-
if (item.font) {
|
|
1474
|
-
data.font = item.font;
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
if (!data.loc) {
|
|
1479
|
-
data.loc = loc || "naka";
|
|
1480
|
-
}
|
|
1481
|
-
if (!data.color) {
|
|
1482
|
-
data.color = color || "#FFFFFF";
|
|
1483
|
-
}
|
|
1484
|
-
if (!data.size) {
|
|
1485
|
-
data.size = size || "medium";
|
|
1486
|
-
data.fontSize = getConfig(config.fontSize, false)[data.size].default;
|
|
1487
|
-
}
|
|
1488
|
-
if (!data.font) {
|
|
1489
|
-
data.font = font || "defont";
|
|
1490
|
-
}
|
|
1491
|
-
if (!data.long) {
|
|
1492
|
-
data.long = 300;
|
|
1493
|
-
}
|
|
1494
|
-
else {
|
|
1495
|
-
data.long = Math.floor(Number(data.long) * 100);
|
|
1496
|
-
}
|
|
1499
|
+
var data = parseCommandAndNicoScript(comment);
|
|
1497
1500
|
var content = [];
|
|
1498
1501
|
content.push({ content: comment.content });
|
|
1499
1502
|
var lineCount = content.reduce(function (pv, val) {
|
|
@@ -1501,7 +1504,7 @@
|
|
|
1501
1504
|
return pv + (((_a = val.content.match(/\n/g)) === null || _a === void 0 ? void 0 : _a.length) || 0);
|
|
1502
1505
|
}, 1);
|
|
1503
1506
|
var lineOffset = 0;
|
|
1504
|
-
return _assign(_assign(
|
|
1507
|
+
return _assign(_assign({}, data), { content: content, lineCount: lineCount, lineOffset: lineOffset });
|
|
1505
1508
|
};
|
|
1506
1509
|
HTML5Comment.prototype.measureText = function (comment) {
|
|
1507
1510
|
var widthLimit = getConfig(config.commentStageSize, false)[comment.full ? "fullWidth" : "width"], scale = getConfig(config.commentScale, false);
|
|
@@ -1654,10 +1657,10 @@
|
|
|
1654
1657
|
posX =
|
|
1655
1658
|
config.canvasWidth +
|
|
1656
1659
|
this.comment.width -
|
|
1657
|
-
getPosX(this.comment.width, vpos - this.comment.vpos, this.comment.long
|
|
1660
|
+
getPosX(this.comment.width, vpos - this.comment.vpos, this.comment.long);
|
|
1658
1661
|
}
|
|
1659
1662
|
else {
|
|
1660
|
-
posX = getPosX(this.comment.width, vpos - this.comment.vpos, this.comment.long
|
|
1663
|
+
posX = getPosX(this.comment.width, vpos - this.comment.vpos, this.comment.long);
|
|
1661
1664
|
}
|
|
1662
1665
|
if (posX > config.canvasWidth || posX + this.comment.width < 0) {
|
|
1663
1666
|
return;
|
|
@@ -1794,6 +1797,7 @@
|
|
|
1794
1797
|
function FlashComment(comment, context) {
|
|
1795
1798
|
this.context = context;
|
|
1796
1799
|
this.scale = 1;
|
|
1800
|
+
this.scaleX = 1;
|
|
1797
1801
|
this._globalScale = getConfig(config.commentScale, true);
|
|
1798
1802
|
this.posY = 0;
|
|
1799
1803
|
comment.content = comment.content.replace(/\t/g, "\u2003\u2003");
|
|
@@ -1931,189 +1935,7 @@
|
|
|
1931
1935
|
};
|
|
1932
1936
|
FlashComment.prototype.parseCommandAndNicoscript = function (comment) {
|
|
1933
1937
|
var _a, _b;
|
|
1934
|
-
var data =
|
|
1935
|
-
if (nicoscript && comment.owner) {
|
|
1936
|
-
var reverse = comment.content.match(/^@逆 ?(全|コメ|投コメ)?/);
|
|
1937
|
-
var content_1 = comment.content.split(""), result = [];
|
|
1938
|
-
var quote = "", last_i = "", string_1 = "";
|
|
1939
|
-
switch (nicoscript[1]) {
|
|
1940
|
-
case "デフォルト":
|
|
1941
|
-
nicoScripts.default.unshift({
|
|
1942
|
-
start: comment.vpos,
|
|
1943
|
-
long: data.long === undefined ? undefined : Math.floor(data.long * 100),
|
|
1944
|
-
color: data.color,
|
|
1945
|
-
size: data.size,
|
|
1946
|
-
font: data.font,
|
|
1947
|
-
loc: data.loc,
|
|
1948
|
-
});
|
|
1949
|
-
break;
|
|
1950
|
-
case "逆":
|
|
1951
|
-
if (!reverse ||
|
|
1952
|
-
!reverse[1] ||
|
|
1953
|
-
!typeGuard.nicoScript.range.target(reverse[1]))
|
|
1954
|
-
break;
|
|
1955
|
-
if (data.long === undefined) {
|
|
1956
|
-
data.long = 30;
|
|
1957
|
-
}
|
|
1958
|
-
nicoScripts.reverse.unshift({
|
|
1959
|
-
start: comment.vpos,
|
|
1960
|
-
end: comment.vpos + data.long * 100,
|
|
1961
|
-
target: reverse[1],
|
|
1962
|
-
});
|
|
1963
|
-
break;
|
|
1964
|
-
case "コメント禁止":
|
|
1965
|
-
if (data.long === undefined) {
|
|
1966
|
-
data.long = 30;
|
|
1967
|
-
}
|
|
1968
|
-
nicoScripts.ban.unshift({
|
|
1969
|
-
start: comment.vpos,
|
|
1970
|
-
end: comment.vpos + data.long * 100,
|
|
1971
|
-
});
|
|
1972
|
-
break;
|
|
1973
|
-
case "置換":
|
|
1974
|
-
for (var _i = 0, _c = content_1.slice(4); _i < _c.length; _i++) {
|
|
1975
|
-
var i = _c[_i];
|
|
1976
|
-
if (i.match(/["'「]/) && quote === "") {
|
|
1977
|
-
quote = i;
|
|
1978
|
-
}
|
|
1979
|
-
else if (i.match(/["']/) && quote === i && last_i !== "\\") {
|
|
1980
|
-
result.push(replaceAll(string_1, "\\n", "\n"));
|
|
1981
|
-
quote = "";
|
|
1982
|
-
string_1 = "";
|
|
1983
|
-
}
|
|
1984
|
-
else if (i.match(/」/) && quote === "「") {
|
|
1985
|
-
result.push(string_1);
|
|
1986
|
-
quote = "";
|
|
1987
|
-
string_1 = "";
|
|
1988
|
-
}
|
|
1989
|
-
else if (quote === "" && i.match(/\s+/)) {
|
|
1990
|
-
if (string_1) {
|
|
1991
|
-
result.push(string_1);
|
|
1992
|
-
string_1 = "";
|
|
1993
|
-
}
|
|
1994
|
-
}
|
|
1995
|
-
else {
|
|
1996
|
-
string_1 += i;
|
|
1997
|
-
}
|
|
1998
|
-
last_i = i;
|
|
1999
|
-
}
|
|
2000
|
-
result.push(string_1);
|
|
2001
|
-
if (result[0] === undefined ||
|
|
2002
|
-
result[1] === undefined ||
|
|
2003
|
-
(result[2] !== undefined &&
|
|
2004
|
-
!typeGuard.nicoScript.replace.range(result[2])) ||
|
|
2005
|
-
(result[3] !== undefined &&
|
|
2006
|
-
!typeGuard.nicoScript.replace.target(result[3])) ||
|
|
2007
|
-
(result[4] !== undefined &&
|
|
2008
|
-
!typeGuard.nicoScript.replace.condition(result[4])))
|
|
2009
|
-
break;
|
|
2010
|
-
nicoScripts.replace.unshift({
|
|
2011
|
-
start: comment.vpos,
|
|
2012
|
-
long: data.long === undefined ? undefined : Math.floor(data.long * 100),
|
|
2013
|
-
keyword: result[0],
|
|
2014
|
-
replace: result[1] || "",
|
|
2015
|
-
range: result[2] || "単",
|
|
2016
|
-
target: result[3] || "コメ",
|
|
2017
|
-
condition: result[4] || "部分一致",
|
|
2018
|
-
color: data.color,
|
|
2019
|
-
size: data.size,
|
|
2020
|
-
font: data.font,
|
|
2021
|
-
loc: data.loc,
|
|
2022
|
-
no: comment.id,
|
|
2023
|
-
});
|
|
2024
|
-
nicoScripts.replace.sort(function (a, b) {
|
|
2025
|
-
if (a.start < b.start)
|
|
2026
|
-
return -1;
|
|
2027
|
-
if (a.start > b.start)
|
|
2028
|
-
return 1;
|
|
2029
|
-
if (a.no < b.no)
|
|
2030
|
-
return -1;
|
|
2031
|
-
if (a.no > b.no)
|
|
2032
|
-
return 1;
|
|
2033
|
-
return 0;
|
|
2034
|
-
});
|
|
2035
|
-
break;
|
|
2036
|
-
}
|
|
2037
|
-
data.invisible = true;
|
|
2038
|
-
}
|
|
2039
|
-
var color = undefined, size = undefined, font = undefined, loc = undefined;
|
|
2040
|
-
for (var i = 0; i < nicoScripts.default.length; i++) {
|
|
2041
|
-
var item = nicoScripts.default[i];
|
|
2042
|
-
if (!item)
|
|
2043
|
-
continue;
|
|
2044
|
-
if (item.long !== undefined && item.start + item.long < comment.vpos) {
|
|
2045
|
-
nicoScripts.default = nicoScripts.default.splice(Number(i), 1);
|
|
2046
|
-
continue;
|
|
2047
|
-
}
|
|
2048
|
-
if (item.loc) {
|
|
2049
|
-
loc = item.loc;
|
|
2050
|
-
}
|
|
2051
|
-
if (item.color) {
|
|
2052
|
-
color = item.color;
|
|
2053
|
-
}
|
|
2054
|
-
if (item.size) {
|
|
2055
|
-
size = item.size;
|
|
2056
|
-
}
|
|
2057
|
-
if (item.font) {
|
|
2058
|
-
font = item.font;
|
|
2059
|
-
}
|
|
2060
|
-
if (loc && color && size && font)
|
|
2061
|
-
break;
|
|
2062
|
-
}
|
|
2063
|
-
for (var i = 0; i < nicoScripts.replace.length; i++) {
|
|
2064
|
-
var item = nicoScripts.replace[i];
|
|
2065
|
-
if (!item)
|
|
2066
|
-
continue;
|
|
2067
|
-
if (item.long !== undefined && item.start + item.long < comment.vpos) {
|
|
2068
|
-
nicoScripts.default = nicoScripts.default.splice(Number(i), 1);
|
|
2069
|
-
continue;
|
|
2070
|
-
}
|
|
2071
|
-
if ((item.target === "コメ" && comment.owner) ||
|
|
2072
|
-
(item.target === "投コメ" && !comment.owner) ||
|
|
2073
|
-
(item.target === "含まない" && comment.owner))
|
|
2074
|
-
continue;
|
|
2075
|
-
if ((item.condition === "完全一致" && comment.content === item.keyword) ||
|
|
2076
|
-
(item.condition === "部分一致" &&
|
|
2077
|
-
comment.content.indexOf(item.keyword) !== -1)) {
|
|
2078
|
-
if (item.range === "単") {
|
|
2079
|
-
comment.content = replaceAll(comment.content, item.keyword, item.replace);
|
|
2080
|
-
}
|
|
2081
|
-
else {
|
|
2082
|
-
comment.content = item.replace;
|
|
2083
|
-
}
|
|
2084
|
-
if (item.loc) {
|
|
2085
|
-
data.loc = item.loc;
|
|
2086
|
-
}
|
|
2087
|
-
if (item.color) {
|
|
2088
|
-
data.color = item.color;
|
|
2089
|
-
}
|
|
2090
|
-
if (item.size) {
|
|
2091
|
-
data.size = item.size;
|
|
2092
|
-
}
|
|
2093
|
-
if (item.font) {
|
|
2094
|
-
data.font = item.font;
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
if (!data.loc) {
|
|
2099
|
-
data.loc = loc || "naka";
|
|
2100
|
-
}
|
|
2101
|
-
if (!data.color) {
|
|
2102
|
-
data.color = color || "#FFFFFF";
|
|
2103
|
-
}
|
|
2104
|
-
if (!data.size) {
|
|
2105
|
-
data.size = size || "medium";
|
|
2106
|
-
data.fontSize = getConfig(config.fontSize, true)[data.size].default;
|
|
2107
|
-
}
|
|
2108
|
-
if (!data.font) {
|
|
2109
|
-
data.font = font || "defont";
|
|
2110
|
-
}
|
|
2111
|
-
if (!data.long) {
|
|
2112
|
-
data.long = 300;
|
|
2113
|
-
}
|
|
2114
|
-
else {
|
|
2115
|
-
data.long = Math.floor(Number(data.long) * 100);
|
|
2116
|
-
}
|
|
1938
|
+
var data = parseCommandAndNicoScript(comment);
|
|
2117
1939
|
var content = [];
|
|
2118
1940
|
var parts = (comment.content.match(/\n|[^\n]+/g) || []).map(function (val) {
|
|
2119
1941
|
return Array.from(val.match(/[ -~。-゚]+|[^ -~。-゚]+/g) || []);
|
|
@@ -2133,8 +1955,8 @@
|
|
|
2133
1955
|
};
|
|
2134
1956
|
var _loop_1 = function (line) {
|
|
2135
1957
|
var lineContent = [];
|
|
2136
|
-
for (var
|
|
2137
|
-
var part = line_1[
|
|
1958
|
+
for (var _c = 0, line_1 = line; _c < line_1.length; _c++) {
|
|
1959
|
+
var part = line_1[_c];
|
|
2138
1960
|
if (part.match(/[ -~。-゚]+/g) !== null) {
|
|
2139
1961
|
lineContent.push({ content: part });
|
|
2140
1962
|
continue;
|
|
@@ -2228,8 +2050,8 @@
|
|
|
2228
2050
|
content.push.apply(content, lineContent);
|
|
2229
2051
|
}
|
|
2230
2052
|
};
|
|
2231
|
-
for (var
|
|
2232
|
-
var line = parts_1[
|
|
2053
|
+
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
2054
|
+
var line = parts_1[_i];
|
|
2233
2055
|
_loop_1(line);
|
|
2234
2056
|
}
|
|
2235
2057
|
var val = content[0];
|
|
@@ -2241,40 +2063,30 @@
|
|
|
2241
2063
|
return pv + (((_a = val.content.match(/\n/g)) === null || _a === void 0 ? void 0 : _a.length) || 0);
|
|
2242
2064
|
}, 1);
|
|
2243
2065
|
var lineOffset = (((_a = comment.content.match(new RegExp(config.flashScriptChar.super, "g"))) === null || _a === void 0 ? void 0 : _a.length) || 0) *
|
|
2244
|
-
-
|
|
2066
|
+
-1 *
|
|
2067
|
+
config.scriptCharOffset +
|
|
2245
2068
|
(((_b = comment.content.match(new RegExp(config.flashScriptChar.sub, "g"))) === null || _b === void 0 ? void 0 : _b.length) || 0) *
|
|
2246
|
-
|
|
2247
|
-
return _assign(_assign(
|
|
2069
|
+
config.scriptCharOffset;
|
|
2070
|
+
return _assign(_assign({}, data), { content: content, lineCount: lineCount, lineOffset: lineOffset });
|
|
2248
2071
|
};
|
|
2249
2072
|
FlashComment.prototype.measureText = function (comment) {
|
|
2250
|
-
var configLineHeight = getConfig(config.lineHeight, true), configFontSize = getConfig(config.fontSize, true)
|
|
2251
|
-
var
|
|
2073
|
+
var configLineHeight = getConfig(config.lineHeight, true), configFontSize = getConfig(config.fontSize, true);
|
|
2074
|
+
var lineCount = comment.lineCount;
|
|
2252
2075
|
if (!comment.lineHeight)
|
|
2253
2076
|
comment.lineHeight = configLineHeight[comment.size].default;
|
|
2254
2077
|
if (!comment.resized && !comment.ender) {
|
|
2255
|
-
if (comment.size === "big" && lineCount > 2)
|
|
2256
|
-
comment.
|
|
2257
|
-
comment.
|
|
2258
|
-
comment.
|
|
2259
|
-
comment.
|
|
2260
|
-
this.context.font = parseFont(comment.font, comment.fontSize);
|
|
2261
|
-
}
|
|
2262
|
-
else if (comment.size === "medium" && lineCount > 4) {
|
|
2263
|
-
comment.fontSize = configFontSize.medium.resized;
|
|
2264
|
-
comment.lineHeight = configLineHeight.medium.resized;
|
|
2265
|
-
comment.resized = true;
|
|
2266
|
-
comment.resizedY = true;
|
|
2267
|
-
this.context.font = parseFont(comment.font, comment.fontSize);
|
|
2268
|
-
}
|
|
2269
|
-
else if (comment.size === "small" && lineCount > 6) {
|
|
2270
|
-
comment.fontSize = configFontSize.small.resized;
|
|
2271
|
-
comment.lineHeight = configLineHeight.small.resized;
|
|
2078
|
+
if ((comment.size === "big" && lineCount > 2) ||
|
|
2079
|
+
(comment.size === "medium" && lineCount > 4) ||
|
|
2080
|
+
(comment.size === "small" && lineCount > 6)) {
|
|
2081
|
+
comment.fontSize = configFontSize[comment.size].resized;
|
|
2082
|
+
comment.lineHeight = configLineHeight[comment.size].resized;
|
|
2272
2083
|
comment.resized = true;
|
|
2273
2084
|
comment.resizedY = true;
|
|
2274
2085
|
this.context.font = parseFont(comment.font, comment.fontSize);
|
|
2275
2086
|
}
|
|
2276
2087
|
}
|
|
2277
|
-
var
|
|
2088
|
+
var width_arr = [], spacedWidth_arr = [];
|
|
2089
|
+
var currentWidth = 0, spacedWidth = 0;
|
|
2278
2090
|
for (var i = 0; i < comment.content.length; i++) {
|
|
2279
2091
|
var item = comment.content[i];
|
|
2280
2092
|
if (item === undefined)
|
|
@@ -2283,59 +2095,52 @@
|
|
|
2283
2095
|
var widths = [];
|
|
2284
2096
|
this.context.font = parseFont(item.font || comment.font, comment.fontSize);
|
|
2285
2097
|
for (var i_1 = 0; i_1 < lines.length; i_1++) {
|
|
2286
|
-
var
|
|
2098
|
+
var value = lines[i_1];
|
|
2099
|
+
if (value === undefined)
|
|
2100
|
+
continue;
|
|
2101
|
+
var measure = this.context.measureText(value);
|
|
2287
2102
|
currentWidth += measure.width;
|
|
2103
|
+
spacedWidth +=
|
|
2104
|
+
measure.width + Math.max(value.length - 1, 0) * config.letterSpacing;
|
|
2288
2105
|
widths.push(measure.width);
|
|
2289
2106
|
if (i_1 < lines.length - 1) {
|
|
2290
2107
|
width_arr.push(currentWidth);
|
|
2108
|
+
spacedWidth_arr.push(spacedWidth);
|
|
2109
|
+
spacedWidth = 0;
|
|
2291
2110
|
currentWidth = 0;
|
|
2292
2111
|
}
|
|
2293
2112
|
}
|
|
2294
2113
|
width_arr.push(currentWidth);
|
|
2114
|
+
spacedWidth_arr.push(spacedWidth);
|
|
2295
2115
|
item.width = widths;
|
|
2296
2116
|
}
|
|
2297
|
-
var
|
|
2117
|
+
var leadLine = (function () {
|
|
2118
|
+
var max = 0, index = -1;
|
|
2119
|
+
for (var i = 0, l = spacedWidth_arr.length; i < l; i++) {
|
|
2120
|
+
var val = spacedWidth_arr[i];
|
|
2121
|
+
if (val && max < val) {
|
|
2122
|
+
max = val;
|
|
2123
|
+
index = i;
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
return { max: max, index: index };
|
|
2127
|
+
})();
|
|
2128
|
+
var width = leadLine.max;
|
|
2129
|
+
this.scaleX = leadLine.max / (width_arr[leadLine.index] || 1);
|
|
2298
2130
|
var width_max = width * this.scale;
|
|
2299
2131
|
var height = (comment.fontSize * comment.lineHeight * lineCount +
|
|
2300
2132
|
config.commentYPaddingTop[comment.resizedY ? "resized" : "default"]) *
|
|
2301
2133
|
this.scale;
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2134
|
+
if (Number.isNaN(height))
|
|
2135
|
+
console.log(comment, lineCount, this.scale);
|
|
2136
|
+
if (comment.loc !== "naka") {
|
|
2137
|
+
var widthLimit = getConfig(config.commentStageSize, true)[comment.full ? "fullWidth" : "width"];
|
|
2138
|
+
if (width_max > widthLimit && !comment.resizedX) {
|
|
2139
|
+
comment.fontSize = configFontSize[comment.size].default;
|
|
2140
|
+
comment.lineHeight = configLineHeight[comment.size].default;
|
|
2141
|
+
this.scale = widthLimit / width_max;
|
|
2307
2142
|
comment.resizedX = true;
|
|
2308
|
-
|
|
2309
|
-
return this.measureText(comment);
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
else if (comment.loc !== "naka" &&
|
|
2313
|
-
comment.resizedY &&
|
|
2314
|
-
width_max > widthLimit &&
|
|
2315
|
-
!comment.resizedX) {
|
|
2316
|
-
comment.fontSize = configFontSize[comment.size].default * 1.1;
|
|
2317
|
-
comment.lineHeight = configLineHeight[comment.size].default;
|
|
2318
|
-
comment.resized = true;
|
|
2319
|
-
comment.resizedX = true;
|
|
2320
|
-
this.context.font = parseFont(comment.font, comment.fontSize);
|
|
2321
|
-
return this.measureText(comment);
|
|
2322
|
-
}
|
|
2323
|
-
else if (comment.loc !== "naka" && comment.resizedY && comment.resizedX) {
|
|
2324
|
-
if (comment.full && width_max > configDoubleResizeMaxWidth.full) {
|
|
2325
|
-
while (width_max > configDoubleResizeMaxWidth.full) {
|
|
2326
|
-
width_max /= 1.1;
|
|
2327
|
-
comment.fontSize -= 0.1;
|
|
2328
|
-
}
|
|
2329
|
-
this.context.font = parseFont(comment.font, comment.fontSize);
|
|
2330
|
-
return this.measureText(comment);
|
|
2331
|
-
}
|
|
2332
|
-
else if (!comment.full &&
|
|
2333
|
-
width_max > configDoubleResizeMaxWidth.normal) {
|
|
2334
|
-
while (width_max > configDoubleResizeMaxWidth.normal) {
|
|
2335
|
-
width_max /= 1.1;
|
|
2336
|
-
comment.fontSize -= 0.1;
|
|
2337
|
-
}
|
|
2338
|
-
this.context.font = parseFont(comment.font, comment.fontSize);
|
|
2143
|
+
comment.resized = true;
|
|
2339
2144
|
return this.measureText(comment);
|
|
2340
2145
|
}
|
|
2341
2146
|
}
|
|
@@ -2404,10 +2209,10 @@
|
|
|
2404
2209
|
posX =
|
|
2405
2210
|
config.canvasWidth +
|
|
2406
2211
|
this.comment.width -
|
|
2407
|
-
getPosX(this.comment.width, vpos - this.comment.vpos, this.comment.long
|
|
2212
|
+
getPosX(this.comment.width, vpos - this.comment.vpos, this.comment.long);
|
|
2408
2213
|
}
|
|
2409
2214
|
else {
|
|
2410
|
-
posX = getPosX(this.comment.width, vpos - this.comment.vpos, this.comment.long
|
|
2215
|
+
posX = getPosX(this.comment.width, vpos - this.comment.vpos, this.comment.long);
|
|
2411
2216
|
}
|
|
2412
2217
|
if (posX > config.canvasWidth || posX + this.comment.width < 0) {
|
|
2413
2218
|
return;
|
|
@@ -2426,19 +2231,21 @@
|
|
|
2426
2231
|
else {
|
|
2427
2232
|
this.context.globalAlpha = 1;
|
|
2428
2233
|
}
|
|
2429
|
-
|
|
2234
|
+
try {
|
|
2235
|
+
this.context.drawImage(this.image, posX, posY);
|
|
2236
|
+
}
|
|
2237
|
+
catch (e) {
|
|
2238
|
+
console.log(this.comment, e);
|
|
2239
|
+
}
|
|
2430
2240
|
}
|
|
2431
2241
|
if (showCollision) {
|
|
2432
2242
|
this.context.strokeStyle = "rgba(255,0,255,1)";
|
|
2433
2243
|
this.context.strokeRect(posX, posY, this.comment.width, this.comment.height);
|
|
2434
2244
|
for (var i = 0; i < this.comment.lineCount; i++) {
|
|
2435
2245
|
var linePosY = ((i + 1) * (this.comment.fontSize * this.comment.lineHeight) +
|
|
2436
|
-
config.commentYPaddingTop[this.comment.resizedY ? "resized" : "default"]
|
|
2437
|
-
this.comment.fontSize *
|
|
2438
|
-
this.comment.lineHeight *
|
|
2439
|
-
config.commentYOffset[this.comment.size][this.comment.resizedY ? "resized" : "default"]) *
|
|
2246
|
+
config.commentYPaddingTop[this.comment.resizedY ? "resized" : "default"]) *
|
|
2440
2247
|
this.scale;
|
|
2441
|
-
this.context.strokeStyle = "rgba(255,255,0,0.
|
|
2248
|
+
this.context.strokeStyle = "rgba(255,255,0,0.25)";
|
|
2442
2249
|
this.context.strokeRect(posX, posY + linePosY * this._globalScale, this.comment.width, this.comment.fontSize *
|
|
2443
2250
|
this.comment.lineHeight *
|
|
2444
2251
|
-1 *
|
|
@@ -2492,7 +2299,8 @@
|
|
|
2492
2299
|
context.font = parseFont(this.comment.font, this.comment.fontSize);
|
|
2493
2300
|
context.scale(this._globalScale *
|
|
2494
2301
|
this.scale *
|
|
2495
|
-
(this.comment.layer === -1 ? options.scale : 1)
|
|
2302
|
+
(this.comment.layer === -1 ? options.scale : 1) *
|
|
2303
|
+
this.scaleX, this._globalScale *
|
|
2496
2304
|
this.scale *
|
|
2497
2305
|
(this.comment.layer === -1 ? options.scale : 1));
|
|
2498
2306
|
context.fillStyle = this.comment.color;
|
|
@@ -2623,7 +2431,7 @@
|
|
|
2623
2431
|
count++;
|
|
2624
2432
|
for (var j = beforeVpos; j < comment.long + 125; j++) {
|
|
2625
2433
|
var vpos = comment.vpos + j;
|
|
2626
|
-
var left_pos = getPosX(comment.width, j, comment.long
|
|
2434
|
+
var left_pos = getPosX(comment.width, j, comment.long);
|
|
2627
2435
|
if (left_pos + comment.width >= config.collisionRange.right &&
|
|
2628
2436
|
left_pos <= config.collisionRange.right) {
|
|
2629
2437
|
var result = getPosY(posY, comment, _this.collision.right[vpos], data);
|
|
@@ -2650,7 +2458,7 @@
|
|
|
2650
2458
|
}
|
|
2651
2459
|
for (var j = beforeVpos; j < comment.long + 125; j++) {
|
|
2652
2460
|
var vpos = comment.vpos + j;
|
|
2653
|
-
var left_pos = getPosX(comment.width, j, comment.long
|
|
2461
|
+
var left_pos = getPosX(comment.width, j, comment.long);
|
|
2654
2462
|
arrayPush(_this.timeline, vpos, index);
|
|
2655
2463
|
if (left_pos + comment.width >= config.collisionRange.right &&
|
|
2656
2464
|
left_pos <= config.collisionRange.right) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpadev-net/niconicomments",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.33",
|
|
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
|
"types": "dist/bundle.d.ts",
|
|
@@ -34,28 +34,28 @@
|
|
|
34
34
|
"dist/bundle.js",
|
|
35
35
|
"dist/bundle.d.ts"
|
|
36
36
|
],
|
|
37
|
-
"homepage": "https://xpadev.
|
|
37
|
+
"homepage": "https://xpadev-net.github.io/niconicomments/",
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@babel/core": "^7.
|
|
41
|
-
"@babel/preset-env": "^7.
|
|
40
|
+
"@babel/core": "^7.20.2",
|
|
41
|
+
"@babel/preset-env": "^7.20.2",
|
|
42
42
|
"@rollup/plugin-babel": "^6.0.2",
|
|
43
43
|
"@rollup/plugin-commonjs": "^23.0.2",
|
|
44
44
|
"@rollup/plugin-json": "^5.0.1",
|
|
45
45
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
46
46
|
"@rollup/plugin-typescript": "^9.0.2",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
48
|
-
"@typescript-eslint/parser": "^5.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^5.43.0",
|
|
48
|
+
"@typescript-eslint/parser": "^5.43.0",
|
|
49
49
|
"copyfiles": "^2.4.1",
|
|
50
|
-
"eslint": "^8.
|
|
50
|
+
"eslint": "^8.27.0",
|
|
51
51
|
"eslint-config-prettier": "8.5.0",
|
|
52
|
-
"husky": "^8.0.
|
|
52
|
+
"husky": "^8.0.2",
|
|
53
53
|
"lint-staged": "^13.0.3",
|
|
54
54
|
"prettier": "2.7.1",
|
|
55
55
|
"rimraf": "^3.0.2",
|
|
56
|
-
"rollup": "^3.
|
|
57
|
-
"typedoc": "^0.23.
|
|
56
|
+
"rollup": "^3.3.0",
|
|
57
|
+
"typedoc": "^0.23.21",
|
|
58
58
|
"typedoc-plugin-missing-exports": "^1.0.0",
|
|
59
|
-
"typescript": "^4.
|
|
59
|
+
"typescript": "^4.9.3"
|
|
60
60
|
}
|
|
61
61
|
}
|